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

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 (181) hide show
  1. package/dist/lib/browser/app-graph-builder-F7VZ6LRN.mjs +137 -0
  2. package/dist/lib/browser/app-graph-builder-F7VZ6LRN.mjs.map +7 -0
  3. package/dist/lib/browser/{chunk-GNLU3GAU.mjs → chunk-ATRNTMSS.mjs} +623 -819
  4. package/dist/lib/browser/chunk-ATRNTMSS.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-WS6SU6HI.mjs +285 -0
  8. package/dist/lib/browser/chunk-WS6SU6HI.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-E6J7E5Y5.mjs +11 -0
  12. package/dist/lib/browser/intent-dispatcher-E6J7E5Y5.mjs.map +7 -0
  13. package/dist/lib/browser/intent-resolver-XLE4L3LS.mjs +38 -0
  14. package/dist/lib/browser/intent-resolver-XLE4L3LS.mjs.map +7 -0
  15. package/dist/lib/browser/meta.json +1 -1
  16. package/dist/lib/browser/store-QU2IKFAI.mjs +19 -0
  17. package/dist/lib/browser/store-QU2IKFAI.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-JGBADFF7.cjs +146 -0
  23. package/dist/lib/node/app-graph-builder-JGBADFF7.cjs.map +7 -0
  24. package/dist/lib/node/chunk-QLVQ6PND.cjs +58 -0
  25. package/dist/lib/node/chunk-QLVQ6PND.cjs.map +7 -0
  26. package/dist/lib/node/chunk-WKC6YMEQ.cjs +1433 -0
  27. package/dist/lib/node/chunk-WKC6YMEQ.cjs.map +7 -0
  28. package/dist/lib/node/chunk-WRWRZKZU.cjs +308 -0
  29. package/dist/lib/node/chunk-WRWRZKZU.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-CFBKDZQR.cjs +32 -0
  33. package/dist/lib/node/intent-dispatcher-CFBKDZQR.cjs.map +7 -0
  34. package/dist/lib/node/intent-resolver-3TKCXP4S.cjs +45 -0
  35. package/dist/lib/node/intent-resolver-3TKCXP4S.cjs.map +7 -0
  36. package/dist/lib/node/meta.json +1 -1
  37. package/dist/lib/node/store-4QMUUU2A.cjs +34 -0
  38. package/dist/lib/node/store-4QMUUU2A.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-2QEX57NX.mjs +138 -0
  44. package/dist/lib/node-esm/app-graph-builder-2QEX57NX.mjs.map +7 -0
  45. package/dist/lib/node-esm/{chunk-KPMTPXQI.mjs → chunk-44J2VZBB.mjs} +623 -819
  46. package/dist/lib/node-esm/chunk-44J2VZBB.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-HTLXL32I.mjs +286 -0
  50. package/dist/lib/node-esm/chunk-HTLXL32I.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-LDQGDZ62.mjs +12 -0
  54. package/dist/lib/node-esm/intent-dispatcher-LDQGDZ62.mjs.map +7 -0
  55. package/dist/lib/node-esm/intent-resolver-7VJWN67U.mjs +39 -0
  56. package/dist/lib/node-esm/intent-resolver-7VJWN67U.mjs.map +7 -0
  57. package/dist/lib/node-esm/meta.json +1 -1
  58. package/dist/lib/node-esm/store-VWDAYUQY.mjs +20 -0
  59. package/dist/lib/node-esm/store-VWDAYUQY.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/package.json +26 -20
  131. package/project.json +3 -3
  132. package/src/App.tsx +15 -14
  133. package/src/common/capabilities.ts +20 -11
  134. package/src/common/events.ts +10 -1
  135. package/src/common/file.ts +1 -1
  136. package/src/common/graph.ts +2 -2
  137. package/src/common/index.ts +0 -1
  138. package/src/common/layout.ts +194 -126
  139. package/src/common/surface.ts +2 -2
  140. package/src/common/translations.ts +7 -8
  141. package/src/core/capabilities.ts +16 -7
  142. package/src/core/manager.test.ts +22 -73
  143. package/src/core/manager.ts +105 -91
  144. package/src/core/plugin.ts +6 -3
  145. package/src/playground/debug/plugin.ts +1 -1
  146. package/src/playground/generator/Toolbar.tsx +11 -11
  147. package/src/playground/generator/generator.ts +25 -0
  148. package/src/playground/generator/plugin.ts +6 -1
  149. package/src/playground/layout/plugin.ts +1 -1
  150. package/src/playground/logger/Toolbar.tsx +2 -1
  151. package/src/playground/logger/plugin.ts +6 -3
  152. package/src/playground/logger/schema.ts +1 -1
  153. package/src/plugin-intent/IntentPlugin.tsx +3 -43
  154. package/src/plugin-intent/actions.ts +1 -1
  155. package/src/plugin-intent/index.ts +0 -1
  156. package/src/plugin-intent/intent-dispatcher.test.ts +48 -29
  157. package/src/plugin-intent/intent-dispatcher.ts +76 -41
  158. package/src/plugin-intent/intent.ts +5 -5
  159. package/src/plugin-settings/SettingsPlugin.ts +19 -13
  160. package/src/plugin-settings/actions.ts +11 -1
  161. package/src/plugin-settings/app-graph-builder.ts +122 -0
  162. package/src/plugin-settings/intent-resolver.ts +28 -0
  163. package/src/plugin-settings/store.ts +20 -0
  164. package/src/plugin-settings/translations.ts +17 -0
  165. package/src/{plugin-intent → react}/IntentContext.tsx +2 -2
  166. package/src/react/Surface.stories.tsx +96 -0
  167. package/src/react/Surface.tsx +11 -8
  168. package/src/react/common.ts +12 -0
  169. package/src/react/index.ts +2 -0
  170. package/src/react/useIntentResolver.ts +22 -0
  171. package/src/testing/withPluginManager.tsx +11 -3
  172. package/src/worker.ts +11 -0
  173. package/tsconfig.json +3 -3
  174. package/dist/lib/browser/chunk-GNLU3GAU.mjs.map +0 -7
  175. package/dist/lib/node/chunk-FBA4BB3J.cjs +0 -1639
  176. package/dist/lib/node/chunk-FBA4BB3J.cjs.map +0 -7
  177. package/dist/lib/node-esm/chunk-KPMTPXQI.mjs.map +0 -7
  178. package/dist/types/src/common/navigation.d.ts +0 -241
  179. package/dist/types/src/common/navigation.d.ts.map +0 -1
  180. package/dist/types/src/plugin-intent/IntentContext.d.ts.map +0 -1
  181. package/src/common/navigation.ts +0 -199
