@dxos/app-framework 0.8.3 → 0.8.4-main.1068cf700f
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/.storybook/main.mts +11 -0
- package/.storybook/preview.mts +8 -0
- package/.swc/plugins/linux_x86_64_19.0.0/727453fb3a62f7f1d952a41e051ca8a6f88cadc45cee43c6a4d1aa45f9b75665.wasmer-v7 +0 -0
- package/README.md +0 -8
- package/dist/lib/browser/capability-7LE5X2NH.mjs +37 -0
- package/dist/lib/browser/capability-7LE5X2NH.mjs.map +7 -0
- package/dist/lib/browser/capability-DU35RXMD.mjs +34 -0
- package/dist/lib/browser/capability-DU35RXMD.mjs.map +7 -0
- package/dist/lib/browser/chunk-4DQMLMGU.mjs +44 -0
- package/dist/lib/browser/chunk-4DQMLMGU.mjs.map +7 -0
- package/dist/lib/browser/chunk-EIFGKQSA.mjs +170 -0
- package/dist/lib/browser/chunk-EIFGKQSA.mjs.map +7 -0
- package/dist/lib/browser/chunk-FHQTHCX7.mjs +8 -0
- package/dist/lib/browser/chunk-FHQTHCX7.mjs.map +7 -0
- package/dist/lib/browser/chunk-IGRQWMWW.mjs +80 -0
- package/dist/lib/browser/chunk-IGRQWMWW.mjs.map +7 -0
- package/dist/lib/browser/chunk-J5LGTIGS.mjs +10 -0
- package/dist/lib/browser/chunk-KWP6PKIU.mjs +145 -0
- package/dist/lib/browser/chunk-KWP6PKIU.mjs.map +7 -0
- package/dist/lib/browser/chunk-NPUEVX42.mjs +34 -0
- package/dist/lib/browser/chunk-NPUEVX42.mjs.map +7 -0
- package/dist/lib/browser/chunk-PKQT6C53.mjs +47 -0
- package/dist/lib/browser/chunk-PKQT6C53.mjs.map +7 -0
- package/dist/lib/browser/chunk-WGWEEBUV.mjs +807 -0
- package/dist/lib/browser/chunk-WGWEEBUV.mjs.map +7 -0
- package/dist/lib/browser/chunk-YAFEA4GV.mjs +1 -0
- package/dist/lib/browser/chunk-YZQ6NFG4.mjs +781 -0
- package/dist/lib/browser/chunk-YZQ6NFG4.mjs.map +7 -0
- package/dist/lib/browser/chunk-ZQO3UZ4R.mjs +77 -0
- package/dist/lib/browser/chunk-ZQO3UZ4R.mjs.map +7 -0
- package/dist/lib/browser/cli/index.mjs +89 -0
- package/dist/lib/browser/cli/index.mjs.map +7 -0
- package/dist/lib/browser/common/activation-events.mjs +23 -0
- package/dist/lib/browser/common/capabilities.mjs +45 -0
- package/dist/lib/browser/core/activation-event.mjs +20 -0
- package/dist/lib/browser/core/activation-event.mjs.map +7 -0
- package/dist/lib/browser/core/capability.mjs +28 -0
- package/dist/lib/browser/core/capability.mjs.map +7 -0
- package/dist/lib/browser/core/plugin-manager.mjs +15 -0
- package/dist/lib/browser/core/plugin-manager.mjs.map +7 -0
- package/dist/lib/browser/core/plugin.mjs +27 -0
- package/dist/lib/browser/core/plugin.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +87 -156
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/invoker-capability-7QW56NOM.mjs +36 -0
- package/dist/lib/browser/invoker-capability-7QW56NOM.mjs.map +7 -0
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +84 -38
- package/dist/lib/browser/testing/index.mjs.map +4 -4
- package/dist/lib/browser/ui/index.mjs +49 -0
- package/dist/lib/browser/ui/index.mjs.map +7 -0
- package/dist/lib/node-esm/capability-OSVYGK4X.mjs +38 -0
- package/dist/lib/node-esm/capability-OSVYGK4X.mjs.map +7 -0
- package/dist/lib/node-esm/capability-SR2EIZFP.mjs +35 -0
- package/dist/lib/node-esm/capability-SR2EIZFP.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-64IMLAS2.mjs +78 -0
- package/dist/lib/node-esm/chunk-64IMLAS2.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-7OWSHPYK.mjs +48 -0
- package/dist/lib/node-esm/chunk-7OWSHPYK.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-DHSHRYIB.mjs +171 -0
- package/dist/lib/node-esm/chunk-DHSHRYIB.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-DZ2XLAGI.mjs +146 -0
- package/dist/lib/node-esm/chunk-DZ2XLAGI.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-HSLMI22Q.mjs +11 -0
- package/dist/lib/node-esm/chunk-HSLMI22Q.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-J2PHTRHC.mjs +45 -0
- package/dist/lib/node-esm/chunk-J2PHTRHC.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-JAZVHID3.mjs +35 -0
- package/dist/lib/node-esm/chunk-JAZVHID3.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-OQYHRZYF.mjs +81 -0
- package/dist/lib/node-esm/chunk-OQYHRZYF.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-UEWJDI2L.mjs +10 -0
- package/dist/lib/node-esm/chunk-UEWJDI2L.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-VV4YHPQQ.mjs +782 -0
- package/dist/lib/node-esm/chunk-VV4YHPQQ.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-XHAKT6UD.mjs +808 -0
- package/dist/lib/node-esm/chunk-XHAKT6UD.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-Z4TJPSMP.mjs +2 -0
- package/dist/lib/node-esm/chunk-Z4TJPSMP.mjs.map +7 -0
- package/dist/lib/node-esm/cli/index.mjs +90 -0
- package/dist/lib/node-esm/cli/index.mjs.map +7 -0
- package/dist/lib/node-esm/common/activation-events.mjs +24 -0
- package/dist/lib/node-esm/common/activation-events.mjs.map +7 -0
- package/dist/lib/node-esm/common/capabilities.mjs +46 -0
- package/dist/lib/node-esm/common/capabilities.mjs.map +7 -0
- package/dist/lib/node-esm/core/activation-event.mjs +21 -0
- package/dist/lib/node-esm/core/activation-event.mjs.map +7 -0
- package/dist/lib/node-esm/core/capability.mjs +29 -0
- package/dist/lib/node-esm/core/capability.mjs.map +7 -0
- package/dist/lib/node-esm/core/plugin-manager.mjs +16 -0
- package/dist/lib/node-esm/core/plugin-manager.mjs.map +7 -0
- package/dist/lib/node-esm/core/plugin.mjs +28 -0
- package/dist/lib/node-esm/core/plugin.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +87 -156
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/invoker-capability-CK4AMF2R.mjs +37 -0
- package/dist/lib/node-esm/invoker-capability-CK4AMF2R.mjs.map +7 -0
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/testing/index.mjs +84 -38
- package/dist/lib/node-esm/testing/index.mjs.map +4 -4
- package/dist/lib/node-esm/ui/index.mjs +50 -0
- package/dist/lib/node-esm/ui/index.mjs.map +7 -0
- package/dist/types/src/cli/cli.d.ts +39 -0
- package/dist/types/src/cli/cli.d.ts.map +1 -0
- package/dist/types/src/cli/index.d.ts +2 -0
- package/dist/types/src/cli/index.d.ts.map +1 -0
- package/dist/types/src/common/activation-events.d.ts +27 -0
- package/dist/types/src/common/activation-events.d.ts.map +1 -0
- package/dist/types/src/common/capabilities.d.ts +114 -121
- package/dist/types/src/common/capabilities.d.ts.map +1 -1
- package/dist/types/src/common/index.d.ts +4 -8
- package/dist/types/src/common/index.d.ts.map +1 -1
- package/dist/types/src/common/operations.d.ts +33 -0
- package/dist/types/src/common/operations.d.ts.map +1 -0
- package/dist/types/src/common/translations.d.ts +8 -8
- package/dist/types/src/common/translations.d.ts.map +1 -1
- package/dist/types/src/context.d.ts +5 -0
- package/dist/types/src/context.d.ts.map +1 -0
- package/dist/types/src/core/{events.d.ts → activation-event.d.ts} +6 -6
- package/dist/types/src/core/activation-event.d.ts.map +1 -0
- package/dist/types/src/core/capability-manager.d.ts +43 -0
- package/dist/types/src/core/capability-manager.d.ts.map +1 -0
- package/dist/types/src/core/capability-manager.test.d.ts +2 -0
- package/dist/types/src/core/capability-manager.test.d.ts.map +1 -0
- package/dist/types/src/core/capability.d.ts +150 -0
- package/dist/types/src/core/capability.d.ts.map +1 -0
- package/dist/types/src/core/index.d.ts +5 -4
- package/dist/types/src/core/index.d.ts.map +1 -1
- package/dist/types/src/core/plugin-manager.d.ts +66 -0
- package/dist/types/src/core/plugin-manager.d.ts.map +1 -0
- package/dist/types/src/core/plugin-manager.test.d.ts +2 -0
- package/dist/types/src/core/plugin-manager.test.d.ts.map +1 -0
- package/dist/types/src/core/plugin.d.ts +97 -32
- package/dist/types/src/core/plugin.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +3 -4
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/plugin-operation/OperationPlugin.d.ts +3 -0
- package/dist/types/src/plugin-operation/OperationPlugin.d.ts.map +1 -0
- package/dist/types/src/plugin-operation/history/capability.d.ts +7 -0
- package/dist/types/src/plugin-operation/history/capability.d.ts.map +1 -0
- package/dist/types/src/plugin-operation/history/errors.d.ts +5 -0
- package/dist/types/src/plugin-operation/history/errors.d.ts.map +1 -0
- package/dist/types/src/plugin-operation/history/history-tracker.d.ts +18 -0
- package/dist/types/src/plugin-operation/history/history-tracker.d.ts.map +1 -0
- package/dist/types/src/plugin-operation/history/history-tracker.test.d.ts +2 -0
- package/dist/types/src/plugin-operation/history/history-tracker.test.d.ts.map +1 -0
- package/dist/types/src/plugin-operation/history/index.d.ts +6 -0
- package/dist/types/src/plugin-operation/history/index.d.ts.map +1 -0
- package/dist/types/src/plugin-operation/history/types.d.ts +13 -0
- package/dist/types/src/plugin-operation/history/types.d.ts.map +1 -0
- package/dist/types/src/plugin-operation/history/undo-mapping.d.ts +101 -0
- package/dist/types/src/plugin-operation/history/undo-mapping.d.ts.map +1 -0
- package/dist/types/src/plugin-operation/history/undo-registry.d.ts +23 -0
- package/dist/types/src/plugin-operation/history/undo-registry.d.ts.map +1 -0
- package/dist/types/src/plugin-operation/history/undo-registry.test.d.ts +2 -0
- package/dist/types/src/plugin-operation/history/undo-registry.test.d.ts.map +1 -0
- package/dist/types/src/plugin-operation/index.d.ts +3 -0
- package/dist/types/src/plugin-operation/index.d.ts.map +1 -0
- package/dist/types/src/plugin-operation/invoker-capability.d.ts +6 -0
- package/dist/types/src/plugin-operation/invoker-capability.d.ts.map +1 -0
- package/dist/types/src/plugin-operation/meta.d.ts +3 -0
- package/dist/types/src/plugin-operation/meta.d.ts.map +1 -0
- package/dist/types/src/plugin-operation/testing.d.ts +109 -0
- package/dist/types/src/plugin-operation/testing.d.ts.map +1 -0
- package/dist/types/src/plugin-runtime/RuntimePlugin.d.ts +3 -0
- package/dist/types/src/plugin-runtime/RuntimePlugin.d.ts.map +1 -0
- package/dist/types/src/plugin-runtime/capability.d.ts +6 -0
- package/dist/types/src/plugin-runtime/capability.d.ts.map +1 -0
- package/dist/types/src/plugin-runtime/index.d.ts +2 -0
- package/dist/types/src/plugin-runtime/index.d.ts.map +1 -0
- package/dist/types/src/plugin-runtime/meta.d.ts +3 -0
- package/dist/types/src/plugin-runtime/meta.d.ts.map +1 -0
- package/dist/types/src/testing/index.d.ts +1 -0
- package/dist/types/src/testing/index.d.ts.map +1 -1
- package/dist/types/src/testing/service.d.ts +8 -0
- package/dist/types/src/testing/service.d.ts.map +1 -0
- package/dist/types/src/testing/withPluginManager.d.ts +11 -10
- package/dist/types/src/testing/withPluginManager.d.ts.map +1 -1
- package/dist/types/src/testing/withPluginManager.stories.d.ts +9 -3
- package/dist/types/src/testing/withPluginManager.stories.d.ts.map +1 -1
- package/dist/types/src/ui/components/App.d.ts +8 -0
- package/dist/types/src/ui/components/App.d.ts.map +1 -0
- package/dist/types/src/ui/components/App.stories.d.ts +14 -0
- package/dist/types/src/ui/components/App.stories.d.ts.map +1 -0
- package/dist/types/src/ui/components/DefaultFallback.d.ts +8 -0
- package/dist/types/src/ui/components/DefaultFallback.d.ts.map +1 -0
- package/dist/types/src/ui/components/ErrorBoundary.d.ts +30 -0
- package/dist/types/src/ui/components/ErrorBoundary.d.ts.map +1 -0
- package/dist/types/src/ui/components/PluginManagerContext.stories.d.ts +13 -0
- package/dist/types/src/ui/components/PluginManagerContext.stories.d.ts.map +1 -0
- package/dist/types/src/ui/components/PluginManagerProvider.d.ts +10 -0
- package/dist/types/src/ui/components/PluginManagerProvider.d.ts.map +1 -0
- package/dist/types/src/ui/components/index.d.ts +5 -0
- package/dist/types/src/ui/components/index.d.ts.map +1 -0
- package/dist/types/src/ui/components/surface/SurfaceComponent.d.ts +12 -0
- package/dist/types/src/ui/components/surface/SurfaceComponent.d.ts.map +1 -0
- package/dist/types/src/ui/components/surface/SurfaceComponent.stories.d.ts +14 -0
- package/dist/types/src/ui/components/surface/SurfaceComponent.stories.d.ts.map +1 -0
- package/dist/types/src/ui/components/surface/SurfaceInfo.d.ts +11 -0
- package/dist/types/src/ui/components/surface/SurfaceInfo.d.ts.map +1 -0
- package/dist/types/src/ui/components/surface/context.d.ts +5 -0
- package/dist/types/src/ui/components/surface/context.d.ts.map +1 -0
- package/dist/types/src/ui/components/surface/index.d.ts +5 -0
- package/dist/types/src/ui/components/surface/index.d.ts.map +1 -0
- package/dist/types/src/ui/components/surface/types.d.ts +94 -0
- package/dist/types/src/ui/components/surface/types.d.ts.map +1 -0
- package/dist/types/src/ui/hooks/index.d.ts +7 -0
- package/dist/types/src/ui/hooks/index.d.ts.map +1 -0
- package/dist/types/src/{App.d.ts → ui/hooks/useApp.d.ts} +16 -9
- package/dist/types/src/ui/hooks/useApp.d.ts.map +1 -0
- package/dist/types/src/ui/hooks/useCapabilities.d.ts +31 -0
- package/dist/types/src/ui/hooks/useCapabilities.d.ts.map +1 -0
- package/dist/types/src/ui/hooks/useLoading.d.ts +18 -0
- package/dist/types/src/ui/hooks/useLoading.d.ts.map +1 -0
- package/dist/types/src/ui/hooks/useOperationResolver.d.ts +19 -0
- package/dist/types/src/ui/hooks/useOperationResolver.d.ts.map +1 -0
- package/dist/types/src/ui/hooks/useSettingsState.d.ts +10 -0
- package/dist/types/src/ui/hooks/useSettingsState.d.ts.map +1 -0
- package/dist/types/src/ui/hooks/useSurface.d.ts +3 -0
- package/dist/types/src/ui/hooks/useSurface.d.ts.map +1 -0
- package/dist/types/src/ui/index.d.ts +4 -0
- package/dist/types/src/ui/index.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/moon.yml +25 -0
- package/package.json +113 -45
- package/src/cli/cli.ts +107 -0
- package/src/{playground/layout → cli}/index.ts +1 -1
- package/src/common/activation-events.ts +44 -0
- package/src/common/capabilities.ts +174 -108
- package/src/common/index.ts +4 -8
- package/src/common/operations.ts +38 -0
- package/src/common/translations.ts +18 -10
- package/src/context.ts +9 -0
- package/src/core/{events.ts → activation-event.ts} +5 -5
- package/src/core/capability-manager.test.ts +151 -0
- package/src/core/capability-manager.ts +171 -0
- package/src/core/capability.ts +236 -0
- package/src/core/index.ts +5 -4
- package/src/core/plugin-manager.test.ts +845 -0
- package/src/core/plugin-manager.ts +696 -0
- package/src/core/plugin.ts +229 -36
- package/src/helpers.test.ts +1 -1
- package/src/index.ts +3 -4
- package/src/plugin-operation/OperationPlugin.ts +25 -0
- package/src/plugin-operation/history/capability.ts +37 -0
- package/src/plugin-operation/history/errors.ts +11 -0
- package/src/plugin-operation/history/history-tracker.test.ts +380 -0
- package/src/plugin-operation/history/history-tracker.ts +129 -0
- package/src/plugin-operation/history/index.ts +9 -0
- package/src/plugin-operation/history/types.ts +17 -0
- package/src/plugin-operation/history/undo-mapping.ts +135 -0
- package/src/plugin-operation/history/undo-registry.test.ts +73 -0
- package/src/plugin-operation/history/undo-registry.ts +54 -0
- package/src/plugin-operation/index.ts +6 -0
- package/src/plugin-operation/invoker-capability.ts +40 -0
- package/src/plugin-operation/meta.ts +11 -0
- package/src/plugin-operation/testing.ts +174 -0
- package/src/plugin-runtime/RuntimePlugin.ts +20 -0
- package/src/plugin-runtime/capability.ts +53 -0
- package/src/{playground/logger → plugin-runtime}/index.ts +1 -1
- package/src/plugin-runtime/meta.ts +11 -0
- package/src/testing/index.ts +1 -0
- package/src/testing/service.ts +52 -0
- package/src/testing/withPluginManager.stories.tsx +15 -11
- package/src/testing/withPluginManager.tsx +43 -44
- package/src/ui/components/App.stories.tsx +62 -0
- package/src/ui/components/App.tsx +57 -0
- package/src/ui/components/DefaultFallback.tsx +26 -0
- package/src/ui/components/ErrorBoundary.tsx +56 -0
- package/src/ui/components/PluginManagerContext.stories.tsx +183 -0
- package/src/{react → ui/components}/PluginManagerProvider.ts +3 -3
- package/src/ui/components/index.ts +8 -0
- package/src/ui/components/surface/SurfaceComponent.stories.tsx +142 -0
- package/src/ui/components/surface/SurfaceComponent.tsx +262 -0
- package/src/ui/components/surface/SurfaceInfo.tsx +107 -0
- package/src/ui/components/surface/context.ts +12 -0
- package/src/ui/components/surface/index.ts +8 -0
- package/src/ui/components/surface/types.ts +119 -0
- package/src/ui/hooks/index.ts +10 -0
- package/src/ui/hooks/useApp.tsx +215 -0
- package/src/ui/hooks/useCapabilities.ts +67 -0
- package/src/ui/hooks/useLoading.tsx +68 -0
- package/src/ui/hooks/useOperationResolver.ts +40 -0
- package/src/ui/hooks/useSettingsState.ts +26 -0
- package/src/ui/hooks/useSurface.ts +13 -0
- package/src/ui/index.ts +7 -0
- package/tsconfig.json +13 -29
- package/vitest.config.ts +8 -3
- package/.eslintrc.cjs +0 -9
- package/README.yml +0 -5
- package/dist/lib/browser/app-graph-builder-BI4VVKSW.mjs +0 -137
- package/dist/lib/browser/app-graph-builder-BI4VVKSW.mjs.map +0 -7
- package/dist/lib/browser/chunk-DIBVO47Z.mjs +0 -406
- package/dist/lib/browser/chunk-DIBVO47Z.mjs.map +0 -7
- package/dist/lib/browser/chunk-EHM4UI3V.mjs +0 -1518
- package/dist/lib/browser/chunk-EHM4UI3V.mjs.map +0 -7
- package/dist/lib/browser/chunk-WWEJRWFX.mjs +0 -32
- package/dist/lib/browser/chunk-WWEJRWFX.mjs.map +0 -7
- package/dist/lib/browser/intent-dispatcher-XVBOMF2Y.mjs +0 -11
- package/dist/lib/browser/intent-resolver-3QMBXLIY.mjs +0 -39
- package/dist/lib/browser/intent-resolver-3QMBXLIY.mjs.map +0 -7
- package/dist/lib/browser/store-5H7XPJGA.mjs +0 -30
- package/dist/lib/browser/store-5H7XPJGA.mjs.map +0 -7
- package/dist/lib/browser/worker.mjs +0 -79
- package/dist/lib/node/app-graph-builder-H7QVE4MJ.cjs +0 -146
- package/dist/lib/node/app-graph-builder-H7QVE4MJ.cjs.map +0 -7
- package/dist/lib/node/chunk-G774ASXO.cjs +0 -58
- package/dist/lib/node/chunk-G774ASXO.cjs.map +0 -7
- package/dist/lib/node/chunk-VSOSVDQ3.cjs +0 -1551
- package/dist/lib/node/chunk-VSOSVDQ3.cjs.map +0 -7
- package/dist/lib/node/chunk-YGAY3H34.cjs +0 -429
- package/dist/lib/node/chunk-YGAY3H34.cjs.map +0 -7
- package/dist/lib/node/index.cjs +0 -193
- package/dist/lib/node/index.cjs.map +0 -7
- package/dist/lib/node/intent-dispatcher-C3SVKJ62.cjs +0 -32
- package/dist/lib/node/intent-dispatcher-C3SVKJ62.cjs.map +0 -7
- package/dist/lib/node/intent-resolver-IOJDYO34.cjs +0 -46
- package/dist/lib/node/intent-resolver-IOJDYO34.cjs.map +0 -7
- package/dist/lib/node/meta.json +0 -1
- package/dist/lib/node/store-ESF5VR57.cjs +0 -45
- package/dist/lib/node/store-ESF5VR57.cjs.map +0 -7
- package/dist/lib/node/testing/index.cjs +0 -119
- package/dist/lib/node/testing/index.cjs.map +0 -7
- package/dist/lib/node/worker.cjs +0 -101
- package/dist/lib/node/worker.cjs.map +0 -7
- package/dist/lib/node-esm/app-graph-builder-NROP6RPQ.mjs +0 -138
- package/dist/lib/node-esm/app-graph-builder-NROP6RPQ.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-2J6FVECI.mjs +0 -1520
- package/dist/lib/node-esm/chunk-2J6FVECI.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-FHNZZWP4.mjs +0 -407
- package/dist/lib/node-esm/chunk-FHNZZWP4.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-I6BVZMAH.mjs +0 -34
- package/dist/lib/node-esm/chunk-I6BVZMAH.mjs.map +0 -7
- package/dist/lib/node-esm/intent-dispatcher-7JPGLCQ5.mjs +0 -12
- package/dist/lib/node-esm/intent-resolver-VY4X5UHN.mjs +0 -40
- package/dist/lib/node-esm/intent-resolver-VY4X5UHN.mjs.map +0 -7
- package/dist/lib/node-esm/store-UKD2R2KA.mjs +0 -31
- package/dist/lib/node-esm/store-UKD2R2KA.mjs.map +0 -7
- package/dist/lib/node-esm/worker.mjs +0 -80
- package/dist/types/src/App.d.ts.map +0 -1
- package/dist/types/src/common/collaboration.d.ts +0 -19
- package/dist/types/src/common/collaboration.d.ts.map +0 -1
- package/dist/types/src/common/events.d.ts +0 -52
- package/dist/types/src/common/events.d.ts.map +0 -1
- package/dist/types/src/common/file.d.ts +0 -14
- package/dist/types/src/common/file.d.ts.map +0 -1
- package/dist/types/src/common/graph.d.ts +0 -21
- package/dist/types/src/common/graph.d.ts.map +0 -1
- package/dist/types/src/common/layout.d.ts +0 -281
- package/dist/types/src/common/layout.d.ts.map +0 -1
- package/dist/types/src/common/surface.d.ts +0 -65
- package/dist/types/src/common/surface.d.ts.map +0 -1
- package/dist/types/src/core/capabilities.d.ts +0 -114
- package/dist/types/src/core/capabilities.d.ts.map +0 -1
- package/dist/types/src/core/capabilities.test.d.ts +0 -2
- package/dist/types/src/core/capabilities.test.d.ts.map +0 -1
- package/dist/types/src/core/events.d.ts.map +0 -1
- package/dist/types/src/core/manager.d.ts +0 -122
- package/dist/types/src/core/manager.d.ts.map +0 -1
- package/dist/types/src/core/manager.test.d.ts +0 -2
- package/dist/types/src/core/manager.test.d.ts.map +0 -1
- package/dist/types/src/playground/debug/Debug.d.ts +0 -6
- package/dist/types/src/playground/debug/Debug.d.ts.map +0 -1
- package/dist/types/src/playground/debug/index.d.ts +0 -2
- package/dist/types/src/playground/debug/index.d.ts.map +0 -1
- package/dist/types/src/playground/debug/plugin.d.ts +0 -2
- package/dist/types/src/playground/debug/plugin.d.ts.map +0 -1
- package/dist/types/src/playground/generator/Main.d.ts +0 -6
- package/dist/types/src/playground/generator/Main.d.ts.map +0 -1
- package/dist/types/src/playground/generator/Toolbar.d.ts +0 -6
- package/dist/types/src/playground/generator/Toolbar.d.ts.map +0 -1
- package/dist/types/src/playground/generator/generator.d.ts +0 -7
- package/dist/types/src/playground/generator/generator.d.ts.map +0 -1
- package/dist/types/src/playground/generator/index.d.ts +0 -3
- package/dist/types/src/playground/generator/index.d.ts.map +0 -1
- package/dist/types/src/playground/generator/plugin.d.ts +0 -2
- package/dist/types/src/playground/generator/plugin.d.ts.map +0 -1
- package/dist/types/src/playground/layout/Layout.d.ts +0 -8
- package/dist/types/src/playground/layout/Layout.d.ts.map +0 -1
- package/dist/types/src/playground/layout/index.d.ts +0 -2
- package/dist/types/src/playground/layout/index.d.ts.map +0 -1
- package/dist/types/src/playground/layout/plugin.d.ts +0 -2
- package/dist/types/src/playground/layout/plugin.d.ts.map +0 -1
- package/dist/types/src/playground/logger/Toolbar.d.ts +0 -6
- package/dist/types/src/playground/logger/Toolbar.d.ts.map +0 -1
- package/dist/types/src/playground/logger/index.d.ts +0 -2
- package/dist/types/src/playground/logger/index.d.ts.map +0 -1
- package/dist/types/src/playground/logger/plugin.d.ts +0 -2
- package/dist/types/src/playground/logger/plugin.d.ts.map +0 -1
- package/dist/types/src/playground/logger/schema.d.ts +0 -13
- package/dist/types/src/playground/logger/schema.d.ts.map +0 -1
- package/dist/types/src/playground/playground.stories.d.ts +0 -10
- package/dist/types/src/playground/playground.stories.d.ts.map +0 -1
- package/dist/types/src/plugin-intent/IntentPlugin.d.ts +0 -2
- package/dist/types/src/plugin-intent/IntentPlugin.d.ts.map +0 -1
- package/dist/types/src/plugin-intent/actions.d.ts +0 -38
- package/dist/types/src/plugin-intent/actions.d.ts.map +0 -1
- package/dist/types/src/plugin-intent/errors.d.ts +0 -16
- package/dist/types/src/plugin-intent/errors.d.ts.map +0 -1
- package/dist/types/src/plugin-intent/index.d.ts +0 -5
- package/dist/types/src/plugin-intent/index.d.ts.map +0 -1
- package/dist/types/src/plugin-intent/intent-dispatcher.d.ts +0 -139
- package/dist/types/src/plugin-intent/intent-dispatcher.d.ts.map +0 -1
- package/dist/types/src/plugin-intent/intent-dispatcher.test.d.ts +0 -2
- package/dist/types/src/plugin-intent/intent-dispatcher.test.d.ts.map +0 -1
- package/dist/types/src/plugin-intent/intent.d.ts +0 -63
- package/dist/types/src/plugin-intent/intent.d.ts.map +0 -1
- package/dist/types/src/plugin-settings/SettingsPlugin.d.ts +0 -2
- package/dist/types/src/plugin-settings/SettingsPlugin.d.ts.map +0 -1
- package/dist/types/src/plugin-settings/actions.d.ts +0 -27
- package/dist/types/src/plugin-settings/actions.d.ts.map +0 -1
- package/dist/types/src/plugin-settings/app-graph-builder.d.ts +0 -4
- package/dist/types/src/plugin-settings/app-graph-builder.d.ts.map +0 -1
- package/dist/types/src/plugin-settings/index.d.ts +0 -3
- package/dist/types/src/plugin-settings/index.d.ts.map +0 -1
- package/dist/types/src/plugin-settings/intent-resolver.d.ts +0 -4
- package/dist/types/src/plugin-settings/intent-resolver.d.ts.map +0 -1
- package/dist/types/src/plugin-settings/store.d.ts +0 -5
- package/dist/types/src/plugin-settings/store.d.ts.map +0 -1
- package/dist/types/src/plugin-settings/translations.d.ts +0 -11
- package/dist/types/src/plugin-settings/translations.d.ts.map +0 -1
- package/dist/types/src/react/ErrorBoundary.d.ts +0 -31
- package/dist/types/src/react/ErrorBoundary.d.ts.map +0 -1
- package/dist/types/src/react/IntentContext.d.ts +0 -8
- package/dist/types/src/react/IntentContext.d.ts.map +0 -1
- package/dist/types/src/react/PluginManagerProvider.d.ts +0 -10
- package/dist/types/src/react/PluginManagerProvider.d.ts.map +0 -1
- package/dist/types/src/react/Surface.d.ts +0 -12
- package/dist/types/src/react/Surface.d.ts.map +0 -1
- package/dist/types/src/react/Surface.stories.d.ts +0 -16
- package/dist/types/src/react/Surface.stories.d.ts.map +0 -1
- package/dist/types/src/react/common.d.ts +0 -13
- package/dist/types/src/react/common.d.ts.map +0 -1
- package/dist/types/src/react/index.d.ts +0 -7
- package/dist/types/src/react/index.d.ts.map +0 -1
- package/dist/types/src/react/useCapabilities.d.ts +0 -13
- package/dist/types/src/react/useCapabilities.d.ts.map +0 -1
- package/dist/types/src/react/useIntentResolver.d.ts +0 -3
- package/dist/types/src/react/useIntentResolver.d.ts.map +0 -1
- package/dist/types/src/worker.d.ts +0 -4
- package/dist/types/src/worker.d.ts.map +0 -1
- package/project.json +0 -29
- package/src/App.tsx +0 -276
- package/src/common/collaboration.ts +0 -21
- package/src/common/events.ts +0 -77
- package/src/common/file.ts +0 -22
- package/src/common/graph.ts +0 -30
- package/src/common/layout.ts +0 -278
- package/src/common/surface.ts +0 -86
- package/src/core/capabilities.test.ts +0 -136
- package/src/core/capabilities.ts +0 -254
- package/src/core/manager.test.ts +0 -516
- package/src/core/manager.ts +0 -519
- package/src/playground/debug/Debug.tsx +0 -39
- package/src/playground/debug/index.ts +0 -5
- package/src/playground/debug/plugin.ts +0 -17
- package/src/playground/generator/Main.tsx +0 -71
- package/src/playground/generator/Toolbar.tsx +0 -46
- package/src/playground/generator/generator.ts +0 -48
- package/src/playground/generator/index.ts +0 -6
- package/src/playground/generator/plugin.ts +0 -23
- package/src/playground/layout/Layout.tsx +0 -33
- package/src/playground/layout/plugin.ts +0 -17
- package/src/playground/logger/Toolbar.tsx +0 -29
- package/src/playground/logger/plugin.ts +0 -36
- package/src/playground/logger/schema.ts +0 -12
- package/src/playground/playground.stories.tsx +0 -42
- package/src/plugin-intent/IntentPlugin.ts +0 -20
- package/src/plugin-intent/actions.ts +0 -33
- package/src/plugin-intent/errors.ts +0 -39
- package/src/plugin-intent/index.ts +0 -8
- package/src/plugin-intent/intent-dispatcher.test.ts +0 -279
- package/src/plugin-intent/intent-dispatcher.ts +0 -333
- package/src/plugin-intent/intent.ts +0 -154
- package/src/plugin-settings/SettingsPlugin.ts +0 -35
- package/src/plugin-settings/actions.ts +0 -29
- package/src/plugin-settings/app-graph-builder.ts +0 -157
- package/src/plugin-settings/index.ts +0 -6
- package/src/plugin-settings/intent-resolver.ts +0 -34
- package/src/plugin-settings/store.ts +0 -33
- package/src/plugin-settings/translations.ts +0 -17
- package/src/react/ErrorBoundary.tsx +0 -45
- package/src/react/IntentContext.tsx +0 -34
- package/src/react/Surface.stories.tsx +0 -96
- package/src/react/Surface.tsx +0 -77
- package/src/react/common.ts +0 -12
- package/src/react/index.ts +0 -10
- package/src/react/useCapabilities.ts +0 -30
- package/src/react/useIntentResolver.ts +0 -22
- package/src/worker.ts +0 -11
- package/typedoc/.nojekyll +0 -1
- package/typedoc/assets/hierarchy.js +0 -1
- package/typedoc/assets/highlight.css +0 -106
- package/typedoc/assets/icons.js +0 -18
- package/typedoc/assets/icons.svg +0 -1
- package/typedoc/assets/main.js +0 -60
- package/typedoc/assets/navigation.js +0 -1
- package/typedoc/assets/search.js +0 -1
- package/typedoc/assets/style.css +0 -1640
- package/typedoc/classes/CollaborationActions.InsertContent.html +0 -421
- package/typedoc/classes/ErrorBoundary.html +0 -125
- package/typedoc/classes/IntentAction.ShowUndo.html +0 -227
- package/typedoc/classes/IntentAction.Track.html +0 -266
- package/typedoc/classes/LayoutAction.AddToast.html +0 -265
- package/typedoc/classes/LayoutAction.Close.html +0 -382
- package/typedoc/classes/LayoutAction.Expose.html +0 -265
- package/typedoc/classes/LayoutAction.Open.html +0 -1123
- package/typedoc/classes/LayoutAction.RevertWorkspace.html +0 -343
- package/typedoc/classes/LayoutAction.ScrollIntoView.html +0 -460
- package/typedoc/classes/LayoutAction.Set.html +0 -460
- package/typedoc/classes/LayoutAction.SetLayoutMode.html +0 -499
- package/typedoc/classes/LayoutAction.SwitchWorkspace.html +0 -265
- package/typedoc/classes/LayoutAction.UpdateComplementary.html +0 -616
- package/typedoc/classes/LayoutAction.UpdateDialog.html +0 -1123
- package/typedoc/classes/LayoutAction.UpdateLayout.html +0 -461
- package/typedoc/classes/LayoutAction.UpdatePopover.html +0 -1435
- package/typedoc/classes/LayoutAction.UpdateSidebar.html +0 -616
- package/typedoc/classes/Plugin.html +0 -6
- package/typedoc/classes/PluginContext.html +0 -38
- package/typedoc/classes/PluginManager.html +0 -43
- package/typedoc/classes/PluginModule.html +0 -18
- package/typedoc/classes/SettingsAction.Open.html +0 -226
- package/typedoc/classes/SettingsAction.OpenPluginRegistry.html +0 -265
- package/typedoc/functions/Events.createStateEvent.html +0 -2
- package/typedoc/functions/IntentPlugin.html +0 -1
- package/typedoc/functions/SettingsPlugin.html +0 -1
- package/typedoc/functions/allOf.html +0 -2
- package/typedoc/functions/chain.html +0 -3
- package/typedoc/functions/contributes.html +0 -2
- package/typedoc/functions/createDispatcher.html +0 -3
- package/typedoc/functions/createIntent.html +0 -6
- package/typedoc/functions/createResolver.html +0 -2
- package/typedoc/functions/createSurface.html +0 -2
- package/typedoc/functions/defineCapability.html +0 -2
- package/typedoc/functions/defineEvent.html +0 -2
- package/typedoc/functions/defineModule.html +0 -2
- package/typedoc/functions/definePlugin.html +0 -2
- package/typedoc/functions/eventKey.html +0 -2
- package/typedoc/functions/getEvents.html +0 -2
- package/typedoc/functions/isAllOf.html +0 -2
- package/typedoc/functions/isOneOf.html +0 -2
- package/typedoc/functions/isSurfaceAvailable.html +0 -2
- package/typedoc/functions/lazy.html +0 -2
- package/typedoc/functions/oneOf.html +0 -2
- package/typedoc/functions/useApp.html +0 -6
- package/typedoc/functions/useAppGraph.html +0 -1
- package/typedoc/functions/useCapabilities.html +0 -3
- package/typedoc/functions/useCapability.html +0 -4
- package/typedoc/functions/useIntentDispatcher.html +0 -1
- package/typedoc/functions/useIntentResolver.html +0 -1
- package/typedoc/functions/useLayout.html +0 -1
- package/typedoc/functions/usePluginManager.html +0 -2
- package/typedoc/hierarchy.html +0 -1
- package/typedoc/index.html +0 -16
- package/typedoc/interfaces/LayoutAction.Toast.html +0 -10
- package/typedoc/media/LICENSE +0 -8
- package/typedoc/modules/Capabilities.html +0 -1
- package/typedoc/modules/CollaborationActions.html +0 -1
- package/typedoc/modules/Events.html +0 -1
- package/typedoc/modules/IntentAction.html +0 -1
- package/typedoc/modules/LayoutAction.html +0 -2
- package/typedoc/modules/SettingsAction.html +0 -1
- package/typedoc/modules.html +0 -1
- package/typedoc/types/ActivationEvent.html +0 -8
- package/typedoc/types/ActivationEvents.html +0 -2
- package/typedoc/types/AnyCapability.html +0 -1
- package/typedoc/types/AnyIntent.html +0 -1
- package/typedoc/types/AnyIntentChain.html +0 -1
- package/typedoc/types/AnyIntentEffectResult.html +0 -1
- package/typedoc/types/AnyIntentResolver.html +0 -1
- package/typedoc/types/AnyIntentResult.html +0 -1
- package/typedoc/types/Capabilities.FileUploader.html +0 -1
- package/typedoc/types/Capabilities.IntentResolver.html +0 -1
- package/typedoc/types/Capabilities.Layout.html +0 -1
- package/typedoc/types/Capabilities.Metadata.html +0 -1
- package/typedoc/types/Capabilities.ReactContext.html +0 -1
- package/typedoc/types/Capabilities.ReactRoot.html +0 -1
- package/typedoc/types/Capabilities.ReactSurface.html +0 -1
- package/typedoc/types/Capabilities.Settings.html +0 -4
- package/typedoc/types/Capability.html +0 -9
- package/typedoc/types/CreateAppOptions.html +0 -10
- package/typedoc/types/FileInfo.html +0 -1
- package/typedoc/types/Intent.html +0 -10
- package/typedoc/types/IntentChain.html +0 -6
- package/typedoc/types/IntentContext.html +0 -5
- package/typedoc/types/IntentData.html +0 -1
- package/typedoc/types/IntentDispatcher.html +0 -2
- package/typedoc/types/IntentDispatcherResult.html +0 -2
- package/typedoc/types/IntentEffectDefinition.html +0 -2
- package/typedoc/types/IntentEffectResult.html +0 -15
- package/typedoc/types/IntentParams.html +0 -3
- package/typedoc/types/IntentResolver.html +0 -2
- package/typedoc/types/IntentResultData.html +0 -1
- package/typedoc/types/IntentSchema.html +0 -1
- package/typedoc/types/IntentUndo.html +0 -2
- package/typedoc/types/InterfaceDef.html +0 -4
- package/typedoc/types/Label.html +0 -1
- package/typedoc/types/NodeSerializer.html +0 -8
- package/typedoc/types/PluginManagerOptions.html +0 -6
- package/typedoc/types/PluginMeta.html +0 -21
- package/typedoc/types/PromiseIntentDispatcher.html +0 -2
- package/typedoc/types/PromiseIntentUndo.html +0 -2
- package/typedoc/types/Resource.html +0 -1
- package/typedoc/types/ResourceKey.html +0 -1
- package/typedoc/types/ResourceLanguage.html +0 -1
- package/typedoc/types/SerializedNode.html +0 -4
- package/typedoc/types/SurfaceComponent.html +0 -2
- package/typedoc/types/SurfaceDefinition.html +0 -2
- package/typedoc/types/SurfaceProps.html +0 -4
- package/typedoc/variables/Capabilities.AnchorSort.html +0 -1
- package/typedoc/variables/Capabilities.AppGraph.html +0 -1
- package/typedoc/variables/Capabilities.AppGraphBuilder.html +0 -1
- package/typedoc/variables/Capabilities.AppGraphSerializer.html +0 -1
- package/typedoc/variables/Capabilities.ArtifactDefinition.html +0 -1
- package/typedoc/variables/Capabilities.FileUploader.html +0 -1
- package/typedoc/variables/Capabilities.IntentDispatcher.html +0 -1
- package/typedoc/variables/Capabilities.IntentResolver.html +0 -1
- package/typedoc/variables/Capabilities.Layout.html +0 -1
- package/typedoc/variables/Capabilities.Metadata.html +0 -1
- package/typedoc/variables/Capabilities.Null.html +0 -1
- package/typedoc/variables/Capabilities.PluginManager.html +0 -1
- package/typedoc/variables/Capabilities.ReactContext.html +0 -1
- package/typedoc/variables/Capabilities.ReactRoot.html +0 -1
- package/typedoc/variables/Capabilities.ReactSurface.html +0 -1
- package/typedoc/variables/Capabilities.RxRegistry.html +0 -1
- package/typedoc/variables/Capabilities.Settings.html +0 -1
- package/typedoc/variables/Capabilities.SettingsStore.html +0 -1
- package/typedoc/variables/Capabilities.Tools.html +0 -1
- package/typedoc/variables/Capabilities.Translations.html +0 -1
- package/typedoc/variables/Events.AppGraphReady.html +0 -2
- package/typedoc/variables/Events.DispatcherReady.html +0 -2
- package/typedoc/variables/Events.LayoutReady.html +0 -1
- package/typedoc/variables/Events.SettingsReady.html +0 -2
- package/typedoc/variables/Events.SetupAppGraph.html +0 -2
- package/typedoc/variables/Events.SetupArtifactDefinition.html +0 -2
- package/typedoc/variables/Events.SetupIntentResolver.html +0 -2
- package/typedoc/variables/Events.SetupMetadata.html +0 -2
- package/typedoc/variables/Events.SetupReactSurface.html +0 -2
- package/typedoc/variables/Events.SetupSettings.html +0 -2
- package/typedoc/variables/Events.SetupTranslations.html +0 -2
- package/typedoc/variables/Events.Startup.html +0 -2
- package/typedoc/variables/FileInfoSchema.html +0 -1
- package/typedoc/variables/INTENT_ACTION.html +0 -1
- package/typedoc/variables/INTENT_PLUGIN.html +0 -1
- package/typedoc/variables/LAYOUT_ACTION.html +0 -1
- package/typedoc/variables/LAYOUT_PLUGIN.html +0 -1
- package/typedoc/variables/Label.html +0 -1
- package/typedoc/variables/LayoutAction.Toast.html +0 -1
- package/typedoc/variables/LayoutAction.UPDATE_LAYOUT.html +0 -1
- package/typedoc/variables/PluginManagerProvider.html +0 -2
- package/typedoc/variables/Resource.html +0 -2
- package/typedoc/variables/ResourceKey.html +0 -1
- package/typedoc/variables/ResourceLanguage.html +0 -1
- package/typedoc/variables/SETTINGS_ACTION.html +0 -1
- package/typedoc/variables/SETTINGS_ID.html +0 -1
- package/typedoc/variables/SETTINGS_KEY.html +0 -1
- package/typedoc/variables/SETTINGS_PLUGIN.html +0 -1
- package/typedoc/variables/Surface.html +0 -2
- package/typedoc/variables/defaultFileTypes.html +0 -1
- /package/dist/lib/browser/{intent-dispatcher-XVBOMF2Y.mjs.map → chunk-J5LGTIGS.mjs.map} +0 -0
- /package/dist/lib/browser/{worker.mjs.map → chunk-YAFEA4GV.mjs.map} +0 -0
- /package/dist/lib/{node-esm/intent-dispatcher-7JPGLCQ5.mjs.map → browser/common/activation-events.mjs.map} +0 -0
- /package/dist/lib/{node-esm/worker.mjs.map → browser/common/capabilities.mjs.map} +0 -0
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { type Meta, type StoryObj } from '@storybook/react-vite';
|
|
6
|
+
import React, { forwardRef, useCallback, useEffect, useRef, useState } from 'react';
|
|
7
|
+
|
|
8
|
+
import { faker } from '@dxos/random';
|
|
9
|
+
import { List, ListItem, Toolbar } from '@dxos/react-ui';
|
|
10
|
+
import { withTheme } from '@dxos/react-ui/testing';
|
|
11
|
+
import { type ColorStyles, getHashStyles, mx } from '@dxos/ui-theme';
|
|
12
|
+
|
|
13
|
+
import { Capabilities } from '../../../common';
|
|
14
|
+
import { withPluginManager } from '../../../testing';
|
|
15
|
+
import { usePluginManager } from '../PluginManagerProvider';
|
|
16
|
+
|
|
17
|
+
import { Surface, useSurfaces } from './SurfaceComponent';
|
|
18
|
+
import { create } from './types';
|
|
19
|
+
|
|
20
|
+
type TestComponentProps = {
|
|
21
|
+
id: string;
|
|
22
|
+
styles: ColorStyles;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const TestComponent = forwardRef<HTMLDivElement, TestComponentProps>(({ styles, id }, forwardedRef) => {
|
|
26
|
+
return (
|
|
27
|
+
<div
|
|
28
|
+
className={mx('flex justify-center items-center border rounded', styles.surface, styles.border)}
|
|
29
|
+
ref={forwardedRef}
|
|
30
|
+
>
|
|
31
|
+
<span className={mx('dx-tag font-mono text-lg', styles.text)}>{id}</span>
|
|
32
|
+
</div>
|
|
33
|
+
);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
const DefaultStory = () => {
|
|
37
|
+
const manager = usePluginManager();
|
|
38
|
+
const surfaces = useSurfaces();
|
|
39
|
+
const [selected, setSelected] = useState<string | undefined>();
|
|
40
|
+
|
|
41
|
+
const handleAdd = useCallback(() => {
|
|
42
|
+
const id = `test-${faker.number.int({ min: 0, max: 1_000 })}`;
|
|
43
|
+
const styles = getHashStyles(id);
|
|
44
|
+
manager.capabilities.contribute({
|
|
45
|
+
module: 'test',
|
|
46
|
+
interface: Capabilities.ReactSurface,
|
|
47
|
+
implementation: create({
|
|
48
|
+
id,
|
|
49
|
+
role: 'item',
|
|
50
|
+
filter: (data): data is any => (data as any)?.id === id,
|
|
51
|
+
component: ({ ref }) => <TestComponent id={id} styles={styles} ref={ref} />,
|
|
52
|
+
}),
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
setSelected(id);
|
|
56
|
+
}, [manager]);
|
|
57
|
+
|
|
58
|
+
const handleSelect = useCallback(() => {
|
|
59
|
+
setSelected(faker.helpers.arrayElement(surfaces)?.id);
|
|
60
|
+
}, [surfaces]);
|
|
61
|
+
|
|
62
|
+
const handleError = useCallback(() => {
|
|
63
|
+
manager.capabilities.contribute({
|
|
64
|
+
module: 'error',
|
|
65
|
+
interface: Capabilities.ReactSurface,
|
|
66
|
+
implementation: create({
|
|
67
|
+
id: 'error',
|
|
68
|
+
role: 'item',
|
|
69
|
+
filter: (data): data is any => (data as any)?.id === 'error',
|
|
70
|
+
component: () => {
|
|
71
|
+
const [count, setCount] = useState(3);
|
|
72
|
+
useEffect(() => {
|
|
73
|
+
const interval = setInterval(() => {
|
|
74
|
+
setCount((count) => {
|
|
75
|
+
if (count <= 1) {
|
|
76
|
+
clearInterval(interval);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return count - 1;
|
|
80
|
+
});
|
|
81
|
+
}, 1_000);
|
|
82
|
+
return () => clearInterval(interval);
|
|
83
|
+
}, []);
|
|
84
|
+
|
|
85
|
+
if (count <= 0) {
|
|
86
|
+
throw new Error('BANG!');
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return (
|
|
90
|
+
<div className='flex justify-center items-center border border-roseFill rounded'>
|
|
91
|
+
<span className='font-mono'>Ticking... {count}</span>
|
|
92
|
+
</div>
|
|
93
|
+
);
|
|
94
|
+
},
|
|
95
|
+
}),
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
setSelected('error');
|
|
99
|
+
}, [manager]);
|
|
100
|
+
|
|
101
|
+
const ref = useRef<HTMLElement>(null);
|
|
102
|
+
useEffect(() => {
|
|
103
|
+
console.log(ref.current);
|
|
104
|
+
}, [ref]);
|
|
105
|
+
|
|
106
|
+
return (
|
|
107
|
+
<div className='flex flex-col bs-full overflow-hidden'>
|
|
108
|
+
<Toolbar.Root>
|
|
109
|
+
<Toolbar.Button onClick={handleAdd}>Add</Toolbar.Button>
|
|
110
|
+
<Toolbar.Button onClick={handleSelect}>Pick</Toolbar.Button>
|
|
111
|
+
<Toolbar.Button onClick={handleError}>Error</Toolbar.Button>
|
|
112
|
+
</Toolbar.Root>
|
|
113
|
+
<div className='grid grid-cols-2 bs-full gap-4 overflow-hidden'>
|
|
114
|
+
<Surface role='item' data={selected ? { id: selected } : undefined} limit={1} ref={ref} />
|
|
115
|
+
<div className='overflow-y-auto bs-full'>
|
|
116
|
+
<List>
|
|
117
|
+
{surfaces.map((surface) => (
|
|
118
|
+
<ListItem.Root key={surface.id} id={surface.id}>
|
|
119
|
+
<ListItem.Heading classNames='flex items-center'>{surface.id}</ListItem.Heading>
|
|
120
|
+
</ListItem.Root>
|
|
121
|
+
))}
|
|
122
|
+
</List>
|
|
123
|
+
</div>
|
|
124
|
+
</div>
|
|
125
|
+
</div>
|
|
126
|
+
);
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
const meta = {
|
|
130
|
+
title: 'sdk/app-framework/Surface',
|
|
131
|
+
render: DefaultStory,
|
|
132
|
+
decorators: [withTheme(), withPluginManager({ capabilities: [] })],
|
|
133
|
+
parameters: {
|
|
134
|
+
layout: 'fullscreen',
|
|
135
|
+
},
|
|
136
|
+
} satisfies Meta<typeof DefaultStory>;
|
|
137
|
+
|
|
138
|
+
export default meta;
|
|
139
|
+
|
|
140
|
+
type Story = StoryObj<typeof meta>;
|
|
141
|
+
|
|
142
|
+
export const Default: Story = {};
|
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import React, {
|
|
6
|
+
Fragment,
|
|
7
|
+
type NamedExoticComponent,
|
|
8
|
+
type RefAttributes,
|
|
9
|
+
Suspense,
|
|
10
|
+
forwardRef,
|
|
11
|
+
memo,
|
|
12
|
+
useEffect,
|
|
13
|
+
useMemo,
|
|
14
|
+
useRef,
|
|
15
|
+
} from 'react';
|
|
16
|
+
|
|
17
|
+
import { log } from '@dxos/log';
|
|
18
|
+
import { useDefaultValue } from '@dxos/react-hooks';
|
|
19
|
+
import { ScrollArea } from '@dxos/react-ui';
|
|
20
|
+
import { byPosition } from '@dxos/util';
|
|
21
|
+
|
|
22
|
+
import { Capabilities } from '../../../common';
|
|
23
|
+
import { type CapabilityManager } from '../../../core';
|
|
24
|
+
import { useCapabilities } from '../../hooks';
|
|
25
|
+
import { ErrorBoundary } from '../ErrorBoundary';
|
|
26
|
+
|
|
27
|
+
import { SurfaceContext } from './context';
|
|
28
|
+
import { SurfaceInfo } from './SurfaceInfo';
|
|
29
|
+
import { type Definition, type Props, type WebComponentDefinition } from './types';
|
|
30
|
+
|
|
31
|
+
const DEFAULT_PLACEHOLDER = <Fragment />;
|
|
32
|
+
|
|
33
|
+
const DEBUG = import.meta.env.VITE_DEBUG;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Wrapper component for rendering Web Component surfaces.
|
|
37
|
+
* Handles creation, prop setting, and cleanup of Web Components.
|
|
38
|
+
*/
|
|
39
|
+
const WebComponentWrapper = memo(
|
|
40
|
+
forwardRef<HTMLElement, Props & { definition: WebComponentDefinition }>(
|
|
41
|
+
({ id, role, data, limit, definition, ...rest }, forwardedRef) => {
|
|
42
|
+
const containerRef = useRef<HTMLDivElement>(null);
|
|
43
|
+
const elementRef = useRef<HTMLElement | null>(null);
|
|
44
|
+
const propsRef = useRef({ id, role, data, limit, ...rest });
|
|
45
|
+
|
|
46
|
+
// Update props ref on every render
|
|
47
|
+
propsRef.current = { id, role, data, limit, ...rest };
|
|
48
|
+
|
|
49
|
+
// Create element only once
|
|
50
|
+
useEffect(() => {
|
|
51
|
+
if (!containerRef.current || elementRef.current) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// Create the Web Component
|
|
56
|
+
const element = document.createElement(definition.tagName);
|
|
57
|
+
elementRef.current = element;
|
|
58
|
+
|
|
59
|
+
// Set initial properties on the Web Component
|
|
60
|
+
Object.assign(element, propsRef.current);
|
|
61
|
+
|
|
62
|
+
// Append to container
|
|
63
|
+
containerRef.current.appendChild(element);
|
|
64
|
+
|
|
65
|
+
// Setup ref forwarding if provided
|
|
66
|
+
if (typeof forwardedRef === 'function') {
|
|
67
|
+
forwardedRef(element);
|
|
68
|
+
} else if (forwardedRef) {
|
|
69
|
+
forwardedRef.current = element;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// Cleanup on unmount to prevent memory leaks
|
|
73
|
+
return () => {
|
|
74
|
+
if (elementRef.current && containerRef.current?.contains(elementRef.current)) {
|
|
75
|
+
containerRef.current.removeChild(elementRef.current);
|
|
76
|
+
}
|
|
77
|
+
if (typeof forwardedRef === 'function') {
|
|
78
|
+
forwardedRef(null);
|
|
79
|
+
} else if (forwardedRef) {
|
|
80
|
+
forwardedRef.current = null;
|
|
81
|
+
}
|
|
82
|
+
elementRef.current = null;
|
|
83
|
+
};
|
|
84
|
+
}, [definition.tagName, forwardedRef]);
|
|
85
|
+
|
|
86
|
+
// Update props on existing element without recreating it
|
|
87
|
+
// This runs on every render to ensure all props (including those in `rest`) are kept up to date
|
|
88
|
+
useEffect(() => {
|
|
89
|
+
const element = elementRef.current;
|
|
90
|
+
if (!element) {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// Update properties on the existing Web Component
|
|
95
|
+
Object.assign(element, propsRef.current);
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
return <div ref={containerRef} />;
|
|
99
|
+
},
|
|
100
|
+
),
|
|
101
|
+
);
|
|
102
|
+
|
|
103
|
+
WebComponentWrapper.displayName = 'WebComponentWrapper';
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Wrapper component that provides context for a surface.
|
|
107
|
+
*/
|
|
108
|
+
const SurfaceContextProvider = memo(
|
|
109
|
+
forwardRef<HTMLElement, Props & { definition: Definition }>(
|
|
110
|
+
({ id, role, data, limit, fallback = DefaultFallback, definition, ...rest }, forwardedRef) => {
|
|
111
|
+
const contextValue = useMemo(() => ({ id, role, data }), [id, role, data]);
|
|
112
|
+
|
|
113
|
+
// Handle Web Component surfaces
|
|
114
|
+
if (definition.kind === 'web-component') {
|
|
115
|
+
return (
|
|
116
|
+
<ErrorBoundary data={data} fallback={fallback}>
|
|
117
|
+
<SurfaceContext.Provider value={contextValue}>
|
|
118
|
+
<WebComponentWrapper
|
|
119
|
+
id={id}
|
|
120
|
+
role={role}
|
|
121
|
+
data={data}
|
|
122
|
+
limit={limit}
|
|
123
|
+
definition={definition}
|
|
124
|
+
ref={forwardedRef}
|
|
125
|
+
{...rest}
|
|
126
|
+
/>
|
|
127
|
+
</SurfaceContext.Provider>
|
|
128
|
+
</ErrorBoundary>
|
|
129
|
+
);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// Handle React component surfaces
|
|
133
|
+
const Component = definition.component;
|
|
134
|
+
|
|
135
|
+
// TODO(burdon): Remove from production build?
|
|
136
|
+
const debug = DEBUG || '__DX_DEBUG__' in window;
|
|
137
|
+
if (debug) {
|
|
138
|
+
return (
|
|
139
|
+
<ErrorBoundary data={data} fallback={fallback}>
|
|
140
|
+
<div role='none' className='contents' data-id={id} data-role={role}>
|
|
141
|
+
<SurfaceContext.Provider value={contextValue}>
|
|
142
|
+
<SurfaceInfo ref={forwardedRef}>
|
|
143
|
+
<Component id={id} role={role} data={data} limit={limit} {...rest} />
|
|
144
|
+
</SurfaceInfo>
|
|
145
|
+
</SurfaceContext.Provider>
|
|
146
|
+
</div>
|
|
147
|
+
</ErrorBoundary>
|
|
148
|
+
);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
return (
|
|
152
|
+
<ErrorBoundary data={data} fallback={fallback}>
|
|
153
|
+
<div role='none' className='contents' data-id={id} data-role={role}>
|
|
154
|
+
<SurfaceContext.Provider value={contextValue}>
|
|
155
|
+
<Component id={id} role={role} data={data} limit={limit} {...rest} ref={forwardedRef} />
|
|
156
|
+
</SurfaceContext.Provider>
|
|
157
|
+
</div>
|
|
158
|
+
</ErrorBoundary>
|
|
159
|
+
);
|
|
160
|
+
},
|
|
161
|
+
),
|
|
162
|
+
);
|
|
163
|
+
|
|
164
|
+
SurfaceContextProvider.displayName = 'SurfaceContextProvider';
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* A surface is a named region of the screen that can be populated by plugins.
|
|
168
|
+
*/
|
|
169
|
+
// TODO(burdon): Remove ref since relying on this would be error prone.
|
|
170
|
+
export const Surface: NamedExoticComponent<Props & RefAttributes<HTMLElement>> = memo(
|
|
171
|
+
forwardRef(({ id: _id, role, data: dataProp, limit, placeholder = DEFAULT_PLACEHOLDER, ...rest }, forwardedRef) => {
|
|
172
|
+
const data = useDefaultValue(dataProp, () => ({}));
|
|
173
|
+
|
|
174
|
+
// TODO(wittjosiah): This will make all surfaces depend on a single signal.
|
|
175
|
+
// This isn't ideal because it means that any change to the data will cause all surfaces to re-render.
|
|
176
|
+
// This effectively means that plugin modules which contribute surfaces need to all be activated at startup.
|
|
177
|
+
// This should be fine for now because it's how it worked prior to capabilities api anyway.
|
|
178
|
+
// In the future, it would be nice to be able to bucket the surface contributions by role.
|
|
179
|
+
const surfaces = useSurfaces();
|
|
180
|
+
|
|
181
|
+
// NOTE: Memoizing the candidates makes the surface not re-render based on reactivity within data.
|
|
182
|
+
const definitions = findCandidates(surfaces, { role, data });
|
|
183
|
+
const candidates = limit ? definitions.slice(0, limit) : definitions;
|
|
184
|
+
if (DEBUG && candidates.length === 0) {
|
|
185
|
+
log.warn('no candidates for surface', { role, data });
|
|
186
|
+
return null;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
return (
|
|
190
|
+
<Suspense fallback={placeholder}>
|
|
191
|
+
{candidates.map((definition) => (
|
|
192
|
+
<SurfaceContextProvider
|
|
193
|
+
key={definition.id}
|
|
194
|
+
id={definition.id}
|
|
195
|
+
role={role}
|
|
196
|
+
data={data}
|
|
197
|
+
limit={limit}
|
|
198
|
+
definition={definition}
|
|
199
|
+
ref={forwardedRef}
|
|
200
|
+
{...rest}
|
|
201
|
+
/>
|
|
202
|
+
))}
|
|
203
|
+
</Suspense>
|
|
204
|
+
);
|
|
205
|
+
}),
|
|
206
|
+
);
|
|
207
|
+
|
|
208
|
+
Surface.displayName = 'Surface';
|
|
209
|
+
|
|
210
|
+
const findCandidates = (surfaces: Definition[], { role, data }: Pick<Props, 'role' | 'data'>) => {
|
|
211
|
+
return Object.values(surfaces)
|
|
212
|
+
.filter((definition) =>
|
|
213
|
+
Array.isArray(definition.role) ? definition.role.includes(role) : definition.role === role,
|
|
214
|
+
)
|
|
215
|
+
.filter(({ filter }) => (filter ? filter(data ?? {}) : true))
|
|
216
|
+
.toSorted(byPosition);
|
|
217
|
+
};
|
|
218
|
+
|
|
219
|
+
// TODO(burdon): Make user facing, with telemetry.
|
|
220
|
+
// TODO(burdon): Change based on dev/prod mode; infer subject type, id.
|
|
221
|
+
const DefaultFallback = ({ data, error, dev }: { data: any; error: Error; dev?: boolean }) => {
|
|
222
|
+
if (dev) {
|
|
223
|
+
return (
|
|
224
|
+
<ScrollArea.Root orientation='vertical'>
|
|
225
|
+
<ScrollArea.Viewport classNames='p-4 gap-4'>
|
|
226
|
+
<h1 className='flex gap-2 text-sm mbs-2'>{error.message}</h1>
|
|
227
|
+
<pre className='overflow-auto text-xs text-description'>{JSON.stringify(data, null, 2)}</pre>
|
|
228
|
+
</ScrollArea.Viewport>
|
|
229
|
+
</ScrollArea.Root>
|
|
230
|
+
);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
return (
|
|
234
|
+
<ScrollArea.Root orientation='vertical'>
|
|
235
|
+
<ScrollArea.Viewport classNames='p-4 gap-4 border border-roseFill'>
|
|
236
|
+
<h1 className='flex gap-2 text-sm mbs-2 text-errorText'>{error.message}</h1>
|
|
237
|
+
<pre className='overflow-x-auto text-xs text-description'>{error.stack}</pre>
|
|
238
|
+
<pre className='overflow-x-auto text-xs text-description'>{JSON.stringify(data, null, 2)}</pre>
|
|
239
|
+
</ScrollArea.Viewport>
|
|
240
|
+
</ScrollArea.Root>
|
|
241
|
+
);
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* @internal
|
|
246
|
+
*/
|
|
247
|
+
export const useSurfaces = () => {
|
|
248
|
+
const surfaces = useCapabilities(Capabilities.ReactSurface);
|
|
249
|
+
return useMemo(() => surfaces.flat(), [surfaces]);
|
|
250
|
+
};
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* @returns `true` if there is a contributed surface which matches the specified role & data, `false` otherwise.
|
|
254
|
+
*/
|
|
255
|
+
export const isSurfaceAvailable = (
|
|
256
|
+
capabilityManager: CapabilityManager.CapabilityManager,
|
|
257
|
+
{ role, data }: Pick<Props, 'role' | 'data'>,
|
|
258
|
+
) => {
|
|
259
|
+
const surfaces = capabilityManager.getAll(Capabilities.ReactSurface);
|
|
260
|
+
const candidates = findCandidates(surfaces.flat(), { role, data });
|
|
261
|
+
return candidates.length > 0;
|
|
262
|
+
};
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import React, {
|
|
6
|
+
type ReactElement,
|
|
7
|
+
type Ref,
|
|
8
|
+
cloneElement,
|
|
9
|
+
forwardRef,
|
|
10
|
+
useCallback,
|
|
11
|
+
useLayoutEffect,
|
|
12
|
+
useState,
|
|
13
|
+
} from 'react';
|
|
14
|
+
import { createPortal } from 'react-dom';
|
|
15
|
+
|
|
16
|
+
import { addEventListener, combine } from '@dxos/async';
|
|
17
|
+
import { useMergeRefs } from '@dxos/react-hooks';
|
|
18
|
+
|
|
19
|
+
import { useSurface } from '../../hooks';
|
|
20
|
+
|
|
21
|
+
export type SurfaceInfoProps = {
|
|
22
|
+
children: ReactElement<{ ref?: Ref<HTMLElement> }>;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Debug wrapper for surfaces.
|
|
27
|
+
*/
|
|
28
|
+
export const SurfaceInfo = forwardRef<HTMLElement, SurfaceInfoProps>(({ children }, forwardedRef) => {
|
|
29
|
+
const [rect, setRect] = useState<DOMRect | null>(null);
|
|
30
|
+
const [expand, setExpand] = useState(false);
|
|
31
|
+
const info = useSurface();
|
|
32
|
+
|
|
33
|
+
const [root, setRoot] = useState<HTMLElement | null>(null);
|
|
34
|
+
const measureRef = useCallback((node: HTMLElement | null) => setRoot(node), []);
|
|
35
|
+
const mergedRef = useMergeRefs([measureRef, forwardedRef]);
|
|
36
|
+
const childWithRef = cloneElement(children, { ref: mergedRef });
|
|
37
|
+
|
|
38
|
+
useLayoutEffect(() => {
|
|
39
|
+
if (!root) {
|
|
40
|
+
setRect(null);
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const measure = () => {
|
|
45
|
+
setRect(root.getBoundingClientRect());
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const observer = new ResizeObserver(measure);
|
|
49
|
+
observer.observe(root);
|
|
50
|
+
measure();
|
|
51
|
+
|
|
52
|
+
return combine(
|
|
53
|
+
addEventListener(window, 'scroll', measure, true),
|
|
54
|
+
addEventListener(window, 'resize', measure),
|
|
55
|
+
() => {
|
|
56
|
+
observer.disconnect();
|
|
57
|
+
},
|
|
58
|
+
);
|
|
59
|
+
}, [root]);
|
|
60
|
+
|
|
61
|
+
const padding = 0;
|
|
62
|
+
return (
|
|
63
|
+
<>
|
|
64
|
+
{childWithRef}
|
|
65
|
+
{rect &&
|
|
66
|
+
createPortal(
|
|
67
|
+
<div
|
|
68
|
+
role='none'
|
|
69
|
+
className='z-[100] fixed flex flex-col-reverse scrollbar-none overflow-auto pointer-events-none'
|
|
70
|
+
style={{
|
|
71
|
+
top: rect.top + padding,
|
|
72
|
+
left: rect.left + padding,
|
|
73
|
+
width: rect.width - padding * 2,
|
|
74
|
+
height: rect.height - padding * 2,
|
|
75
|
+
}}
|
|
76
|
+
>
|
|
77
|
+
{expand ? (
|
|
78
|
+
<div
|
|
79
|
+
className='absolute inset-0 bg-deckSurface border border-green-500 cursor-pointer pointer-events-auto overflow-auto'
|
|
80
|
+
onPointerDown={(ev) => ev.stopPropagation()}
|
|
81
|
+
onClick={(ev) => {
|
|
82
|
+
ev.stopPropagation();
|
|
83
|
+
setExpand(false);
|
|
84
|
+
}}
|
|
85
|
+
>
|
|
86
|
+
<pre className='p-2 text-xs text-description font-mono'>{JSON.stringify({ info }, null, 2)}</pre>
|
|
87
|
+
</div>
|
|
88
|
+
) : (
|
|
89
|
+
<span
|
|
90
|
+
className='absolute right-1 bottom-0 flex items-center p-1 text-green-500 opacity-80 hover:opacity-100 text-xl cursor-pointer pointer-events-auto'
|
|
91
|
+
title={info.id}
|
|
92
|
+
onPointerDown={(ev) => ev.stopPropagation()}
|
|
93
|
+
onClick={(ev) => {
|
|
94
|
+
ev.stopPropagation();
|
|
95
|
+
setExpand(true);
|
|
96
|
+
}}
|
|
97
|
+
>
|
|
98
|
+
ⓘ
|
|
99
|
+
</span>
|
|
100
|
+
)}
|
|
101
|
+
</div>,
|
|
102
|
+
// TODO(burdon): Create well-known element to gather all debug portals.
|
|
103
|
+
document.body,
|
|
104
|
+
)}
|
|
105
|
+
</>
|
|
106
|
+
);
|
|
107
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { type Context, createContext } from 'react';
|
|
6
|
+
|
|
7
|
+
import { type Props } from './types';
|
|
8
|
+
|
|
9
|
+
export type SurfaceContext = Pick<Props, 'id' | 'role' | 'data'>;
|
|
10
|
+
|
|
11
|
+
// TODO(burdon): Use @radix-ui/react-context
|
|
12
|
+
export const SurfaceContext: Context<SurfaceContext | undefined> = createContext<SurfaceContext | undefined>(undefined);
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2023 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import type { PropsWithChildren, ReactNode, RefCallback } from 'react';
|
|
6
|
+
|
|
7
|
+
import type { MakeOptional, Position } from '@dxos/util';
|
|
8
|
+
|
|
9
|
+
import type { ErrorBoundary } from '..';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Props that are passed to the Surface component.
|
|
13
|
+
*/
|
|
14
|
+
export type Props<T extends Record<string, any> = Record<string, unknown>> = {
|
|
15
|
+
/**
|
|
16
|
+
* If specified, the Surface will be wrapped in an error boundary.
|
|
17
|
+
* The fallback component will be rendered if an error occurs.
|
|
18
|
+
*/
|
|
19
|
+
fallback?: ErrorBoundary['props']['fallback'];
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* If specified, the Surface will be wrapped in a suspense boundary.
|
|
23
|
+
* The placeholder component will be rendered while the surface component is loading.
|
|
24
|
+
*/
|
|
25
|
+
placeholder?: ReactNode;
|
|
26
|
+
} & MakeOptional<CoreProps<T>, 'id' | 'data'> &
|
|
27
|
+
/**
|
|
28
|
+
* Additional props to pass to the component.
|
|
29
|
+
* These props are not used by Surface itself but may be used by components which resolve the surface.
|
|
30
|
+
* Exclude known prop names to prevent overriding well-defined props.
|
|
31
|
+
*/
|
|
32
|
+
{
|
|
33
|
+
[K in keyof Record<string, any>]: K extends keyof CoreProps<T> | 'fallback' | 'placeholder' ? never : any;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* NOTE: If `[key: string]: unknown` is included in shared types, when re-used other fields become unknown as well.
|
|
38
|
+
*/
|
|
39
|
+
export type CoreProps<T extends Record<string, any> = Record<string, unknown>> = PropsWithChildren<{
|
|
40
|
+
/**
|
|
41
|
+
* ID for debugging.
|
|
42
|
+
*/
|
|
43
|
+
id: string;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Role defines how the data should be rendered.
|
|
47
|
+
*/
|
|
48
|
+
role: string;
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* The data to be rendered by the surface.
|
|
52
|
+
* NOTE: This must be a stable value.
|
|
53
|
+
*/
|
|
54
|
+
data: T;
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* If more than one component is resolved, the limit determines how many are rendered.
|
|
58
|
+
*/
|
|
59
|
+
limit?: number | undefined;
|
|
60
|
+
}>;
|
|
61
|
+
|
|
62
|
+
// TODO(burdon): Remove ref since relying on this would be error prone.
|
|
63
|
+
export type ComponentProps<T extends Record<string, any> = Record<string, any>> = CoreProps<T> & {
|
|
64
|
+
ref?: RefCallback<HTMLElement>;
|
|
65
|
+
} & Record<string, any>;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* React component used to render a surface once is has matched.
|
|
69
|
+
*/
|
|
70
|
+
export type ComponentFunction<T extends Record<string, any> = Record<string, any>> = (
|
|
71
|
+
props: ComponentProps<T>,
|
|
72
|
+
) => ReactNode;
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Definition of when a React component surface should be rendered.
|
|
76
|
+
*/
|
|
77
|
+
export type ReactDefinition<T extends Record<string, any> = any> = Readonly<{
|
|
78
|
+
kind: 'react';
|
|
79
|
+
id: string;
|
|
80
|
+
role: string | string[];
|
|
81
|
+
position?: Position;
|
|
82
|
+
component: ComponentFunction<T>;
|
|
83
|
+
filter?: (data: Record<string, unknown>) => data is T;
|
|
84
|
+
}>;
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Definition of when a Web Component surface should be rendered.
|
|
88
|
+
*/
|
|
89
|
+
export type WebComponentDefinition<T extends Record<string, any> = any> = Readonly<{
|
|
90
|
+
kind: 'web-component';
|
|
91
|
+
id: string;
|
|
92
|
+
role: string | string[];
|
|
93
|
+
position?: Position;
|
|
94
|
+
/**
|
|
95
|
+
* The tag name of the Web Component to render.
|
|
96
|
+
* The Web Component will receive the same props as React surfaces via properties/attributes.
|
|
97
|
+
*/
|
|
98
|
+
tagName: string;
|
|
99
|
+
filter?: (data: Record<string, unknown>) => data is T;
|
|
100
|
+
}>;
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Definition of when a surface (React or Web Component) should be rendered.
|
|
104
|
+
*/
|
|
105
|
+
export type Definition<T extends Record<string, any> = any> = ReactDefinition<T> | WebComponentDefinition<T>;
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Creates a React surface definition.
|
|
109
|
+
*/
|
|
110
|
+
export const create = <T extends Record<string, any> = any>(
|
|
111
|
+
definition: Omit<ReactDefinition<T>, 'kind'>,
|
|
112
|
+
): ReactDefinition<T> => ({ ...definition, kind: 'react' });
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Creates a Web Component surface definition.
|
|
116
|
+
*/
|
|
117
|
+
export const createWeb = <T extends Record<string, any> = any>(
|
|
118
|
+
definition: Omit<WebComponentDefinition<T>, 'kind'>,
|
|
119
|
+
): WebComponentDefinition<T> => ({ ...definition, kind: 'web-component' });
|