@legendapp/spark 0.0.3 → 0.0.4
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/init-template.cjs +7 -1
- package/package.json +10 -5
- package/patches/dependencies.json +4 -4
- package/patches/react-native-mmkv@4.3.2.patch +2 -2
- package/patches/react-native-nitro-zxing@0.3.1.patch +22 -0
- package/patches/registry.json +615 -0
- package/patches/workspace/expo-audio@55.0.18.patch +159 -0
- package/patches/workspace/op-engineering-op-sqlite@18.2.1.patch +796 -0
- package/patches/workspace/react-native-nitro-modules@0.37.0.patch +1348 -0
- package/patches/workspace/react-native-runtimes-core@0.1.0-alpha.2.patch +276 -0
- package/patches/workspace/react-native-webview@16.0.0.patch +208 -0
- package/postinstall.cjs +10 -1
- package/skills/spark/SKILL.md +37 -4
- package/skills/spark/UPGRADING.md +116 -1
- package/skills/spark/ai-customize.md +39 -0
- package/skills/spark/app-and-documents.md +56 -0
- package/skills/spark/external-libraries.md +87 -0
- package/skills/spark/files.md +64 -0
- package/skills/spark/integrations.md +69 -0
- package/skills/spark/keyboard.md +54 -0
- package/skills/spark/library-compat.md +76 -0
- package/skills/spark/menus-tray-dock.md +83 -0
- package/skills/spark/storage-settings.md +85 -0
- package/skills/spark/ui.md +57 -0
- package/skills/spark/windows.md +91 -0
- package/ui-popover.ts +1 -0
- package/ui-progress.ts +1 -0
- package/ui-sheet.ts +1 -0
- package/ui-split-view.ts +1 -0
- package/ui-table.ts +1 -0
- package/vendor/node_modules/@legendapp/spark-ai/package.json +3 -3
- package/vendor/node_modules/@legendapp/spark-audio/package.json +3 -13
- package/vendor/node_modules/@legendapp/spark-auth-session/package.json +3 -10
- package/vendor/node_modules/@legendapp/spark-cli/dist/add-desktop.js +5 -0
- package/vendor/node_modules/@legendapp/spark-cli/dist/build.js +137 -105
- package/vendor/node_modules/@legendapp/spark-cli/dist/cli-arguments.js +4 -1
- package/vendor/node_modules/@legendapp/spark-cli/dist/commands.js +16 -7
- package/vendor/node_modules/@legendapp/spark-cli/dist/dependency-pins.js +19 -3
- package/vendor/node_modules/@legendapp/spark-cli/dist/dev-command.js +2 -0
- package/vendor/node_modules/@legendapp/spark-cli/dist/dev.js +3 -0
- package/vendor/node_modules/@legendapp/spark-cli/dist/enriched-html-pins.js +2 -0
- package/vendor/node_modules/@legendapp/spark-cli/dist/errors.js +1 -1
- package/vendor/node_modules/@legendapp/spark-cli/dist/index.js +57 -9
- package/vendor/node_modules/@legendapp/spark-cli/dist/init-template.cjs +12 -2
- package/vendor/node_modules/@legendapp/spark-cli/dist/init-template.d.cts +1 -1
- package/vendor/node_modules/@legendapp/spark-cli/dist/metro.cjs +1 -0
- package/vendor/node_modules/@legendapp/spark-cli/dist/migrate.js +65 -0
- package/vendor/node_modules/@legendapp/spark-cli/dist/migration-helpers.cjs +4 -4
- package/vendor/node_modules/@legendapp/spark-cli/dist/migration-helpers.d.cts +2 -2
- package/vendor/node_modules/@legendapp/spark-cli/dist/migrations.cjs +12 -8
- package/vendor/node_modules/@legendapp/spark-cli/dist/native-patch-preflight.js +35 -7
- package/vendor/node_modules/@legendapp/spark-cli/dist/patch.js +92 -0
- package/vendor/node_modules/@legendapp/spark-cli/dist/project-version.js +12 -4
- package/vendor/node_modules/@legendapp/spark-cli/dist/project.js +8 -1
- package/vendor/node_modules/@legendapp/spark-cli/dist/release.json +20 -20
- package/vendor/node_modules/@legendapp/spark-cli/dist/upgrade.js +1 -1
- package/vendor/node_modules/@legendapp/spark-cli/dist/windows.js +3 -0
- package/vendor/node_modules/@legendapp/spark-cli/package.json +5 -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/macos/RNDesktopClipboard.mm +1 -1
- package/vendor/node_modules/@legendapp/spark-clipboard/package.json +3 -10
- package/vendor/node_modules/@legendapp/spark-clipboard/src/desktop.ts +1 -0
- package/vendor/node_modules/@legendapp/spark-codex/package.json +3 -7
- package/vendor/node_modules/@legendapp/spark-commands/package.json +5 -5
- package/vendor/node_modules/@legendapp/spark-context-menu/package.json +3 -10
- package/vendor/node_modules/@legendapp/spark-desktop-app/macos/SparkDesktop.h +3 -1
- package/vendor/node_modules/@legendapp/spark-desktop-app/macos/SparkDesktop.mm +51 -10
- package/vendor/node_modules/@legendapp/spark-desktop-app/macos/SparkStorage.h +4 -0
- package/vendor/node_modules/@legendapp/spark-desktop-app/macos/SparkStorage.mm +82 -0
- package/vendor/node_modules/@legendapp/spark-desktop-app/package.json +2 -8
- package/vendor/node_modules/@legendapp/spark-desktop-config/config.cjs +6 -8
- package/vendor/node_modules/@legendapp/spark-desktop-config/identity.cjs +2 -0
- package/vendor/node_modules/@legendapp/spark-desktop-config/native-patches.cjs +300 -71
- package/vendor/node_modules/@legendapp/spark-desktop-config/native-patches.d.cts +7 -0
- package/vendor/node_modules/@legendapp/spark-desktop-config/package.json +3 -3
- package/vendor/node_modules/@legendapp/spark-desktop-config/patch-registry.cjs +318 -0
- package/vendor/node_modules/@legendapp/spark-desktop-config/patch-registry.d.cts +20 -0
- package/vendor/node_modules/@legendapp/spark-desktop-config/validation.cjs +66 -9
- package/vendor/node_modules/@legendapp/spark-desktop-config/windows.plugin.cjs +1 -0
- package/vendor/node_modules/@legendapp/spark-desktop-host/AppDelegate.mm +1 -0
- package/vendor/node_modules/@legendapp/spark-desktop-host/package.json +2 -2
- package/vendor/node_modules/@legendapp/spark-desktop-links/package.json +3 -10
- package/vendor/node_modules/@legendapp/spark-desktop-shortcuts/package.json +3 -10
- package/vendor/node_modules/@legendapp/spark-desktop-windows/macos/RNDesktopWindows.mm +7 -2
- package/vendor/node_modules/@legendapp/spark-desktop-windows/macos/window-manager/RNWindowManager.mm +235 -240
- package/vendor/node_modules/@legendapp/spark-desktop-windows/package.json +4 -11
- package/vendor/node_modules/@legendapp/spark-desktop-windows/src/api.ts +9 -3
- package/vendor/node_modules/@legendapp/spark-desktop-windows/src/macos-adapter.ts +7 -0
- package/vendor/node_modules/@legendapp/spark-desktop-windows/src/types.ts +32 -3
- package/vendor/node_modules/@legendapp/spark-desktop-windows/src/validation.ts +28 -11
- package/vendor/node_modules/@legendapp/spark-desktop-windows/src/windows/createWindowsNavigator.tsx +15 -3
- package/vendor/node_modules/@legendapp/spark-desktop-windows/src/windows/primaryWindowLifecycle.ts +12 -3
- package/vendor/node_modules/@legendapp/spark-desktop-windows/src/windows/usePrimaryWindowLifecycle.ts +2 -1
- package/vendor/node_modules/@legendapp/spark-desktop-windows/src/windows/useWindowFocusEffect.ts +4 -1
- package/vendor/node_modules/@legendapp/spark-documents/package.json +7 -7
- package/vendor/node_modules/@legendapp/spark-drag-drop/macos/RNDesktopDragView.mm +77 -17
- package/vendor/node_modules/@legendapp/spark-drag-drop/package.json +3 -8
- package/vendor/node_modules/@legendapp/spark-drag-drop/src/DesktopDragViewNativeComponent.ts +1 -0
- package/vendor/node_modules/@legendapp/spark-drag-drop/src/contracts.ts +13 -4
- package/vendor/node_modules/@legendapp/spark-drag-drop/src/index.tsx +5 -3
- package/vendor/node_modules/@legendapp/spark-drag-drop/windows/SparkDragDrop/SparkDragDrop.h +6 -1
- package/vendor/node_modules/@legendapp/spark-expo-compat/metro.cjs +44 -0
- package/vendor/node_modules/@legendapp/spark-expo-compat/package.json +20 -0
- package/vendor/node_modules/@legendapp/spark-expo-compat/src/clipboard.ts +40 -0
- package/vendor/node_modules/@legendapp/spark-expo-compat/src/document-picker.ts +52 -0
- package/vendor/node_modules/@legendapp/spark-file-dialog/package.json +3 -10
- package/vendor/node_modules/@legendapp/spark-file-dialog/src/options.ts +5 -2
- package/vendor/node_modules/@legendapp/spark-file-dialog/src/types.ts +3 -3
- package/vendor/node_modules/@legendapp/spark-file-system/macos/RNDesktopFileSystem.mm +1 -1
- package/vendor/node_modules/@legendapp/spark-file-system/package.json +3 -11
- package/vendor/node_modules/@legendapp/spark-global-shortcuts/package.json +3 -10
- 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 +3 -10
- package/vendor/node_modules/@legendapp/spark-message-dialog/src/index.ts +1 -0
- package/vendor/node_modules/@legendapp/spark-native-menu/package.json +3 -9
- package/vendor/node_modules/@legendapp/spark-native-menu/src/hooks.ts +4 -0
- package/vendor/node_modules/@legendapp/spark-notifications/package.json +3 -10
- package/vendor/node_modules/@legendapp/spark-processes/package.json +3 -10
- package/vendor/node_modules/@legendapp/spark-rich-text/package.json +2 -2
- package/vendor/node_modules/@legendapp/spark-secure-storage/package.json +3 -10
- package/vendor/node_modules/@legendapp/spark-settings/package.json +3 -3
- package/vendor/node_modules/@legendapp/spark-settings-ui/package.json +4 -4
- package/vendor/node_modules/@legendapp/spark-sqlite/package.json +3 -3
- package/vendor/node_modules/@legendapp/spark-system/package.json +3 -10
- package/vendor/node_modules/@legendapp/spark-tray/package.json +3 -10
- package/vendor/node_modules/@legendapp/spark-tray/src/index.ts +2 -1
- package/vendor/node_modules/@legendapp/spark-ui/macos/RNSparkButton.mm +82 -14
- package/vendor/node_modules/@legendapp/spark-ui/macos/RNSparkTextInput.h +1 -1
- package/vendor/node_modules/@legendapp/spark-ui/macos/RNSparkTextInput.mm +94 -11
- package/vendor/node_modules/@legendapp/spark-ui/macos/appkit-split-view/RNSidebarSplitViewComponent.mm +235 -18
- package/vendor/node_modules/@legendapp/spark-ui/macos/appkit-split-view/RNSparkPaneSplitView.h +17 -0
- package/vendor/node_modules/@legendapp/spark-ui/macos/appkit-split-view/RNSparkPaneSplitView.mm +216 -0
- package/vendor/node_modules/@legendapp/spark-ui/macos/appkit-split-view/RNSparkSplitViewComponent.h +4 -0
- package/vendor/node_modules/@legendapp/spark-ui/macos/appkit-split-view/RNSparkSplitViewComponent.mm +212 -0
- package/vendor/node_modules/@legendapp/spark-ui/macos/appkit-split-view/RNSparkSplitViewUpdates.h +6 -0
- package/vendor/node_modules/@legendapp/spark-ui/macos/native-select/RNNativeSegmentedControl.mm +26 -13
- package/vendor/node_modules/@legendapp/spark-ui/macos/popover/RNSparkPopover.h +9 -0
- package/vendor/node_modules/@legendapp/spark-ui/macos/popover/RNSparkPopover.mm +126 -0
- package/vendor/node_modules/@legendapp/spark-ui/macos/progress/RNSparkProgressIndicator.h +9 -0
- package/vendor/node_modules/@legendapp/spark-ui/macos/progress/RNSparkProgressIndicator.mm +66 -0
- package/vendor/node_modules/@legendapp/spark-ui/macos/radio-group/RNSparkRadioGroup.h +9 -0
- package/vendor/node_modules/@legendapp/spark-ui/macos/radio-group/RNSparkRadioGroup.mm +118 -0
- package/vendor/node_modules/@legendapp/spark-ui/macos/sf-symbol/RNSFSymbol.mm +4 -12
- package/vendor/node_modules/@legendapp/spark-ui/macos/sheet/RNSparkSheet.h +9 -0
- package/vendor/node_modules/@legendapp/spark-ui/macos/sheet/RNSparkSheet.mm +109 -0
- package/vendor/node_modules/@legendapp/spark-ui/macos/sidebar/RNSidebar.mm +418 -102
- package/vendor/node_modules/@legendapp/spark-ui/macos/table/RNSparkTable.h +9 -0
- package/vendor/node_modules/@legendapp/spark-ui/macos/table/RNSparkTable.mm +179 -0
- package/vendor/node_modules/@legendapp/spark-ui/package.json +9 -8
- package/vendor/node_modules/@legendapp/spark-ui/src/SparkButtonNativeComponent.ts +10 -2
- package/vendor/node_modules/@legendapp/spark-ui/src/SparkTextInputNativeComponent.ts +2 -0
- package/vendor/node_modules/@legendapp/spark-ui/src/appkit-split-view/SidebarSplitViewNativeComponent.ts +9 -0
- package/vendor/node_modules/@legendapp/spark-ui/src/appkit-split-view/SplitView.tsx +99 -0
- package/vendor/node_modules/@legendapp/spark-ui/src/appkit-split-view/SplitViewNativeComponent.ts +29 -0
- package/vendor/node_modules/@legendapp/spark-ui/src/appkit-split-view/index.tsx +34 -17
- package/vendor/node_modules/@legendapp/spark-ui/src/availability.ts +5 -4
- package/vendor/node_modules/@legendapp/spark-ui/src/checkbox-unavailable.tsx +20 -0
- package/vendor/node_modules/@legendapp/spark-ui/src/control.ts +24 -3
- package/vendor/node_modules/@legendapp/spark-ui/src/desktop.tsx +63 -13
- package/vendor/node_modules/@legendapp/spark-ui/src/index.android.tsx +12 -7
- package/vendor/node_modules/@legendapp/spark-ui/src/index.ios.tsx +12 -7
- package/vendor/node_modules/@legendapp/spark-ui/src/index.web.tsx +35 -13
- package/vendor/node_modules/@legendapp/spark-ui/src/mobile-input.tsx +2 -2
- package/vendor/node_modules/@legendapp/spark-ui/src/native-select/NativeSegmentedControlNativeComponent.ts +3 -1
- package/vendor/node_modules/@legendapp/spark-ui/src/popover/PopoverNativeComponent.ts +20 -0
- package/vendor/node_modules/@legendapp/spark-ui/src/popover/index.tsx +45 -0
- package/vendor/node_modules/@legendapp/spark-ui/src/progress/ProgressIndicatorNativeComponent.ts +13 -0
- package/vendor/node_modules/@legendapp/spark-ui/src/progress/index.tsx +32 -0
- package/vendor/node_modules/@legendapp/spark-ui/src/radio-group/RadioGroupNativeComponent.ts +17 -0
- package/vendor/node_modules/@legendapp/spark-ui/src/sheet/SheetNativeComponent.ts +15 -0
- package/vendor/node_modules/@legendapp/spark-ui/src/sheet/index.tsx +38 -0
- package/vendor/node_modules/@legendapp/spark-ui/src/sidebar/SidebarItemNativeComponent.ts +9 -1
- package/vendor/node_modules/@legendapp/spark-ui/src/sidebar/SidebarNativeComponent.ts +17 -2
- package/vendor/node_modules/@legendapp/spark-ui/src/sidebar/index.tsx +106 -22
- package/vendor/node_modules/@legendapp/spark-ui/src/table/TableNativeComponent.ts +22 -0
- package/vendor/node_modules/@legendapp/spark-ui/src/table/index.tsx +118 -0
- package/vendor/node_modules/@legendapp/spark-ui/src/types.ts +39 -6
- package/vendor/node_modules/@legendapp/spark-ui/uniwind.ts +3 -1
- package/vendor/node_modules/@legendapp/spark-ui/uniwind.web.ts +2 -1
- package/vendor/node_modules/@legendapp/spark-ui/windows/SparkUI/SparkUI.h +46 -15
- package/vendor/node_modules/@legendapp/spark-updates/package.json +3 -9
- package/vendor/node_modules/@legendapp/spark-webview/package.json +2 -2
- package/vendor/node_modules/@legendapp/spark-window-options/package.json +1 -1
|
@@ -5,21 +5,53 @@ import NativeButton from "./SparkButtonNativeComponent";
|
|
|
5
5
|
import NativeSelect from "./native-select/NativeSelectNativeComponent";
|
|
6
6
|
import WindowsSelect from "./SparkSelectNativeComponent";
|
|
7
7
|
import NativeSegmentedControl from "./native-select/NativeSegmentedControlNativeComponent";
|
|
8
|
+
import NativeRadioGroup from "./radio-group/RadioGroupNativeComponent";
|
|
9
|
+
import { RadioGroupFallback } from "./checkbox-unavailable";
|
|
8
10
|
import { SparkError } from "@legendapp/spark-desktop-app/src/contracts";
|
|
9
|
-
import { useControl, useTextValue, validateButton } from "./control";
|
|
11
|
+
import { macosButton, unsupportedPlatform, useControl, useTextValue, validateButton, validateCheckbox, validateRadioGroup, validateSegmented } from "./control";
|
|
10
12
|
import { getControlAvailability } from "./availability";
|
|
11
13
|
import { selectionIndex } from "./select";
|
|
12
|
-
import type { ButtonProps, TextInputProps, SelectProps, SegmentedControlProps } from "./types";
|
|
13
|
-
export type { ButtonProps, TextInputProps, ControlledTextInputProps, UncontrolledTextInputProps, SelectProps, SelectOption, SegmentedControlProps, ControlProps, ControlRef, ControlKind } from "./types";
|
|
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";
|
|
14
16
|
export { getControlAvailability } from "./availability";
|
|
15
17
|
|
|
18
|
+
// AppKit buttons report their intrinsic size, which sizes the view unless a style sets width or height.
|
|
19
|
+
// WinUI buttons do not, so they keep a fixed default frame.
|
|
20
|
+
function useIntrinsicSize(control: ReturnType<typeof useControl>) {
|
|
21
|
+
const [size, setSize] = useState<{ width: number; height: number }>();
|
|
22
|
+
function measured(event: NativeSyntheticEvent<{ width: number; height: number }>) {
|
|
23
|
+
if (!control.mounted()) return;
|
|
24
|
+
const { width, height } = event?.nativeEvent ?? {};
|
|
25
|
+
if (!Number.isFinite(width) || !Number.isFinite(height) || width < 0 || height < 0) { control.error(new SparkError("E_INVALID_DATA", "Invalid native control size")); return; }
|
|
26
|
+
setSize(previous => previous?.width === width && previous.height === height ? previous : { width, height });
|
|
27
|
+
}
|
|
28
|
+
return { frame: Platform.OS === "windows" ? { width: 160, height: 36 } : size, measured };
|
|
29
|
+
}
|
|
16
30
|
export function Button(props: ButtonProps) {
|
|
17
31
|
validateButton(props);
|
|
18
|
-
const
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
32
|
+
const { children, variant = "default", expanded, symbol, size = "regular", onPress, accessibilityLabel = children, style, testID } = props;
|
|
33
|
+
const disclosure = variant === "disclosure";
|
|
34
|
+
const control = useControl(props, Platform.OS === "windows" && macosButton(props) ? unsupportedPlatform : getControlAvailability("button"));
|
|
35
|
+
function symbolError(event: NativeSyntheticEvent<{ name: string; message: string }>) {
|
|
36
|
+
if (!control.mounted()) return;
|
|
37
|
+
if (typeof event?.nativeEvent?.name !== "string" || typeof event?.nativeEvent?.message !== "string") { control.error(new SparkError("E_INVALID_DATA", "Invalid symbol error")); return; }
|
|
38
|
+
if (event.nativeEvent.name === symbol) control.error(new SparkError("E_NOT_FOUND", event.nativeEvent.message));
|
|
39
|
+
}
|
|
40
|
+
const intrinsic = useIntrinsicSize(control);
|
|
41
|
+
const [revision, revise] = useState(0);
|
|
42
|
+
if (control.failed) return <View ref={control.ref} style={[{ width: 160, height: 36 }, style]} testID={testID} accessible accessibilityLabel={accessibilityLabel} accessibilityState={{ disabled: true, expanded }}><Text>{children}</Text></View>;
|
|
43
|
+
return <NativeButton ref={control.ref} title={children} disabled={control.disabled} variant={variant} checked={expanded ?? false} checkedRevision={revision} accessibilityLabel={accessibilityLabel} symbol={symbol ?? ""} controlSize={size} onSymbolError={symbolError}
|
|
44
|
+
onButtonPress={() => { if (!control.active()) return; if (disclosure) revise(value => value + 1); onPress?.(); }} onIntrinsicSize={intrinsic.measured} onUnavailable={control.unavailable} testID={testID} style={[intrinsic.frame, style]} />;
|
|
45
|
+
}
|
|
46
|
+
export function Checkbox(props: CheckboxProps) {
|
|
47
|
+
validateCheckbox(props);
|
|
48
|
+
const control = useControl(props, getControlAvailability("checkbox"));
|
|
49
|
+
const intrinsic = useIntrinsicSize(control);
|
|
50
|
+
const [revision, revise] = useState(0);
|
|
51
|
+
const { children = "", value, onValueChange, accessibilityLabel = children, style, testID } = props;
|
|
52
|
+
if (control.failed) return <View ref={control.ref} style={style} testID={testID} accessible accessibilityRole="checkbox" accessibilityLabel={accessibilityLabel} accessibilityState={{ checked: value, disabled: true }}><Text>{children}</Text></View>;
|
|
53
|
+
return <NativeButton ref={control.ref} title={children} disabled={control.disabled} variant="checkbox" checked={value} checkedRevision={revision} accessibilityLabel={accessibilityLabel}
|
|
54
|
+
onButtonPress={() => { if (!control.active()) return; revise(count => count + 1); onValueChange(!value); }} onIntrinsicSize={intrinsic.measured} onUnavailable={control.unavailable} testID={testID} style={[intrinsic.frame, style]} />;
|
|
23
55
|
}
|
|
24
56
|
export function TextInput(props: TextInputProps) {
|
|
25
57
|
const control = useControl(props, getControlAvailability("text-input"));
|
|
@@ -30,9 +62,10 @@ export function TextInput(props: TextInputProps) {
|
|
|
30
62
|
if (typeof data?.text !== "string" || !Number.isSafeInteger(data.eventCount) || data.eventCount < 1 || data.eventCount > 2147483647) { control.error(new SparkError("E_INVALID_DATA", "Invalid native text change")); return; }
|
|
31
63
|
if (value.acknowledge(data.eventCount)) props.onChangeText?.(data.text);
|
|
32
64
|
}
|
|
33
|
-
const { accessibilityLabel, style, testID } = props;
|
|
34
|
-
|
|
35
|
-
return <
|
|
65
|
+
const { accessibilityLabel, style, testID, placeholder, multiline = false } = props;
|
|
66
|
+
const size = { width: 240, height: multiline ? 80 : 36 };
|
|
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
|
+
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]} />;
|
|
36
69
|
}
|
|
37
70
|
function Selection({ segmented, ...props }: SelectProps & { segmented: boolean }) {
|
|
38
71
|
selectionIndex(props.options, props.value);
|
|
@@ -48,9 +81,26 @@ function Selection({ segmented, ...props }: SelectProps & { segmented: boolean }
|
|
|
48
81
|
}
|
|
49
82
|
const common = { ref: control.ref, value, accessibilityLabel, testID, style: [{ width: 240, height: 36 }, style], selectionRevision };
|
|
50
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>;
|
|
51
|
-
if (segmented) return <NativeSegmentedControl {...common} segmentsJson={JSON.stringify(options)} enabled={!control.disabled} onValueChange={changed} />;
|
|
84
|
+
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} />;
|
|
52
85
|
if (Platform.OS === "windows") return <WindowsSelect {...common} itemsJson={JSON.stringify(options)} disabled={control.disabled} onSelectionChange={changed} onUnavailable={control.unavailable} />;
|
|
53
86
|
return <NativeSelect {...common} itemsJson={JSON.stringify(options)} enabled={!control.disabled} onValueChange={changed} />;
|
|
54
87
|
}
|
|
55
88
|
export function Select(props: SelectProps) { return <Selection {...props} segmented={false} />; }
|
|
56
|
-
export function SegmentedControl(props: SegmentedControlProps) { return <Selection {...props} segmented />; }
|
|
89
|
+
export function SegmentedControl(props: SegmentedControlProps) { validateSegmented(props); return <Selection {...props} segmented />; }
|
|
90
|
+
/** AppKit radio buttons (NSButton) in a stack. Without a width or height style it takes its intrinsic size. */
|
|
91
|
+
export function RadioGroup(props: RadioGroupProps) {
|
|
92
|
+
validateRadioGroup(props);
|
|
93
|
+
const control = useControl(props, getControlAvailability("radio-group"));
|
|
94
|
+
const intrinsic = useIntrinsicSize(control);
|
|
95
|
+
const [selectionRevision, revise] = useState(0);
|
|
96
|
+
const { options, value, onValueChange, orientation = "vertical", size = "regular", accessibilityLabel, style, testID } = props;
|
|
97
|
+
function changed(event: NativeSyntheticEvent<{ value: string }>) {
|
|
98
|
+
if (!control.active()) return;
|
|
99
|
+
const next = event?.nativeEvent?.value;
|
|
100
|
+
if (!options.some(option => option.value === next)) { control.error(new SparkError("E_INVALID_DATA", "Native selection is not an option")); return; }
|
|
101
|
+
revise(revision => revision + 1); onValueChange(next);
|
|
102
|
+
}
|
|
103
|
+
if (control.failed) return <RadioGroupFallback {...props} controlRef={control.ref} />;
|
|
104
|
+
return <NativeRadioGroup ref={control.ref} itemsJson={JSON.stringify(options.map(({ label, value }) => ({ label, value })))} value={value} selectionRevision={selectionRevision} enabled={!control.disabled} orientation={orientation} controlSize={size}
|
|
105
|
+
accessibilityLabel={accessibilityLabel} testID={testID} onValueChange={changed} onIntrinsicSize={intrinsic.measured} style={[intrinsic.frame, style]} />;
|
|
106
|
+
}
|
|
@@ -18,20 +18,22 @@ 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
20
|
import { selectionIndex } from "./select";
|
|
21
|
-
import { useControl, validateButton } from "./control";
|
|
22
|
-
import
|
|
23
|
-
|
|
21
|
+
import { controlKinds, macosButton, unsupportedPlatform, useControl, validateButton, validateSegmented } from "./control";
|
|
22
|
+
import { UnavailableCheckbox, UnavailableRadioGroup } from "./checkbox-unavailable";
|
|
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
25
|
export { TextInput } from "./mobile-input";
|
|
25
26
|
export function getControlAvailability(control: ControlKind): Availability {
|
|
26
|
-
if (!
|
|
27
|
+
if (!controlKinds.includes(control)) throw new SparkError("E_INVALID_ARGUMENT", "Unknown control kind");
|
|
28
|
+
if (control === "checkbox" || control === "radio-group") return unsupportedPlatform;
|
|
27
29
|
return control === "text-input" || requireOptionalNativeModule("ExpoUI") ? { available: true } : { available: false, reason: "missing-module" };
|
|
28
30
|
}
|
|
29
31
|
export function Button(props: ButtonProps) {
|
|
30
|
-
validateButton(props); const control = useControl(props, getControlAvailability("button"));
|
|
32
|
+
validateButton(props); const control = useControl(props, macosButton(props) ? unsupportedPlatform : getControlAvailability("button"));
|
|
31
33
|
const { children, onPress, variant = "default", style, testID, accessibilityLabel = children } = props;
|
|
32
34
|
return <View ref={control.ref} style={[{ width: 160, height: 48 }, style]} testID={testID} accessibilityLabel={accessibilityLabel}>
|
|
33
35
|
{control.failed ? <Text accessibilityState={{ disabled: true }}>{children}</Text> :
|
|
34
|
-
<ExpoButton onClick={() => { if (control.active()) onPress?.(); }} enabled={!control.disabled} variant={variant} label={children} />}
|
|
36
|
+
<ExpoButton onClick={() => { if (control.active()) onPress?.(); }} enabled={!control.disabled} variant={variant as keyof typeof buttons} label={children} />}
|
|
35
37
|
</View>;
|
|
36
38
|
}
|
|
37
39
|
function Selection(props: SelectProps) {
|
|
@@ -46,4 +48,7 @@ function Selection(props: SelectProps) {
|
|
|
46
48
|
}
|
|
47
49
|
/** Android presents its choices inline; there is no dropdown backend in the pinned Expo UI. */
|
|
48
50
|
export function Select(props: SelectProps) { return <Selection {...props} />; }
|
|
49
|
-
export function
|
|
51
|
+
export function Checkbox(props: CheckboxProps) { return <UnavailableCheckbox {...props} availability={getControlAvailability("checkbox")} />; }
|
|
52
|
+
export function RadioGroup(props: RadioGroupProps) { return <UnavailableRadioGroup {...props} availability={getControlAvailability("radio-group")} />; }
|
|
53
|
+
/** Native mobile segmented pickers have one size and fill their frame; `size` and `distribution` keep those defaults here. */
|
|
54
|
+
export function SegmentedControl(props: SegmentedControlProps) { validateSegmented(props); return <Selection {...props} />; }
|
|
@@ -19,23 +19,25 @@ import { frame, buttonStyle, pickerStyle, tag, disabled as disabledModifier, acc
|
|
|
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
|
-
import { useControl, validateButton } from "./control";
|
|
22
|
+
import { controlKinds, macosButton, unsupportedPlatform, useControl, validateButton, validateSegmented } from "./control";
|
|
23
|
+
import { UnavailableCheckbox, UnavailableRadioGroup } from "./checkbox-unavailable";
|
|
23
24
|
import { selectionIndex } from "./select";
|
|
24
|
-
import type { ButtonProps, SelectProps, SegmentedControlProps, ControlKind } from "./types";
|
|
25
|
-
export type { ButtonProps, TextInputProps, ControlledTextInputProps, UncontrolledTextInputProps, SelectProps, SelectOption, SegmentedControlProps, ControlProps, ControlRef, ControlKind } from "./types";
|
|
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
27
|
export { TextInput } from "./mobile-input";
|
|
27
28
|
export function getControlAvailability(control: ControlKind): Availability {
|
|
28
|
-
if (!
|
|
29
|
+
if (!controlKinds.includes(control)) throw new SparkError("E_INVALID_ARGUMENT", "Unknown control kind");
|
|
30
|
+
if (control === "checkbox" || control === "radio-group") return unsupportedPlatform;
|
|
29
31
|
return control === "text-input" || requireOptionalNativeModule("ExpoUI") ? { available: true } : { available: false, reason: "missing-module" };
|
|
30
32
|
}
|
|
31
33
|
const fill = [frame({ maxWidth: Infinity, maxHeight: Infinity })];
|
|
32
34
|
export function Button(props: ButtonProps) {
|
|
33
|
-
validateButton(props); const control = useControl(props, getControlAvailability("button"));
|
|
35
|
+
validateButton(props); const control = useControl(props, macosButton(props) ? unsupportedPlatform : getControlAvailability("button"));
|
|
34
36
|
const { children, onPress, variant = "default", style, testID, accessibilityLabel = children } = props;
|
|
35
37
|
return <View ref={control.ref} style={[{ width: 160, height: 44 }, style]}>
|
|
36
38
|
{control.failed ? <Text accessibilityLabel={accessibilityLabel} accessibilityState={{ disabled: true }} testID={testID}>{children}</Text> :
|
|
37
39
|
<Host style={{ flex: 1 }}><ExpoButton label={children} onPress={() => { if (control.active()) onPress?.(); }}
|
|
38
|
-
modifiers={[...fill, buttonStyle(variant === "default" ? "automatic" : variant), disabledModifier(control.disabled), labelModifier(accessibilityLabel)]} testID={testID} /></Host>}
|
|
40
|
+
modifiers={[...fill, buttonStyle(variant === "default" ? "automatic" : variant as "bordered" | "borderless"), disabledModifier(control.disabled), labelModifier(accessibilityLabel)]} testID={testID} /></Host>}
|
|
39
41
|
</View>;
|
|
40
42
|
}
|
|
41
43
|
function Selection({ segmented, ...props }: SelectProps & { segmented: boolean }) {
|
|
@@ -61,4 +63,7 @@ function Selection({ segmented, ...props }: SelectProps & { segmented: boolean }
|
|
|
61
63
|
</View>;
|
|
62
64
|
}
|
|
63
65
|
export function Select(props: SelectProps) { return <Selection {...props} segmented={false} />; }
|
|
64
|
-
export function
|
|
66
|
+
export function Checkbox(props: CheckboxProps) { return <UnavailableCheckbox {...props} availability={getControlAvailability("checkbox")} />; }
|
|
67
|
+
export function RadioGroup(props: RadioGroupProps) { return <UnavailableRadioGroup {...props} availability={getControlAvailability("radio-group")} />; }
|
|
68
|
+
/** Native mobile segmented pickers have one size and fill their frame; `size` and `distribution` keep those defaults here. */
|
|
69
|
+
export function SegmentedControl(props: SegmentedControlProps) { validateSegmented(props); return <Selection {...props} segmented />; }
|
|
@@ -2,28 +2,38 @@ import { selectionIndex } 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
|
-
import { useControl, useTextValue, validateButton } from "./control";
|
|
6
|
-
import type { ButtonProps, TextInputProps, SelectProps, SegmentedControlProps, ControlKind } from "./types";
|
|
7
|
-
export type { ButtonProps, TextInputProps, ControlledTextInputProps, UncontrolledTextInputProps, SelectProps, SelectOption, SegmentedControlProps, ControlProps, ControlRef, ControlKind } from "./types";
|
|
5
|
+
import { controlKinds, unsupportedPlatform, useControl, useTextValue, validateButton, validateCheckbox, validateRadioGroup, validateSegmented } from "./control";
|
|
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";
|
|
8
8
|
export function getControlAvailability(control: ControlKind): Availability {
|
|
9
|
-
if (!
|
|
9
|
+
if (!controlKinds.includes(control)) throw new SparkError("E_INVALID_ARGUMENT", "Unknown control kind");
|
|
10
10
|
return { available: true };
|
|
11
11
|
}
|
|
12
12
|
const nativeStyle: CSSProperties = { width: "100%", height: "100%", boxSizing: "border-box", font: "14px system-ui" };
|
|
13
13
|
const borderlessStyle: CSSProperties = { ...nativeStyle, border: "none", background: "transparent" };
|
|
14
14
|
export function Button(props: ButtonProps) {
|
|
15
|
-
validateButton(props); const control = useControl(props);
|
|
16
|
-
const { children, onPress, variant = "default", accessibilityLabel = children, style, testID } = props;
|
|
15
|
+
validateButton(props); const control = useControl(props, props.symbol !== undefined ? unsupportedPlatform : undefined);
|
|
16
|
+
const { children, onPress, variant = "default", expanded, size = "regular", accessibilityLabel = children, style, testID } = props;
|
|
17
|
+
const font = size === "regular" ? nativeStyle.font : size === "small" ? "12px system-ui" : "10px system-ui";
|
|
17
18
|
return <View ref={control.ref} style={[{ width: 160, height: 36 }, style]} testID={testID}>
|
|
18
|
-
<button type="button" disabled={control.disabled} onClick={() => { if (control.active()) onPress?.(); }} aria-label={accessibilityLabel}
|
|
19
|
-
style={variant === "borderless" ? borderlessStyle : nativeStyle}>{children}</button>
|
|
19
|
+
<button type="button" disabled={control.disabled || control.failed} onClick={() => { if (control.active()) onPress?.(); }} aria-label={accessibilityLabel} aria-expanded={expanded}
|
|
20
|
+
style={{ ...(variant === "borderless" ? borderlessStyle : nativeStyle), font }}>{variant === "disclosure" ? (expanded ? "\u25B4" : "\u25BE") : children}</button>
|
|
21
|
+
</View>;
|
|
22
|
+
}
|
|
23
|
+
export function Checkbox(props: CheckboxProps) {
|
|
24
|
+
validateCheckbox(props); const control = useControl(props);
|
|
25
|
+
return <View ref={control.ref} style={props.style} testID={props.testID}>
|
|
26
|
+
<label style={{ display: "inline-flex", alignItems: "center", gap: 6, font: "14px system-ui" }}>
|
|
27
|
+
<input type="checkbox" checked={props.value} disabled={control.disabled} aria-label={props.accessibilityLabel} onChange={() => { if (control.active()) props.onValueChange(!props.value); }} />{props.children}
|
|
28
|
+
</label>
|
|
20
29
|
</View>;
|
|
21
30
|
}
|
|
22
31
|
export function TextInput(props: TextInputProps) {
|
|
23
32
|
const control = useControl(props), state = useTextValue(props);
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
33
|
+
const field = { value: state.controlled ? state.text : undefined, defaultValue: state.controlled ? undefined : state.defaultText, disabled: control.disabled, placeholder: props.placeholder,
|
|
34
|
+
onChange: (event: { currentTarget: { value: string } }) => { if (control.active()) props.onChangeText?.(event.currentTarget.value); }, "aria-label": props.accessibilityLabel };
|
|
35
|
+
return <View ref={control.ref} style={[{ width: 240, height: props.multiline ? 80 : 36 }, props.style]} testID={props.testID}>
|
|
36
|
+
{props.multiline ? <textarea {...field} style={{ ...nativeStyle, resize: "none" }} /> : <input type="text" {...field} style={nativeStyle} />}
|
|
27
37
|
</View>;
|
|
28
38
|
}
|
|
29
39
|
function useSelection(props: SelectProps) {
|
|
@@ -45,10 +55,22 @@ export function Select(props: SelectProps) {
|
|
|
45
55
|
</View>;
|
|
46
56
|
}
|
|
47
57
|
export function SegmentedControl(props: SegmentedControlProps) {
|
|
48
|
-
|
|
58
|
+
validateSegmented(props);
|
|
59
|
+
const control = useSelection(props), fill = props.distribution === "fill", font = props.size === "small" ? "12px system-ui" : nativeStyle.font;
|
|
49
60
|
return <View ref={control.ref} style={[{ width: 240, height: 36 }, props.style]} testID={props.testID}>
|
|
50
61
|
<div role="group" aria-label={props.accessibilityLabel} style={{ display: "flex", width: "100%", height: "100%" }}>
|
|
51
|
-
{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, flex: 1 }}>{option.label}</button>)}
|
|
62
|
+
{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
|
+
</div>
|
|
64
|
+
</View>;
|
|
65
|
+
}
|
|
66
|
+
export function RadioGroup(props: RadioGroupProps) {
|
|
67
|
+
validateRadioGroup(props);
|
|
68
|
+
const control = useSelection(props), font = props.size === "small" ? "12px system-ui" : props.size === "mini" ? "10px system-ui" : nativeStyle.font;
|
|
69
|
+
return <View ref={control.ref} style={props.style} testID={props.testID}>
|
|
70
|
+
<div role="radiogroup" aria-label={props.accessibilityLabel} style={{ display: "flex", flexDirection: props.orientation === "horizontal" ? "row" : "column", gap: props.orientation === "horizontal" ? 16 : 6, font }}>
|
|
71
|
+
{props.options.map(option => <label key={option.value} style={{ display: "inline-flex", alignItems: "center", gap: 6 }}>
|
|
72
|
+
<input type="radio" checked={option.value === props.value} disabled={control.disabled} onChange={() => control.change(option.value)} />{option.label}
|
|
73
|
+
</label>)}
|
|
52
74
|
</div>
|
|
53
75
|
</View>;
|
|
54
76
|
}
|
|
@@ -5,7 +5,7 @@ import type { TextInputProps } from "./types";
|
|
|
5
5
|
export function TextInput(props: TextInputProps) {
|
|
6
6
|
const control = useControl(props), state = useTextValue(props);
|
|
7
7
|
return <RNTextInput ref={control.ref} value={state.controlled ? state.text : undefined} defaultValue={state.defaultText}
|
|
8
|
-
onChangeText={text => { if (control.active()) props.onChangeText?.(text); }} editable={!control.disabled} multiline={false}
|
|
8
|
+
onChangeText={text => { if (control.active()) props.onChangeText?.(text); }} editable={!control.disabled} multiline={props.multiline ?? false} placeholder={props.placeholder}
|
|
9
9
|
accessibilityLabel={props.accessibilityLabel} accessibilityState={{ disabled: control.disabled }} testID={props.testID}
|
|
10
|
-
style={[{ width: 240, height: 44, borderWidth: 1, borderColor: "#8e8e93", borderRadius: 6, paddingHorizontal: 8 }, props.style]} />;
|
|
10
|
+
style={[{ width: 240, height: props.multiline ? 88 : 44, textAlignVertical: "top", borderWidth: 1, borderColor: "#8e8e93", borderRadius: 6, paddingHorizontal: 8 }, props.style]} />;
|
|
11
11
|
}
|
|
@@ -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 } from "react-native/Libraries/Types/CodegenTypes";
|
|
3
|
+
import type { DirectEventHandler, Int32, WithDefault } from "react-native/Libraries/Types/CodegenTypes";
|
|
4
4
|
|
|
5
5
|
export type NativeSegmentedControlChangeEvent = {
|
|
6
6
|
value: string;
|
|
@@ -8,6 +8,8 @@ export type NativeSegmentedControlChangeEvent = {
|
|
|
8
8
|
|
|
9
9
|
export interface NativeProps extends ViewProps {
|
|
10
10
|
enabled?: boolean;
|
|
11
|
+
controlSize?: WithDefault<"regular" | "small", "regular">;
|
|
12
|
+
distribution?: WithDefault<"fit" | "fill", "fit">;
|
|
11
13
|
selectionRevision?: Int32;
|
|
12
14
|
segmentsJson: string;
|
|
13
15
|
onValueChange?: DirectEventHandler<NativeSegmentedControlChangeEvent>;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { CodegenTypes, HostComponent, ViewProps } from "react-native";
|
|
2
|
+
import { codegenNativeComponent } from "react-native";
|
|
3
|
+
|
|
4
|
+
export interface NativeProps extends ViewProps {
|
|
5
|
+
/** Shown once the content has a size. The second child is the content; it is hosted in the NSPopover. */
|
|
6
|
+
visible?: CodegenTypes.WithDefault<boolean, false>;
|
|
7
|
+
contentWidth?: CodegenTypes.Double;
|
|
8
|
+
contentHeight?: CodegenTypes.Double;
|
|
9
|
+
edge?: CodegenTypes.WithDefault<"bottom" | "top" | "leading" | "trailing", "bottom">;
|
|
10
|
+
behavior?: CodegenTypes.WithDefault<"transient" | "semitransient" | "applicationDefined", "transient">;
|
|
11
|
+
/** Positioning rect in the view's coordinates; used when anchorWidth or anchorHeight is positive, else the view's bounds. */
|
|
12
|
+
anchorX?: CodegenTypes.Double;
|
|
13
|
+
anchorY?: CodegenTypes.Double;
|
|
14
|
+
anchorWidth?: CodegenTypes.Double;
|
|
15
|
+
anchorHeight?: CodegenTypes.Double;
|
|
16
|
+
/** AppKit closed the popover itself (a click outside, Escape). */
|
|
17
|
+
onClose?: CodegenTypes.DirectEventHandler<Readonly<{}>>;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export default codegenNativeComponent<NativeProps>("SparkPopover") as HostComponent<NativeProps>;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { useState, type ReactNode } from "react";
|
|
2
|
+
import { View, type LayoutChangeEvent } from "react-native";
|
|
3
|
+
import { SparkError } from "@legendapp/spark-desktop-app/src/contracts";
|
|
4
|
+
import { useControl } from "../control";
|
|
5
|
+
import { callback, finite, macosViewAvailability, type SpecializedViewProps } from "../specialized";
|
|
6
|
+
import NativePopover from "./PopoverNativeComponent";
|
|
7
|
+
export interface PopoverAnchorRect { x: number; y: number; width: number; height: number }
|
|
8
|
+
export interface PopoverProps extends SpecializedViewProps {
|
|
9
|
+
/** Controlled visibility. */
|
|
10
|
+
visible: boolean;
|
|
11
|
+
/** React content shown in the popover. Give it a width; without one, text wraps to the anchor's width. */
|
|
12
|
+
content: ReactNode;
|
|
13
|
+
/** Called when AppKit closes a visible popover (a click outside or Escape); set `visible` to false in it. */
|
|
14
|
+
onClose?: () => void;
|
|
15
|
+
/** Preferred side of the anchor: `bottom` (default), `top`, `leading` or `trailing`. AppKit flips it when there is no room. */
|
|
16
|
+
edge?: "bottom" | "top" | "leading" | "trailing";
|
|
17
|
+
/** `transient` (default) closes on any click outside; `semitransient` stays open for clicks in other windows; `applicationDefined` closes only when `visible` turns false. */
|
|
18
|
+
behavior?: "transient" | "semitransient" | "applicationDefined";
|
|
19
|
+
/** A rect within this view to point at, such as a text selection. Defaults to the whole view. */
|
|
20
|
+
anchorRect?: PopoverAnchorRect;
|
|
21
|
+
}
|
|
22
|
+
export function getPopoverAvailability() { return macosViewAvailability("SparkPopover"); }
|
|
23
|
+
/** AppKit's NSPopover, anchored to this view (its children) or to `anchorRect` within it, hosting React `content`. */
|
|
24
|
+
export function Popover({ visible, content, onClose, edge = "bottom", behavior = "transient", anchorRect, ref, onError, children, ...props }: PopoverProps) {
|
|
25
|
+
if (typeof visible !== "boolean" || !["bottom", "top", "leading", "trailing"].includes(edge) || !["transient", "semitransient", "applicationDefined"].includes(behavior)) throw new SparkError("E_INVALID_ARGUMENT", "Invalid popover options");
|
|
26
|
+
callback(onClose, "onClose");
|
|
27
|
+
if (anchorRect !== undefined) {
|
|
28
|
+
if (!anchorRect || typeof anchorRect !== "object") throw new SparkError("E_INVALID_ARGUMENT", "Invalid popover anchorRect");
|
|
29
|
+
finite(anchorRect.x, "anchorRect x", -Infinity); finite(anchorRect.y, "anchorRect y", -Infinity); finite(anchorRect.width, "anchorRect width"); finite(anchorRect.height, "anchorRect height");
|
|
30
|
+
}
|
|
31
|
+
const control = useControl({ ref, onError }, getPopoverAvailability());
|
|
32
|
+
const [size, setSize] = useState<{ width: number; height: number }>();
|
|
33
|
+
const shown = visible && !control.failed;
|
|
34
|
+
if (!shown && size) setSize(undefined);
|
|
35
|
+
function measured(event: LayoutChangeEvent) {
|
|
36
|
+
const { width, height } = event.nativeEvent.layout;
|
|
37
|
+
setSize(previous => previous?.width === width && previous.height === height ? previous : { width, height });
|
|
38
|
+
}
|
|
39
|
+
if (control.failed) return <View {...props} ref={control.ref}>{children}</View>;
|
|
40
|
+
return <NativePopover {...props} ref={control.ref} visible={shown} contentWidth={size?.width ?? 0} contentHeight={size?.height ?? 0} edge={edge} behavior={behavior}
|
|
41
|
+
anchorX={anchorRect?.x ?? 0} anchorY={anchorRect?.y ?? 0} anchorWidth={anchorRect?.width ?? 0} anchorHeight={anchorRect?.height ?? 0} onClose={() => { if (control.mounted()) onClose?.(); }}>
|
|
42
|
+
<View collapsable={false}>{children}</View>
|
|
43
|
+
{shown ? <View collapsable={false} style={{ position: "absolute", left: 0, top: 0 }} onLayout={measured}>{content}</View> : null}
|
|
44
|
+
</NativePopover>;
|
|
45
|
+
}
|
package/vendor/node_modules/@legendapp/spark-ui/src/progress/ProgressIndicatorNativeComponent.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { CodegenTypes, HostComponent, ViewProps } from "react-native";
|
|
2
|
+
import { codegenNativeComponent } from "react-native";
|
|
3
|
+
|
|
4
|
+
export interface NativeProps extends ViewProps {
|
|
5
|
+
variant?: CodegenTypes.WithDefault<"bar" | "spinner", "bar">;
|
|
6
|
+
controlSize?: CodegenTypes.WithDefault<"regular" | "small" | "mini", "regular">;
|
|
7
|
+
/** Determinate progress from 0 to 1; ignored while `indeterminate`. */
|
|
8
|
+
value?: CodegenTypes.Double;
|
|
9
|
+
indeterminate?: CodegenTypes.WithDefault<boolean, true>;
|
|
10
|
+
onIntrinsicSize?: CodegenTypes.DirectEventHandler<Readonly<{ width: CodegenTypes.Double; height: CodegenTypes.Double }>>;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export default codegenNativeComponent<NativeProps>("SparkProgressIndicator") as HostComponent<NativeProps>;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { useState } from "react";
|
|
2
|
+
import { View, type NativeSyntheticEvent } from "react-native";
|
|
3
|
+
import { SparkError } from "@legendapp/spark-desktop-app/src/contracts";
|
|
4
|
+
import { useControl } from "../control";
|
|
5
|
+
import { finite, macosViewAvailability, type SpecializedViewProps } from "../specialized";
|
|
6
|
+
import NativeProgressIndicator from "./ProgressIndicatorNativeComponent";
|
|
7
|
+
export interface ProgressIndicatorProps extends Omit<SpecializedViewProps, "children"> {
|
|
8
|
+
/** `bar` (default) or `spinner`. */
|
|
9
|
+
variant?: "bar" | "spinner";
|
|
10
|
+
/** Determinate progress from 0 to 1. Omitted or `null` animates as indeterminate. */
|
|
11
|
+
value?: number | null;
|
|
12
|
+
/** AppKit control size: `regular` (default) or `small`; spinners also take `mini`. */
|
|
13
|
+
size?: "regular" | "small" | "mini";
|
|
14
|
+
}
|
|
15
|
+
export function getProgressIndicatorAvailability() { return macosViewAvailability("SparkProgressIndicator"); }
|
|
16
|
+
/** AppKit's NSProgressIndicator. A spinner takes its native size; a bar takes its native height and the style's width. */
|
|
17
|
+
export function ProgressIndicator({ variant = "bar", value, size = "regular", ref, onError, style, ...props }: ProgressIndicatorProps) {
|
|
18
|
+
if (!["bar", "spinner"].includes(variant) || !["regular", "small", "mini"].includes(size) || (variant === "bar" && size === "mini")) throw new SparkError("E_INVALID_ARGUMENT", "Invalid progress indicator options");
|
|
19
|
+
if (value !== undefined && value !== null) finite(value, "progress value", 0, 1);
|
|
20
|
+
const control = useControl({ ref, onError }, getProgressIndicatorAvailability());
|
|
21
|
+
const [intrinsic, setIntrinsic] = useState<{ width: number; height: number }>();
|
|
22
|
+
function measured(event: NativeSyntheticEvent<{ width: number; height: number }>) {
|
|
23
|
+
if (!control.mounted()) return;
|
|
24
|
+
const { width, height } = event?.nativeEvent ?? {};
|
|
25
|
+
if (!Number.isFinite(width) || !Number.isFinite(height) || width < 0 || height < 0) { control.error(new SparkError("E_INVALID_DATA", "Invalid native progress size")); return; }
|
|
26
|
+
setIntrinsic(previous => previous?.width === width && previous.height === height ? previous : { width, height });
|
|
27
|
+
}
|
|
28
|
+
const frame = [intrinsic && (variant === "spinner" ? intrinsic : { height: intrinsic.height }), style];
|
|
29
|
+
if (control.failed) return <View {...props} ref={control.ref} style={style} />;
|
|
30
|
+
const determinate = value !== undefined && value !== null;
|
|
31
|
+
return <NativeProgressIndicator {...props} ref={control.ref} variant={variant} controlSize={size} value={determinate ? value : 0} indeterminate={!determinate} onIntrinsicSize={measured} style={frame} />;
|
|
32
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { CodegenTypes, HostComponent, ViewProps } from "react-native";
|
|
2
|
+
import { codegenNativeComponent } from "react-native";
|
|
3
|
+
|
|
4
|
+
export interface NativeProps extends ViewProps {
|
|
5
|
+
/** JSON array of `{ label, value }`. */
|
|
6
|
+
itemsJson: string;
|
|
7
|
+
value: string;
|
|
8
|
+
/** Re-applies `value` when it changes, so a click the app does not accept snaps back. */
|
|
9
|
+
selectionRevision?: CodegenTypes.Int32;
|
|
10
|
+
enabled?: CodegenTypes.WithDefault<boolean, true>;
|
|
11
|
+
orientation?: CodegenTypes.WithDefault<"vertical" | "horizontal", "vertical">;
|
|
12
|
+
controlSize?: CodegenTypes.WithDefault<"regular" | "small" | "mini", "regular">;
|
|
13
|
+
onValueChange?: CodegenTypes.DirectEventHandler<Readonly<{ value: string }>>;
|
|
14
|
+
onIntrinsicSize?: CodegenTypes.DirectEventHandler<Readonly<{ width: CodegenTypes.Double; height: CodegenTypes.Double }>>;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export default codegenNativeComponent<NativeProps>("SparkRadioGroup") as HostComponent<NativeProps>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { CodegenTypes, HostComponent, ViewProps } from "react-native";
|
|
2
|
+
import { codegenNativeComponent } from "react-native";
|
|
3
|
+
|
|
4
|
+
export interface NativeProps extends ViewProps {
|
|
5
|
+
/** Shown once the content has a size. The child is the content; it is hosted in a sheet on this view's window. */
|
|
6
|
+
visible?: CodegenTypes.WithDefault<boolean, false>;
|
|
7
|
+
contentWidth?: CodegenTypes.Double;
|
|
8
|
+
contentHeight?: CodegenTypes.Double;
|
|
9
|
+
/** Escape or ⌘. in the sheet. */
|
|
10
|
+
onCancel?: CodegenTypes.DirectEventHandler<Readonly<{}>>;
|
|
11
|
+
/** Sent while `visible` is false and content is still mounted (after the close animation if the sheet was open); the content may unmount. */
|
|
12
|
+
onDismiss?: CodegenTypes.DirectEventHandler<Readonly<{}>>;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export default codegenNativeComponent<NativeProps>("SparkSheet") as HostComponent<NativeProps>;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { useState, type ReactNode } from "react";
|
|
2
|
+
import { View, type LayoutChangeEvent } from "react-native";
|
|
3
|
+
import { SparkError } from "@legendapp/spark-desktop-app/src/contracts";
|
|
4
|
+
import { useControl } from "../control";
|
|
5
|
+
import { callback, macosViewAvailability, type SpecializedViewProps } from "../specialized";
|
|
6
|
+
import NativeSheet from "./SheetNativeComponent";
|
|
7
|
+
export interface SheetProps extends Omit<SpecializedViewProps, "children"> {
|
|
8
|
+
/** Controlled visibility. */
|
|
9
|
+
visible: boolean;
|
|
10
|
+
/** React content shown in the sheet, at its own layout size: give it a width and height (or content that sizes it). */
|
|
11
|
+
children: ReactNode;
|
|
12
|
+
/** Escape or ⌘. in the sheet; set `visible` to false in it to close. The sheet never closes itself. */
|
|
13
|
+
onCancel?: () => void;
|
|
14
|
+
}
|
|
15
|
+
export function getSheetAvailability() { return macosViewAvailability("SparkSheet"); }
|
|
16
|
+
/** A document-modal sheet on this view's window, hosting React content (a form, say). Render it anywhere in the window. */
|
|
17
|
+
export function Sheet({ visible, children, onCancel, ref, onError, style, ...props }: SheetProps) {
|
|
18
|
+
if (typeof visible !== "boolean") throw new SparkError("E_INVALID_ARGUMENT", "Invalid sheet visibility");
|
|
19
|
+
callback(onCancel, "onCancel");
|
|
20
|
+
const control = useControl({ ref, onError }, getSheetAvailability());
|
|
21
|
+
const [size, setSize] = useState<{ width: number; height: number }>();
|
|
22
|
+
// The content stays mounted until the sheet has finished closing, so it does not animate away blank.
|
|
23
|
+
const [contentMounted, setContentMounted] = useState(visible);
|
|
24
|
+
if (visible && !contentMounted) setContentMounted(true);
|
|
25
|
+
function dismissed() {
|
|
26
|
+
if (!control.mounted() || visible) return;
|
|
27
|
+
setContentMounted(false); setSize(undefined);
|
|
28
|
+
}
|
|
29
|
+
function measured(event: LayoutChangeEvent) {
|
|
30
|
+
const { width, height } = event.nativeEvent.layout;
|
|
31
|
+
setSize(previous => previous?.width === width && previous.height === height ? previous : { width, height });
|
|
32
|
+
}
|
|
33
|
+
if (control.failed) return visible ? <View {...props} ref={control.ref} style={style} accessibilityViewIsModal>{children}</View> : null;
|
|
34
|
+
return <NativeSheet {...props} ref={control.ref} style={[{ position: "absolute", width: 0, height: 0 }, style]} visible={visible} contentWidth={size?.width ?? 0} contentHeight={size?.height ?? 0}
|
|
35
|
+
onCancel={() => { if (control.mounted()) onCancel?.(); }} onDismiss={dismissed}>
|
|
36
|
+
{contentMounted ? <View collapsable={false} style={{ position: "absolute", left: 0, top: 0 }} onLayout={measured}>{children}</View> : null}
|
|
37
|
+
</NativeSheet>;
|
|
38
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { HostComponent, ViewProps } from "react-native";
|
|
2
2
|
import { codegenNativeComponent } from "react-native";
|
|
3
|
-
import type { DirectEventHandler, Double } 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 SidebarItemRightClickEvent = Readonly<{
|
|
6
6
|
altKey: boolean;
|
|
@@ -14,10 +14,18 @@ export type SidebarItemRightClickEvent = Readonly<{
|
|
|
14
14
|
y: Double;
|
|
15
15
|
}>;
|
|
16
16
|
|
|
17
|
+
export type SidebarItemLayoutEvent = Readonly<{
|
|
18
|
+
width: Double;
|
|
19
|
+
}>;
|
|
20
|
+
|
|
17
21
|
export interface NativeProps extends ViewProps {
|
|
18
22
|
autoHeight?: boolean;
|
|
23
|
+
count?: WithDefault<Int32, -1>;
|
|
24
|
+
group?: boolean;
|
|
19
25
|
itemId?: string;
|
|
20
26
|
onRightClick?: DirectEventHandler<SidebarItemRightClickEvent>;
|
|
27
|
+
onSidebarItemLayout?: DirectEventHandler<SidebarItemLayoutEvent>;
|
|
28
|
+
parentId?: string;
|
|
21
29
|
rowHeight?: Double;
|
|
22
30
|
selectable?: boolean;
|
|
23
31
|
}
|
|
@@ -1,9 +1,19 @@
|
|
|
1
1
|
import type { HostComponent, ViewProps } from "react-native";
|
|
2
2
|
import { codegenNativeComponent } from "react-native";
|
|
3
|
-
import type { DirectEventHandler, Double, Int32 } 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 SidebarSelectionChangeEvent = Readonly<{
|
|
6
6
|
id: string;
|
|
7
|
+
idsJson: string;
|
|
8
|
+
}>;
|
|
9
|
+
|
|
10
|
+
export type SidebarExpandedChangeEvent = Readonly<{
|
|
11
|
+
expanded: boolean;
|
|
12
|
+
id: string;
|
|
13
|
+
}>;
|
|
14
|
+
|
|
15
|
+
export type SidebarDoubleClickEvent = Readonly<{
|
|
16
|
+
id: string;
|
|
7
17
|
}>;
|
|
8
18
|
|
|
9
19
|
export type SidebarLayoutEvent = Readonly<{
|
|
@@ -16,13 +26,18 @@ export type SidebarRowLayoutEvent = Readonly<{
|
|
|
16
26
|
}>;
|
|
17
27
|
|
|
18
28
|
export interface NativeProps extends ViewProps {
|
|
29
|
+
allowsMultipleSelection?: boolean;
|
|
30
|
+
collapsedIdsJson?: string;
|
|
19
31
|
contentInsetTop?: Double;
|
|
20
32
|
defaultRowHeight?: Double;
|
|
21
33
|
itemsJson?: string;
|
|
34
|
+
listStyle?: WithDefault<"sidebar" | "plain", "sidebar">;
|
|
35
|
+
onSidebarDoubleClick?: DirectEventHandler<SidebarDoubleClickEvent>;
|
|
36
|
+
onSidebarExpandedChange?: DirectEventHandler<SidebarExpandedChangeEvent>;
|
|
22
37
|
onSidebarLayout?: DirectEventHandler<SidebarLayoutEvent>;
|
|
23
38
|
onSidebarRowLayout?: DirectEventHandler<SidebarRowLayoutEvent>;
|
|
24
39
|
onSidebarSelectionChange?: DirectEventHandler<SidebarSelectionChangeEvent>;
|
|
25
|
-
|
|
40
|
+
selectedIdsJson?: string;
|
|
26
41
|
selectionRevision?: Int32;
|
|
27
42
|
}
|
|
28
43
|
|