@@ -0,0 +1,1433 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var chunk_WKC6YMEQ_exports = {};
30
+ __export(chunk_WKC6YMEQ_exports, {
31
+ Capabilities: () => Capabilities,
32
+ Events: () => Events,
33
+ FileInfoSchema: () => FileInfoSchema,
34
+ INTENT_ACTION: () => INTENT_ACTION,
35
+ INTENT_PLUGIN: () => INTENT_PLUGIN,
36
+ IntentAction: () => IntentAction,
37
+ IntentPlugin: () => IntentPlugin,
38
+ LAYOUT_ACTION: () => LAYOUT_ACTION,
39
+ LAYOUT_PLUGIN: () => LAYOUT_PLUGIN,
40
+ Label: () => Label,
41
+ LayoutAction: () => LayoutAction,
42
+ Plugin: () => Plugin,
43
+ PluginManager: () => PluginManager,
44
+ PluginModule: () => PluginModule,
45
+ PluginsContext: () => PluginsContext,
46
+ Resource: () => Resource,
47
+ ResourceKey: () => ResourceKey,
48
+ ResourceLanguage: () => ResourceLanguage,
49
+ allOf: () => allOf,
50
+ chain: () => chain,
51
+ contributes: () => contributes,
52
+ createDispatcher: () => createDispatcher,
53
+ createIntent: () => createIntent,
54
+ createResolver: () => createResolver,
55
+ createSurface: () => createSurface,
56
+ defaultFileTypes: () => defaultFileTypes,
57
+ defineCapability: () => defineCapability,
58
+ defineEvent: () => defineEvent,
59
+ defineModule: () => defineModule,
60
+ definePlugin: () => definePlugin,
61
+ eventKey: () => eventKey,
62
+ getEvents: () => getEvents,
63
+ intent_dispatcher_default: () => intent_dispatcher_default,
64
+ isAllOf: () => isAllOf,
65
+ isOneOf: () => isOneOf,
66
+ lazy: () => lazy,
67
+ oneOf: () => oneOf
68
+ });
69
+ module.exports = __toCommonJS(chunk_WKC6YMEQ_exports);
70
+ var import_effect = require("effect");
71
+ var import_live_object = require("@dxos/live-object");
72
+ var import_util = require("@dxos/util");
73
+ var import_schema = require("@effect/schema");
74
+ var import_schema2 = require("@effect/schema");
75
+ var import_signals_core = require("@preact/signals-core");
76
+ var import_async = require("@dxos/async");
77
+ var import_invariant = require("@dxos/invariant");
78
+ var import_live_object2 = require("@dxos/live-object");
79
+ var import_log = require("@dxos/log");
80
+ var import_signals_core2 = require("@preact/signals-core");
81
+ var import_effect2 = require("effect");
82
+ var import_async2 = require("@dxos/async");
83
+ var import_live_object3 = require("@dxos/live-object");
84
+ var import_log2 = require("@dxos/log");
85
+ var import_schema3 = require("@effect/schema");
86
+ var import_schema4 = require("@effect/schema");
87
+ var import_schema5 = require("@effect/schema");
88
+ var createIntent = (schema, data = {}, params = {}) => {
89
+ const _ = import_schema2.Schema.validateSync(schema.fields.input)(data);
90
+ const intent = {
91
+ ...params,
92
+ _schema: schema,
93
+ id: schema._tag,
94
+ data
95
+ };
96
+ return {
97
+ first: intent,
98
+ last: intent,
99
+ all: [
100
+ intent
101
+ ]
102
+ };
103
+ };
104
+ var chain = (schema, data = {}, params = {}) => (intent) => {
105
+ const intents = "all" in intent ? intent.all : [
106
+ intent
107
+ ];
108
+ const first = intents[0];
109
+ const last = {
110
+ ...params,
111
+ _schema: schema,
112
+ id: schema._tag,
113
+ data
114
+ };
115
+ return {
116
+ first,
117
+ last,
118
+ all: [
119
+ ...intents,
120
+ last
121
+ ]
122
+ };
123
+ };
124
+ var Label = import_schema2.Schema.Union(import_schema2.Schema.String, import_schema2.Schema.mutable(import_schema2.Schema.Tuple(import_schema2.Schema.String, import_schema2.Schema.mutable(import_schema2.Schema.Struct({
125
+ ns: import_schema2.Schema.String,
126
+ count: import_schema2.Schema.optional(import_schema2.Schema.Number)
127
+ })))));
128
+ var INTENT_PLUGIN = "dxos.org/plugin/intent";
129
+ var INTENT_ACTION = `${INTENT_PLUGIN}/action`;
130
+ var IntentAction;
131
+ (function(IntentAction2) {
132
+ class ShowUndo extends import_schema.Schema.TaggedClass()(`${INTENT_ACTION}/show-undo`, {
133
+ input: import_schema.Schema.Struct({
134
+ message: Label
135
+ }),
136
+ output: import_schema.Schema.Void
137
+ }) {
138
+ }
139
+ IntentAction2.ShowUndo = ShowUndo;
140
+ })(IntentAction || (IntentAction = {}));
141
+ var BaseError = class extends Error {
142
+ constructor(code, message, context) {
143
+ super(message ?? code);
144
+ this.code = code;
145
+ this.context = context;
146
+ this.name = code;
147
+ Object.setPrototypeOf(this, new.target.prototype);
148
+ }
149
+ };
150
+ var NoResolversError = class extends BaseError {
151
+ constructor(action) {
152
+ super("NO_RESOLVERS", "No resolvers were found for the action", {
153
+ action
154
+ });
155
+ }
156
+ };
157
+ var CycleDetectedError = class extends BaseError {
158
+ constructor(context) {
159
+ super("CYCLE_DETECTED", "Intent execution limit exceeded. This is likely due to an infinite loop within intent resolvers.", context);
160
+ }
161
+ };
162
+ var __dxlog_file = "/home/runner/work/dxos/dxos/packages/sdk/app-framework/src/core/capabilities.ts";
163
+ var InterfaceDefTypeId = Symbol.for("InterfaceDefTypeId");
164
+ var defineCapability = (identifier) => {
165
+ return {
166
+ identifier
167
+ };
168
+ };
169
+ var CapabilityImpl = class {
170
+ constructor(moduleId, implementation) {
171
+ this.moduleId = moduleId;
172
+ this.implementation = implementation;
173
+ }
174
+ };
175
+ var contributes = (interfaceDef, implementation, deactivate) => {
176
+ return {
177
+ interface: interfaceDef,
178
+ implementation,
179
+ deactivate
180
+ };
181
+ };
182
+ var lazy = (c) => async (props) => {
183
+ const { default: getCapability } = await c();
184
+ return async () => getCapability(props);
185
+ };
186
+ var PluginsContext = class {
187
+ constructor({ activate, reset }) {
188
+ this._definedCapabilities = /* @__PURE__ */ new Map();
189
+ this.activate = activate;
190
+ this.reset = reset;
191
+ }
192
+ /**
193
+ * @internal
194
+ */
195
+ contributeCapability({ module: moduleId, interface: interfaceDef, implementation }) {
196
+ let current = this._definedCapabilities.get(interfaceDef.identifier);
197
+ if (!current) {
198
+ const object = (0, import_live_object2.create)({
199
+ value: []
200
+ });
201
+ current = (0, import_signals_core.untracked)(() => object.value);
202
+ this._definedCapabilities.set(interfaceDef.identifier, current);
203
+ }
204
+ current.push(new CapabilityImpl(moduleId, implementation));
205
+ (0, import_log.log)("capability contributed", {
206
+ id: interfaceDef.identifier,
207
+ moduleId,
208
+ count: (0, import_signals_core.untracked)(() => current.length)
209
+ }, {
210
+ F: __dxlog_file,
211
+ L: 142,
212
+ S: this,
213
+ C: (f, a) => f(...a)
214
+ });
215
+ }
216
+ /**
217
+ * @internal
218
+ */
219
+ removeCapability(interfaceDef, implementation) {
220
+ const current = this._definedCapabilities.get(interfaceDef.identifier);
221
+ if (!current) {
222
+ return;
223
+ }
224
+ const index = current.findIndex((i) => i.implementation === implementation);
225
+ if (index !== -1) {
226
+ current.splice(index, 1);
227
+ (0, import_log.log)("capability removed", {
228
+ id: interfaceDef.identifier,
229
+ count: (0, import_signals_core.untracked)(() => current.length)
230
+ }, {
231
+ F: __dxlog_file,
232
+ L: 161,
233
+ S: this,
234
+ C: (f, a) => f(...a)
235
+ });
236
+ } else {
237
+ import_log.log.warn("capability not removed", {
238
+ id: interfaceDef.identifier
239
+ }, {
240
+ F: __dxlog_file,
241
+ L: 163,
242
+ S: this,
243
+ C: (f, a) => f(...a)
244
+ });
245
+ }
246
+ }
247
+ /**
248
+ * Requests capabilities from the plugin context.
249
+ * @returns An array of capabilities.
250
+ * @reactive
251
+ */
252
+ requestCapabilities(interfaceDef, filter) {
253
+ let current = this._definedCapabilities.get(interfaceDef.identifier);
254
+ if (!current) {
255
+ const object = (0, import_live_object2.create)({
256
+ value: []
257
+ });
258
+ current = (0, import_signals_core.untracked)(() => object.value);
259
+ this._definedCapabilities.set(interfaceDef.identifier, current);
260
+ }
261
+ const capabilities = filter ? current.filter((c) => filter(c.implementation, c.moduleId)) : current;
262
+ return capabilities.map((c) => c.implementation);
263
+ }
264
+ /**
265
+ * Requests a single capability from the plugin context.
266
+ * @returns The capability.
267
+ * @throws If no capability is found.
268
+ * @reactive
269
+ */
270
+ requestCapability(interfaceDef, filter) {
271
+ const capability = this.requestCapabilities(interfaceDef, filter)[0];
272
+ (0, import_invariant.invariant)(capability, `No capability found for ${interfaceDef.identifier}`, {
273
+ F: __dxlog_file,
274
+ L: 199,
275
+ S: this,
276
+ A: [
277
+ "capability",
278
+ "`No capability found for ${interfaceDef.identifier}`"
279
+ ]
280
+ });
281
+ return capability;
282
+ }
283
+ /**
284
+ * Waits for a capability to be contributed.
285
+ * @returns The capability.
286
+ */
287
+ async waitForCapability(interfaceDef, filter) {
288
+ const trigger = new import_async.Trigger();
289
+ const unsubscribe = (0, import_signals_core.effect)(() => {
290
+ const capabilities = this.requestCapabilities(interfaceDef, filter);
291
+ if (capabilities[0]) {
292
+ trigger.wake(capabilities[0]);
293
+ }
294
+ });
295
+ const capability = await trigger.wait();
296
+ unsubscribe();
297
+ return capability;
298
+ }
299
+ };
300
+ var defineEvent = (id, specifier) => {
301
+ return {
302
+ id,
303
+ specifier
304
+ };
305
+ };
306
+ var eventKey = (event) => event.specifier ? `${event.id}:${event.specifier}` : event.id;
307
+ var oneOf = (...events) => ({
308
+ type: "one-of",
309
+ events
310
+ });
311
+ var allOf = (...events) => ({
312
+ type: "all-of",
313
+ events
314
+ });
315
+ var isOneOf = (events) => "type" in events && events.type === "one-of";
316
+ var isAllOf = (events) => "type" in events && events.type === "all-of";
317
+ var getEvents = (events) => "type" in events ? events.events : [
318
+ events
319
+ ];
320
+ var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/sdk/app-framework/src/core/manager.ts";
321
+ var isPromise = (value) => {
322
+ return value !== null && typeof value === "object" && "then" in value;
323
+ };
324
+ var PluginManager = class {
325
+ constructor({ pluginLoader, plugins = [], core = plugins.map(({ meta }) => meta.id), enabled = [] }) {
326
+ this.activation = new import_async2.Event();
327
+ this.context = new PluginsContext({
328
+ activate: (event) => this.activate(event),
329
+ reset: (id) => this.reset(id)
330
+ });
331
+ this._capabilities = /* @__PURE__ */ new Map();
332
+ this._pluginLoader = pluginLoader;
333
+ this._state = (0, import_live_object3.create)({
334
+ plugins,
335
+ core,
336
+ enabled,
337
+ modules: [],
338
+ active: [],
339
+ pendingReset: [],
340
+ eventsFired: []
341
+ });
342
+ plugins.forEach((plugin) => this._addPlugin(plugin));
343
+ core.forEach((id) => this.enable(id));
344
+ enabled.forEach((id) => this.enable(id));
345
+ }
346
+ /**
347
+ * Plugins that are currently registered.
348
+ *
349
+ * @reactive
350
+ */
351
+ get plugins() {
352
+ return this._state.plugins;
353
+ }
354
+ /**
355
+ * Ids of plugins that are core and cannot be removed.
356
+ *
357
+ * @reactive
358
+ */
359
+ get core() {
360
+ return this._state.core;
361
+ }
362
+ /**
363
+ * Ids of plugins that are currently enabled.
364
+ *
365
+ * @reactive
366
+ */
367
+ get enabled() {
368
+ return this._state.enabled;
369
+ }
370
+ /**
371
+ * Modules of plugins which are currently enabled.
372
+ *
373
+ * @reactive
374
+ */
375
+ get modules() {
376
+ return this._state.modules;
377
+ }
378
+ /**
379
+ * Ids of modules which are currently active.
380
+ *
381
+ * @reactive
382
+ */
383
+ get active() {
384
+ return this._state.active;
385
+ }
386
+ /**
387
+ * Ids of events which have been fired.
388
+ *
389
+ * @reactive
390
+ */
391
+ get eventsFired() {
392
+ return this._state.eventsFired;
393
+ }
394
+ /**
395
+ * Ids of modules which are pending reset.
396
+ *
397
+ * @reactive
398
+ */
399
+ get pendingReset() {
400
+ return this._state.pendingReset;
401
+ }
402
+ /**
403
+ * Adds a plugin to the manager via the plugin loader.
404
+ * @param id The id of the plugin.
405
+ */
406
+ async add(id) {
407
+ return (0, import_signals_core2.untracked)(async () => {
408
+ (0, import_log2.log)("add plugin", {
409
+ id
410
+ }, {
411
+ F: __dxlog_file2,
412
+ L: 146,
413
+ S: this,
414
+ C: (f, a) => f(...a)
415
+ });
416
+ const plugin = await this._pluginLoader(id);
417
+ this._addPlugin(plugin);
418
+ return this.enable(id);
419
+ });
420
+ }
421
+ /**
422
+ * Enables a plugin.
423
+ * @param id The id of the plugin.
424
+ */
425
+ enable(id) {
426
+ return (0, import_signals_core2.untracked)(async () => {
427
+ (0, import_log2.log)("enable plugin", {
428
+ id
429
+ }, {
430
+ F: __dxlog_file2,
431
+ L: 159,
432
+ S: this,
433
+ C: (f, a) => f(...a)
434
+ });
435
+ const plugin = this._getPlugin(id);
436
+ if (!plugin) {
437
+ return false;
438
+ }
439
+ if (!this._state.enabled.includes(id)) {
440
+ this._state.enabled.push(id);
441
+ }
442
+ plugin.modules.forEach((module2) => {
443
+ this._addModule(module2);
444
+ this._setPendingResetByModule(module2);
445
+ });
446
+ (0, import_log2.log)("pending reset", {
447
+ events: [
448
+ ...this.pendingReset
449
+ ]
450
+ }, {
451
+ F: __dxlog_file2,
452
+ L: 174,
453
+ S: this,
454
+ C: (f, a) => f(...a)
455
+ });
456
+ await import_effect2.Effect.runPromise(import_effect2.Effect.all(this.pendingReset.map((event) => this._activate(event)), {
457
+ concurrency: "unbounded"
458
+ }));
459
+ return true;
460
+ });
461
+ }
462
+ /**
463
+ * Removes a plugin from the manager.
464
+ * @param id The id of the plugin.
465
+ */
466
+ remove(id) {
467
+ return (0, import_signals_core2.untracked)(() => {
468
+ (0, import_log2.log)("remove plugin", {
469
+ id
470
+ }, {
471
+ F: __dxlog_file2,
472
+ L: 192,
473
+ S: this,
474
+ C: (f, a) => f(...a)
475
+ });
476
+ const result = this.disable(id);
477
+ if (!result) {
478
+ return false;
479
+ }
480
+ this._removePlugin(id);
481
+ return true;
482
+ });
483
+ }
484
+ /**
485
+ * Disables a plugin.
486
+ * @param id The id of the plugin.
487
+ */
488
+ disable(id) {
489
+ return (0, import_signals_core2.untracked)(async () => {
490
+ (0, import_log2.log)("disable plugin", {
491
+ id
492
+ }, {
493
+ F: __dxlog_file2,
494
+ L: 209,
495
+ S: this,
496
+ C: (f, a) => f(...a)
497
+ });
498
+ if (this._state.core.includes(id)) {
499
+ return false;
500
+ }
501
+ const plugin = this._getPlugin(id);
502
+ if (!plugin) {
503
+ return false;
504
+ }
505
+ const enabledIndex = this._state.enabled.findIndex((enabled) => enabled === id);
506
+ if (enabledIndex !== -1) {
507
+ this._state.enabled.splice(enabledIndex, 1);
508
+ await import_effect2.Effect.runPromise(this._deactivate(id));
509
+ plugin.modules.forEach((module2) => {
510
+ this._removeModule(module2.id);
511
+ });
512
+ }
513
+ return true;
514
+ });
515
+ }
516
+ /**
517
+ * Activates plugins based on the activation event.
518
+ * @param event The activation event.
519
+ * @returns Whether the activation was successful.
520
+ */
521
+ activate(event) {
522
+ return (0, import_signals_core2.untracked)(() => import_effect2.Effect.runPromise(this._activate(event)));
523
+ }
524
+ /**
525
+ * Deactivates all of the modules for a plugin.
526
+ * @param id The id of the plugin.
527
+ * @returns Whether the deactivation was successful.
528
+ */
529
+ deactivate(id) {
530
+ return (0, import_signals_core2.untracked)(() => import_effect2.Effect.runPromise(this._deactivate(id)));
531
+ }
532
+ /**
533
+ * Re-activates the modules that were activated by the event.
534
+ * @param event The activation event.
535
+ * @returns Whether the reset was successful.
536
+ */
537
+ reset(event) {
538
+ return (0, import_signals_core2.untracked)(() => import_effect2.Effect.runPromise(this._reset(event)));
539
+ }
540
+ _addPlugin(plugin) {
541
+ (0, import_signals_core2.untracked)(() => {
542
+ (0, import_log2.log)("add plugin", {
543
+ id: plugin.meta.id
544
+ }, {
545
+ F: __dxlog_file2,
546
+ L: 262,
547
+ S: this,
548
+ C: (f, a) => f(...a)
549
+ });
550
+ if (!this._state.plugins.includes(plugin)) {
551
+ this._state.plugins.push(plugin);
552
+ }
553
+ });
554
+ }
555
+ _removePlugin(id) {
556
+ (0, import_signals_core2.untracked)(() => {
557
+ (0, import_log2.log)("remove plugin", {
558
+ id
559
+ }, {
560
+ F: __dxlog_file2,
561
+ L: 271,
562
+ S: this,
563
+ C: (f, a) => f(...a)
564
+ });
565
+ const pluginIndex = this._state.plugins.findIndex((plugin) => plugin.meta.id === id);
566
+ if (pluginIndex !== -1) {
567
+ this._state.plugins.splice(pluginIndex, 1);
568
+ }
569
+ });
570
+ }
571
+ _addModule(module2) {
572
+ (0, import_signals_core2.untracked)(() => {
573
+ (0, import_log2.log)("add module", {
574
+ id: module2.id
575
+ }, {
576
+ F: __dxlog_file2,
577
+ L: 281,
578
+ S: this,
579
+ C: (f, a) => f(...a)
580
+ });
581
+ if (!this._state.modules.includes(module2)) {
582
+ this._state.modules.push(module2);
583
+ }
584
+ });
585
+ }
586
+ _removeModule(id) {
587
+ (0, import_signals_core2.untracked)(() => {
588
+ (0, import_log2.log)("remove module", {
589
+ id
590
+ }, {
591
+ F: __dxlog_file2,
592
+ L: 290,
593
+ S: this,
594
+ C: (f, a) => f(...a)
595
+ });
596
+ const moduleIndex = this._state.modules.findIndex((module2) => module2.id === id);
597
+ if (moduleIndex !== -1) {
598
+ this._state.modules.splice(moduleIndex, 1);
599
+ }
600
+ });
601
+ }
602
+ _getPlugin(id) {
603
+ return this._state.plugins.find((plugin) => plugin.meta.id === id);
604
+ }
605
+ _getActiveModules() {
606
+ return this._state.modules.filter((module2) => this._state.active.includes(module2.id));
607
+ }
608
+ _getInactiveModules() {
609
+ return this._state.modules.filter((module2) => !this._state.active.includes(module2.id));
610
+ }
611
+ _getActiveModulesByEvent(key) {
612
+ return this._getActiveModules().filter((module2) => getEvents(module2.activatesOn).map(eventKey).includes(key));
613
+ }
614
+ _getInactiveModulesByEvent(key) {
615
+ return this._getInactiveModules().filter((module2) => getEvents(module2.activatesOn).map(eventKey).includes(key));
616
+ }
617
+ _setPendingResetByModule(module2) {
618
+ return (0, import_signals_core2.untracked)(() => {
619
+ const activationEvents = getEvents(module2.activatesOn).map(eventKey).filter((key) => this._state.eventsFired.includes(key));
620
+ const pendingReset = Array.from(new Set(activationEvents)).filter((event) => !this._state.pendingReset.includes(event));
621
+ if (pendingReset.length > 0) {
622
+ (0, import_log2.log)("pending reset", {
623
+ events: pendingReset
624
+ }, {
625
+ F: __dxlog_file2,
626
+ L: 328,
627
+ S: this,
628
+ C: (f, a) => f(...a)
629
+ });
630
+ this._state.pendingReset.push(...pendingReset);
631
+ }
632
+ });
633
+ }
634
+ /**
635
+ * @internal
636
+ */
637
+ // TODO(wittjosiah): Improve error typing.
638
+ _activate(event) {
639
+ return import_effect2.Effect.gen(this, function* () {
640
+ const key = typeof event === "string" ? event : eventKey(event);
641
+ (0, import_log2.log)("activating", {
642
+ key
643
+ }, {
644
+ F: __dxlog_file2,
645
+ L: 341,
646
+ S: this,
647
+ C: (f, a) => f(...a)
648
+ });
649
+ const pendingIndex = this._state.pendingReset.findIndex((event2) => event2 === key);
650
+ if (pendingIndex !== -1) {
651
+ this._state.pendingReset.splice(pendingIndex, 1);
652
+ }
653
+ const modules = this._getInactiveModulesByEvent(key).filter((module2) => {
654
+ const allOf2 = isAllOf(module2.activatesOn);
655
+ if (!allOf2) {
656
+ return true;
657
+ }
658
+ const events = module2.activatesOn.events.filter((event2) => eventKey(event2) !== key);
659
+ return events.every((event2) => this._state.eventsFired.includes(eventKey(event2)));
660
+ });
661
+ if (modules.length === 0) {
662
+ (0, import_log2.log)("no modules to activate", {
663
+ key
664
+ }, {
665
+ F: __dxlog_file2,
666
+ L: 357,
667
+ S: this,
668
+ C: (f, a) => f(...a)
669
+ });
670
+ if (!this._state.eventsFired.includes(key)) {
671
+ this._state.eventsFired.push(key);
672
+ }
673
+ return false;
674
+ }
675
+ (0, import_log2.log)("activating modules", {
676
+ key,
677
+ modules: modules.map((module2) => module2.id)
678
+ }, {
679
+ F: __dxlog_file2,
680
+ L: 364,
681
+ S: this,
682
+ C: (f, a) => f(...a)
683
+ });
684
+ this.activation.emit({
685
+ event: key,
686
+ state: "activating"
687
+ });
688
+ const getCapabilities = yield* import_effect2.Effect.all(modules.map(({ activate }) => import_effect2.Effect.tryPromise({
689
+ try: async () => activate(this.context),
690
+ catch: (error) => error
691
+ })), {
692
+ concurrency: "unbounded"
693
+ });
694
+ const result = yield* (0, import_effect2.pipe)(
695
+ modules,
696
+ import_effect2.Array.zip(getCapabilities),
697
+ import_effect2.Array.map(([module2, getCapabilities2]) => this._activateModule(module2, getCapabilities2)),
698
+ // TODO(wittjosiah): This currently can't be run in parallel.
699
+ // Running this with concurrency causes races with `allOf` activation events.
700
+ import_effect2.Effect.all,
701
+ import_effect2.Effect.either
702
+ );
703
+ if (import_effect2.Either.isLeft(result)) {
704
+ this.activation.emit({
705
+ event: key,
706
+ state: "error",
707
+ error: result.left
708
+ });
709
+ yield* import_effect2.Effect.fail(result.left);
710
+ }
711
+ if (!this._state.eventsFired.includes(key)) {
712
+ this._state.eventsFired.push(key);
713
+ }
714
+ this.activation.emit({
715
+ event: key,
716
+ state: "activated"
717
+ });
718
+ (0, import_log2.log)("activated", {
719
+ key
720
+ }, {
721
+ F: __dxlog_file2,
722
+ L: 398,
723
+ S: this,
724
+ C: (f, a) => f(...a)
725
+ });
726
+ return true;
727
+ });
728
+ }
729
+ _activateModule(module2, getCapabilities) {
730
+ return import_effect2.Effect.gen(this, function* () {
731
+ yield* import_effect2.Effect.all(module2.activatesBefore?.map((event) => this._activate(event)) ?? [], {
732
+ concurrency: "unbounded"
733
+ });
734
+ (0, import_log2.log)("activating module...", {
735
+ module: module2.id
736
+ }, {
737
+ F: __dxlog_file2,
738
+ L: 413,
739
+ S: this,
740
+ C: (f, a) => f(...a)
741
+ });
742
+ const maybeCapabilities = typeof getCapabilities === "function" ? getCapabilities() : getCapabilities;
743
+ const resolvedCapabilities = yield* import_effect2.Match.value(maybeCapabilities).pipe(
744
+ // TODO(wittjosiah): Activate with an effect?
745
+ // Match.when(Effect.isEffect, (effect) => effect),
746
+ import_effect2.Match.when(isPromise, (promise) => import_effect2.Effect.tryPromise({
747
+ try: () => promise,
748
+ catch: (error) => error
749
+ })),
750
+ import_effect2.Match.orElse((program) => import_effect2.Effect.succeed(program))
751
+ );
752
+ const capabilities = import_effect2.Match.value(resolvedCapabilities).pipe(import_effect2.Match.when(Array.isArray, (array) => array), import_effect2.Match.orElse((value) => [
753
+ value
754
+ ]));
755
+ capabilities.forEach((capability) => {
756
+ this.context.contributeCapability({
757
+ module: module2.id,
758
+ ...capability
759
+ });
760
+ });
761
+ this._state.active.push(module2.id);
762
+ this._capabilities.set(module2.id, capabilities);
763
+ (0, import_log2.log)("activated module", {
764
+ module: module2.id
765
+ }, {
766
+ F: __dxlog_file2,
767
+ L: 436,
768
+ S: this,
769
+ C: (f, a) => f(...a)
770
+ });
771
+ yield* import_effect2.Effect.all(module2.activatesAfter?.map((event) => this._activate(event)) ?? [], {
772
+ concurrency: "unbounded"
773
+ });
774
+ });
775
+ }
776
+ _deactivate(id) {
777
+ return import_effect2.Effect.gen(this, function* () {
778
+ const plugin = this._getPlugin(id);
779
+ if (!plugin) {
780
+ return false;
781
+ }
782
+ const modules = plugin.modules;
783
+ const results = yield* import_effect2.Effect.all(modules.map((module2) => this._deactivateModule(module2)), {
784
+ concurrency: "unbounded"
785
+ });
786
+ return results.every((result) => result);
787
+ });
788
+ }
789
+ _deactivateModule(module2) {
790
+ return import_effect2.Effect.gen(this, function* () {
791
+ const id = module2.id;
792
+ (0, import_log2.log)("deactivating", {
793
+ id
794
+ }, {
795
+ F: __dxlog_file2,
796
+ L: 463,
797
+ S: this,
798
+ C: (f, a) => f(...a)
799
+ });
800
+ const capabilities = this._capabilities.get(id);
801
+ if (capabilities) {
802
+ for (const capability of capabilities) {
803
+ this.context.removeCapability(capability.interface, capability.implementation);
804
+ const program = capability.deactivate?.();
805
+ yield* import_effect2.Match.value(program).pipe(import_effect2.Match.when(import_effect2.Effect.isEffect, (effect2) => effect2), import_effect2.Match.when(isPromise, (promise) => import_effect2.Effect.tryPromise({
806
+ try: () => promise,
807
+ catch: (error) => error
808
+ })), import_effect2.Match.orElse((program2) => import_effect2.Effect.succeed(program2)));
809
+ }
810
+ this._capabilities.delete(id);
811
+ }
812
+ const activeIndex = this._state.active.findIndex((event) => event === id);
813
+ if (activeIndex !== -1) {
814
+ this._state.active.splice(activeIndex, 1);
815
+ }
816
+ (0, import_log2.log)("deactivated", {
817
+ id
818
+ }, {
819
+ F: __dxlog_file2,
820
+ L: 489,
821
+ S: this,
822
+ C: (f, a) => f(...a)
823
+ });
824
+ return true;
825
+ });
826
+ }
827
+ _reset(event) {
828
+ return import_effect2.Effect.gen(this, function* () {
829
+ const key = typeof event === "string" ? event : eventKey(event);
830
+ (0, import_log2.log)("reset", {
831
+ key
832
+ }, {
833
+ F: __dxlog_file2,
834
+ L: 497,
835
+ S: this,
836
+ C: (f, a) => f(...a)
837
+ });
838
+ const modules = this._getActiveModulesByEvent(key);
839
+ const results = yield* import_effect2.Effect.all(modules.map((module2) => this._deactivateModule(module2)), {
840
+ concurrency: "unbounded"
841
+ });
842
+ if (results.every((result) => result)) {
843
+ return yield* this._activate(key);
844
+ } else {
845
+ return false;
846
+ }
847
+ });
848
+ }
849
+ };
850
+ var PluginModule = class {
851
+ constructor(options) {
852
+ this.id = options.id;
853
+ this.activatesOn = options.activatesOn;
854
+ this.activatesBefore = options.activatesBefore;
855
+ this.activatesAfter = options.activatesAfter;
856
+ this.activate = options.activate;
857
+ }
858
+ };
859
+ var defineModule = (options) => new PluginModule(options);
860
+ var Plugin = class {
861
+ constructor(meta, modules) {
862
+ this.meta = meta;
863
+ this.modules = modules;
864
+ }
865
+ };
866
+ var definePlugin = (meta, modules) => {
867
+ return new Plugin(meta, modules);
868
+ };
869
+ var Capabilities;
870
+ (function(Capabilities2) {
871
+ Capabilities2.PluginManager = defineCapability("dxos.org/app-framework/capability/plugin-manager");
872
+ Capabilities2.Null = defineCapability("dxos.org/app-framework/capability/null");
873
+ Capabilities2.ReactContext = defineCapability("dxos.org/app-framework/capability/react-context");
874
+ Capabilities2.ReactRoot = defineCapability("dxos.org/app-framework/capability/react-root");
875
+ Capabilities2.ReactSurface = defineCapability("dxos.org/app-framework/common/react-surface");
876
+ Capabilities2.IntentResolver = defineCapability("dxos.org/app-framework/capability/intent-resolver");
877
+ Capabilities2.IntentDispatcher = defineCapability("dxos.org/app-framework/capability/intent-dispatcher");
878
+ Capabilities2.Layout = defineCapability("dxos.org/app-framework/capability/layout");
879
+ Capabilities2.Translations = defineCapability("dxos.org/app-framework/capability/translations");
880
+ Capabilities2.AppGraph = defineCapability("dxos.org/app-framework/capability/app-graph");
881
+ Capabilities2.AppGraphBuilder = defineCapability("dxos.org/app-framework/capability/app-graph-builder");
882
+ Capabilities2.AppGraphSerializer = defineCapability("dxos.org/app-framework/capability/app-graph-serializer");
883
+ Capabilities2.SettingsStore = defineCapability("dxos.org/app-framework/capability/settings-store");
884
+ Capabilities2.Settings = defineCapability("dxos.org/app-framework/capability/settings");
885
+ Capabilities2.Metadata = defineCapability("dxos.org/app-framework/capability/metadata");
886
+ Capabilities2.FileUploader = defineCapability("dxos.org/app-framework/capability/file-uploader");
887
+ })(Capabilities || (Capabilities = {}));
888
+ var Events;
889
+ (function(Events2) {
890
+ Events2.Startup = defineEvent("dxos.org/app-framework/event/startup");
891
+ Events2.SetupSurfaces = defineEvent("dxos.org/app-framework/event/setup-surfaces");
892
+ Events2.SetupMetadata = defineEvent("dxos.org/app-framework/event/setup-metadata");
893
+ Events2.SetupIntents = defineEvent("dxos.org/app-framework/event/setup-intents");
894
+ Events2.SetupSettings = defineEvent("dxos.org/app-framework/event/setup-settings");
895
+ Events2.SetupAppGraph = defineEvent("dxos.org/app-framework/event/setup-graph");
896
+ Events2.SetupTranslations = defineEvent("dxos.org/app-framework/event/setup-translations");
897
+ Events2.DispatcherReady = defineEvent("dxos.org/app-framework/event/dispatcher-ready");
898
+ Events2.SettingsReady = defineEvent("dxos.org/app-framework/event/settings-ready");
899
+ Events2.AppGraphReady = defineEvent("dxos.org/app-framework/event/graph-ready");
900
+ Events2.createStateEvent = (specifier) => defineEvent("dxos.org/app-framework/event/state", specifier);
901
+ Events2.LayoutReady = Events2.createStateEvent(Capabilities.Layout.identifier);
902
+ })(Events || (Events = {}));
903
+ var defaultFileTypes = {
904
+ images: [
905
+ "png",
906
+ "jpg",
907
+ "jpeg",
908
+ "gif"
909
+ ],
910
+ media: [
911
+ "mp3",
912
+ "mp4",
913
+ "mov",
914
+ "avi"
915
+ ],
916
+ text: [
917
+ "pdf",
918
+ "txt",
919
+ "md"
920
+ ]
921
+ };
922
+ var FileInfoSchema = import_schema3.Schema.Struct({
923
+ name: import_schema3.Schema.String,
924
+ type: import_schema3.Schema.String,
925
+ url: import_schema3.Schema.optional(import_schema3.Schema.String),
926
+ cid: import_schema3.Schema.optional(import_schema3.Schema.String)
927
+ });
928
+ var IntentPlugin = () => definePlugin({
929
+ id: INTENT_PLUGIN
930
+ }, [
931
+ defineModule({
932
+ id: `${INTENT_PLUGIN}/module/dispatcher`,
933
+ // TODO(wittjosiah): This will mean that startup needs to be reset when intents are added or removed.
934
+ // This is fine for now because it's how it worked prior to capabilities api anyways.
935
+ // In the future, the intent dispatcher should be able to be reset without resetting the entire app.
936
+ activatesOn: Events.Startup,
937
+ activatesAfter: [
938
+ Events.DispatcherReady
939
+ ],
940
+ activate: lazy(() => import("./intent-dispatcher-CFBKDZQR.cjs"))
941
+ })
942
+ ]);
943
+ var LAYOUT_PLUGIN = "dxos.org/plugin/layout";
944
+ var LAYOUT_ACTION = `${LAYOUT_PLUGIN}/action`;
945
+ var LayoutAction;
946
+ (function(LayoutAction2) {
947
+ LayoutAction2.UPDATE_LAYOUT = `${LAYOUT_ACTION}/update-layout`;
948
+ class UpdateLayout extends import_schema4.Schema.TaggedClass()(LayoutAction2.UPDATE_LAYOUT, {
949
+ input: import_schema4.Schema.Struct({
950
+ part: import_schema4.Schema.String.annotations({
951
+ description: "The part of the layout to mutate."
952
+ }),
953
+ subject: import_schema4.Schema.optional(import_schema4.Schema.Any.annotations({
954
+ description: "The subject of the layout update."
955
+ })),
956
+ options: import_schema4.Schema.optional(import_schema4.Schema.Record({
957
+ key: import_schema4.Schema.String,
958
+ value: import_schema4.Schema.Any
959
+ }).annotations({
960
+ description: "Additional options for the layout action."
961
+ }))
962
+ }),
963
+ output: import_schema4.Schema.Void
964
+ }) {
965
+ }
966
+ LayoutAction2.UpdateLayout = UpdateLayout;
967
+ class SetLayoutMode extends import_schema4.Schema.TaggedClass()(LayoutAction2.UPDATE_LAYOUT, {
968
+ input: import_schema4.Schema.Struct({
969
+ part: import_schema4.Schema.Literal("mode").annotations({
970
+ description: "Setting the layout mode."
971
+ }),
972
+ subject: import_schema4.Schema.optional(import_schema4.Schema.String.annotations({
973
+ description: "Item which is the subject of the new layout mode."
974
+ })),
975
+ options: import_schema4.Schema.Union(import_schema4.Schema.Struct({
976
+ mode: import_schema4.Schema.String.annotations({
977
+ description: "The new layout mode."
978
+ })
979
+ }), import_schema4.Schema.Struct({
980
+ revert: import_schema4.Schema.Boolean.annotations({
981
+ description: "Revert to the previous layout mode."
982
+ })
983
+ }))
984
+ }),
985
+ output: import_schema4.Schema.Void
986
+ }) {
987
+ }
988
+ LayoutAction2.SetLayoutMode = SetLayoutMode;
989
+ class UpdateSidebar extends import_schema4.Schema.TaggedClass()(LayoutAction2.UPDATE_LAYOUT, {
990
+ input: import_schema4.Schema.Struct({
991
+ part: import_schema4.Schema.Literal("sidebar").annotations({
992
+ description: "Updating the sidebar."
993
+ }),
994
+ subject: import_schema4.Schema.optional(import_schema4.Schema.String.annotations({
995
+ description: "URI of the component to display in the sidebar."
996
+ })),
997
+ options: import_schema4.Schema.optional(import_schema4.Schema.Struct({
998
+ state: import_schema4.Schema.Literal("closed", "collapsed", "expanded").annotations({
999
+ description: "Whether the sidebar is closed, collapsed, or expanded."
1000
+ })
1001
+ }))
1002
+ }),
1003
+ output: import_schema4.Schema.Void
1004
+ }) {
1005
+ }
1006
+ LayoutAction2.UpdateSidebar = UpdateSidebar;
1007
+ class UpdateComplementary extends import_schema4.Schema.TaggedClass()(LayoutAction2.UPDATE_LAYOUT, {
1008
+ input: import_schema4.Schema.Struct({
1009
+ part: import_schema4.Schema.Literal("complementary").annotations({
1010
+ description: "Updating the complementary sidebar."
1011
+ }),
1012
+ subject: import_schema4.Schema.optional(import_schema4.Schema.String.annotations({
1013
+ description: "URI of the component to display in the complementary area."
1014
+ })),
1015
+ options: import_schema4.Schema.optional(import_schema4.Schema.Struct({
1016
+ state: import_schema4.Schema.Literal("closed", "collapsed", "expanded").annotations({
1017
+ description: "Whether the complementary sidebar is closed, collapsed, or expanded."
1018
+ })
1019
+ }))
1020
+ }),
1021
+ output: import_schema4.Schema.Void
1022
+ }) {
1023
+ }
1024
+ LayoutAction2.UpdateComplementary = UpdateComplementary;
1025
+ class UpdateDialog extends import_schema4.Schema.TaggedClass()(LayoutAction2.UPDATE_LAYOUT, {
1026
+ input: import_schema4.Schema.Struct({
1027
+ part: import_schema4.Schema.Literal("dialog").annotations({
1028
+ description: "Updating the dialog."
1029
+ }),
1030
+ subject: import_schema4.Schema.optional(import_schema4.Schema.String.annotations({
1031
+ description: "URI of the component to display in the dialog."
1032
+ })),
1033
+ options: import_schema4.Schema.Struct({
1034
+ state: import_schema4.Schema.optional(import_schema4.Schema.Boolean.annotations({
1035
+ description: "Whether the dialog is open or closed."
1036
+ })),
1037
+ blockAlign: import_schema4.Schema.optional(import_schema4.Schema.Literal("start", "center").annotations({
1038
+ description: "The alignment of the dialog."
1039
+ })),
1040
+ type: import_schema4.Schema.optional(import_schema4.Schema.Literal("default", "alert").annotations({
1041
+ description: "The type of dialog."
1042
+ })),
1043
+ props: import_schema4.Schema.optional(import_schema4.Schema.Record({
1044
+ key: import_schema4.Schema.String,
1045
+ value: import_schema4.Schema.Any
1046
+ }).annotations({
1047
+ description: "Additional props for the dialog."
1048
+ }))
1049
+ })
1050
+ }),
1051
+ output: import_schema4.Schema.Void
1052
+ }) {
1053
+ }
1054
+ LayoutAction2.UpdateDialog = UpdateDialog;
1055
+ class UpdatePopover extends import_schema4.Schema.TaggedClass()(LayoutAction2.UPDATE_LAYOUT, {
1056
+ input: import_schema4.Schema.Struct({
1057
+ part: import_schema4.Schema.Literal("popover").annotations({
1058
+ description: "Updating the popover."
1059
+ }),
1060
+ subject: import_schema4.Schema.optional(import_schema4.Schema.String.annotations({
1061
+ description: "URI of the component to display in the popover."
1062
+ })),
1063
+ options: import_schema4.Schema.Struct({
1064
+ anchorId: import_schema4.Schema.String.annotations({
1065
+ description: "The id of the element to anchor the popover to."
1066
+ }),
1067
+ state: import_schema4.Schema.optional(import_schema4.Schema.Boolean.annotations({
1068
+ description: "Whether the popover is open or closed."
1069
+ })),
1070
+ props: import_schema4.Schema.optional(import_schema4.Schema.Record({
1071
+ key: import_schema4.Schema.String,
1072
+ value: import_schema4.Schema.Any
1073
+ }).annotations({
1074
+ description: "Additional props for the popover."
1075
+ }))
1076
+ })
1077
+ }),
1078
+ output: import_schema4.Schema.Void
1079
+ }) {
1080
+ }
1081
+ LayoutAction2.UpdatePopover = UpdatePopover;
1082
+ LayoutAction2.Toast = import_schema4.Schema.Struct({
1083
+ id: import_schema4.Schema.String.annotations({
1084
+ description: "The id of the toast."
1085
+ }),
1086
+ title: import_schema4.Schema.optional(Label.annotations({
1087
+ description: "The title of the toast."
1088
+ })),
1089
+ description: import_schema4.Schema.optional(Label.annotations({
1090
+ description: "The description of the toast."
1091
+ })),
1092
+ icon: import_schema4.Schema.optional(import_schema4.Schema.String.annotations({
1093
+ description: "The icon of the toast."
1094
+ })),
1095
+ duration: import_schema4.Schema.optional(import_schema4.Schema.Number.annotations({
1096
+ description: "The duration of the toast."
1097
+ })),
1098
+ closeLabel: import_schema4.Schema.optional(Label.annotations({
1099
+ description: "The label of the close button."
1100
+ })),
1101
+ actionLabel: import_schema4.Schema.optional(Label.annotations({
1102
+ description: "The label of the action button."
1103
+ })),
1104
+ actionAlt: import_schema4.Schema.optional(Label.annotations({
1105
+ description: "The alt text of the action button."
1106
+ })),
1107
+ onAction: import_schema4.Schema.optional(import_schema4.Schema.Any.annotations({
1108
+ description: "The action to perform when the action button is clicked."
1109
+ }))
1110
+ });
1111
+ class AddToast extends import_schema4.Schema.TaggedClass()(LayoutAction2.UPDATE_LAYOUT, {
1112
+ input: import_schema4.Schema.Struct({
1113
+ part: import_schema4.Schema.Literal("toast").annotations({
1114
+ description: "Adding a toast."
1115
+ }),
1116
+ subject: LayoutAction2.Toast.annotations({
1117
+ description: "The toast to add."
1118
+ })
1119
+ }),
1120
+ output: import_schema4.Schema.Void
1121
+ }) {
1122
+ }
1123
+ LayoutAction2.AddToast = AddToast;
1124
+ class SwitchWorkspace extends import_schema4.Schema.TaggedClass()(LayoutAction2.UPDATE_LAYOUT, {
1125
+ input: import_schema4.Schema.Struct({
1126
+ part: import_schema4.Schema.Literal("workspace").annotations({
1127
+ description: "Switching the workspace."
1128
+ }),
1129
+ subject: import_schema4.Schema.String.annotations({
1130
+ description: "The id of the workspace to switch to."
1131
+ })
1132
+ }),
1133
+ output: import_schema4.Schema.Void
1134
+ }) {
1135
+ }
1136
+ LayoutAction2.SwitchWorkspace = SwitchWorkspace;
1137
+ class Open extends import_schema4.Schema.TaggedClass()(LayoutAction2.UPDATE_LAYOUT, {
1138
+ input: import_schema4.Schema.Struct({
1139
+ part: import_schema4.Schema.Literal("main").annotations({
1140
+ description: "Opening an item in the main content area."
1141
+ }),
1142
+ subject: import_schema4.Schema.Array(import_schema4.Schema.String.annotations({
1143
+ description: "Ids of the items to open."
1144
+ })),
1145
+ options: import_schema4.Schema.optional(import_schema4.Schema.Struct({
1146
+ state: import_schema4.Schema.optional(import_schema4.Schema.Literal(true).annotations({
1147
+ description: "The items are being added."
1148
+ })),
1149
+ key: import_schema4.Schema.optional(import_schema4.Schema.String.annotations({
1150
+ description: "If provided, will replace item with a matching key (id prefix)."
1151
+ })),
1152
+ scrollIntoView: import_schema4.Schema.optional(import_schema4.Schema.Boolean.annotations({
1153
+ description: "Scroll the items into view."
1154
+ })),
1155
+ pivotId: import_schema4.Schema.optional(import_schema4.Schema.String.annotations({
1156
+ description: "The id of the item to place new items next to."
1157
+ })),
1158
+ positioning: import_schema4.Schema.optional(import_schema4.Schema.Union(import_schema4.Schema.Literal("start").annotations({
1159
+ description: "The items are being added before the pivot item."
1160
+ }), import_schema4.Schema.Literal("end").annotations({
1161
+ description: "The items are being added after the pivot item."
1162
+ })))
1163
+ }))
1164
+ }),
1165
+ output: import_schema4.Schema.Void
1166
+ }) {
1167
+ }
1168
+ LayoutAction2.Open = Open;
1169
+ class Set2 extends import_schema4.Schema.TaggedClass()(LayoutAction2.UPDATE_LAYOUT, {
1170
+ input: import_schema4.Schema.Struct({
1171
+ part: import_schema4.Schema.Literal("main").annotations({
1172
+ description: "Setting items in the main content area."
1173
+ }),
1174
+ subject: import_schema4.Schema.Array(import_schema4.Schema.String.annotations({
1175
+ description: "Ids of the items to set."
1176
+ })),
1177
+ options: import_schema4.Schema.Struct({
1178
+ override: import_schema4.Schema.Literal(true).annotations({
1179
+ description: "Override the current items in the main content area."
1180
+ })
1181
+ })
1182
+ }),
1183
+ output: import_schema4.Schema.Void
1184
+ }) {
1185
+ }
1186
+ LayoutAction2.Set = Set2;
1187
+ class Close extends import_schema4.Schema.TaggedClass()(LayoutAction2.UPDATE_LAYOUT, {
1188
+ input: import_schema4.Schema.Struct({
1189
+ part: import_schema4.Schema.Literal("main").annotations({
1190
+ description: "Closing items in the main content area."
1191
+ }),
1192
+ subject: import_schema4.Schema.Array(import_schema4.Schema.String.annotations({
1193
+ description: "Ids of the items to close."
1194
+ })),
1195
+ options: import_schema4.Schema.Struct({
1196
+ state: import_schema4.Schema.Literal(false).annotations({
1197
+ description: "The items are being removed."
1198
+ })
1199
+ })
1200
+ }),
1201
+ output: import_schema4.Schema.Void
1202
+ }) {
1203
+ }
1204
+ LayoutAction2.Close = Close;
1205
+ class ScrollIntoView extends import_schema4.Schema.TaggedClass()(LayoutAction2.UPDATE_LAYOUT, {
1206
+ input: import_schema4.Schema.Struct({
1207
+ part: import_schema4.Schema.Literal("current").annotations({
1208
+ description: "Setting the current item"
1209
+ }),
1210
+ subject: import_schema4.Schema.optional(import_schema4.Schema.String.annotations({
1211
+ description: "The id of the item to set as current."
1212
+ })),
1213
+ options: import_schema4.Schema.optional(import_schema4.Schema.Record({
1214
+ key: import_schema4.Schema.String,
1215
+ value: import_schema4.Schema.Any
1216
+ }).annotations({
1217
+ description: "Additional options for the scroll into view."
1218
+ }))
1219
+ }),
1220
+ output: import_schema4.Schema.Void
1221
+ }) {
1222
+ }
1223
+ LayoutAction2.ScrollIntoView = ScrollIntoView;
1224
+ class Expose extends import_schema4.Schema.TaggedClass()(LayoutAction2.UPDATE_LAYOUT, {
1225
+ input: import_schema4.Schema.Struct({
1226
+ part: import_schema4.Schema.Literal("navigation").annotations({
1227
+ description: "Exposing an item in the navigation area."
1228
+ }),
1229
+ subject: import_schema4.Schema.String.annotations({
1230
+ description: "The id of the item to expose."
1231
+ })
1232
+ }),
1233
+ output: import_schema4.Schema.Void
1234
+ }) {
1235
+ }
1236
+ LayoutAction2.Expose = Expose;
1237
+ })(LayoutAction || (LayoutAction = {}));
1238
+ var createSurface = (definition) => definition;
1239
+ var ResourceKey = import_schema5.Schema.Union(import_schema5.Schema.String, import_schema5.Schema.Record({
1240
+ key: import_schema5.Schema.String,
1241
+ value: import_schema5.Schema.Any
1242
+ }));
1243
+ var ResourceLanguage = import_schema5.Schema.Record({
1244
+ key: import_schema5.Schema.String,
1245
+ value: ResourceKey
1246
+ });
1247
+ var Resource = import_schema5.Schema.Record({
1248
+ key: import_schema5.Schema.String,
1249
+ value: ResourceLanguage
1250
+ });
1251
+ var EXECUTION_LIMIT = 100;
1252
+ var HISTORY_LIMIT = 100;
1253
+ var createResolver = (resolver) => resolver;
1254
+ var isUndoable = (historyEntry) => historyEntry.length > 0 && historyEntry.every(({ undoable }) => !!undoable);
1255
+ var createDispatcher = (getResolvers, { executionLimit = EXECUTION_LIMIT, historyLimit = HISTORY_LIMIT } = {}) => {
1256
+ const historyRef = import_effect.Effect.runSync(import_effect.Ref.make([]));
1257
+ const handleIntent = (intent) => import_effect.Effect.gen(function* () {
1258
+ const candidates = getResolvers(intent.module).filter((r) => r.intent._tag === intent.id).filter((r) => !r.filter || r.filter(intent.data)).toSorted(import_util.byPosition);
1259
+ if (candidates.length === 0) {
1260
+ yield* import_effect.Effect.fail(new NoResolversError(intent.id));
1261
+ }
1262
+ const effect2 = candidates[0].resolve(intent.data, intent.undo ?? false);
1263
+ const result = import_effect.Effect.isEffect(effect2) ? yield* effect2 : yield* import_effect.Effect.promise(async () => effect2);
1264
+ return {
1265
+ _intent: intent,
1266
+ ...result
1267
+ };
1268
+ });
1269
+ const dispatch = (intentChain, depth = 0) => {
1270
+ return import_effect.Effect.gen(function* () {
1271
+ if (depth > executionLimit) {
1272
+ yield* import_effect.Effect.fail(new CycleDetectedError());
1273
+ }
1274
+ const resultsRef = yield* import_effect.Ref.make([]);
1275
+ for (const intent of intentChain.all) {
1276
+ const { data: prev } = (yield* resultsRef.get)[0] ?? {};
1277
+ const result2 = yield* handleIntent({
1278
+ ...intent,
1279
+ data: {
1280
+ ...intent.data,
1281
+ ...prev
1282
+ }
1283
+ });
1284
+ yield* import_effect.Ref.update(resultsRef, (results2) => [
1285
+ result2,
1286
+ ...results2
1287
+ ]);
1288
+ if (result2.intents) {
1289
+ for (const intent2 of result2.intents) {
1290
+ yield* dispatch(intent2, depth + 1);
1291
+ }
1292
+ }
1293
+ if (result2.error) {
1294
+ yield* import_effect.Effect.fail(result2.error);
1295
+ }
1296
+ }
1297
+ const results = yield* resultsRef.get;
1298
+ const result = results[0];
1299
+ yield* import_effect.Ref.update(historyRef, (history) => {
1300
+ const next = [
1301
+ ...history,
1302
+ results
1303
+ ];
1304
+ if (next.length > historyLimit) {
1305
+ next.splice(0, next.length - historyLimit);
1306
+ }
1307
+ return next;
1308
+ });
1309
+ if (result.undoable && isUndoable(results)) {
1310
+ yield* (0, import_effect.pipe)(dispatch(createIntent(IntentAction.ShowUndo, {
1311
+ message: result.undoable.message
1312
+ })), import_effect.Effect.catchSome((err) => err instanceof NoResolversError ? import_effect.Option.some(import_effect.Effect.succeed(void 0)) : import_effect.Option.none()));
1313
+ }
1314
+ return result.data;
1315
+ });
1316
+ };
1317
+ const dispatchPromise = (intentChain) => {
1318
+ return import_effect.Effect.runPromise(dispatch(intentChain)).then((data) => ({
1319
+ data
1320
+ })).catch((error) => ({
1321
+ error
1322
+ }));
1323
+ };
1324
+ const undo = () => {
1325
+ return import_effect.Effect.gen(function* () {
1326
+ const history = yield* historyRef.get;
1327
+ const last = history.findLastIndex(isUndoable);
1328
+ const result = last !== -1 ? history[last] : void 0;
1329
+ if (result) {
1330
+ const all = result.map(({ _intent, undoable }) => {
1331
+ const data = _intent.data;
1332
+ const undoData = undoable?.data ?? {};
1333
+ return {
1334
+ ..._intent,
1335
+ data: {
1336
+ ...data,
1337
+ ...undoData
1338
+ },
1339
+ undo: true
1340
+ };
1341
+ });
1342
+ const intent = {
1343
+ first: all[0],
1344
+ last: all.at(-1),
1345
+ all
1346
+ };
1347
+ yield* import_effect.Ref.update(historyRef, (h) => h.filter((_, index) => index !== last));
1348
+ return yield* dispatch(intent);
1349
+ }
1350
+ });
1351
+ };
1352
+ const undoPromise = () => {
1353
+ return import_effect.Effect.runPromise(undo()).then((data) => ({
1354
+ data
1355
+ })).catch((error) => ({
1356
+ error
1357
+ }));
1358
+ };
1359
+ return {
1360
+ dispatch,
1361
+ dispatchPromise,
1362
+ undo,
1363
+ undoPromise
1364
+ };
1365
+ };
1366
+ var defaultEffect = () => import_effect.Effect.fail(new Error("Intent runtime not ready"));
1367
+ var defaultPromise = () => import_effect.Effect.runPromise(defaultEffect());
1368
+ var intent_dispatcher_default = (context) => {
1369
+ const state = (0, import_live_object.create)({
1370
+ dispatch: defaultEffect,
1371
+ dispatchPromise: defaultPromise,
1372
+ undo: defaultEffect,
1373
+ undoPromise: defaultPromise
1374
+ });
1375
+ const { dispatch, dispatchPromise, undo, undoPromise } = createDispatcher((module2) => context.requestCapabilities(Capabilities.IntentResolver, (c, moduleId) => {
1376
+ return module2 ? moduleId === module2 : true;
1377
+ }).flat());
1378
+ const manager = context.requestCapability(Capabilities.PluginManager);
1379
+ state.dispatch = (intentChain, depth) => {
1380
+ return import_effect.Effect.gen(function* () {
1381
+ yield* manager._activate(Events.SetupIntents);
1382
+ return yield* dispatch(intentChain, depth);
1383
+ });
1384
+ };
1385
+ state.dispatchPromise = async (intentChain) => {
1386
+ await manager.activate(Events.SetupIntents);
1387
+ return await dispatchPromise(intentChain);
1388
+ };
1389
+ state.undo = undo;
1390
+ state.undoPromise = undoPromise;
1391
+ return contributes(Capabilities.IntentDispatcher, state);
1392
+ };
1393
+ // Annotate the CommonJS export names for ESM import in node:
1394
+ 0 && (module.exports = {
1395
+ Capabilities,
1396
+ Events,
1397
+ FileInfoSchema,
1398
+ INTENT_ACTION,
1399
+ INTENT_PLUGIN,
1400
+ IntentAction,
1401
+ IntentPlugin,
1402
+ LAYOUT_ACTION,
1403
+ LAYOUT_PLUGIN,
1404
+ Label,
1405
+ LayoutAction,
1406
+ Plugin,
1407
+ PluginManager,
1408
+ PluginModule,
1409
+ PluginsContext,
1410
+ Resource,
1411
+ ResourceKey,
1412
+ ResourceLanguage,
1413
+ allOf,
1414
+ chain,
1415
+ contributes,
1416
+ createDispatcher,
1417
+ createIntent,
1418
+ createResolver,
1419
+ createSurface,
1420
+ defaultFileTypes,
1421
+ defineCapability,
1422
+ defineEvent,
1423
+ defineModule,
1424
+ definePlugin,
1425
+ eventKey,
1426
+ getEvents,
1427
+ intent_dispatcher_default,
1428
+ isAllOf,
1429
+ isOneOf,
1430
+ lazy,
1431
+ oneOf
1432
+ });
1433
+ //# sourceMappingURL=chunk-WKC6YMEQ.cjs.map