@dxos/app-framework 0.7.5-labs.5f04cf6 → 0.7.5-labs.8a82073

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