@dxos/app-framework 0.7.5-main.9d2a38b → 0.7.5-main.e94eead

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 (205) hide show
  1. package/dist/lib/browser/app-graph-builder-S4MYSHQA.mjs +137 -0
  2. package/dist/lib/browser/app-graph-builder-S4MYSHQA.mjs.map +7 -0
  3. package/dist/lib/browser/{chunk-GNLU3GAU.mjs → chunk-BCMEJONP.mjs} +660 -823
  4. package/dist/lib/browser/chunk-BCMEJONP.mjs.map +7 -0
  5. package/dist/lib/browser/chunk-QS4J6O47.mjs +285 -0
  6. package/dist/lib/browser/chunk-QS4J6O47.mjs.map +7 -0
  7. package/dist/lib/browser/chunk-SRZH2PQ2.mjs +32 -0
  8. package/dist/lib/browser/chunk-SRZH2PQ2.mjs.map +7 -0
  9. package/dist/lib/browser/index.mjs +57 -74
  10. package/dist/lib/browser/index.mjs.map +4 -4
  11. package/dist/lib/browser/intent-dispatcher-GFBH7T2J.mjs +11 -0
  12. package/dist/lib/browser/intent-dispatcher-GFBH7T2J.mjs.map +7 -0
  13. package/dist/lib/browser/intent-resolver-KAFM7CQH.mjs +39 -0
  14. package/dist/lib/browser/intent-resolver-KAFM7CQH.mjs.map +7 -0
  15. package/dist/lib/browser/meta.json +1 -1
  16. package/dist/lib/browser/store-L3VRR7II.mjs +29 -0
  17. package/dist/lib/browser/store-L3VRR7II.mjs.map +7 -0
  18. package/dist/lib/browser/testing/index.mjs +13 -3
  19. package/dist/lib/browser/testing/index.mjs.map +3 -3
  20. package/dist/lib/browser/worker.mjs +77 -0
  21. package/dist/lib/browser/worker.mjs.map +7 -0
  22. package/dist/lib/node/app-graph-builder-VMHWFCTP.cjs +146 -0
  23. package/dist/lib/node/app-graph-builder-VMHWFCTP.cjs.map +7 -0
  24. package/dist/lib/node/chunk-7Y6KJ3OK.cjs +1466 -0
  25. package/dist/lib/node/chunk-7Y6KJ3OK.cjs.map +7 -0
  26. package/dist/lib/node/chunk-B65NJEIJ.cjs +308 -0
  27. package/dist/lib/node/chunk-B65NJEIJ.cjs.map +7 -0
  28. package/dist/lib/node/chunk-VCIHQZSN.cjs +58 -0
  29. package/dist/lib/node/chunk-VCIHQZSN.cjs.map +7 -0
  30. package/dist/lib/node/index.cjs +106 -118
  31. package/dist/lib/node/index.cjs.map +4 -4
  32. package/dist/lib/node/intent-dispatcher-PRCC4KZT.cjs +32 -0
  33. package/dist/lib/node/intent-dispatcher-PRCC4KZT.cjs.map +7 -0
  34. package/dist/lib/node/intent-resolver-OZDKCHPW.cjs +46 -0
  35. package/dist/lib/node/intent-resolver-OZDKCHPW.cjs.map +7 -0
  36. package/dist/lib/node/meta.json +1 -1
  37. package/dist/lib/node/store-BVUKNVKL.cjs +44 -0
  38. package/dist/lib/node/store-BVUKNVKL.cjs.map +7 -0
  39. package/dist/lib/node/testing/index.cjs +18 -8
  40. package/dist/lib/node/testing/index.cjs.map +3 -3
  41. package/dist/lib/node/worker.cjs +99 -0
  42. package/dist/lib/node/worker.cjs.map +7 -0
  43. package/dist/lib/node-esm/app-graph-builder-XHI5IIXQ.mjs +138 -0
  44. package/dist/lib/node-esm/app-graph-builder-XHI5IIXQ.mjs.map +7 -0
  45. package/dist/lib/node-esm/chunk-CBT75GCX.mjs +34 -0
  46. package/dist/lib/node-esm/chunk-CBT75GCX.mjs.map +7 -0
  47. package/dist/lib/node-esm/chunk-JDAHZRYQ.mjs +286 -0
  48. package/dist/lib/node-esm/chunk-JDAHZRYQ.mjs.map +7 -0
  49. package/dist/lib/node-esm/{chunk-KPMTPXQI.mjs → chunk-TVIR2PHY.mjs} +660 -823
  50. package/dist/lib/node-esm/chunk-TVIR2PHY.mjs.map +7 -0
  51. package/dist/lib/node-esm/index.mjs +57 -74
  52. package/dist/lib/node-esm/index.mjs.map +4 -4
  53. package/dist/lib/node-esm/intent-dispatcher-LGACN32C.mjs +12 -0
  54. package/dist/lib/node-esm/intent-dispatcher-LGACN32C.mjs.map +7 -0
  55. package/dist/lib/node-esm/intent-resolver-RBNG76ZX.mjs +40 -0
  56. package/dist/lib/node-esm/intent-resolver-RBNG76ZX.mjs.map +7 -0
  57. package/dist/lib/node-esm/meta.json +1 -1
  58. package/dist/lib/node-esm/store-PHTOEREN.mjs +30 -0
  59. package/dist/lib/node-esm/store-PHTOEREN.mjs.map +7 -0
  60. package/dist/lib/node-esm/testing/index.mjs +13 -3
  61. package/dist/lib/node-esm/testing/index.mjs.map +3 -3
  62. package/dist/lib/node-esm/worker.mjs +78 -0
  63. package/dist/lib/node-esm/worker.mjs.map +7 -0
  64. package/dist/types/src/App.d.ts +2 -2
  65. package/dist/types/src/App.d.ts.map +1 -1
  66. package/dist/types/src/common/capabilities.d.ts +88 -124
  67. package/dist/types/src/common/capabilities.d.ts.map +1 -1
  68. package/dist/types/src/common/events.d.ts +22 -11
  69. package/dist/types/src/common/events.d.ts.map +1 -1
  70. package/dist/types/src/common/file.d.ts +1 -1
  71. package/dist/types/src/common/file.d.ts.map +1 -1
  72. package/dist/types/src/common/graph.d.ts +2 -2
  73. package/dist/types/src/common/graph.d.ts.map +1 -1
  74. package/dist/types/src/common/index.d.ts +0 -1
  75. package/dist/types/src/common/index.d.ts.map +1 -1
  76. package/dist/types/src/common/layout.d.ts +218 -121
  77. package/dist/types/src/common/layout.d.ts.map +1 -1
  78. package/dist/types/src/common/surface.d.ts +3 -3
  79. package/dist/types/src/common/surface.d.ts.map +1 -1
  80. package/dist/types/src/common/translations.d.ts +7 -7
  81. package/dist/types/src/common/translations.d.ts.map +1 -1
  82. package/dist/types/src/core/capabilities.d.ts +6 -2
  83. package/dist/types/src/core/capabilities.d.ts.map +1 -1
  84. package/dist/types/src/core/manager.d.ts +2 -9
  85. package/dist/types/src/core/manager.d.ts.map +1 -1
  86. package/dist/types/src/core/plugin.d.ts +5 -2
  87. package/dist/types/src/core/plugin.d.ts.map +1 -1
  88. package/dist/types/src/playground/debug/Debug.d.ts +2 -3
  89. package/dist/types/src/playground/debug/Debug.d.ts.map +1 -1
  90. package/dist/types/src/playground/debug/plugin.d.ts +1 -1
  91. package/dist/types/src/playground/debug/plugin.d.ts.map +1 -1
  92. package/dist/types/src/playground/generator/Main.d.ts +2 -3
  93. package/dist/types/src/playground/generator/Main.d.ts.map +1 -1
  94. package/dist/types/src/playground/generator/Toolbar.d.ts +2 -3
  95. package/dist/types/src/playground/generator/Toolbar.d.ts.map +1 -1
  96. package/dist/types/src/playground/generator/generator.d.ts +5 -3
  97. package/dist/types/src/playground/generator/generator.d.ts.map +1 -1
  98. package/dist/types/src/playground/generator/plugin.d.ts +1 -1
  99. package/dist/types/src/playground/generator/plugin.d.ts.map +1 -1
  100. package/dist/types/src/playground/layout/Layout.d.ts +2 -2
  101. package/dist/types/src/playground/layout/Layout.d.ts.map +1 -1
  102. package/dist/types/src/playground/layout/plugin.d.ts +1 -1
  103. package/dist/types/src/playground/layout/plugin.d.ts.map +1 -1
  104. package/dist/types/src/playground/logger/Toolbar.d.ts +2 -3
  105. package/dist/types/src/playground/logger/Toolbar.d.ts.map +1 -1
  106. package/dist/types/src/playground/logger/plugin.d.ts +1 -1
  107. package/dist/types/src/playground/logger/plugin.d.ts.map +1 -1
  108. package/dist/types/src/playground/logger/schema.d.ts +1 -1
  109. package/dist/types/src/playground/logger/schema.d.ts.map +1 -1
  110. package/dist/types/src/playground/playground.stories.d.ts +2 -3
  111. package/dist/types/src/playground/playground.stories.d.ts.map +1 -1
  112. package/dist/types/src/plugin-intent/IntentPlugin.d.ts +1 -1
  113. package/dist/types/src/plugin-intent/IntentPlugin.d.ts.map +1 -1
  114. package/dist/types/src/plugin-intent/actions.d.ts +1 -1
  115. package/dist/types/src/plugin-intent/actions.d.ts.map +1 -1
  116. package/dist/types/src/plugin-intent/index.d.ts +0 -1
  117. package/dist/types/src/plugin-intent/index.d.ts.map +1 -1
  118. package/dist/types/src/plugin-intent/intent-dispatcher.d.ts +27 -20
  119. package/dist/types/src/plugin-intent/intent-dispatcher.d.ts.map +1 -1
  120. package/dist/types/src/plugin-intent/intent.d.ts +3 -3
  121. package/dist/types/src/plugin-intent/intent.d.ts.map +1 -1
  122. package/dist/types/src/plugin-settings/SettingsPlugin.d.ts +1 -1
  123. package/dist/types/src/plugin-settings/SettingsPlugin.d.ts.map +1 -1
  124. package/dist/types/src/plugin-settings/actions.d.ts +11 -1
  125. package/dist/types/src/plugin-settings/actions.d.ts.map +1 -1
  126. package/dist/types/src/plugin-settings/app-graph-builder.d.ts +197 -0
  127. package/dist/types/src/plugin-settings/app-graph-builder.d.ts.map +1 -0
  128. package/dist/types/src/plugin-settings/intent-resolver.d.ts +4 -0
  129. package/dist/types/src/plugin-settings/intent-resolver.d.ts.map +1 -0
  130. package/dist/types/src/plugin-settings/store.d.ts +5 -0
  131. package/dist/types/src/plugin-settings/store.d.ts.map +1 -0
  132. package/dist/types/src/plugin-settings/translations.d.ts +11 -0
  133. package/dist/types/src/plugin-settings/translations.d.ts.map +1 -0
  134. package/dist/types/src/react/ErrorBoundary.d.ts +1 -1
  135. package/dist/types/src/{plugin-intent → react}/IntentContext.d.ts +1 -1
  136. package/dist/types/src/react/IntentContext.d.ts.map +1 -0
  137. package/dist/types/src/react/Surface.d.ts.map +1 -1
  138. package/dist/types/src/react/Surface.stories.d.ts +15 -0
  139. package/dist/types/src/react/Surface.stories.d.ts.map +1 -0
  140. package/dist/types/src/react/common.d.ts +13 -0
  141. package/dist/types/src/react/common.d.ts.map +1 -0
  142. package/dist/types/src/react/index.d.ts +2 -0
  143. package/dist/types/src/react/index.d.ts.map +1 -1
  144. package/dist/types/src/react/useCapabilities.d.ts.map +1 -1
  145. package/dist/types/src/react/useIntentResolver.d.ts +3 -0
  146. package/dist/types/src/react/useIntentResolver.d.ts.map +1 -0
  147. package/dist/types/src/testing/withPluginManager.d.ts +6 -4
  148. package/dist/types/src/testing/withPluginManager.d.ts.map +1 -1
  149. package/dist/types/src/worker.d.ts +4 -0
  150. package/dist/types/src/worker.d.ts.map +1 -0
  151. package/package.json +29 -21
  152. package/project.json +4 -3
  153. package/src/App.tsx +17 -15
  154. package/src/common/capabilities.ts +30 -11
  155. package/src/common/events.ts +16 -2
  156. package/src/common/file.ts +1 -1
  157. package/src/common/graph.ts +2 -2
  158. package/src/common/index.ts +0 -1
  159. package/src/common/layout.ts +207 -126
  160. package/src/common/surface.ts +2 -2
  161. package/src/common/translations.ts +7 -8
  162. package/src/core/capabilities.ts +16 -7
  163. package/src/core/manager.test.ts +22 -73
  164. package/src/core/manager.ts +105 -91
  165. package/src/core/plugin.ts +6 -3
  166. package/src/playground/debug/plugin.ts +1 -1
  167. package/src/playground/generator/Toolbar.tsx +11 -11
  168. package/src/playground/generator/generator.ts +25 -0
  169. package/src/playground/generator/plugin.ts +6 -1
  170. package/src/playground/layout/plugin.ts +1 -1
  171. package/src/playground/logger/Toolbar.tsx +2 -1
  172. package/src/playground/logger/plugin.ts +7 -4
  173. package/src/playground/logger/schema.ts +1 -1
  174. package/src/plugin-intent/IntentPlugin.tsx +3 -43
  175. package/src/plugin-intent/actions.ts +1 -1
  176. package/src/plugin-intent/errors.ts +1 -1
  177. package/src/plugin-intent/index.ts +0 -1
  178. package/src/plugin-intent/intent-dispatcher.test.ts +48 -29
  179. package/src/plugin-intent/intent-dispatcher.ts +81 -42
  180. package/src/plugin-intent/intent.ts +5 -5
  181. package/src/plugin-settings/SettingsPlugin.ts +19 -13
  182. package/src/plugin-settings/actions.ts +11 -1
  183. package/src/plugin-settings/app-graph-builder.ts +122 -0
  184. package/src/plugin-settings/intent-resolver.ts +34 -0
  185. package/src/plugin-settings/store.ts +30 -0
  186. package/src/plugin-settings/translations.ts +17 -0
  187. package/src/{plugin-intent → react}/IntentContext.tsx +2 -2
  188. package/src/react/Surface.stories.tsx +96 -0
  189. package/src/react/Surface.tsx +11 -8
  190. package/src/react/common.ts +12 -0
  191. package/src/react/index.ts +2 -0
  192. package/src/react/useCapabilities.ts +1 -0
  193. package/src/react/useIntentResolver.ts +22 -0
  194. package/src/testing/withPluginManager.tsx +28 -4
  195. package/src/worker.ts +11 -0
  196. package/tsconfig.json +7 -13
  197. package/dist/lib/browser/chunk-GNLU3GAU.mjs.map +0 -7
  198. package/dist/lib/node/chunk-FBA4BB3J.cjs +0 -1639
  199. package/dist/lib/node/chunk-FBA4BB3J.cjs.map +0 -7
  200. package/dist/lib/node-esm/chunk-KPMTPXQI.mjs.map +0 -7
  201. package/dist/types/src/common/navigation.d.ts +0 -241
  202. package/dist/types/src/common/navigation.d.ts.map +0 -1
  203. package/dist/types/src/plugin-intent/IntentContext.d.ts.map +0 -1
  204. package/src/common/navigation.ts +0 -199
  205. /package/{.eslintrc.js → .eslintrc.cjs} +0 -0
