@dxos/app-framework 0.8.4-main.5ea62a8 → 0.8.4-main.72ec0f3

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 (192) hide show
  1. package/.storybook/main.mts +11 -0
  2. package/.storybook/preview.mts +8 -0
  3. package/dist/lib/browser/{app-graph-builder-AFFC6VB2.mjs → app-graph-builder-OIEZZC45.mjs} +31 -30
  4. package/dist/lib/browser/app-graph-builder-OIEZZC45.mjs.map +7 -0
  5. package/dist/lib/browser/{chunk-ORWHM7CO.mjs → chunk-SCPE4ZO2.mjs} +11 -8
  6. package/dist/lib/browser/chunk-SCPE4ZO2.mjs.map +7 -0
  7. package/dist/lib/browser/{chunk-DND4XMN4.mjs → chunk-VFUKEZIN.mjs} +233 -191
  8. package/dist/lib/browser/chunk-VFUKEZIN.mjs.map +7 -0
  9. package/dist/lib/browser/{chunk-OZY7HV2A.mjs → chunk-WPW5VVAX.mjs} +281 -273
  10. package/dist/lib/browser/chunk-WPW5VVAX.mjs.map +7 -0
  11. package/dist/lib/browser/index.mjs +14 -56
  12. package/dist/lib/browser/index.mjs.map +3 -3
  13. package/dist/lib/browser/{intent-dispatcher-QG7UPGQX.mjs → intent-dispatcher-LZ4AE66E.mjs} +2 -2
  14. package/dist/lib/browser/{intent-resolver-4S4PSTM5.mjs → intent-resolver-QVCKRX6G.mjs} +7 -7
  15. package/dist/lib/browser/intent-resolver-QVCKRX6G.mjs.map +7 -0
  16. package/dist/lib/browser/meta.json +1 -1
  17. package/dist/lib/browser/react/index.mjs +34 -0
  18. package/dist/lib/browser/{store-6E33KLGK.mjs → store-CNPHOYTJ.mjs} +5 -5
  19. package/dist/lib/browser/store-CNPHOYTJ.mjs.map +7 -0
  20. package/dist/lib/browser/testing/index.mjs +14 -16
  21. package/dist/lib/browser/testing/index.mjs.map +3 -3
  22. package/dist/lib/node-esm/{app-graph-builder-S4OAULX5.mjs → app-graph-builder-EBU4NVWD.mjs} +31 -30
  23. package/dist/lib/node-esm/app-graph-builder-EBU4NVWD.mjs.map +7 -0
  24. package/dist/lib/node-esm/{chunk-E2TK7Z4P.mjs → chunk-IJOHO66N.mjs} +233 -191
  25. package/dist/lib/node-esm/chunk-IJOHO66N.mjs.map +7 -0
  26. package/dist/lib/node-esm/{chunk-F63ZRXMK.mjs → chunk-XJZGUJ3H.mjs} +281 -273
  27. package/dist/lib/node-esm/chunk-XJZGUJ3H.mjs.map +7 -0
  28. package/dist/lib/node-esm/{chunk-UMZQERLE.mjs → chunk-ZX63QUGE.mjs} +11 -8
  29. package/dist/lib/node-esm/chunk-ZX63QUGE.mjs.map +7 -0
  30. package/dist/lib/node-esm/index.mjs +14 -56
  31. package/dist/lib/node-esm/index.mjs.map +3 -3
  32. package/dist/lib/node-esm/{intent-dispatcher-NXBGPJOX.mjs → intent-dispatcher-MGOJ3CHD.mjs} +2 -2
  33. package/dist/lib/node-esm/{intent-resolver-2ZKXI5ET.mjs → intent-resolver-URF3HN3G.mjs} +7 -7
  34. package/dist/lib/node-esm/intent-resolver-URF3HN3G.mjs.map +7 -0
  35. package/dist/lib/node-esm/meta.json +1 -1
  36. package/dist/lib/node-esm/react/index.mjs +35 -0
  37. package/dist/lib/node-esm/{store-QQUTQHHT.mjs → store-RK5B4XEL.mjs} +5 -5
  38. package/dist/lib/node-esm/store-RK5B4XEL.mjs.map +7 -0
  39. package/dist/lib/node-esm/testing/index.mjs +14 -16
  40. package/dist/lib/node-esm/testing/index.mjs.map +3 -3
  41. package/dist/types/src/common/capabilities.d.ts +41 -37
  42. package/dist/types/src/common/capabilities.d.ts.map +1 -1
  43. package/dist/types/src/common/collaboration.d.ts +1 -1
  44. package/dist/types/src/common/collaboration.d.ts.map +1 -1
  45. package/dist/types/src/common/file.d.ts +1 -1
  46. package/dist/types/src/common/file.d.ts.map +1 -1
  47. package/dist/types/src/common/layout.d.ts +1 -3
  48. package/dist/types/src/common/layout.d.ts.map +1 -1
  49. package/dist/types/src/common/surface.d.ts +19 -16
  50. package/dist/types/src/common/surface.d.ts.map +1 -1
  51. package/dist/types/src/common/translations.d.ts +1 -1
  52. package/dist/types/src/common/translations.d.ts.map +1 -1
  53. package/dist/types/src/core/capabilities.d.ts +15 -15
  54. package/dist/types/src/core/capabilities.d.ts.map +1 -1
  55. package/dist/types/src/core/manager.d.ts +1 -1
  56. package/dist/types/src/core/manager.d.ts.map +1 -1
  57. package/dist/types/src/core/plugin.d.ts +8 -1
  58. package/dist/types/src/core/plugin.d.ts.map +1 -1
  59. package/dist/types/src/index.d.ts +0 -2
  60. package/dist/types/src/index.d.ts.map +1 -1
  61. package/dist/types/src/playground/debug/plugin.d.ts +1 -1
  62. package/dist/types/src/playground/debug/plugin.d.ts.map +1 -1
  63. package/dist/types/src/playground/generator/Main.d.ts.map +1 -1
  64. package/dist/types/src/playground/generator/generator.d.ts +1 -1
  65. package/dist/types/src/playground/generator/generator.d.ts.map +1 -1
  66. package/dist/types/src/playground/generator/plugin.d.ts +1 -1
  67. package/dist/types/src/playground/generator/plugin.d.ts.map +1 -1
  68. package/dist/types/src/playground/layout/plugin.d.ts +1 -1
  69. package/dist/types/src/playground/layout/plugin.d.ts.map +1 -1
  70. package/dist/types/src/playground/logger/plugin.d.ts +1 -1
  71. package/dist/types/src/playground/logger/plugin.d.ts.map +1 -1
  72. package/dist/types/src/playground/logger/schema.d.ts +1 -1
  73. package/dist/types/src/playground/logger/schema.d.ts.map +1 -1
  74. package/dist/types/src/playground/playground.stories.d.ts +0 -1
  75. package/dist/types/src/playground/playground.stories.d.ts.map +1 -1
  76. package/dist/types/src/plugin-intent/IntentPlugin.d.ts +1 -1
  77. package/dist/types/src/plugin-intent/IntentPlugin.d.ts.map +1 -1
  78. package/dist/types/src/plugin-intent/actions.d.ts +5 -7
  79. package/dist/types/src/plugin-intent/actions.d.ts.map +1 -1
  80. package/dist/types/src/plugin-intent/errors.d.ts.map +1 -1
  81. package/dist/types/src/plugin-intent/intent-dispatcher.d.ts +4 -4
  82. package/dist/types/src/plugin-intent/intent-dispatcher.d.ts.map +1 -1
  83. package/dist/types/src/plugin-intent/intent.d.ts +1 -1
  84. package/dist/types/src/plugin-intent/intent.d.ts.map +1 -1
  85. package/dist/types/src/plugin-intent/meta.d.ts +3 -0
  86. package/dist/types/src/plugin-intent/meta.d.ts.map +1 -0
  87. package/dist/types/src/plugin-settings/SettingsPlugin.d.ts +1 -1
  88. package/dist/types/src/plugin-settings/SettingsPlugin.d.ts.map +1 -1
  89. package/dist/types/src/plugin-settings/actions.d.ts +5 -7
  90. package/dist/types/src/plugin-settings/actions.d.ts.map +1 -1
  91. package/dist/types/src/plugin-settings/app-graph-builder.d.ts.map +1 -1
  92. package/dist/types/src/plugin-settings/meta.d.ts +3 -0
  93. package/dist/types/src/plugin-settings/meta.d.ts.map +1 -0
  94. package/dist/types/src/plugin-settings/translations.d.ts +2 -1
  95. package/dist/types/src/plugin-settings/translations.d.ts.map +1 -1
  96. package/dist/types/src/react/App.d.ts +10 -0
  97. package/dist/types/src/react/App.d.ts.map +1 -0
  98. package/dist/types/src/react/App.stories.d.ts +14 -0
  99. package/dist/types/src/react/App.stories.d.ts.map +1 -0
  100. package/dist/types/src/react/DefaultFallback.d.ts +8 -0
  101. package/dist/types/src/react/DefaultFallback.d.ts.map +1 -0
  102. package/dist/types/src/react/ErrorBoundary.d.ts +2 -2
  103. package/dist/types/src/react/ErrorBoundary.d.ts.map +1 -1
  104. package/dist/types/src/react/Surface.d.ts +5 -5
  105. package/dist/types/src/react/Surface.d.ts.map +1 -1
  106. package/dist/types/src/react/Surface.stories.d.ts +3 -7
  107. package/dist/types/src/react/Surface.stories.d.ts.map +1 -1
  108. package/dist/types/src/react/index.d.ts +2 -0
  109. package/dist/types/src/react/index.d.ts.map +1 -1
  110. package/dist/types/src/react/types.d.ts +14 -0
  111. package/dist/types/src/react/types.d.ts.map +1 -0
  112. package/dist/types/src/{App.d.ts → react/useApp.d.ts} +7 -6
  113. package/dist/types/src/react/useApp.d.ts.map +1 -0
  114. package/dist/types/src/react/useLoading.d.ts +19 -0
  115. package/dist/types/src/react/useLoading.d.ts.map +1 -0
  116. package/dist/types/src/testing/withPluginManager.d.ts +7 -8
  117. package/dist/types/src/testing/withPluginManager.d.ts.map +1 -1
  118. package/dist/types/tsconfig.tsbuildinfo +1 -1
  119. package/moon.yml +5 -1
  120. package/package.json +44 -40
  121. package/src/common/capabilities.ts +34 -19
  122. package/src/common/collaboration.ts +3 -3
  123. package/src/common/file.ts +1 -1
  124. package/src/common/layout.ts +3 -4
  125. package/src/common/surface.ts +23 -21
  126. package/src/common/translations.ts +1 -1
  127. package/src/core/capabilities.test.ts +2 -2
  128. package/src/core/capabilities.ts +26 -22
  129. package/src/core/manager.test.ts +19 -19
  130. package/src/core/manager.ts +14 -7
  131. package/src/core/plugin.ts +13 -2
  132. package/src/index.ts +0 -2
  133. package/src/playground/debug/Debug.tsx +1 -1
  134. package/src/playground/debug/plugin.ts +7 -8
  135. package/src/playground/generator/Main.tsx +0 -1
  136. package/src/playground/generator/generator.ts +2 -2
  137. package/src/playground/generator/plugin.ts +12 -13
  138. package/src/playground/layout/plugin.ts +9 -8
  139. package/src/playground/logger/plugin.ts +27 -23
  140. package/src/playground/logger/schema.ts +1 -1
  141. package/src/playground/playground.stories.tsx +6 -7
  142. package/src/plugin-intent/IntentPlugin.ts +12 -13
  143. package/src/plugin-intent/actions.ts +4 -6
  144. package/src/plugin-intent/errors.ts +2 -1
  145. package/src/plugin-intent/intent-dispatcher.test.ts +10 -3
  146. package/src/plugin-intent/intent-dispatcher.ts +13 -6
  147. package/src/plugin-intent/intent.ts +1 -1
  148. package/src/plugin-intent/meta.ts +10 -0
  149. package/src/plugin-settings/SettingsPlugin.ts +25 -27
  150. package/src/plugin-settings/actions.ts +9 -13
  151. package/src/plugin-settings/app-graph-builder.ts +22 -20
  152. package/src/plugin-settings/intent-resolver.ts +2 -2
  153. package/src/plugin-settings/meta.ts +10 -0
  154. package/src/plugin-settings/store.ts +2 -2
  155. package/src/plugin-settings/translations.ts +4 -4
  156. package/src/react/App.stories.tsx +33 -0
  157. package/src/react/App.tsx +59 -0
  158. package/src/react/DefaultFallback.tsx +26 -0
  159. package/src/react/ErrorBoundary.tsx +10 -8
  160. package/src/react/Surface.stories.tsx +70 -49
  161. package/src/react/Surface.tsx +67 -36
  162. package/src/react/index.ts +4 -0
  163. package/src/react/types.ts +37 -0
  164. package/src/{App.tsx → react/useApp.tsx} +35 -150
  165. package/src/react/useCapabilities.ts +2 -2
  166. package/src/react/useLoading.tsx +70 -0
  167. package/src/testing/withPluginManager.stories.tsx +1 -1
  168. package/src/testing/withPluginManager.tsx +24 -23
  169. package/tsconfig.json +11 -9
  170. package/vitest.config.ts +8 -6
  171. package/dist/lib/browser/app-graph-builder-AFFC6VB2.mjs.map +0 -7
  172. package/dist/lib/browser/chunk-DND4XMN4.mjs.map +0 -7
  173. package/dist/lib/browser/chunk-ORWHM7CO.mjs.map +0 -7
  174. package/dist/lib/browser/chunk-OZY7HV2A.mjs.map +0 -7
  175. package/dist/lib/browser/intent-resolver-4S4PSTM5.mjs.map +0 -7
  176. package/dist/lib/browser/store-6E33KLGK.mjs.map +0 -7
  177. package/dist/lib/browser/worker.mjs +0 -85
  178. package/dist/lib/node-esm/app-graph-builder-S4OAULX5.mjs.map +0 -7
  179. package/dist/lib/node-esm/chunk-E2TK7Z4P.mjs.map +0 -7
  180. package/dist/lib/node-esm/chunk-F63ZRXMK.mjs.map +0 -7
  181. package/dist/lib/node-esm/chunk-UMZQERLE.mjs.map +0 -7
  182. package/dist/lib/node-esm/intent-resolver-2ZKXI5ET.mjs.map +0 -7
  183. package/dist/lib/node-esm/store-QQUTQHHT.mjs.map +0 -7
  184. package/dist/lib/node-esm/worker.mjs +0 -86
  185. package/dist/types/src/App.d.ts.map +0 -1
  186. package/dist/types/src/worker.d.ts +0 -4
  187. package/dist/types/src/worker.d.ts.map +0 -1
  188. package/src/worker.ts +0 -11
  189. /package/dist/lib/browser/{intent-dispatcher-QG7UPGQX.mjs.map → intent-dispatcher-LZ4AE66E.mjs.map} +0 -0
  190. /package/dist/lib/browser/{worker.mjs.map → react/index.mjs.map} +0 -0
  191. /package/dist/lib/node-esm/{intent-dispatcher-NXBGPJOX.mjs.map → intent-dispatcher-MGOJ3CHD.mjs.map} +0 -0
  192. /package/dist/lib/node-esm/{worker.mjs.map → react/index.mjs.map} +0 -0
