@eldrajs/theme-cli 0.0.0-stage → 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 +27 -2
  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 +56 -3
  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,233 @@
1
+ import { computed, ref, type Ref } from 'vue';
2
+ import type { HistoryStore, WishlistStore } from './types';
3
+
4
+ const RECENTLY_VIEWED_KEY = 'eldra.storefront.recentlyViewed';
5
+ const WISHLIST_KEY = 'eldra.storefront.wishlist';
6
+ const DISMISSED_ANNOUNCEMENTS_KEY = 'eldra.storefront.dismissedAnnouncements';
7
+ const MAX_RECENTLY_VIEWED = 12;
8
+
9
+ /**
10
+ * `localStorage` may be absent (SSR, a unit test running under `environment: 'node'`), disabled
11
+ * (a locked-down browser setting), or full — every read and write here degrades to empty/no-op
12
+ * instead of throwing, the same defensive shape `@eldrajs/sdk`'s own `createCartSession` uses.
13
+ */
14
+ function safeStorage(): Storage | null {
15
+ try {
16
+ return typeof localStorage === 'undefined' ? null : localStorage;
17
+ } catch {
18
+ return null;
19
+ }
20
+ }
21
+
22
+ function readStringList(key: string): string[] {
23
+ try {
24
+ const raw = safeStorage()?.getItem(key);
25
+ if (!raw) return [];
26
+ const parsed: unknown = JSON.parse(raw);
27
+ return Array.isArray(parsed)
28
+ ? parsed.filter((value): value is string => typeof value === 'string')
29
+ : [];
30
+ } catch {
31
+ return [];
32
+ }
33
+ }
34
+
35
+ function writeStringList(key: string, value: string[]): void {
36
+ try {
37
+ safeStorage()?.setItem(key, JSON.stringify(value));
38
+ } catch {
39
+ // Storage unavailable, full, or throwing — the in-memory ref this call already updated is the
40
+ // only state that survives for the rest of this session.
41
+ }
42
+ }
43
+
44
+ /**
45
+ * A short, stable, non-cryptographic hash — just enough to key a dismissal by an announcement's
46
+ * text without storing the whole (possibly long, localized) string as the storage key itself, and
47
+ * without a hashing dependency for something this small.
48
+ */
49
+ export function hashMessage(message: string): string {
50
+ let hash = 0;
51
+ for (let index = 0; index < message.length; index += 1) {
52
+ hash = (hash * 31 + message.charCodeAt(index)) | 0;
53
+ }
54
+ return (hash >>> 0).toString(36);
55
+ }
56
+
57
+ /**
58
+ * Recently-viewed products (`product-detail` records, `product-carousel`'s `recently-viewed`
59
+ * variant reads) and dismissed announcement bars — both `localStorage`-backed, both theme state
60
+ * the SDK has no concept of.
61
+ */
62
+ export function createHistoryStore(
63
+ options: { initialRecentlyViewed?: string[] } = {}
64
+ ): HistoryStore {
65
+ const recentlyViewed = ref<string[]>(
66
+ options.initialRecentlyViewed ?? readStringList(RECENTLY_VIEWED_KEY)
67
+ ) as Ref<string[]>;
68
+ const dismissed = ref<string[]>(readStringList(DISMISSED_ANNOUNCEMENTS_KEY)) as Ref<string[]>;
69
+
70
+ return {
71
+ recentlyViewed,
72
+ recordView(handle) {
73
+ const next = [
74
+ handle,
75
+ ...recentlyViewed.value.filter((existing) => existing !== handle),
76
+ ].slice(0, MAX_RECENTLY_VIEWED);
77
+ recentlyViewed.value = next;
78
+ writeStringList(RECENTLY_VIEWED_KEY, next);
79
+ },
80
+ clearViews() {
81
+ recentlyViewed.value = [];
82
+ writeStringList(RECENTLY_VIEWED_KEY, []);
83
+ },
84
+ isAnnouncementDismissed(message) {
85
+ return dismissed.value.includes(hashMessage(message));
86
+ },
87
+ dismissAnnouncement(message) {
88
+ const hash = hashMessage(message);
89
+ if (dismissed.value.includes(hash)) return;
90
+ const next = [...dismissed.value, hash];
91
+ dismissed.value = next;
92
+ writeStringList(DISMISSED_ANNOUNCEMENTS_KEY, next);
93
+ },
94
+ };
95
+ }
96
+
97
+ /**
98
+ * The one `storage` listener, and every hydrated store's re-read behind it. Module level because
99
+ * the number of *stores* on a page is not something this file controls (see `createWishlistStore`'s
100
+ * own cross-tab note below) while the number of listeners it needs is exactly one.
101
+ */
102
+ const wishlistStorageReaders = new Set<() => void>();
103
+ let wishlistStorageListener: ((event: StorageEvent) => void) | null = null;
104
+
105
+ function subscribeToWishlistStorage(reread: () => void): () => void {
106
+ wishlistStorageReaders.add(reread);
107
+ // `typeof window` rather than a truthiness check: on the server the identifier does not exist at
108
+ // all, and reading an undeclared one throws.
109
+ if (wishlistStorageListener === null && typeof window !== 'undefined') {
110
+ wishlistStorageListener = (event: StorageEvent) => {
111
+ // `key === null` is the whole store being cleared, which includes this key.
112
+ if (event.key !== null && event.key !== WISHLIST_KEY) return;
113
+ for (const run of [...wishlistStorageReaders]) run();
114
+ };
115
+ window.addEventListener('storage', wishlistStorageListener);
116
+ }
117
+ return () => {
118
+ wishlistStorageReaders.delete(reread);
119
+ if (wishlistStorageReaders.size > 0 || wishlistStorageListener === null) return;
120
+ window.removeEventListener('storage', wishlistStorageListener);
121
+ wishlistStorageListener = null;
122
+ };
123
+ }
124
+
125
+ /**
126
+ * The wishlist: the product handles a shopper saved for later, kept in their own browser.
127
+ *
128
+ * **Local only, on purpose.** There is no account behind it and no platform endpoint for one yet,
129
+ * so the whole list is `localStorage` under `eldra.storefront.wishlist` — the same namespace and the
130
+ * same bare JSON array `createHistoryStore` above persists `recentlyViewed` with, and the same
131
+ * unversioned shape `@eldrajs/sdk`'s `createCartSession` keeps the cart id in. Nothing here is
132
+ * wrapped in a `{ version, data }` envelope because neither of those is: the value is a list of
133
+ * strings, every element that is not a string is dropped on read (`readStringList`), and a stored
134
+ * value this code cannot make sense of degrades to an empty list rather than to an error. A
135
+ * migration, if the shape ever grows, is a new key — which is also how `recentlyViewed` would do it.
136
+ *
137
+ * **Handles, not ids.** A saved product is addressed by its storefront handle, which is what the
138
+ * catalogue's own `filter=slug:in:…` read takes (`StorefrontCatalog.byHandles`), so the wishlist
139
+ * page turns the whole list into one batched products read with no extra id bookkeeping — and a
140
+ * handle is also what every surface that can save a product already has in hand.
141
+ *
142
+ * **`items` is empty until `hydrate()`, and that gate is load-bearing.** A shopper's saved list is
143
+ * their own browser's state, so it is never in the HTML a build wrote: a prerendered page shows no
144
+ * saved hearts and no header count. If the store read `localStorage` at construction instead, the
145
+ * browser's *first* render — the one that has to equal the file it is hydrating — would already
146
+ * know the list, disagree with that markup, and make Vue repaint rather than hydrate. So the read
147
+ * happens in `onMounted` (`app/composables/useWishlist.ts` is the one place that calls it, and
148
+ * every surface goes through it), which never runs on the server and runs after the first client
149
+ * render. It is the same gate `blocks/navigation/Block.vue` puts on the cart count, for the same
150
+ * reason. `hydrate()` is idempotent, and every mutation reads storage first (`ensureRead` below) so
151
+ * a toggle on a surface that somehow skipped the composable cannot write an empty list over a saved
152
+ * one.
153
+ *
154
+ * **Cross-tab.** A hydrated store follows the `storage` event, which fires in every *other* tab of
155
+ * the origin, so saving something in one tab updates the header count and the wishlist page in the
156
+ * rest. There is **one listener for the whole page** rather than one per store
157
+ * (`subscribeToWishlistStorage` below): `useStorefront()` builds a fallback demo storefront *per
158
+ * calling component* when nothing is provided — every Storybook story and every block mount does
159
+ * that — and a listener per store would leave one behind for each of them, keeping a dead `items`
160
+ * ref alive and re-reading storage on every event. `release()` is the other half: `useWishlist()`
161
+ * calls it from `onUnmounted`, and the last consumer leaving takes the listener with it.
162
+ */
163
+ export function createWishlistStore(): WishlistStore {
164
+ const items = ref<string[]>([]) as Ref<string[]>;
165
+ /** Has storage been read into `items` yet — separate from whether anyone is listening. */
166
+ let read = false;
167
+ /** Live consumers, so the last one to unmount is the one that drops the listener. */
168
+ let consumers = 0;
169
+ let unsubscribe: (() => void) | null = null;
170
+
171
+ function reread(): void {
172
+ items.value = readStringList(WISHLIST_KEY);
173
+ }
174
+
175
+ /**
176
+ * The read on its own, with no subscription: what a mutation needs before it writes, so a toggle
177
+ * on a store nobody hydrated cannot put `[handle]` over a saved list. It must not subscribe,
178
+ * because nothing would ever release what it registered.
179
+ */
180
+ function ensureRead(): void {
181
+ if (read) return;
182
+ read = true;
183
+ reread();
184
+ }
185
+
186
+ function hydrate(): void {
187
+ consumers += 1;
188
+ ensureRead();
189
+ if (unsubscribe === null) unsubscribe = subscribeToWishlistStorage(reread);
190
+ }
191
+
192
+ function release(): void {
193
+ if (consumers > 0) consumers -= 1;
194
+ if (consumers > 0 || unsubscribe === null) return;
195
+ unsubscribe();
196
+ unsubscribe = null;
197
+ }
198
+
199
+ function write(next: string[]): void {
200
+ items.value = next;
201
+ writeStringList(WISHLIST_KEY, next);
202
+ }
203
+
204
+ return {
205
+ items,
206
+ count: computed(() => items.value.length),
207
+ hydrate,
208
+ release,
209
+ has(handle) {
210
+ return items.value.includes(handle);
211
+ },
212
+ toggle(handle) {
213
+ ensureRead();
214
+ const saved = !items.value.includes(handle);
215
+ // Newest first, like `recentlyViewed`: the wishlist page renders the list in order, and the
216
+ // product a shopper just saved is the one they are most likely looking for.
217
+ write(
218
+ saved ? [handle, ...items.value] : items.value.filter((existing) => existing !== handle)
219
+ );
220
+ return saved;
221
+ },
222
+ remove(handle) {
223
+ ensureRead();
224
+ if (!items.value.includes(handle)) return;
225
+ write(items.value.filter((existing) => existing !== handle));
226
+ },
227
+ clear() {
228
+ ensureRead();
229
+ if (items.value.length === 0) return;
230
+ write([]);
231
+ },
232
+ };
233
+ }
@@ -0,0 +1,247 @@
1
+ import type { ComputedRef } from 'vue';
2
+ import {
3
+ currencyFractionDigits,
4
+ currencySymbol,
5
+ formatCurrency,
6
+ useEldraUiCurrency,
7
+ useEldraUiLocale,
8
+ } from '@eldrajs/ui';
9
+
10
+ /**
11
+ * The theme's money helpers. Storefront amounts are **major units** the whole way through
12
+ * (`types.ts`) — 28 is twenty-eight dollars, not twenty-eight cents — because that is what the
13
+ * gateway sends, and converting on the way in only moves the rounding somewhere less visible.
14
+ *
15
+ * Two shapes are needed because `@eldrajs/ui` takes the other convention: `Price`/`ProductCard`
16
+ * read **minor** units (their own `amount` docs say so), so anything handed to one of those
17
+ * components goes through `toMinorUnits` first, while money that has to appear inside a sentence
18
+ * ("Add to cart · 2.800 kr.") is formatted here with `formatMoney`. A third shape names the
19
+ * currency itself rather than an amount in it ("ISK kr"): `currencyLabel`.
20
+ *
21
+ * **Nothing here builds an `Intl.NumberFormat` of its own.** Both money shapes go through
22
+ * `@eldrajs/ui`'s `formatCurrency`/`currencySymbol`, which is the same formatter — and therefore
23
+ * the same **narrow** currency sign — that every `<Price>`, `<ProductCard>` and `<CurrencyInput>`
24
+ * on the page renders with. A hand-built `{ style: 'currency' }` formatter writes the *wide* sign
25
+ * instead, and that is exactly how this theme came to read "ISK 2,800" in a button label beside a
26
+ * `<Price>` reading "kr 2,800" for the same money.
27
+ *
28
+ * **The currency is the store's, and it is never guessed.** It comes from the platform — the
29
+ * organisation's own commerce settings, read once at build and put on
30
+ * `runtimeConfig.public.eldra.commerce` by `@eldrajs/theme-nuxt`, provided to the whole app under
31
+ * `@eldrajs/ui`'s `CURRENCY_KEY` by `app/plugins/eldra-ui-messages.ts`. So both helpers take it
32
+ * **explicitly, with no default**: a currency guessed from the content locale renders real amounts
33
+ * under the wrong sign, which is worse than rendering them with no sign at all. A store that
34
+ * publishes none formats its prices as a plain number (see `formatMoney`), exactly as the
35
+ * package's own `<Price>` does for the same answer.
36
+ */
37
+
38
+ /** The one locale the theme formats money in until the storefront can say otherwise. */
39
+ export const DEFAULT_LOCALE = 'en-US';
40
+
41
+ /**
42
+ * ISO 4217's own default minor-unit count, for the one case where there is no currency to ask:
43
+ * it is also what `@eldrajs/ui`'s `currencyFractionDigits` falls back to, so `toMinorUnits` and
44
+ * the `<Price>` the value is handed to agree about the scale either way.
45
+ */
46
+ const DEFAULT_FRACTION_DIGITS = 2;
47
+
48
+ /** How one currency-and-locale pair formats: everything both helpers below need, resolved once. */
49
+ interface MoneyFormat {
50
+ format: (amount: number) => string;
51
+ /** Minor units per major unit, as a power of ten. */
52
+ digits: number;
53
+ }
54
+
55
+ /**
56
+ * One cache per currency-and-locale pair, keyed by both.
57
+ *
58
+ * `useMoney().format` is a fresh call on every render of every price and a collection grid renders
59
+ * one or two per card, so what this saves is worth saving: the `currencyFractionDigits` lookup, the
60
+ * one probe that decides whether `Intl` will accept the store's code at all, and — for a store with
61
+ * no currency — the one `Intl.NumberFormat` this module still constructs itself. A store has one
62
+ * currency and a handful of locales, so the cache is a few entries that never need evicting.
63
+ *
64
+ * What it deliberately does **not** cache is a currency formatter. `formatCurrency` is
65
+ * `@eldrajs/ui`'s own, stateless by design, and the single place the narrow sign and the
66
+ * fraction-digit rule are decided; a formatter cached here would be a second definition of both,
67
+ * which is precisely the bug this module had. Its per-amount construction is a few microseconds
68
+ * against a render that costs far more.
69
+ */
70
+ const formats = new Map<string, MoneyFormat>();
71
+
72
+ function resolveFormat(currency: string | undefined, locale: string): MoneyFormat {
73
+ const code = currency ?? '';
74
+ const key = `${locale}\u0000${code}`;
75
+ const cached = formats.get(key);
76
+ if (cached !== undefined) return cached;
77
+
78
+ // The same rule `<Price>` applies to the value `toMinorUnits` hands it, so the two can only ever
79
+ // divide and multiply by the same power of ten — and the same cap `<Price>` formats with, so a
80
+ // zero-decimal currency stays integral in a sentence as well.
81
+ const digits = code === '' ? DEFAULT_FRACTION_DIGITS : currencyFractionDigits(code, locale);
82
+
83
+ /**
84
+ * A plain decimal, for the two cases with no usable currency sign. The code is appended only when
85
+ * there is one to show: a store that published none has nothing to print after the number, and a
86
+ * dangling separator would reach the DOM and the accessible text of every price on the page.
87
+ */
88
+ const decimal = (): MoneyFormat => {
89
+ const formatter = new Intl.NumberFormat(locale, { style: 'decimal' });
90
+ return {
91
+ format: (amount) =>
92
+ code === '' ? formatter.format(amount) : `${formatter.format(amount)} ${code}`,
93
+ digits,
94
+ };
95
+ };
96
+
97
+ let resolved: MoneyFormat;
98
+ if (code === '') {
99
+ resolved = decimal();
100
+ } else {
101
+ // `formatCurrency` throws `RangeError` for a code `Intl` does not know, exactly as the private
102
+ // helper it ports does, and this runs inside `computed`s where a throw takes the whole block
103
+ // down. So the code is probed once per pair here rather than guarded once per amount.
104
+ try {
105
+ formatCurrency(0, locale, code, true, digits, digits);
106
+ resolved = {
107
+ // The narrow sign is the util's own default and the whole reason to go through it. The
108
+ // currency's own count goes in twice: as the cap, because the util's default of 2 would
109
+ // print a fractional króna and round a three-decimal currency to two; and as the
110
+ // **minimum**, which is the util's display rule — without it `$96` and `$96.50` sit in the
111
+ // same column. Both are exactly what `<Price>` passes, so a formatted sentence and the
112
+ // `<Price>` beside it cannot disagree about either.
113
+ format: (amount) => formatCurrency(amount, locale, code, true, digits, digits),
114
+ digits,
115
+ };
116
+ } catch {
117
+ resolved = decimal();
118
+ }
119
+ }
120
+
121
+ formats.set(key, resolved);
122
+ return resolved;
123
+ }
124
+
125
+ /**
126
+ * A major-unit amount as text, in the currency's own shape and its **narrow** sign: `$28.00` for
127
+ * `USD`, `2.800 kr.` for `ISK` on an Icelandic page, `kr 2,800` for the same money on an English
128
+ * one. The fraction count is the currency's own, as both the maximum and the minimum, so a
129
+ * zero-decimal currency never renders phantom decimals and a two-decimal one never renders a
130
+ * ragged column.
131
+ *
132
+ * Three outcomes, and the last two are the honest ones:
133
+ *
134
+ * - a currency the platform published and `Intl` knows — the formatted amount;
135
+ * - **no currency at all** (`undefined` or `''`: the store has not configured commerce) — a plain
136
+ * decimal, no symbol and no code, because there is no code to print;
137
+ * - a code `Intl` rejects — a plain decimal plus the raw code (`28 XYZ1`), the same shape
138
+ * `@eldrajs/ui`'s `Price` falls back to for the identical failure.
139
+ */
140
+ export function formatMoney(
141
+ amount: number,
142
+ currency: string | undefined,
143
+ locale: string = DEFAULT_LOCALE
144
+ ): string {
145
+ return resolveFormat(currency, locale).format(amount);
146
+ }
147
+
148
+ /**
149
+ * A currency *code* as text naming itself, not an amount: `"ISK kr."` on an Icelandic page,
150
+ * `"ISK kr"` on an English one, `"USD $"` — the code plus the sign `formatMoney` prints in front
151
+ * of the amounts on the same page, for a place that names the store's currency rather than
152
+ * formatting a price in it (the footer's currency selector, with one option now that the platform
153
+ * publishes one currency).
154
+ *
155
+ * `@eldrajs/ui`'s `currencySymbol` is where the sign comes from — the **narrow** one, read out of
156
+ * `formatToParts`, never a hand-maintained code → symbol table — so this label and every price on
157
+ * the page are written with the same character. One fallback, and it is the honest one: the code
158
+ * appended to itself is noise, so a currency with no sign distinct from its code in this locale
159
+ * (which is also what `currencySymbol` answers for a code `Intl` rejects) prints just the code.
160
+ */
161
+ export function currencyLabel(code: string, locale: string = DEFAULT_LOCALE): string {
162
+ const symbol = currencySymbol(code, locale);
163
+ return symbol === code ? code : `${code} ${symbol}`;
164
+ }
165
+
166
+ /**
167
+ * Major units → the minor units `@eldrajs/ui`'s `Price`/`ProductCard` expect, using the currency's
168
+ * own minor-unit count rather than a hard-coded ×100 (`ISK` has none: 28 krónur stays 28). With no
169
+ * currency it uses `DEFAULT_FRACTION_DIGITS`, which is what the `<Price>` reading the result falls
170
+ * back to as well.
171
+ */
172
+ export function toMinorUnits(
173
+ amount: number,
174
+ currency: string | undefined,
175
+ locale: string = DEFAULT_LOCALE
176
+ ): number {
177
+ return Math.round(amount * 10 ** resolveFormat(currency, locale).digits);
178
+ }
179
+
180
+ /**
181
+ * The minor units the **platform's own facets** count in, back to the major units every money field
182
+ * in `types.ts` carries — the exact inverse of `toMinorUnits`, over the same currency's own
183
+ * minor-unit count (`ISK` has none: 2800 krónur stays 2800, `USD` 2800 is $28).
184
+ *
185
+ * It exists for one answer, and the comment belongs with the helper rather than the call site: the
186
+ * catalog's `facets.price` span is counted over the same `minPrice`/`maxPrice` parameters it is
187
+ * filtered by, so it arrives in minor units while `CatalogFacets.price` — the span a price slider
188
+ * is drawn across and the shopper's own bounds are written in — is major like everything else.
189
+ * Handing the slider the raw span draws a track a hundred times too wide on a two-decimal currency
190
+ * and writes a `?price=` nothing matches.
191
+ */
192
+ export function fromMinorUnits(
193
+ amount: number,
194
+ currency: string | undefined,
195
+ locale: string = DEFAULT_LOCALE
196
+ ): number {
197
+ return amount / 10 ** resolveFormat(currency, locale).digits;
198
+ }
199
+
200
+ /**
201
+ * Rounds a sum back to two decimals. Major-unit arithmetic is floating point (`28.99 * 3` is
202
+ * `86.96999999999998`), so every total the theme computes itself — a line total, a cart subtotal,
203
+ * a percentage discount — is rounded before it is shown or added to another amount.
204
+ */
205
+ export function roundMoney(amount: number): number {
206
+ return Math.round(amount * 100) / 100;
207
+ }
208
+
209
+ /**
210
+ * The store currency, or `undefined` when the platform published none.
211
+ *
212
+ * `@eldrajs/ui`'s own composable, under the theme's name for it: it reads the very provide the
213
+ * package's components read (`CURRENCY_KEY`), so a `<Price>` and a formatted sentence beside it
214
+ * can never disagree, and it guesses no code — a store whose currency the platform does not know
215
+ * shows its prices as numbers, not as dollars. (The same reasoning does not apply to the number
216
+ * locale: grouping and decimal separators have a sane default, and `useEldraUiLocale()`'s is the
217
+ * theme's own.)
218
+ *
219
+ * Kept as a named wrapper rather than inlined at the two call sites because "the store's currency"
220
+ * is the theme's own vocabulary, and because this is where a theme that resolved it differently —
221
+ * per market, say — would say so once.
222
+ */
223
+ export function useStoreCurrency(): ComputedRef<string | undefined> {
224
+ return useEldraUiCurrency();
225
+ }
226
+
227
+ /**
228
+ * The money helpers bound to the store's currency and the locale the surrounding `@eldrajs/ui`
229
+ * components already resolve — the one place a block resolves either. Call it in `setup()` like
230
+ * any composable.
231
+ *
232
+ * `currency` is exposed for the few callers that format outside a component (`blocks/search`'s
233
+ * pure result mapper takes a formatter built from it).
234
+ */
235
+ export function useMoney(): {
236
+ format: (amount: number) => string;
237
+ minor: (amount: number) => number;
238
+ currency: ComputedRef<string | undefined>;
239
+ } {
240
+ const currency = useStoreCurrency();
241
+ const locale = useEldraUiLocale();
242
+ return {
243
+ format: (amount) => formatMoney(amount, currency.value, locale.value),
244
+ minor: (amount) => toMinorUnits(amount, currency.value, locale.value),
245
+ currency,
246
+ };
247
+ }
@@ -0,0 +1,71 @@
1
+ /**
2
+ * **How a variant option is displayed, and the one place that decision is made.**
3
+ *
4
+ * A merchant chooses it in Studio ("Display as": None / Color / Custom) and the platform stores it
5
+ * on the option itself, so every storefront draws the same option the same way. Both storefront
6
+ * sources go through these two functions — `gateway.ts` reading a live response, `demo.ts`
7
+ * declaring its fixture — which is what keeps `StorefrontProductOption.type` derived from `kind`
8
+ * rather than decided twice.
9
+ *
10
+ * Framework-free and dependency-free on purpose: `facets.ts`, `gateway.ts` and `demo.ts` all import
11
+ * it, and a block may read it too (it is not a Nuxt global — see `CLAUDE.md`'s `blocks/**` rule).
12
+ */
13
+ import type { StorefrontOptionKind } from './types';
14
+
15
+ /**
16
+ * Every kind the platform stores, in its own order.
17
+ *
18
+ * Exported for a **fork**, not for this theme: `storefrontOptionKind` below is its only reader here.
19
+ * The starter is source a customer owns, and a customer who adds a storefront source of their own
20
+ * needs the vocabulary to validate against without restating it.
21
+ */
22
+ export const STOREFRONT_OPTION_KINDS = ['none', 'color', 'custom'] as const;
23
+
24
+ /**
25
+ * **What the wire said, or `none`.** A response from a gateway older than the contract that added
26
+ * the field carries no `kind` at all, and a value this theme has never heard of is a kind it cannot
27
+ * draw — both read as `none`, which is the display every option had before the field existed. Never
28
+ * a throw: this runs on the product read's own path, where a refusal replaces the whole page with
29
+ * an error alert over a presentational field.
30
+ *
31
+ * **It never looks at the option's key.** An option a merchant named "Color" or "Colour" and left on
32
+ * None is pills, because that is what the merchant chose; guessing from the name is what this field
33
+ * exists to replace.
34
+ */
35
+ export function storefrontOptionKind(raw: unknown): StorefrontOptionKind {
36
+ return STOREFRONT_OPTION_KINDS.includes(raw as StorefrontOptionKind)
37
+ ? (raw as StorefrontOptionKind)
38
+ : 'none';
39
+ }
40
+
41
+ /**
42
+ * **`kind` plus a colour to show → the control.** `color` is the only kind that can draw swatches;
43
+ * `none` and `custom` are both pills. A `custom` option is deliberately not a third control: it is
44
+ * pills plus a name (`StorefrontProductOption.metadata`) a theme branches on when it wants one — see
45
+ * `docs/starter-kit.md`.
46
+ *
47
+ * **A `color` option with no colours on any of its values draws pills.** The kind is *permission* to
48
+ * show colours, never a promise that there are any: the platform leaves a value's `swatch` nullable
49
+ * and Studio's own colour control is clearable, so "Display as: Color, colours not picked yet" and
50
+ * "…cleared again" are both ordinary states a merchant can be in. A swatch picker handed no colours
51
+ * draws one blank disc per value with the value's name in visually hidden text — a shopper sees a row
52
+ * of identical empty circles and cannot tell M from XL — where the pills it replaced read their names
53
+ * out loud. So the swatch control is earned by the data, exactly as a filter group's colour dots are
54
+ * (`blocks/collection-grid/parts/groups.ts`'s `facetTypeFor`, the same rule for the same reason), and
55
+ * the two surfaces cannot disagree about one option.
56
+ *
57
+ * **One value without a colour inside an option that has them is kept, uncoloured** — the filter
58
+ * panel's behaviour for the same case, where such a row draws an empty dot beside its name. In the
59
+ * picker's swatch mode that one disc is also unlabelled, since the label is `sr-only` there; filling
60
+ * the colour in (or clearing the rest, which drops the whole option to pills) is the merchant's fix,
61
+ * and dropping the value instead would hide a variant a shopper can buy.
62
+ *
63
+ * `values` defaults to empty, so calling it with a kind alone answers `pills` for every kind — the
64
+ * safe half of the decision, never an accidental swatch group.
65
+ */
66
+ export function optionDisplayType(
67
+ kind: StorefrontOptionKind,
68
+ values: ReadonlyArray<{ swatch?: string | null }> = []
69
+ ): 'swatches' | 'pills' {
70
+ return kind === 'color' && values.some((value) => value.swatch) ? 'swatches' : 'pills';
71
+ }
@@ -0,0 +1,77 @@
1
+ import type { StorefrontPrerenderHandle } from './gateway';
2
+
3
+ /**
4
+ * The bridge between a framework's keyed async data and `gateway.ts`'s
5
+ * `StorefrontRuntime.prerender`, kept out of the plugin so its two sharp edges can be tested
6
+ * without a Nuxt runtime. Both are Nuxt 4.5 behaviours, not guesses — see
7
+ * `nuxt/dist/app/composables/asyncData.js`:
8
+ *
9
+ * * **Never pass a `default`.** A hydrating client short-circuits the whole fetch when
10
+ * `data.value !== undefined` (`asyncData.js`, the `fetchOnServer && nuxtApp.isHydrating`
11
+ * branch), and `default: () => null` makes that true before anything has run. The result is a
12
+ * page whose payload happened not to carry this key — a block rendered only on the client, a
13
+ * key that changed since the build — sitting at `data === null` forever with its handler never
14
+ * called.
15
+ * * **And recover anyway.** On that same miss Nuxt defers the first fetch to the component's
16
+ * `onBeforeMount`, so the handle's own promise resolves *before* the load has run and with
17
+ * nothing in it. A status that is neither `success` nor `error` once it settles is exactly
18
+ * that case, and the only honest answer is to run the load now. `dedupe: 'defer'` is what
19
+ * makes the deferred fetch join this one instead of issuing a second — and what makes two
20
+ * blocks that read the same thing cost one request rather than two.
21
+ */
22
+
23
+ /** What this adapter uses of one keyed async-data handle. Structural, so a spec can model it. */
24
+ export interface KeyedAsyncData<T> {
25
+ data: { value: T | null | undefined };
26
+ error: { value: unknown };
27
+ /** `'idle' | 'pending' | 'success' | 'error'`. */
28
+ status: { value: string };
29
+ /** Runs the load now, joining one already in flight for the same key (`dedupe: 'defer'`). */
30
+ execute(): Promise<unknown>;
31
+ /** Settles when the load registered when the handle was created has finished. */
32
+ settled: Promise<unknown>;
33
+ }
34
+
35
+ /** The options this adapter insists on. Both are correctness, not tuning — see above. */
36
+ export interface KeyedAsyncDataOptions {
37
+ dedupe: 'defer';
38
+ }
39
+
40
+ export type KeyedAsyncDataFn = <T>(
41
+ key: string,
42
+ load: () => Promise<T | null>,
43
+ options: KeyedAsyncDataOptions
44
+ ) => KeyedAsyncData<T>;
45
+
46
+ export function prerenderThroughAsyncData<T>(
47
+ asyncData: KeyedAsyncDataFn,
48
+ key: string,
49
+ load: () => Promise<T | null>
50
+ ): StorefrontPrerenderHandle<T> {
51
+ const handle = asyncData<T>(key, load, { dedupe: 'defer' });
52
+ // A value in hand before anything has run is the hydration payload's, and Nuxt has already called
53
+ // the key `success` for it (`asyncData.js`, the short-circuit branch). `null` counts: it is the
54
+ // answer the server rendered from, not the absence of one, and the status confirms it for a
55
+ // framework that spells an empty answer some other way.
56
+ const answered =
57
+ handle.data.value !== undefined || handle.status.value === 'success'
58
+ ? { data: handle.data.value ?? null }
59
+ : null;
60
+ return {
61
+ answered,
62
+ settled: (async () => {
63
+ await handle.settled;
64
+ // Settled with no answer and no failure: the hydration miss above. Run the load.
65
+ if (handle.status.value !== 'success' && handle.status.value !== 'error') {
66
+ await handle.execute();
67
+ }
68
+ return { data: handle.data.value ?? null, error: asyncDataError(handle.error.value) };
69
+ })(),
70
+ };
71
+ }
72
+
73
+ /** A framework's own error object, as the one string a `StorefrontResult` carries. */
74
+ export function asyncDataError(caught: unknown): string | null {
75
+ if (caught === null || caught === undefined) return null;
76
+ return caught instanceof Error ? caught.message : String(caught);
77
+ }