@dxos/app-framework 0.7.5-main.9cb18ac → 0.7.5-main.9d2a38b
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-GNLU3GAU.mjs +1595 -0
- package/dist/lib/browser/chunk-GNLU3GAU.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +112 -618
- 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-FBA4BB3J.cjs +1639 -0
- package/dist/lib/node/chunk-FBA4BB3J.cjs.map +7 -0
- package/dist/lib/node/index.cjs +123 -651
- 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-KPMTPXQI.mjs +1597 -0
- package/dist/lib/node-esm/chunk-KPMTPXQI.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +112 -618
- 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/{plugins/common → common}/layout.d.ts +0 -11
- package/dist/types/src/common/layout.d.ts.map +1 -0
- package/dist/types/src/{plugins/common → common}/navigation.d.ts +0 -2
- package/dist/types/src/common/navigation.d.ts.map +1 -0
- package/dist/types/src/{plugins/plugin-surface/SurfaceContext.d.ts → common/surface.d.ts} +12 -29
- 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/{plugins/plugin-intent → plugin-intent}/IntentContext.d.ts +1 -1
- 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/{plugins/plugin-intent → plugin-intent}/intent-dispatcher.d.ts +18 -19
- package/dist/types/src/plugin-intent/intent-dispatcher.d.ts.map +1 -0
- package/dist/types/src/plugin-intent/intent-dispatcher.test.d.ts.map +1 -0
- package/dist/types/src/{plugins/plugin-intent → plugin-intent}/intent.d.ts +5 -25
- 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/{plugins/plugin-settings/provides.d.ts → plugin-settings/actions.d.ts} +1 -10
- 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 -1
- package/package.json +28 -15
- 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/{plugins/common → common}/layout.ts +0 -16
- package/src/{plugins/common → common}/navigation.ts +0 -15
- package/src/{plugins/plugin-surface/SurfaceContext.ts → common/surface.ts} +6 -37
- 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/{plugins/plugin-intent → plugin-intent}/IntentContext.tsx +12 -4
- 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/{plugins/plugin-intent → plugin-intent}/index.ts +2 -6
- package/src/{plugins/plugin-intent → plugin-intent}/intent-dispatcher.test.ts +36 -35
- package/src/{plugins/plugin-intent → plugin-intent}/intent-dispatcher.ts +49 -65
- package/src/{plugins/plugin-intent → plugin-intent}/intent.ts +5 -21
- 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 +39 -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 +13 -1
- package/dist/lib/browser/chunk-3E7RY3CE.mjs +0 -72
- package/dist/lib/browser/chunk-3E7RY3CE.mjs.map +0 -7
- package/dist/lib/browser/chunk-QG25ZU2N.mjs +0 -320
- package/dist/lib/browser/chunk-QG25ZU2N.mjs.map +0 -7
- package/dist/lib/browser/chunk-SPDTXTOV.mjs +0 -163
- package/dist/lib/browser/chunk-SPDTXTOV.mjs.map +0 -7
- package/dist/lib/browser/chunk-WBOXEHBE.mjs +0 -51
- package/dist/lib/browser/chunk-WBOXEHBE.mjs.map +0 -7
- package/dist/lib/browser/plugin-intent-T7Y3MJ5C.mjs +0 -32
- package/dist/lib/browser/plugin-intent-T7Y3MJ5C.mjs.map +0 -7
- package/dist/lib/browser/plugin-settings-5U2L2NRU.mjs +0 -15
- package/dist/lib/browser/plugin-settings-5U2L2NRU.mjs.map +0 -7
- package/dist/lib/browser/plugin-surface-OKPF3EQI.mjs +0 -24
- package/dist/lib/browser/plugin-surface-OKPF3EQI.mjs.map +0 -7
- package/dist/lib/node/chunk-BW3RNEVI.cjs +0 -185
- package/dist/lib/node/chunk-BW3RNEVI.cjs.map +0 -7
- package/dist/lib/node/chunk-FCMHRU3M.cjs +0 -70
- package/dist/lib/node/chunk-FCMHRU3M.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-VWHAALIN.cjs +0 -344
- package/dist/lib/node/chunk-VWHAALIN.cjs.map +0 -7
- package/dist/lib/node/plugin-intent-F3TQZIUR.cjs +0 -53
- package/dist/lib/node/plugin-intent-F3TQZIUR.cjs.map +0 -7
- package/dist/lib/node/plugin-settings-W6UHMH5M.cjs +0 -36
- package/dist/lib/node/plugin-settings-W6UHMH5M.cjs.map +0 -7
- package/dist/lib/node/plugin-surface-CCSIONYW.cjs +0 -45
- package/dist/lib/node/plugin-surface-CCSIONYW.cjs.map +0 -7
- package/dist/lib/node-esm/chunk-3T5UIJY3.mjs +0 -53
- package/dist/lib/node-esm/chunk-3T5UIJY3.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-4GX7V5ZE.mjs +0 -164
- package/dist/lib/node-esm/chunk-4GX7V5ZE.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-CFOUYXQ6.mjs +0 -321
- package/dist/lib/node-esm/chunk-CFOUYXQ6.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/plugin-intent-W2HQC6LC.mjs +0 -33
- package/dist/lib/node-esm/plugin-intent-W2HQC6LC.mjs.map +0 -7
- package/dist/lib/node-esm/plugin-settings-H5RHNFVC.mjs +0 -16
- package/dist/lib/node-esm/plugin-settings-H5RHNFVC.mjs.map +0 -7
- package/dist/lib/node-esm/plugin-surface-V3YET3UL.mjs +0 -25
- package/dist/lib/node-esm/plugin-surface-V3YET3UL.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.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 -16
- 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 -6
- package/dist/types/src/plugins/plugin-host/index.d.ts.map +0 -1
- package/dist/types/src/plugins/plugin-host/plugin.d.ts +0 -104
- 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.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/index.d.ts +0 -7
- package/dist/types/src/plugins/plugin-intent/index.d.ts.map +0 -1
- package/dist/types/src/plugins/plugin-intent/intent-dispatcher.d.ts.map +0 -1
- package/dist/types/src/plugins/plugin-intent/intent-dispatcher.test.d.ts.map +0 -1
- package/dist/types/src/plugins/plugin-intent/intent.d.ts.map +0 -1
- package/dist/types/src/plugins/plugin-intent/meta.d.ts +0 -6
- package/dist/types/src/plugins/plugin-intent/meta.d.ts.map +0 -1
- package/dist/types/src/plugins/plugin-intent/provides.d.ts +0 -16
- 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.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 -7
- package/dist/types/src/plugins/plugin-surface/Surface.d.ts.map +0 -1
- package/dist/types/src/plugins/plugin-surface/SurfaceContext.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/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 -17
- 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/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 -88
- 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 -12
- package/src/plugins/plugin-host/plugin.test.ts +0 -158
- package/src/plugins/plugin-host/plugin.ts +0 -133
- package/src/plugins/plugin-intent/IntentPlugin.tsx +0 -75
- package/src/plugins/plugin-intent/meta.ts +0 -11
- package/src/plugins/plugin-intent/provides.ts +0 -26
- 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 -34
- package/src/plugins/plugin-surface/Surface.tsx +0 -62
- package/src/plugins/plugin-surface/SurfacePlugin.tsx +0 -45
- 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 -27
- /package/dist/types/src/{plugins/plugin-intent → plugin-intent}/intent-dispatcher.test.d.ts +0 -0
- /package/dist/types/src/{plugins/plugin-surface → react}/ErrorBoundary.d.ts +0 -0
- /package/src/{plugins/plugin-surface → react}/ErrorBoundary.tsx +0 -0
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2023 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import React, { type JSX, type FC, type PropsWithChildren, type ReactNode, useEffect, useState } from 'react';
|
|
6
|
-
|
|
7
|
-
import { log } from '@dxos/log';
|
|
8
|
-
|
|
9
|
-
import { type HostPluginParams } from './HostPlugin';
|
|
10
|
-
import { type PluginContext } from './PluginContext';
|
|
11
|
-
import { type Plugin, type PluginDefinition, type PluginProvides } from './plugin';
|
|
12
|
-
|
|
13
|
-
export type PluginContainerProps = Pick<HostPluginParams, 'core'> & {
|
|
14
|
-
plugins: Record<string, () => Promise<PluginDefinition>>;
|
|
15
|
-
state: PluginContext;
|
|
16
|
-
placeholder: ReactNode;
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Root component initializes plugins.
|
|
21
|
-
*/
|
|
22
|
-
export const PluginContainer = ({ plugins: definitions, core, state, placeholder }: PluginContainerProps) => {
|
|
23
|
-
const [error, setError] = useState<unknown>();
|
|
24
|
-
|
|
25
|
-
useEffect(() => {
|
|
26
|
-
log('initializing plugins', { enabled: state.enabled });
|
|
27
|
-
const t = setTimeout(async () => {
|
|
28
|
-
try {
|
|
29
|
-
const enabledIds = [...core, ...state.enabled];
|
|
30
|
-
const enabled = await Promise.all(
|
|
31
|
-
enabledIds
|
|
32
|
-
.map((id) => definitions[id])
|
|
33
|
-
// If local storage indicates a plugin is enabled, but it is not available, ignore it.
|
|
34
|
-
.filter((definition): definition is () => Promise<PluginDefinition> => Boolean(definition))
|
|
35
|
-
.map((definition) => definition()),
|
|
36
|
-
);
|
|
37
|
-
|
|
38
|
-
const plugins = await Promise.all(
|
|
39
|
-
enabled.map(async (definition) => {
|
|
40
|
-
const plugin = await initializePlugin(definition).catch((err) => {
|
|
41
|
-
log.error('Failed to initialize plugin:', { id: definition.meta.id, err });
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
log('initialized', { plugin: definition.meta.id });
|
|
45
|
-
return plugin;
|
|
46
|
-
}),
|
|
47
|
-
);
|
|
48
|
-
|
|
49
|
-
const initialized = plugins.filter((plugin): plugin is Plugin => Boolean(plugin));
|
|
50
|
-
log('plugins initialized', { plugins: initialized });
|
|
51
|
-
|
|
52
|
-
await Promise.all(enabled.map((plugin) => plugin.ready?.({ plugins: initialized })));
|
|
53
|
-
log('plugins ready', { plugins: initialized });
|
|
54
|
-
|
|
55
|
-
state.plugins = initialized;
|
|
56
|
-
state.ready = true;
|
|
57
|
-
} catch (err) {
|
|
58
|
-
setError(err);
|
|
59
|
-
}
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
return () => {
|
|
63
|
-
clearTimeout(t);
|
|
64
|
-
state.ready = false;
|
|
65
|
-
// TODO(wittjosiah): Does this ever need to be called prior to having dynamic plugins?
|
|
66
|
-
// void Promise.all(enabled.map((definition) => definition.unload?.()));
|
|
67
|
-
};
|
|
68
|
-
}, []);
|
|
69
|
-
|
|
70
|
-
if (error) {
|
|
71
|
-
throw error;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
if (!state.ready) {
|
|
75
|
-
return <>{placeholder}</>;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
const ComposedContext = composeContext(state.plugins);
|
|
79
|
-
|
|
80
|
-
return <ComposedContext>{rootComponents(state.plugins)}</ComposedContext>;
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* Resolve a `PluginDefinition` into a fully initialized `Plugin`.
|
|
85
|
-
*/
|
|
86
|
-
const initializePlugin = async <T, U>(pluginDefinition: PluginDefinition<T, U>): Promise<Plugin<T & U>> => {
|
|
87
|
-
const provides = await pluginDefinition.initialize?.();
|
|
88
|
-
return {
|
|
89
|
-
...pluginDefinition,
|
|
90
|
-
provides: {
|
|
91
|
-
...pluginDefinition.provides,
|
|
92
|
-
...provides,
|
|
93
|
-
} as PluginProvides<T & U>,
|
|
94
|
-
};
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
const rootComponents = (plugins: Plugin[]) => {
|
|
98
|
-
return plugins
|
|
99
|
-
.map((plugin) => {
|
|
100
|
-
const Component = plugin.provides.root;
|
|
101
|
-
if (Component) {
|
|
102
|
-
return <Component key={plugin.meta.id} />;
|
|
103
|
-
} else {
|
|
104
|
-
return null;
|
|
105
|
-
}
|
|
106
|
-
})
|
|
107
|
-
.filter((node): node is JSX.Element => Boolean(node));
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
const composeContext = (plugins: Plugin[]) => {
|
|
111
|
-
return compose(plugins.map((p) => p.provides.context!).filter(Boolean));
|
|
112
|
-
};
|
|
113
|
-
|
|
114
|
-
const compose = (contexts: FC<PropsWithChildren>[]) => {
|
|
115
|
-
return [...contexts].reduce((Acc, Next) => ({ children }) => (
|
|
116
|
-
<Acc>
|
|
117
|
-
<Next>{children}</Next>
|
|
118
|
-
</Acc>
|
|
119
|
-
));
|
|
120
|
-
};
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2024 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import { createContext, useContext, useMemo } from 'react';
|
|
6
|
-
|
|
7
|
-
import { raise } from '@dxos/debug';
|
|
8
|
-
import { nonNullable } from '@dxos/util';
|
|
9
|
-
|
|
10
|
-
import { type Plugin, type PluginMeta } from './plugin';
|
|
11
|
-
import { findPlugin, resolvePlugin } from '../helpers';
|
|
12
|
-
|
|
13
|
-
export type PluginContext = {
|
|
14
|
-
/**
|
|
15
|
-
* All plugins are ready.
|
|
16
|
-
*/
|
|
17
|
-
ready: boolean;
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Core plugins.
|
|
21
|
-
*/
|
|
22
|
-
core: string[];
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Ids of plugins which are enabled on this device.
|
|
26
|
-
*/
|
|
27
|
-
enabled: string[];
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Initialized and ready plugins.
|
|
31
|
-
*/
|
|
32
|
-
plugins: Plugin[];
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* All available plugins.
|
|
36
|
-
* NOTE: This is metadata rather than just ids because it includes plugins which have not been fully loaded yet.
|
|
37
|
-
*/
|
|
38
|
-
available: PluginMeta[];
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Mark plugin as enabled.
|
|
42
|
-
* Requires reload to take effect.
|
|
43
|
-
*/
|
|
44
|
-
// TODO(burdon): Functions should not be part of the settings type.
|
|
45
|
-
setPlugin: (id: string, enabled: boolean) => void;
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
const PluginContext = createContext<PluginContext | undefined>(undefined);
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Get all plugins.
|
|
52
|
-
*/
|
|
53
|
-
export const usePlugins = (): PluginContext => useContext(PluginContext) ?? raise(new Error('Missing PluginContext'));
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Get a plugin by ID.
|
|
57
|
-
*/
|
|
58
|
-
export const usePlugin = <T,>(id: string): Plugin<T> | undefined => {
|
|
59
|
-
const { plugins } = usePlugins();
|
|
60
|
-
return findPlugin<T>(plugins, id);
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* Resolve a plugin by predicate.
|
|
65
|
-
*/
|
|
66
|
-
export const useResolvePlugin = <T,>(predicate: (plugin: Plugin) => Plugin<T> | undefined): Plugin<T> | undefined => {
|
|
67
|
-
const { plugins } = usePlugins();
|
|
68
|
-
return resolvePlugin(plugins, predicate);
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Resolve a collection of plugins by predicate.
|
|
73
|
-
*/
|
|
74
|
-
export const useResolvePlugins = <T,>(predicate: (plugin: Plugin) => Plugin<T> | undefined): Plugin<T>[] => {
|
|
75
|
-
const { plugins } = usePlugins();
|
|
76
|
-
return useMemo(() => plugins.map(predicate).filter(nonNullable), [plugins, predicate]);
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
export const PluginProvider = PluginContext.Provider;
|
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2023 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import { type FC } from 'react';
|
|
6
|
-
import { describe, expect, test } from 'vitest';
|
|
7
|
-
|
|
8
|
-
import { log } from '@dxos/log';
|
|
9
|
-
|
|
10
|
-
import { type Plugin } from './plugin';
|
|
11
|
-
|
|
12
|
-
// eslint-disable-next-line unused-imports/no-unused-vars
|
|
13
|
-
export interface Interface<T> {
|
|
14
|
-
key: string;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
type InterfaceDef<T> = {
|
|
18
|
-
key: Interface<T>;
|
|
19
|
-
impl: T;
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
export const provide = <T>(key: Interface<T>, impl: T): InterfaceDef<T> => ({ key, impl });
|
|
23
|
-
|
|
24
|
-
export type PluginProps = {
|
|
25
|
-
provides?: InterfaceDef<any>[];
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
export class TestPlugin {
|
|
29
|
-
readonly _interfaces = new Map<string, any>();
|
|
30
|
-
constructor({ provides }: PluginProps) {
|
|
31
|
-
provides?.forEach(({ key, impl }) => this._interfaces.set(key.key, impl));
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
getInterface = <T>(key: Interface<T>): T | undefined => this._interfaces.get(key.key);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
const getInterfaces = <T>(plugins: TestPlugin[], key: Interface<T>): T[] =>
|
|
38
|
-
plugins.map((plugin) => plugin.getInterface(key)).filter(Boolean) as any;
|
|
39
|
-
|
|
40
|
-
//
|
|
41
|
-
// Interfaces allow shared typesafe contracts between plugins.
|
|
42
|
-
// The system might define common contracts (e.g., Printable); others would be defined by individual plugins.
|
|
43
|
-
// This allows parts of the system to find interfaces across all plugins to enable loosely coupled actions
|
|
44
|
-
// (separate from broadcast events) or requests for information.
|
|
45
|
-
//
|
|
46
|
-
|
|
47
|
-
export interface Printable {
|
|
48
|
-
print: (data: any | undefined) => void;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
export const Printable: Interface<Printable> = { key: 'printable' };
|
|
52
|
-
|
|
53
|
-
export interface Selectable {
|
|
54
|
-
selection: () => string | undefined;
|
|
55
|
-
select: (object?: { id: string | undefined }) => void;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export const Selectable: Interface<Selectable> = { key: 'selectable' };
|
|
59
|
-
|
|
60
|
-
// NOTE: Would allow Stack to define a contract for plugins that have embeddable content.
|
|
61
|
-
export type Section = FC<{ object: any; onSelect: (object: string | undefined) => void }>;
|
|
62
|
-
|
|
63
|
-
export const Section: Interface<Section> = { key: 'list' };
|
|
64
|
-
|
|
65
|
-
//
|
|
66
|
-
// Plugin defs
|
|
67
|
-
//
|
|
68
|
-
|
|
69
|
-
// TODO(burdon): Tie to declarative manifest.
|
|
70
|
-
// {
|
|
71
|
-
// Printable: { print: (data: any) => console.log(data) }
|
|
72
|
-
// }
|
|
73
|
-
//
|
|
74
|
-
|
|
75
|
-
const plugin1 = new TestPlugin({
|
|
76
|
-
provides: [
|
|
77
|
-
provide(Printable, {
|
|
78
|
-
print: (data: any | undefined) => log(data),
|
|
79
|
-
}),
|
|
80
|
-
|
|
81
|
-
provide(Selectable, {
|
|
82
|
-
selection: () => undefined,
|
|
83
|
-
select: (data: any) => {}, // TODO(burdon): Update plugin state.
|
|
84
|
-
}),
|
|
85
|
-
|
|
86
|
-
// provide(Section, ({ object }) => <div>{JSON.stringify(object)}</div>),
|
|
87
|
-
],
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
const plugin2 = new TestPlugin({
|
|
91
|
-
provides: [
|
|
92
|
-
provide(Printable, {
|
|
93
|
-
print: (data: any) => log(data),
|
|
94
|
-
}),
|
|
95
|
-
],
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
const plugin3 = new TestPlugin({});
|
|
99
|
-
|
|
100
|
-
describe('Plugins', () => {
|
|
101
|
-
const plugins = [plugin1, plugin2, plugin3];
|
|
102
|
-
|
|
103
|
-
test('invocation', () => {
|
|
104
|
-
// Invoke against all plugins that provide interface.
|
|
105
|
-
expect(getInterfaces(plugins, Printable)).to.have.length(2);
|
|
106
|
-
getInterfaces(plugins, Printable).forEach((i) => i.print({}));
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
test('symbols', () => {
|
|
110
|
-
const s1 = Symbol.for('s1');
|
|
111
|
-
const s2 = Symbol.for('s1');
|
|
112
|
-
expect(s1).to.be.eq(s2);
|
|
113
|
-
|
|
114
|
-
const map = new Map();
|
|
115
|
-
map.set(s1, true);
|
|
116
|
-
map.set(s2, false);
|
|
117
|
-
expect(map.get(s1)).to.be.false;
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
test('filter', () => {
|
|
121
|
-
type Provides1 = {
|
|
122
|
-
test1: {};
|
|
123
|
-
};
|
|
124
|
-
|
|
125
|
-
type Provides2 = {
|
|
126
|
-
test2: {};
|
|
127
|
-
};
|
|
128
|
-
|
|
129
|
-
const p1: Plugin<Provides1> = {
|
|
130
|
-
meta: { id: 'example.com/plugin/plugin-1' },
|
|
131
|
-
provides: {
|
|
132
|
-
test1: {},
|
|
133
|
-
},
|
|
134
|
-
};
|
|
135
|
-
|
|
136
|
-
const p2: Plugin<Provides2> = {
|
|
137
|
-
meta: { id: 'example.com/plugin/plugin-2' },
|
|
138
|
-
provides: {
|
|
139
|
-
test2: {},
|
|
140
|
-
},
|
|
141
|
-
};
|
|
142
|
-
|
|
143
|
-
const plugins: Plugin[] = [p1, p2];
|
|
144
|
-
|
|
145
|
-
const matching = plugins.filter((plugin) => true);
|
|
146
|
-
expect(matching).to.have.length(2);
|
|
147
|
-
});
|
|
148
|
-
});
|
|
149
|
-
|
|
150
|
-
// eslint-disable-next-line unused-imports/no-unused-vars
|
|
151
|
-
// const StackContainer: FC<{}> = () => {
|
|
152
|
-
// const StackSection = plugin1.getInterface(Section)!;
|
|
153
|
-
// const selected = plugin1.getInterface(Selectable)?.selection();
|
|
154
|
-
|
|
155
|
-
// return (
|
|
156
|
-
// <StackSection object={selected} onSelect={(object) => plugin1.getInterface(Selectable)?.select({ id: object })} />
|
|
157
|
-
// );
|
|
158
|
-
// };
|
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2023 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import type { FC, PropsWithChildren } from 'react';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Application context to be provided to plugin callbacks.
|
|
9
|
-
*/
|
|
10
|
-
export type HostContext = {
|
|
11
|
-
plugins: Plugin[];
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Capabilities provided by a plugin.
|
|
16
|
-
* The base surface capabilities are always included.
|
|
17
|
-
*/
|
|
18
|
-
export type PluginProvides<TProvides> = TProvides & {
|
|
19
|
-
/**
|
|
20
|
-
* React Context which is wrapped around the application to enable any hooks the plugin may provide.
|
|
21
|
-
*/
|
|
22
|
-
context?: FC<PropsWithChildren>;
|
|
23
|
-
|
|
24
|
-
/*
|
|
25
|
-
* React component which is rendered at the root of the application.
|
|
26
|
-
*/
|
|
27
|
-
root?: FC<PropsWithChildren>;
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
export type PluginMeta = {
|
|
31
|
-
/**
|
|
32
|
-
* Globally unique ID.
|
|
33
|
-
*
|
|
34
|
-
* Expected to be in the form of a valid URL.
|
|
35
|
-
*
|
|
36
|
-
* @example dxos.org/plugin/example
|
|
37
|
-
*/
|
|
38
|
-
id: string;
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Short ID for use in URLs.
|
|
42
|
-
*
|
|
43
|
-
* NOTE: This is especially experimental and likely to change.
|
|
44
|
-
*/
|
|
45
|
-
// TODO(wittjosiah): How should these be managed?
|
|
46
|
-
shortId?: string;
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Human-readable name.
|
|
50
|
-
*/
|
|
51
|
-
name?: string;
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Short description of plugin functionality.
|
|
55
|
-
*/
|
|
56
|
-
description?: string;
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* URL of home page.
|
|
60
|
-
*/
|
|
61
|
-
homePage?: string;
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* URL of source code.
|
|
65
|
-
*/
|
|
66
|
-
source?: string;
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Tags to help categorize the plugin.
|
|
70
|
-
*/
|
|
71
|
-
tags?: string[];
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* A grep-able symbol string which can be resolved to an icon asset by @ch-ui/icons, via @ch-ui/vite-plugin-icons.
|
|
75
|
-
*/
|
|
76
|
-
icon?: string;
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* A unit of containment of modular functionality that can be provided to an application.
|
|
81
|
-
* Plugins provide things like components, state, actions, etc. to the application.
|
|
82
|
-
*/
|
|
83
|
-
export type Plugin<TProvides = {}> = {
|
|
84
|
-
meta: PluginMeta;
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* Capabilities provided by the plugin.
|
|
88
|
-
*/
|
|
89
|
-
provides: PluginProvides<TProvides>;
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* Plugin definitions extend the base `Plugin` interface with additional lifecycle methods.
|
|
94
|
-
*/
|
|
95
|
-
export type PluginDefinition<TProvides = {}, TInitializeProvides = {}> = Omit<Plugin, 'provides'> & {
|
|
96
|
-
/**
|
|
97
|
-
* Capabilities provided by the plugin.
|
|
98
|
-
*/
|
|
99
|
-
provides?: Plugin<TProvides>['provides'];
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* Initialize any async behavior required by the plugin.
|
|
103
|
-
*
|
|
104
|
-
* @return Capabilities provided by the plugin which are merged with base capabilities.
|
|
105
|
-
*/
|
|
106
|
-
initialize?: () => Promise<PluginProvides<TInitializeProvides> | void>;
|
|
107
|
-
|
|
108
|
-
/**
|
|
109
|
-
* Called once all plugins have been initialized.
|
|
110
|
-
* This is the place to do any initialization which requires other plugins to be ready.
|
|
111
|
-
*
|
|
112
|
-
* @param plugins All plugins which successfully initialized.
|
|
113
|
-
*/
|
|
114
|
-
// TODO(wittjosiah): Rename `ready` to a verb?
|
|
115
|
-
ready?: (context: HostContext) => Promise<void>;
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* Called when the plugin is unloaded.
|
|
119
|
-
* This is the place to do any cleanup required by the plugin.
|
|
120
|
-
*/
|
|
121
|
-
unload?: () => Promise<void>;
|
|
122
|
-
};
|
|
123
|
-
|
|
124
|
-
type LazyPlugin<T> = () => Promise<{ default: (props: T) => PluginDefinition }>;
|
|
125
|
-
|
|
126
|
-
export namespace Plugin {
|
|
127
|
-
export const lazy = <T>(p: LazyPlugin<T>, props?: T) => {
|
|
128
|
-
return () =>
|
|
129
|
-
p().then(({ default: definition }) => {
|
|
130
|
-
return definition(props as T);
|
|
131
|
-
});
|
|
132
|
-
};
|
|
133
|
-
}
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2023 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import { Effect } from 'effect';
|
|
6
|
-
import React from 'react';
|
|
7
|
-
|
|
8
|
-
import { create } from '@dxos/live-object';
|
|
9
|
-
|
|
10
|
-
import { IntentProvider } from './IntentContext';
|
|
11
|
-
import { createDispatcher, type AnyIntentResolver, type IntentContext } from './intent-dispatcher';
|
|
12
|
-
import IntentMeta from './meta';
|
|
13
|
-
import { type IntentPluginProvides, type ResolverDefinitions, parseIntentResolverPlugin } from './provides';
|
|
14
|
-
import { filterPlugins } from '../helpers';
|
|
15
|
-
import { type PluginDefinition } from '../plugin-host';
|
|
16
|
-
|
|
17
|
-
const defaultEffect = () => Effect.fail(new Error('Intent runtime not ready'));
|
|
18
|
-
const defaultPromise = () => Effect.runPromise(defaultEffect());
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Allows plugins to register intent handlers and routes sent intents to the appropriate plugin.
|
|
22
|
-
* Inspired by https://developer.android.com/reference/android/content/Intent.
|
|
23
|
-
*/
|
|
24
|
-
export const IntentPlugin = (): PluginDefinition<IntentPluginProvides> => {
|
|
25
|
-
const state = create<IntentContext>({
|
|
26
|
-
dispatch: defaultEffect,
|
|
27
|
-
dispatchPromise: defaultPromise,
|
|
28
|
-
undo: defaultEffect,
|
|
29
|
-
undoPromise: defaultPromise,
|
|
30
|
-
registerResolver: () => () => {},
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
return {
|
|
34
|
-
meta: IntentMeta,
|
|
35
|
-
ready: async ({ plugins }) => {
|
|
36
|
-
const resolvers = Object.fromEntries(
|
|
37
|
-
filterPlugins(plugins, parseIntentResolverPlugin).map((plugin): [string, AnyIntentResolver[]] => {
|
|
38
|
-
const resolvers = reduceResolvers(
|
|
39
|
-
plugin.provides.intent.resolvers({
|
|
40
|
-
plugins,
|
|
41
|
-
dispatch: (intent) => state.dispatch(intent),
|
|
42
|
-
dispatchPromise: (intent) => state.dispatchPromise(intent),
|
|
43
|
-
undo: () => state.undo(),
|
|
44
|
-
undoPromise: () => state.undoPromise(),
|
|
45
|
-
registerResolver: (id, resolver) => state.registerResolver(id, resolver),
|
|
46
|
-
}),
|
|
47
|
-
);
|
|
48
|
-
return [plugin.meta.id, resolvers];
|
|
49
|
-
}),
|
|
50
|
-
);
|
|
51
|
-
const { dispatch, dispatchPromise, undo, undoPromise, registerResolver } = createDispatcher(resolvers);
|
|
52
|
-
|
|
53
|
-
state.dispatch = dispatch;
|
|
54
|
-
state.dispatchPromise = dispatchPromise;
|
|
55
|
-
state.undo = undo;
|
|
56
|
-
state.undoPromise = undoPromise;
|
|
57
|
-
state.registerResolver = registerResolver;
|
|
58
|
-
},
|
|
59
|
-
provides: {
|
|
60
|
-
intent: state,
|
|
61
|
-
context: ({ children }) => <IntentProvider value={state}>{children}</IntentProvider>,
|
|
62
|
-
},
|
|
63
|
-
};
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
const reduceResolvers = (
|
|
67
|
-
definitions: ResolverDefinitions,
|
|
68
|
-
resolvers: AnyIntentResolver[] = [],
|
|
69
|
-
): AnyIntentResolver[] => {
|
|
70
|
-
if (Array.isArray(definitions)) {
|
|
71
|
-
return definitions.reduce((acc: AnyIntentResolver[], definition) => reduceResolvers(definition, acc), resolvers);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
return [...resolvers, definitions];
|
|
75
|
-
};
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2023 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import { type IntentContext, type AnyIntentResolver } from './intent-dispatcher';
|
|
6
|
-
import { type HostContext, type Plugin } from '../plugin-host';
|
|
7
|
-
|
|
8
|
-
type Context = HostContext & IntentContext;
|
|
9
|
-
|
|
10
|
-
export type ResolverDefinitions = AnyIntentResolver | AnyIntentResolver[] | ResolverDefinitions[];
|
|
11
|
-
|
|
12
|
-
export type IntentResolverProvides = {
|
|
13
|
-
intent: {
|
|
14
|
-
resolvers: (context: Context) => ResolverDefinitions;
|
|
15
|
-
};
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
export type IntentPluginProvides = {
|
|
19
|
-
intent: IntentContext;
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
export const parseIntentPlugin = (plugin: Plugin) =>
|
|
23
|
-
(plugin.provides as any).intent?.dispatch ? (plugin as Plugin<IntentPluginProvides>) : undefined;
|
|
24
|
-
|
|
25
|
-
export const parseIntentResolverPlugin = (plugin: Plugin) =>
|
|
26
|
-
(plugin.provides as any).intent?.resolvers ? (plugin as Plugin<IntentResolverProvides>) : undefined;
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2024 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import { RootSettingsStore } from '@dxos/local-storage';
|
|
6
|
-
|
|
7
|
-
import SettingsMeta from './meta';
|
|
8
|
-
import { type SettingsPluginProvides } from './provides';
|
|
9
|
-
import { type PluginDefinition } from '../plugin-host';
|
|
10
|
-
|
|
11
|
-
export const SettingsPlugin = (): PluginDefinition<SettingsPluginProvides> => {
|
|
12
|
-
// Global settings singleton.
|
|
13
|
-
// TODO(burdon): Make settings storage extensible so that other plugins can decide the persistence of them.
|
|
14
|
-
const settingsStore = new RootSettingsStore();
|
|
15
|
-
|
|
16
|
-
return {
|
|
17
|
-
meta: SettingsMeta,
|
|
18
|
-
provides: {
|
|
19
|
-
settingsStore,
|
|
20
|
-
},
|
|
21
|
-
};
|
|
22
|
-
};
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2023 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import { S } from '@dxos/echo-schema';
|
|
6
|
-
import { type SettingsStoreFactory, type SettingsValue } from '@dxos/local-storage';
|
|
7
|
-
|
|
8
|
-
import { type Plugin } from '../plugin-host';
|
|
9
|
-
|
|
10
|
-
export type SettingsProvides<T extends SettingsValue> = {
|
|
11
|
-
settings: T;
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
export type SettingsPluginProvides = {
|
|
15
|
-
settingsStore: SettingsStoreFactory;
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
export const parseSettingsPlugin = (plugin: Plugin) => {
|
|
19
|
-
return typeof (plugin.provides as any).settingsStore === 'object'
|
|
20
|
-
? (plugin as Plugin<SettingsPluginProvides>)
|
|
21
|
-
: undefined;
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
export const SETTINGS_PLUGIN = 'dxos.org/plugin/settings';
|
|
25
|
-
export const SETTINGS_ACTION = `${SETTINGS_PLUGIN}/action`;
|
|
26
|
-
|
|
27
|
-
export namespace SettingsAction {
|
|
28
|
-
export class Open extends S.TaggedClass<Open>()(`${SETTINGS_ACTION}/open`, {
|
|
29
|
-
input: S.Struct({
|
|
30
|
-
plugin: S.optional(S.String),
|
|
31
|
-
}),
|
|
32
|
-
output: S.Void,
|
|
33
|
-
}) {}
|
|
34
|
-
}
|