Skip to content
Draft
145 changes: 107 additions & 38 deletions Sources/HTMLKit/Abstraction/Attributes/BasicAttributes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import OrderedCollections

/// The alias combines the global attributes of the basic attributes.
@_documentation(visibility: internal)
public typealias GlobalAttributes = AccessKeyAttribute & AutocapitalizeAttribute & AutofocusAttribute & ClassAttribute & EditAttribute & DirectionAttribute & DragAttribute & EnterKeyHintAttribute & HiddenAttribute & InputModeAttribute & IsAttribute & ItemAttribute & ItemIdAttribute & ItemPropertyAttribute & ItemReferenceAttribute & ItemScopeAttribute & ItemTypeAttribute & IdentifierAttribute & LanguageAttribute & NonceAttribute & RoleAttribute & SpellCheckAttribute & StyleAttribute & TabulatorAttribute & TitleAttribute & TranslateAttribute & InertAttribute & PopoverAttribute
public typealias GlobalAttributes = AccessKeyAttribute & AutocapitalizeAttribute & AutofocusAttribute & ClassAttribute & EditAttribute & DirectionAttribute & DragAttribute & EnterKeyAttribute & HiddenAttribute & InputModeAttribute & IsAttribute & ItemAttribute & ItemIdAttribute & ItemPropertyAttribute & ItemReferenceAttribute & ItemScopeAttribute & ItemTypeAttribute & IdentifierAttribute & LanguageAttribute & NonceAttribute & RoleAttribute & SpellCheckAttribute & StyleAttribute & TabulatorAttribute & TitleAttribute & TranslateAttribute & InertAttribute & PopoverAttribute

/// A type that provides the `accessKey` modifier.
@_documentation(visibility: internal)
Expand Down Expand Up @@ -680,7 +680,7 @@ extension ContentAttribute where Self: EmptyNode {
}
}

