@surfaces-ui/components 0.0.0-stage → 0.2.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 (264) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +4 -0
  3. package/README.md +48 -2
  4. package/dist/appComponents.d.ts +86 -0
  5. package/dist/appComponents.js +555 -0
  6. package/dist/appComponents.js.map +1 -0
  7. package/dist/chart/BulletGraph.d.ts +44 -0
  8. package/dist/chart/BulletGraph.js +40 -0
  9. package/dist/chart/BulletGraph.js.map +1 -0
  10. package/dist/chart/Chart.d.ts +177 -0
  11. package/dist/chart/Chart.js +279 -0
  12. package/dist/chart/Chart.js.map +1 -0
  13. package/dist/chart/Sparkline.d.ts +35 -0
  14. package/dist/chart/Sparkline.js +37 -0
  15. package/dist/chart/Sparkline.js.map +1 -0
  16. package/dist/chart/advice.d.ts +28 -0
  17. package/dist/chart/advice.js +39 -0
  18. package/dist/chart/advice.js.map +1 -0
  19. package/dist/chart/option.d.ts +90 -0
  20. package/dist/chart/option.js +252 -0
  21. package/dist/chart/option.js.map +1 -0
  22. package/dist/controls/Combobox.d.ts +39 -0
  23. package/dist/controls/Combobox.js +75 -0
  24. package/dist/controls/Combobox.js.map +1 -0
  25. package/dist/controls/ConfirmDialog.d.ts +35 -0
  26. package/dist/controls/ConfirmDialog.js +84 -0
  27. package/dist/controls/ConfirmDialog.js.map +1 -0
  28. package/dist/controls/ItemControls.d.ts +115 -0
  29. package/dist/controls/ItemControls.js +109 -0
  30. package/dist/controls/ItemControls.js.map +1 -0
  31. package/dist/controls/Popover.d.ts +31 -0
  32. package/dist/controls/Popover.js +114 -0
  33. package/dist/controls/Popover.js.map +1 -0
  34. package/dist/controls/ResizeHandle.d.ts +48 -0
  35. package/dist/controls/ResizeHandle.js +91 -0
  36. package/dist/controls/ResizeHandle.js.map +1 -0
  37. package/dist/controls/SegmentedControl.d.ts +27 -0
  38. package/dist/controls/SegmentedControl.js +17 -0
  39. package/dist/controls/SegmentedControl.js.map +1 -0
  40. package/dist/controls/StatusBadge.d.ts +17 -0
  41. package/dist/controls/StatusBadge.js +10 -0
  42. package/dist/controls/StatusBadge.js.map +1 -0
  43. package/dist/controls/context.d.ts +17 -0
  44. package/dist/controls/context.js +2 -0
  45. package/dist/controls/context.js.map +1 -0
  46. package/dist/controls/placement.d.ts +43 -0
  47. package/dist/controls/placement.js +19 -0
  48. package/dist/controls/placement.js.map +1 -0
  49. package/dist/controls/resize.d.ts +23 -0
  50. package/dist/controls/resize.js +49 -0
  51. package/dist/controls/resize.js.map +1 -0
  52. package/dist/data/DataSourceProvider.d.ts +11 -0
  53. package/dist/data/DataSourceProvider.js +21 -0
  54. package/dist/data/DataSourceProvider.js.map +1 -0
  55. package/dist/data/export.d.ts +33 -0
  56. package/dist/data/export.js +77 -0
  57. package/dist/data/export.js.map +1 -0
  58. package/dist/data/format.d.ts +44 -0
  59. package/dist/data/format.js +127 -0
  60. package/dist/data/format.js.map +1 -0
  61. package/dist/data/messages.d.ts +13 -0
  62. package/dist/data/messages.js +2 -0
  63. package/dist/data/messages.js.map +1 -0
  64. package/dist/data/useRowWindow.d.ts +70 -0
  65. package/dist/data/useRowWindow.js +175 -0
  66. package/dist/data/useRowWindow.js.map +1 -0
  67. package/dist/discovery/AskData.d.ts +22 -0
  68. package/dist/discovery/AskData.js +48 -0
  69. package/dist/discovery/AskData.js.map +1 -0
  70. package/dist/discovery/ContextBuilder.d.ts +49 -0
  71. package/dist/discovery/ContextBuilder.js +167 -0
  72. package/dist/discovery/ContextBuilder.js.map +1 -0
  73. package/dist/discovery/DataSearch.d.ts +27 -0
  74. package/dist/discovery/DataSearch.js +73 -0
  75. package/dist/discovery/DataSearch.js.map +1 -0
  76. package/dist/discovery/ObjectDetail.d.ts +38 -0
  77. package/dist/discovery/ObjectDetail.js +129 -0
  78. package/dist/discovery/ObjectDetail.js.map +1 -0
  79. package/dist/discovery/RelationshipGraph.d.ts +19 -0
  80. package/dist/discovery/RelationshipGraph.js +64 -0
  81. package/dist/discovery/RelationshipGraph.js.map +1 -0
  82. package/dist/discovery/shared.d.ts +38 -0
  83. package/dist/discovery/shared.js +64 -0
  84. package/dist/discovery/shared.js.map +1 -0
  85. package/dist/editor/SqlEditor.d.ts +41 -0
  86. package/dist/editor/SqlEditor.js +181 -0
  87. package/dist/editor/SqlEditor.js.map +1 -0
  88. package/dist/explore/Explorer.d.ts +110 -0
  89. package/dist/explore/Explorer.js +471 -0
  90. package/dist/explore/Explorer.js.map +1 -0
  91. package/dist/explore/ModelLineage.d.ts +22 -0
  92. package/dist/explore/ModelLineage.js +70 -0
  93. package/dist/explore/ModelLineage.js.map +1 -0
  94. package/dist/explore/ReportBuilder.d.ts +39 -0
  95. package/dist/explore/ReportBuilder.js +98 -0
  96. package/dist/explore/ReportBuilder.js.map +1 -0
  97. package/dist/explore/SemanticModelEditor.d.ts +60 -0
  98. package/dist/explore/SemanticModelEditor.js +220 -0
  99. package/dist/explore/SemanticModelEditor.js.map +1 -0
  100. package/dist/explore/SemanticRows.d.ts +42 -0
  101. package/dist/explore/SemanticRows.js +117 -0
  102. package/dist/explore/SemanticRows.js.map +1 -0
  103. package/dist/explore/SemanticsProvider.d.ts +31 -0
  104. package/dist/explore/SemanticsProvider.js +72 -0
  105. package/dist/explore/SemanticsProvider.js.map +1 -0
  106. package/dist/explore/model.d.ts +151 -0
  107. package/dist/explore/model.js +344 -0
  108. package/dist/explore/model.js.map +1 -0
  109. package/dist/explore/report.d.ts +60 -0
  110. package/dist/explore/report.js +92 -0
  111. package/dist/explore/report.js.map +1 -0
  112. package/dist/explore/semantic-proposal.d.ts +44 -0
  113. package/dist/explore/semantic-proposal.js +67 -0
  114. package/dist/explore/semantic-proposal.js.map +1 -0
  115. package/dist/explore/semantic.d.ts +44 -0
  116. package/dist/explore/semantic.js +154 -0
  117. package/dist/explore/semantic.js.map +1 -0
  118. package/dist/files/FileBrowser.d.ts +42 -0
  119. package/dist/files/FileBrowser.js +314 -0
  120. package/dist/files/FileBrowser.js.map +1 -0
  121. package/dist/files/files.d.ts +65 -0
  122. package/dist/files/files.js +165 -0
  123. package/dist/files/files.js.map +1 -0
  124. package/dist/filter/FilterBar.d.ts +49 -0
  125. package/dist/filter/FilterBar.js +153 -0
  126. package/dist/filter/FilterBar.js.map +1 -0
  127. package/dist/filter/QueryFilters.d.ts +25 -0
  128. package/dist/filter/QueryFilters.js +58 -0
  129. package/dist/filter/QueryFilters.js.map +1 -0
  130. package/dist/form/Form.d.ts +76 -0
  131. package/dist/form/Form.js +131 -0
  132. package/dist/form/Form.js.map +1 -0
  133. package/dist/graph/NodeGraph.d.ts +30 -0
  134. package/dist/graph/NodeGraph.js +86 -0
  135. package/dist/graph/NodeGraph.js.map +1 -0
  136. package/dist/graph/model.d.ts +68 -0
  137. package/dist/graph/model.js +122 -0
  138. package/dist/graph/model.js.map +1 -0
  139. package/dist/grid/DataGrid.d.ts +98 -0
  140. package/dist/grid/DataGrid.js +399 -0
  141. package/dist/grid/DataGrid.js.map +1 -0
  142. package/dist/index.d.ts +84 -0
  143. package/dist/index.js +86 -0
  144. package/dist/index.js.map +1 -0
  145. package/dist/locale/SurfacesText.d.ts +17 -0
  146. package/dist/locale/SurfacesText.js +17 -0
  147. package/dist/locale/SurfacesText.js.map +1 -0
  148. package/dist/locale/locale.d.ts +305 -0
  149. package/dist/locale/locale.js +359 -0
  150. package/dist/locale/locale.js.map +1 -0
  151. package/dist/menu/ContextMenu.d.ts +31 -0
  152. package/dist/menu/ContextMenu.js +95 -0
  153. package/dist/menu/ContextMenu.js.map +1 -0
  154. package/dist/metric/Metric.d.ts +33 -0
  155. package/dist/metric/Metric.js +63 -0
  156. package/dist/metric/Metric.js.map +1 -0
  157. package/dist/metric/useMeasure.d.ts +23 -0
  158. package/dist/metric/useMeasure.js +43 -0
  159. package/dist/metric/useMeasure.js.map +1 -0
  160. package/dist/model/ModelDiagram.d.ts +142 -0
  161. package/dist/model/ModelDiagram.js +699 -0
  162. package/dist/model/ModelDiagram.js.map +1 -0
  163. package/dist/panzoom/usePanZoom.d.ts +117 -0
  164. package/dist/panzoom/usePanZoom.js +313 -0
  165. package/dist/panzoom/usePanZoom.js.map +1 -0
  166. package/dist/pipeline/DatasetReview.d.ts +48 -0
  167. package/dist/pipeline/DatasetReview.js +157 -0
  168. package/dist/pipeline/DatasetReview.js.map +1 -0
  169. package/dist/pipeline/IngestWizard.d.ts +51 -0
  170. package/dist/pipeline/IngestWizard.js +79 -0
  171. package/dist/pipeline/IngestWizard.js.map +1 -0
  172. package/dist/pipeline/Pipeline.d.ts +171 -0
  173. package/dist/pipeline/Pipeline.js +203 -0
  174. package/dist/pipeline/Pipeline.js.map +1 -0
  175. package/dist/pipeline/PipelineView.d.ts +63 -0
  176. package/dist/pipeline/PipelineView.js +239 -0
  177. package/dist/pipeline/PipelineView.js.map +1 -0
  178. package/dist/pivot/PivotTable.d.ts +94 -0
  179. package/dist/pivot/PivotTable.js +171 -0
  180. package/dist/pivot/PivotTable.js.map +1 -0
  181. package/dist/plan/QueryPlan.d.ts +29 -0
  182. package/dist/plan/QueryPlan.js +79 -0
  183. package/dist/plan/QueryPlan.js.map +1 -0
  184. package/dist/result/QueryResult.d.ts +51 -0
  185. package/dist/result/QueryResult.js +255 -0
  186. package/dist/result/QueryResult.js.map +1 -0
  187. package/dist/review/ActionReceipt.d.ts +52 -0
  188. package/dist/review/ActionReceipt.js +32 -0
  189. package/dist/review/ActionReceipt.js.map +1 -0
  190. package/dist/review/PiiReview.d.ts +37 -0
  191. package/dist/review/PiiReview.js +29 -0
  192. package/dist/review/PiiReview.js.map +1 -0
  193. package/dist/review/PlanReview.d.ts +42 -0
  194. package/dist/review/PlanReview.js +37 -0
  195. package/dist/review/PlanReview.js.map +1 -0
  196. package/dist/review/StepFlow.d.ts +25 -0
  197. package/dist/review/StepFlow.js +21 -0
  198. package/dist/review/StepFlow.js.map +1 -0
  199. package/dist/review/pii.d.ts +21 -0
  200. package/dist/review/pii.js +67 -0
  201. package/dist/review/pii.js.map +1 -0
  202. package/dist/rows/RowList.d.ts +41 -0
  203. package/dist/rows/RowList.js +71 -0
  204. package/dist/rows/RowList.js.map +1 -0
  205. package/dist/schema/ObjectBrowser.d.ts +78 -0
  206. package/dist/schema/ObjectBrowser.js +467 -0
  207. package/dist/schema/ObjectBrowser.js.map +1 -0
  208. package/dist/schema/ObjectInfo.d.ts +25 -0
  209. package/dist/schema/ObjectInfo.js +69 -0
  210. package/dist/schema/ObjectInfo.js.map +1 -0
  211. package/dist/schema/SchemaExplorer.d.ts +32 -0
  212. package/dist/schema/SchemaExplorer.js +175 -0
  213. package/dist/schema/SchemaExplorer.js.map +1 -0
  214. package/dist/schema/refs.d.ts +32 -0
  215. package/dist/schema/refs.js +65 -0
  216. package/dist/schema/refs.js.map +1 -0
  217. package/dist/site/Site.d.ts +191 -0
  218. package/dist/site/Site.js +138 -0
  219. package/dist/site/Site.js.map +1 -0
  220. package/dist/source/ConnectionBuilder.d.ts +54 -0
  221. package/dist/source/ConnectionBuilder.js +115 -0
  222. package/dist/source/ConnectionBuilder.js.map +1 -0
  223. package/dist/source/SourceList.d.ts +17 -0
  224. package/dist/source/SourceList.js +71 -0
  225. package/dist/source/SourceList.js.map +1 -0
  226. package/dist/styles.css +9882 -0
  227. package/dist/styles.layer.css +9886 -0
  228. package/dist/table/DataTable.d.ts +72 -0
  229. package/dist/table/DataTable.js +68 -0
  230. package/dist/table/DataTable.js.map +1 -0
  231. package/dist/table/Pagination.d.ts +20 -0
  232. package/dist/table/Pagination.js +16 -0
  233. package/dist/table/Pagination.js.map +1 -0
  234. package/dist/table/SelectionBar.d.ts +43 -0
  235. package/dist/table/SelectionBar.js +18 -0
  236. package/dist/table/SelectionBar.js.map +1 -0
  237. package/dist/text/Markdown.d.ts +71 -0
  238. package/dist/text/Markdown.js +187 -0
  239. package/dist/text/Markdown.js.map +1 -0
  240. package/dist/text/highlight.d.ts +23 -0
  241. package/dist/text/highlight.js +196 -0
  242. package/dist/text/highlight.js.map +1 -0
  243. package/dist/theme/ThemePicker.d.ts +16 -0
  244. package/dist/theme/ThemePicker.js +49 -0
  245. package/dist/theme/ThemePicker.js.map +1 -0
  246. package/dist/theme/ThemeProvider.d.ts +43 -0
  247. package/dist/theme/ThemeProvider.js +107 -0
  248. package/dist/theme/ThemeProvider.js.map +1 -0
  249. package/dist/workspace/NavBar.d.ts +23 -0
  250. package/dist/workspace/NavBar.js +171 -0
  251. package/dist/workspace/NavBar.js.map +1 -0
  252. package/dist/workspace/SideNav.d.ts +61 -0
  253. package/dist/workspace/SideNav.js +149 -0
  254. package/dist/workspace/SideNav.js.map +1 -0
  255. package/dist/workspace/Workspace.d.ts +50 -0
  256. package/dist/workspace/Workspace.js +243 -0
  257. package/dist/workspace/Workspace.js.map +1 -0
  258. package/dist/workspace/icons.d.ts +34 -0
  259. package/dist/workspace/icons.js +37 -0
  260. package/dist/workspace/icons.js.map +1 -0
  261. package/dist/workspace/layout.d.ts +74 -0
  262. package/dist/workspace/layout.js +276 -0
  263. package/dist/workspace/layout.js.map +1 -0
  264. package/package.json +85 -3
