@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
@@ -608,6 +608,21 @@ describe('product-detail block', () => {
608
608
  });
609
609
  });
610
610
 
611
+ it('fills each tile with its photo: 5:4 for the wide one, 4:5 for the halves', async () => {
612
+ const wrapper = await mountReady(mock);
613
+ const [wide, half] = tiles(wrapper);
614
+ expect(wide!.classes()).toContain('aspect-[5/4]');
615
+ expect(half!.classes()).toContain('aspect-[4/5]');
616
+ // The tile owns the ratio and the picture is stretched over it — never a picture at its own
617
+ // intrinsic ratio inside a box of another one (the 3:2 photo in a 5:4 tile, with a band of
618
+ // empty surface under it).
619
+ for (const tile of [wide!, half!]) {
620
+ const root = tile.element.firstElementChild!;
621
+ expect(root.className).toMatch(/\babsolute\b/);
622
+ expect(root.className).toMatch(/\binset-0\b/);
623
+ }
624
+ });
625
+
611
626
  it('lays two images side by side, and leads with a wide one from three', async () => {
612
627
  const spans = async (count: number) => {
613
628
  const images = Array.from({ length: count }, (_, index) => ({
@@ -1024,6 +1039,28 @@ describe('product-detail block', () => {
1024
1039
  });
1025
1040
 
1026
1041
  describe('quantity', () => {
1042
+ it('puts the heart beside the stepper and lets Add to cart wrap only when its label does not fit', async () => {
1043
+ const wrapper = await mountReady(mock);
1044
+ const row = wrapper.get('[data-eldra-product-actions]');
1045
+ // DOM order is reading order: quantity, save, add.
1046
+ const order = [...row.element.children].map((child) =>
1047
+ child.querySelector('[role="spinbutton"]')
1048
+ ? 'quantity'
1049
+ : child.getAttribute('aria-pressed') !== null
1050
+ ? 'save'
1051
+ : child.querySelector('button[type="submit"]')
1052
+ ? 'add'
1053
+ : '?'
1054
+ );
1055
+ expect(order).toEqual(['quantity', 'save', 'add']);
1056
+ // No breakpoint forces the button onto a row of its own: it wraps when it does not fit.
1057
+ const add = row.element.children[2]!;
1058
+ expect(add.className).toContain('min-w-max');
1059
+ expect(add.className).not.toMatch(/basis-full|order-last/);
1060
+ expect(row.classes()).toContain('flex-wrap');
1061
+ wrapper.unmount();
1062
+ });
1063
+
1027
1064
  it('follows inventory for its maximum and marks the limits aria-disabled', async () => {
1028
1065
  const wrapper = await mountReady(
1029
1066
  { ...mock, lowStockThreshold: 'off' },
@@ -1302,6 +1339,23 @@ describe('product-detail block', () => {
1302
1339
 
1303
1340
  /** The `tabs` entries render as an accordion now (the design's Details / Care / Delivery and
1304
1341
  * returns rows), the first one open — each row a native disclosure. */
1342
+ describe('maker line', () => {
1343
+ it('names the maker above the title, linked to a search for them', async () => {
1344
+ const wrapper = await mountReady(mock);
1345
+ const link = wrapper.get('[data-product-maker] a');
1346
+ expect(link.text()).toBe('Fell & Fleece');
1347
+ expect(link.attributes('href')).toBe('/search?q=Fell%20%26%20Fleece');
1348
+ const maker = wrapper.get('[data-product-maker]').element;
1349
+ const title = wrapper.get('h1').element;
1350
+ expect(maker.compareDocumentPosition(title) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy();
1351
+ });
1352
+
1353
+ it('draws no maker line for a product without one', async () => {
1354
+ const wrapper = await mountReady(mock, { storefront: storefrontWith({ vendor: undefined }) });
1355
+ expect(wrapper.find('[data-product-maker]').exists()).toBe(false);
1356
+ });
1357
+ });
1358
+
1305
1359
  describe('details accordion', () => {
1306
1360
  const rows = (wrapper: Wrapper) => wrapper.findAll('details');
1307
1361
  const summaries = (wrapper: Wrapper) => wrapper.findAll('details > summary');
@@ -1326,6 +1380,38 @@ describe('product-detail block', () => {
1326
1380
  expect(wrapper.text()).toContain('100% extra-fine Merino wool');
1327
1381
  });
1328
1382
 
1383
+ it('draws a body of bold-labelled facts as a two-column definition list', async () => {
1384
+ const wrapper = await mountReady(mock);
1385
+ const row = rows(wrapper)[0]!;
1386
+ const list = row.get('dl');
1387
+ expect(list.classes()).toEqual(expect.arrayContaining(['grid', 'grid-cols-[auto_1fr]']));
1388
+ expect(list.findAll('dt').map((term) => term.text())).toEqual([
1389
+ 'Material',
1390
+ 'Fit',
1391
+ 'Weight',
1392
+ 'Made in',
1393
+ ]);
1394
+ expect(list.findAll('dd')[0]!.text()).toBe('100% extra-fine Merino wool, 17.5 micron');
1395
+ // The facts replace the list, never sit beside a second copy of it.
1396
+ expect(row.find('ul').exists()).toBe(false);
1397
+ expect(await axe(wrapper.element)).toHaveNoViolations();
1398
+ });
1399
+
1400
+ it('renders any other body as its rich text', async () => {
1401
+ const wrapper = await mountReady(mock);
1402
+ // Care is a plain bullet list (no bold labels): it stays a list.
1403
+ const care = rows(wrapper)[1]!;
1404
+ expect(care.find('dl').exists()).toBe(false);
1405
+ expect(care.find('ul').exists()).toBe(true);
1406
+ });
1407
+
1408
+ it('keeps the facts as editable rich text in the editor', async () => {
1409
+ const wrapper = await mountReady(mock, { editing: true });
1410
+ const row = rows(wrapper)[0]!;
1411
+ expect(row.find('dl').exists()).toBe(false);
1412
+ expect(row.find('ul').exists()).toBe(true);
1413
+ });
1414
+
1329
1415
  it('opens and closes a row from the keyboard, its summary being the one tab stop', async () => {
1330
1416
  const wrapper = await mountReady(mock);
1331
1417
  const care = summaries(wrapper)[1]!;
@@ -0,0 +1,79 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import { specsFromBody } from '../specs';
3
+
4
+ const bold = (text: string) => ({ type: 'text', marks: [{ type: 'bold' }], text });
5
+ const plain = (text: string, marks?: Array<{ type: string }>) => ({ type: 'text', text, marks });
6
+ const item = (...runs: unknown[]) => ({
7
+ type: 'listItem',
8
+ content: [{ type: 'paragraph', content: runs }],
9
+ });
10
+ const list = (...items: unknown[]) => ({
11
+ type: 'doc',
12
+ content: [{ type: 'bulletList', content: items }],
13
+ });
14
+
15
+ describe('specsFromBody', () => {
16
+ it('reads a bullet list of bold labels as label/value pairs', () => {
17
+ expect(
18
+ specsFromBody(
19
+ list(item(bold('Material'), plain(' Wool')), item(bold('Made in:'), plain(' Biella')))
20
+ )
21
+ ).toEqual([
22
+ { label: 'Material', value: 'Wool' },
23
+ { label: 'Made in', value: 'Biella' },
24
+ ]);
25
+ });
26
+
27
+ it('joins a label split across bold runs and a value across plain ones', () => {
28
+ expect(
29
+ specsFromBody(
30
+ list(
31
+ item(
32
+ bold('Made '),
33
+ { ...bold('in'), marks: [{ type: 'bold' }, { type: 'italic' }] },
34
+ plain(' Biella, '),
35
+ plain('Italy', [{ type: 'italic' }])
36
+ )
37
+ )
38
+ )
39
+ ).toEqual([{ label: 'Made in', value: 'Biella, Italy' }]);
40
+ });
41
+
42
+ it.each([
43
+ ['an empty body', { type: 'doc', content: [] }],
44
+ ['no body at all', null],
45
+ ['a paragraph', { type: 'doc', content: [{ type: 'paragraph', content: [plain('Hi')] }] }],
46
+ [
47
+ 'an item without a bold label',
48
+ list(item(bold('Material'), plain(' Wool')), item(plain('Hand wash'))),
49
+ ],
50
+ ['an item that is only a label', list(item(bold('Material')))],
51
+ ['a link in the value', list(item(bold('Guide'), plain(' here', [{ type: 'link' }])))],
52
+ [
53
+ 'an ordered list',
54
+ { type: 'doc', content: [{ type: 'orderedList', content: [item(bold('A'), plain(' b'))] }] },
55
+ ],
56
+ [
57
+ 'a list followed by a paragraph',
58
+ {
59
+ type: 'doc',
60
+ content: [
61
+ ...list(item(bold('A'), plain(' b'))).content,
62
+ { type: 'paragraph', content: [plain('More')] },
63
+ ],
64
+ },
65
+ ],
66
+ [
67
+ 'an item with two paragraphs',
68
+ list({
69
+ type: 'listItem',
70
+ content: [
71
+ { type: 'paragraph', content: [bold('A'), plain(' b')] },
72
+ { type: 'paragraph', content: [plain('c')] },
73
+ ],
74
+ }),
75
+ ],
76
+ ])('answers null for %s, which then renders as rich text', (_, body) => {
77
+ expect(specsFromBody(body as never)).toBeNull();
78
+ });
79
+ });
@@ -10,6 +10,7 @@
10
10
  "fieldId": "productHandle",
11
11
  "name": "Product",
12
12
  "type": "string",
13
+ "allowPrices": false,
13
14
  "helpText": "Leave empty on a product template — the route supplies it.",
14
15
  "description": "Pick one by hand for a featured-product landing section."
15
16
  },
@@ -142,7 +143,8 @@
142
143
  {
143
144
  "fieldId": "sizeGuideHref",
144
145
  "name": "Size guide URL",
145
- "type": "string"
146
+ "type": "string",
147
+ "allowPrices": false
146
148
  },
147
149
  {
148
150
  "fieldId": "stickyBar",
@@ -9,7 +9,7 @@
9
9
  {
10
10
  "icon": "truck",
11
11
  "title": "Free delivery",
12
- "text": "on orders over $80"
12
+ "text": "on orders over ⟦store freeShippingThreshold⟧"
13
13
  },
14
14
  {
15
15
  "icon": "building-store",
@@ -39,7 +39,16 @@
39
39
  "content": [
40
40
  {
41
41
  "type": "text",
42
- "text": "100% extra-fine Merino wool, 17.5 micron"
42
+ "marks": [
43
+ {
44
+ "type": "bold"
45
+ }
46
+ ],
47
+ "text": "Material"
48
+ },
49
+ {
50
+ "type": "text",
51
+ "text": " 100% extra-fine Merino wool, 17.5 micron"
43
52
  }
44
53
  ]
45
54
  }
@@ -53,7 +62,16 @@
53
62
  "content": [
54
63
  {
55
64
  "type": "text",
56
- "text": "Knitted in a family mill in Biella, Italy"
65
+ "marks": [
66
+ {
67
+ "type": "bold"
68
+ }
69
+ ],
70
+ "text": "Fit"
71
+ },
72
+ {
73
+ "type": "text",
74
+ "text": " Relaxed; the model is 180 cm and wears M"
57
75
  }
58
76
  ]
59
77
  }
@@ -67,7 +85,39 @@
67
85
  "content": [
68
86
  {
69
87
  "type": "text",
70
- "text": "Relaxed fit; the model is 180 cm and wears size M"
88
+ "marks": [
89
+ {
90
+ "type": "bold"
91
+ }
92
+ ],
93
+ "text": "Weight"
94
+ },
95
+ {
96
+ "type": "text",
97
+ "text": " Midweight, 12-gauge knit"
98
+ }
99
+ ]
100
+ }
101
+ ]
102
+ },
103
+ {
104
+ "type": "listItem",
105
+ "content": [
106
+ {
107
+ "type": "paragraph",
108
+ "content": [
109
+ {
110
+ "type": "text",
111
+ "marks": [
112
+ {
113
+ "type": "bold"
114
+ }
115
+ ],
116
+ "text": "Made in"
117
+ },
118
+ {
119
+ "type": "text",
120
+ "text": " Biella, Italy, in a family mill"
71
121
  }
72
122
  ]
73
123
  }
@@ -83,6 +83,12 @@ function isWide(index: number): boolean {
83
83
  return index === count.value - 1 && (count.value - 1) % 2 === 1;
84
84
  }
85
85
 
86
+ /**
87
+ * The tile owns the shape (`aspect-*` on the button) and the photo fills it (`UiImage`'s `fill`).
88
+ * Handing the ratio to `UiImage` instead drew the wide tile's photo at its own intrinsic ratio: 5:4
89
+ * is not one of `Image`'s named ratios, so the box was 5:4 and the photo inside it 3:2, with a band
90
+ * of empty `surface` under it.
91
+ */
86
92
  const TILE = 'group relative block w-full cursor-zoom-in overflow-hidden rounded-lg bg-surface';
87
93
  </script>
88
94
 
@@ -98,13 +104,13 @@ const TILE = 'group relative block w-full cursor-zoom-in overflow-hidden rounded
98
104
  type="button"
99
105
  aria-haspopup="dialog"
100
106
  :aria-label="tileLabel(image, index)"
101
- :class="[focusRing, TILE]"
107
+ :class="[focusRing, TILE, isWide(index) ? 'aspect-[5/4]' : 'aspect-[4/5]']"
102
108
  @click="open(index)"
103
109
  >
104
110
  <UiImage
105
111
  :src="image.src"
106
112
  alt=""
107
- :aspect="isWide(index) ? '5/4' : '4/5'"
113
+ fill
108
114
  :priority="index === 0"
109
115
  class="motion-safe:duration-base w-full group-hover:scale-[1.02] motion-safe:transition-transform"
110
116
  />
@@ -0,0 +1,75 @@
1
+ /**
2
+ * **A tab body that is a list of facts, read as label/value pairs.**
3
+ *
4
+ * The design draws the Details row as a two-column definition list (Capacity · 350 ml, Material ·
5
+ * Stoneware). The tab's body is rich text, and a merchant writes facts in it the way they would in
6
+ * any editor: a bullet list, each item starting with its label in bold — "**Material** Stoneware",
7
+ * or "**Material:** Stoneware". When the whole body is exactly that, this answers the pairs and the
8
+ * block draws them as `<dl>`; anything else (a paragraph, a list item without a bold label, a link
9
+ * in the value, a second list) answers `null` and the body renders as the rich text it is, so no
10
+ * merchant content is ever dropped or reshaped into something it was not.
11
+ *
12
+ * Content, not a field: the tab schema is unchanged, so no stored tab needs migrating.
13
+ */
14
+ /** The slice of the stored ProseMirror JSON this reads. */
15
+ interface RichTextNode {
16
+ type?: string;
17
+ text?: string;
18
+ marks?: Array<{ type: string }>;
19
+ content?: RichTextNode[];
20
+ }
21
+
22
+ export interface TabSpec {
23
+ label: string;
24
+ value: string;
25
+ }
26
+
27
+ function isBold(node: RichTextNode): boolean {
28
+ return (node.marks ?? []).some((mark) => mark.type === 'bold');
29
+ }
30
+
31
+ /** Plain text only: a link (or any node that is not text) in the value cannot survive a `<dd>`. */
32
+ function isPlainText(node: RichTextNode): boolean {
33
+ return node.type === 'text' && (node.marks ?? []).every((mark) => mark.type !== 'link');
34
+ }
35
+
36
+ function specFromItem(item: RichTextNode): TabSpec | null {
37
+ if (item.type !== 'listItem') return null;
38
+ const [paragraph, ...rest] = item.content ?? [];
39
+ if (paragraph === undefined || rest.length > 0 || paragraph.type !== 'paragraph') return null;
40
+ const runs = paragraph.content ?? [];
41
+ if (runs.length === 0 || !runs.every(isPlainText)) return null;
42
+
43
+ // The label is the leading bold run (which may be split across nodes by other marks); the value
44
+ // is everything after it.
45
+ let index = 0;
46
+ let label = '';
47
+ while (index < runs.length && isBold(runs[index]!)) {
48
+ label += runs[index]!.text ?? '';
49
+ index += 1;
50
+ }
51
+ const value = runs
52
+ .slice(index)
53
+ .map((run) => run.text ?? '')
54
+ .join('')
55
+ .trim();
56
+ label = label.trim().replace(/:$/, '').trim();
57
+ if (label === '' || value === '') return null;
58
+ return { label, value };
59
+ }
60
+
61
+ export function specsFromBody(body: { content?: unknown[] } | null | undefined): TabSpec[] | null {
62
+ const content = (body?.content ?? []) as RichTextNode[];
63
+ if (content.length !== 1) return null;
64
+ const [list] = content;
65
+ if (list!.type !== 'bulletList') return null;
66
+ const items = list!.content ?? [];
67
+ if (items.length === 0) return null;
68
+ const specs: TabSpec[] = [];
69
+ for (const item of items) {
70
+ const spec = specFromItem(item);
71
+ if (spec === null) return null;
72
+ specs.push(spec);
73
+ }
74
+ return specs;
75
+ }
@@ -63,6 +63,7 @@
63
63
  "fieldId": "sourceLinkHref",
64
64
  "name": "Source link",
65
65
  "type": "string",
66
+ "allowPrices": false,
66
67
  "helpText": "The article or page the role line links to."
67
68
  },
68
69
  {
@@ -74,12 +74,14 @@ import { useEldraLocale } from '@eldrajs/theme-vue';
74
74
  import { useBlockData } from '../../app/composables/useBlockData';
75
75
  import { useEditing } from '../../app/composables/useEditing';
76
76
  import { useStorefront } from '../../app/composables/useStorefront';
77
+ import { useQuickAdd } from '../../app/composables/useQuickAdd';
77
78
  import { useI18n } from 'vue-i18n';
78
79
  import { useUiId } from '../../app/composables/useUiId';
79
80
  import EldraRouterLink from '../../app/components/EldraRouterLink.vue';
80
81
  import { stripStega } from '@eldrajs/theme-core/stega';
81
82
  import { isInternalHref, searchQueryHref, SEARCH_PATH } from '../../app/utils/links';
82
83
  import { toProductCardEntries } from '../../app/storefront/toProductCard';
84
+ import { productCardLook } from '../../app/storefront/productCardLook';
83
85
  import { useMoney } from '../../app/storefront/money';
84
86
  import type { StorefrontCollectionSelector } from '../../app/storefront/types';
85
87
  import { toSearchBarResults } from './results';
@@ -97,6 +99,7 @@ const { data } = useBlockData(props, 'search');
97
99
  const editing = useEditing();
98
100
  const { t } = useI18n();
99
101
  const storefront = useStorefront();
102
+ const quickAdd = useQuickAdd();
100
103
  const headingId = `search-heading-${useUiId()}`;
101
104
 
102
105
  /** What the author writes in `heading` to have the shopper's query dropped into the sentence. */
@@ -498,10 +501,11 @@ const headingClass =
498
501
 
499
502
  <template v-if="hasNoResultsProducts">
500
503
  <p class="text-body-sm text-text font-semibold">{{ t('search.customersLove') }}</p>
501
- <div class="grid grid-cols-2 gap-4">
504
+ <div class="grid grid-cols-1 gap-4 @min-[23.25rem]:grid-cols-2">
502
505
  <ProductCard
503
506
  v-for="entry in noResultsProducts"
504
507
  :key="entry.item.handle"
508
+ v-bind="productCardLook(t, entry.product.title)"
505
509
  :product="entry.product"
506
510
  ratio="4x5"
507
511
  class="min-w-0"
@@ -509,6 +513,7 @@ const headingClass =
509
513
  :link-as="entry.internal ? EldraRouterLink : undefined"
510
514
  :currency="entry.currency ?? currency"
511
515
  :locale="locale"
516
+ @quick-add="quickAdd.add(entry.item)"
512
517
  />
513
518
  </div>
514
519
  </template>
@@ -9,9 +9,12 @@
9
9
  */
10
10
  import { computed, type Component } from 'vue';
11
11
  import { ContentCard, Link, ProductCard } from '@eldrajs/ui';
12
+ import { useI18n } from 'vue-i18n';
13
+ import { useQuickAdd } from '../../app/composables/useQuickAdd';
12
14
  import EldraRouterLink from '../../app/components/EldraRouterLink.vue';
13
15
  import { isInternalHref, safeHref } from '../../app/utils/links';
14
16
  import { toProductCardEntries } from '../../app/storefront/toProductCard';
17
+ import { productCardLook } from '../../app/storefront/productCardLook';
15
18
  import { useMoney } from '../../app/storefront/money';
16
19
  import { useStorefront } from '../../app/composables/useStorefront';
17
20
  import type { StorefrontSearchProduct, StorefrontSearchResponse } from '../../app/storefront/types';
@@ -52,6 +55,8 @@ const props = defineProps<{
52
55
  }>();
53
56
 
54
57
  /** See the `products` prop: sanitised, unusable rows dropped, `internal` per card. */
58
+ const { t } = useI18n();
59
+ const quickAdd = useQuickAdd();
55
60
  const money = useMoney();
56
61
  const shopperCurrency = useStorefront().currency.active;
57
62
  const productCards = computed(() =>
@@ -79,7 +84,7 @@ const pageRows = computed(() =>
79
84
  );
80
85
 
81
86
  const PRODUCTS_GRID_CLASS =
82
- 'grid grid-cols-2 gap-x-4 gap-y-8 @tablet:grid-cols-3 @tablet:gap-x-6 @tablet:gap-y-10 ' +
87
+ 'grid grid-cols-1 @min-[23.25rem]:grid-cols-2 gap-x-4 gap-y-8 @tablet:grid-cols-3 @tablet:gap-x-6 @tablet:gap-y-10 ' +
83
88
  '@content:grid-cols-4 @content:gap-x-8';
84
89
  const JOURNAL_GRID_CLASS = 'grid grid-cols-1 gap-6 @tablet:grid-cols-3 @tablet:gap-8';
85
90
  </script>
@@ -99,6 +104,7 @@ const JOURNAL_GRID_CLASS = 'grid grid-cols-1 gap-6 @tablet:grid-cols-3 @tablet:g
99
104
  <ProductCard
100
105
  v-for="entry in productCards"
101
106
  :key="entry.item.handle"
107
+ v-bind="productCardLook(t, entry.product.title)"
102
108
  :product="entry.product"
103
109
  ratio="4x5"
104
110
  class="min-w-0"
@@ -106,6 +112,7 @@ const JOURNAL_GRID_CLASS = 'grid grid-cols-1 gap-6 @tablet:grid-cols-3 @tablet:g
106
112
  :link-as="entry.internal ? EldraRouterLink : undefined"
107
113
  :currency="entry.currency ?? currency"
108
114
  :locale="locale"
115
+ @quick-add="quickAdd.add(entry.item)"
109
116
  />
110
117
  </div>
111
118
 
@@ -1,5 +1,6 @@
1
1
  // @vitest-environment jsdom
2
- import { mount, type VueWrapper } from '@vue/test-utils';
2
+ import { flushPromises, mount, type VueWrapper } from '@vue/test-utils';
3
+ import { ProductCard } from '@eldrajs/ui';
3
4
  import { nextTick, ref, watch, type Ref } from 'vue';
4
5
  import { afterEach, describe, expect, it, vi } from 'vitest';
5
6
  import { axe } from '../../../test/support/axe';
@@ -317,6 +318,28 @@ describe('search block', () => {
317
318
  expect(live()?.textContent).toContain('7');
318
319
  });
319
320
 
321
+ describe('"+ Add" on a result card', () => {
322
+ it('reads the product and puts one of its variant in the cart', async () => {
323
+ const storefront = withSearch({
324
+ query: 'linen',
325
+ total: 2,
326
+ products: PRODUCTS.slice(0, 2),
327
+ articles: [],
328
+ pages: [],
329
+ suggestion: null,
330
+ });
331
+ const add = vi.spyOn(storefront.cart, 'add');
332
+ const wrapper = mountSearch(mock, { storefront });
333
+ await flushPromises();
334
+ const first = wrapper.findAllComponents(ProductCard)[0]!;
335
+ await first.get('button[data-part="quickAdd"]').trigger('click');
336
+ await flushPromises();
337
+ expect(add).toHaveBeenCalledTimes(1);
338
+ expect(add.mock.calls[0]![0].quantity).toBe(1);
339
+ expect(storefront.cart.lines.value.length).toBe(1);
340
+ });
341
+ });
342
+
320
343
  describe('result tabs', () => {
321
344
  it('a type with zero results has no tab', async () => {
322
345
  const wrapper = mountSearch(mock, {
@@ -96,6 +96,7 @@
96
96
  "fieldId": "noResultsCollection",
97
97
  "name": "No-results collection",
98
98
  "type": "string",
99
+ "allowPrices": false,
99
100
  "helpText": "Collection handle shown under \"Customers love these\"."
100
101
  }
101
102
  ]
Binary file
@@ -22,11 +22,7 @@
22
22
  *
23
23
  * `rows[].text` is optional rich text with a small toolbar (bold/italic/link/undo/redo only — no
24
24
  * headings or lists, per the field's own `metadata.toolbar`), rendered through `EldraRichText` with
25
- * no `api-id`: like `faq`'s own per-item `answer` field, `rows[].text` lives one level inside a list
26
- * item, and `useEldraBlockField`/`isBlockFieldLocalized` only resolve a field's `localized` flag by
27
- * matching a flat top-level `fieldId` — there is no nested-path addressing, so passing `api-id`
28
- * here would silently (and wrongly) resolve `localized: false` regardless of the manifest. See
29
- * `blocks/faq/Block.vue`'s own comment for the full reasoning.
25
+ * `api-id`, so its `localized` flag is read by its list path (`rows.0.text`).
30
26
  *
31
27
  * **The theme's look** (the "makers" story): the image takes the wider `1.15fr` track and the
32
28
  * text `1fr`, side by side from 961px of block width (stacked, image first, below that), with a
@@ -123,6 +119,15 @@ function textOrderClass(index: number): string {
123
119
  return rowSide(index) === 'image-right' ? '@min-[60.0625rem]:order-1' : '';
124
120
  }
125
121
 
122
+ /**
123
+ * The image's root reserves the 5:4 box (`aspect="5/4"` has no `Image` ratio preset, so `UiImage`
124
+ * puts it on the root as an inline `aspect-ratio`), but `Image`'s frame inside it is `ratio="auto"`
125
+ * and would size itself from the photo's own proportions — a 3:2 photo left a strip of empty root
126
+ * under it. `h-full` makes the frame fill the box it sits in, and the `object-cover` media fills the
127
+ * frame, so the image is the full 5:4 the design draws beside the text.
128
+ */
129
+ const IMAGE_FILL_CLASSES = { frame: 'h-full' };
130
+
126
131
  /** The round initials cycle through three theme colours, all dark enough for the light letter. */
127
132
  const AVATAR_TONES = ['bg-primary', 'bg-accent', 'bg-border-strong'] as const;
128
133
  function entryTone(index: number): string {
@@ -189,6 +194,7 @@ useRichTextScrollRegions(rowsRoot, (caption) => caption ?? t('splitContent.richT
189
194
  :field-path="`rows.${index}.image`"
190
195
  aspect="5/4"
191
196
  rounded="xl"
197
+ :classes="IMAGE_FILL_CLASSES"
192
198
  :class="imageOrderClass(index)"
193
199
  />
194
200
  <EditorPlaceholder
@@ -224,6 +230,7 @@ useRichTextScrollRegions(rowsRoot, (caption) => caption ?? t('splitContent.richT
224
230
  class="prose-eldra text-muted mt-4 text-[1.125rem] leading-[1.6] [&>*+*]:mt-3"
225
231
  :entry-id="entryId"
226
232
  :field="`rows.${index}.text`"
233
+ api-id="split-content"
227
234
  :doc="row.text"
228
235
  :min-heading-level="3"
229
236
  />
@@ -261,4 +261,17 @@ describe('split-content block', () => {
261
261
  expect(frame.classes()).toContain('eldra:rounded-xl');
262
262
  }
263
263
  });
264
+
265
+ it('fills the reserved 5:4 box with the image, whatever the photo’s own proportions', () => {
266
+ // The root carries the 5:4 `aspect-ratio`; the frame inside it would otherwise size itself from
267
+ // the photo (3:2 for the demo imagery) and leave the bottom of the box empty.
268
+ const wrapper = mount(Block, mountOptions({ entry: { id: 'e1', data: withImage } }));
269
+ const frames = wrapper.findAll('[data-part="frame"]');
270
+ expect(frames.length).toBeGreaterThan(0);
271
+ for (const frame of frames) {
272
+ const root = frame.element.parentElement!;
273
+ expect(root.getAttribute('style')).toContain('aspect-ratio: 5/4');
274
+ expect(frame.classes()).toContain('h-full');
275
+ }
276
+ });
264
277
  });
@@ -72,7 +72,8 @@
72
72
  {
73
73
  "fieldId": "href",
74
74
  "name": "Button link",
75
- "type": "string"
75
+ "type": "string",
76
+ "allowPrices": false
76
77
  }
77
78
  ]
78
79
  }
@@ -116,7 +117,8 @@
116
117
  {
117
118
  "fieldId": "href",
118
119
  "name": "Link",
119
- "type": "string"
120
+ "type": "string",
121
+ "allowPrices": false
120
122
  }
121
123
  ]
122
124
  }
Binary file