@legendapp/spark 0.0.4 → 0.0.5

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 (74) hide show
  1. package/package.json +3 -3
  2. package/skills/spark/UPGRADING.md +58 -0
  3. package/skills/spark/storage-settings.md +2 -28
  4. package/skills/spark/ui.md +27 -1
  5. package/vendor/node_modules/@legendapp/spark-ai/package.json +3 -3
  6. package/vendor/node_modules/@legendapp/spark-audio/package.json +2 -2
  7. package/vendor/node_modules/@legendapp/spark-auth-session/package.json +3 -3
  8. package/vendor/node_modules/@legendapp/spark-cli/dist/build.js +43 -24
  9. package/vendor/node_modules/@legendapp/spark-cli/dist/migrations.cjs +3 -0
  10. package/vendor/node_modules/@legendapp/spark-cli/dist/package.js +4 -8
  11. package/vendor/node_modules/@legendapp/spark-cli/dist/project.js +1 -1
  12. package/vendor/node_modules/@legendapp/spark-cli/dist/publish-directory.js +32 -0
  13. package/vendor/node_modules/@legendapp/spark-cli/dist/release-app.js +139 -0
  14. package/vendor/node_modules/@legendapp/spark-cli/dist/release.json +21 -21
  15. package/vendor/node_modules/@legendapp/spark-cli/dist/signing.js +61 -41
  16. package/vendor/node_modules/@legendapp/spark-cli/package.json +4 -4
  17. package/vendor/node_modules/@legendapp/spark-cli/templates/blank-typescript/package.json +2 -2
  18. package/vendor/node_modules/@legendapp/spark-cli/templates/universal/package.json +2 -2
  19. package/vendor/node_modules/@legendapp/spark-cli/templates/windows/package.json +2 -2
  20. package/vendor/node_modules/@legendapp/spark-clipboard/package.json +2 -2
  21. package/vendor/node_modules/@legendapp/spark-codex/package.json +2 -2
  22. package/vendor/node_modules/@legendapp/spark-commands/package.json +5 -5
  23. package/vendor/node_modules/@legendapp/spark-context-menu/package.json +2 -2
  24. package/vendor/node_modules/@legendapp/spark-desktop-app/macos/SparkTestDriver.h +2 -0
  25. package/vendor/node_modules/@legendapp/spark-desktop-app/macos/SparkTestDriver.mm +1 -0
  26. package/vendor/node_modules/@legendapp/spark-desktop-app/package.json +1 -1
  27. package/vendor/node_modules/@legendapp/spark-desktop-config/app.plugin.cjs +1 -0
  28. package/vendor/node_modules/@legendapp/spark-desktop-config/package.json +3 -3
  29. package/vendor/node_modules/@legendapp/spark-desktop-config/rpaths.cjs +20 -0
  30. package/vendor/node_modules/@legendapp/spark-desktop-config/rpaths.d.cts +1 -0
  31. package/vendor/node_modules/@legendapp/spark-desktop-host/AppDelegate.mm +16 -5
  32. package/vendor/node_modules/@legendapp/spark-desktop-host/package.json +2 -2
  33. package/vendor/node_modules/@legendapp/spark-desktop-links/package.json +2 -2
  34. package/vendor/node_modules/@legendapp/spark-desktop-shortcuts/package.json +2 -2
  35. package/vendor/node_modules/@legendapp/spark-desktop-windows/package.json +3 -3
  36. package/vendor/node_modules/@legendapp/spark-documents/package.json +7 -7
  37. package/vendor/node_modules/@legendapp/spark-drag-drop/package.json +2 -2
  38. package/vendor/node_modules/@legendapp/spark-expo-compat/package.json +4 -4
  39. package/vendor/node_modules/@legendapp/spark-file-dialog/package.json +2 -2
  40. package/vendor/node_modules/@legendapp/spark-file-system/package.json +2 -2
  41. package/vendor/node_modules/@legendapp/spark-global-shortcuts/package.json +2 -2
  42. package/vendor/node_modules/@legendapp/spark-html/package.json +2 -2
  43. package/vendor/node_modules/@legendapp/spark-markdown/package.json +2 -2
  44. package/vendor/node_modules/@legendapp/spark-message-dialog/package.json +2 -2
  45. package/vendor/node_modules/@legendapp/spark-native-menu/package.json +2 -2
  46. package/vendor/node_modules/@legendapp/spark-notifications/package.json +2 -2
  47. package/vendor/node_modules/@legendapp/spark-processes/package.json +2 -2
  48. package/vendor/node_modules/@legendapp/spark-rich-text/package.json +2 -2
  49. package/vendor/node_modules/@legendapp/spark-secure-storage/package.json +2 -2
  50. package/vendor/node_modules/@legendapp/spark-settings/package.json +3 -3
  51. package/vendor/node_modules/@legendapp/spark-settings-ui/package.json +4 -4
  52. package/vendor/node_modules/@legendapp/spark-settings-ui/src/index.tsx +122 -334
  53. package/vendor/node_modules/@legendapp/spark-settings-ui/src/rows.tsx +183 -0
  54. package/vendor/node_modules/@legendapp/spark-sqlite/package.json +3 -3
  55. package/vendor/node_modules/@legendapp/spark-system/package.json +2 -2
  56. package/vendor/node_modules/@legendapp/spark-tray/package.json +2 -2
  57. package/vendor/node_modules/@legendapp/spark-ui/macos/native-select/RNNativeSegmentedControl.mm +2 -0
  58. package/vendor/node_modules/@legendapp/spark-ui/macos/native-select/RNNativeSelect.mm +17 -1
  59. package/vendor/node_modules/@legendapp/spark-ui/macos/sidebar/RNSidebar.mm +20 -0
  60. package/vendor/node_modules/@legendapp/spark-ui/package.json +2 -2
  61. package/vendor/node_modules/@legendapp/spark-ui/src/availability.ts +2 -1
  62. package/vendor/node_modules/@legendapp/spark-ui/src/control.ts +1 -1
  63. package/vendor/node_modules/@legendapp/spark-ui/src/desktop.tsx +10 -8
  64. package/vendor/node_modules/@legendapp/spark-ui/src/index.android.tsx +7 -6
  65. package/vendor/node_modules/@legendapp/spark-ui/src/index.ios.tsx +10 -9
  66. package/vendor/node_modules/@legendapp/spark-ui/src/index.web.tsx +6 -4
  67. package/vendor/node_modules/@legendapp/spark-ui/src/native-select/NativeSelectNativeComponent.ts +1 -0
  68. package/vendor/node_modules/@legendapp/spark-ui/src/select.ts +4 -0
  69. package/vendor/node_modules/@legendapp/spark-ui/src/switch.tsx +13 -0
  70. package/vendor/node_modules/@legendapp/spark-ui/src/types.ts +16 -4
  71. package/vendor/node_modules/@legendapp/spark-updates/package.json +2 -2
  72. package/vendor/node_modules/@legendapp/spark-webview/package.json +2 -2
  73. package/vendor/node_modules/@legendapp/spark-window-options/package.json +1 -1
  74. /package/{settings-window.ts → ui-settings.ts} +0 -0
