@dxos/app-framework 0.7.4 → 0.7.5-feature-compute.4d9d99a
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/dist/lib/browser/chunk-EGGZVV7Q.mjs +1595 -0
- package/dist/lib/browser/chunk-EGGZVV7Q.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +136 -527
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +67 -0
- package/dist/lib/browser/testing/index.mjs.map +7 -0
- package/dist/lib/node/chunk-UBX6GP2N.cjs +1639 -0
- package/dist/lib/node/chunk-UBX6GP2N.cjs.map +7 -0
- package/dist/lib/node/index.cjs +141 -551
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/testing/index.cjs +91 -0
- package/dist/lib/node/testing/index.cjs.map +7 -0
- package/dist/lib/node-esm/chunk-HG5P55WF.mjs +1597 -0
- package/dist/lib/node-esm/chunk-HG5P55WF.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +136 -527
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/testing/index.mjs +68 -0
- package/dist/lib/node-esm/testing/index.mjs.map +7 -0
- package/dist/types/src/App.d.ts +22 -13
- package/dist/types/src/App.d.ts.map +1 -1
- package/dist/types/src/common/capabilities.d.ts +340 -0
- package/dist/types/src/common/capabilities.d.ts.map +1 -0
- package/dist/types/src/common/events.d.ts +41 -0
- package/dist/types/src/common/events.d.ts.map +1 -0
- package/dist/types/src/common/file.d.ts +14 -0
- package/dist/types/src/common/file.d.ts.map +1 -0
- package/dist/types/src/common/graph.d.ts +21 -0
- package/dist/types/src/common/graph.d.ts.map +1 -0
- package/dist/types/src/{plugins/common → common}/index.d.ts +3 -1
- package/dist/types/src/common/index.d.ts.map +1 -0
- package/dist/types/src/common/layout.d.ts +165 -0
- package/dist/types/src/common/layout.d.ts.map +1 -0
- package/dist/types/src/{plugins/common → common}/navigation.d.ts +77 -32
- package/dist/types/src/common/navigation.d.ts.map +1 -0
- package/dist/types/src/common/surface.d.ts +68 -0
- package/dist/types/src/common/surface.d.ts.map +1 -0
- package/dist/types/src/{plugins/common → common}/translations.d.ts +0 -11
- package/dist/types/src/common/translations.d.ts.map +1 -0
- package/dist/types/src/core/capabilities.d.ts +90 -0
- package/dist/types/src/core/capabilities.d.ts.map +1 -0
- package/dist/types/src/core/capabilities.test.d.ts +2 -0
- package/dist/types/src/core/capabilities.test.d.ts.map +1 -0
- package/dist/types/src/core/events.d.ts +58 -0
- package/dist/types/src/core/events.d.ts.map +1 -0
- package/dist/types/src/core/index.d.ts +5 -0
- package/dist/types/src/core/index.d.ts.map +1 -0
- package/dist/types/src/core/manager.d.ts +126 -0
- package/dist/types/src/core/manager.d.ts.map +1 -0
- package/dist/types/src/core/manager.test.d.ts +2 -0
- package/dist/types/src/core/manager.test.d.ts.map +1 -0
- package/dist/types/src/core/plugin.d.ts +94 -0
- package/dist/types/src/core/plugin.d.ts.map +1 -0
- package/dist/types/src/helpers.d.ts +10 -0
- package/dist/types/src/helpers.d.ts.map +1 -0
- package/dist/types/src/helpers.test.d.ts +2 -0
- package/dist/types/src/helpers.test.d.ts.map +1 -0
- package/dist/types/src/index.d.ts +5 -1
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/playground/debug/Debug.d.ts +6 -0
- package/dist/types/src/playground/debug/Debug.d.ts.map +1 -0
- package/dist/types/src/playground/debug/index.d.ts +2 -0
- package/dist/types/src/playground/debug/index.d.ts.map +1 -0
- package/dist/types/src/playground/debug/plugin.d.ts +2 -0
- package/dist/types/src/playground/debug/plugin.d.ts.map +1 -0
- package/dist/types/src/playground/generator/Main.d.ts +6 -0
- package/dist/types/src/playground/generator/Main.d.ts.map +1 -0
- package/dist/types/src/playground/generator/Toolbar.d.ts +6 -0
- package/dist/types/src/playground/generator/Toolbar.d.ts.map +1 -0
- package/dist/types/src/playground/generator/generator.d.ts +5 -0
- package/dist/types/src/playground/generator/generator.d.ts.map +1 -0
- package/dist/types/src/playground/generator/index.d.ts +3 -0
- package/dist/types/src/playground/generator/index.d.ts.map +1 -0
- package/dist/types/src/playground/generator/plugin.d.ts +2 -0
- package/dist/types/src/playground/generator/plugin.d.ts.map +1 -0
- package/dist/types/src/playground/layout/Layout.d.ts +8 -0
- package/dist/types/src/playground/layout/Layout.d.ts.map +1 -0
- package/dist/types/src/playground/layout/index.d.ts +2 -0
- package/dist/types/src/playground/layout/index.d.ts.map +1 -0
- package/dist/types/src/playground/layout/plugin.d.ts +2 -0
- package/dist/types/src/playground/layout/plugin.d.ts.map +1 -0
- package/dist/types/src/playground/logger/Toolbar.d.ts +6 -0
- package/dist/types/src/playground/logger/Toolbar.d.ts.map +1 -0
- package/dist/types/src/playground/logger/index.d.ts +2 -0
- package/dist/types/src/playground/logger/index.d.ts.map +1 -0
- package/dist/types/src/playground/logger/plugin.d.ts +2 -0
- package/dist/types/src/playground/logger/plugin.d.ts.map +1 -0
- package/dist/types/src/playground/logger/schema.d.ts +13 -0
- package/dist/types/src/playground/logger/schema.d.ts.map +1 -0
- package/dist/types/src/playground/playground.stories.d.ts +10 -0
- package/dist/types/src/playground/playground.stories.d.ts.map +1 -0
- package/dist/types/src/plugin-intent/IntentContext.d.ts +8 -0
- package/dist/types/src/plugin-intent/IntentContext.d.ts.map +1 -0
- package/dist/types/src/plugin-intent/IntentPlugin.d.ts +2 -0
- package/dist/types/src/plugin-intent/IntentPlugin.d.ts.map +1 -0
- package/dist/types/src/plugin-intent/actions.d.ts +23 -0
- package/dist/types/src/plugin-intent/actions.d.ts.map +1 -0
- package/dist/types/src/plugin-intent/errors.d.ts +16 -0
- package/dist/types/src/plugin-intent/errors.d.ts.map +1 -0
- package/dist/types/src/plugin-intent/index.d.ts +6 -0
- package/dist/types/src/plugin-intent/index.d.ts.map +1 -0
- package/dist/types/src/plugin-intent/intent-dispatcher.d.ts +106 -0
- package/dist/types/src/plugin-intent/intent-dispatcher.d.ts.map +1 -0
- package/dist/types/src/plugin-intent/intent-dispatcher.test.d.ts +2 -0
- package/dist/types/src/plugin-intent/intent-dispatcher.test.d.ts.map +1 -0
- package/dist/types/src/plugin-intent/intent.d.ts +68 -0
- package/dist/types/src/plugin-intent/intent.d.ts.map +1 -0
- package/dist/types/src/plugin-settings/SettingsPlugin.d.ts +2 -0
- package/dist/types/src/plugin-settings/SettingsPlugin.d.ts.map +1 -0
- package/dist/types/src/plugin-settings/actions.d.ts +17 -0
- package/dist/types/src/plugin-settings/actions.d.ts.map +1 -0
- package/dist/types/src/plugin-settings/index.d.ts +3 -0
- package/dist/types/src/plugin-settings/index.d.ts.map +1 -0
- package/dist/types/src/react/ErrorBoundary.d.ts.map +1 -0
- package/dist/types/src/react/PluginManagerProvider.d.ts +10 -0
- package/dist/types/src/react/PluginManagerProvider.d.ts.map +1 -0
- package/dist/types/src/react/Surface.d.ts +12 -0
- package/dist/types/src/react/Surface.d.ts.map +1 -0
- package/dist/types/src/react/index.d.ts +5 -0
- package/dist/types/src/react/index.d.ts.map +1 -0
- package/dist/types/src/react/useCapabilities.d.ts +13 -0
- package/dist/types/src/react/useCapabilities.d.ts.map +1 -0
- package/dist/types/src/testing/index.d.ts +2 -0
- package/dist/types/src/testing/index.d.ts.map +1 -0
- package/dist/types/src/testing/withPluginManager.d.ts +10 -0
- package/dist/types/src/testing/withPluginManager.d.ts.map +1 -0
- package/dist/types/src/testing/withPluginManager.stories.d.ts +5 -0
- package/dist/types/src/testing/withPluginManager.stories.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -0
- package/package.json +30 -14
- package/project.json +2 -1
- package/src/App.tsx +138 -34
- package/src/common/capabilities.ts +82 -0
- package/src/common/events.ts +63 -0
- package/src/common/file.ts +22 -0
- package/src/common/graph.ts +30 -0
- package/src/{plugins/common → common}/index.ts +3 -1
- package/src/common/layout.ts +157 -0
- package/src/{plugins/common → common}/navigation.ts +59 -45
- package/src/common/surface.ts +81 -0
- package/src/common/translations.ts +18 -0
- package/src/core/capabilities.test.ts +116 -0
- package/src/core/capabilities.ts +213 -0
- package/src/core/events.ts +58 -0
- package/src/core/index.ts +8 -0
- package/src/core/manager.test.ts +567 -0
- package/src/core/manager.ts +497 -0
- package/src/core/plugin.ts +128 -0
- package/src/helpers.test.ts +97 -0
- package/src/helpers.ts +45 -0
- package/src/index.ts +6 -3
- package/src/playground/debug/Debug.tsx +39 -0
- package/src/playground/debug/index.ts +5 -0
- package/src/playground/debug/plugin.ts +17 -0
- package/src/playground/generator/Main.tsx +71 -0
- package/src/playground/generator/Toolbar.tsx +46 -0
- package/src/playground/generator/generator.ts +23 -0
- package/src/playground/generator/index.ts +6 -0
- package/src/playground/generator/plugin.ts +18 -0
- package/src/playground/layout/Layout.tsx +33 -0
- package/src/playground/layout/index.ts +5 -0
- package/src/playground/layout/plugin.ts +17 -0
- package/src/playground/logger/Toolbar.tsx +28 -0
- package/src/playground/logger/index.ts +5 -0
- package/src/playground/logger/plugin.ts +33 -0
- package/src/playground/logger/schema.ts +12 -0
- package/src/playground/playground.stories.tsx +34 -0
- package/src/plugin-intent/IntentContext.tsx +34 -0
- package/src/plugin-intent/IntentPlugin.tsx +60 -0
- package/src/plugin-intent/actions.ts +22 -0
- package/src/plugin-intent/errors.ts +39 -0
- package/src/plugin-intent/index.ts +9 -0
- package/src/plugin-intent/intent-dispatcher.test.ts +280 -0
- package/src/plugin-intent/intent-dispatcher.ts +269 -0
- package/src/plugin-intent/intent.ts +146 -0
- package/src/plugin-settings/SettingsPlugin.ts +29 -0
- package/src/plugin-settings/actions.ts +17 -0
- package/src/plugin-settings/index.ts +6 -0
- package/src/react/PluginManagerProvider.ts +22 -0
- package/src/react/Surface.tsx +72 -0
- package/src/react/index.ts +8 -0
- package/src/react/useCapabilities.ts +40 -0
- package/src/testing/index.ts +5 -0
- package/src/testing/withPluginManager.stories.tsx +47 -0
- package/src/testing/withPluginManager.tsx +67 -0
- package/tsconfig.json +51 -2
- package/dist/lib/browser/chunk-3E7RY3CE.mjs +0 -72
- package/dist/lib/browser/chunk-3E7RY3CE.mjs.map +0 -7
- package/dist/lib/browser/chunk-653Y45CL.mjs +0 -41
- package/dist/lib/browser/chunk-653Y45CL.mjs.map +0 -7
- package/dist/lib/browser/chunk-FRXJ25VI.mjs +0 -214
- package/dist/lib/browser/chunk-FRXJ25VI.mjs.map +0 -7
- package/dist/lib/browser/chunk-YXM35XRE.mjs +0 -213
- package/dist/lib/browser/chunk-YXM35XRE.mjs.map +0 -7
- package/dist/lib/browser/plugin-intent-LU4KL2RO.mjs +0 -22
- package/dist/lib/browser/plugin-intent-LU4KL2RO.mjs.map +0 -7
- package/dist/lib/browser/plugin-settings-OM3G2QFY.mjs +0 -11
- package/dist/lib/browser/plugin-settings-OM3G2QFY.mjs.map +0 -7
- package/dist/lib/browser/plugin-surface-LECZMKSQ.mjs +0 -24
- package/dist/lib/browser/plugin-surface-LECZMKSQ.mjs.map +0 -7
- package/dist/lib/node/chunk-JZ2JVKRY.cjs +0 -58
- package/dist/lib/node/chunk-JZ2JVKRY.cjs.map +0 -7
- package/dist/lib/node/chunk-QBM42OQ6.cjs +0 -97
- package/dist/lib/node/chunk-QBM42OQ6.cjs.map +0 -7
- package/dist/lib/node/chunk-QSVP5HOW.cjs +0 -238
- package/dist/lib/node/chunk-QSVP5HOW.cjs.map +0 -7
- package/dist/lib/node/chunk-SOVLKUWI.cjs +0 -236
- package/dist/lib/node/chunk-SOVLKUWI.cjs.map +0 -7
- package/dist/lib/node/plugin-intent-FVFR2LKB.cjs +0 -43
- package/dist/lib/node/plugin-intent-FVFR2LKB.cjs.map +0 -7
- package/dist/lib/node/plugin-settings-OZ6IKAE5.cjs +0 -32
- package/dist/lib/node/plugin-settings-OZ6IKAE5.cjs.map +0 -7
- package/dist/lib/node/plugin-surface-YWDRXQTD.cjs +0 -45
- package/dist/lib/node/plugin-surface-YWDRXQTD.cjs.map +0 -7
- package/dist/lib/node-esm/chunk-2R4GVK7O.mjs +0 -215
- package/dist/lib/node-esm/chunk-2R4GVK7O.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-EYCTSFEJ.mjs +0 -74
- package/dist/lib/node-esm/chunk-EYCTSFEJ.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-YFMFQBB4.mjs +0 -214
- package/dist/lib/node-esm/chunk-YFMFQBB4.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-YNU7FTGJ.mjs +0 -43
- package/dist/lib/node-esm/chunk-YNU7FTGJ.mjs.map +0 -7
- package/dist/lib/node-esm/plugin-intent-V7ER24Y6.mjs +0 -23
- package/dist/lib/node-esm/plugin-intent-V7ER24Y6.mjs.map +0 -7
- package/dist/lib/node-esm/plugin-settings-37UVWF2V.mjs +0 -12
- package/dist/lib/node-esm/plugin-settings-37UVWF2V.mjs.map +0 -7
- package/dist/lib/node-esm/plugin-surface-TEU42XQN.mjs +0 -25
- package/dist/lib/node-esm/plugin-surface-TEU42XQN.mjs.map +0 -7
- package/dist/types/src/plugins/common/file.d.ts +0 -22
- package/dist/types/src/plugins/common/file.d.ts.map +0 -1
- package/dist/types/src/plugins/common/graph.d.ts +0 -51
- package/dist/types/src/plugins/common/graph.d.ts.map +0 -1
- package/dist/types/src/plugins/common/index.d.ts.map +0 -1
- package/dist/types/src/plugins/common/layout.d.ts +0 -202
- package/dist/types/src/plugins/common/layout.d.ts.map +0 -1
- package/dist/types/src/plugins/common/metadata.d.ts +0 -16
- package/dist/types/src/plugins/common/metadata.d.ts.map +0 -1
- package/dist/types/src/plugins/common/navigation.d.ts.map +0 -1
- package/dist/types/src/plugins/common/translations.d.ts.map +0 -1
- package/dist/types/src/plugins/helpers.d.ts +0 -41
- package/dist/types/src/plugins/helpers.d.ts.map +0 -1
- package/dist/types/src/plugins/index.d.ts +0 -7
- package/dist/types/src/plugins/index.d.ts.map +0 -1
- package/dist/types/src/plugins/plugin-host/HostPlugin.d.ts +0 -21
- package/dist/types/src/plugins/plugin-host/HostPlugin.d.ts.map +0 -1
- package/dist/types/src/plugins/plugin-host/PluginContainer.d.ts +0 -14
- package/dist/types/src/plugins/plugin-host/PluginContainer.d.ts.map +0 -1
- package/dist/types/src/plugins/plugin-host/PluginContext.d.ts +0 -47
- package/dist/types/src/plugins/plugin-host/PluginContext.d.ts.map +0 -1
- package/dist/types/src/plugins/plugin-host/index.d.ts +0 -4
- package/dist/types/src/plugins/plugin-host/index.d.ts.map +0 -1
- package/dist/types/src/plugins/plugin-host/plugin.d.ts +0 -98
- package/dist/types/src/plugins/plugin-host/plugin.d.ts.map +0 -1
- package/dist/types/src/plugins/plugin-host/plugin.test.d.ts +0 -35
- package/dist/types/src/plugins/plugin-host/plugin.test.d.ts.map +0 -1
- package/dist/types/src/plugins/plugin-intent/IntentContext.d.ts +0 -21
- package/dist/types/src/plugins/plugin-intent/IntentContext.d.ts.map +0 -1
- package/dist/types/src/plugins/plugin-intent/IntentPlugin.d.ts +0 -8
- package/dist/types/src/plugins/plugin-intent/IntentPlugin.d.ts.map +0 -1
- package/dist/types/src/plugins/plugin-intent/helpers.d.ts +0 -6
- package/dist/types/src/plugins/plugin-intent/helpers.d.ts.map +0 -1
- package/dist/types/src/plugins/plugin-intent/index.d.ts +0 -6
- package/dist/types/src/plugins/plugin-intent/index.d.ts.map +0 -1
- package/dist/types/src/plugins/plugin-intent/intent.d.ts +0 -81
- package/dist/types/src/plugins/plugin-intent/intent.d.ts.map +0 -1
- package/dist/types/src/plugins/plugin-intent/meta.d.ts +0 -5
- package/dist/types/src/plugins/plugin-intent/meta.d.ts.map +0 -1
- package/dist/types/src/plugins/plugin-intent/provides.d.ts +0 -20
- package/dist/types/src/plugins/plugin-intent/provides.d.ts.map +0 -1
- package/dist/types/src/plugins/plugin-settings/SettingsPlugin.d.ts +0 -4
- package/dist/types/src/plugins/plugin-settings/SettingsPlugin.d.ts.map +0 -1
- package/dist/types/src/plugins/plugin-settings/index.d.ts +0 -4
- package/dist/types/src/plugins/plugin-settings/index.d.ts.map +0 -1
- package/dist/types/src/plugins/plugin-settings/meta.d.ts +0 -5
- package/dist/types/src/plugins/plugin-settings/meta.d.ts.map +0 -1
- package/dist/types/src/plugins/plugin-settings/provides.d.ts +0 -13
- package/dist/types/src/plugins/plugin-settings/provides.d.ts.map +0 -1
- package/dist/types/src/plugins/plugin-surface/ErrorBoundary.d.ts.map +0 -1
- package/dist/types/src/plugins/plugin-surface/Surface.d.ts +0 -62
- package/dist/types/src/plugins/plugin-surface/Surface.d.ts.map +0 -1
- package/dist/types/src/plugins/plugin-surface/SurfacePlugin.d.ts +0 -7
- package/dist/types/src/plugins/plugin-surface/SurfacePlugin.d.ts.map +0 -1
- package/dist/types/src/plugins/plugin-surface/SurfaceRootContext.d.ts +0 -39
- package/dist/types/src/plugins/plugin-surface/SurfaceRootContext.d.ts.map +0 -1
- package/dist/types/src/plugins/plugin-surface/helpers.d.ts +0 -21
- package/dist/types/src/plugins/plugin-surface/helpers.d.ts.map +0 -1
- package/dist/types/src/plugins/plugin-surface/index.d.ts +0 -8
- package/dist/types/src/plugins/plugin-surface/index.d.ts.map +0 -1
- package/dist/types/src/plugins/plugin-surface/meta.d.ts +0 -5
- package/dist/types/src/plugins/plugin-surface/meta.d.ts.map +0 -1
- package/dist/types/src/plugins/plugin-surface/provides.d.ts +0 -16
- package/dist/types/src/plugins/plugin-surface/provides.d.ts.map +0 -1
- package/src/plugins/common/file.ts +0 -36
- package/src/plugins/common/graph.ts +0 -70
- package/src/plugins/common/layout.ts +0 -155
- package/src/plugins/common/metadata.ts +0 -29
- package/src/plugins/common/translations.ts +0 -36
- package/src/plugins/helpers.ts +0 -92
- package/src/plugins/index.ts +0 -11
- package/src/plugins/plugin-host/HostPlugin.tsx +0 -96
- package/src/plugins/plugin-host/PluginContainer.tsx +0 -120
- package/src/plugins/plugin-host/PluginContext.tsx +0 -79
- package/src/plugins/plugin-host/index.ts +0 -8
- package/src/plugins/plugin-host/plugin.test.ts +0 -158
- package/src/plugins/plugin-host/plugin.ts +0 -126
- package/src/plugins/plugin-intent/IntentContext.tsx +0 -49
- package/src/plugins/plugin-intent/IntentPlugin.tsx +0 -151
- package/src/plugins/plugin-intent/helpers.ts +0 -11
- package/src/plugins/plugin-intent/index.ts +0 -12
- package/src/plugins/plugin-intent/intent.ts +0 -101
- package/src/plugins/plugin-intent/meta.ts +0 -9
- package/src/plugins/plugin-intent/provides.ts +0 -38
- package/src/plugins/plugin-settings/SettingsPlugin.tsx +0 -22
- package/src/plugins/plugin-settings/index.ts +0 -9
- package/src/plugins/plugin-settings/meta.ts +0 -9
- package/src/plugins/plugin-settings/provides.ts +0 -29
- package/src/plugins/plugin-surface/Surface.tsx +0 -195
- package/src/plugins/plugin-surface/SurfacePlugin.tsx +0 -33
- package/src/plugins/plugin-surface/SurfaceRootContext.tsx +0 -60
- package/src/plugins/plugin-surface/helpers.ts +0 -22
- package/src/plugins/plugin-surface/index.ts +0 -14
- package/src/plugins/plugin-surface/meta.ts +0 -9
- package/src/plugins/plugin-surface/provides.ts +0 -26
- /package/dist/types/src/{plugins/plugin-surface → react}/ErrorBoundary.d.ts +0 -0
- /package/src/{plugins/plugin-surface → react}/ErrorBoundary.tsx +0 -0
|
@@ -0,0 +1,1595 @@
|
|
|
1
|
+
// packages/sdk/app-framework/src/core/capabilities.ts
|
|
2
|
+
import { effect, untracked } from "@preact/signals-core";
|
|
3
|
+
import { Trigger } from "@dxos/async";
|
|
4
|
+
import { invariant } from "@dxos/invariant";
|
|
5
|
+
import { create } from "@dxos/live-object";
|
|
6
|
+
import { log } from "@dxos/log";
|
|
7
|
+
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/sdk/app-framework/src/core/capabilities.ts";
|
|
8
|
+
var InterfaceDefTypeId = Symbol.for("InterfaceDefTypeId");
|
|
9
|
+
var defineCapability = (identifier) => {
|
|
10
|
+
return {
|
|
11
|
+
identifier
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
var CapabilityImpl = class {
|
|
15
|
+
constructor(moduleId, implementation) {
|
|
16
|
+
this.moduleId = moduleId;
|
|
17
|
+
this.implementation = implementation;
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
var contributes = (interfaceDef, implementation, deactivate) => {
|
|
21
|
+
return {
|
|
22
|
+
interface: interfaceDef,
|
|
23
|
+
implementation,
|
|
24
|
+
deactivate
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
var lazy = (c) => (props) => c().then(({ default: getCapability }) => {
|
|
28
|
+
return getCapability(props);
|
|
29
|
+
});
|
|
30
|
+
var PluginsContext = class {
|
|
31
|
+
constructor({ activate, reset }) {
|
|
32
|
+
this._definedCapabilities = /* @__PURE__ */ new Map();
|
|
33
|
+
this.activate = activate;
|
|
34
|
+
this.reset = reset;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* @internal
|
|
38
|
+
*/
|
|
39
|
+
contributeCapability({ module: moduleId, interface: interfaceDef, implementation }) {
|
|
40
|
+
let current = this._definedCapabilities.get(interfaceDef.identifier);
|
|
41
|
+
if (!current) {
|
|
42
|
+
const object = create({
|
|
43
|
+
value: []
|
|
44
|
+
});
|
|
45
|
+
current = untracked(() => object.value);
|
|
46
|
+
this._definedCapabilities.set(interfaceDef.identifier, current);
|
|
47
|
+
}
|
|
48
|
+
current.push(new CapabilityImpl(moduleId, implementation));
|
|
49
|
+
log("capability contributed", {
|
|
50
|
+
id: interfaceDef.identifier,
|
|
51
|
+
count: untracked(() => current.length)
|
|
52
|
+
}, {
|
|
53
|
+
F: __dxlog_file,
|
|
54
|
+
L: 139,
|
|
55
|
+
S: this,
|
|
56
|
+
C: (f, a) => f(...a)
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* @internal
|
|
61
|
+
*/
|
|
62
|
+
removeCapability(interfaceDef, implementation) {
|
|
63
|
+
const current = this._definedCapabilities.get(interfaceDef.identifier);
|
|
64
|
+
if (!current) {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
const index = current.findIndex((i) => i.implementation === implementation);
|
|
68
|
+
if (index !== -1) {
|
|
69
|
+
current.splice(index, 1);
|
|
70
|
+
log("capability removed", {
|
|
71
|
+
id: interfaceDef.identifier,
|
|
72
|
+
count: untracked(() => current.length)
|
|
73
|
+
}, {
|
|
74
|
+
F: __dxlog_file,
|
|
75
|
+
L: 154,
|
|
76
|
+
S: this,
|
|
77
|
+
C: (f, a) => f(...a)
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Requests capabilities from the plugin context.
|
|
83
|
+
* @returns An array of capabilities.
|
|
84
|
+
* @reactive
|
|
85
|
+
*/
|
|
86
|
+
requestCapabilities(interfaceDef, filter) {
|
|
87
|
+
let current = this._definedCapabilities.get(interfaceDef.identifier);
|
|
88
|
+
if (!current) {
|
|
89
|
+
const object = create({
|
|
90
|
+
value: []
|
|
91
|
+
});
|
|
92
|
+
current = untracked(() => object.value);
|
|
93
|
+
this._definedCapabilities.set(interfaceDef.identifier, current);
|
|
94
|
+
}
|
|
95
|
+
const capabilities = filter ? current.filter((c) => filter(c.implementation, c.moduleId)) : current;
|
|
96
|
+
return capabilities.map((c) => c.implementation);
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Requests a single capability from the plugin context.
|
|
100
|
+
* @returns The capability.
|
|
101
|
+
* @throws If no capability is found.
|
|
102
|
+
* @reactive
|
|
103
|
+
*/
|
|
104
|
+
requestCapability(interfaceDef, filter) {
|
|
105
|
+
const capability = this.requestCapabilities(interfaceDef, filter)[0];
|
|
106
|
+
invariant(capability, `No capability found for ${interfaceDef.identifier}`, {
|
|
107
|
+
F: __dxlog_file,
|
|
108
|
+
L: 190,
|
|
109
|
+
S: this,
|
|
110
|
+
A: [
|
|
111
|
+
"capability",
|
|
112
|
+
"`No capability found for ${interfaceDef.identifier}`"
|
|
113
|
+
]
|
|
114
|
+
});
|
|
115
|
+
return capability;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Waits for a capability to be contributed.
|
|
119
|
+
* @returns The capability.
|
|
120
|
+
*/
|
|
121
|
+
async waitForCapability(interfaceDef, filter) {
|
|
122
|
+
const trigger = new Trigger();
|
|
123
|
+
const unsubscribe = effect(() => {
|
|
124
|
+
const capabilities = this.requestCapabilities(interfaceDef, filter);
|
|
125
|
+
if (capabilities[0]) {
|
|
126
|
+
trigger.wake(capabilities[0]);
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
const capability = await trigger.wait();
|
|
130
|
+
unsubscribe();
|
|
131
|
+
return capability;
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
// packages/sdk/app-framework/src/core/events.ts
|
|
136
|
+
var defineEvent = (id, specifier) => {
|
|
137
|
+
return {
|
|
138
|
+
id,
|
|
139
|
+
specifier
|
|
140
|
+
};
|
|
141
|
+
};
|
|
142
|
+
var eventKey = (event) => event.specifier ? `${event.id}:${event.specifier}` : event.id;
|
|
143
|
+
var oneOf = (...events) => ({
|
|
144
|
+
type: "one-of",
|
|
145
|
+
events
|
|
146
|
+
});
|
|
147
|
+
var allOf = (...events) => ({
|
|
148
|
+
type: "all-of",
|
|
149
|
+
events
|
|
150
|
+
});
|
|
151
|
+
var isOneOf = (events) => "type" in events && events.type === "one-of";
|
|
152
|
+
var isAllOf = (events) => "type" in events && events.type === "all-of";
|
|
153
|
+
var getEvents = (events) => "type" in events ? events.events : [
|
|
154
|
+
events
|
|
155
|
+
];
|
|
156
|
+
|
|
157
|
+
// packages/sdk/app-framework/src/core/manager.ts
|
|
158
|
+
import { untracked as untracked2 } from "@preact/signals-core";
|
|
159
|
+
import { Effect, Either, Match } from "effect";
|
|
160
|
+
import { Event } from "@dxos/async";
|
|
161
|
+
import { create as create2 } from "@dxos/live-object";
|
|
162
|
+
import { log as log2 } from "@dxos/log";
|
|
163
|
+
var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/sdk/app-framework/src/core/manager.ts";
|
|
164
|
+
var isPromise = (value) => {
|
|
165
|
+
return value !== null && typeof value === "object" && "then" in value;
|
|
166
|
+
};
|
|
167
|
+
var PluginManager = class {
|
|
168
|
+
constructor({ pluginLoader, plugins = [], core = plugins.map(({ meta }) => meta.id), enabled = [] }) {
|
|
169
|
+
this.activation = new Event();
|
|
170
|
+
this.context = new PluginsContext({
|
|
171
|
+
activate: (event) => this.activate(event),
|
|
172
|
+
reset: (id) => this.reset(id)
|
|
173
|
+
});
|
|
174
|
+
this._capabilities = /* @__PURE__ */ new Map();
|
|
175
|
+
this._pluginLoader = pluginLoader;
|
|
176
|
+
this._state = create2({
|
|
177
|
+
plugins,
|
|
178
|
+
core,
|
|
179
|
+
enabled,
|
|
180
|
+
modules: [],
|
|
181
|
+
active: [],
|
|
182
|
+
pendingRemoval: [],
|
|
183
|
+
pendingReset: [],
|
|
184
|
+
eventsFired: []
|
|
185
|
+
});
|
|
186
|
+
plugins.forEach((plugin) => this._addPlugin(plugin));
|
|
187
|
+
core.forEach((id) => this.enable(id));
|
|
188
|
+
enabled.forEach((id) => this.enable(id));
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Plugins that are currently registered.
|
|
192
|
+
*
|
|
193
|
+
* @reactive
|
|
194
|
+
*/
|
|
195
|
+
get plugins() {
|
|
196
|
+
return this._state.plugins;
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Ids of plugins that are core and cannot be removed.
|
|
200
|
+
*
|
|
201
|
+
* @reactive
|
|
202
|
+
*/
|
|
203
|
+
get core() {
|
|
204
|
+
return this._state.core;
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Ids of plugins that are currently enabled.
|
|
208
|
+
*
|
|
209
|
+
* @reactive
|
|
210
|
+
*/
|
|
211
|
+
get enabled() {
|
|
212
|
+
return this._state.enabled;
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Modules of plugins which are currently enabled.
|
|
216
|
+
*
|
|
217
|
+
* @reactive
|
|
218
|
+
*/
|
|
219
|
+
get modules() {
|
|
220
|
+
return this._state.modules;
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Ids of modules which are currently active.
|
|
224
|
+
*
|
|
225
|
+
* @reactive
|
|
226
|
+
*/
|
|
227
|
+
get active() {
|
|
228
|
+
return this._state.active;
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Ids of modules which are pending removal.
|
|
232
|
+
*
|
|
233
|
+
* @reactive
|
|
234
|
+
*/
|
|
235
|
+
get pendingRemoval() {
|
|
236
|
+
return this._state.pendingRemoval;
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Ids of events which have been fired.
|
|
240
|
+
*
|
|
241
|
+
* @reactive
|
|
242
|
+
*/
|
|
243
|
+
get eventsFired() {
|
|
244
|
+
return this._state.eventsFired;
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Ids of modules which are pending reset.
|
|
248
|
+
*
|
|
249
|
+
* @reactive
|
|
250
|
+
*/
|
|
251
|
+
get pendingReset() {
|
|
252
|
+
return this._state.pendingReset;
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* Adds a plugin to the manager via the plugin loader.
|
|
256
|
+
* @param id The id of the plugin.
|
|
257
|
+
*/
|
|
258
|
+
async add(id) {
|
|
259
|
+
return untracked2(async () => {
|
|
260
|
+
log2("add plugin", {
|
|
261
|
+
id
|
|
262
|
+
}, {
|
|
263
|
+
F: __dxlog_file2,
|
|
264
|
+
L: 157,
|
|
265
|
+
S: this,
|
|
266
|
+
C: (f, a) => f(...a)
|
|
267
|
+
});
|
|
268
|
+
const plugin = await this._pluginLoader(id);
|
|
269
|
+
this._addPlugin(plugin);
|
|
270
|
+
return this.enable(id);
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* Enables a plugin.
|
|
275
|
+
* @param id The id of the plugin.
|
|
276
|
+
*/
|
|
277
|
+
enable(id) {
|
|
278
|
+
return untracked2(() => {
|
|
279
|
+
log2("enable plugin", {
|
|
280
|
+
id
|
|
281
|
+
}, {
|
|
282
|
+
F: __dxlog_file2,
|
|
283
|
+
L: 170,
|
|
284
|
+
S: this,
|
|
285
|
+
C: (f, a) => f(...a)
|
|
286
|
+
});
|
|
287
|
+
const plugin = this._getPlugin(id);
|
|
288
|
+
if (!plugin) {
|
|
289
|
+
return false;
|
|
290
|
+
}
|
|
291
|
+
if (!this._state.enabled.includes(id)) {
|
|
292
|
+
this._state.enabled.push(id);
|
|
293
|
+
}
|
|
294
|
+
plugin.modules.forEach((module) => {
|
|
295
|
+
this._addModule(module);
|
|
296
|
+
this._setPendingResetByModule(module);
|
|
297
|
+
});
|
|
298
|
+
return true;
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
/**
|
|
302
|
+
* Removes a plugin from the manager.
|
|
303
|
+
* @param id The id of the plugin.
|
|
304
|
+
*/
|
|
305
|
+
remove(id) {
|
|
306
|
+
return untracked2(() => {
|
|
307
|
+
log2("remove plugin", {
|
|
308
|
+
id
|
|
309
|
+
}, {
|
|
310
|
+
F: __dxlog_file2,
|
|
311
|
+
L: 194,
|
|
312
|
+
S: this,
|
|
313
|
+
C: (f, a) => f(...a)
|
|
314
|
+
});
|
|
315
|
+
const result = this.disable(id);
|
|
316
|
+
if (!result) {
|
|
317
|
+
return false;
|
|
318
|
+
}
|
|
319
|
+
this._removePlugin(id);
|
|
320
|
+
return true;
|
|
321
|
+
});
|
|
322
|
+
}
|
|
323
|
+
/**
|
|
324
|
+
* Disables a plugin.
|
|
325
|
+
* @param id The id of the plugin.
|
|
326
|
+
*/
|
|
327
|
+
disable(id) {
|
|
328
|
+
return untracked2(() => {
|
|
329
|
+
log2("disable plugin", {
|
|
330
|
+
id
|
|
331
|
+
}, {
|
|
332
|
+
F: __dxlog_file2,
|
|
333
|
+
L: 211,
|
|
334
|
+
S: this,
|
|
335
|
+
C: (f, a) => f(...a)
|
|
336
|
+
});
|
|
337
|
+
if (this._state.core.includes(id)) {
|
|
338
|
+
return false;
|
|
339
|
+
}
|
|
340
|
+
const plugin = this._getPlugin(id);
|
|
341
|
+
if (!plugin) {
|
|
342
|
+
return false;
|
|
343
|
+
}
|
|
344
|
+
const enabledIndex = this._state.enabled.findIndex((enabled) => enabled === id);
|
|
345
|
+
if (enabledIndex !== -1) {
|
|
346
|
+
this._state.enabled.splice(enabledIndex, 1);
|
|
347
|
+
plugin.modules.forEach((module) => {
|
|
348
|
+
if (this._state.active.includes(module.id)) {
|
|
349
|
+
this._setPendingResetByModule(module);
|
|
350
|
+
if (!this._state.pendingRemoval.includes(module.id)) {
|
|
351
|
+
this._state.pendingRemoval.push(module.id);
|
|
352
|
+
}
|
|
353
|
+
} else {
|
|
354
|
+
this._removeModule(module.id);
|
|
355
|
+
}
|
|
356
|
+
});
|
|
357
|
+
}
|
|
358
|
+
return true;
|
|
359
|
+
});
|
|
360
|
+
}
|
|
361
|
+
/**
|
|
362
|
+
* Activates plugins based on the activation event.
|
|
363
|
+
* @param event The activation event.
|
|
364
|
+
* @returns Whether the activation was successful.
|
|
365
|
+
*/
|
|
366
|
+
activate(event) {
|
|
367
|
+
return untracked2(() => Effect.runPromise(this._activate(event)));
|
|
368
|
+
}
|
|
369
|
+
/**
|
|
370
|
+
* Deactivates all of the modules for a plugin.
|
|
371
|
+
* @param id The id of the plugin.
|
|
372
|
+
* @returns Whether the deactivation was successful.
|
|
373
|
+
*/
|
|
374
|
+
deactivate(id) {
|
|
375
|
+
return untracked2(() => Effect.runPromise(this._deactivate(id)));
|
|
376
|
+
}
|
|
377
|
+
/**
|
|
378
|
+
* Re-activates the modules that were activated by the event.
|
|
379
|
+
* @param event The activation event.
|
|
380
|
+
* @returns Whether the reset was successful.
|
|
381
|
+
*/
|
|
382
|
+
reset(event) {
|
|
383
|
+
return untracked2(() => Effect.runPromise(this._reset(event)));
|
|
384
|
+
}
|
|
385
|
+
_addPlugin(plugin) {
|
|
386
|
+
untracked2(() => {
|
|
387
|
+
log2("add plugin", {
|
|
388
|
+
id: plugin.meta.id
|
|
389
|
+
}, {
|
|
390
|
+
F: __dxlog_file2,
|
|
391
|
+
L: 270,
|
|
392
|
+
S: this,
|
|
393
|
+
C: (f, a) => f(...a)
|
|
394
|
+
});
|
|
395
|
+
if (!this._state.plugins.includes(plugin)) {
|
|
396
|
+
this._state.plugins.push(plugin);
|
|
397
|
+
}
|
|
398
|
+
});
|
|
399
|
+
}
|
|
400
|
+
_removePlugin(id) {
|
|
401
|
+
untracked2(() => {
|
|
402
|
+
log2("remove plugin", {
|
|
403
|
+
id
|
|
404
|
+
}, {
|
|
405
|
+
F: __dxlog_file2,
|
|
406
|
+
L: 279,
|
|
407
|
+
S: this,
|
|
408
|
+
C: (f, a) => f(...a)
|
|
409
|
+
});
|
|
410
|
+
const pluginIndex = this._state.plugins.findIndex((plugin) => plugin.meta.id === id);
|
|
411
|
+
if (pluginIndex !== -1) {
|
|
412
|
+
this._state.plugins.splice(pluginIndex, 1);
|
|
413
|
+
}
|
|
414
|
+
});
|
|
415
|
+
}
|
|
416
|
+
_addModule(module) {
|
|
417
|
+
untracked2(() => {
|
|
418
|
+
log2("add module", {
|
|
419
|
+
id: module.id
|
|
420
|
+
}, {
|
|
421
|
+
F: __dxlog_file2,
|
|
422
|
+
L: 289,
|
|
423
|
+
S: this,
|
|
424
|
+
C: (f, a) => f(...a)
|
|
425
|
+
});
|
|
426
|
+
if (!this._state.modules.includes(module)) {
|
|
427
|
+
this._state.modules.push(module);
|
|
428
|
+
}
|
|
429
|
+
});
|
|
430
|
+
}
|
|
431
|
+
_removeModule(id) {
|
|
432
|
+
untracked2(() => {
|
|
433
|
+
log2("remove module", {
|
|
434
|
+
id
|
|
435
|
+
}, {
|
|
436
|
+
F: __dxlog_file2,
|
|
437
|
+
L: 298,
|
|
438
|
+
S: this,
|
|
439
|
+
C: (f, a) => f(...a)
|
|
440
|
+
});
|
|
441
|
+
const moduleIndex = this._state.modules.findIndex((module) => module.id === id);
|
|
442
|
+
if (moduleIndex !== -1) {
|
|
443
|
+
this._state.modules.splice(moduleIndex, 1);
|
|
444
|
+
}
|
|
445
|
+
});
|
|
446
|
+
}
|
|
447
|
+
_getPlugin(id) {
|
|
448
|
+
return this._state.plugins.find((plugin) => plugin.meta.id === id);
|
|
449
|
+
}
|
|
450
|
+
_getActiveModules() {
|
|
451
|
+
return this._state.modules.filter((module) => this._state.active.includes(module.id));
|
|
452
|
+
}
|
|
453
|
+
_getInactiveModules() {
|
|
454
|
+
return this._state.modules.filter((module) => !this._state.active.includes(module.id));
|
|
455
|
+
}
|
|
456
|
+
_getActiveModulesByEvent(key) {
|
|
457
|
+
return this._getActiveModules().filter((module) => getEvents(module.activatesOn).map(eventKey).includes(key));
|
|
458
|
+
}
|
|
459
|
+
_getInactiveModulesByEvent(key) {
|
|
460
|
+
return this._getInactiveModules().filter((module) => getEvents(module.activatesOn).map(eventKey).includes(key));
|
|
461
|
+
}
|
|
462
|
+
_setPendingResetByModule(module) {
|
|
463
|
+
return untracked2(() => {
|
|
464
|
+
const activationEvents = getEvents(module.activatesOn).map(eventKey).filter((key) => this._state.eventsFired.includes(key));
|
|
465
|
+
const parentEvents = activationEvents.flatMap((event) => {
|
|
466
|
+
const modules = this._getActiveModules().filter((module2) => module2.activatesBefore?.map(eventKey).includes(event));
|
|
467
|
+
return modules.flatMap((module2) => getEvents(module2.activatesOn)).map(eventKey);
|
|
468
|
+
});
|
|
469
|
+
const pendingReset = Array.from(/* @__PURE__ */ new Set([
|
|
470
|
+
...activationEvents,
|
|
471
|
+
...parentEvents
|
|
472
|
+
])).filter((event) => !this._state.pendingReset.includes(event));
|
|
473
|
+
if (pendingReset.length > 0) {
|
|
474
|
+
log2("pending reset", {
|
|
475
|
+
events: pendingReset
|
|
476
|
+
}, {
|
|
477
|
+
F: __dxlog_file2,
|
|
478
|
+
L: 342,
|
|
479
|
+
S: this,
|
|
480
|
+
C: (f, a) => f(...a)
|
|
481
|
+
});
|
|
482
|
+
this._state.pendingReset.push(...pendingReset);
|
|
483
|
+
}
|
|
484
|
+
});
|
|
485
|
+
}
|
|
486
|
+
// TODO(wittjosiah): Improve error typing.
|
|
487
|
+
_activate(event) {
|
|
488
|
+
const self = this;
|
|
489
|
+
return Effect.gen(function* () {
|
|
490
|
+
const key = typeof event === "string" ? event : eventKey(event);
|
|
491
|
+
log2("activating", {
|
|
492
|
+
key
|
|
493
|
+
}, {
|
|
494
|
+
F: __dxlog_file2,
|
|
495
|
+
L: 353,
|
|
496
|
+
S: this,
|
|
497
|
+
C: (f, a) => f(...a)
|
|
498
|
+
});
|
|
499
|
+
const pendingIndex = self._state.pendingReset.findIndex((event2) => event2 === key);
|
|
500
|
+
if (pendingIndex !== -1) {
|
|
501
|
+
self._state.pendingReset.splice(pendingIndex, 1);
|
|
502
|
+
}
|
|
503
|
+
const modules = self._getInactiveModulesByEvent(key);
|
|
504
|
+
if (modules.length === 0) {
|
|
505
|
+
log2("no modules to activate", {
|
|
506
|
+
key
|
|
507
|
+
}, {
|
|
508
|
+
F: __dxlog_file2,
|
|
509
|
+
L: 361,
|
|
510
|
+
S: this,
|
|
511
|
+
C: (f, a) => f(...a)
|
|
512
|
+
});
|
|
513
|
+
return false;
|
|
514
|
+
}
|
|
515
|
+
self.activation.emit({
|
|
516
|
+
event: key,
|
|
517
|
+
state: "activating"
|
|
518
|
+
});
|
|
519
|
+
for (const module of modules) {
|
|
520
|
+
if (isAllOf(module.activatesOn) && !module.activatesOn.events.filter((event2) => eventKey(event2) !== key).every((event2) => self._state.eventsFired.includes(eventKey(event2)))) {
|
|
521
|
+
continue;
|
|
522
|
+
}
|
|
523
|
+
yield* Effect.all(module.activatesBefore?.map((event2) => self._activate(event2)) ?? []);
|
|
524
|
+
const result = yield* self._activateModule(module).pipe(Effect.either);
|
|
525
|
+
if (Either.isLeft(result)) {
|
|
526
|
+
self.activation.emit({
|
|
527
|
+
event: key,
|
|
528
|
+
state: "error",
|
|
529
|
+
error: result.left
|
|
530
|
+
});
|
|
531
|
+
yield* Effect.fail(result.left);
|
|
532
|
+
}
|
|
533
|
+
yield* Effect.all(module.activatesAfter?.map((event2) => self._activate(event2)) ?? []);
|
|
534
|
+
}
|
|
535
|
+
if (!self._state.eventsFired.includes(key)) {
|
|
536
|
+
self._state.eventsFired.push(key);
|
|
537
|
+
}
|
|
538
|
+
self.activation.emit({
|
|
539
|
+
event: key,
|
|
540
|
+
state: "activated"
|
|
541
|
+
});
|
|
542
|
+
log2("activated", {
|
|
543
|
+
key
|
|
544
|
+
}, {
|
|
545
|
+
F: __dxlog_file2,
|
|
546
|
+
L: 393,
|
|
547
|
+
S: this,
|
|
548
|
+
C: (f, a) => f(...a)
|
|
549
|
+
});
|
|
550
|
+
return true;
|
|
551
|
+
});
|
|
552
|
+
}
|
|
553
|
+
_activateModule(module) {
|
|
554
|
+
const self = this;
|
|
555
|
+
return Effect.gen(function* () {
|
|
556
|
+
const program = module.activate(self.context);
|
|
557
|
+
const maybeCapabilities = yield* Match.value(program).pipe(Match.when(Effect.isEffect, (effect3) => effect3), Match.when(isPromise, (promise) => Effect.tryPromise({
|
|
558
|
+
try: () => promise,
|
|
559
|
+
catch: (error) => error
|
|
560
|
+
})), Match.orElse((program2) => Effect.succeed(program2)));
|
|
561
|
+
const capabilities = Match.value(maybeCapabilities).pipe(Match.when(Array.isArray, (array) => array), Match.orElse((value) => [
|
|
562
|
+
value
|
|
563
|
+
]));
|
|
564
|
+
capabilities.forEach((capability) => {
|
|
565
|
+
self.context.contributeCapability({
|
|
566
|
+
module: module.id,
|
|
567
|
+
...capability
|
|
568
|
+
});
|
|
569
|
+
});
|
|
570
|
+
self._state.active.push(module.id);
|
|
571
|
+
self._capabilities.set(module.id, capabilities);
|
|
572
|
+
});
|
|
573
|
+
}
|
|
574
|
+
_deactivate(id) {
|
|
575
|
+
const self = this;
|
|
576
|
+
return Effect.gen(function* () {
|
|
577
|
+
const plugin = self._getPlugin(id);
|
|
578
|
+
if (!plugin) {
|
|
579
|
+
return false;
|
|
580
|
+
}
|
|
581
|
+
const modules = plugin.modules;
|
|
582
|
+
const results = yield* Effect.all(modules.map((module) => self._deactivateModule(module)));
|
|
583
|
+
return results.every((result) => result);
|
|
584
|
+
});
|
|
585
|
+
}
|
|
586
|
+
_deactivateModule(module) {
|
|
587
|
+
const self = this;
|
|
588
|
+
return Effect.gen(function* () {
|
|
589
|
+
const id = module.id;
|
|
590
|
+
log2("deactivating", {
|
|
591
|
+
id
|
|
592
|
+
}, {
|
|
593
|
+
F: __dxlog_file2,
|
|
594
|
+
L: 444,
|
|
595
|
+
S: this,
|
|
596
|
+
C: (f, a) => f(...a)
|
|
597
|
+
});
|
|
598
|
+
const capabilities = self._capabilities.get(id);
|
|
599
|
+
if (capabilities) {
|
|
600
|
+
for (const capability of capabilities) {
|
|
601
|
+
self.context.removeCapability(capability.interface, capability.implementation);
|
|
602
|
+
const program = capability.deactivate?.();
|
|
603
|
+
yield* Match.value(program).pipe(Match.when(Effect.isEffect, (effect3) => effect3), Match.when(isPromise, (promise) => Effect.tryPromise({
|
|
604
|
+
try: () => promise,
|
|
605
|
+
catch: (error) => error
|
|
606
|
+
})), Match.orElse((program2) => Effect.succeed(program2)));
|
|
607
|
+
}
|
|
608
|
+
self._capabilities.delete(id);
|
|
609
|
+
}
|
|
610
|
+
const activeIndex = self._state.active.findIndex((event) => event === id);
|
|
611
|
+
if (activeIndex !== -1) {
|
|
612
|
+
self._state.active.splice(activeIndex, 1);
|
|
613
|
+
}
|
|
614
|
+
log2("deactivated", {
|
|
615
|
+
id
|
|
616
|
+
}, {
|
|
617
|
+
F: __dxlog_file2,
|
|
618
|
+
L: 470,
|
|
619
|
+
S: this,
|
|
620
|
+
C: (f, a) => f(...a)
|
|
621
|
+
});
|
|
622
|
+
return true;
|
|
623
|
+
});
|
|
624
|
+
}
|
|
625
|
+
_reset(event) {
|
|
626
|
+
const self = this;
|
|
627
|
+
return Effect.gen(function* () {
|
|
628
|
+
const key = typeof event === "string" ? event : eventKey(event);
|
|
629
|
+
log2("reset", {
|
|
630
|
+
key
|
|
631
|
+
}, {
|
|
632
|
+
F: __dxlog_file2,
|
|
633
|
+
L: 479,
|
|
634
|
+
S: this,
|
|
635
|
+
C: (f, a) => f(...a)
|
|
636
|
+
});
|
|
637
|
+
const modules = self._getActiveModulesByEvent(key);
|
|
638
|
+
const results = yield* Effect.all(modules.map((module) => self._deactivateModule(module)));
|
|
639
|
+
if (self._state.pendingRemoval.length > 0) {
|
|
640
|
+
self._state.pendingRemoval.forEach((id) => {
|
|
641
|
+
self._removeModule(id);
|
|
642
|
+
});
|
|
643
|
+
self._state.pendingRemoval.splice(0, self._state.pendingRemoval.length);
|
|
644
|
+
}
|
|
645
|
+
if (results.every((result) => result)) {
|
|
646
|
+
return yield* self._activate(key);
|
|
647
|
+
} else {
|
|
648
|
+
return false;
|
|
649
|
+
}
|
|
650
|
+
});
|
|
651
|
+
}
|
|
652
|
+
};
|
|
653
|
+
|
|
654
|
+
// packages/sdk/app-framework/src/core/plugin.ts
|
|
655
|
+
var PluginModule = class {
|
|
656
|
+
constructor(options) {
|
|
657
|
+
this.id = options.id;
|
|
658
|
+
this.activatesOn = options.activatesOn;
|
|
659
|
+
this.activatesBefore = options.activatesBefore;
|
|
660
|
+
this.activatesAfter = options.activatesAfter;
|
|
661
|
+
this.activate = options.activate;
|
|
662
|
+
}
|
|
663
|
+
};
|
|
664
|
+
var defineModule = (options) => new PluginModule(options);
|
|
665
|
+
var Plugin = class {
|
|
666
|
+
constructor(meta, modules) {
|
|
667
|
+
this.meta = meta;
|
|
668
|
+
this.modules = modules;
|
|
669
|
+
}
|
|
670
|
+
};
|
|
671
|
+
var definePlugin = (meta, modules) => {
|
|
672
|
+
return new Plugin(meta, modules);
|
|
673
|
+
};
|
|
674
|
+
|
|
675
|
+
// packages/sdk/app-framework/src/common/capabilities.ts
|
|
676
|
+
var Capabilities;
|
|
677
|
+
(function(Capabilities2) {
|
|
678
|
+
Capabilities2.PluginManager = defineCapability("dxos.org/app-framework/capability/plugin-manager");
|
|
679
|
+
Capabilities2.Null = defineCapability("dxos.org/app-framework/capability/null");
|
|
680
|
+
Capabilities2.ReactContext = defineCapability("dxos.org/app-framework/capability/react-context");
|
|
681
|
+
Capabilities2.ReactRoot = defineCapability("dxos.org/app-framework/capability/react-root");
|
|
682
|
+
Capabilities2.ReactSurface = defineCapability("dxos.org/app-framework/common/react-surface");
|
|
683
|
+
Capabilities2.IntentResolver = defineCapability("dxos.org/app-framework/capability/intent-resolver");
|
|
684
|
+
Capabilities2.IntentDispatcher = defineCapability("dxos.org/app-framework/capability/intent-dispatcher");
|
|
685
|
+
Capabilities2.Layout = defineCapability("dxos.org/app-framework/capability/layout");
|
|
686
|
+
Capabilities2.MutableLayout = defineCapability("dxos.org/app-framework/capability/layout");
|
|
687
|
+
Capabilities2.Location = defineCapability("dxos.org/app-framework/capability/location");
|
|
688
|
+
Capabilities2.MutableLocation = defineCapability("dxos.org/app-framework/capability/location");
|
|
689
|
+
Capabilities2.Translations = defineCapability("dxos.org/app-framework/capability/translations");
|
|
690
|
+
Capabilities2.AppGraph = defineCapability("dxos.org/app-framework/capability/app-graph");
|
|
691
|
+
Capabilities2.AppGraphBuilder = defineCapability("dxos.org/app-framework/capability/app-graph-builder");
|
|
692
|
+
Capabilities2.AppGraphSerializer = defineCapability("dxos.org/app-framework/capability/app-graph-serializer");
|
|
693
|
+
Capabilities2.SettingsStore = defineCapability("dxos.org/app-framework/capability/settings-store");
|
|
694
|
+
Capabilities2.Settings = defineCapability("dxos.org/app-framework/capability/settings");
|
|
695
|
+
Capabilities2.Metadata = defineCapability("dxos.org/app-framework/capability/metadata");
|
|
696
|
+
Capabilities2.FileUploader = defineCapability("dxos.org/app-framework/capability/file-uploader");
|
|
697
|
+
})(Capabilities || (Capabilities = {}));
|
|
698
|
+
|
|
699
|
+
// packages/sdk/app-framework/src/common/events.ts
|
|
700
|
+
var Events;
|
|
701
|
+
(function(Events2) {
|
|
702
|
+
Events2.Startup = defineEvent("dxos.org/app-framework/event/startup");
|
|
703
|
+
Events2.SetupIntents = defineEvent("dxos.org/app-framework/event/setup-intents");
|
|
704
|
+
Events2.SetupSettings = defineEvent("dxos.org/app-framework/event/setup-settings");
|
|
705
|
+
Events2.SetupAppGraph = defineEvent("dxos.org/app-framework/event/setup-graph");
|
|
706
|
+
Events2.SetupTranslations = defineEvent("dxos.org/app-framework/event/setup-translations");
|
|
707
|
+
Events2.DispatcherReady = defineEvent("dxos.org/app-framework/event/dispatcher-ready");
|
|
708
|
+
Events2.SettingsReady = defineEvent("dxos.org/app-framework/event/settings-ready");
|
|
709
|
+
Events2.AppGraphReady = defineEvent("dxos.org/app-framework/event/graph-ready");
|
|
710
|
+
Events2.createStateEvent = (specifier) => defineEvent("dxos.org/app-framework/event/state", specifier);
|
|
711
|
+
Events2.LayoutReady = Events2.createStateEvent(Capabilities.Layout.identifier);
|
|
712
|
+
Events2.LocationReady = Events2.createStateEvent(Capabilities.Location.identifier);
|
|
713
|
+
})(Events || (Events = {}));
|
|
714
|
+
|
|
715
|
+
// packages/sdk/app-framework/src/common/file.ts
|
|
716
|
+
import { S } from "@dxos/echo-schema";
|
|
717
|
+
var defaultFileTypes = {
|
|
718
|
+
images: [
|
|
719
|
+
"png",
|
|
720
|
+
"jpg",
|
|
721
|
+
"jpeg",
|
|
722
|
+
"gif"
|
|
723
|
+
],
|
|
724
|
+
media: [
|
|
725
|
+
"mp3",
|
|
726
|
+
"mp4",
|
|
727
|
+
"mov",
|
|
728
|
+
"avi"
|
|
729
|
+
],
|
|
730
|
+
text: [
|
|
731
|
+
"pdf",
|
|
732
|
+
"txt",
|
|
733
|
+
"md"
|
|
734
|
+
]
|
|
735
|
+
};
|
|
736
|
+
var FileInfoSchema = S.Struct({
|
|
737
|
+
name: S.String,
|
|
738
|
+
type: S.String,
|
|
739
|
+
url: S.optional(S.String),
|
|
740
|
+
cid: S.optional(S.String)
|
|
741
|
+
});
|
|
742
|
+
|
|
743
|
+
// packages/sdk/app-framework/src/plugin-intent/intent.ts
|
|
744
|
+
import { S as S2 } from "@dxos/echo-schema";
|
|
745
|
+
var createIntent = (schema, data = {}, params = {}) => {
|
|
746
|
+
const _ = S2.validateSync(schema.fields.input)(data);
|
|
747
|
+
const intent = {
|
|
748
|
+
...params,
|
|
749
|
+
_schema: schema,
|
|
750
|
+
action: schema._tag,
|
|
751
|
+
data
|
|
752
|
+
};
|
|
753
|
+
return {
|
|
754
|
+
first: intent,
|
|
755
|
+
last: intent,
|
|
756
|
+
all: [
|
|
757
|
+
intent
|
|
758
|
+
]
|
|
759
|
+
};
|
|
760
|
+
};
|
|
761
|
+
var chain = (schema, data = {}, params = {}) => (intent) => {
|
|
762
|
+
const intents = "all" in intent ? intent.all : [
|
|
763
|
+
intent
|
|
764
|
+
];
|
|
765
|
+
const first = intents[0];
|
|
766
|
+
const last = {
|
|
767
|
+
...params,
|
|
768
|
+
_schema: schema,
|
|
769
|
+
action: schema._tag,
|
|
770
|
+
data
|
|
771
|
+
};
|
|
772
|
+
return {
|
|
773
|
+
first,
|
|
774
|
+
last,
|
|
775
|
+
all: [
|
|
776
|
+
...intents,
|
|
777
|
+
last
|
|
778
|
+
]
|
|
779
|
+
};
|
|
780
|
+
};
|
|
781
|
+
var Label = S2.Union(S2.String, S2.mutable(S2.Tuple(S2.String, S2.mutable(S2.Struct({
|
|
782
|
+
ns: S2.String,
|
|
783
|
+
count: S2.optional(S2.Number)
|
|
784
|
+
})))));
|
|
785
|
+
|
|
786
|
+
// packages/sdk/app-framework/src/plugin-intent/actions.ts
|
|
787
|
+
import { S as S3 } from "@dxos/echo-schema";
|
|
788
|
+
var INTENT_PLUGIN = "dxos.org/plugin/intent";
|
|
789
|
+
var INTENT_ACTION = `${INTENT_PLUGIN}/action`;
|
|
790
|
+
var IntentAction;
|
|
791
|
+
(function(IntentAction2) {
|
|
792
|
+
class ShowUndo extends S3.TaggedClass()(`${INTENT_ACTION}/show-undo`, {
|
|
793
|
+
input: S3.Struct({
|
|
794
|
+
message: Label
|
|
795
|
+
}),
|
|
796
|
+
output: S3.Void
|
|
797
|
+
}) {
|
|
798
|
+
}
|
|
799
|
+
IntentAction2.ShowUndo = ShowUndo;
|
|
800
|
+
})(IntentAction || (IntentAction = {}));
|
|
801
|
+
|
|
802
|
+
// packages/sdk/app-framework/src/plugin-intent/intent-dispatcher.ts
|
|
803
|
+
import { Effect as Effect2, Option, pipe, Ref } from "effect";
|
|
804
|
+
import { byDisposition } from "@dxos/util";
|
|
805
|
+
|
|
806
|
+
// packages/sdk/app-framework/src/plugin-intent/errors.ts
|
|
807
|
+
var BaseError = class extends Error {
|
|
808
|
+
constructor(code, message, context) {
|
|
809
|
+
super(message ?? code);
|
|
810
|
+
this.code = code;
|
|
811
|
+
this.context = context;
|
|
812
|
+
this.name = code;
|
|
813
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
814
|
+
}
|
|
815
|
+
};
|
|
816
|
+
var NoResolversError = class extends BaseError {
|
|
817
|
+
constructor(action) {
|
|
818
|
+
super("NO_RESOLVERS", "No resolvers were found for the action", {
|
|
819
|
+
action
|
|
820
|
+
});
|
|
821
|
+
}
|
|
822
|
+
};
|
|
823
|
+
var CycleDetectedError = class extends BaseError {
|
|
824
|
+
constructor(context) {
|
|
825
|
+
super("CYCLE_DETECTED", "Intent execution limit exceeded. This is likely due to an infinite loop within intent resolvers.", context);
|
|
826
|
+
}
|
|
827
|
+
};
|
|
828
|
+
|
|
829
|
+
// packages/sdk/app-framework/src/plugin-intent/intent-dispatcher.ts
|
|
830
|
+
var EXECUTION_LIMIT = 100;
|
|
831
|
+
var HISTORY_LIMIT = 100;
|
|
832
|
+
var createResolver = (schema, effect3, params = {}) => ({
|
|
833
|
+
action: schema._tag,
|
|
834
|
+
effect: effect3,
|
|
835
|
+
...params
|
|
836
|
+
});
|
|
837
|
+
var isUndoable = (historyEntry) => historyEntry.length > 0 && historyEntry.every(({ undoable }) => !!undoable);
|
|
838
|
+
var createDispatcher = (getResolvers, { executionLimit = EXECUTION_LIMIT, historyLimit = HISTORY_LIMIT } = {}) => {
|
|
839
|
+
const historyRef = Effect2.runSync(Ref.make([]));
|
|
840
|
+
const handleIntent = (intent) => {
|
|
841
|
+
return Effect2.gen(function* () {
|
|
842
|
+
const candidates = getResolvers(intent.module).filter((r) => r.action === intent.action).filter((r) => !r.filter || r.filter(intent.data)).toSorted(byDisposition);
|
|
843
|
+
if (candidates.length === 0) {
|
|
844
|
+
return {
|
|
845
|
+
_intent: intent,
|
|
846
|
+
error: new NoResolversError(intent.action)
|
|
847
|
+
};
|
|
848
|
+
}
|
|
849
|
+
const effect3 = candidates[0].effect(intent.data, intent.undo ?? false);
|
|
850
|
+
const result = Effect2.isEffect(effect3) ? yield* effect3 : yield* Effect2.promise(async () => effect3);
|
|
851
|
+
return {
|
|
852
|
+
_intent: intent,
|
|
853
|
+
...result
|
|
854
|
+
};
|
|
855
|
+
});
|
|
856
|
+
};
|
|
857
|
+
const dispatch = (intentChain, depth = 0) => {
|
|
858
|
+
return Effect2.gen(function* () {
|
|
859
|
+
if (depth > executionLimit) {
|
|
860
|
+
yield* Effect2.fail(new CycleDetectedError());
|
|
861
|
+
}
|
|
862
|
+
const resultsRef = yield* Ref.make([]);
|
|
863
|
+
for (const intent of intentChain.all) {
|
|
864
|
+
const { data: prev } = (yield* resultsRef.get)[0] ?? {};
|
|
865
|
+
const result2 = yield* handleIntent({
|
|
866
|
+
...intent,
|
|
867
|
+
data: {
|
|
868
|
+
...intent.data,
|
|
869
|
+
...prev
|
|
870
|
+
}
|
|
871
|
+
});
|
|
872
|
+
yield* Ref.update(resultsRef, (results2) => [
|
|
873
|
+
result2,
|
|
874
|
+
...results2
|
|
875
|
+
]);
|
|
876
|
+
if (result2.intents) {
|
|
877
|
+
for (const intent2 of result2.intents) {
|
|
878
|
+
yield* dispatch(intent2, depth + 1);
|
|
879
|
+
}
|
|
880
|
+
}
|
|
881
|
+
if (result2.error) {
|
|
882
|
+
yield* Effect2.fail(result2.error);
|
|
883
|
+
}
|
|
884
|
+
}
|
|
885
|
+
const results = yield* resultsRef.get;
|
|
886
|
+
const result = results[0];
|
|
887
|
+
yield* Ref.update(historyRef, (history) => {
|
|
888
|
+
const next = [
|
|
889
|
+
...history,
|
|
890
|
+
results
|
|
891
|
+
];
|
|
892
|
+
if (next.length > historyLimit) {
|
|
893
|
+
next.splice(0, next.length - historyLimit);
|
|
894
|
+
}
|
|
895
|
+
return next;
|
|
896
|
+
});
|
|
897
|
+
if (result.undoable && isUndoable(results)) {
|
|
898
|
+
yield* pipe(dispatch(createIntent(IntentAction.ShowUndo, {
|
|
899
|
+
message: result.undoable.message
|
|
900
|
+
})), Effect2.catchSome((err) => err instanceof NoResolversError ? Option.some(Effect2.succeed(void 0)) : Option.none()));
|
|
901
|
+
}
|
|
902
|
+
return result.data;
|
|
903
|
+
});
|
|
904
|
+
};
|
|
905
|
+
const dispatchPromise = (intentChain) => {
|
|
906
|
+
return Effect2.runPromise(dispatch(intentChain)).then((data) => ({
|
|
907
|
+
data
|
|
908
|
+
})).catch((error) => ({
|
|
909
|
+
error
|
|
910
|
+
}));
|
|
911
|
+
};
|
|
912
|
+
const undo = () => {
|
|
913
|
+
return Effect2.gen(function* () {
|
|
914
|
+
const history = yield* historyRef.get;
|
|
915
|
+
const last = history.findLastIndex(isUndoable);
|
|
916
|
+
const result = last !== -1 ? history[last] : void 0;
|
|
917
|
+
if (result) {
|
|
918
|
+
const all = result.map(({ _intent, undoable }) => {
|
|
919
|
+
const data = _intent.data;
|
|
920
|
+
const undoData = undoable?.data ?? {};
|
|
921
|
+
return {
|
|
922
|
+
..._intent,
|
|
923
|
+
data: {
|
|
924
|
+
...data,
|
|
925
|
+
...undoData
|
|
926
|
+
},
|
|
927
|
+
undo: true
|
|
928
|
+
};
|
|
929
|
+
});
|
|
930
|
+
const intent = {
|
|
931
|
+
first: all[0],
|
|
932
|
+
last: all.at(-1),
|
|
933
|
+
all
|
|
934
|
+
};
|
|
935
|
+
yield* Ref.update(historyRef, (h) => h.filter((_, index) => index !== last));
|
|
936
|
+
return yield* dispatch(intent);
|
|
937
|
+
}
|
|
938
|
+
});
|
|
939
|
+
};
|
|
940
|
+
const undoPromise = () => {
|
|
941
|
+
return Effect2.runPromise(undo()).then((data) => ({
|
|
942
|
+
data
|
|
943
|
+
})).catch((error) => ({
|
|
944
|
+
error
|
|
945
|
+
}));
|
|
946
|
+
};
|
|
947
|
+
return {
|
|
948
|
+
dispatch,
|
|
949
|
+
dispatchPromise,
|
|
950
|
+
undo,
|
|
951
|
+
undoPromise
|
|
952
|
+
};
|
|
953
|
+
};
|
|
954
|
+
|
|
955
|
+
// packages/sdk/app-framework/src/react/ErrorBoundary.tsx
|
|
956
|
+
import React, { Component } from "react";
|
|
957
|
+
var ErrorBoundary = class extends Component {
|
|
958
|
+
constructor(props) {
|
|
959
|
+
super(props);
|
|
960
|
+
this.state = {
|
|
961
|
+
error: void 0
|
|
962
|
+
};
|
|
963
|
+
}
|
|
964
|
+
static getDerivedStateFromError(error) {
|
|
965
|
+
return {
|
|
966
|
+
error
|
|
967
|
+
};
|
|
968
|
+
}
|
|
969
|
+
componentDidUpdate(prevProps) {
|
|
970
|
+
if (prevProps.data !== this.props.data) {
|
|
971
|
+
this.resetError();
|
|
972
|
+
}
|
|
973
|
+
}
|
|
974
|
+
render() {
|
|
975
|
+
if (this.state.error) {
|
|
976
|
+
return /* @__PURE__ */ React.createElement(this.props.fallback, {
|
|
977
|
+
data: this.props.data,
|
|
978
|
+
error: this.state.error,
|
|
979
|
+
reset: this.resetError
|
|
980
|
+
});
|
|
981
|
+
}
|
|
982
|
+
return this.props.children;
|
|
983
|
+
}
|
|
984
|
+
resetError() {
|
|
985
|
+
this.setState({
|
|
986
|
+
error: void 0
|
|
987
|
+
});
|
|
988
|
+
}
|
|
989
|
+
};
|
|
990
|
+
|
|
991
|
+
// packages/sdk/app-framework/src/react/PluginManagerProvider.ts
|
|
992
|
+
import { createContext, useContext } from "react";
|
|
993
|
+
import { raise } from "@dxos/debug";
|
|
994
|
+
var PluginManagerContext = createContext(void 0);
|
|
995
|
+
var usePluginManager = () => useContext(PluginManagerContext) ?? raise(new Error("Missing PluginManagerContext"));
|
|
996
|
+
var PluginManagerProvider = PluginManagerContext.Provider;
|
|
997
|
+
|
|
998
|
+
// packages/sdk/app-framework/src/react/useCapabilities.ts
|
|
999
|
+
import { computed } from "@preact/signals-core";
|
|
1000
|
+
import { useMemo } from "react";
|
|
1001
|
+
var useCapabilities = (interfaceDef, filter) => {
|
|
1002
|
+
const manager = usePluginManager();
|
|
1003
|
+
const signal = useMemo(() => computed(() => manager.context.requestCapabilities(interfaceDef, filter)), [
|
|
1004
|
+
interfaceDef
|
|
1005
|
+
]);
|
|
1006
|
+
return signal.value;
|
|
1007
|
+
};
|
|
1008
|
+
var useCapability = (interfaceDef, filter) => {
|
|
1009
|
+
const manager = usePluginManager();
|
|
1010
|
+
const signal = useMemo(() => computed(() => manager.context.requestCapability(interfaceDef, filter)), [
|
|
1011
|
+
interfaceDef
|
|
1012
|
+
]);
|
|
1013
|
+
return signal.value;
|
|
1014
|
+
};
|
|
1015
|
+
|
|
1016
|
+
// packages/sdk/app-framework/src/react/Surface.tsx
|
|
1017
|
+
import React3, { memo, forwardRef, Suspense, useMemo as useMemo2 } from "react";
|
|
1018
|
+
import { useDefaultValue } from "@dxos/react-hooks";
|
|
1019
|
+
import { byDisposition as byDisposition2 } from "@dxos/util";
|
|
1020
|
+
|
|
1021
|
+
// packages/sdk/app-framework/src/common/layout.ts
|
|
1022
|
+
import { S as S4 } from "@dxos/echo-schema";
|
|
1023
|
+
|
|
1024
|
+
// packages/sdk/app-framework/src/plugin-intent/IntentContext.tsx
|
|
1025
|
+
import { createContext as createContext2, useContext as useContext2, useEffect } from "react";
|
|
1026
|
+
import { raise as raise2 } from "@dxos/debug";
|
|
1027
|
+
import { pick } from "@dxos/util";
|
|
1028
|
+
var IntentContext = /* @__PURE__ */ createContext2(void 0);
|
|
1029
|
+
var useIntentDispatcher = () => {
|
|
1030
|
+
const context = useContext2(IntentContext) ?? raise2(new Error("IntentContext not found"));
|
|
1031
|
+
return pick(context, [
|
|
1032
|
+
"dispatch",
|
|
1033
|
+
"dispatchPromise"
|
|
1034
|
+
]);
|
|
1035
|
+
};
|
|
1036
|
+
var useIntentResolver = (module, resolver) => {
|
|
1037
|
+
const manager = usePluginManager();
|
|
1038
|
+
useEffect(() => {
|
|
1039
|
+
manager.context.contributeCapability({
|
|
1040
|
+
module,
|
|
1041
|
+
interface: Capabilities.IntentResolver,
|
|
1042
|
+
implementation: resolver
|
|
1043
|
+
});
|
|
1044
|
+
return () => manager.context.removeCapability(Capabilities.IntentResolver, resolver);
|
|
1045
|
+
}, [
|
|
1046
|
+
module,
|
|
1047
|
+
resolver
|
|
1048
|
+
]);
|
|
1049
|
+
};
|
|
1050
|
+
var IntentProvider = IntentContext.Provider;
|
|
1051
|
+
|
|
1052
|
+
// packages/sdk/app-framework/src/plugin-intent/IntentPlugin.tsx
|
|
1053
|
+
import { Effect as Effect3 } from "effect";
|
|
1054
|
+
import React2 from "react";
|
|
1055
|
+
import { create as create3 } from "@dxos/live-object";
|
|
1056
|
+
var defaultEffect = () => Effect3.fail(new Error("Intent runtime not ready"));
|
|
1057
|
+
var defaultPromise = () => Effect3.runPromise(defaultEffect());
|
|
1058
|
+
var IntentPlugin = () => definePlugin({
|
|
1059
|
+
id: INTENT_PLUGIN
|
|
1060
|
+
}, [
|
|
1061
|
+
defineModule({
|
|
1062
|
+
id: `${INTENT_PLUGIN}/module/dispatcher`,
|
|
1063
|
+
// TODO(wittjosiah): This will mean that startup needs to be reset when intents are added or removed.
|
|
1064
|
+
// This is fine for now because it's how it worked prior to capabilities api anyways.
|
|
1065
|
+
// In the future, the intent dispatcher should be able to be reset without resetting the entire app.
|
|
1066
|
+
activatesOn: Events.Startup,
|
|
1067
|
+
activatesBefore: [
|
|
1068
|
+
Events.SetupIntents
|
|
1069
|
+
],
|
|
1070
|
+
activatesAfter: [
|
|
1071
|
+
Events.DispatcherReady
|
|
1072
|
+
],
|
|
1073
|
+
activate: (context) => {
|
|
1074
|
+
const state = create3({
|
|
1075
|
+
dispatch: defaultEffect,
|
|
1076
|
+
dispatchPromise: defaultPromise,
|
|
1077
|
+
undo: defaultEffect,
|
|
1078
|
+
undoPromise: defaultPromise
|
|
1079
|
+
});
|
|
1080
|
+
const { dispatch, dispatchPromise, undo, undoPromise } = createDispatcher((module) => context.requestCapabilities(Capabilities.IntentResolver, (c, moduleId) => {
|
|
1081
|
+
return module ? moduleId === module : true;
|
|
1082
|
+
}).flat());
|
|
1083
|
+
state.dispatch = dispatch;
|
|
1084
|
+
state.dispatchPromise = dispatchPromise;
|
|
1085
|
+
state.undo = undo;
|
|
1086
|
+
state.undoPromise = undoPromise;
|
|
1087
|
+
return [
|
|
1088
|
+
contributes(Capabilities.IntentDispatcher, state),
|
|
1089
|
+
contributes(Capabilities.ReactContext, {
|
|
1090
|
+
id: INTENT_PLUGIN,
|
|
1091
|
+
context: ({ children }) => /* @__PURE__ */ React2.createElement(IntentProvider, {
|
|
1092
|
+
value: state
|
|
1093
|
+
}, children)
|
|
1094
|
+
})
|
|
1095
|
+
];
|
|
1096
|
+
}
|
|
1097
|
+
})
|
|
1098
|
+
]);
|
|
1099
|
+
|
|
1100
|
+
// packages/sdk/app-framework/src/common/layout.ts
|
|
1101
|
+
var Toast = S4.Struct({
|
|
1102
|
+
id: S4.String,
|
|
1103
|
+
title: S4.optional(Label),
|
|
1104
|
+
description: S4.optional(Label),
|
|
1105
|
+
icon: S4.optional(S4.String),
|
|
1106
|
+
duration: S4.optional(S4.Number),
|
|
1107
|
+
closeLabel: S4.optional(Label),
|
|
1108
|
+
actionLabel: S4.optional(Label),
|
|
1109
|
+
actionAlt: S4.optional(Label),
|
|
1110
|
+
// TODO(wittjosiah): Make class with customizable method?
|
|
1111
|
+
onAction: S4.optional(S4.Any)
|
|
1112
|
+
});
|
|
1113
|
+
var LayoutMode = S4.Union(S4.Literal("deck"), S4.Literal("solo"), S4.Literal("fullscreen"));
|
|
1114
|
+
var isLayoutMode = (value) => S4.is(LayoutMode)(value);
|
|
1115
|
+
var Layout = S4.mutable(S4.Struct({
|
|
1116
|
+
layoutMode: LayoutMode,
|
|
1117
|
+
sidebarOpen: S4.Boolean,
|
|
1118
|
+
complementarySidebarOpen: S4.Boolean,
|
|
1119
|
+
/**
|
|
1120
|
+
* @deprecated Data to be passed to the complementary sidebar Surface.
|
|
1121
|
+
*/
|
|
1122
|
+
complementarySidebarContent: S4.optional(S4.Any),
|
|
1123
|
+
dialogOpen: S4.Boolean,
|
|
1124
|
+
/**
|
|
1125
|
+
* Data to be passed to the dialog Surface.
|
|
1126
|
+
*/
|
|
1127
|
+
dialogContent: S4.optional(S4.Any),
|
|
1128
|
+
// TODO(wittjosiah): Custom properties?
|
|
1129
|
+
dialogBlockAlign: S4.optional(S4.Literal("start", "center")),
|
|
1130
|
+
dialogType: S4.optional(S4.Literal("default", "alert")),
|
|
1131
|
+
popoverOpen: S4.Boolean,
|
|
1132
|
+
/**
|
|
1133
|
+
* Data to be passed to the popover Surface.
|
|
1134
|
+
*/
|
|
1135
|
+
popoverContent: S4.optional(S4.Any),
|
|
1136
|
+
popoverAnchorId: S4.optional(S4.String),
|
|
1137
|
+
toasts: S4.mutable(S4.Array(Toast)),
|
|
1138
|
+
/**
|
|
1139
|
+
* The identifier of a component to scroll into view when it is mounted.
|
|
1140
|
+
*/
|
|
1141
|
+
scrollIntoView: S4.optional(S4.String)
|
|
1142
|
+
}));
|
|
1143
|
+
var LAYOUT_PLUGIN = "dxos.org/plugin/layout";
|
|
1144
|
+
var LAYOUT_ACTION = `${LAYOUT_PLUGIN}/action`;
|
|
1145
|
+
var LayoutAction;
|
|
1146
|
+
(function(LayoutAction2) {
|
|
1147
|
+
class SetLayout extends S4.TaggedClass()(`${LAYOUT_ACTION}/set-layout`, {
|
|
1148
|
+
input: S4.Struct({
|
|
1149
|
+
/**
|
|
1150
|
+
* Element to set the state of.
|
|
1151
|
+
*/
|
|
1152
|
+
element: S4.Literal("fullscreen", "sidebar", "complementary", "dialog", "popover", "toast"),
|
|
1153
|
+
/**
|
|
1154
|
+
* Whether the element is on or off.
|
|
1155
|
+
*
|
|
1156
|
+
* If omitted, the element's state will be toggled or set based on other provided data.
|
|
1157
|
+
* For example, if `component` is provided, the state will be set to `true`.
|
|
1158
|
+
*/
|
|
1159
|
+
state: S4.optional(S4.Boolean),
|
|
1160
|
+
/**
|
|
1161
|
+
* Component to render in the dialog or popover.
|
|
1162
|
+
*/
|
|
1163
|
+
component: S4.optional(S4.String),
|
|
1164
|
+
/**
|
|
1165
|
+
* Data to be passed to the dialog or popover Surface.
|
|
1166
|
+
*/
|
|
1167
|
+
subject: S4.optional(S4.Any),
|
|
1168
|
+
/**
|
|
1169
|
+
* Anchor ID for the popover.
|
|
1170
|
+
*/
|
|
1171
|
+
anchorId: S4.optional(S4.String),
|
|
1172
|
+
// TODO(wittjosiah): Custom properties?
|
|
1173
|
+
/**
|
|
1174
|
+
* Block alignment for the dialog.
|
|
1175
|
+
*/
|
|
1176
|
+
dialogBlockAlign: S4.optional(S4.Literal("start", "center")),
|
|
1177
|
+
/**
|
|
1178
|
+
* Type of dialog.
|
|
1179
|
+
*/
|
|
1180
|
+
dialogType: S4.optional(S4.Literal("default", "alert"))
|
|
1181
|
+
}),
|
|
1182
|
+
output: S4.Void
|
|
1183
|
+
}) {
|
|
1184
|
+
}
|
|
1185
|
+
LayoutAction2.SetLayout = SetLayout;
|
|
1186
|
+
class SetLayoutMode extends S4.TaggedClass()(`${LAYOUT_ACTION}/set-layout-mode`, {
|
|
1187
|
+
input: S4.Union(S4.Struct({
|
|
1188
|
+
layoutMode: LayoutMode
|
|
1189
|
+
}), S4.Struct({
|
|
1190
|
+
revert: S4.Literal(true)
|
|
1191
|
+
})),
|
|
1192
|
+
output: S4.Void
|
|
1193
|
+
}) {
|
|
1194
|
+
}
|
|
1195
|
+
LayoutAction2.SetLayoutMode = SetLayoutMode;
|
|
1196
|
+
class ScrollIntoView extends S4.TaggedClass()(`${LAYOUT_ACTION}/scroll-into-view`, {
|
|
1197
|
+
input: S4.Struct({
|
|
1198
|
+
id: S4.optional(S4.String),
|
|
1199
|
+
// TODO(wittjosiah): Factor out to thread scroll into view action?
|
|
1200
|
+
cursor: S4.optional(S4.String),
|
|
1201
|
+
ref: S4.optional(S4.String)
|
|
1202
|
+
}),
|
|
1203
|
+
output: S4.Void
|
|
1204
|
+
}) {
|
|
1205
|
+
}
|
|
1206
|
+
LayoutAction2.ScrollIntoView = ScrollIntoView;
|
|
1207
|
+
})(LayoutAction || (LayoutAction = {}));
|
|
1208
|
+
|
|
1209
|
+
// packages/sdk/app-framework/src/common/navigation.ts
|
|
1210
|
+
import { Schema as S5 } from "@effect/schema";
|
|
1211
|
+
import { pick as pick2 } from "@dxos/util";
|
|
1212
|
+
var SLUG_LIST_SEPARATOR = "+";
|
|
1213
|
+
var SLUG_ENTRY_SEPARATOR = "_";
|
|
1214
|
+
var SLUG_KEY_VALUE_SEPARATOR = "-";
|
|
1215
|
+
var SLUG_PATH_SEPARATOR = "~";
|
|
1216
|
+
var SLUG_COLLECTION_INDICATOR = "";
|
|
1217
|
+
var LayoutEntrySchema = S5.mutable(S5.Struct({
|
|
1218
|
+
id: S5.String,
|
|
1219
|
+
path: S5.optional(S5.String)
|
|
1220
|
+
}));
|
|
1221
|
+
var LayoutPartSchema = S5.Union(S5.Literal("sidebar"), S5.Literal("main"), S5.Literal("solo"), S5.Literal("complementary"), S5.Literal("fullScreen"));
|
|
1222
|
+
var LayoutPartsSchema = S5.partial(S5.mutable(S5.Record({
|
|
1223
|
+
key: LayoutPartSchema,
|
|
1224
|
+
value: S5.mutable(S5.Array(LayoutEntrySchema))
|
|
1225
|
+
})));
|
|
1226
|
+
var LayoutCoordinateSchema = S5.mutable(S5.Struct({
|
|
1227
|
+
part: LayoutPartSchema,
|
|
1228
|
+
entryId: S5.String
|
|
1229
|
+
}));
|
|
1230
|
+
var PartAdjustmentSchema = S5.Union(S5.Literal("increment-start"), S5.Literal("increment-end"), S5.Literal("pin-start"), S5.Literal("pin-end"), S5.Literal("close"), S5.Literal("solo"));
|
|
1231
|
+
var LayoutAdjustmentSchema = S5.mutable(S5.Struct({
|
|
1232
|
+
layoutCoordinate: LayoutCoordinateSchema,
|
|
1233
|
+
type: PartAdjustmentSchema
|
|
1234
|
+
}));
|
|
1235
|
+
var ActiveParts = S5.Record({
|
|
1236
|
+
key: S5.String,
|
|
1237
|
+
value: S5.Union(S5.String, S5.mutable(S5.Array(S5.String)))
|
|
1238
|
+
});
|
|
1239
|
+
var LocationProvidesSchema = S5.mutable(S5.Struct({
|
|
1240
|
+
location: S5.Struct({
|
|
1241
|
+
active: LayoutPartsSchema,
|
|
1242
|
+
closed: S5.Array(S5.String)
|
|
1243
|
+
})
|
|
1244
|
+
}));
|
|
1245
|
+
var isLayoutParts = (value) => {
|
|
1246
|
+
return S5.is(LayoutPartsSchema)(value);
|
|
1247
|
+
};
|
|
1248
|
+
var isLayoutAdjustment = (value) => {
|
|
1249
|
+
return S5.is(LayoutAdjustmentSchema)(value);
|
|
1250
|
+
};
|
|
1251
|
+
var openIds = (layout, parts) => {
|
|
1252
|
+
return Object.values(parts ? pick2(layout, parts) : layout).flatMap((part) => part?.map((entry) => entry.id) ?? []).filter((id) => id !== void 0);
|
|
1253
|
+
};
|
|
1254
|
+
var firstIdInPart = (layout, part) => {
|
|
1255
|
+
if (!layout) {
|
|
1256
|
+
return void 0;
|
|
1257
|
+
}
|
|
1258
|
+
return layout[part]?.at(0)?.id;
|
|
1259
|
+
};
|
|
1260
|
+
var indexInPart = (layout, layoutCoordinate) => {
|
|
1261
|
+
if (!layout || !layoutCoordinate) {
|
|
1262
|
+
return void 0;
|
|
1263
|
+
}
|
|
1264
|
+
const { part, entryId } = layoutCoordinate;
|
|
1265
|
+
return layout[part]?.findIndex((entry) => entry.id === entryId);
|
|
1266
|
+
};
|
|
1267
|
+
var partLength = (layout, part) => {
|
|
1268
|
+
if (!layout || !part) {
|
|
1269
|
+
return 0;
|
|
1270
|
+
}
|
|
1271
|
+
return layout[part]?.length ?? 0;
|
|
1272
|
+
};
|
|
1273
|
+
var NAVIGATION_PLUGIN = "dxos.org/plugin/navigation";
|
|
1274
|
+
var NAVIGATION_ACTION = `${NAVIGATION_PLUGIN}/action`;
|
|
1275
|
+
var NavigationAction;
|
|
1276
|
+
(function(NavigationAction2) {
|
|
1277
|
+
class Open extends S5.TaggedClass()(`${NAVIGATION_ACTION}/open`, {
|
|
1278
|
+
input: S5.Struct({
|
|
1279
|
+
activeParts: ActiveParts,
|
|
1280
|
+
noToggle: S5.optional(S5.Boolean)
|
|
1281
|
+
}),
|
|
1282
|
+
output: S5.Struct({
|
|
1283
|
+
open: S5.Array(S5.String)
|
|
1284
|
+
})
|
|
1285
|
+
}) {
|
|
1286
|
+
}
|
|
1287
|
+
NavigationAction2.Open = Open;
|
|
1288
|
+
class AddToActive extends S5.TaggedClass()(`${NAVIGATION_ACTION}/add-to-active`, {
|
|
1289
|
+
input: S5.Struct({
|
|
1290
|
+
id: S5.String,
|
|
1291
|
+
part: LayoutPartSchema,
|
|
1292
|
+
scrollIntoView: S5.optional(S5.Boolean),
|
|
1293
|
+
pivotId: S5.optional(S5.String),
|
|
1294
|
+
positioning: S5.optional(S5.Literal("start", "end"))
|
|
1295
|
+
}),
|
|
1296
|
+
output: S5.Void
|
|
1297
|
+
}) {
|
|
1298
|
+
}
|
|
1299
|
+
NavigationAction2.AddToActive = AddToActive;
|
|
1300
|
+
class Set2 extends S5.TaggedClass()(`${NAVIGATION_ACTION}/set`, {
|
|
1301
|
+
input: S5.Struct({
|
|
1302
|
+
activeParts: ActiveParts
|
|
1303
|
+
}),
|
|
1304
|
+
output: S5.Void
|
|
1305
|
+
}) {
|
|
1306
|
+
}
|
|
1307
|
+
NavigationAction2.Set = Set2;
|
|
1308
|
+
class Close extends S5.TaggedClass()(`${NAVIGATION_ACTION}/close`, {
|
|
1309
|
+
input: S5.Struct({
|
|
1310
|
+
activeParts: ActiveParts,
|
|
1311
|
+
noToggle: S5.optional(S5.Boolean)
|
|
1312
|
+
}),
|
|
1313
|
+
output: S5.Void
|
|
1314
|
+
}) {
|
|
1315
|
+
}
|
|
1316
|
+
NavigationAction2.Close = Close;
|
|
1317
|
+
class Adjust extends S5.TaggedClass()(`${NAVIGATION_ACTION}/adjust`, {
|
|
1318
|
+
input: LayoutAdjustmentSchema,
|
|
1319
|
+
output: S5.Void
|
|
1320
|
+
}) {
|
|
1321
|
+
}
|
|
1322
|
+
NavigationAction2.Adjust = Adjust;
|
|
1323
|
+
class Expose extends S5.TaggedClass()(`${NAVIGATION_ACTION}/expose`, {
|
|
1324
|
+
input: S5.Struct({
|
|
1325
|
+
id: S5.String
|
|
1326
|
+
}),
|
|
1327
|
+
output: S5.Void
|
|
1328
|
+
}) {
|
|
1329
|
+
}
|
|
1330
|
+
NavigationAction2.Expose = Expose;
|
|
1331
|
+
})(NavigationAction || (NavigationAction = {}));
|
|
1332
|
+
|
|
1333
|
+
// packages/sdk/app-framework/src/common/surface.ts
|
|
1334
|
+
var createSurface = (definition) => definition;
|
|
1335
|
+
|
|
1336
|
+
// packages/sdk/app-framework/src/common/translations.ts
|
|
1337
|
+
import { z } from "zod";
|
|
1338
|
+
var ResourceKey = z.union([
|
|
1339
|
+
z.string(),
|
|
1340
|
+
z.record(z.any())
|
|
1341
|
+
]);
|
|
1342
|
+
var ResourceLanguage = z.record(ResourceKey);
|
|
1343
|
+
var Resource = z.record(ResourceLanguage);
|
|
1344
|
+
|
|
1345
|
+
// packages/sdk/app-framework/src/react/Surface.tsx
|
|
1346
|
+
var useSurfaces = () => {
|
|
1347
|
+
const surfaces = useCapabilities(Capabilities.ReactSurface);
|
|
1348
|
+
return useMemo2(() => surfaces.flat(), [
|
|
1349
|
+
surfaces
|
|
1350
|
+
]);
|
|
1351
|
+
};
|
|
1352
|
+
var findCandidates = (surfaces, { role, data }) => {
|
|
1353
|
+
return Object.values(surfaces).filter((definition) => Array.isArray(definition.role) ? definition.role.includes(role) : definition.role === role).filter(({ filter }) => filter ? filter(data ?? {}) : true).toSorted(byDisposition2);
|
|
1354
|
+
};
|
|
1355
|
+
var isSurfaceAvailable = (context, { role, data }) => {
|
|
1356
|
+
const surfaces = context.requestCapabilities(Capabilities.ReactSurface);
|
|
1357
|
+
const candidates = findCandidates(surfaces.flat(), {
|
|
1358
|
+
role,
|
|
1359
|
+
data
|
|
1360
|
+
});
|
|
1361
|
+
return candidates.length > 0;
|
|
1362
|
+
};
|
|
1363
|
+
var Surface = /* @__PURE__ */ memo(/* @__PURE__ */ forwardRef(({ id: _id, role, data: _data, limit, fallback, placeholder, ...rest }, forwardedRef) => {
|
|
1364
|
+
const surfaces = useSurfaces();
|
|
1365
|
+
const data = useDefaultValue(_data, () => ({}));
|
|
1366
|
+
const candidates = useMemo2(() => {
|
|
1367
|
+
const definitions = findCandidates(surfaces, {
|
|
1368
|
+
role,
|
|
1369
|
+
data
|
|
1370
|
+
});
|
|
1371
|
+
return limit ? definitions.slice(0, limit) : definitions;
|
|
1372
|
+
}, [
|
|
1373
|
+
surfaces,
|
|
1374
|
+
role,
|
|
1375
|
+
data,
|
|
1376
|
+
limit
|
|
1377
|
+
]);
|
|
1378
|
+
const nodes = candidates.map(({ component: Component2, id }) => /* @__PURE__ */ React3.createElement(Component2, {
|
|
1379
|
+
ref: forwardedRef,
|
|
1380
|
+
key: id,
|
|
1381
|
+
id,
|
|
1382
|
+
role,
|
|
1383
|
+
data,
|
|
1384
|
+
limit,
|
|
1385
|
+
...rest
|
|
1386
|
+
}));
|
|
1387
|
+
const suspense = placeholder ? /* @__PURE__ */ React3.createElement(Suspense, {
|
|
1388
|
+
fallback: placeholder
|
|
1389
|
+
}, nodes) : nodes;
|
|
1390
|
+
return fallback ? /* @__PURE__ */ React3.createElement(ErrorBoundary, {
|
|
1391
|
+
data,
|
|
1392
|
+
fallback
|
|
1393
|
+
}, suspense) : suspense;
|
|
1394
|
+
}));
|
|
1395
|
+
|
|
1396
|
+
// packages/sdk/app-framework/src/App.tsx
|
|
1397
|
+
import { effect as effect2 } from "@preact/signals-core";
|
|
1398
|
+
import React4 from "react";
|
|
1399
|
+
import { invariant as invariant2 } from "@dxos/invariant";
|
|
1400
|
+
import { create as create4 } from "@dxos/live-object";
|
|
1401
|
+
|
|
1402
|
+
// packages/sdk/app-framework/src/helpers.ts
|
|
1403
|
+
var topologicalSort = (nodes) => {
|
|
1404
|
+
const getDependencies = (nodeId, seen = /* @__PURE__ */ new Set(), path = /* @__PURE__ */ new Set()) => {
|
|
1405
|
+
if (path.has(nodeId)) {
|
|
1406
|
+
throw new Error(`Circular dependency detected involving ${nodeId}`);
|
|
1407
|
+
}
|
|
1408
|
+
if (seen.has(nodeId)) {
|
|
1409
|
+
return [];
|
|
1410
|
+
}
|
|
1411
|
+
const node = nodes.find((n) => n.id === nodeId);
|
|
1412
|
+
if (!node) {
|
|
1413
|
+
throw new Error(`Node ${nodeId} not found but is listed as a dependency`);
|
|
1414
|
+
}
|
|
1415
|
+
const newPath = /* @__PURE__ */ new Set([
|
|
1416
|
+
...path,
|
|
1417
|
+
nodeId
|
|
1418
|
+
]);
|
|
1419
|
+
const newSeen = /* @__PURE__ */ new Set([
|
|
1420
|
+
...seen,
|
|
1421
|
+
nodeId
|
|
1422
|
+
]);
|
|
1423
|
+
const dependsOn = node.dependsOn ?? [];
|
|
1424
|
+
return [
|
|
1425
|
+
...dependsOn.flatMap((depId) => getDependencies(depId, newSeen, newPath)),
|
|
1426
|
+
nodeId
|
|
1427
|
+
];
|
|
1428
|
+
};
|
|
1429
|
+
const allDependencies = nodes.map((node) => node.id).flatMap((id) => getDependencies(id)).filter((id, index, self) => self.indexOf(id) === index);
|
|
1430
|
+
return allDependencies.map((id) => nodes.find((node) => node.id === id)).filter((node) => node !== void 0);
|
|
1431
|
+
};
|
|
1432
|
+
|
|
1433
|
+
// packages/sdk/app-framework/src/App.tsx
|
|
1434
|
+
var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/sdk/app-framework/src/App.tsx";
|
|
1435
|
+
var ENABLED_KEY = "dxos.org/app-framework/enabled";
|
|
1436
|
+
var createApp = ({ pluginManager, pluginLoader: _pluginLoader, plugins = [], core = plugins.map(({ meta }) => meta.id), defaults = [], placeholder = null, fallback = DefaultFallback, cacheEnabled = false }) => {
|
|
1437
|
+
const pluginLoader = _pluginLoader ?? ((id) => {
|
|
1438
|
+
const plugin = plugins.find((plugin2) => plugin2.meta.id === id);
|
|
1439
|
+
invariant2(plugin, `Plugin not found: ${id}`, {
|
|
1440
|
+
F: __dxlog_file3,
|
|
1441
|
+
L: 68,
|
|
1442
|
+
S: void 0,
|
|
1443
|
+
A: [
|
|
1444
|
+
"plugin",
|
|
1445
|
+
"`Plugin not found: ${id}`"
|
|
1446
|
+
]
|
|
1447
|
+
});
|
|
1448
|
+
return plugin;
|
|
1449
|
+
});
|
|
1450
|
+
const state = create4({
|
|
1451
|
+
ready: false,
|
|
1452
|
+
error: null
|
|
1453
|
+
});
|
|
1454
|
+
const cached = JSON.parse(localStorage.getItem(ENABLED_KEY) ?? "[]");
|
|
1455
|
+
const enabled = cacheEnabled && cached.length > 0 ? cached : defaults;
|
|
1456
|
+
const manager = pluginManager ?? new PluginManager({
|
|
1457
|
+
pluginLoader,
|
|
1458
|
+
plugins,
|
|
1459
|
+
core,
|
|
1460
|
+
enabled
|
|
1461
|
+
});
|
|
1462
|
+
manager.activation.on(({ event, state: _state, error }) => {
|
|
1463
|
+
if (event === Events.Startup.id) {
|
|
1464
|
+
state.ready = _state === "activated";
|
|
1465
|
+
}
|
|
1466
|
+
if (error && !state.ready && !state.error) {
|
|
1467
|
+
state.error = error;
|
|
1468
|
+
}
|
|
1469
|
+
});
|
|
1470
|
+
effect2(() => {
|
|
1471
|
+
cacheEnabled && localStorage.setItem(ENABLED_KEY, JSON.stringify(manager.enabled));
|
|
1472
|
+
});
|
|
1473
|
+
manager.context.contributeCapability({
|
|
1474
|
+
interface: Capabilities.PluginManager,
|
|
1475
|
+
implementation: manager,
|
|
1476
|
+
module: "dxos.org/app-framework/plugin-manager"
|
|
1477
|
+
});
|
|
1478
|
+
setupDevtools(manager);
|
|
1479
|
+
void manager.activate(Events.Startup);
|
|
1480
|
+
return () => /* @__PURE__ */ React4.createElement(ErrorBoundary, {
|
|
1481
|
+
fallback
|
|
1482
|
+
}, /* @__PURE__ */ React4.createElement(App, {
|
|
1483
|
+
placeholder,
|
|
1484
|
+
manager,
|
|
1485
|
+
state
|
|
1486
|
+
}));
|
|
1487
|
+
};
|
|
1488
|
+
var App = ({ placeholder, manager, state }) => {
|
|
1489
|
+
if (state.error) {
|
|
1490
|
+
throw state.error;
|
|
1491
|
+
}
|
|
1492
|
+
if (!state.ready) {
|
|
1493
|
+
return /* @__PURE__ */ React4.createElement(React4.Fragment, null, placeholder);
|
|
1494
|
+
}
|
|
1495
|
+
const reactContexts = manager.context.requestCapabilities(Capabilities.ReactContext);
|
|
1496
|
+
const reactRoots = manager.context.requestCapabilities(Capabilities.ReactRoot);
|
|
1497
|
+
const ComposedContext = composeContexts(reactContexts);
|
|
1498
|
+
return /* @__PURE__ */ React4.createElement(PluginManagerProvider, {
|
|
1499
|
+
value: manager
|
|
1500
|
+
}, /* @__PURE__ */ React4.createElement(ComposedContext, null, reactRoots.map(({ id, root: Component2 }) => /* @__PURE__ */ React4.createElement(Component2, {
|
|
1501
|
+
key: id
|
|
1502
|
+
}))));
|
|
1503
|
+
};
|
|
1504
|
+
var DefaultFallback = ({ error }) => {
|
|
1505
|
+
return /* @__PURE__ */ React4.createElement("div", {
|
|
1506
|
+
style: {
|
|
1507
|
+
padding: "1rem"
|
|
1508
|
+
}
|
|
1509
|
+
}, /* @__PURE__ */ React4.createElement("h1", {
|
|
1510
|
+
style: {
|
|
1511
|
+
fontSize: "1.2rem",
|
|
1512
|
+
fontWeight: 700,
|
|
1513
|
+
margin: "0.5rem 0"
|
|
1514
|
+
}
|
|
1515
|
+
}, error.message), /* @__PURE__ */ React4.createElement("pre", null, error.stack));
|
|
1516
|
+
};
|
|
1517
|
+
var composeContexts = (contexts) => {
|
|
1518
|
+
if (contexts.length === 0) {
|
|
1519
|
+
return ({ children }) => /* @__PURE__ */ React4.createElement(React4.Fragment, null, children);
|
|
1520
|
+
}
|
|
1521
|
+
return topologicalSort(contexts).map(({ context }) => context).reduce((Acc, Next) => ({ children }) => /* @__PURE__ */ React4.createElement(Acc, null, /* @__PURE__ */ React4.createElement(Next, null, children)));
|
|
1522
|
+
};
|
|
1523
|
+
var setupDevtools = (manager) => {
|
|
1524
|
+
globalThis.composer ??= {};
|
|
1525
|
+
globalThis.composer.manager = manager;
|
|
1526
|
+
};
|
|
1527
|
+
|
|
1528
|
+
export {
|
|
1529
|
+
defineCapability,
|
|
1530
|
+
contributes,
|
|
1531
|
+
lazy,
|
|
1532
|
+
PluginsContext,
|
|
1533
|
+
defineEvent,
|
|
1534
|
+
eventKey,
|
|
1535
|
+
oneOf,
|
|
1536
|
+
allOf,
|
|
1537
|
+
isOneOf,
|
|
1538
|
+
isAllOf,
|
|
1539
|
+
getEvents,
|
|
1540
|
+
PluginManager,
|
|
1541
|
+
PluginModule,
|
|
1542
|
+
defineModule,
|
|
1543
|
+
Plugin,
|
|
1544
|
+
definePlugin,
|
|
1545
|
+
Capabilities,
|
|
1546
|
+
Events,
|
|
1547
|
+
defaultFileTypes,
|
|
1548
|
+
FileInfoSchema,
|
|
1549
|
+
createIntent,
|
|
1550
|
+
chain,
|
|
1551
|
+
Label,
|
|
1552
|
+
INTENT_PLUGIN,
|
|
1553
|
+
INTENT_ACTION,
|
|
1554
|
+
IntentAction,
|
|
1555
|
+
createResolver,
|
|
1556
|
+
createDispatcher,
|
|
1557
|
+
ErrorBoundary,
|
|
1558
|
+
usePluginManager,
|
|
1559
|
+
PluginManagerProvider,
|
|
1560
|
+
useCapabilities,
|
|
1561
|
+
useCapability,
|
|
1562
|
+
isSurfaceAvailable,
|
|
1563
|
+
Surface,
|
|
1564
|
+
useIntentDispatcher,
|
|
1565
|
+
useIntentResolver,
|
|
1566
|
+
IntentProvider,
|
|
1567
|
+
IntentPlugin,
|
|
1568
|
+
Toast,
|
|
1569
|
+
isLayoutMode,
|
|
1570
|
+
Layout,
|
|
1571
|
+
LAYOUT_PLUGIN,
|
|
1572
|
+
LAYOUT_ACTION,
|
|
1573
|
+
LayoutAction,
|
|
1574
|
+
SLUG_LIST_SEPARATOR,
|
|
1575
|
+
SLUG_ENTRY_SEPARATOR,
|
|
1576
|
+
SLUG_KEY_VALUE_SEPARATOR,
|
|
1577
|
+
SLUG_PATH_SEPARATOR,
|
|
1578
|
+
SLUG_COLLECTION_INDICATOR,
|
|
1579
|
+
ActiveParts,
|
|
1580
|
+
isLayoutParts,
|
|
1581
|
+
isLayoutAdjustment,
|
|
1582
|
+
openIds,
|
|
1583
|
+
firstIdInPart,
|
|
1584
|
+
indexInPart,
|
|
1585
|
+
partLength,
|
|
1586
|
+
NAVIGATION_PLUGIN,
|
|
1587
|
+
NAVIGATION_ACTION,
|
|
1588
|
+
NavigationAction,
|
|
1589
|
+
createSurface,
|
|
1590
|
+
ResourceKey,
|
|
1591
|
+
ResourceLanguage,
|
|
1592
|
+
Resource,
|
|
1593
|
+
createApp
|
|
1594
|
+
};
|
|
1595
|
+
//# sourceMappingURL=chunk-EGGZVV7Q.mjs.map
|