@noix-dev/brix-vue 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 (255) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +74 -2
  3. package/package.json +117 -3
  4. package/src/components/address-field/AddressField.vue +337 -0
  5. package/src/components/address-field/index.ts +1 -0
  6. package/src/components/appearance-picker/AppearancePicker.vue +502 -0
  7. package/src/components/appearance-picker/AppearanceSegment.vue +175 -0
  8. package/src/components/appearance-picker/index.ts +44 -0
  9. package/src/components/autofill/AutoFillDialog.vue +264 -0
  10. package/src/components/autofill/index.ts +1 -0
  11. package/src/components/badge/Badge.vue +23 -0
  12. package/src/components/badge/index.ts +106 -0
  13. package/src/components/build-stamp/BuildStamp.vue +62 -0
  14. package/src/components/build-stamp/index.ts +1 -0
  15. package/src/components/button/Button.vue +31 -0
  16. package/src/components/button/index.ts +122 -0
  17. package/src/components/card/Card.vue +29 -0
  18. package/src/components/card/CardAction.vue +17 -0
  19. package/src/components/card/CardContent.vue +14 -0
  20. package/src/components/card/CardDescription.vue +14 -0
  21. package/src/components/card/CardFooter.vue +22 -0
  22. package/src/components/card/CardHeader.vue +22 -0
  23. package/src/components/card/CardTitle.vue +29 -0
  24. package/src/components/card/index.ts +47 -0
  25. package/src/components/chart/BarChart.vue +123 -0
  26. package/src/components/chart/StackedBarChart.vue +149 -0
  27. package/src/components/chart/appearanceRevision.ts +22 -0
  28. package/src/components/chart/chartColor.ts +59 -0
  29. package/src/components/chart/index.ts +6 -0
  30. package/src/components/checkbox/Checkbox.vue +61 -0
  31. package/src/components/checkbox/index.ts +1 -0
  32. package/src/components/code-editor/CodeEditor.vue +352 -0
  33. package/src/components/code-editor/index.ts +9 -0
  34. package/src/components/code-editor/syntaxTheme.ts +110 -0
  35. package/src/components/colour-picker/ColourPicker.vue +421 -0
  36. package/src/components/colour-picker/index.ts +1 -0
  37. package/src/components/combobox/Combobox.vue +337 -0
  38. package/src/components/combobox/index.ts +1 -0
  39. package/src/components/comments/CommentComposer.vue +302 -0
  40. package/src/components/comments/CommentMessage.vue +259 -0
  41. package/src/components/comments/CommentThread.vue +250 -0
  42. package/src/components/comments/commentBody.ts +185 -0
  43. package/src/components/comments/commentLevels.ts +139 -0
  44. package/src/components/comments/commentNode.ts +35 -0
  45. package/src/components/comments/composer.ts +20 -0
  46. package/src/components/comments/index.ts +29 -0
  47. package/src/components/confirm-dialog/ConfirmDialog.vue +153 -0
  48. package/src/components/confirm-dialog/index.ts +1 -0
  49. package/src/components/containers/Box.vue +42 -0
  50. package/src/components/containers/Section.vue +88 -0
  51. package/src/components/containers/SectionAction.vue +17 -0
  52. package/src/components/containers/SectionContent.vue +14 -0
  53. package/src/components/containers/SectionDescription.vue +14 -0
  54. package/src/components/containers/SectionHeader.vue +22 -0
  55. package/src/components/containers/SectionTitle.vue +17 -0
  56. package/src/components/containers/index.ts +9 -0
  57. package/src/components/data-table/ColumnMenu.vue +241 -0
  58. package/src/components/data-table/DataTable.vue +447 -0
  59. package/src/components/data-table/ExpandCaret.vue +34 -0
  60. package/src/components/data-table/SortableHead.vue +184 -0
  61. package/src/components/data-table/TableLoadingRow.vue +13 -0
  62. package/src/components/data-table/TableProgressRow.vue +26 -0
  63. package/src/components/data-table/columns.ts +13 -0
  64. package/src/components/data-table/index.ts +3 -0
  65. package/src/components/data-table/pinned.ts +19 -0
  66. package/src/components/data-table/rowActivation.ts +14 -0
  67. package/src/components/data-table/sort.ts +13 -0
  68. package/src/components/data-table/types.ts +23 -0
  69. package/src/components/date-picker/CalendarPanel.vue +432 -0
  70. package/src/components/date-picker/DateField.vue +293 -0
  71. package/src/components/date-picker/DatePicker.vue +147 -0
  72. package/src/components/date-picker/UntilDatePicker.vue +96 -0
  73. package/src/components/date-picker/dateFieldGuard.ts +87 -0
  74. package/src/components/date-picker/index.ts +4 -0
  75. package/src/components/date-picker/useDateField.ts +37 -0
  76. package/src/components/date-range-picker/DateRangePicker.vue +247 -0
  77. package/src/components/date-range-picker/index.ts +1 -0
  78. package/src/components/date-time-picker/DateTimePicker.vue +291 -0
  79. package/src/components/date-time-picker/index.ts +1 -0
  80. package/src/components/dialog/Dialog.vue +250 -0
  81. package/src/components/dialog/DialogSurface.vue +214 -0
  82. package/src/components/dialog/dialogEdges.ts +65 -0
  83. package/src/components/dialog/dialogSizes.ts +35 -0
  84. package/src/components/dialog/index.ts +12 -0
  85. package/src/components/dialog/toastHost.ts +18 -0
  86. package/src/components/dropdown/Dropdown.vue +101 -0
  87. package/src/components/dropdown/DropdownItems.vue +154 -0
  88. package/src/components/dropdown/dropdown.ts +64 -0
  89. package/src/components/dropdown/index.ts +2 -0
  90. package/src/components/file-preview/FilePreview.vue +78 -0
  91. package/src/components/file-preview/index.ts +1 -0
  92. package/src/components/file-upload/FileUpload.vue +234 -0
  93. package/src/components/file-upload/index.ts +1 -0
  94. package/src/components/filter-check-menu/FilterCheckMenu.vue +562 -0
  95. package/src/components/filter-check-menu/filterCheckOption.ts +10 -0
  96. package/src/components/filter-check-menu/index.ts +2 -0
  97. package/src/components/form-field/FormField.vue +74 -0
  98. package/src/components/form-field/index.ts +2 -0
  99. package/src/components/form-field/types.ts +5 -0
  100. package/src/components/frames/FrameCentred.vue +137 -0
  101. package/src/components/frames/FrameSidebar.vue +113 -0
  102. package/src/components/frames/FrameSplit.vue +109 -0
  103. package/src/components/frames/index.ts +3 -0
  104. package/src/components/icon/BellIcon.vue +27 -0
  105. package/src/components/icon/BoldIcon.vue +31 -0
  106. package/src/components/icon/CalendarDaysIcon.vue +33 -0
  107. package/src/components/icon/CheckIcon.vue +31 -0
  108. package/src/components/icon/ChevronDownIcon.vue +30 -0
  109. package/src/components/icon/ChevronLeftIcon.vue +31 -0
  110. package/src/components/icon/ChevronRightIcon.vue +31 -0
  111. package/src/components/icon/ChevronUpIcon.vue +30 -0
  112. package/src/components/icon/CircleAlertIcon.vue +29 -0
  113. package/src/components/icon/ClockIcon.vue +31 -0
  114. package/src/components/icon/Columns3Icon.vue +32 -0
  115. package/src/components/icon/FlipHorizontalIcon.vue +29 -0
  116. package/src/components/icon/ItalicIcon.vue +28 -0
  117. package/src/components/icon/LinkIcon.vue +27 -0
  118. package/src/components/icon/ListIcon.vue +29 -0
  119. package/src/components/icon/ListOrderedIcon.vue +28 -0
  120. package/src/components/icon/PenLineIcon.vue +31 -0
  121. package/src/components/icon/PlusIcon.vue +28 -0
  122. package/src/components/icon/RotateCcwIcon.vue +28 -0
  123. package/src/components/icon/RotateCwIcon.vue +28 -0
  124. package/src/components/icon/SearchIcon.vue +31 -0
  125. package/src/components/icon/StarIcon.vue +29 -0
  126. package/src/components/icon/TriangleAlertIcon.vue +29 -0
  127. package/src/components/icon/UnderlineIcon.vue +27 -0
  128. package/src/components/icon/Undo2Icon.vue +28 -0
  129. package/src/components/icon/XIcon.vue +31 -0
  130. package/src/components/icon/ZoomInIcon.vue +30 -0
  131. package/src/components/icon/ZoomOutIcon.vue +29 -0
  132. package/src/components/icon/index.ts +37 -0
  133. package/src/components/icon-picker/IconPicker.vue +560 -0
  134. package/src/components/icon-picker/index.ts +1 -0
  135. package/src/components/image-crop-dialog/CropRatioRow.vue +132 -0
  136. package/src/components/image-crop-dialog/CropVariantStrip.vue +277 -0
  137. package/src/components/image-crop-dialog/ImageCropDialog.vue +1541 -0
  138. package/src/components/image-crop-dialog/index.ts +16 -0
  139. package/src/components/image-upload/ImageUpload.vue +345 -0
  140. package/src/components/image-upload/index.ts +2 -0
  141. package/src/components/input/Input.vue +48 -0
  142. package/src/components/input/index.ts +1 -0
  143. package/src/components/keycap/Keycap.vue +49 -0
  144. package/src/components/keycap/index.ts +1 -0
  145. package/src/components/label/Label.vue +26 -0
  146. package/src/components/label/index.ts +1 -0
  147. package/src/components/menu/MenuCheckboxItem.vue +63 -0
  148. package/src/components/menu/MenuContent.vue +45 -0
  149. package/src/components/menu/MenuGroup.vue +22 -0
  150. package/src/components/menu/MenuItem.vue +34 -0
  151. package/src/components/menu/MenuLabel.vue +22 -0
  152. package/src/components/menu/MenuRadioGroup.vue +22 -0
  153. package/src/components/menu/MenuRadioItem.vue +50 -0
  154. package/src/components/menu/MenuRoot.vue +25 -0
  155. package/src/components/menu/MenuSeparator.vue +27 -0
  156. package/src/components/menu/MenuSub.vue +29 -0
  157. package/src/components/menu/MenuSubContent.vue +48 -0
  158. package/src/components/menu/MenuSubTrigger.vue +49 -0
  159. package/src/components/menu/MenuTrigger.vue +22 -0
  160. package/src/components/menu/index.ts +20 -0
  161. package/src/components/menu/menuClasses.ts +74 -0
  162. package/src/components/morph-select/MorphSelect.vue +150 -0
  163. package/src/components/morph-select/index.ts +1 -0
  164. package/src/components/nav/NavFlyout.vue +343 -0
  165. package/src/components/nav/NavGroup.vue +306 -0
  166. package/src/components/nav/NavItem.vue +243 -0
  167. package/src/components/nav/NavNodes.ts +66 -0
  168. package/src/components/nav/NavSection.vue +105 -0
  169. package/src/components/nav/NavSidebar.vue +137 -0
  170. package/src/components/nav/index.ts +5 -0
  171. package/src/components/nav/navChain.ts +112 -0
  172. package/src/components/nav/navClasses.ts +229 -0
  173. package/src/components/nav/navNode.ts +10 -0
  174. package/src/components/nav/navRegistry.ts +24 -0
  175. package/src/components/notification-list/NotificationList.vue +314 -0
  176. package/src/components/notification-list/index.ts +2 -0
  177. package/src/components/notification-list/notifications.ts +21 -0
  178. package/src/components/pagination/Pagination.vue +296 -0
  179. package/src/components/pagination/index.ts +1 -0
  180. package/src/components/pin-field/PinField.vue +332 -0
  181. package/src/components/pin-field/index.ts +1 -0
  182. package/src/components/popover-panel/PopoverPanel.vue +115 -0
  183. package/src/components/popover-panel/index.ts +5 -0
  184. package/src/components/rating/Rating.vue +201 -0
  185. package/src/components/rating/index.ts +1 -0
  186. package/src/components/record-avatar/RecordAvatar.vue +76 -0
  187. package/src/components/record-avatar/index.ts +1 -0
  188. package/src/components/result-window/ResultWindow.vue +399 -0
  189. package/src/components/result-window/index.ts +2 -0
  190. package/src/components/result-window/results.ts +75 -0
  191. package/src/components/rich-editor/RichEditor.vue +370 -0
  192. package/src/components/rich-editor/RichEditorLinkDialog.vue +133 -0
  193. package/src/components/rich-editor/index.ts +8 -0
  194. package/src/components/row-actions/RowActions.vue +262 -0
  195. package/src/components/row-actions/index.ts +2 -0
  196. package/src/components/row-actions/rowActions.ts +44 -0
  197. package/src/components/search-select/SearchSelect.vue +599 -0
  198. package/src/components/search-select/index.ts +2 -0
  199. package/src/components/search-select/types.ts +14 -0
  200. package/src/components/segmented-choice/SegmentedChoice.vue +136 -0
  201. package/src/components/segmented-choice/index.ts +2 -0
  202. package/src/components/segmented-choice/segmentedOption.ts +6 -0
  203. package/src/components/select/Select.vue +18 -0
  204. package/src/components/select/SelectContent.vue +73 -0
  205. package/src/components/select/SelectGroup.vue +21 -0
  206. package/src/components/select/SelectItem.vue +47 -0
  207. package/src/components/select/SelectItemText.vue +12 -0
  208. package/src/components/select/SelectLabel.vue +17 -0
  209. package/src/components/select/SelectScrollDownButton.vue +36 -0
  210. package/src/components/select/SelectScrollUpButton.vue +36 -0
  211. package/src/components/select/SelectSeparator.vue +19 -0
  212. package/src/components/select/SelectTrigger.vue +52 -0
  213. package/src/components/select/SelectValue.vue +12 -0
  214. package/src/components/select/index.ts +11 -0
  215. package/src/components/session/IdleTimer.vue +71 -0
  216. package/src/components/session/SessionDialogs.vue +177 -0
  217. package/src/components/session/index.ts +2 -0
  218. package/src/components/split-button/SplitButton.vue +122 -0
  219. package/src/components/split-button/index.ts +2 -0
  220. package/src/components/split-button/splitButtonItem.ts +7 -0
  221. package/src/components/switch/Switch.vue +60 -0
  222. package/src/components/switch/index.ts +1 -0
  223. package/src/components/table/Table.vue +51 -0
  224. package/src/components/table/TableBody.vue +14 -0
  225. package/src/components/table/TableCaption.vue +17 -0
  226. package/src/components/table/TableCell.vue +22 -0
  227. package/src/components/table/TableEmpty.vue +72 -0
  228. package/src/components/table/TableFooter.vue +17 -0
  229. package/src/components/table/TableHead.vue +22 -0
  230. package/src/components/table/TableHeader.vue +14 -0
  231. package/src/components/table/TableRow.vue +22 -0
  232. package/src/components/table/index.ts +9 -0
  233. package/src/components/tabs/Tabs.vue +173 -0
  234. package/src/components/tabs/index.ts +2 -0
  235. package/src/components/tabs/tabItem.ts +12 -0
  236. package/src/components/textarea/LimitedTextarea.vue +81 -0
  237. package/src/components/textarea/TextLimitCounter.vue +107 -0
  238. package/src/components/textarea/Textarea.vue +42 -0
  239. package/src/components/textarea/index.ts +4 -0
  240. package/src/components/textarea/textLimit.ts +43 -0
  241. package/src/components/time-picker/TimePicker.vue +522 -0
  242. package/src/components/time-picker/index.ts +1 -0
  243. package/src/components/toast/ToastHost.vue +276 -0
  244. package/src/components/toast/index.ts +1 -0
  245. package/src/components/update-notice/UpdateNotice.vue +103 -0
  246. package/src/components/update-notice/index.ts +1 -0
  247. package/src/components/user-menu/UserMenu.vue +154 -0
  248. package/src/components/user-menu/index.ts +1 -0
  249. package/src/index.ts +182 -0
  250. package/src/lib/cn.ts +21 -0
  251. package/src/lib/panelFocus.ts +65 -0
  252. package/src/lib/sessionMonitor.ts +390 -0
  253. package/src/lib/slotContent.ts +17 -0
  254. package/src/lib/updateCheck.ts +133 -0
  255. package/src/styles.css +82 -0
