@astryxdesign/native 0.7.6-canary.eae5d92 → 0.7.6-canary.eb282ba

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/apple/Package.swift +0 -2
  2. package/apple/README.md +19 -3
  3. package/apple/Sources/Astryx/Avatar/Avatar.swift +9 -12
  4. package/apple/Sources/Astryx/Base/SafeDestination.swift +48 -0
  5. package/apple/Sources/Astryx/Button/Button.swift +3 -21
  6. package/apple/Sources/Astryx/Item/Item.swift +446 -0
  7. package/apple/Sources/Astryx/List/ListItem.swift +255 -0
  8. package/apple/Sources/Astryx/Wire/AstryxNodeView.swift +16 -0
  9. package/apple/Sources/AstryxNative/Generated/AstryxNode.swift +6 -0
  10. package/apple/Sources/AstryxNative/Generated/Item.swift +173 -0
  11. package/apple/Sources/AstryxNative/Generated/ListItem.swift +122 -0
  12. package/apple/Tests/AstryxTests/AvatarTests.swift +14 -0
  13. package/apple/Tests/AstryxTests/ItemTests.swift +295 -0
  14. package/apple/Tests/AstryxTests/ListItemTests.swift +234 -0
  15. package/dist/components/Item.d.ts +10 -0
  16. package/dist/components/Item.d.ts.map +1 -0
  17. package/dist/components/Item.js +22 -0
  18. package/dist/components/ListItem.d.ts +10 -0
  19. package/dist/components/ListItem.d.ts.map +1 -0
  20. package/dist/components/ListItem.js +20 -0
  21. package/dist/components/index.d.ts.map +1 -1
  22. package/dist/components/index.js +4 -0
  23. package/dist/types/android.d.ts +29 -3
  24. package/dist/types/core.d.ts +30 -0
  25. package/dist/types/ios.d.ts +29 -3
  26. package/dist/types/macos.d.ts +29 -3
  27. package/dist/types/shared.d.ts +29 -3
  28. package/dist/types/windows.d.ts +29 -3
  29. package/package.json +3 -3
  30. package/src/components/Item.ts +34 -0
  31. package/src/components/ListItem.ts +32 -0
  32. package/src/components/index.ts +4 -0
  33. package/src/contract/contracts.test.ts +60 -0
  34. package/src/theme/swiftIOSTheme.test.ts +372 -38
  35. package/apple/Sources/Astryx/Avatar/Avatar.spec.md +0 -219
  36. package/apple/Sources/Astryx/Avatar/AvatarStatusDot.spec.md +0 -162
  37. package/apple/Sources/Astryx/Button/Button.spec.md +0 -174
  38. package/apple/Sources/Astryx/Icon/Icon.spec.md +0 -189
  39. package/apple/Sources/Astryx/TextInput/TextInput.spec.md +0 -179
  40. package/apple/Sources/Astryx/Thumbnail/Thumbnail.spec.md +0 -191
