@panyam/tsappkit-dock 0.0.0-stage → 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/LICENSE +202 -0
- package/README.md +60 -2
- package/dist/index.d.mts +274 -0
- package/dist/index.d.ts +274 -0
- package/dist/index.js +659 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +644 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +55 -4
- package/src/dock.ts +566 -0
- package/src/drawer.ts +68 -0
- package/src/drawerView.ts +233 -0
- package/src/index.ts +30 -0
- package/src/layout.ts +174 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,61 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @panyam/tsappkit-dock
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A dock for IDE-like pages, built on [dockview-core](https://www.npmjs.com/package/dockview-core). You list your panels and a default arrangement. The dock restores the reader's saved layout, opens panels you added since it was saved, and keeps the ones the reader closed closed. Panel content lives outside dockview, so it survives a panel being closed and reopened.
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
npm install @panyam/tsappkit-dock dockview-core
|
|
7
|
+
```
|
|
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` 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
|
+
|
|
11
|
+
## What's in it
|
|
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 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.
|
|
18
|
+
- **`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.
|
|
20
|
+
|
|
21
|
+
A three-panel page whose content is built before the dock:
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
import { createDock } from "@panyam/tsappkit-dock";
|
|
25
|
+
|
|
26
|
+
const hosts = new Map(["files", "diff", "log"].map((id) => [id, document.getElementById(`panel-${id}`)!]));
|
|
27
|
+
const park = document.getElementById("park")!;
|
|
28
|
+
|
|
29
|
+
const dock = createDock({
|
|
30
|
+
container: document.getElementById("dock")!,
|
|
31
|
+
panels: [
|
|
32
|
+
{ id: "files", title: "Files" },
|
|
33
|
+
{ id: "diff", title: "Diff" },
|
|
34
|
+
{ id: "log", title: "Log", defaultOpen: false },
|
|
35
|
+
],
|
|
36
|
+
defaultLayout: [
|
|
37
|
+
{ id: "diff" },
|
|
38
|
+
{ id: "files", position: { direction: "left", referencePanel: "diff" } },
|
|
39
|
+
{ id: "log", position: { direction: "below", referencePanel: "diff" } },
|
|
40
|
+
],
|
|
41
|
+
hostFor: (id) => hosts.get(id)!,
|
|
42
|
+
release: (_id, el) => park.appendChild(el),
|
|
43
|
+
storage: localStorage,
|
|
44
|
+
key: "myapp-dock",
|
|
45
|
+
});
|
|
46
|
+
dock.panelsMenu(document.getElementById("toolbar")!);
|
|
47
|
+
```
|
|
48
|
+
|
|
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.
|
|
50
|
+
|
|
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.
|
|
52
|
+
|
|
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.
|
|
54
|
+
|
|
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.
|
|
58
|
+
|
|
59
|
+
## License
|
|
60
|
+
|
|
61
|
+
Apache-2.0
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
import { DockviewApi } from 'dockview-core';
|
|
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
|
+
|
|
46
|
+
/**
|
|
47
|
+
* One panel the app can show. The registry is a list of these in a stable order, and it is saved
|
|
48
|
+
* with every layout so a later load can tell a panel the app added since apart from one the reader
|
|
49
|
+
* closed.
|
|
50
|
+
*/
|
|
51
|
+
interface PanelDef {
|
|
52
|
+
/** The panel's dockview id. It is also its component name and its saved name, so keep it stable. */
|
|
53
|
+
id: string;
|
|
54
|
+
/** The tab label. */
|
|
55
|
+
title: string;
|
|
56
|
+
/**
|
|
57
|
+
* Whether a panel the registry gained after a layout was saved opens on that layout's next load.
|
|
58
|
+
* Default `true`. Set `false` for a panel that should appear only in the Panels menu, so a new
|
|
59
|
+
* feature doesn't crowd an existing reader's arrangement.
|
|
60
|
+
*/
|
|
61
|
+
defaultOpen?: boolean;
|
|
62
|
+
/**
|
|
63
|
+
* Where the panel opens when it isn't in the layout yet: from reconcile, `show`, or the Panels
|
|
64
|
+
* menu. When the reference panel isn't open, or this is absent, the panel's spec in the default
|
|
65
|
+
* layout is tried next, and then the grid root.
|
|
66
|
+
*/
|
|
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;
|
|
93
|
+
}
|
|
94
|
+
/** The saved drawers, by edge. An edge with no drawer is absent. */
|
|
95
|
+
type SavedDrawers = Partial<Record<DrawerEdge, SavedDrawer>>;
|
|
96
|
+
/** A dockview `addPanel` position: a direction from a panel that is already open. */
|
|
97
|
+
interface PanelPosition {
|
|
98
|
+
direction: "left" | "right" | "above" | "below" | "within";
|
|
99
|
+
referencePanel?: string;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* One `addPanel` call written as data. A default layout is a list of these, ordered so every
|
|
103
|
+
* `referencePanel` is added before something refers to it. A spec without a position anchors its
|
|
104
|
+
* panel at the grid root. `title` defaults to the registry's.
|
|
105
|
+
*/
|
|
106
|
+
interface PanelSpec {
|
|
107
|
+
id: string;
|
|
108
|
+
title?: string;
|
|
109
|
+
position?: PanelPosition;
|
|
110
|
+
}
|
|
111
|
+
/** The part of Web Storage the dock needs. `localStorage` satisfies it, and tests pass a fake. */
|
|
112
|
+
interface DockStorage {
|
|
113
|
+
getItem(key: string): string | null;
|
|
114
|
+
setItem(key: string, value: string): void;
|
|
115
|
+
removeItem(key: string): void;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* What `loadLayout` returns. `layout` is dockview's `toJSON()` blob. `savedPanels` is the registry
|
|
119
|
+
* when it was saved, and it is empty for a bare blob from before saves carried one.
|
|
120
|
+
*/
|
|
121
|
+
interface LoadedLayout {
|
|
122
|
+
layout: unknown;
|
|
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;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Saves dockview's `toJSON()` blob as `{v: 1, panels, layout}`, where `panels` is the registry's
|
|
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.
|
|
131
|
+
*/
|
|
132
|
+
declare function saveLayout(storage: DockStorage, key: string, registry: readonly PanelDef[], layout: unknown, drawers?: SavedDrawers): void;
|
|
133
|
+
/**
|
|
134
|
+
* Reads a saved layout. It returns null when nothing is saved or the save isn't JSON, and the
|
|
135
|
+
* caller applies its default layout in both cases. A bare dockview blob, saved before the registry
|
|
136
|
+
* was saved with it, loads with an empty `savedPanels`.
|
|
137
|
+
*/
|
|
138
|
+
declare function loadLayout(storage: DockStorage, key: string): LoadedLayout | null;
|
|
139
|
+
/**
|
|
140
|
+
* Returns the ids of panels to open on a restored layout. These are the registry's panels that
|
|
141
|
+
* the saved registry lacks and that don't have `defaultOpen: false`. A panel the reader closed was
|
|
142
|
+
* in the saved registry, so it stays closed. A bare save has an empty registry, so every panel
|
|
143
|
+
* counts as new once; the caller skips the ones the layout already has open.
|
|
144
|
+
*/
|
|
145
|
+
declare function panelsToReconcile(savedPanels: readonly string[], registry: readonly PanelDef[]): string[];
|
|
146
|
+
/**
|
|
147
|
+
* Returns the ids in `open` that the registry no longer has. A restored layout can name a panel a
|
|
148
|
+
* later release removed, and without pruning it shows as an empty tab.
|
|
149
|
+
*/
|
|
150
|
+
declare function panelsToPrune(open: readonly string[], registry: readonly PanelDef[]): string[];
|
|
151
|
+
/**
|
|
152
|
+
* Maps a page's theme setting to light or dark. A `data-theme` of `light` or `dark` wins, and
|
|
153
|
+
* anything else follows the OS, which the caller passes as `prefersDark`.
|
|
154
|
+
*/
|
|
155
|
+
declare function resolveTheme(dataTheme: string | null, prefersDark: boolean): "dark" | "light";
|
|
156
|
+
/**
|
|
157
|
+
* Reads `resolveTheme` off the document: `data-theme` on `<html>`, then `prefers-color-scheme`.
|
|
158
|
+
* It is `createDock`'s default `theme`.
|
|
159
|
+
*/
|
|
160
|
+
declare function documentTheme(doc?: Document): "dark" | "light";
|
|
161
|
+
|
|
162
|
+
/** What `createDock` needs. */
|
|
163
|
+
interface DockOptions {
|
|
164
|
+
/** The element dockview renders into. It needs a size, as dockview fills it. */
|
|
165
|
+
container: HTMLElement;
|
|
166
|
+
/** The panel registry, in a stable order. These are the panels the Panels menu lists. */
|
|
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;
|
|
175
|
+
/**
|
|
176
|
+
* The arrangement used when nothing is saved, after a rejected save, and on `reset`. Either
|
|
177
|
+
* `addPanel` specs as data, or a function that builds it on the api, for an app that sizes
|
|
178
|
+
* groups after adding them. Registry panels whose `defaultPlacement` is a drawer or a float go
|
|
179
|
+
* there afterwards, whichever form this takes.
|
|
180
|
+
*/
|
|
181
|
+
defaultLayout: readonly PanelSpec[] | ((api: DockviewApi) => void);
|
|
182
|
+
/**
|
|
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.
|
|
186
|
+
*/
|
|
187
|
+
hostFor: (id: string) => HTMLElement;
|
|
188
|
+
/**
|
|
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.
|
|
193
|
+
*/
|
|
194
|
+
release?: (id: string, el: HTMLElement) => void;
|
|
195
|
+
/** Where the layout is saved, usually `localStorage`. Null or absent: nothing is saved. */
|
|
196
|
+
storage?: DockStorage | null;
|
|
197
|
+
/** The storage key. Required with `storage`. */
|
|
198
|
+
key?: string;
|
|
199
|
+
/**
|
|
200
|
+
* Returns the dock's theme. It is read at creation, when `<html data-theme>` changes, when the
|
|
201
|
+
* OS colour scheme changes, and on `applyTheme()`. Default: `documentTheme()`.
|
|
202
|
+
*/
|
|
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;
|
|
216
|
+
}
|
|
217
|
+
/** A dock made by `createDock`. */
|
|
218
|
+
interface Dock {
|
|
219
|
+
/** The dockview api, for anything the dock doesn't wrap. */
|
|
220
|
+
readonly api: DockviewApi;
|
|
221
|
+
/**
|
|
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.
|
|
225
|
+
*/
|
|
226
|
+
show(id: string): boolean;
|
|
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. */
|
|
235
|
+
toggle(id: string): boolean;
|
|
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
|
+
*/
|
|
245
|
+
reset(): void;
|
|
246
|
+
/** Reads `theme` again and applies it. For a theme setting the dock doesn't watch. */
|
|
247
|
+
applyTheme(): void;
|
|
248
|
+
/**
|
|
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.
|
|
253
|
+
*/
|
|
254
|
+
panelsMenu(host: HTMLElement): () => void;
|
|
255
|
+
/**
|
|
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.
|
|
259
|
+
*/
|
|
260
|
+
dispose(): void;
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* Builds a dockview dock from a panel registry. It restores the saved layout when there is one,
|
|
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.
|
|
267
|
+
*
|
|
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.
|
|
271
|
+
*/
|
|
272
|
+
declare function createDock(opts: DockOptions): Dock;
|
|
273
|
+
|
|
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 };
|