@dxos/app-framework 0.7.5-main.9d2a38b → 0.7.5-main.e94eead

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 (205) hide show
  1. package/dist/lib/browser/app-graph-builder-S4MYSHQA.mjs +137 -0
  2. package/dist/lib/browser/app-graph-builder-S4MYSHQA.mjs.map +7 -0
  3. package/dist/lib/browser/{chunk-GNLU3GAU.mjs → chunk-BCMEJONP.mjs} +660 -823
  4. package/dist/lib/browser/chunk-BCMEJONP.mjs.map +7 -0
  5. package/dist/lib/browser/chunk-QS4J6O47.mjs +285 -0
  6. package/dist/lib/browser/chunk-QS4J6O47.mjs.map +7 -0
  7. package/dist/lib/browser/chunk-SRZH2PQ2.mjs +32 -0
  8. package/dist/lib/browser/chunk-SRZH2PQ2.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-GFBH7T2J.mjs +11 -0
  12. package/dist/lib/browser/intent-dispatcher-GFBH7T2J.mjs.map +7 -0
  13. package/dist/lib/browser/intent-resolver-KAFM7CQH.mjs +39 -0
  14. package/dist/lib/browser/intent-resolver-KAFM7CQH.mjs.map +7 -0
  15. package/dist/lib/browser/meta.json +1 -1
  16. package/dist/lib/browser/store-L3VRR7II.mjs +29 -0
  17. package/dist/lib/browser/store-L3VRR7II.mjs.map +7 -0
  18. package/dist/lib/browser/testing/index.mjs +13 -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-VMHWFCTP.cjs +146 -0
  23. package/dist/lib/node/app-graph-builder-VMHWFCTP.cjs.map +7 -0
  24. package/dist/lib/node/chunk-7Y6KJ3OK.cjs +1466 -0
  25. package/dist/lib/node/chunk-7Y6KJ3OK.cjs.map +7 -0
  26. package/dist/lib/node/chunk-B65NJEIJ.cjs +308 -0
  27. package/dist/lib/node/chunk-B65NJEIJ.cjs.map +7 -0
  28. package/dist/lib/node/chunk-VCIHQZSN.cjs +58 -0
  29. package/dist/lib/node/chunk-VCIHQZSN.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-PRCC4KZT.cjs +32 -0
  33. package/dist/lib/node/intent-dispatcher-PRCC4KZT.cjs.map +7 -0
  34. package/dist/lib/node/intent-resolver-OZDKCHPW.cjs +46 -0
  35. package/dist/lib/node/intent-resolver-OZDKCHPW.cjs.map +7 -0
  36. package/dist/lib/node/meta.json +1 -1
  37. package/dist/lib/node/store-BVUKNVKL.cjs +44 -0
  38. package/dist/lib/node/store-BVUKNVKL.cjs.map +7 -0
  39. package/dist/lib/node/testing/index.cjs +18 -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-XHI5IIXQ.mjs +138 -0
  44. package/dist/lib/node-esm/app-graph-builder-XHI5IIXQ.mjs.map +7 -0
  45. package/dist/lib/node-esm/chunk-CBT75GCX.mjs +34 -0
  46. package/dist/lib/node-esm/chunk-CBT75GCX.mjs.map +7 -0
  47. package/dist/lib/node-esm/chunk-JDAHZRYQ.mjs +286 -0
  48. package/dist/lib/node-esm/chunk-JDAHZRYQ.mjs.map +7 -0
  49. package/dist/lib/node-esm/{chunk-KPMTPXQI.mjs → chunk-TVIR2PHY.mjs} +660 -823
  50. package/dist/lib/node-esm/chunk-TVIR2PHY.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-LGACN32C.mjs +12 -0
  54. package/dist/lib/node-esm/intent-dispatcher-LGACN32C.mjs.map +7 -0
  55. package/dist/lib/node-esm/intent-resolver-RBNG76ZX.mjs +40 -0
  56. package/dist/lib/node-esm/intent-resolver-RBNG76ZX.mjs.map +7 -0
  57. package/dist/lib/node-esm/meta.json +1 -1
  58. package/dist/lib/node-esm/store-PHTOEREN.mjs +30 -0
  59. package/dist/lib/node-esm/store-PHTOEREN.mjs.map +7 -0
  60. package/dist/lib/node-esm/testing/index.mjs +13 -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 +2 -2
  65. package/dist/types/src/App.d.ts.map +1 -1
  66. package/dist/types/src/common/capabilities.d.ts +88 -124
  67. package/dist/types/src/common/capabilities.d.ts.map +1 -1
  68. package/dist/types/src/common/events.d.ts +22 -11
  69. package/dist/types/src/common/events.d.ts.map +1 -1
  70. package/dist/types/src/common/file.d.ts +1 -1
  71. package/dist/types/src/common/file.d.ts.map +1 -1
  72. package/dist/types/src/common/graph.d.ts +2 -2
  73. package/dist/types/src/common/graph.d.ts.map +1 -1
  74. package/dist/types/src/common/index.d.ts +0 -1
  75. package/dist/types/src/common/index.d.ts.map +1 -1
  76. package/dist/types/src/common/layout.d.ts +218 -121
  77. package/dist/types/src/common/layout.d.ts.map +1 -1
  78. package/dist/types/src/common/surface.d.ts +3 -3
  79. package/dist/types/src/common/surface.d.ts.map +1 -1
  80. package/dist/types/src/common/translations.d.ts +7 -7
  81. package/dist/types/src/common/translations.d.ts.map +1 -1
  82. package/dist/types/src/core/capabilities.d.ts +6 -2
  83. package/dist/types/src/core/capabilities.d.ts.map +1 -1
  84. package/dist/types/src/core/manager.d.ts +2 -9
  85. package/dist/types/src/core/manager.d.ts.map +1 -1
  86. package/dist/types/src/core/plugin.d.ts +5 -2
  87. package/dist/types/src/core/plugin.d.ts.map +1 -1
  88. package/dist/types/src/playground/debug/Debug.d.ts +2 -3
  89. package/dist/types/src/playground/debug/Debug.d.ts.map +1 -1
  90. package/dist/types/src/playground/debug/plugin.d.ts +1 -1
  91. package/dist/types/src/playground/debug/plugin.d.ts.map +1 -1
  92. package/dist/types/src/playground/generator/Main.d.ts +2 -3
  93. package/dist/types/src/playground/generator/Main.d.ts.map +1 -1
  94. package/dist/types/src/playground/generator/Toolbar.d.ts +2 -3
  95. package/dist/types/src/playground/generator/Toolbar.d.ts.map +1 -1
  96. package/dist/types/src/playground/generator/generator.d.ts +5 -3
  97. package/dist/types/src/playground/generator/generator.d.ts.map +1 -1
  98. package/dist/types/src/playground/generator/plugin.d.ts +1 -1
  99. package/dist/types/src/playground/generator/plugin.d.ts.map +1 -1
  100. package/dist/types/src/playground/layout/Layout.d.ts +2 -2
  101. package/dist/types/src/playground/layout/Layout.d.ts.map +1 -1
  102. package/dist/types/src/playground/layout/plugin.d.ts +1 -1
  103. package/dist/types/src/playground/layout/plugin.d.ts.map +1 -1
  104. package/dist/types/src/playground/logger/Toolbar.d.ts +2 -3
  105. package/dist/types/src/playground/logger/Toolbar.d.ts.map +1 -1
  106. package/dist/types/src/playground/logger/plugin.d.ts +1 -1
  107. package/dist/types/src/playground/logger/plugin.d.ts.map +1 -1
  108. package/dist/types/src/playground/logger/schema.d.ts +1 -1
  109. package/dist/types/src/playground/logger/schema.d.ts.map +1 -1
  110. package/dist/types/src/playground/playground.stories.d.ts +2 -3
  111. package/dist/types/src/playground/playground.stories.d.ts.map +1 -1
  112. package/dist/types/src/plugin-intent/IntentPlugin.d.ts +1 -1
  113. package/dist/types/src/plugin-intent/IntentPlugin.d.ts.map +1 -1
  114. package/dist/types/src/plugin-intent/actions.d.ts +1 -1
  115. package/dist/types/src/plugin-intent/actions.d.ts.map +1 -1
  116. package/dist/types/src/plugin-intent/index.d.ts +0 -1
  117. package/dist/types/src/plugin-intent/index.d.ts.map +1 -1
  118. package/dist/types/src/plugin-intent/intent-dispatcher.d.ts +27 -20
  119. package/dist/types/src/plugin-intent/intent-dispatcher.d.ts.map +1 -1
  120. package/dist/types/src/plugin-intent/intent.d.ts +3 -3
  121. package/dist/types/src/plugin-intent/intent.d.ts.map +1 -1
  122. package/dist/types/src/plugin-settings/SettingsPlugin.d.ts +1 -1
  123. package/dist/types/src/plugin-settings/SettingsPlugin.d.ts.map +1 -1
  124. package/dist/types/src/plugin-settings/actions.d.ts +11 -1
  125. package/dist/types/src/plugin-settings/actions.d.ts.map +1 -1
  126. package/dist/types/src/plugin-settings/app-graph-builder.d.ts +197 -0
  127. package/dist/types/src/plugin-settings/app-graph-builder.d.ts.map +1 -0
  128. package/dist/types/src/plugin-settings/intent-resolver.d.ts +4 -0
  129. package/dist/types/src/plugin-settings/intent-resolver.d.ts.map +1 -0
  130. package/dist/types/src/plugin-settings/store.d.ts +5 -0
  131. package/dist/types/src/plugin-settings/store.d.ts.map +1 -0
  132. package/dist/types/src/plugin-settings/translations.d.ts +11 -0
  133. package/dist/types/src/plugin-settings/translations.d.ts.map +1 -0
  134. package/dist/types/src/react/ErrorBoundary.d.ts +1 -1
  135. package/dist/types/src/{plugin-intent → react}/IntentContext.d.ts +1 -1
  136. package/dist/types/src/react/IntentContext.d.ts.map +1 -0
  137. package/dist/types/src/react/Surface.d.ts.map +1 -1
  138. package/dist/types/src/react/Surface.stories.d.ts +15 -0
  139. package/dist/types/src/react/Surface.stories.d.ts.map +1 -0
  140. package/dist/types/src/react/common.d.ts +13 -0
  141. package/dist/types/src/react/common.d.ts.map +1 -0
  142. package/dist/types/src/react/index.d.ts +2 -0
  143. package/dist/types/src/react/index.d.ts.map +1 -1
  144. package/dist/types/src/react/useCapabilities.d.ts.map +1 -1
  145. package/dist/types/src/react/useIntentResolver.d.ts +3 -0
  146. package/dist/types/src/react/useIntentResolver.d.ts.map +1 -0
  147. package/dist/types/src/testing/withPluginManager.d.ts +6 -4
  148. package/dist/types/src/testing/withPluginManager.d.ts.map +1 -1
  149. package/dist/types/src/worker.d.ts +4 -0
  150. package/dist/types/src/worker.d.ts.map +1 -0
  151. package/package.json +29 -21
  152. package/project.json +4 -3
  153. package/src/App.tsx +17 -15
  154. package/src/common/capabilities.ts +30 -11
  155. package/src/common/events.ts +16 -2
  156. package/src/common/file.ts +1 -1
  157. package/src/common/graph.ts +2 -2
  158. package/src/common/index.ts +0 -1
  159. package/src/common/layout.ts +207 -126
  160. package/src/common/surface.ts +2 -2
  161. package/src/common/translations.ts +7 -8
  162. package/src/core/capabilities.ts +16 -7
  163. package/src/core/manager.test.ts +22 -73
  164. package/src/core/manager.ts +105 -91
  165. package/src/core/plugin.ts +6 -3
  166. package/src/playground/debug/plugin.ts +1 -1
  167. package/src/playground/generator/Toolbar.tsx +11 -11
  168. package/src/playground/generator/generator.ts +25 -0
  169. package/src/playground/generator/plugin.ts +6 -1
  170. package/src/playground/layout/plugin.ts +1 -1
  171. package/src/playground/logger/Toolbar.tsx +2 -1
  172. package/src/playground/logger/plugin.ts +7 -4
  173. package/src/playground/logger/schema.ts +1 -1
  174. package/src/plugin-intent/IntentPlugin.tsx +3 -43
  175. package/src/plugin-intent/actions.ts +1 -1
  176. package/src/plugin-intent/errors.ts +1 -1
  177. package/src/plugin-intent/index.ts +0 -1
  178. package/src/plugin-intent/intent-dispatcher.test.ts +48 -29
  179. package/src/plugin-intent/intent-dispatcher.ts +81 -42
  180. package/src/plugin-intent/intent.ts +5 -5
  181. package/src/plugin-settings/SettingsPlugin.ts +19 -13
  182. package/src/plugin-settings/actions.ts +11 -1
  183. package/src/plugin-settings/app-graph-builder.ts +122 -0
  184. package/src/plugin-settings/intent-resolver.ts +34 -0
  185. package/src/plugin-settings/store.ts +30 -0
  186. package/src/plugin-settings/translations.ts +17 -0
  187. package/src/{plugin-intent → react}/IntentContext.tsx +2 -2
  188. package/src/react/Surface.stories.tsx +96 -0
  189. package/src/react/Surface.tsx +11 -8
  190. package/src/react/common.ts +12 -0
  191. package/src/react/index.ts +2 -0
  192. package/src/react/useCapabilities.ts +1 -0
  193. package/src/react/useIntentResolver.ts +22 -0
  194. package/src/testing/withPluginManager.tsx +28 -4
  195. package/src/worker.ts +11 -0
  196. package/tsconfig.json +7 -13
  197. package/dist/lib/browser/chunk-GNLU3GAU.mjs.map +0 -7
  198. package/dist/lib/node/chunk-FBA4BB3J.cjs +0 -1639
  199. package/dist/lib/node/chunk-FBA4BB3J.cjs.map +0 -7
  200. package/dist/lib/node-esm/chunk-KPMTPXQI.mjs.map +0 -7
  201. package/dist/types/src/common/navigation.d.ts +0 -241
  202. package/dist/types/src/common/navigation.d.ts.map +0 -1
  203. package/dist/types/src/plugin-intent/IntentContext.d.ts.map +0 -1
  204. package/src/common/navigation.ts +0 -199
  205. /package/{.eslintrc.js → .eslintrc.cjs} +0 -0
