@eldrajs/theme-cli 0.2.4 → 0.2.6

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 (167) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/README.md +6 -0
  3. package/dist/cli.js +8 -2
  4. package/dist/index.d.ts +6 -0
  5. package/dist/index.js +1 -1
  6. package/dist/{validate-FjQ-5_ne.js → validate-CC6Mp5i_.js} +2 -1
  7. package/package.json +3 -3
  8. package/template/.eldra/block-types.d.ts +1 -1
  9. package/template/.eldra/manifest.json +30 -2
  10. package/template/.eldra/previews.json +35 -35
  11. package/template/README.md +3 -1
  12. package/template/app/app.vue +16 -3
  13. package/template/app/assets/main.css +13 -15
  14. package/template/app/components/ui/UiImage.vue +29 -17
  15. package/template/app/components/ui/__tests__/UiImage.spec.ts +24 -15
  16. package/template/app/composables/useStorefront.ts +7 -2
  17. package/template/app/pages/[...slug].vue +1 -1
  18. package/template/app/plugins/eldra-storefront.ts +9 -0
  19. package/template/app/storefront/analytics.ts +15 -7
  20. package/template/app/storefront/cart.ts +228 -51
  21. package/template/app/storefront/commerce.ts +8 -2
  22. package/template/app/storefront/currency.ts +205 -0
  23. package/template/app/storefront/demo.ts +10 -2
  24. package/template/app/storefront/feedback.ts +2 -0
  25. package/template/app/storefront/gateway.ts +153 -35
  26. package/template/app/storefront/money.ts +6 -18
  27. package/template/app/storefront/structuredData.ts +16 -5
  28. package/template/app/storefront/toProductCard.ts +14 -14
  29. package/template/app/storefront/types.ts +13 -0
  30. package/template/app/storefront/volatile.ts +4 -0
  31. package/template/app/utils/seoInput.ts +4 -3
  32. package/template/blocks/announcement-bar/Block.vue +3 -2
  33. package/template/blocks/announcement-bar/__tests__/Block.spec.ts +1 -1
  34. package/template/blocks/announcement-bar/preview.png +0 -0
  35. package/template/blocks/article/Block.vue +3 -4
  36. package/template/blocks/article/preview.png +0 -0
  37. package/template/blocks/article-list/Block.vue +18 -9
  38. package/template/blocks/article-list/preview.png +0 -0
  39. package/template/blocks/breadcrumbs/Block.vue +1 -1
  40. package/template/blocks/breadcrumbs/__tests__/Block.spec.ts +9 -9
  41. package/template/blocks/breadcrumbs/preview.png +0 -0
  42. package/template/blocks/cart/Block.vue +42 -23
  43. package/template/blocks/cart/__tests__/Block.spec.ts +2 -3
  44. package/template/blocks/cart/__tests__/loadFailed.spec.ts +135 -0
  45. package/template/blocks/cart/__tests__/notSold.spec.ts +109 -0
  46. package/template/blocks/cart/parts/CartLines.vue +16 -3
  47. package/template/blocks/cart/parts/CheckoutButton.vue +45 -0
  48. package/template/blocks/cart/parts/LoadFailed.vue +37 -0
  49. package/template/blocks/cart/parts/NotSoldNotice.vue +69 -0
  50. package/template/blocks/cart/parts/ShippingBar.vue +1 -1
  51. package/template/blocks/cart/parts/Summary.vue +14 -30
  52. package/template/blocks/cart/parts/notSold.ts +19 -0
  53. package/template/blocks/cart/preview.png +0 -0
  54. package/template/blocks/collection-grid/Block.vue +26 -16
  55. package/template/blocks/collection-grid/__tests__/Block.spec.ts +26 -14
  56. package/template/blocks/collection-grid/preview.png +0 -0
  57. package/template/blocks/collection-header/Block.vue +5 -5
  58. package/template/blocks/collection-header/preview.png +0 -0
  59. package/template/blocks/contact/Block.vue +1 -1
  60. package/template/blocks/contact/__tests__/Block.spec.ts +2 -2
  61. package/template/blocks/contact/preview.png +0 -0
  62. package/template/blocks/cta/Block.vue +16 -18
  63. package/template/blocks/cta/__tests__/Block.spec.ts +8 -12
  64. package/template/blocks/cta/preview.png +0 -0
  65. package/template/blocks/faq/Block.vue +3 -13
  66. package/template/blocks/faq/__tests__/Block.spec.ts +2 -2
  67. package/template/blocks/faq/preview.png +0 -0
  68. package/template/blocks/feature-grid/Block.vue +1 -1
  69. package/template/blocks/feature-grid/__tests__/Block.spec.ts +1 -1
  70. package/template/blocks/feature-grid/preview.png +0 -0
  71. package/template/blocks/footer/Block.vue +33 -55
  72. package/template/blocks/footer/__tests__/Block.spec.ts +5 -5
  73. package/template/blocks/footer/preview.png +0 -0
  74. package/template/blocks/form/Block.vue +1 -1
  75. package/template/blocks/form/preview.png +0 -0
  76. package/template/blocks/gallery/__tests__/Block.spec.ts +1 -1
  77. package/template/blocks/gallery/preview.png +0 -0
  78. package/template/blocks/hero/Block.vue +8 -11
  79. package/template/blocks/hero/__tests__/Block.spec.ts +9 -7
  80. package/template/blocks/hero/preview.png +0 -0
  81. package/template/blocks/image/Block.vue +4 -4
  82. package/template/blocks/image/__tests__/Block.spec.ts +5 -6
  83. package/template/blocks/image/preview.png +0 -0
  84. package/template/blocks/logo-cloud/__tests__/Block.spec.ts +1 -1
  85. package/template/blocks/logo-cloud/preview.png +0 -0
  86. package/template/blocks/navigation/Block.vue +55 -29
  87. package/template/blocks/navigation/__tests__/Block.spec.ts +22 -20
  88. package/template/blocks/navigation/preview.png +0 -0
  89. package/template/blocks/newsletter/__tests__/Block.spec.ts +1 -1
  90. package/template/blocks/newsletter/preview.png +0 -0
  91. package/template/blocks/order-status/Block.vue +23 -15
  92. package/template/blocks/order-status/__tests__/Block.spec.ts +1 -2
  93. package/template/blocks/order-status/preview.png +0 -0
  94. package/template/blocks/pricing-table/__tests__/Block.spec.ts +1 -1
  95. package/template/blocks/pricing-table/preview.png +0 -0
  96. package/template/blocks/product-carousel/Block.vue +11 -8
  97. package/template/blocks/product-carousel/__tests__/Block.spec.ts +26 -8
  98. package/template/blocks/product-carousel/preview.png +0 -0
  99. package/template/blocks/product-detail/Block.vue +54 -18
  100. package/template/blocks/product-detail/__tests__/Block.spec.ts +79 -2
  101. package/template/blocks/product-detail/parts/Gallery.vue +1 -1
  102. package/template/blocks/product-detail/preview.png +0 -0
  103. package/template/blocks/quote/Block.vue +1 -1
  104. package/template/blocks/quote/__tests__/Block.spec.ts +7 -4
  105. package/template/blocks/quote/preview.png +0 -0
  106. package/template/blocks/rich-text/preview.png +0 -0
  107. package/template/blocks/search/Block.vue +10 -4
  108. package/template/blocks/search/PopularChips.vue +1 -1
  109. package/template/blocks/search/TypeSection.vue +8 -2
  110. package/template/blocks/search/preview.png +0 -0
  111. package/template/blocks/search/results.ts +5 -2
  112. package/template/blocks/split-content/Block.vue +2 -3
  113. package/template/blocks/split-content/__tests__/Block.spec.ts +2 -2
  114. package/template/blocks/split-content/preview.png +0 -0
  115. package/template/blocks/stats/__tests__/Block.spec.ts +1 -1
  116. package/template/blocks/stats/preview.png +0 -0
  117. package/template/blocks/tabs/Block.vue +4 -5
  118. package/template/blocks/tabs/__tests__/Block.spec.ts +2 -2
  119. package/template/blocks/tabs/preview.png +0 -0
  120. package/template/blocks/team/preview.png +0 -0
  121. package/template/blocks/testimonials/Block.vue +10 -9
  122. package/template/blocks/testimonials/__tests__/Block.spec.ts +1 -1
  123. package/template/blocks/testimonials/preview.png +0 -0
  124. package/template/blocks/timeline/__tests__/Block.spec.ts +2 -2
  125. package/template/blocks/timeline/preview.png +0 -0
  126. package/template/blocks/trust-strip/Block.vue +1 -1
  127. package/template/blocks/trust-strip/__tests__/Block.spec.ts +1 -1
  128. package/template/blocks/trust-strip/preview.png +0 -0
  129. package/template/blocks/video-embed/Block.vue +3 -3
  130. package/template/blocks/video-embed/__tests__/Block.spec.ts +1 -1
  131. package/template/blocks/video-embed/preview.png +0 -0
  132. package/template/blocks/wishlist/Block.vue +6 -2
  133. package/template/blocks/wishlist/preview.png +0 -0
  134. package/template/i18n/en-US.json +19 -3
  135. package/template/i18n/is-IS.json +19 -3
  136. package/template/nuxt.config.ts +5 -4
  137. package/template/package.json +1 -0
  138. package/template/stories/pages/article.stories.ts +2 -3
  139. package/template/stories/pages/cart.stories.ts +2 -3
  140. package/template/stories/pages/category.stories.ts +2 -3
  141. package/template/stories/pages/collection.stories.ts +2 -3
  142. package/template/stories/pages/home.stories.ts +2 -3
  143. package/template/stories/pages/product.stories.ts +3 -4
  144. package/template/stories/pages/products.stories.ts +2 -3
  145. package/template/stories/pages/search.stories.ts +2 -3
  146. package/template/stories/pages/wishlist.stories.ts +2 -3
  147. package/template/test/carouselKeyboard.spec.ts +2 -2
  148. package/template/test/carouselRing.browser.spec.ts +2 -2
  149. package/template/test/carouselSlideWidth.browser.spec.ts +9 -9
  150. package/template/test/currencyPicker.spec.ts +66 -0
  151. package/template/test/eldraIcon.spec.ts +1 -1
  152. package/template/test/mainCss.spec.ts +7 -0
  153. package/template/test/pages/article.spec.ts +5 -5
  154. package/template/test/pages/collection.spec.ts +5 -5
  155. package/template/test/pages/hydration.spec.ts +10 -10
  156. package/template/test/prerenderRefresh.browser.spec.ts +1 -1
  157. package/template/test/seoInput.spec.ts +22 -0
  158. package/template/test/storefront/analytics.spec.ts +15 -0
  159. package/template/test/storefront/cart.spec.ts +4 -4
  160. package/template/test/storefront/currency.spec.ts +549 -0
  161. package/template/test/storefront/currencyStore.spec.ts +845 -0
  162. package/template/test/storefront/gateway.spec.ts +22 -0
  163. package/template/test/storefront/money.spec.ts +2 -8
  164. package/template/test/storefront/structuredData.spec.ts +45 -0
  165. package/template/test/storefront/toProductCard.spec.ts +1 -1
  166. package/template/test/storefront/volatile.spec.ts +11 -0
  167. package/template/test/support/mountPage.ts +2 -3
