@dxos/app-framework 0.6.13 → 0.6.14-main.2b6a0f3

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.
Files changed (64) hide show
  1. package/dist/lib/browser/{chunk-YYV26N3W.mjs → chunk-SB4XRTGZ.mjs} +4 -5
  2. package/dist/lib/browser/chunk-SB4XRTGZ.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +193 -169
  4. package/dist/lib/browser/index.mjs.map +4 -4
  5. package/dist/lib/browser/meta.json +1 -1
  6. package/dist/lib/browser/{plugin-K3KCPCTJ.mjs → plugin-Y4KRQJE4.mjs} +4 -3
  7. package/dist/lib/browser/plugin-Y4KRQJE4.mjs.map +7 -0
  8. package/dist/lib/node/{chunk-P5GRB4XF.cjs → chunk-PJGE52CN.cjs} +7 -8
  9. package/dist/lib/node/chunk-PJGE52CN.cjs.map +7 -0
  10. package/dist/lib/node/index.cjs +207 -188
  11. package/dist/lib/node/index.cjs.map +4 -4
  12. package/dist/lib/node/meta.json +1 -1
  13. package/dist/lib/node/{plugin-RUJ5PEXB.cjs → plugin-6TEDSCXW.cjs} +10 -9
  14. package/dist/lib/node/plugin-6TEDSCXW.cjs.map +7 -0
  15. package/dist/lib/node-esm/chunk-IY7HCP4K.mjs +22 -0
  16. package/dist/lib/node-esm/chunk-IY7HCP4K.mjs.map +7 -0
  17. package/dist/lib/node-esm/chunk-MBHRXQTR.mjs +27 -0
  18. package/dist/lib/node-esm/chunk-MBHRXQTR.mjs.map +7 -0
  19. package/dist/lib/node-esm/chunk-P2TQLXZR.mjs +54 -0
  20. package/dist/lib/node-esm/chunk-P2TQLXZR.mjs.map +7 -0
  21. package/dist/lib/node-esm/index.mjs +701 -0
  22. package/dist/lib/node-esm/index.mjs.map +7 -0
  23. package/dist/lib/node-esm/meta.json +1 -0
  24. package/dist/lib/node-esm/plugin-5AAUGDB3.mjs +168 -0
  25. package/dist/lib/node-esm/plugin-5AAUGDB3.mjs.map +7 -0
  26. package/dist/lib/node-esm/plugin-J5IRJLM6.mjs +41 -0
  27. package/dist/lib/node-esm/plugin-J5IRJLM6.mjs.map +7 -0
  28. package/dist/types/src/App.d.ts +4 -4
  29. package/dist/types/src/App.d.ts.map +1 -1
  30. package/dist/types/src/plugins/PluginHost/PluginContainer.d.ts +14 -0
  31. package/dist/types/src/plugins/PluginHost/PluginContainer.d.ts.map +1 -0
  32. package/dist/types/src/plugins/PluginHost/PluginContext.d.ts +4 -4
  33. package/dist/types/src/plugins/PluginHost/PluginContext.d.ts.map +1 -1
  34. package/dist/types/src/plugins/PluginHost/PluginHost.d.ts +4 -8
  35. package/dist/types/src/plugins/PluginHost/PluginHost.d.ts.map +1 -1
  36. package/dist/types/src/plugins/PluginHost/plugin.d.ts +37 -83
  37. package/dist/types/src/plugins/PluginHost/plugin.d.ts.map +1 -1
  38. package/dist/types/src/plugins/PluginHost/plugin.test.d.ts.map +1 -1
  39. package/dist/types/src/plugins/SurfacePlugin/Surface.d.ts +2 -2
  40. package/dist/types/src/plugins/SurfacePlugin/Surface.d.ts.map +1 -1
  41. package/dist/types/src/plugins/SurfacePlugin/SurfaceRootContext.d.ts +15 -2
  42. package/dist/types/src/plugins/SurfacePlugin/SurfaceRootContext.d.ts.map +1 -1
  43. package/dist/types/src/plugins/SurfacePlugin/plugin.d.ts +1 -1
  44. package/dist/types/src/plugins/SurfacePlugin/plugin.d.ts.map +1 -1
  45. package/dist/types/src/plugins/common/navigation.d.ts +1 -12
  46. package/dist/types/src/plugins/common/navigation.d.ts.map +1 -1
  47. package/package.json +15 -11
  48. package/project.json +3 -8
  49. package/src/App.tsx +10 -9
  50. package/src/plugins/PluginHost/PluginContainer.tsx +120 -0
  51. package/src/plugins/PluginHost/PluginContext.tsx +8 -14
  52. package/src/plugins/PluginHost/PluginHost.tsx +18 -121
  53. package/src/plugins/PluginHost/plugin.test.ts +1 -2
  54. package/src/plugins/PluginHost/plugin.ts +45 -52
  55. package/src/plugins/SurfacePlugin/Surface.tsx +30 -10
  56. package/src/plugins/SurfacePlugin/SurfaceRootContext.tsx +21 -4
  57. package/src/plugins/SurfacePlugin/plugin.tsx +2 -2
  58. package/src/plugins/common/navigation.ts +4 -12
  59. package/tsconfig.json +1 -29
  60. package/vitest.config.ts +9 -0
  61. package/dist/lib/browser/chunk-YYV26N3W.mjs.map +0 -7
  62. package/dist/lib/browser/plugin-K3KCPCTJ.mjs.map +0 -7
  63. package/dist/lib/node/chunk-P5GRB4XF.cjs.map +0 -7
  64. package/dist/lib/node/plugin-RUJ5PEXB.cjs.map +0 -7
