@eldrajs/theme-cli 0.0.0 → 0.2.0

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 (485) hide show
  1. package/CHANGELOG.md +77 -0
  2. package/LICENSE +21 -0
  3. package/README.md +26 -1
  4. package/dist/cli.d.ts +1 -0
  5. package/dist/cli.js +203 -0
  6. package/dist/index.d.ts +174 -0
  7. package/dist/index.js +3 -0
  8. package/dist/validate-DprFpjV7.js +535 -0
  9. package/package.json +50 -2
  10. package/template/.eldra/block-types.d.ts +429 -0
  11. package/template/.eldra/manifest.json +9378 -0
  12. package/template/.eldra/previews.json +36 -0
  13. package/template/.github/workflows/eldra-deploy.yml +24 -0
  14. package/template/.gitlab-ci.yml +16 -0
  15. package/template/.storybook/eldra.ts +123 -0
  16. package/template/.storybook/i18n.ts +23 -0
  17. package/template/.storybook/main.ts +59 -0
  18. package/template/.storybook/nuxt-link-stub.ts +23 -0
  19. package/template/.storybook/preview.ts +53 -0
  20. package/template/.storybook/shims-vue.d.ts +10 -0
  21. package/template/.storybook/virtual-eldra.d.ts +32 -0
  22. package/template/README.md +293 -0
  23. package/template/app/app.vue +126 -0
  24. package/template/app/assets/main.css +404 -0
  25. package/template/app/components/EldraIcon.vue +66 -0
  26. package/template/app/components/EldraRouterLink.vue +62 -0
  27. package/template/app/components/ui/UiImage.stories.ts +30 -0
  28. package/template/app/components/ui/UiImage.vue +224 -0
  29. package/template/app/components/ui/__tests__/UiImage.spec.ts +292 -0
  30. package/template/app/composables/iconComponent.ts +84 -0
  31. package/template/app/composables/iconFetcher.ts +14 -0
  32. package/template/app/composables/useBlockData.ts +30 -0
  33. package/template/app/composables/useEditing.ts +31 -0
  34. package/template/app/composables/useEldraIcon.ts +46 -0
  35. package/template/app/composables/useRevalidating.ts +69 -0
  36. package/template/app/composables/useRichTextScrollRegions.ts +80 -0
  37. package/template/app/composables/useStorefront.ts +18 -0
  38. package/template/app/composables/useStorefrontFeedback.ts +49 -0
  39. package/template/app/composables/useUiId.ts +18 -0
  40. package/template/app/composables/useWishlist.ts +42 -0
  41. package/template/app/i18n.d.ts +28 -0
  42. package/template/app/icons.ts +185 -0
  43. package/template/app/pages/[...slug].vue +134 -0
  44. package/template/app/plugins/eldra-i18n.ts +98 -0
  45. package/template/app/plugins/eldra-storefront.ts +288 -0
  46. package/template/app/plugins/eldra-ui-messages.ts +112 -0
  47. package/template/app/storefront/cart.ts +245 -0
  48. package/template/app/storefront/categories.ts +283 -0
  49. package/template/app/storefront/collectionSelector.ts +60 -0
  50. package/template/app/storefront/commerce.ts +58 -0
  51. package/template/app/storefront/demo.ts +1313 -0
  52. package/template/app/storefront/facets.ts +476 -0
  53. package/template/app/storefront/feedback.ts +122 -0
  54. package/template/app/storefront/gateway.ts +2256 -0
  55. package/template/app/storefront/history.ts +233 -0
  56. package/template/app/storefront/money.ts +248 -0
  57. package/template/app/storefront/options.ts +71 -0
  58. package/template/app/storefront/prerender.ts +77 -0
  59. package/template/app/storefront/refresh.ts +222 -0
  60. package/template/app/storefront/toProductCard.ts +154 -0
  61. package/template/app/storefront/types.ts +815 -0
  62. package/template/app/storefront/volatile.ts +211 -0
  63. package/template/app/templates.ts +544 -0
  64. package/template/app/utils/classes.ts +40 -0
  65. package/template/app/utils/links.ts +70 -0
  66. package/template/app/utils/pageStructure.ts +77 -0
  67. package/template/app/utils/pageTitle.ts +37 -0
  68. package/template/app/virtual-eldra.d.ts +12 -0
  69. package/template/bitbucket-pipelines.yml +19 -0
  70. package/template/blocks/announcement-bar/Block.vue +203 -0
  71. package/template/blocks/announcement-bar/__tests__/Block.spec.ts +227 -0
  72. package/template/blocks/announcement-bar/block.json +45 -0
  73. package/template/blocks/announcement-bar/mock.json +7 -0
  74. package/template/blocks/announcement-bar/preview.png +0 -0
  75. package/template/blocks/article/Block.vue +317 -0
  76. package/template/blocks/article/__tests__/Block.spec.ts +229 -0
  77. package/template/blocks/article/block.json +148 -0
  78. package/template/blocks/article/mock.json +512 -0
  79. package/template/blocks/article/preview.json +16 -0
  80. package/template/blocks/article/preview.png +0 -0
  81. package/template/blocks/article-list/Block.vue +343 -0
  82. package/template/blocks/article-list/__tests__/Block.spec.ts +279 -0
  83. package/template/blocks/article-list/block.json +181 -0
  84. package/template/blocks/article-list/mock.json +68 -0
  85. package/template/blocks/article-list/preview.json +84 -0
  86. package/template/blocks/article-list/preview.png +0 -0
  87. package/template/blocks/breadcrumbs/Block.vue +278 -0
  88. package/template/blocks/breadcrumbs/__tests__/Block.spec.ts +461 -0
  89. package/template/blocks/breadcrumbs/block.json +89 -0
  90. package/template/blocks/breadcrumbs/mock.json +11 -0
  91. package/template/blocks/breadcrumbs/preview.json +3 -0
  92. package/template/blocks/breadcrumbs/preview.png +0 -0
  93. package/template/blocks/cart/Block.vue +372 -0
  94. package/template/blocks/cart/__tests__/Block.spec.ts +561 -0
  95. package/template/blocks/cart/__tests__/ShippingBar.spec.ts +78 -0
  96. package/template/blocks/cart/__tests__/Summary.spec.ts +245 -0
  97. package/template/blocks/cart/block.json +74 -0
  98. package/template/blocks/cart/mock.json +11 -0
  99. package/template/blocks/cart/parts/CartLines.vue +257 -0
  100. package/template/blocks/cart/parts/ShippingBar.vue +105 -0
  101. package/template/blocks/cart/parts/Summary.vue +291 -0
  102. package/template/blocks/cart/preview.png +0 -0
  103. package/template/blocks/collection-grid/Block.vue +1832 -0
  104. package/template/blocks/collection-grid/__tests__/Block.spec.ts +3037 -0
  105. package/template/blocks/collection-grid/__tests__/groups.spec.ts +731 -0
  106. package/template/blocks/collection-grid/block.json +187 -0
  107. package/template/blocks/collection-grid/mock.json +23 -0
  108. package/template/blocks/collection-grid/parts/groups.ts +861 -0
  109. package/template/blocks/collection-grid/preview.json +7 -0
  110. package/template/blocks/collection-grid/preview.png +0 -0
  111. package/template/blocks/collection-header/Block.vue +533 -0
  112. package/template/blocks/collection-header/__tests__/Block.spec.ts +381 -0
  113. package/template/blocks/collection-header/block.json +140 -0
  114. package/template/blocks/collection-header/mock.json +28 -0
  115. package/template/blocks/collection-header/preview.json +14 -0
  116. package/template/blocks/collection-header/preview.png +0 -0
  117. package/template/blocks/contact/Block.vue +621 -0
  118. package/template/blocks/contact/__tests__/Block.spec.ts +347 -0
  119. package/template/blocks/contact/block.json +174 -0
  120. package/template/blocks/contact/mock.json +28 -0
  121. package/template/blocks/contact/preview.json +9 -0
  122. package/template/blocks/contact/preview.png +0 -0
  123. package/template/blocks/cta/Block.vue +383 -0
  124. package/template/blocks/cta/__tests__/Block.spec.ts +309 -0
  125. package/template/blocks/cta/block.json +86 -0
  126. package/template/blocks/cta/mock.json +10 -0
  127. package/template/blocks/cta/preview.json +9 -0
  128. package/template/blocks/cta/preview.png +0 -0
  129. package/template/blocks/faq/Block.vue +254 -0
  130. package/template/blocks/faq/__tests__/Block.spec.ts +312 -0
  131. package/template/blocks/faq/block.json +113 -0
  132. package/template/blocks/faq/mock.json +115 -0
  133. package/template/blocks/faq/preview.png +0 -0
  134. package/template/blocks/feature-grid/Block.vue +241 -0
  135. package/template/blocks/feature-grid/__tests__/Block.spec.ts +311 -0
  136. package/template/blocks/feature-grid/block.json +106 -0
  137. package/template/blocks/feature-grid/mock.json +29 -0
  138. package/template/blocks/feature-grid/preview.json +45 -0
  139. package/template/blocks/feature-grid/preview.png +0 -0
  140. package/template/blocks/footer/Block.vue +652 -0
  141. package/template/blocks/footer/__tests__/Block.spec.ts +700 -0
  142. package/template/blocks/footer/block.json +240 -0
  143. package/template/blocks/footer/mock.json +161 -0
  144. package/template/blocks/footer/preview.png +0 -0
  145. package/template/blocks/gallery/Block.vue +416 -0
  146. package/template/blocks/gallery/__tests__/Block.spec.ts +289 -0
  147. package/template/blocks/gallery/block.json +87 -0
  148. package/template/blocks/gallery/mock.json +16 -0
  149. package/template/blocks/gallery/preview.json +64 -0
  150. package/template/blocks/gallery/preview.png +0 -0
  151. package/template/blocks/hero/Block.vue +378 -0
  152. package/template/blocks/hero/__tests__/Block.spec.ts +324 -0
  153. package/template/blocks/hero/block.json +146 -0
  154. package/template/blocks/hero/mock.json +11 -0
  155. package/template/blocks/hero/preview.json +55 -0
  156. package/template/blocks/hero/preview.png +0 -0
  157. package/template/blocks/image/Block.vue +232 -0
  158. package/template/blocks/image/__tests__/Block.spec.ts +224 -0
  159. package/template/blocks/image/block.json +67 -0
  160. package/template/blocks/image/mock.json +7 -0
  161. package/template/blocks/image/preview.json +9 -0
  162. package/template/blocks/image/preview.png +0 -0
  163. package/template/blocks/logo-cloud/Block.vue +206 -0
  164. package/template/blocks/logo-cloud/__tests__/Block.spec.ts +210 -0
  165. package/template/blocks/logo-cloud/block.json +79 -0
  166. package/template/blocks/logo-cloud/mock.json +15 -0
  167. package/template/blocks/logo-cloud/preview.json +92 -0
  168. package/template/blocks/logo-cloud/preview.png +0 -0
  169. package/template/blocks/navigation/Block.vue +1348 -0
  170. package/template/blocks/navigation/__tests__/Block.spec.ts +2030 -0
  171. package/template/blocks/navigation/block.json +167 -0
  172. package/template/blocks/navigation/mock.json +191 -0
  173. package/template/blocks/navigation/preview.png +0 -0
  174. package/template/blocks/navigation/useMegaMenuKeys.ts +276 -0
  175. package/template/blocks/newsletter/Block.vue +399 -0
  176. package/template/blocks/newsletter/__tests__/Block.spec.ts +365 -0
  177. package/template/blocks/newsletter/block.json +105 -0
  178. package/template/blocks/newsletter/mock.json +31 -0
  179. package/template/blocks/newsletter/preview.png +0 -0
  180. package/template/blocks/order-status/Block.vue +754 -0
  181. package/template/blocks/order-status/__tests__/Block.spec.ts +515 -0
  182. package/template/blocks/order-status/block.json +138 -0
  183. package/template/blocks/order-status/mock.json +19 -0
  184. package/template/blocks/order-status/preview.png +0 -0
  185. package/template/blocks/pricing-table/Block.vue +297 -0
  186. package/template/blocks/pricing-table/__tests__/Block.spec.ts +357 -0
  187. package/template/blocks/pricing-table/block.json +155 -0
  188. package/template/blocks/pricing-table/mock.json +47 -0
  189. package/template/blocks/pricing-table/preview.png +0 -0
  190. package/template/blocks/product-carousel/Block.vue +459 -0
  191. package/template/blocks/product-carousel/__tests__/Block.spec.ts +957 -0
  192. package/template/blocks/product-carousel/block.json +71 -0
  193. package/template/blocks/product-carousel/mock.json +9 -0
  194. package/template/blocks/product-carousel/preview.json +7 -0
  195. package/template/blocks/product-carousel/preview.png +0 -0
  196. package/template/blocks/product-detail/Block.vue +886 -0
  197. package/template/blocks/product-detail/__tests__/Block.spec.ts +1492 -0
  198. package/template/blocks/product-detail/__tests__/stock.spec.ts +119 -0
  199. package/template/blocks/product-detail/block.json +155 -0
  200. package/template/blocks/product-detail/mock.json +113 -0
  201. package/template/blocks/product-detail/parts/Gallery.vue +181 -0
  202. package/template/blocks/product-detail/parts/StickyBuyBar.vue +99 -0
  203. package/template/blocks/product-detail/preview.png +0 -0
  204. package/template/blocks/product-detail/stock.ts +150 -0
  205. package/template/blocks/quote/Block.vue +206 -0
  206. package/template/blocks/quote/__tests__/Block.spec.ts +265 -0
  207. package/template/blocks/quote/block.json +76 -0
  208. package/template/blocks/quote/mock.json +9 -0
  209. package/template/blocks/quote/preview.json +16 -0
  210. package/template/blocks/quote/preview.png +0 -0
  211. package/template/blocks/rich-text/Block.vue +143 -0
  212. package/template/blocks/rich-text/__tests__/Block.spec.ts +191 -0
  213. package/template/blocks/rich-text/block.json +57 -0
  214. package/template/blocks/rich-text/mock.json +87 -0
  215. package/template/blocks/rich-text/preview.png +0 -0
  216. package/template/blocks/search/Block.vue +589 -0
  217. package/template/blocks/search/PopularChips.vue +40 -0
  218. package/template/blocks/search/TypeSection.vue +148 -0
  219. package/template/blocks/search/__tests__/Block.spec.ts +718 -0
  220. package/template/blocks/search/__tests__/results.spec.ts +166 -0
  221. package/template/blocks/search/block.json +102 -0
  222. package/template/blocks/search/mock.json +18 -0
  223. package/template/blocks/search/preview.png +0 -0
  224. package/template/blocks/search/results.ts +85 -0
  225. package/template/blocks/split-content/Block.vue +195 -0
  226. package/template/blocks/split-content/__tests__/Block.spec.ts +225 -0
  227. package/template/blocks/split-content/block.json +70 -0
  228. package/template/blocks/split-content/mock.json +45 -0
  229. package/template/blocks/split-content/preview.json +58 -0
  230. package/template/blocks/split-content/preview.png +0 -0
  231. package/template/blocks/stats/Block.vue +159 -0
  232. package/template/blocks/stats/__tests__/Block.spec.ts +194 -0
  233. package/template/blocks/stats/block.json +73 -0
  234. package/template/blocks/stats/mock.json +12 -0
  235. package/template/blocks/stats/preview.png +0 -0
  236. package/template/blocks/tabs/Block.vue +278 -0
  237. package/template/blocks/tabs/__tests__/Block.spec.ts +303 -0
  238. package/template/blocks/tabs/block.json +97 -0
  239. package/template/blocks/tabs/mock.json +129 -0
  240. package/template/blocks/tabs/preview.json +153 -0
  241. package/template/blocks/tabs/preview.png +0 -0
  242. package/template/blocks/team/Block.vue +288 -0
  243. package/template/blocks/team/__tests__/Block.spec.ts +221 -0
  244. package/template/blocks/team/block.json +125 -0
  245. package/template/blocks/team/mock.json +39 -0
  246. package/template/blocks/team/preview.json +62 -0
  247. package/template/blocks/team/preview.png +0 -0
  248. package/template/blocks/testimonials/Block.vue +408 -0
  249. package/template/blocks/testimonials/__tests__/Block.spec.ts +319 -0
  250. package/template/blocks/testimonials/block.json +121 -0
  251. package/template/blocks/testimonials/mock.json +46 -0
  252. package/template/blocks/testimonials/preview.json +68 -0
  253. package/template/blocks/testimonials/preview.png +0 -0
  254. package/template/blocks/timeline/Block.vue +274 -0
  255. package/template/blocks/timeline/__tests__/Block.spec.ts +310 -0
  256. package/template/blocks/timeline/block.json +98 -0
  257. package/template/blocks/timeline/mock.json +27 -0
  258. package/template/blocks/timeline/preview.png +0 -0
  259. package/template/blocks/trust-strip/Block.vue +330 -0
  260. package/template/blocks/trust-strip/__tests__/Block.spec.ts +290 -0
  261. package/template/blocks/trust-strip/block.json +117 -0
  262. package/template/blocks/trust-strip/mock.json +37 -0
  263. package/template/blocks/trust-strip/preview.png +0 -0
  264. package/template/blocks/video-embed/Block.vue +354 -0
  265. package/template/blocks/video-embed/__tests__/Block.spec.ts +219 -0
  266. package/template/blocks/video-embed/__tests__/embed.spec.ts +76 -0
  267. package/template/blocks/video-embed/block.json +94 -0
  268. package/template/blocks/video-embed/embed.ts +84 -0
  269. package/template/blocks/video-embed/mock.json +13 -0
  270. package/template/blocks/video-embed/preview.json +9 -0
  271. package/template/blocks/video-embed/preview.png +0 -0
  272. package/template/blocks/wishlist/Block.vue +367 -0
  273. package/template/blocks/wishlist/__tests__/Block.spec.ts +508 -0
  274. package/template/blocks/wishlist/block.json +42 -0
  275. package/template/blocks/wishlist/mock.json +9 -0
  276. package/template/blocks/wishlist/preview.png +0 -0
  277. package/template/i18n/en-US.json +602 -0
  278. package/template/i18n/is-IS.json +602 -0
  279. package/template/nuxt.config.ts +156 -0
  280. package/template/package.json +56 -0
  281. package/template/pages/article.page.json +731 -0
  282. package/template/pages/cart.page.json +85 -0
  283. package/template/pages/category.page.json +133 -0
  284. package/template/pages/collection.page.json +194 -0
  285. package/template/pages/home.page.json +353 -0
  286. package/template/pages/product.page.json +323 -0
  287. package/template/pages/products.page.json +144 -0
  288. package/template/pages/search.page.json +83 -0
  289. package/template/pages/wishlist.page.json +88 -0
  290. package/template/public/apple-touch-icon.png +0 -0
  291. package/template/public/demo/article-cover.svg +1 -0
  292. package/template/public/demo/article-figure.svg +1 -0
  293. package/template/public/demo/avatar-1.svg +3 -0
  294. package/template/public/demo/avatar-2.svg +3 -0
  295. package/template/public/demo/avatar-3.svg +3 -0
  296. package/template/public/demo/avatar-4.svg +3 -0
  297. package/template/public/demo/avatar-5.svg +3 -0
  298. package/template/public/demo/avatar-6.svg +3 -0
  299. package/template/public/demo/avatar-7.svg +3 -0
  300. package/template/public/demo/avatar-8.svg +3 -0
  301. package/template/public/demo/collection-1.svg +1 -0
  302. package/template/public/demo/collection-2.svg +1 -0
  303. package/template/public/demo/cta-split.svg +1 -0
  304. package/template/public/demo/feature-1.svg +1 -0
  305. package/template/public/demo/feature-2.svg +1 -0
  306. package/template/public/demo/feature-3.svg +1 -0
  307. package/template/public/demo/feature-4.svg +1 -0
  308. package/template/public/demo/gallery-1.svg +1 -0
  309. package/template/public/demo/gallery-2.svg +1 -0
  310. package/template/public/demo/gallery-3.svg +1 -0
  311. package/template/public/demo/gallery-4.svg +1 -0
  312. package/template/public/demo/gallery-5.svg +1 -0
  313. package/template/public/demo/gallery-6.svg +1 -0
  314. package/template/public/demo/gallery-7.svg +1 -0
  315. package/template/public/demo/gallery-8.svg +1 -0
  316. package/template/public/demo/hero-slide-1.svg +1 -0
  317. package/template/public/demo/hero-slide-2.svg +1 -0
  318. package/template/public/demo/hero-slide-3.svg +1 -0
  319. package/template/public/demo/hero-slide-4.svg +1 -0
  320. package/template/public/demo/hero-wide.svg +1 -0
  321. package/template/public/demo/hero.svg +1 -0
  322. package/template/public/demo/logo-1.svg +4 -0
  323. package/template/public/demo/logo-2.svg +4 -0
  324. package/template/public/demo/logo-3.svg +4 -0
  325. package/template/public/demo/logo-4.svg +4 -0
  326. package/template/public/demo/logo-5.svg +4 -0
  327. package/template/public/demo/logo-6.svg +4 -0
  328. package/template/public/demo/logo-7.svg +4 -0
  329. package/template/public/demo/logo-8.svg +4 -0
  330. package/template/public/demo/logo.svg +3 -0
  331. package/template/public/demo/map.svg +1 -0
  332. package/template/public/demo/poster.svg +1 -0
  333. package/template/public/demo/product-1.svg +4 -0
  334. package/template/public/demo/product-10.svg +4 -0
  335. package/template/public/demo/product-11.svg +4 -0
  336. package/template/public/demo/product-12.svg +4 -0
  337. package/template/public/demo/product-2.svg +4 -0
  338. package/template/public/demo/product-3.svg +4 -0
  339. package/template/public/demo/product-4.svg +4 -0
  340. package/template/public/demo/product-5.svg +4 -0
  341. package/template/public/demo/product-6.svg +4 -0
  342. package/template/public/demo/product-7.svg +4 -0
  343. package/template/public/demo/product-8.svg +4 -0
  344. package/template/public/demo/product-9.svg +4 -0
  345. package/template/public/demo/product-square-1.svg +4 -0
  346. package/template/public/demo/product-square-2.svg +4 -0
  347. package/template/public/demo/product-square-3.svg +4 -0
  348. package/template/public/demo/product-square-4.svg +4 -0
  349. package/template/public/demo/product-square-5.svg +4 -0
  350. package/template/public/demo/product-square-6.svg +4 -0
  351. package/template/public/demo/quote-portrait.svg +4 -0
  352. package/template/public/demo/split-1.svg +1 -0
  353. package/template/public/demo/split-2.svg +1 -0
  354. package/template/public/demo/split-3.svg +1 -0
  355. package/template/public/demo/split-4.svg +1 -0
  356. package/template/public/demo/team-1.svg +4 -0
  357. package/template/public/demo/team-2.svg +4 -0
  358. package/template/public/demo/team-3.svg +4 -0
  359. package/template/public/demo/team-4.svg +4 -0
  360. package/template/public/favicon.ico +0 -0
  361. package/template/scripts/demo-images.mjs +393 -0
  362. package/template/scripts/generate-stories.mjs +156 -0
  363. package/template/scripts/previewHash.mjs +125 -0
  364. package/template/scripts/previews.mjs +149 -0
  365. package/template/stories/generated/announcement-bar.stories.ts +44 -0
  366. package/template/stories/generated/article-list.stories.ts +87 -0
  367. package/template/stories/generated/article.stories.ts +27 -0
  368. package/template/stories/generated/breadcrumbs.stories.ts +39 -0
  369. package/template/stories/generated/cart.stories.ts +38 -0
  370. package/template/stories/generated/collection-grid.stories.ts +117 -0
  371. package/template/stories/generated/collection-header.stories.ts +51 -0
  372. package/template/stories/generated/contact.stories.ts +45 -0
  373. package/template/stories/generated/cta.stories.ts +51 -0
  374. package/template/stories/generated/faq.stories.ts +56 -0
  375. package/template/stories/generated/feature-grid.stories.ts +69 -0
  376. package/template/stories/generated/footer.stories.ts +50 -0
  377. package/template/stories/generated/gallery.stories.ts +81 -0
  378. package/template/stories/generated/hero.stories.ts +75 -0
  379. package/template/stories/generated/image.stories.ts +99 -0
  380. package/template/stories/generated/logo-cloud.stories.ts +57 -0
  381. package/template/stories/generated/navigation.stories.ts +62 -0
  382. package/template/stories/generated/newsletter.stories.ts +68 -0
  383. package/template/stories/generated/order-status.stories.ts +32 -0
  384. package/template/stories/generated/pricing-table.stories.ts +44 -0
  385. package/template/stories/generated/product-carousel.stories.ts +75 -0
  386. package/template/stories/generated/product-detail.stories.ts +62 -0
  387. package/template/stories/generated/quote.stories.ts +69 -0
  388. package/template/stories/generated/rich-text.stories.ts +50 -0
  389. package/template/stories/generated/search.stories.ts +56 -0
  390. package/template/stories/generated/split-content.stories.ts +39 -0
  391. package/template/stories/generated/stats.stories.ts +68 -0
  392. package/template/stories/generated/tabs.stories.ts +45 -0
  393. package/template/stories/generated/team.stories.ts +45 -0
  394. package/template/stories/generated/testimonials.stories.ts +69 -0
  395. package/template/stories/generated/timeline.stories.ts +80 -0
  396. package/template/stories/generated/trust-strip.stories.ts +62 -0
  397. package/template/stories/generated/video-embed.stories.ts +63 -0
  398. package/template/stories/generated/wishlist.stories.ts +26 -0
  399. package/template/stories/pages/article.stories.ts +51 -0
  400. package/template/stories/pages/cart.stories.ts +56 -0
  401. package/template/stories/pages/category.stories.ts +56 -0
  402. package/template/stories/pages/collection.stories.ts +51 -0
  403. package/template/stories/pages/home.stories.ts +51 -0
  404. package/template/stories/pages/product.stories.ts +47 -0
  405. package/template/stories/pages/products.stories.ts +58 -0
  406. package/template/stories/pages/search.stories.ts +54 -0
  407. package/template/stories/pages/wishlist.stories.ts +53 -0
  408. package/template/stories/support/pageBlocks.ts +115 -0
  409. package/template/test/blocksEmptyData.spec.ts +52 -0
  410. package/template/test/carouselKeyboard.spec.ts +272 -0
  411. package/template/test/carouselRing.browser.spec.ts +193 -0
  412. package/template/test/carouselSlideWidth.browser.spec.ts +102 -0
  413. package/template/test/cartDrawer.spec.ts +295 -0
  414. package/template/test/cartToast.spec.ts +86 -0
  415. package/template/test/countPill.browser.spec.ts +196 -0
  416. package/template/test/demoImages.spec.ts +140 -0
  417. package/template/test/deps.spec.ts +102 -0
  418. package/template/test/eldraIcon.spec.ts +58 -0
  419. package/template/test/framing.spec.ts +76 -0
  420. package/template/test/i18n.spec.ts +200 -0
  421. package/template/test/iconComponent.spec.ts +91 -0
  422. package/template/test/inlineEditable.spec.ts +335 -0
  423. package/template/test/localePrefix.spec.ts +342 -0
  424. package/template/test/mainCss.spec.ts +107 -0
  425. package/template/test/mockGatewayContract.spec.ts +122 -0
  426. package/template/test/mocks/blocks.ts +20 -0
  427. package/template/test/mocks/breakpoints.ts +7 -0
  428. package/template/test/mocks/manifest.ts +11 -0
  429. package/template/test/moneyFormatting.spec.ts +85 -0
  430. package/template/test/pageTitle.spec.ts +49 -0
  431. package/template/test/pages/article.spec.ts +231 -0
  432. package/template/test/pages/category.spec.ts +185 -0
  433. package/template/test/pages/collection.spec.ts +396 -0
  434. package/template/test/pages/home.spec.ts +295 -0
  435. package/template/test/pages/hydration.spec.ts +557 -0
  436. package/template/test/pages/product.spec.ts +396 -0
  437. package/template/test/pages/seededPages.spec.ts +190 -0
  438. package/template/test/pages/ssr.spec.ts +387 -0
  439. package/template/test/prerenderCommerce.spec.ts +134 -0
  440. package/template/test/prerenderFailure.spec.ts +130 -0
  441. package/template/test/prerenderRefresh.browser.spec.ts +1431 -0
  442. package/template/test/previewsFresh.spec.ts +56 -0
  443. package/template/test/richText.spec.ts +164 -0
  444. package/template/test/richTextTypography.spec.ts +182 -0
  445. package/template/test/setup.ts +21 -0
  446. package/template/test/slugPage.spec.ts +244 -0
  447. package/template/test/slugPageTemplate.spec.ts +194 -0
  448. package/template/test/starter.spec.ts +1416 -0
  449. package/template/test/storefront/cart.spec.ts +404 -0
  450. package/template/test/storefront/categories.spec.ts +235 -0
  451. package/template/test/storefront/collectionSelector.spec.ts +74 -0
  452. package/template/test/storefront/demo.spec.ts +555 -0
  453. package/template/test/storefront/facets.spec.ts +425 -0
  454. package/template/test/storefront/feedback.spec.ts +97 -0
  455. package/template/test/storefront/gateway.spec.ts +2673 -0
  456. package/template/test/storefront/gatewayCart.spec.ts +289 -0
  457. package/template/test/storefront/gatewayPrerender.spec.ts +1037 -0
  458. package/template/test/storefront/history.spec.ts +341 -0
  459. package/template/test/storefront/money.spec.ts +170 -0
  460. package/template/test/storefront/toProductCard.spec.ts +138 -0
  461. package/template/test/storefront/volatile.spec.ts +284 -0
  462. package/template/test/support/axe.ts +14 -0
  463. package/template/test/support/dialog.ts +51 -0
  464. package/template/test/support/hydrate.ts +118 -0
  465. package/template/test/support/i18nText.ts +11 -0
  466. package/template/test/support/mockGateway.ts +1017 -0
  467. package/template/test/support/mountBlock.ts +194 -0
  468. package/template/test/support/mountPage.spec.ts +72 -0
  469. package/template/test/support/mountPage.ts +254 -0
  470. package/template/test/support/mountProbe.client.ts +69 -0
  471. package/template/test/support/renderSsr.ts +97 -0
  472. package/template/test/support/staticServer.ts +96 -0
  473. package/template/test/themeIcons.spec.ts +140 -0
  474. package/template/test/toastAnnouncement.spec.ts +133 -0
  475. package/template/test/tokens.spec.ts +102 -0
  476. package/template/test/uiMessagesPlugin.spec.ts +104 -0
  477. package/template/test/useBlockData.spec.ts +49 -0
  478. package/template/test/useEditing.spec.ts +54 -0
  479. package/template/test/useEldraIcon.spec.ts +126 -0
  480. package/template/test/useUiId.spec.ts +40 -0
  481. package/template/tokens.json +149 -0
  482. package/template/tsconfig.json +3 -0
  483. package/template/tsconfig.storybook.json +17 -0
  484. package/template/vitest-axe.d.ts +13 -0
  485. package/template/vitest.config.ts +44 -0
