@legendapp/spark 0.0.1-next.3 → 0.0.1-next.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (161) hide show
  1. package/README.md +1 -1
  2. package/camera.ts +13 -0
  3. package/customize.ts +2 -0
  4. package/html.ts +1 -0
  5. package/markdown.ts +1 -0
  6. package/package.json +34 -15
  7. package/patches/camera/react-native-nitro-image.patch +320 -0
  8. package/patches/camera/react-native-nitro-modules.patch +50 -0
  9. package/patches/camera/react-native-vision-camera.patch +2662 -0
  10. package/patches/camera/upstream.json +22 -0
  11. package/patches/dependencies.json +14 -0
  12. package/patches/react-native-enriched-html@1.1.1.patch +854 -0
  13. package/patches/react-native-enriched-markdown@1.1.1.patch +9261 -0
  14. package/postinstall.cjs +1 -0
  15. package/schema.json +104 -0
  16. package/skills/spark/SKILL.md +56 -0
  17. package/skills/spark/UPGRADING.md +246 -0
  18. package/ui-swipe.ts +1 -0
  19. package/vendor/node_modules/@legendapp/spark-ai/package.json +4 -4
  20. package/vendor/node_modules/@legendapp/spark-ai/src/invocation-command.cjs +11 -0
  21. package/vendor/node_modules/@legendapp/spark-ai/src/invocation-command.d.cts +2 -0
  22. package/vendor/node_modules/@legendapp/spark-ai/src/invocations.ts +2 -19
  23. package/vendor/node_modules/@legendapp/spark-audio/package.json +3 -3
  24. package/vendor/node_modules/@legendapp/spark-auth-session/package.json +3 -3
  25. package/vendor/node_modules/@legendapp/spark-cli/dist/add-desktop.js +4 -4
  26. package/vendor/node_modules/@legendapp/spark-cli/dist/build.js +65 -11
  27. package/vendor/node_modules/@legendapp/spark-cli/dist/cli-arguments.js +2 -1
  28. package/vendor/node_modules/@legendapp/spark-cli/dist/commands.js +3 -2
  29. package/vendor/node_modules/@legendapp/spark-cli/dist/create.js +36 -13
  30. package/vendor/node_modules/@legendapp/spark-cli/dist/credentials.js +41 -26
  31. package/vendor/node_modules/@legendapp/spark-cli/dist/customize-ai.cjs +108 -0
  32. package/vendor/node_modules/@legendapp/spark-cli/dist/customize-artifacts.js +315 -0
  33. package/vendor/node_modules/@legendapp/spark-cli/dist/customize-cli.cjs +75 -0
  34. package/vendor/node_modules/@legendapp/spark-cli/dist/customize-github.cjs +133 -0
  35. package/vendor/node_modules/@legendapp/spark-cli/dist/customize-policy.cjs +102 -0
  36. package/vendor/node_modules/@legendapp/spark-cli/dist/customize-provider.cjs +2 -0
  37. package/vendor/node_modules/@legendapp/spark-cli/dist/customize-worker.cjs +273 -0
  38. package/vendor/node_modules/@legendapp/spark-cli/dist/dependency-pins.js +157 -0
  39. package/vendor/node_modules/@legendapp/spark-cli/dist/dev-command.js +3 -1
  40. package/vendor/node_modules/@legendapp/spark-cli/dist/dev.js +1 -1
  41. package/vendor/node_modules/@legendapp/spark-cli/dist/enriched-html-pins.js +128 -0
  42. package/vendor/node_modules/@legendapp/spark-cli/dist/errors.js +100 -0
  43. package/vendor/node_modules/@legendapp/spark-cli/dist/examples.js +1 -1
  44. package/vendor/node_modules/@legendapp/spark-cli/dist/expo-dev-patch.cjs +30 -1
  45. package/vendor/node_modules/@legendapp/spark-cli/dist/expo-native.cjs +5 -1
  46. package/vendor/node_modules/@legendapp/spark-cli/dist/helpers.js +1 -1
  47. package/vendor/node_modules/@legendapp/spark-cli/dist/index.js +52 -7
  48. package/vendor/node_modules/@legendapp/spark-cli/dist/init-template.d.cts +1 -0
  49. package/vendor/node_modules/@legendapp/spark-cli/dist/js-runtime.cjs +96 -0
  50. package/vendor/node_modules/@legendapp/spark-cli/dist/json.js +16 -0
  51. package/vendor/node_modules/@legendapp/spark-cli/dist/migration-helpers.cjs +152 -0
  52. package/vendor/node_modules/@legendapp/spark-cli/dist/migration-helpers.d.cts +15 -0
  53. package/vendor/node_modules/@legendapp/spark-cli/dist/migrations.cjs +184 -0
  54. package/vendor/node_modules/@legendapp/spark-cli/dist/migrations.d.cts +16 -0
  55. package/vendor/node_modules/@legendapp/spark-cli/dist/native-patch-preflight.js +5 -1
  56. package/vendor/node_modules/@legendapp/spark-cli/dist/package-manager-config.js +41 -0
  57. package/vendor/node_modules/@legendapp/spark-cli/dist/package-manager.js +13 -0
  58. package/vendor/node_modules/@legendapp/spark-cli/dist/process.js +7 -0
  59. package/vendor/node_modules/@legendapp/spark-cli/dist/project-version.js +12 -0
  60. package/vendor/node_modules/@legendapp/spark-cli/dist/project.js +66 -30
  61. package/vendor/node_modules/@legendapp/spark-cli/dist/release.js +2 -1
  62. package/vendor/node_modules/@legendapp/spark-cli/dist/release.json +20 -20
  63. package/vendor/node_modules/@legendapp/spark-cli/dist/runtime-bootstrap.ps1 +87 -0
  64. package/vendor/node_modules/@legendapp/spark-cli/dist/runtime-bootstrap.sh +107 -0
  65. package/vendor/node_modules/@legendapp/spark-cli/dist/runtime-downloads.tsv +13 -0
  66. package/vendor/node_modules/@legendapp/spark-cli/dist/sdk-install.js +8 -3
  67. package/vendor/node_modules/@legendapp/spark-cli/dist/universal.cjs +2 -1
  68. package/vendor/node_modules/@legendapp/spark-cli/dist/upgrade.js +102 -0
  69. package/vendor/node_modules/@legendapp/spark-cli/dist/windows.js +1 -8
  70. package/vendor/node_modules/@legendapp/spark-cli/package.json +6 -4
  71. package/vendor/node_modules/@legendapp/spark-cli/templates/blank-typescript/.claude/skills/spark/SKILL.md +9 -0
  72. package/vendor/node_modules/@legendapp/spark-cli/templates/blank-typescript/AGENTS.md +4 -0
  73. package/vendor/node_modules/@legendapp/spark-cli/templates/blank-typescript/CLAUDE.md +4 -0
  74. package/vendor/node_modules/@legendapp/spark-cli/templates/blank-typescript/README.md +15 -0
  75. package/vendor/node_modules/@legendapp/spark-cli/templates/blank-typescript/package.json +47 -3
  76. package/vendor/node_modules/@legendapp/spark-cli/templates/universal/.claude/skills/spark/SKILL.md +9 -0
  77. package/vendor/node_modules/@legendapp/spark-cli/templates/universal/AGENTS.md +4 -0
  78. package/vendor/node_modules/@legendapp/spark-cli/templates/universal/CLAUDE.md +4 -0
  79. package/vendor/node_modules/@legendapp/spark-cli/templates/universal/README.md +15 -0
  80. package/vendor/node_modules/@legendapp/spark-cli/templates/universal/package.json +46 -3
  81. package/vendor/node_modules/@legendapp/spark-cli/templates/windows/.claude/skills/spark/SKILL.md +9 -0
  82. package/vendor/node_modules/@legendapp/spark-cli/templates/windows/AGENTS.md +4 -0
  83. package/vendor/node_modules/@legendapp/spark-cli/templates/windows/CLAUDE.md +4 -0
  84. package/vendor/node_modules/@legendapp/spark-cli/templates/windows/README.md +15 -0
  85. package/vendor/node_modules/@legendapp/spark-cli/templates/windows/package.json +47 -3
  86. package/vendor/node_modules/@legendapp/spark-clipboard/package.json +3 -3
  87. package/vendor/node_modules/@legendapp/spark-codex/package.json +4 -4
  88. package/vendor/node_modules/@legendapp/spark-commands/package.json +6 -6
  89. package/vendor/node_modules/@legendapp/spark-context-menu/package.json +3 -3
  90. package/vendor/node_modules/@legendapp/spark-desktop-app/macos/RNDesktopApp.mm +14 -1
  91. package/vendor/node_modules/@legendapp/spark-desktop-app/package.json +2 -2
  92. package/vendor/node_modules/@legendapp/spark-desktop-app/src/contracts/menu.ts +6 -4
  93. package/vendor/node_modules/@legendapp/spark-desktop-app/src/customize-hooks.ts +17 -0
  94. package/vendor/node_modules/@legendapp/spark-desktop-app/src/customize.ts +117 -0
  95. package/vendor/node_modules/@legendapp/spark-desktop-config/app.plugin.cjs +20 -1
  96. package/vendor/node_modules/@legendapp/spark-desktop-config/config.cjs +5 -2
  97. package/vendor/node_modules/@legendapp/spark-desktop-config/config.d.cts +14 -0
  98. package/vendor/node_modules/@legendapp/spark-desktop-config/customize-provider.cjs +16 -0
  99. package/vendor/node_modules/@legendapp/spark-desktop-config/customize.cjs +16 -0
  100. package/vendor/node_modules/@legendapp/spark-desktop-config/expo.cjs +1 -0
  101. package/vendor/node_modules/@legendapp/spark-desktop-config/native-patches.cjs +106 -0
  102. package/vendor/node_modules/@legendapp/spark-desktop-config/native-patches.d.cts +1 -0
  103. package/vendor/node_modules/@legendapp/spark-desktop-config/package.json +5 -4
  104. package/vendor/node_modules/@legendapp/spark-desktop-config/schema.json +104 -0
  105. package/vendor/node_modules/@legendapp/spark-desktop-host/SparkCustomize.mm +517 -0
  106. package/vendor/node_modules/@legendapp/spark-desktop-host/package.json +4 -3
  107. package/vendor/node_modules/@legendapp/spark-desktop-links/package.json +3 -3
  108. package/vendor/node_modules/@legendapp/spark-desktop-shortcuts/macos/RNDesktopShortcuts.mm +3 -1
  109. package/vendor/node_modules/@legendapp/spark-desktop-shortcuts/macos/keyboard-manager/RNKeyboardManager.h +3 -0
  110. package/vendor/node_modules/@legendapp/spark-desktop-shortcuts/macos/keyboard-manager/RNKeyboardManager.mm +1 -1
  111. package/vendor/node_modules/@legendapp/spark-desktop-shortcuts/package.json +3 -3
  112. package/vendor/node_modules/@legendapp/spark-desktop-windows/macos/window-manager/RNWindowManager.mm +44 -4
  113. package/vendor/node_modules/@legendapp/spark-desktop-windows/package.json +4 -4
  114. package/vendor/node_modules/@legendapp/spark-desktop-windows/src/api.ts +65 -26
  115. package/vendor/node_modules/@legendapp/spark-desktop-windows/src/macos-adapter.ts +8 -6
  116. package/vendor/node_modules/@legendapp/spark-documents/package.json +8 -8
  117. package/vendor/node_modules/@legendapp/spark-drag-drop/package.json +3 -3
  118. package/vendor/node_modules/@legendapp/spark-file-dialog/package.json +3 -3
  119. package/vendor/node_modules/@legendapp/spark-file-system/macos/SparkFileMutations.h +1 -0
  120. package/vendor/node_modules/@legendapp/spark-file-system/macos/SparkFileMutations.mm +11 -10
  121. package/vendor/node_modules/@legendapp/spark-file-system/package.json +3 -3
  122. package/vendor/node_modules/@legendapp/spark-global-shortcuts/package.json +3 -3
  123. package/vendor/node_modules/@legendapp/spark-html/package.json +24 -0
  124. package/vendor/node_modules/@legendapp/spark-html/src/Html.tsx +22 -0
  125. package/vendor/node_modules/@legendapp/spark-html/src/HtmlInput.tsx +102 -0
  126. package/vendor/node_modules/@legendapp/spark-html/src/index.ts +4 -0
  127. package/vendor/node_modules/@legendapp/spark-html/src/types.ts +4 -0
  128. package/vendor/node_modules/@legendapp/spark-markdown/package.json +24 -0
  129. package/vendor/node_modules/@legendapp/spark-markdown/src/Markdown.tsx +24 -0
  130. package/vendor/node_modules/@legendapp/spark-markdown/src/MarkdownInput.tsx +111 -0
  131. package/vendor/node_modules/@legendapp/spark-markdown/src/index.ts +4 -0
  132. package/vendor/node_modules/@legendapp/spark-message-dialog/package.json +3 -3
  133. package/vendor/node_modules/@legendapp/spark-native-menu/package.json +3 -3
  134. package/vendor/node_modules/@legendapp/spark-notifications/package.json +3 -3
  135. package/vendor/node_modules/@legendapp/spark-notifications/windows/SparkNotifications/SparkNotifications.h +16 -11
  136. package/vendor/node_modules/@legendapp/spark-processes/package.json +3 -3
  137. package/vendor/node_modules/@legendapp/spark-rich-text/package.json +18 -0
  138. package/vendor/node_modules/@legendapp/spark-rich-text/src/components.tsx +52 -0
  139. package/vendor/node_modules/@legendapp/spark-rich-text/src/index.ts +4 -0
  140. package/vendor/node_modules/@legendapp/spark-rich-text/src/types.ts +24 -0
  141. package/vendor/node_modules/@legendapp/spark-rich-text/src/useInputShortcuts.macos.ts +55 -0
  142. package/vendor/node_modules/@legendapp/spark-rich-text/src/useInputShortcuts.ts +13 -0
  143. package/vendor/node_modules/@legendapp/spark-rich-text/src/useInputValue.ts +14 -0
  144. package/vendor/node_modules/@legendapp/spark-rich-text/src/value.ts +16 -0
  145. package/vendor/node_modules/@legendapp/spark-secure-storage/package.json +3 -3
  146. package/vendor/node_modules/@legendapp/spark-settings/package.json +3 -3
  147. package/vendor/node_modules/@legendapp/spark-settings-ui/package.json +5 -5
  148. package/vendor/node_modules/@legendapp/spark-sqlite/package.json +3 -3
  149. package/vendor/node_modules/@legendapp/spark-system/package.json +3 -3
  150. package/vendor/node_modules/@legendapp/spark-tray/package.json +3 -3
  151. package/vendor/node_modules/@legendapp/spark-ui/macos/appkit-split-view/RNSidebarSplitViewComponent.mm +360 -35
  152. package/vendor/node_modules/@legendapp/spark-ui/macos/swipe-actions/RNSwipeActions.h +10 -0
  153. package/vendor/node_modules/@legendapp/spark-ui/macos/swipe-actions/RNSwipeActions.mm +422 -0
  154. package/vendor/node_modules/@legendapp/spark-ui/package.json +4 -3
  155. package/vendor/node_modules/@legendapp/spark-ui/src/appkit-split-view/SidebarSplitViewNativeComponent.ts +11 -0
  156. package/vendor/node_modules/@legendapp/spark-ui/src/appkit-split-view/index.tsx +30 -13
  157. package/vendor/node_modules/@legendapp/spark-ui/src/swipe-actions/SwipeActionsNativeComponent.ts +11 -0
  158. package/vendor/node_modules/@legendapp/spark-ui/src/swipe-actions/index.tsx +41 -0
  159. package/vendor/node_modules/@legendapp/spark-updates/package.json +3 -3
  160. package/vendor/node_modules/@legendapp/spark-webview/package.json +2 -2
  161. package/vendor/node_modules/@legendapp/spark-window-options/package.json +1 -1
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@legendapp/spark-desktop-shortcuts",
3
- "version": "0.0.1-next.3",
3
+ "version": "0.0.1-next.5",
4
4
  "license": "MIT",