@@ -0,0 +1,30 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import { effect } from '@preact/signals-core';
6
+
7
+ import { RootSettingsStore } from '@dxos/local-storage';
8
+
9
+ import { Capabilities } from '../common';
10
+ import { contributes, type PluginsContext } from '../core';
11
+
12
+ export default (context: PluginsContext) => {
13
+ const settingsStore = new RootSettingsStore();
14
+
15
+ let previous: Capabilities.Settings[] = [];
16
+ const unsubscribe = effect(() => {
17
+ const allSettings = context.requestCapabilities(Capabilities.Settings);
18
+ const added = allSettings.filter((setting) => !previous.includes(setting));
19
+ const removed = previous.filter((setting) => !allSettings.includes(setting));
20
+ previous = allSettings;
21
+ added.forEach((setting) => {
22
+ settingsStore.createStore(setting as any);
23
+ });
24
+ removed.forEach((setting) => {
25
+ settingsStore.removeStore(setting.prefix);
26
+ });
27
+ });
28
+
29
+ return contributes(Capabilities.SettingsStore, settingsStore, () => unsubscribe());
30
+ };
@@ -0,0 +1,17 @@
1
+ //
2
+ // Copyright 2023 DXOS.org
3
+ //
4
+
5
+ import { SETTINGS_PLUGIN } from './actions';
6
+
7
+ export default [
8
+ {
9
+ 'en-US': {
10
+ [SETTINGS_PLUGIN]: {
11
+ 'open settings label': 'Open settings',
12
+ 'app settings label': 'Settings',
13
+ 'custom plugins label': 'Plugins',
14
+ },
15
+ },
16
+ },
17
+ ];
@@ -7,9 +7,9 @@ import { type Context, createContext, useContext, type Provider, useEffect } fro
7
7
  import { raise } from '@dxos/debug';
