@dxos/app-framework 0.3.11-main.a6c4a82 → 0.3.11-main.a8c932f
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 → chunk-7MQ2DVDI.mjs} +19 -2
- package/dist/lib/browser/chunk-7MQ2DVDI.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +186 -148
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/plugin-PGPBA2JO.mjs +111 -0
- package/dist/lib/browser/plugin-PGPBA2JO.mjs.map +7 -0
- package/dist/lib/node/{chunk-BOQBLWMX.cjs → chunk-FETX4EGX.cjs} +26 -7
- package/dist/lib/node/chunk-FETX4EGX.cjs.map +7 -0
- package/dist/lib/node/index.cjs +183 -147
- package/dist/lib/node/index.cjs.map +3 -3
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/{plugin-WDNRX2SR.cjs → plugin-HLGHD6N5.cjs} +63 -14
- package/dist/lib/node/plugin-HLGHD6N5.cjs.map +7 -0
- package/dist/types/src/plugins/IntentPlugin/IntentContext.d.ts +10 -2
- package/dist/types/src/plugins/IntentPlugin/IntentContext.d.ts.map +1 -1
- package/dist/types/src/plugins/IntentPlugin/intent.d.ts +34 -1
- package/dist/types/src/plugins/IntentPlugin/intent.d.ts.map +1 -1
- package/dist/types/src/plugins/IntentPlugin/plugin.d.ts.map +1 -1
- package/dist/types/src/plugins/IntentPlugin/provides.d.ts +2 -2
- package/dist/types/src/plugins/IntentPlugin/provides.d.ts.map +1 -1
- package/dist/types/src/plugins/PluginHost/PluginHost.d.ts +4 -2
- package/dist/types/src/plugins/PluginHost/PluginHost.d.ts.map +1 -1
- package/dist/types/src/plugins/PluginHost/plugin.d.ts +1 -1
- package/dist/types/src/plugins/PluginHost/plugin.d.ts.map +1 -1
- package/dist/types/src/plugins/SurfacePlugin/Surface.d.ts +4 -5
- package/dist/types/src/plugins/SurfacePlugin/Surface.d.ts.map +1 -1
- package/dist/types/src/plugins/common/layout.d.ts +17 -15
- package/dist/types/src/plugins/common/layout.d.ts.map +1 -1
- package/package.json +8 -7
- package/project.json +3 -1
- package/src/plugins/IntentPlugin/IntentContext.tsx +27 -3
- package/src/plugins/IntentPlugin/intent.ts +41 -1
- package/src/plugins/IntentPlugin/plugin.tsx +60 -7
- package/src/plugins/IntentPlugin/provides.ts +2 -2
- package/src/plugins/PluginHost/PluginHost.tsx +92 -57
- package/src/plugins/PluginHost/plugin.ts +2 -1
- package/src/plugins/SurfacePlugin/Surface.tsx +15 -21
- package/src/plugins/common/layout.ts +16 -14
- package/src/vite-env.d.ts +5 -0
- package/tsconfig.json +3 -0
- package/dist/lib/browser/chunk-C2K6M6WC.mjs.map +0 -7
- package/dist/lib/browser/plugin-CBPJO5NB.mjs +0 -63
- package/dist/lib/browser/plugin-CBPJO5NB.mjs.map +0 -7
- package/dist/lib/node/chunk-BOQBLWMX.cjs.map +0 -7
- package/dist/lib/node/plugin-WDNRX2SR.cjs.map +0 -7
|
@@ -4,11 +4,26 @@ var parseIntentResolverPlugin = (plugin) => plugin.provides.intent?.resolver ? p
|
|
|
4
4
|
|
|
5
5
|
// packages/sdk/app-framework/src/plugins/IntentPlugin/IntentContext.tsx
|
|
6
6
|
import { createContext, useContext } from "react";
|
|
7
|
+
import { useEffect } from "react";
|
|
7
8
|
var IntentContext = /* @__PURE__ */ createContext({
|
|
8
|
-
dispatch: async () => {
|
|
9
|
+
dispatch: async () => ({}),
|
|
10
|
+
registerResolver: () => () => {
|
|
9
11
|
}
|
|
10
12
|
});
|
|
11
13
|
var useIntent = () => useContext(IntentContext);
|
|
14
|
+
var useIntentDispatcher = () => {
|
|
15
|
+
const { dispatch } = useIntent();
|
|
16
|
+
return dispatch;
|
|
17
|
+
};
|
|
18
|
+
var useIntentResolver = (plugin, resolver) => {
|
|
19
|
+
const { registerResolver } = useIntent();
|
|
20
|
+
useEffect(() => {
|
|
21
|
+
return registerResolver(plugin, resolver);
|
|
22
|
+
}, [
|
|
23
|
+
plugin,
|
|
24
|
+
resolver
|
|
25
|
+
]);
|
|
26
|
+
};
|
|
12
27
|
var IntentProvider = IntentContext.Provider;
|
|
13
28
|
|
|
14
29
|
// packages/sdk/app-framework/src/plugins/IntentPlugin/meta.ts
|
|
@@ -21,7 +36,9 @@ export {
|
|
|
21
36
|
parseIntentPlugin,
|
|
22
37
|
parseIntentResolverPlugin,
|
|
23
38
|
useIntent,
|
|
39
|
+
useIntentDispatcher,
|
|
40
|
+
useIntentResolver,
|
|
24
41
|
IntentProvider,
|
|
25
42
|
meta_default
|
|
26
43
|
};
|
|
27
|
-
//# sourceMappingURL=chunk-
|
|
44
|
+
//# sourceMappingURL=chunk-7MQ2DVDI.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 IntentResolver } from './intent';\nimport { type Plugin } from '../PluginHost';\n\nexport type IntentResolverProvides = {\n intent: {\n resolver: IntentResolver;\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';\nimport { useEffect } from 'react';\n\nimport { type UnsubscribeCallback } from '@dxos/async';\n\nimport { type IntentDispatcher, type IntentResolver } from './intent';\n\nexport type IntentContext = {\n dispatch: IntentDispatcher;\n registerResolver: (pluginId: string, resolver: IntentResolver) => UnsubscribeCallback;\n};\n\nconst IntentContext: Context<IntentContext> = createContext<IntentContext>({\n dispatch: async () => ({}),\n registerResolver: () => () => {},\n});\n\n/**\n * @deprecated\n * TODO(burdon): Use useIntentDispatcher.\n */\nexport const useIntent = () => useContext(IntentContext);\n\n// TODO(burdon): Dispatch or Dispatcher?\nexport const useIntentDispatcher = (): IntentDispatcher => {\n const { dispatch } = useIntent();\n return dispatch;\n};\n\nexport const useIntentResolver = (plugin: string, resolver: IntentResolver) => {\n const { registerResolver } = useIntent();\n useEffect(() => {\n return registerResolver(plugin, resolver);\n }, [plugin, resolver]);\n};\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;AACvE,SAASC,iBAAiB;AAW1B,IAAMC,gBAAwCC,8BAA6B;EACzEC,UAAU,aAAa,CAAC;EACxBC,kBAAkB,MAAM,MAAA;EAAO;AACjC,CAAA;AAMO,IAAMC,YAAY,MAAMC,WAAWL,aAAAA;AAGnC,IAAMM,sBAAsB,MAAA;AACjC,QAAM,EAAEJ,SAAQ,IAAKE,UAAAA;AACrB,SAAOF;AACT;AAEO,IAAMK,oBAAoB,CAACC,QAAgBC,aAAAA;AAChD,QAAM,EAAEN,iBAAgB,IAAKC,UAAAA;AAC7BM,YAAU,MAAA;AACR,WAAOP,iBAAiBK,QAAQC,QAAAA;EAClC,GAAG;IAACD;IAAQC;GAAS;AACvB;AAEO,IAAME,iBAA0CX,cAAcY;;;ACpCrE,IAAMC,aAAa;EACjBC,IAAI;AACN;AAEA,IAAA,eAAeD;",
|
|
6
|
+
"names": ["parseIntentPlugin", "plugin", "provides", "intent", "dispatch", "undefined", "parseIntentResolverPlugin", "resolver", "createContext", "useContext", "useEffect", "IntentContext", "createContext", "dispatch", "registerResolver", "useIntent", "useContext", "useIntentDispatcher", "useIntentResolver", "plugin", "resolver", "useEffect", "IntentProvider", "Provider", "IntentMeta", "id"]
|
|
7
|
+
}
|
|
@@ -10,8 +10,10 @@ import {
|
|
|
10
10
|
meta_default,
|
|
11
11
|
parseIntentPlugin,
|
|
12
12
|
parseIntentResolverPlugin,
|
|
13
|
-
useIntent
|
|
14
|
-
|
|
13
|
+
useIntent,
|
|
14
|
+
useIntentDispatcher,
|
|
15
|
+
useIntentResolver
|
|
16
|
+
} from "./chunk-7MQ2DVDI.mjs";
|
|
15
17
|
import {
|
|
16
18
|
filterPlugins,
|
|
17
19
|
findPlugin,
|
|
@@ -55,6 +57,7 @@ var LayoutAction;
|
|
|
55
57
|
LayoutAction2[LayoutAction2["OPEN_POPOVER"] = `${LAYOUT_ACTION}/open-popover`] = "OPEN_POPOVER";
|
|
56
58
|
LayoutAction2[LayoutAction2["CLOSE_POPOVER"] = `${LAYOUT_ACTION}/close-popover`] = "CLOSE_POPOVER";
|
|
57
59
|
LayoutAction2[LayoutAction2["ACTIVATE"] = `${LAYOUT_ACTION}/activate`] = "ACTIVATE";
|
|
60
|
+
LayoutAction2[LayoutAction2["FOCUS"] = `${LAYOUT_ACTION}/focus`] = "FOCUS";
|
|
58
61
|
})(LayoutAction || (LayoutAction = {}));
|
|
59
62
|
|
|
60
63
|
// packages/sdk/app-framework/src/plugins/common/metadata.ts
|
|
@@ -92,7 +95,7 @@ var parseTranslationsPlugin = (plugin) => {
|
|
|
92
95
|
var pluginMeta = (meta) => meta;
|
|
93
96
|
var Plugin;
|
|
94
97
|
(function(Plugin2) {
|
|
95
|
-
|
|
98
|
+
Plugin2.lazy = (p, props) => {
|
|
96
99
|
return () => p().then(({ default: definition }) => {
|
|
97
100
|
return definition(props);
|
|
98
101
|
});
|
|
@@ -122,141 +125,15 @@ var PluginProvider = PluginContext.Provider;
|
|
|
122
125
|
|
|
123
126
|
// packages/sdk/app-framework/src/plugins/PluginHost/PluginHost.tsx
|
|
124
127
|
import { shallow } from "deepsignal/react";
|
|
125
|
-
import
|
|
128
|
+
import React3, { useEffect, useState } from "react";
|
|
126
129
|
import { LocalStorageStore } from "@dxos/local-storage";
|
|
127
130
|
import { log } from "@dxos/log";
|
|
128
|
-
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/sdk/app-framework/src/plugins/PluginHost/PluginHost.tsx";
|
|
129
|
-
var parsePluginHost = (plugin) => plugin.provides.plugins ? plugin : void 0;
|
|
130
|
-
var PLUGIN_HOST = "dxos.org/plugin/host";
|
|
131
|
-
var PluginHost = ({ order, plugins: definitions, core = [], defaults = [], fallback = null }) => {
|
|
132
|
-
const state = new LocalStorageStore(PLUGIN_HOST, {
|
|
133
|
-
ready: false,
|
|
134
|
-
enabled: [
|
|
135
|
-
...defaults
|
|
136
|
-
],
|
|
137
|
-
plugins: [],
|
|
138
|
-
available: order.filter(({ id }) => !core.includes(id)),
|
|
139
|
-
setPlugin: (id, enabled) => {
|
|
140
|
-
if (enabled) {
|
|
141
|
-
state.values.enabled = [
|
|
142
|
-
...state.values.enabled,
|
|
143
|
-
id
|
|
144
|
-
];
|
|
145
|
-
} else {
|
|
146
|
-
state.values.enabled = state.values.enabled.filter((enabled2) => enabled2 !== id);
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
});
|
|
150
|
-
state.prop(state.values.$enabled, "enabled", LocalStorageStore.json);
|
|
151
|
-
return {
|
|
152
|
-
meta: {
|
|
153
|
-
id: PLUGIN_HOST,
|
|
154
|
-
name: "Plugin host"
|
|
155
|
-
},
|
|
156
|
-
provides: {
|
|
157
|
-
plugins: state.values,
|
|
158
|
-
context: ({ children }) => /* @__PURE__ */ React.createElement(PluginProvider, {
|
|
159
|
-
value: state.values
|
|
160
|
-
}, children),
|
|
161
|
-
root: () => {
|
|
162
|
-
useEffect(() => {
|
|
163
|
-
log("initializing plugins", {
|
|
164
|
-
enabled: state.values.enabled
|
|
165
|
-
}, {
|
|
166
|
-
F: __dxlog_file,
|
|
167
|
-
L: 67,
|
|
168
|
-
S: void 0,
|
|
169
|
-
C: (f, a) => f(...a)
|
|
170
|
-
});
|
|
171
|
-
const timeout = setTimeout(async () => {
|
|
172
|
-
const enabledIds = [
|
|
173
|
-
...core,
|
|
174
|
-
...state.values.enabled
|
|
175
|
-
].sort((a, b) => {
|
|
176
|
-
const indexA = order.findIndex(({ id }) => id === a);
|
|
177
|
-
const indexB = order.findIndex(({ id }) => id === b);
|
|
178
|
-
return indexA - indexB;
|
|
179
|
-
});
|
|
180
|
-
const enabled = await Promise.all(enabledIds.map((id) => definitions[id]).filter((definition) => Boolean(definition)).map((definition) => definition()));
|
|
181
|
-
const plugins = await Promise.all(enabled.map(async (definition) => {
|
|
182
|
-
const plugin = await initializePlugin(definition).catch((err) => {
|
|
183
|
-
console.error("Failed to initialize plugin:", definition.meta.id, err);
|
|
184
|
-
return void 0;
|
|
185
|
-
});
|
|
186
|
-
return plugin;
|
|
187
|
-
})).then((plugins2) => plugins2.filter((plugin) => Boolean(plugin)));
|
|
188
|
-
log("plugins initialized", {
|
|
189
|
-
plugins
|
|
190
|
-
}, {
|
|
191
|
-
F: __dxlog_file,
|
|
192
|
-
L: 92,
|
|
193
|
-
S: void 0,
|
|
194
|
-
C: (f, a) => f(...a)
|
|
195
|
-
});
|
|
196
|
-
await Promise.all(enabled.map(async (pluginDefinition) => {
|
|
197
|
-
await pluginDefinition.ready?.(plugins);
|
|
198
|
-
}));
|
|
199
|
-
log("plugins ready", {
|
|
200
|
-
plugins
|
|
201
|
-
}, {
|
|
202
|
-
F: __dxlog_file,
|
|
203
|
-
L: 99,
|
|
204
|
-
S: void 0,
|
|
205
|
-
C: (f, a) => f(...a)
|
|
206
|
-
});
|
|
207
|
-
state.values.plugins = shallow(plugins);
|
|
208
|
-
state.values.ready = true;
|
|
209
|
-
});
|
|
210
|
-
return () => {
|
|
211
|
-
clearTimeout(timeout);
|
|
212
|
-
state.values.ready = false;
|
|
213
|
-
};
|
|
214
|
-
}, []);
|
|
215
|
-
if (!state.values.ready) {
|
|
216
|
-
return /* @__PURE__ */ React.createElement(React.Fragment, null, fallback);
|
|
217
|
-
}
|
|
218
|
-
const ComposedContext = composeContext(state.values.plugins);
|
|
219
|
-
return /* @__PURE__ */ React.createElement(ComposedContext, null, rootComponents(state.values.plugins));
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
};
|
|
223
|
-
};
|
|
224
|
-
var initializePlugin = async (pluginDefinition) => {
|
|
225
|
-
const provides = await pluginDefinition.initialize?.();
|
|
226
|
-
return {
|
|
227
|
-
...pluginDefinition,
|
|
228
|
-
provides: {
|
|
229
|
-
...pluginDefinition.provides,
|
|
230
|
-
...provides
|
|
231
|
-
}
|
|
232
|
-
};
|
|
233
|
-
};
|
|
234
|
-
var rootComponents = (plugins) => {
|
|
235
|
-
return plugins.map((plugin) => {
|
|
236
|
-
const Component2 = plugin.provides.root;
|
|
237
|
-
if (Component2) {
|
|
238
|
-
return /* @__PURE__ */ React.createElement(Component2, {
|
|
239
|
-
key: plugin.meta.id
|
|
240
|
-
});
|
|
241
|
-
} else {
|
|
242
|
-
return null;
|
|
243
|
-
}
|
|
244
|
-
}).filter((node) => Boolean(node));
|
|
245
|
-
};
|
|
246
|
-
var composeContext = (plugins) => {
|
|
247
|
-
return compose(plugins.map((p) => p.provides.context).filter(Boolean));
|
|
248
|
-
};
|
|
249
|
-
var compose = (contexts) => {
|
|
250
|
-
return [
|
|
251
|
-
...contexts
|
|
252
|
-
].reduce((Acc, Next) => ({ children }) => /* @__PURE__ */ React.createElement(Acc, null, /* @__PURE__ */ React.createElement(Next, null, children)));
|
|
253
|
-
};
|
|
254
131
|
|
|
255
132
|
// packages/sdk/app-framework/src/plugins/SurfacePlugin/helpers.ts
|
|
256
133
|
var isObject = (data) => !!data && typeof data === "object";
|
|
257
134
|
|
|
258
135
|
// packages/sdk/app-framework/src/plugins/SurfacePlugin/ErrorBoundary.tsx
|
|
259
|
-
import
|
|
136
|
+
import React, { Component } from "react";
|
|
260
137
|
var ErrorBoundary = class extends Component {
|
|
261
138
|
constructor(props) {
|
|
262
139
|
super(props);
|
|
@@ -276,7 +153,7 @@ var ErrorBoundary = class extends Component {
|
|
|
276
153
|
}
|
|
277
154
|
render() {
|
|
278
155
|
if (this.state.error) {
|
|
279
|
-
return /* @__PURE__ */
|
|
156
|
+
return /* @__PURE__ */ React.createElement(this.props.fallback, {
|
|
280
157
|
error: this.state.error,
|
|
281
158
|
reset: this.resetError
|
|
282
159
|
});
|
|
@@ -291,9 +168,9 @@ var ErrorBoundary = class extends Component {
|
|
|
291
168
|
};
|
|
292
169
|
|
|
293
170
|
// packages/sdk/app-framework/src/plugins/SurfacePlugin/Surface.tsx
|
|
294
|
-
import
|
|
171
|
+
import React2, { forwardRef, Fragment, isValidElement, Suspense } from "react";
|
|
295
172
|
import { createContext as createContext2, useContext as useContext2 } from "react";
|
|
296
|
-
var Surface = /* @__PURE__ */ forwardRef(({ role, name = role, fallback, ...rest }, forwardedRef) => {
|
|
173
|
+
var Surface = /* @__PURE__ */ forwardRef(({ role, name = role, fallback, placeholder, ...rest }, forwardedRef) => {
|
|
297
174
|
const props = {
|
|
298
175
|
role,
|
|
299
176
|
name,
|
|
@@ -302,16 +179,17 @@ var Surface = /* @__PURE__ */ forwardRef(({ role, name = role, fallback, ...rest
|
|
|
302
179
|
};
|
|
303
180
|
const context = useContext2(SurfaceContext);
|
|
304
181
|
const data = props.data ?? (name && context?.surfaces?.[name]?.data || {});
|
|
305
|
-
|
|
306
|
-
data,
|
|
307
|
-
fallback
|
|
308
|
-
}, /* @__PURE__ */ React3.createElement(SurfaceResolver, {
|
|
182
|
+
const resolver = /* @__PURE__ */ React2.createElement(SurfaceResolver, {
|
|
309
183
|
...props,
|
|
310
184
|
ref: forwardedRef
|
|
311
|
-
})
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
})
|
|
185
|
+
});
|
|
186
|
+
const suspense = placeholder ? /* @__PURE__ */ React2.createElement(Suspense, {
|
|
187
|
+
fallback: placeholder
|
|
188
|
+
}, resolver) : resolver;
|
|
189
|
+
return fallback ? /* @__PURE__ */ React2.createElement(ErrorBoundary, {
|
|
190
|
+
data,
|
|
191
|
+
fallback
|
|
192
|
+
}, suspense) : suspense;
|
|
315
193
|
});
|
|
316
194
|
var SurfaceContext = /* @__PURE__ */ createContext2(null);
|
|
317
195
|
var SurfaceResolver = /* @__PURE__ */ forwardRef((props, forwardedRef) => {
|
|
@@ -325,9 +203,9 @@ var SurfaceResolver = /* @__PURE__ */ forwardRef((props, forwardedRef) => {
|
|
|
325
203
|
...props.surfaces
|
|
326
204
|
}
|
|
327
205
|
};
|
|
328
|
-
return /* @__PURE__ */
|
|
206
|
+
return /* @__PURE__ */ React2.createElement(SurfaceContext.Provider, {
|
|
329
207
|
value: currentContext
|
|
330
|
-
}, nodes
|
|
208
|
+
}, nodes);
|
|
331
209
|
});
|
|
332
210
|
var resolveNodes = (components, props, context, forwardedRef) => {
|
|
333
211
|
const data = {
|
|
@@ -362,12 +240,170 @@ var resolveNodes = (components, props, context, forwardedRef) => {
|
|
|
362
240
|
return 1;
|
|
363
241
|
}
|
|
364
242
|
return 0;
|
|
365
|
-
}).map(([key, result]) => /* @__PURE__ */
|
|
243
|
+
}).map(([key, result]) => /* @__PURE__ */ React2.createElement(Fragment, {
|
|
366
244
|
key
|
|
367
245
|
}, result.node));
|
|
368
246
|
return props.limit ? nodes.slice(0, props.limit) : nodes;
|
|
369
247
|
};
|
|
370
248
|
|
|
249
|
+
// packages/sdk/app-framework/src/plugins/PluginHost/PluginHost.tsx
|
|
250
|
+
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/sdk/app-framework/src/plugins/PluginHost/PluginHost.tsx";
|
|
251
|
+
var parsePluginHost = (plugin) => plugin.provides.plugins ? plugin : void 0;
|
|
252
|
+
var PLUGIN_HOST = "dxos.org/plugin/host";
|
|
253
|
+
var PluginHost = ({ order, plugins: definitions, core = [], defaults = [], fallback = DefaultFallback, placeholder = null }) => {
|
|
254
|
+
const state = new LocalStorageStore(PLUGIN_HOST, {
|
|
255
|
+
ready: false,
|
|
256
|
+
enabled: [
|
|
257
|
+
...defaults
|
|
258
|
+
],
|
|
259
|
+
plugins: [],
|
|
260
|
+
available: order.filter(({ id }) => !core.includes(id)),
|
|
261
|
+
setPlugin: (id, enabled) => {
|
|
262
|
+
if (enabled) {
|
|
263
|
+
state.values.enabled = [
|
|
264
|
+
...state.values.enabled,
|
|
265
|
+
id
|
|
266
|
+
];
|
|
267
|
+
} else {
|
|
268
|
+
state.values.enabled = state.values.enabled.filter((enabled2) => enabled2 !== id);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
});
|
|
272
|
+
state.prop(state.values.$enabled, "enabled", LocalStorageStore.json);
|
|
273
|
+
return {
|
|
274
|
+
meta: {
|
|
275
|
+
id: PLUGIN_HOST,
|
|
276
|
+
name: "Plugin host"
|
|
277
|
+
},
|
|
278
|
+
provides: {
|
|
279
|
+
plugins: state.values,
|
|
280
|
+
context: ({ children }) => /* @__PURE__ */ React3.createElement(PluginProvider, {
|
|
281
|
+
value: state.values
|
|
282
|
+
}, children),
|
|
283
|
+
root: () => {
|
|
284
|
+
return /* @__PURE__ */ React3.createElement(ErrorBoundary, {
|
|
285
|
+
fallback
|
|
286
|
+
}, /* @__PURE__ */ React3.createElement(Root, {
|
|
287
|
+
order,
|
|
288
|
+
core,
|
|
289
|
+
definitions,
|
|
290
|
+
state: state.values,
|
|
291
|
+
placeholder
|
|
292
|
+
}));
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
};
|
|
296
|
+
};
|
|
297
|
+
var DefaultFallback = ({ error }) => {
|
|
298
|
+
return /* @__PURE__ */ React3.createElement("div", {
|
|
299
|
+
style: {
|
|
300
|
+
padding: "1rem"
|
|
301
|
+
}
|
|
302
|
+
}, /* @__PURE__ */ React3.createElement("h1", {
|
|
303
|
+
style: {
|
|
304
|
+
fontSize: "1.2rem",
|
|
305
|
+
fontWeight: 700,
|
|
306
|
+
margin: "0.5rem 0"
|
|
307
|
+
}
|
|
308
|
+
}, error.message), /* @__PURE__ */ React3.createElement("pre", null, error.stack));
|
|
309
|
+
};
|
|
310
|
+
var Root = ({ order, core: corePluginIds, definitions, state, placeholder }) => {
|
|
311
|
+
const [error, setError] = useState();
|
|
312
|
+
useEffect(() => {
|
|
313
|
+
log("initializing plugins", {
|
|
314
|
+
enabled: state.enabled
|
|
315
|
+
}, {
|
|
316
|
+
F: __dxlog_file,
|
|
317
|
+
L: 101,
|
|
318
|
+
S: void 0,
|
|
319
|
+
C: (f, a) => f(...a)
|
|
320
|
+
});
|
|
321
|
+
const timeout = setTimeout(async () => {
|
|
322
|
+
try {
|
|
323
|
+
const enabledIds = [
|
|
324
|
+
...corePluginIds,
|
|
325
|
+
...state.enabled
|
|
326
|
+
].sort((a, b) => {
|
|
327
|
+
const indexA = order.findIndex(({ id }) => id === a);
|
|
328
|
+
const indexB = order.findIndex(({ id }) => id === b);
|
|
329
|
+
return indexA - indexB;
|
|
330
|
+
});
|
|
331
|
+
const enabled = await Promise.all(enabledIds.map((id) => definitions[id]).filter((definition) => Boolean(definition)).map((definition) => definition()));
|
|
332
|
+
const plugins = await Promise.all(enabled.map(async (definition) => {
|
|
333
|
+
const plugin = await initializePlugin(definition).catch((err) => {
|
|
334
|
+
console.error("Failed to initialize plugin:", definition.meta.id, err);
|
|
335
|
+
return void 0;
|
|
336
|
+
});
|
|
337
|
+
return plugin;
|
|
338
|
+
})).then((plugins2) => plugins2.filter((plugin) => Boolean(plugin)));
|
|
339
|
+
log("plugins initialized", {
|
|
340
|
+
plugins
|
|
341
|
+
}, {
|
|
342
|
+
F: __dxlog_file,
|
|
343
|
+
L: 127,
|
|
344
|
+
S: void 0,
|
|
345
|
+
C: (f, a) => f(...a)
|
|
346
|
+
});
|
|
347
|
+
await Promise.all(enabled.map((pluginDefinition) => pluginDefinition.ready?.(plugins)));
|
|
348
|
+
log("plugins ready", {
|
|
349
|
+
plugins
|
|
350
|
+
}, {
|
|
351
|
+
F: __dxlog_file,
|
|
352
|
+
L: 130,
|
|
353
|
+
S: void 0,
|
|
354
|
+
C: (f, a) => f(...a)
|
|
355
|
+
});
|
|
356
|
+
state.plugins = shallow(plugins);
|
|
357
|
+
state.ready = true;
|
|
358
|
+
} catch (err) {
|
|
359
|
+
setError(err);
|
|
360
|
+
}
|
|
361
|
+
});
|
|
362
|
+
return () => {
|
|
363
|
+
clearTimeout(timeout);
|
|
364
|
+
state.ready = false;
|
|
365
|
+
};
|
|
366
|
+
}, []);
|
|
367
|
+
if (error) {
|
|
368
|
+
throw error;
|
|
369
|
+
}
|
|
370
|
+
if (!state.ready) {
|
|
371
|
+
return /* @__PURE__ */ React3.createElement(React3.Fragment, null, placeholder);
|
|
372
|
+
}
|
|
373
|
+
const ComposedContext = composeContext(state.plugins);
|
|
374
|
+
return /* @__PURE__ */ React3.createElement(ComposedContext, null, rootComponents(state.plugins));
|
|
375
|
+
};
|
|
376
|
+
var initializePlugin = async (pluginDefinition) => {
|
|
377
|
+
const provides = await pluginDefinition.initialize?.();
|
|
378
|
+
return {
|
|
379
|
+
...pluginDefinition,
|
|
380
|
+
provides: {
|
|
381
|
+
...pluginDefinition.provides,
|
|
382
|
+
...provides
|
|
383
|
+
}
|
|
384
|
+
};
|
|
385
|
+
};
|
|
386
|
+
var rootComponents = (plugins) => {
|
|
387
|
+
return plugins.map((plugin) => {
|
|
388
|
+
const Component2 = plugin.provides.root;
|
|
389
|
+
if (Component2) {
|
|
390
|
+
return /* @__PURE__ */ React3.createElement(Component2, {
|
|
391
|
+
key: plugin.meta.id
|
|
392
|
+
});
|
|
393
|
+
} else {
|
|
394
|
+
return null;
|
|
395
|
+
}
|
|
396
|
+
}).filter((node) => Boolean(node));
|
|
397
|
+
};
|
|
398
|
+
var composeContext = (plugins) => {
|
|
399
|
+
return compose(plugins.map((p) => p.provides.context).filter(Boolean));
|
|
400
|
+
};
|
|
401
|
+
var compose = (contexts) => {
|
|
402
|
+
return [
|
|
403
|
+
...contexts
|
|
404
|
+
].reduce((Acc, Next) => ({ children }) => /* @__PURE__ */ React3.createElement(Acc, null, /* @__PURE__ */ React3.createElement(Next, null, children)));
|
|
405
|
+
};
|
|
406
|
+
|
|
371
407
|
// packages/sdk/app-framework/src/App.tsx
|
|
372
408
|
import React4 from "react";
|
|
373
409
|
import { invariant } from "@dxos/invariant";
|
|
@@ -382,7 +418,7 @@ var createApp = ({ order, plugins, core = order.map(({ id }) => id), ...params }
|
|
|
382
418
|
plugins: {
|
|
383
419
|
...plugins,
|
|
384
420
|
[meta_default2.id]: Plugin.lazy(() => import("./plugin-JDIMDLDU.mjs")),
|
|
385
|
-
[meta_default.id]: Plugin.lazy(() => import("./plugin-
|
|
421
|
+
[meta_default.id]: Plugin.lazy(() => import("./plugin-PGPBA2JO.mjs"))
|
|
386
422
|
},
|
|
387
423
|
core: [
|
|
388
424
|
meta_default2.id,
|
|
@@ -410,8 +446,8 @@ var createApp = ({ order, plugins, core = order.map(({ id }) => id), ...params }
|
|
|
410
446
|
]
|
|
411
447
|
});
|
|
412
448
|
const Context = host.provides.context;
|
|
413
|
-
const
|
|
414
|
-
return () => /* @__PURE__ */ React4.createElement(Context, null, /* @__PURE__ */ React4.createElement(
|
|
449
|
+
const Root2 = host.provides.root;
|
|
450
|
+
return () => /* @__PURE__ */ React4.createElement(Context, null, /* @__PURE__ */ React4.createElement(Root2, null));
|
|
415
451
|
};
|
|
416
452
|
export {
|
|
417
453
|
ErrorBoundary,
|
|
@@ -448,6 +484,8 @@ export {
|
|
|
448
484
|
pluginMeta,
|
|
449
485
|
resolvePlugin,
|
|
450
486
|
useIntent,
|
|
487
|
+
useIntentDispatcher,
|
|
488
|
+
useIntentResolver,
|
|
451
489
|
usePlugin,
|
|
452
490
|
usePlugins,
|
|
453
491
|
useResolvePlugin,
|