@liberation-data/desk 0.38.0 → 0.39.0
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 +3 -1
- package/dist/css/windows.css +24 -0
- package/dist/desk.css +24 -0
- package/dist/react/split.d.ts +10 -5
- package/dist/react/split.d.ts.map +1 -1
- package/dist/react/split.js +26 -21
- package/dist/react/split.js.map +1 -1
- package/llms.txt +3 -2
- package/package.json +1 -1
- package/src/css/windows.css +24 -0
- package/src/react/split.tsx +39 -27
package/README.md
CHANGED
|
@@ -311,7 +311,9 @@ in this browser, so the section opens the way it was left.
|
|
|
311
311
|
|
|
312
312
|
`size` is where the side section starts (280px), `min` the narrowest it goes (200px), and `max` the most of
|
|
313
313
|
the window it may take, as CSS (`50%`), so a width remembered from a big screen still leaves room on a
|
|
314
|
-
small one. `at="end"` puts it on the right.
|
|
314
|
+
small one. `at="end"` puts it on the right. `orientation="vertical"` puts one above the other instead, such as an
|
|
315
|
+
editor over the results it runs: `at` is then the top or the bottom, the sizes are heights, and the edge moves up
|
|
316
|
+
and down. Dragging from one section to the other is the ordinary
|
|
315
317
|
`useDragSource` and `useDropTarget` (see [Dragging between windows](#dragging-between-windows)), which
|
|
316
318
|
works the same inside one window. The garage sample's Workshop window is Service beside Rides.
|
|
317
319
|
|
package/dist/css/windows.css
CHANGED
|
@@ -414,6 +414,30 @@
|
|
|
414
414
|
grid-template-columns: minmax(0, 1fr) auto var(--desk-split-size);
|
|
415
415
|
}
|
|
416
416
|
|
|
417
|
+
/* One above the other: the same, in rows. */
|
|
418
|
+
.desk-split[data-orientation="vertical"] {
|
|
419
|
+
grid-template-columns: minmax(0, 1fr);
|
|
420
|
+
grid-template-rows: var(--desk-split-size) auto minmax(0, 1fr);
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
.desk-split[data-orientation="vertical"][data-at="end"] {
|
|
424
|
+
grid-template-rows: minmax(0, 1fr) auto var(--desk-split-size);
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
.desk-split[data-orientation="vertical"] > .desk-split-edge {
|
|
428
|
+
width: auto;
|
|
429
|
+
height: 1px;
|
|
430
|
+
cursor: row-resize;
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
.desk-split[data-orientation="vertical"] > .desk-split-edge::before {
|
|
434
|
+
inset: -6px 0;
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
.desk-split[data-orientation="vertical"][data-dragging] {
|
|
438
|
+
cursor: row-resize;
|
|
439
|
+
}
|
|
440
|
+
|
|
417
441
|
.desk-split[data-dragging] {
|
|
418
442
|
user-select: none;
|
|
419
443
|
cursor: col-resize;
|
package/dist/desk.css
CHANGED
|
@@ -567,6 +567,30 @@
|
|
|
567
567
|
grid-template-columns: minmax(0, 1fr) auto var(--desk-split-size);
|
|
568
568
|
}
|
|
569
569
|
|
|
570
|
+
/* One above the other: the same, in rows. */
|
|
571
|
+
.desk-split[data-orientation="vertical"] {
|
|
572
|
+
grid-template-columns: minmax(0, 1fr);
|
|
573
|
+
grid-template-rows: var(--desk-split-size) auto minmax(0, 1fr);
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
.desk-split[data-orientation="vertical"][data-at="end"] {
|
|
577
|
+
grid-template-rows: minmax(0, 1fr) auto var(--desk-split-size);
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
.desk-split[data-orientation="vertical"] > .desk-split-edge {
|
|
581
|
+
width: auto;
|
|
582
|
+
height: 1px;
|
|
583
|
+
cursor: row-resize;
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
.desk-split[data-orientation="vertical"] > .desk-split-edge::before {
|
|
587
|
+
inset: -6px 0;
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
.desk-split[data-orientation="vertical"][data-dragging] {
|
|
591
|
+
cursor: row-resize;
|
|
592
|
+
}
|
|
593
|
+
|
|
570
594
|
.desk-split[data-dragging] {
|
|
571
595
|
user-select: none;
|
|
572
596
|
cursor: col-resize;
|
package/dist/react/split.d.ts
CHANGED
|
@@ -4,22 +4,27 @@ export interface SplitProps {
|
|
|
4
4
|
readonly side: ReactNode;
|
|
5
5
|
/** The rest of the window: what the side panel chooses for. */
|
|
6
6
|
readonly children: ReactNode;
|
|
7
|
-
/** Which edge the side panel stands at. Default `start`. */
|
|
7
|
+
/** Which edge the side panel stands at: the left or right, or with `orientation="vertical"` the top or bottom. Default `start`. */
|
|
8
8
|
readonly at?: 'start' | 'end';
|
|
9
|
-
/**
|
|
9
|
+
/**
|
|
10
|
+
* `horizontal` (the default) puts the panels side by side; `vertical` puts one above the other, as an editor
|
|
11
|
+
* over what it runs. The sizes are then heights, and the edge between them moves up and down.
|
|
12
|
+
*/
|
|
13
|
+
readonly orientation?: 'horizontal' | 'vertical';
|
|
14
|
+
/** The side panel's width, or height when vertical, in px, until it is dragged. Default 280. */
|
|
10
15
|
readonly size?: number;
|
|
11
16
|
/** The narrowest it can be dragged to. Default 200. */
|
|
12
17
|
readonly min?: number;
|
|
13
18
|
/**
|
|
14
|
-
* The most of the window it may take, as CSS: `50%` (the default), `420px`. A
|
|
19
|
+
* The most of the window it may take, as CSS: `50%` (the default), `420px`. A size remembered from
|
|
15
20
|
* a big screen never leaves a small one without room for the rest.
|
|
16
21
|
*/
|
|
17
22
|
readonly max?: string;
|
|
18
|
-
/** Remembers the
|
|
23
|
+
/** Remembers the size in this browser under this key, so the panel opens at the size it was left at. */
|
|
19
24
|
readonly remember?: string;
|
|
20
25
|
/** What the edge is called to assistive technology. Default "Resize". */
|
|
21
26
|
readonly label?: string;
|
|
22
27
|
readonly className?: string;
|
|
23
28
|
}
|
|
24
|
-
export declare function Split({ side, children, at, size, min, max, remember, label, className }: SplitProps): import("react").JSX.Element;
|
|
29
|
+
export declare function Split({ side, children, at, orientation, size, min, max, remember, label, className }: SplitProps): import("react").JSX.Element;
|
|
25
30
|
//# sourceMappingURL=split.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"split.d.ts","sourceRoot":"","sources":["../../src/react/split.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAmE,SAAS,EAAE,MAAM,OAAO,CAAA;AAYvG,MAAM,WAAW,UAAU;IACzB,2DAA2D;IAC3D,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAA;IACxB,+DAA+D;IAC/D,QAAQ,CAAC,QAAQ,EAAE,SAAS,CAAA;IAC5B,
|
|
1
|
+
{"version":3,"file":"split.d.ts","sourceRoot":"","sources":["../../src/react/split.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAmE,SAAS,EAAE,MAAM,OAAO,CAAA;AAYvG,MAAM,WAAW,UAAU;IACzB,2DAA2D;IAC3D,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAA;IACxB,+DAA+D;IAC/D,QAAQ,CAAC,QAAQ,EAAE,SAAS,CAAA;IAC5B,mIAAmI;IACnI,QAAQ,CAAC,EAAE,CAAC,EAAE,OAAO,GAAG,KAAK,CAAA;IAC7B;;;OAGG;IACH,QAAQ,CAAC,WAAW,CAAC,EAAE,YAAY,GAAG,UAAU,CAAA;IAChD,gGAAgG;IAChG,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAA;IACtB,uDAAuD;IACvD,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAA;IACrB;;;OAGG;IACH,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAA;IACrB,wGAAwG;IACxG,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;IAC1B,yEAAyE;IACzE,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAA;IACvB,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAA;CAC5B;AA2BD,wBAAgB,KAAK,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAY,EAAE,WAA0B,EAAE,IAAU,EAAE,GAAS,EAAE,GAAW,EAAE,QAAQ,EAAE,KAAgB,EAAE,SAAS,EAAE,EAAE,UAAU,+BA0GxK"}
|
package/dist/react/split.js
CHANGED
|
@@ -8,38 +8,41 @@ function recall(name, fallback, min) {
|
|
|
8
8
|
return fallback;
|
|
9
9
|
try {
|
|
10
10
|
const stored = Number(globalThis.localStorage?.getItem(key(name)));
|
|
11
|
-
// Storage is outside the program: anything that is not a usable
|
|
11
|
+
// Storage is outside the program: anything that is not a usable size is none.
|
|
12
12
|
return Number.isFinite(stored) && stored >= min ? stored : fallback;
|
|
13
13
|
}
|
|
14
14
|
catch {
|
|
15
15
|
return fallback;
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
|
-
function keep(name,
|
|
18
|
+
function keep(name, extent) {
|
|
19
19
|
if (!name)
|
|
20
20
|
return;
|
|
21
21
|
try {
|
|
22
|
-
globalThis.localStorage?.setItem(key(name), String(
|
|
22
|
+
globalThis.localStorage?.setItem(key(name), String(extent));
|
|
23
23
|
}
|
|
24
24
|
catch {
|
|
25
25
|
// Private windows and full storage: the panel still resizes, it just opens at its default.
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
|
-
export function Split({ side, children, at = 'start', size = 280, min = 200, max = '50%', remember, label = 'Resize', className }) {
|
|
28
|
+
export function Split({ side, children, at = 'start', orientation = 'horizontal', size = 280, min = 200, max = '50%', remember, label = 'Resize', className }) {
|
|
29
|
+
const vertical = orientation === 'vertical';
|
|
30
|
+
const measure = (box) => (vertical ? box?.height : box?.width);
|
|
29
31
|
const initial = Math.max(min, size);
|
|
30
|
-
|
|
32
|
+
// The side panel's width, or its height when vertical.
|
|
33
|
+
const [extent, setExtent] = useState(() => recall(remember, initial, min));
|
|
31
34
|
const root = useRef(null);
|
|
32
35
|
const panel = useRef(null);
|
|
33
36
|
const length = (px) => `min(${px}px, ${max})`;
|
|
34
37
|
const commit = (next) => {
|
|
35
38
|
const clamped = Math.max(min, Math.round(next));
|
|
36
|
-
|
|
39
|
+
setExtent(clamped);
|
|
37
40
|
keep(remember, clamped);
|
|
38
41
|
};
|
|
39
42
|
/*
|
|
40
43
|
* While dragging, only the variable on this element changes, so the panels follow the pointer
|
|
41
|
-
* without re-rendering what is in them; the
|
|
42
|
-
* the
|
|
44
|
+
* without re-rendering what is in them; the size is committed once, on release. It starts from
|
|
45
|
+
* the size as drawn, which `max` may have capped, so the edge never lags behind the pointer.
|
|
43
46
|
*/
|
|
44
47
|
const startDrag = (event) => {
|
|
45
48
|
if (event.button !== 0)
|
|
@@ -47,15 +50,16 @@ export function Split({ side, children, at = 'start', size = 280, min = 200, max
|
|
|
47
50
|
event.preventDefault();
|
|
48
51
|
const handle = event.currentTarget;
|
|
49
52
|
const element = root.current;
|
|
50
|
-
const origin = panel.current?.getBoundingClientRect()
|
|
51
|
-
const
|
|
53
|
+
const origin = measure(panel.current?.getBoundingClientRect()) ?? extent;
|
|
54
|
+
const start = vertical ? event.clientY : event.clientX;
|
|
52
55
|
let next = origin;
|
|
53
56
|
handle.setPointerCapture?.(event.pointerId);
|
|
54
57
|
if (element)
|
|
55
58
|
element.dataset.dragging = '';
|
|
56
59
|
const onMove = (move) => {
|
|
57
|
-
// Towards the middle is
|
|
58
|
-
const
|
|
60
|
+
// Towards the middle is bigger, whichever edge the panel is at.
|
|
61
|
+
const now = vertical ? move.clientY : move.clientX;
|
|
62
|
+
const pulled = at === 'start' ? now - start : start - now;
|
|
59
63
|
next = Math.max(min, origin + pulled);
|
|
60
64
|
element?.style.setProperty('--desk-split-size', length(next));
|
|
61
65
|
};
|
|
@@ -65,8 +69,8 @@ export function Split({ side, children, at = 'start', size = 280, min = 200, max
|
|
|
65
69
|
handle.removeEventListener('pointercancel', onUp);
|
|
66
70
|
if (element)
|
|
67
71
|
delete element.dataset.dragging;
|
|
68
|
-
// Back to what React drew, so the commit is what draws the new
|
|
69
|
-
element?.style.setProperty('--desk-split-size', length(
|
|
72
|
+
// Back to what React drew, so the commit is what draws the new size, and a click draws nothing.
|
|
73
|
+
element?.style.setProperty('--desk-split-size', length(extent));
|
|
70
74
|
if (Math.round(next) !== Math.round(origin))
|
|
71
75
|
commit(next);
|
|
72
76
|
};
|
|
@@ -74,11 +78,12 @@ export function Split({ side, children, at = 'start', size = 280, min = 200, max
|
|
|
74
78
|
handle.addEventListener('pointerup', onUp);
|
|
75
79
|
handle.addEventListener('pointercancel', onUp);
|
|
76
80
|
};
|
|
77
|
-
// The edge is a separator that can be focused, so the
|
|
81
|
+
// The edge is a separator that can be focused, so the size can be set without a pointer.
|
|
78
82
|
const onKeyDown = (event) => {
|
|
79
|
-
const
|
|
80
|
-
const
|
|
81
|
-
const
|
|
83
|
+
const [forward, back] = vertical ? ['ArrowDown', 'ArrowUp'] : ['ArrowRight', 'ArrowLeft'];
|
|
84
|
+
const wider = at === 'start' ? forward : back;
|
|
85
|
+
const narrower = at === 'start' ? back : forward;
|
|
86
|
+
const drawn = measure(panel.current?.getBoundingClientRect()) || extent;
|
|
82
87
|
if (event.key === wider)
|
|
83
88
|
commit(drawn + STEP);
|
|
84
89
|
else if (event.key === narrower)
|
|
@@ -92,10 +97,10 @@ export function Split({ side, children, at = 'start', size = 280, min = 200, max
|
|
|
92
97
|
event.preventDefault();
|
|
93
98
|
};
|
|
94
99
|
const sidePanel = (_jsx("div", { ref: panel, className: "desk-split-panel", "data-side": "", children: side }, "side"));
|
|
95
|
-
const edge = (_jsx("div", { role: "separator", "aria-orientation":
|
|
96
|
-
// Back to the
|
|
100
|
+
const edge = (_jsx("div", { role: "separator", "aria-orientation": vertical ? 'horizontal' : 'vertical', "aria-label": label, "aria-valuenow": extent, "aria-valuemin": min, tabIndex: 0, className: "desk-split-edge", onPointerDown: startDrag, onKeyDown: onKeyDown,
|
|
101
|
+
// Back to the size it started at, as a double-click on a divider does on a Mac.
|
|
97
102
|
onDoubleClick: () => commit(initial) }, "edge"));
|
|
98
103
|
const main = (_jsx("div", { className: "desk-split-panel", children: children }, "main"));
|
|
99
|
-
return (_jsx("div", { ref: root, className: ['desk-split', className].filter(Boolean).join(' '), "data-at": at, style: { '--desk-split-size': length(
|
|
104
|
+
return (_jsx("div", { ref: root, className: ['desk-split', className].filter(Boolean).join(' '), "data-at": at, "data-orientation": orientation, style: { '--desk-split-size': length(extent) }, children: at === 'start' ? [sidePanel, edge, main] : [main, edge, sidePanel] }));
|
|
100
105
|
}
|
|
101
106
|
//# sourceMappingURL=split.js.map
|
package/dist/react/split.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"split.js","sourceRoot":"","sources":["../../src/react/split.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;
|
|
1
|
+
{"version":3,"file":"split.js","sourceRoot":"","sources":["../../src/react/split.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAyCxC,2CAA2C;AAC3C,MAAM,IAAI,GAAG,EAAE,CAAA;AAEf,MAAM,GAAG,GAAG,CAAC,IAAY,EAAE,EAAE,CAAC,cAAc,IAAI,EAAE,CAAA;AAElD,SAAS,MAAM,CAAC,IAAwB,EAAE,QAAgB,EAAE,GAAW;IACrE,IAAI,CAAC,IAAI;QAAE,OAAO,QAAQ,CAAA;IAC1B,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,MAAM,CAAC,UAAU,CAAC,YAAY,EAAE,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;QAClE,8EAA8E;QAC9E,OAAO,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,MAAM,IAAI,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAA;IACrE,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,QAAQ,CAAA;IACjB,CAAC;AACH,CAAC;AAED,SAAS,IAAI,CAAC,IAAwB,EAAE,MAAc;IACpD,IAAI,CAAC,IAAI;QAAE,OAAM;IACjB,IAAI,CAAC;QACH,UAAU,CAAC,YAAY,EAAE,OAAO,CAAC,GAAG,CAA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AC,CAAC,SAAS,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,SAAS,CAAC,GAC/D,CACP,CAAA;AACH,CAAC"}
|
package/llms.txt
CHANGED
|
@@ -299,10 +299,11 @@ window; `lazyWindow` retries its import on reload, unlike `React.lazy`, which ca
|
|
|
299
299
|
<PaneHeader title={ReactNode} actions?={ReactNode} /> // the pane's title and its Refresh, on one row
|
|
300
300
|
<Section title={ReactNode} actions?={ReactNode}>{content}</Section> // a titled group inside a pane
|
|
301
301
|
<Toolbar label?={string} trailing?={ReactNode}>{controls}</Toolbar> // className="desk-grow" takes spare room
|
|
302
|
-
<Split side={ReactNode} at?={'start'|'end'} size?={280} min?={200} max?={'50%'} remember?={key} label?={string}>{rest}</Split>
|
|
302
|
+
<Split side={ReactNode} at?={'start'|'end'} orientation?={'horizontal'|'vertical'} size?={280} min?={200} max?={'50%'} remember?={key} label?={string}>{rest}</Split>
|
|
303
303
|
// two sections of one app in one window, with a draggable edge between them (arrow keys, Home, Enter or
|
|
304
304
|
// double-click to reset); remember keeps the width in localStorage. Drag and drop between the sections is
|
|
305
|
-
// useDragSource/useDropTarget as anywhere else.
|
|
305
|
+
// useDragSource/useDropTarget as anywhere else. orientation="vertical" stacks them (at=start is the top) and
|
|
306
|
+
// the sizes are heights: an editor over what it runs. One app, one window: use this, not two windows side by side.
|
|
306
307
|
<Page label?={string} fill?>{long text}</Page> // a sheet for text read at length, on --desk-page; fill = at least the room's height
|
|
307
308
|
// --desk-page-tint (4% light, 5% dark) is how much --desk-accent is mixed into the page; 0% for the neutral alone.
|
|
308
309
|
// text size by class, never px: desk-text-body | desk-text-small | desk-text-caption, plus desk-text-muted.
|
package/package.json
CHANGED
package/src/css/windows.css
CHANGED
|
@@ -413,6 +413,30 @@
|
|
|
413
413
|
grid-template-columns: minmax(0, 1fr) auto var(--desk-split-size);
|
|
414
414
|
}
|
|
415
415
|
|
|
416
|
+
/* One above the other: the same, in rows. */
|
|
417
|
+
.desk-split[data-orientation="vertical"] {
|
|
418
|
+
grid-template-columns: minmax(0, 1fr);
|
|
419
|
+
grid-template-rows: var(--desk-split-size) auto minmax(0, 1fr);
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
.desk-split[data-orientation="vertical"][data-at="end"] {
|
|
423
|
+
grid-template-rows: minmax(0, 1fr) auto var(--desk-split-size);
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
.desk-split[data-orientation="vertical"] > .desk-split-edge {
|
|
427
|
+
width: auto;
|
|
428
|
+
height: 1px;
|
|
429
|
+
cursor: row-resize;
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
.desk-split[data-orientation="vertical"] > .desk-split-edge::before {
|
|
433
|
+
inset: -6px 0;
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
.desk-split[data-orientation="vertical"][data-dragging] {
|
|
437
|
+
cursor: row-resize;
|
|
438
|
+
}
|
|
439
|
+
|
|
416
440
|
.desk-split[data-dragging] {
|
|
417
441
|
user-select: none;
|
|
418
442
|
cursor: col-resize;
|
package/src/react/split.tsx
CHANGED
|
@@ -7,7 +7,7 @@ import type { CSSProperties, KeyboardEvent, PointerEvent as ReactPointerEvent, R
|
|
|
7
7
|
*
|
|
8
8
|
* They are one app, so they are one window: they open, close, minimize and move together, and
|
|
9
9
|
* nothing can pull them apart. Only the edge between them moves, and it is remembered, so the side
|
|
10
|
-
* panel opens at the
|
|
10
|
+
* panel opens at the size it was left at. Dragging things from one panel to the other is the
|
|
11
11
|
* ordinary drag and drop (`useDragSource`, `useDropTarget`), which does not care where its ends are.
|
|
12
12
|
*/
|
|
13
13
|
|
|
@@ -16,18 +16,23 @@ export interface SplitProps {
|
|
|
16
16
|
readonly side: ReactNode
|
|
17
17
|
/** The rest of the window: what the side panel chooses for. */
|
|
18
18
|
readonly children: ReactNode
|
|
19
|
-
/** Which edge the side panel stands at. Default `start`. */
|
|
19
|
+
/** Which edge the side panel stands at: the left or right, or with `orientation="vertical"` the top or bottom. Default `start`. */
|
|
20
20
|
readonly at?: 'start' | 'end'
|
|
21
|
-
/**
|
|
21
|
+
/**
|
|
22
|
+
* `horizontal` (the default) puts the panels side by side; `vertical` puts one above the other, as an editor
|
|
23
|
+
* over what it runs. The sizes are then heights, and the edge between them moves up and down.
|
|
24
|
+
*/
|
|
25
|
+
readonly orientation?: 'horizontal' | 'vertical'
|
|
26
|
+
/** The side panel's width, or height when vertical, in px, until it is dragged. Default 280. */
|
|
22
27
|
readonly size?: number
|
|
23
28
|
/** The narrowest it can be dragged to. Default 200. */
|
|
24
29
|
readonly min?: number
|
|
25
30
|
/**
|
|
26
|
-
* The most of the window it may take, as CSS: `50%` (the default), `420px`. A
|
|
31
|
+
* The most of the window it may take, as CSS: `50%` (the default), `420px`. A size remembered from
|
|
27
32
|
* a big screen never leaves a small one without room for the rest.
|
|
28
33
|
*/
|
|
29
34
|
readonly max?: string
|
|
30
|
-
/** Remembers the
|
|
35
|
+
/** Remembers the size in this browser under this key, so the panel opens at the size it was left at. */
|
|
31
36
|
readonly remember?: string
|
|
32
37
|
/** What the edge is called to assistive technology. Default "Resize". */
|
|
33
38
|
readonly label?: string
|
|
@@ -43,53 +48,57 @@ function recall(name: string | undefined, fallback: number, min: number): number
|
|
|
43
48
|
if (!name) return fallback
|
|
44
49
|
try {
|
|
45
50
|
const stored = Number(globalThis.localStorage?.getItem(key(name)))
|
|
46
|
-
// Storage is outside the program: anything that is not a usable
|
|
51
|
+
// Storage is outside the program: anything that is not a usable size is none.
|
|
47
52
|
return Number.isFinite(stored) && stored >= min ? stored : fallback
|
|
48
53
|
} catch {
|
|
49
54
|
return fallback
|
|
50
55
|
}
|
|
51
56
|
}
|
|
52
57
|
|
|
53
|
-
function keep(name: string | undefined,
|
|
58
|
+
function keep(name: string | undefined, extent: number) {
|
|
54
59
|
if (!name) return
|
|
55
60
|
try {
|
|
56
|
-
globalThis.localStorage?.setItem(key(name), String(
|
|
61
|
+
globalThis.localStorage?.setItem(key(name), String(extent))
|
|
57
62
|
} catch {
|
|
58
63
|
// Private windows and full storage: the panel still resizes, it just opens at its default.
|
|
59
64
|
}
|
|
60
65
|
}
|
|
61
66
|
|
|
62
|
-
export function Split({ side, children, at = 'start', size = 280, min = 200, max = '50%', remember, label = 'Resize', className }: SplitProps) {
|
|
67
|
+
export function Split({ side, children, at = 'start', orientation = 'horizontal', size = 280, min = 200, max = '50%', remember, label = 'Resize', className }: SplitProps) {
|
|
68
|
+
const vertical = orientation === 'vertical'
|
|
69
|
+
const measure = (box: DOMRect | undefined) => (vertical ? box?.height : box?.width)
|
|
63
70
|
const initial = Math.max(min, size)
|
|
64
|
-
|
|
71
|
+
// The side panel's width, or its height when vertical.
|
|
72
|
+
const [extent, setExtent] = useState(() => recall(remember, initial, min))
|
|
65
73
|
const root = useRef<HTMLDivElement>(null)
|
|
66
74
|
const panel = useRef<HTMLDivElement>(null)
|
|
67
75
|
const length = (px: number) => `min(${px}px, ${max})`
|
|
68
76
|
|
|
69
77
|
const commit = (next: number) => {
|
|
70
78
|
const clamped = Math.max(min, Math.round(next))
|
|
71
|
-
|
|
79
|
+
setExtent(clamped)
|
|
72
80
|
keep(remember, clamped)
|
|
73
81
|
}
|
|
74
82
|
|
|
75
83
|
/*
|
|
76
84
|
* While dragging, only the variable on this element changes, so the panels follow the pointer
|
|
77
|
-
* without re-rendering what is in them; the
|
|
78
|
-
* the
|
|
85
|
+
* without re-rendering what is in them; the size is committed once, on release. It starts from
|
|
86
|
+
* the size as drawn, which `max` may have capped, so the edge never lags behind the pointer.
|
|
79
87
|
*/
|
|
80
88
|
const startDrag = (event: ReactPointerEvent<HTMLDivElement>) => {
|
|
81
89
|
if (event.button !== 0) return
|
|
82
90
|
event.preventDefault()
|
|
83
91
|
const handle = event.currentTarget
|
|
84
92
|
const element = root.current
|
|
85
|
-
const origin = panel.current?.getBoundingClientRect()
|
|
86
|
-
const
|
|
93
|
+
const origin = measure(panel.current?.getBoundingClientRect()) ?? extent
|
|
94
|
+
const start = vertical ? event.clientY : event.clientX
|
|
87
95
|
let next = origin
|
|
88
96
|
handle.setPointerCapture?.(event.pointerId)
|
|
89
97
|
if (element) element.dataset.dragging = ''
|
|
90
98
|
const onMove = (move: PointerEvent) => {
|
|
91
|
-
// Towards the middle is
|
|
92
|
-
const
|
|
99
|
+
// Towards the middle is bigger, whichever edge the panel is at.
|
|
100
|
+
const now = vertical ? move.clientY : move.clientX
|
|
101
|
+
const pulled = at === 'start' ? now - start : start - now
|
|
93
102
|
next = Math.max(min, origin + pulled)
|
|
94
103
|
element?.style.setProperty('--desk-split-size', length(next))
|
|
95
104
|
}
|
|
@@ -98,8 +107,8 @@ export function Split({ side, children, at = 'start', size = 280, min = 200, max
|
|
|
98
107
|
handle.removeEventListener('pointerup', onUp)
|
|
99
108
|
handle.removeEventListener('pointercancel', onUp)
|
|
100
109
|
if (element) delete element.dataset.dragging
|
|
101
|
-
// Back to what React drew, so the commit is what draws the new
|
|
102
|
-
element?.style.setProperty('--desk-split-size', length(
|
|
110
|
+
// Back to what React drew, so the commit is what draws the new size, and a click draws nothing.
|
|
111
|
+
element?.style.setProperty('--desk-split-size', length(extent))
|
|
103
112
|
if (Math.round(next) !== Math.round(origin)) commit(next)
|
|
104
113
|
}
|
|
105
114
|
handle.addEventListener('pointermove', onMove)
|
|
@@ -107,11 +116,12 @@ export function Split({ side, children, at = 'start', size = 280, min = 200, max
|
|
|
107
116
|
handle.addEventListener('pointercancel', onUp)
|
|
108
117
|
}
|
|
109
118
|
|
|
110
|
-
// The edge is a separator that can be focused, so the
|
|
119
|
+
// The edge is a separator that can be focused, so the size can be set without a pointer.
|
|
111
120
|
const onKeyDown = (event: KeyboardEvent<HTMLDivElement>) => {
|
|
112
|
-
const
|
|
113
|
-
const
|
|
114
|
-
const
|
|
121
|
+
const [forward, back] = vertical ? ['ArrowDown', 'ArrowUp'] : ['ArrowRight', 'ArrowLeft']
|
|
122
|
+
const wider = at === 'start' ? forward : back
|
|
123
|
+
const narrower = at === 'start' ? back : forward
|
|
124
|
+
const drawn = measure(panel.current?.getBoundingClientRect()) || extent
|
|
115
125
|
if (event.key === wider) commit(drawn + STEP)
|
|
116
126
|
else if (event.key === narrower) commit(drawn - STEP)
|
|
117
127
|
else if (event.key === 'Home') commit(min)
|
|
@@ -129,15 +139,16 @@ export function Split({ side, children, at = 'start', size = 280, min = 200, max
|
|
|
129
139
|
<div
|
|
130
140
|
key="edge"
|
|
131
141
|
role="separator"
|
|
132
|
-
|
|
142
|
+
// The edge runs across the way the panels are laid out: a vertical edge between panels side by side.
|
|
143
|
+
aria-orientation={vertical ? 'horizontal' : 'vertical'}
|
|
133
144
|
aria-label={label}
|
|
134
|
-
aria-valuenow={
|
|
145
|
+
aria-valuenow={extent}
|
|
135
146
|
aria-valuemin={min}
|
|
136
147
|
tabIndex={0}
|
|
137
148
|
className="desk-split-edge"
|
|
138
149
|
onPointerDown={startDrag}
|
|
139
150
|
onKeyDown={onKeyDown}
|
|
140
|
-
// Back to the
|
|
151
|
+
// Back to the size it started at, as a double-click on a divider does on a Mac.
|
|
141
152
|
onDoubleClick={() => commit(initial)}
|
|
142
153
|
/>
|
|
143
154
|
)
|
|
@@ -152,7 +163,8 @@ export function Split({ side, children, at = 'start', size = 280, min = 200, max
|
|
|
152
163
|
ref={root}
|
|
153
164
|
className={['desk-split', className].filter(Boolean).join(' ')}
|
|
154
165
|
data-at={at}
|
|
155
|
-
|
|
166
|
+
data-orientation={orientation}
|
|
167
|
+
style={{ '--desk-split-size': length(extent) } as CSSProperties}
|
|
156
168
|
>
|
|
157
169
|
{/* In reading order, so Tab walks the panels the way they are drawn. */}
|
|
158
170
|
{at === 'start' ? [sidePanel, edge, main] : [main, edge, sidePanel]}
|