@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
|
@@ -29,7 +29,11 @@ import {
|
|
|
29
29
|
} from '@eldrajs/theme-vue';
|
|
30
30
|
import { CURRENCY_KEY, LOCALE_KEY, MESSAGES_KEY, enUS as uiEnUS } from '@eldrajs/ui';
|
|
31
31
|
import { isIS as uiIsIS } from '@eldrajs/ui/messages/is-IS';
|
|
32
|
-
import {
|
|
32
|
+
import type { StoreRegion } from '@eldrajs/theme-nuxt/region';
|
|
33
|
+
import { REGION_KEY, regionalFormatLocale } from '../../app/composables/useRegionalFormat';
|
|
34
|
+
import { createDemoStorefront, DEMO_STORE_AMOUNTS } from '../../app/storefront/demo';
|
|
35
|
+
import { STORE_AMOUNTS_KEY } from '../../app/composables/usePriceTokens';
|
|
36
|
+
import type { StoreAmounts } from '@eldrajs/sdk/tokens';
|
|
33
37
|
import { STOREFRONT_KEY, type StorefrontCommerce } from '../../app/storefront/types';
|
|
34
38
|
import enUSMessages from '../../i18n/en-US.json';
|
|
35
39
|
import isISMessages from '../../i18n/is-IS.json';
|
|
@@ -82,6 +86,15 @@ export function mountOptions(
|
|
|
82
86
|
* same way the two plugins take both from one runtime-config read on a real page.
|
|
83
87
|
*/
|
|
84
88
|
commerce?: StorefrontCommerce | null;
|
|
89
|
+
/**
|
|
90
|
+
* The organisation's regional format, for a spec about how numbers and dates are written:
|
|
91
|
+
* none by default (the content locale formats), as on a site whose build learned none. Wired
|
|
92
|
+
* the way `app/plugins/eldra-ui-messages.ts` wires it: `LOCALE_KEY` and `REGION_KEY`.
|
|
93
|
+
*/
|
|
94
|
+
region?: StoreRegion | null;
|
|
95
|
+
/** The store's amounts for `⟦store …⟧` price tokens; the demo store's by default, `null` for a
|
|
96
|
+
* store whose thresholds could not be read. */
|
|
97
|
+
storeAmounts?: StoreAmounts | null;
|
|
85
98
|
} = {}
|
|
86
99
|
): {
|
|
87
100
|
props: { entry: { id: string; data: Record<string, unknown> } };
|
|
@@ -118,8 +131,11 @@ export function mountOptions(
|
|
|
118
131
|
// platform's answer there, the demo source's own here — never from the
|
|
119
132
|
// locale.
|
|
120
133
|
[MESSAGES_KEY]: uiMessagesFor(effectiveLocale),
|
|
121
|
-
[LOCALE_KEY]: effectiveLocale,
|
|
134
|
+
[LOCALE_KEY]: regionalFormatLocale(options.region ?? null, effectiveLocale),
|
|
135
|
+
[REGION_KEY]: options.region ?? null,
|
|
122
136
|
[CURRENCY_KEY]: storefront.commerce?.currency,
|
|
137
|
+
[STORE_AMOUNTS_KEY]:
|
|
138
|
+
options.storeAmounts === undefined ? DEMO_STORE_AMOUNTS : options.storeAmounts,
|
|
123
139
|
// The same wiring `app/plugins/eldra-storefront.ts` does on a real page: a commerce block
|
|
124
140
|
// reads `useStorefront()`, never the client directly, so every block test sees the
|
|
125
141
|
// Northwind demo catalogue (`app/storefront/demo.ts`) instead of a live gateway.
|
|
@@ -169,7 +185,10 @@ function createTestEldraContext(
|
|
|
169
185
|
}
|
|
170
186
|
|
|
171
187
|
function createTestEldraClient(): EldraClient {
|
|
172
|
-
return createEldraClient({
|
|
188
|
+
return createEldraClient({
|
|
189
|
+
gatewayUrl: 'https://vitest.invalid',
|
|
190
|
+
orgId: 'vitest',
|
|
191
|
+
});
|
|
173
192
|
}
|
|
174
193
|
|
|
175
194
|
/**
|
|
@@ -187,7 +206,9 @@ const NuxtLinkStub = defineComponent({
|
|
|
187
206
|
return () =>
|
|
188
207
|
h(
|
|
189
208
|
'a',
|
|
190
|
-
{
|
|
209
|
+
{
|
|
210
|
+
href: typeof props.to === 'string' ? props.to : JSON.stringify(props.to),
|
|
211
|
+
},
|
|
191
212
|
slots.default?.()
|
|
192
213
|
);
|
|
193
214
|
},
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { resolveBlockTokens } from '../../app/composables/usePriceTokens';
|
|
2
|
+
import { DEMO_STORE_AMOUNTS } from '../../app/storefront/demo';
|
|
3
|
+
import { formatMoney } from '../../app/storefront/money';
|
|
4
|
+
|
|
5
|
+
/** How `mountOptions` resolves price tokens: the demo store's dollars and thresholds. */
|
|
6
|
+
export const DEMO_PRICE_OPTIONS = {
|
|
7
|
+
currency: 'USD',
|
|
8
|
+
locale: 'en-US',
|
|
9
|
+
storeAmounts: DEMO_STORE_AMOUNTS,
|
|
10
|
+
format: formatMoney,
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* A seed value as a block mounted by `mountOptions` shows it: every price token written out in the
|
|
15
|
+
* demo store's currency (`useBlockData`). A spec comparing page text with `mock.json` compares with
|
|
16
|
+
* this, since a seed's `⟦store freeShippingThreshold⟧` reads "$80.00" on the page.
|
|
17
|
+
*/
|
|
18
|
+
export function shown<T>(value: T): T {
|
|
19
|
+
return resolveBlockTokens(value, DEMO_PRICE_OPTIONS);
|
|
20
|
+
}
|
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import { afterEach, describe, expect, it, vi } from 'vitest';
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
CURRENCY_KEY,
|
|
4
|
+
LOCALE_KEY,
|
|
5
|
+
MESSAGES_KEY,
|
|
6
|
+
enUS as uiEnUS,
|
|
7
|
+
type UiMessages,
|
|
8
|
+
} from '@eldrajs/ui';
|
|
9
|
+
import { REGION_KEY } from '../app/composables/useRegionalFormat';
|
|
3
10
|
|
|
4
11
|
/**
|
|
5
12
|
* `app/plugins/eldra-ui-messages.ts` is the one place the store's currency reaches `@eldrajs/ui` —
|
|
@@ -20,6 +27,8 @@ vi.mock('nuxt/app', () => ({
|
|
|
20
27
|
|
|
21
28
|
const { default: plugin } = await import('../app/plugins/eldra-ui-messages');
|
|
22
29
|
|
|
30
|
+
const ICELAND = { countryCode: 'IS', formatLocale: 'is-IS', timeZone: 'Atlantic/Reykjavik' };
|
|
31
|
+
|
|
23
32
|
const ISK = { currency: 'ISK', taxInclusivePricing: true, defaultTaxRate: 0.24 };
|
|
24
33
|
|
|
25
34
|
/** Runs the plugin against one `runtimeConfig.public`, and reports what it provided. */
|
|
@@ -101,4 +110,28 @@ describe('eldra-ui-messages', () => {
|
|
|
101
110
|
|
|
102
111
|
expect(eldraWarnings(warn)).toEqual([]);
|
|
103
112
|
});
|
|
113
|
+
|
|
114
|
+
it('formats in the organisation’s regional format, while its strings stay on the content locale', () => {
|
|
115
|
+
const provided = provideWith({ commerce: ISK, region: ICELAND });
|
|
116
|
+
|
|
117
|
+
expect((provided.get(LOCALE_KEY) as () => string | undefined)()).toBe('is-IS');
|
|
118
|
+
expect(provided.get(REGION_KEY)).toEqual(ICELAND);
|
|
119
|
+
// No content locale here (no theme context), so the strings are the English defaults — the
|
|
120
|
+
// regional format must not have pulled them to Icelandic.
|
|
121
|
+
const messages = provided.get(MESSAGES_KEY) as UiMessages;
|
|
122
|
+
const plainKey = (Object.keys(uiEnUS) as (keyof UiMessages)[]).find(
|
|
123
|
+
(key) => typeof uiEnUS[key] === 'string'
|
|
124
|
+
)!;
|
|
125
|
+
expect(messages[plainKey]).toBe(uiEnUS[plainKey]);
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
it('falls back to the content locale when the build learned no regional format', () => {
|
|
129
|
+
// Absent, the `''` Nuxt serialises a null as, and a record `Intl` would throw on all read the
|
|
130
|
+
// same: no regional format, so `LOCALE_KEY` answers the content locale (none here).
|
|
131
|
+
for (const region of [undefined, null, '', { ...ICELAND, timeZone: 'Mars/Olympus_Mons' }]) {
|
|
132
|
+
const provided = provideWith({ commerce: ISK, region });
|
|
133
|
+
expect((provided.get(LOCALE_KEY) as () => string | undefined)()).toBeUndefined();
|
|
134
|
+
expect(provided.get(REGION_KEY)).toBeNull();
|
|
135
|
+
}
|
|
136
|
+
});
|
|
104
137
|
});
|
package/template/tokens.json
CHANGED
|
@@ -108,8 +108,8 @@
|
|
|
108
108
|
"label": "Narrow",
|
|
109
109
|
"maxWidth": "40rem",
|
|
110
110
|
"gutter": {
|
|
111
|
-
"normal": "
|
|
112
|
-
"tablet": "
|
|
111
|
+
"normal": "1rem",
|
|
112
|
+
"tablet": "1rem",
|
|
113
113
|
"mobile": "1rem"
|
|
114
114
|
},
|
|
115
115
|
"allowSiteOverride": true
|
|
@@ -118,8 +118,8 @@
|
|
|
118
118
|
"label": "Content",
|
|
119
119
|
"maxWidth": "64rem",
|
|
120
120
|
"gutter": {
|
|
121
|
-
"normal": "
|
|
122
|
-
"tablet": "
|
|
121
|
+
"normal": "1rem",
|
|
122
|
+
"tablet": "1rem",
|
|
123
123
|
"mobile": "1rem"
|
|
124
124
|
},
|
|
125
125
|
"allowSiteOverride": true
|
|
@@ -128,8 +128,8 @@
|
|
|
128
128
|
"label": "Wide",
|
|
129
129
|
"maxWidth": "78rem",
|
|
130
130
|
"gutter": {
|
|
131
|
-
"normal": "
|
|
132
|
-
"tablet": "
|
|
131
|
+
"normal": "1rem",
|
|
132
|
+
"tablet": "1rem",
|
|
133
133
|
"mobile": "1rem"
|
|
134
134
|
},
|
|
135
135
|
"allowSiteOverride": true
|
|
@@ -138,8 +138,8 @@
|
|
|
138
138
|
"label": "Full",
|
|
139
139
|
"maxWidth": "none",
|
|
140
140
|
"gutter": {
|
|
141
|
-
"normal": "
|
|
142
|
-
"tablet": "
|
|
141
|
+
"normal": "1rem",
|
|
142
|
+
"tablet": "1rem",
|
|
143
143
|
"mobile": "1rem"
|
|
144
144
|
},
|
|
145
145
|
"allowSiteOverride": true
|