@@ -0,0 +1,183 @@
1
+ import { SegmentedControl, Select, Switch, type SelectOption } from "@legendapp/spark-ui";
2
+ import { selectionIndex } from "@legendapp/spark-ui/src/select";
3
+ import { SFSymbol } from "@legendapp/spark-ui/src/sf-symbol";
4
+ import { SparkError } from "@legendapp/spark-desktop-app/src/contracts";
5
+ import { Children, Fragment, useState, type ReactNode } from "react";
6
+ import * as RN from "react-native";
7
+ import type { ColorValue, ImageSourcePropType, NativeSyntheticEvent } from "react-native";
8
+
9
+ const { Image, Platform, PlatformColor, Pressable, StyleSheet, Text, View } = RN;
10
+
11
+ // The macOS type entry also declares globals. Keep the additions used here local.
12
+ const macOS = RN as typeof RN & {
13
+ DynamicColorMacOS(colors: { light: string; dark: string }): ColorValue;
14
+ };
15
+ type KeyEvent = NativeSyntheticEvent<{
16
+ key: string;
17
+ altKey: boolean;
18
+ ctrlKey: boolean;
19
+ metaKey: boolean;
20
+ shiftKey: boolean;
21
+ }>;
22
+ const cardColor = Platform.OS === "macos" ? macOS.DynamicColorMacOS({
23
+ light: "rgba(0,0,0,0.03)",
24
+ dark: "rgba(255,255,255,0.025)",
25
+ }) : undefined;
26
+
27
+ interface RowText {
28
+ label: string;
29
+ description?: string;
30
+ info?: string;
31
+ }
32
+ export interface SettingsSectionProps {
33
+ title?: string;
34
+ children: ReactNode;
35
+ }
36
+ export interface SettingsRowProps extends RowText {
37
+ children?: ReactNode;
38
+ }
39
+ export interface SettingsSwitchRowProps extends RowText {
40
+ value: boolean;
41
+ onValueChange: (value: boolean) => void;
42
+ disabled?: boolean;
43
+ }
44
+ export interface SettingsSelectRowProps extends RowText {
45
+ disabled?: boolean;
46
+ options: readonly SelectOption[];
47
+ value: string;
48
+ onValueChange: (value: string) => void;
49
+ }
50
+ export type SettingsSegmentedRowProps = SettingsSelectRowProps;
51
+ export interface SettingsImageChoiceOption extends SelectOption {
52
+ image: ImageSourcePropType;
53
+ }
54
+ export interface SettingsImageChoiceRowProps extends SettingsSelectRowProps {
55
+ options: readonly SettingsImageChoiceOption[];
56
+ }
57
+
58
+ export function SettingsSection({ title, children }: SettingsSectionProps) {
59
+ if (Platform.OS !== "macos") throw new SparkError("E_UNSUPPORTED_PLATFORM", "Settings sections require macOS");
60
+ return (
61
+ <View style={styles.section}>
62
+ {title ? <Text accessibilityRole="header" style={[styles.heading, { color: PlatformColor("labelColor") }]}>{title}</Text> : null}
63
+ <View style={styles.card}>
64
+ {Children.toArray(children).map((child, index) => (
65
+ <Fragment key={typeof child === "object" && "key" in child ? child.key : index}>
66
+ {index > 0 ? <View style={[styles.divider, { backgroundColor: PlatformColor("separatorColor") }]} /> : null}
67
+ {child}
68
+ </Fragment>
69
+ ))}
70
+ </View>
71
+ </View>
72
+ );
73
+ }
74
+
75
+ function Row({ label, description, info, children, disabled, imageChoice }: SettingsRowProps & { disabled?: boolean; imageChoice?: boolean }) {
76
+ if (Platform.OS !== "macos") throw new SparkError("E_UNSUPPORTED_PLATFORM", "Settings rows require macOS");
77
+ return (
78
+ <View style={[styles.row, imageChoice && styles.imageRow]}>
79
+ <View style={[styles.rowText, imageChoice && styles.imageRowText]}>
80
+ <View style={styles.labelLine}>
81
+ <Text style={[styles.label, { color: PlatformColor(disabled ? "tertiaryLabelColor" : "labelColor") }]}>{label}</Text>
82
+ {info ? <View accessible={false} {...{ tooltip: info }} style={styles.info}>
83
+ <SFSymbol accessible={false} name="info.circle" size={13} color={PlatformColor("secondaryLabelColor")} />
84
+ </View> : null}
85
+ </View>
86
+ {description ? <Text style={[styles.description, { color: PlatformColor(disabled ? "tertiaryLabelColor" : "secondaryLabelColor") }]}>{description}</Text> : null}
87
+ </View>
88
+ {children != null ? <View style={[styles.control, imageChoice && styles.imageControl]}>{children}</View> : null}
89
+ </View>
90
+ );
91
+ }
92
+
93
+ export function SettingsRow(props: SettingsRowProps) {
94
+ return <Row {...props} />;
95
+ }
96
+
97
+ function accessibility({ label, description, info }: RowText) {
98
+ return { accessibilityLabel: label, accessibilityHint: [description, info].filter(Boolean).join(" ") || undefined };
99
+ }
100
+
101
+ export function SettingsSwitchRow({ value, onValueChange, disabled, ...text }: SettingsSwitchRowProps) {
102
+ return <Row {...text} disabled={disabled}>
103
+ <Switch value={value} onValueChange={onValueChange} disabled={disabled} {...accessibility(text)} />
104
+ </Row>;
105
+ }
106
+
107
+ export function SettingsSelectRow({ value, options, onValueChange, disabled, ...text }: SettingsSelectRowProps) {
108
+ return <Row {...text} disabled={disabled}>
109
+ <Select options={options} value={value} onValueChange={onValueChange} disabled={disabled} variant="borderless" style={styles.selection} {...accessibility(text)} />
110
+ </Row>;
111
+ }
112
+
113
+ export function SettingsSegmentedRow({ value, options, onValueChange, disabled, ...text }: SettingsSegmentedRowProps) {
114
+ return <Row {...text} disabled={disabled}>
115
+ <SegmentedControl options={options} value={value} onValueChange={onValueChange} disabled={disabled} style={styles.selection} {...accessibility(text)} />
116
+ </Row>;
117
+ }
118
+
119
+ const choiceKeys = [{ key: "ArrowLeft" }, { key: "ArrowRight" }];
120
+
121
+ export function SettingsImageChoiceRow({ options, value, onValueChange, disabled = false, ...text }: SettingsImageChoiceRowProps) {
122
+ if (!Array.isArray(options) || options.some(option => option?.image == null) || typeof onValueChange !== "function" || typeof disabled !== "boolean") {
123
+ throw new SparkError("E_INVALID_ARGUMENT", "Image choices require options with images and onValueChange");
124
+ }
125
+ const selectedIndex = selectionIndex(options.map(({ image, ...option }) => option), value);
126
+ const [focused, setFocused] = useState(false);
127
+ const accentColor = PlatformColor("controlAccentColor");
128
+ function choose(next: string) {
129
+ if (!disabled && next !== value) onValueChange(next);
130
+ }
131
+ function onKeyDown({ nativeEvent }: KeyEvent) {
132
+ const { key, altKey, ctrlKey, metaKey, shiftKey } = nativeEvent;
133
+ if (altKey || ctrlKey || metaKey || shiftKey) return;
134
+ const step = key === "ArrowLeft" ? -1 : key === "ArrowRight" ? 1 : 0;
135
+ if (step) choose(options[(selectedIndex + step + options.length) % options.length].value);
136
+ }
137
+ return (
138
+ <Row {...text} disabled={disabled} imageChoice>
139
+ <View style={styles.choices} accessibilityRole="radiogroup" accessibilityState={{ disabled }} {...accessibility(text)}
140
+ focusable={!disabled} onFocus={() => setFocused(true)} onBlur={() => setFocused(false)}
141
+ {...{ enableFocusRing: false, ...(!disabled && { onKeyDown, keyDownEvents: choiceKeys }) }}>
142
+ {options.map(option => {
143
+ const selected = option.value === value;
144
+ const captionColor = PlatformColor(disabled ? "tertiaryLabelColor" : selected ? "labelColor" : "secondaryLabelColor");
145
+ return (
146
+ <Pressable key={option.value} accessibilityRole="radio" accessibilityLabel={option.label}
147
+ accessibilityState={{ checked: selected, disabled }} focusable={false} disabled={disabled} onPress={() => choose(option.value)}
148
+ style={styles.choice}>
149
+ <View style={[styles.ring, selected && { borderColor: accentColor }, selected && focused && !disabled && { outlineColor: accentColor, outlineWidth: 1, outlineOffset: 2 }]}>
150
+ <Image accessible={false} source={option.image} resizeMode="cover"
151
+ style={[styles.image, !selected && { borderColor: PlatformColor("separatorColor"), borderWidth: StyleSheet.hairlineWidth }]} />
152
+ </View>
153
+ <Text style={[styles.caption, { color: captionColor, fontWeight: selected ? "600" : "400" }]}>{option.label}</Text>
154
+ </Pressable>
155
+ );
156
+ })}
157
+ </View>
158
+ </Row>
159
+ );
160
+ }
161
+
162
+ const styles = StyleSheet.create({
163
+ section: { gap: 6 },
164
+ heading: { fontSize: 13, lineHeight: 16, fontWeight: "600", marginHorizontal: 10 },
165
+ card: { backgroundColor: cardColor, borderRadius: 10, overflow: "hidden" },
166
+ divider: { height: StyleSheet.hairlineWidth, marginHorizontal: 10 },
167
+ row: { flexDirection: "row", alignItems: "center", minHeight: 42, padding: 10, gap: 12 },
168
+ rowText: { flex: 1, minWidth: 0, gap: 2 },
169
+ labelLine: { flexDirection: "row", alignItems: "flex-start", gap: 6 },
170
+ label: { fontSize: 13, lineHeight: 16, flexShrink: 1 },
171
+ description: { fontSize: 11, lineHeight: 14 },
172
+ info: { marginTop: 1.5 },
173
+ control: { flexShrink: 1, alignItems: "flex-end" },
174
+ selection: { height: 22, width: 190 },
175
+ imageControl: { maxWidth: "70%" },
176
+ imageRow: { alignItems: "flex-start", paddingVertical: 8 },
177
+ imageRowText: { paddingTop: 5 },
178
+ choices: { flexDirection: "row", flexWrap: "wrap", justifyContent: "flex-end", gap: 20 },
179
+ choice: { width: 76, alignItems: "center", gap: 6 },
180
+ ring: { borderWidth: 3, borderColor: "transparent", borderRadius: 10, padding: 1 },
181
+ image: { width: 68, height: 42, borderRadius: 6 },
182
+ caption: { fontSize: 11, lineHeight: 14, textAlign: "center" },
183
+ });
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@legendapp/spark-sqlite",
3
- "version": "0.0.4",
3
+ "version": "0.0.5",
4
4
  "license": "MIT",
