@slashsuite/ui-react 0.0.0-stage → 0.12.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 (304) hide show
  1. package/LICENSE +21 -0
  2. package/MIGRATING.md +540 -0
  3. package/README.md +549 -2
  4. package/dist/AppShell.d.ts +127 -0
  5. package/dist/AppShell.js +119 -0
  6. package/dist/AppShellMenu.d.ts +26 -0
  7. package/dist/AppShellMenu.js +66 -0
  8. package/dist/Avatar.d.ts +75 -0
  9. package/dist/Avatar.js +95 -0
  10. package/dist/AvatarStack.d.ts +31 -0
  11. package/dist/AvatarStack.js +34 -0
  12. package/dist/Badge.d.ts +15 -0
  13. package/dist/Badge.js +15 -0
  14. package/dist/BottomSheet.d.ts +36 -0
  15. package/dist/BottomSheet.js +142 -0
  16. package/dist/Breadcrumbs.d.ts +27 -0
  17. package/dist/Breadcrumbs.js +29 -0
  18. package/dist/BulletList.d.ts +18 -0
  19. package/dist/BulletList.js +18 -0
  20. package/dist/Button.d.ts +121 -0
  21. package/dist/Button.js +182 -0
  22. package/dist/ButtonGroup.d.ts +15 -0
  23. package/dist/ButtonGroup.js +10 -0
  24. package/dist/Callout.d.ts +43 -0
  25. package/dist/Callout.js +45 -0
  26. package/dist/Card.d.ts +148 -0
  27. package/dist/Card.js +171 -0
  28. package/dist/CardBadge.d.ts +7 -0
  29. package/dist/CardBadge.js +12 -0
  30. package/dist/CardBody.d.ts +28 -0
  31. package/dist/CardBody.js +30 -0
  32. package/dist/CardGrid.d.ts +53 -0
  33. package/dist/CardGrid.js +52 -0
  34. package/dist/CardParts.d.ts +40 -0
  35. package/dist/CardParts.js +41 -0
  36. package/dist/ChatComposer.d.ts +35 -0
  37. package/dist/ChatComposer.js +50 -0
  38. package/dist/ChatMessage.d.ts +26 -0
  39. package/dist/ChatMessage.js +21 -0
  40. package/dist/ChatThread.d.ts +25 -0
  41. package/dist/ChatThread.js +60 -0
  42. package/dist/Checkbox.d.ts +42 -0
  43. package/dist/Checkbox.js +63 -0
  44. package/dist/Chevron.d.ts +5 -0
  45. package/dist/Chevron.js +6 -0
  46. package/dist/Cluster.d.ts +70 -0
  47. package/dist/Cluster.js +47 -0
  48. package/dist/Code.d.ts +6 -0
  49. package/dist/Code.js +5 -0
  50. package/dist/CodeBlock.d.ts +46 -0
  51. package/dist/CodeBlock.js +21 -0
  52. package/dist/CodeBody.d.ts +20 -0
  53. package/dist/CodeBody.js +38 -0
  54. package/dist/CodeExample.d.ts +25 -0
  55. package/dist/CodeExample.js +17 -0
  56. package/dist/CodeText.d.ts +11 -0
  57. package/dist/CodeText.js +64 -0
  58. package/dist/ColourSchemeToggle.d.ts +36 -0
  59. package/dist/ColourSchemeToggle.js +64 -0
  60. package/dist/Container.d.ts +22 -0
  61. package/dist/Container.js +26 -0
  62. package/dist/CopyButton.d.ts +17 -0
  63. package/dist/CopyButton.js +39 -0
  64. package/dist/CopyLine.d.ts +9 -0
  65. package/dist/CopyLine.js +7 -0
  66. package/dist/DateCalendar.d.ts +23 -0
  67. package/dist/DateCalendar.js +89 -0
  68. package/dist/DateField.d.ts +124 -0
  69. package/dist/DateField.js +111 -0
  70. package/dist/DateFieldCalendar.d.ts +24 -0
  71. package/dist/DateFieldCalendar.js +50 -0
  72. package/dist/DateRangePicker.d.ts +47 -0
  73. package/dist/DateRangePicker.js +44 -0
  74. package/dist/Dialog.d.ts +56 -0
  75. package/dist/Dialog.js +94 -0
  76. package/dist/Disclosure.d.ts +29 -0
  77. package/dist/Disclosure.js +23 -0
  78. package/dist/Divider.d.ts +4 -0
  79. package/dist/Divider.js +5 -0
  80. package/dist/DocsLayout.d.ts +69 -0
  81. package/dist/DocsLayout.js +64 -0
  82. package/dist/Drawer.d.ts +30 -0
  83. package/dist/Drawer.js +24 -0
  84. package/dist/EmptyState.d.ts +47 -0
  85. package/dist/EmptyState.js +34 -0
  86. package/dist/Field.d.ts +44 -0
  87. package/dist/Field.js +51 -0
  88. package/dist/FieldDialog.d.ts +26 -0
  89. package/dist/FieldDialog.js +31 -0
  90. package/dist/Fieldset.d.ts +21 -0
  91. package/dist/Fieldset.js +22 -0
  92. package/dist/FileDrop.d.ts +17 -0
  93. package/dist/FileDrop.js +14 -0
  94. package/dist/FormRow.d.ts +46 -0
  95. package/dist/FormRow.js +39 -0
  96. package/dist/Hero.d.ts +23 -0
  97. package/dist/Hero.js +28 -0
  98. package/dist/Icon.d.ts +40 -0
  99. package/dist/Icon.js +30 -0
  100. package/dist/IconButton.d.ts +72 -0
  101. package/dist/IconButton.js +65 -0
  102. package/dist/Image.d.ts +58 -0
  103. package/dist/Image.js +69 -0
  104. package/dist/InlineEdit.d.ts +22 -0
  105. package/dist/InlineEdit.js +60 -0
  106. package/dist/Input.d.ts +40 -0
  107. package/dist/Input.js +42 -0
  108. package/dist/InputShell.d.ts +24 -0
  109. package/dist/InputShell.js +40 -0
  110. package/dist/Kbd.d.ts +6 -0
  111. package/dist/Kbd.js +5 -0
  112. package/dist/KeyValueList.d.ts +34 -0
  113. package/dist/KeyValueList.js +35 -0
  114. package/dist/Lightbox.d.ts +45 -0
  115. package/dist/Lightbox.js +46 -0
  116. package/dist/ListRow.d.ts +26 -0
  117. package/dist/ListRow.js +151 -0
  118. package/dist/Markdown.d.ts +11 -0
  119. package/dist/Markdown.js +49 -0
  120. package/dist/MediaTile.d.ts +66 -0
  121. package/dist/MediaTile.js +50 -0
  122. package/dist/Menu.d.ts +64 -0
  123. package/dist/Menu.js +86 -0
  124. package/dist/MetaList.d.ts +23 -0
  125. package/dist/MetaList.js +20 -0
  126. package/dist/Morph.d.ts +41 -0
  127. package/dist/Morph.js +107 -0
  128. package/dist/NavigationProgress.d.ts +20 -0
  129. package/dist/NavigationProgress.js +26 -0
  130. package/dist/OutlineRegion.d.ts +60 -0
  131. package/dist/OutlineRegion.js +51 -0
  132. package/dist/PageFade.d.ts +30 -0
  133. package/dist/PageFade.js +46 -0
  134. package/dist/PageHeader.d.ts +26 -0
  135. package/dist/PageHeader.js +18 -0
  136. package/dist/PageLayouts.d.ts +100 -0
  137. package/dist/PageLayouts.js +78 -0
  138. package/dist/Pagination.d.ts +38 -0
  139. package/dist/Pagination.js +65 -0
  140. package/dist/Pill.d.ts +79 -0
  141. package/dist/Pill.js +121 -0
  142. package/dist/ProgressBar.d.ts +47 -0
  143. package/dist/ProgressBar.js +47 -0
  144. package/dist/RadioGroup.d.ts +55 -0
  145. package/dist/RadioGroup.js +53 -0
  146. package/dist/ScrollStrip.d.ts +21 -0
  147. package/dist/ScrollStrip.js +12 -0
  148. package/dist/SearchInput.d.ts +9 -0
  149. package/dist/SearchInput.js +55 -0
  150. package/dist/Section.d.ts +93 -0
  151. package/dist/Section.js +55 -0
  152. package/dist/SegmentedControl.d.ts +47 -0
  153. package/dist/SegmentedControl.js +78 -0
  154. package/dist/Select.d.ts +28 -0
  155. package/dist/Select.js +19 -0
  156. package/dist/Show.d.ts +33 -0
  157. package/dist/Show.js +27 -0
  158. package/dist/SideColumn.d.ts +50 -0
  159. package/dist/SideColumn.js +45 -0
  160. package/dist/SidebarLayout.d.ts +32 -0
  161. package/dist/SidebarLayout.js +77 -0
  162. package/dist/SiteFooter.d.ts +31 -0
  163. package/dist/SiteFooter.js +24 -0
  164. package/dist/SiteSearch.d.ts +40 -0
  165. package/dist/SiteSearch.js +150 -0
  166. package/dist/SortableList.d.ts +86 -0
  167. package/dist/SortableList.js +191 -0
  168. package/dist/SplitBar.d.ts +29 -0
  169. package/dist/SplitBar.js +22 -0
  170. package/dist/Stack.d.ts +114 -0
  171. package/dist/Stack.js +76 -0
  172. package/dist/StackedBar.d.ts +64 -0
  173. package/dist/StackedBar.js +58 -0
  174. package/dist/StatTile.d.ts +33 -0
  175. package/dist/StatTile.js +44 -0
  176. package/dist/StatusPages.d.ts +49 -0
  177. package/dist/StatusPages.js +63 -0
  178. package/dist/Steps.d.ts +29 -0
  179. package/dist/Steps.js +43 -0
  180. package/dist/StickyBar.d.ts +12 -0
  181. package/dist/StickyBar.js +10 -0
  182. package/dist/Switch.d.ts +56 -0
  183. package/dist/Switch.js +91 -0
  184. package/dist/Table.d.ts +92 -0
  185. package/dist/Table.js +92 -0
  186. package/dist/TableCells.d.ts +97 -0
  187. package/dist/TableCells.js +104 -0
  188. package/dist/TableEditCell.d.ts +31 -0
  189. package/dist/TableEditCell.js +17 -0
  190. package/dist/TableExpandCell.d.ts +25 -0
  191. package/dist/TableExpandCell.js +15 -0
  192. package/dist/Tabs.d.ts +38 -0
  193. package/dist/Tabs.js +46 -0
  194. package/dist/TextLink.d.ts +51 -0
  195. package/dist/TextLink.js +38 -0
  196. package/dist/Textarea.d.ts +11 -0
  197. package/dist/Textarea.js +11 -0
  198. package/dist/Timeline.d.ts +31 -0
  199. package/dist/Timeline.js +38 -0
  200. package/dist/ToastRegion.d.ts +44 -0
  201. package/dist/ToastRegion.js +37 -0
  202. package/dist/Tooltip.d.ts +46 -0
  203. package/dist/Tooltip.js +181 -0
  204. package/dist/TrendChart.d.ts +36 -0
  205. package/dist/TrendChart.js +58 -0
  206. package/dist/Video.d.ts +13 -0
  207. package/dist/Video.js +9 -0
  208. package/dist/blocked.d.ts +31 -0
  209. package/dist/blocked.js +31 -0
  210. package/dist/cardContext.d.ts +8 -0
  211. package/dist/cardContext.js +14 -0
  212. package/dist/cardWait.d.ts +13 -0
  213. package/dist/cardWait.js +16 -0
  214. package/dist/colourScheme.d.ts +22 -0
  215. package/dist/colourScheme.js +53 -0
  216. package/dist/control.d.ts +29 -0
  217. package/dist/control.js +37 -0
  218. package/dist/copyScript.d.ts +13 -0
  219. package/dist/copyScript.js +13 -0
  220. package/dist/cx.d.ts +19 -0
  221. package/dist/cx.js +21 -0
  222. package/dist/density.d.ts +38 -0
  223. package/dist/density.js +77 -0
  224. package/dist/emptySlot.d.ts +11 -0
  225. package/dist/emptySlot.js +16 -0
  226. package/dist/fieldControl.d.ts +23 -0
  227. package/dist/fieldControl.js +24 -0
  228. package/dist/fieldWait.d.ts +30 -0
  229. package/dist/fieldWait.js +27 -0
  230. package/dist/foldedColumn.d.ts +18 -0
  231. package/dist/foldedColumn.js +51 -0
  232. package/dist/headingLevel.d.ts +10 -0
  233. package/dist/headingLevel.js +18 -0
  234. package/dist/highlight.d.ts +18 -0
  235. package/dist/highlight.js +306 -0
  236. package/dist/highlightConsole.d.ts +9 -0
  237. package/dist/highlightConsole.js +42 -0
  238. package/dist/highlightHtml.d.ts +7 -0
  239. package/dist/highlightHtml.js +132 -0
  240. package/dist/highlightKit.d.ts +16 -0
  241. package/dist/highlightKit.js +23 -0
  242. package/dist/highlightYaml.d.ts +3 -0
  243. package/dist/highlightYaml.js +143 -0
  244. package/dist/icons.d.ts +16 -0
  245. package/dist/icons.js +108 -0
  246. package/dist/index.d.ts +99 -0
  247. package/dist/index.js +92 -0
  248. package/dist/isoDate.d.ts +5 -0
  249. package/dist/isoDate.js +16 -0
  250. package/dist/labelWords.d.ts +20 -0
  251. package/dist/labelWords.js +28 -0
  252. package/dist/layoutWait.d.ts +15 -0
  253. package/dist/layoutWait.js +18 -0
  254. package/dist/link.d.ts +82 -0
  255. package/dist/link.js +68 -0
  256. package/dist/listRowProps.d.ts +108 -0
  257. package/dist/listRowProps.js +1 -0
  258. package/dist/listRowWait.d.ts +6 -0
  259. package/dist/listRowWait.js +14 -0
  260. package/dist/modal.d.ts +25 -0
  261. package/dist/modal.js +61 -0
  262. package/dist/navFold.d.ts +15 -0
  263. package/dist/navFold.js +46 -0
  264. package/dist/pillTip.d.ts +8 -0
  265. package/dist/pillTip.js +25 -0
  266. package/dist/props.d.ts +26 -0
  267. package/dist/props.js +14 -0
  268. package/dist/scrollEdges.d.ts +12 -0
  269. package/dist/scrollEdges.js +40 -0
  270. package/dist/scrollStop.d.ts +32 -0
  271. package/dist/scrollStop.js +79 -0
  272. package/dist/sheetSnap.d.ts +27 -0
  273. package/dist/sheetSnap.js +45 -0
  274. package/dist/shownDate.d.ts +88 -0
  275. package/dist/shownDate.js +186 -0
  276. package/dist/size.d.ts +45 -0
  277. package/dist/size.js +12 -0
  278. package/dist/skeleton.d.ts +83 -0
  279. package/dist/skeleton.js +88 -0
  280. package/dist/stackGap.d.ts +9 -0
  281. package/dist/stackGap.js +16 -0
  282. package/dist/stickyColumn.d.ts +38 -0
  283. package/dist/stickyColumn.js +38 -0
  284. package/dist/switcher.d.ts +93 -0
  285. package/dist/switcher.js +78 -0
  286. package/dist/tableColumns.d.ts +31 -0
  287. package/dist/tableColumns.js +72 -0
  288. package/dist/tableEmpty.d.ts +15 -0
  289. package/dist/tableEmpty.js +26 -0
  290. package/dist/tableRow.d.ts +67 -0
  291. package/dist/tableRow.js +49 -0
  292. package/dist/tableSort.d.ts +22 -0
  293. package/dist/tableSort.js +19 -0
  294. package/dist/textBox.d.ts +10 -0
  295. package/dist/textBox.js +23 -0
  296. package/dist/tone.d.ts +11 -0
  297. package/dist/tone.js +1 -0
  298. package/dist/trend.d.ts +26 -0
  299. package/dist/trend.js +64 -0
  300. package/dist/typography.d.ts +203 -0
  301. package/dist/typography.js +242 -0
  302. package/dist/useImageFailed.d.ts +19 -0
  303. package/dist/useImageFailed.js +21 -0
  304. package/package.json +84 -4
