@dxos/app-framework 0.3.11-main.f14932f → 0.3.11-main.f4c1077

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 (38) hide show
  1. package/dist/lib/browser/{chunk-QYIBDGYI.mjs → chunk-7MQ2DVDI.mjs} +2 -3
  2. package/dist/lib/browser/{chunk-QYIBDGYI.mjs.map → chunk-7MQ2DVDI.mjs.map} +2 -2
  3. package/dist/lib/browser/index.mjs +180 -147
  4. package/dist/lib/browser/index.mjs.map +3 -3
  5. package/dist/lib/browser/meta.json +1 -1
  6. package/dist/lib/browser/{plugin-YLDDUID4.mjs → plugin-PGPBA2JO.mjs} +36 -13
  7. package/dist/lib/browser/plugin-PGPBA2JO.mjs.map +7 -0
  8. package/dist/lib/node/{chunk-YWRBMGDT.cjs → chunk-FETX4EGX.cjs} +5 -6
  9. package/dist/lib/node/{chunk-YWRBMGDT.cjs.map → chunk-FETX4EGX.cjs.map} +2 -2
  10. package/dist/lib/node/index.cjs +180 -149
  11. package/dist/lib/node/index.cjs.map +3 -3
  12. package/dist/lib/node/meta.json +1 -1
  13. package/dist/lib/node/{plugin-NP3IH5Q3.cjs → plugin-HLGHD6N5.cjs} +43 -19
  14. package/dist/lib/node/plugin-HLGHD6N5.cjs.map +7 -0
  15. package/dist/types/src/plugins/IntentPlugin/intent.d.ts +33 -2
  16. package/dist/types/src/plugins/IntentPlugin/intent.d.ts.map +1 -1
  17. package/dist/types/src/plugins/IntentPlugin/plugin.d.ts.map +1 -1
  18. package/dist/types/src/plugins/PluginHost/PluginHost.d.ts +4 -2
  19. package/dist/types/src/plugins/PluginHost/PluginHost.d.ts.map +1 -1
  20. package/dist/types/src/plugins/PluginHost/plugin.d.ts +1 -1
  21. package/dist/types/src/plugins/PluginHost/plugin.d.ts.map +1 -1
  22. package/dist/types/src/plugins/SurfacePlugin/Surface.d.ts +4 -5
  23. package/dist/types/src/plugins/SurfacePlugin/Surface.d.ts.map +1 -1
  24. package/dist/types/src/plugins/common/layout.d.ts +15 -14
  25. package/dist/types/src/plugins/common/layout.d.ts.map +1 -1
  26. package/package.json +8 -7
  27. package/project.json +3 -1
  28. package/src/plugins/IntentPlugin/IntentContext.tsx +1 -1
  29. package/src/plugins/IntentPlugin/intent.ts +38 -2
  30. package/src/plugins/IntentPlugin/plugin.tsx +38 -9
  31. package/src/plugins/PluginHost/PluginHost.tsx +92 -57
  32. package/src/plugins/PluginHost/plugin.ts +2 -1
  33. package/src/plugins/SurfacePlugin/Surface.tsx +15 -21
  34. package/src/plugins/common/layout.ts +15 -14
  35. package/src/vite-env.d.ts +5 -0
  36. package/tsconfig.json +3 -0
  37. package/dist/lib/browser/plugin-YLDDUID4.mjs.map +0 -7
  38. package/dist/lib/node/plugin-NP3IH5Q3.cjs.map +0 -7
@@ -29,7 +29,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
29
29
  var node_exports = {};