5
5
  "main": "src/index",
6
6
  "react-native": "src/index",
@@ -10,7 +10,7 @@
10
10
  "*.podspec"
11
11
  ],
12
12
  "peerDependencies": {
13
- "react": "19.1.4",
13
+ "react": "^19.1.0",
14
14
  "react-native": "0.81.6"
15
15
  },
16
16
  "codegenConfig": {
@@ -40,7 +40,7 @@
40
40
  ]
41
41
  },
42
42
  "dependencies": {
43
- "@legendapp/spark-desktop-app": "0.0.1-next.3"
43
+ "@legendapp/spark-desktop-app": "0.0.1-next.5"
44
44
  },
45
45
  "private": true
46
46
  }
@@ -556,12 +556,13 @@ static void LegendPrepareWindowForDisplay(NSWindow *window, NSString *background
556
556
 
557
557
  static void LegendApplyContentLayoutMode(NSWindow *window, NSNumber *maskNumber, BOOL usesTitlebarBackground)
558
558
  {
559
- if (usesTitlebarBackground) {
559
+ NSString *contentLayoutMode = objc_getAssociatedObject(window, &LegendContentLayoutModeKey);
560
+ if ([contentLayoutMode isEqualToString:@"fullSize"] || (usesTitlebarBackground && ![contentLayoutMode isEqualToString:@"contentLayoutGuide"])) {
560
561
  window.styleMask = window.styleMask | NSWindowStyleMaskFullSizeContentView;
561
562
  return;
562
563
  }
563
564
 
564
- if (maskNumber && (maskNumber.unsignedIntegerValue & NSWindowStyleMaskFullSizeContentView) == 0) {
565
+ if ([contentLayoutMode isEqualToString:@"contentLayoutGuide"] || (maskNumber && (maskNumber.unsignedIntegerValue & NSWindowStyleMaskFullSizeContentView) == 0)) {
565
566
  window.styleMask = window.styleMask & ~NSWindowStyleMaskFullSizeContentView;
566
567
  }
567
568
  }
@@ -683,7 +684,7 @@ static void LegendApplyWindowOptions(NSWindow *window, NSDictionary *options)
683
684
  LegendApplyWindowBackgroundColor(window, backgroundColor);
684
685
 
685
686
  RCTUIView *rootView = LegendManagedRootView(window);
686
- if (usesTitlebarBackground && rootView) {
687
+ if ((usesTitlebarBackground || contentLayoutMode.length > 0) && rootView) {
687
688
  LegendEnsureRootViewContainer(window, rootView);
688
689
  LegendSizeRootViewToWindow(rootView, window);
689
690
  }
@@ -1219,7 +1220,37 @@ RCT_EXPORT_MODULE(NativeWindowManager)
1219
1220
  NSMutableDictionary *config = [item mutableCopy]; config[@"instanceId"] = objc_getAssociatedObject(window, NSSelectorFromString(@"sparkWindowInstanceId")) ?: @""; [configs addObject:config];
1220
1221
  }
1221
1222
  }
1223
+ NSArray<NSDictionary *> *previousConfigs = self.toolbarItemConfigs[toolbar.identifier];
1224
+ BOOL menuUpdate = previousConfigs != nil && previousConfigs.count == configs.count;
1225
+ for (NSUInteger index = 0; menuUpdate && index < configs.count; index++) {
1226
+ NSMutableDictionary *previous = [previousConfigs[index] mutableCopy];
1227
+ NSMutableDictionary *next = [configs[index] mutableCopy];
1228
+ if ([next[@"type"] isEqual:@"menuButton"]) {
1229
+ [previous removeObjectForKey:@"menuItems"];
1230
+ [next removeObjectForKey:@"menuItems"];
1231
+ }
1232
+ menuUpdate = [previous isEqualToDictionary:next];
1233
+ }
1222
1234
  self.toolbarItemConfigs[toolbar.identifier] = configs;
1235
+ if (menuUpdate) {
1236
+ for (NSDictionary *config in configs) {
1237
+ if (![config[@"type"] isEqual:@"menuButton"]) continue;
1238
+ NSString *itemId = config[@"id"];
1239
+ if (![itemId isKindOfClass:NSString.class] || itemId.length == 0) { menuUpdate = NO; break; }
1240
+ NSString *itemIdentifier = [@"legend.toolbar." stringByAppendingString:itemId];
1241
+ NSToolbarItem *item = nil;
1242
+ for (NSToolbarItem *candidate in toolbar.items) {
1243
+ if ([candidate.itemIdentifier isEqual:itemIdentifier]) { item = candidate; break; }
1244
+ }
1245
+ id control = item.view ?: item;
1246
+ NSDictionary *metadata = control ? objc_getAssociatedObject(control, &LegendToolbarControlMetadataKey) : nil;
1247
+ if (!metadata) { menuUpdate = NO; break; }
1248
+ NSMutableDictionary *nextMetadata = [metadata mutableCopy];
1249
+ nextMetadata[@"menuItems"] = config[@"menuItems"] ?: @[];
1250
+ objc_setAssociatedObject(control, &LegendToolbarControlMetadataKey, nextMetadata, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
1251
+ }
1252
+ if (menuUpdate) return;
1253
+ }
1223
1254
 
1224
1255
  while (toolbar.items.count > 0) {
1225
1256
  [toolbar removeItemAtIndex:toolbar.items.count - 1];
@@ -2262,7 +2293,7 @@ willBeInsertedIntoToolbar:(BOOL)flag
2262
2293
  }
2263
2294
  [rootView removeFromSuperview];
2264
2295
  targetWindow.contentView = rootView;
2265
- if (usesTitlebarBackground) {
2296
+ if (usesTitlebarBackground || contentLayoutMode.length > 0) {
2266
2297
  LegendEnsureRootViewContainer(targetWindow, rootView);
2267
2298
  }
2268
2299
  LegendApplyWindowBackgroundColor(targetWindow, backgroundColor);
@@ -2416,6 +2447,15 @@ willBeInsertedIntoToolbar:(BOOL)flag
2416
2447
  resolve([self failureJson:@"Toolbar item does not support text"]);
2417
2448
  return;
2418
2449
  }
2450
+ NSMutableArray *configs = [self.toolbarItemConfigs[window.toolbar.identifier] mutableCopy];
2451
+ for (NSUInteger index = 0; index < configs.count; index++) {
2452
+ if (![[self toolbarItemIdentifierForConfig:configs[index]] isEqualToString:toolbarIdentifier]) continue;
2453
+ NSMutableDictionary *config = [configs[index] mutableCopy];
2454
+ config[[toolbarItem.view isKindOfClass:NSTextField.class] ? @"text" : @"label"] = text ?: @"";
2455
+ configs[index] = config;
2456
+ break;
2457
+ }
2458
+ self.toolbarItemConfigs[window.toolbar.identifier] = configs;
2419
2459
  resolve([self successJson]);
2420
2460
  });
2421
2461
  #else
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@legendapp/spark-desktop-windows",
3
- "version": "0.0.1-next.3",
3
+ "version": "0.0.1-next.5",
4
4
  "license": "MIT",
5
5
  "main": "src/index",
6
6
  "react-native": "src/index",
@@ -10,7 +10,7 @@
10
10
  "*.podspec"
11
11
  ],
