@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/README.md
CHANGED
|
@@ -6,14 +6,17 @@ A dock for IDE-like pages, built on [dockview-core](https://www.npmjs.com/packag
|
|
|
6
6
|
npm install @panyam/tsappkit-dock dockview-core
|
|
7
7
|
```
|
|
8
8
|
|
|
9
|
-
It needs `dockview-core` 4.13 or later, up to 8.x, and no UI framework. It shares one version with tsappkit and goapplib, so `@panyam/tsappkit-dock@0.7.
|
|
9
|
+
It needs `dockview-core` 4.13 or later, up to 8.x, and no UI framework. It shares one version with tsappkit and goapplib, so `@panyam/tsappkit-dock@0.7.9` goes with `@panyam/tsappkit@0.7.9` and goapplib `v0.7.9`. Load dockview's stylesheet in your page. dockview-core 4.13 to 7.x ship it as `dockview-core/dist/styles/dockview.css`. 8.x doesn't, and the same file comes in the `dockview` package as `dockview/dist/styles/dockview.css`.
|
|
10
10
|
|
|
11
11
|
## What's in it
|
|
12
12
|
|
|
13
|
-
- **`createDock`** builds the dock from a panel registry, a default layout, and `hostFor`, which returns the element each panel shows. `release` gets the element back when its panel leaves
|
|
14
|
-
-
|
|
13
|
+
- **`createDock`** builds the dock from a panel registry, a default layout, and `hostFor`, which returns the element each panel shows. `release` gets the element back when its panel leaves where it was. The returned dock has `show`, `place`, `where`, `toggle`, `toggleDrawer`, `reset`, `panelsMenu` (a Panels button with a toggle per panel and Reset layout) and `api`, the dockview api.
|
|
14
|
+
- **Placement.** A panel lives in the grid, in a floating group over it, or in the drawer on one of the four edges. `dock.place(id, {kind: "drawer", edge: "bottom"})` moves it, and so does the ⋯ menu on each group and each drawer tab. `PanelDef.defaultPlacement` says where a panel starts, and Reset layout puts it back there.
|
|
15
|
+
- **Drawers.** One per edge, laid over the dock with a scrim. A drawer holding several panels shows tabs. Escape or a click on the scrim closes it, and a drag on its inner edge resizes it. The saved layout keeps each drawer's panels, active tab, size and open state.
|
|
16
|
+
- **Panels added at runtime.** `resolve(id)` describes a panel the registry doesn't list, such as one per open document. `dock.show(id)` opens it, it can be placed anywhere, and a saved layout brings it back.
|
|
17
|
+
- **`saveLayout`, `loadLayout`, `panelsToReconcile` and `panelsToPrune`** are the saved-layout logic `createDock` uses, without dockview, for an app that drives dockview itself. A save is `{v: 2, panels, layout, drawers}`: `panels` is the registry when it was saved, which is how a later load tells a new panel from a closed one. A version 1 save, from 0.7.9, loads as grid only.
|
|
15
18
|
- **`resolveTheme` and `documentTheme`** map `<html data-theme>` and the OS colour scheme to light or dark. The dock follows both by default.
|
|
16
|
-
- **`drawerSize`, `clampSize`, `loadDrawerSize` and `saveDrawerSize`**
|
|
19
|
+
- **`drawerSize`, `clampSize`, `loadDrawerSize` and `saveDrawerSize`** are the drawers' sizing, for an app that builds its own: a size on any edge from a drag on its inner edge, clamped to a minimum and a share of the viewport.
|
|
17
20
|
|
|
18
21
|
A three-panel page whose content is built before the dock:
|
|
19
22
|
|
|
@@ -45,11 +48,13 @@ dock.panelsMenu(document.getElementById("toolbar")!);
|
|
|
45
48
|
|
|
46
49
|
`log` has `defaultOpen: false`, so a reader whose layout was saved before `log` existed finds it in the Panels menu rather than in their grid.
|
|
47
50
|
|
|
48
|
-
Panel content can be anything that renders into an element: plain DOM, Solid, or another framework. With Solid, mount once into the element `hostFor` returns, and return that same element every time. The dock calls `hostFor` whenever a panel
|
|
51
|
+
Panel content can be anything that renders into an element: plain DOM, Solid, or another framework. With Solid, mount once into the element `hostFor` returns, and return that same element every time. The dock calls `hostFor` whenever a panel arrives somewhere, and Solid's `render` appends, so rendering inside `hostFor` adds a second tree on each reopen. A closed panel's tree keeps running, since it's only detached. To tear it down, call `render`'s dispose function in `release` and build a fresh host next time.
|
|
49
52
|
|
|
50
53
|
A panel reopened from the Panels menu goes to its `PanelDef.position`, then to its spec in the default layout. The first panel in a default layout usually has no position, so give it one in its `PanelDef` if it should come back to the same place.
|
|
51
54
|
|
|
52
|
-
|
|
55
|
+
Moving a panel into or out of a drawer moves its element to a new parent, and the browser reloads an iframe when that happens. Moving between the grid and a float, or between tabs in the grid, doesn't, since dockview keeps panel content in a layer of its own. Keep iframes out of panels that go into drawers, or reload what they show.
|
|
56
|
+
|
|
57
|
+
The [dock guide](https://panyam.github.io/goapplib/guide/dock/) has a live demo whose panels are the docsite's own pages.
|
|
53
58
|
|
|
54
59
|
## License
|
|
55
60
|
|
package/dist/index.d.mts
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;
|
|
25
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;
|
|
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
|
|
@@ -91,24 +163,33 @@ declare function documentTheme(doc?: Document): "dark" | "light";
|
|
|
91
163
|
interface DockOptions {
|
|
92
164
|
/** The element dockview renders into. It needs a size, as dockview fills it. */
|
|
93
165
|
container: HTMLElement;
|
|
94
|
-
/** The panel registry, in a stable order.
|
|
166
|
+
/** The panel registry, in a stable order. These are the panels the Panels menu lists. */
|
|
95
167
|
panels: readonly PanelDef[];
|
|
168
|
+
/**
|
|
169
|
+
* Describes a panel the registry doesn't list, such as one per document the reader opens.
|
|
170
|
+
* Return undefined for an id that isn't one. A resolvable panel opens with `show(id)`, can be
|
|
171
|
+
* placed anywhere, and is kept when a saved layout names it. The Panels menu lists it while it's
|
|
172
|
+
* open.
|
|
173
|
+
*/
|
|
174
|
+
resolve?: (id: string) => PanelDef | undefined;
|
|
96
175
|
/**
|
|
97
176
|
* The arrangement used when nothing is saved, after a rejected save, and on `reset`. Either
|
|
98
177
|
* `addPanel` specs as data, or a function that builds it on the api, for an app that sizes
|
|
99
|
-
* groups after adding them.
|
|
178
|
+
* groups after adding them. Registry panels whose `defaultPlacement` is a drawer or a float go
|
|
179
|
+
* there afterwards, whichever form this takes.
|
|
100
180
|
*/
|
|
101
181
|
defaultLayout: readonly PanelSpec[] | ((api: DockviewApi) => void);
|
|
102
182
|
/**
|
|
103
|
-
* Returns the element a panel shows. The dock calls it each time the panel
|
|
104
|
-
*
|
|
105
|
-
* only called with registry
|
|
183
|
+
* Returns the element a panel shows. The dock calls it each time the panel arrives somewhere: in
|
|
184
|
+
* the grid, in a float, or in a drawer. Return the same element every time if its content should
|
|
185
|
+
* survive a move, a close and a reopen. It's only called with ids the registry or `resolve` knows.
|
|
106
186
|
*/
|
|
107
187
|
hostFor: (id: string) => HTMLElement;
|
|
108
188
|
/**
|
|
109
|
-
* Called when a panel leaves
|
|
110
|
-
*
|
|
111
|
-
*
|
|
189
|
+
* Called when a panel leaves where it was, with the element `hostFor` gave it, already detached.
|
|
190
|
+
* Closing a panel calls it, and so does moving it between the grid and a drawer, before `hostFor`
|
|
191
|
+
* is called for the new place. Moving it between the grid and a float doesn't, since dockview
|
|
192
|
+
* keeps the element. Clearing the layout, as `reset` does, calls it for every open panel.
|
|
112
193
|
*/
|
|
113
194
|
release?: (id: string, el: HTMLElement) => void;
|
|
114
195
|
/** Where the layout is saved, usually `localStorage`. Null or absent: nothing is saved. */
|
|
@@ -120,83 +201,74 @@ interface DockOptions {
|
|
|
120
201
|
* OS colour scheme changes, and on `applyTheme()`. Default: `documentTheme()`.
|
|
121
202
|
*/
|
|
122
203
|
theme?: () => "light" | "dark";
|
|
204
|
+
/** Each edge's drawer size and bounds. An edge left out gets the defaults from drawer.ts. */
|
|
205
|
+
drawers?: Partial<Record<DrawerEdge, DrawerConfig>>;
|
|
206
|
+
/**
|
|
207
|
+
* The element drawers are laid over, and the box their sizes are measured against. Default
|
|
208
|
+
* `container`. The dock makes it `position: relative` if it's static.
|
|
209
|
+
*/
|
|
210
|
+
drawerHost?: HTMLElement;
|
|
211
|
+
/**
|
|
212
|
+
* Whether each dockview group gets a ⋯ button with Dock, Float and the four drawers for its
|
|
213
|
+
* active panel. Default true. Drawer tabs always have one.
|
|
214
|
+
*/
|
|
215
|
+
moveMenu?: boolean;
|
|
123
216
|
}
|
|
124
217
|
/** A dock made by `createDock`. */
|
|
125
218
|
interface Dock {
|
|
126
219
|
/** The dockview api, for anything the dock doesn't wrap. */
|
|
127
220
|
readonly api: DockviewApi;
|
|
128
221
|
/**
|
|
129
|
-
* Brings a panel to the front, opening
|
|
130
|
-
* nothing, for an id
|
|
222
|
+
* Brings a panel to the front wherever it is, opening its drawer if it's in one. A closed panel
|
|
223
|
+
* opens at its `defaultPlacement`. It returns false, and does nothing, for an id that neither the
|
|
224
|
+
* registry nor `resolve` knows.
|
|
131
225
|
*/
|
|
132
226
|
show(id: string): boolean;
|
|
133
|
-
/**
|
|
227
|
+
/**
|
|
228
|
+
* Moves a panel to `target` and brings it to the front. A closed panel opens there. False for an
|
|
229
|
+
* unknown id.
|
|
230
|
+
*/
|
|
231
|
+
place(id: string, target: Placement): boolean;
|
|
232
|
+
/** Where a panel is now, or null when it's closed. */
|
|
233
|
+
where(id: string): Placement | null;
|
|
234
|
+
/** Opens a closed panel or closes an open one. False for an unknown id. */
|
|
134
235
|
toggle(id: string): boolean;
|
|
135
|
-
/**
|
|
236
|
+
/**
|
|
237
|
+
* Opens or closes the drawer on `edge`, or flips it when `open` is absent. An empty drawer stays
|
|
238
|
+
* closed. Returns whether it's open afterwards.
|
|
239
|
+
*/
|
|
240
|
+
toggleDrawer(edge: DrawerEdge, open?: boolean): boolean;
|
|
241
|
+
/**
|
|
242
|
+
* Forgets the saved layout and applies the default one, drawers included. Panels keep their
|
|
243
|
+
* `hostFor` elements.
|
|
244
|
+
*/
|
|
136
245
|
reset(): void;
|
|
137
246
|
/** Reads `theme` again and applies it. For a theme setting the dock doesn't watch. */
|
|
138
247
|
applyTheme(): void;
|
|
139
248
|
/**
|
|
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
|
-
*
|
|
249
|
+
* Adds a Panels menu button to `host`. Its list has one item per registry panel and per open
|
|
250
|
+
* resolved panel, each toggling its panel, with a ✓ on the open ones and where a panel is when
|
|
251
|
+
* it's not in the grid, and then Reset layout. Returns a function that removes it. The elements
|
|
252
|
+
* carry `dock-panels-*` classes and no styles beyond showing and hiding the list.
|
|
144
253
|
*/
|
|
145
254
|
panelsMenu(host: HTMLElement): () => void;
|
|
146
255
|
/**
|
|
147
|
-
* Saves the layout, stops watching the theme, removes
|
|
148
|
-
* dockview. Changes are otherwise saved a microtask after
|
|
149
|
-
* does nothing.
|
|
256
|
+
* Saves the layout, stops watching the theme, removes the menus and drawers, and disposes of
|
|
257
|
+
* dockview. Panels in drawers are released. Changes are otherwise saved a microtask after
|
|
258
|
+
* dockview reports them. A second call does nothing.
|
|
150
259
|
*/
|
|
151
260
|
dispose(): void;
|
|
152
261
|
}
|
|
153
262
|
/**
|
|
154
263
|
* 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.
|
|
264
|
+
* drawers included, opens the panels added to the registry since it was saved, and closes the
|
|
265
|
+
* ones nothing knows any more. A save that dockview rejects is removed and the default layout
|
|
266
|
+
* applied. Every change after that is saved.
|
|
158
267
|
*
|
|
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
|
-
*
|
|
268
|
+
* Content lives outside dockview. `hostFor` hands an element to a panel when it arrives somewhere,
|
|
269
|
+
* and `release` hands it back when it leaves, so an app can keep a panel's content alive while the
|
|
270
|
+
* panel is closed or moving between the grid and a drawer.
|
|
162
271
|
*/
|
|
163
272
|
declare function createDock(opts: DockOptions): Dock;
|
|
164
273
|
|
|
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 };
|
|
274
|
+
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 PanelDef, type PanelPosition, type PanelSpec, type Placement, type SavedDrawer, type SavedDrawers, clampSize, createDock, documentTheme, drawerSize, loadDrawerSize, loadLayout, panelsToPrune, panelsToReconcile, resolveTheme, saveDrawerSize, saveLayout };
|
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;
|
|
25
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;
|
|
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
|
|
@@ -91,24 +163,33 @@ declare function documentTheme(doc?: Document): "dark" | "light";
|
|
|
91
163
|
interface DockOptions {
|
|
92
164
|
/** The element dockview renders into. It needs a size, as dockview fills it. */
|
|
93
165
|
container: HTMLElement;
|
|
94
|
-
/** The panel registry, in a stable order.
|
|
166
|
+
/** The panel registry, in a stable order. These are the panels the Panels menu lists. */
|
|
95
167
|
panels: readonly PanelDef[];
|
|
168
|
+
/**
|
|
169
|
+
* Describes a panel the registry doesn't list, such as one per document the reader opens.
|
|
170
|
+
* Return undefined for an id that isn't one. A resolvable panel opens with `show(id)`, can be
|
|
171
|
+
* placed anywhere, and is kept when a saved layout names it. The Panels menu lists it while it's
|
|
172
|
+
* open.
|
|
173
|
+
*/
|
|
174
|
+
resolve?: (id: string) => PanelDef | undefined;
|
|
96
175
|
/**
|
|
97
176
|
* The arrangement used when nothing is saved, after a rejected save, and on `reset`. Either
|
|
98
177
|
* `addPanel` specs as data, or a function that builds it on the api, for an app that sizes
|
|
99
|
-
* groups after adding them.
|
|
178
|
+
* groups after adding them. Registry panels whose `defaultPlacement` is a drawer or a float go
|
|
179
|
+
* there afterwards, whichever form this takes.
|
|
100
180
|
*/
|
|
101
181
|
defaultLayout: readonly PanelSpec[] | ((api: DockviewApi) => void);
|
|
102
182
|
/**
|
|
103
|
-
* Returns the element a panel shows. The dock calls it each time the panel
|
|
104
|
-
*
|
|
105
|
-
* only called with registry
|
|
183
|
+
* Returns the element a panel shows. The dock calls it each time the panel arrives somewhere: in
|
|
184
|
+
* the grid, in a float, or in a drawer. Return the same element every time if its content should
|
|
185
|
+
* survive a move, a close and a reopen. It's only called with ids the registry or `resolve` knows.
|
|
106
186
|
*/
|
|
107
187
|
hostFor: (id: string) => HTMLElement;
|
|
108
188
|
/**
|
|
109
|
-
* Called when a panel leaves
|
|
110
|
-
*
|
|
111
|
-
*
|
|
189
|
+
* Called when a panel leaves where it was, with the element `hostFor` gave it, already detached.
|
|
190
|
+
* Closing a panel calls it, and so does moving it between the grid and a drawer, before `hostFor`
|
|
191
|
+
* is called for the new place. Moving it between the grid and a float doesn't, since dockview
|
|
192
|
+
* keeps the element. Clearing the layout, as `reset` does, calls it for every open panel.
|
|
112
193
|
*/
|
|
113
194
|
release?: (id: string, el: HTMLElement) => void;
|
|
114
195
|
/** Where the layout is saved, usually `localStorage`. Null or absent: nothing is saved. */
|
|
@@ -120,83 +201,74 @@ interface DockOptions {
|
|
|
120
201
|
* OS colour scheme changes, and on `applyTheme()`. Default: `documentTheme()`.
|
|
121
202
|
*/
|
|
122
203
|
theme?: () => "light" | "dark";
|
|
204
|
+
/** Each edge's drawer size and bounds. An edge left out gets the defaults from drawer.ts. */
|
|
205
|
+
drawers?: Partial<Record<DrawerEdge, DrawerConfig>>;
|
|
206
|
+
/**
|
|
207
|
+
* The element drawers are laid over, and the box their sizes are measured against. Default
|
|
208
|
+
* `container`. The dock makes it `position: relative` if it's static.
|
|
209
|
+
*/
|
|
210
|
+
drawerHost?: HTMLElement;
|
|
211
|
+
/**
|
|
212
|
+
* Whether each dockview group gets a ⋯ button with Dock, Float and the four drawers for its
|
|
213
|
+
* active panel. Default true. Drawer tabs always have one.
|
|
214
|
+
*/
|
|
215
|
+
moveMenu?: boolean;
|
|
123
216
|
}
|
|
124
217
|
/** A dock made by `createDock`. */
|
|
125
218
|
interface Dock {
|
|
126
219
|
/** The dockview api, for anything the dock doesn't wrap. */
|
|
127
220
|
readonly api: DockviewApi;
|
|
128
221
|
/**
|
|
129
|
-
* Brings a panel to the front, opening
|
|
130
|
-
* nothing, for an id
|
|
222
|
+
* Brings a panel to the front wherever it is, opening its drawer if it's in one. A closed panel
|
|
223
|
+
* opens at its `defaultPlacement`. It returns false, and does nothing, for an id that neither the
|
|
224
|
+
* registry nor `resolve` knows.
|
|
131
225
|
*/
|
|
132
226
|
show(id: string): boolean;
|
|
133
|
-
/**
|
|
227
|
+
/**
|
|
228
|
+
* Moves a panel to `target` and brings it to the front. A closed panel opens there. False for an
|
|
229
|
+
* unknown id.
|
|
230
|
+
*/
|
|
231
|
+
place(id: string, target: Placement): boolean;
|
|
232
|
+
/** Where a panel is now, or null when it's closed. */
|
|
233
|
+
where(id: string): Placement | null;
|
|
234
|
+
/** Opens a closed panel or closes an open one. False for an unknown id. */
|
|
134
235
|
toggle(id: string): boolean;
|
|
135
|
-
/**
|
|
236
|
+
/**
|
|
237
|
+
* Opens or closes the drawer on `edge`, or flips it when `open` is absent. An empty drawer stays
|
|
238
|
+
* closed. Returns whether it's open afterwards.
|
|
239
|
+
*/
|
|
240
|
+
toggleDrawer(edge: DrawerEdge, open?: boolean): boolean;
|
|
241
|
+
/**
|
|
242
|
+
* Forgets the saved layout and applies the default one, drawers included. Panels keep their
|
|
243
|
+
* `hostFor` elements.
|
|
244
|
+
*/
|
|
136
245
|
reset(): void;
|
|
137
246
|
/** Reads `theme` again and applies it. For a theme setting the dock doesn't watch. */
|
|
138
247
|
applyTheme(): void;
|
|
139
248
|
/**
|
|
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
|
-
*
|
|
249
|
+
* Adds a Panels menu button to `host`. Its list has one item per registry panel and per open
|
|
250
|
+
* resolved panel, each toggling its panel, with a ✓ on the open ones and where a panel is when
|
|
251
|
+
* it's not in the grid, and then Reset layout. Returns a function that removes it. The elements
|
|
252
|
+
* carry `dock-panels-*` classes and no styles beyond showing and hiding the list.
|
|
144
253
|
*/
|
|
145
254
|
panelsMenu(host: HTMLElement): () => void;
|
|
146
255
|
/**
|
|
147
|
-
* Saves the layout, stops watching the theme, removes
|
|
148
|
-
* dockview. Changes are otherwise saved a microtask after
|
|
149
|
-
* does nothing.
|
|
256
|
+
* Saves the layout, stops watching the theme, removes the menus and drawers, and disposes of
|
|
257
|
+
* dockview. Panels in drawers are released. Changes are otherwise saved a microtask after
|
|
258
|
+
* dockview reports them. A second call does nothing.
|
|
150
259
|
*/
|
|
151
260
|
dispose(): void;
|
|
152
261
|
}
|
|
153
262
|
/**
|
|
154
263
|
* 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.
|
|
264
|
+
* drawers included, opens the panels added to the registry since it was saved, and closes the
|
|
265
|
+
* ones nothing knows any more. A save that dockview rejects is removed and the default layout
|
|
266
|
+
* applied. Every change after that is saved.
|
|
158
267
|
*
|
|
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
|
-
*
|
|
268
|
+
* Content lives outside dockview. `hostFor` hands an element to a panel when it arrives somewhere,
|
|
269
|
+
* and `release` hands it back when it leaves, so an app can keep a panel's content alive while the
|
|
270
|
+
* panel is closed or moving between the grid and a drawer.
|
|
162
271
|
*/
|
|
163
272
|
declare function createDock(opts: DockOptions): Dock;
|
|
164
273
|
|
|
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 };
|
|
274
|
+
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 PanelDef, type PanelPosition, type PanelSpec, type Placement, type SavedDrawer, type SavedDrawers, clampSize, createDock, documentTheme, drawerSize, loadDrawerSize, loadLayout, panelsToPrune, panelsToReconcile, resolveTheme, saveDrawerSize, saveLayout };
|