@legendapp/spark 0.0.4 → 0.0.6
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.
- package/package.json +4 -4
- package/skills/spark/UPGRADING.md +105 -0
- package/skills/spark/storage-settings.md +2 -28
- package/skills/spark/ui.md +27 -1
- package/vendor/node_modules/@legendapp/spark-ai/package.json +3 -3
- package/vendor/node_modules/@legendapp/spark-audio/package.json +2 -2
- package/vendor/node_modules/@legendapp/spark-auth-session/package.json +3 -3
- package/vendor/node_modules/@legendapp/spark-cli/dist/build.js +47 -25
- package/vendor/node_modules/@legendapp/spark-cli/dist/expo-desktop-template-bare-minimum-55.83.10.tgz +0 -0
- package/vendor/node_modules/@legendapp/spark-cli/dist/migrations.cjs +6 -0
- package/vendor/node_modules/@legendapp/spark-cli/dist/package.js +4 -8
- package/vendor/node_modules/@legendapp/spark-cli/dist/project.js +5 -3
- package/vendor/node_modules/@legendapp/spark-cli/dist/publish-directory.js +40 -0
- package/vendor/node_modules/@legendapp/spark-cli/dist/release-app.js +139 -0
- package/vendor/node_modules/@legendapp/spark-cli/dist/release.json +21 -21
- package/vendor/node_modules/@legendapp/spark-cli/dist/signing.js +61 -41
- package/vendor/node_modules/@legendapp/spark-cli/package.json +4 -4
- package/vendor/node_modules/@legendapp/spark-cli/templates/blank-typescript/package.json +2 -2
- package/vendor/node_modules/@legendapp/spark-cli/templates/universal/package.json +2 -2
- package/vendor/node_modules/@legendapp/spark-cli/templates/windows/package.json +2 -2
- package/vendor/node_modules/@legendapp/spark-clipboard/package.json +2 -2
- package/vendor/node_modules/@legendapp/spark-codex/package.json +2 -2
- package/vendor/node_modules/@legendapp/spark-commands/package.json +5 -5
- package/vendor/node_modules/@legendapp/spark-context-menu/package.json +2 -2
- package/vendor/node_modules/@legendapp/spark-desktop-app/macos/SparkTestDriver.h +2 -0
- package/vendor/node_modules/@legendapp/spark-desktop-app/macos/SparkTestDriver.mm +1 -0
- package/vendor/node_modules/@legendapp/spark-desktop-app/package.json +1 -1
- package/vendor/node_modules/@legendapp/spark-desktop-config/app.plugin.cjs +1 -0
- package/vendor/node_modules/@legendapp/spark-desktop-config/native-patches.cjs +15 -1
- package/vendor/node_modules/@legendapp/spark-desktop-config/native-patches.d.cts +1 -0
- package/vendor/node_modules/@legendapp/spark-desktop-config/package.json +3 -3
- package/vendor/node_modules/@legendapp/spark-desktop-config/rpaths.cjs +20 -0
- package/vendor/node_modules/@legendapp/spark-desktop-config/rpaths.d.cts +1 -0
- package/vendor/node_modules/@legendapp/spark-desktop-host/AppDelegate.mm +16 -5
- package/vendor/node_modules/@legendapp/spark-desktop-host/package.json +2 -2
- package/vendor/node_modules/@legendapp/spark-desktop-links/package.json +2 -2
- package/vendor/node_modules/@legendapp/spark-desktop-shortcuts/package.json +2 -2
- package/vendor/node_modules/@legendapp/spark-desktop-windows/package.json +3 -3
- package/vendor/node_modules/@legendapp/spark-documents/package.json +7 -7
- package/vendor/node_modules/@legendapp/spark-drag-drop/package.json +2 -2
- package/vendor/node_modules/@legendapp/spark-expo-compat/package.json +4 -4
- package/vendor/node_modules/@legendapp/spark-file-dialog/package.json +2 -2
- package/vendor/node_modules/@legendapp/spark-file-system/package.json +2 -2
- package/vendor/node_modules/@legendapp/spark-global-shortcuts/package.json +2 -2
- package/vendor/node_modules/@legendapp/spark-html/package.json +2 -2
- package/vendor/node_modules/@legendapp/spark-markdown/package.json +2 -2
- package/vendor/node_modules/@legendapp/spark-message-dialog/package.json +2 -2
- package/vendor/node_modules/@legendapp/spark-native-menu/package.json +2 -2
- package/vendor/node_modules/@legendapp/spark-notifications/package.json +2 -2
- package/vendor/node_modules/@legendapp/spark-processes/package.json +2 -2
- package/vendor/node_modules/@legendapp/spark-rich-text/package.json +2 -2
- package/vendor/node_modules/@legendapp/spark-secure-storage/package.json +2 -2
- package/vendor/node_modules/@legendapp/spark-settings/package.json +3 -3
- package/vendor/node_modules/@legendapp/spark-settings-ui/package.json +5 -5
- package/vendor/node_modules/@legendapp/spark-settings-ui/src/heading.tsx +14 -0
- package/vendor/node_modules/@legendapp/spark-settings-ui/src/index.tsx +132 -332
- package/vendor/node_modules/@legendapp/spark-settings-ui/src/rows.tsx +185 -0
- package/vendor/node_modules/@legendapp/spark-sqlite/package.json +3 -3
- package/vendor/node_modules/@legendapp/spark-system/package.json +2 -2
- package/vendor/node_modules/@legendapp/spark-tray/package.json +2 -2
- package/vendor/node_modules/@legendapp/spark-ui/macos/native-select/RNNativeSegmentedControl.mm +29 -0
- package/vendor/node_modules/@legendapp/spark-ui/macos/native-select/RNNativeSelect.mm +17 -1
- package/vendor/node_modules/@legendapp/spark-ui/macos/sidebar/RNSidebar.mm +20 -0
- package/vendor/node_modules/@legendapp/spark-ui/package.json +2 -2
- package/vendor/node_modules/@legendapp/spark-ui/src/availability.ts +2 -1
- package/vendor/node_modules/@legendapp/spark-ui/src/control.ts +1 -1
- package/vendor/node_modules/@legendapp/spark-ui/src/desktop.tsx +15 -12
- package/vendor/node_modules/@legendapp/spark-ui/src/index.android.tsx +7 -6
- package/vendor/node_modules/@legendapp/spark-ui/src/index.ios.tsx +10 -9
- package/vendor/node_modules/@legendapp/spark-ui/src/index.web.tsx +6 -4
- package/vendor/node_modules/@legendapp/spark-ui/src/native-select/NativeSegmentedControlNativeComponent.ts +2 -1
- package/vendor/node_modules/@legendapp/spark-ui/src/native-select/NativeSelectNativeComponent.ts +1 -0
- package/vendor/node_modules/@legendapp/spark-ui/src/select.ts +4 -0
- package/vendor/node_modules/@legendapp/spark-ui/src/switch.tsx +13 -0
- package/vendor/node_modules/@legendapp/spark-ui/src/types.ts +16 -4
- package/vendor/node_modules/@legendapp/spark-updates/package.json +2 -2
- package/vendor/node_modules/@legendapp/spark-webview/package.json +2 -2
- package/vendor/node_modules/@legendapp/spark-window-options/package.json +1 -1
- /package/{settings-window.ts → ui-settings.ts} +0 -0
|
@@ -0,0 +1,185 @@
|
|
|
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
|
+
import { SettingsHeading, settingsHeadingGap, settingsRowInset } from "./heading";
|
|
9
|
+
|
|
10
|
+
const { Image, Platform, PlatformColor, Pressable, StyleSheet, Text, View } = RN;
|
|
11
|
+
|
|
12
|
+
// The macOS type entry also declares globals. Keep the additions used here local.
|
|
13
|
+
const macOS = RN as typeof RN & {
|
|
14
|
+
DynamicColorMacOS(colors: { light: string; dark: string }): ColorValue;
|
|
15
|
+
};
|
|
16
|
+
type KeyEvent = NativeSyntheticEvent<{
|
|
17
|
+
key: string;
|
|
18
|
+
altKey: boolean;
|
|
19
|
+
ctrlKey: boolean;
|
|
20
|
+
metaKey: boolean;
|
|
21
|
+
shiftKey: boolean;
|
|
22
|
+
}>;
|
|
23
|
+
const cardColor = Platform.OS === "macos" ? macOS.DynamicColorMacOS({
|
|
24
|
+
light: "rgba(0,0,0,0.03)",
|
|
25
|
+
dark: "rgba(255,255,255,0.025)",
|
|
26
|
+
}) : undefined;
|
|
27
|
+
|
|
28
|
+
interface RowText {
|
|
29
|
+
label: string;
|
|
30
|
+
description?: string;
|
|
31
|
+
info?: string;
|
|
32
|
+
}
|
|
33
|
+
export interface SettingsSectionProps {
|
|
34
|
+
title?: string;
|
|
35
|
+
children: ReactNode;
|
|
36
|
+
}
|
|
37
|
+
export interface SettingsRowProps extends RowText {
|
|
38
|
+
children?: ReactNode;
|
|
39
|
+
}
|
|
40
|
+
export interface SettingsSwitchRowProps extends RowText {
|
|
41
|
+
value: boolean;
|
|
42
|
+
onValueChange: (value: boolean) => void;
|
|
43
|
+
disabled?: boolean;
|
|
44
|
+
}
|
|
45
|
+
export interface SettingsSelectRowProps extends RowText {
|
|
46
|
+
disabled?: boolean;
|
|
47
|
+
options: readonly SelectOption[];
|
|
48
|
+
value: string;
|
|
49
|
+
onValueChange: (value: string) => void;
|
|
50
|
+
}
|
|
51
|
+
export type SettingsSegmentedRowProps = SettingsSelectRowProps;
|
|
52
|
+
export interface SettingsImageChoiceOption extends SelectOption {
|
|
53
|
+
image: ImageSourcePropType;
|
|
54
|
+
}
|
|
55
|
+
export interface SettingsImageChoiceRowProps extends SettingsSelectRowProps {
|
|
56
|
+
options: readonly SettingsImageChoiceOption[];
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function SettingsSection({ title, children }: SettingsSectionProps) {
|
|
60
|
+
if (Platform.OS !== "macos") throw new SparkError("E_UNSUPPORTED_PLATFORM", "Settings sections require macOS");
|
|
61
|
+
return (
|
|
62
|
+
<View style={styles.section}>
|
|
63
|
+
{title ? <SettingsHeading title={title} variant="section" /> : null}
|
|
64
|
+
<View style={styles.card}>
|
|
65
|
+
{Children.toArray(children).map((child, index) => (
|
|
66
|
+
<Fragment key={typeof child === "object" && "key" in child ? child.key : index}>
|
|
67
|
+
{index > 0 ? <View style={[styles.divider, { backgroundColor: PlatformColor("separatorColor") }]} /> : null}
|
|
68
|
+
{child}
|
|
69
|
+
</Fragment>
|
|
70
|
+
))}
|
|
71
|
+
</View>
|
|
72
|
+
</View>
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function Row({ label, description, info, children, disabled, imageChoice }: SettingsRowProps & { disabled?: boolean; imageChoice?: boolean }) {
|
|
77
|
+
if (Platform.OS !== "macos") throw new SparkError("E_UNSUPPORTED_PLATFORM", "Settings rows require macOS");
|
|
78
|
+
return (
|
|
79
|
+
<View style={[styles.row, description && styles.rowWithDescription, imageChoice && styles.imageRow]}>
|
|
80
|
+
<View style={[styles.rowText, imageChoice && styles.imageRowText]}>
|
|
81
|
+
<View style={styles.labelLine}>
|
|
82
|
+
<Text style={[styles.label, { color: PlatformColor(disabled ? "tertiaryLabelColor" : "labelColor") }]}>{label}</Text>
|
|
83
|
+
{info ? <View accessible={false} {...{ tooltip: info }} style={styles.info}>
|
|
84
|
+
<SFSymbol accessible={false} name="info.circle" size={13} color={PlatformColor("secondaryLabelColor")} />
|
|
85
|
+
</View> : null}
|
|
86
|
+
</View>
|
|
87
|
+
{description ? <Text style={[styles.description, { color: PlatformColor(disabled ? "tertiaryLabelColor" : "secondaryLabelColor") }]}>{description}</Text> : null}
|
|
88
|
+
</View>
|
|
89
|
+
{children != null ? <View style={[styles.control, imageChoice && styles.imageControl]}>{children}</View> : null}
|
|
90
|
+
</View>
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export function SettingsRow(props: SettingsRowProps) {
|
|
95
|
+
return <Row {...props} />;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function accessibility({ label, description, info }: RowText) {
|
|
99
|
+
return { accessibilityLabel: label, accessibilityHint: [description, info].filter(Boolean).join(" ") || undefined };
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export function SettingsSwitchRow({ value, onValueChange, disabled, ...text }: SettingsSwitchRowProps) {
|
|
103
|
+
return <Row {...text} disabled={disabled}>
|
|
104
|
+
<View style={styles.switchControl}><Switch value={value} onValueChange={onValueChange} disabled={disabled} {...accessibility(text)} /></View>
|
|
105
|
+
</Row>;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export function SettingsSelectRow({ value, options, onValueChange, disabled, ...text }: SettingsSelectRowProps) {
|
|
109
|
+
return <Row {...text} disabled={disabled}>
|
|
110
|
+
<Select options={options} value={value} onValueChange={onValueChange} disabled={disabled} variant="borderless" style={styles.selection} {...accessibility(text)} />
|
|
111
|
+
</Row>;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export function SettingsSegmentedRow({ value, options, onValueChange, disabled, ...text }: SettingsSegmentedRowProps) {
|
|
115
|
+
return <Row {...text} disabled={disabled}>
|
|
116
|
+
<SegmentedControl options={options} value={value} onValueChange={onValueChange} disabled={disabled} {...accessibility(text)} />
|
|
117
|
+
</Row>;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
const choiceKeys = [{ key: "ArrowLeft" }, { key: "ArrowRight" }];
|
|
121
|
+
|
|
122
|
+
export function SettingsImageChoiceRow({ options, value, onValueChange, disabled = false, ...text }: SettingsImageChoiceRowProps) {
|
|
123
|
+
if (!Array.isArray(options) || options.some(option => option?.image == null) || typeof onValueChange !== "function" || typeof disabled !== "boolean") {
|
|
124
|
+
throw new SparkError("E_INVALID_ARGUMENT", "Image choices require options with images and onValueChange");
|
|
125
|
+
}
|
|
126
|
+
const selectedIndex = selectionIndex(options.map(({ image, ...option }) => option), value);
|
|
127
|
+
const [focused, setFocused] = useState(false);
|
|
128
|
+
const accentColor = PlatformColor("controlAccentColor");
|
|
129
|
+
function choose(next: string) {
|
|
130
|
+
if (!disabled && next !== value) onValueChange(next);
|
|
131
|
+
}
|
|
132
|
+
function onKeyDown({ nativeEvent }: KeyEvent) {
|
|
133
|
+
const { key, altKey, ctrlKey, metaKey, shiftKey } = nativeEvent;
|
|
134
|
+
if (altKey || ctrlKey || metaKey || shiftKey) return;
|
|
135
|
+
const step = key === "ArrowLeft" ? -1 : key === "ArrowRight" ? 1 : 0;
|
|
136
|
+
if (step) choose(options[(selectedIndex + step + options.length) % options.length].value);
|
|
137
|
+
}
|
|
138
|
+
return (
|
|
139
|
+
<Row {...text} disabled={disabled} imageChoice>
|
|
140
|
+
<View style={styles.choices} accessibilityRole="radiogroup" accessibilityState={{ disabled }} {...accessibility(text)}
|
|
141
|
+
focusable={!disabled} onFocus={() => setFocused(true)} onBlur={() => setFocused(false)}
|
|
142
|
+
{...{ enableFocusRing: false, ...(!disabled && { onKeyDown, keyDownEvents: choiceKeys }) }}>
|
|
143
|
+
{options.map(option => {
|
|
144
|
+
const selected = option.value === value;
|
|
145
|
+
const captionColor = PlatformColor(disabled ? "tertiaryLabelColor" : selected ? "labelColor" : "secondaryLabelColor");
|
|
146
|
+
return (
|
|
147
|
+
<Pressable key={option.value} accessibilityRole="radio" accessibilityLabel={option.label}
|
|
148
|
+
accessibilityState={{ checked: selected, disabled }} focusable={false} disabled={disabled} onPress={() => choose(option.value)}
|
|
149
|
+
style={styles.choice}>
|
|
150
|
+
<View style={[styles.ring, selected && { borderColor: accentColor }, selected && focused && !disabled && { outlineColor: accentColor, outlineWidth: 1, outlineOffset: 2 }]}>
|
|
151
|
+
<Image accessible={false} source={option.image} resizeMode="cover"
|
|
152
|
+
style={[styles.image, !selected && { borderColor: PlatformColor("separatorColor"), borderWidth: StyleSheet.hairlineWidth }]} />
|
|
153
|
+
</View>
|
|
154
|
+
<Text style={[styles.caption, { color: captionColor, fontWeight: selected ? "600" : "400" }]}>{option.label}</Text>
|
|
155
|
+
</Pressable>
|
|
156
|
+
);
|
|
157
|
+
})}
|
|
158
|
+
</View>
|
|
159
|
+
</Row>
|
|
160
|
+
);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
const styles = StyleSheet.create({
|
|
164
|
+
section: { gap: settingsHeadingGap },
|
|
165
|
+
card: { backgroundColor: cardColor, borderRadius: 10, overflow: "hidden" },
|
|
166
|
+
divider: { height: StyleSheet.hairlineWidth, marginHorizontal: settingsRowInset },
|
|
167
|
+
row: { flexDirection: "row", alignItems: "center", minHeight: 42, paddingHorizontal: settingsRowInset, paddingVertical: 10, gap: 12 },
|
|
168
|
+
rowText: { flex: 1, minWidth: 0, gap: 3 },
|
|
169
|
+
rowWithDescription: { paddingVertical: 11 },
|
|
170
|
+
labelLine: { flexDirection: "row", alignItems: "flex-start", gap: 6 },
|
|
171
|
+
label: { fontSize: 13, lineHeight: 16, flexShrink: 1 },
|
|
172
|
+
description: { fontSize: 11, lineHeight: 14 },
|
|
173
|
+
info: { marginTop: 1.5 },
|
|
174
|
+
control: { flexShrink: 1, alignItems: "flex-end" },
|
|
175
|
+
switchControl: { height: 22, justifyContent: "center" },
|
|
176
|
+
selection: { height: 22, width: 190 },
|
|
177
|
+
imageControl: { maxWidth: "70%" },
|
|
178
|
+
imageRow: { alignItems: "flex-start" },
|
|
179
|
+
imageRowText: { paddingTop: 5 },
|
|
180
|
+
choices: { flexDirection: "row", flexWrap: "wrap", justifyContent: "flex-end", gap: 20 },
|
|
181
|
+
choice: { width: 76, alignItems: "center", gap: 6 },
|
|
182
|
+
ring: { borderWidth: 3, borderColor: "transparent", borderRadius: 10, padding: 1 },
|
|
183
|
+
image: { width: 68, height: 42, borderRadius: 6 },
|
|
184
|
+
caption: { fontSize: 11, lineHeight: 14, textAlign: "center" },
|
|
185
|
+
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@legendapp/spark-sqlite",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.6",
|
|
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.
|
|
12
|
-
"@legendapp/spark-file-system": "0.0.
|
|
11
|
+
"@legendapp/spark-desktop-app": "0.0.6",
|
|
12
|
+
"@legendapp/spark-file-system": "0.0.6"
|
|
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.
|
|
3
|
+
"version": "0.0.6",
|
|
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.
|
|
36
|
+
"@legendapp/spark-desktop-app": "0.0.6"
|
|
37
37
|
},
|
|
38
38
|
"private": true
|
|
39
39
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@legendapp/spark-tray",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.6",
|
|
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.
|
|
36
|
+
"@legendapp/spark-desktop-app": "0.0.6"
|
|
37
37
|
},
|
|
38
38
|
"private": true
|
|
39
39
|
}
|
package/vendor/node_modules/@legendapp/spark-ui/macos/native-select/RNNativeSegmentedControl.mm
CHANGED
|
@@ -19,6 +19,7 @@ using namespace facebook::react;
|
|
|
19
19
|
NSString *_value;
|
|
20
20
|
NSArray<NSString *> *_labels;
|
|
21
21
|
BOOL _isUpdatingSelection;
|
|
22
|
+
NSSize _reportedSize;
|
|
22
23
|
#else
|
|
23
24
|
UIView *_segmentedControl;
|
|
24
25
|
#endif
|
|
@@ -107,6 +108,20 @@ using namespace facebook::react;
|
|
|
107
108
|
}
|
|
108
109
|
}
|
|
109
110
|
|
|
111
|
+
- (void)reportIntrinsicSize
|
|
112
|
+
{
|
|
113
|
+
if (_labels.count == 0 || _segmentedControl.segmentDistribution != NSSegmentDistributionFit) return;
|
|
114
|
+
auto emitter = std::static_pointer_cast<const NativeSegmentedControlEventEmitter>(_eventEmitter);
|
|
115
|
+
NSSize size = _segmentedControl.intrinsicContentSize;
|
|
116
|
+
size = NSMakeSize(ceil(size.width), ceil(size.height));
|
|
117
|
+
if (!emitter || NSEqualSizes(size, _reportedSize)) return;
|
|
118
|
+
_reportedSize = size;
|
|
119
|
+
NativeSegmentedControlEventEmitter::OnIntrinsicSize event;
|
|
120
|
+
event.width = size.width;
|
|
121
|
+
event.height = size.height;
|
|
122
|
+
emitter->onIntrinsicSize(event);
|
|
123
|
+
}
|
|
124
|
+
|
|
110
125
|
- (void)selectValue:(NSString *)value
|
|
111
126
|
{
|
|
112
127
|
_isUpdatingSelection = YES;
|
|
@@ -167,9 +182,21 @@ using namespace facebook::react;
|
|
|
167
182
|
}
|
|
168
183
|
_segmentedControl.enabled = newProps.enabled;
|
|
169
184
|
_segmentedControl.accessibilityLabel = [NSString stringWithUTF8String:newProps.accessibilityLabel.c_str()];
|
|
185
|
+
_segmentedControl.accessibilityHelp = [NSString stringWithUTF8String:newProps.accessibilityHint.c_str()];
|
|
170
186
|
_segmentedControl.accessibilityIdentifier = [NSString stringWithUTF8String:newProps.testId.c_str()];
|
|
171
187
|
#endif
|
|
172
188
|
[super updateProps:props oldProps:oldProps];
|
|
189
|
+
#if TARGET_OS_OSX
|
|
190
|
+
[self reportIntrinsicSize];
|
|
191
|
+
#endif
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
- (void)updateEventEmitter:(EventEmitter::Shared const &)eventEmitter
|
|
195
|
+
{
|
|
196
|
+
[super updateEventEmitter:eventEmitter];
|
|
197
|
+
#if TARGET_OS_OSX
|
|
198
|
+
[self reportIntrinsicSize];
|
|
199
|
+
#endif
|
|
173
200
|
}
|
|
174
201
|
|
|
175
202
|
- (void)prepareForRecycle
|
|
@@ -181,8 +208,10 @@ using namespace facebook::react;
|
|
|
181
208
|
_segmentsJson = @"";
|
|
182
209
|
_value = @"";
|
|
183
210
|
_isUpdatingSelection = NO;
|
|
211
|
+
_reportedSize = NSZeroSize;
|
|
184
212
|
_segmentedControl.segmentCount = 0;
|
|
185
213
|
_segmentedControl.enabled = YES;
|
|
214
|
+
_segmentedControl.accessibilityHelp = nil;
|
|
186
215
|
_segmentedControl.accessibilityLabel = nil; _segmentedControl.accessibilityIdentifier = nil;
|
|
187
216
|
#endif
|
|
188
217
|
}
|
|
@@ -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
|
-
|
|
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.
|
|
3
|
+
"version": "0.0.6",
|
|
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.
|
|
73
|
+
"@legendapp/spark-desktop-app": "0.0.6"
|
|
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,13 +10,13 @@ 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
|
|
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
|
-
// AppKit
|
|
19
|
-
// WinUI buttons do not, so they keep a fixed default frame.
|
|
19
|
+
// AppKit controls can report their intrinsic size. Explicit styles take precedence.
|
|
20
20
|
function useIntrinsicSize(control: ReturnType<typeof useControl>) {
|
|
21
21
|
const [size, setSize] = useState<{ width: number; height: number }>();
|
|
22
22
|
function measured(event: NativeSyntheticEvent<{ width: number; height: number }>) {
|
|
@@ -67,25 +67,28 @@ export function TextInput(props: TextInputProps) {
|
|
|
67
67
|
if (control.failed) return <View ref={control.ref} style={[size, style]} testID={testID} accessible accessibilityLabel={accessibilityLabel} accessibilityState={{ disabled: true }}><Text>{value.controlled ? value.text : value.defaultText}</Text></View>;
|
|
68
68
|
return <NativeTextInput ref={control.ref} text={value.text} defaultText={value.defaultText} controlled={value.controlled} eventCount={value.eventCount} disabled={control.disabled} placeholder={placeholder} multiline={multiline} onTextChange={changed} onUnavailable={control.unavailable} accessibilityLabel={accessibilityLabel} testID={testID} style={[size, style]} />;
|
|
69
69
|
}
|
|
70
|
-
function Selection({ segmented, ...props }: SelectProps & { segmented: boolean }) {
|
|
70
|
+
function Selection({ segmented, size = "regular", distribution = "fit", ...props }: SelectProps & Pick<SegmentedControlProps, "size" | "distribution"> & { segmented: boolean }) {
|
|
71
71
|
selectionIndex(props.options, props.value);
|
|
72
72
|
if (typeof props.onValueChange !== "function") throw new SparkError("E_INVALID_ARGUMENT", "Expected onValueChange");
|
|
73
|
-
const
|
|
73
|
+
const { variant = "default" } = props;
|
|
74
|
+
const control = useControl(props, variant === "borderless" && Platform.OS !== "macos" ? unsupportedPlatform : getControlAvailability(segmented ? "segmented-control" : "select"));
|
|
75
|
+
const intrinsic = useIntrinsicSize(control);
|
|
76
|
+
const fit = segmented && Platform.OS === "macos" && distribution === "fit";
|
|
74
77
|
const [selectionRevision, revise] = useState(0);
|
|
75
|
-
const { options, value, onValueChange, accessibilityLabel, style, testID } = props;
|
|
78
|
+
const { options, value, onValueChange, accessibilityLabel, accessibilityHint, style, testID } = props;
|
|
76
79
|
function changed(event: NativeSyntheticEvent<{ value: string }>) {
|
|
77
80
|
if (!control.active()) return;
|
|
78
81
|
const next = event?.nativeEvent?.value;
|
|
79
82
|
if (!options.some(option => option.value === next)) { control.error(new SparkError("E_INVALID_DATA", "Native selection is not an option")); return; }
|
|
80
83
|
revise(revision => revision + 1); onValueChange(next);
|
|
81
84
|
}
|
|
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
|
-
if (segmented) return <NativeSegmentedControl {...common} segmentsJson={JSON.stringify(options)} enabled={!control.disabled} controlSize={
|
|
85
|
+
const common = { ref: control.ref, value, accessibilityLabel, accessibilityHint, testID, style: [fit && intrinsic.frame ? intrinsic.frame : { width: 240, height: 36 }, style], selectionRevision };
|
|
86
|
+
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>;
|
|
87
|
+
if (segmented) return <NativeSegmentedControl {...common} segmentsJson={JSON.stringify(options)} enabled={!control.disabled} controlSize={size} distribution={distribution} onIntrinsicSize={fit ? intrinsic.measured : undefined} onValueChange={changed} />;
|
|
85
88
|
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} />;
|
|
89
|
+
return <NativeSelect {...common} borderless={variant === "borderless"} itemsJson={JSON.stringify(options)} enabled={!control.disabled} onValueChange={changed} />;
|
|
87
90
|
}
|
|
88
|
-
export function Select(props: SelectProps) { return <Selection {...props} segmented={false} />; }
|
|
91
|
+
export function Select(props: SelectProps) { validateSelectVariant(props.variant); return <Selection {...props} segmented={false} />; }
|
|
89
92
|
export function SegmentedControl(props: SegmentedControlProps) { validateSegmented(props); return <Selection {...props} segmented />; }
|
|
90
93
|
/** AppKit radio buttons (NSButton) in a stack. Without a width or height style it takes its intrinsic size. */
|
|
91
94
|
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
|
|
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
|
|
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
|
|
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>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { HostComponent, ViewProps } from "react-native";
|
|
2
2
|
import { codegenNativeComponent } from "react-native";
|
|
3
|
-
import type { DirectEventHandler, Int32, WithDefault } from "react-native/Libraries/Types/CodegenTypes";
|
|
3
|
+
import type { DirectEventHandler, Double, Int32, WithDefault } from "react-native/Libraries/Types/CodegenTypes";
|
|
4
4
|
|
|
5
5
|
export type NativeSegmentedControlChangeEvent = {
|
|
6
6
|
value: string;
|
|
@@ -12,6 +12,7 @@ export interface NativeProps extends ViewProps {
|
|
|
12
12
|
distribution?: WithDefault<"fit" | "fill", "fit">;
|
|
13
13
|
selectionRevision?: Int32;
|
|
14
14
|
segmentsJson: string;
|
|
15
|
+
onIntrinsicSize?: DirectEventHandler<Readonly<{ width: Double; height: Double }>>;
|
|
15
16
|
onValueChange?: DirectEventHandler<NativeSegmentedControlChangeEvent>;
|
|
16
17
|
value: string;
|
|
17
18
|
}
|