@@ -1,3 +1,95 @@
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 { log as log3 } from "@dxos/log";
5
+ import { byPosition } from "@dxos/util";
6
+
7
+ // packages/sdk/app-framework/src/plugin-intent/actions.ts
8
+ import { Schema as S2 } from "@effect/schema";
9
+
10
+ // packages/sdk/app-framework/src/plugin-intent/intent.ts
11
+ import { Schema as S } from "@effect/schema";
12
+ var createIntent = (schema, data = {}, params = {}) => {
13
+ const _ = S.validateSync(schema.fields.input)(data);
14
+ const intent = {
15
+ ...params,
16
+ _schema: schema,
17
+ id: schema._tag,
18
+ data
19
+ };
20
+ return {
21
+ first: intent,
22
+ last: intent,
23
+ all: [
24
+ intent
25
+ ]
26
+ };
27
+ };
28
+ var chain = (schema, data = {}, params = {}) => (intent) => {
29
+ const intents = "all" in intent ? intent.all : [
30
+ intent
31
+ ];
32
+ const first = intents[0];
33
+ const last = {
34
+ ...params,
35
+ _schema: schema,
36
+ id: schema._tag,
37
+ data
38
+ };
39
+ return {
40
+ first,
41
+ last,
42
+ all: [
43
+ ...intents,
44
+ last
45
+ ]
46
+ };
47
+ };
48
+ var Label = S.Union(S.String, S.mutable(S.Tuple(S.String, S.mutable(S.Struct({
49
+ ns: S.String,
50
+ count: S.optional(S.Number)
51
+ })))));
52
+
53
+ // packages/sdk/app-framework/src/plugin-intent/actions.ts
54
+ var INTENT_PLUGIN = "dxos.org/plugin/intent";
55
+ var INTENT_ACTION = `${INTENT_PLUGIN}/action`;
56
+ var IntentAction;
57
+ (function(IntentAction2) {
58
+ class ShowUndo extends S2.TaggedClass()(`${INTENT_ACTION}/show-undo`, {
59
+ input: S2.Struct({
60
+ message: Label
61
+ }),
62
+ output: S2.Void
63
+ }) {
64
+ }
65
+ IntentAction2.ShowUndo = ShowUndo;
66
+ })(IntentAction || (IntentAction = {}));
67
+
68
+ // packages/sdk/app-framework/src/plugin-intent/errors.ts
69
+ var BaseError = class extends Error {
70
+ constructor(code, message, context) {
71
+ super(message ?? code, {
72
+ cause: context
73
+ });
74
+ this.code = code;
75
+ this.context = context;
76
+ this.name = code;
77
+ Object.setPrototypeOf(this, new.target.prototype);
78
+ }
79
+ };
80
+ var NoResolversError = class extends BaseError {
81
+ constructor(action) {
82
+ super("NO_RESOLVERS", "No resolvers were found for the action", {
83
+ action
84
+ });
85
+ }
86
+ };
87
+ var CycleDetectedError = class extends BaseError {
88
+ constructor(context) {
89
+ super("CYCLE_DETECTED", "Intent execution limit exceeded. This is likely due to an infinite loop within intent resolvers.", context);
90
+ }
91
+ };
92
+
1
93
  // packages/sdk/app-framework/src/core/capabilities.ts
