@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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@legendapp/spark-desktop-windows",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "license": "MIT",
5
5
  "main": "src/index",
6
6
  "react-native": "src/index",
@@ -27,21 +27,14 @@
27
27
  },
28
28
  "spark": {
29
29
  "sdk": true,
30
- "nativeModules": [
31
- "NativeDesktopWindowManager",
32
- "NativeWindowManager"
33
- ],
34
- "pod": "RNDesktopWindows",
35
- "platforms": [
36
- "macos"
37
- ],
30
+ "nativeModules": true,
38
31
  "requires": [
39
32
  "@legendapp/spark-desktop-app"
40
33
  ]
41
34
  },
42
35
  "dependencies": {
43
- "@legendapp/spark-desktop-app": "0.0.2",
44
- "@legendapp/spark-window-options": "0.0.2",
36
+ "@legendapp/spark-desktop-app": "0.0.4",
37
+ "@legendapp/spark-window-options": "0.0.4",
45
38
  "@legendapp/state": "^3.0.0-beta.42"
46
39
  },
47
40
  "private": true
@@ -1,4 +1,4 @@
1
- import { Platform } from "react-native";
1
+ import { AppState, Platform } from "react-native";
2
2
  import { SparkError, asyncRegistration, nativeError, type AsyncRegistration, type Availability } from "@legendapp/spark-desktop-app/src/contracts";
3
3
  export type { AsyncRegistration } from "@legendapp/spark-desktop-app/src/contracts";
4
4
  import { onDesktopEvent } from "@legendapp/spark-desktop-app/src/events";
@@ -7,6 +7,7 @@ import { createMacOSWindow, macosNative, updateMacOSWindow } from "./macos-adapt
7
7
  import { bounds, keys, number, object, text, validateOptions, windowId } from "./validation";
8
8
  import { getNativeDisplays, isBounds, isInfo, record, subscribeToWindowInstance, windowCall, windowCommand, type NativeWindowInfo } from "./transport";
9
9
  import type { CenterWindowOptions, CloseResult, CursorPoint, DisplayInfo, SetWindowBoundsOptions, ShowWindowOptions, WindowBounds, WindowEventMap, WindowInfo, WindowOpenOptions, WindowUpdateOptions } from "./types";
10
+ declare const __DEV__: boolean | undefined;
10
11
  export type * from "./types";
11
12
 