12
12
  "peerDependencies": {
13
- "react": "19.1.4",
13
+ "react": "^19.1.0",
14
14
  "react-native": "0.81.6"
15
15
  },
16
16
  "codegenConfig": {
@@ -40,8 +40,8 @@
40
40
  ]
41
41
  },
42
42
  "dependencies": {
43
- "@legendapp/spark-desktop-app": "0.0.1-next.3",
44
- "@legendapp/spark-window-options": "0.0.1-next.3",
43
+ "@legendapp/spark-desktop-app": "0.0.1-next.5",
44
+ "@legendapp/spark-window-options": "0.0.1-next.5",
45
45
  "@legendapp/state": "^3.0.0-beta.42"
46
46
  },
47
47
  "private": true
@@ -33,8 +33,8 @@ export async function openWindow(options: WindowOpenOptions): Promise<WindowInfo
33
33
  try {
34
34
  const info = await windowCall("completeOpen", snapshot, isInfo);
35
35
  // Common chrome is applied first; explicit AppKit groups own their corresponding fields.
36
- if (!snapshot.macos) return publicInfo(info);
37
- await updateMacOSWindow(snapshot.id, snapshot.macos);
36
+ if (!snapshot.macos && snapshot.appearance === undefined && snapshot.backgroundColor === undefined) return publicInfo(info);
37
+ await updateMacOSWindow(snapshot.id, snapshot);
38
38
  // The window now exists: reflect the applied chrome, but a transient read-back
39
39
  // failure must not discard a window that opened successfully, so fall back to info.
40
40
  try { return await getWindow(snapshot.id); } catch { return publicInfo(info); }
@@ -54,8 +54,10 @@ export async function getCursorPoint(): Promise<CursorPoint> { return windowCall
54
54
  export async function setWindowOptions(id: string, options: WindowUpdateOptions): Promise<void> {
55
55
  windowId(id); validateOptions(options, Platform.OS, false);
56
56
  const snapshot = JSON.parse(JSON.stringify(options)) as WindowUpdateOptions;
57
- await windowCommand("options", { id, options: snapshot });
58
- if (snapshot.macos) await updateMacOSWindow(id, snapshot.macos);
57
+ if (!snapshot.macos || Object.keys(snapshot).some(key => key !== "macos")) {
58
+ await windowCommand("options", { id, options: snapshot });
59
+ }
60
+ if (Platform.OS === "macos" && (snapshot.macos || snapshot.appearance !== undefined || snapshot.backgroundColor !== undefined)) await updateMacOSWindow(id, snapshot);
59
61
  }
60
62
  /** Portable frame change. Animated moves are macOS-only: pass `macos.durationMs` and the call rejects on Windows rather than ignoring the request. */
61
63
  export async function setWindowBounds(id: string, value: WindowBounds, options: SetWindowBoundsOptions = {}): Promise<void> {
@@ -111,43 +113,80 @@ export async function addWindowListener<K extends keyof WindowEventMap>(id: stri
111
113
  try { listener(payload as WindowEventMap[K]); } catch (cause) { report(options, cause); }
112
114
  }, [type]);
113
115
  }
114
- const guards = new Map<string, AsyncRegistration>();
116
+ interface CloseGuardOwner {
117
+ handler: () => boolean | Promise<boolean>;
118
+ options: WindowListenerOptions;
119
+ stopped: boolean;
120
+ registration: AsyncRegistration;
121
+ }
122
+ interface CloseGuard {
123
+ owner?: CloseGuardOwner;
124
+ acquire(handler: CloseGuardOwner["handler"], options: WindowListenerOptions): AsyncRegistration;
125
+ }
126
+ const guards = new Map<string, CloseGuard>();
115
127
  const creatingGuards = new Set<string>();
116
128
  const orphanGuards = new Map<string, AsyncRegistration>();
117
129
  let guardSequence = 0;
118
- /** Each window accepts one close guard; a second registration rejects E_BUSY until the first is removed. Removal is idempotent. */
130
+ /** One owner per window. Replacement waits for removal; native protection survives the handoff. */
119
131
  export async function beforeWindowClose(id: string, handler: () => boolean | Promise<boolean>, options: WindowListenerOptions = {}): Promise<AsyncRegistration> {
120
132
  windowId(id); object(options, "guard options"); keys(options, ["onError"]);
121
133
  if (typeof handler !== "function" || (options.onError !== undefined && typeof options.onError !== "function")) throw new SparkError("E_INVALID_ARGUMENT", "Expected window close callbacks");
122
- if (orphanGuards.has(id)) { await orphanGuards.get(id)!.remove(); orphanGuards.delete(id); }
123
- if (guards.has(id) || creatingGuards.has(id)) throw new SparkError("E_BUSY", "Window already has a close guard");
134
+ if (creatingGuards.has(id)) throw new SparkError("E_BUSY", "Window already has a close guard");
124
135
  creatingGuards.add(id);
136
+ try {
137
+ if (orphanGuards.has(id)) { await orphanGuards.get(id)!.remove(); orphanGuards.delete(id); }
138
+ const existing = guards.get(id);
139
+ if (existing) {
140
+ if (existing.owner && !existing.owner.stopped) throw new SparkError("E_BUSY", "Window already has a close guard");
141
+ if (existing.owner) await existing.owner.registration.remove();
142
+ if (guards.get(id) === existing) return existing.acquire(handler, options);
143
+ }
144
+ return await createCloseGuard(id, handler, options);
145
+ } finally { creatingGuards.delete(id); }
146
+ }
147
+ async function createCloseGuard(id: string, handler: CloseGuardOwner["handler"], options: WindowListenerOptions): Promise<AsyncRegistration> {
125
148
  const guardId = `close-${Date.now()}-${++guardSequence}`;
126
- let stopped = false, instance: string | undefined, request: number | undefined, latestRequest = 0;
149
+ let closed = false, instance: string | undefined, request: number | undefined, latestRequest = 0;
127
150
  let subscription: ReturnType<typeof onDesktopEvent>;
128
- try { subscription = onDesktopEvent(event => {
129
- if (stopped || event.windowId !== id || event.instanceId !== instance) return;
130
- if (event.type === "closed") { stopped = true; subscription.remove(); guards.delete(id); return; }
151
+ const stop = () => { closed = true; request = undefined; subscription.remove(); if (guards.get(id) === guard) guards.delete(id); };
152
+ const guard: CloseGuard = { acquire(handler, options) {
153
+ const owner: CloseGuardOwner = { handler, options, stopped: false, registration: asyncRegistration(() => {
154
+ owner.stopped = true; request = undefined;
155
+ }, async () => {
156
+ // Keep the native dispatcher installed for this window instance. Re-arming
157
+ // acknowledges removal and cancels pending decisions without an unguarded gap.
158
+ try { if (!closed && instance) await windowCommand("closeGuard", { id, instanceId: instance, guardId, enabled: true }); }
159
+ catch (cause) { if (nativeError(cause).code !== "E_NOT_FOUND") throw cause; stop(); }
160
+ if (guard.owner === owner) guard.owner = undefined;
161
+ }) };
162
+ guard.owner = owner;
163
+ return owner.registration;
164
+ } };
165
+ const registration = guard.acquire(handler, options);
166
+ subscription = onDesktopEvent(event => {
167
+ if (closed || event.windowId !== id || event.instanceId !== instance) return;
168
+ if (event.type === "closed") { stop(); return; }
131
169
  if (event.guardId !== guardId) return;
132
- if (event.type === "closeGuardTimeout") { request = undefined; report(options, new SparkError("E_TIMEOUT", "Window close guard exceeded 30 seconds")); return; }
170
+ const owner = guard.owner;
171
+ if (event.type === "closeGuardTimeout") { request = undefined; if (owner && !owner.stopped) report(owner.options, new SparkError("E_TIMEOUT", "Window close guard exceeded 30 seconds")); return; }
133
172
  if (event.type !== "beforeClose" || !Number.isSafeInteger(event.requestId) || (event.requestId as number) <= latestRequest) return;
134
173
  const current = latestRequest = request = event.requestId as number;
135
- void Promise.resolve().then(() => stopped ? false : handler()).catch(cause => { report(options, cause); return false; }).then(async allow => {
136
- if (stopped || request !== current) return;
137
- await windowCommand("replyClose", { id, instanceId: instance, guardId, requestId: current, allow: allow === true });
138
- }).catch(cause => report(options, cause)).finally(() => { if (request === current) request = undefined; });
139
- }, { types: ["closed", "beforeClose", "closeGuardTimeout"], target: { field: "windowId", value: id } }); } catch (cause) { creatingGuards.delete(id); throw cause; }
140
- const registration = asyncRegistration(() => { stopped = true; subscription.remove(); }, async () => {
141
- try { if (instance) await windowCommand("closeGuard", { id, instanceId: instance, guardId, enabled: false }); }
142
- catch (cause) { if (nativeError(cause).code !== "E_NOT_FOUND") throw cause; }
143
- if (guards.get(id) === registration) guards.delete(id);
144
- });
174
+ void Promise.resolve().then(() => owner ? !owner.stopped && owner.handler() : true).catch(cause => { if (owner && !owner.stopped) report(owner.options, cause); return false; }).then(async allow => {
175
+ if (closed || request !== current) return;
176
+ await windowCommand("replyClose", { id, instanceId: instance, guardId, requestId: current, allow: guard.owner === owner && allow === true });
177
+ }).catch(cause => { if (owner && !owner.stopped) report(owner.options, cause); }).finally(() => { if (request === current) request = undefined; });
178
+ }, { types: ["closed", "beforeClose", "closeGuardTimeout"], target: { field: "windowId", value: id } });
145
179
  try {
146
180
  instance = (await windowCall("observe", { id }, isInfo)).instanceId;
147
181
  await windowCommand("closeGuard", { id, instanceId: instance, guardId, enabled: true });
148
- if (!stopped) guards.set(id, registration); return registration;
182
+ if (!closed) guards.set(id, guard);
183
+ return registration;
149
184
  } catch (cause) {
150
- try { await registration.remove(); } catch (cleanup) { orphanGuards.set(id, registration); report(options, cleanup); }
185
+ const cleanup = asyncRegistration(stop, async () => {
186
+ try { if (instance) await windowCommand("closeGuard", { id, instanceId: instance, guardId, enabled: false }); }
187
+ catch (cause) { if (nativeError(cause).code !== "E_NOT_FOUND") throw cause; }
188
+ });
189
+ try { await cleanup.remove(); } catch (error) { orphanGuards.set(id, cleanup); report(options, error); }
151
190
  throw cause;
152
- } finally { creatingGuards.delete(id); }
191
+ }
153
192
  }
