@bigpixelrocket/uiok 0.2.2 → 0.3.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/CHANGELOG.md +62 -1
- package/dist/button/TextLink.d.ts +27 -0
- package/dist/button/TextLink.js +15 -0
- package/dist/button/button.css +48 -0
- package/dist/button/index.d.ts +2 -1
- package/dist/button/index.js +2 -1
- package/dist/charts/Sparkline.d.ts +20 -0
- package/dist/charts/Sparkline.js +12 -0
- package/dist/charts/Sparkline.logic.d.ts +9 -0
- package/dist/charts/Sparkline.logic.js +27 -0
- package/dist/charts/charts.css +17 -0
- package/dist/charts/index.d.ts +2 -0
- package/dist/charts/index.js +2 -0
- package/dist/dialog/ConfirmDialog.d.ts +17 -1
- package/dist/dialog/ConfirmDialog.js +10 -4
- package/dist/dialog/DialogLists.d.ts +8 -1
- package/dist/dialog/DialogLists.js +3 -2
- package/dist/dialog/ModalDialog.d.ts +8 -0
- package/dist/dialog/ModalDialog.js +4 -2
- package/dist/dialog/ProgressDialog.d.ts +34 -0
- package/dist/dialog/ProgressDialog.js +40 -0
- package/dist/dialog/TypedNameDialog.d.ts +36 -0
- package/dist/dialog/TypedNameDialog.js +17 -0
- package/dist/dialog/index.d.ts +5 -2
- package/dist/dialog/index.js +4 -1
- package/dist/field/Switch.d.ts +26 -0
- package/dist/field/Switch.js +20 -0
- package/dist/field/field.css +110 -2
- package/dist/field/index.d.ts +3 -2
- package/dist/field/index.js +3 -2
- package/dist/filter/filter.css +16 -0
- package/dist/frame/AppRoot.d.ts +44 -0
- package/dist/frame/AppRoot.js +26 -0
- package/dist/frame/Dock.d.ts +88 -0
- package/dist/frame/Dock.js +129 -0
- package/dist/frame/FilterChips.d.ts +28 -0
- package/dist/frame/FilterChips.js +14 -0
- package/dist/frame/PageParts.d.ts +69 -0
- package/dist/frame/PageParts.js +60 -0
- package/dist/frame/PaneSplit.d.ts +74 -0
- package/dist/frame/PaneSplit.js +197 -0
- package/dist/frame/SidebarResizer.d.ts +35 -0
- package/dist/frame/SidebarResizer.js +43 -0
- package/dist/frame/StatusNotice.d.ts +20 -0
- package/dist/frame/StatusNotice.js +13 -0
- package/dist/frame/Tree.d.ts +140 -0
- package/dist/frame/Tree.js +141 -0
- package/dist/frame/TreeToggle.d.ts +18 -0
- package/dist/frame/TreeToggle.js +17 -0
- package/dist/frame/WindowFrame.d.ts +57 -0
- package/dist/frame/WindowFrame.js +19 -0
- package/dist/frame/frame.css +801 -0
- package/dist/frame/index.d.ts +22 -0
- package/dist/frame/index.js +22 -0
- package/dist/frame/sharedRef.d.ts +8 -0
- package/dist/frame/sharedRef.js +26 -0
- package/dist/grid/DataGrid.d.ts +10 -2
- package/dist/grid/DataGrid.js +47 -13
- package/dist/grid/DataGrid.logic.d.ts +16 -0
- package/dist/grid/DataGrid.logic.js +28 -0
- package/dist/grid/grid.css +128 -4
- package/dist/index.d.ts +4 -0
- package/dist/index.js +4 -0
- package/dist/labels/UiokLabels.d.ts +6 -0
- package/dist/labels/UiokLabels.js +5 -1
- package/dist/labels/dialog.d.ts +12 -0
- package/dist/labels/dialog.js +7 -1
- package/dist/labels/index.d.ts +2 -0
- package/dist/labels/index.js +2 -0
- package/dist/labels/keys.js +2 -0
- package/dist/labels/paneTabs.d.ts +27 -0
- package/dist/labels/paneTabs.js +10 -0
- package/dist/labels/selectAll.d.ts +4 -1
- package/dist/labels/selectAll.js +1 -1
- package/dist/labels/settings.d.ts +46 -0
- package/dist/labels/settings.js +29 -0
- package/dist/legend/KeyLegendStrip.d.ts +9 -1
- package/dist/legend/KeyLegendStrip.js +119 -5
- package/dist/legend/legend.css +52 -0
- package/dist/listing/EmptyState.d.ts +40 -0
- package/dist/listing/EmptyState.js +14 -0
- package/dist/listing/Listing.d.ts +23 -5
- package/dist/listing/Listing.js +11 -8
- package/dist/listing/index.d.ts +3 -1
- package/dist/listing/index.js +3 -1
- package/dist/listing/listing.css +172 -5
- package/dist/log/LogWell.d.ts +34 -0
- package/dist/log/LogWell.js +39 -0
- package/dist/log/LogWell.logic.d.ts +16 -0
- package/dist/log/LogWell.logic.js +26 -0
- package/dist/log/index.d.ts +8 -0
- package/dist/log/index.js +8 -0
- package/dist/log/log.css +57 -0
- package/dist/pane/Pane.d.ts +49 -0
- package/dist/pane/Pane.js +17 -0
- package/dist/pane/PaneActions.d.ts +3 -1
- package/dist/pane/PaneActions.js +6 -5
- package/dist/pane/PaneKeys.d.ts +10 -3
- package/dist/pane/PaneKeys.js +26 -7
- package/dist/pane/PaneTabs.d.ts +92 -0
- package/dist/pane/PaneTabs.js +326 -0
- package/dist/pane/PaneTabs.logic.d.ts +97 -0
- package/dist/pane/PaneTabs.logic.js +158 -0
- package/dist/pane/index.d.ts +7 -1
- package/dist/pane/index.js +7 -1
- package/dist/pane/panetabs.css +408 -0
- package/dist/pane/usePaneKeys.js +9 -11
- package/dist/pane/useTabDrag.d.ts +49 -0
- package/dist/pane/useTabDrag.js +306 -0
- package/dist/segmented/SegmentedChoice.d.ts +8 -1
- package/dist/segmented/SegmentedChoice.js +7 -4
- package/dist/shell/AboutWindow.d.ts +21 -0
- package/dist/shell/AboutWindow.js +10 -0
- package/dist/shell/LanguageChoice.d.ts +27 -0
- package/dist/shell/LanguageChoice.js +17 -0
- package/dist/shell/LoadFailure.d.ts +22 -0
- package/dist/shell/LoadFailure.js +15 -0
- package/dist/shell/Lockup.d.ts +52 -0
- package/dist/shell/Lockup.js +30 -0
- package/dist/shell/SettingsDialog.d.ts +97 -0
- package/dist/shell/SettingsDialog.js +219 -0
- package/dist/shell/SettingsDialog.logic.d.ts +33 -0
- package/dist/shell/SettingsDialog.logic.js +42 -0
- package/dist/shell/SettingsFiles.d.ts +55 -0
- package/dist/shell/SettingsFiles.js +30 -0
- package/dist/shell/SettingsPageKeys.d.ts +42 -0
- package/dist/shell/SettingsPageKeys.js +70 -0
- package/dist/shell/SettingsSubsection.d.ts +34 -0
- package/dist/shell/SettingsSubsection.js +30 -0
- package/dist/shell/SignIn.d.ts +61 -0
- package/dist/shell/SignIn.js +36 -0
- package/dist/shell/ThemePicker.d.ts +74 -0
- package/dist/shell/ThemePicker.js +96 -0
- package/dist/shell/ThemePicker.logic.d.ts +13 -0
- package/dist/shell/ThemePicker.logic.js +26 -0
- package/dist/shell/TitleBar.d.ts +44 -0
- package/dist/shell/TitleBar.js +23 -0
- package/dist/shell/UpdatePill.d.ts +26 -0
- package/dist/shell/UpdatePill.js +17 -0
- package/dist/shell/Updates.d.ts +99 -0
- package/dist/shell/Updates.js +72 -0
- package/dist/shell/index.d.ts +27 -0
- package/dist/shell/index.js +27 -0
- package/dist/shell/shell.css +243 -4
- package/dist/styles.css +10 -0
- package/dist/surface/GroupSwatch.d.ts +22 -0
- package/dist/surface/GroupSwatch.js +15 -0
- package/dist/surface/Tag.d.ts +26 -0
- package/dist/surface/Tag.js +12 -0
- package/dist/surface/index.d.ts +7 -0
- package/dist/surface/index.js +7 -0
- package/dist/surface/surface.css +116 -1
- package/dist/themes/catalog.js +4 -0
- package/dist/themes/themes.generated.css +244 -0
- package/dist/themes/tokens.d.ts +17 -5
- package/dist/themes/tokens.js +75 -1
- package/dist/tokens.css +11 -0
- package/package.json +1 -1
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/** How far the pointer travels before a press on a tab becomes a drag, in pixels. */
|
|
2
|
+
export declare const DRAG_SLOP = 4;
|
|
3
|
+
/** What a drag needs from its strip; the strip hands it over after every layout. */
|
|
4
|
+
export interface TabStripHandle {
|
|
5
|
+
/** Every tab in the order drawn now, folded ones included. */
|
|
6
|
+
readonly order: readonly string[];
|
|
7
|
+
/** The pinned tabs, which move only among themselves. */
|
|
8
|
+
readonly pinned: ReadonlySet<string>;
|
|
9
|
+
/** The strip's tabs element, whose padding edge a drag's offsets count from. */
|
|
10
|
+
readonly strip: HTMLElement | null;
|
|
11
|
+
/** A drop that changed the order: the strip hands it to its host. */
|
|
12
|
+
readonly commit: (order: readonly string[]) => void;
|
|
13
|
+
}
|
|
14
|
+
/** What a press on a picked tab adds to a drag. */
|
|
15
|
+
export interface CarriedTabs {
|
|
16
|
+
/** Every tab the drag carries, the pressed one among them. */
|
|
17
|
+
readonly ids: readonly string[];
|
|
18
|
+
/** Runs when the press ends without a drag: a plain click on the tab. */
|
|
19
|
+
readonly onClick: () => void;
|
|
20
|
+
}
|
|
21
|
+
/** One strip's drag. */
|
|
22
|
+
export interface TabDrag {
|
|
23
|
+
/** The tabs in the hand once the pointer has moved past the slop; none at rest. */
|
|
24
|
+
readonly draggingIds: readonly string[];
|
|
25
|
+
/** The order the strip draws while a drag runs; null at rest, when the host's order stands. */
|
|
26
|
+
readonly liveOrder: readonly string[] | null;
|
|
27
|
+
/** Starts a possible drag of the tab `id` from a press on `tab` at `clientX`. */
|
|
28
|
+
readonly begin: (id: string, tab: HTMLElement, clientX: number, carried?: CarriedTabs) => void;
|
|
29
|
+
/** A stable ref callback per tab id, so the drag knows where each tab on show is drawn. */
|
|
30
|
+
readonly tabRef: (id: string) => (element: HTMLElement | null) => (() => void) | undefined;
|
|
31
|
+
/** The strip has laid out: the drag reads its handle and keeps the hand under the pointer. */
|
|
32
|
+
readonly afterLayout: (handle: TabStripHandle) => void;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Dragging a strip's tabs to reorder them. The held tab follows the pointer
|
|
36
|
+
* along the strip, lifted over its neighbours, and the strip reorders under
|
|
37
|
+
* it: a neighbour steps aside once the held tab covers half of it
|
|
38
|
+
* (`draggedTabOrder`). An unpinned tab stops at the pin rule and a pinned
|
|
39
|
+
* one moves only among the pinned; the hand never goes past the last tab on
|
|
40
|
+
* show, so nothing drops among the folded tabs. Picked tabs close up round
|
|
41
|
+
* the held one as the drag starts (`gatherTabs`) and ride as one block.
|
|
42
|
+
*
|
|
43
|
+
* Escape (or the window losing the focus, or a cancelled pointer) puts
|
|
44
|
+
* every tab back; the Escape is the drag's alone, taken on the window's
|
|
45
|
+
* capture ahead of every other handler, with its repeats until it comes up. Release hands the new order
|
|
46
|
+
* to the strip's `commit` when it changed. The window follows the pointer,
|
|
47
|
+
* since a reordered tab moves in the document and would drop a capture.
|
|
48
|
+
*/
|
|
49
|
+
export declare function useTabDrag(): TabDrag;
|
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
import { useEffect, useMemo, useRef, useState } from 'react';
|
|
2
|
+
import { draggedTabOrder, gatherTabs } from './PaneTabs.logic.js';
|
|
3
|
+
/** How far the pointer travels before a press on a tab becomes a drag, in pixels. */
|
|
4
|
+
export const DRAG_SLOP = 4;
|
|
5
|
+
/** Parses a duration token's computed value ("120ms", "0.12s") to milliseconds. */
|
|
6
|
+
const durationMs = (value) => {
|
|
7
|
+
const text = value.trim();
|
|
8
|
+
const amount = parseFloat(text);
|
|
9
|
+
return Number.isFinite(amount) ? (text.endsWith('ms') ? amount : amount * 1000) : 0;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Slides a tab from an offset back to where the layout now has it, over the
|
|
13
|
+
* fast duration token with its easing, so reduced motion (which zeroes the
|
|
14
|
+
* token) makes it a jump.
|
|
15
|
+
*/
|
|
16
|
+
function slideHome(tab, from) {
|
|
17
|
+
if (from === '' || from === 'none') {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
const style = getComputedStyle(tab);
|
|
21
|
+
const duration = durationMs(style.getPropertyValue('--duration-fast'));
|
|
22
|
+
if (duration <= 0) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
// Optional: jsdom has no Web Animations.
|
|
26
|
+
tab.animate?.([{ transform: from }, { transform: 'none' }], {
|
|
27
|
+
duration,
|
|
28
|
+
easing: style.getPropertyValue('--ease-out').trim() || 'ease-out'
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Dragging a strip's tabs to reorder them. The held tab follows the pointer
|
|
33
|
+
* along the strip, lifted over its neighbours, and the strip reorders under
|
|
34
|
+
* it: a neighbour steps aside once the held tab covers half of it
|
|
35
|
+
* (`draggedTabOrder`). An unpinned tab stops at the pin rule and a pinned
|
|
36
|
+
* one moves only among the pinned; the hand never goes past the last tab on
|
|
37
|
+
* show, so nothing drops among the folded tabs. Picked tabs close up round
|
|
38
|
+
* the held one as the drag starts (`gatherTabs`) and ride as one block.
|
|
39
|
+
*
|
|
40
|
+
* Escape (or the window losing the focus, or a cancelled pointer) puts
|
|
41
|
+
* every tab back; the Escape is the drag's alone, taken on the window's
|
|
42
|
+
* capture ahead of every other handler, with its repeats until it comes up. Release hands the new order
|
|
43
|
+
* to the strip's `commit` when it changed. The window follows the pointer,
|
|
44
|
+
* since a reordered tab moves in the document and would drop a capture.
|
|
45
|
+
*/
|
|
46
|
+
export function useTabDrag() {
|
|
47
|
+
const [draggingIds, setDraggingIds] = useState([]);
|
|
48
|
+
const [liveOrder, setLiveOrder] = useState(null);
|
|
49
|
+
const stopRef = useRef(null);
|
|
50
|
+
// A drag in flight when the strip goes away must not leave the window listening.
|
|
51
|
+
useEffect(() => () => stopRef.current?.(), []);
|
|
52
|
+
const drag = useMemo(() => {
|
|
53
|
+
const tabs = new Map();
|
|
54
|
+
const refs = new Map();
|
|
55
|
+
const lastLefts = new Map();
|
|
56
|
+
// Where each tab was drawn as a drag was cancelled, which it slides back from.
|
|
57
|
+
const returning = new Map();
|
|
58
|
+
let handle = null;
|
|
59
|
+
let held = null;
|
|
60
|
+
const segmentOf = (order, id) => {
|
|
61
|
+
const pinned = handle?.pinned.has(id) ?? false;
|
|
62
|
+
return order.filter((other) => (handle?.pinned.has(other) ?? false) === pinned);
|
|
63
|
+
};
|
|
64
|
+
// The hand's tabs on show, in strip order, each with how far into the block it rides.
|
|
65
|
+
const blockOf = (at) => {
|
|
66
|
+
const order = handle?.order ?? at.ids;
|
|
67
|
+
const shown = order.flatMap((id) => {
|
|
68
|
+
const tab = at.ids.includes(id) ? tabs.get(id) : undefined;
|
|
69
|
+
return tab ? [{ id, tab }] : [];
|
|
70
|
+
});
|
|
71
|
+
const gap = parseFloat(getComputedStyle(handle?.strip ?? document.body).columnGap) || 0;
|
|
72
|
+
let width = 0;
|
|
73
|
+
const members = shown.map((member) => {
|
|
74
|
+
const into = width;
|
|
75
|
+
width += member.tab.offsetWidth + gap;
|
|
76
|
+
return { ...member, into };
|
|
77
|
+
});
|
|
78
|
+
return { members, width: Math.max(0, width - gap) };
|
|
79
|
+
};
|
|
80
|
+
// Where the block's near edge is: the pressed tab under the pointer where
|
|
81
|
+
// it was grabbed, but never outside its segment's tabs on show.
|
|
82
|
+
const heldLeft = (at) => {
|
|
83
|
+
const pressed = tabs.get(at.id);
|
|
84
|
+
const origin = pressed?.offsetParent?.getBoundingClientRect().left;
|
|
85
|
+
if (!handle || !pressed || origin === undefined) {
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
88
|
+
const block = blockOf(at);
|
|
89
|
+
const into = block.members.find((member) => member.id === at.id)?.into ?? 0;
|
|
90
|
+
const shown = segmentOf(handle.order, at.id).flatMap((id) => {
|
|
91
|
+
const tab = tabs.get(id);
|
|
92
|
+
return tab ? [tab] : [];
|
|
93
|
+
});
|
|
94
|
+
const start = Math.min(...shown.map((tab) => tab.offsetLeft));
|
|
95
|
+
const end = Math.max(...shown.map((tab) => tab.offsetLeft + tab.offsetWidth)) - block.width;
|
|
96
|
+
return Math.max(start, Math.min(at.x - at.grab - origin - into, end));
|
|
97
|
+
};
|
|
98
|
+
const follow = () => {
|
|
99
|
+
const left = held?.moved ? heldLeft(held) : null;
|
|
100
|
+
if (held && left !== null) {
|
|
101
|
+
for (const { tab, into } of blockOf(held).members) {
|
|
102
|
+
tab.style.transform = `translateX(${left + into - tab.offsetLeft}px)`;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
// A tab let go of slides from where the hand had it to its place.
|
|
107
|
+
const settle = (id) => {
|
|
108
|
+
const tab = tabs.get(id);
|
|
109
|
+
if (tab) {
|
|
110
|
+
const from = tab.style.transform;
|
|
111
|
+
tab.style.transform = '';
|
|
112
|
+
slideHome(tab, from);
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
const move = (event) => {
|
|
116
|
+
if (!held || !handle) {
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
held.direction = Math.sign(event.clientX - held.x) || held.direction;
|
|
120
|
+
held.x = event.clientX;
|
|
121
|
+
if (!held.moved) {
|
|
122
|
+
if (Math.abs(held.x - held.startX) < DRAG_SLOP) {
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
held.moved = true;
|
|
126
|
+
held.startOrder = handle.order;
|
|
127
|
+
window.addEventListener('keydown', escape, true);
|
|
128
|
+
setDraggingIds(held.ids);
|
|
129
|
+
// Picked tabs close up round the pressed one as the drag lifts them;
|
|
130
|
+
// the strip lays them out together before the block moves.
|
|
131
|
+
const gathered = gatherTabs(handle.order, held.ids, held.id);
|
|
132
|
+
if (gathered.some((id, index) => id !== handle?.order[index])) {
|
|
133
|
+
setLiveOrder(gathered);
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
follow();
|
|
138
|
+
const left = heldLeft(held);
|
|
139
|
+
if (left === null) {
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
const { id, ids, direction } = held;
|
|
143
|
+
const order = handle.order;
|
|
144
|
+
const segment = segmentOf(order, id);
|
|
145
|
+
const block = segment.filter((other) => ids.includes(other));
|
|
146
|
+
const moved = draggedTabOrder(segment.filter((other) => other === id || !ids.includes(other)), { id, left, width: blockOf(held).width }, segment.flatMap((other) => {
|
|
147
|
+
const tab = ids.includes(other) ? undefined : tabs.get(other);
|
|
148
|
+
return tab ? [{ id: other, left: tab.offsetLeft, width: tab.offsetWidth }] : [];
|
|
149
|
+
}), direction).flatMap((other) => (other === id ? block : [other]));
|
|
150
|
+
const others = order.filter((other) => !segment.includes(other));
|
|
151
|
+
const next = handle.pinned.has(id) ? [...moved, ...others] : [...others, ...moved];
|
|
152
|
+
if (next.some((other, index) => other !== order[index])) {
|
|
153
|
+
setLiveOrder(next);
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
const stop = () => {
|
|
157
|
+
window.removeEventListener('pointermove', move);
|
|
158
|
+
window.removeEventListener('pointerup', end);
|
|
159
|
+
window.removeEventListener('pointercancel', cancel);
|
|
160
|
+
window.removeEventListener('keydown', escape, true);
|
|
161
|
+
window.removeEventListener('blur', cancel);
|
|
162
|
+
stopRef.current = null;
|
|
163
|
+
};
|
|
164
|
+
// Ends the drag with every tab back where it began, and a press that was
|
|
165
|
+
// not yet a drag without its click.
|
|
166
|
+
function cancel() {
|
|
167
|
+
const dropped = held;
|
|
168
|
+
held = null;
|
|
169
|
+
stop();
|
|
170
|
+
if (dropped === null || !dropped.moved) {
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
for (const [id, tab] of tabs) {
|
|
174
|
+
returning.set(id, tab.getBoundingClientRect().left);
|
|
175
|
+
tab.style.transform = '';
|
|
176
|
+
}
|
|
177
|
+
setDraggingIds([]);
|
|
178
|
+
setLiveOrder(null);
|
|
179
|
+
}
|
|
180
|
+
function escape(event) {
|
|
181
|
+
if (event.key === 'Escape' && held?.moved) {
|
|
182
|
+
event.preventDefault();
|
|
183
|
+
event.stopImmediatePropagation();
|
|
184
|
+
cancel();
|
|
185
|
+
window.addEventListener('keydown', swallowEscape, true);
|
|
186
|
+
window.addEventListener('keyup', releaseEscape, true);
|
|
187
|
+
window.addEventListener('blur', releaseEscape);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
// The Escape that cancelled, still held: its repeats are the cancel's too.
|
|
191
|
+
function swallowEscape(event) {
|
|
192
|
+
if (event.key === 'Escape') {
|
|
193
|
+
event.preventDefault();
|
|
194
|
+
event.stopImmediatePropagation();
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
function releaseEscape(event) {
|
|
198
|
+
if (event instanceof KeyboardEvent && event.key !== 'Escape') {
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
window.removeEventListener('keydown', swallowEscape, true);
|
|
202
|
+
window.removeEventListener('keyup', releaseEscape, true);
|
|
203
|
+
window.removeEventListener('blur', releaseEscape);
|
|
204
|
+
}
|
|
205
|
+
function end() {
|
|
206
|
+
const dropped = held;
|
|
207
|
+
held = null;
|
|
208
|
+
stop();
|
|
209
|
+
if (dropped === null) {
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
if (!dropped.moved) {
|
|
213
|
+
dropped.onClick?.();
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
dropped.ids.forEach(settle);
|
|
217
|
+
setDraggingIds([]);
|
|
218
|
+
const order = handle?.order ?? dropped.startOrder;
|
|
219
|
+
if (order.some((id, index) => id !== dropped.startOrder[index])) {
|
|
220
|
+
handle?.commit(order);
|
|
221
|
+
}
|
|
222
|
+
setLiveOrder(null);
|
|
223
|
+
}
|
|
224
|
+
return {
|
|
225
|
+
begin: (id, tab, clientX, carried) => {
|
|
226
|
+
stopRef.current?.();
|
|
227
|
+
const pinned = handle?.pinned.has(id) ?? false;
|
|
228
|
+
const ids = carried?.ids.includes(id)
|
|
229
|
+
? carried.ids.filter((other) => (handle?.pinned.has(other) ?? false) === pinned)
|
|
230
|
+
: [id];
|
|
231
|
+
for (const [other, element] of tabs) {
|
|
232
|
+
lastLefts.set(other, element.offsetLeft);
|
|
233
|
+
}
|
|
234
|
+
held = {
|
|
235
|
+
id,
|
|
236
|
+
ids,
|
|
237
|
+
onClick: carried?.onClick ?? null,
|
|
238
|
+
startX: clientX,
|
|
239
|
+
grab: clientX - tab.getBoundingClientRect().left,
|
|
240
|
+
x: clientX,
|
|
241
|
+
direction: 0,
|
|
242
|
+
moved: false,
|
|
243
|
+
startOrder: handle?.order ?? []
|
|
244
|
+
};
|
|
245
|
+
returning.clear();
|
|
246
|
+
stopRef.current = stop;
|
|
247
|
+
window.addEventListener('pointermove', move);
|
|
248
|
+
window.addEventListener('pointerup', end);
|
|
249
|
+
window.addEventListener('pointercancel', cancel);
|
|
250
|
+
window.addEventListener('blur', cancel);
|
|
251
|
+
},
|
|
252
|
+
tabRef: (id) => {
|
|
253
|
+
let ref = refs.get(id);
|
|
254
|
+
if (ref === undefined) {
|
|
255
|
+
ref = (element) => {
|
|
256
|
+
if (element === null) {
|
|
257
|
+
return undefined;
|
|
258
|
+
}
|
|
259
|
+
tabs.set(id, element);
|
|
260
|
+
return () => {
|
|
261
|
+
if (tabs.get(id) === element) {
|
|
262
|
+
tabs.delete(id);
|
|
263
|
+
lastLefts.delete(id);
|
|
264
|
+
returning.delete(id);
|
|
265
|
+
}
|
|
266
|
+
};
|
|
267
|
+
};
|
|
268
|
+
refs.set(id, ref);
|
|
269
|
+
}
|
|
270
|
+
return ref;
|
|
271
|
+
},
|
|
272
|
+
afterLayout: (next) => {
|
|
273
|
+
handle = next;
|
|
274
|
+
for (const id of refs.keys()) {
|
|
275
|
+
if (!next.order.includes(id)) {
|
|
276
|
+
refs.delete(id);
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
const dragged = held?.moved ? held.ids : null;
|
|
280
|
+
for (const [id, tab] of tabs) {
|
|
281
|
+
const left = tab.offsetLeft;
|
|
282
|
+
const before = lastLefts.get(id);
|
|
283
|
+
const from = returning.get(id);
|
|
284
|
+
// A tab a cancel put back slides from where it was drawn.
|
|
285
|
+
if (from !== undefined) {
|
|
286
|
+
const at = tab.getBoundingClientRect().left;
|
|
287
|
+
returning.delete(id);
|
|
288
|
+
if (Math.abs(from - at) > 0.5) {
|
|
289
|
+
slideHome(tab, `translateX(${from - at}px)`);
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
// A neighbour the drag displaced slides to its new place instead of jumping.
|
|
293
|
+
if (dragged !== null &&
|
|
294
|
+
!dragged.includes(id) &&
|
|
295
|
+
before !== undefined &&
|
|
296
|
+
before !== left) {
|
|
297
|
+
slideHome(tab, `translateX(${before - left}px)`);
|
|
298
|
+
}
|
|
299
|
+
lastLefts.set(id, left);
|
|
300
|
+
}
|
|
301
|
+
follow();
|
|
302
|
+
}
|
|
303
|
+
};
|
|
304
|
+
}, []);
|
|
305
|
+
return useMemo(() => ({ draggingIds, liveOrder, ...drag }), [draggingIds, liveOrder, drag]);
|
|
306
|
+
}
|
|
@@ -17,6 +17,13 @@ export interface SegmentedChoiceProps<T extends string | number | null> {
|
|
|
17
17
|
* None unless given; the chosen one should not be among them.
|
|
18
18
|
*/
|
|
19
19
|
readonly disabledChoices?: readonly T[];
|
|
20
|
+
/**
|
|
21
|
+
* Holds the whole choice while it cannot change (a change it started is
|
|
22
|
+
* running): every segment is disabled and the chosen one stays drawn as
|
|
23
|
+
* chosen, so the control still says what is set. Neither a click nor the
|
|
24
|
+
* arrow keys change it.
|
|
25
|
+
*/
|
|
26
|
+
readonly disabled?: boolean;
|
|
20
27
|
/**
|
|
21
28
|
* What the choice does, as the group's accessible description: the
|
|
22
29
|
* `control` half of `labelHelp(help)` spread on the group, whose `label`
|
|
@@ -35,4 +42,4 @@ export interface SegmentedChoiceProps<T extends string | number | null> {
|
|
|
35
42
|
* its own (`.segmented-choice` in `@bigpixelrocket/uiok/styles.css`), so it draws the same
|
|
36
43
|
* in a dialog and on a page.
|
|
37
44
|
*/
|
|
38
|
-
export declare function SegmentedChoice<T extends string | number | null>({ labelId, choices, value, onChange, render, disabledChoices, 'aria-description': description }: SegmentedChoiceProps<T>): ReactElement;
|
|
45
|
+
export declare function SegmentedChoice<T extends string | number | null>({ labelId, choices, value, onChange, render, disabledChoices, disabled, 'aria-description': description }: SegmentedChoiceProps<T>): ReactElement;
|
|
@@ -10,10 +10,13 @@ import { useRef } from 'react';
|
|
|
10
10
|
* its own (`.segmented-choice` in `@bigpixelrocket/uiok/styles.css`), so it draws the same
|
|
11
11
|
* in a dialog and on a page.
|
|
12
12
|
*/
|
|
13
|
-
export function SegmentedChoice({ labelId, choices, value, onChange, render, disabledChoices = [], 'aria-description': description }) {
|
|
13
|
+
export function SegmentedChoice({ labelId, choices, value, onChange, render, disabledChoices = [], disabled = false, 'aria-description': description }) {
|
|
14
14
|
const group = useRef(null);
|
|
15
15
|
const step = (event, delta) => {
|
|
16
16
|
event.preventDefault();
|
|
17
|
+
if (disabled) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
17
20
|
const from = choices.indexOf(value);
|
|
18
21
|
// The next choice that can be chosen, at most one lap round.
|
|
19
22
|
for (let moved = 1; moved < choices.length; moved += 1) {
|
|
@@ -26,16 +29,16 @@ export function SegmentedChoice({ labelId, choices, value, onChange, render, dis
|
|
|
26
29
|
}
|
|
27
30
|
}
|
|
28
31
|
};
|
|
29
|
-
return (_jsx("div", { "aria-description": description, "aria-labelledby": labelId, className: "segmented-choice", onKeyDown: (event) => {
|
|
32
|
+
return (_jsx("div", { "aria-description": description, "aria-disabled": disabled || undefined, "aria-labelledby": labelId, className: "segmented-choice", onKeyDown: (event) => {
|
|
30
33
|
if (event.key === 'ArrowRight' || event.key === 'ArrowDown') {
|
|
31
34
|
step(event, 1);
|
|
32
35
|
}
|
|
33
36
|
else if (event.key === 'ArrowLeft' || event.key === 'ArrowUp') {
|
|
34
37
|
step(event, -1);
|
|
35
38
|
}
|
|
36
|
-
}, ref: group, role: "radiogroup", children: choices.map((choice) => (_jsx("button", { "aria-checked": choice === value, className: "segmented-choice-option", disabled: disabledChoices.includes(choice), onClick: () => {
|
|
39
|
+
}, ref: group, role: "radiogroup", children: choices.map((choice) => (_jsx("button", { "aria-checked": choice === value, className: "segmented-choice-option", disabled: disabled || disabledChoices.includes(choice), onClick: () => {
|
|
37
40
|
// The chosen segment again changes nothing, so it reads nothing.
|
|
38
|
-
if (choice !== value) {
|
|
41
|
+
if (choice !== value && !disabled) {
|
|
39
42
|
onChange(choice);
|
|
40
43
|
}
|
|
41
44
|
}, role: "radio", tabIndex: choice === value ? 0 : -1, type: "button", children: render(choice) }, String(choice)))) }));
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { ReactElement, ReactNode } from 'react';
|
|
2
|
+
/** Props for {@link AboutWindow}. */
|
|
3
|
+
export interface AboutWindowProps {
|
|
4
|
+
/** The app icon's URL: the round patch on a transparent canvas, drawn at 128px. */
|
|
5
|
+
readonly icon: string;
|
|
6
|
+
/** The product's `Lockup`, without its mark (the icon stands above it). */
|
|
7
|
+
readonly lockup: ReactNode;
|
|
8
|
+
/** The channel's name on a build that is not the release, as a `channel-tag`; none on the release. */
|
|
9
|
+
readonly channelTag?: string | null;
|
|
10
|
+
/** The channel the window wears (`data-channel`), which colours the tag; none on the release. */
|
|
11
|
+
readonly channel?: string | null;
|
|
12
|
+
/** The version line, the one line a reader may select. */
|
|
13
|
+
readonly version?: string | null;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* The About window's one panel: the app's icon, the lockup with the
|
|
17
|
+
* channel tag of a build that is not the release, and the version. A fixed
|
|
18
|
+
* frame the window's height that never scrolls; the panel drags the window
|
|
19
|
+
* under a hidden title bar, all but the version line.
|
|
20
|
+
*/
|
|
21
|
+
export declare function AboutWindow({ icon, lockup, channelTag, channel, version }: AboutWindowProps): ReactElement;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* The About window's one panel: the app's icon, the lockup with the
|
|
4
|
+
* channel tag of a build that is not the release, and the version. A fixed
|
|
5
|
+
* frame the window's height that never scrolls; the panel drags the window
|
|
6
|
+
* under a hidden title bar, all but the version line.
|
|
7
|
+
*/
|
|
8
|
+
export function AboutWindow({ icon, lockup, channelTag = null, channel = null, version = null }) {
|
|
9
|
+
return (_jsxs("main", { className: "about-window", "data-channel": channel ?? undefined, children: [_jsx("img", { alt: "", className: "about-icon", src: icon }), _jsxs("div", { className: "about-lockup", children: [lockup, channelTag ? _jsx("span", { className: "channel-tag", children: channelTag }) : null] }), version ? _jsx("p", { className: "about-version", children: version }) : null] }));
|
|
10
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { ReactElement } from 'react';
|
|
2
|
+
/** One language a Language page offers. */
|
|
3
|
+
export interface LanguageOption {
|
|
4
|
+
/** What the host saves ("system", "de-DE"). */
|
|
5
|
+
readonly value: string;
|
|
6
|
+
/** The language by its own name ("Deutsch"), or the system choice ("Match System (English)"). */
|
|
7
|
+
readonly label: string;
|
|
8
|
+
/** The option's own language tag, so it is read in its language; none for the system choice. */
|
|
9
|
+
readonly lang?: string | null;
|
|
10
|
+
}
|
|
11
|
+
/** Props for {@link LanguageChoice}. */
|
|
12
|
+
export interface LanguageChoiceProps {
|
|
13
|
+
/** The row's label ("Language"). */
|
|
14
|
+
readonly label: string;
|
|
15
|
+
/** What changes and when, the label's tooltip. */
|
|
16
|
+
readonly help?: string;
|
|
17
|
+
readonly value: string;
|
|
18
|
+
readonly options: readonly LanguageOption[];
|
|
19
|
+
/** Hears a new choice, never the one already shown. */
|
|
20
|
+
readonly onChange: (value: string) => void;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* A Language page of Settings: one pop-up menu on the label column, the
|
|
24
|
+
* system's choice first and then every language by its own name. The host
|
|
25
|
+
* saves each choice, which applies at once.
|
|
26
|
+
*/
|
|
27
|
+
export declare function LanguageChoice({ label, help, value, options, onChange }: LanguageChoiceProps): ReactElement;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useId } from 'react';
|
|
3
|
+
import { labelHelp } from '../field/labelHelp.js';
|
|
4
|
+
/**
|
|
5
|
+
* A Language page of Settings: one pop-up menu on the label column, the
|
|
6
|
+
* system's choice first and then every language by its own name. The host
|
|
7
|
+
* saves each choice, which applies at once.
|
|
8
|
+
*/
|
|
9
|
+
export function LanguageChoice({ label, help, value, options, onChange }) {
|
|
10
|
+
const id = useId();
|
|
11
|
+
const hint = labelHelp(help);
|
|
12
|
+
const choose = (event) => {
|
|
13
|
+
if (event.target.value !== value)
|
|
14
|
+
onChange(event.target.value);
|
|
15
|
+
};
|
|
16
|
+
return (_jsxs("div", { className: "field-grid", children: [_jsx("label", { className: "field-label", htmlFor: id, ...hint.label, children: label }), _jsx("div", { className: "field-value", children: _jsx("div", { className: "field-option", children: _jsx("select", { ...hint.control, className: "field field-sm", id: id, onChange: choose, value: value, children: options.map((option) => (_jsx("option", { lang: option.lang ?? undefined, value: option.value, children: option.label }, option.value))) }) }) })] }));
|
|
17
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { type LucideIcon } from 'lucide-react';
|
|
2
|
+
import type { ReactElement, ReactNode } from 'react';
|
|
3
|
+
/** Props for {@link LoadFailure}. */
|
|
4
|
+
export interface LoadFailureProps {
|
|
5
|
+
/** What could not load ("Could not load projects"). */
|
|
6
|
+
readonly title: string;
|
|
7
|
+
/** Why, as the system said it or in a sentence. */
|
|
8
|
+
readonly reason?: ReactNode;
|
|
9
|
+
/** Its way on (a `Button`: Try Again). */
|
|
10
|
+
readonly action?: ReactNode;
|
|
11
|
+
/** The failure's glyph, in the danger tone; `CircleAlert` unless given. */
|
|
12
|
+
readonly icon?: LucideIcon;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* The block a window shows in place of content that failed to load, outside
|
|
16
|
+
* any pane: the failure's glyph in the danger tone, the headline, the
|
|
17
|
+
* reason (dim, at most 420px wide), and its way on, centred in the space it
|
|
18
|
+
* takes and announced as an alert. Its words can be selected and copied. A
|
|
19
|
+
* pane inside the window that could not load says so with `EmptyState`'s
|
|
20
|
+
* `failure` instead.
|
|
21
|
+
*/
|
|
22
|
+
export declare function LoadFailure({ title, reason, action, icon: Icon }: LoadFailureProps): ReactElement;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { CircleAlert } from 'lucide-react';
|
|
3
|
+
import { drawn } from '../frame/WindowFrame.js';
|
|
4
|
+
import { ICON_XL } from '../icon/sizes.js';
|
|
5
|
+
/**
|
|
6
|
+
* The block a window shows in place of content that failed to load, outside
|
|
7
|
+
* any pane: the failure's glyph in the danger tone, the headline, the
|
|
8
|
+
* reason (dim, at most 420px wide), and its way on, centred in the space it
|
|
9
|
+
* takes and announced as an alert. Its words can be selected and copied. A
|
|
10
|
+
* pane inside the window that could not load says so with `EmptyState`'s
|
|
11
|
+
* `failure` instead.
|
|
12
|
+
*/
|
|
13
|
+
export function LoadFailure({ title, reason, action, icon: Icon = CircleAlert }) {
|
|
14
|
+
return (_jsxs("div", { className: "space-load-failure", role: "alert", children: [_jsx(Icon, { "aria-hidden": true, size: ICON_XL }), _jsx("strong", { children: title }), drawn(reason) ? _jsx("p", { children: reason }) : null, action] }));
|
|
15
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { ReactElement, ReactNode } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* How a brand mark's shape is drawn: `fill` fills it in the brand's white,
|
|
4
|
+
* `line` strokes it in that white (a line drawing), and `cut` strokes it in
|
|
5
|
+
* the plate's colour over a white fill, so it reads as cut out of the white
|
|
6
|
+
* (the tiers of a cylinder).
|
|
7
|
+
*/
|
|
8
|
+
export type BrandMarkLook = 'fill' | 'line' | 'cut';
|
|
9
|
+
/** One shape of a brand mark's glyph: an SVG path on the mark's 24-unit grid, and how it is drawn. */
|
|
10
|
+
export interface BrandMarkShape {
|
|
11
|
+
/** The path's data (`d`), inside the plate: from 1 to 19 on each axis. */
|
|
12
|
+
readonly d: string;
|
|
13
|
+
readonly look: BrandMarkLook;
|
|
14
|
+
}
|
|
15
|
+
/** Props for {@link BrandMark}. */
|
|
16
|
+
export interface BrandMarkProps {
|
|
17
|
+
/** The app's glyph, its shapes drawn in order over the plate. */
|
|
18
|
+
readonly glyph: readonly BrandMarkShape[];
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* The family's brand mark: a rounded plate in the theme's accent with the
|
|
22
|
+
* app's glyph on it in white, and a green check badge at its lower right,
|
|
23
|
+
* ringed in the title bar's own ground so it reads as cut out of the
|
|
24
|
+
* plate. Drawn for the eye only; the wordmark beside it names the product.
|
|
25
|
+
* Every colour is a token (`--brand-white`, `--brand-plate`, the accent and
|
|
26
|
+
* success hues), so it follows the theme in light and dark.
|
|
27
|
+
*/
|
|
28
|
+
export declare function BrandMark({ glyph }: BrandMarkProps): ReactElement;
|
|
29
|
+
/** A lockup's size by where it stands: the title bar, the About window, or a page of its own. */
|
|
30
|
+
export type LockupSize = 'title' | 'about' | 'hero';
|
|
31
|
+
/** Props for {@link Lockup}. */
|
|
32
|
+
export interface LockupProps {
|
|
33
|
+
/** The wordmark's lighter first part ("Database"). */
|
|
34
|
+
readonly lead: string;
|
|
35
|
+
/** The wordmark's heavier last part ("OK"). */
|
|
36
|
+
readonly strong: string;
|
|
37
|
+
/** The brand mark before the wordmark (`BrandMark`); none where an icon stands beside it instead. */
|
|
38
|
+
readonly mark?: ReactNode;
|
|
39
|
+
/**
|
|
40
|
+
* Its size: `title` in the title bar (15px), `about` in the About window
|
|
41
|
+
* (21px), `hero` on a page of its own (40px, the default).
|
|
42
|
+
*/
|
|
43
|
+
readonly size?: LockupSize;
|
|
44
|
+
/** The element it draws: the window's heading by default, a `span` inside one. */
|
|
45
|
+
readonly as?: 'h1' | 'span';
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* A product's lockup, the title bar's heading and the About window's: the
|
|
49
|
+
* mark (when given) beside the wordmark, its `strong` part in the heavier
|
|
50
|
+
* weight, at its `size`; the mark scales with it.
|
|
51
|
+
*/
|
|
52
|
+
export declare function Lockup({ lead, strong, mark, size, as: Element }: LockupProps): ReactElement;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
const SHAPE_CLASS = {
|
|
3
|
+
fill: 'brand-mark-glyph',
|
|
4
|
+
line: 'brand-mark-line',
|
|
5
|
+
cut: 'brand-mark-cut'
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* The family's brand mark: a rounded plate in the theme's accent with the
|
|
9
|
+
* app's glyph on it in white, and a green check badge at its lower right,
|
|
10
|
+
* ringed in the title bar's own ground so it reads as cut out of the
|
|
11
|
+
* plate. Drawn for the eye only; the wordmark beside it names the product.
|
|
12
|
+
* Every colour is a token (`--brand-white`, `--brand-plate`, the accent and
|
|
13
|
+
* success hues), so it follows the theme in light and dark.
|
|
14
|
+
*/
|
|
15
|
+
export function BrandMark({ glyph }) {
|
|
16
|
+
return (_jsxs("svg", { "aria-hidden": true, className: "brand-mark", focusable: "false", viewBox: "0 0 24 24", children: [_jsx("rect", { className: "brand-mark-plate", height: "18", rx: "4.5", width: "18", x: "1", y: "1" }), glyph.map((shape, index) => (_jsx("path", { className: SHAPE_CLASS[shape.look], d: shape.d }, index))), _jsx("circle", { className: "brand-mark-badge", cx: "18.5", cy: "18.5", r: "4.25" }), _jsx("path", { className: "brand-mark-check", d: "M16.6 18.6l1.3 1.3 2.5-2.7" })] }));
|
|
17
|
+
}
|
|
18
|
+
const LOCKUP_CLASS = {
|
|
19
|
+
title: 'lockup shell-lockup',
|
|
20
|
+
about: 'lockup about-lockup-text',
|
|
21
|
+
hero: 'lockup'
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* A product's lockup, the title bar's heading and the About window's: the
|
|
25
|
+
* mark (when given) beside the wordmark, its `strong` part in the heavier
|
|
26
|
+
* weight, at its `size`; the mark scales with it.
|
|
27
|
+
*/
|
|
28
|
+
export function Lockup({ lead, strong, mark, size = 'hero', as: Element = 'h1' }) {
|
|
29
|
+
return (_jsxs(Element, { className: LOCKUP_CLASS[size], children: [mark, _jsxs("span", { className: "lockup-wordmark", children: [lead, _jsx("b", { children: strong })] })] }));
|
|
30
|
+
}
|