@pstdio/workbench 0.4.0 → 0.6.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 (34) hide show
  1. package/README.md +66 -72
  2. package/dist/composition-resolver-types-CWykPyEK.js +241 -0
  3. package/dist/composition-resolver-types-CWykPyEK.js.map +1 -0
  4. package/dist/extensions.d.ts +359 -43
  5. package/dist/extensions.js +1595 -1044
  6. package/dist/extensions.js.map +1 -1
  7. package/dist/file-renderer-view-zpunbE4I.js +432 -0
  8. package/dist/file-renderer-view-zpunbE4I.js.map +1 -0
  9. package/dist/file-section-navigation-CfYqVObc.js +30 -0
  10. package/dist/file-section-navigation-CfYqVObc.js.map +1 -0
  11. package/dist/index.d.ts +287 -19
  12. package/dist/index.js +2323 -2011
  13. package/dist/index.js.map +1 -1
  14. package/dist/layout-types-DMoZz38-.js.map +1 -1
  15. package/dist/react.d.ts +157 -16
  16. package/dist/react.js +2675 -2736
  17. package/dist/react.js.map +1 -1
  18. package/dist/storage.d.ts +96 -2
  19. package/dist/storage.js +173 -115
  20. package/dist/storage.js.map +1 -1
  21. package/dist/testing.d.ts +146 -14
  22. package/dist/webview-runtime.js +1 -1
  23. package/dist/webview-runtime.js.map +1 -1
  24. package/dist/workbench-built-ins-BtgeB274.js +1171 -0
  25. package/dist/workbench-built-ins-BtgeB274.js.map +1 -0
  26. package/dist/workbench-menu-paths-Bb0ICxeG.js +20 -0
  27. package/dist/workbench-menu-paths-Bb0ICxeG.js.map +1 -0
  28. package/package.json +3 -3
  29. package/dist/context-key-service-W4QEfVdN.js +0 -1031
  30. package/dist/context-key-service-W4QEfVdN.js.map +0 -1
  31. package/dist/file-renderer-view-DrrhYnb_.js +0 -171
  32. package/dist/file-renderer-view-DrrhYnb_.js.map +0 -1
  33. package/dist/workbench-menu-paths-B_QJzcNU.js +0 -12
  34. package/dist/workbench-menu-paths-B_QJzcNU.js.map +0 -1
