@slashsuite/ui-react 0.12.1 → 0.13.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (385) hide show
  1. package/MIGRATING.md +386 -8
  2. package/README.md +89 -44
  3. package/agent-docs/components/app-shell.md +9 -6
  4. package/agent-docs/components/article-layout.md +140 -0
  5. package/agent-docs/components/audio.md +42 -0
  6. package/agent-docs/components/badge.md +2 -1
  7. package/agent-docs/components/body-text.md +26 -15
  8. package/agent-docs/components/bottom-sheet.md +27 -17
  9. package/agent-docs/components/breadcrumbs.md +10 -6
  10. package/agent-docs/components/button.md +2 -2
  11. package/agent-docs/components/call-to-action.md +59 -0
  12. package/agent-docs/components/callout.md +4 -3
  13. package/agent-docs/components/card-grid.md +15 -7
  14. package/agent-docs/components/card.md +33 -18
  15. package/agent-docs/components/cart-button.md +63 -0
  16. package/agent-docs/components/chat-composer.md +4 -3
  17. package/agent-docs/components/checkbox.md +11 -5
  18. package/agent-docs/components/cluster.md +10 -8
  19. package/agent-docs/components/code-example.md +2 -2
  20. package/agent-docs/components/code.md +7 -5
  21. package/agent-docs/components/colour-scheme-toggle.md +12 -6
  22. package/agent-docs/components/colour-swatch.md +41 -0
  23. package/agent-docs/components/combobox.md +88 -0
  24. package/agent-docs/components/confirm-dialog.md +98 -0
  25. package/agent-docs/components/container.md +2 -1
  26. package/agent-docs/components/copy-button.md +7 -5
  27. package/agent-docs/components/copy-line.md +6 -5
  28. package/agent-docs/components/date-field.md +14 -11
  29. package/agent-docs/components/date-range-picker.md +16 -9
  30. package/agent-docs/components/date-time-field.md +73 -0
  31. package/agent-docs/components/dialog.md +22 -68
  32. package/agent-docs/components/disclosure.md +4 -0
  33. package/agent-docs/components/docs-layout.md +10 -6
  34. package/agent-docs/components/drawer.md +13 -4
  35. package/agent-docs/components/embed-frame.md +48 -0
  36. package/agent-docs/components/empty-state.md +4 -1
  37. package/agent-docs/components/field-dialog.md +6 -5
  38. package/agent-docs/components/field.md +10 -7
  39. package/agent-docs/components/fieldset.md +4 -4
  40. package/agent-docs/components/flow-diagram.md +87 -0
  41. package/agent-docs/components/form-layout.md +4 -1
  42. package/agent-docs/components/form-row.md +7 -7
  43. package/agent-docs/components/full-bleed-layout.md +0 -2
  44. package/agent-docs/components/headings.md +13 -7
  45. package/agent-docs/components/hero.md +11 -2
  46. package/agent-docs/components/icon-button.md +1 -3
  47. package/agent-docs/components/icon.md +6 -13
  48. package/agent-docs/components/image.md +24 -14
  49. package/agent-docs/components/input.md +8 -7
  50. package/agent-docs/components/key-value-list.md +4 -1
  51. package/agent-docs/components/lightbox.md +1 -1
  52. package/agent-docs/components/list-layout.md +5 -7
  53. package/agent-docs/components/list-row.md +37 -34
  54. package/agent-docs/components/loading.md +2 -2
  55. package/agent-docs/components/markdown.md +13 -13
  56. package/agent-docs/components/media-tile.md +8 -4
  57. package/agent-docs/components/menu.md +19 -12
  58. package/agent-docs/components/meta-list.md +2 -2
  59. package/agent-docs/components/morph.md +11 -5
  60. package/agent-docs/components/navigation-progress.md +2 -2
  61. package/agent-docs/components/number-field.md +75 -0
  62. package/agent-docs/components/outline-region.md +19 -8
  63. package/agent-docs/components/page-fade.md +2 -1
  64. package/agent-docs/components/pill.md +7 -6
  65. package/agent-docs/components/popover.md +63 -0
  66. package/agent-docs/components/price.md +49 -0
  67. package/agent-docs/components/product-tile.md +78 -0
  68. package/agent-docs/components/promo-banner.md +46 -0
  69. package/agent-docs/components/prose-layout.md +1 -1
  70. package/agent-docs/components/radio-group.md +9 -6
  71. package/agent-docs/components/scroll-strip.md +3 -3
  72. package/agent-docs/components/segmented-control.md +4 -2
  73. package/agent-docs/components/select.md +8 -3
  74. package/agent-docs/components/show.md +2 -2
  75. package/agent-docs/components/side-column.md +13 -9
  76. package/agent-docs/components/sidebar-layout.md +1 -1
  77. package/agent-docs/components/site-footer.md +4 -4
  78. package/agent-docs/components/site-search.md +21 -9
  79. package/agent-docs/components/slider.md +59 -0
  80. package/agent-docs/components/sortable-list.md +15 -10
  81. package/agent-docs/components/stack.md +3 -3
  82. package/agent-docs/components/stacked-bar.md +7 -4
  83. package/agent-docs/components/state-machine.md +95 -0
  84. package/agent-docs/components/status-pages.md +13 -6
  85. package/agent-docs/components/stepper.md +54 -0
  86. package/agent-docs/components/switch.md +4 -4
  87. package/agent-docs/components/table-of-contents.md +78 -0
  88. package/agent-docs/components/table.md +35 -24
  89. package/agent-docs/components/tabs.md +24 -26
  90. package/agent-docs/components/text-link.md +12 -7
  91. package/agent-docs/components/textarea.md +4 -2
  92. package/agent-docs/components/toast.md +19 -14
  93. package/agent-docs/components/video.md +7 -2
  94. package/agent-docs/llms.txt +22 -3
  95. package/dist/AppShell.d.ts +25 -9
  96. package/dist/AppShell.js +67 -33
  97. package/dist/AppShellMenu.d.ts +31 -18
  98. package/dist/AppShellMenu.js +72 -45
  99. package/dist/ArticleLayout.d.ts +36 -0
  100. package/dist/ArticleLayout.js +27 -0
  101. package/dist/Audio.d.ts +16 -0
  102. package/dist/Audio.js +11 -0
  103. package/dist/Badge.d.ts +2 -1
  104. package/dist/Badge.js +3 -2
  105. package/dist/BottomSheet.d.ts +17 -6
  106. package/dist/BottomSheet.js +62 -11
  107. package/dist/Breadcrumbs.d.ts +8 -6
  108. package/dist/Breadcrumbs.js +17 -7
  109. package/dist/Button.d.ts +4 -2
  110. package/dist/Button.js +9 -87
  111. package/dist/CallToAction.d.ts +25 -0
  112. package/dist/CallToAction.js +17 -0
  113. package/dist/Callout.d.ts +2 -2
  114. package/dist/Callout.js +2 -2
  115. package/dist/Card.d.ts +88 -31
  116. package/dist/Card.js +55 -92
  117. package/dist/CardBody.d.ts +2 -0
  118. package/dist/CardBody.js +33 -3
  119. package/dist/CardGrid.d.ts +32 -4
  120. package/dist/CardGrid.js +42 -8
  121. package/dist/CardParts.d.ts +7 -1
  122. package/dist/CardParts.js +7 -2
  123. package/dist/CartButton.d.ts +33 -0
  124. package/dist/CartButton.js +18 -0
  125. package/dist/ChatComposer.d.ts +10 -4
  126. package/dist/ChatComposer.js +35 -13
  127. package/dist/Checkbox.d.ts +21 -3
  128. package/dist/Checkbox.js +66 -20
  129. package/dist/Chevron.js +1 -1
  130. package/dist/Cluster.d.ts +28 -15
  131. package/dist/Cluster.js +21 -4
  132. package/dist/Code.d.ts +15 -3
  133. package/dist/Code.js +23 -3
  134. package/dist/CodeBlock.d.ts +4 -4
  135. package/dist/CodeBlock.js +2 -2
  136. package/dist/CodeBody.d.ts +1 -1
  137. package/dist/CodeBody.js +4 -10
  138. package/dist/CodeExample.d.ts +1 -1
  139. package/dist/CodeExample.js +3 -2
  140. package/dist/ColourSchemeToggle.d.ts +21 -5
  141. package/dist/ColourSchemeToggle.js +15 -9
  142. package/dist/ColourSwatch.d.ts +15 -0
  143. package/dist/ColourSwatch.js +14 -0
  144. package/dist/Combobox.d.ts +42 -0
  145. package/dist/Combobox.js +43 -0
  146. package/dist/ConfirmDialog.d.ts +40 -0
  147. package/dist/ConfirmDialog.js +36 -0
  148. package/dist/Container.d.ts +3 -3
  149. package/dist/Container.js +1 -1
  150. package/dist/CopyButton.d.ts +8 -2
  151. package/dist/CopyButton.js +38 -28
  152. package/dist/CopyLine.d.ts +4 -2
  153. package/dist/CopyLine.js +4 -4
  154. package/dist/DateCalendar.d.ts +2 -0
  155. package/dist/DateCalendar.js +11 -9
  156. package/dist/DateField.d.ts +52 -21
  157. package/dist/DateField.js +73 -37
  158. package/dist/DateFieldCalendar.d.ts +12 -8
  159. package/dist/DateFieldCalendar.js +37 -18
  160. package/dist/DateRangePicker.d.ts +23 -3
  161. package/dist/DateRangePicker.js +10 -8
  162. package/dist/DateTimeField.d.ts +31 -0
  163. package/dist/DateTimeField.js +19 -0
  164. package/dist/Dialog.d.ts +42 -6
  165. package/dist/Dialog.js +50 -12
  166. package/dist/Disclosure.js +9 -1
  167. package/dist/DocsLayout.d.ts +13 -5
  168. package/dist/DocsLayout.js +11 -9
  169. package/dist/Drawer.d.ts +22 -7
  170. package/dist/Drawer.js +89 -8
  171. package/dist/EmbedFrame.d.ts +36 -0
  172. package/dist/EmbedFrame.js +18 -0
  173. package/dist/Field.d.ts +41 -4
  174. package/dist/Field.js +61 -25
  175. package/dist/FieldDialog.d.ts +8 -3
  176. package/dist/FieldDialog.js +19 -9
  177. package/dist/Fieldset.d.ts +3 -3
  178. package/dist/Fieldset.js +7 -9
  179. package/dist/FileDrop.js +2 -1
  180. package/dist/FlowDiagram.d.ts +92 -0
  181. package/dist/FlowDiagram.js +100 -0
  182. package/dist/FormRow.d.ts +6 -4
  183. package/dist/FormRow.js +11 -9
  184. package/dist/Hero.d.ts +30 -7
  185. package/dist/Hero.js +23 -9
  186. package/dist/Icon.d.ts +1 -1
  187. package/dist/Icon.js +1 -1
  188. package/dist/IconButton.js +1 -1
  189. package/dist/Image.d.ts +33 -9
  190. package/dist/Image.js +61 -16
  191. package/dist/Input.d.ts +1 -1
  192. package/dist/Input.js +4 -4
  193. package/dist/InputShell.d.ts +7 -0
  194. package/dist/InputShell.js +18 -3
  195. package/dist/KeyValueList.d.ts +2 -2
  196. package/dist/Lightbox.js +5 -3
  197. package/dist/ListRow.d.ts +4 -5
  198. package/dist/ListRow.js +36 -26
  199. package/dist/Mark.d.ts +10 -0
  200. package/dist/Mark.js +9 -0
  201. package/dist/Markdown.d.ts +18 -4
  202. package/dist/Markdown.js +176 -37
  203. package/dist/MediaTile.d.ts +9 -3
  204. package/dist/MediaTile.js +8 -4
  205. package/dist/Menu.d.ts +19 -8
  206. package/dist/Menu.js +13 -11
  207. package/dist/MetaList.d.ts +4 -3
  208. package/dist/MetaList.js +12 -4
  209. package/dist/Morph.d.ts +15 -1
  210. package/dist/Morph.js +70 -22
  211. package/dist/NavigationProgress.d.ts +2 -2
  212. package/dist/NavigationProgress.js +7 -5
  213. package/dist/NumberField.d.ts +66 -0
  214. package/dist/NumberField.js +68 -0
  215. package/dist/OutlineRegion.d.ts +41 -10
  216. package/dist/OutlineRegion.js +31 -6
  217. package/dist/PageFade.d.ts +9 -5
  218. package/dist/PageFade.js +39 -8
  219. package/dist/PageLayouts.d.ts +15 -5
  220. package/dist/PageLayouts.js +3 -3
  221. package/dist/Pill.d.ts +9 -4
  222. package/dist/Pill.js +15 -6
  223. package/dist/Popover.d.ts +31 -0
  224. package/dist/Popover.js +43 -0
  225. package/dist/Price.d.ts +21 -0
  226. package/dist/Price.js +34 -0
  227. package/dist/ProductTile.d.ts +36 -0
  228. package/dist/ProductTile.js +31 -0
  229. package/dist/ProgressBar.js +4 -2
  230. package/dist/PromoBanner.d.ts +25 -0
  231. package/dist/PromoBanner.js +16 -0
  232. package/dist/RadioGroup.d.ts +18 -8
  233. package/dist/RadioGroup.js +42 -18
  234. package/dist/ScrollStrip.d.ts +1 -1
  235. package/dist/ScrollStrip.js +1 -1
  236. package/dist/SearchInput.d.ts +17 -2
  237. package/dist/SearchInput.js +72 -13
  238. package/dist/SegmentedField.d.ts +15 -0
  239. package/dist/SegmentedField.js +15 -0
  240. package/dist/Select.js +5 -4
  241. package/dist/Show.d.ts +1 -1
  242. package/dist/Show.js +1 -1
  243. package/dist/SideColumn.d.ts +42 -15
  244. package/dist/SideColumn.js +45 -19
  245. package/dist/SiteFooter.d.ts +3 -3
  246. package/dist/SiteFooter.js +4 -3
  247. package/dist/SiteSearch.d.ts +57 -27
  248. package/dist/SiteSearch.js +13 -93
  249. package/dist/Slider.d.ts +27 -0
  250. package/dist/Slider.js +58 -0
  251. package/dist/SortableList.d.ts +19 -35
  252. package/dist/SortableList.js +36 -88
  253. package/dist/Stack.d.ts +4 -4
  254. package/dist/StackedBar.d.ts +13 -4
  255. package/dist/StackedBar.js +12 -7
  256. package/dist/StateMachine.d.ts +65 -0
  257. package/dist/StateMachine.js +116 -0
  258. package/dist/StatusPages.d.ts +28 -10
  259. package/dist/StatusPages.js +10 -10
  260. package/dist/Stepper.d.ts +21 -0
  261. package/dist/Stepper.js +33 -0
  262. package/dist/Steps.js +4 -3
  263. package/dist/Switch.d.ts +3 -3
  264. package/dist/Switch.js +18 -14
  265. package/dist/Table.d.ts +32 -9
  266. package/dist/Table.js +50 -20
  267. package/dist/TableCells.d.ts +24 -21
  268. package/dist/TableCells.js +68 -27
  269. package/dist/TableEditCell.d.ts +1 -1
  270. package/dist/TableOfContents.d.ts +34 -0
  271. package/dist/TableOfContents.js +23 -0
  272. package/dist/Tabs.d.ts +31 -16
  273. package/dist/Tabs.js +97 -22
  274. package/dist/TextLink.d.ts +18 -5
  275. package/dist/TextLink.js +19 -6
  276. package/dist/Textarea.d.ts +12 -1
  277. package/dist/Textarea.js +15 -2
  278. package/dist/ToastRegion.d.ts +17 -9
  279. package/dist/ToastRegion.js +70 -13
  280. package/dist/Tooltip.d.ts +10 -2
  281. package/dist/Tooltip.js +32 -11
  282. package/dist/Video.d.ts +19 -4
  283. package/dist/Video.js +15 -5
  284. package/dist/cardContext.d.ts +7 -0
  285. package/dist/cardContext.js +14 -0
  286. package/dist/cardControl.d.ts +15 -0
  287. package/dist/cardControl.js +32 -0
  288. package/dist/cardForm.d.ts +39 -0
  289. package/dist/cardForm.js +81 -0
  290. package/dist/cardWait.js +2 -1
  291. package/dist/colourScheme.d.ts +12 -2
  292. package/dist/colourScheme.js +32 -6
  293. package/dist/control.d.ts +30 -8
  294. package/dist/control.js +74 -7
  295. package/dist/copyScript.d.ts +7 -8
  296. package/dist/copyScript.js +8 -9
  297. package/dist/core/button.d.ts +33 -0
  298. package/dist/core/button.js +89 -0
  299. package/dist/core/control.d.ts +15 -0
  300. package/dist/core/control.js +14 -0
  301. package/dist/core/fixtures/button.d.ts +26 -0
  302. package/dist/core/fixtures/button.js +52 -0
  303. package/dist/core/fixtures/types.d.ts +13 -0
  304. package/dist/core/fixtures/types.js +10 -0
  305. package/dist/core/focus.d.ts +7 -0
  306. package/dist/core/focus.js +7 -0
  307. package/dist/core/index.d.ts +12 -0
  308. package/dist/core/index.js +12 -0
  309. package/dist/core/parity.d.ts +22 -0
  310. package/dist/core/parity.js +53 -0
  311. package/dist/core/themeNative.d.ts +62 -0
  312. package/dist/core/themeNative.js +290 -0
  313. package/dist/cx.d.ts +17 -5
  314. package/dist/cx.js +18 -5
  315. package/dist/dateLocale.d.ts +17 -0
  316. package/dist/dateLocale.js +30 -0
  317. package/dist/density.d.ts +17 -3
  318. package/dist/density.js +30 -19
  319. package/dist/emptySlot.d.ts +1 -0
  320. package/dist/fieldAnnounce.d.ts +11 -0
  321. package/dist/fieldAnnounce.js +36 -0
  322. package/dist/fieldControl.d.ts +7 -2
  323. package/dist/fieldControl.js +6 -2
  324. package/dist/fieldWait.d.ts +3 -3
  325. package/dist/fieldWait.js +3 -4
  326. package/dist/flowLayout.d.ts +68 -0
  327. package/dist/flowLayout.js +105 -0
  328. package/dist/focus.d.ts +2 -0
  329. package/dist/focus.js +9 -0
  330. package/dist/fromXState.d.ts +73 -0
  331. package/dist/fromXState.js +110 -0
  332. package/dist/icons.d.ts +1 -1
  333. package/dist/icons.js +15 -0
  334. package/dist/index.d.ts +37 -11
  335. package/dist/index.js +24 -2
  336. package/dist/isoDate.d.ts +8 -1
  337. package/dist/isoDate.js +20 -1
  338. package/dist/labelWords.d.ts +16 -7
  339. package/dist/labelWords.js +14 -12
  340. package/dist/listRowProps.d.ts +17 -15
  341. package/dist/modal.d.ts +5 -0
  342. package/dist/modal.js +21 -1
  343. package/dist/navFold.js +6 -3
  344. package/dist/optionCard.d.ts +18 -0
  345. package/dist/optionCard.js +16 -0
  346. package/dist/scrollBody.d.ts +16 -0
  347. package/dist/scrollBody.js +15 -0
  348. package/dist/scrollEdges.d.ts +7 -0
  349. package/dist/scrollEdges.js +39 -5
  350. package/dist/scrollStop.d.ts +6 -2
  351. package/dist/scrollStop.js +24 -8
  352. package/dist/shownDate.d.ts +28 -10
  353. package/dist/shownDate.js +41 -22
  354. package/dist/siteSearchBody.d.ts +34 -0
  355. package/dist/siteSearchBody.js +117 -0
  356. package/dist/size.d.ts +7 -1
  357. package/dist/sortableDrop.d.ts +44 -0
  358. package/dist/sortableDrop.js +78 -0
  359. package/dist/sortableSlide.d.ts +9 -0
  360. package/dist/sortableSlide.js +70 -0
  361. package/dist/sortableTitle.d.ts +10 -0
  362. package/dist/sortableTitle.js +48 -0
  363. package/dist/stateMachineDots.d.ts +77 -0
  364. package/dist/stateMachineDots.js +188 -0
  365. package/dist/stickyColumn.d.ts +2 -2
  366. package/dist/stickyColumn.js +2 -2
  367. package/dist/switcher.d.ts +10 -5
  368. package/dist/switcher.js +7 -5
  369. package/dist/tableColumns.d.ts +17 -0
  370. package/dist/tableColumns.js +30 -2
  371. package/dist/tableEmpty.js +5 -5
  372. package/dist/tableRow.d.ts +26 -2
  373. package/dist/tableRow.js +23 -1
  374. package/dist/tableSort.d.ts +10 -5
  375. package/dist/tableSort.js +15 -4
  376. package/dist/target.d.ts +12 -0
  377. package/dist/target.js +12 -0
  378. package/dist/textBox.js +1 -1
  379. package/dist/truncated.d.ts +31 -0
  380. package/dist/truncated.js +51 -0
  381. package/dist/typography.d.ts +19 -11
  382. package/dist/typography.js +11 -13
  383. package/dist/useFlowLayout.d.ts +38 -0
  384. package/dist/useFlowLayout.js +122 -0
  385. package/package.json +5 -3
