@dxos/app-framework 0.6.12 → 0.6.13-main.548ca8d
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/dist/lib/browser/index.mjs +169 -163
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +183 -182
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node-esm/chunk-ERPIGFBI.mjs +28 -0
- package/dist/lib/node-esm/chunk-ERPIGFBI.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-IY7HCP4K.mjs +22 -0
- package/dist/lib/node-esm/chunk-IY7HCP4K.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-P2TQLXZR.mjs +54 -0
- package/dist/lib/node-esm/chunk-P2TQLXZR.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +683 -0
- package/dist/lib/node-esm/index.mjs.map +7 -0
- package/dist/lib/node-esm/meta.json +1 -0
- package/dist/lib/node-esm/plugin-24ZP3LDU.mjs +40 -0
- package/dist/lib/node-esm/plugin-24ZP3LDU.mjs.map +7 -0
- package/dist/lib/node-esm/plugin-5AAUGDB3.mjs +168 -0
- package/dist/lib/node-esm/plugin-5AAUGDB3.mjs.map +7 -0
- package/dist/types/src/App.d.ts +4 -4
- package/dist/types/src/App.d.ts.map +1 -1
- package/dist/types/src/plugins/PluginHost/PluginContainer.d.ts +14 -0
- package/dist/types/src/plugins/PluginHost/PluginContainer.d.ts.map +1 -0
- package/dist/types/src/plugins/PluginHost/PluginContext.d.ts +4 -4
- package/dist/types/src/plugins/PluginHost/PluginContext.d.ts.map +1 -1
- package/dist/types/src/plugins/PluginHost/PluginHost.d.ts +4 -8
- package/dist/types/src/plugins/PluginHost/PluginHost.d.ts.map +1 -1
- package/dist/types/src/plugins/PluginHost/plugin.d.ts +37 -83
- package/dist/types/src/plugins/PluginHost/plugin.d.ts.map +1 -1
- package/dist/types/src/plugins/PluginHost/plugin.test.d.ts.map +1 -1
- package/dist/types/src/plugins/common/navigation.d.ts +1 -12
- package/dist/types/src/plugins/common/navigation.d.ts.map +1 -1
- package/package.json +14 -11
- package/project.json +3 -8
- package/src/App.tsx +10 -9
- package/src/plugins/PluginHost/PluginContainer.tsx +120 -0
- package/src/plugins/PluginHost/PluginContext.tsx +8 -14
- package/src/plugins/PluginHost/PluginHost.tsx +18 -121
- package/src/plugins/PluginHost/plugin.test.ts +1 -2
- package/src/plugins/PluginHost/plugin.ts +45 -52
- package/src/plugins/common/navigation.ts +4 -12
- package/tsconfig.json +1 -29
- package/vitest.config.ts +9 -0
|
@@ -2,19 +2,20 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import React, { type
|
|
5
|
+
import React, { type ReactNode } from 'react';
|
|
6
6
|
|
|
7
7
|
import { LocalStorageStore } from '@dxos/local-storage';
|
|
8
|
-
import { log } from '@dxos/log';
|
|
9
8
|
|
|
9
|
+
import { PluginContainer } from './PluginContainer';
|
|
10
10
|
import { type PluginContext, PluginProvider } from './PluginContext';
|
|
11
|
-
import { type Plugin, type PluginDefinition, type
|
|
11
|
+
import { type Plugin, type PluginDefinition, type PluginMeta } from './plugin';
|
|
12
12
|
import { ErrorBoundary } from '../SurfacePlugin';
|
|
13
13
|
|
|
14
14
|
export type BootstrapPluginsParams = {
|
|
15
|
-
order: PluginDefinition['meta'][];
|
|
16
15
|
plugins: Record<string, () => Promise<PluginDefinition>>;
|
|
17
|
-
|
|
16
|
+
// Ordered list of plugins.
|
|
17
|
+
meta: PluginMeta[];
|
|
18
|
+
core: string[];
|
|
18
19
|
defaults?: string[];
|
|
19
20
|
fallback?: ErrorBoundary['props']['fallback'];
|
|
20
21
|
placeholder?: ReactNode;
|
|
@@ -33,9 +34,9 @@ const PLUGIN_HOST = 'dxos.org/plugin/host';
|
|
|
33
34
|
* Bootstraps an application by initializing plugins and rendering root components.
|
|
34
35
|
*/
|
|
35
36
|
export const PluginHost = ({
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
core
|
|
37
|
+
plugins,
|
|
38
|
+
meta,
|
|
39
|
+
core,
|
|
39
40
|
defaults = [],
|
|
40
41
|
fallback = DefaultFallback,
|
|
41
42
|
placeholder = null,
|
|
@@ -45,7 +46,7 @@ export const PluginHost = ({
|
|
|
45
46
|
core,
|
|
46
47
|
enabled: [...defaults],
|
|
47
48
|
plugins: [],
|
|
48
|
-
available:
|
|
49
|
+
available: meta.filter(({ id }) => !core.includes(id)),
|
|
49
50
|
setPlugin: (id: string, enabled: boolean) => {
|
|
50
51
|
if (enabled) {
|
|
51
52
|
state.values.enabled.push(id);
|
|
@@ -56,6 +57,7 @@ export const PluginHost = ({
|
|
|
56
57
|
},
|
|
57
58
|
});
|
|
58
59
|
|
|
60
|
+
// Register and load values.
|
|
59
61
|
state.prop({ key: 'enabled', type: LocalStorageStore.json<string[]>() });
|
|
60
62
|
|
|
61
63
|
return {
|
|
@@ -65,11 +67,13 @@ export const PluginHost = ({
|
|
|
65
67
|
},
|
|
66
68
|
provides: {
|
|
67
69
|
plugins: state.values,
|
|
68
|
-
context: ({ children }) =>
|
|
70
|
+
context: ({ children }) => {
|
|
71
|
+
return <PluginProvider value={state.values}>{children}</PluginProvider>;
|
|
72
|
+
},
|
|
69
73
|
root: () => {
|
|
70
74
|
return (
|
|
71
75
|
<ErrorBoundary fallback={fallback}>
|
|
72
|
-
<
|
|
76
|
+
<PluginContainer plugins={plugins} core={core} state={state.values} placeholder={placeholder} />
|
|
73
77
|
</ErrorBoundary>
|
|
74
78
|
);
|
|
75
79
|
},
|
|
@@ -77,6 +81,9 @@ export const PluginHost = ({
|
|
|
77
81
|
};
|
|
78
82
|
};
|
|
79
83
|
|
|
84
|
+
/**
|
|
85
|
+
* Fallback does not use tailwind or theme.
|
|
86
|
+
*/
|
|
80
87
|
const DefaultFallback = ({ error }: { error: Error }) => {
|
|
81
88
|
return (
|
|
82
89
|
<div style={{ padding: '1rem' }}>
|
|
@@ -86,113 +93,3 @@ const DefaultFallback = ({ error }: { error: Error }) => {
|
|
|
86
93
|
</div>
|
|
87
94
|
);
|
|
88
95
|
};
|
|
89
|
-
|
|
90
|
-
type RootProps = {
|
|
91
|
-
order: PluginDefinition['meta'][];
|
|
92
|
-
state: PluginContext;
|
|
93
|
-
definitions: Record<string, () => Promise<PluginDefinition>>;
|
|
94
|
-
core: string[];
|
|
95
|
-
placeholder: ReactNode;
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
const Root = ({ order, core: corePluginIds, definitions, state, placeholder }: RootProps) => {
|
|
99
|
-
const [error, setError] = useState<unknown>();
|
|
100
|
-
|
|
101
|
-
useEffect(() => {
|
|
102
|
-
log('initializing plugins', { enabled: state.enabled });
|
|
103
|
-
const timeout = setTimeout(async () => {
|
|
104
|
-
try {
|
|
105
|
-
const enabledIds = [...corePluginIds, ...state.enabled].sort((a, b) => {
|
|
106
|
-
const indexA = order.findIndex(({ id }) => id === a);
|
|
107
|
-
const indexB = order.findIndex(({ id }) => id === b);
|
|
108
|
-
return indexA - indexB;
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
const enabled = await Promise.all(
|
|
112
|
-
enabledIds
|
|
113
|
-
.map((id) => definitions[id])
|
|
114
|
-
// If local storage indicates a plugin is enabled, but it is not available, ignore it.
|
|
115
|
-
.filter((definition): definition is () => Promise<PluginDefinition> => Boolean(definition))
|
|
116
|
-
.map((definition) => definition()),
|
|
117
|
-
);
|
|
118
|
-
|
|
119
|
-
const plugins = await Promise.all(
|
|
120
|
-
enabled.map(async (definition) => {
|
|
121
|
-
const plugin = await initializePlugin(definition).catch((err) => {
|
|
122
|
-
log.error('Failed to initialize plugin:', { id: definition.meta.id, err });
|
|
123
|
-
return undefined;
|
|
124
|
-
});
|
|
125
|
-
return plugin;
|
|
126
|
-
}),
|
|
127
|
-
).then((plugins) => plugins.filter((plugin): plugin is Plugin => Boolean(plugin)));
|
|
128
|
-
log('plugins initialized', { plugins });
|
|
129
|
-
|
|
130
|
-
await Promise.all(enabled.map((pluginDefinition) => pluginDefinition.ready?.(plugins)));
|
|
131
|
-
log('plugins ready', { plugins });
|
|
132
|
-
|
|
133
|
-
state.plugins = plugins;
|
|
134
|
-
state.ready = true;
|
|
135
|
-
} catch (err) {
|
|
136
|
-
setError(err);
|
|
137
|
-
}
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
return () => {
|
|
141
|
-
clearTimeout(timeout);
|
|
142
|
-
state.ready = false;
|
|
143
|
-
// TODO(wittjosiah): Does this ever need to be called prior to having dynamic plugins?
|
|
144
|
-
// void Promise.all(enabled.map((definition) => definition.unload?.()));
|
|
145
|
-
};
|
|
146
|
-
}, []);
|
|
147
|
-
|
|
148
|
-
if (error) {
|
|
149
|
-
throw error;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
if (!state.ready) {
|
|
153
|
-
return <>{placeholder}</>;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
const ComposedContext = composeContext(state.plugins);
|
|
157
|
-
|
|
158
|
-
return <ComposedContext>{rootComponents(state.plugins)}</ComposedContext>;
|
|
159
|
-
};
|
|
160
|
-
|
|
161
|
-
/**
|
|
162
|
-
* Resolve a `PluginDefinition` into a fully initialized `Plugin`.
|
|
163
|
-
*/
|
|
164
|
-
export const initializePlugin = async <T, U>(pluginDefinition: PluginDefinition<T, U>): Promise<Plugin<T & U>> => {
|
|
165
|
-
const provides = await pluginDefinition.initialize?.();
|
|
166
|
-
return {
|
|
167
|
-
...pluginDefinition,
|
|
168
|
-
provides: {
|
|
169
|
-
...pluginDefinition.provides,
|
|
170
|
-
...provides,
|
|
171
|
-
} as PluginProvides<T & U>,
|
|
172
|
-
};
|
|
173
|
-
};
|
|
174
|
-
|
|
175
|
-
const rootComponents = (plugins: Plugin[]) => {
|
|
176
|
-
return plugins
|
|
177
|
-
.map((plugin) => {
|
|
178
|
-
const Component = plugin.provides.root;
|
|
179
|
-
if (Component) {
|
|
180
|
-
return <Component key={plugin.meta.id} />;
|
|
181
|
-
} else {
|
|
182
|
-
return null;
|
|
183
|
-
}
|
|
184
|
-
})
|
|
185
|
-
.filter((node): node is JSX.Element => Boolean(node));
|
|
186
|
-
};
|
|
187
|
-
|
|
188
|
-
const composeContext = (plugins: Plugin[]) => {
|
|
189
|
-
return compose(plugins.map((p) => p.provides.context!).filter(Boolean));
|
|
190
|
-
};
|
|
191
|
-
|
|
192
|
-
const compose = (contexts: FC<PropsWithChildren>[]) => {
|
|
193
|
-
return [...contexts].reduce((Acc, Next) => ({ children }) => (
|
|
194
|
-
<Acc>
|
|
195
|
-
<Next>{children}</Next>
|
|
196
|
-
</Acc>
|
|
197
|
-
));
|
|
198
|
-
};
|
|
@@ -2,11 +2,10 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { expect } from 'chai';
|
|
6
5
|
import { type FC } from 'react';
|
|
6
|
+
import { describe, expect, test } from 'vitest';
|
|
7
7
|
|
|
8
8
|
import { log } from '@dxos/log';
|
|
9
|
-
import { describe, test } from '@dxos/test';
|
|
10
9
|
|
|
11
10
|
import { type Plugin } from './plugin';
|
|
12
11
|
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import type { IconProps } from '@phosphor-icons/react';
|
|
6
5
|
import type { FC, PropsWithChildren } from 'react';
|
|
7
6
|
|
|
8
7
|
/**
|
|
@@ -21,60 +20,56 @@ export type PluginProvides<TProvides> = TProvides & {
|
|
|
21
20
|
root?: FC<PropsWithChildren>;
|
|
22
21
|
};
|
|
23
22
|
|
|
23
|
+
export type PluginMeta = {
|
|
24
|
+
/**
|
|
25
|
+
* Globally unique ID.
|
|
26
|
+
*
|
|
27
|
+
* Expected to be in the form of a valid URL.
|
|
28
|
+
*
|
|
29
|
+
* @example dxos.org/plugin/example
|
|
30
|
+
*/
|
|
31
|
+
id: string;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Short ID for use in URLs.
|
|
35
|
+
*
|
|
36
|
+
* NOTE: This is especially experimental and likely to change.
|
|
37
|
+
*/
|
|
38
|
+
// TODO(wittjosiah): How should these be managed?
|
|
39
|
+
shortId?: string;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Human-readable name.
|
|
43
|
+
*/
|
|
44
|
+
name?: string;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Short description of plugin functionality.
|
|
48
|
+
*/
|
|
49
|
+
description?: string;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* URL of home page.
|
|
53
|
+
*/
|
|
54
|
+
homePage?: string;
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Tags to help categorize the plugin.
|
|
58
|
+
*/
|
|
59
|
+
tags?: string[];
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* A grep-able symbol string which can be resolved to an icon asset by @ch-ui/icons, via @ch-ui/vite-plugin-icons.
|
|
63
|
+
*/
|
|
64
|
+
icon?: string;
|
|
65
|
+
};
|
|
66
|
+
|
|
24
67
|
/**
|
|
25
68
|
* A unit of containment of modular functionality that can be provided to an application.
|
|
26
69
|
* Plugins provide things like components, state, actions, etc. to the application.
|
|
27
70
|
*/
|
|
28
71
|
export type Plugin<TProvides = {}> = {
|
|
29
|
-
meta:
|
|
30
|
-
/**
|
|
31
|
-
* Globally unique ID.
|
|
32
|
-
*
|
|
33
|
-
* Expected to be in the form of a valid URL.
|
|
34
|
-
*
|
|
35
|
-
* @example dxos.org/plugin/example
|
|
36
|
-
*/
|
|
37
|
-
id: string;
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Short ID for use in URLs.
|
|
41
|
-
*
|
|
42
|
-
* NOTE: This is especially experimental and likely to change.
|
|
43
|
-
*/
|
|
44
|
-
// TODO(wittjosiah): How should these be managed?
|
|
45
|
-
shortId?: string;
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Human-readable name.
|
|
49
|
-
*/
|
|
50
|
-
name?: string;
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Short description of plugin functionality.
|
|
54
|
-
*/
|
|
55
|
-
description?: string;
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* URL of home page.
|
|
59
|
-
*/
|
|
60
|
-
homePage?: string;
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Tags to help categorize the plugin.
|
|
64
|
-
*/
|
|
65
|
-
tags?: string[];
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* Component to render icon for the plugin when displayed in a list.
|
|
69
|
-
* @deprecated
|
|
70
|
-
*/
|
|
71
|
-
iconComponent?: FC<IconProps>;
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* A grep-able symbol string which can be resolved to an icon asset by @ch-ui/icons, via @ch-ui/vite-plugin-icons.
|
|
75
|
-
*/
|
|
76
|
-
iconSymbol?: string;
|
|
77
|
-
};
|
|
72
|
+
meta: PluginMeta;
|
|
78
73
|
|
|
79
74
|
/**
|
|
80
75
|
* Capabilities provided by the plugin.
|
|
@@ -114,8 +109,6 @@ export type PluginDefinition<TProvides = {}, TInitializeProvides = {}> = Omit<Pl
|
|
|
114
109
|
unload?: () => Promise<void>;
|
|
115
110
|
};
|
|
116
111
|
|
|
117
|
-
export const pluginMeta = (meta: Plugin['meta']) => meta;
|
|
118
|
-
|
|
119
112
|
type LazyPlugin<T> = () => Promise<{ default: (props: T) => PluginDefinition }>;
|
|
120
113
|
|
|
121
114
|
export namespace Plugin {
|
|
@@ -2,10 +2,9 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
+
import { Schema as S } from '@effect/schema';
|
|
5
6
|
import { z } from 'zod';
|
|
6
7
|
|
|
7
|
-
import { S } from '@dxos/echo-schema';
|
|
8
|
-
|
|
9
8
|
import type { IntentData } from '../IntentPlugin';
|
|
10
9
|
import type { Plugin } from '../PluginHost';
|
|
11
10
|
|
|
@@ -19,7 +18,6 @@ export const SLUG_COLLECTION_INDICATOR = '';
|
|
|
19
18
|
const LayoutEntrySchema = S.mutable(S.Struct({ id: S.String, path: S.optional(S.String) }));
|
|
20
19
|
export type LayoutEntry = S.Schema.Type<typeof LayoutEntrySchema>;
|
|
21
20
|
|
|
22
|
-
// TODO(Zan): Consider making solo it's own part. It's not really a function of the 'main' part?
|
|
23
21
|
// TODO(Zan): Consider renaming the 'main' part to 'deck' part now that we are throwing out the old layout plugin.
|
|
24
22
|
// TODO(Zan): Extend to all strings?
|
|
25
23
|
const LayoutPartSchema = S.Union(
|
|
@@ -31,7 +29,9 @@ const LayoutPartSchema = S.Union(
|
|
|
31
29
|
);
|
|
32
30
|
export type LayoutPart = S.Schema.Type<typeof LayoutPartSchema>;
|
|
33
31
|
|
|
34
|
-
const LayoutPartsSchema = S.partial(
|
|
32
|
+
const LayoutPartsSchema = S.partial(
|
|
33
|
+
S.mutable(S.Record({ key: LayoutPartSchema, value: S.mutable(S.Array(LayoutEntrySchema)) })),
|
|
34
|
+
);
|
|
35
35
|
export type LayoutParts = S.Schema.Type<typeof LayoutPartsSchema>;
|
|
36
36
|
|
|
37
37
|
const LayoutCoordinateSchema = S.mutable(S.Struct({ part: LayoutPartSchema, entryId: S.String }));
|
|
@@ -52,14 +52,6 @@ export type ActiveParts = z.infer<typeof ActiveParts>;
|
|
|
52
52
|
// TODO(burdon): Where should this go?
|
|
53
53
|
export type LayoutContainerProps<T> = T & { role?: string; coordinate?: LayoutCoordinate };
|
|
54
54
|
|
|
55
|
-
/**
|
|
56
|
-
* Basic state provided by a navigation plugin.
|
|
57
|
-
*/
|
|
58
|
-
export const Attention = z.object({
|
|
59
|
-
attended: z.set(z.string()).optional().describe('Ids of items which have focus.'),
|
|
60
|
-
});
|
|
61
|
-
export type Attention = z.infer<typeof Attention>;
|
|
62
|
-
|
|
63
55
|
/**
|
|
64
56
|
* Provides for a plugin that can manage the app navigation.
|
|
65
57
|
*/
|
package/tsconfig.json
CHANGED
|
@@ -16,35 +16,7 @@
|
|
|
16
16
|
"include": [
|
|
17
17
|
"src"
|
|
18
18
|
],
|
|
19
|
-
"references": [
|
|
20
|
-
{
|
|
21
|
-
"path": "../../common/async"
|
|
22
|
-
},
|
|
23
|
-
{
|
|
24
|
-
"path": "../../common/debug"
|
|
25
|
-
},
|
|
26
|
-
{
|
|
27
|
-
"path": "../../common/invariant"
|
|
28
|
-
},
|
|
29
|
-
{
|
|
30
|
-
"path": "../../common/local-storage"
|
|
31
|
-
},
|
|
32
|
-
{
|
|
33
|
-
"path": "../../common/log"
|
|
34
|
-
},
|
|
35
|
-
{
|
|
36
|
-
"path": "../../common/util"
|
|
37
|
-
},
|
|
38
|
-
{
|
|
39
|
-
"path": "../../core/echo/echo-schema"
|
|
40
|
-
},
|
|
41
|
-
{
|
|
42
|
-
"path": "../app-graph"
|
|
43
|
-
},
|
|
44
|
-
{
|
|
45
|
-
"path": "../client-protocol"
|
|
46
|
-
}
|
|
47
|
-
],
|
|
19
|
+
"references": [],
|
|
48
20
|
"ts-node": {
|
|
49
21
|
"compilerOptions": {
|
|
50
22
|
"module": "CommonJS"
|
package/vitest.config.ts
ADDED