@dxos/app-framework 0.6.12 → 0.6.13-main.548ca8d
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/index.mjs +169 -163
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +183 -182
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node-esm/chunk-ERPIGFBI.mjs +28 -0
- package/dist/lib/node-esm/chunk-ERPIGFBI.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-IY7HCP4K.mjs +22 -0
- package/dist/lib/node-esm/chunk-IY7HCP4K.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-P2TQLXZR.mjs +54 -0
- package/dist/lib/node-esm/chunk-P2TQLXZR.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +683 -0
- package/dist/lib/node-esm/index.mjs.map +7 -0
- package/dist/lib/node-esm/meta.json +1 -0
- package/dist/lib/node-esm/plugin-24ZP3LDU.mjs +40 -0
- package/dist/lib/node-esm/plugin-24ZP3LDU.mjs.map +7 -0
- package/dist/lib/node-esm/plugin-5AAUGDB3.mjs +168 -0
- package/dist/lib/node-esm/plugin-5AAUGDB3.mjs.map +7 -0
- package/dist/types/src/App.d.ts +4 -4
- package/dist/types/src/App.d.ts.map +1 -1
- package/dist/types/src/plugins/PluginHost/PluginContainer.d.ts +14 -0
- package/dist/types/src/plugins/PluginHost/PluginContainer.d.ts.map +1 -0
- package/dist/types/src/plugins/PluginHost/PluginContext.d.ts +4 -4
- package/dist/types/src/plugins/PluginHost/PluginContext.d.ts.map +1 -1
- package/dist/types/src/plugins/PluginHost/PluginHost.d.ts +4 -8
- package/dist/types/src/plugins/PluginHost/PluginHost.d.ts.map +1 -1
- package/dist/types/src/plugins/PluginHost/plugin.d.ts +37 -83
- package/dist/types/src/plugins/PluginHost/plugin.d.ts.map +1 -1
- package/dist/types/src/plugins/PluginHost/plugin.test.d.ts.map +1 -1
- package/dist/types/src/plugins/common/navigation.d.ts +1 -12
- package/dist/types/src/plugins/common/navigation.d.ts.map +1 -1
- package/package.json +14 -11
- package/project.json +3 -8
- package/src/App.tsx +10 -9
- package/src/plugins/PluginHost/PluginContainer.tsx +120 -0
- package/src/plugins/PluginHost/PluginContext.tsx +8 -14
- package/src/plugins/PluginHost/PluginHost.tsx +18 -121
- package/src/plugins/PluginHost/plugin.test.ts +1 -2
- package/src/plugins/PluginHost/plugin.ts +45 -52
- package/src/plugins/common/navigation.ts +4 -12
- package/tsconfig.json +1 -29
- package/vitest.config.ts +9 -0
package/dist/lib/node/index.cjs
CHANGED
|
@@ -29,7 +29,6 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
29
29
|
var node_exports = {};
|
|
30
30
|
__export(node_exports, {
|
|
31
31
|
ActiveParts: () => ActiveParts,
|
|
32
|
-
Attention: () => Attention,
|
|
33
32
|
ErrorBoundary: () => ErrorBoundary,
|
|
34
33
|
IntentAction: () => import_chunk_DFST5IG5.IntentAction,
|
|
35
34
|
IntentProvider: () => import_chunk_DFST5IG5.IntentProvider,
|
|
@@ -59,7 +58,6 @@ __export(node_exports, {
|
|
|
59
58
|
firstIdInPart: () => firstIdInPart,
|
|
60
59
|
getPlugin: () => import_chunk_62W6CMGM.getPlugin,
|
|
61
60
|
indexInPart: () => indexInPart,
|
|
62
|
-
initializePlugin: () => initializePlugin,
|
|
63
61
|
isLayoutAdjustment: () => isLayoutAdjustment,
|
|
64
62
|
isLayoutMode: () => isLayoutMode,
|
|
65
63
|
isLayoutParts: () => isLayoutParts,
|
|
@@ -81,7 +79,6 @@ __export(node_exports, {
|
|
|
81
79
|
parseSurfacePlugin: () => import_chunk_P5GRB4XF.parseSurfacePlugin,
|
|
82
80
|
parseTranslationsPlugin: () => parseTranslationsPlugin,
|
|
83
81
|
partLength: () => partLength,
|
|
84
|
-
pluginMeta: () => pluginMeta,
|
|
85
82
|
resolvePlugin: () => import_chunk_62W6CMGM.resolvePlugin,
|
|
86
83
|
useIntent: () => import_chunk_DFST5IG5.useIntent,
|
|
87
84
|
useIntentDispatcher: () => import_chunk_DFST5IG5.useIntentDispatcher,
|
|
@@ -98,19 +95,21 @@ var import_chunk_P5GRB4XF = require("./chunk-P5GRB4XF.cjs");
|
|
|
98
95
|
var import_chunk_DFST5IG5 = require("./chunk-DFST5IG5.cjs");
|
|
99
96
|
var import_chunk_62W6CMGM = require("./chunk-62W6CMGM.cjs");
|
|
100
97
|
var import_zod = require("zod");
|
|
98
|
+
var import_schema = require("@effect/schema");
|
|
101
99
|
var import_zod2 = require("zod");
|
|
102
|
-
var import_echo_schema = require("@dxos/echo-schema");
|
|
103
100
|
var import_zod3 = require("zod");
|
|
104
101
|
var import_react = require("react");
|
|
102
|
+
var import_debug = require("@dxos/debug");
|
|
105
103
|
var import_util = require("@dxos/util");
|
|
106
104
|
var import_react2 = __toESM(require("react"));
|
|
107
105
|
var import_local_storage = require("@dxos/local-storage");
|
|
108
|
-
var import_log = require("@dxos/log");
|
|
109
106
|
var import_react3 = __toESM(require("react"));
|
|
107
|
+
var import_log = require("@dxos/log");
|
|
110
108
|
var import_react4 = __toESM(require("react"));
|
|
111
|
-
var import_react5 = require("react");
|
|
112
|
-
var
|
|
113
|
-
var
|
|
109
|
+
var import_react5 = __toESM(require("react"));
|
|
110
|
+
var import_react6 = require("react");
|
|
111
|
+
var import_debug2 = require("@dxos/debug");
|
|
112
|
+
var import_react7 = __toESM(require("react"));
|
|
114
113
|
var import_invariant = require("@dxos/invariant");
|
|
115
114
|
var defaultFileTypes = {
|
|
116
115
|
images: [
|
|
@@ -203,18 +202,21 @@ var SLUG_ENTRY_SEPARATOR = "_";
|
|
|
203
202
|
var SLUG_KEY_VALUE_SEPARATOR = "-";
|
|
204
203
|
var SLUG_PATH_SEPARATOR = "~";
|
|
205
204
|
var SLUG_COLLECTION_INDICATOR = "";
|
|
206
|
-
var LayoutEntrySchema =
|
|
207
|
-
id:
|
|
208
|
-
path:
|
|
205
|
+
var LayoutEntrySchema = import_schema.Schema.mutable(import_schema.Schema.Struct({
|
|
206
|
+
id: import_schema.Schema.String,
|
|
207
|
+
path: import_schema.Schema.optional(import_schema.Schema.String)
|
|
209
208
|
}));
|
|
210
|
-
var LayoutPartSchema =
|
|
211
|
-
var LayoutPartsSchema =
|
|
212
|
-
|
|
209
|
+
var LayoutPartSchema = import_schema.Schema.Union(import_schema.Schema.Literal("sidebar"), import_schema.Schema.Literal("main"), import_schema.Schema.Literal("solo"), import_schema.Schema.Literal("complementary"), import_schema.Schema.Literal("fullScreen"));
|
|
210
|
+
var LayoutPartsSchema = import_schema.Schema.partial(import_schema.Schema.mutable(import_schema.Schema.Record({
|
|
211
|
+
key: LayoutPartSchema,
|
|
212
|
+
value: import_schema.Schema.mutable(import_schema.Schema.Array(LayoutEntrySchema))
|
|
213
|
+
})));
|
|
214
|
+
var LayoutCoordinateSchema = import_schema.Schema.mutable(import_schema.Schema.Struct({
|
|
213
215
|
part: LayoutPartSchema,
|
|
214
|
-
entryId:
|
|
216
|
+
entryId: import_schema.Schema.String
|
|
215
217
|
}));
|
|
216
|
-
var PartAdjustmentSchema =
|
|
217
|
-
var LayoutAdjustmentSchema =
|
|
218
|
+
var PartAdjustmentSchema = import_schema.Schema.Union(import_schema.Schema.Literal("increment-start"), import_schema.Schema.Literal("increment-end"), import_schema.Schema.Literal("solo"));
|
|
219
|
+
var LayoutAdjustmentSchema = import_schema.Schema.mutable(import_schema.Schema.Struct({
|
|
218
220
|
layoutCoordinate: LayoutCoordinateSchema,
|
|
219
221
|
type: PartAdjustmentSchema
|
|
220
222
|
}));
|
|
@@ -222,27 +224,24 @@ var ActiveParts = import_zod2.z.record(import_zod2.z.string(), import_zod2.z.uni
|
|
|
222
224
|
import_zod2.z.string(),
|
|
223
225
|
import_zod2.z.array(import_zod2.z.string())
|
|
224
226
|
]));
|
|
225
|
-
var
|
|
226
|
-
|
|
227
|
-
});
|
|
228
|
-
var LocationProvidesSchema = import_echo_schema.S.mutable(import_echo_schema.S.Struct({
|
|
229
|
-
location: import_echo_schema.S.Struct({
|
|
227
|
+
var LocationProvidesSchema = import_schema.Schema.mutable(import_schema.Schema.Struct({
|
|
228
|
+
location: import_schema.Schema.Struct({
|
|
230
229
|
active: LayoutPartsSchema,
|
|
231
|
-
closed:
|
|
230
|
+
closed: import_schema.Schema.Array(import_schema.Schema.String)
|
|
232
231
|
})
|
|
233
232
|
}));
|
|
234
233
|
var isLayoutParts = (value) => {
|
|
235
|
-
return
|
|
234
|
+
return import_schema.Schema.is(LayoutPartsSchema)(value);
|
|
236
235
|
};
|
|
237
236
|
var isLayoutAdjustment = (value) => {
|
|
238
|
-
return
|
|
237
|
+
return import_schema.Schema.is(LayoutAdjustmentSchema)(value);
|
|
239
238
|
};
|
|
240
239
|
var parseNavigationPlugin = (plugin) => {
|
|
241
240
|
const location = plugin.provides?.location;
|
|
242
241
|
if (!location) {
|
|
243
242
|
return void 0;
|
|
244
243
|
}
|
|
245
|
-
if (
|
|
244
|
+
if (import_schema.Schema.is(LocationProvidesSchema)({
|
|
246
245
|
location
|
|
247
246
|
})) {
|
|
248
247
|
return plugin;
|
|
@@ -299,7 +298,6 @@ var parseTranslationsPlugin = (plugin) => {
|
|
|
299
298
|
const { success } = import_zod3.z.array(Resource).safeParse(plugin.provides.translations);
|
|
300
299
|
return success ? plugin : void 0;
|
|
301
300
|
};
|
|
302
|
-
var pluginMeta = (meta) => meta;
|
|
303
301
|
var Plugin;
|
|
304
302
|
(function(Plugin2) {
|
|
305
303
|
Plugin2.lazy = (p, props) => {
|
|
@@ -308,16 +306,8 @@ var Plugin;
|
|
|
308
306
|
});
|
|
309
307
|
};
|
|
310
308
|
})(Plugin || (Plugin = {}));
|
|
311
|
-
var PluginContext = /* @__PURE__ */ (0, import_react.createContext)(
|
|
312
|
-
|
|
313
|
-
core: [],
|
|
314
|
-
enabled: [],
|
|
315
|
-
plugins: [],
|
|
316
|
-
available: [],
|
|
317
|
-
setPlugin: () => {
|
|
318
|
-
}
|
|
319
|
-
});
|
|
320
|
-
var usePlugins = () => (0, import_react.useContext)(PluginContext);
|
|
309
|
+
var PluginContext = /* @__PURE__ */ (0, import_react.createContext)(void 0);
|
|
310
|
+
var usePlugins = () => (0, import_react.useContext)(PluginContext) ?? (0, import_debug.raise)(new Error("Missing PluginContext"));
|
|
321
311
|
var usePlugin = (id) => {
|
|
322
312
|
const { plugins } = usePlugins();
|
|
323
313
|
return (0, import_chunk_62W6CMGM.findPlugin)(plugins, id);
|
|
@@ -334,8 +324,117 @@ var useResolvePlugins = (predicate) => {
|
|
|
334
324
|
]);
|
|
335
325
|
};
|
|
336
326
|
var PluginProvider = PluginContext.Provider;
|
|
327
|
+
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/sdk/app-framework/src/plugins/PluginHost/PluginContainer.tsx";
|
|
328
|
+
var PluginContainer = ({ plugins: definitions, core, state, placeholder }) => {
|
|
329
|
+
const [error, setError] = (0, import_react3.useState)();
|
|
330
|
+
(0, import_react3.useEffect)(() => {
|
|
331
|
+
(0, import_log.log)("initializing plugins", {
|
|
332
|
+
enabled: state.enabled
|
|
333
|
+
}, {
|
|
334
|
+
F: __dxlog_file,
|
|
335
|
+
L: 26,
|
|
336
|
+
S: void 0,
|
|
337
|
+
C: (f, a) => f(...a)
|
|
338
|
+
});
|
|
339
|
+
const t = setTimeout(async () => {
|
|
340
|
+
try {
|
|
341
|
+
const enabledIds = [
|
|
342
|
+
...core,
|
|
343
|
+
...state.enabled
|
|
344
|
+
];
|
|
345
|
+
const enabled = await Promise.all(enabledIds.map((id) => definitions[id]).filter((definition) => Boolean(definition)).map((definition) => definition()));
|
|
346
|
+
const plugins = await Promise.all(enabled.map(async (definition) => {
|
|
347
|
+
const plugin = await initializePlugin(definition).catch((err) => {
|
|
348
|
+
import_log.log.error("Failed to initialize plugin:", {
|
|
349
|
+
id: definition.meta.id,
|
|
350
|
+
err
|
|
351
|
+
}, {
|
|
352
|
+
F: __dxlog_file,
|
|
353
|
+
L: 41,
|
|
354
|
+
S: void 0,
|
|
355
|
+
C: (f, a) => f(...a)
|
|
356
|
+
});
|
|
357
|
+
});
|
|
358
|
+
(0, import_log.log)("initialized", {
|
|
359
|
+
plugin: definition.meta.id
|
|
360
|
+
}, {
|
|
361
|
+
F: __dxlog_file,
|
|
362
|
+
L: 44,
|
|
363
|
+
S: void 0,
|
|
364
|
+
C: (f, a) => f(...a)
|
|
365
|
+
});
|
|
366
|
+
return plugin;
|
|
367
|
+
}));
|
|
368
|
+
const initialized = plugins.filter((plugin) => Boolean(plugin));
|
|
369
|
+
(0, import_log.log)("plugins initialized", {
|
|
370
|
+
plugins: initialized
|
|
371
|
+
}, {
|
|
372
|
+
F: __dxlog_file,
|
|
373
|
+
L: 50,
|
|
374
|
+
S: void 0,
|
|
375
|
+
C: (f, a) => f(...a)
|
|
376
|
+
});
|
|
377
|
+
await Promise.all(enabled.map((plugin) => plugin.ready?.(initialized)));
|
|
378
|
+
(0, import_log.log)("plugins ready", {
|
|
379
|
+
plugins: initialized
|
|
380
|
+
}, {
|
|
381
|
+
F: __dxlog_file,
|
|
382
|
+
L: 53,
|
|
383
|
+
S: void 0,
|
|
384
|
+
C: (f, a) => f(...a)
|
|
385
|
+
});
|
|
386
|
+
state.plugins = initialized;
|
|
387
|
+
state.ready = true;
|
|
388
|
+
} catch (err) {
|
|
389
|
+
setError(err);
|
|
390
|
+
}
|
|
391
|
+
});
|
|
392
|
+
return () => {
|
|
393
|
+
clearTimeout(t);
|
|
394
|
+
state.ready = false;
|
|
395
|
+
};
|
|
396
|
+
}, []);
|
|
397
|
+
if (error) {
|
|
398
|
+
throw error;
|
|
399
|
+
}
|
|
400
|
+
if (!state.ready) {
|
|
401
|
+
return /* @__PURE__ */ import_react3.default.createElement(import_react3.default.Fragment, null, placeholder);
|
|
402
|
+
}
|
|
403
|
+
const ComposedContext = composeContext(state.plugins);
|
|
404
|
+
return /* @__PURE__ */ import_react3.default.createElement(ComposedContext, null, rootComponents(state.plugins));
|
|
405
|
+
};
|
|
406
|
+
var initializePlugin = async (pluginDefinition) => {
|
|
407
|
+
const provides = await pluginDefinition.initialize?.();
|
|
408
|
+
return {
|
|
409
|
+
...pluginDefinition,
|
|
410
|
+
provides: {
|
|
411
|
+
...pluginDefinition.provides,
|
|
412
|
+
...provides
|
|
413
|
+
}
|
|
414
|
+
};
|
|
415
|
+
};
|
|
416
|
+
var rootComponents = (plugins) => {
|
|
417
|
+
return plugins.map((plugin) => {
|
|
418
|
+
const Component2 = plugin.provides.root;
|
|
419
|
+
if (Component2) {
|
|
420
|
+
return /* @__PURE__ */ import_react3.default.createElement(Component2, {
|
|
421
|
+
key: plugin.meta.id
|
|
422
|
+
});
|
|
423
|
+
} else {
|
|
424
|
+
return null;
|
|
425
|
+
}
|
|
426
|
+
}).filter((node) => Boolean(node));
|
|
427
|
+
};
|
|
428
|
+
var composeContext = (plugins) => {
|
|
429
|
+
return compose(plugins.map((p) => p.provides.context).filter(Boolean));
|
|
430
|
+
};
|
|
431
|
+
var compose = (contexts) => {
|
|
432
|
+
return [
|
|
433
|
+
...contexts
|
|
434
|
+
].reduce((Acc, Next) => ({ children }) => /* @__PURE__ */ import_react3.default.createElement(Acc, null, /* @__PURE__ */ import_react3.default.createElement(Next, null, children)));
|
|
435
|
+
};
|
|
337
436
|
var isObject = (data) => !!data && typeof data === "object";
|
|
338
|
-
var ErrorBoundary = class extends
|
|
437
|
+
var ErrorBoundary = class extends import_react4.Component {
|
|
339
438
|
constructor(props) {
|
|
340
439
|
super(props);
|
|
341
440
|
this.state = {
|
|
@@ -354,7 +453,7 @@ var ErrorBoundary = class extends import_react3.Component {
|
|
|
354
453
|
}
|
|
355
454
|
render() {
|
|
356
455
|
if (this.state.error) {
|
|
357
|
-
return /* @__PURE__ */
|
|
456
|
+
return /* @__PURE__ */ import_react4.default.createElement(this.props.fallback, {
|
|
358
457
|
data: this.props.data,
|
|
359
458
|
error: this.state.error,
|
|
360
459
|
reset: this.resetError
|
|
@@ -368,32 +467,32 @@ var ErrorBoundary = class extends import_react3.Component {
|
|
|
368
467
|
});
|
|
369
468
|
}
|
|
370
469
|
};
|
|
371
|
-
var Surface = /* @__PURE__ */ (0,
|
|
470
|
+
var Surface = /* @__PURE__ */ (0, import_react5.forwardRef)(({ role, name = role, fallback, placeholder, ...rest }, forwardedRef) => {
|
|
372
471
|
const props = {
|
|
373
472
|
role,
|
|
374
473
|
name,
|
|
375
474
|
fallback,
|
|
376
475
|
...rest
|
|
377
476
|
};
|
|
378
|
-
const context = (0,
|
|
477
|
+
const context = (0, import_react6.useContext)(SurfaceContext);
|
|
379
478
|
const data = props.data ?? (name && context?.surfaces?.[name]?.data || {});
|
|
380
|
-
const resolver = /* @__PURE__ */
|
|
479
|
+
const resolver = /* @__PURE__ */ import_react5.default.createElement(SurfaceResolver, {
|
|
381
480
|
...props,
|
|
382
481
|
ref: forwardedRef
|
|
383
482
|
});
|
|
384
|
-
const suspense = placeholder ? /* @__PURE__ */
|
|
483
|
+
const suspense = placeholder ? /* @__PURE__ */ import_react5.default.createElement(import_react5.Suspense, {
|
|
385
484
|
fallback: placeholder
|
|
386
485
|
}, resolver) : resolver;
|
|
387
|
-
return fallback ? /* @__PURE__ */
|
|
486
|
+
return fallback ? /* @__PURE__ */ import_react5.default.createElement(ErrorBoundary, {
|
|
388
487
|
data,
|
|
389
488
|
fallback
|
|
390
489
|
}, suspense) : suspense;
|
|
391
490
|
});
|
|
392
|
-
var SurfaceContext = /* @__PURE__ */ (0,
|
|
393
|
-
var useSurface = () => (0,
|
|
394
|
-
var SurfaceResolver = /* @__PURE__ */ (0,
|
|
491
|
+
var SurfaceContext = /* @__PURE__ */ (0, import_react6.createContext)(null);
|
|
492
|
+
var useSurface = () => (0, import_react6.useContext)(SurfaceContext) ?? (0, import_debug2.raise)(new Error("Surface context not found"));
|
|
493
|
+
var SurfaceResolver = /* @__PURE__ */ (0, import_react5.forwardRef)((props, forwardedRef) => {
|
|
395
494
|
const { components } = (0, import_chunk_P5GRB4XF.useSurfaceRoot)();
|
|
396
|
-
const parent = (0,
|
|
495
|
+
const parent = (0, import_react6.useContext)(SurfaceContext);
|
|
397
496
|
const nodes = resolveNodes(components, props, parent, forwardedRef);
|
|
398
497
|
const currentContext = {
|
|
399
498
|
...props,
|
|
@@ -402,7 +501,7 @@ var SurfaceResolver = /* @__PURE__ */ (0, import_react4.forwardRef)((props, forw
|
|
|
402
501
|
...props.surfaces
|
|
403
502
|
}
|
|
404
503
|
};
|
|
405
|
-
return /* @__PURE__ */
|
|
504
|
+
return /* @__PURE__ */ import_react5.default.createElement(SurfaceContext.Provider, {
|
|
406
505
|
value: currentContext
|
|
407
506
|
}, nodes);
|
|
408
507
|
});
|
|
@@ -422,7 +521,7 @@ var resolveNodes = (components, props, context, forwardedRef) => {
|
|
|
422
521
|
return "node" in result ? [
|
|
423
522
|
key,
|
|
424
523
|
result
|
|
425
|
-
] : /* @__PURE__ */ (0,
|
|
524
|
+
] : /* @__PURE__ */ (0, import_react5.isValidElement)(result) ? [
|
|
426
525
|
key,
|
|
427
526
|
{
|
|
428
527
|
node: result
|
|
@@ -439,15 +538,14 @@ var resolveNodes = (components, props, context, forwardedRef) => {
|
|
|
439
538
|
return 1;
|
|
440
539
|
}
|
|
441
540
|
return 0;
|
|
442
|
-
}).map(([key, result]) => /* @__PURE__ */
|
|
541
|
+
}).map(([key, result]) => /* @__PURE__ */ import_react5.default.createElement(import_react5.Fragment, {
|
|
443
542
|
key
|
|
444
543
|
}, result.node));
|
|
445
544
|
return props.limit ? nodes.slice(0, props.limit) : nodes;
|
|
446
545
|
};
|
|
447
|
-
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/sdk/app-framework/src/plugins/PluginHost/PluginHost.tsx";
|
|
448
546
|
var parsePluginHost = (plugin) => plugin.provides.plugins ? plugin : void 0;
|
|
449
547
|
var PLUGIN_HOST = "dxos.org/plugin/host";
|
|
450
|
-
var PluginHost = ({
|
|
548
|
+
var PluginHost = ({ plugins, meta, core, defaults = [], fallback = DefaultFallback, placeholder = null }) => {
|
|
451
549
|
const state = new import_local_storage.LocalStorageStore(PLUGIN_HOST, {
|
|
452
550
|
ready: false,
|
|
453
551
|
core,
|
|
@@ -455,7 +553,7 @@ var PluginHost = ({ order, plugins: definitions, core = [], defaults = [], fallb
|
|
|
455
553
|
...defaults
|
|
456
554
|
],
|
|
457
555
|
plugins: [],
|
|
458
|
-
available:
|
|
556
|
+
available: meta.filter(({ id }) => !core.includes(id)),
|
|
459
557
|
setPlugin: (id, enabled) => {
|
|
460
558
|
if (enabled) {
|
|
461
559
|
state.values.enabled.push(id);
|
|
@@ -476,16 +574,17 @@ var PluginHost = ({ order, plugins: definitions, core = [], defaults = [], fallb
|
|
|
476
574
|
},
|
|
477
575
|
provides: {
|
|
478
576
|
plugins: state.values,
|
|
479
|
-
context: ({ children }) =>
|
|
480
|
-
|
|
481
|
-
|
|
577
|
+
context: ({ children }) => {
|
|
578
|
+
return /* @__PURE__ */ import_react2.default.createElement(PluginProvider, {
|
|
579
|
+
value: state.values
|
|
580
|
+
}, children);
|
|
581
|
+
},
|
|
482
582
|
root: () => {
|
|
483
583
|
return /* @__PURE__ */ import_react2.default.createElement(ErrorBoundary, {
|
|
484
584
|
fallback
|
|
485
|
-
}, /* @__PURE__ */ import_react2.default.createElement(
|
|
486
|
-
|
|
585
|
+
}, /* @__PURE__ */ import_react2.default.createElement(PluginContainer, {
|
|
586
|
+
plugins,
|
|
487
587
|
core,
|
|
488
|
-
definitions,
|
|
489
588
|
state: state.values,
|
|
490
589
|
placeholder
|
|
491
590
|
}));
|
|
@@ -506,123 +605,20 @@ var DefaultFallback = ({ error }) => {
|
|
|
506
605
|
}
|
|
507
606
|
}, error.message), /* @__PURE__ */ import_react2.default.createElement("pre", null, error.stack));
|
|
508
607
|
};
|
|
509
|
-
var Root = ({ order, core: corePluginIds, definitions, state, placeholder }) => {
|
|
510
|
-
const [error, setError] = (0, import_react2.useState)();
|
|
511
|
-
(0, import_react2.useEffect)(() => {
|
|
512
|
-
(0, import_log.log)("initializing plugins", {
|
|
513
|
-
enabled: state.enabled
|
|
514
|
-
}, {
|
|
515
|
-
F: __dxlog_file,
|
|
516
|
-
L: 102,
|
|
517
|
-
S: void 0,
|
|
518
|
-
C: (f, a) => f(...a)
|
|
519
|
-
});
|
|
520
|
-
const timeout = setTimeout(async () => {
|
|
521
|
-
try {
|
|
522
|
-
const enabledIds = [
|
|
523
|
-
...corePluginIds,
|
|
524
|
-
...state.enabled
|
|
525
|
-
].sort((a, b) => {
|
|
526
|
-
const indexA = order.findIndex(({ id }) => id === a);
|
|
527
|
-
const indexB = order.findIndex(({ id }) => id === b);
|
|
528
|
-
return indexA - indexB;
|
|
529
|
-
});
|
|
530
|
-
const enabled = await Promise.all(enabledIds.map((id) => definitions[id]).filter((definition) => Boolean(definition)).map((definition) => definition()));
|
|
531
|
-
const plugins = await Promise.all(enabled.map(async (definition) => {
|
|
532
|
-
const plugin = await initializePlugin(definition).catch((err) => {
|
|
533
|
-
import_log.log.error("Failed to initialize plugin:", {
|
|
534
|
-
id: definition.meta.id,
|
|
535
|
-
err
|
|
536
|
-
}, {
|
|
537
|
-
F: __dxlog_file,
|
|
538
|
-
L: 122,
|
|
539
|
-
S: void 0,
|
|
540
|
-
C: (f, a) => f(...a)
|
|
541
|
-
});
|
|
542
|
-
return void 0;
|
|
543
|
-
});
|
|
544
|
-
return plugin;
|
|
545
|
-
})).then((plugins2) => plugins2.filter((plugin) => Boolean(plugin)));
|
|
546
|
-
(0, import_log.log)("plugins initialized", {
|
|
547
|
-
plugins
|
|
548
|
-
}, {
|
|
549
|
-
F: __dxlog_file,
|
|
550
|
-
L: 128,
|
|
551
|
-
S: void 0,
|
|
552
|
-
C: (f, a) => f(...a)
|
|
553
|
-
});
|
|
554
|
-
await Promise.all(enabled.map((pluginDefinition) => pluginDefinition.ready?.(plugins)));
|
|
555
|
-
(0, import_log.log)("plugins ready", {
|
|
556
|
-
plugins
|
|
557
|
-
}, {
|
|
558
|
-
F: __dxlog_file,
|
|
559
|
-
L: 131,
|
|
560
|
-
S: void 0,
|
|
561
|
-
C: (f, a) => f(...a)
|
|
562
|
-
});
|
|
563
|
-
state.plugins = plugins;
|
|
564
|
-
state.ready = true;
|
|
565
|
-
} catch (err) {
|
|
566
|
-
setError(err);
|
|
567
|
-
}
|
|
568
|
-
});
|
|
569
|
-
return () => {
|
|
570
|
-
clearTimeout(timeout);
|
|
571
|
-
state.ready = false;
|
|
572
|
-
};
|
|
573
|
-
}, []);
|
|
574
|
-
if (error) {
|
|
575
|
-
throw error;
|
|
576
|
-
}
|
|
577
|
-
if (!state.ready) {
|
|
578
|
-
return /* @__PURE__ */ import_react2.default.createElement(import_react2.default.Fragment, null, placeholder);
|
|
579
|
-
}
|
|
580
|
-
const ComposedContext = composeContext(state.plugins);
|
|
581
|
-
return /* @__PURE__ */ import_react2.default.createElement(ComposedContext, null, rootComponents(state.plugins));
|
|
582
|
-
};
|
|
583
|
-
var initializePlugin = async (pluginDefinition) => {
|
|
584
|
-
const provides = await pluginDefinition.initialize?.();
|
|
585
|
-
return {
|
|
586
|
-
...pluginDefinition,
|
|
587
|
-
provides: {
|
|
588
|
-
...pluginDefinition.provides,
|
|
589
|
-
...provides
|
|
590
|
-
}
|
|
591
|
-
};
|
|
592
|
-
};
|
|
593
|
-
var rootComponents = (plugins) => {
|
|
594
|
-
return plugins.map((plugin) => {
|
|
595
|
-
const Component2 = plugin.provides.root;
|
|
596
|
-
if (Component2) {
|
|
597
|
-
return /* @__PURE__ */ import_react2.default.createElement(Component2, {
|
|
598
|
-
key: plugin.meta.id
|
|
599
|
-
});
|
|
600
|
-
} else {
|
|
601
|
-
return null;
|
|
602
|
-
}
|
|
603
|
-
}).filter((node) => Boolean(node));
|
|
604
|
-
};
|
|
605
|
-
var composeContext = (plugins) => {
|
|
606
|
-
return compose(plugins.map((p) => p.provides.context).filter(Boolean));
|
|
607
|
-
};
|
|
608
|
-
var compose = (contexts) => {
|
|
609
|
-
return [
|
|
610
|
-
...contexts
|
|
611
|
-
].reduce((Acc, Next) => ({ children }) => /* @__PURE__ */ import_react2.default.createElement(Acc, null, /* @__PURE__ */ import_react2.default.createElement(Next, null, children)));
|
|
612
|
-
};
|
|
613
608
|
var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/sdk/app-framework/src/App.tsx";
|
|
614
|
-
var createApp = ({
|
|
609
|
+
var createApp = ({ meta, plugins, core, ...params }) => {
|
|
615
610
|
const host = PluginHost({
|
|
616
|
-
order: [
|
|
617
|
-
import_chunk_P5GRB4XF.meta_default,
|
|
618
|
-
import_chunk_DFST5IG5.meta_default,
|
|
619
|
-
...order
|
|
620
|
-
],
|
|
621
611
|
plugins: {
|
|
622
612
|
...plugins,
|
|
623
613
|
[import_chunk_P5GRB4XF.meta_default.id]: Plugin.lazy(() => import("./plugin-RUJ5PEXB.cjs")),
|
|
624
614
|
[import_chunk_DFST5IG5.meta_default.id]: Plugin.lazy(() => import("./plugin-QV7ESETI.cjs"))
|
|
625
615
|
},
|
|
616
|
+
// TODO(burdon): Why not include in core?
|
|
617
|
+
meta: [
|
|
618
|
+
import_chunk_P5GRB4XF.meta_default,
|
|
619
|
+
import_chunk_DFST5IG5.meta_default,
|
|
620
|
+
...meta
|
|
621
|
+
],
|
|
626
622
|
core: [
|
|
627
623
|
import_chunk_P5GRB4XF.meta_default.id,
|
|
628
624
|
import_chunk_DFST5IG5.meta_default.id,
|
|
@@ -630,32 +626,39 @@ var createApp = ({ order, plugins, core = order.map(({ id }) => id), ...params }
|
|
|
630
626
|
],
|
|
631
627
|
...params
|
|
632
628
|
});
|
|
633
|
-
(0, import_invariant.invariant)(host.provides
|
|
629
|
+
(0, import_invariant.invariant)(host.provides, void 0, {
|
|
634
630
|
F: __dxlog_file2,
|
|
635
|
-
L:
|
|
631
|
+
L: 52,
|
|
636
632
|
S: void 0,
|
|
637
633
|
A: [
|
|
638
|
-
"host.provides
|
|
634
|
+
"host.provides",
|
|
639
635
|
""
|
|
640
636
|
]
|
|
641
637
|
});
|
|
642
|
-
|
|
638
|
+
const { context: Context, root: Root } = host.provides;
|
|
639
|
+
(0, import_invariant.invariant)(Context, void 0, {
|
|
643
640
|
F: __dxlog_file2,
|
|
644
|
-
L:
|
|
641
|
+
L: 54,
|
|
642
|
+
S: void 0,
|
|
643
|
+
A: [
|
|
644
|
+
"Context",
|
|
645
|
+
""
|
|
646
|
+
]
|
|
647
|
+
});
|
|
648
|
+
(0, import_invariant.invariant)(Root, void 0, {
|
|
649
|
+
F: __dxlog_file2,
|
|
650
|
+
L: 55,
|
|
645
651
|
S: void 0,
|
|
646
652
|
A: [
|
|
647
|
-
"
|
|
653
|
+
"Root",
|
|
648
654
|
""
|
|
649
655
|
]
|
|
650
656
|
});
|
|
651
|
-
|
|
652
|
-
const Root2 = host.provides.root;
|
|
653
|
-
return () => /* @__PURE__ */ import_react6.default.createElement(Context, null, /* @__PURE__ */ import_react6.default.createElement(Root2, null));
|
|
657
|
+
return () => /* @__PURE__ */ import_react7.default.createElement(Context, null, /* @__PURE__ */ import_react7.default.createElement(Root, null));
|
|
654
658
|
};
|
|
655
659
|
// Annotate the CommonJS export names for ESM import in node:
|
|
656
660
|
0 && (module.exports = {
|
|
657
661
|
ActiveParts,
|
|
658
|
-
Attention,
|
|
659
662
|
ErrorBoundary,
|
|
660
663
|
IntentAction,
|
|
661
664
|
IntentProvider,
|
|
@@ -685,7 +688,6 @@ var createApp = ({ order, plugins, core = order.map(({ id }) => id), ...params }
|
|
|
685
688
|
firstIdInPart,
|
|
686
689
|
getPlugin,
|
|
687
690
|
indexInPart,
|
|
688
|
-
initializePlugin,
|
|
689
691
|
isLayoutAdjustment,
|
|
690
692
|
isLayoutMode,
|
|
691
693
|
isLayoutParts,
|
|
@@ -707,7 +709,6 @@ var createApp = ({ order, plugins, core = order.map(({ id }) => id), ...params }
|
|
|
707
709
|
parseSurfacePlugin,
|
|
708
710
|
parseTranslationsPlugin,
|
|
709
711
|
partLength,
|
|
710
|
-
pluginMeta,
|
|
711
712
|
resolvePlugin,
|
|
712
713
|
useIntent,
|
|
713
714
|
useIntentDispatcher,
|