@slotform/react-ui 0.0.0-stage → 0.1.1
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,2215 @@
|
|
|
1
|
+
import { Field } from "@base-ui/react/field";
|
|
2
|
+
import { cn } from "@slotform/ui-core/cn";
|
|
3
|
+
import type {
|
|
4
|
+
CellValue,
|
|
5
|
+
ChangeKind,
|
|
6
|
+
ChoiceRegions,
|
|
7
|
+
ColumnWidth,
|
|
8
|
+
Dragged,
|
|
9
|
+
DragSource,
|
|
10
|
+
Fact,
|
|
11
|
+
IconLinkAct,
|
|
12
|
+
Reorder,
|
|
13
|
+
StatusMark,
|
|
14
|
+
TableCell,
|
|
15
|
+
TableChoice,
|
|
16
|
+
TableColumn,
|
|
17
|
+
TablePick,
|
|
18
|
+
TableRowRegions,
|
|
19
|
+
} from "@slotform/ui-core/descriptors";
|
|
20
|
+
import { stepOf } from "@slotform/ui-core/drag";
|
|
21
|
+
import { formatterFor } from "@slotform/ui-core/format";
|
|
22
|
+
import {
|
|
23
|
+
alongRows,
|
|
24
|
+
type Chooser,
|
|
25
|
+
type Cursor,
|
|
26
|
+
cellEdit,
|
|
27
|
+
cellLocked,
|
|
28
|
+
changeKind,
|
|
29
|
+
changeMeta,
|
|
30
|
+
chipOf,
|
|
31
|
+
chooseReason,
|
|
32
|
+
columnAsked,
|
|
33
|
+
columnWidth,
|
|
34
|
+
firstDirection,
|
|
35
|
+
gridFloor,
|
|
36
|
+
hideable,
|
|
37
|
+
idsChooser,
|
|
38
|
+
isChangeCell,
|
|
39
|
+
isEnd,
|
|
40
|
+
isPick,
|
|
41
|
+
isStatusFact,
|
|
42
|
+
isTouchSplit,
|
|
43
|
+
moveCursor,
|
|
44
|
+
nextSort,
|
|
45
|
+
pageRows,
|
|
46
|
+
pickChooser,
|
|
47
|
+
rangeIds,
|
|
48
|
+
type Sort,
|
|
49
|
+
shown as shownWith,
|
|
50
|
+
sorted,
|
|
51
|
+
type TableRecord,
|
|
52
|
+
tableRecords,
|
|
53
|
+
tickable,
|
|
54
|
+
touchFacts,
|
|
55
|
+
touchNamed,
|
|
56
|
+
turnedOver,
|
|
57
|
+
} from "@slotform/ui-core/list-state";
|
|
58
|
+
import { PAINT_ROWS, painting } from "@slotform/ui-core/paint";
|
|
59
|
+
import { useClock } from "@slotform/ui-core/react/clock";
|
|
60
|
+
import { useCollection, useWindow } from "@slotform/ui-core/react/read";
|
|
61
|
+
import { useWords } from "@slotform/ui-core/react/words";
|
|
62
|
+
import {
|
|
63
|
+
type Datum,
|
|
64
|
+
isRead,
|
|
65
|
+
pagesOf,
|
|
66
|
+
placeholderData,
|
|
67
|
+
type Read,
|
|
68
|
+
readKey,
|
|
69
|
+
sameQuery,
|
|
70
|
+
windowOf,
|
|
71
|
+
} from "@slotform/ui-core/read";
|
|
72
|
+
import { sameBy } from "@slotform/ui-core/same-by";
|
|
73
|
+
import {
|
|
74
|
+
CARD,
|
|
75
|
+
FIGURES,
|
|
76
|
+
PRESS_WASH,
|
|
77
|
+
ROW_ACTS,
|
|
78
|
+
ROW_CURRENT_BAR,
|
|
79
|
+
TABLE,
|
|
80
|
+
TABLE_CELL,
|
|
81
|
+
TABLE_CHANGE,
|
|
82
|
+
TABLE_FROZEN,
|
|
83
|
+
TABLE_NAME,
|
|
84
|
+
tableChangeValue,
|
|
85
|
+
tableFrozenCell,
|
|
86
|
+
tableHead,
|
|
87
|
+
tableHeadLabel,
|
|
88
|
+
tableRow,
|
|
89
|
+
text,
|
|
90
|
+
textStrong,
|
|
91
|
+
} from "@slotform/ui-core/variants";
|
|
92
|
+
import { pagesCovering } from "@slotform/ui-core/window";
|
|
93
|
+
import {
|
|
94
|
+
type FocusEvent,
|
|
95
|
+
type KeyboardEvent,
|
|
96
|
+
type MouseEvent,
|
|
97
|
+
memo,
|
|
98
|
+
type PointerEvent,
|
|
99
|
+
type ReactNode,
|
|
100
|
+
use,
|
|
101
|
+
useCallback,
|
|
102
|
+
useEffect,
|
|
103
|
+
useLayoutEffect,
|
|
104
|
+
useMemo,
|
|
105
|
+
useRef,
|
|
106
|
+
useState,
|
|
107
|
+
} from "react";
|
|
108
|
+
import { ChipBase } from "../../atoms/chip/base.tsx";
|
|
109
|
+
import { Icon } from "../../atoms/icon/index.tsx";
|
|
110
|
+
import { LockMark } from "../../atoms/row/lock.tsx";
|
|
111
|
+
import { WarningMark } from "../../atoms/row/marks.tsx";
|
|
112
|
+
import { SheetCard } from "../../atoms/section/card.tsx";
|
|
113
|
+
import { StatusBase } from "../../atoms/status/base.tsx";
|
|
114
|
+
import { ChangeMark } from "../../atoms/status/change.tsx";
|
|
115
|
+
import { HeldCheckbox } from "../../atoms/switch/checkbox.tsx";
|
|
116
|
+
import { Turn } from "../../atoms/turn.tsx";
|
|
117
|
+
import type { IconAct, MenuEntry } from "../../lib/act.ts";
|
|
118
|
+
import { age, ageWidest } from "../../lib/age.ts";
|
|
119
|
+
import type { Closed } from "../../lib/closed.ts";
|
|
120
|
+
import { useColumns } from "../../lib/columns.ts";
|
|
121
|
+
import { PageTitle } from "../../lib/container.ts";
|
|
122
|
+
import {
|
|
123
|
+
draggedLabel,
|
|
124
|
+
press,
|
|
125
|
+
useDrop,
|
|
126
|
+
useOffers,
|
|
127
|
+
useTouchHold,
|
|
128
|
+
} from "../../lib/drag.ts";
|
|
129
|
+
import type { Empty } from "../../lib/empty.tsx";
|
|
130
|
+
import type { CellFit } from "../../lib/field.ts";
|
|
131
|
+
import { useTouch } from "../../lib/media.ts";
|
|
132
|
+
import { MoreRow } from "../../lib/more.tsx";
|
|
133
|
+
import { follow, navigate } from "../../lib/navigate.ts";
|
|
134
|
+
import { NOOP } from "../../lib/noop.ts";
|
|
135
|
+
import { Painted } from "../../lib/paint.tsx";
|
|
136
|
+
import { FrameBody, FrameLine, stillOf } from "../../lib/read.tsx";
|
|
137
|
+
import {
|
|
138
|
+
type Edge,
|
|
139
|
+
edgeOf,
|
|
140
|
+
type Movable,
|
|
141
|
+
movesOf,
|
|
142
|
+
stepKey,
|
|
143
|
+
useMovable,
|
|
144
|
+
} from "../../lib/reorder.ts";
|
|
145
|
+
import type { VarStyle } from "../../lib/style.ts";
|
|
146
|
+
import { Scroller, Window } from "../../lib/window.tsx";
|
|
147
|
+
import { IconActFace } from "../button/face.tsx";
|
|
148
|
+
import { HeldInput } from "../input/base.tsx";
|
|
149
|
+
import { MenuBase } from "../menu/base.tsx";
|
|
150
|
+
import { HeldPicker } from "../picker/base.tsx";
|
|
151
|
+
import type { RowItem } from "../section/index.tsx";
|
|
152
|
+
import { Rows } from "../section/rows.tsx";
|
|
153
|
+
import { ColumnsMenu } from "./columns.tsx";
|
|
154
|
+
|
|
155
|
+
// The table fills what its column leaves. Where the density is desktop the grid
|
|
156
|
+
// stands; on touch the rows are a list under the sort's pick. Only the live form
|
|
157
|
+
// mounts, chosen by the density (`useTouch`).
|
|
158
|
+
const FORM = "flex flex-col grow";
|
|
159
|
+
// The grid is its own stacking context, so its frozen column stands over its
|
|
160
|
+
// cells alone, never over a sheet.
|
|
161
|
+
const BOX = "flex flex-col isolate";
|
|
162
|
+
// The card's edge closes the last row: it draws no hairline of its own.
|
|
163
|
+
const BODY_ROWS = "[&>tr:last-child]:border-b-0";
|
|
164
|
+
// On every pointer the grid stands at least as wide as its columns' floors
|
|
165
|
+
// (`gridFloor`) and scrolls sideways under its frozen leading column when the
|
|
166
|
+
// page is narrower. A cell focused under that column scrolls clear of it: the
|
|
167
|
+
// scroller's padding at its start is the frozen width (the leading column's
|
|
168
|
+
// short measure, and the tick column's square before it).
|
|
169
|
+
const SCROLLS = "overflow-x-auto scroll-ps-(--container-measure-short)";
|
|
170
|
+
const SCROLLS_TICKED =
|
|
171
|
+
"overflow-x-auto scroll-ps-[calc(var(--container-measure-short)+var(--spacing-target))]";
|
|
172
|
+
const GRID = "w-full table-fixed";
|
|
173
|
+
const HEAD_CELL = "p-0 font-normal";
|
|
174
|
+
const START = "text-start";
|
|
175
|
+
const END = "text-end";
|
|
176
|
+
// The frozen columns stand over the cells that scroll beneath them: the tick
|
|
177
|
+
// column first, the leading column after it (at the tick column's width when
|
|
178
|
+
// the table chooses rows), the acts column at the end.
|
|
179
|
+
const FROZEN = "sticky z-1";
|
|
180
|
+
const FROZEN_AT = "left-0";
|
|
181
|
+
const FROZEN_AFTER_TICK = "left-target";
|
|
182
|
+
const FROZEN_END = "right-0";
|
|
183
|
+
// A cell focused under the acts column scrolls clear of it by the scroller's
|
|
184
|
+
// padding at its end: its icons (`--acts`).
|
|
185
|
+
const SCROLLS_END = "scroll-pe-[calc(var(--spacing-target)*var(--acts))]";
|
|
186
|
+
// An icon of the acts column takes a target of its own, so the icons of rows
|
|
187
|
+
// that have one and rows that have none stand in the same places. Its icon
|
|
188
|
+
// rises from the meta ink to the body ink while its row is hovered or holds
|
|
189
|
+
// focus.
|
|
190
|
+
const ACT_REGION =
|
|
191
|
+
"flex shrink-0 items-center justify-center w-target group-hover/row:*:text-ink-body group-focus-within/row:*:text-ink-body";
|
|
192
|
+
// The icons overflow the line's box centred, so a row with acts keeps the
|
|
193
|
+
// height of one without.
|
|
194
|
+
const ACTS_LINE = "flex items-center h-line-body";
|
|
195
|
+
// The tick column is a square the row's height, its tick centred. A row that
|
|
196
|
+
// carries a reason grows to the two-line row, in every cell of it.
|
|
197
|
+
const TICK_WIDTH = "w-target";
|
|
198
|
+
const TICK_BOX = "flex items-center justify-center";
|
|
199
|
+
// A row is a floor its line box and gaps grow past (never a set height): the
|
|
200
|
+
// row token, the two-line token for a row that carries a reason, and the
|
|
201
|
+
// control height under the header (its sort act is a control).
|
|
202
|
+
const FLOOR = "min-h-row";
|
|
203
|
+
const TALL = "min-h-[calc(var(--spacing-row)+var(--leading-meta))]";
|
|
204
|
+
const HEAD_FLOOR = "min-h-control";
|
|
205
|
+
// The leading cell's name over the reason a row's tick stands as it does.
|
|
206
|
+
const REASON_STACK = "flex flex-col min-w-0";
|
|
207
|
+
const SORT = cn(
|
|
208
|
+
"group/sort flex items-center w-full min-w-0",
|
|
209
|
+
PRESS_WASH,
|
|
210
|
+
"in-data-[modality=keyboard]:focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-ring",
|
|
211
|
+
);
|
|
212
|
+
const HEAD = "flex items-center gap-gap min-w-0";
|
|
213
|
+
// A header wraps between its words to a second line before it cuts, a word
|
|
214
|
+
// longer than its column breaking inside itself rather than standing cut; its
|
|
215
|
+
// column floor takes its longest word into account (`columnFloor`).
|
|
216
|
+
const LABEL = "min-w-0 line-clamp-2 wrap-break-word";
|
|
217
|
+
const GLYPH_SORTED = "flex shrink-0 text-ink-body";
|
|
218
|
+
// An unsorted column shows the both-ways arrow under the pointer and the
|
|
219
|
+
// keyboard.
|
|
220
|
+
const GLYPH_HINT =
|
|
221
|
+
"invisible flex shrink-0 text-ink-meta group-hover/sort:visible group-focus-visible/sort:visible";
|
|
222
|
+
// The cell cursor rings inward; the grid holds one cell at tabindex 0. Every
|
|
223
|
+
// body cell sets tabular figures, so a column's digits line up whatever it holds.
|
|
224
|
+
const BODY_CELL = cn(
|
|
225
|
+
FIGURES,
|
|
226
|
+
"p-0 in-data-[modality=keyboard]:focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-ring",
|
|
227
|
+
);
|
|
228
|
+
const CELL = "flex items-center gap-gap min-w-0";
|
|
229
|
+
const CELL_END = "justify-end";
|
|
230
|
+
const VALUE = "truncate";
|
|
231
|
+
const WRAP = "break-words hyphens-auto";
|
|
232
|
+
const CHANGE = "flex items-center min-w-0";
|
|
233
|
+
// A change in a column that wraps: its before and its after share the cell's width
|
|
234
|
+
// beside the arrow and wrap at their words, the arrow one item centred on the cell.
|
|
235
|
+
// Each takes an equal share of what the arrow and the gaps leave (`flex-1 basis-0`), so a
|
|
236
|
+
// long unbroken run breaks inside its share; a short value does not lend its room.
|
|
237
|
+
const CHANGE_WRAP = cn("flex-1 basis-0 min-w-0", WRAP);
|
|
238
|
+
// The leading cell's change mark and the name (with the reason under it) side
|
|
239
|
+
// by side, the mark centred on the name's own line.
|
|
240
|
+
const CHANGE_LEAD = "flex items-start min-w-0";
|
|
241
|
+
const MARK_LINE = "flex shrink-0 items-center h-line-body";
|
|
242
|
+
// A row that opens washes under the pointer and the press, the open record a
|
|
243
|
+
// step darker under the pointer; its frozen cell repeats the wash over its
|
|
244
|
+
// own surface.
|
|
245
|
+
const ROW = "group/row";
|
|
246
|
+
const ROW_CHOSEN_PRESS = "hover:bg-wash-selected-hover active:bg-wash-press";
|
|
247
|
+
const FROZEN_PRESS =
|
|
248
|
+
"group-hover/row:bg-wash-hover group-active/row:bg-wash-press";
|
|
249
|
+
const FROZEN_CHOSEN_PRESS =
|
|
250
|
+
"group-hover/row:bg-wash-selected-hover group-active/row:bg-wash-press";
|
|
251
|
+
// The row the cell cursor stands in washes like the pointer's row while the
|
|
252
|
+
// keyboard holds the focus, so the active row reads along its whole width.
|
|
253
|
+
const ROW_ACTIVE = "has-[:focus-visible]:bg-wash-hover";
|
|
254
|
+
const ROW_CHOSEN_ACTIVE = "has-[:focus-visible]:bg-wash-selected-hover";
|
|
255
|
+
const FROZEN_ACTIVE = "group-has-[:focus-visible]/row:bg-wash-hover";
|
|
256
|
+
const FROZEN_CHOSEN_ACTIVE =
|
|
257
|
+
"group-has-[:focus-visible]/row:bg-wash-selected-hover";
|
|
258
|
+
// The bar over the grid: the read's total, formatted, in the meta ink at its start
|
|
259
|
+
// (a windowed read says how many rows it holds, the grid's scroll being the
|
|
260
|
+
// only other sign), the columns menu at its end. The sort's pick over the
|
|
261
|
+
// touch list stands at the same end.
|
|
262
|
+
const BAR = "flex items-center justify-end";
|
|
263
|
+
const COUNT = "me-auto tabular-nums";
|
|
264
|
+
const TOTAL = formatterFor("number");
|
|
265
|
+
|
|
266
|
+
// A column's width: its measure, its share, or what the others leave (never
|
|
267
|
+
// less than the short measure, by the grid's floor).
|
|
268
|
+
const WIDTH: Record<ColumnWidth, string> = {
|
|
269
|
+
"measure-short": "w-measure-short",
|
|
270
|
+
"1/4": "w-1/4",
|
|
271
|
+
};
|
|
272
|
+
|
|
273
|
+
interface TableBase<T, Q> extends Closed {
|
|
274
|
+
/** The items the rows draw: constants, or a selection, which paints `PAINT_ROWS` rows until its read lands. A selection is the table's own frame: it holds its read and draws the failed, missing and empty shapes in its own box whatever stands above it. A window read (`orpc.x.list.window(input)`) under a scroller sizes the grid to its total and loads the pages the view covers; a paginated read whose procedure declares `sort` is sorted by the server through the header. */
|
|
275
|
+
items: Datum<readonly T[]> | Read<readonly T[], Q>;
|
|
276
|
+
/** The columns in order, the first the row's name, each reading its cell from the item. A header is never cut while it can wrap: it wraps between its words to a second line, and a column takes the room of its header's longest word where the short measure cannot hold it. A `chip` column with no `width` takes the room of its widest chip where the short measure cannot hold it, so a chip is never cut while a free text column has room. */
|
|
277
|
+
columns: readonly TableColumn<T>[];
|
|
278
|
+
/** The row's own regions, each read from the item: `editable` (false: its cells draw the plain value, no mark, no act, for a row that is simply not editable in place) and `locked` (the columns held read only, each drawing the lock, the hold of an open change set); `act` (the row's one icon act at its end, with its wiring) and `more` (its other acts), which draw an acts column at the grid's end and the keys on the active row (Shift+Enter runs the act, Enter too where the row opens nothing, the Context Menu key opens the menu); and `drop` (the row takes a drag, like a Shell place). */
|
|
279
|
+
row: RowRegions<T, Q>;
|
|
280
|
+
/** The rows can be dragged (a press that moves; a finger after a hold) onto a `drop`: a Shell place with one, or a row of another collection. A ticked row drags every row ticked, over a pick of the query too, an unticked one itself; what it carries is `{ kind, picked }`. Each drop that accepts the kind is also an entry in the rows' more menu, so a drag is never the pointer's alone. */
|
|
281
|
+
drag?: DragSource;
|
|
282
|
+
/** What the table says in its own box when its `items` selection answers none: the `sentence` and the act that makes the first row (an act that runs, or a `{ label, href }` that goes to a route), the form a `Section`'s `empty` draws. A constant from the parent: a screen with a filter on gives the sentence for it, so the table knows nothing of filters. Without it the generic sentence stands, with no act. */
|
|
283
|
+
empty?: Empty;
|
|
284
|
+
/** The rows can be moved within the grid while it is unsorted: the pointer lands a row at the line between two others (the page scrolls near its edges), Alt with Up, Down, Home or End moves the active row, and the 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 grid shows the move at once and the order the read answers replaces it. */
|
|
285
|
+
reorder?: Reorder;
|
|
286
|
+
/** The table's accessible name (a short phrase), for a page that holds more than one table; without it the page's title names the grid. */
|
|
287
|
+
label?: string;
|
|
288
|
+
/** The open record's id, washed as selected. */
|
|
289
|
+
selected?: string;
|
|
290
|
+
/** The id of the current row, the one a list stands at beside the open record (what is playing, the step a run is at): the current bar at its start, as the open row of a list carries it, and `aria-current` for assistive tech. On touch the row is current in a list row's way, the bar and the wash. */
|
|
291
|
+
current?: string;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
/** The rows the viewer ticks. */
|
|
295
|
+
type Chooses<T, Q> =
|
|
296
|
+
| { choose?: undefined }
|
|
297
|
+
| {
|
|
298
|
+
/** The rows the viewer ticks: a tick column leads the grid (its head tick over the rows that can be ticked) and, on touch, each row's leading is its tick. `chosen` is the ticked ids and `onChange` hears the set a tick makes, which the consumer applies its rule to and hands back through `chosen`; `blocked` and `moved` give a row's reason under its leading cell. Over a paginated read (`pages` or `window`), `{ picked, onPick, … }` holds a `Picked` instead: the head tick chooses the read's query, every row it matches loaded or not, and a tick then unticks a row (`except`); a mutation takes `picked` whole (`selector()` of `@slotform/api`). A filter that changes the query ends a pick of the old one. The acts that apply to the rows ticked are the Pane's `foot`, an `ActionBar` with `chosen` (the count: the ticked and the rows that can be ticked, M, and a select-all that hears the set both make) the consumer gives it. */
|
|
299
|
+
choose: TableChoice<T> | TablePick<T, Q>;
|
|
300
|
+
};
|
|
301
|
+
|
|
302
|
+
interface Reads {
|
|
303
|
+
/** Opens a record: a press on its row, Enter on its leading cell. */
|
|
304
|
+
onOpen?: (id: string) => void;
|
|
305
|
+
onEdit?: never;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
interface Edits {
|
|
309
|
+
/** Opens a record: a press on its row, Enter on its leading cell. A Table whose columns edit takes it, since a phone edits through the record it shows. */
|
|
310
|
+
onOpen: (id: string) => void;
|
|
311
|
+
/** Hears one committed edit of a cell whose column edits; a phone edits through the record `onOpen` shows. Return the save's promise and the cell's control holds the viewer's value while it pends; a refusal puts it back, with its reason. */
|
|
312
|
+
onEdit?: (id: string, key: string, value: CellValue) => unknown;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
/** The Table's row regions: ui-core's, whose `act` and `more` the platform widens with the `sheet` an act may open. */
|
|
316
|
+
export type RowRegions<T, Q = unknown> = Omit<
|
|
317
|
+
TableRowRegions<T, Q>,
|
|
318
|
+
"act" | "more"
|
|
319
|
+
> & {
|
|
320
|
+
act?: (item: T) => IconAct | IconLinkAct | undefined;
|
|
321
|
+
more?: (item: T) => readonly MenuEntry[] | undefined;
|
|
322
|
+
};
|
|
323
|
+
|
|
324
|
+
/** Records in columns, from items. */
|
|
325
|
+
export type TableProps<T = unknown, Q = unknown> = TableBase<T, Q> &
|
|
326
|
+
Chooses<T, Q> &
|
|
327
|
+
(Reads | Edits);
|
|
328
|
+
|
|
329
|
+
// What a cell reads as, an age in this platform's words.
|
|
330
|
+
function shown(column: TableColumn, cell: TableCell | undefined): string {
|
|
331
|
+
return shownWith(column, cell, age);
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
// Focus inside an open edit: an Input's value.
|
|
335
|
+
const inEdit = (target: HTMLElement) => target instanceof HTMLInputElement;
|
|
336
|
+
|
|
337
|
+
function editOf(
|
|
338
|
+
columns: readonly TableColumn[],
|
|
339
|
+
at: number,
|
|
340
|
+
edits: boolean,
|
|
341
|
+
row: TableRecord,
|
|
342
|
+
) {
|
|
343
|
+
const column = columns[at];
|
|
344
|
+
return column ? cellEdit(column, at === 0, edits, row) : undefined;
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
/** Where the density is desktop a grid: a header of sortable acts (the table sorts in its own state: newest or largest first, then turned over, then off) over one row per record, its leading cell the record's name (its row's change mark, when it has one, ahead of it and its warning after it); a `chip` column draws each cell on the column's `family`, or on its own where the cell returns `{ label, family }`; its columns never squeeze below the short measure (the grid stands at least `gridFloor` wide) and, when its column is narrower, the grid scrolls sideways on every pointer under its frozen leading column. Its keyboard is a cell cursor (one Tab stop, the arrows, Home and End; Enter opens the row from its leading cell or edits an editable cell, Escape leaves an edit); a press on a row opens it, a press on an editable value edits it in place, typed in an `Input`. On touch one `Row` per record (its leading cell the title, its change the row's mark, its first age trailing and a further one a fact that says its column, "Seen: 1 day ago", each status column a status badge with its tone mark, the first leading, a table with several saying their column, "Staging: Passing", as does any words value of a kind that stands in more than one column, "Observed: usd"; warning and chip the marks, the other values its facts, a value longer than a fact holds (the short measure, its label with it) said whole in the row's line instead) under the sort's pick. Over a paginated read whose procedure declares `sort` the header sorts through the read's input (the server orders the whole query, and a column the procedure does not name does not sort); over a window read under a scroller the grid is as long as the read's total, mounts the rows in view and loads the pages they stand in wherever the scrollbar lands (rows not loaded yet stand painted), and a changed query keeps the previous rows drawn until its first page lands; over a cursor read that scrolls (`VIRTUAL_FROM` rows) the next page loads as the end nears. While the `items` selection's read waits, `PAINT_ROWS` rows stand in the columns the table declares (the regions are run over the placeholder), the header constant over them, each cell painted by its column's kind and the rows inert, busy only while the read waits (a read not asked for yet stands painted and still); the touch list paints the same records as its rows. The table is a frame of its items: it draws the failed shape with Retry, the missing shape and the empty shape (its `empty`, else the generic sentence) in its own box, and the stale and paused line above its rows while it holds its read, whatever stands above it. With `choose` it ticks rows; the acts that apply to them are the Pane's `foot`, a chosen bar the consumer gives (an `ActionBar` with `chosen`). On touch the rows stand on a hairline sheet like any list's, the sort's pick bare above it. */
|
|
348
|
+
export function Table<T, Q = unknown>(props: TableProps<T, Q>) {
|
|
349
|
+
const { selected, current, onOpen, onEdit, choose } = props;
|
|
350
|
+
const rootBox = useRef<HTMLDivElement | null>(null);
|
|
351
|
+
const wide = !useTouch();
|
|
352
|
+
const scroll = use(Scroller);
|
|
353
|
+
const [picked, setSort] = useState<Sort>();
|
|
354
|
+
// The columns the viewer has shown (the consumer's `hidden` under what the
|
|
355
|
+
// viewer chose, kept per table); a sort on a column that is hidden is off.
|
|
356
|
+
const {
|
|
357
|
+
shown: visible,
|
|
358
|
+
choice,
|
|
359
|
+
toggle,
|
|
360
|
+
reset,
|
|
361
|
+
} = useColumns(props.columns, props.label);
|
|
362
|
+
const sort =
|
|
363
|
+
picked && visible.some((column) => column.key === picked.key)
|
|
364
|
+
? picked
|
|
365
|
+
: undefined;
|
|
366
|
+
// A read's `sort` is ordered by the server: docs/architecture/plugins/react-ui.md, "Table".
|
|
367
|
+
const sorting = isRead(props.items) ? props.items.sorting : undefined;
|
|
368
|
+
const items$ = useMemo<Datum<readonly T[]>>(
|
|
369
|
+
() =>
|
|
370
|
+
sorting && sort
|
|
371
|
+
? // `isRead` narrows to a read of unknown rows; its sorted read holds these.
|
|
372
|
+
(sorting.by({
|
|
373
|
+
column: sort.key,
|
|
374
|
+
direction: sort.direction === "ascending" ? "asc" : "desc",
|
|
375
|
+
}) as Datum<readonly T[]>)
|
|
376
|
+
: props.items,
|
|
377
|
+
[props.items, sorting, sort],
|
|
378
|
+
);
|
|
379
|
+
const windowRead = windowOf(items$);
|
|
380
|
+
const columns = useMemo(() => {
|
|
381
|
+
const keep = sorting?.columns ?? (windowRead ? [] : undefined);
|
|
382
|
+
return keep
|
|
383
|
+
? visible.map((column) =>
|
|
384
|
+
column.sortable && !keep.includes(column.key)
|
|
385
|
+
? { ...column, sortable: false }
|
|
386
|
+
: column,
|
|
387
|
+
)
|
|
388
|
+
: visible;
|
|
389
|
+
}, [visible, sorting, windowRead]);
|
|
390
|
+
// The widening of `act` and `more` by the sheet an act may open is the
|
|
391
|
+
// platform's; the records are ui-core's.
|
|
392
|
+
const regions = props.row as unknown as TableRowRegions<T, Q>;
|
|
393
|
+
const { drawn, frame } = useCollection(items$);
|
|
394
|
+
// A window read under a scroller, in the grid: the rows stand at their
|
|
395
|
+
// places in a scroller sized to the total, and the pages the view covers load.
|
|
396
|
+
const view = useWindow(windowRead);
|
|
397
|
+
const virtual = windowRead !== undefined && scroll !== null && wide;
|
|
398
|
+
// Painted, `PAINT_ROWS` records over the placeholder, in the order the
|
|
399
|
+
// data would arrive. A window keeps the previous query's rows drawn until
|
|
400
|
+
// the new query's first page lands.
|
|
401
|
+
const painted = virtual ? view === undefined : drawn.painted;
|
|
402
|
+
const loaded: readonly T[] = painted
|
|
403
|
+
? Array.from({ length: PAINT_ROWS }, () => drawn.value as T)
|
|
404
|
+
: // Unpainted, the value is the rows: `painted` also counts a window
|
|
405
|
+
// waiting, so it does not narrow `drawn`.
|
|
406
|
+
(drawn.value as readonly T[]);
|
|
407
|
+
const made = painted
|
|
408
|
+
? tableRecords(loaded, columns, regions, props.choose, true)
|
|
409
|
+
: virtual && view
|
|
410
|
+
? placed(
|
|
411
|
+
// A window page holds the read's rows, untyped by the port.
|
|
412
|
+
view.rows as readonly T[],
|
|
413
|
+
view.total,
|
|
414
|
+
columns,
|
|
415
|
+
regions,
|
|
416
|
+
props.choose,
|
|
417
|
+
)
|
|
418
|
+
: tableRecords(loaded, columns, regions, props.choose);
|
|
419
|
+
const arranged: readonly (TableRecord | undefined)[] =
|
|
420
|
+
painted || virtual || sorting
|
|
421
|
+
? made
|
|
422
|
+
: // Only a window's records hold holes, and a window is not sorted here.
|
|
423
|
+
sorted(made as TableRecord[], columns, sort);
|
|
424
|
+
// The rows the viewer has moved stand where they moved them to, until the
|
|
425
|
+
// data answers another order; a grid sorted by a column has no order of its own to move.
|
|
426
|
+
const { rows: records, movable } = useMovable({
|
|
427
|
+
reorder: props.reorder,
|
|
428
|
+
on: !painted && sort === undefined,
|
|
429
|
+
source: virtual ? view?.rows : drawn.value,
|
|
430
|
+
rows: arranged,
|
|
431
|
+
idOf: recordId,
|
|
432
|
+
box: rootBox,
|
|
433
|
+
});
|
|
434
|
+
const standing = records.filter(
|
|
435
|
+
(one): one is TableRecord => one !== undefined,
|
|
436
|
+
);
|
|
437
|
+
const more = painted ? undefined : pagesOf(items$);
|
|
438
|
+
// `pagesOf` reads any datum, so its query is untyped; it is this read's.
|
|
439
|
+
const query = more?.query as Q | undefined;
|
|
440
|
+
const total = view && windowRead ? view.total : undefined;
|
|
441
|
+
const chooser: Chooser | undefined = !choose
|
|
442
|
+
? undefined
|
|
443
|
+
: isPick(choose)
|
|
444
|
+
? pickChooser(standing, choose.picked, choose.onPick, { query, total })
|
|
445
|
+
: idsChooser(standing, choose.chosen, choose.onChange);
|
|
446
|
+
// A pick of a query ends when the read answers another (a filter): its
|
|
447
|
+
// rows are not the ones shown. A changed read also scrolls back to the top.
|
|
448
|
+
const key = readKey(items$);
|
|
449
|
+
const last = useRef(key);
|
|
450
|
+
useEffect(() => {
|
|
451
|
+
if (
|
|
452
|
+
choose &&
|
|
453
|
+
isPick(choose) &&
|
|
454
|
+
"query" in choose.picked &&
|
|
455
|
+
!sameQuery(choose.picked.query, query)
|
|
456
|
+
) {
|
|
457
|
+
choose.onPick({ ids: [] });
|
|
458
|
+
}
|
|
459
|
+
});
|
|
460
|
+
useLayoutEffect(() => {
|
|
461
|
+
if (last.current === key) return;
|
|
462
|
+
last.current = key;
|
|
463
|
+
scroll?.holder.current?.scrollTo({ top: 0 });
|
|
464
|
+
}, [key, scroll]);
|
|
465
|
+
// The pages of the rows mounted load, whichever place the scrollbar lands.
|
|
466
|
+
const onRange = useCallback(
|
|
467
|
+
(indices: readonly number[]) => {
|
|
468
|
+
if (!view) return;
|
|
469
|
+
view
|
|
470
|
+
.ensure(pagesCovering(indices, view.size, view.total))
|
|
471
|
+
// A page that failed stands painted; the next scroll asks for it again.
|
|
472
|
+
.catch(NOOP);
|
|
473
|
+
},
|
|
474
|
+
[view],
|
|
475
|
+
);
|
|
476
|
+
const blank = more
|
|
477
|
+
? tableRecords(
|
|
478
|
+
// The placeholder stands for an item; the regions are painted over it.
|
|
479
|
+
[placeholderData() as T],
|
|
480
|
+
columns,
|
|
481
|
+
regions,
|
|
482
|
+
props.choose,
|
|
483
|
+
true,
|
|
484
|
+
)[0]
|
|
485
|
+
: undefined;
|
|
486
|
+
// The acts column stands when the rows have an act or a menu: their own
|
|
487
|
+
// `more`, the drops that accept what they drag, the moves of a table that reorders.
|
|
488
|
+
const offered = useOffers(props.drag?.kind, OFFER).length > 0;
|
|
489
|
+
const menu = props.row.more !== undefined || movable !== undefined || offered;
|
|
490
|
+
let form: ReactNode;
|
|
491
|
+
if (wide) {
|
|
492
|
+
form = (
|
|
493
|
+
<Grid
|
|
494
|
+
columns={columns}
|
|
495
|
+
rows={records}
|
|
496
|
+
sort={sort}
|
|
497
|
+
onSort={(column) => setSort((current) => nextSort(current, column))}
|
|
498
|
+
selected={selected}
|
|
499
|
+
chooser={chooser}
|
|
500
|
+
current={current}
|
|
501
|
+
onOpen={onOpen}
|
|
502
|
+
onEdit={onEdit}
|
|
503
|
+
painted={painted}
|
|
504
|
+
busy={frame.holds && frame.shape === "waiting"}
|
|
505
|
+
more={virtual ? undefined : more}
|
|
506
|
+
onRange={virtual ? onRange : undefined}
|
|
507
|
+
label={props.label}
|
|
508
|
+
drag={props.drag}
|
|
509
|
+
movable={movable}
|
|
510
|
+
hasAct={props.row.act !== undefined}
|
|
511
|
+
menu={menu}
|
|
512
|
+
/>
|
|
513
|
+
);
|
|
514
|
+
} else {
|
|
515
|
+
const list = (
|
|
516
|
+
<Phone
|
|
517
|
+
columns={columns}
|
|
518
|
+
rows={standing}
|
|
519
|
+
sort={sort}
|
|
520
|
+
onSort={setSort}
|
|
521
|
+
selected={selected}
|
|
522
|
+
onOpen={onOpen}
|
|
523
|
+
chooser={chooser}
|
|
524
|
+
current={current}
|
|
525
|
+
painted={painted}
|
|
526
|
+
more={more}
|
|
527
|
+
blank={blank}
|
|
528
|
+
drag={props.drag}
|
|
529
|
+
movable={movable}
|
|
530
|
+
warns={props.row.warning !== undefined}
|
|
531
|
+
links={props.row.href !== undefined}
|
|
532
|
+
changes={props.row.change !== undefined}
|
|
533
|
+
/>
|
|
534
|
+
);
|
|
535
|
+
form = props.label ? (
|
|
536
|
+
// biome-ignore lint/a11y/useSemanticElements: a fieldset groups a form's controls; this names a list of rows
|
|
537
|
+
<div className={FORM} role="group" aria-label={props.label}>
|
|
538
|
+
{list}
|
|
539
|
+
</div>
|
|
540
|
+
) : (
|
|
541
|
+
<div className={FORM}>{list}</div>
|
|
542
|
+
);
|
|
543
|
+
}
|
|
544
|
+
return (
|
|
545
|
+
<div
|
|
546
|
+
ref={rootBox}
|
|
547
|
+
data-wide=""
|
|
548
|
+
data-still={stillOf(frame)}
|
|
549
|
+
className={FORM}
|
|
550
|
+
>
|
|
551
|
+
<FrameBody frame={frame} empty={props.empty}>
|
|
552
|
+
<FrameLine frame={frame} />
|
|
553
|
+
{wide && (hideable(props.columns) || total !== undefined) ? (
|
|
554
|
+
<div className={BAR}>
|
|
555
|
+
{total === undefined ? null : (
|
|
556
|
+
<span className={cn(text({ role: "meta" }), COUNT)}>
|
|
557
|
+
{TOTAL.format(total)}
|
|
558
|
+
</span>
|
|
559
|
+
)}
|
|
560
|
+
{hideable(props.columns) ? (
|
|
561
|
+
<ColumnsMenu
|
|
562
|
+
columns={props.columns}
|
|
563
|
+
choice={choice}
|
|
564
|
+
onToggle={toggle}
|
|
565
|
+
onReset={reset}
|
|
566
|
+
/>
|
|
567
|
+
) : null}
|
|
568
|
+
</div>
|
|
569
|
+
) : null}
|
|
570
|
+
{form}
|
|
571
|
+
</FrameBody>
|
|
572
|
+
</div>
|
|
573
|
+
);
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
// Only whether a drop accepts the kind is asked of it, so no row is read.
|
|
577
|
+
const OFFER = (): Dragged => ({ kind: "", picked: { ids: [] } });
|
|
578
|
+
|
|
579
|
+
const recordId = (record: TableRecord | undefined) => record?.id;
|
|
580
|
+
|
|
581
|
+
// The records of a window's loaded rows at their places, `total` long with a
|
|
582
|
+
// hole where a page is not loaded.
|
|
583
|
+
function placed<T>(
|
|
584
|
+
rows: readonly T[],
|
|
585
|
+
total: number,
|
|
586
|
+
columns: readonly TableColumn<T>[],
|
|
587
|
+
row: TableRowRegions<T>,
|
|
588
|
+
choose: ChoiceRegions<T> | undefined,
|
|
589
|
+
): (TableRecord | undefined)[] {
|
|
590
|
+
const at: number[] = [];
|
|
591
|
+
const items: T[] = [];
|
|
592
|
+
// `rows` is sparse and `forEach` skips its holes, so `at` holds each
|
|
593
|
+
// loaded row's place.
|
|
594
|
+
rows.forEach((item, index) => {
|
|
595
|
+
at.push(index);
|
|
596
|
+
items.push(item);
|
|
597
|
+
});
|
|
598
|
+
const records = new Array<TableRecord | undefined>(total);
|
|
599
|
+
// `tableRecords` makes one record per item, in the order of `items`.
|
|
600
|
+
tableRecords(items, columns, row, choose).forEach((record, k) => {
|
|
601
|
+
records[at[k] as number] = record;
|
|
602
|
+
});
|
|
603
|
+
return records;
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
// What a row and its cells call back into the grid: one object for the grid's
|
|
607
|
+
// life, reading the grid's latest render, so a memoised row or cell never
|
|
608
|
+
// re-renders for a new callback.
|
|
609
|
+
interface GridActions {
|
|
610
|
+
start: (row: string, column: number) => void;
|
|
611
|
+
edit: (row: TableRecord, column: TableColumn, value: CellValue) => unknown;
|
|
612
|
+
click: (event: MouseEvent, row: TableRecord) => void;
|
|
613
|
+
tick: (row: TableRecord, on: boolean) => void;
|
|
614
|
+
// What a drag of the row carries now: the pick when the row is in it.
|
|
615
|
+
dragged: (id: string) => Dragged;
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
type Editing = "started" | "entered";
|
|
619
|
+
|
|
620
|
+
// A row re-renders only when its record, its selection, its tick or the
|
|
621
|
+
// cursor's place in it changes. The cursor's columns count the tick column
|
|
622
|
+
// first when the table chooses rows (`choosing`).
|
|
623
|
+
const Row = memo(function Row(props: {
|
|
624
|
+
row: TableRecord;
|
|
625
|
+
index: number;
|
|
626
|
+
columns: readonly TableColumn[];
|
|
627
|
+
chosen: boolean;
|
|
628
|
+
choosing: boolean;
|
|
629
|
+
current: boolean;
|
|
630
|
+
ticked: boolean;
|
|
631
|
+
opens: boolean;
|
|
632
|
+
edits: boolean;
|
|
633
|
+
// The cursor's column in this row, else -1, and its edit.
|
|
634
|
+
cursor: number;
|
|
635
|
+
editing: Editing | undefined;
|
|
636
|
+
// The acts column: whether the table's rows have an act, a menu.
|
|
637
|
+
hasAct: boolean;
|
|
638
|
+
menu: boolean;
|
|
639
|
+
// What the row drags (the kind), and the order it moves in with its place.
|
|
640
|
+
kind: string | undefined;
|
|
641
|
+
movable: Movable | undefined;
|
|
642
|
+
edge: Edge | undefined;
|
|
643
|
+
actions: GridActions;
|
|
644
|
+
}) {
|
|
645
|
+
const { row, index, columns, choosing, opens, actions } = props;
|
|
646
|
+
// A drag over a row that takes it, and a ticked row, wash it as the open record is, in the neutral wash.
|
|
647
|
+
const { mark, over } = useDrop(row.drop, row.href);
|
|
648
|
+
const chosen = props.chosen || over || props.ticked;
|
|
649
|
+
const lead = columns[0];
|
|
650
|
+
const name = lead ? shown(lead, row.cells[lead.key]) : "";
|
|
651
|
+
const shift = choosing ? 1 : 0;
|
|
652
|
+
const reason = chooseReason(row);
|
|
653
|
+
return (
|
|
654
|
+
<tr
|
|
655
|
+
aria-rowindex={index + 2}
|
|
656
|
+
aria-selected={props.chosen || props.ticked || undefined}
|
|
657
|
+
aria-current={props.current ? "true" : undefined}
|
|
658
|
+
onClick={(event) => actions.click(event, row)}
|
|
659
|
+
{...mark}
|
|
660
|
+
className={cn(
|
|
661
|
+
tableRow({ state: chosen ? "selected" : "rest" }),
|
|
662
|
+
ROW,
|
|
663
|
+
opens && (chosen ? ROW_CHOSEN_PRESS : PRESS_WASH),
|
|
664
|
+
chosen ? ROW_CHOSEN_ACTIVE : ROW_ACTIVE,
|
|
665
|
+
)}
|
|
666
|
+
>
|
|
667
|
+
{choosing ? (
|
|
668
|
+
<TickCell
|
|
669
|
+
row={row}
|
|
670
|
+
name={name}
|
|
671
|
+
ticked={props.ticked}
|
|
672
|
+
tall={reason !== undefined}
|
|
673
|
+
current={props.current}
|
|
674
|
+
chosen={chosen}
|
|
675
|
+
opens={opens}
|
|
676
|
+
here={props.cursor === 0}
|
|
677
|
+
actions={actions}
|
|
678
|
+
/>
|
|
679
|
+
) : null}
|
|
680
|
+
{columns.map((column, place) => (
|
|
681
|
+
<Cell
|
|
682
|
+
key={column.key}
|
|
683
|
+
row={row}
|
|
684
|
+
column={column}
|
|
685
|
+
place={place + shift}
|
|
686
|
+
leading={place === 0}
|
|
687
|
+
cell={row.cells[column.key]}
|
|
688
|
+
control={editOf(columns, place, props.edits, row)}
|
|
689
|
+
locked={cellLocked(column, place === 0, props.edits, row)}
|
|
690
|
+
frozen={place === 0}
|
|
691
|
+
shifted={choosing}
|
|
692
|
+
current={props.current && place === 0 && !choosing}
|
|
693
|
+
reason={reason}
|
|
694
|
+
chosen={chosen}
|
|
695
|
+
opens={opens}
|
|
696
|
+
here={props.cursor === place + shift}
|
|
697
|
+
editing={props.cursor === place + shift ? props.editing : undefined}
|
|
698
|
+
actions={actions}
|
|
699
|
+
/>
|
|
700
|
+
))}
|
|
701
|
+
{props.hasAct || props.menu ? (
|
|
702
|
+
<ActsCell
|
|
703
|
+
row={row}
|
|
704
|
+
name={name}
|
|
705
|
+
place={columns.length + shift}
|
|
706
|
+
here={props.cursor === columns.length + shift}
|
|
707
|
+
chosen={chosen}
|
|
708
|
+
opens={opens}
|
|
709
|
+
hasAct={props.hasAct}
|
|
710
|
+
menu={props.menu}
|
|
711
|
+
kind={props.kind}
|
|
712
|
+
movable={props.movable}
|
|
713
|
+
edge={props.edge}
|
|
714
|
+
actions={actions}
|
|
715
|
+
/>
|
|
716
|
+
) : null}
|
|
717
|
+
</tr>
|
|
718
|
+
);
|
|
719
|
+
}, sameBy("row"));
|
|
720
|
+
|
|
721
|
+
// A row's tick cell: a Checkbox named by the leading cell's name, disabled
|
|
722
|
+
// while the row is blocked. Frozen
|
|
723
|
+
// first, the leading column freezing after it.
|
|
724
|
+
function TickCell(props: {
|
|
725
|
+
row: TableRecord;
|
|
726
|
+
name: string;
|
|
727
|
+
ticked: boolean;
|
|
728
|
+
current: boolean;
|
|
729
|
+
tall: boolean;
|
|
730
|
+
chosen: boolean;
|
|
731
|
+
opens: boolean;
|
|
732
|
+
here: boolean;
|
|
733
|
+
actions: GridActions;
|
|
734
|
+
}) {
|
|
735
|
+
const { row, actions } = props;
|
|
736
|
+
const box = cn(TICK_BOX, props.tall ? TALL : FLOOR);
|
|
737
|
+
const cell = cn(
|
|
738
|
+
BODY_CELL,
|
|
739
|
+
TABLE_FROZEN,
|
|
740
|
+
FROZEN,
|
|
741
|
+
FROZEN_AT,
|
|
742
|
+
props.current && ROW_CURRENT_BAR,
|
|
743
|
+
tableFrozenCell({ state: props.chosen ? "selected" : "rest" }),
|
|
744
|
+
props.opens && (props.chosen ? FROZEN_CHOSEN_PRESS : FROZEN_PRESS),
|
|
745
|
+
props.chosen ? FROZEN_CHOSEN_ACTIVE : FROZEN_ACTIVE,
|
|
746
|
+
);
|
|
747
|
+
return (
|
|
748
|
+
<td
|
|
749
|
+
data-row={row.id}
|
|
750
|
+
data-column={0}
|
|
751
|
+
data-choose=""
|
|
752
|
+
tabIndex={props.here ? 0 : -1}
|
|
753
|
+
className={cell}
|
|
754
|
+
>
|
|
755
|
+
{/* biome-ignore lint/a11y/noLabelWithoutControl: the Checkbox inside is the control */}
|
|
756
|
+
<label className={box}>
|
|
757
|
+
<Field.Root disabled={row.blocked !== undefined}>
|
|
758
|
+
<HeldCheckbox
|
|
759
|
+
tabIndex={-1}
|
|
760
|
+
target={{}}
|
|
761
|
+
checked={props.ticked}
|
|
762
|
+
onChange={(on) => actions.tick(row, on)}
|
|
763
|
+
label={props.name}
|
|
764
|
+
/>
|
|
765
|
+
</Field.Root>
|
|
766
|
+
</label>
|
|
767
|
+
</td>
|
|
768
|
+
);
|
|
769
|
+
}
|
|
770
|
+
|
|
771
|
+
// A row's acts cell, at the grid's end and frozen there: its icon act, then
|
|
772
|
+
// its more menu (its own entries, the drops that take what it drags, the
|
|
773
|
+
// moves). One cursor stop like any cell; its icons stand out of the Tab order,
|
|
774
|
+
// and the keys on the active row press them (Shift+Enter, the Context Menu key).
|
|
775
|
+
function ActsCell(props: {
|
|
776
|
+
row: TableRecord;
|
|
777
|
+
name: string;
|
|
778
|
+
place: number;
|
|
779
|
+
here: boolean;
|
|
780
|
+
chosen: boolean;
|
|
781
|
+
opens: boolean;
|
|
782
|
+
hasAct: boolean;
|
|
783
|
+
menu: boolean;
|
|
784
|
+
kind: string | undefined;
|
|
785
|
+
movable: Movable | undefined;
|
|
786
|
+
edge: Edge | undefined;
|
|
787
|
+
actions: GridActions;
|
|
788
|
+
}) {
|
|
789
|
+
const { row, actions } = props;
|
|
790
|
+
const words = useWords();
|
|
791
|
+
const offers = useOffers(props.kind, () => actions.dragged(row.id));
|
|
792
|
+
const moves = props.movable
|
|
793
|
+
? movesOf(words, props.movable, row.id, props.edge)
|
|
794
|
+
: [];
|
|
795
|
+
const items: MenuEntry[] = [...(row.more ?? []), ...offers, ...moves];
|
|
796
|
+
const box = cn(TICK_BOX, FLOOR);
|
|
797
|
+
const cell = cn(
|
|
798
|
+
BODY_CELL,
|
|
799
|
+
TABLE_FROZEN,
|
|
800
|
+
FROZEN,
|
|
801
|
+
FROZEN_END,
|
|
802
|
+
tableFrozenCell({
|
|
803
|
+
state: props.chosen ? "selected" : "rest",
|
|
804
|
+
edge: "start",
|
|
805
|
+
}),
|
|
806
|
+
props.opens && (props.chosen ? FROZEN_CHOSEN_PRESS : FROZEN_PRESS),
|
|
807
|
+
props.chosen ? FROZEN_CHOSEN_ACTIVE : FROZEN_ACTIVE,
|
|
808
|
+
);
|
|
809
|
+
return (
|
|
810
|
+
<td
|
|
811
|
+
data-row={row.id}
|
|
812
|
+
data-column={props.place}
|
|
813
|
+
data-acts=""
|
|
814
|
+
tabIndex={props.here ? 0 : -1}
|
|
815
|
+
className={cell}
|
|
816
|
+
>
|
|
817
|
+
<div className={box}>
|
|
818
|
+
<span className={cn(ACTS_LINE, ROW_ACTS)}>
|
|
819
|
+
{props.hasAct ? (
|
|
820
|
+
<span data-act="" className={ACT_REGION}>
|
|
821
|
+
{row.act ? (
|
|
822
|
+
<IconActFace
|
|
823
|
+
// The record holds the act the row region gave, the platform's.
|
|
824
|
+
act={row.act as IconAct | IconLinkAct}
|
|
825
|
+
tabIndex={-1}
|
|
826
|
+
/>
|
|
827
|
+
) : null}
|
|
828
|
+
</span>
|
|
829
|
+
) : null}
|
|
830
|
+
{props.menu ? (
|
|
831
|
+
<span data-more="" className={ACT_REGION}>
|
|
832
|
+
{items.length ? (
|
|
833
|
+
<MenuBase
|
|
834
|
+
label={`${words.more} ${props.name}`}
|
|
835
|
+
title={props.name}
|
|
836
|
+
items={items}
|
|
837
|
+
tabIndex={-1}
|
|
838
|
+
/>
|
|
839
|
+
) : null}
|
|
840
|
+
</span>
|
|
841
|
+
) : null}
|
|
842
|
+
</span>
|
|
843
|
+
</div>
|
|
844
|
+
</td>
|
|
845
|
+
);
|
|
846
|
+
}
|
|
847
|
+
|
|
848
|
+
// A cell holds the pointer's hover itself, so a pointer crossing the grid
|
|
849
|
+
// re-renders only the cells it leaves and enters: an editable cell under the
|
|
850
|
+
// pointer shows its control.
|
|
851
|
+
const Cell = memo(function Cell(props: {
|
|
852
|
+
row: TableRecord;
|
|
853
|
+
column: TableColumn;
|
|
854
|
+
// The cursor's column, counting the tick column first when there is one.
|
|
855
|
+
place: number;
|
|
856
|
+
leading: boolean;
|
|
857
|
+
cell: TableCell | undefined;
|
|
858
|
+
control: TableColumn["edit"];
|
|
859
|
+
// Its row locks a value its column edits: a lock ends the cell.
|
|
860
|
+
locked: boolean;
|
|
861
|
+
frozen: boolean;
|
|
862
|
+
// A tick column stands before it.
|
|
863
|
+
shifted: boolean;
|
|
864
|
+
// The leading cell's reason under the name.
|
|
865
|
+
reason: string | undefined;
|
|
866
|
+
// The row is current and this cell starts it: the leading cell, when no tick column does.
|
|
867
|
+
current: boolean;
|
|
868
|
+
chosen: boolean;
|
|
869
|
+
opens: boolean;
|
|
870
|
+
here: boolean;
|
|
871
|
+
editing: Editing | undefined;
|
|
872
|
+
actions: GridActions;
|
|
873
|
+
}) {
|
|
874
|
+
const { row, column, place, cell, control, actions } = props;
|
|
875
|
+
const [hovered, setHovered] = useState(false);
|
|
876
|
+
// A started edit's control mounts afresh over the one the pointer showed,
|
|
877
|
+
// so it mounts focused.
|
|
878
|
+
const starts = props.editing === "started";
|
|
879
|
+
const live =
|
|
880
|
+
control !== undefined && (props.editing !== undefined || hovered);
|
|
881
|
+
const field: CellFit = { label: column.label, starts };
|
|
882
|
+
const box = cn(
|
|
883
|
+
TABLE_CELL,
|
|
884
|
+
CELL,
|
|
885
|
+
isEnd(column) && CELL_END,
|
|
886
|
+
props.leading && props.reason !== undefined ? TALL : FLOOR,
|
|
887
|
+
);
|
|
888
|
+
const pinned =
|
|
889
|
+
props.frozen &&
|
|
890
|
+
cn(
|
|
891
|
+
TABLE_FROZEN,
|
|
892
|
+
FROZEN,
|
|
893
|
+
props.shifted ? FROZEN_AFTER_TICK : FROZEN_AT,
|
|
894
|
+
tableFrozenCell({
|
|
895
|
+
state: props.chosen ? "selected" : "rest",
|
|
896
|
+
edge: "end",
|
|
897
|
+
}),
|
|
898
|
+
props.opens && (props.chosen ? FROZEN_CHOSEN_PRESS : FROZEN_PRESS),
|
|
899
|
+
props.chosen ? FROZEN_CHOSEN_ACTIVE : FROZEN_ACTIVE,
|
|
900
|
+
);
|
|
901
|
+
return (
|
|
902
|
+
<td
|
|
903
|
+
data-row={row.id}
|
|
904
|
+
data-column={place}
|
|
905
|
+
data-edit={control}
|
|
906
|
+
tabIndex={props.here ? 0 : -1}
|
|
907
|
+
onPointerEnter={control ? () => setHovered(true) : undefined}
|
|
908
|
+
onPointerLeave={control ? () => setHovered(false) : undefined}
|
|
909
|
+
className={cn(BODY_CELL, props.current && ROW_CURRENT_BAR, pinned)}
|
|
910
|
+
>
|
|
911
|
+
{live ? (
|
|
912
|
+
<CellEdit
|
|
913
|
+
key={starts ? "started" : "shown"}
|
|
914
|
+
column={column}
|
|
915
|
+
cell={cell}
|
|
916
|
+
field={field}
|
|
917
|
+
onEdit={(value) => actions.edit(row, column, value)}
|
|
918
|
+
/>
|
|
919
|
+
) : (
|
|
920
|
+
<div className={box}>
|
|
921
|
+
<CellValueView
|
|
922
|
+
column={column}
|
|
923
|
+
cell={cell}
|
|
924
|
+
leading={props.leading}
|
|
925
|
+
href={row.href}
|
|
926
|
+
warning={row.warning}
|
|
927
|
+
change={row.change}
|
|
928
|
+
reason={props.reason}
|
|
929
|
+
/>
|
|
930
|
+
{props.locked ? <LockMark /> : null}
|
|
931
|
+
</div>
|
|
932
|
+
)}
|
|
933
|
+
</td>
|
|
934
|
+
);
|
|
935
|
+
});
|
|
936
|
+
|
|
937
|
+
// The cursor's column stops that carry no column key: the tick column and the
|
|
938
|
+
// acts column.
|
|
939
|
+
const TICK_STOP = Symbol("tick");
|
|
940
|
+
const ACTS_STOP = Symbol("acts");
|
|
941
|
+
|
|
942
|
+
// The cursor's cell as its record and its column's stop, so a row landing
|
|
943
|
+
// above it, a sort or a column hidden leaves it on its cell; its `place`
|
|
944
|
+
// stands where the record or the stop is gone, and for a window's row not
|
|
945
|
+
// loaded yet, which has no id.
|
|
946
|
+
interface CursorCell {
|
|
947
|
+
id: string | undefined;
|
|
948
|
+
stop: string | symbol | undefined;
|
|
949
|
+
place: Cursor;
|
|
950
|
+
}
|
|
951
|
+
|
|
952
|
+
function Grid(props: {
|
|
953
|
+
columns: readonly TableColumn[];
|
|
954
|
+
// `undefined` where a window's page is not loaded: its row is painted.
|
|
955
|
+
rows: readonly (TableRecord | undefined)[];
|
|
956
|
+
sort: Sort | undefined;
|
|
957
|
+
onSort: (column: TableColumn) => void;
|
|
958
|
+
selected: string | undefined;
|
|
959
|
+
current: string | undefined;
|
|
960
|
+
chooser: Chooser | undefined;
|
|
961
|
+
// Hears the indices of the rows mounted: a window loads their pages.
|
|
962
|
+
onRange: ((indices: readonly number[]) => void) | undefined;
|
|
963
|
+
onOpen: ((id: string) => void) | undefined;
|
|
964
|
+
onEdit: ((id: string, key: string, value: CellValue) => unknown) | undefined;
|
|
965
|
+
painted: boolean;
|
|
966
|
+
// The read waits: a read not asked for yet stands painted and still, not busy.
|
|
967
|
+
busy: boolean;
|
|
968
|
+
more: Read<unknown> | undefined;
|
|
969
|
+
label: string | undefined;
|
|
970
|
+
drag: DragSource | undefined;
|
|
971
|
+
movable: Movable | undefined;
|
|
972
|
+
// The acts column: the rows have an act, a menu.
|
|
973
|
+
hasAct: boolean;
|
|
974
|
+
menu: boolean;
|
|
975
|
+
}) {
|
|
976
|
+
const { columns, rows, sort, painted, chooser } = props;
|
|
977
|
+
useTouchHold(props.drag !== undefined || props.movable !== undefined);
|
|
978
|
+
const words = useWords();
|
|
979
|
+
// The cursor's columns: a tick column leads them, the acts column follows
|
|
980
|
+
// them as the last stop. The leading cell is column `shift`.
|
|
981
|
+
const acting = props.hasAct || props.menu;
|
|
982
|
+
const stops: readonly (string | symbol)[] = [
|
|
983
|
+
...(chooser ? [TICK_STOP] : []),
|
|
984
|
+
...columns.map((column) => column.key),
|
|
985
|
+
...(acting ? [ACTS_STOP] : []),
|
|
986
|
+
];
|
|
987
|
+
const shift = stops[0] === TICK_STOP ? 1 : 0;
|
|
988
|
+
const actsAt = stops.indexOf(ACTS_STOP);
|
|
989
|
+
const acts = (props.hasAct ? 1 : 0) + (props.menu ? 1 : 0);
|
|
990
|
+
const actsWide: VarStyle | undefined = acting
|
|
991
|
+
? { "--acts": acts }
|
|
992
|
+
: undefined;
|
|
993
|
+
const title = use(PageTitle);
|
|
994
|
+
const scroll = use(Scroller);
|
|
995
|
+
const frame = useRef<HTMLDivElement>(null);
|
|
996
|
+
const body = useRef<HTMLTableSectionElement>(null);
|
|
997
|
+
const places = useMemo(() => {
|
|
998
|
+
const map = new Map<string, number>();
|
|
999
|
+
rows.forEach((each, place) => {
|
|
1000
|
+
if (each) map.set(each.id, place);
|
|
1001
|
+
});
|
|
1002
|
+
return map;
|
|
1003
|
+
}, [rows]);
|
|
1004
|
+
const indexOf = (id: string | undefined) => places.get(id ?? "") ?? -1;
|
|
1005
|
+
// No cursor set yet stands at the first cell.
|
|
1006
|
+
const [cursor, setCursor] = useState<CursorCell>();
|
|
1007
|
+
const cursorAt = (row: number, column: number) =>
|
|
1008
|
+
setCursor({
|
|
1009
|
+
id: rows[row]?.id,
|
|
1010
|
+
stop: stops[column],
|
|
1011
|
+
place: { row, column },
|
|
1012
|
+
});
|
|
1013
|
+
// The cursor's cell in its edit: `started` from the keyboard or a tap, its
|
|
1014
|
+
// control mounted afresh (focused), or `entered` when focus
|
|
1015
|
+
// reached a control the pointer already showed.
|
|
1016
|
+
const [editing, setEditing] = useState<"started" | "entered">();
|
|
1017
|
+
const start = (id: string, column: number) => {
|
|
1018
|
+
cursorAt(indexOf(id), column);
|
|
1019
|
+
setEditing("started");
|
|
1020
|
+
};
|
|
1021
|
+
const found = {
|
|
1022
|
+
row: indexOf(cursor?.id),
|
|
1023
|
+
column: cursor?.stop === undefined ? -1 : stops.indexOf(cursor.stop),
|
|
1024
|
+
};
|
|
1025
|
+
const fallback = cursor?.place ?? { row: 0, column: 0 };
|
|
1026
|
+
const at: Cursor = {
|
|
1027
|
+
row:
|
|
1028
|
+
found.row >= 0
|
|
1029
|
+
? found.row
|
|
1030
|
+
: Math.min(fallback.row, Math.max(rows.length - 1, 0)),
|
|
1031
|
+
column:
|
|
1032
|
+
found.column >= 0
|
|
1033
|
+
? found.column
|
|
1034
|
+
: Math.min(fallback.column, Math.max(stops.length - 1, 0)),
|
|
1035
|
+
};
|
|
1036
|
+
const edits = props.onEdit !== undefined;
|
|
1037
|
+
// The characters of each chip column's widest chip among the rows loaded,
|
|
1038
|
+
// so the fixed grid gives the column the room its chips take.
|
|
1039
|
+
const fits = useMemo(
|
|
1040
|
+
() =>
|
|
1041
|
+
columns.map((column) => {
|
|
1042
|
+
if (column.kind !== "chip") return 0;
|
|
1043
|
+
let widest = 0;
|
|
1044
|
+
for (const row of rows) {
|
|
1045
|
+
const chip = chipOf(column, row?.cells[column.key]);
|
|
1046
|
+
if (chip) widest = Math.max(widest, chip.label.length);
|
|
1047
|
+
}
|
|
1048
|
+
return widest;
|
|
1049
|
+
}),
|
|
1050
|
+
[columns, rows],
|
|
1051
|
+
);
|
|
1052
|
+
|
|
1053
|
+
// A cell carries its row's id, not its place: a row landing above it
|
|
1054
|
+
// would render every row below it with a new place.
|
|
1055
|
+
const cellAt = (id: string, column: number) =>
|
|
1056
|
+
frame.current?.querySelector<HTMLElement>(
|
|
1057
|
+
`td[data-row="${CSS.escape(id)}"][data-column="${column}"]`,
|
|
1058
|
+
);
|
|
1059
|
+
// The cursor moves first and its cell takes focus once the row stands: a row
|
|
1060
|
+
// the window had not mounted is kept by the cursor, drawn by this render.
|
|
1061
|
+
const [wanted, setWanted] = useState<Cursor>();
|
|
1062
|
+
const focusCell = (row: number, column: number) => {
|
|
1063
|
+
cursorAt(row, column);
|
|
1064
|
+
setWanted({ row, column });
|
|
1065
|
+
};
|
|
1066
|
+
// The cell scrolls clear of the frozen columns it would stand under, by the
|
|
1067
|
+
// scroller's padding at its start; a frozen cell stands in place, so it
|
|
1068
|
+
// scrolls nothing.
|
|
1069
|
+
// A row of a window not loaded yet takes the focus once its page lands.
|
|
1070
|
+
const wantedId = wanted ? rows[wanted.row]?.id : undefined;
|
|
1071
|
+
useLayoutEffect(() => {
|
|
1072
|
+
if (!wanted) return;
|
|
1073
|
+
const cell = cellAt(rows[wanted.row]?.id ?? "", wanted.column);
|
|
1074
|
+
if (!cell) return;
|
|
1075
|
+
if (wanted.column <= shift) {
|
|
1076
|
+
cell.focus();
|
|
1077
|
+
return;
|
|
1078
|
+
}
|
|
1079
|
+
cell.focus({ preventScroll: true });
|
|
1080
|
+
cell.scrollIntoView({ block: "nearest", inline: "nearest" });
|
|
1081
|
+
}, [wanted, wantedId]);
|
|
1082
|
+
const open = (row: TableRecord) => {
|
|
1083
|
+
if (props.onOpen) props.onOpen(row.id);
|
|
1084
|
+
else if (row.href !== undefined) navigate(row.href);
|
|
1085
|
+
};
|
|
1086
|
+
const edit = (row: TableRecord, column: TableColumn, value: CellValue) =>
|
|
1087
|
+
props.onEdit?.(row.id, column.key, value);
|
|
1088
|
+
// The rows a Shift-arrow run ticks, from where it began to where it stands;
|
|
1089
|
+
// any other move, tick or press ends the run.
|
|
1090
|
+
const run = useRef<{ from: number; to: number }>(undefined);
|
|
1091
|
+
const tick = (row: TableRecord, on: boolean) => {
|
|
1092
|
+
run.current = undefined;
|
|
1093
|
+
chooser?.tick(row.id, on);
|
|
1094
|
+
};
|
|
1095
|
+
// A Shift-arrow takes the ticks along with the cursor: the rows between the
|
|
1096
|
+
// run's start and the cursor are ticked (the loaded ones that can be) and
|
|
1097
|
+
// the rows it leaves behind by turning back are unticked.
|
|
1098
|
+
const extend = (from: number, to: number) => {
|
|
1099
|
+
const was = run.current ?? { from, to: from };
|
|
1100
|
+
const now = { from: was.from, to };
|
|
1101
|
+
const on = rangeIds(rows, now.from, now.to);
|
|
1102
|
+
const off = rangeIds(rows, was.from, was.to).filter(
|
|
1103
|
+
(id) => !on.includes(id),
|
|
1104
|
+
);
|
|
1105
|
+
chooser?.tickSet(on, off);
|
|
1106
|
+
run.current = now;
|
|
1107
|
+
};
|
|
1108
|
+
// PageUp and PageDown move by the rows in view less one. The view's height
|
|
1109
|
+
// over a row's is read here because CSS cannot say how many rows a scroller
|
|
1110
|
+
// holds.
|
|
1111
|
+
const pageOf = (cell: HTMLElement) =>
|
|
1112
|
+
pageRows(
|
|
1113
|
+
scroll?.holder.current?.clientHeight ?? window.innerHeight,
|
|
1114
|
+
cell.closest("tr")?.getBoundingClientRect().height ?? 0,
|
|
1115
|
+
);
|
|
1116
|
+
|
|
1117
|
+
const onFocus = (event: FocusEvent) => {
|
|
1118
|
+
const { target } = event;
|
|
1119
|
+
if (!(target instanceof HTMLElement)) return;
|
|
1120
|
+
const cell = target.closest<HTMLElement>("td[data-row]");
|
|
1121
|
+
if (!cell || !frame.current?.contains(cell)) return;
|
|
1122
|
+
const row = indexOf(cell.dataset.row);
|
|
1123
|
+
if (row < 0) return;
|
|
1124
|
+
const column = Number(cell.dataset.column);
|
|
1125
|
+
const same = row === at.row && column === at.column;
|
|
1126
|
+
// A focus on the cursor's own cell sets nothing.
|
|
1127
|
+
if (!same) cursorAt(row, column);
|
|
1128
|
+
// The started edit's control taking focus keeps it started.
|
|
1129
|
+
setEditing((now) =>
|
|
1130
|
+
inEdit(target) ? (same && now) || "entered" : undefined,
|
|
1131
|
+
);
|
|
1132
|
+
};
|
|
1133
|
+
// Leaving a typed edit for anywhere outside its cell ends it.
|
|
1134
|
+
const onBlur = (event: FocusEvent) => {
|
|
1135
|
+
const { target, relatedTarget } = event;
|
|
1136
|
+
if (!(target instanceof HTMLInputElement)) return;
|
|
1137
|
+
const cell = target.closest("td[data-row]");
|
|
1138
|
+
if (!cell) return;
|
|
1139
|
+
if (!(relatedTarget instanceof Node && cell.contains(relatedTarget)))
|
|
1140
|
+
setEditing(undefined);
|
|
1141
|
+
};
|
|
1142
|
+
const onKeyDown = (event: KeyboardEvent) => {
|
|
1143
|
+
const { target } = event;
|
|
1144
|
+
if (!(target instanceof HTMLElement)) return;
|
|
1145
|
+
const cell = target.closest<HTMLElement>("td[data-row]");
|
|
1146
|
+
if (!cell) return;
|
|
1147
|
+
const row = indexOf(cell.dataset.row);
|
|
1148
|
+
const column = Number(cell.dataset.column);
|
|
1149
|
+
const record = rows[row];
|
|
1150
|
+
// The tick column has no field, nor has the acts column.
|
|
1151
|
+
const place = column - shift;
|
|
1152
|
+
const field = columns[place];
|
|
1153
|
+
const onActs = column === actsAt;
|
|
1154
|
+
if (!record || (!field && column >= shift && !onActs)) return;
|
|
1155
|
+
if (inEdit(target)) {
|
|
1156
|
+
// An open edit: Enter has committed and Escape put the value back and
|
|
1157
|
+
// ended the moment, so the field leaving for its cell commits nothing
|
|
1158
|
+
// more.
|
|
1159
|
+
if (
|
|
1160
|
+
(event.key === "Enter" || event.key === "Escape") &&
|
|
1161
|
+
target instanceof HTMLInputElement
|
|
1162
|
+
) {
|
|
1163
|
+
event.preventDefault();
|
|
1164
|
+
setEditing(undefined);
|
|
1165
|
+
cell.focus();
|
|
1166
|
+
}
|
|
1167
|
+
return;
|
|
1168
|
+
}
|
|
1169
|
+
// Alt with Up, Down, Home or End moves the row where the pointer would.
|
|
1170
|
+
const step = props.movable ? stepKey(event) : undefined;
|
|
1171
|
+
if (step && props.movable) {
|
|
1172
|
+
event.preventDefault();
|
|
1173
|
+
const moved = stepOf(props.movable.ids(), record.id, step);
|
|
1174
|
+
if (moved) {
|
|
1175
|
+
props.movable.move(record.id, moved);
|
|
1176
|
+
// The cursor holds the record, so it follows it to its new place.
|
|
1177
|
+
setWanted({ row: moved.index, column });
|
|
1178
|
+
}
|
|
1179
|
+
return;
|
|
1180
|
+
}
|
|
1181
|
+
// The Context Menu key (or Shift+F10) opens the row's menu.
|
|
1182
|
+
if (
|
|
1183
|
+
event.key === "ContextMenu" ||
|
|
1184
|
+
(event.shiftKey && event.key === "F10")
|
|
1185
|
+
) {
|
|
1186
|
+
event.preventDefault();
|
|
1187
|
+
pressIn(cell, "[data-more] button");
|
|
1188
|
+
return;
|
|
1189
|
+
}
|
|
1190
|
+
const to = moveCursor(event.key, { row, column }, event.ctrlKey, {
|
|
1191
|
+
rows: rows.length,
|
|
1192
|
+
columns: stops.length,
|
|
1193
|
+
page: pageOf(cell),
|
|
1194
|
+
});
|
|
1195
|
+
// The leading link answers Enter and Space itself; the
|
|
1196
|
+
// arrows move the cursor from them as from their cell.
|
|
1197
|
+
if (target !== cell && !to) return;
|
|
1198
|
+
if (to) {
|
|
1199
|
+
event.preventDefault();
|
|
1200
|
+
if (chooser && event.shiftKey && alongRows(event.key)) {
|
|
1201
|
+
extend(row, to.row);
|
|
1202
|
+
} else {
|
|
1203
|
+
run.current = undefined;
|
|
1204
|
+
}
|
|
1205
|
+
focusCell(to.row, to.column);
|
|
1206
|
+
return;
|
|
1207
|
+
}
|
|
1208
|
+
if (event.ctrlKey || event.metaKey || event.altKey) return;
|
|
1209
|
+
const enter = event.key === "Enter";
|
|
1210
|
+
const space = event.key === " ";
|
|
1211
|
+
const x = event.key.toLowerCase() === "x";
|
|
1212
|
+
// The acts cell presses its act, else its menu.
|
|
1213
|
+
if (onActs) {
|
|
1214
|
+
if (!enter && !space) return;
|
|
1215
|
+
event.preventDefault();
|
|
1216
|
+
pressIn(
|
|
1217
|
+
cell,
|
|
1218
|
+
record.act ? "[data-act] :is(button, a)" : "[data-more] button",
|
|
1219
|
+
);
|
|
1220
|
+
return;
|
|
1221
|
+
}
|
|
1222
|
+
// Shift+Enter runs the row's act from any cell; Enter does where the
|
|
1223
|
+
// row opens nothing (and the cell is not the tick's, which Enter ticks).
|
|
1224
|
+
if (
|
|
1225
|
+
enter &&
|
|
1226
|
+
record.act &&
|
|
1227
|
+
(event.shiftKey ||
|
|
1228
|
+
(field && props.onOpen === undefined && record.href === undefined))
|
|
1229
|
+
) {
|
|
1230
|
+
event.preventDefault();
|
|
1231
|
+
pressIn(cell, "[data-act] :is(button, a)");
|
|
1232
|
+
return;
|
|
1233
|
+
}
|
|
1234
|
+
const toggle = () => {
|
|
1235
|
+
if (record.blocked === undefined) {
|
|
1236
|
+
tick(record, !chooser?.ticked(record.id));
|
|
1237
|
+
}
|
|
1238
|
+
};
|
|
1239
|
+
// The tick column's cell ticks on Enter, Space and `x`.
|
|
1240
|
+
if (!field) {
|
|
1241
|
+
if (!enter && !space && !x) return;
|
|
1242
|
+
event.preventDefault();
|
|
1243
|
+
toggle();
|
|
1244
|
+
return;
|
|
1245
|
+
}
|
|
1246
|
+
const edit = editOf(columns, place, edits, record);
|
|
1247
|
+
if (edit && (enter || space)) {
|
|
1248
|
+
event.preventDefault();
|
|
1249
|
+
start(record.id, column);
|
|
1250
|
+
return;
|
|
1251
|
+
}
|
|
1252
|
+
// Space and `x` tick the row of a table that chooses. Without `choose`
|
|
1253
|
+
// Space is not claimed.
|
|
1254
|
+
if (chooser && (x || space)) {
|
|
1255
|
+
event.preventDefault();
|
|
1256
|
+
toggle();
|
|
1257
|
+
return;
|
|
1258
|
+
}
|
|
1259
|
+
if (!enter) return;
|
|
1260
|
+
event.preventDefault();
|
|
1261
|
+
const link = place === 0 ? cell.querySelector("a") : null;
|
|
1262
|
+
if (link) link.click();
|
|
1263
|
+
else open(record);
|
|
1264
|
+
};
|
|
1265
|
+
// Presses the control a row's acts cell holds: what a key on the row does is
|
|
1266
|
+
// what a press on it does, wiring and all.
|
|
1267
|
+
const pressIn = (cell: HTMLElement, control: string) =>
|
|
1268
|
+
cell.closest("tr")?.querySelector<HTMLElement>(control)?.click();
|
|
1269
|
+
// What a drag of a row carries: the pick when it is ticked, else itself.
|
|
1270
|
+
const dragged = (id: string): Dragged => ({
|
|
1271
|
+
kind: props.drag?.kind ?? "",
|
|
1272
|
+
picked: chooser?.ticked(id) ? chooser.pick : { ids: [id] },
|
|
1273
|
+
});
|
|
1274
|
+
// A press that moves a row drags it, to a drop or within the grid.
|
|
1275
|
+
const onPointerDown = (event: PointerEvent) => {
|
|
1276
|
+
if (!props.drag && !props.movable) return;
|
|
1277
|
+
const { target } = event;
|
|
1278
|
+
if (!(target instanceof Element)) return;
|
|
1279
|
+
const cell = target.closest<HTMLElement>("td[data-row]");
|
|
1280
|
+
if (!cell || !frame.current?.contains(cell)) return;
|
|
1281
|
+
if (cell.hasAttribute("data-choose") || cell.hasAttribute("data-acts"))
|
|
1282
|
+
return;
|
|
1283
|
+
const id = cell.dataset.row ?? "";
|
|
1284
|
+
press(event, () => {
|
|
1285
|
+
const record = rows.find((one) => one?.id === id);
|
|
1286
|
+
if (!record) return undefined;
|
|
1287
|
+
const ticked =
|
|
1288
|
+
chooser?.ticked(id) === true && record.blocked === undefined;
|
|
1289
|
+
const lead = columns[0];
|
|
1290
|
+
const name = lead ? shown(lead, record.cells[lead.key]) : id;
|
|
1291
|
+
const count = ticked ? (chooser?.count ?? 1) : 1;
|
|
1292
|
+
return {
|
|
1293
|
+
drag: props.drag && dragged(id),
|
|
1294
|
+
label: draggedLabel(words, name, count),
|
|
1295
|
+
reorder:
|
|
1296
|
+
props.movable && count <= 1 ? { id, ...props.movable } : undefined,
|
|
1297
|
+
};
|
|
1298
|
+
});
|
|
1299
|
+
};
|
|
1300
|
+
// A press on a row opens it, unless it lands on an editable cell (which it
|
|
1301
|
+
// starts editing, its box and a cell already editing answering the press
|
|
1302
|
+
// themselves), the tick cell or the leading cell's link.
|
|
1303
|
+
const onClick = (event: MouseEvent, row: TableRecord) => {
|
|
1304
|
+
run.current = undefined;
|
|
1305
|
+
const { target } = event;
|
|
1306
|
+
if (!(target instanceof HTMLElement)) return;
|
|
1307
|
+
// A press in the row's more menu, a portal, reaches the row through
|
|
1308
|
+
// React's tree alone.
|
|
1309
|
+
if (!event.currentTarget.contains(target)) return;
|
|
1310
|
+
const editable = target.closest<HTMLElement>("td[data-edit]");
|
|
1311
|
+
if (editable) {
|
|
1312
|
+
const column = Number(editable.dataset.column);
|
|
1313
|
+
const live =
|
|
1314
|
+
editing !== undefined &&
|
|
1315
|
+
at.row === indexOf(row.id) &&
|
|
1316
|
+
at.column === column;
|
|
1317
|
+
if (!live) start(row.id, column);
|
|
1318
|
+
return;
|
|
1319
|
+
}
|
|
1320
|
+
if (target.closest("td[data-choose], td[data-acts], a")) return;
|
|
1321
|
+
if (props.onOpen || row.href !== undefined) open(row);
|
|
1322
|
+
};
|
|
1323
|
+
|
|
1324
|
+
const opens = props.onOpen !== undefined;
|
|
1325
|
+
const latest = useRef({ start, edit, click: onClick, tick, dragged });
|
|
1326
|
+
latest.current = { start, edit, click: onClick, tick, dragged };
|
|
1327
|
+
const [actions] = useState<GridActions>(() => ({
|
|
1328
|
+
dragged: (id) => latest.current.dragged(id),
|
|
1329
|
+
start: (row, column) => latest.current.start(row, column),
|
|
1330
|
+
edit: (row, column, value) => latest.current.edit(row, column, value),
|
|
1331
|
+
click: (event, row) => latest.current.click(event, row),
|
|
1332
|
+
tick: (row, on) => latest.current.tick(row, on),
|
|
1333
|
+
}));
|
|
1334
|
+
// The head tick reaches the rows that can be ticked; with none it is off.
|
|
1335
|
+
const reach = tickable(rows.filter((one) => one !== undefined)).length > 0;
|
|
1336
|
+
|
|
1337
|
+
// A row's key: its id, else its place (a painted row, or a window's row not
|
|
1338
|
+
// loaded; `~` keeps it from an id).
|
|
1339
|
+
const keyAt = (index: number) =>
|
|
1340
|
+
painted ? index : (rows[index]?.id ?? `~${index}`);
|
|
1341
|
+
// Built by index, so a long grid builds only the rows its Window mounts.
|
|
1342
|
+
const rowAt = (index: number) => {
|
|
1343
|
+
const row = rows[index];
|
|
1344
|
+
return painted || !row ? (
|
|
1345
|
+
<PaintedRow
|
|
1346
|
+
key={keyAt(index)}
|
|
1347
|
+
index={index}
|
|
1348
|
+
columns={columns}
|
|
1349
|
+
choosing={chooser !== undefined}
|
|
1350
|
+
acts={acting}
|
|
1351
|
+
/>
|
|
1352
|
+
) : (
|
|
1353
|
+
<Row
|
|
1354
|
+
key={row.id}
|
|
1355
|
+
row={row}
|
|
1356
|
+
index={index}
|
|
1357
|
+
columns={columns}
|
|
1358
|
+
chosen={row.id === props.selected}
|
|
1359
|
+
current={row.id === props.current}
|
|
1360
|
+
choosing={chooser !== undefined}
|
|
1361
|
+
ticked={chooser?.ticked(row.id) ?? false}
|
|
1362
|
+
opens={opens || row.href !== undefined}
|
|
1363
|
+
edits={edits}
|
|
1364
|
+
cursor={index === at.row ? at.column : -1}
|
|
1365
|
+
editing={index === at.row ? editing : undefined}
|
|
1366
|
+
hasAct={props.hasAct}
|
|
1367
|
+
menu={props.menu}
|
|
1368
|
+
kind={props.drag?.kind}
|
|
1369
|
+
movable={props.movable}
|
|
1370
|
+
edge={props.movable ? edgeOf(index, rows.length) : undefined}
|
|
1371
|
+
actions={actions}
|
|
1372
|
+
/>
|
|
1373
|
+
);
|
|
1374
|
+
};
|
|
1375
|
+
|
|
1376
|
+
return (
|
|
1377
|
+
<div className={FORM}>
|
|
1378
|
+
<div
|
|
1379
|
+
ref={frame}
|
|
1380
|
+
className={cn(
|
|
1381
|
+
CARD,
|
|
1382
|
+
BOX,
|
|
1383
|
+
chooser ? SCROLLS_TICKED : SCROLLS,
|
|
1384
|
+
acting && SCROLLS_END,
|
|
1385
|
+
)}
|
|
1386
|
+
style={actsWide}
|
|
1387
|
+
>
|
|
1388
|
+
<table
|
|
1389
|
+
// biome-ignore lint/a11y/noNoninteractiveElementToInteractiveRole: a table whose keyboard is a cell cursor is the WAI-ARIA grid
|
|
1390
|
+
role="grid"
|
|
1391
|
+
aria-label={props.label}
|
|
1392
|
+
aria-labelledby={props.label ? undefined : title}
|
|
1393
|
+
aria-busy={props.busy || undefined}
|
|
1394
|
+
aria-rowcount={rows.length + 1}
|
|
1395
|
+
onFocus={onFocus}
|
|
1396
|
+
onBlur={onBlur}
|
|
1397
|
+
onKeyDown={onKeyDown}
|
|
1398
|
+
onPointerDown={onPointerDown}
|
|
1399
|
+
// The leading link is not dragged by the browser: the press drags the row.
|
|
1400
|
+
onDragStart={
|
|
1401
|
+
props.drag || props.movable
|
|
1402
|
+
? (event) => event.preventDefault()
|
|
1403
|
+
: undefined
|
|
1404
|
+
}
|
|
1405
|
+
style={{
|
|
1406
|
+
minWidth: gridFloor(
|
|
1407
|
+
columns,
|
|
1408
|
+
chooser !== undefined,
|
|
1409
|
+
acts,
|
|
1410
|
+
ageWidest(),
|
|
1411
|
+
fits,
|
|
1412
|
+
),
|
|
1413
|
+
}}
|
|
1414
|
+
className={cn(TABLE, GRID)}
|
|
1415
|
+
>
|
|
1416
|
+
<Cols
|
|
1417
|
+
columns={columns}
|
|
1418
|
+
choosing={chooser !== undefined}
|
|
1419
|
+
acts={acts}
|
|
1420
|
+
fits={fits}
|
|
1421
|
+
/>
|
|
1422
|
+
<thead>
|
|
1423
|
+
<tr aria-rowindex={1} className={tableRow({ state: "rest" })}>
|
|
1424
|
+
{chooser ? (
|
|
1425
|
+
<th
|
|
1426
|
+
scope="col"
|
|
1427
|
+
className={cn(HEAD_CELL, cn(TABLE_FROZEN, FROZEN, FROZEN_AT))}
|
|
1428
|
+
>
|
|
1429
|
+
<div
|
|
1430
|
+
className={cn(
|
|
1431
|
+
TICK_BOX,
|
|
1432
|
+
HEAD_FLOOR,
|
|
1433
|
+
tableFrozenCell({ state: "rest" }),
|
|
1434
|
+
)}
|
|
1435
|
+
>
|
|
1436
|
+
<Field.Root disabled={!reach}>
|
|
1437
|
+
<HeldCheckbox
|
|
1438
|
+
checked={chooser.head}
|
|
1439
|
+
onChange={() => chooser.toggleAll()}
|
|
1440
|
+
label={words.chooseAll}
|
|
1441
|
+
/>
|
|
1442
|
+
</Field.Root>
|
|
1443
|
+
</div>
|
|
1444
|
+
</th>
|
|
1445
|
+
) : null}
|
|
1446
|
+
{columns.map((column, place) => (
|
|
1447
|
+
<HeadCell
|
|
1448
|
+
key={column.key}
|
|
1449
|
+
column={column}
|
|
1450
|
+
sort={sort}
|
|
1451
|
+
frozen={place === 0}
|
|
1452
|
+
shifted={chooser !== undefined}
|
|
1453
|
+
onSort={() => props.onSort(column)}
|
|
1454
|
+
/>
|
|
1455
|
+
))}
|
|
1456
|
+
{acting ? (
|
|
1457
|
+
<th
|
|
1458
|
+
scope="col"
|
|
1459
|
+
className={cn(
|
|
1460
|
+
HEAD_CELL,
|
|
1461
|
+
cn(TABLE_FROZEN, FROZEN, FROZEN_END),
|
|
1462
|
+
)}
|
|
1463
|
+
>
|
|
1464
|
+
{/* The header names the column in text (axe: a th needs
|
|
1465
|
+
text), visually hidden: the acts' icons say the rest. */}
|
|
1466
|
+
<div
|
|
1467
|
+
className={cn(
|
|
1468
|
+
HEAD_FLOOR,
|
|
1469
|
+
tableFrozenCell({ state: "rest", edge: "start" }),
|
|
1470
|
+
)}
|
|
1471
|
+
>
|
|
1472
|
+
<span className="sr-only">{words.actions}</span>
|
|
1473
|
+
</div>
|
|
1474
|
+
</th>
|
|
1475
|
+
) : null}
|
|
1476
|
+
</tr>
|
|
1477
|
+
</thead>
|
|
1478
|
+
<tbody ref={body} className={BODY_ROWS}>
|
|
1479
|
+
<Window
|
|
1480
|
+
box={body}
|
|
1481
|
+
keep={at.row}
|
|
1482
|
+
spacer="tr"
|
|
1483
|
+
count={rows.length}
|
|
1484
|
+
keyOf={keyAt}
|
|
1485
|
+
row={rowAt}
|
|
1486
|
+
onRange={props.onRange}
|
|
1487
|
+
/>
|
|
1488
|
+
</tbody>
|
|
1489
|
+
</table>
|
|
1490
|
+
</div>
|
|
1491
|
+
{props.more ? (
|
|
1492
|
+
<MoreRow
|
|
1493
|
+
read={props.more}
|
|
1494
|
+
empty={rows.length === 0}
|
|
1495
|
+
paint={() => (
|
|
1496
|
+
<MorePage
|
|
1497
|
+
columns={columns}
|
|
1498
|
+
choosing={chooser !== undefined}
|
|
1499
|
+
acts={acts}
|
|
1500
|
+
fits={fits}
|
|
1501
|
+
/>
|
|
1502
|
+
)}
|
|
1503
|
+
/>
|
|
1504
|
+
) : null}
|
|
1505
|
+
</div>
|
|
1506
|
+
);
|
|
1507
|
+
}
|
|
1508
|
+
|
|
1509
|
+
// The grid's columns, at the widths its cells keep; the acts column a target
|
|
1510
|
+
// for each icon it holds.
|
|
1511
|
+
function Cols(props: {
|
|
1512
|
+
columns: readonly TableColumn[];
|
|
1513
|
+
choosing: boolean;
|
|
1514
|
+
acts: number;
|
|
1515
|
+
// The characters of each chip column's widest chip, by column.
|
|
1516
|
+
fits: readonly number[];
|
|
1517
|
+
}) {
|
|
1518
|
+
return (
|
|
1519
|
+
<colgroup>
|
|
1520
|
+
{props.choosing ? <col className={TICK_WIDTH} /> : null}
|
|
1521
|
+
{props.columns.map((column, at) => {
|
|
1522
|
+
// A column whose header has a word the short measure cannot hold, or a
|
|
1523
|
+
// figure column with no width, stands at its own floor
|
|
1524
|
+
// (`columnAsked`), the others at their width.
|
|
1525
|
+
const asked = columnAsked(column, ageWidest(), props.fits[at]);
|
|
1526
|
+
const width = columnWidth(column);
|
|
1527
|
+
return (
|
|
1528
|
+
<col
|
|
1529
|
+
key={column.key}
|
|
1530
|
+
className={width && !asked ? WIDTH[width] : undefined}
|
|
1531
|
+
style={asked ? { width: asked } : undefined}
|
|
1532
|
+
/>
|
|
1533
|
+
);
|
|
1534
|
+
})}
|
|
1535
|
+
{props.acts > 0 ? (
|
|
1536
|
+
<col style={{ width: `calc(var(--spacing-target) * ${props.acts})` }} />
|
|
1537
|
+
) : null}
|
|
1538
|
+
</colgroup>
|
|
1539
|
+
);
|
|
1540
|
+
}
|
|
1541
|
+
|
|
1542
|
+
// The next page while it loads: `PAINT_ROWS` painted rows at the grid's
|
|
1543
|
+
// columns, in a grid of their own under the loaded one.
|
|
1544
|
+
function MorePage(props: {
|
|
1545
|
+
columns: readonly TableColumn[];
|
|
1546
|
+
choosing: boolean;
|
|
1547
|
+
acts: number;
|
|
1548
|
+
fits: readonly number[];
|
|
1549
|
+
}) {
|
|
1550
|
+
return (
|
|
1551
|
+
<div
|
|
1552
|
+
aria-hidden
|
|
1553
|
+
className={cn(CARD, BOX, props.choosing ? SCROLLS_TICKED : SCROLLS)}
|
|
1554
|
+
>
|
|
1555
|
+
<table
|
|
1556
|
+
style={{
|
|
1557
|
+
minWidth: gridFloor(
|
|
1558
|
+
props.columns,
|
|
1559
|
+
props.choosing,
|
|
1560
|
+
props.acts,
|
|
1561
|
+
ageWidest(),
|
|
1562
|
+
props.fits,
|
|
1563
|
+
),
|
|
1564
|
+
}}
|
|
1565
|
+
className={cn(TABLE, GRID)}
|
|
1566
|
+
>
|
|
1567
|
+
<Cols
|
|
1568
|
+
columns={props.columns}
|
|
1569
|
+
choosing={props.choosing}
|
|
1570
|
+
acts={props.acts}
|
|
1571
|
+
fits={props.fits}
|
|
1572
|
+
/>
|
|
1573
|
+
<tbody className={BODY_ROWS}>
|
|
1574
|
+
{Array.from({ length: PAINT_ROWS }, (_, index) => (
|
|
1575
|
+
<PaintedRow
|
|
1576
|
+
key={index}
|
|
1577
|
+
index={index}
|
|
1578
|
+
columns={props.columns}
|
|
1579
|
+
choosing={props.choosing}
|
|
1580
|
+
acts={props.acts > 0}
|
|
1581
|
+
/>
|
|
1582
|
+
))}
|
|
1583
|
+
</tbody>
|
|
1584
|
+
</table>
|
|
1585
|
+
</div>
|
|
1586
|
+
);
|
|
1587
|
+
}
|
|
1588
|
+
|
|
1589
|
+
function HeadCell(props: {
|
|
1590
|
+
column: TableColumn;
|
|
1591
|
+
sort: Sort | undefined;
|
|
1592
|
+
frozen: boolean;
|
|
1593
|
+
// A tick column stands before it.
|
|
1594
|
+
shifted: boolean;
|
|
1595
|
+
onSort: () => void;
|
|
1596
|
+
}) {
|
|
1597
|
+
const { column, sort, frozen } = props;
|
|
1598
|
+
const end = isEnd(column);
|
|
1599
|
+
const direction = sort?.key === column.key ? sort.direction : undefined;
|
|
1600
|
+
const label = (
|
|
1601
|
+
<span
|
|
1602
|
+
className={cn(
|
|
1603
|
+
tableHeadLabel({ sort: direction ? "sorted" : "none" }),
|
|
1604
|
+
LABEL,
|
|
1605
|
+
)}
|
|
1606
|
+
>
|
|
1607
|
+
{column.label}
|
|
1608
|
+
</span>
|
|
1609
|
+
);
|
|
1610
|
+
const glyph = direction ? (
|
|
1611
|
+
<span className={GLYPH_SORTED}>
|
|
1612
|
+
<Turn
|
|
1613
|
+
name="ArrowDown"
|
|
1614
|
+
fit="meta"
|
|
1615
|
+
turned={direction === "ascending"}
|
|
1616
|
+
by="half"
|
|
1617
|
+
/>
|
|
1618
|
+
</span>
|
|
1619
|
+
) : (
|
|
1620
|
+
<span className={GLYPH_HINT}>
|
|
1621
|
+
<Icon name="ArrowUpDown" fit="meta" />
|
|
1622
|
+
</span>
|
|
1623
|
+
);
|
|
1624
|
+
const lock = column.locked ? <LockMark /> : null;
|
|
1625
|
+
const content = (
|
|
1626
|
+
<>
|
|
1627
|
+
{end ? glyph : null}
|
|
1628
|
+
{label}
|
|
1629
|
+
{lock}
|
|
1630
|
+
{end ? null : glyph}
|
|
1631
|
+
</>
|
|
1632
|
+
);
|
|
1633
|
+
const edge = frozen && tableFrozenCell({ state: "rest", edge: "end" });
|
|
1634
|
+
return (
|
|
1635
|
+
<th
|
|
1636
|
+
scope="col"
|
|
1637
|
+
aria-sort={column.sortable ? (direction ?? "none") : undefined}
|
|
1638
|
+
className={cn(
|
|
1639
|
+
HEAD_CELL,
|
|
1640
|
+
end ? END : START,
|
|
1641
|
+
frozen &&
|
|
1642
|
+
cn(
|
|
1643
|
+
TABLE_FROZEN,
|
|
1644
|
+
FROZEN,
|
|
1645
|
+
props.shifted ? FROZEN_AFTER_TICK : FROZEN_AT,
|
|
1646
|
+
),
|
|
1647
|
+
)}
|
|
1648
|
+
>
|
|
1649
|
+
{column.sortable ? (
|
|
1650
|
+
<button
|
|
1651
|
+
type="button"
|
|
1652
|
+
onClick={props.onSort}
|
|
1653
|
+
className={cn(
|
|
1654
|
+
tableHead({ state: "rest" }),
|
|
1655
|
+
HEAD_FLOOR,
|
|
1656
|
+
edge,
|
|
1657
|
+
SORT,
|
|
1658
|
+
end && CELL_END,
|
|
1659
|
+
)}
|
|
1660
|
+
>
|
|
1661
|
+
{content}
|
|
1662
|
+
</button>
|
|
1663
|
+
) : (
|
|
1664
|
+
<div
|
|
1665
|
+
className={cn(TABLE_CELL, HEAD_FLOOR, edge, HEAD, end && CELL_END)}
|
|
1666
|
+
>
|
|
1667
|
+
{label}
|
|
1668
|
+
{lock}
|
|
1669
|
+
</div>
|
|
1670
|
+
)}
|
|
1671
|
+
</th>
|
|
1672
|
+
);
|
|
1673
|
+
}
|
|
1674
|
+
|
|
1675
|
+
// An age cell's words, read off the shared clock: the cell draws again only
|
|
1676
|
+
// when they change.
|
|
1677
|
+
function Age(props: { moment: string }) {
|
|
1678
|
+
return useClock((now) => age(props.moment, now));
|
|
1679
|
+
}
|
|
1680
|
+
|
|
1681
|
+
// A cell at rest: the leading cell the record's name (its link when it has
|
|
1682
|
+
// one) with its change mark ahead of it and its warning after it, and its
|
|
1683
|
+
// tick's reason under that line, the others by their column's kind.
|
|
1684
|
+
function CellValueView(props: {
|
|
1685
|
+
column: TableColumn;
|
|
1686
|
+
cell: TableCell | undefined;
|
|
1687
|
+
leading: boolean;
|
|
1688
|
+
href: string | undefined;
|
|
1689
|
+
warning: string | undefined;
|
|
1690
|
+
change: ChangeKind | undefined;
|
|
1691
|
+
reason: string | undefined;
|
|
1692
|
+
}) {
|
|
1693
|
+
const { column, cell, leading } = props;
|
|
1694
|
+
if (cell === null || cell === undefined) return null;
|
|
1695
|
+
if (leading) {
|
|
1696
|
+
const strong = cn(
|
|
1697
|
+
text({ role: "body" }),
|
|
1698
|
+
textStrong({ role: "body" }),
|
|
1699
|
+
VALUE,
|
|
1700
|
+
);
|
|
1701
|
+
const name =
|
|
1702
|
+
props.href !== undefined ? (
|
|
1703
|
+
<a href={props.href} onClick={follow} tabIndex={-1} className={strong}>
|
|
1704
|
+
{shown(column, cell)}
|
|
1705
|
+
</a>
|
|
1706
|
+
) : (
|
|
1707
|
+
<span className={strong}>{shown(column, cell)}</span>
|
|
1708
|
+
);
|
|
1709
|
+
const line =
|
|
1710
|
+
props.warning === undefined ? (
|
|
1711
|
+
name
|
|
1712
|
+
) : (
|
|
1713
|
+
<span className={cn(TABLE_NAME, CHANGE)}>
|
|
1714
|
+
{name}
|
|
1715
|
+
<WarningMark label={props.warning} />
|
|
1716
|
+
</span>
|
|
1717
|
+
);
|
|
1718
|
+
const stack =
|
|
1719
|
+
props.reason === undefined ? (
|
|
1720
|
+
line
|
|
1721
|
+
) : (
|
|
1722
|
+
<span className={REASON_STACK}>
|
|
1723
|
+
{line}
|
|
1724
|
+
<span className={cn(text({ role: "meta" }), VALUE)}>
|
|
1725
|
+
{props.reason}
|
|
1726
|
+
</span>
|
|
1727
|
+
</span>
|
|
1728
|
+
);
|
|
1729
|
+
// The change mark stands on the name's line and the reason under the
|
|
1730
|
+
// name, both starting where the name does.
|
|
1731
|
+
if (props.change === undefined) return stack;
|
|
1732
|
+
return (
|
|
1733
|
+
<span className={cn(TABLE_NAME, CHANGE_LEAD)}>
|
|
1734
|
+
<span className={MARK_LINE}>
|
|
1735
|
+
<ChangeMark kind={props.change} />
|
|
1736
|
+
</span>
|
|
1737
|
+
{stack}
|
|
1738
|
+
</span>
|
|
1739
|
+
);
|
|
1740
|
+
}
|
|
1741
|
+
switch (column.kind) {
|
|
1742
|
+
case "status": {
|
|
1743
|
+
// A `status` column gives a `StatusMark`, the kind's contract, which
|
|
1744
|
+
// its `cell` type (any `TableCell`) does not carry.
|
|
1745
|
+
const status = cell as StatusMark;
|
|
1746
|
+
return <StatusBase tone={status.tone} label={status.label} />;
|
|
1747
|
+
}
|
|
1748
|
+
case "change": {
|
|
1749
|
+
if (!isChangeCell(cell)) return null;
|
|
1750
|
+
const kind = changeKind(cell);
|
|
1751
|
+
if (kind === undefined) return null;
|
|
1752
|
+
return (
|
|
1753
|
+
<span className={cn(CHANGE, TABLE_CHANGE)}>
|
|
1754
|
+
{cell.before !== null && (
|
|
1755
|
+
<span
|
|
1756
|
+
className={cn(
|
|
1757
|
+
tableChangeValue({
|
|
1758
|
+
kind: kind === "removed" ? "removed" : "before",
|
|
1759
|
+
}),
|
|
1760
|
+
column.wrap ? CHANGE_WRAP : VALUE,
|
|
1761
|
+
)}
|
|
1762
|
+
>
|
|
1763
|
+
{cell.before}
|
|
1764
|
+
</span>
|
|
1765
|
+
)}
|
|
1766
|
+
{kind === "changed" && <Icon name="ArrowRight" fit="meta" />}
|
|
1767
|
+
{cell.after !== null && (
|
|
1768
|
+
<span
|
|
1769
|
+
className={cn(
|
|
1770
|
+
tableChangeValue({
|
|
1771
|
+
kind: kind === "added" ? "added" : "after",
|
|
1772
|
+
}),
|
|
1773
|
+
column.wrap ? CHANGE_WRAP : VALUE,
|
|
1774
|
+
)}
|
|
1775
|
+
>
|
|
1776
|
+
{cell.after}
|
|
1777
|
+
</span>
|
|
1778
|
+
)}
|
|
1779
|
+
</span>
|
|
1780
|
+
);
|
|
1781
|
+
}
|
|
1782
|
+
case "chip": {
|
|
1783
|
+
const chip = chipOf(column, cell);
|
|
1784
|
+
return chip ? <ChipBase family={chip.family} label={chip.label} /> : null;
|
|
1785
|
+
}
|
|
1786
|
+
case "source":
|
|
1787
|
+
return (
|
|
1788
|
+
<span
|
|
1789
|
+
className={cn(text({ role: "code" }), column.wrap ? WRAP : VALUE)}
|
|
1790
|
+
>
|
|
1791
|
+
{shown(column, cell)}
|
|
1792
|
+
</span>
|
|
1793
|
+
);
|
|
1794
|
+
case "number":
|
|
1795
|
+
return (
|
|
1796
|
+
<span className={cn(text({ role: "body" }), VALUE)}>
|
|
1797
|
+
{shown(column, cell)}
|
|
1798
|
+
</span>
|
|
1799
|
+
);
|
|
1800
|
+
case "age":
|
|
1801
|
+
return (
|
|
1802
|
+
<span className={cn(text({ role: "meta" }), VALUE)}>
|
|
1803
|
+
<Age moment={String(cell)} />
|
|
1804
|
+
</span>
|
|
1805
|
+
);
|
|
1806
|
+
default:
|
|
1807
|
+
return (
|
|
1808
|
+
<span
|
|
1809
|
+
className={cn(text({ role: "body" }), column.wrap ? WRAP : VALUE)}
|
|
1810
|
+
>
|
|
1811
|
+
{shown(column, cell)}
|
|
1812
|
+
</span>
|
|
1813
|
+
);
|
|
1814
|
+
}
|
|
1815
|
+
}
|
|
1816
|
+
|
|
1817
|
+
// A cell's edit in place: the Input of its column's kind. The cell sets its
|
|
1818
|
+
// fit, its name and its tab stop.
|
|
1819
|
+
function CellEdit(props: {
|
|
1820
|
+
column: TableColumn;
|
|
1821
|
+
cell: TableCell | undefined;
|
|
1822
|
+
field: CellFit;
|
|
1823
|
+
onEdit: (value: CellValue) => unknown;
|
|
1824
|
+
}) {
|
|
1825
|
+
const { column, cell } = props;
|
|
1826
|
+
const [draft, setDraft] = useState(
|
|
1827
|
+
cell === null || cell === undefined ? "" : String(cell),
|
|
1828
|
+
);
|
|
1829
|
+
const number = column.kind === "number";
|
|
1830
|
+
return (
|
|
1831
|
+
<HeldInput
|
|
1832
|
+
cell={props.field}
|
|
1833
|
+
kind={number ? "number" : column.kind === "source" ? "source" : "text"}
|
|
1834
|
+
value={draft}
|
|
1835
|
+
onChange={setDraft}
|
|
1836
|
+
onCommit={(value) =>
|
|
1837
|
+
props.onEdit(
|
|
1838
|
+
number ? (value.trim() === "" ? null : Number(value)) : value,
|
|
1839
|
+
)
|
|
1840
|
+
}
|
|
1841
|
+
/>
|
|
1842
|
+
);
|
|
1843
|
+
}
|
|
1844
|
+
|
|
1845
|
+
// A painted cell by its column's kind: a number, an age or an id as a figure's
|
|
1846
|
+
// filler, a status as its painted mark, a chip as a box, the rest as the text a column holds.
|
|
1847
|
+
function PaintedCell(props: {
|
|
1848
|
+
column: TableColumn;
|
|
1849
|
+
leading: boolean;
|
|
1850
|
+
index: number;
|
|
1851
|
+
}) {
|
|
1852
|
+
const { column, index } = props;
|
|
1853
|
+
if (props.leading)
|
|
1854
|
+
return (
|
|
1855
|
+
<span
|
|
1856
|
+
className={cn(
|
|
1857
|
+
text({ role: "body" }),
|
|
1858
|
+
textStrong({ role: "body" }),
|
|
1859
|
+
VALUE,
|
|
1860
|
+
)}
|
|
1861
|
+
>
|
|
1862
|
+
<Painted role="name" at={index} />
|
|
1863
|
+
</span>
|
|
1864
|
+
);
|
|
1865
|
+
switch (column.kind) {
|
|
1866
|
+
case "status":
|
|
1867
|
+
return <StatusBase painted />;
|
|
1868
|
+
case "chip":
|
|
1869
|
+
return <ChipBase family={column.family} label="" painted />;
|
|
1870
|
+
case "source":
|
|
1871
|
+
return (
|
|
1872
|
+
<span className={cn(text({ role: "code" }), VALUE)}>
|
|
1873
|
+
<Painted role="id" at={index} />
|
|
1874
|
+
</span>
|
|
1875
|
+
);
|
|
1876
|
+
case "number":
|
|
1877
|
+
case "age":
|
|
1878
|
+
return (
|
|
1879
|
+
<span
|
|
1880
|
+
className={cn(
|
|
1881
|
+
text({ role: column.kind === "age" ? "meta" : "body" }),
|
|
1882
|
+
VALUE,
|
|
1883
|
+
)}
|
|
1884
|
+
>
|
|
1885
|
+
<Painted role="figure" at={index} />
|
|
1886
|
+
</span>
|
|
1887
|
+
);
|
|
1888
|
+
default:
|
|
1889
|
+
return (
|
|
1890
|
+
<span className={cn(text({ role: "body" }), VALUE)}>
|
|
1891
|
+
<Painted role="phrase" at={index + 1} />
|
|
1892
|
+
</span>
|
|
1893
|
+
);
|
|
1894
|
+
}
|
|
1895
|
+
}
|
|
1896
|
+
|
|
1897
|
+
// A painted row: the loaded row's cells at their boxes, each painted by its
|
|
1898
|
+
// column's kind, the row inert.
|
|
1899
|
+
function PaintedRow(props: {
|
|
1900
|
+
index: number;
|
|
1901
|
+
columns: readonly TableColumn[];
|
|
1902
|
+
choosing: boolean;
|
|
1903
|
+
// The acts column stands, empty, so the loaded row lands in the same boxes.
|
|
1904
|
+
acts: boolean;
|
|
1905
|
+
}) {
|
|
1906
|
+
return (
|
|
1907
|
+
<tr inert className={tableRow({ state: "rest" })}>
|
|
1908
|
+
{props.choosing ? (
|
|
1909
|
+
<td className={cn(BODY_CELL, cn(TABLE_FROZEN, FROZEN, FROZEN_AT))}>
|
|
1910
|
+
<div
|
|
1911
|
+
className={cn(TICK_BOX, FLOOR, tableFrozenCell({ state: "rest" }))}
|
|
1912
|
+
>
|
|
1913
|
+
<HeldCheckbox checked={false} onChange={NOOP} label="" painted />
|
|
1914
|
+
</div>
|
|
1915
|
+
</td>
|
|
1916
|
+
) : null}
|
|
1917
|
+
{props.columns.map((column, place) => {
|
|
1918
|
+
const frozen = place === 0;
|
|
1919
|
+
return (
|
|
1920
|
+
<td
|
|
1921
|
+
key={column.key}
|
|
1922
|
+
className={cn(
|
|
1923
|
+
BODY_CELL,
|
|
1924
|
+
frozen &&
|
|
1925
|
+
cn(
|
|
1926
|
+
TABLE_FROZEN,
|
|
1927
|
+
FROZEN,
|
|
1928
|
+
props.choosing ? FROZEN_AFTER_TICK : FROZEN_AT,
|
|
1929
|
+
),
|
|
1930
|
+
)}
|
|
1931
|
+
>
|
|
1932
|
+
<div
|
|
1933
|
+
className={cn(
|
|
1934
|
+
TABLE_CELL,
|
|
1935
|
+
FLOOR,
|
|
1936
|
+
CELL,
|
|
1937
|
+
isEnd(column) && CELL_END,
|
|
1938
|
+
frozen && tableFrozenCell({ state: "rest", edge: "end" }),
|
|
1939
|
+
)}
|
|
1940
|
+
>
|
|
1941
|
+
<PaintedCell
|
|
1942
|
+
column={column}
|
|
1943
|
+
leading={place === 0}
|
|
1944
|
+
index={props.index + place}
|
|
1945
|
+
/>
|
|
1946
|
+
</div>
|
|
1947
|
+
</td>
|
|
1948
|
+
);
|
|
1949
|
+
})}
|
|
1950
|
+
{props.acts ? (
|
|
1951
|
+
<td className={cn(BODY_CELL, TABLE_FROZEN, FROZEN, FROZEN_END)}>
|
|
1952
|
+
<div
|
|
1953
|
+
className={cn(
|
|
1954
|
+
TICK_BOX,
|
|
1955
|
+
FLOOR,
|
|
1956
|
+
tableFrozenCell({ state: "rest", edge: "start" }),
|
|
1957
|
+
)}
|
|
1958
|
+
/>
|
|
1959
|
+
</td>
|
|
1960
|
+
) : null}
|
|
1961
|
+
</tr>
|
|
1962
|
+
);
|
|
1963
|
+
}
|
|
1964
|
+
|
|
1965
|
+
// On touch: the sort's pick over one Row per record.
|
|
1966
|
+
function Phone(props: {
|
|
1967
|
+
columns: readonly TableColumn[];
|
|
1968
|
+
rows: readonly TableRecord[];
|
|
1969
|
+
sort: Sort | undefined;
|
|
1970
|
+
onSort: (sort: Sort) => void;
|
|
1971
|
+
selected: string | undefined;
|
|
1972
|
+
current: string | undefined;
|
|
1973
|
+
onOpen: ((id: string) => void) | undefined;
|
|
1974
|
+
chooser: Chooser | undefined;
|
|
1975
|
+
painted: boolean;
|
|
1976
|
+
more: Read<unknown> | undefined;
|
|
1977
|
+
// A record over the placeholder, the next page's painted rows.
|
|
1978
|
+
blank: TableRecord | undefined;
|
|
1979
|
+
drag: DragSource | undefined;
|
|
1980
|
+
movable: Movable | undefined;
|
|
1981
|
+
warns: boolean;
|
|
1982
|
+
links: boolean;
|
|
1983
|
+
changes: boolean;
|
|
1984
|
+
}) {
|
|
1985
|
+
const words = useWords();
|
|
1986
|
+
const { columns, sort, chooser } = props;
|
|
1987
|
+
// The sheet the rows stand on and window in.
|
|
1988
|
+
const box = useRef<HTMLDivElement>(null);
|
|
1989
|
+
const [leading, ...rest] = columns;
|
|
1990
|
+
// Every status column is a status badge, its tone mark before its word; the
|
|
1991
|
+
// first leads the row's facts. Several say their column ("Staging: Passing"),
|
|
1992
|
+
// as the words of any kind that stands more than once do (`touchNamed`).
|
|
1993
|
+
const statuses = rest.filter((column) => column.kind === "status");
|
|
1994
|
+
const chip = rest.find((column) => column.kind === "chip");
|
|
1995
|
+
const ageColumn = rest.find((column) => column.kind === "age");
|
|
1996
|
+
const meta = rest.filter(
|
|
1997
|
+
(column) =>
|
|
1998
|
+
column.kind !== "status" && column !== chip && column !== ageColumn,
|
|
1999
|
+
);
|
|
2000
|
+
// A column of changes (a value before and after) and a column that wraps (a
|
|
2001
|
+
// sentence a cut badge would hide) are the row's line, not facts.
|
|
2002
|
+
const sentence = (column: TableColumn) =>
|
|
2003
|
+
column.kind === "change" || column.wrap === true;
|
|
2004
|
+
const lined = meta.some(sentence);
|
|
2005
|
+
const stated = meta.filter((column) => column.wrap !== true);
|
|
2006
|
+
// The columns whose values say their label: each of several alike.
|
|
2007
|
+
const named = touchNamed(stated);
|
|
2008
|
+
const sortable = columns.filter((column) => column.sortable);
|
|
2009
|
+
const sortedBy = sortable.find((column) => column.key === sort?.key);
|
|
2010
|
+
const arrow = sort?.direction === "ascending" ? "ArrowUp" : "ArrowDown";
|
|
2011
|
+
const pick = sortable.length ? (
|
|
2012
|
+
<div className={BAR}>
|
|
2013
|
+
<HeldPicker<string>
|
|
2014
|
+
label={words.sort}
|
|
2015
|
+
options={sortable.map((column) => ({
|
|
2016
|
+
value: column.key,
|
|
2017
|
+
label: column.label,
|
|
2018
|
+
leading: column === sortedBy ? { icon: arrow } : undefined,
|
|
2019
|
+
}))}
|
|
2020
|
+
value={sortedBy?.key}
|
|
2021
|
+
onChange={(key) => {
|
|
2022
|
+
const column = sortable.find((each) => each.key === key);
|
|
2023
|
+
if (!column) return;
|
|
2024
|
+
props.onSort(
|
|
2025
|
+
sort?.key === key
|
|
2026
|
+
? { key, direction: turnedOver(sort.direction) }
|
|
2027
|
+
: { key, direction: firstDirection(column) },
|
|
2028
|
+
);
|
|
2029
|
+
}}
|
|
2030
|
+
fit="row"
|
|
2031
|
+
/>
|
|
2032
|
+
</div>
|
|
2033
|
+
) : null;
|
|
2034
|
+
const cell = (record: TableRecord, column: TableColumn | undefined) =>
|
|
2035
|
+
column ? record.cells[column.key] : undefined;
|
|
2036
|
+
const { onOpen, painted } = props;
|
|
2037
|
+
// A field is given only when a column fills it, so the painted rows stand
|
|
2038
|
+
// in the shape the loaded ones draw; a mark whose cell the placeholder does
|
|
2039
|
+
// not shape (a status, a chip, an age) is given by its column instead.
|
|
2040
|
+
const rowOf = (record: TableRecord, painted: boolean): RowItem => {
|
|
2041
|
+
// A region that throws on the painted record answers the record, which a
|
|
2042
|
+
// painted row reads as filler whatever `R` is.
|
|
2043
|
+
const region = <R,>(fn: (one: TableRecord) => R): R =>
|
|
2044
|
+
painted ? (painting(fn, record) as R) : fn(record);
|
|
2045
|
+
// The facts in the order the row leads with them: the statuses, what is
|
|
2046
|
+
// wrong, the chip, then the other values.
|
|
2047
|
+
const facts: Fact[] = [];
|
|
2048
|
+
for (const status of statuses) {
|
|
2049
|
+
const state = region((one) => {
|
|
2050
|
+
if (painted) return { tone: "done" as const, label: "" };
|
|
2051
|
+
const cellOf = cell(one, status);
|
|
2052
|
+
if (!isStatusFact(cellOf)) return undefined;
|
|
2053
|
+
const word = cellOf.label ?? words[cellOf.tone];
|
|
2054
|
+
return {
|
|
2055
|
+
tone: cellOf.tone,
|
|
2056
|
+
label: statuses.length > 1 ? `${status.label}: ${word}` : word,
|
|
2057
|
+
};
|
|
2058
|
+
});
|
|
2059
|
+
if (state) facts.push(state);
|
|
2060
|
+
}
|
|
2061
|
+
if (props.warns && record.warning !== undefined)
|
|
2062
|
+
facts.push({ warning: record.warning });
|
|
2063
|
+
if (chip?.kind === "chip") {
|
|
2064
|
+
const kind = region((one) => {
|
|
2065
|
+
if (painted) return { family: chip.family, label: "" };
|
|
2066
|
+
return chipOf(chip, cell(one, chip));
|
|
2067
|
+
});
|
|
2068
|
+
if (kind) facts.push(kind);
|
|
2069
|
+
}
|
|
2070
|
+
// The values too long to stand as a fact (`touchFacts`), said whole in the
|
|
2071
|
+
// row's line.
|
|
2072
|
+
const long: string[] = [];
|
|
2073
|
+
if (stated.length || chooser) {
|
|
2074
|
+
const split = region((one) => {
|
|
2075
|
+
const parts = stated
|
|
2076
|
+
.filter((column) => !isChangeCell(cell(one, column)))
|
|
2077
|
+
.map((column) => {
|
|
2078
|
+
const at = cell(one, column);
|
|
2079
|
+
if (column.kind === "number" && at !== null && at !== undefined)
|
|
2080
|
+
return `${column.label} ${at}`;
|
|
2081
|
+
const word = isStatusFact(at)
|
|
2082
|
+
? (at.label ?? words[at.tone])
|
|
2083
|
+
: shown(column, at);
|
|
2084
|
+
return named.has(column.key) && word !== ""
|
|
2085
|
+
? `${column.label}: ${word}`
|
|
2086
|
+
: word;
|
|
2087
|
+
})
|
|
2088
|
+
.filter((part) => part !== "");
|
|
2089
|
+
// The tick draws a blocked reason itself; with none, the rule's
|
|
2090
|
+
// move is the reason.
|
|
2091
|
+
const moved = one.blocked === undefined ? chooseReason(one) : undefined;
|
|
2092
|
+
const split = touchFacts(parts, moved);
|
|
2093
|
+
return split.facts.length || split.said.length ? split : undefined;
|
|
2094
|
+
});
|
|
2095
|
+
// A region that threw over the filler is one filler fact.
|
|
2096
|
+
if (isTouchSplit(split)) {
|
|
2097
|
+
facts.push(...split.facts);
|
|
2098
|
+
long.push(...split.said);
|
|
2099
|
+
} else if (split !== undefined) facts.push("");
|
|
2100
|
+
}
|
|
2101
|
+
// What changed is a sentence ("Payload None → 1 page"), and so is a wrap
|
|
2102
|
+
// column's text and a value too long for a fact: never a fact, the row's
|
|
2103
|
+
// `line`, wrapping whole where touch cannot read a cut badge, the sentences
|
|
2104
|
+
// joined by "; ". A painted row paints its one filler where such a column
|
|
2105
|
+
// stands.
|
|
2106
|
+
const said = lined
|
|
2107
|
+
? painted
|
|
2108
|
+
? ""
|
|
2109
|
+
: [
|
|
2110
|
+
...long,
|
|
2111
|
+
...meta
|
|
2112
|
+
.filter(sentence)
|
|
2113
|
+
.map((column) => {
|
|
2114
|
+
const at = cell(record, column);
|
|
2115
|
+
if (isChangeCell(at)) return changeMeta(at, words);
|
|
2116
|
+
return shown(column, at);
|
|
2117
|
+
})
|
|
2118
|
+
.filter((part) => part !== ""),
|
|
2119
|
+
].join("; ")
|
|
2120
|
+
: !painted && long.length > 0
|
|
2121
|
+
? long.join("; ")
|
|
2122
|
+
: undefined;
|
|
2123
|
+
return {
|
|
2124
|
+
key: record.id,
|
|
2125
|
+
title: region((one) =>
|
|
2126
|
+
leading ? shown(leading, cell(one, leading)) : one.id,
|
|
2127
|
+
),
|
|
2128
|
+
// A tick draws a blocked reason itself (`Row`'s `check.blocked`);
|
|
2129
|
+
// the reason of a moved tick leads the row's facts.
|
|
2130
|
+
leading: chooser
|
|
2131
|
+
? {
|
|
2132
|
+
check: {
|
|
2133
|
+
checked: chooser.ticked(record.id),
|
|
2134
|
+
onChange: (on) => chooser.tick(record.id, on),
|
|
2135
|
+
blocked: record.blocked,
|
|
2136
|
+
},
|
|
2137
|
+
}
|
|
2138
|
+
: undefined,
|
|
2139
|
+
facts: facts.length ? facts : undefined,
|
|
2140
|
+
line: said === "" && !painted ? undefined : said,
|
|
2141
|
+
// The row words its age moment and keeps it current itself.
|
|
2142
|
+
trailing: ageColumn
|
|
2143
|
+
? region((one) => {
|
|
2144
|
+
if (painted) return { age: "" };
|
|
2145
|
+
const when = cell(one, ageColumn);
|
|
2146
|
+
return typeof when === "string" ? { age: when } : undefined;
|
|
2147
|
+
})
|
|
2148
|
+
: undefined,
|
|
2149
|
+
change: props.changes ? record.change : undefined,
|
|
2150
|
+
href: props.links ? record.href : undefined,
|
|
2151
|
+
// The row's act and menu, and the drag it carries and the drop it is.
|
|
2152
|
+
act: painted
|
|
2153
|
+
? undefined
|
|
2154
|
+
: // The record holds the act the row region gave, the platform's.
|
|
2155
|
+
(record.act as IconAct | IconLinkAct | undefined),
|
|
2156
|
+
more: painted ? undefined : record.more,
|
|
2157
|
+
drag: painted
|
|
2158
|
+
? undefined
|
|
2159
|
+
: props.drag && {
|
|
2160
|
+
kind: props.drag.kind,
|
|
2161
|
+
picked: chooser?.ticked(record.id)
|
|
2162
|
+
? chooser.pick
|
|
2163
|
+
: { ids: [record.id] },
|
|
2164
|
+
},
|
|
2165
|
+
drop: painted ? undefined : record.drop,
|
|
2166
|
+
// The open record is current; the others, at their `href`.
|
|
2167
|
+
selected:
|
|
2168
|
+
record.id === props.selected ||
|
|
2169
|
+
record.id === props.current ||
|
|
2170
|
+
undefined,
|
|
2171
|
+
// A row with `href` goes there; the others open through `onOpen`.
|
|
2172
|
+
onOpen: onOpen ? () => onOpen(record.id) : undefined,
|
|
2173
|
+
};
|
|
2174
|
+
};
|
|
2175
|
+
return (
|
|
2176
|
+
<>
|
|
2177
|
+
{pick}
|
|
2178
|
+
<SheetCard box={box}>
|
|
2179
|
+
<Rows
|
|
2180
|
+
drawn={
|
|
2181
|
+
painted
|
|
2182
|
+
? { painted: true, phase: "waiting", value: placeholderData() }
|
|
2183
|
+
: {
|
|
2184
|
+
painted: false,
|
|
2185
|
+
value: props.rows.map((one) => rowOf(one, false)),
|
|
2186
|
+
}
|
|
2187
|
+
}
|
|
2188
|
+
box={box}
|
|
2189
|
+
movable={props.movable}
|
|
2190
|
+
paint={
|
|
2191
|
+
painted && props.rows[0] ? rowOf(props.rows[0], true) : undefined
|
|
2192
|
+
}
|
|
2193
|
+
/>
|
|
2194
|
+
{props.more && props.blank ? (
|
|
2195
|
+
<MoreRow
|
|
2196
|
+
read={props.more}
|
|
2197
|
+
empty={props.rows.length === 0}
|
|
2198
|
+
inset
|
|
2199
|
+
paint={() => (
|
|
2200
|
+
<Rows
|
|
2201
|
+
drawn={{
|
|
2202
|
+
painted: true,
|
|
2203
|
+
phase: "waiting",
|
|
2204
|
+
value: placeholderData(),
|
|
2205
|
+
}}
|
|
2206
|
+
tail
|
|
2207
|
+
paint={props.blank ? rowOf(props.blank, true) : undefined}
|
|
2208
|
+
/>
|
|
2209
|
+
)}
|
|
2210
|
+
/>
|
|
2211
|
+
) : null}
|
|
2212
|
+
</SheetCard>
|
|
2213
|
+
</>
|
|
2214
|
+
);
|
|
2215
|
+
}
|