@@ -0,0 +1,23 @@
1
+ import { type ReactNode } from "react";
2
+ import { type SideNavGroup } from "./SideNav.js";
3
+ export interface NavBarProps {
4
+ /** What the navigation is for, for assistive technology: "Surfaces UI". */
5
+ label: string;
6
+ /**
7
+ * The sections and their pages: the same groups `SideNav` takes. Each group's label is a section in the bar; the
8
+ * section holding the current page shows its pages in a second bar beneath. A group with no label is shown under the
9
+ * name "More".
10
+ */
11
+ groups: SideNavGroup[];
12
+ /** The id of the item for the page being shown. */
13
+ current?: string;
14
+ onSelect?(id: string): void;
15
+ /** At the bar's start: a name or a mark. Pressing it is the host's to decide. */
16
+ brand?: ReactNode;
17
+ /** At the bar's end: a status, a picker. On a narrow screen it moves into the menu. */
18
+ actions?: ReactNode;
19
+ className?: string;
20
+ }
21
+ /** Below this width the sections fold into a menu that covers the screen. */
22
+ export declare const NAVBAR_NARROW = "(max-width: 48rem)";
23
+ export declare function NavBar({ label, groups, current, onSelect, brand, actions, className }: NavBarProps): import("react").JSX.Element;
@@ -0,0 +1,171 @@
1
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useEffect, useId, useLayoutEffect, useRef, useState } from "react";
3
+ import { ControlIcon } from "../controls/ItemControls.js";
4
+ import { navigationName } from "./SideNav.js";
5
+ /** Below this width the sections fold into a menu that covers the screen. */
6
+ export const NAVBAR_NARROW = "(max-width: 48rem)";
7
+ const FOCUSABLE = 'a[href], button:not([disabled]), select:not([disabled]), input:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])';
8
+ function useMedia(query) {
9
+ const get = () => (typeof window !== "undefined" && typeof window.matchMedia === "function" ? window.matchMedia(query) : undefined);
10
+ const [matches, setMatches] = useState(() => get()?.matches ?? false);
11
+ useEffect(() => {
12
+ const media = get();
13
+ if (!media)
14
+ return;
15
+ const change = () => setMatches(media.matches);
16
+ change();
17
+ media.addEventListener("change", change);
18
+ return () => media.removeEventListener("change", change);
19
+ // biome-ignore lint/correctness/useExhaustiveDependencies: the query is fixed for the component's life.
20
+ }, [query]);
21
+ return matches;
22
+ }
23
+ /** True once the page has scrolled, so the bar can show the edge between it and the content passing beneath. */
24
+ function useScrolled() {
25
+ const [scrolled, setScrolled] = useState(false);
26
+ useEffect(() => {
27
+ if (typeof window === "undefined")
28
+ return;
29
+ const check = () => setScrolled(window.scrollY > 0);
30
+ check();
31
+ window.addEventListener("scroll", check, { passive: true });
32
+ return () => window.removeEventListener("scroll", check);
33
+ }, []);
34
+ return scrolled;
35
+ }
36
+ const sectionOf = (groups, id) => groups.findIndex((g) => g.items.some((i) => i.id === id));
37
+ const sectionLabel = (group) => group.label ?? "More";
38
+ function ItemLink({ item, current, onChoose, className }) {
39
+ const here = item.id === current ? "page" : undefined;
40
+ if (item.href) {
41
+ return (_jsx("a", { className: className, href: item.href, "aria-current": here, onClick: () => onChoose(item.id), children: item.label }));
42
+ }
43
+ return (_jsx("button", { type: "button", className: className, "aria-current": here, onClick: () => onChoose(item.id), children: item.label }));
44
+ }
45
+ /**
46
+ * Navigation across the top of a site, after Apple's: a bar of sections that stays at the top on glass, and beneath
47
+ * it a second bar with the current section's name and its pages. A section goes to its first page. Content scrolls
48
+ * under both, and an edge appears once it does. On a narrow screen the sections fold into a menu button that opens
49
+ * every section and page over the whole screen, as a dialog: focus goes in and stays there until Escape, the close
50
+ * button or a choice closes it, then goes back to the menu button. The second bar stays, its pages scrolling sideways.
51
+ */
52
+ /**
53
+ * Puts one highlight under the current item of a list, as CSS variables on the list (`--sf-indicator-x`, `-y`, `-w`,
54
+ * `-h`), so the highlight slides from item to item instead of jumping. `group` names which set of items the list
55
+ * holds: when it changes the items are new, and the highlight is placed without sliding. A list whose size changes
56
+ * (a wider window, a font loading) moves it at once too.
57
+ */
58
+ function useIndicator(list, selector, current, group) {
59
+ const shownGroup = useRef(group);
60
+ useLayoutEffect(() => {
61
+ const ul = list.current;
62
+ if (!ul)
63
+ return;
64
+ const place = (instant) => {
65
+ const item = ul.querySelector(selector);
66
+ if (!item) {
67
+ ul.removeAttribute("data-indicator");
68
+ return;
69
+ }
70
+ if (instant)
71
+ ul.setAttribute("data-instant", "");
72
+ ul.style.setProperty("--sf-indicator-x", `${item.offsetLeft}px`);
73
+ ul.style.setProperty("--sf-indicator-y", `${item.offsetTop}px`);
74
+ ul.style.setProperty("--sf-indicator-w", `${item.offsetWidth}px`);
75
+ ul.style.setProperty("--sf-indicator-h", `${item.offsetHeight}px`);
76
+ ul.setAttribute("data-indicator", "");
77
+ if (instant)
78
+ requestAnimationFrame(() => ul.removeAttribute("data-instant"));
79
+ };
80
+ place(!ul.hasAttribute("data-indicator") || shownGroup.current !== group);
81
+ shownGroup.current = group;
82
+ // An observer reports once as soon as it watches; only a real change of size moves the highlight (at once).
83
+ let size = `${ul.offsetWidth}x${ul.offsetHeight}`;
84
+ const resized = typeof ResizeObserver === "function"
85
+ ? new ResizeObserver(() => {
86
+ const now = `${ul.offsetWidth}x${ul.offsetHeight}`;
87
+ if (now === size)
88
+ return;
89
+ size = now;
90
+ place(true);
91
+ })
92
+ : undefined;
93
+ resized?.observe(ul);
94
+ return () => resized?.disconnect();
95
+ }, [list, selector, current, group]);
96
+ }
97
+ export function NavBar({ label, groups, current, onSelect, brand, actions, className }) {
98
+ const id = useId();
99
+ const narrow = useMedia(NAVBAR_NARROW);
100
+ const scrolled = useScrolled();
101
+ const [open, setOpen] = useState(false);
102
+ const sheet = useRef(null);
103
+ const opener = useRef(null);
104
+ const here = sectionOf(groups, current);
105
+ const section = here >= 0 ? groups[here] : undefined;
106
+ const menuOpen = open && narrow;
107
+ useEffect(() => {
108
+ if (menuOpen)
109
+ sheet.current?.querySelector(".sf-navbar-close")?.focus();
110
+ }, [menuOpen]);
111
+ // Widening the window while the menu is open closes it: the sections are in the bar again.
112
+ useEffect(() => {
113
+ if (!narrow)
114
+ setOpen(false);
115
+ }, [narrow]);
116
+ // Going to another page from inside the menu (a link among the actions, say) closes it, as choosing a page does.
117
+ const shown = useRef(current);
118
+ useEffect(() => {
119
+ if (shown.current === current)
120
+ return;
121
+ shown.current = current;
122
+ setOpen(false);
123
+ }, [current]);
124
+ // The current page in the second bar is kept in view when it scrolls sideways.
125
+ const local = useRef(null);
126
+ const sections = useRef(null);
127
+ useIndicator(sections, ".sf-navbar-section[aria-current]", current, narrow ? "narrow" : "wide");
128
+ useIndicator(local, '.sf-navbar-page[aria-current="page"]', current, section ? sectionLabel(section) : undefined);
129
+ useEffect(() => {
130
+ local.current?.querySelector('[aria-current="page"]')?.scrollIntoView?.({ block: "nearest", inline: "nearest" });
131
+ }, [current]);
132
+ const close = () => {
133
+ setOpen(false);
134
+ requestAnimationFrame(() => opener.current?.focus());
135
+ };
136
+ const choose = (item) => {
137
+ onSelect?.(item);
138
+ if (menuOpen)
139
+ close();
140
+ };
141
+ const onKey = (event) => {
142
+ if (event.key === "Escape") {
143
+ event.preventDefault();
144
+ close();
145
+ return;
146
+ }
147
+ if (event.key === "Tab" && sheet.current) {
148
+ const all = [...sheet.current.querySelectorAll(FOCUSABLE)];
149
+ const first = all[0];
150
+ const last = all[all.length - 1];
151
+ if (!first || !last)
152
+ return;
153
+ if (event.shiftKey && document.activeElement === first) {
154
+ event.preventDefault();
155
+ last.focus();
156
+ }
157
+ else if (!event.shiftKey && document.activeElement === last) {
158
+ event.preventDefault();
159
+ first.focus();
160
+ }
161
+ }
162
+ };
163
+ return (_jsxs(_Fragment, { children: [_jsxs("header", { className: `sf-navbar${className ? ` ${className}` : ""}`, "data-scrolled": scrolled || undefined, "data-narrow": narrow || undefined, children: [_jsx("nav", { className: "sf-navbar-global", "aria-label": label, children: _jsxs("div", { className: "sf-navbar-row", children: [brand && _jsx("div", { className: "sf-navbar-brand", children: brand }), !narrow && (_jsx("ul", { ref: sections, className: "sf-navbar-sections", children: groups.map((group, index) => {
164
+ const first = group.items[0];
165
+ if (!first)
166
+ return null;
167
+ const inSection = index === here;
168
+ return (_jsx("li", { children: first.href ? (_jsx("a", { className: "sf-navbar-section", href: first.href, "aria-current": inSection ? "true" : undefined, onClick: () => choose(first.id), children: sectionLabel(group) })) : (_jsx("button", { type: "button", className: "sf-navbar-section", "aria-current": inSection ? "true" : undefined, onClick: () => choose(first.id), children: sectionLabel(group) })) }, sectionLabel(group)));
169
+ }) })), !narrow && actions && _jsx("div", { className: "sf-navbar-actions", children: actions }), narrow && (_jsx("button", { ref: opener, type: "button", className: "sf-navbar-menu", "aria-expanded": menuOpen, "aria-controls": `${id}-menu`, "aria-label": `Show ${navigationName(label)}`, onClick: () => setOpen(true), children: _jsx(ControlIcon, { icon: "menu" }) }))] }) }), section && (_jsx("nav", { className: "sf-navbar-local", "aria-label": `${sectionLabel(section)} pages`, children: _jsxs("div", { className: "sf-navbar-row", children: [_jsx("p", { className: "sf-navbar-title", children: sectionLabel(section) }), _jsx("ul", { ref: local, className: "sf-navbar-pages", children: section.items.map((item) => (_jsx("li", { children: _jsx(ItemLink, { item: item, current: current, onChoose: choose, className: "sf-navbar-page" }) }, item.id))) })] }) }))] }), menuOpen && (_jsxs("div", { id: `${id}-menu`, ref: sheet, className: "sf-navbar-sheet", role: "dialog", "aria-modal": "true", "aria-label": navigationName(label), onKeyDown: onKey, children: [_jsxs("div", { className: "sf-navbar-sheet-top", children: [brand && _jsx("div", { className: "sf-navbar-brand", children: brand }), _jsx("button", { type: "button", className: "sf-navbar-close", "aria-label": "Close navigation", onClick: close, children: _jsx(ControlIcon, { icon: "close" }) })] }), _jsxs("div", { className: "sf-navbar-sheet-body", children: [groups.map((group) => (_jsxs("section", { className: "sf-navbar-sheet-group", "aria-label": sectionLabel(group), children: [_jsx("h2", { className: "sf-navbar-sheet-label", children: sectionLabel(group) }), _jsx("ul", { children: group.items.map((item) => (_jsx("li", { children: _jsx(ItemLink, { item: item, current: current, onChoose: choose, className: "sf-navbar-sheet-item" }) }, item.id))) })] }, sectionLabel(group)))), actions && _jsx("div", { className: "sf-navbar-sheet-actions", children: actions })] })] }))] }));
170
+ }
171
+ //# sourceMappingURL=NavBar.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NavBar.js","sourceRoot":"","sources":["../../src/workspace/NavBar.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAsD,SAAS,EAAE,KAAK,EAAE,eAAe,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAChI,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC1D,OAAO,EAAuC,cAAc,EAAE,MAAM,cAAc,CAAC;AAqBnF,6EAA6E;AAC7E,MAAM,CAAC,MAAM,aAAa,GAAG,oBAAoB,CAAC;AAElD,MAAM,SAAS,GAAG,2IAA2I,CAAC;AAE9J,SAAS,QAAQ,CAAC,KAAa;IAC7B,MAAM,GAAG,GAAG,GAAG,EAAE,CAAC,CAAC,OAAO,MAAM,KAAK,WAAW,IAAI,OAAO,MAAM,CAAC,UAAU,KAAK,UAAU,C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AAC,QAAQ,EAAC,SAAS,EAAC,iBAAiB,gBAAY,kBAAkB,EAAC,OAAO,EAAE,KAAK,YAC5F,KAAC,WAAW,IAAC,IAAI,EAAC,OAAO,GAAG,GACrB,IACL,EACN,eAAK,SAAS,EAAC,sBAAsB,aAClC,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CACrB,mBAAmC,SAAS,EAAC,uBAAuB,gBAAa,YAAY,CAAC,KAAK,CAAC,aAClG,aAAI,SAAS,EAAC,uBAAuB,YAAE,YAAY,CAAC,KAAK,CAAC,GAAM,EAChE,uBACG,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CACzB,uBACE,KAAC,QAAQ,IAAC,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAC,sBAAsB,GAAG,IADtF,IAAI,CAAC,EAAE,CAEX,CACN,CAAC,GACC,KARO,YAAY,CAAC,KAAK,CAAC,CASvB,CACX,CAAC,EACD,OAAO,IAAI,cAAK,SAAS,EAAC,yBAAyB,YAAE,OAAO,GAAO,IAChE,IACF,CACP,IACA,CACJ,CAAC;AACJ,CAAC","sourcesContent":["import { type KeyboardEvent, type ReactNode, type RefObject, useEffect, useId, useLayoutEffect, useRef, useState } from \"react\";\nimport { ControlIcon } from \"../controls/ItemControls.js\";\nimport { type SideNavGroup, type SideNavItem, navigationName } from \"./SideNav.js\";\n\nexport interface NavBarProps {\n /** What the navigation is for, for assistive technology: \"Surfaces UI\". */\n label: string;\n /**\n * The sections and their pages: the same groups `SideNav` takes. Each group's label is a section in the bar; the\n * section holding the current page shows its pages in a second bar beneath. A group with no label is shown under the\n * name \"More\".\n */\n groups: SideNavGroup[];\n /** The id of the item for the page being shown. */\n current?: string;\n onSelect?(id: string): void;\n /** At the bar's start: a name or a mark. Pressing it is the host's to decide. */\n brand?: ReactNode;\n /** At the bar's end: a status, a picker. On a narrow screen it moves into the menu. */\n actions?: ReactNode;\n className?: string;\n}\n\n/** Below this width the sections fold into a menu that covers the screen. */\nexport const NAVBAR_NARROW = \"(max-width: 48rem)\";\n\nconst FOCUSABLE = 'a[href], button:not([disabled]), select:not([disabled]), input:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex=\"-1\"])';\n\nfunction useMedia(query: string): boolean {\n const get = () => (typeof window !== \"undefined\" && typeof window.matchMedia === \"function\" ? window.matchMedia(query) : undefined);\n const [matches, setMatches] = useState(() => get()?.matches ?? false);\n useEffect(() => {\n const media = get();\n if (!media) return;\n const change = () => setMatches(media.matches);\n change();\n media.addEventListener(\"change\", change);\n return () => media.removeEventListener(\"change\", change);\n // biome-ignore lint/correctness/useExhaustiveDependencies: the query is fixed for the component's life.\n }, [query]);\n return matches;\n}\n\n/** True once the page has scrolled, so the bar can show the edge between it and the content passing beneath. */\nfunction useScrolled(): boolean {\n const [scrolled, setScrolled] = useState(false);\n useEffect(() => {\n if (typeof window === \"undefined\") return;\n const check = () => setScrolled(window.scrollY > 0);\n check();\n window.addEventListener(\"scroll\", check, { passive: true });\n return () => window.removeEventListener(\"scroll\", check);\n }, []);\n return scrolled;\n}\n\nconst sectionOf = (groups: SideNavGroup[], id?: string) => groups.findIndex((g) => g.items.some((i) => i.id === id));\nconst sectionLabel = (group: SideNavGroup) => group.label ?? \"More\";\n\nfunction ItemLink({ item, current, onChoose, className }: { item: SideNavItem; current?: string; onChoose(id: string): void; className: string }) {\n const here = item.id === current ? \"page\" : undefined;\n if (item.href) {\n return (\n <a className={className} href={item.href} aria-current={here} onClick={() => onChoose(item.id)}>\n {item.label}\n </a>\n );\n }\n return (\n <button type=\"button\" className={className} aria-current={here} onClick={() => onChoose(item.id)}>\n {item.label}\n </button>\n );\n}\n\n/**\n * Navigation across the top of a site, after Apple's: a bar of sections that stays at the top on glass, and beneath\n * it a second bar with the current section's name and its pages. A section goes to its first page. Content scrolls\n * under both, and an edge appears once it does. On a narrow screen the sections fold into a menu button that opens\n * every section and page over the whole screen, as a dialog: focus goes in and stays there until Escape, the close\n * button or a choice closes it, then goes back to the menu button. The second bar stays, its pages scrolling sideways.\n */\n/**\n * Puts one highlight under the current item of a list, as CSS variables on the list (`--sf-indicator-x`, `-y`, `-w`,\n * `-h`), so the highlight slides from item to item instead of jumping. `group` names which set of items the list\n * holds: when it changes the items are new, and the highlight is placed without sliding. A list whose size changes\n * (a wider window, a font loading) moves it at once too.\n */\nfunction useIndicator(list: RefObject<HTMLUListElement | null>, selector: string, current: string | undefined, group?: string) {\n const shownGroup = useRef(group);\n useLayoutEffect(() => {\n const ul = list.current;\n if (!ul) return;\n const place = (instant: boolean) => {\n const item = ul.querySelector<HTMLElement>(selector);\n if (!item) {\n ul.removeAttribute(\"data-indicator\");\n return;\n }\n if (instant) ul.setAttribute(\"data-instant\", \"\");\n ul.style.setProperty(\"--sf-indicator-x\", `${item.offsetLeft}px`);\n ul.style.setProperty(\"--sf-indicator-y\", `${item.offsetTop}px`);\n ul.style.setProperty(\"--sf-indicator-w\", `${item.offsetWidth}px`);\n ul.style.setProperty(\"--sf-indicator-h\", `${item.offsetHeight}px`);\n ul.setAttribute(\"data-indicator\", \"\");\n if (instant) requestAnimationFrame(() => ul.removeAttribute(\"data-instant\"));\n };\n place(!ul.hasAttribute(\"data-indicator\") || shownGroup.current !== group);\n shownGroup.current = group;\n // An observer reports once as soon as it watches; only a real change of size moves the highlight (at once).\n let size = `${ul.offsetWidth}x${ul.offsetHeight}`;\n const resized =\n typeof ResizeObserver === \"function\"\n ? new ResizeObserver(() => {\n const now = `${ul.offsetWidth}x${ul.offsetHeight}`;\n if (now === size) return;\n size = now;\n place(true);\n })\n : undefined;\n resized?.observe(ul);\n return () => resized?.disconnect();\n }, [list, selector, current, group]);\n}\n\nexport function NavBar({ label, groups, current, onSelect, brand, actions, className }: NavBarProps) {\n const id = useId();\n const narrow = useMedia(NAVBAR_NARROW);\n const scrolled = useScrolled();\n const [open, setOpen] = useState(false);\n const sheet = useRef<HTMLDivElement>(null);\n const opener = useRef<HTMLButtonElement>(null);\n const here = sectionOf(groups, current);\n const section = here >= 0 ? groups[here] : undefined;\n const menuOpen = open && narrow;\n\n useEffect(() => {\n if (menuOpen) sheet.current?.querySelector<HTMLElement>(\".sf-navbar-close\")?.focus();\n }, [menuOpen]);\n // Widening the window while the menu is open closes it: the sections are in the bar again.\n useEffect(() => {\n if (!narrow) setOpen(false);\n }, [narrow]);\n // Going to another page from inside the menu (a link among the actions, say) closes it, as choosing a page does.\n const shown = useRef(current);\n useEffect(() => {\n if (shown.current === current) return;\n shown.current = current;\n setOpen(false);\n }, [current]);\n // The current page in the second bar is kept in view when it scrolls sideways.\n const local = useRef<HTMLUListElement>(null);\n const sections = useRef<HTMLUListElement>(null);\n useIndicator(sections, \".sf-navbar-section[aria-current]\", current, narrow ? \"narrow\" : \"wide\");\n useIndicator(local, '.sf-navbar-page[aria-current=\"page\"]', current, section ? sectionLabel(section) : undefined);\n useEffect(() => {\n local.current?.querySelector<HTMLElement>('[aria-current=\"page\"]')?.scrollIntoView?.({ block: \"nearest\", inline: \"nearest\" });\n }, [current]);\n\n const close = () => {\n setOpen(false);\n requestAnimationFrame(() => opener.current?.focus());\n };\n const choose = (item: string) => {\n onSelect?.(item);\n if (menuOpen) close();\n };\n const onKey = (event: KeyboardEvent<HTMLDivElement>) => {\n if (event.key === \"Escape\") {\n event.preventDefault();\n close();\n return;\n }\n if (event.key === \"Tab\" && sheet.current) {\n const all = [...sheet.current.querySelectorAll<HTMLElement>(FOCUSABLE)];\n const first = all[0];\n const last = all[all.length - 1];\n if (!first || !last) return;\n if (event.shiftKey && document.activeElement === first) {\n event.preventDefault();\n last.focus();\n } else if (!event.shiftKey && document.activeElement === last) {\n event.preventDefault();\n first.focus();\n }\n }\n };\n\n return (\n <>\n <header className={`sf-navbar${className ? ` ${className}` : \"\"}`} data-scrolled={scrolled || undefined} data-narrow={narrow || undefined}>\n <nav className=\"sf-navbar-global\" aria-label={label}>\n <div className=\"sf-navbar-row\">\n {brand && <div className=\"sf-navbar-brand\">{brand}</div>}\n {!narrow && (\n <ul ref={sections} className=\"sf-navbar-sections\">\n {groups.map((group, index) => {\n const first = group.items[0];\n if (!first) return null;\n const inSection = index === here;\n return (\n <li key={sectionLabel(group)}>\n {first.href ? (\n <a className=\"sf-navbar-section\" href={first.href} aria-current={inSection ? \"true\" : undefined} onClick={() => choose(first.id)}>\n {sectionLabel(group)}\n </a>\n ) : (\n <button type=\"button\" className=\"sf-navbar-section\" aria-current={inSection ? \"true\" : undefined} onClick={() => choose(first.id)}>\n {sectionLabel(group)}\n </button>\n )}\n </li>\n );\n })}\n </ul>\n )}\n {!narrow && actions && <div className=\"sf-navbar-actions\">{actions}</div>}\n {narrow && (\n <button\n ref={opener}\n type=\"button\"\n className=\"sf-navbar-menu\"\n aria-expanded={menuOpen}\n aria-controls={`${id}-menu`}\n aria-label={`Show ${navigationName(label)}`}\n onClick={() => setOpen(true)}\n >\n <ControlIcon icon=\"menu\" />\n </button>\n )}\n </div>\n </nav>\n {section && (\n <nav className=\"sf-navbar-local\" aria-label={`${sectionLabel(section)} pages`}>\n <div className=\"sf-navbar-row\">\n <p className=\"sf-navbar-title\">{sectionLabel(section)}</p>\n <ul ref={local} className=\"sf-navbar-pages\">\n {section.items.map((item) => (\n <li key={item.id}>\n <ItemLink item={item} current={current} onChoose={choose} className=\"sf-navbar-page\" />\n </li>\n ))}\n </ul>\n </div>\n </nav>\n )}\n </header>\n {/* Outside the bar: the bar's backdrop blur would make it the box a fixed sheet is placed in. */}\n {menuOpen && (\n // biome-ignore lint/a11y/noStaticElementInteractions: Escape and Tab are handled here for everything inside; the controls themselves are buttons and links.\n <div id={`${id}-menu`} ref={sheet} className=\"sf-navbar-sheet\" role=\"dialog\" aria-modal=\"true\" aria-label={navigationName(label)} onKeyDown={onKey}>\n <div className=\"sf-navbar-sheet-top\">\n {brand && <div className=\"sf-navbar-brand\">{brand}</div>}\n <button type=\"button\" className=\"sf-navbar-close\" aria-label=\"Close navigation\" onClick={close}>\n <ControlIcon icon=\"close\" />\n </button>\n </div>\n <div className=\"sf-navbar-sheet-body\">\n {groups.map((group) => (\n <section key={sectionLabel(group)} className=\"sf-navbar-sheet-group\" aria-label={sectionLabel(group)}>\n <h2 className=\"sf-navbar-sheet-label\">{sectionLabel(group)}</h2>\n <ul>\n {group.items.map((item) => (\n <li key={item.id}>\n <ItemLink item={item} current={current} onChoose={choose} className=\"sf-navbar-sheet-item\" />\n </li>\n ))}\n </ul>\n </section>\n ))}\n {actions && <div className=\"sf-navbar-sheet-actions\">{actions}</div>}\n </div>\n </div>\n )}\n </>\n );\n}\n"]}
@@ -0,0 +1,61 @@
1
+ import { type ReactNode } from "react";
2
+ export interface SideNavItem {
3
+ id: string;
4
+ label: string;
5
+ /** Where the item goes. Without one the item is a button and only `onSelect` is called. */
6
+ href?: string;
7
+ }
8
+ export interface SideNavGroup {
9
+ /** A heading over the group's items. */
10
+ label?: string;
11
+ items: SideNavItem[];
12
+ }
13
+ export interface SideNavProps {
14
+ /** What the navigation is for, for assistive technology: "Playground". */
15
+ label: string;
16
+ groups: SideNavGroup[];
17
+ /** The id of the item for the page being shown. */
18
+ current?: string;
19
+ onSelect?(id: string): void;
20
+ /** Whether the navigation stays open beside the page. Give it with `onPinnedChange` to hold it yourself. */
21
+ pinned?: boolean;
22
+ /** Whether it starts pinned when it holds the state itself. Defaults to true. */
23
+ defaultPinned?: boolean;
24
+ onPinnedChange?(pinned: boolean): void;
25
+ /** Shown above the items: a name, a status, a picker. */
26
+ header?: ReactNode;
27
+ /** Shown below the items. */
28
+ footer?: ReactNode;
29
+ className?: string;
30
+ }
31
+ /** Below this width the navigation is always folded away: docked beside a phone's page it would leave the page no room. */
32
+ export declare const SIDENAV_NARROW = "(max-width: 40rem)";
33
+ /** The least room, in px each way, a drawer needs: in a smaller box it takes the window instead. */
34
+ export declare const SIDENAV_LEAST = 240;
35
+ /** A box on screen, in px from the window's top left. */
36
+ export interface NavBox {
37
+ top: number;
38
+ left: number;
39
+ width: number;
40
+ height: number;
41
+ }
42
+ /**
43
+ * Where a folded navigation's drawer goes: the part of its holder that is on screen. Nothing (the whole window) when
44
+ * the holder is not laid out, is off screen, or shows less than `least` px either way.
45
+ */
46
+ export declare function drawerBox(holder: NavBox | undefined, viewport: {
47
+ width: number;
48
+ height: number;
49
+ }, least?: number): NavBox | undefined;
50
+ /** "Site navigation" for "Site", and "Main navigation" left as it is: a label that already says so is not said twice. */
51
+ export declare const navigationName: (label: string) => string;
52
+ /**
53
+ * Side navigation that can get out of the way. Pinned, it sits beside the page. Unpinned, it keeps only the room its
54
+ * menu button takes: a slim strip where the navigation was, so the button never sits over the page or a host's own
55
+ * toolbar. Pressing it slides the navigation in from the left as a dialog: over the window, or, drawn inside a region
56
+ * that answers to its own size (a surface in a host's canvas, a chat reply), over that region only. Focus moves into
57
+ * it and stays there until it closes, on Escape, on its close button, or when an item is chosen; focus then goes back
58
+ * to the menu button. Where the window or that region is under 40rem wide (`SIDENAV_NARROW`) it is always folded and
59
+ * offers no pin.
60
+ */
61
+ export declare function SideNav({ label, groups, current, onSelect, pinned: given, defaultPinned, onPinnedChange, header, footer, className }: SideNavProps): import("react").JSX.Element;
@@ -0,0 +1,149 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useEffect, useId, useLayoutEffect, useRef, useState } from "react";
3
+ import { ControlIcon } from "../controls/ItemControls.js";
4
+ /** Below this width the navigation is always folded away: docked beside a phone's page it would leave the page no room. */
5
+ export const SIDENAV_NARROW = "(max-width: 40rem)";
6
+ const narrowQuery = () => (typeof window !== "undefined" && typeof window.matchMedia === "function" ? window.matchMedia(SIDENAV_NARROW) : undefined);
7
+ /** The width, in rem, under which whatever holds the navigation is too narrow to dock it beside the page. */
8
+ const NARROW_REM = 40;
9
+ /** The least room, in px each way, a drawer needs: in a smaller box it takes the window instead. */
10
+ export const SIDENAV_LEAST = 240;
11
+ /**
12
+ * Where a folded navigation's drawer goes: the part of its holder that is on screen. Nothing (the whole window) when
13
+ * the holder is not laid out, is off screen, or shows less than `least` px either way.
14
+ */
15
+ export function drawerBox(holder, viewport, least = SIDENAV_LEAST) {
16
+ if (!holder)
17
+ return undefined;
18
+ const top = Math.max(holder.top, 0);
19
+ const left = Math.max(holder.left, 0);
20
+ const width = Math.min(holder.left + holder.width, viewport.width) - left;
21
+ const height = Math.min(holder.top + holder.height, viewport.height) - top;
22
+ if (!(width >= least) || !(height >= least))
23
+ return undefined;
24
+ return { top, left, width, height };
25
+ }
26
+ /** What holds the navigation when it is drawn inside a region that answers to its own size (a surface, a result). */
27
+ const holderOf = (element) => element?.closest(".sf-container") ?? undefined;
28
+ /** True when the window, or the region the navigation is drawn in, is too narrow to dock it. */
29
+ function useNarrow(root) {
30
+ const [narrow, setNarrow] = useState(() => narrowQuery()?.matches ?? false);
31
+ const [tight, setTight] = useState(false);
32
+ useEffect(() => {
33
+ const query = narrowQuery();
34
+ if (!query)
35
+ return;
36
+ const change = () => setNarrow(query.matches);
37
+ change();
38
+ query.addEventListener("change", change);
39
+ return () => query.removeEventListener("change", change);
40
+ }, []);
41
+ useEffect(() => {
42
+ const holder = holderOf(root.current);
43
+ if (!holder || typeof ResizeObserver === "undefined")
44
+ return;
45
+ const measure = () => {
46
+ const width = holder.getBoundingClientRect().width;
47
+ const rem = Number.parseFloat(getComputedStyle(document.documentElement).fontSize) || 16;
48
+ // A holder that is not laid out says nothing.
49
+ setTight(width > 0 && width < NARROW_REM * rem);
50
+ };
51
+ measure();
52
+ const observer = new ResizeObserver(measure);
53
+ observer.observe(holder);
54
+ return () => observer.disconnect();
55
+ }, [root]);
56
+ return narrow || tight;
57
+ }
58
+ /** "Site navigation" for "Site", and "Main navigation" left as it is: a label that already says so is not said twice. */
59
+ export const navigationName = (label) => (/\bnavigation\s*$/i.test(label) ? label.trim() : `${label.trim()} navigation`);
60
+ const FOCUSABLE = 'a[href], button:not([disabled]), select:not([disabled]), input:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])';
61
+ /**
62
+ * Side navigation that can get out of the way. Pinned, it sits beside the page. Unpinned, it keeps only the room its
63
+ * menu button takes: a slim strip where the navigation was, so the button never sits over the page or a host's own
64
+ * toolbar. Pressing it slides the navigation in from the left as a dialog: over the window, or, drawn inside a region
65
+ * that answers to its own size (a surface in a host's canvas, a chat reply), over that region only. Focus moves into
66
+ * it and stays there until it closes, on Escape, on its close button, or when an item is chosen; focus then goes back
67
+ * to the menu button. Where the window or that region is under 40rem wide (`SIDENAV_NARROW`) it is always folded and
68
+ * offers no pin.
69
+ */
70
+ export function SideNav({ label, groups, current, onSelect, pinned: given, defaultPinned = true, onPinnedChange, header, footer, className }) {
71
+ const id = useId();
72
+ const [kept, setKept] = useState(defaultPinned);
73
+ const root = useRef(null);
74
+ const narrow = useNarrow(root);
75
+ // On a narrow screen it is folded whatever was chosen; the choice comes back on a wider one.
76
+ const pinned = (given ?? kept) && !narrow;
77
+ const [open, setOpen] = useState(false);
78
+ const panel = useRef(null);
79
+ const opener = () => document.getElementById(`${id}-open`);
80
+ const close = () => {
81
+ setOpen(false);
82
+ requestAnimationFrame(() => opener()?.focus());
83
+ };
84
+ const setPinned = (next) => {
85
+ setKept(next);
86
+ setOpen(false);
87
+ onPinnedChange?.(next);
88
+ // Folding away from the button inside the panel: focus goes to the menu button that opens it again.
89
+ if (!next)
90
+ requestAnimationFrame(() => opener()?.focus());
91
+ };
92
+ const taking = !pinned && open;
93
+ // Where the drawer goes while it is open: the part of its holder on screen, kept current as that moves.
94
+ const [box, setBox] = useState(undefined);
95
+ useLayoutEffect(() => {
96
+ if (!taking)
97
+ return;
98
+ const place = () => {
99
+ const rect = holderOf(root.current)?.getBoundingClientRect();
100
+ const next = drawerBox(rect ? { top: rect.top, left: rect.left, width: rect.width, height: rect.height } : undefined, { width: window.innerWidth, height: window.innerHeight });
101
+ setBox((before) => (before && next && before.top === next.top && before.left === next.left && before.width === next.width && before.height === next.height ? before : next));
102
+ };
103
+ place();
104
+ window.addEventListener("resize", place);
105
+ window.addEventListener("scroll", place, true);
106
+ return () => {
107
+ window.removeEventListener("resize", place);
108
+ window.removeEventListener("scroll", place, true);
109
+ };
110
+ }, [taking]);
111
+ const placed = !pinned && box ? { "--sf-sidenav-top": `${box.top}px`, "--sf-sidenav-left": `${box.left}px`, "--sf-sidenav-width": `${box.width}px`, "--sf-sidenav-height": `${box.height}px` } : undefined;
112
+ // Opened over the page: focus goes in, to the close button first.
113
+ useEffect(() => {
114
+ if (taking)
115
+ panel.current?.querySelector(".sf-sidenav-close")?.focus();
116
+ }, [taking]);
117
+ const onKey = (event) => {
118
+ if (!taking)
119
+ return;
120
+ if (event.key === "Escape") {
121
+ event.preventDefault();
122
+ close();
123
+ return;
124
+ }
125
+ // Focus stays inside while it covers the page.
126
+ if (event.key === "Tab" && panel.current) {
127
+ const all = [...panel.current.querySelectorAll(FOCUSABLE)];
128
+ const first = all[0];
129
+ const last = all[all.length - 1];
130
+ if (!first || !last)
131
+ return;
132
+ if (event.shiftKey && document.activeElement === first) {
133
+ event.preventDefault();
134
+ last.focus();
135
+ }
136
+ else if (!event.shiftKey && document.activeElement === last) {
137
+ event.preventDefault();
138
+ first.focus();
139
+ }
140
+ }
141
+ };
142
+ const choose = (item) => {
143
+ onSelect?.(item);
144
+ if (taking)
145
+ close();
146
+ };
147
+ return (_jsxs("div", { ref: root, className: `sf-sidenav${className ? ` ${className}` : ""}`, "data-pinned": pinned, "data-open": open || undefined, "data-narrow": narrow || undefined, style: placed, onKeyDown: onKey, children: [!pinned && (_jsx("button", { id: `${id}-open`, type: "button", className: "sf-sidenav-open", "aria-expanded": open, "aria-controls": `${id}-panel`, "aria-label": `Show ${navigationName(label)}`, onClick: () => setOpen(true), children: _jsx(ControlIcon, { icon: "menu" }) })), _jsxs("div", { className: "sf-sidenav-stage", children: [taking && _jsx("div", { className: "sf-sidenav-backdrop", "aria-hidden": "true", onClick: close }), _jsxs("div", { id: `${id}-panel`, ref: panel, className: "sf-sidenav-panel", role: pinned ? undefined : "dialog", "aria-modal": taking || undefined, "aria-label": pinned ? undefined : navigationName(label), children: [_jsxs("div", { className: "sf-sidenav-top", children: [_jsx("div", { className: "sf-sidenav-header", children: header }), !narrow && (_jsxs("button", { type: "button", className: "sf-sidenav-pin", "aria-pressed": pinned, title: pinned ? "Let the navigation fold away" : "Keep the navigation open", onClick: () => setPinned(!pinned), children: [_jsx(ControlIcon, { icon: pinned ? "fold" : "unfold" }), _jsx("span", { className: "sf-sidenav-pin-label", children: pinned ? "Fold away" : "Keep open" })] })), !pinned && (_jsx("button", { type: "button", className: "sf-sidenav-close", "aria-label": `Close ${navigationName(label)}`, onClick: close, children: _jsx(ControlIcon, { icon: "close" }) }))] }), _jsx("nav", { className: "sf-sidenav-nav", "aria-label": label, children: groups.map((group, g) => (_jsxs("section", { className: "sf-sidenav-group", "aria-labelledby": group.label ? `${id}-group-${g}` : undefined, children: [group.label && (_jsx("h2", { id: `${id}-group-${g}`, className: "sf-sidenav-group-label", children: group.label })), _jsx("ul", { children: group.items.map((item) => (_jsx("li", { children: item.href ? (_jsx("a", { href: item.href, "aria-current": item.id === current ? "page" : undefined, onClick: () => choose(item.id), children: item.label })) : (_jsx("button", { type: "button", "aria-current": item.id === current ? "page" : undefined, onClick: () => choose(item.id), children: item.label })) }, item.id))) })] }, group.label ?? g))) }), footer && _jsx("div", { className: "sf-sidenav-footer", children: footer })] })] })] }));
148
+ }
149
+ //# sourceMappingURL=SideNav.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SideNav.js","sourceRoot":"","sources":["../../src/workspace/SideNav.tsx"],"names":[],"mappings":";AAAA,OAAO,EAA0E,SAAS,EAAE,KAAK,EAAE,eAAe,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACpJ,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAkC1D,2HAA2H;AAC3H,MAAM,CAAC,MAAM,cAAc,GAAG,oB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C,CAAC,SAAS,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,YACzG,IAAI,CAAC,KAAK,GACJ,CACV,IATM,IAAI,CAAC,EAAE,CAUX,CACN,CAAC,GACC,KApBO,KAAK,CAAC,KAAK,IAAI,CAAC,CAqBpB,CACX,CAAC,GACE,EACL,MAAM,IAAI,cAAK,SAAS,EAAC,mBAAmB,YAAE,MAAM,GAAO,IACxD,IACA,IACF,CACP,CAAC;AACJ,CAAC","sourcesContent":["import { type CSSProperties, type KeyboardEvent, type ReactNode, type RefObject, useEffect, useId, useLayoutEffect, useRef, useState } from \"react\";\nimport { ControlIcon } from \"../controls/ItemControls.js\";\n\nexport interface SideNavItem {\n id: string;\n label: string;\n /** Where the item goes. Without one the item is a button and only `onSelect` is called. */\n href?: string;\n}\n\nexport interface SideNavGroup {\n /** A heading over the group's items. */\n label?: string;\n items: SideNavItem[];\n}\n\nexport interface SideNavProps {\n /** What the navigation is for, for assistive technology: \"Playground\". */\n label: string;\n groups: SideNavGroup[];\n /** The id of the item for the page being shown. */\n current?: string;\n onSelect?(id: string): void;\n /** Whether the navigation stays open beside the page. Give it with `onPinnedChange` to hold it yourself. */\n pinned?: boolean;\n /** Whether it starts pinned when it holds the state itself. Defaults to true. */\n defaultPinned?: boolean;\n onPinnedChange?(pinned: boolean): void;\n /** Shown above the items: a name, a status, a picker. */\n header?: ReactNode;\n /** Shown below the items. */\n footer?: ReactNode;\n className?: string;\n}\n\n/** Below this width the navigation is always folded away: docked beside a phone's page it would leave the page no room. */\nexport const SIDENAV_NARROW = \"(max-width: 40rem)\";\n\nconst narrowQuery = () => (typeof window !== \"undefined\" && typeof window.matchMedia === \"function\" ? window.matchMedia(SIDENAV_NARROW) : undefined);\n\n/** The width, in rem, under which whatever holds the navigation is too narrow to dock it beside the page. */\nconst NARROW_REM = 40;\n/** The least room, in px each way, a drawer needs: in a smaller box it takes the window instead. */\nexport const SIDENAV_LEAST = 240;\n\n/** A box on screen, in px from the window's top left. */\nexport interface NavBox {\n top: number;\n left: number;\n width: number;\n height: number;\n}\n\n/**\n * Where a folded navigation's drawer goes: the part of its holder that is on screen. Nothing (the whole window) when\n * the holder is not laid out, is off screen, or shows less than `least` px either way.\n */\nexport function drawerBox(holder: NavBox | undefined, viewport: { width: number; height: number }, least = SIDENAV_LEAST): NavBox | undefined {\n if (!holder) return undefined;\n const top = Math.max(holder.top, 0);\n const left = Math.max(holder.left, 0);\n const width = Math.min(holder.left + holder.width, viewport.width) - left;\n const height = Math.min(holder.top + holder.height, viewport.height) - top;\n if (!(width >= least) || !(height >= least)) return undefined;\n return { top, left, width, height };\n}\n\n/** What holds the navigation when it is drawn inside a region that answers to its own size (a surface, a result). */\nconst holderOf = (element: Element | null) => element?.closest(\".sf-container\") ?? undefined;\n\n/** True when the window, or the region the navigation is drawn in, is too narrow to dock it. */\nfunction useNarrow(root: RefObject<HTMLElement | null>): boolean {\n const [narrow, setNarrow] = useState(() => narrowQuery()?.matches ?? false);\n const [tight, setTight] = useState(false);\n useEffect(() => {\n const query = narrowQuery();\n if (!query) return;\n const change = () => setNarrow(query.matches);\n change();\n query.addEventListener(\"change\", change);\n return () => query.removeEventListener(\"change\", change);\n }, []);\n useEffect(() => {\n const holder = holderOf(root.current);\n if (!holder || typeof ResizeObserver === \"undefined\") return;\n const measure = () => {\n const width = holder.getBoundingClientRect().width;\n const rem = Number.parseFloat(getComputedStyle(document.documentElement).fontSize) || 16;\n // A holder that is not laid out says nothing.\n setTight(width > 0 && width < NARROW_REM * rem);\n };\n measure();\n const observer = new ResizeObserver(measure);\n observer.observe(holder);\n return () => observer.disconnect();\n }, [root]);\n return narrow || tight;\n}\n\n/** \"Site navigation\" for \"Site\", and \"Main navigation\" left as it is: a label that already says so is not said twice. */\nexport const navigationName = (label: string) => (/\\bnavigation\\s*$/i.test(label) ? label.trim() : `${label.trim()} navigation`);\n\nconst FOCUSABLE = 'a[href], button:not([disabled]), select:not([disabled]), input:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex=\"-1\"])';\n\n/**\n * Side navigation that can get out of the way. Pinned, it sits beside the page. Unpinned, it keeps only the room its\n * menu button takes: a slim strip where the navigation was, so the button never sits over the page or a host's own\n * toolbar. Pressing it slides the navigation in from the left as a dialog: over the window, or, drawn inside a region\n * that answers to its own size (a surface in a host's canvas, a chat reply), over that region only. Focus moves into\n * it and stays there until it closes, on Escape, on its close button, or when an item is chosen; focus then goes back\n * to the menu button. Where the window or that region is under 40rem wide (`SIDENAV_NARROW`) it is always folded and\n * offers no pin.\n */\nexport function SideNav({ label, groups, current, onSelect, pinned: given, defaultPinned = true, onPinnedChange, header, footer, className }: SideNavProps) {\n const id = useId();\n const [kept, setKept] = useState(defaultPinned);\n const root = useRef<HTMLDivElement>(null);\n const narrow = useNarrow(root);\n // On a narrow screen it is folded whatever was chosen; the choice comes back on a wider one.\n const pinned = (given ?? kept) && !narrow;\n const [open, setOpen] = useState(false);\n const panel = useRef<HTMLDivElement>(null);\n const opener = () => document.getElementById(`${id}-open`);\n const close = () => {\n setOpen(false);\n requestAnimationFrame(() => opener()?.focus());\n };\n const setPinned = (next: boolean) => {\n setKept(next);\n setOpen(false);\n onPinnedChange?.(next);\n // Folding away from the button inside the panel: focus goes to the menu button that opens it again.\n if (!next) requestAnimationFrame(() => opener()?.focus());\n };\n const taking = !pinned && open;\n // Where the drawer goes while it is open: the part of its holder on screen, kept current as that moves.\n const [box, setBox] = useState<NavBox | undefined>(undefined);\n useLayoutEffect(() => {\n if (!taking) return;\n const place = () => {\n const rect = holderOf(root.current)?.getBoundingClientRect();\n const next = drawerBox(rect ? { top: rect.top, left: rect.left, width: rect.width, height: rect.height } : undefined, { width: window.innerWidth, height: window.innerHeight });\n setBox((before) => (before && next && before.top === next.top && before.left === next.left && before.width === next.width && before.height === next.height ? before : next));\n };\n place();\n window.addEventListener(\"resize\", place);\n window.addEventListener(\"scroll\", place, true);\n return () => {\n window.removeEventListener(\"resize\", place);\n window.removeEventListener(\"scroll\", place, true);\n };\n }, [taking]);\n const placed = !pinned && box ? ({ \"--sf-sidenav-top\": `${box.top}px`, \"--sf-sidenav-left\": `${box.left}px`, \"--sf-sidenav-width\": `${box.width}px`, \"--sf-sidenav-height\": `${box.height}px` } as CSSProperties) : undefined;\n // Opened over the page: focus goes in, to the close button first.\n useEffect(() => {\n if (taking) panel.current?.querySelector<HTMLElement>(\".sf-sidenav-close\")?.focus();\n }, [taking]);\n\n const onKey = (event: KeyboardEvent<HTMLDivElement>) => {\n if (!taking) return;\n if (event.key === \"Escape\") {\n event.preventDefault();\n close();\n return;\n }\n // Focus stays inside while it covers the page.\n if (event.key === \"Tab\" && panel.current) {\n const all = [...panel.current.querySelectorAll<HTMLElement>(FOCUSABLE)];\n const first = all[0];\n const last = all[all.length - 1];\n if (!first || !last) return;\n if (event.shiftKey && document.activeElement === first) {\n event.preventDefault();\n last.focus();\n } else if (!event.shiftKey && document.activeElement === last) {\n event.preventDefault();\n first.focus();\n }\n }\n };\n const choose = (item: string) => {\n onSelect?.(item);\n if (taking) close();\n };\n\n return (\n // biome-ignore lint/a11y/noStaticElementInteractions: Escape and Tab are handled here for everything inside; the controls themselves are buttons and links.\n <div ref={root} className={`sf-sidenav${className ? ` ${className}` : \"\"}`} data-pinned={pinned} data-open={open || undefined} data-narrow={narrow || undefined} style={placed} onKeyDown={onKey}>\n {!pinned && (\n <button id={`${id}-open`} type=\"button\" className=\"sf-sidenav-open\" aria-expanded={open} aria-controls={`${id}-panel`} aria-label={`Show ${navigationName(label)}`} onClick={() => setOpen(true)}>\n <ControlIcon icon=\"menu\" />\n </button>\n )}\n {/* Folded, the drawer and the dimmed page behind it live in a stage laid over the holder, which clips the drawer as it slides. */}\n <div className=\"sf-sidenav-stage\">\n {/* The page behind a drawer is dimmed, and a press on it closes the drawer; Escape and the close button do the same. */}\n {/* biome-ignore lint/a11y/useKeyWithClickEvents lint/a11y/noStaticElementInteractions: a pointer's shortcut; the keyboard closes it with Escape or the close button. */}\n {taking && <div className=\"sf-sidenav-backdrop\" aria-hidden=\"true\" onClick={close} />}\n <div\n id={`${id}-panel`}\n ref={panel}\n className=\"sf-sidenav-panel\"\n role={pinned ? undefined : \"dialog\"}\n aria-modal={taking || undefined}\n aria-label={pinned ? undefined : navigationName(label)}\n >\n <div className=\"sf-sidenav-top\">\n <div className=\"sf-sidenav-header\">{header}</div>\n {!narrow && (\n <button type=\"button\" className=\"sf-sidenav-pin\" aria-pressed={pinned} title={pinned ? \"Let the navigation fold away\" : \"Keep the navigation open\"} onClick={() => setPinned(!pinned)}>\n <ControlIcon icon={pinned ? \"fold\" : \"unfold\"} />\n <span className=\"sf-sidenav-pin-label\">{pinned ? \"Fold away\" : \"Keep open\"}</span>\n </button>\n )}\n {!pinned && (\n <button type=\"button\" className=\"sf-sidenav-close\" aria-label={`Close ${navigationName(label)}`} onClick={close}>\n <ControlIcon icon=\"close\" />\n </button>\n )}\n </div>\n <nav className=\"sf-sidenav-nav\" aria-label={label}>\n {groups.map((group, g) => (\n <section key={group.label ?? g} className=\"sf-sidenav-group\" aria-labelledby={group.label ? `${id}-group-${g}` : undefined}>\n {group.label && (\n <h2 id={`${id}-group-${g}`} className=\"sf-sidenav-group-label\">\n {group.label}\n </h2>\n )}\n <ul>\n {group.items.map((item) => (\n <li key={item.id}>\n {item.href ? (\n <a href={item.href} aria-current={item.id === current ? \"page\" : undefined} onClick={() => choose(item.id)}>\n {item.label}\n </a>\n ) : (\n <button type=\"button\" aria-current={item.id === current ? \"page\" : undefined} onClick={() => choose(item.id)}>\n {item.label}\n </button>\n )}\n </li>\n ))}\n </ul>\n </section>\n ))}\n </nav>\n {footer && <div className=\"sf-sidenav-footer\">{footer}</div>}\n </div>\n </div>\n </div>\n );\n}\n"]}
@@ -0,0 +1,50 @@
1
+ import { type ReactNode } from "react";
2
+ import { type WorkspaceIconName } from "./icons.js";
3
+ import { type FullLayout, type WorkspaceLayout } from "./layout.js";
4
+ export interface WorkspacePanel {
5
+ id: string;
6
+ /** Shown in the panel's heading, and on the rail unless `shortTitle` is given. One to three words. */
7
+ title: string;
8
+ /** A shorter name for the rail, where there is room for about ten characters a line: "Data" for "Data model". */
9
+ shortTitle?: string;
10
+ /** The rail's icon: one of the built-in names, or your own node. Left out, the title's first letter. */
11
+ icon?: WorkspaceIconName | ReactNode;
12
+ content: ReactNode;
13
+ }
14
+ export interface WorkspaceProps {
15
+ /** What the workspace is, for assistive technology: "Playground panels". */
16
+ label: string;
17
+ panels: WorkspacePanel[];
18
+ /** Where the panels sit. Give it with `onLayoutChange` to hold the layout yourself; otherwise the workspace keeps it. */
19
+ layout?: WorkspaceLayout;
20
+ /** Where the panels start when the workspace keeps the layout. Defaults to one column. */
21
+ defaultLayout?: WorkspaceLayout;
22
+ /** Called with the whole layout when a person moves, resizes, shows or hides a panel. */
23
+ onLayoutChange?(layout: FullLayout): void;
24
+ /** Which side the rail of panel toggles sits on; `false` leaves it out. Defaults to the right. */
25
+ rail?: "left" | "right" | false;
26
+ /**
27
+ * Whether the rail shows a short name under each icon. The rail is icons
28
+ * only unless this is set, with each panel's name in a tooltip that shows
29
+ * at once on hover or focus. A person switches between the two with the
30
+ * button at the rail's foot. Give it with `onRailLabelsChange` to hold the
31
+ * choice yourself. A workspace inside another is always icons only.
32
+ */
33
+ railLabels?: boolean;
34
+ /** Whether names show to begin with, when the workspace holds the choice. Defaults to false. */
35
+ defaultRailLabels?: boolean;
36
+ onRailLabelsChange?(labels: boolean): void;
37
+ /** A CSS height. A workspace needs one: its panels scroll inside it. Defaults to 32rem. */
38
+ height?: string | number;
39
+ className?: string;
40
+ }
41
+ /**
42
+ * Panels in columns that a person arranges: drag a panel by its heading to
43
+ * another column, to a place in a stack, or to an edge for a column of its
44
+ * own; drag a divider to resize; hide a panel and bring it back from the
45
+ * rail. Everything a drag does, the "Move" menu in each heading and the arrow
46
+ * keys on a divider do too, so the workspace works without a pointer. The
47
+ * layout is plain data (`WorkspaceLayout`), so a host can keep it and an
48
+ * agent can set it.
49
+ */
50
+ export declare function Workspace({ label, panels, layout: given, defaultLayout, onLayoutChange, rail, railLabels: givenLabels, defaultRailLabels, onRailLabelsChange, height, className }: WorkspaceProps): import("react").JSX.Element;