8
8
  import { pick } from '@dxos/util';
9
9
 
10
- import { type AnyIntentResolver, type IntentContext } from './intent-dispatcher';
10
+ import { usePluginManager } from './PluginManagerProvider';
11
11
  import { Capabilities } from '../common';
12
- import { usePluginManager } from '../react';
12
+ import { type AnyIntentResolver, type IntentContext } from '../plugin-intent';
13
13
 
14
14
  const IntentContext: Context<IntentContext | undefined> = createContext<IntentContext | undefined>(undefined);
15
15
 
@@ -0,0 +1,96 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import '@dxos-theme';
6
+
7
+ import React, { useCallback, useState } from 'react';
8
+
9
+ import { faker } from '@dxos/random';
10
+ import { Button, List, ListItem } from '@dxos/react-ui';
11
+ import { withLayout, withTheme } from '@dxos/storybook-utils';
12
+
13
+ import { PluginManagerProvider, usePluginManager } from './PluginManagerProvider';
14
+ import { Surface, useSurfaces } from './Surface';
15
+ import { Capabilities, createSurface } from '../common';
16
+ import { type PluginManager } from '../core';
17
+ import { setupPluginManager } from '../testing';
18
+
19
+ const randomColor = (): string => {
20
+ const hue = faker.number.int({ min: 0, max: 360 });
21
+ const saturation = faker.number.int({ min: 50, max: 90 });
22
+ const lightness = faker.number.int({ min: 40, max: 70 });
23
+ return `hsl(${hue}, ${saturation}%, ${lightness}%)`;
24
+ };
25
+
26
+ const Story = () => {
27
+ const manager = usePluginManager();
28
+ const surfaces = useSurfaces();
29
+ const [picked, setPicked] = useState('test');
30
+
31
+ const handleAdd = useCallback(() => {
32
+ const id = `test-${faker.number.int({ min: 0, max: 1_000_000 })}`;
33
+ const backgroundColor = randomColor();
34
+
35
+ manager.context.contributeCapability({
36
+ module: 'test',
37
+ interface: Capabilities.ReactSurface,
38
+ implementation: createSurface({
39
+ id,
40
+ role: id,
41
+ component: () => (
42
+ <div className='flex-1' style={{ backgroundColor }}>
43
+ {id}
44
+ </div>
45
+ ),
46
+ }),
47
+ });
48
+
49
+ setPicked(id);
50
+ }, [manager]);
51
+
52
+ const handlePick = useCallback(() => {
53
+ setPicked(faker.helpers.arrayElement(surfaces).id);
54
+ }, [surfaces]);
55
+
56
+ return (
57
+ <div className='flex flex-col gap-2'>
58
+ <div className='flex gap-2'>
59
+ <Button onClick={handleAdd}>Add</Button>
60
+ <Button onClick={handlePick}>Pick</Button>
61
+ </div>
62
+ <div className='flex gap-2'>
63
+ <div className='flex-1'>
64
+ <List itemSizes='one'>
65
+ {surfaces.map((surface) => (
66
+ <ListItem.Root key={surface.id} id={surface.id}>
67
+ <ListItem.Heading classNames='grow pbs-2'>{surface.id}</ListItem.Heading>
68
+ </ListItem.Root>
69
+ ))}
70
+ </List>
71
+ </div>
72
+ <div className='flex-1'>
73
+ <Surface role={picked} limit={1} />
74
+ </div>
75
+ </div>
76
+ </div>
77
+ );
78
+ };
79
+
80
+ export default {
81
+ title: 'sdk/app-framework/Surface',
82
+ render: ({ manager }: { manager: PluginManager }) => {
83
+ return (
84
+ <PluginManagerProvider value={manager}>
85
+ <Story />
86
+ </PluginManagerProvider>
87
+ );
88
+ },
89
+ // NOTE: Intentionally not using withPluginManager to try to reduce surface area of the story.
90
+ decorators: [withTheme, withLayout({ tooltips: true })],
91
+ args: {
92
+ manager: setupPluginManager(),
93
+ },
94
+ };
95
+
96
+ export const Default = {};
@@ -5,14 +5,17 @@
5
5
  import React, { memo, forwardRef, Suspense, useMemo } from 'react';
