@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
@@ -1,6 +1,7 @@
1
1
  // @vitest-environment jsdom
2
2
  import { mount } from '@vue/test-utils';
3
3
  import { h, nextTick } from 'vue';
4
+ import { flushPromises } from '@vue/test-utils';
4
5
  import { axe } from '../../../test/support/axe';
5
6
  import { describe, expect, it } from 'vitest';
6
7
  import Block from '../Block.vue';
@@ -89,37 +90,88 @@ describe('hero block', () => {
89
90
  expect(frame.classes()).toContain('@min-[68.8125rem]:aspect-[21/9]!');
90
91
  });
91
92
 
92
- it('renders the caption as one same-site link naming the item and its detail', () => {
93
+ /**
94
+ * WS-1277: the caption was three typed fields, its price a string ("ISK 4,790") that ignored the
95
+ * regional format and the shopper's currency and went stale with the catalog. It is the picked
96
+ * product now, its name, price and link all read from the storefront.
97
+ */
98
+ it('names the picked product and its price from the catalog, and links to it', async () => {
93
99
  const wrapper = mount(Block, mountOptions({ entry: { id: 'e1', data: card } }));
94
- const caption = wrapper
95
- .findAll('a')
96
- .find((link) => link.text().includes(withImage.captionLabel));
97
- expect(caption).toBeDefined();
98
- expect(caption!.text()).toContain(withImage.captionDetail);
99
- expect(caption!.attributes('href')).toBe(withImage.captionHref);
100
+ await flushPromises();
101
+ const caption = wrapper.get('[data-eldra-hero-caption]');
102
+ expect(caption.text()).toContain('Glazed milk jug');
103
+ expect(caption.attributes('href')).toBe('/products/glazed-milk-jug');
104
+ expect(caption.text()).toContain('$34');
100
105
  });
101
106
 
102
- it('renders no caption without a link, and none in the other variants', () => {
103
- const noHref = mount(
104
- Block,
105
- mountOptions({ entry: { id: 'e1', data: { ...card, captionHref: '' } } })
106
- );
107
- expect(noHref.text()).not.toContain(withImage.captionLabel);
108
- const imageRight = mount(
107
+ it('writes the price in the regional format and the store currency', async () => {
108
+ const wrapper = mount(
109
109
  Block,
110
- mountOptions({ entry: { id: 'e1', data: { ...card, variant: 'image-right' } } })
110
+ mountOptions(
111
+ { entry: { id: 'e1', data: card } },
112
+ {
113
+ locale: 'en-US',
114
+ commerce: { currency: 'ISK', taxInclusivePricing: true, defaultTaxRate: 0.24 },
115
+ region: { countryCode: 'IS', formatLocale: 'is-IS', timeZone: 'Atlantic/Reykjavik' },
116
+ }
117
+ )
111
118
  );
112
- expect(imageRight.text()).not.toContain(withImage.captionLabel);
119
+ await flushPromises();
120
+ const caption = wrapper.get('[data-eldra-hero-caption]');
121
+ // `is-IS` writes a no-break space before the currency.
122
+ expect(caption.text()).toMatch(/34\u00a0kr\./);
123
+ expect(caption.text()).not.toContain('ISK');
113
124
  });
114
125
 
115
- it('drops an unsafe caption link', () => {
126
+ it('takes its own text in place of the product name, keeping the price and link', async () => {
116
127
  const wrapper = mount(
117
128
  Block,
118
129
  mountOptions({
119
- entry: { id: 'e1', data: { ...card, captionHref: 'javascript:alert(1)' } },
130
+ entry: { id: 'e1', data: { ...card, captionLabel: 'Our bestselling jug' } },
131
+ })
132
+ );
133
+ await flushPromises();
134
+ const caption = wrapper.get('[data-eldra-hero-caption]');
135
+ expect(caption.text()).toContain('Our bestselling jug');
136
+ expect(caption.text()).not.toContain('Glazed milk jug');
137
+ expect(caption.attributes('href')).toBe('/products/glazed-milk-jug');
138
+ });
139
+
140
+ it('draws the caption as a pill whose words are never underlined, at rest, hovered or pressed', async () => {
141
+ // The design's shoppable pill (`.nw-shoppable`): the pill is the affordance. `Link`'s
142
+ // `underline: false` still underlines on hover and press, so the caption turns both off.
143
+ const wrapper = mount(Block, mountOptions({ entry: { id: 'e1', data: card } }));
144
+ await flushPromises();
145
+ const caption = wrapper.get('[data-eldra-hero-caption]');
146
+ for (const token of [
147
+ 'no-underline',
148
+ 'hover:no-underline',
149
+ 'active:no-underline',
150
+ 'rounded-full',
151
+ ]) {
152
+ expect(caption.classes()).toContain(token);
153
+ }
154
+ expect(caption.classes()).toContain('eldra:hover:underline');
155
+ });
156
+
157
+ it('shows no caption without a product, for a sold-out one, or outside the card variant', async () => {
158
+ const caption = async (data: Record<string, unknown>) => {
159
+ const wrapper = mount(Block, mountOptions({ entry: { id: 'e1', data } }));
160
+ await flushPromises();
161
+ return wrapper.find('[data-eldra-hero-caption]').exists();
162
+ };
163
+ expect(await caption({ ...card, captionProduct: null })).toBe(false);
164
+ expect(
165
+ await caption({
166
+ ...card,
167
+ captionProduct: { _type: 'product', slug: 'enamel-camp-cups-set-of-6' },
120
168
  })
169
+ ).toBe(false);
170
+ // A draft's bare stub names no slug yet: nothing to look up until it is published.
171
+ expect(await caption({ ...card, captionProduct: { _type: 'product', id: 'abc' } })).toBe(
172
+ false
121
173
  );
122
- expect(wrapper.text()).not.toContain(withImage.captionLabel);
174
+ expect(await caption({ ...card, variant: 'image-right' })).toBe(false);
123
175
  });
124
176
  });
125
177
 
@@ -4,7 +4,7 @@
4
4
  "description": "Top-of-page banner with heading, supporting text, image and calls to action.",
5
5
  "icon": "layout-dashboard",
6
6
  "category": "marketing",
7
- "version": 2,
7
+ "version": 3,
8
8
  "migrations": [
9
9
  {
10
10
  "version": 2,
@@ -12,7 +12,8 @@
12
12
  { "from": "ctaLabel", "to": "primaryCtaLabel" },
13
13
  { "from": "ctaHref", "to": "primaryCtaHref" }
14
14
  ]
15
- }
15
+ },
16
+ { "version": 3, "renames": [] }
16
17
  ],
17
18
  "groups": [
18
19
  { "groupId": "content", "name": "Content", "defaultOpen": true },
@@ -101,39 +102,30 @@
101
102
  "type": "string",
102
103
  "localized": true
103
104
  },
104
- { "fieldId": "href", "name": "Link", "type": "string" }
105
+ { "fieldId": "href", "name": "Link", "type": "string", "allowPrices": false }
105
106
  ]
106
107
  }
107
108
  }
