@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,107 @@
1
+ import { Input as Control } from "@base-ui/react/input";
2
+ import { cn } from "@slotform/ui-core/cn";
3
+ import { wordCount } from "@slotform/ui-core/controls";
4
+ import type { Draft } from "@slotform/ui-core/react/acts";
5
+ import {
6
+ fieldValue,
7
+ TEXT_AREA_VALUE,
8
+ textArea,
9
+ textAreaBudget,
10
+ } from "@slotform/ui-core/variants";
11
+ import { useHeldDraft } from "../../lib/act.ts";
12
+ import { caretAtEnd } from "../../lib/caret.ts";
13
+ import { useCommit } from "../../lib/commit.ts";
14
+ import { BOX_FOCUS, useModality } from "../../lib/modality.ts";
15
+ import { PAINT_CONTROL_HIDDEN } from "../../lib/paint.tsx";
16
+ import { BOX_HOVER } from "./base.tsx";
17
+ import type { ProseProps } from "./index.tsx";
18
+
19
+ // The box draws the field's states, as `Input`'s does.
20
+ const BOX = "flex flex-col";
21
+ const BOX_DISABLED = "bg-fill-disabled";
22
+ const VALUE =
23
+ "block w-full resize-none field-sizing-content outline-none placeholder:text-ink-meta disabled:text-ink-disabled";
24
+ const BUDGET_LINE = "flex justify-end";
25
+ const BUDGET_DISABLED = "text-ink-disabled";
26
+
27
+ /** The field box every prose Input renders, on the `draft` its host holds: a field hosts the draft of its text area and draws a rejection in its own line. It grows with its value from three lines, the budget's count under the value. Outside the package's exports. */
28
+ export function ProseBase({
29
+ draft,
30
+ source,
31
+ onChange,
32
+ onCommit,
33
+ placeholder,
34
+ budget,
35
+ autoFocus,
36
+ }: Omit<ProseProps, "value"> & { draft: Draft<string> }) {
37
+ useModality();
38
+ // A read that ended leaves the box empty and blocked: a keystroke says why
39
+ // and changes nothing.
40
+ const ended = draft.ended;
41
+ const painted = draft.painted && !ended;
42
+ const shown = draft.painted ? "" : draft.value;
43
+ const edit = (next: string) => {
44
+ draft.change(next);
45
+ if (!ended) onChange(next);
46
+ };
47
+ // A commit that returns its save's promise holds the value while it pends.
48
+ const save =
49
+ onCommit && ((next: string) => draft.change(next, () => onCommit(next)));
50
+ const mono = source === true;
51
+ const commit = useCommit(shown, edit, save, false);
52
+ const count = budget === undefined ? undefined : wordCount(shown);
53
+ return (
54
+ <Control
55
+ value={shown}
56
+ onValueChange={edit}
57
+ onFocus={commit.onFocus}
58
+ onBlur={commit.onBlur}
59
+ onKeyDown={commit.onKeyDown}
60
+ autoCapitalize={mono ? "off" : undefined}
61
+ spellCheck={mono ? false : undefined}
62
+ placeholder={placeholder}
63
+ autoFocus={autoFocus}
64
+ ref={autoFocus ? caretAtEnd : undefined}
65
+ // Base UI's Field wires the control: docs/architecture/plugins/react-ui.md, "Field box and focus rings".
66
+ render={(control, state) => (
67
+ <div
68
+ aria-disabled={state.disabled || ended || undefined}
69
+ inert={painted || undefined}
70
+ className={cn(
71
+ textArea({ state: state.valid === false ? "error" : "rest" }),
72
+ BOX,
73
+ BOX_FOCUS,
74
+ state.disabled ? BOX_DISABLED : state.valid !== false && BOX_HOVER,
75
+ painted && PAINT_CONTROL_HIDDEN,
76
+ )}
77
+ >
78
+ <textarea
79
+ {...control}
80
+ className={cn(
81
+ fieldValue({ kind: mono ? "code" : "text" }),
82
+ TEXT_AREA_VALUE,
83
+ VALUE,
84
+ )}
85
+ />
86
+ {count !== undefined && budget !== undefined ? (
87
+ <div className={BUDGET_LINE}>
88
+ <span
89
+ className={cn(
90
+ textAreaBudget({ state: count > budget ? "error" : "rest" }),
91
+ state.disabled && BUDGET_DISABLED,
92
+ )}
93
+ >
94
+ {count} / {budget}
95
+ </span>
96
+ </div>
97
+ ) : null}
98
+ </div>
99
+ )}
100
+ />
101
+ );
102
+ }
103
+
104
+ /** A prose Input that holds its own draft, as a bare one does; a rejection toasts. */
105
+ export function HeldProse({ value, ...rest }: ProseProps) {
106
+ return <ProseBase draft={useHeldDraft(value)} {...rest} />;
107
+ }
@@ -0,0 +1,30 @@
1
+ import { cn } from "@slotform/ui-core/cn";
2
+ import { FIELD_ERROR_LINE, FLOW_IN } from "@slotform/ui-core/variants";
3
+ import { type AriaAttributes, useId, useState } from "react";
4
+
5
+ // What a control refused (a code's check, a file of the wrong type) stands in
6
+ // its own line under it until the next change: the control draws invalid and
7
+ // is described by that line beside its field's own description.
8
+ export function useRefusal() {
9
+ const [refused, refuse] = useState<string>();
10
+ const id = useId();
11
+ const wired = (
12
+ control: Pick<AriaAttributes, "aria-invalid" | "aria-describedby">,
13
+ ) => ({
14
+ "aria-invalid": refused ? true : control["aria-invalid"],
15
+ "aria-describedby": refused
16
+ ? [control["aria-describedby"], id].filter(Boolean).join(" ")
17
+ : control["aria-describedby"],
18
+ });
19
+ const line = refused ? (
20
+ <p
21
+ id={id}
22
+ key={refused}
23
+ role="alert"
24
+ className={cn(FIELD_ERROR_LINE, FLOW_IN)}
25
+ >
26
+ {refused}
27
+ </p>
28
+ ) : null;
29
+ return { refused, refuse, wired, line };
30
+ }
@@ -0,0 +1,410 @@
1
+ import { Button as BaseButton } from "@base-ui/react/button";
2
+ import { cn } from "@slotform/ui-core/cn";
3
+ import type {
4
+ OptionPick,
5
+ RecordFact,
6
+ RowMark,
7
+ Run,
8
+ Runs,
9
+ } from "@slotform/ui-core/descriptors";
10
+ import {
11
+ factKey,
12
+ isChipFact,
13
+ isMarkFact,
14
+ isStatusFact,
15
+ isWarningFact,
16
+ says,
17
+ wordless,
18
+ } from "@slotform/ui-core/list-state";
19
+ import { useArrivals } from "@slotform/ui-core/react/arrive";
20
+ import { useSelections } from "@slotform/ui-core/react/read";
21
+ import { useWords } from "@slotform/ui-core/react/words";
22
+ import { type Datum, type Drawn, paints } from "@slotform/ui-core/read";
23
+ import {
24
+ factParts,
25
+ filled,
26
+ isCode,
27
+ partRuns,
28
+ partText,
29
+ } from "@slotform/ui-core/runs";
30
+ import {
31
+ BADGE_LINE,
32
+ BLOCK_IN,
33
+ FIGURES,
34
+ ITEM_FACT_HIT,
35
+ ITEM_HEADER,
36
+ ITEM_HEADER_PICTURE,
37
+ ITEM_OVERLINE,
38
+ ITEM_PILL,
39
+ ITEM_PILL_ACT,
40
+ ITEM_PILL_GLYPH,
41
+ TITLE_CODE,
42
+ text,
43
+ } from "@slotform/ui-core/variants";
44
+ import { useState } from "react";
45
+ import { Icon } from "../../atoms/icon/index.tsx";
46
+ import {
47
+ Badge,
48
+ ChipBadge,
49
+ MarkBadge,
50
+ StatusBadge,
51
+ WarningBadge,
52
+ WordsBadge,
53
+ } from "../../atoms/row/badges.tsx";
54
+ import { EndMark } from "../../atoms/row/marks.tsx";
55
+ import { RunText } from "../../lib/code.tsx";
56
+ import { useTouch } from "../../lib/media.ts";
57
+ import { follow } from "../../lib/navigate.ts";
58
+ import { Painted } from "../../lib/paint.tsx";
59
+ import { PartsLine, TrailLine } from "../../lib/parts-line.tsx";
60
+ import { Count } from "../count/index.tsx";
61
+ import { PictureTile } from "../image/base.tsx";
62
+ import { HeldPicker } from "../picker/base.tsx";
63
+
64
+ const HEAD = "flex flex-col";
65
+ // The overline is a text line: one line at every density, cut at its end with
66
+ // an ellipsis, its parts a middle dot apart (`PartsLine`), on touch as
67
+ // on the desktop, its figures tabular (`ITEM_OVERLINE`). On touch the trail
68
+ // leads it, cut at its own start (`TrailLine`).
69
+ const OVERLINE = "truncate";
70
+ // The name draws whole: it wraps between its words.
71
+ const NAME = "min-w-0";
72
+ // A quiet fact (a mark with no words) stands at the end of the name's first
73
+ // line, as a row's stands in its end group: the name's row is a flex row of the
74
+ // name and the glyphs, each glyph in a box of the name's line height so it
75
+ // stays on the first line of a wrapped name, and it takes no line of the
76
+ // facts, whatever the facts hold.
77
+ const NAME_ROW = "flex items-start gap-gap";
78
+ const ASIDE = "flex items-center shrink-0 h-lh";
79
+ // The record name's view timeline: docs/architecture/ui-core/layout.md, "Record head".
80
+ const NAME_TIMELINE = "record-name";
81
+ const FACTS = "flex flex-wrap items-center";
82
+ const DESCRIPTION = "max-w-measure";
83
+ // A head with a picture is a row of the tile and the text column, which takes the rest.
84
+ const PICTURED = "flex items-start";
85
+ const COLUMN = "min-w-0 grow";
86
+ // A fact is a badge (`Badge`), one box that never breaks inside, a gap apart
87
+ // on the line (`BADGE_LINE`). A fact that acts keeps its own control: a pick is
88
+ // its picker's pill, and a fact that opens a sheet is the outlined pill with its
89
+ // chevron, so nothing outlined in the head is inert. A fact that links is a
90
+ // badge whose words are underlined, inside the hit box (`ITEM_FACT_HIT`) the
91
+ // target floor needs, the badge inside it carrying the washes. The pill and
92
+ // the hit box around it are one inline box.
93
+ const PILL = "inline-flex items-center min-w-0 max-w-full";
94
+ const WORDS = cn("truncate", FIGURES);
95
+ // A pick is its own control and its own pill (the picker's `fact` fit): one box,
96
+ // the state pill itself where the chosen option carries a state, never a pill
97
+ // inside a pill.
98
+ const PICK = "inline-flex min-w-0 max-w-full";
99
+
100
+ /** What a record's head holds besides its name: the parts that place the record and its facts. */
101
+ export interface ItemHeaderParts<V extends string | null = string> {
102
+ /** The parts that place the record (its project, key, cycle), a text line, not badges, joined by a middle dot (each a short phrase, a dot inside one no more than its text; one line, cut at its end with an ellipsis on touch as on the desktop). A part that is a selection paints, and the head is inert, until its read lands. */
103
+ overline?: readonly Datum<Run>[];
104
+ /** The facts in a wrapping line of badges under the overline, each one fact (`RecordFact`: words, a status, a chip, what is wrong as `{ warning }`, a boolean mark, words that go to a route (a linked badge), words that open a sheet (an outlined pill with its chevron, since it acts), a status that moves as a pick whose options carry states (its own control pill), a count beside its word; a boolean mark with `words: false` is its glyph alone, named by the label and, on a pointer, its tooltip, standing at the end of the name's first line, so a quiet fact such as where the content came from takes no width and no line of the facts) (each string a short phrase; the facts line wraps between badges, none breaking inside, a fact too long for the line cut with an ellipsis inside its badge, a `{ quoted }` part whole, cut by its badge, a `{ code }` run in the mono). A status is a badge with its tone's mark inside, before its word. A fact that is a selection paints in its place (a status or a pick keeps its form, any other is a badge's filler), and the head is inert, until its read lands. */
105
+ facts?: readonly Datum<RecordFact<V>>[];
106
+ /** The record's description, under the facts at the reading measure (a sentence or a short paragraph; wraps): plain text, or runs of one text, so a machine name inside it is a `{ code }` run boxed in the mono (`["The server at ", { code: "10.0.0.4:8790" }, " lists routes that differ."]`). A selection paints a line in its place, and the head is inert, until its read lands; absent or empty, nothing is drawn. */
107
+ description?: Datum<Run | Runs>;
108
+ /** A picture of the record (a person's photo, a product shot), a square tile beside the head's text, at its top: painted while its `src` is a selection still to land, a skeleton while the bytes come, an `ImageOff` glyph in the meta ink where it failed or the address is empty (the `alt` its tooltip). `alt` says what it shows. */
109
+ image?: { src: Datum<string>; alt: string };
110
+ }
111
+
112
+ // A fact is a block of the line, fading in if it came on its own once the
113
+ // header was drawn, held from the first render. A status is the Status's own.
114
+ function FactPart<V extends string | null>({
115
+ fact,
116
+ arrived,
117
+ }: {
118
+ fact: RecordFact<V>;
119
+ arrived: boolean;
120
+ }) {
121
+ const [fades] = useState(arrived);
122
+ // A fact that goes to a route is a linked badge: its words underlined, in the
123
+ // hit box that gives it the target's size.
124
+ if (typeof fact === "object" && "href" in fact)
125
+ return (
126
+ <a
127
+ href={fact.href}
128
+ onClick={follow}
129
+ className={cn(ITEM_FACT_HIT, PILL, fades && BLOCK_IN)}
130
+ >
131
+ <Badge hit>
132
+ <RunText runs={partRuns(fact.label)} fit="name" />
133
+ </Badge>
134
+ </a>
135
+ );
136
+ if (typeof fact === "object" && "onOpen" in fact)
137
+ return (
138
+ <BaseButton
139
+ onClick={fact.onOpen}
140
+ aria-haspopup="dialog"
141
+ className={cn(ITEM_FACT_HIT, PILL, fades && BLOCK_IN)}
142
+ >
143
+ <OpenPill label={fact.label} />
144
+ </BaseButton>
145
+ );
146
+ return (
147
+ <span className={cn(PICK, fades && BLOCK_IN)}>
148
+ <FactBadge fact={fact} />
149
+ </span>
150
+ );
151
+ }
152
+
153
+ // A fact that neither links nor opens: its own box on the line.
154
+ function FactBadge<V extends string | null>({ fact }: { fact: RecordFact<V> }) {
155
+ if (typeof fact === "object" && "pick" in fact)
156
+ return <HeldPicker {...fact.pick} fit="fact" />;
157
+ // A status is a badge: its tone's mark inside, then its word, the tone's
158
+ // where it brings none.
159
+ if (isStatusFact(fact)) return <StatusBadge status={fact} />;
160
+ // What is wrong: the warn glyph and its phrase, a badge.
161
+ if (isWarningFact(fact)) return <WarningBadge warning={fact.warning} />;
162
+ // A data value's tag: the family's dot (none for neutral) and its value.
163
+ if (isChipFact(fact)) return <ChipBadge chip={fact} />;
164
+ // A count is a badge: its word and its figure.
165
+ if (typeof fact === "object" && "count" in fact)
166
+ return (
167
+ <Badge>
168
+ {fact.label} <Count value={fact.count} />
169
+ </Badge>
170
+ );
171
+ if (isMarkFact(fact))
172
+ return wordless(fact) ? (
173
+ <Badge glyph={<EndMark mark={fact} />} />
174
+ ) : (
175
+ <MarkBadge mark={fact} />
176
+ );
177
+ // Every other kind of fact is told apart above: what is left is words.
178
+ return <WordsBadge fact={fact as Run} />;
179
+ }
180
+
181
+ // A quiet fact beside the name: the glyph alone, fading in if it came on its
182
+ // own once the header was drawn, held from the first render.
183
+ function AsideMark({ mark, arrived }: { mark: RowMark; arrived: boolean }) {
184
+ const [fades] = useState(arrived);
185
+ return (
186
+ <span className={cn(fades && BLOCK_IN)}>
187
+ <EndMark mark={mark} />
188
+ </span>
189
+ );
190
+ }
191
+
192
+ // The pill of a fact that opens or links: its words, then a chevron at its end;
193
+ // the hover wash and the ring are the pill's, the hit box around it the caller's.
194
+ function OpenPill({ label }: { label: Run }) {
195
+ return (
196
+ <span
197
+ className={cn(text({ role: "caption" }), ITEM_PILL, ITEM_PILL_ACT, PILL)}
198
+ >
199
+ <span className={WORDS}>
200
+ <RunText runs={partRuns(label)} fit="name" />
201
+ </span>
202
+ <span className={ITEM_PILL_GLYPH}>
203
+ <Icon name="ChevronRight" fit="meta" />
204
+ </span>
205
+ </span>
206
+ );
207
+ }
208
+
209
+ // A fact that is not here, in the form its selection's shape says: the
210
+ // stand-in is no object, so a selection that gives the fact whole paints as
211
+ // a word.
212
+ function PaintedFact({ fact, at }: { fact: unknown; at: number }) {
213
+ if (isStatusFact(fact))
214
+ return (
215
+ <span className={PICK}>
216
+ <StatusBadge status={fact} painted />
217
+ </span>
218
+ );
219
+ // A painted fact is its selection's sample, whose `pick` is the shape the
220
+ // selector gives the fact.
221
+ if (typeof fact === "object" && fact !== null && "pick" in fact)
222
+ return (
223
+ <span className={PICK}>
224
+ <HeldPicker {...(fact.pick as OptionPick)} fit="fact" painted />
225
+ </span>
226
+ );
227
+ return (
228
+ <span className={PICK}>
229
+ <Badge painted paint={{ role: "word", at }} />
230
+ </span>
231
+ );
232
+ }
233
+
234
+ // A record's name draws none where its read ended or it landed empty: the
235
+ // page's shape says why, and an empty heading would only be one for a screen
236
+ // reader to land on.
237
+ export function drawsNoName(name: Drawn<Run>): boolean {
238
+ return name.painted ? !paints(name) : partText(name.value) === "";
239
+ }
240
+
241
+ /** A record's head: its place (the overline, led on touch by the trail of places the record lives in, which the bar holds on the desktop), its name and its facts, a pair apart; the bar holds the acts, so the head holds none. The name is the Pane's title, drawn whole and wrapping as the `h2` that names the Pane, its filler inside it while its read waits; a name that draws none leaves the head the overline and the facts. A name, a part or a fact that is a selection paints in its place, and the facts take no press, until its read lands. Outside the package's exports: a Pane draws it for its `record`. */
242
+ export function ItemHeaderBase<V extends string | null = string>({
243
+ name: title,
244
+ nameId,
245
+ trail = [],
246
+ overline: given = [],
247
+ facts = [],
248
+ description,
249
+ image,
250
+ }: ItemHeaderParts<V> & {
251
+ /** The labels of the places the record lives in, the nearest last: on touch, where the bar holds the name alone, they lead the overline, so the trail stands once at every density. */
252
+ trail?: readonly string[];
253
+ /** The record's name: the Pane's title. */
254
+ name: Datum<Run>;
255
+ /** The id the name carries, which names the Pane. */
256
+ nameId?: string;
257
+ }) {
258
+ const [name] = useSelections([title]);
259
+ // On touch the bar drops the trail for the name, so the overline leads with
260
+ // it; a name whose read ended leaves the trail in the bar.
261
+ const touch = useTouch();
262
+ const named = !drawsNoName(name);
263
+ const led = touch && named && trail.length > 0;
264
+ // One subscription draws the overline's parts, then the facts, so every
265
+ // value types as the union of both: the casts name the slice's own, a
266
+ // `Run` in the overline's and a `RecordFact` in the facts'.
267
+ const drawn = useSelections([...given, ...facts]);
268
+ const [about] = useSelections([description]);
269
+ // A part or a fact whose read ended draws nothing; the frame that holds the
270
+ // read says why.
271
+ const draws = (each: (typeof drawn)[number]) => !each.painted || paints(each);
272
+ // A loaded part with no text draws nothing, so no separator dangles after
273
+ // the part before it.
274
+ const placed = drawn
275
+ .slice(0, given.length)
276
+ .filter(
277
+ (each) => draws(each) && (each.painted || filled(each.value as Run)),
278
+ );
279
+ // An absent fact (a loaded part with no text) draws nothing: absence says
280
+ // nothing.
281
+ const stood = drawn
282
+ .slice(given.length)
283
+ .filter(
284
+ (each) =>
285
+ draws(each) &&
286
+ (each.painted ||
287
+ typeof each.value !== "string" ||
288
+ filled(each.value as Run)) &&
289
+ (each.painted || !isMarkFact(each.value) || says(each.value)),
290
+ );
291
+ const painted = drawn.some(paints) || paints(name) || paints(about);
292
+ // A quiet fact stands beside the name where the head draws one; a head with
293
+ // no name keeps it in the facts line.
294
+ const aside = (each: (typeof stood)[number]) =>
295
+ named && !each.painted && isMarkFact(each.value) && wordless(each.value);
296
+ // A filter keeps no narrowing: `quiet` holds marks alone (`aside`).
297
+ const quiet = stood.filter(aside);
298
+ const line = stood.filter((each) => !aside(each));
299
+ const arrived = useArrivals(
300
+ stood.flatMap((fact) =>
301
+ fact.painted ? [] : [factKey(fact.value as RecordFact<V>)],
302
+ ),
303
+ !painted,
304
+ );
305
+ // The name is the Pane's heading in every form it draws: a waiting name
306
+ // paints inside it, named by the waiting word since its filler is hidden,
307
+ // so the page keeps its heading while the record loads.
308
+ const words = useWords();
309
+ const heading = named ? (
310
+ <h2
311
+ id={nameId}
312
+ aria-label={name.painted ? words.waiting : undefined}
313
+ className={cn(
314
+ text({ role: "title" }),
315
+ NAME,
316
+ NAME_TIMELINE,
317
+ quiet.length > 0 && "grow",
318
+ )}
319
+ >
320
+ {name.painted ? (
321
+ <Painted role="title" />
322
+ ) : isCode(name.value) ? (
323
+ <code className={TITLE_CODE}>{name.value.code}</code>
324
+ ) : (
325
+ <RunText runs={partRuns(name.value)} wraps fit="name" />
326
+ )}
327
+ </h2>
328
+ ) : null;
329
+ const parts =
330
+ placed.length > 0 ? (
331
+ <PartsLine
332
+ parts={placed.flatMap((part, at) =>
333
+ part.painted
334
+ ? [<Painted key={at} role="word" at={at} />]
335
+ : // A part is one part, a dot inside its string text: every
336
+ // separator is the line's.
337
+ factParts([part.value as Run]).map((runs, within) => (
338
+ <RunText key={`${at}.${within}`} runs={runs} fit="name" />
339
+ )),
340
+ )}
341
+ />
342
+ ) : null;
343
+ const column = (
344
+ <div className={cn(ITEM_HEADER, HEAD, image && COLUMN)}>
345
+ {led ? (
346
+ <TrailLine trail={trail} className={ITEM_OVERLINE}>
347
+ {parts}
348
+ </TrailLine>
349
+ ) : parts ? (
350
+ <p className={cn(ITEM_OVERLINE, OVERLINE)}>{parts}</p>
351
+ ) : null}
352
+ {quiet.length > 0 ? (
353
+ <div className={NAME_ROW}>
354
+ {heading}
355
+ <span className={cn(text({ role: "title" }), ASIDE)}>
356
+ {quiet.map((fact) => (
357
+ <AsideMark
358
+ key={factKey(fact.value as RecordFact<V>)}
359
+ mark={fact.value as RowMark}
360
+ arrived={arrived.has(factKey(fact.value as RecordFact<V>))}
361
+ />
362
+ ))}
363
+ </span>
364
+ </div>
365
+ ) : (
366
+ heading
367
+ )}
368
+ {line.length > 0 ? (
369
+ // Only the facts take a press: none does until the head lands.
370
+ <div inert={painted || undefined} className={cn(BADGE_LINE, FACTS)}>
371
+ {line.map((fact, at) =>
372
+ fact.painted ? (
373
+ <PaintedFact key={at} fact={fact.value} at={at} />
374
+ ) : (
375
+ <FactPart
376
+ key={factKey(fact.value as RecordFact<V>)}
377
+ fact={fact.value as RecordFact<V>}
378
+ arrived={arrived.has(factKey(fact.value as RecordFact<V>))}
379
+ />
380
+ ),
381
+ )}
382
+ </div>
383
+ ) : null}
384
+ {paints(about) ? (
385
+ <p className={cn(text({ role: "body" }), DESCRIPTION)}>
386
+ <Painted role="sentence" />
387
+ </p>
388
+ ) : !about.painted &&
389
+ about.value !== undefined &&
390
+ partText(about.value) !== "" ? (
391
+ <p className={cn(text({ role: "body" }), DESCRIPTION)}>
392
+ <RunText runs={partRuns(about.value)} whole />
393
+ </p>
394
+ ) : null}
395
+ </div>
396
+ );
397
+ return image === undefined ? (
398
+ column
399
+ ) : (
400
+ <div className={cn(ITEM_HEADER_PICTURE, PICTURED)}>
401
+ <PictureTile
402
+ src={image.src}
403
+ alt={image.alt}
404
+ fit="thumb"
405
+ box={undefined}
406
+ />
407
+ {column}
408
+ </div>
409
+ );
410
+ }