5
5
  "main": "src/index.ts",
6
6
  "react-native": "src/index.ts",
@@ -8,8 +8,8 @@
8
8
  "src"
9
9
  ],
10
10
  "dependencies": {
11
- "@legendapp/spark-desktop-app": "0.0.4",
12
- "@legendapp/spark-file-system": "0.0.4"
11
+ "@legendapp/spark-desktop-app": "0.0.5",
12
+ "@legendapp/spark-file-system": "0.0.5"
13
13
  },
14
14
  "private": true,
15
15
  "peerDependencies": {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@legendapp/spark-system",
3
- "version": "0.0.4",
3
+ "version": "0.0.5",
4
4
  "license": "MIT",
5
5
  "main": "src/index.ts",
6
6
  "react-native": "src/index.ts",
@@ -33,7 +33,7 @@
33
33
  ]
34
34
  },
35
35
  "dependencies": {
36
- "@legendapp/spark-desktop-app": "0.0.4"
36
+ "@legendapp/spark-desktop-app": "0.0.5"
37
37
  },
38
38
  "private": true
39
39
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@legendapp/spark-tray",
3
- "version": "0.0.4",
3
+ "version": "0.0.5",
4
4
  "license": "MIT",
5
5
  "main": "src/index.ts",
6
6
  "react-native": "src/index.ts",