/// A type that provides the `isEditable` modifier.
/// A type that provides the `editable` modifier.
@_documentation(visibility: internal)
public protocol EditAttribute: Attribute {

Expand All @@ -690,13 +690,13 @@ public protocol EditAttribute: Attribute {
/// Blockquote {
/// "Lorem ipsum..."
/// }
/// .isEditable(false)
/// .editable(false)
/// ```
///
/// - Parameter condition: Whether the element should be editable.
/// - Parameter value: Whether the element should be editable.
///
/// - Returns: The element
func isEditable(_ condition: Bool) -> Self
func editable(_ value: Bool) -> Self
}

extension EditAttribute where Self: ContentNode {
Expand Down Expand Up @@ -1028,7 +1028,7 @@ extension DownloadAttribute where Self: EmptyNode {
}
}

/// A type that provides the `isDraggable` modifier.
/// A type that provides the `draggable` modifier.
@_documentation(visibility: internal)
public protocol DragAttribute: Attribute {

Expand All @@ -1038,13 +1038,13 @@ public protocol DragAttribute: Attribute {
/// Division {
/// ...
/// }
/// .isDraggable(false)
/// .draggable(false)
/// ```
///
/// - Parameter condition: Whether the element should be draggable.
/// - Parameter value: Whether the element should be draggable.
///
/// - Returns: The element
func isDraggable(_ condition: Bool) -> Self
func draggable(_ value: Bool) -> Self
}

extension DragAttribute where Self: ContentNode {
Expand Down Expand Up @@ -1093,32 +1093,32 @@ extension EncodingAttribute where Self: EmptyNode {
}
}

/// A type that provides the `enterKeyHint` modifier.
/// A type that provides the `enterKey` modifier.
@_documentation(visibility: internal)
public protocol EnterKeyHintAttribute: Attribute {
public protocol EnterKeyAttribute: Attribute {

/// Change the enter key for the virtual keyboards.
///
/// ```swift
/// Input()
/// .type(.text)
/// .enterKeyHint(.search)
/// .enterKey(.search)
/// ```
///
/// - Parameter value: The enter key to apply.
///
/// - Returns: The element
func enterKeyHint(_ value: Values.Hint) -> Self
func enterKey(_ value: Values.Hint) -> Self
}

extension EnterKeyHintAttribute where Self: ContentNode {
extension EnterKeyAttribute where Self: ContentNode {

internal func mutate(enterkeyhint value: String) -> Self {
return self.mutate(key: "enterkeyhint", value: value)
}
}

extension EnterKeyHintAttribute where Self: EmptyNode {
extension EnterKeyAttribute where Self: EmptyNode {

internal func mutate(enterkeyhint value: String) -> Self {
return self.mutate(key: "enterkeyhint", value: value)
Expand Down Expand Up @@ -1245,7 +1245,7 @@ public protocol EquivalentAttribute: Attribute {
func equivalent(_ value: Values.Equivalent) -> Self
}

extension HeaderAttribute where Self: ContentNode {
extension EquivalentAttribute where Self: ContentNode {

internal func mutate(httpequiv value: String) -> Self {
return self.mutate(key: "http-equiv", value: value)
Expand All @@ -1261,31 +1261,45 @@ extension EquivalentAttribute where Self: EmptyNode {

/// A type that provides the `headers` modifier.
@_documentation(visibility: internal)
public protocol HeaderAttribute: Attribute {
public protocol HeadersAttribute: Attribute {

/// Specify the header cells for an element.
///
/// ```swift
/// DataCell {
/// "Lorem ipsum..."
/// }
/// .headers("ids")
/// .headers(["id", "id"])
/// ```
///
/// - Parameter ids: The identifiers of the cells to associate with.
///
/// - Returns: The element
func headers(_ ids: String) -> Self
func headers(_ ids: [String]) -> Self

/// Specify the header cells for an element.
///
/// ```swift
/// DataCell {
/// "Lorem ipsum..."
/// }
/// .headers("id", "id")
/// ```
///
/// - Parameter ids: The identifiers of the cells to associate with.
///
/// - Returns: The element
func headers(_ ids: String...) -> Self
}

extension HeaderAttribute where Self: ContentNode {
extension HeadersAttribute where Self: ContentNode {

internal func mutate(headers value: String) -> Self {
return self.mutate(key: "headers", value: value)
}
}

extension HeaderAttribute where Self: EmptyNode {
extension HeadersAttribute where Self: EmptyNode {

internal func mutate(headers value: String) -> Self {
return self.mutate(key: "headers", value: value)
Expand Down Expand Up @@ -1933,20 +1947,57 @@ public protocol LabelAttribute: Attribute {
///
/// - Returns: The element
func label(_ value: String) -> Self

/// Specify a label for the element.
///
/// ```swift
/// Track()
/// .source("...vtt")
/// .kind(.chapters)
/// .label("lorem")
/// ```
///
/// - Parameter localizedKey: The string key to be translated.
/// - Parameter tableName: The translation table to look in.
///
/// - Returns: The element
func label(_ localizedKey: LocalizedStringKey, tableName: String?) -> Self

/// Specify a label for the element without localization.
///
/// ```swift
/// Track()
/// .source("...vtt")
/// .kind(.chapters)
/// .label(verbatim: "lorem")
/// ```
///
/// - Parameter value: The text to use as a label.
///
/// - Returns: The element
func label(verbatim value: String) -> Self
}

extension LabelAttribute where Self: ContentNode {

internal func mutate(label value: String) -> Self {
return self.mutate(key: "label", value: value)
}

internal func mutate(label value: LocalizedString) -> Self {
return self.mutate(key: "label", value: value)
}
}

extension LabelAttribute where Self: EmptyNode {

internal func mutate(label value: String) -> Self {
return self.mutate(key: "label", value: value)
}

internal func mutate(label value: LocalizedString) -> Self {
return self.mutate(key: "label", value: value)
}
}

/// A type that provides the `language` modifier.
Expand Down Expand Up @@ -2452,7 +2503,7 @@ extension NoValidateAttribute where Self: EmptyNode {
}
}

/// A type that provides the `isOpen` modifier.
/// A type that provides the `open` modifier.
@_documentation(visibility: internal)
public protocol OpenAttribute: Attribute {

Expand All @@ -2467,25 +2518,25 @@ public protocol OpenAttribute: Attribute {
/// "Lorem ipsum..."
/// }
/// }
/// .isOpen(true)
/// .open(true)
/// ```
///
/// - Parameter condition: Whether the details should be open.
///
/// - Returns: The element
func isOpen(_ condition: Bool) -> Self
func open(_ condition: Bool) -> Self
}

extension OpenAttribute where Self: ContentNode {

internal func mutate(open value: Bool) -> Self {
internal func mutate(open value: String) -> Self {
return self.mutate(key: "open", value: value)
}
}

extension OpenAttribute where Self: EmptyNode {

internal func mutate(open value: Bool) -> Self {
internal func mutate(open value: String) -> Self {
return self.mutate(key: "open", value: value)
}
}
Expand Down Expand Up @@ -3136,17 +3187,27 @@ extension ScopeAttribute where Self: EmptyNode {
@_documentation(visibility: internal)
public protocol ShapeAttribute: Attribute {

/// Define the entire area as shape.
///
/// ```swift
/// Area()
/// .shape()
/// ```
///
/// - Returns: The element
func shape() -> Self

/// Define the shape for an area.
///
/// ```swift
/// Area()
/// .shape(.circle)
/// .shape(.rect, coordinates: "0, 0, 200, 100")
/// ```
///
/// - Parameter value: The shape used to interpret the coordinates.
///
/// - Returns: The element
func shape(_ value: Values.Shape) -> Self
func shape(_ value: Values.Shape, coordinates: String) -> Self
}

extension ShapeAttribute where Self: ContentNode {
Expand Down Expand Up @@ -3298,21 +3359,21 @@ extension SpanAttribute where Self: EmptyNode {
}
}

/// A type that provides the `hasSpellCheck` modifier.
/// A type that provides the `spellcheck` modifier.
@_documentation(visibility: internal)
public protocol SpellCheckAttribute: Attribute {

/// Mark a element as spellchecked.
///
/// ```swift
/// Input()
/// .hasSpellCheck(false)
/// .spellcheck(false)
/// ```
///
/// - Parameter condition: Whether to spellcheck the content.
/// - Parameter value: Whether to spellcheck the content.
///
/// - Returns: The element
func hasSpellCheck(_ condition: Bool) -> Self
func spellcheck(_ value: Bool) -> Self
}

extension SpellCheckAttribute where Self: ContentNode {
Expand Down Expand Up @@ -3708,13 +3769,13 @@ public protocol TranslateAttribute: Attribute {
/// Paragraph {
/// "Lorem ipsum..."
/// }
/// .translate(.no)
/// .translate(true)
/// ```
///
/// - Parameter value: Whether to exclude the content from translation.
///
/// - Returns: The element
func translate(_ value: Values.Decision) -> Self
func translate(_ value: Bool) -> Self
}

extension TranslateAttribute where Self: ContentNode {
Expand Down Expand Up @@ -3776,8 +3837,7 @@ public protocol UseMapAttribute: Attribute {
/// .useMap("...")
/// Map {
/// Area()
/// .shape(.circle)
/// .coordinates(...)
/// .shape(.circle, coordinates: "...")
/// }
/// .name("...")
/// ```
Expand Down Expand Up @@ -4278,27 +4338,36 @@ public protocol PopoverTargetAttribute: Attribute {
/// Button {
/// "Lorem ipsum"
/// }
/// .popoverTarget("id")
/// .popoverTarget("id", as: .hide)
/// ```
///
/// - Parameter id: The identifier of the target to bind the popover to.
/// - Parameter action: The action to perform when triggered.
///
/// - Returns: The element
func popoverTarget(_ id: String) -> Self
func popoverTarget(_ id: String, as action: Values.Popover.Action) -> Self
}

extension PopoverTargetAttribute where Self: ContentNode {

internal func mutate(popovertarget value: String) -> Self {
return self.mutate(key: "popovertarget", value: value)
}

internal func mutate(popovertargetaction value: String) -> Self {
return self.mutate(key: "popovertargetaction", value: value)
}
}

extension PopoverTargetAttribute where Self: EmptyNode {

internal func mutate(popovertarget value: String) -> Self {
return self.mutate(key: "popovertarget", value: value)
}

internal func mutate(popovertargetaction value: String) -> Self {
return self.mutate(key: "popovertargetaction", value: value)
}
}

/// A type that provides the `popoverAction` modifier
Expand Down
Loading