@eldrajs/theme-cli 0.2.2 → 0.2.4
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.
- package/dist/cli.js +2 -3
- package/dist/index.d.ts +0 -12
- package/dist/index.js +1 -1
- package/dist/{validate-DprFpjV7.js → validate-FjQ-5_ne.js} +9 -18
- package/package.json +3 -3
- package/template/.eldra/previews.json +35 -35
- package/template/app/plugins/chunk-reload.client.ts +29 -0
- package/template/app/plugins/eldra-storefront.ts +5 -0
- package/template/app/storefront/gateway.ts +34 -14
- package/template/app/storefront/sharedRead.ts +34 -0
- package/template/app/storefront/structuredData.ts +19 -2
- package/template/app/storefront/types.ts +0 -5
- package/template/app/utils/chunkReload.ts +11 -0
- package/template/app/utils/seoInput.ts +0 -1
- package/template/blocks/article-list/preview.png +0 -0
- package/template/blocks/breadcrumbs/preview.png +0 -0
- package/template/blocks/cart/preview.png +0 -0
- package/template/blocks/collection-grid/Block.vue +146 -94
- package/template/blocks/collection-grid/__tests__/Block.spec.ts +116 -2
- package/template/blocks/collection-grid/preview.png +0 -0
- package/template/blocks/collection-header/preview.png +0 -0
- package/template/blocks/navigation/Block.vue +125 -541
- package/template/blocks/navigation/__tests__/Block.spec.ts +172 -73
- package/template/blocks/navigation/parts/MenuLink.vue +15 -0
- package/template/blocks/product-detail/preview.png +0 -0
- package/template/blocks/search/preview.png +0 -0
- package/template/blocks/team/preview.png +0 -0
- package/template/blocks/video-embed/preview.png +0 -0
- package/template/package.json +1 -1
- package/template/test/chunkReload.spec.ts +20 -0
- package/template/test/imageFraming.browser.spec.ts +125 -0
- package/template/test/pages/article.spec.ts +1 -1
- package/template/test/pages/collection.spec.ts +1 -1
- package/template/test/pages/home.spec.ts +1 -1
- package/template/test/pages/product.spec.ts +1 -1
- package/template/test/prerenderRefresh.browser.spec.ts +58 -13
- package/template/test/seoInput.spec.ts +5 -4
- package/template/test/storefront/gateway.spec.ts +6 -0
- package/template/test/storefront/gatewayPrerender.spec.ts +26 -1
- package/template/test/storefront/sharedRead.spec.ts +43 -0
- package/template/test/storefront/structuredData.spec.ts +34 -6
- package/template/test/structuredData.generate.spec.ts +1 -1
- package/template/test/support/mockGateway.ts +8 -3
- package/template/blocks/navigation/useMegaMenuKeys.ts +0 -276
|
@@ -1,276 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The header bar's mega-menu keyboard model, kept out of `Block.vue` because it is a self-contained
|
|
3
|
-
* piece of behaviour over the bar's own DOM — the block keeps the open state and this drives focus
|
|
4
|
-
* through it.
|
|
5
|
-
*
|
|
6
|
-
* The pattern is the WAI-ARIA APG's **Disclosure Navigation Menu** with its arrow-key extension.
|
|
7
|
-
* Not a `combobox` (that role belongs to a text input) and not a `menubar` (these are site
|
|
8
|
-
* navigation links, not application commands), so there is no `role="menu"`, no
|
|
9
|
-
* `aria-activedescendant` and no roving `tabindex`: focus moves to the real links with `.focus()`,
|
|
10
|
-
* every one of them stays in the tab sequence, and the only ARIA on the trigger is
|
|
11
|
-
* `aria-expanded` / `aria-controls`.
|
|
12
|
-
*
|
|
13
|
-
* Reading order is the DOM's: the bar's list renders one `<li>` per resolved link — the trigger (or
|
|
14
|
-
* plain link) first, then that item's panel — so the `<li>`'s position *is* the `links` index, and
|
|
15
|
-
* a panel's links come out of `querySelectorAll` already in the order a visitor reads them (the
|
|
16
|
-
* group columns, then the trailing "View all" row). Nothing here keeps a parallel list of elements
|
|
17
|
-
* that could fall out of step with what is rendered.
|
|
18
|
-
*
|
|
19
|
-
* Arrow keys clamp at both ends rather than wrapping: a visitor holding ArrowDown should stop at
|
|
20
|
-
* the last row instead of silently landing back on the first.
|
|
21
|
-
*/
|
|
22
|
-
import { nextTick, type Ref } from 'vue';
|
|
23
|
-
|
|
24
|
-
/** A focusable top-level item of the bar's list, with the `links` index its `<li>` sits at. */
|
|
25
|
-
interface TopLevelItem {
|
|
26
|
-
el: HTMLElement;
|
|
27
|
-
index: number;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
type Edge = 'first' | 'last';
|
|
31
|
-
|
|
32
|
-
export interface MegaMenuKeysOptions {
|
|
33
|
-
/** The bar's own `<ul>` of top-level items (`null` while the bar renders without it). */
|
|
34
|
-
list: Ref<HTMLElement | null>;
|
|
35
|
-
/** Which panel is open, `null` for none. */
|
|
36
|
-
openIndex: Ref<number | null>;
|
|
37
|
-
/** Whether the item at `index` has a mega-menu panel at all. */
|
|
38
|
-
hasPanel: (index: number) => boolean;
|
|
39
|
-
/** Open `index`'s panel (closing any other) as a keyboard-owned one, which hover never closes. */
|
|
40
|
-
open: (index: number) => void;
|
|
41
|
-
/** Toggle `index`'s panel. */
|
|
42
|
-
toggle: (index: number) => void;
|
|
43
|
-
/** Close whatever is open, leaving focus where it is. */
|
|
44
|
-
close: () => void;
|
|
45
|
-
/** Close `index`'s panel and put focus back on its trigger. */
|
|
46
|
-
closeAndFocusTrigger: (index: number) => void;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export interface MegaMenuKeys {
|
|
50
|
-
onTriggerKeydown: (index: number, event: KeyboardEvent) => void;
|
|
51
|
-
onPanelKeydown: (index: number, event: KeyboardEvent) => void;
|
|
52
|
-
onBarLinkKeydown: (index: number, event: KeyboardEvent) => void;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export function useMegaMenuKeys(options: MegaMenuKeysOptions): MegaMenuKeys {
|
|
56
|
-
function itemElement(index: number): HTMLElement | null {
|
|
57
|
-
const li = options.list.value?.children[index];
|
|
58
|
-
return li instanceof HTMLElement ? li : null;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* The bar's focusable top-level items in bar order: a mega-menu trigger (`<button>`) or a plain
|
|
63
|
-
* link (`<a>`), each the first element child of its `<li>`. This walks the `<li>` children rather
|
|
64
|
-
* than querying the list for `a, button` because an open panel's own links live deeper in that
|
|
65
|
-
* same `<li>` and must never be mistaken for a top-level item. An item whose destination no
|
|
66
|
-
* longer resolves renders as a `<span>`: not focusable, so an arrow key steps over it instead of
|
|
67
|
-
* landing on a dead row.
|
|
68
|
-
*/
|
|
69
|
-
function topLevelItems(): TopLevelItem[] {
|
|
70
|
-
const list = options.list.value;
|
|
71
|
-
if (list === null) return [];
|
|
72
|
-
const items: TopLevelItem[] = [];
|
|
73
|
-
const rows = Array.from(list.children);
|
|
74
|
-
for (let index = 0; index < rows.length; index += 1) {
|
|
75
|
-
for (const child of Array.from(rows[index]!.children)) {
|
|
76
|
-
if (child instanceof HTMLElement && (child.tagName === 'BUTTON' || child.tagName === 'A')) {
|
|
77
|
-
items.push({ el: child, index });
|
|
78
|
-
break;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
return items;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* One panel's focusable links, in the panel's own DOM order. A row with no destination renders as
|
|
87
|
-
* a `<span>`, so `a[href]` doubles as the "is it focusable" test; `button` is matched too so a
|
|
88
|
-
* panel part that grows one later is walked without a change here.
|
|
89
|
-
*/
|
|
90
|
-
function panelLinks(index: number): HTMLElement[] {
|
|
91
|
-
const panel = itemElement(index)?.querySelector('[data-eldra-mega-panel]');
|
|
92
|
-
if (!(panel instanceof HTMLElement)) return [];
|
|
93
|
-
return Array.from(panel.querySelectorAll<HTMLElement>('a[href], button:not([disabled])'));
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
function clamp(position: number, length: number): number {
|
|
97
|
-
return Math.min(Math.max(position, 0), length - 1);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* The panel is `v-show`n, so between the open state changing and Vue flushing it the element is
|
|
102
|
-
* still `display: none` — and `focus()` on a hidden element does nothing. Always focus on the
|
|
103
|
-
* next tick, which is also harmless when the panel was open already (Home/End inside one).
|
|
104
|
-
*/
|
|
105
|
-
function focusPanelEdge(index: number, edge: Edge): void {
|
|
106
|
-
void nextTick(() => {
|
|
107
|
-
const links = panelLinks(index);
|
|
108
|
-
const target = edge === 'first' ? links[0] : links[links.length - 1];
|
|
109
|
-
target?.focus();
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
function focusPanelLink(index: number, position: number): void {
|
|
114
|
-
const links = panelLinks(index);
|
|
115
|
-
if (links.length === 0) return;
|
|
116
|
-
links[clamp(position, links.length)]?.focus();
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
/** Which link in the panel has focus now, `-1` when focus sits somewhere else in it. */
|
|
120
|
-
function focusedPanelPosition(index: number): number {
|
|
121
|
-
const active = typeof document === 'undefined' ? null : document.activeElement;
|
|
122
|
-
if (active === null) return -1;
|
|
123
|
-
return panelLinks(index).findIndex((link) => link === active || link.contains(active));
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
/**
|
|
127
|
-
* Moves focus to another top-level item, and takes the open panel with it.
|
|
128
|
-
*
|
|
129
|
-
* Focus always lands on the item itself — the trigger button or the plain link — never inside the
|
|
130
|
-
* neighbour's panel, wherever it travelled from: the pattern's own rule is "move to the next
|
|
131
|
-
* button and expand its dropdown", and `ArrowDown` from there is what enters the panel. That also
|
|
132
|
-
* means nothing can strand focus: an open panel with no focusable row of its own (every child's
|
|
133
|
-
* destination deleted, and a `kind: "none"` parent so there is no "View all" either) leaves focus
|
|
134
|
-
* sitting on its trigger, where every key still works.
|
|
135
|
-
*
|
|
136
|
-
* The open panel follows: landing on another trigger opens that one, and landing on a plain link
|
|
137
|
-
* closes what was open. With nothing open to begin with, this is a plain focus move.
|
|
138
|
-
*/
|
|
139
|
-
function focusTopLevel(position: number): void {
|
|
140
|
-
const items = topLevelItems();
|
|
141
|
-
const target = items[position];
|
|
142
|
-
if (target === undefined) return;
|
|
143
|
-
if (options.openIndex.value !== null) {
|
|
144
|
-
if (options.hasPanel(target.index)) options.open(target.index);
|
|
145
|
-
else options.close();
|
|
146
|
-
}
|
|
147
|
-
target.el.focus();
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
/** ArrowRight / ArrowLeft: one step along the bar, clamped at both ends. */
|
|
151
|
-
function stepTopLevel(index: number, delta: number): void {
|
|
152
|
-
const items = topLevelItems();
|
|
153
|
-
const position = items.findIndex((item) => item.index === index);
|
|
154
|
-
if (position === -1) return;
|
|
155
|
-
const next = clamp(position + delta, items.length);
|
|
156
|
-
// Already at that end: nothing moves, and focus stays exactly where the visitor left it.
|
|
157
|
-
if (next === position) return;
|
|
158
|
-
focusTopLevel(next);
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
/** Home / End: the bar's first or last item. */
|
|
162
|
-
function edgeTopLevel(edge: Edge): void {
|
|
163
|
-
const items = topLevelItems();
|
|
164
|
-
if (items.length === 0) return;
|
|
165
|
-
focusTopLevel(edge === 'first' ? 0 : items.length - 1);
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
/**
|
|
169
|
-
* The four keys that travel the bar's own row, shared by every handler below so they cannot drift
|
|
170
|
-
* apart as keys are added. Returns whether it took the key, which is what keeps `preventDefault`
|
|
171
|
-
* to the keys actually handled.
|
|
172
|
-
*/
|
|
173
|
-
function barTravel(index: number, event: KeyboardEvent): boolean {
|
|
174
|
-
switch (event.key) {
|
|
175
|
-
case 'ArrowRight':
|
|
176
|
-
event.preventDefault();
|
|
177
|
-
stepTopLevel(index, 1);
|
|
178
|
-
return true;
|
|
179
|
-
case 'ArrowLeft':
|
|
180
|
-
event.preventDefault();
|
|
181
|
-
stepTopLevel(index, -1);
|
|
182
|
-
return true;
|
|
183
|
-
case 'Home':
|
|
184
|
-
event.preventDefault();
|
|
185
|
-
edgeTopLevel('first');
|
|
186
|
-
return true;
|
|
187
|
-
case 'End':
|
|
188
|
-
event.preventDefault();
|
|
189
|
-
edgeTopLevel('last');
|
|
190
|
-
return true;
|
|
191
|
-
default:
|
|
192
|
-
return false;
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
function onTriggerKeydown(index: number, event: KeyboardEvent): void {
|
|
197
|
-
// `preventDefault` is called only on the keys handled here, so page scrolling and every
|
|
198
|
-
// shortcut this block has no business in behave exactly as they do anywhere else.
|
|
199
|
-
switch (event.key) {
|
|
200
|
-
case 'Enter':
|
|
201
|
-
case ' ':
|
|
202
|
-
event.preventDefault();
|
|
203
|
-
options.toggle(index);
|
|
204
|
-
return;
|
|
205
|
-
case 'Escape':
|
|
206
|
-
if (options.openIndex.value !== index) return;
|
|
207
|
-
event.preventDefault();
|
|
208
|
-
options.closeAndFocusTrigger(index);
|
|
209
|
-
return;
|
|
210
|
-
// ArrowDown / ArrowUp open the panel if it is closed and step straight into it, at the end
|
|
211
|
-
// the key points at — the APG's own "open and move focus into the disclosure" keys. `open()`
|
|
212
|
-
// runs either way, so a panel the pointer opened is the keyboard's from this point on.
|
|
213
|
-
case 'ArrowDown':
|
|
214
|
-
case 'ArrowUp': {
|
|
215
|
-
event.preventDefault();
|
|
216
|
-
options.open(index);
|
|
217
|
-
focusPanelEdge(index, event.key === 'ArrowDown' ? 'first' : 'last');
|
|
218
|
-
return;
|
|
219
|
-
}
|
|
220
|
-
default:
|
|
221
|
-
barTravel(index, event);
|
|
222
|
-
return;
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
/**
|
|
227
|
-
* The same left/right/Home/End travel along the bar, for a top-level item that is a plain link
|
|
228
|
-
* rather than a disclosure. Without it the arrow keys would be a one-way street: a visitor
|
|
229
|
-
* arrowing out of a mega-menu onto an ordinary link could not arrow any further, and the bar's
|
|
230
|
-
* row would read as navigable in one direction only. Down and up are *not* handled here — a plain
|
|
231
|
-
* link has no panel to open, so those keys stay the page's own scroll.
|
|
232
|
-
*/
|
|
233
|
-
function onBarLinkKeydown(index: number, event: KeyboardEvent): void {
|
|
234
|
-
barTravel(index, event);
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
function onPanelKeydown(index: number, event: KeyboardEvent): void {
|
|
238
|
-
switch (event.key) {
|
|
239
|
-
case 'Escape':
|
|
240
|
-
event.preventDefault();
|
|
241
|
-
options.closeAndFocusTrigger(index);
|
|
242
|
-
return;
|
|
243
|
-
// Down and up walk the panel's own reading order, clamped at its ends; Home and End jump to
|
|
244
|
-
// them. Tab still moves through the very same links, in the very same order.
|
|
245
|
-
case 'ArrowDown':
|
|
246
|
-
case 'ArrowUp': {
|
|
247
|
-
event.preventDefault();
|
|
248
|
-
const position = focusedPanelPosition(index);
|
|
249
|
-
if (position < 0) {
|
|
250
|
-
// Focus is inside the panel but not on one of its links. Enter at the end the key points
|
|
251
|
-
// at, exactly as entering from the trigger does, rather than clamping to the first row.
|
|
252
|
-
focusPanelEdge(index, event.key === 'ArrowDown' ? 'first' : 'last');
|
|
253
|
-
return;
|
|
254
|
-
}
|
|
255
|
-
focusPanelLink(index, position + (event.key === 'ArrowDown' ? 1 : -1));
|
|
256
|
-
return;
|
|
257
|
-
}
|
|
258
|
-
case 'Home':
|
|
259
|
-
event.preventDefault();
|
|
260
|
-
focusPanelEdge(index, 'first');
|
|
261
|
-
return;
|
|
262
|
-
case 'End':
|
|
263
|
-
event.preventDefault();
|
|
264
|
-
focusPanelEdge(index, 'last');
|
|
265
|
-
return;
|
|
266
|
-
// Left and right travel the bar from in here too, landing on the neighbouring item itself.
|
|
267
|
-
// Home and End never reach this: in a panel they belong to the panel, and the cases above
|
|
268
|
-
// have already taken them.
|
|
269
|
-
default:
|
|
270
|
-
barTravel(index, event);
|
|
271
|
-
return;
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
return { onTriggerKeydown, onPanelKeydown, onBarLinkKeydown };
|
|
276
|
-
}
|