@legendapp/spark 0.0.2 → 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.
Files changed (224) hide show
  1. package/init-template.cjs +7 -1
  2. package/package.json +10 -5
  3. package/patches/dependencies.json +252 -0
  4. package/patches/expo-application@55.0.19.patch +54 -0
  5. package/patches/expo-blur@55.0.18.patch +130 -0
  6. package/patches/expo-device@55.0.21.patch +149 -0
  7. package/patches/expo-font@55.0.8.patch +55 -0
  8. package/patches/expo-glass-effect@55.0.11.patch +304 -0
  9. package/patches/expo-haptics@55.0.18.patch +54 -0
  10. package/patches/expo-image-manipulator@55.0.21.patch +312 -0
  11. package/patches/expo-image-picker@55.0.24.patch +327 -0
  12. package/patches/expo-image@55.0.11.patch +158 -0
  13. package/patches/expo-keep-awake@55.0.8.patch +41 -0
  14. package/patches/expo-localization@55.0.19.patch +32 -0
  15. package/patches/expo-location@55.1.15.patch +190 -0
  16. package/patches/expo-symbols@55.0.9.patch +286 -0
  17. package/patches/expo-system-ui@55.0.22.patch +61 -0
  18. package/patches/expo-web-browser@55.0.20.patch +13 -0
  19. package/patches/react-native-app-logs@0.3.1.patch +20 -0
  20. package/patches/react-native-blurhash@2.1.3.patch +318 -0
  21. package/patches/react-native-community-blur@4.4.1.patch +415 -0
  22. package/patches/react-native-community-datetimepicker@9.2.2.patch +320 -0
  23. package/patches/react-native-fast-image@10.9.9.patch +131 -0
  24. package/patches/react-native-graph@1.4.0.patch +157 -0
  25. package/patches/react-native-keyboard-controller@1.22.9.patch +16 -0
  26. package/patches/react-native-masked-view-masked-view@0.3.2.patch +140 -0
  27. package/patches/react-native-mmkv@4.3.2.patch +40 -0
  28. package/patches/react-native-nitro-fetch@1.9.0.patch +130 -0
  29. package/patches/react-native-nitro-zxing@0.3.0.patch +13 -0
  30. package/patches/react-native-nitro-zxing@0.3.1.patch +22 -0
  31. package/patches/react-native-quick-base64@3.0.1.patch +13 -0
  32. package/patches/react-native-quick-crypto@1.1.9.patch +31 -0
  33. package/patches/react-native-release-profiler@0.4.5.patch +37 -0
  34. package/patches/react-native-screen-corner-radius@0.2.3.patch +13 -0
  35. package/patches/react-native-screens@4.23.0.patch +160 -0
  36. package/patches/react-native-svg@15.15.3.patch +31 -0
  37. package/patches/react-native-unistyles@3.6.0.patch +203 -0
  38. package/patches/react-native-worklets-core@1.6.3.patch +13 -0
  39. package/patches/react-navigation-native-stack@7.21.0.patch +16 -0
  40. package/patches/registry.json +615 -0
  41. package/patches/sentry-react-native@8.32.0.patch +76 -0
  42. package/patches/workspace/expo-audio@55.0.18.patch +159 -0
  43. package/patches/workspace/op-engineering-op-sqlite@18.2.1.patch +796 -0
  44. package/patches/workspace/react-native-nitro-modules@0.37.0.patch +1348 -0
  45. package/patches/workspace/react-native-runtimes-core@0.1.0-alpha.2.patch +276 -0
  46. package/patches/workspace/react-native-webview@16.0.0.patch +208 -0
  47. package/postinstall.cjs +10 -1
  48. package/skills/spark/SKILL.md +37 -4
  49. package/skills/spark/UPGRADING.md +150 -1
  50. package/skills/spark/ai-customize.md +39 -0
  51. package/skills/spark/app-and-documents.md +56 -0
  52. package/skills/spark/external-libraries.md +87 -0
  53. package/skills/spark/files.md +64 -0
  54. package/skills/spark/integrations.md +69 -0
  55. package/skills/spark/keyboard.md +54 -0
  56. package/skills/spark/library-compat.md +76 -0
  57. package/skills/spark/menus-tray-dock.md +83 -0
  58. package/skills/spark/storage-settings.md +85 -0
  59. package/skills/spark/ui.md +57 -0
  60. package/skills/spark/windows.md +91 -0
  61. package/ui-popover.ts +1 -0
  62. package/ui-progress.ts +1 -0
  63. package/ui-sheet.ts +1 -0
  64. package/ui-split-view.ts +1 -0
  65. package/ui-table.ts +1 -0
  66. package/vendor/node_modules/@legendapp/spark-ai/package.json +3 -3
  67. package/vendor/node_modules/@legendapp/spark-audio/package.json +3 -13
  68. package/vendor/node_modules/@legendapp/spark-auth-session/package.json +3 -10
  69. package/vendor/node_modules/@legendapp/spark-cli/dist/add-desktop.js +5 -0
  70. package/vendor/node_modules/@legendapp/spark-cli/dist/build.js +139 -104
  71. package/vendor/node_modules/@legendapp/spark-cli/dist/cli-arguments.js +4 -1
  72. package/vendor/node_modules/@legendapp/spark-cli/dist/commands.js +16 -7
  73. package/vendor/node_modules/@legendapp/spark-cli/dist/dependency-pins.js +19 -3
  74. package/vendor/node_modules/@legendapp/spark-cli/dist/dev-command.js +2 -0
  75. package/vendor/node_modules/@legendapp/spark-cli/dist/dev.js +10 -2
  76. package/vendor/node_modules/@legendapp/spark-cli/dist/enriched-html-pins.js +2 -0
  77. package/vendor/node_modules/@legendapp/spark-cli/dist/errors.js +1 -1
  78. package/vendor/node_modules/@legendapp/spark-cli/dist/index.js +57 -9
  79. package/vendor/node_modules/@legendapp/spark-cli/dist/init-template.cjs +12 -2
  80. package/vendor/node_modules/@legendapp/spark-cli/dist/init-template.d.cts +1 -1
  81. package/vendor/node_modules/@legendapp/spark-cli/dist/metro.cjs +1 -0
  82. package/vendor/node_modules/@legendapp/spark-cli/dist/migrate.js +65 -0
  83. package/vendor/node_modules/@legendapp/spark-cli/dist/migration-helpers.cjs +4 -4
  84. package/vendor/node_modules/@legendapp/spark-cli/dist/migration-helpers.d.cts +2 -2
  85. package/vendor/node_modules/@legendapp/spark-cli/dist/migrations.cjs +15 -8
  86. package/vendor/node_modules/@legendapp/spark-cli/dist/native-patch-preflight.js +35 -7
  87. package/vendor/node_modules/@legendapp/spark-cli/dist/patch.js +92 -0
  88. package/vendor/node_modules/@legendapp/spark-cli/dist/project-version.js +12 -4
  89. package/vendor/node_modules/@legendapp/spark-cli/dist/project.js +20 -1
  90. package/vendor/node_modules/@legendapp/spark-cli/dist/release.json +20 -20
  91. package/vendor/node_modules/@legendapp/spark-cli/dist/runtime-input-cache.js +140 -0
  92. package/vendor/node_modules/@legendapp/spark-cli/dist/upgrade.js +1 -1
  93. package/vendor/node_modules/@legendapp/spark-cli/dist/windows.js +3 -0
  94. package/vendor/node_modules/@legendapp/spark-cli/package.json +5 -4
  95. package/vendor/node_modules/@legendapp/spark-cli/templates/blank-typescript/package.json +2 -2
  96. package/vendor/node_modules/@legendapp/spark-cli/templates/universal/package.json +2 -2
  97. package/vendor/node_modules/@legendapp/spark-cli/templates/windows/package.json +2 -2
  98. package/vendor/node_modules/@legendapp/spark-clipboard/macos/RNDesktopClipboard.mm +1 -1
  99. package/vendor/node_modules/@legendapp/spark-clipboard/package.json +3 -10
  100. package/vendor/node_modules/@legendapp/spark-clipboard/src/desktop.ts +1 -0
  101. package/vendor/node_modules/@legendapp/spark-codex/package.json +3 -7
  102. package/vendor/node_modules/@legendapp/spark-commands/package.json +5 -5
  103. package/vendor/node_modules/@legendapp/spark-context-menu/package.json +3 -10
  104. package/vendor/node_modules/@legendapp/spark-desktop-app/macos/SparkDesktop.h +3 -1
  105. package/vendor/node_modules/@legendapp/spark-desktop-app/macos/SparkDesktop.mm +51 -10
  106. package/vendor/node_modules/@legendapp/spark-desktop-app/macos/SparkStorage.h +4 -0
  107. package/vendor/node_modules/@legendapp/spark-desktop-app/macos/SparkStorage.mm +82 -0
  108. package/vendor/node_modules/@legendapp/spark-desktop-app/macos/SparkTestDriver.mm +64 -2
  109. package/vendor/node_modules/@legendapp/spark-desktop-app/package.json +2 -8
  110. package/vendor/node_modules/@legendapp/spark-desktop-config/autolinking.cjs +3 -2
  111. package/vendor/node_modules/@legendapp/spark-desktop-config/config.cjs +6 -8
  112. package/vendor/node_modules/@legendapp/spark-desktop-config/identity.cjs +2 -0
  113. package/vendor/node_modules/@legendapp/spark-desktop-config/native-patches.cjs +315 -68
  114. package/vendor/node_modules/@legendapp/spark-desktop-config/native-patches.d.cts +7 -0
  115. package/vendor/node_modules/@legendapp/spark-desktop-config/package.json +3 -3
  116. package/vendor/node_modules/@legendapp/spark-desktop-config/patch-registry.cjs +318 -0
  117. package/vendor/node_modules/@legendapp/spark-desktop-config/patch-registry.d.cts +20 -0
  118. package/vendor/node_modules/@legendapp/spark-desktop-config/validation.cjs +66 -9
  119. package/vendor/node_modules/@legendapp/spark-desktop-config/windows.plugin.cjs +1 -0
  120. package/vendor/node_modules/@legendapp/spark-desktop-host/AppDelegate.mm +1 -0
  121. package/vendor/node_modules/@legendapp/spark-desktop-host/package.json +2 -2
  122. package/vendor/node_modules/@legendapp/spark-desktop-links/package.json +3 -10
  123. package/vendor/node_modules/@legendapp/spark-desktop-shortcuts/package.json +3 -10
  124. package/vendor/node_modules/@legendapp/spark-desktop-windows/macos/RNDesktopWindows.mm +7 -2
  125. package/vendor/node_modules/@legendapp/spark-desktop-windows/macos/window-manager/RNWindowManager.mm +235 -240
  126. package/vendor/node_modules/@legendapp/spark-desktop-windows/package.json +4 -11
  127. package/vendor/node_modules/@legendapp/spark-desktop-windows/src/api.ts +9 -3
  128. package/vendor/node_modules/@legendapp/spark-desktop-windows/src/macos-adapter.ts +7 -0
  129. package/vendor/node_modules/@legendapp/spark-desktop-windows/src/types.ts +32 -3
  130. package/vendor/node_modules/@legendapp/spark-desktop-windows/src/validation.ts +28 -11
  131. package/vendor/node_modules/@legendapp/spark-desktop-windows/src/windows/createWindowsNavigator.tsx +15 -3
  132. package/vendor/node_modules/@legendapp/spark-desktop-windows/src/windows/primaryWindowLifecycle.ts +12 -3
  133. package/vendor/node_modules/@legendapp/spark-desktop-windows/src/windows/usePrimaryWindowLifecycle.ts +2 -1
  134. package/vendor/node_modules/@legendapp/spark-desktop-windows/src/windows/useWindowFocusEffect.ts +4 -1
  135. package/vendor/node_modules/@legendapp/spark-documents/package.json +7 -7
  136. package/vendor/node_modules/@legendapp/spark-drag-drop/macos/RNDesktopDragView.mm +77 -17
  137. package/vendor/node_modules/@legendapp/spark-drag-drop/package.json +3 -8
  138. package/vendor/node_modules/@legendapp/spark-drag-drop/src/DesktopDragViewNativeComponent.ts +1 -0
  139. package/vendor/node_modules/@legendapp/spark-drag-drop/src/contracts.ts +13 -4
  140. package/vendor/node_modules/@legendapp/spark-drag-drop/src/index.tsx +5 -3
  141. package/vendor/node_modules/@legendapp/spark-drag-drop/windows/SparkDragDrop/SparkDragDrop.h +6 -1
  142. package/vendor/node_modules/@legendapp/spark-expo-compat/metro.cjs +44 -0
  143. package/vendor/node_modules/@legendapp/spark-expo-compat/package.json +20 -0
  144. package/vendor/node_modules/@legendapp/spark-expo-compat/src/clipboard.ts +40 -0
  145. package/vendor/node_modules/@legendapp/spark-expo-compat/src/document-picker.ts +52 -0
  146. package/vendor/node_modules/@legendapp/spark-file-dialog/package.json +3 -10
  147. package/vendor/node_modules/@legendapp/spark-file-dialog/src/options.ts +5 -2
  148. package/vendor/node_modules/@legendapp/spark-file-dialog/src/types.ts +3 -3
  149. package/vendor/node_modules/@legendapp/spark-file-system/macos/RNDesktopFileSystem.mm +1 -1
  150. package/vendor/node_modules/@legendapp/spark-file-system/package.json +3 -11
  151. package/vendor/node_modules/@legendapp/spark-global-shortcuts/package.json +3 -10
  152. package/vendor/node_modules/@legendapp/spark-html/package.json +2 -2
  153. package/vendor/node_modules/@legendapp/spark-markdown/package.json +2 -2
  154. package/vendor/node_modules/@legendapp/spark-message-dialog/package.json +3 -10
  155. package/vendor/node_modules/@legendapp/spark-message-dialog/src/index.ts +1 -0
  156. package/vendor/node_modules/@legendapp/spark-native-menu/package.json +3 -9
  157. package/vendor/node_modules/@legendapp/spark-native-menu/src/hooks.ts +4 -0
  158. package/vendor/node_modules/@legendapp/spark-notifications/package.json +3 -10
  159. package/vendor/node_modules/@legendapp/spark-processes/package.json +3 -10
  160. package/vendor/node_modules/@legendapp/spark-rich-text/package.json +2 -2
  161. package/vendor/node_modules/@legendapp/spark-secure-storage/package.json +3 -10
  162. package/vendor/node_modules/@legendapp/spark-settings/package.json +3 -3
  163. package/vendor/node_modules/@legendapp/spark-settings-ui/package.json +4 -4
  164. package/vendor/node_modules/@legendapp/spark-sqlite/package.json +3 -3
  165. package/vendor/node_modules/@legendapp/spark-system/package.json +3 -10
  166. package/vendor/node_modules/@legendapp/spark-tray/package.json +3 -10
  167. package/vendor/node_modules/@legendapp/spark-tray/src/index.ts +2 -1
  168. package/vendor/node_modules/@legendapp/spark-ui/macos/RNSparkButton.mm +82 -14
  169. package/vendor/node_modules/@legendapp/spark-ui/macos/RNSparkTextInput.h +1 -1
  170. package/vendor/node_modules/@legendapp/spark-ui/macos/RNSparkTextInput.mm +94 -11
  171. package/vendor/node_modules/@legendapp/spark-ui/macos/appkit-split-view/RNSidebarSplitViewComponent.mm +235 -18
  172. package/vendor/node_modules/@legendapp/spark-ui/macos/appkit-split-view/RNSparkPaneSplitView.h +17 -0
  173. package/vendor/node_modules/@legendapp/spark-ui/macos/appkit-split-view/RNSparkPaneSplitView.mm +216 -0
  174. package/vendor/node_modules/@legendapp/spark-ui/macos/appkit-split-view/RNSparkSplitViewComponent.h +4 -0
  175. package/vendor/node_modules/@legendapp/spark-ui/macos/appkit-split-view/RNSparkSplitViewComponent.mm +212 -0
  176. package/vendor/node_modules/@legendapp/spark-ui/macos/appkit-split-view/RNSparkSplitViewUpdates.h +6 -0
  177. package/vendor/node_modules/@legendapp/spark-ui/macos/native-select/RNNativeSegmentedControl.mm +26 -13
  178. package/vendor/node_modules/@legendapp/spark-ui/macos/popover/RNSparkPopover.h +9 -0
  179. package/vendor/node_modules/@legendapp/spark-ui/macos/popover/RNSparkPopover.mm +126 -0
  180. package/vendor/node_modules/@legendapp/spark-ui/macos/progress/RNSparkProgressIndicator.h +9 -0
  181. package/vendor/node_modules/@legendapp/spark-ui/macos/progress/RNSparkProgressIndicator.mm +66 -0
  182. package/vendor/node_modules/@legendapp/spark-ui/macos/radio-group/RNSparkRadioGroup.h +9 -0
  183. package/vendor/node_modules/@legendapp/spark-ui/macos/radio-group/RNSparkRadioGroup.mm +118 -0
  184. package/vendor/node_modules/@legendapp/spark-ui/macos/sf-symbol/RNSFSymbol.mm +4 -12
  185. package/vendor/node_modules/@legendapp/spark-ui/macos/sheet/RNSparkSheet.h +9 -0
  186. package/vendor/node_modules/@legendapp/spark-ui/macos/sheet/RNSparkSheet.mm +109 -0
  187. package/vendor/node_modules/@legendapp/spark-ui/macos/sidebar/RNSidebar.mm +418 -102
  188. package/vendor/node_modules/@legendapp/spark-ui/macos/table/RNSparkTable.h +9 -0
  189. package/vendor/node_modules/@legendapp/spark-ui/macos/table/RNSparkTable.mm +179 -0
  190. package/vendor/node_modules/@legendapp/spark-ui/package.json +9 -8
  191. package/vendor/node_modules/@legendapp/spark-ui/src/SparkButtonNativeComponent.ts +10 -2
  192. package/vendor/node_modules/@legendapp/spark-ui/src/SparkTextInputNativeComponent.ts +2 -0
  193. package/vendor/node_modules/@legendapp/spark-ui/src/appkit-split-view/SidebarSplitViewNativeComponent.ts +9 -0
  194. package/vendor/node_modules/@legendapp/spark-ui/src/appkit-split-view/SplitView.tsx +99 -0
  195. package/vendor/node_modules/@legendapp/spark-ui/src/appkit-split-view/SplitViewNativeComponent.ts +29 -0
  196. package/vendor/node_modules/@legendapp/spark-ui/src/appkit-split-view/index.tsx +34 -17
  197. package/vendor/node_modules/@legendapp/spark-ui/src/availability.ts +5 -4
  198. package/vendor/node_modules/@legendapp/spark-ui/src/checkbox-unavailable.tsx +20 -0
  199. package/vendor/node_modules/@legendapp/spark-ui/src/control.ts +24 -3
  200. package/vendor/node_modules/@legendapp/spark-ui/src/desktop.tsx +63 -13
  201. package/vendor/node_modules/@legendapp/spark-ui/src/index.android.tsx +12 -7
  202. package/vendor/node_modules/@legendapp/spark-ui/src/index.ios.tsx +12 -7
  203. package/vendor/node_modules/@legendapp/spark-ui/src/index.web.tsx +35 -13
  204. package/vendor/node_modules/@legendapp/spark-ui/src/mobile-input.tsx +2 -2
  205. package/vendor/node_modules/@legendapp/spark-ui/src/native-select/NativeSegmentedControlNativeComponent.ts +3 -1
  206. package/vendor/node_modules/@legendapp/spark-ui/src/popover/PopoverNativeComponent.ts +20 -0
  207. package/vendor/node_modules/@legendapp/spark-ui/src/popover/index.tsx +45 -0
  208. package/vendor/node_modules/@legendapp/spark-ui/src/progress/ProgressIndicatorNativeComponent.ts +13 -0
  209. package/vendor/node_modules/@legendapp/spark-ui/src/progress/index.tsx +32 -0
  210. package/vendor/node_modules/@legendapp/spark-ui/src/radio-group/RadioGroupNativeComponent.ts +17 -0
  211. package/vendor/node_modules/@legendapp/spark-ui/src/sheet/SheetNativeComponent.ts +15 -0
  212. package/vendor/node_modules/@legendapp/spark-ui/src/sheet/index.tsx +38 -0
  213. package/vendor/node_modules/@legendapp/spark-ui/src/sidebar/SidebarItemNativeComponent.ts +9 -1
  214. package/vendor/node_modules/@legendapp/spark-ui/src/sidebar/SidebarNativeComponent.ts +17 -2
  215. package/vendor/node_modules/@legendapp/spark-ui/src/sidebar/index.tsx +106 -22
  216. package/vendor/node_modules/@legendapp/spark-ui/src/table/TableNativeComponent.ts +22 -0
  217. package/vendor/node_modules/@legendapp/spark-ui/src/table/index.tsx +118 -0
  218. package/vendor/node_modules/@legendapp/spark-ui/src/types.ts +39 -6
  219. package/vendor/node_modules/@legendapp/spark-ui/uniwind.ts +3 -1
  220. package/vendor/node_modules/@legendapp/spark-ui/uniwind.web.ts +2 -1
  221. package/vendor/node_modules/@legendapp/spark-ui/windows/SparkUI/SparkUI.h +46 -15
  222. package/vendor/node_modules/@legendapp/spark-updates/package.json +3 -9
  223. package/vendor/node_modules/@legendapp/spark-webview/package.json +2 -2
  224. package/vendor/node_modules/@legendapp/spark-window-options/package.json +1 -1