108
109
  }
109
110
  },
110
111
  {
111
- "fieldId": "captionLabel",
112
- "name": "Image caption",
113
- "type": "string",
112
+ "fieldId": "captionProduct",
113
+ "name": "Image caption product",
114
+ "type": "reference",
114
115
  "groupId": "content",
115
- "localized": true,
116
- "helpText": "A small link on the photo naming what is in it, e.g. \"Glazed milk jug\". Card variant only.",
117
- "showWhen": { "field": "variant", "in": ["card"] },
118
- "validators": { "maxLength": 60 }
116
+ "relation": { "allowProducts": true },
117
+ "helpText": "The product in the photo. The caption shows its name and price and links to it, and hides while it is sold out. Card variant only.",
118
+ "showWhen": { "field": "variant", "in": ["card"] }
119
119
  },
120
120
  {
121
- "fieldId": "captionDetail",
122
- "name": "Image caption detail",
121
+ "fieldId": "captionLabel",
122
+ "name": "Image caption text",
123
123
  "type": "string",
124
124
  "groupId": "content",
125
125
  "localized": true,
126
- "helpText": "Shown after the caption in a lighter weight, e.g. the price.",
126
+ "helpText": "Leave empty to use the product's name.",
127
127
  "showWhen": { "field": "variant", "in": ["card"] },
128
- "validators": { "maxLength": 30 }
129
- },
130
- {
131
- "fieldId": "captionHref",
132
- "name": "Image caption link",
133
- "type": "string",
134
- "groupId": "content",
135
- "helpText": "Where the caption goes, usually the product in the photo. No link, no caption.",
136
- "showWhen": { "field": "variant", "in": ["card"] }
128
+ "validators": { "maxLength": 60 }
137
129
  },
138
130
  {
139
131
  "fieldId": "spacing",
@@ -153,6 +145,7 @@
153
145
  "fieldId": "primaryCtaHref",
154
146
  "name": "Button link",
155
147
  "type": "string",
148
+ "allowPrices": false,
156
149
  "groupId": "action"
157
150
  },
158
151
  {
@@ -166,6 +159,7 @@
166
159
  "fieldId": "secondaryCtaHref",
167
160
  "name": "Secondary button link",
168
161
  "type": "string",
162
+ "allowPrices": false,
169
163
  "groupId": "action"
170
164
  }
171
165
  ],
@@ -52,9 +52,7 @@
52
52
  "href": "/products/dinner-plates"
53
53
  }
54
54
  ],
55
- "captionLabel": "Glazed milk jug",
56
- "captionDetail": "$34",
57
- "captionHref": "/products/glazed-milk-jug",
55
+ "captionProduct": { "_type": "product", "slug": "glazed-milk-jug" },
58
56
  "primaryCtaHref": "/collections/the-winter-edit",
59
57
  "secondaryCtaLabel": "Meet the makers",
60
58
  "secondaryCtaHref": "/pages/makers",
Binary file
@@ -61,7 +61,8 @@
61
61
  {
62
62
  "fieldId": "linkHref",
63
63
  "name": "Link",
64
- "type": "string"
64
+ "type": "string",
65
+ "allowPrices": false
65
66
  }
66
67
  ]
67
68
  }
Binary file
@@ -61,6 +61,7 @@
61
61
  "fieldId": "href",
62
62
  "name": "Link",
63
63
  "type": "string",
64
+ "allowPrices": false,
64
65
  "helpText": "Stockist page or article. When set, the logo becomes a link."
65
66
  }
66
67
  ]