@dxos/app-framework 0.6.13-main.548ca8d → 0.6.13-staging.1e988a3
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 +163 -169
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +182 -183
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- 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/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 +8 -4
- package/dist/types/src/plugins/PluginHost/PluginHost.d.ts.map +1 -1
- package/dist/types/src/plugins/PluginHost/plugin.d.ts +83 -37
- 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 +12 -1
- package/dist/types/src/plugins/common/navigation.d.ts.map +1 -1
- package/package.json +11 -14
- package/project.json +8 -3
- package/src/App.tsx +9 -10
- package/src/plugins/PluginHost/PluginContext.tsx +14 -8
- package/src/plugins/PluginHost/PluginHost.tsx +121 -18
- package/src/plugins/PluginHost/plugin.test.ts +2 -1
- package/src/plugins/PluginHost/plugin.ts +52 -45
- package/src/plugins/common/navigation.ts +12 -4
- package/tsconfig.json +29 -1
- package/dist/lib/node-esm/chunk-ERPIGFBI.mjs +0 -28
- package/dist/lib/node-esm/chunk-ERPIGFBI.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-IY7HCP4K.mjs +0 -22
- package/dist/lib/node-esm/chunk-IY7HCP4K.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-P2TQLXZR.mjs +0 -54
- package/dist/lib/node-esm/chunk-P2TQLXZR.mjs.map +0 -7
- package/dist/lib/node-esm/index.mjs +0 -683
- package/dist/lib/node-esm/index.mjs.map +0 -7
- package/dist/lib/node-esm/meta.json +0 -1
- package/dist/lib/node-esm/plugin-24ZP3LDU.mjs +0 -40
- package/dist/lib/node-esm/plugin-24ZP3LDU.mjs.map +0 -7
- package/dist/lib/node-esm/plugin-5AAUGDB3.mjs +0 -168
- package/dist/lib/node-esm/plugin-5AAUGDB3.mjs.map +0 -7
- package/dist/types/src/plugins/PluginHost/PluginContainer.d.ts +0 -14
- package/dist/types/src/plugins/PluginHost/PluginContainer.d.ts.map +0 -1
- package/src/plugins/PluginHost/PluginContainer.tsx +0 -120
- package/vitest.config.ts +0 -9
package/dist/lib/node/index.cjs
CHANGED
|
@@ -29,6 +29,7 @@ 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,
|
|
32
33
|
ErrorBoundary: () => ErrorBoundary,
|
|
33
34
|
IntentAction: () => import_chunk_DFST5IG5.IntentAction,
|
|
34
35
|
IntentProvider: () => import_chunk_DFST5IG5.IntentProvider,
|
|
@@ -58,6 +59,7 @@ __export(node_exports, {
|
|
|
58
59
|
firstIdInPart: () => firstIdInPart,
|
|
59
60
|
getPlugin: () => import_chunk_62W6CMGM.getPlugin,
|
|
60
61
|
indexInPart: () => indexInPart,
|
|
62
|
+
initializePlugin: () => initializePlugin,
|
|
61
63
|
isLayoutAdjustment: () => isLayoutAdjustment,
|
|
62
64
|
isLayoutMode: () => isLayoutMode,
|
|
63
65
|
isLayoutParts: () => isLayoutParts,
|
|
@@ -79,6 +81,7 @@ __export(node_exports, {
|
|
|
79
81
|
parseSurfacePlugin: () => import_chunk_P5GRB4XF.parseSurfacePlugin,
|
|
80
82
|
parseTranslationsPlugin: () => parseTranslationsPlugin,
|
|
81
83
|
partLength: () => partLength,
|
|
84
|
+
pluginMeta: () => pluginMeta,
|
|
82
85
|
resolvePlugin: () => import_chunk_62W6CMGM.resolvePlugin,
|
|
83
86
|
useIntent: () => import_chunk_DFST5IG5.useIntent,
|
|
84
87
|
useIntentDispatcher: () => import_chunk_DFST5IG5.useIntentDispatcher,
|
|
@@ -95,21 +98,19 @@ var import_chunk_P5GRB4XF = require("./chunk-P5GRB4XF.cjs");
|
|
|
95
98
|
var import_chunk_DFST5IG5 = require("./chunk-DFST5IG5.cjs");
|
|
96
99
|
var import_chunk_62W6CMGM = require("./chunk-62W6CMGM.cjs");
|
|
97
100
|
var import_zod = require("zod");
|
|
98
|
-
var import_schema = require("@effect/schema");
|
|
99
101
|
var import_zod2 = require("zod");
|
|
102
|
+
var import_echo_schema = require("@dxos/echo-schema");
|
|
100
103
|
var import_zod3 = require("zod");
|
|
101
104
|
var import_react = require("react");
|
|
102
|
-
var import_debug = require("@dxos/debug");
|
|
103
105
|
var import_util = require("@dxos/util");
|
|
104
106
|
var import_react2 = __toESM(require("react"));
|
|
105
107
|
var import_local_storage = require("@dxos/local-storage");
|
|
106
|
-
var import_react3 = __toESM(require("react"));
|
|
107
108
|
var import_log = require("@dxos/log");
|
|
109
|
+
var import_react3 = __toESM(require("react"));
|
|
108
110
|
var import_react4 = __toESM(require("react"));
|
|
109
|
-
var import_react5 =
|
|
110
|
-
var
|
|
111
|
-
var
|
|
112
|
-
var import_react7 = __toESM(require("react"));
|
|
111
|
+
var import_react5 = require("react");
|
|
112
|
+
var import_debug = require("@dxos/debug");
|
|
113
|
+
var import_react6 = __toESM(require("react"));
|
|
113
114
|
var import_invariant = require("@dxos/invariant");
|
|
114
115
|
var defaultFileTypes = {
|
|
115
116
|
images: [
|
|
@@ -202,21 +203,18 @@ var SLUG_ENTRY_SEPARATOR = "_";
|
|
|
202
203
|
var SLUG_KEY_VALUE_SEPARATOR = "-";
|
|
203
204
|
var SLUG_PATH_SEPARATOR = "~";
|
|
204
205
|
var SLUG_COLLECTION_INDICATOR = "";
|
|
205
|
-
var LayoutEntrySchema =
|
|
206
|
-
id:
|
|
207
|
-
path:
|
|
206
|
+
var LayoutEntrySchema = import_echo_schema.S.mutable(import_echo_schema.S.Struct({
|
|
207
|
+
id: import_echo_schema.S.String,
|
|
208
|
+
path: import_echo_schema.S.optional(import_echo_schema.S.String)
|
|
208
209
|
}));
|
|
209
|
-
var LayoutPartSchema =
|
|
210
|
-
var LayoutPartsSchema =
|
|
211
|
-
|
|
212
|
-
value: import_schema.Schema.mutable(import_schema.Schema.Array(LayoutEntrySchema))
|
|
213
|
-
})));
|
|
214
|
-
var LayoutCoordinateSchema = import_schema.Schema.mutable(import_schema.Schema.Struct({
|
|
210
|
+
var LayoutPartSchema = import_echo_schema.S.Union(import_echo_schema.S.Literal("sidebar"), import_echo_schema.S.Literal("main"), import_echo_schema.S.Literal("solo"), import_echo_schema.S.Literal("complementary"), import_echo_schema.S.Literal("fullScreen"));
|
|
211
|
+
var LayoutPartsSchema = import_echo_schema.S.partial(import_echo_schema.S.mutable(import_echo_schema.S.Record(LayoutPartSchema, import_echo_schema.S.mutable(import_echo_schema.S.Array(LayoutEntrySchema)))));
|
|
212
|
+
var LayoutCoordinateSchema = import_echo_schema.S.mutable(import_echo_schema.S.Struct({
|
|
215
213
|
part: LayoutPartSchema,
|
|
216
|
-
entryId:
|
|
214
|
+
entryId: import_echo_schema.S.String
|
|
217
215
|
}));
|
|
218
|
-
var PartAdjustmentSchema =
|
|
219
|
-
var LayoutAdjustmentSchema =
|
|
216
|
+
var PartAdjustmentSchema = import_echo_schema.S.Union(import_echo_schema.S.Literal("increment-start"), import_echo_schema.S.Literal("increment-end"), import_echo_schema.S.Literal("solo"));
|
|
217
|
+
var LayoutAdjustmentSchema = import_echo_schema.S.mutable(import_echo_schema.S.Struct({
|
|
220
218
|
layoutCoordinate: LayoutCoordinateSchema,
|
|
221
219
|
type: PartAdjustmentSchema
|
|
222
220
|
}));
|
|
@@ -224,24 +222,27 @@ var ActiveParts = import_zod2.z.record(import_zod2.z.string(), import_zod2.z.uni
|
|
|
224
222
|
import_zod2.z.string(),
|
|
225
223
|
import_zod2.z.array(import_zod2.z.string())
|
|
226
224
|
]));
|
|
227
|
-
var
|
|
228
|
-
|
|
225
|
+
var Attention = import_zod2.z.object({
|
|
226
|
+
attended: import_zod2.z.set(import_zod2.z.string()).optional().describe("Ids of items which have focus.")
|
|
227
|
+
});
|
|
228
|
+
var LocationProvidesSchema = import_echo_schema.S.mutable(import_echo_schema.S.Struct({
|
|
229
|
+
location: import_echo_schema.S.Struct({
|
|
229
230
|
active: LayoutPartsSchema,
|
|
230
|
-
closed:
|
|
231
|
+
closed: import_echo_schema.S.Array(import_echo_schema.S.String)
|
|
231
232
|
})
|
|
232
233
|
}));
|
|
233
234
|
var isLayoutParts = (value) => {
|
|
234
|
-
return
|
|
235
|
+
return import_echo_schema.S.is(LayoutPartsSchema)(value);
|
|
235
236
|
};
|
|
236
237
|
var isLayoutAdjustment = (value) => {
|
|
237
|
-
return
|
|
238
|
+
return import_echo_schema.S.is(LayoutAdjustmentSchema)(value);
|
|
238
239
|
};
|
|
239
240
|
var parseNavigationPlugin = (plugin) => {
|
|
240
241
|
const location = plugin.provides?.location;
|
|
241
242
|
if (!location) {
|
|
242
243
|
return void 0;
|
|
243
244
|
}
|
|
244
|
-
if (
|
|
245
|
+
if (import_echo_schema.S.is(LocationProvidesSchema)({
|
|
245
246
|
location
|
|
246
247
|
})) {
|
|
247
248
|
return plugin;
|
|
@@ -298,6 +299,7 @@ var parseTranslationsPlugin = (plugin) => {
|
|
|
298
299
|
const { success } = import_zod3.z.array(Resource).safeParse(plugin.provides.translations);
|
|
299
300
|
return success ? plugin : void 0;
|
|
300
301
|
};
|
|
302
|
+
var pluginMeta = (meta) => meta;
|
|
301
303
|
var Plugin;
|
|
302
304
|
(function(Plugin2) {
|
|
303
305
|
Plugin2.lazy = (p, props) => {
|
|
@@ -306,8 +308,16 @@ var Plugin;
|
|
|
306
308
|
});
|
|
307
309
|
};
|
|
308
310
|
})(Plugin || (Plugin = {}));
|
|
309
|
-
var PluginContext = /* @__PURE__ */ (0, import_react.createContext)(
|
|
310
|
-
|
|
311
|
+
var PluginContext = /* @__PURE__ */ (0, import_react.createContext)({
|
|
312
|
+
ready: false,
|
|
313
|
+
core: [],
|
|
314
|
+
enabled: [],
|
|
315
|
+
plugins: [],
|
|
316
|
+
available: [],
|
|
317
|
+
setPlugin: () => {
|
|
318
|
+
}
|
|
319
|
+
});
|
|
320
|
+
var usePlugins = () => (0, import_react.useContext)(PluginContext);
|
|
311
321
|
var usePlugin = (id) => {
|
|
312
322
|
const { plugins } = usePlugins();
|
|
313
323
|
return (0, import_chunk_62W6CMGM.findPlugin)(plugins, id);
|
|
@@ -324,117 +334,8 @@ var useResolvePlugins = (predicate) => {
|
|
|
324
334
|
]);
|
|
325
335
|
};
|
|
326
336
|
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
|
-
};
|
|
436
337
|
var isObject = (data) => !!data && typeof data === "object";
|
|
437
|
-
var ErrorBoundary = class extends
|
|
338
|
+
var ErrorBoundary = class extends import_react3.Component {
|
|
438
339
|
constructor(props) {
|
|
439
340
|
super(props);
|
|
440
341
|
this.state = {
|
|
@@ -453,7 +354,7 @@ var ErrorBoundary = class extends import_react4.Component {
|
|
|
453
354
|
}
|
|
454
355
|
render() {
|
|
455
356
|
if (this.state.error) {
|
|
456
|
-
return /* @__PURE__ */
|
|
357
|
+
return /* @__PURE__ */ import_react3.default.createElement(this.props.fallback, {
|
|
457
358
|
data: this.props.data,
|
|
458
359
|
error: this.state.error,
|
|
459
360
|
reset: this.resetError
|
|
@@ -467,32 +368,32 @@ var ErrorBoundary = class extends import_react4.Component {
|
|
|
467
368
|
});
|
|
468
369
|
}
|
|
469
370
|
};
|
|
470
|
-
var Surface = /* @__PURE__ */ (0,
|
|
371
|
+
var Surface = /* @__PURE__ */ (0, import_react4.forwardRef)(({ role, name = role, fallback, placeholder, ...rest }, forwardedRef) => {
|
|
471
372
|
const props = {
|
|
472
373
|
role,
|
|
473
374
|
name,
|
|
474
375
|
fallback,
|
|
475
376
|
...rest
|
|
476
377
|
};
|
|
477
|
-
const context = (0,
|
|
378
|
+
const context = (0, import_react5.useContext)(SurfaceContext);
|
|
478
379
|
const data = props.data ?? (name && context?.surfaces?.[name]?.data || {});
|
|
479
|
-
const resolver = /* @__PURE__ */
|
|
380
|
+
const resolver = /* @__PURE__ */ import_react4.default.createElement(SurfaceResolver, {
|
|
480
381
|
...props,
|
|
481
382
|
ref: forwardedRef
|
|
482
383
|
});
|
|
483
|
-
const suspense = placeholder ? /* @__PURE__ */
|
|
384
|
+
const suspense = placeholder ? /* @__PURE__ */ import_react4.default.createElement(import_react4.Suspense, {
|
|
484
385
|
fallback: placeholder
|
|
485
386
|
}, resolver) : resolver;
|
|
486
|
-
return fallback ? /* @__PURE__ */
|
|
387
|
+
return fallback ? /* @__PURE__ */ import_react4.default.createElement(ErrorBoundary, {
|
|
487
388
|
data,
|
|
488
389
|
fallback
|
|
489
390
|
}, suspense) : suspense;
|
|
490
391
|
});
|
|
491
|
-
var SurfaceContext = /* @__PURE__ */ (0,
|
|
492
|
-
var useSurface = () => (0,
|
|
493
|
-
var SurfaceResolver = /* @__PURE__ */ (0,
|
|
392
|
+
var SurfaceContext = /* @__PURE__ */ (0, import_react5.createContext)(null);
|
|
393
|
+
var useSurface = () => (0, import_react5.useContext)(SurfaceContext) ?? (0, import_debug.raise)(new Error("Surface context not found"));
|
|
394
|
+
var SurfaceResolver = /* @__PURE__ */ (0, import_react4.forwardRef)((props, forwardedRef) => {
|
|
494
395
|
const { components } = (0, import_chunk_P5GRB4XF.useSurfaceRoot)();
|
|
495
|
-
const parent = (0,
|
|
396
|
+
const parent = (0, import_react5.useContext)(SurfaceContext);
|
|
496
397
|
const nodes = resolveNodes(components, props, parent, forwardedRef);
|
|
497
398
|
const currentContext = {
|
|
498
399
|
...props,
|
|
@@ -501,7 +402,7 @@ var SurfaceResolver = /* @__PURE__ */ (0, import_react5.forwardRef)((props, forw
|
|
|
501
402
|
...props.surfaces
|
|
502
403
|
}
|
|
503
404
|
};
|
|
504
|
-
return /* @__PURE__ */
|
|
405
|
+
return /* @__PURE__ */ import_react4.default.createElement(SurfaceContext.Provider, {
|
|
505
406
|
value: currentContext
|
|
506
407
|
}, nodes);
|
|
507
408
|
});
|
|
@@ -521,7 +422,7 @@ var resolveNodes = (components, props, context, forwardedRef) => {
|
|
|
521
422
|
return "node" in result ? [
|
|
522
423
|
key,
|
|
523
424
|
result
|
|
524
|
-
] : /* @__PURE__ */ (0,
|
|
425
|
+
] : /* @__PURE__ */ (0, import_react4.isValidElement)(result) ? [
|
|
525
426
|
key,
|
|
526
427
|
{
|
|
527
428
|
node: result
|
|
@@ -538,14 +439,15 @@ var resolveNodes = (components, props, context, forwardedRef) => {
|
|
|
538
439
|
return 1;
|
|
539
440
|
}
|
|
540
441
|
return 0;
|
|
541
|
-
}).map(([key, result]) => /* @__PURE__ */
|
|
442
|
+
}).map(([key, result]) => /* @__PURE__ */ import_react4.default.createElement(import_react4.Fragment, {
|
|
542
443
|
key
|
|
543
444
|
}, result.node));
|
|
544
445
|
return props.limit ? nodes.slice(0, props.limit) : nodes;
|
|
545
446
|
};
|
|
447
|
+
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/sdk/app-framework/src/plugins/PluginHost/PluginHost.tsx";
|
|
546
448
|
var parsePluginHost = (plugin) => plugin.provides.plugins ? plugin : void 0;
|
|
547
449
|
var PLUGIN_HOST = "dxos.org/plugin/host";
|
|
548
|
-
var PluginHost = ({
|
|
450
|
+
var PluginHost = ({ order, plugins: definitions, core = [], defaults = [], fallback = DefaultFallback, placeholder = null }) => {
|
|
549
451
|
const state = new import_local_storage.LocalStorageStore(PLUGIN_HOST, {
|
|
550
452
|
ready: false,
|
|
551
453
|
core,
|
|
@@ -553,7 +455,7 @@ var PluginHost = ({ plugins, meta, core, defaults = [], fallback = DefaultFallba
|
|
|
553
455
|
...defaults
|
|
554
456
|
],
|
|
555
457
|
plugins: [],
|
|
556
|
-
available:
|
|
458
|
+
available: order.filter(({ id }) => !core.includes(id)),
|
|
557
459
|
setPlugin: (id, enabled) => {
|
|
558
460
|
if (enabled) {
|
|
559
461
|
state.values.enabled.push(id);
|
|
@@ -574,17 +476,16 @@ var PluginHost = ({ plugins, meta, core, defaults = [], fallback = DefaultFallba
|
|
|
574
476
|
},
|
|
575
477
|
provides: {
|
|
576
478
|
plugins: state.values,
|
|
577
|
-
context: ({ children }) => {
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
}, children);
|
|
581
|
-
},
|
|
479
|
+
context: ({ children }) => /* @__PURE__ */ import_react2.default.createElement(PluginProvider, {
|
|
480
|
+
value: state.values
|
|
481
|
+
}, children),
|
|
582
482
|
root: () => {
|
|
583
483
|
return /* @__PURE__ */ import_react2.default.createElement(ErrorBoundary, {
|
|
584
484
|
fallback
|
|
585
|
-
}, /* @__PURE__ */ import_react2.default.createElement(
|
|
586
|
-
|
|
485
|
+
}, /* @__PURE__ */ import_react2.default.createElement(Root, {
|
|
486
|
+
order,
|
|
587
487
|
core,
|
|
488
|
+
definitions,
|
|
588
489
|
state: state.values,
|
|
589
490
|
placeholder
|
|
590
491
|
}));
|
|
@@ -605,20 +506,123 @@ var DefaultFallback = ({ error }) => {
|
|
|
605
506
|
}
|
|
606
507
|
}, error.message), /* @__PURE__ */ import_react2.default.createElement("pre", null, error.stack));
|
|
607
508
|
};
|
|
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
|
+
};
|
|
608
613
|
var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/sdk/app-framework/src/App.tsx";
|
|
609
|
-
var createApp = ({
|
|
614
|
+
var createApp = ({ order, plugins, core = order.map(({ id }) => id), ...params }) => {
|
|
610
615
|
const host = PluginHost({
|
|
616
|
+
order: [
|
|
617
|
+
import_chunk_P5GRB4XF.meta_default,
|
|
618
|
+
import_chunk_DFST5IG5.meta_default,
|
|
619
|
+
...order
|
|
620
|
+
],
|
|
611
621
|
plugins: {
|
|
612
622
|
...plugins,
|
|
613
623
|
[import_chunk_P5GRB4XF.meta_default.id]: Plugin.lazy(() => import("./plugin-RUJ5PEXB.cjs")),
|
|
614
624
|
[import_chunk_DFST5IG5.meta_default.id]: Plugin.lazy(() => import("./plugin-QV7ESETI.cjs"))
|
|
615
625
|
},
|
|
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
|
-
],
|
|
622
626
|
core: [
|
|
623
627
|
import_chunk_P5GRB4XF.meta_default.id,
|
|
624
628
|
import_chunk_DFST5IG5.meta_default.id,
|
|
@@ -626,39 +630,32 @@ var createApp = ({ meta, plugins, core, ...params }) => {
|
|
|
626
630
|
],
|
|
627
631
|
...params
|
|
628
632
|
});
|
|
629
|
-
(0, import_invariant.invariant)(host.provides, void 0, {
|
|
633
|
+
(0, import_invariant.invariant)(host.provides?.context, void 0, {
|
|
630
634
|
F: __dxlog_file2,
|
|
631
|
-
L:
|
|
635
|
+
L: 51,
|
|
632
636
|
S: void 0,
|
|
633
637
|
A: [
|
|
634
|
-
"host.provides",
|
|
638
|
+
"host.provides?.context",
|
|
635
639
|
""
|
|
636
640
|
]
|
|
637
641
|
});
|
|
638
|
-
|
|
639
|
-
(0, import_invariant.invariant)(Context, void 0, {
|
|
642
|
+
(0, import_invariant.invariant)(host.provides?.root, void 0, {
|
|
640
643
|
F: __dxlog_file2,
|
|
641
|
-
L:
|
|
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,
|
|
644
|
+
L: 52,
|
|
651
645
|
S: void 0,
|
|
652
646
|
A: [
|
|
653
|
-
"
|
|
647
|
+
"host.provides?.root",
|
|
654
648
|
""
|
|
655
649
|
]
|
|
656
650
|
});
|
|
657
|
-
|
|
651
|
+
const Context = host.provides.context;
|
|
652
|
+
const Root2 = host.provides.root;
|
|
653
|
+
return () => /* @__PURE__ */ import_react6.default.createElement(Context, null, /* @__PURE__ */ import_react6.default.createElement(Root2, null));
|
|
658
654
|
};
|
|
659
655
|
// Annotate the CommonJS export names for ESM import in node:
|
|
660
656
|
0 && (module.exports = {
|
|
661
657
|
ActiveParts,
|
|
658
|
+
Attention,
|
|
662
659
|
ErrorBoundary,
|
|
663
660
|
IntentAction,
|
|
664
661
|
IntentProvider,
|
|
@@ -688,6 +685,7 @@ var createApp = ({ meta, plugins, core, ...params }) => {
|
|
|
688
685
|
firstIdInPart,
|
|
689
686
|
getPlugin,
|
|
690
687
|
indexInPart,
|
|
688
|
+
initializePlugin,
|
|
691
689
|
isLayoutAdjustment,
|
|
692
690
|
isLayoutMode,
|
|
693
691
|
isLayoutParts,
|
|
@@ -709,6 +707,7 @@ var createApp = ({ meta, plugins, core, ...params }) => {
|
|
|
709
707
|
parseSurfacePlugin,
|
|
710
708
|
parseTranslationsPlugin,
|
|
711
709
|
partLength,
|
|
710
|
+
pluginMeta,
|
|
712
711
|
resolvePlugin,
|
|
713
712
|
useIntent,
|
|
714
713
|
useIntentDispatcher,
|