@@ -5,9 +5,21 @@ import { useControl } from "../control";
5
5
  import { callback, finite, identifier, macosViewAvailability, type SpecializedViewProps } from "../specialized";
6
6
  import NativeSidebar from "./SidebarNativeComponent";
7
7
  import NativeSidebarItem from "./SidebarItemNativeComponent";
8
- export interface SidebarItemData { id: string; label: string; selectable?: boolean }
8
+ export interface SidebarItemData {
9
+ id: string;
10
+ label: string;
11
+ selectable?: boolean;
12
+ /** A section header: the source list's group-row style, never selectable. */
13
+ group?: boolean;
14
+ /** A trailing count in the system's secondary style. */
15
+ count?: number;
16
+ /** Nested rows, shown under a disclosure (Show/Hide on group rows). */
17
+ children?: readonly SidebarItemData[];
18
+ }
9
19
  export type SidebarRowHeight = number | "auto";
10
- export interface SidebarSelectionEvent { id: string | null }
20
+ export interface SidebarSelectionEvent { id: string | null; ids: string[] }
21
+ export interface SidebarExpandedChangeEvent { id: string; expanded: boolean }
22
+ export interface SidebarDoubleClickEvent { id: string }
11
23
  export interface SidebarContentLayoutEvent { width: number; height: number }
