@panyam/tsappkit-dock 0.7.9 → 0.7.11
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 +7 -5
- package/dist/index.d.mts +64 -4
- package/dist/index.d.ts +64 -4
- package/dist/index.js +191 -46
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +189 -47
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/dock.ts +149 -34
- package/src/drawer.ts +27 -2
- package/src/drawerView.ts +121 -23
- package/src/index.ts +4 -1
package/README.md
CHANGED
|
@@ -6,17 +6,19 @@ 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.10` goes with `@panyam/tsappkit@0.7.10` and goapplib `v0.7.10`. 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
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
|
-
-
|
|
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. `dock.where(id)` also reports `{kind: "popout"}` for a panel popped out through `dock.api`.
|
|
15
|
+
- **`moved`.** Called after a panel ends up somewhere new, with its element in place. Its `documentChanged` flag is true on the way into a popout window and back, which is when a canvas needs rebuilding.
|
|
16
|
+
- **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. A drag below its minimum, or a finger flicked toward the edge, closes it. A `size` up to 1 is a share of the dock, `tabs: false` hides the tab strip, and `drawerChanged` reports each open, close and tab change. The saved layout keeps each drawer's panels, active tab, size and open state.
|
|
17
|
+
- **Phone pages.** One panel in the grid and the rest in a bottom drawer make a phone layout, with the app's own buttons calling `dock.show(id)`. This replaces tsappkit's deprecated `MobileBottomDrawer`. The [guide](https://panyam.github.io/goapplib/guide/dock/#phone-pages) has the setup.
|
|
16
18
|
- **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.
|
|
19
|
+
- **`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.10, loads as grid only.
|
|
18
20
|
- **`resolveTheme` and `documentTheme`** map `<html data-theme>` and the OS colour scheme to light or dark. The dock follows both by default.
|
|
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.
|
|
21
|
+
- **`drawerSize`, `clampSize`, `drawerPixels`, `closesOnRelease`, `loadDrawerSize` and `saveDrawerSize`** are the drawers' sizing and close rule, 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.
|
|
20
22
|
|
|
21
23
|
A three-panel page whose content is built before the dock:
|
|
22
24
|
|
package/dist/index.d.mts
CHANGED
|
@@ -24,6 +24,24 @@ declare function clampSize(px: number, viewport: number, bounds?: DrawerBounds):
|
|
|
24
24
|
* left or right drawer, and `clientY` and the height for a top or bottom one.
|
|
25
25
|
*/
|
|
26
26
|
declare function drawerSize(edge: DrawerEdge, pointer: number, viewport: number, bounds?: DrawerBounds): number;
|
|
27
|
+
/**
|
|
28
|
+
* Turns a configured or saved size into px against the viewport on the drawer's axis, clamped. A
|
|
29
|
+
* size up to 1 is a share of the viewport, so `0.65` makes a phone sheet that covers 65 percent of
|
|
30
|
+
* the screen whatever its height. A larger size is px.
|
|
31
|
+
*/
|
|
32
|
+
declare function drawerPixels(size: number, viewport: number, bounds?: DrawerBounds): number;
|
|
33
|
+
/**
|
|
34
|
+
* How fast, in px per ms toward the anchored edge, a touch drag has to be moving when it's let go
|
|
35
|
+
* to close the drawer wherever it ends.
|
|
36
|
+
*/
|
|
37
|
+
declare const DRAWER_FLICK = 0.5;
|
|
38
|
+
/**
|
|
39
|
+
* Whether letting go of a drag on a drawer's inner edge closes the drawer. It closes when the edge
|
|
40
|
+
* ends nearer the anchored edge than half of `min`, or when `speed` (px per ms toward the anchored
|
|
41
|
+
* edge, negative away from it) is over `DRAWER_FLICK`. Pass a speed of 0 for a mouse, so a quick
|
|
42
|
+
* resize on a desktop doesn't close anything.
|
|
43
|
+
*/
|
|
44
|
+
declare function closesOnRelease(fromEdge: number, min: number, speed: number): boolean;
|
|
27
45
|
/** The part of Web Storage drawer sizes need. A null storage means sizes aren't saved. */
|
|
28
46
|
interface DrawerStorage {
|
|
29
47
|
getItem(key: string): string | null;
|
|
@@ -39,8 +57,18 @@ declare function saveDrawerSize(storage: DrawerStorage | null, key: string, px:
|
|
|
39
57
|
|
|
40
58
|
/** Per-edge drawer settings for `createDock`. */
|
|
41
59
|
interface DrawerConfig extends DrawerBounds {
|
|
42
|
-
/**
|
|
60
|
+
/**
|
|
61
|
+
* The size when nothing is saved. Over 1 it's px. Up to 1 it's a share of the drawer host on
|
|
62
|
+
* the drawer's axis, so `0.65` makes a bottom sheet 65 percent of the dock's height. Default
|
|
63
|
+
* `DRAWER_DEFAULT`.
|
|
64
|
+
*/
|
|
43
65
|
size?: number;
|
|
66
|
+
/**
|
|
67
|
+
* Whether the drawer shows its tab strip. Default true. Turn it off when the app picks the panel
|
|
68
|
+
* with its own buttons, such as a phone page's bottom bar calling `dock.show(id)`. The panels are
|
|
69
|
+
* still tabs underneath, and the drawer still drags from its edge.
|
|
70
|
+
*/
|
|
71
|
+
tabs?: boolean;
|
|
44
72
|
}
|
|
45
73
|
|
|
46
74
|
/**
|
|
@@ -159,6 +187,23 @@ declare function resolveTheme(dataTheme: string | null, prefersDark: boolean): "
|
|
|
159
187
|
*/
|
|
160
188
|
declare function documentTheme(doc?: Document): "dark" | "light";
|
|
161
189
|
|
|
190
|
+
/**
|
|
191
|
+
* Where a panel is: a `Placement`, or a dockview popout window. Popouts come from `dock.api`, since
|
|
192
|
+
* the dock doesn't place panels there itself (see the dock experiments page for why).
|
|
193
|
+
*/
|
|
194
|
+
type PanelLocation = Placement | {
|
|
195
|
+
kind: "popout";
|
|
196
|
+
};
|
|
197
|
+
/** What `moved` gets besides the panel and its old and new place. */
|
|
198
|
+
interface MoveInfo {
|
|
199
|
+
/**
|
|
200
|
+
* True when the panel's element is in a different document from the last time the dock saw it,
|
|
201
|
+
* which happens on the way into a popout window and on the way back. A canvas can't draw again
|
|
202
|
+
* once the window it was in has closed, so rebuild canvases (and WebGL contexts) when this is
|
|
203
|
+
* true. Moves within one document leave canvases working.
|
|
204
|
+
*/
|
|
205
|
+
documentChanged: boolean;
|
|
206
|
+
}
|
|
162
207
|
/** What `createDock` needs. */
|
|
163
208
|
interface DockOptions {
|
|
164
209
|
/** The element dockview renders into. It needs a size, as dockview fills it. */
|
|
@@ -192,6 +237,21 @@ interface DockOptions {
|
|
|
192
237
|
* keeps the element. Clearing the layout, as `reset` does, calls it for every open panel.
|
|
193
238
|
*/
|
|
194
239
|
release?: (id: string, el: HTMLElement) => void;
|
|
240
|
+
/**
|
|
241
|
+
* Called after a panel ends up somewhere new, with its element already in place. `to` and
|
|
242
|
+
* `from` are where it is and where it was, and null means closed. It covers every way a panel
|
|
243
|
+
* moves: `place`, `show`, `toggle`, Reset layout, the reader dragging a tab into a float, a popout
|
|
244
|
+
* made through `dock.api`, and a popout window closing. It isn't called for the layout the dock
|
|
245
|
+
* starts with. See `MoveInfo.documentChanged` for the one move that breaks a canvas.
|
|
246
|
+
*/
|
|
247
|
+
moved?: (id: string, el: HTMLElement, to: PanelLocation | null, from: PanelLocation | null, info: MoveInfo) => void;
|
|
248
|
+
/**
|
|
249
|
+
* Called when a drawer opens, closes, or shows a different tab, with whether it's open and its
|
|
250
|
+
* active panel afterwards. A phone page uses it to highlight the button for the panel on show.
|
|
251
|
+
* It covers the reader's taps, drags and Escape as well as `show`, `place`, `toggleDrawer` and
|
|
252
|
+
* Reset layout, and isn't called for the drawers the dock starts with.
|
|
253
|
+
*/
|
|
254
|
+
drawerChanged?: (edge: DrawerEdge, open: boolean, active: string | undefined) => void;
|
|
195
255
|
/** Where the layout is saved, usually `localStorage`. Null or absent: nothing is saved. */
|
|
196
256
|
storage?: DockStorage | null;
|
|
197
257
|
/** The storage key. Required with `storage`. */
|
|
@@ -229,8 +289,8 @@ interface Dock {
|
|
|
229
289
|
* unknown id.
|
|
230
290
|
*/
|
|
231
291
|
place(id: string, target: Placement): boolean;
|
|
232
|
-
/** Where a panel is now, or null when it's closed. */
|
|
233
|
-
where(id: string):
|
|
292
|
+
/** Where a panel is now, or null when it's closed. A panel in a dockview popout reports `popout`. */
|
|
293
|
+
where(id: string): PanelLocation | null;
|
|
234
294
|
/** Opens a closed panel or closes an open one. False for an unknown id. */
|
|
235
295
|
toggle(id: string): boolean;
|
|
236
296
|
/**
|
|
@@ -271,4 +331,4 @@ interface Dock {
|
|
|
271
331
|
*/
|
|
272
332
|
declare function createDock(opts: DockOptions): Dock;
|
|
273
333
|
|
|
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 };
|
|
334
|
+
export { DRAWER_DEFAULT, DRAWER_FLICK, 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, closesOnRelease, createDock, documentTheme, drawerPixels, drawerSize, loadDrawerSize, loadLayout, panelsToPrune, panelsToReconcile, resolveTheme, saveDrawerSize, saveLayout };
|
package/dist/index.d.ts
CHANGED
|
@@ -24,6 +24,24 @@ declare function clampSize(px: number, viewport: number, bounds?: DrawerBounds):
|
|
|
24
24
|
* left or right drawer, and `clientY` and the height for a top or bottom one.
|
|
25
25
|
*/
|
|
26
26
|
declare function drawerSize(edge: DrawerEdge, pointer: number, viewport: number, bounds?: DrawerBounds): number;
|
|
27
|
+
/**
|
|
28
|
+
* Turns a configured or saved size into px against the viewport on the drawer's axis, clamped. A
|
|
29
|
+
* size up to 1 is a share of the viewport, so `0.65` makes a phone sheet that covers 65 percent of
|
|
30
|
+
* the screen whatever its height. A larger size is px.
|
|
31
|
+
*/
|
|
32
|
+
declare function drawerPixels(size: number, viewport: number, bounds?: DrawerBounds): number;
|
|
33
|
+
/**
|
|
34
|
+
* How fast, in px per ms toward the anchored edge, a touch drag has to be moving when it's let go
|
|
35
|
+
* to close the drawer wherever it ends.
|
|
36
|
+
*/
|
|
37
|
+
declare const DRAWER_FLICK = 0.5;
|
|
38
|
+
/**
|
|
39
|
+
* Whether letting go of a drag on a drawer's inner edge closes the drawer. It closes when the edge
|
|
40
|
+
* ends nearer the anchored edge than half of `min`, or when `speed` (px per ms toward the anchored
|
|
41
|
+
* edge, negative away from it) is over `DRAWER_FLICK`. Pass a speed of 0 for a mouse, so a quick
|
|
42
|
+
* resize on a desktop doesn't close anything.
|
|
43
|
+
*/
|
|
44
|
+
declare function closesOnRelease(fromEdge: number, min: number, speed: number): boolean;
|
|
27
45
|
/** The part of Web Storage drawer sizes need. A null storage means sizes aren't saved. */
|
|
28
46
|
interface DrawerStorage {
|
|
29
47
|
getItem(key: string): string | null;
|
|
@@ -39,8 +57,18 @@ declare function saveDrawerSize(storage: DrawerStorage | null, key: string, px:
|
|
|
39
57
|
|
|
40
58
|
/** Per-edge drawer settings for `createDock`. */
|
|
41
59
|
interface DrawerConfig extends DrawerBounds {
|
|
42
|
-
/**
|
|
60
|
+
/**
|
|
61
|
+
* The size when nothing is saved. Over 1 it's px. Up to 1 it's a share of the drawer host on
|
|
62
|
+
* the drawer's axis, so `0.65` makes a bottom sheet 65 percent of the dock's height. Default
|
|
63
|
+
* `DRAWER_DEFAULT`.
|
|
64
|
+
*/
|
|
43
65
|
size?: number;
|
|
66
|
+
/**
|
|
67
|
+
* Whether the drawer shows its tab strip. Default true. Turn it off when the app picks the panel
|
|
68
|
+
* with its own buttons, such as a phone page's bottom bar calling `dock.show(id)`. The panels are
|
|
69
|
+
* still tabs underneath, and the drawer still drags from its edge.
|
|
70
|
+
*/
|
|
71
|
+
tabs?: boolean;
|
|
44
72
|
}
|
|
45
73
|
|
|
46
74
|
/**
|
|
@@ -159,6 +187,23 @@ declare function resolveTheme(dataTheme: string | null, prefersDark: boolean): "
|
|
|
159
187
|
*/
|
|
160
188
|
declare function documentTheme(doc?: Document): "dark" | "light";
|
|
161
189
|
|
|
190
|
+
/**
|
|
191
|
+
* Where a panel is: a `Placement`, or a dockview popout window. Popouts come from `dock.api`, since
|
|
192
|
+
* the dock doesn't place panels there itself (see the dock experiments page for why).
|
|
193
|
+
*/
|
|
194
|
+
type PanelLocation = Placement | {
|
|
195
|
+
kind: "popout";
|
|
196
|
+
};
|
|
197
|
+
/** What `moved` gets besides the panel and its old and new place. */
|
|
198
|
+
interface MoveInfo {
|
|
199
|
+
/**
|
|
200
|
+
* True when the panel's element is in a different document from the last time the dock saw it,
|
|
201
|
+
* which happens on the way into a popout window and on the way back. A canvas can't draw again
|
|
202
|
+
* once the window it was in has closed, so rebuild canvases (and WebGL contexts) when this is
|
|
203
|
+
* true. Moves within one document leave canvases working.
|
|
204
|
+
*/
|
|
205
|
+
documentChanged: boolean;
|
|
206
|
+
}
|
|
162
207
|
/** What `createDock` needs. */
|
|
163
208
|
interface DockOptions {
|
|
164
209
|
/** The element dockview renders into. It needs a size, as dockview fills it. */
|
|
@@ -192,6 +237,21 @@ interface DockOptions {
|
|
|
192
237
|
* keeps the element. Clearing the layout, as `reset` does, calls it for every open panel.
|
|
193
238
|
*/
|
|
194
239
|
release?: (id: string, el: HTMLElement) => void;
|
|
240
|
+
/**
|
|
241
|
+
* Called after a panel ends up somewhere new, with its element already in place. `to` and
|
|
242
|
+
* `from` are where it is and where it was, and null means closed. It covers every way a panel
|
|
243
|
+
* moves: `place`, `show`, `toggle`, Reset layout, the reader dragging a tab into a float, a popout
|
|
244
|
+
* made through `dock.api`, and a popout window closing. It isn't called for the layout the dock
|
|
245
|
+
* starts with. See `MoveInfo.documentChanged` for the one move that breaks a canvas.
|
|
246
|
+
*/
|
|
247
|
+
moved?: (id: string, el: HTMLElement, to: PanelLocation | null, from: PanelLocation | null, info: MoveInfo) => void;
|
|
248
|
+
/**
|
|
249
|
+
* Called when a drawer opens, closes, or shows a different tab, with whether it's open and its
|
|
250
|
+
* active panel afterwards. A phone page uses it to highlight the button for the panel on show.
|
|
251
|
+
* It covers the reader's taps, drags and Escape as well as `show`, `place`, `toggleDrawer` and
|
|
252
|
+
* Reset layout, and isn't called for the drawers the dock starts with.
|
|
253
|
+
*/
|
|
254
|
+
drawerChanged?: (edge: DrawerEdge, open: boolean, active: string | undefined) => void;
|
|
195
255
|
/** Where the layout is saved, usually `localStorage`. Null or absent: nothing is saved. */
|
|
196
256
|
storage?: DockStorage | null;
|
|
197
257
|
/** The storage key. Required with `storage`. */
|
|
@@ -229,8 +289,8 @@ interface Dock {
|
|
|
229
289
|
* unknown id.
|
|
230
290
|
*/
|
|
231
291
|
place(id: string, target: Placement): boolean;
|
|
232
|
-
/** Where a panel is now, or null when it's closed. */
|
|
233
|
-
where(id: string):
|
|
292
|
+
/** Where a panel is now, or null when it's closed. A panel in a dockview popout reports `popout`. */
|
|
293
|
+
where(id: string): PanelLocation | null;
|
|
234
294
|
/** Opens a closed panel or closes an open one. False for an unknown id. */
|
|
235
295
|
toggle(id: string): boolean;
|
|
236
296
|
/**
|
|
@@ -271,4 +331,4 @@ interface Dock {
|
|
|
271
331
|
*/
|
|
272
332
|
declare function createDock(opts: DockOptions): Dock;
|
|
273
333
|
|
|
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 };
|
|
334
|
+
export { DRAWER_DEFAULT, DRAWER_FLICK, 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, closesOnRelease, createDock, documentTheme, drawerPixels, drawerSize, loadDrawerSize, loadLayout, panelsToPrune, panelsToReconcile, resolveTheme, saveDrawerSize, saveLayout };
|
package/dist/index.js
CHANGED
|
@@ -17,6 +17,13 @@ function drawerSize(edge, pointer, viewport, bounds) {
|
|
|
17
17
|
const fromEdge = edge === "left" || edge === "top" ? pointer : viewport - pointer;
|
|
18
18
|
return clampSize(fromEdge, viewport, bounds);
|
|
19
19
|
}
|
|
20
|
+
function drawerPixels(size, viewport, bounds) {
|
|
21
|
+
return clampSize(size <= 1 ? size * viewport : size, viewport, bounds);
|
|
22
|
+
}
|
|
23
|
+
var DRAWER_FLICK = 0.5;
|
|
24
|
+
function closesOnRelease(fromEdge, min, speed) {
|
|
25
|
+
return fromEdge < min / 2 || speed > DRAWER_FLICK;
|
|
26
|
+
}
|
|
20
27
|
function loadDrawerSize(storage, key, fallback = DRAWER_DEFAULT) {
|
|
21
28
|
let raw = null;
|
|
22
29
|
try {
|
|
@@ -38,6 +45,9 @@ function saveDrawerSize(storage, key, px) {
|
|
|
38
45
|
var Z_SCRIM = "calc(var(--dv-overlay-z-index, 999) + 200)";
|
|
39
46
|
var Z_DRAWER = "calc(var(--dv-overlay-z-index, 999) + 201)";
|
|
40
47
|
var HORIZONTAL = { left: true, right: true, top: false, bottom: false };
|
|
48
|
+
var TOWARD = { left: -1, right: 1, top: -1, bottom: 1 };
|
|
49
|
+
var DRAG_SLOP = 6;
|
|
50
|
+
var FLICK_WINDOW_MS = 100;
|
|
41
51
|
var DrawerView = class {
|
|
42
52
|
constructor(edge, host, config, hooks) {
|
|
43
53
|
this.edge = edge;
|
|
@@ -69,20 +79,25 @@ var DrawerView = class {
|
|
|
69
79
|
this.tabStrip = doc.createElement("div");
|
|
70
80
|
this.tabStrip.className = "dock-drawer-tabs";
|
|
71
81
|
this.tabStrip.setAttribute("role", "tablist");
|
|
72
|
-
Object.assign(this.tabStrip.style, { display: "flex", gap: "2px", alignItems: "center", flex: "none" });
|
|
82
|
+
Object.assign(this.tabStrip.style, { display: config.tabs === false ? "none" : "flex", gap: "2px", alignItems: "center", flex: "none" });
|
|
73
83
|
this.body = doc.createElement("div");
|
|
74
84
|
this.body.className = "dock-drawer-body";
|
|
75
85
|
Object.assign(this.body.style, { flex: "1", minHeight: "0", overflow: "auto", position: "relative" });
|
|
76
86
|
this.handle = doc.createElement("div");
|
|
77
87
|
this.handle.className = "dock-drawer-handle";
|
|
78
88
|
const inner = { left: "right", right: "left", top: "bottom", bottom: "top" }[edge];
|
|
89
|
+
const thick = doc.defaultView?.matchMedia?.("(pointer: coarse)").matches ? 24 : 6;
|
|
79
90
|
Object.assign(this.handle.style, {
|
|
80
91
|
position: "absolute",
|
|
81
|
-
[inner]:
|
|
82
|
-
...HORIZONTAL[edge] ? { top: "0", bottom: "0", width:
|
|
92
|
+
[inner]: `-${thick / 2}px`,
|
|
93
|
+
...HORIZONTAL[edge] ? { top: "0", bottom: "0", width: `${thick}px`, cursor: "col-resize" } : { left: "0", right: "0", height: `${thick}px`, cursor: "row-resize" },
|
|
83
94
|
touchAction: "none"
|
|
84
95
|
});
|
|
85
|
-
this.handle.addEventListener("pointerdown", (e) => this.drag(e));
|
|
96
|
+
this.handle.addEventListener("pointerdown", (e) => this.drag(e, 0));
|
|
97
|
+
if (edge === "bottom") {
|
|
98
|
+
this.tabStrip.style.touchAction = "none";
|
|
99
|
+
this.tabStrip.addEventListener("pointerdown", (e) => this.drag(e, DRAG_SLOP));
|
|
100
|
+
}
|
|
86
101
|
this.root.append(this.tabStrip, this.body, this.handle);
|
|
87
102
|
host.append(this.scrim, this.root);
|
|
88
103
|
this.applySize();
|
|
@@ -96,9 +111,19 @@ var DrawerView = class {
|
|
|
96
111
|
get open() {
|
|
97
112
|
return this.isOpen;
|
|
98
113
|
}
|
|
114
|
+
/** The size as configured, saved or dragged: px, or a share of the host when it's up to 1. */
|
|
99
115
|
get size() {
|
|
100
116
|
return this.px;
|
|
101
117
|
}
|
|
118
|
+
/** The size in px against the host as it is now, or unclamped while the host has no size. */
|
|
119
|
+
get pixels() {
|
|
120
|
+
const span = this.span();
|
|
121
|
+
return span > 0 ? drawerPixels(this.px, span, this.config) : this.px;
|
|
122
|
+
}
|
|
123
|
+
/** The element a panel in this drawer shows, or undefined if it isn't here. */
|
|
124
|
+
elementOf(id) {
|
|
125
|
+
return this.tabs.find((t) => t.id === id)?.el;
|
|
126
|
+
}
|
|
102
127
|
has(id) {
|
|
103
128
|
return this.tabs.some((t) => t.id === id);
|
|
104
129
|
}
|
|
@@ -167,8 +192,8 @@ var DrawerView = class {
|
|
|
167
192
|
if (show) this.applySize();
|
|
168
193
|
if (notify) this.hooks.changed();
|
|
169
194
|
}
|
|
170
|
-
setSize(
|
|
171
|
-
this.px = Math.round(
|
|
195
|
+
setSize(size, notify = true) {
|
|
196
|
+
this.px = size > 1 ? Math.round(size) : size;
|
|
172
197
|
this.applySize();
|
|
173
198
|
if (notify) this.hooks.changed();
|
|
174
199
|
}
|
|
@@ -179,31 +204,88 @@ var DrawerView = class {
|
|
|
179
204
|
this.scrim.remove();
|
|
180
205
|
this.root.remove();
|
|
181
206
|
}
|
|
207
|
+
span() {
|
|
208
|
+
const rect = this.host.getBoundingClientRect();
|
|
209
|
+
return HORIZONTAL[this.edge] ? rect.width : rect.height;
|
|
210
|
+
}
|
|
182
211
|
// Clamps against the host as it is now, so a drawer saved on a big window still fits a small one.
|
|
212
|
+
// A host with no size yet (not laid out) gets a share as a percentage and px unclamped.
|
|
183
213
|
applySize() {
|
|
184
|
-
const
|
|
185
|
-
const
|
|
186
|
-
|
|
187
|
-
this.root.style[HORIZONTAL[this.edge] ? "width" : "height"] = `${px}px`;
|
|
214
|
+
const span = this.span();
|
|
215
|
+
const css = span > 0 ? `${drawerPixels(this.px, span, this.config)}px` : this.px <= 1 ? `${this.px * 100}%` : `${this.px}px`;
|
|
216
|
+
this.root.style[HORIZONTAL[this.edge] ? "width" : "height"] = css;
|
|
188
217
|
}
|
|
189
|
-
drag
|
|
190
|
-
|
|
218
|
+
// A drag on the inner edge. It resizes while the edge is above `min`. Below it the drawer slides
|
|
219
|
+
// toward its edge under the pointer, and letting go there, or flicking a finger toward the edge,
|
|
220
|
+
// closes it at the size it had before the drag. `slop` is how far the pointer moves before this
|
|
221
|
+
// counts as a drag, so a tap on a tab in the strip still picks the tab.
|
|
222
|
+
drag(e, slop) {
|
|
223
|
+
if (e.button > 0) return;
|
|
224
|
+
const doc = this.host.ownerDocument;
|
|
225
|
+
const horizontal = HORIZONTAL[this.edge];
|
|
226
|
+
const toward = TOWARD[this.edge];
|
|
227
|
+
const touch = e.pointerType === "touch" || e.pointerType === "pen";
|
|
228
|
+
const min = this.config.min ?? DRAWER_MIN;
|
|
229
|
+
const at = (ev) => horizontal ? ev.clientX : ev.clientY;
|
|
230
|
+
const start = at(e);
|
|
231
|
+
const before = this.px;
|
|
232
|
+
let dragging = false;
|
|
233
|
+
let fromEdge = Number.NaN;
|
|
234
|
+
let last = { pos: start, t: e.timeStamp };
|
|
235
|
+
let speed = 0;
|
|
236
|
+
const begin = () => {
|
|
237
|
+
dragging = true;
|
|
238
|
+
this.root.classList.add("dock-drawer-resizing");
|
|
239
|
+
};
|
|
240
|
+
if (slop === 0) {
|
|
241
|
+
e.preventDefault();
|
|
242
|
+
begin();
|
|
243
|
+
}
|
|
191
244
|
const move = (ev) => {
|
|
245
|
+
const pos = at(ev);
|
|
246
|
+
if (!dragging) {
|
|
247
|
+
if (Math.abs(pos - start) < slop) return;
|
|
248
|
+
begin();
|
|
249
|
+
}
|
|
250
|
+
ev.preventDefault();
|
|
192
251
|
const rect = this.host.getBoundingClientRect();
|
|
193
|
-
const horizontal = HORIZONTAL[this.edge];
|
|
194
|
-
const pointer = horizontal ? ev.clientX - rect.left : ev.clientY - rect.top;
|
|
195
252
|
const span = horizontal ? rect.width : rect.height;
|
|
196
|
-
|
|
253
|
+
const pointer = pos - (horizontal ? rect.left : rect.top);
|
|
254
|
+
fromEdge = toward > 0 ? span - pointer : pointer;
|
|
255
|
+
const dt = ev.timeStamp - last.t;
|
|
256
|
+
if (dt > 0) speed = toward * (pos - last.pos) / dt;
|
|
257
|
+
last = { pos, t: ev.timeStamp };
|
|
258
|
+
const px = drawerPixels(fromEdge, span, this.config);
|
|
259
|
+
this.setSize(px, false);
|
|
260
|
+
const slide = Math.max(0, px - fromEdge);
|
|
261
|
+
this.root.style.transform = slide > 0 ? `translate${horizontal ? "X" : "Y"}(${toward * slide}px)` : "";
|
|
197
262
|
};
|
|
198
|
-
const
|
|
199
|
-
|
|
200
|
-
|
|
263
|
+
const end = (ev) => {
|
|
264
|
+
doc.removeEventListener("pointermove", move);
|
|
265
|
+
doc.removeEventListener("pointerup", end);
|
|
266
|
+
doc.removeEventListener("pointercancel", end);
|
|
267
|
+
if (!dragging) return;
|
|
201
268
|
this.root.classList.remove("dock-drawer-resizing");
|
|
269
|
+
this.root.style.transform = "";
|
|
270
|
+
if (slop > 0) {
|
|
271
|
+
const swallow = (c) => {
|
|
272
|
+
c.stopPropagation();
|
|
273
|
+
c.preventDefault();
|
|
274
|
+
};
|
|
275
|
+
this.tabStrip.addEventListener("click", swallow, { capture: true, once: true });
|
|
276
|
+
setTimeout(() => this.tabStrip.removeEventListener("click", swallow, { capture: true }), 0);
|
|
277
|
+
}
|
|
278
|
+
const fresh = ev.timeStamp - last.t <= FLICK_WINDOW_MS;
|
|
279
|
+
if (ev.type === "pointerup" && Number.isFinite(fromEdge) && closesOnRelease(fromEdge, min, touch && fresh ? speed : 0)) {
|
|
280
|
+
this.setSize(before, false);
|
|
281
|
+
this.setOpen(false);
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
202
284
|
this.hooks.changed();
|
|
203
285
|
};
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
286
|
+
doc.addEventListener("pointermove", move);
|
|
287
|
+
doc.addEventListener("pointerup", end);
|
|
288
|
+
doc.addEventListener("pointercancel", end);
|
|
207
289
|
}
|
|
208
290
|
};
|
|
209
291
|
|
|
@@ -256,7 +338,8 @@ function documentTheme(doc = document) {
|
|
|
256
338
|
|
|
257
339
|
// src/dock.ts
|
|
258
340
|
var EDGES = ["left", "right", "top", "bottom"];
|
|
259
|
-
var placementLabel = (p) => !p || p.kind === "grid" ? "" : p.kind === "
|
|
341
|
+
var placementLabel = (p) => !p || p.kind === "grid" ? "" : p.kind === "drawer" ? ` \xB7 ${p.edge} drawer` : ` \xB7 ${p.kind}`;
|
|
342
|
+
var TOWARD_EDGE = { left: "left", right: "right", top: "above", bottom: "below" };
|
|
260
343
|
function createDock(opts) {
|
|
261
344
|
const { container, panels, hostFor, release } = opts;
|
|
262
345
|
const storage = opts.storage ?? null;
|
|
@@ -301,14 +384,16 @@ function createDock(opts) {
|
|
|
301
384
|
if (d) return { kind: "drawer", edge: d.edge };
|
|
302
385
|
const panel = api.getPanel(id);
|
|
303
386
|
if (!panel) return null;
|
|
304
|
-
|
|
387
|
+
const type = panel.group.api.location.type;
|
|
388
|
+
return type === "floating" ? { kind: "float" } : type === "popout" ? { kind: "popout" } : { kind: "grid" };
|
|
305
389
|
};
|
|
390
|
+
const elementOf = (id) => drawerWith(id)?.elementOf(id) ?? api.getPanel(id)?.view.content.element;
|
|
306
391
|
const same = (a, b) => !!a && a.kind === b.kind && (a.kind !== "drawer" || b.kind === "drawer" && a.edge === b.edge);
|
|
307
392
|
const drawer = (edge) => {
|
|
308
393
|
let d = drawers.get(edge);
|
|
309
394
|
if (!d) {
|
|
310
395
|
if (doc.defaultView?.getComputedStyle(drawerHost).position === "static") drawerHost.style.position = "relative";
|
|
311
|
-
d = new DrawerView(edge, drawerHost, opts.drawers?.[edge] ?? {}, { changed: () =>
|
|
396
|
+
d = new DrawerView(edge, drawerHost, opts.drawers?.[edge] ?? {}, { changed: () => changed(), menu: (anchor, id) => moveMenu(anchor, id) });
|
|
312
397
|
drawers.set(edge, d);
|
|
313
398
|
}
|
|
314
399
|
return d;
|
|
@@ -319,11 +404,24 @@ function createDock(opts) {
|
|
|
319
404
|
return out;
|
|
320
405
|
};
|
|
321
406
|
const usable = (p) => !!p && (!p.referencePanel || !!api.getPanel(p.referencePanel));
|
|
322
|
-
const
|
|
407
|
+
const inGrid = (p) => !!p && (!p.referencePanel || api.getPanel(p.referencePanel)?.group.api.location.type === "grid" && api.getPanel(p.referencePanel).group.api.isVisible);
|
|
408
|
+
const addToGrid = (id, prefer) => {
|
|
323
409
|
const def = defOf(id);
|
|
324
410
|
const spec = specs?.find((s) => s.id === id);
|
|
325
|
-
const position = [def.position, spec?.position].find(
|
|
326
|
-
|
|
411
|
+
const position = [prefer, def.position, spec?.position].find(inGrid);
|
|
412
|
+
if (position) {
|
|
413
|
+
api.addPanel({ id, component: id, title: def.title, position });
|
|
414
|
+
return;
|
|
415
|
+
}
|
|
416
|
+
const showing = (g) => !!g && g.api.location.type === "grid" && g.api.isVisible;
|
|
417
|
+
const active = api.activeGroup;
|
|
418
|
+
const group = showing(active) ? active : api.groups.find(showing);
|
|
419
|
+
api.addPanel({
|
|
420
|
+
id,
|
|
421
|
+
component: id,
|
|
422
|
+
title: def.title,
|
|
423
|
+
position: group ? { referenceGroup: group, direction: "within" } : { direction: "right" }
|
|
424
|
+
});
|
|
327
425
|
};
|
|
328
426
|
const enter = (id, target) => {
|
|
329
427
|
if (target.kind === "drawer") {
|
|
@@ -353,33 +451,50 @@ function createDock(opts) {
|
|
|
353
451
|
}
|
|
354
452
|
api.getPanel(id)?.api.setActive();
|
|
355
453
|
};
|
|
454
|
+
const batch = (fn) => {
|
|
455
|
+
quiet++;
|
|
456
|
+
try {
|
|
457
|
+
fn();
|
|
458
|
+
} finally {
|
|
459
|
+
quiet--;
|
|
460
|
+
}
|
|
461
|
+
changed();
|
|
462
|
+
};
|
|
356
463
|
const place = (id, target) => {
|
|
357
464
|
if (!defOf(id)) return false;
|
|
465
|
+
batch(() => placeNow(id, target));
|
|
466
|
+
return true;
|
|
467
|
+
};
|
|
468
|
+
const placeNow = (id, target) => {
|
|
358
469
|
const now = where(id);
|
|
359
470
|
if (!same(now, target)) {
|
|
360
|
-
if (
|
|
361
|
-
|
|
471
|
+
if (now?.kind === "drawer" && target.kind === "grid") {
|
|
472
|
+
const size = drawer(now.edge).pixels;
|
|
473
|
+
leave(id);
|
|
474
|
+
addToGrid(id, { direction: TOWARD_EDGE[now.edge] });
|
|
475
|
+
const horizontal = now.edge === "left" || now.edge === "right";
|
|
476
|
+
api.getPanel(id)?.api.setSize(horizontal ? { width: size } : { height: size });
|
|
477
|
+
} else {
|
|
478
|
+
if (!(now?.kind === "grid" && target.kind === "float")) leave(id);
|
|
479
|
+
enter(id, target);
|
|
480
|
+
}
|
|
362
481
|
}
|
|
363
482
|
reveal(id);
|
|
364
|
-
save();
|
|
365
|
-
return true;
|
|
366
483
|
};
|
|
367
484
|
const show = (id) => {
|
|
368
485
|
const def = defOf(id);
|
|
369
486
|
if (!def) return false;
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
487
|
+
batch(() => {
|
|
488
|
+
if (!where(id)) enter(id, def.defaultPlacement ?? { kind: "grid" });
|
|
489
|
+
reveal(id);
|
|
490
|
+
});
|
|
373
491
|
return true;
|
|
374
492
|
};
|
|
375
493
|
const toggle = (id) => {
|
|
376
494
|
if (!defOf(id)) return false;
|
|
377
|
-
if (where(id))
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
return true;
|
|
381
|
-
}
|
|
382
|
-
return show(id);
|
|
495
|
+
if (!where(id)) return show(id);
|
|
496
|
+
batch(() => leave(id));
|
|
497
|
+
return true;
|
|
383
498
|
};
|
|
384
499
|
const applyDefault = () => {
|
|
385
500
|
const elsewhere = (def) => !!def?.defaultPlacement && def.defaultPlacement.kind === "drawer";
|
|
@@ -446,6 +561,34 @@ function createDock(opts) {
|
|
|
446
561
|
if (quiet || disposed || !storage) return;
|
|
447
562
|
saveLayout(storage, key, panels, api.toJSON(), drawerStates());
|
|
448
563
|
};
|
|
564
|
+
const seen = /* @__PURE__ */ new Map();
|
|
565
|
+
const key0 = (p) => JSON.stringify(p);
|
|
566
|
+
const drawerSeen = /* @__PURE__ */ new Map();
|
|
567
|
+
const sync = (notify = true) => {
|
|
568
|
+
if (disposed || quiet) return;
|
|
569
|
+
const ids = /* @__PURE__ */ new Set([...panels.map((p) => p.id), ...api.panels.map((p) => p.id), ...[...drawers.values()].flatMap((d) => d.ids), ...seen.keys()]);
|
|
570
|
+
for (const id of ids) {
|
|
571
|
+
if (!defOf(id)) continue;
|
|
572
|
+
const at = where(id);
|
|
573
|
+
const prev = seen.get(id);
|
|
574
|
+
const el = at ? elementOf(id) : prev?.el;
|
|
575
|
+
const doc2 = at && el ? el.ownerDocument : prev?.doc;
|
|
576
|
+
seen.set(id, { at, el, doc: doc2 });
|
|
577
|
+
if (!notify || !opts.moved || !el) continue;
|
|
578
|
+
if (key0(at) === key0(prev?.at ?? null) && doc2 === prev?.doc) continue;
|
|
579
|
+
opts.moved(id, el, at, prev?.at ?? null, { documentChanged: !!prev?.doc && doc2 !== prev.doc });
|
|
580
|
+
}
|
|
581
|
+
for (const [edge, d] of drawers) {
|
|
582
|
+
const now = `${d.open} ${d.active ?? ""}`;
|
|
583
|
+
const before = drawerSeen.get(edge) ?? "false ";
|
|
584
|
+
drawerSeen.set(edge, now);
|
|
585
|
+
if (notify && now !== before) opts.drawerChanged?.(edge, d.open, d.active);
|
|
586
|
+
}
|
|
587
|
+
};
|
|
588
|
+
const changed = () => {
|
|
589
|
+
save();
|
|
590
|
+
sync();
|
|
591
|
+
};
|
|
449
592
|
const reset = () => {
|
|
450
593
|
quiet++;
|
|
451
594
|
try {
|
|
@@ -456,7 +599,7 @@ function createDock(opts) {
|
|
|
456
599
|
} finally {
|
|
457
600
|
quiet--;
|
|
458
601
|
}
|
|
459
|
-
|
|
602
|
+
changed();
|
|
460
603
|
};
|
|
461
604
|
quiet++;
|
|
462
605
|
try {
|
|
@@ -464,11 +607,10 @@ function createDock(opts) {
|
|
|
464
607
|
} finally {
|
|
465
608
|
quiet--;
|
|
466
609
|
}
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
}
|
|
610
|
+
save();
|
|
611
|
+
sync(false);
|
|
612
|
+
const sub = api.onDidLayoutChange(() => changed());
|
|
613
|
+
cleanups.push(() => sub.dispose());
|
|
472
614
|
const applyTheme = () => component.updateOptions({ theme: theme() === "dark" ? dockviewCore.themeDark : dockviewCore.themeLight });
|
|
473
615
|
const view = doc.defaultView;
|
|
474
616
|
if (view?.MutationObserver) {
|
|
@@ -642,11 +784,14 @@ function createDock(opts) {
|
|
|
642
784
|
}
|
|
643
785
|
|
|
644
786
|
exports.DRAWER_DEFAULT = DRAWER_DEFAULT;
|
|
787
|
+
exports.DRAWER_FLICK = DRAWER_FLICK;
|
|
645
788
|
exports.DRAWER_MAX_FRAC = DRAWER_MAX_FRAC;
|
|
646
789
|
exports.DRAWER_MIN = DRAWER_MIN;
|
|
647
790
|
exports.clampSize = clampSize;
|
|
791
|
+
exports.closesOnRelease = closesOnRelease;
|
|
648
792
|
exports.createDock = createDock;
|
|
649
793
|
exports.documentTheme = documentTheme;
|
|
794
|
+
exports.drawerPixels = drawerPixels;
|
|
650
795
|
exports.drawerSize = drawerSize;
|
|
651
796
|
exports.loadDrawerSize = loadDrawerSize;
|
|
652
797
|
exports.loadLayout = loadLayout;
|