6
6
 
7
7
  import { useDefaultValue } from '@dxos/react-hooks';
8
- import { byDisposition } from '@dxos/util';
8
+ import { byPosition } from '@dxos/util';
9
9
 
10
10
  import { ErrorBoundary } from './ErrorBoundary';
11
11
  import { useCapabilities } from './useCapabilities';
12
12
  import { Capabilities, type SurfaceDefinition, type SurfaceProps } from '../common';
13
13
  import { type PluginsContext } from '../core';
14
14
 
15
- const useSurfaces = () => {
15
+ /**
16
+ * @internal
17
+ */
18
+ export const useSurfaces = () => {
16
19
  const surfaces = useCapabilities(Capabilities.ReactSurface);
17
20
  return useMemo(() => surfaces.flat(), [surfaces]);
18
21
  };
@@ -23,7 +26,7 @@ const findCandidates = (surfaces: SurfaceDefinition[], { role, data }: Pick<Surf
23
26
  Array.isArray(definition.role) ? definition.role.includes(role) : definition.role === role,
24
27
  )
25
28
  .filter(({ filter }) => (filter ? filter(data ?? {}) : true))
26
- .toSorted(byDisposition);
29
+ .toSorted(byPosition);
27
30
  };
28
31
 
29
32
  /**
@@ -49,11 +52,9 @@ export const Surface = memo(
49
52
  const surfaces = useSurfaces();
50
53
  const data = useDefaultValue(_data, () => ({}));
51
54
 
52
- const candidates = useMemo(() => {
53
- const definitions = findCandidates(surfaces, { role, data });
54
- return limit ? definitions.slice(0, limit) : definitions;
55
- }, [surfaces, role, data, limit]);
56
-
55
+ // NOTE: Memoizing the candidates makes the surface not re-render based on reactivity within data.
56
+ const definitions = findCandidates(surfaces, { role, data });
57
+ const candidates = limit ? definitions.slice(0, limit) : definitions;
57
58
  const nodes = candidates.map(({ component: Component, id }) => (
58
59
  <Component ref={forwardedRef} key={id} id={id} role={role} data={data} limit={limit} {...rest} />
59
60
  ));
@@ -70,3 +71,5 @@ export const Surface = memo(
70
71
  },
71
72
  ),
72
73
  );
74
+
75
+ Surface.displayName = 'Surface';
@@ -0,0 +1,12 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import { useCapability } from './useCapabilities';
6
+ import { Capabilities } from '../common';
7
+
8
+ export const useIntentDispatcher = () => useCapability(Capabilities.IntentDispatcher);
9
+
10
+ export const useAppGraph = () => useCapability(Capabilities.AppGraph);
11
+
12
+ export const useLayout = () => useCapability(Capabilities.Layout);
@@ -2,7 +2,9 @@
2
2
  // Copyright 2023 DXOS.org
3
3
  //
4
4
 
5
+ export * from './common';
5
6
  export * from './ErrorBoundary';
6
7
  export * from './PluginManagerProvider';
7
8
  export * from './Surface';
8
9
  export * from './useCapabilities';
10
+ export * from './useIntentResolver';
@@ -21,6 +21,7 @@ export const useCapabilities = <T, U extends T = T>(
21
21
  () => computed(() => manager.context.requestCapabilities(interfaceDef, filter)),
22
22
  [interfaceDef],
23
23
  );
24
+
24
25
  return signal.value;
25
26
  };
26
27
 
@@ -0,0 +1,22 @@
1
+ //
2
+ // Copyright 2023 DXOS.org
3
+ //
4
+
5
+ import { useEffect } from 'react';
6
+
7
+ import { Capabilities } from '../common';
8
+ import { type AnyIntentResolver } from '../plugin-intent';
9
+ import { usePluginManager } from '../react';
10
+
11
+ export const useIntentResolver = (module: string, resolver: AnyIntentResolver) => {
12
+ const manager = usePluginManager();
13
+ useEffect(() => {
14
+ manager.context.contributeCapability({
15
+ module,
16
+ interface: Capabilities.IntentResolver,
17
+ implementation: resolver,
18
+ });
19
+
20
+ return () => manager.context.removeCapability(Capabilities.IntentResolver, resolver);
21
+ }, [module, resolver]);
22
+ };
@@ -9,17 +9,24 @@ import { raise } from '@dxos/debug';
9
9
 
10
10
  import { createApp, type CreateAppOptions } from '../App';
11
11
  import { Capabilities, Events } from '../common';
12
- import { type AnyCapability, contributes, defineModule, definePlugin, PluginManager } from '../core';
12
+ import {
13
+ type ActivationEvent,
14
+ type AnyCapability,
15
+ contributes,
16
+ defineModule,
17
+ definePlugin,
18
+ PluginManager,
19
+ } from '../core';
13
20
 
14
21
  /**
15
- * Wraps a story with a plugin manager.
22
+ * @internal
16
23
  */