@@ -2,7 +2,7 @@ import { Platform } from "react-native";
2
2
  import { SparkError, invokeNative, parseNativeResult } from "@legendapp/spark-desktop-app/src/contracts";
3
3
  import { menuItems } from "@legendapp/spark-desktop-app/src/contracts/menu";
4
4
  import Native from "./window-manager/NativeWindowManager";
5
- import type { MacOSWindowOptions, WindowOpenOptions } from "./types";
5
+ import type { WindowOpenOptions, WindowUpdateOptions } from "./types";
6
6
  export function macosNative() {
7
7
  if (Platform.OS !== "macos") throw new SparkError("E_UNSUPPORTED_PLATFORM", "This operation requires macOS");
8
8
  if (!Native) throw new SparkError("E_MODULE_UNAVAILABLE", "The macOS window module is unavailable");
@@ -12,9 +12,11 @@ export async function macosCommand(operation: () => Promise<string>): Promise<vo
12
12
  const result = parseNativeResult(await invokeNative(operation), (value): value is { success: boolean; message?: string } => !!value && typeof value === "object" && typeof (value as any).success === "boolean");
13
13
  if (!result.success) throw new SparkError("E_NATIVE", result.message ?? "macOS window operation failed");
14
14
  }
15
- export function macosOptions(options: MacOSWindowOptions | undefined): Record<string, unknown> {
16
- if (!options) return {};
15
+ export function macosOptions({ macos: options, appearance, backgroundColor }: Pick<WindowOpenOptions, "macos" | "appearance" | "backgroundColor">): Record<string, unknown> {
17
16
  const result: Record<string, unknown> = {}, style: Record<string, unknown> = {};
17
+ if (appearance !== undefined) style.appearance = appearance;
18
+ if (backgroundColor !== undefined) style.backgroundColor = backgroundColor;
19
+ if (!options) return { windowStyle: style };
18
20
  if (options.representedUri !== undefined) result.representedURL = options.representedUri;
19
21
  if (options.restoreOnLaunch !== undefined) result.restoreOnLaunch = options.restoreOnLaunch;
20
22
  if (options.startupSplitView !== undefined) style.startupSplitView = options.startupSplitView;
@@ -38,7 +40,7 @@ export function macosOptions(options: MacOSWindowOptions | undefined): Record<st
38
40
  if (options.toolbar.items) style.toolbarItems = options.toolbar.items.map(item => {
39
41
  const { type, ...common } = item;
40
42
  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 })) }; }
