@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.
- package/README.md +1 -1
- package/camera.ts +13 -0
- package/customize.ts +2 -0
- package/html.ts +1 -0
- package/markdown.ts +1 -0
- package/package.json +34 -15
- package/patches/camera/react-native-nitro-image.patch +320 -0
- package/patches/camera/react-native-nitro-modules.patch +50 -0
- package/patches/camera/react-native-vision-camera.patch +2662 -0
- package/patches/camera/upstream.json +22 -0
- package/patches/dependencies.json +14 -0
- package/patches/react-native-enriched-html@1.1.1.patch +854 -0
- package/patches/react-native-enriched-markdown@1.1.1.patch +9261 -0
- package/postinstall.cjs +1 -0
- package/schema.json +104 -0
- package/skills/spark/SKILL.md +56 -0
- package/skills/spark/UPGRADING.md +246 -0
- package/ui-swipe.ts +1 -0
- package/vendor/node_modules/@legendapp/spark-ai/package.json +4 -4
- package/vendor/node_modules/@legendapp/spark-ai/src/invocation-command.cjs +11 -0
- package/vendor/node_modules/@legendapp/spark-ai/src/invocation-command.d.cts +2 -0
- package/vendor/node_modules/@legendapp/spark-ai/src/invocations.ts +2 -19
- package/vendor/node_modules/@legendapp/spark-audio/package.json +3 -3
- package/vendor/node_modules/@legendapp/spark-auth-session/package.json +3 -3
- package/vendor/node_modules/@legendapp/spark-cli/dist/add-desktop.js +4 -4
- package/vendor/node_modules/@legendapp/spark-cli/dist/build.js +65 -11
- package/vendor/node_modules/@legendapp/spark-cli/dist/cli-arguments.js +2 -1
- package/vendor/node_modules/@legendapp/spark-cli/dist/commands.js +3 -2
- package/vendor/node_modules/@legendapp/spark-cli/dist/create.js +36 -13
- package/vendor/node_modules/@legendapp/spark-cli/dist/credentials.js +41 -26
- package/vendor/node_modules/@legendapp/spark-cli/dist/customize-ai.cjs +108 -0
- package/vendor/node_modules/@legendapp/spark-cli/dist/customize-artifacts.js +315 -0
- package/vendor/node_modules/@legendapp/spark-cli/dist/customize-cli.cjs +75 -0
- package/vendor/node_modules/@legendapp/spark-cli/dist/customize-github.cjs +133 -0
- package/vendor/node_modules/@legendapp/spark-cli/dist/customize-policy.cjs +102 -0
- package/vendor/node_modules/@legendapp/spark-cli/dist/customize-provider.cjs +2 -0
- package/vendor/node_modules/@legendapp/spark-cli/dist/customize-worker.cjs +273 -0
- package/vendor/node_modules/@legendapp/spark-cli/dist/dependency-pins.js +157 -0
- package/vendor/node_modules/@legendapp/spark-cli/dist/dev-command.js +3 -1
- package/vendor/node_modules/@legendapp/spark-cli/dist/dev.js +1 -1
- package/vendor/node_modules/@legendapp/spark-cli/dist/enriched-html-pins.js +128 -0
- package/vendor/node_modules/@legendapp/spark-cli/dist/errors.js +100 -0
- package/vendor/node_modules/@legendapp/spark-cli/dist/examples.js +1 -1
- package/vendor/node_modules/@legendapp/spark-cli/dist/expo-dev-patch.cjs +30 -1
- package/vendor/node_modules/@legendapp/spark-cli/dist/expo-native.cjs +5 -1
- package/vendor/node_modules/@legendapp/spark-cli/dist/helpers.js +1 -1
- package/vendor/node_modules/@legendapp/spark-cli/dist/index.js +52 -7
- package/vendor/node_modules/@legendapp/spark-cli/dist/init-template.d.cts +1 -0
- package/vendor/node_modules/@legendapp/spark-cli/dist/js-runtime.cjs +96 -0
- package/vendor/node_modules/@legendapp/spark-cli/dist/json.js +16 -0
- package/vendor/node_modules/@legendapp/spark-cli/dist/migration-helpers.cjs +152 -0
- package/vendor/node_modules/@legendapp/spark-cli/dist/migration-helpers.d.cts +15 -0
- package/vendor/node_modules/@legendapp/spark-cli/dist/migrations.cjs +184 -0
- package/vendor/node_modules/@legendapp/spark-cli/dist/migrations.d.cts +16 -0
- package/vendor/node_modules/@legendapp/spark-cli/dist/native-patch-preflight.js +5 -1
- package/vendor/node_modules/@legendapp/spark-cli/dist/package-manager-config.js +41 -0
- package/vendor/node_modules/@legendapp/spark-cli/dist/package-manager.js +13 -0
- package/vendor/node_modules/@legendapp/spark-cli/dist/process.js +7 -0
- package/vendor/node_modules/@legendapp/spark-cli/dist/project-version.js +12 -0
- package/vendor/node_modules/@legendapp/spark-cli/dist/project.js +66 -30
- package/vendor/node_modules/@legendapp/spark-cli/dist/release.js +2 -1
- package/vendor/node_modules/@legendapp/spark-cli/dist/release.json +20 -20
- package/vendor/node_modules/@legendapp/spark-cli/dist/runtime-bootstrap.ps1 +87 -0
- package/vendor/node_modules/@legendapp/spark-cli/dist/runtime-bootstrap.sh +107 -0
- package/vendor/node_modules/@legendapp/spark-cli/dist/runtime-downloads.tsv +13 -0
- package/vendor/node_modules/@legendapp/spark-cli/dist/sdk-install.js +8 -3
- package/vendor/node_modules/@legendapp/spark-cli/dist/universal.cjs +2 -1
- package/vendor/node_modules/@legendapp/spark-cli/dist/upgrade.js +102 -0
- package/vendor/node_modules/@legendapp/spark-cli/dist/windows.js +1 -8
- package/vendor/node_modules/@legendapp/spark-cli/package.json +6 -4
- package/vendor/node_modules/@legendapp/spark-cli/templates/blank-typescript/.claude/skills/spark/SKILL.md +9 -0
- package/vendor/node_modules/@legendapp/spark-cli/templates/blank-typescript/AGENTS.md +4 -0
- package/vendor/node_modules/@legendapp/spark-cli/templates/blank-typescript/CLAUDE.md +4 -0
- package/vendor/node_modules/@legendapp/spark-cli/templates/blank-typescript/README.md +15 -0
- package/vendor/node_modules/@legendapp/spark-cli/templates/blank-typescript/package.json +47 -3
- package/vendor/node_modules/@legendapp/spark-cli/templates/universal/.claude/skills/spark/SKILL.md +9 -0
- package/vendor/node_modules/@legendapp/spark-cli/templates/universal/AGENTS.md +4 -0
- package/vendor/node_modules/@legendapp/spark-cli/templates/universal/CLAUDE.md +4 -0
- package/vendor/node_modules/@legendapp/spark-cli/templates/universal/README.md +15 -0
- package/vendor/node_modules/@legendapp/spark-cli/templates/universal/package.json +46 -3
- package/vendor/node_modules/@legendapp/spark-cli/templates/windows/.claude/skills/spark/SKILL.md +9 -0
- package/vendor/node_modules/@legendapp/spark-cli/templates/windows/AGENTS.md +4 -0
- package/vendor/node_modules/@legendapp/spark-cli/templates/windows/CLAUDE.md +4 -0
- package/vendor/node_modules/@legendapp/spark-cli/templates/windows/README.md +15 -0
- package/vendor/node_modules/@legendapp/spark-cli/templates/windows/package.json +47 -3
- package/vendor/node_modules/@legendapp/spark-clipboard/package.json +3 -3
- package/vendor/node_modules/@legendapp/spark-codex/package.json +4 -4
- package/vendor/node_modules/@legendapp/spark-commands/package.json +6 -6
- package/vendor/node_modules/@legendapp/spark-context-menu/package.json +3 -3
- package/vendor/node_modules/@legendapp/spark-desktop-app/macos/RNDesktopApp.mm +14 -1
- package/vendor/node_modules/@legendapp/spark-desktop-app/package.json +2 -2
- package/vendor/node_modules/@legendapp/spark-desktop-app/src/contracts/menu.ts +6 -4
- package/vendor/node_modules/@legendapp/spark-desktop-app/src/customize-hooks.ts +17 -0
- package/vendor/node_modules/@legendapp/spark-desktop-app/src/customize.ts +117 -0
- package/vendor/node_modules/@legendapp/spark-desktop-config/app.plugin.cjs +20 -1
- package/vendor/node_modules/@legendapp/spark-desktop-config/config.cjs +5 -2
- package/vendor/node_modules/@legendapp/spark-desktop-config/config.d.cts +14 -0
- package/vendor/node_modules/@legendapp/spark-desktop-config/customize-provider.cjs +16 -0
- package/vendor/node_modules/@legendapp/spark-desktop-config/customize.cjs +16 -0
- package/vendor/node_modules/@legendapp/spark-desktop-config/expo.cjs +1 -0
- package/vendor/node_modules/@legendapp/spark-desktop-config/native-patches.cjs +106 -0
- package/vendor/node_modules/@legendapp/spark-desktop-config/native-patches.d.cts +1 -0
- package/vendor/node_modules/@legendapp/spark-desktop-config/package.json +5 -4
- package/vendor/node_modules/@legendapp/spark-desktop-config/schema.json +104 -0
- package/vendor/node_modules/@legendapp/spark-desktop-host/SparkCustomize.mm +517 -0
- package/vendor/node_modules/@legendapp/spark-desktop-host/package.json +4 -3
- package/vendor/node_modules/@legendapp/spark-desktop-links/package.json +3 -3
- package/vendor/node_modules/@legendapp/spark-desktop-shortcuts/macos/RNDesktopShortcuts.mm +3 -1
- package/vendor/node_modules/@legendapp/spark-desktop-shortcuts/macos/keyboard-manager/RNKeyboardManager.h +3 -0
- package/vendor/node_modules/@legendapp/spark-desktop-shortcuts/macos/keyboard-manager/RNKeyboardManager.mm +1 -1
- package/vendor/node_modules/@legendapp/spark-desktop-shortcuts/package.json +3 -3
- package/vendor/node_modules/@legendapp/spark-desktop-windows/macos/window-manager/RNWindowManager.mm +44 -4
- package/vendor/node_modules/@legendapp/spark-desktop-windows/package.json +4 -4
- package/vendor/node_modules/@legendapp/spark-desktop-windows/src/api.ts +65 -26
- package/vendor/node_modules/@legendapp/spark-desktop-windows/src/macos-adapter.ts +8 -6
- package/vendor/node_modules/@legendapp/spark-documents/package.json +8 -8
- package/vendor/node_modules/@legendapp/spark-drag-drop/package.json +3 -3
- package/vendor/node_modules/@legendapp/spark-file-dialog/package.json +3 -3
- package/vendor/node_modules/@legendapp/spark-file-system/macos/SparkFileMutations.h +1 -0
- package/vendor/node_modules/@legendapp/spark-file-system/macos/SparkFileMutations.mm +11 -10
- package/vendor/node_modules/@legendapp/spark-file-system/package.json +3 -3
- package/vendor/node_modules/@legendapp/spark-global-shortcuts/package.json +3 -3
- package/vendor/node_modules/@legendapp/spark-html/package.json +24 -0
- package/vendor/node_modules/@legendapp/spark-html/src/Html.tsx +22 -0
- package/vendor/node_modules/@legendapp/spark-html/src/HtmlInput.tsx +102 -0
- package/vendor/node_modules/@legendapp/spark-html/src/index.ts +4 -0
- package/vendor/node_modules/@legendapp/spark-html/src/types.ts +4 -0
- package/vendor/node_modules/@legendapp/spark-markdown/package.json +24 -0
- package/vendor/node_modules/@legendapp/spark-markdown/src/Markdown.tsx +24 -0
- package/vendor/node_modules/@legendapp/spark-markdown/src/MarkdownInput.tsx +111 -0
- package/vendor/node_modules/@legendapp/spark-markdown/src/index.ts +4 -0
- package/vendor/node_modules/@legendapp/spark-message-dialog/package.json +3 -3
- package/vendor/node_modules/@legendapp/spark-native-menu/package.json +3 -3
- package/vendor/node_modules/@legendapp/spark-notifications/package.json +3 -3
- package/vendor/node_modules/@legendapp/spark-notifications/windows/SparkNotifications/SparkNotifications.h +16 -11
- package/vendor/node_modules/@legendapp/spark-processes/package.json +3 -3
- package/vendor/node_modules/@legendapp/spark-rich-text/package.json +18 -0
- package/vendor/node_modules/@legendapp/spark-rich-text/src/components.tsx +52 -0
- package/vendor/node_modules/@legendapp/spark-rich-text/src/index.ts +4 -0
- package/vendor/node_modules/@legendapp/spark-rich-text/src/types.ts +24 -0
- package/vendor/node_modules/@legendapp/spark-rich-text/src/useInputShortcuts.macos.ts +55 -0
- package/vendor/node_modules/@legendapp/spark-rich-text/src/useInputShortcuts.ts +13 -0
- package/vendor/node_modules/@legendapp/spark-rich-text/src/useInputValue.ts +14 -0
- package/vendor/node_modules/@legendapp/spark-rich-text/src/value.ts +16 -0
- package/vendor/node_modules/@legendapp/spark-secure-storage/package.json +3 -3
- package/vendor/node_modules/@legendapp/spark-settings/package.json +3 -3
- package/vendor/node_modules/@legendapp/spark-settings-ui/package.json +5 -5
- package/vendor/node_modules/@legendapp/spark-sqlite/package.json +3 -3
- package/vendor/node_modules/@legendapp/spark-system/package.json +3 -3
- package/vendor/node_modules/@legendapp/spark-tray/package.json +3 -3
- package/vendor/node_modules/@legendapp/spark-ui/macos/appkit-split-view/RNSidebarSplitViewComponent.mm +360 -35
- package/vendor/node_modules/@legendapp/spark-ui/macos/swipe-actions/RNSwipeActions.h +10 -0
- package/vendor/node_modules/@legendapp/spark-ui/macos/swipe-actions/RNSwipeActions.mm +422 -0
- package/vendor/node_modules/@legendapp/spark-ui/package.json +4 -3
- package/vendor/node_modules/@legendapp/spark-ui/src/appkit-split-view/SidebarSplitViewNativeComponent.ts +11 -0
- package/vendor/node_modules/@legendapp/spark-ui/src/appkit-split-view/index.tsx +30 -13
- package/vendor/node_modules/@legendapp/spark-ui/src/swipe-actions/SwipeActionsNativeComponent.ts +11 -0
- package/vendor/node_modules/@legendapp/spark-ui/src/swipe-actions/index.tsx +41 -0
- package/vendor/node_modules/@legendapp/spark-updates/package.json +3 -3
- package/vendor/node_modules/@legendapp/spark-webview/package.json +2 -2
- 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
|
+
"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.
|
|
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.
|
|
43
|
+
"@legendapp/spark-desktop-app": "0.0.1-next.5"
|
|
44
44
|
},
|
|
45
45
|
"private": true
|
|
46
46
|
}
|
package/vendor/node_modules/@legendapp/spark-desktop-windows/macos/window-manager/RNWindowManager.mm
CHANGED
|
@@ -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
|
-
|
|
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
|
+
"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.
|
|
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.
|
|
44
|
-
"@legendapp/spark-window-options": "0.0.1-next.
|
|
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
|
|
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
|
-
|
|
58
|
-
|
|
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
|
-
|
|
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
|
-
/**
|
|
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 (
|
|
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
|
|
149
|
+
let closed = false, instance: string | undefined, request: number | undefined, latestRequest = 0;
|
|
127
150
|
let subscription: ReturnType<typeof onDesktopEvent>;
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
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
|
-
|
|
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(() =>
|
|
136
|
-
if (
|
|
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 } });
|
|
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 (!
|
|
182
|
+
if (!closed) guards.set(id, guard);
|
|
183
|
+
return registration;
|
|
149
184
|
} catch (cause) {
|
|
150
|
-
|
|
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
|
-
}
|
|
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 {
|
|
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:
|
|
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 { ...
|
|
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
|
|
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:
|
|
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
|
+
"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.
|
|
12
|
-
"@legendapp/spark-file-system": "0.0.1-next.
|
|
13
|
-
"@legendapp/spark-native-menu": "0.0.1-next.
|
|
14
|
-
"@legendapp/spark-desktop-app": "0.0.1-next.
|
|
15
|
-
"@legendapp/spark-desktop-windows": "0.0.1-next.
|
|
16
|
-
"@legendapp/spark-desktop-links": "0.0.1-next.
|
|
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.
|
|
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
|
+
"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.
|
|
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.
|
|
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
|
+
"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.
|
|
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.
|
|
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
|
-
|
|
206
|
-
if (
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
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
|
+
"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.
|
|
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.
|
|
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
|
+
"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.
|
|
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.
|
|
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
|
+
}
|