Skip to content

Commit

Permalink
Upgrade the package (#142)
Browse files Browse the repository at this point in the history
* Make some of the components identifiable

* Add center as an option for the content space

* Revise some css

* Make actions exclusive

* Fix some css

* Fix the test from failing

The encoder doesn't keep the order of the keys. Therefore I revised the part to a simple text representation. It is okay for the time being. But later on, with more complex validators, it needs to be changed.

* Revise the carousel component

* Introduce the recently added search element

* Introduce the recently added menu element

* Update some of the value tokens accordingly to the latest html standard

* Introduce the inert attribute

* Introduce the fetchpriority attribute

* Introduce the loading attribute

* Introduce the sourceset attribute

* Introduce the decoding attribute

* Introduce the recently added blocking attribute

* Introduce the recently added popover attribute

* Introduce the recently added popovertarget attribute

* Introduce the recently added popovertargetaction attribute
  • Loading branch information
mattesmohr authored Oct 16, 2023
1 parent 676792d commit 5987966
Show file tree
Hide file tree
Showing 60 changed files with 3,550 additions and 448 deletions.
221 changes: 220 additions & 1 deletion Sources/HTMLKit/Abstraction/Attributes/BasicAttributes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import OrderedCollections

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

/// The protocol provides the element with the accesskey handler.
public protocol AccessKeyAttribute: Attribute {
Expand Down Expand Up @@ -2662,3 +2662,222 @@ extension ShadowRootModeAttribute where Self: ContentNode {
return self.mutate(key: "shadowrootmode", value: value)
}
}

/// The protocol provides the element with inhert handler.
public protocol InertAttribute: Attribute {

/// The function represents the html-attribute 'inert'.
///
/// ```html
/// <tag inert />
/// ```
func inert() -> Self

func inert(_ condition: Bool) -> Self
}

extension InertAttribute where Self: ContentNode {

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

extension InertAttribute where Self: EmptyNode {

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

public protocol FetchPriorityAttribute: Attribute {

/// The function represents the html-attribute 'shadowrootmode'.
///
/// ```html
/// <tag fetchpriority="" />
/// ```
func fetchPriority(_ value: Values.Priority) -> Self
}

extension FetchPriorityAttribute where Self: ContentNode {

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

extension FetchPriorityAttribute where Self: EmptyNode {

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

public protocol LoadingAttribute: Attribute {

/// The function represents the html-attribute 'loading'.
///
/// ```html
/// <tag loading="" />
/// ```
func loading(_ value: Values.Loading) -> Self
}

extension LoadingAttribute where Self: ContentNode {

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

extension LoadingAttribute where Self: EmptyNode {

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

public protocol SourceSetAttribute: Attribute {

/// The function represents the html-attribute 'loading'.
///
/// ```html
/// <tag srcset="" />
/// ```
func sourceSet(_ value: String) -> Self
}

extension SourceSetAttribute where Self: ContentNode {

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

extension SourceSetAttribute where Self: EmptyNode {

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

public protocol DecodingAttribute: Attribute {

/// The function represents the html-attribute 'decoding'.
///
/// ```html
/// <tag decoding="" />
/// ```
func decoding(_ value: Values.Decoding) -> Self
}

extension DecodingAttribute where Self: ContentNode {

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

extension DecodingAttribute where Self: EmptyNode {

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

public protocol BlockingAttribute: Attribute {

/// The function represents the html-attribute 'blocking'.
///
/// ```html
/// <tag blocking="" />
/// ```
func blocking(_ value: Values.Blocking) -> Self
}

extension BlockingAttribute where Self: ContentNode {

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

extension BlockingAttribute where Self: EmptyNode {

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

public protocol PopoverAttribute: Attribute {

/// The function represents the html-attribute 'popover'.
///
/// ```html
/// <tag popover="" />
/// ```
func popover(_ value: Values.Popover.State) -> Self
}

extension PopoverAttribute where Self: ContentNode {

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

extension PopoverAttribute where Self: EmptyNode {

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

public protocol PopoverTargetAttribute: Attribute {

/// The function represents the html-attribute 'popovertarget'.
///
/// ```html
/// <tag popovertarget="" />
/// ```
func popoverTarget(_ value: String) -> Self
}

extension PopoverAttribute where Self: ContentNode {

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

extension PopoverAttribute where Self: EmptyNode {

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

public protocol PopoverActionAttribute: Attribute {

/// The function represents the html-attribute 'popovertargetaction'.
///
/// ```html
/// <tag popovertargetaction="" />
/// ```
func popoverAction(_ value: Values.Popover.Action) -> Self
}

extension PopoverAttribute where Self: ContentNode {

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

extension PopoverAttribute where Self: EmptyNode {

internal func mutate(popoveraction value: String) -> Self {
return self.mutate(key: "popovertargetaction", value: value)
}
}
17 changes: 17 additions & 0 deletions Sources/HTMLKit/Abstraction/Elements/BasicElements.swift
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,23 @@ extension Html: GlobalAttributes, GlobalEventAttributes {
return mutate(translate: value.rawValue)
}

public func inert() -> Html {
return mutate(inert: "inert")
}

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

if condition {
return mutate(inert: "inert")
}

return self
}

public func popover(_ value: Values.Popover.State) -> Html {
return mutate(popover: value.rawValue)
}

public func custom(key: String, value: Any) -> Html {
return mutate(key: key, value: value)
}
Expand Down
Loading

0 comments on commit 5987966

Please sign in to comment.