@dxos/app-framework 0.6.12-main.15a606f → 0.6.12-main.2d19bf1

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 (31) hide show
  1. package/dist/lib/browser/index.mjs +169 -163
  2. package/dist/lib/browser/index.mjs.map +4 -4
  3. package/dist/lib/browser/meta.json +1 -1
  4. package/dist/lib/node/index.cjs +183 -182
  5. package/dist/lib/node/index.cjs.map +4 -4
  6. package/dist/lib/node/meta.json +1 -1
  7. package/dist/lib/node-esm/index.mjs +169 -163
  8. package/dist/lib/node-esm/index.mjs.map +4 -4
  9. package/dist/lib/node-esm/meta.json +1 -1
  10. package/dist/types/src/App.d.ts +4 -4
  11. package/dist/types/src/App.d.ts.map +1 -1
  12. package/dist/types/src/plugins/PluginHost/PluginContainer.d.ts +14 -0
  13. package/dist/types/src/plugins/PluginHost/PluginContainer.d.ts.map +1 -0
  14. package/dist/types/src/plugins/PluginHost/PluginContext.d.ts +4 -4
  15. package/dist/types/src/plugins/PluginHost/PluginContext.d.ts.map +1 -1
  16. package/dist/types/src/plugins/PluginHost/PluginHost.d.ts +4 -8
  17. package/dist/types/src/plugins/PluginHost/PluginHost.d.ts.map +1 -1
  18. package/dist/types/src/plugins/PluginHost/plugin.d.ts +37 -72
  19. package/dist/types/src/plugins/PluginHost/plugin.d.ts.map +1 -1
  20. package/dist/types/src/plugins/common/navigation.d.ts +1 -12
  21. package/dist/types/src/plugins/common/navigation.d.ts.map +1 -1
  22. package/package.json +12 -10
  23. package/project.json +2 -1
  24. package/src/App.tsx +10 -9
  25. package/src/plugins/PluginHost/PluginContainer.tsx +120 -0
  26. package/src/plugins/PluginHost/PluginContext.tsx +8 -14
  27. package/src/plugins/PluginHost/PluginHost.tsx +18 -121
  28. package/src/plugins/PluginHost/plugin.ts +45 -45
  29. package/src/plugins/common/navigation.ts +4 -11
  30. package/tsconfig.json +1 -29
  31. package/vitest.config.ts +1 -1
@@ -120,8 +120,8 @@ var parseMetadataResolverPlugin = (plugin) => {
120
120
  };
121
121
 
122
122
  // packages/sdk/app-framework/src/plugins/common/navigation.ts
123
+ import { Schema as S } from "@effect/schema";
123
124
  import { z as z2 } from "zod";
124
- import { S } from "@dxos/echo-schema";
125
125
  var SLUG_LIST_SEPARATOR = "+";
126
126
  var SLUG_ENTRY_SEPARATOR = "_";
127
127
  var SLUG_KEY_VALUE_SEPARATOR = "-";
@@ -132,7 +132,10 @@ var LayoutEntrySchema = S.mutable(S.Struct({
132
132
  path: S.optional(S.String)
133
133
  }));
134
134
  var LayoutPartSchema = S.Union(S.Literal("sidebar"), S.Literal("main"), S.Literal("solo"), S.Literal("complementary"), S.Literal("fullScreen"));