30
30
  __export(node_exports, {
31
31
  ErrorBoundary: () => ErrorBoundary,
32
- IntentProvider: () => import_chunk_YWRBMGDT.IntentProvider,
32
+ IntentProvider: () => import_chunk_FETX4EGX.IntentProvider,
33
33
  Layout: () => Layout,
34
34
  LayoutAction: () => LayoutAction,
35
35
  Plugin: () => Plugin,
@@ -49,8 +49,8 @@ __export(node_exports, {
49
49
  isObject: () => isObject,
50
50
  parseGraphBuilderPlugin: () => parseGraphBuilderPlugin,
51
51
  parseGraphPlugin: () => parseGraphPlugin,
52
- parseIntentPlugin: () => import_chunk_YWRBMGDT.parseIntentPlugin,
53
- parseIntentResolverPlugin: () => import_chunk_YWRBMGDT.parseIntentResolverPlugin,
52
+ parseIntentPlugin: () => import_chunk_FETX4EGX.parseIntentPlugin,
53
+ parseIntentResolverPlugin: () => import_chunk_FETX4EGX.parseIntentResolverPlugin,
54
54
  parseLayoutPlugin: () => parseLayoutPlugin,
55
55
  parseMetadataRecordsPlugin: () => parseMetadataRecordsPlugin,
56
56
  parseMetadataResolverPlugin: () => parseMetadataResolverPlugin,
@@ -61,9 +61,9 @@ __export(node_exports, {
61
61
  parseTranslationsPlugin: () => parseTranslationsPlugin,
62
62
  pluginMeta: () => pluginMeta,
63
63
  resolvePlugin: () => import_chunk_VDKZ7AAF.resolvePlugin,
64
- useIntent: () => import_chunk_YWRBMGDT.useIntent,
65
- useIntentDispatcher: () => import_chunk_YWRBMGDT.useIntentDispatcher,
66
- useIntentResolver: () => import_chunk_YWRBMGDT.useIntentResolver,
64
+ useIntent: () => import_chunk_FETX4EGX.useIntent,
65
+ useIntentDispatcher: () => import_chunk_FETX4EGX.useIntentDispatcher,
66
+ useIntentResolver: () => import_chunk_FETX4EGX.useIntentResolver,
67
67
  usePlugin: () => usePlugin,
68
68
  usePlugins: () => usePlugins,
69
69
  useResolvePlugin: () => useResolvePlugin,
@@ -71,7 +71,7 @@ __export(node_exports, {
71
71
  });
72
72
  module.exports = __toCommonJS(node_exports);
73
73
  var import_chunk_DC3GU6QR = require("./chunk-DC3GU6QR.cjs");
74
- var import_chunk_YWRBMGDT = require("./chunk-YWRBMGDT.cjs");
74
+ var import_chunk_FETX4EGX = require("./chunk-FETX4EGX.cjs");
75
75
  var import_chunk_VDKZ7AAF = require("./chunk-VDKZ7AAF.cjs");
76
76
  var import_zod = require("zod");
77
77
  var import_zod2 = require("zod");
@@ -146,7 +146,7 @@ var parseTranslationsPlugin = (plugin) => {
146
146
  var pluginMeta = (meta) => meta;
147
147
  var Plugin;
148
148
  (function(Plugin2) {
149
- var lazy = Plugin2.lazy = (p, props) => {
149
+ Plugin2.lazy = (p, props) => {
150
150
  return () => p().then(({ default: definition }) => {
151
151
  return definition(props);
152
152
  });
@@ -170,132 +170,6 @@ var useResolvePlugin = (predicate) => {
170
170
  return (0, import_chunk_VDKZ7AAF.resolvePlugin)(plugins, predicate);
171
171
  };
172
172
  var PluginProvider = PluginContext.Provider;
173
- var __dxlog_file = "/home/runner/work/dxos/dxos/packages/sdk/app-framework/src/plugins/PluginHost/PluginHost.tsx";
174
- var parsePluginHost = (plugin) => plugin.provides.plugins ? plugin : void 0;
175
- var PLUGIN_HOST = "dxos.org/plugin/host";
176
- var PluginHost = ({ order, plugins: definitions, core = [], defaults = [], fallback = null }) => {
177
- const state = new import_local_storage.LocalStorageStore(PLUGIN_HOST, {
178
- ready: false,
179
- enabled: [
180
- ...defaults
181
- ],
182
- plugins: [],
183
- available: order.filter(({ id }) => !core.includes(id)),
184
- setPlugin: (id, enabled) => {
185
- if (enabled) {
186
- state.values.enabled = [
187
- ...state.values.enabled,
188
- id
189
- ];
190
- } else {
191
- state.values.enabled = state.values.enabled.filter((enabled2) => enabled2 !== id);
192
- }
193
- }
194
- });
195
- state.prop(state.values.$enabled, "enabled", import_local_storage.LocalStorageStore.json);
196
- return {
197
- meta: {
198
- id: PLUGIN_HOST,
199
- name: "Plugin host"
200
- },
201
- provides: {
202
- plugins: state.values,
203
- context: ({ children }) => /* @__PURE__ */ import_react3.default.createElement(PluginProvider, {
204
- value: state.values
205
- }, children),
206
- root: () => {
207
- (0, import_react3.useEffect)(() => {
208
- (0, import_log.log)("initializing plugins", {
209
- enabled: state.values.enabled
210
- }, {
211
- F: __dxlog_file,
212
- L: 67,
213
- S: void 0,
214
- C: (f, a) => f(...a)
215
- });
216
- const timeout = setTimeout(async () => {
217
- const enabledIds = [
218
- ...core,
219
- ...state.values.enabled
220
- ].sort((a, b) => {
221
- const indexA = order.findIndex(({ id }) => id === a);
222
- const indexB = order.findIndex(({ id }) => id === b);
223
- return indexA - indexB;
224
- });
225
- const enabled = await Promise.all(enabledIds.map((id) => definitions[id]).filter((definition) => Boolean(definition)).map((definition) => definition()));
226
- const plugins = await Promise.all(enabled.map(async (definition) => {
227
- const plugin = await initializePlugin(definition).catch((err) => {
228
- console.error("Failed to initialize plugin:", definition.meta.id, err);
229
- return void 0;
230
- });
231
- return plugin;
232
- })).then((plugins2) => plugins2.filter((plugin) => Boolean(plugin)));
233
- (0, import_log.log)("plugins initialized", {
234
- plugins
235
- }, {
236
- F: __dxlog_file,
237
- L: 92,
238
- S: void 0,
239
- C: (f, a) => f(...a)
240
- });
241
- await Promise.all(enabled.map(async (pluginDefinition) => {
242
- await pluginDefinition.ready?.(plugins);
243
- }));
244
- (0, import_log.log)("plugins ready", {
245
- plugins
246
- }, {
247
- F: __dxlog_file,
248
- L: 99,
249
- S: void 0,
250
- C: (f, a) => f(...a)
251
- });
252
- state.values.plugins = (0, import_react2.shallow)(plugins);
253
- state.values.ready = true;
254
- });
255
- return () => {
256
- clearTimeout(timeout);
257
- state.values.ready = false;
258
- };
259
- }, []);
260
- if (!state.values.ready) {
261
- return /* @__PURE__ */ import_react3.default.createElement(import_react3.default.Fragment, null, fallback);
262
- }
263
- const ComposedContext = composeContext(state.values.plugins);
264
- return /* @__PURE__ */ import_react3.default.createElement(ComposedContext, null, rootComponents(state.values.plugins));
265
- }
266
- }
267
- };
268
- };
269
- var initializePlugin = async (pluginDefinition) => {
270
- const provides = await pluginDefinition.initialize?.();
271
- return {
272
- ...pluginDefinition,
273
- provides: {
274
- ...pluginDefinition.provides,
275
- ...provides
276
- }
277
- };
278
- };
279
- var rootComponents = (plugins) => {
280
- return plugins.map((plugin) => {
281
- const Component2 = plugin.provides.root;
282
- if (Component2) {
283
- return /* @__PURE__ */ import_react3.default.createElement(Component2, {
284
- key: plugin.meta.id
285
- });
286
- } else {
287
- return null;
288
- }
289
- }).filter((node) => Boolean(node));
290
- };
291
- var composeContext = (plugins) => {
292
- return compose(plugins.map((p) => p.provides.context).filter(Boolean));
293
- };
294
- var compose = (contexts) => {
295
- return [
296
- ...contexts
297
- ].reduce((Acc, Next) => ({ children }) => /* @__PURE__ */ import_react3.default.createElement(Acc, null, /* @__PURE__ */ import_react3.default.createElement(Next, null, children)));
298
- };
299
173
  var isObject = (data) => !!data && typeof data === "object";
300
174
  var ErrorBoundary = class extends import_react4.Component {
301
175
  constructor(props) {
@@ -329,7 +203,7 @@ var ErrorBoundary = class extends import_react4.Component {
329
203
  });
330
204
  }
331
205
  };
332
- var Surface = /* @__PURE__ */ (0, import_react5.forwardRef)(({ role, name = role, fallback, ...rest }, forwardedRef) => {
206
+ var Surface = /* @__PURE__ */ (0, import_react5.forwardRef)(({ role, name = role, fallback, placeholder, ...rest }, forwardedRef) => {
333
207
  const props = {
334
208
  role,
335
209
  name,
@@ -338,16 +212,17 @@ var Surface = /* @__PURE__ */ (0, import_react5.forwardRef)(({ role, name = role
338
212
  };
339
213
  const context = (0, import_react6.useContext)(SurfaceContext);
340
214
  const data = props.data ?? (name && context?.surfaces?.[name]?.data || {});
341
- return /* @__PURE__ */ import_react5.default.createElement(import_react5.default.Fragment, null, fallback ? /* @__PURE__ */ import_react5.default.createElement(ErrorBoundary, {
342
- data,
343
- fallback
344
- }, /* @__PURE__ */ import_react5.default.createElement(SurfaceResolver, {
345
- ...props,
346
- ref: forwardedRef
347
- })) : /* @__PURE__ */ import_react5.default.createElement(SurfaceResolver, {
215
+ const resolver = /* @__PURE__ */ import_react5.default.createElement(SurfaceResolver, {
348
216
  ...props,
349
217
  ref: forwardedRef
350
- }));
218
+ });
219
+ const suspense = placeholder ? /* @__PURE__ */ import_react5.default.createElement(import_react5.Suspense, {
220
+ fallback: placeholder
221
+ }, resolver) : resolver;
222
+ return fallback ? /* @__PURE__ */ import_react5.default.createElement(ErrorBoundary, {
223
+ data,
224
+ fallback
225
+ }, suspense) : suspense;
351
226
  });
352
227
  var SurfaceContext = /* @__PURE__ */ (0, import_react6.createContext)(null);
353
228
  var SurfaceResolver = /* @__PURE__ */ (0, import_react5.forwardRef)((props, forwardedRef) => {
@@ -363,7 +238,7 @@ var SurfaceResolver = /* @__PURE__ */ (0, import_react5.forwardRef)((props, forw
363
238
  };
364
239
  return /* @__PURE__ */ import_react5.default.createElement(SurfaceContext.Provider, {
365
240
  value: currentContext
366
- }, nodes.length > 0 ? nodes : props.contentFallback ? /* @__PURE__ */ import_react5.default.createElement(props.contentFallback, null) : null);
241
+ }, nodes);
367
242
  });
368
243
  var resolveNodes = (components, props, context, forwardedRef) => {
369
244
  const data = {
@@ -403,22 +278,178 @@ var resolveNodes = (components, props, context, forwardedRef) => {
403
278
  }, result.node));
404
279
  return props.limit ? nodes.slice(0, props.limit) : nodes;
405
280
  };
281
+ var __dxlog_file = "/home/runner/work/dxos/dxos/packages/sdk/app-framework/src/plugins/PluginHost/PluginHost.tsx";
282
+ var parsePluginHost = (plugin) => plugin.provides.plugins ? plugin : void 0;
283
+ var PLUGIN_HOST = "dxos.org/plugin/host";
284
+ var PluginHost = ({ order, plugins: definitions, core = [], defaults = [], fallback = DefaultFallback, placeholder = null }) => {
285
+ const state = new import_local_storage.LocalStorageStore(PLUGIN_HOST, {
286
+ ready: false,
287
+ enabled: [
288
+ ...defaults
289
+ ],
290
+ plugins: [],
291
+ available: order.filter(({ id }) => !core.includes(id)),
292
+ setPlugin: (id, enabled) => {
293
+ if (enabled) {
294
+ state.values.enabled = [
295
+ ...state.values.enabled,
296
+ id
297
+ ];
298
+ } else {
299
+ state.values.enabled = state.values.enabled.filter((enabled2) => enabled2 !== id);
300
+ }
301
+ }
302
+ });
303
+ state.prop(state.values.$enabled, "enabled", import_local_storage.LocalStorageStore.json);
304
+ return {
305
+ meta: {
306
+ id: PLUGIN_HOST,
307
+ name: "Plugin host"
308
+ },
309
+ provides: {
310
+ plugins: state.values,
311
+ context: ({ children }) => /* @__PURE__ */ import_react3.default.createElement(PluginProvider, {
312
+ value: state.values
313
+ }, children),
314
+ root: () => {
315
+ return /* @__PURE__ */ import_react3.default.createElement(ErrorBoundary, {
316
+ fallback
317
+ }, /* @__PURE__ */ import_react3.default.createElement(Root, {
318
+ order,
319
+ core,
320
+ definitions,
321
+ state: state.values,
322
+ placeholder
323
+ }));
324
+ }
325
+ }
326
+ };
327
+ };
328
+ var DefaultFallback = ({ error }) => {
329
+ return /* @__PURE__ */ import_react3.default.createElement("div", {
330
+ style: {
331
+ padding: "1rem"
332
+ }
333
+ }, /* @__PURE__ */ import_react3.default.createElement("h1", {
334
+ style: {
335
+ fontSize: "1.2rem",
336
+ fontWeight: 700,
337
+ margin: "0.5rem 0"
338
+ }
339
+ }, error.message), /* @__PURE__ */ import_react3.default.createElement("pre", null, error.stack));
340
+ };
341
+ var Root = ({ order, core: corePluginIds, definitions, state, placeholder }) => {
342
+ const [error, setError] = (0, import_react3.useState)();
343
+ (0, import_react3.useEffect)(() => {
344
+ (0, import_log.log)("initializing plugins", {
345
+ enabled: state.enabled
346
+ }, {
347
+ F: __dxlog_file,
348
+ L: 101,
349
+ S: void 0,
350
+ C: (f, a) => f(...a)
351
+ });
352
+ const timeout = setTimeout(async () => {
353
+ try {
354
+ const enabledIds = [
355
+ ...corePluginIds,
356
+ ...state.enabled
357
+ ].sort((a, b) => {
358
+ const indexA = order.findIndex(({ id }) => id === a);
359
+ const indexB = order.findIndex(({ id }) => id === b);
360
+ return indexA - indexB;
361
+ });
362
+ const enabled = await Promise.all(enabledIds.map((id) => definitions[id]).filter((definition) => Boolean(definition)).map((definition) => definition()));
363
+ const plugins = await Promise.all(enabled.map(async (definition) => {
364
+ const plugin = await initializePlugin(definition).catch((err) => {
365
+ console.error("Failed to initialize plugin:", definition.meta.id, err);
366
+ return void 0;
367
+ });
368
+ return plugin;
369
+ })).then((plugins2) => plugins2.filter((plugin) => Boolean(plugin)));
370
+ (0, import_log.log)("plugins initialized", {
371
+ plugins
372
+ }, {
373
+ F: __dxlog_file,
374
+ L: 127,
375
+ S: void 0,
376
+ C: (f, a) => f(...a)
377
+ });
378
+ await Promise.all(enabled.map((pluginDefinition) => pluginDefinition.ready?.(plugins)));
379
+ (0, import_log.log)("plugins ready", {
380
+ plugins
381
+ }, {
382
+ F: __dxlog_file,
383
+ L: 130,
384
+ S: void 0,
385
+ C: (f, a) => f(...a)
386
+ });
387
+ state.plugins = (0, import_react2.shallow)(plugins);
388
+ state.ready = true;
389
+ } catch (err) {
390
+ setError(err);
391
+ }
392
+ });
393
+ return () => {
394
+ clearTimeout(timeout);
395
+ state.ready = false;
396
+ };
397
+ }, []);
398
+ if (error) {
399
+ throw error;
400
+ }
401
+ if (!state.ready) {
402
+ return /* @__PURE__ */ import_react3.default.createElement(import_react3.default.Fragment, null, placeholder);
403
+ }
404
+ const ComposedContext = composeContext(state.plugins);
405
+ return /* @__PURE__ */ import_react3.default.createElement(ComposedContext, null, rootComponents(state.plugins));
406
+ };
407
+ var initializePlugin = async (pluginDefinition) => {
408
+ const provides = await pluginDefinition.initialize?.();
409
+ return {
410
+ ...pluginDefinition,
411
+ provides: {
412
+ ...pluginDefinition.provides,
413
+ ...provides
414
+ }
415
+ };
416
+ };
417
+ var rootComponents = (plugins) => {
418
+ return plugins.map((plugin) => {
419
+ const Component2 = plugin.provides.root;
420
+ if (Component2) {
421
+ return /* @__PURE__ */ import_react3.default.createElement(Component2, {
422
+ key: plugin.meta.id
423
+ });
424
+ } else {
425
+ return null;
426
+ }
427
+ }).filter((node) => Boolean(node));
428
+ };
429
+ var composeContext = (plugins) => {
430
+ return compose(plugins.map((p) => p.provides.context).filter(Boolean));
431
+ };
432
+ var compose = (contexts) => {
433
+ return [
434
+ ...contexts
435
+ ].reduce((Acc, Next) => ({ children }) => /* @__PURE__ */ import_react3.default.createElement(Acc, null, /* @__PURE__ */ import_react3.default.createElement(Next, null, children)));
436
+ };
406
437
  var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/sdk/app-framework/src/App.tsx";
407
438
  var createApp = ({ order, plugins, core = order.map(({ id }) => id), ...params }) => {
408
439
  const host = PluginHost({
409
440
  order: [
410
441
  import_chunk_DC3GU6QR.meta_default,
411
- import_chunk_YWRBMGDT.meta_default,
442
+ import_chunk_FETX4EGX.meta_default,
412
443
  ...order
413
444
  ],
414
445
  plugins: {
415
446
  ...plugins,
416
447
  [import_chunk_DC3GU6QR.meta_default.id]: Plugin.lazy(() => import("./plugin-JGSJGRMS.cjs")),
417
- [import_chunk_YWRBMGDT.meta_default.id]: Plugin.lazy(() => import("./plugin-NP3IH5Q3.cjs"))
448
+ [import_chunk_FETX4EGX.meta_default.id]: Plugin.lazy(() => import("./plugin-HLGHD6N5.cjs"))
418
449
  },
419
450
  core: [
420
451
  import_chunk_DC3GU6QR.meta_default.id,
421
- import_chunk_YWRBMGDT.meta_default.id,
452
+ import_chunk_FETX4EGX.meta_default.id,
422
453
  ...core
423
454
  ],
424
455
  ...params
@@ -442,8 +473,8 @@ var createApp = ({ order, plugins, core = order.map(({ id }) => id), ...params }
442
473
  ]
443
474
  });
444
475
  const Context = host.provides.context;
445
- const Root = host.provides.root;
446
- return () => /* @__PURE__ */ import_react7.default.createElement(Context, null, /* @__PURE__ */ import_react7.default.createElement(Root, null));
476
+ const Root2 = host.provides.root;
477
+ return () => /* @__PURE__ */ import_react7.default.createElement(Context, null, /* @__PURE__ */ import_react7.default.createElement(Root2, null));
447
478
  };
448
479
  // Annotate the CommonJS export names for ESM import in node:
449
480
  0 && (module.exports = {