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