@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.
Files changed (169) hide show
  1. package/CHANGELOG.md +12 -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 +51 -17
  45. package/template/blocks/collection-header/__tests__/Block.spec.ts +80 -4
  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 +405 -159
  76. package/template/blocks/navigation/__tests__/Block.spec.ts +816 -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/previewParity.browser.spec.ts +36 -2
  159. package/template/test/priceTokens.spec.ts +309 -0
  160. package/template/test/regionalFormat.spec.ts +80 -0
  161. package/template/test/starter.spec.ts +23 -7
  162. package/template/test/storefront/demo.spec.ts +19 -18
  163. package/template/test/storefront/toProductCard.spec.ts +17 -2
  164. package/template/test/structuredData.generate.spec.ts +4 -2
  165. package/template/test/support/mockGateway.ts +21 -1
  166. package/template/test/support/mountBlock.ts +25 -4
  167. package/template/test/support/priceTokens.ts +20 -0
  168. package/template/test/uiMessagesPlugin.spec.ts +34 -1
  169. 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 { createDemoStorefront } from '../../app/storefront/demo';
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({ gatewayUrl: 'https://vitest.invalid', orgId: 'vitest' });
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
- { href: typeof props.to === 'string' ? props.to : JSON.stringify(props.to) },
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 { CURRENCY_KEY, LOCALE_KEY, MESSAGES_KEY } from '@eldrajs/ui';
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
  });
@@ -108,8 +108,8 @@
108
108
  "label": "Narrow",
109
109
  "maxWidth": "40rem",
110
110
  "gutter": {
111
- "normal": "2rem",
112
- "tablet": "1.5rem",
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": "2rem",
122
- "tablet": "1.5rem",
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": "2rem",
132
- "tablet": "1.5rem",
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": "2rem",
142
- "tablet": "1.5rem",
141
+ "normal": "1rem",
142
+ "tablet": "1rem",
143
143
  "mobile": "1rem"
144
144
  },
145
145
  "allowSiteOverride": true