@astryxdesign/native 0.7.5-canary.8be99c4 → 0.7.5-canary.8c3f3be

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.
@@ -181,6 +181,14 @@ struct TooltipPresenter: ViewModifier {
181
181
  isFocused: holdsByFocus(isFocused: isFocused, focusIsKeyboard: focusIsKeyboard), focus: focus)
182
182
  }
183
183
 
184
+ /// Whether keyboard focus still holds the bubble after the pointer enters
185
+ /// or leaves the view or the bubble: a pointer leaving lets the bubble hide
186
+ /// even though focus opened it, as core's `mouseleave` schedules the hide
187
+ /// whatever brought it up, until focus leaves and returns.
188
+ nonisolated static func keyboardFocusHolds(afterHover inside: Bool, holds: Bool) -> Bool {
189
+ inside && holds
190
+ }
191
+
184
192
  /// Whether focus came from the keyboard, as core's `:focus-visible`: not
185
193
  /// while a pointer rests on the view, and not within a press of it.
186
194
  nonisolated static func isKeyboardFocus(isHovering: Bool, sincePress: TimeInterval) -> Bool {
@@ -195,6 +203,7 @@ struct TooltipPresenter: ViewModifier {
195
203
  .simultaneousGesture(TapGesture().onEnded { pressed() })
196
204
  .onHover { inside in
197
205
  isHovering = inside
206
+ focusIsKeyboard = Self.keyboardFocusHolds(afterHover: inside, holds: focusIsKeyboard)
198
207
  update()
199
208
  }
200
209
  .onChange(of: isFocused) {
@@ -208,23 +217,20 @@ struct TooltipPresenter: ViewModifier {
208
217
  }
209
218
  .overlay(alignment: above ? .top : .bottom) {
210
219
  if isShown || isTapShown, let text {
211
- let gap = astryx.tokens.space.s1
212
- let isAbove = above
213
220
  TooltipBubble(text: text)
214
221
  .onGeometryChange(for: CGRect.self) { $0.frame(in: .global) } action: { bubbleFrame = $0 }
215
222
  .background(TooltipWindowReader { window = $0 })
216
223
  .onHover { inside in
217
224
  isHoveringBubble = inside
225
+ focusIsKeyboard = Self.keyboardFocusHolds(afterHover: inside, holds: focusIsKeyboard)
218
226
  update()
219
227
  }
220
- .offset(x: sideways)
221
228
  .background(TooltipEscape(hide: hideAll))
222
229
  .background(
223
230
  TooltipOutsideTap(isActive: isTapShown, viewFrame: viewFrame, bubbleFrame: bubbleFrame) {
224
231
  isTapShown = false
225
232
  })
226
- // `space.s1` between the bubble and the view, above or below it.
227
- .alignmentGuide(isAbove ? .top : .bottom) { d in isAbove ? d[.bottom] + gap : d[.top] - gap }
233
+ .modifier(TooltipPlacement(isAbove: above, gap: astryx.tokens.space.s1, slide: sideways))
228
234
  }
229
235
  }
230
236
  .zIndex(isShown || isTapShown ? 1 : 0)
@@ -340,6 +346,22 @@ private struct TooltipWindowProbe: View {
340
346
  }
341
347
  #endif
342
348
 
349
+ /// Places the bubble `gap` above the view it decorates, or below it, slid
350
+ /// sideways by `slide`. The bubble hangs from a zero-height frame on the
351
+ /// view's top or bottom edge, so it needs no measured height and sits in
352
+ /// place on its first frame. Used inside an overlay aligned to that edge.
353
+ struct TooltipPlacement: ViewModifier {
354
+ let isAbove: Bool
355
+ let gap: CGFloat
356
+ let slide: CGFloat
357
+
358
+ func body(content: Content) -> some View {
359
+ content
360
+ .frame(height: 0, alignment: isAbove ? .bottom : .top)
361
+ .offset(x: slide, y: isAbove ? -gap : gap)
362
+ }
363
+ }
364
+
343
365
  /// Escape hides a shown bubble wherever focus is, as core's top-most layer
344
366
  /// takes the press: a hidden button bound to Escape lives while the bubble
345
367
  /// shows.
@@ -16,14 +16,6 @@ public struct SwitchStatus: Equatable, Codable, Sendable {
16
16
  self.message = message
17
17
  }
18
18
  }
19
- public enum SwitchLabelPosition: String, CaseIterable, Codable, Sendable {
20
- case start = "start"
21
- case end = "end"
22
- }
23
- public enum SwitchLabelSpacing: String, CaseIterable, Codable, Sendable {
24
- case hug = "hug"
25
- case spread = "spread"
26
- }
27
19
  #if os(iOS)
28
20
  public struct SwitchProps {
29
21
  /// Base props attach to this part on every platform.
@@ -42,9 +34,7 @@ public struct SwitchProps {
42
34
  public var isRequired: Bool?
43
35
  public var status: SwitchStatus?
44
36
  public var labelTooltip: String?
45
- public var labelPosition: SwitchLabelPosition?
46
- public var labelSpacing: SwitchLabelSpacing?
47
- public init(label: String, value: Bool, onChange: ((Bool) -> Void)? = nil, isLoading: Bool? = nil, isLabelHidden: Bool? = nil, description: String? = nil, isDisabled: Bool? = nil, size: SwitchSize? = nil, disabledMessage: String? = nil, isOptional: Bool? = nil, isRequired: Bool? = nil, status: SwitchStatus? = nil, labelTooltip: String? = nil, labelPosition: SwitchLabelPosition? = nil, labelSpacing: SwitchLabelSpacing? = nil, base: AstryxBaseProps = AstryxBaseProps()) {
37
+ public init(label: String, value: Bool, onChange: ((Bool) -> Void)? = nil, isLoading: Bool? = nil, isLabelHidden: Bool? = nil, description: String? = nil, isDisabled: Bool? = nil, size: SwitchSize? = nil, disabledMessage: String? = nil, isOptional: Bool? = nil, isRequired: Bool? = nil, status: SwitchStatus? = nil, labelTooltip: String? = nil, base: AstryxBaseProps = AstryxBaseProps()) {
48
38
  self.label = label
49
39
  self.value = value
50
40
  self.onChange = onChange
@@ -58,8 +48,6 @@ public struct SwitchProps {
58
48
  self.isRequired = isRequired
59
49
  self.status = status
60
50
  self.labelTooltip = labelTooltip
61
- self.labelPosition = labelPosition
62
- self.labelSpacing = labelSpacing
63
51
  self.base = base
64
52
  }
65
53
  }
@@ -77,8 +65,6 @@ public struct SwitchNode: Decodable, Equatable, Sendable {
77
65
  public var isRequired: Bool?
78
66
  public var status: SwitchStatus?
79
67
  public var labelTooltip: String?
80
- public var labelPosition: SwitchLabelPosition?
81
- public var labelSpacing: SwitchLabelSpacing?
82
68
  }
83
69
  public let key: String
84
70
  public let base: AstryxBaseProps?
@@ -105,8 +91,6 @@ public struct SwitchNode: Decodable, Equatable, Sendable {
105
91
  isRequired: props.isRequired,
106
92
  status: props.status,
107
93
  labelTooltip: props.labelTooltip,
108
- labelPosition: props.labelPosition,
109
- labelSpacing: props.labelSpacing,
110
94
  base: base ?? AstryxBaseProps()
111
95
  )
112
96
  }
@@ -130,9 +114,7 @@ public struct SwitchProps {
130
114
  public var isRequired: Bool?
131
115
  public var status: SwitchStatus?
132
116
  public var labelTooltip: String?
133
- public var labelPosition: SwitchLabelPosition?
134
- public var labelSpacing: SwitchLabelSpacing?
135
- public init(label: String, value: Bool, onChange: ((Bool) -> Void)? = nil, isLoading: Bool? = nil, isLabelHidden: Bool? = nil, description: String? = nil, isDisabled: Bool? = nil, size: SwitchSize? = nil, disabledMessage: String? = nil, isOptional: Bool? = nil, isRequired: Bool? = nil, status: SwitchStatus? = nil, labelTooltip: String? = nil, labelPosition: SwitchLabelPosition? = nil, labelSpacing: SwitchLabelSpacing? = nil, base: AstryxBaseProps = AstryxBaseProps()) {
117
+ public init(label: String, value: Bool, onChange: ((Bool) -> Void)? = nil, isLoading: Bool? = nil, isLabelHidden: Bool? = nil, description: String? = nil, isDisabled: Bool? = nil, size: SwitchSize? = nil, disabledMessage: String? = nil, isOptional: Bool? = nil, isRequired: Bool? = nil, status: SwitchStatus? = nil, labelTooltip: String? = nil, base: AstryxBaseProps = AstryxBaseProps()) {
136
118
  self.label = label
137
119
  self.value = value
138
120
  self.onChange = onChange
@@ -146,8 +128,6 @@ public struct SwitchProps {
146
128
  self.isRequired = isRequired
147
129
  self.status = status
148
130
  self.labelTooltip = labelTooltip
149
- self.labelPosition = labelPosition
150
- self.labelSpacing = labelSpacing
151
131
  self.base = base
152
132
  }
153
133
  }
@@ -165,8 +145,6 @@ public struct SwitchNode: Decodable, Equatable, Sendable {
165
145
  public var isRequired: Bool?
166
146
  public var status: SwitchStatus?
167
147
  public var labelTooltip: String?
168
- public var labelPosition: SwitchLabelPosition?
169
- public var labelSpacing: SwitchLabelSpacing?
170
148
  }
171
149
  public let key: String
172
150
  public let base: AstryxBaseProps?
@@ -193,8 +171,6 @@ public struct SwitchNode: Decodable, Equatable, Sendable {
193
171
  isRequired: props.isRequired,
194
172
  status: props.status,
195
173
  labelTooltip: props.labelTooltip,
196
- labelPosition: props.labelPosition,
197
- labelSpacing: props.labelSpacing,
198
174
  base: base ?? AstryxBaseProps()
199
175
  )
200
176
  }
@@ -67,8 +67,18 @@ import Testing
67
67
 
68
68
  @MainActor
69
69
  @Test func aTransparentCardDrawsNoGroundAndNoBorder() {
70
- let card = Pixels(Astryx.Card(variant: .transparent) { Color.clear.frame(width: 40, height: 40) }.frame(width: 80))
71
- #expect(card.contains { $0[3] > 0 } == false)
70
+ // An opaque marker beside the card keeps the rendered image from being
71
+ // empty, which the iOS Simulator's image renderer does not draw reliably;
72
+ // only the card's 80 points are checked.
73
+ let view = SwiftUI.HStack(spacing: 0) {
74
+ Astryx.Card(variant: .transparent) { Color.clear.frame(width: 40, height: 40) }.frame(width: 80)
75
+ Color.black.frame(width: 8)
76
+ }
77
+ let pixels = Pixels(view.fixedSize())
78
+ #expect(close(pixels.at(pixels.width - 4, pixels.height / 2), [0, 0, 0, 255]))
79
+ for y in 0..<pixels.height {
80
+ for x in 0..<80 { #expect(pixels.at(x, y)[3] == 0, "pixel \(x),\(y)") }
81
+ }
72
82
  }
73
83
 
74
84
  @MainActor
@@ -168,3 +168,53 @@ import Testing
168
168
  #expect(P.showsBubble(hasText: true, isHovering: false, isHoveringBubble: false, isFocused: true, focusIsKeyboard: true, focus: .tabStop))
169
169
  }
170
170
 
171
+ @Test func aPointerLeavingLetsAKeyboardFocusedBubbleHide() {
172
+ typealias P = TooltipPresenter
173
+ #expect(!P.keyboardFocusHolds(afterHover: false, holds: true))
174
+ #expect(P.keyboardFocusHolds(afterHover: true, holds: true))
175
+ #expect(!P.keyboardFocusHolds(afterHover: true, holds: false))
176
+ }
177
+
178
+ /// Rows the bubble's dark fill covers, and rows the view shows, in a render
179
+ /// of a 36-point view with a placed bubble.
180
+ @MainActor
181
+ private func placedRows(isAbove: Bool, text: String = "Ada Lovelace") -> (bubble: ClosedRange<Int>?, view: ClosedRange<Int>) {
182
+ let theme = Theme.default.light
183
+ let probe = ZStack(alignment: .topLeading) {
184
+ Color.white
185
+ Color.blue.frame(width: 36, height: 36)
186
+ .overlay(alignment: isAbove ? .top : .bottom) {
187
+ TooltipBubble(text: text).modifier(TooltipPlacement(isAbove: isAbove, gap: 4, slide: 0))
188
+ }
189
+ .offset(x: 150, y: 100)
190
+ }
191
+ .frame(width: 400, height: 240)
192
+ let pixels = Pixels(probe.astryxTheme())
193
+ let ink = rgba(theme.color.textPrimary)
194
+ func rows(_ match: ([Int]) -> Bool) -> [Int] {
195
+ (0..<pixels.height).filter { y in (0..<pixels.width).contains { x in match(pixels.at(x, y)) } }
196
+ }
197
+ let dark = rows { close($0, ink, within: 12) }
198
+ let blue = rows { $0[2] > 200 && $0[0] < 60 && $0[1] < 140 }
199
+ return (dark.isEmpty ? nil : dark.first!...dark.last!, blue.first!...blue.last!)
200
+ }
201
+
202
+ // INV1: the bubble sits `gap` above the view, or below it, and never on it.
203
+ @MainActor
204
+ @Test func theBubbleSitsAboveOrBelowTheViewNotOnIt() throws {
205
+ let above = placedRows(isAbove: true)
206
+ let bubble = try #require(above.bubble)
207
+ #expect(above.view == 100...135)
208
+ #expect(bubble.upperBound == 95)
209
+ #expect(bubble.count >= 20)
210
+ let below = placedRows(isAbove: false)
211
+ let under = try #require(below.bubble)
212
+ #expect(below.view == 100...135)
213
+ #expect(under.lowerBound == 140)
214
+ // Long words wrap upward from the same edge.
215
+ let long = placedRows(isAbove: true, text: String(repeating: "A long tooltip ", count: 6))
216
+ let wrapped = try #require(long.bubble)
217
+ #expect(wrapped.upperBound == 95)
218
+ #expect(wrapped.count > bubble.count)
219
+ }
220
+
@@ -1 +1 @@
1
- {"version":3,"file":"Switch.d.ts","sourceRoot":"","sources":["../../src/components/Switch.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAC,eAAe,EAAC,MAAM,iCAAiC,CAAC;AAErE,eAAO,MAAM,aAAa,EAAE,eAI3B,CAAC"}
1
+ {"version":3,"file":"Switch.d.ts","sourceRoot":"","sources":["../../src/components/Switch.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAC,eAAe,EAAC,MAAM,iCAAiC,CAAC;AAErE,eAAO,MAAM,aAAa,EAAE,eAiB3B,CAAC"}
@@ -3,4 +3,17 @@ export const switchControl = {
3
3
  name: 'Switch',
4
4
  // The web Switch forwards base props to its root wrapper.
5
5
  baseTarget: 'root',
6
+ // Apple switch rows follow the system toggle layout, label leading and
7
+ // system spacing (Swift component API A2); Android and Windows keep both
8
+ // props until a ruling covers them.
9
+ onlyOn: {
10
+ labelPosition: {
11
+ platforms: ['android', 'windows'],
12
+ reason: 'Apple rows follow the system toggle layout (component API A2)',
13
+ },
14
+ labelSpacing: {
15
+ platforms: ['android', 'windows'],
16
+ reason: "Apple rows use the system's spacing (component API A2)",
17
+ },
18
+ },
6
19
  };
@@ -74,6 +74,16 @@ export interface NativeAdditions {
74
74
  * reason, such as a web presentation heuristic a native platform replaces.
75
75
  */
76
76
  readonly webOnly?: Readonly<Record<string, string>>;
77
+ /**
78
+ * Portable core-doc props that only some native platforms carry, with those
79
+ * platforms and the reason (AST-082 FR3): the prop leaves the core and joins
80
+ * each listed platform's contract unchanged, so a platform a ruling covers
81
+ * drops it while the others keep it.
82
+ */
83
+ readonly onlyOn?: Readonly<Record<string, {
84
+ readonly platforms: readonly NativePlatform[];
85
+ readonly reason: string;
86
+ }>>;
77
87
  }
78
88
  export declare function fromComponentDoc(doc: ComponentDocLike, additions: NativeAdditions): ComponentContract;
79
89
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"fromComponentDoc.d.ts","sourceRoot":"","sources":["../../src/contract/fromComponentDoc.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EACV,UAAU,EACV,iBAAiB,EACjB,OAAO,EAIR,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,EAAC,cAAc,EAAC,MAAM,iBAAiB,CAAC;AAEpD,UAAU,OAAO;IACf,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC;IACx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,CAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,CACjD,CAAC;IACF;;;OAGG;IACH,QAAQ,CAAC,OAAO,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IACpD;;;;;OAKG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,QAAQ,CACxB,MAAM,CACJ,MAAM,EACN;QAAC,QAAQ,CAAC,SAAS,EAAE,SAAS,cAAc,EAAE,CAAC;QAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;KAAC,CACzE,CACF,CAAC;CACH;AA0BD,wBAAgB,gBAAgB,CAC9B,GAAG,EAAE,gBAAgB,EACrB,SAAS,EAAE,eAAe,GACzB,iBAAiB,CAsJnB"}
@@ -127,12 +127,26 @@ export function fromComponentDoc(doc, additions) {
127
127
  ...describe(prop),
128
128
  };
129
129
  }
130
+ const platforms = Object.fromEntries(Object.entries(additions.platforms ?? {}).map(([p, props]) => [
131
+ p,
132
+ { ...props },
133
+ ]));
134
+ for (const [name, { platforms: only }] of Object.entries(additions.onlyOn ?? {})) {
135
+ const spec = core[name];
136
+ if (!spec) {
137
+ throw new Error(`${additions.name}: onlyOn names "${name}", which is not a portable core prop`);
138
+ }
139
+ delete core[name];
140
+ for (const platform of only) {
141
+ platforms[platform] = { ...platforms[platform], [name]: spec };
142
+ }
143
+ }
130
144
  return {
131
145
  name: additions.name,
132
146
  baseTarget: additions.baseTarget,
133
147
  types,
134
148
  core,
135
- platforms: additions.platforms ?? {},
149
+ platforms,
136
150
  webOnly,
137
151
  projections,
138
152
  sameMeaning: Object.keys(additions.sameMeaning ?? {}).filter(name => name in core),
@@ -31,7 +31,10 @@ export interface SelectorProps extends SelectorCoreProps {
31
31
  }
32
32
  export declare function Selector(props: SelectorProps): unknown;
33
33
  /** Switch props: core contract plus the android contract. */
34
- export interface SwitchProps extends SwitchCoreProps {}
34
+ export interface SwitchProps extends SwitchCoreProps {
35
+ labelPosition?: 'start' | 'end';
36
+ labelSpacing?: 'hug' | 'spread';
37
+ }
35
38
  export declare function Switch(props: SwitchProps): unknown;
36
39
  /** Text props: core contract plus the android contract. */
37
40
  export interface TextProps extends TextCoreProps {}
@@ -137,8 +137,6 @@ export interface SwitchCoreProps extends AstryxSharedBaseProps {
137
137
  isRequired?: boolean;
138
138
  status?: {type: 'warning' | 'error' | 'success'; message?: string;};
139
139
  labelTooltip?: string;
140
- labelPosition?: 'start' | 'end';
141
- labelSpacing?: 'hug' | 'spread';
142
140
  }
143
141
  /** Core contract. Base props attach to the root. */
144
142
  export interface TextCoreProps extends AstryxSharedBaseProps {
@@ -114,7 +114,7 @@ export interface SwitchNode {
114
114
  component: 'Switch';
115
115
  key: string;
116
116
  base?: AstryxSharedBaseProps;
117
- props: {label: string; value: boolean; isLoading?: boolean; isLabelHidden?: boolean; description?: string; isDisabled?: boolean; size?: 'sm' | 'md'; disabledMessage?: string; isOptional?: boolean; isRequired?: boolean; status?: {type: 'warning' | 'error' | 'success'; message?: string;}; labelTooltip?: string; labelPosition?: 'start' | 'end'; labelSpacing?: 'hug' | 'spread';};
117
+ props: {label: string; value: boolean; isLoading?: boolean; isLabelHidden?: boolean; description?: string; isDisabled?: boolean; size?: 'sm' | 'md'; disabledMessage?: string; isOptional?: boolean; isRequired?: boolean; status?: {type: 'warning' | 'error' | 'success'; message?: string;}; labelTooltip?: string;};
118
118
  /** The callbacks the core listens to. */
119
119
  events?: ReadonlyArray<'onChange'>;
120
120
  }
@@ -114,7 +114,7 @@ export interface SwitchNode {
114
114
  component: 'Switch';
115
115
  key: string;
116
116
  base?: AstryxSharedBaseProps;
117
- props: {label: string; value: boolean; isLoading?: boolean; isLabelHidden?: boolean; description?: string; isDisabled?: boolean; size?: 'sm' | 'md'; disabledMessage?: string; isOptional?: boolean; isRequired?: boolean; status?: {type: 'warning' | 'error' | 'success'; message?: string;}; labelTooltip?: string; labelPosition?: 'start' | 'end'; labelSpacing?: 'hug' | 'spread';};
117
+ props: {label: string; value: boolean; isLoading?: boolean; isLabelHidden?: boolean; description?: string; isDisabled?: boolean; size?: 'sm' | 'md'; disabledMessage?: string; isOptional?: boolean; isRequired?: boolean; status?: {type: 'warning' | 'error' | 'success'; message?: string;}; labelTooltip?: string;};
118
118
  /** The callbacks the core listens to. */
119
119
  events?: ReadonlyArray<'onChange'>;
120
120
  }
@@ -112,7 +112,7 @@ export interface SwitchNode {
112
112
  component: 'Switch';
113
113
  key: string;
114
114
  base?: AstryxSharedBaseProps;
115
- props: {label: string; value: boolean; isLoading?: boolean; isLabelHidden?: boolean; description?: string; isDisabled?: boolean; size?: 'sm' | 'md'; disabledMessage?: string; isOptional?: boolean; isRequired?: boolean; status?: {type: 'warning' | 'error' | 'success'; message?: string;}; labelTooltip?: string; labelPosition?: 'start' | 'end'; labelSpacing?: 'hug' | 'spread';};
115
+ props: {label: string; value: boolean; isLoading?: boolean; isLabelHidden?: boolean; description?: string; isDisabled?: boolean; size?: 'sm' | 'md'; disabledMessage?: string; isOptional?: boolean; isRequired?: boolean; status?: {type: 'warning' | 'error' | 'success'; message?: string;}; labelTooltip?: string;};
116
116
  /** The callbacks the core listens to. */
117
117
  events?: ReadonlyArray<'onChange'>;
118
118
  }
@@ -29,7 +29,10 @@ export declare function ProgressBar(props: ProgressBarProps): unknown;
29
29
  export interface SelectorProps extends SelectorCoreProps {}
30
30
  export declare function Selector(props: SelectorProps): unknown;
31
31
  /** Switch props: core contract plus the windows contract. */
32
- export interface SwitchProps extends SwitchCoreProps {}
32
+ export interface SwitchProps extends SwitchCoreProps {
33
+ labelPosition?: 'start' | 'end';
34
+ labelSpacing?: 'hug' | 'spread';
35
+ }
33
36
  export declare function Switch(props: SwitchProps): unknown;
34
37
  /** Text props: core contract plus the windows contract. */
35
38
  export interface TextProps extends TextCoreProps {}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astryxdesign/native",
3
- "version": "0.7.5-canary.8be99c4",
3
+ "version": "0.7.5-canary.8c3f3be",
4
4
  "description": "Experimental native platforms for Astryx (iOS, Android, macOS, Windows) — published to npm only under the @canary dist-tag; never released as a stable (latest) version.",
5
5
  "author": "Meta Open Source",
6
6
  "license": "MIT",
@@ -70,10 +70,10 @@
70
70
  }
71
71
  },
72
72
  "peerDependencies": {
73
- "@astryxdesign/core": "0.7.5-canary.8be99c4"
73
+ "@astryxdesign/core": "0.7.5-canary.8c3f3be"
74
74
  },
75
75
  "devDependencies": {
76
- "@astryxdesign/core": "0.7.5-canary.8be99c4"
76
+ "@astryxdesign/core": "0.7.5-canary.8c3f3be"
77
77
  },
78
78
  "scripts": {
79
79
  "build": "node ../../scripts/clean-dist.mjs && tsc --project tsconfig.build.json && node scripts/generate.mjs --types",
@@ -14,4 +14,17 @@ export const switchControl: NativeAdditions = {
14
14
  name: 'Switch',
15
15
  // The web Switch forwards base props to its root wrapper.
16
16
  baseTarget: 'root',
17
+ // Apple switch rows follow the system toggle layout, label leading and
18
+ // system spacing (Swift component API A2); Android and Windows keep both
19
+ // props until a ruling covers them.
20
+ onlyOn: {
21
+ labelPosition: {
22
+ platforms: ['android', 'windows'],
23
+ reason: 'Apple rows follow the system toggle layout (component API A2)',
24
+ },
25
+ labelSpacing: {
26
+ platforms: ['android', 'windows'],
27
+ reason: "Apple rows use the system's spacing (component API A2)",
28
+ },
29
+ },
17
30
  };
@@ -52,6 +52,20 @@ describe('native contracts', () => {
52
52
  expect(selector!.core).not.toHaveProperty('controlXstyle');
53
53
  });
54
54
 
55
+ it('moves a prop only some native platforms carry out of the core and onto those platforms', async () => {
56
+ const {contracts} = await buildContracts(loadCoreDoc);
57
+ const switchContract = contracts.find(
58
+ contract => contract.name === 'Switch',
59
+ )!;
60
+ for (const name of ['labelPosition', 'labelSpacing']) {
61
+ expect(switchContract.core).not.toHaveProperty(name);
62
+ expect(switchContract.platforms.android).toHaveProperty(name);
63
+ expect(switchContract.platforms.windows).toHaveProperty(name);
64
+ expect(switchContract.platforms.ios ?? {}).not.toHaveProperty(name);
65
+ expect(switchContract.platforms.macos ?? {}).not.toHaveProperty(name);
66
+ }
67
+ });
68
+
55
69
  it('keeps value callbacks, typed text slots, and number sets in the core', async () => {
56
70
  const {contracts} = await buildContracts(loadCoreDoc);
57
71
  const byName = new Map(
@@ -98,6 +98,18 @@ export interface NativeAdditions {
98
98
  * reason, such as a web presentation heuristic a native platform replaces.
99
99
  */
100
100
  readonly webOnly?: Readonly<Record<string, string>>;
101
+ /**
102
+ * Portable core-doc props that only some native platforms carry, with those
103
+ * platforms and the reason (AST-082 FR3): the prop leaves the core and joins
104
+ * each listed platform's contract unchanged, so a platform a ruling covers
105
+ * drops it while the others keep it.
106
+ */
107
+ readonly onlyOn?: Readonly<
108
+ Record<
109
+ string,
110
+ {readonly platforms: readonly NativePlatform[]; readonly reason: string}
111
+ >
112
+ >;
101
113
  }
102
114
 
103
115
  /** The documented props of the component the additions name. */
@@ -243,12 +255,34 @@ export function fromComponentDoc(
243
255
  };
244
256
  }
245
257
 
258
+ const platforms: Partial<Record<NativePlatform, Record<string, PropSpec>>> =
259
+ Object.fromEntries(
260
+ Object.entries(additions.platforms ?? {}).map(([p, props]) => [
261
+ p,
262
+ {...props},
263
+ ]),
264
+ );
265
+ for (const [name, {platforms: only}] of Object.entries(
266
+ additions.onlyOn ?? {},
267
+ )) {
268
+ const spec = core[name];
269
+ if (!spec) {
270
+ throw new Error(
271
+ `${additions.name}: onlyOn names "${name}", which is not a portable core prop`,
272
+ );
273
+ }
274
+ delete core[name];
275
+ for (const platform of only) {
276
+ platforms[platform] = {...platforms[platform], [name]: spec};
277
+ }
278
+ }
279
+
246
280
  return {
247
281
  name: additions.name,
248
282
  baseTarget: additions.baseTarget,
249
283
  types,
250
284
  core,
251
- platforms: additions.platforms ?? {},
285
+ platforms,
252
286
  webOnly,
253
287
  projections,
254
288
  sameMeaning: Object.keys(additions.sameMeaning ?? {}).filter(