17
- export const withPluginManager = ({
24
+ export const setupPluginManager = ({
18
25
  capabilities,
19
26
  plugins = [],
20
27
  core = plugins.map(({ meta }) => meta.id),
21
28
  ...options
22
- }: CreateAppOptions & { capabilities?: AnyCapability[] } = {}): Decorator => {
29
+ }: CreateAppOptions & { capabilities?: AnyCapability[] } = {}) => {
23
30
  const pluginManager = new PluginManager({
24
31
  pluginLoader: () => raise(new Error('Not implemented')),
25
32
  plugins: [StoryPlugin(), ...plugins],
@@ -37,8 +44,25 @@ export const withPluginManager = ({
37
44
  });
38
45
  }
39
46
 
47
+ return pluginManager;
48
+ };
49
+
50
+ export type WithPluginManagerOptions = CreateAppOptions & {
51
+ capabilities?: AnyCapability[];
52
+ fireEvents?: (ActivationEvent | string)[];
53
+ };
54
+
55
+ /**
56
+ * Wraps a story with a plugin manager.
57
+ */
58
+ export const withPluginManager = (options: WithPluginManagerOptions = {}): Decorator => {
59
+ const pluginManager = setupPluginManager(options);
40
60
  const App = createApp({ pluginManager });
41
61
 
62
+ options.fireEvents?.forEach((event) => {
63
+ void pluginManager.activate(event);
64
+ });
65
+
42
66
  return (Story, context) => {
43
67
  useEffect(() => {
44
68
  const capability = contributes(Capabilities.ReactRoot, {
package/src/worker.ts ADDED
@@ -0,0 +1,11 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ // Entrypoint for using plugins in workers runtimes (e.g. Cloudflare Workers, etc.)
6
+ // Excludes all frontend code & dependencies (e.g. localStorage, React, etc.)
7
+
8
+ export * from './core';
9
+ // NOTE: Common includes browser capabilities but they are types only.
10
+ export * from './common';
11
+ export * from './plugin-intent';
package/tsconfig.json CHANGED
@@ -1,15 +1,6 @@
1
1
  {
2
2
  "extends": "../../../tsconfig.base.json",
3
- "compilerOptions": {
4
- "esModuleInterop": true,
5
- "jsx": "react",
6
- "lib": [
7
- "DOM",
8
- "ESNext"
9
- ],
10
- "module": "ESNext",
11
- "outDir": "./dist/types"
12
- },
3
+ "compilerOptions": {},
13
4
  "exclude": [
14
5
  "/node_modules/"
15
6
  ],
@@ -20,9 +11,6 @@
20
11
  {
21
12
  "path": "../../common/async"
22
13
  },
23
- {
24
- "path": "../../common/context"
25
- },
26
14
  {
27
15
  "path": "../../common/debug"
28
16
  },
@@ -35,6 +23,9 @@
35
23
  {
36
24
  "path": "../../common/log"
37
25
  },
26
+ {
27
+ "path": "../../common/random"
28
+ },
38
29
  {
39
30
  "path": "../../common/storybook-utils"
40
31
  },
@@ -50,6 +41,9 @@
50
41
  {
51
42
  "path": "../../core/echo/live-object"
52
43
  },
44
+ {
45
+ "path": "../../experimental/artifact"
46
+ },
53
47
  {
54
48
  "path": "../../ui/primitives/react-hooks"
55
49
  },