@@ -33,7 +33,7 @@
33
33
  ]
34
34
  },
35
35
  "dependencies": {
36
- "@legendapp/spark-desktop-app": "0.0.4"
36
+ "@legendapp/spark-desktop-app": "0.0.5"
37
37
  },
38
38
  "private": true
39
39
  }
@@ -167,6 +167,7 @@ using namespace facebook::react;
167
167
  }
168
168
  _segmentedControl.enabled = newProps.enabled;
169
169
  _segmentedControl.accessibilityLabel = [NSString stringWithUTF8String:newProps.accessibilityLabel.c_str()];
170
+ _segmentedControl.accessibilityHelp = [NSString stringWithUTF8String:newProps.accessibilityHint.c_str()];
170
171
  _segmentedControl.accessibilityIdentifier = [NSString stringWithUTF8String:newProps.testId.c_str()];
171
172
  #endif
172
173
  [super updateProps:props oldProps:oldProps];
@@ -183,6 +184,7 @@ using namespace facebook::react;
183
184
  _isUpdatingSelection = NO;
184
185
  _segmentedControl.segmentCount = 0;
185
186
  _segmentedControl.enabled = YES;
187
+ _segmentedControl.accessibilityHelp = nil;
186
188
  _segmentedControl.accessibilityLabel = nil; _segmentedControl.accessibilityIdentifier = nil;
187
189
  #endif
188
190
  }
@@ -140,11 +140,15 @@ using namespace facebook::react;
140
140
  [self selectValue:_value];
141
141
  }
142
142
 
143
+ _popUpButton.bordered = !newProps.borderless;
144
+ ((NSPopUpButtonCell *)_popUpButton.cell).arrowPosition = NSPopUpArrowAtCenter;
143
145
  _popUpButton.enabled = newProps.enabled;
144
146
  _popUpButton.accessibilityLabel = [NSString stringWithUTF8String:newProps.accessibilityLabel.c_str()];
147
+ _popUpButton.accessibilityHelp = [NSString stringWithUTF8String:newProps.accessibilityHint.c_str()];
145
148
  _popUpButton.accessibilityIdentifier = [NSString stringWithUTF8String:newProps.testId.c_str()];
146
149
  #endif
147
150
  [super updateProps:props oldProps:oldProps];
151
+ [self layoutSubviews];
148
152
  }
149
153
 
150
154
  - (void)prepareForRecycle
@@ -156,6 +160,8 @@ using namespace facebook::react;
156
160
  _isUpdatingSelection = NO;
157
161
  [_popUpButton removeAllItems];
158
162
  _popUpButton.enabled = YES;
163
+ _popUpButton.bordered = YES;
164
+ _popUpButton.accessibilityHelp = nil;
159
165
  _popUpButton.accessibilityLabel = nil; _popUpButton.accessibilityIdentifier = nil;
160
166
  #endif
161
167
  }
@@ -163,7 +169,17 @@ using namespace facebook::react;
163
169
  - (void)layoutSubviews
164
170
  {
165
171
  [super layoutSubviews];
166
- _popUpButton.frame = self.bounds;
172
+ CGRect frame = self.bounds;
173
+ #if TARGET_OS_OSX
174
+ if (!_popUpButton.isBordered) {
175
+ CGFloat width = _popUpButton.intrinsicContentSize.width;
176
+ if (width > 0 && width < NSWidth(frame)) {
177
+ if (_popUpButton.userInterfaceLayoutDirection == NSUserInterfaceLayoutDirectionLeftToRight) frame.origin.x = NSMaxX(frame) - width;
178
+ frame.size.width = width;
179
+ }
180
+ }
181
+ #endif
182
+ _popUpButton.frame = frame;
167
183
  }
168
184
 
169
185
  - (void)updateLayoutMetrics:(const LayoutMetrics &)layoutMetrics
@@ -103,10 +103,23 @@ static void RNSidebarLayoutCount(NSView *cell, NSTextField *field)
103
103
  @end
104
104
 
105
105
  @interface RNSidebarRowView : NSTableRowView
106
+ @property (nonatomic, weak) NSOutlineView *outlineView;
106
107
  @property (nonatomic, assign) BOOL contextHighlighted;
107
108
  @end
108
109
 
109
110
  @implementation RNSidebarRowView
111
+ - (BOOL)isEmphasized
112
+ {
113
+ if (self.outlineView.style == NSTableViewStyleSourceList && self.window) return self.window.isKeyWindow;
114
+ return [super isEmphasized];
115
+ }
116
+
117
+ - (void)setEmphasized:(BOOL)emphasized
118
+ {
119
+ if (self.outlineView.style == NSTableViewStyleSourceList && self.window) emphasized = self.window.isKeyWindow;
120
+ [super setEmphasized:emphasized];
121
+ }
122
+
110
123
  - (void)setContextHighlighted:(BOOL)contextHighlighted
111
124
  {
112
125
  _contextHighlighted = contextHighlighted;
@@ -822,9 +835,16 @@ static std::string RNSidebarJsonFromStrings(NSArray<NSString *> *strings)
822
835
  return node.selectable && !node.group;
823
836
  }
