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