@@ -0,0 +1,476 @@
1
+ /**
2
+ * The shopper's facets, applied over a list of products, and the facets counted over that same list
3
+ * — **the demo storefront's half of the filter contract**, and the vocabulary both halves share.
4
+ *
5
+ * `collection-grid` sends `filters` keyed by its own `filters[].source` ids (see that block's
6
+ * `requestFiltersFor`): `category`, `collection`, `option:size`, `option:colour`, `availability`,
7
+ * and `price` as a single `"<min>-<max>"` string in whole major units with either end allowed to be
8
+ * empty. `createDemoStorefront` answers the whole of that request from its own fixture through
9
+ * `filterItems` and `deriveFacets`, which is what lets a Storybook story, a sample page and a spec
10
+ * filter for real with no gateway behind them — and what keeps a shopper from being shown a filter
11
+ * that moves the chips, the URL and the active-filter row while the grid stays as it was.
12
+ *
13
+ * `createGatewayStorefront` does neither: the catalog list filters and counts server-side
14
+ * (`gateway.ts`, public contract 3.7.0), over the whole collection rather than the rows one read
15
+ * could reach. What it still shares is `canonicalAvailability*` — which spellings the `availability`
16
+ * family has, including the retired hyphenated one a shared link may carry — because that is the
17
+ * theme's own vocabulary rather than any one backend's, and `collection-grid` reads a URL through it
18
+ * too.
19
+ *
20
+ * Everything here is pure: no Vue, no client, no module state — which is what lets
21
+ * `test/storefront/facets.spec.ts` pin every bound on its own.
22
+ */
23
+ import { ancestorsOf, EMPTY_CATEGORY_INDEX, type CategoryIndex } from './categories';
24
+ import type {
25
+ CatalogFacetOption,
26
+ CatalogFacetOptionValue,
27
+ CatalogFacetTerm,
28
+ CatalogFacets,
29
+ StorefrontProductListItem,
30
+ } from './types';
31
+
32
+ /** The `filters` key a variant option is named with: `option:colour`, `option:size`. */
33
+ export const OPTION_SOURCE_PREFIX = 'option:';
34
+ /** The one option key whose values a product *card* already carries (`item.colours`). */
35
+ export const COLOUR_OPTION_KEY = 'colour';
36
+
37
+ /**
38
+ * The two `availability` values the platform's facets count, and the whole filter vocabulary: the
39
+ * hyphenated spellings are read as well, so a link shared before the rename still filters.
40
+ *
41
+ * Anything else — `backorder` from a theme that offered it, a value some other storefront invented
42
+ * — is **unknown**, and an unknown clause is ignored rather than treated as unmatched, exactly as
43
+ * every other source in this file is. Reading it as "not in stock" showed a shopper following an
44
+ * old link nothing but the sold-out products, under a chip quoting the word they clicked.
45
+ */
46
+ export const IN_STOCK = 'in_stock';
47
+ export const OUT_OF_STOCK = 'out_of_stock';
48
+ const IN_STOCK_VALUES = new Set([IN_STOCK, 'in-stock']);
49
+ const OUT_OF_STOCK_VALUES = new Set([OUT_OF_STOCK, 'out-of-stock']);
50
+
51
+ /**
52
+ * The current spelling of one `availability` value, or `null` for a value this pass does not know.
53
+ *
54
+ * The block normalises its own state through this, so a legacy spelling out of a URL ticks the box
55
+ * it means instead of appearing beside it as an untranslated third row.
56
+ */
57
+ export function canonicalAvailability(value: string): string | null {
58
+ if (IN_STOCK_VALUES.has(value)) return IN_STOCK;
59
+ if (OUT_OF_STOCK_VALUES.has(value)) return OUT_OF_STOCK;
60
+ return null;
61
+ }
62
+
63
+ /** Every value of an `availability` clause in its current spelling, de-duplicated, unknowns
64
+ * dropped. `[]` when nothing in it is a value this vocabulary has. */
65
+ export function canonicalAvailabilityValues(values: readonly string[]): string[] {
66
+ const out: string[] = [];
67
+ for (const value of values) {
68
+ const canonical = canonicalAvailability(value);
69
+ if (canonical !== null && !out.includes(canonical)) out.push(canonical);
70
+ }
71
+ return out;
72
+ }
73
+
74
+ /** A category or collection a product belongs to: the `slug` is the filter value, the `title` is
75
+ * what the shopper reads, and `id` is the catalog id when the source knows one — which is also what
76
+ * a `category` clause resolves a parent through (see `matchesClause`). */
77
+ export interface ProductFacetTerm {
78
+ slug: string;
79
+ title?: string;
80
+ id?: string;
81
+ /** Where the term sits in the category tree — carried through to `CatalogFacetTerm.parentId`, which
82
+ * is what lets the filter panel nest it. Absent on a flat family, and on every collection. */
83
+ parentId?: string | null;
84
+ }
85
+
86
+ /** One value of one variant option, as the source knows it. */
87
+ export interface ProductFacetOptionValue {
88
+ value: string;
89
+ label?: string;
90
+ swatch?: string;
91
+ }
92
+
93
+ /**
94
+ * What a source knows about one product beyond what a product *card* shows. A property left
95
+ * `undefined` means "this backend cannot tell", and a filter on it is then **ignored** rather than
96
+ * treated as unmatched: a backend that does not know which sizes a product is made in has no
97
+ * business emptying the grid because the shopper ticked "M". An empty array is the opposite — a
98
+ * known "none", which matches nothing (an `options` bag with no entry for a key is unknown, not
99
+ * empty — see `optionValuesOf`).
100
+ */
101
+ export interface ProductFacetAttributes {
102
+ /** The category this product sits under. */
103
+ category?: ProductFacetTerm;
104
+ /** Every collection this product belongs to. */
105
+ collections?: readonly ProductFacetTerm[];
106
+ /** The option values this product is made in, keyed by option key (`size`, `colour`). */
107
+ options?: Readonly<Record<string, readonly ProductFacetOptionValue[]>>;
108
+ }
109
+
110
+ const NOTHING_KNOWN: ProductFacetAttributes = {};
111
+
112
+ /** How a caller supplies the per-product attributes neither a card nor a list row carries. */
113
+ export type ProductFacetAttributesFor = (
114
+ item: StorefrontProductListItem
115
+ ) => ProductFacetAttributes | undefined;
116
+
117
+ /**
118
+ * `"<min>-<max>"` in whole major units, either end empty for "no bound". **Both bounds are
119
+ * inclusive** — a shopper asking for 50–150 means 50 and 150 are in.
120
+ */
121
+ export function matchesPrice(item: StorefrontProductListItem, range: string | undefined): boolean {
122
+ if (range === undefined) return true;
123
+ const [rawMin = '', rawMax = ''] = range.split('-');
124
+ const amount = item.price.amount;
125
+ if (rawMin !== '' && amount < Number(rawMin)) return false;
126
+ if (rawMax !== '' && amount > Number(rawMax)) return false;
127
+ return true;
128
+ }
129
+
130
+ /** Orderable now: the one meaning "In stock" can have on a list row (see `item.stock`). */
131
+ function inStock(item: StorefrontProductListItem): boolean {
132
+ return item.available && item.stock !== 'out';
133
+ }
134
+
135
+ /**
136
+ * The values of one option for one product, or `undefined` when the source cannot tell.
137
+ *
138
+ * The one place the two sources of option values are reconciled, and it is shared by the filter
139
+ * and by the derivation on purpose: a value the panel offers has to be a value the pass can match,
140
+ * or ticking it changes the chips and the URL and nothing else. `attributes.options` is what a
141
+ * source declares; a product card's own `colours` is the fallback, because that is the one option
142
+ * a `StorefrontProductListItem` already carries.
143
+ *
144
+ * The unknown/empty distinction is per **option key**, not per bag: a key the source does not name
145
+ * is unknown and a filter on it is ignored (an option this store does not have — `option:fabric` —
146
+ * must not empty the grid), while a key named with an empty list is a known "none" and a filter on
147
+ * it excludes the product. So a source that can answer for an option answers for it explicitly,
148
+ * including with `[]`, which is what `createDemoStorefront` does for a product with no sizes.
149
+ */
150
+ export function optionValuesOf(
151
+ item: StorefrontProductListItem,
152
+ attributes: ProductFacetAttributes,
153
+ key: string
154
+ ): readonly ProductFacetOptionValue[] | undefined {
155
+ const declared = attributes.options?.[key];
156
+ if (declared !== undefined) return declared;
157
+ if (key === COLOUR_OPTION_KEY && item.colours !== undefined) {
158
+ return item.colours.map((colour) => ({
159
+ value: colour.name.toLowerCase(),
160
+ label: colour.name,
161
+ swatch: colour.swatch,
162
+ }));
163
+ }
164
+ return undefined;
165
+ }
166
+
167
+ /** One `filters` clause against one product. `true` for a clause this pass cannot judge. */
168
+ function matchesClause(
169
+ item: StorefrontProductListItem,
170
+ source: string,
171
+ selected: readonly string[],
172
+ attributes: ProductFacetAttributes,
173
+ categories: CategoryIndex
174
+ ): boolean {
175
+ if (source === 'price') return matchesPrice(item, selected[0]);
176
+ if (source === 'availability') {
177
+ const known = canonicalAvailabilityValues(selected);
178
+ if (known.length === 0) return true;
179
+ return known.some((value) => (value === IN_STOCK ? inStock(item) : !inStock(item)));
180
+ }
181
+ if (source === 'category') {
182
+ const term = attributes.category;
183
+ if (term?.slug === undefined) return true;
184
+ if (selected.includes(term.slug)) return true;
185
+ // **A ticked parent carries its whole branch.** The filter panel offers parent rows, and the
186
+ // platform's own `categoryId` filter expands a category to its descendants — so a product in
187
+ // `Cups` matches a shopper's `tableware`. Without the tree there is nothing to expand through
188
+ // and this is the direct match it always was.
189
+ if (term.id === undefined) return false;
190
+ return ancestorsOf(categories, term.id).some((ancestor) => selected.includes(ancestor.slug));
191
+ }
192
+ if (source === 'collection') {
193
+ const terms = attributes.collections;
194
+ if (terms === undefined) return true;
195
+ return selected.some((value) => terms.some((term) => term.slug === value));
196
+ }
197
+ if (source.startsWith(OPTION_SOURCE_PREFIX)) {
198
+ const values = optionValuesOf(item, attributes, source.slice(OPTION_SOURCE_PREFIX.length));
199
+ if (values === undefined) return true;
200
+ return selected.some((value) => values.some((candidate) => candidate.value === value));
201
+ }
202
+ // An unknown source is ignored rather than treated as "matches nothing": a backend that does
203
+ // not know a filter has no business emptying the grid because of it.
204
+ return true;
205
+ }
206
+
207
+ /**
208
+ * Every clause is AND-ed across sources and OR-ed within one source, the ordinary faceted-search
209
+ * semantics the block's own UI implies (ticking two colours widens, ticking a colour and a size
210
+ * narrows).
211
+ *
212
+ * `availability` and `price` read the item itself, so they work for any source. `category`,
213
+ * `collection` and `option:*` need `attributes`; see `ProductFacetAttributes` for what an absent
214
+ * one means.
215
+ */
216
+ export function matchesFilters(
217
+ item: StorefrontProductListItem,
218
+ filters: Record<string, string[]> | undefined,
219
+ attributes: ProductFacetAttributes = NOTHING_KNOWN,
220
+ /** The store's category tree, so a ticked **parent** category matches a product in a child of it.
221
+ * Omitted — a source with no tree — and a `category` clause is the direct match it always was. */
222
+ categories: CategoryIndex = EMPTY_CATEGORY_INDEX
223
+ ): boolean {
224
+ return matchesFiltersExcept(item, filters, null, attributes, categories);
225
+ }
226
+
227
+ /**
228
+ * `matchesFilters` with one source left out — the whole of the "counts ignore the facet's own
229
+ * filter" rule, and the reason it is written once here rather than in each source.
230
+ *
231
+ * `ignore` is a `filters` key (`category`, `option:colour`, `price`), or `null` to judge every
232
+ * clause.
233
+ */
234
+ export function matchesFiltersExcept(
235
+ item: StorefrontProductListItem,
236
+ filters: Record<string, string[]> | undefined,
237
+ ignore: string | null,
238
+ attributes: ProductFacetAttributes = NOTHING_KNOWN,
239
+ categories: CategoryIndex = EMPTY_CATEGORY_INDEX
240
+ ): boolean {
241
+ if (filters === undefined) return true;
242
+ for (const [source, selected] of Object.entries(filters)) {
243
+ if (selected.length === 0 || source === ignore) continue;
244
+ if (!matchesClause(item, source, selected, attributes, categories)) return false;
245
+ }
246
+ return true;
247
+ }
248
+
249
+ /** `matchesFilters` over a list, keeping the list's own order (so a server-side sort survives). */
250
+ export function filterItems(
251
+ items: readonly StorefrontProductListItem[],
252
+ filters: Record<string, string[]> | undefined,
253
+ attributesFor?: ProductFacetAttributesFor,
254
+ categories: CategoryIndex = EMPTY_CATEGORY_INDEX
255
+ ): StorefrontProductListItem[] {
256
+ if (!hasActiveFilters(filters)) return [...items];
257
+ return items.filter((item) => matchesFilters(item, filters, attributesFor?.(item), categories));
258
+ }
259
+
260
+ /** Whether a request carries anything to filter on at all — `{}` and `{colour: []}` do not. */
261
+ export function hasActiveFilters(filters: Record<string, string[]> | undefined): boolean {
262
+ if (filters === undefined) return false;
263
+ return Object.values(filters).some((selected) => selected.length > 0);
264
+ }
265
+
266
+ export interface DeriveFacetsOptions {
267
+ /** The filters the scope was read under, so each family's counts can ignore its own. */
268
+ filters?: Record<string, string[]>;
269
+ /** The per-product attributes a card does not carry (`category`, `collections`, `options`). */
270
+ attributesFor?: ProductFacetAttributesFor;
271
+ /**
272
+ * The store's category tree, so the `categories` family comes out **placed and counted up**: every
273
+ * term carries its `parentId`, every ancestor is a term of its own, and a product counts towards its
274
+ * own category and each ancestor above it (`categoryTermsOf`). That is what lets the filter panel
275
+ * draw parent rows — and it is only honest here because `matchesClause` expands a ticked parent to
276
+ * its descendants too, the way the platform's own `categoryId` does.
277
+ *
278
+ * Omitted — a source with no tree to declare — and the family is flat, its counts direct, exactly as
279
+ * it was: the panel then offers no parent row at all (`CatalogFacets.categoryCounts`).
280
+ */
281
+ categories?: CategoryIndex;
282
+ }
283
+
284
+ /**
285
+ * **The `facets` object counted in the client**, over the products a source holds — the demo
286
+ * storefront's answer, where the fixture *is* the whole catalogue.
287
+ *
288
+ * It answers the same `CatalogFacets` shape the platform does, under the same two rules
289
+ * (`types.ts`): a family's counts are computed with that family's own filter left out, and the
290
+ * price bounds with every filter except price applied. So ticking one colour leaves the other
291
+ * colours countable, and dragging a price thumb never moves the track.
292
+ *
293
+ * What it can see is bounded by what it was given. The vocabulary — which values exist, in which
294
+ * order, under which labels — comes from the items themselves and from `attributesFor`, so a
295
+ * backend that tells a source nothing about categories produces no category values rather than
296
+ * invented ones, and a value that only exists beyond the list is simply not there. That is the one
297
+ * limit a count made where the whole catalogue lives does not have.
298
+ */
299
+ export function deriveFacets(
300
+ items: readonly StorefrontProductListItem[],
301
+ options: DeriveFacetsOptions = {}
302
+ ): CatalogFacets {
303
+ const { filters, attributesFor, categories = EMPTY_CATEGORY_INDEX } = options;
304
+ const attributesOf = (item: StorefrontProductListItem): ProductFacetAttributes =>
305
+ attributesFor?.(item) ?? NOTHING_KNOWN;
306
+ /** The scope one family counts against: every filter but its own. */
307
+ const scopeWithout = (ignore: string): StorefrontProductListItem[] =>
308
+ items.filter((item) =>
309
+ matchesFiltersExcept(item, filters, ignore, attributesOf(item), categories)
310
+ );
311
+
312
+ return {
313
+ price: priceBounds(scopeWithout('price')),
314
+ categories: termFacet(items, scopeWithout('category'), (item) =>
315
+ categoryTermsOf(attributesOf(item).category, categories)
316
+ ),
317
+ // The ancestor counts above are this derivation's own and are **deduplicated**, because a product
318
+ // is counted once per term however many of its categories lead there. So the panel must not sum
319
+ // them again (`CatalogFacets.categoryCounts`) — unlike the platform's counts today, which are per
320
+ // assigned category and which the panel does roll up. A source with no tree declares nothing,
321
+ // which reads as `'direct'`, which is what a flat family is.
322
+ ...(categories.byId.size > 0 ? { categoryCounts: 'rolled-up' as const } : {}),
323
+ collections: termFacet(
324
+ items,
325
+ scopeWithout('collection'),
326
+ (item) => attributesOf(item).collections ?? []
327
+ ),
328
+ availability: availabilityCounts(scopeWithout('availability')),
329
+ options: optionFacets(items, scopeWithout, attributesOf),
330
+ };
331
+ }
332
+
333
+ /**
334
+ * **The category terms one product counts towards: its own, and every ancestor above it.**
335
+ *
336
+ * Both halves of why. A product assigned to `Cups` is a product in `Tableware`, and a filter on
337
+ * `tableware` returns it (`matchesClause` expands a ticked parent the same way the platform's own
338
+ * `categoryId` does) — so a facet that counted only the leaf would offer a parent row claiming 0 and
339
+ * then return 28, which is the one thing a count may never do. And the ancestors have to be in the
340
+ * *vocabulary* at all, or the parent row the shopper wants to tick is not there to tick: a catalogue
341
+ * of cups and bowls names those two and never names what they are.
342
+ *
343
+ * Counted **once per term**, because the vocabulary is a set: a product in two sibling categories is
344
+ * one product under their parent, not two.
345
+ *
346
+ * Without a tree there is nothing above anything, and this is the single direct term it always was.
347
+ */
348
+ function categoryTermsOf(
349
+ term: ProductFacetTerm | undefined,
350
+ categories: CategoryIndex
351
+ ): readonly ProductFacetTerm[] {
352
+ if (term === undefined) return [];
353
+ if (term.id === undefined || categories.byId.size === 0) return [term];
354
+ const placed = { ...term, parentId: categories.byId.get(term.id)?.parentId ?? null };
355
+ return [...ancestorsOf(categories, term.id), placed];
356
+ }
357
+
358
+ /** The span of the loaded items, or a zero span when there is nothing to span. */
359
+ function priceBounds(items: readonly StorefrontProductListItem[]): { min: number; max: number } {
360
+ if (items.length === 0) return { min: 0, max: 0 };
361
+ let min = Number.POSITIVE_INFINITY;
362
+ let max = Number.NEGATIVE_INFINITY;
363
+ for (const item of items) {
364
+ const amount = item.price.amount;
365
+ if (!Number.isFinite(amount)) continue;
366
+ if (amount < min) min = amount;
367
+ if (amount > max) max = amount;
368
+ }
369
+ if (!Number.isFinite(min) || !Number.isFinite(max)) return { min: 0, max: 0 };
370
+ return { min, max };
371
+ }
372
+
373
+ /**
374
+ * One term family (categories, collections): the vocabulary in the order the items first name it,
375
+ * counted over `scope` — the set every filter *but this family's own* was applied to. A term the
376
+ * other filters exclude is therefore listed with a count of 0 rather than dropped, which is what
377
+ * lets the panel disable it instead of making it disappear under the shopper's pointer.
378
+ */
379
+ function termFacet(
380
+ all: readonly StorefrontProductListItem[],
381
+ scope: readonly StorefrontProductListItem[],
382
+ termsOf: (item: StorefrontProductListItem) => readonly ProductFacetTerm[]
383
+ ): CatalogFacetTerm[] {
384
+ const vocabulary = new Map<string, ProductFacetTerm>();
385
+ for (const item of all) {
386
+ for (const term of termsOf(item)) {
387
+ if (!vocabulary.has(term.slug)) vocabulary.set(term.slug, term);
388
+ }
389
+ }
390
+ const counts = new Map<string, number>();
391
+ for (const item of scope) {
392
+ for (const term of termsOf(item)) {
393
+ counts.set(term.slug, (counts.get(term.slug) ?? 0) + 1);
394
+ }
395
+ }
396
+ return [...vocabulary.values()].map((term) => ({
397
+ id: term.id ?? term.slug,
398
+ slug: term.slug,
399
+ title: term.title ?? term.slug,
400
+ count: counts.get(term.slug) ?? 0,
401
+ ...(term.parentId === undefined ? {} : { parentId: term.parentId }),
402
+ }));
403
+ }
404
+
405
+ function availabilityCounts(items: readonly StorefrontProductListItem[]): {
406
+ in_stock: number;
407
+ out_of_stock: number;
408
+ } {
409
+ const available = items.filter(inStock).length;
410
+ return { in_stock: available, out_of_stock: items.length - available };
411
+ }
412
+
413
+ /**
414
+ * Every variant option the items name, each counted over the scope its *own* filter was left out
415
+ * of — so the colour counts narrow when a size is ticked and stay put when another colour is.
416
+ *
417
+ * `name` is the option's key: a product list row carries no display name for an option, and a
418
+ * group title the shopper reads belongs to the theme's own strings (`collection-grid` labels its
419
+ * groups from `filters[].label` or its i18n set), never to a raw store key.
420
+ */
421
+ function optionFacets(
422
+ all: readonly StorefrontProductListItem[],
423
+ scopeWithout: (ignore: string) => StorefrontProductListItem[],
424
+ attributesOf: (item: StorefrontProductListItem) => ProductFacetAttributes
425
+ ): CatalogFacetOption[] {
426
+ const vocabulary = new Map<string, Map<string, ProductFacetOptionValue>>();
427
+ for (const item of all) {
428
+ const attributes = attributesOf(item);
429
+ for (const key of optionKeysOf(item, attributes)) {
430
+ const values = optionValuesOf(item, attributes, key) ?? [];
431
+ const known = vocabulary.get(key) ?? new Map<string, ProductFacetOptionValue>();
432
+ vocabulary.set(key, known);
433
+ for (const value of values) {
434
+ if (!known.has(value.value)) known.set(value.value, value);
435
+ }
436
+ }
437
+ }
438
+
439
+ const out: CatalogFacetOption[] = [];
440
+ for (const [key, known] of vocabulary) {
441
+ const scope = scopeWithout(`${OPTION_SOURCE_PREFIX}${key}`);
442
+ const counts = new Map<string, number>();
443
+ for (const item of scope) {
444
+ for (const value of optionValuesOf(item, attributesOf(item), key) ?? []) {
445
+ counts.set(value.value, (counts.get(value.value) ?? 0) + 1);
446
+ }
447
+ }
448
+ const values: CatalogFacetOptionValue[] = [...known.values()].map((value) => ({
449
+ value: value.value,
450
+ label: value.label ?? value.value,
451
+ ...(value.swatch === undefined ? {} : { swatch: value.swatch }),
452
+ count: counts.get(value.value) ?? 0,
453
+ }));
454
+ // **The kind comes from the values, because this source has no merchant to ask.** A real store's
455
+ // facets carry the option's own `kind` (`gateway.ts`'s `mapFacets`); a derivation over product
456
+ // *cards* has only what those cards carry, and a swatch is the one thing only a `color` option
457
+ // ever has (`StorefrontProductListItem.colours`, `ProductFacetOptionValue.swatch`). Nothing is
458
+ // read off the key: an option named `colour` whose values carry no swatch is `none` here, the
459
+ // same answer the live site would give for an option a merchant left on None.
460
+ const kind = values.some((value) => value.swatch !== undefined) ? 'color' : 'none';
461
+ if (values.length > 0) out.push({ key, name: key, kind, values });
462
+ }
463
+ return out;
464
+ }
465
+
466
+ /** Which options one product has values for: what it declares, plus the card's own colours. */
467
+ function optionKeysOf(
468
+ item: StorefrontProductListItem,
469
+ attributes: ProductFacetAttributes
470
+ ): string[] {
471
+ const keys = Object.keys(attributes.options ?? {});
472
+ if (attributes.options?.[COLOUR_OPTION_KEY] === undefined && item.colours !== undefined) {
473
+ keys.push(COLOUR_OPTION_KEY);
474
+ }
475
+ return keys;
476
+ }
@@ -0,0 +1,122 @@
1
+ import { EldraHttpError } from '@eldrajs/sdk';
2
+
3
+ /**
4
+ * The one toast id for an add-to-cart attempt — success ("Added to cart", `cart.added`) and
5
+ * failure (`useStorefrontFeedback`'s report) alike, which is what lets a refusal replace a stale
6
+ * success toast and a later success replace a stale refusal in place, same position, rather than
7
+ * stacking a second one (`useToast`'s `id` dedupe). Shared between `blocks/product-detail/Block.vue`
8
+ * (which raises both) and `app/app.vue` (which dismisses it once the cart drawer the toast's own
9
+ * "View cart" action opens — or the header bag, or anything else — takes over as the confirmation),
10
+ * so the two can never drift onto different strings.
11
+ */
12
+ export const CART_ADD_TOAST_ID = 'product-add-to-cart';
13
+
14
+ /**
15
+ * The one toast id for the wishlist heart — "Saved to wishlist" and "Removed from wishlist" alike,
16
+ * so pressing the heart twice replaces the sentence in place instead of leaving two that contradict
17
+ * each other on screen. Separate from `CART_ADD_TOAST_ID` on purpose: a save must not dismiss the
18
+ * confirmation of an add the shopper has not acted on yet, and `app/app.vue`'s drawer dismissal must
19
+ * not take the wishlist's sentence with it. Named here rather than written inline at the one call
20
+ * site (`blocks/product-detail/Block.vue`) for the same reason its sibling above is: a bare string
21
+ * in a block is a string that drifts the moment a second file needs it.
22
+ */
23
+ export const WISHLIST_TOAST_ID = 'product-wishlist';
24
+
25
+ /**
26
+ * What a *failed storefront mutation* is, in one shape, and which sentence a shopper is told about
27
+ * it. Framework-free and pure: `app/storefront/cart.ts` records failures through
28
+ * `toStorefrontFailure`, and `app/composables/useStorefrontFeedback.ts` is the one place that turns
29
+ * one into a toast.
30
+ *
31
+ * **Why it exists.** A read that fails leaves the page showing what it already had, and the blocks
32
+ * say so in place (`StorefrontResult.error`). A *mutation* that fails leaves nothing behind: the
33
+ * shopper pressed Add to cart, the button's spinner stopped, and the page looks exactly as it did —
34
+ * so unless something says otherwise, a refusal is indistinguishable from a button that does
35
+ * nothing. That is what happened to a real add the gateway answered `409
36
+ * { code: 'CONFLICT', errorId: 'CART_INSUFFICIENT_STOCK' }`.
37
+ *
38
+ * **Why the message is not the backend's.** `EldraHttpError.message` is "Web Studio request failed
39
+ * with 409 Conflict". It is the right thing to keep for a developer and the wrong thing to show a
40
+ * shopper, so `message` below stays out of the UI and the copy is chosen from `errorId` here instead
41
+ * — one mapping, in one file, rather than a sentence invented by each block that mutates.
42
+ */
43
+ export interface StorefrontFailure {
44
+ /** The thrown error's own message. For diagnosis, never for display — see above. */
45
+ message: string;
46
+ /** The problem body's `errorId`: which failure this is (`CART_INSUFFICIENT_STOCK`). */
47
+ errorId: string | null;
48
+ /** The problem body's `code`: the *class* of failure (`CONFLICT`), shared by unrelated refusals. */
49
+ code: string | null;
50
+ /** The HTTP status, when the failure was an answer at all rather than a dropped request. */
51
+ status: number | null;
52
+ }
53
+
54
+ /** The gateway refused the add because the stock is not there. */
55
+ const INSUFFICIENT_STOCK = 'CART_INSUFFICIENT_STOCK';
56
+
57
+ /**
58
+ * The failures this theme has its own words for, by the `errorId` the cart service actually sends.
59
+ * Everything else — and every failure that never reached the gateway — gets
60
+ * `storefront.mutationFailed`, because a sentence a shopper cannot act on is worse than the plain
61
+ * one: naming an `errorId` at them is noise, and guessing a cause from a status is how "check your
62
+ * spelling" ends up in front of someone whose connection dropped. The cart service's remaining ids
63
+ * are about the store's own internals (database, marshalling, version conflicts) or about the
64
+ * discount field, which reports itself inline (`blocks/cart/parts/Summary.vue`); neither is something
65
+ * a shopper can do anything with.
66
+ */
67
+ const MESSAGE_BY_ERROR_ID: Record<string, MessageKey> = {
68
+ [INSUFFICIENT_STOCK]: 'storefront.outOfStock',
69
+ // The product, or the variant of it, no longer resolves — discontinued since the page was built,
70
+ // or never buyable at all.
71
+ CART_INVALID_PRODUCT: 'storefront.unavailable',
72
+ CART_INVALID_PRODUCT_ID: 'storefront.unavailable',
73
+ CART_INVALID_VARIANT_ID: 'storefront.unavailable',
74
+ // The cart, or the line in it, is not there any more: the shopper's page is describing a cart the
75
+ // store has moved on from, and reloading is the one thing that fixes it.
76
+ CART_NOT_FOUND: 'storefront.cartOutOfDate',
77
+ CART_ITEM_NOT_FOUND: 'storefront.cartOutOfDate',
78
+ };
79
+
80
+ /**
81
+ * Reads the structured halves off whatever was thrown. `@eldrajs/sdk` throws `EldraHttpError` for
82
+ * any non-2xx answer, carrying the problem body's `code`/`errorId`; a request that never got an
83
+ * answer (offline, aborted) throws an ordinary `Error`, which has neither — and that difference is
84
+ * itself information, so it is kept rather than flattened into a string.
85
+ */
86
+ export function toStorefrontFailure(caught: unknown): StorefrontFailure {
87
+ if (caught instanceof EldraHttpError) {
88
+ return {
89
+ message: caught.message,
90
+ errorId: caught.errorId ?? null,
91
+ code: caught.code ?? null,
92
+ status: caught.status,
93
+ };
94
+ }
95
+ return {
96
+ message: caught instanceof Error ? caught.message : 'Something went wrong.',
97
+ errorId: null,
98
+ code: null,
99
+ status: null,
100
+ };
101
+ }
102
+
103
+ /** The sentence to show for a failure — `storefront.mutationFailed` unless it names a known cause. */
104
+ export function failureMessageKey(failure: StorefrontFailure | null): MessageKey {
105
+ if (failure === null) return 'storefront.mutationFailed';
106
+ // `code` is read only as a tolerance: today's gateway always sends an `errorId` beside the generic
107
+ // `code` (`CONFLICT`), and this costs nothing should a refusal ever arrive with only the one field.
108
+ return (
109
+ MESSAGE_BY_ERROR_ID[failure.errorId ?? ''] ??
110
+ MESSAGE_BY_ERROR_ID[failure.code ?? ''] ??
111
+ 'storefront.mutationFailed'
112
+ );
113
+ }
114
+
115
+ /**
116
+ * Was this refusal about stock — the one failure a *page* reacts to and not only reports. The
117
+ * product page flips its own stock line to sold out on it, because the cart service has just proved
118
+ * it knows something the page's own read did not.
119
+ */
120
+ export function isOutOfStock(failure: StorefrontFailure | null): boolean {
121
+ return failure !== null && failureMessageKey(failure) === 'storefront.outOfStock';
122
+ }