@ng-native/desktop 0.0.0 → 0.24.0
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/README.md +52 -0
- package/app.plugin.cjs +17 -0
- package/bin/app-config.mjs +168 -0
- package/bin/autolink.mjs +224 -0
- package/bin/cli.mjs +158 -0
- package/bin/host.mjs +427 -0
- package/bin/ng-native-desktop.mjs +4 -0
- package/bin/package.mjs +971 -0
- package/bin/plist.mjs +68 -0
- package/bin/prebuilt.mjs +328 -0
- package/bin/toolchain.mjs +192 -0
- package/native/CMakeLists.txt +277 -0
- package/native/appkit/CMakeLists.txt +130 -0
- package/native/appkit/address-search.h +26 -0
- package/native/appkit/address-search.mm +277 -0
- package/native/appkit/animation-frames.h +14 -0
- package/native/appkit/animation-frames.mm +106 -0
- package/native/appkit/app-info.h +12 -0
- package/native/appkit/app-info.mm +98 -0
- package/native/appkit/app-updater.mm +128 -0
- package/native/appkit/app-windows.h +81 -0
- package/native/appkit/app-windows.mm +318 -0
- package/native/appkit/appkit-backend.h +73 -0
- package/native/appkit/appkit-backend.mm +276 -0
- package/native/appkit/apple-authentication.h +19 -0
- package/native/appkit/apple-authentication.mm +248 -0
- package/native/appkit/apple-button-view.h +10 -0
- package/native/appkit/apple-button-view.mm +37 -0
- package/native/appkit/apple-id-button.h +16 -0
- package/native/appkit/apple-id-button.mm +50 -0
- package/native/appkit/audio.h +16 -0
- package/native/appkit/audio.mm +275 -0
- package/native/appkit/battery.h +13 -0
- package/native/appkit/battery.mm +92 -0
- package/native/appkit/bookmarks.h +17 -0
- package/native/appkit/bookmarks.mm +145 -0
- package/native/appkit/calendar.h +25 -0
- package/native/appkit/calendar.mm +660 -0
- package/native/appkit/camera-sheet.h +59 -0
- package/native/appkit/camera-sheet.mm +344 -0
- package/native/appkit/camera-view.h +15 -0
- package/native/appkit/camera-view.mm +134 -0
- package/native/appkit/camera.h +61 -0
- package/native/appkit/camera.mm +496 -0
- package/native/appkit/cg-canvas.h +24 -0
- package/native/appkit/cg-canvas.mm +663 -0
- package/native/appkit/component-view.h +17 -0
- package/native/appkit/crypto.h +19 -0
- package/native/appkit/crypto.mm +78 -0
- package/native/appkit/desktop-expo.h +29 -0
- package/native/appkit/desktop-expo.mm +385 -0
- package/native/appkit/expo-image-drawing.h +46 -0
- package/native/appkit/expo-image-drawing.mm +131 -0
- package/native/appkit/expo-image-view.h +15 -0
- package/native/appkit/expo-image-view.mm +182 -0
- package/native/appkit/expo-ui-renderer.h +68 -0
- package/native/appkit/expo-ui-renderer.mm +101 -0
- package/native/appkit/expo-ui-view.h +26 -0
- package/native/appkit/expo-ui-view.mm +134 -0
- package/native/appkit/expo-ui.swift +1284 -0
- package/native/appkit/file-system.h +16 -0
- package/native/appkit/file-system.mm +140 -0
- package/native/appkit/fonts.h +12 -0
- package/native/appkit/fonts.mm +48 -0
- package/native/appkit/geocoder.h +19 -0
- package/native/appkit/geocoder.mm +101 -0
- package/native/appkit/glass-effect.h +22 -0
- package/native/appkit/glass-effect.mm +63 -0
- package/native/appkit/glass-view.h +8 -0
- package/native/appkit/glass-view.mm +65 -0
- package/native/appkit/header-toolbar.h +60 -0
- package/native/appkit/header-toolbar.mm +632 -0
- package/native/appkit/host-view.h +54 -0
- package/native/appkit/host-view.mm +1228 -0
- package/native/appkit/image-manipulator.h +14 -0
- package/native/appkit/image-manipulator.mm +191 -0
- package/native/appkit/image-request.h +22 -0
- package/native/appkit/image-request.mm +62 -0
- package/native/appkit/image-view.h +8 -0
- package/native/appkit/image-view.mm +142 -0
- package/native/appkit/input-replay.h +25 -0
- package/native/appkit/input-replay.mm +418 -0
- package/native/appkit/language-model.h +14 -0
- package/native/appkit/language-model.mm +99 -0
- package/native/appkit/language-model.swift +472 -0
- package/native/appkit/local-authentication.h +15 -0
- package/native/appkit/local-authentication.mm +133 -0
- package/native/appkit/location.h +16 -0
- package/native/appkit/location.mm +214 -0
- package/native/appkit/main.mm +1475 -0
- package/native/appkit/map-view.h +15 -0
- package/native/appkit/map-view.mm +109 -0
- package/native/appkit/maps.h +35 -0
- package/native/appkit/maps.mm +343 -0
- package/native/appkit/menu-bar.h +22 -0
- package/native/appkit/menu-bar.mm +208 -0
- package/native/appkit/modal-focus.h +16 -0
- package/native/appkit/modal-focus.mm +26 -0
- package/native/appkit/modal-host-view.h +79 -0
- package/native/appkit/modal-host-view.mm +442 -0
- package/native/appkit/native-controls.h +22 -0
- package/native/appkit/native-controls.mm +431 -0
- package/native/appkit/network-state.h +12 -0
- package/native/appkit/network-state.mm +64 -0
- package/native/appkit/network.h +14 -0
- package/native/appkit/network.mm +396 -0
- package/native/appkit/notifications.h +19 -0
- package/native/appkit/notifications.mm +309 -0
- package/native/appkit/photo-library.h +33 -0
- package/native/appkit/photo-library.mm +548 -0
- package/native/appkit/pointer-buttons.h +32 -0
- package/native/appkit/presentation-label.h +15 -0
- package/native/appkit/presentation-label.mm +12 -0
- package/native/appkit/presented-screen.h +19 -0
- package/native/appkit/presented-screen.mm +181 -0
- package/native/appkit/printing.h +42 -0
- package/native/appkit/printing.mm +393 -0
- package/native/appkit/push.h +19 -0
- package/native/appkit/push.mm +81 -0
- package/native/appkit/red-box.h +26 -0
- package/native/appkit/red-box.mm +387 -0
- package/native/appkit/screen-capture.h +21 -0
- package/native/appkit/screen-capture.mm +92 -0
- package/native/appkit/scroll-view.h +13 -0
- package/native/appkit/scroll-view.mm +251 -0
- package/native/appkit/scrollers.h +25 -0
- package/native/appkit/scrollers.mm +43 -0
- package/native/appkit/search-field.h +34 -0
- package/native/appkit/search-field.mm +291 -0
- package/native/appkit/search-toolbar-item.h +19 -0
- package/native/appkit/search-toolbar-item.mm +269 -0
- package/native/appkit/share-picker.h +34 -0
- package/native/appkit/share-picker.mm +121 -0
- package/native/appkit/split-view.h +77 -0
- package/native/appkit/split-view.mm +1206 -0
- package/native/appkit/store-review.h +13 -0
- package/native/appkit/store-review.mm +28 -0
- package/native/appkit/surface-view.h +45 -0
- package/native/appkit/surface-view.mm +562 -0
- package/native/appkit/svg-view.h +18 -0
- package/native/appkit/svg-view.mm +103 -0
- package/native/appkit/symbol-drawing.h +24 -0
- package/native/appkit/symbol-drawing.mm +117 -0
- package/native/appkit/symbol-view.h +8 -0
- package/native/appkit/symbol-view.mm +33 -0
- package/native/appkit/system-access.h +34 -0
- package/native/appkit/system-access.mm +210 -0
- package/native/appkit/system.h +24 -0
- package/native/appkit/system.mm +403 -0
- package/native/appkit/tab-walk.h +31 -0
- package/native/appkit/tab-walk.mm +64 -0
- package/native/appkit/test-launch.h +36 -0
- package/native/appkit/test-launch.mm +115 -0
- package/native/appkit/text-input-field.h +81 -0
- package/native/appkit/text-input-field.mm +525 -0
- package/native/appkit/text-layout.h +58 -0
- package/native/appkit/text-layout.mm +485 -0
- package/native/appkit/text-recognition.h +13 -0
- package/native/appkit/text-recognition.mm +102 -0
- package/native/appkit/tracking.h +13 -0
- package/native/appkit/tracking.mm +51 -0
- package/native/appkit/tray-and-dock.h +45 -0
- package/native/appkit/tray-and-dock.mm +130 -0
- package/native/appkit/undo.h +23 -0
- package/native/appkit/undo.mm +125 -0
- package/native/appkit/updates.h +17 -0
- package/native/appkit/updates.mm +71 -0
- package/native/appkit/video-view.h +10 -0
- package/native/appkit/video-view.mm +42 -0
- package/native/appkit/video.h +38 -0
- package/native/appkit/video.mm +404 -0
- package/native/appkit/web-browser.h +12 -0
- package/native/appkit/web-browser.mm +97 -0
- package/native/appkit/web-view-component.h +10 -0
- package/native/appkit/web-view-component.mm +62 -0
- package/native/appkit/web-view.h +31 -0
- package/native/appkit/web-view.mm +401 -0
- package/native/cmake/libraries/react-native-reanimated.cmake +45 -0
- package/native/cmake/libraries/react-native-worklets.cmake +46 -0
- package/native/cmake/libraries.cmake +109 -0
- package/native/cmake/linked-modules.cmake +112 -0
- package/native/cmake/react-native.cmake +175 -0
- package/native/cmake/runtime-dependencies.cmake +34 -0
- package/native/cmake/swift.cmake +43 -0
- package/native/cmake/third-party.cmake +74 -0
- package/native/core/include/ngn/absent-views.h +27 -0
- package/native/core/include/ngn/accessibility.h +140 -0
- package/native/core/include/ngn/address-search.h +69 -0
- package/native/core/include/ngn/animation-frames.h +39 -0
- package/native/core/include/ngn/app-info.h +52 -0
- package/native/core/include/ngn/app-menus.h +151 -0
- package/native/core/include/ngn/app-windows.h +181 -0
- package/native/core/include/ngn/apple-authentication.h +116 -0
- package/native/core/include/ngn/asset.h +28 -0
- package/native/core/include/ngn/audio.h +125 -0
- package/native/core/include/ngn/back-swipe.h +121 -0
- package/native/core/include/ngn/battery.h +48 -0
- package/native/core/include/ngn/bytes.h +59 -0
- package/native/core/include/ngn/calendar.h +180 -0
- package/native/core/include/ngn/camera.h +222 -0
- package/native/core/include/ngn/control-sizes.h +111 -0
- package/native/core/include/ngn/core-modules.h +108 -0
- package/native/core/include/ngn/crypto.h +38 -0
- package/native/core/include/ngn/default-menu.h +91 -0
- package/native/core/include/ngn/desktop-expo.h +193 -0
- package/native/core/include/ngn/desktop-modal.h +109 -0
- package/native/core/include/ngn/desktop-props.h +75 -0
- package/native/core/include/ngn/desktop-view-props.h +110 -0
- package/native/core/include/ngn/dev-server.h +33 -0
- package/native/core/include/ngn/dom-web-view.h +53 -0
- package/native/core/include/ngn/download.h +24 -0
- package/native/core/include/ngn/expo-image.h +192 -0
- package/native/core/include/ngn/expo-ui.h +133 -0
- package/native/core/include/ngn/file-system.h +274 -0
- package/native/core/include/ngn/focus-order.h +63 -0
- package/native/core/include/ngn/fonts.h +64 -0
- package/native/core/include/ngn/gestures.h +305 -0
- package/native/core/include/ngn/glass.h +67 -0
- package/native/core/include/ngn/header-bar.h +112 -0
- package/native/core/include/ngn/host-state.h +243 -0
- package/native/core/include/ngn/image-manipulator.h +70 -0
- package/native/core/include/ngn/input-dispatcher.h +211 -0
- package/native/core/include/ngn/input-script.h +56 -0
- package/native/core/include/ngn/input.h +112 -0
- package/native/core/include/ngn/key-value-store.h +41 -0
- package/native/core/include/ngn/language-model.h +69 -0
- package/native/core/include/ngn/launch-frame.h +47 -0
- package/native/core/include/ngn/launch-settings.h +98 -0
- package/native/core/include/ngn/layout-animations.h +24 -0
- package/native/core/include/ngn/library-components.h +13 -0
- package/native/core/include/ngn/library-glue.h +53 -0
- package/native/core/include/ngn/live-regions.h +54 -0
- package/native/core/include/ngn/local-authentication.h +74 -0
- package/native/core/include/ngn/location.h +89 -0
- package/native/core/include/ngn/maps.h +226 -0
- package/native/core/include/ngn/module-registry.h +51 -0
- package/native/core/include/ngn/mounting-backend.h +96 -0
- package/native/core/include/ngn/mounting-manager.h +155 -0
- package/native/core/include/ngn/native-controls.h +161 -0
- package/native/core/include/ngn/native-module.h +109 -0
- package/native/core/include/ngn/network-state.h +44 -0
- package/native/core/include/ngn/network.h +100 -0
- package/native/core/include/ngn/notifications.h +185 -0
- package/native/core/include/ngn/photo-library.h +134 -0
- package/native/core/include/ngn/printing.h +69 -0
- package/native/core/include/ngn/processes.h +114 -0
- package/native/core/include/ngn/red-box.h +119 -0
- package/native/core/include/ngn/reload-thread.h +258 -0
- package/native/core/include/ngn/runtime.h +163 -0
- package/native/core/include/ngn/safe-areas.h +82 -0
- package/native/core/include/ngn/screen-capture.h +35 -0
- package/native/core/include/ngn/screen-presentation.h +85 -0
- package/native/core/include/ngn/screen-stacks.h +80 -0
- package/native/core/include/ngn/scrollers.h +106 -0
- package/native/core/include/ngn/sharing.h +39 -0
- package/native/core/include/ngn/spawn-rules.h +78 -0
- package/native/core/include/ngn/splash-screen.h +41 -0
- package/native/core/include/ngn/split-view.h +270 -0
- package/native/core/include/ngn/sqlite.h +38 -0
- package/native/core/include/ngn/store-review.h +26 -0
- package/native/core/include/ngn/surface-book.h +101 -0
- package/native/core/include/ngn/surface-metrics.h +51 -0
- package/native/core/include/ngn/svg.h +434 -0
- package/native/core/include/ngn/symbol.h +90 -0
- package/native/core/include/ngn/system.h +102 -0
- package/native/core/include/ngn/tabs-host.h +171 -0
- package/native/core/include/ngn/text-input.h +134 -0
- package/native/core/include/ngn/text-measurer.h +38 -0
- package/native/core/include/ngn/text-recognition.h +55 -0
- package/native/core/include/ngn/tracking.h +34 -0
- package/native/core/include/ngn/tray-and-dock.h +107 -0
- package/native/core/include/ngn/undo.h +37 -0
- package/native/core/include/ngn/updates.h +253 -0
- package/native/core/include/ngn/video.h +126 -0
- package/native/core/include/ngn/view-box.h +126 -0
- package/native/core/include/ngn/view-transform.h +26 -0
- package/native/core/include/ngn/view-tree.h +85 -0
- package/native/core/include/ngn/web-browser.h +45 -0
- package/native/core/include/ngn/web-view.h +137 -0
- package/native/core/include/ngn/worklet-host.h +98 -0
- package/native/core/src/absent-views.cpp +41 -0
- package/native/core/src/accessibility.cpp +374 -0
- package/native/core/src/animation-frames.cpp +49 -0
- package/native/core/src/app-menus.cpp +359 -0
- package/native/core/src/app-windows.cpp +444 -0
- package/native/core/src/back-swipe.cpp +98 -0
- package/native/core/src/bytes.cpp +158 -0
- package/native/core/src/control-sizes.cpp +232 -0
- package/native/core/src/default-menu.cpp +96 -0
- package/native/core/src/desktop-modal.cpp +162 -0
- package/native/core/src/desktop-view-props.cpp +80 -0
- package/native/core/src/dev-server-helper.cpp +152 -0
- package/native/core/src/dev-server.cpp +103 -0
- package/native/core/src/dom-web-view.cpp +45 -0
- package/native/core/src/download.cpp +53 -0
- package/native/core/src/expo-image.cpp +548 -0
- package/native/core/src/expo-ui.cpp +203 -0
- package/native/core/src/focus-order.cpp +441 -0
- package/native/core/src/gestures.cpp +1806 -0
- package/native/core/src/glass.cpp +49 -0
- package/native/core/src/header-bar.cpp +104 -0
- package/native/core/src/host-services.cpp +50 -0
- package/native/core/src/host-state.cpp +61 -0
- package/native/core/src/input-dispatcher.cpp +727 -0
- package/native/core/src/input-script.cpp +123 -0
- package/native/core/src/key-value-store.cpp +169 -0
- package/native/core/src/launch-settings.cpp +148 -0
- package/native/core/src/layout-animations.cpp +62 -0
- package/native/core/src/libraries/RNCWebViewSpec.cpp +80 -0
- package/native/core/src/libraries/react-native-reanimated.cpp +216 -0
- package/native/core/src/libraries/react-native-worklets.cpp +192 -0
- package/native/core/src/libraries/rnscreens.cpp +125 -0
- package/native/core/src/libraries/rnsvg.cpp +358 -0
- package/native/core/src/libraries/safeareacontext.cpp +70 -0
- package/native/core/src/libraries/worklets-idle-frames.js +70 -0
- package/native/core/src/library-glue.cpp +35 -0
- package/native/core/src/live-regions.cpp +122 -0
- package/native/core/src/module-registry.cpp +50 -0
- package/native/core/src/modules/accessibility-manager.cpp +98 -0
- package/native/core/src/modules/address-search.cpp +219 -0
- package/native/core/src/modules/alert-manager.cpp +140 -0
- package/native/core/src/modules/app-info.cpp +74 -0
- package/native/core/src/modules/app-modules.cpp +412 -0
- package/native/core/src/modules/apple-authentication.cpp +188 -0
- package/native/core/src/modules/asset.cpp +111 -0
- package/native/core/src/modules/async-storage.cpp +192 -0
- package/native/core/src/modules/audio.cpp +541 -0
- package/native/core/src/modules/battery.cpp +88 -0
- package/native/core/src/modules/calendar.cpp +457 -0
- package/native/core/src/modules/camera.cpp +401 -0
- package/native/core/src/modules/core-modules.cpp +62 -0
- package/native/core/src/modules/crypto.cpp +117 -0
- package/native/core/src/modules/desktop-expo.cpp +527 -0
- package/native/core/src/modules/file-system.cpp +941 -0
- package/native/core/src/modules/fonts.cpp +163 -0
- package/native/core/src/modules/image-loader.cpp +105 -0
- package/native/core/src/modules/image-manipulator.cpp +305 -0
- package/native/core/src/modules/language-model.cpp +195 -0
- package/native/core/src/modules/local-authentication.cpp +140 -0
- package/native/core/src/modules/location.cpp +186 -0
- package/native/core/src/modules/maps.cpp +500 -0
- package/native/core/src/modules/network-state.cpp +72 -0
- package/native/core/src/modules/networking.cpp +387 -0
- package/native/core/src/modules/notifications.cpp +549 -0
- package/native/core/src/modules/photo-library.cpp +385 -0
- package/native/core/src/modules/printing.cpp +201 -0
- package/native/core/src/modules/screen-capture.cpp +71 -0
- package/native/core/src/modules/sharing.cpp +59 -0
- package/native/core/src/modules/splash-screen.cpp +70 -0
- package/native/core/src/modules/sqlite.cpp +421 -0
- package/native/core/src/modules/store-review.cpp +23 -0
- package/native/core/src/modules/text-recognition.cpp +107 -0
- package/native/core/src/modules/tracking.cpp +46 -0
- package/native/core/src/modules/undo.cpp +59 -0
- package/native/core/src/modules/video.cpp +366 -0
- package/native/core/src/modules/web-browser.cpp +100 -0
- package/native/core/src/modules/web-socket.cpp +266 -0
- package/native/core/src/mounting-manager.cpp +384 -0
- package/native/core/src/native-controls.cpp +129 -0
- package/native/core/src/native-module.cpp +250 -0
- package/native/core/src/network.cpp +219 -0
- package/native/core/src/posix-launcher.cpp +366 -0
- package/native/core/src/processes.cpp +324 -0
- package/native/core/src/red-box-errors.js +83 -0
- package/native/core/src/red-box.cpp +306 -0
- package/native/core/src/runtime.cpp +420 -0
- package/native/core/src/safe-areas.cpp +137 -0
- package/native/core/src/screen-presentation.cpp +61 -0
- package/native/core/src/screen-stacks.cpp +254 -0
- package/native/core/src/scrollers.cpp +181 -0
- package/native/core/src/spawn-rules.cpp +292 -0
- package/native/core/src/split-view.cpp +343 -0
- package/native/core/src/svg.cpp +2190 -0
- package/native/core/src/symbol.cpp +94 -0
- package/native/core/src/tabs-host.cpp +234 -0
- package/native/core/src/text-input.cpp +139 -0
- package/native/core/src/text-layout-manager.cpp +63 -0
- package/native/core/src/tray-and-dock.cpp +154 -0
- package/native/core/src/updates.cpp +965 -0
- package/native/core/src/view-box.cpp +788 -0
- package/native/core/src/view-transform.cpp +45 -0
- package/native/core/src/view-tree.cpp +234 -0
- package/native/core/src/web-view.cpp +143 -0
- package/native/core/src/worklet-host.cpp +10 -0
- package/native/scripts/build-hermes.sh +44 -0
- package/native/scripts/build.sh +175 -0
- package/native/scripts/cache-dir.sh +18 -0
- package/native/scripts/codegen-library.sh +193 -0
- package/native/scripts/compiler-launcher.sh +17 -0
- package/native/scripts/fetch.sh +174 -0
- package/native/scripts/hermes-built.sh +10 -0
- package/native/scripts/host-dir.sh +16 -0
- package/native/scripts/launch-probe.sh +60 -0
- package/native/scripts/macos-target.sh +8 -0
- package/native/scripts/make-prebuilt.mjs +360 -0
- package/native/scripts/prebuilt-host-cache.mjs +158 -0
- package/native/shim/openssl/sha.h +22 -0
- package/native/shim/view-platform/react/renderer/components/view/HostPlatformViewTraitsInitializer.h +37 -0
- package/package.json +73 -1
- package/prebuilt.json +33 -0
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
#include "ngn/spawn-rules.h"
|
|
2
|
+
|
|
3
|
+
#include <algorithm>
|
|
4
|
+
#include <cctype>
|
|
5
|
+
#include <set>
|
|
6
|
+
|
|
7
|
+
namespace ngn {
|
|
8
|
+
|
|
9
|
+
const std::vector<std::string> kSearchPath{
|
|
10
|
+
"/usr/bin", "/bin", "/usr/sbin", "/sbin", "/opt/homebrew/bin", "/usr/local/bin"};
|
|
11
|
+
|
|
12
|
+
namespace {
|
|
13
|
+
|
|
14
|
+
const std::set<std::string> kRefusedPrograms{
|
|
15
|
+
"sh", "bash", "zsh", "dash", "ksh", "mksh", "csh", "tcsh", "fish", "nu",
|
|
16
|
+
"env", "xargs", "sudo", "doas", "su", "osascript", "cmd", "powershell", "pwsh",
|
|
17
|
+
"nice", "nohup"};
|
|
18
|
+
|
|
19
|
+
std::string lower(std::string s) {
|
|
20
|
+
std::transform(s.begin(), s.end(), s.begin(), [](unsigned char c) { return std::tolower(c); });
|
|
21
|
+
return s;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
bool hasNul(const std::string &s) {
|
|
25
|
+
return s.find('\0') != std::string::npos;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
bool endsWith(const std::string &s, const std::string &end) {
|
|
29
|
+
return s.size() >= end.size() && s.compare(s.size() - end.size(), end.size(), end) == 0;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
std::string baseName(const std::string &program) {
|
|
33
|
+
auto at = program.find_last_of("\\/");
|
|
34
|
+
std::string last = at == std::string::npos ? program : program.substr(at + 1);
|
|
35
|
+
last = lower(last);
|
|
36
|
+
if (endsWith(last, ".exe")) {
|
|
37
|
+
last.resize(last.size() - 4);
|
|
38
|
+
}
|
|
39
|
+
return last;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
std::vector<std::string> segments(const std::string &path) {
|
|
43
|
+
std::vector<std::string> out;
|
|
44
|
+
size_t start = 0;
|
|
45
|
+
while (true) {
|
|
46
|
+
auto slash = path.find('/', start);
|
|
47
|
+
out.push_back(path.substr(start, slash == std::string::npos ? std::string::npos : slash - start));
|
|
48
|
+
if (slash == std::string::npos) {
|
|
49
|
+
return out;
|
|
50
|
+
}
|
|
51
|
+
start = slash + 1;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
bool passes(const ArgumentRule &rule, const std::string &arg) {
|
|
56
|
+
if (!arg.empty() && arg[0] == '-' && !rule.option) {
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
return std::regex_match(arg, rule.pattern);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
bool fits(const ArgumentRule &rule, const std::string &arg) {
|
|
63
|
+
return rule.placeholder ? passes(rule, arg) : rule.value == arg;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
} // namespace
|
|
67
|
+
|
|
68
|
+
std::optional<std::string> programProblem(const std::string &program) {
|
|
69
|
+
if (program.empty()) {
|
|
70
|
+
return "a program is required";
|
|
71
|
+
}
|
|
72
|
+
if (hasNul(program)) {
|
|
73
|
+
return "a program cannot hold a NUL character";
|
|
74
|
+
}
|
|
75
|
+
if (std::isspace(static_cast<unsigned char>(program.front())) ||
|
|
76
|
+
std::isspace(static_cast<unsigned char>(program.back()))) {
|
|
77
|
+
return "a program cannot start or end with white space";
|
|
78
|
+
}
|
|
79
|
+
auto l = lower(program);
|
|
80
|
+
if (endsWith(l, ".bat") || endsWith(l, ".cmd")) {
|
|
81
|
+
return program + " is a batch file, which runs through cmd.exe and re-parses its arguments";
|
|
82
|
+
}
|
|
83
|
+
if (kRefusedPrograms.contains(baseName(program))) {
|
|
84
|
+
return program + " runs its arguments as a command, so it cannot be declared";
|
|
85
|
+
}
|
|
86
|
+
if (program[0] == '/') {
|
|
87
|
+
auto parts = segments(program.substr(1));
|
|
88
|
+
for (const auto &part : parts) {
|
|
89
|
+
if (part.empty() || part == "." || part == "..") {
|
|
90
|
+
return program + " is not a normalized absolute path";
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return std::nullopt;
|
|
94
|
+
}
|
|
95
|
+
if (program.find_first_of("\\/") != std::string::npos) {
|
|
96
|
+
return program + " is a relative path: give an absolute path or a bare name";
|
|
97
|
+
}
|
|
98
|
+
if (program == "." || program == "..") {
|
|
99
|
+
return program + " is not a program";
|
|
100
|
+
}
|
|
101
|
+
return std::nullopt;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// A pattern's top-level alternatives: `-v|.*` is `-v` and `.*`. A `|` in a group, in a class or
|
|
105
|
+
// escaped is not one. The pattern has compiled, so its groups and classes are balanced.
|
|
106
|
+
static std::vector<std::string> topLevelAlternatives(const std::string &source) {
|
|
107
|
+
std::vector<std::string> found;
|
|
108
|
+
int depth = 0;
|
|
109
|
+
bool inClass = false;
|
|
110
|
+
size_t start = 0;
|
|
111
|
+
for (size_t at = 0; at < source.size(); at++) {
|
|
112
|
+
char c = source[at];
|
|
113
|
+
if (c == '\\') {
|
|
114
|
+
at++;
|
|
115
|
+
} else if (inClass) {
|
|
116
|
+
inClass = c != ']';
|
|
117
|
+
} else if (c == '[') {
|
|
118
|
+
inClass = true;
|
|
119
|
+
} else if (c == '(') {
|
|
120
|
+
depth++;
|
|
121
|
+
} else if (c == ')') {
|
|
122
|
+
depth--;
|
|
123
|
+
} else if (c == '|' && depth == 0) {
|
|
124
|
+
found.push_back(source.substr(start, at - start));
|
|
125
|
+
start = at + 1;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
found.push_back(source.substr(start));
|
|
129
|
+
return found;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
ArgumentRule parseArgument(const std::string &arg) {
|
|
133
|
+
if (hasNul(arg)) {
|
|
134
|
+
throw SpawnRuleError("an argument cannot hold a NUL character");
|
|
135
|
+
}
|
|
136
|
+
static const std::regex placeholder(R"(^\{([A-Za-z_][A-Za-z0-9_]*):([\s\S]+)\}(\.\.\.)?$)");
|
|
137
|
+
std::smatch m;
|
|
138
|
+
if (!std::regex_match(arg, m, placeholder)) {
|
|
139
|
+
return ArgumentRule{.value = arg};
|
|
140
|
+
}
|
|
141
|
+
std::string name = m[1];
|
|
142
|
+
std::string source = m[2];
|
|
143
|
+
bool repeated = m[3].matched;
|
|
144
|
+
ArgumentRule rule{.placeholder = true, .value = name, .repeated = repeated};
|
|
145
|
+
try {
|
|
146
|
+
// On its own first: a pattern that compiles alone has balanced groups, so one such as
|
|
147
|
+
// `a)|(.*` cannot close the anchoring group early and escape it.
|
|
148
|
+
std::regex alone(source, std::regex::ECMAScript);
|
|
149
|
+
rule.pattern = std::regex("^(?:" + source + ")$", std::regex::ECMAScript);
|
|
150
|
+
} catch (const std::regex_error &error) {
|
|
151
|
+
throw SpawnRuleError("{" + name + "} has a pattern that does not compile: " + error.what());
|
|
152
|
+
}
|
|
153
|
+
rule.option = true;
|
|
154
|
+
for (const auto &alternative : topLevelAlternatives(source)) {
|
|
155
|
+
std::string_view rest(alternative);
|
|
156
|
+
if (!rest.empty() && rest[0] == '^') {
|
|
157
|
+
rest.remove_prefix(1);
|
|
158
|
+
}
|
|
159
|
+
if (!rest.empty() && rest[0] == '\\') {
|
|
160
|
+
rest.remove_prefix(1);
|
|
161
|
+
}
|
|
162
|
+
rule.option = rule.option && !rest.empty() && rest[0] == '-';
|
|
163
|
+
}
|
|
164
|
+
return rule;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
CompiledCapability compileCapability(const SpawnCapability &capability) {
|
|
168
|
+
if (auto problem = programProblem(capability.program)) {
|
|
169
|
+
throw SpawnRuleError(*problem);
|
|
170
|
+
}
|
|
171
|
+
CompiledCapability out{.program = capability.program};
|
|
172
|
+
std::set<std::string> names;
|
|
173
|
+
int repeated = 0;
|
|
174
|
+
for (const auto &arg : capability.args) {
|
|
175
|
+
auto rule = parseArgument(arg);
|
|
176
|
+
if (rule.placeholder) {
|
|
177
|
+
if (!names.insert(rule.value).second) {
|
|
178
|
+
throw SpawnRuleError(capability.program + ": {" + rule.value + "} is declared twice");
|
|
179
|
+
}
|
|
180
|
+
repeated += rule.repeated ? 1 : 0;
|
|
181
|
+
}
|
|
182
|
+
out.args.push_back(std::move(rule));
|
|
183
|
+
}
|
|
184
|
+
if (repeated > 1) {
|
|
185
|
+
throw SpawnRuleError(capability.program + ": at most one placeholder may repeat");
|
|
186
|
+
}
|
|
187
|
+
return out;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
bool matchArguments(const std::vector<ArgumentRule> &rules, const std::vector<std::string> &args) {
|
|
191
|
+
if (std::any_of(args.begin(), args.end(), hasNul)) {
|
|
192
|
+
return false;
|
|
193
|
+
}
|
|
194
|
+
auto repeatedAt = std::find_if(rules.begin(), rules.end(), [](const auto &r) { return r.placeholder && r.repeated; });
|
|
195
|
+
if (repeatedAt == rules.end()) {
|
|
196
|
+
if (args.size() != rules.size()) {
|
|
197
|
+
return false;
|
|
198
|
+
}
|
|
199
|
+
for (size_t i = 0; i < rules.size(); i++) {
|
|
200
|
+
if (!fits(rules[i], args[i])) {
|
|
201
|
+
return false;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
return true;
|
|
205
|
+
}
|
|
206
|
+
size_t at = static_cast<size_t>(repeatedAt - rules.begin());
|
|
207
|
+
size_t tail = rules.size() - at - 1;
|
|
208
|
+
if (args.size() < at + tail) {
|
|
209
|
+
return false;
|
|
210
|
+
}
|
|
211
|
+
for (size_t i = 0; i < at; i++) {
|
|
212
|
+
if (!fits(rules[i], args[i])) {
|
|
213
|
+
return false;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
size_t tailStart = args.size() - tail;
|
|
217
|
+
for (size_t i = 0; i < tail; i++) {
|
|
218
|
+
if (!fits(rules[at + 1 + i], args[tailStart + i])) {
|
|
219
|
+
return false;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
for (size_t i = at; i < tailStart; i++) {
|
|
223
|
+
if (!passes(*repeatedAt, args[i])) {
|
|
224
|
+
return false;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
return true;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
std::optional<std::string> matchSpawn(
|
|
231
|
+
const std::vector<CompiledCapability> &capabilities,
|
|
232
|
+
const std::string &program,
|
|
233
|
+
const std::vector<std::string> &args,
|
|
234
|
+
const std::map<std::string, std::optional<std::string>> &resolved) {
|
|
235
|
+
for (const auto &capability : capabilities) {
|
|
236
|
+
std::optional<std::string> pinned;
|
|
237
|
+
if (!capability.program.empty() && capability.program[0] == '/') {
|
|
238
|
+
pinned = capability.program;
|
|
239
|
+
} else if (auto it = resolved.find(capability.program); it != resolved.end()) {
|
|
240
|
+
pinned = it->second;
|
|
241
|
+
}
|
|
242
|
+
if (!pinned) {
|
|
243
|
+
continue;
|
|
244
|
+
}
|
|
245
|
+
if (program != capability.program && program != *pinned) {
|
|
246
|
+
continue;
|
|
247
|
+
}
|
|
248
|
+
if (matchArguments(capability.args, args)) {
|
|
249
|
+
return pinned;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
return std::nullopt;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
std::optional<std::string> resolveProgram(const std::string &program, const ProgramLookup &lookup) {
|
|
256
|
+
if (programProblem(program)) {
|
|
257
|
+
return std::nullopt;
|
|
258
|
+
}
|
|
259
|
+
std::vector<std::string> candidates;
|
|
260
|
+
if (program[0] == '/') {
|
|
261
|
+
candidates.push_back(program);
|
|
262
|
+
} else {
|
|
263
|
+
for (const auto &dir : kSearchPath) {
|
|
264
|
+
candidates.push_back(dir + "/" + program);
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
for (const auto &candidate : candidates) {
|
|
268
|
+
if (!lookup.isExecutable || !lookup.isExecutable(candidate)) {
|
|
269
|
+
continue;
|
|
270
|
+
}
|
|
271
|
+
if (lookup.isStub && lookup.isStub(candidate)) {
|
|
272
|
+
return std::nullopt;
|
|
273
|
+
}
|
|
274
|
+
return candidate;
|
|
275
|
+
}
|
|
276
|
+
return std::nullopt;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
std::map<std::string, std::string> filterEnvironment(
|
|
280
|
+
const std::map<std::string, std::string> &env,
|
|
281
|
+
const std::vector<std::string> &allowed) {
|
|
282
|
+
std::map<std::string, std::string> out;
|
|
283
|
+
for (const auto &name : allowed) {
|
|
284
|
+
auto it = env.find(name);
|
|
285
|
+
if (it != env.end() && !hasNul(it->second)) {
|
|
286
|
+
out[name] = it->second;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
return out;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
} // namespace ngn
|
|
@@ -0,0 +1,343 @@
|
|
|
1
|
+
#include "ngn/split-view.h"
|
|
2
|
+
|
|
3
|
+
#include "ngn/desktop-view-props.h"
|
|
4
|
+
#include "ngn/native-controls.h"
|
|
5
|
+
|
|
6
|
+
#include <react/renderer/core/propsConversions.h>
|
|
7
|
+
|
|
8
|
+
#include <algorithm>
|
|
9
|
+
#include <string_view>
|
|
10
|
+
|
|
11
|
+
using namespace facebook::react;
|
|
12
|
+
|
|
13
|
+
namespace ngn {
|
|
14
|
+
|
|
15
|
+
const char SplitViewComponentName[] = "NgNativeSplitView";
|
|
16
|
+
const char SidebarComponentName[] = "NgNativeSidebar";
|
|
17
|
+
const char SplitContentComponentName[] = "NgNativeSplitContent";
|
|
18
|
+
const char SidebarSectionComponentName[] = "NgNativeSidebarSection";
|
|
19
|
+
const char SidebarItemComponentName[] = "NgNativeSidebarItem";
|
|
20
|
+
|
|
21
|
+
SplitPaneProps::SplitPaneProps(const PropsParserContext &context, const SplitPaneProps &sourceProps, const RawProps &rawProps)
|
|
22
|
+
: ViewProps(context, sourceProps, rawProps),
|
|
23
|
+
collapsed(convertRawProp(context, rawProps, "collapsed", sourceProps.collapsed, false)),
|
|
24
|
+
paneMinWidth(convertRawProp(context, rawProps, "paneMinWidth", sourceProps.paneMinWidth, Float{0})),
|
|
25
|
+
paneMaxWidth(convertRawProp(context, rawProps, "paneMaxWidth", sourceProps.paneMaxWidth, Float{0})),
|
|
26
|
+
autosaveName(convertRawProp(context, rawProps, "autosaveName", sourceProps.autosaveName, std::string{})) {}
|
|
27
|
+
|
|
28
|
+
SidebarSectionProps::SidebarSectionProps(
|
|
29
|
+
const PropsParserContext &context,
|
|
30
|
+
const SidebarSectionProps &sourceProps,
|
|
31
|
+
const RawProps &rawProps)
|
|
32
|
+
: ViewProps(context, sourceProps, rawProps),
|
|
33
|
+
title(convertRawProp(context, rawProps, "title", sourceProps.title, std::string{})),
|
|
34
|
+
collapsible(convertRawProp(context, rawProps, "collapsible", sourceProps.collapsible, false)) {}
|
|
35
|
+
|
|
36
|
+
SidebarItemProps::SidebarItemProps(
|
|
37
|
+
const PropsParserContext &context,
|
|
38
|
+
const SidebarItemProps &sourceProps,
|
|
39
|
+
const RawProps &rawProps)
|
|
40
|
+
: ViewProps(context, sourceProps, rawProps),
|
|
41
|
+
label(convertRawProp(context, rawProps, "label", sourceProps.label, std::string{})),
|
|
42
|
+
badge(convertRawProp(context, rawProps, "badge", sourceProps.badge, std::string{})),
|
|
43
|
+
sfSymbol(convertRawProp(context, rawProps, "sfSymbol", sourceProps.sfSymbol, std::string{})),
|
|
44
|
+
drawable(convertRawProp(context, rawProps, "drawable", sourceProps.drawable, std::string{})),
|
|
45
|
+
selected(convertRawProp(context, rawProps, "selected", sourceProps.selected, false)) {}
|
|
46
|
+
|
|
47
|
+
void SidebarSectionShadowNode::applySourceListLayout() const {
|
|
48
|
+
ensureUnsealed();
|
|
49
|
+
const auto &props = getConcreteProps();
|
|
50
|
+
auto style = yogaNode_.style();
|
|
51
|
+
bool titled = !props.title.empty();
|
|
52
|
+
style.setPadding(
|
|
53
|
+
facebook::yoga::Edge::Top,
|
|
54
|
+
titled ? facebook::yoga::StyleLength::points(kSidebarHeaderHeight)
|
|
55
|
+
: props.yogaStyle.padding(facebook::yoga::Edge::Top));
|
|
56
|
+
style.setDimension(
|
|
57
|
+
facebook::yoga::Dimension::Height,
|
|
58
|
+
titled && getStateData().collapsed ? facebook::yoga::StyleSizeLength::points(kSidebarHeaderHeight)
|
|
59
|
+
: props.yogaStyle.dimension(facebook::yoga::Dimension::Height));
|
|
60
|
+
if (!(style == yogaNode_.style())) {
|
|
61
|
+
yogaNode_.setStyle(style);
|
|
62
|
+
yogaNode_.setDirty(true);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
void SidebarSectionComponentDescriptor::adopt(ShadowNode &shadowNode) const {
|
|
67
|
+
static_cast<const SidebarSectionShadowNode &>(shadowNode).applySourceListLayout();
|
|
68
|
+
ConcreteComponentDescriptor::adopt(shadowNode);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
void SidebarItemShadowNode::applySourceListLayout() const {
|
|
72
|
+
ensureUnsealed();
|
|
73
|
+
const auto &props = getConcreteProps();
|
|
74
|
+
auto style = yogaNode_.style();
|
|
75
|
+
auto minHeight = props.yogaStyle.minDimension(facebook::yoga::Dimension::Height);
|
|
76
|
+
bool tallEnough = minHeight.isPoints() && minHeight.value().isDefined() &&
|
|
77
|
+
minHeight.value().unwrap() >= kSidebarRowHeight;
|
|
78
|
+
style.setMinDimension(
|
|
79
|
+
facebook::yoga::Dimension::Height,
|
|
80
|
+
tallEnough ? minHeight : facebook::yoga::StyleSizeLength::points(kSidebarRowHeight));
|
|
81
|
+
Float width = getStateData().size.width;
|
|
82
|
+
style.setDimension(
|
|
83
|
+
facebook::yoga::Dimension::Width,
|
|
84
|
+
width > 0 ? facebook::yoga::StyleSizeLength::points(width)
|
|
85
|
+
: props.yogaStyle.dimension(facebook::yoga::Dimension::Width));
|
|
86
|
+
if (!(style == yogaNode_.style())) {
|
|
87
|
+
yogaNode_.setStyle(style);
|
|
88
|
+
yogaNode_.setDirty(true);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
void SidebarItemComponentDescriptor::adopt(ShadowNode &shadowNode) const {
|
|
93
|
+
static_cast<const SidebarItemShadowNode &>(shadowNode).applySourceListLayout();
|
|
94
|
+
ConcreteComponentDescriptor::adopt(shadowNode);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
namespace {
|
|
98
|
+
|
|
99
|
+
bool named(const ViewTree::Node *node, const char *name) {
|
|
100
|
+
return node != nullptr && std::string_view(node->view.componentName) == name;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
bool isSection(const ViewTree::Node *node) {
|
|
104
|
+
return named(node, SidebarSectionComponentName);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
bool isItem(const ViewTree::Node *node) {
|
|
108
|
+
return named(node, SidebarItemComponentName);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
SidebarGroup group(const ViewTree &tree, const ViewTree::Node §ion) {
|
|
112
|
+
SidebarGroup out;
|
|
113
|
+
out.tag = section.view.tag;
|
|
114
|
+
if (const auto *props = dynamic_cast<const SidebarSectionProps *>(section.view.props.get())) {
|
|
115
|
+
out.title = props->title;
|
|
116
|
+
out.collapsible = props->collapsible;
|
|
117
|
+
}
|
|
118
|
+
for (Tag child : section.children) {
|
|
119
|
+
const auto *node = tree.find(child);
|
|
120
|
+
if (!isItem(node)) {
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
SidebarRow row{.tag = child, .custom = !node->children.empty()};
|
|
124
|
+
if (const auto *props = dynamic_cast<const SidebarItemProps *>(node->view.props.get())) {
|
|
125
|
+
row.label = props->label;
|
|
126
|
+
row.badge = props->badge;
|
|
127
|
+
row.sfSymbol = props->sfSymbol;
|
|
128
|
+
row.selected = props->selected;
|
|
129
|
+
}
|
|
130
|
+
out.rows.push_back(std::move(row));
|
|
131
|
+
}
|
|
132
|
+
return out;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
} // namespace
|
|
136
|
+
|
|
137
|
+
std::vector<SourceList> sourceLists(const ViewTree &tree, Tag parent) {
|
|
138
|
+
std::vector<SourceList> lists;
|
|
139
|
+
const auto *node = tree.find(parent);
|
|
140
|
+
if (node == nullptr) {
|
|
141
|
+
return lists;
|
|
142
|
+
}
|
|
143
|
+
bool inRun = false;
|
|
144
|
+
for (Tag child : node->children) {
|
|
145
|
+
const auto *section = tree.find(child);
|
|
146
|
+
if (!isSection(section)) {
|
|
147
|
+
inRun = false;
|
|
148
|
+
continue;
|
|
149
|
+
}
|
|
150
|
+
if (!inRun) {
|
|
151
|
+
lists.emplace_back();
|
|
152
|
+
inRun = true;
|
|
153
|
+
}
|
|
154
|
+
lists.back().groups.push_back(group(tree, *section));
|
|
155
|
+
}
|
|
156
|
+
return lists;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
bool rowContentTakesClick(const ViewTree &tree, const std::vector<Tag> &chain) {
|
|
160
|
+
for (size_t i = 1; i < chain.size(); i++) {
|
|
161
|
+
const auto *node = tree.find(chain[i]);
|
|
162
|
+
if (node == nullptr) {
|
|
163
|
+
continue;
|
|
164
|
+
}
|
|
165
|
+
std::string_view name = node->view.componentName;
|
|
166
|
+
if (name == "TextInput" || controlKind(name)) {
|
|
167
|
+
return true;
|
|
168
|
+
}
|
|
169
|
+
if (node->view.props) {
|
|
170
|
+
auto desktop = desktopProps(*node->view.props);
|
|
171
|
+
if (desktop.focusable.value_or(false) || desktop.tabIndex.value_or(-1) >= 0) {
|
|
172
|
+
return true;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
return false;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
void Sidebars::childrenChanged(const ViewTree &tree, Tag parent) {
|
|
180
|
+
// Resolved in settle, once the transaction has put every node in its place.
|
|
181
|
+
dirtyParents_.insert(parent);
|
|
182
|
+
if (const auto *parentNode = tree.find(parent)) {
|
|
183
|
+
for (Tag child : parentNode->children) {
|
|
184
|
+
const auto *node = tree.find(child);
|
|
185
|
+
bool splits = named(node, SplitViewComponentName) || named(node, "RNSTabsHostIOS");
|
|
186
|
+
if (splits && !placed_.contains(child) &&
|
|
187
|
+
std::find(newSplits_.begin(), newSplits_.end(), child) == newSplits_.end()) {
|
|
188
|
+
newSplits_.push_back(child);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
void Sidebars::propsChanged(const ViewTree &tree, Tag tag) {
|
|
195
|
+
const auto *node = tree.find(tag);
|
|
196
|
+
if (isSection(node) || isItem(node)) {
|
|
197
|
+
dirtyParents_.insert(tag);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
void Sidebars::deleted(Tag tag) {
|
|
202
|
+
dirtyParents_.erase(tag);
|
|
203
|
+
lists_.erase(tag);
|
|
204
|
+
std::erase(newSplits_, tag);
|
|
205
|
+
placed_.erase(tag);
|
|
206
|
+
std::erase_if(windowSplits_, [tag](const auto &entry) { return entry.second == tag; });
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
namespace {
|
|
210
|
+
|
|
211
|
+
// The parent whose children a dirty tag's source lists are: an item's section's parent, a
|
|
212
|
+
// section's parent, or the tag itself.
|
|
213
|
+
Tag listParent(const ViewTree &tree, Tag tag) {
|
|
214
|
+
const auto *node = tree.find(tag);
|
|
215
|
+
if (isItem(node)) {
|
|
216
|
+
node = tree.find(node->parent);
|
|
217
|
+
}
|
|
218
|
+
if (isSection(node)) {
|
|
219
|
+
return node->parent;
|
|
220
|
+
}
|
|
221
|
+
return tag;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
// Whether a split view is inside something that keeps it from being its window's: another split
|
|
225
|
+
// view, a modal or a tabs host. Nothing when it is not connected to the surface's root.
|
|
226
|
+
std::optional<bool> nested(const ViewTree &tree, Tag split, SurfaceId surfaceId) {
|
|
227
|
+
bool inside = false;
|
|
228
|
+
const auto *node = tree.find(split);
|
|
229
|
+
while (node != nullptr && node->view.tag != surfaceId) {
|
|
230
|
+
node = tree.find(node->parent);
|
|
231
|
+
if (node == nullptr) {
|
|
232
|
+
return std::nullopt;
|
|
233
|
+
}
|
|
234
|
+
std::string_view name = node->view.componentName;
|
|
235
|
+
inside = inside || name == SplitViewComponentName || name == "ModalHostView" || name == "RNSTabsHostIOS" ||
|
|
236
|
+
name == "RNSTabsHost";
|
|
237
|
+
}
|
|
238
|
+
return node == nullptr ? std::nullopt : std::optional<bool>(inside);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
int depth(const ViewTree &tree, Tag tag) {
|
|
242
|
+
int d = 0;
|
|
243
|
+
for (const auto *node = tree.find(tag); node != nullptr && node->parent != -1; node = tree.find(node->parent)) {
|
|
244
|
+
d++;
|
|
245
|
+
}
|
|
246
|
+
return d;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
} // namespace
|
|
250
|
+
|
|
251
|
+
Sidebars::Changes Sidebars::settle(const ViewTree &tree, SurfaceId surfaceId) {
|
|
252
|
+
Changes changes;
|
|
253
|
+
|
|
254
|
+
auto splits = std::move(newSplits_);
|
|
255
|
+
newSplits_.clear();
|
|
256
|
+
std::erase_if(splits, [&](Tag tag) { return !tree.contains(tag); });
|
|
257
|
+
std::stable_sort(splits.begin(), splits.end(), [&](Tag a, Tag b) { return depth(tree, a) < depth(tree, b); });
|
|
258
|
+
for (Tag split : splits) {
|
|
259
|
+
auto inside = nested(tree, split, surfaceId);
|
|
260
|
+
if (!inside) {
|
|
261
|
+
// Not in the surface yet: decided once it is.
|
|
262
|
+
newSplits_.push_back(split);
|
|
263
|
+
continue;
|
|
264
|
+
}
|
|
265
|
+
placed_.insert(split);
|
|
266
|
+
bool window = !*inside && !windowSplits_.contains(surfaceId);
|
|
267
|
+
if (window) {
|
|
268
|
+
windowSplits_[surfaceId] = split;
|
|
269
|
+
}
|
|
270
|
+
changes.splitViews.push_back({.tag = split, .window = window});
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
auto dirty = std::move(dirtyParents_);
|
|
274
|
+
dirtyParents_.clear();
|
|
275
|
+
std::unordered_set<Tag> parents;
|
|
276
|
+
for (Tag tag : dirty) {
|
|
277
|
+
parents.insert(listParent(tree, tag));
|
|
278
|
+
}
|
|
279
|
+
std::vector<Tag> ordered(parents.begin(), parents.end());
|
|
280
|
+
std::sort(ordered.begin(), ordered.end());
|
|
281
|
+
for (Tag parent : ordered) {
|
|
282
|
+
if (parent == -1) {
|
|
283
|
+
continue;
|
|
284
|
+
}
|
|
285
|
+
auto lists = sourceLists(tree, parent);
|
|
286
|
+
auto known = lists_.find(parent);
|
|
287
|
+
bool had = known != lists_.end();
|
|
288
|
+
if (had ? known->second == lists : lists.empty()) {
|
|
289
|
+
continue;
|
|
290
|
+
}
|
|
291
|
+
if (lists.empty()) {
|
|
292
|
+
lists_.erase(parent);
|
|
293
|
+
} else {
|
|
294
|
+
lists_[parent] = lists;
|
|
295
|
+
}
|
|
296
|
+
changes.lists.push_back({.parent = parent, .lists = std::move(lists)});
|
|
297
|
+
}
|
|
298
|
+
return changes;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
std::optional<bool> SidebarCollapse::propChanged(bool collapsed) {
|
|
302
|
+
prop_ = collapsed;
|
|
303
|
+
if (toolkit_ == collapsed) {
|
|
304
|
+
return std::nullopt;
|
|
305
|
+
}
|
|
306
|
+
toolkit_ = collapsed;
|
|
307
|
+
return collapsed;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
bool SidebarCollapse::toolkitChanged(bool collapsed) {
|
|
311
|
+
if (toolkit_ == collapsed) {
|
|
312
|
+
return false;
|
|
313
|
+
}
|
|
314
|
+
toolkit_ = collapsed;
|
|
315
|
+
return collapsed != prop_;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
bool FrameSizes::report(Tag tag, Size size) {
|
|
319
|
+
bool first = pending_.empty();
|
|
320
|
+
pending_[tag] = size;
|
|
321
|
+
return first;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
std::vector<std::pair<Tag, Size>> FrameSizes::flush() {
|
|
325
|
+
std::vector<std::pair<Tag, Size>> out;
|
|
326
|
+
for (const auto &[tag, size] : pending_) {
|
|
327
|
+
auto applied = applied_.find(tag);
|
|
328
|
+
if (applied == applied_.end() || applied->second != size) {
|
|
329
|
+
applied_[tag] = size;
|
|
330
|
+
out.emplace_back(tag, size);
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
pending_.clear();
|
|
334
|
+
std::sort(out.begin(), out.end(), [](const auto &a, const auto &b) { return a.first < b.first; });
|
|
335
|
+
return out;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
void FrameSizes::forget(Tag tag) {
|
|
339
|
+
pending_.erase(tag);
|
|
340
|
+
applied_.erase(tag);
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
} // namespace ngn
|