@eldrajs/theme-cli 0.2.10 → 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 +11 -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 +34 -11
- package/template/blocks/collection-header/__tests__/Block.spec.ts +3 -3
- 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 +404 -159
- package/template/blocks/navigation/__tests__/Block.spec.ts +806 -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/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
|
@@ -1,37 +1,37 @@
|
|
|
1
1
|
{
|
|
2
|
-
"announcement-bar": "
|
|
3
|
-
"article": "
|
|
4
|
-
"article-list": "
|
|
5
|
-
"breadcrumbs": "
|
|
6
|
-
"cart": "
|
|
7
|
-
"collection-grid": "
|
|
8
|
-
"collection-header": "
|
|
9
|
-
"contact": "
|
|
10
|
-
"cta": "
|
|
11
|
-
"faq": "
|
|
12
|
-
"feature-grid": "
|
|
13
|
-
"footer": "
|
|
14
|
-
"form": "
|
|
15
|
-
"gallery": "
|
|
16
|
-
"hero": "
|
|
17
|
-
"image": "
|
|
18
|
-
"logo-cloud": "
|
|
19
|
-
"navigation": "
|
|
20
|
-
"newsletter": "
|
|
21
|
-
"order-status": "
|
|
22
|
-
"pricing-table": "
|
|
23
|
-
"product-carousel": "
|
|
24
|
-
"product-detail": "
|
|
25
|
-
"quote": "
|
|
26
|
-
"rich-text": "
|
|
27
|
-
"search": "
|
|
28
|
-
"split-content": "
|
|
29
|
-
"stats": "
|
|
30
|
-
"tabs": "
|
|
31
|
-
"team": "
|
|
32
|
-
"testimonials": "
|
|
33
|
-
"timeline": "
|
|
34
|
-
"trust-strip": "
|
|
35
|
-
"video-embed": "
|
|
36
|
-
"wishlist": "
|
|
2
|
+
"announcement-bar": "2c0ef9db5dab75165ee6bea1fdbac720c959abb45da9b7057bbc2866f5a165ee",
|
|
3
|
+
"article": "8d1d3c85642cf3910b3dbb660e268e6ae59a9acf67de7c8565cbd842c1b618aa",
|
|
4
|
+
"article-list": "b9699500b43e2f1e5ba0a2d8a0c25bd0d4c85dbf792d131ccc1cde51ccc50c6a",
|
|
5
|
+
"breadcrumbs": "b3d320fec4f5bd50fe10c009bcb4fedb2b19b641f3c130aea6bcdffe13c9449f",
|
|
6
|
+
"cart": "946bab5b15d6a132cda56867149d10099129b5d46d8297f192627939d2bb95b9",
|
|
7
|
+
"collection-grid": "0bc38d87a39fb7dab9a5e9396147d159b3921d7fb6b89de0937575106efeb922",
|
|
8
|
+
"collection-header": "25984c9c4b01925527ff30ffa01faf1934b6fad886663f726f3389a6dc4a7335",
|
|
9
|
+
"contact": "9cfc3b751b4ba94fcbe3b222f4f54aa5cf7b37d73f03aa7b036be05719f12cd4",
|
|
10
|
+
"cta": "02db69b901146652b815383602d674979084411353db6f741dcde9bed3be6803",
|
|
11
|
+
"faq": "b329d266f6830d7b6e03e736774dd841090de50f063ffb70d5c8954211c83e9c",
|
|
12
|
+
"feature-grid": "7c24d51e1ee17cbf217d8979acfa81c16173296458769618f18e0d846bb4226a",
|
|
13
|
+
"footer": "f23d3d8ef3784f7135992805d5b1eddc1e1a563d2906b47e07a4f652c997df6b",
|
|
14
|
+
"form": "8ee00d930cbbb9e798c6c8e204010e6c02690828d3110983adf0494f55523145",
|
|
15
|
+
"gallery": "0695b4f0ddaea53ab30ec08f77983d553fd803894de75fdd69b06b9cd17c0168",
|
|
16
|
+
"hero": "2ea1c4370d7a26004e42321143fed89cc1ab59eb66a1b68ad14de81210ee2ddf",
|
|
17
|
+
"image": "b6ab6030d6ed8c64e0e24456084b0d59ff2ed99ed61f14a2df029afaa4b34b92",
|
|
18
|
+
"logo-cloud": "00bea2e0f8a8e4397480144f4ddba414e23b89597c123f5a27da9f99a5eeb839",
|
|
19
|
+
"navigation": "a0560e290f8053a8844bbff2fb5db8e066a2288320a6af29c0419bebb7531aff",
|
|
20
|
+
"newsletter": "1a803d0974385c7f3dc9237674d302e7398eae76fd7879acfce3eefee534703e",
|
|
21
|
+
"order-status": "06697d579f778b545da564029875159f28a61a6b184303e84dc02e53fd74861c",
|
|
22
|
+
"pricing-table": "349f8b1b609c56e91846b1ffc549bc9067ae0d1a45805787f1140dc017d2f8da",
|
|
23
|
+
"product-carousel": "305b5c8cf936b79a1ea1f6045f7c438cdc7fd843cf44911e7ba3ee1e77d27356",
|
|
24
|
+
"product-detail": "0ff885a0bf63e3523ca9bc378d040210e9dad16095afaf8d257c3be3b315b91f",
|
|
25
|
+
"quote": "a71b7ea5bf1a73b5dce59db9159a4ed9cd552c50a122416319dce1d9da21fb67",
|
|
26
|
+
"rich-text": "e02d52116bc25269809f50e6952ec80581f3b9730129cae68cea6769a8d485c3",
|
|
27
|
+
"search": "600e4c956a0ab88f46541369697771e1cf5b22a90e3eaa3c90ef9aeadefa5b30",
|
|
28
|
+
"split-content": "b586f7f5abc1a78d994ed0db7ef84e0d261880ffb7ffe6147e647f00d47d9973",
|
|
29
|
+
"stats": "29408d0c562c971599e1064cb939171cddfbeab1fbd4856af63c4fd67c38be72",
|
|
30
|
+
"tabs": "a06e80dd16fabcc0e2f41da88d2267fea3c5ffbf782bd36e0500bbcffafd76b9",
|
|
31
|
+
"team": "86ce1682ebe13049ed13e65f32e224f00827d319e29b843b9dd2dc9bd87e2815",
|
|
32
|
+
"testimonials": "a972a5aa4391f26f9f64f535001cc750b8cabbcc0bddbe51fded2bab712f1dce",
|
|
33
|
+
"timeline": "6874b55b591ea7046b91133c1340690eb3225592bea905af1ee22f81684ae4f0",
|
|
34
|
+
"trust-strip": "5ea9160b8e8b7f155df3f620ac94d24986e82ff6a9282da11d61c1061ae5d369",
|
|
35
|
+
"video-embed": "d212b948fe1cdeb188d3db937cdeac326038af6570c08a0a704a6b3634caa0b9",
|
|
36
|
+
"wishlist": "b05ec0a68456b0d4db451fe7ecae96f9a71d9b93638fecd39671cc7e85e38006"
|
|
37
37
|
}
|
|
@@ -9,7 +9,8 @@ import {
|
|
|
9
9
|
provideEldraUiLocale,
|
|
10
10
|
provideEldraUiMessages,
|
|
11
11
|
} from '@eldrajs/ui';
|
|
12
|
-
import { createDemoStorefront, DEMO_CART_LINES } from '../app/storefront/demo';
|
|
12
|
+
import { createDemoStorefront, DEMO_CART_LINES, DEMO_STORE_AMOUNTS } from '../app/storefront/demo';
|
|
13
|
+
import { STORE_AMOUNTS_KEY } from '../app/composables/usePriceTokens';
|
|
13
14
|
import { STOREFRONT_KEY } from '../app/storefront/types';
|
|
14
15
|
import { storybookI18n } from './i18n';
|
|
15
16
|
import enUSMessages from '../i18n/en-US.json';
|
|
@@ -71,7 +72,10 @@ export const withEldraContext: Decorator = (story, storyContext) => ({
|
|
|
71
72
|
components: { story },
|
|
72
73
|
setup() {
|
|
73
74
|
const context = provideEldra({
|
|
74
|
-
client: createEldraClient({
|
|
75
|
+
client: createEldraClient({
|
|
76
|
+
gatewayUrl: 'https://storybook.invalid',
|
|
77
|
+
orgId: 'storybook',
|
|
78
|
+
}),
|
|
75
79
|
// The same catalogue `storybookI18n` (`./i18n.ts`) installs — nothing in Storybook reads
|
|
76
80
|
// `context.messages` directly today, but the shape should match a real page's (the merged/
|
|
77
81
|
// resolved `virtual:eldra/messages`) rather than the empty fallback `provideEldra` otherwise
|
|
@@ -116,6 +120,7 @@ export const withEldraContext: Decorator = (story, storyContext) => ({
|
|
|
116
120
|
});
|
|
117
121
|
if (isCartStory) storefront.cart.drawerOpen.value = true;
|
|
118
122
|
provideEldraUiCurrency(storefront.commerce?.currency);
|
|
123
|
+
provide(STORE_AMOUNTS_KEY, DEMO_STORE_AMOUNTS);
|
|
119
124
|
provide(STOREFRONT_KEY, storefront);
|
|
120
125
|
return {};
|
|
121
126
|
},
|
|
@@ -48,6 +48,11 @@
|
|
|
48
48
|
--eldra-radius-xl: 1.25rem;
|
|
49
49
|
--eldra-control-height: 2.75rem;
|
|
50
50
|
--eldra-control-height-lg: 3.25rem;
|
|
51
|
+
/* Every block's `Container` pads by these two, not by the theme's per-container gutter tokens
|
|
52
|
+
(those reach only layout zones), so they follow the wide container's gutters from
|
|
53
|
+
`tokens.json`: the design's 1rem at every width, and a Studio override of them still lands. */
|
|
54
|
+
--eldra-gutter-tablet: var(--eldra-container-wide-gutter-tablet, 1rem);
|
|
55
|
+
--eldra-gutter-desktop: var(--eldra-container-wide-gutter-normal, 1rem);
|
|
51
56
|
}
|
|
52
57
|
|
|
53
58
|
/* Hides the native scrollbar on a scroll-snap carousel track while keeping
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { computed, type ComputedRef } from 'vue';
|
|
2
|
-
import { useEldraBlockField } from '@eldrajs/theme-vue';
|
|
2
|
+
import { provideEldraPrices, useEldraBlockField } from '@eldrajs/theme-vue';
|
|
3
|
+
import { priceNodeResolver, resolveBlockTokens, usePriceTokenOptions } from './usePriceTokens';
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* Typed access to a block's CMS data. `EldraBlockData`/`EldraBlockEntry` are
|
|
@@ -13,6 +14,10 @@ import { useEldraBlockField } from '@eldrajs/theme-vue';
|
|
|
13
14
|
* passes `api-id="article"` to `EldraRichText` as a literal — `apiId` here
|
|
14
15
|
* is the same idea: a `Block.vue` always knows its own apiId statically, so
|
|
15
16
|
* it passes it once as the second argument.
|
|
17
|
+
*
|
|
18
|
+
* `data` has every **price token** already written in the shopper's currency, in every string at
|
|
19
|
+
* any depth, and the block's rich text gets the resolver for its `price` nodes
|
|
20
|
+
* (`usePriceTokens.ts`): this is the one place prices resolve, so no block handles them itself.
|
|
16
21
|
*/
|
|
17
22
|
export function useBlockData<K extends keyof EldraBlockData>(
|
|
18
23
|
props: { entry: EldraBlockEntry<K> },
|
|
@@ -22,8 +27,10 @@ export function useBlockData<K extends keyof EldraBlockData>(
|
|
|
22
27
|
entryId: string;
|
|
23
28
|
field: (fieldId: string) => ReturnType<typeof useEldraBlockField>;
|
|
24
29
|
} {
|
|
30
|
+
const tokens = usePriceTokenOptions();
|
|
31
|
+
provideEldraPrices(priceNodeResolver(tokens));
|
|
25
32
|
return {
|
|
26
|
-
data: computed(() => props.entry.data),
|
|
33
|
+
data: computed(() => resolveBlockTokens(props.entry.data, tokens.value)),
|
|
27
34
|
entryId: props.entry.id,
|
|
28
35
|
field: (fieldId: string) => useEldraBlockField(apiId, fieldId),
|
|
29
36
|
};
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { computed, inject, type ComputedRef, type InjectionKey } from 'vue';
|
|
2
|
+
import { useEldraUiCurrency, useEldraUiLocale } from '@eldrajs/ui';
|
|
3
|
+
import {
|
|
4
|
+
formatToken,
|
|
5
|
+
hasTokens,
|
|
6
|
+
parseToken,
|
|
7
|
+
resolvePriceNode,
|
|
8
|
+
toMajorUnits,
|
|
9
|
+
resolveTokens,
|
|
10
|
+
type ResolveTokensOptions,
|
|
11
|
+
type StoreAmounts,
|
|
12
|
+
} from '@eldrajs/sdk/tokens';
|
|
13
|
+
import { decodeStega, encodeStega, type StegaPricePart } from '@eldrajs/theme-core/stega';
|
|
14
|
+
import { formatMoney } from '../storefront/money';
|
|
15
|
+
import { STOREFRONT_KEY } from '../storefront/types';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* **Price tokens** (WS-1474, WS-1473): a merchant can put a price in any text field of any block —
|
|
19
|
+
* `Free shipping over ⟦store freeShippingThreshold⟧!`, `⟦price#a3f ISK=4790 EUR=3200⟧ a box` — and
|
|
20
|
+
* the page writes it in the shopper's currency, formatted exactly like every `<Price>` beside it.
|
|
21
|
+
* Each currency's amount is the merchant's own, never converted; a sentence whose price has no
|
|
22
|
+
* amount in the shopper's currency is left out (`@eldrajs/sdk/tokens`' `resolveTokens`).
|
|
23
|
+
*
|
|
24
|
+
* No block does anything for this: `useBlockData` hands every block its data with every string
|
|
25
|
+
* already written out (`resolveBlockTokens`), and provides the rich-text resolver its
|
|
26
|
+
* `EldraRichText` reads for a `price` node.
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* The store's own amounts for `⟦store …⟧` tokens, in minor units per currency —
|
|
31
|
+
* `{ freeShippingThreshold: { ISK: 1500000 } }`. `@eldrajs/theme-nuxt` reads them from the
|
|
32
|
+
* delivery methods once at build (`runtimeConfig.public.eldra.storeAmounts`) and
|
|
33
|
+
* `app/plugins/eldra-ui-messages.ts` provides them; Storybook and the block tests provide the
|
|
34
|
+
* Northwind demo's. Absent, every store-setting token's sentence is left out.
|
|
35
|
+
*/
|
|
36
|
+
export const STORE_AMOUNTS_KEY: InjectionKey<StoreAmounts | null> = Symbol.for(
|
|
37
|
+
'eldra.starter.store-amounts'
|
|
38
|
+
) as InjectionKey<StoreAmounts | null>;
|
|
39
|
+
|
|
40
|
+
/** The store's own amounts for its settings, as `app/plugins/eldra-ui-messages.ts` provides them. */
|
|
41
|
+
export function useStoreAmounts(): StoreAmounts | null {
|
|
42
|
+
return inject(STORE_AMOUNTS_KEY, null);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* One store setting's amount in one currency, in **major units** like every storefront amount
|
|
47
|
+
* (`app/storefront/types.ts`): `freeShippingThreshold` in ISK is the lowest free-shipping threshold
|
|
48
|
+
* among the store's delivery methods in ISK. `null` when the store has none in that currency —
|
|
49
|
+
* never another currency's amount, never converted.
|
|
50
|
+
*/
|
|
51
|
+
export function storeAmountIn(
|
|
52
|
+
amounts: StoreAmounts | null,
|
|
53
|
+
name: string,
|
|
54
|
+
currency: string | null | undefined
|
|
55
|
+
): number | null {
|
|
56
|
+
if (currency === null || currency === undefined || currency === '') return null;
|
|
57
|
+
const minor = amounts?.[name]?.[currency];
|
|
58
|
+
return typeof minor === 'number' && Number.isFinite(minor) && minor > 0
|
|
59
|
+
? toMajorUnits(minor, currency)
|
|
60
|
+
: null;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** How this page writes a token: the shopper's currency, the regional format, the theme's money. */
|
|
64
|
+
export function usePriceTokenOptions(): ComputedRef<ResolveTokensOptions> {
|
|
65
|
+
// The **shopper's** currency — what the picker chose, the one product cards price in — not the
|
|
66
|
+
// store's base currency `CURRENCY_KEY` carries: a shopper in euros reads the euro amount.
|
|
67
|
+
const shopperCurrency = inject(STOREFRONT_KEY, null)?.currency.active;
|
|
68
|
+
const storeCurrency = useEldraUiCurrency();
|
|
69
|
+
const locale = useEldraUiLocale();
|
|
70
|
+
const storeAmounts = inject(STORE_AMOUNTS_KEY, null);
|
|
71
|
+
return computed(() => ({
|
|
72
|
+
currency: shopperCurrency?.value ?? storeCurrency.value,
|
|
73
|
+
locale: locale.value,
|
|
74
|
+
storeAmounts,
|
|
75
|
+
format: formatMoney,
|
|
76
|
+
}));
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** A rich-text `price` node's text, for `provideEldraPrices`. */
|
|
80
|
+
export function priceNodeResolver(
|
|
81
|
+
options: ComputedRef<ResolveTokensOptions>
|
|
82
|
+
): (attrs: unknown) => string | null {
|
|
83
|
+
return (attrs) => resolvePriceNode(attrs, options.value);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** One string with its tokens written out. */
|
|
87
|
+
function resolveString(value: string, options: ResolveTokensOptions): string {
|
|
88
|
+
if (!hasTokens(value)) return value;
|
|
89
|
+
const { cleaned, meta } = decodeStega(value);
|
|
90
|
+
const written = resolveTokens(cleaned, options);
|
|
91
|
+
// Every sentence left out (no amount in this currency): the value is empty, and must read as
|
|
92
|
+
// empty to the block — a payload alone is invisible but not blank to `trim()`, so an info item
|
|
93
|
+
// or a heading would still draw its icon or its wrapper around nothing.
|
|
94
|
+
if (written.trim() === '') return '';
|
|
95
|
+
// The builder preview's payload names the field. The text the page shows is no longer the text
|
|
96
|
+
// the field stores, so the payload also carries the stored text (`parts`): the overlay edits
|
|
97
|
+
// that on the canvas, each price as a chip, and posts every edit with its tokens intact.
|
|
98
|
+
return meta === null
|
|
99
|
+
? written
|
|
100
|
+
: encodeStega(written, { ...meta, parts: storedParts(cleaned, options) });
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** A field's stored text as the overlay edits it: plain runs, and each token with its label. */
|
|
104
|
+
function storedParts(text: string, options: ResolveTokensOptions): StegaPricePart[] {
|
|
105
|
+
return text
|
|
106
|
+
.split(/(⟦[^⟦⟧]*⟧)/)
|
|
107
|
+
.filter((run) => run !== '')
|
|
108
|
+
.map((run): StegaPricePart => {
|
|
109
|
+
const token = run.startsWith('⟦') ? parseToken(run.slice(1, -1)) : null;
|
|
110
|
+
if (token === null) return run;
|
|
111
|
+
const label = formatToken(token, options);
|
|
112
|
+
if (label !== null) return { token: run, label };
|
|
113
|
+
const currency = options.currency ?? '';
|
|
114
|
+
const what = token.kind === 'store' ? 'threshold' : 'price';
|
|
115
|
+
return { token: run, label: `No ${currency} ${what}`.replace(' ', ' '), missing: true };
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** A rich-text document: its `price` nodes are `EldraRichText`'s to write, not this walk's. */
|
|
120
|
+
function isRichTextDocument(value: object): boolean {
|
|
121
|
+
return (value as { type?: unknown }).type === 'doc';
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* The block data with every token in every string written out, at any depth (list items, groups).
|
|
126
|
+
* Returns the very same object when nothing held a token, so a block with no prices pays one walk
|
|
127
|
+
* and keeps its identity.
|
|
128
|
+
*/
|
|
129
|
+
export function resolveBlockTokens<T>(value: T, options: ResolveTokensOptions): T {
|
|
130
|
+
if (typeof value === 'string') return resolveString(value, options) as T;
|
|
131
|
+
if (value === null || typeof value !== 'object') return value;
|
|
132
|
+
if (Array.isArray(value)) {
|
|
133
|
+
let changed = false;
|
|
134
|
+
const out = value.map((item: unknown) => {
|
|
135
|
+
const next = resolveBlockTokens(item, options);
|
|
136
|
+
if (next !== item) changed = true;
|
|
137
|
+
return next;
|
|
138
|
+
});
|
|
139
|
+
return (changed ? out : value) as T;
|
|
140
|
+
}
|
|
141
|
+
if (isRichTextDocument(value)) return value;
|
|
142
|
+
let out: Record<string, unknown> | null = null;
|
|
143
|
+
for (const [key, item] of Object.entries(value as Record<string, unknown>)) {
|
|
144
|
+
const next = resolveBlockTokens(item, options);
|
|
145
|
+
if (next === item) continue;
|
|
146
|
+
out ??= { ...(value as Record<string, unknown>) };
|
|
147
|
+
out[key] = next;
|
|
148
|
+
}
|
|
149
|
+
return (out ?? value) as T;
|
|
150
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { nextTick, ref, watch, type Ref } from 'vue';
|
|
2
|
+
import { useI18n } from 'vue-i18n';
|
|
3
|
+
import { useToast } from '@eldrajs/ui';
|
|
4
|
+
import { useEldraLocale } from '@eldrajs/theme-vue';
|
|
5
|
+
import { useStorefront } from './useStorefront';
|
|
6
|
+
import { useStorefrontFeedback } from './useStorefrontFeedback';
|
|
7
|
+
import { CART_ADD_TOAST_ID } from '../storefront/feedback';
|
|
8
|
+
import type { StorefrontProduct } from '../storefront/types';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* A product card's "+ Add": reads the product the card names (its list item carries no variant),
|
|
12
|
+
* adds one of its default variant to the cart, and says so in the shared cart toast — "Added to
|
|
13
|
+
* cart", with "View cart" opening the cart drawer when the page has one, else linking to `/cart`.
|
|
14
|
+
* A product with nothing to add, or an add the cart refuses, reports through the same toast.
|
|
15
|
+
*
|
|
16
|
+
* Shared by every block that draws `ProductCard`s with `quick-add` on (product-carousel,
|
|
17
|
+
* collection-grid, search), so the button does the same thing everywhere. Not a Nuxt global: a
|
|
18
|
+
* plain composable over `useStorefront()`, so blocks may call it.
|
|
19
|
+
*/
|
|
20
|
+
export function useQuickAdd(): {
|
|
21
|
+
busy: Ref<boolean>;
|
|
22
|
+
add: (item: { handle: string }) => Promise<void>;
|
|
23
|
+
} {
|
|
24
|
+
const { t } = useI18n();
|
|
25
|
+
const storefront = useStorefront();
|
|
26
|
+
const toast = useToast();
|
|
27
|
+
const feedback = useStorefrontFeedback();
|
|
28
|
+
const activeLocale = useEldraLocale();
|
|
29
|
+
|
|
30
|
+
/** `null` until a button is pressed, so the read asks for nothing on the server or on load. */
|
|
31
|
+
const handle = ref<string | null>(null);
|
|
32
|
+
const result = storefront.catalog.product(handle);
|
|
33
|
+
const busy = ref(false);
|
|
34
|
+
|
|
35
|
+
/** Resolves once the read for `wanted` has settled: the product, or `null` when it failed. */
|
|
36
|
+
async function readProduct(wanted: string): Promise<StorefrontProduct | null> {
|
|
37
|
+
handle.value = wanted;
|
|
38
|
+
await nextTick();
|
|
39
|
+
const settled = (): boolean =>
|
|
40
|
+
!result.loading.value &&
|
|
41
|
+
(result.data.value?.handle === wanted || result.error.value !== null);
|
|
42
|
+
if (!settled()) {
|
|
43
|
+
await new Promise<void>((resolve) => {
|
|
44
|
+
const stop = watch(
|
|
45
|
+
() => [result.loading.value, result.data.value, result.error.value],
|
|
46
|
+
() => {
|
|
47
|
+
if (!settled()) return;
|
|
48
|
+
stop();
|
|
49
|
+
resolve();
|
|
50
|
+
}
|
|
51
|
+
);
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
const product = result.data.value;
|
|
55
|
+
return product !== null && product.handle === wanted ? product : null;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
async function add(item: { handle: string }): Promise<void> {
|
|
59
|
+
if (busy.value) return;
|
|
60
|
+
busy.value = true;
|
|
61
|
+
try {
|
|
62
|
+
const product = await readProduct(item.handle);
|
|
63
|
+
if (product === null || product.variantId === '') {
|
|
64
|
+
feedback.report(null, { id: CART_ADD_TOAST_ID });
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
const cart = storefront.cart;
|
|
68
|
+
const failure = await cart.add({
|
|
69
|
+
productId: product.productId,
|
|
70
|
+
variantId: product.variantId,
|
|
71
|
+
quantity: 1,
|
|
72
|
+
});
|
|
73
|
+
if (failure !== null) {
|
|
74
|
+
feedback.report(failure, { id: CART_ADD_TOAST_ID });
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
toast.show({
|
|
78
|
+
id: CART_ADD_TOAST_ID,
|
|
79
|
+
title: t('cart.added'),
|
|
80
|
+
action: cart.drawerAvailable.value
|
|
81
|
+
? {
|
|
82
|
+
label: t('cart.viewCart'),
|
|
83
|
+
onActivate: () => {
|
|
84
|
+
cart.drawerOpen.value = true;
|
|
85
|
+
},
|
|
86
|
+
}
|
|
87
|
+
: { label: t('cart.viewCart'), href: activeLocale.path('/cart') },
|
|
88
|
+
});
|
|
89
|
+
} finally {
|
|
90
|
+
busy.value = false;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return { busy, add };
|
|
95
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { computed, inject, toValue, type ComputedRef, type InjectionKey } from 'vue';
|
|
2
|
+
import { LOCALE_KEY, formatDate, type FormatDateOptions } from '@eldrajs/ui';
|
|
3
|
+
import { useEldra } from '@eldrajs/theme-vue';
|
|
4
|
+
import type { StoreRegion } from '@eldrajs/theme-nuxt/region';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The organisation's **regional format** — the locale money, numbers and dates are written in and
|
|
8
|
+
* the time zone they are shown in — as `app/plugins/eldra-ui-messages.ts` provides it from
|
|
9
|
+
* `runtimeConfig.public.eldra.region` (`@eldrajs/theme-nuxt` reads it once at build). `null` when
|
|
10
|
+
* the build could not learn one; Storybook and the block specs provide nothing, which reads the
|
|
11
|
+
* same.
|
|
12
|
+
*
|
|
13
|
+
* Deliberately separate from the content locale: an English-language Icelandic store writes its
|
|
14
|
+
* copy in English and its prices and dates as "4.790 kr." and "26. nóvember 2026". Strings
|
|
15
|
+
* (`useI18n`, `@eldrajs/ui`'s messages, a list's "and") stay on the content locale; only numbers,
|
|
16
|
+
* money and dates follow this.
|
|
17
|
+
*
|
|
18
|
+
* A plain `inject`, not a Nuxt global, so a block may call it.
|
|
19
|
+
*/
|
|
20
|
+
export const REGION_KEY: InjectionKey<StoreRegion | null> = Symbol('starter-region');
|
|
21
|
+
|
|
22
|
+
export function useRegion(): StoreRegion | null {
|
|
23
|
+
return inject(REGION_KEY, null);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* The locale a page formats in: the regional format when the organisation published one, else the
|
|
28
|
+
* content locale (what every page did before regional formats existed). What the plugin provides
|
|
29
|
+
* as `LOCALE_KEY`, as a pure function so a spec can pin it.
|
|
30
|
+
*/
|
|
31
|
+
export function regionalFormatLocale(
|
|
32
|
+
region: StoreRegion | null,
|
|
33
|
+
contentLocale: string | undefined
|
|
34
|
+
): string | undefined {
|
|
35
|
+
return region?.formatLocale ?? contentLocale;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* The locale this page formats numbers, money and dates in: the plugin's `LOCALE_KEY` (the
|
|
40
|
+
* regional format, else the content locale), else — with no plugin, in a story or a spec — the
|
|
41
|
+
* content locale off the theme context, else `en-US`.
|
|
42
|
+
*/
|
|
43
|
+
export function useFormatLocale(): ComputedRef<string> {
|
|
44
|
+
const provided = inject(LOCALE_KEY, undefined);
|
|
45
|
+
const context = tryUseEldra();
|
|
46
|
+
return computed(
|
|
47
|
+
() => toValue(provided) ?? context?.locales?.active ?? context?.preview.locale ?? 'en-US'
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* `@eldrajs/ui`'s `formatDate` in the regional format: the regional locale, and a timestamp's
|
|
53
|
+
* calendar day **in the organisation's time zone** — an order placed at 23:30 UTC in a UTC−5 shop
|
|
54
|
+
* was placed on the day before, whatever zone the build machine or the visitor is in. A bare
|
|
55
|
+
* `YYYY-MM-DD` is a calendar day already and is passed through. Never throws; `null` for a value
|
|
56
|
+
* `formatDate` cannot read, exactly as it answers.
|
|
57
|
+
*/
|
|
58
|
+
export function useFormatDate(): (iso: string, options?: FormatDateOptions) => string | null {
|
|
59
|
+
const locale = useFormatLocale();
|
|
60
|
+
const timeZone = useRegion()?.timeZone;
|
|
61
|
+
return (iso, options) => formatDate(calendarDayIn(iso, timeZone), locale.value, options);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* The `YYYY-MM-DD` calendar day `iso` falls on in `timeZone`. A value with no time part, no zone
|
|
66
|
+
* to convert to, or a timestamp `Date` cannot parse is returned unchanged (`formatDate` takes the
|
|
67
|
+
* date part as it stands, which is what it always did).
|
|
68
|
+
*/
|
|
69
|
+
export function calendarDayIn(iso: string, timeZone: string | undefined): string {
|
|
70
|
+
if (timeZone === undefined || !iso.includes('T')) return iso;
|
|
71
|
+
const instant = new Date(iso);
|
|
72
|
+
if (Number.isNaN(instant.getTime())) return iso;
|
|
73
|
+
try {
|
|
74
|
+
const parts = new Intl.DateTimeFormat('en-US', {
|
|
75
|
+
timeZone,
|
|
76
|
+
year: 'numeric',
|
|
77
|
+
month: '2-digit',
|
|
78
|
+
day: '2-digit',
|
|
79
|
+
}).formatToParts(instant);
|
|
80
|
+
const part = (type: Intl.DateTimeFormatPartTypes): string =>
|
|
81
|
+
parts.find((entry) => entry.type === type)?.value ?? '';
|
|
82
|
+
return `${part('year')}-${part('month')}-${part('day')}`;
|
|
83
|
+
} catch {
|
|
84
|
+
return iso;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function tryUseEldra(): ReturnType<typeof useEldra> | undefined {
|
|
89
|
+
try {
|
|
90
|
+
return useEldra();
|
|
91
|
+
} catch {
|
|
92
|
+
return undefined;
|
|
93
|
+
}
|
|
94
|
+
}
|
package/template/app/icons.ts
CHANGED
|
@@ -51,6 +51,7 @@ import gridDotsIcon from '@tabler/icons/outline/grid-dots.svg?raw';
|
|
|
51
51
|
import heartIcon from '@tabler/icons/outline/heart.svg?raw';
|
|
52
52
|
import helpCircleIcon from '@tabler/icons/outline/help-circle.svg?raw';
|
|
53
53
|
import infoCircleIcon from '@tabler/icons/outline/info-circle.svg?raw';
|
|
54
|
+
import languageIcon from '@tabler/icons/outline/language.svg?raw';
|
|
54
55
|
import layoutAlignTopIcon from '@tabler/icons/outline/layout-align-top.svg?raw';
|
|
55
56
|
import layoutBottombarIcon from '@tabler/icons/outline/layout-bottombar.svg?raw';
|
|
56
57
|
import layoutColumnsIcon from '@tabler/icons/outline/layout-columns.svg?raw';
|
|
@@ -71,6 +72,7 @@ import packageIcon from '@tabler/icons/outline/package.svg?raw';
|
|
|
71
72
|
import phoneIcon from '@tabler/icons/outline/phone.svg?raw';
|
|
72
73
|
import photoIcon from '@tabler/icons/outline/photo.svg?raw';
|
|
73
74
|
import playerPlayIcon from '@tabler/icons/outline/player-play.svg?raw';
|
|
75
|
+
import plusIcon from '@tabler/icons/outline/plus.svg?raw';
|
|
74
76
|
import quoteIcon from '@tabler/icons/outline/quote.svg?raw';
|
|
75
77
|
import receiptIcon from '@tabler/icons/outline/receipt.svg?raw';
|
|
76
78
|
import searchIcon from '@tabler/icons/outline/search.svg?raw';
|
|
@@ -136,6 +138,7 @@ const RAW = {
|
|
|
136
138
|
heart: heartIcon,
|
|
137
139
|
'help-circle': helpCircleIcon,
|
|
138
140
|
'info-circle': infoCircleIcon,
|
|
141
|
+
language: languageIcon,
|
|
139
142
|
'layout-align-top': layoutAlignTopIcon,
|
|
140
143
|
'layout-bottombar': layoutBottombarIcon,
|
|
141
144
|
'layout-columns': layoutColumnsIcon,
|
|
@@ -156,6 +159,7 @@ const RAW = {
|
|
|
156
159
|
phone: phoneIcon,
|
|
157
160
|
photo: photoIcon,
|
|
158
161
|
'player-play': playerPlayIcon,
|
|
162
|
+
plus: plusIcon,
|
|
159
163
|
quote: quoteIcon,
|
|
160
164
|
receipt: receiptIcon,
|
|
161
165
|
search: searchIcon,
|
|
@@ -94,6 +94,7 @@ export default defineNuxtPlugin({
|
|
|
94
94
|
}
|
|
95
95
|
|
|
96
96
|
const route: StorefrontRoute = reactive({
|
|
97
|
+
path: '',
|
|
97
98
|
productHandle: null,
|
|
98
99
|
collectionHandle: null,
|
|
99
100
|
categorySlug: null,
|
|
@@ -136,6 +137,7 @@ export default defineNuxtPlugin({
|
|
|
136
137
|
// catalog template behind it — the storefront pages a site has before its first deploy
|
|
137
138
|
// seeds the templates, and the demo/Storybook routes.
|
|
138
139
|
watchEffect(() => {
|
|
140
|
+
route.path = activeRoute.value.path;
|
|
139
141
|
const handle = firstOf(activeRoute.value.params.handle as string | string[] | undefined);
|
|
140
142
|
const match = catalog.value;
|
|
141
143
|
if (match === null) {
|
|
@@ -9,7 +9,11 @@ import {
|
|
|
9
9
|
} from '@eldrajs/ui';
|
|
10
10
|
import { isIS as uiIsIS } from '@eldrajs/ui/messages/is-IS';
|
|
11
11
|
import { ELDRA_KEY, type EldraContext } from '@eldrajs/theme-vue';
|
|
12
|
+
import { resolveStoreRegion } from '@eldrajs/theme-nuxt/region';
|
|
13
|
+
import { toStoreAmounts } from '@eldrajs/theme-nuxt/store-amounts';
|
|
12
14
|
import { toStorefrontCommerce } from '../storefront/commerce';
|
|
15
|
+
import { REGION_KEY, regionalFormatLocale } from '../composables/useRegionalFormat';
|
|
16
|
+
import { STORE_AMOUNTS_KEY } from '../composables/usePriceTokens';
|
|
13
17
|
|
|
14
18
|
/** The package's own default message set for a content locale — `is-IS` takes its Icelandic entry
|
|
15
19
|
* point, anything else (including `undefined`) keeps the English defaults. Only this plugin's own
|
|
@@ -32,8 +36,8 @@ function uiPackageMessagesFor(locale: string | null | undefined): UiMessages {
|
|
|
32
36
|
* through a getter is what makes the switch reactive — and, unlike a `watch`,
|
|
33
37
|
* it creates no effect that would outlive a server request.
|
|
34
38
|
*
|
|
35
|
-
* The same provide gives the package the
|
|
36
|
-
* formatted in (`UnitInput`, `CurrencyInput`, `QuantityStepper`, `Price`), as
|
|
39
|
+
* The same provide gives the package the locale its **numbers** are
|
|
40
|
+
* formatted in — the regional format, falling back to the content locale (see below) — (`UnitInput`, `CurrencyInput`, `QuantityStepper`, `Price`), as
|
|
37
41
|
* a getter for the same reason, plus the store **currency** `Price` formats
|
|
38
42
|
* amounts in. All three are separate keys on purpose: the strings a component
|
|
39
43
|
* renders, the locale its numbers are formatted in, and the currency its
|
|
@@ -77,8 +81,12 @@ export default defineNuxtPlugin({
|
|
|
77
81
|
inject<EldraContext | undefined>(ELDRA_KEY, undefined)
|
|
78
82
|
);
|
|
79
83
|
const publicConfig = useRuntimeConfig().public as unknown as {
|
|
80
|
-
eldra?: { commerce?: unknown };
|
|
84
|
+
eldra?: { commerce?: unknown; region?: unknown; storeAmounts?: unknown };
|
|
81
85
|
};
|
|
86
|
+
// The organisation's regional format (`@eldrajs/theme-nuxt`'s build-time read): the locale
|
|
87
|
+
// numbers, money and dates are written in and the zone dates are shown in. Read once, like the
|
|
88
|
+
// currency: it cannot change while the page is open.
|
|
89
|
+
const region = resolveStoreRegion(publicConfig.eldra?.region);
|
|
82
90
|
const currency = toStorefrontCommerce(publicConfig.eldra?.commerce)?.currency;
|
|
83
91
|
// The page's own content locale, read through a getter on every access for the same reason
|
|
84
92
|
// the message getters below exist: it changes when the visitor changes language, and the
|
|
@@ -102,11 +110,17 @@ export default defineNuxtPlugin({
|
|
|
102
110
|
});
|
|
103
111
|
}
|
|
104
112
|
nuxtApp.vueApp.provide(MESSAGES_KEY, messages);
|
|
105
|
-
// The
|
|
106
|
-
// `
|
|
107
|
-
//
|
|
108
|
-
//
|
|
109
|
-
|
|
113
|
+
// The locale every `Intl` format in the theme runs in — `@eldrajs/ui`'s `Price`/`CurrencyInput`/
|
|
114
|
+
// `ContentCard` dates and, through `useEldraUiLocale()`/`useFormatLocale()`,
|
|
115
|
+
// `app/storefront/money.ts` and the blocks' own dates — is the organisation's **regional
|
|
116
|
+
// format**, not the content locale: an Icelandic store prints "4.790 kr." and Icelandic dates
|
|
117
|
+
// on its English pages too. The strings above stay on the content locale. With no regional
|
|
118
|
+
// format published, the content locale formats, as before.
|
|
119
|
+
nuxtApp.vueApp.provide(LOCALE_KEY, () => regionalFormatLocale(region, activeLocale()));
|
|
120
|
+
nuxtApp.vueApp.provide(REGION_KEY, region);
|
|
110
121
|
nuxtApp.vueApp.provide(CURRENCY_KEY, currency);
|
|
122
|
+
// The store's own amounts for `⟦store …⟧` price tokens (the free-shipping threshold per
|
|
123
|
+
// currency), read once at build like the currency: `app/composables/usePriceTokens.ts`.
|
|
124
|
+
nuxtApp.vueApp.provide(STORE_AMOUNTS_KEY, toStoreAmounts(publicConfig.eldra?.storeAmounts));
|
|
111
125
|
},
|
|
112
126
|
});
|