@dxos/app-framework 0.8.4-main.f9ba587 → 0.8.4-main.fffef41
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/.swc/plugins/{v7_linux_x86_64_13.0.0/fce1bdb8e20a094e4af08bad09cc81497ed0e2e7c51223b07d371063cca18429 → linux_x86_64_19.0.0/fce1bdb8e20a094e4af08bad09cc81497ed0e2e7c51223b07d371063cca18429.wasmer-v7} +0 -0
- package/dist/lib/browser/{app-graph-builder-BGGXLD6T.mjs → app-graph-builder-OIEZZC45.mjs} +32 -31
- package/dist/lib/browser/app-graph-builder-OIEZZC45.mjs.map +7 -0
- package/dist/lib/browser/{chunk-DHZB7HG7.mjs → chunk-6XKO24JP.mjs} +254 -184
- package/dist/lib/browser/chunk-6XKO24JP.mjs.map +7 -0
- package/dist/lib/browser/{chunk-ORWHM7CO.mjs → chunk-SCPE4ZO2.mjs} +11 -8
- package/dist/lib/browser/chunk-SCPE4ZO2.mjs.map +7 -0
- package/dist/lib/browser/{chunk-2636QSIK.mjs → chunk-WPW5VVAX.mjs} +399 -266
- package/dist/lib/browser/chunk-WPW5VVAX.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +20 -56
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/{intent-dispatcher-TWKB22NI.mjs → intent-dispatcher-LZ4AE66E.mjs} +2 -2
- package/dist/lib/browser/{intent-resolver-O67UANYP.mjs → intent-resolver-QVCKRX6G.mjs} +7 -7
- package/dist/lib/browser/intent-resolver-QVCKRX6G.mjs.map +7 -0
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/react/index.mjs +34 -0
- package/dist/lib/browser/{store-LFKDWHUQ.mjs → store-CNPHOYTJ.mjs} +5 -5
- package/dist/lib/browser/store-CNPHOYTJ.mjs.map +7 -0
- package/dist/lib/browser/testing/index.mjs +17 -21
- package/dist/lib/browser/testing/index.mjs.map +3 -3
- package/dist/lib/node-esm/{app-graph-builder-QHIJUYYW.mjs → app-graph-builder-EBU4NVWD.mjs} +32 -31
- package/dist/lib/node-esm/app-graph-builder-EBU4NVWD.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-NJAFK626.mjs → chunk-3UPX5OIS.mjs} +254 -184
- package/dist/lib/node-esm/chunk-3UPX5OIS.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-VSKRV3NW.mjs → chunk-XJZGUJ3H.mjs} +399 -266
- package/dist/lib/node-esm/chunk-XJZGUJ3H.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-UMZQERLE.mjs → chunk-ZX63QUGE.mjs} +11 -8
- package/dist/lib/node-esm/chunk-ZX63QUGE.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +20 -56
- package/dist/lib/node-esm/index.mjs.map +3 -3
- package/dist/lib/node-esm/{intent-dispatcher-5PRM3KGH.mjs → intent-dispatcher-MGOJ3CHD.mjs} +2 -2
- package/dist/lib/node-esm/{intent-resolver-K3D4BXQQ.mjs → intent-resolver-URF3HN3G.mjs} +7 -7
- package/dist/lib/node-esm/intent-resolver-URF3HN3G.mjs.map +7 -0
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/react/index.mjs +35 -0
- package/dist/lib/node-esm/{store-53XDUBMD.mjs → store-RK5B4XEL.mjs} +5 -5
- package/dist/lib/node-esm/store-RK5B4XEL.mjs.map +7 -0
- package/dist/lib/node-esm/testing/index.mjs +17 -21
- package/dist/lib/node-esm/testing/index.mjs.map +3 -3
- package/dist/types/src/common/capabilities.d.ts +111 -38
- package/dist/types/src/common/capabilities.d.ts.map +1 -1
- package/dist/types/src/common/collaboration.d.ts +10 -9
- package/dist/types/src/common/collaboration.d.ts.map +1 -1
- package/dist/types/src/common/events.d.ts.map +1 -1
- package/dist/types/src/common/file.d.ts +1 -1
- package/dist/types/src/common/file.d.ts.map +1 -1
- package/dist/types/src/common/layout.d.ts +1 -3
- package/dist/types/src/common/layout.d.ts.map +1 -1
- package/dist/types/src/common/surface.d.ts +19 -16
- package/dist/types/src/common/surface.d.ts.map +1 -1
- package/dist/types/src/common/translations.d.ts +1 -1
- package/dist/types/src/common/translations.d.ts.map +1 -1
- package/dist/types/src/core/capabilities.d.ts +19 -16
- package/dist/types/src/core/capabilities.d.ts.map +1 -1
- package/dist/types/src/core/manager.d.ts +7 -3
- package/dist/types/src/core/manager.d.ts.map +1 -1
- package/dist/types/src/core/plugin.d.ts +8 -1
- package/dist/types/src/core/plugin.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +0 -2
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/playground/debug/Debug.d.ts +1 -1
- package/dist/types/src/playground/debug/plugin.d.ts +1 -1
- package/dist/types/src/playground/debug/plugin.d.ts.map +1 -1
- package/dist/types/src/playground/generator/Main.d.ts +1 -1
- package/dist/types/src/playground/generator/Main.d.ts.map +1 -1
- package/dist/types/src/playground/generator/Toolbar.d.ts +1 -1
- package/dist/types/src/playground/generator/Toolbar.d.ts.map +1 -1
- package/dist/types/src/playground/generator/generator.d.ts +1 -1
- package/dist/types/src/playground/generator/generator.d.ts.map +1 -1
- package/dist/types/src/playground/generator/plugin.d.ts +1 -1
- package/dist/types/src/playground/generator/plugin.d.ts.map +1 -1
- package/dist/types/src/playground/layout/Layout.d.ts +2 -2
- package/dist/types/src/playground/layout/plugin.d.ts +1 -1
- package/dist/types/src/playground/layout/plugin.d.ts.map +1 -1
- package/dist/types/src/playground/logger/Toolbar.d.ts +1 -1
- package/dist/types/src/playground/logger/Toolbar.d.ts.map +1 -1
- package/dist/types/src/playground/logger/plugin.d.ts +1 -1
- package/dist/types/src/playground/logger/plugin.d.ts.map +1 -1
- package/dist/types/src/playground/logger/schema.d.ts +1 -1
- package/dist/types/src/playground/logger/schema.d.ts.map +1 -1
- package/dist/types/src/playground/playground.stories.d.ts +5 -4
- package/dist/types/src/playground/playground.stories.d.ts.map +1 -1
- package/dist/types/src/plugin-intent/IntentPlugin.d.ts +1 -1
- package/dist/types/src/plugin-intent/IntentPlugin.d.ts.map +1 -1
- package/dist/types/src/plugin-intent/actions.d.ts +5 -7
- package/dist/types/src/plugin-intent/actions.d.ts.map +1 -1
- package/dist/types/src/plugin-intent/errors.d.ts.map +1 -1
- package/dist/types/src/plugin-intent/index.d.ts +1 -0
- package/dist/types/src/plugin-intent/index.d.ts.map +1 -1
- package/dist/types/src/plugin-intent/intent-dispatcher.d.ts +7 -7
- package/dist/types/src/plugin-intent/intent-dispatcher.d.ts.map +1 -1
- package/dist/types/src/plugin-intent/intent.d.ts +1 -1
- package/dist/types/src/plugin-intent/intent.d.ts.map +1 -1
- package/dist/types/src/plugin-intent/meta.d.ts +3 -0
- package/dist/types/src/plugin-intent/meta.d.ts.map +1 -0
- package/dist/types/src/plugin-settings/SettingsPlugin.d.ts +1 -1
- package/dist/types/src/plugin-settings/SettingsPlugin.d.ts.map +1 -1
- package/dist/types/src/plugin-settings/actions.d.ts +5 -7
- package/dist/types/src/plugin-settings/actions.d.ts.map +1 -1
- package/dist/types/src/plugin-settings/app-graph-builder.d.ts +1 -1
- package/dist/types/src/plugin-settings/app-graph-builder.d.ts.map +1 -1
- package/dist/types/src/plugin-settings/intent-resolver.d.ts +1 -1
- package/dist/types/src/plugin-settings/intent-resolver.d.ts.map +1 -1
- package/dist/types/src/plugin-settings/meta.d.ts +3 -0
- package/dist/types/src/plugin-settings/meta.d.ts.map +1 -0
- package/dist/types/src/plugin-settings/store.d.ts +1 -1
- package/dist/types/src/plugin-settings/store.d.ts.map +1 -1
- package/dist/types/src/plugin-settings/translations.d.ts +2 -1
- package/dist/types/src/plugin-settings/translations.d.ts.map +1 -1
- package/dist/types/src/react/App.d.ts +10 -0
- package/dist/types/src/react/App.d.ts.map +1 -0
- package/dist/types/src/react/App.stories.d.ts +14 -0
- package/dist/types/src/react/App.stories.d.ts.map +1 -0
- package/dist/types/src/react/DefaultFallback.d.ts +8 -0
- package/dist/types/src/react/DefaultFallback.d.ts.map +1 -0
- package/dist/types/src/react/ErrorBoundary.d.ts +13 -14
- package/dist/types/src/react/ErrorBoundary.d.ts.map +1 -1
- package/dist/types/src/react/IntentContext.d.ts.map +1 -1
- package/dist/types/src/react/Surface.d.ts +5 -5
- package/dist/types/src/react/Surface.d.ts.map +1 -1
- package/dist/types/src/react/Surface.stories.d.ts +8 -10
- package/dist/types/src/react/Surface.stories.d.ts.map +1 -1
- package/dist/types/src/react/common.d.ts.map +1 -1
- package/dist/types/src/react/index.d.ts +2 -0
- package/dist/types/src/react/index.d.ts.map +1 -1
- package/dist/types/src/react/types.d.ts +14 -0
- package/dist/types/src/react/types.d.ts.map +1 -0
- package/dist/types/src/{App.d.ts → react/useApp.d.ts} +7 -6
- package/dist/types/src/react/useApp.d.ts.map +1 -0
- package/dist/types/src/react/useCapabilities.d.ts.map +1 -1
- package/dist/types/src/react/useLoading.d.ts +19 -0
- package/dist/types/src/react/useLoading.d.ts.map +1 -0
- package/dist/types/src/testing/withPluginManager.d.ts +9 -8
- 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/tsconfig.tsbuildinfo +1 -1
- package/moon.yml +5 -1
- package/package.json +46 -38
- package/src/common/capabilities.ts +120 -19
- package/src/common/collaboration.ts +6 -9
- package/src/common/events.ts +3 -1
- package/src/common/file.ts +1 -1
- package/src/common/layout.ts +3 -4
- package/src/common/surface.ts +23 -21
- package/src/common/translations.ts +1 -1
- package/src/core/capabilities.test.ts +3 -3
- package/src/core/capabilities.ts +36 -27
- package/src/core/manager.test.ts +22 -21
- package/src/core/manager.ts +141 -56
- package/src/core/plugin.ts +13 -2
- package/src/helpers.test.ts +1 -1
- package/src/index.ts +0 -2
- package/src/playground/debug/Debug.tsx +1 -1
- package/src/playground/debug/plugin.ts +7 -8
- package/src/playground/generator/Main.tsx +0 -1
- package/src/playground/generator/Toolbar.tsx +2 -1
- package/src/playground/generator/generator.ts +4 -4
- package/src/playground/generator/plugin.ts +12 -13
- package/src/playground/layout/plugin.ts +10 -9
- package/src/playground/logger/Toolbar.tsx +2 -1
- package/src/playground/logger/plugin.ts +30 -25
- package/src/playground/logger/schema.ts +1 -1
- package/src/playground/playground.stories.tsx +20 -16
- package/src/plugin-intent/IntentPlugin.ts +13 -13
- package/src/plugin-intent/actions.ts +4 -6
- package/src/plugin-intent/errors.ts +2 -1
- package/src/plugin-intent/index.ts +1 -0
- package/src/plugin-intent/intent-dispatcher.test.ts +10 -3
- package/src/plugin-intent/intent-dispatcher.ts +21 -12
- package/src/plugin-intent/intent.ts +1 -1
- package/src/plugin-intent/meta.ts +10 -0
- package/src/plugin-settings/SettingsPlugin.ts +27 -28
- package/src/plugin-settings/actions.ts +9 -13
- package/src/plugin-settings/app-graph-builder.ts +25 -22
- package/src/plugin-settings/intent-resolver.ts +5 -4
- package/src/plugin-settings/meta.ts +10 -0
- package/src/plugin-settings/store.ts +3 -3
- package/src/plugin-settings/translations.ts +4 -4
- package/src/react/App.stories.tsx +33 -0
- package/src/react/App.tsx +59 -0
- package/src/react/DefaultFallback.tsx +26 -0
- package/src/react/ErrorBoundary.tsx +26 -15
- package/src/react/IntentContext.tsx +3 -2
- package/src/react/Surface.stories.tsx +81 -52
- package/src/react/Surface.tsx +70 -38
- package/src/react/common.ts +2 -1
- package/src/react/index.ts +4 -0
- package/src/react/types.ts +38 -0
- package/src/react/useApp.tsx +165 -0
- package/src/react/useCapabilities.ts +4 -3
- package/src/react/useLoading.tsx +70 -0
- package/src/testing/withPluginManager.stories.tsx +9 -5
- package/src/testing/withPluginManager.tsx +33 -32
- package/tsconfig.json +15 -10
- package/vitest.config.ts +8 -6
- package/.eslintrc.cjs +0 -9
- package/.swc/plugins/v7_linux_x86_64_13.0.0/f45bdff002284d9e8f9ef3f0be909de12da36c049cbcf261ac78fc00abb09a2d +0 -0
- package/dist/lib/browser/app-graph-builder-BGGXLD6T.mjs.map +0 -7
- package/dist/lib/browser/chunk-2636QSIK.mjs.map +0 -7
- package/dist/lib/browser/chunk-DHZB7HG7.mjs.map +0 -7
- package/dist/lib/browser/chunk-ORWHM7CO.mjs.map +0 -7
- package/dist/lib/browser/intent-resolver-O67UANYP.mjs.map +0 -7
- package/dist/lib/browser/store-LFKDWHUQ.mjs.map +0 -7
- package/dist/lib/browser/worker.mjs +0 -79
- package/dist/lib/node-esm/app-graph-builder-QHIJUYYW.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-NJAFK626.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-UMZQERLE.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-VSKRV3NW.mjs.map +0 -7
- package/dist/lib/node-esm/intent-resolver-K3D4BXQQ.mjs.map +0 -7
- package/dist/lib/node-esm/store-53XDUBMD.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/worker.d.ts +0 -4
- package/dist/types/src/worker.d.ts.map +0 -1
- package/src/App.tsx +0 -276
- 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 -12
- 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-TWKB22NI.mjs.map → intent-dispatcher-LZ4AE66E.mjs.map} +0 -0
- /package/dist/lib/browser/{worker.mjs.map → react/index.mjs.map} +0 -0
- /package/dist/lib/node-esm/{intent-dispatcher-5PRM3KGH.mjs.map → intent-dispatcher-MGOJ3CHD.mjs.map} +0 -0
- /package/dist/lib/node-esm/{worker.mjs.map → react/index.mjs.map} +0 -0
package/src/react/Surface.tsx
CHANGED
|
@@ -2,76 +2,108 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import React, {
|
|
5
|
+
import React, {
|
|
6
|
+
Fragment,
|
|
7
|
+
type NamedExoticComponent,
|
|
8
|
+
type RefAttributes,
|
|
9
|
+
Suspense,
|
|
10
|
+
forwardRef,
|
|
11
|
+
memo,
|
|
12
|
+
useMemo,
|
|
13
|
+
} from 'react';
|
|
6
14
|
|
|
7
15
|
import { useDefaultValue } from '@dxos/react-hooks';
|
|
8
16
|
import { byPosition } from '@dxos/util';
|
|
9
17
|
|
|
10
|
-
import { ErrorBoundary } from './ErrorBoundary';
|
|
11
|
-
import { useCapabilities } from './useCapabilities';
|
|
12
18
|
import { Capabilities, type SurfaceDefinition, type SurfaceProps } from '../common';
|
|
13
19
|
import { type PluginContext } from '../core';
|
|
14
20
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* @internal
|
|
19
|
-
*/
|
|
20
|
-
export const useSurfaces = () => {
|
|
21
|
-
const surfaces = useCapabilities(Capabilities.ReactSurface);
|
|
22
|
-
return useMemo(() => surfaces.flat(), [surfaces]);
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
const findCandidates = (surfaces: SurfaceDefinition[], { role, data }: Pick<SurfaceProps, 'role' | 'data'>) => {
|
|
26
|
-
return Object.values(surfaces)
|
|
27
|
-
.filter((definition) =>
|
|
28
|
-
Array.isArray(definition.role) ? definition.role.includes(role) : definition.role === role,
|
|
29
|
-
)
|
|
30
|
-
.filter(({ filter }) => (filter ? filter(data ?? {}) : true))
|
|
31
|
-
.toSorted(byPosition);
|
|
32
|
-
};
|
|
21
|
+
import { ErrorBoundary } from './ErrorBoundary';
|
|
22
|
+
import { useCapabilities } from './useCapabilities';
|
|
33
23
|
|
|
34
|
-
|
|
35
|
-
* @returns `true` if there is a contributed surface which matches the specified role & data, `false` otherwise.
|
|
36
|
-
*/
|
|
37
|
-
export const isSurfaceAvailable = (context: PluginContext, { role, data }: Pick<SurfaceProps, 'role' | 'data'>) => {
|
|
38
|
-
const surfaces = context.getCapabilities(Capabilities.ReactSurface);
|
|
39
|
-
const candidates = findCandidates(surfaces.flat(), { role, data });
|
|
40
|
-
return candidates.length > 0;
|
|
41
|
-
};
|
|
24
|
+
const DEFAULT_PLACEHOLDER = <Fragment />;
|
|
42
25
|
|
|
43
26
|
/**
|
|
44
27
|
* A surface is a named region of the screen that can be populated by plugins.
|
|
45
28
|
*/
|
|
46
|
-
export const Surface = memo(
|
|
47
|
-
forwardRef
|
|
48
|
-
(
|
|
29
|
+
export const Surface: NamedExoticComponent<SurfaceProps & RefAttributes<HTMLElement>> = memo(
|
|
30
|
+
forwardRef(
|
|
31
|
+
(
|
|
32
|
+
{ id: _id, role, data: dataParam, limit, fallback = DefaultFallback, placeholder = DEFAULT_PLACEHOLDER, ...rest },
|
|
33
|
+
forwardedRef,
|
|
34
|
+
) => {
|
|
49
35
|
// TODO(wittjosiah): This will make all surfaces depend on a single signal.
|
|
50
36
|
// This isn't ideal because it means that any change to the data will cause all surfaces to re-render.
|
|
51
37
|
// This effectively means that plugin modules which contribute surfaces need to all be activated at startup.
|
|
52
|
-
// This should be fine for now because it's how it worked prior to capabilities api
|
|
38
|
+
// This should be fine for now because it's how it worked prior to capabilities api anyway.
|
|
53
39
|
// In the future, it would be nice to be able to bucket the surface contributions by role.
|
|
54
40
|
const surfaces = useSurfaces();
|
|
55
|
-
const data = useDefaultValue(
|
|
41
|
+
const data = useDefaultValue(dataParam, () => ({}));
|
|
56
42
|
|
|
57
43
|
// NOTE: Memoizing the candidates makes the surface not re-render based on reactivity within data.
|
|
58
44
|
const definitions = findCandidates(surfaces, { role, data });
|
|
59
45
|
const candidates = limit ? definitions.slice(0, limit) : definitions;
|
|
60
|
-
const nodes = candidates.map(({ component: Component
|
|
46
|
+
const nodes = candidates.map(({ id, component: Component }) => (
|
|
61
47
|
<Component ref={forwardedRef} key={id} id={id} role={role} data={data} limit={limit} {...rest} />
|
|
62
48
|
));
|
|
63
49
|
|
|
50
|
+
// TODO(burdon): Able to inject DOM properties into root (e.g., object.id).
|
|
64
51
|
const suspense = <Suspense fallback={placeholder}>{nodes}</Suspense>;
|
|
65
52
|
|
|
66
|
-
return
|
|
53
|
+
return (
|
|
67
54
|
<ErrorBoundary data={data} fallback={fallback}>
|
|
68
55
|
{suspense}
|
|
69
56
|
</ErrorBoundary>
|
|
70
|
-
) : (
|
|
71
|
-
suspense
|
|
72
57
|
);
|
|
73
58
|
},
|
|
74
59
|
),
|
|
75
60
|
);
|
|
76
61
|
|
|
62
|
+
// TODO(burdon): Make user facing, with telemetry.
|
|
63
|
+
// TODO(burdon): Change based on dev/prod mode; infer subject type, id.
|
|
64
|
+
const DefaultFallback = ({ data, error, dev }: { data: any; error: Error; dev?: boolean }) => {
|
|
65
|
+
if (dev) {
|
|
66
|
+
return (
|
|
67
|
+
<div className='flex flex-col gap-4 p-4 is-full overflow-y-auto'>
|
|
68
|
+
<h1 className='flex gap-2 text-sm mbs-2'>{error.message}</h1>
|
|
69
|
+
<pre className='overflow-auto text-xs text-description'>{JSON.stringify(data, null, 2)}</pre>
|
|
70
|
+
</div>
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return (
|
|
75
|
+
<div className='flex flex-col gap-4 p-4 is-full overflow-y-auto border border-roseFill'>
|
|
76
|
+
<h1 className='flex gap-2 text-sm mbs-2 text-rose-500'>{error.message}</h1>
|
|
77
|
+
<pre className='overflow-auto text-xs text-description'>{error.stack}</pre>
|
|
78
|
+
<pre className='overflow-auto text-xs text-description'>{JSON.stringify(data, null, 2)}</pre>
|
|
79
|
+
</div>
|
|
80
|
+
);
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* @internal
|
|
85
|
+
*/
|
|
86
|
+
export const useSurfaces = () => {
|
|
87
|
+
const surfaces = useCapabilities(Capabilities.ReactSurface);
|
|
88
|
+
return useMemo(() => surfaces.flat(), [surfaces]);
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* @returns `true` if there is a contributed surface which matches the specified role & data, `false` otherwise.
|
|
93
|
+
*/
|
|
94
|
+
export const isSurfaceAvailable = (context: PluginContext, { role, data }: Pick<SurfaceProps, 'role' | 'data'>) => {
|
|
95
|
+
const surfaces = context.getCapabilities(Capabilities.ReactSurface);
|
|
96
|
+
const candidates = findCandidates(surfaces.flat(), { role, data });
|
|
97
|
+
return candidates.length > 0;
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
const findCandidates = (surfaces: SurfaceDefinition[], { role, data }: Pick<SurfaceProps, 'role' | 'data'>) => {
|
|
101
|
+
return Object.values(surfaces)
|
|
102
|
+
.filter((definition) =>
|
|
103
|
+
Array.isArray(definition.role) ? definition.role.includes(role) : definition.role === role,
|
|
104
|
+
)
|
|
105
|
+
.filter(({ filter }) => (filter ? filter(data ?? {}) : true))
|
|
106
|
+
.toSorted(byPosition);
|
|
107
|
+
};
|
|
108
|
+
|
|
77
109
|
Surface.displayName = 'Surface';
|
package/src/react/common.ts
CHANGED
|
@@ -2,9 +2,10 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { useCapability } from './useCapabilities';
|
|
6
5
|
import { Capabilities } from '../common';
|
|
7
6
|
|
|
7
|
+
import { useCapability } from './useCapabilities';
|
|
8
|
+
|
|
8
9
|
export const useIntentDispatcher = () => useCapability(Capabilities.IntentDispatcher);
|
|
9
10
|
|
|
10
11
|
export const useAppGraph = () => useCapability(Capabilities.AppGraph);
|
package/src/react/index.ts
CHANGED
|
@@ -3,8 +3,12 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
export * from './common';
|
|
6
|
+
export * from './types';
|
|
7
|
+
|
|
6
8
|
export * from './ErrorBoundary';
|
|
7
9
|
export * from './PluginManagerProvider';
|
|
8
10
|
export * from './Surface';
|
|
11
|
+
|
|
12
|
+
export * from './useApp';
|
|
9
13
|
export * from './useCapabilities';
|
|
10
14
|
export * from './useIntentResolver';
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import * as Schema from 'effect/Schema';
|
|
6
|
+
|
|
7
|
+
import { type Obj } from '@dxos/echo';
|
|
8
|
+
|
|
9
|
+
export const SurfaceCardRole = Schema.Literal(
|
|
10
|
+
'card',
|
|
11
|
+
'card--popover',
|
|
12
|
+
'card--intrinsic',
|
|
13
|
+
'card--extrinsic',
|
|
14
|
+
'card--transclusion',
|
|
15
|
+
);
|
|
16
|
+
|
|
17
|
+
export type SurfaceCardRole = Schema.Schema.Type<typeof SurfaceCardRole>;
|
|
18
|
+
|
|
19
|
+
// TODO(burdon): Define all roles.
|
|
20
|
+
export type SurfaceRole =
|
|
21
|
+
| 'item'
|
|
22
|
+
| 'article'
|
|
23
|
+
| 'complementary' // (for companion?)
|
|
24
|
+
| 'section'
|
|
25
|
+
| SurfaceCardRole;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Base type for surface components.
|
|
29
|
+
*/
|
|
30
|
+
// TODO(burdon): Standardize PluginSettings and ObjectProperties.
|
|
31
|
+
// TODO(burdon): Include attendableId?
|
|
32
|
+
// TODO(burdon): companionTo?
|
|
33
|
+
export type SurfaceComponentProps<Subject extends Obj.Any = Obj.Any, Role extends string = string> = {
|
|
34
|
+
role?: Role;
|
|
35
|
+
|
|
36
|
+
/** The primary object being displayed. */
|
|
37
|
+
subject: Subject;
|
|
38
|
+
};
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { RegistryContext } from '@effect-atom/atom-react';
|
|
6
|
+
import { effect } from '@preact/signals-core';
|
|
7
|
+
import React, { type FC, useCallback, useEffect, useMemo } from 'react';
|
|
8
|
+
|
|
9
|
+
import { invariant } from '@dxos/invariant';
|
|
10
|
+
import { live } from '@dxos/live-object';
|
|
11
|
+
import { useAsyncEffect, useDefaultValue } from '@dxos/react-hooks';
|
|
12
|
+
|
|
13
|
+
import { Capabilities, Events } from '../common';
|
|
14
|
+
import { type Plugin, PluginManager, type PluginManagerOptions } from '../core';
|
|
15
|
+
|
|
16
|
+
import { App } from './App';
|
|
17
|
+
import { DefaultFallback } from './DefaultFallback';
|
|
18
|
+
import { ErrorBoundary } from './ErrorBoundary';
|
|
19
|
+
import { PluginManagerProvider } from './PluginManagerProvider';
|
|
20
|
+
|
|
21
|
+
const ENABLED_KEY = 'dxos.org/app-framework/enabled';
|
|
22
|
+
|
|
23
|
+
export type UseAppOptions = {
|
|
24
|
+
pluginManager?: PluginManager;
|
|
25
|
+
pluginLoader?: PluginManagerOptions['pluginLoader'];
|
|
26
|
+
plugins?: Plugin[];
|
|
27
|
+
core?: string[];
|
|
28
|
+
defaults?: string[];
|
|
29
|
+
placeholder?: FC<{ stage: number }>;
|
|
30
|
+
fallback?: ErrorBoundary['props']['fallback'];
|
|
31
|
+
cacheEnabled?: boolean;
|
|
32
|
+
safeMode?: boolean;
|
|
33
|
+
debounce?: number;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Expected usage is for this to be the entrypoint of the application.
|
|
38
|
+
* Initializes plugins and renders the root components.
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* const plugins = [LayoutPlugin(), MyPlugin()];
|
|
42
|
+
* const core = [LayoutPluginId];
|
|
43
|
+
* const default = [MyPluginId];
|
|
44
|
+
* const fallback = <div>Initializing Plugins...</div>;
|
|
45
|
+
* const App = useApp({ plugins, core, default, fallback });
|
|
46
|
+
* createRoot(document.getElementById('root')!).render(
|
|
47
|
+
* <StrictMode>
|
|
48
|
+
* <App />
|
|
49
|
+
* </StrictMode>,
|
|
50
|
+
* );
|
|
51
|
+
*
|
|
52
|
+
* @param params.pluginLoader A function which loads new plugins.
|
|
53
|
+
* @param params.plugins All plugins available to the application.
|
|
54
|
+
* @param params.core Core plugins which will always be enabled.
|
|
55
|
+
* @param params.defaults Default plugins are enabled by default but can be disabled by the user.
|
|
56
|
+
* @param params.placeholder Placeholder component to render during startup.
|
|
57
|
+
* @param params.fallback Fallback component to render if an error occurs during startup.
|
|
58
|
+
* @param params.cacheEnabled Whether to cache enabled plugins in localStorage.
|
|
59
|
+
* @param params.safeMode Whether to enable safe mode, which disables optional plugins.
|
|
60
|
+
*/
|
|
61
|
+
export const useApp = ({
|
|
62
|
+
pluginManager,
|
|
63
|
+
pluginLoader: pluginLoaderParam,
|
|
64
|
+
plugins: pluginsParam,
|
|
65
|
+
core: coreParam,
|
|
66
|
+
defaults: defaultsParam,
|
|
67
|
+
placeholder,
|
|
68
|
+
fallback = DefaultFallback,
|
|
69
|
+
cacheEnabled = false,
|
|
70
|
+
safeMode = false,
|
|
71
|
+
debounce = 0,
|
|
72
|
+
}: UseAppOptions) => {
|
|
73
|
+
const plugins = useDefaultValue(pluginsParam, () => []);
|
|
74
|
+
const core = useDefaultValue(coreParam, () => plugins.map(({ meta }) => meta.id));
|
|
75
|
+
const defaults = useDefaultValue(defaultsParam, () => []);
|
|
76
|
+
|
|
77
|
+
// TODO(wittjosiah): Provide a custom plugin loader which supports loading via url.
|
|
78
|
+
const pluginLoader = useMemo(
|
|
79
|
+
() =>
|
|
80
|
+
pluginLoaderParam ??
|
|
81
|
+
((id: string) => {
|
|
82
|
+
const plugin = plugins.find((plugin) => plugin.meta.id === id);
|
|
83
|
+
invariant(plugin, `Plugin not found: ${id}`);
|
|
84
|
+
return plugin;
|
|
85
|
+
}),
|
|
86
|
+
[pluginLoaderParam, plugins],
|
|
87
|
+
);
|
|
88
|
+
|
|
89
|
+
const state = useMemo(() => live({ ready: false, error: null }), []);
|
|
90
|
+
const cached: string[] = useMemo(() => JSON.parse(localStorage.getItem(ENABLED_KEY) ?? '[]'), []);
|
|
91
|
+
const enabled = useMemo(
|
|
92
|
+
() => (safeMode ? [] : cacheEnabled && cached.length > 0 ? cached : defaults),
|
|
93
|
+
[safeMode, cacheEnabled, cached, defaults],
|
|
94
|
+
);
|
|
95
|
+
const manager = useMemo(
|
|
96
|
+
() => pluginManager ?? new PluginManager({ pluginLoader, plugins, core, enabled }),
|
|
97
|
+
[pluginManager, pluginLoader, plugins, core, enabled],
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
useEffect(() => {
|
|
101
|
+
return manager.activation.on(({ event, state: _state, error }) => {
|
|
102
|
+
// Once the app is ready the first time, don't show the fallback again.
|
|
103
|
+
if (!state.ready && event === Events.Startup.id) {
|
|
104
|
+
state.ready = _state === 'activated';
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
if (error && !state.ready && !state.error) {
|
|
108
|
+
state.error = error;
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
}, [manager, state]);
|
|
112
|
+
|
|
113
|
+
useEffect(() => {
|
|
114
|
+
effect(() => {
|
|
115
|
+
cacheEnabled && localStorage.setItem(ENABLED_KEY, JSON.stringify(manager.enabled));
|
|
116
|
+
});
|
|
117
|
+
}, [cacheEnabled, manager]);
|
|
118
|
+
|
|
119
|
+
useEffect(() => {
|
|
120
|
+
setupDevtools(manager);
|
|
121
|
+
}, [manager]);
|
|
122
|
+
|
|
123
|
+
useAsyncEffect(async () => {
|
|
124
|
+
manager.context.contributeCapability({
|
|
125
|
+
interface: Capabilities.PluginManager,
|
|
126
|
+
implementation: manager,
|
|
127
|
+
module: 'dxos.org/app-framework/plugin-manager',
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
manager.context.contributeCapability({
|
|
131
|
+
interface: Capabilities.AtomRegistry,
|
|
132
|
+
implementation: manager.registry,
|
|
133
|
+
module: 'dxos.org/app-framework/atom-registry',
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
await Promise.all([
|
|
137
|
+
// TODO(wittjosiah): Factor out such that this could be called per surface role when attempting to render.
|
|
138
|
+
manager.activate(Events.SetupReactSurface),
|
|
139
|
+
manager.activate(Events.Startup),
|
|
140
|
+
]);
|
|
141
|
+
|
|
142
|
+
return () => {
|
|
143
|
+
manager.context.removeCapability(Capabilities.PluginManager, manager);
|
|
144
|
+
manager.context.removeCapability(Capabilities.AtomRegistry, manager.registry);
|
|
145
|
+
};
|
|
146
|
+
}, [manager]);
|
|
147
|
+
|
|
148
|
+
return useCallback(
|
|
149
|
+
() => (
|
|
150
|
+
<ErrorBoundary fallback={fallback}>
|
|
151
|
+
<PluginManagerProvider value={manager}>
|
|
152
|
+
<RegistryContext.Provider value={manager.registry}>
|
|
153
|
+
<App placeholder={placeholder} state={state} debounce={debounce} />
|
|
154
|
+
</RegistryContext.Provider>
|
|
155
|
+
</PluginManagerProvider>
|
|
156
|
+
</ErrorBoundary>
|
|
157
|
+
),
|
|
158
|
+
[fallback, manager, placeholder, state],
|
|
159
|
+
);
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
const setupDevtools = (manager: PluginManager) => {
|
|
163
|
+
(globalThis as any).composer ??= {};
|
|
164
|
+
(globalThis as any).composer.manager = manager;
|
|
165
|
+
};
|
|
@@ -2,20 +2,21 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import { useAtomValue } from '@effect-atom/atom-react';
|
|
6
6
|
|
|
7
7
|
import { invariant } from '@dxos/invariant';
|
|
8
8
|
|
|
9
|
-
import { usePluginManager } from './PluginManagerProvider';
|
|
10
9
|
import { type InterfaceDef } from '../core';
|
|
11
10
|
|
|
11
|
+
import { usePluginManager } from './PluginManagerProvider';
|
|
12
|
+
|
|
12
13
|
/**
|
|
13
14
|
* Hook to request capabilities from the plugin context.
|
|
14
15
|
* @returns An array of capabilities.
|
|
15
16
|
*/
|
|
16
17
|
export const useCapabilities = <T>(interfaceDef: InterfaceDef<T>) => {
|
|
17
18
|
const manager = usePluginManager();
|
|
18
|
-
return
|
|
19
|
+
return useAtomValue(manager.context.capabilities(interfaceDef));
|
|
19
20
|
};
|
|
20
21
|
|
|
21
22
|
/**
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { useEffect, useState } from 'react';
|
|
6
|
+
|
|
7
|
+
import { type AppProps } from './App';
|
|
8
|
+
|
|
9
|
+
export enum LoadingState {
|
|
10
|
+
Loading = 0,
|
|
11
|
+
FadeIn = 1,
|
|
12
|
+
FadeOut = 2,
|
|
13
|
+
Done = 3,
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* To avoid "flashing" the placeholder, we wait a period of time before starting the loading animation.
|
|
18
|
+
* If loading completes during this time the placehoder is not shown, otherwise is it displayed for a minimum period of time.
|
|
19
|
+
*
|
|
20
|
+
* States:
|
|
21
|
+
* 0: Loading - Wait for a period of time before starting the loading animation.
|
|
22
|
+
* 1: Fade-in - Display a loading animation.
|
|
23
|
+
* 2: Fade-out - Fade out the loading animation.
|
|
24
|
+
* 3: Done - Remove the placeholder.
|
|
25
|
+
*/
|
|
26
|
+
export const useLoading = (state: AppProps['state'], debounce = 0) => {
|
|
27
|
+
const [stage, setStage] = useState<LoadingState>(LoadingState.Loading);
|
|
28
|
+
useEffect(() => {
|
|
29
|
+
if (!debounce) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const i = setInterval(() => {
|
|
34
|
+
setStage((stage) => {
|
|
35
|
+
switch (stage) {
|
|
36
|
+
case LoadingState.Loading: {
|
|
37
|
+
if (!state.ready) {
|
|
38
|
+
return LoadingState.FadeIn;
|
|
39
|
+
} else {
|
|
40
|
+
clearInterval(i);
|
|
41
|
+
return LoadingState.Done;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
case LoadingState.FadeIn: {
|
|
46
|
+
if (state.ready) {
|
|
47
|
+
return LoadingState.FadeOut;
|
|
48
|
+
}
|
|
49
|
+
break;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
case LoadingState.FadeOut: {
|
|
53
|
+
clearInterval(i);
|
|
54
|
+
return LoadingState.Done;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return stage;
|
|
59
|
+
});
|
|
60
|
+
}, debounce);
|
|
61
|
+
|
|
62
|
+
return () => clearInterval(i);
|
|
63
|
+
}, [debounce]);
|
|
64
|
+
|
|
65
|
+
if (!debounce) {
|
|
66
|
+
return state.ready ? LoadingState.Done : LoadingState.Loading;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return stage;
|
|
70
|
+
};
|
|
@@ -2,15 +2,17 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
+
import { type Meta, type StoryObj } from '@storybook/react-vite';
|
|
5
6
|
import React from 'react';
|
|
6
7
|
|
|
7
|
-
import { withTheme
|
|
8
|
+
import { withTheme } from '@dxos/react-ui/testing';
|
|
8
9
|
|
|
9
|
-
import { withPluginManager } from './withPluginManager';
|
|
10
10
|
import { Capabilities, createSurface } from '../common';
|
|
11
11
|
import { contributes } from '../core';
|
|
12
12
|
import { Surface } from '../react';
|
|
13
13
|
|
|
14
|
+
import { withPluginManager } from './withPluginManager';
|
|
15
|
+
|
|
14
16
|
const DefaultStory = () => {
|
|
15
17
|
console.log('Render');
|
|
16
18
|
return (
|
|
@@ -21,7 +23,7 @@ const DefaultStory = () => {
|
|
|
21
23
|
);
|
|
22
24
|
};
|
|
23
25
|
|
|
24
|
-
const meta
|
|
26
|
+
const meta = {
|
|
25
27
|
title: 'sdk/app-framework/withPluginManager',
|
|
26
28
|
render: DefaultStory,
|
|
27
29
|
decorators: [
|
|
@@ -39,8 +41,10 @@ const meta: Meta = {
|
|
|
39
41
|
],
|
|
40
42
|
}),
|
|
41
43
|
],
|
|
42
|
-
}
|
|
44
|
+
} satisfies Meta<typeof DefaultStory>;
|
|
43
45
|
|
|
44
46
|
export default meta;
|
|
45
47
|
|
|
46
|
-
|
|
48
|
+
type Story = StoryObj<typeof meta>;
|
|
49
|
+
|
|
50
|
+
export const Default: Story = {};
|
|
@@ -2,29 +2,24 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { type Decorator } from '@storybook/react';
|
|
5
|
+
import { type Decorator, type StoryContext } from '@storybook/react';
|
|
6
6
|
import React, { useEffect, useMemo } from 'react';
|
|
7
7
|
|
|
8
8
|
import { raise } from '@dxos/debug';
|
|
9
|
+
import { useAsyncEffect } from '@dxos/react-hooks';
|
|
10
|
+
import { type MaybeProvider, getProviderValue } from '@dxos/util';
|
|
9
11
|
|
|
10
|
-
import { useApp, type CreateAppOptions } from '../App';
|
|
11
12
|
import { Capabilities, Events } from '../common';
|
|
12
13
|
import {
|
|
13
|
-
contributes,
|
|
14
|
-
defineModule,
|
|
15
|
-
definePlugin,
|
|
16
14
|
type ActivationEvent,
|
|
17
15
|
type AnyCapability,
|
|
18
|
-
PluginManager,
|
|
19
16
|
type PluginContext,
|
|
17
|
+
PluginManager,
|
|
18
|
+
contributes,
|
|
19
|
+
defineModule,
|
|
20
|
+
definePlugin,
|
|
20
21
|
} from '../core';
|
|
21
|
-
|
|
22
|
-
// TODO(burdon): Factor out (use consistently in plugin framework?)
|
|
23
|
-
export type Provider<C, R> = (context: C) => R;
|
|
24
|
-
export type ProviderOrValue<C, R> = Provider<C, R> | R;
|
|
25
|
-
export const getValue = <C, R>(providerOrValue: ProviderOrValue<C, R>, context: C): R => {
|
|
26
|
-
return typeof providerOrValue === 'function' ? (providerOrValue as Provider<C, R>)(context) : providerOrValue;
|
|
27
|
-
};
|
|
22
|
+
import { type UseAppOptions, useApp } from '../react';
|
|
28
23
|
|
|
29
24
|
/**
|
|
30
25
|
* @internal
|
|
@@ -34,16 +29,16 @@ export const setupPluginManager = ({
|
|
|
34
29
|
plugins = [],
|
|
35
30
|
core = plugins.map(({ meta }) => meta.id),
|
|
36
31
|
...options
|
|
37
|
-
}:
|
|
32
|
+
}: UseAppOptions & Pick<WithPluginManagerOptions, 'capabilities'> = {}) => {
|
|
38
33
|
const pluginManager = new PluginManager({
|
|
39
34
|
pluginLoader: () => raise(new Error('Not implemented')),
|
|
40
|
-
plugins: [
|
|
41
|
-
core: [
|
|
35
|
+
plugins: [StoryPlugin(), ...plugins],
|
|
36
|
+
core: [StoryPlugin.meta.id, ...core],
|
|
42
37
|
...options,
|
|
43
38
|
});
|
|
44
39
|
|
|
45
40
|
if (capabilities) {
|
|
46
|
-
|
|
41
|
+
getProviderValue(capabilities, pluginManager.context).forEach((capability) => {
|
|
47
42
|
pluginManager.context.contributeCapability({
|
|
48
43
|
interface: capability.interface,
|
|
49
44
|
implementation: capability.implementation,
|
|
@@ -55,18 +50,25 @@ export const setupPluginManager = ({
|
|
|
55
50
|
return pluginManager;
|
|
56
51
|
};
|
|
57
52
|
|
|
58
|
-
export type WithPluginManagerOptions =
|
|
59
|
-
|
|
53
|
+
export type WithPluginManagerOptions = UseAppOptions & {
|
|
54
|
+
/** @deprecated */
|
|
55
|
+
capabilities?: MaybeProvider<AnyCapability[], PluginContext>;
|
|
56
|
+
/** @deprecated */
|
|
60
57
|
fireEvents?: (ActivationEvent | string)[];
|
|
61
58
|
};
|
|
62
59
|
|
|
60
|
+
export type WithPluginManagerInitializer<Args = void> =
|
|
61
|
+
| WithPluginManagerOptions
|
|
62
|
+
| ((context: StoryContext<Args>) => WithPluginManagerOptions);
|
|
63
|
+
|
|
63
64
|
/**
|
|
64
65
|
* Wraps a story with a plugin manager.
|
|
65
66
|
* NOTE: This builds up and tears down the plugin manager on every render.
|
|
66
67
|
*/
|
|
67
|
-
export const withPluginManager = (
|
|
68
|
+
export const withPluginManager = <Args,>(init: WithPluginManagerInitializer<Args> = {}): Decorator => {
|
|
68
69
|
return (Story, context) => {
|
|
69
|
-
const
|
|
70
|
+
const options = typeof init === 'function' ? init(context as any) : init;
|
|
71
|
+
const pluginManager = useMemo(() => setupPluginManager(options), [init]);
|
|
70
72
|
|
|
71
73
|
// Set-up root capability.
|
|
72
74
|
useEffect(() => {
|
|
@@ -86,12 +88,8 @@ export const withPluginManager = (options: WithPluginManagerOptions = {}): Decor
|
|
|
86
88
|
}, [pluginManager, context]);
|
|
87
89
|
|
|
88
90
|
// Fire events.
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
await Promise.all(options.fireEvents?.map((event) => pluginManager.activate(event)) ?? []);
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
return () => clearTimeout(timeout);
|
|
91
|
+
useAsyncEffect(async () => {
|
|
92
|
+
await Promise.all(options.fireEvents?.map((event) => pluginManager.activate(event)) ?? []);
|
|
95
93
|
}, [pluginManager]);
|
|
96
94
|
|
|
97
95
|
// Create app.
|
|
@@ -101,10 +99,13 @@ export const withPluginManager = (options: WithPluginManagerOptions = {}): Decor
|
|
|
101
99
|
};
|
|
102
100
|
};
|
|
103
101
|
|
|
102
|
+
const storyMeta = {
|
|
103
|
+
id: 'dxos.org/app-framework/story',
|
|
104
|
+
name: 'Story',
|
|
105
|
+
};
|
|
106
|
+
|
|
104
107
|
// No-op plugin to ensure there exists at least one plugin for the startup event.
|
|
105
108
|
// This is necessary because `createApp` expects the startup event to complete before the app is ready.
|
|
106
|
-
const
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
defineModule({ id: STORY_PLUGIN, activatesOn: Events.Startup, activate: () => [] }),
|
|
110
|
-
]);
|
|
109
|
+
const StoryPlugin = definePlugin(storyMeta, () => [
|
|
110
|
+
defineModule({ id: storyMeta.id, activatesOn: Events.Startup, activate: () => [] }),
|
|
111
|
+
]);
|