@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,267 @@
|
|
|
1
|
+
import { Collapsible } from "@base-ui/react/collapsible";
|
|
2
|
+
import {
|
|
3
|
+
moreMenu,
|
|
4
|
+
type Offered,
|
|
5
|
+
offered,
|
|
6
|
+
offerOf,
|
|
7
|
+
} from "@slotform/ui-core/acts";
|
|
8
|
+
import { cn } from "@slotform/ui-core/cn";
|
|
9
|
+
import type { IconLinkAct, Run, Runs } from "@slotform/ui-core/descriptors";
|
|
10
|
+
import {
|
|
11
|
+
type Frame,
|
|
12
|
+
useDrawsFailure,
|
|
13
|
+
useSelections,
|
|
14
|
+
} from "@slotform/ui-core/react/read";
|
|
15
|
+
import { ReasonHostContext } from "@slotform/ui-core/react/reason";
|
|
16
|
+
import { useWords } from "@slotform/ui-core/react/words";
|
|
17
|
+
import { type Datum, paints, shownText } from "@slotform/ui-core/read";
|
|
18
|
+
import { META_TAIL, partRuns, partText } from "@slotform/ui-core/runs";
|
|
19
|
+
import {
|
|
20
|
+
PAGE_TITLE_FLOOR,
|
|
21
|
+
SECTION_ACTS,
|
|
22
|
+
SECTION_HEAD,
|
|
23
|
+
SECTION_HEAD_ROW,
|
|
24
|
+
SECTION_LABEL,
|
|
25
|
+
SECTION_TITLE,
|
|
26
|
+
SECTION_TOGGLE,
|
|
27
|
+
text,
|
|
28
|
+
} from "@slotform/ui-core/variants";
|
|
29
|
+
import { type ReactNode, use } from "react";
|
|
30
|
+
import { IconButtonBase } from "../../atoms/button/glyph.tsx";
|
|
31
|
+
import { useReasonLine } from "../../atoms/button/reason.tsx";
|
|
32
|
+
import { Turn } from "../../atoms/turn.tsx";
|
|
33
|
+
import type { IconAct, MenuEntry } from "../../lib/act.ts";
|
|
34
|
+
import { RunText } from "../../lib/code.tsx";
|
|
35
|
+
import { HeadingContext } from "../../lib/heading.ts";
|
|
36
|
+
import { useTouch } from "../../lib/media.ts";
|
|
37
|
+
import { Painted } from "../../lib/paint.tsx";
|
|
38
|
+
import { BusyMark, FrameLine } from "../../lib/read.tsx";
|
|
39
|
+
import { IconActFace } from "../button/face.tsx";
|
|
40
|
+
import { Count } from "../count/index.tsx";
|
|
41
|
+
import { MenuBase } from "../menu/base.tsx";
|
|
42
|
+
import { Text } from "../text/index.tsx";
|
|
43
|
+
|
|
44
|
+
// A waiting description is one line, clipped where it ends: the loaded one is
|
|
45
|
+
// a short sentence, and a bar that wraps would be taller than it.
|
|
46
|
+
const PAINTED_LINE = "block overflow-hidden whitespace-nowrap";
|
|
47
|
+
const HEAD = "flex flex-col";
|
|
48
|
+
const HEAD_ROW = "flex items-center";
|
|
49
|
+
// The title keeps its floor (`PAGE_TITLE_FLOOR`) and its act is an icon, so
|
|
50
|
+
// nothing folds. On the desktop the head is one line and the title truncates;
|
|
51
|
+
// on touch, where the acts leave it a short line, the title wraps whole, so a
|
|
52
|
+
// short name is never cut to its first letters.
|
|
53
|
+
const TITLE_BLOCK = "flex flex-col grow min-w-0";
|
|
54
|
+
const TITLE_LINE = "flex items-center min-w-0";
|
|
55
|
+
const TITLE_FOLD = "flex min-w-0";
|
|
56
|
+
const TITLE = "truncate touch:whitespace-normal touch:break-words";
|
|
57
|
+
// The heading and its count stand on one baseline, the sizes differing; the
|
|
58
|
+
// busy mark and the chevron beside them stay centred on the line. The group
|
|
59
|
+
// is the heading's own line (`1lh` of the heading role), so a count that
|
|
60
|
+
// arrives, its smaller box hanging lower under the baseline, never grows the
|
|
61
|
+
// head; a wrapped title on touch grows it by its lines.
|
|
62
|
+
const NAME =
|
|
63
|
+
"flex items-baseline min-w-0 h-[1lh] touch:h-auto touch:min-h-[1lh]";
|
|
64
|
+
// The chevron draws in the toggle's ink (currentColor), stepping to the body
|
|
65
|
+
// ink under the pointer. The toggle is a target tall, its label centred, and
|
|
66
|
+
// overhangs the label's line above and below by what the target has over it
|
|
67
|
+
// (`1lh` at the label's leading), so the head takes the line alone and a
|
|
68
|
+
// folding heading stands where a plain one does after the same gap.
|
|
69
|
+
// On touch the toggle is a target tall (`min-h-target`) and takes its room, its
|
|
70
|
+
// label centred and the box growing by the lines of a wrapped title, so it
|
|
71
|
+
// keeps the floor of every control and the description stands under it.
|
|
72
|
+
const TOGGLE =
|
|
73
|
+
"flex items-center grow min-w-0 -ms-gap leading-caption -my-[calc((var(--spacing-target)-1lh)*0.5)] text-start text-ink-meta hover:bg-wash-hover hover:text-ink-body active:bg-wash-press active:text-ink-body touch:my-0 touch:min-h-target";
|
|
74
|
+
// On touch, where the title wraps, the count is bound to the title's last
|
|
75
|
+
// character (the two stand in one unbroken span, and no break falls between
|
|
76
|
+
// that character and the rest of its word), so the count never stands alone in
|
|
77
|
+
// a column of its own, and a last word wider than the line still breaks inside
|
|
78
|
+
// itself, the count after its last piece.
|
|
79
|
+
const LAST = "whitespace-nowrap";
|
|
80
|
+
const LAST_COUNT = "inline-flex ms-gap";
|
|
81
|
+
// A dot inside a title is bound to the word before it, so a wrapped title
|
|
82
|
+
// never starts a line on one.
|
|
83
|
+
const BOUND_DOT = "\u00A0· ";
|
|
84
|
+
// The act and the more stand a row's act gap apart (`SECTION_ACTS`, as a list row's).
|
|
85
|
+
const ACTS = "relative flex items-center min-w-0 max-w-full";
|
|
86
|
+
|
|
87
|
+
// A title's runs with each dot between words bound to the word before it.
|
|
88
|
+
function bindDots(runs: Runs): Runs {
|
|
89
|
+
return runs.map((run) =>
|
|
90
|
+
typeof run === "string" ? run.replaceAll(META_TAIL, BOUND_DOT) : run,
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// A title's runs split before its last character: a code run whole.
|
|
95
|
+
function lastCharacter(runs: Runs): [Runs, Runs] {
|
|
96
|
+
const end = runs.at(-1);
|
|
97
|
+
if (end === undefined) return [[], []];
|
|
98
|
+
const before = runs.slice(0, -1);
|
|
99
|
+
if (typeof end !== "string") return [before, [end]];
|
|
100
|
+
const last = Array.from(end).at(-1) ?? "";
|
|
101
|
+
return [[...before, end.slice(0, end.length - last.length)], [last]];
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** A Section's head: the heading with its count, its description, its act and more, the line of its read's state and a blocked act's reason. It subscribes to the description, the act and the more itself, so one of those reads landing renders the head and nothing under the Section's body. Outside the package's exports. */
|
|
105
|
+
export function SectionHead(props: {
|
|
106
|
+
title: Datum<Run>;
|
|
107
|
+
/** The body is a list (`items` that are not facts alone): only a list's head counts, so a head over parts, or over a sheet whose every row has a label (a definition list), draws none whatever its frame's read holds. */
|
|
108
|
+
list: boolean;
|
|
109
|
+
/** The body's total, when the frame gives none. */
|
|
110
|
+
count?: number;
|
|
111
|
+
description?: Datum<string>;
|
|
112
|
+
act?: Offered<IconAct | IconLinkAct>;
|
|
113
|
+
more?: Offered<readonly MenuEntry[]>;
|
|
114
|
+
/** The Section folds: the title is the toggle. */
|
|
115
|
+
foldable: boolean;
|
|
116
|
+
open: boolean;
|
|
117
|
+
/** The id of the body the toggle controls. */
|
|
118
|
+
bodyId: string;
|
|
119
|
+
/** The Section's frame, whose count, busy mark and state line the head draws. */
|
|
120
|
+
frame: Frame;
|
|
121
|
+
}) {
|
|
122
|
+
const {
|
|
123
|
+
title,
|
|
124
|
+
list,
|
|
125
|
+
count,
|
|
126
|
+
description,
|
|
127
|
+
act,
|
|
128
|
+
more,
|
|
129
|
+
foldable,
|
|
130
|
+
open,
|
|
131
|
+
bodyId,
|
|
132
|
+
frame,
|
|
133
|
+
} = props;
|
|
134
|
+
const level = use(HeadingContext);
|
|
135
|
+
const Heading = `h${level}` as const;
|
|
136
|
+
const actOf = offered<IconAct | IconLinkAct>(act);
|
|
137
|
+
const moreOf = offered<readonly MenuEntry[]>(more);
|
|
138
|
+
const [named, said, shownAct, shownMore] = useSelections([
|
|
139
|
+
title,
|
|
140
|
+
description,
|
|
141
|
+
actOf,
|
|
142
|
+
moreOf,
|
|
143
|
+
]);
|
|
144
|
+
// A title Datum is a selection of the read the Section holds, never a second
|
|
145
|
+
// read; one whose read ended draws no text, and the frame says why.
|
|
146
|
+
const heading = named.painted ? undefined : named.value;
|
|
147
|
+
const label = heading === undefined ? "" : partText(heading);
|
|
148
|
+
// A painted title is filler: its heading is hidden from assistive tech and
|
|
149
|
+
// inert, as a painted description is, until the title lands.
|
|
150
|
+
const waiting = paints(named) ? { "aria-hidden": true, inert: true } : {};
|
|
151
|
+
useDrawsFailure([actOf, moreOf]);
|
|
152
|
+
const words = useWords();
|
|
153
|
+
const { waits, given, blocked } = offerOf(words, shownAct);
|
|
154
|
+
// The act hands its blocked press here, so its reason stands on the head's
|
|
155
|
+
// own line under the row.
|
|
156
|
+
const reason = useReasonLine(blocked, true);
|
|
157
|
+
const described = shownText(said);
|
|
158
|
+
let sentence: ReactNode = null;
|
|
159
|
+
if (described?.painted)
|
|
160
|
+
sentence = (
|
|
161
|
+
<Text kind="meta">
|
|
162
|
+
<span className={PAINTED_LINE}>
|
|
163
|
+
<Painted role="phrase" />
|
|
164
|
+
</span>
|
|
165
|
+
</Text>
|
|
166
|
+
);
|
|
167
|
+
else if (described) sentence = <Text kind="meta">{described.text}</Text>;
|
|
168
|
+
// A count is not drawn until its body has answered: a painted chip would
|
|
169
|
+
// carry an unseen "0" for a number nobody knows yet, and the count arrives at
|
|
170
|
+
// the title's end, where it moves nothing. A read of an array gives its length.
|
|
171
|
+
// A count is a list's: over parts (cards, controls) or facts the head draws none.
|
|
172
|
+
const answered = list && (frame.shape === "ready" || frame.shape === "empty");
|
|
173
|
+
const total = answered ? (count ?? frame.count) : undefined;
|
|
174
|
+
const tally =
|
|
175
|
+
total !== undefined && total !== 0 ? <Count value={total} /> : null;
|
|
176
|
+
// An act paints, inert, while its own datum waits; the frame's read is not
|
|
177
|
+
// its concern. An act beside a heading is an icon act: its words are its
|
|
178
|
+
// accessible name and its tooltip, never drawn beside the title.
|
|
179
|
+
let actNode: ReactNode = null;
|
|
180
|
+
if (waits) actNode = <IconButtonBase icon="Plus" label="" painted />;
|
|
181
|
+
else if (given !== undefined)
|
|
182
|
+
actNode = (
|
|
183
|
+
<ReasonHostContext value={reason.host}>
|
|
184
|
+
<IconActFace act={given} />
|
|
185
|
+
</ReasonHostContext>
|
|
186
|
+
);
|
|
187
|
+
const menu = moreMenu(words, shownMore);
|
|
188
|
+
const touch = useTouch();
|
|
189
|
+
const [lead, last] =
|
|
190
|
+
heading === undefined
|
|
191
|
+
? [[], []]
|
|
192
|
+
: lastCharacter(bindDots(partRuns(heading)));
|
|
193
|
+
const shown = (
|
|
194
|
+
<>
|
|
195
|
+
<span
|
|
196
|
+
className={cn(
|
|
197
|
+
text({ role: "heading" }),
|
|
198
|
+
SECTION_LABEL,
|
|
199
|
+
SECTION_TITLE,
|
|
200
|
+
NAME,
|
|
201
|
+
)}
|
|
202
|
+
>
|
|
203
|
+
<span className={TITLE}>
|
|
204
|
+
{heading !== undefined ? (
|
|
205
|
+
touch && tally !== null ? (
|
|
206
|
+
<>
|
|
207
|
+
<RunText runs={lead} fit="name" bound wraps />
|
|
208
|
+
<span className={LAST}>
|
|
209
|
+
<RunText runs={last} fit="name" bound wraps />
|
|
210
|
+
<span className={LAST_COUNT}>{tally}</span>
|
|
211
|
+
</span>
|
|
212
|
+
</>
|
|
213
|
+
) : (
|
|
214
|
+
<RunText runs={lead.concat(last)} fit="name" bound wraps />
|
|
215
|
+
)
|
|
216
|
+
) : paints(named) ? (
|
|
217
|
+
<Painted role="title" />
|
|
218
|
+
) : null}
|
|
219
|
+
</span>
|
|
220
|
+
{touch && heading !== undefined ? null : tally}
|
|
221
|
+
</span>
|
|
222
|
+
<BusyMark frame={frame} />
|
|
223
|
+
</>
|
|
224
|
+
);
|
|
225
|
+
// A title whose read ended (failed or missing) draws no head: the Section's
|
|
226
|
+
// failed or missing shape stands alone in its place.
|
|
227
|
+
if (named.painted && !paints(named)) return null;
|
|
228
|
+
return (
|
|
229
|
+
<div className={cn(SECTION_HEAD, HEAD)}>
|
|
230
|
+
<div className={cn(SECTION_HEAD_ROW, HEAD_ROW)}>
|
|
231
|
+
<div className={cn(TITLE_BLOCK, PAGE_TITLE_FLOOR)}>
|
|
232
|
+
{foldable ? (
|
|
233
|
+
<Heading className={TITLE_FOLD} {...waiting}>
|
|
234
|
+
<Collapsible.Trigger
|
|
235
|
+
aria-controls={bodyId}
|
|
236
|
+
className={cn(SECTION_TOGGLE, TOGGLE)}
|
|
237
|
+
>
|
|
238
|
+
{shown}
|
|
239
|
+
<Turn name="ChevronDown" turned={!open} by="quarter" />
|
|
240
|
+
</Collapsible.Trigger>
|
|
241
|
+
</Heading>
|
|
242
|
+
) : (
|
|
243
|
+
<Heading className={cn(SECTION_TITLE, TITLE_LINE)} {...waiting}>
|
|
244
|
+
{shown}
|
|
245
|
+
</Heading>
|
|
246
|
+
)}
|
|
247
|
+
{sentence}
|
|
248
|
+
</div>
|
|
249
|
+
{actNode || menu.painted || menu.items.length ? (
|
|
250
|
+
<div className={cn(SECTION_ACTS, ACTS)}>
|
|
251
|
+
{actNode}
|
|
252
|
+
{menu.painted || menu.items.length ? (
|
|
253
|
+
<MenuBase
|
|
254
|
+
label={`${words.more} ${label}`}
|
|
255
|
+
title={label}
|
|
256
|
+
items={menu.items}
|
|
257
|
+
painted={menu.painted}
|
|
258
|
+
/>
|
|
259
|
+
) : null}
|
|
260
|
+
</div>
|
|
261
|
+
) : null}
|
|
262
|
+
</div>
|
|
263
|
+
<FrameLine frame={frame} />
|
|
264
|
+
{reason.line}
|
|
265
|
+
</div>
|
|
266
|
+
);
|
|
267
|
+
}
|
|
@@ -0,0 +1,409 @@
|
|
|
1
|
+
import { Collapsible } from "@base-ui/react/collapsible";
|
|
2
|
+
import type { Offered } from "@slotform/ui-core/acts";
|
|
3
|
+
import { cn } from "@slotform/ui-core/cn";
|
|
4
|
+
import type {
|
|
5
|
+
Band as BandData,
|
|
6
|
+
IconLinkAct,
|
|
7
|
+
LinkAct,
|
|
8
|
+
Reorder,
|
|
9
|
+
Row as RowData,
|
|
10
|
+
RowItem as RowItemData,
|
|
11
|
+
Run,
|
|
12
|
+
} from "@slotform/ui-core/descriptors";
|
|
13
|
+
import {
|
|
14
|
+
factsOnly,
|
|
15
|
+
listedRows,
|
|
16
|
+
optionReads,
|
|
17
|
+
ownCount,
|
|
18
|
+
} from "@slotform/ui-core/list-state";
|
|
19
|
+
import {
|
|
20
|
+
type Frame,
|
|
21
|
+
useCollection,
|
|
22
|
+
useFrame,
|
|
23
|
+
useOptions,
|
|
24
|
+
useSelections,
|
|
25
|
+
} from "@slotform/ui-core/react/read";
|
|
26
|
+
import { useWords } from "@slotform/ui-core/react/words";
|
|
27
|
+
import {
|
|
28
|
+
combine,
|
|
29
|
+
type Datum,
|
|
30
|
+
isEnded,
|
|
31
|
+
isSelection,
|
|
32
|
+
pagesOf,
|
|
33
|
+
type Selection,
|
|
34
|
+
sampleOf,
|
|
35
|
+
} from "@slotform/ui-core/read";
|
|
36
|
+
import { ROWS, SECTION, SECTION_BODY } from "@slotform/ui-core/variants";
|
|
37
|
+
import { type ReactNode, use, useId, useMemo, useRef, useState } from "react";
|
|
38
|
+
import { SheetCard } from "../../atoms/section/card.tsx";
|
|
39
|
+
import type { Act, IconAct, MenuEntry, Sheeted } from "../../lib/act.ts";
|
|
40
|
+
import type { Closed } from "../../lib/closed.ts";
|
|
41
|
+
import type { Empty } from "../../lib/empty.tsx";
|
|
42
|
+
import { DEEPER, HeadingContext } from "../../lib/heading.ts";
|
|
43
|
+
import { FrameBody, FrameLine, StateLine, stillOf } from "../../lib/read.tsx";
|
|
44
|
+
import { useMovable } from "../../lib/reorder.ts";
|
|
45
|
+
import { SectionHead } from "./head.tsx";
|
|
46
|
+
import { keyOf, Rows } from "./rows.tsx";
|
|
47
|
+
|
|
48
|
+
// The Section subgrids the Pane's columns: docs/architecture/ui-core/layout.md, "Rows grid".
|
|
49
|
+
const BOX = "min-w-0";
|
|
50
|
+
// The body is its parts, each a card of its own, a `ROWS` run too.
|
|
51
|
+
const BODY = ROWS;
|
|
52
|
+
|
|
53
|
+
/** A band as the platform draws it: its act may open a sheet. */
|
|
54
|
+
export type Band = Omit<BandData, "act"> & { act?: IconAct | IconLinkAct };
|
|
55
|
+
|
|
56
|
+
// A descriptor as the platform draws it: each field that can be a read of its
|
|
57
|
+
// own (a row's `act`, `more`, `title`, `line` and `facts`, a switch's
|
|
58
|
+
// `checked`, a pick's `options` and `value`, the same in a tree's children)
|
|
59
|
+
// may be a `Datum`; the row's `facts` may be a read of the whole list or a
|
|
60
|
+
// list of facts that are each a read of their own.
|
|
61
|
+
type WithReads<T> = T extends unknown
|
|
62
|
+
? {
|
|
63
|
+
[K in keyof T]: K extends "act" | "more"
|
|
64
|
+
? Datum<Sheeted<T[K]>>
|
|
65
|
+
: K extends "facts"
|
|
66
|
+
? T[K] extends readonly (infer F)[] | undefined
|
|
67
|
+
? Datum<readonly Datum<F>[]>
|
|
68
|
+
: never
|
|
69
|
+
: K extends "title" | "line" | "value" | "options" | "checked"
|
|
70
|
+
? Datum<Exclude<T[K], undefined>>
|
|
71
|
+
: K extends "switch" | "pick"
|
|
72
|
+
? WithReads<T[K]>
|
|
73
|
+
: K extends "children"
|
|
74
|
+
? T[K] extends readonly (infer C)[] | undefined
|
|
75
|
+
? readonly WithReads<C>[] | undefined
|
|
76
|
+
: never
|
|
77
|
+
: T[K];
|
|
78
|
+
}
|
|
79
|
+
: never;
|
|
80
|
+
|
|
81
|
+
/** A row of a Section's sheet: a row item or a file, its reads widened to a `Datum`. */
|
|
82
|
+
export type Row<V extends string | null = string, Q = unknown> = WithReads<
|
|
83
|
+
RowData<V, Q>
|
|
84
|
+
>;
|
|
85
|
+
/** A row item as the platform draws it. */
|
|
86
|
+
export type RowItem<V extends string | null = string, Q = unknown> = WithReads<
|
|
87
|
+
RowItemData<V, Q>
|
|
88
|
+
>;
|
|
89
|
+
|
|
90
|
+
interface SectionHeadProps extends Closed {
|
|
91
|
+
/** Under the title (a sentence; wraps). It paints where it will stand while its selection waits; `""` and an undefined one draw no line. */
|
|
92
|
+
description?: Datum<string>;
|
|
93
|
+
/** Set, the title folds the body, and this is its initial fold: `true` starts folded, `false` open; later changes are not read. */
|
|
94
|
+
folded?: boolean;
|
|
95
|
+
/** Called as a foldable section opens or closes, with whether it is now open. */
|
|
96
|
+
onToggle?: (open: boolean) => void;
|
|
97
|
+
/** The section's one act, at the head's end: an icon act, or an icon link to a route (`{ icon, label, href }`, drawn as an anchor); its words are its accessible name. It is live whatever the read does. Given as a selection it paints, inert, while its own read waits or stands still, and stands blocked with the failed sentence once that read failed or is missing; its `label` and `blocked` may be selections on their own, which paint it the same way. */
|
|
98
|
+
act?: Offered<IconAct | IconLinkAct>;
|
|
99
|
+
/** The section's other acts, in a menu under the more act after its act (destructive ones marked; a `{ label, href }` entry goes to its route); the head row never moves, and a foldable section's more does not fold it. It paints and stands blocked as the act does. */
|
|
100
|
+
more?: Offered<readonly MenuEntry[]>;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
type Parts = SectionHeadProps & {
|
|
104
|
+
/** The heading (a short phrase; truncates on the desktop and wraps on touch). A section titled by its record takes a `Datum`: a selection of the read the section holds (its `read`), never a second read of its own; it paints a title-length filler, its heading inert and hidden from assistive tech, until it lands. A title whose read ended (failed or missing) draws no head at all (no heading, count or acts): the failed or missing shape of the Section stands alone in its place. */
|
|
105
|
+
title: Datum<Run>;
|
|
106
|
+
/** The body's parts, each a card of its own: a Form, a Table, a Stats, a BarChart, or a `Card` around anything else; none stand while the `read` is empty. */
|
|
107
|
+
children?: ReactNode;
|
|
108
|
+
items?: never;
|
|
109
|
+
groups?: never;
|
|
110
|
+
} & (
|
|
111
|
+
| {
|
|
112
|
+
read?: undefined;
|
|
113
|
+
empty?: never;
|
|
114
|
+
}
|
|
115
|
+
| {
|
|
116
|
+
/** What the section's body holds, read once for the frame: while it waits the body's leaves paint, its failure and a missing record stand in the body's place, and an empty selection draws `empty`. It holds the reads of `read` that no enclosing frame holds: those draw their failure and say they are busy; the rest only wait and empty. */
|
|
117
|
+
read: Selection<unknown>;
|
|
118
|
+
description?: undefined;
|
|
119
|
+
/** What the body says when the `read` is empty: this stands in the body's place in a hairline frame, the `sentence` and the act after it. */
|
|
120
|
+
empty?: Empty;
|
|
121
|
+
}
|
|
122
|
+
| {
|
|
123
|
+
read: Selection<unknown>;
|
|
124
|
+
description: Datum<string>;
|
|
125
|
+
/** The act the body offers when the `read` is empty, alone in a hairline frame: the description says what the section holds, so the frame draws no sentence of its own, only the word for none when no act is given. */
|
|
126
|
+
empty?: { act: Act | LinkAct };
|
|
127
|
+
}
|
|
128
|
+
);
|
|
129
|
+
|
|
130
|
+
type Sheet<V extends string | null, Q> = SectionHeadProps & {
|
|
131
|
+
/** The heading (a short phrase; truncates); the head over the sheet is drawn with it, and a Section with no title is the sheet alone. */
|
|
132
|
+
title?: Datum<Run>;
|
|
133
|
+
/** The sheet's rows: constants (none draw the empty shape, as an empty read does), or a selection, which paints as many rows as it last loaded (`PAINT_ROWS` the first time) until its read lands, each in the regions its selector gives one record where it maps the records (`list.map(toRow)`), a list row or a file row, else a title over a facts line. A selection is the section's own frame: it holds its read and draws the failed, missing and empty shapes in the sheet's place, and the head's count is the loaded rows'. One row given alone, not in an array, is a value (a field that holds one thing), no list: it stands on the sheet as a row of a list does, and the head draws no count. */
|
|
134
|
+
items: Datum<readonly Row<V, Q>[]> | Row<V, Q>;
|
|
135
|
+
/** The sheet's bands, in order: a band over the list rows of each (their `group` is its `key`), with its label, the count of its rows (none for a lone band holding every row under a counted head, whose count is the same) and its act. Rows whose `group` names no key, or with none, stand before the first band; the painted (waiting) rows stand with no bands. A selection is the section's own read as `items` is: the rows paint with no bands until it lands, and its failed, missing and empty shapes stand in the sheet's place. */
|
|
136
|
+
groups?: Datum<readonly Band[]>;
|
|
137
|
+
/** The sheet's rows can be moved: a press that moves drags a row to the line between two others (the sheet scrolls near its edges), Alt with Up, Down, Home or End moves the focused row, and every row's more menu holds Move up, down, to top and to bottom. `onMove` hears the id and where it lands (`index`, and the ids it stands `after` and `before`); the rows show the move at once and the order the read answers replaces it. A flat sheet only: a tree or a sheet with `groups` does not reorder. */
|
|
138
|
+
reorder?: Reorder;
|
|
139
|
+
children?: never;
|
|
140
|
+
/** What the sheet says when its `items` are empty (a read that answered none, or no constants): the sentence and the act that makes the first one, in place of the generic sentence; under a `description`, with no sentence given, its act alone or the word for none. */
|
|
141
|
+
empty?: Empty;
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
/** A titled stretch of a page over its rows, or its parts. With `items` it draws the row list (a list row, a definition or a file row each); with `children` it frames parts, and `empty` belongs to the `read` it answers for, so one given without the other does not type-check; a parts Section with a `description` takes an `empty` of its `act` alone, since its frame never draws a sentence, and a described sheet draws the sentence it is given, never the generic one. */
|
|
145
|
+
export type SectionProps<V extends string | null = string, Q = unknown> =
|
|
146
|
+
| Parts
|
|
147
|
+
| Sheet<V, Q>;
|
|
148
|
+
|
|
149
|
+
/** A heading (the heading size at 500) with its count in the meta ink, description, act and more act over its body; the title folds the body when `folded` is set, at the heading size folded or not. With `items` the body is the hairline sheet on the surface, its rows abutting under a hairline once between them: one row per item, `PAINT_ROWS` rows while the `items` selection's read waits (each in the shape its selector gives one record, a list row or a file row, painted, inert and with no link; a tree draws flat then), the failed shape with Retry, the missing shape saying it was not found and the empty shape each on a sheet with the generic sentence (the empty shape under a `description` its own sentence, else its act alone or the word for none), the stale and paused line above the rows, and the count of the loaded rows after the title (its top-level rows, the items it lists, less any row with `counted: false` (a top-level row that is no item of the list: an add row, a row that only points elsewhere), with any nested row with `counted: true` (a nested row that is an item in its own right): a tree's other nested rows are parts of their row), unless every row has a label (facts, which a count does not number) or `items` is one row given alone (a value, no list). A band with `groups` spans the sheet, a `control` high, closed by a rule in the body ink, its text at the rows' inset; `children` on a list row make the sheet a tree. A definition row draws no hairlines of its own, its rows at the `control` height abutting on the sheet. With `children` the body stands on the canvas, a sections gap from the next: its parts a fields gap apart, each a card of its own (a Form, a Table, a Stats, a BarChart, or a `Card` around anything else), and its empty shape on a card of its own; the Section draws no card, no count beside its title (a count is a list's) and reads nothing of its children. A Section with `items` and no `title` draws no head: the sheet alone. A blocked act's reason draws under the head row, which never moves. No Section stands in a Section. It is a `section` with no name, so no landmark of its own (a `section` is a region only when named): the `Pane` is the page's named region, and a Section titled as its Pane is not a second region of that name. */
|
|
150
|
+
export function Section<V extends string | null = string, Q = unknown>(
|
|
151
|
+
props: SectionProps<V, Q>,
|
|
152
|
+
) {
|
|
153
|
+
return props.items === undefined ? (
|
|
154
|
+
<PartsSection {...props} />
|
|
155
|
+
) : (
|
|
156
|
+
<SheetSection {...props} />
|
|
157
|
+
);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// The shape the waiting rows paint in: one record as the items' selector maps
|
|
161
|
+
// it, a list row or a file row; else the roster's title over a facts line.
|
|
162
|
+
function paintOf<V extends string | null, Q>(
|
|
163
|
+
items: Datum<readonly Row<V, Q>[]>,
|
|
164
|
+
): Row | undefined {
|
|
165
|
+
if (!isSelection(items)) return undefined;
|
|
166
|
+
const one = sampleOf(items);
|
|
167
|
+
if (one === undefined || "path" in one) return one;
|
|
168
|
+
// The default `RowItem`, which reads no `V`: a `V` row is not assignable to it.
|
|
169
|
+
const row = one as RowItem;
|
|
170
|
+
// Facts the selector passes through whole (`facts: record.facts`) sample
|
|
171
|
+
// as the placeholder itself, a word where the facts stand: they paint one
|
|
172
|
+
// part, as facts built in parts do, so the row keeps its facts line.
|
|
173
|
+
return typeof row.facts === "string" ? { ...row, facts: [""] } : row;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// A described Section's empty shape says no generic sentence, its description
|
|
177
|
+
// saying what it holds: a sheet's own sentence stands, else the act alone, or
|
|
178
|
+
// the word for none.
|
|
179
|
+
function emptyOf(
|
|
180
|
+
description: Datum<string> | undefined,
|
|
181
|
+
empty: Empty | { act: Act | LinkAct } | undefined,
|
|
182
|
+
none: string,
|
|
183
|
+
): { sentence?: Datum<string>; act?: Act | LinkAct } | undefined {
|
|
184
|
+
if (
|
|
185
|
+
description === undefined ||
|
|
186
|
+
(empty && "sentence" in empty && empty.sentence)
|
|
187
|
+
)
|
|
188
|
+
return empty;
|
|
189
|
+
return empty?.act ? { act: empty.act } : { sentence: none };
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
function PartsSection(props: Parts) {
|
|
193
|
+
const { read, empty, description, children } = props;
|
|
194
|
+
const words = useWords();
|
|
195
|
+
const frame = useFrame(read);
|
|
196
|
+
const body =
|
|
197
|
+
read === undefined ? (
|
|
198
|
+
children
|
|
199
|
+
) : (
|
|
200
|
+
<FrameBody frame={frame} empty={emptyOf(description, empty, words.none)}>
|
|
201
|
+
{children}
|
|
202
|
+
</FrameBody>
|
|
203
|
+
);
|
|
204
|
+
return <Titled {...props} list={false} frame={frame} body={body} />;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
const NO_ROWS: readonly Row[] = [];
|
|
208
|
+
|
|
209
|
+
function SheetSection<V extends string | null, Q>(props: Sheet<V, Q>) {
|
|
210
|
+
const { title, groups, description, empty } = props;
|
|
211
|
+
// One row given alone is a value, not a list: it stands as a list of one,
|
|
212
|
+
// and its head counts nothing (a count is a list's).
|
|
213
|
+
const one = !Array.isArray(props.items) && !isSelection(props.items);
|
|
214
|
+
// `Array.isArray` narrows no readonly array out of `items`, and `one` holds
|
|
215
|
+
// the test apart from the value it tested.
|
|
216
|
+
const items = (one ? [props.items] : props.items) as Datum<
|
|
217
|
+
readonly Row<V, Q>[]
|
|
218
|
+
>;
|
|
219
|
+
const words = useWords();
|
|
220
|
+
// The sheet's data is its rows together with the reads they stand on: when
|
|
221
|
+
// `groups` is a selection, the rows paint until it lands and its
|
|
222
|
+
// failure ends the sheet, as the rows' own read does.
|
|
223
|
+
const together = [items, groups].filter(isSelection);
|
|
224
|
+
const whole =
|
|
225
|
+
isSelection(items) && together.length === 1
|
|
226
|
+
? items
|
|
227
|
+
: together.length > 0
|
|
228
|
+
? combine(together as [Selection<unknown>], (...values) =>
|
|
229
|
+
isSelection(items) ? values[0] : items,
|
|
230
|
+
)
|
|
231
|
+
: items;
|
|
232
|
+
// `combine` over the rows and the bands answers `unknown`; its answer is the rows.
|
|
233
|
+
const collection = useCollection(whole as Datum<readonly Row<V, Q>[]>);
|
|
234
|
+
const { drawn } = collection;
|
|
235
|
+
const [bands] = useSelections([groups] as const);
|
|
236
|
+
// A constant with no rows is empty as a read that answered none is: its
|
|
237
|
+
// empty shape stands (`empty`, else the generic sentence), never a sheet
|
|
238
|
+
// with nothing on it.
|
|
239
|
+
const frame: Frame =
|
|
240
|
+
!isSelection(items) && !isSelection(groups) && items.length === 0
|
|
241
|
+
? { ...collection.frame, shape: "empty" }
|
|
242
|
+
: collection.frame;
|
|
243
|
+
// The sheet is the box the rows stand in, which they window in.
|
|
244
|
+
const box = useRef<HTMLDivElement>(null);
|
|
245
|
+
// A flat sheet orders its rows as the viewer moved them. The sheet draws a
|
|
246
|
+
// row of any `V` and `Q` as the default `Row`, which reads neither: a `V`
|
|
247
|
+
// row is not assignable to it (its pick's `value` may be `null`).
|
|
248
|
+
const loaded = drawn.painted ? NO_ROWS : (drawn.value as readonly Row[]);
|
|
249
|
+
const { rows: ordered, movable } = useMovable({
|
|
250
|
+
reorder: props.reorder,
|
|
251
|
+
on:
|
|
252
|
+
props.reorder !== undefined &&
|
|
253
|
+
!drawn.painted &&
|
|
254
|
+
groups === undefined &&
|
|
255
|
+
!loaded.some((row) => "children" in row && row.children !== undefined),
|
|
256
|
+
source: drawn.painted ? undefined : drawn.value,
|
|
257
|
+
rows: loaded,
|
|
258
|
+
idOf: keyOf,
|
|
259
|
+
box,
|
|
260
|
+
});
|
|
261
|
+
// While the rows wait they paint in the shape the items' selector gives one
|
|
262
|
+
// record (its leading mark, its facts, its trailing value), so the text and
|
|
263
|
+
// the end group stand where the loaded rows' will.
|
|
264
|
+
const paint = useMemo(() => paintOf(items), [items]);
|
|
265
|
+
const forms = (
|
|
266
|
+
<FrameBody
|
|
267
|
+
frame={frame}
|
|
268
|
+
fit="part"
|
|
269
|
+
empty={emptyOf(description, empty, words.none)}
|
|
270
|
+
>
|
|
271
|
+
{title === undefined ? <FrameLine frame={frame} /> : null}
|
|
272
|
+
<PicksLine rows={loaded} />
|
|
273
|
+
<SheetCard box={box}>
|
|
274
|
+
<Rows
|
|
275
|
+
drawn={drawn.painted ? drawn : { ...drawn, value: ordered }}
|
|
276
|
+
more={pagesOf(items)}
|
|
277
|
+
box={box}
|
|
278
|
+
paint={paint}
|
|
279
|
+
groups={bands.painted ? undefined : bands.value}
|
|
280
|
+
movable={movable}
|
|
281
|
+
counted={
|
|
282
|
+
!one &&
|
|
283
|
+
title !== undefined &&
|
|
284
|
+
// A painted value is the read's placeholder, a list of rows too.
|
|
285
|
+
!factsOnly(drawn.value as readonly Row[])
|
|
286
|
+
}
|
|
287
|
+
/>
|
|
288
|
+
</SheetCard>
|
|
289
|
+
</FrameBody>
|
|
290
|
+
);
|
|
291
|
+
// The failed, missing and empty shapes stand at the sheet's inset inside the
|
|
292
|
+
// sheet's own card, headed or not, where the rows would stand.
|
|
293
|
+
const body =
|
|
294
|
+
isEnded(frame.shape) || frame.shape === "empty" ? (
|
|
295
|
+
<SheetCard>{forms}</SheetCard>
|
|
296
|
+
) : (
|
|
297
|
+
forms
|
|
298
|
+
);
|
|
299
|
+
if (title === undefined) return body;
|
|
300
|
+
return (
|
|
301
|
+
<Titled
|
|
302
|
+
{...props}
|
|
303
|
+
title={title}
|
|
304
|
+
list={!one && (drawn.painted || !factsOnly(drawn.value))}
|
|
305
|
+
frame={frame}
|
|
306
|
+
// The count is the things the Section lists: its top-level rows less
|
|
307
|
+
// those marked `counted: false`, and the nested rows marked `counted:
|
|
308
|
+
// true`, so it agrees with a head's "N steps"; a nested row is otherwise
|
|
309
|
+
// a part of its row. A read's own count is the top level, and stands
|
|
310
|
+
// unless a row says otherwise.
|
|
311
|
+
count={
|
|
312
|
+
drawn.painted || (isSelection(items) && ownCount(drawn.value))
|
|
313
|
+
? undefined
|
|
314
|
+
: listedRows(drawn.value).length
|
|
315
|
+
}
|
|
316
|
+
body={body}
|
|
317
|
+
/>
|
|
318
|
+
);
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
// What the sheet says once of the options its rows' picks read: a row's pick
|
|
322
|
+
// draws its box blocked (inert) when its options ended, the sentence and the
|
|
323
|
+
// retry stand here, a line over the sheet, never repeated in every row.
|
|
324
|
+
function PicksLine({ rows }: { rows: readonly Row[] }) {
|
|
325
|
+
const words = useWords();
|
|
326
|
+
const options = optionReads(rows);
|
|
327
|
+
const picks =
|
|
328
|
+
options.length === 0
|
|
329
|
+
? undefined
|
|
330
|
+
: combine(options as [Selection<unknown>], () => null);
|
|
331
|
+
const { drawn, retry } = useOptions(picks);
|
|
332
|
+
if (!drawn.painted) return null;
|
|
333
|
+
if (drawn.phase === "failed")
|
|
334
|
+
return (
|
|
335
|
+
<StateLine
|
|
336
|
+
sentence={words.readFailed}
|
|
337
|
+
act={{ label: words.retry, onAct: retry }}
|
|
338
|
+
/>
|
|
339
|
+
);
|
|
340
|
+
return drawn.phase === "missing" ? (
|
|
341
|
+
<StateLine sentence={words.missing} />
|
|
342
|
+
) : null;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
// The head over a body, the body folding under the title when the Section is
|
|
346
|
+
// foldable. The frame is the Section's read: its busy mark, its state line and
|
|
347
|
+
// its count stand in the head.
|
|
348
|
+
function Titled(
|
|
349
|
+
props: SectionHeadProps & {
|
|
350
|
+
title: Datum<Run>;
|
|
351
|
+
frame: Frame;
|
|
352
|
+
list: boolean;
|
|
353
|
+
count?: number;
|
|
354
|
+
body: ReactNode;
|
|
355
|
+
},
|
|
356
|
+
) {
|
|
357
|
+
const {
|
|
358
|
+
title,
|
|
359
|
+
list,
|
|
360
|
+
count,
|
|
361
|
+
description,
|
|
362
|
+
folded,
|
|
363
|
+
onToggle,
|
|
364
|
+
act,
|
|
365
|
+
more,
|
|
366
|
+
frame,
|
|
367
|
+
body,
|
|
368
|
+
} = props;
|
|
369
|
+
const level = use(HeadingContext);
|
|
370
|
+
const bodyId = useId();
|
|
371
|
+
// `folded` is the initial fold: the section holds its fold from there.
|
|
372
|
+
const [open, setOpen] = useState(folded !== true);
|
|
373
|
+
return (
|
|
374
|
+
<Collapsible.Root
|
|
375
|
+
render={<section />}
|
|
376
|
+
open={open}
|
|
377
|
+
onOpenChange={(next) => {
|
|
378
|
+
setOpen(next);
|
|
379
|
+
onToggle?.(next);
|
|
380
|
+
}}
|
|
381
|
+
aria-busy={(frame.holds && frame.shape === "waiting") || undefined}
|
|
382
|
+
data-still={stillOf(frame)}
|
|
383
|
+
className={cn(SECTION, ROWS, BOX)}
|
|
384
|
+
>
|
|
385
|
+
<SectionHead
|
|
386
|
+
title={title}
|
|
387
|
+
list={list}
|
|
388
|
+
count={count}
|
|
389
|
+
description={description}
|
|
390
|
+
act={act}
|
|
391
|
+
more={more}
|
|
392
|
+
foldable={folded !== undefined}
|
|
393
|
+
open={open}
|
|
394
|
+
bodyId={bodyId}
|
|
395
|
+
frame={frame}
|
|
396
|
+
/>
|
|
397
|
+
{/* Kept mounted while folded, so its `aria-controls` resolves in either state (Base UI names it only while open) and what the body holds (a field's text, a fold inside) keeps its state. A section without children draws no body. */}
|
|
398
|
+
{body == null || body === false ? null : (
|
|
399
|
+
<Collapsible.Panel
|
|
400
|
+
id={bodyId}
|
|
401
|
+
keepMounted
|
|
402
|
+
className={cn(SECTION_BODY, BODY)}
|
|
403
|
+
>
|
|
404
|
+
<HeadingContext value={DEEPER[level]}>{body}</HeadingContext>
|
|
405
|
+
</Collapsible.Panel>
|
|
406
|
+
)}
|
|
407
|
+
</Collapsible.Root>
|
|
408
|
+
);
|
|
409
|
+
}
|