Skip to content

Commit c811b23

Browse files
authored
Upgrade the package (#119)
* Make the storage manager public To make the environment for htmlkit work, the manager needs to be cached in the application storage. * Add the press modifier to the text component * Add the environment value to the content rendering In a specific case the environment value didn't get caught by the renderer. * Fix the styling of the divider component * Add a dropdown component * Revise the card component * Remove the css from the grid item The grid should only be for alignment. * Add a scrollview component * Add a carousel component * Extend the carousel component * Add more component tests * Fix test failing * Add motion to the carousel by adding javascript * Add autoplay to the carousel * Fix tests * Add a test for the symbol component * Add the possibility to disable views * Fix the css classes for the position index * Add a few new symbols * Add more symbols * Add the possibility to hide views * Revise the input fields to accept a placeholder value * Add the submit event to the form component * Add comments * Refactor code and rearrange files * Add form validation * Fix some sort of things * Change the js initialization for the carousel component * Add a textpad component
1 parent 4041787 commit c811b23

File tree

83 files changed

+1522
-253
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+1522
-253
lines changed

Package.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ let package = Package(
3333
dependencies: [
3434
.product(name: "Lingo", package: "Lingo"),
3535
.product(name: "Collections", package: "swift-collections")
36-
]
36+
],
37+
exclude: ["Abstraction/README.md", "Framework/README.md"]
3738
),
3839
.target(
3940
name: "HTMLKitConverter",

Sources/HTMLKit/Abstraction/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Abstraction
2+
3+
This directory contains the HTML abstraction.
4+
5+
### Attributes
6+
7+
### Elements
8+
9+
### Tokens
10+
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
import Foundation
22

33
/// A type, that manages the environment storage
4-
internal class Manager {
4+
public class Manager {
55

66
/// The storage of the environment
7-
internal var storage: [AnyKeyPath: Any]
7+
private var storage: [AnyKeyPath: Any]
88

99
/// Initiates a manager
10-
internal init() {
10+
public init() {
1111

1212
self.storage = [:]
1313
}
1414

1515
/// Retrieves an item from storage by its path
16-
internal func retrieve(for path: AnyKeyPath) -> Any? {
16+
public func retrieve(for path: AnyKeyPath) -> Any? {
1717

1818
if let value = self.storage[path] {
1919
return value
@@ -23,7 +23,7 @@ internal class Manager {
2323
}
2424

2525
/// Adds und updates an item to the storage
26-
internal func upsert<T>(_ value: T, for path: AnyKeyPath) {
26+
public func upsert<T>(_ value: T, for path: AnyKeyPath) {
2727
self.storage[path] = value
2828
}
2929
}

Sources/HTMLKit/Framework/README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Framework
2+
3+
This directory contains sources for
4+
5+
### Builders
6+
7+
### Environment
8+
9+
### Extensions
10+
11+
### Helpers
12+
13+
### Localization
14+
15+
### Primitives
16+
17+
### Rendering

Sources/HTMLKit/Framework/Rendering/Renderer.swift

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,12 @@ public class Renderer {
5454
self.lingo = lingo
5555
}
5656

57-
public func add<T>(model: T) where T: Encodable {
58-
manager.upsert(model, for: \T.self)
57+
/// Initiates the renderer.
58+
public init(lingo: Lingo? = nil, manager: Manager) {
59+
60+
self.environment = Environment()
61+
self.manager = manager
62+
self.lingo = lingo
5963
}
6064

6165
/// Renders a view
@@ -112,6 +116,10 @@ public class Renderer {
112116
result += try render(modifier: modifier)
113117
}
114118

119+
if let value = content as? EnvironmentValue {
120+
result += try render(value: value)
121+
}
122+
115123
if let element = content as? String {
116124
result += element
117125
}

Sources/HTMLKitComponents/Actions.swift

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,42 @@
11
/*
22
Abstract:
3-
The file contains the actions for the components.
3+
The file contains the action stencils for the components.
44
*/
55

6+
import Foundation
7+
8+
/// A collection of actions, that can be triggered by events.
69
public enum Actions {
710

11+
/// Shows the target.
812
case show(_ target: String)
13+
14+
/// Hides the target.
915
case hide(_ target: String)
16+
17+
/// Animates the target.
1018
case animate(_ target: String)
19+
20+
/// Opens the target.
1121
case open(_ target: String)
22+
23+
/// Closes the target.
1224
case close(_ target: String)
1325

26+
/// Validates the form.
27+
case valdiate(_ target: String, _ rules: [Validator])
28+
29+
public var description: String {
30+
31+
switch self {
32+
case .valdiate(_, _):
33+
return "validate"
34+
default:
35+
return "default"
36+
}
37+
}
38+
39+
/// The script for the action.
1440
public var script: String {
1541

1642
switch self {
@@ -28,26 +54,47 @@ public enum Actions {
2854

2955
case .close(let target):
3056
return close(target)
57+
58+
case .valdiate(let target, let rules):
59+
return validate(target, rules)
3160
}
3261
}
3362

63+
/// Returns a show action stencil.
3464
private func show(_ target: String) -> String {
3565
return "$('#\(target)').show();"
3666
}
3767

68+
/// Returns a hide action stencil.
3869
private func hide(_ target: String) -> String {
3970
return "$('#\(target)').hide();"
4071
}
4172

73+
/// Returns a animate action stencil.
4274
private func animate(_ target: String) -> String {
4375
return "$('#\(target)').animate();"
4476
}
4577

78+
/// Returns a open action stencil.
4679
private func open(_ target: String) -> String {
4780
return "$('#\(target)').open();"
4881
}
4982

83+
/// Returns a close action stencil.
5084
private func close(_ target: String) -> String {
5185
return "$('#\(target)').close();"
5286
}
87+
88+
/// Returns a close action stencil.
89+
private func validate(_ target: String, _ validators: [Validator]) -> String {
90+
91+
if let data = try? JSONEncoder().encode(validators) {
92+
93+
if let result = String(data: data, encoding: .utf8) {
94+
return "$('#\(target)').validate('\(result)');"
95+
}
96+
}
97+
98+
return "$('#\(target)').validate('[]');"
99+
}
53100
}

Sources/HTMLKitComponents/Components/Button.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,15 @@ extension Button: ButtonModifier {
7777
public func backgroundColor(_ color: Tokens.BackgroundColor) -> Button {
7878
return self.mutate(backgroundcolor: color.rawValue)
7979
}
80+
81+
public func disabled(_ condition: Bool) -> Button {
82+
83+
if condition {
84+
return self.mutate(state: Tokens.ViewState.disabled.rawValue)
85+
}
86+
87+
return self
88+
}
8089
}
8190

8291
extension Button: PressModifier {
@@ -153,4 +162,13 @@ extension LinkButton: ButtonModifier {
153162
public func backgroundColor(_ color: Tokens.BackgroundColor) -> LinkButton {
154163
return self.mutate(backgroundcolor: color.rawValue)
155164
}
165+
166+
public func disabled(_ condition: Bool) -> LinkButton {
167+
168+
if condition {
169+
return self.mutate(state: Tokens.ViewState.disabled.rawValue)
170+
}
171+
172+
return self
173+
}
156174
}
Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,57 @@
1+
/*
2+
Abstract:
3+
The file contains a card component.
4+
*/
5+
16
import HTMLKit
27

3-
public struct Card: View, Modifiable {
8+
/// A component that distinguish content.
9+
public class Card: View {
10+
11+
/// The header of the card.
12+
public var header: [Content]?
413

5-
internal var content: [Content]
14+
/// The content of the card.
15+
public var content: [Content]
616

17+
/// The classes of the content.
718
internal var classes: [String]
819

20+
/// Creates a card.
921
public init(@ContentBuilder<Content> content: () -> [Content]) {
1022

1123
self.content = content()
1224
self.classes = ["card"]
1325
}
1426

27+
/// Creates a card.
28+
public init(@ContentBuilder<Content> content: () -> [Content],
29+
@ContentBuilder<Content> header: () -> [Content]) {
30+
31+
self.content = content()
32+
self.header = header()
33+
self.classes = ["card"]
34+
}
35+
36+
/// Creates a card.
37+
internal init(header: [Content]?, content: [Content], classes: [String]) {
38+
39+
self.header = header
40+
self.content = content
41+
self.classes = classes
42+
}
43+
1544
public var body: Content {
1645
Division {
17-
content
46+
Division {
47+
header
48+
}
49+
.class("card-header")
50+
Division {
51+
content
52+
}
53+
.class("card-body")
1854
}
19-
.class(self.classes.joined(separator: " "))
55+
.class(classes.joined(separator: " "))
2056
}
2157
}
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
/*
2+
Abstract:
3+
The file contains a carousel component.
4+
*/
5+
6+
import HTMLKit
7+
8+
/// A compnonent that cycles through an amount of views.
9+
public struct Carousel: View {
10+
11+
/// The indication for the carousel.
12+
internal var indication: [Content]
13+
14+
/// The content of the carousel.
15+
internal var content: [Content]
16+
17+
/// The classes of the carousel.
18+
internal var classes: [String]
19+
20+
/// Creates a carousel.
21+
public init(@ContentBuilder<Content> content: () -> [Content],
22+
@ContentBuilder<Content> indication: () -> [Content]) {
23+
24+
self.content = content()
25+
self.indication = indication()
26+
self.classes = ["carousel"]
27+
}
28+
29+
/// Creates a carousel.
30+
internal init(indication: [Content], content: [Content], classes: [String]) {
31+
32+
self.indication = indication
33+
self.content = content
34+
self.classes = classes
35+
}
36+
37+
public var body: Content {
38+
Division {
39+
Division {
40+
content
41+
}
42+
.class("carousel-content")
43+
Division {
44+
indication
45+
}
46+
.class("carousel-indication")
47+
}
48+
.class(classes.joined(separator: " "))
49+
}
50+
}
51+
52+
public struct Slide: View, Identifiable, Modifiable {
53+
54+
internal var id: String?
55+
56+
internal var source: String
57+
58+
internal var classes: [String]
59+
60+
internal var caption: [Content]
61+
62+
public init(source: String, @ContentBuilder<Content> caption: () -> [Content]) {
63+
64+
self.source = source
65+
self.caption = caption()
66+
self.classes = ["slide"]
67+
}
68+
69+
internal init(id: String?, source: String, caption: [Content], classes: [String]) {
70+
71+
self.id = id
72+
self.source = source
73+
self.caption = caption
74+
self.classes = classes
75+
}
76+
77+
public var body: Content {
78+
Division {
79+
Division {
80+
HTMLKit.Image()
81+
.source(source)
82+
}
83+
.class("slide-thumbnail")
84+
Division {
85+
caption
86+
}
87+
.class("slide-caption")
88+
}
89+
.class(classes.joined(separator: " "))
90+
.modify(unwrap: id) {
91+
$0.id($1)
92+
}
93+
}
94+
95+
public func tag(_ value: String) -> Slide {
96+
return self.mutate(id: value)
97+
}
98+
}
99+
100+
public struct Indicator: View {
101+
102+
internal var tag: String
103+
104+
public init(for tag: String) {
105+
self.tag = "#" + tag
106+
}
107+
108+
public var body: Content {
109+
Anchor {
110+
}
111+
.class("indicator")
112+
.reference(tag)
113+
}
114+
}

0 commit comments

Comments
 (0)