@dxos/app-framework 0.3.7-main.8c7953e → 0.3.7-main.cdda206
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-C2K6M6WC.mjs +27 -0
- package/dist/lib/browser/chunk-C2K6M6WC.mjs.map +7 -0
- package/dist/lib/browser/chunk-CFZ5JAJF.mjs +18 -0
- package/dist/lib/browser/chunk-CFZ5JAJF.mjs.map +7 -0
- package/dist/lib/browser/chunk-WDA7VA54.mjs +26 -0
- package/dist/lib/browser/chunk-WDA7VA54.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +139 -188
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/plugin-CBPJO5NB.mjs +63 -0
- package/dist/lib/browser/plugin-CBPJO5NB.mjs.map +7 -0
- package/dist/lib/browser/plugin-XEJ5RYCP.mjs +39 -0
- package/dist/lib/browser/plugin-XEJ5RYCP.mjs.map +7 -0
- package/dist/lib/node/index.cjs +331 -186
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/types/src/App.d.ts +13 -3
- package/dist/types/src/App.d.ts.map +1 -1
- package/dist/types/src/plugins/IntentPlugin/index.d.ts +1 -1
- package/dist/types/src/plugins/IntentPlugin/index.d.ts.map +1 -1
- package/dist/types/src/plugins/IntentPlugin/meta.d.ts +5 -0
- package/dist/types/src/plugins/IntentPlugin/meta.d.ts.map +1 -0
- package/dist/types/src/plugins/IntentPlugin/plugin.d.ts +9 -0
- package/dist/types/src/plugins/IntentPlugin/plugin.d.ts.map +1 -0
- package/dist/types/src/plugins/IntentPlugin/{IntentPlugin.d.ts → provides.d.ts} +2 -7
- package/dist/types/src/plugins/IntentPlugin/provides.d.ts.map +1 -0
- package/dist/types/src/plugins/PluginHost/PluginContext.d.ts +27 -3
- package/dist/types/src/plugins/PluginHost/PluginContext.d.ts.map +1 -1
- package/dist/types/src/plugins/PluginHost/PluginHost.d.ts +7 -4
- package/dist/types/src/plugins/PluginHost/PluginHost.d.ts.map +1 -1
- package/dist/types/src/plugins/PluginHost/plugin.d.ts +49 -1
- package/dist/types/src/plugins/PluginHost/plugin.d.ts.map +1 -1
- package/dist/types/src/plugins/SurfacePlugin/Surface.d.ts +9 -4
- package/dist/types/src/plugins/SurfacePlugin/Surface.d.ts.map +1 -1
- package/dist/types/src/plugins/SurfacePlugin/SurfaceRootContext.d.ts +8 -2
- package/dist/types/src/plugins/SurfacePlugin/SurfaceRootContext.d.ts.map +1 -1
- package/dist/types/src/plugins/SurfacePlugin/index.d.ts +1 -1
- package/dist/types/src/plugins/SurfacePlugin/index.d.ts.map +1 -1
- package/dist/types/src/plugins/SurfacePlugin/meta.d.ts +5 -0
- package/dist/types/src/plugins/SurfacePlugin/meta.d.ts.map +1 -0
- package/dist/types/src/plugins/SurfacePlugin/plugin.d.ts +8 -0
- package/dist/types/src/plugins/SurfacePlugin/plugin.d.ts.map +1 -0
- package/dist/types/src/plugins/SurfacePlugin/{SurfacePlugin.d.ts → provides.d.ts} +2 -6
- package/dist/types/src/plugins/SurfacePlugin/provides.d.ts.map +1 -0
- package/package.json +8 -6
- package/src/App.tsx +24 -6
- package/src/plugins/IntentPlugin/index.ts +2 -1
- package/src/plugins/IntentPlugin/meta.ts +9 -0
- package/src/plugins/IntentPlugin/{IntentPlugin.tsx → plugin.tsx} +8 -22
- package/src/plugins/IntentPlugin/provides.ts +23 -0
- package/src/plugins/PluginHost/PluginContext.tsx +36 -5
- package/src/plugins/PluginHost/PluginHost.tsx +58 -98
- package/src/plugins/PluginHost/plugin.ts +31 -1
- package/src/plugins/SurfacePlugin/Surface.tsx +34 -27
- package/src/plugins/SurfacePlugin/SurfaceRootContext.tsx +11 -2
- package/src/plugins/SurfacePlugin/index.ts +2 -1
- package/src/plugins/SurfacePlugin/meta.ts +9 -0
- package/src/plugins/SurfacePlugin/plugin.tsx +36 -0
- package/src/plugins/SurfacePlugin/provides.ts +25 -0
- package/tsconfig.json +3 -0
- package/dist/types/src/plugins/IntentPlugin/IntentPlugin.d.ts.map +0 -1
- package/dist/types/src/plugins/SurfacePlugin/SurfacePlugin.d.ts.map +0 -1
- package/src/plugins/SurfacePlugin/SurfacePlugin.tsx +0 -53
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// packages/sdk/app-framework/src/plugins/IntentPlugin/provides.ts
|
|
2
|
+
var parseIntentPlugin = (plugin) => plugin.provides.intent?.dispatch ? plugin : void 0;
|
|
3
|
+
var parseIntentResolverPlugin = (plugin) => plugin.provides.intent?.resolver ? plugin : void 0;
|
|
4
|
+
|
|
5
|
+
// packages/sdk/app-framework/src/plugins/IntentPlugin/IntentContext.tsx
|
|
6
|
+
import { createContext, useContext } from "react";
|
|
7
|
+
var IntentContext = /* @__PURE__ */ createContext({
|
|
8
|
+
dispatch: async () => {
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
var useIntent = () => useContext(IntentContext);
|
|
12
|
+
var IntentProvider = IntentContext.Provider;
|
|
13
|
+
|
|
14
|
+
// packages/sdk/app-framework/src/plugins/IntentPlugin/meta.ts
|
|
15
|
+
var IntentMeta = {
|
|
16
|
+
id: "dxos.org/plugin/intent"
|
|
17
|
+
};
|
|
18
|
+
var meta_default = IntentMeta;
|
|
19
|
+
|
|
20
|
+
export {
|
|
21
|
+
parseIntentPlugin,
|
|
22
|
+
parseIntentResolverPlugin,
|
|
23
|
+
useIntent,
|
|
24
|
+
IntentProvider,
|
|
25
|
+
meta_default
|
|
26
|
+
};
|
|
27
|
+
//# sourceMappingURL=chunk-C2K6M6WC.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/plugins/IntentPlugin/provides.ts", "../../../src/plugins/IntentPlugin/IntentContext.tsx", "../../../src/plugins/IntentPlugin/meta.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { type IntentContext } from './IntentContext';\nimport { type Intent } from './intent';\nimport { type Plugin } from '../PluginHost';\n\nexport type IntentResolverProvides = {\n intent: {\n resolver: (intent: Intent, plugins: Plugin[]) => any;\n };\n};\n\nexport type IntentPluginProvides = {\n intent: IntentContext;\n};\n\nexport const parseIntentPlugin = (plugin: Plugin) =>\n (plugin.provides as any).intent?.dispatch ? (plugin as Plugin<IntentPluginProvides>) : undefined;\n\nexport const parseIntentResolverPlugin = (plugin: Plugin) =>\n (plugin.provides as any).intent?.resolver ? (plugin as Plugin<IntentResolverProvides>) : undefined;\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { type Context, createContext, useContext, type Provider } from 'react';\n\nimport { type DispatchIntent } from './intent';\n\nexport type IntentContext = {\n dispatch: DispatchIntent;\n};\n\nconst IntentContext: Context<IntentContext> = createContext<IntentContext>({ dispatch: async () => {} });\n\nexport const useIntent = () => useContext(IntentContext);\n\nexport const IntentProvider: Provider<IntentContext> = IntentContext.Provider;\n", "//\n// Copyright 2023 DXOS.org\n//\n\nconst IntentMeta = {\n id: 'dxos.org/plugin/intent',\n};\n\nexport default IntentMeta;\n"],
|
|
5
|
+
"mappings": ";AAkBO,IAAMA,oBAAoB,CAACC,WAC/BA,OAAOC,SAAiBC,QAAQC,WAAYH,SAA0CI;AAElF,IAAMC,4BAA4B,CAACL,WACvCA,OAAOC,SAAiBC,QAAQI,WAAYN,SAA4CI;;;AClB3F,SAAuBG,eAAeC,kBAAiC;AAQvE,IAAMC,gBAAwCC,8BAA6B;EAAEC,UAAU,YAAA;EAAa;AAAE,CAAA;AAE/F,IAAMC,YAAY,MAAMC,WAAWJ,aAAAA;AAEnC,IAAMK,iBAA0CL,cAAcM;;;ACZrE,IAAMC,aAAa;EACjBC,IAAI;AACN;AAEA,IAAA,eAAeD;",
|
|
6
|
+
"names": ["parseIntentPlugin", "plugin", "provides", "intent", "dispatch", "undefined", "parseIntentResolverPlugin", "resolver", "createContext", "useContext", "IntentContext", "createContext", "dispatch", "useIntent", "useContext", "IntentProvider", "Provider", "IntentMeta", "id"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// packages/sdk/app-framework/src/plugins/helpers.ts
|
|
2
|
+
import { raise } from "@dxos/debug";
|
|
3
|
+
var findPlugin = (plugins, id) => {
|
|
4
|
+
return plugins.find((plugin) => plugin.meta.id === id || typeof plugin.meta.shortId === "string" && plugin.meta.shortId === id);
|
|
5
|
+
};
|
|
6
|
+
var getPlugin = (plugins, id) => {
|
|
7
|
+
return findPlugin(plugins, id) ?? raise(new Error(`Plugin not found: ${id}`));
|
|
8
|
+
};
|
|
9
|
+
var filterPlugins = (plugins, predicate) => plugins.map((plugin) => predicate(plugin)).filter((plugin) => !!plugin);
|
|
10
|
+
var resolvePlugin = (plugins, predicate) => filterPlugins(plugins, predicate)[0];
|
|
11
|
+
|
|
12
|
+
export {
|
|
13
|
+
findPlugin,
|
|
14
|
+
getPlugin,
|
|
15
|
+
filterPlugins,
|
|
16
|
+
resolvePlugin
|
|
17
|
+
};
|
|
18
|
+
//# sourceMappingURL=chunk-CFZ5JAJF.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/plugins/helpers.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { raise } from '@dxos/debug';\n\nimport { type Plugin } from './PluginHost';\n\n/**\n * Find a plugin by ID.\n */\nexport const findPlugin = <T>(plugins: Plugin[], id: string): Plugin<T> | undefined => {\n return plugins.find(\n (plugin) => plugin.meta.id === id || (typeof plugin.meta.shortId === 'string' && plugin.meta.shortId === id),\n ) as Plugin<T>;\n};\n\n/**\n * Find a plugin by ID, or raise an error if not found.\n */\nexport const getPlugin = <T>(plugins: Plugin[], id: string): Plugin<T> => {\n return findPlugin(plugins, id) ?? raise(new Error(`Plugin not found: ${id}`));\n};\n\n/**\n * Filter a list of plugins to only those that match a predicate.\n */\nexport const filterPlugins = <T>(\n plugins: Plugin[],\n predicate: (plugin: Plugin) => Plugin<T> | undefined,\n): Plugin<T>[] => plugins.map((plugin) => predicate(plugin)).filter((plugin): plugin is Plugin<T> => !!plugin);\n\n/**\n * Resolves a plugin by predicate.\n *\n * @example\n * import { parseIntentPlugin, resolvePlugin } from '@dxos/app-framework';\n * const intentPlugin = resolvePlugin(plugins, parseIntentPlugin);\n */\nexport const resolvePlugin = <T>(\n plugins: Plugin[],\n predicate: (plugin: Plugin) => Plugin<T> | undefined,\n): Plugin<T> | undefined => filterPlugins(plugins, predicate)[0];\n"],
|
|
5
|
+
"mappings": ";AAIA,SAASA,aAAa;AAOf,IAAMC,aAAa,CAAIC,SAAmBC,OAAAA;AAC/C,SAAOD,QAAQE,KACb,CAACC,WAAWA,OAAOC,KAAKH,OAAOA,MAAO,OAAOE,OAAOC,KAAKC,YAAY,YAAYF,OAAOC,KAAKC,YAAYJ,EAAAA;AAE7G;AAKO,IAAMK,YAAY,CAAIN,SAAmBC,OAAAA;AAC9C,SAAOF,WAAWC,SAASC,EAAAA,KAAOM,MAAM,IAAIC,MAAM,qBAAqBP,EAAAA,EAAI,CAAA;AAC7E;AAKO,IAAMQ,gBAAgB,CAC3BT,SACAU,cACgBV,QAAQW,IAAI,CAACR,WAAWO,UAAUP,MAAAA,CAAAA,EAASS,OAAO,CAACT,WAAgC,CAAC,CAACA,MAAAA;AAShG,IAAMU,gBAAgB,CAC3Bb,SACAU,cAC0BD,cAAcT,SAASU,SAAAA,EAAW,CAAA;",
|
|
6
|
+
"names": ["raise", "findPlugin", "plugins", "id", "find", "plugin", "meta", "shortId", "getPlugin", "raise", "Error", "filterPlugins", "predicate", "map", "filter", "resolvePlugin"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// packages/sdk/app-framework/src/plugins/SurfacePlugin/provides.ts
|
|
2
|
+
var parseRootSurfacePlugin = (plugin) => plugin?.provides?.surface?.components ? plugin : void 0;
|
|
3
|
+
var parseSurfacePlugin = (plugin) => plugin?.provides?.surface?.component ? plugin : void 0;
|
|
4
|
+
|
|
5
|
+
// packages/sdk/app-framework/src/plugins/SurfacePlugin/SurfaceRootContext.tsx
|
|
6
|
+
import { createContext, useContext } from "react";
|
|
7
|
+
var SurfaceRootContext = /* @__PURE__ */ createContext({
|
|
8
|
+
components: {}
|
|
9
|
+
});
|
|
10
|
+
var useSurface = () => useContext(SurfaceRootContext);
|
|
11
|
+
var SurfaceProvider = SurfaceRootContext.Provider;
|
|
12
|
+
|
|
13
|
+
// packages/sdk/app-framework/src/plugins/SurfacePlugin/meta.ts
|
|
14
|
+
var SurfaceMeta = {
|
|
15
|
+
id: "dxos.org/plugin/surface"
|
|
16
|
+
};
|
|
17
|
+
var meta_default = SurfaceMeta;
|
|
18
|
+
|
|
19
|
+
export {
|
|
20
|
+
parseRootSurfacePlugin,
|
|
21
|
+
parseSurfacePlugin,
|
|
22
|
+
useSurface,
|
|
23
|
+
SurfaceProvider,
|
|
24
|
+
meta_default
|
|
25
|
+
};
|
|
26
|
+
//# sourceMappingURL=chunk-WDA7VA54.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/plugins/SurfacePlugin/provides.ts", "../../../src/plugins/SurfacePlugin/SurfaceRootContext.tsx", "../../../src/plugins/SurfacePlugin/meta.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { type SurfaceComponent, type SurfaceRootContext } from './SurfaceRootContext';\nimport { type Plugin } from '../PluginHost';\n\nexport type SurfaceProvides = {\n surface: {\n /**\n * Used by the `Surface` resolver to find a component to render.\n */\n component: SurfaceComponent;\n };\n};\n\nexport type SurfacePluginProvides = {\n surface: SurfaceRootContext;\n};\n\nexport const parseRootSurfacePlugin = (plugin?: Plugin) =>\n (plugin?.provides as any)?.surface?.components ? (plugin as Plugin<SurfacePluginProvides>) : undefined;\n\nexport const parseSurfacePlugin = (plugin?: Plugin) =>\n (plugin?.provides as any)?.surface?.component ? (plugin as Plugin<SurfaceProvides>) : undefined;\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { createContext, useContext, type Context, type Provider, type ReactNode, type ForwardedRef } from 'react';\n\nimport { type SurfaceProps } from './Surface';\n\n// TODO(wittjosiah): Factor out.\ntype WithRequiredProperty<Type, Key extends keyof Type> = Type & {\n [Property in Key]-?: Type[Property];\n};\n\ntype SurfaceComponentProps = WithRequiredProperty<SurfaceProps, 'data'>;\n\n/**\n * Function which resolves a Surface.\n *\n * If a null value is returned, the rendering is deferred to other plugins.\n */\nexport type SurfaceComponent = (props: SurfaceComponentProps, forwardedRef: ForwardedRef<HTMLElement>) => ReactNode;\n\nexport type SurfaceRootContext = {\n components: Record<string, SurfaceComponent>;\n};\n\nconst SurfaceRootContext: Context<SurfaceRootContext> = createContext<SurfaceRootContext>({ components: {} });\n\nexport const useSurface = () => useContext(SurfaceRootContext);\n\nexport const SurfaceProvider: Provider<SurfaceRootContext> = SurfaceRootContext.Provider;\n", "//\n// Copyright 2023 DXOS.org\n//\n\nconst SurfaceMeta = {\n id: 'dxos.org/plugin/surface',\n};\n\nexport default SurfaceMeta;\n"],
|
|
5
|
+
"mappings": ";AAoBO,IAAMA,yBAAyB,CAACC,WACpCA,QAAQC,UAAkBC,SAASC,aAAcH,SAA2CI;AAExF,IAAMC,qBAAqB,CAACL,WAChCA,QAAQC,UAAkBC,SAASI,YAAaN,SAAqCI;;;ACpBxF,SAASG,eAAeC,kBAAkF;AAsB1G,IAAMC,qBAAkDC,8BAAkC;EAAEC,YAAY,CAAC;AAAE,CAAA;AAEpG,IAAMC,aAAa,MAAMC,WAAWJ,kBAAAA;AAEpC,IAAMK,kBAAgDL,mBAAmBM;;;AC1BhF,IAAMC,cAAc;EAClBC,IAAI;AACN;AAEA,IAAA,eAAeD;",
|
|
6
|
+
"names": ["parseRootSurfacePlugin", "plugin", "provides", "surface", "components", "undefined", "parseSurfacePlugin", "component", "createContext", "useContext", "SurfaceRootContext", "createContext", "components", "useSurface", "useContext", "SurfaceProvider", "Provider", "SurfaceMeta", "id"]
|
|
7
|
+
}
|
|
@@ -1,3 +1,24 @@
|
|
|
1
|
+
import {
|
|
2
|
+
SurfaceProvider,
|
|
3
|
+
meta_default as meta_default2,
|
|
4
|
+
parseRootSurfacePlugin,
|
|
5
|
+
parseSurfacePlugin,
|
|
6
|
+
useSurface
|
|
7
|
+
} from "./chunk-WDA7VA54.mjs";
|
|
8
|
+
import {
|
|
9
|
+
IntentProvider,
|
|
10
|
+
meta_default,
|
|
11
|
+
parseIntentPlugin,
|
|
12
|
+
parseIntentResolverPlugin,
|
|
13
|
+
useIntent
|
|
14
|
+
} from "./chunk-C2K6M6WC.mjs";
|
|
15
|
+
import {
|
|
16
|
+
filterPlugins,
|
|
17
|
+
findPlugin,
|
|
18
|
+
getPlugin,
|
|
19
|
+
resolvePlugin
|
|
20
|
+
} from "./chunk-CFZ5JAJF.mjs";
|
|
21
|
+
|
|
1
22
|
// packages/sdk/app-framework/src/plugins/common/graph.ts
|
|
2
23
|
var parseGraphPlugin = (plugin) => plugin.provides.graph?.root ? plugin : void 0;
|
|
3
24
|
var parseGraphBuilderPlugin = (plugin) => plugin.provides.graph?.builder ? plugin : void 0;
|
|
@@ -56,88 +77,30 @@ var parseTranslationsPlugin = (plugin) => {
|
|
|
56
77
|
return success ? plugin : void 0;
|
|
57
78
|
};
|
|
58
79
|
|
|
59
|
-
// packages/sdk/app-framework/src/plugins/
|
|
60
|
-
|
|
61
|
-
var
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
};
|
|
67
|
-
var filterPlugins = (plugins, predicate) => plugins.map((plugin) => predicate(plugin)).filter((plugin) => !!plugin);
|
|
68
|
-
var resolvePlugin = (plugins, predicate) => filterPlugins(plugins, predicate)[0];
|
|
69
|
-
|
|
70
|
-
// packages/sdk/app-framework/src/plugins/IntentPlugin/IntentContext.tsx
|
|
71
|
-
import { createContext, useContext } from "react";
|
|
72
|
-
var IntentContext = /* @__PURE__ */ createContext({
|
|
73
|
-
dispatch: async () => {
|
|
74
|
-
}
|
|
75
|
-
});
|
|
76
|
-
var useIntent = () => useContext(IntentContext);
|
|
77
|
-
var IntentProvider = IntentContext.Provider;
|
|
78
|
-
|
|
79
|
-
// packages/sdk/app-framework/src/plugins/IntentPlugin/IntentPlugin.tsx
|
|
80
|
-
import { deepSignal } from "deepsignal/react";
|
|
81
|
-
import React from "react";
|
|
82
|
-
var parseIntentPlugin = (plugin) => plugin.provides.intent?.dispatch ? plugin : void 0;
|
|
83
|
-
var parseIntentResolverPlugin = (plugin) => plugin.provides.intent?.resolver ? plugin : void 0;
|
|
84
|
-
var IntentPlugin = () => {
|
|
85
|
-
const state = deepSignal({
|
|
86
|
-
dispatch: async () => {
|
|
87
|
-
}
|
|
88
|
-
});
|
|
89
|
-
return {
|
|
90
|
-
meta: {
|
|
91
|
-
id: "dxos.org/plugin/intent"
|
|
92
|
-
},
|
|
93
|
-
ready: async (plugins) => {
|
|
94
|
-
const dispatch = async (intent) => {
|
|
95
|
-
if (intent.plugin) {
|
|
96
|
-
const plugin = findPlugin(plugins, intent.plugin);
|
|
97
|
-
return plugin?.provides.intent.resolver(intent, plugins);
|
|
98
|
-
}
|
|
99
|
-
for (const plugin of filterPlugins(plugins, parseIntentResolverPlugin)) {
|
|
100
|
-
const result = await plugin.provides.intent.resolver(intent, plugins);
|
|
101
|
-
if (result) {
|
|
102
|
-
return result;
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
};
|
|
106
|
-
state.dispatch = async (intentOrArray) => {
|
|
107
|
-
let result = null;
|
|
108
|
-
for (const intent of Array.isArray(intentOrArray) ? intentOrArray : [
|
|
109
|
-
intentOrArray
|
|
110
|
-
]) {
|
|
111
|
-
const data = intent.data ? {
|
|
112
|
-
...result,
|
|
113
|
-
...intent.data
|
|
114
|
-
} : result;
|
|
115
|
-
result = await dispatch({
|
|
116
|
-
...intent,
|
|
117
|
-
data
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
return result;
|
|
121
|
-
};
|
|
122
|
-
},
|
|
123
|
-
provides: {
|
|
124
|
-
intent: state,
|
|
125
|
-
context: ({ children }) => /* @__PURE__ */ React.createElement(IntentProvider, {
|
|
126
|
-
value: state
|
|
127
|
-
}, children)
|
|
128
|
-
}
|
|
80
|
+
// packages/sdk/app-framework/src/plugins/PluginHost/plugin.ts
|
|
81
|
+
var pluginMeta = (meta) => meta;
|
|
82
|
+
var Plugin;
|
|
83
|
+
(function(Plugin2) {
|
|
84
|
+
var lazy = Plugin2.lazy = (p, props) => {
|
|
85
|
+
return () => p().then(({ default: definition }) => {
|
|
86
|
+
return definition(props);
|
|
87
|
+
});
|
|
129
88
|
};
|
|
130
|
-
};
|
|
89
|
+
})(Plugin || (Plugin = {}));
|
|
131
90
|
|
|
132
91
|
// packages/sdk/app-framework/src/plugins/PluginHost/PluginContext.tsx
|
|
133
|
-
import { createContext
|
|
134
|
-
var PluginContext = /* @__PURE__ */
|
|
92
|
+
import { createContext, useContext } from "react";
|
|
93
|
+
var PluginContext = /* @__PURE__ */ createContext({
|
|
135
94
|
ready: false,
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
95
|
+
enabled: [],
|
|
96
|
+
plugins: [],
|
|
97
|
+
available: [],
|
|
98
|
+
enablePlugin: () => {
|
|
99
|
+
},
|
|
100
|
+
disablePlugin: () => {
|
|
101
|
+
}
|
|
139
102
|
});
|
|
140
|
-
var usePlugins = () =>
|
|
103
|
+
var usePlugins = () => useContext(PluginContext);
|
|
141
104
|
var usePlugin = (id) => {
|
|
142
105
|
const { plugins } = usePlugins();
|
|
143
106
|
return findPlugin(plugins, id);
|
|
@@ -149,90 +112,100 @@ var useResolvePlugin = (predicate) => {
|
|
|
149
112
|
var PluginProvider = PluginContext.Provider;
|
|
150
113
|
|
|
151
114
|
// packages/sdk/app-framework/src/plugins/PluginHost/PluginHost.tsx
|
|
152
|
-
import {
|
|
153
|
-
import
|
|
115
|
+
import { shallow } from "deepsignal/react";
|
|
116
|
+
import React, { useEffect } from "react";
|
|
117
|
+
import { LocalStorageStore } from "@dxos/local-storage";
|
|
154
118
|
import { log } from "@dxos/log";
|
|
155
119
|
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/sdk/app-framework/src/plugins/PluginHost/PluginHost.tsx";
|
|
156
120
|
var parsePluginHost = (plugin) => plugin.provides.plugins ? plugin : void 0;
|
|
157
|
-
var
|
|
158
|
-
|
|
121
|
+
var PLUGIN_HOST = "dxos.org/plugin/host";
|
|
122
|
+
var PluginHost = ({ order, plugins: definitions, core = order.map(({ id }) => id), defaults = [], fallback = null }) => {
|
|
123
|
+
const state = new LocalStorageStore(PLUGIN_HOST, {
|
|
159
124
|
ready: false,
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
125
|
+
enabled: [
|
|
126
|
+
...defaults
|
|
127
|
+
],
|
|
128
|
+
plugins: [],
|
|
129
|
+
available: order.filter(({ id }) => !core.includes(id)),
|
|
130
|
+
enablePlugin: (id) => {
|
|
131
|
+
state.values.enabled = [
|
|
132
|
+
...state.values.enabled,
|
|
133
|
+
id
|
|
134
|
+
];
|
|
135
|
+
},
|
|
136
|
+
disablePlugin: (id) => {
|
|
137
|
+
state.values.enabled = state.values.enabled.filter((enabled) => enabled !== id);
|
|
138
|
+
}
|
|
163
139
|
});
|
|
140
|
+
state.prop(state.values.$enabled, "enabled", LocalStorageStore.json);
|
|
164
141
|
return {
|
|
165
142
|
meta: {
|
|
166
|
-
id:
|
|
143
|
+
id: PLUGIN_HOST
|
|
167
144
|
},
|
|
168
145
|
provides: {
|
|
169
|
-
plugins: state,
|
|
170
|
-
context: ({ children }) => /* @__PURE__ */
|
|
171
|
-
value: state
|
|
146
|
+
plugins: state.values,
|
|
147
|
+
context: ({ children }) => /* @__PURE__ */ React.createElement(PluginProvider, {
|
|
148
|
+
value: state.values
|
|
172
149
|
}, children),
|
|
173
150
|
root: () => {
|
|
174
151
|
useEffect(() => {
|
|
175
152
|
log("initializing plugins", {
|
|
176
|
-
|
|
153
|
+
enabled: state.values.enabled
|
|
177
154
|
}, {
|
|
178
155
|
F: __dxlog_file,
|
|
179
|
-
L:
|
|
156
|
+
L: 65,
|
|
180
157
|
S: void 0,
|
|
181
158
|
C: (f, a) => f(...a)
|
|
182
159
|
});
|
|
183
160
|
const timeout = setTimeout(async () => {
|
|
184
|
-
|
|
185
|
-
|
|
161
|
+
const enabledIds = [
|
|
162
|
+
...core,
|
|
163
|
+
...state.values.enabled
|
|
164
|
+
].sort((a, b) => {
|
|
165
|
+
const indexA = order.findIndex(({ id }) => id === a);
|
|
166
|
+
const indexB = order.findIndex(({ id }) => id === b);
|
|
167
|
+
return indexA - indexB;
|
|
168
|
+
});
|
|
169
|
+
const enabled = await Promise.all(enabledIds.map((id) => definitions[id]).filter((definition) => Boolean(definition)).map((definition) => definition()));
|
|
170
|
+
const plugins = await Promise.all(enabled.map(async (definition) => {
|
|
186
171
|
const plugin = await initializePlugin(definition).catch((err) => {
|
|
187
172
|
console.error("Failed to initialize plugin:", definition.meta.id, err);
|
|
188
173
|
return void 0;
|
|
189
174
|
});
|
|
190
|
-
state.initializing = shallow(state.initializing.filter((plugin2) => plugin2 !== definition));
|
|
191
175
|
return plugin;
|
|
192
176
|
})).then((plugins2) => plugins2.filter((plugin) => Boolean(plugin)));
|
|
193
177
|
log("plugins initialized", {
|
|
194
178
|
plugins
|
|
195
179
|
}, {
|
|
196
180
|
F: __dxlog_file,
|
|
197
|
-
L:
|
|
181
|
+
L: 90,
|
|
198
182
|
S: void 0,
|
|
199
183
|
C: (f, a) => f(...a)
|
|
200
184
|
});
|
|
201
|
-
|
|
202
|
-
await Promise.all(definitions.map(async (pluginDefinition) => {
|
|
185
|
+
await Promise.all(enabled.map(async (pluginDefinition) => {
|
|
203
186
|
await pluginDefinition.ready?.(plugins);
|
|
204
|
-
state.loading = shallow(state.loading.filter((plugin) => plugin !== pluginDefinition));
|
|
205
187
|
}));
|
|
206
188
|
log("plugins ready", {
|
|
207
189
|
plugins
|
|
208
190
|
}, {
|
|
209
191
|
F: __dxlog_file,
|
|
210
|
-
L:
|
|
192
|
+
L: 97,
|
|
211
193
|
S: void 0,
|
|
212
194
|
C: (f, a) => f(...a)
|
|
213
195
|
});
|
|
214
|
-
state.plugins = shallow(plugins);
|
|
215
|
-
state.ready = true;
|
|
196
|
+
state.values.plugins = shallow(plugins);
|
|
197
|
+
state.values.ready = true;
|
|
216
198
|
});
|
|
217
199
|
return () => {
|
|
218
200
|
clearTimeout(timeout);
|
|
219
|
-
state.ready = false;
|
|
220
|
-
void Promise.all(definitions.map((definition) => definition.unload?.()));
|
|
201
|
+
state.values.ready = false;
|
|
221
202
|
};
|
|
222
203
|
}, []);
|
|
223
|
-
if (!state.ready) {
|
|
224
|
-
|
|
225
|
-
const FallbackComponent = fallback;
|
|
226
|
-
return /* @__PURE__ */ React2.createElement(FallbackComponent, {
|
|
227
|
-
initializing: state.initializing,
|
|
228
|
-
loading: state.loading,
|
|
229
|
-
plugins: state.plugins
|
|
230
|
-
});
|
|
231
|
-
}
|
|
232
|
-
return /* @__PURE__ */ React2.createElement(React2.Fragment, null, fallback ?? null);
|
|
204
|
+
if (!state.values.ready) {
|
|
205
|
+
return /* @__PURE__ */ React.createElement(React.Fragment, null, fallback);
|
|
233
206
|
}
|
|
234
|
-
const ComposedContext = composeContext(state.plugins);
|
|
235
|
-
return /* @__PURE__ */
|
|
207
|
+
const ComposedContext = composeContext(state.values.plugins);
|
|
208
|
+
return /* @__PURE__ */ React.createElement(ComposedContext, null, rootComponents(state.values.plugins));
|
|
236
209
|
}
|
|
237
210
|
}
|
|
238
211
|
};
|
|
@@ -251,7 +224,7 @@ var rootComponents = (plugins) => {
|
|
|
251
224
|
return plugins.map((plugin) => {
|
|
252
225
|
const Component2 = plugin.provides.root;
|
|
253
226
|
if (Component2) {
|
|
254
|
-
return /* @__PURE__ */
|
|
227
|
+
return /* @__PURE__ */ React.createElement(Component2, {
|
|
255
228
|
key: plugin.meta.id
|
|
256
229
|
});
|
|
257
230
|
} else {
|
|
@@ -265,11 +238,11 @@ var composeContext = (plugins) => {
|
|
|
265
238
|
var compose = (contexts) => {
|
|
266
239
|
return [
|
|
267
240
|
...contexts
|
|
268
|
-
].reduce((Acc, Next) => ({ children }) => /* @__PURE__ */
|
|
241
|
+
].reduce((Acc, Next) => ({ children }) => /* @__PURE__ */ React.createElement(Acc, null, /* @__PURE__ */ React.createElement(Next, null, children)));
|
|
269
242
|
};
|
|
270
243
|
|
|
271
244
|
// packages/sdk/app-framework/src/plugins/SurfacePlugin/ErrorBoundary.tsx
|
|
272
|
-
import
|
|
245
|
+
import React2, { Component } from "react";
|
|
273
246
|
var ErrorBoundary = class extends Component {
|
|
274
247
|
constructor(props) {
|
|
275
248
|
super(props);
|
|
@@ -289,7 +262,7 @@ var ErrorBoundary = class extends Component {
|
|
|
289
262
|
}
|
|
290
263
|
render() {
|
|
291
264
|
if (this.state.error) {
|
|
292
|
-
return /* @__PURE__ */
|
|
265
|
+
return /* @__PURE__ */ React2.createElement(this.props.fallback, {
|
|
293
266
|
error: this.state.error,
|
|
294
267
|
reset: this.resetError
|
|
295
268
|
});
|
|
@@ -304,37 +277,33 @@ var ErrorBoundary = class extends Component {
|
|
|
304
277
|
};
|
|
305
278
|
|
|
306
279
|
// packages/sdk/app-framework/src/plugins/SurfacePlugin/Surface.tsx
|
|
307
|
-
import
|
|
308
|
-
import { createContext as
|
|
309
|
-
|
|
310
|
-
// packages/sdk/app-framework/src/plugins/SurfacePlugin/SurfaceRootContext.tsx
|
|
311
|
-
import { createContext as createContext3, useContext as useContext3 } from "react";
|
|
312
|
-
var SurfaceRootContext = /* @__PURE__ */ createContext3({
|
|
313
|
-
components: {}
|
|
314
|
-
});
|
|
315
|
-
var useSurface = () => useContext3(SurfaceRootContext);
|
|
316
|
-
var SurfaceProvider = SurfaceRootContext.Provider;
|
|
317
|
-
|
|
318
|
-
// packages/sdk/app-framework/src/plugins/SurfacePlugin/Surface.tsx
|
|
319
|
-
var Surface = ({ role, name = role, fallback, ...rest }) => {
|
|
280
|
+
import React3, { forwardRef, Fragment } from "react";
|
|
281
|
+
import { createContext as createContext2, useContext as useContext2 } from "react";
|
|
282
|
+
var Surface = /* @__PURE__ */ forwardRef(({ role, name = role, fallback, ...rest }, forwardedRef) => {
|
|
320
283
|
const props = {
|
|
321
284
|
role,
|
|
322
285
|
name,
|
|
323
286
|
fallback,
|
|
324
287
|
...rest
|
|
325
288
|
};
|
|
326
|
-
const context =
|
|
289
|
+
const context = useContext2(SurfaceContext);
|
|
327
290
|
const data = props.data ?? (name && context?.surfaces?.[name]?.data || {});
|
|
328
|
-
return /* @__PURE__ */
|
|
291
|
+
return /* @__PURE__ */ React3.createElement(React3.Fragment, null, fallback ? /* @__PURE__ */ React3.createElement(ErrorBoundary, {
|
|
329
292
|
data,
|
|
330
293
|
fallback
|
|
331
|
-
}, /* @__PURE__ */
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
294
|
+
}, /* @__PURE__ */ React3.createElement(SurfaceResolver, {
|
|
295
|
+
...props,
|
|
296
|
+
ref: forwardedRef
|
|
297
|
+
})) : /* @__PURE__ */ React3.createElement(SurfaceResolver, {
|
|
298
|
+
...props,
|
|
299
|
+
ref: forwardedRef
|
|
300
|
+
}));
|
|
301
|
+
});
|
|
302
|
+
var SurfaceContext = /* @__PURE__ */ createContext2(null);
|
|
303
|
+
var SurfaceResolver = /* @__PURE__ */ forwardRef((props, forwardedRef) => {
|
|
335
304
|
const { components } = useSurface();
|
|
336
|
-
const parent =
|
|
337
|
-
const nodes = resolveNodes(components, props, parent);
|
|
305
|
+
const parent = useContext2(SurfaceContext);
|
|
306
|
+
const nodes = resolveNodes(components, props, parent, forwardedRef);
|
|
338
307
|
const currentContext = {
|
|
339
308
|
...props,
|
|
340
309
|
surfaces: {
|
|
@@ -342,71 +311,53 @@ var SurfaceResolver = (props) => {
|
|
|
342
311
|
...props.surfaces
|
|
343
312
|
}
|
|
344
313
|
};
|
|
345
|
-
return /* @__PURE__ */
|
|
314
|
+
return /* @__PURE__ */ React3.createElement(SurfaceContext.Provider, {
|
|
346
315
|
value: currentContext
|
|
347
|
-
}, nodes.length > 0 ? nodes : props.contentFallback ? /* @__PURE__ */
|
|
348
|
-
};
|
|
349
|
-
var resolveNodes = (components, props, context) => {
|
|
316
|
+
}, nodes.length > 0 ? nodes : props.contentFallback ? /* @__PURE__ */ React3.createElement(props.contentFallback, null) : null);
|
|
317
|
+
});
|
|
318
|
+
var resolveNodes = (components, props, context, forwardedRef) => {
|
|
350
319
|
const data = {
|
|
351
320
|
...props.name && context?.surfaces?.[props.name]?.data || {},
|
|
352
321
|
...props.data
|
|
353
322
|
};
|
|
354
323
|
const nodes = Object.entries(components).map(([key, component]) => {
|
|
355
|
-
const result = component(
|
|
356
|
-
|
|
324
|
+
const result = component({
|
|
325
|
+
...props,
|
|
326
|
+
data
|
|
327
|
+
}, forwardedRef);
|
|
328
|
+
return result ? /* @__PURE__ */ React3.createElement(Fragment, {
|
|
357
329
|
key
|
|
358
330
|
}, result) : void 0;
|
|
359
331
|
}).filter((Component2) => Boolean(Component2));
|
|
360
332
|
return props.limit ? nodes.slice(0, props.limit) : nodes;
|
|
361
333
|
};
|
|
362
|
-
var Wrapper = ({ children }) => /* @__PURE__ */ React4.createElement(React4.Fragment, null, children);
|
|
363
|
-
|
|
364
|
-
// packages/sdk/app-framework/src/plugins/SurfacePlugin/SurfacePlugin.tsx
|
|
365
|
-
import { deepSignal as deepSignal3, shallow as shallow2 } from "deepsignal/react";
|
|
366
|
-
import React5 from "react";
|
|
367
|
-
var parseRootSurfacePlugin = (plugin) => plugin?.provides?.surface?.components ? plugin : void 0;
|
|
368
|
-
var parseSurfacePlugin = (plugin) => plugin?.provides?.surface?.component ? plugin : void 0;
|
|
369
|
-
var SurfacePlugin = () => {
|
|
370
|
-
const state = deepSignal3({
|
|
371
|
-
components: {}
|
|
372
|
-
});
|
|
373
|
-
return {
|
|
374
|
-
meta: {
|
|
375
|
-
id: "dxos.org/plugin/surface"
|
|
376
|
-
},
|
|
377
|
-
ready: async (plugins) => {
|
|
378
|
-
state.components = shallow2(filterPlugins(plugins, parseSurfacePlugin).reduce((acc, plugin) => {
|
|
379
|
-
return {
|
|
380
|
-
...acc,
|
|
381
|
-
[plugin.meta.id]: plugin.provides.surface.component
|
|
382
|
-
};
|
|
383
|
-
}, {}));
|
|
384
|
-
},
|
|
385
|
-
provides: {
|
|
386
|
-
surface: state,
|
|
387
|
-
context: ({ children }) => /* @__PURE__ */ React5.createElement(SurfaceProvider, {
|
|
388
|
-
value: state
|
|
389
|
-
}, children)
|
|
390
|
-
}
|
|
391
|
-
};
|
|
392
|
-
};
|
|
393
334
|
|
|
394
335
|
// packages/sdk/app-framework/src/App.tsx
|
|
395
|
-
import
|
|
336
|
+
import React4 from "react";
|
|
396
337
|
import { invariant } from "@dxos/invariant";
|
|
397
338
|
var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/sdk/app-framework/src/App.tsx";
|
|
398
|
-
var createApp = ({ plugins,
|
|
339
|
+
var createApp = ({ order, plugins, core = [], ...params }) => {
|
|
399
340
|
const host = PluginHost({
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
...
|
|
341
|
+
order: [
|
|
342
|
+
meta_default2,
|
|
343
|
+
meta_default,
|
|
344
|
+
...order
|
|
404
345
|
],
|
|
405
|
-
|
|
346
|
+
plugins: {
|
|
347
|
+
...plugins,
|
|
348
|
+
[meta_default2.id]: Plugin.lazy(() => import("./plugin-XEJ5RYCP.mjs")),
|
|
349
|
+
[meta_default.id]: Plugin.lazy(() => import("./plugin-CBPJO5NB.mjs"))
|
|
350
|
+
},
|
|
351
|
+
core: [
|
|
352
|
+
meta_default2.id,
|
|
353
|
+
meta_default.id,
|
|
354
|
+
...core
|
|
355
|
+
],
|
|
356
|
+
...params
|
|
406
357
|
});
|
|
407
358
|
invariant(host.provides?.context, void 0, {
|
|
408
359
|
F: __dxlog_file2,
|
|
409
|
-
L:
|
|
360
|
+
L: 51,
|
|
410
361
|
S: void 0,
|
|
411
362
|
A: [
|
|
412
363
|
"host.provides?.context",
|
|
@@ -415,7 +366,7 @@ var createApp = ({ plugins, fallback }) => {
|
|
|
415
366
|
});
|
|
416
367
|
invariant(host.provides?.root, void 0, {
|
|
417
368
|
F: __dxlog_file2,
|
|
418
|
-
L:
|
|
369
|
+
L: 52,
|
|
419
370
|
S: void 0,
|
|
420
371
|
A: [
|
|
421
372
|
"host.provides?.root",
|
|
@@ -424,21 +375,20 @@ var createApp = ({ plugins, fallback }) => {
|
|
|
424
375
|
});
|
|
425
376
|
const Context = host.provides.context;
|
|
426
377
|
const Root = host.provides.root;
|
|
427
|
-
return () => /* @__PURE__ */
|
|
378
|
+
return () => /* @__PURE__ */ React4.createElement(Context, null, /* @__PURE__ */ React4.createElement(Root, null));
|
|
428
379
|
};
|
|
429
380
|
export {
|
|
430
381
|
ErrorBoundary,
|
|
431
|
-
IntentPlugin,
|
|
432
382
|
IntentProvider,
|
|
433
383
|
Layout,
|
|
434
384
|
LayoutAction,
|
|
385
|
+
Plugin,
|
|
435
386
|
PluginHost,
|
|
436
387
|
PluginProvider,
|
|
437
388
|
Resource,
|
|
438
389
|
ResourceKey,
|
|
439
390
|
ResourceLanguage,
|
|
440
391
|
Surface,
|
|
441
|
-
SurfacePlugin,
|
|
442
392
|
SurfaceProvider,
|
|
443
393
|
createApp,
|
|
444
394
|
filterPlugins,
|
|
@@ -456,6 +406,7 @@ export {
|
|
|
456
406
|
parseRootSurfacePlugin,
|
|
457
407
|
parseSurfacePlugin,
|
|
458
408
|
parseTranslationsPlugin,
|
|
409
|
+
pluginMeta,
|
|
459
410
|
resolvePlugin,
|
|
460
411
|
useIntent,
|
|
461
412
|
usePlugin,
|