12
24
  export interface SidebarContextMenuEvent {
13
25
  id: string;
@@ -16,20 +28,55 @@ export interface SidebarContextMenuEvent {
16
28
  windowPosition: { x: number; y: number };
17
29
  modifiers: { alt: boolean; control: boolean; meta: boolean; shift: boolean };
18
30
  }
31
+ export type SidebarListStyle = "sidebar" | "plain";
19
32
  export interface SidebarBaseProps extends Omit<SpecializedViewProps, "children"> {
20
33
  contentInsetTop?: number;
34
+ /** `sidebar` (default) is the source list for window sidebars; `plain` is a content list with standard selection. */
35
+ listStyle?: SidebarListStyle;
21
36
  defaultRowHeight?: number;
22
- selectedId: string | null;
37
+ /** IDs of collapsed rows. Applied when the value changes; the user's toggles report through `onExpandedChange`. */
38
+ collapsedIds?: readonly string[];
39
+ onExpandedChange?: (event: SidebarExpandedChangeEvent) => void;
40
+ onDoubleClick?: (event: SidebarDoubleClickEvent) => void;
23
41
  onContentLayout?: (event: SidebarContentLayoutEvent) => void;
24
42
  onSelectionChange: (event: SidebarSelectionEvent) => void;
25
43
  }
26
- export type SidebarProps = SidebarBaseProps & ({ items: readonly SidebarItemData[]; children?: never } | { items?: never; children: ReactNode });
44
+ /** `selectedId` selects one row; `selectedIds` enables multiple selection (⌘/⇧-click). */
45
+ export type SidebarSelectionProps = { selectedId: string | null; selectedIds?: never } | { selectedIds: readonly string[]; selectedId?: never };
46
+ export type SidebarProps = SidebarBaseProps & SidebarSelectionProps & ({ items: readonly SidebarItemData[]; children?: never } | { items?: never; children: ReactNode });
27
47
  export interface SidebarItemProps extends SpecializedViewProps {
28
48
  id: string;
49
+ /** Nests this row under an earlier row. */
50
+ parentId?: string;
51
+ /** A section header: the source list's group-row style, never selectable. */
52
+ group?: boolean;
53
+ /** A trailing count in the system's secondary style, beside the row's content. */
54
+ count?: number;
29
55
  rowHeight?: SidebarRowHeight;
30
56
  selectable?: boolean;
31
57
  onContextMenu?: (event: SidebarContextMenuEvent) => void;
32
58
  }
59
+ interface SidebarEntry { id: string; label?: string; selectable?: boolean; group?: boolean; count?: number; parentId?: string }
60
+ function count(value: unknown) {
61
+ if (value !== undefined && (typeof value !== "number" || !Number.isInteger(value) || value < 0)) throw new SparkError("E_INVALID_ARGUMENT", "Sidebar count must be a non-negative integer");
62
+ }
63
+ function flag(value: unknown, name: string) {
64
+ if (value !== undefined && typeof value !== "boolean") throw new SparkError("E_INVALID_ARGUMENT", `Expected ${name} boolean`);
65
+ }
66
+ function flattenItems(items: readonly SidebarItemData[], parentId: string | undefined, entries: SidebarEntry[]) {
67
+ if (!Array.isArray(items)) throw new SparkError("E_INVALID_ARGUMENT", "Expected sidebar items array");
68
+ for (const item of items) {
69
+ if (!item || typeof item !== "object") throw new SparkError("E_INVALID_ARGUMENT", "Invalid sidebar item");
70
+ entries.push({ id: item.id, label: item.label, selectable: item.selectable, group: item.group, count: item.count, parentId });
71
+ if (item.children !== undefined) flattenItems(item.children, item.id, entries);
72
+ }
73
+ return entries;
74
+ }
75
+ function stringList(value: unknown, name: string): readonly string[] {
76
+ if (!Array.isArray(value)) throw new SparkError("E_INVALID_ARGUMENT", `Expected ${name} array`);
77
+ for (const id of value) identifier(id, name);
78
+ return value;
79
+ }
33
80
  // Inside a Sidebar: the row width the native list reports, which React rows take, since it excludes
34
81
  // the source-list insets and a scroller. Undefined until the first native layout.
35
82
  const SidebarContext = createContext<{ rowWidth: number | undefined } | null>(null);
@@ -47,34 +94,60 @@ function childRows(children: ReactNode): ReactElement<SidebarItemProps>[] {
47
94
  });