41
- if (type === "menu") { const value = item as Extract<typeof item, { type: "menu" }>; return { ...common, type: "menuButton", enabled: !value.disabled, systemImageName: value.symbol, menuItems: menuItems(value.items, { types: ["action", "checkbox", "separator", "slider"], icons: ["symbol"] }, "macos") }; }
43
+ 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") }; }
42
44
  return { ...common, type, ...("disabled" in item ? { enabled: !item.disabled } : {}), ...("symbol" in item ? { systemImageName: item.symbol } : {}) };
43
45
  });
44
46
  }
@@ -46,8 +48,8 @@ export function macosOptions(options: MacOSWindowOptions | undefined): Record<st
46
48
  return result;
47
49
  }
48
50
  export async function createMacOSWindow(options: WindowOpenOptions): Promise<void> {
49
- await macosCommand(() => macosNative().openWindow(JSON.stringify({ ...macosOptions(options.macos), identifier: options.id, moduleName: options.component, initialProperties: options.props ?? {}, title: options.title, deferOrderFront: true, sparkOverlay: options.kind === "overlay" })));
51
+ await macosCommand(() => macosNative().openWindow(JSON.stringify({ ...macosOptions(options), identifier: options.id, moduleName: options.component, initialProperties: options.props ?? {}, title: options.title, deferOrderFront: true, sparkOverlay: options.kind === "overlay" })));
50
52
  }
