@liberation-data/desk 0.37.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 +26 -0
- package/dist/css/windows.css +76 -0
- package/dist/desk.css +76 -0
- package/dist/react/index.d.ts +2 -0
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js +1 -0
- package/dist/react/index.js.map +1 -1
- package/dist/react/split.d.ts +30 -0
- package/dist/react/split.d.ts.map +1 -0
- package/dist/react/split.js +106 -0
- package/dist/react/split.js.map +1 -0
- package/llms.txt +5 -0
- package/package.json +1 -1
- package/src/css/windows.css +76 -0
- package/src/react/index.ts +2 -0
- package/src/react/split.tsx +173 -0
package/README.md
CHANGED
|
@@ -293,6 +293,30 @@ and a terminal's grey in a dark one. A trace of the accent is mixed into it, `--
|
|
|
293
293
|
sheet belongs to the theme it is read in; set that to `0%` for the neutral alone. `fill` makes it at least as tall as the room it is given, so a short
|
|
294
294
|
section is still a whole sheet.
|
|
295
295
|
|
|
296
|
+
### Two sections of one app: a split
|
|
297
|
+
|
|
298
|
+
```tsx
|
|
299
|
+
import { Split } from '@liberation-data/desk/react'
|
|
300
|
+
|
|
301
|
+
<Split side={<Catalogue />} remember="studio.explore">
|
|
302
|
+
<Canvas />
|
|
303
|
+
</Split>
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
A picker and the canvas it fills, or a list and its detail, are one app, so they are one window. Two windows
|
|
307
|
+
placed side by side drift apart and can be pulled apart. In a split they open, close and move together, and
|
|
308
|
+
only the edge between them moves. Drag the edge, or focus it and use the arrow keys. Home makes the side
|
|
309
|
+
section as narrow as it goes, and Enter or a double-click puts it back. With `remember`, the width is kept
|
|
310
|
+
in this browser, so the section opens the way it was left.
|
|
311
|
+
|
|
312
|
+
`size` is where the side section starts (280px), `min` the narrowest it goes (200px), and `max` the most of
|
|
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. `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
|
|
317
|
+
`useDragSource` and `useDropTarget` (see [Dragging between windows](#dragging-between-windows)), which
|
|
318
|
+
works the same inside one window. The garage sample's Workshop window is Service beside Rides.
|
|
319
|
+
|
|
296
320
|
`InfoTip` is an (i) holding what the view would explain if asked, so a window does not open with a
|
|
297
321
|
paragraph everyone reads once. Explanation only: a warning belongs in front of people, not behind a
|
|
298
322
|
disclosure.
|
|
@@ -502,6 +526,8 @@ content: the steps are the app's.
|
|
|
502
526
|
|
|
503
527
|
## Dragging between windows
|
|
504
528
|
|
|
529
|
+
The same hooks drag between the sections of one window, such as from a `Split`'s side section to the rest.
|
|
530
|
+
|
|
505
531
|
```tsx
|
|
506
532
|
// In the list — one source, because a hook cannot be called per row
|
|
507
533
|
const rides = useDragSource<Ride>({ type: 'ride' })
|
package/dist/css/windows.css
CHANGED
|
@@ -402,6 +402,82 @@
|
|
|
402
402
|
|
|
403
403
|
/* ── The inside of a window: controls that stay, content that scrolls ── */
|
|
404
404
|
|
|
405
|
+
/* Two panels in one window, and the edge between them that moves. */
|
|
406
|
+
.desk-split {
|
|
407
|
+
display: grid;
|
|
408
|
+
grid-template-columns: var(--desk-split-size) auto minmax(0, 1fr);
|
|
409
|
+
height: 100%;
|
|
410
|
+
min-height: 0;
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
.desk-split[data-at="end"] {
|
|
414
|
+
grid-template-columns: minmax(0, 1fr) auto var(--desk-split-size);
|
|
415
|
+
}
|
|
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
|
+
|
|
441
|
+
.desk-split[data-dragging] {
|
|
442
|
+
user-select: none;
|
|
443
|
+
cursor: col-resize;
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
.desk-split-panel {
|
|
447
|
+
display: flex;
|
|
448
|
+
flex-direction: column;
|
|
449
|
+
min-width: 0;
|
|
450
|
+
min-height: 0;
|
|
451
|
+
overflow: hidden;
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
/* A hairline to see, and a wider strip either side of it to catch. */
|
|
455
|
+
.desk-split-edge {
|
|
456
|
+
position: relative;
|
|
457
|
+
width: 1px;
|
|
458
|
+
background: var(--desk-rule);
|
|
459
|
+
cursor: col-resize;
|
|
460
|
+
touch-action: none;
|
|
461
|
+
outline: none;
|
|
462
|
+
/* Above the panels, so the strip it catches with is not covered by something positioned in them. */
|
|
463
|
+
z-index: 1;
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
/* 13px to catch with: a hairline you can see, and enough either side that you need not aim for it. */
|
|
467
|
+
.desk-split-edge::before {
|
|
468
|
+
content: "";
|
|
469
|
+
position: absolute;
|
|
470
|
+
inset: 0 -6px;
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
.desk-split-edge:hover,
|
|
474
|
+
.desk-split-edge:focus-visible,
|
|
475
|
+
.desk-split[data-dragging] > .desk-split-edge {
|
|
476
|
+
background: var(--desk-accent);
|
|
477
|
+
box-shadow: 0 0 0 1px var(--desk-accent);
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
|
|
405
481
|
.desk-pane {
|
|
406
482
|
display: flex;
|
|
407
483
|
flex-direction: column;
|
package/dist/desk.css
CHANGED
|
@@ -555,6 +555,82 @@
|
|
|
555
555
|
|
|
556
556
|
/* ── The inside of a window: controls that stay, content that scrolls ── */
|
|
557
557
|
|
|
558
|
+
/* Two panels in one window, and the edge between them that moves. */
|
|
559
|
+
.desk-split {
|
|
560
|
+
display: grid;
|
|
561
|
+
grid-template-columns: var(--desk-split-size) auto minmax(0, 1fr);
|
|
562
|
+
height: 100%;
|
|
563
|
+
min-height: 0;
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
.desk-split[data-at="end"] {
|
|
567
|
+
grid-template-columns: minmax(0, 1fr) auto var(--desk-split-size);
|
|
568
|
+
}
|
|
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
|
+
|
|
594
|
+
.desk-split[data-dragging] {
|
|
595
|
+
user-select: none;
|
|
596
|
+
cursor: col-resize;
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
.desk-split-panel {
|
|
600
|
+
display: flex;
|
|
601
|
+
flex-direction: column;
|
|
602
|
+
min-width: 0;
|
|
603
|
+
min-height: 0;
|
|
604
|
+
overflow: hidden;
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
/* A hairline to see, and a wider strip either side of it to catch. */
|
|
608
|
+
.desk-split-edge {
|
|
609
|
+
position: relative;
|
|
610
|
+
width: 1px;
|
|
611
|
+
background: var(--desk-rule);
|
|
612
|
+
cursor: col-resize;
|
|
613
|
+
touch-action: none;
|
|
614
|
+
outline: none;
|
|
615
|
+
/* Above the panels, so the strip it catches with is not covered by something positioned in them. */
|
|
616
|
+
z-index: 1;
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
/* 13px to catch with: a hairline you can see, and enough either side that you need not aim for it. */
|
|
620
|
+
.desk-split-edge::before {
|
|
621
|
+
content: "";
|
|
622
|
+
position: absolute;
|
|
623
|
+
inset: 0 -6px;
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
.desk-split-edge:hover,
|
|
627
|
+
.desk-split-edge:focus-visible,
|
|
628
|
+
.desk-split[data-dragging] > .desk-split-edge {
|
|
629
|
+
background: var(--desk-accent);
|
|
630
|
+
box-shadow: 0 0 0 1px var(--desk-accent);
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
|
|
558
634
|
.desk-pane {
|
|
559
635
|
display: flex;
|
|
560
636
|
flex-direction: column;
|
package/dist/react/index.d.ts
CHANGED
|
@@ -30,6 +30,8 @@ export { PageDots, pageWindow } from './pageDots.js';
|
|
|
30
30
|
export type { PageDot, PageDotsProps } from './pageDots.js';
|
|
31
31
|
export type { LedColor, LedProps } from './led.js';
|
|
32
32
|
export { Page, Pane, PaneHeader, Section, Toolbar } from './pane.js';
|
|
33
|
+
export { Split } from './split.js';
|
|
34
|
+
export type { SplitProps } from './split.js';
|
|
33
35
|
export type { PageProps, PaneHeaderProps, PaneProps, SectionProps, ToolbarProps } from './pane.js';
|
|
34
36
|
export { InfoTip } from './infoTip.js';
|
|
35
37
|
export type { InfoTipProps } from './infoTip.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/react/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAC1E,YAAY,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAClD,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,WAAW,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAChG,YAAY,EACV,OAAO,EACP,IAAI,EACJ,gBAAgB,EAChB,eAAe,EACf,UAAU,EACV,iBAAiB,EACjB,iBAAiB,EACjB,gBAAgB,GACjB,MAAM,UAAU,CAAA;AACjB,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AACtC,YAAY,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAChD,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AACxG,YAAY,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAA;AACrD,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AACnF,YAAY,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAA;AACtD,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AACtC,YAAY,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAC5D,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,eAAe,CAAA;AAC3D,OAAO,EAAE,gBAAgB,EAAE,MAA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AAO,EAAE,KAAK,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAC9E,YAAY,EAAE,UAAU,EAAE,YAAY,EAAE,mBAAmB,EAAE,UAAU,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AACjH,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,UAAU,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAC3G,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AACjD,YAAY,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAA;AACrG,YAAY,EAAE,IAAI,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAA;AAChE,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACxC,YAAY,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAChE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,QAAQ,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AAC/E,YAAY,EAAE,SAAS,EAAE,QAAQ,EAAE,QAAQ,EAAE,SAAS,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA"}
|
package/dist/react/index.js
CHANGED
|
@@ -15,6 +15,7 @@ export { useWindowInfo, useWindowNote } from './windowDescription.js';
|
|
|
15
15
|
export { Led } from './led.js';
|
|
16
16
|
export { PageDots, pageWindow } from './pageDots.js';
|
|
17
17
|
export { Page, Pane, PaneHeader, Section, Toolbar } from './pane.js';
|
|
18
|
+
export { Split } from './split.js';
|
|
18
19
|
export { InfoTip } from './infoTip.js';
|
|
19
20
|
export { Checklist, useTasks } from './tasks.js';
|
|
20
21
|
export { localSetupStore, useSetupProgress } from './setupProgress.js';
|
package/dist/react/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","s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AAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AAGjD,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAExC,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,QAAQ,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
export interface SplitProps {
|
|
3
|
+
/** The panel at the edge: a list, a picker, an outline. */
|
|
4
|
+
readonly side: ReactNode;
|
|
5
|
+
/** The rest of the window: what the side panel chooses for. */
|
|
6
|
+
readonly children: ReactNode;
|
|
7
|
+
/** Which edge the side panel stands at: the left or right, or with `orientation="vertical"` the top or bottom. Default `start`. */
|
|
8
|
+
readonly at?: 'start' | 'end';
|
|
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. */
|
|
15
|
+
readonly size?: number;
|
|
16
|
+
/** The narrowest it can be dragged to. Default 200. */
|
|
17
|
+
readonly min?: number;
|
|
18
|
+
/**
|
|
19
|
+
* The most of the window it may take, as CSS: `50%` (the default), `420px`. A size remembered from
|
|
20
|
+
* a big screen never leaves a small one without room for the rest.
|
|
21
|
+
*/
|
|
22
|
+
readonly max?: string;
|
|
23
|
+
/** Remembers the size in this browser under this key, so the panel opens at the size it was left at. */
|
|
24
|
+
readonly remember?: string;
|
|
25
|
+
/** What the edge is called to assistive technology. Default "Resize". */
|
|
26
|
+
readonly label?: string;
|
|
27
|
+
readonly className?: string;
|
|
28
|
+
}
|
|
29
|
+
export declare function Split({ side, children, at, orientation, size, min, max, remember, label, className }: SplitProps): import("react").JSX.Element;
|
|
30
|
+
//# sourceMappingURL=split.d.ts.map
|
|
@@ -0,0 +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,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"}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useRef, useState } from 'react';
|
|
3
|
+
/** How far an arrow key moves the edge. */
|
|
4
|
+
const STEP = 16;
|
|
5
|
+
const key = (name) => `desk.split.${name}`;
|
|
6
|
+
function recall(name, fallback, min) {
|
|
7
|
+
if (!name)
|
|
8
|
+
return fallback;
|
|
9
|
+
try {
|
|
10
|
+
const stored = Number(globalThis.localStorage?.getItem(key(name)));
|
|
11
|
+
// Storage is outside the program: anything that is not a usable size is none.
|
|
12
|
+
return Number.isFinite(stored) && stored >= min ? stored : fallback;
|
|
13
|
+
}
|
|
14
|
+
catch {
|
|
15
|
+
return fallback;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
function keep(name, extent) {
|
|
19
|
+
if (!name)
|
|
20
|
+
return;
|
|
21
|
+
try {
|
|
22
|
+
globalThis.localStorage?.setItem(key(name), String(extent));
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
// Private windows and full storage: the panel still resizes, it just opens at its default.
|
|
26
|
+
}
|
|
27
|
+
}
|
|
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);
|
|
31
|
+
const initial = Math.max(min, size);
|
|
32
|
+
// The side panel's width, or its height when vertical.
|
|
33
|
+
const [extent, setExtent] = useState(() => recall(remember, initial, min));
|
|
34
|
+
const root = useRef(null);
|
|
35
|
+
const panel = useRef(null);
|
|
36
|
+
const length = (px) => `min(${px}px, ${max})`;
|
|
37
|
+
const commit = (next) => {
|
|
38
|
+
const clamped = Math.max(min, Math.round(next));
|
|
39
|
+
setExtent(clamped);
|
|
40
|
+
keep(remember, clamped);
|
|
41
|
+
};
|
|
42
|
+
/*
|
|
43
|
+
* While dragging, only the variable on this element changes, so the panels follow the pointer
|
|
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.
|
|
46
|
+
*/
|
|
47
|
+
const startDrag = (event) => {
|
|
48
|
+
if (event.button !== 0)
|
|
49
|
+
return;
|
|
50
|
+
event.preventDefault();
|
|
51
|
+
const handle = event.currentTarget;
|
|
52
|
+
const element = root.current;
|
|
53
|
+
const origin = measure(panel.current?.getBoundingClientRect()) ?? extent;
|
|
54
|
+
const start = vertical ? event.clientY : event.clientX;
|
|
55
|
+
let next = origin;
|
|
56
|
+
handle.setPointerCapture?.(event.pointerId);
|
|
57
|
+
if (element)
|
|
58
|
+
element.dataset.dragging = '';
|
|
59
|
+
const onMove = (move) => {
|
|
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;
|
|
63
|
+
next = Math.max(min, origin + pulled);
|
|
64
|
+
element?.style.setProperty('--desk-split-size', length(next));
|
|
65
|
+
};
|
|
66
|
+
const onUp = () => {
|
|
67
|
+
handle.removeEventListener('pointermove', onMove);
|
|
68
|
+
handle.removeEventListener('pointerup', onUp);
|
|
69
|
+
handle.removeEventListener('pointercancel', onUp);
|
|
70
|
+
if (element)
|
|
71
|
+
delete element.dataset.dragging;
|
|
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));
|
|
74
|
+
if (Math.round(next) !== Math.round(origin))
|
|
75
|
+
commit(next);
|
|
76
|
+
};
|
|
77
|
+
handle.addEventListener('pointermove', onMove);
|
|
78
|
+
handle.addEventListener('pointerup', onUp);
|
|
79
|
+
handle.addEventListener('pointercancel', onUp);
|
|
80
|
+
};
|
|
81
|
+
// The edge is a separator that can be focused, so the size can be set without a pointer.
|
|
82
|
+
const onKeyDown = (event) => {
|
|
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;
|
|
87
|
+
if (event.key === wider)
|
|
88
|
+
commit(drawn + STEP);
|
|
89
|
+
else if (event.key === narrower)
|
|
90
|
+
commit(drawn - STEP);
|
|
91
|
+
else if (event.key === 'Home')
|
|
92
|
+
commit(min);
|
|
93
|
+
else if (event.key === 'Enter')
|
|
94
|
+
commit(initial);
|
|
95
|
+
else
|
|
96
|
+
return;
|
|
97
|
+
event.preventDefault();
|
|
98
|
+
};
|
|
99
|
+
const sidePanel = (_jsx("div", { ref: panel, className: "desk-split-panel", "data-side": "", children: side }, "side"));
|
|
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.
|
|
102
|
+
onDoubleClick: () => commit(initial) }, "edge"));
|
|
103
|
+
const main = (_jsx("div", { className: "desk-split-panel", children: children }, "main"));
|
|
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] }));
|
|
105
|
+
}
|
|
106
|
+
//# sourceMappingURL=split.js.map
|
|
@@ -0,0 +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;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,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AAE,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,IAZhC,MAAM,CAaV,CACH,CAAA;IACD,MAAM,IAAI,GAAG,CACX,cAAgB,SAAS,EAAC,kBAAkB,YACzC,QAAQ,IADF,MAAM,CAET,CACP,CAAA;IAED,OAAO,CACL,cACE,GAAG,EAAE,IAAI,EACT,SAAS,EAAE,CAAC,YAAY,EAAE,SAAS,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,aACrD,EAAE,sBACO,WAAW,EAC7B,KAAK,EAAE,EAAE,mBAAmB,EAAE,MAAM,CAAC,MAAM,CAAC,EAAmB,YAG9D,EAAE,KAAK,OAAO,CAAC,CAAC,CAAC,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,6 +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'} orientation?={'horizontal'|'vertical'} size?={280} min?={200} max?={'50%'} remember?={key} label?={string}>{rest}</Split>
|
|
303
|
+
// two sections of one app in one window, with a draggable edge between them (arrow keys, Home, Enter or
|
|
304
|
+
// double-click to reset); remember keeps the width in localStorage. Drag and drop between the sections is
|
|
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.
|
|
302
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
|
|
303
308
|
// --desk-page-tint (4% light, 5% dark) is how much --desk-accent is mixed into the page; 0% for the neutral alone.
|
|
304
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
|
@@ -401,6 +401,82 @@
|
|
|
401
401
|
|
|
402
402
|
/* ── The inside of a window: controls that stay, content that scrolls ── */
|
|
403
403
|
|
|
404
|
+
/* Two panels in one window, and the edge between them that moves. */
|
|
405
|
+
.desk-split {
|
|
406
|
+
display: grid;
|
|
407
|
+
grid-template-columns: var(--desk-split-size) auto minmax(0, 1fr);
|
|
408
|
+
height: 100%;
|
|
409
|
+
min-height: 0;
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
.desk-split[data-at="end"] {
|
|
413
|
+
grid-template-columns: minmax(0, 1fr) auto var(--desk-split-size);
|
|
414
|
+
}
|
|
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
|
+
|
|
440
|
+
.desk-split[data-dragging] {
|
|
441
|
+
user-select: none;
|
|
442
|
+
cursor: col-resize;
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
.desk-split-panel {
|
|
446
|
+
display: flex;
|
|
447
|
+
flex-direction: column;
|
|
448
|
+
min-width: 0;
|
|
449
|
+
min-height: 0;
|
|
450
|
+
overflow: hidden;
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
/* A hairline to see, and a wider strip either side of it to catch. */
|
|
454
|
+
.desk-split-edge {
|
|
455
|
+
position: relative;
|
|
456
|
+
width: 1px;
|
|
457
|
+
background: var(--desk-rule);
|
|
458
|
+
cursor: col-resize;
|
|
459
|
+
touch-action: none;
|
|
460
|
+
outline: none;
|
|
461
|
+
/* Above the panels, so the strip it catches with is not covered by something positioned in them. */
|
|
462
|
+
z-index: 1;
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
/* 13px to catch with: a hairline you can see, and enough either side that you need not aim for it. */
|
|
466
|
+
.desk-split-edge::before {
|
|
467
|
+
content: "";
|
|
468
|
+
position: absolute;
|
|
469
|
+
inset: 0 -6px;
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
.desk-split-edge:hover,
|
|
473
|
+
.desk-split-edge:focus-visible,
|
|
474
|
+
.desk-split[data-dragging] > .desk-split-edge {
|
|
475
|
+
background: var(--desk-accent);
|
|
476
|
+
box-shadow: 0 0 0 1px var(--desk-accent);
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
|
|
404
480
|
.desk-pane {
|
|
405
481
|
display: flex;
|
|
406
482
|
flex-direction: column;
|
package/src/react/index.ts
CHANGED
|
@@ -52,6 +52,8 @@ export { PageDots, pageWindow } from './pageDots.js'
|
|
|
52
52
|
export type { PageDot, PageDotsProps } from './pageDots.js'
|
|
53
53
|
export type { LedColor, LedProps } from './led.js'
|
|
54
54
|
export { Page, Pane, PaneHeader, Section, Toolbar } from './pane.js'
|
|
55
|
+
export { Split } from './split.js'
|
|
56
|
+
export type { SplitProps } from './split.js'
|
|
55
57
|
export type { PageProps, PaneHeaderProps, PaneProps, SectionProps, ToolbarProps } from './pane.js'
|
|
56
58
|
export { InfoTip } from './infoTip.js'
|
|
57
59
|
export type { InfoTipProps } from './infoTip.js'
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import { useRef, useState } from 'react'
|
|
2
|
+
import type { CSSProperties, KeyboardEvent, PointerEvent as ReactPointerEvent, ReactNode } from 'react'
|
|
3
|
+
|
|
4
|
+
/*
|
|
5
|
+
* Two panels in one window, with the edge between them to drag: a list beside its detail, a picker
|
|
6
|
+
* beside the canvas it fills.
|
|
7
|
+
*
|
|
8
|
+
* They are one app, so they are one window: they open, close, minimize and move together, and
|
|
9
|
+
* nothing can pull them apart. Only the edge between them moves, and it is remembered, so the side
|
|
10
|
+
* panel opens at the size it was left at. Dragging things from one panel to the other is the
|
|
11
|
+
* ordinary drag and drop (`useDragSource`, `useDropTarget`), which does not care where its ends are.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
export interface SplitProps {
|
|
15
|
+
/** The panel at the edge: a list, a picker, an outline. */
|
|
16
|
+
readonly side: ReactNode
|
|
17
|
+
/** The rest of the window: what the side panel chooses for. */
|
|
18
|
+
readonly children: ReactNode
|
|
19
|
+
/** Which edge the side panel stands at: the left or right, or with `orientation="vertical"` the top or bottom. Default `start`. */
|
|
20
|
+
readonly at?: 'start' | 'end'
|
|
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. */
|
|
27
|
+
readonly size?: number
|
|
28
|
+
/** The narrowest it can be dragged to. Default 200. */
|
|
29
|
+
readonly min?: number
|
|
30
|
+
/**
|
|
31
|
+
* The most of the window it may take, as CSS: `50%` (the default), `420px`. A size remembered from
|
|
32
|
+
* a big screen never leaves a small one without room for the rest.
|
|
33
|
+
*/
|
|
34
|
+
readonly max?: string
|
|
35
|
+
/** Remembers the size in this browser under this key, so the panel opens at the size it was left at. */
|
|
36
|
+
readonly remember?: string
|
|
37
|
+
/** What the edge is called to assistive technology. Default "Resize". */
|
|
38
|
+
readonly label?: string
|
|
39
|
+
readonly className?: string
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** How far an arrow key moves the edge. */
|
|
43
|
+
const STEP = 16
|
|
44
|
+
|
|
45
|
+
const key = (name: string) => `desk.split.${name}`
|
|
46
|
+
|
|
47
|
+
function recall(name: string | undefined, fallback: number, min: number): number {
|
|
48
|
+
if (!name) return fallback
|
|
49
|
+
try {
|
|
50
|
+
const stored = Number(globalThis.localStorage?.getItem(key(name)))
|
|
51
|
+
// Storage is outside the program: anything that is not a usable size is none.
|
|
52
|
+
return Number.isFinite(stored) && stored >= min ? stored : fallback
|
|
53
|
+
} catch {
|
|
54
|
+
return fallback
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function keep(name: string | undefined, extent: number) {
|
|
59
|
+
if (!name) return
|
|
60
|
+
try {
|
|
61
|
+
globalThis.localStorage?.setItem(key(name), String(extent))
|
|
62
|
+
} catch {
|
|
63
|
+
// Private windows and full storage: the panel still resizes, it just opens at its default.
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
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)
|
|
70
|
+
const initial = Math.max(min, size)
|
|
71
|
+
// The side panel's width, or its height when vertical.
|
|
72
|
+
const [extent, setExtent] = useState(() => recall(remember, initial, min))
|
|
73
|
+
const root = useRef<HTMLDivElement>(null)
|
|
74
|
+
const panel = useRef<HTMLDivElement>(null)
|
|
75
|
+
const length = (px: number) => `min(${px}px, ${max})`
|
|
76
|
+
|
|
77
|
+
const commit = (next: number) => {
|
|
78
|
+
const clamped = Math.max(min, Math.round(next))
|
|
79
|
+
setExtent(clamped)
|
|
80
|
+
keep(remember, clamped)
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/*
|
|
84
|
+
* While dragging, only the variable on this element changes, so the panels follow the pointer
|
|
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.
|
|
87
|
+
*/
|
|
88
|
+
const startDrag = (event: ReactPointerEvent<HTMLDivElement>) => {
|
|
89
|
+
if (event.button !== 0) return
|
|
90
|
+
event.preventDefault()
|
|
91
|
+
const handle = event.currentTarget
|
|
92
|
+
const element = root.current
|
|
93
|
+
const origin = measure(panel.current?.getBoundingClientRect()) ?? extent
|
|
94
|
+
const start = vertical ? event.clientY : event.clientX
|
|
95
|
+
let next = origin
|
|
96
|
+
handle.setPointerCapture?.(event.pointerId)
|
|
97
|
+
if (element) element.dataset.dragging = ''
|
|
98
|
+
const onMove = (move: PointerEvent) => {
|
|
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
|
|
102
|
+
next = Math.max(min, origin + pulled)
|
|
103
|
+
element?.style.setProperty('--desk-split-size', length(next))
|
|
104
|
+
}
|
|
105
|
+
const onUp = () => {
|
|
106
|
+
handle.removeEventListener('pointermove', onMove)
|
|
107
|
+
handle.removeEventListener('pointerup', onUp)
|
|
108
|
+
handle.removeEventListener('pointercancel', onUp)
|
|
109
|
+
if (element) delete element.dataset.dragging
|
|
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))
|
|
112
|
+
if (Math.round(next) !== Math.round(origin)) commit(next)
|
|
113
|
+
}
|
|
114
|
+
handle.addEventListener('pointermove', onMove)
|
|
115
|
+
handle.addEventListener('pointerup', onUp)
|
|
116
|
+
handle.addEventListener('pointercancel', onUp)
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// The edge is a separator that can be focused, so the size can be set without a pointer.
|
|
120
|
+
const onKeyDown = (event: KeyboardEvent<HTMLDivElement>) => {
|
|
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
|
|
125
|
+
if (event.key === wider) commit(drawn + STEP)
|
|
126
|
+
else if (event.key === narrower) commit(drawn - STEP)
|
|
127
|
+
else if (event.key === 'Home') commit(min)
|
|
128
|
+
else if (event.key === 'Enter') commit(initial)
|
|
129
|
+
else return
|
|
130
|
+
event.preventDefault()
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
const sidePanel = (
|
|
134
|
+
<div key="side" ref={panel} className="desk-split-panel" data-side="">
|
|
135
|
+
{side}
|
|
136
|
+
</div>
|
|
137
|
+
)
|
|
138
|
+
const edge = (
|
|
139
|
+
<div
|
|
140
|
+
key="edge"
|
|
141
|
+
role="separator"
|
|
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'}
|
|
144
|
+
aria-label={label}
|
|
145
|
+
aria-valuenow={extent}
|
|
146
|
+
aria-valuemin={min}
|
|
147
|
+
tabIndex={0}
|
|
148
|
+
className="desk-split-edge"
|
|
149
|
+
onPointerDown={startDrag}
|
|
150
|
+
onKeyDown={onKeyDown}
|
|
151
|
+
// Back to the size it started at, as a double-click on a divider does on a Mac.
|
|
152
|
+
onDoubleClick={() => commit(initial)}
|
|
153
|
+
/>
|
|
154
|
+
)
|
|
155
|
+
const main = (
|
|
156
|
+
<div key="main" className="desk-split-panel">
|
|
157
|
+
{children}
|
|
158
|
+
</div>
|
|
159
|
+
)
|
|
160
|
+
|
|
161
|
+
return (
|
|
162
|
+
<div
|
|
163
|
+
ref={root}
|
|
164
|
+
className={['desk-split', className].filter(Boolean).join(' ')}
|
|
165
|
+
data-at={at}
|
|
166
|
+
data-orientation={orientation}
|
|
167
|
+
style={{ '--desk-split-size': length(extent) } as CSSProperties}
|
|
168
|
+
>
|
|
169
|
+
{/* In reading order, so Tab walks the panels the way they are drawn. */}
|
|
170
|
+
{at === 'start' ? [sidePanel, edge, main] : [main, edge, sidePanel]}
|
|
171
|
+
</div>
|
|
172
|
+
)
|
|
173
|
+
}
|