12
13
  export function getWindowAvailability(): Availability {
@@ -53,6 +54,7 @@ export async function getDisplays(): Promise<DisplayInfo[]> { return getNativeDi
53
54
  export async function getCursorPoint(): Promise<CursorPoint> { return windowCall("cursorPoint", {}, (value): value is CursorPoint => record(value) && typeof value.displayId === "string" && Number.isFinite(value.x) && Number.isFinite(value.y)); }
54
55
  export async function setWindowOptions(id: string, options: WindowUpdateOptions): Promise<void> {
55
56
  windowId(id); validateOptions(options, Platform.OS, false);
57
+ if (id === "main" && options.macos?.restoreOnLaunch !== undefined) throw new SparkError("E_UNSUPPORTED_OPTION", "The host creates the main window; macos.restoreOnLaunch only applies to secondary windows");
56
58
  const snapshot = JSON.parse(JSON.stringify(options)) as WindowUpdateOptions;
57
59
  if (!snapshot.macos || Object.keys(snapshot).some(key => key !== "macos")) {
58
60
  await windowCommand("options", { id, options: snapshot });
@@ -72,9 +74,13 @@ export async function setWindowBounds(id: string, value: WindowBounds, options:
72
74
  await windowCommand("bounds", { id, bounds: value });
73
75
  }
74
76
  export async function showWindow(id: string, options: ShowWindowOptions = {}): Promise<void> {
75
- windowId(id); object(options, "show options"); keys(options, ["focus"]);
77
+ windowId(id); object(options, "show options"); keys(options, ["focus", "activate"]);
76
78
  if (options.focus !== undefined && typeof options.focus !== "boolean") throw new SparkError("E_INVALID_ARGUMENT", "focus must be boolean");
77
- await windowCommand("show", { id, focus: options.focus ?? true });
79
+ if (options.activate !== undefined && typeof options.activate !== "boolean") throw new SparkError("E_INVALID_ARGUMENT", "activate must be boolean");
80
+ const focus = options.focus ?? true, activate = options.activate ?? false;
81
+ if (activate && !focus) throw new SparkError("E_INVALID_ARGUMENT", "activate requires focus");
82
+ if (Platform.OS === "macos" && focus && !activate && typeof __DEV__ !== "undefined" && __DEV__ && AppState.currentState !== "active") console.warn(`showWindow("${id}") while the app is inactive keeps the window behind other apps; pass { activate: true } when showing it from a tray, popover, menu bar or dock-menu click.`);
83
+ await windowCommand("show", { id, focus, activate });
78
84
  }
79
85
  export async function centerWindow(id: string, options: CenterWindowOptions = {}): Promise<void> {
80
86
  windowId(id); object(options, "center options"); keys(options, ["displayId"]);
@@ -18,6 +18,9 @@ export function macosOptions({ macos: options, appearance, backgroundColor }: Pi
18
18
  if (backgroundColor !== undefined) style.backgroundColor = backgroundColor;
19
19
  if (!options) return { windowStyle: style };
20
20
  if (options.representedUri !== undefined) result.representedURL = options.representedUri;
21
+ if (options.subtitle !== undefined) result.subtitle = options.subtitle;
22
+ if (options.tabbing?.mode !== undefined) result.tabbingMode = options.tabbing.mode;
23
+ if (options.tabbing?.identifier !== undefined) result.tabbingIdentifier = options.tabbing.identifier;
21
24
  if (options.restoreOnLaunch !== undefined) result.restoreOnLaunch = options.restoreOnLaunch;
22
25
  if (options.startupSplitView !== undefined) style.startupSplitView = options.startupSplitView;
23
26
  if (options.level !== undefined) {
@@ -32,6 +35,9 @@ export function macosOptions({ macos: options, appearance, backgroundColor }: Pi
32
35
  if (title) {
33
36
  const fields = { contentLayout: "contentLayoutMode", transparent: "titlebarAppearsTransparent", titleVisibility: "titleVisibility", separator: "titlebarSeparatorStyle", material: "titlebarMaterial", blendingMode: "titlebarMaterialBlendingMode", materialState: "titlebarMaterialState", trafficLights: "trafficLights" } as const;
34
37
  for (const [key, target] of Object.entries(fields)) if (title[key as keyof typeof fields] !== undefined) style[target] = title[key as keyof typeof fields];
38
+ if (title.tintColor !== undefined && title.material === undefined) style.titlebarMaterial = "titlebar";
39
+ if (typeof title.tintColor === "string") style.titlebarMaterialTintColor = { light: title.tintColor, dark: title.tintColor };
40
+ else if (title.tintColor) style.titlebarMaterialTintColor = title.tintColor;
35
41
  if (title.controls) style.titlebarControls = title.controls.map(({ symbol, disabled, ...control }) => ({ ...control, type: "button", enabled: !disabled, systemImageName: symbol }));
36
42
  }
37
43
  if (options.toolbar) {
@@ -40,6 +46,7 @@ export function macosOptions({ macos: options, appearance, backgroundColor }: Pi
40
46
  if (options.toolbar.items) style.toolbarItems = options.toolbar.items.map(item => {
41
47
  const { type, ...common } = item;
42
48
  if (type === "segmented") { const value = item as Extract<typeof item, { type: "segmented" }>; return { ...common, type, selectedValue: value.value, segments: value.segments.map(({ symbol, ...segment }) => ({ ...segment, systemImageName: symbol })) }; }
49
+ if (type === "popup") { const { items, options, value, disabled, ...rest } = item as Extract<typeof item, { type: "popup" }>; return { ...rest, type, enabled: !disabled, selectedValue: value, options: options.map(({ symbol, ...option }) => ({ ...option, systemImageName: symbol })), menuItems: items ? menuItems(items, { types: ["action", "separator"], icons: ["symbol"] }, "macos") : [] }; }
43
50
  if (type === "menu") { const { items, ...value } = item as Extract<typeof item, { type: "menu" }>; return { ...value, type: "menuButton", enabled: !value.disabled, systemImageName: value.symbol, menuItems: menuItems(items, { types: ["action", "checkbox", "separator", "slider"], icons: ["symbol"] }, "macos") }; }
44
51
  return { ...common, type, ...("disabled" in item ? { enabled: !item.disabled } : {}), ...("symbol" in item ? { systemImageName: item.symbol } : {}) };
45
52
  });
@@ -60,7 +60,15 @@ export interface WindowInfo {
60
60
  bounds: WindowBounds;
61
61
  }
62
62
  export type CloseResult = { closed: true } | { closed: false; reason: "vetoed" };
63
- export interface ShowWindowOptions { focus?: boolean }
63
+ export interface ShowWindowOptions {
64
+ /** Makes the window key within the app (default true). Does not bring an inactive app in front of other apps. */
65
+ focus?: boolean;
66
+ /**
67
+ * Activates the app first so the window comes in front of other apps (default false). Use it when showing a window
68
+ * in response to a tray, popover, menu bar or dock-menu click, since non-activating panels don't activate the app.
69
+ */
70
+ activate?: boolean;
71
+ }
64
72
  export interface CenterWindowOptions { displayId?: DisplayId }
65
73
  export interface WindowEventMap {
66
74
  focusChanged: { windowId: WindowId; focused: boolean };
@@ -84,8 +92,12 @@ export interface MacOSTitleBarOptions {
84
92
  titleVisibility?: "visible" | "hidden";
85
93
  separator?: "automatic" | "none" | "line" | "shadow";
86
94
  material?: "none" | "glass" | "titlebar" | "headerView" | "hudWindow" | "sidebar" | "windowBackground";
95
+ /** Needs `material` (not `none` or `glass`) or `tintColor` in the same call. */
87
96
  blendingMode?: "behindWindow" | "withinWindow";
97
+ /** Needs `material` (not `none` or `glass`) or `tintColor` in the same call. */
88
98
  materialState?: "active" | "inactive" | "followsWindowActiveState";
99
+ /** #RRGGBB or #RRGGBBAA over the material; use alpha to keep the blur visible. Without `material` in the same call, uses `titlebar`. */
100
+ tintColor?: string | { light: string; dark: string };
89
101
  trafficLights?: boolean;
90
102
  controls?: readonly MacOSTitleBarControl[];
91
103
  }
@@ -97,12 +109,17 @@ type ToolbarMenuItem =
97
109
  | (ToolbarMenuEntry & { type: "action" })
98
110
  | (ToolbarMenuEntry & { type: "checkbox"; checked: boolean })
99
111
  | (ToolbarMenuEntry & { type: "slider"; min: number; max: number; value: number; suffix?: string });
112
+ type ToolbarPopupMenuItem = Extract<ToolbarMenuItem, { type: "separator" | "action" }>;
100
113
  export type MacOSToolbarItem =
101
- | (ToolbarEntry & { type: "button"; disabled?: boolean; bordered?: boolean; symbol?: string; tooltip?: string; monospacedDigits?: boolean; width?: number })
114
+ | (ToolbarEntry & { type: "button"; disabled?: boolean; bordered?: boolean; symbol?: string; tooltip?: string })
102
115
  | (ToolbarEntry & { type: "menu"; disabled?: boolean; bordered?: boolean; symbol?: string; tooltip?: string; width?: number; items: readonly ToolbarMenuItem[] })
103
116
  | (ToolbarEntry & { type: "label"; text: string; width?: number })
104
117
  | (ToolbarEntry & { type: "search"; disabled?: boolean; collapses?: boolean; placeholder?: string; value?: string; width?: number })
105
- | (ToolbarEntry & { type: "segmented"; segments: readonly MacOSToolbarSegment[]; value: string | null });
118
+ | (ToolbarEntry & { type: "segmented"; segments: readonly MacOSToolbarSegment[]; value: string | null })
119
+ /** An NSPopUpButton showing the current `value` (null shows nothing selected); choosing an option emits `toolbarSelectionChanged`. `items` (actions and separators) follow the options after a separator and emit `toolbarMenuAction`, leaving the value shown. */
120
+ | (ToolbarEntry & { type: "popup"; options: readonly MacOSToolbarSegment[]; value: string | null; items?: readonly ToolbarPopupMenuItem[]; disabled?: boolean; tooltip?: string; width?: number })
121
+ /** An NSProgressIndicator: `value` from 0 to 1 is determinate; omitted or null is indeterminate (animating). `bar` (default) or `spinner`. Value changes update the item in place. */
122
+ | (ToolbarEntry & { type: "progress"; value?: number | null; variant?: "bar" | "spinner"; width?: number });
106
123
  export interface MacOSToolbarOptions {
107
124
  visible?: boolean;
108
125
  style?: "automatic" | "expanded" | "preference" | "unified" | "unifiedCompact";
@@ -118,13 +135,25 @@ export interface MacOSStartupSplitViewOptions {
118
135
  sidebarBackgroundColor: string;
119
136
  contentTitlebarHeight?: number;
120
137
  }
138
+ export interface MacOSWindowTabbingOptions {
139
+ /** `automatic` (default) follows the user's "Prefer tabs" setting; `preferred` always tabs; `disallowed` never does. */
140
+ mode?: "automatic" | "preferred" | "disallowed";
141
+ /** Windows with the same identifier can share a tab group. Defaults to AppKit's identifier for the window's class. */
142
+ identifier?: string;
143
+ }
121
144
  export interface MacOSWindowOptions {
122
145
  panelStyle?: "utility" | "documentModal" | "nonactivating";
123
146
  representedUri?: string | null;
147
+ /** NSWindow subtitle, shown under the title (beside it in a compact toolbar). An empty string removes it. */
148
+ subtitle?: string;
149
+ /** Native window tabs (NSWindow tabbing). Windows sharing an `identifier` can merge into one tab group; `preferred` opens them as tabs. */
150
+ tabbing?: MacOSWindowTabbingOptions;
124
151
  level?: "normal" | "floating" | "modalPanel" | "mainMenu" | "status" | "screenSaver";
125
152
  titleBar?: MacOSTitleBarOptions;
126
153
  toolbar?: MacOSToolbarOptions;
154
+ /** Optional pre-React shell. Without the native split-view backend, startup uses the ordinary window content. */
127
155
  startupSplitView?: MacOSStartupSplitViewOptions | null;
156
+ /** Secondary windows only; the host always creates the main window. */
128
157
  restoreOnLaunch?: boolean;
129
158
  }
130
159
  /** Panel class and startup shell are fixed when the native window is created. */
@@ -71,7 +71,6 @@ export function validateOptions(options: WindowOpenOptions | WindowUpdateOptions
71
71
  if (platform !== "macos") throw new SparkError("E_UNSUPPORTED_OPTION", "macos window options require macOS");
72
72
  validateMacOS(options.macos);
73
73
  if (!opening && "panelStyle" in options.macos) throw new SparkError("E_UNSUPPORTED_OPTION", "panelStyle is fixed when opening a window");
74
- if (options.alwaysOnTop !== undefined && options.macos.level !== undefined) throw new SparkError("E_INVALID_ARGUMENT", "Choose alwaysOnTop or a macOS window level");
75
74
  }
76
75
  if (opening) {
77
76
  const value = options as WindowOpenOptions;
@@ -99,17 +98,23 @@ function entries(value: unknown, name: string): ObjectValue[] {
99
98
  return value;
100
99
  }
101
100
  export function validateMacOS(value: MacOSWindowOptions) {
102
- object(value, "macos"); keys(value, ["panelStyle", "representedUri", "level", "titleBar", "toolbar", "startupSplitView", "restoreOnLaunch"]);
101
+ object(value, "macos"); keys(value, ["panelStyle", "representedUri", "subtitle", "tabbing", "level", "titleBar", "toolbar", "startupSplitView", "restoreOnLaunch"]);
103
102
  enumValue(value.panelStyle, ["utility", "documentModal", "nonactivating"], "panelStyle");
104
103
  enumValue(value.level, ["normal", "floating", "modalPanel", "mainMenu", "status", "screenSaver"], "level");
105
104
  flags(value, ["restoreOnLaunch"]);
105
+ if (value.subtitle !== undefined) text(value.subtitle, "subtitle");
106
+ if (value.tabbing !== undefined) {
107
+ object(value.tabbing, "tabbing"); keys(value.tabbing, ["mode", "identifier"]);
108
+ enumValue(value.tabbing.mode, ["automatic", "preferred", "disallowed"], "tabbing.mode");
109
+ if (value.tabbing.identifier !== undefined) text(value.tabbing.identifier, "tabbing identifier", false);
110
+ }
106
111
  if (value.representedUri !== undefined && value.representedUri !== null) {
107
112
  text(value.representedUri, "represented URI", false);
108
113
  try { new URL(value.representedUri); } catch { throw new SparkError("E_INVALID_ARGUMENT", "representedUri must be an absolute URI"); }
109
114
  }
110
115
  if (value.titleBar !== undefined) {
111
116
  const title = value.titleBar; object(title, "titleBar");
112
- keys(title, ["contentLayout", "transparent", "titleVisibility", "separator", "material", "blendingMode", "materialState", "trafficLights", "controls"]);
117
+ keys(title, ["contentLayout", "transparent", "titleVisibility", "separator", "material", "blendingMode", "materialState", "tintColor", "trafficLights", "controls"]);
113
118
  flags(title, ["transparent", "trafficLights"]);
114
119
  enumValue(title.contentLayout, ["contentLayoutGuide", "fullSize"], "contentLayout");
115
120
  enumValue(title.titleVisibility, ["visible", "hidden"], "titleVisibility");
@@ -117,35 +122,47 @@ export function validateMacOS(value: MacOSWindowOptions) {
117
122
  enumValue(title.material, ["none", "glass", "titlebar", "headerView", "hudWindow", "sidebar", "windowBackground"], "material");
118
123
  enumValue(title.blendingMode, ["behindWindow", "withinWindow"], "blendingMode");
119
124
  enumValue(title.materialState, ["active", "inactive", "followsWindowActiveState"], "materialState");
125
+ if (typeof title.tintColor === "object") { object(title.tintColor, "tintColor"); keys(title.tintColor, ["light", "dark"]); color(title.tintColor.light); color(title.tintColor.dark); }
126
+ else if (title.tintColor !== undefined) color(title.tintColor);
127
+ const material = title.material ?? (title.tintColor !== undefined ? "titlebar" : undefined);
128
+ if (title.tintColor !== undefined && material === "none") throw new SparkError("E_INVALID_ARGUMENT", "titleBar.tintColor needs a material other than none");
129
+ for (const key of ["blendingMode", "materialState"] as const) if (title[key] !== undefined && (material === undefined || material === "none" || material === "glass")) throw new SparkError("E_INVALID_ARGUMENT", `titleBar.${key} needs a material other than none or glass in the same call`);
120
130
  if (title.controls !== undefined) for (const control of entries(title.controls, "titlebar control")) {
121
131
  keys(control, ["id", "label", "placement", "disabled", "selected", "symbol", "tooltip"]); flags(control, ["disabled", "selected"]);
122
132
  enumValue(control.placement, ["left", "right"], "control placement");
123
- for (const field of ["label", "symbol", "tooltip"]) if (control[field] !== undefined) text(control[field], field);
133
+ for (const field of ["label", "symbol", "tooltip"]) if (control[field] !== undefined) text(control[field], field, field !== "symbol");
124
134
  }
125
135
  }
126
136
  if (value.toolbar !== undefined) {
127
137
  object(value.toolbar, "toolbar"); keys(value.toolbar, ["visible", "style", "items"]); flags(value.toolbar, ["visible"]);
128
138
  enumValue(value.toolbar.style, ["automatic", "expanded", "preference", "unified", "unifiedCompact"], "toolbar style");
139
+ if (value.toolbar.visible === false && value.toolbar.items !== undefined) throw new SparkError("E_INVALID_ARGUMENT", "toolbar.items creates a toolbar; omit items when setting visible to false");
129
140
  if (value.toolbar.items !== undefined) for (const item of entries(value.toolbar.items, "toolbar item")) {
130
- const fields: Record<string, string[]> = { button: ["disabled", "bordered", "symbol", "tooltip", "monospacedDigits", "width"], menu: ["disabled", "bordered", "symbol", "tooltip", "width", "items"], label: ["text", "width"], search: ["disabled", "collapses", "placeholder", "value", "width"], segmented: ["segments", "value"] };
141
+ const fields: Record<string, string[]> = { button: ["disabled", "bordered", "symbol", "tooltip"], menu: ["disabled", "bordered", "symbol", "tooltip", "width", "items"], label: ["text", "width"], search: ["disabled", "collapses", "placeholder", "value", "width"], segmented: ["segments", "value"], popup: ["options", "value", "items", "disabled", "tooltip", "width"], progress: ["value", "variant", "width"] };
131
142
  if (typeof item.type !== "string" || !Object.hasOwn(fields, item.type)) throw new SparkError("E_INVALID_ARGUMENT", "Unknown toolbar item type");
132
143
  keys(item, ["id", "label", "placement", "type", ...fields[item.type]]);
133
- flags(item, ["disabled", "bordered", "monospacedDigits", "collapses"]);
144
+ flags(item, ["disabled", "bordered", "collapses"]);
134
145
  enumValue(item.placement, ["leading", "trailing"], "toolbar placement");
135
- for (const field of ["label", "symbol", "tooltip", "text", "placeholder"]) if (item[field] !== undefined) text(item[field], field);
146
+ for (const field of ["label", "symbol", "tooltip", "text", "placeholder"]) if (item[field] !== undefined) text(item[field], field, field !== "symbol");
136
147
  if (item.width !== undefined) number(item.width, "toolbar width", 1, 20000);
137
148
  if (item.type === "label") text(item.text, "toolbar text");
138
149
  if (item.type === "search" && item.value !== undefined) text(item.value, "search value");
150
+ if (item.type === "progress") {
151
+ if (item.value !== undefined && item.value !== null) number(item.value, "progress value", 0, 1);
152
+ enumValue(item.variant, ["bar", "spinner"], "progress variant");
153
+ }
139
154
  if (item.type === "menu") menuItems(item.items as never, { types: ["action", "checkbox", "separator", "slider"], icons: ["symbol"] }, "macos");
140
- if (item.type === "segmented") {
141
- if (!Array.isArray(item.segments) || !item.segments.length) throw new SparkError("E_INVALID_ARGUMENT", "Toolbar segments must be nonempty");
155
+ if (item.type === "popup" && item.items !== undefined) menuItems(item.items as never, { types: ["action", "separator"], icons: ["symbol"] }, "macos");
156
+ if (item.type === "segmented" || item.type === "popup") {
157
+ const segments = item.type === "popup" ? item.options : item.segments, what = item.type === "popup" ? "Toolbar popup options" : "Toolbar segments";
158
+ if (!Array.isArray(segments) || !segments.length) throw new SparkError("E_INVALID_ARGUMENT", `${what} must be nonempty`);
142
159
  const values = new Set<string>();
143
- for (const segment of item.segments) {
160
+ for (const segment of segments) {
144
161
  object(segment, "segment"); keys(segment, ["value", "label", "symbol"]); text(segment.value, "segment value"); text(segment.label, "segment label", false);
145
162
  if (segment.symbol !== undefined) text(segment.symbol, "segment symbol", false);
146
163
  if (values.has(segment.value)) throw new SparkError("E_INVALID_ARGUMENT", "Segment values must be unique"); values.add(segment.value);
147
164
  }
148
- if (item.value !== null && !values.has(item.value as string)) throw new SparkError("E_INVALID_ARGUMENT", "Unknown toolbar segment value");
165
+ if (item.value !== null && !values.has(item.value as string)) throw new SparkError("E_INVALID_ARGUMENT", `Unknown toolbar ${item.type === "popup" ? "popup" : "segment"} value`);
149
166
  }
150
167
  }
151
168
  }
@@ -21,6 +21,18 @@ const registrations = new Set<string>();
21
21
  function component(value: unknown): value is ComponentType<any> {
22
22
  return typeof value === "function" || (!!value && typeof value === "object" && [Symbol.for("react.memo"), Symbol.for("react.forward_ref"), Symbol.for("react.lazy")].includes((value as any).$$typeof));
23
23
  }
24
+ function isOptionGroup(value: unknown): value is Record<string, unknown> {
25
+ if (value === null || typeof value !== "object") return false;
26
+ const prototype = Object.getPrototypeOf(value);
27
+ return prototype === Object.prototype || prototype === null;
28
+ }
29
+ function mergeOptions(defaults: Record<string, unknown>, overrides: Record<string, unknown>): Record<string, unknown> {
30
+ const entries = Object.entries(overrides).map(([key, override]) => {
31
+ const registered = defaults[key];
32
+ return [key, isOptionGroup(registered) && isOptionGroup(override) ? mergeOptions(registered, override) : override];
33
+ });
34
+ return { ...defaults, ...Object.fromEntries(entries) };
35
+ }
24
36
  export function createWindowsNavigator<T extends WindowsConfig>(config: T): WindowsNavigator<T> {
25
37
  object(config, "navigator configuration");
26
38
  const ids = new Set<string>();
@@ -29,7 +41,7 @@ export function createWindowsNavigator<T extends WindowsConfig>(config: T): Wind
29
41
  if (entry.id === "main" || ids.has(entry.id) || registrations.has(entry.id)) throw new SparkError("E_ALREADY_EXISTS", "Window ID is already registered or reserved");
30
42
  ids.add(entry.id);
31
43
  if ((entry.component !== undefined) === (entry.loadComponent !== undefined) || (entry.component !== undefined && !component(entry.component)) || (entry.loadComponent !== undefined && typeof entry.loadComponent !== "function")) throw new SparkError("E_INVALID_ARGUMENT", "Register exactly one component or loadComponent");
32
- if (entry.options) {
44
+ if (entry.options !== undefined) {
33
45
  object(entry.options, "registration options");
34
46
  for (const key of ["id", "component", "props"]) if (key in entry.options) throw new SparkError("E_INVALID_ARGUMENT", "Navigator identity and props cannot be overridden in options");
35
47
  validateOptions({ ...entry.options, id: entry.id, component: "registration" } as WindowOpenOptions, Platform.OS, true);
@@ -63,8 +75,8 @@ export function createWindowsNavigator<T extends WindowsConfig>(config: T): Wind
63
75
  async open(name, ...args) {
64
76
  const registration = get(name), request = args[0] ?? {};
65
77
  object(request, "open request"); keys(request, ["props", "options"]);
66
- if (request.options) { object(request.options, "open options"); for (const key of ["id", "component", "props"]) if (key in request.options) throw new SparkError("E_INVALID_ARGUMENT", "Navigator identity and props cannot be overridden in options"); }
67
- const options = { ...registration.options, ...request.options, id: registration.id, component: registration.moduleName, props: request.props } as WindowOpenOptions;
78
+ if (request.options !== undefined) { object(request.options, "open options"); for (const key of ["id", "component", "props"]) if (key in request.options) throw new SparkError("E_INVALID_ARGUMENT", "Navigator identity and props cannot be overridden in options"); }
79
+ const options = { ...mergeOptions(registration.options, request.options ?? {}), id: registration.id, component: registration.moduleName, props: request.props } as WindowOpenOptions;
68
80
  validateOptions(options, Platform.OS, true);
69
81
  const snapshot = JSON.parse(JSON.stringify(options));
70
82
  // Always load before native creation. Failed loaders remain retryable and leave no native shell.
@@ -1,4 +1,5 @@
1
1
  import { addAppListener } from "@legendapp/spark-desktop-app";
2
+ import { keys, object, windowId } from "../validation";
2
3
  import { SparkError, nativeError, type Subscription } from "@legendapp/spark-desktop-app/src/contracts";
3
4
 
4
5
  export interface PrimaryWindowLifecycleOptions {
@@ -9,12 +10,20 @@ export interface PrimaryWindowLifecycleOptions {
9
10
  onError: (error: SparkError) => void;
10
11
  }
11
12
 
13
+ /** Shared validation for the imperative owner and its React binding. */
14
+ export function validatePrimaryWindowLifecycleOptions(options: PrimaryWindowLifecycleOptions): void {
15
+ object(options, "primary window lifecycle options");
16
+ keys(options, ["windowId", "onInitialOpen", "onReopenRequested", "onWindowClosed", "onError"]);
17
+ windowId(options.windowId);
18
+ for (const key of ["onInitialOpen", "onReopenRequested", "onWindowClosed", "onError"] as const) {
19
+ if ((key === "onInitialOpen" || key === "onError" || options[key] !== undefined) && typeof options[key] !== "function") throw new SparkError("E_INVALID_ARGUMENT", `Expected ${key} callback`);
20
+ }
21
+ }
22
+
12
23
  /** Owns application events for one logical window, including reopened instances. */
13
24
  export function createPrimaryWindowLifecycle(options: PrimaryWindowLifecycleOptions): Subscription {
25
+ validatePrimaryWindowLifecycleOptions(options);
14
26
  const { windowId, onInitialOpen, onReopenRequested, onWindowClosed, onError } = options;
15
- if (typeof windowId !== "string" || !/^[a-zA-Z0-9_-]{1,100}$/.test(windowId)) {
16
- throw new SparkError("E_INVALID_ARGUMENT", "Expected a window ID");
17
- }
18
27
  let active = true;
19
28
  const run = (action: (() => void | Promise<void>) | undefined) => {
20
29
  if (active && action) void Promise.resolve().then(() => { if (active) return action(); })
@@ -1,8 +1,9 @@
1
1
  import { useEffect, useLayoutEffect, useRef } from "react";
2
- import { createPrimaryWindowLifecycle, type PrimaryWindowLifecycleOptions } from "./primaryWindowLifecycle";
2
+ import { createPrimaryWindowLifecycle, validatePrimaryWindowLifecycleOptions, type PrimaryWindowLifecycleOptions } from "./primaryWindowLifecycle";
3
3
  export type UsePrimaryWindowLifecycleOptions = PrimaryWindowLifecycleOptions;
4
4
 
5
5
  export function usePrimaryWindowLifecycle(options: UsePrimaryWindowLifecycleOptions): void {
6
+ validatePrimaryWindowLifecycleOptions(options);
6
7
  const latest = useRef(options);
7
8
  useLayoutEffect(() => { latest.current = options; });
8
9
  useEffect(() => {
@@ -1,9 +1,12 @@
1
1
  import { useEffect, useLayoutEffect, useRef } from "react";
2
- import { nativeError, type AsyncRegistration, type SparkError } from "@legendapp/spark-desktop-app/src/contracts";
2
+ import { nativeError, SparkError, type AsyncRegistration } from "@legendapp/spark-desktop-app/src/contracts";
3
+ import { keys, object } from "../validation";
3
4
  import { addWindowListener } from "../api";
4
5
  import { useWindowId } from "./WindowProvider";
5
6
  export interface WindowHookOptions { onError?: (error: SparkError) => void }
6
7
  export function useWindowFocusEffect(callback: () => void, options: WindowHookOptions = {}) {
8
+ object(options, "window focus options"); keys(options, ["onError"]);
9
+ if (typeof callback !== "function" || (options.onError !== undefined && typeof options.onError !== "function")) throw new SparkError("E_INVALID_ARGUMENT", "Expected window focus callbacks");
7
10
  const id = useWindowId(), latest = useRef({ callback, onError: options.onError });
8
11
  useLayoutEffect(() => { latest.current = { callback, onError: options.onError }; }, [callback, options.onError]);
9
12
  useEffect(() => {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@legendapp/spark-documents",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "private": true,
5
5
  "license": "MIT",
6
6
  "main": "src/index.tsx",
@@ -8,12 +8,12 @@
8
8
  "src"
9
9
  ],
10
10
  "dependencies": {
11
- "@legendapp/spark-file-dialog": "0.0.2",
12
- "@legendapp/spark-file-system": "0.0.2",
13
- "@legendapp/spark-native-menu": "0.0.2",
14
- "@legendapp/spark-desktop-app": "0.0.2",
15
- "@legendapp/spark-desktop-windows": "0.0.2",
16
- "@legendapp/spark-desktop-links": "0.0.2"
11
+ "@legendapp/spark-file-dialog": "0.0.4",
12
+ "@legendapp/spark-file-system": "0.0.4",
13
+ "@legendapp/spark-native-menu": "0.0.4",
14
+ "@legendapp/spark-desktop-app": "0.0.4",
15
+ "@legendapp/spark-desktop-windows": "0.0.4",
16
+ "@legendapp/spark-desktop-links": "0.0.4"
17
17
  },
18
18
  "peerDependencies": {
19
19
  "react": "^19.2.0",
@@ -14,15 +14,46 @@ static NSArray *PasteboardTypes(NSArray *types) {
14
14
  for (NSString *type in types) [result addObject:[type isEqual:@"files"] ? NSPasteboardTypeFileURL : [type isEqual:@"text"] ? NSPasteboardTypeString : [type isEqual:@"urls"] ? NSPasteboardTypeURL : CustomType(type)];
15
15
  return result;
16
16
  }
17
+ @interface RNDesktopDragView ()
18
+ - (BOOL)beginDragFromMouseEvent:(NSEvent *)event;
19
+ @end
20
+
21
+ @interface RNDesktopDragGesture : NSGestureRecognizer
22
+ @end
23
+
24
+ @implementation RNDesktopDragGesture {
25
+ NSPoint _start;
26
+ }
27
+ - (void)mouseDown:(NSEvent *)event { _start = event.locationInWindow; }
28
+ - (void)mouseDragged:(NSEvent *)event {
29
+ NSPoint point = event.locationInWindow;
30
+ if (self.state != NSGestureRecognizerStatePossible || hypot(point.x - _start.x, point.y - _start.y) < 6) return;
31
+ BOOL started = [(RNDesktopDragView *)self.view beginDragFromMouseEvent:event];
32
+ self.state = started ? NSGestureRecognizerStateRecognized : NSGestureRecognizerStateFailed;
33
+ }
34
+ - (void)mouseUp:(NSEvent *)event {
35
+ if (self.state == NSGestureRecognizerStatePossible) self.state = NSGestureRecognizerStateFailed;
36
+ }
37
+ @end
38
+
17
39
  @implementation RNDesktopDragView {
18
40
  NSDictionary *_source;
19
41
  NSDictionary *_options;
20
42
  BOOL _disabled;
21
- BOOL _dragging;
22
- BOOL _mouseDown;
23
- NSPoint _start;
43
+ RNDesktopDragGesture *_dragGesture;
44
+ __weak NSDraggingSession *_dragSession;
45
+ }
46
+ - (instancetype)init {
47
+ if (self = [super init]) {
48
+ _props = std::make_shared<const DesktopDragViewProps>();
49
+ _dragGesture = [RNDesktopDragGesture new];
50
+ _dragGesture.delaysPrimaryMouseButtonEvents = YES;
51
+ _dragGesture.enabled = NO;
52
+ [self addGestureRecognizer:_dragGesture];
53
+ [self registerForDraggedTypes:@[NSPasteboardTypeFileURL, NSPasteboardTypeURL, NSPasteboardTypeString]];
54
+ }
55
+ return self;
24
56
  }
25
- - (instancetype)init { if (self = [super init]) { _props = std::make_shared<const DesktopDragViewProps>(); [self registerForDraggedTypes:@[NSPasteboardTypeFileURL, NSPasteboardTypeURL, NSPasteboardTypeString]]; } return self; }
26
57
  - (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &)oldProps {
27
58
  const auto &value = *std::static_pointer_cast<DesktopDragViewProps const>(props);
28
59
  NSString *json = [NSString stringWithUTF8String:value.sourceJson.c_str()];
@@ -30,11 +61,11 @@ static NSArray *PasteboardTypes(NSArray *types) {
30
61
  NSString *options = [NSString stringWithUTF8String:value.optionsJson.c_str()];
31
62
  _options = options.length ? [NSJSONSerialization JSONObjectWithData:[options dataUsingEncoding:NSUTF8StringEncoding] options:0 error:nil] : nil;
32
63
  [self unregisterDraggedTypes]; [self registerForDraggedTypes:PasteboardTypes(_options[@"acceptedTypes"] ?: @[@"files", @"text", @"urls"])];
33
- _disabled = value.disabled; [super updateProps:props oldProps:oldProps];
64
+ _disabled = value.disabled;
65
+ _dragGesture.enabled = _source.count && !_disabled;
66
+ [super updateProps:props oldProps:oldProps];
34
67
  }
35
68
  - (BOOL)isFlipped { return YES; }
36
- // Fabric parents call the UIKit-compatible overload directly when traversing children.
37
- - (NSView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event { NSView *hit = [super hitTest:point withEvent:event]; return hit && _source.count && !_disabled ? self : hit; }
38
69
  - (BOOL)mouseDownCanMoveWindow { return _source.count && !_disabled ? NO : [super mouseDownCanMoveWindow]; }
39
70
  - (NSDragOperation)operation:(id<NSDraggingInfo>)sender {
40
71
  if (_disabled || ![sender.draggingPasteboard availableTypeFromArray:PasteboardTypes(_options[@"acceptedTypes"] ?: @[@"files", @"text", @"urls"])]) return NSDragOperationNone;
@@ -63,10 +94,8 @@ static NSArray *PasteboardTypes(NSArray *types) {
63
94
  }
64
95
  - (void)draggingExited:(id<NSDraggingInfo>)sender { auto emitter = std::static_pointer_cast<const DesktopDragViewEventEmitter>(_eventEmitter); if (emitter) emitter->onDragLeave({ "{}" }); }
65
96
  - (BOOL)performDragOperation:(id<NSDraggingInfo>)sender { if (![self operation:sender]) return NO; auto emitter = std::static_pointer_cast<const DesktopDragViewEventEmitter>(_eventEmitter); if (!emitter) return NO; emitter->onDrop({ JSON([self payload:sender]) }); return YES; }
66
- - (void)mouseDown:(NSEvent *)event { _mouseDown = YES; _start = event.locationInWindow; if (!_source.count || _disabled) [super mouseDown:event]; }
67
- - (void)mouseUp:(NSEvent *)event { _mouseDown = NO; [super mouseUp:event]; }
68
- - (void)mouseDragged:(NSEvent *)event {
69
- if (!_mouseDown || _dragging || _disabled || !_source.count || hypot(event.locationInWindow.x - _start.x, event.locationInWindow.y - _start.y) < 6) { [super mouseDragged:event]; return; }
97
+ - (BOOL)beginDragFromMouseEvent:(NSEvent *)event {
98
+ if (_dragSession || _disabled || !_source.count || !self.window) return NO;
70
99
  NSMutableArray *writers = [NSMutableArray new];
71
100
  for (NSString *file in _source[@"files"]) if ([file hasPrefix:@"/"]) [writers addObject:[NSURL fileURLWithPath:file]];
72
101
  for (NSString *value in _source[@"urls"]) { NSURL *url = [NSURL URLWithString:value]; if (url) [writers addObject:url]; }
@@ -76,19 +105,50 @@ static NSArray *PasteboardTypes(NSArray *types) {
76
105
  for (NSString *type in _source[@"data"]) [custom setString:_source[@"data"][type] forType:CustomType(type)];
77
106
  [writers addObject:custom];
78
107
  }
79
- if (!writers.count) return;
108
+ if (!writers.count) return NO;
109
+ NSImage *snapshot = nil;
110
+ NSRect sourceRect = NSZeroRect;
111
+ if ([_options[@"dragPreview"] isEqual:@"snapshot"]) {
112
+ sourceRect = NSIntersectionRect(self.bounds, self.visibleRect);
113
+ NSBitmapImageRep *bitmap = NSIsEmptyRect(sourceRect) ? nil : [self bitmapImageRepForCachingDisplayInRect:sourceRect];
114
+ if (bitmap) {
115
+ [self cacheDisplayInRect:sourceRect toBitmapImageRep:bitmap];
116
+ snapshot = [[NSImage alloc] initWithSize:sourceRect.size];
117
+ [snapshot addRepresentation:bitmap];
118
+ }
119
+ }
120
+ NSRect frame = snapshot ? sourceRect : NSMakeRect(0, 0, 32, 32);
121
+ NSImage *image = snapshot ?: [NSImage imageWithSystemSymbolName:@"doc" accessibilityDescription:@"Dragged item"];
80
122
  NSMutableArray *items = [NSMutableArray new];
81
123
  for (id<NSPasteboardWriting> writer in writers) {
82
124
  NSDraggingItem *item = [[NSDraggingItem alloc] initWithPasteboardWriter:writer];
83
- NSImage *image = [NSImage imageWithSystemSymbolName:@"doc" accessibilityDescription:@"Dragged item"];
84
- [item setDraggingFrame:NSMakeRect(0, 0, 32, 32) contents:image]; [items addObject:item];
125
+ // One snapshot represents the whole source, even when it has multiple pasteboard writers.
126
+ if (!snapshot || items.count == 0) [item setDraggingFrame:frame contents:image];
127
+ [items addObject:item];
85
128
  }
86
- _dragging = YES; [self beginDraggingSessionWithItems:items event:event source:self];
129
+ _dragSession = [self beginDraggingSessionWithItems:items event:event source:self];
130
+ return _dragSession != nil;
131
+ }
132
+ - (void)draggingSession:(NSDraggingSession *)session willBeginAtPoint:(NSPoint)point {
133
+ if (session != _dragSession) return;
134
+ auto emitter = std::static_pointer_cast<const DesktopDragViewEventEmitter>(_eventEmitter);
135
+ if (emitter) emitter->onDragStart({ "{}" });
87
136
  }
88
137
  - (NSDragOperation)draggingSession:(NSDraggingSession *)session sourceOperationMaskForDraggingContext:(NSDraggingContext)context { NSDragOperation mask = NSDragOperationNone; for (NSString *name in _options[@"sourceOperations"] ?: @[@"copy"]) mask |= Operation(name); return mask; }
89
138
  - (void)draggingSession:(NSDraggingSession *)session endedAtPoint:(NSPoint)point operation:(NSDragOperation)operation {
90
- _dragging = NO; _mouseDown = NO; auto emitter = std::static_pointer_cast<const DesktopDragViewEventEmitter>(_eventEmitter); if (emitter) emitter->onDragEnd({ JSON(@{ @"accepted": @(operation != NSDragOperationNone), @"operation": OperationName(operation) }) });
139
+ if (session != _dragSession) return;
140
+ _dragSession = nil;
141
+ auto emitter = std::static_pointer_cast<const DesktopDragViewEventEmitter>(_eventEmitter); if (emitter) emitter->onDragEnd({ JSON(@{ @"accepted": @(operation != NSDragOperationNone), @"operation": OperationName(operation) }) });
142
+ }
143
+ - (void)prepareForRecycle {
144
+ [super prepareForRecycle];
145
+ _source = nil;
146
+ _options = nil;
147
+ _disabled = NO;
148
+ _dragGesture.enabled = NO;
149
+ _dragSession = nil;
150
+ [self unregisterDraggedTypes];
151
+ [self registerForDraggedTypes:PasteboardTypes(@[@"files", @"text", @"urls"])];
91
152
  }
92
- - (void)prepareForRecycle { [super prepareForRecycle]; _source = nil; _options = nil; [self unregisterDraggedTypes]; [self registerForDraggedTypes:PasteboardTypes(@[@"files", @"text", @"urls"])]; _disabled = NO; _dragging = NO; _mouseDown = NO; _start = NSZeroPoint; }
93
153
  + (ComponentDescriptorProvider)componentDescriptorProvider { return concreteComponentDescriptorProvider<DesktopDragViewComponentDescriptor>(); }
94
154
  @end
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@legendapp/spark-drag-drop",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "license": "MIT",
5
5
  "main": "src/index.tsx",
6
6
  "react-native": "src/index.tsx",
@@ -28,18 +28,13 @@
28
28
  },
29
29
  "spark": {
30
30
  "sdk": true,
31
- "nativeModules": [],
32
- "pod": "RNDesktopDrag",
33
- "platforms": [
34
- "macos",
35
- "windows"
36
- ],
31
+ "nativeModules": true,
37
32
  "requires": [
38
33
  "@legendapp/spark-desktop-app"
39
34
  ]
40
35
  },
41
36
  "dependencies": {
42
- "@legendapp/spark-desktop-app": "0.0.2"
37
+ "@legendapp/spark-desktop-app": "0.0.4"
43
38
  },
44
39
  "private": true
45
40
  }
@@ -11,6 +11,7 @@ export interface NativeProps extends ViewProps {
11
11
  onDragEnter?: DirectEventHandler<Payload>;
12
12
  onDragOver?: DirectEventHandler<Payload>;
13
13
  onDragLeave?: DirectEventHandler<Payload>;
14
+ onDragStart?: DirectEventHandler<Payload>;
14
15
  onDragEnd?: DirectEventHandler<Payload>;
15
16
  }
16
17
  export default codegenNativeComponent<NativeProps>("DesktopDragView") as HostComponent<NativeProps>;
@@ -8,6 +8,8 @@ export interface DragOverEvent { x: number; y: number; operation: DragOperation
8
8
  export interface DropEvent extends DragPayload, DragOverEvent {}
9
9
  export type DragEndEvent = { accepted: true; operation: DragOperation } | { accepted: false; operation: "none" };
10
10
  export interface DragOptions {
11
+ /** Defaults to the platform preview. Snapshot captures the visible source on macOS and uses the default on Windows. */
12
+ dragPreview?: "default" | "snapshot";
11
13
  sourceOperations?: readonly DragOperation[];
12
14
  acceptedOperations?: readonly DragOperation[];
13
15
  /** Built-ins: files, text, urls. Custom types use MIME names. Default: built-ins. */
@@ -48,17 +50,24 @@ export function dragSource(source: DragPayload | undefined, platform: string, in
48
50
  }
49
51
  export function dragConfiguration(source: DragPayload | undefined, options: DragOptions, platform: string): string {
50
52
  dragSource(source, platform);
51
- return dragOptions(options);
53
+ return dragOptions(options, platform);
52
54
  }
53
- export function dragOptions(options: DragOptions): string {
55
+ export function dragOptions(options: DragOptions, platform: string): string {
54
56
  if (!record(options)) invalid("Expected drag options");
55
- for (const key of Object.keys(options)) if (!["sourceOperations", "acceptedOperations", "acceptedTypes"].includes(key)) throw new SparkError("E_UNSUPPORTED_OPTION", `Unknown drag option: ${key}`);
57
+ for (const key of Object.keys(options)) if (!["sourceOperations", "acceptedOperations", "acceptedTypes", "dragPreview"].includes(key)) throw new SparkError("E_UNSUPPORTED_OPTION", `Unknown drag option: ${key}`);
56
58
  for (const values of [options.sourceOperations, options.acceptedOperations]) {
57
59
  if (values !== undefined && (!strings(values) || values.some(value => !operations.includes(value)) || new Set(values).size !== values.length)) invalid("Drag operations must be unique copy, move or link values");
58
60
  }
59
61
  const types = options.acceptedTypes ?? builtins;
60
62
  if (!strings(types) || new Set(types).size !== types.length || types.some(type => !builtins.includes(type) && !customType(type))) invalid("Invalid or duplicate accepted drag type");
61
- return JSON.stringify({ sourceOperations: options.sourceOperations ?? ["copy"], acceptedOperations: options.acceptedOperations ?? ["copy"], acceptedTypes: types });
63
+ const { dragPreview } = options;
64
+ if (dragPreview !== undefined && dragPreview !== "default" && dragPreview !== "snapshot") invalid("Drag preview must be default or snapshot");
65
+ return JSON.stringify({
66
+ sourceOperations: options.sourceOperations ?? ["copy"],
67
+ acceptedOperations: options.acceptedOperations ?? ["copy"],
68
+ acceptedTypes: types,
69
+ dragPreview: platform === "macos" && dragPreview === "snapshot" ? dragPreview : undefined,
70
+ });
62
71
  }
63
72
  function position(value: unknown): value is DragOverEvent {
64
73
  return record(value) && typeof value.x === "number" && Number.isFinite(value.x) && typeof value.y === "number" && Number.isFinite(value.y) && operations.includes(value.operation as string);