@slotform/react-ui 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (280) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +44 -2
  3. package/dist/density.d.ts +4 -0
  4. package/dist/density.d.ts.map +1 -0
  5. package/dist/density.js +8 -0
  6. package/dist/density.js.map +1 -0
  7. package/dist/index.d.ts +400 -0
  8. package/dist/index.d.ts.map +1 -0
  9. package/dist/index.js +388 -0
  10. package/dist/index.js.map +1 -0
  11. package/dist/node/canvas.d.ts +3 -0
  12. package/dist/node/canvas.d.ts.map +1 -0
  13. package/dist/node/canvas.js +13 -0
  14. package/dist/node/canvas.js.map +1 -0
  15. package/dist/node/codegen.d.ts +6 -0
  16. package/dist/node/codegen.d.ts.map +1 -0
  17. package/dist/node/codegen.js +70 -0
  18. package/dist/node/codegen.js.map +1 -0
  19. package/dist/node/css-escape.d.ts +8 -0
  20. package/dist/node/css-escape.d.ts.map +1 -0
  21. package/dist/node/css-escape.js +12 -0
  22. package/dist/node/css-escape.js.map +1 -0
  23. package/dist/node/fonts.d.ts +6 -0
  24. package/dist/node/fonts.d.ts.map +1 -0
  25. package/dist/node/fonts.js +219 -0
  26. package/dist/node/fonts.js.map +1 -0
  27. package/dist/node/lint.d.ts +3 -0
  28. package/dist/node/lint.d.ts.map +1 -0
  29. package/dist/node/lint.js +23 -0
  30. package/dist/node/lint.js.map +1 -0
  31. package/dist/node/mode.d.ts +9 -0
  32. package/dist/node/mode.d.ts.map +1 -0
  33. package/dist/node/mode.js +38 -0
  34. package/dist/node/mode.js.map +1 -0
  35. package/dist/node/theme.d.ts +13 -0
  36. package/dist/node/theme.d.ts.map +1 -0
  37. package/dist/node/theme.js +160 -0
  38. package/dist/node/theme.js.map +1 -0
  39. package/dist/types.d.ts +250 -0
  40. package/dist/types.d.ts.map +1 -0
  41. package/dist/types.js +80 -0
  42. package/dist/types.js.map +1 -0
  43. package/guide/acts.md +61 -0
  44. package/guide/audio.md +77 -0
  45. package/guide/blocks.md +82 -0
  46. package/guide/canvas-choosing.md +34 -0
  47. package/guide/canvas-editing.md +36 -0
  48. package/guide/canvas-layout.md +46 -0
  49. package/guide/canvas-opening.md +47 -0
  50. package/guide/canvas-overview.md +24 -0
  51. package/guide/canvas-states.md +37 -0
  52. package/guide/canvas-view.md +46 -0
  53. package/guide/canvas.md +94 -0
  54. package/guide/containers.md +60 -0
  55. package/guide/content.md +40 -0
  56. package/guide/controls.md +89 -0
  57. package/guide/density.md +48 -0
  58. package/guide/dock.md +42 -0
  59. package/guide/drag.md +38 -0
  60. package/guide/figures.md +25 -0
  61. package/guide/forms.md +82 -0
  62. package/guide/pane-bar.md +11 -0
  63. package/guide/pane.md +50 -0
  64. package/guide/reference.md +74 -0
  65. package/guide/rules.md +109 -0
  66. package/guide/section.md +29 -0
  67. package/guide/shell.md +26 -0
  68. package/guide/shots.md +37 -0
  69. package/guide/sidebar.md +30 -0
  70. package/guide/table.md +119 -0
  71. package/lint/no-arbitrary-value.grit +9 -0
  72. package/lint/no-class-on-component.grit +12 -0
  73. package/lint/no-density.grit +8 -0
  74. package/lint/no-host-look.grit +38 -0
  75. package/lint/no-img.grit +10 -0
  76. package/lint/no-navigate-act.grit +22 -0
  77. package/lint/no-raw-style.grit +8 -0
  78. package/package.json +150 -3
  79. package/src/density.ts +9 -0
  80. package/src/index.ts +503 -0
  81. package/src/node/canvas.ts +14 -0
  82. package/src/node/codegen.ts +100 -0
  83. package/src/node/css-escape.ts +27 -0
  84. package/src/node/fonts.ts +260 -0
  85. package/src/node/lint.ts +25 -0
  86. package/src/node/mode.ts +64 -0
  87. package/src/node/theme.ts +232 -0
  88. package/src/types.ts +120 -0
  89. package/src/ui/atoms/avatar/base.tsx +42 -0
  90. package/src/ui/atoms/button/glyph.tsx +244 -0
  91. package/src/ui/atoms/button/link.tsx +81 -0
  92. package/src/ui/atoms/button/look.ts +32 -0
  93. package/src/ui/atoms/button/reason.tsx +69 -0
  94. package/src/ui/atoms/chip/base.tsx +85 -0
  95. package/src/ui/atoms/count/base.tsx +27 -0
  96. package/src/ui/atoms/icon/index.tsx +51 -0
  97. package/src/ui/atoms/message/waiting.tsx +19 -0
  98. package/src/ui/atoms/prose/painted.tsx +35 -0
  99. package/src/ui/atoms/row/badges.tsx +226 -0
  100. package/src/ui/atoms/row/leading.tsx +166 -0
  101. package/src/ui/atoms/row/lock.tsx +17 -0
  102. package/src/ui/atoms/row/marks.tsx +79 -0
  103. package/src/ui/atoms/section/card.tsx +27 -0
  104. package/src/ui/atoms/spinner/index.tsx +42 -0
  105. package/src/ui/atoms/status/base.tsx +51 -0
  106. package/src/ui/atoms/status/change.tsx +29 -0
  107. package/src/ui/atoms/status/dot.tsx +45 -0
  108. package/src/ui/atoms/switch/checkbox.tsx +121 -0
  109. package/src/ui/atoms/turn.tsx +28 -0
  110. package/src/ui/components/action-bar/base.tsx +276 -0
  111. package/src/ui/components/action-bar/index.tsx +20 -0
  112. package/src/ui/components/avatar/index.tsx +21 -0
  113. package/src/ui/components/banner/index.tsx +207 -0
  114. package/src/ui/components/banner/pending.tsx +109 -0
  115. package/src/ui/components/bar-chart/index.tsx +701 -0
  116. package/src/ui/components/button/base.tsx +214 -0
  117. package/src/ui/components/button/face.tsx +84 -0
  118. package/src/ui/components/button/index.tsx +206 -0
  119. package/src/ui/components/canvas/connection.tsx +26 -0
  120. package/src/ui/components/canvas/edges.tsx +116 -0
  121. package/src/ui/components/canvas/elk.ts +260 -0
  122. package/src/ui/components/canvas/floor.ts +173 -0
  123. package/src/ui/components/canvas/geometry.ts +772 -0
  124. package/src/ui/components/canvas/ground.tsx +97 -0
  125. package/src/ui/components/canvas/group.tsx +156 -0
  126. package/src/ui/components/canvas/hit.ts +40 -0
  127. package/src/ui/components/canvas/index.tsx +497 -0
  128. package/src/ui/components/canvas/label.tsx +53 -0
  129. package/src/ui/components/canvas/layout.ts +543 -0
  130. package/src/ui/components/canvas/lift.ts +272 -0
  131. package/src/ui/components/canvas/look.ts +129 -0
  132. package/src/ui/components/canvas/node.tsx +689 -0
  133. package/src/ui/components/canvas/open.ts +243 -0
  134. package/src/ui/components/canvas/opening.ts +240 -0
  135. package/src/ui/components/canvas/view.ts +621 -0
  136. package/src/ui/components/canvas/viewport.ts +417 -0
  137. package/src/ui/components/canvas/zoom.tsx +113 -0
  138. package/src/ui/components/card/index.tsx +20 -0
  139. package/src/ui/components/chip/index.tsx +24 -0
  140. package/src/ui/components/code/frame.ts +2 -0
  141. package/src/ui/components/code/index.tsx +234 -0
  142. package/src/ui/components/columns/index.tsx +51 -0
  143. package/src/ui/components/count/index.tsx +17 -0
  144. package/src/ui/components/diff/index.tsx +249 -0
  145. package/src/ui/components/diff/word.tsx +104 -0
  146. package/src/ui/components/dock/index.tsx +262 -0
  147. package/src/ui/components/file-row/index.tsx +213 -0
  148. package/src/ui/components/form/base.tsx +280 -0
  149. package/src/ui/components/form/derive.tsx +269 -0
  150. package/src/ui/components/form/index.tsx +49 -0
  151. package/src/ui/components/form/saved.tsx +39 -0
  152. package/src/ui/components/form-field/index.tsx +658 -0
  153. package/src/ui/components/gallery/index.tsx +83 -0
  154. package/src/ui/components/gate/index.tsx +183 -0
  155. package/src/ui/components/image/base.tsx +245 -0
  156. package/src/ui/components/image/index.tsx +58 -0
  157. package/src/ui/components/input/base.tsx +246 -0
  158. package/src/ui/components/input/code.tsx +108 -0
  159. package/src/ui/components/input/drop.ts +37 -0
  160. package/src/ui/components/input/file.tsx +154 -0
  161. package/src/ui/components/input/index.tsx +132 -0
  162. package/src/ui/components/input/prose.tsx +107 -0
  163. package/src/ui/components/input/refusal.tsx +30 -0
  164. package/src/ui/components/item-header/base.tsx +410 -0
  165. package/src/ui/components/menu/base.tsx +319 -0
  166. package/src/ui/components/message/attachments.tsx +101 -0
  167. package/src/ui/components/message/base.tsx +266 -0
  168. package/src/ui/components/message-input/index.tsx +377 -0
  169. package/src/ui/components/missing/base.tsx +45 -0
  170. package/src/ui/components/pane/head.tsx +399 -0
  171. package/src/ui/components/pane/index.tsx +325 -0
  172. package/src/ui/components/picker/base.tsx +1551 -0
  173. package/src/ui/components/picker/index.tsx +224 -0
  174. package/src/ui/components/picker/list.tsx +423 -0
  175. package/src/ui/components/picker/segments.tsx +183 -0
  176. package/src/ui/components/prose/index.tsx +259 -0
  177. package/src/ui/components/qr-code/index.tsx +65 -0
  178. package/src/ui/components/row/acts.tsx +126 -0
  179. package/src/ui/components/row/fact.tsx +54 -0
  180. package/src/ui/components/row/index.tsx +1370 -0
  181. package/src/ui/components/row/progress.tsx +38 -0
  182. package/src/ui/components/row/status.tsx +54 -0
  183. package/src/ui/components/row/title.ts +7 -0
  184. package/src/ui/components/rules/index.tsx +290 -0
  185. package/src/ui/components/section/band.tsx +39 -0
  186. package/src/ui/components/section/head.tsx +267 -0
  187. package/src/ui/components/section/index.tsx +409 -0
  188. package/src/ui/components/section/rows.tsx +356 -0
  189. package/src/ui/components/sheet/base.tsx +272 -0
  190. package/src/ui/components/sheet/confirm.tsx +79 -0
  191. package/src/ui/components/sheet/docked.tsx +218 -0
  192. package/src/ui/components/sheet/form.tsx +76 -0
  193. package/src/ui/components/sheet/head.tsx +120 -0
  194. package/src/ui/components/sheet/index.tsx +45 -0
  195. package/src/ui/components/sheet/layer.tsx +168 -0
  196. package/src/ui/components/sheet/outlet.tsx +58 -0
  197. package/src/ui/components/sheet/task.tsx +41 -0
  198. package/src/ui/components/shell/cut.tsx +116 -0
  199. package/src/ui/components/shell/drag.tsx +45 -0
  200. package/src/ui/components/shell/host.tsx +71 -0
  201. package/src/ui/components/shell/index.tsx +737 -0
  202. package/src/ui/components/shell/panes.tsx +76 -0
  203. package/src/ui/components/shell/preview.ts +230 -0
  204. package/src/ui/components/shell/rail.tsx +163 -0
  205. package/src/ui/components/shell/row.ts +11 -0
  206. package/src/ui/components/shell/switcher.tsx +143 -0
  207. package/src/ui/components/shell/tree.tsx +252 -0
  208. package/src/ui/components/slider/base.tsx +139 -0
  209. package/src/ui/components/slider/index.tsx +57 -0
  210. package/src/ui/components/stages/index.tsx +198 -0
  211. package/src/ui/components/stats/count-links.tsx +47 -0
  212. package/src/ui/components/stats/index.tsx +203 -0
  213. package/src/ui/components/stats/meter.tsx +213 -0
  214. package/src/ui/components/stats/parts.ts +10 -0
  215. package/src/ui/components/step-count/index.tsx +45 -0
  216. package/src/ui/components/switch/base.tsx +86 -0
  217. package/src/ui/components/switch/index.tsx +38 -0
  218. package/src/ui/components/table/columns.tsx +131 -0
  219. package/src/ui/components/table/index.tsx +2215 -0
  220. package/src/ui/components/text/index.tsx +37 -0
  221. package/src/ui/components/thread/index.tsx +503 -0
  222. package/src/ui/components/thread/latest.tsx +59 -0
  223. package/src/ui/components/toast/index.tsx +113 -0
  224. package/src/ui/components/toast/layer.tsx +26 -0
  225. package/src/ui/components/toolbar/filters.tsx +161 -0
  226. package/src/ui/components/toolbar/index.tsx +125 -0
  227. package/src/ui/components/waveform/index.tsx +205 -0
  228. package/src/ui/globals.css +427 -0
  229. package/src/ui/lib/act.ts +60 -0
  230. package/src/ui/lib/age.ts +49 -0
  231. package/src/ui/lib/bound.ts +16 -0
  232. package/src/ui/lib/canvas-layout.ts +11 -0
  233. package/src/ui/lib/caret.ts +9 -0
  234. package/src/ui/lib/chip-lines.ts +3 -0
  235. package/src/ui/lib/closed.ts +8 -0
  236. package/src/ui/lib/code.tsx +184 -0
  237. package/src/ui/lib/columns.ts +39 -0
  238. package/src/ui/lib/commit.ts +24 -0
  239. package/src/ui/lib/container.ts +112 -0
  240. package/src/ui/lib/copy.ts +29 -0
  241. package/src/ui/lib/drag.ts +575 -0
  242. package/src/ui/lib/empty.tsx +85 -0
  243. package/src/ui/lib/field.ts +39 -0
  244. package/src/ui/lib/focus.ts +175 -0
  245. package/src/ui/lib/folds.ts +67 -0
  246. package/src/ui/lib/follow.ts +220 -0
  247. package/src/ui/lib/form.ts +19 -0
  248. package/src/ui/lib/guards.ts +38 -0
  249. package/src/ui/lib/heading.ts +14 -0
  250. package/src/ui/lib/ink.ts +26 -0
  251. package/src/ui/lib/lang.ts +7 -0
  252. package/src/ui/lib/leave.ts +14 -0
  253. package/src/ui/lib/lockup.tsx +145 -0
  254. package/src/ui/lib/measure.ts +22 -0
  255. package/src/ui/lib/media.ts +63 -0
  256. package/src/ui/lib/modality.ts +69 -0
  257. package/src/ui/lib/moment.ts +13 -0
  258. package/src/ui/lib/more.tsx +76 -0
  259. package/src/ui/lib/navigate.ts +210 -0
  260. package/src/ui/lib/noop.ts +3 -0
  261. package/src/ui/lib/not-found.tsx +40 -0
  262. package/src/ui/lib/paint.tsx +55 -0
  263. package/src/ui/lib/parts-line.tsx +54 -0
  264. package/src/ui/lib/picked.ts +18 -0
  265. package/src/ui/lib/player-store.ts +38 -0
  266. package/src/ui/lib/player.ts +139 -0
  267. package/src/ui/lib/portal.ts +12 -0
  268. package/src/ui/lib/read.tsx +269 -0
  269. package/src/ui/lib/region.tsx +49 -0
  270. package/src/ui/lib/reorder.ts +154 -0
  271. package/src/ui/lib/rest.ts +16 -0
  272. package/src/ui/lib/saved.ts +29 -0
  273. package/src/ui/lib/scramble.tsx +147 -0
  274. package/src/ui/lib/scrolls.ts +70 -0
  275. package/src/ui/lib/style.ts +6 -0
  276. package/src/ui/lib/swap.tsx +107 -0
  277. package/src/ui/lib/toast.ts +39 -0
  278. package/src/ui/lib/walk-classes.ts +16 -0
  279. package/src/ui/lib/window.tsx +376 -0
  280. package/src/ui/worker.d.ts +4 -0
