@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
@@ -4,10 +4,9 @@ var parseSurfacePlugin = (plugin) => plugin?.provides?.surface?.component ? plug
4
4
 
5
5
  // packages/sdk/app-framework/src/plugins/SurfacePlugin/SurfaceRootContext.tsx
6
6
  import { createContext, useContext } from "react";
7
- var SurfaceRootContext = /* @__PURE__ */ createContext({
8
- components: {}
9
- });
10
- var useSurfaceRoot = () => useContext(SurfaceRootContext);
7
+ import { raise } from "@dxos/debug";
8
+ var SurfaceRootContext = /* @__PURE__ */ createContext(void 0);
9
+ var useSurfaceRoot = () => useContext(SurfaceRootContext) ?? raise(new Error("Missing SurfaceRootContext"));
11
10
  var SurfaceProvider = SurfaceRootContext.Provider;
12
11
 
13
12
  // packages/sdk/app-framework/src/plugins/SurfacePlugin/meta.ts
@@ -23,4 +22,4 @@ export {
23
22
  SurfaceProvider,
24
23
  meta_default
25
24
  };
26
- //# sourceMappingURL=chunk-YYV26N3W.mjs.map
25
+ //# sourceMappingURL=chunk-SB4XRTGZ.mjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/plugins/SurfacePlugin/provides.ts", "../../../src/plugins/SurfacePlugin/SurfaceRootContext.tsx", "../../../src/plugins/SurfacePlugin/meta.ts"],
4
+ "sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { type SurfaceComponent, type SurfaceRootContext } from './SurfaceRootContext';\nimport { type Plugin } from '../PluginHost';\n\nexport type SurfaceProvides = {\n surface: {\n /**\n * Used by the `Surface` resolver to find a component to render.\n */\n component: SurfaceComponent;\n };\n};\n\nexport type SurfacePluginProvides = {\n surface: SurfaceRootContext;\n};\n\nexport const parseRootSurfacePlugin = (plugin?: Plugin) =>\n (plugin?.provides as any)?.surface?.components ? (plugin as Plugin<SurfacePluginProvides>) : undefined;\n\nexport const parseSurfacePlugin = (plugin?: Plugin) =>\n (plugin?.provides as any)?.surface?.component ? (plugin as Plugin<SurfaceProvides>) : undefined;\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { createContext, useContext, type JSX, type ForwardedRef } from 'react';\n\nimport { raise } from '@dxos/debug';\n\nimport { type SurfaceProps } from './Surface';\n\n// TODO(wittjosiah): Factor out.\ntype WithRequiredProperty<Type, Key extends keyof Type> = Type & {\n [Property in Key]-?: Type[Property];\n};\n\ntype SurfaceComponentProps = WithRequiredProperty<SurfaceProps, 'data'>;\n\n/**\n * Determines the priority of the surface when multiple components are resolved.\n */\nexport type SurfaceDisposition = 'hoist' | 'fallback';\n\n/**\n * Surface debug info.\n * NOTE: Short-term measure to track perf issues.\n */\nexport type DebugInfo = {\n id: string;\n created: number;\n renderCount: number;\n} & Pick<SurfaceProps, 'role' | 'name'>;\n\nexport type SurfaceResult = {\n node: JSX.Element;\n disposition?: SurfaceDisposition;\n};\n\n/**\n * Function which resolves a Surface.\n *\n * If a null value is returned, the rendering is deferred to other plugins.\n */\nexport type SurfaceComponent = (\n props: SurfaceComponentProps,\n forwardedRef: ForwardedRef<HTMLElement>,\n) => JSX.Element | SurfaceResult | null;\n\nexport type SurfaceRootContext = {\n components: Record<string, SurfaceComponent>;\n\n /**\n * Debug info.\n */\n debugInfo?: Map<string, DebugInfo>;\n};\n\nconst SurfaceRootContext = createContext<SurfaceRootContext | undefined>(undefined);\n\nexport const useSurfaceRoot = () => useContext(SurfaceRootContext) ?? raise(new Error('Missing SurfaceRootContext'));\n\nexport const SurfaceProvider = SurfaceRootContext.Provider;\n", "//\n// Copyright 2023 DXOS.org\n//\n\nconst SurfaceMeta = {\n id: 'dxos.org/plugin/surface',\n};\n\nexport default SurfaceMeta;\n"],
5
+ "mappings": ";AAoBO,IAAMA,yBAAyB,CAACC,WACpCA,QAAQC,UAAkBC,SAASC,aAAcH,SAA2CI;AAExF,IAAMC,qBAAqB,CAACL,WAChCA,QAAQC,UAAkBC,SAASI,YAAaN,SAAqCI;;;ACpBxF,SAASG,eAAeC,kBAA+C;AAEvE,SAASC,aAAa;AAkDtB,IAAMC,qBAAqBC,8BAA8CC,MAAAA;AAElE,IAAMC,iBAAiB,MAAMC,WAAWJ,kBAAAA,KAAuBK,MAAM,IAAIC,MAAM,4BAAA,CAAA;AAE/E,IAAMC,kBAAkBP,mBAAmBQ;;;ACxDlD,IAAMC,cAAc;EAClBC,IAAI;AACN;AAEA,IAAA,eAAeD;",
6
+ "names": ["parseRootSurfacePlugin", "plugin", "provides", "surface", "components", "undefined", "parseSurfacePlugin", "component", "createContext", "useContext", "raise", "SurfaceRootContext", "createContext", "undefined", "useSurfaceRoot", "useContext", "raise", "Error", "SurfaceProvider", "Provider", "SurfaceMeta", "id"]
7
+ }
@@ -4,7 +4,7 @@ import {
4
4
  parseRootSurfacePlugin,
5
5
  parseSurfacePlugin,
6
6
  useSurfaceRoot
7
- } from "./chunk-YYV26N3W.mjs";
7
+ } from "./chunk-SB4XRTGZ.mjs";
8
8
  import {
9
9
  IntentAction,
10
10
  IntentProvider,
@@ -119,8 +119,8 @@ var parseMetadataResolverPlugin = (plugin) => {
119
119
  };
120
120
 
121
121
  // packages/sdk/app-framework/src/plugins/common/navigation.ts
122
+ import { Schema as S } from "@effect/schema";
122
123
  import { z as z2 } from "zod";
123
- import { S } from "@dxos/echo-schema";
124
124
  var SLUG_LIST_SEPARATOR = "+";
125
125
  var SLUG_ENTRY_SEPARATOR = "_";
126
126
  var SLUG_KEY_VALUE_SEPARATOR = "-";
@@ -131,7 +131,10 @@ var LayoutEntrySchema = S.mutable(S.Struct({
131
131
  path: S.optional(S.String)
132
132
  }));
133
133
  var LayoutPartSchema = S.Union(S.Literal("sidebar"), S.Literal("main"), S.Literal("solo"), S.Literal("complementary"), S.Literal("fullScreen"));
134
- var LayoutPartsSchema = S.partial(S.mutable(S.Record(LayoutPartSchema, S.mutable(S.Array(LayoutEntrySchema)))));
134
+ var LayoutPartsSchema = S.partial(S.mutable(S.Record({
135
+ key: LayoutPartSchema,
136
+ value: S.mutable(S.Array(LayoutEntrySchema))
137
+ })));
135
138
  var LayoutCoordinateSchema = S.mutable(S.Struct({
136
139
  part: LayoutPartSchema,
137
140
  entryId: S.String
@@ -145,9 +148,6 @@ var ActiveParts = z2.record(z2.string(), z2.union([
145
148
  z2.string(),
146
149
  z2.array(z2.string())
147
150
  ]));
148
- var Attention = z2.object({
149
- attended: z2.set(z2.string()).optional().describe("Ids of items which have focus.")
150
- });
151
151
  var LocationProvidesSchema = S.mutable(S.Struct({
152
152
  location: S.Struct({
153
153
  active: LayoutPartsSchema,
@@ -229,7 +229,6 @@ var parseTranslationsPlugin = (plugin) => {
229
229
  };
230
230
 
231
231
  // packages/sdk/app-framework/src/plugins/PluginHost/plugin.ts
232
- var pluginMeta = (meta) => meta;
233
232
  var Plugin;
234
233
  (function(Plugin2) {
235
234
  Plugin2.lazy = (p, props) => {
@@ -241,17 +240,10 @@ var Plugin;
241
240
 
242
241
  // packages/sdk/app-framework/src/plugins/PluginHost/PluginContext.tsx
243
242
  import { createContext, useContext, useMemo } from "react";
243
+ import { raise } from "@dxos/debug";
244
244
  import { nonNullable } from "@dxos/util";
245
- var PluginContext = /* @__PURE__ */ createContext({
246
- ready: false,
247
- core: [],
248
- enabled: [],
249
- plugins: [],
250
- available: [],
251
- setPlugin: () => {
252
- }
253
- });
254
- var usePlugins = () => useContext(PluginContext);
245
+ var PluginContext = /* @__PURE__ */ createContext(void 0);
246
+ var usePlugins = () => useContext(PluginContext) ?? raise(new Error("Missing PluginContext"));
255
247
  var usePlugin = (id) => {
256
248
  const { plugins } = usePlugins();
257
249
  return findPlugin(plugins, id);
@@ -270,15 +262,127 @@ var useResolvePlugins = (predicate) => {
270
262
  var PluginProvider = PluginContext.Provider;
271
263
 
272
264
  // packages/sdk/app-framework/src/plugins/PluginHost/PluginHost.tsx
273
- import React3, { useEffect, useState } from "react";
265
+ import React4 from "react";
274
266
  import { LocalStorageStore } from "@dxos/local-storage";
267
+
268
+ // packages/sdk/app-framework/src/plugins/PluginHost/PluginContainer.tsx
269
+ import React, { useEffect, useState } from "react";
275
270
  import { log } from "@dxos/log";
271
+ var __dxlog_file = "/home/runner/work/dxos/dxos/packages/sdk/app-framework/src/plugins/PluginHost/PluginContainer.tsx";
272
+ var PluginContainer = ({ plugins: definitions, core, state, placeholder }) => {
273
+ const [error, setError] = useState();
274
+ useEffect(() => {
275
+ log("initializing plugins", {
276
+ enabled: state.enabled
277
+ }, {
278
+ F: __dxlog_file,
279
+ L: 26,
280
+ S: void 0,
281
+ C: (f, a) => f(...a)
282
+ });
283
+ const t = setTimeout(async () => {
284
+ try {
285
+ const enabledIds = [
286
+ ...core,
287
+ ...state.enabled
288
+ ];
289
+ const enabled = await Promise.all(enabledIds.map((id) => definitions[id]).filter((definition) => Boolean(definition)).map((definition) => definition()));
290
+ const plugins = await Promise.all(enabled.map(async (definition) => {
291
+ const plugin = await initializePlugin(definition).catch((err) => {
292
+ log.error("Failed to initialize plugin:", {
293
+ id: definition.meta.id,
294
+ err
295
+ }, {
296
+ F: __dxlog_file,
297
+ L: 41,
298
+ S: void 0,
299
+ C: (f, a) => f(...a)
300
+ });
301
+ });
302
+ log("initialized", {
303
+ plugin: definition.meta.id
304
+ }, {
305
+ F: __dxlog_file,
306
+ L: 44,
307
+ S: void 0,
308
+ C: (f, a) => f(...a)
309
+ });
310
+ return plugin;
311
+ }));
312
+ const initialized = plugins.filter((plugin) => Boolean(plugin));
313
+ log("plugins initialized", {
314
+ plugins: initialized
315
+ }, {
316
+ F: __dxlog_file,
317
+ L: 50,
318
+ S: void 0,
319
+ C: (f, a) => f(...a)
320
+ });
321
+ await Promise.all(enabled.map((plugin) => plugin.ready?.(initialized)));
322
+ log("plugins ready", {
323
+ plugins: initialized
324
+ }, {
325
+ F: __dxlog_file,
326
+ L: 53,
327
+ S: void 0,
328
+ C: (f, a) => f(...a)
329
+ });
330
+ state.plugins = initialized;
331
+ state.ready = true;
332
+ } catch (err) {
333
+ setError(err);
334
+ }
335
+ });
336
+ return () => {
337
+ clearTimeout(t);
338
+ state.ready = false;
339
+ };
340
+ }, []);
341
+ if (error) {
342
+ throw error;
343
+ }
344
+ if (!state.ready) {
345
+ return /* @__PURE__ */ React.createElement(React.Fragment, null, placeholder);
346
+ }
347
+ const ComposedContext = composeContext(state.plugins);
348
+ return /* @__PURE__ */ React.createElement(ComposedContext, null, rootComponents(state.plugins));
349
+ };
350
+ var initializePlugin = async (pluginDefinition) => {
351
+ const provides = await pluginDefinition.initialize?.();
352
+ return {
353
+ ...pluginDefinition,
354
+ provides: {
355
+ ...pluginDefinition.provides,
356
+ ...provides
357
+ }
358
+ };
359
+ };
360
+ var rootComponents = (plugins) => {
361
+ return plugins.map((plugin) => {
362
+ const Component2 = plugin.provides.root;
363
+ if (Component2) {
364
+ return /* @__PURE__ */ React.createElement(Component2, {
365
+ key: plugin.meta.id
366
+ });
367
+ } else {
368
+ return null;
369
+ }
370
+ }).filter((node) => Boolean(node));
371
+ };
372
+ var composeContext = (plugins) => {
373
+ return compose(plugins.map((p) => p.provides.context).filter(Boolean));
374
+ };
375
+ var compose = (contexts) => {
376
+ return [
377
+ ...contexts
378
+ ].reduce((Acc, Next) => ({ children }) => /* @__PURE__ */ React.createElement(Acc, null, /* @__PURE__ */ React.createElement(Next, null, children)));
379
+ };
276
380
 
277
381
  // packages/sdk/app-framework/src/plugins/SurfacePlugin/helpers.ts
278
382
  var isObject = (data) => !!data && typeof data === "object";
279
383
 
280
384
  // packages/sdk/app-framework/src/plugins/SurfacePlugin/ErrorBoundary.tsx
281
- import React, { Component } from "react";
385
+ import React2, { Component } from "react";
282
386
  var ErrorBoundary = class extends Component {
283
387
  constructor(props) {
284
388
  super(props);
@@ -298,7 +402,7 @@ var ErrorBoundary = class extends Component {
298
402
  }
299
403
  render() {
300
404
  if (this.state.error) {
301
- return /* @__PURE__ */ React.createElement(this.props.fallback, {
405
+ return /* @__PURE__ */ React2.createElement(this.props.fallback, {
302
406
  data: this.props.data,
303
407
  error: this.state.error,
304
408
  reset: this.resetError
@@ -314,32 +418,50 @@ var ErrorBoundary = class extends Component {
314
418
  };
315
419
 
316
420
  // packages/sdk/app-framework/src/plugins/SurfacePlugin/Surface.tsx
317
- import React2, { forwardRef, Fragment, isValidElement, Suspense } from "react";
318
- import { createContext as createContext2, useContext as useContext2 } from "react";
319
- import { raise } from "@dxos/debug";
320
- var Surface = /* @__PURE__ */ forwardRef(({ role, name = role, fallback, placeholder, ...rest }, forwardedRef) => {
421
+ import React3, { Fragment, Suspense, createContext as createContext2, forwardRef, isValidElement, memo, useContext as useContext2, useEffect as useEffect2, useState as useState2 } from "react";
422
+ import { raise as raise2 } from "@dxos/debug";
423
+ var Surface = /* @__PURE__ */ memo(/* @__PURE__ */ forwardRef(({ role, name = role, fallback, placeholder, ...rest }, forwardedRef) => {
321
424
  const props = {
322
425
  role,
323
426
  name,
324
427
  fallback,
325
428
  ...rest
326
429
  };
430
+ const { debugInfo } = useSurfaceRoot();
431
+ const [id] = useState2(Math.random().toString(36).slice(2));
432
+ useEffect2(() => {
433
+ debugInfo?.set(id, {
434
+ id,
435
+ created: Date.now(),
436
+ name,
437
+ role,
438
+ renderCount: 0
439
+ });
440
+ return () => {
441
+ debugInfo?.delete(id);
442
+ };
443
+ }, [
444
+ id
445
+ ]);
446
+ if (debugInfo?.get(id)) {
447
+ debugInfo.get(id).renderCount++;
448
+ }
327
449
  const context = useContext2(SurfaceContext);
328
450
  const data = props.data ?? (name && context?.surfaces?.[name]?.data || {});
329
- const resolver = /* @__PURE__ */ React2.createElement(SurfaceResolver, {
451
+ const resolver = /* @__PURE__ */ React3.createElement(SurfaceResolver, {
330
452
  ...props,
331
453
  ref: forwardedRef
332
454
  });
333
- const suspense = placeholder ? /* @__PURE__ */ React2.createElement(Suspense, {
455
+ const suspense = placeholder ? /* @__PURE__ */ React3.createElement(Suspense, {
334
456
  fallback: placeholder
335
457
  }, resolver) : resolver;
336
- return fallback ? /* @__PURE__ */ React2.createElement(ErrorBoundary, {
458
+ return fallback ? /* @__PURE__ */ React3.createElement(ErrorBoundary, {
337
459
  data,
338
460
  fallback
339
461
  }, suspense) : suspense;
340
- });
341
- var SurfaceContext = /* @__PURE__ */ createContext2(null);
342
- var useSurface = () => useContext2(SurfaceContext) ?? raise(new Error("Surface context not found"));
462
+ }));
463
+ var SurfaceContext = /* @__PURE__ */ createContext2(void 0);
464
+ var useSurface = () => useContext2(SurfaceContext) ?? raise2(new Error("Surface context not found"));
343
465
  var SurfaceResolver = /* @__PURE__ */ forwardRef((props, forwardedRef) => {
344
466
  const { components } = useSurfaceRoot();
345
467
  const parent = useContext2(SurfaceContext);
@@ -351,7 +473,7 @@ var SurfaceResolver = /* @__PURE__ */ forwardRef((props, forwardedRef) => {
351
473
  ...props.surfaces
352
474
  }
353
475
  };
354
- return /* @__PURE__ */ React2.createElement(SurfaceContext.Provider, {
476
+ return /* @__PURE__ */ React3.createElement(SurfaceContext.Provider, {
355
477
  value: currentContext
356
478
  }, nodes);
357
479
  });
@@ -388,17 +510,16 @@ var resolveNodes = (components, props, context, forwardedRef) => {
388
510
  return 1;
389
511
  }
390
512
  return 0;
391
- }).map(([key, result]) => /* @__PURE__ */ React2.createElement(Fragment, {
513
+ }).map(([key, result]) => /* @__PURE__ */ React3.createElement(Fragment, {
392
514
  key
393
515
  }, result.node));
394
516
  return props.limit ? nodes.slice(0, props.limit) : nodes;
395
517
  };
396
518
 
397
519
  // packages/sdk/app-framework/src/plugins/PluginHost/PluginHost.tsx
398
- var __dxlog_file = "/home/runner/work/dxos/dxos/packages/sdk/app-framework/src/plugins/PluginHost/PluginHost.tsx";
399
520
  var parsePluginHost = (plugin) => plugin.provides.plugins ? plugin : void 0;
400
521
  var PLUGIN_HOST = "dxos.org/plugin/host";
401
- var PluginHost = ({ order, plugins: definitions, core = [], defaults = [], fallback = DefaultFallback, placeholder = null }) => {
522
+ var PluginHost = ({ plugins, meta, core, defaults = [], fallback = DefaultFallback, placeholder = null }) => {
402
523
  const state = new LocalStorageStore(PLUGIN_HOST, {
403
524
  ready: false,
404
525
  core,
@@ -406,7 +527,7 @@ var PluginHost = ({ order, plugins: definitions, core = [], defaults = [], fallb
406
527
  ...defaults
407
528
  ],
408
529
  plugins: [],
409
- available: order.filter(({ id }) => !core.includes(id)),
530
+ available: meta.filter(({ id }) => !core.includes(id)),
410
531
  setPlugin: (id, enabled) => {
411
532
  if (enabled) {
412
533
  state.values.enabled.push(id);
@@ -427,16 +548,17 @@ var PluginHost = ({ order, plugins: definitions, core = [], defaults = [], fallb
427
548
  },
428
549
  provides: {
429
550
  plugins: state.values,
430
- context: ({ children }) => /* @__PURE__ */ React3.createElement(PluginProvider, {
431
- value: state.values
432
- }, children),
551
+ context: ({ children }) => {
552
+ return /* @__PURE__ */ React4.createElement(PluginProvider, {
553
+ value: state.values
554
+ }, children);
555
+ },
433
556
  root: () => {
434
- return /* @__PURE__ */ React3.createElement(ErrorBoundary, {
557
+ return /* @__PURE__ */ React4.createElement(ErrorBoundary, {
435
558
  fallback
436
- }, /* @__PURE__ */ React3.createElement(Root, {
437
- order,
559
+ }, /* @__PURE__ */ React4.createElement(PluginContainer, {
560
+ plugins,
438
561
  core,
439
- definitions,
440
562
  state: state.values,
441
563
  placeholder
442
564
  }));
@@ -445,139 +567,36 @@ var PluginHost = ({ order, plugins: definitions, core = [], defaults = [], fallb
445
567
  };
446
568
  };
447
569
  var DefaultFallback = ({ error }) => {
448
- return /* @__PURE__ */ React3.createElement("div", {
570
+ return /* @__PURE__ */ React4.createElement("div", {
449
571
  style: {
450
572
  padding: "1rem"
451
573
  }
452
- }, /* @__PURE__ */ React3.createElement("h1", {
574
+ }, /* @__PURE__ */ React4.createElement("h1", {
453
575
  style: {
454
576
  fontSize: "1.2rem",
455
577
  fontWeight: 700,
456
578
  margin: "0.5rem 0"
457
579
  }
458
- }, error.message), /* @__PURE__ */ React3.createElement("pre", null, error.stack));
459
- };
460
- var Root = ({ order, core: corePluginIds, definitions, state, placeholder }) => {
461
- const [error, setError] = useState();
462
- useEffect(() => {
463
- log("initializing plugins", {
464
- enabled: state.enabled
465
- }, {
466
- F: __dxlog_file,
467
- L: 102,
468
- S: void 0,
469
- C: (f, a) => f(...a)
470
- });
471
- const timeout = setTimeout(async () => {
472
- try {
473
- const enabledIds = [
474
- ...corePluginIds,
475
- ...state.enabled
476
- ].sort((a, b) => {
477
- const indexA = order.findIndex(({ id }) => id === a);
478
- const indexB = order.findIndex(({ id }) => id === b);
479
- return indexA - indexB;
480
- });
481
- const enabled = await Promise.all(enabledIds.map((id) => definitions[id]).filter((definition) => Boolean(definition)).map((definition) => definition()));
482
- const plugins = await Promise.all(enabled.map(async (definition) => {
483
- const plugin = await initializePlugin(definition).catch((err) => {
484
- log.error("Failed to initialize plugin:", {
485
- id: definition.meta.id,
486
- err
487
- }, {
488
- F: __dxlog_file,
489
- L: 122,
490
- S: void 0,
491
- C: (f, a) => f(...a)
492
- });
493
- return void 0;
494
- });
495
- return plugin;
496
- })).then((plugins2) => plugins2.filter((plugin) => Boolean(plugin)));
497
- log("plugins initialized", {
498
- plugins
499
- }, {
500
- F: __dxlog_file,
501
- L: 128,
502
- S: void 0,
503
- C: (f, a) => f(...a)
504
- });
505
- await Promise.all(enabled.map((pluginDefinition) => pluginDefinition.ready?.(plugins)));
506
- log("plugins ready", {
507
- plugins
508
- }, {
509
- F: __dxlog_file,
510
- L: 131,
511
- S: void 0,
512
- C: (f, a) => f(...a)
513
- });
514
- state.plugins = plugins;
515
- state.ready = true;
516
- } catch (err) {
517
- setError(err);
518
- }
519
- });
520
- return () => {
521
- clearTimeout(timeout);
522
- state.ready = false;
523
- };
524
- }, []);
525
- if (error) {
526
- throw error;
527
- }
528
- if (!state.ready) {
529
- return /* @__PURE__ */ React3.createElement(React3.Fragment, null, placeholder);
530
- }
531
- const ComposedContext = composeContext(state.plugins);
532
- return /* @__PURE__ */ React3.createElement(ComposedContext, null, rootComponents(state.plugins));
533
- };
534
- var initializePlugin = async (pluginDefinition) => {
535
- const provides = await pluginDefinition.initialize?.();
536
- return {
537
- ...pluginDefinition,
538
- provides: {
539
- ...pluginDefinition.provides,
540
- ...provides
541
- }
542
- };
543
- };
544
- var rootComponents = (plugins) => {
545
- return plugins.map((plugin) => {
546
- const Component2 = plugin.provides.root;
547
- if (Component2) {
548
- return /* @__PURE__ */ React3.createElement(Component2, {
549
- key: plugin.meta.id
550
- });
551
- } else {
552
- return null;
553
- }
554
- }).filter((node) => Boolean(node));
555
- };
556
- var composeContext = (plugins) => {
557
- return compose(plugins.map((p) => p.provides.context).filter(Boolean));
558
- };
559
- var compose = (contexts) => {
560
- return [
561
- ...contexts
562
- ].reduce((Acc, Next) => ({ children }) => /* @__PURE__ */ React3.createElement(Acc, null, /* @__PURE__ */ React3.createElement(Next, null, children)));
580
+ }, error.message), /* @__PURE__ */ React4.createElement("pre", null, error.stack));
563
581
  };
564
582
 
565
583
  // packages/sdk/app-framework/src/App.tsx
566
- import React4 from "react";
584
+ import React5 from "react";
567
585
  import { invariant } from "@dxos/invariant";
568
586
  var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/sdk/app-framework/src/App.tsx";
569
- var createApp = ({ order, plugins, core = order.map(({ id }) => id), ...params }) => {
587
+ var createApp = ({ meta, plugins, core, ...params }) => {
570
588
  const host = PluginHost({
571
- order: [
572
- meta_default2,
573
- meta_default,
574
- ...order
575
- ],
576
589
  plugins: {
577
590
  ...plugins,
578
- [meta_default2.id]: Plugin.lazy(() => import("./plugin-K3KCPCTJ.mjs")),
591
+ [meta_default2.id]: Plugin.lazy(() => import("./plugin-Y4KRQJE4.mjs")),
579
592
  [meta_default.id]: Plugin.lazy(() => import("./plugin-MM66VRCO.mjs"))
580
593
  },
594
+ // TODO(burdon): Why not include in core?
595
+ meta: [
596
+ meta_default2,
597
+ meta_default,
598
+ ...meta
599
+ ],
581
600
  core: [
582
601
  meta_default2.id,
583
602
  meta_default.id,
@@ -585,31 +604,38 @@ var createApp = ({ order, plugins, core = order.map(({ id }) => id), ...params }
585
604
  ],
586
605
  ...params
587
606
  });
588
- invariant(host.provides?.context, void 0, {
607
+ invariant(host.provides, void 0, {
589
608
  F: __dxlog_file2,
590
- L: 51,
609
+ L: 52,
591
610
  S: void 0,
592
611
  A: [
593
- "host.provides?.context",
612
+ "host.provides",
594
613
  ""
595
614
  ]
596
615
  });
597
- invariant(host.provides?.root, void 0, {
616
+ const { context: Context, root: Root } = host.provides;
617
+ invariant(Context, void 0, {
598
618
  F: __dxlog_file2,
599
- L: 52,
619
+ L: 54,
620
+ S: void 0,
621
+ A: [
622
+ "Context",
623
+ ""
624
+ ]
625
+ });
626
+ invariant(Root, void 0, {
627
+ F: __dxlog_file2,
628
+ L: 55,
600
629
  S: void 0,
601
630
  A: [
602
- "host.provides?.root",
631
+ "Root",
603
632
  ""
604
633
  ]
605
634
  });
606
- const Context = host.provides.context;
607
- const Root2 = host.provides.root;
608
- return () => /* @__PURE__ */ React4.createElement(Context, null, /* @__PURE__ */ React4.createElement(Root2, null));
635
+ return () => /* @__PURE__ */ React5.createElement(Context, null, /* @__PURE__ */ React5.createElement(Root, null));
609
636
  };
610
637
  export {
611
638
  ActiveParts,
612
- Attention,
613
639
  ErrorBoundary,
614
640
  IntentAction,
615
641
  IntentProvider,
@@ -639,7 +665,6 @@ export {
639
665
  firstIdInPart,
640
666
  getPlugin,
641
667
  indexInPart,
642
- initializePlugin,
643
668
  isLayoutAdjustment,
644
669
  isLayoutMode,
645
670
  isLayoutParts,
@@ -661,7 +686,6 @@ export {
661
686
  parseSurfacePlugin,
662
687
  parseTranslationsPlugin,
663
688
  partLength,
664
- pluginMeta,
665
689
  resolvePlugin,
666
690
  useIntent,
667
691
  useIntentDispatcher,