@mountaya/studio 0.1.0 → 0.2.0

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 (260) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/dist/agent/index.cjs +2561 -2815
  3. package/dist/agent/index.cjs.map +1 -1
  4. package/dist/agent/index.d.cts +766 -786
  5. package/dist/agent/index.d.ts +766 -786
  6. package/dist/agent/index.js +2553 -2790
  7. package/dist/agent/index.js.map +1 -1
  8. package/dist/chunk-3Oi_Zrtm.js +9 -0
  9. package/dist/chunk-3Oi_Zrtm.js.map +1 -0
  10. package/dist/chunk-B18OPIu_.js +6 -0
  11. package/dist/chunk-B18OPIu_.js.map +1 -0
  12. package/dist/chunk-B5Uz3Qct.cjs +15 -0
  13. package/dist/chunk-B5Uz3Qct.cjs.map +1 -0
  14. package/dist/chunk-BBEJwkd3.d.cts +839 -0
  15. package/dist/chunk-BIEc_SkR.cjs +29 -0
  16. package/dist/chunk-BIEc_SkR.cjs.map +1 -0
  17. package/dist/chunk-BKMFOe-N.js +171 -0
  18. package/dist/chunk-BKMFOe-N.js.map +1 -0
  19. package/dist/chunk-BP4uy7E1.d.ts +11583 -0
  20. package/dist/chunk-BSHTsFiB.js +1403 -0
  21. package/dist/chunk-BSHTsFiB.js.map +1 -0
  22. package/dist/chunk-BTUUABGI.js +17 -0
  23. package/dist/chunk-BTUUABGI.js.map +1 -0
  24. package/dist/chunk-BaPiaz5X.cjs +115 -0
  25. package/dist/chunk-BaPiaz5X.cjs.map +1 -0
  26. package/dist/chunk-BeCVpkYr.cjs +542 -0
  27. package/dist/chunk-BeCVpkYr.cjs.map +1 -0
  28. package/dist/chunk-BgngsvK8.cjs +6202 -0
  29. package/dist/chunk-BgngsvK8.cjs.map +1 -0
  30. package/dist/chunk-BhInd7CJ.d.cts +253 -0
  31. package/dist/chunk-Bn6ZbxkS.cjs +27 -0
  32. package/dist/chunk-By9ZnkVI.js +60 -0
  33. package/dist/chunk-By9ZnkVI.js.map +1 -0
  34. package/dist/chunk-BzqPhxsz.cjs +367 -0
  35. package/dist/chunk-BzqPhxsz.cjs.map +1 -0
  36. package/dist/chunk-C2mMX81q.d.ts +443 -0
  37. package/dist/chunk-C2rr9Q0V.cjs +1402 -0
  38. package/dist/chunk-C2rr9Q0V.cjs.map +1 -0
  39. package/dist/{directorThreads-CqmvsV8b.d.cts → chunk-CDJCbwIQ.d.cts} +20 -22
  40. package/dist/chunk-CLGvBOVH.d.cts +1654 -0
  41. package/dist/chunk-COdw1dc6.d.ts +525 -0
  42. package/dist/chunk-CQCJnT2i.d.ts +511 -0
  43. package/dist/chunk-CSyHY67q.cjs +353 -0
  44. package/dist/chunk-CSyHY67q.cjs.map +1 -0
  45. package/dist/chunk-CiK1Iqrv.js +950 -0
  46. package/dist/chunk-CiK1Iqrv.js.map +1 -0
  47. package/dist/chunk-CmJBgSwZ.cjs +24 -0
  48. package/dist/chunk-CmJBgSwZ.cjs.map +1 -0
  49. package/dist/chunk-CnrsRK2u.cjs +83 -0
  50. package/dist/chunk-CnrsRK2u.cjs.map +1 -0
  51. package/dist/chunk-Co782_9r.js +326 -0
  52. package/dist/chunk-Co782_9r.js.map +1 -0
  53. package/dist/chunk-Csr3KDpZ.cjs +32 -0
  54. package/dist/chunk-Csr3KDpZ.cjs.map +1 -0
  55. package/dist/chunk-CwkmccXv.js +89 -0
  56. package/dist/chunk-CwkmccXv.js.map +1 -0
  57. package/dist/chunk-D0Q4iL9B.cjs +255 -0
  58. package/dist/chunk-D0Q4iL9B.cjs.map +1 -0
  59. package/dist/chunk-DFwiSzUS.cjs +72 -0
  60. package/dist/chunk-DFwiSzUS.cjs.map +1 -0
  61. package/dist/chunk-DIFayl2P.d.cts +443 -0
  62. package/dist/chunk-DIGF58ux.d.cts +525 -0
  63. package/dist/chunk-DKuuuld5.js +101 -0
  64. package/dist/chunk-DKuuuld5.js.map +1 -0
  65. package/dist/chunk-DMePkFEo.js +5054 -0
  66. package/dist/chunk-DMePkFEo.js.map +1 -0
  67. package/dist/chunk-DO5SIBgu.js +305 -0
  68. package/dist/chunk-DO5SIBgu.js.map +1 -0
  69. package/dist/chunk-DOQ_7eE5.d.ts +6662 -0
  70. package/dist/{tabs-B2nRO4p_.d.ts → chunk-DThaaNeb.d.cts} +2 -2
  71. package/dist/{tabs-B2nRO4p_.d.cts → chunk-DThaaNeb.d.ts} +2 -2
  72. package/dist/{directorThreads-CqmvsV8b.d.ts → chunk-DUQzjUJy.d.ts} +20 -22
  73. package/dist/chunk-DX37IPhV.cjs +1903 -0
  74. package/dist/chunk-DX37IPhV.cjs.map +1 -0
  75. package/dist/chunk-Damps5Tk.cjs +155 -0
  76. package/dist/chunk-Damps5Tk.cjs.map +1 -0
  77. package/dist/chunk-DbK5PhpJ.d.ts +1654 -0
  78. package/dist/chunk-De0vAASv.d.ts +253 -0
  79. package/dist/chunk-DhSZ7YZt.d.cts +6662 -0
  80. package/dist/chunk-DjEvqvPA.cjs +43 -0
  81. package/dist/chunk-DjEvqvPA.cjs.map +1 -0
  82. package/dist/{saveFile-j-1kkApx.d.cts → chunk-DkwDzwvu.d.cts} +7 -9
  83. package/dist/{saveFile-j-1kkApx.d.ts → chunk-DkwDzwvu.d.ts} +7 -9
  84. package/dist/chunk-Dmszv9If.js +71 -0
  85. package/dist/chunk-Dmszv9If.js.map +1 -0
  86. package/dist/chunk-Dp_ftNWY.d.cts +511 -0
  87. package/dist/chunk-DsHQySz0.js +31 -0
  88. package/dist/chunk-DsHQySz0.js.map +1 -0
  89. package/dist/chunk-DwoUyHHh.js +281 -0
  90. package/dist/chunk-DwoUyHHh.js.map +1 -0
  91. package/dist/chunk-IaIDQflj.d.cts +2315 -0
  92. package/dist/chunk-IaIDQflj.d.ts +2315 -0
  93. package/dist/chunk-cVXLsZfL.d.ts +839 -0
  94. package/dist/chunk-mIaCX9EJ.d.cts +11583 -0
  95. package/dist/chunk-nJQxbOwQ.cjs +8962 -0
  96. package/dist/chunk-nJQxbOwQ.cjs.map +1 -0
  97. package/dist/chunk-o9jaxhCO.js +8852 -0
  98. package/dist/chunk-o9jaxhCO.js.map +1 -0
  99. package/dist/chunk-p-Tt_Lwz.js +14 -0
  100. package/dist/chunk-p-Tt_Lwz.js.map +1 -0
  101. package/dist/engines/index.cjs +2046 -3401
  102. package/dist/engines/index.cjs.map +1 -1
  103. package/dist/engines/index.d.cts +1510 -1550
  104. package/dist/engines/index.d.ts +1510 -1550
  105. package/dist/engines/index.js +2039 -3380
  106. package/dist/engines/index.js.map +1 -1
  107. package/dist/handlers/index.cjs +47 -93
  108. package/dist/handlers/index.cjs.map +1 -1
  109. package/dist/handlers/index.d.cts +61 -103
  110. package/dist/handlers/index.d.ts +61 -103
  111. package/dist/handlers/index.js +27 -36
  112. package/dist/handlers/index.js.map +1 -1
  113. package/dist/index.cjs +3347 -4398
  114. package/dist/index.cjs.map +1 -1
  115. package/dist/index.d.cts +8 -7297
  116. package/dist/index.d.ts +8 -7297
  117. package/dist/index.js +2997 -3187
  118. package/dist/index.js.map +1 -1
  119. package/dist/plugins/index.cjs +482 -949
  120. package/dist/plugins/index.cjs.map +1 -1
  121. package/dist/plugins/index.d.cts +44 -61
  122. package/dist/plugins/index.d.ts +44 -61
  123. package/dist/plugins/index.js +471 -915
  124. package/dist/plugins/index.js.map +1 -1
  125. package/dist/seams/index.cjs +77 -140
  126. package/dist/seams/index.cjs.map +1 -1
  127. package/dist/seams/index.d.cts +125 -158
  128. package/dist/seams/index.d.ts +125 -158
  129. package/dist/seams/index.js +41 -71
  130. package/dist/seams/index.js.map +1 -1
  131. package/dist/strings/fr/index.cjs +2130 -2116
  132. package/dist/strings/fr/index.cjs.map +1 -1
  133. package/dist/strings/fr/index.d.cts +3 -5
  134. package/dist/strings/fr/index.d.ts +3 -5
  135. package/dist/strings/fr/index.js +2125 -2114
  136. package/dist/strings/fr/index.js.map +1 -1
  137. package/dist/strings/index.cjs +2331 -2625
  138. package/dist/strings/index.cjs.map +1 -1
  139. package/dist/strings/index.d.cts +3 -731
  140. package/dist/strings/index.d.ts +3 -731
  141. package/dist/strings/index.js +2324 -2615
  142. package/dist/strings/index.js.map +1 -1
  143. package/dist/testing/index.cjs +214 -276
  144. package/dist/testing/index.cjs.map +1 -1
  145. package/dist/testing/index.d.cts +61 -121
  146. package/dist/testing/index.d.ts +61 -121
  147. package/dist/testing/index.js +208 -273
  148. package/dist/testing/index.js.map +1 -1
  149. package/dist/time/index.cjs +23 -23
  150. package/dist/time/index.cjs.map +1 -1
  151. package/dist/time/index.d.cts +5 -7
  152. package/dist/time/index.d.ts +5 -7
  153. package/dist/time/index.js +18 -21
  154. package/dist/time/index.js.map +1 -1
  155. package/package.json +14 -15
  156. package/src/agent/rules/stateDelta.ts +1 -0
  157. package/src/agent/stores/agentThreads.ts +1 -4
  158. package/src/bus/rules/bus.ts +1 -2
  159. package/src/bus/rules/defineRegistry.ts +3 -5
  160. package/src/bus/rules/types.ts +6 -7
  161. package/src/chrome/stores/uiStore.ts +4 -2
  162. package/src/embed/rules/fieldDependencies.ts +2 -0
  163. package/src/embed/rules/safetyRules.ts +2 -0
  164. package/src/embed/rules/tableCode.ts +4 -3
  165. package/src/index.ts +6 -27
  166. package/src/itinerary/rules/import.ts +6 -8
  167. package/src/plugins/contracts/plugin.ts +4 -2
  168. package/src/seams/rules/formatters.ts +5 -3
  169. package/src/testing/index.ts +1 -5
  170. package/src/viewer/rules/platformViewer.ts +1 -0
  171. package/dist/bus-BwiNiXdH.d.ts +0 -514
  172. package/dist/bus-DzmhPwdK.d.cts +0 -514
  173. package/dist/chainModel-B23pEP_1.d.cts +0 -127
  174. package/dist/chainModel-B23pEP_1.d.ts +0 -127
  175. package/dist/chunk-2HFY7ETU.js +0 -5721
  176. package/dist/chunk-2HFY7ETU.js.map +0 -1
  177. package/dist/chunk-355TOXSB.js +0 -72
  178. package/dist/chunk-355TOXSB.js.map +0 -1
  179. package/dist/chunk-4ZCUZVSV.js +0 -10275
  180. package/dist/chunk-4ZCUZVSV.js.map +0 -1
  181. package/dist/chunk-6HEKY3NF.js +0 -95
  182. package/dist/chunk-6HEKY3NF.js.map +0 -1
  183. package/dist/chunk-7GFLGGBX.cjs +0 -8
  184. package/dist/chunk-7GFLGGBX.cjs.map +0 -1
  185. package/dist/chunk-7NBRCENN.cjs +0 -19
  186. package/dist/chunk-7NBRCENN.cjs.map +0 -1
  187. package/dist/chunk-AF5GCXE3.js +0 -8
  188. package/dist/chunk-AF5GCXE3.js.map +0 -1
  189. package/dist/chunk-CJDIFRGZ.cjs +0 -2005
  190. package/dist/chunk-CJDIFRGZ.cjs.map +0 -1
  191. package/dist/chunk-CNPZY7N3.js +0 -349
  192. package/dist/chunk-CNPZY7N3.js.map +0 -1
  193. package/dist/chunk-DZJHTWSF.cjs +0 -45
  194. package/dist/chunk-DZJHTWSF.cjs.map +0 -1
  195. package/dist/chunk-EABIHHWA.js +0 -42
  196. package/dist/chunk-EABIHHWA.js.map +0 -1
  197. package/dist/chunk-EKZWV6RS.cjs +0 -415
  198. package/dist/chunk-EKZWV6RS.cjs.map +0 -1
  199. package/dist/chunk-EOKRXXAC.cjs +0 -24
  200. package/dist/chunk-EOKRXXAC.cjs.map +0 -1
  201. package/dist/chunk-F73W2ZTJ.js +0 -1126
  202. package/dist/chunk-F73W2ZTJ.js.map +0 -1
  203. package/dist/chunk-H4DVOZ5O.js +0 -1897
  204. package/dist/chunk-H4DVOZ5O.js.map +0 -1
  205. package/dist/chunk-HI52PBFT.cjs +0 -10314
  206. package/dist/chunk-HI52PBFT.cjs.map +0 -1
  207. package/dist/chunk-IDBXFBLG.cjs +0 -1225
  208. package/dist/chunk-IDBXFBLG.cjs.map +0 -1
  209. package/dist/chunk-LBWTJZUJ.js +0 -297
  210. package/dist/chunk-LBWTJZUJ.js.map +0 -1
  211. package/dist/chunk-NCLA6DKD.cjs +0 -310
  212. package/dist/chunk-NCLA6DKD.cjs.map +0 -1
  213. package/dist/chunk-O4MC5DPD.js +0 -19
  214. package/dist/chunk-O4MC5DPD.js.map +0 -1
  215. package/dist/chunk-OP37FKW6.cjs +0 -98
  216. package/dist/chunk-OP37FKW6.cjs.map +0 -1
  217. package/dist/chunk-OQSYFH3Z.cjs +0 -5945
  218. package/dist/chunk-OQSYFH3Z.cjs.map +0 -1
  219. package/dist/chunk-PACIO4NS.cjs +0 -26
  220. package/dist/chunk-PACIO4NS.cjs.map +0 -1
  221. package/dist/chunk-PSZ2R3TC.cjs +0 -75
  222. package/dist/chunk-PSZ2R3TC.cjs.map +0 -1
  223. package/dist/chunk-QFO5CZG2.cjs +0 -136
  224. package/dist/chunk-QFO5CZG2.cjs.map +0 -1
  225. package/dist/chunk-QL63MUEW.cjs +0 -140
  226. package/dist/chunk-QL63MUEW.cjs.map +0 -1
  227. package/dist/chunk-RFUPPVZO.js +0 -17
  228. package/dist/chunk-RFUPPVZO.js.map +0 -1
  229. package/dist/chunk-RPG2LWMP.js +0 -23
  230. package/dist/chunk-RPG2LWMP.js.map +0 -1
  231. package/dist/chunk-TIBXK6B7.cjs +0 -12
  232. package/dist/chunk-TIBXK6B7.cjs.map +0 -1
  233. package/dist/chunk-UU65VNEV.js +0 -381
  234. package/dist/chunk-UU65VNEV.js.map +0 -1
  235. package/dist/chunk-VGX6TR2I.js +0 -209
  236. package/dist/chunk-VGX6TR2I.js.map +0 -1
  237. package/dist/chunk-WUTDDBVP.js +0 -130
  238. package/dist/chunk-WUTDDBVP.js.map +0 -1
  239. package/dist/chunk-WVQQLKCI.cjs +0 -224
  240. package/dist/chunk-WVQQLKCI.cjs.map +0 -1
  241. package/dist/chunk-WZYXG3SE.js +0 -111
  242. package/dist/chunk-WZYXG3SE.js.map +0 -1
  243. package/dist/chunk-XDI2X3KE.js +0 -6
  244. package/dist/chunk-XDI2X3KE.js.map +0 -1
  245. package/dist/chunk-XKHLRIC7.cjs +0 -381
  246. package/dist/chunk-XKHLRIC7.cjs.map +0 -1
  247. package/dist/context-DNtd2WUv.d.cts +0 -11666
  248. package/dist/context-DgB72Bur.d.ts +0 -11666
  249. package/dist/en-Bu4Ti9Ev.d.cts +0 -2315
  250. package/dist/en-Bu4Ti9Ev.d.ts +0 -2315
  251. package/dist/shareLink-B6hlt942.d.ts +0 -144
  252. package/dist/shareLink-C7rIMb7x.d.ts +0 -527
  253. package/dist/shareLink-CnTxxXjp.d.cts +0 -144
  254. package/dist/shareLink-DyZVYH2V.d.cts +0 -527
  255. package/dist/studioPlugin-C3C7VjMy.d.ts +0 -847
  256. package/dist/studioPlugin-Cf3OBNUv.d.cts +0 -847
  257. package/dist/types-BzJRV6UI.d.cts +0 -845
  258. package/dist/types-BzJRV6UI.d.ts +0 -845
  259. package/dist/zoneForm-CdYNtnnA.d.cts +0 -320
  260. package/dist/zoneForm-mG85yt5e.d.ts +0 -320