@@ -76,7 +76,7 @@ const { t } = useI18n();
76
76
  const isEditing = useEditing();
77
77
  const headingId = `product-carousel-heading-${useUiId()}`;
78
78
  /** The h2 recipe, also applied to the heading's own link so `Link`'s standalone size and weight do
79
- * not shrink the title (tailwind-merge keeps the later font-size/weight). */
79
+ * not shrink the title (an app utility outranks the kit's `eldra:` classes by cascade layer). */
80
80
  const HEADING_CLASSES =
81
81
  'font-heading @tablet:text-h2 text-[1.625rem] leading-[1.15] font-bold tracking-[-0.015em]';
82
82
 
@@ -186,7 +186,8 @@ const hasData = computed(() => activeResult.value.data.value !== null);
186
186
  const showSkeletons = computed(() => pending.value && !hasData.value);
187
187
  const { any: cardsRevalidating, refreshing } = useRevalidating({
188
188
  keys: () => activeResult.value.revalidating.value,
189
- refreshing: () => activeResult.value.loading.value && hasData.value,
189
+ refreshing: () =>
190
+ (activeResult.value.loading.value && hasData.value) || storefront.currency.pending.value,
190
191
  });
191
192
 
192
193
  /**
@@ -216,10 +217,12 @@ const cappedProducts = computed(() => products.value.slice(0, limit.value));
216
217
  * "fewer than 2 products" floor or leave the carousel controls claiming a slide that isn't there.
217
218
  */
218
219
  const money = useMoney();
220
+ const shopperCurrency = useStorefront().currency.active;
219
221
  const cards = computed(() =>
220
222
  toProductCardEntries(cappedProducts.value, {
221
223
  ratio: cardRatio.value,
222
224
  minorUnits: money.minor,
225
+ shopperCurrency: shopperCurrency.value,
223
226
  revalidating: cardsRevalidating.value,
224
227
  })
225
228
  );
@@ -279,11 +282,11 @@ const cardRatio = computed(() => (isRecentlyViewed.value ? '1x1' : '4x5'));
279
282
  * `min-w-56`, which is right in a grid whose columns are sized for it and wrong in a slide whose
280
283
  * width is `(track − gaps) / perView`: at six per view on a 1228px track a slide is 189px, so a
281
284
  * 224px card ran 35px past its slide, swallowed the 16px gap and overlapped the next card — the
282
- * operator saw the recently-viewed row drawn with no space between its tiles. `min-w-0` wins over
283
- * the component's own `min-w-56` through `partClass`'s tailwind-merge, so the card fills exactly
285
+ * operator saw the recently-viewed row drawn with no space between its tiles. `min-w-0` (an app
286
+ * utility) outranks the component's own `eldra:min-w-56` by cascade layer, so the card fills exactly
284
287
  * its slide on every variant and at every container width.
285
288
  */
286
- const CARD_CLASSES = { root: 'min-w-0' } as const;
289
+ const CARD_CLASS = 'min-w-0';
287
290
 
288
291
  /**
289
292
  * While pending, `Carousel`'s own accessible name announces the loading state instead of
@@ -418,7 +421,7 @@ const showBlock = computed(() =>
418
421
  variant="standalone"
419
422
  arrow
420
423
  :aria-label="`${heading} — ${data.viewAllLabel}${t('productCarousel.viewAllContext')}`"
421
- :classes="{ root: `${HEADING_CLASSES} text-inherit` }"
424
+ :class="`${HEADING_CLASSES} text-inherit`"
422
425
  >
423
426
  {{ heading }}
424
427
  </Link>
@@ -440,7 +443,7 @@ const showBlock = computed(() =>
440
443
  <ProductCard
441
444
  :product="entry.product"
442
445
  :ratio="cardRatio"
443
- :classes="CARD_CLASSES"
446
+ :class="CARD_CLASS"
444
447
  :show-swatches="!isRecentlyViewed && showSwatchesField"
445
448
  :show-rating="!isRecentlyViewed"
446
449
  :quick-add="false"
@@ -448,7 +451,7 @@ const showBlock = computed(() =>
448
451
  :revalidating="entry.revalidating"
449
452
  :announce="false"
450
453
  :link-as="entry.internal ? EldraRouterLink : undefined"
451
- :currency="currency"
454
+ :currency="entry.currency ?? currency"
452
455
  :locale="locale"
453
456
  />
454
457
  </div>
@@ -760,7 +760,7 @@ describe('product-carousel block', () => {
760
760
  const { storefront, revalidating } = refreshableSource();
761
761
  const wrapper = mountBlock(mock, { storefront });
762
762
  await flushPromises();
763
- const region = () => wrapper.get('p.sr-only[role="status"]');
763
+ const region = () => wrapper.get('p.eldra\\:sr-only[role="status"]');
764
764
 
765
765
  // Mounted and empty first: a live region that arrives already holding its message is
766
766
  // announced unreliably, which is what a prerendered page would produce if the block read
@@ -771,7 +771,7 @@ describe('product-carousel block', () => {
771
771
  await flushPromises();
772
772
 
773
773
  expect(region().text()).toBe(enUS.storefront.updatingValues);
774
- expect(wrapper.findAll('p.sr-only[role="status"]')).toHaveLength(1);
774
+ expect(wrapper.findAll('p.eldra\\:sr-only[role="status"]')).toHaveLength(1);
775
775
  // `announce: false` on every card — the per-value regions are gone, not merely empty.
776
776
  expect(wrapper.findAll('[data-part="srStatus"]')).toHaveLength(0);
777
777
  expect(
@@ -794,12 +794,14 @@ describe('product-carousel block', () => {
794
794
  const wrapper = mountBlock(mock, { storefront });
795
795
 
796
796
  expect(wrapper.find('[data-part="spinner"]').exists()).toBe(false);
797
- expect(wrapper.get('p.sr-only[role="status"]').text()).toBe('');
797
+ expect(wrapper.get('p.eldra\\:sr-only[role="status"]').text()).toBe('');
798
798
 
799
799
  await flushPromises();
800
800
 
801
801
  expect(wrapper.find('[data-part="spinner"]').exists()).toBe(true);
802
- expect(wrapper.get('p.sr-only[role="status"]').text()).toBe(enUS.storefront.updatingValues);
802
+ expect(wrapper.get('p.eldra\\:sr-only[role="status"]').text()).toBe(
803
+ enUS.storefront.updatingValues
804
+ );
803
805
  });
804
806
 
805
807
  it('never draws a skeleton over cards the visitor can already see', async () => {
@@ -848,10 +850,16 @@ describe('product-carousel block', () => {
848
850
 
849
851
  /**
850
852
  * Every utility rule the build emits, in source order, with the container query it sits under.
851
- * Only `@layer utilities`: the same stylesheet carries a preflight `padding: 0` and the
853
+ * Only `@layer components` (the package's prebuilt, `eldra:`-prefixed rules) and `@layer
854
+ * utilities` (this theme's own): the same stylesheet carries a preflight `padding: 0` and the
852
855
  * rich-text `padding-left` of a blockquote, and neither is on this element.
853
856
  */
854
- type Rule = { condition: string; declarations: Array<[string, string]> };
857
+ type Rule = {
858
+ condition: string;
859
+ layer: string;
860
+ selector: string;
861
+ declarations: Array<[string, string]>;
862
+ };
855
863
 
856
864
  function flatten(css: string, condition: string, layer: string, out: Rule[]): void {
857
865
  let i = 0;
@@ -875,9 +883,11 @@ describe('product-carousel block', () => {
875
883
  namedLayer ? namedLayer[1]! : layer,
876
884
  out
877
885
  );
878
- } else if (layer === 'utilities') {
886
+ } else if (layer === 'utilities' || layer === 'components') {
879
887
  out.push({
880
888
  condition,
889
+ layer,
890
+ selector: head,
881
891
  declarations: body
882
892
  .split(';')
883
893
  .map((part) => part.trim())
@@ -915,7 +925,15 @@ describe('product-carousel block', () => {
915
925
  });
916
926
  const rules: Rule[] = [];
917
927
  flatten(compiler.build(classes), '', '', rules);
918
- return rules;
928
+ // `components.css` ships whole, whatever the candidates, so only its rules for this
929
+ // element's own classes apply; and every utility outranks every component rule by layer.
930
+ const own = new Set(classes.map((name) => `.${name}`));
931
+ return [
932
+ ...rules.filter(
933
+ (rule) => rule.layer === 'components' && own.has(rule.selector.replace(/\\(.)/g, '$1'))
934
+ ),
935
+ ...rules.filter((rule) => rule.layer === 'utilities'),
936
+ ];
919
937
  }
920
938
 
921
939
  /** `max(bleed, reach)` can only be at least the reach; the bare reach is exactly it. */
@@ -163,7 +163,8 @@ const {
163
163
  refreshing,
164
164
  } = useRevalidating({
165
165
  keys: () => productResult.revalidating.value,
166
- refreshing: () => productResult.loading.value && product.value !== null,
166
+ refreshing: () =>
167
+ (productResult.loading.value && product.value !== null) || storefront.currency.pending.value,
167
168
  });
168
169
 
169
170
  /**
@@ -257,9 +258,17 @@ const showRating = computed(
257
258
  const money = useMoney();
258
259
 
259
260
  const formattedPrice = computed(() =>
260
- product.value === null ? '' : money.format(product.value.price.amount)
261
+ product.value === null
262
+ ? ''
263
+ : money.format(product.value.price.amount, product.value.price.currency)
261
264
  );
262
265
 
266
+ /** No price in the visitor's currency: shown, but not for sale until they shop in the store's own. */
267
+ const notSold = computed(() => product.value?.price.soldInCurrency === false);
268
+ const shopperCurrency = computed(() => storefront.currency.active.value ?? '');
269
+ const baseCurrency = computed(() => storefront.currency.base ?? '');
270
+ const cartWillSwitch = computed(() => notSold.value && storefront.cart.lines.value.length > 0);
271
+
263
272
  /** Spec States, Sale row: 'The saving badge ("Save $32") is calculated from the two prices, never
264
273
  * typed in.' Only a real sale counts — a `compareAt` at or below the current price is ignored, the
265
274
  * same rule `Price`'s own sale state applies. */
@@ -268,7 +277,7 @@ const saving = computed<string | null>(() => {
268
277
  if (price === undefined) return null;
269
278
  const compareAt = price.compareAt ?? null;
270
279
  if (compareAt === null || compareAt <= price.amount) return null;
271
- return money.format(roundMoney(compareAt - price.amount));
280
+ return money.format(roundMoney(compareAt - price.amount), price.currency);
272
281
  });
273
282
  const onSale = computed(() => saving.value !== null);
274
283
 
@@ -380,9 +389,9 @@ const isBackorder = computed(() => stockLine.value.state === 'backorder');
380
389
 
381
390
  /** Spec States, Back-order row: `warning` with the clock icon. `StockBadge`'s own `preorder` level
382
391
  * draws the clock in `muted` (it serves a quieter product-card context too), so the block asks for
383
- * the spec's colour through the component's sanctioned per-part `classes`, never by patching it. */
384
- const stockClasses = computed(() =>
385
- isBackorder.value ? { root: 'text-warning font-semibold' } : { root: 'font-semibold' }
392
+ * the spec's colour through its `class`, never by patching it. */
393
+ const stockClass = computed(() =>
394
+ isBackorder.value ? 'text-warning font-semibold' : 'font-semibold'
386
395
  );
387
396
 
388
397
  /* ------------------------------------------------------------------------- */
@@ -413,9 +422,12 @@ watch(
413
422
  * It costs nothing: before mount there is no cart request a visitor could have started, so the
414
423
  * gated value and the real one only ever differ on the render that must not use the real one.
415
424
  */
416
- const cartBusy = computed(() => mounted.value && storefront.cart.pending.value);
425
+ const cartBusy = computed(
426
+ () => mounted.value && (storefront.cart.pending.value || storefront.currency.pending.value)
427
+ );
417
428
 
418
429
  const addToCartLabel = computed(() => {
430
+ if (notSold.value) return t('currency.shopIn', { currency: baseCurrency.value });
419
431
  if (soldOut.value) return t('product.notifyMe');
420
432
  if (isBackorder.value) return t('product.backorder');
421
433
  return t('product.addToCart', { price: formattedPrice.value });
@@ -501,6 +513,13 @@ watch(
501
513
  * refusal for stock flips its own stock line to sold out.
502
514
  */
503
515
  async function primaryAction(): Promise<void> {
516
+ if (notSold.value) {
517
+ // Already in the store currency (its product read failed): read the product again.
518
+ if (storefront.currency.active.value === storefront.currency.base) void productResult.refresh();
519
+ else storefront.currency.chooseBase();
520
+ return;
521
+ }
522
+ if (storefront.currency.pending.value) return;
504
523
  if (soldOut.value) {
505
524
  notifyOpen.value = true;
506
525
  return;
@@ -613,7 +632,7 @@ function tabValue(index: number): string {
613
632
  spacing="none"
614
633
  :labelled-by="titleId"
615
634
  :aria-busy="refreshing ? 'true' : undefined"
616
- :classes="{ root: SECTION_SPACING }"
635
+ :class="SECTION_SPACING"
617
636
  >
618
637
  <Container width="content">
619
638
  <div
@@ -651,15 +670,22 @@ function tabValue(index: number): string {
651
670
  <h1 :id="titleId" :class="TITLE_CLASS">{{ product.title }}</h1>
652
671
 
653
672
  <div class="mt-2 flex flex-wrap items-center gap-x-4 gap-y-2">
673
+ <p v-if="notSold" class="text-text" data-eldra-not-sold>
674
+ {{ t('currency.notSoldInLong', { currency: shopperCurrency }) }}
675
+ </p>
654
676
  <Price
655
- :amount="money.minor(product.price.amount)"
677
+ v-else
678
+ :amount="money.minor(product.price.amount, product.price.currency)"
656
679
  :compare-at="
657
- product.price.compareAt == null ? null : money.minor(product.price.compareAt)
680
+ product.price.compareAt == null
681
+ ? null
682
+ : money.minor(product.price.compareAt, product.price.currency)
658
683
  "
684
+ :currency="product.price.currency"
659
685
  :revalidating="priceRevalidating"
660
686
  />
661
687
  <Badge
662
- v-if="saving"
688
+ v-if="saving && !notSold"
663
689
  variant="sale"
664
690
  :label="t('product.saving', { amount: saving })"
665
691
  />
@@ -726,7 +752,7 @@ function tabValue(index: number): string {
726
752
  :level="stockLine.level"
727
753
  :message="t(stockLine.key, stockLine.params)"
728
754
  :revalidating="stockRevalidating"
729
- :classes="stockClasses"
755
+ :class="stockClass"
730
756
  />
731
757
  <span v-if="stockLine.noteKey" class="text-muted mt-1 block pl-6 text-[0.875rem]">{{
732
758
  t(stockLine.noteKey)
@@ -734,9 +760,9 @@ function tabValue(index: number): string {
734
760
  </p>
735
761
 
736
762
  <FieldWrapper
737
- v-if="showQuantity && !soldOut"
763
+ v-if="showQuantity && !soldOut && !notSold"
738
764
  :label="t('product.quantity')"
739
- :classes="{ root: 'gap-2' }"
765
+ class="gap-2"
740
766
  >
741
767
  <QuantityStepper
742
768
  v-model="quantity"
@@ -777,6 +803,9 @@ function tabValue(index: number): string {
777
803
  </template>
778
804
  </Button>
779
805
  </div>
806
+ <p v-if="cartWillSwitch" class="text-muted text-body-sm -mt-2">
807
+ {{ t('currency.cartWillSwitch', { currency: baseCurrency }) }}
808
+ </p>
780
809
  </form>
781
810
 
782
811
  <ul
@@ -822,7 +851,7 @@ function tabValue(index: number): string {
822
851
  </div>
823
852
 
824
853
  <StickyBuyBar
825
- v-if="stickyBarEnabled"
854
+ v-if="stickyBarEnabled && !notSold"
826
855
  :target="addToCartTarget"
827
856
  :title="product.title"
828
857
  :meta="
@@ -849,7 +878,14 @@ function tabValue(index: number): string {
849
878
  @submit="submitNotify"
850
879
  >
851
880
  <FieldWrapper :label="t('product.notifyEmail')" :error="notifyError ?? undefined">
852
- <Input v-model="notifyEmail" type="email" name="email" autocomplete="email" required />
881
+ <Input
882
+ v-model="notifyEmail"
883
+ type="email"
884
+ name="email"
885
+ autocomplete="email"
886
+ required
887
+ autofocus
888
+ />
853
889
  </FieldWrapper>
854
890
  <template #actions>
855
891
  <Button type="submit" variant="primary" :label="t('product.notifySubmit')">
@@ -861,7 +897,7 @@ function tabValue(index: number): string {
861
897
  </Container>
862
898
  </Section>
863
899
 
864
- <Section v-else-if="showStatus" spacing="none" :classes="{ root: SECTION_SPACING }">
900
+ <Section v-else-if="showStatus" spacing="none" :class="SECTION_SPACING">
865
901
  <Container width="content">
866
902
  <p role="status" class="text-muted">
867
903
  {{ productResult.error.value ? t('storefront.error') : t('storefront.loading') }}
@@ -872,7 +908,7 @@ function tabValue(index: number): string {
872
908
  <!-- The read answered, and the answer was "there is no such product". Said plainly, before the
873
909
  editor hint below, because on a live page this is what a visitor who followed an old link
874
910
  sees and the hint is not for them. -->
875
- <Section v-else-if="notFound" spacing="none" :classes="{ root: SECTION_SPACING }">
911
+ <Section v-else-if="notFound" spacing="none" :class="SECTION_SPACING">
876
912
  <Container width="content">
877
913
  <p role="status" class="text-muted">{{ t('storefront.notFound') }}</p>
878
914
  </Container>
@@ -4,7 +4,7 @@ import { computed, defineComponent, h, nextTick, ref } from 'vue';
4
4
  import { ELDRA_KEY, type EldraLocaleState } from '@eldrajs/theme-vue';
5
5
  import { EldraHttpError } from '@eldrajs/sdk';
6
6
  import { useToast, type ToastAction } from '@eldrajs/ui';
7
- import { afterEach, describe, expect, it } from 'vitest';
7
+ import { afterEach, describe, expect, it, vi } from 'vitest';
8
8
  import { axe } from '../../../test/support/axe';
9
9
  import { mountOptions } from '../../../test/support/mountBlock';
10
10
  import { createDemoStorefront } from '../../../app/storefront/demo';
@@ -1046,6 +1046,83 @@ describe('product-detail block', () => {
1046
1046
  expect(storefront.cart.lines.value[0]!.quantity).toBe(2);
1047
1047
  });
1048
1048
 
1049
+ it('offers the store currency in place of adding a product with no price in the chosen one', async () => {
1050
+ const storefront = storefrontWith({
1051
+ price: { amount: 96, compareAt: null, currency: 'USD', soldInCurrency: false },
1052
+ });
1053
+ storefront.currency.offered.value = ['USD', 'EUR'];
1054
+ storefront.currency.started.value = true;
1055
+ storefront.currency.choose('EUR');
1056
+ await vi.waitFor(() => expect(storefront.currency.active.value).toBe('EUR'));
1057
+ const wrapper = await mountReady(mock, { storefront });
1058
+
1059
+ expect(wrapper.get('[data-eldra-not-sold]').text()).toBe('Not available in EUR.');
1060
+ expect(addToCart(wrapper).attributes('disabled')).toBeUndefined();
1061
+ expect(addToCart(wrapper).text()).toBe('Shop in USD');
1062
+ expect(wrapper.find('[data-part="quantity"]').exists()).toBe(false);
1063
+ expect(await axe(wrapper.element)).toHaveNoViolations();
1064
+
1065
+ await wrapper.get('form').trigger('submit');
1066
+ await flushPromises();
1067
+ expect(storefront.cart.lines.value).toHaveLength(0);
1068
+ expect(storefront.currency.active.value).toBe('USD');
1069
+ });
1070
+
1071
+ it('4662896775: reads the product again when it is already in the store currency', async () => {
1072
+ const storefront = storefrontWith({
1073
+ price: { amount: 96, compareAt: null, currency: 'USD', soldInCurrency: false },
1074
+ });
1075
+ const refreshes: number[] = [];
1076
+ const product = storefront.catalog.product;
1077
+ storefront.catalog.product = (handle) => {
1078
+ const result = product(handle);
1079
+ return {
1080
+ ...result,
1081
+ refresh: async () => {
1082
+ refreshes.push(1);
1083
+ },
1084
+ };
1085
+ };
1086
+ storefront.currency.started.value = true;
1087
+ const wrapper = await mountReady(mock, { storefront });
1088
+ expect(storefront.currency.active.value).toBe('USD');
1089
+ await wrapper.get('form').trigger('submit');
1090
+ await flushPromises();
1091
+ expect(refreshes).toHaveLength(1);
1092
+ });
1093
+
1094
+ it('says the cart will switch when there is one', async () => {
1095
+ const storefront = storefrontWith({
1096
+ price: { amount: 96, compareAt: null, currency: 'USD', soldInCurrency: false },
1097
+ });
1098
+ storefront.currency.offered.value = ['USD', 'EUR'];
1099
+ storefront.currency.started.value = true;
1100
+ storefront.currency.choose('EUR');
1101
+ await vi.waitFor(() => expect(storefront.currency.active.value).toBe('EUR'));
1102
+ await storefront.cart.add({ productId: 'p', variantId: 'v', quantity: 1 });
1103
+ const wrapper = await mountReady(mock, { storefront });
1104
+ expect(wrapper.text()).toContain('Your cart will switch to USD.');
1105
+ });
1106
+
1107
+ it("holds Add to cart while the visitor's currency is still being applied", async () => {
1108
+ const storefront = storefrontWith();
1109
+ storefront.currency.offered.value = ['USD', 'EUR'];
1110
+ const wrapper = await mountReady(mock, { storefront });
1111
+ expect(storefront.currency.pending.value).toBe(true);
1112
+ await wrapper.get('form').trigger('submit');
1113
+ await flushPromises();
1114
+ expect(storefront.cart.lines.value).toHaveLength(0);
1115
+ expect(addToCart(wrapper).attributes('aria-busy')).toBe('true');
1116
+ });
1117
+
1118
+ it('formats the price in the currency it carries', async () => {
1119
+ const storefront = storefrontWith({
1120
+ price: { amount: 19.9, compareAt: null, currency: 'EUR' },
1121
+ });
1122
+ const wrapper = await mountReady(mock, { storefront });
1123
+ expect(addToCart(wrapper).text()).toContain('€19.90');
1124
+ });
1125
+
1049
1126
  it('toggles the wishlist button aria-pressed', async () => {
1050
1127
  const wrapper = await mountReady(mock);
1051
1128
  const button = wrapper.get('button[aria-pressed]');
@@ -1285,7 +1362,7 @@ describe('product-detail block', () => {
1285
1362
  expect(bar.text()).toContain('Oat / XS · $96.00');
1286
1363
  // The quick-add button is the one control that exists only below 48rem, where primary
1287
1364
  // actions are at least 2.75rem tall: it takes the package's `lg` size.
1288
- expect(bar.get('button[type="button"]').classes()).toContain('control-h-lg');
1365
+ expect(bar.get('button[type="button"]').classes()).toContain('eldra:control-h-lg');
1289
1366
  expect(await axe(wrapper.element)).toHaveNoViolations();
1290
1367
 
1291
1368
  observers[0]!([{ isIntersecting: true }]);
@@ -127,7 +127,7 @@ const THUMBNAIL_IDLE =
127
127
  icon-only
128
128
  variant="outline"
129
129
  aria-haspopup="dialog"
130
- :classes="{ container: 'size-11 shadow-sm' }"
130
+ class="size-11 shadow-sm"
131
131
  :label="t('product.zoom', { index: current + 1, count })"
132
132
  @click="lightboxOpen = true"
133
133
  >
@@ -32,7 +32,7 @@
32
32
  * (`text-text` on `none`/`surface`/`surface-strong`, `text-primary-contrast`/`text-accent-contrast`
33
33
  * on the two inverting grounds), and that is a normal inherited CSS `color` — so the quote paragraph
34
34
  * and the `<cite>` name carry no colour class of their own and simply inherit whichever one is
35
- * right. `Link` already inverts its own `muted` tone through its `group-data-[section=…]/section:`
35
+ * right. `Link` already inverts its own `muted` tone through its `section-primary:`/`section-accent:`
36
36
  * classes, so the role line needs no extra handling when it is a link. Only the two parts with no
37
37
  * such built-in mechanism branch by hand: the quote mark (`accent` by default, since an `accent`
38
38
  * mark would vanish on an `accent` ground) and the plain-text role line for when there is no
@@ -70,7 +70,7 @@ describe('quote block', () => {
70
70
  it('the block root is a labelled <section> that measures its own width (@container)', () => {
71
71
  const wrapper = mountBlock(mock);
72
72
  const section = wrapper.get('section');
73
- expect(section.classes()).toContain('@container');
73
+ expect(section.classes()).toContain('eldra:@container');
74
74
  expect(section.attributes('aria-labelledby')).toBeTruthy();
75
75
  });
76
76
 
@@ -79,7 +79,7 @@ describe('quote block', () => {
79
79
  const heading = wrapper.get(`#${wrapper.get('section').attributes('aria-labelledby')}`);
80
80
  expect(heading.element.tagName).toBe('H2');
81
81
  expect(heading.text()).toBe(`Quote from ${mock.name}`);
82
- expect(heading.classes()).toContain('sr-only');
82
+ expect(heading.classes()).toContain('eldra:sr-only');
83
83
 
84
84
  const figure = wrapper.get('figure');
85
85
  const blockquote = figure.get('blockquote');
@@ -150,7 +150,7 @@ describe('quote block', () => {
150
150
  expect(link.text()).toBe(mock.role);
151
151
  expect(link.attributes('href')).toBe(sourceLinkHref);
152
152
  expect(link.attributes('aria-label')).toBe(mock.sourceLinkLabel);
153
- expect(link.classes()).toContain('eldra-focus');
153
+ expect(link.classes()).toContain('eldra:eldra-focus');
154
154
  const focusable = Array.from(wrapper.element.querySelectorAll('a, button, input, [tabindex]'));
155
155
  expect(focusable).toContain(link.element);
156
156
  });
@@ -167,7 +167,9 @@ describe('quote block', () => {
167
167
  it('has no italic class anywhere in the block', () => {
168
168
  const wrapper = mountBlock(withMedia);
169
169
  for (const element of wrapper.element.querySelectorAll('*')) {
170
- expect(Array.from(element.classList)).not.toContain('italic');
170
+ expect(Array.from(element.classList, (token) => token.replace(/^eldra:/, ''))).not.toContain(
171
+ 'italic'
172
+ );
171
173
  }
172
174
  });
173
175
 
@@ -259,6 +261,7 @@ describe('quote block', () => {
259
261
  });
260
262
  const link = wrapper.get('figcaption a');
261
263
  expect(link.classes()).not.toContain('block');
264
+ expect(link.classes()).not.toContain('eldra:block');
262
265
  expect(link.element.parentElement?.tagName).toBe('P');
263
266
  expect(link.text()).toBe(mock.role);
264
267
  });
Binary file
@@ -275,6 +275,7 @@ const isLoading = computed(() => response.value === null && searchResult.loading
275
275
  /** The store's currency and the page's locale, for the suggestion prices below and the
276
276
  * `<ProductCard>`s the no-results state renders (`money.minor`). */
277
277
  const money = useMoney();
278
+ const shopperCurrency = useStorefront().currency.active;
278
279
 
279
280
  const barResults = computed(() =>
280
281
  toSearchBarResults(response.value, suggestionsPerGroup.value, money.format)
@@ -289,7 +290,11 @@ const barResults = computed(() =>
289
290
  * would head a tab "Products (3)" over a grid showing fewer, or, when the pricing read failed, none.
290
291
  */
291
292
  const productCards = computed(() =>
292
- toProductCardEntries(response.value?.products ?? [], { ratio: '4x5', minorUnits: money.minor })
293
+ toProductCardEntries(response.value?.products ?? [], {
294
+ ratio: '4x5',
295
+ minorUnits: money.minor,
296
+ shopperCurrency: shopperCurrency.value,
297
+ })
293
298
  );
294
299
 
295
300
  function countFor(type: ResultTypeId): number {
@@ -380,6 +385,7 @@ const noResultsProducts = computed(() =>
380
385
  toProductCardEntries((noResultsCollection.data.value?.items ?? []).slice(0, 4), {
381
386
  ratio: '4x5',
382
387
  minorUnits: money.minor,
388
+ shopperCurrency: shopperCurrency.value,
383
389
  })
384
390
  );
385
391
  const hasNoResultsProducts = computed(() => noResultsProducts.value.length > 0);
@@ -398,7 +404,7 @@ const sectionAriaLabel = computed(() =>
398
404
  /** Spec "Search results page" → Container/Section: "2rem top, `section-md` bottom" — the shared
399
405
  * `sm`/`md`/`lg` scale is symmetric, so `spacing="none"` on `Section` and the padding is written
400
406
  * here, the same pattern `collection-header`'s/`footer`'s own asymmetric padding uses. */
401
- const sectionClasses = { root: 'pt-8 pb-[var(--eldra-section-md)]' };
407
+ const sectionClass = 'pt-8 pb-[var(--eldra-section-md)]';
402
408
 
403
409
  const headingClass =
404
410
  'font-heading text-[1.625rem] leading-[1.15] font-bold tracking-[-0.015em] break-words ' +
@@ -408,7 +414,7 @@ const headingClass =
408
414
  <template>
409
415
  <Section
410
416
  spacing="none"
411
- :classes="sectionClasses"
417
+ :class="sectionClass"
412
418
  :labelled-by="sectionLabelledBy"
413
419
  :aria-label="sectionAriaLabel"
414
420
  >
@@ -500,7 +506,7 @@ const headingClass =
500
506
  ratio="4x5"
501
507
  :heading-level="2"
502
508
  :link-as="entry.internal ? EldraRouterLink : undefined"
503
- :currency="currency"
509
+ :currency="entry.currency ?? currency"
504
510
  :locale="locale"
505
511
  />
506
512
  </div>
@@ -31,7 +31,7 @@ const CHIP_CLASS =
31
31
  <p class="text-body-sm text-text font-semibold">{{ heading }}</p>
32
32
  <ul class="flex flex-wrap gap-2">
33
33
  <li v-for="item in items" :key="item.label">
34
- <Link :href="item.href" :as="linkAs" :underline="false" :classes="{ root: CHIP_CLASS }">
34
+ <Link :href="item.href" :as="linkAs" :underline="false" :class="CHIP_CLASS">
35
35
  <EldraIcon name="search" size="sm" />
36
36
  {{ item.label }}
37
37
  </Link>
@@ -13,6 +13,7 @@ import EldraRouterLink from '../../app/components/EldraRouterLink.vue';
13
13
  import { isInternalHref, safeHref } from '../../app/utils/links';
14
14
  import { toProductCardEntries } from '../../app/storefront/toProductCard';
15
15
  import { useMoney } from '../../app/storefront/money';
16
+ import { useStorefront } from '../../app/composables/useStorefront';
16
17
  import type { StorefrontSearchProduct, StorefrontSearchResponse } from '../../app/storefront/types';
17
18
 
18
19
  type ResultTypeId = 'products' | 'journal' | 'pages';
@@ -52,8 +53,13 @@ const props = defineProps<{
52
53
 
53
54
  /** See the `products` prop: sanitised, unusable rows dropped, `internal` per card. */
54
55
  const money = useMoney();
56
+ const shopperCurrency = useStorefront().currency.active;
55
57
  const productCards = computed(() =>
56
- toProductCardEntries(props.products, { ratio: '4x5', minorUnits: money.minor })
58
+ toProductCardEntries(props.products, {
59
+ ratio: '4x5',
60
+ minorUnits: money.minor,
61
+ shopperCurrency: shopperCurrency.value,
62
+ })
57
63
  );
58
64
 
59
65
  /** The journal rows that have a usable link, with the sanitised href and whether it routes. */
@@ -97,7 +103,7 @@ const JOURNAL_GRID_CLASS = 'grid grid-cols-1 gap-6 @tablet:grid-cols-3 @tablet:g
97
103
  ratio="4x5"
98
104
  :heading-level="3"
99
105
  :link-as="entry.internal ? EldraRouterLink : undefined"
100
- :currency="currency"
106
+ :currency="entry.currency ?? currency"
101
107
  :locale="locale"
102
108
  />
103
109
  </div>
Binary file
@@ -45,7 +45,7 @@ function rankProducts(products: StorefrontSearchProduct[]): StorefrontSearchProd
45
45
  export function toSearchBarResults(
46
46
  response: StorefrontSearchResponse | null,
47
47
  suggestionsPerGroup: number,
48
- formatPrice: (amount: number) => string
48
+ formatPrice: (amount: number, currency?: string) => string
49
49
  ): SearchResults | undefined {
50
50
  if (response === null) return undefined;
51
51
 
@@ -58,7 +58,10 @@ export function toSearchBarResults(
58
58
  // `SearchResultItem.price` is optional, so a product this storefront could not price keeps its
59
59
  // row and loses only the price. Formatting a `null` as a number would print the store's own
60
60
  // "$0.00" — a real price, and the wrong one (`StorefrontSearchProduct`).
61
- price: product.price === null ? undefined : formatPrice(product.price.amount),
61
+ price:
62
+ product.price === null || product.price.soldInCurrency === false
63
+ ? undefined
64
+ : formatPrice(product.price.amount, product.price.currency),
62
65
  image: product.featuredImage?.src,
63
66
  imageAlt: product.featuredImage?.alt,
64
67
  }));