824
837
 
838
+ - (NSString *)outlineView:(NSOutlineView *)outlineView typeSelectStringForTableColumn:(NSTableColumn *)tableColumn item:(id)item
839
+ {
840
+ RNSidebarNode *node = item;
841
+ return node.view ? node.view.accessibilityLabel : node.title;
842
+ }
843
+
825
844
  - (NSTableRowView *)outlineView:(NSOutlineView *)outlineView rowViewForItem:(id)item
826
845
  {
827
846
  RNSidebarRowView *rowView = [RNSidebarRowView new];
847
+ rowView.outlineView = outlineView;
828
848
  RNSidebarItem *view = ((RNSidebarNode *)item).view;
829
849
  rowView.contextHighlighted = view && view == _contextHighlightedItem;
830
850
  return rowView;
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@legendapp/spark-ui",
3
- "version": "0.0.4",
3
+ "version": "0.0.5",
4
4
  "license": "MIT",
5
5
  "main": "src/index",
6
6
  "react-native": "src/index",
@@ -70,6 +70,6 @@
70
70
  "dependencies": {
71
71
  "clsx": "^2.1.1",
72
72
  "tailwind-merge": "^3.4.0",
73
- "@legendapp/spark-desktop-app": "0.0.4"
73
+ "@legendapp/spark-desktop-app": "0.0.5"
74
74
  }
75
75
  }
@@ -3,9 +3,10 @@ import { SparkError, type Availability } from "@legendapp/spark-desktop-app/src/
3
3
  import { controlKinds, unsupportedPlatform } from "./control";
4
4
  import type { ControlKind } from "./types";
5
5
  export function getControlAvailability(control: ControlKind): Availability {
6
- const names: Record<ControlKind, string> = { button: "SparkButton", "text-input": "SparkTextInput", select: Platform.OS === "windows" ? "SparkSelect" : "NativeSelect", "segmented-control": "NativeSegmentedControl", checkbox: "SparkButton", "radio-group": "SparkRadioGroup" };
7
6
  if (!controlKinds.includes(control)) throw new SparkError("E_INVALID_ARGUMENT", "Unknown control kind");
8
7
  if (Platform.OS !== "macos" && Platform.OS !== "windows") return unsupportedPlatform;
9
8
  if (Platform.OS === "windows" && (control === "segmented-control" || control === "radio-group")) return unsupportedPlatform;
9
+ if (control === "switch") return { available: true };
10
+ const names = { button: "SparkButton", "text-input": "SparkTextInput", select: Platform.OS === "windows" ? "SparkSelect" : "NativeSelect", "segmented-control": "NativeSegmentedControl", checkbox: "SparkButton", "radio-group": "SparkRadioGroup" };
10
11
  return UIManager.hasViewManagerConfig(names[control]) ? { available: true } : { available: false, reason: "missing-module" };
11
12
  }
