Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 76 additions & 25 deletions Sources/HTMLKit/Abstraction/Attributes/BasicAttributes.swift
Original file line number Diff line number Diff line change
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 @@ -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 @@ -3298,21 +3349,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 +3759,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
27 changes: 26 additions & 1 deletion Sources/HTMLKit/Abstraction/Elements/BasicElements.swift
Original file line number Diff line number Diff line change
Expand Up @@ -124,17 +124,27 @@ extension Html: GlobalAttributes, GlobalEventAttributes {
return mutate(class: value)
}

@available(*, deprecated, message: "Use the editable(_:) modifier instead.")
public func isEditable(_ value: Bool) -> Html {
return mutate(contenteditable: value)
}

public func editable(_ value: Bool = true) -> Html {
return mutate(contenteditable: value)
}

public func direction(_ value: Values.Direction) -> Html {
return mutate(dir: value.rawValue)
}

@available(*, deprecated, message: "Use the draggable(_:) modifier instead.")
public func isDraggable(_ value: Bool) -> Html {
return mutate(draggable: value)
}

public func draggable(_ value: Bool = true) -> Html {
return mutate(draggable: value)
}

public func enterKeyHint(_ value: Values.Hint) -> Html {
return mutate(enterkeyhint: value.rawValue)
Expand All @@ -149,7 +159,7 @@ extension Html: GlobalAttributes, GlobalEventAttributes {
return self
}

@available(*, deprecated, message: "The inputmode attribute is actually an enumerated attribute. Use the inputMode(_: Mode) modifier instead.")
@available(*, unavailable, message: "Use the inputMode(_:) modifier instead.")
public func inputMode(_ value: String) -> Html {
return mutate(inputmode: value)
}
Expand Down Expand Up @@ -210,9 +220,14 @@ extension Html: GlobalAttributes, GlobalEventAttributes {
return mutate(role: value.rawValue)
}

@available(*, deprecated, message: "Use the spellcheck(_:) modifier instead.")
public func hasSpellCheck(_ value: Bool) -> Html {
return mutate(spellcheck: value)
}

public func spellcheck(_ value: Bool = true) -> Html {
return mutate(spellcheck: value)
}

public func style(_ value: String) -> Html {
return mutate(style: TaintedString(value, as: .css(.attribute)))
Expand All @@ -235,10 +250,20 @@ extension Html: GlobalAttributes, GlobalEventAttributes {
return mutate(title: value)
}

@available(*, deprecated, message: "Use the translate(_:) modifier instead.")
public func translate(_ value: Values.Decision) -> Html {
return mutate(translate: value.rawValue)
}

public func translate(_ value: Bool = true) -> Html {

if value {
return mutate(translate: "yes")
}

return mutate(translate: "no")
}

public func inert(_ condition: Bool = true) -> Html {

if condition {
Expand Down
Loading
Loading