@@ -0,0 +1,30 @@
1
+ import type { ReactElement, ReactNode } from "react";
2
+ import type { Size } from "./size.js";
3
+ /** A bone the height of a text control at `size`, else the density around it (a `sm` table or card). */
4
+ export declare function ControlBone({ size }: {
5
+ size?: Size | undefined;
6
+ }): ReactElement;
7
+ /**
8
+ * A choice (a checkbox, a switch, a radio) waiting for its value: the mark a bone of its shape, the
9
+ * label drawn beside it, then the owner's hidden label.
10
+ */
11
+ export declare function WaitingChoice({ own, loadingLabel, label, look, shape, attrs, }: {
12
+ own: boolean | undefined;
13
+ loadingLabel: string | undefined;
14
+ label: ReactNode;
15
+ look: string;
16
+ shape: string;
17
+ attrs: object;
18
+ }): ReactElement;
19
+ /**
20
+ * A field with its own label (a date field) waiting for its value: the label drawn as `look` sets
21
+ * it, the control a bone of its height, then the owner's hidden label.
22
+ */
23
+ export declare function WaitingField({ own, loadingLabel, label, look, size, attrs, }: {
24
+ own: boolean | undefined;
25
+ loadingLabel: string | undefined;
26
+ label: ReactNode;
27
+ look: string;
28
+ size: Size | undefined;
29
+ attrs: object;
30
+ }): ReactElement;
@@ -0,0 +1,27 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { cx } from "./cx.js";
3
+ import { useDensity } from "./density.js";
4
+ import { Bone, BusyLabel, busy, passthroughOf, useLoading } from "./skeleton.js";
5
+ /* The bones of a form part waiting for its value: the label is drawn, the control is a bone. */
6
+ /** A text control's height by `size`: its padding, line height and border, as `controlClass` draws it. */
7
+ const CONTROL_HEIGHT = { sm: "h-6.5", md: "h-9.5", lg: "h-11.5" };
8
+ /** A bone the height of a text control at `size`, else the density around it (a `sm` table or card). */
9
+ export function ControlBone({ size }) {
10
+ return _jsx(Bone, { shape: cx("block w-full rounded-lg", CONTROL_HEIGHT[useDensity(size)]) });
11
+ }
12
+ /**
13
+ * A choice (a checkbox, a switch, a radio) waiting for its value: the mark a bone of its shape, the
14
+ * label drawn beside it, then the owner's hidden label.
15
+ */
16
+ export function WaitingChoice({ own, loadingLabel, label, look, shape, attrs, }) {
17
+ const { loading, owner } = useLoading(own);
18
+ return (_jsxs("span", { ...passthroughOf(attrs), ...busy(owner, loading), className: cx("inline-flex items-start text-slate-700", look), children: [_jsx(Bone, { shape: cx("shrink-0", shape) }), label != null && _jsx("span", { children: label }), _jsx(BusyLabel, { owner: owner, loading: loading, label: loadingLabel })] }));
19
+ }
20
+ /**
21
+ * A field with its own label (a date field) waiting for its value: the label drawn as `look` sets
22
+ * it, the control a bone of its height, then the owner's hidden label.
23
+ */
24
+ export function WaitingField({ own, loadingLabel, label, look, size, attrs, }) {
25
+ const { loading, owner } = useLoading(own);
26
+ return (_jsxs("div", { ...passthroughOf(attrs), ...busy(owner, loading), className: "flex flex-col gap-1.5", children: [label != null && _jsx("span", { className: look, children: label }), _jsx(ControlBone, { size: size }), _jsx(BusyLabel, { owner: owner, loading: loading, label: loadingLabel })] }));
27
+ }
@@ -0,0 +1,18 @@
1
+ import { type ReactElement, type ReactNode } from "react";
2
+ /** The breakpoint a folded column opens up at: below it the column sits behind a disclosure. */
3
+ export type FoldFrom = "md" | "lg" | "xl";
4
+ /**
5
+ * A side column that folds behind a native `<details>` disclosure named `label`, closed, below
6
+ * `from`, and is the same column, always open, from `from` up. The column stays mounted while it is
7
+ * folded, so state inside it is kept. Shared by `SidebarLayout` (`md`), `SideColumn` (`lg`) and `DocsLayout`'s contents list (`xl`).
8
+ *
9
+ * From `from` up the CSS shows the content of the closed `<details>` (the first frame, and a page
10
+ * that never hydrates). But a closed `<details>` is hidden to the accessibility tree and to axe, so
11
+ * once mounted an effect also opens it for real from `from` up and closes it again below. There is
12
+ * no `open` prop, so React never fights the browser's toggle and the server markup stays closed.
13
+ */
14
+ export declare function FoldedColumn({ from, label, children, }: {
15
+ from: FoldFrom;
16
+ label: string;
17
+ children: ReactNode;
18
+ }): ReactElement;
@@ -0,0 +1,51 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useEffect, useRef } from "react";
3
+ import { cx, focusRing } from "./cx.js";
4
+ // Each variant is written out whole, so Tailwind sees every class.
5
+ const FOLD = {
6
+ md: {
7
+ query: "(width >= 48rem)",
8
+ content: "md:[&::details-content]:[content-visibility:visible]",
9
+ summary: "md:hidden",
10
+ body: "md:mt-0",
11
+ },
12
+ lg: {
13
+ query: "(width >= 64rem)",
14
+ content: "lg:[&::details-content]:[content-visibility:visible]",
15
+ summary: "lg:hidden",
16
+ body: "lg:mt-0",
17
+ },
18
+ xl: {
19
+ query: "(width >= 80rem)",
20
+ content: "xl:[&::details-content]:[content-visibility:visible]",
21
+ summary: "xl:hidden",
22
+ body: "xl:mt-0",
23
+ },
24
+ };
25
+ /**
26
+ * A side column that folds behind a native `<details>` disclosure named `label`, closed, below
27
+ * `from`, and is the same column, always open, from `from` up. The column stays mounted while it is
28
+ * folded, so state inside it is kept. Shared by `SidebarLayout` (`md`), `SideColumn` (`lg`) and `DocsLayout`'s contents list (`xl`).
29
+ *
30
+ * From `from` up the CSS shows the content of the closed `<details>` (the first frame, and a page
31
+ * that never hydrates). But a closed `<details>` is hidden to the accessibility tree and to axe, so
32
+ * once mounted an effect also opens it for real from `from` up and closes it again below. There is
33
+ * no `open` prop, so React never fights the browser's toggle and the server markup stays closed.
34
+ */
35
+ export function FoldedColumn({ from, label, children, }) {
36
+ const fold = FOLD[from];
37
+ const details = useRef(null);
38
+ useEffect(() => {
39
+ const el = details.current;
40
+ if (!el || typeof window.matchMedia !== "function")
41
+ return undefined;
42
+ const wide = window.matchMedia(fold.query);
43
+ const sync = () => {
44
+ el.open = wide.matches;
45
+ };
46
+ sync();
47
+ wide.addEventListener("change", sync);
48
+ return () => wide.removeEventListener("change", sync);
49
+ }, [fold.query]);
50
+ return (_jsxs("details", { ref: details, className: cx("group", fold.content), children: [_jsxs("summary", { className: cx("flex cursor-pointer list-none items-center justify-between rounded-lg border border-slate-300 bg-white px-3 py-2 text-sm font-medium text-slate-900 select-none hover:bg-slate-50 [&::-webkit-details-marker]:hidden", fold.summary, focusRing), children: [label, _jsx("svg", { viewBox: "0 0 20 20", width: "16", height: "16", fill: "none", stroke: "currentColor", strokeWidth: "1.8", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", className: "shrink-0 text-slate-500 group-open:rotate-180", children: _jsx("path", { d: "M5 8l5 5 5-5" }) })] }), _jsx("div", { className: cx("mt-2", fold.body), children: children })] }));
51
+ }
@@ -0,0 +1,10 @@
1
+ import { type ReactElement, type ReactNode } from "react";
2
+ /** A heading level below the page's own `h1`. */
3
+ export type HeadingLevel = 2 | 3 | 4 | 5 | 6;
4
+ /** Sets the level of the heading that holds `children`. */
5
+ export declare function HeadingLevelProvider({ level, children, }: {
6
+ level: HeadingLevel;
7
+ children: ReactNode;
8
+ }): ReactElement;
9
+ /** A heading's level: its own, else one below the heading that holds it, never past 6. */
10
+ export declare function useHeadingLevel(level: HeadingLevel | undefined): HeadingLevel;
@@ -0,0 +1,18 @@
1
+ import { createContext, createElement, useContext } from "react";
2
+ /**
3
+ * The level of the nearest heading that holds what is inside: a `Section` or a titled `Card` sets
4
+ * its own, so a `Card` in a `Section` is a 3 and an `EmptyState` in that card a 4. With none it is
5
+ * the page's `h1`. Internal: not exported from the package.
6
+ */
7
+ const LevelContext = createContext(1);
8
+ /** The level one below each, stopping at 6. */
9
+ const NEXT = { 1: 2, 2: 3, 3: 4, 4: 5, 5: 6, 6: 6 };
10
+ /** Sets the level of the heading that holds `children`. */
11
+ export function HeadingLevelProvider({ level, children, }) {
12
+ return createElement(LevelContext.Provider, { value: level }, children);
13
+ }
14
+ /** A heading's level: its own, else one below the heading that holds it, never past 6. */
15
+ export function useHeadingLevel(level) {
16
+ const outer = useContext(LevelContext);
17
+ return level ?? NEXT[outer];
18
+ }
@@ -0,0 +1,18 @@
1
+ /**
2
+ * A small tokenizer for the languages the docs show. It splits code into coloured runs and nothing
3
+ * else: no HTML, no client JS. `CodeText` maps a run to a palette utility, so a theme recolours
4
+ * highlighted code exactly as it recolours everything else.
5
+ *
6
+ * The grammars are deliberately shallow: enough for examples, not a compiler front end. `text`
7
+ * returns the code as one plain run, so nothing is coloured where no language is named. The
8
+ * languages: `text`, `tsx`, `ts`, `js`, `json`, `bash`, `console` (a shell session: `$ ` commands
9
+ * scanned as bash, everything else output), `css`, `html` (with `<script>` scanned as JS and
10
+ * `<style>` as CSS) and `yaml`.
11
+ */
12
+ import type { Token } from "./highlightKit.js";
13
+ export { consoleCommands } from "./highlightConsole.js";
14
+ export type { Token, TokenKind } from "./highlightKit.js";
15
+ /** The languages a `CodeBlock` colours; `text` is plain, and `console` marks the commands of a terminal session. */
16
+ export type CodeLanguage = "text" | "tsx" | "ts" | "js" | "json" | "bash" | "console" | "css" | "html" | "yaml";
17
+ /** The coloured runs of `code`. The text of every token joined back together is `code`. */
18
+ export declare function highlight(code: string, language: CodeLanguage): Token[];
@@ -0,0 +1,306 @@
1
+ /**
2
+ * A small tokenizer for the languages the docs show. It splits code into coloured runs and nothing
3
+ * else: no HTML, no client JS. `CodeText` maps a run to a palette utility, so a theme recolours
4
+ * highlighted code exactly as it recolours everything else.
5
+ *
6
+ * The grammars are deliberately shallow: enough for examples, not a compiler front end. `text`
7
+ * returns the code as one plain run, so nothing is coloured where no language is named. The
8
+ * languages: `text`, `tsx`, `ts`, `js`, `json`, `bash`, `console` (a shell session: `$ ` commands
9
+ * scanned as bash, everything else output), `css`, `html` (with `<script>` scanned as JS and
10
+ * `<style>` as CSS) and `yaml`.
11
+ */
12
+ import { scanConsole } from "./highlightConsole.js";
13
+ import { scanHtml } from "./highlightHtml.js";
14
+ import { scanYaml } from "./highlightYaml.js";
15
+ export { consoleCommands } from "./highlightConsole.js";
16
+ /** The coloured runs of `code`. The text of every token joined back together is `code`. */
17
+ export function highlight(code, language) {
18
+ const tokens = [];
19
+ const emit = (kind, text) => {
20
+ if (text === "")
21
+ return;
22
+ const last = tokens.at(-1);
23
+ if (last !== undefined && last.kind === kind)
24
+ last.text += text;
25
+ else
26
+ tokens.push({ kind, text });
27
+ };
28
+ if (language === "text")
29
+ emit("plain", code);
30
+ else if (language === "bash")
31
+ scanBash(code, emit);
32
+ else if (language === "console")
33
+ scanConsole(code, emit, scanBash);
34
+ else if (language === "css")
35
+ scanCss(code, emit);
36
+ else if (language === "html")
37
+ scanHtml(code, emit, scanJs, scanCss);
38
+ else if (language === "yaml")
39
+ scanYaml(code, emit);
40
+ // JS, TS and TSX share one scanner. JSON is JS with no code around it: keys are strings,
41
+ // `true`/`false`/`null` are keywords.
42
+ else
43
+ scanJs(code, emit);
44
+ return tokens;
45
+ }
46
+ const isLetter = (c) => c !== "" && /[A-Za-z_$]/.test(c);
47
+ /** The first rule that matches at `at`, if any. Every pattern consumes at least one character. */
48
+ function match(rules, code, at) {
49
+ for (const rule of rules) {
50
+ rule.pattern.lastIndex = at;
51
+ const found = rule.pattern.exec(code);
52
+ if (found === null)
53
+ continue;
54
+ const end = at + found[0].length;
55
+ const kind = typeof rule.kind === "function" ? rule.kind(code, at, end) : rule.kind;
56
+ return { kind, end };
57
+ }
58
+ return undefined;
59
+ }
60
+ /** The index past the quoted run starting at `at`, or `undefined` when there is none there. */
61
+ function quotedEnd(code, at) {
62
+ const quote = code.charAt(at);
63
+ if (quote !== '"' && quote !== "'" && quote !== "`")
64
+ return undefined;
65
+ let i = at + 1;
66
+ while (i < code.length) {
67
+ const c = code.charAt(i);
68
+ if (c === "\\") {
69
+ i += 2;
70
+ continue;
71
+ }
72
+ if (c === quote)
73
+ return i + 1;
74
+ if (c === "\n" && quote !== "`")
75
+ return i;
76
+ i += 1;
77
+ }
78
+ return code.length;
79
+ }
80
+ const STRING_RULES = [
81
+ { pattern: /"(?:\\.|[^"\\\n])*"?/y, kind: "string" },
82
+ { pattern: /'(?:\\.|[^'\\\n])*'?/y, kind: "string" },
83
+ { pattern: /`(?:\\.|[^`\\])*`?/y, kind: "string" },
84
+ ];
85
+ const JS_KEYWORDS = new Set(("as async await break case catch class const continue default delete do else export " +
86
+ "extends false finally for from function if import in instanceof interface let new " +
87
+ "null of return satisfies static super switch this throw true try type typeof " +
88
+ "undefined var void while yield").split(" "));
89
+ /** The first character past `from` that is not a space. */
90
+ function afterSpace(code, from) {
91
+ let i = from;
92
+ while (code.charAt(i) === " ")
93
+ i += 1;
94
+ return code.charAt(i);
95
+ }
96
+ const JS_RULES = [
97
+ { pattern: /\/\/[^\n]*/y, kind: "comment" },
98
+ { pattern: /\/\*[\s\S]*?(?:\*\/|$)/y, kind: "comment" },
99
+ ...STRING_RULES,
100
+ { pattern: /\d[\w.]*/y, kind: "number" },
101
+ {
102
+ pattern: /[A-Za-z_$][\w$]*/y,
103
+ kind: (code, start, end) => {
104
+ if (JS_KEYWORDS.has(code.slice(start, end)))
105
+ return "keyword";
106
+ return afterSpace(code, end) === "(" ? "function" : "plain";
107
+ },
108
+ },
109
+ ];
110
+ /** `\w`-style names in a tag, including the dashes of `aria-label` and `data-testid`. */
111
+ const TAG_NAME_RULE = { pattern: /[A-Za-z_$][\w$-]*/y, kind: "tag" };
112
+ const ATTR_RULE = { pattern: /[A-Za-z_$][\w$-]*/y, kind: "attr" };
113
+ function take(scan, token) {
114
+ scan.emit(token.kind, scan.code.slice(scan.at, token.end));
115
+ scan.at = token.end;
116
+ }
117
+ function takeChar(scan) {
118
+ scan.emit("plain", scan.code.charAt(scan.at));
119
+ scan.at += 1;
120
+ }
121
+ /** `<Name` or `</Name` opens an element here; in children text a fragment `<>` does too. */
122
+ function opensElement(code, at) {
123
+ const next = code.charAt(at + 1);
124
+ if (next === "/")
125
+ return isLetter(code.charAt(at + 2));
126
+ return next === ">" || isLetter(next);
127
+ }
128
+ function openElement(scan) {
129
+ const next = scan.code.charAt(scan.at + 1);
130
+ scan.closing = next === "/";
131
+ scan.openedFrom = scan.mode;
132
+ scan.emit("plain", scan.closing ? "</" : "<");
133
+ scan.at += scan.closing ? 2 : 1;
134
+ scan.mode = "tag";
135
+ const name = match([TAG_NAME_RULE], scan.code, scan.at);
136
+ if (name !== undefined)
137
+ take(scan, name);
138
+ }
139
+ function endTag(scan) {
140
+ const selfClosed = scan.code.charAt(scan.at - 1) === "/";
141
+ takeChar(scan);
142
+ if (scan.closing)
143
+ scan.mode = scan.elements.pop() ?? "children";
144
+ else if (selfClosed)
145
+ scan.mode = scan.openedFrom;
146
+ else {
147
+ scan.elements.push(scan.openedFrom);
148
+ scan.mode = "children";
149
+ }
150
+ }
151
+ function openBrace(scan, back) {
152
+ scan.expressions.push({ back, depth: 0 });
153
+ scan.mode = "js";
154
+ takeChar(scan);
155
+ }
156
+ /** In code, `{` only deepens the JSX expression it is already inside. */
157
+ function openNestedBrace(scan) {
158
+ const open = scan.expressions.at(-1);
159
+ if (open !== undefined)
160
+ open.depth += 1;
161
+ takeChar(scan);
162
+ }
163
+ function closeBrace(scan) {
164
+ const open = scan.expressions.at(-1);
165
+ if (open === undefined) {
166
+ takeChar(scan);
167
+ return;
168
+ }
169
+ if (open.depth === 0) {
170
+ scan.expressions.pop();
171
+ scan.mode = open.back;
172
+ }
173
+ else
174
+ open.depth -= 1;
175
+ takeChar(scan);
176
+ }
177
+ function codeStep(scan) {
178
+ const c = scan.code.charAt(scan.at);
179
+ if (c === "<" && opensElement(scan.code, scan.at))
180
+ return openElement(scan);
181
+ if (c === "{")
182
+ return openNestedBrace(scan);
183
+ if (c === "}")
184
+ return closeBrace(scan);
185
+ const token = match(JS_RULES, scan.code, scan.at);
186
+ if (token !== undefined)
187
+ return take(scan, token);
188
+ takeChar(scan);
189
+ }
190
+ function tagStep(scan) {
191
+ const c = scan.code.charAt(scan.at);
192
+ if (c === "{")
193
+ return openBrace(scan, "tag");
194
+ if (c === ">")
195
+ return endTag(scan);
196
+ const quoted = quotedEnd(scan.code, scan.at);
197
+ if (quoted !== undefined)
198
+ return take(scan, { kind: "string", end: quoted });
199
+ const token = match([ATTR_RULE], scan.code, scan.at);
200
+ if (token !== undefined)
201
+ return take(scan, token);
202
+ takeChar(scan);
203
+ }
204
+ function childrenStep(scan) {
205
+ const c = scan.code.charAt(scan.at);
206
+ if (c === "{")
207
+ return openBrace(scan, "children");
208
+ if (c === "<" && opensElement(scan.code, scan.at))
209
+ return openElement(scan);
210
+ takeChar(scan);
211
+ }
212
+ /**
213
+ * JS, TS and TSX. Three modes (code, inside a tag, and children text) keep an apostrophe in
214
+ * `<p>Don't</p>` as text rather than the start of a runaway string, and every open element records
215
+ * the mode to return to, so a `{…}` expression that holds JSX closes back into code.
216
+ */
217
+ function scanJs(code, emit) {
218
+ const scan = {
219
+ code,
220
+ emit,
221
+ at: 0,
222
+ mode: "js",
223
+ elements: [],
224
+ expressions: [],
225
+ closing: false,
226
+ openedFrom: "js",
227
+ };
228
+ while (scan.at < code.length) {
229
+ if (scan.mode === "js")
230
+ codeStep(scan);
231
+ else if (scan.mode === "tag")
232
+ tagStep(scan);
233
+ else
234
+ childrenStep(scan);
235
+ }
236
+ }
237
+ /** A `#` comment reaches its line end; it starts only at the start of a line or after a space. */
238
+ function bashCommentEnd(code, at) {
239
+ if (code.charAt(at) !== "#")
240
+ return undefined;
241
+ if (at > 0 && !/\s/.test(code.charAt(at - 1)))
242
+ return undefined;
243
+ const newline = code.indexOf("\n", at);
244
+ return newline === -1 ? code.length : newline;
245
+ }
246
+ /** A word of a shell command: a quoted string, a `-flag`, or a run of path characters. */
247
+ function bashWord(code, at, isCommand) {
248
+ const quoted = quotedEnd(code, at);
249
+ if (quoted !== undefined)
250
+ return { kind: "string", end: quoted };
251
+ const token = match([
252
+ { pattern: /-{1,2}[\w-]+/y, kind: "attr" },
253
+ { pattern: /[A-Za-z0-9_./@:~+-]+/y, kind: isCommand ? "function" : "plain" },
254
+ ], code, at);
255
+ return token;
256
+ }
257
+ function scanBash(code, emit) {
258
+ let at = 0;
259
+ /** The next word is the command: the line's first word, or one after `&&`, `|` or `;`. */
260
+ let isCommand = true;
261
+ while (at < code.length) {
262
+ const comment = bashCommentEnd(code, at);
263
+ if (comment !== undefined) {
264
+ emit("comment", code.slice(at, comment));
265
+ at = comment;
266
+ continue;
267
+ }
268
+ const word = bashWord(code, at, isCommand);
269
+ if (word !== undefined) {
270
+ emit(word.kind, code.slice(at, word.end));
271
+ at = word.end;
272
+ isCommand = false;
273
+ continue;
274
+ }
275
+ const c = code.charAt(at);
276
+ if (c === "\n" || c === "&" || c === "|" || c === ";")
277
+ isCommand = true;
278
+ emit("plain", c);
279
+ at += 1;
280
+ }
281
+ }
282
+ const CSS_RULES = [
283
+ { pattern: /\/\*[\s\S]*?(?:\*\/|$)/y, kind: "comment" },
284
+ ...STRING_RULES,
285
+ { pattern: /@[\w-]+/y, kind: "keyword" },
286
+ { pattern: /#[\w]+/y, kind: "number" },
287
+ { pattern: /\d[\w.]*/y, kind: "number" },
288
+ {
289
+ // A property name is a word before `:`; anything else is a selector or a value.
290
+ pattern: /-?[A-Za-z][\w-]*/y,
291
+ kind: (code, _start, end) => (afterSpace(code, end) === ":" ? "attr" : "plain"),
292
+ },
293
+ ];
294
+ function scanCss(code, emit) {
295
+ let at = 0;
296
+ while (at < code.length) {
297
+ const token = match(CSS_RULES, code, at);
298
+ if (token !== undefined) {
299
+ emit(token.kind, code.slice(at, token.end));
300
+ at = token.end;
301
+ continue;
302
+ }
303
+ emit("plain", code.charAt(at));
304
+ at += 1;
305
+ }
306
+ }
@@ -0,0 +1,9 @@
1
+ import type { Emit, Scanner } from "./highlightKit.js";
2
+ /** A shell session: `$ ` is the prompt, the command after it is bash, other lines are output. */
3
+ export declare function scanConsole(code: string, emit: Emit, bash: Scanner): void;
4
+ /**
5
+ * What a console block's copy button copies: each command without its `$ `, plus the lines that
6
+ * continue it as written (the trailing `\\` and the indentation kept, so the paste runs), joined by
7
+ * newlines. Output is left out. A block with no `$ ` line has no commands, so it is copied as given.
8
+ */
9
+ export declare function consoleCommands(code: string): string;
@@ -0,0 +1,42 @@
1
+ import { splitLines } from "./highlightKit.js";
2
+ const CONSOLE_PROMPT = "$ ";
3
+ /**
4
+ * The lines of a console session, marked: a line that starts with `$ ` is a command (`prompt`), and
5
+ * so is every line after a command line that ends with `\\`, which continues it. The rest is output.
6
+ */
7
+ function consoleLines(code) {
8
+ let continued = false;
9
+ return splitLines(code).map(({ body, eol }) => {
10
+ const prompt = !continued && body.startsWith(CONSOLE_PROMPT);
11
+ const command = prompt || continued;
12
+ continued = command && body.endsWith("\\");
13
+ return { body, eol, command, prompt };
14
+ });
15
+ }
16
+ /** A shell session: `$ ` is the prompt, the command after it is bash, other lines are output. */
17
+ export function scanConsole(code, emit, bash) {
18
+ for (const { body, eol, command, prompt } of consoleLines(code)) {
19
+ if (prompt)
20
+ emit("prompt", CONSOLE_PROMPT);
21
+ const text = prompt ? body.slice(CONSOLE_PROMPT.length) : body;
22
+ if (command)
23
+ bash(text, emit);
24
+ else
25
+ emit("plain", text);
26
+ emit("plain", eol);
27
+ }
28
+ }
29
+ /**
30
+ * What a console block's copy button copies: each command without its `$ `, plus the lines that
31
+ * continue it as written (the trailing `\\` and the indentation kept, so the paste runs), joined by
32
+ * newlines. Output is left out. A block with no `$ ` line has no commands, so it is copied as given.
33
+ */
34
+ export function consoleCommands(code) {
35
+ const lines = consoleLines(code);
36
+ if (!lines.some((line) => line.prompt))
37
+ return code;
38
+ return lines
39
+ .filter((line) => line.command)
40
+ .map((line) => (line.prompt ? line.body.slice(CONSOLE_PROMPT.length) : line.body))
41
+ .join("\n");
42
+ }
@@ -0,0 +1,7 @@
1
+ import type { Emit, Scanner } from "./highlightKit.js";
2
+ /**
3
+ * HTML: comments, the doctype, tags with their attributes (a start tag may span lines), and text,
4
+ * which is plain. The content of `<script>` and `<style>` runs to the first closing tag of that
5
+ * name, wherever it falls, and is scanned with `script` (JS) or `style` (CSS).
6
+ */
7
+ export declare function scanHtml(code: string, emit: Emit, script: Scanner, style: Scanner): void;