@@ -30,7 +30,7 @@ export function useControl(props: ControlProps, availability: Availability = { a
30
30
  const ref = useCallback((value: MeasureTarget) => { target.current = value; }, []);
31
31
  return { ref, disabled, failed: failed || !availability.available, error, unavailable, mounted: () => mounted.current, active: () => mounted.current && !disabled && !failed && availability.available };
32
32
  }
33
- export const controlKinds = ["button", "text-input", "select", "segmented-control", "checkbox", "radio-group"] as const;
33
+ export const controlKinds = ["button", "text-input", "select", "segmented-control", "checkbox", "radio-group", "switch"] as const;
34
34
  export const unsupportedPlatform: Availability = { available: false, reason: "unsupported-platform" };
35
35
  export function validateButton(props: ButtonProps) {
36
36
  if (typeof props.children !== "string" || !props.children.length || (props.onPress !== undefined && typeof props.onPress !== "function") || (props.variant !== undefined && !["default", "bordered", "borderless", "disclosure"].includes(props.variant))) throw new SparkError("E_INVALID_ARGUMENT", "Invalid button options");
@@ -10,9 +10,10 @@ import { RadioGroupFallback } from "./checkbox-unavailable";
10
10
  import { SparkError } from "@legendapp/spark-desktop-app/src/contracts";
11
11
  import { macosButton, unsupportedPlatform, useControl, useTextValue, validateButton, validateCheckbox, validateRadioGroup, validateSegmented } from "./control";
12
12
  import { getControlAvailability } from "./availability";
13
- import { selectionIndex } from "./select";
13
+ import { selectionIndex, validateSelectVariant } from "./select";
14
14
  import type { ButtonProps, CheckboxProps, RadioGroupProps, TextInputProps, SelectProps, SegmentedControlProps } from "./types";
15
- export type { ButtonProps, CheckboxProps, RadioGroupProps, TextInputProps, ControlledTextInputProps, UncontrolledTextInputProps, SelectProps, SelectOption, SegmentedControlProps, ControlProps, ControlRef, ControlKind } from "./types";
15
+ export { Switch } from "./switch";
16
+ export type { SwitchProps, ButtonProps, CheckboxProps, RadioGroupProps, TextInputProps, ControlledTextInputProps, UncontrolledTextInputProps, SelectProps, SelectOption, SegmentedControlProps, ControlProps, ControlRef, ControlKind } from "./types";
16
17
  export { getControlAvailability } from "./availability";
17
18
 
18
19
  // AppKit buttons report their intrinsic size, which sizes the view unless a style sets width or height.
@@ -70,22 +71,23 @@ export function TextInput(props: TextInputProps) {
70
71
  function Selection({ segmented, ...props }: SelectProps & { segmented: boolean }) {
71
72
  selectionIndex(props.options, props.value);
72
73
  if (typeof props.onValueChange !== "function") throw new SparkError("E_INVALID_ARGUMENT", "Expected onValueChange");
73
- const control = useControl(props, getControlAvailability(segmented ? "segmented-control" : "select"));
74
+ const { variant = "default" } = props;
75
+ const control = useControl(props, variant === "borderless" && Platform.OS !== "macos" ? unsupportedPlatform : getControlAvailability(segmented ? "segmented-control" : "select"));
74
76
  const [selectionRevision, revise] = useState(0);
75
- const { options, value, onValueChange, accessibilityLabel, style, testID } = props;
77
+ const { options, value, onValueChange, accessibilityLabel, accessibilityHint, style, testID } = props;
76
78
  function changed(event: NativeSyntheticEvent<{ value: string }>) {
77
79
  if (!control.active()) return;
78
80
  const next = event?.nativeEvent?.value;
79
81
  if (!options.some(option => option.value === next)) { control.error(new SparkError("E_INVALID_DATA", "Native selection is not an option")); return; }
80
82
  revise(revision => revision + 1); onValueChange(next);
81
83
  }
82
- const common = { ref: control.ref, value, accessibilityLabel, testID, style: [{ width: 240, height: 36 }, style], selectionRevision };
83
- if (control.failed) return <View ref={control.ref} style={common.style} testID={testID} accessible accessibilityLabel={accessibilityLabel} accessibilityState={{ disabled: true }}><Text>{options.find(option => option.value === value)!.label}</Text></View>;
84
+ const common = { ref: control.ref, value, accessibilityLabel, accessibilityHint, testID, style: [{ width: 240, height: 36 }, style], selectionRevision };
85
+ if (control.failed) return <View ref={control.ref} style={common.style} testID={testID} accessible accessibilityLabel={accessibilityLabel} accessibilityHint={accessibilityHint} accessibilityState={{ disabled: true }}><Text>{options.find(option => option.value === value)!.label}</Text></View>;
84
86
  if (segmented) return <NativeSegmentedControl {...common} segmentsJson={JSON.stringify(options)} enabled={!control.disabled} controlSize={(props as SegmentedControlProps).size ?? "regular"} distribution={(props as SegmentedControlProps).distribution ?? "fit"} onValueChange={changed} />;
85
87
  if (Platform.OS === "windows") return <WindowsSelect {...common} itemsJson={JSON.stringify(options)} disabled={control.disabled} onSelectionChange={changed} onUnavailable={control.unavailable} />;
86
- return <NativeSelect {...common} itemsJson={JSON.stringify(options)} enabled={!control.disabled} onValueChange={changed} />;
88
+ return <NativeSelect {...common} borderless={variant === "borderless"} itemsJson={JSON.stringify(options)} enabled={!control.disabled} onValueChange={changed} />;
87
89
  }
88
- export function Select(props: SelectProps) { return <Selection {...props} segmented={false} />; }
90
+ export function Select(props: SelectProps) { validateSelectVariant(props.variant); return <Selection {...props} segmented={false} />; }
89
91
  export function SegmentedControl(props: SegmentedControlProps) { validateSegmented(props); return <Selection {...props} segmented />; }
90
92
  /** AppKit radio buttons (NSButton) in a stack. Without a width or height style it takes its intrinsic size. */
91
93
  export function RadioGroup(props: RadioGroupProps) {
@@ -17,16 +17,17 @@ function Segments({ labels, selected, enabled, onSelect }: { labels: string[]; s
17
17
  import { View, Text } from "react-native";
18
18
  import { requireOptionalNativeModule } from "expo-modules-core";
19
19
  import { SparkError, type Availability } from "@legendapp/spark-desktop-app/src/contracts";
20
- import { selectionIndex } from "./select";
20
+ import { selectionIndex, validateSelectVariant } from "./select";
21
21
  import { controlKinds, macosButton, unsupportedPlatform, useControl, validateButton, validateSegmented } from "./control";
22
22
  import { UnavailableCheckbox, UnavailableRadioGroup } from "./checkbox-unavailable";
23
23
  import type { ButtonProps, CheckboxProps, RadioGroupProps, SelectProps, SegmentedControlProps, ControlKind } from "./types";
24
- export type { ButtonProps, CheckboxProps, RadioGroupProps, TextInputProps, ControlledTextInputProps, UncontrolledTextInputProps, SelectProps, SelectOption, SegmentedControlProps, ControlProps, ControlRef, ControlKind } from "./types";
24
+ export { Switch } from "./switch";
25
+ export type { SwitchProps, ButtonProps, CheckboxProps, RadioGroupProps, TextInputProps, ControlledTextInputProps, UncontrolledTextInputProps, SelectProps, SelectOption, SegmentedControlProps, ControlProps, ControlRef, ControlKind } from "./types";
25
26
  export { TextInput } from "./mobile-input";
26
27
  export function getControlAvailability(control: ControlKind): Availability {
27
28
  if (!controlKinds.includes(control)) throw new SparkError("E_INVALID_ARGUMENT", "Unknown control kind");
28
29
  if (control === "checkbox" || control === "radio-group") return unsupportedPlatform;
29
- return control === "text-input" || requireOptionalNativeModule("ExpoUI") ? { available: true } : { available: false, reason: "missing-module" };
30
+ return control === "switch" || control === "text-input" || requireOptionalNativeModule("ExpoUI") ? { available: true } : { available: false, reason: "missing-module" };
30
31
  }
31
32
  export function Button(props: ButtonProps) {
32
33
  validateButton(props); const control = useControl(props, macosButton(props) ? unsupportedPlatform : getControlAvailability("button"));
@@ -39,15 +40,15 @@ export function Button(props: ButtonProps) {
39
40
  function Selection(props: SelectProps) {
40
41
  const selected = selectionIndex(props.options, props.value);
41
42
  if (typeof props.onValueChange !== "function") throw new SparkError("E_INVALID_ARGUMENT", "Expected onValueChange");
42
- const control = useControl(props, getControlAvailability("select"));
43
- return <View ref={control.ref} style={[{ width: 280, minHeight: 48, flexDirection: "row" }, props.style]} testID={props.testID} accessibilityLabel={props.accessibilityLabel}>
43
+ const control = useControl(props, props.variant === "borderless" ? unsupportedPlatform : getControlAvailability("select"));
44
+ return <View ref={control.ref} style={[{ width: 280, minHeight: 48, flexDirection: "row" }, props.style]} testID={props.testID} accessibilityLabel={props.accessibilityLabel} accessibilityHint={props.accessibilityHint}>
44
45
  {control.failed ? <Text accessibilityState={{ disabled: true }}>{props.options[selected].label}</Text> :
45
46
  <Segments labels={props.options.map(option => option.label)} selected={selected} enabled={!control.disabled}
46
47
  onSelect={index => { if (control.active()) props.onValueChange(props.options[index].value); }} />}
47
48
  </View>;
48
49
  }
49
50
  /** Android presents its choices inline; there is no dropdown backend in the pinned Expo UI. */
50
- export function Select(props: SelectProps) { return <Selection {...props} />; }
51
+ export function Select(props: SelectProps) { validateSelectVariant(props.variant); return <Selection {...props} />; }
51
52
  export function Checkbox(props: CheckboxProps) { return <UnavailableCheckbox {...props} availability={getControlAvailability("checkbox")} />; }
52
53
  export function RadioGroup(props: RadioGroupProps) { return <UnavailableRadioGroup {...props} availability={getControlAvailability("radio-group")} />; }
53
54
  /** Native mobile segmented pickers have one size and fill their frame; `size` and `distribution` keep those defaults here. */
@@ -15,20 +15,21 @@ function Option(props: ComponentProps<typeof import("@expo/ui/swift-ui").Text>)
15
15
  const Component = (require("@expo/ui/swift-ui") as typeof import("@expo/ui/swift-ui")).Text;
16
16
  return <Component {...props} />;
17
17
  }
18
- import { frame, buttonStyle, pickerStyle, tag, disabled as disabledModifier, accessibilityLabel as labelModifier } from "@expo/ui/swift-ui/modifiers";
18
+ import { frame, buttonStyle, pickerStyle, tag, disabled as disabledModifier, accessibilityLabel as labelModifier, accessibilityHint as hintModifier } from "@expo/ui/swift-ui/modifiers";
19
19
  import { View, Text } from "react-native";
20
20
  import { SparkError, type Availability } from "@legendapp/spark-desktop-app/src/contracts";
21
21
  import { requireOptionalNativeModule } from "expo-modules-core";
22
22
  import { controlKinds, macosButton, unsupportedPlatform, useControl, validateButton, validateSegmented } from "./control";
23
23
  import { UnavailableCheckbox, UnavailableRadioGroup } from "./checkbox-unavailable";
24
- import { selectionIndex } from "./select";
24
+ import { selectionIndex, validateSelectVariant } from "./select";
25
25
  import type { ButtonProps, CheckboxProps, RadioGroupProps, SelectProps, SegmentedControlProps, ControlKind } from "./types";
26
- export type { ButtonProps, CheckboxProps, RadioGroupProps, TextInputProps, ControlledTextInputProps, UncontrolledTextInputProps, SelectProps, SelectOption, SegmentedControlProps, ControlProps, ControlRef, ControlKind } from "./types";
26
+ export { Switch } from "./switch";
27
+ export type { SwitchProps, ButtonProps, CheckboxProps, RadioGroupProps, TextInputProps, ControlledTextInputProps, UncontrolledTextInputProps, SelectProps, SelectOption, SegmentedControlProps, ControlProps, ControlRef, ControlKind } from "./types";
27
28
  export { TextInput } from "./mobile-input";
28
29
  export function getControlAvailability(control: ControlKind): Availability {
29
30
  if (!controlKinds.includes(control)) throw new SparkError("E_INVALID_ARGUMENT", "Unknown control kind");
30
31
  if (control === "checkbox" || control === "radio-group") return unsupportedPlatform;
31
- return control === "text-input" || requireOptionalNativeModule("ExpoUI") ? { available: true } : { available: false, reason: "missing-module" };
32
+ return control === "switch" || control === "text-input" || requireOptionalNativeModule("ExpoUI") ? { available: true } : { available: false, reason: "missing-module" };
32
33
  }
33
34
  const fill = [frame({ maxWidth: Infinity, maxHeight: Infinity })];
34
35
  export function Button(props: ButtonProps) {
@@ -44,11 +45,11 @@ function Selection({ segmented, ...props }: SelectProps & { segmented: boolean }
44
45
  const selectedIndex = selectionIndex(props.options, props.value);
45
46
  const [selectionRevision, revise] = useState(0);
46
47
  if (typeof props.onValueChange !== "function") throw new SparkError("E_INVALID_ARGUMENT", "Expected onValueChange");
47
- const control = useControl(props, getControlAvailability(segmented ? "segmented-control" : "select"));
48
- const { options, onValueChange, accessibilityLabel, style, testID } = props;
49
- const modifiers = [disabledModifier(control.disabled), ...(accessibilityLabel ? [labelModifier(accessibilityLabel)] : [])];
48
+ const control = useControl(props, props.variant === "borderless" ? unsupportedPlatform : getControlAvailability(segmented ? "segmented-control" : "select"));
49
+ const { options, onValueChange, accessibilityLabel, accessibilityHint, style, testID } = props;
50
+ const modifiers = [disabledModifier(control.disabled), ...(accessibilityLabel ? [labelModifier(accessibilityLabel)] : []), ...(accessibilityHint ? [hintModifier(accessibilityHint)] : [])];
50
51
  return <View ref={control.ref} style={[{ width: 240, height: 44 }, style]}>
51
- {control.failed ? <Text accessibilityLabel={accessibilityLabel} accessibilityState={{ disabled: true }} testID={testID}>{options[selectedIndex].label}</Text> :
52
+ {control.failed ? <Text accessibilityLabel={accessibilityLabel} accessibilityHint={accessibilityHint} accessibilityState={{ disabled: true }} testID={testID}>{options[selectedIndex].label}</Text> :
52
53
  <Host style={{ flex: 1 }}><Picker key={selectionRevision} selection={selectedIndex}
53
54
  onSelectionChange={index => {
54
55
  if (!control.active()) return;
@@ -62,7 +63,7 @@ function Selection({ segmented, ...props }: SelectProps & { segmented: boolean }
62
63
  </Picker></Host>}
63
64
  </View>;
64
65
  }
65
- export function Select(props: SelectProps) { return <Selection {...props} segmented={false} />; }
66
+ export function Select(props: SelectProps) { validateSelectVariant(props.variant); return <Selection {...props} segmented={false} />; }
66
67
  export function Checkbox(props: CheckboxProps) { return <UnavailableCheckbox {...props} availability={getControlAvailability("checkbox")} />; }
67
68
  export function RadioGroup(props: RadioGroupProps) { return <UnavailableRadioGroup {...props} availability={getControlAvailability("radio-group")} />; }
68
69
  /** Native mobile segmented pickers have one size and fill their frame; `size` and `distribution` keep those defaults here. */
@@ -1,10 +1,11 @@
1
- import { selectionIndex } from "./select";
1
+ import { selectionIndex, validateSelectVariant } from "./select";
2
2
  import type { CSSProperties } from "react";
3
3
  import { View } from "react-native";
4
4
  import { SparkError, type Availability } from "@legendapp/spark-desktop-app/src/contracts";
5
5
  import { controlKinds, unsupportedPlatform, useControl, useTextValue, validateButton, validateCheckbox, validateRadioGroup, validateSegmented } from "./control";
6
6
  import type { ButtonProps, CheckboxProps, RadioGroupProps, TextInputProps, SelectProps, SegmentedControlProps, ControlKind } from "./types";
7
- export type { ButtonProps, CheckboxProps, RadioGroupProps, TextInputProps, ControlledTextInputProps, UncontrolledTextInputProps, SelectProps, SelectOption, SegmentedControlProps, ControlProps, ControlRef, ControlKind } from "./types";
7
+ export { Switch } from "./switch";
8
+ export type { SwitchProps, ButtonProps, CheckboxProps, RadioGroupProps, TextInputProps, ControlledTextInputProps, UncontrolledTextInputProps, SelectProps, SelectOption, SegmentedControlProps, ControlProps, ControlRef, ControlKind } from "./types";
8
9
  export function getControlAvailability(control: ControlKind): Availability {
9
10
  if (!controlKinds.includes(control)) throw new SparkError("E_INVALID_ARGUMENT", "Unknown control kind");
10
11
  return { available: true };
@@ -47,9 +48,10 @@ function useSelection(props: SelectProps) {
47
48
  } };
48
49
  }
49
50
  export function Select(props: SelectProps) {
51
+ validateSelectVariant(props.variant);
50
52
  const control = useSelection(props);
51
53
  return <View ref={control.ref} style={[{ width: 240, height: 36 }, props.style]} testID={props.testID}>
52
- <select value={props.value} disabled={control.disabled} onChange={event => control.change(event.currentTarget.value)} aria-label={props.accessibilityLabel} style={nativeStyle}>
54
+ <select value={props.value} disabled={control.disabled} onChange={event => control.change(event.currentTarget.value)} aria-label={props.accessibilityLabel} aria-description={props.accessibilityHint} style={props.variant === "borderless" ? borderlessStyle : nativeStyle}>
53
55
  {props.options.map(option => <option key={option.value} value={option.value}>{option.label}</option>)}
54
56
  </select>
55
57
  </View>;
@@ -58,7 +60,7 @@ export function SegmentedControl(props: SegmentedControlProps) {
58
60
  validateSegmented(props);
59
61
  const control = useSelection(props), fill = props.distribution === "fill", font = props.size === "small" ? "12px system-ui" : nativeStyle.font;
60
62
  return <View ref={control.ref} style={[{ width: 240, height: 36 }, props.style]} testID={props.testID}>
61
- <div role="group" aria-label={props.accessibilityLabel} style={{ display: "flex", width: "100%", height: "100%" }}>
63
+ <div role="group" aria-label={props.accessibilityLabel} aria-description={props.accessibilityHint} style={{ display: "flex", width: "100%", height: "100%" }}>
62
64
  {props.options.map(option => <button type="button" key={option.value} disabled={control.disabled} aria-pressed={option.value === props.value} onClick={() => control.change(option.value)} style={{ ...nativeStyle, font, flex: fill ? 1 : "0 0 auto", width: fill ? "100%" : "auto" }}>{option.label}</button>)}
63
65
  </div>
64
66
  </View>;
@@ -7,6 +7,7 @@ export type NativeSelectChangeEvent = {
7
7
  };
8
8
 
9
9
  export interface NativeProps extends ViewProps {
10
+ borderless?: boolean;
10
11
  enabled?: boolean;
11
12
  selectionRevision?: Int32;
12
13
  itemsJson: string;
@@ -7,3 +7,7 @@ export function selectionIndex(options: SelectProps["options"], value: string):
7
7
  if (index < 0) throw new SparkError("E_INVALID_ARGUMENT", "Select value must match an option");
8
8
  return index;
9
9
  }
10
+
11
+ export function validateSelectVariant(variant: SelectProps["variant"]) {
12
+ if (variant !== undefined && variant !== "default" && variant !== "borderless") throw new SparkError("E_INVALID_ARGUMENT", "Invalid Select variant");
13
+ }
@@ -0,0 +1,13 @@
1
+ import { Platform, Switch as NativeSwitch, View } from "react-native";
2
+ import { SparkError } from "@legendapp/spark-desktop-app/src/contracts";
3
+ import { unsupportedPlatform, useControl } from "./control";
4
+ import type { SwitchProps } from "./types";
5
+
6
+ export function Switch(props: SwitchProps) {
7
+ const { value, onValueChange, accessibilityLabel, accessibilityHint, style, testID } = props;
8
+ if (typeof value !== "boolean" || typeof onValueChange !== "function") throw new SparkError("E_INVALID_ARGUMENT", "Switch requires a boolean value and onValueChange");
9
+ const control = useControl(props, ["macos", "windows", "ios", "android", "web"].includes(Platform.OS) ? undefined : unsupportedPlatform);
10
+ if (control.failed) return <View ref={control.ref} style={style} testID={testID} accessible accessibilityRole="switch" accessibilityLabel={accessibilityLabel} accessibilityHint={accessibilityHint} accessibilityState={{ checked: value, disabled: true }} />;
11
+ return <NativeSwitch ref={control.ref} value={value} onValueChange={next => { if (control.active()) onValueChange(next); }}
12
+ disabled={control.disabled} accessibilityLabel={accessibilityLabel} accessibilityHint={accessibilityHint} accessibilityState={{ checked: value }} style={style} testID={testID} />;
13
+ }