@dxos/app-framework 0.7.5-feature-compute.4d9d99a → 0.7.5-labs.071a3e2
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/app-graph-builder-MOLT4EHG.mjs +137 -0
- package/dist/lib/browser/app-graph-builder-MOLT4EHG.mjs.map +7 -0
- package/dist/lib/browser/{chunk-EGGZVV7Q.mjs → chunk-G3HBVVT5.mjs} +627 -819
- package/dist/lib/browser/chunk-G3HBVVT5.mjs.map +7 -0
- package/dist/lib/browser/chunk-LDJ3T4V3.mjs +32 -0
- package/dist/lib/browser/chunk-LDJ3T4V3.mjs.map +7 -0
- package/dist/lib/browser/chunk-TGOF2WQZ.mjs +285 -0
- package/dist/lib/browser/chunk-TGOF2WQZ.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +57 -74
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/intent-dispatcher-LJKNIGAM.mjs +11 -0
- package/dist/lib/browser/intent-dispatcher-LJKNIGAM.mjs.map +7 -0
- package/dist/lib/browser/intent-resolver-Z724VAMC.mjs +38 -0
- package/dist/lib/browser/intent-resolver-Z724VAMC.mjs.map +7 -0
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/store-NWCY7LAP.mjs +19 -0
- package/dist/lib/browser/store-NWCY7LAP.mjs.map +7 -0
- package/dist/lib/browser/testing/index.mjs +10 -3
- package/dist/lib/browser/testing/index.mjs.map +3 -3
- package/dist/lib/browser/worker.mjs +77 -0
- package/dist/lib/browser/worker.mjs.map +7 -0
- package/dist/lib/node/app-graph-builder-G7SRXDFD.cjs +146 -0
- package/dist/lib/node/app-graph-builder-G7SRXDFD.cjs.map +7 -0
- package/dist/lib/node/chunk-55KIQ6YK.cjs +1437 -0
- package/dist/lib/node/chunk-55KIQ6YK.cjs.map +7 -0
- package/dist/lib/node/chunk-5GABBW2Q.cjs +308 -0
- package/dist/lib/node/chunk-5GABBW2Q.cjs.map +7 -0
- package/dist/lib/node/chunk-QLVQ6PND.cjs +58 -0
- package/dist/lib/node/chunk-QLVQ6PND.cjs.map +7 -0
- package/dist/lib/node/index.cjs +106 -118
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/intent-dispatcher-CGUK3BCJ.cjs +32 -0
- package/dist/lib/node/intent-dispatcher-CGUK3BCJ.cjs.map +7 -0
- package/dist/lib/node/intent-resolver-7GNKPRWT.cjs +45 -0
- package/dist/lib/node/intent-resolver-7GNKPRWT.cjs.map +7 -0
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/store-WMJSEQPC.cjs +34 -0
- package/dist/lib/node/store-WMJSEQPC.cjs.map +7 -0
- package/dist/lib/node/testing/index.cjs +15 -8
- package/dist/lib/node/testing/index.cjs.map +3 -3
- package/dist/lib/node/worker.cjs +99 -0
- package/dist/lib/node/worker.cjs.map +7 -0
- package/dist/lib/node-esm/app-graph-builder-MKLYH3NE.mjs +138 -0
- package/dist/lib/node-esm/app-graph-builder-MKLYH3NE.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-47FG42II.mjs +286 -0
- package/dist/lib/node-esm/chunk-47FG42II.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-CNJYZNSL.mjs +34 -0
- package/dist/lib/node-esm/chunk-CNJYZNSL.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-HG5P55WF.mjs → chunk-ZTB4TA6Q.mjs} +627 -819
- package/dist/lib/node-esm/chunk-ZTB4TA6Q.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +57 -74
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/intent-dispatcher-RZAWA4XD.mjs +12 -0
- package/dist/lib/node-esm/intent-dispatcher-RZAWA4XD.mjs.map +7 -0
- package/dist/lib/node-esm/intent-resolver-UIU37CKJ.mjs +39 -0
- package/dist/lib/node-esm/intent-resolver-UIU37CKJ.mjs.map +7 -0
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/store-YUWINFBN.mjs +20 -0
- package/dist/lib/node-esm/store-YUWINFBN.mjs.map +7 -0
- package/dist/lib/node-esm/testing/index.mjs +10 -3
- package/dist/lib/node-esm/testing/index.mjs.map +3 -3
- package/dist/lib/node-esm/worker.mjs +78 -0
- package/dist/lib/node-esm/worker.mjs.map +7 -0
- package/dist/types/src/App.d.ts.map +1 -1
- package/dist/types/src/common/capabilities.d.ts +66 -110
- package/dist/types/src/common/capabilities.d.ts.map +1 -1
- package/dist/types/src/common/events.d.ts +8 -1
- 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 +0 -1
- package/dist/types/src/common/index.d.ts.map +1 -1
- package/dist/types/src/common/layout.d.ts +204 -121
- package/dist/types/src/common/layout.d.ts.map +1 -1
- 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 +6 -2
- package/dist/types/src/core/capabilities.d.ts.map +1 -1
- package/dist/types/src/core/manager.d.ts +2 -9
- package/dist/types/src/core/manager.d.ts.map +1 -1
- package/dist/types/src/core/plugin.d.ts +5 -2
- 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 +2 -0
- 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/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 +0 -1
- package/dist/types/src/plugin-intent/index.d.ts.map +1 -1
- package/dist/types/src/plugin-intent/intent-dispatcher.d.ts +27 -20
- 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 +11 -1
- package/dist/types/src/plugin-settings/actions.d.ts.map +1 -1
- package/dist/types/src/plugin-settings/app-graph-builder.d.ts +197 -0
- package/dist/types/src/plugin-settings/app-graph-builder.d.ts.map +1 -0
- package/dist/types/src/plugin-settings/intent-resolver.d.ts +4 -0
- package/dist/types/src/plugin-settings/intent-resolver.d.ts.map +1 -0
- package/dist/types/src/plugin-settings/store.d.ts +5 -0
- package/dist/types/src/plugin-settings/store.d.ts.map +1 -0
- package/dist/types/src/plugin-settings/translations.d.ts +11 -0
- package/dist/types/src/plugin-settings/translations.d.ts.map +1 -0
- package/dist/types/src/{plugin-intent → react}/IntentContext.d.ts +1 -1
- package/dist/types/src/react/IntentContext.d.ts.map +1 -0
- package/dist/types/src/react/Surface.d.ts.map +1 -1
- package/dist/types/src/react/Surface.stories.d.ts +16 -0
- package/dist/types/src/react/Surface.stories.d.ts.map +1 -0
- package/dist/types/src/react/common.d.ts +12 -0
- package/dist/types/src/react/common.d.ts.map +1 -0
- 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/useIntentResolver.d.ts +3 -0
- package/dist/types/src/react/useIntentResolver.d.ts.map +1 -0
- package/dist/types/src/testing/withPluginManager.d.ts +1 -1
- package/dist/types/src/testing/withPluginManager.d.ts.map +1 -1
- package/dist/types/src/worker.d.ts +4 -0
- package/dist/types/src/worker.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +27 -21
- package/project.json +3 -3
- package/src/App.tsx +15 -14
- package/src/common/capabilities.ts +26 -11
- package/src/common/events.ts +10 -1
- package/src/common/file.ts +1 -1
- package/src/common/graph.ts +2 -2
- package/src/common/index.ts +0 -1
- package/src/common/layout.ts +194 -126
- package/src/common/surface.ts +2 -2
- package/src/common/translations.ts +7 -8
- package/src/core/capabilities.ts +16 -7
- package/src/core/manager.test.ts +22 -73
- package/src/core/manager.ts +105 -91
- package/src/core/plugin.ts +6 -3
- package/src/playground/debug/plugin.ts +1 -1
- package/src/playground/generator/Toolbar.tsx +11 -11
- package/src/playground/generator/generator.ts +25 -0
- package/src/playground/generator/plugin.ts +6 -1
- package/src/playground/layout/plugin.ts +1 -1
- package/src/playground/logger/Toolbar.tsx +2 -1
- package/src/playground/logger/plugin.ts +6 -3
- package/src/playground/logger/schema.ts +1 -1
- package/src/plugin-intent/IntentPlugin.tsx +3 -43
- package/src/plugin-intent/actions.ts +1 -1
- package/src/plugin-intent/errors.ts +1 -1
- package/src/plugin-intent/index.ts +0 -1
- package/src/plugin-intent/intent-dispatcher.test.ts +48 -29
- package/src/plugin-intent/intent-dispatcher.ts +76 -41
- package/src/plugin-intent/intent.ts +5 -5
- package/src/plugin-settings/SettingsPlugin.ts +19 -13
- package/src/plugin-settings/actions.ts +11 -1
- package/src/plugin-settings/app-graph-builder.ts +122 -0
- package/src/plugin-settings/intent-resolver.ts +28 -0
- package/src/plugin-settings/store.ts +20 -0
- package/src/plugin-settings/translations.ts +17 -0
- package/src/{plugin-intent → react}/IntentContext.tsx +2 -2
- package/src/react/Surface.stories.tsx +96 -0
- package/src/react/Surface.tsx +11 -8
- package/src/react/common.ts +12 -0
- package/src/react/index.ts +2 -0
- package/src/react/useIntentResolver.ts +22 -0
- package/src/testing/withPluginManager.tsx +11 -3
- package/src/worker.ts +11 -0
- package/tsconfig.json +6 -3
- package/dist/lib/browser/chunk-EGGZVV7Q.mjs.map +0 -7
- package/dist/lib/node/chunk-UBX6GP2N.cjs +0 -1639
- package/dist/lib/node/chunk-UBX6GP2N.cjs.map +0 -7
- package/dist/lib/node-esm/chunk-HG5P55WF.mjs.map +0 -7
- package/dist/types/src/common/navigation.d.ts +0 -241
- package/dist/types/src/common/navigation.d.ts.map +0 -1
- package/dist/types/src/plugin-intent/IntentContext.d.ts.map +0 -1
- package/src/common/navigation.ts +0 -199
|
@@ -1,3 +1,94 @@
|
|
|
1
|
+
// packages/sdk/app-framework/src/plugin-intent/intent-dispatcher.ts
|
|
2
|
+
import { Effect as Effect2, Option, pipe as pipe2, Ref } from "effect";
|
|
3
|
+
import { create as create3 } from "@dxos/live-object";
|
|
4
|
+
import { byPosition } from "@dxos/util";
|
|
5
|
+
|
|
6
|
+
// packages/sdk/app-framework/src/plugin-intent/actions.ts
|
|
7
|
+
import { Schema as S2 } from "@effect/schema";
|
|
8
|
+
|
|
9
|
+
// packages/sdk/app-framework/src/plugin-intent/intent.ts
|
|
10
|
+
import { Schema as S } from "@effect/schema";
|
|
11
|
+
var createIntent = (schema, data = {}, params = {}) => {
|
|
12
|
+
const _ = S.validateSync(schema.fields.input)(data);
|
|
13
|
+
const intent = {
|
|
14
|
+
...params,
|
|
15
|
+
_schema: schema,
|
|
16
|
+
id: schema._tag,
|
|
17
|
+
data
|
|
18
|
+
};
|
|
19
|
+
return {
|
|
20
|
+
first: intent,
|
|
21
|
+
last: intent,
|
|
22
|
+
all: [
|
|
23
|
+
intent
|
|
24
|
+
]
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
var chain = (schema, data = {}, params = {}) => (intent) => {
|
|
28
|
+
const intents = "all" in intent ? intent.all : [
|
|
29
|
+
intent
|
|
30
|
+
];
|
|
31
|
+
const first = intents[0];
|
|
32
|
+
const last = {
|
|
33
|
+
...params,
|
|
34
|
+
_schema: schema,
|
|
35
|
+
id: schema._tag,
|
|
36
|
+
data
|
|
37
|
+
};
|
|
38
|
+
return {
|
|
39
|
+
first,
|
|
40
|
+
last,
|
|
41
|
+
all: [
|
|
42
|
+
...intents,
|
|
43
|
+
last
|
|
44
|
+
]
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
var Label = S.Union(S.String, S.mutable(S.Tuple(S.String, S.mutable(S.Struct({
|
|
48
|
+
ns: S.String,
|
|
49
|
+
count: S.optional(S.Number)
|
|
50
|
+
})))));
|
|
51
|
+
|
|
52
|
+
// packages/sdk/app-framework/src/plugin-intent/actions.ts
|
|
53
|
+
var INTENT_PLUGIN = "dxos.org/plugin/intent";
|
|
54
|
+
var INTENT_ACTION = `${INTENT_PLUGIN}/action`;
|
|
55
|
+
var IntentAction;
|
|
56
|
+
(function(IntentAction2) {
|
|
57
|
+
class ShowUndo extends S2.TaggedClass()(`${INTENT_ACTION}/show-undo`, {
|
|
58
|
+
input: S2.Struct({
|
|
59
|
+
message: Label
|
|
60
|
+
}),
|
|
61
|
+
output: S2.Void
|
|
62
|
+
}) {
|
|
63
|
+
}
|
|
64
|
+
IntentAction2.ShowUndo = ShowUndo;
|
|
65
|
+
})(IntentAction || (IntentAction = {}));
|
|
66
|
+
|
|
67
|
+
// packages/sdk/app-framework/src/plugin-intent/errors.ts
|
|
68
|
+
var BaseError = class extends Error {
|
|
69
|
+
constructor(code, message, context) {
|
|
70
|
+
super(message ?? code, {
|
|
71
|
+
cause: context
|
|
72
|
+
});
|
|
73
|
+
this.code = code;
|
|
74
|
+
this.context = context;
|
|
75
|
+
this.name = code;
|
|
76
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
var NoResolversError = class extends BaseError {
|
|
80
|
+
constructor(action) {
|
|
81
|
+
super("NO_RESOLVERS", "No resolvers were found for the action", {
|
|
82
|
+
action
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
var CycleDetectedError = class extends BaseError {
|
|
87
|
+
constructor(context) {
|
|
88
|
+
super("CYCLE_DETECTED", "Intent execution limit exceeded. This is likely due to an infinite loop within intent resolvers.", context);
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
|
|
1
92
|
// packages/sdk/app-framework/src/core/capabilities.ts
|
|
2
93
|
import { effect, untracked } from "@preact/signals-core";
|
|
3
94
|
import { Trigger } from "@dxos/async";
|
|
@@ -24,9 +115,10 @@ var contributes = (interfaceDef, implementation, deactivate) => {
|
|
|
24
115
|
deactivate
|
|
25
116
|
};
|
|
26
117
|
};
|
|
27
|
-
var lazy = (c) => (props) =>
|
|
28
|
-
|
|
29
|
-
|
|
118
|
+
var lazy = (c) => async (props) => {
|
|
119
|
+
const { default: getCapability } = await c();
|
|
120
|
+
return async () => getCapability(props);
|
|
121
|
+
};
|
|
30
122
|
var PluginsContext = class {
|
|
31
123
|
constructor({ activate, reset }) {
|
|
32
124
|
this._definedCapabilities = /* @__PURE__ */ new Map();
|
|
@@ -48,10 +140,11 @@ var PluginsContext = class {
|
|
|
48
140
|
current.push(new CapabilityImpl(moduleId, implementation));
|
|
49
141
|
log("capability contributed", {
|
|
50
142
|
id: interfaceDef.identifier,
|
|
143
|
+
moduleId,
|
|
51
144
|
count: untracked(() => current.length)
|
|
52
145
|
}, {
|
|
53
146
|
F: __dxlog_file,
|
|
54
|
-
L:
|
|
147
|
+
L: 142,
|
|
55
148
|
S: this,
|
|
56
149
|
C: (f, a) => f(...a)
|
|
57
150
|
});
|
|
@@ -72,7 +165,16 @@ var PluginsContext = class {
|
|
|
72
165
|
count: untracked(() => current.length)
|
|
73
166
|
}, {
|
|
74
167
|
F: __dxlog_file,
|
|
75
|
-
L:
|
|
168
|
+
L: 161,
|
|
169
|
+
S: this,
|
|
170
|
+
C: (f, a) => f(...a)
|
|
171
|
+
});
|
|
172
|
+
} else {
|
|
173
|
+
log.warn("capability not removed", {
|
|
174
|
+
id: interfaceDef.identifier
|
|
175
|
+
}, {
|
|
176
|
+
F: __dxlog_file,
|
|
177
|
+
L: 163,
|
|
76
178
|
S: this,
|
|
77
179
|
C: (f, a) => f(...a)
|
|
78
180
|
});
|
|
@@ -105,7 +207,7 @@ var PluginsContext = class {
|
|
|
105
207
|
const capability = this.requestCapabilities(interfaceDef, filter)[0];
|
|
106
208
|
invariant(capability, `No capability found for ${interfaceDef.identifier}`, {
|
|
107
209
|
F: __dxlog_file,
|
|
108
|
-
L:
|
|
210
|
+
L: 199,
|
|
109
211
|
S: this,
|
|
110
212
|
A: [
|
|
111
213
|
"capability",
|
|
@@ -156,7 +258,7 @@ var getEvents = (events) => "type" in events ? events.events : [
|
|
|
156
258
|
|
|
157
259
|
// packages/sdk/app-framework/src/core/manager.ts
|
|
158
260
|
import { untracked as untracked2 } from "@preact/signals-core";
|
|
159
|
-
import { Effect, Either, Match } from "effect";
|
|
261
|
+
import { Array as A, Effect, Either, Match, pipe } from "effect";
|
|
160
262
|
import { Event } from "@dxos/async";
|
|
161
263
|
import { create as create2 } from "@dxos/live-object";
|
|
162
264
|
import { log as log2 } from "@dxos/log";
|
|
@@ -179,7 +281,6 @@ var PluginManager = class {
|
|
|
179
281
|
enabled,
|
|
180
282
|
modules: [],
|
|
181
283
|
active: [],
|
|
182
|
-
pendingRemoval: [],
|
|
183
284
|
pendingReset: [],
|
|
184
285
|
eventsFired: []
|
|
185
286
|
});
|
|
@@ -228,14 +329,6 @@ var PluginManager = class {
|
|
|
228
329
|
return this._state.active;
|
|
229
330
|
}
|
|
230
331
|
/**
|
|
231
|
-
* Ids of modules which are pending removal.
|
|
232
|
-
*
|
|
233
|
-
* @reactive
|
|
234
|
-
*/
|
|
235
|
-
get pendingRemoval() {
|
|
236
|
-
return this._state.pendingRemoval;
|
|
237
|
-
}
|
|
238
|
-
/**
|
|
239
332
|
* Ids of events which have been fired.
|
|
240
333
|
*
|
|
241
334
|
* @reactive
|
|
@@ -261,7 +354,7 @@ var PluginManager = class {
|
|
|
261
354
|
id
|
|
262
355
|
}, {
|
|
263
356
|
F: __dxlog_file2,
|
|
264
|
-
L:
|
|
357
|
+
L: 146,
|
|
265
358
|
S: this,
|
|
266
359
|
C: (f, a) => f(...a)
|
|
267
360
|
});
|
|
@@ -275,12 +368,12 @@ var PluginManager = class {
|
|
|
275
368
|
* @param id The id of the plugin.
|
|
276
369
|
*/
|
|
277
370
|
enable(id) {
|
|
278
|
-
return untracked2(() => {
|
|
371
|
+
return untracked2(async () => {
|
|
279
372
|
log2("enable plugin", {
|
|
280
373
|
id
|
|
281
374
|
}, {
|
|
282
375
|
F: __dxlog_file2,
|
|
283
|
-
L:
|
|
376
|
+
L: 159,
|
|
284
377
|
S: this,
|
|
285
378
|
C: (f, a) => f(...a)
|
|
286
379
|
});
|
|
@@ -295,6 +388,19 @@ var PluginManager = class {
|
|
|
295
388
|
this._addModule(module);
|
|
296
389
|
this._setPendingResetByModule(module);
|
|
297
390
|
});
|
|
391
|
+
log2("pending reset", {
|
|
392
|
+
events: [
|
|
393
|
+
...this.pendingReset
|
|
394
|
+
]
|
|
395
|
+
}, {
|
|
396
|
+
F: __dxlog_file2,
|
|
397
|
+
L: 174,
|
|
398
|
+
S: this,
|
|
399
|
+
C: (f, a) => f(...a)
|
|
400
|
+
});
|
|
401
|
+
await Effect.runPromise(Effect.all(this.pendingReset.map((event) => this._activate(event)), {
|
|
402
|
+
concurrency: "unbounded"
|
|
403
|
+
}));
|
|
298
404
|
return true;
|
|
299
405
|
});
|
|
300
406
|
}
|
|
@@ -308,7 +414,7 @@ var PluginManager = class {
|
|
|
308
414
|
id
|
|
309
415
|
}, {
|
|
310
416
|
F: __dxlog_file2,
|
|
311
|
-
L:
|
|
417
|
+
L: 192,
|
|
312
418
|
S: this,
|
|
313
419
|
C: (f, a) => f(...a)
|
|
314
420
|
});
|
|
@@ -325,12 +431,12 @@ var PluginManager = class {
|
|
|
325
431
|
* @param id The id of the plugin.
|
|
326
432
|
*/
|
|
327
433
|
disable(id) {
|
|
328
|
-
return untracked2(() => {
|
|
434
|
+
return untracked2(async () => {
|
|
329
435
|
log2("disable plugin", {
|
|
330
436
|
id
|
|
331
437
|
}, {
|
|
332
438
|
F: __dxlog_file2,
|
|
333
|
-
L:
|
|
439
|
+
L: 209,
|
|
334
440
|
S: this,
|
|
335
441
|
C: (f, a) => f(...a)
|
|
336
442
|
});
|
|
@@ -344,15 +450,9 @@ var PluginManager = class {
|
|
|
344
450
|
const enabledIndex = this._state.enabled.findIndex((enabled) => enabled === id);
|
|
345
451
|
if (enabledIndex !== -1) {
|
|
346
452
|
this._state.enabled.splice(enabledIndex, 1);
|
|
453
|
+
await Effect.runPromise(this._deactivate(id));
|
|
347
454
|
plugin.modules.forEach((module) => {
|
|
348
|
-
|
|
349
|
-
this._setPendingResetByModule(module);
|
|
350
|
-
if (!this._state.pendingRemoval.includes(module.id)) {
|
|
351
|
-
this._state.pendingRemoval.push(module.id);
|
|
352
|
-
}
|
|
353
|
-
} else {
|
|
354
|
-
this._removeModule(module.id);
|
|
355
|
-
}
|
|
455
|
+
this._removeModule(module.id);
|
|
356
456
|
});
|
|
357
457
|
}
|
|
358
458
|
return true;
|
|
@@ -388,7 +488,7 @@ var PluginManager = class {
|
|
|
388
488
|
id: plugin.meta.id
|
|
389
489
|
}, {
|
|
390
490
|
F: __dxlog_file2,
|
|
391
|
-
L:
|
|
491
|
+
L: 262,
|
|
392
492
|
S: this,
|
|
393
493
|
C: (f, a) => f(...a)
|
|
394
494
|
});
|
|
@@ -403,7 +503,7 @@ var PluginManager = class {
|
|
|
403
503
|
id
|
|
404
504
|
}, {
|
|
405
505
|
F: __dxlog_file2,
|
|
406
|
-
L:
|
|
506
|
+
L: 271,
|
|
407
507
|
S: this,
|
|
408
508
|
C: (f, a) => f(...a)
|
|
409
509
|
});
|
|
@@ -419,7 +519,7 @@ var PluginManager = class {
|
|
|
419
519
|
id: module.id
|
|
420
520
|
}, {
|
|
421
521
|
F: __dxlog_file2,
|
|
422
|
-
L:
|
|
522
|
+
L: 281,
|
|
423
523
|
S: this,
|
|
424
524
|
C: (f, a) => f(...a)
|
|
425
525
|
});
|
|
@@ -434,7 +534,7 @@ var PluginManager = class {
|
|
|
434
534
|
id
|
|
435
535
|
}, {
|
|
436
536
|
F: __dxlog_file2,
|
|
437
|
-
L:
|
|
537
|
+
L: 290,
|
|
438
538
|
S: this,
|
|
439
539
|
C: (f, a) => f(...a)
|
|
440
540
|
});
|
|
@@ -462,20 +562,13 @@ var PluginManager = class {
|
|
|
462
562
|
_setPendingResetByModule(module) {
|
|
463
563
|
return untracked2(() => {
|
|
464
564
|
const activationEvents = getEvents(module.activatesOn).map(eventKey).filter((key) => this._state.eventsFired.includes(key));
|
|
465
|
-
const
|
|
466
|
-
const modules = this._getActiveModules().filter((module2) => module2.activatesBefore?.map(eventKey).includes(event));
|
|
467
|
-
return modules.flatMap((module2) => getEvents(module2.activatesOn)).map(eventKey);
|
|
468
|
-
});
|
|
469
|
-
const pendingReset = Array.from(/* @__PURE__ */ new Set([
|
|
470
|
-
...activationEvents,
|
|
471
|
-
...parentEvents
|
|
472
|
-
])).filter((event) => !this._state.pendingReset.includes(event));
|
|
565
|
+
const pendingReset = Array.from(new Set(activationEvents)).filter((event) => !this._state.pendingReset.includes(event));
|
|
473
566
|
if (pendingReset.length > 0) {
|
|
474
567
|
log2("pending reset", {
|
|
475
568
|
events: pendingReset
|
|
476
569
|
}, {
|
|
477
570
|
F: __dxlog_file2,
|
|
478
|
-
L:
|
|
571
|
+
L: 328,
|
|
479
572
|
S: this,
|
|
480
573
|
C: (f, a) => f(...a)
|
|
481
574
|
});
|
|
@@ -483,59 +576,87 @@ var PluginManager = class {
|
|
|
483
576
|
}
|
|
484
577
|
});
|
|
485
578
|
}
|
|
579
|
+
/**
|
|
580
|
+
* @internal
|
|
581
|
+
*/
|
|
486
582
|
// TODO(wittjosiah): Improve error typing.
|
|
487
583
|
_activate(event) {
|
|
488
|
-
|
|
489
|
-
return Effect.gen(function* () {
|
|
584
|
+
return Effect.gen(this, function* () {
|
|
490
585
|
const key = typeof event === "string" ? event : eventKey(event);
|
|
491
586
|
log2("activating", {
|
|
492
587
|
key
|
|
493
588
|
}, {
|
|
494
589
|
F: __dxlog_file2,
|
|
495
|
-
L:
|
|
590
|
+
L: 341,
|
|
496
591
|
S: this,
|
|
497
592
|
C: (f, a) => f(...a)
|
|
498
593
|
});
|
|
499
|
-
const pendingIndex =
|
|
594
|
+
const pendingIndex = this._state.pendingReset.findIndex((event2) => event2 === key);
|
|
500
595
|
if (pendingIndex !== -1) {
|
|
501
|
-
|
|
596
|
+
this._state.pendingReset.splice(pendingIndex, 1);
|
|
502
597
|
}
|
|
503
|
-
const modules =
|
|
598
|
+
const modules = this._getInactiveModulesByEvent(key).filter((module) => {
|
|
599
|
+
const allOf2 = isAllOf(module.activatesOn);
|
|
600
|
+
if (!allOf2) {
|
|
601
|
+
return true;
|
|
602
|
+
}
|
|
603
|
+
const events = module.activatesOn.events.filter((event2) => eventKey(event2) !== key);
|
|
604
|
+
return events.every((event2) => this._state.eventsFired.includes(eventKey(event2)));
|
|
605
|
+
});
|
|
504
606
|
if (modules.length === 0) {
|
|
505
607
|
log2("no modules to activate", {
|
|
506
608
|
key
|
|
507
609
|
}, {
|
|
508
610
|
F: __dxlog_file2,
|
|
509
|
-
L:
|
|
611
|
+
L: 357,
|
|
510
612
|
S: this,
|
|
511
613
|
C: (f, a) => f(...a)
|
|
512
614
|
});
|
|
615
|
+
if (!this._state.eventsFired.includes(key)) {
|
|
616
|
+
this._state.eventsFired.push(key);
|
|
617
|
+
}
|
|
513
618
|
return false;
|
|
514
619
|
}
|
|
515
|
-
|
|
620
|
+
log2("activating modules", {
|
|
621
|
+
key,
|
|
622
|
+
modules: modules.map((module) => module.id)
|
|
623
|
+
}, {
|
|
624
|
+
F: __dxlog_file2,
|
|
625
|
+
L: 364,
|
|
626
|
+
S: this,
|
|
627
|
+
C: (f, a) => f(...a)
|
|
628
|
+
});
|
|
629
|
+
this.activation.emit({
|
|
516
630
|
event: key,
|
|
517
631
|
state: "activating"
|
|
518
632
|
});
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
633
|
+
const getCapabilities = yield* Effect.all(modules.map(({ activate }) => Effect.tryPromise({
|
|
634
|
+
try: async () => activate(this.context),
|
|
635
|
+
catch: (error) => error
|
|
636
|
+
})), {
|
|
637
|
+
concurrency: "unbounded"
|
|
638
|
+
});
|
|
639
|
+
const result = yield* pipe(
|
|
640
|
+
modules,
|
|
641
|
+
A.zip(getCapabilities),
|
|
642
|
+
A.map(([module, getCapabilities2]) => this._activateModule(module, getCapabilities2)),
|
|
643
|
+
// TODO(wittjosiah): This currently can't be run in parallel.
|
|
644
|
+
// Running this with concurrency causes races with `allOf` activation events.
|
|
645
|
+
Effect.all,
|
|
646
|
+
Effect.either
|
|
647
|
+
);
|
|
648
|
+
if (Either.isLeft(result)) {
|
|
649
|
+
this.activation.emit({
|
|
650
|
+
event: key,
|
|
651
|
+
state: "error",
|
|
652
|
+
error: result.left
|
|
653
|
+
});
|
|
654
|
+
yield* Effect.fail(result.left);
|
|
534
655
|
}
|
|
535
|
-
if (!
|
|
536
|
-
|
|
656
|
+
if (!this._state.eventsFired.includes(key)) {
|
|
657
|
+
this._state.eventsFired.push(key);
|
|
537
658
|
}
|
|
538
|
-
|
|
659
|
+
this.activation.emit({
|
|
539
660
|
event: key,
|
|
540
661
|
state: "activated"
|
|
541
662
|
});
|
|
@@ -543,79 +664,105 @@ var PluginManager = class {
|
|
|
543
664
|
key
|
|
544
665
|
}, {
|
|
545
666
|
F: __dxlog_file2,
|
|
546
|
-
L:
|
|
667
|
+
L: 398,
|
|
547
668
|
S: this,
|
|
548
669
|
C: (f, a) => f(...a)
|
|
549
670
|
});
|
|
550
671
|
return true;
|
|
551
672
|
});
|
|
552
673
|
}
|
|
553
|
-
_activateModule(module) {
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
}
|
|
561
|
-
|
|
674
|
+
_activateModule(module, getCapabilities) {
|
|
675
|
+
return Effect.gen(this, function* () {
|
|
676
|
+
yield* Effect.all(module.activatesBefore?.map((event) => this._activate(event)) ?? [], {
|
|
677
|
+
concurrency: "unbounded"
|
|
678
|
+
});
|
|
679
|
+
log2("activating module...", {
|
|
680
|
+
module: module.id
|
|
681
|
+
}, {
|
|
682
|
+
F: __dxlog_file2,
|
|
683
|
+
L: 413,
|
|
684
|
+
S: this,
|
|
685
|
+
C: (f, a) => f(...a)
|
|
686
|
+
});
|
|
687
|
+
const maybeCapabilities = typeof getCapabilities === "function" ? getCapabilities() : getCapabilities;
|
|
688
|
+
const resolvedCapabilities = yield* Match.value(maybeCapabilities).pipe(
|
|
689
|
+
// TODO(wittjosiah): Activate with an effect?
|
|
690
|
+
// Match.when(Effect.isEffect, (effect) => effect),
|
|
691
|
+
Match.when(isPromise, (promise) => Effect.tryPromise({
|
|
692
|
+
try: () => promise,
|
|
693
|
+
catch: (error) => error
|
|
694
|
+
})),
|
|
695
|
+
Match.orElse((program) => Effect.succeed(program))
|
|
696
|
+
);
|
|
697
|
+
const capabilities = Match.value(resolvedCapabilities).pipe(Match.when(Array.isArray, (array) => array), Match.orElse((value) => [
|
|
562
698
|
value
|
|
563
699
|
]));
|
|
564
700
|
capabilities.forEach((capability) => {
|
|
565
|
-
|
|
701
|
+
this.context.contributeCapability({
|
|
566
702
|
module: module.id,
|
|
567
703
|
...capability
|
|
568
704
|
});
|
|
569
705
|
});
|
|
570
|
-
|
|
571
|
-
|
|
706
|
+
this._state.active.push(module.id);
|
|
707
|
+
this._capabilities.set(module.id, capabilities);
|
|
708
|
+
log2("activated module", {
|
|
709
|
+
module: module.id
|
|
710
|
+
}, {
|
|
711
|
+
F: __dxlog_file2,
|
|
712
|
+
L: 436,
|
|
713
|
+
S: this,
|
|
714
|
+
C: (f, a) => f(...a)
|
|
715
|
+
});
|
|
716
|
+
yield* Effect.all(module.activatesAfter?.map((event) => this._activate(event)) ?? [], {
|
|
717
|
+
concurrency: "unbounded"
|
|
718
|
+
});
|
|
572
719
|
});
|
|
573
720
|
}
|
|
574
721
|
_deactivate(id) {
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
const plugin = self._getPlugin(id);
|
|
722
|
+
return Effect.gen(this, function* () {
|
|
723
|
+
const plugin = this._getPlugin(id);
|
|
578
724
|
if (!plugin) {
|
|
579
725
|
return false;
|
|
580
726
|
}
|
|
581
727
|
const modules = plugin.modules;
|
|
582
|
-
const results = yield* Effect.all(modules.map((module) =>
|
|
728
|
+
const results = yield* Effect.all(modules.map((module) => this._deactivateModule(module)), {
|
|
729
|
+
concurrency: "unbounded"
|
|
730
|
+
});
|
|
583
731
|
return results.every((result) => result);
|
|
584
732
|
});
|
|
585
733
|
}
|
|
586
734
|
_deactivateModule(module) {
|
|
587
|
-
|
|
588
|
-
return Effect.gen(function* () {
|
|
735
|
+
return Effect.gen(this, function* () {
|
|
589
736
|
const id = module.id;
|
|
590
737
|
log2("deactivating", {
|
|
591
738
|
id
|
|
592
739
|
}, {
|
|
593
740
|
F: __dxlog_file2,
|
|
594
|
-
L:
|
|
741
|
+
L: 463,
|
|
595
742
|
S: this,
|
|
596
743
|
C: (f, a) => f(...a)
|
|
597
744
|
});
|
|
598
|
-
const capabilities =
|
|
745
|
+
const capabilities = this._capabilities.get(id);
|
|
599
746
|
if (capabilities) {
|
|
600
747
|
for (const capability of capabilities) {
|
|
601
|
-
|
|
748
|
+
this.context.removeCapability(capability.interface, capability.implementation);
|
|
602
749
|
const program = capability.deactivate?.();
|
|
603
|
-
yield* Match.value(program).pipe(Match.when(Effect.isEffect, (
|
|
750
|
+
yield* Match.value(program).pipe(Match.when(Effect.isEffect, (effect2) => effect2), Match.when(isPromise, (promise) => Effect.tryPromise({
|
|
604
751
|
try: () => promise,
|
|
605
752
|
catch: (error) => error
|
|
606
753
|
})), Match.orElse((program2) => Effect.succeed(program2)));
|
|
607
754
|
}
|
|
608
|
-
|
|
755
|
+
this._capabilities.delete(id);
|
|
609
756
|
}
|
|
610
|
-
const activeIndex =
|
|
757
|
+
const activeIndex = this._state.active.findIndex((event) => event === id);
|
|
611
758
|
if (activeIndex !== -1) {
|
|
612
|
-
|
|
759
|
+
this._state.active.splice(activeIndex, 1);
|
|
613
760
|
}
|
|
614
761
|
log2("deactivated", {
|
|
615
762
|
id
|
|
616
763
|
}, {
|
|
617
764
|
F: __dxlog_file2,
|
|
618
|
-
L:
|
|
765
|
+
L: 489,
|
|
619
766
|
S: this,
|
|
620
767
|
C: (f, a) => f(...a)
|
|
621
768
|
});
|
|
@@ -623,27 +770,22 @@ var PluginManager = class {
|
|
|
623
770
|
});
|
|
624
771
|
}
|
|
625
772
|
_reset(event) {
|
|
626
|
-
|
|
627
|
-
return Effect.gen(function* () {
|
|
773
|
+
return Effect.gen(this, function* () {
|
|
628
774
|
const key = typeof event === "string" ? event : eventKey(event);
|
|
629
775
|
log2("reset", {
|
|
630
776
|
key
|
|
631
777
|
}, {
|
|
632
778
|
F: __dxlog_file2,
|
|
633
|
-
L:
|
|
779
|
+
L: 497,
|
|
634
780
|
S: this,
|
|
635
781
|
C: (f, a) => f(...a)
|
|
636
782
|
});
|
|
637
|
-
const modules =
|
|
638
|
-
const results = yield* Effect.all(modules.map((module) =>
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
self._removeModule(id);
|
|
642
|
-
});
|
|
643
|
-
self._state.pendingRemoval.splice(0, self._state.pendingRemoval.length);
|
|
644
|
-
}
|
|
783
|
+
const modules = this._getActiveModulesByEvent(key);
|
|
784
|
+
const results = yield* Effect.all(modules.map((module) => this._deactivateModule(module)), {
|
|
785
|
+
concurrency: "unbounded"
|
|
786
|
+
});
|
|
645
787
|
if (results.every((result) => result)) {
|
|
646
|
-
return yield*
|
|
788
|
+
return yield* this._activate(key);
|
|
647
789
|
} else {
|
|
648
790
|
return false;
|
|
649
791
|
}
|
|
@@ -683,9 +825,6 @@ var Capabilities;
|
|
|
683
825
|
Capabilities2.IntentResolver = defineCapability("dxos.org/app-framework/capability/intent-resolver");
|
|
684
826
|
Capabilities2.IntentDispatcher = defineCapability("dxos.org/app-framework/capability/intent-dispatcher");
|
|
685
827
|
Capabilities2.Layout = defineCapability("dxos.org/app-framework/capability/layout");
|
|
686
|
-
Capabilities2.MutableLayout = defineCapability("dxos.org/app-framework/capability/layout");
|
|
687
|
-
Capabilities2.Location = defineCapability("dxos.org/app-framework/capability/location");
|
|
688
|
-
Capabilities2.MutableLocation = defineCapability("dxos.org/app-framework/capability/location");
|
|
689
828
|
Capabilities2.Translations = defineCapability("dxos.org/app-framework/capability/translations");
|
|
690
829
|
Capabilities2.AppGraph = defineCapability("dxos.org/app-framework/capability/app-graph");
|
|
691
830
|
Capabilities2.AppGraphBuilder = defineCapability("dxos.org/app-framework/capability/app-graph-builder");
|
|
@@ -693,6 +832,8 @@ var Capabilities;
|
|
|
693
832
|
Capabilities2.SettingsStore = defineCapability("dxos.org/app-framework/capability/settings-store");
|
|
694
833
|
Capabilities2.Settings = defineCapability("dxos.org/app-framework/capability/settings");
|
|
695
834
|
Capabilities2.Metadata = defineCapability("dxos.org/app-framework/capability/metadata");
|
|
835
|
+
Capabilities2.Tools = defineCapability("dxos.org/app-framework/capability/tools");
|
|
836
|
+
Capabilities2.ArtifactDefinition = defineCapability("dxos.org/app-framework/capability/artifact-definition");
|
|
696
837
|
Capabilities2.FileUploader = defineCapability("dxos.org/app-framework/capability/file-uploader");
|
|
697
838
|
})(Capabilities || (Capabilities = {}));
|
|
698
839
|
|
|
@@ -700,6 +841,8 @@ var Capabilities;
|
|
|
700
841
|
var Events;
|
|
701
842
|
(function(Events2) {
|
|
702
843
|
Events2.Startup = defineEvent("dxos.org/app-framework/event/startup");
|
|
844
|
+
Events2.SetupSurfaces = defineEvent("dxos.org/app-framework/event/setup-surfaces");
|
|
845
|
+
Events2.SetupMetadata = defineEvent("dxos.org/app-framework/event/setup-metadata");
|
|
703
846
|
Events2.SetupIntents = defineEvent("dxos.org/app-framework/event/setup-intents");
|
|
704
847
|
Events2.SetupSettings = defineEvent("dxos.org/app-framework/event/setup-settings");
|
|
705
848
|
Events2.SetupAppGraph = defineEvent("dxos.org/app-framework/event/setup-graph");
|
|
@@ -709,11 +852,10 @@ var Events;
|
|
|
709
852
|
Events2.AppGraphReady = defineEvent("dxos.org/app-framework/event/graph-ready");
|
|
710
853
|
Events2.createStateEvent = (specifier) => defineEvent("dxos.org/app-framework/event/state", specifier);
|
|
711
854
|
Events2.LayoutReady = Events2.createStateEvent(Capabilities.Layout.identifier);
|
|
712
|
-
Events2.LocationReady = Events2.createStateEvent(Capabilities.Location.identifier);
|
|
713
855
|
})(Events || (Events = {}));
|
|
714
856
|
|
|
715
857
|
// packages/sdk/app-framework/src/common/file.ts
|
|
716
|
-
import {
|
|
858
|
+
import { Schema as S3 } from "@effect/schema";
|
|
717
859
|
var defaultFileTypes = {
|
|
718
860
|
images: [
|
|
719
861
|
"png",
|
|
@@ -733,127 +875,367 @@ var defaultFileTypes = {
|
|
|
733
875
|
"md"
|
|
734
876
|
]
|
|
735
877
|
};
|
|
736
|
-
var FileInfoSchema =
|
|
737
|
-
name:
|
|
738
|
-
type:
|
|
739
|
-
url:
|
|
740
|
-
cid:
|
|
878
|
+
var FileInfoSchema = S3.Struct({
|
|
879
|
+
name: S3.String,
|
|
880
|
+
type: S3.String,
|
|
881
|
+
url: S3.optional(S3.String),
|
|
882
|
+
cid: S3.optional(S3.String)
|
|
741
883
|
});
|
|
742
884
|
|
|
743
|
-
// packages/sdk/app-framework/src/
|
|
744
|
-
import {
|
|
745
|
-
var createIntent = (schema, data = {}, params = {}) => {
|
|
746
|
-
const _ = S2.validateSync(schema.fields.input)(data);
|
|
747
|
-
const intent = {
|
|
748
|
-
...params,
|
|
749
|
-
_schema: schema,
|
|
750
|
-
action: schema._tag,
|
|
751
|
-
data
|
|
752
|
-
};
|
|
753
|
-
return {
|
|
754
|
-
first: intent,
|
|
755
|
-
last: intent,
|
|
756
|
-
all: [
|
|
757
|
-
intent
|
|
758
|
-
]
|
|
759
|
-
};
|
|
760
|
-
};
|
|
761
|
-
var chain = (schema, data = {}, params = {}) => (intent) => {
|
|
762
|
-
const intents = "all" in intent ? intent.all : [
|
|
763
|
-
intent
|
|
764
|
-
];
|
|
765
|
-
const first = intents[0];
|
|
766
|
-
const last = {
|
|
767
|
-
...params,
|
|
768
|
-
_schema: schema,
|
|
769
|
-
action: schema._tag,
|
|
770
|
-
data
|
|
771
|
-
};
|
|
772
|
-
return {
|
|
773
|
-
first,
|
|
774
|
-
last,
|
|
775
|
-
all: [
|
|
776
|
-
...intents,
|
|
777
|
-
last
|
|
778
|
-
]
|
|
779
|
-
};
|
|
780
|
-
};
|
|
781
|
-
var Label = S2.Union(S2.String, S2.mutable(S2.Tuple(S2.String, S2.mutable(S2.Struct({
|
|
782
|
-
ns: S2.String,
|
|
783
|
-
count: S2.optional(S2.Number)
|
|
784
|
-
})))));
|
|
885
|
+
// packages/sdk/app-framework/src/common/layout.ts
|
|
886
|
+
import { Schema as S4 } from "@effect/schema";
|
|
785
887
|
|
|
786
|
-
// packages/sdk/app-framework/src/plugin-intent/
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
888
|
+
// packages/sdk/app-framework/src/plugin-intent/IntentPlugin.tsx
|
|
889
|
+
var IntentPlugin = () => definePlugin({
|
|
890
|
+
id: INTENT_PLUGIN
|
|
891
|
+
}, [
|
|
892
|
+
defineModule({
|
|
893
|
+
id: `${INTENT_PLUGIN}/module/dispatcher`,
|
|
894
|
+
// TODO(wittjosiah): This will mean that startup needs to be reset when intents are added or removed.
|
|
895
|
+
// This is fine for now because it's how it worked prior to capabilities api anyways.
|
|
896
|
+
// In the future, the intent dispatcher should be able to be reset without resetting the entire app.
|
|
897
|
+
activatesOn: Events.Startup,
|
|
898
|
+
activatesAfter: [
|
|
899
|
+
Events.DispatcherReady
|
|
900
|
+
],
|
|
901
|
+
activate: lazy(() => import("./intent-dispatcher-LJKNIGAM.mjs"))
|
|
902
|
+
})
|
|
903
|
+
]);
|
|
904
|
+
|
|
905
|
+
// packages/sdk/app-framework/src/common/layout.ts
|
|
906
|
+
var LAYOUT_PLUGIN = "dxos.org/plugin/layout";
|
|
907
|
+
var LAYOUT_ACTION = `${LAYOUT_PLUGIN}/action`;
|
|
908
|
+
var LayoutAction;
|
|
909
|
+
(function(LayoutAction2) {
|
|
910
|
+
LayoutAction2.UPDATE_LAYOUT = `${LAYOUT_ACTION}/update-layout`;
|
|
911
|
+
class UpdateLayout extends S4.TaggedClass()(LayoutAction2.UPDATE_LAYOUT, {
|
|
912
|
+
input: S4.Struct({
|
|
913
|
+
part: S4.String.annotations({
|
|
914
|
+
description: "The part of the layout to mutate."
|
|
915
|
+
}),
|
|
916
|
+
subject: S4.optional(S4.Any.annotations({
|
|
917
|
+
description: "The subject of the layout update."
|
|
918
|
+
})),
|
|
919
|
+
options: S4.optional(S4.Record({
|
|
920
|
+
key: S4.String,
|
|
921
|
+
value: S4.Any
|
|
922
|
+
}).annotations({
|
|
923
|
+
description: "Additional options for the layout action."
|
|
924
|
+
}))
|
|
795
925
|
}),
|
|
796
|
-
output:
|
|
926
|
+
output: S4.Void
|
|
797
927
|
}) {
|
|
798
928
|
}
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
929
|
+
LayoutAction2.UpdateLayout = UpdateLayout;
|
|
930
|
+
class SetLayoutMode extends S4.TaggedClass()(LayoutAction2.UPDATE_LAYOUT, {
|
|
931
|
+
input: S4.Struct({
|
|
932
|
+
part: S4.Literal("mode").annotations({
|
|
933
|
+
description: "Setting the layout mode."
|
|
934
|
+
}),
|
|
935
|
+
subject: S4.optional(S4.String.annotations({
|
|
936
|
+
description: "Item which is the subject of the new layout mode."
|
|
937
|
+
})),
|
|
938
|
+
options: S4.Union(S4.Struct({
|
|
939
|
+
mode: S4.String.annotations({
|
|
940
|
+
description: "The new layout mode."
|
|
941
|
+
})
|
|
942
|
+
}), S4.Struct({
|
|
943
|
+
revert: S4.Boolean.annotations({
|
|
944
|
+
description: "Revert to the previous layout mode."
|
|
945
|
+
})
|
|
946
|
+
}))
|
|
947
|
+
}),
|
|
948
|
+
output: S4.Void
|
|
949
|
+
}) {
|
|
814
950
|
}
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
951
|
+
LayoutAction2.SetLayoutMode = SetLayoutMode;
|
|
952
|
+
class UpdateSidebar extends S4.TaggedClass()(LayoutAction2.UPDATE_LAYOUT, {
|
|
953
|
+
input: S4.Struct({
|
|
954
|
+
part: S4.Literal("sidebar").annotations({
|
|
955
|
+
description: "Updating the sidebar."
|
|
956
|
+
}),
|
|
957
|
+
subject: S4.optional(S4.String.annotations({
|
|
958
|
+
description: "URI of the component to display in the sidebar."
|
|
959
|
+
})),
|
|
960
|
+
options: S4.optional(S4.Struct({
|
|
961
|
+
state: S4.Literal("closed", "collapsed", "expanded").annotations({
|
|
962
|
+
description: "Whether the sidebar is closed, collapsed, or expanded."
|
|
963
|
+
})
|
|
964
|
+
}))
|
|
965
|
+
}),
|
|
966
|
+
output: S4.Void
|
|
967
|
+
}) {
|
|
821
968
|
}
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
969
|
+
LayoutAction2.UpdateSidebar = UpdateSidebar;
|
|
970
|
+
class UpdateComplementary extends S4.TaggedClass()(LayoutAction2.UPDATE_LAYOUT, {
|
|
971
|
+
input: S4.Struct({
|
|
972
|
+
part: S4.Literal("complementary").annotations({
|
|
973
|
+
description: "Updating the complementary sidebar."
|
|
974
|
+
}),
|
|
975
|
+
subject: S4.optional(S4.String.annotations({
|
|
976
|
+
description: "URI of the component to display in the complementary area."
|
|
977
|
+
})),
|
|
978
|
+
options: S4.optional(S4.Struct({
|
|
979
|
+
state: S4.Literal("closed", "collapsed", "expanded").annotations({
|
|
980
|
+
description: "Whether the complementary sidebar is closed, collapsed, or expanded."
|
|
981
|
+
})
|
|
982
|
+
}))
|
|
983
|
+
}),
|
|
984
|
+
output: S4.Void
|
|
985
|
+
}) {
|
|
826
986
|
}
|
|
827
|
-
|
|
987
|
+
LayoutAction2.UpdateComplementary = UpdateComplementary;
|
|
988
|
+
class UpdateDialog extends S4.TaggedClass()(LayoutAction2.UPDATE_LAYOUT, {
|
|
989
|
+
input: S4.Struct({
|
|
990
|
+
part: S4.Literal("dialog").annotations({
|
|
991
|
+
description: "Updating the dialog."
|
|
992
|
+
}),
|
|
993
|
+
subject: S4.optional(S4.String.annotations({
|
|
994
|
+
description: "URI of the component to display in the dialog."
|
|
995
|
+
})),
|
|
996
|
+
options: S4.Struct({
|
|
997
|
+
state: S4.optional(S4.Boolean.annotations({
|
|
998
|
+
description: "Whether the dialog is open or closed."
|
|
999
|
+
})),
|
|
1000
|
+
blockAlign: S4.optional(S4.Literal("start", "center").annotations({
|
|
1001
|
+
description: "The alignment of the dialog."
|
|
1002
|
+
})),
|
|
1003
|
+
type: S4.optional(S4.Literal("default", "alert").annotations({
|
|
1004
|
+
description: "The type of dialog."
|
|
1005
|
+
})),
|
|
1006
|
+
props: S4.optional(S4.Record({
|
|
1007
|
+
key: S4.String,
|
|
1008
|
+
value: S4.Any
|
|
1009
|
+
}).annotations({
|
|
1010
|
+
description: "Additional props for the dialog."
|
|
1011
|
+
}))
|
|
1012
|
+
})
|
|
1013
|
+
}),
|
|
1014
|
+
output: S4.Void
|
|
1015
|
+
}) {
|
|
1016
|
+
}
|
|
1017
|
+
LayoutAction2.UpdateDialog = UpdateDialog;
|
|
1018
|
+
class UpdatePopover extends S4.TaggedClass()(LayoutAction2.UPDATE_LAYOUT, {
|
|
1019
|
+
input: S4.Struct({
|
|
1020
|
+
part: S4.Literal("popover").annotations({
|
|
1021
|
+
description: "Updating the popover."
|
|
1022
|
+
}),
|
|
1023
|
+
subject: S4.optional(S4.String.annotations({
|
|
1024
|
+
description: "URI of the component to display in the popover."
|
|
1025
|
+
})),
|
|
1026
|
+
options: S4.Struct({
|
|
1027
|
+
anchorId: S4.String.annotations({
|
|
1028
|
+
description: "The id of the element to anchor the popover to."
|
|
1029
|
+
}),
|
|
1030
|
+
state: S4.optional(S4.Boolean.annotations({
|
|
1031
|
+
description: "Whether the popover is open or closed."
|
|
1032
|
+
})),
|
|
1033
|
+
props: S4.optional(S4.Record({
|
|
1034
|
+
key: S4.String,
|
|
1035
|
+
value: S4.Any
|
|
1036
|
+
}).annotations({
|
|
1037
|
+
description: "Additional props for the popover."
|
|
1038
|
+
}))
|
|
1039
|
+
})
|
|
1040
|
+
}),
|
|
1041
|
+
output: S4.Void
|
|
1042
|
+
}) {
|
|
1043
|
+
}
|
|
1044
|
+
LayoutAction2.UpdatePopover = UpdatePopover;
|
|
1045
|
+
LayoutAction2.Toast = S4.Struct({
|
|
1046
|
+
id: S4.String.annotations({
|
|
1047
|
+
description: "The id of the toast."
|
|
1048
|
+
}),
|
|
1049
|
+
title: S4.optional(Label.annotations({
|
|
1050
|
+
description: "The title of the toast."
|
|
1051
|
+
})),
|
|
1052
|
+
description: S4.optional(Label.annotations({
|
|
1053
|
+
description: "The description of the toast."
|
|
1054
|
+
})),
|
|
1055
|
+
icon: S4.optional(S4.String.annotations({
|
|
1056
|
+
description: "The icon of the toast."
|
|
1057
|
+
})),
|
|
1058
|
+
duration: S4.optional(S4.Number.annotations({
|
|
1059
|
+
description: "The duration of the toast."
|
|
1060
|
+
})),
|
|
1061
|
+
closeLabel: S4.optional(Label.annotations({
|
|
1062
|
+
description: "The label of the close button."
|
|
1063
|
+
})),
|
|
1064
|
+
actionLabel: S4.optional(Label.annotations({
|
|
1065
|
+
description: "The label of the action button."
|
|
1066
|
+
})),
|
|
1067
|
+
actionAlt: S4.optional(Label.annotations({
|
|
1068
|
+
description: "The alt text of the action button."
|
|
1069
|
+
})),
|
|
1070
|
+
onAction: S4.optional(S4.Any.annotations({
|
|
1071
|
+
description: "The action to perform when the action button is clicked."
|
|
1072
|
+
}))
|
|
1073
|
+
});
|
|
1074
|
+
class AddToast extends S4.TaggedClass()(LayoutAction2.UPDATE_LAYOUT, {
|
|
1075
|
+
input: S4.Struct({
|
|
1076
|
+
part: S4.Literal("toast").annotations({
|
|
1077
|
+
description: "Adding a toast."
|
|
1078
|
+
}),
|
|
1079
|
+
subject: LayoutAction2.Toast.annotations({
|
|
1080
|
+
description: "The toast to add."
|
|
1081
|
+
})
|
|
1082
|
+
}),
|
|
1083
|
+
output: S4.Void
|
|
1084
|
+
}) {
|
|
1085
|
+
}
|
|
1086
|
+
LayoutAction2.AddToast = AddToast;
|
|
1087
|
+
class SwitchWorkspace extends S4.TaggedClass()(LayoutAction2.UPDATE_LAYOUT, {
|
|
1088
|
+
input: S4.Struct({
|
|
1089
|
+
part: S4.Literal("workspace").annotations({
|
|
1090
|
+
description: "Switching the workspace."
|
|
1091
|
+
}),
|
|
1092
|
+
subject: S4.String.annotations({
|
|
1093
|
+
description: "The id of the workspace to switch to."
|
|
1094
|
+
})
|
|
1095
|
+
}),
|
|
1096
|
+
output: S4.Void
|
|
1097
|
+
}) {
|
|
1098
|
+
}
|
|
1099
|
+
LayoutAction2.SwitchWorkspace = SwitchWorkspace;
|
|
1100
|
+
class Open extends S4.TaggedClass()(LayoutAction2.UPDATE_LAYOUT, {
|
|
1101
|
+
input: S4.Struct({
|
|
1102
|
+
part: S4.Literal("main").annotations({
|
|
1103
|
+
description: "Opening an item in the main content area."
|
|
1104
|
+
}),
|
|
1105
|
+
subject: S4.Array(S4.String.annotations({
|
|
1106
|
+
description: "Ids of the items to open."
|
|
1107
|
+
})),
|
|
1108
|
+
options: S4.optional(S4.Struct({
|
|
1109
|
+
state: S4.optional(S4.Literal(true).annotations({
|
|
1110
|
+
description: "The items are being added."
|
|
1111
|
+
})),
|
|
1112
|
+
key: S4.optional(S4.String.annotations({
|
|
1113
|
+
description: "If provided, will replace item with a matching key (id prefix)."
|
|
1114
|
+
})),
|
|
1115
|
+
scrollIntoView: S4.optional(S4.Boolean.annotations({
|
|
1116
|
+
description: "Scroll the items into view."
|
|
1117
|
+
})),
|
|
1118
|
+
pivotId: S4.optional(S4.String.annotations({
|
|
1119
|
+
description: "The id of the item to place new items next to."
|
|
1120
|
+
})),
|
|
1121
|
+
positioning: S4.optional(S4.Union(S4.Literal("start").annotations({
|
|
1122
|
+
description: "The items are being added before the pivot item."
|
|
1123
|
+
}), S4.Literal("end").annotations({
|
|
1124
|
+
description: "The items are being added after the pivot item."
|
|
1125
|
+
})))
|
|
1126
|
+
}))
|
|
1127
|
+
}),
|
|
1128
|
+
output: S4.Void
|
|
1129
|
+
}) {
|
|
1130
|
+
}
|
|
1131
|
+
LayoutAction2.Open = Open;
|
|
1132
|
+
class Set2 extends S4.TaggedClass()(LayoutAction2.UPDATE_LAYOUT, {
|
|
1133
|
+
input: S4.Struct({
|
|
1134
|
+
part: S4.Literal("main").annotations({
|
|
1135
|
+
description: "Setting items in the main content area."
|
|
1136
|
+
}),
|
|
1137
|
+
subject: S4.Array(S4.String.annotations({
|
|
1138
|
+
description: "Ids of the items to set."
|
|
1139
|
+
})),
|
|
1140
|
+
options: S4.Struct({
|
|
1141
|
+
override: S4.Literal(true).annotations({
|
|
1142
|
+
description: "Override the current items in the main content area."
|
|
1143
|
+
})
|
|
1144
|
+
})
|
|
1145
|
+
}),
|
|
1146
|
+
output: S4.Void
|
|
1147
|
+
}) {
|
|
1148
|
+
}
|
|
1149
|
+
LayoutAction2.Set = Set2;
|
|
1150
|
+
class Close extends S4.TaggedClass()(LayoutAction2.UPDATE_LAYOUT, {
|
|
1151
|
+
input: S4.Struct({
|
|
1152
|
+
part: S4.Literal("main").annotations({
|
|
1153
|
+
description: "Closing items in the main content area."
|
|
1154
|
+
}),
|
|
1155
|
+
subject: S4.Array(S4.String.annotations({
|
|
1156
|
+
description: "Ids of the items to close."
|
|
1157
|
+
})),
|
|
1158
|
+
options: S4.Struct({
|
|
1159
|
+
state: S4.Literal(false).annotations({
|
|
1160
|
+
description: "The items are being removed."
|
|
1161
|
+
})
|
|
1162
|
+
})
|
|
1163
|
+
}),
|
|
1164
|
+
output: S4.Void
|
|
1165
|
+
}) {
|
|
1166
|
+
}
|
|
1167
|
+
LayoutAction2.Close = Close;
|
|
1168
|
+
class ScrollIntoView extends S4.TaggedClass()(LayoutAction2.UPDATE_LAYOUT, {
|
|
1169
|
+
input: S4.Struct({
|
|
1170
|
+
part: S4.Literal("current").annotations({
|
|
1171
|
+
description: "Setting the current item"
|
|
1172
|
+
}),
|
|
1173
|
+
subject: S4.optional(S4.String.annotations({
|
|
1174
|
+
description: "The id of the item to set as current."
|
|
1175
|
+
})),
|
|
1176
|
+
options: S4.optional(S4.Record({
|
|
1177
|
+
key: S4.String,
|
|
1178
|
+
value: S4.Any
|
|
1179
|
+
}).annotations({
|
|
1180
|
+
description: "Additional options for the scroll into view."
|
|
1181
|
+
}))
|
|
1182
|
+
}),
|
|
1183
|
+
output: S4.Void
|
|
1184
|
+
}) {
|
|
1185
|
+
}
|
|
1186
|
+
LayoutAction2.ScrollIntoView = ScrollIntoView;
|
|
1187
|
+
class Expose extends S4.TaggedClass()(LayoutAction2.UPDATE_LAYOUT, {
|
|
1188
|
+
input: S4.Struct({
|
|
1189
|
+
part: S4.Literal("navigation").annotations({
|
|
1190
|
+
description: "Exposing an item in the navigation area."
|
|
1191
|
+
}),
|
|
1192
|
+
subject: S4.String.annotations({
|
|
1193
|
+
description: "The id of the item to expose."
|
|
1194
|
+
})
|
|
1195
|
+
}),
|
|
1196
|
+
output: S4.Void
|
|
1197
|
+
}) {
|
|
1198
|
+
}
|
|
1199
|
+
LayoutAction2.Expose = Expose;
|
|
1200
|
+
})(LayoutAction || (LayoutAction = {}));
|
|
1201
|
+
|
|
1202
|
+
// packages/sdk/app-framework/src/common/surface.ts
|
|
1203
|
+
var createSurface = (definition) => definition;
|
|
1204
|
+
|
|
1205
|
+
// packages/sdk/app-framework/src/common/translations.ts
|
|
1206
|
+
import { Schema as S5 } from "@effect/schema";
|
|
1207
|
+
var ResourceKey = S5.Union(S5.String, S5.Record({
|
|
1208
|
+
key: S5.String,
|
|
1209
|
+
value: S5.Any
|
|
1210
|
+
}));
|
|
1211
|
+
var ResourceLanguage = S5.Record({
|
|
1212
|
+
key: S5.String,
|
|
1213
|
+
value: ResourceKey
|
|
1214
|
+
});
|
|
1215
|
+
var Resource = S5.Record({
|
|
1216
|
+
key: S5.String,
|
|
1217
|
+
value: ResourceLanguage
|
|
1218
|
+
});
|
|
828
1219
|
|
|
829
1220
|
// packages/sdk/app-framework/src/plugin-intent/intent-dispatcher.ts
|
|
830
1221
|
var EXECUTION_LIMIT = 100;
|
|
831
1222
|
var HISTORY_LIMIT = 100;
|
|
832
|
-
var createResolver = (
|
|
833
|
-
action: schema._tag,
|
|
834
|
-
effect: effect3,
|
|
835
|
-
...params
|
|
836
|
-
});
|
|
1223
|
+
var createResolver = (resolver) => resolver;
|
|
837
1224
|
var isUndoable = (historyEntry) => historyEntry.length > 0 && historyEntry.every(({ undoable }) => !!undoable);
|
|
838
1225
|
var createDispatcher = (getResolvers, { executionLimit = EXECUTION_LIMIT, historyLimit = HISTORY_LIMIT } = {}) => {
|
|
839
1226
|
const historyRef = Effect2.runSync(Ref.make([]));
|
|
840
|
-
const handleIntent = (intent) => {
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
_intent: intent,
|
|
853
|
-
...result
|
|
854
|
-
};
|
|
855
|
-
});
|
|
856
|
-
};
|
|
1227
|
+
const handleIntent = (intent) => Effect2.gen(function* () {
|
|
1228
|
+
const candidates = getResolvers(intent.module).filter((r) => r.intent._tag === intent.id).filter((r) => !r.filter || r.filter(intent.data)).toSorted(byPosition);
|
|
1229
|
+
if (candidates.length === 0) {
|
|
1230
|
+
yield* Effect2.fail(new NoResolversError(intent.id));
|
|
1231
|
+
}
|
|
1232
|
+
const effect2 = candidates[0].resolve(intent.data, intent.undo ?? false);
|
|
1233
|
+
const result = Effect2.isEffect(effect2) ? yield* effect2 : yield* Effect2.promise(async () => effect2);
|
|
1234
|
+
return {
|
|
1235
|
+
_intent: intent,
|
|
1236
|
+
...result
|
|
1237
|
+
};
|
|
1238
|
+
});
|
|
857
1239
|
const dispatch = (intentChain, depth = 0) => {
|
|
858
1240
|
return Effect2.gen(function* () {
|
|
859
1241
|
if (depth > executionLimit) {
|
|
@@ -895,7 +1277,7 @@ var createDispatcher = (getResolvers, { executionLimit = EXECUTION_LIMIT, histor
|
|
|
895
1277
|
return next;
|
|
896
1278
|
});
|
|
897
1279
|
if (result.undoable && isUndoable(results)) {
|
|
898
|
-
yield*
|
|
1280
|
+
yield* pipe2(dispatch(createIntent(IntentAction.ShowUndo, {
|
|
899
1281
|
message: result.undoable.message
|
|
900
1282
|
})), Effect2.catchSome((err) => err instanceof NoResolversError ? Option.some(Effect2.succeed(void 0)) : Option.none()));
|
|
901
1283
|
}
|
|
@@ -951,578 +1333,32 @@ var createDispatcher = (getResolvers, { executionLimit = EXECUTION_LIMIT, histor
|
|
|
951
1333
|
undoPromise
|
|
952
1334
|
};
|
|
953
1335
|
};
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
};
|
|
963
|
-
}
|
|
964
|
-
static getDerivedStateFromError(error) {
|
|
965
|
-
return {
|
|
966
|
-
error
|
|
967
|
-
};
|
|
968
|
-
}
|
|
969
|
-
componentDidUpdate(prevProps) {
|
|
970
|
-
if (prevProps.data !== this.props.data) {
|
|
971
|
-
this.resetError();
|
|
972
|
-
}
|
|
973
|
-
}
|
|
974
|
-
render() {
|
|
975
|
-
if (this.state.error) {
|
|
976
|
-
return /* @__PURE__ */ React.createElement(this.props.fallback, {
|
|
977
|
-
data: this.props.data,
|
|
978
|
-
error: this.state.error,
|
|
979
|
-
reset: this.resetError
|
|
980
|
-
});
|
|
981
|
-
}
|
|
982
|
-
return this.props.children;
|
|
983
|
-
}
|
|
984
|
-
resetError() {
|
|
985
|
-
this.setState({
|
|
986
|
-
error: void 0
|
|
987
|
-
});
|
|
988
|
-
}
|
|
989
|
-
};
|
|
990
|
-
|
|
991
|
-
// packages/sdk/app-framework/src/react/PluginManagerProvider.ts
|
|
992
|
-
import { createContext, useContext } from "react";
|
|
993
|
-
import { raise } from "@dxos/debug";
|
|
994
|
-
var PluginManagerContext = createContext(void 0);
|
|
995
|
-
var usePluginManager = () => useContext(PluginManagerContext) ?? raise(new Error("Missing PluginManagerContext"));
|
|
996
|
-
var PluginManagerProvider = PluginManagerContext.Provider;
|
|
997
|
-
|
|
998
|
-
// packages/sdk/app-framework/src/react/useCapabilities.ts
|
|
999
|
-
import { computed } from "@preact/signals-core";
|
|
1000
|
-
import { useMemo } from "react";
|
|
1001
|
-
var useCapabilities = (interfaceDef, filter) => {
|
|
1002
|
-
const manager = usePluginManager();
|
|
1003
|
-
const signal = useMemo(() => computed(() => manager.context.requestCapabilities(interfaceDef, filter)), [
|
|
1004
|
-
interfaceDef
|
|
1005
|
-
]);
|
|
1006
|
-
return signal.value;
|
|
1007
|
-
};
|
|
1008
|
-
var useCapability = (interfaceDef, filter) => {
|
|
1009
|
-
const manager = usePluginManager();
|
|
1010
|
-
const signal = useMemo(() => computed(() => manager.context.requestCapability(interfaceDef, filter)), [
|
|
1011
|
-
interfaceDef
|
|
1012
|
-
]);
|
|
1013
|
-
return signal.value;
|
|
1014
|
-
};
|
|
1015
|
-
|
|
1016
|
-
// packages/sdk/app-framework/src/react/Surface.tsx
|
|
1017
|
-
import React3, { memo, forwardRef, Suspense, useMemo as useMemo2 } from "react";
|
|
1018
|
-
import { useDefaultValue } from "@dxos/react-hooks";
|
|
1019
|
-
import { byDisposition as byDisposition2 } from "@dxos/util";
|
|
1020
|
-
|
|
1021
|
-
// packages/sdk/app-framework/src/common/layout.ts
|
|
1022
|
-
import { S as S4 } from "@dxos/echo-schema";
|
|
1023
|
-
|
|
1024
|
-
// packages/sdk/app-framework/src/plugin-intent/IntentContext.tsx
|
|
1025
|
-
import { createContext as createContext2, useContext as useContext2, useEffect } from "react";
|
|
1026
|
-
import { raise as raise2 } from "@dxos/debug";
|
|
1027
|
-
import { pick } from "@dxos/util";
|
|
1028
|
-
var IntentContext = /* @__PURE__ */ createContext2(void 0);
|
|
1029
|
-
var useIntentDispatcher = () => {
|
|
1030
|
-
const context = useContext2(IntentContext) ?? raise2(new Error("IntentContext not found"));
|
|
1031
|
-
return pick(context, [
|
|
1032
|
-
"dispatch",
|
|
1033
|
-
"dispatchPromise"
|
|
1034
|
-
]);
|
|
1035
|
-
};
|
|
1036
|
-
var useIntentResolver = (module, resolver) => {
|
|
1037
|
-
const manager = usePluginManager();
|
|
1038
|
-
useEffect(() => {
|
|
1039
|
-
manager.context.contributeCapability({
|
|
1040
|
-
module,
|
|
1041
|
-
interface: Capabilities.IntentResolver,
|
|
1042
|
-
implementation: resolver
|
|
1043
|
-
});
|
|
1044
|
-
return () => manager.context.removeCapability(Capabilities.IntentResolver, resolver);
|
|
1045
|
-
}, [
|
|
1046
|
-
module,
|
|
1047
|
-
resolver
|
|
1048
|
-
]);
|
|
1049
|
-
};
|
|
1050
|
-
var IntentProvider = IntentContext.Provider;
|
|
1051
|
-
|
|
1052
|
-
// packages/sdk/app-framework/src/plugin-intent/IntentPlugin.tsx
|
|
1053
|
-
import { Effect as Effect3 } from "effect";
|
|
1054
|
-
import React2 from "react";
|
|
1055
|
-
import { create as create3 } from "@dxos/live-object";
|
|
1056
|
-
var defaultEffect = () => Effect3.fail(new Error("Intent runtime not ready"));
|
|
1057
|
-
var defaultPromise = () => Effect3.runPromise(defaultEffect());
|
|
1058
|
-
var IntentPlugin = () => definePlugin({
|
|
1059
|
-
id: INTENT_PLUGIN
|
|
1060
|
-
}, [
|
|
1061
|
-
defineModule({
|
|
1062
|
-
id: `${INTENT_PLUGIN}/module/dispatcher`,
|
|
1063
|
-
// TODO(wittjosiah): This will mean that startup needs to be reset when intents are added or removed.
|
|
1064
|
-
// This is fine for now because it's how it worked prior to capabilities api anyways.
|
|
1065
|
-
// In the future, the intent dispatcher should be able to be reset without resetting the entire app.
|
|
1066
|
-
activatesOn: Events.Startup,
|
|
1067
|
-
activatesBefore: [
|
|
1068
|
-
Events.SetupIntents
|
|
1069
|
-
],
|
|
1070
|
-
activatesAfter: [
|
|
1071
|
-
Events.DispatcherReady
|
|
1072
|
-
],
|
|
1073
|
-
activate: (context) => {
|
|
1074
|
-
const state = create3({
|
|
1075
|
-
dispatch: defaultEffect,
|
|
1076
|
-
dispatchPromise: defaultPromise,
|
|
1077
|
-
undo: defaultEffect,
|
|
1078
|
-
undoPromise: defaultPromise
|
|
1079
|
-
});
|
|
1080
|
-
const { dispatch, dispatchPromise, undo, undoPromise } = createDispatcher((module) => context.requestCapabilities(Capabilities.IntentResolver, (c, moduleId) => {
|
|
1081
|
-
return module ? moduleId === module : true;
|
|
1082
|
-
}).flat());
|
|
1083
|
-
state.dispatch = dispatch;
|
|
1084
|
-
state.dispatchPromise = dispatchPromise;
|
|
1085
|
-
state.undo = undo;
|
|
1086
|
-
state.undoPromise = undoPromise;
|
|
1087
|
-
return [
|
|
1088
|
-
contributes(Capabilities.IntentDispatcher, state),
|
|
1089
|
-
contributes(Capabilities.ReactContext, {
|
|
1090
|
-
id: INTENT_PLUGIN,
|
|
1091
|
-
context: ({ children }) => /* @__PURE__ */ React2.createElement(IntentProvider, {
|
|
1092
|
-
value: state
|
|
1093
|
-
}, children)
|
|
1094
|
-
})
|
|
1095
|
-
];
|
|
1096
|
-
}
|
|
1097
|
-
})
|
|
1098
|
-
]);
|
|
1099
|
-
|
|
1100
|
-
// packages/sdk/app-framework/src/common/layout.ts
|
|
1101
|
-
var Toast = S4.Struct({
|
|
1102
|
-
id: S4.String,
|
|
1103
|
-
title: S4.optional(Label),
|
|
1104
|
-
description: S4.optional(Label),
|
|
1105
|
-
icon: S4.optional(S4.String),
|
|
1106
|
-
duration: S4.optional(S4.Number),
|
|
1107
|
-
closeLabel: S4.optional(Label),
|
|
1108
|
-
actionLabel: S4.optional(Label),
|
|
1109
|
-
actionAlt: S4.optional(Label),
|
|
1110
|
-
// TODO(wittjosiah): Make class with customizable method?
|
|
1111
|
-
onAction: S4.optional(S4.Any)
|
|
1112
|
-
});
|
|
1113
|
-
var LayoutMode = S4.Union(S4.Literal("deck"), S4.Literal("solo"), S4.Literal("fullscreen"));
|
|
1114
|
-
var isLayoutMode = (value) => S4.is(LayoutMode)(value);
|
|
1115
|
-
var Layout = S4.mutable(S4.Struct({
|
|
1116
|
-
layoutMode: LayoutMode,
|
|
1117
|
-
sidebarOpen: S4.Boolean,
|
|
1118
|
-
complementarySidebarOpen: S4.Boolean,
|
|
1119
|
-
/**
|
|
1120
|
-
* @deprecated Data to be passed to the complementary sidebar Surface.
|
|
1121
|
-
*/
|
|
1122
|
-
complementarySidebarContent: S4.optional(S4.Any),
|
|
1123
|
-
dialogOpen: S4.Boolean,
|
|
1124
|
-
/**
|
|
1125
|
-
* Data to be passed to the dialog Surface.
|
|
1126
|
-
*/
|
|
1127
|
-
dialogContent: S4.optional(S4.Any),
|
|
1128
|
-
// TODO(wittjosiah): Custom properties?
|
|
1129
|
-
dialogBlockAlign: S4.optional(S4.Literal("start", "center")),
|
|
1130
|
-
dialogType: S4.optional(S4.Literal("default", "alert")),
|
|
1131
|
-
popoverOpen: S4.Boolean,
|
|
1132
|
-
/**
|
|
1133
|
-
* Data to be passed to the popover Surface.
|
|
1134
|
-
*/
|
|
1135
|
-
popoverContent: S4.optional(S4.Any),
|
|
1136
|
-
popoverAnchorId: S4.optional(S4.String),
|
|
1137
|
-
toasts: S4.mutable(S4.Array(Toast)),
|
|
1138
|
-
/**
|
|
1139
|
-
* The identifier of a component to scroll into view when it is mounted.
|
|
1140
|
-
*/
|
|
1141
|
-
scrollIntoView: S4.optional(S4.String)
|
|
1142
|
-
}));
|
|
1143
|
-
var LAYOUT_PLUGIN = "dxos.org/plugin/layout";
|
|
1144
|
-
var LAYOUT_ACTION = `${LAYOUT_PLUGIN}/action`;
|
|
1145
|
-
var LayoutAction;
|
|
1146
|
-
(function(LayoutAction2) {
|
|
1147
|
-
class SetLayout extends S4.TaggedClass()(`${LAYOUT_ACTION}/set-layout`, {
|
|
1148
|
-
input: S4.Struct({
|
|
1149
|
-
/**
|
|
1150
|
-
* Element to set the state of.
|
|
1151
|
-
*/
|
|
1152
|
-
element: S4.Literal("fullscreen", "sidebar", "complementary", "dialog", "popover", "toast"),
|
|
1153
|
-
/**
|
|
1154
|
-
* Whether the element is on or off.
|
|
1155
|
-
*
|
|
1156
|
-
* If omitted, the element's state will be toggled or set based on other provided data.
|
|
1157
|
-
* For example, if `component` is provided, the state will be set to `true`.
|
|
1158
|
-
*/
|
|
1159
|
-
state: S4.optional(S4.Boolean),
|
|
1160
|
-
/**
|
|
1161
|
-
* Component to render in the dialog or popover.
|
|
1162
|
-
*/
|
|
1163
|
-
component: S4.optional(S4.String),
|
|
1164
|
-
/**
|
|
1165
|
-
* Data to be passed to the dialog or popover Surface.
|
|
1166
|
-
*/
|
|
1167
|
-
subject: S4.optional(S4.Any),
|
|
1168
|
-
/**
|
|
1169
|
-
* Anchor ID for the popover.
|
|
1170
|
-
*/
|
|
1171
|
-
anchorId: S4.optional(S4.String),
|
|
1172
|
-
// TODO(wittjosiah): Custom properties?
|
|
1173
|
-
/**
|
|
1174
|
-
* Block alignment for the dialog.
|
|
1175
|
-
*/
|
|
1176
|
-
dialogBlockAlign: S4.optional(S4.Literal("start", "center")),
|
|
1177
|
-
/**
|
|
1178
|
-
* Type of dialog.
|
|
1179
|
-
*/
|
|
1180
|
-
dialogType: S4.optional(S4.Literal("default", "alert"))
|
|
1181
|
-
}),
|
|
1182
|
-
output: S4.Void
|
|
1183
|
-
}) {
|
|
1184
|
-
}
|
|
1185
|
-
LayoutAction2.SetLayout = SetLayout;
|
|
1186
|
-
class SetLayoutMode extends S4.TaggedClass()(`${LAYOUT_ACTION}/set-layout-mode`, {
|
|
1187
|
-
input: S4.Union(S4.Struct({
|
|
1188
|
-
layoutMode: LayoutMode
|
|
1189
|
-
}), S4.Struct({
|
|
1190
|
-
revert: S4.Literal(true)
|
|
1191
|
-
})),
|
|
1192
|
-
output: S4.Void
|
|
1193
|
-
}) {
|
|
1194
|
-
}
|
|
1195
|
-
LayoutAction2.SetLayoutMode = SetLayoutMode;
|
|
1196
|
-
class ScrollIntoView extends S4.TaggedClass()(`${LAYOUT_ACTION}/scroll-into-view`, {
|
|
1197
|
-
input: S4.Struct({
|
|
1198
|
-
id: S4.optional(S4.String),
|
|
1199
|
-
// TODO(wittjosiah): Factor out to thread scroll into view action?
|
|
1200
|
-
cursor: S4.optional(S4.String),
|
|
1201
|
-
ref: S4.optional(S4.String)
|
|
1202
|
-
}),
|
|
1203
|
-
output: S4.Void
|
|
1204
|
-
}) {
|
|
1205
|
-
}
|
|
1206
|
-
LayoutAction2.ScrollIntoView = ScrollIntoView;
|
|
1207
|
-
})(LayoutAction || (LayoutAction = {}));
|
|
1208
|
-
|
|
1209
|
-
// packages/sdk/app-framework/src/common/navigation.ts
|
|
1210
|
-
import { Schema as S5 } from "@effect/schema";
|
|
1211
|
-
import { pick as pick2 } from "@dxos/util";
|
|
1212
|
-
var SLUG_LIST_SEPARATOR = "+";
|
|
1213
|
-
var SLUG_ENTRY_SEPARATOR = "_";
|
|
1214
|
-
var SLUG_KEY_VALUE_SEPARATOR = "-";
|
|
1215
|
-
var SLUG_PATH_SEPARATOR = "~";
|
|
1216
|
-
var SLUG_COLLECTION_INDICATOR = "";
|
|
1217
|
-
var LayoutEntrySchema = S5.mutable(S5.Struct({
|
|
1218
|
-
id: S5.String,
|
|
1219
|
-
path: S5.optional(S5.String)
|
|
1220
|
-
}));
|
|
1221
|
-
var LayoutPartSchema = S5.Union(S5.Literal("sidebar"), S5.Literal("main"), S5.Literal("solo"), S5.Literal("complementary"), S5.Literal("fullScreen"));
|
|
1222
|
-
var LayoutPartsSchema = S5.partial(S5.mutable(S5.Record({
|
|
1223
|
-
key: LayoutPartSchema,
|
|
1224
|
-
value: S5.mutable(S5.Array(LayoutEntrySchema))
|
|
1225
|
-
})));
|
|
1226
|
-
var LayoutCoordinateSchema = S5.mutable(S5.Struct({
|
|
1227
|
-
part: LayoutPartSchema,
|
|
1228
|
-
entryId: S5.String
|
|
1229
|
-
}));
|
|
1230
|
-
var PartAdjustmentSchema = S5.Union(S5.Literal("increment-start"), S5.Literal("increment-end"), S5.Literal("pin-start"), S5.Literal("pin-end"), S5.Literal("close"), S5.Literal("solo"));
|
|
1231
|
-
var LayoutAdjustmentSchema = S5.mutable(S5.Struct({
|
|
1232
|
-
layoutCoordinate: LayoutCoordinateSchema,
|
|
1233
|
-
type: PartAdjustmentSchema
|
|
1234
|
-
}));
|
|
1235
|
-
var ActiveParts = S5.Record({
|
|
1236
|
-
key: S5.String,
|
|
1237
|
-
value: S5.Union(S5.String, S5.mutable(S5.Array(S5.String)))
|
|
1238
|
-
});
|
|
1239
|
-
var LocationProvidesSchema = S5.mutable(S5.Struct({
|
|
1240
|
-
location: S5.Struct({
|
|
1241
|
-
active: LayoutPartsSchema,
|
|
1242
|
-
closed: S5.Array(S5.String)
|
|
1243
|
-
})
|
|
1244
|
-
}));
|
|
1245
|
-
var isLayoutParts = (value) => {
|
|
1246
|
-
return S5.is(LayoutPartsSchema)(value);
|
|
1247
|
-
};
|
|
1248
|
-
var isLayoutAdjustment = (value) => {
|
|
1249
|
-
return S5.is(LayoutAdjustmentSchema)(value);
|
|
1250
|
-
};
|
|
1251
|
-
var openIds = (layout, parts) => {
|
|
1252
|
-
return Object.values(parts ? pick2(layout, parts) : layout).flatMap((part) => part?.map((entry) => entry.id) ?? []).filter((id) => id !== void 0);
|
|
1253
|
-
};
|
|
1254
|
-
var firstIdInPart = (layout, part) => {
|
|
1255
|
-
if (!layout) {
|
|
1256
|
-
return void 0;
|
|
1257
|
-
}
|
|
1258
|
-
return layout[part]?.at(0)?.id;
|
|
1259
|
-
};
|
|
1260
|
-
var indexInPart = (layout, layoutCoordinate) => {
|
|
1261
|
-
if (!layout || !layoutCoordinate) {
|
|
1262
|
-
return void 0;
|
|
1263
|
-
}
|
|
1264
|
-
const { part, entryId } = layoutCoordinate;
|
|
1265
|
-
return layout[part]?.findIndex((entry) => entry.id === entryId);
|
|
1266
|
-
};
|
|
1267
|
-
var partLength = (layout, part) => {
|
|
1268
|
-
if (!layout || !part) {
|
|
1269
|
-
return 0;
|
|
1270
|
-
}
|
|
1271
|
-
return layout[part]?.length ?? 0;
|
|
1272
|
-
};
|
|
1273
|
-
var NAVIGATION_PLUGIN = "dxos.org/plugin/navigation";
|
|
1274
|
-
var NAVIGATION_ACTION = `${NAVIGATION_PLUGIN}/action`;
|
|
1275
|
-
var NavigationAction;
|
|
1276
|
-
(function(NavigationAction2) {
|
|
1277
|
-
class Open extends S5.TaggedClass()(`${NAVIGATION_ACTION}/open`, {
|
|
1278
|
-
input: S5.Struct({
|
|
1279
|
-
activeParts: ActiveParts,
|
|
1280
|
-
noToggle: S5.optional(S5.Boolean)
|
|
1281
|
-
}),
|
|
1282
|
-
output: S5.Struct({
|
|
1283
|
-
open: S5.Array(S5.String)
|
|
1284
|
-
})
|
|
1285
|
-
}) {
|
|
1286
|
-
}
|
|
1287
|
-
NavigationAction2.Open = Open;
|
|
1288
|
-
class AddToActive extends S5.TaggedClass()(`${NAVIGATION_ACTION}/add-to-active`, {
|
|
1289
|
-
input: S5.Struct({
|
|
1290
|
-
id: S5.String,
|
|
1291
|
-
part: LayoutPartSchema,
|
|
1292
|
-
scrollIntoView: S5.optional(S5.Boolean),
|
|
1293
|
-
pivotId: S5.optional(S5.String),
|
|
1294
|
-
positioning: S5.optional(S5.Literal("start", "end"))
|
|
1295
|
-
}),
|
|
1296
|
-
output: S5.Void
|
|
1297
|
-
}) {
|
|
1298
|
-
}
|
|
1299
|
-
NavigationAction2.AddToActive = AddToActive;
|
|
1300
|
-
class Set2 extends S5.TaggedClass()(`${NAVIGATION_ACTION}/set`, {
|
|
1301
|
-
input: S5.Struct({
|
|
1302
|
-
activeParts: ActiveParts
|
|
1303
|
-
}),
|
|
1304
|
-
output: S5.Void
|
|
1305
|
-
}) {
|
|
1306
|
-
}
|
|
1307
|
-
NavigationAction2.Set = Set2;
|
|
1308
|
-
class Close extends S5.TaggedClass()(`${NAVIGATION_ACTION}/close`, {
|
|
1309
|
-
input: S5.Struct({
|
|
1310
|
-
activeParts: ActiveParts,
|
|
1311
|
-
noToggle: S5.optional(S5.Boolean)
|
|
1312
|
-
}),
|
|
1313
|
-
output: S5.Void
|
|
1314
|
-
}) {
|
|
1315
|
-
}
|
|
1316
|
-
NavigationAction2.Close = Close;
|
|
1317
|
-
class Adjust extends S5.TaggedClass()(`${NAVIGATION_ACTION}/adjust`, {
|
|
1318
|
-
input: LayoutAdjustmentSchema,
|
|
1319
|
-
output: S5.Void
|
|
1320
|
-
}) {
|
|
1321
|
-
}
|
|
1322
|
-
NavigationAction2.Adjust = Adjust;
|
|
1323
|
-
class Expose extends S5.TaggedClass()(`${NAVIGATION_ACTION}/expose`, {
|
|
1324
|
-
input: S5.Struct({
|
|
1325
|
-
id: S5.String
|
|
1326
|
-
}),
|
|
1327
|
-
output: S5.Void
|
|
1328
|
-
}) {
|
|
1329
|
-
}
|
|
1330
|
-
NavigationAction2.Expose = Expose;
|
|
1331
|
-
})(NavigationAction || (NavigationAction = {}));
|
|
1332
|
-
|
|
1333
|
-
// packages/sdk/app-framework/src/common/surface.ts
|
|
1334
|
-
var createSurface = (definition) => definition;
|
|
1335
|
-
|
|
1336
|
-
// packages/sdk/app-framework/src/common/translations.ts
|
|
1337
|
-
import { z } from "zod";
|
|
1338
|
-
var ResourceKey = z.union([
|
|
1339
|
-
z.string(),
|
|
1340
|
-
z.record(z.any())
|
|
1341
|
-
]);
|
|
1342
|
-
var ResourceLanguage = z.record(ResourceKey);
|
|
1343
|
-
var Resource = z.record(ResourceLanguage);
|
|
1344
|
-
|
|
1345
|
-
// packages/sdk/app-framework/src/react/Surface.tsx
|
|
1346
|
-
var useSurfaces = () => {
|
|
1347
|
-
const surfaces = useCapabilities(Capabilities.ReactSurface);
|
|
1348
|
-
return useMemo2(() => surfaces.flat(), [
|
|
1349
|
-
surfaces
|
|
1350
|
-
]);
|
|
1351
|
-
};
|
|
1352
|
-
var findCandidates = (surfaces, { role, data }) => {
|
|
1353
|
-
return Object.values(surfaces).filter((definition) => Array.isArray(definition.role) ? definition.role.includes(role) : definition.role === role).filter(({ filter }) => filter ? filter(data ?? {}) : true).toSorted(byDisposition2);
|
|
1354
|
-
};
|
|
1355
|
-
var isSurfaceAvailable = (context, { role, data }) => {
|
|
1356
|
-
const surfaces = context.requestCapabilities(Capabilities.ReactSurface);
|
|
1357
|
-
const candidates = findCandidates(surfaces.flat(), {
|
|
1358
|
-
role,
|
|
1359
|
-
data
|
|
1336
|
+
var defaultEffect = () => Effect2.fail(new Error("Intent runtime not ready"));
|
|
1337
|
+
var defaultPromise = () => Effect2.runPromise(defaultEffect());
|
|
1338
|
+
var intent_dispatcher_default = (context) => {
|
|
1339
|
+
const state = create3({
|
|
1340
|
+
dispatch: defaultEffect,
|
|
1341
|
+
dispatchPromise: defaultPromise,
|
|
1342
|
+
undo: defaultEffect,
|
|
1343
|
+
undoPromise: defaultPromise
|
|
1360
1344
|
});
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
const
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
data
|
|
1345
|
+
const { dispatch, dispatchPromise, undo, undoPromise } = createDispatcher((module) => context.requestCapabilities(Capabilities.IntentResolver, (c, moduleId) => {
|
|
1346
|
+
return module ? moduleId === module : true;
|
|
1347
|
+
}).flat());
|
|
1348
|
+
const manager = context.requestCapability(Capabilities.PluginManager);
|
|
1349
|
+
state.dispatch = (intentChain, depth) => {
|
|
1350
|
+
return Effect2.gen(function* () {
|
|
1351
|
+
yield* manager._activate(Events.SetupIntents);
|
|
1352
|
+
return yield* dispatch(intentChain, depth);
|
|
1370
1353
|
});
|
|
1371
|
-
return limit ? definitions.slice(0, limit) : definitions;
|
|
1372
|
-
}, [
|
|
1373
|
-
surfaces,
|
|
1374
|
-
role,
|
|
1375
|
-
data,
|
|
1376
|
-
limit
|
|
1377
|
-
]);
|
|
1378
|
-
const nodes = candidates.map(({ component: Component2, id }) => /* @__PURE__ */ React3.createElement(Component2, {
|
|
1379
|
-
ref: forwardedRef,
|
|
1380
|
-
key: id,
|
|
1381
|
-
id,
|
|
1382
|
-
role,
|
|
1383
|
-
data,
|
|
1384
|
-
limit,
|
|
1385
|
-
...rest
|
|
1386
|
-
}));
|
|
1387
|
-
const suspense = placeholder ? /* @__PURE__ */ React3.createElement(Suspense, {
|
|
1388
|
-
fallback: placeholder
|
|
1389
|
-
}, nodes) : nodes;
|
|
1390
|
-
return fallback ? /* @__PURE__ */ React3.createElement(ErrorBoundary, {
|
|
1391
|
-
data,
|
|
1392
|
-
fallback
|
|
1393
|
-
}, suspense) : suspense;
|
|
1394
|
-
}));
|
|
1395
|
-
|
|
1396
|
-
// packages/sdk/app-framework/src/App.tsx
|
|
1397
|
-
import { effect as effect2 } from "@preact/signals-core";
|
|
1398
|
-
import React4 from "react";
|
|
1399
|
-
import { invariant as invariant2 } from "@dxos/invariant";
|
|
1400
|
-
import { create as create4 } from "@dxos/live-object";
|
|
1401
|
-
|
|
1402
|
-
// packages/sdk/app-framework/src/helpers.ts
|
|
1403
|
-
var topologicalSort = (nodes) => {
|
|
1404
|
-
const getDependencies = (nodeId, seen = /* @__PURE__ */ new Set(), path = /* @__PURE__ */ new Set()) => {
|
|
1405
|
-
if (path.has(nodeId)) {
|
|
1406
|
-
throw new Error(`Circular dependency detected involving ${nodeId}`);
|
|
1407
|
-
}
|
|
1408
|
-
if (seen.has(nodeId)) {
|
|
1409
|
-
return [];
|
|
1410
|
-
}
|
|
1411
|
-
const node = nodes.find((n) => n.id === nodeId);
|
|
1412
|
-
if (!node) {
|
|
1413
|
-
throw new Error(`Node ${nodeId} not found but is listed as a dependency`);
|
|
1414
|
-
}
|
|
1415
|
-
const newPath = /* @__PURE__ */ new Set([
|
|
1416
|
-
...path,
|
|
1417
|
-
nodeId
|
|
1418
|
-
]);
|
|
1419
|
-
const newSeen = /* @__PURE__ */ new Set([
|
|
1420
|
-
...seen,
|
|
1421
|
-
nodeId
|
|
1422
|
-
]);
|
|
1423
|
-
const dependsOn = node.dependsOn ?? [];
|
|
1424
|
-
return [
|
|
1425
|
-
...dependsOn.flatMap((depId) => getDependencies(depId, newSeen, newPath)),
|
|
1426
|
-
nodeId
|
|
1427
|
-
];
|
|
1428
1354
|
};
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
var createApp = ({ pluginManager, pluginLoader: _pluginLoader, plugins = [], core = plugins.map(({ meta }) => meta.id), defaults = [], placeholder = null, fallback = DefaultFallback, cacheEnabled = false }) => {
|
|
1437
|
-
const pluginLoader = _pluginLoader ?? ((id) => {
|
|
1438
|
-
const plugin = plugins.find((plugin2) => plugin2.meta.id === id);
|
|
1439
|
-
invariant2(plugin, `Plugin not found: ${id}`, {
|
|
1440
|
-
F: __dxlog_file3,
|
|
1441
|
-
L: 68,
|
|
1442
|
-
S: void 0,
|
|
1443
|
-
A: [
|
|
1444
|
-
"plugin",
|
|
1445
|
-
"`Plugin not found: ${id}`"
|
|
1446
|
-
]
|
|
1447
|
-
});
|
|
1448
|
-
return plugin;
|
|
1449
|
-
});
|
|
1450
|
-
const state = create4({
|
|
1451
|
-
ready: false,
|
|
1452
|
-
error: null
|
|
1453
|
-
});
|
|
1454
|
-
const cached = JSON.parse(localStorage.getItem(ENABLED_KEY) ?? "[]");
|
|
1455
|
-
const enabled = cacheEnabled && cached.length > 0 ? cached : defaults;
|
|
1456
|
-
const manager = pluginManager ?? new PluginManager({
|
|
1457
|
-
pluginLoader,
|
|
1458
|
-
plugins,
|
|
1459
|
-
core,
|
|
1460
|
-
enabled
|
|
1461
|
-
});
|
|
1462
|
-
manager.activation.on(({ event, state: _state, error }) => {
|
|
1463
|
-
if (event === Events.Startup.id) {
|
|
1464
|
-
state.ready = _state === "activated";
|
|
1465
|
-
}
|
|
1466
|
-
if (error && !state.ready && !state.error) {
|
|
1467
|
-
state.error = error;
|
|
1468
|
-
}
|
|
1469
|
-
});
|
|
1470
|
-
effect2(() => {
|
|
1471
|
-
cacheEnabled && localStorage.setItem(ENABLED_KEY, JSON.stringify(manager.enabled));
|
|
1472
|
-
});
|
|
1473
|
-
manager.context.contributeCapability({
|
|
1474
|
-
interface: Capabilities.PluginManager,
|
|
1475
|
-
implementation: manager,
|
|
1476
|
-
module: "dxos.org/app-framework/plugin-manager"
|
|
1477
|
-
});
|
|
1478
|
-
setupDevtools(manager);
|
|
1479
|
-
void manager.activate(Events.Startup);
|
|
1480
|
-
return () => /* @__PURE__ */ React4.createElement(ErrorBoundary, {
|
|
1481
|
-
fallback
|
|
1482
|
-
}, /* @__PURE__ */ React4.createElement(App, {
|
|
1483
|
-
placeholder,
|
|
1484
|
-
manager,
|
|
1485
|
-
state
|
|
1486
|
-
}));
|
|
1487
|
-
};
|
|
1488
|
-
var App = ({ placeholder, manager, state }) => {
|
|
1489
|
-
if (state.error) {
|
|
1490
|
-
throw state.error;
|
|
1491
|
-
}
|
|
1492
|
-
if (!state.ready) {
|
|
1493
|
-
return /* @__PURE__ */ React4.createElement(React4.Fragment, null, placeholder);
|
|
1494
|
-
}
|
|
1495
|
-
const reactContexts = manager.context.requestCapabilities(Capabilities.ReactContext);
|
|
1496
|
-
const reactRoots = manager.context.requestCapabilities(Capabilities.ReactRoot);
|
|
1497
|
-
const ComposedContext = composeContexts(reactContexts);
|
|
1498
|
-
return /* @__PURE__ */ React4.createElement(PluginManagerProvider, {
|
|
1499
|
-
value: manager
|
|
1500
|
-
}, /* @__PURE__ */ React4.createElement(ComposedContext, null, reactRoots.map(({ id, root: Component2 }) => /* @__PURE__ */ React4.createElement(Component2, {
|
|
1501
|
-
key: id
|
|
1502
|
-
}))));
|
|
1503
|
-
};
|
|
1504
|
-
var DefaultFallback = ({ error }) => {
|
|
1505
|
-
return /* @__PURE__ */ React4.createElement("div", {
|
|
1506
|
-
style: {
|
|
1507
|
-
padding: "1rem"
|
|
1508
|
-
}
|
|
1509
|
-
}, /* @__PURE__ */ React4.createElement("h1", {
|
|
1510
|
-
style: {
|
|
1511
|
-
fontSize: "1.2rem",
|
|
1512
|
-
fontWeight: 700,
|
|
1513
|
-
margin: "0.5rem 0"
|
|
1514
|
-
}
|
|
1515
|
-
}, error.message), /* @__PURE__ */ React4.createElement("pre", null, error.stack));
|
|
1516
|
-
};
|
|
1517
|
-
var composeContexts = (contexts) => {
|
|
1518
|
-
if (contexts.length === 0) {
|
|
1519
|
-
return ({ children }) => /* @__PURE__ */ React4.createElement(React4.Fragment, null, children);
|
|
1520
|
-
}
|
|
1521
|
-
return topologicalSort(contexts).map(({ context }) => context).reduce((Acc, Next) => ({ children }) => /* @__PURE__ */ React4.createElement(Acc, null, /* @__PURE__ */ React4.createElement(Next, null, children)));
|
|
1522
|
-
};
|
|
1523
|
-
var setupDevtools = (manager) => {
|
|
1524
|
-
globalThis.composer ??= {};
|
|
1525
|
-
globalThis.composer.manager = manager;
|
|
1355
|
+
state.dispatchPromise = async (intentChain) => {
|
|
1356
|
+
await manager.activate(Events.SetupIntents);
|
|
1357
|
+
return await dispatchPromise(intentChain);
|
|
1358
|
+
};
|
|
1359
|
+
state.undo = undo;
|
|
1360
|
+
state.undoPromise = undoPromise;
|
|
1361
|
+
return contributes(Capabilities.IntentDispatcher, state);
|
|
1526
1362
|
};
|
|
1527
1363
|
|
|
1528
1364
|
export {
|
|
@@ -1554,42 +1390,14 @@ export {
|
|
|
1554
1390
|
IntentAction,
|
|
1555
1391
|
createResolver,
|
|
1556
1392
|
createDispatcher,
|
|
1557
|
-
|
|
1558
|
-
usePluginManager,
|
|
1559
|
-
PluginManagerProvider,
|
|
1560
|
-
useCapabilities,
|
|
1561
|
-
useCapability,
|
|
1562
|
-
isSurfaceAvailable,
|
|
1563
|
-
Surface,
|
|
1564
|
-
useIntentDispatcher,
|
|
1565
|
-
useIntentResolver,
|
|
1566
|
-
IntentProvider,
|
|
1393
|
+
intent_dispatcher_default,
|
|
1567
1394
|
IntentPlugin,
|
|
1568
|
-
Toast,
|
|
1569
|
-
isLayoutMode,
|
|
1570
|
-
Layout,
|
|
1571
1395
|
LAYOUT_PLUGIN,
|
|
1572
1396
|
LAYOUT_ACTION,
|
|
1573
1397
|
LayoutAction,
|
|
1574
|
-
SLUG_LIST_SEPARATOR,
|
|
1575
|
-
SLUG_ENTRY_SEPARATOR,
|
|
1576
|
-
SLUG_KEY_VALUE_SEPARATOR,
|
|
1577
|
-
SLUG_PATH_SEPARATOR,
|
|
1578
|
-
SLUG_COLLECTION_INDICATOR,
|
|
1579
|
-
ActiveParts,
|
|
1580
|
-
isLayoutParts,
|
|
1581
|
-
isLayoutAdjustment,
|
|
1582
|
-
openIds,
|
|
1583
|
-
firstIdInPart,
|
|
1584
|
-
indexInPart,
|
|
1585
|
-
partLength,
|
|
1586
|
-
NAVIGATION_PLUGIN,
|
|
1587
|
-
NAVIGATION_ACTION,
|
|
1588
|
-
NavigationAction,
|
|
1589
1398
|
createSurface,
|
|
1590
1399
|
ResourceKey,
|
|
1591
1400
|
ResourceLanguage,
|
|
1592
|
-
Resource
|
|
1593
|
-
createApp
|
|
1401
|
+
Resource
|
|
1594
1402
|
};
|
|
1595
|
-
//# sourceMappingURL=chunk-
|
|
1403
|
+
//# sourceMappingURL=chunk-G3HBVVT5.mjs.map
|