@@ -1,933 +1,489 @@
1
- import { studioPluginIdPattern, RESERVED_PLUGIN_NAMESPACES, studioContributionIdPattern } from '../chunk-AF5GCXE3.js';
2
- export { RESERVED_PLUGIN_NAMESPACES, studioContributionIdPattern, studioPluginIdPattern } from '../chunk-AF5GCXE3.js';
3
- import { surfaceFault, notifyListeners } from '../chunk-RPG2LWMP.js';
4
- import * as z from 'zod';
5
- import { MountayaElementsError } from '@mountaya/elements/errors';
6
-
7
- var studioPluginSlotSchema = z.enum([
8
- "itinerary.menu",
9
- "map.contextMenu",
10
- "map.controls",
11
- "profile.header",
12
- "profile.plot",
13
- "segment.menu",
14
- "waypoint.menu",
15
- "zone.menu"
1
+ import { n as studioContributionIdPattern, r as studioPluginIdPattern, t as RESERVED_PLUGIN_NAMESPACES } from "../chunk-B18OPIu_.js";
2
+ import { n as surfaceFault, t as notifyListeners } from "../chunk-BTUUABGI.js";
3
+ import * as z$1 from "zod";
4
+ import { MountayaElementsError } from "@mountaya/elements/errors";
5
+ const studioPluginSlotSchema = z$1.enum([
6
+ "itinerary.menu",
7
+ "map.contextMenu",
8
+ "map.controls",
9
+ "profile.header",
10
+ "profile.plot",
11
+ "segment.menu",
12
+ "waypoint.menu",
13
+ "zone.menu"
16
14
  ]);
17
-
18
- // src/plugins/rules/contributions.ts
19
- var isStudioContributionAvailable = (contribution, ctx) => {
20
- const gate = contribution.gate;
21
- if (gate === void 0) {
22
- return true;
23
- }
24
- try {
25
- for (const capability of gate.capabilities ?? []) {
26
- if (!ctx.capabilities.has(capability)) {
27
- return false;
28
- }
29
- }
30
- for (const entitlement of gate.entitlements ?? []) {
31
- if (!ctx.viewer.hasEntitlement(entitlement)) {
32
- return false;
33
- }
34
- }
35
- return gate.when === void 0 || gate.when(ctx) === true;
36
- } catch (fault) {
37
- const faulted = typeof gate === "object" && gate !== null ? gate : contribution;
38
- if (!faultedGates.has(faulted)) {
39
- faultedGates.add(faulted);
40
- surfaceFault(fault);
41
- }
42
- return false;
43
- }
15
+ const isStudioContributionAvailable = (contribution, ctx) => {
16
+ const gate = contribution.gate;
17
+ if (gate === void 0) return true;
18
+ try {
19
+ for (const capability of gate.capabilities ?? []) if (!ctx.capabilities.has(capability)) return false;
20
+ for (const entitlement of gate.entitlements ?? []) if (!ctx.viewer.hasEntitlement(entitlement)) return false;
21
+ return gate.when === void 0 || gate.when(ctx) === true;
22
+ } catch (fault) {
23
+ const faulted = typeof gate === "object" && gate !== null ? gate : contribution;
24
+ if (!faultedGates.has(faulted)) {
25
+ faultedGates.add(faulted);
26
+ surfaceFault(fault);
27
+ }
28
+ return false;
29
+ }
44
30
  };
45
- var faultedGates = /* @__PURE__ */ new WeakSet();
46
- var availableStudioContributions = (contributions, ctx) => {
47
- if (contributions.every((contribution) => isStudioContributionAvailable(contribution, ctx))) {
48
- return contributions;
49
- }
50
- return contributions.filter((contribution) => isStudioContributionAvailable(contribution, ctx));
31
+ const faultedGates = /* @__PURE__ */ new WeakSet();
32
+ const availableStudioContributions = (contributions, ctx) => {
33
+ if (contributions.every((contribution) => isStudioContributionAvailable(contribution, ctx))) return contributions;
34
+ return contributions.filter((contribution) => isStudioContributionAvailable(contribution, ctx));
51
35
  };
52
- var orderOf = ({ order }) => order !== void 0 && Number.isFinite(order) ? order : 0;
53
- var sortStudioContributions = (contributions) => [...contributions].sort(
54
- (left, right) => orderOf(left) - orderOf(right) || (left.sequence ?? 0) - (right.sequence ?? 0)
55
- );
56
- var STUDIO_PLUGIN_ERROR_NAME = "StudioPluginError";
36
+ const orderOf = ({ order }) => order !== void 0 && Number.isFinite(order) ? order : 0;
37
+ const sortStudioContributions = (contributions) => [...contributions].sort((left, right) => orderOf(left) - orderOf(right) || (left.sequence ?? 0) - (right.sequence ?? 0));
38
+ const STUDIO_PLUGIN_ERROR_NAME = "StudioPluginError";
57
39
  var StudioPluginError = class extends MountayaElementsError {
58
- name = STUDIO_PLUGIN_ERROR_NAME;
59
- defects;
60
- constructor(defects, options) {
61
- super(
62
- `plugin install refused: ${defects.map((defect) => `${defect.pluginId} ${defect.code}${defect.subject === void 0 ? "" : ` (${defect.subject})`}`).join(", ")}`,
63
- options
64
- );
65
- this.defects = defects;
66
- }
40
+ name = STUDIO_PLUGIN_ERROR_NAME;
41
+ defects;
42
+ constructor(defects, options) {
43
+ super(`plugin install refused: ${defects.map((defect) => `${defect.pluginId} ${defect.code}${defect.subject === void 0 ? "" : ` (${defect.subject})`}`).join(", ")}`, options);
44
+ this.defects = defects;
45
+ }
67
46
  };
68
- var isStudioPluginError = (error) => typeof error === "object" && error !== null && error.name === STUDIO_PLUGIN_ERROR_NAME && Array.isArray(error.defects);
69
-
70
- // src/plugins/rules/ids.ts
71
- var studioPluginToolPrefix = (pluginId) => `${pluginId}.`;
72
- var isStudioPluginToolName = (pluginId, name) => name.startsWith(studioPluginToolPrefix(pluginId));
73
- var qualifyStudioContributionId = (pluginId, contributionId) => `${pluginId}:${contributionId}`;
74
- var studioPluginDefectCodeSchema = z.enum([
75
- "contribution_empty",
76
- "contribution_id_duplicate",
77
- "contribution_id_invalid",
78
- "plugin_id_invalid",
79
- "plugin_id_reserved",
80
- "plugin_id_taken",
81
- "slot_unknown",
82
- "tool_key_mismatch",
83
- "tool_name_empty",
84
- "tool_name_not_namespaced",
85
- "tool_name_taken"
47
+ const isStudioPluginError = (error) => typeof error === "object" && error !== null && error.name === STUDIO_PLUGIN_ERROR_NAME && Array.isArray(error.defects);
48
+ const studioPluginToolPrefix = (pluginId) => `${pluginId}.`;
49
+ const isStudioPluginToolName = (pluginId, name) => name.startsWith(studioPluginToolPrefix(pluginId));
50
+ const qualifyStudioContributionId = (pluginId, contributionId) => `${pluginId}:${contributionId}`;
51
+ const studioPluginDefectCodeSchema = z$1.enum([
52
+ "contribution_empty",
53
+ "contribution_id_duplicate",
54
+ "contribution_id_invalid",
55
+ "plugin_id_invalid",
56
+ "plugin_id_reserved",
57
+ "plugin_id_taken",
58
+ "slot_unknown",
59
+ "tool_key_mismatch",
60
+ "tool_name_empty",
61
+ "tool_name_not_namespaced",
62
+ "tool_name_taken"
86
63
  ]);
87
- var isRecord = (value) => typeof value === "object" && value !== null;
88
- var printed = (value) => {
89
- if (typeof value === "string") {
90
- return value;
91
- }
92
- try {
93
- return String(value);
94
- } catch {
95
- return typeof value;
96
- }
64
+ const isRecord = (value) => typeof value === "object" && value !== null;
65
+ const printed = (value) => {
66
+ if (typeof value === "string") return value;
67
+ try {
68
+ return String(value);
69
+ } catch {
70
+ return typeof value;
71
+ }
97
72
  };
98
- var validateStudioPlugin = (plugin, scope) => {
99
- const declaration = plugin;
100
- const members = isRecord(declaration) ? declaration : {};
101
- const defects = [];
102
- const pluginId = typeof members.id === "string" ? members.id : "";
103
- const defect = (code, subject) => {
104
- defects.push(subject === void 0 ? { code, pluginId } : { code, pluginId, subject });
105
- };
106
- if (!studioPluginIdPattern.test(pluginId)) {
107
- defect("plugin_id_invalid");
108
- }
109
- const vendor = pluginId.split(".")[0];
110
- if (RESERVED_PLUGIN_NAMESPACES.some((reserved) => reserved === vendor)) {
111
- defect("plugin_id_reserved");
112
- }
113
- if (scope.installed.has(pluginId)) {
114
- defect("plugin_id_taken");
115
- }
116
- const seen = /* @__PURE__ */ new Set();
117
- const declared = members.contributions ?? [];
118
- const contributions = Array.isArray(declared) ? declared : [declared];
119
- for (const entry of contributions) {
120
- const contribution = isRecord(entry) ? entry : {};
121
- const subject = printed(contribution.id);
122
- if (!studioPluginSlotSchema.safeParse(contribution.slot).success) {
123
- defect("slot_unknown", printed(contribution.slot));
124
- }
125
- if (typeof contribution.id !== "string" || !studioContributionIdPattern.test(contribution.id)) {
126
- defect("contribution_id_invalid", subject);
127
- } else if (seen.has(contribution.id)) {
128
- defect("contribution_id_duplicate", subject);
129
- }
130
- if (typeof contribution.id === "string") {
131
- seen.add(contribution.id);
132
- }
133
- const hasView = contribution.view !== void 0 && contribution.view !== null;
134
- const hasAction = typeof contribution.label === "string" && contribution.label.trim() !== "" && typeof contribution.run === "function";
135
- if (!hasView && !hasAction) {
136
- defect("contribution_empty", subject);
137
- }
138
- }
139
- if (members.tools !== void 0 && members.tools !== null && !isRecord(members.tools)) {
140
- defect("tool_key_mismatch", printed(members.tools));
141
- }
142
- for (const [key, tool] of Object.entries(isRecord(members.tools) ? members.tools : {})) {
143
- const name = isRecord(tool) ? tool.name : void 0;
144
- if (typeof name !== "string") {
145
- defect("tool_key_mismatch", key);
146
- continue;
147
- }
148
- if (key !== name) {
149
- defect("tool_key_mismatch", key);
150
- }
151
- if (!isStudioPluginToolName(pluginId, name)) {
152
- defect("tool_name_not_namespaced", name);
153
- } else if (name === studioPluginToolPrefix(pluginId)) {
154
- defect("tool_name_empty", name);
155
- }
156
- if (scope.tools.has(name)) {
157
- defect("tool_name_taken", name);
158
- }
159
- }
160
- return defects;
73
+ const validateStudioPlugin = (plugin, scope) => {
74
+ const declaration = plugin;
75
+ const members = isRecord(declaration) ? declaration : {};
76
+ const defects = [];
77
+ const pluginId = typeof members.id === "string" ? members.id : "";
78
+ const defect = (code, subject) => {
79
+ defects.push(subject === void 0 ? {
80
+ code,
81
+ pluginId
82
+ } : {
83
+ code,
84
+ pluginId,
85
+ subject
86
+ });
87
+ };
88
+ if (!studioPluginIdPattern.test(pluginId)) defect("plugin_id_invalid");
89
+ const vendor = pluginId.split(".")[0];
90
+ if (RESERVED_PLUGIN_NAMESPACES.some((reserved) => reserved === vendor)) defect("plugin_id_reserved");
91
+ if (scope.installed.has(pluginId)) defect("plugin_id_taken");
92
+ const seen = /* @__PURE__ */ new Set();
93
+ const declared = members.contributions ?? [];
94
+ const contributions = Array.isArray(declared) ? declared : [declared];
95
+ for (const entry of contributions) {
96
+ const contribution = isRecord(entry) ? entry : {};
97
+ const subject = printed(contribution.id);
98
+ if (!studioPluginSlotSchema.safeParse(contribution.slot).success) defect("slot_unknown", printed(contribution.slot));
99
+ if (typeof contribution.id !== "string" || !studioContributionIdPattern.test(contribution.id)) defect("contribution_id_invalid", subject);
100
+ else if (seen.has(contribution.id)) defect("contribution_id_duplicate", subject);
101
+ if (typeof contribution.id === "string") seen.add(contribution.id);
102
+ const hasView = contribution.view !== void 0 && contribution.view !== null;
103
+ const hasAction = typeof contribution.label === "string" && contribution.label.trim() !== "" && typeof contribution.run === "function";
104
+ if (!hasView && !hasAction) defect("contribution_empty", subject);
105
+ }
106
+ if (members.tools !== void 0 && members.tools !== null && !isRecord(members.tools)) defect("tool_key_mismatch", printed(members.tools));
107
+ for (const [key, tool] of Object.entries(isRecord(members.tools) ? members.tools : {})) {
108
+ const name = isRecord(tool) ? tool.name : void 0;
109
+ if (typeof name !== "string") {
110
+ defect("tool_key_mismatch", key);
111
+ continue;
112
+ }
113
+ if (key !== name) defect("tool_key_mismatch", key);
114
+ if (!isStudioPluginToolName(pluginId, name)) defect("tool_name_not_namespaced", name);
115
+ else if (name === studioPluginToolPrefix(pluginId)) defect("tool_name_empty", name);
116
+ if (scope.tools.has(name)) defect("tool_name_taken", name);
117
+ }
118
+ return defects;
161
119
  };
162
-
163
- // src/plugins/engines/studioPlugin.ts
164
- var NO_CONTRIBUTIONS = Object.freeze([]);
165
- var emptyIndex = () => ({
166
- "itinerary.menu": NO_CONTRIBUTIONS,
167
- "map.contextMenu": NO_CONTRIBUTIONS,
168
- "map.controls": NO_CONTRIBUTIONS,
169
- "profile.header": NO_CONTRIBUTIONS,
170
- "profile.plot": NO_CONTRIBUTIONS,
171
- "segment.menu": NO_CONTRIBUTIONS,
172
- "waypoint.menu": NO_CONTRIBUTIONS,
173
- "zone.menu": NO_CONTRIBUTIONS
120
+ const NO_CONTRIBUTIONS = Object.freeze([]);
121
+ const emptyIndex = () => ({
122
+ "itinerary.menu": NO_CONTRIBUTIONS,
123
+ "map.contextMenu": NO_CONTRIBUTIONS,
124
+ "map.controls": NO_CONTRIBUTIONS,
125
+ "profile.header": NO_CONTRIBUTIONS,
126
+ "profile.plot": NO_CONTRIBUTIONS,
127
+ "segment.menu": NO_CONTRIBUTIONS,
128
+ "waypoint.menu": NO_CONTRIBUTIONS,
129
+ "zone.menu": NO_CONTRIBUTIONS
174
130
  });
175
- var refusalsFor = (onRefused) => {
176
- if (onRefused !== void 0) {
177
- return { reporter: onRefused, settle: () => void 0 };
178
- }
179
- let first;
180
- return {
181
- reporter: (error) => {
182
- first ??= { error };
183
- },
184
- settle: () => {
185
- if (first !== void 0) {
186
- throw first.error;
187
- }
188
- }
189
- };
131
+ const refusalsFor = (onRefused) => {
132
+ if (onRefused !== void 0) return {
133
+ reporter: onRefused,
134
+ settle: () => void 0
135
+ };
136
+ let first;
137
+ return {
138
+ reporter: (error) => {
139
+ first ??= { error };
140
+ },
141
+ settle: () => {
142
+ if (first !== void 0) throw first.error;
143
+ }
144
+ };
190
145
  };
191
- var declaredId = (plugin) => typeof plugin === "object" && plugin !== null && "id" in plugin && typeof plugin.id === "string" ? plugin.id : void 0;
192
- var noRefusalsTold = () => ({ byId: /* @__PURE__ */ new Map(), unnamed: /* @__PURE__ */ new Map() });
193
- var unnamedSubject = (member) => {
194
- if (typeof member === "function") {
195
- return Function;
196
- }
197
- return typeof member === "object" && member !== null ? Object : member;
146
+ const declaredId = (plugin) => typeof plugin === "object" && plugin !== null && "id" in plugin && typeof plugin.id === "string" ? plugin.id : void 0;
147
+ const noRefusalsTold = () => ({
148
+ byId: /* @__PURE__ */ new Map(),
149
+ unnamed: /* @__PURE__ */ new Map()
150
+ });
151
+ const unnamedSubject = (member) => {
152
+ if (typeof member === "function") return Function;
153
+ return typeof member === "object" && member !== null ? Object : member;
198
154
  };
199
- var refusalWords = (error) => {
200
- if (error instanceof Error) {
201
- return `${error.name}: ${error.message}`;
202
- }
203
- try {
204
- return String(error);
205
- } catch {
206
- return "";
207
- }
155
+ const refusalWords = (error) => {
156
+ if (error instanceof Error) return `${error.name}: ${error.message}`;
157
+ try {
158
+ return String(error);
159
+ } catch {
160
+ return "";
161
+ }
208
162
  };
209
- var noteRefusal = (told, before, member, error) => {
210
- const id = declaredId(member);
211
- const words = refusalWords(error);
212
- if (id === void 0) {
213
- const subject = unnamedSubject(member);
214
- const stated = told.unnamed.get(subject) ?? /* @__PURE__ */ new Set();
215
- told.unnamed.set(subject, stated.add(words));
216
- return before.unnamed.get(subject)?.has(words) === true;
217
- }
218
- const held = before.byId.get(id);
219
- told.byId.set(id, words);
220
- return held === words || held === null;
163
+ const noteRefusal = (told, before, member, error) => {
164
+ const id = declaredId(member);
165
+ const words = refusalWords(error);
166
+ if (id === void 0) {
167
+ const subject = unnamedSubject(member);
168
+ const stated = told.unnamed.get(subject) ?? /* @__PURE__ */ new Set();
169
+ told.unnamed.set(subject, stated.add(words));
170
+ return before.unnamed.get(subject)?.has(words) === true;
171
+ }
172
+ const held = before.byId.get(id);
173
+ told.byId.set(id, words);
174
+ return held === words || held === null;
221
175
  };
222
- var declaredListReporter = (onRefused, told, before, surface) => (error, plugin) => {
223
- const member = plugin;
224
- if (typeof member !== "object" || member === null) {
225
- if (surface !== void 0 && !noteRefusal(told, before, member, error)) {
226
- surface(error);
227
- }
228
- return;
229
- }
230
- if (!noteRefusal(told, before, member, error)) {
231
- onRefused(error, plugin);
232
- }
176
+ const declaredListReporter = (onRefused, told, before, surface) => (error, plugin) => {
177
+ const member = plugin;
178
+ if (typeof member !== "object" || member === null) {
179
+ if (surface !== void 0 && !noteRefusal(told, before, member, error)) surface(error);
180
+ return;
181
+ }
182
+ if (!noteRefusal(told, before, member, error)) onRefused(error, plugin);
233
183
  };
234
- var isStillKept = (held, listed) => listed !== void 0 && (!held.listedAsGiven || listed === held.tool);
184
+ const isStillKept = (held, listed) => listed !== void 0 && (!held.listedAsGiven || listed === held.tool);
235
185
  var StudioPluginEngine = class {
236
- listeners = /* @__PURE__ */ new Set();
237
- observers = /* @__PURE__ */ new Set();
238
- /** The installed declarations, by id, in install order. */
239
- plugins = /* @__PURE__ */ new Map();
240
- /** Each plugin's resolved entries, by id, in declaration order. */
241
- entries = /* @__PURE__ */ new Map();
242
- /**
243
- * Every tool name THIS registry owns, mapped to the plugin that brought it.
244
- *
245
- * Ownership rather than registration state, which is the difference that matters while there is
246
- * no sink: {@link attachTools} is allowed to arrive late, and the names a plugin claimed have to
247
- * be known before then, both to re-register them when a sink appears and to refuse a second
248
- * plugin claiming the same one in the meantime.
249
- */
250
- toolNames = /* @__PURE__ */ new Map();
251
- /**
252
- * The tools this registry put on the attached sink, by name: the ones it registered there and
253
- * the ones it adopted where the sink had kept them.
254
- *
255
- * It is what {@link withdraw} reads before it asks the sink for a name back. A name that is
256
- * not here was never this registry's on that sink, whoever holds it there, and is never asked
257
- * for. Empty while no sink is attached.
258
- */
259
- placed = /* @__PURE__ */ new Map();
260
- /**
261
- * The names each sink would not release, by sink: each with the plugin that brought it and
262
- * the tool that plugin declared.
263
- *
264
- * A sink answers `unregister` with false for a name it keeps. The tool is then on the sink
265
- * with no installed plugin behind it, and this map is what lets the plugin's own declaration
266
- * meet that sink again, by a new install or by a new attach: the name reads as the plugin's
267
- * and the held tool is adopted where it stands. An entry is a fact about its sink and stands
268
- * while another sink is attached, so a registry that returns to a sink it left finds its
269
- * tools there. Keyed weakly, so a sink that is gone keeps nothing alive.
270
- *
271
- * An entry is what the registry remembers, and the sink decides: its owner may take a kept
272
- * name off it at any time. So a kept name is met again only while the sink still lists it,
273
- * which {@link register} reads before it adopts, and an entry the sink no longer lists is
274
- * forgotten there.
275
- */
276
- unreleased = /* @__PURE__ */ new WeakMap();
277
- /**
278
- * The ids a DECLARED list owns, which is the only thing {@link sync} may take back.
279
- *
280
- * The two install paths compose rather than competing, and this set is what makes that true. A
281
- * host's `install` array is one authority and a settings screen calling `install()` is another;
282
- * a reconciliation that dropped every id absent from its own list would silently uninstall the
283
- * other's the moment the array's identity changed. Seeded by the constructor's `install`,
284
- * because that is the same declared list the host then syncs.
285
- */
286
- declared = /* @__PURE__ */ new Set();
287
- /**
288
- * What the declared list read last was told of, which holds each refusal to one report while
289
- * the list goes on stating it. See {@link declaredListReporter}.
290
- */
291
- told = noRefusalsTold();
292
- index = emptyIndex();
293
- sequence = 0;
294
- revision = 0;
295
- /** The installed declarations as {@link installed} hands them back, or null when stale. */
296
- snapshot = null;
297
- sink;
298
- constructor(options = {}) {
299
- this.sink = options.tools;
300
- const told = noRefusalsTold();
301
- const onRefused = options.onRefused === void 0 ? void 0 : declaredListReporter(options.onRefused, told, this.told, void 0);
302
- try {
303
- for (const plugin of options.install ?? []) {
304
- if (this.take(plugin, onRefused)) {
305
- this.declared.add(plugin.id);
306
- }
307
- }
308
- this.told = told;
309
- } catch (error) {
310
- this.dispose();
311
- throw error;
312
- }
313
- }
314
- /**
315
- * at returns the installed contributions for one slot, sorted, UNGATED.
316
- *
317
- * The same array between mutations, as the class docblock states. Cast-free, which is why the
318
- * index is a mapped-type record rather than a `Map`: the one member every render touches is the
319
- * one that should not need a cast.
320
- */
321
- at(slot) {
322
- return this.index[slot];
323
- }
324
- /**
325
- * installed returns the declarations currently installed, in install order.
326
- *
327
- * Materialised once per change and handed back by reference until the next one, for the reason
328
- * this file's opening comment gives about `at`: a getter shaped like a snapshot will be read as
329
- * one (`useSyncExternalStore(engine.subscribe, engine.installed)` is the obvious thing for
330
- * a consumer holding the engine to write), and a fresh array per call is an infinite render
331
- * loop. An arrow PROPERTY for the same reason {@link subscribe} is one: it is passed detached.
332
- */
333
- installed = () => {
334
- this.snapshot ??= Object.freeze([...this.plugins.values()]);
335
- return this.snapshot;
336
- };
337
- /**
338
- * version is a counter that changes whenever any slot does.
339
- *
340
- * The scalar a `useSyncExternalStore` reads, so the binding subscribes once for the whole
341
- * engine rather than once per slot, and the per-slot arrays stay plain reads inside the
342
- * memo that filters them. An arrow PROPERTY for the same reason {@link subscribe} is one.
343
- */
344
- version = () => this.revision;
345
- /**
346
- * subscribe registers a listener called after any change, and returns the detach.
347
- *
348
- * An arrow PROPERTY rather than a method, and this is not style: `useSyncExternalStore` calls
349
- * it detached from the object (`useSyncExternalStore(engine.subscribe, …)`), so a method
350
- * would arrive with `this` unbound and throw on the first render that reads it.
351
- */
352
- subscribe = (listener) => {
353
- this.listeners.add(listener);
354
- return () => {
355
- this.listeners.delete(listener);
356
- };
357
- };
358
- /** observe registers a per-`run` telemetry observer and returns the detach. */
359
- observe(observer) {
360
- this.observers.add(observer);
361
- return () => {
362
- this.observers.delete(observer);
363
- };
364
- }
365
- /**
366
- * attachTools points the engine at a tool sink, moving every installed plugin's tools onto it.
367
- *
368
- * The sink is a LIFETIME rather than a construction fact, and this is the member that says so. An
369
- * engine outlives the bus a binding built for it (a React host rebuilds the bus whenever its
370
- * handlers, its grants or its confirm gate move), and an engine holding the one it was
371
- * constructed with would keep registering a plugin's verbs onto a bus nothing dispatches
372
- * through. It is also the only way an engine a CONSUMER constructed, and handed to the studio,
373
- * ever reaches a bus at all.
374
- *
375
- * It is total in both directions: the outgoing sink gives every name back, the incoming one
376
- * receives every installed plugin's tools, and `null` detaches. A sink that REFUSES a plugin's
377
- * tools (a name it already holds) costs that plugin its install, reported through the refusal
378
- * reporter, because a plugin whose contributions are on the menu and whose verbs are on no bus
379
- * is half-installed in the one way nothing downstream can see.
380
- *
381
- * A detach moves tools and no ownership. The names stay their plugins' while no sink is
382
- * attached, so a second plugin claiming one is refused when it is installed, and the tools go
383
- * onto the sink that arrives next.
384
- *
385
- * With no reporter the first refusal is thrown, and only once every other plugin's tools are
386
- * on the incoming sink and the subscribers have heard: a throw never leaves a later plugin on
387
- * the menu with its verbs on no sink.
388
- *
389
- * With a reporter, a refused plugin a declared list states is told of here once: the
390
- * reconciliation after this attach reports its refusal to nobody, in whatever words it reads
391
- * there. See {@link StudioPluginRefusalReporter}.
392
- *
393
- * It does not notify on its own: moving tools between buses changes no slot. A refusal does
394
- * change one, and that notifies.
395
- *
396
- * `onRefused` is a parameter here rather than a construction option, as it is on {@link sync},
397
- * and deliberately: a reporter held as a FIELD would put `TView` in an input position on this
398
- * class, which is what keeps `StudioPluginEngine<never>` (the engine a bare
399
- * `new StudioPluginEngine()` builds) assignable to the bound one a React host takes.
400
- */
401
- attachTools(sink, onRefused) {
402
- const outgoing = this.sink;
403
- if (outgoing !== void 0) {
404
- for (const [name, owner] of [...this.toolNames]) {
405
- this.withdraw(name, owner, outgoing);
406
- }
407
- }
408
- this.sink = sink ?? void 0;
409
- if (sink === null) {
410
- return;
411
- }
412
- const refusals = refusalsFor(onRefused);
413
- let dropped = false;
414
- for (const plugin of [...this.plugins.values()]) {
415
- try {
416
- this.register(plugin, sink);
417
- } catch (error) {
418
- const stated = this.declared.has(plugin.id);
419
- this.drop(plugin.id);
420
- dropped = true;
421
- this.report(error, plugin, refusals.reporter);
422
- if (onRefused !== void 0 && stated) {
423
- this.told.byId.set(plugin.id, null);
424
- }
425
- }
426
- }
427
- if (dropped) {
428
- this.notify();
429
- }
430
- refusals.settle();
431
- }
432
- /**
433
- * install validates a plugin, registers its tools and indexes its contributions, or refuses
434
- * the whole thing.
435
- *
436
- * It throws a {@link StudioPluginError} carrying EVERY defect, because an install a host asked
437
- * for and did not get has to be loud: a plugin that silently failed to install is a menu item
438
- * that is missing, which reads as the studio being broken rather than as the plugin being
439
- * malformed. A sink that refuses one of the plugin's tools throws ITS OWN error through here
440
- * unchanged, after the rollback, so a caller catching this catches both kinds.
441
- *
442
- * A value that is no declaration at all, `null` off a manifest for one, is refused the same
443
- * way: a {@link StudioPluginError} whose defect says it states no id.
444
- *
445
- * What it installs is never reconciled away: {@link sync} owns the ids a DECLARED list brought,
446
- * and this is the other path. A settings screen installing on demand and a host declaring an
447
- * array compose rather than competing, until the same id appears in the declared list, which
448
- * takes ownership of it.
449
- *
450
- * @throws StudioPluginError carrying every defect of a declaration the validation refuses.
451
- * @throws whatever the tool sink throws for a tool it refuses, after the rollback.
452
- */
453
- install(plugin) {
454
- this.adopt(plugin);
455
- this.notify();
456
- }
457
- /**
458
- * uninstall removes a plugin and everything it brought, reporting whether it was there.
459
- *
460
- * It takes back only the tool names THIS engine registered for THIS plugin (tracked as they
461
- * are registered rather than recomputed from the declaration), which is what guarantees an
462
- * uninstall can never take a `studio.*` verb, or another plugin's, down with it.
463
- */
464
- uninstall(pluginId) {
465
- if (!this.drop(pluginId)) {
466
- return false;
467
- }
468
- this.notify();
469
- return true;
470
- }
471
- /**
472
- * sync reconciles the installed set against a declared list, and notifies at most once.
473
- *
474
- * It reconciles by ID for install and uninstall, and ADDITIONALLY replaces a stored
475
- * declaration when the plugin's object reference changed: rebuilding the touched slots, and
476
- * re-registering bus tools only when the tool-name list actually differs.
477
- *
478
- * Replacing on reference is the one place this departs from a pure by-id reconciliation, and
479
- * the reason is a real trap: a host that changes language and passes new labels under the same
480
- * ids would otherwise see nothing change. It is safe HERE because the notification flows
481
- * strictly DOWN (every subscriber is a menu below the host, and a menu re-rendering never
482
- * re-renders the host), so there is no cycle to fall into.
483
- *
484
- * What it costs is a host who writes the array inline: the menus beneath them re-render
485
- * whenever the host does. Hoist the declarations to module scope, which is the natural way to
486
- * write them, and nothing churns.
487
- *
488
- * **It removes only what a DECLARED list installed.** An id that arrived through
489
- * {@link install} (a settings screen, a marketplace loading one on demand) is another
490
- * authority's, and a reconciliation that dropped it would make the two paths compete for the
491
- * engine rather than compose in it. A declaration naming that id takes ownership of it from
492
- * then on.
493
- *
494
- * `onRefused` decides what a malformed declaration costs. Supplied, it is reported and skipped
495
- * and every other declaration still lands; omitted, the first refusal is thrown once every
496
- * declaration that could be applied has been and the subscribers have heard. A binding
497
- * reconciling inside a render tree passes one: see {@link StudioPluginRefusalReporter}.
498
- *
499
- * A member of the list that is no object is one more malformed declaration: refused where it
500
- * stands, with the defect of a declaration that states no id. With no reporter it is thrown as
501
- * any refusal is. With one it is handed to nobody, since a reporter is handed a declaration:
502
- * its refusal is surfaced on a microtask. Subscribers hear of what the list applied whatever
503
- * leaves this call.
504
- *
505
- * A refusal is reported, or surfaced, once while the list goes on stating it, the seed's list
506
- * included and a list written inline as well: see {@link StudioPluginRefusalReporter}. With no
507
- * reporter every call throws its first refusal, since each call is one its caller asked for.
508
- */
509
- sync(plugins, onRefused) {
510
- const next = /* @__PURE__ */ new Map();
511
- for (const plugin of plugins) {
512
- next.set(declaredId(plugin) ?? {}, plugin);
513
- }
514
- const told = noRefusalsTold();
515
- const refusals = refusalsFor(
516
- onRefused === void 0 ? void 0 : declaredListReporter(onRefused, told, this.told, surfaceFault)
517
- );
518
- let changed = false;
519
- try {
520
- for (const id of [...this.declared]) {
521
- if (!next.has(id)) {
522
- this.drop(id);
523
- changed = true;
524
- }
525
- }
526
- for (const [id, plugin] of next) {
527
- if (typeof id !== "string") {
528
- this.take(plugin, refusals.reporter);
529
- continue;
530
- }
531
- if (this.reconcile(id, plugin, refusals.reporter)) {
532
- changed = true;
533
- }
534
- }
535
- } finally {
536
- this.told = told;
537
- if (changed) {
538
- this.notify();
539
- }
540
- }
541
- refusals.settle();
542
- }
543
- /**
544
- * reconcile brings one declaration of a declared list in under its id: installed where the id
545
- * is new, replaced where its reference changed, and left where it is the one installed.
546
- *
547
- * @returns Whether a slot may have changed: a plugin was installed, replaced, or lost to a
548
- * sink that refused its replacement.
549
- */
550
- reconcile(id, plugin, onRefused) {
551
- const current = this.plugins.get(id);
552
- if (current === plugin) {
553
- this.declared.add(id);
554
- return false;
555
- }
556
- if (current === void 0) {
557
- if (!this.take(plugin, onRefused)) {
558
- return false;
559
- }
560
- this.declared.add(id);
561
- return true;
562
- }
563
- let defects;
564
- try {
565
- defects = validateStudioPlugin(plugin, this.scope(id, true));
566
- } catch (error) {
567
- this.report(error, plugin, onRefused);
568
- return false;
569
- }
570
- if (defects.length > 0) {
571
- this.report(new StudioPluginError(defects), plugin, onRefused);
572
- return false;
573
- }
574
- this.drop(id);
575
- if (this.take(plugin, onRefused)) {
576
- this.declared.add(id);
577
- }
578
- return true;
579
- }
580
- /**
581
- * run invokes a contribution's verb and reports how it ended. It ALWAYS resolves.
582
- *
583
- * It re-checks two things the caller cannot, because a menu can outlive both: that the entry is
584
- * still installed (a plugin uninstalled, or its declaration replaced, while the dropdown was
585
- * open) and that its gate still passes (an entitlement that lapsed mid-session). Neither is a
586
- * throw: a stale click is a no-op with a reason, not a crash.
587
- *
588
- * `onError` is how the thrown value reaches a caller that has to report it. The outcome alone
589
- * cannot carry one, and an observer is registered per ENGINE rather than per call, so a
590
- * binding wanting to hand the failure to a host seam beside the contribution it came from
591
- * passes this. It is called at most once, before the promise resolves. An `onError` that itself
592
- * throws leaves the outcome `threw`, and its fault is surfaced on a microtask.
593
- */
594
- async run(entry, ctx, target, onError) {
595
- const start = performance.now();
596
- const report = (outcome, error) => {
597
- this.emit({
598
- ...error === void 0 ? {} : { error },
599
- latencyMs: performance.now() - start,
600
- outcome,
601
- pluginId: entry.pluginId,
602
- qualifiedId: entry.qualifiedId,
603
- slot: entry.slot
604
- });
605
- return outcome;
606
- };
607
- if (!this.index[entry.slot].some((live) => live === entry)) {
608
- return report("unknown");
609
- }
610
- if (!isStudioContributionAvailable(entry, ctx)) {
611
- return report("gated");
612
- }
613
- const verb = entry.run;
614
- if (verb === void 0) {
615
- return report("inert");
616
- }
617
- try {
618
- await verb(ctx, target);
619
- } catch (error) {
620
- try {
621
- onError?.(error);
622
- } catch (fault) {
623
- surfaceFault(fault);
624
- }
625
- return report("threw", error);
626
- }
627
- return report("ran");
628
- }
629
- /**
630
- * dispose uninstalls everything and drops every listener and observer.
631
- *
632
- * It leaves an EMPTY engine rather than a poisoned one (installing into it afterwards works),
633
- * because the alternative breaks React's StrictMode, where an effect's cleanup runs between
634
- * two runs of the effect itself.
635
- *
636
- * An empty engine was told of nothing: a list declared after it is told of its refusals as a
637
- * list stated for the first time is.
638
- */
639
- dispose() {
640
- const had = this.plugins.size > 0;
641
- for (const id of [...this.plugins.keys()]) {
642
- this.drop(id);
643
- }
644
- this.told = noRefusalsTold();
645
- if (had) {
646
- this.notify();
647
- }
648
- this.listeners.clear();
649
- this.observers.clear();
650
- }
651
- /**
652
- * adopt is install without the notification: validate, register with rollback, then index.
653
- *
654
- * The order is the atomicity. Validation reads and changes nothing; tool registration is the
655
- * only step that can fail, and it unwinds its own partial work; indexing is pure mutation of
656
- * state this object owns and cannot throw. So a refused install leaves the bus and every slot
657
- * exactly as they were.
658
- *
659
- * A sink that keeps a name it is asked for is the one exception, and {@link register} states
660
- * what becomes of that name.
661
- */
662
- adopt(plugin) {
663
- const defects = validateStudioPlugin(plugin, this.scope(declaredId(plugin) ?? "", false));
664
- if (defects.length > 0) {
665
- throw new StudioPluginError(defects);
666
- }
667
- const sink = this.sink;
668
- const declaredTools = Object.values(plugin.tools ?? {}).map((tool) => tool.name);
669
- const registered = sink === void 0 ? declaredTools : this.register(plugin, sink);
670
- for (const name of registered) {
671
- this.toolNames.set(name, plugin.id);
672
- }
673
- this.plugins.set(plugin.id, plugin);
674
- this.snapshot = null;
675
- const touched = /* @__PURE__ */ new Set();
676
- const resolved = (plugin.contributions ?? []).map((contribution) => {
677
- touched.add(contribution.slot);
678
- return {
679
- ...contribution,
680
- pluginId: plugin.id,
681
- qualifiedId: qualifyStudioContributionId(plugin.id, contribution.id),
682
- sequence: this.sequence++
683
- };
684
- });
685
- this.entries.set(plugin.id, resolved);
686
- this.rebuild(touched);
687
- }
688
- /**
689
- * register puts one plugin's tools on a sink, unwinding its own partial work if one is refused.
690
- *
691
- * The only step of an adoption that can fail, which is why it is the only one with a rollback
692
- * (see {@link install}'s note on atomicity). `instanceof Error` here is the narrow question "is
693
- * this already a throwable with a message", not the class-identity check `isStudioPluginError`
694
- * exists to avoid: the value is the sink's, and wrapping one that is already an error would
695
- * bury the bus's own message one `cause` deeper.
696
- *
697
- * The rollback asks the sink for each name back through {@link withdraw}, as an uninstall
698
- * does. A name the sink keeps is remembered as the plugin's own, so the declaration put right
699
- * meets its tool where the refusal left it.
700
- *
701
- * A name the sink kept from the plugin's earlier install ({@link unreleased}) is adopted
702
- * where it stands, and only while the sink still lists it: the sink is read once, when the
703
- * first such name is met. A kept name the sink does not list then is forgotten and its tool is
704
- * registered as any other. So is a kept name under which the sink lists another tool, where
705
- * the sink lists what it is given ({@link isStillKept}): its owner registered that tool since,
706
- * the sink is offered the plugin's and answers for the name itself. A sink that throws from
707
- * that read refuses the plugin, as one that throws from `register` does.
708
- */
709
- register(plugin, sink) {
710
- const kept = this.unreleased.get(sink);
711
- const registered = [];
712
- const adopted = [];
713
- let listed;
714
- try {
715
- for (const tool of Object.values(plugin.tools ?? {})) {
716
- const held = kept?.get(tool.name);
717
- if (held?.pluginId === plugin.id) {
718
- listed ??= new Map(sink.registered().map((entry) => [entry.name, entry]));
719
- if (isStillKept(held, listed.get(tool.name))) {
720
- if (held.tool !== tool) {
721
- throw new MountayaElementsError(
722
- `plugin ${plugin.id} cannot register ${tool.name}: the tool sink kept that name from an earlier install and would not release it. Install the declaration that registered it, or stop reserving the plugin's vendor segment on the sink.`
723
- );
724
- }
725
- adopted.push(held);
726
- continue;
727
- }
728
- kept?.delete(tool.name);
729
- }
730
- sink.register(tool);
731
- this.placed.set(tool.name, tool);
732
- registered.push(tool.name);
733
- }
734
- } catch (error) {
735
- for (const name of registered) {
736
- this.withdraw(name, plugin.id, sink);
737
- }
738
- throw error instanceof Error ? error : new MountayaElementsError(`plugin ${plugin.id} failed to register a tool`, {
739
- cause: error
740
- });
741
- }
742
- for (const { tool } of adopted) {
743
- this.placed.set(tool.name, tool);
744
- kept?.delete(tool.name);
745
- }
746
- return [...adopted.map(({ tool }) => tool.name), ...registered];
747
- }
748
- /**
749
- * take is {@link adopt} with the refusal routed rather than thrown. Reports whether it landed.
750
- *
751
- * The one place the two postures meet: with a reporter a refusal is one plugin's problem, and
752
- * without one it is the caller's. Everything above that wants "apply what you can" goes through
753
- * here, and the atomicity `adopt` guarantees is untouched either way.
754
- */
755
- take(plugin, onRefused) {
756
- try {
757
- this.adopt(plugin);
758
- } catch (error) {
759
- this.report(error, plugin, onRefused);
760
- return false;
761
- }
762
- return true;
763
- }
764
- /** report hands a refusal to the reporter, or rethrows it when there is none. */
765
- report(error, plugin, onRefused) {
766
- if (onRefused === void 0) {
767
- throw error;
768
- }
769
- try {
770
- onRefused(error, plugin);
771
- } catch (fault) {
772
- surfaceFault(fault);
773
- }
774
- }
775
- /** drop is uninstall without the notification. Reports whether the plugin was there. */
776
- drop(pluginId) {
777
- this.declared.delete(pluginId);
778
- if (!this.plugins.has(pluginId)) {
779
- return false;
780
- }
781
- const touched = new Set(
782
- (this.entries.get(pluginId) ?? []).map((entry) => entry.slot)
783
- );
784
- this.plugins.delete(pluginId);
785
- this.entries.delete(pluginId);
786
- this.snapshot = null;
787
- this.rebuild(touched);
788
- for (const [name, owner] of [...this.toolNames]) {
789
- if (owner === pluginId) {
790
- this.toolNames.delete(name);
791
- if (this.sink !== void 0) {
792
- this.withdraw(name, pluginId, this.sink);
793
- }
794
- }
795
- }
796
- return true;
797
- }
798
- /**
799
- * withdraw asks a sink for one name back, and remembers a name the sink would not give up.
800
- *
801
- * Only a name this registry put there ({@link placed}) is asked for: a name the sink holds
802
- * for somebody else was never this registry's to take back.
803
- *
804
- * `unregister` answers false for a name the sink never held and for one it refuses to release,
805
- * so the sink is asked whether it still lists the name. A tool left there stays in service
806
- * with no installed plugin behind it, and is remembered with the tool this registry handed
807
- * over: see {@link unreleased}. The sink is read by name, since it may hand back another object
808
- * than it was given.
809
- *
810
- * A fault the sink throws here is surfaced on a microtask and leaves through no caller: an
811
- * uninstall, a reconciliation and a move between sinks each finish what they were doing.
812
- */
813
- withdraw(name, pluginId, sink) {
814
- const tool = this.placed.get(name);
815
- if (tool === void 0) {
816
- return;
817
- }
818
- this.placed.delete(name);
819
- let listed;
820
- try {
821
- if (sink.unregister(name)) {
822
- return;
823
- }
824
- listed = sink.registered().find((held) => held.name === name);
825
- } catch (fault) {
826
- surfaceFault(fault);
827
- return;
828
- }
829
- if (listed === void 0) {
830
- return;
831
- }
832
- const kept = this.unreleased.get(sink) ?? /* @__PURE__ */ new Map();
833
- kept.set(name, { listedAsGiven: listed === tool, pluginId, tool });
834
- this.unreleased.set(sink, kept);
835
- }
836
- /**
837
- * rebuild re-materialises exactly the slots named, and nothing else.
838
- *
839
- * Only the touched ones, which is what makes "installing a `segment.menu` plugin leaves
840
- * `at('map.controls')` referentially identical" true: the property a memo keyed on a slot's
841
- * array depends on.
842
- */
843
- rebuild(slots) {
844
- for (const slot of slots) {
845
- const found = [];
846
- for (const entries of this.entries.values()) {
847
- for (const entry of entries) {
848
- if (entry.slot === slot) {
849
- found.push(entry);
850
- }
851
- }
852
- }
853
- this.setSlot(
854
- slot,
855
- found.length === 0 ? NO_CONTRIBUTIONS : Object.freeze(sortStudioContributions(found))
856
- );
857
- }
858
- }
859
- /**
860
- * setSlot writes one slot of the index.
861
- *
862
- * The second localized cast, and it is the mapped type's: writing through a key whose type is
863
- * the whole union makes TypeScript demand a value assignable to EVERY member's value type at
864
- * once, which nothing is. Moving the index to a `Map` would trade this cast for one in `at`,
865
- * the wrong side of the trade, since `at` is the member every render touches.
866
- */
867
- setSlot(slot, entries) {
868
- this.index[slot] = entries;
869
- }
870
- /**
871
- * The collision scope a declaration of `pluginId` is validated against: the ids installed, and
872
- * every tool name already taken.
873
- *
874
- * `replacing` takes the installed plugin of that id back out of it: its id and the names it
875
- * brought, including the ones the sink is holding for it. That is what lets a replacement be
876
- * validated while its incumbent is still installed. Without it every re-declaration under an
877
- * unchanged id would read as `plugin_id_taken` plus one `tool_name_taken` per verb.
878
- *
879
- * A name the sink kept from an earlier install of the same id is the plugin's own either way,
880
- * and taken for every other plugin: see {@link unreleased}. It is the plugin's own only while
881
- * what the sink lists under it is still the tool it kept ({@link isStillKept}): a name its
882
- * owner gave another tool since is taken, for this plugin as for any other.
883
- */
884
- scope(pluginId, replacing) {
885
- const own = /* @__PURE__ */ new Set();
886
- const tools = /* @__PURE__ */ new Set();
887
- const kept = this.sink === void 0 ? void 0 : this.unreleased.get(this.sink);
888
- const listed = this.sink?.registered() ?? [];
889
- const listedByName = new Map(listed.map((tool) => [tool.name, tool]));
890
- for (const [name, held] of kept ?? []) {
891
- if (held.pluginId === pluginId && isStillKept(held, listedByName.get(name))) {
892
- own.add(name);
893
- }
894
- }
895
- for (const [name, owner] of this.toolNames) {
896
- if (replacing && owner === pluginId) {
897
- own.add(name);
898
- } else {
899
- tools.add(name);
900
- }
901
- }
902
- for (const tool of listed) {
903
- if (!own.has(tool.name)) {
904
- tools.add(tool.name);
905
- }
906
- }
907
- const installed = new Set(this.plugins.keys());
908
- if (replacing) {
909
- installed.delete(pluginId);
910
- }
911
- return { installed, tools };
912
- }
913
- /**
914
- * notify advances the version FIRST, so a listener reading `at` already sees the new list.
915
- *
916
- * Every listener is told, by the one rule the package's engines share (`notifyListeners`). A
917
- * listener that throws skips no listener after it and never leaves through the `install` or
918
- * `sync` that had already changed the state, which would break, from the outside, the
919
- * atomicity this class guarantees. Its fault is surfaced on a microtask.
920
- */
921
- notify() {
922
- this.revision += 1;
923
- notifyListeners(this.listeners);
924
- }
925
- /** emit reports one run to every observer, by the rule {@link notify} follows. */
926
- emit(event) {
927
- notifyListeners(this.observers, event);
928
- }
186
+ listeners = /* @__PURE__ */ new Set();
187
+ observers = /* @__PURE__ */ new Set();
188
+ plugins = /* @__PURE__ */ new Map();
189
+ entries = /* @__PURE__ */ new Map();
190
+ toolNames = /* @__PURE__ */ new Map();
191
+ placed = /* @__PURE__ */ new Map();
192
+ unreleased = /* @__PURE__ */ new WeakMap();
193
+ declared = /* @__PURE__ */ new Set();
194
+ told = noRefusalsTold();
195
+ index = emptyIndex();
196
+ sequence = 0;
197
+ revision = 0;
198
+ snapshot = null;
199
+ sink;
200
+ constructor(options = {}) {
201
+ this.sink = options.tools;
202
+ const told = noRefusalsTold();
203
+ const onRefused = options.onRefused === void 0 ? void 0 : declaredListReporter(options.onRefused, told, this.told, void 0);
204
+ try {
205
+ for (const plugin of options.install ?? []) if (this.take(plugin, onRefused)) this.declared.add(plugin.id);
206
+ this.told = told;
207
+ } catch (error) {
208
+ this.dispose();
209
+ throw error;
210
+ }
211
+ }
212
+ at(slot) {
213
+ return this.index[slot];
214
+ }
215
+ installed = () => {
216
+ this.snapshot ??= Object.freeze([...this.plugins.values()]);
217
+ return this.snapshot;
218
+ };
219
+ version = () => this.revision;
220
+ subscribe = (listener) => {
221
+ this.listeners.add(listener);
222
+ return () => {
223
+ this.listeners.delete(listener);
224
+ };
225
+ };
226
+ observe(observer) {
227
+ this.observers.add(observer);
228
+ return () => {
229
+ this.observers.delete(observer);
230
+ };
231
+ }
232
+ attachTools(sink, onRefused) {
233
+ const outgoing = this.sink;
234
+ if (outgoing !== void 0) for (const [name, owner] of [...this.toolNames]) this.withdraw(name, owner, outgoing);
235
+ this.sink = sink ?? void 0;
236
+ if (sink === null) return;
237
+ const refusals = refusalsFor(onRefused);
238
+ let dropped = false;
239
+ for (const plugin of [...this.plugins.values()]) try {
240
+ this.register(plugin, sink);
241
+ } catch (error) {
242
+ const stated = this.declared.has(plugin.id);
243
+ this.drop(plugin.id);
244
+ dropped = true;
245
+ this.report(error, plugin, refusals.reporter);
246
+ if (onRefused !== void 0 && stated) this.told.byId.set(plugin.id, null);
247
+ }
248
+ if (dropped) this.notify();
249
+ refusals.settle();
250
+ }
251
+ install(plugin) {
252
+ this.adopt(plugin);
253
+ this.notify();
254
+ }
255
+ uninstall(pluginId) {
256
+ if (!this.drop(pluginId)) return false;
257
+ this.notify();
258
+ return true;
259
+ }
260
+ sync(plugins, onRefused) {
261
+ const next = /* @__PURE__ */ new Map();
262
+ for (const plugin of plugins) next.set(declaredId(plugin) ?? {}, plugin);
263
+ const told = noRefusalsTold();
264
+ const refusals = refusalsFor(onRefused === void 0 ? void 0 : declaredListReporter(onRefused, told, this.told, surfaceFault));
265
+ let changed = false;
266
+ try {
267
+ for (const id of [...this.declared]) if (!next.has(id)) {
268
+ this.drop(id);
269
+ changed = true;
270
+ }
271
+ for (const [id, plugin] of next) {
272
+ if (typeof id !== "string") {
273
+ this.take(plugin, refusals.reporter);
274
+ continue;
275
+ }
276
+ if (this.reconcile(id, plugin, refusals.reporter)) changed = true;
277
+ }
278
+ } finally {
279
+ this.told = told;
280
+ if (changed) this.notify();
281
+ }
282
+ refusals.settle();
283
+ }
284
+ reconcile(id, plugin, onRefused) {
285
+ const current = this.plugins.get(id);
286
+ if (current === plugin) {
287
+ this.declared.add(id);
288
+ return false;
289
+ }
290
+ if (current === void 0) {
291
+ if (!this.take(plugin, onRefused)) return false;
292
+ this.declared.add(id);
293
+ return true;
294
+ }
295
+ let defects;
296
+ try {
297
+ defects = validateStudioPlugin(plugin, this.scope(id, true));
298
+ } catch (error) {
299
+ this.report(error, plugin, onRefused);
300
+ return false;
301
+ }
302
+ if (defects.length > 0) {
303
+ this.report(new StudioPluginError(defects), plugin, onRefused);
304
+ return false;
305
+ }
306
+ this.drop(id);
307
+ if (this.take(plugin, onRefused)) this.declared.add(id);
308
+ return true;
309
+ }
310
+ async run(entry, ctx, target, onError) {
311
+ const start = performance.now();
312
+ const report = (outcome, error) => {
313
+ this.emit({
314
+ ...error === void 0 ? {} : { error },
315
+ latencyMs: performance.now() - start,
316
+ outcome,
317
+ pluginId: entry.pluginId,
318
+ qualifiedId: entry.qualifiedId,
319
+ slot: entry.slot
320
+ });
321
+ return outcome;
322
+ };
323
+ if (!this.index[entry.slot].some((live) => live === entry)) return report("unknown");
324
+ if (!isStudioContributionAvailable(entry, ctx)) return report("gated");
325
+ const verb = entry.run;
326
+ if (verb === void 0) return report("inert");
327
+ try {
328
+ await verb(ctx, target);
329
+ } catch (error) {
330
+ try {
331
+ onError?.(error);
332
+ } catch (fault) {
333
+ surfaceFault(fault);
334
+ }
335
+ return report("threw", error);
336
+ }
337
+ return report("ran");
338
+ }
339
+ dispose() {
340
+ const had = this.plugins.size > 0;
341
+ for (const id of [...this.plugins.keys()]) this.drop(id);
342
+ this.told = noRefusalsTold();
343
+ if (had) this.notify();
344
+ this.listeners.clear();
345
+ this.observers.clear();
346
+ }
347
+ adopt(plugin) {
348
+ const defects = validateStudioPlugin(plugin, this.scope(declaredId(plugin) ?? "", false));
349
+ if (defects.length > 0) throw new StudioPluginError(defects);
350
+ const sink = this.sink;
351
+ const declaredTools = Object.values(plugin.tools ?? {}).map((tool) => tool.name);
352
+ const registered = sink === void 0 ? declaredTools : this.register(plugin, sink);
353
+ for (const name of registered) this.toolNames.set(name, plugin.id);
354
+ this.plugins.set(plugin.id, plugin);
355
+ this.snapshot = null;
356
+ const touched = /* @__PURE__ */ new Set();
357
+ const resolved = (plugin.contributions ?? []).map((contribution) => {
358
+ touched.add(contribution.slot);
359
+ return {
360
+ ...contribution,
361
+ pluginId: plugin.id,
362
+ qualifiedId: qualifyStudioContributionId(plugin.id, contribution.id),
363
+ sequence: this.sequence++
364
+ };
365
+ });
366
+ this.entries.set(plugin.id, resolved);
367
+ this.rebuild(touched);
368
+ }
369
+ register(plugin, sink) {
370
+ const kept = this.unreleased.get(sink);
371
+ const registered = [];
372
+ const adopted = [];
373
+ let listed;
374
+ try {
375
+ for (const tool of Object.values(plugin.tools ?? {})) {
376
+ const held = kept?.get(tool.name);
377
+ if (held?.pluginId === plugin.id) {
378
+ listed ??= new Map(sink.registered().map((entry) => [entry.name, entry]));
379
+ if (isStillKept(held, listed.get(tool.name))) {
380
+ if (held.tool !== tool) throw new MountayaElementsError(`plugin ${plugin.id} cannot register ${tool.name}: the tool sink kept that name from an earlier install and would not release it. Install the declaration that registered it, or stop reserving the plugin's vendor segment on the sink.`);
381
+ adopted.push(held);
382
+ continue;
383
+ }
384
+ kept?.delete(tool.name);
385
+ }
386
+ sink.register(tool);
387
+ this.placed.set(tool.name, tool);
388
+ registered.push(tool.name);
389
+ }
390
+ } catch (error) {
391
+ for (const name of registered) this.withdraw(name, plugin.id, sink);
392
+ throw error instanceof Error ? error : new MountayaElementsError(`plugin ${plugin.id} failed to register a tool`, { cause: error });
393
+ }
394
+ for (const { tool } of adopted) {
395
+ this.placed.set(tool.name, tool);
396
+ kept?.delete(tool.name);
397
+ }
398
+ return [...adopted.map(({ tool }) => tool.name), ...registered];
399
+ }
400
+ take(plugin, onRefused) {
401
+ try {
402
+ this.adopt(plugin);
403
+ } catch (error) {
404
+ this.report(error, plugin, onRefused);
405
+ return false;
406
+ }
407
+ return true;
408
+ }
409
+ report(error, plugin, onRefused) {
410
+ if (onRefused === void 0) throw error;
411
+ try {
412
+ onRefused(error, plugin);
413
+ } catch (fault) {
414
+ surfaceFault(fault);
415
+ }
416
+ }
417
+ drop(pluginId) {
418
+ this.declared.delete(pluginId);
419
+ if (!this.plugins.has(pluginId)) return false;
420
+ const touched = new Set((this.entries.get(pluginId) ?? []).map((entry) => entry.slot));
421
+ this.plugins.delete(pluginId);
422
+ this.entries.delete(pluginId);
423
+ this.snapshot = null;
424
+ this.rebuild(touched);
425
+ for (const [name, owner] of [...this.toolNames]) if (owner === pluginId) {
426
+ this.toolNames.delete(name);
427
+ if (this.sink !== void 0) this.withdraw(name, pluginId, this.sink);
428
+ }
429
+ return true;
430
+ }
431
+ withdraw(name, pluginId, sink) {
432
+ const tool = this.placed.get(name);
433
+ if (tool === void 0) return;
434
+ this.placed.delete(name);
435
+ let listed;
436
+ try {
437
+ if (sink.unregister(name)) return;
438
+ listed = sink.registered().find((held) => held.name === name);
439
+ } catch (fault) {
440
+ surfaceFault(fault);
441
+ return;
442
+ }
443
+ if (listed === void 0) return;
444
+ const kept = this.unreleased.get(sink) ?? /* @__PURE__ */ new Map();
445
+ kept.set(name, {
446
+ listedAsGiven: listed === tool,
447
+ pluginId,
448
+ tool
449
+ });
450
+ this.unreleased.set(sink, kept);
451
+ }
452
+ rebuild(slots) {
453
+ for (const slot of slots) {
454
+ const found = [];
455
+ for (const entries of this.entries.values()) for (const entry of entries) if (entry.slot === slot) found.push(entry);
456
+ this.setSlot(slot, found.length === 0 ? NO_CONTRIBUTIONS : Object.freeze(sortStudioContributions(found)));
457
+ }
458
+ }
459
+ setSlot(slot, entries) {
460
+ this.index[slot] = entries;
461
+ }
462
+ scope(pluginId, replacing) {
463
+ const own = /* @__PURE__ */ new Set();
464
+ const tools = /* @__PURE__ */ new Set();
465
+ const kept = this.sink === void 0 ? void 0 : this.unreleased.get(this.sink);
466
+ const listed = this.sink?.registered() ?? [];
467
+ const listedByName = new Map(listed.map((tool) => [tool.name, tool]));
468
+ for (const [name, held] of kept ?? []) if (held.pluginId === pluginId && isStillKept(held, listedByName.get(name))) own.add(name);
469
+ for (const [name, owner] of this.toolNames) if (replacing && owner === pluginId) own.add(name);
470
+ else tools.add(name);
471
+ for (const tool of listed) if (!own.has(tool.name)) tools.add(tool.name);
472
+ const installed = new Set(this.plugins.keys());
473
+ if (replacing) installed.delete(pluginId);
474
+ return {
475
+ installed,
476
+ tools
477
+ };
478
+ }
479
+ notify() {
480
+ this.revision += 1;
481
+ notifyListeners(this.listeners);
482
+ }
483
+ emit(event) {
484
+ notifyListeners(this.observers, event);
485
+ }
929
486
  };
487
+ export { RESERVED_PLUGIN_NAMESPACES, StudioPluginEngine, StudioPluginError, availableStudioContributions, isStudioContributionAvailable, isStudioPluginError, isStudioPluginToolName, qualifyStudioContributionId, sortStudioContributions, studioContributionIdPattern, studioPluginDefectCodeSchema, studioPluginIdPattern, studioPluginSlotSchema, studioPluginToolPrefix, validateStudioPlugin };
930
488
 
931
- export { StudioPluginEngine, StudioPluginError, availableStudioContributions, isStudioContributionAvailable, isStudioPluginError, isStudioPluginToolName, qualifyStudioContributionId, sortStudioContributions, studioPluginDefectCodeSchema, studioPluginSlotSchema, studioPluginToolPrefix, validateStudioPlugin };
932
- //# sourceMappingURL=index.js.map
933
489
  //# sourceMappingURL=index.js.map