@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.
- package/.storybook/main.mts +11 -0
- package/.storybook/preview.mts +8 -0
- package/dist/lib/browser/{app-graph-builder-AFFC6VB2.mjs → app-graph-builder-OIEZZC45.mjs} +31 -30
- package/dist/lib/browser/app-graph-builder-OIEZZC45.mjs.map +7 -0
- package/dist/lib/browser/{chunk-ORWHM7CO.mjs → chunk-SCPE4ZO2.mjs} +11 -8
- package/dist/lib/browser/chunk-SCPE4ZO2.mjs.map +7 -0
- package/dist/lib/browser/{chunk-DND4XMN4.mjs → chunk-VFUKEZIN.mjs} +233 -191
- package/dist/lib/browser/chunk-VFUKEZIN.mjs.map +7 -0
- package/dist/lib/browser/{chunk-OZY7HV2A.mjs → chunk-WPW5VVAX.mjs} +281 -273
- package/dist/lib/browser/chunk-WPW5VVAX.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +14 -56
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/{intent-dispatcher-QG7UPGQX.mjs → intent-dispatcher-LZ4AE66E.mjs} +2 -2
- package/dist/lib/browser/{intent-resolver-4S4PSTM5.mjs → intent-resolver-QVCKRX6G.mjs} +7 -7
- package/dist/lib/browser/intent-resolver-QVCKRX6G.mjs.map +7 -0
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/react/index.mjs +34 -0
- package/dist/lib/browser/{store-6E33KLGK.mjs → store-CNPHOYTJ.mjs} +5 -5
- package/dist/lib/browser/store-CNPHOYTJ.mjs.map +7 -0
- package/dist/lib/browser/testing/index.mjs +14 -16
- package/dist/lib/browser/testing/index.mjs.map +3 -3
- package/dist/lib/node-esm/{app-graph-builder-S4OAULX5.mjs → app-graph-builder-EBU4NVWD.mjs} +31 -30
- package/dist/lib/node-esm/app-graph-builder-EBU4NVWD.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-E2TK7Z4P.mjs → chunk-IJOHO66N.mjs} +233 -191
- package/dist/lib/node-esm/chunk-IJOHO66N.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-F63ZRXMK.mjs → chunk-XJZGUJ3H.mjs} +281 -273
- package/dist/lib/node-esm/chunk-XJZGUJ3H.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-UMZQERLE.mjs → chunk-ZX63QUGE.mjs} +11 -8
- package/dist/lib/node-esm/chunk-ZX63QUGE.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +14 -56
- package/dist/lib/node-esm/index.mjs.map +3 -3
- package/dist/lib/node-esm/{intent-dispatcher-NXBGPJOX.mjs → intent-dispatcher-MGOJ3CHD.mjs} +2 -2
- package/dist/lib/node-esm/{intent-resolver-2ZKXI5ET.mjs → intent-resolver-URF3HN3G.mjs} +7 -7
- package/dist/lib/node-esm/intent-resolver-URF3HN3G.mjs.map +7 -0
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/react/index.mjs +35 -0
- package/dist/lib/node-esm/{store-QQUTQHHT.mjs → store-RK5B4XEL.mjs} +5 -5
- package/dist/lib/node-esm/store-RK5B4XEL.mjs.map +7 -0
- package/dist/lib/node-esm/testing/index.mjs +14 -16
- package/dist/lib/node-esm/testing/index.mjs.map +3 -3
- package/dist/types/src/common/capabilities.d.ts +41 -37
- package/dist/types/src/common/capabilities.d.ts.map +1 -1
- package/dist/types/src/common/collaboration.d.ts +1 -1
- package/dist/types/src/common/collaboration.d.ts.map +1 -1
- package/dist/types/src/common/file.d.ts +1 -1
- package/dist/types/src/common/file.d.ts.map +1 -1
- package/dist/types/src/common/layout.d.ts +1 -3
- package/dist/types/src/common/layout.d.ts.map +1 -1
- package/dist/types/src/common/surface.d.ts +19 -16
- package/dist/types/src/common/surface.d.ts.map +1 -1
- package/dist/types/src/common/translations.d.ts +1 -1
- package/dist/types/src/common/translations.d.ts.map +1 -1
- package/dist/types/src/core/capabilities.d.ts +15 -15
- package/dist/types/src/core/capabilities.d.ts.map +1 -1
- package/dist/types/src/core/manager.d.ts +1 -1
- package/dist/types/src/core/manager.d.ts.map +1 -1
- package/dist/types/src/core/plugin.d.ts +8 -1
- package/dist/types/src/core/plugin.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +0 -2
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/playground/debug/plugin.d.ts +1 -1
- package/dist/types/src/playground/debug/plugin.d.ts.map +1 -1
- package/dist/types/src/playground/generator/Main.d.ts.map +1 -1
- package/dist/types/src/playground/generator/generator.d.ts +1 -1
- package/dist/types/src/playground/generator/generator.d.ts.map +1 -1
- package/dist/types/src/playground/generator/plugin.d.ts +1 -1
- package/dist/types/src/playground/generator/plugin.d.ts.map +1 -1
- package/dist/types/src/playground/layout/plugin.d.ts +1 -1
- package/dist/types/src/playground/layout/plugin.d.ts.map +1 -1
- package/dist/types/src/playground/logger/plugin.d.ts +1 -1
- package/dist/types/src/playground/logger/plugin.d.ts.map +1 -1
- package/dist/types/src/playground/logger/schema.d.ts +1 -1
- package/dist/types/src/playground/logger/schema.d.ts.map +1 -1
- package/dist/types/src/playground/playground.stories.d.ts +0 -1
- package/dist/types/src/playground/playground.stories.d.ts.map +1 -1
- package/dist/types/src/plugin-intent/IntentPlugin.d.ts +1 -1
- package/dist/types/src/plugin-intent/IntentPlugin.d.ts.map +1 -1
- package/dist/types/src/plugin-intent/actions.d.ts +5 -7
- package/dist/types/src/plugin-intent/actions.d.ts.map +1 -1
- package/dist/types/src/plugin-intent/errors.d.ts.map +1 -1
- package/dist/types/src/plugin-intent/intent-dispatcher.d.ts +4 -4
- package/dist/types/src/plugin-intent/intent-dispatcher.d.ts.map +1 -1
- package/dist/types/src/plugin-intent/intent.d.ts +1 -1
- package/dist/types/src/plugin-intent/intent.d.ts.map +1 -1
- package/dist/types/src/plugin-intent/meta.d.ts +3 -0
- package/dist/types/src/plugin-intent/meta.d.ts.map +1 -0
- package/dist/types/src/plugin-settings/SettingsPlugin.d.ts +1 -1
- package/dist/types/src/plugin-settings/SettingsPlugin.d.ts.map +1 -1
- package/dist/types/src/plugin-settings/actions.d.ts +5 -7
- package/dist/types/src/plugin-settings/actions.d.ts.map +1 -1
- package/dist/types/src/plugin-settings/app-graph-builder.d.ts.map +1 -1
- package/dist/types/src/plugin-settings/meta.d.ts +3 -0
- package/dist/types/src/plugin-settings/meta.d.ts.map +1 -0
- package/dist/types/src/plugin-settings/translations.d.ts +2 -1
- package/dist/types/src/plugin-settings/translations.d.ts.map +1 -1
- package/dist/types/src/react/App.d.ts +10 -0
- package/dist/types/src/react/App.d.ts.map +1 -0
- package/dist/types/src/react/App.stories.d.ts +14 -0
- package/dist/types/src/react/App.stories.d.ts.map +1 -0
- package/dist/types/src/react/DefaultFallback.d.ts +8 -0
- package/dist/types/src/react/DefaultFallback.d.ts.map +1 -0
- package/dist/types/src/react/ErrorBoundary.d.ts +2 -2
- package/dist/types/src/react/ErrorBoundary.d.ts.map +1 -1
- package/dist/types/src/react/Surface.d.ts +5 -5
- package/dist/types/src/react/Surface.d.ts.map +1 -1
- package/dist/types/src/react/Surface.stories.d.ts +3 -7
- package/dist/types/src/react/Surface.stories.d.ts.map +1 -1
- package/dist/types/src/react/index.d.ts +2 -0
- package/dist/types/src/react/index.d.ts.map +1 -1
- package/dist/types/src/react/types.d.ts +14 -0
- package/dist/types/src/react/types.d.ts.map +1 -0
- package/dist/types/src/{App.d.ts → react/useApp.d.ts} +7 -6
- package/dist/types/src/react/useApp.d.ts.map +1 -0
- package/dist/types/src/react/useLoading.d.ts +19 -0
- package/dist/types/src/react/useLoading.d.ts.map +1 -0
- package/dist/types/src/testing/withPluginManager.d.ts +7 -8
- package/dist/types/src/testing/withPluginManager.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/moon.yml +5 -1
- package/package.json +44 -40
- package/src/common/capabilities.ts +34 -19
- package/src/common/collaboration.ts +3 -3
- package/src/common/file.ts +1 -1
- package/src/common/layout.ts +3 -4
- package/src/common/surface.ts +23 -21
- package/src/common/translations.ts +1 -1
- package/src/core/capabilities.test.ts +2 -2
- package/src/core/capabilities.ts +26 -22
- package/src/core/manager.test.ts +19 -19
- package/src/core/manager.ts +14 -7
- package/src/core/plugin.ts +13 -2
- package/src/index.ts +0 -2
- package/src/playground/debug/Debug.tsx +1 -1
- package/src/playground/debug/plugin.ts +7 -8
- package/src/playground/generator/Main.tsx +0 -1
- package/src/playground/generator/generator.ts +2 -2
- package/src/playground/generator/plugin.ts +12 -13
- package/src/playground/layout/plugin.ts +9 -8
- package/src/playground/logger/plugin.ts +27 -23
- package/src/playground/logger/schema.ts +1 -1
- package/src/playground/playground.stories.tsx +6 -7
- package/src/plugin-intent/IntentPlugin.ts +12 -13
- package/src/plugin-intent/actions.ts +4 -6
- package/src/plugin-intent/errors.ts +2 -1
- package/src/plugin-intent/intent-dispatcher.test.ts +10 -3
- package/src/plugin-intent/intent-dispatcher.ts +13 -6
- package/src/plugin-intent/intent.ts +1 -1
- package/src/plugin-intent/meta.ts +10 -0
- package/src/plugin-settings/SettingsPlugin.ts +25 -27
- package/src/plugin-settings/actions.ts +9 -13
- package/src/plugin-settings/app-graph-builder.ts +22 -20
- package/src/plugin-settings/intent-resolver.ts +2 -2
- package/src/plugin-settings/meta.ts +10 -0
- package/src/plugin-settings/store.ts +2 -2
- package/src/plugin-settings/translations.ts +4 -4
- package/src/react/App.stories.tsx +33 -0
- package/src/react/App.tsx +59 -0
- package/src/react/DefaultFallback.tsx +26 -0
- package/src/react/ErrorBoundary.tsx +10 -8
- package/src/react/Surface.stories.tsx +70 -49
- package/src/react/Surface.tsx +67 -36
- package/src/react/index.ts +4 -0
- package/src/react/types.ts +37 -0
- package/src/{App.tsx → react/useApp.tsx} +35 -150
- package/src/react/useCapabilities.ts +2 -2
- package/src/react/useLoading.tsx +70 -0
- package/src/testing/withPluginManager.stories.tsx +1 -1
- package/src/testing/withPluginManager.tsx +24 -23
- package/tsconfig.json +11 -9
- package/vitest.config.ts +8 -6
- package/dist/lib/browser/app-graph-builder-AFFC6VB2.mjs.map +0 -7
- package/dist/lib/browser/chunk-DND4XMN4.mjs.map +0 -7
- package/dist/lib/browser/chunk-ORWHM7CO.mjs.map +0 -7
- package/dist/lib/browser/chunk-OZY7HV2A.mjs.map +0 -7
- package/dist/lib/browser/intent-resolver-4S4PSTM5.mjs.map +0 -7
- package/dist/lib/browser/store-6E33KLGK.mjs.map +0 -7
- package/dist/lib/browser/worker.mjs +0 -85
- package/dist/lib/node-esm/app-graph-builder-S4OAULX5.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-E2TK7Z4P.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-F63ZRXMK.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-UMZQERLE.mjs.map +0 -7
- package/dist/lib/node-esm/intent-resolver-2ZKXI5ET.mjs.map +0 -7
- package/dist/lib/node-esm/store-QQUTQHHT.mjs.map +0 -7
- package/dist/lib/node-esm/worker.mjs +0 -86
- package/dist/types/src/App.d.ts.map +0 -1
- package/dist/types/src/worker.d.ts +0 -4
- package/dist/types/src/worker.d.ts.map +0 -1
- package/src/worker.ts +0 -11
- /package/dist/lib/browser/{intent-dispatcher-QG7UPGQX.mjs.map → intent-dispatcher-LZ4AE66E.mjs.map} +0 -0
- /package/dist/lib/browser/{worker.mjs.map → react/index.mjs.map} +0 -0
- /package/dist/lib/node-esm/{intent-dispatcher-NXBGPJOX.mjs.map → intent-dispatcher-MGOJ3CHD.mjs.map} +0 -0
- /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 {
|
|
12
|
-
import {
|
|
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 {
|
|
16
|
-
import { setupPluginManager } from '../testing';
|
|
14
|
+
import { withPluginManager } from '../testing';
|
|
17
15
|
|
|
18
|
-
import {
|
|
16
|
+
import { usePluginManager } from './PluginManagerProvider';
|
|
19
17
|
import { Surface, useSurfaces } from './Surface';
|
|
20
18
|
|
|
21
|
-
const
|
|
22
|
-
const
|
|
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:
|
|
35
|
-
const
|
|
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:
|
|
33
|
+
role: 'item',
|
|
34
|
+
filter: (data): data is any => (data as any)?.id === id,
|
|
43
35
|
component: () => (
|
|
44
|
-
<div className='flex-
|
|
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
|
-
|
|
43
|
+
setSelected(id);
|
|
52
44
|
}, [manager]);
|
|
53
45
|
|
|
54
|
-
const
|
|
55
|
-
|
|
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
|
|
60
|
-
<
|
|
61
|
-
<Button onClick={handleAdd}>Add</Button>
|
|
62
|
-
<Button onClick={
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
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='
|
|
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
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
manager: setupPluginManager(),
|
|
115
|
+
decorators: [withTheme, withPluginManager({ capabilities: [] })],
|
|
116
|
+
parameters: {
|
|
117
|
+
layout: 'fullscreen',
|
|
97
118
|
},
|
|
98
119
|
} satisfies Meta<typeof DefaultStory>;
|
|
99
120
|
|
package/src/react/Surface.tsx
CHANGED
|
@@ -2,7 +2,15 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import 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
|
|
49
|
-
(
|
|
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
|
|
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(
|
|
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
|
|
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
|
|
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';
|
package/src/react/index.ts
CHANGED
|
@@ -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-
|
|
5
|
+
import { RegistryContext } from '@effect-atom/atom-react';
|
|
6
6
|
import { effect } from '@preact/signals-core';
|
|
7
|
-
import React, { type FC,
|
|
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 '
|
|
14
|
-
import { type Plugin, PluginManager, type PluginManagerOptions } from '
|
|
15
|
-
|
|
16
|
-
import {
|
|
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
|
|
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 =
|
|
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:
|
|
60
|
-
plugins:
|
|
61
|
-
core:
|
|
62
|
-
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
|
-
|
|
68
|
-
|
|
69
|
-
const
|
|
70
|
-
const
|
|
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
|
-
|
|
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
|
-
[
|
|
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.
|
|
131
|
+
interface: Capabilities.AtomRegistry,
|
|
123
132
|
implementation: manager.registry,
|
|
124
|
-
module: 'dxos.org/app-framework/
|
|
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 {
|
|
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
|
|
19
|
+
return useAtomValue(manager.context.capabilities(interfaceDef));
|
|
20
20
|
};
|
|
21
21
|
|
|
22
22
|
/**
|