@@ -1,1031 +0,0 @@
1
- import { w as y, r as Z } from "./layout-types-DMoZz38-.js";
2
- import { r as X, l as Y, g as ee } from "./surface-map-C1pOTUmF.js";
3
- import { devtools as te } from "zustand/middleware";
4
- import { createStore as ne } from "zustand/vanilla";
5
- const h = (e) => {
6
- let t = !1;
7
- return {
8
- dispose() {
9
- t || (t = !0, e());
10
- }
11
- };
12
- }, ie = (e, t) => Object.is(e, t), P = (e) => {
13
- const t = ne()(te(() => e.initialState, {
14
- name: e.name ?? "workbench.store"
15
- })), n = (o, r, i = {}) => {
16
- const c = i.equalityFn ?? ie;
17
- let s = o(t.getState());
18
- return i.fireImmediately && r(s, s), t.subscribe((a) => {
19
- const d = o(a);
20
- if (c(s, d)) return;
21
- const g = s;
22
- s = d, r(d, g);
23
- });
24
- };
25
- return {
26
- getState: t.getState,
27
- getInitialState: t.getInitialState,
28
- subscribe: t.subscribe,
29
- subscribeSelector: n,
30
- setState: t.setState,
31
- api: t
32
- };
33
- }, Re = (e, t) => {
34
- for (const n of Object.values(e.regions)) {
35
- const o = n.widgets.findIndex((r) => r.contributionId === t);
36
- if (o >= 0) return {
37
- regionId: n.id,
38
- index: o,
39
- placement: n.widgets[o]
40
- };
41
- }
42
- }, Me = (e, t, n) => {
43
- for (const o of Object.values(e.regions)) {
44
- const r = o.widgets.findIndex((i) => i.contributionId === t && i.resourceUri === n);
45
- if (r >= 0) return {
46
- regionId: o.id,
47
- index: r,
48
- placement: o.widgets[r]
49
- };
50
- }
51
- }, re = (e, t) => {
52
- for (const n of Object.values(e.regions)) {
53
- const o = n.widgets.findIndex((r) => r.widgetId === t);
54
- if (o >= 0) return {
55
- regionId: n.id,
56
- index: o,
57
- placement: n.widgets[o]
58
- };
59
- }
60
- }, Le = (e, t) => {
61
- const n = new Set(Object.values(e.regions).flatMap((o) => o.widgets.map((r) => r.widgetId)));
62
- return Z(n, t);
63
- }, A = (e) => e.widgets.find((t) => t.widgetId === e.activeWidgetId) ?? e.widgets[0], W = (e) => e.role === "location", _ = (e) => e.resourceUri ?? `${e.contributionId}:${e.widgetId}`, V = (e, t, n, o) => {
64
- if (!t) return e;
65
- const r = _(t), c = {
66
- ...e.locationSubPanelSelections?.[r] ?? {}
67
- };
68
- return o ? c[n] = o : delete c[n], {
69
- ...e,
70
- locationSubPanelSelections: {
71
- ...e.locationSubPanelSelections,
72
- [r]: c
73
- }
74
- };
75
- }, T = (e, t) => {
76
- if (!e.locationSubPanelSelections) return e;
77
- const n = Object.fromEntries(Object.entries(e.locationSubPanelSelections).map(([o, r]) => [o, Object.fromEntries(Object.entries(r).filter(([, i]) => i !== t))]));
78
- return {
79
- ...e,
80
- locationSubPanelSelections: n
81
- };
82
- }, k = (e) => {
83
- const t = e.regions.main.widgets.filter(W);
84
- return t.find((n) => n.widgetId === e.activeLocationWidgetId) ?? t.at(-1);
85
- }, Oe = (e, t, n) => {
86
- const o = {
87
- ...e
88
- };
89
- return n.resource ? (o.resource = n.resource, o.resourceUri = n.resource.uri, o.title = n.title ?? n.resource.label ?? t.title) : n.title !== void 0 && (o.title = n.title), n.pinned !== void 0 && (o.pinned = n.pinned), n.closable !== void 0 && (o.closable = n.closable), n.mountStrategy !== void 0 && (o.mountStrategy = n.mountStrategy), n.hiddenByDefault !== void 0 && (o.hiddenByDefault = n.hiddenByDefault), n.tabRetention !== void 0 && (o.tabRetention = n.tabRetention), n.tab !== void 0 && (o.tab = n.tab), n.ownerId !== void 0 && (o.ownerId = n.ownerId), n.source !== void 0 && (o.source = n.source), o;
90
- }, xe = (e, t, n) => ({
91
- widgetId: e,
92
- contributionId: t.id,
93
- ownerId: n.ownerId ?? t.ownerId,
94
- source: n.source ?? t.source,
95
- resource: n.resource,
96
- resourceUri: n.resource?.uri,
97
- title: n.title ?? n.resource?.label ?? t.title,
98
- pinned: n.pinned,
99
- // Tabbed (non-singleton) widgets are closable unless they opt out; singleton
100
- // panels stay non-closable by default.
101
- closable: n.closable ?? t.closable ?? !t.singleton,
102
- mountStrategy: n.mountStrategy ?? t.mountStrategy,
103
- hiddenByDefault: n.hiddenByDefault ?? t.hiddenByDefault,
104
- tabRetention: n.tabRetention,
105
- tab: n.tab ?? t.tab,
106
- role: t.role
107
- }), Ce = (e, t, n, o = {}) => {
108
- const r = e.regions[t], i = n(r.widgets), c = o.activeWidgetId !== void 0 ? o.activeWidgetId : o.clearActiveWidget ? void 0 : r.activeWidgetId;
109
- return {
110
- ...e,
111
- activeLocationWidgetId: t === "main" && !i.some((s) => s.widgetId === e.activeLocationWidgetId) ? i.filter(W).at(-1)?.widgetId : e.activeLocationWidgetId,
112
- regions: {
113
- ...e.regions,
114
- [t]: {
115
- ...r,
116
- widgets: i,
117
- activeWidgetId: c
118
- }
119
- }
120
- };
121
- }, Ue = (e, t) => {
122
- let n = e;
123
- for (const r of Object.values(e.regions)) {
124
- const i = r.widgets.filter((a) => a.contributionId === t), c = r.widgets.filter((a) => a.contributionId !== t);
125
- if (c.length === r.widgets.length) continue;
126
- const s = r.activeWidgetId && !c.some((a) => a.widgetId === r.activeWidgetId) ? void 0 : r.activeWidgetId;
127
- n = {
128
- ...n,
129
- regions: {
130
- ...n.regions,
131
- [r.id]: {
132
- ...r,
133
- widgets: c,
134
- activeWidgetId: s
135
- }
136
- }
137
- };
138
- for (const a of i)
139
- n = T(n, a.widgetId);
140
- }
141
- const o = Object.values(n.regions).some((r) => r.widgets.some((i) => i.widgetId === n.activeWidgetId));
142
- return n.activeWidgetId && (!o || n.activeWidgetId.startsWith(`${t}:`) || n.activeWidgetId === t) && (n = {
143
- ...n,
144
- activeWidgetId: void 0,
145
- activeResourceUri: void 0
146
- }), n.activeLocationWidgetId && !n.regions.main.widgets.some((r) => r.widgetId === n.activeLocationWidgetId) && (n = {
147
- ...n,
148
- activeLocationWidgetId: n.regions.main.widgets.filter(W).at(-1)?.widgetId
149
- }), n;
150
- }, je = (e, t) => {
151
- const n = re(e, t);
152
- if (!n) return;
153
- const o = e.regions[n.regionId], r = o.widgets.filter((u) => u.widgetId !== t), i = o.activeWidgetId === t || !o.activeWidgetId && n.index === 0, s = (n.placement.role === "sub-panel" ? r.find((u) => u.role === "sub-panel" && u.ownerResourceUri === n.placement.ownerResourceUri) : void 0) ?? (n.placement.role === "sub-panel" && n.regionId === "main" ? k(e) : r[n.index] ?? r[n.index - 1]), a = i ? s?.widgetId : o.activeWidgetId, d = {
154
- ...o,
155
- widgets: r,
156
- activeWidgetId: a
157
- };
158
- let g = T({
159
- ...e,
160
- activeLocationWidgetId: e.activeLocationWidgetId === t ? e.regions.main.widgets.filter((u) => u.widgetId !== t && W(u)).at(-1)?.widgetId : e.activeLocationWidgetId,
161
- regions: {
162
- ...e.regions,
163
- [o.id]: d
164
- }
165
- }, t);
166
- return i && n.regionId !== "side" && y.includes(n.regionId) && (g = V(g, k(g), n.regionId, s?.role === "sub-panel" ? s.widgetId : void 0)), e.activeWidgetId === t && (g = {
167
- ...g,
168
- activeWidgetId: s?.widgetId,
169
- activeResourceUri: s?.resourceUri
170
- }), {
171
- regionId: n.regionId,
172
- closedPlacement: n.placement,
173
- activePlacement: A(d),
174
- layout: g
175
- };
176
- }, Ae = (e, t, n) => {
177
- const o = e.regions[t];
178
- if (t === "main" && W(n)) {
179
- const i = e.locationSubPanelSelections?.[_(n)] ?? {}, c = {
180
- ...e.regions
181
- };
182
- for (const s of y) {
183
- const a = c[s], d = i[s], g = a.widgets.find((u) => u.widgetId === d && u.role === "sub-panel" && (!u.ownerResourceUri || u.ownerResourceUri === n.resourceUri));
184
- c[s] = {
185
- ...a,
186
- activeWidgetId: s === "side" ? a.activeWidgetId : g?.widgetId ?? (s === "main" ? n.widgetId : void 0)
187
- };
188
- }
189
- return {
190
- ...e,
191
- activeWidgetId: n.widgetId,
192
- activeLocationWidgetId: n.widgetId,
193
- activeResourceUri: n.resourceUri,
194
- regions: c
195
- };
196
- }
197
- const r = n.role === "sub-panel" && t !== "side" && y.includes(t) ? V(e, k(e), t, n.widgetId) : e;
198
- return {
199
- ...r,
200
- activeWidgetId: n.widgetId,
201
- activeLocationWidgetId: e.activeLocationWidgetId,
202
- activeResourceUri: n.resourceUri,
203
- regions: {
204
- ...r.regions,
205
- [t]: {
206
- ...o,
207
- activeWidgetId: n.widgetId
208
- }
209
- }
210
- };
211
- }, oe = (e, t) => e.region === t || e.fallbackRegion === t, q = (e, t) => !(e.resourceKinds?.length && (!t || !e.resourceKinds.includes(t.kind)) || e.canOpen && (!t || !e.canOpen(t))), Ke = (e, t, n, o = {}) => {
212
- const r = e.regions[t];
213
- return r.widgets.find((i) => i.widgetId === r.activeWidgetId && i.role === "sub-panel" && (o.ignoreOwnerResourceUri || !i.ownerResourceUri || i.ownerResourceUri === n?.uri));
214
- }, Ee = (e) => k(e), F = (e, t, n, o) => {
215
- const r = e.eligibleLocations;
216
- return !(!z(e, n) || r?.resourceKinds?.length && (!t || !r.resourceKinds.includes(t.kind)) || r?.resourceIds?.length && (!t?.id || !r.resourceIds.includes(t.id)) || r?.canOpen && (!t || !r.canOpen(t)) || o?.ownerResourceUri && o.ownerResourceUri !== t?.uri);
217
- }, z = (e, t) => {
218
- const n = e.eligibleLocations?.modeIds;
219
- return !n?.length || t !== void 0 && n.includes(t);
220
- }, $e = (e, t, n, o, r = {}) => q(e, o.resource ?? t) ? r.ignoreResourceLocation ? z(e, n) : F(e, t, n, o) : !1, De = (e, t) => {
221
- const n = e.regions.main.widgets.find((o) => o.widgetId === e.regions.main.activeWidgetId) ?? k(e);
222
- return n ? t.find((o) => o.id === n.contributionId)?.floatingPanels !== "hidden" : !0;
223
- }, He = (e, t) => {
224
- const n = e.panelMenuOwner ?? {
225
- level: "panel"
226
- };
227
- return t.subPanel ? n.level === "sub-panel" && t.subPanel.contributionId === n.contributionId : n.level === "panel" ? !n.contributionId || t.locationPanel?.contributionId === n.contributionId : !1;
228
- }, se = (e, t, n) => e.singleton && Object.values(t.regions).some((o) => o.widgets.some((r) => r.contributionId === e.id && r.ownerResourceUri === n?.uri)), ce = (e) => e.widget.role === "sub-panel" && oe(e.widget, e.region) && q(e.widget, e.resource) && F(e.widget, e.resource, e.modeId) && !se(e.widget, e.layout, e.resource), Be = (e) => e.widgets.filter((t) => ce({
229
- ...e,
230
- widget: t
231
- })), ae = "workbench.core", N = (e = {}) => ({
232
- source: e.source ?? "module",
233
- ownerId: e.ownerId ?? ae,
234
- priority: e.priority ?? 0
235
- }), x = (e, t) => t.priority - e.priority || e.ownerId.localeCompare(t.ownerId), de = (e) => Array.isArray(e) ? e : e.trim().split(/\s+/).filter(Boolean), le = (e) => {
236
- const t = de(e);
237
- return t.length === 1 ? t[0] ?? "" : t;
238
- }, _e = (e) => {
239
- const t = P({
240
- name: "workbench.keybindings",
241
- initialState: {
242
- keybindings: []
243
- }
244
- });
245
- return {
246
- store: t,
247
- registerKeybinding(n, o) {
248
- if (!e.commands.getCommand(n.commandId)) throw new Error(`Keybinding command not registered: ${n.commandId}`);
249
- const r = {
250
- ...N(o),
251
- ...n,
252
- keybinding: le(n.keybinding)
253
- }, i = t.getState();
254
- return t.setState({
255
- keybindings: [...i.keybindings, r]
256
- }, !1, "registerKeybinding"), h(() => {
257
- const c = t.getState(), s = c.keybindings.filter((a) => a !== r);
258
- s.length !== c.keybindings.length && t.setState({
259
- keybindings: s
260
- }, !1, "unregisterKeybinding");
261
- });
262
- },
263
- listKeybindings() {
264
- return [...t.getState().keybindings].sort(x);
265
- },
266
- listActiveKeybindings() {
267
- return t.getState().keybindings.filter((n) => e.context.matches(n.when)).sort(x);
268
- }
269
- };
270
- }, Ve = (e = {}) => {
271
- const {
272
- strategy: t,
273
- ...n
274
- } = e;
275
- return t ? t.kind === "activate-or-open" ? {
276
- ...n,
277
- tabPosition: t.position,
278
- tabRetention: "persistent"
279
- } : t.kind === "replace-active" ? {
280
- ...n,
281
- replaceActive: !0
282
- } : t.kind === "replace-panel" ? {
283
- ...n,
284
- replaceWidgetId: t.instanceId
285
- } : {
286
- ...n,
287
- tabRetention: "preview",
288
- tabPosition: t.position
289
- } : {
290
- ...n,
291
- tabRetention: "persistent"
292
- };
293
- }, Te = (e) => ({
294
- instanceId: e.widgetId,
295
- panelId: e.contributionId,
296
- ownerId: e.ownerId,
297
- source: e.source,
298
- resource: e.resource,
299
- resourceUri: e.resourceUri,
300
- ownerResourceUri: e.ownerResourceUri,
301
- title: e.title,
302
- pinned: e.pinned,
303
- closable: e.closable === !0,
304
- mountStrategy: e.mountStrategy,
305
- hiddenByDefault: e.hiddenByDefault,
306
- tabRetention: e.tabRetention,
307
- tab: e.tab
308
- }), qe = (e) => {
309
- const {
310
- ownedPanelMenuIds: t,
311
- role: n,
312
- ...o
313
- } = e;
314
- return {
315
- ...o,
316
- closable: o.closable === !0
317
- };
318
- }, Fe = (e, t) => A(e.regions[X(t)])?.resource, ze = ({
319
- layout: e,
320
- primary: t,
321
- isInScope: n
322
- }) => {
323
- const o = [];
324
- for (const r of Y()) {
325
- const i = ee(r);
326
- if (i.role !== "anchor" || i.persistence === "primary") continue;
327
- const c = A(e.regions[r]);
328
- if (c?.resource) {
329
- if (c.role === "sub-panel" && c.ownerResourceUri) {
330
- o.push({
331
- region: r,
332
- action: "keep"
333
- });
334
- continue;
335
- }
336
- if (i.persistence === "derived") {
337
- o.push({
338
- region: r,
339
- action: "clear"
340
- });
341
- continue;
342
- }
343
- o.push({
344
- region: r,
345
- action: n(c.resource, t) ? "keep" : "clear"
346
- });
347
- }
348
- }
349
- return o;
350
- }, E = (e) => e ? Array.isArray(e) ? [...e] : [e] : [], p = {
351
- main: ["main-header", "main-left-menu", "main", "main-right-menu"],
352
- secondary: ["secondary-header", "secondary-left-menu", "secondary", "secondary-right-menu"],
353
- side: ["side-header", "side-left-menu", "side", "side-right-menu"]
354
- }, $ = Object.values(p).flat(), C = (e) => e.panels ?? y, Ne = (e) => Object.keys(p).find((t) => p[t].some((n) => n === e)), Ge = (e, t) => !e || C(e).includes(t), m = (e, t) => {
355
- if (t)
356
- return Object.values(e.regions).flatMap((n) => n.widgets).find((n) => n.widgetId === t);
357
- }, U = (e, t) => {
358
- const n = t.find((o) => o && m(e, o.widgetId));
359
- return {
360
- ...e,
361
- activeWidgetId: n?.widgetId,
362
- activeResourceUri: n?.resourceUri
363
- };
364
- }, ge = (e, t) => {
365
- if (t.length === 0) return e;
366
- const n = new Set(Object.keys(p).filter((a) => p[a].some((d) => t.includes(d)))), o = t.some((a) => {
367
- const d = e.regions[a];
368
- return d.widgets.length > 0 || d.activeWidgetId !== void 0 || d.visible;
369
- }), r = Object.values(e.locationSubPanelSelections ?? {}).some((a) => Object.keys(a).some((d) => n.has(d)));
370
- if (!o && !r) return e;
371
- const i = {
372
- ...e.regions
373
- };
374
- for (const a of t)
375
- i[a] = {
376
- ...i[a],
377
- widgets: [],
378
- activeWidgetId: void 0,
379
- visible: !1
380
- };
381
- const c = Object.fromEntries(Object.entries(e.locationSubPanelSelections ?? {}).map(([a, d]) => [a, Object.fromEntries(Object.entries(d).filter(([g]) => !n.has(g)))])), s = {
382
- ...e,
383
- regions: i
384
- };
385
- return {
386
- ...U(s, [m(s, e.activeWidgetId)]),
387
- activeLocationWidgetId: m(s, e.activeLocationWidgetId)?.widgetId,
388
- locationSubPanelSelections: c
389
- };
390
- }, j = (e, t) => {
391
- const n = new Set(t), o = Object.keys(p).filter((r) => !n.has(r)).flatMap((r) => p[r]);
392
- return ge(e, o);
393
- }, ue = (e, t, n) => {
394
- if (!t) {
395
- const s = {
396
- ...e.regions
397
- };
398
- for (const d of $) {
399
- const g = s[d], u = g.widgets.filter((b) => b.role !== "content");
400
- s[d] = {
401
- ...g,
402
- widgets: u,
403
- activeWidgetId: u.some((b) => b.widgetId === g.activeWidgetId) ? g.activeWidgetId : void 0
404
- };
405
- }
406
- const a = {
407
- ...e,
408
- regions: s
409
- };
410
- return j({
411
- ...U(a, [m(a, e.activeWidgetId)]),
412
- activeLocationWidgetId: m(a, e.activeLocationWidgetId)?.widgetId
413
- }, n);
414
- }
415
- const o = {
416
- ...e.regions
417
- };
418
- for (const s of $) o[s] = t.regions[s];
419
- const r = j({
420
- ...e,
421
- regions: o
422
- }, n), i = m(r, t.activeWidgetId), c = m(r, e.activeWidgetId);
423
- return {
424
- ...U(r, [i, c]),
425
- activeLocationWidgetId: m(r, t.activeLocationWidgetId)?.widgetId ?? m(r, e.activeLocationWidgetId)?.widgetId,
426
- locationSubPanelSelections: t.locationSubPanelSelections
427
- };
428
- }, O = (e) => {
429
- for (let t = e.length - 1; t >= 0; t -= 1)
430
- e[t]?.dispose();
431
- }, D = (e, t) => {
432
- t !== e.layout.getLayout() && e.layout.restoreLayout(t);
433
- for (const n of y) e.panels.setOpen(n, t.regions[n].visible);
434
- }, Je = (e) => {
435
- const t = P({
436
- name: "workbench.modes",
437
- initialState: {
438
- modes: {},
439
- activeModeId: void 0
440
- }
441
- }), n = /* @__PURE__ */ new Map(), o = /* @__PURE__ */ new Set(), r = /* @__PURE__ */ new Map();
442
- let i = [], c, s, a = !1;
443
- const d = (l) => {
444
- if (n.has(l.id)) return;
445
- const f = E(l.activate(e.resolveContext()));
446
- n.set(l.id, f);
447
- }, g = (l) => {
448
- const f = e.resolveContext(), v = `${l.id}\0${f.layout.getPersistenceScope() ?? "unscoped"}`, S = f.layout.getLayout(), w = j(S, C(l));
449
- if (D(f, w), o.has(v)) return;
450
- let I = !1, L = () => {
451
- };
452
- const K = () => {
453
- if (I) return;
454
- const R = f.layout.getActivePanel("main");
455
- R && (I = !0, L(), e.establishLocation?.(R.instanceId));
456
- };
457
- L = f.layout.store.subscribeSelector((R) => R.layout.regions.main, K);
458
- try {
459
- l.seed?.(f), K(), o.add(v);
460
- } finally {
461
- L();
462
- }
463
- }, u = () => {
464
- O(i), i = [], c?.dispose(), c = void 0;
465
- }, b = (l, f) => {
466
- const v = e.resolveContext(), S = t.getState().modes[l];
467
- if (!S) throw new Error(`Workbench mode not registered: ${l}`);
468
- const w = v.context.createScope("workbench.mode");
469
- w.set("activeWorkbenchMode", l), w.set(`workbenchMode.${l}`, !0), c = w;
470
- try {
471
- d(S), t.setState({
472
- ...t.getState(),
473
- activeModeId: l
474
- }, !1, "activateMode"), f.seed && g(S), i = E(S.enter?.(v));
475
- } catch (I) {
476
- throw u(), t.setState({
477
- ...t.getState(),
478
- activeModeId: void 0
479
- }, !1, "deactivateMode"), I;
480
- }
481
- }, J = e.resolveContext().layout.onDidChangePersistenceScope(() => {
482
- const l = t.getState().activeModeId;
483
- if (l === s) return;
484
- const f = l ? t.getState().modes[l] : void 0;
485
- f && g(f);
486
- }), Q = h(() => {
487
- J.dispose(), u();
488
- for (const l of n.values()) O(l);
489
- n.clear(), o.clear(), r.clear(), t.setState({
490
- modes: {},
491
- activeModeId: void 0
492
- }, !1, "disposeModes");
493
- });
494
- return {
495
- store: t,
496
- dispose() {
497
- Q.dispose();
498
- },
499
- registerMode(l) {
500
- const f = t.getState();
501
- if (f.modes[l.id]) throw new Error(`Workbench mode already registered: ${l.id}`);
502
- return t.setState({
503
- ...f,
504
- modes: {
505
- ...f.modes,
506
- [l.id]: l
507
- }
508
- }, !1, "registerMode"), h(() => {
509
- const v = t.getState();
510
- if (v.modes[l.id] !== l) return;
511
- v.activeModeId === l.id && (u(), t.setState({
512
- ...t.getState(),
513
- activeModeId: void 0
514
- }, !1, "deactivateMode")), O(n.get(l.id) ?? []), n.delete(l.id), r.delete(l.id);
515
- for (const I of o)
516
- I.startsWith(`${l.id}\0`) && o.delete(I);
517
- const {
518
- [l.id]: S,
519
- ...w
520
- } = v.modes;
521
- t.setState({
522
- ...t.getState(),
523
- modes: w
524
- }, !1, "unregisterMode");
525
- });
526
- },
527
- getMode(l) {
528
- return t.getState().modes[l];
529
- },
530
- listModes() {
531
- return Object.values(t.getState().modes);
532
- },
533
- getActiveModeId() {
534
- return t.getState().activeModeId;
535
- },
536
- isTransitioning() {
537
- return a;
538
- },
539
- setActiveMode(l, f = {}) {
540
- if (l !== t.getState().activeModeId) {
541
- a = !0, s = f.deferSeed ? l : void 0;
542
- try {
543
- const v = e.resolveContext(), S = t.getState().activeModeId;
544
- if (S && v.layout.getPersistenceScope() === void 0 && r.set(S, v.layout.getLayout()), u(), l === void 0) {
545
- t.setState({
546
- ...t.getState(),
547
- activeModeId: void 0
548
- }, !1, "deactivateMode");
549
- return;
550
- }
551
- const w = t.getState().modes[l];
552
- if (!w) throw new Error(`Workbench mode not registered: ${l}`);
553
- v.layout.getPersistenceScope() === void 0 && D(v, ue(v.layout.getLayout(), r.get(l), C(w))), b(l, {
554
- seed: s !== l
555
- });
556
- } finally {
557
- a = !1;
558
- }
559
- }
560
- },
561
- seedActiveMode() {
562
- const l = t.getState().activeModeId, f = l ? t.getState().modes[l] : void 0;
563
- s = void 0, f && g(f);
564
- },
565
- onDidChangeActive(l) {
566
- const f = t.subscribeSelector((v) => v.activeModeId, () => l());
567
- return h(f);
568
- }
569
- };
570
- }, M = (e, t) => {
571
- const {
572
- [t]: n,
573
- ...o
574
- } = e;
575
- return o;
576
- }, fe = () => {
577
- if (typeof document > "u")
578
- throw new Error("workbench.renderers.registerRenderer({ keepAlive: true }): no DOM available. The default host factory uses document.createElement. In a non-browser environment (Bun tests, SSR), pass a custom factory via createWorkbenchCore({ renderers: { createHost: () => myHost } }).");
579
- const e = document.createElement("div");
580
- return e.style.display = "contents", e.dataset.workbenchKeepAliveHost = "", e;
581
- }, Qe = (e = {}) => {
582
- const t = e.createHost ?? fe, n = P({
583
- name: "workbench.renderers",
584
- initialState: {
585
- renderers: {},
586
- hosts: {},
587
- claims: {}
588
- }
589
- }), o = (i) => {
590
- const c = n.getState(), s = c.hosts[i], a = s?.attachedTo;
591
- !s || !a || (a.contains(s.host) && a.removeChild(s.host), n.setState({
592
- ...c,
593
- hosts: {
594
- ...c.hosts,
595
- [i]: {
596
- ...s,
597
- attachedTo: void 0
598
- }
599
- },
600
- claims: M(c.claims, i)
601
- }, !1, "renderers.detach"));
602
- }, r = {
603
- store: n,
604
- registerRenderer(i) {
605
- const c = n.getState();
606
- if (c.renderers[i.id]) throw new Error(`Renderer already registered: ${i.id}`);
607
- const s = i.keepAlive ? t() : void 0, a = s ? {
608
- ...c.hosts,
609
- [i.id]: {
610
- rendererId: i.id,
611
- host: s
612
- }
613
- } : c.hosts;
614
- return n.setState({
615
- ...c,
616
- renderers: {
617
- ...c.renderers,
618
- [i.id]: i
619
- },
620
- hosts: a
621
- }, !1, "registerRenderer"), h(() => {
622
- if (n.getState().renderers[i.id] !== i) return;
623
- i.keepAlive && o(i.id);
624
- const g = n.getState();
625
- n.setState({
626
- ...g,
627
- renderers: M(g.renderers, i.id),
628
- hosts: M(g.hosts, i.id),
629
- claims: M(g.claims, i.id)
630
- }, !1, "unregisterRenderer");
631
- });
632
- },
633
- getRenderer(i) {
634
- return n.getState().renderers[i];
635
- },
636
- listRenderers() {
637
- return Object.values(n.getState().renderers);
638
- },
639
- onDidChange(i) {
640
- const c = n.subscribeSelector((s) => s.renderers, () => i());
641
- return h(c);
642
- },
643
- claim(i, c, s) {
644
- const a = n.getState(), d = a.renderers[i];
645
- if (!d) throw new Error(`Renderer is not registered: ${i}`);
646
- if (!d.keepAlive) throw new Error(`Renderer ${i} is not keep-alive; cannot claim`);
647
- const g = a.hosts[i];
648
- if (!g) throw new Error(`Renderer ${i} has no host`);
649
- if (g.attachedTo === c)
650
- n.setState({
651
- ...a,
652
- claims: {
653
- ...a.claims,
654
- [i]: s
655
- }
656
- }, !1, "renderers.updateClaim");
657
- else {
658
- o(i);
659
- const u = n.getState(), b = u.hosts[i];
660
- c.appendChild(b.host), n.setState({
661
- ...u,
662
- hosts: {
663
- ...u.hosts,
664
- [i]: {
665
- ...b,
666
- attachedTo: c
667
- }
668
- },
669
- claims: {
670
- ...u.claims,
671
- [i]: s
672
- }
673
- }, !1, "renderers.attach");
674
- }
675
- return h(() => {
676
- const b = n.getState().hosts[i];
677
- !b || b.attachedTo !== c || o(i);
678
- });
679
- },
680
- getHost(i) {
681
- return n.getState().hosts[i]?.host;
682
- },
683
- getClaim(i) {
684
- return n.getState().claims[i];
685
- }
686
- };
687
- for (const i of e.initialRenderers ?? []) r.registerRenderer(i);
688
- return r;
689
- }, Ze = {
690
- project: "folder-root",
691
- workspace: "computer",
692
- worktree: "git-pull-request-draft",
693
- settings: "settings",
694
- kanbanRenderer: "table-properties"
695
- }, ve = "workbench.resource.kind", be = "workbench.resource.id", he = (e) => `workbench.resource.metadata.${e}`, G = "workbench.selectionResourceUri", Se = (e) => typeof e == "string" || typeof e == "number" || typeof e == "boolean", Xe = (e) => {
696
- if (!e) return {};
697
- const t = {
698
- [ve]: e.kind,
699
- [be]: e.id ?? e.uri
700
- };
701
- for (const [n, o] of Object.entries(e.metadata ?? {}))
702
- Se(o) && (t[he(n)] = o);
703
- return t;
704
- }, Ye = (e) => ({
705
- [G]: e.uri
706
- }), et = (e) => {
707
- if (!e) return [];
708
- const t = e.metadata?.[G];
709
- return typeof t != "string" || t === e.uri ? [e.uri] : [e.uri, t];
710
- }, H = (e) => [...e].sort((t, n) => n.priority - t.priority || t.id.localeCompare(n.id)), B = (e) => [...e].sort((t, n) => n.priority - t.priority || t.id.localeCompare(n.id)), we = (e) => (typeof e == "object" || typeof e == "function") && e !== null && "then" in e && typeof e.then == "function", tt = (e = {}) => {
711
- const t = /* @__PURE__ */ new Set(), n = e.establishLocation;
712
- let o = 0;
713
- const r = P({
714
- name: "workbench.resources",
715
- initialState: {
716
- kinds: {},
717
- presenters: {},
718
- providers: {},
719
- hierarchyProviders: {}
720
- }
721
- });
722
- return {
723
- store: r,
724
- registerKind(i, c) {
725
- const s = r.getState();
726
- if (s.kinds[i.kind]) throw new Error(`Resource kind already registered: ${i.kind}`);
727
- const a = {
728
- ...N(c),
729
- ...i
730
- };
731
- return r.setState({
732
- ...s,
733
- kinds: {
734
- ...s.kinds,
735
- [i.kind]: a
736
- }
737
- }, !1, "registerKind"), h(() => {
738
- const d = r.getState();
739
- if (d.kinds[i.kind] !== a) return;
740
- const {
741
- [i.kind]: g,
742
- ...u
743
- } = d.kinds;
744
- r.setState({
745
- ...d,
746
- kinds: u
747
- }, !1, "unregisterKind");
748
- });
749
- },
750
- getKind(i) {
751
- return r.getState().kinds[i];
752
- },
753
- getSurface(i) {
754
- return r.getState().kinds[i.kind]?.surface;
755
- },
756
- listKinds() {
757
- return Object.values(r.getState().kinds).sort(x);
758
- },
759
- registerPresenter(i) {
760
- const c = r.getState();
761
- if (c.presenters[i.id]) throw new Error(`Resource presenter already registered: ${i.id}`);
762
- const s = {
763
- ...i,
764
- priority: i.priority ?? 0
765
- };
766
- return r.setState({
767
- ...c,
768
- presenters: {
769
- ...c.presenters,
770
- [i.id]: s
771
- }
772
- }, !1, "registerPresenter"), h(() => {
773
- const a = r.getState();
774
- if (a.presenters[i.id] !== s) return;
775
- const {
776
- [i.id]: d,
777
- ...g
778
- } = a.presenters;
779
- r.setState({
780
- ...a,
781
- presenters: g
782
- }, !1, "unregisterPresenter");
783
- });
784
- },
785
- listPresenters() {
786
- return H(Object.values(r.getState().presenters));
787
- },
788
- registerProvider(i) {
789
- const c = r.getState();
790
- if (c.providers[i.id]) throw new Error(`Resource provider already registered: ${i.id}`);
791
- return r.setState({
792
- ...c,
793
- providers: {
794
- ...c.providers,
795
- [i.id]: i
796
- }
797
- }, !1, "registerProvider"), h(() => {
798
- const s = r.getState();
799
- if (s.providers[i.id] !== i) return;
800
- const {
801
- [i.id]: a,
802
- ...d
803
- } = s.providers;
804
- r.setState({
805
- ...s,
806
- providers: d
807
- }, !1, "unregisterProvider");
808
- });
809
- },
810
- listProviders() {
811
- return Object.values(r.getState().providers);
812
- },
813
- listResources(i) {
814
- const c = {
815
- primary: e.getPrimary?.()
816
- }, s = [];
817
- for (const a of Object.values(r.getState().providers))
818
- s.push(...a.list(i, c));
819
- return s;
820
- },
821
- registerHierarchyProvider(i) {
822
- const c = r.getState();
823
- if (c.hierarchyProviders[i.id])
824
- throw new Error(`Resource hierarchy provider already registered: ${i.id}`);
825
- const s = {
826
- ...i,
827
- priority: i.priority ?? 0
828
- };
829
- return r.setState({
830
- ...c,
831
- hierarchyProviders: {
832
- ...c.hierarchyProviders,
833
- [i.id]: s
834
- }
835
- }, !1, "registerHierarchyProvider"), h(() => {
836
- const a = r.getState();
837
- if (a.hierarchyProviders[i.id] !== s) return;
838
- const {
839
- [i.id]: d,
840
- ...g
841
- } = a.hierarchyProviders;
842
- r.setState({
843
- ...a,
844
- hierarchyProviders: g
845
- }, !1, "unregisterHierarchyProvider");
846
- });
847
- },
848
- listHierarchyProviders() {
849
- return B(Object.values(r.getState().hierarchyProviders));
850
- },
851
- walkHierarchy(i) {
852
- if (!i) return [];
853
- const c = B(Object.values(r.getState().hierarchyProviders)), s = [i], a = /* @__PURE__ */ new Set([i.uri]);
854
- let d = i;
855
- for (; ; ) {
856
- const u = c.find((b) => b.canResolve(d))?.getParent(d);
857
- if (!u || a.has(u.uri)) break;
858
- s.unshift(u), a.add(u.uri), d = u;
859
- }
860
- return s;
861
- },
862
- isOpeningResource() {
863
- return o > 0;
864
- },
865
- async openResource(i, c = {}) {
866
- const s = r.getState();
867
- if (!s.kinds[i.kind]) throw new Error(`Unknown resource kind: ${i.kind}`);
868
- const a = H(Object.values(s.presenters)).find((g) => g.canOpen(i));
869
- if (!a) throw new Error(`No presenter registered for resource kind: ${i.kind}`);
870
- o += 1;
871
- let d;
872
- try {
873
- const g = a.open(i, c);
874
- d = we(g) ? await g : g, d = n?.(d) ?? d;
875
- } finally {
876
- o -= 1;
877
- }
878
- for (const g of t) g(i);
879
- return d;
880
- },
881
- onDidOpenResource(i) {
882
- return t.add(i), h(() => {
883
- t.delete(i);
884
- });
885
- }
886
- };
887
- }, me = (e) => e.replace(/^['"]|['"]$/g, ""), Ie = (e, t) => {
888
- const n = t.trim();
889
- if (n.length === 0) return !0;
890
- const o = n.match(/^([A-Za-z0-9_.-]+)\s*(==|!=)\s*(.+)$/);
891
- if (o) {
892
- const [, r, i, c] = o, s = e[r ?? ""], a = me(c ?? "");
893
- return i === "==" ? String(s) === a : String(s) !== a;
894
- }
895
- return n.startsWith("!") ? !e[n.slice(1)] : !!e[n];
896
- }, pe = (e, t) => t ? t.split("||").some((n) => n.split("&&").every((o) => Ie(e, o))) : !0, nt = () => {
897
- const e = P({
898
- name: "workbench.context",
899
- initialState: {
900
- values: {}
901
- }
902
- });
903
- let t = {};
904
- const n = /* @__PURE__ */ new Map(), o = () => {
905
- const i = {
906
- ...t
907
- };
908
- for (const c of n.values()) Object.assign(i, c);
909
- return i;
910
- }, r = (i) => {
911
- e.setState({
912
- values: o()
913
- }, !1, i);
914
- };
915
- return {
916
- store: e,
917
- set(i, c) {
918
- t[i] !== c && (t = {
919
- ...t,
920
- [i]: c
921
- }, r("setContextKey"));
922
- },
923
- get(i) {
924
- return e.getState().values[i];
925
- },
926
- delete(i) {
927
- if (!(i in t)) return;
928
- const {
929
- [i]: c,
930
- ...s
931
- } = t;
932
- t = s, r("deleteContextKey");
933
- },
934
- createScope(i) {
935
- n.set(i, n.get(i) ?? {});
936
- let c = !1;
937
- const s = () => {
938
- if (c) throw new Error(`Context key scope disposed: ${i}`);
939
- };
940
- return {
941
- ownerId: i,
942
- set(a, d) {
943
- s();
944
- const g = n.get(i) ?? {};
945
- g[a] !== d && (n.set(i, {
946
- ...g,
947
- [a]: d
948
- }), r("setScopedContextKey"));
949
- },
950
- get(a) {
951
- return s(), n.get(i)?.[a];
952
- },
953
- delete(a) {
954
- s();
955
- const d = n.get(i);
956
- if (!d || !(a in d)) return;
957
- const {
958
- [a]: g,
959
- ...u
960
- } = d;
961
- n.set(i, u), r("deleteScopedContextKey");
962
- },
963
- dispose() {
964
- c || (c = !0, n.delete(i) && r("disposeContextKeyScope"));
965
- }
966
- };
967
- },
968
- deleteOwner(i) {
969
- n.delete(i) && r("deleteContextKeyOwner");
970
- },
971
- snapshot() {
972
- return {
973
- ...e.getState().values
974
- };
975
- },
976
- matches(i) {
977
- return pe(e.getState().values, i);
978
- }
979
- };
980
- };
981
- export {
982
- tt as A,
983
- _e as B,
984
- Je as C,
985
- Xe as D,
986
- Ye as E,
987
- de as F,
988
- Ne as G,
989
- et as H,
990
- Ge as I,
991
- pe as J,
992
- Ze as K,
993
- be as L,
994
- ve as M,
995
- he as N,
996
- G as O,
997
- Be as P,
998
- Ke as Q,
999
- Ee as R,
1000
- z as S,
1001
- He as T,
1002
- $e as U,
1003
- De as V,
1004
- h as a,
1005
- x as b,
1006
- P as c,
1007
- A as d,
1008
- Ce as e,
1009
- re as f,
1010
- k as g,
1011
- T as h,
1012
- Oe as i,
1013
- Me as j,
1014
- Re as k,
1015
- Le as l,
1016
- F as m,
1017
- N as n,
1018
- xe as o,
1019
- je as p,
1020
- Ve as q,
1021
- Ue as r,
1022
- qe as s,
1023
- Te as t,
1024
- V as u,
1025
- Ae as v,
1026
- Fe as w,
1027
- ze as x,
1028
- nt as y,
1029
- Qe as z
1030
- };
1031
- //# sourceMappingURL=context-key-service-W4QEfVdN.js.map