@panyam/tsappkit-dock 0.7.8 → 0.7.9
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.
- package/README.md +11 -6
- package/dist/index.d.mts +138 -66
- package/dist/index.d.ts +138 -66
- package/dist/index.js +476 -90
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +476 -90
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/dock.ts +368 -77
- package/src/drawerView.ts +233 -0
- package/src/index.ts +4 -0
- package/src/layout.ts +37 -7
package/dist/index.js
CHANGED
|
@@ -4,10 +4,214 @@ var dockviewCore = require('dockview-core');
|
|
|
4
4
|
|
|
5
5
|
// src/dock.ts
|
|
6
6
|
|
|
7
|
+
// src/drawer.ts
|
|
8
|
+
var DRAWER_MIN = 280;
|
|
9
|
+
var DRAWER_MAX_FRAC = 0.9;
|
|
10
|
+
var DRAWER_DEFAULT = 420;
|
|
11
|
+
function clampSize(px, viewport, bounds = {}) {
|
|
12
|
+
const min = bounds.min ?? DRAWER_MIN;
|
|
13
|
+
const max = Math.max(min, Math.floor(viewport * (bounds.maxFrac ?? DRAWER_MAX_FRAC)));
|
|
14
|
+
return Math.min(max, Math.max(min, Math.round(px)));
|
|
15
|
+
}
|
|
16
|
+
function drawerSize(edge, pointer, viewport, bounds) {
|
|
17
|
+
const fromEdge = edge === "left" || edge === "top" ? pointer : viewport - pointer;
|
|
18
|
+
return clampSize(fromEdge, viewport, bounds);
|
|
19
|
+
}
|
|
20
|
+
function loadDrawerSize(storage, key, fallback = DRAWER_DEFAULT) {
|
|
21
|
+
let raw = null;
|
|
22
|
+
try {
|
|
23
|
+
raw = storage?.getItem(key) ?? null;
|
|
24
|
+
} catch {
|
|
25
|
+
return fallback;
|
|
26
|
+
}
|
|
27
|
+
const n = raw == null ? NaN : parseInt(raw, 10);
|
|
28
|
+
return Number.isFinite(n) && n > 0 ? n : fallback;
|
|
29
|
+
}
|
|
30
|
+
function saveDrawerSize(storage, key, px) {
|
|
31
|
+
try {
|
|
32
|
+
storage?.setItem(key, String(Math.round(px)));
|
|
33
|
+
} catch {
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// src/drawerView.ts
|
|
38
|
+
var Z_SCRIM = "calc(var(--dv-overlay-z-index, 999) + 200)";
|
|
39
|
+
var Z_DRAWER = "calc(var(--dv-overlay-z-index, 999) + 201)";
|
|
40
|
+
var HORIZONTAL = { left: true, right: true, top: false, bottom: false };
|
|
41
|
+
var DrawerView = class {
|
|
42
|
+
constructor(edge, host, config, hooks) {
|
|
43
|
+
this.edge = edge;
|
|
44
|
+
this.host = host;
|
|
45
|
+
this.config = config;
|
|
46
|
+
this.hooks = hooks;
|
|
47
|
+
this.tabs = [];
|
|
48
|
+
this.isOpen = false;
|
|
49
|
+
const doc = host.ownerDocument;
|
|
50
|
+
this.px = config.size ?? DRAWER_DEFAULT;
|
|
51
|
+
this.scrim = doc.createElement("div");
|
|
52
|
+
this.scrim.className = `dock-drawer-scrim dock-drawer-scrim-${edge}`;
|
|
53
|
+
Object.assign(this.scrim.style, { position: "absolute", inset: "0", background: "rgba(0,0,0,.25)", zIndex: Z_SCRIM, display: "none" });
|
|
54
|
+
this.scrim.addEventListener("click", () => this.setOpen(false));
|
|
55
|
+
this.root = doc.createElement("aside");
|
|
56
|
+
this.root.className = `dock-drawer dock-drawer-${edge}`;
|
|
57
|
+
this.root.dataset.edge = edge;
|
|
58
|
+
Object.assign(this.root.style, {
|
|
59
|
+
position: "absolute",
|
|
60
|
+
zIndex: Z_DRAWER,
|
|
61
|
+
display: "none",
|
|
62
|
+
flexDirection: "column",
|
|
63
|
+
background: "var(--dv-group-view-background-color, Canvas)",
|
|
64
|
+
color: "var(--dv-activegroup-visiblepanel-tab-color, CanvasText)",
|
|
65
|
+
boxShadow: "0 0 16px rgba(0,0,0,.35)",
|
|
66
|
+
[edge]: "0",
|
|
67
|
+
...HORIZONTAL[edge] ? { top: "0", bottom: "0" } : { left: "0", right: "0" }
|
|
68
|
+
});
|
|
69
|
+
this.tabStrip = doc.createElement("div");
|
|
70
|
+
this.tabStrip.className = "dock-drawer-tabs";
|
|
71
|
+
this.tabStrip.setAttribute("role", "tablist");
|
|
72
|
+
Object.assign(this.tabStrip.style, { display: "flex", gap: "2px", alignItems: "center", flex: "none" });
|
|
73
|
+
this.body = doc.createElement("div");
|
|
74
|
+
this.body.className = "dock-drawer-body";
|
|
75
|
+
Object.assign(this.body.style, { flex: "1", minHeight: "0", overflow: "auto", position: "relative" });
|
|
76
|
+
this.handle = doc.createElement("div");
|
|
77
|
+
this.handle.className = "dock-drawer-handle";
|
|
78
|
+
const inner = { left: "right", right: "left", top: "bottom", bottom: "top" }[edge];
|
|
79
|
+
Object.assign(this.handle.style, {
|
|
80
|
+
position: "absolute",
|
|
81
|
+
[inner]: "-3px",
|
|
82
|
+
...HORIZONTAL[edge] ? { top: "0", bottom: "0", width: "6px", cursor: "col-resize" } : { left: "0", right: "0", height: "6px", cursor: "row-resize" },
|
|
83
|
+
touchAction: "none"
|
|
84
|
+
});
|
|
85
|
+
this.handle.addEventListener("pointerdown", (e) => this.drag(e));
|
|
86
|
+
this.root.append(this.tabStrip, this.body, this.handle);
|
|
87
|
+
host.append(this.scrim, this.root);
|
|
88
|
+
this.applySize();
|
|
89
|
+
}
|
|
90
|
+
get ids() {
|
|
91
|
+
return this.tabs.map((t) => t.id);
|
|
92
|
+
}
|
|
93
|
+
get active() {
|
|
94
|
+
return this.activeId;
|
|
95
|
+
}
|
|
96
|
+
get open() {
|
|
97
|
+
return this.isOpen;
|
|
98
|
+
}
|
|
99
|
+
get size() {
|
|
100
|
+
return this.px;
|
|
101
|
+
}
|
|
102
|
+
has(id) {
|
|
103
|
+
return this.tabs.some((t) => t.id === id);
|
|
104
|
+
}
|
|
105
|
+
/** Adds a panel as a tab, or does nothing if it's already here. It doesn't open the drawer. */
|
|
106
|
+
add(id, title, el) {
|
|
107
|
+
if (this.has(id)) return;
|
|
108
|
+
const doc = this.host.ownerDocument;
|
|
109
|
+
const button = doc.createElement("button");
|
|
110
|
+
button.type = "button";
|
|
111
|
+
button.className = "dock-drawer-tab";
|
|
112
|
+
button.setAttribute("role", "tab");
|
|
113
|
+
button.dataset.panel = id;
|
|
114
|
+
const label = doc.createElement("span");
|
|
115
|
+
label.textContent = title;
|
|
116
|
+
const more = doc.createElement("span");
|
|
117
|
+
more.className = "dock-drawer-tab-menu";
|
|
118
|
+
more.textContent = "\u22EF";
|
|
119
|
+
more.title = "Move this panel";
|
|
120
|
+
more.addEventListener("click", (e) => {
|
|
121
|
+
e.stopPropagation();
|
|
122
|
+
this.hooks.menu(more, id);
|
|
123
|
+
});
|
|
124
|
+
button.append(label, " ", more);
|
|
125
|
+
button.addEventListener("click", () => this.activate(id));
|
|
126
|
+
this.tabStrip.appendChild(button);
|
|
127
|
+
el.style.display = "none";
|
|
128
|
+
this.body.appendChild(el);
|
|
129
|
+
this.tabs.push({ id, el, button });
|
|
130
|
+
if (!this.activeId) this.activate(id, false);
|
|
131
|
+
this.hooks.changed();
|
|
132
|
+
}
|
|
133
|
+
/** Takes a panel out and returns its element, detached. The next tab becomes active. */
|
|
134
|
+
remove(id) {
|
|
135
|
+
const i = this.tabs.findIndex((t) => t.id === id);
|
|
136
|
+
if (i < 0) return void 0;
|
|
137
|
+
const [tab] = this.tabs.splice(i, 1);
|
|
138
|
+
tab.button.remove();
|
|
139
|
+
tab.el.remove();
|
|
140
|
+
tab.el.style.display = "";
|
|
141
|
+
if (this.activeId === id) {
|
|
142
|
+
this.activeId = void 0;
|
|
143
|
+
const next = this.tabs[Math.min(i, this.tabs.length - 1)];
|
|
144
|
+
if (next) this.activate(next.id, false);
|
|
145
|
+
}
|
|
146
|
+
if (this.tabs.length === 0) this.setOpen(false, false);
|
|
147
|
+
this.hooks.changed();
|
|
148
|
+
return tab.el;
|
|
149
|
+
}
|
|
150
|
+
activate(id, notify = true) {
|
|
151
|
+
if (!this.has(id)) return;
|
|
152
|
+
this.activeId = id;
|
|
153
|
+
for (const t of this.tabs) {
|
|
154
|
+
const on = t.id === id;
|
|
155
|
+
t.el.style.display = on ? "" : "none";
|
|
156
|
+
t.button.classList.toggle("dock-drawer-tab-active", on);
|
|
157
|
+
t.button.setAttribute("aria-selected", String(on));
|
|
158
|
+
}
|
|
159
|
+
if (notify) this.hooks.changed();
|
|
160
|
+
}
|
|
161
|
+
setOpen(open, notify = true) {
|
|
162
|
+
const show = open && this.tabs.length > 0;
|
|
163
|
+
if (show === this.isOpen) return;
|
|
164
|
+
this.isOpen = show;
|
|
165
|
+
this.root.style.display = show ? "flex" : "none";
|
|
166
|
+
this.scrim.style.display = show ? "block" : "none";
|
|
167
|
+
if (show) this.applySize();
|
|
168
|
+
if (notify) this.hooks.changed();
|
|
169
|
+
}
|
|
170
|
+
setSize(px, notify = true) {
|
|
171
|
+
this.px = Math.round(px);
|
|
172
|
+
this.applySize();
|
|
173
|
+
if (notify) this.hooks.changed();
|
|
174
|
+
}
|
|
175
|
+
state() {
|
|
176
|
+
return { panels: this.ids, active: this.activeId, size: this.px, open: this.isOpen };
|
|
177
|
+
}
|
|
178
|
+
dispose() {
|
|
179
|
+
this.scrim.remove();
|
|
180
|
+
this.root.remove();
|
|
181
|
+
}
|
|
182
|
+
// Clamps against the host as it is now, so a drawer saved on a big window still fits a small one.
|
|
183
|
+
applySize() {
|
|
184
|
+
const rect = this.host.getBoundingClientRect();
|
|
185
|
+
const span = HORIZONTAL[this.edge] ? rect.width : rect.height;
|
|
186
|
+
const px = span > 0 ? clampSize(this.px, span, this.config) : this.px;
|
|
187
|
+
this.root.style[HORIZONTAL[this.edge] ? "width" : "height"] = `${px}px`;
|
|
188
|
+
}
|
|
189
|
+
drag(e) {
|
|
190
|
+
e.preventDefault();
|
|
191
|
+
const move = (ev) => {
|
|
192
|
+
const rect = this.host.getBoundingClientRect();
|
|
193
|
+
const horizontal = HORIZONTAL[this.edge];
|
|
194
|
+
const pointer = horizontal ? ev.clientX - rect.left : ev.clientY - rect.top;
|
|
195
|
+
const span = horizontal ? rect.width : rect.height;
|
|
196
|
+
this.setSize(drawerSize(this.edge, pointer, span, this.config), false);
|
|
197
|
+
};
|
|
198
|
+
const up = () => {
|
|
199
|
+
this.handle.ownerDocument.removeEventListener("pointermove", move);
|
|
200
|
+
this.handle.ownerDocument.removeEventListener("pointerup", up);
|
|
201
|
+
this.root.classList.remove("dock-drawer-resizing");
|
|
202
|
+
this.hooks.changed();
|
|
203
|
+
};
|
|
204
|
+
this.root.classList.add("dock-drawer-resizing");
|
|
205
|
+
this.handle.ownerDocument.addEventListener("pointermove", move);
|
|
206
|
+
this.handle.ownerDocument.addEventListener("pointerup", up);
|
|
207
|
+
}
|
|
208
|
+
};
|
|
209
|
+
|
|
7
210
|
// src/layout.ts
|
|
8
|
-
function saveLayout(storage, key, registry, layout) {
|
|
211
|
+
function saveLayout(storage, key, registry, layout, drawers) {
|
|
9
212
|
try {
|
|
10
|
-
const
|
|
213
|
+
const panels = registry.map((p) => p.id);
|
|
214
|
+
const saved = drawers ? { v: 2, panels, layout, drawers } : { v: 1, panels, layout };
|
|
11
215
|
storage.setItem(key, JSON.stringify(saved));
|
|
12
216
|
} catch {
|
|
13
217
|
}
|
|
@@ -24,9 +228,10 @@ function loadLayout(storage, key) {
|
|
|
24
228
|
const parsed = JSON.parse(raw);
|
|
25
229
|
if (parsed && typeof parsed === "object" && "v" in parsed && "layout" in parsed) {
|
|
26
230
|
const s = parsed;
|
|
27
|
-
|
|
231
|
+
const drawers = s.v === 2 && s.drawers && typeof s.drawers === "object" ? s.drawers : {};
|
|
232
|
+
return { layout: s.layout, savedPanels: Array.isArray(s.panels) ? s.panels : [], drawers };
|
|
28
233
|
}
|
|
29
|
-
return { layout: parsed, savedPanels: [] };
|
|
234
|
+
return { layout: parsed, savedPanels: [], drawers: {} };
|
|
30
235
|
} catch {
|
|
31
236
|
return null;
|
|
32
237
|
}
|
|
@@ -50,6 +255,8 @@ function documentTheme(doc = document) {
|
|
|
50
255
|
}
|
|
51
256
|
|
|
52
257
|
// src/dock.ts
|
|
258
|
+
var EDGES = ["left", "right", "top", "bottom"];
|
|
259
|
+
var placementLabel = (p) => !p || p.kind === "grid" ? "" : p.kind === "float" ? " \xB7 float" : ` \xB7 ${p.edge} drawer`;
|
|
53
260
|
function createDock(opts) {
|
|
54
261
|
const { container, panels, hostFor, release } = opts;
|
|
55
262
|
const storage = opts.storage ?? null;
|
|
@@ -60,9 +267,18 @@ function createDock(opts) {
|
|
|
60
267
|
const byId = new Map(panels.map((p) => [p.id, p]));
|
|
61
268
|
const specs = Array.isArray(opts.defaultLayout) ? opts.defaultLayout : null;
|
|
62
269
|
const cleanups = [];
|
|
270
|
+
const drawerHost = opts.drawerHost ?? container;
|
|
271
|
+
const drawers = /* @__PURE__ */ new Map();
|
|
63
272
|
let disposed = false;
|
|
273
|
+
let quiet = 0;
|
|
274
|
+
const defOf = (id) => {
|
|
275
|
+
const known = byId.get(id);
|
|
276
|
+
if (known) return known;
|
|
277
|
+
const def = opts.resolve?.(id);
|
|
278
|
+
return def && def.id === id ? def : void 0;
|
|
279
|
+
};
|
|
64
280
|
const renderer = (id) => {
|
|
65
|
-
if (!
|
|
281
|
+
if (!defOf(id)) return { element: doc.createElement("div"), init: () => {
|
|
66
282
|
} };
|
|
67
283
|
const element = hostFor(id);
|
|
68
284
|
return { element, init: () => {
|
|
@@ -70,29 +286,139 @@ function createDock(opts) {
|
|
|
70
286
|
};
|
|
71
287
|
const component = new dockviewCore.DockviewComponent(container, {
|
|
72
288
|
createComponent: (o) => renderer(o.id),
|
|
73
|
-
// "always" keeps a background tab's content attached, only hidden
|
|
74
|
-
// and an app that finds its content by id
|
|
289
|
+
// "always" keeps a background tab's content attached, only hidden, in a layer dockview
|
|
290
|
+
// positions over the group. The default detaches it, and an app that finds its content by id
|
|
291
|
+
// at startup would miss the panels behind a tab. The layer also means dragging a tab between
|
|
292
|
+
// groups doesn't re-parent the content, so an iframe in it doesn't reload.
|
|
75
293
|
defaultRenderer: "always",
|
|
76
|
-
theme: theme() === "dark" ? dockviewCore.themeDark : dockviewCore.themeLight
|
|
294
|
+
theme: theme() === "dark" ? dockviewCore.themeDark : dockviewCore.themeLight,
|
|
295
|
+
...opts.moveMenu === false ? {} : { createRightHeaderActionComponent: () => headerMenu() }
|
|
77
296
|
});
|
|
78
297
|
const api = component.api;
|
|
298
|
+
const drawerWith = (id) => [...drawers.values()].find((d) => d.has(id));
|
|
299
|
+
const where = (id) => {
|
|
300
|
+
const d = drawerWith(id);
|
|
301
|
+
if (d) return { kind: "drawer", edge: d.edge };
|
|
302
|
+
const panel = api.getPanel(id);
|
|
303
|
+
if (!panel) return null;
|
|
304
|
+
return panel.group.api.location.type === "floating" ? { kind: "float" } : { kind: "grid" };
|
|
305
|
+
};
|
|
306
|
+
const same = (a, b) => !!a && a.kind === b.kind && (a.kind !== "drawer" || b.kind === "drawer" && a.edge === b.edge);
|
|
307
|
+
const drawer = (edge) => {
|
|
308
|
+
let d = drawers.get(edge);
|
|
309
|
+
if (!d) {
|
|
310
|
+
if (doc.defaultView?.getComputedStyle(drawerHost).position === "static") drawerHost.style.position = "relative";
|
|
311
|
+
d = new DrawerView(edge, drawerHost, opts.drawers?.[edge] ?? {}, { changed: () => save(), menu: (anchor, id) => moveMenu(anchor, id) });
|
|
312
|
+
drawers.set(edge, d);
|
|
313
|
+
}
|
|
314
|
+
return d;
|
|
315
|
+
};
|
|
316
|
+
const drawerStates = () => {
|
|
317
|
+
const out = {};
|
|
318
|
+
for (const [edge, d] of drawers) if (d.ids.length || d.size !== (opts.drawers?.[edge]?.size ?? DRAWER_DEFAULT)) out[edge] = d.state();
|
|
319
|
+
return out;
|
|
320
|
+
};
|
|
79
321
|
const usable = (p) => !!p && (!p.referencePanel || !!api.getPanel(p.referencePanel));
|
|
80
|
-
const
|
|
81
|
-
const def =
|
|
322
|
+
const addToGrid = (id) => {
|
|
323
|
+
const def = defOf(id);
|
|
82
324
|
const spec = specs?.find((s) => s.id === id);
|
|
83
325
|
const position = [def.position, spec?.position].find(usable);
|
|
84
326
|
api.addPanel({ id, component: id, title: def.title, ...position ? { position } : {} });
|
|
85
327
|
};
|
|
328
|
+
const enter = (id, target) => {
|
|
329
|
+
if (target.kind === "drawer") {
|
|
330
|
+
drawer(target.edge).add(id, defOf(id).title, hostFor(id));
|
|
331
|
+
return;
|
|
332
|
+
}
|
|
333
|
+
if (!api.getPanel(id)) addToGrid(id);
|
|
334
|
+
const panel = api.getPanel(id);
|
|
335
|
+
if (target.kind === "float" && panel.group.api.location.type !== "floating") api.addFloatingGroup(panel);
|
|
336
|
+
};
|
|
337
|
+
const leave = (id) => {
|
|
338
|
+
const d = drawerWith(id);
|
|
339
|
+
if (d) {
|
|
340
|
+
const el = d.remove(id);
|
|
341
|
+
if (el) release?.(id, el);
|
|
342
|
+
return;
|
|
343
|
+
}
|
|
344
|
+
const panel = api.getPanel(id);
|
|
345
|
+
if (panel) api.removePanel(panel);
|
|
346
|
+
};
|
|
347
|
+
const reveal = (id) => {
|
|
348
|
+
const d = drawerWith(id);
|
|
349
|
+
if (d) {
|
|
350
|
+
d.activate(id);
|
|
351
|
+
d.setOpen(true);
|
|
352
|
+
return;
|
|
353
|
+
}
|
|
354
|
+
api.getPanel(id)?.api.setActive();
|
|
355
|
+
};
|
|
356
|
+
const place = (id, target) => {
|
|
357
|
+
if (!defOf(id)) return false;
|
|
358
|
+
const now = where(id);
|
|
359
|
+
if (!same(now, target)) {
|
|
360
|
+
if (!(now?.kind === "grid" && target.kind === "float")) leave(id);
|
|
361
|
+
enter(id, target);
|
|
362
|
+
}
|
|
363
|
+
reveal(id);
|
|
364
|
+
save();
|
|
365
|
+
return true;
|
|
366
|
+
};
|
|
367
|
+
const show = (id) => {
|
|
368
|
+
const def = defOf(id);
|
|
369
|
+
if (!def) return false;
|
|
370
|
+
if (!where(id)) enter(id, def.defaultPlacement ?? { kind: "grid" });
|
|
371
|
+
reveal(id);
|
|
372
|
+
save();
|
|
373
|
+
return true;
|
|
374
|
+
};
|
|
375
|
+
const toggle = (id) => {
|
|
376
|
+
if (!defOf(id)) return false;
|
|
377
|
+
if (where(id)) {
|
|
378
|
+
leave(id);
|
|
379
|
+
save();
|
|
380
|
+
return true;
|
|
381
|
+
}
|
|
382
|
+
return show(id);
|
|
383
|
+
};
|
|
86
384
|
const applyDefault = () => {
|
|
87
|
-
|
|
385
|
+
const elsewhere = (def) => !!def?.defaultPlacement && def.defaultPlacement.kind === "drawer";
|
|
386
|
+
if (specs) {
|
|
387
|
+
for (const spec of specs) {
|
|
388
|
+
const def = byId.get(spec.id);
|
|
389
|
+
if (!def || elsewhere(def) || api.getPanel(spec.id)) continue;
|
|
390
|
+
const position = usable(spec.position) ? spec.position : void 0;
|
|
391
|
+
api.addPanel({ id: spec.id, component: spec.id, title: spec.title ?? def.title, ...position ? { position } : {} });
|
|
392
|
+
}
|
|
393
|
+
} else {
|
|
88
394
|
opts.defaultLayout(api);
|
|
89
|
-
return;
|
|
90
395
|
}
|
|
91
|
-
for (const
|
|
92
|
-
const
|
|
93
|
-
if (!
|
|
94
|
-
|
|
95
|
-
|
|
396
|
+
for (const def of panels) {
|
|
397
|
+
const p = def.defaultPlacement;
|
|
398
|
+
if (!p || p.kind === "grid") continue;
|
|
399
|
+
if (p.kind === "drawer" && !where(def.id)) enter(def.id, p);
|
|
400
|
+
if (p.kind === "float" && (where(def.id)?.kind ?? "grid") === "grid") enter(def.id, p);
|
|
401
|
+
}
|
|
402
|
+
};
|
|
403
|
+
const clearDrawers = () => {
|
|
404
|
+
for (const d of drawers.values()) {
|
|
405
|
+
for (const id of d.ids) leave(id);
|
|
406
|
+
d.setOpen(false, false);
|
|
407
|
+
d.setSize(opts.drawers?.[d.edge]?.size ?? DRAWER_DEFAULT, false);
|
|
408
|
+
}
|
|
409
|
+
};
|
|
410
|
+
const restoreDrawers = (saved) => {
|
|
411
|
+
for (const edge of EDGES) {
|
|
412
|
+
const s = saved[edge];
|
|
413
|
+
if (!s) continue;
|
|
414
|
+
const d = drawer(edge);
|
|
415
|
+
if (typeof s.size === "number" && s.size > 0) d.setSize(s.size, false);
|
|
416
|
+
for (const id of Array.isArray(s.panels) ? s.panels : []) {
|
|
417
|
+
const def = defOf(id);
|
|
418
|
+
if (def && !where(id)) d.add(id, def.title, hostFor(id));
|
|
419
|
+
}
|
|
420
|
+
if (s.active) d.activate(s.active, false);
|
|
421
|
+
if (s.open) d.setOpen(true, false);
|
|
96
422
|
}
|
|
97
423
|
};
|
|
98
424
|
const restore = () => {
|
|
@@ -103,24 +429,44 @@ function createDock(opts) {
|
|
|
103
429
|
}
|
|
104
430
|
try {
|
|
105
431
|
api.fromJSON(saved.layout);
|
|
106
|
-
for (const
|
|
107
|
-
|
|
108
|
-
if (panel) api.removePanel(panel);
|
|
109
|
-
}
|
|
432
|
+
for (const panel of [...api.panels]) if (!defOf(panel.id)) api.removePanel(panel);
|
|
433
|
+
restoreDrawers(saved.drawers);
|
|
110
434
|
for (const id of panelsToReconcile(saved.savedPanels, panels)) {
|
|
111
|
-
if (!
|
|
435
|
+
if (!where(id)) enter(id, byId.get(id).defaultPlacement ?? { kind: "grid" });
|
|
112
436
|
}
|
|
113
437
|
} catch (err) {
|
|
114
438
|
console.warn("tsappkit-dock: saved layout rejected, using the default", err);
|
|
115
439
|
storage?.removeItem(key);
|
|
440
|
+
clearDrawers();
|
|
441
|
+
api.clear();
|
|
442
|
+
applyDefault();
|
|
443
|
+
}
|
|
444
|
+
};
|
|
445
|
+
const save = () => {
|
|
446
|
+
if (quiet || disposed || !storage) return;
|
|
447
|
+
saveLayout(storage, key, panels, api.toJSON(), drawerStates());
|
|
448
|
+
};
|
|
449
|
+
const reset = () => {
|
|
450
|
+
quiet++;
|
|
451
|
+
try {
|
|
452
|
+
storage?.removeItem(key);
|
|
453
|
+
clearDrawers();
|
|
116
454
|
api.clear();
|
|
117
455
|
applyDefault();
|
|
456
|
+
} finally {
|
|
457
|
+
quiet--;
|
|
118
458
|
}
|
|
459
|
+
save();
|
|
119
460
|
};
|
|
120
|
-
|
|
461
|
+
quiet++;
|
|
462
|
+
try {
|
|
463
|
+
restore();
|
|
464
|
+
} finally {
|
|
465
|
+
quiet--;
|
|
466
|
+
}
|
|
121
467
|
if (storage) {
|
|
122
|
-
|
|
123
|
-
const sub = api.onDidLayoutChange(() =>
|
|
468
|
+
save();
|
|
469
|
+
const sub = api.onDidLayoutChange(() => save());
|
|
124
470
|
cleanups.push(() => sub.dispose());
|
|
125
471
|
}
|
|
126
472
|
const applyTheme = () => component.updateOptions({ theme: theme() === "dark" ? dockviewCore.themeDark : dockviewCore.themeLight });
|
|
@@ -135,18 +481,78 @@ function createDock(opts) {
|
|
|
135
481
|
mq.addEventListener("change", applyTheme);
|
|
136
482
|
cleanups.push(() => mq.removeEventListener("change", applyTheme));
|
|
137
483
|
}
|
|
138
|
-
const
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
484
|
+
const escape = (e) => {
|
|
485
|
+
if (e.key !== "Escape") return;
|
|
486
|
+
closeMenu();
|
|
487
|
+
for (const d of drawers.values()) d.setOpen(false);
|
|
142
488
|
};
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
489
|
+
doc.addEventListener("keydown", escape);
|
|
490
|
+
cleanups.push(() => doc.removeEventListener("keydown", escape));
|
|
491
|
+
let menu = null;
|
|
492
|
+
const closeMenu = () => {
|
|
493
|
+
menu?.remove();
|
|
494
|
+
menu = null;
|
|
495
|
+
};
|
|
496
|
+
const outside = (e) => {
|
|
497
|
+
if (menu && !menu.contains(e.target)) closeMenu();
|
|
149
498
|
};
|
|
499
|
+
doc.addEventListener("pointerdown", outside, true);
|
|
500
|
+
cleanups.push(() => doc.removeEventListener("pointerdown", outside, true), closeMenu);
|
|
501
|
+
const moveItems = (id) => {
|
|
502
|
+
const now = where(id);
|
|
503
|
+
const items = [];
|
|
504
|
+
if (now?.kind !== "grid") items.push(["Dock", { kind: "grid" }]);
|
|
505
|
+
if (now?.kind !== "float") items.push(["Float", { kind: "float" }]);
|
|
506
|
+
for (const edge of EDGES) {
|
|
507
|
+
if (!(now?.kind === "drawer" && now.edge === edge)) items.push([`Move to ${edge} drawer`, { kind: "drawer", edge }]);
|
|
508
|
+
}
|
|
509
|
+
items.push(["Close", null]);
|
|
510
|
+
return items;
|
|
511
|
+
};
|
|
512
|
+
const moveMenu = (anchor, id) => {
|
|
513
|
+
closeMenu();
|
|
514
|
+
const list = doc.createElement("div");
|
|
515
|
+
list.className = "dock-menu";
|
|
516
|
+
list.setAttribute("role", "menu");
|
|
517
|
+
list.dataset.panel = id;
|
|
518
|
+
const r = anchor.getBoundingClientRect();
|
|
519
|
+
Object.assign(list.style, { position: "fixed", left: `${Math.round(r.left)}px`, top: `${Math.round(r.bottom + 2)}px`, zIndex: "calc(var(--dv-overlay-z-index, 999) + 300)" });
|
|
520
|
+
for (const [label, target] of moveItems(id)) {
|
|
521
|
+
const b = doc.createElement("button");
|
|
522
|
+
b.type = "button";
|
|
523
|
+
b.className = "dock-menu-item";
|
|
524
|
+
b.setAttribute("role", "menuitem");
|
|
525
|
+
b.textContent = label;
|
|
526
|
+
b.addEventListener("click", () => {
|
|
527
|
+
closeMenu();
|
|
528
|
+
if (target) place(id, target);
|
|
529
|
+
else toggle(id);
|
|
530
|
+
});
|
|
531
|
+
list.appendChild(b);
|
|
532
|
+
}
|
|
533
|
+
doc.body.appendChild(list);
|
|
534
|
+
menu = list;
|
|
535
|
+
};
|
|
536
|
+
function headerMenu() {
|
|
537
|
+
const btn = doc.createElement("button");
|
|
538
|
+
btn.type = "button";
|
|
539
|
+
btn.className = "dock-move-btn";
|
|
540
|
+
btn.textContent = "\u22EF";
|
|
541
|
+
btn.title = "Move this panel";
|
|
542
|
+
let group;
|
|
543
|
+
btn.addEventListener("click", (e) => {
|
|
544
|
+
e.stopPropagation();
|
|
545
|
+
const id = group?.activePanel?.id;
|
|
546
|
+
if (id && defOf(id)) moveMenu(btn, id);
|
|
547
|
+
});
|
|
548
|
+
return {
|
|
549
|
+
element: btn,
|
|
550
|
+
init: (params) => {
|
|
551
|
+
group = params.group;
|
|
552
|
+
},
|
|
553
|
+
dispose: () => btn.remove()
|
|
554
|
+
};
|
|
555
|
+
}
|
|
150
556
|
const panelsMenu = (host) => {
|
|
151
557
|
const btn = doc.createElement("button");
|
|
152
558
|
btn.type = "button";
|
|
@@ -157,9 +563,9 @@ function createDock(opts) {
|
|
|
157
563
|
const list = doc.createElement("div");
|
|
158
564
|
list.className = "dock-panels-list";
|
|
159
565
|
list.style.display = "none";
|
|
160
|
-
const setOpen = (
|
|
161
|
-
list.style.display =
|
|
162
|
-
btn.setAttribute("aria-expanded", String(
|
|
566
|
+
const setOpen = (show2) => {
|
|
567
|
+
list.style.display = show2 ? "block" : "none";
|
|
568
|
+
btn.setAttribute("aria-expanded", String(show2));
|
|
163
569
|
};
|
|
164
570
|
const item = (label, cls, act) => {
|
|
165
571
|
const b = doc.createElement("button");
|
|
@@ -173,30 +579,30 @@ function createDock(opts) {
|
|
|
173
579
|
return b;
|
|
174
580
|
};
|
|
175
581
|
const rebuild = () => {
|
|
582
|
+
const open = /* @__PURE__ */ new Set([...api.panels.map((p) => p.id), ...[...drawers.values()].flatMap((d) => d.ids)]);
|
|
583
|
+
const listed = [...panels, ...[...open].filter((id) => !byId.has(id)).map((id) => defOf(id)).filter((d) => !!d)];
|
|
176
584
|
list.replaceChildren(
|
|
177
|
-
...
|
|
178
|
-
|
|
179
|
-
|
|
585
|
+
...listed.map((def) => {
|
|
586
|
+
const at = where(def.id);
|
|
587
|
+
return item(`${at ? "\u2713" : " "} ${def.title}${placementLabel(at)}`, "dock-panels-item", () => toggle(def.id));
|
|
588
|
+
}),
|
|
180
589
|
item(" Reset layout", "dock-panels-item dock-panels-reset", reset)
|
|
181
590
|
);
|
|
182
591
|
};
|
|
183
592
|
btn.addEventListener("click", () => {
|
|
184
|
-
const
|
|
185
|
-
if (
|
|
186
|
-
setOpen(
|
|
593
|
+
const show2 = list.style.display === "none";
|
|
594
|
+
if (show2) rebuild();
|
|
595
|
+
setOpen(show2);
|
|
187
596
|
});
|
|
188
|
-
const
|
|
189
|
-
if (!host.contains(e.target)) setOpen(false);
|
|
597
|
+
const close = (e) => {
|
|
598
|
+
if (e instanceof KeyboardEvent ? e.key === "Escape" : !host.contains(e.target)) setOpen(false);
|
|
190
599
|
};
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
};
|
|
194
|
-
doc.addEventListener("click", outside);
|
|
195
|
-
doc.addEventListener("keydown", escape);
|
|
600
|
+
doc.addEventListener("click", close);
|
|
601
|
+
doc.addEventListener("keydown", close);
|
|
196
602
|
host.append(btn, list);
|
|
197
603
|
const remove = () => {
|
|
198
|
-
doc.removeEventListener("click",
|
|
199
|
-
doc.removeEventListener("keydown",
|
|
604
|
+
doc.removeEventListener("click", close);
|
|
605
|
+
doc.removeEventListener("keydown", close);
|
|
200
606
|
btn.remove();
|
|
201
607
|
list.remove();
|
|
202
608
|
};
|
|
@@ -205,56 +611,36 @@ function createDock(opts) {
|
|
|
205
611
|
};
|
|
206
612
|
return {
|
|
207
613
|
api,
|
|
208
|
-
show
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
api.getPanel(id)?.api.setActive();
|
|
212
|
-
return true;
|
|
213
|
-
},
|
|
614
|
+
show,
|
|
615
|
+
place,
|
|
616
|
+
where,
|
|
214
617
|
toggle,
|
|
618
|
+
toggleDrawer(edge, open) {
|
|
619
|
+
const d = drawers.get(edge);
|
|
620
|
+
if (!d) return false;
|
|
621
|
+
d.setOpen(open ?? !d.open);
|
|
622
|
+
return d.open;
|
|
623
|
+
},
|
|
215
624
|
reset,
|
|
216
625
|
applyTheme,
|
|
217
626
|
panelsMenu,
|
|
218
627
|
dispose() {
|
|
219
628
|
if (disposed) return;
|
|
629
|
+
save();
|
|
220
630
|
disposed = true;
|
|
221
631
|
for (const c of cleanups.splice(0)) c();
|
|
222
|
-
|
|
632
|
+
for (const d of drawers.values()) {
|
|
633
|
+
for (const id of d.ids) {
|
|
634
|
+
const el = d.remove(id);
|
|
635
|
+
if (el) release?.(id, el);
|
|
636
|
+
}
|
|
637
|
+
d.dispose();
|
|
638
|
+
}
|
|
223
639
|
component.dispose();
|
|
224
640
|
}
|
|
225
641
|
};
|
|
226
642
|
}
|
|
227
643
|
|
|
228
|
-
// src/drawer.ts
|
|
229
|
-
var DRAWER_MIN = 280;
|
|
230
|
-
var DRAWER_MAX_FRAC = 0.9;
|
|
231
|
-
var DRAWER_DEFAULT = 420;
|
|
232
|
-
function clampSize(px, viewport, bounds = {}) {
|
|
233
|
-
const min = bounds.min ?? DRAWER_MIN;
|
|
234
|
-
const max = Math.max(min, Math.floor(viewport * (bounds.maxFrac ?? DRAWER_MAX_FRAC)));
|
|
235
|
-
return Math.min(max, Math.max(min, Math.round(px)));
|
|
236
|
-
}
|
|
237
|
-
function drawerSize(edge, pointer, viewport, bounds) {
|
|
238
|
-
const fromEdge = edge === "left" || edge === "top" ? pointer : viewport - pointer;
|
|
239
|
-
return clampSize(fromEdge, viewport, bounds);
|
|
240
|
-
}
|
|
241
|
-
function loadDrawerSize(storage, key, fallback = DRAWER_DEFAULT) {
|
|
242
|
-
let raw = null;
|
|
243
|
-
try {
|
|
244
|
-
raw = storage?.getItem(key) ?? null;
|
|
245
|
-
} catch {
|
|
246
|
-
return fallback;
|
|
247
|
-
}
|
|
248
|
-
const n = raw == null ? NaN : parseInt(raw, 10);
|
|
249
|
-
return Number.isFinite(n) && n > 0 ? n : fallback;
|
|
250
|
-
}
|
|
251
|
-
function saveDrawerSize(storage, key, px) {
|
|
252
|
-
try {
|
|
253
|
-
storage?.setItem(key, String(Math.round(px)));
|
|
254
|
-
} catch {
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
|
|
258
644
|
exports.DRAWER_DEFAULT = DRAWER_DEFAULT;
|
|
259
645
|
exports.DRAWER_MAX_FRAC = DRAWER_MAX_FRAC;
|
|
260
646
|
exports.DRAWER_MIN = DRAWER_MIN;
|