@dxos/app-framework 0.8.4-main.fd6878d → 0.8.4-main.fffef41

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 (209) hide show
  1. package/.storybook/main.mts +11 -0
  2. package/.storybook/preview.mts +8 -0
  3. package/.swc/plugins/linux_x86_64_19.0.0/727453fb3a62f7f1d952a41e051ca8a6f88cadc45cee43c6a4d1aa45f9b75665.wasmer-v7 +0 -0
  4. package/.swc/plugins/{v7_linux_x86_64_13.0.0/fce1bdb8e20a094e4af08bad09cc81497ed0e2e7c51223b07d371063cca18429 → linux_x86_64_19.0.0/fce1bdb8e20a094e4af08bad09cc81497ed0e2e7c51223b07d371063cca18429.wasmer-v7} +0 -0
  5. package/dist/lib/browser/{app-graph-builder-MOVKFH3J.mjs → app-graph-builder-OIEZZC45.mjs} +31 -30
  6. package/dist/lib/browser/app-graph-builder-OIEZZC45.mjs.map +7 -0
  7. package/dist/lib/browser/{chunk-OSBZFKMO.mjs → chunk-6XKO24JP.mjs} +232 -177
  8. package/dist/lib/browser/chunk-6XKO24JP.mjs.map +7 -0
  9. package/dist/lib/browser/{chunk-ORWHM7CO.mjs → chunk-SCPE4ZO2.mjs} +11 -8
  10. package/dist/lib/browser/chunk-SCPE4ZO2.mjs.map +7 -0
  11. package/dist/lib/browser/{chunk-NKCIDYDI.mjs → chunk-WPW5VVAX.mjs} +189 -136
  12. package/dist/lib/browser/chunk-WPW5VVAX.mjs.map +7 -0
  13. package/dist/lib/browser/index.mjs +20 -56
  14. package/dist/lib/browser/index.mjs.map +3 -3
  15. package/dist/lib/browser/{intent-dispatcher-FTTJLVGN.mjs → intent-dispatcher-LZ4AE66E.mjs} +2 -2
  16. package/dist/lib/browser/{intent-resolver-ZCGEAG3E.mjs → intent-resolver-QVCKRX6G.mjs} +7 -7
  17. package/dist/lib/browser/intent-resolver-QVCKRX6G.mjs.map +7 -0
  18. package/dist/lib/browser/meta.json +1 -1
  19. package/dist/lib/browser/react/index.mjs +34 -0
  20. package/dist/lib/browser/{store-3QB6Q2BC.mjs → store-CNPHOYTJ.mjs} +5 -5
  21. package/dist/lib/browser/store-CNPHOYTJ.mjs.map +7 -0
  22. package/dist/lib/browser/testing/index.mjs +17 -21
  23. package/dist/lib/browser/testing/index.mjs.map +3 -3
  24. package/dist/lib/node-esm/{app-graph-builder-ODE4B5GT.mjs → app-graph-builder-EBU4NVWD.mjs} +31 -30
  25. package/dist/lib/node-esm/app-graph-builder-EBU4NVWD.mjs.map +7 -0
  26. package/dist/lib/node-esm/{chunk-WU3QN5B6.mjs → chunk-3UPX5OIS.mjs} +232 -177
  27. package/dist/lib/node-esm/chunk-3UPX5OIS.mjs.map +7 -0
  28. package/dist/lib/node-esm/{chunk-YEN7NKTF.mjs → chunk-XJZGUJ3H.mjs} +189 -136
  29. package/dist/lib/node-esm/chunk-XJZGUJ3H.mjs.map +7 -0
  30. package/dist/lib/node-esm/{chunk-UMZQERLE.mjs → chunk-ZX63QUGE.mjs} +11 -8
  31. package/dist/lib/node-esm/chunk-ZX63QUGE.mjs.map +7 -0
  32. package/dist/lib/node-esm/index.mjs +20 -56
  33. package/dist/lib/node-esm/index.mjs.map +3 -3
  34. package/dist/lib/node-esm/{intent-dispatcher-YQIQ55LJ.mjs → intent-dispatcher-MGOJ3CHD.mjs} +2 -2
  35. package/dist/lib/node-esm/{intent-resolver-KG27L7EQ.mjs → intent-resolver-URF3HN3G.mjs} +7 -7
  36. package/dist/lib/node-esm/intent-resolver-URF3HN3G.mjs.map +7 -0
  37. package/dist/lib/node-esm/meta.json +1 -1
  38. package/dist/lib/node-esm/react/index.mjs +35 -0
  39. package/dist/lib/node-esm/{store-TIJAVO3D.mjs → store-RK5B4XEL.mjs} +5 -5
  40. package/dist/lib/node-esm/store-RK5B4XEL.mjs.map +7 -0
  41. package/dist/lib/node-esm/testing/index.mjs +17 -21
  42. package/dist/lib/node-esm/testing/index.mjs.map +3 -3
  43. package/dist/types/src/common/capabilities.d.ts +41 -43
  44. package/dist/types/src/common/capabilities.d.ts.map +1 -1
  45. package/dist/types/src/common/collaboration.d.ts +10 -9
  46. package/dist/types/src/common/collaboration.d.ts.map +1 -1
  47. package/dist/types/src/common/file.d.ts +1 -1
  48. package/dist/types/src/common/file.d.ts.map +1 -1
  49. package/dist/types/src/common/layout.d.ts +1 -3
  50. package/dist/types/src/common/layout.d.ts.map +1 -1
  51. package/dist/types/src/common/surface.d.ts +19 -16
  52. package/dist/types/src/common/surface.d.ts.map +1 -1
  53. package/dist/types/src/common/translations.d.ts +1 -1
  54. package/dist/types/src/common/translations.d.ts.map +1 -1
  55. package/dist/types/src/core/capabilities.d.ts +19 -16
  56. package/dist/types/src/core/capabilities.d.ts.map +1 -1
  57. package/dist/types/src/core/manager.d.ts +1 -1
  58. package/dist/types/src/core/manager.d.ts.map +1 -1
  59. package/dist/types/src/core/plugin.d.ts +8 -1
  60. package/dist/types/src/core/plugin.d.ts.map +1 -1
  61. package/dist/types/src/index.d.ts +0 -2
  62. package/dist/types/src/index.d.ts.map +1 -1
  63. package/dist/types/src/playground/debug/Debug.d.ts +1 -1
  64. package/dist/types/src/playground/debug/plugin.d.ts +1 -1
  65. package/dist/types/src/playground/debug/plugin.d.ts.map +1 -1
  66. package/dist/types/src/playground/generator/Main.d.ts +1 -1
  67. package/dist/types/src/playground/generator/Main.d.ts.map +1 -1
  68. package/dist/types/src/playground/generator/Toolbar.d.ts +1 -1
  69. package/dist/types/src/playground/generator/generator.d.ts +1 -1
  70. package/dist/types/src/playground/generator/generator.d.ts.map +1 -1
  71. package/dist/types/src/playground/generator/plugin.d.ts +1 -1
  72. package/dist/types/src/playground/generator/plugin.d.ts.map +1 -1
  73. package/dist/types/src/playground/layout/Layout.d.ts +2 -2
  74. package/dist/types/src/playground/layout/plugin.d.ts +1 -1
  75. package/dist/types/src/playground/layout/plugin.d.ts.map +1 -1
  76. package/dist/types/src/playground/logger/Toolbar.d.ts +1 -1
  77. package/dist/types/src/playground/logger/plugin.d.ts +1 -1
  78. package/dist/types/src/playground/logger/plugin.d.ts.map +1 -1
  79. package/dist/types/src/playground/logger/schema.d.ts +1 -1
  80. package/dist/types/src/playground/logger/schema.d.ts.map +1 -1
  81. package/dist/types/src/playground/playground.stories.d.ts +5 -4
  82. package/dist/types/src/playground/playground.stories.d.ts.map +1 -1
  83. package/dist/types/src/plugin-intent/IntentPlugin.d.ts +1 -1
  84. package/dist/types/src/plugin-intent/IntentPlugin.d.ts.map +1 -1
  85. package/dist/types/src/plugin-intent/actions.d.ts +5 -7
  86. package/dist/types/src/plugin-intent/actions.d.ts.map +1 -1
  87. package/dist/types/src/plugin-intent/errors.d.ts.map +1 -1
  88. package/dist/types/src/plugin-intent/index.d.ts +1 -0
  89. package/dist/types/src/plugin-intent/index.d.ts.map +1 -1
  90. package/dist/types/src/plugin-intent/intent-dispatcher.d.ts +5 -5
  91. package/dist/types/src/plugin-intent/intent-dispatcher.d.ts.map +1 -1
  92. package/dist/types/src/plugin-intent/intent.d.ts +1 -1
  93. package/dist/types/src/plugin-intent/intent.d.ts.map +1 -1
  94. package/dist/types/src/plugin-intent/meta.d.ts +3 -0
  95. package/dist/types/src/plugin-intent/meta.d.ts.map +1 -0
  96. package/dist/types/src/plugin-settings/SettingsPlugin.d.ts +1 -1
  97. package/dist/types/src/plugin-settings/SettingsPlugin.d.ts.map +1 -1
  98. package/dist/types/src/plugin-settings/actions.d.ts +5 -7
  99. package/dist/types/src/plugin-settings/actions.d.ts.map +1 -1
  100. package/dist/types/src/plugin-settings/app-graph-builder.d.ts +1 -1
  101. package/dist/types/src/plugin-settings/app-graph-builder.d.ts.map +1 -1
  102. package/dist/types/src/plugin-settings/intent-resolver.d.ts +1 -1
  103. package/dist/types/src/plugin-settings/meta.d.ts +3 -0
  104. package/dist/types/src/plugin-settings/meta.d.ts.map +1 -0
  105. package/dist/types/src/plugin-settings/store.d.ts +1 -1
  106. package/dist/types/src/plugin-settings/translations.d.ts +2 -1
  107. package/dist/types/src/plugin-settings/translations.d.ts.map +1 -1
  108. package/dist/types/src/react/App.d.ts +10 -0
  109. package/dist/types/src/react/App.d.ts.map +1 -0
  110. package/dist/types/src/react/App.stories.d.ts +14 -0
  111. package/dist/types/src/react/App.stories.d.ts.map +1 -0
  112. package/dist/types/src/react/DefaultFallback.d.ts +8 -0
  113. package/dist/types/src/react/DefaultFallback.d.ts.map +1 -0
  114. package/dist/types/src/react/ErrorBoundary.d.ts +2 -2
  115. package/dist/types/src/react/ErrorBoundary.d.ts.map +1 -1
  116. package/dist/types/src/react/Surface.d.ts +5 -5
  117. package/dist/types/src/react/Surface.d.ts.map +1 -1
  118. package/dist/types/src/react/Surface.stories.d.ts +8 -10
  119. package/dist/types/src/react/Surface.stories.d.ts.map +1 -1
  120. package/dist/types/src/react/index.d.ts +2 -0
  121. package/dist/types/src/react/index.d.ts.map +1 -1
  122. package/dist/types/src/react/types.d.ts +14 -0
  123. package/dist/types/src/react/types.d.ts.map +1 -0
  124. package/dist/types/src/{App.d.ts → react/useApp.d.ts} +7 -6
  125. package/dist/types/src/react/useApp.d.ts.map +1 -0
  126. package/dist/types/src/react/useLoading.d.ts +19 -0
  127. package/dist/types/src/react/useLoading.d.ts.map +1 -0
  128. package/dist/types/src/testing/withPluginManager.d.ts +7 -8
  129. package/dist/types/src/testing/withPluginManager.d.ts.map +1 -1
  130. package/dist/types/src/testing/withPluginManager.stories.d.ts +9 -3
  131. package/dist/types/src/testing/withPluginManager.stories.d.ts.map +1 -1
  132. package/dist/types/tsconfig.tsbuildinfo +1 -1
  133. package/moon.yml +5 -1
  134. package/package.json +44 -40
  135. package/src/common/capabilities.ts +33 -25
  136. package/src/common/collaboration.ts +6 -9
  137. package/src/common/file.ts +1 -1
  138. package/src/common/layout.ts +3 -4
  139. package/src/common/surface.ts +23 -21
  140. package/src/common/translations.ts +1 -1
  141. package/src/core/capabilities.test.ts +2 -2
  142. package/src/core/capabilities.ts +35 -27
  143. package/src/core/manager.test.ts +19 -19
  144. package/src/core/manager.ts +14 -7
  145. package/src/core/plugin.ts +13 -2
  146. package/src/index.ts +0 -2
  147. package/src/playground/debug/Debug.tsx +1 -1
  148. package/src/playground/debug/plugin.ts +7 -8
  149. package/src/playground/generator/Main.tsx +0 -1
  150. package/src/playground/generator/generator.ts +2 -2
  151. package/src/playground/generator/plugin.ts +12 -13
  152. package/src/playground/layout/plugin.ts +9 -8
  153. package/src/playground/logger/plugin.ts +27 -23
  154. package/src/playground/logger/schema.ts +1 -1
  155. package/src/playground/playground.stories.tsx +17 -14
  156. package/src/plugin-intent/IntentPlugin.ts +12 -13
  157. package/src/plugin-intent/actions.ts +4 -6
  158. package/src/plugin-intent/errors.ts +2 -1
  159. package/src/plugin-intent/index.ts +1 -0
  160. package/src/plugin-intent/intent-dispatcher.test.ts +10 -3
  161. package/src/plugin-intent/intent-dispatcher.ts +16 -8
  162. package/src/plugin-intent/intent.ts +1 -1
  163. package/src/plugin-intent/meta.ts +10 -0
  164. package/src/plugin-settings/SettingsPlugin.ts +25 -27
  165. package/src/plugin-settings/actions.ts +9 -13
  166. package/src/plugin-settings/app-graph-builder.ts +22 -20
  167. package/src/plugin-settings/intent-resolver.ts +2 -2
  168. package/src/plugin-settings/meta.ts +10 -0
  169. package/src/plugin-settings/store.ts +2 -2
  170. package/src/plugin-settings/translations.ts +4 -4
  171. package/src/react/App.stories.tsx +33 -0
  172. package/src/react/App.tsx +59 -0
  173. package/src/react/DefaultFallback.tsx +26 -0
  174. package/src/react/ErrorBoundary.tsx +10 -8
  175. package/src/react/Surface.stories.tsx +79 -51
  176. package/src/react/Surface.tsx +67 -36
  177. package/src/react/index.ts +4 -0
  178. package/src/react/types.ts +38 -0
  179. package/src/react/useApp.tsx +165 -0
  180. package/src/react/useCapabilities.ts +2 -2
  181. package/src/react/useLoading.tsx +70 -0
  182. package/src/testing/withPluginManager.stories.tsx +7 -4
  183. package/src/testing/withPluginManager.tsx +27 -29
  184. package/tsconfig.json +11 -9
  185. package/vitest.config.ts +8 -6
  186. package/.swc/plugins/v7_linux_x86_64_13.0.0/c614d7475354583212fbd7669acbae95b9832c305bf51bdaabe2e6de05abb6bf +0 -0
  187. package/dist/lib/browser/app-graph-builder-MOVKFH3J.mjs.map +0 -7
  188. package/dist/lib/browser/chunk-NKCIDYDI.mjs.map +0 -7
  189. package/dist/lib/browser/chunk-ORWHM7CO.mjs.map +0 -7
  190. package/dist/lib/browser/chunk-OSBZFKMO.mjs.map +0 -7
  191. package/dist/lib/browser/intent-resolver-ZCGEAG3E.mjs.map +0 -7
  192. package/dist/lib/browser/store-3QB6Q2BC.mjs.map +0 -7
  193. package/dist/lib/browser/worker.mjs +0 -79
  194. package/dist/lib/node-esm/app-graph-builder-ODE4B5GT.mjs.map +0 -7
  195. package/dist/lib/node-esm/chunk-UMZQERLE.mjs.map +0 -7
  196. package/dist/lib/node-esm/chunk-WU3QN5B6.mjs.map +0 -7
  197. package/dist/lib/node-esm/chunk-YEN7NKTF.mjs.map +0 -7
  198. package/dist/lib/node-esm/intent-resolver-KG27L7EQ.mjs.map +0 -7
  199. package/dist/lib/node-esm/store-TIJAVO3D.mjs.map +0 -7
  200. package/dist/lib/node-esm/worker.mjs +0 -80
  201. package/dist/types/src/App.d.ts.map +0 -1
  202. package/dist/types/src/worker.d.ts +0 -4
  203. package/dist/types/src/worker.d.ts.map +0 -1
  204. package/src/App.tsx +0 -284
  205. package/src/worker.ts +0 -11
  206. /package/dist/lib/browser/{intent-dispatcher-FTTJLVGN.mjs.map → intent-dispatcher-LZ4AE66E.mjs.map} +0 -0
  207. /package/dist/lib/browser/{worker.mjs.map → react/index.mjs.map} +0 -0
  208. /package/dist/lib/node-esm/{intent-dispatcher-YQIQ55LJ.mjs.map → intent-dispatcher-MGOJ3CHD.mjs.map} +0 -0
  209. /package/dist/lib/node-esm/{worker.mjs.map → react/index.mjs.map} +0 -0
