@eldrajs/theme-cli 0.2.9 → 0.2.11
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/CHANGELOG.md +12 -1
- package/package.json +3 -3
- package/template/.eldra/block-types.d.ts +4 -6
- package/template/.eldra/manifest.json +228 -246
- package/template/.eldra/previews.json +35 -35
- package/template/.storybook/eldra.ts +7 -2
- package/template/app/assets/main.css +5 -0
- package/template/app/composables/useBlockData.ts +9 -2
- package/template/app/composables/usePriceTokens.ts +150 -0
- package/template/app/composables/useQuickAdd.ts +95 -0
- package/template/app/composables/useRegionalFormat.ts +94 -0
- package/template/app/icons.ts +4 -0
- package/template/app/plugins/eldra-storefront.ts +2 -0
- package/template/app/plugins/eldra-ui-messages.ts +22 -8
- package/template/app/storefront/demo.ts +188 -16
- package/template/app/storefront/gateway.ts +19 -0
- package/template/app/storefront/productCardLook.ts +76 -0
- package/template/app/storefront/productReference.ts +17 -0
- package/template/app/storefront/toProductCard.ts +12 -8
- package/template/app/storefront/types.ts +17 -0
- package/template/blocks/announcement-bar/__tests__/Block.spec.ts +19 -7
- package/template/blocks/announcement-bar/block.json +2 -1
- package/template/blocks/announcement-bar/mock.json +1 -1
- package/template/blocks/announcement-bar/preview.png +0 -0
- package/template/blocks/article/Block.vue +8 -18
- package/template/blocks/article/block.json +3 -1
- package/template/blocks/article/preview.png +0 -0
- package/template/blocks/article-list/block.json +10 -1
- package/template/blocks/article-list/preview.png +0 -0
- package/template/blocks/breadcrumbs/Block.vue +15 -3
- package/template/blocks/breadcrumbs/__tests__/Block.spec.ts +13 -0
- package/template/blocks/breadcrumbs/block.json +1 -0
- package/template/blocks/breadcrumbs/preview.png +0 -0
- package/template/blocks/cart/Block.vue +15 -5
- package/template/blocks/cart/__tests__/Block.spec.ts +53 -10
- package/template/blocks/cart/__tests__/ShippingBar.spec.ts +10 -8
- package/template/blocks/cart/block.json +8 -5
- package/template/blocks/cart/mock.json +2 -2
- package/template/blocks/cart/parts/ShippingBar.vue +24 -30
- package/template/blocks/cart/parts/notSold.ts +4 -3
- package/template/blocks/collection-grid/Block.vue +168 -85
- package/template/blocks/collection-grid/__tests__/Block.spec.ts +101 -23
- package/template/blocks/collection-grid/preview.png +0 -0
- package/template/blocks/collection-header/Block.vue +51 -17
- package/template/blocks/collection-header/__tests__/Block.spec.ts +80 -4
- package/template/blocks/collection-header/block.json +2 -0
- package/template/blocks/collection-header/preview.png +0 -0
- package/template/blocks/contact/block.json +4 -0
- package/template/blocks/contact/preview.png +0 -0
- package/template/blocks/cta/block.json +2 -0
- package/template/blocks/faq/Block.vue +5 -10
- package/template/blocks/faq/block.json +2 -1
- package/template/blocks/faq/mock.json +12 -1
- package/template/blocks/faq/preview.png +0 -0
- package/template/blocks/feature-grid/__tests__/Block.spec.ts +30 -7
- package/template/blocks/feature-grid/block.json +3 -2
- package/template/blocks/feature-grid/mock.json +1 -1
- package/template/blocks/feature-grid/preview.png +0 -0
- package/template/blocks/footer/Block.vue +64 -21
- package/template/blocks/footer/__tests__/Block.spec.ts +97 -1
- package/template/blocks/footer/block.json +5 -2
- package/template/blocks/footer/mock.json +1 -1
- package/template/blocks/footer/preview.png +0 -0
- package/template/blocks/form/block.json +1 -0
- package/template/blocks/gallery/preview.png +0 -0
- package/template/blocks/hero/Block.vue +38 -9
- package/template/blocks/hero/__tests__/Block.spec.ts +71 -19
- package/template/blocks/hero/block.json +16 -22
- package/template/blocks/hero/preview.json +1 -3
- package/template/blocks/hero/preview.png +0 -0
- package/template/blocks/image/block.json +2 -1
- package/template/blocks/image/preview.png +0 -0
- package/template/blocks/logo-cloud/block.json +1 -0
- package/template/blocks/logo-cloud/preview.png +0 -0
- package/template/blocks/navigation/Block.vue +405 -159
- package/template/blocks/navigation/__tests__/Block.spec.ts +816 -172
- package/template/blocks/navigation/__tests__/currentItem.spec.ts +90 -0
- package/template/blocks/navigation/block.json +2 -11
- package/template/blocks/navigation/mock.json +3 -3
- package/template/blocks/navigation/parts/LocalePicker.vue +103 -0
- package/template/blocks/navigation/parts/currentItem.ts +82 -0
- package/template/blocks/navigation/preview.json +7 -1
- package/template/blocks/navigation/preview.png +0 -0
- package/template/blocks/newsletter/Block.vue +6 -2
- package/template/blocks/newsletter/block.json +2 -0
- package/template/blocks/newsletter/preview.png +0 -0
- package/template/blocks/order-status/Block.vue +8 -17
- package/template/blocks/order-status/block.json +3 -0
- package/template/blocks/order-status/preview.png +0 -0
- package/template/blocks/pricing-table/__tests__/Block.spec.ts +12 -4
- package/template/blocks/pricing-table/block.json +2 -0
- package/template/blocks/pricing-table/mock.json +6 -6
- package/template/blocks/pricing-table/preview.png +0 -0
- package/template/blocks/product-carousel/Block.vue +36 -126
- package/template/blocks/product-carousel/__tests__/Block.spec.ts +88 -0
- package/template/blocks/product-carousel/block.json +1 -0
- package/template/blocks/product-carousel/preview.png +0 -0
- package/template/blocks/product-detail/Block.vue +84 -31
- package/template/blocks/product-detail/__tests__/Block.spec.ts +86 -0
- package/template/blocks/product-detail/__tests__/specs.spec.ts +79 -0
- package/template/blocks/product-detail/block.json +3 -1
- package/template/blocks/product-detail/mock.json +54 -4
- package/template/blocks/product-detail/parts/Gallery.vue +8 -2
- package/template/blocks/product-detail/preview.png +0 -0
- package/template/blocks/product-detail/specs.ts +75 -0
- package/template/blocks/quote/block.json +1 -0
- package/template/blocks/rich-text/preview.png +0 -0
- package/template/blocks/search/Block.vue +6 -1
- package/template/blocks/search/TypeSection.vue +8 -1
- package/template/blocks/search/__tests__/Block.spec.ts +24 -1
- package/template/blocks/search/block.json +1 -0
- package/template/blocks/search/preview.png +0 -0
- package/template/blocks/split-content/Block.vue +12 -5
- package/template/blocks/split-content/__tests__/Block.spec.ts +13 -0
- package/template/blocks/split-content/block.json +4 -2
- package/template/blocks/split-content/preview.png +0 -0
- package/template/blocks/stats/preview.png +0 -0
- package/template/blocks/tabs/Block.vue +3 -4
- package/template/blocks/tabs/block.json +1 -1
- package/template/blocks/tabs/preview.png +0 -0
- package/template/blocks/team/block.json +3 -1
- package/template/blocks/team/preview.png +0 -0
- package/template/blocks/testimonials/block.json +2 -0
- package/template/blocks/testimonials/preview.png +0 -0
- package/template/blocks/timeline/block.json +2 -1
- package/template/blocks/timeline/preview.png +0 -0
- package/template/blocks/trust-strip/Block.vue +2 -2
- package/template/blocks/trust-strip/__tests__/Block.spec.ts +38 -9
- package/template/blocks/trust-strip/block.json +1 -1
- package/template/blocks/trust-strip/mock.json +1 -1
- package/template/blocks/trust-strip/preview.json +1 -1
- package/template/blocks/trust-strip/preview.png +0 -0
- package/template/blocks/video-embed/block.json +2 -0
- package/template/blocks/video-embed/preview.png +0 -0
- package/template/blocks/wishlist/Block.vue +2 -2
- package/template/blocks/wishlist/preview.png +0 -0
- package/template/i18n/en-US.json +13 -5
- package/template/i18n/is-IS.json +12 -4
- package/template/pages/article.page.json +1 -3
- package/template/pages/cart.page.json +1 -3
- package/template/pages/category.page.json +2 -4
- package/template/pages/collection.page.json +1 -3
- package/template/pages/home.page.json +7 -18
- package/template/pages/product.page.json +62 -131
- package/template/pages/products.page.json +1 -3
- package/template/pages/search.page.json +1 -3
- package/template/pages/wishlist.page.json +1 -3
- package/template/stories/generated/footer.stories.ts +6 -0
- package/template/stories/generated/navigation.stories.ts +0 -18
- package/template/test/inlineEditable.spec.ts +10 -2
- package/template/test/localePrefix.spec.ts +2 -19
- package/template/test/pages/article.spec.ts +0 -2
- package/template/test/pages/category.spec.ts +35 -13
- package/template/test/pages/home.spec.ts +33 -17
- package/template/test/pages/product.spec.ts +64 -44
- package/template/test/pages/ssr.spec.ts +3 -1
- package/template/test/prerenderRefresh.browser.spec.ts +30 -25
- package/template/test/previewParity.browser.spec.ts +36 -2
- package/template/test/priceTokens.spec.ts +309 -0
- package/template/test/regionalFormat.spec.ts +80 -0
- package/template/test/starter.spec.ts +23 -7
- package/template/test/storefront/demo.spec.ts +19 -18
- package/template/test/storefront/toProductCard.spec.ts +17 -2
- package/template/test/structuredData.generate.spec.ts +4 -2
- package/template/test/support/mockGateway.ts +21 -1
- package/template/test/support/mountBlock.ts +25 -4
- package/template/test/support/priceTokens.ts +20 -0
- package/template/test/uiMessagesPlugin.spec.ts +34 -1
- package/template/tokens.json +8 -8
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { markCurrent, type CurrentEntry } from '../parts/currentItem';
|
|
3
|
+
|
|
4
|
+
const MENU: CurrentEntry[] = [
|
|
5
|
+
{
|
|
6
|
+
href: '/collections',
|
|
7
|
+
menu: ['/categories/home/knitwear', '/categories/home/ceramics', '/categories/home/kitchen'],
|
|
8
|
+
},
|
|
9
|
+
{ href: '/categories/home/ceramics', menu: [] },
|
|
10
|
+
{ href: '/journal', menu: ['/journal/linen', '/journal/boards'] },
|
|
11
|
+
{ href: '/about', menu: [] },
|
|
12
|
+
];
|
|
13
|
+
|
|
14
|
+
const HOME_CERAMICS = ['/categories/home', '/categories/home/ceramics'];
|
|
15
|
+
|
|
16
|
+
describe('markCurrent', () => {
|
|
17
|
+
it('marks only the entry for the product’s main category, not the menu that contains it', () => {
|
|
18
|
+
const marks = markCurrent(MENU, {
|
|
19
|
+
path: '/products/speckled-latte-mug',
|
|
20
|
+
trail: HOME_CERAMICS,
|
|
21
|
+
});
|
|
22
|
+
expect(marks).toEqual([undefined, 'true', undefined, undefined]);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it('marks the entry as the page itself on its own category page', () => {
|
|
26
|
+
const marks = markCurrent(MENU, {
|
|
27
|
+
path: '/categories/home/ceramics',
|
|
28
|
+
trail: HOME_CERAMICS,
|
|
29
|
+
});
|
|
30
|
+
expect(marks).toEqual([undefined, 'page', undefined, undefined]);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it('falls back to a menu that holds a category with no entry of its own', () => {
|
|
34
|
+
const marks = markCurrent(MENU, {
|
|
35
|
+
path: '/categories/home/knitwear',
|
|
36
|
+
trail: ['/categories/home', '/categories/home/knitwear'],
|
|
37
|
+
});
|
|
38
|
+
expect(marks).toEqual(['true', undefined, undefined, undefined]);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it('marks the Journal for the Journal and for a story in it', () => {
|
|
42
|
+
expect(markCurrent(MENU, { path: '/journal', trail: [] })).toEqual([
|
|
43
|
+
undefined,
|
|
44
|
+
undefined,
|
|
45
|
+
'page',
|
|
46
|
+
undefined,
|
|
47
|
+
]);
|
|
48
|
+
expect(markCurrent(MENU, { path: '/journal/linen', trail: [] })).toEqual([
|
|
49
|
+
undefined,
|
|
50
|
+
undefined,
|
|
51
|
+
'true',
|
|
52
|
+
undefined,
|
|
53
|
+
]);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('prefers the longest matching path, and an entry’s own link to a menu that merely holds it', () => {
|
|
57
|
+
const nested: CurrentEntry[] = [
|
|
58
|
+
{ href: '/shop', menu: [] },
|
|
59
|
+
{ href: '/shop/mugs', menu: [] },
|
|
60
|
+
];
|
|
61
|
+
expect(markCurrent(nested, { path: '/shop/mugs/tall', trail: [] })).toEqual([
|
|
62
|
+
undefined,
|
|
63
|
+
'true',
|
|
64
|
+
]);
|
|
65
|
+
const held: CurrentEntry[] = [
|
|
66
|
+
{ href: '/shop', menu: ['/shop/mugs'] },
|
|
67
|
+
{ href: '/shop/mugs', menu: [] },
|
|
68
|
+
];
|
|
69
|
+
expect(markCurrent(held, { path: '/shop/mugs', trail: [] })).toEqual([undefined, 'page']);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it('marks nothing when nothing matches, and never the home entry for every page', () => {
|
|
73
|
+
const entries: CurrentEntry[] = [{ href: '/', menu: [] }, ...MENU];
|
|
74
|
+
expect(markCurrent(entries, { path: '/nowhere', trail: [] })).toEqual([
|
|
75
|
+
undefined,
|
|
76
|
+
undefined,
|
|
77
|
+
undefined,
|
|
78
|
+
undefined,
|
|
79
|
+
undefined,
|
|
80
|
+
]);
|
|
81
|
+
expect(markCurrent(entries, { path: '/', trail: [] })[0]).toBe('page');
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it('never marks two entries', () => {
|
|
85
|
+
for (const path of ['/journal/linen', '/categories/home/ceramics', '/about', '/x']) {
|
|
86
|
+
const marks = markCurrent(MENU, { path, trail: HOME_CERAMICS });
|
|
87
|
+
expect(marks.filter((mark) => mark !== undefined).length).toBeLessThanOrEqual(1);
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
});
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"description": "The store's top bar: an optional info strip, brand, primary links with optional mega-menus, search, saved items, cart and one call to action.",
|
|
5
5
|
"icon": "layout-navbar",
|
|
6
6
|
"category": "structure",
|
|
7
|
-
"version":
|
|
7
|
+
"version": 6,
|
|
8
8
|
"groups": [
|
|
9
9
|
{
|
|
10
10
|
"groupId": "brand",
|
|
@@ -176,16 +176,6 @@
|
|
|
176
176
|
"default": true,
|
|
177
177
|
"helpText": "Opens Search (also on / and ⌘K / Ctrl+K)."
|
|
178
178
|
},
|
|
179
|
-
{
|
|
180
|
-
"fieldId": "searchStyle",
|
|
181
|
-
"name": "Search style",
|
|
182
|
-
"type": "select",
|
|
183
|
-
"groupId": "actions",
|
|
184
|
-
"metadata": {
|
|
185
|
-
"options": ["icon", "field", "inline"]
|
|
186
|
-
},
|
|
187
|
-
"helpText": "icon: a labelled Search button. field: a \"Search the shop\" pill from 80rem, the Search button below. inline: a live search bar in the bar, centered variant only, from 68.8rem only."
|
|
188
|
-
},
|
|
189
179
|
{
|
|
190
180
|
"fieldId": "ctaLabel",
|
|
191
181
|
"name": "Button label",
|
|
@@ -251,6 +241,7 @@
|
|
|
251
241
|
"fieldId": "href",
|
|
252
242
|
"name": "Link URL",
|
|
253
243
|
"type": "string",
|
|
244
|
+
"allowPrices": false,
|
|
254
245
|
"helpText": "Optional. A page path, a full URL or tel:/mailto:."
|
|
255
246
|
},
|
|
256
247
|
{
|
|
@@ -372,12 +372,12 @@
|
|
|
372
372
|
"_type": "collection",
|
|
373
373
|
"slug": "sale"
|
|
374
374
|
},
|
|
375
|
-
"label": "Sale"
|
|
375
|
+
"label": "Sale",
|
|
376
|
+
"tone": "accent"
|
|
376
377
|
}
|
|
377
378
|
],
|
|
378
379
|
"drawerLayout": "accordion",
|
|
379
380
|
"showSearch": true,
|
|
380
|
-
"searchStyle": "field",
|
|
381
381
|
"ctaLabel": "Shop gifts",
|
|
382
382
|
"cta": {
|
|
383
383
|
"kind": "collection",
|
|
@@ -390,7 +390,7 @@
|
|
|
390
390
|
"transparentOverHero": false,
|
|
391
391
|
"infoItems": [
|
|
392
392
|
{
|
|
393
|
-
"text": "Free delivery over
|
|
393
|
+
"text": "Free delivery over ⟦store freeShippingThreshold⟧",
|
|
394
394
|
"icon": "truck",
|
|
395
395
|
"placement": "start"
|
|
396
396
|
},
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
/**
|
|
3
|
+
* The header's language picker: the site's own locales, each named in its own language
|
|
4
|
+
* ("íslenska (Ísland)"), and the page's locale as its value. It sits beside the currency picker
|
|
5
|
+
* and is drawn the same way, so it takes the same `label`/`showLabel`/`size`/`placement`/`classes`
|
|
6
|
+
* and the same `label`, `leading`, `value` and `optionContent` slots as `CurrencyPicker`.
|
|
7
|
+
*
|
|
8
|
+
* It renders nothing unless the organisation serves more than one locale: `supported` is empty on
|
|
9
|
+
* a store that configures none and on every render outside a Nuxt site (a story, a unit mount), and
|
|
10
|
+
* a list of one is not a choice.
|
|
11
|
+
*
|
|
12
|
+
* Choosing is a navigation (`select`), never local state, so the value is always the page's own
|
|
13
|
+
* locale — the same rule as the footer's switcher. The names come from `useEldraLocale().name`,
|
|
14
|
+
* resolved once on the server, so a prerendered header does not hydrate into different words.
|
|
15
|
+
*/
|
|
16
|
+
import { computed } from 'vue';
|
|
17
|
+
import { FieldWrapper, Select } from '@eldrajs/ui';
|
|
18
|
+
import type { SelectOption, SelectPart, SelectPlacement } from '@eldrajs/ui';
|
|
19
|
+
import { useEldraLocale } from '@eldrajs/theme-vue';
|
|
20
|
+
|
|
21
|
+
const props = withDefaults(
|
|
22
|
+
defineProps<{
|
|
23
|
+
label: string;
|
|
24
|
+
showLabel?: boolean;
|
|
25
|
+
size?: 'sm' | 'md';
|
|
26
|
+
placement?: SelectPlacement;
|
|
27
|
+
classes?: Partial<Record<SelectPart | 'root' | 'label', string>>;
|
|
28
|
+
}>(),
|
|
29
|
+
{ showLabel: false, size: 'sm', placement: 'auto', classes: undefined }
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
const locales = useEldraLocale();
|
|
33
|
+
|
|
34
|
+
const options = computed<SelectOption[]>(() =>
|
|
35
|
+
locales.supported.map((tag) => ({ value: tag, label: locales.name(tag) }))
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
const selected = computed<string>({
|
|
39
|
+
get: () => locales.active ?? '',
|
|
40
|
+
set: (tag) => {
|
|
41
|
+
if (tag !== '' && tag !== locales.active) locales.select(tag);
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
/** The language subtag, for a closed picker that shows a short code: `is-IS` → `IS`. */
|
|
46
|
+
function shortCode(tag: string): string {
|
|
47
|
+
return (tag.split('-')[0] ?? tag).toUpperCase();
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const rootClass = computed(() => props.classes?.root);
|
|
51
|
+
const labelClasses = computed(() =>
|
|
52
|
+
props.showLabel ? { label: props.classes?.label } : { label: 'sr-only' }
|
|
53
|
+
);
|
|
54
|
+
const selectClasses = computed(() => {
|
|
55
|
+
const { root: _root, label: _label, ...rest } = props.classes ?? {};
|
|
56
|
+
return rest;
|
|
57
|
+
});
|
|
58
|
+
</script>
|
|
59
|
+
|
|
60
|
+
<template>
|
|
61
|
+
<FieldWrapper
|
|
62
|
+
v-if="options.length > 1"
|
|
63
|
+
data-eldra-header-locale-picker
|
|
64
|
+
:label="label"
|
|
65
|
+
:classes="labelClasses"
|
|
66
|
+
:class="rootClass"
|
|
67
|
+
>
|
|
68
|
+
<template v-if="$slots.label" #label><slot name="label" /></template>
|
|
69
|
+
<!-- Not `searchable`: a store has a handful of locales, and a search field over three options
|
|
70
|
+
is one more thing between a visitor and their language. An empty `placeholder`: the page
|
|
71
|
+
always has a locale, and `Select` reserves the placeholder's width under its value, which
|
|
72
|
+
would leave a gap after a two-letter "EN". -->
|
|
73
|
+
<Select
|
|
74
|
+
v-model="selected"
|
|
75
|
+
:options="options"
|
|
76
|
+
:placement="placement"
|
|
77
|
+
:searchable="false"
|
|
78
|
+
placeholder=""
|
|
79
|
+
:size="size"
|
|
80
|
+
:classes="selectClasses"
|
|
81
|
+
>
|
|
82
|
+
<template v-if="$slots.leading" #leading><slot name="leading" /></template>
|
|
83
|
+
<template v-if="$slots.optionContent" #optionContent="{ option, selected: chosen }">
|
|
84
|
+
<slot
|
|
85
|
+
name="optionContent"
|
|
86
|
+
:tag="option.value"
|
|
87
|
+
:code="shortCode(option.value)"
|
|
88
|
+
:label="option.label"
|
|
89
|
+
:selected="chosen"
|
|
90
|
+
/>
|
|
91
|
+
</template>
|
|
92
|
+
<template #value="{ option }">
|
|
93
|
+
<slot
|
|
94
|
+
name="value"
|
|
95
|
+
:tag="option.value"
|
|
96
|
+
:code="shortCode(option.value)"
|
|
97
|
+
:label="option.label"
|
|
98
|
+
>{{ shortCode(option.value) }}</slot
|
|
99
|
+
>
|
|
100
|
+
</template>
|
|
101
|
+
</Select>
|
|
102
|
+
</FieldWrapper>
|
|
103
|
+
</template>
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which one top-level entry of the header is "current".
|
|
3
|
+
*
|
|
4
|
+
* At most one is, by the product owner's rule: the entry for the page's MAIN category wins (a
|
|
5
|
+
* product's primary category, or the category the page is), then the single best match for the
|
|
6
|
+
* page's path, else none. `NavMenu` draws the result as `aria-current="page"` when the entry is the
|
|
7
|
+
* page itself, `"true"` when it only holds it (an ancestor, or a menu that contains the page).
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
export interface CurrentEntry {
|
|
11
|
+
/** The entry's own destination, when it has one. */
|
|
12
|
+
href: string | null | undefined;
|
|
13
|
+
/** The destinations in its panel. */
|
|
14
|
+
menu: readonly (string | null | undefined)[];
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface CurrentContext {
|
|
18
|
+
/** The page's own path. */
|
|
19
|
+
path: string;
|
|
20
|
+
/** The page's main category and its ancestors, root first (a product's primary category's trail). */
|
|
21
|
+
trail: readonly string[];
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export type CurrentMark = 'page' | 'true' | undefined;
|
|
25
|
+
|
|
26
|
+
function normalise(href: string | null | undefined): string | null {
|
|
27
|
+
if (typeof href !== 'string' || href === '') return null;
|
|
28
|
+
const bare = href.split(/[?#]/)[0] ?? '';
|
|
29
|
+
if (!bare.startsWith('/')) return null;
|
|
30
|
+
return bare.length > 1 ? bare.replace(/\/+$/, '') : bare;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** The length of the match: the whole path when equal, the entry's when it is an ancestor path; 0 for none. */
|
|
34
|
+
function matchLength(href: string | null | undefined, target: string): number {
|
|
35
|
+
const own = normalise(href);
|
|
36
|
+
if (own === null) return 0;
|
|
37
|
+
if (own === target) return own.length;
|
|
38
|
+
return own !== '/' && target.startsWith(`${own}/`) ? own.length : 0;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function markCurrent(
|
|
42
|
+
entries: readonly CurrentEntry[],
|
|
43
|
+
context: CurrentContext
|
|
44
|
+
): CurrentMark[] {
|
|
45
|
+
const marks: CurrentMark[] = entries.map(() => undefined);
|
|
46
|
+
const path = normalise(context.path) ?? '';
|
|
47
|
+
const specific = context.trail
|
|
48
|
+
.map(normalise)
|
|
49
|
+
.filter((href): href is string => href !== null)
|
|
50
|
+
.reverse();
|
|
51
|
+
|
|
52
|
+
// 1. The entry that links to the main category, else to its nearest ancestor that has an entry.
|
|
53
|
+
for (const target of specific) {
|
|
54
|
+
const at = entries.findIndex((entry) => normalise(entry.href) === target);
|
|
55
|
+
if (at !== -1) {
|
|
56
|
+
marks[at] = target === path ? 'page' : 'true';
|
|
57
|
+
return marks;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// 2. The most specific entry whose link or menu holds the page (or, failing that, its category):
|
|
62
|
+
// the longest matching path wins, and an entry's own link beats a menu at the same length.
|
|
63
|
+
for (const target of [path, ...specific]) {
|
|
64
|
+
if (target === '') continue;
|
|
65
|
+
let best = -1;
|
|
66
|
+
let bestScore = 0;
|
|
67
|
+
entries.forEach((entry, at) => {
|
|
68
|
+
const own = matchLength(entry.href, target);
|
|
69
|
+
const menu = Math.max(0, ...entry.menu.map((href) => matchLength(href, target)));
|
|
70
|
+
const score = Math.max(own * 2 + (own > 0 ? 1 : 0), menu * 2);
|
|
71
|
+
if (score > bestScore) {
|
|
72
|
+
best = at;
|
|
73
|
+
bestScore = score;
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
if (best !== -1) {
|
|
77
|
+
marks[best] = normalise(entries[best]!.href) === target && target === path ? 'page' : 'true';
|
|
78
|
+
return marks;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return marks;
|
|
82
|
+
}
|
|
@@ -303,9 +303,15 @@
|
|
|
303
303
|
{
|
|
304
304
|
"kind": "url",
|
|
305
305
|
"url": "/collections/the-winter-edit",
|
|
306
|
-
"label": "Sale"
|
|
306
|
+
"label": "Sale",
|
|
307
|
+
"tone": "accent"
|
|
307
308
|
}
|
|
308
309
|
],
|
|
310
|
+
"account": {
|
|
311
|
+
"kind": "url",
|
|
312
|
+
"url": "/pages/account",
|
|
313
|
+
"label": "Account"
|
|
314
|
+
},
|
|
309
315
|
"ctaLabel": null,
|
|
310
316
|
"cta": null
|
|
311
317
|
}
|
|
Binary file
|
|
@@ -250,6 +250,10 @@ const submitWidthClass = computed(() =>
|
|
|
250
250
|
isSplit.value ? '@min-[24rem]:w-auto w-full' : '@two-col:w-auto w-full'
|
|
251
251
|
);
|
|
252
252
|
|
|
253
|
+
/** The band's field and button are the standard 2.75rem control (the design's `.nw-nl`), a step
|
|
254
|
+
* below the centred variant's large ones, which stand alone under their heading. */
|
|
255
|
+
const controlSize = computed<'md' | 'lg'>(() => (isSplit.value ? 'md' : 'lg'));
|
|
256
|
+
|
|
253
257
|
/* ---------------------------------------------------------------------- */
|
|
254
258
|
/* Form state */
|
|
255
259
|
/* ---------------------------------------------------------------------- */
|
|
@@ -450,7 +454,7 @@ async function onSubmit(payload: FormLayoutSubmitPayload): Promise<void> {
|
|
|
450
454
|
type="email"
|
|
451
455
|
name="email"
|
|
452
456
|
autocomplete="email"
|
|
453
|
-
size="
|
|
457
|
+
:size="controlSize"
|
|
454
458
|
:placeholder="placeholderText"
|
|
455
459
|
/>
|
|
456
460
|
</FieldWrapper>
|
|
@@ -493,7 +497,7 @@ async function onSubmit(payload: FormLayoutSubmitPayload): Promise<void> {
|
|
|
493
497
|
<Button
|
|
494
498
|
type="submit"
|
|
495
499
|
variant="primary"
|
|
496
|
-
size="
|
|
500
|
+
:size="controlSize"
|
|
497
501
|
:class="submitWidthClass"
|
|
498
502
|
:label="t('newsletter.subscribing')"
|
|
499
503
|
:aria-describedby="consentSentence ? consentSentenceId : undefined"
|
|
@@ -91,6 +91,7 @@
|
|
|
91
91
|
"fieldId": "formKey",
|
|
92
92
|
"name": "Form",
|
|
93
93
|
"type": "string",
|
|
94
|
+
"allowPrices": false,
|
|
94
95
|
"helpText": "The key of the sign-up form on the Forms page. Defaults to \"newsletter\" when unset."
|
|
95
96
|
},
|
|
96
97
|
{
|
|
@@ -138,6 +139,7 @@
|
|
|
138
139
|
"fieldId": "href",
|
|
139
140
|
"name": "Link",
|
|
140
141
|
"type": "string",
|
|
142
|
+
"allowPrices": false,
|
|
141
143
|
"helpText": "tel:, mailto: or a page. Optional."
|
|
142
144
|
},
|
|
143
145
|
{
|
|
Binary file
|
|
@@ -95,11 +95,10 @@ import {
|
|
|
95
95
|
Section,
|
|
96
96
|
Skeleton,
|
|
97
97
|
VisuallyHidden,
|
|
98
|
-
formatDate,
|
|
99
98
|
type BadgeTone,
|
|
100
99
|
} from '@eldrajs/ui';
|
|
101
|
-
import { useEldra } from '@eldrajs/theme-vue';
|
|
102
100
|
import { useBlockData } from '../../app/composables/useBlockData';
|
|
101
|
+
import { useFormatDate } from '../../app/composables/useRegionalFormat';
|
|
103
102
|
import { useEditing } from '../../app/composables/useEditing';
|
|
104
103
|
import { iconComponent } from '../../app/composables/iconComponent';
|
|
105
104
|
import { useStorefront } from '../../app/composables/useStorefront';
|
|
@@ -128,15 +127,9 @@ const titleId = `order-status-title-${useUiId()}`;
|
|
|
128
127
|
/** Order money is major units (`app/storefront/types.ts`); `<Price>` reads minor. */
|
|
129
128
|
const money = useMoney();
|
|
130
129
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
} catch {
|
|
135
|
-
return undefined;
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
/** See `article`'s identical helper: `formatDate` needs the raw locale string, not a translation. */
|
|
139
|
-
const locale = computed(() => tryUseEldra()?.preview.locale ?? 'en-US');
|
|
130
|
+
/** `@eldrajs/ui`'s `formatDate` in the organisation's regional format and time zone — not the
|
|
131
|
+
* content locale: an Icelandic store's English page still prints an Icelandic date. */
|
|
132
|
+
const formatRegionalDate = useFormatDate();
|
|
140
133
|
|
|
141
134
|
function interpolate(template: string, params: Record<string, string>): string {
|
|
142
135
|
return template.replace(/\{(\w+)\}/g, (match, key: string) =>
|
|
@@ -187,9 +180,7 @@ const CheckIcon = iconComponent('check');
|
|
|
187
180
|
/* Head: order number, placed line, status badge */
|
|
188
181
|
/* ------------------------------------------------------------------------------------------- */
|
|
189
182
|
|
|
190
|
-
const placedDate = computed(() =>
|
|
191
|
-
order.value ? formatDate(order.value.placedAt, locale.value) : null
|
|
192
|
-
);
|
|
183
|
+
const placedDate = computed(() => (order.value ? formatRegionalDate(order.value.placedAt) : null));
|
|
193
184
|
const placedLine = computed(() => {
|
|
194
185
|
if (!order.value || placedDate.value === null) return '';
|
|
195
186
|
return order.value.itemCount === 1
|
|
@@ -252,7 +243,7 @@ const panelTitle = computed(() => {
|
|
|
252
243
|
if (o.status === 'delayed') return data.value.delayedTitle;
|
|
253
244
|
if (o.status === 'cancelled') return data.value.cancelledTitle;
|
|
254
245
|
const deliveredDate = o.steps.find((step) => step.key === 'delivered')?.date;
|
|
255
|
-
const formatted = deliveredDate ?
|
|
246
|
+
const formatted = deliveredDate ? formatRegionalDate(deliveredDate) : null;
|
|
256
247
|
return interpolate(data.value.deliveredTitle, { date: formatted ?? '' });
|
|
257
248
|
});
|
|
258
249
|
|
|
@@ -343,10 +334,10 @@ const steps = computed<StepView[]>(() => {
|
|
|
343
334
|
const isCurrent = step.state === 'current';
|
|
344
335
|
let dateText = '';
|
|
345
336
|
if (isWarning) {
|
|
346
|
-
const formatted = step.date ?
|
|
337
|
+
const formatted = step.date ? formatRegionalDate(step.date) : null;
|
|
347
338
|
if (formatted) dateText = t('order.estimated', { date: formatted });
|
|
348
339
|
} else if (step.date) {
|
|
349
|
-
dateText =
|
|
340
|
+
dateText = formatRegionalDate(step.date) ?? '';
|
|
350
341
|
} else if (isCurrent) {
|
|
351
342
|
dateText = t('order.inProgress');
|
|
352
343
|
}
|
|
@@ -80,6 +80,7 @@
|
|
|
80
80
|
"fieldId": "returnLinkHref",
|
|
81
81
|
"name": "Return link URL",
|
|
82
82
|
"type": "string",
|
|
83
|
+
"allowPrices": false,
|
|
83
84
|
"default": "/pages/returns"
|
|
84
85
|
},
|
|
85
86
|
{
|
|
@@ -94,6 +95,7 @@
|
|
|
94
95
|
"fieldId": "shopAgainLinkHref",
|
|
95
96
|
"name": "Shop again link URL",
|
|
96
97
|
"type": "string",
|
|
98
|
+
"allowPrices": false,
|
|
97
99
|
"default": "/collections/all"
|
|
98
100
|
},
|
|
99
101
|
{
|
|
@@ -119,6 +121,7 @@
|
|
|
119
121
|
"fieldId": "href",
|
|
120
122
|
"name": "Link URL",
|
|
121
123
|
"type": "string",
|
|
124
|
+
"allowPrices": false,
|
|
122
125
|
"validators": { "required": true }
|
|
123
126
|
},
|
|
124
127
|
{
|
|
Binary file
|
|
@@ -7,6 +7,7 @@ import { axe } from '../../../test/support/axe';
|
|
|
7
7
|
import Block from '../Block.vue';
|
|
8
8
|
import mock from '../mock.json';
|
|
9
9
|
import { mountOptions } from '../../../test/support/mountBlock';
|
|
10
|
+
import { shown } from '../../../test/support/priceTokens';
|
|
10
11
|
|
|
11
12
|
/** No media fields, so — like `stats` — there is no `preview.json` to merge onto `mock.json`.
|
|
12
13
|
* `mock.json` is the block's one full content fixture; `bare` below is the genuinely minimal one,
|
|
@@ -36,7 +37,10 @@ const DEMO_CTA_HREFS = [
|
|
|
36
37
|
];
|
|
37
38
|
const mockWithCta = {
|
|
38
39
|
...mock,
|
|
39
|
-
plans: mock.plans.map((plan, index) => ({
|
|
40
|
+
plans: mock.plans.map((plan, index) => ({
|
|
41
|
+
...plan,
|
|
42
|
+
ctaHref: DEMO_CTA_HREFS[index],
|
|
43
|
+
})),
|
|
40
44
|
};
|
|
41
45
|
|
|
42
46
|
function mountBlock(data: Record<string, unknown>, options: { editing?: boolean } = {}) {
|
|
@@ -70,10 +74,10 @@ describe('pricing-table block', () => {
|
|
|
70
74
|
await flush();
|
|
71
75
|
expect(wrapper.text()).toContain(mock.heading);
|
|
72
76
|
expect(wrapper.text()).toContain(mock.intro);
|
|
73
|
-
expect(wrapper.text()).toContain(mock.footnote);
|
|
77
|
+
expect(wrapper.text()).toContain(shown(mock.footnote));
|
|
74
78
|
for (const plan of mock.plans) {
|
|
75
79
|
expect(wrapper.text()).toContain(plan.name);
|
|
76
|
-
expect(wrapper.text()).toContain(plan.price);
|
|
80
|
+
expect(wrapper.text()).toContain(shown(plan.price));
|
|
77
81
|
expect(wrapper.text()).toContain(plan.ctaLabel);
|
|
78
82
|
}
|
|
79
83
|
expect(await axe(wrapper.element)).toHaveNoViolations();
|
|
@@ -302,7 +306,11 @@ describe('pricing-table block', () => {
|
|
|
302
306
|
.element as HTMLAnchorElement;
|
|
303
307
|
link.focus();
|
|
304
308
|
expect(document.activeElement).toBe(link);
|
|
305
|
-
const enter = new KeyboardEvent('keydown', {
|
|
309
|
+
const enter = new KeyboardEvent('keydown', {
|
|
310
|
+
key: 'Enter',
|
|
311
|
+
bubbles: true,
|
|
312
|
+
cancelable: true,
|
|
313
|
+
});
|
|
306
314
|
link.dispatchEvent(enter);
|
|
307
315
|
expect(enter.defaultPrevented).toBe(false);
|
|
308
316
|
wrapper.unmount();
|
|
@@ -107,6 +107,7 @@
|
|
|
107
107
|
"fieldId": "ctaHref",
|
|
108
108
|
"name": "Button link",
|
|
109
109
|
"type": "string",
|
|
110
|
+
"allowPrices": false,
|
|
110
111
|
"helpText": "Selling plan or cart permalink.",
|
|
111
112
|
"validators": { "required": true }
|
|
112
113
|
},
|
|
@@ -128,6 +129,7 @@
|
|
|
128
129
|
"fieldId": "highlightedPlan",
|
|
129
130
|
"name": "Highlighted plan",
|
|
130
131
|
"type": "string",
|
|
132
|
+
"allowPrices": false,
|
|
131
133
|
"helpText": "Must match a plan name exactly; leave empty for no highlight."
|
|
132
134
|
},
|
|
133
135
|
{
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
{
|
|
13
13
|
"name": "Monthly",
|
|
14
14
|
"description": "Coffee, preserves and one small kitchen piece, delivered on the first Friday.",
|
|
15
|
-
"price": "
|
|
15
|
+
"price": "⟦price#month EUR=3500 ISK=5400 USD=3800⟧",
|
|
16
16
|
"period": "/ month",
|
|
17
17
|
"note": "Billed monthly. Skip or cancel any time.",
|
|
18
18
|
"ctaLabel": "Start monthly",
|
|
@@ -22,9 +22,9 @@
|
|
|
22
22
|
{
|
|
23
23
|
"name": "Seasonal",
|
|
24
24
|
"description": "Three boxes a season, timed to what our makers are harvesting and firing.",
|
|
25
|
-
"price": "
|
|
25
|
+
"price": "⟦price#season EUR=9600 ISK=15000 USD=10500⟧",
|
|
26
26
|
"period": "/ 3 months",
|
|
27
|
-
"note": "
|
|
27
|
+
"note": "⟦price#sbox EUR=3200 ISK=5000 USD=3500⟧ a box, billed each season.",
|
|
28
28
|
"ctaLabel": "Start seasonal",
|
|
29
29
|
"ctaHref": "",
|
|
30
30
|
"included": [true, true, true, true, false]
|
|
@@ -32,9 +32,9 @@
|
|
|
32
32
|
{
|
|
33
33
|
"name": "Annual",
|
|
34
34
|
"description": "Twelve boxes and a thank-you from the workshop at the start of winter.",
|
|
35
|
-
"price": "
|
|
35
|
+
"price": "⟦price#year EUR=36000 ISK=55000 USD=39600⟧",
|
|
36
36
|
"period": "/ year",
|
|
37
|
-
"note": "
|
|
37
|
+
"note": "⟦price#ybox EUR=3000 ISK=4600 USD=3300⟧ a box, billed once a year.",
|
|
38
38
|
"ctaLabel": "Start annual",
|
|
39
39
|
"ctaHref": "",
|
|
40
40
|
"included": [true, true, true, true, true]
|
|
@@ -42,6 +42,6 @@
|
|
|
42
42
|
],
|
|
43
43
|
"highlightedPlan": "Seasonal",
|
|
44
44
|
"highlightLabel": "Most popular",
|
|
45
|
-
"footnote": "Prices include tax. Delivery to Canada and the EU is
|
|
45
|
+
"footnote": "Prices include tax. Delivery to Canada and the EU is ⟦price#intl EUR=600 ISK=900 USD=600⟧ a box.",
|
|
46
46
|
"sectionBackground": "none"
|
|
47
47
|
}
|
|
Binary file
|