@slotform/react-ui 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +44 -2
- package/dist/density.d.ts +4 -0
- package/dist/density.d.ts.map +1 -0
- package/dist/density.js +8 -0
- package/dist/density.js.map +1 -0
- package/dist/index.d.ts +400 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +388 -0
- package/dist/index.js.map +1 -0
- package/dist/node/canvas.d.ts +3 -0
- package/dist/node/canvas.d.ts.map +1 -0
- package/dist/node/canvas.js +13 -0
- package/dist/node/canvas.js.map +1 -0
- package/dist/node/codegen.d.ts +6 -0
- package/dist/node/codegen.d.ts.map +1 -0
- package/dist/node/codegen.js +70 -0
- package/dist/node/codegen.js.map +1 -0
- package/dist/node/css-escape.d.ts +8 -0
- package/dist/node/css-escape.d.ts.map +1 -0
- package/dist/node/css-escape.js +12 -0
- package/dist/node/css-escape.js.map +1 -0
- package/dist/node/fonts.d.ts +6 -0
- package/dist/node/fonts.d.ts.map +1 -0
- package/dist/node/fonts.js +219 -0
- package/dist/node/fonts.js.map +1 -0
- package/dist/node/lint.d.ts +3 -0
- package/dist/node/lint.d.ts.map +1 -0
- package/dist/node/lint.js +23 -0
- package/dist/node/lint.js.map +1 -0
- package/dist/node/mode.d.ts +9 -0
- package/dist/node/mode.d.ts.map +1 -0
- package/dist/node/mode.js +38 -0
- package/dist/node/mode.js.map +1 -0
- package/dist/node/theme.d.ts +13 -0
- package/dist/node/theme.d.ts.map +1 -0
- package/dist/node/theme.js +160 -0
- package/dist/node/theme.js.map +1 -0
- package/dist/types.d.ts +250 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +80 -0
- package/dist/types.js.map +1 -0
- package/guide/acts.md +61 -0
- package/guide/audio.md +77 -0
- package/guide/blocks.md +82 -0
- package/guide/canvas-choosing.md +34 -0
- package/guide/canvas-editing.md +36 -0
- package/guide/canvas-layout.md +46 -0
- package/guide/canvas-opening.md +47 -0
- package/guide/canvas-overview.md +24 -0
- package/guide/canvas-states.md +37 -0
- package/guide/canvas-view.md +46 -0
- package/guide/canvas.md +94 -0
- package/guide/containers.md +60 -0
- package/guide/content.md +40 -0
- package/guide/controls.md +89 -0
- package/guide/density.md +48 -0
- package/guide/dock.md +42 -0
- package/guide/drag.md +38 -0
- package/guide/figures.md +25 -0
- package/guide/forms.md +82 -0
- package/guide/pane-bar.md +11 -0
- package/guide/pane.md +50 -0
- package/guide/reference.md +74 -0
- package/guide/rules.md +109 -0
- package/guide/section.md +29 -0
- package/guide/shell.md +26 -0
- package/guide/shots.md +37 -0
- package/guide/sidebar.md +30 -0
- package/guide/table.md +119 -0
- package/lint/no-arbitrary-value.grit +9 -0
- package/lint/no-class-on-component.grit +12 -0
- package/lint/no-density.grit +8 -0
- package/lint/no-host-look.grit +38 -0
- package/lint/no-img.grit +10 -0
- package/lint/no-navigate-act.grit +22 -0
- package/lint/no-raw-style.grit +8 -0
- package/package.json +150 -3
- package/src/density.ts +9 -0
- package/src/index.ts +503 -0
- package/src/node/canvas.ts +14 -0
- package/src/node/codegen.ts +100 -0
- package/src/node/css-escape.ts +27 -0
- package/src/node/fonts.ts +260 -0
- package/src/node/lint.ts +25 -0
- package/src/node/mode.ts +64 -0
- package/src/node/theme.ts +232 -0
- package/src/types.ts +120 -0
- package/src/ui/atoms/avatar/base.tsx +42 -0
- package/src/ui/atoms/button/glyph.tsx +244 -0
- package/src/ui/atoms/button/link.tsx +81 -0
- package/src/ui/atoms/button/look.ts +32 -0
- package/src/ui/atoms/button/reason.tsx +69 -0
- package/src/ui/atoms/chip/base.tsx +85 -0
- package/src/ui/atoms/count/base.tsx +27 -0
- package/src/ui/atoms/icon/index.tsx +51 -0
- package/src/ui/atoms/message/waiting.tsx +19 -0
- package/src/ui/atoms/prose/painted.tsx +35 -0
- package/src/ui/atoms/row/badges.tsx +226 -0
- package/src/ui/atoms/row/leading.tsx +166 -0
- package/src/ui/atoms/row/lock.tsx +17 -0
- package/src/ui/atoms/row/marks.tsx +79 -0
- package/src/ui/atoms/section/card.tsx +27 -0
- package/src/ui/atoms/spinner/index.tsx +42 -0
- package/src/ui/atoms/status/base.tsx +51 -0
- package/src/ui/atoms/status/change.tsx +29 -0
- package/src/ui/atoms/status/dot.tsx +45 -0
- package/src/ui/atoms/switch/checkbox.tsx +121 -0
- package/src/ui/atoms/turn.tsx +28 -0
- package/src/ui/components/action-bar/base.tsx +276 -0
- package/src/ui/components/action-bar/index.tsx +20 -0
- package/src/ui/components/avatar/index.tsx +21 -0
- package/src/ui/components/banner/index.tsx +207 -0
- package/src/ui/components/banner/pending.tsx +109 -0
- package/src/ui/components/bar-chart/index.tsx +701 -0
- package/src/ui/components/button/base.tsx +214 -0
- package/src/ui/components/button/face.tsx +84 -0
- package/src/ui/components/button/index.tsx +206 -0
- package/src/ui/components/canvas/connection.tsx +26 -0
- package/src/ui/components/canvas/edges.tsx +116 -0
- package/src/ui/components/canvas/elk.ts +260 -0
- package/src/ui/components/canvas/floor.ts +173 -0
- package/src/ui/components/canvas/geometry.ts +772 -0
- package/src/ui/components/canvas/ground.tsx +97 -0
- package/src/ui/components/canvas/group.tsx +156 -0
- package/src/ui/components/canvas/hit.ts +40 -0
- package/src/ui/components/canvas/index.tsx +497 -0
- package/src/ui/components/canvas/label.tsx +53 -0
- package/src/ui/components/canvas/layout.ts +543 -0
- package/src/ui/components/canvas/lift.ts +272 -0
- package/src/ui/components/canvas/look.ts +129 -0
- package/src/ui/components/canvas/node.tsx +689 -0
- package/src/ui/components/canvas/open.ts +243 -0
- package/src/ui/components/canvas/opening.ts +240 -0
- package/src/ui/components/canvas/view.ts +621 -0
- package/src/ui/components/canvas/viewport.ts +417 -0
- package/src/ui/components/canvas/zoom.tsx +113 -0
- package/src/ui/components/card/index.tsx +20 -0
- package/src/ui/components/chip/index.tsx +24 -0
- package/src/ui/components/code/frame.ts +2 -0
- package/src/ui/components/code/index.tsx +234 -0
- package/src/ui/components/columns/index.tsx +51 -0
- package/src/ui/components/count/index.tsx +17 -0
- package/src/ui/components/diff/index.tsx +249 -0
- package/src/ui/components/diff/word.tsx +104 -0
- package/src/ui/components/dock/index.tsx +262 -0
- package/src/ui/components/file-row/index.tsx +213 -0
- package/src/ui/components/form/base.tsx +280 -0
- package/src/ui/components/form/derive.tsx +269 -0
- package/src/ui/components/form/index.tsx +49 -0
- package/src/ui/components/form/saved.tsx +39 -0
- package/src/ui/components/form-field/index.tsx +658 -0
- package/src/ui/components/gallery/index.tsx +83 -0
- package/src/ui/components/gate/index.tsx +183 -0
- package/src/ui/components/image/base.tsx +245 -0
- package/src/ui/components/image/index.tsx +58 -0
- package/src/ui/components/input/base.tsx +246 -0
- package/src/ui/components/input/code.tsx +108 -0
- package/src/ui/components/input/drop.ts +37 -0
- package/src/ui/components/input/file.tsx +154 -0
- package/src/ui/components/input/index.tsx +132 -0
- package/src/ui/components/input/prose.tsx +107 -0
- package/src/ui/components/input/refusal.tsx +30 -0
- package/src/ui/components/item-header/base.tsx +410 -0
- package/src/ui/components/menu/base.tsx +319 -0
- package/src/ui/components/message/attachments.tsx +101 -0
- package/src/ui/components/message/base.tsx +266 -0
- package/src/ui/components/message-input/index.tsx +377 -0
- package/src/ui/components/missing/base.tsx +45 -0
- package/src/ui/components/pane/head.tsx +399 -0
- package/src/ui/components/pane/index.tsx +325 -0
- package/src/ui/components/picker/base.tsx +1551 -0
- package/src/ui/components/picker/index.tsx +224 -0
- package/src/ui/components/picker/list.tsx +423 -0
- package/src/ui/components/picker/segments.tsx +183 -0
- package/src/ui/components/prose/index.tsx +259 -0
- package/src/ui/components/qr-code/index.tsx +65 -0
- package/src/ui/components/row/acts.tsx +126 -0
- package/src/ui/components/row/fact.tsx +54 -0
- package/src/ui/components/row/index.tsx +1370 -0
- package/src/ui/components/row/progress.tsx +38 -0
- package/src/ui/components/row/status.tsx +54 -0
- package/src/ui/components/row/title.ts +7 -0
- package/src/ui/components/rules/index.tsx +290 -0
- package/src/ui/components/section/band.tsx +39 -0
- package/src/ui/components/section/head.tsx +267 -0
- package/src/ui/components/section/index.tsx +409 -0
- package/src/ui/components/section/rows.tsx +356 -0
- package/src/ui/components/sheet/base.tsx +272 -0
- package/src/ui/components/sheet/confirm.tsx +79 -0
- package/src/ui/components/sheet/docked.tsx +218 -0
- package/src/ui/components/sheet/form.tsx +76 -0
- package/src/ui/components/sheet/head.tsx +120 -0
- package/src/ui/components/sheet/index.tsx +45 -0
- package/src/ui/components/sheet/layer.tsx +168 -0
- package/src/ui/components/sheet/outlet.tsx +58 -0
- package/src/ui/components/sheet/task.tsx +41 -0
- package/src/ui/components/shell/cut.tsx +116 -0
- package/src/ui/components/shell/drag.tsx +45 -0
- package/src/ui/components/shell/host.tsx +71 -0
- package/src/ui/components/shell/index.tsx +737 -0
- package/src/ui/components/shell/panes.tsx +76 -0
- package/src/ui/components/shell/preview.ts +230 -0
- package/src/ui/components/shell/rail.tsx +163 -0
- package/src/ui/components/shell/row.ts +11 -0
- package/src/ui/components/shell/switcher.tsx +143 -0
- package/src/ui/components/shell/tree.tsx +252 -0
- package/src/ui/components/slider/base.tsx +139 -0
- package/src/ui/components/slider/index.tsx +57 -0
- package/src/ui/components/stages/index.tsx +198 -0
- package/src/ui/components/stats/count-links.tsx +47 -0
- package/src/ui/components/stats/index.tsx +203 -0
- package/src/ui/components/stats/meter.tsx +213 -0
- package/src/ui/components/stats/parts.ts +10 -0
- package/src/ui/components/step-count/index.tsx +45 -0
- package/src/ui/components/switch/base.tsx +86 -0
- package/src/ui/components/switch/index.tsx +38 -0
- package/src/ui/components/table/columns.tsx +131 -0
- package/src/ui/components/table/index.tsx +2215 -0
- package/src/ui/components/text/index.tsx +37 -0
- package/src/ui/components/thread/index.tsx +503 -0
- package/src/ui/components/thread/latest.tsx +59 -0
- package/src/ui/components/toast/index.tsx +113 -0
- package/src/ui/components/toast/layer.tsx +26 -0
- package/src/ui/components/toolbar/filters.tsx +161 -0
- package/src/ui/components/toolbar/index.tsx +125 -0
- package/src/ui/components/waveform/index.tsx +205 -0
- package/src/ui/globals.css +427 -0
- package/src/ui/lib/act.ts +60 -0
- package/src/ui/lib/age.ts +49 -0
- package/src/ui/lib/bound.ts +16 -0
- package/src/ui/lib/canvas-layout.ts +11 -0
- package/src/ui/lib/caret.ts +9 -0
- package/src/ui/lib/chip-lines.ts +3 -0
- package/src/ui/lib/closed.ts +8 -0
- package/src/ui/lib/code.tsx +184 -0
- package/src/ui/lib/columns.ts +39 -0
- package/src/ui/lib/commit.ts +24 -0
- package/src/ui/lib/container.ts +112 -0
- package/src/ui/lib/copy.ts +29 -0
- package/src/ui/lib/drag.ts +575 -0
- package/src/ui/lib/empty.tsx +85 -0
- package/src/ui/lib/field.ts +39 -0
- package/src/ui/lib/focus.ts +175 -0
- package/src/ui/lib/folds.ts +67 -0
- package/src/ui/lib/follow.ts +220 -0
- package/src/ui/lib/form.ts +19 -0
- package/src/ui/lib/guards.ts +38 -0
- package/src/ui/lib/heading.ts +14 -0
- package/src/ui/lib/ink.ts +26 -0
- package/src/ui/lib/lang.ts +7 -0
- package/src/ui/lib/leave.ts +14 -0
- package/src/ui/lib/lockup.tsx +145 -0
- package/src/ui/lib/measure.ts +22 -0
- package/src/ui/lib/media.ts +63 -0
- package/src/ui/lib/modality.ts +69 -0
- package/src/ui/lib/moment.ts +13 -0
- package/src/ui/lib/more.tsx +76 -0
- package/src/ui/lib/navigate.ts +210 -0
- package/src/ui/lib/noop.ts +3 -0
- package/src/ui/lib/not-found.tsx +40 -0
- package/src/ui/lib/paint.tsx +55 -0
- package/src/ui/lib/parts-line.tsx +54 -0
- package/src/ui/lib/picked.ts +18 -0
- package/src/ui/lib/player-store.ts +38 -0
- package/src/ui/lib/player.ts +139 -0
- package/src/ui/lib/portal.ts +12 -0
- package/src/ui/lib/read.tsx +269 -0
- package/src/ui/lib/region.tsx +49 -0
- package/src/ui/lib/reorder.ts +154 -0
- package/src/ui/lib/rest.ts +16 -0
- package/src/ui/lib/saved.ts +29 -0
- package/src/ui/lib/scramble.tsx +147 -0
- package/src/ui/lib/scrolls.ts +70 -0
- package/src/ui/lib/style.ts +6 -0
- package/src/ui/lib/swap.tsx +107 -0
- package/src/ui/lib/toast.ts +39 -0
- package/src/ui/lib/walk-classes.ts +16 -0
- package/src/ui/lib/window.tsx +376 -0
- package/src/ui/worker.d.ts +4 -0
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
import { trackTime } from "@slotform/ui-core/clock";
|
|
2
|
+
import { cn } from "@slotform/ui-core/cn";
|
|
3
|
+
import type { Track } from "@slotform/ui-core/descriptors";
|
|
4
|
+
import { dockSeek, shortcut } from "@slotform/ui-core/player";
|
|
5
|
+
import { useSelections } from "@slotform/ui-core/react/read";
|
|
6
|
+
import { useWords } from "@slotform/ui-core/react/words";
|
|
7
|
+
import {
|
|
8
|
+
DOCK,
|
|
9
|
+
DOCK_BAR,
|
|
10
|
+
DOCK_TEXT,
|
|
11
|
+
DOCK_TIME,
|
|
12
|
+
DOCK_VOLUME,
|
|
13
|
+
text,
|
|
14
|
+
textStrong,
|
|
15
|
+
} from "@slotform/ui-core/variants";
|
|
16
|
+
import { useEffect } from "react";
|
|
17
|
+
import { useHeldDraft } from "../../lib/act.ts";
|
|
18
|
+
import { useTouch } from "../../lib/media.ts";
|
|
19
|
+
import { NOOP } from "../../lib/noop.ts";
|
|
20
|
+
import { player, usePlayer, usePlayerTime } from "../../lib/player.ts";
|
|
21
|
+
import { store } from "../../lib/player-store.ts";
|
|
22
|
+
import { Button } from "../button/index.tsx";
|
|
23
|
+
import { PictureTile } from "../image/base.tsx";
|
|
24
|
+
import { SliderBase } from "../slider/base.tsx";
|
|
25
|
+
import { Waveform } from "../waveform/index.tsx";
|
|
26
|
+
|
|
27
|
+
// The dock is a column of bars (two on touch) under the place, clear of the
|
|
28
|
+
// bottom safe inset.
|
|
29
|
+
const COLUMN = "flex flex-col pb-safe";
|
|
30
|
+
const BAR = "flex items-center min-w-0";
|
|
31
|
+
// The bar's zones share its width by flex: the name's and, on the desktop, the
|
|
32
|
+
// seek's, each the same basis, so the transport between them stands at the
|
|
33
|
+
// bar's centre.
|
|
34
|
+
const ZONE = "flex items-center gap-gap grow basis-0 min-w-0";
|
|
35
|
+
const TEXT = "flex flex-col grow basis-0 min-w-0";
|
|
36
|
+
const LINE = "truncate";
|
|
37
|
+
const FAILED = "text-danger";
|
|
38
|
+
const SEEK = "grow basis-0 min-w-0";
|
|
39
|
+
const TIME = "shrink-0";
|
|
40
|
+
const ELAPSED = "text-end";
|
|
41
|
+
const VOLUME = "flex items-center shrink-0";
|
|
42
|
+
const TRANSPORT = "flex items-center shrink-0";
|
|
43
|
+
|
|
44
|
+
// Space and the horizontal arrows are the page's: docs/architecture/ui-core/sound.md, "Dock keys".
|
|
45
|
+
const TEXT_INPUTS = new Set([
|
|
46
|
+
"text",
|
|
47
|
+
"search",
|
|
48
|
+
"email",
|
|
49
|
+
"url",
|
|
50
|
+
"tel",
|
|
51
|
+
"password",
|
|
52
|
+
"number",
|
|
53
|
+
"date",
|
|
54
|
+
"datetime-local",
|
|
55
|
+
"month",
|
|
56
|
+
"time",
|
|
57
|
+
"week",
|
|
58
|
+
]);
|
|
59
|
+
const PRESSED =
|
|
60
|
+
'button, a[href], summary, select, input:not([type="range"]), [role="button"], [role="link"], [role="switch"], [role="checkbox"], [role="radio"], [role="menuitem"], [role="menuitemcheckbox"], [role="menuitemradio"], [role="tab"], [role="option"], [role="treeitem"]';
|
|
61
|
+
const ARROWED =
|
|
62
|
+
'select, input, textarea, [contenteditable]:not([contenteditable="false"]), [role="slider"], [role="textbox"], [role="combobox"], [role="listbox"], [role="menu"], [role="menubar"], [role="tablist"], [role="tree"], [role="grid"], [role="radiogroup"], [role="spinbutton"], [role="scrollbar"]';
|
|
63
|
+
|
|
64
|
+
function typing(target: Element): boolean {
|
|
65
|
+
if (target instanceof HTMLElement && target.isContentEditable) return true;
|
|
66
|
+
if (target instanceof HTMLTextAreaElement) return true;
|
|
67
|
+
return target instanceof HTMLInputElement && TEXT_INPUTS.has(target.type);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** The key, if the player takes it where focus stands. */
|
|
71
|
+
function taken(event: KeyboardEvent) {
|
|
72
|
+
if (event.defaultPrevented || event.altKey || event.ctrlKey || event.metaKey)
|
|
73
|
+
return undefined;
|
|
74
|
+
const target = event.target instanceof Element ? event.target : null;
|
|
75
|
+
if (target && typing(target)) return undefined;
|
|
76
|
+
const key = shortcut(event.key, event.shiftKey);
|
|
77
|
+
if (!key) return undefined;
|
|
78
|
+
if (target?.closest(key.to === "toggle" ? PRESSED : ARROWED))
|
|
79
|
+
return undefined;
|
|
80
|
+
return key;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** The player's dock, for a `Shell`'s `foot`: while a track is loaded, its name, transport, seek and volume under the place. It draws what `player` holds and plays nothing itself (the app's `connectOutput` is the sound), takes Space and the horizontal arrows anywhere that is not typing or a control that takes them. The system's media controls are the output's (`audioOutput`). */
|
|
84
|
+
export function Dock() {
|
|
85
|
+
const state = usePlayer();
|
|
86
|
+
const touch = useTouch();
|
|
87
|
+
const words = useWords();
|
|
88
|
+
const { track } = state;
|
|
89
|
+
// The cover as the tile draws it is what the system's media controls show.
|
|
90
|
+
const [cover] = useSelections([track?.image ?? ""]);
|
|
91
|
+
useEffect(() => {
|
|
92
|
+
if (track) store.cover(track, cover);
|
|
93
|
+
}, [track, cover]);
|
|
94
|
+
useEffect(() => {
|
|
95
|
+
if (!track) return;
|
|
96
|
+
const onKey = (event: KeyboardEvent) => {
|
|
97
|
+
const key = taken(event);
|
|
98
|
+
if (!key) return;
|
|
99
|
+
event.preventDefault();
|
|
100
|
+
if (key.to === "toggle") player.toggle();
|
|
101
|
+
else player.skip(key.by);
|
|
102
|
+
};
|
|
103
|
+
window.addEventListener("keydown", onKey);
|
|
104
|
+
return () => window.removeEventListener("keydown", onKey);
|
|
105
|
+
}, [track]);
|
|
106
|
+
|
|
107
|
+
if (!track) return null;
|
|
108
|
+
|
|
109
|
+
const transport = (
|
|
110
|
+
<div className={TRANSPORT}>
|
|
111
|
+
{state.queued ? (
|
|
112
|
+
<Button
|
|
113
|
+
glyph
|
|
114
|
+
icon="SkipBack"
|
|
115
|
+
label={words.previous}
|
|
116
|
+
onAct={player.playPrevious}
|
|
117
|
+
/>
|
|
118
|
+
) : null}
|
|
119
|
+
<Button
|
|
120
|
+
glyph
|
|
121
|
+
act="primary"
|
|
122
|
+
icon={state.playing ? "Pause" : "Play"}
|
|
123
|
+
label={state.playing ? words.pause : words.play}
|
|
124
|
+
onAct={player.toggle}
|
|
125
|
+
/>
|
|
126
|
+
{state.hasNext ? (
|
|
127
|
+
<Button
|
|
128
|
+
glyph
|
|
129
|
+
icon="SkipForward"
|
|
130
|
+
label={words.next}
|
|
131
|
+
onAct={player.playNext}
|
|
132
|
+
/>
|
|
133
|
+
) : null}
|
|
134
|
+
</div>
|
|
135
|
+
);
|
|
136
|
+
const close = (
|
|
137
|
+
<Button glyph icon="X" label={words.close} onAct={player.close} />
|
|
138
|
+
);
|
|
139
|
+
const progress = <Progress track={track} />;
|
|
140
|
+
|
|
141
|
+
return (
|
|
142
|
+
<aside aria-label={words.player} className={cn(DOCK, COLUMN)}>
|
|
143
|
+
<div className={cn(DOCK_BAR, BAR)}>
|
|
144
|
+
<div className={ZONE}>
|
|
145
|
+
<PictureTile
|
|
146
|
+
src={track.image ?? ""}
|
|
147
|
+
alt={track.title}
|
|
148
|
+
fit="mini"
|
|
149
|
+
box={undefined}
|
|
150
|
+
/>
|
|
151
|
+
<div className={cn(DOCK_TEXT, TEXT)}>
|
|
152
|
+
<span
|
|
153
|
+
className={cn(
|
|
154
|
+
text({ role: "body" }),
|
|
155
|
+
textStrong({ role: "body" }),
|
|
156
|
+
LINE,
|
|
157
|
+
)}
|
|
158
|
+
>
|
|
159
|
+
{track.title}
|
|
160
|
+
</span>
|
|
161
|
+
{state.failed ? (
|
|
162
|
+
<span className={cn(text({ role: "meta" }), LINE, FAILED)}>
|
|
163
|
+
{words.playFailed}
|
|
164
|
+
</span>
|
|
165
|
+
) : track.line ? (
|
|
166
|
+
<span className={cn(text({ role: "meta" }), LINE)}>
|
|
167
|
+
{track.line}
|
|
168
|
+
</span>
|
|
169
|
+
) : null}
|
|
170
|
+
</div>
|
|
171
|
+
</div>
|
|
172
|
+
{transport}
|
|
173
|
+
{touch ? (
|
|
174
|
+
close
|
|
175
|
+
) : (
|
|
176
|
+
<div className={ZONE}>
|
|
177
|
+
{progress}
|
|
178
|
+
<Volume />
|
|
179
|
+
{close}
|
|
180
|
+
</div>
|
|
181
|
+
)}
|
|
182
|
+
</div>
|
|
183
|
+
{touch ? <div className={cn(DOCK_BAR, BAR)}>{progress}</div> : null}
|
|
184
|
+
</aside>
|
|
185
|
+
);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// The elapsed time, the seek and the total: the seek is the track's waveform
|
|
189
|
+
// where it has peaks, else a slider. The time is its own reader, so only this
|
|
190
|
+
// part draws again as the track moves.
|
|
191
|
+
function Progress({ track }: { track: Track }) {
|
|
192
|
+
const words = useWords();
|
|
193
|
+
const { time, duration } = usePlayerTime();
|
|
194
|
+
const { length, peaks } = dockSeek(track, duration);
|
|
195
|
+
return (
|
|
196
|
+
<div className={ZONE}>
|
|
197
|
+
<span className={cn(DOCK_TIME, TIME, ELAPSED)}>{trackTime(time)}</span>
|
|
198
|
+
<div className={SEEK}>
|
|
199
|
+
{peaks ? (
|
|
200
|
+
<Waveform
|
|
201
|
+
fit="bar"
|
|
202
|
+
label={words.seek}
|
|
203
|
+
peaks={peaks}
|
|
204
|
+
duration={length}
|
|
205
|
+
at={time}
|
|
206
|
+
onSeek={player.seek}
|
|
207
|
+
/>
|
|
208
|
+
) : (
|
|
209
|
+
<Seek time={time} length={length} />
|
|
210
|
+
)}
|
|
211
|
+
</div>
|
|
212
|
+
<span className={cn(DOCK_TIME, TIME)}>{trackTime(length)}</span>
|
|
213
|
+
</div>
|
|
214
|
+
);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
function Seek({ time, length }: { time: number; length: number }) {
|
|
218
|
+
const words = useWords();
|
|
219
|
+
const draft = useHeldDraft(Math.floor(time));
|
|
220
|
+
return (
|
|
221
|
+
<SliderBase
|
|
222
|
+
bare
|
|
223
|
+
label={words.seek}
|
|
224
|
+
draft={draft}
|
|
225
|
+
onChange={NOOP}
|
|
226
|
+
onCommit={player.seek}
|
|
227
|
+
min={0}
|
|
228
|
+
max={Math.max(1, Math.floor(length))}
|
|
229
|
+
step={1}
|
|
230
|
+
said={trackTime}
|
|
231
|
+
/>
|
|
232
|
+
);
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
function Volume() {
|
|
236
|
+
const state = usePlayer();
|
|
237
|
+
const words = useWords();
|
|
238
|
+
const shown = state.muted ? 0 : Math.round(state.volume * 100);
|
|
239
|
+
const draft = useHeldDraft(shown);
|
|
240
|
+
return (
|
|
241
|
+
<div className={VOLUME}>
|
|
242
|
+
<Button
|
|
243
|
+
glyph
|
|
244
|
+
icon={state.muted || shown === 0 ? "VolumeX" : "Volume2"}
|
|
245
|
+
label={state.muted ? words.unmute : words.mute}
|
|
246
|
+
onAct={() => player.mute()}
|
|
247
|
+
/>
|
|
248
|
+
<div className={DOCK_VOLUME}>
|
|
249
|
+
<SliderBase
|
|
250
|
+
bare
|
|
251
|
+
label={words.volume}
|
|
252
|
+
draft={draft}
|
|
253
|
+
onChange={(value) => player.setVolume(value / 100)}
|
|
254
|
+
min={0}
|
|
255
|
+
max={100}
|
|
256
|
+
step={5}
|
|
257
|
+
unit="percent"
|
|
258
|
+
/>
|
|
259
|
+
</div>
|
|
260
|
+
</div>
|
|
261
|
+
);
|
|
262
|
+
}
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import { Button as BaseButton } from "@base-ui/react/button";
|
|
2
|
+
import { cn } from "@slotform/ui-core/cn";
|
|
3
|
+
import type { FileItem } from "@slotform/ui-core/descriptors";
|
|
4
|
+
import {
|
|
5
|
+
DIRECTORY_LEAD,
|
|
6
|
+
glyph,
|
|
7
|
+
pathCut,
|
|
8
|
+
split,
|
|
9
|
+
} from "@slotform/ui-core/list-state";
|
|
10
|
+
import { isCurrent } from "@slotform/ui-core/route";
|
|
11
|
+
import { sameBy } from "@slotform/ui-core/same-by";
|
|
12
|
+
import {
|
|
13
|
+
DIFF_MARKS,
|
|
14
|
+
FILE_COUNT_YIELD,
|
|
15
|
+
FILE_COUNTS,
|
|
16
|
+
FILE_PATH,
|
|
17
|
+
fileCount,
|
|
18
|
+
filePathPart,
|
|
19
|
+
PRESS_WASH,
|
|
20
|
+
ROW_LEADING,
|
|
21
|
+
row,
|
|
22
|
+
YIELDS_FIRST,
|
|
23
|
+
} from "@slotform/ui-core/variants";
|
|
24
|
+
import { memo } from "react";
|
|
25
|
+
import { ChipBase } from "../../atoms/chip/base.tsx";
|
|
26
|
+
import { IconBase } from "../../atoms/icon/index.tsx";
|
|
27
|
+
import { ChangeMark } from "../../atoms/status/change.tsx";
|
|
28
|
+
import { follow, useRoute } from "../../lib/navigate.ts";
|
|
29
|
+
import { Painted } from "../../lib/paint.tsx";
|
|
30
|
+
import { Roll, Swap } from "../../lib/swap.tsx";
|
|
31
|
+
|
|
32
|
+
// A row's floor, as a list row's: on touch it stands at the target.
|
|
33
|
+
const ROW = "relative flex items-center min-h-row";
|
|
34
|
+
const CHOSEN_PRESS = "hover:bg-wash-selected-hover active:bg-wash-press";
|
|
35
|
+
// The hit covers the row and rings inset.
|
|
36
|
+
const HIT = "absolute inset-0 focus-visible:-outline-offset-2";
|
|
37
|
+
// The change mark stands in its own lane at the row's start, ahead of the glyph.
|
|
38
|
+
const MARK = "flex shrink-0";
|
|
39
|
+
const LEADING = "flex shrink-0 items-center justify-center text-ink-meta";
|
|
40
|
+
// The path takes the overflow first (its shrink weight is 10^7, then the
|
|
41
|
+
// counts' lanes 10^5 (`FILE_COUNT_YIELD`), against the chip's 1, the weight of a mark's label in a list row's meta line), down to its floor, a `min-width`
|
|
42
|
+
// in `ch` (the path is mono) from its name; it clips what its floor holds.
|
|
43
|
+
const PATH = `flex grow ${YIELDS_FIRST} overflow-hidden`;
|
|
44
|
+
const DIRECTORY = "shrink-10000 truncate";
|
|
45
|
+
const NAME = "flex min-w-0 shrink";
|
|
46
|
+
const STEM = "min-w-0 truncate";
|
|
47
|
+
const PART = "shrink-0";
|
|
48
|
+
// The chip stands at its label's measure cap while the path holds above its
|
|
49
|
+
// floor; below it the chip's label truncates.
|
|
50
|
+
const CHIP = "flex min-w-0 shrink";
|
|
51
|
+
// The counts' block carries their type and stands aside: each lane is an item of the row.
|
|
52
|
+
const COUNTS = "contents";
|
|
53
|
+
// The lane of figures keeps them whole where the page breaks a word anywhere.
|
|
54
|
+
const COUNT = "text-end wrap-normal";
|
|
55
|
+
|
|
56
|
+
/** What a Section hands the row it draws while its items are not here; no app sets them. */
|
|
57
|
+
interface FileRowInternal {
|
|
58
|
+
/** The file is not here: the glyph, the path and the counts paint, never the chip, the row is inert and builds no hit. */
|
|
59
|
+
painted?: boolean;
|
|
60
|
+
/** The row's place among the painted rows, which varies the filler's lengths. */
|
|
61
|
+
at?: number;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// The path fits by layout: the directory takes the room the name leaves,
|
|
65
|
+
// ellipsized at its end, so it gives way first, down to its first character and an ellipsis;
|
|
66
|
+
// then the name's stem truncates before its
|
|
67
|
+
// kept end, a cut in its middle, down to the name's floor, below which the
|
|
68
|
+
// chip's label truncates. A directory keeps two characters beside the name's
|
|
69
|
+
// floor (its own `min-width`, in the path's): its first and the ellipsis after
|
|
70
|
+
// it ("d…"), so what gives way says it is cut. The floor is its characters in `ch` rounded up to the
|
|
71
|
+
// pixel: `ch` is the advance of "0" and a run of text can advance a 64th of a
|
|
72
|
+
// pixel per glyph past it, so an exact floor leaves the name's last character
|
|
73
|
+
// short and `text-overflow` cuts it.
|
|
74
|
+
function Path(props: { path: string }) {
|
|
75
|
+
const [dir, name] = split(props.path);
|
|
76
|
+
const { stem, tail, floor } = pathCut(name);
|
|
77
|
+
// Each part's floor rounds up on its own, so their sum is the path's floor.
|
|
78
|
+
const lead = `round(up, ${DIRECTORY_LEAD}ch, 1px)`;
|
|
79
|
+
const space = `round(up, ${floor}ch, 1px)`;
|
|
80
|
+
return (
|
|
81
|
+
<span
|
|
82
|
+
className={cn(FILE_PATH, PATH)}
|
|
83
|
+
style={{ minWidth: dir ? `calc(${space} + ${lead})` : space }}
|
|
84
|
+
>
|
|
85
|
+
{dir ? (
|
|
86
|
+
<span
|
|
87
|
+
className={cn(filePathPart({ part: "directory" }), DIRECTORY)}
|
|
88
|
+
style={{ minWidth: lead }}
|
|
89
|
+
>
|
|
90
|
+
{dir}
|
|
91
|
+
</span>
|
|
92
|
+
) : null}
|
|
93
|
+
<span className={cn(filePathPart({ part: "name" }), NAME)}>
|
|
94
|
+
<span className={STEM}>{stem}</span>
|
|
95
|
+
<span className={PART}>{tail}</span>
|
|
96
|
+
</span>
|
|
97
|
+
</span>
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** A changed file: its seen mark leading, its path in mono (the directory in the meta ink, the name at 500) cut to the room its chip leaves, its chip, its added and removed counts each in its own lane. A row that opens is one hit, current (the selection wash) at its `href`, named by the path; it washes under the pointer and the press. At the card's inset and the row radius. */
|
|
102
|
+
function FileRowBase({
|
|
103
|
+
path,
|
|
104
|
+
added,
|
|
105
|
+
removed,
|
|
106
|
+
seen,
|
|
107
|
+
change: kind,
|
|
108
|
+
chip: given,
|
|
109
|
+
href,
|
|
110
|
+
onOpen,
|
|
111
|
+
painted = false,
|
|
112
|
+
at = 0,
|
|
113
|
+
}: Omit<FileItem, "key"> & FileRowInternal) {
|
|
114
|
+
// A chip says why a file is listed: whether a row has one is the item's own
|
|
115
|
+
// data, which the painted shape cannot know, so it is never painted.
|
|
116
|
+
const chip = painted ? undefined : given;
|
|
117
|
+
// Nor is its change mark painted: whether a file has one is the item's data.
|
|
118
|
+
const change = painted ? undefined : kind;
|
|
119
|
+
const route = useRoute();
|
|
120
|
+
const current = !painted && href !== undefined && isCurrent(href, route);
|
|
121
|
+
let hit = null;
|
|
122
|
+
if (!painted && href !== undefined)
|
|
123
|
+
hit = (
|
|
124
|
+
// biome-ignore lint/a11y/useAnchorContent: the hit covers the row, named by its path
|
|
125
|
+
<a
|
|
126
|
+
href={href}
|
|
127
|
+
onClick={follow}
|
|
128
|
+
aria-label={path}
|
|
129
|
+
aria-current={current ? "page" : undefined}
|
|
130
|
+
className={HIT}
|
|
131
|
+
/>
|
|
132
|
+
);
|
|
133
|
+
else if (!painted && onOpen)
|
|
134
|
+
hit = <BaseButton aria-label={path} onClick={onOpen} className={HIT} />;
|
|
135
|
+
return (
|
|
136
|
+
<div
|
|
137
|
+
inert={painted || undefined}
|
|
138
|
+
className={cn(
|
|
139
|
+
row({ state: current ? "selected" : "rest" }),
|
|
140
|
+
ROW,
|
|
141
|
+
hit && (current ? CHOSEN_PRESS : PRESS_WASH),
|
|
142
|
+
)}
|
|
143
|
+
>
|
|
144
|
+
{hit}
|
|
145
|
+
{change ? (
|
|
146
|
+
<span className={MARK}>
|
|
147
|
+
<ChangeMark kind={change} />
|
|
148
|
+
</span>
|
|
149
|
+
) : null}
|
|
150
|
+
<span className={cn(ROW_LEADING, LEADING)}>
|
|
151
|
+
{painted ? (
|
|
152
|
+
<IconBase name={glyph(seen)} stroke="line" painted />
|
|
153
|
+
) : (
|
|
154
|
+
// The seen mark changing while shown is a mark change.
|
|
155
|
+
<Swap id={glyph(seen)} scale>
|
|
156
|
+
<IconBase name={glyph(seen)} stroke="line" />
|
|
157
|
+
</Swap>
|
|
158
|
+
)}
|
|
159
|
+
</span>
|
|
160
|
+
{painted ? (
|
|
161
|
+
<span className={cn(FILE_PATH, PATH)}>
|
|
162
|
+
<span className={cn(filePathPart({ part: "name" }), STEM)}>
|
|
163
|
+
<Painted role="phrase" at={at} />
|
|
164
|
+
</span>
|
|
165
|
+
</span>
|
|
166
|
+
) : (
|
|
167
|
+
<Path path={path} />
|
|
168
|
+
)}
|
|
169
|
+
{chip ? (
|
|
170
|
+
<span className={CHIP}>
|
|
171
|
+
<ChipBase family={chip.family} label={chip.label} />
|
|
172
|
+
</span>
|
|
173
|
+
) : null}
|
|
174
|
+
<span className={cn(FILE_COUNTS, COUNTS)}>
|
|
175
|
+
<span
|
|
176
|
+
className={cn(fileCount({ kind: "added" }), FILE_COUNT_YIELD, COUNT)}
|
|
177
|
+
>
|
|
178
|
+
{painted ? (
|
|
179
|
+
<Painted role="figure" at={at} />
|
|
180
|
+
) : added > 0 ? (
|
|
181
|
+
<Roll text={`+${added}`} of={added} />
|
|
182
|
+
) : null}
|
|
183
|
+
</span>
|
|
184
|
+
<span
|
|
185
|
+
className={cn(
|
|
186
|
+
fileCount({ kind: "removed" }),
|
|
187
|
+
FILE_COUNT_YIELD,
|
|
188
|
+
COUNT,
|
|
189
|
+
)}
|
|
190
|
+
>
|
|
191
|
+
{painted ? (
|
|
192
|
+
<Painted role="figure" at={at + 1} />
|
|
193
|
+
) : removed > 0 ? (
|
|
194
|
+
<Roll text={`${DIFF_MARKS.removed}${removed}`} of={removed} />
|
|
195
|
+
) : null}
|
|
196
|
+
</span>
|
|
197
|
+
</span>
|
|
198
|
+
</div>
|
|
199
|
+
);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/** One file row of a Section from its item: a refetch that changes one item renders that row alone. */
|
|
203
|
+
function FileRowItemBase(props: {
|
|
204
|
+
item: FileItem;
|
|
205
|
+
/** A painted row's place, which varies its fillers; a loaded row takes none. */
|
|
206
|
+
index?: number;
|
|
207
|
+
painted: boolean;
|
|
208
|
+
}) {
|
|
209
|
+
const { key: _key, ...file } = props.item;
|
|
210
|
+
return <FileRowBase {...file} painted={props.painted} at={props.index} />;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
export const FileRowItem = memo(FileRowItemBase, sameBy("item"));
|