51
- export async function updateMacOSWindow(id: string, options: MacOSWindowOptions): Promise<void> {
53
+ export async function updateMacOSWindow(id: string, options: WindowUpdateOptions): Promise<void> {
52
54
  await macosCommand(() => macosNative().setWindowOptions(id, JSON.stringify(macosOptions(options))));
53
55
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@legendapp/spark-documents",
3
- "version": "0.0.1-next.3",
3
+ "version": "0.0.1-next.5",
4
4
  "private": true,
5
5
  "license": "MIT",
6
6
  "main": "src/index.tsx",
@@ -8,15 +8,15 @@
8
8
  "src"
9
9
  ],
10
10
  "dependencies": {
11
- "@legendapp/spark-file-dialog": "0.0.1-next.3",
12
- "@legendapp/spark-file-system": "0.0.1-next.3",
13
- "@legendapp/spark-native-menu": "0.0.1-next.3",
14
- "@legendapp/spark-desktop-app": "0.0.1-next.3",
15
- "@legendapp/spark-desktop-windows": "0.0.1-next.3",
16
- "@legendapp/spark-desktop-links": "0.0.1-next.3"
11
+ "@legendapp/spark-file-dialog": "0.0.1-next.5",
12
+ "@legendapp/spark-file-system": "0.0.1-next.5",
13
+ "@legendapp/spark-native-menu": "0.0.1-next.5",
14
+ "@legendapp/spark-desktop-app": "0.0.1-next.5",
15
+ "@legendapp/spark-desktop-windows": "0.0.1-next.5",
16
+ "@legendapp/spark-desktop-links": "0.0.1-next.5"
17
17
  },
18
18
  "peerDependencies": {
19
- "react": "19.1.4",
19
+ "react": "^19.1.0",
20
20
  "react-native": "0.81.6"
21
21
  }
22
22
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@legendapp/spark-drag-drop",
3
- "version": "0.0.1-next.3",
3
+ "version": "0.0.1-next.5",
4
4
  "license": "MIT",
5
5
  "main": "src/index.tsx",
6
6
  "react-native": "src/index.tsx",
@@ -12,7 +12,7 @@
12
12
  "react-native.config.js"
13
13
  ],