@@ -2,98 +2,119 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
- import '@dxos-theme';
6
-
7
5
  import { type Meta, type StoryObj } from '@storybook/react-vite';
8
- import React, { useCallback, useState } from 'react';
6
+ import React, { useCallback, useEffect, useState } from 'react';
9
7
 
10
8
  import { faker } from '@dxos/random';
11
- import { Button, List, ListItem } from '@dxos/react-ui';
12
- import { withLayout, withTheme } from '@dxos/storybook-utils';
9
+ import { List, ListItem, Toolbar } from '@dxos/react-ui';
10
+ import { withTheme } from '@dxos/react-ui/testing';
11
+ import { getHashStyles, mx } from '@dxos/react-ui-theme';
13
12
 
14
13
  import { Capabilities, createSurface } from '../common';
15
- import { type PluginManager } from '../core';
16
- import { setupPluginManager } from '../testing';
14
+ import { withPluginManager } from '../testing';
17
15
 
18
- import { PluginManagerProvider, usePluginManager } from './PluginManagerProvider';
16
+ import { usePluginManager } from './PluginManagerProvider';
19
17
  import { Surface, useSurfaces } from './Surface';
20
18
 
21
- const randomColor = (): string => {
22
- const hue = faker.number.int({ min: 0, max: 360 });
23
- const saturation = faker.number.int({ min: 50, max: 90 });
24
- const lightness = faker.number.int({ min: 40, max: 70 });
25
- return `hsl(${hue}, ${saturation}%, ${lightness}%)`;
26
- };
27
-
28
- const Component = () => {
19
+ const DefaultStory = () => {
20
+ const [selected, setSelected] = useState<string | undefined>();
29
21
  const manager = usePluginManager();
30
22
  const surfaces = useSurfaces();
31
- const [picked, setPicked] = useState('test');
32
23
 
33
24
  const handleAdd = useCallback(() => {
34
- const id = `test-${faker.number.int({ min: 0, max: 1_000_000 })}`;
35
- const backgroundColor = randomColor();
25
+ const id = `test-${faker.number.int({ min: 0, max: 1_000 })}`;
26
+ const styles = getHashStyles(id);
36
27
 
37
28
  manager.context.contributeCapability({
38
29
  module: 'test',
39
30
  interface: Capabilities.ReactSurface,
40
31
  implementation: createSurface({
41
32
  id,
42
- role: id,
33
+ role: 'item',
34
+ filter: (data): data is any => (data as any)?.id === id,
43
35
  component: () => (
44
- <div className='flex-1' style={{ backgroundColor }}>
45
- {id}
36
+ <div className={mx('flex justify-center items-center border rounded', styles.surface, styles.border)}>
37
+ <span className={mx('dx-tag font-mono text-lg', styles.text)}>{id}</span>
46
38
  </div>
47
39
  ),
48
40
  }),
49
41
  });
50
42
 
51
- setPicked(id);
43
+ setSelected(id);
52
44
  }, [manager]);
53
45
 
54
- const handlePick = useCallback(() => {
55
- setPicked(faker.helpers.arrayElement(surfaces).id);
46
+ const handleSelect = useCallback(() => {
47
+ setSelected(faker.helpers.arrayElement(surfaces)?.id);
56
48
  }, [surfaces]);
57
49
 
50
+ const handleError = useCallback(() => {
51
+ manager.context.contributeCapability({
52
+ module: 'error',
53
+ interface: Capabilities.ReactSurface,
54
+ implementation: createSurface({
55
+ id: 'error',
56
+ role: 'item',
57
+ filter: (data): data is any => (data as any)?.id === 'error',
58
+ component: () => {
59
+ const [count, setCount] = useState(3);
60
+ useEffect(() => {
61
+ const interval = setInterval(() => {
62
+ setCount((count) => {
63
+ if (count <= 1) {
64
+ clearInterval(interval);
65
+ }
66
+
67
+ return count - 1;
68
+ });
69
+ }, 1_000);
70
+ return () => clearInterval(interval);
71
+ }, []);
72
+
73
+ if (count <= 0) {
74
+ throw new Error('BANG!');
75
+ }
76
+
77
+ return (
78
+ <div className='flex justify-center items-center border border-roseFill rounded'>
79
+ <span className='font-mono'>Ticking... {count}</span>
80
+ </div>
81
+ );
82
+ },
83
+ }),
84
+ });
85
+
86
+ setSelected('error');
87
+ }, [manager]);
88
+
58
89
  return (
59
- <div className='flex flex-col gap-2'>
60
- <div className='flex gap-2'>
61
- <Button onClick={handleAdd}>Add</Button>
62
- <Button onClick={handlePick}>Pick</Button>
63
- </div>
64
- <div className='flex gap-2'>
65
- <div className='flex-1'>
66
- <List itemSizes='one'>
90
+ <div className='flex flex-col bs-full overflow-hidden'>
91
+ <Toolbar.Root>
92
+ <Toolbar.Button onClick={handleAdd}>Add</Toolbar.Button>
93
+ <Toolbar.Button onClick={handleSelect}>Pick</Toolbar.Button>
94
+ <Toolbar.Button onClick={handleError}>Error</Toolbar.Button>
95
+ </Toolbar.Root>
96
+ <div className='grid grid-cols-2 bs-full gap-4 overflow-hidden'>
97
+ <Surface role='item' data={selected ? { id: selected } : undefined} limit={1} />
98
+ <div className='overflow-y-auto bs-full'>
99
+ <List>
67
100
  {surfaces.map((surface) => (
68
101
  <ListItem.Root key={surface.id} id={surface.id}>
69
- <ListItem.Heading classNames='grow pbs-2'>{surface.id}</ListItem.Heading>
102
+ <ListItem.Heading classNames='flex items-center'>{surface.id}</ListItem.Heading>
70
103
  </ListItem.Root>
71
104
  ))}
72
105
  </List>
73
106
  </div>
74
- <div className='flex-1'>
75
- <Surface role={picked} limit={1} />
76
- </div>
77
107
  </div>
78
108
  </div>
79
109
  );
80
110
  };
81
111
 
82
- const DefaultStory = (props: { manager: PluginManager }) => {
83
- return (
84
- <PluginManagerProvider value={props.manager}>
85
- <Component />
86
- </PluginManagerProvider>
87
- );
88
- };
89
-
90
112
  const meta = {
91
113
  title: 'sdk/app-framework/Surface',
92
114
  render: DefaultStory,
93
- // NOTE: Intentionally not using withPluginManager to try to reduce surface area of the story.
94
- decorators: [withTheme, withLayout()],
95
- args: {
96
- manager: setupPluginManager(),
115
+ decorators: [withTheme, withPluginManager({ capabilities: [] })],
116
+ parameters: {
117
+ layout: 'fullscreen',
97
118
  },
98
119
  } satisfies Meta<typeof DefaultStory>;
99
120
 
@@ -2,7 +2,15 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
- import React, { Fragment, Suspense, forwardRef, memo, useMemo } from 'react';
5
+ import React, {
6
+ Fragment,
7
+ type NamedExoticComponent,
8
+ type RefAttributes,
9
+ Suspense,
10
+ forwardRef,
11
+ memo,
12
+ useMemo,
13
+ } from 'react';
6
14
 
7
15
  import { useDefaultValue } from '@dxos/react-hooks';
8
16
  import { byPosition } from '@dxos/util';
@@ -15,64 +23,87 @@ import { useCapabilities } from './useCapabilities';
15
23
 
16
24
  const DEFAULT_PLACEHOLDER = <Fragment />;
17
25
 
18
- /**
19
- * @internal
20
- */
21
- export const useSurfaces = () => {
22
- const surfaces = useCapabilities(Capabilities.ReactSurface);
23
- return useMemo(() => surfaces.flat(), [surfaces]);
24
- };
25
-
26
- const findCandidates = (surfaces: SurfaceDefinition[], { role, data }: Pick<SurfaceProps, 'role' | 'data'>) => {
27
- return Object.values(surfaces)
28
- .filter((definition) =>
29
- Array.isArray(definition.role) ? definition.role.includes(role) : definition.role === role,
30
- )
31
- .filter(({ filter }) => (filter ? filter(data ?? {}) : true))
32
- .toSorted(byPosition);
33
- };
34
-
35
- /**
36
- * @returns `true` if there is a contributed surface which matches the specified role & data, `false` otherwise.
37
- */
38
- export const isSurfaceAvailable = (context: PluginContext, { role, data }: Pick<SurfaceProps, 'role' | 'data'>) => {
39
- const surfaces = context.getCapabilities(Capabilities.ReactSurface);
40
- const candidates = findCandidates(surfaces.flat(), { role, data });
41
- return candidates.length > 0;
42
- };
43
-
44
26
  /**
45
27
  * A surface is a named region of the screen that can be populated by plugins.
46
28
  */
47
- export const Surface = memo(
48
- forwardRef<HTMLElement, SurfaceProps>(
49
- ({ id: _id, role, data: _data, limit, fallback, placeholder = DEFAULT_PLACEHOLDER, ...rest }, forwardedRef) => {
29
+ export const Surface: NamedExoticComponent<SurfaceProps & RefAttributes<HTMLElement>> = memo(
30
+ forwardRef(
31
+ (
32
+ { id: _id, role, data: dataParam, limit, fallback = DefaultFallback, placeholder = DEFAULT_PLACEHOLDER, ...rest },
33
+ forwardedRef,
34
+ ) => {
50
35
  // TODO(wittjosiah): This will make all surfaces depend on a single signal.
51
36
  // This isn't ideal because it means that any change to the data will cause all surfaces to re-render.
52
37
  // This effectively means that plugin modules which contribute surfaces need to all be activated at startup.
53
- // This should be fine for now because it's how it worked prior to capabilities api anyways.
38
+ // This should be fine for now because it's how it worked prior to capabilities api anyway.
54
39
  // In the future, it would be nice to be able to bucket the surface contributions by role.
55
40
  const surfaces = useSurfaces();
56
- const data = useDefaultValue(_data, () => ({}));
41
+ const data = useDefaultValue(dataParam, () => ({}));
57
42
 
58
43
  // NOTE: Memoizing the candidates makes the surface not re-render based on reactivity within data.
59
44
  const definitions = findCandidates(surfaces, { role, data });
60
45
  const candidates = limit ? definitions.slice(0, limit) : definitions;
61
- const nodes = candidates.map(({ component: Component, id }) => (
46
+ const nodes = candidates.map(({ id, component: Component }) => (
62
47
  <Component ref={forwardedRef} key={id} id={id} role={role} data={data} limit={limit} {...rest} />
63
48
  ));
64
49
 
50
+ // TODO(burdon): Able to inject DOM properties into root (e.g., object.id).
65
51
  const suspense = <Suspense fallback={placeholder}>{nodes}</Suspense>;
66
52
 
67
- return fallback ? (
53
+ return (
68
54
  <ErrorBoundary data={data} fallback={fallback}>
69
55
  {suspense}
70
56
  </ErrorBoundary>
71
- ) : (
72
- suspense
73
57
  );
74
58
  },
75
59
  ),
76
60
  );
77
61
 
62
+ // TODO(burdon): Make user facing, with telemetry.
63
+ // TODO(burdon): Change based on dev/prod mode; infer subject type, id.
64
+ const DefaultFallback = ({ data, error, dev }: { data: any; error: Error; dev?: boolean }) => {
65
+ if (dev) {
66
+ return (
67
+ <div className='flex flex-col gap-4 p-4 is-full overflow-y-auto'>
68
+ <h1 className='flex gap-2 text-sm mbs-2'>{error.message}</h1>
69
+ <pre className='overflow-auto text-xs text-description'>{JSON.stringify(data, null, 2)}</pre>
70
+ </div>
71
+ );
72
+ }
73
+
74
+ return (
75
+ <div className='flex flex-col gap-4 p-4 is-full overflow-y-auto border border-roseFill'>
76
+ <h1 className='flex gap-2 text-sm mbs-2 text-rose-500'>{error.message}</h1>
77
+ <pre className='overflow-auto text-xs text-description'>{error.stack}</pre>
78
+ <pre className='overflow-auto text-xs text-description'>{JSON.stringify(data, null, 2)}</pre>
79
+ </div>
80
+ );
81
+ };
82
+
83
+ /**
84
+ * @internal
85
+ */
86
+ export const useSurfaces = () => {
87
+ const surfaces = useCapabilities(Capabilities.ReactSurface);
88
+ return useMemo(() => surfaces.flat(), [surfaces]);
89
+ };
90
+
91
+ /**
92
+ * @returns `true` if there is a contributed surface which matches the specified role & data, `false` otherwise.
93
+ */
94
+ export const isSurfaceAvailable = (context: PluginContext, { role, data }: Pick<SurfaceProps, 'role' | 'data'>) => {
95
+ const surfaces = context.getCapabilities(Capabilities.ReactSurface);
96
+ const candidates = findCandidates(surfaces.flat(), { role, data });
97
+ return candidates.length > 0;
98
+ };
99
+
100
+ const findCandidates = (surfaces: SurfaceDefinition[], { role, data }: Pick<SurfaceProps, 'role' | 'data'>) => {
101
+ return Object.values(surfaces)
102
+ .filter((definition) =>
103
+ Array.isArray(definition.role) ? definition.role.includes(role) : definition.role === role,
104
+ )
105
+ .filter(({ filter }) => (filter ? filter(data ?? {}) : true))
106
+ .toSorted(byPosition);
107
+ };
108
+
78
109
  Surface.displayName = 'Surface';
@@ -3,8 +3,12 @@
3
3
  //
4
4
 
5
5
  export * from './common';
6
+ export * from './types';
7
+
6
8
  export * from './ErrorBoundary';
7
9
  export * from './PluginManagerProvider';
8
10
  export * from './Surface';
11
+
12
+ export * from './useApp';
9
13
  export * from './useCapabilities';
10
14
  export * from './useIntentResolver';
@@ -0,0 +1,37 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import * as Schema from 'effect/Schema';
6
+
7
+ import { type Obj } from '@dxos/echo';
8
+
9
+ export const SurfaceCardRole = Schema.Literal(
10
+ 'card',
11
+ 'card--popover',
12
+ 'card--intrinsic',
13
+ 'card--extrinsic',
14
+ 'card--transclusion',
15
+ );
16
+
17
+ export type SurfaceCardRole = Schema.Schema.Type<typeof SurfaceCardRole>;
18
+
19
+ // TODO(burdon): Define all roles.
20
+ export type SurfaceRole =
21
+ | 'item'
22
+ | 'article'
23
+ | 'complementary' // (for companion?)
24
+ | 'section'
25
+ | SurfaceCardRole;
26
+
27
+ /**
28
+ * Base type for surface components.
29
+ */
30
+ // TODO(burdon): Standardize PluginSettings and ObjectProperties.
31
+ // TODO(burdon): Include attendableId?
32
+ export type SurfaceComponentProps<Subject extends Obj.Any = Obj.Any, Props = {}, Role extends string = string> = {
33
+ role?: Role;
34
+
35
+ /** The object being displayed. */
36
+ subject: Subject;
37
+ } & Props;
@@ -2,22 +2,25 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
- import { RegistryContext } from '@effect-rx/rx-react';
5
+ import { RegistryContext } from '@effect-atom/atom-react';
6
6
  import { effect } from '@preact/signals-core';
7
- import React, { type FC, type PropsWithChildren, useCallback, useEffect, useMemo, useState } from 'react';
7
+ import React, { type FC, useCallback, useEffect, useMemo } from 'react';
8
8
 
9
9
  import { invariant } from '@dxos/invariant';
10
10
  import { live } from '@dxos/live-object';
11
11
  import { useAsyncEffect, useDefaultValue } from '@dxos/react-hooks';
12
12
 
13
- import { Capabilities, Events } from './common';
14
- import { type Plugin, PluginManager, type PluginManagerOptions } from './core';
15
- import { topologicalSort } from './helpers';
16
- import { ErrorBoundary, PluginManagerProvider, useCapabilities } from './react';
13
+ import { Capabilities, Events } from '../common';
14
+ import { type Plugin, PluginManager, type PluginManagerOptions } from '../core';
15
+
16
+ import { App } from './App';
17
+ import { DefaultFallback } from './DefaultFallback';
18
+ import { ErrorBoundary } from './ErrorBoundary';
19
+ import { PluginManagerProvider } from './PluginManagerProvider';
17
20
 
18
21
  const ENABLED_KEY = 'dxos.org/app-framework/enabled';
19
22
 
20
- export type CreateAppOptions = {
23
+ export type UseAppOptions = {
21
24
  pluginManager?: PluginManager;
22
25
  pluginLoader?: PluginManagerOptions['pluginLoader'];
23
26
  plugins?: Plugin[];
@@ -27,6 +30,7 @@ export type CreateAppOptions = {
27
30
  fallback?: ErrorBoundary['props']['fallback'];
28
31
  cacheEnabled?: boolean;
29
32
  safeMode?: boolean;
33
+ debounce?: number;
30
34
  };
31
35
 
32
36
  /**
@@ -38,7 +42,7 @@ export type CreateAppOptions = {
38
42
  * const core = [LayoutPluginId];
39
43
  * const default = [MyPluginId];
40
44
  * const fallback = <div>Initializing Plugins...</div>;
41
- * const App = createApp({ plugins, core, default, fallback });
45
+ * const App = useApp({ plugins, core, default, fallback });
42
46
  * createRoot(document.getElementById('root')!).render(
43
47
  * <StrictMode>
44
48
  * <App />
@@ -56,29 +60,30 @@ export type CreateAppOptions = {
56
60
  */
57
61
  export const useApp = ({
58
62
  pluginManager,
59
- pluginLoader: _pluginLoader,
60
- plugins: _plugins,
61
- core: _core,
62
- defaults: _defaults,
63
+ pluginLoader: pluginLoaderParam,
64
+ plugins: pluginsParam,
65
+ core: coreParam,
66
+ defaults: defaultsParam,
63
67
  placeholder,
64
68
  fallback = DefaultFallback,
65
69
  cacheEnabled = false,
66
70
  safeMode = false,
67
- }: CreateAppOptions) => {
68
- const plugins = useDefaultValue(_plugins, () => []);
69
- const core = useDefaultValue(_core, () => plugins.map(({ meta }) => meta.id));
70
- const defaults = useDefaultValue(_defaults, () => []);
71
+ debounce = 0,
72
+ }: UseAppOptions) => {
73
+ const plugins = useDefaultValue(pluginsParam, () => []);
74
+ const core = useDefaultValue(coreParam, () => plugins.map(({ meta }) => meta.id));
75
+ const defaults = useDefaultValue(defaultsParam, () => []);
71
76
 
72
77
  // TODO(wittjosiah): Provide a custom plugin loader which supports loading via url.
73
78
  const pluginLoader = useMemo(
74
79
  () =>
75
- _pluginLoader ??
80
+ pluginLoaderParam ??
76
81
  ((id: string) => {
77
82
  const plugin = plugins.find((plugin) => plugin.meta.id === id);
78
83
  invariant(plugin, `Plugin not found: ${id}`);
79
84
  return plugin;
80
85
  }),
81
- [_pluginLoader, plugins],
86
+ [pluginLoaderParam, plugins],
82
87
  );
83
88
 
84
89
  const state = useMemo(() => live({ ready: false, error: null }), []);
@@ -112,6 +117,10 @@ export const useApp = ({
112
117
  }, [cacheEnabled, manager]);
113
118
 
114
119
  useEffect(() => {
120
+ setupDevtools(manager);
121
+ }, [manager]);
122
+
123
+ useAsyncEffect(async () => {
115
124
  manager.context.contributeCapability({
116
125
  interface: Capabilities.PluginManager,
117
126
  implementation: manager,
@@ -119,27 +128,21 @@ export const useApp = ({
119
128
  });
120
129
 
121
130
  manager.context.contributeCapability({
122
- interface: Capabilities.RxRegistry,
131
+ interface: Capabilities.AtomRegistry,
123
132
  implementation: manager.registry,
124
- module: 'dxos.org/app-framework/rx-registry',
133
+ module: 'dxos.org/app-framework/atom-registry',
125
134
  });
126
135
 
127
- return () => {
128
- manager.context.removeCapability(Capabilities.PluginManager, manager);
129
- manager.context.removeCapability(Capabilities.RxRegistry, manager.registry);
130
- };
131
- }, [manager]);
132
-
133
- useEffect(() => {
134
- setupDevtools(manager);
135
- }, [manager]);
136
-
137
- useAsyncEffect(async () => {
138
136
  await Promise.all([
139
137
  // TODO(wittjosiah): Factor out such that this could be called per surface role when attempting to render.
140
138
  manager.activate(Events.SetupReactSurface),
141
139
  manager.activate(Events.Startup),
142
140
  ]);
141
+
142
+ return () => {
143
+ manager.context.removeCapability(Capabilities.PluginManager, manager);
144
+ manager.context.removeCapability(Capabilities.AtomRegistry, manager.registry);
145
+ };
143
146
  }, [manager]);
144
147
 
145
148
  return useCallback(
@@ -147,7 +150,7 @@ export const useApp = ({
147
150
  <ErrorBoundary fallback={fallback}>
148
151
  <PluginManagerProvider value={manager}>
149
152
  <RegistryContext.Provider value={manager.registry}>
150
- <App placeholder={placeholder} state={state} />
153
+ <App placeholder={placeholder} state={state} debounce={debounce} />
151
154
  </RegistryContext.Provider>
152
155
  </PluginManagerProvider>
153
156
  </ErrorBoundary>
@@ -156,124 +159,6 @@ export const useApp = ({
156
159
  );
157
160
  };
158
161
 
159
- const DELAY_PLACEHOLDER = 2_000;
160
-
161
- enum LoadingState {
162
- Loading = 0,
163
- FadeIn = 1,
164
- FadeOut = 2,
165
- Done = 3,
166
- }
167
-
168
- /**
169
- * To avoid "flashing" the placeholder, we wait a period of time before starting the loading animation.
170
- * If loading completes during this time the placehoder is not shown, otherwise is it displayed for a minimum period of time.
171
- *
172
- * States:
173
- * 0: Loading - Wait for a period of time before starting the loading animation.
174
- * 1: Fade-in - Display a loading animation.
175
- * 2: Fade-out - Fade out the loading animation.
176
- * 3: Done - Remove the placeholder.
177
- */
178
- const useLoading = (state: AppProps['state']) => {
179
- const [stage, setStage] = useState<LoadingState>(LoadingState.Loading);
180
- useEffect(() => {
181
- const i = setInterval(() => {
182
- setStage((tick) => {
183
- switch (tick) {
184
- case LoadingState.Loading:
185
- if (!state.ready) {
186
- return LoadingState.FadeIn;
187
- } else {
188
- clearInterval(i);
189
- return LoadingState.Done;
190
- }
191
- case LoadingState.FadeIn:
192
- if (state.ready) {
193
- return LoadingState.FadeOut;
194
- }
195
- break;
196
- case LoadingState.FadeOut:
197
- clearInterval(i);
198
- return LoadingState.Done;
199
- }
200
-
201
- return tick;
202
- });
203
- }, DELAY_PLACEHOLDER);
204
-
205
- return () => clearInterval(i);
206
- }, []);
207
-
208
- return stage;
209
- };
210
-
211
- type AppProps = Pick<CreateAppOptions, 'placeholder'> & {
212
- state: { ready: boolean; error: unknown };
213
- };
214
-
215
- const App = ({ placeholder: Placeholder, state }: AppProps) => {
216
- const reactContexts = useCapabilities(Capabilities.ReactContext);
217
- const reactRoots = useCapabilities(Capabilities.ReactRoot);
218
- const stage = useLoading(state);
219
-
220
- if (state.error) {
221
- // This triggers the error boundary to provide UI feedback for the startup error.
222
- throw state.error;
223
- }
224
-
225
- // TODO(wittjosiah): Consider using Suspense instead?
226
- if (stage < LoadingState.Done) {
227
- if (!Placeholder) {
228
- return null;
229
- }
230
-
231
- return <Placeholder stage={stage} />;
232
- }
233
-
234
- const ComposedContext = composeContexts(reactContexts);
235
- return (
236
- <ComposedContext>
237
- {reactRoots.map(({ id, root: Component }) => (
238
- <Component key={id} />
239
- ))}
240
- </ComposedContext>
241
- );
242
- };
243
-
244
- // Default fallback does not use tailwind or theme.
245
- const DefaultFallback = ({ error }: { error: Error }) => {
246
- return (
247
- <div
248
- style={{
249
- margin: '1rem',
250
- padding: '1rem',
251
- overflow: 'hidden',
252
- border: '4px solid teal',
253
- borderRadius: '1rem',
254
- }}
255
- >
256
- {/* TODO(wittjosiah): Link to docs for replacing default. */}
257
- <h1 style={{ margin: '0.5rem 0', fontSize: '1.2rem' }}>[ERROR]: {error.message}</h1>
258
- <pre style={{ overflow: 'auto', fontSize: '1rem', whiteSpace: 'pre-wrap', color: '#888888' }}>{error.stack}</pre>
259
- </div>
260
- );
261
- };
262
-
263
- const composeContexts = (contexts: Capabilities.ReactContext[]) => {
264
- if (contexts.length === 0) {
265
- return ({ children }: PropsWithChildren) => <>{children}</>;
266
- }
267
-
268
- return topologicalSort(contexts)
269
- .map(({ context }) => context)
270
- .reduce((Acc, Next) => ({ children }) => (
271
- <Acc>
272
- <Next>{children}</Next>
273
- </Acc>
274
- ));
275
- };
276
-
277
162
  const setupDevtools = (manager: PluginManager) => {
278
163
  (globalThis as any).composer ??= {};
279
164
  (globalThis as any).composer.manager = manager;
@@ -2,7 +2,7 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
- import { useRxValue } from '@effect-rx/rx-react';
5
+ import { useAtomValue } from '@effect-atom/atom-react';
6
6
 
7
7
  import { invariant } from '@dxos/invariant';
8
8
 
@@ -16,7 +16,7 @@ import { usePluginManager } from './PluginManagerProvider';
16
16
  */
17
17
  export const useCapabilities = <T>(interfaceDef: InterfaceDef<T>) => {
18
18
  const manager = usePluginManager();
19
- return useRxValue(manager.context.capabilities(interfaceDef));
19
+ return useAtomValue(manager.context.capabilities(interfaceDef));
20
20
  };
21
21
 
22
22
  /**