@@ -0,0 +1,255 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ import AstryxNative
4
+ import SwiftUI
5
+
6
+ /// A row of a `List` (core `ListItem`): an `Item` that takes its density,
7
+ /// marker, dividers, and edge from the list that holds it. Outside a list it
8
+ /// draws as a plain `Item`.
9
+ ///
10
+ /// ```swift
11
+ /// ListItem("Preheat the oven", description: "To 180 degrees")
12
+ /// ListItem("Wi-Fi", description: "Home") {
13
+ /// Icon(.check)
14
+ /// } onClick: { openWiFi() }
15
+ /// ```
16
+ public struct ListItem<StartContent: View, EndContent: View>: View {
17
+ /// The contract the view draws, the same for both initializers.
18
+ public let props: ListItemProps
19
+ let startContent: StartContent
20
+ let endContent: EndContent
21
+ @Environment(\.astryx) private var astryx
22
+ @Environment(\.astryxListContext) private var list
23
+ @Environment(\.astryxListNumbers) private var numbers
24
+ /// This row's identity among its list's rows, for its number.
25
+ @State private var rowID = UUID()
26
+
27
+ /// A list row from its labeled props. A single trailing closure is the start
28
+ /// content; set `onClick` by label or as a trailing `onClick:` closure.
29
+ /// - Parameters:
30
+ /// - label: The row's main words (core `label`).
31
+ /// - description: Supporting words under the label (core `description`).
32
+ /// - align: How the start and end content line up with the words; `nil` is `center` (core `align`).
33
+ /// - href: A URL the system opens when the row is tapped; the row becomes a link (core `href`).
34
+ /// - isDisabled: Dims the row; a button or link row stays reachable and does nothing (core `isDisabled`).
35
+ /// - isSelected: Draws the row as selected and reads it as selected (core `isSelected`).
36
+ /// - startContent: Content before the words, such as an `Icon` or an `Avatar` (core `startContent`).
37
+ /// - endContent: Content after the words (core `endContent`).
38
+ /// - onClick: Runs when the row is tapped; the row becomes a button when it has no `href` (core `onClick`).
39
+ public init(
40
+ _ label: String,
41
+ description: String? = nil,
42
+ align: ListItemAlign? = nil,
43
+ href: String? = nil,
44
+ isDisabled: Bool? = nil,
45
+ isSelected: Bool? = nil,
46
+ @ViewBuilder startContent: () -> StartContent = { EmptyView() },
47
+ @ViewBuilder endContent: () -> EndContent = { EmptyView() },
48
+ onClick: (() -> Void)? = nil
49
+ ) {
50
+ self.init(
51
+ ListItemProps(
52
+ label: label, description: description, onClick: onClick, href: href, align: align,
53
+ isDisabled: isDisabled, isSelected: isSelected),
54
+ startContent: startContent, endContent: endContent)
55
+ }
56
+
57
+ /// A list row from its generated contract, for generated and wire-driven callers.
58
+ public init(
59
+ _ props: ListItemProps,
60
+ @ViewBuilder startContent: () -> StartContent = { EmptyView() },
61
+ @ViewBuilder endContent: () -> EndContent = { EmptyView() }
62
+ ) {
63
+ self.props = props
64
+ self.startContent = startContent()
65
+ self.endContent = endContent()
66
+ }
67
+
68
+ public var body: some View {
69
+ Item(itemProps, startContent: { startContent }, endContent: { endContent }, marker: { marker })
70
+ .environment(\.astryxItemListTreatment, treatment)
71
+ // A row in a list announces itself so the list can number its rows in
72
+ // order, as core's CSS counter counts list items.
73
+ .preference(key: ListRowsKey.self, value: list == nil ? [] : [rowID])
74
+ }
75
+
76
+ /// The `Item` this row draws: its own props, with the list's density.
77
+ var itemProps: ItemProps {
78
+ ItemProps(
79
+ label: props.label, description: props.description,
80
+ align: props.align.flatMap { ItemAlign(rawValue: $0.rawValue) },
81
+ density: list?.density, onClick: props.onClick, href: props.href, isSelected: props.isSelected,
82
+ isDisabled: props.isDisabled, base: props.base)
83
+ }
84
+
85
+ /// How the list draws this row: the marker on the first line, no inline
86
+ /// inset in a flush list, and square corners between dividers.
87
+ var treatment: ItemListTreatment? {
88
+ guard let list else { return nil }
89
+ return ItemListTreatment(
90
+ markerOnFirstLine: list.marker != nil,
91
+ inlineInset: list.isFlush ? 0 : nil,
92
+ squareCorners: list.hasDividers)
93
+ }
94
+
95
+ /// The list's marker for this row: a dot, a ring, or its number.
96
+ @ViewBuilder var marker: some View {
97
+ switch list?.marker {
98
+ case .disc:
99
+ Circle()
100
+ .fill(astryx.tokens.color.textPrimary)
101
+ .frame(width: ListItem.markerDot, height: ListItem.markerDot)
102
+ .frame(width: ListItem.markerColumn(astryx))
103
+ .accessibilityHidden(!ListItem.markerIsRead(.disc))
104
+ case .circle:
105
+ Circle()
106
+ .strokeBorder(astryx.tokens.color.textPrimary, lineWidth: 1)
107
+ .frame(width: ListItem.markerDot, height: ListItem.markerDot)
108
+ .frame(width: ListItem.markerColumn(astryx))
109
+ .accessibilityHidden(!ListItem.markerIsRead(.circle))
110
+ case .decimal:
111
+ ListMarkerNumber(
112
+ text: ListItem.number(ordinal: numbers?.number(for: rowID) ?? 1), row: rowID, numbers: numbers,
113
+ inset: rowInset)
114
+ case nil:
115
+ EmptyView()
116
+ }
117
+ }
118
+
119
+ /// The row's inline inset, which a wide number may reach into: none in a
120
+ /// flush list, else core's padding for the list's density.
121
+ var rowInset: CGFloat {
122
+ guard let list else { return 0 }
123
+ return list.isFlush ? 0 : Item<EmptyView, EmptyView, EmptyView>.inlinePadding(density: list.density, tokens: astryx.tokens)
124
+ }
125
+
126
+ /// Whether VoiceOver reads a marker: a number is read as part of the row;
127
+ /// a dot or ring is decoration and hidden.
128
+ nonisolated static func markerIsRead(_ marker: ListContext.Marker) -> Bool { marker == .decimal }
129
+
130
+ /// The marker column: core's `space.s4`, grown with Dynamic Type as the
131
+ /// number in it grows, and the same width on every row.
132
+ static func markerColumn(_ astryx: AstryxStyle) -> CGFloat {
133
+ (astryx.tokens.space.s4 * max(astryx.textScale, 1)).rounded()
134
+ }
135
+
136
+ /// A number marker's column: the marker column, or wider when the list's
137
+ /// widest number does not fit it and the row's inline inset together, so
138
+ /// every row of the list widens alike and no number moves its own row's
139
+ /// words (core's numbered markers; `spec:AST-061` FR11).
140
+ nonisolated static func numberColumn(base: CGFloat, widest: CGFloat, inset: CGFloat) -> CGFloat {
141
+ max(base, widest - inset)
142
+ }
143
+
144
+ /// Core's marker dot: 6 points.
145
+ nonisolated static var markerDot: CGFloat { 6 }
146
+
147
+ /// A decimal marker's words: the row's number and a period, as core's
148
+ /// `counter(…) "."`.
149
+ nonisolated static func number(ordinal: Int) -> String { "\(ordinal)." }
150
+ }
151
+
152
+ /// A decimal marker: the number and its period in the body type with tabular
153
+ /// figures, ending at the column's end so every period in the list lines up,
154
+ /// as core's numbered markers do. A number wider than the column reaches into
155
+ /// the row's inline inset; past that, the list's shared column widens.
156
+ struct ListMarkerNumber: View {
157
+ let text: String
158
+ var row: UUID? = nil
159
+ var numbers: ListNumbers? = nil
160
+ var inset: CGFloat = 0
161
+ @Environment(\.astryx) private var astryx
162
+ @State private var natural: CGFloat = 0
163
+
164
+ var body: some View {
165
+ let column = ListItem<EmptyView, EmptyView>.numberColumn(
166
+ base: ListItem<EmptyView, EmptyView>.markerColumn(astryx), widest: numbers?.widest ?? natural, inset: inset)
167
+ SwiftUI.Text(text)
168
+ .font(astryx.font(size: "text-body-size", 14, weight: "text-body-weight"))
169
+ .monospacedDigit()
170
+ .foregroundStyle(astryx.tokens.color.textPrimary)
171
+ .fixedSize()
172
+ .onGeometryChange(for: CGFloat.self) { $0.size.width } action: { width in
173
+ natural = width
174
+ if let row { numbers?.report(row, width: width) }
175
+ }
176
+ .frame(width: column, alignment: .trailing)
177
+ }
178
+ }
179
+
180
+ /// The list a `ListItem` sits in, as `List` describes it to its rows.
181
+ struct ListContext: Equatable {
182
+ /// The kind of marker each row draws.
183
+ enum Marker: Equatable { case disc, circle, decimal }
184
+
185
+ var density: ItemDensity?
186
+ var hasDividers: Bool
187
+ var isFlush: Bool
188
+ var marker: Marker?
189
+ }
190
+
191
+ private struct ListContextKey: EnvironmentKey {
192
+ static let defaultValue: ListContext? = nil
193
+ }
194
+
195
+ /// The numbers a list gives its rows, by row, in the order the rows appear.
196
+ @MainActor @Observable
197
+ final class ListNumbers {
198
+ private(set) var numbers: [UUID: Int] = [:]
199
+
200
+ nonisolated init() {}
201
+
202
+ /// The widest number any row of the list draws, for the shared column.
203
+ private(set) var widest: CGFloat = 0
204
+ private var widths: [UUID: CGFloat] = [:]
205
+
206
+ /// Numbers the rows in order, the first one `start`, and forgets the widths
207
+ /// of rows that left the list.
208
+ func assign(_ rows: [UUID], start: Int) {
209
+ let numbered = Dictionary(rows.enumerated().map { ($0.element, start + $0.offset) }, uniquingKeysWith: { first, _ in first })
210
+ if numbered != numbers { numbers = numbered }
211
+ let kept = widths.filter { numbered[$0.key] != nil }
212
+ if kept.count != widths.count {
213
+ widths = kept
214
+ updateWidest()
215
+ }
216
+ }
217
+
218
+ /// Records the width a row's number draws at.
219
+ func report(_ row: UUID, width: CGFloat) {
220
+ guard widths[row] != width else { return }
221
+ widths[row] = width
222
+ updateWidest()
223
+ }
224
+
225
+ private func updateWidest() {
226
+ let next = widths.values.max() ?? 0
227
+ if next != widest { widest = next }
228
+ }
229
+
230
+ func number(for row: UUID) -> Int? { numbers[row] }
231
+ }
232
+
233
+ /// The rows of a list, in order: each `ListItem` adds its own identity.
234
+ struct ListRowsKey: PreferenceKey {
235
+ static let defaultValue: [UUID] = []
236
+ static func reduce(value: inout [UUID], nextValue: () -> [UUID]) { value.append(contentsOf: nextValue()) }
237
+ }
238
+
239
+ private struct ListNumbersKey: EnvironmentKey {
240
+ static let defaultValue: ListNumbers? = nil
241
+ }
242
+
243
+ extension EnvironmentValues {
244
+ /// The list around a row; `nil` outside a list.
245
+ var astryxListContext: ListContext? {
246
+ get { self[ListContextKey.self] }
247
+ set { self[ListContextKey.self] = newValue }
248
+ }
249
+
250
+ /// The numbers of the rows of the list around a row.
251
+ var astryxListNumbers: ListNumbers? {
252
+ get { self[ListNumbersKey.self] }
253
+ set { self[ListNumbersKey.self] = newValue }
254
+ }
255
+ }
@@ -25,6 +25,20 @@ public struct AstryxNodeView: View {
25
25
  Avatar(avatar.viewProps(send: send)) { AstryxNodeList(nodes: avatar.props.status ?? [], send: send) }
26
26
  case .avatarStatusDot(let dot): AvatarStatusDot(dot.viewProps(send: send))
27
27
  case .thumbnail(let thumbnail): Thumbnail(thumbnail.viewProps(send: send))
28
+ case .item(let item):
29
+ Item(item.viewProps(send: send)) {
30
+ AstryxNodeList(nodes: item.props.startContent ?? [], send: send)
31
+ } endContent: {
32
+ AstryxNodeList(nodes: item.props.endContent ?? [], send: send)
33
+ } marker: {
34
+ AstryxNodeList(nodes: item.props.marker ?? [], send: send)
35
+ }
36
+ case .listItem(let row):
37
+ ListItem(row.viewProps(send: send)) {
38
+ AstryxNodeList(nodes: row.props.startContent ?? [], send: send)
39
+ } endContent: {
40
+ AstryxNodeList(nodes: row.props.endContent ?? [], send: send)
41
+ }
28
42
  default: AstryxUnsupportedNode(component: Self.componentName(node))
29
43
  }
