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