14
14
  "peerDependencies": {
15
- "react": "19.1.4",
15
+ "react": "^19.1.0",
16
16
  "react-native": "0.81.6"
17
17
  },
18
18
  "codegenConfig": {
@@ -39,7 +39,7 @@
39
39
  ]
40
40
  },
41
41
  "dependencies": {
42
- "@legendapp/spark-desktop-app": "0.0.1-next.3"
42
+ "@legendapp/spark-desktop-app": "0.0.1-next.5"
43
43
  },
44
44
  "private": true
45
45
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@legendapp/spark-file-dialog",
3
- "version": "0.0.1-next.3",
3
+ "version": "0.0.1-next.5",
4
4
  "main": "src/index",
5
5
  "react-native": "src/index",
6
6
  "codegenConfig": {
@@ -18,7 +18,7 @@
18
18
  }
19
19
  },
20
20
  "peerDependencies": {
21
- "react": "19.1.4",
21
+ "react": "^19.1.0",
22
22
  "react-native": "0.81.6"
23
23
  },
24
24
  "license": "MIT",
@@ -45,6 +45,6 @@
45
45
  },
46
46
  "private": true,
47
47
  "dependencies": {
48
- "@legendapp/spark-desktop-app": "0.0.1-next.3"
48
+ "@legendapp/spark-desktop-app": "0.0.1-next.5"
49
49
  }
50
50
  }
@@ -18,6 +18,7 @@ enum SparkTransferTestFailure {
18
18
  SparkFailBackupRemoval = 1 << 5,
19
19
  SparkFailStageCleanup = 1 << 6,
20
20
  };
21
+ void SparkSetRemoveTestHook(void (^hook)(void));
21
22
  void SparkSetTransferTestFailures(unsigned failures, BOOL forceCrossVolumeMove);
22
23
  #endif
23
24
  /** Copies or moves, replacing the destination only when overwrite is set. An existing destination otherwise conflicts with NSFileWriteFileExistsError, including a dangling link. Self-transfers and overlapping paths reject. Transfers stage beside the destination before publication; cross-volume moves copy then delete. A cross-volume source-cleanup failure can leave a partial source; source-cleanup and backup-cleanup errors report committed and retained paths. */
@@ -6,6 +6,8 @@
6
6
  #import <stdio.h>
7
7
 
8
8
  #if defined(SPARK_FILE_MUTATIONS_TESTING)
9
+ static void (^SparkRemoveTestHook)(void);
10
+ void SparkSetRemoveTestHook(void (^hook)(void)) { SparkRemoveTestHook = [hook copy]; }
9
11
  static unsigned SparkTransferTestFailures;
10
12
  static BOOL SparkForceCrossVolumeMove;
11
13
  void SparkSetTransferTestFailures(unsigned failures, BOOL forceCrossVolumeMove) {
@@ -202,14 +204,13 @@ BOOL SparkRemoveFile(NSURL *url, BOOL recursive, NSError **error) {
202
204
  userInfo:@{NSUnderlyingErrorKey: [NSError errorWithDomain:NSPOSIXErrorDomain code:code userInfo:nil]}];
203
205
  return NO;
204
206
  }
205
- NSFileManager *fm = NSFileManager.defaultManager;
206
- if (S_ISDIR(info.st_mode) && !recursive) {
207
- NSArray *children = [fm contentsOfDirectoryAtPath:url.path error:error];
208
- if (!children) return NO;
209
- if (children.count) {
210
- if (error) *error = [NSError errorWithDomain:NSPOSIXErrorDomain code:ENOTEMPTY userInfo:nil];
211
- return NO;
212
- }
213
- }
214
- return [fm removeItemAtURL:url error:error];
207
+ #if defined(SPARK_FILE_MUTATIONS_TESTING)
208
+ if (SparkRemoveTestHook) { void (^hook)(void) = SparkRemoveTestHook; SparkRemoveTestHook = nil; hook(); }
209
+ #endif
210
+ if (recursive && S_ISDIR(info.st_mode)) return [NSFileManager.defaultManager removeItemAtURL:url error:error];
211
+ // The OS checks emptiness atomically; never recursively remove a concurrent child.
212
+ if ((S_ISDIR(info.st_mode) ? rmdir(url.fileSystemRepresentation) : unlink(url.fileSystemRepresentation)) == 0) return YES;
213
+ int code = errno;
214
+ if (code != ENOENT && code != ENOTDIR && error) *error = [NSError errorWithDomain:NSPOSIXErrorDomain code:code userInfo:nil];
215
+ return NO;
215
216
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@legendapp/spark-file-system",
3
- "version": "0.0.1-next.3",
3
+ "version": "0.0.1-next.5",
4
4
  "license": "MIT",
5
5
  "main": "src/index.ts",
6
6
  "react-native": "src/index.ts",
@@ -12,7 +12,7 @@
12
12
  "react-native.config.js"
13
13
  ],
14
14
  "peerDependencies": {
15
- "react": "19.1.4",
15
+ "react": "^19.1.0",
16
16
  "react-native": "0.81.6"
17
17
  },
18
18
  "codegenConfig": {
@@ -43,7 +43,7 @@
43
43
  ]
44
44
  },
45
45
  "dependencies": {
46
- "@legendapp/spark-desktop-app": "0.0.1-next.3"
46
+ "@legendapp/spark-desktop-app": "0.0.1-next.5"
47
47
  },
48
48
  "private": true
49
49
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@legendapp/spark-global-shortcuts",
3
- "version": "0.0.1-next.3",
3
+ "version": "0.0.1-next.5",
4
4
  "license": "MIT",
5
5
  "main": "src/index.ts",
6
6
  "react-native": "src/index.ts",
@@ -12,7 +12,7 @@
12
12
  "react-native.config.js"
13
13
  ],
14
14
  "peerDependencies": {
15
- "react": "19.1.4",
15
+ "react": "^19.1.0",
16
16
  "react-native": "0.81.6"
17
17
  },
