@dxos/app-framework 0.3.7-main.8c7953e → 0.3.7-main.c3c2c7d
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 +140 -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 +332 -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 +59 -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,101 @@ 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 = [], 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,
|
|
144
|
+
name: "Plugin host"
|
|
167
145
|
},
|
|
168
146
|
provides: {
|
|
169
|
-
plugins: state,
|
|
170
|
-
context: ({ children }) => /* @__PURE__ */
|
|
171
|
-
value: state
|
|
147
|
+
plugins: state.values,
|
|
148
|
+
context: ({ children }) => /* @__PURE__ */ React.createElement(PluginProvider, {
|
|
149
|
+
value: state.values
|
|
172
150
|
}, children),
|
|
173
151
|
root: () => {
|
|
174
152
|
useEffect(() => {
|
|
175
153
|
log("initializing plugins", {
|
|
176
|
-
|
|
154
|
+
enabled: state.values.enabled
|
|
177
155
|
}, {
|
|
178
156
|
F: __dxlog_file,
|
|
179
|
-
L:
|
|
157
|
+
L: 66,
|
|
180
158
|
S: void 0,
|
|
181
159
|
C: (f, a) => f(...a)
|
|
182
160
|
});
|
|
183
161
|
const timeout = setTimeout(async () => {
|
|
184
|
-
|
|
185
|
-
|
|
162
|
+
const enabledIds = [
|
|
163
|
+
...core,
|
|
164
|
+
...state.values.enabled
|
|
165
|
+
].sort((a, b) => {
|
|
166
|
+
const indexA = order.findIndex(({ id }) => id === a);
|
|
167
|
+
const indexB = order.findIndex(({ id }) => id === b);
|
|
168
|
+
return indexA - indexB;
|
|
169
|
+
});
|
|
170
|
+
const enabled = await Promise.all(enabledIds.map((id) => definitions[id]).filter((definition) => Boolean(definition)).map((definition) => definition()));
|
|
171
|
+
const plugins = await Promise.all(enabled.map(async (definition) => {
|
|
186
172
|
const plugin = await initializePlugin(definition).catch((err) => {
|
|
187
173
|
console.error("Failed to initialize plugin:", definition.meta.id, err);
|
|
188
174
|
return void 0;
|
|
189
175
|
});
|
|
190
|
-
state.initializing = shallow(state.initializing.filter((plugin2) => plugin2 !== definition));
|
|
191
176
|
return plugin;
|
|
192
177
|
})).then((plugins2) => plugins2.filter((plugin) => Boolean(plugin)));
|
|
193
178
|
log("plugins initialized", {
|
|
194
179
|
plugins
|
|
195
180
|
}, {
|
|
196
181
|
F: __dxlog_file,
|
|
197
|
-
L:
|
|
182
|
+
L: 91,
|
|
198
183
|
S: void 0,
|
|
199
184
|
C: (f, a) => f(...a)
|
|
200
185
|
});
|
|
201
|
-
|
|
202
|
-
await Promise.all(definitions.map(async (pluginDefinition) => {
|
|
186
|
+
await Promise.all(enabled.map(async (pluginDefinition) => {
|
|
203
187
|
await pluginDefinition.ready?.(plugins);
|
|
204
|
-
state.loading = shallow(state.loading.filter((plugin) => plugin !== pluginDefinition));
|
|
205
188
|
}));
|
|
206
189
|
log("plugins ready", {
|
|
207
190
|
plugins
|
|
208
191
|
}, {
|
|
209
192
|
F: __dxlog_file,
|
|
210
|
-
L:
|
|
193
|
+
L: 98,
|
|
211
194
|
S: void 0,
|
|
212
195
|
C: (f, a) => f(...a)
|
|
213
196
|
});
|
|
214
|
-
state.plugins = shallow(plugins);
|
|
215
|
-
state.ready = true;
|
|
197
|
+
state.values.plugins = shallow(plugins);
|
|
198
|
+
state.values.ready = true;
|
|
216
199
|
});
|
|
217
200
|
return () => {
|
|
218
201
|
clearTimeout(timeout);
|
|
219
|
-
state.ready = false;
|
|
220
|
-
void Promise.all(definitions.map((definition) => definition.unload?.()));
|
|
202
|
+
state.values.ready = false;
|
|
221
203
|
};
|
|
222
204
|
}, []);
|
|
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);
|
|
205
|
+
if (!state.values.ready) {
|
|
206
|
+
return /* @__PURE__ */ React.createElement(React.Fragment, null, fallback);
|
|
233
207
|
}
|
|
234
|
-
const ComposedContext = composeContext(state.plugins);
|
|
235
|
-
return /* @__PURE__ */
|
|
208
|
+
const ComposedContext = composeContext(state.values.plugins);
|
|
209
|
+
return /* @__PURE__ */ React.createElement(ComposedContext, null, rootComponents(state.values.plugins));
|
|
236
210
|
}
|
|
237
211
|
}
|
|
238
212
|
};
|
|
@@ -251,7 +225,7 @@ var rootComponents = (plugins) => {
|
|
|
251
225
|
return plugins.map((plugin) => {
|
|
252
226
|
const Component2 = plugin.provides.root;
|
|
253
227
|
if (Component2) {
|
|
254
|
-
return /* @__PURE__ */
|
|
228
|
+
return /* @__PURE__ */ React.createElement(Component2, {
|
|
255
229
|
key: plugin.meta.id
|
|
256
230
|
});
|
|
257
231
|
} else {
|
|
@@ -265,11 +239,11 @@ var composeContext = (plugins) => {
|
|
|
265
239
|
var compose = (contexts) => {
|
|
266
240
|
return [
|
|
267
241
|
...contexts
|
|
268
|
-
].reduce((Acc, Next) => ({ children }) => /* @__PURE__ */
|
|
242
|
+
].reduce((Acc, Next) => ({ children }) => /* @__PURE__ */ React.createElement(Acc, null, /* @__PURE__ */ React.createElement(Next, null, children)));
|
|
269
243
|
};
|
|
270
244
|
|
|
271
245
|
// packages/sdk/app-framework/src/plugins/SurfacePlugin/ErrorBoundary.tsx
|
|
272
|
-
import
|
|
246
|
+
import React2, { Component } from "react";
|
|
273
247
|
var ErrorBoundary = class extends Component {
|
|
274
248
|
constructor(props) {
|
|
275
249
|
super(props);
|
|
@@ -289,7 +263,7 @@ var ErrorBoundary = class extends Component {
|
|
|
289
263
|
}
|
|
290
264
|
render() {
|
|
291
265
|
if (this.state.error) {
|
|
292
|
-
return /* @__PURE__ */
|
|
266
|
+
return /* @__PURE__ */ React2.createElement(this.props.fallback, {
|
|
293
267
|
error: this.state.error,
|
|
294
268
|
reset: this.resetError
|
|
295
269
|
});
|
|
@@ -304,37 +278,33 @@ var ErrorBoundary = class extends Component {
|
|
|
304
278
|
};
|
|
305
279
|
|
|
306
280
|
// 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 }) => {
|
|
281
|
+
import React3, { forwardRef, Fragment } from "react";
|
|
282
|
+
import { createContext as createContext2, useContext as useContext2 } from "react";
|
|
283
|
+
var Surface = /* @__PURE__ */ forwardRef(({ role, name = role, fallback, ...rest }, forwardedRef) => {
|
|
320
284
|
const props = {
|
|
321
285
|
role,
|
|
322
286
|
name,
|
|
323
287
|
fallback,
|
|
324
288
|
...rest
|
|
325
289
|
};
|
|
326
|
-
const context =
|
|
290
|
+
const context = useContext2(SurfaceContext);
|
|
327
291
|
const data = props.data ?? (name && context?.surfaces?.[name]?.data || {});
|
|
328
|
-
return /* @__PURE__ */
|
|
292
|
+
return /* @__PURE__ */ React3.createElement(React3.Fragment, null, fallback ? /* @__PURE__ */ React3.createElement(ErrorBoundary, {
|
|
329
293
|
data,
|
|
330
294
|
fallback
|
|
331
|
-
}, /* @__PURE__ */
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
295
|
+
}, /* @__PURE__ */ React3.createElement(SurfaceResolver, {
|
|
296
|
+
...props,
|
|
297
|
+
ref: forwardedRef
|
|
298
|
+
})) : /* @__PURE__ */ React3.createElement(SurfaceResolver, {
|
|
299
|
+
...props,
|
|
300
|
+
ref: forwardedRef
|
|
301
|
+
}));
|
|
302
|
+
});
|
|
303
|
+
var SurfaceContext = /* @__PURE__ */ createContext2(null);
|
|
304
|
+
var SurfaceResolver = /* @__PURE__ */ forwardRef((props, forwardedRef) => {
|
|
335
305
|
const { components } = useSurface();
|
|
336
|
-
const parent =
|
|
337
|
-
const nodes = resolveNodes(components, props, parent);
|
|
306
|
+
const parent = useContext2(SurfaceContext);
|
|
307
|
+
const nodes = resolveNodes(components, props, parent, forwardedRef);
|
|
338
308
|
const currentContext = {
|
|
339
309
|
...props,
|
|
340
310
|
surfaces: {
|
|
@@ -342,71 +312,53 @@ var SurfaceResolver = (props) => {
|
|
|
342
312
|
...props.surfaces
|
|
343
313
|
}
|
|
344
314
|
};
|
|
345
|
-
return /* @__PURE__ */
|
|
315
|
+
return /* @__PURE__ */ React3.createElement(SurfaceContext.Provider, {
|
|
346
316
|
value: currentContext
|
|
347
|
-
}, nodes.length > 0 ? nodes : props.contentFallback ? /* @__PURE__ */
|
|
348
|
-
};
|
|
349
|
-
var resolveNodes = (components, props, context) => {
|
|
317
|
+
}, nodes.length > 0 ? nodes : props.contentFallback ? /* @__PURE__ */ React3.createElement(props.contentFallback, null) : null);
|
|
318
|
+
});
|
|
319
|
+
var resolveNodes = (components, props, context, forwardedRef) => {
|
|
350
320
|
const data = {
|
|
351
321
|
...props.name && context?.surfaces?.[props.name]?.data || {},
|
|
352
322
|
...props.data
|
|
353
323
|
};
|
|
354
324
|
const nodes = Object.entries(components).map(([key, component]) => {
|
|
355
|
-
const result = component(
|
|
356
|
-
|
|
325
|
+
const result = component({
|
|
326
|
+
...props,
|
|
327
|
+
data
|
|
328
|
+
}, forwardedRef);
|
|
329
|
+
return result ? /* @__PURE__ */ React3.createElement(Fragment, {
|
|
357
330
|
key
|
|
358
331
|
}, result) : void 0;
|
|
359
332
|
}).filter((Component2) => Boolean(Component2));
|
|
360
333
|
return props.limit ? nodes.slice(0, props.limit) : nodes;
|
|
361
334
|
};
|
|
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
335
|
|
|
394
336
|
// packages/sdk/app-framework/src/App.tsx
|
|
395
|
-
import
|
|
337
|
+
import React4 from "react";
|
|
396
338
|
import { invariant } from "@dxos/invariant";
|
|
397
339
|
var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/sdk/app-framework/src/App.tsx";
|
|
398
|
-
var createApp = ({ plugins,
|
|
340
|
+
var createApp = ({ order, plugins, core = order.map(({ id }) => id), ...params }) => {
|
|
399
341
|
const host = PluginHost({
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
...
|
|
342
|
+
order: [
|
|
343
|
+
meta_default2,
|
|
344
|
+
meta_default,
|
|
345
|
+
...order
|
|
404
346
|
],
|
|
405
|
-
|
|
347
|
+
plugins: {
|
|
348
|
+
...plugins,
|
|
349
|
+
[meta_default2.id]: Plugin.lazy(() => import("./plugin-XEJ5RYCP.mjs")),
|
|
350
|
+
[meta_default.id]: Plugin.lazy(() => import("./plugin-CBPJO5NB.mjs"))
|
|
351
|
+
},
|
|
352
|
+
core: [
|
|
353
|
+
meta_default2.id,
|
|
354
|
+
meta_default.id,
|
|
355
|
+
...core
|
|
356
|
+
],
|
|
357
|
+
...params
|
|
406
358
|
});
|
|
407
359
|
invariant(host.provides?.context, void 0, {
|
|
408
360
|
F: __dxlog_file2,
|
|
409
|
-
L:
|
|
361
|
+
L: 51,
|
|
410
362
|
S: void 0,
|
|
411
363
|
A: [
|
|
412
364
|
"host.provides?.context",
|
|
@@ -415,7 +367,7 @@ var createApp = ({ plugins, fallback }) => {
|
|
|
415
367
|
});
|
|
416
368
|
invariant(host.provides?.root, void 0, {
|
|
417
369
|
F: __dxlog_file2,
|
|
418
|
-
L:
|
|
370
|
+
L: 52,
|
|
419
371
|
S: void 0,
|
|
420
372
|
A: [
|
|
421
373
|
"host.provides?.root",
|
|
@@ -424,21 +376,20 @@ var createApp = ({ plugins, fallback }) => {
|
|
|
424
376
|
});
|
|
425
377
|
const Context = host.provides.context;
|
|
426
378
|
const Root = host.provides.root;
|
|
427
|
-
return () => /* @__PURE__ */
|
|
379
|
+
return () => /* @__PURE__ */ React4.createElement(Context, null, /* @__PURE__ */ React4.createElement(Root, null));
|
|
428
380
|
};
|
|
429
381
|
export {
|
|
430
382
|
ErrorBoundary,
|
|
431
|
-
IntentPlugin,
|
|
432
383
|
IntentProvider,
|
|
433
384
|
Layout,
|
|
434
385
|
LayoutAction,
|
|
386
|
+
Plugin,
|
|
435
387
|
PluginHost,
|
|
436
388
|
PluginProvider,
|
|
437
389
|
Resource,
|
|
438
390
|
ResourceKey,
|
|
439
391
|
ResourceLanguage,
|
|
440
392
|
Surface,
|
|
441
|
-
SurfacePlugin,
|
|
442
393
|
SurfaceProvider,
|
|
443
394
|
createApp,
|
|
444
395
|
filterPlugins,
|
|
@@ -456,6 +407,7 @@ export {
|
|
|
456
407
|
parseRootSurfacePlugin,
|
|
457
408
|
parseSurfacePlugin,
|
|
458
409
|
parseTranslationsPlugin,
|
|
410
|
+
pluginMeta,
|
|
459
411
|
resolvePlugin,
|
|
460
412
|
useIntent,
|
|
461
413
|
usePlugin,
|