@eldrajs/theme-cli 0.0.0 → 0.1.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 (483) hide show
  1. package/CHANGELOG.md +69 -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-C6jB8_Oc.js +510 -0
  9. package/package.json +50 -2
  10. package/template/.eldra/block-types.d.ts +429 -0
  11. package/template/.eldra/manifest.json +9377 -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 +52 -0
  20. package/template/.storybook/shims-vue.d.ts +10 -0
  21. package/template/.storybook/virtual-eldra.d.ts +27 -0
  22. package/template/README.md +288 -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 +247 -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 +1495 -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 +148 -0
  280. package/template/package.json +55 -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/demo/article-cover.svg +1 -0
  291. package/template/public/demo/article-figure.svg +1 -0
  292. package/template/public/demo/avatar-1.svg +3 -0
  293. package/template/public/demo/avatar-2.svg +3 -0
  294. package/template/public/demo/avatar-3.svg +3 -0
  295. package/template/public/demo/avatar-4.svg +3 -0
  296. package/template/public/demo/avatar-5.svg +3 -0
  297. package/template/public/demo/avatar-6.svg +3 -0
  298. package/template/public/demo/avatar-7.svg +3 -0
  299. package/template/public/demo/avatar-8.svg +3 -0
  300. package/template/public/demo/collection-1.svg +1 -0
  301. package/template/public/demo/collection-2.svg +1 -0
  302. package/template/public/demo/cta-split.svg +1 -0
  303. package/template/public/demo/feature-1.svg +1 -0
  304. package/template/public/demo/feature-2.svg +1 -0
  305. package/template/public/demo/feature-3.svg +1 -0
  306. package/template/public/demo/feature-4.svg +1 -0
  307. package/template/public/demo/gallery-1.svg +1 -0
  308. package/template/public/demo/gallery-2.svg +1 -0
  309. package/template/public/demo/gallery-3.svg +1 -0
  310. package/template/public/demo/gallery-4.svg +1 -0
  311. package/template/public/demo/gallery-5.svg +1 -0
  312. package/template/public/demo/gallery-6.svg +1 -0
  313. package/template/public/demo/gallery-7.svg +1 -0
  314. package/template/public/demo/gallery-8.svg +1 -0
  315. package/template/public/demo/hero-slide-1.svg +1 -0
  316. package/template/public/demo/hero-slide-2.svg +1 -0
  317. package/template/public/demo/hero-slide-3.svg +1 -0
  318. package/template/public/demo/hero-slide-4.svg +1 -0
  319. package/template/public/demo/hero-wide.svg +1 -0
  320. package/template/public/demo/hero.svg +1 -0
  321. package/template/public/demo/logo-1.svg +4 -0
  322. package/template/public/demo/logo-2.svg +4 -0
  323. package/template/public/demo/logo-3.svg +4 -0
  324. package/template/public/demo/logo-4.svg +4 -0
  325. package/template/public/demo/logo-5.svg +4 -0
  326. package/template/public/demo/logo-6.svg +4 -0
  327. package/template/public/demo/logo-7.svg +4 -0
  328. package/template/public/demo/logo-8.svg +4 -0
  329. package/template/public/demo/logo.svg +3 -0
  330. package/template/public/demo/map.svg +1 -0
  331. package/template/public/demo/poster.svg +1 -0
  332. package/template/public/demo/product-1.svg +4 -0
  333. package/template/public/demo/product-10.svg +4 -0
  334. package/template/public/demo/product-11.svg +4 -0
  335. package/template/public/demo/product-12.svg +4 -0
  336. package/template/public/demo/product-2.svg +4 -0
  337. package/template/public/demo/product-3.svg +4 -0
  338. package/template/public/demo/product-4.svg +4 -0
  339. package/template/public/demo/product-5.svg +4 -0
  340. package/template/public/demo/product-6.svg +4 -0
  341. package/template/public/demo/product-7.svg +4 -0
  342. package/template/public/demo/product-8.svg +4 -0
  343. package/template/public/demo/product-9.svg +4 -0
  344. package/template/public/demo/product-square-1.svg +4 -0
  345. package/template/public/demo/product-square-2.svg +4 -0
  346. package/template/public/demo/product-square-3.svg +4 -0
  347. package/template/public/demo/product-square-4.svg +4 -0
  348. package/template/public/demo/product-square-5.svg +4 -0
  349. package/template/public/demo/product-square-6.svg +4 -0
  350. package/template/public/demo/quote-portrait.svg +4 -0
  351. package/template/public/demo/split-1.svg +1 -0
  352. package/template/public/demo/split-2.svg +1 -0
  353. package/template/public/demo/split-3.svg +1 -0
  354. package/template/public/demo/split-4.svg +1 -0
  355. package/template/public/demo/team-1.svg +4 -0
  356. package/template/public/demo/team-2.svg +4 -0
  357. package/template/public/demo/team-3.svg +4 -0
  358. package/template/public/demo/team-4.svg +4 -0
  359. package/template/scripts/demo-images.mjs +393 -0
  360. package/template/scripts/generate-stories.mjs +156 -0
  361. package/template/scripts/previewHash.mjs +125 -0
  362. package/template/scripts/previews.mjs +149 -0
  363. package/template/stories/generated/announcement-bar.stories.ts +44 -0
  364. package/template/stories/generated/article-list.stories.ts +87 -0
  365. package/template/stories/generated/article.stories.ts +27 -0
  366. package/template/stories/generated/breadcrumbs.stories.ts +39 -0
  367. package/template/stories/generated/cart.stories.ts +38 -0
  368. package/template/stories/generated/collection-grid.stories.ts +117 -0
  369. package/template/stories/generated/collection-header.stories.ts +51 -0
  370. package/template/stories/generated/contact.stories.ts +45 -0
  371. package/template/stories/generated/cta.stories.ts +51 -0
  372. package/template/stories/generated/faq.stories.ts +56 -0
  373. package/template/stories/generated/feature-grid.stories.ts +69 -0
  374. package/template/stories/generated/footer.stories.ts +50 -0
  375. package/template/stories/generated/gallery.stories.ts +81 -0
  376. package/template/stories/generated/hero.stories.ts +75 -0
  377. package/template/stories/generated/image.stories.ts +99 -0
  378. package/template/stories/generated/logo-cloud.stories.ts +57 -0
  379. package/template/stories/generated/navigation.stories.ts +62 -0
  380. package/template/stories/generated/newsletter.stories.ts +68 -0
  381. package/template/stories/generated/order-status.stories.ts +32 -0
  382. package/template/stories/generated/pricing-table.stories.ts +44 -0
  383. package/template/stories/generated/product-carousel.stories.ts +75 -0
  384. package/template/stories/generated/product-detail.stories.ts +62 -0
  385. package/template/stories/generated/quote.stories.ts +69 -0
  386. package/template/stories/generated/rich-text.stories.ts +50 -0
  387. package/template/stories/generated/search.stories.ts +56 -0
  388. package/template/stories/generated/split-content.stories.ts +39 -0
  389. package/template/stories/generated/stats.stories.ts +68 -0
  390. package/template/stories/generated/tabs.stories.ts +45 -0
  391. package/template/stories/generated/team.stories.ts +45 -0
  392. package/template/stories/generated/testimonials.stories.ts +69 -0
  393. package/template/stories/generated/timeline.stories.ts +80 -0
  394. package/template/stories/generated/trust-strip.stories.ts +62 -0
  395. package/template/stories/generated/video-embed.stories.ts +63 -0
  396. package/template/stories/generated/wishlist.stories.ts +26 -0
  397. package/template/stories/pages/article.stories.ts +51 -0
  398. package/template/stories/pages/cart.stories.ts +56 -0
  399. package/template/stories/pages/category.stories.ts +56 -0
  400. package/template/stories/pages/collection.stories.ts +51 -0
  401. package/template/stories/pages/home.stories.ts +51 -0
  402. package/template/stories/pages/product.stories.ts +47 -0
  403. package/template/stories/pages/products.stories.ts +58 -0
  404. package/template/stories/pages/search.stories.ts +54 -0
  405. package/template/stories/pages/wishlist.stories.ts +53 -0
  406. package/template/stories/support/pageBlocks.ts +115 -0
  407. package/template/test/blocksEmptyData.spec.ts +52 -0
  408. package/template/test/carouselKeyboard.spec.ts +272 -0
  409. package/template/test/carouselRing.browser.spec.ts +193 -0
  410. package/template/test/carouselSlideWidth.browser.spec.ts +102 -0
  411. package/template/test/cartDrawer.spec.ts +295 -0
  412. package/template/test/cartToast.spec.ts +86 -0
  413. package/template/test/countPill.browser.spec.ts +196 -0
  414. package/template/test/demoImages.spec.ts +140 -0
  415. package/template/test/deps.spec.ts +102 -0
  416. package/template/test/eldraIcon.spec.ts +58 -0
  417. package/template/test/framing.spec.ts +76 -0
  418. package/template/test/i18n.spec.ts +200 -0
  419. package/template/test/iconComponent.spec.ts +91 -0
  420. package/template/test/inlineEditable.spec.ts +334 -0
  421. package/template/test/localePrefix.spec.ts +342 -0
  422. package/template/test/mainCss.spec.ts +107 -0
  423. package/template/test/mockGatewayContract.spec.ts +122 -0
  424. package/template/test/mocks/blocks.ts +20 -0
  425. package/template/test/mocks/breakpoints.ts +7 -0
  426. package/template/test/mocks/manifest.ts +11 -0
  427. package/template/test/moneyFormatting.spec.ts +89 -0
  428. package/template/test/pageTitle.spec.ts +49 -0
  429. package/template/test/pages/article.spec.ts +231 -0
  430. package/template/test/pages/category.spec.ts +185 -0
  431. package/template/test/pages/collection.spec.ts +396 -0
  432. package/template/test/pages/home.spec.ts +295 -0
  433. package/template/test/pages/hydration.spec.ts +557 -0
  434. package/template/test/pages/product.spec.ts +396 -0
  435. package/template/test/pages/seededPages.spec.ts +190 -0
  436. package/template/test/pages/ssr.spec.ts +393 -0
  437. package/template/test/prerenderCommerce.spec.ts +134 -0
  438. package/template/test/prerenderFailure.spec.ts +130 -0
  439. package/template/test/prerenderRefresh.browser.spec.ts +1431 -0
  440. package/template/test/previewsFresh.spec.ts +56 -0
  441. package/template/test/richText.spec.ts +161 -0
  442. package/template/test/richTextTypography.spec.ts +182 -0
  443. package/template/test/setup.ts +21 -0
  444. package/template/test/slugPage.spec.ts +244 -0
  445. package/template/test/slugPageTemplate.spec.ts +194 -0
  446. package/template/test/starter.spec.ts +1416 -0
  447. package/template/test/storefront/cart.spec.ts +404 -0
  448. package/template/test/storefront/categories.spec.ts +235 -0
  449. package/template/test/storefront/collectionSelector.spec.ts +74 -0
  450. package/template/test/storefront/demo.spec.ts +555 -0
  451. package/template/test/storefront/facets.spec.ts +425 -0
  452. package/template/test/storefront/feedback.spec.ts +97 -0
  453. package/template/test/storefront/gateway.spec.ts +2673 -0
  454. package/template/test/storefront/gatewayCart.spec.ts +289 -0
  455. package/template/test/storefront/gatewayPrerender.spec.ts +1037 -0
  456. package/template/test/storefront/history.spec.ts +341 -0
  457. package/template/test/storefront/money.spec.ts +171 -0
  458. package/template/test/storefront/toProductCard.spec.ts +138 -0
  459. package/template/test/storefront/volatile.spec.ts +284 -0
  460. package/template/test/support/axe.ts +14 -0
  461. package/template/test/support/dialog.ts +51 -0
  462. package/template/test/support/hydrate.ts +118 -0
  463. package/template/test/support/i18nText.ts +11 -0
  464. package/template/test/support/mockGateway.ts +1017 -0
  465. package/template/test/support/mountBlock.ts +194 -0
  466. package/template/test/support/mountPage.spec.ts +72 -0
  467. package/template/test/support/mountPage.ts +254 -0
  468. package/template/test/support/mountProbe.client.ts +69 -0
  469. package/template/test/support/renderSsr.ts +97 -0
  470. package/template/test/support/staticServer.ts +96 -0
  471. package/template/test/themeIcons.spec.ts +140 -0
  472. package/template/test/toastAnnouncement.spec.ts +133 -0
  473. package/template/test/tokens.spec.ts +102 -0
  474. package/template/test/uiMessagesPlugin.spec.ts +104 -0
  475. package/template/test/useBlockData.spec.ts +46 -0
  476. package/template/test/useEditing.spec.ts +54 -0
  477. package/template/test/useEldraIcon.spec.ts +126 -0
  478. package/template/test/useUiId.spec.ts +40 -0
  479. package/template/tokens.json +149 -0
  480. package/template/tsconfig.json +3 -0
  481. package/template/tsconfig.storybook.json +17 -0
  482. package/template/vitest-axe.d.ts +13 -0
  483. package/template/vitest.config.ts +44 -0