48
95
  return rows;
49
96
  }
50
- export function Sidebar({ items, children, selectedId, contentInsetTop = 0, defaultRowHeight = 28, onContentLayout, onSelectionChange, ref, onError, ...props }: SidebarProps) {
97
+ export function Sidebar({ items, children, selectedId, selectedIds, collapsedIds, contentInsetTop = 0, defaultRowHeight = 28, listStyle = "sidebar", onContentLayout, onDoubleClick, onExpandedChange, onSelectionChange, ref, onError, ...props }: SidebarProps) {
51
98
  finite(contentInsetTop, "content inset"); finite(defaultRowHeight, "row height", 1);
52
- callback(onContentLayout, "content layout");
99
+ callback(onContentLayout, "content layout"); callback(onDoubleClick, "double click"); callback(onExpandedChange, "expanded change");
100
+ if (listStyle !== "sidebar" && listStyle !== "plain") throw new SparkError("E_INVALID_ARGUMENT", "Invalid sidebar list style");
53
101
  if (typeof onSelectionChange !== "function") throw new SparkError("E_INVALID_ARGUMENT", "Sidebar selection is controlled and requires onSelectionChange");
54
102
  if (items !== undefined && (children !== undefined || !Array.isArray(items))) throw new SparkError("E_INVALID_ARGUMENT", "Use either items or SidebarItem children");
103
+ const multiple = selectedIds !== undefined;
104
+ if (multiple === (selectedId !== undefined)) throw new SparkError("E_INVALID_ARGUMENT", "Use either selectedId or selectedIds");
55
105
  const { selectableIds, itemsJson } = useMemo(() => {
56
- const rows = items === undefined ? childRows(children) : [];
57
- const entries = items === undefined ? rows.map(row => ({ id: row.props.id, selectable: row.props.selectable })) : items;
106
+ const entries = items === undefined ? childRows(children).map(row => ({ ...row.props, label: undefined })) : flattenItems(items, undefined, []);
58
107
  const ids = new Set<string>(), selectableIds = new Set<string>();
59
108
  for (const item of entries) {
60
- if (!item || typeof item !== "object") throw new SparkError("E_INVALID_ARGUMENT", "Invalid sidebar item");
61
109
  identifier(item.id, "sidebar ID");
62
- if (ids.has(item.id)) throw new SparkError("E_INVALID_ARGUMENT", "Sidebar IDs must be unique"); ids.add(item.id);
63
- if (item.selectable !== undefined && typeof item.selectable !== "boolean") throw new SparkError("E_INVALID_ARGUMENT", "Expected selectable boolean");
64
- if (items !== undefined) identifier((item as SidebarItemData).label, "sidebar label");
65
- if (item.selectable !== false) selectableIds.add(item.id);
110
+ if (ids.has(item.id)) throw new SparkError("E_INVALID_ARGUMENT", "Sidebar IDs must be unique");
111
+ if (item.parentId !== undefined && !ids.has(item.parentId)) throw new SparkError("E_INVALID_ARGUMENT", "Sidebar parentId must identify an earlier row");
112
+ ids.add(item.id);
113
+ flag(item.selectable, "selectable"); flag(item.group, "group"); count(item.count);
114
+ if (item.group && item.selectable) throw new SparkError("E_INVALID_ARGUMENT", "Sidebar group rows are not selectable");
115
+ if (items !== undefined) identifier(item.label, "sidebar label");
116
+ if (item.selectable !== false && !item.group) selectableIds.add(item.id);
66
117
  }
67
- return { selectableIds, itemsJson: items === undefined ? "" : JSON.stringify(items.map(({ id, label, selectable = true }) => ({ id, title: label, selectable }))) };
118
+ return { selectableIds, itemsJson: items === undefined ? "" : JSON.stringify(entries.map(({ id, label, group, selectable = !group, count, parentId }) =>
119
+ ({ id, title: label, selectable, ...(group ? { group } : {}), ...(count !== undefined ? { count } : {}), ...(parentId !== undefined ? { parentId } : {}) }))) };
68
120
  }, [items, children]);
69
- if (selectedId !== null && !selectableIds.has(selectedId)) throw new SparkError("E_INVALID_ARGUMENT", "Selected sidebar ID must identify a selectable row");
121
+ const selected = multiple ? stringList(selectedIds, "selected sidebar ID") : selectedId === null ? [] : [selectedId];
122
+ for (const id of selected) if (!selectableIds.has(id)) throw new SparkError("E_INVALID_ARGUMENT", "Selected sidebar ID must identify a selectable row");
123
+ if (new Set(selected).size !== selected.length) throw new SparkError("E_INVALID_ARGUMENT", "Selected sidebar IDs must be unique");
124
+ const selectedKey = selected.join("\n");
125
+ const selectedIdsJson = useMemo(() => JSON.stringify(selected), [selectedKey]);
126
+ const collapsedIdsJson = useMemo(() => collapsedIds === undefined ? "" : JSON.stringify(stringList(collapsedIds, "collapsed sidebar ID")), [collapsedIds]);
70
127
  const control = useControl({ ref, onError }, getSidebarAvailability());
71
128
  const [selectionRevision, revise] = useState(0);
72
129
  const [rowWidth, setRowWidth] = useState<number>();
73
- function selection(event: NativeSyntheticEvent<{ id: string }>) {
130
+ function selection(event: NativeSyntheticEvent<{ id: string; idsJson: string }>) {
74
131
  if (!control.active()) return;
75
132
  const id = event?.nativeEvent?.id;
76
- if (typeof id !== "string" || (id !== "" && !selectableIds.has(id))) { control.error(new SparkError("E_INVALID_DATA", "Invalid sidebar selection")); return; }
77
- revise(value => value + 1); onSelectionChange?.({ id: id || null });
133
+ let ids: unknown;
134
+ try { ids = JSON.parse(event?.nativeEvent?.idsJson); } catch { ids = undefined; }
135
+ if (typeof id !== "string" || !Array.isArray(ids) || (id !== "" && !ids.includes(id)) || ids.some(value => typeof value !== "string" || !selectableIds.has(value)) || (!multiple && ids.length > 1)) {
136
+ control.error(new SparkError("E_INVALID_DATA", "Invalid sidebar selection")); return;
137
+ }
138
+ revise(value => value + 1); onSelectionChange?.({ id: id || null, ids: ids as string[] });
139
+ }
140
+ function expandedChange(event: NativeSyntheticEvent<{ id: string; expanded: boolean }>) {
141
+ if (!control.active()) return;
142
+ const data = event?.nativeEvent;
143
+ if (typeof data?.id !== "string" || data.id === "" || typeof data.expanded !== "boolean") { control.error(new SparkError("E_INVALID_DATA", "Invalid sidebar expansion")); return; }
144
+ onExpandedChange?.({ id: data.id, expanded: data.expanded });
145
+ }
146
+ function doubleClick(event: NativeSyntheticEvent<{ id: string }>) {
147
+ if (!control.active()) return;
148
+ const id = event?.nativeEvent?.id;
149
+ if (typeof id !== "string" || id === "") { control.error(new SparkError("E_INVALID_DATA", "Invalid sidebar double click")); return; }
150
+ onDoubleClick?.({ id });
78
151
  }
79
152
  function layout(event: NativeSyntheticEvent<{ width: number; height: number }>) {
80
153
  if (!control.active()) return;
@@ -89,15 +162,19 @@ export function Sidebar({ items, children, selectedId, contentInsetTop = 0, defa
89
162
  setRowWidth(event.nativeEvent.width);
90
163
  }
91
164
  const context = useMemo(() => ({ rowWidth }), [rowWidth]);
92
- if (control.failed) return <View {...props} ref={control.ref}><SidebarContext.Provider value={context}>{items?.map(item => <Text key={item.id}>{item.label}</Text>) ?? children}</SidebarContext.Provider></View>;
93
- return <NativeSidebar {...props} ref={control.ref} itemsJson={itemsJson} selectedId={selectedId ?? ""} selectionRevision={selectionRevision} contentInsetTop={contentInsetTop} defaultRowHeight={defaultRowHeight} onSidebarLayout={layout} onSidebarRowLayout={rowLayout} onSidebarSelectionChange={selection}>
165
+ if (control.failed) return <View {...props} ref={control.ref}><SidebarContext.Provider value={context}>{items ? flattenItems(items, undefined, []).map(item => <Text key={item.id}>{item.label}</Text>) : children}</SidebarContext.Provider></View>;
166
+ return <NativeSidebar {...props} ref={control.ref} itemsJson={itemsJson} listStyle={listStyle} allowsMultipleSelection={multiple} selectedIdsJson={selectedIdsJson} selectionRevision={selectionRevision} collapsedIdsJson={collapsedIdsJson} contentInsetTop={contentInsetTop} defaultRowHeight={defaultRowHeight} onSidebarLayout={layout} onSidebarRowLayout={rowLayout} onSidebarSelectionChange={selection} onSidebarExpandedChange={expandedChange} onSidebarDoubleClick={doubleClick}>
94
167
  <SidebarContext.Provider value={context}>{children}</SidebarContext.Provider>
95
168
  </NativeSidebar>;
96
169
  }
97
- export function SidebarItem({ id, children, rowHeight, selectable = true, onContextMenu, ref, onError, style, ...props }: SidebarItemProps) {
170
+ export function SidebarItem({ id, children, parentId, group = false, count: rowCount, rowHeight, selectable = !group, onContextMenu, ref, onError, style, ...props }: SidebarItemProps) {
98
171
  const sidebar = useContext(SidebarContext);
99
172
  if (!sidebar) throw new SparkError("E_INVALID_ARGUMENT", "SidebarItem requires a Sidebar parent");
100
173
  identifier(id, "sidebar ID"); callback(onContextMenu, "context menu");
174
+ if (parentId !== undefined) identifier(parentId, "sidebar parentId");
175
+ flag(group, "group"); count(rowCount);
176
+ if (group && selectable) throw new SparkError("E_INVALID_ARGUMENT", "Sidebar group rows are not selectable");
177
+ const [ownWidth, setOwnWidth] = useState<number>();
101
178
  if (rowHeight !== undefined && rowHeight !== "auto") finite(rowHeight, "row height", 1);
102
179
  if (typeof selectable !== "boolean") throw new SparkError("E_INVALID_ARGUMENT", "Expected selectable boolean");
103
180
  const control = useControl({ ref, onError }, getSidebarAvailability());
@@ -110,6 +187,13 @@ export function SidebarItem({ id, children, rowHeight, selectable = true, onCont
110
187
  } catch (cause) { control.error(new SparkError("E_INVALID_DATA", "Invalid sidebar context menu event", { cause })); return; }
111
188
  onContextMenu?.({ id, position: { x: data.x, y: data.y }, windowPosition: { x: data.pageX, y: data.pageY }, modifiers: { alt: data.altKey, control: data.ctrlKey, meta: data.metaKey, shift: data.shiftKey } });
112
189
  }
190
+ function itemLayout(event: NativeSyntheticEvent<{ width: number }>) {
191
+ if (!control.active()) return;
192
+ try { finite(event?.nativeEvent?.width, "row width"); }
193
+ catch (cause) { control.error(new SparkError("E_INVALID_DATA", "Invalid sidebar row layout", { cause })); return; }
194
+ setOwnWidth(event.nativeEvent.width);
195
+ }
113
196
  if (control.failed) return <View {...props} style={style} ref={control.ref}>{children}</View>;
114
- return <NativeSidebarItem {...props} style={sidebar.rowWidth === undefined ? style : [style, { width: sidebar.rowWidth }]} ref={control.ref} itemId={id} autoHeight={rowHeight === "auto"} rowHeight={typeof rowHeight === "number" ? rowHeight : 0} selectable={selectable} onRightClick={contextMenu}>{children}</NativeSidebarItem>;
197
+ const width = ownWidth ?? sidebar.rowWidth;
198
+ return <NativeSidebarItem {...props} style={width === undefined ? style : [style, { width }]} ref={control.ref} itemId={id} parentId={parentId ?? ""} group={group} count={rowCount ?? -1} autoHeight={rowHeight === "auto"} rowHeight={typeof rowHeight === "number" ? rowHeight : 0} selectable={selectable} onRightClick={contextMenu} onSidebarItemLayout={itemLayout}>{children}</NativeSidebarItem>;
115
199
  }
@@ -0,0 +1,22 @@
1
+ import type { CodegenTypes, HostComponent, ViewProps } from "react-native";
2
+ import { codegenNativeComponent } from "react-native";
3
+
4
+ export interface NativeProps extends ViewProps {
5
+ /** [{ id, title, width?, minWidth?, maxWidth?, alignment?, monospacedDigits?, secondary? }] */
6
+ columnsJson?: string;
7
+ /** [{ id, values: { [columnId]: string } }] */
8
+ rowsJson?: string;
9
+ selectedIdsJson?: string;
10
+ /** Changes after each native selection so the parent's `selectedIdsJson` is re-applied even when unchanged. */
11
+ selectionRevision?: CodegenTypes.Int32;
12
+ allowsMultipleSelection?: CodegenTypes.WithDefault<boolean, false>;
13
+ headerVisible?: CodegenTypes.WithDefault<boolean, true>;
14
+ alternatingRows?: CodegenTypes.WithDefault<boolean, false>;
15
+ rowHeight?: CodegenTypes.Double;
16
+ reportsColumnResize?: boolean;
17
+ onTableSelectionChange?: CodegenTypes.DirectEventHandler<Readonly<{ id: string; idsJson: string }>>;
18
+ onTableColumnResize?: CodegenTypes.DirectEventHandler<Readonly<{ id: string; width: CodegenTypes.Double }>>;
19
+ onTableDoubleClick?: CodegenTypes.DirectEventHandler<Readonly<{ id: string }>>;
20
+ }
21
+
22
+ export default codegenNativeComponent<NativeProps>("SparkTable") as HostComponent<NativeProps>;
@@ -0,0 +1,118 @@
1
+ import { useMemo, useState } from "react";
2
+ import { Text, View, type NativeSyntheticEvent } from "react-native";
3
+ import { SparkError } from "@legendapp/spark-desktop-app/src/contracts";
4
+ import { useControl } from "../control";
5
+ import { callback, finite, identifier, macosViewAvailability, type SpecializedViewProps } from "../specialized";
6
+ import NativeTable from "./TableNativeComponent";
7
+ export interface TableColumn {
8
+ id: string;
9
+ /** Header title. */
10
+ title: string;
11
+ /** Fixed width (the user can still resize it). Columns without one share the remaining width. */
12
+ width?: number;
13
+ minWidth?: number;
14
+ maxWidth?: number;
15
+ /** Text alignment of the header and cells: `leading` (default), `center` or `trailing`. */
16
+ alignment?: "leading" | "center" | "trailing";
17
+ /** Tabular digits, for numbers, dates and hashes. */
18
+ monospacedDigits?: boolean;
19
+ /** The system's secondary text color, for supporting columns such as an author or date. */
20
+ secondary?: boolean;
21
+ }
22
+ export interface TableRow {
23
+ id: string;
24
+ /** Cell text by column ID; a missing value is an empty cell. */
25
+ values: Readonly<Record<string, string>>;
26
+ }
27
+ export interface TableSelectionEvent { id: string | null; ids: string[] }
28
+ export interface TableColumnResizeEvent { id: string; width: number }
29
+ export interface TableBaseProps extends Omit<SpecializedViewProps, "children"> {
30
+ columns: readonly TableColumn[];
31
+ rows: readonly TableRow[];
32
+ /** Hides the column header. Defaults to true (shown). */
33
+ headerVisible?: boolean;
34
+ /** Alternating row backgrounds instead of vertical grid lines. */
35
+ alternatingRows?: boolean;
36
+ /** Row height in points; defaults to the system's row size. */
37
+ rowHeight?: number;
38
+ onSelectionChange: (event: TableSelectionEvent) => void;
39
+ onColumnResize?: (event: TableColumnResizeEvent) => void;
40
+ onDoubleClick?: (event: { id: string }) => void;
41
+ children?: never;
42
+ }
43
+ /** `selectedId` selects one row; `selectedIds` enables multiple selection (⌘/⇧-click). */
44
+ export type TableSelectionProps = { selectedId: string | null; selectedIds?: never } | { selectedIds: readonly string[]; selectedId?: never };
45
+ export type TableProps = TableBaseProps & TableSelectionProps;
46
+ export function getTableAvailability() { return macosViewAvailability("SparkTable"); }
47
+ const columnKeys = ["id", "title", "width", "minWidth", "maxWidth", "alignment", "monospacedDigits", "secondary"];
48
+ function validate(columns: readonly TableColumn[], rows: readonly TableRow[]) {
49
+ if (!Array.isArray(columns) || !columns.length) throw new SparkError("E_INVALID_ARGUMENT", "A table needs at least one column");
50
+ const columnIds = new Set<string>();
51
+ for (const column of columns) {
52
+ if (!column || typeof column !== "object") throw new SparkError("E_INVALID_ARGUMENT", "Expected a table column");
53
+ for (const key of Object.keys(column)) if (!columnKeys.includes(key)) throw new SparkError("E_UNSUPPORTED_OPTION", `Unknown table column option: ${key}`);
54
+ identifier(column.id, "column ID");
55
+ if (columnIds.has(column.id)) throw new SparkError("E_INVALID_ARGUMENT", "Table column IDs must be unique"); columnIds.add(column.id);
56
+ if (typeof column.title !== "string") throw new SparkError("E_INVALID_ARGUMENT", "Expected a column title");
57
+ for (const key of ["width", "minWidth", "maxWidth"] as const) if (column[key] !== undefined) finite(column[key], `column ${key}`, 1, 20000);
58
+ if ((column.minWidth ?? 0) > (column.maxWidth ?? Infinity) || (column.width !== undefined && (column.width < (column.minWidth ?? 0) || column.width > (column.maxWidth ?? Infinity)))) throw new SparkError("E_INVALID_ARGUMENT", "Column width is outside its limits");
59
+ if (column.alignment !== undefined && !["leading", "center", "trailing"].includes(column.alignment)) throw new SparkError("E_INVALID_ARGUMENT", "Invalid column alignment");
60
+ for (const key of ["monospacedDigits", "secondary"] as const) if (column[key] !== undefined && typeof column[key] !== "boolean") throw new SparkError("E_INVALID_ARGUMENT", `Column ${key} must be boolean`);
61
+ }
62
+ if (!Array.isArray(rows)) throw new SparkError("E_INVALID_ARGUMENT", "Expected table rows");
63
+ const rowIds = new Set<string>();
64
+ for (const row of rows) {
65
+ if (!row || typeof row !== "object" || !row.values || typeof row.values !== "object") throw new SparkError("E_INVALID_ARGUMENT", "Expected table rows with values");
66
+ identifier(row.id, "row ID");
67
+ if (rowIds.has(row.id)) throw new SparkError("E_INVALID_ARGUMENT", "Table row IDs must be unique"); rowIds.add(row.id);
68
+ for (const [key, value] of Object.entries(row.values)) {
69
+ if (!columnIds.has(key)) throw new SparkError("E_INVALID_ARGUMENT", `Row value for unknown column: ${key}`);
70
+ if (typeof value !== "string") throw new SparkError("E_INVALID_ARGUMENT", "Table cell values must be strings");
71
+ }
72
+ }
73
+ }
74
+ /** AppKit's NSTableView with a header and text columns. Only visible rows have cells, so long tables stay cheap. */
75
+ export function Table(props: TableProps) {
76
+ const { columns, rows, selectedId, selectedIds, headerVisible = true, alternatingRows = false, rowHeight, onSelectionChange, onColumnResize, onDoubleClick, ref, onError, style, ...rest } = props;
77
+ validate(columns, rows);
78
+ if (typeof headerVisible !== "boolean" || typeof alternatingRows !== "boolean") throw new SparkError("E_INVALID_ARGUMENT", "headerVisible and alternatingRows must be boolean");
79
+ if (rowHeight !== undefined) finite(rowHeight, "row height", 1, 1000);
80
+ if (typeof onSelectionChange !== "function") throw new SparkError("E_INVALID_ARGUMENT", "Expected onSelectionChange");
81
+ callback(onDoubleClick, "double-click");
82
+ callback(onColumnResize, "column resize");
83
+ const multiple = selectedIds !== undefined;
84
+ if (multiple === (selectedId !== undefined)) throw new SparkError("E_INVALID_ARGUMENT", "Pass exactly one of selectedId and selectedIds");
85
+ const selection = multiple ? selectedIds : selectedId === null ? [] : [selectedId];
86
+ if (!Array.isArray(selection) || selection.some(id => typeof id !== "string")) throw new SparkError("E_INVALID_ARGUMENT", "Selected IDs must be strings");
87
+ const control = useControl({ ref, onError }, getTableAvailability());
88
+ const [revision, revise] = useState(0);
89
+ const columnsJson = useMemo(() => JSON.stringify(columns), [columns]);
90
+ const rowsJson = useMemo(() => JSON.stringify(rows), [rows]);
91
+ function selectionChanged(event: NativeSyntheticEvent<{ id: string; idsJson: string }>) {
92
+ if (!control.active()) return;
93
+ let ids: string[];
94
+ try { ids = JSON.parse(event.nativeEvent.idsJson); if (!Array.isArray(ids) || ids.some(id => typeof id !== "string")) throw new Error("Expected row IDs"); }
95
+ catch (cause) { control.error(new SparkError("E_INVALID_DATA", "Invalid table selection", { cause })); return; }
96
+ // A click can land on rows a newer render already removed; report only the rows still present.
97
+ const present = new Set(rows.map(row => row.id));
98
+ ids = ids.filter(id => present.has(id));
99
+ revise(value => value + 1);
100
+ onSelectionChange({ id: present.has(event.nativeEvent.id) ? event.nativeEvent.id : ids[0] ?? null, ids });
101
+ }
102
+ function columnResized(event: NativeSyntheticEvent<TableColumnResizeEvent>) {
103
+ if (!control.active() || !onColumnResize) return;
104
+ const { id, width } = event.nativeEvent ?? {};
105
+ if (typeof id !== "string" || typeof width !== "number" || !Number.isFinite(width) || width <= 0) {
106
+ control.error(new SparkError("E_INVALID_DATA", "Invalid table column resize"));
107
+ return;
108
+ }
109
+ if (columns.some(column => column.id === id)) onColumnResize({ id, width });
110
+ }
111
+ if (control.failed) return <View {...rest} ref={control.ref} style={style} accessibilityRole="list">
112
+ {rows.map(row => <Text key={row.id} accessibilityState={{ selected: selection.includes(row.id) }}>{columns.map(column => row.values[column.id] ?? "").join(" ")}</Text>)}
113
+ </View>;
114
+ return <NativeTable {...rest} ref={control.ref} style={style} columnsJson={columnsJson} rowsJson={rowsJson} selectedIdsJson={JSON.stringify(selection)} selectionRevision={revision}
115
+ allowsMultipleSelection={multiple} headerVisible={headerVisible} alternatingRows={alternatingRows} rowHeight={rowHeight ?? 0}
116
+ reportsColumnResize={onColumnResize !== undefined} onTableColumnResize={onColumnResize ? columnResized : undefined}
117
+ onTableSelectionChange={selectionChanged} onTableDoubleClick={event => { if (control.active() && rows.some(row => row.id === event.nativeEvent.id)) onDoubleClick?.({ id: event.nativeEvent.id }); }} />;
118
+ }
@@ -11,18 +11,39 @@ export interface ControlProps {
11
11
  ref?: Ref<ControlRef>;
12
12
  onError?: (error: SparkError) => void;
13
13
  }
14
- /** A native text button. Layout styles affect its frame, not OS-managed chrome. */
14
+ /**
15
+ * A native text button. Without a width or height style it takes its intrinsic size on desktop.
16
+ * `disclosure` is the macOS disclosure button (a chevron); it requires `expanded`, and its text names it for accessibility.
17
+ */
15
18
  export interface ButtonProps extends ControlProps {
16
19
  children: string;
17
20
  onPress?: () => void;
18
- variant?: "default" | "bordered" | "borderless";
21
+ variant?: "default" | "bordered" | "borderless" | "disclosure";
22
+ /** Controlled expansion of a `disclosure` button; toggle it in `onPress`. Only valid with that variant. */
23
+ expanded?: boolean;
24
+ /** macOS SF Symbol shown before the title (not with `disclosure`). A name missing on this system reports `E_NOT_FOUND`; other platforms report `E_UNSUPPORTED_PLATFORM`. */
25
+ symbol?: string;
26
+ /** AppKit control size; `regular` (default) everywhere, `small` and `mini` on macOS and web. */
27
+ size?: "regular" | "small" | "mini";
19
28
  }
20
- export interface ControlledTextInputProps extends ControlProps {
29
+ /** A controlled native checkbox. `children` is its label; without one, set `accessibilityLabel`. */
30
+ export interface CheckboxProps extends ControlProps {
31
+ value: boolean;
32
+ onValueChange: (value: boolean) => void;
33
+ children?: string;
34
+ }
35
+ interface TextInputCommonProps extends ControlProps {
36
+ /** Shown while the input is empty. */
37
+ placeholder?: string;
38
+ /** Several lines that wrap and scroll (an NSTextView on macOS, a `textarea` on web); Return inserts a newline. Defaults to one line. */
39
+ multiline?: boolean;
40
+ }
41
+ export interface ControlledTextInputProps extends TextInputCommonProps {
21
42
  value: string;
22
43
  defaultValue?: never;
23
44
  onChangeText?: (text: string) => void;
24
45
  }
25
- export interface UncontrolledTextInputProps extends ControlProps {
46
+ export interface UncontrolledTextInputProps extends TextInputCommonProps {
26
47
  value?: never;
27
48
  /** Read only on mount. Remount to reset an uncontrolled input. */
28
49
  defaultValue?: string;
@@ -35,5 +56,17 @@ export interface SelectProps extends ControlProps {
35
56
  value: string;
36
57
  onValueChange: (value: string) => void;
37
58
  }
38
- export interface SegmentedControlProps extends SelectProps {}
39
- export type ControlKind = "button" | "text-input" | "select" | "segmented-control";
59
+ export interface SegmentedControlProps extends SelectProps {
60
+ /** `small` is the compact control size. Defaults to `regular`. */
61
+ size?: "regular" | "small";
62
+ /** `fit` sizes segments to their labels; `fill` shares the control's width equally. Defaults to `fit`. */
63
+ distribution?: "fit" | "fill";
64
+ }
65
+ /** A controlled group of native radio buttons: one per option, with `value` selected. */
66
+ export interface RadioGroupProps extends SelectProps {
67
+ /** `vertical` (default) stacks the buttons; `horizontal` puts them on one line. */
68
+ orientation?: "vertical" | "horizontal";
69
+ /** AppKit control size: `regular` (default), `small` or `mini`. */
70
+ size?: "regular" | "small" | "mini";
71
+ }
72
+ export type ControlKind = "button" | "text-input" | "select" | "segmented-control" | "checkbox" | "radio-group";
@@ -1,9 +1,11 @@
1
1
  import { withUniwind } from "uniwind";
2
- import { Button as NativeButton, TextInput as NativeTextInput, Select as NativeSelect, SegmentedControl as NativeSegmentedControl } from "./src/index";
2
+ import { Button as NativeButton, Checkbox as NativeCheckbox, RadioGroup as NativeRadioGroup, TextInput as NativeTextInput, Select as NativeSelect, SegmentedControl as NativeSegmentedControl } from "./src/index";
3
3
 
4
4
  // Optional, module-level bindings preserve each platform's native implementation.
5
5
  // className maps to the existing layout style; explicit style wins on conflicts.
6
6
  export const Button = withUniwind(NativeButton);
7
+ export const Checkbox = withUniwind(NativeCheckbox);
8
+ export const RadioGroup = withUniwind(NativeRadioGroup);
7
9
  export const TextInput = withUniwind(NativeTextInput);
8
10
  export const Select = withUniwind(NativeSelect);
9
11
 
@@ -1,7 +1,7 @@
1
1
  import { createElement, type ComponentType } from "react";
2
2
  import type { StyleProp, ViewStyle } from "react-native";
3
3
  import { useResolveClassNames } from "uniwind";
4
- import { Button as NativeButton, TextInput as NativeTextInput, Select as NativeSelect, SegmentedControl as NativeSegmentedControl } from "./src/index";
4
+ import { Button as NativeButton, Checkbox as NativeCheckbox, TextInput as NativeTextInput, Select as NativeSelect, SegmentedControl as NativeSegmentedControl } from "./src/index";
5
5
 
6
6
  function withSparkClasses<Props extends { style?: StyleProp<ViewStyle> }>(Component: ComponentType<Props>) {
7
7
  return function UniwindControl({ className = "", style, ...props }: Props & { className?: string }) {
@@ -13,6 +13,7 @@ function withSparkClasses<Props extends { style?: StyleProp<ViewStyle> }>(Compon
13
13
  }
14
14
 
15
15
  export const Button = withSparkClasses(NativeButton);
16
+ export const Checkbox = withSparkClasses(NativeCheckbox);
16
17
  export const TextInput = withSparkClasses(NativeTextInput);
17
18
  export const Select = withSparkClasses(NativeSelect);
18
19
 
@@ -16,21 +16,34 @@ namespace React = Microsoft::ReactNative;
16
16
  namespace Composition = Microsoft::ReactNative::Composition;
17
17
  namespace Xaml = Microsoft::UI::Xaml;
18
18
  namespace Json = Windows::Data::Json;
19
+ // WinUI TextBox breaks lines with \r; Spark text uses \n.
20
+ inline std::string NewlineText(std::string const &text) {
21
+ std::string lines; lines.reserve(text.size());
22
+ for (size_t i = 0; i < text.size(); ++i) {
23
+ if (text[i] != '\r') { lines += text[i]; continue; }
24
+ lines += '\n';
25
+ if (i + 1 < text.size() && text[i + 1] == '\n') ++i;
26
+ }
27
+ return lines;
28
+ }
19
29
  struct Props : implements<Props, React::IComponentProps> {
20
30
  React::ViewProps view{nullptr};
21
- std::string title, defaultText, text, itemsJson = "[]", value, variant = "default";
22
- bool disabled = false, controlled = false;
31
+ std::string title, defaultText, text, placeholder, itemsJson = "[]", value, variant = "default";
32
+ bool disabled = false, controlled = false, multiline = false, checked = false;
23
33
  int32_t eventCount = 0;
24
34
  void SetProp(uint32_t, hstring const &name, React::IJSValueReader const &reader) noexcept {
25
35
  if (name == L"title") React::ReadValue(reader, title);
26
36
  else if (name == L"defaultText") React::ReadValue(reader, defaultText);
27
37
  else if (name == L"text") React::ReadValue(reader, text);
38
+ else if (name == L"placeholder") React::ReadValue(reader, placeholder);
39
+ else if (name == L"multiline") React::ReadValue(reader, multiline);
28
40
  else if (name == L"controlled") React::ReadValue(reader, controlled);
29
41
  else if (name == L"eventCount") React::ReadValue(reader, eventCount);
30
42
  else if (name == L"itemsJson") React::ReadValue(reader, itemsJson);
31
43
  else if (name == L"value") React::ReadValue(reader, value);
32
44
  else if (name == L"variant") React::ReadValue(reader, variant);
33
45
  else if (name == L"disabled") React::ReadValue(reader, disabled);
46
+ else if (name == L"checked") React::ReadValue(reader, checked);
34
47
  }
35
48
  };
36
49
  struct Control : implements<Control, Windows::Foundation::IInspectable> {
@@ -56,6 +69,7 @@ struct Control : implements<Control, Windows::Foundation::IInspectable> {
56
69
  std::vector<std::string> values;
57
70
  bool initialized = false, updating = false;
58
71
  int32_t eventCount = 0;
72
+ float width = 0, height = 0;
59
73
  void Emit(hstring const &name, std::string const &key = "", std::string const &value = "") {
60
74
  const auto count = eventCount;
61
75
  if (emitter) emitter.DispatchEvent(name, [key, value, name, count](React::IJSValueWriter const &writer) {
@@ -65,6 +79,18 @@ struct Control : implements<Control, Windows::Foundation::IInspectable> {
65
79
  writer.WriteObjectEnd();
66
80
  });
67
81
  }
82
+ // A Checkbox is SparkButton's checkbox variant; the variant arrives with the first props, so the button is replaced then.
83
+ Xaml::Controls::Control MakeButton(bool checkbox) {
84
+ Xaml::Controls::Primitives::ButtonBase button{nullptr};
85
+ if (checkbox) button = Xaml::Controls::CheckBox(); else button = Xaml::Controls::Button();
86
+ button.Click([weak = get_weak()](auto const &, auto const &) { if (auto self = weak.get()) self->Emit(L"buttonPress"); });
87
+ return button;
88
+ }
89
+ void Place() {
90
+ control.HorizontalAlignment(Xaml::HorizontalAlignment::Stretch);
91
+ control.VerticalAlignment(Xaml::VerticalAlignment::Stretch);
92
+ if (width > 0 || height > 0) { control.Width(width); control.Height(height); }
93
+ }
68
94
  void Create(Composition::ContentIslandComponentView const &view, std::string type) {
69
95
  kind = std::move(type); component = make_weak(view);
70
96
  try {
@@ -74,13 +100,11 @@ struct Control : implements<Control, Windows::Foundation::IInspectable> {
74
100
  const auto weak = get_weak();
75
101
  windowThemeChanged = view.ThemeChanged(auto_revoke, [weak](auto const &, auto const &) { if (auto self = weak.get()) self->ApplyTheme(); });
76
102
  if (kind == "Button") {
77
- Xaml::Controls::Button button;
78
- button.Click([weak](auto const &, auto const &) { if (auto self = weak.get()) self->Emit(L"buttonPress"); });
79
- control = button;
103
+ control = MakeButton(false);
80
104
  } else if (kind == "TextInput") {
81
105
  Xaml::Controls::TextBox input;
82
106
  input.TextChanged([weak](auto const &sender, auto const &) {
83
- if (auto self = weak.get(); self && !self->updating && self->control.IsEnabled()) { ++self->eventCount; self->Emit(L"textChange", "text", to_string(sender.template as<Xaml::Controls::TextBox>().Text())); }
107
+ if (auto self = weak.get(); self && !self->updating && self->control.IsEnabled()) { ++self->eventCount; self->Emit(L"textChange", "text", NewlineText(to_string(sender.template as<Xaml::Controls::TextBox>().Text()))); }
84
108
  });
85
109
  control = input;
86
110
  } else {
@@ -93,8 +117,7 @@ struct Control : implements<Control, Windows::Foundation::IInspectable> {
93
117
  });
94
118
  control = select;
95
119
  }
96
- control.HorizontalAlignment(Xaml::HorizontalAlignment::Stretch);
97
- control.VerticalAlignment(Xaml::VerticalAlignment::Stretch);
120
+ Place();
98
121
  context = React::ReactContext(view.ReactContext());
99
122
  ApplyTheme();
100
123
  themeSubscription = context.Notifications().Subscribe(ThemeChanged(), context.UIDispatcher(), [weak](auto const &, auto const &) {
@@ -113,18 +136,25 @@ struct Control : implements<Control, Windows::Foundation::IInspectable> {
113
136
  if (!control || !failure.empty()) return;
114
137
  try {
115
138
  updating = true;
139
+ if (kind == "Button" && (props.variant == "checkbox") != static_cast<bool>(control.try_as<Xaml::Controls::CheckBox>())) {
140
+ control = MakeButton(props.variant == "checkbox"); Place(); island.Content(control); ApplyTheme();
141
+ }
116
142
  control.IsEnabled(!props.disabled);
117
143
  Xaml::Automation::AutomationProperties::SetAutomationId(control, props.view.TestId());
118
144
  Xaml::Automation::AutomationProperties::SetName(control, props.view.AccessibilityLabel().empty() && kind == "Button" ? to_hstring(props.title) : props.view.AccessibilityLabel());
119
145
  if (kind == "Button") {
120
- auto button = control.as<Xaml::Controls::Button>();
121
- button.Content(box_value(to_hstring(props.title)));
122
- // WinUI owns hover, pressed, keyboard, disabled, and accessibility states.
123
- button.BorderThickness(props.variant == "borderless" ? Xaml::Thickness{0, 0, 0, 0} : Xaml::Thickness{1, 1, 1, 1});
146
+ control.as<Xaml::Controls::ContentControl>().Content(box_value(to_hstring(props.title)));
147
+ // WinUI owns hover, pressed, keyboard, disabled, and accessibility states. The checkbox state is controlled:
148
+ // a click toggles it, and every update (including the press acknowledgment) restores the value.
149
+ if (auto box = control.try_as<Xaml::Controls::CheckBox>()) box.IsChecked(props.checked);
150
+ else control.BorderThickness(props.variant == "borderless" ? Xaml::Thickness{0, 0, 0, 0} : Xaml::Thickness{1, 1, 1, 1});
124
151
  } else if (kind == "TextInput") {
125
152
  auto input = control.as<Xaml::Controls::TextBox>();
126
153
  if (!initialized) input.Text(to_hstring(props.defaultText));
127
- if (props.controlled && props.eventCount >= eventCount && input.Text() != to_hstring(props.text)) input.Text(to_hstring(props.text));
154
+ if (props.controlled && props.eventCount >= eventCount && NewlineText(to_string(input.Text())) != props.text) input.Text(to_hstring(props.text));
155
+ input.PlaceholderText(to_hstring(props.placeholder));
156
+ input.AcceptsReturn(props.multiline);
157
+ input.TextWrapping(props.multiline ? Xaml::TextWrapping::Wrap : Xaml::TextWrapping::NoWrap);
128
158
  } else {
129
159
  auto select = control.as<Xaml::Controls::ComboBox>();
130
160
  if (items != props.itemsJson) {
@@ -157,8 +187,8 @@ inline void RegisterControls(React::IReactPackageBuilder const &package) {
157
187
  if (previous) {
158
188
  auto old = get_self<Props>(previous);
159
189
  props->title = old->title; props->defaultText = old->defaultText; props->itemsJson = old->itemsJson;
160
- props->text = old->text; props->controlled = old->controlled; props->eventCount = old->eventCount;
161
- props->value = old->value; props->variant = old->variant; props->disabled = old->disabled;
190
+ props->text = old->text; props->placeholder = old->placeholder; props->multiline = old->multiline; props->controlled = old->controlled; props->eventCount = old->eventCount;
191
+ props->value = old->value; props->variant = old->variant; props->disabled = old->disabled; props->checked = old->checked;
162
192
  }
163
193
  props->view = view; return props.as<React::IComponentProps>();
164
194
  });
@@ -169,6 +199,7 @@ inline void RegisterControls(React::IReactPackageBuilder const &package) {
169
199
  view.LayoutMetricsChanged([weak](auto const &, React::LayoutMetricsChangedArgs const &args) {
170
200
  if (auto self = weak.get(); self && self->control) {
171
201
  auto frame = args.NewLayoutMetrics().Frame;
202
+ self->width = frame.Width; self->height = frame.Height;
172
203
  self->control.Width(frame.Width); self->control.Height(frame.Height);
173
204
  }
174
205
  });
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@legendapp/spark-updates",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "license": "MIT",
5
5
  "main": "src/index.ts",
6
6
  "react-native": "src/index.ts",
@@ -26,19 +26,13 @@
26
26
  },
27
27
  "spark": {
28
28
  "sdk": true,
29
- "nativeModules": [
30
- "NativeDesktopUpdates"
31
- ],
32
- "pod": "RNDesktopUpdates",
33
- "platforms": [
34
- "macos"
35
- ],
29
+ "nativeModules": true,
36
30
  "requires": [
37
31
  "@legendapp/spark-desktop-app"
38
32
  ]
39
33
  },
40
34
  "dependencies": {
41
- "@legendapp/spark-desktop-app": "0.0.2"
35
+ "@legendapp/spark-desktop-app": "0.0.4"
42
36
  },
43
37
  "private": true
44
38
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@legendapp/spark-webview",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "license": "MIT",
5
5
  "main": "src/index.ts",
6
6
  "react-native": "src/index.ts",
@@ -8,7 +8,7 @@
8
8
  "src"
9
9
  ],
10
10
  "dependencies": {
11
- "@legendapp/spark-desktop-app": "0.0.2"
11
+ "@legendapp/spark-desktop-app": "0.0.4"
12
12
  },
13
13
  "private": true,
14
14
  "peerDependencies": {