@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.
Files changed (168) hide show
  1. package/CHANGELOG.md +11 -1
  2. package/package.json +3 -3
  3. package/template/.eldra/block-types.d.ts +4 -6
  4. package/template/.eldra/manifest.json +228 -246
  5. package/template/.eldra/previews.json +35 -35
  6. package/template/.storybook/eldra.ts +7 -2
  7. package/template/app/assets/main.css +5 -0
  8. package/template/app/composables/useBlockData.ts +9 -2
  9. package/template/app/composables/usePriceTokens.ts +150 -0
  10. package/template/app/composables/useQuickAdd.ts +95 -0
  11. package/template/app/composables/useRegionalFormat.ts +94 -0
  12. package/template/app/icons.ts +4 -0
  13. package/template/app/plugins/eldra-storefront.ts +2 -0
  14. package/template/app/plugins/eldra-ui-messages.ts +22 -8
  15. package/template/app/storefront/demo.ts +188 -16
  16. package/template/app/storefront/gateway.ts +19 -0
  17. package/template/app/storefront/productCardLook.ts +76 -0
  18. package/template/app/storefront/productReference.ts +17 -0
  19. package/template/app/storefront/toProductCard.ts +12 -8
  20. package/template/app/storefront/types.ts +17 -0
  21. package/template/blocks/announcement-bar/__tests__/Block.spec.ts +19 -7
  22. package/template/blocks/announcement-bar/block.json +2 -1
  23. package/template/blocks/announcement-bar/mock.json +1 -1
  24. package/template/blocks/announcement-bar/preview.png +0 -0
  25. package/template/blocks/article/Block.vue +8 -18
  26. package/template/blocks/article/block.json +3 -1
  27. package/template/blocks/article/preview.png +0 -0
  28. package/template/blocks/article-list/block.json +10 -1
  29. package/template/blocks/article-list/preview.png +0 -0
  30. package/template/blocks/breadcrumbs/Block.vue +15 -3
  31. package/template/blocks/breadcrumbs/__tests__/Block.spec.ts +13 -0
  32. package/template/blocks/breadcrumbs/block.json +1 -0
  33. package/template/blocks/breadcrumbs/preview.png +0 -0
  34. package/template/blocks/cart/Block.vue +15 -5
  35. package/template/blocks/cart/__tests__/Block.spec.ts +53 -10
  36. package/template/blocks/cart/__tests__/ShippingBar.spec.ts +10 -8
  37. package/template/blocks/cart/block.json +8 -5
  38. package/template/blocks/cart/mock.json +2 -2
  39. package/template/blocks/cart/parts/ShippingBar.vue +24 -30
  40. package/template/blocks/cart/parts/notSold.ts +4 -3
  41. package/template/blocks/collection-grid/Block.vue +168 -85
  42. package/template/blocks/collection-grid/__tests__/Block.spec.ts +101 -23
  43. package/template/blocks/collection-grid/preview.png +0 -0
  44. package/template/blocks/collection-header/Block.vue +34 -11
  45. package/template/blocks/collection-header/__tests__/Block.spec.ts +3 -3
  46. package/template/blocks/collection-header/block.json +2 -0
  47. package/template/blocks/collection-header/preview.png +0 -0
  48. package/template/blocks/contact/block.json +4 -0
  49. package/template/blocks/contact/preview.png +0 -0
  50. package/template/blocks/cta/block.json +2 -0
  51. package/template/blocks/faq/Block.vue +5 -10
  52. package/template/blocks/faq/block.json +2 -1
  53. package/template/blocks/faq/mock.json +12 -1
  54. package/template/blocks/faq/preview.png +0 -0
  55. package/template/blocks/feature-grid/__tests__/Block.spec.ts +30 -7
  56. package/template/blocks/feature-grid/block.json +3 -2
  57. package/template/blocks/feature-grid/mock.json +1 -1
  58. package/template/blocks/feature-grid/preview.png +0 -0
  59. package/template/blocks/footer/Block.vue +64 -21
  60. package/template/blocks/footer/__tests__/Block.spec.ts +97 -1
  61. package/template/blocks/footer/block.json +5 -2
  62. package/template/blocks/footer/mock.json +1 -1
  63. package/template/blocks/footer/preview.png +0 -0
  64. package/template/blocks/form/block.json +1 -0
  65. package/template/blocks/gallery/preview.png +0 -0
  66. package/template/blocks/hero/Block.vue +38 -9
  67. package/template/blocks/hero/__tests__/Block.spec.ts +71 -19
  68. package/template/blocks/hero/block.json +16 -22
  69. package/template/blocks/hero/preview.json +1 -3
  70. package/template/blocks/hero/preview.png +0 -0
  71. package/template/blocks/image/block.json +2 -1
  72. package/template/blocks/image/preview.png +0 -0
  73. package/template/blocks/logo-cloud/block.json +1 -0
  74. package/template/blocks/logo-cloud/preview.png +0 -0
  75. package/template/blocks/navigation/Block.vue +404 -159
  76. package/template/blocks/navigation/__tests__/Block.spec.ts +806 -172
  77. package/template/blocks/navigation/__tests__/currentItem.spec.ts +90 -0
  78. package/template/blocks/navigation/block.json +2 -11
  79. package/template/blocks/navigation/mock.json +3 -3
  80. package/template/blocks/navigation/parts/LocalePicker.vue +103 -0
  81. package/template/blocks/navigation/parts/currentItem.ts +82 -0
  82. package/template/blocks/navigation/preview.json +7 -1
  83. package/template/blocks/navigation/preview.png +0 -0
  84. package/template/blocks/newsletter/Block.vue +6 -2
  85. package/template/blocks/newsletter/block.json +2 -0
  86. package/template/blocks/newsletter/preview.png +0 -0
  87. package/template/blocks/order-status/Block.vue +8 -17
  88. package/template/blocks/order-status/block.json +3 -0
  89. package/template/blocks/order-status/preview.png +0 -0
  90. package/template/blocks/pricing-table/__tests__/Block.spec.ts +12 -4
  91. package/template/blocks/pricing-table/block.json +2 -0
  92. package/template/blocks/pricing-table/mock.json +6 -6
  93. package/template/blocks/pricing-table/preview.png +0 -0
  94. package/template/blocks/product-carousel/Block.vue +36 -126
  95. package/template/blocks/product-carousel/__tests__/Block.spec.ts +88 -0
  96. package/template/blocks/product-carousel/block.json +1 -0
  97. package/template/blocks/product-carousel/preview.png +0 -0
  98. package/template/blocks/product-detail/Block.vue +84 -31
  99. package/template/blocks/product-detail/__tests__/Block.spec.ts +86 -0
  100. package/template/blocks/product-detail/__tests__/specs.spec.ts +79 -0
  101. package/template/blocks/product-detail/block.json +3 -1
  102. package/template/blocks/product-detail/mock.json +54 -4
  103. package/template/blocks/product-detail/parts/Gallery.vue +8 -2
  104. package/template/blocks/product-detail/preview.png +0 -0
  105. package/template/blocks/product-detail/specs.ts +75 -0
  106. package/template/blocks/quote/block.json +1 -0
  107. package/template/blocks/rich-text/preview.png +0 -0
  108. package/template/blocks/search/Block.vue +6 -1
  109. package/template/blocks/search/TypeSection.vue +8 -1
  110. package/template/blocks/search/__tests__/Block.spec.ts +24 -1
  111. package/template/blocks/search/block.json +1 -0
  112. package/template/blocks/search/preview.png +0 -0
  113. package/template/blocks/split-content/Block.vue +12 -5
  114. package/template/blocks/split-content/__tests__/Block.spec.ts +13 -0
  115. package/template/blocks/split-content/block.json +4 -2
  116. package/template/blocks/split-content/preview.png +0 -0
  117. package/template/blocks/stats/preview.png +0 -0
  118. package/template/blocks/tabs/Block.vue +3 -4
  119. package/template/blocks/tabs/block.json +1 -1
  120. package/template/blocks/tabs/preview.png +0 -0
  121. package/template/blocks/team/block.json +3 -1
  122. package/template/blocks/team/preview.png +0 -0
  123. package/template/blocks/testimonials/block.json +2 -0
  124. package/template/blocks/testimonials/preview.png +0 -0
  125. package/template/blocks/timeline/block.json +2 -1
  126. package/template/blocks/timeline/preview.png +0 -0
  127. package/template/blocks/trust-strip/Block.vue +2 -2
  128. package/template/blocks/trust-strip/__tests__/Block.spec.ts +38 -9
  129. package/template/blocks/trust-strip/block.json +1 -1
  130. package/template/blocks/trust-strip/mock.json +1 -1
  131. package/template/blocks/trust-strip/preview.json +1 -1
  132. package/template/blocks/trust-strip/preview.png +0 -0
  133. package/template/blocks/video-embed/block.json +2 -0
  134. package/template/blocks/video-embed/preview.png +0 -0
  135. package/template/blocks/wishlist/Block.vue +2 -2
  136. package/template/blocks/wishlist/preview.png +0 -0
  137. package/template/i18n/en-US.json +13 -5
  138. package/template/i18n/is-IS.json +12 -4
  139. package/template/pages/article.page.json +1 -3
  140. package/template/pages/cart.page.json +1 -3
  141. package/template/pages/category.page.json +2 -4
  142. package/template/pages/collection.page.json +1 -3
  143. package/template/pages/home.page.json +7 -18
  144. package/template/pages/product.page.json +62 -131
  145. package/template/pages/products.page.json +1 -3
  146. package/template/pages/search.page.json +1 -3
  147. package/template/pages/wishlist.page.json +1 -3
  148. package/template/stories/generated/footer.stories.ts +6 -0
  149. package/template/stories/generated/navigation.stories.ts +0 -18
  150. package/template/test/inlineEditable.spec.ts +10 -2
  151. package/template/test/localePrefix.spec.ts +2 -19
  152. package/template/test/pages/article.spec.ts +0 -2
  153. package/template/test/pages/category.spec.ts +35 -13
  154. package/template/test/pages/home.spec.ts +33 -17
  155. package/template/test/pages/product.spec.ts +64 -44
  156. package/template/test/pages/ssr.spec.ts +3 -1
  157. package/template/test/prerenderRefresh.browser.spec.ts +30 -25
  158. package/template/test/priceTokens.spec.ts +309 -0
  159. package/template/test/regionalFormat.spec.ts +80 -0
  160. package/template/test/starter.spec.ts +23 -7
  161. package/template/test/storefront/demo.spec.ts +19 -18
  162. package/template/test/storefront/toProductCard.spec.ts +17 -2
  163. package/template/test/structuredData.generate.spec.ts +4 -2
  164. package/template/test/support/mockGateway.ts +21 -1
  165. package/template/test/support/mountBlock.ts +25 -4
  166. package/template/test/support/priceTokens.ts +20 -0
  167. package/template/test/uiMessagesPlugin.spec.ts +34 -1
  168. package/template/tokens.json +8 -8
