@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,1313 @@
1
+ import { nextTick, reactive, ref, watch, type Ref } from 'vue';
2
+ import { createCartStore, type CartOps, type CartSnapshot } from './cart';
3
+ import { createHistoryStore, createWishlistStore } from './history';
4
+ import { roundMoney } from './money';
5
+ import { optionDisplayType } from './options';
6
+ import {
7
+ deriveFacets,
8
+ filterItems,
9
+ type ProductFacetAttributes,
10
+ type ProductFacetTerm,
11
+ } from './facets';
12
+ import {
13
+ buildCategoryIndex,
14
+ categoryTrailFor,
15
+ isInSubtree,
16
+ placeCategory,
17
+ type CategoryRow,
18
+ } from './categories';
19
+ import type {
20
+ StorefrontAck,
21
+ StorefrontCartLine,
22
+ StorefrontCartTotals,
23
+ StorefrontCatalog,
24
+ StorefrontCollectionInfo,
25
+ StorefrontCollectionSelector,
26
+ StorefrontCommerce,
27
+ StorefrontForms,
28
+ StorefrontMedia,
29
+ StorefrontOrder,
30
+ StorefrontOrderStatus,
31
+ StorefrontOrders,
32
+ StorefrontProduct,
33
+ StorefrontProductListItem,
34
+ StorefrontResult,
35
+ StorefrontRoute,
36
+ StorefrontSearch,
37
+ StorefrontSearchResponse,
38
+ StorefrontSource,
39
+ VolatileKey,
40
+ VolatileSnapshot,
41
+ } from './types';
42
+
43
+ /**
44
+ * Northwind Goods — the fictional store every commerce block demos against (plan §"Global
45
+ * Constraints": Portland, Oregon studio, USD, free shipping over $80, 30-day returns, 10 %
46
+ * newsletter code). This is the data `test/support/mountBlock.ts` and `.storybook/eldra.ts` inject
47
+ * for every block/story/preview, and what `test/storefront/demo.spec.ts` checks against the
48
+ * catalogue named in `eldra-starter-spec/02-blocks.md` (lines 3140–3142, 3270–3272, 3373–3375,
49
+ * 3581–3583, 3692–3694, 3806–3811).
50
+ *
51
+ * Money is major units throughout — see `types.ts`.
52
+ */
53
+
54
+ const FREE_SHIPPING_THRESHOLD = 80; // $80.00
55
+ const FLAT_SHIPPING = 6; // $6.00, below the free-shipping threshold
56
+
57
+ function demoImage(index: number, alt: string): StorefrontMedia {
58
+ // Only `product-1`..`product-6` exist in `public/demo/` today (scripts/demo-images.mjs) — a
59
+ // commerce block that needs more can extend that manifest. Money doesn't come into it, this
60
+ // just cycles through what already exists.
61
+ const name = `product-${((index - 1) % 6) + 1}`;
62
+ return { src: `/demo/${name}.svg`, alt };
63
+ }
64
+
65
+ // ---------------------------------------------------------------------------------------------
66
+ // Catalogue
67
+ // ---------------------------------------------------------------------------------------------
68
+
69
+ /** The `category` facet's own values — the fixture's **leaves** (`DEMO_CATEGORIES`). */
70
+ type DemoCategory = 'knitwear' | 'ceramics' | 'kitchen';
71
+
72
+ interface DemoProductDef {
73
+ handle: string;
74
+ title: string;
75
+ amount: number;
76
+ compareAt?: number;
77
+ stock: 'in' | 'low' | 'out' | 'preorder';
78
+ available: boolean;
79
+ /**
80
+ * The fixture's **variant** id for this product's first buyable variant. The product's own id is
81
+ * its `handle` (`buildListItem` below): the two are different ids in the demo exactly as they are
82
+ * in a real catalogue, so every path that has to send the pair — a cart add, above all — is
83
+ * exercised here rather than passing by accident because one id stood in for both.
84
+ */
85
+ variantId: string;
86
+ rating?: { value: number; count: number } | null;
87
+ colours?: Array<{ name: string; swatch: string }>;
88
+ /**
89
+ * Which `category` facet value this product sits under, and which `size` values it is made in
90
+ * (apparel only). Neither is part of `StorefrontProductListItem` — a product *card* never shows
91
+ * them — but `collectionProducts` needs them to answer a filtered request, which is what a real
92
+ * backend does from the same underlying product data. `PRODUCT_ATTRIBUTES` below is the lookup.
93
+ */
94
+ category: DemoCategory;
95
+ sizes?: string[];
96
+ }
97
+
98
+ const PRODUCT_DEFS: DemoProductDef[] = [
99
+ {
100
+ handle: 'merino-crew-sweater',
101
+ category: 'knitwear',
102
+ sizes: ['xs', 's', 'm', 'l', 'xl'],
103
+ title: 'Merino crew sweater',
104
+ amount: 96,
105
+ compareAt: 128,
106
+ stock: 'in',
107
+ available: true,
108
+ variantId: 'merino-crew-sweater::oat::m',
109
+ rating: { value: 4.5, count: 126 },
110
+ colours: [
111
+ { name: 'Oat', swatch: '#d8cbb0' },
112
+ { name: 'Charcoal', swatch: '#3a3a3a' },
113
+ { name: 'Clay', swatch: '#b5651d' },
114
+ { name: 'Moss', swatch: '#6b7a4f' },
115
+ ],
116
+ },
117
+ {
118
+ handle: 'fisherman-rib-cardigan',
119
+ category: 'knitwear',
120
+ sizes: ['xs', 's', 'm', 'l', 'xl'],
121
+ title: 'Fisherman rib cardigan',
122
+ amount: 164,
123
+ stock: 'in',
124
+ available: true,
125
+ variantId: 'fisherman-rib-cardigan::natural::m',
126
+ },
127
+ {
128
+ handle: 'lambswool-throw-blanket',
129
+ category: 'knitwear',
130
+ title: 'Lambswool throw blanket',
131
+ amount: 148,
132
+ stock: 'in',
133
+ available: true,
134
+ variantId: 'lambswool-throw-blanket::default',
135
+ },
136
+ {
137
+ handle: 'ribbed-lambswool-beanie',
138
+ category: 'knitwear',
139
+ sizes: ['s', 'm', 'l'],
140
+ title: 'Ribbed lambswool beanie',
141
+ amount: 38,
142
+ stock: 'in',
143
+ available: true,
144
+ variantId: 'ribbed-lambswool-beanie::default',
145
+ },
146
+ {
147
+ handle: 'linen-tea-towels-pair',
148
+ category: 'kitchen',
149
+ title: 'Linen tea towels, pair',
150
+ amount: 24,
151
+ stock: 'out',
152
+ available: false,
153
+ variantId: 'linen-tea-towels-pair::natural',
154
+ },
155
+ {
156
+ handle: 'speckled-latte-mug',
157
+ category: 'ceramics',
158
+ title: 'Speckled latte mug',
159
+ amount: 28,
160
+ stock: 'in',
161
+ available: true,
162
+ variantId: 'speckled-latte-mug::clay',
163
+ colours: [{ name: 'Clay', swatch: '#b5651d' }],
164
+ },
165
+ {
166
+ handle: 'stoneware-dinner-plates-set-of-4',
167
+ category: 'ceramics',
168
+ title: 'Stoneware dinner plates, set of 4',
169
+ amount: 72,
170
+ stock: 'in',
171
+ available: true,
172
+ variantId: 'stoneware-dinner-plates-set-of-4::default',
173
+ },
174
+ {
175
+ handle: 'walnut-serving-board',
176
+ category: 'kitchen',
177
+ title: 'Walnut serving board',
178
+ amount: 58,
179
+ stock: 'in',
180
+ available: true,
181
+ variantId: 'walnut-serving-board::large',
182
+ },
183
+ {
184
+ handle: 'hand-thrown-serving-bowl',
185
+ category: 'ceramics',
186
+ title: 'Hand-thrown serving bowl',
187
+ amount: 64,
188
+ stock: 'in',
189
+ available: true,
190
+ variantId: 'hand-thrown-serving-bowl::default',
191
+ },
192
+ {
193
+ handle: 'glazed-milk-jug',
194
+ category: 'ceramics',
195
+ title: 'Glazed milk jug',
196
+ amount: 34,
197
+ stock: 'in',
198
+ available: true,
199
+ variantId: 'glazed-milk-jug::default',
200
+ },
201
+ {
202
+ handle: 'linen-napkins-set-of-4',
203
+ category: 'kitchen',
204
+ title: 'Linen napkins, set of 4',
205
+ amount: 40,
206
+ stock: 'in',
207
+ available: true,
208
+ variantId: 'linen-napkins-set-of-4::natural',
209
+ },
210
+ {
211
+ handle: 'stonewashed-linen-throw',
212
+ category: 'knitwear',
213
+ title: 'Stonewashed linen throw',
214
+ amount: 118,
215
+ stock: 'in',
216
+ available: true,
217
+ variantId: 'stonewashed-linen-throw::default',
218
+ },
219
+ ];
220
+
221
+ /**
222
+ * The filterable/sortable attributes of one product, keyed by the *item* handle — including the
223
+ * suffixed clones `buildCollectionItems` makes (`merino-crew-sweater-2`), whose handles cannot be
224
+ * mapped back to a def by string surgery (`stoneware-dinner-plates-set-of-4` already ends in a
225
+ * number). Populated as items are built, which is why every item is created through
226
+ * `buildListItem`/`buildCollectionItems` and never by hand.
227
+ */
228
+ /**
229
+ * **The fixture's category tree**, in the shape `GET /catalog/v1/categories` answers: one row per
230
+ * category, a tree by `parentId`.
231
+ *
232
+ * Two levels and one shallow branch on purpose, because that is the shape a real store has and the
233
+ * shape both features need to be exercised at all: `Homeware` holds `Ceramics` and `Kitchen`, while
234
+ * `Knitwear` is a root with nothing under it. So a product page's trail is two crumbs for a mug
235
+ * (`Homeware / Ceramics`) and one for a sweater (`Knitwear`), and the collection grid's category
236
+ * group draws one parent row with two indented children beside one plain row — with `Homeware`
237
+ * itself counting nothing directly, which is exactly the parent a flat facet never names.
238
+ *
239
+ * The root is titled **Homeware** rather than "Home", which it was until the category page existed:
240
+ * its own page's breadcrumb starts at the site's `Home` crumb, and a trail reading "Home › Home ›
241
+ * Ceramics" is a fixture that teaches the wrong thing. The slug is untouched, so every path and
242
+ * every `?category=` value in the fixtures is the same.
243
+ *
244
+ * Ids are the slugs here. The demo keeps product ids and variant ids deliberately distinct (see
245
+ * `DemoProductDef.variantId`) because a *request* sends both and they must not pass by accident; a
246
+ * category id is only ever looked up against this list, so a readable id is worth more than a fake
247
+ * uuid — and every lookup that matters (`categoryTrailFor`, `ancestorsOf`) keys on ids either way.
248
+ */
249
+ const DEMO_CATEGORIES: readonly CategoryRow[] = [
250
+ { id: 'home', slug: 'home', title: 'Homeware', parentId: null },
251
+ { id: 'knitwear', slug: 'knitwear', title: 'Knitwear', parentId: null },
252
+ { id: 'ceramics', slug: 'ceramics', title: 'Ceramics', parentId: 'home' },
253
+ { id: 'kitchen', slug: 'kitchen', title: 'Kitchen', parentId: 'home' },
254
+ ];
255
+
256
+ /** The tree indexed both ways, for the trail and for placing the facet's own terms. */
257
+ const CATEGORY_INDEX = buildCategoryIndex(DEMO_CATEGORIES);
258
+
259
+ /** What a `category` facet value is called where a shopper reads it. */
260
+ const CATEGORY_TITLES: Record<DemoCategory, string> = {
261
+ knitwear: 'Knitwear',
262
+ ceramics: 'Ceramics',
263
+ kitchen: 'Kitchen',
264
+ };
265
+
266
+ const NO_ATTRIBUTES: ProductFacetAttributes = { options: {} };
267
+ const PRODUCT_ATTRIBUTES = new Map<string, ProductFacetAttributes>();
268
+
269
+ /**
270
+ * The attributes in `app/storefront/facets.ts`'s own shape — the same one `createGatewayStorefront`
271
+ * builds from a product list row — so the demo and the live site filter *and* count by exactly the
272
+ * same rules. Labels and swatches ride along with the values, which is what lets `deriveFacets`
273
+ * answer a facet a shopper can read ("Oat", "M") rather than a raw key.
274
+ *
275
+ * `collections` is deliberately absent here and filled in by `attributesFor` instead: which
276
+ * collections hold a product is a fact about the fixture's collections, which are declared below
277
+ * this line.
278
+ */
279
+ function registerAttributes(handle: string, def: DemoProductDef): void {
280
+ PRODUCT_ATTRIBUTES.set(handle, {
281
+ // The `id` is what a parent clause is resolved through — `matchesClause` walks a product's own
282
+ // category up the tree — and what `categoryTermsOf` places the facet's own terms by.
283
+ category: { id: def.category, slug: def.category, title: CATEGORY_TITLES[def.category] },
284
+ options: {
285
+ size: (def.sizes ?? []).map((size) => ({ value: size, label: size.toUpperCase() })),
286
+ colour: (def.colours ?? []).map((colour) => ({
287
+ value: colour.name.toLowerCase(),
288
+ label: colour.name,
289
+ swatch: colour.swatch,
290
+ })),
291
+ },
292
+ });
293
+ }
294
+
295
+ function buildListItem(def: DemoProductDef, index: number): StorefrontProductListItem {
296
+ registerAttributes(def.handle, def);
297
+ return {
298
+ handle: def.handle,
299
+ title: def.title,
300
+ url: `/products/${def.handle}`,
301
+ featuredImage: demoImage(index + 1, def.title),
302
+ price: { amount: def.amount, compareAt: def.compareAt ?? null },
303
+ rating: def.rating ?? null,
304
+ colours: def.colours,
305
+ stock: def.stock,
306
+ available: def.available,
307
+ productId: def.handle,
308
+ };
309
+ }
310
+
311
+ /** The Northwind catalogue — exactly the twelve products the block specs name. */
312
+ export const PRODUCTS: StorefrontProductListItem[] = PRODUCT_DEFS.map(buildListItem);
313
+
314
+ /**
315
+ * One option as the fixture declares it: the merchant's facts — the key, the label, the display kind
316
+ * and the values — with `type` derived from the kind *and the values* by the same function the
317
+ * gateway source uses (`optionDisplayType`). Going through it rather than writing `'swatches'` is
318
+ * what keeps Storybook honest: the demo's swatches are there for the reason the live site's are, and
319
+ * a fixture that declared `kind: 'color'` and forgot the colours would draw pills here exactly as it
320
+ * would on a real store.
321
+ */
322
+ function demoOption(
323
+ option: Omit<StorefrontProduct['options'][number], 'type'>
324
+ ): StorefrontProduct['options'][number] {
325
+ return { ...option, type: optionDisplayType(option.kind, option.values) };
326
+ }
327
+
328
+ /**
329
+ * The fixture's own option set, and the one place in the demo that declares a display kind. Colour is
330
+ * `color` with a colour on every value, so it draws swatches; size is `none` — a plain list of
331
+ * values, and what every option looked like before the field existed.
332
+ */
333
+ const MERINO_OPTIONS: StorefrontProduct['options'] = [
334
+ demoOption({
335
+ name: 'colour',
336
+ label: 'Colour',
337
+ kind: 'color',
338
+ values: [
339
+ { value: 'oat', label: 'Oat', swatch: '#d8cbb0', available: true },
340
+ { value: 'charcoal', label: 'Charcoal', swatch: '#3a3a3a', available: true },
341
+ { value: 'clay', label: 'Clay', swatch: '#b5651d', available: true },
342
+ { value: 'moss', label: 'Moss', swatch: '#6b7a4f', available: false },
343
+ ],
344
+ }),
345
+ demoOption({
346
+ name: 'size',
347
+ label: 'Size',
348
+ kind: 'none',
349
+ values: [
350
+ { value: 'xs', label: 'XS', available: true },
351
+ { value: 's', label: 'S', available: true },
352
+ { value: 'm', label: 'M', available: true },
353
+ { value: 'l', label: 'L', available: true },
354
+ { value: 'xl', label: 'XL', available: false },
355
+ ],
356
+ }),
357
+ ];
358
+
359
+ function buildFullProduct(def: DemoProductDef, index: number): StorefrontProduct {
360
+ const listItem = buildListItem(def, index);
361
+ const isMerino = def.handle === 'merino-crew-sweater';
362
+ return {
363
+ ...listItem,
364
+ variantId: def.variantId,
365
+ images: [demoImage(index + 1, def.title), demoImage(index + 7, `${def.title}, alternate view`)],
366
+ options: isMerino ? MERINO_OPTIONS : [],
367
+ // Walked up the fixture's own tree from the product's category, exactly as
368
+ // `createGatewayStorefront` walks the store's: `Home / Ceramics` for a mug, `Knitwear` for a
369
+ // sweater, and each level a link into the catalogue filtered by it. Hand-written levels used to
370
+ // stand here, pointing at `/collections/knitwear/sweaters` — a route this theme has never served.
371
+ categoryTrail: categoryTrailFor(CATEGORY_INDEX, def.category),
372
+ description: isMerino
373
+ ? 'A relaxed crew knitted from extra-fine Merino in a family mill in Biella. Soft enough to wear next to skin, warm without the bulk.'
374
+ : `${def.title}, from Northwind Goods' Portland studio.`,
375
+ inventory: def.available ? 42 : 0,
376
+ shipsBy: def.available ? 'Tue 29 Sep – Thu 1 Oct' : null,
377
+ };
378
+ }
379
+
380
+ const PRODUCTS_FULL: Record<string, StorefrontProduct> = Object.fromEntries(
381
+ PRODUCT_DEFS.map((def, index) => [def.handle, buildFullProduct(def, index)])
382
+ );
383
+
384
+ /** Every fixture product a volatile refresh could be asked about, by the id a card carries. */
385
+ const PRODUCTS_BY_ID = new Map(PRODUCTS.map((product) => [product.productId, product]));
386
+
387
+ /**
388
+ * The demo half of `catalog.volatileByIds`. The fixture never changes, so this always answers with
389
+ * exactly the values the page already has — which is the point: it proves the refresh path end to
390
+ * end (ids out, snapshots back, `applyVolatileSnapshots` keeping every object at its identity)
391
+ * without a story or a spec ever seeing a price move under it.
392
+ *
393
+ * An id the catalogue does not know is simply absent from the answer, the same way the gateway's
394
+ * own `id:in:` read answers, and no `inventory` is reported — the products list carries none.
395
+ */
396
+ function demoVolatileSnapshots(ids: readonly string[]): VolatileSnapshot[] {
397
+ const snapshots: VolatileSnapshot[] = [];
398
+ for (const id of ids) {
399
+ const product = PRODUCTS_BY_ID.get(id);
400
+ if (!product) continue;
401
+ snapshots.push({
402
+ id: product.productId,
403
+ price: product.price,
404
+ available: product.available,
405
+ stock: product.stock,
406
+ });
407
+ }
408
+ return snapshots;
409
+ }
410
+
411
+ /** "You may also like" (`product-carousel`'s `related` variant default content). */
412
+ const RELATED_HANDLES = [
413
+ 'fisherman-rib-cardigan',
414
+ 'ribbed-lambswool-beanie',
415
+ 'lambswool-throw-blanket',
416
+ 'merino-crew-sweater',
417
+ 'speckled-latte-mug',
418
+ 'hand-thrown-serving-bowl',
419
+ 'walnut-serving-board',
420
+ ];
421
+ const RELATED_ITEMS = RELATED_HANDLES.map((handle) =>
422
+ PRODUCTS.find((product) => product.handle === handle)!
423
+ );
424
+
425
+ /** `product-carousel`'s `recently-viewed` variant default content. */
426
+ const DEFAULT_RECENTLY_VIEWED = [
427
+ 'speckled-latte-mug',
428
+ 'stoneware-dinner-plates-set-of-4',
429
+ 'linen-tea-towels-pair',
430
+ 'glazed-milk-jug',
431
+ 'ribbed-lambswool-beanie',
432
+ 'hand-thrown-serving-bowl',
433
+ ];
434
+
435
+ // ---------------------------------------------------------------------------------------------
436
+ // Collections
437
+ // ---------------------------------------------------------------------------------------------
438
+
439
+ /** A curated subset of `PRODUCTS`, not a slice by position — see the `best-sellers` entry below. */
440
+ const BEST_SELLER_HANDLES = [
441
+ 'merino-crew-sweater',
442
+ 'speckled-latte-mug',
443
+ 'walnut-serving-board',
444
+ 'hand-thrown-serving-bowl',
445
+ 'stoneware-dinner-plates-set-of-4',
446
+ 'ribbed-lambswool-beanie',
447
+ ];
448
+ const BEST_SELLER_ITEMS: StorefrontProductListItem[] = BEST_SELLER_HANDLES.map((handle) =>
449
+ PRODUCTS.find((product) => product.handle === handle)!
450
+ );
451
+
452
+ const COLLECTIONS: Record<string, StorefrontCollectionInfo> = {
453
+ 'winter-knitwear': {
454
+ handle: 'winter-knitwear',
455
+ title: 'Winter knitwear',
456
+ description:
457
+ 'Heavy-gauge knits for the coldest months, from our Portland studio and two family mills in Biella and the Scottish Borders.',
458
+ image: demoImage(1, 'Winter knitwear'),
459
+ productCount: 48,
460
+ },
461
+ 'the-winter-edit': {
462
+ handle: 'the-winter-edit',
463
+ title: 'The winter edit',
464
+ description:
465
+ 'Heavy-gauge knits, stoneware for slow breakfasts and kitchen goods for the cold months, from our Portland studio and two family mills in Biella and the Scottish Borders.',
466
+ image: demoImage(2, 'The winter edit'),
467
+ productCount: 48,
468
+ },
469
+ /**
470
+ * `search`'s own `noResultsCollection` mock value (`blocks/search/mock.json`) — "Customers love
471
+ * these" on the no-results page (spec `02-blocks.md` "Search results page" → Default content:
472
+ * "Merino crew sweater, Speckled latte mug"), those two first so a `.slice(0, 4)` still leads
473
+ * with them.
474
+ */
475
+ 'best-sellers': {
476
+ handle: 'best-sellers',
477
+ title: 'Best sellers',
478
+ description: 'The Northwind pieces shoppers reach for again and again.',
479
+ image: demoImage(6, 'Best sellers'),
480
+ productCount: BEST_SELLER_HANDLES.length,
481
+ },
482
+ };
483
+
484
+ /**
485
+ * The demo's catalog collection ids — what a CMS `reference` field stores when an
486
+ * author picks a collection in Studio, and all a page builder draft overlay or a
487
+ * depth-0 read hands a block. Keyed by id so `collectionProducts({ id })`
488
+ * resolves to the handle the rest of this fixture is keyed by, which is exactly
489
+ * what the real gateway does (`gateway.ts`'s `resolveCollectionSlug`). An id
490
+ * nobody here knows resolves to nothing, like any other unknown collection.
491
+ */
492
+ const COLLECTION_HANDLES_BY_ID: Record<string, string> = {
493
+ '2f1b8d54-0d3a-4a6f-9a0b-7f6c1d2e3a01': 'winter-knitwear',
494
+ '2f1b8d54-0d3a-4a6f-9a0b-7f6c1d2e3a02': 'the-winter-edit',
495
+ '2f1b8d54-0d3a-4a6f-9a0b-7f6c1d2e3a03': 'best-sellers',
496
+ };
497
+
498
+ /** The id the demo fixture knows a collection by — the value a `reference` field
499
+ * carries for it, so a story or a test can seed one without repeating a uuid. */
500
+ export function demoCollectionId(handle: string): string | null {
501
+ const found = Object.entries(COLLECTION_HANDLES_BY_ID).find(([, slug]) => slug === handle);
502
+ return found?.[0] ?? null;
503
+ }
504
+
505
+ /** Collections whose items are a curated list rather than `buildCollectionItems`'s generic cycle
506
+ * through `PRODUCTS` by position — currently only `best-sellers`. */
507
+ const COLLECTION_ITEMS: Record<string, StorefrontProductListItem[]> = {
508
+ 'best-sellers': BEST_SELLER_ITEMS,
509
+ };
510
+
511
+ /**
512
+ * **The whole catalogue**, as `catalog.products` answers it: every fixture product, padded with the
513
+ * same suffixed clones a collection is padded with, so the `/products` page has a realistic number of
514
+ * rows to page and count over rather than the fixture's twelve.
515
+ */
516
+ const CATALOGUE_ITEMS: StorefrontProductListItem[] = buildCollectionItems(48);
517
+
518
+ function buildCollectionItems(total: number): StorefrontProductListItem[] {
519
+ return Array.from({ length: total }, (_, i) => {
520
+ const base = PRODUCTS[i % PRODUCTS.length]!;
521
+ const cycle = Math.floor(i / PRODUCTS.length);
522
+ if (cycle === 0) return base;
523
+ const suffix = `-${cycle + 1}`;
524
+ const handle = `${base.handle}${suffix}`;
525
+ // A clone is the same product in the shopper's eyes, so it filters and sorts identically.
526
+ registerAttributes(handle, PRODUCT_DEFS[i % PRODUCTS.length]!);
527
+ return {
528
+ ...base,
529
+ handle,
530
+ url: `${base.url}${suffix}`,
531
+ productId: `${base.productId}${suffix}`,
532
+ };
533
+ });
534
+ }
535
+
536
+ // ---------------------------------------------------------------------------------------------
537
+ // Filtering and sorting a collection — what a real backend does for `collectionProducts`
538
+ // ---------------------------------------------------------------------------------------------
539
+
540
+ /**
541
+ * How the demo answers a facet request: `app/storefront/facets.ts` is the pass itself — shared
542
+ * with `createGatewayStorefront`, so the demo and the real site filter by exactly the same rules —
543
+ * and this supplies the per-product attributes a product *card* does not carry (`category`,
544
+ * `sizes`, `colours`). Without an answer here the shopper's filter changed the URL, the chips and
545
+ * the active-filter row while the grid and the count stayed exactly as they were, which is worse
546
+ * than not offering filters at all.
547
+ */
548
+ /**
549
+ * The products a **category page** lists: the catalogue narrowed to one category's whole subtree,
550
+ * which is what the platform's `categoryId` parameter matches. `CATALOGUE_ITEMS` for no path at all
551
+ * (every other page), and `null` for a path no category occupies — the fixture's own version of
552
+ * "no such page".
553
+ */
554
+ function categoryScopeOf(
555
+ categoryPath: string | undefined
556
+ ): StorefrontProductListItem[] | readonly StorefrontProductListItem[] | null {
557
+ if (categoryPath === undefined || categoryPath === '') return CATALOGUE_ITEMS;
558
+ const scopeId = CATEGORY_INDEX.idByPath.get(categoryPath);
559
+ if (scopeId === undefined) return null;
560
+ return CATALOGUE_ITEMS.filter((item) => {
561
+ const id = attributesFor(item).category?.id;
562
+ return id !== undefined && isInSubtree(CATEGORY_INDEX, id, scopeId);
563
+ });
564
+ }
565
+
566
+ function attributesFor(item: StorefrontProductListItem): ProductFacetAttributes {
567
+ return {
568
+ ...(PRODUCT_ATTRIBUTES.get(item.handle) ?? NO_ATTRIBUTES),
569
+ collections: collectionsOf(item),
570
+ };
571
+ }
572
+
573
+ /**
574
+ * Which of the fixture's collections hold a product — the `collection` filter group's own data,
575
+ * and the one attribute a real backend answers from a join table rather than from the product.
576
+ *
577
+ * Declared as a rule rather than a list so a clone (`merino-crew-sweater-2`) belongs wherever the
578
+ * product it copies does: the winter edit is the demo's catch-all, `winter-knitwear` is its
579
+ * knitwear, and `best-sellers` is the curated list `BEST_SELLER_HANDLES` names.
580
+ */
581
+ function collectionsOf(item: StorefrontProductListItem): ProductFacetTerm[] {
582
+ const handles = ['the-winter-edit'];
583
+ if (PRODUCT_ATTRIBUTES.get(item.handle)?.category?.slug === 'knitwear') {
584
+ handles.push('winter-knitwear');
585
+ }
586
+ if (BEST_SELLER_HANDLES.includes(baseHandleOf(item))) handles.push('best-sellers');
587
+ return handles.map((handle) => ({
588
+ slug: handle,
589
+ title: COLLECTIONS[handle]?.title ?? handle,
590
+ id: demoCollectionId(handle) ?? handle,
591
+ }));
592
+ }
593
+
594
+ /**
595
+ * The `sortOptions` values `collection-grid` offers. `featured` is the fixture's own curated order,
596
+ * `newest` its reverse (the list is written oldest-first), and `best-selling` follows
597
+ * `BEST_SELLER_HANDLES` with everything it does not name keeping its relative order behind them —
598
+ * the demo has no per-product sales figures, and inventing some would be a fake statistic.
599
+ *
600
+ * Returns a new array; `Array.prototype.sort` is stable in every supported runtime, so equal keys
601
+ * keep the collection's own order.
602
+ */
603
+ function sortCollectionItems(
604
+ items: readonly StorefrontProductListItem[],
605
+ sort: string | undefined
606
+ ): StorefrontProductListItem[] {
607
+ const list = [...items];
608
+ if (sort === undefined || sort === '' || sort === 'featured') return list;
609
+ if (sort === 'newest') return list.reverse();
610
+ if (sort === 'price-asc') return list.sort((a, b) => a.price.amount - b.price.amount);
611
+ if (sort === 'price-desc') return list.sort((a, b) => b.price.amount - a.price.amount);
612
+ if (sort === 'best-selling') {
613
+ const rank = (item: StorefrontProductListItem): number => {
614
+ const index = BEST_SELLER_HANDLES.indexOf(baseHandleOf(item));
615
+ return index === -1 ? BEST_SELLER_HANDLES.length : index;
616
+ };
617
+ return list.sort((a, b) => rank(a) - rank(b));
618
+ }
619
+ return list;
620
+ }
621
+
622
+ /** A collection clone (`merino-crew-sweater-2`) ranks as the product it is a copy of. */
623
+ function baseHandleOf(item: StorefrontProductListItem): string {
624
+ return PRODUCTS.some((product) => product.handle === item.handle)
625
+ ? item.handle
626
+ : item.handle.replace(/-\d+$/, '');
627
+ }
628
+
629
+ // ---------------------------------------------------------------------------------------------
630
+ // Order NW-10482 (`order-status`'s default content, spec lines ~3806–3835)
631
+ // ---------------------------------------------------------------------------------------------
632
+
633
+ const ORDER_LINES: StorefrontCartLine[] = [
634
+ {
635
+ id: 'nw-10482-1',
636
+ productId: 'fell-crew-sweater',
637
+ variantId: 'fell-crew-sweater::oatmeal::m',
638
+ title: 'Fell crew sweater',
639
+ url: '/products/fell-crew-sweater',
640
+ variantLabel: 'Oatmeal / M',
641
+ quantity: 1,
642
+ unitPrice: 148,
643
+ lineTotal: 148,
644
+ image: demoImage(1, 'Fell crew sweater'),
645
+ max: null,
646
+ },
647
+ {
648
+ id: 'nw-10482-2',
649
+ productId: 'everyday-mug',
650
+ variantId: 'everyday-mug::fjord::350ml',
651
+ title: 'Everyday mug',
652
+ url: '/products/everyday-mug',
653
+ variantLabel: 'Fjord / 350 ml',
654
+ quantity: 2,
655
+ unitPrice: 32,
656
+ lineTotal: 64,
657
+ image: demoImage(2, 'Everyday mug'),
658
+ max: null,
659
+ },
660
+ {
661
+ id: 'nw-10482-3',
662
+ productId: 'linen-tea-towels-set-of-2',
663
+ variantId: 'linen-tea-towels-set-of-2::sage',
664
+ title: 'Linen tea towels, set of 2',
665
+ url: '/products/linen-tea-towels-set-of-2',
666
+ variantLabel: 'Sage',
667
+ quantity: 1,
668
+ unitPrice: 32,
669
+ lineTotal: 32,
670
+ image: demoImage(3, 'Linen tea towels, set of 2'),
671
+ max: null,
672
+ },
673
+ ];
674
+
675
+ const ORDER_TOTALS: StorefrontCartTotals = {
676
+ subtotal: 244,
677
+ discount: null,
678
+ shipping: 0,
679
+ tax: 19.52,
680
+ total: 263.52,
681
+ };
682
+
683
+ const ORDER_SHIPPING_ADDRESS = [
684
+ 'Maren Holt',
685
+ '214 Linden Street, Apt 3B',
686
+ 'Portland, OR 97209',
687
+ 'United States',
688
+ ];
689
+
690
+ const ORDER_PAYMENT = { brand: 'Visa', last4: '4242' };
691
+ const ORDER_TRACKING_NUMBER = '1Z 999 AA1 01 2345 6784';
692
+ const ORDER_TRACKING_URL = 'https://www.ups.com/track?tracknum=1Z999AA10123456784';
693
+ const ORDER_CARRIER = 'UPS Standard';
694
+
695
+ function buildOrderSteps(status: StorefrontOrderStatus): StorefrontOrder['steps'] {
696
+ switch (status) {
697
+ case 'processing':
698
+ return [
699
+ { key: 'ordered', label: 'Ordered', date: '2026-09-18', state: 'done' },
700
+ { key: 'packed', label: 'Packed', date: null, state: 'current' },
701
+ { key: 'shipped', label: 'Shipped', date: null, state: 'upcoming' },
702
+ { key: 'delivered', label: 'Delivered', date: null, state: 'upcoming' },
703
+ ];
704
+ case 'delivered':
705
+ return [
706
+ { key: 'ordered', label: 'Ordered', date: '2026-09-18', state: 'done' },
707
+ { key: 'packed', label: 'Packed', date: '2026-09-19', state: 'done' },
708
+ { key: 'shipped', label: 'Shipped', date: '2026-09-20', state: 'done' },
709
+ { key: 'delivered', label: 'Delivered', date: '2026-09-24', state: 'done' },
710
+ ];
711
+ case 'delayed':
712
+ return [
713
+ { key: 'ordered', label: 'Ordered', date: '2026-09-18', state: 'done' },
714
+ { key: 'packed', label: 'Packed', date: '2026-09-19', state: 'done' },
715
+ { key: 'shipped', label: 'Shipped', date: '2026-09-20', state: 'done' },
716
+ { key: 'delivered', label: 'Delivered', date: '2026-09-30', state: 'warning' },
717
+ ];
718
+ case 'cancelled':
719
+ return [
720
+ { key: 'ordered', label: 'Ordered', date: '2026-09-18', state: 'done' },
721
+ { key: 'packed', label: 'Packed', date: '2026-09-19', state: 'warning' },
722
+ { key: 'shipped', label: 'Shipped', date: null, state: 'upcoming' },
723
+ { key: 'delivered', label: 'Delivered', date: null, state: 'upcoming' },
724
+ ];
725
+ case 'shipped':
726
+ default:
727
+ return [
728
+ { key: 'ordered', label: 'Ordered', date: '2026-09-18', state: 'done' },
729
+ { key: 'packed', label: 'Packed', date: '2026-09-19', state: 'done' },
730
+ { key: 'shipped', label: 'Shipped', date: '2026-09-20', state: 'current' },
731
+ { key: 'delivered', label: 'Delivered', date: '2026-09-26', state: 'upcoming' },
732
+ ];
733
+ }
734
+ }
735
+
736
+ /**
737
+ * Exported so `order-status` can fall back to the same sample order the demo
738
+ * storefront itself serves (`createDemoStorefront().orders.current`, `status` defaulting to
739
+ * `'shipped'`) for its own "freshly inserted in the editor, no order token yet" case (spec →
740
+ * States, "no empty layout") — without constructing a whole second `StorefrontSource` just to
741
+ * reach one order.
742
+ */
743
+ export function buildOrder(status: StorefrontOrderStatus = 'shipped'): StorefrontOrder {
744
+ const base: StorefrontOrder = {
745
+ number: 'NW-10482',
746
+ placedAt: '2026-09-18',
747
+ itemCount: ORDER_LINES.reduce((sum, line) => sum + line.quantity, 0),
748
+ status,
749
+ steps: buildOrderSteps(status),
750
+ lines: ORDER_LINES,
751
+ totals: ORDER_TOTALS,
752
+ shippingAddress: ORDER_SHIPPING_ADDRESS,
753
+ payment: ORDER_PAYMENT,
754
+ };
755
+ if (status === 'processing') return base;
756
+ if (status === 'cancelled') {
757
+ return {
758
+ ...base,
759
+ cancelNote:
760
+ 'Cancelled at your request on 19 September. A refund of $263.52 is on its way to Visa ending 4242 and should appear within 5 business days.',
761
+ };
762
+ }
763
+ const withTracking: StorefrontOrder = {
764
+ ...base,
765
+ carrier: ORDER_CARRIER,
766
+ trackingNumber: ORDER_TRACKING_NUMBER,
767
+ trackingUrl: ORDER_TRACKING_URL,
768
+ };
769
+ if (status === 'delayed') {
770
+ return {
771
+ ...withTracking,
772
+ eta: 'Monday 30 September',
773
+ delayNote:
774
+ 'Storms in the North Sea have held up our carrier. New estimate: Monday 30 September. Sorry for the wait.',
775
+ };
776
+ }
777
+ if (status === 'delivered') return withTracking;
778
+ return { ...withTracking, eta: 'Thursday 26 September' };
779
+ }
780
+
781
+ // ---------------------------------------------------------------------------------------------
782
+ // Search — case-insensitive match on title, category and journal titles/deks; an empty query has
783
+ // nothing to search for, and a near miss gets a "did you mean" suggestion (spec `02-blocks.md`
784
+ // "Search results page" → Default content, the "linen" query and the "linnen napkns" no-results
785
+ // example).
786
+ // ---------------------------------------------------------------------------------------------
787
+
788
+ const JOURNAL_ARTICLES: StorefrontSearchResponse['articles'] = [
789
+ {
790
+ title: 'How to wash and store linen',
791
+ href: '/journal/how-to-wash-and-store-linen',
792
+ category: 'Care guide',
793
+ readingTime: '4 min read',
794
+ image: demoImage(1, 'How to wash and store linen'),
795
+ },
796
+ {
797
+ title: 'Linen vs. cotton for the kitchen',
798
+ href: '/journal/linen-vs-cotton-for-the-kitchen',
799
+ category: 'Journal',
800
+ readingTime: '6 min read',
801
+ image: demoImage(2, 'Linen vs. cotton for the kitchen'),
802
+ },
803
+ {
804
+ title: 'A visit to the Kortrijk flax mill',
805
+ href: '/journal/a-visit-to-the-kortrijk-flax-mill',
806
+ category: 'Journal',
807
+ readingTime: '8 min read',
808
+ image: demoImage(3, 'A visit to the Kortrijk flax mill'),
809
+ },
810
+ ];
811
+
812
+ const JOURNAL_PAGES: StorefrontSearchResponse['pages'] = [
813
+ {
814
+ title: 'Care guide: linen & wool',
815
+ href: '/pages/care',
816
+ path: 'northwindgoods.com/pages/care',
817
+ snippet: 'How to wash, dry and store our linen and wool pieces.',
818
+ },
819
+ {
820
+ title: 'Materials',
821
+ href: '/pages/materials',
822
+ path: 'northwindgoods.com/pages/materials',
823
+ snippet: 'Where our linen, wool and stoneware come from.',
824
+ },
825
+ ];
826
+
827
+ /**
828
+ * Search-friendly aliases for `PRODUCT_DEFS`, in the same order — shorter than some titles
829
+ * ("Linen napkins, set of 4" → "linen napkins") so a "did you mean" suggestion reads the way a
830
+ * shopper would type it, not the full merchandising title.
831
+ */
832
+ const SEARCH_TERMS: string[] = [
833
+ 'merino crew sweater',
834
+ 'fisherman rib cardigan',
835
+ 'lambswool throw blanket',
836
+ 'ribbed lambswool beanie',
837
+ 'linen tea towels',
838
+ 'speckled latte mug',
839
+ 'stoneware dinner plates',
840
+ 'walnut serving board',
841
+ 'hand-thrown serving bowl',
842
+ 'glazed milk jug',
843
+ 'linen napkins',
844
+ 'stonewashed linen throw',
845
+ ];
846
+
847
+ function normalise(text: string): string {
848
+ return text.trim().toLowerCase();
849
+ }
850
+
851
+ function includesQuery(haystack: string, query: string): boolean {
852
+ return normalise(haystack).includes(query);
853
+ }
854
+
855
+ /** Plain Levenshtein edit distance — short search terms only, never a document. */
856
+ function editDistance(a: string, b: string): number {
857
+ const rows: number[][] = Array.from({ length: a.length + 1 }, () =>
858
+ new Array<number>(b.length + 1).fill(0)
859
+ );
860
+ for (let i = 0; i <= a.length; i += 1) rows[i]![0] = i;
861
+ for (let j = 0; j <= b.length; j += 1) rows[0]![j] = j;
862
+ for (let i = 1; i <= a.length; i += 1) {
863
+ for (let j = 1; j <= b.length; j += 1) {
864
+ const cost = a[i - 1] === b[j - 1] ? 0 : 1;
865
+ rows[i]![j] = Math.min(
866
+ rows[i - 1]![j]! + 1,
867
+ rows[i]![j - 1]! + 1,
868
+ rows[i - 1]![j - 1]! + cost
869
+ );
870
+ }
871
+ }
872
+ return rows[a.length]![b.length]!;
873
+ }
874
+
875
+ /**
876
+ * The closest `SEARCH_TERMS` entry within a quarter of its own length (at least 2 edits of
877
+ * slack) — a real "did you mean" for a near miss ("linnen napkns" → "linen napkins"), not a guess
878
+ * for a query that shares nothing with the catalogue.
879
+ */
880
+ function suggestionFor(query: string): string | null {
881
+ let best: { term: string; distance: number } | null = null;
882
+ for (const term of SEARCH_TERMS) {
883
+ const distance = editDistance(query, term);
884
+ if (best === null || distance < best.distance) best = { term, distance };
885
+ }
886
+ if (best === null || best.distance === 0) return null;
887
+ return best.distance <= Math.max(2, Math.ceil(best.term.length / 4)) ? best.term : null;
888
+ }
889
+
890
+ function buildSearchResponse(query: string): StorefrontSearchResponse {
891
+ const q = normalise(query);
892
+ if (q === '') {
893
+ return { query, total: 0, products: [], articles: [], pages: [], suggestion: null };
894
+ }
895
+ const products = PRODUCTS.filter((product) => includesQuery(product.title, q));
896
+ const articles = JOURNAL_ARTICLES.filter(
897
+ (article) => includesQuery(article.title, q) || includesQuery(article.category, q)
898
+ );
899
+ const pages = JOURNAL_PAGES.filter(
900
+ (page) => includesQuery(page.title, q) || includesQuery(page.snippet, q)
901
+ );
902
+ const total = products.length + articles.length + pages.length;
903
+ return {
904
+ query,
905
+ total,
906
+ products,
907
+ articles,
908
+ pages,
909
+ suggestion: total === 0 ? suggestionFor(q) : null,
910
+ };
911
+ }
912
+
913
+ // ---------------------------------------------------------------------------------------------
914
+ // Demo cart — a small, generic in-memory engine (not the spec's exact cart-block fixture, which
915
+ // is that block's own mock/preview content; this is the "server" every block's own story adds
916
+ // items to).
917
+ // ---------------------------------------------------------------------------------------------
918
+
919
+ /**
920
+ * The cart the `cart` block's own stories and specs render (spec `02-blocks.md` "Cart" →
921
+ * "Default content": Merino crew sweater · Oat / M · $96.00, Speckled latte mug · Clay · $28.00
922
+ * each × 2, Walnut serving board · Large, 45 cm · $58.00 — $210.00, over the $80 free-shipping
923
+ * threshold). Seeded through `createDemoStorefront({ cartLines })`: the demo cart is empty by
924
+ * default, the same as a real shopper's first visit, so nothing else changes by this existing.
925
+ */
926
+ export const DEMO_CART_LINES: StorefrontCartLine[] = [
927
+ {
928
+ id: 'demo-cart-1',
929
+ productId: 'merino-crew-sweater',
930
+ variantId: 'merino-crew-sweater::oat::m',
931
+ title: 'Merino crew sweater',
932
+ url: '/products/merino-crew-sweater',
933
+ variantLabel: 'Oat / M',
934
+ quantity: 1,
935
+ unitPrice: 96,
936
+ lineTotal: 96,
937
+ image: demoImage(1, 'Merino crew sweater'),
938
+ max: null,
939
+ },
940
+ {
941
+ id: 'demo-cart-2',
942
+ productId: 'speckled-latte-mug',
943
+ variantId: 'speckled-latte-mug::clay',
944
+ title: 'Speckled latte mug',
945
+ url: '/products/speckled-latte-mug',
946
+ variantLabel: 'Clay',
947
+ quantity: 2,
948
+ unitPrice: 28,
949
+ lineTotal: 56,
950
+ image: demoImage(6, 'Speckled latte mug'),
951
+ max: null,
952
+ },
953
+ {
954
+ id: 'demo-cart-3',
955
+ productId: 'walnut-serving-board',
956
+ variantId: 'walnut-serving-board::large',
957
+ title: 'Walnut serving board',
958
+ url: '/products/walnut-serving-board',
959
+ variantLabel: 'Large, 45 cm',
960
+ quantity: 1,
961
+ unitPrice: 58,
962
+ lineTotal: 58,
963
+ image: demoImage(8, 'Walnut serving board'),
964
+ max: null,
965
+ },
966
+ ];
967
+
968
+ function createDemoCartOps(seedLines: StorefrontCartLine[]): CartOps {
969
+ let lines: StorefrontCartLine[] = seedLines.map((line) => ({ ...line }));
970
+ let discount: { code: string; amount: number } | null = null;
971
+ let nextLineId = lines.length + 1;
972
+ const checkoutUrl = ref<string | null>(null);
973
+
974
+ function computeTotals(): StorefrontCartTotals {
975
+ const subtotal = roundMoney(lines.reduce((sum, line) => sum + line.lineTotal, 0));
976
+ const shipping =
977
+ subtotal === 0 ? null : subtotal >= FREE_SHIPPING_THRESHOLD ? 0 : FLAT_SHIPPING;
978
+ const discountAmount = discount?.amount ?? 0;
979
+ const total = roundMoney(Math.max(0, subtotal - discountAmount + (shipping ?? 0)));
980
+ return { subtotal, discount, shipping, tax: null, total };
981
+ }
982
+
983
+ function snapshot(): CartSnapshot {
984
+ checkoutUrl.value = lines.length > 0 ? '/checkout/demo-cart' : null;
985
+ return { lines: [...lines], totals: computeTotals() };
986
+ }
987
+
988
+ return {
989
+ async init() {
990
+ return snapshot();
991
+ },
992
+ async add({ productId, variantId, quantity }) {
993
+ const product = PRODUCTS.find((p) => p.productId === productId);
994
+ const existing = lines.find((line) => line.variantId === variantId);
995
+ if (existing) {
996
+ existing.quantity += quantity;
997
+ existing.lineTotal = roundMoney(existing.unitPrice * existing.quantity);
998
+ } else {
999
+ const unitPrice = product?.price.amount ?? 0;
1000
+ lines = [
1001
+ ...lines,
1002
+ {
1003
+ id: `line-${nextLineId++}`,
1004
+ productId,
1005
+ variantId,
1006
+ title: product?.title ?? 'Product',
1007
+ url: product?.url ?? '#',
1008
+ variantLabel: product?.colours?.[0]?.name ?? '',
1009
+ quantity,
1010
+ unitPrice,
1011
+ lineTotal: roundMoney(unitPrice * quantity),
1012
+ image: product?.featuredImage ?? null,
1013
+ max: null,
1014
+ },
1015
+ ];
1016
+ }
1017
+ return snapshot();
1018
+ },
1019
+ async setQuantity(lineId, quantity) {
1020
+ lines = lines.map((line) =>
1021
+ line.id === lineId
1022
+ ? { ...line, quantity, lineTotal: roundMoney(line.unitPrice * quantity) }
1023
+ : line
1024
+ );
1025
+ return snapshot();
1026
+ },
1027
+ async remove(lineId) {
1028
+ lines = lines.filter((line) => line.id !== lineId);
1029
+ return snapshot();
1030
+ },
1031
+ async applyDiscount(code) {
1032
+ if (code !== 'WINTER15') return { ack: { ok: false, reason: 'invalid' } };
1033
+ const subtotal = lines.reduce((sum, line) => sum + line.lineTotal, 0);
1034
+ discount = { code, amount: roundMoney(subtotal * 0.1) };
1035
+ return { ack: { ok: true }, snapshot: snapshot() };
1036
+ },
1037
+ async removeDiscount() {
1038
+ discount = null;
1039
+ return snapshot();
1040
+ },
1041
+ checkoutUrl,
1042
+ };
1043
+ }
1044
+
1045
+ // ---------------------------------------------------------------------------------------------
1046
+ // StorefrontResult helper — resolves on the next tick, so every consumer sees a real (if brief)
1047
+ // `pending` transition instead of already-resolved data, matching the gateway's own async shape.
1048
+ // ---------------------------------------------------------------------------------------------
1049
+
1050
+ /** The handle behind a selector: a slug as given, an id through the fixture's own
1051
+ * id map — the demo's stand-in for the gateway's by-id lookup. */
1052
+ function demoCollectionHandle(selector: StorefrontCollectionSelector | null): string | null {
1053
+ if (selector === null) return null;
1054
+ if ('slug' in selector) return selector.slug || null;
1055
+ return COLLECTION_HANDLES_BY_ID[selector.id] ?? null;
1056
+ }
1057
+
1058
+ function createDemoResult<T>(
1059
+ sources: Ref<unknown>[],
1060
+ resolve: () => T | null
1061
+ ): StorefrontResult<T> {
1062
+ const data = ref<T | null>(null) as Ref<T | null>;
1063
+ const pending = ref(true);
1064
+ const loading = ref(false);
1065
+ const error = ref<string | null>(null);
1066
+ // The fixture is synchronous and never goes stale, so nothing here ever revalidates — the field
1067
+ // exists because `StorefrontResult` has it, and a block must read the same shape from either
1068
+ // source.
1069
+ const revalidating = ref<ReadonlySet<VolatileKey>>(new Set());
1070
+
1071
+ async function load(): Promise<void> {
1072
+ // Server rendering gets one pass and no second chance: whatever the first render produced is
1073
+ // the prerendered HTML, so a read that answers "later" bakes the skeleton into the page — the
1074
+ // very defect this theme's gateway storefront was made prerender-aware to close
1075
+ // (`app/storefront/prerender.ts`). The fixture is synchronous, so off a browser it answers
1076
+ // inside the render rather than on the next tick. Nothing hydrates a demo-rendered page (the
1077
+ // demo backs Storybook and the tests; a real site reads the gateway), so the browser keeps the
1078
+ // asynchronous shape below, which is what lets a block spec observe a real pending transition.
1079
+ if (typeof window === 'undefined') {
1080
+ loading.value = true;
1081
+ error.value = null;
1082
+ data.value = resolve();
1083
+ pending.value = false;
1084
+ loading.value = false;
1085
+ return;
1086
+ }
1087
+ // The fixture answers on the next tick rather than instantly, so a block sees the same
1088
+ // `loading` → settled sequence it sees from a real read; `pending` still only means "nothing
1089
+ // to show yet", so a reload over existing fixture data never raises it.
1090
+ loading.value = true;
1091
+ // Same three flags as the gateway's (`types.ts`): `pending` is the skeleton state — a read in
1092
+ // flight with nothing to show — so a reload over fixture data never raises it, and an answer
1093
+ // of "nothing" clears it rather than leaving the block loading forever.
1094
+ pending.value = data.value === null;
1095
+ error.value = null;
1096
+ await nextTick();
1097
+ data.value = resolve();
1098
+ pending.value = false;
1099
+ loading.value = false;
1100
+ }
1101
+
1102
+ watch(sources, load, { immediate: true, deep: true });
1103
+
1104
+ return { data, pending, loading, error, revalidating, refresh: load };
1105
+ }
1106
+
1107
+ // ---------------------------------------------------------------------------------------------
1108
+ // createDemoStorefront
1109
+ // ---------------------------------------------------------------------------------------------
1110
+
1111
+ /**
1112
+ * What the Northwind fixture sells in. Every amount in this file is a US dollar price and the demo
1113
+ * order quotes 8% sales tax on top of its subtotal (`ORDER_TOTALS`: 19.52 on 244), so the demo
1114
+ * store's own settings say exactly that. A spec or story that wants another currency — or a store
1115
+ * that publishes none — passes `createDemoStorefront({ commerce })`.
1116
+ */
1117
+ export const DEMO_COMMERCE: StorefrontCommerce = {
1118
+ currency: 'USD',
1119
+ taxInclusivePricing: false,
1120
+ defaultTaxRate: 0.08,
1121
+ };
1122
+
1123
+ export interface DemoStorefrontOptions {
1124
+ orderStatus?: StorefrontOrderStatus;
1125
+ /** What the demo store sells in; `DEMO_COMMERCE` by default, `null` for a store that publishes
1126
+ * no currency at all. */
1127
+ commerce?: StorefrontCommerce | null;
1128
+ recentlyViewed?: string[];
1129
+ query?: string;
1130
+ collectionHandle?: string;
1131
+ productHandle?: string;
1132
+ failForms?: boolean;
1133
+ /** Seeds the cart with these lines, e.g. `DEMO_CART_LINES` — the demo cart is empty otherwise. */
1134
+ cartLines?: StorefrontCartLine[];
1135
+ /** Seeds `route.sort` — restores `collection-grid`'s sort choice the way a shared URL would. */
1136
+ sort?: string;
1137
+ /** Seeds `route.columns`. */
1138
+ columns?: string;
1139
+ /** Seeds `route.filters` — restores `collection-grid`'s filter selection and price range. */
1140
+ filters?: Record<string, string[]>;
1141
+ /**
1142
+ * Seeds the **category page**'s route context: a category's canonical path (`home/ceramics`), the
1143
+ * ancestors' slugs root first then its own. Absent — the default — is a route that is not a
1144
+ * category page at all, so `collection-grid` in `category` scope, `collection-header`'s category
1145
+ * mode and `breadcrumbs`' `fromCategory` each draw nothing, exactly as they do on a product page.
1146
+ */
1147
+ categoryPath?: string;
1148
+ }
1149
+
1150
+ /** Northwind fixtures in the theme's own view types — the "knobs" are exactly what a block spec
1151
+ * needs to demonstrate its states. */
1152
+ export function createDemoStorefront(options: DemoStorefrontOptions = {}): StorefrontSource {
1153
+ const order = buildOrder(options.orderStatus ?? 'shipped');
1154
+
1155
+ const categoryPath = options.categoryPath ?? null;
1156
+ const route: StorefrontRoute = reactive({
1157
+ productHandle: options.productHandle ?? 'merino-crew-sweater',
1158
+ collectionHandle: options.collectionHandle ?? 'winter-knitwear',
1159
+ categorySlug: categoryPath === null ? null : (categoryPath.split('/').at(-1) ?? null) || null,
1160
+ categoryPath,
1161
+ orderToken: 'demo-order-token',
1162
+ query: options.query ?? null,
1163
+ page: 1,
1164
+ sort: options.sort ?? null,
1165
+ columns: options.columns ?? null,
1166
+ filters: options.filters ?? {},
1167
+ setQuery(patch: Record<string, string | string[] | null>) {
1168
+ for (const [key, value] of Object.entries(patch)) {
1169
+ if (key === 'q') {
1170
+ const first = Array.isArray(value) ? (value[0] ?? null) : value;
1171
+ route.query = first || null;
1172
+ } else if (key === 'page') {
1173
+ const first = Array.isArray(value) ? value[0] : value;
1174
+ const page = Number(first);
1175
+ route.page = Number.isFinite(page) && page > 0 ? page : 1;
1176
+ } else if (key === 'sort') {
1177
+ const first = Array.isArray(value) ? (value[0] ?? null) : value;
1178
+ route.sort = first || null;
1179
+ } else if (key === 'columns') {
1180
+ const first = Array.isArray(value) ? (value[0] ?? null) : value;
1181
+ route.columns = first || null;
1182
+ } else {
1183
+ // Every other key is a `collection-grid` filter or its price range — kept generically
1184
+ // (see `types.ts`'s own doc comment on `StorefrontRoute.filters`) rather than named here.
1185
+ const next = { ...route.filters };
1186
+ if (value === null) delete next[key];
1187
+ else next[key] = Array.isArray(value) ? value : [value];
1188
+ route.filters = next;
1189
+ }
1190
+ }
1191
+ },
1192
+ });
1193
+
1194
+ async function ack(): Promise<StorefrontAck> {
1195
+ await nextTick();
1196
+ return options.failForms ? { ok: false, reason: 'failed' } : { ok: true };
1197
+ }
1198
+
1199
+ const catalog: StorefrontCatalog = {
1200
+ product: (handle) =>
1201
+ createDemoResult([handle], () =>
1202
+ handle.value ? (PRODUCTS_FULL[handle.value] ?? null) : null
1203
+ ),
1204
+ collection: (handle) =>
1205
+ createDemoResult([handle], () => (handle.value ? (COLLECTIONS[handle.value] ?? null) : null)),
1206
+ /** The category page's own read, over the fixture's tree — the same `placeCategory` walk the
1207
+ * gateway source runs, so a Storybook story and a spec see exactly what the live site does. */
1208
+ category: (path) =>
1209
+ createDemoResult([path], () =>
1210
+ path.value ? placeCategory(CATEGORY_INDEX, path.value) : null
1211
+ ),
1212
+ /**
1213
+ * Honours `sort` and `filters`, not just `page`/`pageSize`. It used to destructure only the
1214
+ * paging pair, so in the scaffolded site and the collection sample page — both demo-backed —
1215
+ * choosing a filter or a sort updated the URL, the chips and the active-filter row while the
1216
+ * grid and the `total` never moved, and the drawer's "Show N products" button always quoted the
1217
+ * unfiltered count. `total` is now the size of the *filtered* set, which is what the grid's
1218
+ * count line and its paging both read.
1219
+ */
1220
+ collectionProducts: (collection, opts) =>
1221
+ createDemoResult([collection, opts], () => {
1222
+ const handle = demoCollectionHandle(collection.value);
1223
+ if (handle === null) return null;
1224
+ const info = COLLECTIONS[handle];
1225
+ if (!info) return null;
1226
+ const all = COLLECTION_ITEMS[handle] ?? buildCollectionItems(info.productCount);
1227
+ const { page, pageSize, sort, filters } = opts.value;
1228
+ // The tree goes in, so a shopper ticking a **parent** category gets the products in its
1229
+ // children — what the platform's own `categoryId` filter does, and what the nested category
1230
+ // group the panel draws from these same facets promises.
1231
+ const matching = filterItems(all, filters, attributesFor, CATEGORY_INDEX);
1232
+ const ordered = sortCollectionItems(matching, sort);
1233
+ const start = (page - 1) * pageSize;
1234
+ return {
1235
+ items: ordered.slice(start, start + pageSize),
1236
+ total: ordered.length,
1237
+ // The same derivation `createGatewayStorefront` runs, over the whole collection rather
1238
+ // than over one fetched page: the vocabulary is every value the collection holds, and
1239
+ // each family's counts leave that family's own filter out (`deriveFacets`), so ticking
1240
+ // one colour narrows the sizes and leaves the other colours countable.
1241
+ facets: deriveFacets(all, { filters, attributesFor, categories: CATEGORY_INDEX }),
1242
+ };
1243
+ }),
1244
+ /**
1245
+ * The whole catalogue, under exactly the same rules as one collection's products — the read behind
1246
+ * the `/products` page. The one difference is the scope, and therefore the one group a collection
1247
+ * scope cannot narrow by: nothing is `unfilterable` here, so ticking a collection really does
1248
+ * intersect (`filterItems` reads each product's own collections from `attributesFor`).
1249
+ *
1250
+ * The scope is every product the fixture has, clones included (`buildCollectionItems` is how the
1251
+ * demo gets past twelve), so the counts and the paging read like a real store's rather than like a
1252
+ * one-page list.
1253
+ */
1254
+ products: (opts) =>
1255
+ createDemoResult([opts], () => {
1256
+ const { page, pageSize, sort, filters, categoryPath } = opts.value;
1257
+ // **A category page narrows the scope itself**, before a single filter is applied — the
1258
+ // platform's `categoryId` matches a whole subtree, so this is the fixture's own version of
1259
+ // that. A path no category occupies is `null` (the grid's empty state), never the unscoped
1260
+ // catalogue, which is the same answer an unknown collection handle gets.
1261
+ const scope = categoryScopeOf(categoryPath);
1262
+ if (scope === null) return null;
1263
+ const matching = filterItems(scope, filters, attributesFor, CATEGORY_INDEX);
1264
+ const ordered = sortCollectionItems(matching, sort);
1265
+ const start = (page - 1) * pageSize;
1266
+ return {
1267
+ items: ordered.slice(start, start + pageSize),
1268
+ total: ordered.length,
1269
+ // Counted over the **scope**, not the whole catalogue: on a category page the `category`
1270
+ // group lists that category's children with the counts they have inside it.
1271
+ facets: deriveFacets(scope, { filters, attributesFor, categories: CATEGORY_INDEX }),
1272
+ };
1273
+ }),
1274
+ related: (handle, limit) =>
1275
+ createDemoResult([handle], () => (handle.value ? RELATED_ITEMS.slice(0, limit) : [])),
1276
+ byHandles: (handles) =>
1277
+ createDemoResult([handles], () =>
1278
+ handles.value
1279
+ .map((handle) => PRODUCTS.find((product) => product.handle === handle))
1280
+ .filter((product): product is StorefrontProductListItem => Boolean(product))
1281
+ ),
1282
+ volatileByIds: (ids) => Promise.resolve(demoVolatileSnapshots(ids)),
1283
+ notifyBackInStock: () => ack(),
1284
+ };
1285
+
1286
+ const search: StorefrontSearch = {
1287
+ run: (query) => createDemoResult([query], () => buildSearchResponse(query.value)),
1288
+ };
1289
+
1290
+ const orders: StorefrontOrders = {
1291
+ current: (token) => createDemoResult([token], () => (token.value ? order : null)),
1292
+ };
1293
+
1294
+ const forms: StorefrontForms = {
1295
+ subscribe: () => ack(),
1296
+ sendMessage: () => ack(),
1297
+ };
1298
+
1299
+ return {
1300
+ ready: ref(true),
1301
+ commerce: options.commerce === undefined ? DEMO_COMMERCE : options.commerce,
1302
+ route,
1303
+ catalog,
1304
+ cart: createCartStore(createDemoCartOps(options.cartLines ?? [])),
1305
+ search,
1306
+ orders,
1307
+ forms,
1308
+ wishlist: createWishlistStore(),
1309
+ history: createHistoryStore({
1310
+ initialRecentlyViewed: options.recentlyViewed ?? DEFAULT_RECENTLY_VIEWED,
1311
+ }),
1312
+ };
1313
+ }