Skip to content

Commit ceff351

Browse files
authored
Revise some attributes (#207)
* Revise the drag attribute * Mark older deprecations as unavailable * Revise the edit attribute * Revise the spellcheck attribute * Revise the translate attribute * Make the label attribute localizable * Revise the open attribute * Revise the headers attribute * Mark older deprecations as unavailable * Fix failing test * Consolidate fill attributes * Revise the enterkey attribute * Consolidate popovertarget attributes * Consolidate shape attributes * Consolidate stroke attributes * Tidy up a bit
1 parent 77081ae commit ceff351

19 files changed

+4032
-366
lines changed

Sources/HTMLKit/Abstraction/Attributes/BasicAttributes.swift

Lines changed: 118 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import OrderedCollections
33

44
/// The alias combines the global attributes of the basic attributes.
55
@_documentation(visibility: internal)
6-
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
6+
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
77

88
/// A type that provides the `accessKey` modifier.
99
@_documentation(visibility: internal)
@@ -680,7 +680,7 @@ extension ContentAttribute where Self: EmptyNode {
680680
}
681681
}
682682

683-
/// A type that provides the `isEditable` modifier.
683+
/// A type that provides the `editable` modifier.
684684
@_documentation(visibility: internal)
685685
public protocol EditAttribute: Attribute {
686686

@@ -690,13 +690,13 @@ public protocol EditAttribute: Attribute {
690690
/// Blockquote {
691691
/// "Lorem ipsum..."
692692
/// }
693-
/// .isEditable(false)
693+
/// .editable(false)
694694
/// ```
695695
///
696-
/// - Parameter condition: Whether the element should be editable.
696+
/// - Parameter value: Whether the element should be editable.
697697
///
698698
/// - Returns: The element
699-
func isEditable(_ condition: Bool) -> Self
699+
func editable(_ value: Bool) -> Self
700700
}
701701

702702
extension EditAttribute where Self: ContentNode {
@@ -1028,7 +1028,7 @@ extension DownloadAttribute where Self: EmptyNode {
10281028
}
10291029
}
10301030

1031-
/// A type that provides the `isDraggable` modifier.
1031+
/// A type that provides the `draggable` modifier.
10321032
@_documentation(visibility: internal)
10331033
public protocol DragAttribute: Attribute {
10341034

@@ -1038,13 +1038,13 @@ public protocol DragAttribute: Attribute {
10381038
/// Division {
10391039
/// ...
10401040
/// }
1041-
/// .isDraggable(false)
1041+
/// .draggable(false)
10421042
/// ```
10431043
///
1044-
/// - Parameter condition: Whether the element should be draggable.
1044+
/// - Parameter value: Whether the element should be draggable.
10451045
///
10461046
/// - Returns: The element
1047-
func isDraggable(_ condition: Bool) -> Self
1047+
func draggable(_ value: Bool) -> Self
10481048
}
10491049

10501050
extension DragAttribute where Self: ContentNode {
@@ -1093,32 +1093,32 @@ extension EncodingAttribute where Self: EmptyNode {
10931093
}
10941094
}
10951095

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

11001100
/// Change the enter key for the virtual keyboards.
11011101
///
11021102
/// ```swift
11031103
/// Input()
11041104
/// .type(.text)
1105-
/// .enterKeyHint(.search)
1105+
/// .enterKey(.search)
11061106
/// ```
11071107
///
11081108
/// - Parameter value: The enter key to apply.
11091109
///
11101110
/// - Returns: The element
1111-
func enterKeyHint(_ value: Values.Hint) -> Self
1111+
func enterKey(_ value: Values.Hint) -> Self
11121112
}
11131113

1114-
extension EnterKeyHintAttribute where Self: ContentNode {
1114+
extension EnterKeyAttribute where Self: ContentNode {
11151115

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

1121-
extension EnterKeyHintAttribute where Self: EmptyNode {
1121+
extension EnterKeyAttribute where Self: EmptyNode {
11221122

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

1248-
extension HeaderAttribute where Self: ContentNode {
1248+
extension EquivalentAttribute where Self: ContentNode {
12491249

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

12621262
/// A type that provides the `headers` modifier.
12631263
@_documentation(visibility: internal)
1264-
public protocol HeaderAttribute: Attribute {
1264+
public protocol HeadersAttribute: Attribute {
12651265

12661266
/// Specify the header cells for an element.
12671267
///
12681268
/// ```swift
12691269
/// DataCell {
12701270
/// "Lorem ipsum..."
12711271
/// }
1272-
/// .headers("ids")
1272+
/// .headers(["id", "id"])
12731273
/// ```
12741274
///
12751275
/// - Parameter ids: The identifiers of the cells to associate with.
12761276
///
12771277
/// - Returns: The element
1278-
func headers(_ ids: String) -> Self
1278+
func headers(_ ids: [String]) -> Self
1279+
1280+
/// Specify the header cells for an element.
1281+
///
1282+
/// ```swift
1283+
/// DataCell {
1284+
/// "Lorem ipsum..."
1285+
/// }
1286+
/// .headers("id", "id")
1287+
/// ```
1288+
///
1289+
/// - Parameter ids: The identifiers of the cells to associate with.
1290+
///
1291+
/// - Returns: The element
1292+
func headers(_ ids: String...) -> Self
12791293
}
12801294

1281-
extension HeaderAttribute where Self: ContentNode {
1295+
extension HeadersAttribute where Self: ContentNode {
12821296

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

1288-
extension HeaderAttribute where Self: EmptyNode {
1302+
extension HeadersAttribute where Self: EmptyNode {
12891303

12901304
internal func mutate(headers value: String) -> Self {
12911305
return self.mutate(key: "headers", value: value)
@@ -1933,20 +1947,57 @@ public protocol LabelAttribute: Attribute {
19331947
///
19341948
/// - Returns: The element
19351949
func label(_ value: String) -> Self
1950+
1951+
/// Specify a label for the element.
1952+
///
1953+
/// ```swift
1954+
/// Track()
1955+
/// .source("...vtt")
1956+
/// .kind(.chapters)
1957+
/// .label("lorem")
1958+
/// ```
1959+
///
1960+
/// - Parameter localizedKey: The string key to be translated.
1961+
/// - Parameter tableName: The translation table to look in.
1962+
///
1963+
/// - Returns: The element
1964+
func label(_ localizedKey: LocalizedStringKey, tableName: String?) -> Self
1965+
1966+
/// Specify a label for the element without localization.
1967+
///
1968+
/// ```swift
1969+
/// Track()
1970+
/// .source("...vtt")
1971+
/// .kind(.chapters)
1972+
/// .label(verbatim: "lorem")
1973+
/// ```
1974+
///
1975+
/// - Parameter value: The text to use as a label.
1976+
///
1977+
/// - Returns: The element
1978+
func label(verbatim value: String) -> Self
19361979
}
19371980

19381981
extension LabelAttribute where Self: ContentNode {
19391982

19401983
internal func mutate(label value: String) -> Self {
19411984
return self.mutate(key: "label", value: value)
19421985
}
1986+
1987+
internal func mutate(label value: LocalizedString) -> Self {
1988+
return self.mutate(key: "label", value: value)
1989+
}
19431990
}
19441991

19451992
extension LabelAttribute where Self: EmptyNode {
19461993

19471994
internal func mutate(label value: String) -> Self {
19481995
return self.mutate(key: "label", value: value)
19491996
}
1997+
1998+
internal func mutate(label value: LocalizedString) -> Self {
1999+
return self.mutate(key: "label", value: value)
2000+
}
19502001
}
19512002

19522003
/// A type that provides the `language` modifier.
@@ -2452,7 +2503,7 @@ extension NoValidateAttribute where Self: EmptyNode {
24522503
}
24532504
}
24542505

2455-
/// A type that provides the `isOpen` modifier.
2506+
/// A type that provides the `open` modifier.
24562507
@_documentation(visibility: internal)
24572508
public protocol OpenAttribute: Attribute {
24582509

@@ -2467,25 +2518,25 @@ public protocol OpenAttribute: Attribute {
24672518
/// "Lorem ipsum..."
24682519
/// }
24692520
/// }
2470-
/// .isOpen(true)
2521+
/// .open(true)
24712522
/// ```
24722523
///
24732524
/// - Parameter condition: Whether the details should be open.
24742525
///
24752526
/// - Returns: The element
2476-
func isOpen(_ condition: Bool) -> Self
2527+
func open(_ condition: Bool) -> Self
24772528
}
24782529

24792530
extension OpenAttribute where Self: ContentNode {
24802531

2481-
internal func mutate(open value: Bool) -> Self {
2532+
internal func mutate(open value: String) -> Self {
24822533
return self.mutate(key: "open", value: value)
24832534
}
24842535
}
24852536

24862537
extension OpenAttribute where Self: EmptyNode {
24872538

2488-
internal func mutate(open value: Bool) -> Self {
2539+
internal func mutate(open value: String) -> Self {
24892540
return self.mutate(key: "open", value: value)
24902541
}
24912542
}
@@ -3136,17 +3187,28 @@ extension ScopeAttribute where Self: EmptyNode {
31363187
@_documentation(visibility: internal)
31373188
public protocol ShapeAttribute: Attribute {
31383189

3190+
/// Define the entire area as shape.
3191+
///
3192+
/// ```swift
3193+
/// Area()
3194+
/// .shape()
3195+
/// ```
3196+
///
3197+
/// - Returns: The element
3198+
func shape() -> Self
3199+
31393200
/// Define the shape for an area.
31403201
///
31413202
/// ```swift
31423203
/// Area()
3143-
/// .shape(.circle)
3204+
/// .shape(.rect, coordinates: "0, 0, 200, 100")
31443205
/// ```
31453206
///
31463207
/// - Parameter value: The shape used to interpret the coordinates.
3208+
/// - Parameter coordinates: The coordinates on which to base the shape.
31473209
///
31483210
/// - Returns: The element
3149-
func shape(_ value: Values.Shape) -> Self
3211+
func shape(_ value: Values.Shape, coordinates: String) -> Self
31503212
}
31513213

31523214
extension ShapeAttribute where Self: ContentNode {
@@ -3298,21 +3360,21 @@ extension SpanAttribute where Self: EmptyNode {
32983360
}
32993361
}
33003362

3301-
/// A type that provides the `hasSpellCheck` modifier.
3363+
/// A type that provides the `spellcheck` modifier.
33023364
@_documentation(visibility: internal)
33033365
public protocol SpellCheckAttribute: Attribute {
33043366

33053367
/// Mark a element as spellchecked.
33063368
///
33073369
/// ```swift
33083370
/// Input()
3309-
/// .hasSpellCheck(false)
3371+
/// .spellcheck(false)
33103372
/// ```
33113373
///
3312-
/// - Parameter condition: Whether to spellcheck the content.
3374+
/// - Parameter value: Whether to spellcheck the content.
33133375
///
33143376
/// - Returns: The element
3315-
func hasSpellCheck(_ condition: Bool) -> Self
3377+
func spellcheck(_ value: Bool) -> Self
33163378
}
33173379

33183380
extension SpellCheckAttribute where Self: ContentNode {
@@ -3708,13 +3770,13 @@ public protocol TranslateAttribute: Attribute {
37083770
/// Paragraph {
37093771
/// "Lorem ipsum..."
37103772
/// }
3711-
/// .translate(.no)
3773+
/// .translate(true)
37123774
/// ```
37133775
///
37143776
/// - Parameter value: Whether to exclude the content from translation.
37153777
///
37163778
/// - Returns: The element
3717-
func translate(_ value: Values.Decision) -> Self
3779+
func translate(_ value: Bool) -> Self
37183780
}
37193781

37203782
extension TranslateAttribute where Self: ContentNode {
@@ -3776,8 +3838,7 @@ public protocol UseMapAttribute: Attribute {
37763838
/// .useMap("...")
37773839
/// Map {
37783840
/// Area()
3779-
/// .shape(.circle)
3780-
/// .coordinates(...)
3841+
/// .shape(.circle, coordinates: "...")
37813842
/// }
37823843
/// .name("...")
37833844
/// ```
@@ -4278,27 +4339,46 @@ public protocol PopoverTargetAttribute: Attribute {
42784339
/// Button {
42794340
/// "Lorem ipsum"
42804341
/// }
4281-
/// .popoverTarget("id")
4342+
/// .popoverTarget("id", action: .hide)
42824343
/// ```
42834344
///
42844345
/// - Parameter id: The identifier of the target to bind the popover to.
4346+
/// - Parameter action: The action to perform when triggered.
42854347
///
42864348
/// - Returns: The element
4287-
func popoverTarget(_ id: String) -> Self
4349+
func popoverTarget(_ id: String, action: Values.Popover.Action?) -> Self
42884350
}
42894351

42904352
extension PopoverTargetAttribute where Self: ContentNode {
42914353

42924354
internal func mutate(popovertarget value: String) -> Self {
42934355
return self.mutate(key: "popovertarget", value: value)
42944356
}
4357+
4358+
internal func mutate(popovertargetaction value: String?) -> Self {
4359+
4360+
if let value = value {
4361+
return self.mutate(key: "popovertargetaction", value: value)
4362+
}
4363+
4364+
return self
4365+
}
42954366
}
42964367

42974368
extension PopoverTargetAttribute where Self: EmptyNode {
42984369

42994370
internal func mutate(popovertarget value: String) -> Self {
43004371
return self.mutate(key: "popovertarget", value: value)
43014372
}
4373+
4374+
internal func mutate(popovertargetaction value: String?) -> Self {
4375+
4376+
if let value = value {
4377+
return self.mutate(key: "popovertargetaction", value: value)
4378+
}
4379+
4380+
return self
4381+
}
43024382
}
43034383

43044384
/// A type that provides the `popoverAction` modifier

0 commit comments

Comments
 (0)