@@ -1,37 +1,37 @@
1
1
  {
2
- "announcement-bar": "57585e73344f7f93e035e0ad2b4dd6bb78a637938748fe3e3cc3a5be03f9dd2e",
3
- "article": "a1547a989ef3d10050746285d4ce1c24b16e2610e2bd050dafa5c488c67af89a",
4
- "article-list": "d3f44dd64ee22d9a0601d09a83796630102908a1ec6382de920438b0abab5a18",
5
- "breadcrumbs": "d4c6ced656b44bf949c4e4ea227d92d3890ca4cbc655aa07660d60d3121e7e18",
6
- "cart": "36f3bc9cb2d5344d23e5cba32e02a7f4406b516f1f67bd048940b5277aa366af",
7
- "collection-grid": "ca49c57711dfdce4360fb71b625c7e09352b0e5aa906e511108221198e6b8ca4",
8
- "collection-header": "84ccdb7fec7818e26c7380c54109c6bef6fd4220bca2881a495fa6c37498ba11",
9
- "contact": "a5a8e88a33a067924dee514db34fabc75a041571174543c1f20a726d7d9dea97",
10
- "cta": "e1971283c825fb8151ea021adb8342291dce7d0fb131cd3c523b4a214d91e629",
11
- "faq": "b7300c859d2fbe9df7a530f023ac31217e2ce903e73ecf97420eaf2f5e412e1c",
12
- "feature-grid": "fd3843fd1ec77463f2ba1aac882071febeb4ab6ff3942b167f7cfc78b60a1f0c",
13
- "footer": "36921634f057d3c242d8af500e1c02bb2b7d5cd2496333de343f582f5b9c8c33",
14
- "form": "6a8a93e671d828b43823b0f59d774f582e89df4d89aaba6494a1841cbe7998da",
15
- "gallery": "ed4b5a8bf44ef89c105555d95863227ce17434cb42226bbc7872ec24b863cf09",
16
- "hero": "d8a215c971ff457a249de48195c5cd01145254779dedb2f46665fe22c1071af2",
17
- "image": "2a02bc00b716a913973fcdffcb27a393055ccdd5d2cc02b43c25d59c391a04a9",
18
- "logo-cloud": "879e21642dd6af00c38dab6677367d7813ba6297dfba96c76c83c858dbb13fd2",
19
- "navigation": "f819d25dd803e67b89309caf8c45242d32aa3917cbf4aa6efcb2177f9d50cebe",
20
- "newsletter": "72df60e514a4409ed38df928ef1a2c3ad4593ebaaa436e283c492a91be183769",
21
- "order-status": "c171b7f74e618d7df6f30b5bbbd4c440489a4e0a3783637738c92598b1d681e9",
22
- "pricing-table": "fb5bc12b2ec9e945ee2d0a89c75104a181d0d5b50cff23bf44f9126cbe37bed7",
23
- "product-carousel": "4e79a2f991af8a61865b369669a8da5abb60ef59d356cd1ef69da39b721433de",
24
- "product-detail": "433cd3a66afa9c12f70b85a32c60325fca25f389c0df9a5a5747d6608c56dcb6",
25
- "quote": "5b759a46d13182767cb7ec7000c5522dffebffc7d15b5875b0e6ed10a5d15f2e",
26
- "rich-text": "3335be168a9da49e74975a5d08cb2bc7611e5352ae084f67847978641172ca5e",
27
- "search": "7b3a1246e7f1fde145586bae58727915457a96fc99bf32256ea79739831a1dd3",
28
- "split-content": "0809f4b9293ed1923674e1980985fb036ecd225b8e8ec4daf475c4993f3abd68",
29
- "stats": "a20899c1e2276a2ca9dd506a37509f3184c4c59cac7599638ca0f3d4b5015211",
30
- "tabs": "e0673e483c57e6240488a7c6977daed94b3de3a02b144535e720ac55de6e5c7d",
31
- "team": "d94f9148f05f4891439cf20d92682ec8531528fbdea78df388cd9a63646e3d60",
32
- "testimonials": "941e03c9f08aff291be1819a0aa6ea691471d1482bb86632be0b3c8f3d0f039b",
33
- "timeline": "f289d4b847e8784fb2fcc0c50fceef3438472c94bdb6c866c31a6070fb84765b",
34
- "trust-strip": "ea8ff8d5cdf05e46334badbc818d67115b99cf534a1bea9cf4f8852df35f82fc",
35
- "video-embed": "db48fd9b3442c0195afdfe7adf48b9c7b2a6bb8a824bff7bdf44807a39867fb6",
36
- "wishlist": "b214be4a302e780cfbb2b04f23fa1cd4f6dc5ca5ac65a03ec7a802825a80dfcd"
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({ gatewayUrl: 'https://storybook.invalid', orgId: 'storybook' }),
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
+ }
@@ -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 content locale its **numbers** are
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 same value is the locale every `Intl` format in the theme runs in — `@eldrajs/ui`'s
106
- // `Price`/`CurrencyInput` and, through `useEldraUiLocale()`, `app/storefront/money.ts`. So a
107
- // page served under `/is-IS` prints "2.800 kr." where the same money reads "ISK 2,800" on the
108
- // English one, while the currency itself stays the store's.
109
- nuxtApp.vueApp.provide(LOCALE_KEY, activeLocale);
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
  });