package/dist/shownDate.js CHANGED
@@ -1,15 +1,34 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { toCalendarDate, toCalendarDateTime, } from "@internationalized/date";
2
3
  import { useCallback, useEffect, useRef, useState, } from "react";
3
4
  import { flushSync } from "react-dom";
4
- import { fromISODate, toISODate } from "./isoDate.js";
5
+ import { fromISODate, fromISODateTime, toISODate, toISODateTime } from "./isoDate.js";
6
+ /** A day: `YYYY-MM-DD`. */
7
+ export const DATE = {
8
+ granularity: "day",
9
+ toISO: toISODate,
10
+ fromISO: fromISODate,
11
+ narrow: (value) => value && toCalendarDate(value),
12
+ whole: "Enter the whole date.",
13
+ };
14
+ /** A day and a time to the minute: `YYYY-MM-DDTHH:mm`. */
15
+ export const DATE_TIME = {
16
+ granularity: "minute",
17
+ toISO: toISODateTime,
18
+ fromISO: fromISODateTime,
19
+ narrow: (value) => value && toCalendarDateTime(value),
20
+ whole: "Enter the whole date and time.",
21
+ };
22
+ /** `a` is before (negative), at (0) or after (positive) `b`, to the minute. */
23
+ const compare = (a, b) => toCalendarDateTime(a).compare(toCalendarDateTime(b));
5
24
  /** `iso` when it is a date within min/max, else `""`. */