18
18
  "codegenConfig": {
@@ -41,7 +41,7 @@
41
41
  ]
42
42
  },
43
43
  "dependencies": {
44
- "@legendapp/spark-desktop-app": "0.0.1-next.3"
44
+ "@legendapp/spark-desktop-app": "0.0.1-next.5"
45
45
  },
46
46
  "private": true
47
47
  }
@@ -0,0 +1,24 @@
1
+ {
2
+ "name": "@legendapp/spark-html",
3
+ "version": "0.0.1-next.5",
4
+ "private": true,
5
+ "license": "MIT",
6
+ "main": "src/index.ts",
7
+ "react-native": "src/index.ts",
8
+ "files": [
9
+ "src"
10
+ ],
11
+ "peerDependencies": {
12
+ "react": "^19.1.0",
13
+ "react-native": "0.81.6",
14
+ "react-native-enriched-html": "1.1.1"
15
+ },
16
+ "dependencies": {
17
+ "@legendapp/spark-rich-text": "0.0.1-next.5"
18
+ },
19
+ "peerDependenciesMeta": {
20
+ "react-native-enriched-html": {
21
+ "optional": true
22
+ }
23
+ }
24
+ }
@@ -0,0 +1,22 @@
1
+ import { StyleSheet, type StyleProp, type TextStyle, type ViewProps } from "react-native";
2
+ import { EnrichedText, type EnrichedTextHtmlStyle } from "react-native-enriched-html";
3
+
4
+ export interface HtmlProps extends Omit<ViewProps, "children" | "style"> {
5
+ value?: string;
6
+ children?: string;
7
+ style?: StyleProp<TextStyle>;
8
+ htmlStyle?: EnrichedTextHtmlStyle;
9
+ selectable?: boolean;
10
+ onLinkPress?(event: { url: string }): void;
11
+ }
12
+
13
+ export function Html({ value, children, style, selectable = true, ...props }: HtmlProps) {
14
+ return (
15
+ <EnrichedText
16
+ {...props}
17
+ children={value ?? children ?? ""}
18
+ style={StyleSheet.flatten(style)}
19
+ selectable={selectable}
20
+ />
21
+ );
22
+ }
@@ -0,0 +1,102 @@
1
+ import { useImperativeHandle, useRef, useState } from "react";
2
+ import { StyleSheet, Text, View, type NativeSyntheticEvent } from "react-native";
3
+ import { EnrichedTextInput, type EnrichedTextInputInstance } from "react-native-enriched-html";
4
+ import {
5
+ FormattingButtons,
6
+ InputPreview,
7
+ useInputValue,
8
+ useInputShortcuts,
9
+ type FormattingAction,
10
+ } from "@legendapp/spark-rich-text";
11
+ import { Html } from "./Html";
12
+ import type { HtmlInputProps } from "./types";
13
+
14
+ export function HtmlInput(props: HtmlInputProps) {
15
+ return <HtmlEditor {...props} />;
16
+ }
17
+
18
+ export function EditableHtml(props: HtmlInputProps) {
19
+ return <HtmlEditor {...props} preview />;
20
+ }
21
+
22
+ function HtmlEditor({
23
+ value,
24
+ onChangeText,
25
+ placeholder,
26
+ autoFocus,
27
+ onFocus,
28
+ onBlur,
29
+ style,
30
+ ref,
31
+ formatting,
32
+ onRequestLink,
33
+ accessibilityLabel,
34
+ testID,
35
+ preview = false,
36
+ }: HtmlInputProps & { preview?: boolean }) {
37
+ const input = useRef<EnrichedTextInputInstance | null>(null);
38
+ const initialValue = useRef(value).current;
39
+ const selection = useRef({ start: 0, end: 0, text: "" });
40
+ const [editing, setEditing] = useState(false);
41
+ const format = (action: FormattingAction) => {
42
+ const url = action === "link" ? onRequestLink?.() : undefined;
43
+ input.current?.focus();
44
+ if (action === "link") {
45
+ if (url)
46
+ input.current?.setLink(
47
+ selection.current.start,
48
+ selection.current.end,
49
+ selection.current.text || url,
50
+ url,
51
+ );
52
+ } else if (action === "bold") input.current?.toggleBold();
53
+ else if (action === "italic") input.current?.toggleItalic();
54
+ else if (action === "unorderedList") input.current?.toggleUnorderedList();
55
+ else input.current?.toggleOrderedList();
56
+ };
57
+ useInputShortcuts(input, editing, formatting ? { onFormat: format, linkEnabled: !!onRequestLink } : undefined);
58
+ const change = useInputValue(value, (next) => input.current?.setValue(next), onChangeText);
59
+ useImperativeHandle(ref, () => ({ focus: () => input.current?.focus(), blur: () => input.current?.blur() }), []);
60
+ const inputStyle = StyleSheet.flatten([{ minHeight: 44, padding: 0, fontSize: 16 }, style]);
61
+ return (
62
+ <View>
63
+ {formatting && <FormattingButtons linkEnabled={!!onRequestLink} onFormat={format} />}
64
+ <View>
65
+ <EnrichedTextInput
66
+ ref={input}
67
+ defaultValue={initialValue}
68
+ scrollEnabled={false}
69
+ autoFocus={autoFocus}
70
+ placeholder={placeholder}
71
+ style={inputStyle}
72
+ accessibilityLabel={accessibilityLabel}
73
+ testID={testID}
74
+ onChangeHtml={(event: NativeSyntheticEvent<{ value: string }>) => change(event.nativeEvent.value)}
75
+ onChangeSelection={(event: NativeSyntheticEvent<{ start: number; end: number; text: string }>) => {
76
+ selection.current = event.nativeEvent;
77
+ }}
78
+ onFocus={() => {
79
+ setEditing(true);
80
+ onFocus?.();
81
+ }}
82
+ onBlur={() => {
83
+ setEditing(false);
84
+ onBlur?.();
85
+ }}
86
+ onKeyPress={(event: NativeSyntheticEvent<{ key: string }>) => {
87
+ if (event.nativeEvent.key === "Escape") input.current?.blur();
88
+ }}
89
+ />
90
+ {preview && (
91
+ <InputPreview editing={editing} style={style}>
92
+ {value ? (
93
+ <Html value={value} style={inputStyle} selectable={false} />
94
+ ) : (
95
+ <Text style={[inputStyle, { color: "#888" }]}>{placeholder}</Text>
96
+ )}
97
+ </InputPreview>
98
+ )}
99
+ </View>
100
+ </View>
101
+ );
102
+ }