@@ -0,0 +1,245 @@
1
+ import { computed, ref, type ComputedRef, type Ref } from 'vue';
2
+ import { toStorefrontFailure, type StorefrontFailure } from './feedback';
3
+ import type { StorefrontAck, StorefrontCartLine, StorefrontCartTotals } from './types';
4
+
5
+ export interface CartStore {
6
+ lines: Ref<StorefrontCartLine[]>;
7
+ totals: Ref<StorefrontCartTotals | null>;
8
+ count: ComputedRef<number>;
9
+ pending: Ref<boolean>;
10
+ /**
11
+ * The last *run* mutation's failure message, for the cart as a whole — a status, not a per-call
12
+ * answer. A caller asking "did **my** call fail?" reads the value its own call resolved with
13
+ * (every mutation below answers `StorefrontFailure | null`); reading this instead would describe
14
+ * whatever the cart did last, including another block's request and a call that never ran.
15
+ */
16
+ error: Ref<string | null>;
17
+ /** The same failure, structured (`app/storefront/feedback.ts`), with the same caveat. */
18
+ lastFailure: Ref<StorefrontFailure | null>;
19
+ /**
20
+ * The three facts about the cart drawer that two unrelated component trees — the header
21
+ * (`blocks/navigation/Block.vue`) and the cart itself (`blocks/cart/Block.vue`) — have to agree
22
+ * on. **This doc comment is the one place the rules behind them live**; every other file that
23
+ * takes part points here rather than restating them.
24
+ *
25
+ * - `drawerOpen` — is the drawer showing. The bag toggles it, the `Drawer`'s `v-model` follows it,
26
+ * and the app shell sets it back to `false` on **every** route change: the drawer is mounted in
27
+ * `app/app.vue`, so no navigation unmounts it, and a modal `<dialog>` left open over the page the
28
+ * shopper just navigated to makes that page inert and stops it scrolling. The destinations inside
29
+ * the drawer (each line's product title, Check out when it is same-site, View cart) are ordinary
30
+ * router links, so one rule in the shell covers all of them and any added later; `popstate` is
31
+ * covered too, because the router turns it into a route change.
32
+ * - `drawerAvailable` — is a drawer mounted and *live*. It is what turns the header's bag from an
33
+ * `<a href="/cart">` into a `<button>` that toggles `drawerOpen`. Raised by the hosting block
34
+ * from `onMounted`, deliberately: on a prerendered page no mount hook has run, so the bag is a
35
+ * working link in the HTML a static host serves — what a visitor with no JavaScript, and one
36
+ * reading the page before it hydrates, has — and the swap to a button afterwards is an ordinary
37
+ * reactive update rather than a hydration correction.
38
+ * - `drawerHosted` — **the theme itself mounts the drawer.** A cart has to be openable from the
39
+ * header on every route, so the drawer belongs to the shell and not to a page: `app/app.vue`
40
+ * mounts one `cart` block in its `drawer` variant with `host` set. It declares this flag in its
41
+ * own `setup()`, before any block on the page is created, so a `drawer`-variant `cart` block an
42
+ * author placed finds it already true and defers — no `<dialog>` of its own, on the server as
43
+ * much as in the browser, which is what keeps the generated HTML and the hydrated page at
44
+ * exactly one drawer. That block still shows its editor placeholder, saying the theme hosts the
45
+ * drawer. No field and no `block.json` version changes, so nothing migrates on deploy.
46
+ *
47
+ * They are presentation state in a storefront object on purpose: this store is already the channel
48
+ * the header and the cart coordinate the drawer through, and it is built per request
49
+ * (`app/plugins/eldra-storefront.ts`), so nothing leaks between server renders.
50
+ */
51
+ drawerOpen: Ref<boolean>;
52
+ drawerAvailable: Ref<boolean>;
53
+ drawerHosted: Ref<boolean>;
54
+ lastRemoved: Ref<{ line: StorefrontCartLine; index: number } | null>;
55
+ /**
56
+ * Every mutation resolves with **its own** outcome: `null` when it succeeded, or when there was
57
+ * nothing to do (a line that is already gone, an undo with nothing to restore), and the failure
58
+ * when the backend refused it. That is what a block reports to the shopper
59
+ * (`app/composables/useStorefrontFeedback.ts`) — a store-wide field read after the fact cannot say
60
+ * whose call it describes, and says nothing at all about a call that returned early.
61
+ */
62
+ add(i: CartAddInput): Promise<StorefrontFailure | null>;
63
+ setQuantity(lineId: string, quantity: number): Promise<StorefrontFailure | null>;
64
+ remove(lineId: string): Promise<StorefrontFailure | null>;
65
+ undoRemove(): Promise<StorefrontFailure | null>;
66
+ applyDiscount(code: string): Promise<StorefrontAck>;
67
+ removeDiscount(code: string): Promise<StorefrontFailure | null>;
68
+ checkoutUrl: ComputedRef<string | null>;
69
+ }
70
+
71
+ /**
72
+ * Both halves of "what to put in the cart". The backend resolves the pair together — one lookup of
73
+ * "this variant, of this product" — so a variant id alone is not enough, and a product id sent as
74
+ * both is a pair that does not exist. A caller gets the pair from a product *detail* read
75
+ * (`StorefrontProduct.productId`/`variantId`) or from a cart line (`StorefrontCartLine`); a product
76
+ * card carries no variant at all, by design (`app/storefront/types.ts`).
77
+ */
78
+ export interface CartAddInput {
79
+ productId: string;
80
+ variantId: string;
81
+ quantity: number;
82
+ }
83
+
84
+ export interface CartSnapshot {
85
+ lines: StorefrontCartLine[];
86
+ totals: StorefrontCartTotals;
87
+ }
88
+
89
+ /**
90
+ * What `createCartStore` needs from whoever actually keeps the cart persisted: a live cart id
91
+ * plus `client.cart.*` for `gateway.ts`, an in-memory Northwind fixture for `demo.ts`. The store
92
+ * itself owns only reactive presentation state (`pending`/`error`, the drawer flags, the
93
+ * optimistic remove/undo pair) — every change that has to survive a reload goes through here.
94
+ */
95
+ export interface CartOps {
96
+ /** The cart as it exists when the store is created (e.g. a previously remembered cart id). */
97
+ init(): Promise<CartSnapshot>;
98
+ add(input: CartAddInput): Promise<CartSnapshot>;
99
+ setQuantity(lineId: string, quantity: number): Promise<CartSnapshot>;
100
+ remove(lineId: string): Promise<CartSnapshot>;
101
+ applyDiscount(code: string): Promise<{ ack: StorefrontAck; snapshot?: CartSnapshot }>;
102
+ removeDiscount(): Promise<CartSnapshot>;
103
+ /** Reactive so a cart id assigned after the first `add()` updates the link immediately. */
104
+ checkoutUrl: Ref<string | null>;
105
+ }
106
+
107
+ /**
108
+ * The shared cart engine both `demo.ts` and `gateway.ts` build their `StorefrontSource.cart` from,
109
+ * swapping only `ops` — this is what `cart.spec.ts` exercises directly, against a small fake `ops`
110
+ * it defines itself, so the reactive/undo/pending behaviour is proven once regardless of backend.
111
+ */
112
+ export function createCartStore(ops: CartOps): CartStore {
113
+ const lines = ref<StorefrontCartLine[]>([]) as Ref<StorefrontCartLine[]>;
114
+ const totals = ref<StorefrontCartTotals | null>(null);
115
+ const pending = ref(false);
116
+ const error = ref<string | null>(null);
117
+ const lastFailure = ref<StorefrontFailure | null>(null);
118
+
119
+ /** Every `catch` in this file, so no path can record one half of a failure and not the other —
120
+ * and the one place the caller's own answer comes from. */
121
+ function fail(caught: unknown): StorefrontFailure {
122
+ const failure = toStorefrontFailure(caught);
123
+ lastFailure.value = failure;
124
+ error.value = failure.message;
125
+ return failure;
126
+ }
127
+
128
+ /** Every mutation's start: the previous failure is this mutation's history, not its result. */
129
+ function clearFailure(): void {
130
+ lastFailure.value = null;
131
+ error.value = null;
132
+ }
133
+ const drawerOpen = ref(false);
134
+ const drawerAvailable = ref(false);
135
+ const drawerHosted = ref(false);
136
+ const lastRemoved = ref<{ line: StorefrontCartLine; index: number } | null>(null) as Ref<{
137
+ line: StorefrontCartLine;
138
+ index: number;
139
+ } | null>;
140
+
141
+ const count = computed(() => lines.value.reduce((sum, line) => sum + line.quantity, 0));
142
+ const checkoutUrl = computed(() => ops.checkoutUrl.value);
143
+
144
+ let inFlight = 0;
145
+
146
+ async function run(task: () => Promise<CartSnapshot>): Promise<StorefrontFailure | null> {
147
+ inFlight += 1;
148
+ pending.value = true;
149
+ clearFailure();
150
+ try {
151
+ const snapshot = await task();
152
+ lines.value = snapshot.lines;
153
+ totals.value = snapshot.totals;
154
+ return null;
155
+ } catch (caught) {
156
+ return fail(caught);
157
+ } finally {
158
+ inFlight -= 1;
159
+ if (inFlight === 0) pending.value = false;
160
+ }
161
+ }
162
+
163
+ // Loads whatever cart already exists (a remembered cart id for the gateway, the Northwind
164
+ // fixture for the demo) as soon as the store is created — no separate "refresh" the caller has
165
+ // to remember to call first.
166
+ void run(() => ops.init());
167
+
168
+ return {
169
+ lines,
170
+ totals,
171
+ count,
172
+ pending,
173
+ error,
174
+ lastFailure,
175
+ drawerOpen,
176
+ drawerAvailable,
177
+ drawerHosted,
178
+ lastRemoved,
179
+ checkoutUrl,
180
+ add: (input) => run(() => ops.add(input)),
181
+ setQuantity: (lineId, quantity) => run(() => ops.setQuantity(lineId, quantity)),
182
+ async remove(lineId) {
183
+ const index = lines.value.findIndex((line) => line.id === lineId);
184
+ // Already gone — nothing was asked of the backend, so nothing failed.
185
+ if (index === -1) return null;
186
+ const line = lines.value[index]!;
187
+ const failure = await run(() => ops.remove(lineId));
188
+ if (failure === null) lastRemoved.value = { line, index };
189
+ return failure;
190
+ },
191
+ async undoRemove() {
192
+ const removed = lastRemoved.value;
193
+ if (!removed) return null;
194
+ // Reinsert at the exact index it was removed from — trusting a re-`add()`'s own returned
195
+ // line order would not guarantee that, so this half is local and synchronous.
196
+ lines.value = [
197
+ ...lines.value.slice(0, removed.index),
198
+ removed.line,
199
+ ...lines.value.slice(removed.index),
200
+ ];
201
+ lastRemoved.value = null;
202
+ inFlight += 1;
203
+ pending.value = true;
204
+ clearFailure();
205
+ try {
206
+ const snapshot = await ops.add({
207
+ productId: removed.line.productId,
208
+ variantId: removed.line.variantId,
209
+ quantity: removed.line.quantity,
210
+ });
211
+ // Only totals are trusted from the backend here — `lines` stays the locally-restored
212
+ // order above.
213
+ totals.value = snapshot.totals;
214
+ return null;
215
+ } catch (caught) {
216
+ return fail(caught);
217
+ } finally {
218
+ inFlight -= 1;
219
+ if (inFlight === 0) pending.value = false;
220
+ }
221
+ },
222
+ async applyDiscount(code) {
223
+ inFlight += 1;
224
+ pending.value = true;
225
+ clearFailure();
226
+ try {
227
+ const { ack, snapshot } = await ops.applyDiscount(code);
228
+ if (snapshot) {
229
+ lines.value = snapshot.lines;
230
+ totals.value = snapshot.totals;
231
+ }
232
+ return ack;
233
+ } catch (caught) {
234
+ fail(caught);
235
+ return { ok: false, reason: 'failed' };
236
+ } finally {
237
+ inFlight -= 1;
238
+ if (inFlight === 0) pending.value = false;
239
+ }
240
+ },
241
+ // `code` identifies which applied-discount chip the caller removed; a cart only ever carries
242
+ // one discount today, so `ops.removeDiscount()` itself needs no argument.
243
+ removeDiscount: (_code) => run(() => ops.removeDiscount()),
244
+ };
245
+ }
@@ -0,0 +1,283 @@
1
+ /**
2
+ * The store's **category tree**, and the four things a theme does with it: a product's breadcrumb
3
+ * trail, the category page's own trail and child strip, the parent rows the collection grid's
4
+ * category facet is drawn with, and the canonical path every category link is addressed by.
5
+ *
6
+ * `GET /catalog/v1/categories` answers the whole list in one read — `{id, slug, title, parentId}`
7
+ * per row, a tree by `parentId` — and a product carries `primaryCategoryId` (plus `categoryIds`, the
8
+ * full set). Neither read carries a *trail* or a *path*: the ancestors are the theme's own walk up
9
+ * the tree, which is what this file is.
10
+ *
11
+ * Everything here is pure — no Vue, no client, no module state — so both storefront sources share it
12
+ * (`gateway.ts` builds the index from the live read, `demo.ts` from its fixture) and
13
+ * `test/storefront/categories.spec.ts` can pin every bound without mounting anything.
14
+ *
15
+ * `ancestorsOf` is also the demo storefront's own expansion of a ticked **parent** category
16
+ * (`app/storefront/facets.ts`), which is what makes the demo behave like the platform it stands in
17
+ * for rather than like a flat list.
18
+ *
19
+ * **Where a category crumb links to.** The theme ships a category *page* now
20
+ * (`pages/category.page.json`, route template `/categories/:path*`), and a category is addressed by
21
+ * its **canonical path**: the slugs of its ancestors, root first, then its own, joined with `/`.
22
+ * That path is the one thing the route answers — canonical only, no redirects — so it is what
23
+ * `pathOf` computes, what `idByPath` reads back, and what `categoryHref`
24
+ * (`app/utils/links.ts`) turns into a destination. A category the list cannot place has no path at
25
+ * all, which is also honest: there is no page to link to.
26
+ */
27
+ import { categoryHref } from '../utils/links';
28
+ import type { StorefrontCategory, StorefrontCategoryRef } from './types';
29
+
30
+ /** One row of the store's category list. Loose, like every raw gateway shape this theme reads. */
31
+ export interface CategoryRow {
32
+ id?: string;
33
+ slug?: string;
34
+ title?: string;
35
+ /** `null`/absent for a root. */
36
+ parentId?: string | null;
37
+ }
38
+
39
+ /** One category, as this theme needs it: always identified, always named, parent or root. */
40
+ export interface CategoryNode {
41
+ id: string;
42
+ slug: string;
43
+ title: string;
44
+ parentId: string | null;
45
+ }
46
+
47
+ /**
48
+ * The store's categories, by id, by slug and by canonical path.
49
+ *
50
+ * Each lookup is needed and for a different job: `byId` walks a product's `primaryCategoryId` up to
51
+ * its root (and gives a facet term its parent), `idBySlug` turns a shopper's `?category=ceramics`
52
+ * into the `categoryId` the catalog list filters by, and the two path maps are the category
53
+ * **page**'s — `idByPath` resolves the path a route carried, `pathById` builds the href a crumb,
54
+ * a child chip or a product's category label points at.
55
+ *
56
+ * A category whose ancestor chain does not reach a root through rows this list holds — a parent
57
+ * since unpublished, a `parentId` cycle — is in `byId` and in **neither** path map: it has no
58
+ * canonical path, so it has no page, and a path built over that gap would address a different
59
+ * category.
60
+ */
61
+ export interface CategoryIndex {
62
+ byId: ReadonlyMap<string, CategoryNode>;
63
+ idBySlug: ReadonlyMap<string, string>;
64
+ /** Canonical path → category id. */
65
+ idByPath: ReadonlyMap<string, string>;
66
+ /** Category id → canonical path. */
67
+ pathById: ReadonlyMap<string, string>;
68
+ }
69
+
70
+ export const EMPTY_CATEGORY_INDEX: CategoryIndex = {
71
+ byId: new Map(),
72
+ idBySlug: new Map(),
73
+ idByPath: new Map(),
74
+ pathById: new Map(),
75
+ };
76
+
77
+ /**
78
+ * How deep a chain may go before this stops walking.
79
+ *
80
+ * A guard against a cycle in the data, not a product decision: a category whose `parentId` points at
81
+ * a descendant (or at itself) would otherwise walk for ever inside a `computed`, where a throw takes
82
+ * the whole block down. Six is well past any storefront's real depth, and the `seen` set below
83
+ * already catches an outright loop — this catches the pathological chain too.
84
+ */
85
+ const MAX_TRAIL_DEPTH = 6;
86
+
87
+ /**
88
+ * A row is only usable with all three of an id, a slug and a title: the id is what a product and a
89
+ * facet term name it by, the slug is what a URL and a filter are spelled with, and the title is the
90
+ * only thing a shopper can read. A row missing any of them is dropped rather than shown as a crumb
91
+ * labelled with a uuid.
92
+ */
93
+ export function buildCategoryIndex(rows: readonly CategoryRow[] | null | undefined): CategoryIndex {
94
+ const byId = new Map<string, CategoryNode>();
95
+ const idBySlug = new Map<string, string>();
96
+ for (const row of rows ?? []) {
97
+ const { id, slug, title } = row;
98
+ if (typeof id !== 'string' || id === '') continue;
99
+ if (typeof slug !== 'string' || slug === '') continue;
100
+ if (typeof title !== 'string' || title === '') continue;
101
+ byId.set(id, { id, slug, title, parentId: row.parentId ?? null });
102
+ // First row wins a duplicate slug, the same way the whole-store slug→id lookup always behaved.
103
+ if (!idBySlug.has(slug)) idBySlug.set(slug, id);
104
+ }
105
+
106
+ const idByPath = new Map<string, string>();
107
+ const pathById = new Map<string, string>();
108
+ for (const node of byId.values()) {
109
+ const chain = chainOf(byId, node);
110
+ if (chain === null) continue;
111
+ const path = [...chain, node].map((level) => level.slug).join('/');
112
+ pathById.set(node.id, path);
113
+ // First row wins a duplicate path too — two siblings sharing a slug are one page, and the
114
+ // second cannot be reached by a URL whatever this did.
115
+ if (!idByPath.has(path)) idByPath.set(path, node.id);
116
+ }
117
+ return { byId, idBySlug, idByPath, pathById };
118
+ }
119
+
120
+ /**
121
+ * The node's ancestors, root first, or `null` when the chain does not reach a root through rows the
122
+ * index holds — a missing parent, or a cycle. `null` is the answer that costs the node its path.
123
+ */
124
+ function chainOf(
125
+ byId: ReadonlyMap<string, CategoryNode>,
126
+ node: CategoryNode
127
+ ): CategoryNode[] | null {
128
+ const chain: CategoryNode[] = [];
129
+ const seen = new Set<string>([node.id]);
130
+ let parentId = node.parentId;
131
+ for (let depth = 0; depth < MAX_TRAIL_DEPTH; depth += 1) {
132
+ if (parentId === null || parentId === '') return chain;
133
+ if (seen.has(parentId)) return null;
134
+ const parent = byId.get(parentId);
135
+ if (parent === undefined) return null;
136
+ seen.add(parentId);
137
+ chain.unshift(parent);
138
+ parentId = parent.parentId;
139
+ }
140
+ return null;
141
+ }
142
+
143
+ /**
144
+ * The path the catalogue grid lives at — `pages/products.page.json`'s own slug. One constant so the
145
+ * paging links, the docs and the specs cannot drift from the page.
146
+ */
147
+ export const CATALOGUE_PATH = '/products';
148
+
149
+ /**
150
+ * A category's canonical path, or `null` for a category the index cannot place. The one place a
151
+ * caller should get a path from: never `node.slug` on its own, which is a path only for a root.
152
+ */
153
+ export function pathOf(index: CategoryIndex, categoryId: string | null | undefined): string | null {
154
+ if (typeof categoryId !== 'string' || categoryId === '') return null;
155
+ return index.pathById.get(categoryId) ?? null;
156
+ }
157
+
158
+ /** One crumb: what the shopper reads, and where it goes. */
159
+ export interface CategoryCrumb {
160
+ label: string;
161
+ href: string;
162
+ }
163
+
164
+ /**
165
+ * A product's category trail, **root ancestor first, the product's own category last**.
166
+ *
167
+ * `[]` for every honest "no trail": a product with no category (`null`/`''`), a `primaryCategoryId`
168
+ * the category list does not hold (a category since unpublished, or a list this read could not
169
+ * reach), a category the list holds but cannot place (its own parent is gone, so there is no page to
170
+ * link to), or an index that is empty because the read failed. A product page without a category
171
+ * crumb is a page; a page with a crumb reading `undefined` is a bug, so there is no fallback label
172
+ * here.
173
+ *
174
+ * Every level is a real category **page** now, and every level's href is that page's canonical path
175
+ * — which is why the trail is walked **down** the leaf's own path rather than up the tree: each
176
+ * prefix of a canonical path is itself a canonical path, so the ancestors come out already placed.
177
+ *
178
+ * The last level is still a link. A product's category is not the current page — the product is — so
179
+ * every level stays followable, which is also why `product-detail` draws the trail itself rather
180
+ * than through `@eldrajs/ui`'s `Breadcrumb` (that one always renders its last item as the current
181
+ * page).
182
+ */
183
+ export function categoryTrailFor(
184
+ index: CategoryIndex,
185
+ categoryId: string | null | undefined
186
+ ): CategoryCrumb[] {
187
+ const leafPath = pathOf(index, categoryId);
188
+ if (leafPath === null) return [];
189
+ const segments = leafPath.split('/');
190
+ return segments.flatMap((_segment, depth) => {
191
+ const path = segments.slice(0, depth + 1).join('/');
192
+ const id = index.idByPath.get(path);
193
+ const node = id === undefined ? undefined : index.byId.get(id);
194
+ return node === undefined ? [] : [{ label: node.title, href: categoryHref(path) }];
195
+ });
196
+ }
197
+
198
+ /** The ancestors of a category, root first, excluding the category itself. */
199
+ export function ancestorsOf(index: CategoryIndex, categoryId: string): CategoryNode[] {
200
+ const out: CategoryNode[] = [];
201
+ const seen = new Set<string>([categoryId]);
202
+ let id = index.byId.get(categoryId)?.parentId ?? null;
203
+ while (id !== null && id !== '' && out.length < MAX_TRAIL_DEPTH && !seen.has(id)) {
204
+ seen.add(id);
205
+ const node = index.byId.get(id);
206
+ if (node === undefined) break;
207
+ out.unshift(node);
208
+ id = node.parentId;
209
+ }
210
+ return out;
211
+ }
212
+
213
+ /**
214
+ * The **direct** children of a category, in the order the list served them — what the category
215
+ * page's child strip is drawn from, and never a whole subtree: the strip is one level, so a
216
+ * grandchild belongs under its own parent's page.
217
+ *
218
+ * A child the index cannot place is left out, because it has no page to link to.
219
+ */
220
+ export function childrenOf(index: CategoryIndex, categoryId: string): CategoryNode[] {
221
+ const out: CategoryNode[] = [];
222
+ if (categoryId === '') return out;
223
+ for (const node of index.byId.values()) {
224
+ if (node.parentId === categoryId && index.pathById.has(node.id)) out.push(node);
225
+ }
226
+ return out;
227
+ }
228
+
229
+ /**
230
+ * Whether a category is the given one or a descendant of it — the test a **category page's** own
231
+ * scope is held to.
232
+ *
233
+ * The platform's `categoryId` filter matches a whole subtree, so a category page asks for its own
234
+ * id and a shopper ticking a child narrows *within* that subtree. A ticked value that is not in the
235
+ * subtree would widen it instead (the parameter is an OR over a list), which is a category page
236
+ * showing products that are not in its category — so the scope is intersected through this rather
237
+ * than trusted.
238
+ */
239
+ export function isInSubtree(index: CategoryIndex, categoryId: string, rootId: string): boolean {
240
+ if (categoryId === '' || rootId === '') return false;
241
+ if (categoryId === rootId) return true;
242
+ return ancestorsOf(index, categoryId).some((ancestor) => ancestor.id === rootId);
243
+ }
244
+
245
+ /**
246
+ * **One category placed in the tree, by its canonical path** — what a category page is drawn from,
247
+ * and the one implementation both storefront sources answer `catalog.category` with.
248
+ *
249
+ * `null` for a path no category occupies: a leaf without its ancestors, a wrong parent, a trailing
250
+ * extra segment, or a category the tree cannot place at all. The route is canonical only, so those
251
+ * are the same answer — there is no page here — and the block draws its own empty state rather than
252
+ * a heading with nothing under it.
253
+ *
254
+ * The ancestors come out of the path's own prefixes rather than a second walk up the tree: every
255
+ * prefix of a canonical path is itself a canonical path, so they are already placed and already in
256
+ * order.
257
+ */
258
+ export function placeCategory(index: CategoryIndex, path: string): StorefrontCategory | null {
259
+ const id = index.idByPath.get(path);
260
+ const node = id === undefined ? undefined : index.byId.get(id);
261
+ if (id === undefined || node === undefined) return null;
262
+ const segments = path.split('/');
263
+ const ancestors = segments.slice(0, -1).flatMap((_segment, depth) => {
264
+ const ancestorPath = segments.slice(0, depth + 1).join('/');
265
+ const ancestorId = index.idByPath.get(ancestorPath);
266
+ const ancestor = ancestorId === undefined ? undefined : index.byId.get(ancestorId);
267
+ return ancestor === undefined ? [] : [refOf(ancestor, ancestorPath)];
268
+ });
269
+ return {
270
+ id,
271
+ slug: node.slug,
272
+ title: node.title,
273
+ path,
274
+ ancestors,
275
+ children: childrenOf(index, id).map((child) =>
276
+ refOf(child, index.pathById.get(child.id) ?? '')
277
+ ),
278
+ };
279
+ }
280
+
281
+ function refOf(node: CategoryNode, path: string): StorefrontCategoryRef {
282
+ return { slug: node.slug, title: node.title, path };
283
+ }
@@ -0,0 +1,60 @@
1
+ import type { StorefrontCollectionSelector } from './types';
2
+
3
+ /**
4
+ * Turns what a block knows about "which collection" into the one identifier the
5
+ * storefront layer takes (`StorefrontCollectionSelector`).
6
+ *
7
+ * A `reference` field targeting catalog collections is the only way a block
8
+ * names a collection — the legacy handle fields are gone. It normally stores the
9
+ * collection's id, so a renamed collection can never silently empty a block, and
10
+ * the public read resolves that id into an object carrying the `slug` too — but
11
+ * not always: at depth 0, and while the page builder is showing an unsaved draft
12
+ * overlay, the value is the bare stub `{ id, _type: 'collection' }`. A theme's
13
+ * own seed is the mirror image (`{ _type: 'collection', slug }`, which Core
14
+ * resolves against the organisation's catalog on deploy). All three are usable,
15
+ * and the `slug` is preferred when it is there because every storefront can look
16
+ * a handle up, while resolving an id may cost an extra request or not be
17
+ * possible at all (`gateway.ts`).
18
+ *
19
+ * `routeSlug` is the collection template's own segment
20
+ * (`storefront.route.collectionHandle`), the fallback for a block dropped onto a
21
+ * collection page with the field left empty — "field wins, route is the
22
+ * fallback". `product-carousel` passes none: it never sits on a collection
23
+ * route's own subject.
24
+ */
25
+ export function collectionSelector(
26
+ reference: EldraCollectionReference | null | undefined,
27
+ routeSlug?: string | null
28
+ ): StorefrontCollectionSelector | null {
29
+ const picked = referenceSelector(reference);
30
+ if (picked !== null) return picked;
31
+ const trimmed = (routeSlug ?? '').trim();
32
+ return trimmed === '' ? null : { slug: trimmed };
33
+ }
34
+
35
+ /** The slug a selector names, or `null` when it names a collection by id — what
36
+ * a block needs for anything a slug is the only key to, such as a
37
+ * `/collections/<slug>` link. */
38
+ export function selectorSlug(selector: StorefrontCollectionSelector | null): string | null {
39
+ return selector !== null && 'slug' in selector ? selector.slug : null;
40
+ }
41
+
42
+ /** Whether the selector can only be resolved by id: the case a storefront may
43
+ * not be able to answer, where the block shows its empty state and, in the
44
+ * editor, the "publish to load products" hint rather than an error. */
45
+ export function selectorNeedsPublish(selector: StorefrontCollectionSelector | null): boolean {
46
+ return selector !== null && !('slug' in selector);
47
+ }
48
+
49
+ /** The reference's own identifier. Field data is CMS-authored, so neither key is
50
+ * assumed to be present at runtime even though the generated type declares
51
+ * `id` as required. */
52
+ function referenceSelector(
53
+ reference: EldraCollectionReference | null | undefined
54
+ ): StorefrontCollectionSelector | null {
55
+ if (reference === null || reference === undefined) return null;
56
+ const slug = typeof reference.slug === 'string' ? reference.slug.trim() : '';
57
+ if (slug !== '') return { slug };
58
+ const id = typeof reference.id === 'string' ? reference.id.trim() : '';
59
+ return id !== '' ? { id } : null;
60
+ }
@@ -0,0 +1,58 @@
1
+ import type { StorefrontCommerce } from './types';
2
+
3
+ /**
4
+ * Reads the `commerce` slice `@eldrajs/theme-nuxt` puts on `runtimeConfig.public.eldra` — the
5
+ * store's own settings, read once from the platform during the build (that module's
6
+ * `src/runtime/commerce.ts`). `null` when the store publishes none, when the build had no gateway
7
+ * credentials, or when the read failed; the module warns about all three at build time.
8
+ *
9
+ * Both plugins that need it go through here (`eldra-ui-messages` wants only the currency,
10
+ * `eldra-storefront` puts the whole thing on `useStorefront()`), so the shape is read once rather
11
+ * than cast twice.
12
+ *
13
+ * It is checked because this is an `unknown` boundary, not because a customer is expected to write
14
+ * the key: the module rebuilds `runtimeConfig.public.eldra` itself and then overwrites `commerce`
15
+ * with what it read, so `nuxt.config.ts` cannot set it. What arrives here is still whatever a
16
+ * runtime config happens to hold — a Nuxt `NUXT_PUBLIC_…` override on a server-rendered deploy,
17
+ * hand-edited `.nuxt` state, some future writer — and the rule is all-or-nothing on purpose: a
18
+ * half-set record would reach a block reading `taxInclusivePricing` as `undefined`, which tests as
19
+ * "prices exclude tax" at every call site that asks. A partial answer is no answer — but it is a
20
+ * loud one, because throwing away a currency somebody did publish is not something to do quietly.
21
+ */
22
+ export function toStorefrontCommerce(value: unknown): StorefrontCommerce | null {
23
+ // `null` and `undefined` — and `''`, which is what reaches the page when the module wrote `null`:
24
+ // Nuxt serialises a null public-runtime-config value as an empty string (the same thing happens
25
+ // to `locale`) — all mean one thing, that the store published nothing. Not a mistake, nothing to
26
+ // report.
27
+ if (value === null || value === undefined || value === '') return null;
28
+ if (typeof value !== 'object') return discard(value, 'commerce is not an object');
29
+ const { currency, taxInclusivePricing, defaultTaxRate } = value as Record<string, unknown>;
30
+ if (typeof currency !== 'string' || currency === '') return discard(value, 'currency');
31
+ if (typeof taxInclusivePricing !== 'boolean') return discard(value, 'taxInclusivePricing');
32
+ if (typeof defaultTaxRate !== 'number') return discard(value, 'defaultTaxRate');
33
+ return { currency, taxInclusivePricing, defaultTaxRate };
34
+ }
35
+
36
+ /**
37
+ * Says which field was missing or wrong, in dev only. A store whose whole page silently drops to
38
+ * bare numbers because two tax fields were absent is a bug nobody can see; the dev guard keeps the
39
+ * line out of a production bundle, where there is nobody to read it and the page has already made
40
+ * the safe choice.
41
+ *
42
+ * Vite's `import.meta.env.DEV`, not Nuxt's `import.meta.dev`: this module is also compiled by
43
+ * Storybook and by the test run, neither of which is a Nuxt build — the same guard, and for the
44
+ * same reason, that `@eldrajs/ui`'s own `Price` uses for its invalid-currency warning. It is read
45
+ * through a cast because the starter does not depend on `vite` itself, so `vite/client`'s
46
+ * declaration of `ImportMeta.env` is not available to every tsconfig that compiles this file; an
47
+ * environment that defines neither simply never warns, which is the safe direction.
48
+ */
49
+ function discard(value: unknown, field: string): null {
50
+ const meta = import.meta as ImportMeta & { env?: { DEV?: boolean } };
51
+ if (meta.env?.DEV === true) {
52
+ console.warn(
53
+ `[eldra] ignoring the store's commerce settings: ${field} is missing or not the right type`,
54
+ value
55
+ );
56
+ }
57
+ return null;
58
+ }