6
- function withinRange(iso, { minValue, maxValue }) {
7
- const date = fromISODate(iso);
25
+ function withinRange(iso, { minValue, maxValue }, kind) {
26
+ const date = kind.fromISO(iso);
8
27
  if (!date)
9
28
  return "";
10
- if (minValue && date.compare(minValue) < 0)
29
+ if (minValue && compare(date, minValue) < 0)
11
30
  return "";
12
- if (maxValue && date.compare(maxValue) > 0)
31
+ if (maxValue && compare(date, maxValue) > 0)
13
32
  return "";
14
33
  return iso;
15
34
  }
@@ -32,23 +51,23 @@ function withinRange(iso, { minValue, maxValue }) {
32
51
  *
33
52
  * `shown` (`YYYY-MM-DD` or `""`) is what the hidden `name` input posts.
34
53
  */
35
- export function useShownDate(props) {
54
+ export function useShownDate(props, kind) {
36
55
  const { value, defaultValue, onChange, isRequired } = props;
37
56
  const [inner, setInner] = useState(value ?? defaultValue ?? null);
38
57
  const [read, setRead] = useState({
39
- typed: toISODate(inner),
58
+ typed: kind.toISO(inner),
40
59
  impossible: null,
41
60
  partial: false,
42
61
  });
43
62
  const side = useLeaving(read.impossible);
44
- const shown = withinRange(read.typed, props);
63
+ const shown = withinRange(read.typed, props, kind);
45
64
  const reported = useRef(shown);
46
65
  const report = useRef(onChange);
47
66
  useEffect(() => {
48
67
  report.current = onChange;
49
68
  });
50
- const given = value === undefined ? undefined : toISODate(value);
51
- const givenShown = withinRange(given ?? "", props);
69
+ const given = value === undefined ? undefined : kind.toISO(value);
70
+ const givenShown = withinRange(given ?? "", props, kind);
52
71
  const lastGiven = useRef(given);
53
72
  useEffect(() => {
54
73
  if (given === lastGiven.current)
@@ -57,22 +76,22 @@ export function useShownDate(props) {
57
76
  if (given === undefined || given === reported.current)
58
77
  return;
59
78
  reported.current = givenShown;
60
- setInner(fromISODate(given));
61
- }, [given, givenShown]);
79
+ setInner(kind.fromISO(given));
80
+ }, [given, givenShown, kind]);
62
81
  const onRead = useCallback((next) => setRead(next), []);
63
82
  useEffect(() => {
64
83
  if (shown === reported.current)
65
84
  return;
66
85
  reported.current = shown;
67
- report.current?.(fromISODate(shown));
68
- }, [shown]);
86
+ report.current?.(kind.fromISO(shown));
87
+ }, [shown, kind]);
69
88
  return {
70
89
  inner,
71
90
  setInner,
72
91
  shown,
73
92
  impossible: read.impossible,
74
93
  onRead,
75
- validate: () => (isRequired && read.partial ? "Enter the whole date." : null),
94
+ validate: () => (isRequired && read.partial ? kind.whole : null),
76
95
  ...side,
77
96
  };
78
97
  }