135
- var LayoutPartsSchema = S.partial(S.mutable(S.Record(LayoutPartSchema, S.mutable(S.Array(LayoutEntrySchema)))));
135
+ var LayoutPartsSchema = S.partial(S.mutable(S.Record({
136
+ key: LayoutPartSchema,
137
+ value: S.mutable(S.Array(LayoutEntrySchema))
138
+ })));
136
139
  var LayoutCoordinateSchema = S.mutable(S.Struct({
137
140
  part: LayoutPartSchema,
138
141
  entryId: S.String
@@ -146,9 +149,6 @@ var ActiveParts = z2.record(z2.string(), z2.union([
146
149
  z2.string(),
147
150
  z2.array(z2.string())
148
151
  ]));
149
- var Attention = z2.object({
150
- attended: z2.set(z2.string()).describe("Ids of items which have focus.")
151
- });
152
152
  var LocationProvidesSchema = S.mutable(S.Struct({
153
153
  location: S.Struct({
154
154
  active: LayoutPartsSchema,
@@ -230,7 +230,6 @@ var parseTranslationsPlugin = (plugin) => {
230
230
  };
231
231
 
232
232
  // packages/sdk/app-framework/src/plugins/PluginHost/plugin.ts
233
- var pluginMeta = (meta) => meta;
234
233
  var Plugin;
235
234
  (function(Plugin2) {
236
235
  Plugin2.lazy = (p, props) => {
@@ -242,17 +241,10 @@ var Plugin;
242
241
 
243
242
  // packages/sdk/app-framework/src/plugins/PluginHost/PluginContext.tsx
244
243
  import { createContext, useContext, useMemo } from "react";
244
+ import { raise } from "@dxos/debug";
245
245
  import { nonNullable } from "@dxos/util";
246
- var PluginContext = /* @__PURE__ */ createContext({
247
- ready: false,
248
- core: [],
249
- enabled: [],
250
- plugins: [],
251
- available: [],
252
- setPlugin: () => {
253
- }
254
- });
255
- var usePlugins = () => useContext(PluginContext);
246
+ var PluginContext = /* @__PURE__ */ createContext(void 0);
247
+ var usePlugins = () => useContext(PluginContext) ?? raise(new Error("Missing PluginContext"));
256
248
  var usePlugin = (id) => {
257
249
  const { plugins } = usePlugins();
258
250
  return findPlugin(plugins, id);
@@ -271,15 +263,127 @@ var useResolvePlugins = (predicate) => {
271
263
  var PluginProvider = PluginContext.Provider;
272
264
 
273
265
  // packages/sdk/app-framework/src/plugins/PluginHost/PluginHost.tsx
274
- import React3, { useEffect, useState } from "react";
266
+ import React4 from "react";
275
267
  import { LocalStorageStore } from "@dxos/local-storage";
268
+
269
+ // packages/sdk/app-framework/src/plugins/PluginHost/PluginContainer.tsx
270
+ import React, { useEffect, useState } from "react";
276
271
  import { log } from "@dxos/log";
272
+ var __dxlog_file = "/home/runner/work/dxos/dxos/packages/sdk/app-framework/src/plugins/PluginHost/PluginContainer.tsx";
273
+ var PluginContainer = ({ plugins: definitions, core, state, placeholder }) => {
274
+ const [error, setError] = useState();
275
+ useEffect(() => {
276
+ log("initializing plugins", {
277
+ enabled: state.enabled
278
+ }, {
279
+ F: __dxlog_file,
280
+ L: 26,
281
+ S: void 0,
282
+ C: (f, a) => f(...a)
283
+ });
284
+ const t = setTimeout(async () => {
285
+ try {
286
+ const enabledIds = [
287
+ ...core,
288
+ ...state.enabled
289
+ ];
290
+ const enabled = await Promise.all(enabledIds.map((id) => definitions[id]).filter((definition) => Boolean(definition)).map((definition) => definition()));
291
+ const plugins = await Promise.all(enabled.map(async (definition) => {
292
+ const plugin = await initializePlugin(definition).catch((err) => {
293
+ log.error("Failed to initialize plugin:", {
294
+ id: definition.meta.id,
295
+ err
296
+ }, {
297
+ F: __dxlog_file,
298
+ L: 41,
299
+ S: void 0,
300
+ C: (f, a) => f(...a)
301
+ });
302
+ });
303
+ log("initialized", {
304
+ plugin: definition.meta.id
305
+ }, {
306
+ F: __dxlog_file,
307
+ L: 44,
308
+ S: void 0,
309
+ C: (f, a) => f(...a)
310
+ });
311
+ return plugin;
312
+ }));
313
+ const initialized = plugins.filter((plugin) => Boolean(plugin));
314
+ log("plugins initialized", {
315
+ plugins: initialized
316
+ }, {
317
+ F: __dxlog_file,
318
+ L: 50,
319
+ S: void 0,
320
+ C: (f, a) => f(...a)
321
+ });
322
+ await Promise.all(enabled.map((plugin) => plugin.ready?.(initialized)));
323
+ log("plugins ready", {
324
+ plugins: initialized
325
+ }, {
326
+ F: __dxlog_file,
327
+ L: 53,
328
+ S: void 0,
329
+ C: (f, a) => f(...a)
330
+ });
331
+ state.plugins = initialized;
332
+ state.ready = true;
333
+ } catch (err) {
334
+ setError(err);
335
+ }
336
+ });
337
+ return () => {
338
+ clearTimeout(t);
339
+ state.ready = false;
340
+ };
341
+ }, []);
342
+ if (error) {
343
+ throw error;
344
+ }
345
+ if (!state.ready) {
346
+ return /* @__PURE__ */ React.createElement(React.Fragment, null, placeholder);
347
+ }
348
+ const ComposedContext = composeContext(state.plugins);
349
+ return /* @__PURE__ */ React.createElement(ComposedContext, null, rootComponents(state.plugins));
350
+ };
351
+ var initializePlugin = async (pluginDefinition) => {
352
+ const provides = await pluginDefinition.initialize?.();
353
+ return {
354
+ ...pluginDefinition,
355
+ provides: {
356
+ ...pluginDefinition.provides,
357
+ ...provides
358
+ }
359
+ };
360
+ };
361
+ var rootComponents = (plugins) => {
362
+ return plugins.map((plugin) => {
363
+ const Component2 = plugin.provides.root;
364
+ if (Component2) {
365
+ return /* @__PURE__ */ React.createElement(Component2, {
366
+ key: plugin.meta.id
367
+ });
368
+ } else {
369
+ return null;
370
+ }
371
+ }).filter((node) => Boolean(node));
372
+ };
373
+ var composeContext = (plugins) => {
374
+ return compose(plugins.map((p) => p.provides.context).filter(Boolean));
375
+ };
376
+ var compose = (contexts) => {
377
+ return [
378
+ ...contexts
379
+ ].reduce((Acc, Next) => ({ children }) => /* @__PURE__ */ React.createElement(Acc, null, /* @__PURE__ */ React.createElement(Next, null, children)));
380
+ };
277
381
 
278
382
  // packages/sdk/app-framework/src/plugins/SurfacePlugin/helpers.ts
279
383
  var isObject = (data) => !!data && typeof data === "object";
280
384
 
281
385
  // packages/sdk/app-framework/src/plugins/SurfacePlugin/ErrorBoundary.tsx
282
- import React, { Component } from "react";
386
+ import React2, { Component } from "react";
283
387
  var ErrorBoundary = class extends Component {
284
388
  constructor(props) {
285
389
  super(props);
@@ -299,7 +403,7 @@ var ErrorBoundary = class extends Component {
299
403
  }
300
404
  render() {
301
405
  if (this.state.error) {
302
- return /* @__PURE__ */ React.createElement(this.props.fallback, {
406
+ return /* @__PURE__ */ React2.createElement(this.props.fallback, {
303
407
  data: this.props.data,
304
408
  error: this.state.error,
305
409
  reset: this.resetError
@@ -315,9 +419,9 @@ var ErrorBoundary = class extends Component {
315
419
  };
316
420
 
317
421
  // packages/sdk/app-framework/src/plugins/SurfacePlugin/Surface.tsx
318
- import React2, { forwardRef, Fragment, isValidElement, Suspense } from "react";
422
+ import React3, { forwardRef, Fragment, isValidElement, Suspense } from "react";
319
423
  import { createContext as createContext2, useContext as useContext2 } from "react";
320
- import { raise } from "@dxos/debug";
424
+ import { raise as raise2 } from "@dxos/debug";
321
425
  var Surface = /* @__PURE__ */ forwardRef(({ role, name = role, fallback, placeholder, ...rest }, forwardedRef) => {
322
426
  const props = {
323
427
  role,
@@ -327,20 +431,20 @@ var Surface = /* @__PURE__ */ forwardRef(({ role, name = role, fallback, placeho
327
431
  };
328
432
  const context = useContext2(SurfaceContext);
329
433
  const data = props.data ?? (name && context?.surfaces?.[name]?.data || {});
330
- const resolver = /* @__PURE__ */ React2.createElement(SurfaceResolver, {
434
+ const resolver = /* @__PURE__ */ React3.createElement(SurfaceResolver, {
331
435
  ...props,
332
436
  ref: forwardedRef
333
437
  });
334
- const suspense = placeholder ? /* @__PURE__ */ React2.createElement(Suspense, {
438
+ const suspense = placeholder ? /* @__PURE__ */ React3.createElement(Suspense, {
335
439
  fallback: placeholder
336
440
  }, resolver) : resolver;
337
- return fallback ? /* @__PURE__ */ React2.createElement(ErrorBoundary, {
441
+ return fallback ? /* @__PURE__ */ React3.createElement(ErrorBoundary, {
338
442
  data,
339
443
  fallback
340
444
  }, suspense) : suspense;
341
445
  });
342
446
  var SurfaceContext = /* @__PURE__ */ createContext2(null);
343
- var useSurface = () => useContext2(SurfaceContext) ?? raise(new Error("Surface context not found"));
447
+ var useSurface = () => useContext2(SurfaceContext) ?? raise2(new Error("Surface context not found"));
344
448
  var SurfaceResolver = /* @__PURE__ */ forwardRef((props, forwardedRef) => {
345
449
  const { components } = useSurfaceRoot();
346
450
  const parent = useContext2(SurfaceContext);
@@ -352,7 +456,7 @@ var SurfaceResolver = /* @__PURE__ */ forwardRef((props, forwardedRef) => {
352
456
  ...props.surfaces
353
457
  }
354
458
  };
355
- return /* @__PURE__ */ React2.createElement(SurfaceContext.Provider, {
459
+ return /* @__PURE__ */ React3.createElement(SurfaceContext.Provider, {
356
460
  value: currentContext
357
461
  }, nodes);
358
462
  });
@@ -389,17 +493,16 @@ var resolveNodes = (components, props, context, forwardedRef) => {
389
493
  return 1;
390
494
  }
391
495
  return 0;
392
- }).map(([key, result]) => /* @__PURE__ */ React2.createElement(Fragment, {
496
+ }).map(([key, result]) => /* @__PURE__ */ React3.createElement(Fragment, {
393
497
  key
394
498
  }, result.node));
395
499
  return props.limit ? nodes.slice(0, props.limit) : nodes;
396
500
  };
397
501
 
398
502
  // packages/sdk/app-framework/src/plugins/PluginHost/PluginHost.tsx
399
- var __dxlog_file = "/home/runner/work/dxos/dxos/packages/sdk/app-framework/src/plugins/PluginHost/PluginHost.tsx";
400
503
  var parsePluginHost = (plugin) => plugin.provides.plugins ? plugin : void 0;
401
504
  var PLUGIN_HOST = "dxos.org/plugin/host";
402
- var PluginHost = ({ order, plugins: definitions, core = [], defaults = [], fallback = DefaultFallback, placeholder = null }) => {
505
+ var PluginHost = ({ plugins, meta, core, defaults = [], fallback = DefaultFallback, placeholder = null }) => {
403
506
  const state = new LocalStorageStore(PLUGIN_HOST, {
404
507
  ready: false,
405
508
  core,
@@ -407,7 +510,7 @@ var PluginHost = ({ order, plugins: definitions, core = [], defaults = [], fallb
407
510
  ...defaults
408
511
  ],
409
512
  plugins: [],
410
- available: order.filter(({ id }) => !core.includes(id)),
513
+ available: meta.filter(({ id }) => !core.includes(id)),
411
514
  setPlugin: (id, enabled) => {
412
515
  if (enabled) {
413
516
  state.values.enabled.push(id);
@@ -428,16 +531,17 @@ var PluginHost = ({ order, plugins: definitions, core = [], defaults = [], fallb
428
531
  },
429
532
  provides: {
430
533
  plugins: state.values,
431
- context: ({ children }) => /* @__PURE__ */ React3.createElement(PluginProvider, {
432
- value: state.values
433
- }, children),
534
+ context: ({ children }) => {
535
+ return /* @__PURE__ */ React4.createElement(PluginProvider, {
536
+ value: state.values
537
+ }, children);
538
+ },
434
539
  root: () => {
435
- return /* @__PURE__ */ React3.createElement(ErrorBoundary, {
540
+ return /* @__PURE__ */ React4.createElement(ErrorBoundary, {
436
541
  fallback
437
- }, /* @__PURE__ */ React3.createElement(Root, {
438
- order,
542
+ }, /* @__PURE__ */ React4.createElement(PluginContainer, {
543
+ plugins,
439
544
  core,
440
- definitions,
441
545
  state: state.values,
442
546
  placeholder
443
547
  }));
@@ -446,139 +550,36 @@ var PluginHost = ({ order, plugins: definitions, core = [], defaults = [], fallb
446
550
  };
447
551
  };
448
552
  var DefaultFallback = ({ error }) => {
449
- return /* @__PURE__ */ React3.createElement("div", {
553
+ return /* @__PURE__ */ React4.createElement("div", {
450
554
  style: {
451
555
  padding: "1rem"
452
556
  }
453
- }, /* @__PURE__ */ React3.createElement("h1", {
557
+ }, /* @__PURE__ */ React4.createElement("h1", {
454
558
  style: {
455
559
  fontSize: "1.2rem",
456
560
  fontWeight: 700,
457
561
  margin: "0.5rem 0"
458
562
  }
459
- }, error.message), /* @__PURE__ */ React3.createElement("pre", null, error.stack));
460
- };
461
- var Root = ({ order, core: corePluginIds, definitions, state, placeholder }) => {
462
- const [error, setError] = useState();
463
- useEffect(() => {
464
- log("initializing plugins", {
465
- enabled: state.enabled
466
- }, {
467
- F: __dxlog_file,
468
- L: 102,
469
- S: void 0,
470
- C: (f, a) => f(...a)
471
- });
472
- const timeout = setTimeout(async () => {
473
- try {
474
- const enabledIds = [
475
- ...corePluginIds,
476
- ...state.enabled
477
- ].sort((a, b) => {
478
- const indexA = order.findIndex(({ id }) => id === a);
479
- const indexB = order.findIndex(({ id }) => id === b);
480
- return indexA - indexB;
481
- });
482
- const enabled = await Promise.all(enabledIds.map((id) => definitions[id]).filter((definition) => Boolean(definition)).map((definition) => definition()));
483
- const plugins = await Promise.all(enabled.map(async (definition) => {
484
- const plugin = await initializePlugin(definition).catch((err) => {
485
- log.error("Failed to initialize plugin:", {
486
- id: definition.meta.id,
487
- err
488
- }, {
489
- F: __dxlog_file,
490
- L: 122,
491
- S: void 0,
492
- C: (f, a) => f(...a)
493
- });
494
- return void 0;
495
- });
496
- return plugin;
497
- })).then((plugins2) => plugins2.filter((plugin) => Boolean(plugin)));
498
- log("plugins initialized", {
499
- plugins
500
- }, {
501
- F: __dxlog_file,
502
- L: 128,
503
- S: void 0,
504
- C: (f, a) => f(...a)
505
- });
506
- await Promise.all(enabled.map((pluginDefinition) => pluginDefinition.ready?.(plugins)));
507
- log("plugins ready", {
508
- plugins
509
- }, {
510
- F: __dxlog_file,
511
- L: 131,
512
- S: void 0,
513
- C: (f, a) => f(...a)
514
- });
515
- state.plugins = plugins;
516
- state.ready = true;
517
- } catch (err) {
518
- setError(err);
519
- }
520
- });
521
- return () => {
522
- clearTimeout(timeout);
523
- state.ready = false;
524
- };
525
- }, []);
526
- if (error) {
527
- throw error;
528
- }
529
- if (!state.ready) {
530
- return /* @__PURE__ */ React3.createElement(React3.Fragment, null, placeholder);
531
- }
532
- const ComposedContext = composeContext(state.plugins);
533
- return /* @__PURE__ */ React3.createElement(ComposedContext, null, rootComponents(state.plugins));
534
- };
535
- var initializePlugin = async (pluginDefinition) => {
536
- const provides = await pluginDefinition.initialize?.();
537
- return {
538
- ...pluginDefinition,
539
- provides: {
540
- ...pluginDefinition.provides,
541
- ...provides
542
- }
543
- };
544
- };
545
- var rootComponents = (plugins) => {
546
- return plugins.map((plugin) => {
547
- const Component2 = plugin.provides.root;
548
- if (Component2) {
549
- return /* @__PURE__ */ React3.createElement(Component2, {
550
- key: plugin.meta.id
551
- });
552
- } else {
553
- return null;
554
- }
555
- }).filter((node) => Boolean(node));
556
- };
557
- var composeContext = (plugins) => {
558
- return compose(plugins.map((p) => p.provides.context).filter(Boolean));
559
- };
560
- var compose = (contexts) => {
561
- return [
562
- ...contexts
563
- ].reduce((Acc, Next) => ({ children }) => /* @__PURE__ */ React3.createElement(Acc, null, /* @__PURE__ */ React3.createElement(Next, null, children)));
563
+ }, error.message), /* @__PURE__ */ React4.createElement("pre", null, error.stack));
564
564
  };
565
565
 
566
566
  // packages/sdk/app-framework/src/App.tsx
567
- import React4 from "react";
567
+ import React5 from "react";
568
568
  import { invariant } from "@dxos/invariant";
569
569
  var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/sdk/app-framework/src/App.tsx";
570
- var createApp = ({ order, plugins, core = order.map(({ id }) => id), ...params }) => {
570
+ var createApp = ({ meta, plugins, core, ...params }) => {
571
571
  const host = PluginHost({
572
- order: [
573
- meta_default2,
574
- meta_default,
575
- ...order
576
- ],
577
572
  plugins: {
578
573
  ...plugins,
579
574
  [meta_default2.id]: Plugin.lazy(() => import("./plugin-24ZP3LDU.mjs")),
580
575
  [meta_default.id]: Plugin.lazy(() => import("./plugin-5AAUGDB3.mjs"))
581
576
  },
577
+ // TODO(burdon): Why not include in core?
578
+ meta: [
579
+ meta_default2,
580
+ meta_default,
581
+ ...meta
582
+ ],
582
583
  core: [
583
584
  meta_default2.id,
584
585
  meta_default.id,
@@ -586,31 +587,38 @@ var createApp = ({ order, plugins, core = order.map(({ id }) => id), ...params }
586
587
  ],
587
588
  ...params
588
589
  });
589
- invariant(host.provides?.context, void 0, {
590
+ invariant(host.provides, void 0, {
590
591
  F: __dxlog_file2,
591
- L: 51,
592
+ L: 52,
592
593
  S: void 0,
593
594
  A: [
594
- "host.provides?.context",
595
+ "host.provides",
595
596
  ""
596
597
  ]
597
598
  });
598
- invariant(host.provides?.root, void 0, {
599
+ const { context: Context, root: Root } = host.provides;
600
+ invariant(Context, void 0, {
599
601
  F: __dxlog_file2,
600
- L: 52,
602
+ L: 54,
603
+ S: void 0,
604
+ A: [
605
+ "Context",
606
+ ""
607
+ ]
608
+ });
609
+ invariant(Root, void 0, {
610
+ F: __dxlog_file2,
611
+ L: 55,
601
612
  S: void 0,
602
613
  A: [
603
- "host.provides?.root",
614
+ "Root",
604
615
  ""
605
616
  ]
606
617
  });
607
- const Context = host.provides.context;
608
- const Root2 = host.provides.root;
609
- return () => /* @__PURE__ */ React4.createElement(Context, null, /* @__PURE__ */ React4.createElement(Root2, null));
618
+ return () => /* @__PURE__ */ React5.createElement(Context, null, /* @__PURE__ */ React5.createElement(Root, null));
610
619
  };
611
620
  export {
612
621
  ActiveParts,
613
- Attention,
614
622
  ErrorBoundary,
615
623
  IntentAction,
616
624
  IntentProvider,
@@ -640,7 +648,6 @@ export {
640
648
  firstIdInPart,
641
649
  getPlugin,
642
650
  indexInPart,
643
- initializePlugin,
644
651
  isLayoutAdjustment,
645
652
  isLayoutMode,
646
653
  isLayoutParts,
@@ -662,7 +669,6 @@ export {
662
669
  parseSurfacePlugin,
663
670
  parseTranslationsPlugin,
664
671
  partLength,
665
- pluginMeta,
666
672
  resolvePlugin,
667
673
  useIntent,
668
674
  useIntentDispatcher,