basalt-core 0.0.0-rc5
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/LICENSE +21 -0
- package/dist/cli/basalt.d.ts +3 -0
- package/dist/cli/basalt.d.ts.map +1 -0
- package/dist/cli/basalt.js +47 -0
- package/dist/cli/basalt.js.map +1 -0
- package/dist/cli/bundle-cli.d.ts +12 -0
- package/dist/cli/bundle-cli.d.ts.map +1 -0
- package/dist/cli/bundle-cli.js +124 -0
- package/dist/cli/bundle-cli.js.map +1 -0
- package/dist/cli/bundleWithAssets.d.ts +79 -0
- package/dist/cli/bundleWithAssets.d.ts.map +1 -0
- package/dist/cli/bundleWithAssets.js +198 -0
- package/dist/cli/bundleWithAssets.js.map +1 -0
- package/dist/cli/desktop.d.ts +339 -0
- package/dist/cli/desktop.d.ts.map +1 -0
- package/dist/cli/desktop.js +1029 -0
- package/dist/cli/desktop.js.map +1 -0
- package/dist/cli/doctor.d.ts +31 -0
- package/dist/cli/doctor.d.ts.map +1 -0
- package/dist/cli/doctor.js +283 -0
- package/dist/cli/doctor.js.map +1 -0
- package/dist/cli/init.d.ts +77 -0
- package/dist/cli/init.d.ts.map +1 -0
- package/dist/cli/init.js +442 -0
- package/dist/cli/init.js.map +1 -0
- package/dist/cli/metro.d.ts +49 -0
- package/dist/cli/metro.d.ts.map +1 -0
- package/dist/cli/metro.js +148 -0
- package/dist/cli/metro.js.map +1 -0
- package/dist/cli/packageApp.d.ts +102 -0
- package/dist/cli/packageApp.d.ts.map +1 -0
- package/dist/cli/packageApp.js +319 -0
- package/dist/cli/packageApp.js.map +1 -0
- package/dist/cli/steps.d.ts +34 -0
- package/dist/cli/steps.d.ts.map +1 -0
- package/dist/cli/steps.js +53 -0
- package/dist/cli/steps.js.map +1 -0
- package/dist/metro-config.d.ts +168 -0
- package/dist/metro-config.d.ts.map +1 -0
- package/dist/metro-config.js +671 -0
- package/dist/metro-config.js.map +1 -0
- package/dist/react-native.config.d.ts +7 -0
- package/dist/react-native.config.d.ts.map +1 -0
- package/dist/react-native.config.js +80 -0
- package/dist/react-native.config.js.map +1 -0
- package/dist/src/DragSource.d.ts +52 -0
- package/dist/src/DragSource.d.ts.map +1 -0
- package/dist/src/DragSource.js +97 -0
- package/dist/src/DragSource.js.map +1 -0
- package/dist/src/DropTarget.d.ts +58 -0
- package/dist/src/DropTarget.d.ts.map +1 -0
- package/dist/src/DropTarget.js +131 -0
- package/dist/src/DropTarget.js.map +1 -0
- package/dist/src/KeyHandler.d.ts +57 -0
- package/dist/src/KeyHandler.d.ts.map +1 -0
- package/dist/src/KeyHandler.js +48 -0
- package/dist/src/KeyHandler.js.map +1 -0
- package/dist/src/Menu.d.ts +72 -0
- package/dist/src/Menu.d.ts.map +1 -0
- package/dist/src/Menu.js +179 -0
- package/dist/src/Menu.js.map +1 -0
- package/dist/src/TitleBar.d.ts +75 -0
- package/dist/src/TitleBar.d.ts.map +1 -0
- package/dist/src/TitleBar.js +236 -0
- package/dist/src/TitleBar.js.map +1 -0
- package/dist/src/Window.d.ts +87 -0
- package/dist/src/Window.d.ts.map +1 -0
- package/dist/src/Window.js +248 -0
- package/dist/src/Window.js.map +1 -0
- package/dist/src/closeRequest.d.ts +55 -0
- package/dist/src/closeRequest.d.ts.map +1 -0
- package/dist/src/closeRequest.js +134 -0
- package/dist/src/closeRequest.js.map +1 -0
- package/dist/src/index.d.ts +45 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +92 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/overrides/Alert.d.ts +69 -0
- package/dist/src/overrides/Alert.d.ts.map +1 -0
- package/dist/src/overrides/Alert.js +112 -0
- package/dist/src/overrides/Alert.js.map +1 -0
- package/dist/src/overrides/BaseViewConfig.d.ts +28 -0
- package/dist/src/overrides/BaseViewConfig.d.ts.map +1 -0
- package/dist/src/overrides/BaseViewConfig.js +72 -0
- package/dist/src/overrides/BaseViewConfig.js.map +1 -0
- package/dist/src/overrides/Platform.linux.d.ts +10 -0
- package/dist/src/overrides/Platform.linux.d.ts.map +1 -0
- package/dist/src/overrides/Platform.linux.js +15 -0
- package/dist/src/overrides/Platform.linux.js.map +1 -0
- package/dist/src/overrides/Platform.macos.d.ts +10 -0
- package/dist/src/overrides/Platform.macos.d.ts.map +1 -0
- package/dist/src/overrides/Platform.macos.js +15 -0
- package/dist/src/overrides/Platform.macos.js.map +1 -0
- package/dist/src/overrides/Platform.windows.d.ts +10 -0
- package/dist/src/overrides/Platform.windows.d.ts.map +1 -0
- package/dist/src/overrides/Platform.windows.js +15 -0
- package/dist/src/overrides/Platform.windows.js.map +1 -0
- package/dist/src/overrides/ReactDevToolsSettingsManager.d.ts +24 -0
- package/dist/src/overrides/ReactDevToolsSettingsManager.d.ts.map +1 -0
- package/dist/src/overrides/ReactDevToolsSettingsManager.js +30 -0
- package/dist/src/overrides/ReactDevToolsSettingsManager.js.map +1 -0
- package/dist/src/overrides/RefreshControl.d.ts +52 -0
- package/dist/src/overrides/RefreshControl.d.ts.map +1 -0
- package/dist/src/overrides/RefreshControl.js +92 -0
- package/dist/src/overrides/RefreshControl.js.map +1 -0
- package/dist/src/overrides/ScrollView.d.ts +39 -0
- package/dist/src/overrides/ScrollView.d.ts.map +1 -0
- package/dist/src/overrides/ScrollView.js +59 -0
- package/dist/src/overrides/ScrollView.js.map +1 -0
- package/dist/src/overrides/Share.d.ts +96 -0
- package/dist/src/overrides/Share.d.ts.map +1 -0
- package/dist/src/overrides/Share.js +97 -0
- package/dist/src/overrides/Share.js.map +1 -0
- package/dist/src/overrides/TextInput.d.ts +81 -0
- package/dist/src/overrides/TextInput.d.ts.map +1 -0
- package/dist/src/overrides/TextInput.js +213 -0
- package/dist/src/overrides/TextInput.js.map +1 -0
- package/dist/src/overrides/View.d.ts +36 -0
- package/dist/src/overrides/View.d.ts.map +1 -0
- package/dist/src/overrides/View.js +99 -0
- package/dist/src/overrides/View.js.map +1 -0
- package/dist/src/overrides/createPlatform.d.ts +32 -0
- package/dist/src/overrides/createPlatform.d.ts.map +1 -0
- package/dist/src/overrides/createPlatform.js +84 -0
- package/dist/src/overrides/createPlatform.js.map +1 -0
- package/dist/src/overrides/setUpDeveloperTools.d.ts +28 -0
- package/dist/src/overrides/setUpDeveloperTools.d.ts.map +1 -0
- package/dist/src/overrides/setUpDeveloperTools.js +84 -0
- package/dist/src/overrides/setUpDeveloperTools.js.map +1 -0
- package/dist/src/overrides/setUpXHR.d.ts +46 -0
- package/dist/src/overrides/setUpXHR.d.ts.map +1 -0
- package/dist/src/overrides/setUpXHR.js +236 -0
- package/dist/src/overrides/setUpXHR.js.map +1 -0
- package/dist/src/quitRequest.d.ts +55 -0
- package/dist/src/quitRequest.d.ts.map +1 -0
- package/dist/src/quitRequest.js +121 -0
- package/dist/src/quitRequest.js.map +1 -0
- package/dist/src/resourcePath.d.ts +18 -0
- package/dist/src/resourcePath.d.ts.map +1 -0
- package/dist/src/resourcePath.js +31 -0
- package/dist/src/resourcePath.js.map +1 -0
- package/dist/src/responseBody.d.ts +76 -0
- package/dist/src/responseBody.d.ts.map +1 -0
- package/dist/src/responseBody.js +94 -0
- package/dist/src/responseBody.js.map +1 -0
- package/dist/src/responseHeaders.d.ts +40 -0
- package/dist/src/responseHeaders.d.ts.map +1 -0
- package/dist/src/responseHeaders.js +75 -0
- package/dist/src/responseHeaders.js.map +1 -0
- package/dist/src/titleBarState.d.ts +43 -0
- package/dist/src/titleBarState.d.ts.map +1 -0
- package/dist/src/titleBarState.js +77 -0
- package/dist/src/titleBarState.js.map +1 -0
- package/dist/src/useContextMenu.d.ts +113 -0
- package/dist/src/useContextMenu.d.ts.map +1 -0
- package/dist/src/useContextMenu.js +109 -0
- package/dist/src/useContextMenu.js.map +1 -0
- package/dist/src/useDialog.d.ts +98 -0
- package/dist/src/useDialog.d.ts.map +1 -0
- package/dist/src/useDialog.js +112 -0
- package/dist/src/useDialog.js.map +1 -0
- package/dist/src/useDisplays.d.ts +70 -0
- package/dist/src/useDisplays.d.ts.map +1 -0
- package/dist/src/useDisplays.js +118 -0
- package/dist/src/useDisplays.js.map +1 -0
- package/dist/src/useHandledKeys.d.ts +38 -0
- package/dist/src/useHandledKeys.d.ts.map +1 -0
- package/dist/src/useHandledKeys.js +70 -0
- package/dist/src/useHandledKeys.js.map +1 -0
- package/dist/src/useWindow.d.ts +140 -0
- package/dist/src/useWindow.d.ts.map +1 -0
- package/dist/src/useWindow.js +233 -0
- package/dist/src/useWindow.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/native/CMakeLists.txt +355 -0
- package/native/bootstrap.sh +613 -0
- package/native/cmake/CompilerFlags.cmake +49 -0
- package/native/cmake/Expo.cmake +125 -0
- package/native/cmake/ReactNativeCore.cmake +612 -0
- package/native/cmake/Reanimated.cmake +108 -0
- package/native/cmake/Skia.cmake +379 -0
- package/native/cmake/ThirdParty.cmake +290 -0
- package/native/cmake/Worklets.cmake +67 -0
- package/native/cmake/codegen/CMakeLists.txt +32 -0
- package/native/core/AppIdentity.cpp +85 -0
- package/native/core/AppIdentity.h +59 -0
- package/native/core/AppPaths.cpp +96 -0
- package/native/core/AppPaths.h +53 -0
- package/native/core/AppearanceModule.cpp +60 -0
- package/native/core/AppearanceModule.h +40 -0
- package/native/core/Backface.h +59 -0
- package/native/core/BlobModule.cpp +283 -0
- package/native/core/BlobModule.h +76 -0
- package/native/core/BlobRegistry.cpp +75 -0
- package/native/core/BlobRegistry.h +44 -0
- package/native/core/ColorScheme.cpp +105 -0
- package/native/core/ColorScheme.h +59 -0
- package/native/core/ComponentRegistry.h +30 -0
- package/native/core/ControlMetrics.h +37 -0
- package/native/core/CoreModules.cpp +592 -0
- package/native/core/CoreModules.h +308 -0
- package/native/core/DebuggingOverlay.cpp +106 -0
- package/native/core/DebuggingOverlay.h +65 -0
- package/native/core/DesktopControls.cpp +232 -0
- package/native/core/DesktopControls.h +170 -0
- package/native/core/DevBundle.cpp +108 -0
- package/native/core/DevBundle.h +69 -0
- package/native/core/DevMenu.cpp +99 -0
- package/native/core/DevMenu.h +75 -0
- package/native/core/DialogModule.cpp +150 -0
- package/native/core/DialogModule.h +51 -0
- package/native/core/DragAndDrop.cpp +45 -0
- package/native/core/DragAndDrop.h +225 -0
- package/native/core/ExpoImageComponent.cpp +79 -0
- package/native/core/ExpoImageComponent.h +80 -0
- package/native/core/ExpoModules.cpp +415 -0
- package/native/core/ExpoModules.h +115 -0
- package/native/core/ExpoRuntime.cpp +366 -0
- package/native/core/ExpoRuntime.h +42 -0
- package/native/core/FocusRing.h +36 -0
- package/native/core/FontRegistry.h +51 -0
- package/native/core/GestureHandlerModule.cpp +136 -0
- package/native/core/GestureHandlerModule.h +71 -0
- package/native/core/Gestures.cpp +533 -0
- package/native/core/Gestures.h +145 -0
- package/native/core/HoverTracker.cpp +69 -0
- package/native/core/HoverTracker.h +109 -0
- package/native/core/HttpClient.cpp +282 -0
- package/native/core/ImageBytes.cpp +205 -0
- package/native/core/ImageBytes.h +29 -0
- package/native/core/ImageCache.cpp +51 -0
- package/native/core/ImageCache.h +89 -0
- package/native/core/JsRuntimeAccess.cpp +70 -0
- package/native/core/JsRuntimeAccess.h +60 -0
- package/native/core/JsiPromise.h +51 -0
- package/native/core/KeyEvents.cpp +116 -0
- package/native/core/KeyEvents.h +144 -0
- package/native/core/LogBoxSurface.cpp +46 -0
- package/native/core/LogBoxSurface.h +68 -0
- package/native/core/MenuModel.h +117 -0
- package/native/core/MenuModule.cpp +209 -0
- package/native/core/MenuModule.h +66 -0
- package/native/core/MountingWalk.h +524 -0
- package/native/core/PackageModules.cpp.in +25 -0
- package/native/core/PackageModules.h +50 -0
- package/native/core/PlatformConstantsModule.cpp +63 -0
- package/native/core/PlatformConstantsModule.h +64 -0
- package/native/core/PlatformServices.h +213 -0
- package/native/core/PointerButtons.h +63 -0
- package/native/core/PullToRefresh.cpp +57 -0
- package/native/core/PullToRefresh.h +73 -0
- package/native/core/ReanimatedCompat.h +47 -0
- package/native/core/ReanimatedModule.cpp +203 -0
- package/native/core/ReanimatedModule.h +55 -0
- package/native/core/ScrollAnimation.cpp +59 -0
- package/native/core/ScrollAnimation.h +70 -0
- package/native/core/ScrollBounds.cpp +26 -0
- package/native/core/ScrollBounds.h +68 -0
- package/native/core/ScrollIndicator.cpp +50 -0
- package/native/core/ScrollIndicator.h +69 -0
- package/native/core/ScrollMomentum.cpp +71 -0
- package/native/core/ScrollMomentum.h +73 -0
- package/native/core/ScrollSnap.cpp +123 -0
- package/native/core/ScrollSnap.h +80 -0
- package/native/core/ShareFallback.cpp +101 -0
- package/native/core/ShareFallback.h +45 -0
- package/native/core/SkiaPictureViewComponent.cpp +11 -0
- package/native/core/SkiaPictureViewComponent.h +47 -0
- package/native/core/SourceCodeModule.cpp +55 -0
- package/native/core/SourceCodeModule.h +53 -0
- package/native/core/StatusBarModule.cpp +23 -0
- package/native/core/StatusBarModule.h +42 -0
- package/native/core/TestDialog.cpp +148 -0
- package/native/core/TestDialog.h +96 -0
- package/native/core/TestKeys.cpp +78 -0
- package/native/core/TestKeys.h +50 -0
- package/native/core/TestQuitFile.cpp +33 -0
- package/native/core/TestQuitFile.h +60 -0
- package/native/core/TestSettle.h +192 -0
- package/native/core/TitleBarRegions.h +31 -0
- package/native/core/TurboModuleProxy.cpp +51 -0
- package/native/core/TurboModuleProxy.h +46 -0
- package/native/core/UIManagerAccess.cpp +43 -0
- package/native/core/UIManagerAccess.h +43 -0
- package/native/core/WindowBoundsCache.cpp +319 -0
- package/native/core/WindowControl.h +235 -0
- package/native/core/WindowHost.h +158 -0
- package/native/core/WindowMethods.cpp +167 -0
- package/native/core/WindowMethods.h +84 -0
- package/native/core/WindowsModule.cpp +448 -0
- package/native/core/WindowsModule.h +133 -0
- package/native/core/WorkletsModule.cpp +199 -0
- package/native/core/WorkletsModule.h +57 -0
- package/native/core/portability_probe.cpp +210 -0
- package/native/tests/EventRecorder.h +124 -0
- package/native/tests/TestHarness.cpp +109 -0
- package/native/tests/TestHarness.h +89 -0
- package/native/tests/TreeDump.h +49 -0
- package/native/tests/test_app_identity.cpp +114 -0
- package/native/tests/test_app_paths.cpp +48 -0
- package/native/tests/test_appearance.cpp +107 -0
- package/native/tests/test_backface.cpp +79 -0
- package/native/tests/test_blobs.cpp +157 -0
- package/native/tests/test_controls.cpp +185 -0
- package/native/tests/test_devbundle.cpp +103 -0
- package/native/tests/test_drag_and_drop.cpp +143 -0
- package/native/tests/test_gestures.cpp +331 -0
- package/native/tests/test_hover.cpp +92 -0
- package/native/tests/test_image_cache.cpp +109 -0
- package/native/tests/test_js_runtime_access.cpp +137 -0
- package/native/tests/test_key_events.cpp +235 -0
- package/native/tests/test_momentum.cpp +138 -0
- package/native/tests/test_quit_file.cpp +104 -0
- package/native/tests/test_scroll_animation.cpp +120 -0
- package/native/tests/test_scroll_bounds.cpp +66 -0
- package/native/tests/test_scroll_indicator.cpp +149 -0
- package/native/tests/test_scroll_snap.cpp +112 -0
- package/native/tests/test_settle.cpp +115 -0
- package/native/tests/test_share.cpp +75 -0
- package/native/tests/test_sourcecode.cpp +62 -0
- package/native/tests/test_window_close.cpp +119 -0
- package/native/tests/test_window_limits.cpp +123 -0
- package/package.json +43 -0
- package/react-native.config.js +86 -0
- package/supported-versions.json +66 -0
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The application menu.
|
|
3
|
+
*
|
|
4
|
+
* <Menu>
|
|
5
|
+
* <Menu.Submenu label="File">
|
|
6
|
+
* <Menu.Item label="Open…" accelerator="CmdOrCtrl+O" onClick={open} />
|
|
7
|
+
* <Menu.Separator />
|
|
8
|
+
* <Menu.Item role="close" />
|
|
9
|
+
* </Menu.Submenu>
|
|
10
|
+
* <Menu.Submenu label="Edit">
|
|
11
|
+
* <Menu.Item role="undo" />
|
|
12
|
+
* <Menu.Item role="copy" />
|
|
13
|
+
* <Menu.Item role="paste" />
|
|
14
|
+
* </Menu.Submenu>
|
|
15
|
+
* </Menu>
|
|
16
|
+
*
|
|
17
|
+
* Declarative because a menu bar is state, not a command: it is on screen for
|
|
18
|
+
* as long as the component is mounted, and unmounting restores whatever the
|
|
19
|
+
* platform's default was. `<Menu>` renders nothing.
|
|
20
|
+
*
|
|
21
|
+
* ## Roles
|
|
22
|
+
*
|
|
23
|
+
* An item with a `role` is one the platform implements itself, and it needs no
|
|
24
|
+
* `onClick` and no label -- it gets the platform's own word and the platform's
|
|
25
|
+
* own shortcut. The names are Electron's: about, quit, undo, redo, cut, copy,
|
|
26
|
+
* paste, delete, selectAll, minimize, zoom, close, togglefullscreen.
|
|
27
|
+
*
|
|
28
|
+
* Roles are not a convenience. On macOS AppKit routes every key equivalent
|
|
29
|
+
* through the main menu before anything else sees it, so `role="copy"` is what
|
|
30
|
+
* makes Cmd-C reach a text field at all -- and an app that never renders a
|
|
31
|
+
* <Menu> gets an Edit menu anyway, for exactly that reason.
|
|
32
|
+
*
|
|
33
|
+
* ## Where there is no menu bar
|
|
34
|
+
*
|
|
35
|
+
* `Menu.isSupported` is false on Linux, and that is not a gap waiting to be
|
|
36
|
+
* filled: GNOME's guidelines have said to use a header bar with a menu button
|
|
37
|
+
* since GNOME 3, and GTK4 removed the menu bar widget. An app that cares can
|
|
38
|
+
* ask and put its commands in its own header with <TitleBar>. An app that does
|
|
39
|
+
* not is no worse off -- the description is simply not shown.
|
|
40
|
+
*
|
|
41
|
+
* @format
|
|
42
|
+
*/
|
|
43
|
+
import * as React from 'react';
|
|
44
|
+
/** One of the role names in `native/core/MenuModel.h`. */
|
|
45
|
+
export type MenuRole = string;
|
|
46
|
+
export type MenuItemProps = {
|
|
47
|
+
label?: string;
|
|
48
|
+
/** Handled by the platform, and never reported back. See the header. */
|
|
49
|
+
role?: MenuRole;
|
|
50
|
+
/** "CmdOrCtrl+O", in Electron's spelling. Ignored for a role. */
|
|
51
|
+
accelerator?: string;
|
|
52
|
+
enabled?: boolean;
|
|
53
|
+
onClick?: () => void;
|
|
54
|
+
};
|
|
55
|
+
export type MenuSubmenuProps = {
|
|
56
|
+
label?: string;
|
|
57
|
+
enabled?: boolean;
|
|
58
|
+
children?: React.ReactNode;
|
|
59
|
+
};
|
|
60
|
+
/** Whether this platform shows an application menu at all. See the header. */
|
|
61
|
+
export declare const isSupported: boolean;
|
|
62
|
+
export type MenuProps = {
|
|
63
|
+
children?: React.ReactNode;
|
|
64
|
+
};
|
|
65
|
+
export declare function Menu({ children }: MenuProps): null;
|
|
66
|
+
export declare namespace Menu {
|
|
67
|
+
var Item: (_props: MenuItemProps) => null;
|
|
68
|
+
var Separator: () => null;
|
|
69
|
+
var Submenu: (_props: MenuSubmenuProps) => null;
|
|
70
|
+
var isSupported: boolean;
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=Menu.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Menu.d.ts","sourceRoot":"","sources":["../../src/Menu.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AAEH,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAI/B,0DAA0D;AAC1D,MAAM,MAAM,QAAQ,GAAG,MAAM,CAAC;AAE9B,MAAM,MAAM,aAAa,GAAG;IAC1B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,wEAAwE;IACxE,IAAI,CAAC,EAAE,QAAQ,CAAC;IAChB,iEAAiE;IACjE,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG;IAC7B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;CAC5B,CAAC;AA6BF,8EAA8E;AAC9E,eAAO,MAAM,WAAW,SAAuC,CAAC;AAoEhE,MAAM,MAAM,SAAS,GAAG;IAAC,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;CAAC,CAAC;AAErD,wBAAgB,IAAI,CAAC,EAAC,QAAQ,EAAC,EAAE,SAAS,GAAG,IAAI,CAgChD;yBAhCe,IAAI;uBAZE,aAAa,KAAG,IAAI;yBAGpB,IAAI;0BAGD,gBAAgB,KAAG,IAAI"}
|
package/dist/src/Menu.js
ADDED
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* The application menu.
|
|
4
|
+
*
|
|
5
|
+
* <Menu>
|
|
6
|
+
* <Menu.Submenu label="File">
|
|
7
|
+
* <Menu.Item label="Open…" accelerator="CmdOrCtrl+O" onClick={open} />
|
|
8
|
+
* <Menu.Separator />
|
|
9
|
+
* <Menu.Item role="close" />
|
|
10
|
+
* </Menu.Submenu>
|
|
11
|
+
* <Menu.Submenu label="Edit">
|
|
12
|
+
* <Menu.Item role="undo" />
|
|
13
|
+
* <Menu.Item role="copy" />
|
|
14
|
+
* <Menu.Item role="paste" />
|
|
15
|
+
* </Menu.Submenu>
|
|
16
|
+
* </Menu>
|
|
17
|
+
*
|
|
18
|
+
* Declarative because a menu bar is state, not a command: it is on screen for
|
|
19
|
+
* as long as the component is mounted, and unmounting restores whatever the
|
|
20
|
+
* platform's default was. `<Menu>` renders nothing.
|
|
21
|
+
*
|
|
22
|
+
* ## Roles
|
|
23
|
+
*
|
|
24
|
+
* An item with a `role` is one the platform implements itself, and it needs no
|
|
25
|
+
* `onClick` and no label -- it gets the platform's own word and the platform's
|
|
26
|
+
* own shortcut. The names are Electron's: about, quit, undo, redo, cut, copy,
|
|
27
|
+
* paste, delete, selectAll, minimize, zoom, close, togglefullscreen.
|
|
28
|
+
*
|
|
29
|
+
* Roles are not a convenience. On macOS AppKit routes every key equivalent
|
|
30
|
+
* through the main menu before anything else sees it, so `role="copy"` is what
|
|
31
|
+
* makes Cmd-C reach a text field at all -- and an app that never renders a
|
|
32
|
+
* <Menu> gets an Edit menu anyway, for exactly that reason.
|
|
33
|
+
*
|
|
34
|
+
* ## Where there is no menu bar
|
|
35
|
+
*
|
|
36
|
+
* `Menu.isSupported` is false on Linux, and that is not a gap waiting to be
|
|
37
|
+
* filled: GNOME's guidelines have said to use a header bar with a menu button
|
|
38
|
+
* since GNOME 3, and GTK4 removed the menu bar widget. An app that cares can
|
|
39
|
+
* ask and put its commands in its own header with <TitleBar>. An app that does
|
|
40
|
+
* not is no worse off -- the description is simply not shown.
|
|
41
|
+
*
|
|
42
|
+
* @format
|
|
43
|
+
*/
|
|
44
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
45
|
+
if (k2 === undefined) k2 = k;
|
|
46
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
47
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
48
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
49
|
+
}
|
|
50
|
+
Object.defineProperty(o, k2, desc);
|
|
51
|
+
}) : (function(o, m, k, k2) {
|
|
52
|
+
if (k2 === undefined) k2 = k;
|
|
53
|
+
o[k2] = m[k];
|
|
54
|
+
}));
|
|
55
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
56
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
57
|
+
}) : function(o, v) {
|
|
58
|
+
o["default"] = v;
|
|
59
|
+
});
|
|
60
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
61
|
+
var ownKeys = function(o) {
|
|
62
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
63
|
+
var ar = [];
|
|
64
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
65
|
+
return ar;
|
|
66
|
+
};
|
|
67
|
+
return ownKeys(o);
|
|
68
|
+
};
|
|
69
|
+
return function (mod) {
|
|
70
|
+
if (mod && mod.__esModule) return mod;
|
|
71
|
+
var result = {};
|
|
72
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
73
|
+
__setModuleDefault(result, mod);
|
|
74
|
+
return result;
|
|
75
|
+
};
|
|
76
|
+
})();
|
|
77
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
78
|
+
exports.isSupported = void 0;
|
|
79
|
+
exports.Menu = Menu;
|
|
80
|
+
const React = __importStar(require("react"));
|
|
81
|
+
const react_native_1 = require("react-native");
|
|
82
|
+
const NativeMenu = react_native_1.TurboModuleRegistry.get('BasaltMenu');
|
|
83
|
+
// Must match kMenuChosenEvent in native/core/MenuModule.h.
|
|
84
|
+
const CHOSEN_EVENT = 'basaltMenuItemChosen';
|
|
85
|
+
/** Whether this platform shows an application menu at all. See the header. */
|
|
86
|
+
exports.isSupported = NativeMenu?.isSupported?.() === true;
|
|
87
|
+
// Every `onClick` in the tree, by the id the native side reports back. Ids are
|
|
88
|
+
// assigned here rather than by the app: an app numbering its own items would be
|
|
89
|
+
// an app with two items numbered 3.
|
|
90
|
+
let nextId = 1;
|
|
91
|
+
function describe(children, handlers) {
|
|
92
|
+
const items = [];
|
|
93
|
+
React.Children.forEach(children, rawChild => {
|
|
94
|
+
if (rawChild == null || typeof rawChild !== 'object') {
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
// `React.Children.forEach` types its argument as ReactNode; everything
|
|
98
|
+
// below only makes sense for an element, and anything else is skipped by
|
|
99
|
+
// the type checks that follow.
|
|
100
|
+
const child = rawChild;
|
|
101
|
+
const { kind, label, role, accelerator, enabled, onClick } = child.props ?? {};
|
|
102
|
+
if (child.type === Separator) {
|
|
103
|
+
items.push({ separator: true });
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
if (child.type === Submenu) {
|
|
107
|
+
items.push({
|
|
108
|
+
label: label ?? '',
|
|
109
|
+
enabled: enabled !== false,
|
|
110
|
+
submenu: describe(child.props.children, handlers),
|
|
111
|
+
});
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
if (child.type !== Item) {
|
|
115
|
+
// Anything else in a <Menu> is a mistake rather than a thing to render:
|
|
116
|
+
// there is nowhere for it to go.
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
const item = {
|
|
120
|
+
label: label ?? '',
|
|
121
|
+
role: role ?? '',
|
|
122
|
+
accelerator: accelerator ?? '',
|
|
123
|
+
enabled: enabled !== false,
|
|
124
|
+
id: 0,
|
|
125
|
+
};
|
|
126
|
+
// A role is handled by the platform and never comes back, so it needs no
|
|
127
|
+
// id and no handler. See the header.
|
|
128
|
+
if (!role && typeof onClick === 'function') {
|
|
129
|
+
item.id = nextId++;
|
|
130
|
+
handlers.set(item.id, onClick);
|
|
131
|
+
}
|
|
132
|
+
items.push(item);
|
|
133
|
+
void kind;
|
|
134
|
+
});
|
|
135
|
+
return items;
|
|
136
|
+
}
|
|
137
|
+
function Item(_props) {
|
|
138
|
+
return null;
|
|
139
|
+
}
|
|
140
|
+
function Separator() {
|
|
141
|
+
return null;
|
|
142
|
+
}
|
|
143
|
+
function Submenu(_props) {
|
|
144
|
+
return null;
|
|
145
|
+
}
|
|
146
|
+
function Menu({ children }) {
|
|
147
|
+
const handlers = React.useRef(new Map());
|
|
148
|
+
// Described during render rather than in the effect, so that the effect's
|
|
149
|
+
// dependency is the menu itself: a menu whose labels did not change should
|
|
150
|
+
// not be reinstalled, and reinstalling one closes it if it happens to be open.
|
|
151
|
+
const items = React.useMemo(() => {
|
|
152
|
+
handlers.current = new Map();
|
|
153
|
+
return describe(children, handlers.current);
|
|
154
|
+
}, [children]);
|
|
155
|
+
const serialised = React.useMemo(() => JSON.stringify(items), [items]);
|
|
156
|
+
React.useEffect(() => {
|
|
157
|
+
NativeMenu?.setApplicationMenu?.(JSON.parse(serialised));
|
|
158
|
+
return () => {
|
|
159
|
+
// Back to the platform's default, which on macOS is the minimum an
|
|
160
|
+
// application needs to be usable -- an Edit menu included.
|
|
161
|
+
NativeMenu?.setApplicationMenu?.([]);
|
|
162
|
+
};
|
|
163
|
+
}, [serialised]);
|
|
164
|
+
React.useEffect(() => {
|
|
165
|
+
const subscription = react_native_1.DeviceEventEmitter.addListener(CHOSEN_EVENT, (id) => {
|
|
166
|
+
const onClick = handlers.current.get(id);
|
|
167
|
+
if (onClick != null) {
|
|
168
|
+
onClick();
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
return () => subscription.remove();
|
|
172
|
+
}, []);
|
|
173
|
+
return null;
|
|
174
|
+
}
|
|
175
|
+
Menu.Item = Item;
|
|
176
|
+
Menu.Separator = Separator;
|
|
177
|
+
Menu.Submenu = Submenu;
|
|
178
|
+
Menu.isSupported = exports.isSupported;
|
|
179
|
+
//# sourceMappingURL=Menu.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Menu.js","sourceRoot":"","sources":["../../src/Menu.tsx"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2HH,oBAgCC;AAzJD,6CAA+B;AAE/B,+CAAqE;AA2CrE,MAAM,UAAU,GAAG,kCAAmB,CAAC,GAAG,CAAmB,YAAY,CAAC,CAAC;AAE3E,2DAA2D;AAC3D,MAAM,YAAY,GAAG,sBAAsB,CAAC;AAE5C,8EAA8E;AACjE,QAAA,WAAW,GAAG,UAAU,EAAE,WAAW,EAAE,EAAE,KAAK,IAAI,CAAC;AAEhE,+EAA+E;AAC/E,gFAAgF;AAChF,oCAAoC;AACpC,IAAI,MAAM,GAAG,CAAC,CAAC;AAEf,SAAS,QAAQ,CAAC,QAAyB,EAAE,QAAsB;IACjE,MAAM,KAAK,GAAoB,EAAE,CAAC;IAClC,KAAK,CAAC,QAAQ,CAAC,OAAO,CAAC,QAAQ,EAAE,QAAQ,CAAC,EAAE;QAC1C,IAAI,QAAQ,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EAAE;QACnB,MAAM,YAAY,GAAG,iCAAkB,CAAC,WAAW,CAAC,YAAY,EAAE,CAAC,EAAU,EAAE,EAAE;YAC/E,MAAM,OAAO,GAAG,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;YACzC,IAAI,OAAO,IAAI,IAAI,EAAE,CAAC;gBACpB,OAAO,EAAE,CAAC;YACZ,CAAC;QACH,CAAC,CAAC,CAAC;QACH,OAAO,GAAG,EAAE,CAAC,YAAY,CAAC,MAAM,EAAE,CAAC;IACrC,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,OAAO,IAAI,CAAC;AACd,CAAC;AAED,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;AACjB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;AAC3B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;AACvB,IAAI,CAAC,WAAW,GAAG,mBAAW,CAAC"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The window's title bar: its title, its colours, and whether the host draws
|
|
3
|
+
* it or the app does.
|
|
4
|
+
*
|
|
5
|
+
* useTitleBar({title, backgroundColor, textColor, borderColor, style})
|
|
6
|
+
* <TitleBar title="Inbox" backgroundColor="#1f1f1f" textColor="#fff" />
|
|
7
|
+
*
|
|
8
|
+
* `style: 'native'` (the default) keeps the system's title bar and colours it.
|
|
9
|
+
* `style: 'hidden'` removes it: the app's own content reaches the top of the
|
|
10
|
+
* window, the host still draws the minimise, maximise and close buttons over
|
|
11
|
+
* the top right corner, and the app says which parts of its header drag the
|
|
12
|
+
* window:
|
|
13
|
+
*
|
|
14
|
+
* Window.minimize(); Window.toggleMaximize(); Window.close();
|
|
15
|
+
*
|
|
16
|
+
* const {height, buttonsWidth} = useTitleBarMetrics();
|
|
17
|
+
* <TitleBar.DragRegion style={{height, paddingRight: buttonsWidth}}>
|
|
18
|
+
* <Text>Inbox</Text>
|
|
19
|
+
* <TitleBar.NoDragRegion><Button title="Compose" /></TitleBar.NoDragRegion>
|
|
20
|
+
* </TitleBar.DragRegion>
|
|
21
|
+
*
|
|
22
|
+
* Requests stack like <StatusBar>'s: the most recently mounted wins, key by key,
|
|
23
|
+
* and unmounting one restores what was beneath it. See titleBarState.ts.
|
|
24
|
+
*
|
|
25
|
+
* All three hosts have a title bar module. The calls are guarded regardless:
|
|
26
|
+
* on a host without one -- or before it has registered -- every call is
|
|
27
|
+
* ignored and the metrics are all zero, so the same code runs everywhere.
|
|
28
|
+
*
|
|
29
|
+
* `<TitleBar.DragRegion>` is where the three are not yet equal. Windows and
|
|
30
|
+
* GTK read the marks and drag the window from them; macOS does not read them
|
|
31
|
+
* yet, so a header an app drew there shows correctly but does not move the
|
|
32
|
+
* window. See core/TitleBarRegions.h for the marks and the rule.
|
|
33
|
+
*
|
|
34
|
+
* @format
|
|
35
|
+
*/
|
|
36
|
+
import * as React from 'react';
|
|
37
|
+
import type { ViewProps } from 'react-native';
|
|
38
|
+
import type { TitleBarOptions, TitleBarStyle } from './titleBarState';
|
|
39
|
+
export type { TitleBarOptions, TitleBarStyle } from './titleBarState';
|
|
40
|
+
/** How much of the window a hidden title bar's caption takes, in layout units. */
|
|
41
|
+
export type TitleBarMetrics = {
|
|
42
|
+
height: number;
|
|
43
|
+
buttonsWidth: number;
|
|
44
|
+
style: TitleBarStyle;
|
|
45
|
+
};
|
|
46
|
+
export declare function useTitleBar(options?: TitleBarOptions | null): void;
|
|
47
|
+
export declare function TitleBar(props: TitleBarOptions): null;
|
|
48
|
+
export declare namespace TitleBar {
|
|
49
|
+
var DragRegion: (props: ViewProps) => React.ReactElement;
|
|
50
|
+
var NoDragRegion: (props: ViewProps) => React.ReactElement;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* What the caption buttons do, for an app drawing its own header.
|
|
54
|
+
*
|
|
55
|
+
* The system's buttons need none of this -- they are the system's -- but a
|
|
56
|
+
* header the app drew has no way to act on itself otherwise, which makes the
|
|
57
|
+
* hidden style a picture of a title bar rather than one.
|
|
58
|
+
*
|
|
59
|
+
* Every call is ignored on a host with no window module, like the rest of this
|
|
60
|
+
* file, so the same code runs everywhere.
|
|
61
|
+
*/
|
|
62
|
+
export declare const Window: {
|
|
63
|
+
minimize(): void;
|
|
64
|
+
toggleMaximize(): void;
|
|
65
|
+
close(): void;
|
|
66
|
+
/**
|
|
67
|
+
* Starts dragging the window, to be called from a press on an app-drawn
|
|
68
|
+
* caption. A no-op where the host moves windows some other way: GTK does it
|
|
69
|
+
* through a widget rather than a call, so the drag regions handle it and
|
|
70
|
+
* this has nothing to begin.
|
|
71
|
+
*/
|
|
72
|
+
startDrag(): void;
|
|
73
|
+
};
|
|
74
|
+
export declare function useTitleBarMetrics(): TitleBarMetrics;
|
|
75
|
+
//# sourceMappingURL=TitleBar.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TitleBar.d.ts","sourceRoot":"","sources":["../../src/TitleBar.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AAEH,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,KAAK,EAAc,SAAS,EAAC,MAAM,cAAc,CAAC;AAIzD,OAAO,KAAK,EAAgB,eAAe,EAAmB,aAAa,EAAC,MAAM,iBAAiB,CAAC;AAEpG,YAAY,EAAC,eAAe,EAAE,aAAa,EAAC,MAAM,iBAAiB,CAAC;AAwBpE,kFAAkF;AAClF,MAAM,MAAM,eAAe,GAAG;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,EAAE,MAAM,CAAC;IACrB,KAAK,EAAE,aAAa,CAAC;CACtB,CAAC;AA+EF,wBAAgB,WAAW,CAAC,OAAO,CAAC,EAAE,eAAe,GAAG,IAAI,GAAG,IAAI,CA2BlE;AAED,wBAAgB,QAAQ,CAAC,KAAK,EAAE,eAAe,GAAG,IAAI,CAGrD;yBAHe,QAAQ;4BAKG,SAAS,KAAG,KAAK,CAAC,YAAY;8BAI5B,SAAS,KAAG,KAAK,CAAC,YAAY;;AAkB3D;;;;;;;;;GASG;AACH,eAAO,MAAM,MAAM;;;;IAUjB;;;;;OAKG;;CAIJ,CAAC;AAMF,wBAAgB,kBAAkB,IAAI,eAAe,CAiBpD"}
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* The window's title bar: its title, its colours, and whether the host draws
|
|
4
|
+
* it or the app does.
|
|
5
|
+
*
|
|
6
|
+
* useTitleBar({title, backgroundColor, textColor, borderColor, style})
|
|
7
|
+
* <TitleBar title="Inbox" backgroundColor="#1f1f1f" textColor="#fff" />
|
|
8
|
+
*
|
|
9
|
+
* `style: 'native'` (the default) keeps the system's title bar and colours it.
|
|
10
|
+
* `style: 'hidden'` removes it: the app's own content reaches the top of the
|
|
11
|
+
* window, the host still draws the minimise, maximise and close buttons over
|
|
12
|
+
* the top right corner, and the app says which parts of its header drag the
|
|
13
|
+
* window:
|
|
14
|
+
*
|
|
15
|
+
* Window.minimize(); Window.toggleMaximize(); Window.close();
|
|
16
|
+
*
|
|
17
|
+
* const {height, buttonsWidth} = useTitleBarMetrics();
|
|
18
|
+
* <TitleBar.DragRegion style={{height, paddingRight: buttonsWidth}}>
|
|
19
|
+
* <Text>Inbox</Text>
|
|
20
|
+
* <TitleBar.NoDragRegion><Button title="Compose" /></TitleBar.NoDragRegion>
|
|
21
|
+
* </TitleBar.DragRegion>
|
|
22
|
+
*
|
|
23
|
+
* Requests stack like <StatusBar>'s: the most recently mounted wins, key by key,
|
|
24
|
+
* and unmounting one restores what was beneath it. See titleBarState.ts.
|
|
25
|
+
*
|
|
26
|
+
* All three hosts have a title bar module. The calls are guarded regardless:
|
|
27
|
+
* on a host without one -- or before it has registered -- every call is
|
|
28
|
+
* ignored and the metrics are all zero, so the same code runs everywhere.
|
|
29
|
+
*
|
|
30
|
+
* `<TitleBar.DragRegion>` is where the three are not yet equal. Windows and
|
|
31
|
+
* GTK read the marks and drag the window from them; macOS does not read them
|
|
32
|
+
* yet, so a header an app drew there shows correctly but does not move the
|
|
33
|
+
* window. See core/TitleBarRegions.h for the marks and the rule.
|
|
34
|
+
*
|
|
35
|
+
* @format
|
|
36
|
+
*/
|
|
37
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
38
|
+
if (k2 === undefined) k2 = k;
|
|
39
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
40
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
41
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
42
|
+
}
|
|
43
|
+
Object.defineProperty(o, k2, desc);
|
|
44
|
+
}) : (function(o, m, k, k2) {
|
|
45
|
+
if (k2 === undefined) k2 = k;
|
|
46
|
+
o[k2] = m[k];
|
|
47
|
+
}));
|
|
48
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
49
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
50
|
+
}) : function(o, v) {
|
|
51
|
+
o["default"] = v;
|
|
52
|
+
});
|
|
53
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
54
|
+
var ownKeys = function(o) {
|
|
55
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
56
|
+
var ar = [];
|
|
57
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
58
|
+
return ar;
|
|
59
|
+
};
|
|
60
|
+
return ownKeys(o);
|
|
61
|
+
};
|
|
62
|
+
return function (mod) {
|
|
63
|
+
if (mod && mod.__esModule) return mod;
|
|
64
|
+
var result = {};
|
|
65
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
66
|
+
__setModuleDefault(result, mod);
|
|
67
|
+
return result;
|
|
68
|
+
};
|
|
69
|
+
})();
|
|
70
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
71
|
+
exports.Window = void 0;
|
|
72
|
+
exports.useTitleBar = useTitleBar;
|
|
73
|
+
exports.TitleBar = TitleBar;
|
|
74
|
+
exports.useTitleBarMetrics = useTitleBarMetrics;
|
|
75
|
+
const React = __importStar(require("react"));
|
|
76
|
+
const react_native_1 = require("react-native");
|
|
77
|
+
const titleBarState_1 = require("./titleBarState");
|
|
78
|
+
const NativeWindow = react_native_1.TurboModuleRegistry.get('BasaltWindow');
|
|
79
|
+
const METRICS_EVENT = 'basaltTitleBarMetricsChanged';
|
|
80
|
+
// Must match kTitleBarDragRegionId and kTitleBarNoDragRegionId in
|
|
81
|
+
// core/TitleBarRegions.h, which is where the hosts read them from -- Win32
|
|
82
|
+
// through Win32TitleBarLayout.h and GTK through GtkTitleBarLayout.h. They were
|
|
83
|
+
// spelled in the Windows host alone when Windows was the only reader; that
|
|
84
|
+
// header now takes its values from core rather than repeating them, so these
|
|
85
|
+
// two literals are the only other copy.
|
|
86
|
+
const DRAG_REGION_ID = 'basalt-titlebar-drag';
|
|
87
|
+
const NO_DRAG_REGION_ID = 'basalt-titlebar-no-drag';
|
|
88
|
+
const NO_METRICS = Object.freeze({
|
|
89
|
+
height: 0,
|
|
90
|
+
buttonsWidth: 0,
|
|
91
|
+
style: 'native',
|
|
92
|
+
});
|
|
93
|
+
const stack = (0, titleBarState_1.createTitleBarStack)();
|
|
94
|
+
let applied = null;
|
|
95
|
+
// processColor turns any React Native colour into the 0xAARRGGBB number the
|
|
96
|
+
// host reads. Null, and anything it cannot process, asks for the system's
|
|
97
|
+
// colour back.
|
|
98
|
+
function colorFor(value) {
|
|
99
|
+
if (value == null) {
|
|
100
|
+
return null;
|
|
101
|
+
}
|
|
102
|
+
const processed = (0, react_native_1.processColor)(value);
|
|
103
|
+
return typeof processed === 'number' ? processed : null;
|
|
104
|
+
}
|
|
105
|
+
function normalizeMetrics(value) {
|
|
106
|
+
if (value == null) {
|
|
107
|
+
return NO_METRICS;
|
|
108
|
+
}
|
|
109
|
+
return {
|
|
110
|
+
height: value.height ?? 0,
|
|
111
|
+
buttonsWidth: value.buttonsWidth ?? 0,
|
|
112
|
+
style: value.style === 'hidden' ? 'hidden' : 'native',
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
function applyStack() {
|
|
116
|
+
if (NativeWindow == null) {
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
const request = stack.resolve();
|
|
120
|
+
if (applied != null && (0, titleBarState_1.sameRequest)(request, applied)) {
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
const previous = applied ?? {};
|
|
124
|
+
const first = applied == null;
|
|
125
|
+
applied = request;
|
|
126
|
+
if (first || request.title !== previous.title) {
|
|
127
|
+
// Null restores the window's default title, which is the app's name.
|
|
128
|
+
NativeWindow.setTitle(request.title == null ? null : String(request.title));
|
|
129
|
+
}
|
|
130
|
+
if (first ||
|
|
131
|
+
request.backgroundColor !== previous.backgroundColor ||
|
|
132
|
+
request.textColor !== previous.textColor ||
|
|
133
|
+
request.borderColor !== previous.borderColor) {
|
|
134
|
+
NativeWindow.setTitleBarColors(colorFor(request.backgroundColor), colorFor(request.textColor), colorFor(request.borderColor));
|
|
135
|
+
}
|
|
136
|
+
if (first || request.style !== previous.style) {
|
|
137
|
+
NativeWindow.setTitleBarStyle(request.style === 'hidden' ? 'hidden' : 'native');
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
function useTitleBar(options) {
|
|
141
|
+
const { title, style, backgroundColor, textColor, borderColor } = options ?? {};
|
|
142
|
+
const idRef = React.useRef(null);
|
|
143
|
+
// Mount and unmount. Layout effects, so a hidden title bar is in place before
|
|
144
|
+
// the first frame is painted rather than one frame after it.
|
|
145
|
+
React.useLayoutEffect(() => {
|
|
146
|
+
const id = stack.push({ title, style, backgroundColor, textColor, borderColor });
|
|
147
|
+
idRef.current = id;
|
|
148
|
+
applyStack();
|
|
149
|
+
return () => {
|
|
150
|
+
stack.remove(id);
|
|
151
|
+
idRef.current = null;
|
|
152
|
+
applyStack();
|
|
153
|
+
};
|
|
154
|
+
// Changes arrive through the effect below; this one only enters and leaves
|
|
155
|
+
// the stack.
|
|
156
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
157
|
+
}, []);
|
|
158
|
+
React.useLayoutEffect(() => {
|
|
159
|
+
if (idRef.current == null) {
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
stack.update(idRef.current, { title, style, backgroundColor, textColor, borderColor });
|
|
163
|
+
applyStack();
|
|
164
|
+
}, [title, style, backgroundColor, textColor, borderColor]);
|
|
165
|
+
}
|
|
166
|
+
function TitleBar(props) {
|
|
167
|
+
useTitleBar(props);
|
|
168
|
+
return null;
|
|
169
|
+
}
|
|
170
|
+
function DragRegion(props) {
|
|
171
|
+
return React.createElement(react_native_1.View, { ...props, nativeID: DRAG_REGION_ID });
|
|
172
|
+
}
|
|
173
|
+
function NoDragRegion(props) {
|
|
174
|
+
return React.createElement(react_native_1.View, { ...props, nativeID: NO_DRAG_REGION_ID });
|
|
175
|
+
}
|
|
176
|
+
TitleBar.DragRegion = DragRegion;
|
|
177
|
+
TitleBar.NoDragRegion = NoDragRegion;
|
|
178
|
+
function readMetrics() {
|
|
179
|
+
if (NativeWindow == null) {
|
|
180
|
+
return NO_METRICS;
|
|
181
|
+
}
|
|
182
|
+
try {
|
|
183
|
+
return normalizeMetrics(NativeWindow.getTitleBarMetrics());
|
|
184
|
+
}
|
|
185
|
+
catch {
|
|
186
|
+
return NO_METRICS;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* What the caption buttons do, for an app drawing its own header.
|
|
191
|
+
*
|
|
192
|
+
* The system's buttons need none of this -- they are the system's -- but a
|
|
193
|
+
* header the app drew has no way to act on itself otherwise, which makes the
|
|
194
|
+
* hidden style a picture of a title bar rather than one.
|
|
195
|
+
*
|
|
196
|
+
* Every call is ignored on a host with no window module, like the rest of this
|
|
197
|
+
* file, so the same code runs everywhere.
|
|
198
|
+
*/
|
|
199
|
+
exports.Window = {
|
|
200
|
+
minimize() {
|
|
201
|
+
NativeWindow?.minimize();
|
|
202
|
+
},
|
|
203
|
+
toggleMaximize() {
|
|
204
|
+
NativeWindow?.toggleMaximize();
|
|
205
|
+
},
|
|
206
|
+
close() {
|
|
207
|
+
NativeWindow?.close();
|
|
208
|
+
},
|
|
209
|
+
/**
|
|
210
|
+
* Starts dragging the window, to be called from a press on an app-drawn
|
|
211
|
+
* caption. A no-op where the host moves windows some other way: GTK does it
|
|
212
|
+
* through a widget rather than a call, so the drag regions handle it and
|
|
213
|
+
* this has nothing to begin.
|
|
214
|
+
*/
|
|
215
|
+
startDrag() {
|
|
216
|
+
NativeWindow?.startWindowDrag();
|
|
217
|
+
},
|
|
218
|
+
};
|
|
219
|
+
// How much of the window a hidden title bar's caption takes: its height, and
|
|
220
|
+
// the width of the buttons in the top right corner, both in layout units. All
|
|
221
|
+
// zero while the title bar is native. Updates when the style changes, the
|
|
222
|
+
// window moves to a display with a different DPI, or it is maximised.
|
|
223
|
+
function useTitleBarMetrics() {
|
|
224
|
+
const [metrics, setMetrics] = React.useState(readMetrics);
|
|
225
|
+
React.useEffect(() => {
|
|
226
|
+
if (NativeWindow == null) {
|
|
227
|
+
return undefined;
|
|
228
|
+
}
|
|
229
|
+
const subscription = react_native_1.DeviceEventEmitter.addListener(METRICS_EVENT, (next) => setMetrics(normalizeMetrics(next)));
|
|
230
|
+
// Anything that changed between the first render and subscribing.
|
|
231
|
+
setMetrics(readMetrics());
|
|
232
|
+
return () => subscription.remove();
|
|
233
|
+
}, []);
|
|
234
|
+
return metrics;
|
|
235
|
+
}
|
|
236
|
+
//# sourceMappingURL=TitleBar.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TitleBar.js","sourceRoot":"","sources":["../../src/TitleBar.tsx"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;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AAI,YAAY,IAAI,IAAI,EAAE,CAAC;YACzB,OAAO,SAAS,CAAC;QACnB,CAAC;QACD,MAAM,YAAY,GAAG,iCAAkB,CAAC,WAAW,CACjD,aAAa,EACb,CAAC,IAAqC,EAAE,EAAE,CAAC,UAAU,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC,CAC9E,CAAC;QACF,kEAAkE;QAClE,UAAU,CAAC,WAAW,EAAE,CAAC,CAAC;QAC1B,OAAO,GAAG,EAAE,CAAC,YAAY,CAAC,MAAM,EAAE,CAAC;IACrC,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A second window.
|
|
3
|
+
*
|
|
4
|
+
* <Window title="Preview" width={600} height={400} onClose={hide}>
|
|
5
|
+
* <Preview id={id} />
|
|
6
|
+
* </Window>
|
|
7
|
+
*
|
|
8
|
+
* Mount it and a window opens; unmount it and the window closes. React Native
|
|
9
|
+
* has no API for this because a phone has one window and it is the screen.
|
|
10
|
+
*
|
|
11
|
+
* ## A window is a React root
|
|
12
|
+
*
|
|
13
|
+
* That is Fabric's grain rather than a decision this makes: a surface is what
|
|
14
|
+
* has a size, a layout context and a root shadow node, and two windows sharing
|
|
15
|
+
* one would be two windows sharing a layout. So a second window runs a second
|
|
16
|
+
* React tree, and `<Window>`'s children are rendered *there* rather than where
|
|
17
|
+
* they were written.
|
|
18
|
+
*
|
|
19
|
+
* Which has a consequence worth stating plainly, because it is the one thing
|
|
20
|
+
* that will surprise people: **the children do not see React context from the
|
|
21
|
+
* tree they were written in.** A theme provider, a navigation container or a
|
|
22
|
+
* Redux store wrapping the `<Window>` is not wrapping its children. What does
|
|
23
|
+
* cross is props -- the elements themselves are passed through, so anything
|
|
24
|
+
* captured in a closure or given as a prop arrives intact, including state and
|
|
25
|
+
* callbacks:
|
|
26
|
+
*
|
|
27
|
+
* const [count, setCount] = useState(0);
|
|
28
|
+
* <Window><Text onPress={() => setCount(count + 1)}>{count}</Text></Window>
|
|
29
|
+
*
|
|
30
|
+
* works, and re-renders the window when `count` changes. A `useContext` inside
|
|
31
|
+
* `<Preview>` does not. An app that needs context in a window should pass the
|
|
32
|
+
* value as a prop and re-provide it inside.
|
|
33
|
+
*
|
|
34
|
+
* ## `onClose`
|
|
35
|
+
*
|
|
36
|
+
* Called when the *person* closed the window -- its own close button, or the
|
|
37
|
+
* window manager -- and not when the app unmounted the `<Window>`. An app that
|
|
38
|
+
* unmounted it already knows.
|
|
39
|
+
*
|
|
40
|
+
* It is the half that keeps the two sides agreeing: without it an app's `open`
|
|
41
|
+
* flag would stay true after the window had gone, the next render would try to
|
|
42
|
+
* close a window that closed itself, and the window could never be reopened.
|
|
43
|
+
*
|
|
44
|
+
* ## `onCloseRequest`
|
|
45
|
+
*
|
|
46
|
+
* <Window onCloseRequest={close => (dirty ? ask() : close())}>
|
|
47
|
+
*
|
|
48
|
+
* The other half of `onClose`, and the earlier one: somebody is *trying* to
|
|
49
|
+
* close the window and it has not closed. A `<Window>` with this prop refuses
|
|
50
|
+
* every close the window manager asks for and reports the attempt instead, so
|
|
51
|
+
* the app can ask "are you sure".
|
|
52
|
+
*
|
|
53
|
+
* There are two ways to then say yes, and they are not the same one written
|
|
54
|
+
* twice. Unmounting the `<Window>` is the React-shaped one and usually right --
|
|
55
|
+
* the window is a render of some state, and agreeing to close it is that state
|
|
56
|
+
* changing. The `close` the handler is handed is the other, for when the app
|
|
57
|
+
* has no such state to change, and it closes the window without `onClose`,
|
|
58
|
+
* because an app that just said yes is not waiting to be told.
|
|
59
|
+
*
|
|
60
|
+
* `onClose` is unaffected by any of this: it still means the person closed the
|
|
61
|
+
* window, which now only happens when there is no handler to refuse it.
|
|
62
|
+
*
|
|
63
|
+
* `useWindow()` inside a second window's tree still reports the *active*
|
|
64
|
+
* window, not the one it is in; that is a real gap and is in docs/BACKLOG.md.
|
|
65
|
+
*
|
|
66
|
+
* @format
|
|
67
|
+
*/
|
|
68
|
+
import * as React from 'react';
|
|
69
|
+
import type { CloseRequestHandler } from './closeRequest';
|
|
70
|
+
/** How a second window opens. Changing these afterwards is `useWindow()`'s job. */
|
|
71
|
+
export type WindowProps = {
|
|
72
|
+
title?: string;
|
|
73
|
+
width?: number;
|
|
74
|
+
height?: number;
|
|
75
|
+
children?: React.ReactNode;
|
|
76
|
+
/** The person closed it. The window is already gone when this arrives. */
|
|
77
|
+
onClose?: () => void;
|
|
78
|
+
/** Be asked first. See closeRequest.ts. */
|
|
79
|
+
onCloseRequest?: CloseRequestHandler | null;
|
|
80
|
+
};
|
|
81
|
+
/** Whether this platform can open a second window at all. */
|
|
82
|
+
export declare const isSupported: boolean;
|
|
83
|
+
export declare function Window({ title, width, height, children, onClose, onCloseRequest, }: WindowProps): null;
|
|
84
|
+
export declare namespace Window {
|
|
85
|
+
var isSupported: boolean;
|
|
86
|
+
}
|
|
87
|
+
//# sourceMappingURL=Window.d.ts.map
|