@pstdio/workbench 0.10.0 → 0.11.1

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.
@@ -0,0 +1,871 @@
1
+ import { resourceKey as v } from "@pstdio/sdk/extensions";
2
+ import { devtools as z } from "zustand/middleware";
3
+ import { createStore as F } from "zustand/vanilla";
4
+ const y = (e) => {
5
+ let t = !1;
6
+ return {
7
+ dispose() {
8
+ t || (t = !0, e());
9
+ }
10
+ };
11
+ };
12
+ function R(e, t) {
13
+ try {
14
+ return t();
15
+ } catch (n) {
16
+ console.error(`Workbench effect failed (${e})`, n);
17
+ return;
18
+ }
19
+ }
20
+ let b = 0;
21
+ const m = /* @__PURE__ */ new Map(), D = (e, t) => {
22
+ if (b === 0) {
23
+ R("store subscriber", t);
24
+ return;
25
+ }
26
+ m.has(e) || m.set(e, t);
27
+ }, we = (e) => {
28
+ b++;
29
+ try {
30
+ return e();
31
+ } finally {
32
+ if (b--, b === 0) {
33
+ b++;
34
+ try {
35
+ for (; m.size; ) {
36
+ const [t, n] = m.entries().next().value;
37
+ m.delete(t), R("store subscriber", n);
38
+ }
39
+ } finally {
40
+ b--;
41
+ }
42
+ }
43
+ }
44
+ }, N = (e, t) => Object.is(e, t), O = (e) => {
45
+ const t = F()(z(() => e.initialState, {
46
+ name: e.name ?? "workbench.store"
47
+ })), n = (r) => {
48
+ const s = {};
49
+ return t.subscribe((o, a) => D(s, () => r(t.getState(), a)));
50
+ }, i = (r, s, o = {}) => {
51
+ const a = o.equalityFn ?? N;
52
+ let c = r(t.getState());
53
+ return o.fireImmediately && s(c, c), n((d) => {
54
+ const l = r(d);
55
+ if (a(c, l)) return;
56
+ const g = c;
57
+ c = l, s(l, g);
58
+ });
59
+ };
60
+ return {
61
+ getState: t.getState,
62
+ getInitialState: t.getInitialState,
63
+ subscribe: n,
64
+ subscribeSelector: i,
65
+ setState: t.setState,
66
+ api: t
67
+ };
68
+ }, A = ["nav", "activity", "sidenav", "main-header", "main-left-menu", "main", "main-right-menu", "secondary-header", "secondary-left-menu", "secondary", "secondary-right-menu", "side-header", "side-left-menu", "side", "side-right-menu", "status", "overlay"], w = ["main", "secondary", "side"], Ie = {
69
+ main: {
70
+ left: "main-left-menu",
71
+ right: "main-right-menu"
72
+ },
73
+ secondary: {
74
+ left: "secondary-left-menu",
75
+ right: "secondary-right-menu"
76
+ },
77
+ side: {
78
+ left: "side-left-menu",
79
+ right: "side-right-menu"
80
+ }
81
+ }, U = {
82
+ "main-left-menu": "main",
83
+ "main-right-menu": "main",
84
+ "secondary-left-menu": "secondary",
85
+ "secondary-right-menu": "secondary",
86
+ "side-left-menu": "side",
87
+ "side-right-menu": "side"
88
+ }, pe = (e) => U[e], T = (e, t, n = t) => {
89
+ if (!e.has(n)) return n;
90
+ let i = 1;
91
+ for (; e.has(`${t}:${i}`); ) i += 1;
92
+ return `${t}:${i}`;
93
+ }, We = (e, t) => {
94
+ for (const n of Object.values(e.regions)) {
95
+ const i = n.widgets.findIndex((r) => r.contributionId === t);
96
+ if (i >= 0) return {
97
+ regionId: n.id,
98
+ index: i,
99
+ placement: n.widgets[i]
100
+ };
101
+ }
102
+ }, Se = (e, t, n) => {
103
+ for (const i of Object.values(e.regions)) {
104
+ const r = i.widgets.findIndex((s) => s.contributionId === t && s.resourceKey === n);
105
+ if (r >= 0) return {
106
+ regionId: i.id,
107
+ index: r,
108
+ placement: i.widgets[r]
109
+ };
110
+ }
111
+ }, Z = (e, t) => {
112
+ for (const n of Object.values(e.regions)) {
113
+ const i = n.widgets.findIndex((r) => r.widgetId === t);
114
+ if (i >= 0) return {
115
+ regionId: n.id,
116
+ index: i,
117
+ placement: n.widgets[i]
118
+ };
119
+ }
120
+ }, ke = (e, t) => {
121
+ const n = new Set(Object.values(e.regions).flatMap((i) => i.widgets.map((r) => r.widgetId)));
122
+ return T(n, t);
123
+ }, L = (e) => e.widgets.find((t) => t.widgetId === e.activeWidgetId) ?? e.widgets[0], p = (e) => e.role === "location", $ = (e) => e.resourceKey ?? `${e.contributionId}:${e.widgetId}`, x = (e, t, n, i) => {
124
+ if (!t) return e;
125
+ const r = $(t), o = {
126
+ ...e.locationSubPanelSelections?.[r] ?? {}
127
+ };
128
+ return i ? o[n] = i : delete o[n], {
129
+ ...e,
130
+ locationSubPanelSelections: {
131
+ ...e.locationSubPanelSelections,
132
+ [r]: o
133
+ }
134
+ };
135
+ }, E = (e, t) => {
136
+ if (!e.locationSubPanelSelections) return e;
137
+ const n = Object.fromEntries(Object.entries(e.locationSubPanelSelections).map(([i, r]) => [i, Object.fromEntries(Object.entries(r).filter(([, s]) => s !== t))]));
138
+ return {
139
+ ...e,
140
+ locationSubPanelSelections: n
141
+ };
142
+ }, I = (e) => {
143
+ const t = e.regions.main.widgets.filter(p);
144
+ return t.find((n) => n.widgetId === e.activeLocationWidgetId) ?? t.at(-1);
145
+ }, Pe = (e, t, n, i = {}) => {
146
+ const r = e.regions[t], s = n(r.widgets), o = i.activeWidgetId !== void 0 ? i.activeWidgetId : i.clearActiveWidget ? void 0 : r.activeWidgetId;
147
+ return {
148
+ ...e,
149
+ activeLocationWidgetId: t === "main" && !s.some((a) => a.widgetId === e.activeLocationWidgetId) ? s.filter(p).at(-1)?.widgetId : e.activeLocationWidgetId,
150
+ regions: {
151
+ ...e.regions,
152
+ [t]: {
153
+ ...r,
154
+ widgets: s,
155
+ activeWidgetId: o
156
+ }
157
+ }
158
+ };
159
+ }, Ke = (e, t) => {
160
+ let n = e;
161
+ for (const r of Object.values(e.regions)) {
162
+ const s = r.widgets.filter((c) => c.contributionId === t), o = r.widgets.filter((c) => c.contributionId !== t);
163
+ if (o.length === r.widgets.length) continue;
164
+ const a = r.activeWidgetId && !o.some((c) => c.widgetId === r.activeWidgetId) ? void 0 : r.activeWidgetId;
165
+ n = {
166
+ ...n,
167
+ regions: {
168
+ ...n.regions,
169
+ [r.id]: {
170
+ ...r,
171
+ widgets: o,
172
+ activeWidgetId: a
173
+ }
174
+ }
175
+ };
176
+ for (const c of s)
177
+ n = E(n, c.widgetId);
178
+ }
179
+ const i = Object.values(n.regions).some((r) => r.widgets.some((s) => s.widgetId === n.activeWidgetId));
180
+ return n.activeWidgetId && (!i || n.activeWidgetId.startsWith(`${t}:`) || n.activeWidgetId === t) && (n = {
181
+ ...n,
182
+ activeWidgetId: void 0,
183
+ activeResourceKey: void 0
184
+ }), n.activeLocationWidgetId && !n.regions.main.widgets.some((r) => r.widgetId === n.activeLocationWidgetId) && (n = {
185
+ ...n,
186
+ activeLocationWidgetId: n.regions.main.widgets.filter(p).at(-1)?.widgetId
187
+ }), n;
188
+ }, Re = (e, t) => {
189
+ const n = Z(e, t);
190
+ if (!n) return;
191
+ const i = e.regions[n.regionId], r = i.widgets.filter((g) => g.widgetId !== t), s = i.activeWidgetId === t || !i.activeWidgetId && n.index === 0, a = (n.placement.role === "sub-panel" ? r.find((g) => g.role === "sub-panel" && g.ownerResourceKey === n.placement.ownerResourceKey) : void 0) ?? (n.placement.role === "sub-panel" && n.regionId === "main" ? I(e) : r[n.index] ?? r[n.index - 1]), c = s ? a?.widgetId : i.activeWidgetId, d = {
192
+ ...i,
193
+ widgets: r,
194
+ activeWidgetId: c
195
+ };
196
+ let l = E({
197
+ ...e,
198
+ activeLocationWidgetId: e.activeLocationWidgetId === t ? e.regions.main.widgets.filter((g) => g.widgetId !== t && p(g)).at(-1)?.widgetId : e.activeLocationWidgetId,
199
+ regions: {
200
+ ...e.regions,
201
+ [i.id]: d
202
+ }
203
+ }, t);
204
+ return s && n.regionId !== "side" && w.includes(n.regionId) && (l = x(l, I(l), n.regionId, a?.role === "sub-panel" ? a.widgetId : void 0)), e.activeWidgetId === t && (l = {
205
+ ...l,
206
+ activeWidgetId: a?.widgetId,
207
+ activeResourceKey: a?.resourceKey
208
+ }), {
209
+ regionId: n.regionId,
210
+ closedPlacement: n.placement,
211
+ activePlacement: L(d),
212
+ layout: l
213
+ };
214
+ }, Oe = (e, t, n) => {
215
+ const i = e.regions[t];
216
+ if (t === "main" && p(n)) {
217
+ const s = e.locationSubPanelSelections?.[$(n)] ?? {}, o = Object.fromEntries(Object.entries(e.regions).map(([a, c]) => [a, {
218
+ ...c,
219
+ widgets: c.widgets.map((d) => !n.resource || d.widgetId === n.widgetId || d.ownerResourceKey !== n.resourceKey || d.resourceKey !== n.resourceKey ? d : {
220
+ ...d,
221
+ resource: n.resource
222
+ })
223
+ }]));
224
+ for (const a of w) {
225
+ const c = o[a], d = s[a], l = c.widgets.find((g) => g.widgetId === d && g.role === "sub-panel" && (!g.ownerResourceKey || g.ownerResourceKey === n.resourceKey));
226
+ o[a] = {
227
+ ...c,
228
+ activeWidgetId: a === "side" ? c.activeWidgetId : l?.widgetId ?? (a === "main" ? n.widgetId : void 0)
229
+ };
230
+ }
231
+ return {
232
+ ...e,
233
+ activeWidgetId: n.widgetId,
234
+ activeLocationWidgetId: n.widgetId,
235
+ activeResourceKey: n.resourceKey,
236
+ regions: o
237
+ };
238
+ }
239
+ const r = n.role === "sub-panel" && t !== "side" && w.includes(t) ? x(e, I(e), t, n.widgetId) : e;
240
+ return {
241
+ ...r,
242
+ activeWidgetId: n.widgetId,
243
+ activeLocationWidgetId: e.activeLocationWidgetId,
244
+ activeResourceKey: n.resourceKey,
245
+ regions: {
246
+ ...r.regions,
247
+ [t]: {
248
+ ...i,
249
+ activeWidgetId: n.widgetId
250
+ }
251
+ }
252
+ };
253
+ }, Le = (e, t, n) => {
254
+ const i = e.regions[t], r = n ? i.widgets.find((a) => a.widgetId === n) : void 0;
255
+ if (n && !r) throw new Error(`Widget placement not found in ${t}: ${n}`);
256
+ if (i.activeWidgetId === n) return;
257
+ const s = e.activeWidgetId === i.activeWidgetId, o = {
258
+ ...e,
259
+ activeWidgetId: s ? r?.widgetId : e.activeWidgetId,
260
+ activeResourceKey: s ? r?.resourceKey : e.activeResourceKey,
261
+ activeLocationWidgetId: t === "main" && r?.role === "location" ? r.widgetId : e.activeLocationWidgetId,
262
+ regions: {
263
+ ...e.regions,
264
+ [t]: {
265
+ ...i,
266
+ activeWidgetId: r?.widgetId
267
+ }
268
+ }
269
+ };
270
+ return t === "side" || !w.includes(t) ? o : x(o, I(o), t, r?.role === "sub-panel" ? r.widgetId : void 0);
271
+ }, G = (e, t) => !(e.resourceKinds?.length && (!t || !e.resourceKinds.includes(t.type)) || e.canOpen && (!t || !e.canOpen(t))), xe = (e, t, n, i = {}) => {
272
+ const r = e.regions[t];
273
+ return r.widgets.find((s) => s.widgetId === r.activeWidgetId && s.role === "sub-panel" && (i.ignoreOwnerResourceKey || !s.ownerResourceKey || s.ownerResourceKey === v(n)));
274
+ }, je = (e) => I(e), J = (e, t, n, i, r) => {
275
+ const s = e.eligibleLocations;
276
+ return !(!V(e, n) || s?.resourceKinds?.length && (!t || !s.resourceKinds.includes(t.type)) || s?.resourceIds?.length && (!t?.id || !s.resourceIds.includes(t.id)) || s?.canOpen && (!t || !s.canOpen(t)) || s?.canOpenLocation && !s.canOpenLocation({
277
+ resource: t,
278
+ viewId: r?.viewId
279
+ }) || i?.ownerResourceKey && i.ownerResourceKey !== v(t));
280
+ }, V = (e, t) => {
281
+ const n = e.eligibleLocations?.modeIds;
282
+ return !n?.length || t !== void 0 && n.includes(t);
283
+ }, Ce = (e, t, n, i, r = {}) => G(e, i?.resource ?? t) ? r.ignoreResourceLocation ? V(e, n) : J(e, t, n, i, r.location) : !1, Me = (e, t) => {
284
+ const n = e.panelMenuOwner ?? {
285
+ level: "panel"
286
+ };
287
+ return n.contributionId ? (t.subPanel ?? t.locationPanel)?.contributionId === n.contributionId : t.subPanel ? n.level === "sub-panel" : n.level === "panel";
288
+ }, Q = "workbench.core", _ = (e = {}) => ({
289
+ source: e.source ?? "module",
290
+ ownerId: e.ownerId ?? Q,
291
+ priority: e.priority ?? 0
292
+ }), W = (e, t) => t.priority - e.priority || e.ownerId.localeCompare(t.ownerId), Ae = (e = {}, t) => {
293
+ const {
294
+ strategy: n,
295
+ ...i
296
+ } = e, r = i.resource && i.viewId === void 0 ? {
297
+ ...i,
298
+ viewId: null
299
+ } : i;
300
+ return n ? n.kind === "persistent" ? {
301
+ ...r,
302
+ tabPosition: n.position,
303
+ tabRetention: "persistent"
304
+ } : n.kind === "replace-active" ? {
305
+ ...r,
306
+ replaceActive: !0
307
+ } : n.kind === "replace-panel" ? {
308
+ ...r,
309
+ replaceWidgetId: n.instanceId,
310
+ tabRetention: n.retention
311
+ } : {
312
+ ...r,
313
+ tabRetention: "preview",
314
+ tabPosition: n.position
315
+ } : {
316
+ ...r,
317
+ tabRetention: t
318
+ };
319
+ }, $e = (e) => ({
320
+ instanceId: e.widgetId,
321
+ panelId: e.contributionId,
322
+ placementIdentity: e.placementIdentity,
323
+ viewId: e.viewId,
324
+ ownerId: e.ownerId,
325
+ source: e.source,
326
+ resource: e.resource,
327
+ section: e.section,
328
+ resourceKey: e.resourceKey,
329
+ ownerResourceKey: e.ownerResourceKey,
330
+ title: e.title,
331
+ pinned: e.pinned,
332
+ closable: e.closable === !0,
333
+ mountStrategy: e.mountStrategy,
334
+ hiddenByDefault: e.hiddenByDefault,
335
+ tabRetention: e.tabRetention,
336
+ tab: e.tab
337
+ }), Ee = (e) => {
338
+ const {
339
+ closable: t,
340
+ ownedPanelMenuIds: n,
341
+ ...i
342
+ } = e;
343
+ return i;
344
+ }, h = {
345
+ main: ["main-header", "main-left-menu", "main", "main-right-menu"],
346
+ secondary: ["secondary-header", "secondary-left-menu", "secondary", "secondary-right-menu"],
347
+ side: ["side-header", "side-left-menu", "side", "side-right-menu"]
348
+ }, C = Object.values(h).flat(), X = (e) => e.panels ?? w, Ve = (e) => Object.keys(h).find((t) => h[t].some((n) => n === e)), _e = (e, t) => !e || X(e).includes(t), f = (e, t) => {
349
+ if (t)
350
+ return Object.values(e.regions).flatMap((n) => n.widgets).find((n) => n.widgetId === t);
351
+ }, K = (e, t) => {
352
+ const n = t.find((i) => i && f(e, i.widgetId));
353
+ return {
354
+ ...e,
355
+ activeWidgetId: n?.widgetId,
356
+ activeResourceKey: n?.resourceKey
357
+ };
358
+ }, Y = (e, t) => {
359
+ if (t.length === 0) return e;
360
+ const n = new Set(Object.keys(h).filter((c) => h[c].some((d) => t.includes(d)))), i = t.some((c) => {
361
+ const d = e.regions[c];
362
+ return d.widgets.length > 0 || d.activeWidgetId !== void 0 || d.visible;
363
+ }), r = Object.values(e.locationSubPanelSelections ?? {}).some((c) => Object.keys(c).some((d) => n.has(d)));
364
+ if (!i && !r) return e;
365
+ const s = {
366
+ ...e.regions
367
+ };
368
+ for (const c of t)
369
+ s[c] = {
370
+ ...s[c],
371
+ widgets: [],
372
+ activeWidgetId: void 0,
373
+ visible: !1
374
+ };
375
+ const o = Object.fromEntries(Object.entries(e.locationSubPanelSelections ?? {}).map(([c, d]) => [c, Object.fromEntries(Object.entries(d).filter(([l]) => !n.has(l)))])), a = {
376
+ ...e,
377
+ regions: s
378
+ };
379
+ return {
380
+ ...K(a, [f(a, e.activeWidgetId)]),
381
+ activeLocationWidgetId: f(a, e.activeLocationWidgetId)?.widgetId,
382
+ locationSubPanelSelections: o
383
+ };
384
+ }, M = (e, t) => {
385
+ const n = new Set(t), i = Object.keys(h).filter((r) => !n.has(r)).flatMap((r) => h[r]);
386
+ return Y(e, i);
387
+ }, He = (e, t, n) => {
388
+ if (!t) {
389
+ const a = {
390
+ ...e.regions
391
+ };
392
+ for (const d of C) {
393
+ const l = a[d], g = l.widgets.filter((k) => k.role !== "content");
394
+ a[d] = {
395
+ ...l,
396
+ widgets: g,
397
+ activeWidgetId: g.some((k) => k.widgetId === l.activeWidgetId) ? l.activeWidgetId : void 0
398
+ };
399
+ }
400
+ const c = {
401
+ ...e,
402
+ regions: a
403
+ };
404
+ return M({
405
+ ...K(c, [f(c, e.activeWidgetId)]),
406
+ activeLocationWidgetId: f(c, e.activeLocationWidgetId)?.widgetId
407
+ }, n);
408
+ }
409
+ const i = {
410
+ ...e.regions
411
+ };
412
+ for (const a of C) i[a] = t.regions[a];
413
+ const r = M({
414
+ ...e,
415
+ regions: i
416
+ }, n), s = f(r, t.activeWidgetId), o = f(r, e.activeWidgetId);
417
+ return {
418
+ ...K(r, [s, o]),
419
+ activeLocationWidgetId: f(r, t.activeLocationWidgetId)?.widgetId ?? f(r, e.activeLocationWidgetId)?.widgetId,
420
+ locationSubPanelSelections: t.locationSubPanelSelections
421
+ };
422
+ }, Be = (e) => {
423
+ for (let t = e.length - 1; t >= 0; t -= 1)
424
+ R("mode disposal", () => e[t]?.dispose());
425
+ }, qe = (e, t) => {
426
+ t !== e.layout.getLayout() && e.layout.restoreLayout(t);
427
+ }, ee = (e) => Array.isArray(e) ? e : e.trim().split(/\s+/).filter(Boolean), te = (e) => {
428
+ const t = ee(e);
429
+ return t.length === 1 ? t[0] ?? "" : t;
430
+ }, ze = (e) => {
431
+ const t = O({
432
+ name: "workbench.keybindings",
433
+ initialState: {
434
+ keybindings: []
435
+ }
436
+ });
437
+ return {
438
+ store: t,
439
+ registerKeybinding(n, i) {
440
+ if (n.action.kind === "command" && !e.commands.getCommand(n.action.commandId))
441
+ throw new Error(`Keybinding command not registered: ${n.action.commandId}`);
442
+ const r = {
443
+ ..._(i),
444
+ ...n,
445
+ keybinding: te(n.keybinding)
446
+ }, s = t.getState();
447
+ return t.setState({
448
+ keybindings: [...s.keybindings, r]
449
+ }, !1, "registerKeybinding"), y(() => {
450
+ const o = t.getState(), a = o.keybindings.filter((c) => c !== r);
451
+ a.length !== o.keybindings.length && t.setState({
452
+ keybindings: a
453
+ }, !1, "unregisterKeybinding");
454
+ });
455
+ },
456
+ listKeybindings() {
457
+ return [...t.getState().keybindings].sort(W);
458
+ },
459
+ listActiveKeybindings() {
460
+ return t.getState().keybindings.filter((n) => e.context.matches(n.when)).sort(W);
461
+ },
462
+ listCommandKeybindings() {
463
+ return [...t.getState().keybindings].sort(W).flatMap((n) => n.action.kind === "command" ? [{
464
+ commandId: n.action.commandId,
465
+ keybinding: n.keybinding
466
+ }] : []);
467
+ }
468
+ };
469
+ }, P = (e, t, n) => ({
470
+ role: "anchor",
471
+ anchor: e,
472
+ persistence: t,
473
+ candidates: n
474
+ }), u = (e, t = !1) => t ? {
475
+ role: "projection",
476
+ reads: e,
477
+ navigator: t
478
+ } : {
479
+ role: "projection",
480
+ reads: e
481
+ }, ne = {
482
+ role: "chrome"
483
+ }, ie = {
484
+ role: "transient"
485
+ }, j = {
486
+ // The top bar hosts breadcrumbs (primary trail) and session status (attached), so it
487
+ // reads both anchors — it is a projection, not inert chrome.
488
+ nav: u(["primary", "attached"]),
489
+ activity: ne,
490
+ sidenav: u(["primary"], !0),
491
+ "main-header": u(["primary"]),
492
+ "main-left-menu": u(["primary"]),
493
+ main: P("primary", "primary", "global"),
494
+ "main-right-menu": u(["primary"]),
495
+ "secondary-header": u(["primary"]),
496
+ "secondary-left-menu": u(["secondary"]),
497
+ secondary: P("secondary", "derived", "scoped"),
498
+ "secondary-right-menu": u(["secondary"]),
499
+ status: u(["primary", "attached"]),
500
+ overlay: ie,
501
+ "side-header": u(["attached"]),
502
+ "side-left-menu": u(["attached"]),
503
+ side: P("attached", "detached", "scoped"),
504
+ "side-right-menu": u(["attached"])
505
+ }, re = (e) => j[e], se = () => A.filter((e) => j[e].role === "anchor"), oe = (e) => {
506
+ const t = A.find((n) => {
507
+ const i = j[n];
508
+ return i.role === "anchor" && i.anchor === e;
509
+ });
510
+ if (!t) throw new Error(`No region hosts anchor: ${e}`);
511
+ return t;
512
+ }, Fe = (e, t) => L(e.regions[oe(t)])?.resource, De = ({
513
+ layout: e,
514
+ primary: t,
515
+ isInScope: n
516
+ }) => {
517
+ const i = [];
518
+ for (const r of se()) {
519
+ const s = re(r);
520
+ if (s.role !== "anchor" || s.persistence === "primary") continue;
521
+ const o = L(e.regions[r]);
522
+ if (o?.resource) {
523
+ if (o.role === "sub-panel" && o.ownerResourceKey) {
524
+ i.push({
525
+ region: r,
526
+ action: "keep"
527
+ });
528
+ continue;
529
+ }
530
+ if (s.persistence === "derived") {
531
+ i.push({
532
+ region: r,
533
+ action: "clear"
534
+ });
535
+ continue;
536
+ }
537
+ i.push({
538
+ region: r,
539
+ action: n(o.resource, t) ? "keep" : "clear"
540
+ });
541
+ }
542
+ }
543
+ return i;
544
+ }, Ne = {
545
+ project: "folder-root",
546
+ workspace: "computer",
547
+ worktree: "git-pull-request-draft",
548
+ settings: "settings",
549
+ kanbanRenderer: "table-properties"
550
+ }, S = (e) => "viewId" in e && e.type === "view", ce = "resource_hierarchy_cycle", H = (e) => [...e].sort((t, n) => n.priority - t.priority || t.id.localeCompare(n.id)), ae = (e, t, n) => {
551
+ const i = H(e), r = [t], s = /* @__PURE__ */ new Set([`resource:${v(t)}`]);
552
+ let o = t;
553
+ for (; ; ) {
554
+ const c = i.find((l) => l.canResolve(o))?.getParent(o);
555
+ if (!c) break;
556
+ const d = S(c) ? `view:${c.viewId}` : `resource:${v(c)}`;
557
+ if (s.has(d)) {
558
+ n({
559
+ code: ce,
560
+ path: [...r],
561
+ repeatedUri: S(c) ? d : v(c)
562
+ });
563
+ break;
564
+ }
565
+ if (r.unshift(c), s.add(d), S(c)) break;
566
+ o = c;
567
+ }
568
+ return r;
569
+ }, de = "workbench.resource.type", le = "workbench.resource.id", ge = (e) => `workbench.resource.metadata.${e}`, B = "workbench.selectionResourceKey", ue = (e) => typeof e == "string" || typeof e == "number" || typeof e == "boolean", Ue = (e) => {
570
+ if (!e) return {};
571
+ const t = {
572
+ [de]: e.type,
573
+ [le]: e.id
574
+ };
575
+ for (const [n, i] of Object.entries(e.metadata ?? {}))
576
+ ue(i) && (t[ge(n)] = i);
577
+ return t;
578
+ }, Te = (e) => ({
579
+ [B]: v(e)
580
+ }), Ze = (e) => {
581
+ if (!e) return [];
582
+ const t = e.metadata?.[B];
583
+ return typeof t != "string" || t === v(e) ? [v(e)] : [v(e), t];
584
+ }, Ge = (e = {}) => {
585
+ const t = /* @__PURE__ */ new Set(), n = O({
586
+ name: "workbench.resources",
587
+ initialState: {
588
+ kinds: {},
589
+ providers: {},
590
+ hierarchyProviders: {}
591
+ }
592
+ });
593
+ return {
594
+ store: n,
595
+ registerKind(i, r) {
596
+ const s = n.getState();
597
+ if (s.kinds[i.kind]) throw new Error(`Resource kind already registered: ${i.kind}`);
598
+ const o = {
599
+ ..._(r),
600
+ ...i
601
+ };
602
+ return n.setState({
603
+ ...s,
604
+ kinds: {
605
+ ...s.kinds,
606
+ [i.kind]: o
607
+ }
608
+ }, !1, "registerKind"), y(() => {
609
+ const a = n.getState();
610
+ if (a.kinds[i.kind] !== o) return;
611
+ const {
612
+ [i.kind]: c,
613
+ ...d
614
+ } = a.kinds;
615
+ n.setState({
616
+ ...a,
617
+ kinds: d
618
+ }, !1, "unregisterKind");
619
+ });
620
+ },
621
+ getKind(i) {
622
+ return n.getState().kinds[i];
623
+ },
624
+ listKinds() {
625
+ return Object.values(n.getState().kinds).sort(W);
626
+ },
627
+ registerProvider(i) {
628
+ const r = n.getState();
629
+ if (r.providers[i.id]) throw new Error(`Resource provider already registered: ${i.id}`);
630
+ return n.setState({
631
+ ...r,
632
+ providers: {
633
+ ...r.providers,
634
+ [i.id]: i
635
+ }
636
+ }, !1, "registerProvider"), y(() => {
637
+ const s = n.getState();
638
+ if (s.providers[i.id] !== i) return;
639
+ const {
640
+ [i.id]: o,
641
+ ...a
642
+ } = s.providers;
643
+ n.setState({
644
+ ...s,
645
+ providers: a
646
+ }, !1, "unregisterProvider");
647
+ });
648
+ },
649
+ listProviders() {
650
+ return Object.values(n.getState().providers);
651
+ },
652
+ listResources(i) {
653
+ const r = {
654
+ primary: e.getPrimary?.()
655
+ }, s = [];
656
+ for (const o of Object.values(n.getState().providers))
657
+ s.push(...o.list(i, r));
658
+ return s;
659
+ },
660
+ registerHierarchyProvider(i) {
661
+ const r = n.getState();
662
+ if (r.hierarchyProviders[i.id])
663
+ throw new Error(`Resource hierarchy provider already registered: ${i.id}`);
664
+ const s = {
665
+ ...i,
666
+ priority: i.priority ?? 0
667
+ };
668
+ return n.setState({
669
+ ...r,
670
+ hierarchyProviders: {
671
+ ...r.hierarchyProviders,
672
+ [i.id]: s
673
+ }
674
+ }, !1, "registerHierarchyProvider"), y(() => {
675
+ const o = n.getState();
676
+ if (o.hierarchyProviders[i.id] !== s) return;
677
+ const {
678
+ [i.id]: a,
679
+ ...c
680
+ } = o.hierarchyProviders;
681
+ n.setState({
682
+ ...o,
683
+ hierarchyProviders: c
684
+ }, !1, "unregisterHierarchyProvider");
685
+ });
686
+ },
687
+ listHierarchyProviders() {
688
+ return H(Object.values(n.getState().hierarchyProviders));
689
+ },
690
+ walkHierarchy(i) {
691
+ return i ? ae(Object.values(n.getState().hierarchyProviders), i, (s) => {
692
+ for (const o of t) o(s);
693
+ }).map((s) => {
694
+ if (!S(s)) return s;
695
+ const o = e.resolveView?.(s.viewId);
696
+ return o ? {
697
+ ...s,
698
+ label: o.label,
699
+ icon: o.icon
700
+ } : s;
701
+ }) : [];
702
+ },
703
+ onDidDetectHierarchyCycle(i) {
704
+ return t.add(i), y(() => {
705
+ t.delete(i);
706
+ });
707
+ }
708
+ };
709
+ }, fe = (e) => e.replace(/^['"]|['"]$/g, ""), ve = (e, t) => {
710
+ const n = t.trim();
711
+ if (n.length === 0) return !0;
712
+ const i = n.match(/^([A-Za-z0-9_.-]+)\s*(==|!=)\s*(.+)$/);
713
+ if (i) {
714
+ const [, r, s, o] = i, a = e[r ?? ""], c = fe(o ?? "");
715
+ return s === "==" ? String(a) === c : String(a) !== c;
716
+ }
717
+ return n.startsWith("!") ? !e[n.slice(1)] : !!e[n];
718
+ }, he = (e, t) => t ? t.split("||").some((n) => n.split("&&").every((i) => ve(e, i))) : !0, Je = () => {
719
+ const e = O({
720
+ name: "workbench.context",
721
+ initialState: {
722
+ values: {}
723
+ }
724
+ });
725
+ let t = {};
726
+ const n = /* @__PURE__ */ new Map(), i = () => {
727
+ const s = {
728
+ ...t
729
+ };
730
+ for (const o of n.values()) Object.assign(s, o);
731
+ return s;
732
+ }, r = (s) => {
733
+ e.setState({
734
+ values: i()
735
+ }, !1, s);
736
+ };
737
+ return {
738
+ store: e,
739
+ set(s, o) {
740
+ t[s] !== o && (t = {
741
+ ...t,
742
+ [s]: o
743
+ }, r("setContextKey"));
744
+ },
745
+ get(s) {
746
+ return e.getState().values[s];
747
+ },
748
+ delete(s) {
749
+ if (!(s in t)) return;
750
+ const {
751
+ [s]: o,
752
+ ...a
753
+ } = t;
754
+ t = a, r("deleteContextKey");
755
+ },
756
+ createScope(s) {
757
+ n.set(s, n.get(s) ?? {});
758
+ let o = !1;
759
+ const a = () => {
760
+ if (o) throw new Error(`Context key scope disposed: ${s}`);
761
+ };
762
+ return {
763
+ ownerId: s,
764
+ set(c, d) {
765
+ a();
766
+ const l = n.get(s) ?? {};
767
+ l[c] !== d && (n.set(s, {
768
+ ...l,
769
+ [c]: d
770
+ }), r("setScopedContextKey"));
771
+ },
772
+ get(c) {
773
+ return a(), n.get(s)?.[c];
774
+ },
775
+ delete(c) {
776
+ a();
777
+ const d = n.get(s);
778
+ if (!d || !(c in d)) return;
779
+ const {
780
+ [c]: l,
781
+ ...g
782
+ } = d;
783
+ n.set(s, g), r("deleteScopedContextKey");
784
+ },
785
+ dispose() {
786
+ o || (o = !0, n.delete(s) && r("disposeContextKeyScope"));
787
+ }
788
+ };
789
+ },
790
+ deleteOwner(s) {
791
+ n.delete(s) && r("deleteContextKeyOwner");
792
+ },
793
+ snapshot() {
794
+ return {
795
+ ...e.getState().values
796
+ };
797
+ },
798
+ matches(s) {
799
+ return he(e.getState().values, s);
800
+ }
801
+ };
802
+ }, q = /* @__PURE__ */ new WeakMap(), Qe = (e, t) => {
803
+ q.set(e, t);
804
+ }, Xe = (e) => {
805
+ const t = q.get(e);
806
+ if (!t) throw new Error("Workbench renderers are not initialized");
807
+ return t;
808
+ };
809
+ export {
810
+ Fe as $,
811
+ M as A,
812
+ X as B,
813
+ qe as C,
814
+ He as D,
815
+ _e as E,
816
+ Ce as F,
817
+ we as G,
818
+ D as H,
819
+ oe as I,
820
+ De as J,
821
+ Je as K,
822
+ Ge as L,
823
+ ze as M,
824
+ Qe as N,
825
+ Ue as O,
826
+ Te as P,
827
+ ee as Q,
828
+ Ve as R,
829
+ Ze as S,
830
+ S as T,
831
+ he as U,
832
+ ce as V,
833
+ Ne as W,
834
+ le as X,
835
+ ge as Y,
836
+ de as Z,
837
+ B as _,
838
+ y as a,
839
+ Xe as a0,
840
+ xe as a1,
841
+ pe as a2,
842
+ je as a3,
843
+ V as a4,
844
+ Me as a5,
845
+ W as b,
846
+ O as c,
847
+ Ke as d,
848
+ Pe as e,
849
+ E as f,
850
+ L as g,
851
+ R as h,
852
+ Se as i,
853
+ I as j,
854
+ We as k,
855
+ ke as l,
856
+ Z as m,
857
+ _ as n,
858
+ Re as o,
859
+ Ae as p,
860
+ Ee as q,
861
+ T as r,
862
+ w as s,
863
+ $e as t,
864
+ Ie as u,
865
+ x as v,
866
+ A as w,
867
+ Le as x,
868
+ Oe as y,
869
+ Be as z
870
+ };
871
+ //# sourceMappingURL=workbench-renderers-BhgHQ-Ne.js.map