@@ -0,0 +1,1370 @@
1
+ import { Button as BaseButton } from "@base-ui/react/button";
2
+ import { Field } from "@base-ui/react/field";
3
+ import { cn } from "@slotform/ui-core/cn";
4
+ import type { RowTitle, RowTrailing, Run } from "@slotform/ui-core/descriptors";
5
+ import { stepOf } from "@slotform/ui-core/drag";
6
+ import {
7
+ isAbsent,
8
+ isCopy,
9
+ isStatusFact,
10
+ splitFacts,
11
+ titleWords,
12
+ valueCut,
13
+ } from "@slotform/ui-core/list-state";
14
+ import { useClock } from "@slotform/ui-core/react/clock";
15
+ import { useRow, useSelections } from "@slotform/ui-core/react/read";
16
+ import { useWords } from "@slotform/ui-core/react/words";
17
+ import { endedSentence, paints } from "@slotform/ui-core/read";
18
+ import { isCurrent } from "@slotform/ui-core/route";
19
+ import { filled, isCode, META_TAIL, runsOf } from "@slotform/ui-core/runs";
20
+ import { sameBy } from "@slotform/ui-core/same-by";
21
+ import {
22
+ BLOCK_IN,
23
+ CODE_NAME,
24
+ DEFINITION_ABSENT,
25
+ DEFINITION_BOX,
26
+ DEFINITION_LABEL,
27
+ DEFINITION_LINE,
28
+ DEFINITION_NAME,
29
+ DROP_ON,
30
+ FIELD_ERROR_LINE,
31
+ FIGURES,
32
+ FLOW_IN,
33
+ PRESS_WASH,
34
+ ROW_ACTS,
35
+ ROW_CURRENT_BAR,
36
+ ROW_END,
37
+ ROW_ENTRY,
38
+ ROW_INLINE,
39
+ ROW_LEADING,
40
+ ROW_LEADING_STATUS,
41
+ ROW_META_LINE,
42
+ ROW_STEPS,
43
+ ROW_TEXT_FLOOR,
44
+ ROW_TITLE_LINE,
45
+ ROW_TRAILING,
46
+ row,
47
+ rowStep,
48
+ rowTitle,
49
+ rowTitleLines,
50
+ STATUS,
51
+ text,
52
+ YIELDS_FIRST,
53
+ } from "@slotform/ui-core/variants";
54
+ import {
55
+ type KeyboardEvent,
56
+ memo,
57
+ type PointerEvent,
58
+ type ReactNode,
59
+ use,
60
+ useState,
61
+ } from "react";
62
+ import { IconButtonBase } from "../../atoms/button/glyph.tsx";
63
+ import { useReasonLine } from "../../atoms/button/reason.tsx";
64
+ import {
65
+ Badge,
66
+ BadgesLine,
67
+ ChipBadge,
68
+ LockBadge,
69
+ MarkBadge,
70
+ StatusBadge,
71
+ WarningBadge,
72
+ WordsBadge,
73
+ } from "../../atoms/row/badges.tsx";
74
+ import {
75
+ First,
76
+ Leading,
77
+ type RowTree,
78
+ TreeLead,
79
+ treeFold,
80
+ } from "../../atoms/row/leading.tsx";
81
+ import { EndMark } from "../../atoms/row/marks.tsx";
82
+ import { StatusBase } from "../../atoms/status/base.tsx";
83
+ import { ChangeMark } from "../../atoms/status/change.tsx";
84
+ import { StatusDot } from "../../atoms/status/dot.tsx";
85
+ import { ageShort } from "../../lib/age.ts";
86
+ import { CodeCut, CodeWhole, RunText, Soft } from "../../lib/code.tsx";
87
+ import { press, useDrop, useOffers, useTouchHold } from "../../lib/drag.ts";
88
+ import { DistanceContext, useTouch } from "../../lib/media.ts";
89
+ import { follow, navigate, useRoute } from "../../lib/navigate.ts";
90
+ import { Painted } from "../../lib/paint.tsx";
91
+ import { FailedMark, RetryMark } from "../../lib/read.tsx";
92
+ import {
93
+ type Edge,
94
+ type Movable,
95
+ movesOf,
96
+ stepKey,
97
+ } from "../../lib/reorder.ts";
98
+ import type { VarStyle } from "../../lib/style.ts";
99
+ import { HeldInput } from "../input/base.tsx";
100
+ import { MenuBase } from "../menu/base.tsx";
101
+ import { HeldPicker } from "../picker/base.tsx";
102
+ import type { RowItem as RowItemData } from "../section/index.tsx";
103
+ import { HeldSwitch } from "../switch/base.tsx";
104
+ import {
105
+ ActButton,
106
+ ActLine,
107
+ hasMore,
108
+ PaintedAct,
109
+ RowAct,
110
+ RowMore,
111
+ } from "./acts.tsx";
112
+ import { CopyAct, IdValue } from "./fact.tsx";
113
+ import { RowProgress } from "./progress.tsx";
114
+ import { RowStatusDot, RowStatusWord, StatusValue } from "./status.tsx";
115
+ import { TITLE_ADAPTS, TITLE_COMPACT } from "./title.ts";
116
+
117
+ // The row is one box on the sheet's rows: docs/architecture/ui-core/layout.md, "Definition rows".
118
+ const ROW = "relative flex items-center min-h-row";
119
+ // A definition row stands its value under its label: docs/architecture/ui-core/layout.md, "Definition rows".
120
+ export const STACKED_BOX =
121
+ "definitions-stacked:flex definitions-stacked:flex-col definitions-stacked:items-stretch";
122
+ // A row whose title wraps whole, that holds an entry, or that has a label stands
123
+ // its change mark, tick and tree lane on the first line; its end group stays
124
+ // centred on the row. A label stands on the value's first line too, whatever
125
+ // the value's lines (facts that wrap beside a switch included), so it shares
126
+ // that line's baseline as on a one-line row; on touch the label
127
+ // stands over the line.
128
+ const ROW_WHOLE = "relative flex items-start min-h-row";
129
+ const ROW_LABELLED = "relative";
130
+ // The line of a row with a label, in the second column.
131
+ const LINE = "flex items-center min-w-0";
132
+ // Without a title, a facts line or an entry, a row with a label stands the
133
+ // label and the end group on one line on touch too, as a titled row does: a
134
+ // switch or an act is an end-group part on the first line (docs/architecture/ui-core/layout.md, "Title and facts"),
135
+ // never a value under its label. The label wraps in the room the end group
136
+ // leaves it. A form's toggle field stands the same way.
137
+ export const ASIDE =
138
+ "touch:flex-row touch:items-center definitions-stacked:flex-row definitions-stacked:items-center";
139
+ // The label keeps its longest word whole (the end group yields before it: a
140
+ // pick truncates its value), wrapping between words in what the end leaves.
141
+ export const ASIDE_LABEL = "min-w-min shrink-3";
142
+ export const ASIDE_LINE = "touch:grow definitions-stacked:grow";
143
+ // A described value beside a control (a pick, a switch) never falls under a
144
+ // reading floor (the short measure, or the line's whole width where it is
145
+ // narrower), so its description never breaks to a word a line: where the text
146
+ // at that floor and the control do not fit side by side, the end group stands
147
+ // under the text, at the line's end, a gap below it. A value with no
148
+ // description is one line that truncates, and acts stay on the value's line
149
+ // (docs/architecture/ui-core/layout.md, "Title and facts"), each keeping the row's floor of two fifths beside its end.
150
+ const LINE_WRAPS = "flex-wrap gap-y-gap";
151
+ const TEXT_READS = "basis-[min(100%,var(--container-measure-short))]";
152
+ // Started at the top, the line still runs the row's height, so its end group
153
+ // stands on the row's centre; a value of one line shorter than the body line
154
+ // (a code, the facts) stands centred on the label's line, as it stood on the row.
155
+ const LINE_FIRST = "items-start self-stretch";
156
+ const TEXT_FIRST = "min-h-line-body justify-center";
157
+ // The label wraps inside its column, never inside a word: the body's
158
+ // `overflow-wrap: anywhere` would make a letter its floor, so it sets
159
+ // `wrap-normal`.
160
+ const LABEL = "wrap-normal text-start";
161
+ // A row that opens washes under the pointer and the press; the chosen one a
162
+ // step darker under the pointer.
163
+ const CHOSEN_PRESS = "hover:bg-wash-selected-hover active:bg-wash-press";
164
+ // The hit covers the row, under its pick and its acts, and rings inset.
165
+ const HIT = "absolute inset-0 focus-visible:-outline-offset-2";
166
+ // A tree's row is its own focus stop, ringed inset like the hit it replaces.
167
+ const TREE_ITEM = "focus-visible:-outline-offset-2";
168
+ // A tree's child washes from its own rail, where the hairline above it starts
169
+ // (`TREE_DIVIDER`'s arithmetic on the row's own depth, `--tree-depth`): the indent
170
+ // before the rail is its parent's ground, so a bar and a wash there would mark
171
+ // the parent. The wash, and the current bar with it, is a layer under the
172
+ // row's parts from the rail's inner side to the row's end, taking no room; the
173
+ // rail stays whole beside the bar, which keeps its width. It eases as the row
174
+ // would (`ANSWER`'s transition, inherited).
175
+ const TREE_WASH =
176
+ "isolate before:absolute before:inset-y-0 before:end-0 before:start-[calc(var(--spacing-pad)+var(--tree-depth)*var(--spacing-stack))] before:-z-1 before:rounded-[inherit] before:[transition:inherit]";
177
+ // `ROW`'s selected wash and `ROW_CURRENT_BAR` on the layer.
178
+ const TREE_CURRENT =
179
+ "before:bg-wash-selected before:shadow-[inset_calc(3*var(--spacing-hairline))_0_0_var(--color-accent)] before:rounded-s-none";
180
+ const TREE_PRESS = "hover:before:bg-wash-hover active:before:bg-wash-press";
181
+ const TREE_CHOSEN_PRESS =
182
+ "hover:before:bg-wash-selected-hover active:before:bg-wash-press";
183
+ const LEADING = "flex shrink-0 items-center justify-center";
184
+ // A tick takes its hit box and stands above the row's hit, so a press on it
185
+ // ticks and never opens.
186
+ const TICK = "relative size-target";
187
+ // The text group keeps its floor of two fifths of the row (`ROW_TEXT_FLOOR`),
188
+ // the end group taking the rest; beside an end group that holds a control (a
189
+ // pick, a switch), which never cuts, the floor gives way to it, so the title
190
+ // wraps to its second line rather than the control's value be cut. A row with fact words and nothing else under
191
+ // its title is one line where it is wide enough and two below (the `row`
192
+ // container, `rowOneLine`: a rule of the row's width, never a measure of its
193
+ // content); on touch it is two lines at every width, and a row with a mark, an
194
+ // entry or the steps at every width and on every device.
195
+ const CONTAINED = "@container/row";
196
+ const TEXT_WORDS = "basis-auto w-min max-w-full shrink-0";
197
+ const TEXT_ADAPTS =
198
+ "row-two-line:basis-auto row-two-line:w-min row-two-line:max-w-full row-two-line:shrink-0";
199
+ // The facts line takes the text group's width and adds nothing to its minimum, so
200
+ // the title's longest word sets it, never a badge.
201
+ const BADGES_APART = "[contain:inline-size]";
202
+ const BADGES_APART_ADAPTS = "row-two-line:[contain:inline-size]";
203
+ // The text group, one class list per form: docs/architecture/ui-core/layout.md, "Text group and end group".
204
+ const TEXT_LINES = "flex flex-col grow min-w-0 gap-badge";
205
+ const TEXT_LISTS = {
206
+ plain: `${TEXT_LINES} ${ROW_TEXT_FLOOR}`,
207
+ reads: `${TEXT_LINES} ${TEXT_READS} ${YIELDS_FIRST}`,
208
+ controlled: `${TEXT_LINES} ${YIELDS_FIRST}`,
209
+ whole: `${TEXT_LINES} ${TEXT_WORDS}`,
210
+ };
211
+ // The text group in the form its row has: `plain` at the floor, `reads` (a
212
+ // label over a described value beside a control) at the reading floor,
213
+ // `controlled` (a control's row) at none, `whole` (touch, words whole) shrinking
214
+ // never, and `adapts` the container's form that holds the words whole below the
215
+ // row's one-line width.
216
+ function textGroup(form: keyof typeof TEXT_LISTS, adapts: boolean): string {
217
+ return adapts ? `${TEXT_LISTS[form]} ${TEXT_ADAPTS}` : TEXT_LISTS[form];
218
+ }
219
+ const TITLE = "truncate";
220
+ const TITLE_WHOLE = "min-w-0";
221
+ // A title that is one span of code stands in a flex line, so its stem
222
+ // truncates and its tail keeps the room it needs; in a row that wraps it stands
223
+ // whole, breaking at its path or URL separators first (`CodeWhole`), then
224
+ // anywhere.
225
+ const TITLE_CODE = "flex items-center min-w-0 overflow-hidden";
226
+ const CODE_WHOLE = "wrap-anywhere";
227
+ // The end group is a line after the text group's floor: its value is cut with
228
+ // an ellipsis to the room its controls and acts leave, which stand whole. It is
229
+ // centred on the row, whatever its lines; a control taller than its line
230
+ // overflows it centred.
231
+ // The group lets a press through to the row's hit; what in it takes the pointer
232
+ // (the controls, the acts, the fold) says so.
233
+ const END = "relative flex items-center min-w-0 ms-auto pointer-events-none";
234
+ const POINTED = "pointer-events-auto";
235
+ const END_SELF = "self-center";
236
+ // An end group overflows the row's line centred, so the row keeps its height
237
+ // whatever it holds: an icon act's, a switch's and a pick's box stand over the
238
+ // row's inset, as tall as the row at most (the control height is the row's), so
239
+ // a row with a pick stands at the rows' one height: its first-line
240
+ // box and the gap above and below it (32 px desktop, 44 touch), never a set
241
+ // height.
242
+ const END_LINE = "h-line-body";
243
+ // The end group's controls stand whole: the group never shrinks below them, and
244
+ // the text group gives way past its floor (`ROW_TEXT_FLOOR` is where it stops
245
+ // while the end group is smaller), its facts and then its title truncating
246
+ // first. The trailing value, the one part of the group that may be long, is cut
247
+ // at the short measure. A pick yields instead (`PICK`), and so does a room
248
+ // row's status (`STATE_WORD` truncates), so a group that holds one shrinks.
249
+ const END_WHOLE = "shrink-0";
250
+ // On touch a two-line row's end group stands on the title's line, at its end,
251
+ // and the facts line runs the row's whole width under both
252
+ // (docs/architecture/ui-core/layout.md, "Title and facts"): the title's line is
253
+ // its own flex line, the end group on its first line box. A control taller
254
+ // than the line overflows it centred, into the row's gap.
255
+ const HEAD = "flex flex-wrap items-start min-w-0";
256
+ const HEAD_END = "self-start";
257
+ // The title's group in that line keeps its floor as its basis, so the end group
258
+ // stands under it when the two do not fit side by side, never squeezing the
259
+ // title. A title that wraps keeps its longest word whole (`min-w-min`, over the
260
+ // body's `overflow-wrap: anywhere`, which would make a letter its floor), capped
261
+ // at the line, where a word wider than the row breaks as the last resort.
262
+ const HEAD_TEXT = "flex flex-col grow max-w-full";
263
+ const HEAD_ROOMY = "min-w-0";
264
+ const HEAD_WORDS = "min-w-min";
265
+ // A trailing value is cut with an ellipsis at the short measure; an age and a
266
+ // count are a few characters and stand whole.
267
+ const TRAILING = "min-w-0 max-w-measure-short truncate";
268
+ const TRAILING_WHOLE = "shrink-0";
269
+ // A control (a switch, a pick: its value is one word and a chevron) stands
270
+ // whole.
271
+ const CONTROL = "flex shrink-0";
272
+ // A pick yields to the room its row leaves: its trigger truncates the value,
273
+ // its chevron standing whole, so a pick never runs past the row.
274
+ const PICK = "flex min-w-0";
275
+ // The facts are a line of badges (`BadgesLine`): whole badges, none breaking
276
+ // inside, a gap apart with no separator, a long one cut with an ellipsis
277
+ // inside its badge. In a one-line row they follow the title on its line and
278
+ // stand on one line, the last cut where the line is out of room
279
+ // (`BADGES_INLINE`); below the row's one-line width they stand under the title
280
+ // and wrap whole (`row-two-line:`, `INLINE_ADAPTS`), as they do in a two-line
281
+ // row and under a wrapped title (`wrap`). A lone `{ code }` fact in a row is no
282
+ // badge: it is the row's value, one line cut in its middle (`valueCut`), and in
283
+ // the two-line form it wraps whole, breaking anywhere, so a command is read to
284
+ // its end. A painted line is the fillers, one badge each.
285
+ const META_CODE = "flex min-w-0";
286
+ const META_FREE = "break-words";
287
+ const BADGES_INLINE = "min-w-0 shrink";
288
+ // A one-line row's text: the title and the facts after it on one line. The
289
+ // title keeps its whole width up to the group's and is cut only once the facts
290
+ // are gone; below the row's one-line width the badges stand under it.
291
+ const INLINE = "flex items-center min-w-0";
292
+ // Folded, the badges stand a `badge` under the title, as a meta line does.
293
+ const INLINE_ADAPTS =
294
+ "row-two-line:flex-col row-two-line:items-stretch row-two-line:gap-badge";
295
+ const INLINE_TITLE = "shrink-0 max-w-full";
296
+ // The line under the title and the badges is text that wraps whole; a badge's
297
+ // gap stands between it and the badges above.
298
+ const LINE_TEXT = "min-w-0 break-words";
299
+ const LINE_BELOW = "mt-badge";
300
+ // A step is one body line's box tall (the step lists' 19 of the references,
301
+ // at the type scale's rung), its label truncating before its mark does.
302
+ const STEPS = "flex flex-col min-w-0";
303
+ const STEP = "flex items-center min-w-0 h-line-body";
304
+ const STEP_LABEL = "truncate";
305
+ const ACTS = "flex shrink-0 items-center pointer-events-auto";
306
+ // The entry stands above the hit: the input and its act, the field filling
307
+ // the room the act leaves. The act's label is never cut: the field keeps a
308
+ // reading floor (the short measure, or the line's width where it is
309
+ // narrower), and where it and the whole act do not fit side by side the act
310
+ // stands under the field at its own width, at the line's end, a gap below it,
311
+ // as a described value's end group does. The field's refusal stands in the
312
+ // field's own cell, under the input, so where the act wraps it stands between
313
+ // the two and never under the act it does not name; the input and the act
314
+ // start on one line, the refusal under the input beside the act's room.
315
+ const ENTRY = "relative flex flex-wrap items-start min-w-0 gap-y-gap";
316
+ const ENTRY_FIELD =
317
+ "flex flex-col grow min-w-0 gap-gap basis-[min(100%,var(--container-measure-short))]";
318
+ const ENTRY_ACT = "flex shrink-0 max-w-full ms-auto";
319
+ // In a room a row whose only mark is a status draws one line, as a row with
320
+ // fact words and no mark does at the desktop's width: the title, the facts after
321
+ // it, and the status after the facts, a dot and its word at the end group's
322
+ // start before the age. The board holds twice the rows. The status takes its
323
+ // natural width, whatever the word, and the facts take the room they leave (the
324
+ // text group grows into it, and the facts are the part cut, last: its box
325
+ // shrinks, the title's does not). The word ends in an ellipsis only where the
326
+ // room is under what the one-line form needs (`rowOneLine`, the facts
327
+ // standing under the title below it, as any row's does): a window narrower
328
+ // than a room is.
329
+ // The status word is the end group's part that yields first: the age, a figure,
330
+ // keeps its room beside it.
331
+ const STATE = "flex items-center min-w-0 shrink-100";
332
+ const STATE_WORD = "min-w-0 truncate";
333
+ // A status value stands at the value's start, its dot and word whole, centred
334
+ // on the first line's box. It is no target: a press on it reaches the row's
335
+ // hit, as one on the end group does (`END`), so a pill in the title never
336
+ // swallows the row's open target.
337
+ const VALUE_STATUS = "flex items-center h-line-body pointer-events-none";
338
+
339
+ // No facts: one list, so a row without any reads the same selections each render.
340
+ const NO_FACTS: readonly unknown[] = [];
341
+
342
+ const noDrag = (event: { preventDefault: () => void }) =>
343
+ event.preventDefault();
344
+
345
+ /** What a Section hands the rows it draws; no app sets them, so they are outside the items. */
346
+ interface RowInternal {
347
+ /** The row's place in a tree `List`: its depth (the roots 0), for a branch whether its children are drawn and how to fold them, and whether it is the tree's one tab stop. */
348
+ tree?: RowTree;
349
+ /** The Section's items are not here: every part paints at its role, the row is inert and builds no hit. */
350
+ painted?: boolean;
351
+ /** The row's place among the painted rows, which varies the filler's lengths. */
352
+ at?: number;
353
+ /** The row came to a Section already drawn, on its own: it fades in as it mounts, and holds the fade for the life of the instance. */
354
+ arrived?: boolean;
355
+ /** The row's key in its sheet, which a move and a drop name it by. */
356
+ id?: string;
357
+ /** The sheet reorders: the order the row reads and moves by. */
358
+ movable?: Movable;
359
+ /** Where the row stands in a movable sheet (first, last or alone), which decides the moves its menu offers. */
360
+ edge?: Edge;
361
+ }
362
+
363
+ /** The fields a row takes: a list item's or a fact's, its reads widened to a `Datum`. */
364
+ type RowProps<V extends string | null = string> = Omit<
365
+ RowItemData<V>,
366
+ "key" | "children" | "group"
367
+ > &
368
+ RowInternal;
369
+
370
+ // A trailing age's short words, read off the shared clock: the row draws
371
+ // again only when they change.
372
+ function Age(props: { moment: string }) {
373
+ return useClock((now) => ageShort(props.moment, now));
374
+ }
375
+
376
+ function trailingWord(trailing: RowTrailing): ReactNode {
377
+ if ("age" in trailing)
378
+ return (
379
+ <>
380
+ <Age moment={trailing.age} />
381
+ {trailing.beside === undefined
382
+ ? null
383
+ : `${META_TAIL}${trailing.beside}`}
384
+ </>
385
+ );
386
+ if ("count" in trailing) return String(trailing.count);
387
+ return trailing.value;
388
+ }
389
+
390
+ /** The one row of a Section's sheet, whatever it holds. Its box is a line of three groups: a leading region (the change mark, then the leading mark: a glyph, a status dot, an avatar, a type's mark or a tick; a tree's rails), a text group (the title over the facts line) and an end group, in one order: the marks whose words are not drawn (`words: false`: a glyph named by its label, with a tooltip), the trailing value, a switch, a pick, the act (an icon act), the copy act, the more act, a tree's fold. The facts line is a line of badges (`BadgesLine`), each fact one badge in the order given, none breaking inside, none separated from the next by a dot, whole badges wrapping to the next line: the status its tone's mark and word, the row's lock (the lock glyph and its reason, a link to what holds the fact with an `href`, inert without one) right after it, a warning the warn glyph and phrase, a chip its family's dot and value, a ring (outlined, its centre filled) or a flag its glyph and label, words and a code in the mono their text; a blocked tick's reason is the first badge, plain. A badge too long for the line is cut inside its box with an ellipsis. A sentence is not a fact: the row's `line` is text under the title and the badges, in the meta ink at the meta role, wrapping whole at every width (runs, a code run moving whole to the next line), a badge's gap below the badges above it, so a row with a line is at least two lines (the line under the title where the badges follow it on its line); empty it draws nothing, painted it is one sentence's filler. A row with a mark is two lines at every width; a row with fact words alone is one line where it is wide enough and two below (the `row` container, `rowOneLine`: a rule of the row's width, never a measure of its content), and on touch two at every width. In a one-line row the badges follow the title on its line on one line, the last one cut where the line is out of room; under the title, and under a wrapped title (`wrap`), they wrap whole. A lone `{ code }` fact is no badge: it is the row's value, the mono cut in its middle and, in the two-line form, whole. A room place's row whose only mark is a status keeps it in the end group's start after the facts, a dot and its word, one line. A row with a `label` stands in the sheet's two columns, the label in the first at the body role in the meta ink (a `code` label in the code role) in a column as wide as the widest label of the Pane, and the line in the second; on touch the line stands under the label. A row without one spans the sheet from its start. A row that opens (`href` or `onOpen`) draws no chevron: it is one hit, washing under the pointer, current (the bar) when `selected`, or at its `href` unless `selected` is `false`; a linked badge (the lock) stands above the hit and takes the pointer, the rest of the line none. A title truncates on one line unless `wrap`, whether the row has a label or not; the end group is centred on the row; an absent word is in the meta ink, a status title is its tone's mark and word at the title's start, plain (no pill: colour stays on the glyph), a copyable code is the mono and, too long for its room, cut in its middle. The painted shape is the loaded one with every part in its filler, a badge's filler at the loaded badge's size, inert. The row is the frame of the selections it draws (`title`, `facts`, `line`): one that failed, with no frame above holding it, makes the failed shape (the label stays, the end shows the failure mark and the retry icon, the facts line reads "This didn't load." as text, and pressing the row retries). Outside the package's exports. */
391
+ export function RowBase<V extends string | null = string>(props: RowProps<V>) {
392
+ const {
393
+ change: kind,
394
+ label,
395
+ leading,
396
+ title,
397
+ facts: offered,
398
+ line,
399
+ trailing,
400
+ lock: lockGiven,
401
+ entry,
402
+ steps,
403
+ progress,
404
+ dim = false,
405
+ wrap: wraps = false,
406
+ switch: toggle,
407
+ pick,
408
+ act,
409
+ more,
410
+ href,
411
+ selected,
412
+ onOpen,
413
+ tree,
414
+ painted = false,
415
+ at = 0,
416
+ arrived = false,
417
+ drag,
418
+ drop,
419
+ id,
420
+ movable,
421
+ edge,
422
+ } = props;
423
+ const labelled = label !== undefined;
424
+ const labelText = typeof label === "object" ? label.code : label;
425
+ const words = useWords();
426
+ const route = useRoute();
427
+ // A row that is dragged, reordered or dropped on: the press that moves
428
+ // drags it, the drop under the pointer washes, and what a drag does by
429
+ // pointer is also in its more menu (the drops that accept it, the moves).
430
+ const { mark: dropMark, over } = useDrop(painted ? undefined : drop, href);
431
+ const dragged = painted ? undefined : drag;
432
+ // `useOffers` asks for the drag only while its kind stands, so `dragged`
433
+ // is there.
434
+ const offers = useOffers(
435
+ dragged?.kind,
436
+ () => dragged as NonNullable<typeof dragged>,
437
+ );
438
+ const moves =
439
+ movable && id !== undefined && !painted
440
+ ? movesOf(words, movable, id, edge)
441
+ : [];
442
+ const extra = [...offers, ...moves];
443
+ const draggable =
444
+ !painted && (dragged !== undefined || movable !== undefined);
445
+ useTouchHold(draggable);
446
+ // The row is a block among its list's: named for the page's block move, and
447
+ // fading in if it arrived on its own (held from the first render, so the
448
+ // fade is not cut short by a later one).
449
+ const [fades] = useState(arrived);
450
+ // The row is the frame of the reads it draws that no frame above holds: one
451
+ // that ended is the row's failed shape, in place of its title, facts and end;
452
+ // a read an enclosing frame holds is that frame's to say.
453
+ // The facts are a list, a read of its own or of each fact: one that waits
454
+ // paints a filler in its place.
455
+ const [read, said, lineRead] = useSelections([title, offered, line]);
456
+ const given: readonly unknown[] =
457
+ !said.painted && Array.isArray(said.value) ? said.value : NO_FACTS;
458
+ const each = useSelections(given);
459
+ const { ended, busy, retry } = useRow([title, offered, line, ...given]);
460
+ const failed = ended === "failed";
461
+ // Painted by the Section, or by a datum of its own that waits: either way the
462
+ // row draws its loaded tree, each part the datum reaches in its filler, and
463
+ // takes no press.
464
+ const waitsTitle = !ended && (painted || paints(read));
465
+ const waitsFacts =
466
+ !ended && (painted || paints(said) || each.some((fact) => paints(fact)));
467
+ // The line is a sentence under the title: given and waiting it paints one
468
+ // sentence's filler, loaded it is text, and empty it draws nothing.
469
+ const waitsLine =
470
+ !ended && line !== undefined && (painted || paints(lineRead));
471
+ const inert = waitsTitle || waitsFacts || waitsLine;
472
+ const toldLine =
473
+ ended || painted || lineRead.painted ? undefined : lineRead.value;
474
+ const hasLine =
475
+ waitsLine || (toldLine !== undefined && runsOf(toldLine).some(filled));
476
+ // A placeholder is a function proxy that no type test passes: the title is
477
+ // read only once painted is ruled out.
478
+ const plain =
479
+ painted || read.painted ? undefined : (read.value as RowTitle | undefined);
480
+ // Over the placeholder the title is not a name.
481
+ const named = painted
482
+ ? ""
483
+ : (labelText ?? (plain === undefined ? "" : titleWords(plain)));
484
+ const current =
485
+ !inert && (selected ?? (href !== undefined && isCurrent(href, route)));
486
+ const opens =
487
+ !inert && !ended && (href !== undefined || onOpen !== undefined);
488
+ const live = failed || opens;
489
+ // A tree's child: its wash starts at its rail (`TREE_WASH`).
490
+ const child = tree !== undefined && tree.depth > 0;
491
+ const moreActs = hasMore(more);
492
+ const ticks = leading !== undefined && "check" in leading;
493
+ const blocked = ticks && !painted ? leading.check.blocked : undefined;
494
+ const listed = steps?.length ? steps : undefined;
495
+ const change = painted ? undefined : kind;
496
+ // The lock: a reason, a link with its `href`.
497
+ const lock = ended
498
+ ? undefined
499
+ : typeof lockGiven === "object"
500
+ ? lockGiven.reason
501
+ : lockGiven;
502
+ const lockHref =
503
+ ended || typeof lockGiven !== "object" ? undefined : lockGiven.href;
504
+ // The copy act copies the code a title names.
505
+ const copied = isCopy(plain) ? plain.code : undefined;
506
+ // A waiting title's value is the placeholder, which stands in a title's shape.
507
+ const shape = (waitsTitle && title !== undefined ? read.value : plain) as
508
+ | RowTitle
509
+ | undefined;
510
+ // A fact's copyable code is read to its end, as a definition is: the value
511
+ // stands whole on as many lines as it takes, at a path's or URL's
512
+ // separators first, never cut in its middle (the copy act has the whole).
513
+ const wrap = wraps || (label !== undefined && isCopy(shape));
514
+ // The facts by kind (`splitFacts`, the one reading of them). A list read that
515
+ // waits is one filler, a fact whose read ended draws nothing and one that
516
+ // waits is a filler in its place. A loaded part with no text draws nothing,
517
+ // so no separator dangles after the part before it; a painted row keeps one
518
+ // filler per part the region gave. The failed sentence takes the words' place.
519
+ const drawn = said.painted
520
+ ? paints(said)
521
+ ? [""]
522
+ : []
523
+ : each
524
+ .filter((fact) => !fact.painted || paints(fact))
525
+ .map((fact) => fact.value);
526
+ const split = splitFacts(drawn);
527
+ const status = split.facts.flatMap((part) =>
528
+ part.kind === "status" ? [part.fact] : [],
529
+ )[0];
530
+ const warnings = split.facts.filter((part) => part.kind === "warning");
531
+ const factWords = split.facts.flatMap((part) =>
532
+ part.kind === "words" ? [part.fact] : [],
533
+ );
534
+ // A chip and the boolean marks are the item's data, which the painted shape
535
+ // cannot know: never painted (the loaded rows that have none would land
536
+ // narrower).
537
+ const chips = painted
538
+ ? []
539
+ : split.facts.filter((part) => part.kind === "chip");
540
+ let told: Run[];
541
+ if (ended) told = [endedSentence(words, ended)];
542
+ else if (waitsFacts) told = factWords;
543
+ else told = factWords.filter(filled);
544
+ const hasTitle = title !== undefined && !ended;
545
+ const hasMeta = told.length > 0;
546
+ // A mark whose words are not drawn (`words: false`) stands in the end
547
+ // group, a glyph named by its label, so it is no mark of the facts line: a
548
+ // row with only such marks has no second line for them.
549
+ const endFacts = painted ? [] : split.quiet;
550
+ const metaFacts = painted
551
+ ? []
552
+ : split.facts.filter((part) => part.kind === "mark");
553
+ // The marks lead the facts line; an entry or the steps stand in its place, as
554
+ // the facts' words do.
555
+ const marking =
556
+ entry === undefined &&
557
+ !listed &&
558
+ (status !== undefined ||
559
+ warnings.length > 0 ||
560
+ lock !== undefined ||
561
+ chips.length > 0 ||
562
+ metaFacts.length > 0);
563
+ // A room Panes's row whose only mark is a status stands it in the end
564
+ // group after the facts, one line (`STATE`): the title's own line is the
565
+ // row's, wherever the row has the width the desktop's one-line form needs.
566
+ const far = use(DistanceContext);
567
+ const stated =
568
+ far &&
569
+ marking &&
570
+ !ended &&
571
+ status !== undefined &&
572
+ warnings.length === 0 &&
573
+ lock === undefined &&
574
+ chips.length === 0 &&
575
+ metaFacts.length === 0 &&
576
+ !wrap &&
577
+ !labelled;
578
+ const marked = marking && !stated;
579
+ // A room row with no mark that takes a line (only wordless marks, which
580
+ // stand in the end group, or none) is as a status-only one: its form is the
581
+ // row's width to decide, one line where it is wide enough.
582
+ const quiet =
583
+ far &&
584
+ !marking &&
585
+ entry === undefined &&
586
+ listed === undefined &&
587
+ !wrap &&
588
+ !labelled;
589
+ const roomy = stated || quiet;
590
+ const touch = useTouch();
591
+ // A row is two lines where it holds an entry, the steps or a mark, and on
592
+ // touch where it has fact words; one with fact words and nothing else under
593
+ // its title is one line where the row is wide enough, two below
594
+ // (`row-two-line:`). A row with no facts has no second line to take.
595
+ const twoLined =
596
+ entry !== undefined ||
597
+ listed !== undefined ||
598
+ marked ||
599
+ (touch && (hasMeta || hasLine) && !roomy);
600
+ const adapts = !twoLined && !wrap && hasMeta;
601
+ const lines = wrap ? "whole" : twoLined ? "two" : "one";
602
+ const oneLine = lines === "one";
603
+ // The row is the `row` container where its form is the container's to decide:
604
+ // its title wraps to a second line below the row's one-line width.
605
+ const contained = (!touch || roomy) && (adapts || marked);
606
+ // A wrapped title and an entry's input are lines under the first, so the
607
+ // change mark, tick and tree lane beside them stand on that first line; the
608
+ // end group stands on the row's centre whatever the lines.
609
+ const top = wrap || entry !== undefined;
610
+ // Beside a label a value that may take more than a line (facts, which
611
+ // wraps or stands under the title, or a second line) starts at the top, its
612
+ // parts on its first line beside the label, as a wrapped title's do
613
+ // (`ROW_WHOLE`); a title alone is one line and stays centred.
614
+ const onFirst =
615
+ top || (labelled && !touch && (hasMeta || hasLine || twoLined));
616
+ // A status dot is the title's bullet: on a row of more than one line it
617
+ // stands on the title's first line, never between the title and the facts
618
+ // on the row's centre.
619
+ const dotFirst =
620
+ (!oneLine || hasLine) &&
621
+ !onFirst &&
622
+ leading !== undefined &&
623
+ "tone" in leading;
624
+ // A model-written name (a `{ quoted }` run) wraps in a row that has a second line, so
625
+ // its closing quote is never cut away; its row grows by the lines it wraps.
626
+ const quotedWraps =
627
+ !painted &&
628
+ twoLined &&
629
+ typeof plain === "object" &&
630
+ !Array.isArray(plain) &&
631
+ "quoted" in plain;
632
+ const reads =
633
+ labelled && hasMeta && (pick !== undefined || toggle !== undefined);
634
+ // An end group made of a control gives the text group's floor way (a
635
+ // described value beside one keeps its reading floor, `reads`).
636
+ const controlled = !labelled && (pick !== undefined || toggle !== undefined);
637
+ const wordsWhole = !wrap && !quotedWraps;
638
+ const form =
639
+ wordsWhole && touch && !roomy
640
+ ? "whole"
641
+ : reads
642
+ ? "reads"
643
+ : controlled
644
+ ? "controlled"
645
+ : "plain";
646
+ const bar =
647
+ progress && !painted ? <RowProgress {...progress} name={named} /> : null;
648
+ const column = cn(
649
+ textGroup(form, wordsWhole && contained),
650
+ onFirst && !top && TEXT_FIRST,
651
+ );
652
+ const inline = { label: entry?.label ?? "" };
653
+ const entryReason = useReasonLine(painted ? undefined : entry?.act.blocked);
654
+ // The pressed reason of the act, which its button and its line both read:
655
+ // the row holds it, neither knows the other.
656
+ const [stood, stand] = useState<string>();
657
+ const actLine =
658
+ act === undefined || painted ? null : <ActLine act={act} stood={stood} />;
659
+ // A blocked tick's reason is the first badge, plain.
660
+ const parts: Run[] = blocked !== undefined ? [blocked, ...told] : told;
661
+ // A fact that is one span of code, alone, is the row's value and cuts in its
662
+ // middle; beside other facts it is a badge in the mono.
663
+ const [only] = parts;
664
+ const coded =
665
+ !painted && parts.length === 1 && only && isCode(only) ? only : undefined;
666
+ const trailed = trailing ? (
667
+ <span
668
+ className={cn(
669
+ ROW_TRAILING,
670
+ TRAILING,
671
+ !("value" in trailing) && TRAILING_WHOLE,
672
+ )}
673
+ >
674
+ {painted ? <Painted role="figure" at={at} /> : trailingWord(trailing)}
675
+ </span>
676
+ ) : null;
677
+ // The badges, in the order the facts are given: a blocked tick's reason first,
678
+ // the status, the lock right after it (first where there is no status), then
679
+ // each fact its kind draws. A status that stands in the end
680
+ // group (a room row's) is no badge. A fact that waits, or a row that is
681
+ // painted, draws the filler of what the kind keeps painted: every word one
682
+ // filler badge, whether the region gave words or the placeholder whole.
683
+ const lockBadge =
684
+ lock === undefined ? null : (
685
+ <LockBadge key="lock" reason={lock} href={lockHref} painted={painted} />
686
+ );
687
+ const badges: ReactNode[] = [];
688
+ if (!ended) {
689
+ if (blocked !== undefined)
690
+ badges.push(<WordsBadge key="blocked" fact={blocked} />);
691
+ let locked = lockBadge === null;
692
+ const lockAfterStatus = status !== undefined && !stated;
693
+ if (!locked && !lockAfterStatus) {
694
+ badges.push(lockBadge);
695
+ locked = true;
696
+ }
697
+ // The first status leads the badges and the lock follows it; each further
698
+ // status is a badge of its own, its tone mark before its word, where it
699
+ // stands in the list.
700
+ let led = false;
701
+ split.facts.forEach((part, index) => {
702
+ // The chips and marks are the item's data, never painted.
703
+ if (painted && (part.kind === "chip" || part.kind === "mark")) return;
704
+ const key = `fact-${index}`;
705
+ if (part.kind === "status") {
706
+ const badge = (
707
+ <StatusBadge key={key} status={part.fact} painted={painted} />
708
+ );
709
+ if (led) {
710
+ badges.push(badge);
711
+ return;
712
+ }
713
+ led = true;
714
+ if (stated) return;
715
+ badges.push(badge);
716
+ if (!locked) badges.push(lockBadge);
717
+ locked = true;
718
+ } else if (part.kind === "warning")
719
+ badges.push(
720
+ <WarningBadge key={key} warning={part.fact} painted={painted} />,
721
+ );
722
+ else if (part.kind === "chip")
723
+ badges.push(<ChipBadge key={key} chip={part.fact} />);
724
+ else if (part.kind === "mark")
725
+ badges.push(<MarkBadge key={key} mark={part.fact} />);
726
+ else if (waitsFacts) badges.push(<Badge key={key} painted />);
727
+ else if (filled(part.fact))
728
+ badges.push(<WordsBadge key={key} fact={part.fact} />);
729
+ });
730
+ }
731
+ // The title, in the form its data takes: words (they wrap in a row with a
732
+ // label, truncate in one without), a status's pill, an identifier in the
733
+ // mono or the absent word.
734
+ let titleLine: ReactNode = null;
735
+ if (hasTitle) {
736
+ const whole = wrap || quotedWraps;
737
+ const box = cn(
738
+ rowTitle({ lines: rowTitleLines(dim) }),
739
+ whole
740
+ ? TITLE_WHOLE
741
+ : cn(
742
+ TITLE,
743
+ touch && !roomy && TITLE_COMPACT,
744
+ contained && TITLE_ADAPTS,
745
+ ),
746
+ FIGURES,
747
+ oneLine && hasMeta && INLINE_TITLE,
748
+ );
749
+ if (waitsTitle) {
750
+ if (isStatusFact(shape))
751
+ titleLine = (
752
+ <span className={VALUE_STATUS}>
753
+ <StatusBase painted />
754
+ </span>
755
+ );
756
+ // The id's one position, in this form and the loaded one, so the region
757
+ // that waited is the region that arrived.
758
+ else if (isCopy(shape)) titleLine = <IdValue painted at={at} />;
759
+ else
760
+ titleLine = (
761
+ <span className={box}>
762
+ <Painted role="title" at={at} />
763
+ </span>
764
+ );
765
+ } else if (isCopy(plain)) {
766
+ if (whole) titleLine = <IdValue stem={plain.code} whole />;
767
+ else {
768
+ const { stem, tail } = valueCut(plain.code);
769
+ titleLine = <IdValue stem={stem} tail={tail} />;
770
+ }
771
+ } else if (isAbsent(plain)) {
772
+ titleLine = (
773
+ <span className={cn(box, DEFINITION_ABSENT)}>{plain.absent}</span>
774
+ );
775
+ } else if (isStatusFact(plain)) {
776
+ titleLine = (
777
+ <span className={VALUE_STATUS}>
778
+ <StatusValue status={plain} />
779
+ </span>
780
+ );
781
+ } else if (plain !== undefined && isCode(plain)) {
782
+ titleLine = whole ? (
783
+ <span
784
+ className={cn(rowTitle({ lines: rowTitleLines(dim) }), TITLE_WHOLE)}
785
+ >
786
+ <code className={cn(CODE_NAME, CODE_WHOLE)}>
787
+ <CodeWhole code={plain.code} />
788
+ </code>
789
+ </span>
790
+ ) : (
791
+ <span
792
+ className={cn(
793
+ rowTitle({ lines: rowTitleLines(dim) }),
794
+ TITLE_CODE,
795
+ oneLine && hasMeta && INLINE_TITLE,
796
+ )}
797
+ >
798
+ <CodeCut code={plain.code} />
799
+ </span>
800
+ );
801
+ } else if (plain !== undefined) {
802
+ titleLine = (
803
+ <span className={box}>
804
+ {typeof plain === "string" ? (
805
+ <Soft text={plain} />
806
+ ) : (
807
+ <RunText
808
+ runs={runsOf(plain)}
809
+ whole={whole}
810
+ wraps={whole}
811
+ fit="name"
812
+ />
813
+ )}
814
+ </span>
815
+ );
816
+ }
817
+ }
818
+ // The facts line, drawn once: after the title on its line in a one-line row,
819
+ // under it in a wrapped or two-line one. A lone code is the row's value, one
820
+ // line cut in its middle, or whole where the row is two lines; the failed
821
+ // form's sentence is text.
822
+ const partRole = cn(text({ role: "meta" }), FIGURES);
823
+ const metaNode: ReactNode =
824
+ ended && told[0] !== undefined ? (
825
+ <span
826
+ className={cn(
827
+ partRole,
828
+ oneLine ? "min-w-0 shrink truncate" : META_FREE,
829
+ )}
830
+ >
831
+ <RunText runs={runsOf(told[0])} whole wraps={!oneLine} fit="name" />
832
+ </span>
833
+ ) : coded && !marked ? (
834
+ <span className={cn(partRole, oneLine ? META_CODE : META_FREE)}>
835
+ {oneLine ? (
836
+ <CodeCut code={coded.code} />
837
+ ) : (
838
+ <code className={cn(CODE_NAME, CODE_WHOLE)}>
839
+ <CodeWhole code={coded.code} />
840
+ </code>
841
+ )}
842
+ </span>
843
+ ) : badges.length > 0 ? (
844
+ <BadgesLine
845
+ wrap={!oneLine}
846
+ adapts={adapts}
847
+ className={cn(
848
+ oneLine && BADGES_INLINE,
849
+ wordsWhole && touch && !roomy && BADGES_APART,
850
+ wordsWhole && contained && BADGES_APART_ADAPTS,
851
+ )}
852
+ >
853
+ {badges}
854
+ </BadgesLine>
855
+ ) : null;
856
+ // The line, drawn once, under the title and the badges: the meta ink at the
857
+ // meta role, wrapping whole at every width (a sentence is text, never a
858
+ // badge), a badge's gap below the badges that stand above it. Painted it is
859
+ // one sentence's filler.
860
+ const lineNode: ReactNode = hasLine ? (
861
+ <span
862
+ className={cn(
863
+ partRole,
864
+ LINE_TEXT,
865
+ metaNode !== null && !entry && !listed && LINE_BELOW,
866
+ )}
867
+ >
868
+ {waitsLine || toldLine === undefined ? (
869
+ <Painted role="sentence" at={at} />
870
+ ) : (
871
+ <RunText runs={runsOf(toldLine)} whole wraps fit="name" />
872
+ )}
873
+ </span>
874
+ ) : null;
875
+ // A room row's status, the end group's first item.
876
+ const state =
877
+ stated && status !== undefined ? (
878
+ <span className={cn(STATUS, STATE)}>
879
+ <RowStatusDot status={status} painted={painted} />
880
+ <span className={cn(text({ role: "meta" }), STATE_WORD)}>
881
+ <RowStatusWord status={status} painted={painted} />
882
+ </span>
883
+ </span>
884
+ ) : null;
885
+ // The control of a fact: its switch, in the end group, or the failure mark
886
+ // and the retry in the failed shape.
887
+ const control = ended ? (
888
+ <span className={cn("flex items-center", ROW_END, POINTED)}>
889
+ <FailedMark />
890
+ {failed ? <RetryMark busy={busy} /> : null}
891
+ </span>
892
+ ) : toggle ? (
893
+ <span className={cn(CONTROL, POINTED)}>
894
+ <HeldSwitch
895
+ {...toggle}
896
+ label={painted ? "" : named}
897
+ painted={inert}
898
+ disabled={lock !== undefined}
899
+ />
900
+ </span>
901
+ ) : null;
902
+ const copyAct = ended ? null : waitsTitle && isCopy(shape) ? (
903
+ <IconButtonBase icon="Copy" label="" painted />
904
+ ) : copied === undefined ? null : (
905
+ <CopyAct label={labelText ?? copied} value={copied} />
906
+ );
907
+ const acted = act !== undefined || moreActs || extra.length > 0;
908
+ const acting = acted || copyAct !== null;
909
+ const folding = tree ? treeFold(tree, named, words) : null;
910
+ const hasEnd =
911
+ folding !== null ||
912
+ state !== null ||
913
+ endFacts.length > 0 ||
914
+ trailed !== null ||
915
+ control !== null ||
916
+ pick !== undefined ||
917
+ acting;
918
+ // On touch a row of two lines stands its end group on the title's line and
919
+ // runs its facts line the row's whole width under both (docs/architecture/ui-core/layout.md, "Title and facts"), its
920
+ // leading on the title's line with them; an entry, the steps and a label
921
+ // keep the end group centred on the row.
922
+ const headed =
923
+ touch &&
924
+ twoLined &&
925
+ !labelled &&
926
+ entry === undefined &&
927
+ listed === undefined &&
928
+ hasEnd &&
929
+ titleLine !== null;
930
+ // A tree is one focus stop: docs/architecture/ui-core/layout.md, "Trees".
931
+ const pointed = tree ? -1 : undefined;
932
+ const rove = tree && !tree.tabbable ? (-1 as const) : undefined;
933
+ let hit = null;
934
+ if (failed)
935
+ hit = (
936
+ <BaseButton
937
+ data-hit=""
938
+ aria-label={`${words.retry} ${named}`}
939
+ onClick={() => {
940
+ if (!busy) void retry();
941
+ }}
942
+ className={HIT}
943
+ />
944
+ );
945
+ else if (opens && href !== undefined)
946
+ hit = (
947
+ // biome-ignore lint/a11y/useAnchorContent: the hit covers the row, named by its title
948
+ <a
949
+ data-hit=""
950
+ href={href}
951
+ onClick={follow}
952
+ aria-label={named}
953
+ aria-current={!tree && current ? "page" : undefined}
954
+ tabIndex={pointed}
955
+ className={HIT}
956
+ />
957
+ );
958
+ else if (opens && onOpen)
959
+ hit = (
960
+ <BaseButton
961
+ data-hit=""
962
+ aria-label={named}
963
+ onClick={onOpen}
964
+ aria-current={!tree && current ? "true" : undefined}
965
+ tabIndex={pointed}
966
+ className={HIT}
967
+ />
968
+ );
969
+ // Enter on a tree's row opens what the hit does.
970
+ const openOnEnter = (event: KeyboardEvent<HTMLElement>) => {
971
+ if (event.key !== "Enter" || event.target !== event.currentTarget) return;
972
+ if (href !== undefined) navigate(href);
973
+ else onOpen?.();
974
+ };
975
+ // The press that moves drags the row; Alt with an arrow moves it where it
976
+ // stands, from any control in it (the keyboard's way to the pointer's reorder).
977
+ const onPress = draggable
978
+ ? (event: PointerEvent<HTMLElement>) =>
979
+ press(event, () => ({
980
+ drag: dragged,
981
+ label: named,
982
+ reorder: movable && id !== undefined ? { id, ...movable } : undefined,
983
+ }))
984
+ : undefined;
985
+ const onMoveKey = (event: KeyboardEvent<HTMLElement>) => {
986
+ const step = stepKey(event);
987
+ if (!step || !movable || id === undefined) return;
988
+ const { target } = event;
989
+ if (!(target instanceof HTMLElement)) return;
990
+ if (target.closest("input, textarea, select, [contenteditable]")) return;
991
+ event.preventDefault();
992
+ const to = stepOf(movable.ids(), id, step);
993
+ if (!to) return;
994
+ movable.move(id, to);
995
+ // The row moves in the document and the control loses the focus; it takes
996
+ // it back once the move has rendered, which no event marks.
997
+ queueMicrotask(() => target.focus());
998
+ };
999
+ // A tree's row is a `treeitem` (the WAI-ARIA tree pattern) with its level
1000
+ // and, on a branch, whether it is open; the tree holds one tab stop, so the
1001
+ // rest are focusable by script.
1002
+ const treeItem = tree
1003
+ ? {
1004
+ role: "treeitem",
1005
+ tabIndex: tree.tabbable ? 0 : -1,
1006
+ "aria-level": tree.depth + 1,
1007
+ "aria-setsize": tree.size,
1008
+ "aria-posinset": tree.place,
1009
+ "aria-expanded": tree.fold?.open,
1010
+ "data-key": tree.key,
1011
+ "aria-current": current ? ("page" as const) : undefined,
1012
+ onKeyDown: opens ? openOnEnter : undefined,
1013
+ }
1014
+ : {};
1015
+ const endGroup = hasEnd ? (
1016
+ <span
1017
+ className={cn(
1018
+ ROW_END,
1019
+ END,
1020
+ headed ? HEAD_END : END_SELF,
1021
+ END_LINE,
1022
+ pick === undefined && state === null && END_WHOLE,
1023
+ )}
1024
+ >
1025
+ {state}
1026
+ {endFacts.map((mark) => (
1027
+ <EndMark key={mark.label} mark={mark} />
1028
+ ))}
1029
+ {trailed}
1030
+ {control}
1031
+ {pick ? (
1032
+ <span className={cn(PICK, POINTED)}>
1033
+ <HeldPicker {...pick} fit="row" painted={inert} tabIndex={rove} />
1034
+ </span>
1035
+ ) : null}
1036
+ {acting ? (
1037
+ <span className={cn(ROW_ACTS, ACTS)}>
1038
+ {act ? (
1039
+ painted ? (
1040
+ <PaintedAct at={at} icon />
1041
+ ) : (
1042
+ <RowAct act={act} stand={stand} at={at} />
1043
+ )
1044
+ ) : null}
1045
+ {copyAct}
1046
+ {(more !== undefined && hasMore(more)) || extra.length > 0 ? (
1047
+ painted ? (
1048
+ <MenuBase
1049
+ label={`${words.more} ${named}`}
1050
+ title={named}
1051
+ items={[]}
1052
+ painted
1053
+ />
1054
+ ) : (
1055
+ <RowMore
1056
+ more={more}
1057
+ extra={extra}
1058
+ named={named}
1059
+ tabIndex={rove}
1060
+ />
1061
+ )
1062
+ ) : null}
1063
+ </span>
1064
+ ) : null}
1065
+ {folding ? <span className={cn("flex", POINTED)}>{folding}</span> : null}
1066
+ </span>
1067
+ ) : null;
1068
+ const textNode =
1069
+ titleLine === null &&
1070
+ metaNode === null &&
1071
+ lineNode === null ? null : entry ? (
1072
+ <Field.Root
1073
+ invalid={!painted && Boolean(entry.error)}
1074
+ className={cn(ROW_ENTRY, column)}
1075
+ >
1076
+ {titleLine}
1077
+ {lineNode}
1078
+ <span className={cn(ROW_META_LINE, ENTRY)}>
1079
+ <span className={ENTRY_FIELD}>
1080
+ <HeldInput
1081
+ inline={inline}
1082
+ value={entry.field.value}
1083
+ onChange={entry.field.onChange}
1084
+ onCommit={entry.field.onCommit}
1085
+ placeholder={entry.placeholder}
1086
+ painted={painted}
1087
+ />
1088
+ {entry.error && !painted ? (
1089
+ <Field.Error
1090
+ key={entry.error}
1091
+ match
1092
+ className={cn(FIELD_ERROR_LINE, FLOW_IN)}
1093
+ >
1094
+ {entry.error}
1095
+ </Field.Error>
1096
+ ) : null}
1097
+ </span>
1098
+ <span className={ENTRY_ACT}>
1099
+ <ActButton
1100
+ act={entry.act}
1101
+ host={entryReason.host}
1102
+ painted={painted}
1103
+ at={at}
1104
+ />
1105
+ </span>
1106
+ </span>
1107
+ {entryReason.line}
1108
+ {actLine}
1109
+ {bar}
1110
+ </Field.Root>
1111
+ ) : listed ? (
1112
+ <span className={column}>
1113
+ {titleLine}
1114
+ {lineNode}
1115
+ <span className={cn(ROW_STEPS, STEPS)}>
1116
+ {listed.map((step, index) => (
1117
+ <span
1118
+ key={step.label}
1119
+ className={cn(
1120
+ rowStep({
1121
+ state:
1122
+ !painted && step.tone === "running" ? "running" : "rest",
1123
+ }),
1124
+ STEP,
1125
+ )}
1126
+ >
1127
+ <StatusDot
1128
+ tone={painted ? "done" : step.tone}
1129
+ painted={painted}
1130
+ />
1131
+ <span className={STEP_LABEL}>
1132
+ {painted ? (
1133
+ <Painted role="phrase" at={at + index} />
1134
+ ) : (
1135
+ step.label
1136
+ )}
1137
+ </span>
1138
+ </span>
1139
+ ))}
1140
+ </span>
1141
+ {actLine}
1142
+ {bar}
1143
+ </span>
1144
+ ) : headed ? (
1145
+ <span className={column}>
1146
+ <span className={cn(ROW_TITLE_LINE, HEAD)}>
1147
+ <span
1148
+ className={cn(
1149
+ HEAD_TEXT,
1150
+ ROW_TEXT_FLOOR,
1151
+ roomy ? HEAD_ROOMY : HEAD_WORDS,
1152
+ )}
1153
+ >
1154
+ {titleLine}
1155
+ </span>
1156
+ {endGroup}
1157
+ </span>
1158
+ {metaNode}
1159
+ {lineNode}
1160
+ {actLine}
1161
+ {bar}
1162
+ </span>
1163
+ ) : (
1164
+ <span className={column}>
1165
+ {oneLine && titleLine !== null && metaNode !== null ? (
1166
+ <span className={cn(ROW_INLINE, INLINE, adapts && INLINE_ADAPTS)}>
1167
+ {titleLine}
1168
+ {metaNode}
1169
+ </span>
1170
+ ) : (
1171
+ <>
1172
+ {titleLine}
1173
+ {metaNode}
1174
+ </>
1175
+ )}
1176
+ {lineNode}
1177
+ {actLine}
1178
+ {bar}
1179
+ </span>
1180
+ );
1181
+ const aside = labelled && textNode === null;
1182
+ const body = (
1183
+ <>
1184
+ {tree ? <TreeLead tree={tree} /> : null}
1185
+ {change ? (
1186
+ <First on={onFirst || headed} top={headed && !top}>
1187
+ <ChangeMark kind={change} />
1188
+ </First>
1189
+ ) : null}
1190
+ {leading ? (
1191
+ <First
1192
+ on={onFirst || dotFirst || headed}
1193
+ top={(dotFirst || headed) && !top}
1194
+ >
1195
+ <span
1196
+ className={cn(
1197
+ "tone" in leading ? ROW_LEADING_STATUS : ROW_LEADING,
1198
+ LEADING,
1199
+ ticks && TICK,
1200
+ )}
1201
+ >
1202
+ <Leading
1203
+ leading={leading}
1204
+ named={named}
1205
+ painted={painted}
1206
+ tabIndex={rove}
1207
+ />
1208
+ </span>
1209
+ </First>
1210
+ ) : null}
1211
+ {textNode}
1212
+ {headed ? null : endGroup}
1213
+ </>
1214
+ );
1215
+ return (
1216
+ // biome-ignore lint/a11y/noStaticElementInteractions: the press that moves is a pointer's way to what the row's hit and its menu do by keyboard (Alt with an arrow on the hit, Move up in the menu)
1217
+ <div
1218
+ {...treeItem}
1219
+ {...dropMark}
1220
+ {...(movable && id !== undefined ? { "data-row": id } : {})}
1221
+ onPointerDown={onPress}
1222
+ // The row's link is not dragged by the browser: the press drags the row.
1223
+ onDragStart={draggable ? noDrag : undefined}
1224
+ {...(movable ? { onKeyDown: onMoveKey } : {})}
1225
+ style={rails(tree)}
1226
+ inert={inert || undefined}
1227
+ className={cn(
1228
+ row({ state: current && !child ? "selected" : "rest" }),
1229
+ labelled
1230
+ ? cn(
1231
+ DEFINITION_BOX,
1232
+ STACKED_BOX,
1233
+ ROW_LABELLED,
1234
+ (twoLined || onFirst) && "items-start",
1235
+ aside && ASIDE,
1236
+ )
1237
+ : cn(top ? ROW_WHOLE : ROW, contained && CONTAINED),
1238
+ fades && BLOCK_IN,
1239
+ child
1240
+ ? cn(
1241
+ TREE_WASH,
1242
+ current && TREE_CURRENT,
1243
+ live && (current ? TREE_CHOSEN_PRESS : TREE_PRESS),
1244
+ )
1245
+ : cn(
1246
+ current && ROW_CURRENT_BAR,
1247
+ live && (current ? CHOSEN_PRESS : PRESS_WASH),
1248
+ ),
1249
+ tree && TREE_ITEM,
1250
+ draggable && "touch:select-none",
1251
+ over && DROP_ON,
1252
+ )}
1253
+ >
1254
+ {hit}
1255
+ {labelled ? (
1256
+ <>
1257
+ <span className={cn(DEFINITION_LABEL, aside && ASIDE_LABEL)}>
1258
+ <span
1259
+ className={cn(
1260
+ text({ role: typeof label === "object" ? "code" : "body" }),
1261
+ DEFINITION_NAME,
1262
+ LABEL,
1263
+ )}
1264
+ >
1265
+ {painted ? <Painted role="name" at={at} /> : labelText}
1266
+ </span>
1267
+ </span>
1268
+ <div
1269
+ className={cn(
1270
+ DEFINITION_LINE,
1271
+ LINE,
1272
+ reads && LINE_WRAPS,
1273
+ onFirst ? LINE_FIRST : "items-center",
1274
+ contained && CONTAINED,
1275
+ aside && ASIDE_LINE,
1276
+ )}
1277
+ >
1278
+ {body}
1279
+ </div>
1280
+ </>
1281
+ ) : (
1282
+ body
1283
+ )}
1284
+ </div>
1285
+ );
1286
+ }
1287
+
1288
+ // A tree row hands its tree the depth its hairline starts at (`TREE_DIVIDER`):
1289
+ // the rail of the row under it, a root under it leaving the hairline whole;
1290
+ // and a child its own depth, where its wash starts (`TREE_WASH`).
1291
+ function rails(tree: RowTree | undefined): VarStyle | undefined {
1292
+ if (!tree) return undefined;
1293
+ return {
1294
+ ...(tree.under > 0 && { "--rule-depth": tree.under }),
1295
+ ...(tree.depth > 0 && { "--tree-depth": tree.depth }),
1296
+ };
1297
+ }
1298
+
1299
+ /** What a Section hands the RowItem it draws; no app sets it. */
1300
+ interface RowItemProps {
1301
+ item: RowItemData;
1302
+ /** The item's key, which a tree's keys find the row by. */
1303
+ id: string;
1304
+ /** A painted row's place among the rows, which varies its fillers; a loaded row takes none, its place moving when a row lands above it. */
1305
+ index?: number;
1306
+ painted: boolean;
1307
+ /** In a tree: the row's depth, its fold (`open` on a branch alone, and `fold` hears the item's key) and whether it holds the tab stop. Flat so the memo compares them. */
1308
+ depth?: number;
1309
+ /** In a tree: the depth of the row under it, 0 for none. */
1310
+ under?: number;
1311
+ size?: number;
1312
+ place?: number;
1313
+ open?: boolean;
1314
+ tabbable?: boolean;
1315
+ fold?: (key: string) => void;
1316
+ /** The row arrived on its own after the Section was drawn. */
1317
+ arrived?: boolean;
1318
+ /** The sheet reorders: the order its rows read and move by, and where this row stands in it. */
1319
+ movable?: Movable;
1320
+ edge?: Edge;
1321
+ }
1322
+
1323
+ function RowItemBase({
1324
+ item,
1325
+ id,
1326
+ index,
1327
+ painted,
1328
+ depth,
1329
+ under = 0,
1330
+ size = 1,
1331
+ place = 1,
1332
+ open,
1333
+ tabbable = false,
1334
+ fold,
1335
+ arrived,
1336
+ movable,
1337
+ edge,
1338
+ }: RowItemProps) {
1339
+ const tree: RowTree | undefined =
1340
+ depth === undefined
1341
+ ? undefined
1342
+ : {
1343
+ depth,
1344
+ under,
1345
+ size,
1346
+ place,
1347
+ key: id,
1348
+ fold:
1349
+ open === undefined
1350
+ ? undefined
1351
+ : { open, onToggle: () => fold?.(id) },
1352
+ tabbable,
1353
+ };
1354
+ const { key: _key, ...rest } = item;
1355
+ return (
1356
+ <RowBase
1357
+ {...rest}
1358
+ tree={tree}
1359
+ painted={painted}
1360
+ arrived={arrived}
1361
+ at={index}
1362
+ id={id}
1363
+ movable={movable}
1364
+ edge={edge}
1365
+ />
1366
+ );
1367
+ }
1368
+
1369
+ /** One row of a Section from its item: a refetch that changes one item renders that row alone. */
1370
+ export const RowItem = memo(RowItemBase, sameBy("item", "arrived"));