@legendapp/spark 0.0.3 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (186) hide show
  1. package/init-template.cjs +7 -1
  2. package/package.json +10 -5
  3. package/patches/dependencies.json +4 -4
  4. package/patches/react-native-mmkv@4.3.2.patch +2 -2
  5. package/patches/react-native-nitro-zxing@0.3.1.patch +22 -0
  6. package/patches/registry.json +615 -0
  7. package/patches/workspace/expo-audio@55.0.18.patch +159 -0
  8. package/patches/workspace/op-engineering-op-sqlite@18.2.1.patch +796 -0
  9. package/patches/workspace/react-native-nitro-modules@0.37.0.patch +1348 -0
  10. package/patches/workspace/react-native-runtimes-core@0.1.0-alpha.2.patch +276 -0
  11. package/patches/workspace/react-native-webview@16.0.0.patch +208 -0
  12. package/postinstall.cjs +10 -1
  13. package/skills/spark/SKILL.md +37 -4
  14. package/skills/spark/UPGRADING.md +116 -1
  15. package/skills/spark/ai-customize.md +39 -0
  16. package/skills/spark/app-and-documents.md +56 -0
  17. package/skills/spark/external-libraries.md +87 -0
  18. package/skills/spark/files.md +64 -0
  19. package/skills/spark/integrations.md +69 -0
  20. package/skills/spark/keyboard.md +54 -0
  21. package/skills/spark/library-compat.md +76 -0
  22. package/skills/spark/menus-tray-dock.md +83 -0
  23. package/skills/spark/storage-settings.md +85 -0
  24. package/skills/spark/ui.md +57 -0
  25. package/skills/spark/windows.md +91 -0
  26. package/ui-popover.ts +1 -0
  27. package/ui-progress.ts +1 -0
  28. package/ui-sheet.ts +1 -0
  29. package/ui-split-view.ts +1 -0
  30. package/ui-table.ts +1 -0
  31. package/vendor/node_modules/@legendapp/spark-ai/package.json +3 -3
  32. package/vendor/node_modules/@legendapp/spark-audio/package.json +3 -13
  33. package/vendor/node_modules/@legendapp/spark-auth-session/package.json +3 -10
  34. package/vendor/node_modules/@legendapp/spark-cli/dist/add-desktop.js +5 -0
  35. package/vendor/node_modules/@legendapp/spark-cli/dist/build.js +137 -105
  36. package/vendor/node_modules/@legendapp/spark-cli/dist/cli-arguments.js +4 -1
  37. package/vendor/node_modules/@legendapp/spark-cli/dist/commands.js +16 -7
  38. package/vendor/node_modules/@legendapp/spark-cli/dist/dependency-pins.js +19 -3
  39. package/vendor/node_modules/@legendapp/spark-cli/dist/dev-command.js +2 -0
  40. package/vendor/node_modules/@legendapp/spark-cli/dist/dev.js +3 -0
  41. package/vendor/node_modules/@legendapp/spark-cli/dist/enriched-html-pins.js +2 -0
  42. package/vendor/node_modules/@legendapp/spark-cli/dist/errors.js +1 -1
  43. package/vendor/node_modules/@legendapp/spark-cli/dist/index.js +57 -9
  44. package/vendor/node_modules/@legendapp/spark-cli/dist/init-template.cjs +12 -2
  45. package/vendor/node_modules/@legendapp/spark-cli/dist/init-template.d.cts +1 -1
  46. package/vendor/node_modules/@legendapp/spark-cli/dist/metro.cjs +1 -0
  47. package/vendor/node_modules/@legendapp/spark-cli/dist/migrate.js +65 -0
  48. package/vendor/node_modules/@legendapp/spark-cli/dist/migration-helpers.cjs +4 -4
  49. package/vendor/node_modules/@legendapp/spark-cli/dist/migration-helpers.d.cts +2 -2
  50. package/vendor/node_modules/@legendapp/spark-cli/dist/migrations.cjs +12 -8
  51. package/vendor/node_modules/@legendapp/spark-cli/dist/native-patch-preflight.js +35 -7
  52. package/vendor/node_modules/@legendapp/spark-cli/dist/patch.js +92 -0
  53. package/vendor/node_modules/@legendapp/spark-cli/dist/project-version.js +12 -4
  54. package/vendor/node_modules/@legendapp/spark-cli/dist/project.js +8 -1
  55. package/vendor/node_modules/@legendapp/spark-cli/dist/release.json +20 -20
  56. package/vendor/node_modules/@legendapp/spark-cli/dist/upgrade.js +1 -1
  57. package/vendor/node_modules/@legendapp/spark-cli/dist/windows.js +3 -0
  58. package/vendor/node_modules/@legendapp/spark-cli/package.json +5 -4
  59. package/vendor/node_modules/@legendapp/spark-cli/templates/blank-typescript/package.json +2 -2
  60. package/vendor/node_modules/@legendapp/spark-cli/templates/universal/package.json +2 -2
  61. package/vendor/node_modules/@legendapp/spark-cli/templates/windows/package.json +2 -2
  62. package/vendor/node_modules/@legendapp/spark-clipboard/macos/RNDesktopClipboard.mm +1 -1
  63. package/vendor/node_modules/@legendapp/spark-clipboard/package.json +3 -10
  64. package/vendor/node_modules/@legendapp/spark-clipboard/src/desktop.ts +1 -0
  65. package/vendor/node_modules/@legendapp/spark-codex/package.json +3 -7
  66. package/vendor/node_modules/@legendapp/spark-commands/package.json +5 -5
  67. package/vendor/node_modules/@legendapp/spark-context-menu/package.json +3 -10
  68. package/vendor/node_modules/@legendapp/spark-desktop-app/macos/SparkDesktop.h +3 -1
  69. package/vendor/node_modules/@legendapp/spark-desktop-app/macos/SparkDesktop.mm +51 -10
  70. package/vendor/node_modules/@legendapp/spark-desktop-app/macos/SparkStorage.h +4 -0
  71. package/vendor/node_modules/@legendapp/spark-desktop-app/macos/SparkStorage.mm +82 -0
  72. package/vendor/node_modules/@legendapp/spark-desktop-app/package.json +2 -8
  73. package/vendor/node_modules/@legendapp/spark-desktop-config/config.cjs +6 -8
  74. package/vendor/node_modules/@legendapp/spark-desktop-config/identity.cjs +2 -0
  75. package/vendor/node_modules/@legendapp/spark-desktop-config/native-patches.cjs +300 -71
  76. package/vendor/node_modules/@legendapp/spark-desktop-config/native-patches.d.cts +7 -0
  77. package/vendor/node_modules/@legendapp/spark-desktop-config/package.json +3 -3
  78. package/vendor/node_modules/@legendapp/spark-desktop-config/patch-registry.cjs +318 -0
  79. package/vendor/node_modules/@legendapp/spark-desktop-config/patch-registry.d.cts +20 -0
  80. package/vendor/node_modules/@legendapp/spark-desktop-config/validation.cjs +66 -9
  81. package/vendor/node_modules/@legendapp/spark-desktop-config/windows.plugin.cjs +1 -0
  82. package/vendor/node_modules/@legendapp/spark-desktop-host/AppDelegate.mm +1 -0
  83. package/vendor/node_modules/@legendapp/spark-desktop-host/package.json +2 -2
  84. package/vendor/node_modules/@legendapp/spark-desktop-links/package.json +3 -10
  85. package/vendor/node_modules/@legendapp/spark-desktop-shortcuts/package.json +3 -10
  86. package/vendor/node_modules/@legendapp/spark-desktop-windows/macos/RNDesktopWindows.mm +7 -2
  87. package/vendor/node_modules/@legendapp/spark-desktop-windows/macos/window-manager/RNWindowManager.mm +235 -240
  88. package/vendor/node_modules/@legendapp/spark-desktop-windows/package.json +4 -11
  89. package/vendor/node_modules/@legendapp/spark-desktop-windows/src/api.ts +9 -3
  90. package/vendor/node_modules/@legendapp/spark-desktop-windows/src/macos-adapter.ts +7 -0
  91. package/vendor/node_modules/@legendapp/spark-desktop-windows/src/types.ts +32 -3
  92. package/vendor/node_modules/@legendapp/spark-desktop-windows/src/validation.ts +28 -11
  93. package/vendor/node_modules/@legendapp/spark-desktop-windows/src/windows/createWindowsNavigator.tsx +15 -3
  94. package/vendor/node_modules/@legendapp/spark-desktop-windows/src/windows/primaryWindowLifecycle.ts +12 -3
  95. package/vendor/node_modules/@legendapp/spark-desktop-windows/src/windows/usePrimaryWindowLifecycle.ts +2 -1
  96. package/vendor/node_modules/@legendapp/spark-desktop-windows/src/windows/useWindowFocusEffect.ts +4 -1
  97. package/vendor/node_modules/@legendapp/spark-documents/package.json +7 -7
  98. package/vendor/node_modules/@legendapp/spark-drag-drop/macos/RNDesktopDragView.mm +77 -17
  99. package/vendor/node_modules/@legendapp/spark-drag-drop/package.json +3 -8
  100. package/vendor/node_modules/@legendapp/spark-drag-drop/src/DesktopDragViewNativeComponent.ts +1 -0
  101. package/vendor/node_modules/@legendapp/spark-drag-drop/src/contracts.ts +13 -4
  102. package/vendor/node_modules/@legendapp/spark-drag-drop/src/index.tsx +5 -3
  103. package/vendor/node_modules/@legendapp/spark-drag-drop/windows/SparkDragDrop/SparkDragDrop.h +6 -1
  104. package/vendor/node_modules/@legendapp/spark-expo-compat/metro.cjs +44 -0
  105. package/vendor/node_modules/@legendapp/spark-expo-compat/package.json +20 -0
  106. package/vendor/node_modules/@legendapp/spark-expo-compat/src/clipboard.ts +40 -0
  107. package/vendor/node_modules/@legendapp/spark-expo-compat/src/document-picker.ts +52 -0
  108. package/vendor/node_modules/@legendapp/spark-file-dialog/package.json +3 -10
  109. package/vendor/node_modules/@legendapp/spark-file-dialog/src/options.ts +5 -2
  110. package/vendor/node_modules/@legendapp/spark-file-dialog/src/types.ts +3 -3
  111. package/vendor/node_modules/@legendapp/spark-file-system/macos/RNDesktopFileSystem.mm +1 -1
  112. package/vendor/node_modules/@legendapp/spark-file-system/package.json +3 -11
  113. package/vendor/node_modules/@legendapp/spark-global-shortcuts/package.json +3 -10
  114. package/vendor/node_modules/@legendapp/spark-html/package.json +2 -2
  115. package/vendor/node_modules/@legendapp/spark-markdown/package.json +2 -2
  116. package/vendor/node_modules/@legendapp/spark-message-dialog/package.json +3 -10
  117. package/vendor/node_modules/@legendapp/spark-message-dialog/src/index.ts +1 -0
  118. package/vendor/node_modules/@legendapp/spark-native-menu/package.json +3 -9
  119. package/vendor/node_modules/@legendapp/spark-native-menu/src/hooks.ts +4 -0
  120. package/vendor/node_modules/@legendapp/spark-notifications/package.json +3 -10
  121. package/vendor/node_modules/@legendapp/spark-processes/package.json +3 -10
  122. package/vendor/node_modules/@legendapp/spark-rich-text/package.json +2 -2
  123. package/vendor/node_modules/@legendapp/spark-secure-storage/package.json +3 -10
  124. package/vendor/node_modules/@legendapp/spark-settings/package.json +3 -3
  125. package/vendor/node_modules/@legendapp/spark-settings-ui/package.json +4 -4
  126. package/vendor/node_modules/@legendapp/spark-sqlite/package.json +3 -3
  127. package/vendor/node_modules/@legendapp/spark-system/package.json +3 -10
  128. package/vendor/node_modules/@legendapp/spark-tray/package.json +3 -10
  129. package/vendor/node_modules/@legendapp/spark-tray/src/index.ts +2 -1
  130. package/vendor/node_modules/@legendapp/spark-ui/macos/RNSparkButton.mm +82 -14
  131. package/vendor/node_modules/@legendapp/spark-ui/macos/RNSparkTextInput.h +1 -1
  132. package/vendor/node_modules/@legendapp/spark-ui/macos/RNSparkTextInput.mm +94 -11
  133. package/vendor/node_modules/@legendapp/spark-ui/macos/appkit-split-view/RNSidebarSplitViewComponent.mm +235 -18
  134. package/vendor/node_modules/@legendapp/spark-ui/macos/appkit-split-view/RNSparkPaneSplitView.h +17 -0
  135. package/vendor/node_modules/@legendapp/spark-ui/macos/appkit-split-view/RNSparkPaneSplitView.mm +216 -0
  136. package/vendor/node_modules/@legendapp/spark-ui/macos/appkit-split-view/RNSparkSplitViewComponent.h +4 -0
  137. package/vendor/node_modules/@legendapp/spark-ui/macos/appkit-split-view/RNSparkSplitViewComponent.mm +212 -0
  138. package/vendor/node_modules/@legendapp/spark-ui/macos/appkit-split-view/RNSparkSplitViewUpdates.h +6 -0
  139. package/vendor/node_modules/@legendapp/spark-ui/macos/native-select/RNNativeSegmentedControl.mm +26 -13
  140. package/vendor/node_modules/@legendapp/spark-ui/macos/popover/RNSparkPopover.h +9 -0
  141. package/vendor/node_modules/@legendapp/spark-ui/macos/popover/RNSparkPopover.mm +126 -0
  142. package/vendor/node_modules/@legendapp/spark-ui/macos/progress/RNSparkProgressIndicator.h +9 -0
  143. package/vendor/node_modules/@legendapp/spark-ui/macos/progress/RNSparkProgressIndicator.mm +66 -0
  144. package/vendor/node_modules/@legendapp/spark-ui/macos/radio-group/RNSparkRadioGroup.h +9 -0
  145. package/vendor/node_modules/@legendapp/spark-ui/macos/radio-group/RNSparkRadioGroup.mm +118 -0
  146. package/vendor/node_modules/@legendapp/spark-ui/macos/sf-symbol/RNSFSymbol.mm +4 -12
  147. package/vendor/node_modules/@legendapp/spark-ui/macos/sheet/RNSparkSheet.h +9 -0
  148. package/vendor/node_modules/@legendapp/spark-ui/macos/sheet/RNSparkSheet.mm +109 -0
  149. package/vendor/node_modules/@legendapp/spark-ui/macos/sidebar/RNSidebar.mm +418 -102
  150. package/vendor/node_modules/@legendapp/spark-ui/macos/table/RNSparkTable.h +9 -0
  151. package/vendor/node_modules/@legendapp/spark-ui/macos/table/RNSparkTable.mm +179 -0
  152. package/vendor/node_modules/@legendapp/spark-ui/package.json +9 -8
  153. package/vendor/node_modules/@legendapp/spark-ui/src/SparkButtonNativeComponent.ts +10 -2
  154. package/vendor/node_modules/@legendapp/spark-ui/src/SparkTextInputNativeComponent.ts +2 -0
  155. package/vendor/node_modules/@legendapp/spark-ui/src/appkit-split-view/SidebarSplitViewNativeComponent.ts +9 -0
  156. package/vendor/node_modules/@legendapp/spark-ui/src/appkit-split-view/SplitView.tsx +99 -0
  157. package/vendor/node_modules/@legendapp/spark-ui/src/appkit-split-view/SplitViewNativeComponent.ts +29 -0
  158. package/vendor/node_modules/@legendapp/spark-ui/src/appkit-split-view/index.tsx +34 -17
  159. package/vendor/node_modules/@legendapp/spark-ui/src/availability.ts +5 -4
  160. package/vendor/node_modules/@legendapp/spark-ui/src/checkbox-unavailable.tsx +20 -0
  161. package/vendor/node_modules/@legendapp/spark-ui/src/control.ts +24 -3
  162. package/vendor/node_modules/@legendapp/spark-ui/src/desktop.tsx +63 -13
  163. package/vendor/node_modules/@legendapp/spark-ui/src/index.android.tsx +12 -7
  164. package/vendor/node_modules/@legendapp/spark-ui/src/index.ios.tsx +12 -7
  165. package/vendor/node_modules/@legendapp/spark-ui/src/index.web.tsx +35 -13
  166. package/vendor/node_modules/@legendapp/spark-ui/src/mobile-input.tsx +2 -2
  167. package/vendor/node_modules/@legendapp/spark-ui/src/native-select/NativeSegmentedControlNativeComponent.ts +3 -1
  168. package/vendor/node_modules/@legendapp/spark-ui/src/popover/PopoverNativeComponent.ts +20 -0
  169. package/vendor/node_modules/@legendapp/spark-ui/src/popover/index.tsx +45 -0
  170. package/vendor/node_modules/@legendapp/spark-ui/src/progress/ProgressIndicatorNativeComponent.ts +13 -0
  171. package/vendor/node_modules/@legendapp/spark-ui/src/progress/index.tsx +32 -0
  172. package/vendor/node_modules/@legendapp/spark-ui/src/radio-group/RadioGroupNativeComponent.ts +17 -0
  173. package/vendor/node_modules/@legendapp/spark-ui/src/sheet/SheetNativeComponent.ts +15 -0
  174. package/vendor/node_modules/@legendapp/spark-ui/src/sheet/index.tsx +38 -0
  175. package/vendor/node_modules/@legendapp/spark-ui/src/sidebar/SidebarItemNativeComponent.ts +9 -1
  176. package/vendor/node_modules/@legendapp/spark-ui/src/sidebar/SidebarNativeComponent.ts +17 -2
  177. package/vendor/node_modules/@legendapp/spark-ui/src/sidebar/index.tsx +106 -22
  178. package/vendor/node_modules/@legendapp/spark-ui/src/table/TableNativeComponent.ts +22 -0
  179. package/vendor/node_modules/@legendapp/spark-ui/src/table/index.tsx +118 -0
  180. package/vendor/node_modules/@legendapp/spark-ui/src/types.ts +39 -6
  181. package/vendor/node_modules/@legendapp/spark-ui/uniwind.ts +3 -1
  182. package/vendor/node_modules/@legendapp/spark-ui/uniwind.web.ts +2 -1
  183. package/vendor/node_modules/@legendapp/spark-ui/windows/SparkUI/SparkUI.h +46 -15
  184. package/vendor/node_modules/@legendapp/spark-updates/package.json +3 -9
  185. package/vendor/node_modules/@legendapp/spark-webview/package.json +2 -2
  186. package/vendor/node_modules/@legendapp/spark-window-options/package.json +1 -1
