@panyam/tsappkit-dock 0.7.8 → 0.7.10
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 +12 -6
- package/dist/index.d.mts +163 -66
- package/dist/index.d.ts +163 -66
- package/dist/index.js +537 -94
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +537 -94
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/dock.ts +473 -82
- package/src/drawerView.ts +238 -0
- package/src/index.ts +5 -1
- package/src/layout.ts +37 -7
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,48 @@
|
|
|
1
1
|
import { DockviewApi } from 'dockview-core';
|
|
2
2
|
|
|
3
|
+
/** The page edge a drawer is anchored to. */
|
|
4
|
+
type DrawerEdge = "left" | "right" | "top" | "bottom";
|
|
5
|
+
/** The smallest a drawer gets, in px, unless the caller passes its own `min`. */
|
|
6
|
+
declare const DRAWER_MIN = 280;
|
|
7
|
+
/** The largest share of the viewport a drawer takes, unless the caller passes its own `maxFrac`. */
|
|
8
|
+
declare const DRAWER_MAX_FRAC = 0.9;
|
|
9
|
+
/** A drawer's size when nothing is saved. */
|
|
10
|
+
declare const DRAWER_DEFAULT = 420;
|
|
11
|
+
/** Bounds for `clampSize` and `drawerSize`. */
|
|
12
|
+
interface DrawerBounds {
|
|
13
|
+
min?: number;
|
|
14
|
+
maxFrac?: number;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Clamps `px` to `[min, viewport * maxFrac]` and rounds it. A viewport too small for the minimum
|
|
18
|
+
* gets the minimum, so the drawer can overflow a tiny window rather than vanish.
|
|
19
|
+
*/
|
|
20
|
+
declare function clampSize(px: number, viewport: number, bounds?: DrawerBounds): number;
|
|
21
|
+
/**
|
|
22
|
+
* Turns a drag on a drawer's inner edge into its size. The size is the distance from the pointer
|
|
23
|
+
* to the anchored edge, then clamped. Pass the pointer's `clientX` and the viewport's width for a
|
|
24
|
+
* left or right drawer, and `clientY` and the height for a top or bottom one.
|
|
25
|
+
*/
|
|
26
|
+
declare function drawerSize(edge: DrawerEdge, pointer: number, viewport: number, bounds?: DrawerBounds): number;
|
|
27
|
+
/** The part of Web Storage drawer sizes need. A null storage means sizes aren't saved. */
|
|
28
|
+
interface DrawerStorage {
|
|
29
|
+
getItem(key: string): string | null;
|
|
30
|
+
setItem(key: string, value: string): void;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Reads a saved size, or `fallback` when nothing is saved or the value isn't a positive number.
|
|
34
|
+
* It doesn't clamp, since the viewport may have changed; clamp against the live one when applying.
|
|
35
|
+
*/
|
|
36
|
+
declare function loadDrawerSize(storage: DrawerStorage | null, key: string, fallback?: number): number;
|
|
37
|
+
/** Saves a size, rounded. A storage that throws is ignored. */
|
|
38
|
+
declare function saveDrawerSize(storage: DrawerStorage | null, key: string, px: number): void;
|
|
39
|
+
|
|
40
|
+
/** Per-edge drawer settings for `createDock`. */
|
|
41
|
+
interface DrawerConfig extends DrawerBounds {
|
|
42
|
+
/** The size, in px, when nothing is saved. Default `DRAWER_DEFAULT`. */
|
|
43
|
+
size?: number;
|
|
44
|
+
}
|
|
45
|
+
|
|
3
46
|
/**
|
|
4
47
|
* One panel the app can show. The registry is a list of these in a stable order, and it is saved
|
|
5
48
|
* with every layout so a later load can tell a panel the app added since apart from one the reader
|
|
@@ -22,7 +65,34 @@ interface PanelDef {
|
|
|
22
65
|
* layout is tried next, and then the grid root.
|
|
23
66
|
*/
|
|
24
67
|
position?: PanelPosition;
|
|
68
|
+
/**
|
|
69
|
+
* Where the panel goes when it opens on its own: on first run, on reconcile, from `show`, and on
|
|
70
|
+
* Reset layout. Default `{kind: "grid"}`. A panel in the default layout's specs starts in the grid
|
|
71
|
+
* unless this says a drawer or float.
|
|
72
|
+
*/
|
|
73
|
+
defaultPlacement?: Placement;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Where a panel lives. `grid` is dockview's grid, `float` a dockview floating group over it, and
|
|
77
|
+
* `drawer` the drawer on that edge.
|
|
78
|
+
*/
|
|
79
|
+
type Placement = {
|
|
80
|
+
kind: "grid";
|
|
81
|
+
} | {
|
|
82
|
+
kind: "float";
|
|
83
|
+
} | {
|
|
84
|
+
kind: "drawer";
|
|
85
|
+
edge: DrawerEdge;
|
|
86
|
+
};
|
|
87
|
+
/** One drawer's saved state: its panels in tab order, the active one, its size, and whether it's open. */
|
|
88
|
+
interface SavedDrawer {
|
|
89
|
+
panels: string[];
|
|
90
|
+
active?: string;
|
|
91
|
+
size?: number;
|
|
92
|
+
open?: boolean;
|
|
25
93
|
}
|
|
94
|
+
/** The saved drawers, by edge. An edge with no drawer is absent. */
|
|
95
|
+
type SavedDrawers = Partial<Record<DrawerEdge, SavedDrawer>>;
|
|
26
96
|
/** A dockview `addPanel` position: a direction from a panel that is already open. */
|
|
27
97
|
interface PanelPosition {
|
|
28
98
|
direction: "left" | "right" | "above" | "below" | "within";
|
|
@@ -51,13 +121,15 @@ interface DockStorage {
|
|
|
51
121
|
interface LoadedLayout {
|
|
52
122
|
layout: unknown;
|
|
53
123
|
savedPanels: string[];
|
|
124
|
+
/** The drawers from a version 2 save. A version 1 or bare save has none, so it loads as grid only. */
|
|
125
|
+
drawers: SavedDrawers;
|
|
54
126
|
}
|
|
55
127
|
/**
|
|
56
128
|
* Saves dockview's `toJSON()` blob as `{v: 1, panels, layout}`, where `panels` is the registry's
|
|
57
|
-
* ids.
|
|
58
|
-
* layout just isn't saved.
|
|
129
|
+
* ids. With `drawers` it saves `{v: 2, panels, layout, drawers}`. A storage that throws (quota,
|
|
130
|
+
* private mode) is ignored, so the page keeps working and the layout just isn't saved.
|
|
59
131
|
*/
|
|
60
|
-
declare function saveLayout(storage: DockStorage, key: string, registry: readonly PanelDef[], layout: unknown): void;
|
|
132
|
+
declare function saveLayout(storage: DockStorage, key: string, registry: readonly PanelDef[], layout: unknown, drawers?: SavedDrawers): void;
|
|
61
133
|
/**
|
|
62
134
|
* Reads a saved layout. It returns null when nothing is saved or the save isn't JSON, and the
|
|
63
135
|
* caller applies its default layout in both cases. A bare dockview blob, saved before the registry
|
|
@@ -87,30 +159,64 @@ declare function resolveTheme(dataTheme: string | null, prefersDark: boolean): "
|
|
|
87
159
|
*/
|
|
88
160
|
declare function documentTheme(doc?: Document): "dark" | "light";
|
|
89
161
|
|
|
162
|
+
/**
|
|
163
|
+
* Where a panel is: a `Placement`, or a dockview popout window. Popouts come from `dock.api`, since
|
|
164
|
+
* the dock doesn't place panels there itself (see the dock experiments page for why).
|
|
165
|
+
*/
|
|
166
|
+
type PanelLocation = Placement | {
|
|
167
|
+
kind: "popout";
|
|
168
|
+
};
|
|
169
|
+
/** What `moved` gets besides the panel and its old and new place. */
|
|
170
|
+
interface MoveInfo {
|
|
171
|
+
/**
|
|
172
|
+
* True when the panel's element is in a different document from the last time the dock saw it,
|
|
173
|
+
* which happens on the way into a popout window and on the way back. A canvas can't draw again
|
|
174
|
+
* once the window it was in has closed, so rebuild canvases (and WebGL contexts) when this is
|
|
175
|
+
* true. Moves within one document leave canvases working.
|
|
176
|
+
*/
|
|
177
|
+
documentChanged: boolean;
|
|
178
|
+
}
|
|
90
179
|
/** What `createDock` needs. */
|
|
91
180
|
interface DockOptions {
|
|
92
181
|
/** The element dockview renders into. It needs a size, as dockview fills it. */
|
|
93
182
|
container: HTMLElement;
|
|
94
|
-
/** The panel registry, in a stable order.
|
|
183
|
+
/** The panel registry, in a stable order. These are the panels the Panels menu lists. */
|
|
95
184
|
panels: readonly PanelDef[];
|
|
185
|
+
/**
|
|
186
|
+
* Describes a panel the registry doesn't list, such as one per document the reader opens.
|
|
187
|
+
* Return undefined for an id that isn't one. A resolvable panel opens with `show(id)`, can be
|
|
188
|
+
* placed anywhere, and is kept when a saved layout names it. The Panels menu lists it while it's
|
|
189
|
+
* open.
|
|
190
|
+
*/
|
|
191
|
+
resolve?: (id: string) => PanelDef | undefined;
|
|
96
192
|
/**
|
|
97
193
|
* The arrangement used when nothing is saved, after a rejected save, and on `reset`. Either
|
|
98
194
|
* `addPanel` specs as data, or a function that builds it on the api, for an app that sizes
|
|
99
|
-
* groups after adding them.
|
|
195
|
+
* groups after adding them. Registry panels whose `defaultPlacement` is a drawer or a float go
|
|
196
|
+
* there afterwards, whichever form this takes.
|
|
100
197
|
*/
|
|
101
198
|
defaultLayout: readonly PanelSpec[] | ((api: DockviewApi) => void);
|
|
102
199
|
/**
|
|
103
|
-
* Returns the element a panel shows. The dock calls it each time the panel
|
|
104
|
-
*
|
|
105
|
-
* only called with registry
|
|
200
|
+
* Returns the element a panel shows. The dock calls it each time the panel arrives somewhere: in
|
|
201
|
+
* the grid, in a float, or in a drawer. Return the same element every time if its content should
|
|
202
|
+
* survive a move, a close and a reopen. It's only called with ids the registry or `resolve` knows.
|
|
106
203
|
*/
|
|
107
204
|
hostFor: (id: string) => HTMLElement;
|
|
108
205
|
/**
|
|
109
|
-
* Called when a panel leaves
|
|
110
|
-
*
|
|
111
|
-
*
|
|
206
|
+
* Called when a panel leaves where it was, with the element `hostFor` gave it, already detached.
|
|
207
|
+
* Closing a panel calls it, and so does moving it between the grid and a drawer, before `hostFor`
|
|
208
|
+
* is called for the new place. Moving it between the grid and a float doesn't, since dockview
|
|
209
|
+
* keeps the element. Clearing the layout, as `reset` does, calls it for every open panel.
|
|
112
210
|
*/
|
|
113
211
|
release?: (id: string, el: HTMLElement) => void;
|
|
212
|
+
/**
|
|
213
|
+
* Called after a panel ends up somewhere new, with its element already in place. `to` and
|
|
214
|
+
* `from` are where it is and where it was, and null means closed. It covers every way a panel
|
|
215
|
+
* moves: `place`, `show`, `toggle`, Reset layout, the reader dragging a tab into a float, a popout
|
|
216
|
+
* made through `dock.api`, and a popout window closing. It isn't called for the layout the dock
|
|
217
|
+
* starts with. See `MoveInfo.documentChanged` for the one move that breaks a canvas.
|
|
218
|
+
*/
|
|
219
|
+
moved?: (id: string, el: HTMLElement, to: PanelLocation | null, from: PanelLocation | null, info: MoveInfo) => void;
|
|
114
220
|
/** Where the layout is saved, usually `localStorage`. Null or absent: nothing is saved. */
|
|
115
221
|
storage?: DockStorage | null;
|
|
116
222
|
/** The storage key. Required with `storage`. */
|
|
@@ -120,83 +226,74 @@ interface DockOptions {
|
|
|
120
226
|
* OS colour scheme changes, and on `applyTheme()`. Default: `documentTheme()`.
|
|
121
227
|
*/
|
|
122
228
|
theme?: () => "light" | "dark";
|
|
229
|
+
/** Each edge's drawer size and bounds. An edge left out gets the defaults from drawer.ts. */
|
|
230
|
+
drawers?: Partial<Record<DrawerEdge, DrawerConfig>>;
|
|
231
|
+
/**
|
|
232
|
+
* The element drawers are laid over, and the box their sizes are measured against. Default
|
|
233
|
+
* `container`. The dock makes it `position: relative` if it's static.
|
|
234
|
+
*/
|
|
235
|
+
drawerHost?: HTMLElement;
|
|
236
|
+
/**
|
|
237
|
+
* Whether each dockview group gets a ⋯ button with Dock, Float and the four drawers for its
|
|
238
|
+
* active panel. Default true. Drawer tabs always have one.
|
|
239
|
+
*/
|
|
240
|
+
moveMenu?: boolean;
|
|
123
241
|
}
|
|
124
242
|
/** A dock made by `createDock`. */
|
|
125
243
|
interface Dock {
|
|
126
244
|
/** The dockview api, for anything the dock doesn't wrap. */
|
|
127
245
|
readonly api: DockviewApi;
|
|
128
246
|
/**
|
|
129
|
-
* Brings a panel to the front, opening
|
|
130
|
-
* nothing, for an id
|
|
247
|
+
* Brings a panel to the front wherever it is, opening its drawer if it's in one. A closed panel
|
|
248
|
+
* opens at its `defaultPlacement`. It returns false, and does nothing, for an id that neither the
|
|
249
|
+
* registry nor `resolve` knows.
|
|
131
250
|
*/
|
|
132
251
|
show(id: string): boolean;
|
|
133
|
-
/**
|
|
252
|
+
/**
|
|
253
|
+
* Moves a panel to `target` and brings it to the front. A closed panel opens there. False for an
|
|
254
|
+
* unknown id.
|
|
255
|
+
*/
|
|
256
|
+
place(id: string, target: Placement): boolean;
|
|
257
|
+
/** Where a panel is now, or null when it's closed. A panel in a dockview popout reports `popout`. */
|
|
258
|
+
where(id: string): PanelLocation | null;
|
|
259
|
+
/** Opens a closed panel or closes an open one. False for an unknown id. */
|
|
134
260
|
toggle(id: string): boolean;
|
|
135
|
-
/**
|
|
261
|
+
/**
|
|
262
|
+
* Opens or closes the drawer on `edge`, or flips it when `open` is absent. An empty drawer stays
|
|
263
|
+
* closed. Returns whether it's open afterwards.
|
|
264
|
+
*/
|
|
265
|
+
toggleDrawer(edge: DrawerEdge, open?: boolean): boolean;
|
|
266
|
+
/**
|
|
267
|
+
* Forgets the saved layout and applies the default one, drawers included. Panels keep their
|
|
268
|
+
* `hostFor` elements.
|
|
269
|
+
*/
|
|
136
270
|
reset(): void;
|
|
137
271
|
/** Reads `theme` again and applies it. For a theme setting the dock doesn't watch. */
|
|
138
272
|
applyTheme(): void;
|
|
139
273
|
/**
|
|
140
|
-
* Adds a Panels menu button to `host`. Its list has one item per registry panel
|
|
141
|
-
* its panel, with a ✓ on the open ones
|
|
142
|
-
* it
|
|
143
|
-
*
|
|
274
|
+
* Adds a Panels menu button to `host`. Its list has one item per registry panel and per open
|
|
275
|
+
* resolved panel, each toggling its panel, with a ✓ on the open ones and where a panel is when
|
|
276
|
+
* it's not in the grid, and then Reset layout. Returns a function that removes it. The elements
|
|
277
|
+
* carry `dock-panels-*` classes and no styles beyond showing and hiding the list.
|
|
144
278
|
*/
|
|
145
279
|
panelsMenu(host: HTMLElement): () => void;
|
|
146
280
|
/**
|
|
147
|
-
* Saves the layout, stops watching the theme, removes
|
|
148
|
-
* dockview. Changes are otherwise saved a microtask after
|
|
149
|
-
* does nothing.
|
|
281
|
+
* Saves the layout, stops watching the theme, removes the menus and drawers, and disposes of
|
|
282
|
+
* dockview. Panels in drawers are released. Changes are otherwise saved a microtask after
|
|
283
|
+
* dockview reports them. A second call does nothing.
|
|
150
284
|
*/
|
|
151
285
|
dispose(): void;
|
|
152
286
|
}
|
|
153
287
|
/**
|
|
154
288
|
* Builds a dockview dock from a panel registry. It restores the saved layout when there is one,
|
|
155
|
-
* opens the panels added to the registry since it was saved, and closes the
|
|
156
|
-
*
|
|
157
|
-
* change after that is saved.
|
|
289
|
+
* drawers included, opens the panels added to the registry since it was saved, and closes the
|
|
290
|
+
* ones nothing knows any more. A save that dockview rejects is removed and the default layout
|
|
291
|
+
* applied. Every change after that is saved.
|
|
158
292
|
*
|
|
159
|
-
* Content lives outside dockview. `hostFor` hands an element to a panel when it
|
|
160
|
-
* and `release` hands it back when it leaves, so an app can keep a panel's content alive while
|
|
161
|
-
*
|
|
293
|
+
* Content lives outside dockview. `hostFor` hands an element to a panel when it arrives somewhere,
|
|
294
|
+
* and `release` hands it back when it leaves, so an app can keep a panel's content alive while the
|
|
295
|
+
* panel is closed or moving between the grid and a drawer.
|
|
162
296
|
*/
|
|
163
297
|
declare function createDock(opts: DockOptions): Dock;
|
|
164
298
|
|
|
165
|
-
|
|
166
|
-
type DrawerEdge = "left" | "right" | "top" | "bottom";
|
|
167
|
-
/** The smallest a drawer gets, in px, unless the caller passes its own `min`. */
|
|
168
|
-
declare const DRAWER_MIN = 280;
|
|
169
|
-
/** The largest share of the viewport a drawer takes, unless the caller passes its own `maxFrac`. */
|
|
170
|
-
declare const DRAWER_MAX_FRAC = 0.9;
|
|
171
|
-
/** A drawer's size when nothing is saved. */
|
|
172
|
-
declare const DRAWER_DEFAULT = 420;
|
|
173
|
-
/** Bounds for `clampSize` and `drawerSize`. */
|
|
174
|
-
interface DrawerBounds {
|
|
175
|
-
min?: number;
|
|
176
|
-
maxFrac?: number;
|
|
177
|
-
}
|
|
178
|
-
/**
|
|
179
|
-
* Clamps `px` to `[min, viewport * maxFrac]` and rounds it. A viewport too small for the minimum
|
|
180
|
-
* gets the minimum, so the drawer can overflow a tiny window rather than vanish.
|
|
181
|
-
*/
|
|
182
|
-
declare function clampSize(px: number, viewport: number, bounds?: DrawerBounds): number;
|
|
183
|
-
/**
|
|
184
|
-
* Turns a drag on a drawer's inner edge into its size. The size is the distance from the pointer
|
|
185
|
-
* to the anchored edge, then clamped. Pass the pointer's `clientX` and the viewport's width for a
|
|
186
|
-
* left or right drawer, and `clientY` and the height for a top or bottom one.
|
|
187
|
-
*/
|
|
188
|
-
declare function drawerSize(edge: DrawerEdge, pointer: number, viewport: number, bounds?: DrawerBounds): number;
|
|
189
|
-
/** The part of Web Storage drawer sizes need. A null storage means sizes aren't saved. */
|
|
190
|
-
interface DrawerStorage {
|
|
191
|
-
getItem(key: string): string | null;
|
|
192
|
-
setItem(key: string, value: string): void;
|
|
193
|
-
}
|
|
194
|
-
/**
|
|
195
|
-
* Reads a saved size, or `fallback` when nothing is saved or the value isn't a positive number.
|
|
196
|
-
* It doesn't clamp, since the viewport may have changed; clamp against the live one when applying.
|
|
197
|
-
*/
|
|
198
|
-
declare function loadDrawerSize(storage: DrawerStorage | null, key: string, fallback?: number): number;
|
|
199
|
-
/** Saves a size, rounded. A storage that throws is ignored. */
|
|
200
|
-
declare function saveDrawerSize(storage: DrawerStorage | null, key: string, px: number): void;
|
|
201
|
-
|
|
202
|
-
export { DRAWER_DEFAULT, DRAWER_MAX_FRAC, DRAWER_MIN, type Dock, type DockOptions, type DockStorage, type DrawerBounds, type DrawerEdge, type DrawerStorage, type LoadedLayout, type PanelDef, type PanelPosition, type PanelSpec, clampSize, createDock, documentTheme, drawerSize, loadDrawerSize, loadLayout, panelsToPrune, panelsToReconcile, resolveTheme, saveDrawerSize, saveLayout };
|
|
299
|
+
export { DRAWER_DEFAULT, DRAWER_MAX_FRAC, DRAWER_MIN, type Dock, type DockOptions, type DockStorage, type DrawerBounds, type DrawerConfig, type DrawerEdge, type DrawerStorage, type LoadedLayout, type MoveInfo, type PanelDef, type PanelLocation, type PanelPosition, type PanelSpec, type Placement, type SavedDrawer, type SavedDrawers, clampSize, createDock, documentTheme, drawerSize, loadDrawerSize, loadLayout, panelsToPrune, panelsToReconcile, resolveTheme, saveDrawerSize, saveLayout };
|