@@ -0,0 +1,343 @@
1
+ <script setup lang="ts">
2
+ import { useEventListener } from '@vueuse/core';
3
+ import { HoverCardContent, HoverCardPortal, HoverCardRoot } from 'reka-ui';
4
+ import type { HTMLAttributes } from 'vue';
5
+ import { computed, inject, nextTick, onBeforeUnmount, provide, ref, useId, watch } from 'vue';
6
+ import { cn } from '../../lib/cn';
7
+ import { NAV_CHAIN, navFlyoutRows } from './navChain';
8
+ import type { NavChainApi } from './navChain';
9
+ import { navFlyoutClass, navFlyoutTitleClass } from './navClasses';
10
+ import { NAV_COLLAPSED, NAV_DEPTH } from './navRegistry';
11
+
12
+ /**
13
+ * One link of the chain a collapsed rail opens: the panel that holds a group's children when the
14
+ * column has no room to hold them in place. A group inside this panel opens another of these
15
+ * beside it, and so on without a limit, which is what makes it a cascade rather than a menu.
16
+ *
17
+ * It is internal to the family and not exported from the package barrel. `NavGroup` is the only
18
+ * thing that renders it, and it is rendered only while it is open: shut, it is not here at all.
19
+ *
20
+ * WHAT IT IS, IN ARIA. A `group`, named by the uppercase title it draws (the record's `.ftitle`),
21
+ * holding links. NOT a `menu` of `menuitem`s: a menu role would make every page of the
22
+ * application a command, and `aria-current="page"` on a command is a contradiction. The trigger
23
+ * that opens it is a disclosure (`aria-expanded`, and `aria-controls` naming this panel while it
24
+ * stands open), which `NavGroup` writes, because `NavGroup` owns the row.
25
+ *
26
+ * WHAT THE ENGINE IS, AND WHY IT IS THIS ONE. `reka-ui`'s HoverCard primitives: `PopperContent`
27
+ * under them is the one overlay engine this package already has (the shipped `PopoverPanel`
28
+ * wraps the same positioner), and of the three families that wrap it this is the only one that
29
+ * writes no `role` of its own and mounts no focus scope. `PopoverContent` would force
30
+ * `role="dialog"` on every link of the chain and a `loop`ed focus scope a keyboard cannot Tab out
31
+ * of; the `NavigationMenu` primitives carry no positioner at all, and nothing here could then
32
+ * flip at the viewport's edge. See the task's report for the measurements.
33
+ *
34
+ * THE `id`, THE `role` AND THE NAME ABOVE ARE THIS FILE'S BECAUSE THE ENGINE SETS NONE OF THEM,
35
+ * and NOT because a caller outranks it. `HoverCardContentImpl` renders
36
+ * `mergeProps({ ...forwarded, ...$attrs }, { … })`, so a caller's attributes are the EARLIER
37
+ * argument and the engine's own would win a collision — which is how `PopoverContent` keeps its
38
+ * `role="dialog"` and its `id` from any caller. Nothing here collides, so do not read this as a
39
+ * licence to override something the engine does write.
40
+ *
41
+ * The engine gives the position (`avoidCollisions` and `sideFlip` are its defaults, so the chain
42
+ * turns back on itself at the edge of the window instead of running off it), the portal, and the
43
+ * layer that answers Escape and a press outside. It does NOT give the pointer intent or the
44
+ * arrows: `HoverCardTrigger` opens on focus and closes on blur, which would open a flyout at
45
+ * every Tab stop and shut it the moment focus entered the panel, so there is no trigger here and
46
+ * the row's intent is `NavGroup`'s. The grace-area hull the trigger would have brought is given
47
+ * up with it; the two delays in `navChain.ts` stand in for it. It also does something that has
48
+ * to be UNDONE rather than supplied: it takes the panel's rows out of the tab order. The watch
49
+ * below puts them back and says what that does and does not buy.
50
+ *
51
+ * DISMISSAL IS THE CHAIN'S, NOT ONE LINK'S. Escape, a press outside, and following a link all
52
+ * shut the whole chain from its root; the first two arrive from the engine's layer as
53
+ * `update:open: false`. `ArrowLeft` is the other half of that rule and the only thing that shuts
54
+ * one link: it closes this panel and returns to the row that opened it. FOCUS GOES BACK TO THE
55
+ * ROW ONLY IF THE CHAIN HELD IT — the engine's layer answers Escape and an outside press
56
+ * wherever the user is, and a chain the pointer opened holds no focus at all, so a dismissal
57
+ * that always focused the trigger took the caret out of whatever was being typed in. A press on a row that
58
+ * opened ANY link of the chain is not a dismissal at all — it is that row's own toggle, so the
59
+ * layer is told to leave it alone, and the question is put to the chain and not to one link,
60
+ * because the layer that answers a press is the innermost open one.
61
+ *
62
+ * INSIDE THE PANEL the rail is over: rows draw their labels again (`NAV_COLLAPSED` is false
63
+ * here) at the record's base scale (`NAV_DEPTH` is 0, as a section does it), and the registry is
64
+ * left alone, so a row in here still registers with the group that holds it and the rail's row
65
+ * keeps naming the page it holds.
66
+ *
67
+ * KNOWN LIMIT: `side` is physical, as the engine's is. The chain opens to the right whatever the
68
+ * document's direction, so a right-to-left column needs a slice of its own.
69
+ */
70
+ defineOptions({ inheritAttrs: false });
71
+
72
+ const props = defineProps<{
73
+ /** The group this panel belongs to: its title, and the panel's accessible name. */
74
+ label: string;
75
+ /** The row the panel hangs off and returns focus to. */
76
+ reference?: HTMLElement;
77
+ /**
78
+ * Take focus into the panel as it appears. `ArrowRight` on the trigger asks for it; a pointer
79
+ * never does. It is answered when the panel's own element arrives rather than after a counted
80
+ * number of ticks, because how many ticks the engine takes is the engine's business.
81
+ */
82
+ enter?: boolean;
83
+ class?: HTMLAttributes['class'];
84
+ }>();
85
+
86
+ const emit = defineEmits<{
87
+ 'update:open': [boolean];
88
+ /** True while the pointer is on the panel, false when it has left it. */
89
+ intent: [boolean];
90
+ }>();
91
+
92
+ const titleId = useId();
93
+ const parent = inject(NAV_CHAIN, null);
94
+
95
+ /**
96
+ * Does focus stand inside this link, or inside any link above it? Asked upwards, as
97
+ * `ownsTrigger` is, because a panel is portalled away from the panel whose row opened it: an
98
+ * outer link's element contains neither the inner panel nor the inner row.
99
+ */
100
+ function holdsFocus(): boolean {
101
+ const active = document.activeElement;
102
+ if (!(active instanceof Node)) return false;
103
+ if (panelEl.value?.contains(active)) return true;
104
+ if (props.reference?.contains(active)) return true;
105
+ return parent?.holdsFocus() ?? false;
106
+ }
107
+
108
+ /**
109
+ * Shut this link alone and give focus back to its trigger — BUT ONLY IF THE CHAIN WAS HOLDING
110
+ * IT. `ArrowLeft` steps back out of a panel, so there focus is inside the chain and the row is
111
+ * where it belongs. A chain the pointer opened holds no focus at all, and Escape and a press
112
+ * outside arrive through the same path from the engine's layer: focusing the row then took the
113
+ * caret out of whatever the user was actually typing in. The pointer never asked for focus, so a
114
+ * dismissal must not hand it anywhere.
115
+ */
116
+ function close(restore = holdsFocus()): void {
117
+ if (restore) props.reference?.focus();
118
+ emit('update:open', false);
119
+ }
120
+
121
+ /**
122
+ * Shut every link, from the root down. On the root link the two are the same thing.
123
+ *
124
+ * The answer travels UP with the request, and that is not ceremony either: the link that is
125
+ * dismissed is the innermost open one, which is where focus is if the chain has it at all, while
126
+ * the row focus belongs on is the ROOT's. Asked again at the root, the question would read false
127
+ * for a chain two links deep whose innermost panel holds the focus.
128
+ */
129
+ function closeAll(restore = holdsFocus()): void {
130
+ if (parent) parent.closeAll(restore);
131
+ else close(restore);
132
+ }
133
+
134
+ /**
135
+ * Pointer intent, told to the group that owns this link and then to every link above it. The
136
+ * walk is not an optimisation: a nested panel is portalled away and is no descendant of the panel
137
+ * whose row opened it, so the hand crossing between them leaves the outer one. See `navChain.ts`.
138
+ */
139
+ function relayIntent(open: boolean): void {
140
+ emit('intent', open);
141
+ parent?.intent(open);
142
+ }
143
+
144
+ /** Does the press belong to a row that opened some link of this chain? Ask upwards. */
145
+ function ownsTrigger(target: Node): boolean {
146
+ if (props.reference?.contains(target)) return true;
147
+ return parent?.ownsTrigger(target) ?? false;
148
+ }
149
+
150
+ /**
151
+ * The `holdsFocus` of every link below this one, however deep. Each link hands its own to the
152
+ * chain above it when it appears and takes it back when it goes, so the root can answer for the
153
+ * whole chain. Each of them asks upwards, so a link's own answer already includes this one's.
154
+ */
155
+ const below = new Set<() => boolean>();
156
+ function adopt(holds: () => boolean): () => void {
157
+ below.add(holds);
158
+ const release = parent?.adopt(holds);
159
+ return () => {
160
+ below.delete(holds);
161
+ release?.();
162
+ };
163
+ }
164
+
165
+ /**
166
+ * Does focus stand ANYWHERE in this chain — this link's panel or row, or any link below it? This
167
+ * is the question a widen asks of the root, and it is `holdsFocus` for every link, not a second
168
+ * predicate: a dismissal is told where focus is by the link it arrives at, a widen arrives at
169
+ * the root and has to ask. Read before the panel is unmounted, while it is still in the document.
170
+ */
171
+ function chainHoldsFocus(): boolean {
172
+ return holdsFocus() || [...below].some((holds) => holds());
173
+ }
174
+ defineExpose({ chainHoldsFocus });
175
+
176
+ if (parent) {
177
+ const release = parent.adopt(holdsFocus);
178
+ onBeforeUnmount(release);
179
+ }
180
+
181
+ provide<NavChainApi>(NAV_CHAIN, {
182
+ closeAll,
183
+ intent: relayIntent,
184
+ ownsTrigger,
185
+ holdsFocus,
186
+ adopt,
187
+ });
188
+ provide(NAV_COLLAPSED, ref(false));
189
+ provide(NAV_DEPTH, ref(0));
190
+
191
+ /**
192
+ * The panel's own element, which is not this component's root: the engine wraps it in a positioner
193
+ * and renders it behind a presence gate, so it arrives some ticks after this component does.
194
+ * `$el` on a reka primitive reads a ref the engine writes when the element mounts, so a computed
195
+ * over it tracks that arrival instead of guessing at when it happens.
196
+ */
197
+ const panelRef = ref<{ $el?: unknown } | null>(null);
198
+ const panelEl = computed(() => {
199
+ const el = panelRef.value?.$el;
200
+ return el instanceof HTMLElement ? el : undefined;
201
+ });
202
+
203
+ watch([panelEl, () => props.enter], ([panel, enter]) => {
204
+ if (panel && enter) navFlyoutRows(panel)[0]?.focus();
205
+ });
206
+
207
+ /**
208
+ * THE PANEL'S DOM LISTENERS ARE BOUND HERE AND NOT IN THE TEMPLATE, and that is a measurement and
209
+ * not a preference. A listener written on `HoverCardContent` reaches the panel as a fall-through
210
+ * attribute through three component layers, and it was MEASURED to be dropped from the element on
211
+ * a later patch: with two links of the chain open, closing the inner one left the outer panel's
212
+ * element in place, its `data-slot`, `role` and classes intact, and its keydown handler gone — so
213
+ * ArrowLeft stopped working on exactly the panel a user steps back into. Bound to the element the
214
+ * engine hands us, the three survive every patch. `pointerDownOutside` below is a DECLARED emit of
215
+ * `HoverCardContent`, consumed before any of that, which is why it stays in the template.
216
+ */
217
+ useEventListener(panelEl, 'keydown', (event: KeyboardEvent) => onKeydown(event));
218
+ useEventListener(panelEl, 'pointerenter', () => relayIntent(true));
219
+ useEventListener(panelEl, 'pointerleave', () => relayIntent(false));
220
+
221
+ /**
222
+ * THE ENGINE TAKES THIS PANEL'S ROWS OUT OF THE TAB ORDER, AND THIS PUTS THEM BACK.
223
+ * `HoverCardContentImpl`'s `onMounted` walks every node whose `tabIndex` is 0 or more and sets
224
+ * `tabindex="-1"` on it, unconditionally (`reka-ui@2.12.0`, `HoverCard/utils.js`): a hover card
225
+ * is a thing you read, and the engine keeps the whole of it out of the sequence. This panel is
226
+ * something else — the region a disclosure's `aria-controls` names, holding LINKS — and a region
227
+ * that holds no tab stop at all is a broken keyboard contract. It is taken off this family's own
228
+ * rows only, so nothing a consumer put in the slot is touched. A row inside a nested group's
229
+ * hidden kids container keeps the engine's `-1`: it is `display: none` and takes no focus anyway.
230
+ *
231
+ * AFTER A TICK, NOT AT ONCE, AND THAT IS THE ENGINE'S BUSINESS — measured, not assumed.
232
+ * `HoverCardContentImpl` is an async component, so whether its `onMounted` has run when this
233
+ * panel's element arrives depends on whether that module is still being imported: cached, the
234
+ * engine writes the attribute synchronously at mount; uncached, it writes between the element's
235
+ * arrival and the first tick. `nextTick` is after both, so one pass there answers both orders. A
236
+ * pass at the moment of arrival was a second path to the same outcome (removing it left both the
237
+ * cached suite and the uncached `NavFlyout.firstopen.test.ts` green) and was deleted. A pass
238
+ * before the engine writes passed a whole suite and failed the same run alone, which is why the
239
+ * pass is not made at arrival.
240
+ *
241
+ * WHAT IT DOES NOT BUY, stated so that nobody reads more into it: the panel is portalled to the
242
+ * end of `body`, so tab order follows DOM order and these rows sit at the end of the document
243
+ * rather than after the trigger. Stripping the attribute does not make the panel the NEXT tab
244
+ * stop and is not meant to. `ArrowRight` remains the designed way in; what this restores is that
245
+ * a row which has been reached is in the sequence, and can be left by `Tab` like any link.
246
+ */
247
+ function freeTabStops(panel: HTMLElement): void {
248
+ for (const row of navFlyoutRows(panel)) row.removeAttribute('tabindex');
249
+ }
250
+
251
+ watch(panelEl, (panel) => {
252
+ if (!panel) return;
253
+ void nextTick(() => {
254
+ if (panelEl.value === panel) freeTabStops(panel);
255
+ });
256
+ });
257
+
258
+ /**
259
+ * FOLLOWING A LINK CLOSES THE WHOLE CHAIN. A press on a row that has children opens that row's
260
+ * own panel instead and is not this, which is why only a link counts. The two ways a user follows
261
+ * one — a press, and `Enter` with the link focused — are the same `click` to an anchor, so one
262
+ * listener answers both.
263
+ *
264
+ * It is deferred by a microtask, and that is not ceremony. Removing an anchor from the document
265
+ * part-way through its own click can keep the browser from following it at all, and the chain
266
+ * closing unmounts the very anchor that was pressed. A microtask runs after the event's activation
267
+ * behaviour, so the navigation is under way before the panel goes. jsdom follows no link, so the
268
+ * suite can measure the closing but not this ordering; it is stated here instead of asserted.
269
+ */
270
+ useEventListener(panelEl, 'click', (event: MouseEvent) => {
271
+ const target = event.target;
272
+ if (!(target instanceof Element)) return;
273
+ if (target.closest('a[data-slot="nav-item"]')) queueMicrotask(closeAll);
274
+ });
275
+
276
+ /**
277
+ * The arrows that move inside one panel, and the one that steps back out of it. Down and up
278
+ * clamp at the ends, as a listbox does; they never step into another link of the chain, because
279
+ * a nested panel is portalled away and is not inside this element to be found.
280
+ */
281
+ function onKeydown(event: KeyboardEvent): void {
282
+ if (event.defaultPrevented) return;
283
+ if (event.key === 'ArrowLeft') {
284
+ event.preventDefault();
285
+ close();
286
+ return;
287
+ }
288
+ if (event.key !== 'ArrowDown' && event.key !== 'ArrowUp') return;
289
+ const rows = navFlyoutRows(panelEl.value);
290
+ if (rows.length === 0) return;
291
+ event.preventDefault();
292
+ const at = rows.indexOf(document.activeElement as HTMLElement);
293
+ const last = rows.length - 1;
294
+ const next =
295
+ event.key === 'ArrowDown'
296
+ ? at < 0
297
+ ? 0
298
+ : Math.min(at + 1, last)
299
+ : at < 0
300
+ ? last
301
+ : Math.max(at - 1, 0);
302
+ rows[next]?.focus();
303
+ }
304
+
305
+ /** A press on a row that opened a link of this chain belongs to that row, not to a dismissal. */
306
+ function onPointerDownOutside(event: CustomEvent<{ originalEvent: PointerEvent }>): void {
307
+ const target = event.detail.originalEvent.target;
308
+ if (target instanceof Node && ownsTrigger(target)) event.preventDefault();
309
+ }
310
+ </script>
311
+
312
+ <template>
313
+ <HoverCardRoot
314
+ :open="true"
315
+ @update:open="
316
+ (next: boolean) => {
317
+ if (!next) closeAll();
318
+ }
319
+ "
320
+ >
321
+ <HoverCardPortal>
322
+ <HoverCardContent
323
+ ref="panelRef"
324
+ v-bind="$attrs"
325
+ data-slot="nav-flyout"
326
+ role="group"
327
+ :aria-labelledby="titleId"
328
+ :reference="reference"
329
+ side="right"
330
+ align="start"
331
+ :side-offset="4"
332
+ :collision-padding="8"
333
+ :class="cn(navFlyoutClass, props.class)"
334
+ @pointer-down-outside="onPointerDownOutside"
335
+ >
336
+ <div :id="titleId" data-slot="nav-flyout-title" :class="navFlyoutTitleClass">
337
+ {{ label }}
338
+ </div>
339
+ <slot />
340
+ </HoverCardContent>
341
+ </HoverCardPortal>
342
+ </HoverCardRoot>
343
+ </template>
@@ -0,0 +1,306 @@
1
+ <script setup lang="ts">
2
+ import type { HTMLAttributes, Ref } from 'vue';
3
+ import {
4
+ computed,
5
+ inject,
6
+ onBeforeUnmount,
7
+ provide,
8
+ ref,
9
+ shallowReactive,
10
+ useId,
11
+ watch,
12
+ } from 'vue';
13
+ import { cn } from '../../lib/cn';
14
+ import NavFlyout from './NavFlyout.vue';
15
+ import { NAV_CHAIN, NAV_FLYOUT_CLOSE_DELAY, NAV_FLYOUT_OPEN_DELAY } from './navChain';
16
+ import {
17
+ navChevronClass,
18
+ navChevronShutClass,
19
+ navHoldsClass,
20
+ navIconClass,
21
+ navIconCurrentClass,
22
+ navIconRailClass,
23
+ navIconRestClass,
24
+ navKidsClass,
25
+ navLabelClass,
26
+ navRowBarlessClass,
27
+ navRowClass,
28
+ navRowCollapsedClass,
29
+ navRowCurrentClass,
30
+ navRowDepthClass,
31
+ navRowInteractiveClass,
32
+ } from './navClasses';
33
+ import { NAV_COLLAPSED, NAV_DEPTH, NAV_GROUP } from './navRegistry';
34
+ import type { NavEntry, NavGroupApi } from './navRegistry';
35
+
36
+ /**
37
+ * A navigation level that holds levels: a trigger row and, beneath it, the items and groups it
38
+ * contains. `open` is the consumer's (ADR 0017); the group only asks for a change.
39
+ *
40
+ * While shut it names the current page it holds, and is drawn as a current row while it does,
41
+ * as the record draws it. To know that it needs its items mounted even when they are not on
42
+ * screen, so the kids are hidden with `display: none` (`v-show`) and stay mounted: they still
43
+ * register, and are out of the accessibility tree, the pointer's reach and the tab order.
44
+ *
45
+ * WHERE THE CHILDREN GO, AND WHO OWNS THE DISCLOSURE. In the open column they are drawn in place,
46
+ * one level in, under the consumer's `open`. In a 56px rail there is no room for 22px of indent,
47
+ * and in a 178px panel no more, so a group **in either** hands its children to a `NavFlyout`
48
+ * beside the row instead (the record's cascade) and the group's own disclosure state is then the
49
+ * flyout's, kept here and NOT the consumer's: a flyout that opens under the pointer must not
50
+ * quietly expand a group the consumer believes is shut. That is the second deliberate asymmetry
51
+ * in this family, beside the one `NavSidebar` records between its two doors, and `open` is left
52
+ * untouched in a rail for exactly that reason.
53
+ *
54
+ * THE CHILDREN ARE MOUNTED IN ONE OF THE TWO PLACES, AND ALWAYS IN EXACTLY ONE, which is the
55
+ * part worth not undoing. While the flyout is shut they sit in the hidden kids container as they
56
+ * always have; while it is open they are in the panel. Both halves register, so the one cue a
57
+ * 56px column has to the page the whole menu holds — the row drawn as the current row — survives
58
+ * a shut flyout. Unmounting them with the panel would take it away. This heading read "EITHER
59
+ * WAY" before, which was taken for "in both places": the state it has to rule out is the one
60
+ * where they are in NEITHER, and that is what the watch on `flyout` below exists for.
61
+ *
62
+ * THE TRIGGER'S ATTRIBUTES DESCRIBE THE THING THAT OPENS. `aria-expanded` is the disclosure's
63
+ * state wherever the children are, and `aria-controls` names them: the kids container in the open
64
+ * column, and the flyout's panel in a rail — but only while that panel is rendered, because a
65
+ * shut flyout is not in the document and an `aria-controls` pointing at nothing is worse than
66
+ * none. An earlier revision dropped both attributes in a rail, and was right to while the kids
67
+ * were merely hidden and nothing ever opened; it is the flyout that makes the claim true.
68
+ *
69
+ * The holds label resolves after the first tick. Items register while the group renders, after
70
+ * its own trigger has been drawn, so the label follows on the next render. That is inherent to
71
+ * registration during render and is not a bug; it is also absent from server output.
72
+ */
73
+ defineOptions({ inheritAttrs: false });
74
+
75
+ const props = defineProps<{
76
+ label: string;
77
+ open?: boolean;
78
+ class?: HTMLAttributes['class'];
79
+ }>();
80
+ const emit = defineEmits<{ 'update:open': [boolean] }>();
81
+
82
+ const depth = inject(NAV_DEPTH, ref(0));
83
+ const collapsed = inject(NAV_COLLAPSED, ref(false));
84
+ const parent = inject(NAV_GROUP, null);
85
+ const chain = inject(NAV_CHAIN, null);
86
+
87
+ // A rail row flies out; so does a row already inside a flyout, which is what carries the cascade
88
+ // past its second link. Nothing else does.
89
+ const flyout = computed(() => collapsed.value || chain !== null);
90
+
91
+ // Registration order is child-setup order, not document order after a later insertion, so only
92
+ // "the first current entry" is read from it and nothing order-sensitive.
93
+ let nextId = 0;
94
+ const entries = shallowReactive(new Map<number, Ref<Readonly<NavEntry>>>());
95
+ const api: NavGroupApi = {
96
+ register(entry) {
97
+ const id = nextId++;
98
+ entries.set(id, entry);
99
+ return () => {
100
+ entries.delete(id);
101
+ };
102
+ },
103
+ };
104
+ provide(NAV_GROUP, api);
105
+ provide(
106
+ NAV_DEPTH,
107
+ computed(() => depth.value + 1),
108
+ );
109
+
110
+ const holds = computed(() => {
111
+ for (const entry of entries.values()) if (entry.value.current) return entry.value;
112
+ return undefined;
113
+ });
114
+
115
+ // A nested group tells its own parent about the page it holds, so a shut ancestor can name it.
116
+ const own = computed<Readonly<NavEntry>>(() => ({
117
+ label: holds.value?.label ?? props.label,
118
+ current: !!holds.value,
119
+ }));
120
+ const withdraw = parent?.register(own);
121
+ onBeforeUnmount(() => withdraw?.());
122
+
123
+ const rowEl = ref<HTMLElement>();
124
+ const flyoutOpen = ref(false);
125
+ // Whether the open now in flight is also to take focus into the panel. ArrowRight asks for that;
126
+ // a pointer never does, or a hand crossing the column would take the keyboard with it.
127
+ const enterOnOpen = ref(false);
128
+
129
+ // The group's disclosure: the flyout's state where there is one, the consumer's where there is not.
130
+ const isOpen = computed(() => (flyout.value ? flyoutOpen.value : !!props.open));
131
+
132
+ /**
133
+ * DRAWN AS THE CURRENT ROW, which is a different question from being open and must not be read
134
+ * off the same flag. Where the children are drawn in place, an open group must not take the
135
+ * marking: the current row is on screen one level in and would be said twice. IN THE RAIL the
136
+ * children are never in the column at all, so the row carries it whether its flyout stands open or
137
+ * not — `wave-3-layout.html:999` draws exactly that, the rail row on `--sidebar-accent` while the
138
+ * pointer is on a row of the flyout, so that ground is not a hover state. Tying this to `isOpen`
139
+ * alone cost the rail its one cue to the page the whole menu holds for as long as the chain stood
140
+ * open, which is also the reason the children stay mounted.
141
+ *
142
+ * `collapsed` AND NOT `flyout`, and the reason is no longer the one it was. It used to be that the
143
+ * wider flag would have put a current row's bar outside a 178px panel; a panel now draws no bar at
144
+ * all (`navRowBarlessClass`), so that cost is gone. What is left is the surface: THE COLUMN IS
145
+ * PERSISTENT and has to say where you are at every moment, and in a rail this row is the only
146
+ * standing that branch has in it. A row inside a PANEL is already on a transient surface, so it
147
+ * keeps the in-place rule and steps back while its own panel is open — which walks the marking
148
+ * down to the deepest level on screen while the column's row holds steady. It also keeps the
149
+ * holds label, which this flag drives too, on the one state it reads well in: a label naming the
150
+ * page behind a row you cannot see into.
151
+ */
152
+ const holdsCurrent = computed(() => (collapsed.value || !isOpen.value) && !!holds.value);
153
+
154
+ const kidsId = useId();
155
+
156
+ /**
157
+ * POINTER INTENT, which is the difference between a pointer that crosses the row and one that
158
+ * stays on it. One pending timer at a time: entering the row cancels a pending close, leaving it
159
+ * cancels a pending open, and the panel reports its own `intent` through the same two calls, so
160
+ * the hand can travel from a 38px row to the panel beside it without the panel going out on the
161
+ * way. A press is intent already stated and waits for nothing.
162
+ */
163
+ let timer: ReturnType<typeof setTimeout> | undefined;
164
+ function cancel(): void {
165
+ if (timer !== undefined) clearTimeout(timer);
166
+ timer = undefined;
167
+ }
168
+
169
+ /** State stated outright: a press, a key, or the panel saying it has been dismissed. */
170
+ function setFlyout(open: boolean, enter = false): void {
171
+ cancel();
172
+ enterOnOpen.value = open && enter;
173
+ flyoutOpen.value = open;
174
+ }
175
+
176
+ /** State asked for by a pointer, which has to mean it by staying. */
177
+ function intend(open: boolean): void {
178
+ cancel();
179
+ if (open === flyoutOpen.value) return;
180
+ timer = setTimeout(
181
+ () => {
182
+ timer = undefined;
183
+ setFlyout(open);
184
+ },
185
+ open ? NAV_FLYOUT_OPEN_DELAY : NAV_FLYOUT_CLOSE_DELAY,
186
+ );
187
+ }
188
+ onBeforeUnmount(cancel);
189
+
190
+ /**
191
+ * THE FLYOUT'S STATE IS THE FLYOUT'S, so it goes when the flyout does. `flyout` turns false the
192
+ * moment the column is widened — which is exactly what the `toggle` the `#top` slot is handed
193
+ * does — and the panel is then taken out by its own `v-if` without emitting anything, so nothing
194
+ * else in this file would clear `flyoutOpen`. Left standing it is read twice: the panel is gone
195
+ * because `flyout` is false, and the kids container renders nothing because `v-if="!flyoutOpen"`
196
+ * is false. The children are then in NEITHER place and the whole branch is gone from the column,
197
+ * with the row's marking and the holds label going with their registrations — and narrowing again
198
+ * would open a panel with no pointer and no key behind it. The pointer path heals itself when the
199
+ * closing timer fires; the keyboard path does not, which is why this is a watch and not a delay.
200
+ */
201
+ const flyoutRef = ref<InstanceType<typeof NavFlyout>>();
202
+ watch(flyout, (flies) => {
203
+ if (flies) return;
204
+ // Asked while the panel is still in the document (a pre-flush watch runs before the render
205
+ // that removes it). A widen is not a dismissal and the dismissal's rule is the same: take
206
+ // focus to this row only if the chain held it, so a caret in a field elsewhere stays there.
207
+ const restore = flyoutRef.value?.chainHoldsFocus() ?? false;
208
+ setFlyout(false);
209
+ if (restore) rowEl.value?.focus();
210
+ });
211
+
212
+ function press(): void {
213
+ if (flyout.value) setFlyout(!flyoutOpen.value);
214
+ else emit('update:open', !isOpen.value);
215
+ }
216
+
217
+ /**
218
+ * ArrowRight opens the flyout and steps into it. WHICH tick the panel is in the document by is
219
+ * the engine's business and has changed under us once already, so the step in is not counted in
220
+ * ticks here: `NavFlyout` is handed `enter` and takes the focus when its own panel appears.
221
+ */
222
+ function onKeydown(event: KeyboardEvent): void {
223
+ if (!flyout.value || event.key !== 'ArrowRight' || event.defaultPrevented) return;
224
+ event.preventDefault();
225
+ setFlyout(true, true);
226
+ }
227
+ </script>
228
+
229
+ <template>
230
+ <div v-bind="$attrs" data-slot="nav-group" :class="cn('grid', props.class)">
231
+ <button
232
+ ref="rowEl"
233
+ type="button"
234
+ data-slot="nav-group-trigger"
235
+ :aria-expanded="isOpen"
236
+ :aria-controls="flyout && !flyoutOpen ? undefined : kidsId"
237
+ :title="collapsed ? label : undefined"
238
+ :class="
239
+ cn(
240
+ navRowClass,
241
+ navRowDepthClass(depth),
242
+ navRowInteractiveClass,
243
+ holdsCurrent && navRowCurrentClass,
244
+ holdsCurrent && chain !== null && navRowBarlessClass,
245
+ collapsed && navRowCollapsedClass,
246
+ )
247
+ "
248
+ @click="press()"
249
+ @keydown="onKeydown"
250
+ @pointerenter="flyout && intend(true)"
251
+ @pointerleave="flyout && intend(false)"
252
+ >
253
+ <span
254
+ v-if="$slots.icon"
255
+ :class="
256
+ cn(
257
+ navIconClass,
258
+ holdsCurrent ? navIconCurrentClass : navIconRestClass,
259
+ collapsed && navIconRailClass,
260
+ )
261
+ "
262
+ >
263
+ <slot name="icon" />
264
+ </span>
265
+ <template v-if="!collapsed">
266
+ <span :class="cn(navLabelClass, holdsCurrent && 'flex-initial')">{{ label }}</span>
267
+ <span v-if="holdsCurrent" data-slot="nav-group-holds" :class="navHoldsClass"
268
+ >· {{ holds!.label }}</span
269
+ >
270
+ <svg
271
+ data-slot="nav-group-chevron"
272
+ viewBox="0 0 24 24"
273
+ fill="none"
274
+ stroke="currentColor"
275
+ stroke-width="2.5"
276
+ stroke-linecap="round"
277
+ aria-hidden="true"
278
+ :class="cn(navChevronClass, (flyout || !isOpen) && navChevronShutClass)"
279
+ >
280
+ <path d="m6 9 6 6 6-6" />
281
+ </svg>
282
+ </template>
283
+ <span v-else class="sr-only">{{ label }}</span>
284
+ </button>
285
+ <NavFlyout
286
+ v-if="flyout && flyoutOpen"
287
+ :id="kidsId"
288
+ ref="flyoutRef"
289
+ :label="label"
290
+ :reference="rowEl"
291
+ :enter="enterOnOpen"
292
+ @update:open="(next: boolean) => setFlyout(next)"
293
+ @intent="intend"
294
+ >
295
+ <slot />
296
+ </NavFlyout>
297
+ <div
298
+ v-show="isOpen && !flyout"
299
+ :id="flyout ? undefined : kidsId"
300
+ data-slot="nav-group-kids"
301
+ :class="navKidsClass(depth + 1)"
302
+ >
303
+ <slot v-if="!flyoutOpen" />
304
+ </div>
305
+ </div>
306
+ </template>