@dxos/app-framework 0.7.5-labs.e27f9b9 → 0.7.5-main.2567c87
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/{chunk-G3HBVVT5.mjs → chunk-GNLU3GAU.mjs} +819 -627
- package/dist/lib/browser/chunk-GNLU3GAU.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +74 -57
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +3 -10
- package/dist/lib/browser/testing/index.mjs.map +3 -3
- package/dist/lib/node/chunk-FBA4BB3J.cjs +1639 -0
- package/dist/lib/node/chunk-FBA4BB3J.cjs.map +7 -0
- package/dist/lib/node/index.cjs +118 -106
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/testing/index.cjs +8 -15
- package/dist/lib/node/testing/index.cjs.map +3 -3
- package/dist/lib/node-esm/{chunk-ZTB4TA6Q.mjs → chunk-KPMTPXQI.mjs} +819 -627
- package/dist/lib/node-esm/chunk-KPMTPXQI.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +74 -57
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/testing/index.mjs +3 -10
- package/dist/lib/node-esm/testing/index.mjs.map +3 -3
- package/dist/types/src/App.d.ts.map +1 -1
- package/dist/types/src/common/capabilities.d.ts +110 -66
- package/dist/types/src/common/capabilities.d.ts.map +1 -1
- package/dist/types/src/common/events.d.ts +1 -8
- package/dist/types/src/common/events.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/graph.d.ts +2 -2
- package/dist/types/src/common/graph.d.ts.map +1 -1
- package/dist/types/src/common/index.d.ts +1 -0
- package/dist/types/src/common/index.d.ts.map +1 -1
- package/dist/types/src/common/layout.d.ts +121 -204
- package/dist/types/src/common/layout.d.ts.map +1 -1
- package/dist/types/src/common/navigation.d.ts +241 -0
- package/dist/types/src/common/navigation.d.ts.map +1 -0
- package/dist/types/src/common/surface.d.ts +3 -3
- package/dist/types/src/common/surface.d.ts.map +1 -1
- package/dist/types/src/common/translations.d.ts +7 -7
- package/dist/types/src/common/translations.d.ts.map +1 -1
- package/dist/types/src/core/capabilities.d.ts +2 -6
- package/dist/types/src/core/capabilities.d.ts.map +1 -1
- package/dist/types/src/core/manager.d.ts +9 -2
- package/dist/types/src/core/manager.d.ts.map +1 -1
- package/dist/types/src/core/plugin.d.ts +2 -5
- package/dist/types/src/core/plugin.d.ts.map +1 -1
- package/dist/types/src/playground/generator/Toolbar.d.ts.map +1 -1
- package/dist/types/src/playground/generator/generator.d.ts +0 -2
- package/dist/types/src/playground/generator/generator.d.ts.map +1 -1
- package/dist/types/src/playground/generator/plugin.d.ts.map +1 -1
- package/dist/types/src/playground/logger/Toolbar.d.ts.map +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/{react → plugin-intent}/IntentContext.d.ts +1 -1
- package/dist/types/src/plugin-intent/IntentContext.d.ts.map +1 -0
- package/dist/types/src/plugin-intent/IntentPlugin.d.ts.map +1 -1
- package/dist/types/src/plugin-intent/actions.d.ts +1 -1
- package/dist/types/src/plugin-intent/actions.d.ts.map +1 -1
- package/dist/types/src/plugin-intent/index.d.ts +1 -0
- package/dist/types/src/plugin-intent/index.d.ts.map +1 -1
- package/dist/types/src/plugin-intent/intent-dispatcher.d.ts +20 -27
- package/dist/types/src/plugin-intent/intent-dispatcher.d.ts.map +1 -1
- package/dist/types/src/plugin-intent/intent.d.ts +3 -3
- package/dist/types/src/plugin-intent/intent.d.ts.map +1 -1
- package/dist/types/src/plugin-settings/SettingsPlugin.d.ts.map +1 -1
- package/dist/types/src/plugin-settings/actions.d.ts +1 -11
- package/dist/types/src/plugin-settings/actions.d.ts.map +1 -1
- package/dist/types/src/react/Surface.d.ts.map +1 -1
- package/dist/types/src/react/index.d.ts +0 -2
- package/dist/types/src/react/index.d.ts.map +1 -1
- package/dist/types/src/react/useCapabilities.d.ts.map +1 -1
- package/dist/types/src/testing/withPluginManager.d.ts +1 -1
- package/dist/types/src/testing/withPluginManager.d.ts.map +1 -1
- package/package.json +21 -28
- package/project.json +3 -3
- package/src/App.tsx +14 -15
- package/src/common/capabilities.ts +11 -26
- package/src/common/events.ts +1 -10
- package/src/common/file.ts +1 -1
- package/src/common/graph.ts +2 -2
- package/src/common/index.ts +1 -0
- package/src/common/layout.ts +126 -194
- package/src/common/navigation.ts +199 -0
- package/src/common/surface.ts +2 -2
- package/src/common/translations.ts +8 -7
- package/src/core/capabilities.ts +7 -16
- package/src/core/manager.test.ts +73 -22
- package/src/core/manager.ts +91 -105
- package/src/core/plugin.ts +3 -6
- package/src/playground/debug/plugin.ts +1 -1
- package/src/playground/generator/Toolbar.tsx +11 -11
- package/src/playground/generator/generator.ts +0 -25
- package/src/playground/generator/plugin.ts +1 -6
- package/src/playground/layout/plugin.ts +1 -1
- package/src/playground/logger/Toolbar.tsx +1 -2
- package/src/playground/logger/plugin.ts +3 -6
- package/src/playground/logger/schema.ts +1 -1
- package/src/{react → plugin-intent}/IntentContext.tsx +2 -2
- package/src/plugin-intent/IntentPlugin.tsx +43 -3
- package/src/plugin-intent/actions.ts +1 -1
- package/src/plugin-intent/errors.ts +1 -1
- package/src/plugin-intent/index.ts +1 -0
- package/src/plugin-intent/intent-dispatcher.test.ts +29 -48
- package/src/plugin-intent/intent-dispatcher.ts +41 -76
- package/src/plugin-intent/intent.ts +5 -5
- package/src/plugin-settings/SettingsPlugin.ts +13 -19
- package/src/plugin-settings/actions.ts +1 -11
- package/src/react/Surface.tsx +8 -11
- package/src/react/index.ts +0 -2
- package/src/react/useCapabilities.ts +0 -1
- package/src/testing/withPluginManager.tsx +3 -11
- package/tsconfig.json +3 -6
- package/dist/lib/browser/app-graph-builder-MOLT4EHG.mjs +0 -137
- package/dist/lib/browser/app-graph-builder-MOLT4EHG.mjs.map +0 -7
- package/dist/lib/browser/chunk-G3HBVVT5.mjs.map +0 -7
- package/dist/lib/browser/chunk-LDJ3T4V3.mjs +0 -32
- package/dist/lib/browser/chunk-LDJ3T4V3.mjs.map +0 -7
- package/dist/lib/browser/chunk-TGOF2WQZ.mjs +0 -285
- package/dist/lib/browser/chunk-TGOF2WQZ.mjs.map +0 -7
- package/dist/lib/browser/intent-dispatcher-LJKNIGAM.mjs +0 -11
- package/dist/lib/browser/intent-dispatcher-LJKNIGAM.mjs.map +0 -7
- package/dist/lib/browser/intent-resolver-Z724VAMC.mjs +0 -38
- package/dist/lib/browser/intent-resolver-Z724VAMC.mjs.map +0 -7
- package/dist/lib/browser/store-NWCY7LAP.mjs +0 -19
- package/dist/lib/browser/store-NWCY7LAP.mjs.map +0 -7
- package/dist/lib/browser/worker.mjs +0 -77
- package/dist/lib/browser/worker.mjs.map +0 -7
- package/dist/lib/node/app-graph-builder-G7SRXDFD.cjs +0 -146
- package/dist/lib/node/app-graph-builder-G7SRXDFD.cjs.map +0 -7
- package/dist/lib/node/chunk-55KIQ6YK.cjs +0 -1437
- package/dist/lib/node/chunk-55KIQ6YK.cjs.map +0 -7
- package/dist/lib/node/chunk-5GABBW2Q.cjs +0 -308
- package/dist/lib/node/chunk-5GABBW2Q.cjs.map +0 -7
- package/dist/lib/node/chunk-QLVQ6PND.cjs +0 -58
- package/dist/lib/node/chunk-QLVQ6PND.cjs.map +0 -7
- package/dist/lib/node/intent-dispatcher-CGUK3BCJ.cjs +0 -32
- package/dist/lib/node/intent-dispatcher-CGUK3BCJ.cjs.map +0 -7
- package/dist/lib/node/intent-resolver-7GNKPRWT.cjs +0 -45
- package/dist/lib/node/intent-resolver-7GNKPRWT.cjs.map +0 -7
- package/dist/lib/node/store-WMJSEQPC.cjs +0 -34
- package/dist/lib/node/store-WMJSEQPC.cjs.map +0 -7
- package/dist/lib/node/worker.cjs +0 -99
- package/dist/lib/node/worker.cjs.map +0 -7
- package/dist/lib/node-esm/app-graph-builder-MKLYH3NE.mjs +0 -138
- package/dist/lib/node-esm/app-graph-builder-MKLYH3NE.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-47FG42II.mjs +0 -286
- package/dist/lib/node-esm/chunk-47FG42II.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-CNJYZNSL.mjs +0 -34
- package/dist/lib/node-esm/chunk-CNJYZNSL.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-ZTB4TA6Q.mjs.map +0 -7
- package/dist/lib/node-esm/intent-dispatcher-RZAWA4XD.mjs +0 -12
- package/dist/lib/node-esm/intent-dispatcher-RZAWA4XD.mjs.map +0 -7
- package/dist/lib/node-esm/intent-resolver-UIU37CKJ.mjs +0 -39
- package/dist/lib/node-esm/intent-resolver-UIU37CKJ.mjs.map +0 -7
- package/dist/lib/node-esm/store-YUWINFBN.mjs +0 -20
- package/dist/lib/node-esm/store-YUWINFBN.mjs.map +0 -7
- package/dist/lib/node-esm/worker.mjs +0 -78
- package/dist/lib/node-esm/worker.mjs.map +0 -7
- package/dist/types/src/plugin-settings/app-graph-builder.d.ts +0 -197
- package/dist/types/src/plugin-settings/app-graph-builder.d.ts.map +0 -1
- package/dist/types/src/plugin-settings/intent-resolver.d.ts +0 -4
- package/dist/types/src/plugin-settings/intent-resolver.d.ts.map +0 -1
- package/dist/types/src/plugin-settings/store.d.ts +0 -5
- package/dist/types/src/plugin-settings/store.d.ts.map +0 -1
- package/dist/types/src/plugin-settings/translations.d.ts +0 -11
- package/dist/types/src/plugin-settings/translations.d.ts.map +0 -1
- package/dist/types/src/react/IntentContext.d.ts.map +0 -1
- package/dist/types/src/react/Surface.stories.d.ts +0 -16
- package/dist/types/src/react/Surface.stories.d.ts.map +0 -1
- package/dist/types/src/react/common.d.ts +0 -12
- package/dist/types/src/react/common.d.ts.map +0 -1
- package/dist/types/src/react/useIntentResolver.d.ts +0 -3
- package/dist/types/src/react/useIntentResolver.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/plugin-settings/app-graph-builder.ts +0 -122
- package/src/plugin-settings/intent-resolver.ts +0 -28
- package/src/plugin-settings/store.ts +0 -20
- package/src/plugin-settings/translations.ts +0 -17
- package/src/react/Surface.stories.tsx +0 -96
- package/src/react/common.ts +0 -12
- package/src/react/useIntentResolver.ts +0 -22
- package/src/worker.ts +0 -11
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2024 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { Schema as S } from '@effect/schema';
|
|
6
|
+
|
|
7
|
+
import { pick } from '@dxos/util';
|
|
8
|
+
|
|
9
|
+
// NOTE(thure): These are chosen from RFC 1738’s `safe` characters: http://www.faqs.org/rfcs/rfc1738.html
|
|
10
|
+
export const SLUG_LIST_SEPARATOR = '+';
|
|
11
|
+
export const SLUG_ENTRY_SEPARATOR = '_';
|
|
12
|
+
export const SLUG_KEY_VALUE_SEPARATOR = '-';
|
|
13
|
+
export const SLUG_PATH_SEPARATOR = '~';
|
|
14
|
+
export const SLUG_COLLECTION_INDICATOR = '';
|
|
15
|
+
|
|
16
|
+
const LayoutEntrySchema = S.mutable(S.Struct({ id: S.String, path: S.optional(S.String) }));
|
|
17
|
+
export type LayoutEntry = S.Schema.Type<typeof LayoutEntrySchema>;
|
|
18
|
+
|
|
19
|
+
// TODO(Zan): Consider renaming the 'main' part to 'deck' part now that we are throwing out the old layout plugin.
|
|
20
|
+
// TODO(Zan): Extend to all strings?
|
|
21
|
+
const LayoutPartSchema = S.Union(
|
|
22
|
+
S.Literal('sidebar'),
|
|
23
|
+
S.Literal('main'),
|
|
24
|
+
S.Literal('solo'),
|
|
25
|
+
S.Literal('complementary'),
|
|
26
|
+
S.Literal('fullScreen'),
|
|
27
|
+
);
|
|
28
|
+
export type LayoutPart = S.Schema.Type<typeof LayoutPartSchema>;
|
|
29
|
+
|
|
30
|
+
const LayoutPartsSchema = S.partial(
|
|
31
|
+
S.mutable(S.Record({ key: LayoutPartSchema, value: S.mutable(S.Array(LayoutEntrySchema)) })),
|
|
32
|
+
);
|
|
33
|
+
export type LayoutParts = S.Schema.Type<typeof LayoutPartsSchema>;
|
|
34
|
+
|
|
35
|
+
const LayoutCoordinateSchema = S.mutable(S.Struct({ part: LayoutPartSchema, entryId: S.String }));
|
|
36
|
+
export type LayoutCoordinate = S.Schema.Type<typeof LayoutCoordinateSchema>;
|
|
37
|
+
|
|
38
|
+
const PartAdjustmentSchema = S.Union(
|
|
39
|
+
S.Literal('increment-start'),
|
|
40
|
+
S.Literal('increment-end'),
|
|
41
|
+
S.Literal('pin-start'),
|
|
42
|
+
S.Literal('pin-end'),
|
|
43
|
+
S.Literal('close'),
|
|
44
|
+
S.Literal('solo'),
|
|
45
|
+
);
|
|
46
|
+
export type PartAdjustment = S.Schema.Type<typeof PartAdjustmentSchema>;
|
|
47
|
+
|
|
48
|
+
const LayoutAdjustmentSchema = S.mutable(
|
|
49
|
+
S.Struct({ layoutCoordinate: LayoutCoordinateSchema, type: PartAdjustmentSchema }),
|
|
50
|
+
);
|
|
51
|
+
export type LayoutAdjustment = S.Schema.Type<typeof LayoutAdjustmentSchema>;
|
|
52
|
+
|
|
53
|
+
/** @deprecated */
|
|
54
|
+
export const ActiveParts = S.Record({ key: S.String, value: S.Union(S.String, S.mutable(S.Array(S.String))) });
|
|
55
|
+
export type ActiveParts = S.Schema.Type<typeof ActiveParts>;
|
|
56
|
+
|
|
57
|
+
// TODO(burdon): Where should this go?
|
|
58
|
+
export type LayoutContainerProps<T> = T & { role?: string; coordinate?: LayoutCoordinate };
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Provides for a plugin that can manage the app navigation.
|
|
62
|
+
*/
|
|
63
|
+
const LocationProvidesSchema = S.mutable(
|
|
64
|
+
S.Struct({
|
|
65
|
+
location: S.Struct({
|
|
66
|
+
active: LayoutPartsSchema,
|
|
67
|
+
closed: S.Array(S.String),
|
|
68
|
+
}),
|
|
69
|
+
}),
|
|
70
|
+
);
|
|
71
|
+
export type LocationProvides = S.Schema.Type<typeof LocationProvidesSchema>;
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Type guard for layout plugins.
|
|
75
|
+
*/
|
|
76
|
+
export const isLayoutParts = (value: unknown): value is LayoutParts => {
|
|
77
|
+
return S.is(LayoutPartsSchema)(value);
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
// Type guard for PartAdjustment.
|
|
81
|
+
export const isLayoutAdjustment = (value: unknown): value is LayoutAdjustment => {
|
|
82
|
+
return S.is(LayoutAdjustmentSchema)(value);
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Utilities.
|
|
87
|
+
*/
|
|
88
|
+
|
|
89
|
+
/** Extracts all unique IDs from the layout parts. */
|
|
90
|
+
export const openIds = (layout: LayoutParts, parts?: LayoutPart[]): string[] => {
|
|
91
|
+
return Object.values(parts ? pick(layout, parts) : layout)
|
|
92
|
+
.flatMap((part) => part?.map((entry) => entry.id) ?? [])
|
|
93
|
+
.filter((id): id is string => id !== undefined);
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
export const firstIdInPart = (layout: LayoutParts | undefined, part: LayoutPart): string | undefined => {
|
|
97
|
+
if (!layout) {
|
|
98
|
+
return undefined;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
return layout[part]?.at(0)?.id;
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
export const indexInPart = (
|
|
105
|
+
layout: LayoutParts | undefined,
|
|
106
|
+
layoutCoordinate: LayoutCoordinate | undefined,
|
|
107
|
+
): number | undefined => {
|
|
108
|
+
if (!layout || !layoutCoordinate) {
|
|
109
|
+
return undefined;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const { part, entryId } = layoutCoordinate;
|
|
113
|
+
return layout[part]?.findIndex((entry) => entry.id === entryId);
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
export const partLength = (layout: LayoutParts | undefined, part: LayoutPart | undefined): number => {
|
|
117
|
+
if (!layout || !part) {
|
|
118
|
+
return 0;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
return layout[part]?.length ?? 0;
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
//
|
|
125
|
+
// Intents
|
|
126
|
+
//
|
|
127
|
+
|
|
128
|
+
export const NAVIGATION_PLUGIN = 'dxos.org/plugin/navigation';
|
|
129
|
+
export const NAVIGATION_ACTION = `${NAVIGATION_PLUGIN}/action`;
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Expected payload for navigation actions.
|
|
133
|
+
*/
|
|
134
|
+
// TODO(wittjosiah): These seem to be too deck-specific.
|
|
135
|
+
export namespace NavigationAction {
|
|
136
|
+
/**
|
|
137
|
+
* An additive overlay to apply to `location.active` (i.e. the result is a union of previous active and the argument)
|
|
138
|
+
*/
|
|
139
|
+
export class Open extends S.TaggedClass<Open>()(`${NAVIGATION_ACTION}/open`, {
|
|
140
|
+
input: S.Struct({
|
|
141
|
+
activeParts: ActiveParts,
|
|
142
|
+
noToggle: S.optional(S.Boolean),
|
|
143
|
+
}),
|
|
144
|
+
output: S.Struct({
|
|
145
|
+
open: S.Array(S.String),
|
|
146
|
+
}),
|
|
147
|
+
}) {}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Payload for adding an item to the active items.
|
|
151
|
+
*/
|
|
152
|
+
export class AddToActive extends S.TaggedClass<AddToActive>()(`${NAVIGATION_ACTION}/add-to-active`, {
|
|
153
|
+
input: S.Struct({
|
|
154
|
+
id: S.String,
|
|
155
|
+
part: LayoutPartSchema,
|
|
156
|
+
scrollIntoView: S.optional(S.Boolean),
|
|
157
|
+
pivotId: S.optional(S.String),
|
|
158
|
+
positioning: S.optional(S.Literal('start', 'end')),
|
|
159
|
+
}),
|
|
160
|
+
output: S.Void,
|
|
161
|
+
}) {}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* The active parts to directly set, to be used when working with URLs or restoring a specific state.
|
|
165
|
+
*/
|
|
166
|
+
export class Set extends S.TaggedClass<Set>()(`${NAVIGATION_ACTION}/set`, {
|
|
167
|
+
input: S.Struct({
|
|
168
|
+
activeParts: ActiveParts,
|
|
169
|
+
}),
|
|
170
|
+
output: S.Void,
|
|
171
|
+
}) {}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* A subtractive overlay to apply to `location.active` (i.e. the result is a subtraction from the previous active of the argument)
|
|
175
|
+
*/
|
|
176
|
+
export class Close extends S.TaggedClass<Close>()(`${NAVIGATION_ACTION}/close`, {
|
|
177
|
+
input: S.Struct({
|
|
178
|
+
activeParts: ActiveParts,
|
|
179
|
+
noToggle: S.optional(S.Boolean),
|
|
180
|
+
}),
|
|
181
|
+
output: S.Void,
|
|
182
|
+
}) {}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* An atomic transaction to apply to `location.active`, describing which element to (attempt to) move to which location.
|
|
186
|
+
*/
|
|
187
|
+
export class Adjust extends S.TaggedClass<Adjust>()(`${NAVIGATION_ACTION}/adjust`, {
|
|
188
|
+
input: LayoutAdjustmentSchema,
|
|
189
|
+
output: S.Void,
|
|
190
|
+
}) {}
|
|
191
|
+
|
|
192
|
+
// TODO(wittjosiah): This action seems unrelated to the others.
|
|
193
|
+
export class Expose extends S.TaggedClass<Expose>()(`${NAVIGATION_ACTION}/expose`, {
|
|
194
|
+
input: S.Struct({
|
|
195
|
+
id: S.String,
|
|
196
|
+
}),
|
|
197
|
+
output: S.Void,
|
|
198
|
+
}) {}
|
|
199
|
+
}
|
package/src/common/surface.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
import { type JSX, type ForwardedRef, type PropsWithChildren, type ReactNode } from 'react';
|
|
6
6
|
|
|
7
|
-
import { type GuardedType, type MakeOptional, type
|
|
7
|
+
import { type GuardedType, type MakeOptional, type Disposition } from '@dxos/util';
|
|
8
8
|
|
|
9
9
|
import { type ErrorBoundary } from '../react';
|
|
10
10
|
|
|
@@ -73,7 +73,7 @@ export type SurfaceComponent<T extends Record<string, any> = Record<string, unkn
|
|
|
73
73
|
export type SurfaceDefinition<T extends Record<string, any> = any> = Readonly<{
|
|
74
74
|
id: string;
|
|
75
75
|
role: string | string[];
|
|
76
|
-
|
|
76
|
+
disposition?: Disposition;
|
|
77
77
|
filter?: (data: Record<string, unknown>) => data is T;
|
|
78
78
|
component: SurfaceComponent<GuardedType<SurfaceDefinition<T>['filter']>>;
|
|
79
79
|
}>;
|
|
@@ -2,16 +2,17 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import { z } from 'zod';
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
export
|
|
7
|
+
// TODO(burdon): Replace zod with effect.
|
|
8
|
+
export const ResourceKey = z.union([z.string(), z.record(z.any())]);
|
|
9
|
+
export type ResourceKey = z.infer<typeof ResourceKey>;
|
|
9
10
|
|
|
10
|
-
export const ResourceLanguage =
|
|
11
|
-
export type ResourceLanguage =
|
|
11
|
+
export const ResourceLanguage = z.record(ResourceKey);
|
|
12
|
+
export type ResourceLanguage = z.infer<typeof ResourceLanguage>;
|
|
12
13
|
|
|
13
14
|
/**
|
|
14
15
|
* A resource is a collection of translations for a language.
|
|
15
16
|
*/
|
|
16
|
-
export const Resource =
|
|
17
|
-
export type Resource =
|
|
17
|
+
export const Resource = z.record(ResourceLanguage);
|
|
18
|
+
export type Resource = z.infer<typeof Resource>;
|
package/src/core/capabilities.ts
CHANGED
|
@@ -79,20 +79,17 @@ export const contributes = <T>(
|
|
|
79
79
|
return { interface: interfaceDef, implementation, deactivate } satisfies Capability<T>;
|
|
80
80
|
};
|
|
81
81
|
|
|
82
|
-
type
|
|
83
|
-
type LoadCapabilities<T> = () => Promise<{ default: (props: T) => MaybePromise<AnyCapability[]> }>;
|
|
84
|
-
// TODO(wittjosiah): Not having the array be `any` causes type errors when using the lazy capability.
|
|
85
|
-
type LazyCapability<T, U> = (props?: T) => Promise<() => Promise<Capability<U> | AnyCapability[]>>;
|
|
82
|
+
type LazyCapability<T, U> = () => Promise<{ default: (props: T) => MaybePromise<Capability<U>> }>;
|
|
86
83
|
|
|
87
84
|
/**
|
|
88
85
|
* Helper to define a lazily loaded implementation of a capability.
|
|
89
86
|
*/
|
|
90
87
|
export const lazy =
|
|
91
|
-
<T, U>(c:
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
88
|
+
<T, U>(c: LazyCapability<T, U>) =>
|
|
89
|
+
(props?: T): Promise<Capability<U>> =>
|
|
90
|
+
c().then(({ default: getCapability }) => {
|
|
91
|
+
return getCapability(props as T);
|
|
92
|
+
});
|
|
96
93
|
|
|
97
94
|
/**
|
|
98
95
|
* Context which is passed to plugins, allowing them to interact with each other.
|
|
@@ -139,11 +136,7 @@ export class PluginsContext {
|
|
|
139
136
|
}
|
|
140
137
|
|
|
141
138
|
current.push(new CapabilityImpl(moduleId, implementation));
|
|
142
|
-
log('capability contributed', {
|
|
143
|
-
id: interfaceDef.identifier,
|
|
144
|
-
moduleId,
|
|
145
|
-
count: untracked(() => current.length),
|
|
146
|
-
});
|
|
139
|
+
log('capability contributed', { id: interfaceDef.identifier, count: untracked(() => current.length) });
|
|
147
140
|
}
|
|
148
141
|
|
|
149
142
|
/**
|
|
@@ -159,8 +152,6 @@ export class PluginsContext {
|
|
|
159
152
|
if (index !== -1) {
|
|
160
153
|
current.splice(index, 1);
|
|
161
154
|
log('capability removed', { id: interfaceDef.identifier, count: untracked(() => current.length) });
|
|
162
|
-
} else {
|
|
163
|
-
log.warn('capability not removed', { id: interfaceDef.identifier });
|
|
164
155
|
}
|
|
165
156
|
}
|
|
166
157
|
|
package/src/core/manager.test.ts
CHANGED
|
@@ -62,10 +62,10 @@ describe('PluginManager', () => {
|
|
|
62
62
|
const Test = definePlugin(testMeta, [Hello]);
|
|
63
63
|
|
|
64
64
|
const manager = new PluginManager({ plugins: [Test], core: [], pluginLoader });
|
|
65
|
-
|
|
65
|
+
manager.enable(testMeta.id);
|
|
66
66
|
expect(manager.enabled).toEqual([Test.meta.id]);
|
|
67
67
|
expect(manager.modules).toEqual([Hello]);
|
|
68
|
-
|
|
68
|
+
manager.disable(testMeta.id);
|
|
69
69
|
expect(manager.enabled).toEqual([]);
|
|
70
70
|
expect(manager.modules).toEqual([]);
|
|
71
71
|
});
|
|
@@ -111,8 +111,7 @@ describe('PluginManager', () => {
|
|
|
111
111
|
const Fail = defineModule({
|
|
112
112
|
id: 'dxos.org/test/fail',
|
|
113
113
|
activatesOn: FailEvent,
|
|
114
|
-
|
|
115
|
-
activate: async () => async () => raise(new Error('test')),
|
|
114
|
+
activate: async () => raise(new Error('test')),
|
|
116
115
|
});
|
|
117
116
|
plugins = [definePlugin(testMeta, [Hello, Fail])];
|
|
118
117
|
|
|
@@ -288,7 +287,7 @@ describe('PluginManager', () => {
|
|
|
288
287
|
id: 'dxos.org/test/count',
|
|
289
288
|
activatesOn: Events.Startup,
|
|
290
289
|
activatesBefore: [CountEvent],
|
|
291
|
-
activate:
|
|
290
|
+
activate: (context) => {
|
|
292
291
|
computeTotal(context);
|
|
293
292
|
return contributes(Total, state);
|
|
294
293
|
},
|
|
@@ -329,18 +328,57 @@ describe('PluginManager', () => {
|
|
|
329
328
|
|
|
330
329
|
{
|
|
331
330
|
await manager.disable(Test.meta.id);
|
|
331
|
+
expect(manager.active).toEqual([...Test.modules.map((m) => m.id), Count.meta.id]);
|
|
332
|
+
expect(manager.pendingReset).toEqual([CountEvent.id, Events.Startup.id]);
|
|
333
|
+
|
|
334
|
+
const totals = manager.context.requestCapabilities(Total);
|
|
335
|
+
expect(totals).toHaveLength(1);
|
|
336
|
+
expect(totals[0].total).toEqual(6);
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
{
|
|
340
|
+
await manager.reset(CountEvent);
|
|
332
341
|
expect(manager.active).toEqual([Count.meta.id]);
|
|
333
|
-
expect(manager.pendingReset).toEqual([]);
|
|
342
|
+
expect(manager.pendingReset).toEqual([Events.Startup.id]);
|
|
334
343
|
|
|
335
344
|
const totals = manager.context.requestCapabilities(Total);
|
|
336
345
|
expect(totals).toHaveLength(1);
|
|
337
|
-
// Total doesn't change because it is not reactive.
|
|
338
346
|
expect(totals[0].total).toEqual(6);
|
|
339
347
|
}
|
|
340
348
|
|
|
349
|
+
{
|
|
350
|
+
await manager.reset(Events.Startup);
|
|
351
|
+
expect(manager.active).toEqual([Count.meta.id]);
|
|
352
|
+
expect(manager.pendingReset).toEqual([]);
|
|
353
|
+
|
|
354
|
+
const totals = manager.context.requestCapabilities(Total);
|
|
355
|
+
expect(totals).toHaveLength(1);
|
|
356
|
+
expect(totals[0].total).toEqual(0);
|
|
357
|
+
}
|
|
358
|
+
|
|
341
359
|
{
|
|
342
360
|
await manager.enable(Test.meta.id);
|
|
361
|
+
expect(manager.active).toEqual([Count.meta.id]);
|
|
362
|
+
expect(manager.pendingReset).toEqual([CountEvent.id, Events.Startup.id]);
|
|
363
|
+
|
|
364
|
+
const totals = manager.context.requestCapabilities(Total);
|
|
365
|
+
expect(totals).toHaveLength(1);
|
|
366
|
+
expect(totals[0].total).toEqual(0);
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
{
|
|
370
|
+
await manager.reset(CountEvent);
|
|
343
371
|
expect(manager.active).toEqual([Count.meta.id, ...Test.modules.map((m) => m.id)]);
|
|
372
|
+
expect(manager.pendingReset).toEqual([Events.Startup.id]);
|
|
373
|
+
|
|
374
|
+
const totals = manager.context.requestCapabilities(Total);
|
|
375
|
+
expect(totals).toHaveLength(1);
|
|
376
|
+
expect(totals[0].total).toEqual(0);
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
{
|
|
380
|
+
await manager.reset(Events.Startup);
|
|
381
|
+
expect(manager.active).toEqual([...Test.modules.map((m) => m.id), Count.meta.id]);
|
|
344
382
|
expect(manager.pendingReset).toEqual([]);
|
|
345
383
|
|
|
346
384
|
const totals = manager.context.requestCapabilities(Total);
|
|
@@ -426,6 +464,9 @@ describe('PluginManager', () => {
|
|
|
426
464
|
using activeUpdates = updateCounter(() => {
|
|
427
465
|
const _ = manager.active.length;
|
|
428
466
|
});
|
|
467
|
+
using pendingRemovalUpdates = updateCounter(() => {
|
|
468
|
+
const _ = manager.pendingRemoval.length;
|
|
469
|
+
});
|
|
429
470
|
using eventsFiredUpdates = updateCounter(() => {
|
|
430
471
|
const _ = manager.eventsFired.length;
|
|
431
472
|
});
|
|
@@ -436,6 +477,7 @@ describe('PluginManager', () => {
|
|
|
436
477
|
expect(enabledUpdates.count).toEqual(0);
|
|
437
478
|
expect(modulesUpdates.count).toEqual(0);
|
|
438
479
|
expect(activeUpdates.count).toEqual(0);
|
|
480
|
+
expect(pendingRemovalUpdates.count).toEqual(0);
|
|
439
481
|
expect(eventsFiredUpdates.count).toEqual(0);
|
|
440
482
|
expect(pendingResetUpdates.count).toEqual(0);
|
|
441
483
|
|
|
@@ -444,6 +486,7 @@ describe('PluginManager', () => {
|
|
|
444
486
|
expect(enabledUpdates.count).toEqual(1);
|
|
445
487
|
expect(modulesUpdates.count).toEqual(1);
|
|
446
488
|
expect(activeUpdates.count).toEqual(0);
|
|
489
|
+
expect(pendingRemovalUpdates.count).toEqual(0);
|
|
447
490
|
expect(eventsFiredUpdates.count).toEqual(0);
|
|
448
491
|
expect(pendingResetUpdates.count).toEqual(0);
|
|
449
492
|
|
|
@@ -452,6 +495,7 @@ describe('PluginManager', () => {
|
|
|
452
495
|
expect(enabledUpdates.count).toEqual(1);
|
|
453
496
|
expect(modulesUpdates.count).toEqual(1);
|
|
454
497
|
expect(activeUpdates.count).toEqual(1);
|
|
498
|
+
expect(pendingRemovalUpdates.count).toEqual(0);
|
|
455
499
|
expect(eventsFiredUpdates.count).toEqual(1);
|
|
456
500
|
expect(pendingResetUpdates.count).toEqual(0);
|
|
457
501
|
|
|
@@ -459,15 +503,17 @@ describe('PluginManager', () => {
|
|
|
459
503
|
expect(pluginUpdates.count).toEqual(2);
|
|
460
504
|
expect(enabledUpdates.count).toEqual(2);
|
|
461
505
|
expect(modulesUpdates.count).toEqual(2);
|
|
462
|
-
expect(activeUpdates.count).toEqual(
|
|
506
|
+
expect(activeUpdates.count).toEqual(1);
|
|
507
|
+
expect(pendingRemovalUpdates.count).toEqual(0);
|
|
463
508
|
expect(eventsFiredUpdates.count).toEqual(1);
|
|
464
|
-
expect(pendingResetUpdates.count).toEqual(
|
|
509
|
+
expect(pendingResetUpdates.count).toEqual(1);
|
|
465
510
|
|
|
466
511
|
await manager.activate(CountEvent);
|
|
467
512
|
expect(pluginUpdates.count).toEqual(2);
|
|
468
513
|
expect(enabledUpdates.count).toEqual(2);
|
|
469
514
|
expect(modulesUpdates.count).toEqual(2);
|
|
470
515
|
expect(activeUpdates.count).toEqual(2);
|
|
516
|
+
expect(pendingRemovalUpdates.count).toEqual(0);
|
|
471
517
|
expect(eventsFiredUpdates.count).toEqual(1);
|
|
472
518
|
expect(pendingResetUpdates.count).toEqual(2);
|
|
473
519
|
|
|
@@ -475,42 +521,47 @@ describe('PluginManager', () => {
|
|
|
475
521
|
expect(pluginUpdates.count).toEqual(3);
|
|
476
522
|
expect(enabledUpdates.count).toEqual(3);
|
|
477
523
|
expect(modulesUpdates.count).toEqual(3);
|
|
478
|
-
expect(activeUpdates.count).toEqual(
|
|
524
|
+
expect(activeUpdates.count).toEqual(2);
|
|
525
|
+
expect(pendingRemovalUpdates.count).toEqual(0);
|
|
479
526
|
expect(eventsFiredUpdates.count).toEqual(1);
|
|
480
|
-
expect(pendingResetUpdates.count).toEqual(
|
|
527
|
+
expect(pendingResetUpdates.count).toEqual(3);
|
|
481
528
|
|
|
482
529
|
await manager.reset(CountEvent);
|
|
483
530
|
expect(pluginUpdates.count).toEqual(3);
|
|
484
531
|
expect(enabledUpdates.count).toEqual(3);
|
|
485
532
|
expect(modulesUpdates.count).toEqual(3);
|
|
486
|
-
// Starts at
|
|
487
|
-
expect(activeUpdates.count).toEqual(
|
|
533
|
+
// Starts at 2, plus deactivates 2, plus activates 3.
|
|
534
|
+
expect(activeUpdates.count).toEqual(7);
|
|
535
|
+
expect(pendingRemovalUpdates.count).toEqual(0);
|
|
488
536
|
expect(eventsFiredUpdates.count).toEqual(1);
|
|
489
537
|
expect(pendingResetUpdates.count).toEqual(4);
|
|
490
538
|
|
|
491
539
|
await manager.disable(One.meta.id);
|
|
492
540
|
expect(pluginUpdates.count).toEqual(3);
|
|
493
541
|
expect(enabledUpdates.count).toEqual(4);
|
|
494
|
-
expect(modulesUpdates.count).toEqual(
|
|
495
|
-
expect(activeUpdates.count).toEqual(
|
|
542
|
+
expect(modulesUpdates.count).toEqual(3);
|
|
543
|
+
expect(activeUpdates.count).toEqual(7);
|
|
544
|
+
expect(pendingRemovalUpdates.count).toEqual(1);
|
|
496
545
|
expect(eventsFiredUpdates.count).toEqual(1);
|
|
497
|
-
expect(pendingResetUpdates.count).toEqual(
|
|
546
|
+
expect(pendingResetUpdates.count).toEqual(5);
|
|
498
547
|
|
|
499
548
|
await manager.remove(One.meta.id);
|
|
500
549
|
expect(pluginUpdates.count).toEqual(4);
|
|
501
550
|
expect(enabledUpdates.count).toEqual(4);
|
|
502
|
-
expect(modulesUpdates.count).toEqual(
|
|
503
|
-
expect(activeUpdates.count).toEqual(
|
|
551
|
+
expect(modulesUpdates.count).toEqual(3);
|
|
552
|
+
expect(activeUpdates.count).toEqual(7);
|
|
553
|
+
expect(pendingRemovalUpdates.count).toEqual(1);
|
|
504
554
|
expect(eventsFiredUpdates.count).toEqual(1);
|
|
505
|
-
expect(pendingResetUpdates.count).toEqual(
|
|
555
|
+
expect(pendingResetUpdates.count).toEqual(5);
|
|
506
556
|
|
|
507
557
|
await manager.reset(CountEvent);
|
|
508
558
|
expect(pluginUpdates.count).toEqual(4);
|
|
509
559
|
expect(enabledUpdates.count).toEqual(4);
|
|
510
560
|
expect(modulesUpdates.count).toEqual(4);
|
|
511
|
-
// Starts at
|
|
512
|
-
expect(activeUpdates.count).toEqual(
|
|
561
|
+
// Starts at 7, plus deactivates 3, plus activates 2.
|
|
562
|
+
expect(activeUpdates.count).toEqual(12);
|
|
563
|
+
expect(pendingRemovalUpdates.count).toEqual(2);
|
|
513
564
|
expect(eventsFiredUpdates.count).toEqual(1);
|
|
514
|
-
expect(pendingResetUpdates.count).toEqual(
|
|
565
|
+
expect(pendingResetUpdates.count).toEqual(6);
|
|
515
566
|
});
|
|
516
567
|
});
|