package/src/App.tsx DELETED
@@ -1,284 +0,0 @@
1
- //
2
- // Copyright 2025 DXOS.org
3
- //
4
-
5
- import { RegistryContext } from '@effect-rx/rx-react';
6
- import { effect } from '@preact/signals-core';
7
- import React, { type FC, type PropsWithChildren, useCallback, useEffect, useMemo, useState } from 'react';
8
-
9
- import { invariant } from '@dxos/invariant';
10
- import { live } from '@dxos/live-object';
11
- import { useDefaultValue } from '@dxos/react-hooks';
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';
17
-
18
- const ENABLED_KEY = 'dxos.org/app-framework/enabled';
19
-
20
- export type CreateAppOptions = {
21
- pluginManager?: PluginManager;
22
- pluginLoader?: PluginManagerOptions['pluginLoader'];
23
- plugins?: Plugin[];
24
- core?: string[];
25
- defaults?: string[];
26
- placeholder?: FC<{ stage: number }>;
27
- fallback?: ErrorBoundary['props']['fallback'];
28
- cacheEnabled?: boolean;
29
- safeMode?: boolean;
30
- };
31
-
32
- /**
33
- * Expected usage is for this to be the entrypoint of the application.
34
- * Initializes plugins and renders the root components.
35
- *
36
- * @example
37
- * const plugins = [LayoutPlugin(), MyPlugin()];
38
- * const core = [LayoutPluginId];
39
- * const default = [MyPluginId];
40
- * const fallback = <div>Initializing Plugins...</div>;
41
- * const App = createApp({ plugins, core, default, fallback });
42
- * createRoot(document.getElementById('root')!).render(
43
- * <StrictMode>
44
- * <App />
45
- * </StrictMode>,
46
- * );
47
- *
48
- * @param params.pluginLoader A function which loads new plugins.
49
- * @param params.plugins All plugins available to the application.
50
- * @param params.core Core plugins which will always be enabled.
51
- * @param params.defaults Default plugins are enabled by default but can be disabled by the user.
52
- * @param params.placeholder Placeholder component to render during startup.
53
- * @param params.fallback Fallback component to render if an error occurs during startup.
54
- * @param params.cacheEnabled Whether to cache enabled plugins in localStorage.
55
- * @param params.safeMode Whether to enable safe mode, which disables optional plugins.
56
- */
57
- export const useApp = ({
58
- pluginManager,
59
- pluginLoader: _pluginLoader,
60
- plugins: _plugins,
61
- core: _core,
62
- defaults: _defaults,
63
- placeholder,
64
- fallback = DefaultFallback,
65
- cacheEnabled = false,
66
- 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
-
72
- // TODO(wittjosiah): Provide a custom plugin loader which supports loading via url.
73
- const pluginLoader = useMemo(
74
- () =>
75
- _pluginLoader ??
76
- ((id: string) => {
77
- const plugin = plugins.find((plugin) => plugin.meta.id === id);
78
- invariant(plugin, `Plugin not found: ${id}`);
79
- return plugin;
80
- }),
81
- [_pluginLoader, plugins],
82
- );
83
-
84
- const state = useMemo(() => live({ ready: false, error: null }), []);
85
- const cached: string[] = useMemo(() => JSON.parse(localStorage.getItem(ENABLED_KEY) ?? '[]'), []);
86
- const enabled = useMemo(
87
- () => (safeMode ? [] : cacheEnabled && cached.length > 0 ? cached : defaults),
88
- [safeMode, cacheEnabled, cached, defaults],
89
- );
90
- const manager = useMemo(
91
- () => pluginManager ?? new PluginManager({ pluginLoader, plugins, core, enabled }),
92
- [pluginManager, pluginLoader, plugins, core, enabled],
93
- );
94
-
95
- useEffect(() => {
96
- return manager.activation.on(({ event, state: _state, error }) => {
97
- // Once the app is ready the first time, don't show the fallback again.
98
- if (!state.ready && event === Events.Startup.id) {
99
- state.ready = _state === 'activated';
100
- }
101
-
102
- if (error && !state.ready && !state.error) {
103
- state.error = error;
104
- }
105
- });
106
- }, [manager, state]);
107
-
108
- useEffect(() => {
109
- effect(() => {
110
- cacheEnabled && localStorage.setItem(ENABLED_KEY, JSON.stringify(manager.enabled));
111
- });
112
- }, [cacheEnabled, manager]);
113
-
114
- useEffect(() => {
115
- manager.context.contributeCapability({
116
- interface: Capabilities.PluginManager,
117
- implementation: manager,
118
- module: 'dxos.org/app-framework/plugin-manager',
119
- });
120
-
121
- manager.context.contributeCapability({
122
- interface: Capabilities.RxRegistry,
123
- implementation: manager.registry,
124
- module: 'dxos.org/app-framework/rx-registry',
125
- });
126
-
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
- useEffect(() => {
138
- const timeout = setTimeout(async () => {
139
- await Promise.all([
140
- // TODO(wittjosiah): Factor out such that this could be called per surface role when attempting to render.
141
- manager.activate(Events.SetupReactSurface),
142
- manager.activate(Events.Startup),
143
- ]);
144
- });
145
-
146
- return () => clearTimeout(timeout);
147
- }, [manager]);
148
-
149
- return useCallback(
150
- () => (
151
- <ErrorBoundary fallback={fallback}>
152
- <PluginManagerProvider value={manager}>
153
- <RegistryContext.Provider value={manager.registry}>
154
- <App placeholder={placeholder} state={state} />
155
- </RegistryContext.Provider>
156
- </PluginManagerProvider>
157
- </ErrorBoundary>
158
- ),
159
- [fallback, manager, placeholder, state],
160
- );
161
- };
162
-
163
- const DELAY_PLACEHOLDER = 2_000;
164
-
165
- enum LoadingState {
166
- Loading = 0,
167
- FadeIn = 1,
168
- FadeOut = 2,
169
- Done = 3,
170
- }
171
-
172
- /**
173
- * To avoid "flashing" the placeholder, we wait a period of time before starting the loading animation.
174
- * If loading completes during this time the placehoder is not shown, otherwise is it displayed for a minimum period of time.
175
- *
176
- * States:
177
- * 0: Loading - Wait for a period of time before starting the loading animation.
178
- * 1: Fade-in - Display a loading animation.
179
- * 2: Fade-out - Fade out the loading animation.
180
- * 3: Done - Remove the placeholder.
181
- */
182
- const useLoading = (state: AppProps['state']) => {
183
- const [stage, setStage] = useState<LoadingState>(LoadingState.Loading);
184
- useEffect(() => {
185
- const i = setInterval(() => {
186
- setStage((tick) => {
187
- switch (tick) {
188
- case LoadingState.Loading:
189
- if (!state.ready) {
190
- return LoadingState.FadeIn;
191
- } else {
192
- clearInterval(i);
193
- return LoadingState.Done;
194
- }
195
- case LoadingState.FadeIn:
196
- if (state.ready) {
197
- return LoadingState.FadeOut;
198
- }
199
- break;
200
- case LoadingState.FadeOut:
201
- clearInterval(i);
202
- return LoadingState.Done;
203
- }
204
-
205
- return tick;
206
- });
207
- }, DELAY_PLACEHOLDER);
208
-
209
- return () => clearInterval(i);
210
- }, []);
211
-
212
- return stage;
213
- };
214
-
215
- type AppProps = Pick<CreateAppOptions, 'placeholder'> & {
216
- state: { ready: boolean; error: unknown };
217
- };
218
-
219
- const App = ({ placeholder: Placeholder, state }: AppProps) => {
220
- const reactContexts = useCapabilities(Capabilities.ReactContext);
221
- const reactRoots = useCapabilities(Capabilities.ReactRoot);
222
- const stage = useLoading(state);
223
-
224
- if (state.error) {
225
- // This triggers the error boundary to provide UI feedback for the startup error.
226
- throw state.error;
227
- }
228
-
229
- // TODO(wittjosiah): Consider using Suspense instead?
230
- if (stage < LoadingState.Done) {
231
- if (!Placeholder) {
232
- return null;
233
- }
234
-
235
- return <Placeholder stage={stage} />;
236
- }
237
-
238
- const ComposedContext = composeContexts(reactContexts);
239
- return (
240
- <ComposedContext>
241
- {reactRoots.map(({ id, root: Component }) => (
242
- <Component key={id} />
243
- ))}
244
- </ComposedContext>
245
- );
246
- };
247
-
248
- // Default fallback does not use tailwind or theme.
249
- const DefaultFallback = ({ error }: { error: Error }) => {
250
- return (
251
- <div
252
- style={{
253
- margin: '1rem',
254
- padding: '1rem',
255
- overflow: 'hidden',
256
- border: '4px solid teal',
257
- borderRadius: '1rem',
258
- }}
259
- >
260
- {/* TODO(wittjosiah): Link to docs for replacing default. */}
261
- <h1 style={{ margin: '0.5rem 0', fontSize: '1.2rem' }}>[ERROR]: {error.message}</h1>
262
- <pre style={{ overflow: 'auto', fontSize: '1rem', whiteSpace: 'pre-wrap', color: '#888888' }}>{error.stack}</pre>
263
- </div>
264
- );
265
- };
266
-
267
- const composeContexts = (contexts: Capabilities.ReactContext[]) => {
268
- if (contexts.length === 0) {
269
- return ({ children }: PropsWithChildren) => <>{children}</>;
270
- }
271
-
272
- return topologicalSort(contexts)
273
- .map(({ context }) => context)
274
- .reduce((Acc, Next) => ({ children }) => (
275
- <Acc>
276
- <Next>{children}</Next>
277
- </Acc>
278
- ));
279
- };
280
-
281
- const setupDevtools = (manager: PluginManager) => {
282
- (globalThis as any).composer ??= {};
283
- (globalThis as any).composer.manager = manager;
284
- };
package/src/worker.ts DELETED
@@ -1,11 +0,0 @@
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';