@@ -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,
@@ -49,7 +48,7 @@ __export(node_exports, {
49
48
  SLUG_PATH_SEPARATOR: () => SLUG_PATH_SEPARATOR,
50
49
  SettingsAction: () => SettingsAction,
51
50
  Surface: () => Surface,
52
- SurfaceProvider: () => import_chunk_P5GRB4XF.SurfaceProvider,
51
+ SurfaceProvider: () => import_chunk_PJGE52CN.SurfaceProvider,
53
52
  Toast: () => Toast,
54
53
  createApp: () => createApp,
55
54
  defaultFileTypes: () => defaultFileTypes,
@@ -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,
@@ -76,12 +74,11 @@ __export(node_exports, {
76
74
  parseMetadataResolverPlugin: () => parseMetadataResolverPlugin,
77
75
  parseNavigationPlugin: () => parseNavigationPlugin,
78
76
  parsePluginHost: () => parsePluginHost,
79
- parseRootSurfacePlugin: () => import_chunk_P5GRB4XF.parseRootSurfacePlugin,
77
+ parseRootSurfacePlugin: () => import_chunk_PJGE52CN.parseRootSurfacePlugin,
80
78
  parseSettingsPlugin: () => parseSettingsPlugin,
81
- parseSurfacePlugin: () => import_chunk_P5GRB4XF.parseSurfacePlugin,
79
+ parseSurfacePlugin: () => import_chunk_PJGE52CN.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,
@@ -91,25 +88,26 @@ __export(node_exports, {
91
88
  useResolvePlugin: () => useResolvePlugin,
92
89
  useResolvePlugins: () => useResolvePlugins,
93
90
  useSurface: () => useSurface,
94
- useSurfaceRoot: () => import_chunk_P5GRB4XF.useSurfaceRoot
91
+ useSurfaceRoot: () => import_chunk_PJGE52CN.useSurfaceRoot
95
92
  });
96
93
  module.exports = __toCommonJS(node_exports);
97
- var import_chunk_P5GRB4XF = require("./chunk-P5GRB4XF.cjs");
94
+ var import_chunk_PJGE52CN = require("./chunk-PJGE52CN.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 import_debug = require("@dxos/debug");
109
+ var import_react5 = __toESM(require("react"));
110
+ var import_debug2 = require("@dxos/debug");
113
111
  var import_react6 = __toESM(require("react"));
114
112
  var import_invariant = require("@dxos/invariant");
115
113
  var defaultFileTypes = {
@@ -203,18 +201,21 @@ var SLUG_ENTRY_SEPARATOR = "_";
203
201
  var SLUG_KEY_VALUE_SEPARATOR = "-";
204
202
  var SLUG_PATH_SEPARATOR = "~";
205
203
  var SLUG_COLLECTION_INDICATOR = "";
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)
204
+ var LayoutEntrySchema = import_schema.Schema.mutable(import_schema.Schema.Struct({
205
+ id: import_schema.Schema.String,
206
+ path: import_schema.Schema.optional(import_schema.Schema.String)
209
207
  }));
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({
208
+ 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"));
209
+ var LayoutPartsSchema = import_schema.Schema.partial(import_schema.Schema.mutable(import_schema.Schema.Record({
210
+ key: LayoutPartSchema,
211
+ value: import_schema.Schema.mutable(import_schema.Schema.Array(LayoutEntrySchema))
212
+ })));
213
+ var LayoutCoordinateSchema = import_schema.Schema.mutable(import_schema.Schema.Struct({
213
214
  part: LayoutPartSchema,
214
- entryId: import_echo_schema.S.String
215
+ entryId: import_schema.Schema.String
215
216
  }));
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({
217
+ var PartAdjustmentSchema = import_schema.Schema.Union(import_schema.Schema.Literal("increment-start"), import_schema.Schema.Literal("increment-end"), import_schema.Schema.Literal("solo"));
218
+ var LayoutAdjustmentSchema = import_schema.Schema.mutable(import_schema.Schema.Struct({
218
219
  layoutCoordinate: LayoutCoordinateSchema,
219
220
  type: PartAdjustmentSchema
220
221
  }));
@@ -222,27 +223,24 @@ var ActiveParts = import_zod2.z.record(import_zod2.z.string(), import_zod2.z.uni
222
223
  import_zod2.z.string(),
223
224
  import_zod2.z.array(import_zod2.z.string())
224
225
  ]));
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({
226
+ var LocationProvidesSchema = import_schema.Schema.mutable(import_schema.Schema.Struct({
227
+ location: import_schema.Schema.Struct({
230
228
  active: LayoutPartsSchema,
231
- closed: import_echo_schema.S.Array(import_echo_schema.S.String)
229
+ closed: import_schema.Schema.Array(import_schema.Schema.String)
232
230
  })
233
231
  }));
234
232
  var isLayoutParts = (value) => {
235
- return import_echo_schema.S.is(LayoutPartsSchema)(value);
233
+ return import_schema.Schema.is(LayoutPartsSchema)(value);
236
234
  };
237
235
  var isLayoutAdjustment = (value) => {
238
- return import_echo_schema.S.is(LayoutAdjustmentSchema)(value);
236
+ return import_schema.Schema.is(LayoutAdjustmentSchema)(value);
239
237
  };
240
238
  var parseNavigationPlugin = (plugin) => {
241
239
  const location = plugin.provides?.location;
242
240
  if (!location) {
243
241
  return void 0;
244
242
  }
245
- if (import_echo_schema.S.is(LocationProvidesSchema)({
243
+ if (import_schema.Schema.is(LocationProvidesSchema)({
246
244
  location
247
245
  })) {
248
246
  return plugin;
@@ -299,7 +297,6 @@ var parseTranslationsPlugin = (plugin) => {
299
297
  const { success } = import_zod3.z.array(Resource).safeParse(plugin.provides.translations);
300
298
  return success ? plugin : void 0;
301
299
  };
302
- var pluginMeta = (meta) => meta;
303
300
  var Plugin;
304
301
  (function(Plugin2) {
305
302
  Plugin2.lazy = (p, props) => {
@@ -308,16 +305,8 @@ var Plugin;
308
305
  });
309
306
  };
310
307
  })(Plugin || (Plugin = {}));
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);
308
+ var PluginContext = /* @__PURE__ */ (0, import_react.createContext)(void 0);
309
+ var usePlugins = () => (0, import_react.useContext)(PluginContext) ?? (0, import_debug.raise)(new Error("Missing PluginContext"));
321
310
  var usePlugin = (id) => {
322
311
  const { plugins } = usePlugins();
323
312
  return (0, import_chunk_62W6CMGM.findPlugin)(plugins, id);
@@ -334,8 +323,117 @@ var useResolvePlugins = (predicate) => {
334
323
  ]);
335
324
  };
336
325
  var PluginProvider = PluginContext.Provider;
326
+ var __dxlog_file = "/home/runner/work/dxos/dxos/packages/sdk/app-framework/src/plugins/PluginHost/PluginContainer.tsx";
327
+ var PluginContainer = ({ plugins: definitions, core, state, placeholder }) => {
328
+ const [error, setError] = (0, import_react3.useState)();
329
+ (0, import_react3.useEffect)(() => {
330
+ (0, import_log.log)("initializing plugins", {
331
+ enabled: state.enabled
332
+ }, {
333
+ F: __dxlog_file,
334
+ L: 26,
335
+ S: void 0,
336
+ C: (f, a) => f(...a)
337
+ });
338
+ const t = setTimeout(async () => {
339
+ try {
340
+ const enabledIds = [
341
+ ...core,
342
+ ...state.enabled
343
+ ];
344
+ const enabled = await Promise.all(enabledIds.map((id) => definitions[id]).filter((definition) => Boolean(definition)).map((definition) => definition()));
345
+ const plugins = await Promise.all(enabled.map(async (definition) => {
346
+ const plugin = await initializePlugin(definition).catch((err) => {
347
+ import_log.log.error("Failed to initialize plugin:", {
348
+ id: definition.meta.id,
349
+ err
350
+ }, {
351
+ F: __dxlog_file,
352
+ L: 41,
353
+ S: void 0,
354
+ C: (f, a) => f(...a)
355
+ });
356
+ });
357
+ (0, import_log.log)("initialized", {
358
+ plugin: definition.meta.id
359
+ }, {
360
+ F: __dxlog_file,
361
+ L: 44,
362
+ S: void 0,
363
+ C: (f, a) => f(...a)
364
+ });
365
+ return plugin;
366
+ }));
367
+ const initialized = plugins.filter((plugin) => Boolean(plugin));
368
+ (0, import_log.log)("plugins initialized", {
369
+ plugins: initialized
370
+ }, {
371
+ F: __dxlog_file,
372
+ L: 50,
373
+ S: void 0,
374
+ C: (f, a) => f(...a)
375
+ });
376
+ await Promise.all(enabled.map((plugin) => plugin.ready?.(initialized)));
377
+ (0, import_log.log)("plugins ready", {
378
+ plugins: initialized
379
+ }, {
380
+ F: __dxlog_file,
381
+ L: 53,
382
+ S: void 0,
383
+ C: (f, a) => f(...a)
384
+ });
385
+ state.plugins = initialized;
386
+ state.ready = true;
387
+ } catch (err) {
388
+ setError(err);
389
+ }
390
+ });
391
+ return () => {
392
+ clearTimeout(t);
393
+ state.ready = false;
394
+ };
395
+ }, []);
396
+ if (error) {
397
+ throw error;
398
+ }
399
+ if (!state.ready) {
400
+ return /* @__PURE__ */ import_react3.default.createElement(import_react3.default.Fragment, null, placeholder);
401
+ }
402
+ const ComposedContext = composeContext(state.plugins);
403
+ return /* @__PURE__ */ import_react3.default.createElement(ComposedContext, null, rootComponents(state.plugins));
404
+ };
405
+ var initializePlugin = async (pluginDefinition) => {
406
+ const provides = await pluginDefinition.initialize?.();
407
+ return {
408
+ ...pluginDefinition,
409
+ provides: {
410
+ ...pluginDefinition.provides,
411
+ ...provides
412
+ }
413
+ };
414
+ };
415
+ var rootComponents = (plugins) => {
416
+ return plugins.map((plugin) => {
417
+ const Component2 = plugin.provides.root;
418
+ if (Component2) {
419
+ return /* @__PURE__ */ import_react3.default.createElement(Component2, {
420
+ key: plugin.meta.id
421
+ });
422
+ } else {
423
+ return null;
424
+ }
425
+ }).filter((node) => Boolean(node));
426
+ };
427
+ var composeContext = (plugins) => {
428
+ return compose(plugins.map((p) => p.provides.context).filter(Boolean));
429
+ };
430
+ var compose = (contexts) => {
431
+ return [
432
+ ...contexts
433
+ ].reduce((Acc, Next) => ({ children }) => /* @__PURE__ */ import_react3.default.createElement(Acc, null, /* @__PURE__ */ import_react3.default.createElement(Next, null, children)));
434
+ };
337
435
  var isObject = (data) => !!data && typeof data === "object";
338
- var ErrorBoundary = class extends import_react3.Component {
436
+ var ErrorBoundary = class extends import_react4.Component {
339
437
  constructor(props) {
340
438
  super(props);
341
439
  this.state = {
@@ -354,7 +452,7 @@ var ErrorBoundary = class extends import_react3.Component {
354
452
  }
355
453
  render() {
356
454
  if (this.state.error) {
357
- return /* @__PURE__ */ import_react3.default.createElement(this.props.fallback, {
455
+ return /* @__PURE__ */ import_react4.default.createElement(this.props.fallback, {
358
456
  data: this.props.data,
359
457
  error: this.state.error,
360
458
  reset: this.resetError
@@ -368,31 +466,50 @@ var ErrorBoundary = class extends import_react3.Component {
368
466
  });
369
467
  }
370
468
  };
371
- var Surface = /* @__PURE__ */ (0, import_react4.forwardRef)(({ role, name = role, fallback, placeholder, ...rest }, forwardedRef) => {
469
+ var Surface = /* @__PURE__ */ (0, import_react5.memo)(/* @__PURE__ */ (0, import_react5.forwardRef)(({ role, name = role, fallback, placeholder, ...rest }, forwardedRef) => {
372
470
  const props = {
373
471
  role,
374
472
  name,
375
473
  fallback,
376
474
  ...rest
377
475
  };
476
+ const { debugInfo } = (0, import_chunk_PJGE52CN.useSurfaceRoot)();
477
+ const [id] = (0, import_react5.useState)(Math.random().toString(36).slice(2));
478
+ (0, import_react5.useEffect)(() => {
479
+ debugInfo?.set(id, {
480
+ id,
481
+ created: Date.now(),
482
+ name,
483
+ role,
484
+ renderCount: 0
485
+ });
486
+ return () => {
487
+ debugInfo?.delete(id);
488
+ };
489
+ }, [
490
+ id
491
+ ]);
492
+ if (debugInfo?.get(id)) {
493
+ debugInfo.get(id).renderCount++;
494
+ }
378
495
  const context = (0, import_react5.useContext)(SurfaceContext);
379
496
  const data = props.data ?? (name && context?.surfaces?.[name]?.data || {});
380
- const resolver = /* @__PURE__ */ import_react4.default.createElement(SurfaceResolver, {
497
+ const resolver = /* @__PURE__ */ import_react5.default.createElement(SurfaceResolver, {
381
498
  ...props,
382
499
  ref: forwardedRef
383
500
  });
384
- const suspense = placeholder ? /* @__PURE__ */ import_react4.default.createElement(import_react4.Suspense, {
501
+ const suspense = placeholder ? /* @__PURE__ */ import_react5.default.createElement(import_react5.Suspense, {
385
502
  fallback: placeholder
386
503
  }, resolver) : resolver;
387
- return fallback ? /* @__PURE__ */ import_react4.default.createElement(ErrorBoundary, {
504
+ return fallback ? /* @__PURE__ */ import_react5.default.createElement(ErrorBoundary, {
388
505
  data,
389
506
  fallback
390
507
  }, suspense) : suspense;
391
- });
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) => {
395
- const { components } = (0, import_chunk_P5GRB4XF.useSurfaceRoot)();
508
+ }));
509
+ var SurfaceContext = /* @__PURE__ */ (0, import_react5.createContext)(void 0);
510
+ var useSurface = () => (0, import_react5.useContext)(SurfaceContext) ?? (0, import_debug2.raise)(new Error("Surface context not found"));
511
+ var SurfaceResolver = /* @__PURE__ */ (0, import_react5.forwardRef)((props, forwardedRef) => {
512
+ const { components } = (0, import_chunk_PJGE52CN.useSurfaceRoot)();
396
513
  const parent = (0, import_react5.useContext)(SurfaceContext);
397
514
  const nodes = resolveNodes(components, props, parent, forwardedRef);
398
515
  const currentContext = {
@@ -402,7 +519,7 @@ var SurfaceResolver = /* @__PURE__ */ (0, import_react4.forwardRef)((props, forw
402
519
  ...props.surfaces
403
520
  }
404
521
  };
405
- return /* @__PURE__ */ import_react4.default.createElement(SurfaceContext.Provider, {
522
+ return /* @__PURE__ */ import_react5.default.createElement(SurfaceContext.Provider, {
406
523
  value: currentContext
407
524
  }, nodes);
408
525
  });
@@ -422,7 +539,7 @@ var resolveNodes = (components, props, context, forwardedRef) => {
422
539
  return "node" in result ? [
423
540
  key,
424
541
  result
425
- ] : /* @__PURE__ */ (0, import_react4.isValidElement)(result) ? [
542
+ ] : /* @__PURE__ */ (0, import_react5.isValidElement)(result) ? [
426
543
  key,
427
544
  {
428
545
  node: result
@@ -439,15 +556,14 @@ var resolveNodes = (components, props, context, forwardedRef) => {
439
556
  return 1;
440
557
  }
441
558
  return 0;
442
- }).map(([key, result]) => /* @__PURE__ */ import_react4.default.createElement(import_react4.Fragment, {
559
+ }).map(([key, result]) => /* @__PURE__ */ import_react5.default.createElement(import_react5.Fragment, {
443
560
  key
444
561
  }, result.node));
445
562
  return props.limit ? nodes.slice(0, props.limit) : nodes;
446
563
  };
447
- var __dxlog_file = "/home/runner/work/dxos/dxos/packages/sdk/app-framework/src/plugins/PluginHost/PluginHost.tsx";
448
564
  var parsePluginHost = (plugin) => plugin.provides.plugins ? plugin : void 0;
449
565
  var PLUGIN_HOST = "dxos.org/plugin/host";
450
- var PluginHost = ({ order, plugins: definitions, core = [], defaults = [], fallback = DefaultFallback, placeholder = null }) => {
566
+ var PluginHost = ({ plugins, meta, core, defaults = [], fallback = DefaultFallback, placeholder = null }) => {
451
567
  const state = new import_local_storage.LocalStorageStore(PLUGIN_HOST, {
452
568
  ready: false,
453
569
  core,
@@ -455,7 +571,7 @@ var PluginHost = ({ order, plugins: definitions, core = [], defaults = [], fallb
455
571
  ...defaults
456
572
  ],
457
573
  plugins: [],
458
- available: order.filter(({ id }) => !core.includes(id)),
574
+ available: meta.filter(({ id }) => !core.includes(id)),
459
575
  setPlugin: (id, enabled) => {
460
576
  if (enabled) {
461
577
  state.values.enabled.push(id);
@@ -476,16 +592,17 @@ var PluginHost = ({ order, plugins: definitions, core = [], defaults = [], fallb
476
592
  },
477
593
  provides: {
478
594
  plugins: state.values,
479
- context: ({ children }) => /* @__PURE__ */ import_react2.default.createElement(PluginProvider, {
480
- value: state.values
481
- }, children),
595
+ context: ({ children }) => {
596
+ return /* @__PURE__ */ import_react2.default.createElement(PluginProvider, {
597
+ value: state.values
598
+ }, children);
599
+ },
482
600
  root: () => {
483
601
  return /* @__PURE__ */ import_react2.default.createElement(ErrorBoundary, {
484
602
  fallback
485
- }, /* @__PURE__ */ import_react2.default.createElement(Root, {
486
- order,
603
+ }, /* @__PURE__ */ import_react2.default.createElement(PluginContainer, {
604
+ plugins,
487
605
  core,
488
- definitions,
489
606
  state: state.values,
490
607
  placeholder
491
608
  }));
@@ -506,156 +623,60 @@ var DefaultFallback = ({ error }) => {
506
623
  }
507
624
  }, error.message), /* @__PURE__ */ import_react2.default.createElement("pre", null, error.stack));
508
625
  };
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
626
  var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/sdk/app-framework/src/App.tsx";
614
- var createApp = ({ order, plugins, core = order.map(({ id }) => id), ...params }) => {
627
+ var createApp = ({ meta, plugins, core, ...params }) => {
615
628
  const host = PluginHost({
616
- order: [
617
- import_chunk_P5GRB4XF.meta_default,
618
- import_chunk_DFST5IG5.meta_default,
619
- ...order
620
- ],
621
629
  plugins: {
622
630
  ...plugins,
623
- [import_chunk_P5GRB4XF.meta_default.id]: Plugin.lazy(() => import("./plugin-RUJ5PEXB.cjs")),
631
+ [import_chunk_PJGE52CN.meta_default.id]: Plugin.lazy(() => import("./plugin-6TEDSCXW.cjs")),
624
632
  [import_chunk_DFST5IG5.meta_default.id]: Plugin.lazy(() => import("./plugin-QV7ESETI.cjs"))
625
633
  },
634
+ // TODO(burdon): Why not include in core?
635
+ meta: [
636
+ import_chunk_PJGE52CN.meta_default,
637
+ import_chunk_DFST5IG5.meta_default,
638
+ ...meta
639
+ ],
626
640
  core: [
627
- import_chunk_P5GRB4XF.meta_default.id,
641
+ import_chunk_PJGE52CN.meta_default.id,
628
642
  import_chunk_DFST5IG5.meta_default.id,
629
643
  ...core
630
644
  ],
631
645
  ...params
632
646
  });
633
- (0, import_invariant.invariant)(host.provides?.context, void 0, {
647
+ (0, import_invariant.invariant)(host.provides, void 0, {
634
648
  F: __dxlog_file2,
635
- L: 51,
649
+ L: 52,
636
650
  S: void 0,
637
651
  A: [
638
- "host.provides?.context",
652
+ "host.provides",
639
653
  ""
640
654
  ]
641
655
  });
642
- (0, import_invariant.invariant)(host.provides?.root, void 0, {
656
+ const { context: Context, root: Root } = host.provides;
657
+ (0, import_invariant.invariant)(Context, void 0, {
643
658
  F: __dxlog_file2,
644
- L: 52,
659
+ L: 54,
660
+ S: void 0,
661
+ A: [
662
+ "Context",
663
+ ""
664
+ ]
665
+ });
666
+ (0, import_invariant.invariant)(Root, void 0, {
667
+ F: __dxlog_file2,
668
+ L: 55,
645
669
  S: void 0,
646
670
  A: [
647
- "host.provides?.root",
671
+ "Root",
648
672
  ""
649
673
  ]
650
674
  });
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));
675
+ return () => /* @__PURE__ */ import_react6.default.createElement(Context, null, /* @__PURE__ */ import_react6.default.createElement(Root, null));
654
676
  };
655
677
  // Annotate the CommonJS export names for ESM import in node:
656
678
  0 && (module.exports = {
657
679
  ActiveParts,
658
- Attention,
659
680
  ErrorBoundary,
660
681
  IntentAction,
661
682
  IntentProvider,
@@ -685,7 +706,6 @@ var createApp = ({ order, plugins, core = order.map(({ id }) => id), ...params }
685
706
  firstIdInPart,
686
707
  getPlugin,
687
708
  indexInPart,
688
- initializePlugin,
689
709
  isLayoutAdjustment,
690
710
  isLayoutMode,
691
711
  isLayoutParts,
@@ -707,7 +727,6 @@ var createApp = ({ order, plugins, core = order.map(({ id }) => id), ...params }
707
727
  parseSurfacePlugin,
708
728
  parseTranslationsPlugin,
709
729
  partLength,
710
- pluginMeta,
711
730
  resolvePlugin,
712
731
  useIntent,
713
732
  useIntentDispatcher,