@@ -0,0 +1,66 @@
1
+ #import "RNSparkProgressIndicator.h"
2
+ #import <react/renderer/components/RNSparkUISpec/ComponentDescriptors.h>
3
+ #import <react/renderer/components/RNSparkUISpec/EventEmitters.h>
4
+ #import <react/renderer/components/RNSparkUISpec/Props.h>
5
+ using namespace facebook::react;
6
+
7
+ @implementation RNSparkProgressIndicator {
8
+ NSProgressIndicator *_indicator;
9
+ NSSize _reportedSize;
10
+ }
11
+ - (instancetype)init {
12
+ if (self = [super init]) {
13
+ _props = std::make_shared<const SparkProgressIndicatorProps>();
14
+ _indicator = [NSProgressIndicator new];
15
+ _indicator.minValue = 0;
16
+ _indicator.maxValue = 1;
17
+ _indicator.displayedWhenStopped = YES;
18
+ [self addSubview:_indicator];
19
+ }
20
+ return self;
21
+ }
22
+ - (BOOL)isFlipped { return YES; }
23
+ - (void)reportIntrinsicSize {
24
+ auto emitter = std::static_pointer_cast<const SparkProgressIndicatorEventEmitter>(_eventEmitter);
25
+ [_indicator sizeToFit];
26
+ NSSize size = NSMakeSize(ceil(_indicator.frame.size.width), ceil(_indicator.frame.size.height));
27
+ _indicator.frame = self.bounds;
28
+ if (!emitter || NSEqualSizes(size, _reportedSize)) return;
29
+ _reportedSize = size;
30
+ SparkProgressIndicatorEventEmitter::OnIntrinsicSize event;
31
+ event.width = size.width;
32
+ event.height = size.height;
33
+ emitter->onIntrinsicSize(event);
34
+ }
35
+ - (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &)oldProps {
36
+ const auto &value = *std::static_pointer_cast<const SparkProgressIndicatorProps>(props);
37
+ _indicator.style = value.variant == SparkProgressIndicatorVariant::Spinner ? NSProgressIndicatorStyleSpinning : NSProgressIndicatorStyleBar;
38
+ _indicator.controlSize = value.controlSize == SparkProgressIndicatorControlSize::Mini ? NSControlSizeMini : value.controlSize == SparkProgressIndicatorControlSize::Small ? NSControlSizeSmall : NSControlSizeRegular;
39
+ _indicator.indeterminate = value.indeterminate;
40
+ if (value.indeterminate) {
41
+ [_indicator startAnimation:nil];
42
+ } else {
43
+ _indicator.doubleValue = value.value;
44
+ [_indicator stopAnimation:nil];
45
+ }
46
+ NSString *label = [NSString stringWithUTF8String:value.accessibilityLabel.c_str()];
47
+ _indicator.accessibilityLabel = label.length ? label : nil;
48
+ [super updateProps:props oldProps:oldProps];
49
+ [self reportIntrinsicSize];
50
+ }
51
+ - (void)updateEventEmitter:(EventEmitter::Shared const &)eventEmitter {
52
+ [super updateEventEmitter:eventEmitter];
53
+ [self reportIntrinsicSize];
54
+ }
55
+ - (void)layoutSubviews { [super layoutSubviews]; _indicator.frame = self.bounds; }
56
+ - (void)updateLayoutMetrics:(const LayoutMetrics &)layoutMetrics oldLayoutMetrics:(const LayoutMetrics &)oldLayoutMetrics {
57
+ [super updateLayoutMetrics:layoutMetrics oldLayoutMetrics:oldLayoutMetrics];
58
+ [self layoutSubviews];
59
+ }
60
+ - (void)prepareForRecycle {
61
+ [super prepareForRecycle];
62
+ [_indicator stopAnimation:nil];
63
+ _reportedSize = NSZeroSize;
64
+ }
65
+ + (ComponentDescriptorProvider)componentDescriptorProvider { return concreteComponentDescriptorProvider<SparkProgressIndicatorComponentDescriptor>(); }
66
+ @end
@@ -0,0 +1,9 @@
1
+ #import <React/RCTViewComponentView.h>
2
+ #import <AppKit/AppKit.h>
3
+
4
+ NS_ASSUME_NONNULL_BEGIN
5
+
6
+ @interface RNSparkRadioGroup : RCTViewComponentView
7
+ @end
8
+
9
+ NS_ASSUME_NONNULL_END
@@ -0,0 +1,118 @@
1
+ #import "RNSparkRadioGroup.h"
2
+ #import "RNSparkLayoutDirection.h"
3
+ #import <react/renderer/components/RNSparkUISpec/ComponentDescriptors.h>
4
+ #import <react/renderer/components/RNSparkUISpec/EventEmitters.h>
5
+ #import <react/renderer/components/RNSparkUISpec/Props.h>
6
+ using namespace facebook::react;
7
+
8
+ // NSButton radios in an NSStackView. Radios sharing a superview and action form one AppKit group,
9
+ // so a click unchecks the others; the group then reports the value and waits for the app to confirm it.
10
+ @implementation RNSparkRadioGroup {
11
+ NSStackView *_stack;
12
+ NSArray<NSString *> *_values;
13
+ NSString *_itemsJson;
14
+ NSString *_value;
15
+ int _selectionRevision;
16
+ NSSize _reportedSize;
17
+ }
18
+ - (instancetype)init {
19
+ if (self = [super init]) {
20
+ _props = std::make_shared<const SparkRadioGroupProps>();
21
+ _values = @[];
22
+ _itemsJson = @"";
23
+ _value = @"";
24
+ _stack = [NSStackView new];
25
+ _stack.orientation = NSUserInterfaceLayoutOrientationVertical;
26
+ _stack.alignment = NSLayoutAttributeLeading;
27
+ _stack.spacing = 6;
28
+ _stack.accessibilityRole = NSAccessibilityRadioGroupRole;
29
+ _stack.accessibilityElement = YES;
30
+ [self addSubview:_stack];
31
+ }
32
+ return self;
33
+ }
34
+ - (BOOL)isFlipped { return YES; }
35
+ - (NSArray<NSButton *> *)radios { return (NSArray<NSButton *> *)_stack.arrangedSubviews; }
36
+ - (void)reloadItems {
37
+ for (NSView *view in _stack.arrangedSubviews.copy) [view removeFromSuperview];
38
+ NSMutableArray<NSString *> *values = [NSMutableArray new];
39
+ id parsed = [NSJSONSerialization JSONObjectWithData:[_itemsJson dataUsingEncoding:NSUTF8StringEncoding] ?: NSData.data options:0 error:nil];
40
+ for (NSDictionary *item in [parsed isKindOfClass:NSArray.class] ? parsed : @[]) {
41
+ if (![item isKindOfClass:NSDictionary.class] || ![item[@"label"] isKindOfClass:NSString.class] || ![item[@"value"] isKindOfClass:NSString.class]) continue;
42
+ NSButton *radio = [NSButton radioButtonWithTitle:item[@"label"] target:self action:@selector(radioClicked:)];
43
+ [_stack addArrangedSubview:radio];
44
+ [values addObject:item[@"value"]];
45
+ }
46
+ _values = values;
47
+ }
48
+ - (void)applyValue {
49
+ NSArray<NSButton *> *radios = self.radios;
50
+ for (NSUInteger index = 0; index < radios.count; index += 1) radios[index].state = [_values[index] isEqualToString:_value] ? NSControlStateValueOn : NSControlStateValueOff;
51
+ }
52
+ - (void)radioClicked:(NSButton *)sender {
53
+ NSUInteger index = [self.radios indexOfObjectIdenticalTo:sender];
54
+ if (index == NSNotFound || [_values[index] isEqualToString:_value]) { [self applyValue]; return; }
55
+ auto emitter = std::static_pointer_cast<const SparkRadioGroupEventEmitter>(_eventEmitter);
56
+ if (emitter) emitter->onValueChange({.value = _values[index].UTF8String});
57
+ }
58
+ - (void)reportIntrinsicSize {
59
+ NSSize size = _stack.fittingSize;
60
+ size = NSMakeSize(ceil(size.width), ceil(size.height));
61
+ auto emitter = std::static_pointer_cast<const SparkRadioGroupEventEmitter>(_eventEmitter);
62
+ if (!emitter || NSEqualSizes(size, _reportedSize)) return;
63
+ _reportedSize = size;
64
+ SparkRadioGroupEventEmitter::OnIntrinsicSize event;
65
+ event.width = size.width;
66
+ event.height = size.height;
67
+ emitter->onIntrinsicSize(event);
68
+ }
69
+ - (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &)oldProps {
70
+ const auto &next = *std::static_pointer_cast<const SparkRadioGroupProps>(props);
71
+ NSString *itemsJson = [NSString stringWithUTF8String:next.itemsJson.c_str()] ?: @"";
72
+ NSString *value = [NSString stringWithUTF8String:next.value.c_str()] ?: @"";
73
+ BOOL reload = ![itemsJson isEqualToString:_itemsJson];
74
+ if (reload) { _itemsJson = itemsJson; [self reloadItems]; }
75
+ if (reload || ![value isEqualToString:_value] || next.selectionRevision != _selectionRevision) {
76
+ _value = value;
77
+ _selectionRevision = next.selectionRevision;
78
+ [self applyValue];
79
+ }
80
+ _stack.orientation = next.orientation == SparkRadioGroupOrientation::Horizontal ? NSUserInterfaceLayoutOrientationHorizontal : NSUserInterfaceLayoutOrientationVertical;
81
+ _stack.alignment = _stack.orientation == NSUserInterfaceLayoutOrientationHorizontal ? NSLayoutAttributeFirstBaseline : NSLayoutAttributeLeading;
82
+ _stack.spacing = _stack.orientation == NSUserInterfaceLayoutOrientationHorizontal ? 16 : 6;
83
+ NSControlSize size = next.controlSize == SparkRadioGroupControlSize::Mini ? NSControlSizeMini : next.controlSize == SparkRadioGroupControlSize::Small ? NSControlSizeSmall : NSControlSizeRegular;
84
+ for (NSButton *radio in self.radios) {
85
+ radio.controlSize = size;
86
+ radio.font = [NSFont systemFontOfSize:[NSFont systemFontSizeForControlSize:size]];
87
+ radio.enabled = next.enabled;
88
+ }
89
+ NSString *label = [NSString stringWithUTF8String:next.accessibilityLabel.c_str()];
90
+ _stack.accessibilityLabel = label.length ? label : nil;
91
+ _stack.accessibilityIdentifier = [NSString stringWithUTF8String:next.testId.c_str()];
92
+ [super updateProps:props oldProps:oldProps];
93
+ [self reportIntrinsicSize];
94
+ }
95
+ - (void)updateEventEmitter:(EventEmitter::Shared const &)eventEmitter {
96
+ [super updateEventEmitter:eventEmitter];
97
+ [self reportIntrinsicSize];
98
+ }
99
+ - (void)layoutSubviews {
100
+ [super layoutSubviews];
101
+ _stack.frame = self.bounds;
102
+ }
103
+ - (void)updateLayoutMetrics:(const LayoutMetrics &)layoutMetrics oldLayoutMetrics:(const LayoutMetrics &)oldLayoutMetrics {
104
+ [super updateLayoutMetrics:layoutMetrics oldLayoutMetrics:oldLayoutMetrics];
105
+ _stack.userInterfaceLayoutDirection = RNSparkLayoutDirection(layoutMetrics);
106
+ [self layoutSubviews];
107
+ }
108
+ - (void)prepareForRecycle {
109
+ [super prepareForRecycle];
110
+ _itemsJson = @"";
111
+ _value = @"";
112
+ _selectionRevision = 0;
113
+ _reportedSize = NSZeroSize;
114
+ _values = @[];
115
+ for (NSView *view in _stack.arrangedSubviews.copy) [view removeFromSuperview];
116
+ }
117
+ + (ComponentDescriptorProvider)componentDescriptorProvider { return concreteComponentDescriptorProvider<SparkRadioGroupComponentDescriptor>(); }
118
+ @end
@@ -1,6 +1,8 @@
1
1
  #import "RNSFSymbol.h"
