@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
@@ -47,6 +47,26 @@ static BOOL LegendTestDriverActive(void) { return NO; }
47
47
  @end
48
48
 
49
49
  #if TARGET_OS_OSX
50
+ static NSString *LegendInvalidWindowSymbol(id value)
51
+ {
52
+ if ([value isKindOfClass:NSDictionary.class]) {
53
+ id symbol = value[@"systemImageName"];
54
+ if (symbol && (![symbol isKindOfClass:NSString.class] || ![symbol length] || ![NSImage imageWithSystemSymbolName:symbol accessibilityDescription:nil])) {
55
+ return [NSString stringWithFormat:@"Unknown SF Symbol: %@", symbol];
56
+ }
57
+ for (id child in [value allValues]) {
58
+ NSString *error = LegendInvalidWindowSymbol(child);
59
+ if (error) return error;
60
+ }
61
+ } else if ([value isKindOfClass:NSArray.class]) {
62
+ for (id child in value) {
63
+ NSString *error = LegendInvalidWindowSymbol(child);
64
+ if (error) return error;
65
+ }
66
+ }
67
+ return nil;
68
+ }
69
+
50
70
  static char LegendManagedFullscreenPresentationKey;
51
71
  static NSString * const LegendApplicationReopenRequestedNotification = @"LegendApplicationReopenRequestedNotification";
52
72
  static NSString * const LegendMainWindowCloseRequestedNotification = @"LegendMainWindowCloseRequestedNotification";
@@ -439,6 +459,34 @@ static NSView *LegendCreateOverscannedGlassEffectView(NSRect frame)
439
459
  return containerView;
440
460
  }
441
461
 
462
+ @interface LegendTitlebarTintView : NSView
463
+ @property (nonatomic, strong) NSColor *lightColor;
464
+ @property (nonatomic, strong) NSColor *darkColor;
465
+ @end
466
+
467
+ @implementation LegendTitlebarTintView
468
+ - (BOOL)wantsUpdateLayer
469
+ {
470
+ return YES;
471
+ }
472
+
473
+ - (void)updateLayer
474
+ {
475
+ self.layer.backgroundColor = (LegendAppearanceIsDark(self.effectiveAppearance) ? self.darkColor : self.lightColor).CGColor;
476
+ }
477
+
478
+ - (void)viewDidChangeEffectiveAppearance
479
+ {
480
+ [super viewDidChangeEffectiveAppearance];
481
+ self.needsDisplay = YES;
482
+ }
483
+
484
+ - (NSView *)hitTest:(NSPoint)point
485
+ {
486
+ return nil;
487
+ }
488
+ @end
489
+
442
490
  static void LegendApplyTitlebarBackgroundColor(NSView *view, NSColor *backgroundColor)
443
491
  {
444
492
  BOOL isTitlebarContainer = LegendViewIsTitlebarContainer(view);
@@ -488,12 +536,6 @@ static char LegendContentLayoutModeKey;
488
536
  static char LegendTitlebarControlMetadataKey;
489
537
  static char LegendToolbarControlMetadataKey;
490
538
  static char LegendToolbarWindowIdentifierKey;
491
- static char LegendToolbarSearchFieldKey;
492
- static char LegendToolbarSearchItemKey;
493
- static char LegendToolbarSearchWidthKey;
494
- static char LegendToolbarSearchButtonKey;
495
- static char LegendToolbarSearchContainerKey;
496
- static char LegendToolbarSearchWidthConstraintKey;
497
539
  static const CGFloat LegendToolbarSearchCollapsedSize = 34;
498
540
  static const CGFloat LegendToolbarIconControlWidth = 36;
499
541
 
@@ -584,6 +626,32 @@ static BOOL LegendDictionaryHasKey(NSDictionary *dictionary, NSString *key)
584
626
  return [dictionary isKindOfClass:NSDictionary.class] && dictionary[key] != nil;
585
627
  }
586
628
 