2
94
  import { effect, untracked } from "@preact/signals-core";
3
95
  import { Trigger } from "@dxos/async";
@@ -24,9 +116,10 @@ var contributes = (interfaceDef, implementation, deactivate) => {
24
116
  deactivate
25
117
  };
26
118
  };
27
- var lazy = (c) => (props) => c().then(({ default: getCapability }) => {
28
- return getCapability(props);
29
- });
119
+ var lazy = (c) => async (props) => {
120
+ const { default: getCapability } = await c();
121
+ return async () => getCapability(props);
122
+ };
30
123
  var PluginsContext = class {
31
124
  constructor({ activate, reset }) {
32
125
  this._definedCapabilities = /* @__PURE__ */ new Map();
@@ -48,10 +141,11 @@ var PluginsContext = class {
48
141
  current.push(new CapabilityImpl(moduleId, implementation));
49
142
  log("capability contributed", {
50
143
  id: interfaceDef.identifier,
144
+ moduleId,
51
145
  count: untracked(() => current.length)
52
146
  }, {
53
147
  F: __dxlog_file,
54
- L: 139,
148
+ L: 142,
55
149
  S: this,
56
150
  C: (f, a) => f(...a)
57
151
  });
@@ -72,7 +166,16 @@ var PluginsContext = class {
72
166
  count: untracked(() => current.length)
73
167
  }, {
74
168
  F: __dxlog_file,
75
- L: 154,
169
+ L: 161,
170
+ S: this,
171
+ C: (f, a) => f(...a)
172
+ });
173
+ } else {
174
+ log.warn("capability not removed", {
175
+ id: interfaceDef.identifier
176
+ }, {
177
+ F: __dxlog_file,
178
+ L: 163,
76
179
  S: this,
77
180
  C: (f, a) => f(...a)
78
181
  });
@@ -105,7 +208,7 @@ var PluginsContext = class {
105
208
  const capability = this.requestCapabilities(interfaceDef, filter)[0];
106
209
  invariant(capability, `No capability found for ${interfaceDef.identifier}`, {
107
210
  F: __dxlog_file,
108
- L: 190,
211
+ L: 199,
109
212
  S: this,
110
213
  A: [
111
214
  "capability",
@@ -156,7 +259,7 @@ var getEvents = (events) => "type" in events ? events.events : [
156
259
 
157
260
  // packages/sdk/app-framework/src/core/manager.ts
158
261
  import { untracked as untracked2 } from "@preact/signals-core";
159
- import { Effect, Either, Match } from "effect";
262
+ import { Array as A, Effect, Either, Match, pipe } from "effect";
160
263
  import { Event } from "@dxos/async";
161
264
  import { create as create2 } from "@dxos/live-object";
162
265
  import { log as log2 } from "@dxos/log";
@@ -179,7 +282,6 @@ var PluginManager = class {
179
282
  enabled,
180
283
  modules: [],
181
284
  active: [],
182
- pendingRemoval: [],
183
285
  pendingReset: [],
184
286
  eventsFired: []
185
287
  });
@@ -228,14 +330,6 @@ var PluginManager = class {
228
330
  return this._state.active;
229
331
  }
230
332
  /**
231
- * Ids of modules which are pending removal.
232
- *
233
- * @reactive
234
- */
235
- get pendingRemoval() {
236
- return this._state.pendingRemoval;
237
- }
238
- /**
239
333
  * Ids of events which have been fired.
240
334
  *
241
335
  * @reactive
@@ -261,7 +355,7 @@ var PluginManager = class {
261
355
  id
262
356
  }, {
263
357
  F: __dxlog_file2,
264
- L: 157,
358
+ L: 146,
265
359
  S: this,
266
360
  C: (f, a) => f(...a)
267
361
  });
@@ -275,12 +369,12 @@ var PluginManager = class {
275
369
  * @param id The id of the plugin.
276
370
  */
277
371
  enable(id) {
278
- return untracked2(() => {
372
+ return untracked2(async () => {
279
373
  log2("enable plugin", {
280
374
  id
281
375
  }, {
282
376
  F: __dxlog_file2,
283
- L: 170,
377
+ L: 159,
284
378
  S: this,
285
379
  C: (f, a) => f(...a)
286
380
  });
@@ -295,6 +389,19 @@ var PluginManager = class {
295
389
  this._addModule(module);
296
390
  this._setPendingResetByModule(module);
297
391
  });
392
+ log2("pending reset", {
393
+ events: [
394
+ ...this.pendingReset
395
+ ]
396
+ }, {
397
+ F: __dxlog_file2,
398
+ L: 174,
399
+ S: this,
400
+ C: (f, a) => f(...a)
401
+ });
402
+ await Effect.runPromise(Effect.all(this.pendingReset.map((event) => this._activate(event)), {
403
+ concurrency: "unbounded"
404
+ }));
298
405
  return true;
299
406
  });
300
407
  }
@@ -308,7 +415,7 @@ var PluginManager = class {
308
415
  id
309
416
  }, {
310
417
  F: __dxlog_file2,
311
- L: 194,
418
+ L: 192,
312
419
  S: this,
313
420
  C: (f, a) => f(...a)
314
421
  });
@@ -325,12 +432,12 @@ var PluginManager = class {
325
432
  * @param id The id of the plugin.
326
433
  */
327
434
  disable(id) {
328
- return untracked2(() => {
435
+ return untracked2(async () => {
329
436
  log2("disable plugin", {
330
437
  id
331
438
  }, {
332
439
  F: __dxlog_file2,
333
- L: 211,
440
+ L: 209,
334
441
  S: this,
335
442
  C: (f, a) => f(...a)
336
443
  });
@@ -344,15 +451,9 @@ var PluginManager = class {
344
451
  const enabledIndex = this._state.enabled.findIndex((enabled) => enabled === id);
345
452
  if (enabledIndex !== -1) {
346
453
  this._state.enabled.splice(enabledIndex, 1);
454
+ await Effect.runPromise(this._deactivate(id));
347
455
  plugin.modules.forEach((module) => {
348
- if (this._state.active.includes(module.id)) {
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
- }
456
+ this._removeModule(module.id);
356
457
  });
357
458
  }
358
459
  return true;
@@ -388,7 +489,7 @@ var PluginManager = class {
388
489
  id: plugin.meta.id
389
490
  }, {
390
491
  F: __dxlog_file2,
391
- L: 270,
492
+ L: 262,
392
493
  S: this,
393
494
  C: (f, a) => f(...a)
394
495
  });
@@ -403,7 +504,7 @@ var PluginManager = class {
403
504
  id
404
505
  }, {
405
506
  F: __dxlog_file2,
406
- L: 279,
507
+ L: 271,
407
508
  S: this,
408
509
  C: (f, a) => f(...a)
409
510
  });
@@ -419,7 +520,7 @@ var PluginManager = class {
419
520
  id: module.id
420
521
  }, {
421
522
  F: __dxlog_file2,
422
- L: 289,
523
+ L: 281,
423
524
  S: this,
424
525
  C: (f, a) => f(...a)
425
526
  });
@@ -434,7 +535,7 @@ var PluginManager = class {
434
535
  id
435
536
  }, {
436
537
  F: __dxlog_file2,
437
- L: 298,
538
+ L: 290,
438
539
  S: this,
439
540
  C: (f, a) => f(...a)
440
541
  });
@@ -462,20 +563,13 @@ var PluginManager = class {
462
563
  _setPendingResetByModule(module) {
463
564
  return untracked2(() => {
464
565
  const activationEvents = getEvents(module.activatesOn).map(eventKey).filter((key) => this._state.eventsFired.includes(key));
465
- const parentEvents = activationEvents.flatMap((event) => {
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));
566
+ const pendingReset = Array.from(new Set(activationEvents)).filter((event) => !this._state.pendingReset.includes(event));
473
567
  if (pendingReset.length > 0) {
474
568
  log2("pending reset", {
475
569
  events: pendingReset
476
570
  }, {
477
571
  F: __dxlog_file2,
478
- L: 342,
572
+ L: 328,
479
573
  S: this,
480
574
  C: (f, a) => f(...a)
481
575
  });
@@ -483,59 +577,87 @@ var PluginManager = class {
483
577
  }
484
578
  });
485
579
  }
580
+ /**
581
+ * @internal
582
+ */
486
583
  // TODO(wittjosiah): Improve error typing.
487
584
  _activate(event) {
488
- const self = this;
489
- return Effect.gen(function* () {
585
+ return Effect.gen(this, function* () {
490
586
  const key = typeof event === "string" ? event : eventKey(event);
491
587
  log2("activating", {
492
588
  key
493
589
  }, {
494
590
  F: __dxlog_file2,
495
- L: 353,
591
+ L: 341,
496
592
  S: this,
497
593
  C: (f, a) => f(...a)
498
594
  });
499
- const pendingIndex = self._state.pendingReset.findIndex((event2) => event2 === key);
595
+ const pendingIndex = this._state.pendingReset.findIndex((event2) => event2 === key);
500
596
  if (pendingIndex !== -1) {
501
- self._state.pendingReset.splice(pendingIndex, 1);
597
+ this._state.pendingReset.splice(pendingIndex, 1);
502
598
  }
503
- const modules = self._getInactiveModulesByEvent(key);
599
+ const modules = this._getInactiveModulesByEvent(key).filter((module) => {
600
+ const allOf2 = isAllOf(module.activatesOn);
601
+ if (!allOf2) {
602
+ return true;
603
+ }
604
+ const events = module.activatesOn.events.filter((event2) => eventKey(event2) !== key);
605
+ return events.every((event2) => this._state.eventsFired.includes(eventKey(event2)));
606
+ });
504
607
  if (modules.length === 0) {
505
608
  log2("no modules to activate", {
506
609
  key
507
610
  }, {
508
611
  F: __dxlog_file2,
509
- L: 361,
612
+ L: 357,
510
613
  S: this,
511
614
  C: (f, a) => f(...a)
512
615
  });
616
+ if (!this._state.eventsFired.includes(key)) {
617
+ this._state.eventsFired.push(key);
618
+ }
513
619
  return false;
514
620
  }
515
- self.activation.emit({
621
+ log2("activating modules", {
622
+ key,
623
+ modules: modules.map((module) => module.id)
624
+ }, {
625
+ F: __dxlog_file2,
626
+ L: 364,
627
+ S: this,
628
+ C: (f, a) => f(...a)
629
+ });
630
+ this.activation.emit({
516
631
  event: key,
517
632
  state: "activating"
518
633
  });
519
- for (const module of modules) {
520
- if (isAllOf(module.activatesOn) && !module.activatesOn.events.filter((event2) => eventKey(event2) !== key).every((event2) => self._state.eventsFired.includes(eventKey(event2)))) {
521
- continue;
522
- }
523
- yield* Effect.all(module.activatesBefore?.map((event2) => self._activate(event2)) ?? []);
524
- const result = yield* self._activateModule(module).pipe(Effect.either);
525
- if (Either.isLeft(result)) {
526
- self.activation.emit({
527
- event: key,
528
- state: "error",
529
- error: result.left
530
- });
531
- yield* Effect.fail(result.left);
532
- }
533
- yield* Effect.all(module.activatesAfter?.map((event2) => self._activate(event2)) ?? []);
634
+ const getCapabilities = yield* Effect.all(modules.map(({ activate }) => Effect.tryPromise({
635
+ try: async () => activate(this.context),
636
+ catch: (error) => error
637
+ })), {
638
+ concurrency: "unbounded"
639
+ });
640
+ const result = yield* pipe(
641
+ modules,
642
+ A.zip(getCapabilities),
643
+ A.map(([module, getCapabilities2]) => this._activateModule(module, getCapabilities2)),
644
+ // TODO(wittjosiah): This currently can't be run in parallel.
645
+ // Running this with concurrency causes races with `allOf` activation events.
646
+ Effect.all,
647
+ Effect.either
648
+ );
649
+ if (Either.isLeft(result)) {
650
+ this.activation.emit({
651
+ event: key,
652
+ state: "error",
653
+ error: result.left
654
+ });
655
+ yield* Effect.fail(result.left);
534
656
  }
535
- if (!self._state.eventsFired.includes(key)) {
536
- self._state.eventsFired.push(key);
657
+ if (!this._state.eventsFired.includes(key)) {
658
+ this._state.eventsFired.push(key);
537
659
  }
538
- self.activation.emit({
660
+ this.activation.emit({
539
661
  event: key,
540
662
  state: "activated"
541
663
  });
@@ -543,79 +665,105 @@ var PluginManager = class {
543
665
  key
544
666
  }, {
545
667
  F: __dxlog_file2,
546
- L: 393,
668
+ L: 398,
547
669
  S: this,
548
670
  C: (f, a) => f(...a)
549
671
  });
550
672
  return true;
551
673
  });
552
674
  }
553
- _activateModule(module) {
554
- const self = this;
555
- return Effect.gen(function* () {
556
- const program = module.activate(self.context);
557
- const maybeCapabilities = yield* Match.value(program).pipe(Match.when(Effect.isEffect, (effect3) => effect3), Match.when(isPromise, (promise) => Effect.tryPromise({
558
- try: () => promise,
559
- catch: (error) => error
560
- })), Match.orElse((program2) => Effect.succeed(program2)));
561
- const capabilities = Match.value(maybeCapabilities).pipe(Match.when(Array.isArray, (array) => array), Match.orElse((value) => [
675
+ _activateModule(module, getCapabilities) {
676
+ return Effect.gen(this, function* () {
677
+ yield* Effect.all(module.activatesBefore?.map((event) => this._activate(event)) ?? [], {
678
+ concurrency: "unbounded"
679
+ });
680
+ log2("activating module...", {
681
+ module: module.id
682
+ }, {
683
+ F: __dxlog_file2,
684
+ L: 413,
685
+ S: this,
686
+ C: (f, a) => f(...a)
687
+ });
688
+ const maybeCapabilities = typeof getCapabilities === "function" ? getCapabilities() : getCapabilities;
689
+ const resolvedCapabilities = yield* Match.value(maybeCapabilities).pipe(
690
+ // TODO(wittjosiah): Activate with an effect?
691
+ // Match.when(Effect.isEffect, (effect) => effect),
692
+ Match.when(isPromise, (promise) => Effect.tryPromise({
693
+ try: () => promise,
694
+ catch: (error) => error
695
+ })),
696
+ Match.orElse((program) => Effect.succeed(program))
697
+ );
698
+ const capabilities = Match.value(resolvedCapabilities).pipe(Match.when(Array.isArray, (array) => array), Match.orElse((value) => [
562
699
  value
563
700
  ]));
564
701
  capabilities.forEach((capability) => {
565
- self.context.contributeCapability({
702
+ this.context.contributeCapability({
566
703
  module: module.id,
567
704
  ...capability
568
705
  });
569
706
  });
570
- self._state.active.push(module.id);
571
- self._capabilities.set(module.id, capabilities);
707
+ this._state.active.push(module.id);
708
+ this._capabilities.set(module.id, capabilities);
709
+ log2("activated module", {
710
+ module: module.id
711
+ }, {
712
+ F: __dxlog_file2,
713
+ L: 436,
714
+ S: this,
715
+ C: (f, a) => f(...a)
716
+ });
717
+ yield* Effect.all(module.activatesAfter?.map((event) => this._activate(event)) ?? [], {
718
+ concurrency: "unbounded"
719
+ });
572
720
  });
573
721
  }
574
722
  _deactivate(id) {
575
- const self = this;
576
- return Effect.gen(function* () {
577
- const plugin = self._getPlugin(id);
723
+ return Effect.gen(this, function* () {
724
+ const plugin = this._getPlugin(id);
578
725
  if (!plugin) {
579
726
  return false;
580
727
  }
581
728
  const modules = plugin.modules;
582
- const results = yield* Effect.all(modules.map((module) => self._deactivateModule(module)));
729
+ const results = yield* Effect.all(modules.map((module) => this._deactivateModule(module)), {
730
+ concurrency: "unbounded"
731
+ });
583
732
  return results.every((result) => result);
584
733
  });
585
734
  }
586
735
  _deactivateModule(module) {
587
- const self = this;
588
- return Effect.gen(function* () {
736
+ return Effect.gen(this, function* () {
589
737
  const id = module.id;
590
738
  log2("deactivating", {
591
739
  id
592
740
  }, {
593
741
  F: __dxlog_file2,
594
- L: 444,
742
+ L: 463,
595
743
  S: this,
596
744
  C: (f, a) => f(...a)
597
745
  });
598
- const capabilities = self._capabilities.get(id);
746
+ const capabilities = this._capabilities.get(id);
599
747
  if (capabilities) {
600
748
  for (const capability of capabilities) {
601
- self.context.removeCapability(capability.interface, capability.implementation);
749
+ this.context.removeCapability(capability.interface, capability.implementation);
602
750
  const program = capability.deactivate?.();
603
- yield* Match.value(program).pipe(Match.when(Effect.isEffect, (effect3) => effect3), Match.when(isPromise, (promise) => Effect.tryPromise({
751
+ yield* Match.value(program).pipe(Match.when(Effect.isEffect, (effect2) => effect2), Match.when(isPromise, (promise) => Effect.tryPromise({
604
752
  try: () => promise,
605
753
  catch: (error) => error
606
754
  })), Match.orElse((program2) => Effect.succeed(program2)));
607
755
  }
608
- self._capabilities.delete(id);
756
+ this._capabilities.delete(id);
609
757
  }
610
- const activeIndex = self._state.active.findIndex((event) => event === id);
758
+ const activeIndex = this._state.active.findIndex((event) => event === id);
611
759
  if (activeIndex !== -1) {
612
- self._state.active.splice(activeIndex, 1);
760
+ this._state.active.splice(activeIndex, 1);
613
761
  }
614
762
  log2("deactivated", {
615
763
  id
616
764
  }, {
617
765
  F: __dxlog_file2,
618
- L: 470,
766
+ L: 489,
619
767
  S: this,
620
768
  C: (f, a) => f(...a)
621
769
  });
@@ -623,27 +771,22 @@ var PluginManager = class {
623
771
  });
624
772
  }
625
773
  _reset(event) {
626
- const self = this;
627
- return Effect.gen(function* () {
774
+ return Effect.gen(this, function* () {
628
775
  const key = typeof event === "string" ? event : eventKey(event);
629
776
  log2("reset", {
630
777
  key
631
778
  }, {
632
779
  F: __dxlog_file2,
633
- L: 479,
780
+ L: 497,
634
781
  S: this,
635
782
  C: (f, a) => f(...a)
636
783
  });
637
- const modules = self._getActiveModulesByEvent(key);
638
- const results = yield* Effect.all(modules.map((module) => self._deactivateModule(module)));
639
- if (self._state.pendingRemoval.length > 0) {
640
- self._state.pendingRemoval.forEach((id) => {
641
- self._removeModule(id);
642
- });
643
- self._state.pendingRemoval.splice(0, self._state.pendingRemoval.length);
644
- }
784
+ const modules = this._getActiveModulesByEvent(key);
785
+ const results = yield* Effect.all(modules.map((module) => this._deactivateModule(module)), {
786
+ concurrency: "unbounded"
787
+ });
645
788
  if (results.every((result) => result)) {
646
- return yield* self._activate(key);
789
+ return yield* this._activate(key);
647
790
  } else {
648
791
  return false;
649
792
  }
@@ -683,9 +826,6 @@ var Capabilities;
683
826
  Capabilities2.IntentResolver = defineCapability("dxos.org/app-framework/capability/intent-resolver");
684
827
  Capabilities2.IntentDispatcher = defineCapability("dxos.org/app-framework/capability/intent-dispatcher");
685
828
  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
829
  Capabilities2.Translations = defineCapability("dxos.org/app-framework/capability/translations");
690
830
  Capabilities2.AppGraph = defineCapability("dxos.org/app-framework/capability/app-graph");
691
831
  Capabilities2.AppGraphBuilder = defineCapability("dxos.org/app-framework/capability/app-graph-builder");
@@ -693,6 +833,8 @@ var Capabilities;
693
833
  Capabilities2.SettingsStore = defineCapability("dxos.org/app-framework/capability/settings-store");
694
834
  Capabilities2.Settings = defineCapability("dxos.org/app-framework/capability/settings");
695
835
  Capabilities2.Metadata = defineCapability("dxos.org/app-framework/capability/metadata");
836
+ Capabilities2.Tools = defineCapability("dxos.org/app-framework/capability/tools");
837
+ Capabilities2.ArtifactDefinition = defineCapability("dxos.org/app-framework/capability/artifact-definition");
696
838
  Capabilities2.FileUploader = defineCapability("dxos.org/app-framework/capability/file-uploader");
697
839
  })(Capabilities || (Capabilities = {}));
698
840
 
@@ -700,20 +842,22 @@ var Capabilities;
700
842
  var Events;
701
843
  (function(Events2) {
702
844
  Events2.Startup = defineEvent("dxos.org/app-framework/event/startup");
703
- Events2.SetupIntents = defineEvent("dxos.org/app-framework/event/setup-intents");
845
+ Events2.SetupReactSurface = defineEvent("dxos.org/app-framework/event/setup-react-surface");
846
+ Events2.SetupMetadata = defineEvent("dxos.org/app-framework/event/setup-metadata");
847
+ Events2.SetupIntentResolver = defineEvent("dxos.org/app-framework/event/setup-intent-resolver");
704
848
  Events2.SetupSettings = defineEvent("dxos.org/app-framework/event/setup-settings");
705
849
  Events2.SetupAppGraph = defineEvent("dxos.org/app-framework/event/setup-graph");
706
850
  Events2.SetupTranslations = defineEvent("dxos.org/app-framework/event/setup-translations");
851
+ Events2.SetupArtifactDefinition = defineEvent("dxos.org/app-framework/event/setup-artifact-definition");
707
852
  Events2.DispatcherReady = defineEvent("dxos.org/app-framework/event/dispatcher-ready");
708
853
  Events2.SettingsReady = defineEvent("dxos.org/app-framework/event/settings-ready");
709
854
  Events2.AppGraphReady = defineEvent("dxos.org/app-framework/event/graph-ready");
710
855
  Events2.createStateEvent = (specifier) => defineEvent("dxos.org/app-framework/event/state", specifier);
711
856
  Events2.LayoutReady = Events2.createStateEvent(Capabilities.Layout.identifier);
712
- Events2.LocationReady = Events2.createStateEvent(Capabilities.Location.identifier);
713
857
  })(Events || (Events = {}));
714
858
 
715
859
  // packages/sdk/app-framework/src/common/file.ts
716
- import { S } from "@dxos/echo-schema";
860
+ import { Schema as S3 } from "@effect/schema";
717
861
  var defaultFileTypes = {
718
862
  images: [
719
863
  "png",
@@ -733,127 +877,386 @@ var defaultFileTypes = {
733
877
  "md"
734
878
  ]
735
879
  };
736
- var FileInfoSchema = S.Struct({
737
- name: S.String,
738
- type: S.String,
739
- url: S.optional(S.String),
740
- 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)
741
885
  });
742
886
 
743
- // packages/sdk/app-framework/src/plugin-intent/intent.ts
744
- import { S as S2 } from "@dxos/echo-schema";
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
- })))));
887
+ // packages/sdk/app-framework/src/common/layout.ts
888
+ import { Schema as S4 } from "@effect/schema";
785
889
 
786
- // packages/sdk/app-framework/src/plugin-intent/actions.ts
787
- import { S as S3 } from "@dxos/echo-schema";
788
- var INTENT_PLUGIN = "dxos.org/plugin/intent";
789
- var INTENT_ACTION = `${INTENT_PLUGIN}/action`;
790
- var IntentAction;
791
- (function(IntentAction2) {
792
- class ShowUndo extends S3.TaggedClass()(`${INTENT_ACTION}/show-undo`, {
793
- input: S3.Struct({
794
- 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-GFBH7T2J.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
+ }))
795
927
  }),
796
- output: S3.Void
928
+ output: S4.Void
797
929
  }) {
798
930
  }
799
- IntentAction2.ShowUndo = ShowUndo;
800
- })(IntentAction || (IntentAction = {}));
801
-
802
- // packages/sdk/app-framework/src/plugin-intent/intent-dispatcher.ts
803
- import { Effect as Effect2, Option, pipe, Ref } from "effect";
804
- import { byDisposition } from "@dxos/util";
805
-
806
- // packages/sdk/app-framework/src/plugin-intent/errors.ts
807
- var BaseError = class extends Error {
808
- constructor(code, message, context) {
809
- super(message ?? code);
810
- this.code = code;
811
- this.context = context;
812
- this.name = code;
813
- 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
+ }) {
814
952
  }
815
- };
816
- var NoResolversError = class extends BaseError {
817
- constructor(action) {
818
- super("NO_RESOLVERS", "No resolvers were found for the action", {
819
- action
820
- });
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
+ }) {
821
970
  }
822
- };
823
- var CycleDetectedError = class extends BaseError {
824
- constructor(context) {
825
- 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
+ }) {
826
988
  }
827
- };
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", "end").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
+ side: S4.optional(S4.Literal("top", "right", "bottom", "left").annotations({
1033
+ description: "The side of the anchor."
1034
+ })),
1035
+ state: S4.optional(S4.Boolean.annotations({
1036
+ description: "Whether the popover is open or closed."
1037
+ })),
1038
+ props: S4.optional(S4.Record({
1039
+ key: S4.String,
1040
+ value: S4.Any
1041
+ }).annotations({
1042
+ description: "Additional props for the popover."
1043
+ }))
1044
+ })
1045
+ }),
1046
+ output: S4.Void
1047
+ }) {
1048
+ }
1049
+ LayoutAction2.UpdatePopover = UpdatePopover;
1050
+ LayoutAction2.Toast = S4.Struct({
1051
+ id: S4.String.annotations({
1052
+ description: "The id of the toast."
1053
+ }),
1054
+ title: S4.optional(Label.annotations({
1055
+ description: "The title of the toast."
1056
+ })),
1057
+ description: S4.optional(Label.annotations({
1058
+ description: "The description of the toast."
1059
+ })),
1060
+ icon: S4.optional(S4.String.annotations({
1061
+ description: "The icon of the toast."
1062
+ })),
1063
+ duration: S4.optional(S4.Number.annotations({
1064
+ description: "The duration of the toast."
1065
+ })),
1066
+ closeLabel: S4.optional(Label.annotations({
1067
+ description: "The label of the close button."
1068
+ })),
1069
+ actionLabel: S4.optional(Label.annotations({
1070
+ description: "The label of the action button."
1071
+ })),
1072
+ actionAlt: S4.optional(Label.annotations({
1073
+ description: "The alt text of the action button."
1074
+ })),
1075
+ onAction: S4.optional(S4.Any.annotations({
1076
+ description: "The action to perform when the action button is clicked."
1077
+ }))
1078
+ });
1079
+ class AddToast extends S4.TaggedClass()(LayoutAction2.UPDATE_LAYOUT, {
1080
+ input: S4.Struct({
1081
+ part: S4.Literal("toast").annotations({
1082
+ description: "Adding a toast."
1083
+ }),
1084
+ subject: LayoutAction2.Toast.annotations({
1085
+ description: "The toast to add."
1086
+ })
1087
+ }),
1088
+ output: S4.Void
1089
+ }) {
1090
+ }
1091
+ LayoutAction2.AddToast = AddToast;
1092
+ class SwitchWorkspace extends S4.TaggedClass()(LayoutAction2.UPDATE_LAYOUT, {
1093
+ input: S4.Struct({
1094
+ part: S4.Literal("workspace").annotations({
1095
+ description: "Switching the workspace."
1096
+ }),
1097
+ subject: S4.String.annotations({
1098
+ description: "The id of the workspace to switch to."
1099
+ })
1100
+ }),
1101
+ output: S4.Void
1102
+ }) {
1103
+ }
1104
+ LayoutAction2.SwitchWorkspace = SwitchWorkspace;
1105
+ class RevertWorkspace extends S4.TaggedClass()(LayoutAction2.UPDATE_LAYOUT, {
1106
+ input: S4.Struct({
1107
+ part: S4.Literal("workspace").annotations({
1108
+ description: "Switching the workspace."
1109
+ }),
1110
+ options: S4.Struct({
1111
+ revert: S4.Literal(true).annotations({
1112
+ description: "Revert to the previous workspace."
1113
+ })
1114
+ })
1115
+ }),
1116
+ output: S4.Void
1117
+ }) {
1118
+ }
1119
+ LayoutAction2.RevertWorkspace = RevertWorkspace;
1120
+ class Open extends S4.TaggedClass()(LayoutAction2.UPDATE_LAYOUT, {
1121
+ input: S4.Struct({
1122
+ part: S4.Literal("main").annotations({
1123
+ description: "Opening an item in the main content area."
1124
+ }),
1125
+ subject: S4.Array(S4.String.annotations({
1126
+ description: "Ids of the items to open."
1127
+ })),
1128
+ options: S4.optional(S4.Struct({
1129
+ state: S4.optional(S4.Literal(true).annotations({
1130
+ description: "The items are being added."
1131
+ })),
1132
+ key: S4.optional(S4.String.annotations({
1133
+ description: "If provided, will replace item with a matching key (id prefix)."
1134
+ })),
1135
+ scrollIntoView: S4.optional(S4.Boolean.annotations({
1136
+ description: "Scroll the items into view."
1137
+ })),
1138
+ pivotId: S4.optional(S4.String.annotations({
1139
+ description: "The id of the item to place new items next to."
1140
+ })),
1141
+ positioning: S4.optional(S4.Union(S4.Literal("start").annotations({
1142
+ description: "The items are being added before the pivot item."
1143
+ }), S4.Literal("end").annotations({
1144
+ description: "The items are being added after the pivot item."
1145
+ })))
1146
+ }))
1147
+ }),
1148
+ output: S4.Void
1149
+ }) {
1150
+ }
1151
+ LayoutAction2.Open = Open;
1152
+ class Set2 extends S4.TaggedClass()(LayoutAction2.UPDATE_LAYOUT, {
1153
+ input: S4.Struct({
1154
+ part: S4.Literal("main").annotations({
1155
+ description: "Setting items in the main content area."
1156
+ }),
1157
+ subject: S4.Array(S4.String.annotations({
1158
+ description: "Ids of the items to set."
1159
+ })),
1160
+ options: S4.Struct({
1161
+ override: S4.Literal(true).annotations({
1162
+ description: "Override the current items in the main content area."
1163
+ })
1164
+ })
1165
+ }),
1166
+ output: S4.Void
1167
+ }) {
1168
+ }
1169
+ LayoutAction2.Set = Set2;
1170
+ class Close extends S4.TaggedClass()(LayoutAction2.UPDATE_LAYOUT, {
1171
+ input: S4.Struct({
1172
+ part: S4.Literal("main").annotations({
1173
+ description: "Closing items in the main content area."
1174
+ }),
1175
+ subject: S4.Array(S4.String.annotations({
1176
+ description: "Ids of the items to close."
1177
+ })),
1178
+ options: S4.Struct({
1179
+ state: S4.Literal(false).annotations({
1180
+ description: "The items are being removed."
1181
+ })
1182
+ })
1183
+ }),
1184
+ output: S4.Void
1185
+ }) {
1186
+ }
1187
+ LayoutAction2.Close = Close;
1188
+ class ScrollIntoView extends S4.TaggedClass()(LayoutAction2.UPDATE_LAYOUT, {
1189
+ input: S4.Struct({
1190
+ part: S4.Literal("current").annotations({
1191
+ description: "Setting the current item"
1192
+ }),
1193
+ subject: S4.optional(S4.String.annotations({
1194
+ description: "The id of the item to set as current."
1195
+ })),
1196
+ options: S4.optional(S4.Record({
1197
+ key: S4.String,
1198
+ value: S4.Any
1199
+ }).annotations({
1200
+ description: "Additional options for the scroll into view."
1201
+ }))
1202
+ }),
1203
+ output: S4.Void
1204
+ }) {
1205
+ }
1206
+ LayoutAction2.ScrollIntoView = ScrollIntoView;
1207
+ class Expose extends S4.TaggedClass()(LayoutAction2.UPDATE_LAYOUT, {
1208
+ input: S4.Struct({
1209
+ part: S4.Literal("navigation").annotations({
1210
+ description: "Exposing an item in the navigation area."
1211
+ }),
1212
+ subject: S4.String.annotations({
1213
+ description: "The id of the item to expose."
1214
+ })
1215
+ }),
1216
+ output: S4.Void
1217
+ }) {
1218
+ }
1219
+ LayoutAction2.Expose = Expose;
1220
+ })(LayoutAction || (LayoutAction = {}));
1221
+
1222
+ // packages/sdk/app-framework/src/common/surface.ts
1223
+ var createSurface = (definition) => definition;
1224
+
1225
+ // packages/sdk/app-framework/src/common/translations.ts
1226
+ import { Schema as S5 } from "@effect/schema";
1227
+ var ResourceKey = S5.Union(S5.String, S5.Record({
1228
+ key: S5.String,
1229
+ value: S5.Any
1230
+ }));
1231
+ var ResourceLanguage = S5.Record({
1232
+ key: S5.String,
1233
+ value: ResourceKey
1234
+ });
1235
+ var Resource = S5.Record({
1236
+ key: S5.String,
1237
+ value: ResourceLanguage
1238
+ });
828
1239
 
829
1240
  // packages/sdk/app-framework/src/plugin-intent/intent-dispatcher.ts
1241
+ var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/sdk/app-framework/src/plugin-intent/intent-dispatcher.ts";
830
1242
  var EXECUTION_LIMIT = 100;
831
1243
  var HISTORY_LIMIT = 100;
832
- var createResolver = (schema, effect3, params = {}) => ({
833
- action: schema._tag,
834
- effect: effect3,
835
- ...params
836
- });
1244
+ var createResolver = (resolver) => resolver;
837
1245
  var isUndoable = (historyEntry) => historyEntry.length > 0 && historyEntry.every(({ undoable }) => !!undoable);
838
1246
  var createDispatcher = (getResolvers, { executionLimit = EXECUTION_LIMIT, historyLimit = HISTORY_LIMIT } = {}) => {
839
1247
  const historyRef = Effect2.runSync(Ref.make([]));
840
- const handleIntent = (intent) => {
841
- return Effect2.gen(function* () {
842
- const candidates = getResolvers(intent.module).filter((r) => r.action === intent.action).filter((r) => !r.filter || r.filter(intent.data)).toSorted(byDisposition);
843
- if (candidates.length === 0) {
844
- return {
845
- _intent: intent,
846
- error: new NoResolversError(intent.action)
847
- };
848
- }
849
- const effect3 = candidates[0].effect(intent.data, intent.undo ?? false);
850
- const result = Effect2.isEffect(effect3) ? yield* effect3 : yield* Effect2.promise(async () => effect3);
851
- return {
852
- _intent: intent,
853
- ...result
854
- };
855
- });
856
- };
1248
+ const handleIntent = (intent) => Effect2.gen(function* () {
1249
+ const candidates = getResolvers(intent.module).filter((r) => r.intent._tag === intent.id).filter((r) => !r.filter || r.filter(intent.data)).toSorted(byPosition);
1250
+ if (candidates.length === 0) {
1251
+ yield* Effect2.fail(new NoResolversError(intent.id));
1252
+ }
1253
+ const effect2 = candidates[0].resolve(intent.data, intent.undo ?? false);
1254
+ const result = Effect2.isEffect(effect2) ? yield* effect2 : yield* Effect2.promise(async () => effect2);
1255
+ return {
1256
+ _intent: intent,
1257
+ ...result
1258
+ };
1259
+ });
857
1260
  const dispatch = (intentChain, depth = 0) => {
858
1261
  return Effect2.gen(function* () {
859
1262
  if (depth > executionLimit) {
@@ -895,7 +1298,7 @@ var createDispatcher = (getResolvers, { executionLimit = EXECUTION_LIMIT, histor
895
1298
  return next;
896
1299
  });
897
1300
  if (result.undoable && isUndoable(results)) {
898
- yield* pipe(dispatch(createIntent(IntentAction.ShowUndo, {
1301
+ yield* pipe2(dispatch(createIntent(IntentAction.ShowUndo, {
899
1302
  message: result.undoable.message
900
1303
  })), Effect2.catchSome((err) => err instanceof NoResolversError ? Option.some(Effect2.succeed(void 0)) : Option.none()));
901
1304
  }
@@ -905,9 +1308,17 @@ var createDispatcher = (getResolvers, { executionLimit = EXECUTION_LIMIT, histor
905
1308
  const dispatchPromise = (intentChain) => {
906
1309
  return Effect2.runPromise(dispatch(intentChain)).then((data) => ({
907
1310
  data
908
- })).catch((error) => ({
909
- error
910
- }));
1311
+ })).catch((error) => {
1312
+ log3.catch(error, void 0, {
1313
+ F: __dxlog_file3,
1314
+ L: 241,
1315
+ S: void 0,
1316
+ C: (f, a) => f(...a)
1317
+ });
1318
+ return {
1319
+ error
1320
+ };
1321
+ });
911
1322
  };
912
1323
  const undo = () => {
913
1324
  return Effect2.gen(function* () {
@@ -951,578 +1362,32 @@ var createDispatcher = (getResolvers, { executionLimit = EXECUTION_LIMIT, histor
951
1362
  undoPromise
952
1363
  };
953
1364
  };
954
-
955
- // packages/sdk/app-framework/src/react/ErrorBoundary.tsx
956
- import React, { Component } from "react";
957
- var ErrorBoundary = class extends Component {
958
- constructor(props) {
959
- super(props);
960
- this.state = {
961
- error: void 0
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
1365
+ var defaultEffect = () => Effect2.fail(new Error("Intent runtime not ready"));
1366
+ var defaultPromise = () => Effect2.runPromise(defaultEffect());
1367
+ var intent_dispatcher_default = (context) => {
1368
+ const state = create3({
1369
+ dispatch: defaultEffect,
1370
+ dispatchPromise: defaultPromise,
1371
+ undo: defaultEffect,
1372
+ undoPromise: defaultPromise
1360
1373
  });
1361
- return candidates.length > 0;
1362
- };
1363
- var Surface = /* @__PURE__ */ memo(/* @__PURE__ */ forwardRef(({ id: _id, role, data: _data, limit, fallback, placeholder, ...rest }, forwardedRef) => {
1364
- const surfaces = useSurfaces();
1365
- const data = useDefaultValue(_data, () => ({}));
1366
- const candidates = useMemo2(() => {
1367
- const definitions = findCandidates(surfaces, {
1368
- role,
1369
- data
1374
+ const { dispatch, dispatchPromise, undo, undoPromise } = createDispatcher((module) => context.requestCapabilities(Capabilities.IntentResolver, (c, moduleId) => {
1375
+ return module ? moduleId === module : true;
1376
+ }).flat());
1377
+ const manager = context.requestCapability(Capabilities.PluginManager);
1378
+ state.dispatch = (intentChain, depth) => {
1379
+ return Effect2.gen(function* () {
1380
+ yield* manager._activate(Events.SetupIntentResolver);
1381
+ return yield* dispatch(intentChain, depth);
1370
1382
  });
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
1383
  };
1429
- const allDependencies = nodes.map((node) => node.id).flatMap((id) => getDependencies(id)).filter((id, index, self) => self.indexOf(id) === index);
1430
- return allDependencies.map((id) => nodes.find((node) => node.id === id)).filter((node) => node !== void 0);
1431
- };
1432
-
1433
- // packages/sdk/app-framework/src/App.tsx
1434
- var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/sdk/app-framework/src/App.tsx";
1435
- var ENABLED_KEY = "dxos.org/app-framework/enabled";
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;
1384
+ state.dispatchPromise = async (intentChain) => {
1385
+ await manager.activate(Events.SetupIntentResolver);
1386
+ return await dispatchPromise(intentChain);
1387
+ };
1388
+ state.undo = undo;
1389
+ state.undoPromise = undoPromise;
1390
+ return contributes(Capabilities.IntentDispatcher, state);
1526
1391
  };
1527
1392
 
1528
1393
  export {
@@ -1554,42 +1419,14 @@ export {
1554
1419
  IntentAction,
1555
1420
  createResolver,
1556
1421
  createDispatcher,
1557
- ErrorBoundary,
1558
- usePluginManager,
1559
- PluginManagerProvider,
1560
- useCapabilities,
1561
- useCapability,
1562
- isSurfaceAvailable,
1563
- Surface,
1564
- useIntentDispatcher,
1565
- useIntentResolver,
1566
- IntentProvider,
1422
+ intent_dispatcher_default,
1567
1423
  IntentPlugin,
1568
- Toast,
1569
- isLayoutMode,
1570
- Layout,
1571
1424
  LAYOUT_PLUGIN,
1572
1425
  LAYOUT_ACTION,
1573
1426
  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
1427
  createSurface,
1590
1428
  ResourceKey,
1591
1429
  ResourceLanguage,
1592
- Resource,
1593
- createApp
1430
+ Resource
1594
1431
  };
1595
- //# sourceMappingURL=chunk-GNLU3GAU.mjs.map
1432
+ //# sourceMappingURL=chunk-BCMEJONP.mjs.map