2
2
  #import "RNSparkLayoutDirection.h"
3
3
 
4
+ #import <React/RCTConversions.h>
5
+
4
6
  #import <react/renderer/components/RNSparkUISpec/ComponentDescriptors.h>
5
7
  #import <react/renderer/components/RNSparkUISpec/Props.h>
6
8
  #import <react/renderer/components/RNSparkUISpec/EventEmitters.h>
@@ -66,12 +68,7 @@ using namespace facebook::react;
66
68
  _imageView.symbolConfiguration = [NSImageSymbolConfiguration configurationWithPointSize:_size
67
69
  weight:NSFontWeightRegular
68
70
  scale:symbolScale];
69
- _imageView.contentTintColor = newProps.color
70
- ? [NSColor colorWithRed:(CGFloat)redFromColor(newProps.color) / 255.0
71
- green:(CGFloat)greenFromColor(newProps.color) / 255.0
72
- blue:(CGFloat)blueFromColor(newProps.color) / 255.0
73
- alpha:(CGFloat)alphaFromColor(newProps.color) / 255.0]
74
- : NSColor.labelColor;
71
+ _imageView.contentTintColor = RCTUIColorFromSharedColor(newProps.color) ?: NSColor.labelColor;
75
72
  #else
76
73
  if (@available(iOS 13.0, *)) {
77
74
  UIImageSymbolScale symbolScale = UIImageSymbolScaleMedium;
@@ -85,12 +82,7 @@ using namespace facebook::react;
85
82
  [UIImageSymbolConfiguration configurationWithPointSize:_size weight:UIImageSymbolWeightRegular scale:symbolScale];
86
83
  _imageView.image = [[[UIImage systemImageNamed:_symbolName] imageWithConfiguration:configuration]
87
84
  imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
88
- _imageView.tintColor = newProps.color
89
- ? [UIColor colorWithRed:(CGFloat)redFromColor(newProps.color) / 255.0
90
- green:(CGFloat)greenFromColor(newProps.color) / 255.0
91
- blue:(CGFloat)blueFromColor(newProps.color) / 255.0
92
- alpha:(CGFloat)alphaFromColor(newProps.color) / 255.0]
93
- : UIColor.labelColor;
85
+ _imageView.tintColor = RCTUIColorFromSharedColor(newProps.color) ?: UIColor.labelColor;
94
86
  }
95
87
  #endif
96
88
 
@@ -0,0 +1,9 @@
1
+ #import <React/RCTViewComponentView.h>
2
+ #import <AppKit/AppKit.h>
3
+
4
+ NS_ASSUME_NONNULL_BEGIN
5
+
6
+ @interface RNSparkSheet : RCTViewComponentView
7
+ @end
8
+
9
+ NS_ASSUME_NONNULL_END
@@ -0,0 +1,109 @@
1
+ #import "RNSparkSheet.h"
2
+ #import <React/RCTSurfaceTouchHandler.h>
3
+ #import <react/renderer/components/RNSparkUISpec/ComponentDescriptors.h>
4
+ #import <react/renderer/components/RNSparkUISpec/EventEmitters.h>
5
+ #import <react/renderer/components/RNSparkUISpec/Props.h>
6
+ using namespace facebook::react;
7
+
8
+ @interface RNSparkSheetContentView : NSView
9
+ @end
10
+ @implementation RNSparkSheetContentView
11
+ - (BOOL)isFlipped { return YES; }
12
+ @end
13
+
14
+ // Escape and ⌘. reach the sheet as cancelOperation:; the sheet reports them and stays until `visible` turns false.
15
+ @interface RNSparkSheetWindow : NSPanel
16
+ @property (nonatomic, copy) void (^onCancel)(void);
17
+ @end
18
+ @implementation RNSparkSheetWindow
19
+ - (BOOL)canBecomeKeyWindow { return YES; }
20
+ - (void)cancelOperation:(id)sender { if (_onCancel) _onCancel(); }
21
+ @end
22
+
23
+ // The React child moves into a document-modal sheet on this view's window. The content keeps its own touch handler,
24
+ // since the surface's handler only sees its own window. endSheet: returns after the close animation, and only then
25
+ // does onDismiss tell React it may unmount the content. Closing the parent window ends the sheet, which would
26
+ // otherwise keep the closed window alive.
27
+ @implementation RNSparkSheet {
28
+ RNSparkSheetWindow *_sheet;
29
+ RNSparkSheetContentView *_contentView;
30
+ RCTSurfaceTouchHandler *_touchHandler;
31
+ NSView *_content;
32
+ __weak NSWindow *_parent;
33
+ id _parentObserver;
34
+ BOOL _visible;
35
+ NSSize _contentSize;
36
+ }
37
+ - (instancetype)init {
38
+ if (self = [super init]) {
39
+ _props = std::make_shared<const SparkSheetProps>();
40
+ _contentView = [[RNSparkSheetContentView alloc] initWithFrame:NSZeroRect];
41
+ _sheet = [[RNSparkSheetWindow alloc] initWithContentRect:NSMakeRect(0, 0, 100, 100) styleMask:NSWindowStyleMaskTitled backing:NSBackingStoreBuffered defer:YES];
42
+ _sheet.releasedWhenClosed = NO;
43
+ _sheet.contentView = _contentView;
44
+ __weak RNSparkSheet *weakSelf = self;
45
+ _sheet.onCancel = ^{ [weakSelf cancel]; };
46
+ _touchHandler = [RCTSurfaceTouchHandler new];
47
+ [_touchHandler attachToView:_contentView];
48
+ }
49
+ return self;
50
+ }
51
+ - (BOOL)isFlipped { return YES; }
52
+ - (void)mountChildComponentView:(RCTUIView<RCTComponentViewProtocol> *)childComponentView index:(NSInteger)index {
53
+ _content = childComponentView;
54
+ [_contentView addSubview:childComponentView];
55
+ [self dismissIfHidden];
56
+ }
57
+ - (void)unmountChildComponentView:(RCTUIView<RCTComponentViewProtocol> *)childComponentView index:(NSInteger)index {
58
+ if (childComponentView == _content) _content = nil;
59
+ [childComponentView removeFromSuperview];
60
+ }
61
+ - (void)cancel {
62
+ auto emitter = std::static_pointer_cast<const SparkSheetEventEmitter>(_eventEmitter);
63
+ if (_visible && emitter) emitter->onCancel({});
64
+ }
65
+ // Sent whenever the view is hidden but still holds content, not only on a visible → hidden change: Fabric can skip
66
+ // the commit that showed it.
67
+ - (void)dismissIfHidden {
68
+ auto emitter = std::static_pointer_cast<const SparkSheetEventEmitter>(_eventEmitter);
69
+ if (!_visible && _content && emitter) emitter->onDismiss({});
70
+ }
71
+ - (void)endSheet {
72
+ if (_parentObserver) { [NSNotificationCenter.defaultCenter removeObserver:_parentObserver]; _parentObserver = nil; }
73
+ NSWindow *parent = _parent;
74
+ _parent = nil;
75
+ [parent endSheet:_sheet];
76
+ }
77
+ - (void)updatePresentation {
78
+ BOOL show = _visible && _contentSize.width > 0 && _contentSize.height > 0 && self.window != nil;
79
+ if (!show) { [self endSheet]; return; }
80
+ if (!NSEqualSizes(_sheet.contentView.frame.size, _contentSize)) [_sheet setContentSize:_contentSize];
81
+ if (_parent && _parent == self.window) return;
82
+ [self endSheet];
83
+ _parent = self.window;
84
+ __weak RNSparkSheet *weakSelf = self;
85
+ _parentObserver = [NSNotificationCenter.defaultCenter addObserverForName:NSWindowWillCloseNotification object:_parent queue:nil
86
+ usingBlock:^(NSNotification *) { [weakSelf endSheet]; }];
87
+ [_parent beginSheet:_sheet completionHandler:nil];
88
+ }
89
+ - (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &)oldProps {
90
+ const auto &next = *std::static_pointer_cast<const SparkSheetProps>(props);
91
+ _visible = next.visible;
92
+ _contentSize = NSMakeSize(MAX(0, next.contentWidth), MAX(0, next.contentHeight));
93
+ _contentView.accessibilityLabel = next.accessibilityLabel.empty() ? nil : [NSString stringWithUTF8String:next.accessibilityLabel.c_str()];
94
+ [super updateProps:props oldProps:oldProps];
95
+ [self updatePresentation];
96
+ [self dismissIfHidden];
97
+ }
98
+ - (void)viewDidMoveToWindow {
99
+ [super viewDidMoveToWindow];
100
+ [self updatePresentation];
101
+ }
102
+ - (void)prepareForRecycle {
103
+ _visible = NO;
104
+ [self updatePresentation];
105
+ _contentSize = NSZeroSize;
106
+ [super prepareForRecycle];
107
+ }
108
+ + (ComponentDescriptorProvider)componentDescriptorProvider { return concreteComponentDescriptorProvider<SparkSheetComponentDescriptor>(); }
109
+ @end