30
44
  }
@@ -41,6 +55,8 @@ public struct AstryxNodeView: View {
41
55
  case .heading: "Heading"
42
56
  case .hStack: "HStack"
43
57
  case .icon: "Icon"
58
+ case .item: "Item"
59
+ case .listItem: "ListItem"
44
60
  case .progressBar: "ProgressBar"
45
61
  case .selector: "Selector"
46
62
  case .switch: "Switch"
@@ -16,6 +16,8 @@ public enum AstryxNode: Decodable, Equatable, Sendable {
16
16
  case heading(HeadingNode)
17
17
  case hStack(HStackNode)
18
18
  case icon(IconNode)
19
+ case item(ItemNode)
20
+ case listItem(ListItemNode)
19
21
  case progressBar(ProgressBarNode)
20
22
  case selector(SelectorNode)
21
23
  case `switch`(SwitchNode)
@@ -36,6 +38,8 @@ public enum AstryxNode: Decodable, Equatable, Sendable {
36
38
  case .heading(let node): return node.key
37
39
  case .hStack(let node): return node.key
38
40
  case .icon(let node): return node.key
41
+ case .item(let node): return node.key
42
+ case .listItem(let node): return node.key
39
43
  case .progressBar(let node): return node.key
40
44
  case .selector(let node): return node.key
41
45
  case .`switch`(let node): return node.key
@@ -64,6 +68,8 @@ public enum AstryxNode: Decodable, Equatable, Sendable {
64
68
  case "Heading": self = .heading(try HeadingNode(from: decoder))
65
69
  case "HStack": self = .hStack(try HStackNode(from: decoder))
66
70
  case "Icon": self = .icon(try IconNode(from: decoder))
71
+ case "Item": self = .item(try ItemNode(from: decoder))
72
+ case "ListItem": self = .listItem(try ListItemNode(from: decoder))
67
73
  case "ProgressBar": self = .progressBar(try ProgressBarNode(from: decoder))
68
74
  case "Selector": self = .selector(try SelectorNode(from: decoder))
69
75
  case "Switch": self = .`switch`(try SwitchNode(from: decoder))
@@ -0,0 +1,173 @@
1
+ // Generated by @astryxdesign/native. Do not edit.
2
+ public enum ItemAlign: String, CaseIterable, Codable, Sendable {
3
+ case center = "center"
4
+ case start = "start"
5
+ case firstLine = "first-line"
6
+ }
7
+ public enum ItemDensity: String, CaseIterable, Codable, Sendable {
8
+ case compact = "compact"
9
+ case balanced = "balanced"
10
+ case spacious = "spacious"
11
+ }
12
+ public enum ItemLayout: String, CaseIterable, Codable, Sendable {
13
+ case stacked = "stacked"
14
+ case inline = "inline"
15
+ }
16
+ #if os(iOS)
17
+ public struct ItemProps {
18
+ /// Base props attach to this part on every platform.
19
+ public static let baseTarget: AstryxBaseTarget = .root
20
+ public var base: AstryxBaseProps
21
+ public var label: String
22
+ public var description: String?
23
+ public var align: ItemAlign?
24
+ public var density: ItemDensity?
25
+ public var labelLines: Double?
26
+ public var descriptionLines: Double?
27
+ public var layout: ItemLayout?
28
+ public var onClick: (() -> Void)?
29
+ public var href: String?
30
+ public var isHighlighted: Bool?
31
+ public var isSelected: Bool?
32
+ public var isDisabled: Bool?
33
+ public init(label: String, description: String? = nil, align: ItemAlign? = nil, density: ItemDensity? = nil, labelLines: Double? = nil, descriptionLines: Double? = nil, layout: ItemLayout? = nil, onClick: (() -> Void)? = nil, href: String? = nil, isHighlighted: Bool? = nil, isSelected: Bool? = nil, isDisabled: Bool? = nil, base: AstryxBaseProps = AstryxBaseProps()) {
34
+ self.label = label
35
+ self.description = description
36
+ self.align = align
37
+ self.density = density
38
+ self.labelLines = labelLines
39
+ self.descriptionLines = descriptionLines
40
+ self.layout = layout
41
+ self.onClick = onClick
42
+ self.href = href
43
+ self.isHighlighted = isHighlighted
44
+ self.isSelected = isSelected
45
+ self.isDisabled = isDisabled
46
+ self.base = base
47
+ }
48
+ }
49
+ public struct ItemNode: Decodable, Equatable, Sendable {
50
+ public struct Props: Decodable, Equatable, Sendable {
51
+ public var label: String
52
+ public var marker: [AstryxNode]?
53
+ public var startContent: [AstryxNode]?
54
+ public var description: String?
55
+ public var endContent: [AstryxNode]?
56
+ public var align: ItemAlign?
57
+ public var density: ItemDensity?
58
+ public var labelLines: Double?
59
+ public var descriptionLines: Double?
60
+ public var layout: ItemLayout?
61
+ public var href: String?
62
+ public var isHighlighted: Bool?
63
+ public var isSelected: Bool?
64
+ public var isDisabled: Bool?
65
+ }
66
+ public let key: String
67
+ public let base: AstryxBaseProps?
68
+ public let props: Props
69
+ /// The callbacks the core listens to, by prop name.
70
+ public let events: [String]?
71
+
72
+ public func listens(_ event: String) -> Bool { events?.contains(event) ?? false }
73
+
74
+ /// The contract a Item view takes; its callbacks send actions to the core.
75
+ public func viewProps(send: @escaping @Sendable (AstryxAction) -> Void) -> ItemProps {
76
+ let key = self.key
77
+ return ItemProps(
78
+ label: props.label,
79
+ description: props.description,
80
+ align: props.align,
81
+ density: props.density,
82
+ labelLines: props.labelLines,
83
+ descriptionLines: props.descriptionLines,
84
+ layout: props.layout,
85
+ onClick: listens("onClick") ? { send(AstryxAction(key: key, component: "Item", event: "onClick", args: [])) } : nil,
86
+ href: props.href,
87
+ isHighlighted: props.isHighlighted,
88
+ isSelected: props.isSelected,
89
+ isDisabled: props.isDisabled,
90
+ base: base ?? AstryxBaseProps()
91
+ )
92
+ }
93
+ }
94
+ #endif
95
+ #if os(macOS)
96
+ public struct ItemProps {
97
+ /// Base props attach to this part on every platform.
98
+ public static let baseTarget: AstryxBaseTarget = .root
99
+ public var base: AstryxBaseProps
100
+ public var label: String
101
+ public var description: String?
102
+ public var align: ItemAlign?
103
+ public var density: ItemDensity?
104
+ public var labelLines: Double?
105
+ public var descriptionLines: Double?
106
+ public var layout: ItemLayout?
107
+ public var onClick: (() -> Void)?
108
+ public var href: String?
109
+ public var isHighlighted: Bool?
110
+ public var isSelected: Bool?
111
+ public var isDisabled: Bool?
112
+ public init(label: String, description: String? = nil, align: ItemAlign? = nil, density: ItemDensity? = nil, labelLines: Double? = nil, descriptionLines: Double? = nil, layout: ItemLayout? = nil, onClick: (() -> Void)? = nil, href: String? = nil, isHighlighted: Bool? = nil, isSelected: Bool? = nil, isDisabled: Bool? = nil, base: AstryxBaseProps = AstryxBaseProps()) {
113
+ self.label = label
114
+ self.description = description
115
+ self.align = align
116
+ self.density = density
117
+ self.labelLines = labelLines
118
+ self.descriptionLines = descriptionLines
119
+ self.layout = layout
120
+ self.onClick = onClick
121
+ self.href = href
122
+ self.isHighlighted = isHighlighted
123
+ self.isSelected = isSelected
124
+ self.isDisabled = isDisabled
125
+ self.base = base
126
+ }
127
+ }
128
+ public struct ItemNode: Decodable, Equatable, Sendable {
129
+ public struct Props: Decodable, Equatable, Sendable {
130
+ public var label: String
131
+ public var marker: [AstryxNode]?
132
+ public var startContent: [AstryxNode]?
133
+ public var description: String?
134
+ public var endContent: [AstryxNode]?
135
+ public var align: ItemAlign?
136
+ public var density: ItemDensity?
137
+ public var labelLines: Double?
138
+ public var descriptionLines: Double?
139
+ public var layout: ItemLayout?
140
+ public var href: String?
141
+ public var isHighlighted: Bool?
142
+ public var isSelected: Bool?
143
+ public var isDisabled: Bool?
144
+ }
145
+ public let key: String
146
+ public let base: AstryxBaseProps?
147
+ public let props: Props
148
+ /// The callbacks the core listens to, by prop name.
149
+ public let events: [String]?
150
+
151
+ public func listens(_ event: String) -> Bool { events?.contains(event) ?? false }
152
+
153
+ /// The contract a Item view takes; its callbacks send actions to the core.
154
+ public func viewProps(send: @escaping @Sendable (AstryxAction) -> Void) -> ItemProps {
155
+ let key = self.key
156
+ return ItemProps(
157
+ label: props.label,
158
+ description: props.description,
159
+ align: props.align,
160
+ density: props.density,
161
+ labelLines: props.labelLines,
162
+ descriptionLines: props.descriptionLines,
163
+ layout: props.layout,
164
+ onClick: listens("onClick") ? { send(AstryxAction(key: key, component: "Item", event: "onClick", args: [])) } : nil,
165
+ href: props.href,
166
+ isHighlighted: props.isHighlighted,
167
+ isSelected: props.isSelected,
168
+ isDisabled: props.isDisabled,
169
+ base: base ?? AstryxBaseProps()
170
+ )
171
+ }
172
+ }
173
+ #endif
@@ -0,0 +1,122 @@
1
+ // Generated by @astryxdesign/native. Do not edit.
2
+ public enum ListItemAlign: String, CaseIterable, Codable, Sendable {
3
+ case center = "center"
4
+ case start = "start"
5
+ case firstLine = "first-line"
6
+ }
7
+ #if os(iOS)
8
+ public struct ListItemProps {
9
+ /// Base props attach to this part on every platform.
10
+ public static let baseTarget: AstryxBaseTarget = .root
11
+ public var base: AstryxBaseProps
12
+ public var label: String
13
+ public var description: String?
14
+ public var onClick: (() -> Void)?
15
+ public var href: String?
16
+ public var align: ListItemAlign?
17
+ public var isDisabled: Bool?
18
+ public var isSelected: Bool?
19
+ public init(label: String, description: String? = nil, onClick: (() -> Void)? = nil, href: String? = nil, align: ListItemAlign? = nil, isDisabled: Bool? = nil, isSelected: Bool? = nil, base: AstryxBaseProps = AstryxBaseProps()) {
20
+ self.label = label
21
+ self.description = description
22
+ self.onClick = onClick
23
+ self.href = href
24
+ self.align = align
25
+ self.isDisabled = isDisabled
26
+ self.isSelected = isSelected
27
+ self.base = base
28
+ }
29
+ }
30
+ public struct ListItemNode: Decodable, Equatable, Sendable {
31
+ public struct Props: Decodable, Equatable, Sendable {
32
+ public var label: String
33
+ public var description: String?
34
+ public var startContent: [AstryxNode]?
35
+ public var endContent: [AstryxNode]?
36
+ public var href: String?
37
+ public var align: ListItemAlign?
38
+ public var isDisabled: Bool?
39
+ public var isSelected: Bool?
40
+ }
41
+ public let key: String
42
+ public let base: AstryxBaseProps?
43
+ public let props: Props
44
+ /// The callbacks the core listens to, by prop name.
45
+ public let events: [String]?
46
+
47
+ public func listens(_ event: String) -> Bool { events?.contains(event) ?? false }
48
+
49
+ /// The contract a ListItem view takes; its callbacks send actions to the core.
50
+ public func viewProps(send: @escaping @Sendable (AstryxAction) -> Void) -> ListItemProps {
51
+ let key = self.key
52
+ return ListItemProps(
53
+ label: props.label,
54
+ description: props.description,
55
+ onClick: listens("onClick") ? { send(AstryxAction(key: key, component: "ListItem", event: "onClick", args: [])) } : nil,
56
+ href: props.href,
57
+ align: props.align,
58
+ isDisabled: props.isDisabled,
59
+ isSelected: props.isSelected,
60
+ base: base ?? AstryxBaseProps()
61
+ )
62
+ }
63
+ }
64
+ #endif
65
+ #if os(macOS)
66
+ public struct ListItemProps {
67
+ /// Base props attach to this part on every platform.
68
+ public static let baseTarget: AstryxBaseTarget = .root
69
+ public var base: AstryxBaseProps
70
+ public var label: String
71
+ public var description: String?
72
+ public var onClick: (() -> Void)?
73
+ public var href: String?
74
+ public var align: ListItemAlign?
75
+ public var isDisabled: Bool?
76
+ public var isSelected: Bool?
77
+ public init(label: String, description: String? = nil, onClick: (() -> Void)? = nil, href: String? = nil, align: ListItemAlign? = nil, isDisabled: Bool? = nil, isSelected: Bool? = nil, base: AstryxBaseProps = AstryxBaseProps()) {
78
+ self.label = label
79
+ self.description = description
80
+ self.onClick = onClick
81
+ self.href = href
82
+ self.align = align
83
+ self.isDisabled = isDisabled
84
+ self.isSelected = isSelected
85
+ self.base = base
86
+ }
87
+ }
88
+ public struct ListItemNode: Decodable, Equatable, Sendable {
89
+ public struct Props: Decodable, Equatable, Sendable {
90
+ public var label: String
91
+ public var description: String?
92
+ public var startContent: [AstryxNode]?
93
+ public var endContent: [AstryxNode]?
94
+ public var href: String?
95
+ public var align: ListItemAlign?
96
+ public var isDisabled: Bool?
97
+ public var isSelected: Bool?
98
+ }
99
+ public let key: String
100
+ public let base: AstryxBaseProps?
101
+ public let props: Props
102
+ /// The callbacks the core listens to, by prop name.
103
+ public let events: [String]?
104
+
105
+ public func listens(_ event: String) -> Bool { events?.contains(event) ?? false }
106
+
107
+ /// The contract a ListItem view takes; its callbacks send actions to the core.
108
+ public func viewProps(send: @escaping @Sendable (AstryxAction) -> Void) -> ListItemProps {
109
+ let key = self.key
110
+ return ListItemProps(
111
+ label: props.label,
112
+ description: props.description,
113
+ onClick: listens("onClick") ? { send(AstryxAction(key: key, component: "ListItem", event: "onClick", args: [])) } : nil,
114
+ href: props.href,
115
+ align: props.align,
116
+ isDisabled: props.isDisabled,
117
+ isSelected: props.isSelected,
118
+ base: base ?? AstryxBaseProps()
119
+ )
120
+ }
121
+ }
122
+ #endif
@@ -125,6 +125,20 @@ import Testing
125
125
  #expect(Avatar("Ada").linkURL == nil)
126
126
  }
127
127
 
128
+ // family:navigation-destinations FR4: a script URL or an HTML document in a
129
+ // data URL never makes the avatar a link; it stays a button with onClick, or
130
+ // static, as Swift Button and Item refuse them.
131
+ @MainActor
132
+ @Test func aRefusedDestinationLeavesTheAvatarWithoutALink() {
133
+ for refused in ["javascript:alert(1)", " JavaScript: alert(1)", "vbscript:msgbox", "data:text/html,<p>", "data: text/html,<p>"] {
134
+ #expect(Avatar("Ada", href: refused).linkURL == nil, "\(refused)")
135
+ #expect(Avatar("Ada", href: refused).tap == .none, "\(refused)")
136
+ #expect(Avatar("Ada", href: refused, onClick: {}).tap == .button, "\(refused)")
137
+ }
138
+ // Other schemes still open, as before.
139
+ #expect(Avatar("Ada", href: "data:image/png;base64,AAAA").linkURL != nil)
140
+ }
141
+
128
142
  @MainActor
129
143
  @Test func avatarsReadTheirTapAndTraits() {
130
144
  #expect(Avatar("Ada").tap == .none)