@@ -107,14 +126,14 @@ function givenKey(value, bounds) {
107
126
  return "";
108
127
  const [start, end] = [toISODate(value.start), toISODate(value.end)];
109
128
  return bounds
110
- ? rangeKey(withinRange(start, bounds), withinRange(end, bounds))
129
+ ? rangeKey(withinRange(start, bounds, DATE), withinRange(end, bounds, DATE))
111
130
  : `${start}/${end}`;
112
131
  }
113
132
  /** An impossible day, naming its side, or else an end before the start; `null` for neither. */
114
- function problemOf(start, end, startShown, endShown) {
133
+ function problemOf([start, end], [startLabel, endLabel], startShown, endShown) {
115
134
  const impossible = [
116
- start.impossible && `Start date: ${start.impossible}`,
117
- end.impossible && `End date: ${end.impossible}`,
135
+ start.impossible && `${startLabel}: ${start.impossible}`,
136
+ end.impossible && `${endLabel}: ${end.impossible}`,
118
137
  ].filter(Boolean);
119
138
  if (impossible.length > 0)
120
139
  return impossible.join(" ");
@@ -140,10 +159,10 @@ export function useShownRange(props) {
140
159
  const onReadEnd = useCallback((next) => setEnd(next), []);
141
160
  const startSide = useLeaving(start.impossible);
142
161
  const endSide = useLeaving(end.impossible);
143
- const startShown = withinRange(start.typed, props);
144
- const endShown = withinRange(end.typed, props);
162
+ const startShown = withinRange(start.typed, props, DATE);
163
+ const endShown = withinRange(end.typed, props, DATE);
145
164
  const shown = rangeKey(startShown, endShown);
146
- const problem = problemOf(start, end, startShown, endShown);
165
+ const problem = problemOf([start, end], props.labels, startShown, endShown);
147
166
  const reported = useRef(shown);
148
167
  const report = useRef(onChange);
149
168
  useEffect(() => {
@@ -0,0 +1,34 @@
1
+ /** One page the search can find. */
2
+ export type SiteSearchItem = {
3
+ /** The page's name: the row's label and the first thing matched. */
4
+ label: string;
5
+ /** A muted line under the label, matched last. */
6
+ description?: string | undefined;
7
+ /** Where the row goes. */
8
+ href: string;
9
+ /** Other names the page answers to (the exports it documents), matched like the label but not shown. */
10
+ keywords?: string[] | undefined;
11
+ };
12
+ /**
13
+ * The items that match `text`, best first: the label starts with it, then the label contains it,
14
+ * then a keyword contains it, then the description does. Case is ignored, and items of the same
15
+ * rank keep their order in `items`. Empty text matches nothing.
16
+ */
17
+ export declare function rankSiteSearch(items: readonly SiteSearchItem[], text: string): SiteSearchItem[];
18
+ /** What the live region says for a result count, in English. */
19
+ export declare function englishCount(count: number): string;
20
+ /** The words `SearchBody` renders, each a `SiteSearch` prop with its English default. */
21
+ export type BodyWords = {
22
+ resultsLabel: string;
23
+ placeholder: string;
24
+ hintLabel: string;
25
+ noResultsLabel: string;
26
+ countLabel: (count: number) => string;
27
+ allResultsLabel: string;
28
+ };
29
+ export declare function SearchBody({ items, label, resultsHref, words: { resultsLabel, placeholder, hintLabel, noResultsLabel, countLabel, allResultsLabel }, }: {
30
+ items: readonly SiteSearchItem[];
31
+ label: string;
32
+ resultsHref: ((query: string) => string) | undefined;
33
+ words: BodyWords;
34
+ }): import("react").JSX.Element;
@@ -0,0 +1,117 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useRef, useState, } from "react";
3
+ import { Input } from "./Input.js";
4
+ import { ListRow } from "./ListRow.js";
5
+ import { Text } from "./typography.js";
6
+ /**
7
+ * The items that match `text`, best first: the label starts with it, then the label contains it,
8
+ * then a keyword contains it, then the description does. Case is ignored, and items of the same
9
+ * rank keep their order in `items`. Empty text matches nothing.
10
+ */
11
+ export function rankSiteSearch(items, text) {
12
+ const query = text.trim().toLowerCase();
13
+ if (query === "")
14
+ return [];
15
+ const rankOf = (item) => {
16
+ const label = item.label.toLowerCase();
17
+ if (label.startsWith(query))
18
+ return 0;
19
+ if (label.includes(query))
20
+ return 1;
21
+ if (item.keywords?.some((keyword) => keyword.toLowerCase().includes(query)))
22
+ return 2;
23
+ if (item.description?.toLowerCase().includes(query))
24
+ return 3;
25
+ return -1;
26
+ };
27
+ return items
28
+ .map((item, index) => ({ item, index, rank: rankOf(item) }))
29
+ .filter((entry) => entry.rank >= 0)
30
+ .toSorted((a, b) => a.rank - b.rank || a.index - b.index)
31
+ .map((entry) => entry.item);
32
+ }
33
+ /** What the live region says for a result count, in English. */
34
+ export function englishCount(count) {
35
+ if (count === 0)
36
+ return "No results";
37
+ return count === 1 ? "1 result" : `${count} results`;
38
+ }
39
+ /**
40
+ * An Enter that commits an input method's composition (a Japanese or Chinese keyboard) is not a
41
+ * submit. Safari has already cleared `isComposing` by then, and only the 229 keyCode tells.
42
+ */
43
+ function isComposing({ nativeEvent }) {
44
+ return nativeEvent.isComposing || nativeEvent.keyCode === 229;
45
+ }
46
+ // A link that stays on the page (a hash, an app's router) still closes the search; one opened in a
47
+ // new tab or window leaves it open.
48
+ function onListClick(event) {
49
+ if (event.ctrlKey || event.metaKey || event.shiftKey)
50
+ return;
51
+ if (event.target instanceof Element && event.target.closest("a[href]")) {
52
+ event.currentTarget.closest("dialog")?.close();
53
+ }
54
+ }
55
+ /** The result links in the list, in order. */
56
+ function linksIn(list) {
57
+ return list ? [...list.querySelectorAll("a[href]")] : [];
58
+ }
59
+ /** The muted line under the field: the prompt before anything is typed, the no-match line after. */
60
+ function SearchNote({ query, found, words: { hintLabel, noResultsLabel }, }) {
61
+ if (query.trim() === "")
62
+ return _jsx(Text, { tone: "muted", children: hintLabel });
63
+ if (found)
64
+ return null;
65
+ return (_jsxs(Text, { tone: "muted", children: [noResultsLabel, " ", query.trim()] }));
66
+ }
67
+ /** The matches, then the link to the full results page when there is one. */
68
+ function SearchResults({ list, results, all, label, onKeyDown, }) {
69
+ if (results.length === 0 && all === undefined)
70
+ return null;
71
+ return (_jsxs("ul", { ref: list, "aria-label": label, onKeyDown: onKeyDown, onClick: onListClick, className: "border-slate-200/70 *:not-first:border-t *:not-first:border-inherit", children: [results.map((item) => (_jsx("li", { children: _jsx(ListRow, { href: item.href, size: "sm", secondary: item.description, children: item.label }) }, item.href))), all !== undefined && (_jsx("li", { children: _jsx(ListRow, { href: all.href, size: "sm", children: all.text }) }))] }));
72
+ }
73
+ export function SearchBody({ items, label, resultsHref, words: { resultsLabel, placeholder, hintLabel, noResultsLabel, countLabel, allResultsLabel }, }) {
74
+ const [query, setQuery] = useState("");
75
+ const box = useRef(null);
76
+ const list = useRef(null);
77
+ const results = rankSiteSearch(items, query);
78
+ const typed = query.trim() !== "";
79
+ const all = typed && resultsHref ? resultsHref(query.trim()) : undefined;
80
+ const onFieldKey = (event) => {
81
+ if (event.key === "Escape") {
82
+ // Close here, so no engine spends the first Esc clearing the search field.
83
+ event.preventDefault();
84
+ event.currentTarget.closest("dialog")?.close();
85
+ }
86
+ else if (event.key === "Enter") {
87
+ if (isComposing(event))
88
+ return;
89
+ event.preventDefault();
90
+ // The field highlights no result, so with a results page Enter goes there (its link is last).
91
+ const links = linksIn(list.current);
92
+ (all === undefined ? links[0] : links.at(-1))?.click();
93
+ }
94
+ else if (event.key === "ArrowDown") {
95
+ const first = linksIn(list.current)[0];
96
+ if (first) {
97
+ event.preventDefault();
98
+ first.focus();
99
+ }
100
+ }
101
+ };
102
+ const onListKey = (event) => {
103
+ if (event.key !== "ArrowDown" && event.key !== "ArrowUp")
104
+ return;
105
+ const links = linksIn(list.current);
106
+ const at = links.findIndex((link) => link === document.activeElement);
107
+ if (at < 0)
108
+ return;
109
+ event.preventDefault();
110
+ const next = at + (event.key === "ArrowDown" ? 1 : -1);
111
+ if (next < 0)
112
+ box.current?.querySelector("input")?.focus();
113
+ else
114
+ links[Math.min(next, links.length - 1)]?.focus();
115
+ };
116
+ return (_jsxs("search", { ref: box, role: "search", className: "flex flex-col gap-3", children: [_jsx(Input, { type: "search", icon: "search", "aria-label": label, placeholder: placeholder, autoComplete: "off", autoCorrect: "off", autoCapitalize: "off", spellCheck: false, value: query, onChange: (event) => setQuery(event.target.value), onKeyDown: onFieldKey }), _jsx("div", { role: "status", "aria-live": "polite", className: "sr-only", children: typed ? countLabel(results.length) : "" }), _jsx(SearchNote, { query: query, found: results.length > 0, words: { hintLabel, noResultsLabel } }), _jsx(SearchResults, { list: list, results: results, all: all === undefined ? undefined : { href: all, text: `${allResultsLabel} ${query.trim()}` }, label: resultsLabel, onKeyDown: onListKey })] }));
117
+ }
package/dist/size.d.ts CHANGED
@@ -9,6 +9,8 @@
9
9
  * - `Cluster` and `ScrollStrip` `gap`: `xs`, `sm` and `md`, the first steps of the gap scale.
10
10
  * - `Icon` `size`: also `feature`, the mark of a feature card.
11
11
  * - `Dialog` `width`: also `full`, the whole screen. `ChatThread` `height`: also `fill`, its parent's.
12
+ * - `ImageWidth` (`Image`, `RegionFrame` and `MediaTile` `width`): also `xl` and `full`, the
13
+ * parent's width; `sm`, `md`, `lg` and `xl` are 96, 160, 256 and 448px.
12
14
  *
13
15
  * Defaults that are not `md`:
14
16
  * - `Table` `size` is `sm`, its row padding, and the buttons and pills in a table take that size;
@@ -17,11 +19,15 @@
17
19
  * column.
18
20
  * - `Stack` and `Section` `gap` are `xs` inside a `Card`, `Dialog`, `Drawer`, `BottomSheet`,
19
21
  * `Callout` or `ListRow`.
22
+ * - `Image` and `RegionFrame` `width` are `full`: a picture fills its column unless it is a
23
+ * thumbnail. `MediaTile` `width` is `md`, one tile of a grid of them.
20
24
  * - A `Pill`, `Button` or `IconButton` with no `size` takes the size of the `Card`, `ListRow` or
21
25
  * `Table` it sits in; an `EmptyState` takes its slot's.
22
26
  *
23
27
  * A responsive size, `{ base, md }` (`ResponsiveSize`), changes at Tailwind's `md` breakpoint (48rem)
24
- * in CSS, with no script: `Button`, `IconButton`, `SegmentedControl` and `Icon` take it.
28
+ * in CSS, with no script: `Button`, `IconButton`, `SegmentedControl` and `Icon` take it, and so do
29
+ * the text fields, `Input`, `Select`, `Textarea`, `DateField`, `DateTimeField` and
30
+ * `DateRangePicker`, so a field and the button beside it stay aligned at both widths.
25
31
  *
26
32
  * With no `size` at all, because they take the size of the text or the control they sit on:
27
33
  * `Callout`, `CopyButton`, `Kbd`, `Badge` and `Breadcrumbs`.
@@ -0,0 +1,44 @@
1
+ import type { DropTarget, Key } from "react-aria-components";
2
+ /** A move the user made: which item, the section it lands in, and the item it lands next to. */
3
+ export type SortableMove = {
4
+ /** The `id` of the item that moved. */
5
+ id: string;
6
+ /** The `id` of the `SortableSection` the item lands in. Set whenever the list has sections. */
7
+ section?: string;
8
+ /**
9
+ * The item it was dropped before or after. Absent only for a drop into an empty section, where
10
+ * there is no item to land next to.
11
+ */
12
+ target?: {
13
+ id: string;
14
+ position: "before" | "after";
15
+ };
16
+ };
17
+ /** A marker on every row a pointer can drop next to: the items and each section's tail row. */
18
+ export declare const ROW_MARK = "data-sortable-row";
19
+ /**
20
+ * The key of a section's tail row. Every section ends with one: in an empty section it is the "Drop
21
+ * here" row, in one with items it is an empty row of no height. A drop before it is a drop at the
22
+ * end of the section. react-aria's keyboard drop moves cannot step from "after the last item" of a
23
+ * section into the next one (it wraps to the top), but they do step from "before" a row to "before"
24
+ * the next row across sections, so with a tail row the end of each section is a "before" target.
25
+ */
26
+ export declare function tailKey(section: string): string;
27
+ /** A row's section and title; a tail row also lists its section's items, in order. */
28
+ export type Place = {
29
+ section?: string;
30
+ title: string;
31
+ tail?: string[];
32
+ };
33
+ /** react-aria's pointer drop delegate, aware of sections (the stock one sees only top-level items). */
34
+ export declare function sectionDelegate(listId: string): {
35
+ getDropTargetFromPoint: (_x: number, y: number) => DropTarget | null;
36
+ };
37
+ /** Only a drop between two rows is a move; a drop on a row's centre, or on the list itself, is not. */
38
+ export declare function dropOperation(target: DropTarget): "move" | "cancel";
39
+ /**
40
+ * The move react-aria reported, as the app's `SortableMove`, or nothing when it is not one (a drop
41
+ * on a row's centre, or next to the item itself). A drop at a section's tail lands after the
42
+ * section's last other item, or with no target when it has none.
43
+ */
44
+ export declare function moveOf(places: Map<string, Place>, keys: Iterable<Key>, target: DropTarget): SortableMove | null;
@@ -0,0 +1,78 @@
1
+ /** A marker on every row a pointer can drop next to: the items and each section's tail row. */
2
+ export const ROW_MARK = "data-sortable-row";
3
+ /**
4
+ * The key of a section's tail row. Every section ends with one: in an empty section it is the "Drop
5
+ * here" row, in one with items it is an empty row of no height. A drop before it is a drop at the
6
+ * end of the section. react-aria's keyboard drop moves cannot step from "after the last item" of a
7
+ * section into the next one (it wraps to the top), but they do step from "before" a row to "before"
8
+ * the next row across sections, so with a tail row the end of each section is a "before" target.
9
+ */
10
+ export function tailKey(section) {
11
+ return `hackcove-sortable-end:${section}`;
12
+ }
13
+ /**
14
+ * Where a pointer drops: before or after the row it is over, by which half it is in. Over a section
15
+ * heading, or in a gap, it is before the next row below (the first item of that section, or its
16
+ * "Drop here" row), and below every row it is after the last. Never "on" a row.
17
+ */
18
+ function dropTargetAt(list, y) {
19
+ if (!list)
20
+ return null;
21
+ const top = y + list.getBoundingClientRect().top;
22
+ const rows = [...list.querySelectorAll(`[${ROW_MARK}]`)];
23
+ for (const row of rows) {
24
+ const key = row.dataset.key;
25
+ if (key == null)
26
+ continue;
27
+ const box = row.getBoundingClientRect();
28
+ if (top < box.top)
29
+ return { type: "item", key, dropPosition: "before" };
30
+ if (top <= box.bottom) {
31
+ return {
32
+ type: "item",
33
+ key,
34
+ dropPosition: top < box.top + box.height / 2 ? "before" : "after",
35
+ };
36
+ }
37
+ }
38
+ const last = rows.at(-1)?.dataset.key;
39
+ return last == null ? null : { type: "item", key: last, dropPosition: "after" };
40
+ }
41
+ /** react-aria's pointer drop delegate, aware of sections (the stock one sees only top-level items). */
42
+ export function sectionDelegate(listId) {
43
+ return {
44
+ getDropTargetFromPoint: (_x, y) => dropTargetAt(document.getElementById(listId), y),
45
+ };
46
+ }
47
+ /** Only a drop between two rows is a move; a drop on a row's centre, or on the list itself, is not. */
48
+ export function dropOperation(target) {
49
+ return target.type === "item" && target.dropPosition !== "on" ? "move" : "cancel";
50
+ }
51
+ /**
52
+ * The move react-aria reported, as the app's `SortableMove`, or nothing when it is not one (a drop
53
+ * on a row's centre, or next to the item itself). A drop at a section's tail lands after the
54
+ * section's last other item, or with no target when it has none.
55
+ */
56
+ export function moveOf(places, keys, target) {
57
+ const [key] = keys;
58
+ if (key == null || target.type !== "item" || target.dropPosition === "on")
59
+ return null;
60
+ const place = places.get(String(target.key));
61
+ if (!place)
62
+ return null;
63
+ const id = String(key);
64
+ if (String(target.key) === id)
65
+ return null;
66
+ const section = place.section === undefined ? {} : { section: place.section };
67
+ if (place.tail) {
68
+ const last = place.tail.filter((item) => item !== id).at(-1);
69
+ return last === undefined
70
+ ? { id, ...section }
71
+ : { id, ...section, target: { id: last, position: "after" } };
72
+ }
73
+ return {
74
+ id,
75
+ ...section,
76
+ target: { id: String(target.key), position: target.dropPosition },
77
+ };
78
+ }
@@ -0,0 +1,9 @@
1
+ /**
2
+ * After the app applies a move, every row (an element carrying `mark`) that changed place slides
3
+ * from where it was to where it is (a FLIP step through the Web Animations API), so the eye can
4
+ * follow the move. The list records where its rows are each time the app renders it; react-aria
5
+ * then puts the rows in their new order in a later commit, and an observer slides them before the
6
+ * next paint. Only a change of order slides anything (a drop indicator coming and going does not),
7
+ * and nothing slides under `prefers-reduced-motion` or on a first render.
8
+ */
9
+ export declare function useSlide(listId: string, mark: string): void;
@@ -0,0 +1,70 @@
1
+ import { useEffect, useLayoutEffect, useRef } from "react";
2
+ // How a `SortableList` row slides to its new place after a move.
3
+ /** How long a row takes to slide to its new place after a move. */
4
+ const SLIDE = { duration: 200, easing: "ease-out" };
5
+ /** The rows' keys in order, read without measuring anything. */
6
+ function orderOf(list, mark) {
7
+ return [...list.querySelectorAll(`[${mark}][data-key]`)]
8
+ .map((row) => row.dataset.key ?? "")
9
+ .join("\n");
10
+ }
11
+ function places(list, mark) {
12
+ const top = list.getBoundingClientRect().top;
13
+ const tops = new Map();
14
+ for (const row of list.querySelectorAll(`[${mark}][data-key]`)) {
15
+ const key = row.dataset.key ?? "";
16
+ tops.set(key, row.getBoundingClientRect().top - top);
17
+ }
18
+ return { order: [...tops.keys()].join("\n"), tops };
19
+ }
20
+ /** Whether rows may slide: only where the Web Animations API is, and not under `prefers-reduced-motion`. */
21
+ function maySlide(list) {
22
+ if (typeof list.animate !== "function")
23
+ return false;
24
+ return !window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;
25
+ }
26
+ /** Slides each row that moved from where it was (`before`) to where it is (`after`). */
27
+ function slide(list, mark, before, after) {
28
+ for (const row of list.querySelectorAll(`[${mark}][data-key]`)) {
29
+ const key = row.dataset.key ?? "";
30
+ const was = before.tops.get(key);
31
+ const now = after.tops.get(key);
32
+ if (was === undefined || now === undefined || was === now)
33
+ continue;
34
+ row.animate([{ translate: `0 ${was - now}px` }, { translate: "0 0" }], SLIDE);
35
+ }
36
+ }
37
+ /**
38
+ * After the app applies a move, every row (an element carrying `mark`) that changed place slides
39
+ * from where it was to where it is (a FLIP step through the Web Animations API), so the eye can
40
+ * follow the move. The list records where its rows are each time the app renders it; react-aria
41
+ * then puts the rows in their new order in a later commit, and an observer slides them before the
42
+ * next paint. Only a change of order slides anything (a drop indicator coming and going does not),
43
+ * and nothing slides under `prefers-reduced-motion` or on a first render.
44
+ */
45
+ export function useSlide(listId, mark) {
46
+ const last = useRef(null);
47
+ // Each render of the list: where the rows are before its new order lands.
48
+ useLayoutEffect(() => {
49
+ const list = document.getElementById(listId);
50
+ if (list)
51
+ last.current = places(list, mark);
52
+ });
53
+ useEffect(() => {
54
+ const list = document.getElementById(listId);
55
+ if (!list || typeof MutationObserver !== "function")
56
+ return undefined;
57
+ const observer = new MutationObserver(() => {
58
+ const before = last.current;
59
+ // A drop indicator coming and going changes no order: leave it without measuring a row.
60
+ if (before?.order === orderOf(list, mark))
61
+ return;
62
+ const after = places(list, mark);
63
+ last.current = after;
64
+ if (before && maySlide(list))
65
+ slide(list, mark, before, after);
66
+ });
67
+ observer.observe(list, { childList: true, subtree: true });
68
+ return () => observer.disconnect();
69
+ }, [listId, mark]);
70
+ }
@@ -0,0 +1,10 @@
1
+ import { type ReactElement } from "react";
2
+ /**
3
+ * A `SortableItem`'s one-line title. Cut, it shows in full in a tooltip: on the pointer over it, a
4
+ * tap, or the keyboard's focus on the row or its handle. react-aria renders an item's own hooks
5
+ * outside the page, so the title is its own part, and it listens for focus on the row it lands in.
6
+ * Internal.
7
+ */
8
+ export declare function ItemTitle({ title }: {
9
+ title: string;
10
+ }): ReactElement;
@@ -0,0 +1,48 @@
1
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useEffect, useRef, useState } from "react";
3
+ import { useTooltip } from "./Tooltip.js";
4
+ import { useCut } from "./truncated.js";
5
+ /** Whether the element has the focus ring's focus (the keyboard's); a browser without `:focus-visible` counts every focus. */
6
+ function ringed(target) {
7
+ if (!(target instanceof Element))
8
+ return false;
9
+ try {
10
+ return target.matches(":focus-visible");
11
+ }
12
+ catch {
13
+ return true;
14
+ }
15
+ }
16
+ /**
17
+ * A `SortableItem`'s one-line title. Cut, it shows in full in a tooltip: on the pointer over it, a
18
+ * tap, or the keyboard's focus on the row or its handle. react-aria renders an item's own hooks
19
+ * outside the page, so the title is its own part, and it listens for focus on the row it lands in.
20
+ * Internal.
21
+ */
22
+ export function ItemTitle({ title }) {
23
+ const line = useRef(null);
24
+ const [focused, setFocused] = useState(false);
25
+ const { cut } = useCut(line, title);
26
+ const { props: tip, tooltip } = useTooltip(cut ? title : undefined, { describes: false, tap: true, focused }, {});
27
+ useEffect(() => {
28
+ const row = line.current?.closest('[role="row"]');
29
+ if (!row)
30
+ return undefined;
31
+ const focus = (event) => setFocused(ringed(event.target));
32
+ const blur = () => setFocused(false);
33
+ // Dismissed where it stands (WCAG 1.4.13); the key goes on to the list.
34
+ const key = (event) => {
35
+ if (event.key === "Escape")
36
+ setFocused(false);
37
+ };
38
+ row.addEventListener("focusin", focus);
39
+ row.addEventListener("focusout", blur);
40
+ row.addEventListener("keydown", key);
41
+ return () => {
42
+ row.removeEventListener("focusin", focus);
43
+ row.removeEventListener("focusout", blur);
44
+ row.removeEventListener("keydown", key);
45
+ };
46
+ }, []);
47
+ return (_jsxs(_Fragment, { children: [_jsx("div", { ref: line, className: "truncate", style: tip.style, onPointerEnter: tip.onPointerEnter, onPointerLeave: tip.onPointerLeave, onPointerDown: tip.onPointerDown, title: tip.title, children: title }), tooltip] }));
48
+ }
@@ -0,0 +1,77 @@
1
+ import { type ReactElement } from "react";
2
+ import type { FlowLayout, FlowNodeBox } from "./flowLayout.js";
3
+ import type { StateMachineItem } from "./StateMachine.js";
4
+ /**
5
+ * The box items whose `state` is no state of the machine go in. Printable, since it reaches the DOM
6
+ * (a box's `data-measure`), where a server render would turn a control character into U+FFFD.
7
+ */
8
+ export declare const UNPLACED = "hc-sm:unplaced";
9
+ /** A dot's slot in its box: three to a row, each wide enough for a short ref. */
10
+ export declare const SLOT_W = 76;
11
+ export declare const SLOT_H = 22;
12
+ export declare const COLS = 3;
13
+ /** An item on its way from one state to another; `seq` restarts the run when it moves again. */
14
+ type Move = {
15
+ from: string;
16
+ to: string;
17
+ seq: number;
18
+ };
19
+ /** Which box each item sits in: its state's, else the unplaced box. */
20
+ export declare function placeOf(items: readonly StateMachineItem[], known: ReadonlySet<string>): Map<string, string>;
21
+ /**
22
+ * Remembers where every item was, and when one's place changes records the move, during render
23
+ * (React's "adjust state when a prop changes"), so the re-render that measures the boxes does not
24
+ * lose it. A move ends on its run's `animationend` (`done`), at the next change of places (which
25
+ * records only its own moves), or on `clear` (a box opened, which would start a run long over).
26
+ */
27
+ export declare function useMoves(items: readonly StateMachineItem[], known: ReadonlySet<string>): {
28
+ moves: ReadonlyMap<string, Move>;
29
+ done: (id: string, seq: number) => void;
30
+ clear: () => void;
31
+ };
32
+ /** How many slots a box with `count` items draws: all of them, or the first few and a `+N`; one more for "fewer" when open. */
33
+ export declare function slotsFor(count: number, open: boolean): number;
34
+ /**
35
+ * The rows a box reserves for its dots, whatever its count: the nine it shows (the `+N` included),
36
+ * or the rows of an open box's full list. A box with few or no items reserves the same rows, so
37
+ * its size does not depend on how many items it holds.
38
+ */
39
+ export declare function rowsFor(slots: number): number;
40
+ /**
41
+ * The room a box reserves under its tags for `slots` dots: the full grid's width and `rowsFor`'s
42
+ * height, so it is the same at 0, 1, 9 or 12 items (closed) and grows only when a box is opened.
43
+ */
44
+ export declare function dotArea(slots: number): {
45
+ width: number;
46
+ height: number;
47
+ };
48
+ /** A box's tag row: one small pill's height. */
49
+ export declare const TAG_ROW = 20;
50
+ /** The gap between the tag row and the dot area (`mt-1`). */
51
+ export declare const TAG_GAP = 4;
52
+ /**
53
+ * The size of what a box holds under its label: its tag row, then its dot area. The layout takes
54
+ * it before the box can be measured (a server render), so the dots, placed up from the box's
55
+ * bottom, already sit under the tags and never on them.
56
+ */
57
+ export declare function boxContentSize(slots: number): {
58
+ width: number;
59
+ height: number;
60
+ };
61
+ /** Where slot `i` of `slots` sits in `box`: its left edge and its vertical centre, on the box's fixed grid. */
62
+ export declare function slotAt(box: FlowNodeBox, i: number, slots: number): {
63
+ left: number;
64
+ y: number;
65
+ };
66
+ /** What the dot layer draws from: the items in each box, the boxes' names, which boxes are open, and the moves. */
67
+ type DotPlaces = {
68
+ inBox: ReadonlyMap<string, readonly StateMachineItem[]>;
69
+ names: ReadonlyMap<string, string>;
70
+ open: ReadonlySet<string>;
71
+ toggle: (id: string) => void;
72
+ moves: ReadonlyMap<string, Move>;
73
+ done: (id: string, seq: number) => void;
74
+ };
75
+ /** Every box's dots, over the drawn diagram. */
76
+ export declare function dotLayer(layout: FlowLayout, places: DotPlaces): ReactElement;
77
+ export {};