629
+ // A number from 0 to 1 is determinate progress; anything else (null or absent) animates as indeterminate.
630
+ // Shows `value` in a toolbar popup and remembers it, so an action item can put it back.
631
+ static void LegendSelectPopupValue(NSPopUpButton *popup, id value)
632
+ {
633
+ NSInteger index = -1;
634
+ for (NSMenuItem *item in popup.itemArray) {
635
+ if ([item.representedObject isKindOfClass:NSDictionary.class] && [item.representedObject[@"value"] isEqual:value]) { index = [popup indexOfItem:item]; break; }
636
+ }
637
+ [popup selectItemAtIndex:index];
638
+ NSMutableDictionary *metadata = [objc_getAssociatedObject(popup, &LegendToolbarControlMetadataKey) mutableCopy] ?: [NSMutableDictionary new];
639
+ metadata[@"value"] = index >= 0 ? value : @"";
640
+ objc_setAssociatedObject(popup, &LegendToolbarControlMetadataKey, metadata, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
641
+ }
642
+
643
+ static void LegendApplyProgressValue(NSProgressIndicator *indicator, id value)
644
+ {
645
+ BOOL determinate = [value isKindOfClass:NSNumber.class];
646
+ indicator.indeterminate = !determinate;
647
+ if (determinate) {
648
+ indicator.doubleValue = [value doubleValue];
649
+ [indicator stopAnimation:nil];
650
+ } else {
651
+ [indicator startAnimation:nil];
652
+ }
653
+ }
654
+
587
655
  static void LegendSizeRootViewToWindow(RCTUIView *rootView, NSWindow *window);
588
656
 
589
657
  static NSURL *LegendURLFromString(NSString *value)
@@ -639,6 +707,13 @@ static void LegendApplyWindowOptions(NSWindow *window, NSDictionary *options)
639
707
  if (hasTitle || hasRepresentedURL) {
640
708
  LegendApplyWindowTitleAndRepresentedURL(window, title, hasRepresentedURL, representedURLValue, nil);
641
709
  }
710
+ if ([options[@"subtitle"] isKindOfClass:NSString.class]) window.subtitle = options[@"subtitle"];
711
+ NSString *tabbingMode = [options[@"tabbingMode"] isKindOfClass:NSString.class] ? options[@"tabbingMode"] : nil;
712
+ if (tabbingMode) {
713
+ window.tabbingMode = [tabbingMode isEqualToString:@"preferred"] ? NSWindowTabbingModePreferred
714
+ : [tabbingMode isEqualToString:@"disallowed"] ? NSWindowTabbingModeDisallowed : NSWindowTabbingModeAutomatic;
715
+ }
716
+ if ([options[@"tabbingIdentifier"] isKindOfClass:NSString.class]) window.tabbingIdentifier = options[@"tabbingIdentifier"];
642
717
 
643
718
  NSDictionary *windowStyle = [options[@"windowStyle"] isKindOfClass:NSDictionary.class] ? options[@"windowStyle"] : @{};
644
719
  if (windowStyle[@"startupSplitView"] == NSNull.null && LegendFinishSidebarSplitViewStartup) {
@@ -907,8 +982,7 @@ RCT_EXPORT_MODULE(NativeWindowManager)
907
982
  - (void)bindChromeControlView:(NSView *)view
908
983
  {
909
984
  BOOL managed = objc_getAssociatedObject(view, &LegendToolbarControlMetadataKey) != nil ||
910
- objc_getAssociatedObject(view, &LegendTitlebarControlMetadataKey) != nil ||
911
- objc_getAssociatedObject(view, &LegendToolbarSearchItemKey) != nil;
985
+ objc_getAssociatedObject(view, &LegendTitlebarControlMetadataKey) != nil;
912
986
  if (managed && [view isKindOfClass:NSControl.class]) {
913
987
  ((NSControl *)view).target = self;
914
988
  if ([view isKindOfClass:NSSearchField.class]) ((NSSearchField *)view).delegate = self;
@@ -1054,6 +1128,17 @@ RCT_EXPORT_MODULE(NativeWindowManager)
1054
1128
  effectView.state = LegendVisualEffectStateForName(state);
1055
1129
  }
1056
1130
 
1131
+ NSDictionary *tintColor = [windowStyle[@"titlebarMaterialTintColor"] isKindOfClass:NSDictionary.class]
1132
+ ? windowStyle[@"titlebarMaterialTintColor"]
1133
+ : nil;
1134
+ if (tintColor) {
1135
+ LegendTitlebarTintView *tintView = [[LegendTitlebarTintView alloc] initWithFrame:materialView.bounds];
1136
+ tintView.lightColor = LegendColorFromHexString(tintColor[@"light"]);
1137
+ tintView.darkColor = LegendColorFromHexString(tintColor[@"dark"]);
1138
+ tintView.autoresizingMask = NSViewWidthSizable | NSViewHeightSizable;
1139
+ [materialView addSubview:tintView];
1140
+ }
1141
+
1057
1142
  materialView.translatesAutoresizingMaskIntoConstraints = YES;
1058
1143
  materialView.autoresizingMask = NSViewWidthSizable | NSViewMinYMargin;
1059
1144
  [frameView addSubview:materialView positioned:NSWindowAbove relativeTo:window.contentView];
@@ -1238,35 +1323,49 @@ RCT_EXPORT_MODULE(NativeWindowManager)
1238
1323
  }
1239
1324
  }
1240
1325
  NSArray<NSDictionary *> *previousConfigs = self.toolbarItemConfigs[toolbar.identifier];
1241
- BOOL menuUpdate = previousConfigs != nil && previousConfigs.count == configs.count;
1242
- for (NSUInteger index = 0; menuUpdate && index < configs.count; index++) {
1326
+ // Menu items of menu buttons and values of progress items change in place, keeping the item (and an open menu or a
1327
+ // running animation); any other change replaces the changed items below.
1328
+ BOOL inPlaceUpdate = previousConfigs != nil && previousConfigs.count == configs.count;
1329
+ for (NSUInteger index = 0; inPlaceUpdate && index < configs.count; index++) {
1243
1330
  NSMutableDictionary *previous = [previousConfigs[index] mutableCopy];
1244
1331
  NSMutableDictionary *next = [configs[index] mutableCopy];
1245
- if ([next[@"type"] isEqual:@"menuButton"]) {
1246
- [previous removeObjectForKey:@"menuItems"];
1247
- [next removeObjectForKey:@"menuItems"];
1332
+ NSString *inPlaceKey = [next[@"type"] isEqual:@"menuButton"] ? @"menuItems" : [next[@"type"] isEqual:@"progress"] ? @"value" : [next[@"type"] isEqual:@"popup"] ? @"selectedValue" : nil;
1333
+ if (inPlaceKey) {
1334
+ [previous removeObjectForKey:inPlaceKey];
1335
+ [next removeObjectForKey:inPlaceKey];
1248
1336
  }
1249
- menuUpdate = [previous isEqualToDictionary:next];
1337
+ inPlaceUpdate = [previous isEqualToDictionary:next];
1250
1338
  }
1251
1339
  self.toolbarItemConfigs[toolbar.identifier] = configs;
1252
- if (menuUpdate) {
1340
+ if (inPlaceUpdate) {
1253
1341
  for (NSDictionary *config in configs) {
1254
- if (![config[@"type"] isEqual:@"menuButton"]) continue;
1342
+ BOOL menu = [config[@"type"] isEqual:@"menuButton"], progress = [config[@"type"] isEqual:@"progress"], popup = [config[@"type"] isEqual:@"popup"];
1343
+ if (!menu && !progress && !popup) continue;
1255
1344
  NSString *itemId = config[@"id"];
1256
- if (![itemId isKindOfClass:NSString.class] || itemId.length == 0) { menuUpdate = NO; break; }
1345
+ if (![itemId isKindOfClass:NSString.class] || itemId.length == 0) { inPlaceUpdate = NO; break; }
1257
1346
  NSString *itemIdentifier = [@"legend.toolbar." stringByAppendingString:itemId];
1258
1347
  NSToolbarItem *item = nil;
1259
1348
  for (NSToolbarItem *candidate in toolbar.items) {
1260
1349
  if ([candidate.itemIdentifier isEqual:itemIdentifier]) { item = candidate; break; }
1261
1350
  }
1351
+ if (progress) {
1352
+ if (![item.view isKindOfClass:NSProgressIndicator.class]) { inPlaceUpdate = NO; break; }
1353
+ LegendApplyProgressValue((NSProgressIndicator *)item.view, config[@"value"]);
1354
+ continue;
1355
+ }
1356
+ if (popup) {
1357
+ if (![item.view isKindOfClass:NSPopUpButton.class]) { inPlaceUpdate = NO; break; }
1358
+ LegendSelectPopupValue((NSPopUpButton *)item.view, config[@"selectedValue"]);
1359
+ continue;
1360
+ }
1262
1361
  id control = item.view ?: item;
1263
1362
  NSDictionary *metadata = control ? objc_getAssociatedObject(control, &LegendToolbarControlMetadataKey) : nil;
1264
- if (!metadata) { menuUpdate = NO; break; }
1363
+ if (!metadata) { inPlaceUpdate = NO; break; }
1265
1364
  NSMutableDictionary *nextMetadata = [metadata mutableCopy];
1266
1365
  nextMetadata[@"menuItems"] = config[@"menuItems"] ?: @[];
1267
1366
  objc_setAssociatedObject(control, &LegendToolbarControlMetadataKey, nextMetadata, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
1268
1367
  }
1269
- if (menuUpdate) return;
1368
+ if (inPlaceUpdate) return;
1270
1369
  }
1271
1370
  // Moving an item takes its control out of the window, which ends editing in a focused text field (ignored while
1272
1371
  // movingToolbarItem is set), so focus and selection are restored afterwards.
@@ -1333,123 +1432,6 @@ RCT_EXPORT_MODULE(NativeWindowManager)
1333
1432
  return @[];
1334
1433
  }
1335
1434
 
1336
- - (NSImage *)toolbarSearchImageWithLabel:(NSString *)label
1337
- {
1338
- if (@available(macOS 11.0, *)) {
1339
- return [NSImage imageWithSystemSymbolName:@"magnifyingglass" accessibilityDescription:label ?: @"Search"];
1340
- }
1341
- return [NSImage imageNamed:NSImageNameTouchBarSearchTemplate];
1342
- }
1343
-
1344
- - (void)focusToolbarSearchField:(NSSearchField *)searchField
1345
- {
1346
- id metadata = objc_getAssociatedObject(searchField, &LegendToolbarControlMetadataKey);
1347
- NSDictionary *representedObject = [metadata isKindOfClass:NSDictionary.class]
1348
- ? metadata
1349
- : @{};
1350
- NSString *identifier = [representedObject[@"windowIdentifier"] isKindOfClass:NSString.class]
1351
- ? representedObject[@"windowIdentifier"]
1352
- : @"";
1353
- NSWindow *window = [self windowForIdentifier:identifier];
1354
- [window makeKeyAndOrderFront:nil];
1355
- [window makeFirstResponder:searchField];
1356
- }
1357
-
1358
- - (void)setToolbarSearchItem:(NSToolbarItem *)toolbarItem
1359
- expanded:(BOOL)expanded
1360
- value:(NSString *)value
1361
- focus:(BOOL)focus
1362
- sendChange:(BOOL)sendChange
1363
- animated:(BOOL)animated
1364
- {
1365
- if (!toolbarItem) {
1366
- return;
1367
- }
1368
-
1369
- id associatedField = objc_getAssociatedObject(toolbarItem, &LegendToolbarSearchFieldKey);
1370
- id associatedButton = objc_getAssociatedObject(toolbarItem, &LegendToolbarSearchButtonKey);
1371
- id associatedContainer = objc_getAssociatedObject(toolbarItem, &LegendToolbarSearchContainerKey);
1372
- id associatedWidthConstraint = objc_getAssociatedObject(toolbarItem, &LegendToolbarSearchWidthConstraintKey);
1373
- if (![associatedField isKindOfClass:NSSearchField.class]) {
1374
- return;
1375
- }
1376
-
1377
- NSSearchField *searchField = (NSSearchField *)associatedField;
1378
- NSButton *button = [associatedButton isKindOfClass:NSButton.class] ? (NSButton *)associatedButton : nil;
1379
- NSView *container = [associatedContainer isKindOfClass:NSView.class] ? (NSView *)associatedContainer : toolbarItem.view;
1380
- NSLayoutConstraint *widthConstraint = [associatedWidthConstraint isKindOfClass:NSLayoutConstraint.class]
1381
- ? (NSLayoutConstraint *)associatedWidthConstraint
1382
- : nil;
1383
- NSNumber *widthNumber = objc_getAssociatedObject(toolbarItem, &LegendToolbarSearchWidthKey);
1384
- CGFloat width = [widthNumber isKindOfClass:NSNumber.class] ? widthNumber.doubleValue : 240;
1385
- CGFloat targetWidth = expanded ? width : LegendToolbarSearchCollapsedSize;
1386
-
1387
- if (value) {
1388
- searchField.stringValue = value;
1389
- }
1390
- if (expanded) {
1391
- searchField.hidden = NO;
1392
- button.hidden = NO;
1393
- }
1394
- if (focus) {
1395
- [self focusToolbarSearchField:searchField];
1396
- }
1397
- if (container) {
1398
- NSRect frame = container.frame;
1399
- frame.size.width = targetWidth;
1400
- if (animated) {
1401
- [NSAnimationContext runAnimationGroup:^(NSAnimationContext *context) {
1402
- context.duration = 0.18;
1403
- context.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
1404
- widthConstraint.animator.constant = targetWidth;
1405
- container.animator.frame = frame;
1406
- searchField.animator.alphaValue = expanded ? 1 : 0;
1407
- button.animator.alphaValue = expanded ? 0 : 1;
1408
- [container.superview.animator layoutSubtreeIfNeeded];
1409
- [container.animator layoutSubtreeIfNeeded];
1410
- } completionHandler:^{
1411
- button.hidden = expanded;
1412
- searchField.hidden = !expanded;
1413
- }];
1414
- } else {
1415
- widthConstraint.constant = targetWidth;
1416
- container.frame = frame;
1417
- searchField.alphaValue = expanded ? 1 : 0;
1418
- button.alphaValue = expanded ? 0 : 1;
1419
- button.hidden = expanded;
1420
- searchField.hidden = !expanded;
1421
- [container layoutSubtreeIfNeeded];
1422
- }
1423
- }
1424
- if (sendChange) {
1425
- [self sendToolbarSearchEventForField:searchField submitted:NO shiftKey:NO];
1426
- }
1427
- }
1428
-
1429
- - (void)collapseToolbarSearchItem:(NSToolbarItem *)toolbarItem animated:(BOOL)animated
1430
- {
1431
- [self setToolbarSearchItem:toolbarItem
1432
- expanded:NO
1433
- value:nil
1434
- focus:NO
1435
- sendChange:NO
1436
- animated:animated];
1437
- }
1438
-
1439
- - (void)expandToolbarSearchItem:(NSToolbarItem *)toolbarItem
1440
- value:(NSString *)value
1441
- focus:(BOOL)focus
1442
- sendChange:(BOOL)sendChange
1443
- animated:(BOOL)animated
1444
- {
1445
- [self setToolbarSearchItem:toolbarItem
1446
- expanded:YES
1447
- value:value
1448
- focus:focus
1449
- sendChange:sendChange
1450
- animated:animated];
1451
- }
1452
-
1453
1435
  - (NSToolbarItem *)toolbar:(NSToolbar *)toolbar
1454
1436
  itemForItemIdentifier:(NSToolbarItemIdentifier)itemIdentifier
1455
1437
  willBeInsertedIntoToolbar:(BOOL)flag
@@ -1496,6 +1478,7 @@ willBeInsertedIntoToolbar:(BOOL)flag
1496
1478
  @"value": [config[@"value"] isKindOfClass:NSString.class] ? config[@"value"] : @"",
1497
1479
  @"windowIdentifier": LegendToolbarWindowIdentifier(toolbar),
1498
1480
  @"instanceId": config[@"instanceId"] ?: @"",
1481
+ @"enabled": @(toolbarItem.enabled),
1499
1482
  };
1500
1483
  if (isMenuButton) {
1501
1484
  // The fallback name identifies the item; it is never what the control displays, so an
@@ -1552,6 +1535,30 @@ willBeInsertedIntoToolbar:(BOOL)flag
1552
1535
  return toolbarItem;
1553
1536
  }
1554
1537
 
1538
+ if ([type isEqualToString:@"progress"]) {
1539
+ NSString *itemId = [config[@"id"] isKindOfClass:NSString.class] ? config[@"id"] : @"";
1540
+ NSString *label = [config[@"label"] isKindOfClass:NSString.class] ? config[@"label"] : itemId;
1541
+ BOOL spinner = [config[@"variant"] isEqual:@"spinner"];
1542
+ NSNumber *widthNumber = [config[@"width"] isKindOfClass:NSNumber.class] ? config[@"width"] : nil;
1543
+ NSProgressIndicator *indicator = [NSProgressIndicator new];
1544
+ indicator.style = spinner ? NSProgressIndicatorStyleSpinning : NSProgressIndicatorStyleBar;
1545
+ indicator.controlSize = spinner ? NSControlSizeSmall : NSControlSizeRegular;
1546
+ indicator.displayedWhenStopped = YES;
1547
+ indicator.minValue = 0;
1548
+ indicator.maxValue = 1;
1549
+ indicator.translatesAutoresizingMaskIntoConstraints = NO;
1550
+ [indicator.widthAnchor constraintEqualToConstant:widthNumber ? widthNumber.doubleValue : spinner ? 16 : 120].active = YES;
1551
+ indicator.accessibilityLabel = label;
1552
+ LegendApplyProgressValue(indicator, config[@"value"]);
1553
+
1554
+ NSToolbarItem *toolbarItem = [[NSToolbarItem alloc] initWithItemIdentifier:itemIdentifier];
1555
+ toolbarItem.view = indicator;
1556
+ toolbarItem.label = label;
1557
+ toolbarItem.paletteLabel = label;
1558
+ toolbarItem.toolTip = label;
1559
+ return toolbarItem;
1560
+ }
1561
+
1555
1562
  if ([type isEqualToString:@"search"]) {
1556
1563
  NSString *itemId = [config[@"id"] isKindOfClass:NSString.class] ? config[@"id"] : @"";
1557
1564
  NSString *label = [config[@"label"] isKindOfClass:NSString.class] ? config[@"label"] : itemId;
@@ -1566,64 +1573,13 @@ willBeInsertedIntoToolbar:(BOOL)flag
1566
1573
  @"instanceId": config[@"instanceId"] ?: @"",
1567
1574
  };
1568
1575
 
1569
- NSSearchField *searchField = nil;
1570
- NSToolbarItem *toolbarItem = nil;
1576
+ NSSearchToolbarItem *toolbarItem = [[NSSearchToolbarItem alloc] initWithItemIdentifier:itemIdentifier];
1577
+ NSSearchField *searchField = toolbarItem.searchField;
1571
1578
  if (collapses) {
1572
- CGFloat initialWidth = value.length > 0 ? width : LegendToolbarSearchCollapsedSize;
1573
- NSView *container = [[NSView alloc] initWithFrame:NSMakeRect(0, 0, initialWidth, LegendToolbarSearchCollapsedSize)];
1574
- container.translatesAutoresizingMaskIntoConstraints = NO;
1575
- NSLayoutConstraint *containerWidthConstraint = [container.widthAnchor constraintEqualToConstant:initialWidth];
1576
- containerWidthConstraint.active = YES;
1577
- [container.heightAnchor constraintEqualToConstant:LegendToolbarSearchCollapsedSize].active = YES;
1578
-
1579
- NSButton *searchButton = [NSButton buttonWithImage:[self toolbarSearchImageWithLabel:label]
1580
- target:self
1581
- action:@selector(toolbarSearchButtonPressed:)];
1582
- searchButton.translatesAutoresizingMaskIntoConstraints = NO;
1583
- searchButton.bordered = YES;
1584
- searchButton.bezelStyle = NSBezelStyleCircular;
1585
- searchButton.controlSize = NSControlSizeRegular;
1586
- searchButton.imagePosition = NSImageOnly;
1587
- searchButton.toolTip = placeholder;
1588
- searchButton.enabled = LegendDictionaryHasKey(config, @"enabled") ? [config[@"enabled"] boolValue] : YES;
1589
- [container addSubview:searchButton];
1590
- [NSLayoutConstraint activateConstraints:@[
1591
- [searchButton.centerXAnchor constraintEqualToAnchor:container.centerXAnchor],
1592
- [searchButton.centerYAnchor constraintEqualToAnchor:container.centerYAnchor],
1593
- [searchButton.widthAnchor constraintEqualToConstant:LegendToolbarSearchCollapsedSize],
1594
- [searchButton.heightAnchor constraintEqualToConstant:LegendToolbarSearchCollapsedSize],
1595
- ]];
1596
-
1597
- searchField = [[NSSearchField alloc] initWithFrame:NSMakeRect(0, 0, width, 28)];
1598
- searchField.translatesAutoresizingMaskIntoConstraints = NO;
1599
- searchField.hidden = value.length == 0;
1600
- searchField.alphaValue = value.length > 0 ? 1 : 0;
1601
- searchButton.hidden = value.length > 0;
1602
- searchButton.alphaValue = value.length > 0 ? 0 : 1;
1603
- [container addSubview:searchField];
1604
- [NSLayoutConstraint activateConstraints:@[
1605
- [searchField.leadingAnchor constraintEqualToAnchor:container.leadingAnchor],
1606
- [searchField.trailingAnchor constraintEqualToAnchor:container.trailingAnchor],
1607
- [searchField.topAnchor constraintEqualToAnchor:container.topAnchor],
1608
- [searchField.bottomAnchor constraintEqualToAnchor:container.bottomAnchor],
1609
- ]];
1610
- toolbarItem = [[NSToolbarItem alloc] initWithItemIdentifier:itemIdentifier];
1611
- toolbarItem.view = container;
1612
- objc_setAssociatedObject(toolbarItem, &LegendToolbarSearchFieldKey, searchField, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
1613
- objc_setAssociatedObject(toolbarItem, &LegendToolbarSearchWidthKey, @(width), OBJC_ASSOCIATION_RETAIN_NONATOMIC);
1614
- objc_setAssociatedObject(toolbarItem, &LegendToolbarSearchButtonKey, searchButton, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
1615
- objc_setAssociatedObject(toolbarItem, &LegendToolbarSearchContainerKey, container, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
1616
- objc_setAssociatedObject(toolbarItem, &LegendToolbarSearchWidthConstraintKey, containerWidthConstraint, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
1617
- objc_setAssociatedObject(searchButton, &LegendToolbarSearchItemKey, toolbarItem, OBJC_ASSOCIATION_ASSIGN);
1618
- objc_setAssociatedObject(searchField, &LegendToolbarSearchItemKey, toolbarItem, OBJC_ASSOCIATION_ASSIGN);
1619
- } else if (@available(macOS 11.0, *)) {
1620
- NSSearchToolbarItem *searchToolbarItem = [[NSSearchToolbarItem alloc] initWithItemIdentifier:itemIdentifier];
1621
- searchField = searchToolbarItem.searchField;
1622
- toolbarItem = searchToolbarItem;
1623
- } else {
1624
- searchField = [[NSSearchField alloc] initWithFrame:NSMakeRect(0, 0, width, 28)];
1625
- toolbarItem = [[NSToolbarItem alloc] initWithItemIdentifier:itemIdentifier];
1626
- toolbarItem.view = searchField;
1579
+ toolbarItem.preferredWidthForSearchField = width;
1580
+ NSLayoutConstraint *collapsedWidth = [searchField.widthAnchor constraintEqualToConstant:LegendToolbarSearchCollapsedSize];
1581
+ collapsedWidth.priority = NSLayoutPriorityDefaultLow;
1582
+ collapsedWidth.active = YES;
1627
1583
  }
1628
1584
 
1629
1585
  searchField.placeholderString = placeholder;
@@ -1639,15 +1595,63 @@ willBeInsertedIntoToolbar:(BOOL)flag
1639
1595
  toolbarItem.paletteLabel = label;
1640
1596
  toolbarItem.toolTip = placeholder;
1641
1597
  toolbarItem.enabled = searchField.enabled;
1642
- if (collapses) {
1643
- searchField.enabled = toolbarItem.enabled;
1644
- } else {
1598
+ if (!collapses) {
1645
1599
  toolbarItem.minSize = NSMakeSize(MIN(width, 120), 28);
1646
1600
  toolbarItem.maxSize = NSMakeSize(width, 28);
1647
1601
  }
1648
1602
  return toolbarItem;
1649
1603
  }
1650
1604
 
1605
+ if ([type isEqualToString:@"popup"]) {
1606
+ NSString *itemId = [config[@"id"] isKindOfClass:NSString.class] ? config[@"id"] : @"";
1607
+ NSString *label = [config[@"label"] isKindOfClass:NSString.class] ? config[@"label"] : itemId;
1608
+ NSPopUpButton *popup = [[NSPopUpButton alloc] initWithFrame:NSZeroRect pullsDown:NO];
1609
+ popup.target = self;
1610
+ popup.action = @selector(toolbarPopupChanged:);
1611
+ popup.controlSize = NSControlSizeRegular;
1612
+ popup.enabled = LegendDictionaryHasKey(config, @"enabled") ? [config[@"enabled"] boolValue] : YES;
1613
+ popup.toolTip = [config[@"tooltip"] isKindOfClass:NSString.class] ? config[@"tooltip"] : label;
1614
+ popup.accessibilityLabel = label;
1615
+ popup.menu.autoenablesItems = NO;
1616
+ for (NSDictionary *option in [config[@"options"] isKindOfClass:NSArray.class] ? config[@"options"] : @[]) {
1617
+ if (![option isKindOfClass:NSDictionary.class] || ![option[@"value"] isKindOfClass:NSString.class]) continue;
1618
+ NSMenuItem *item = [[NSMenuItem alloc] initWithTitle:[option[@"label"] isKindOfClass:NSString.class] ? option[@"label"] : option[@"value"] action:nil keyEquivalent:@""];
1619
+ NSString *symbol = [option[@"systemImageName"] isKindOfClass:NSString.class] ? option[@"systemImageName"] : nil;
1620
+ if (symbol.length > 0) item.image = [NSImage imageWithSystemSymbolName:symbol accessibilityDescription:item.title];
1621
+ item.representedObject = @{ @"value": option[@"value"] };
1622
+ [popup.menu addItem:item];
1623
+ }
1624
+ NSArray *menuItems = [config[@"menuItems"] isKindOfClass:NSArray.class] ? config[@"menuItems"] : @[];
1625
+ if (menuItems.count > 0) [popup.menu addItem:NSMenuItem.separatorItem];
1626
+ for (NSDictionary *entry in menuItems) {
1627
+ if (![entry isKindOfClass:NSDictionary.class]) continue;
1628
+ if ([entry[@"separator"] boolValue]) { [popup.menu addItem:NSMenuItem.separatorItem]; continue; }
1629
+ if (![entry[@"id"] isKindOfClass:NSString.class] || ![entry[@"title"] isKindOfClass:NSString.class]) continue;
1630
+ NSMenuItem *item = [[NSMenuItem alloc] initWithTitle:entry[@"title"] action:nil keyEquivalent:@""];
1631
+ item.enabled = LegendDictionaryHasKey(entry, @"enabled") ? [entry[@"enabled"] boolValue] : YES;
1632
+ NSString *symbol = [entry[@"systemImageName"] isKindOfClass:NSString.class] ? entry[@"systemImageName"] : nil;
1633
+ if (symbol.length > 0) item.image = [NSImage imageWithSystemSymbolName:symbol accessibilityDescription:item.title];
1634
+ item.representedObject = @{ @"action": entry[@"id"] };
1635
+ [popup.menu addItem:item];
1636
+ }
1637
+ objc_setAssociatedObject(popup, &LegendToolbarControlMetadataKey, @{
1638
+ @"itemId": itemId, @"windowIdentifier": LegendToolbarWindowIdentifier(toolbar), @"instanceId": config[@"instanceId"] ?: @"",
1639
+ }, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
1640
+ LegendSelectPopupValue(popup, config[@"selectedValue"]);
1641
+ [popup sizeToFit];
1642
+ NSNumber *widthNumber = [config[@"width"] isKindOfClass:NSNumber.class] ? config[@"width"] : nil;
1643
+ if (widthNumber) popup.frame = NSMakeRect(0, 0, widthNumber.doubleValue, NSHeight(popup.frame));
1644
+
1645
+ NSToolbarItem *toolbarItem = [[NSToolbarItem alloc] initWithItemIdentifier:itemIdentifier];
1646
+ toolbarItem.view = popup;
1647
+ toolbarItem.label = label;
1648
+ toolbarItem.paletteLabel = label;
1649
+ toolbarItem.toolTip = popup.toolTip;
1650
+ toolbarItem.enabled = popup.enabled;
1651
+ if (@available(macOS 11.0, *)) toolbarItem.navigational = [config[@"placement"] isEqual:@"leading"];
1652
+ return toolbarItem;
1653
+ }
1654
+
1651
1655
  if (![type isEqualToString:@"segmented"]) {
1652
1656
  return nil;
1653
1657
  }
@@ -1726,9 +1730,31 @@ willBeInsertedIntoToolbar:(BOOL)flag
1726
1730
  toolbarItem.view = control;
1727
1731
  toolbarItem.label = [config[@"label"] isKindOfClass:NSString.class] ? config[@"label"] : itemId;
1728
1732
  toolbarItem.paletteLabel = toolbarItem.label;
1733
+ if (@available(macOS 11.0, *)) {
1734
+ toolbarItem.navigational = [config[@"placement"] isEqual:@"leading"];
1735
+ }
1729
1736
  return toolbarItem;
1730
1737
  }
1731
1738
 
1739
+ - (void)toolbarPopupChanged:(NSPopUpButton *)sender
1740
+ {
1741
+ NSDictionary *metadata = objc_getAssociatedObject(sender, &LegendToolbarControlMetadataKey) ?: @{};
1742
+ NSDictionary *chosen = [sender.selectedItem.representedObject isKindOfClass:NSDictionary.class] ? sender.selectedItem.representedObject : @{};
1743
+ NSMutableDictionary *body = [@{ @"identifier": metadata[@"windowIdentifier"] ?: @"", @"itemId": metadata[@"itemId"] ?: @"", @"instanceId": metadata[@"instanceId"] ?: @"" } mutableCopy];
1744
+ if (chosen[@"action"]) {
1745
+ // An action leaves the popup showing the value it showed before.
1746
+ LegendSelectPopupValue(sender, metadata[@"value"]);
1747
+ body[@"action"] = @{ @"type": @"action", @"itemId": chosen[@"action"] };
1748
+ } else {
1749
+ NSMutableDictionary *nextMetadata = [metadata mutableCopy];
1750
+ nextMetadata[@"value"] = chosen[@"value"] ?: @"";
1751
+ objc_setAssociatedObject(sender, &LegendToolbarControlMetadataKey, nextMetadata, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
1752
+ body[@"value"] = chosen[@"value"] ?: @"";
1753
+ body[@"kind"] = @"selection";
1754
+ }
1755
+ [self sendWindowEventWithName:@"onToolbarItemSelected" body:body];
1756
+ }
1757
+
1732
1758
  - (void)toolbarMenuSliderChanged:(NSSlider *)sender
1733
1759
  {
1734
1760
  NSDictionary *metadata = objc_getAssociatedObject(sender, &LegendToolbarControlMetadataKey);
@@ -1761,19 +1787,11 @@ willBeInsertedIntoToolbar:(BOOL)flag
1761
1787
  body:@{@"identifier": identifier, @"itemId": itemId, @"action": @{ @"type": @"action", @"itemId": value }, @"instanceId": representedObject[@"instanceId"] ?: @""}];
1762
1788
  }
1763
1789
 
1764
- - (void)toolbarSearchButtonPressed:(id)sender
1790
+ // AppKit validation enables any item whose target answers its action, so the item's `enabled` option is the answer.
1791
+ - (BOOL)validateToolbarItem:(NSToolbarItem *)item
1765
1792
  {
1766
- NSToolbarItem *toolbarItem = [sender isKindOfClass:NSToolbarItem.class]
1767
- ? (NSToolbarItem *)sender
1768
- : nil;
1769
- if (!toolbarItem) {
1770
- id associatedItem = objc_getAssociatedObject(sender, &LegendToolbarSearchItemKey);
1771
- if ([associatedItem isKindOfClass:NSToolbarItem.class]) {
1772
- toolbarItem = (NSToolbarItem *)associatedItem;
1773
- }
1774
- }
1775
-
1776
- [self expandToolbarSearchItem:toolbarItem value:nil focus:YES sendChange:YES animated:YES];
1793
+ NSDictionary *metadata = objc_getAssociatedObject(item, &LegendToolbarControlMetadataKey);
1794
+ return ![metadata isKindOfClass:NSDictionary.class] || ![metadata[@"enabled"] isEqual:@NO];
1777
1795
  }
1778
1796
 
1779
1797
  - (void)toolbarButtonItemPressed:(id)sender
@@ -1946,19 +1964,6 @@ willBeInsertedIntoToolbar:(BOOL)flag
1946
1964
  return NO;
1947
1965
  }
1948
1966
 
1949
- - (void)controlTextDidEndEditing:(NSNotification *)notification
1950
- {
1951
- if (!self.movingToolbarItem && [notification.object isKindOfClass:NSSearchField.class]) {
1952
- NSSearchField *searchField = (NSSearchField *)notification.object;
1953
- if (searchField.stringValue.length == 0) {
1954
- id associatedItem = objc_getAssociatedObject(searchField, &LegendToolbarSearchItemKey);
1955
- if ([associatedItem isKindOfClass:NSToolbarItem.class]) {
1956
- [self collapseToolbarSearchItem:(NSToolbarItem *)associatedItem animated:YES];
1957
- }
1958
- }
1959
- }
1960
- }
1961
-
1962
1967
  - (void)toolbarSearchSubmitted:(NSSearchField *)sender
1963
1968
  {
1964
1969
  if (self.movingToolbarItem) return;
@@ -2138,6 +2143,8 @@ willBeInsertedIntoToolbar:(BOOL)flag
2138
2143
  #if TARGET_OS_OSX
2139
2144
  RCTExecuteOnMainQueue(^{
2140
2145
  NSDictionary *options = [self parseObjectJSON:optionsJson];
2146
+ NSString *symbolError = LegendInvalidWindowSymbol(options[@"windowStyle"]);
2147
+ if (symbolError) { reject(@"E_INVALID_ARGUMENT", symbolError, nil); return; }
2141
2148
  NSString *identifier = [options[@"identifier"] isKindOfClass:NSString.class] ? options[@"identifier"] : nil;
2142
2149
  NSString *moduleName = [options[@"moduleName"] isKindOfClass:NSString.class] ? options[@"moduleName"] : nil;
2143
2150
  NSAppearance *darkAppearance = LegendDarkAppearance();
@@ -2570,32 +2577,16 @@ willBeInsertedIntoToolbar:(BOOL)flag
2570
2577
  return;
2571
2578
  }
2572
2579
 
2573
- NSSearchField *searchField = nil;
2574
- if (@available(macOS 11.0, *)) {
2575
- if ([toolbarItem isKindOfClass:NSSearchToolbarItem.class]) {
2576
- searchField = ((NSSearchToolbarItem *)toolbarItem).searchField;
2577
- }
2578
- }
2579
- if (!searchField && [toolbarItem.view isKindOfClass:NSSearchField.class]) {
2580
- searchField = (NSSearchField *)toolbarItem.view;
2581
- }
2582
- if (!searchField) {
2583
- id associatedField = objc_getAssociatedObject(toolbarItem, &LegendToolbarSearchFieldKey);
2584
- if ([associatedField isKindOfClass:NSSearchField.class]) {
2585
- [self expandToolbarSearchItem:toolbarItem value:value focus:YES sendChange:YES animated:YES];
2586
- resolve([self successJson]);
2587
- return;
2588
- }
2589
- }
2590
- if (!searchField) {
2580
+ if (![toolbarItem isKindOfClass:NSSearchToolbarItem.class]) {
2591
2581
  reject(@"E_NOT_FOUND", @"Toolbar search field not found", nil);
2592
2582
  return;
2593
2583
  }
2594
2584
 
2585
+ NSSearchField *searchField = ((NSSearchToolbarItem *)toolbarItem).searchField;
2595
2586
  if (value) searchField.stringValue = value;
2596
2587
  [self sendToolbarSearchEventForField:searchField submitted:NO shiftKey:NO];
2597
2588
  [window makeKeyAndOrderFront:nil];
2598
- [window makeFirstResponder:searchField];
2589
+ [(NSSearchToolbarItem *)toolbarItem beginSearchInteraction];
2599
2590
  resolve([self successJson]);
2600
2591
  });
2601
2592
  #else
@@ -2714,6 +2705,8 @@ willBeInsertedIntoToolbar:(BOOL)flag
2714
2705
  }
2715
2706
 
2716
2707
  NSDictionary *options = [self parseObjectJSON:optionsJson];
2708
+ NSString *symbolError = LegendInvalidWindowSymbol(options[@"windowStyle"]);
2709
+ if (symbolError) { reject(@"E_INVALID_ARGUMENT", symbolError, nil); return; }
2717
2710
  // Safe and driver modes save no window chrome.
2718
2711
  id startupSplitView = (LegendSafeMode() || LegendTestDriverActive()) ? nil : options[@"windowStyle"][@"startupSplitView"];
2719
2712
  if ([startupSplitView isKindOfClass:NSDictionary.class]) {
@@ -2744,6 +2737,8 @@ willBeInsertedIntoToolbar:(BOOL)flag
2744
2737
  RCTExecuteOnMainQueue(^{
2745
2738
  NSString *targetIdentifier = [self normalizeIdentifier:identifier];
2746
2739
  NSDictionary *options = [self parseObjectJSON:optionsJson];
2740
+ NSString *symbolError = LegendInvalidWindowSymbol(options[@"windowStyle"]);
2741
+ if (symbolError) { reject(@"E_INVALID_ARGUMENT", symbolError, nil); return; }
2747
2742
  NSWindow *window = [self windowForIdentifier:targetIdentifier];
2748
2743
  if (!window) {
2749
2744
  reject(@"E_NOT_FOUND", @"Window not found", nil);