@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.
- package/CHANGELOG.md +69 -0
- package/LICENSE +21 -0
- package/README.md +27 -2
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +203 -0
- package/dist/index.d.ts +174 -0
- package/dist/index.js +3 -0
- package/dist/validate-C6jB8_Oc.js +510 -0
- package/package.json +56 -3
- package/template/.eldra/block-types.d.ts +429 -0
- package/template/.eldra/manifest.json +9377 -0
- package/template/.eldra/previews.json +36 -0
- package/template/.github/workflows/eldra-deploy.yml +24 -0
- package/template/.gitlab-ci.yml +16 -0
- package/template/.storybook/eldra.ts +123 -0
- package/template/.storybook/i18n.ts +23 -0
- package/template/.storybook/main.ts +59 -0
- package/template/.storybook/nuxt-link-stub.ts +23 -0
- package/template/.storybook/preview.ts +52 -0
- package/template/.storybook/shims-vue.d.ts +10 -0
- package/template/.storybook/virtual-eldra.d.ts +27 -0
- package/template/README.md +288 -0
- package/template/app/app.vue +126 -0
- package/template/app/assets/main.css +404 -0
- package/template/app/components/EldraIcon.vue +66 -0
- package/template/app/components/EldraRouterLink.vue +62 -0
- package/template/app/components/ui/UiImage.stories.ts +30 -0
- package/template/app/components/ui/UiImage.vue +224 -0
- package/template/app/components/ui/__tests__/UiImage.spec.ts +292 -0
- package/template/app/composables/iconComponent.ts +84 -0
- package/template/app/composables/iconFetcher.ts +14 -0
- package/template/app/composables/useBlockData.ts +30 -0
- package/template/app/composables/useEditing.ts +31 -0
- package/template/app/composables/useEldraIcon.ts +46 -0
- package/template/app/composables/useRevalidating.ts +69 -0
- package/template/app/composables/useRichTextScrollRegions.ts +80 -0
- package/template/app/composables/useStorefront.ts +18 -0
- package/template/app/composables/useStorefrontFeedback.ts +49 -0
- package/template/app/composables/useUiId.ts +18 -0
- package/template/app/composables/useWishlist.ts +42 -0
- package/template/app/i18n.d.ts +28 -0
- package/template/app/icons.ts +185 -0
- package/template/app/pages/[...slug].vue +134 -0
- package/template/app/plugins/eldra-i18n.ts +98 -0
- package/template/app/plugins/eldra-storefront.ts +288 -0
- package/template/app/plugins/eldra-ui-messages.ts +112 -0
- package/template/app/storefront/cart.ts +245 -0
- package/template/app/storefront/categories.ts +283 -0
- package/template/app/storefront/collectionSelector.ts +60 -0
- package/template/app/storefront/commerce.ts +58 -0
- package/template/app/storefront/demo.ts +1313 -0
- package/template/app/storefront/facets.ts +476 -0
- package/template/app/storefront/feedback.ts +122 -0
- package/template/app/storefront/gateway.ts +2256 -0
- package/template/app/storefront/history.ts +233 -0
- package/template/app/storefront/money.ts +247 -0
- package/template/app/storefront/options.ts +71 -0
- package/template/app/storefront/prerender.ts +77 -0
- package/template/app/storefront/refresh.ts +222 -0
- package/template/app/storefront/toProductCard.ts +154 -0
- package/template/app/storefront/types.ts +815 -0
- package/template/app/storefront/volatile.ts +211 -0
- package/template/app/templates.ts +544 -0
- package/template/app/utils/classes.ts +40 -0
- package/template/app/utils/links.ts +70 -0
- package/template/app/utils/pageStructure.ts +77 -0
- package/template/app/utils/pageTitle.ts +37 -0
- package/template/app/virtual-eldra.d.ts +12 -0
- package/template/bitbucket-pipelines.yml +19 -0
- package/template/blocks/announcement-bar/Block.vue +203 -0
- package/template/blocks/announcement-bar/__tests__/Block.spec.ts +227 -0
- package/template/blocks/announcement-bar/block.json +45 -0
- package/template/blocks/announcement-bar/mock.json +7 -0
- package/template/blocks/announcement-bar/preview.png +0 -0
- package/template/blocks/article/Block.vue +317 -0
- package/template/blocks/article/__tests__/Block.spec.ts +229 -0
- package/template/blocks/article/block.json +148 -0
- package/template/blocks/article/mock.json +512 -0
- package/template/blocks/article/preview.json +16 -0
- package/template/blocks/article/preview.png +0 -0
- package/template/blocks/article-list/Block.vue +343 -0
- package/template/blocks/article-list/__tests__/Block.spec.ts +279 -0
- package/template/blocks/article-list/block.json +181 -0
- package/template/blocks/article-list/mock.json +68 -0
- package/template/blocks/article-list/preview.json +84 -0
- package/template/blocks/article-list/preview.png +0 -0
- package/template/blocks/breadcrumbs/Block.vue +278 -0
- package/template/blocks/breadcrumbs/__tests__/Block.spec.ts +461 -0
- package/template/blocks/breadcrumbs/block.json +89 -0
- package/template/blocks/breadcrumbs/mock.json +11 -0
- package/template/blocks/breadcrumbs/preview.json +3 -0
- package/template/blocks/breadcrumbs/preview.png +0 -0
- package/template/blocks/cart/Block.vue +372 -0
- package/template/blocks/cart/__tests__/Block.spec.ts +561 -0
- package/template/blocks/cart/__tests__/ShippingBar.spec.ts +78 -0
- package/template/blocks/cart/__tests__/Summary.spec.ts +245 -0
- package/template/blocks/cart/block.json +74 -0
- package/template/blocks/cart/mock.json +11 -0
- package/template/blocks/cart/parts/CartLines.vue +257 -0
- package/template/blocks/cart/parts/ShippingBar.vue +105 -0
- package/template/blocks/cart/parts/Summary.vue +291 -0
- package/template/blocks/cart/preview.png +0 -0
- package/template/blocks/collection-grid/Block.vue +1832 -0
- package/template/blocks/collection-grid/__tests__/Block.spec.ts +3037 -0
- package/template/blocks/collection-grid/__tests__/groups.spec.ts +731 -0
- package/template/blocks/collection-grid/block.json +187 -0
- package/template/blocks/collection-grid/mock.json +23 -0
- package/template/blocks/collection-grid/parts/groups.ts +861 -0
- package/template/blocks/collection-grid/preview.json +7 -0
- package/template/blocks/collection-grid/preview.png +0 -0
- package/template/blocks/collection-header/Block.vue +533 -0
- package/template/blocks/collection-header/__tests__/Block.spec.ts +381 -0
- package/template/blocks/collection-header/block.json +140 -0
- package/template/blocks/collection-header/mock.json +28 -0
- package/template/blocks/collection-header/preview.json +14 -0
- package/template/blocks/collection-header/preview.png +0 -0
- package/template/blocks/contact/Block.vue +621 -0
- package/template/blocks/contact/__tests__/Block.spec.ts +347 -0
- package/template/blocks/contact/block.json +174 -0
- package/template/blocks/contact/mock.json +28 -0
- package/template/blocks/contact/preview.json +9 -0
- package/template/blocks/contact/preview.png +0 -0
- package/template/blocks/cta/Block.vue +383 -0
- package/template/blocks/cta/__tests__/Block.spec.ts +309 -0
- package/template/blocks/cta/block.json +86 -0
- package/template/blocks/cta/mock.json +10 -0
- package/template/blocks/cta/preview.json +9 -0
- package/template/blocks/cta/preview.png +0 -0
- package/template/blocks/faq/Block.vue +254 -0
- package/template/blocks/faq/__tests__/Block.spec.ts +312 -0
- package/template/blocks/faq/block.json +113 -0
- package/template/blocks/faq/mock.json +115 -0
- package/template/blocks/faq/preview.png +0 -0
- package/template/blocks/feature-grid/Block.vue +241 -0
- package/template/blocks/feature-grid/__tests__/Block.spec.ts +311 -0
- package/template/blocks/feature-grid/block.json +106 -0
- package/template/blocks/feature-grid/mock.json +29 -0
- package/template/blocks/feature-grid/preview.json +45 -0
- package/template/blocks/feature-grid/preview.png +0 -0
- package/template/blocks/footer/Block.vue +652 -0
- package/template/blocks/footer/__tests__/Block.spec.ts +700 -0
- package/template/blocks/footer/block.json +240 -0
- package/template/blocks/footer/mock.json +161 -0
- package/template/blocks/footer/preview.png +0 -0
- package/template/blocks/gallery/Block.vue +416 -0
- package/template/blocks/gallery/__tests__/Block.spec.ts +289 -0
- package/template/blocks/gallery/block.json +87 -0
- package/template/blocks/gallery/mock.json +16 -0
- package/template/blocks/gallery/preview.json +64 -0
- package/template/blocks/gallery/preview.png +0 -0
- package/template/blocks/hero/Block.vue +378 -0
- package/template/blocks/hero/__tests__/Block.spec.ts +324 -0
- package/template/blocks/hero/block.json +146 -0
- package/template/blocks/hero/mock.json +11 -0
- package/template/blocks/hero/preview.json +55 -0
- package/template/blocks/hero/preview.png +0 -0
- package/template/blocks/image/Block.vue +232 -0
- package/template/blocks/image/__tests__/Block.spec.ts +224 -0
- package/template/blocks/image/block.json +67 -0
- package/template/blocks/image/mock.json +7 -0
- package/template/blocks/image/preview.json +9 -0
- package/template/blocks/image/preview.png +0 -0
- package/template/blocks/logo-cloud/Block.vue +206 -0
- package/template/blocks/logo-cloud/__tests__/Block.spec.ts +210 -0
- package/template/blocks/logo-cloud/block.json +79 -0
- package/template/blocks/logo-cloud/mock.json +15 -0
- package/template/blocks/logo-cloud/preview.json +92 -0
- package/template/blocks/logo-cloud/preview.png +0 -0
- package/template/blocks/navigation/Block.vue +1348 -0
- package/template/blocks/navigation/__tests__/Block.spec.ts +2030 -0
- package/template/blocks/navigation/block.json +167 -0
- package/template/blocks/navigation/mock.json +191 -0
- package/template/blocks/navigation/preview.png +0 -0
- package/template/blocks/navigation/useMegaMenuKeys.ts +276 -0
- package/template/blocks/newsletter/Block.vue +399 -0
- package/template/blocks/newsletter/__tests__/Block.spec.ts +365 -0
- package/template/blocks/newsletter/block.json +105 -0
- package/template/blocks/newsletter/mock.json +31 -0
- package/template/blocks/newsletter/preview.png +0 -0
- package/template/blocks/order-status/Block.vue +754 -0
- package/template/blocks/order-status/__tests__/Block.spec.ts +515 -0
- package/template/blocks/order-status/block.json +138 -0
- package/template/blocks/order-status/mock.json +19 -0
- package/template/blocks/order-status/preview.png +0 -0
- package/template/blocks/pricing-table/Block.vue +297 -0
- package/template/blocks/pricing-table/__tests__/Block.spec.ts +357 -0
- package/template/blocks/pricing-table/block.json +155 -0
- package/template/blocks/pricing-table/mock.json +47 -0
- package/template/blocks/pricing-table/preview.png +0 -0
- package/template/blocks/product-carousel/Block.vue +459 -0
- package/template/blocks/product-carousel/__tests__/Block.spec.ts +957 -0
- package/template/blocks/product-carousel/block.json +71 -0
- package/template/blocks/product-carousel/mock.json +9 -0
- package/template/blocks/product-carousel/preview.json +7 -0
- package/template/blocks/product-carousel/preview.png +0 -0
- package/template/blocks/product-detail/Block.vue +886 -0
- package/template/blocks/product-detail/__tests__/Block.spec.ts +1495 -0
- package/template/blocks/product-detail/__tests__/stock.spec.ts +119 -0
- package/template/blocks/product-detail/block.json +155 -0
- package/template/blocks/product-detail/mock.json +113 -0
- package/template/blocks/product-detail/parts/Gallery.vue +181 -0
- package/template/blocks/product-detail/parts/StickyBuyBar.vue +99 -0
- package/template/blocks/product-detail/preview.png +0 -0
- package/template/blocks/product-detail/stock.ts +150 -0
- package/template/blocks/quote/Block.vue +206 -0
- package/template/blocks/quote/__tests__/Block.spec.ts +265 -0
- package/template/blocks/quote/block.json +76 -0
- package/template/blocks/quote/mock.json +9 -0
- package/template/blocks/quote/preview.json +16 -0
- package/template/blocks/quote/preview.png +0 -0
- package/template/blocks/rich-text/Block.vue +143 -0
- package/template/blocks/rich-text/__tests__/Block.spec.ts +191 -0
- package/template/blocks/rich-text/block.json +57 -0
- package/template/blocks/rich-text/mock.json +87 -0
- package/template/blocks/rich-text/preview.png +0 -0
- package/template/blocks/search/Block.vue +589 -0
- package/template/blocks/search/PopularChips.vue +40 -0
- package/template/blocks/search/TypeSection.vue +148 -0
- package/template/blocks/search/__tests__/Block.spec.ts +718 -0
- package/template/blocks/search/__tests__/results.spec.ts +166 -0
- package/template/blocks/search/block.json +102 -0
- package/template/blocks/search/mock.json +18 -0
- package/template/blocks/search/preview.png +0 -0
- package/template/blocks/search/results.ts +85 -0
- package/template/blocks/split-content/Block.vue +195 -0
- package/template/blocks/split-content/__tests__/Block.spec.ts +225 -0
- package/template/blocks/split-content/block.json +70 -0
- package/template/blocks/split-content/mock.json +45 -0
- package/template/blocks/split-content/preview.json +58 -0
- package/template/blocks/split-content/preview.png +0 -0
- package/template/blocks/stats/Block.vue +159 -0
- package/template/blocks/stats/__tests__/Block.spec.ts +194 -0
- package/template/blocks/stats/block.json +73 -0
- package/template/blocks/stats/mock.json +12 -0
- package/template/blocks/stats/preview.png +0 -0
- package/template/blocks/tabs/Block.vue +278 -0
- package/template/blocks/tabs/__tests__/Block.spec.ts +303 -0
- package/template/blocks/tabs/block.json +97 -0
- package/template/blocks/tabs/mock.json +129 -0
- package/template/blocks/tabs/preview.json +153 -0
- package/template/blocks/tabs/preview.png +0 -0
- package/template/blocks/team/Block.vue +288 -0
- package/template/blocks/team/__tests__/Block.spec.ts +221 -0
- package/template/blocks/team/block.json +125 -0
- package/template/blocks/team/mock.json +39 -0
- package/template/blocks/team/preview.json +62 -0
- package/template/blocks/team/preview.png +0 -0
- package/template/blocks/testimonials/Block.vue +408 -0
- package/template/blocks/testimonials/__tests__/Block.spec.ts +319 -0
- package/template/blocks/testimonials/block.json +121 -0
- package/template/blocks/testimonials/mock.json +46 -0
- package/template/blocks/testimonials/preview.json +68 -0
- package/template/blocks/testimonials/preview.png +0 -0
- package/template/blocks/timeline/Block.vue +274 -0
- package/template/blocks/timeline/__tests__/Block.spec.ts +310 -0
- package/template/blocks/timeline/block.json +98 -0
- package/template/blocks/timeline/mock.json +27 -0
- package/template/blocks/timeline/preview.png +0 -0
- package/template/blocks/trust-strip/Block.vue +330 -0
- package/template/blocks/trust-strip/__tests__/Block.spec.ts +290 -0
- package/template/blocks/trust-strip/block.json +117 -0
- package/template/blocks/trust-strip/mock.json +37 -0
- package/template/blocks/trust-strip/preview.png +0 -0
- package/template/blocks/video-embed/Block.vue +354 -0
- package/template/blocks/video-embed/__tests__/Block.spec.ts +219 -0
- package/template/blocks/video-embed/__tests__/embed.spec.ts +76 -0
- package/template/blocks/video-embed/block.json +94 -0
- package/template/blocks/video-embed/embed.ts +84 -0
- package/template/blocks/video-embed/mock.json +13 -0
- package/template/blocks/video-embed/preview.json +9 -0
- package/template/blocks/video-embed/preview.png +0 -0
- package/template/blocks/wishlist/Block.vue +367 -0
- package/template/blocks/wishlist/__tests__/Block.spec.ts +508 -0
- package/template/blocks/wishlist/block.json +42 -0
- package/template/blocks/wishlist/mock.json +9 -0
- package/template/blocks/wishlist/preview.png +0 -0
- package/template/i18n/en-US.json +602 -0
- package/template/i18n/is-IS.json +602 -0
- package/template/nuxt.config.ts +148 -0
- package/template/package.json +55 -0
- package/template/pages/article.page.json +731 -0
- package/template/pages/cart.page.json +85 -0
- package/template/pages/category.page.json +133 -0
- package/template/pages/collection.page.json +194 -0
- package/template/pages/home.page.json +353 -0
- package/template/pages/product.page.json +323 -0
- package/template/pages/products.page.json +144 -0
- package/template/pages/search.page.json +83 -0
- package/template/pages/wishlist.page.json +88 -0
- package/template/public/demo/article-cover.svg +1 -0
- package/template/public/demo/article-figure.svg +1 -0
- package/template/public/demo/avatar-1.svg +3 -0
- package/template/public/demo/avatar-2.svg +3 -0
- package/template/public/demo/avatar-3.svg +3 -0
- package/template/public/demo/avatar-4.svg +3 -0
- package/template/public/demo/avatar-5.svg +3 -0
- package/template/public/demo/avatar-6.svg +3 -0
- package/template/public/demo/avatar-7.svg +3 -0
- package/template/public/demo/avatar-8.svg +3 -0
- package/template/public/demo/collection-1.svg +1 -0
- package/template/public/demo/collection-2.svg +1 -0
- package/template/public/demo/cta-split.svg +1 -0
- package/template/public/demo/feature-1.svg +1 -0
- package/template/public/demo/feature-2.svg +1 -0
- package/template/public/demo/feature-3.svg +1 -0
- package/template/public/demo/feature-4.svg +1 -0
- package/template/public/demo/gallery-1.svg +1 -0
- package/template/public/demo/gallery-2.svg +1 -0
- package/template/public/demo/gallery-3.svg +1 -0
- package/template/public/demo/gallery-4.svg +1 -0
- package/template/public/demo/gallery-5.svg +1 -0
- package/template/public/demo/gallery-6.svg +1 -0
- package/template/public/demo/gallery-7.svg +1 -0
- package/template/public/demo/gallery-8.svg +1 -0
- package/template/public/demo/hero-slide-1.svg +1 -0
- package/template/public/demo/hero-slide-2.svg +1 -0
- package/template/public/demo/hero-slide-3.svg +1 -0
- package/template/public/demo/hero-slide-4.svg +1 -0
- package/template/public/demo/hero-wide.svg +1 -0
- package/template/public/demo/hero.svg +1 -0
- package/template/public/demo/logo-1.svg +4 -0
- package/template/public/demo/logo-2.svg +4 -0
- package/template/public/demo/logo-3.svg +4 -0
- package/template/public/demo/logo-4.svg +4 -0
- package/template/public/demo/logo-5.svg +4 -0
- package/template/public/demo/logo-6.svg +4 -0
- package/template/public/demo/logo-7.svg +4 -0
- package/template/public/demo/logo-8.svg +4 -0
- package/template/public/demo/logo.svg +3 -0
- package/template/public/demo/map.svg +1 -0
- package/template/public/demo/poster.svg +1 -0
- package/template/public/demo/product-1.svg +4 -0
- package/template/public/demo/product-10.svg +4 -0
- package/template/public/demo/product-11.svg +4 -0
- package/template/public/demo/product-12.svg +4 -0
- package/template/public/demo/product-2.svg +4 -0
- package/template/public/demo/product-3.svg +4 -0
- package/template/public/demo/product-4.svg +4 -0
- package/template/public/demo/product-5.svg +4 -0
- package/template/public/demo/product-6.svg +4 -0
- package/template/public/demo/product-7.svg +4 -0
- package/template/public/demo/product-8.svg +4 -0
- package/template/public/demo/product-9.svg +4 -0
- package/template/public/demo/product-square-1.svg +4 -0
- package/template/public/demo/product-square-2.svg +4 -0
- package/template/public/demo/product-square-3.svg +4 -0
- package/template/public/demo/product-square-4.svg +4 -0
- package/template/public/demo/product-square-5.svg +4 -0
- package/template/public/demo/product-square-6.svg +4 -0
- package/template/public/demo/quote-portrait.svg +4 -0
- package/template/public/demo/split-1.svg +1 -0
- package/template/public/demo/split-2.svg +1 -0
- package/template/public/demo/split-3.svg +1 -0
- package/template/public/demo/split-4.svg +1 -0
- package/template/public/demo/team-1.svg +4 -0
- package/template/public/demo/team-2.svg +4 -0
- package/template/public/demo/team-3.svg +4 -0
- package/template/public/demo/team-4.svg +4 -0
- package/template/scripts/demo-images.mjs +393 -0
- package/template/scripts/generate-stories.mjs +156 -0
- package/template/scripts/previewHash.mjs +125 -0
- package/template/scripts/previews.mjs +149 -0
- package/template/stories/generated/announcement-bar.stories.ts +44 -0
- package/template/stories/generated/article-list.stories.ts +87 -0
- package/template/stories/generated/article.stories.ts +27 -0
- package/template/stories/generated/breadcrumbs.stories.ts +39 -0
- package/template/stories/generated/cart.stories.ts +38 -0
- package/template/stories/generated/collection-grid.stories.ts +117 -0
- package/template/stories/generated/collection-header.stories.ts +51 -0
- package/template/stories/generated/contact.stories.ts +45 -0
- package/template/stories/generated/cta.stories.ts +51 -0
- package/template/stories/generated/faq.stories.ts +56 -0
- package/template/stories/generated/feature-grid.stories.ts +69 -0
- package/template/stories/generated/footer.stories.ts +50 -0
- package/template/stories/generated/gallery.stories.ts +81 -0
- package/template/stories/generated/hero.stories.ts +75 -0
- package/template/stories/generated/image.stories.ts +99 -0
- package/template/stories/generated/logo-cloud.stories.ts +57 -0
- package/template/stories/generated/navigation.stories.ts +62 -0
- package/template/stories/generated/newsletter.stories.ts +68 -0
- package/template/stories/generated/order-status.stories.ts +32 -0
- package/template/stories/generated/pricing-table.stories.ts +44 -0
- package/template/stories/generated/product-carousel.stories.ts +75 -0
- package/template/stories/generated/product-detail.stories.ts +62 -0
- package/template/stories/generated/quote.stories.ts +69 -0
- package/template/stories/generated/rich-text.stories.ts +50 -0
- package/template/stories/generated/search.stories.ts +56 -0
- package/template/stories/generated/split-content.stories.ts +39 -0
- package/template/stories/generated/stats.stories.ts +68 -0
- package/template/stories/generated/tabs.stories.ts +45 -0
- package/template/stories/generated/team.stories.ts +45 -0
- package/template/stories/generated/testimonials.stories.ts +69 -0
- package/template/stories/generated/timeline.stories.ts +80 -0
- package/template/stories/generated/trust-strip.stories.ts +62 -0
- package/template/stories/generated/video-embed.stories.ts +63 -0
- package/template/stories/generated/wishlist.stories.ts +26 -0
- package/template/stories/pages/article.stories.ts +51 -0
- package/template/stories/pages/cart.stories.ts +56 -0
- package/template/stories/pages/category.stories.ts +56 -0
- package/template/stories/pages/collection.stories.ts +51 -0
- package/template/stories/pages/home.stories.ts +51 -0
- package/template/stories/pages/product.stories.ts +47 -0
- package/template/stories/pages/products.stories.ts +58 -0
- package/template/stories/pages/search.stories.ts +54 -0
- package/template/stories/pages/wishlist.stories.ts +53 -0
- package/template/stories/support/pageBlocks.ts +115 -0
- package/template/test/blocksEmptyData.spec.ts +52 -0
- package/template/test/carouselKeyboard.spec.ts +272 -0
- package/template/test/carouselRing.browser.spec.ts +193 -0
- package/template/test/carouselSlideWidth.browser.spec.ts +102 -0
- package/template/test/cartDrawer.spec.ts +295 -0
- package/template/test/cartToast.spec.ts +86 -0
- package/template/test/countPill.browser.spec.ts +196 -0
- package/template/test/demoImages.spec.ts +140 -0
- package/template/test/deps.spec.ts +102 -0
- package/template/test/eldraIcon.spec.ts +58 -0
- package/template/test/framing.spec.ts +76 -0
- package/template/test/i18n.spec.ts +200 -0
- package/template/test/iconComponent.spec.ts +91 -0
- package/template/test/inlineEditable.spec.ts +334 -0
- package/template/test/localePrefix.spec.ts +342 -0
- package/template/test/mainCss.spec.ts +107 -0
- package/template/test/mockGatewayContract.spec.ts +122 -0
- package/template/test/mocks/blocks.ts +20 -0
- package/template/test/mocks/breakpoints.ts +7 -0
- package/template/test/mocks/manifest.ts +11 -0
- package/template/test/moneyFormatting.spec.ts +89 -0
- package/template/test/pageTitle.spec.ts +49 -0
- package/template/test/pages/article.spec.ts +231 -0
- package/template/test/pages/category.spec.ts +185 -0
- package/template/test/pages/collection.spec.ts +396 -0
- package/template/test/pages/home.spec.ts +295 -0
- package/template/test/pages/hydration.spec.ts +557 -0
- package/template/test/pages/product.spec.ts +396 -0
- package/template/test/pages/seededPages.spec.ts +190 -0
- package/template/test/pages/ssr.spec.ts +393 -0
- package/template/test/prerenderCommerce.spec.ts +134 -0
- package/template/test/prerenderFailure.spec.ts +130 -0
- package/template/test/prerenderRefresh.browser.spec.ts +1431 -0
- package/template/test/previewsFresh.spec.ts +56 -0
- package/template/test/richText.spec.ts +161 -0
- package/template/test/richTextTypography.spec.ts +182 -0
- package/template/test/setup.ts +21 -0
- package/template/test/slugPage.spec.ts +244 -0
- package/template/test/slugPageTemplate.spec.ts +194 -0
- package/template/test/starter.spec.ts +1416 -0
- package/template/test/storefront/cart.spec.ts +404 -0
- package/template/test/storefront/categories.spec.ts +235 -0
- package/template/test/storefront/collectionSelector.spec.ts +74 -0
- package/template/test/storefront/demo.spec.ts +555 -0
- package/template/test/storefront/facets.spec.ts +425 -0
- package/template/test/storefront/feedback.spec.ts +97 -0
- package/template/test/storefront/gateway.spec.ts +2673 -0
- package/template/test/storefront/gatewayCart.spec.ts +289 -0
- package/template/test/storefront/gatewayPrerender.spec.ts +1037 -0
- package/template/test/storefront/history.spec.ts +341 -0
- package/template/test/storefront/money.spec.ts +171 -0
- package/template/test/storefront/toProductCard.spec.ts +138 -0
- package/template/test/storefront/volatile.spec.ts +284 -0
- package/template/test/support/axe.ts +14 -0
- package/template/test/support/dialog.ts +51 -0
- package/template/test/support/hydrate.ts +118 -0
- package/template/test/support/i18nText.ts +11 -0
- package/template/test/support/mockGateway.ts +1017 -0
- package/template/test/support/mountBlock.ts +194 -0
- package/template/test/support/mountPage.spec.ts +72 -0
- package/template/test/support/mountPage.ts +254 -0
- package/template/test/support/mountProbe.client.ts +69 -0
- package/template/test/support/renderSsr.ts +97 -0
- package/template/test/support/staticServer.ts +96 -0
- package/template/test/themeIcons.spec.ts +140 -0
- package/template/test/toastAnnouncement.spec.ts +133 -0
- package/template/test/tokens.spec.ts +102 -0
- package/template/test/uiMessagesPlugin.spec.ts +104 -0
- package/template/test/useBlockData.spec.ts +46 -0
- package/template/test/useEditing.spec.ts +54 -0
- package/template/test/useEldraIcon.spec.ts +126 -0
- package/template/test/useUiId.spec.ts +40 -0
- package/template/tokens.json +149 -0
- package/template/tsconfig.json +3 -0
- package/template/tsconfig.storybook.json +17 -0
- package/template/vitest-axe.d.ts +13 -0
- package/template/vitest.config.ts +44 -0
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
import { applyVolatileSnapshots, collectVolatileTargets } from './volatile';
|
|
2
|
+
import type { VolatileKey, VolatileSnapshot } from './types';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The page's one volatile refresh, as a collector.
|
|
6
|
+
*
|
|
7
|
+
* A prerendered page paints real values (`types.ts`'s `StorefrontResult` doc comment), and the
|
|
8
|
+
* only thing that can have moved since the build is money and the stock line. So after hydration
|
|
9
|
+
* every storefront result that is *about* products registers itself here, and this fires **one**
|
|
10
|
+
* batched read for the whole page rather than one read per block: a collection grid, a "you may
|
|
11
|
+
* also like" carousel and a hand-picked row of cards are three results asking about overlapping
|
|
12
|
+
* products, and three requests would be three chances to paint three different truths.
|
|
13
|
+
*
|
|
14
|
+
* Framework-free and network-free, like `volatile.ts`: it is handed the batched read
|
|
15
|
+
* (`catalog.volatileByIds`) and *when* to run it (`schedule`, called once per pending batch, with
|
|
16
|
+
* the result that opened it) — the plugin passes one that waits for the app to mount, a spec
|
|
17
|
+
* passes a no-op and calls `refresh()` itself.
|
|
18
|
+
*
|
|
19
|
+
* **A batch is every result registered before it flushes, and there can be more than one.** It
|
|
20
|
+
* cannot be one batch per *page*, and that was a real defect: a theme's blocks are lazily imported
|
|
21
|
+
* components, so on a generated page the ones whose chunk arrives after the app has mounted create
|
|
22
|
+
* their results after the first batch has already gone out. A one-shot refresher dropped them —
|
|
23
|
+
* the product page's carousel never refreshed a price and never drew the refresh treatment,
|
|
24
|
+
* because `product-detail` had opened and closed the page's only batch a tick earlier.
|
|
25
|
+
*
|
|
26
|
+
* **What is once per page load is the question, not the batch.** A second burst asking again about
|
|
27
|
+
* products the first burst has already re-read was the next defect, live: the deployed product page
|
|
28
|
+
* issued its detail read and its `id:in` batch twice, 35 ms apart, with identical ids. So this keeps
|
|
29
|
+
* a *session* — the whole page load, across every burst:
|
|
30
|
+
*
|
|
31
|
+
* - `refreshed` — every result that has already taken part. A result registered twice takes part
|
|
32
|
+
* once.
|
|
33
|
+
* - `answerFor` — the read that is answering, or has already answered, for one product id. A
|
|
34
|
+
* target in there is never asked about again; the result that shows it waits for the answer
|
|
35
|
+
* already on its way and folds in exactly the same values. That is also what makes two results
|
|
36
|
+
* needing the same detail read cost one request, and what keeps two blocks showing the same
|
|
37
|
+
* product from painting two different truths.
|
|
38
|
+
*
|
|
39
|
+
* Which results register at all is `gateway.ts`'s decision: only one holding a value the
|
|
40
|
+
* *prerender* produced, never one a client navigation has just read live.
|
|
41
|
+
* `StorefrontResult.refresh()` is a full reload and has nothing to do with any of this.
|
|
42
|
+
*/
|
|
43
|
+
|
|
44
|
+
/** What a storefront result lends the collector. Accessors rather than the refs themselves: a
|
|
45
|
+
* result owns its own `data`/`revalidating` and their types, and the collector only needs to read
|
|
46
|
+
* a value, write one back, and know whether the result has moved on since it asked. */
|
|
47
|
+
export interface VolatileRefreshEntry {
|
|
48
|
+
/** The data the page is currently showing. */
|
|
49
|
+
read(): unknown;
|
|
50
|
+
/** The same data with the fresh volatile values folded in (`applyVolatileSnapshots`). */
|
|
51
|
+
write(next: unknown): void;
|
|
52
|
+
/** `{price, stock}` while the refresh is in flight, empty once it has settled. */
|
|
53
|
+
setRevalidating(keys: ReadonlySet<VolatileKey>): void;
|
|
54
|
+
/**
|
|
55
|
+
* Changes whenever the result reloads. Captured when the refresh is issued and checked again
|
|
56
|
+
* when it answers: a result whose sources changed meanwhile has *fresher* data than the answer,
|
|
57
|
+
* so the answer is dropped rather than written over it.
|
|
58
|
+
*/
|
|
59
|
+
token(): number;
|
|
60
|
+
/**
|
|
61
|
+
* A result that cannot go through the batched read refreshes itself with this, and is passed the
|
|
62
|
+
* data it is refreshing. The product detail page is the case that exists: it needs the
|
|
63
|
+
* variant-level inventory the products list carries none of (`gateway.ts`'s `mapProductDetails`),
|
|
64
|
+
* so it re-reads the product and answers with a snapshot of its own.
|
|
65
|
+
*/
|
|
66
|
+
own?(current: unknown): Promise<VolatileSnapshot[]>;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export interface VolatileRefresher {
|
|
70
|
+
/** Joins the pending batch, opening one when there is none. */
|
|
71
|
+
register(entry: VolatileRefreshEntry): void;
|
|
72
|
+
/** Flushes the pending batch now. Nothing pending, nothing happens. */
|
|
73
|
+
refresh(): Promise<void>;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** The keys a volatile refresh is about; both move together, so there is one set, not two. */
|
|
77
|
+
const REVALIDATING: ReadonlySet<VolatileKey> = new Set<VolatileKey>(['price', 'stock']);
|
|
78
|
+
const SETTLED: ReadonlySet<VolatileKey> = new Set<VolatileKey>();
|
|
79
|
+
|
|
80
|
+
export function createVolatileRefresher(
|
|
81
|
+
volatileByIds: (ids: string[]) => Promise<VolatileSnapshot[]>,
|
|
82
|
+
schedule: (run: () => void) => void
|
|
83
|
+
): VolatileRefresher {
|
|
84
|
+
const entries: VolatileRefreshEntry[] = [];
|
|
85
|
+
/** A flush is already scheduled for the entries collected so far. */
|
|
86
|
+
let armed = false;
|
|
87
|
+
/** Every result that has taken part in a refresh this page load, however often it registered. */
|
|
88
|
+
const refreshed = new WeakSet<VolatileRefreshEntry>();
|
|
89
|
+
/**
|
|
90
|
+
* Per product id, the read that is answering — or has answered — for it, for the whole page load.
|
|
91
|
+
* Kept after it settles on purpose: a result that arrives later and shows the same product folds
|
|
92
|
+
* the same answer in instead of asking a second time, and a target whose read *failed* is not
|
|
93
|
+
* retried either (the page keeps the value it was built with, which is the same outcome).
|
|
94
|
+
*/
|
|
95
|
+
const answerFor = new Map<string, Promise<readonly VolatileSnapshot[]>>();
|
|
96
|
+
/**
|
|
97
|
+
* The same thing for results that read for themselves (`VolatileRefreshEntry.own`), kept apart
|
|
98
|
+
* from `answerFor` on purpose: the two kinds of read cannot stand in for one another. `own` exists
|
|
99
|
+
* *because* the batched read cannot answer what such a result needs — the product page's
|
|
100
|
+
* variant-level inventory, which the products list carries none of — so a batch answer folded into
|
|
101
|
+
* a detail page would leave it on the stock the page was built with, which is the whole thing the
|
|
102
|
+
* refresh is for. Two detail results over the same product still share one read, through here.
|
|
103
|
+
*
|
|
104
|
+
* (It used to need no saying: a detail product's volatile id was a *variant's*, so no list read
|
|
105
|
+
* could ever match it. Now that every row names the product it is about, they do match.)
|
|
106
|
+
*/
|
|
107
|
+
const ownAnswerFor = new Map<string, Promise<readonly VolatileSnapshot[]>>();
|
|
108
|
+
|
|
109
|
+
/** Every snapshot the reads this entry is waiting on answer with, as one list. */
|
|
110
|
+
function merged(
|
|
111
|
+
waiting: ReadonlySet<Promise<readonly VolatileSnapshot[]>>
|
|
112
|
+
): Promise<readonly VolatileSnapshot[]> {
|
|
113
|
+
const reads = [...waiting];
|
|
114
|
+
if (reads.length === 1) return reads[0]!;
|
|
115
|
+
return Promise.all(reads).then((lists) => lists.flat());
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/** Splits an entry's targets into the reads already answering for them and the ids nothing is. */
|
|
119
|
+
function claim(
|
|
120
|
+
pending: ReadonlyMap<string, Promise<readonly VolatileSnapshot[]>>,
|
|
121
|
+
targets: readonly string[]
|
|
122
|
+
): { waiting: Set<Promise<readonly VolatileSnapshot[]>>; missing: string[] } {
|
|
123
|
+
const waiting = new Set<Promise<readonly VolatileSnapshot[]>>();
|
|
124
|
+
const missing: string[] = [];
|
|
125
|
+
for (const id of targets) {
|
|
126
|
+
const answered = pending.get(id);
|
|
127
|
+
if (answered === undefined) missing.push(id);
|
|
128
|
+
else waiting.add(answered);
|
|
129
|
+
}
|
|
130
|
+
return { waiting, missing };
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* One entry's half of the refresh: mark, await, fold in, unmark. A failure is swallowed on
|
|
135
|
+
* purpose — the page already shows a value, and replacing it with an error would be a worse
|
|
136
|
+
* answer than a price that is a few minutes old.
|
|
137
|
+
*/
|
|
138
|
+
async function settle(
|
|
139
|
+
entry: VolatileRefreshEntry,
|
|
140
|
+
answer: Promise<readonly VolatileSnapshot[]>
|
|
141
|
+
): Promise<void> {
|
|
142
|
+
const token = entry.token();
|
|
143
|
+
entry.setRevalidating(REVALIDATING);
|
|
144
|
+
try {
|
|
145
|
+
const snapshots = await answer;
|
|
146
|
+
// The result reloaded while this was in flight: its data is newer than this answer.
|
|
147
|
+
if (entry.token() !== token) return;
|
|
148
|
+
entry.write(applyVolatileSnapshots(entry.read(), snapshots));
|
|
149
|
+
} catch {
|
|
150
|
+
// Keep what the page has. `revalidating` still clears below.
|
|
151
|
+
} finally {
|
|
152
|
+
if (entry.token() === token) entry.setRevalidating(SETTLED);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
async function refresh(): Promise<void> {
|
|
157
|
+
armed = false;
|
|
158
|
+
const registered = entries.splice(0);
|
|
159
|
+
if (registered.length === 0) return;
|
|
160
|
+
const ids: string[] = [];
|
|
161
|
+
const work: Array<Promise<void>> = [];
|
|
162
|
+
// This flush's batched read, promised before it is issued so the ids it will answer for can be
|
|
163
|
+
// claimed in `answerFor` as the entries are walked — a second entry in the same flush showing
|
|
164
|
+
// the same product then waits for this one read rather than adding a second.
|
|
165
|
+
let answerBatch!: (snapshots: readonly VolatileSnapshot[]) => void;
|
|
166
|
+
let failBatch!: (cause: unknown) => void;
|
|
167
|
+
const batch = new Promise<readonly VolatileSnapshot[]>((resolve, reject) => {
|
|
168
|
+
answerBatch = resolve;
|
|
169
|
+
failBatch = reject;
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
for (const entry of registered) {
|
|
173
|
+
// A result that has already taken part in this page's refresh. Registering twice is a block
|
|
174
|
+
// creating its results twice (a remount, a second render pass), not a second thing to ask.
|
|
175
|
+
if (refreshed.has(entry)) continue;
|
|
176
|
+
refreshed.add(entry);
|
|
177
|
+
// Nothing on screen to refresh — a result that answered `null`, or one whose data holds no
|
|
178
|
+
// products at all (a collection's own info, an order). Asking would be a request for
|
|
179
|
+
// nobody.
|
|
180
|
+
const targets = collectVolatileTargets(entry.read());
|
|
181
|
+
if (targets.length === 0) continue;
|
|
182
|
+
|
|
183
|
+
// A result that reads for itself asks its own question, shared only with another result that
|
|
184
|
+
// would ask exactly the same one (`ownAnswerFor`), never with the batch.
|
|
185
|
+
if (entry.own !== undefined) {
|
|
186
|
+
const { waiting, missing } = claim(ownAnswerFor, targets);
|
|
187
|
+
if (missing.length > 0) {
|
|
188
|
+
const read = Promise.resolve(entry.own(entry.read()));
|
|
189
|
+
for (const id of missing) ownAnswerFor.set(id, read);
|
|
190
|
+
waiting.add(read);
|
|
191
|
+
}
|
|
192
|
+
work.push(settle(entry, merged(waiting)));
|
|
193
|
+
continue;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
const { waiting, missing } = claim(answerFor, targets);
|
|
197
|
+
// Nothing missing: every value it shows is already being re-read, or has been. Fold that
|
|
198
|
+
// answer in rather than asking again.
|
|
199
|
+
if (missing.length > 0) {
|
|
200
|
+
for (const id of missing) answerFor.set(id, batch);
|
|
201
|
+
ids.push(...missing);
|
|
202
|
+
waiting.add(batch);
|
|
203
|
+
}
|
|
204
|
+
work.push(settle(entry, merged(waiting)));
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
// One read for every id this flush is the first to ask about, shared by every result in it.
|
|
208
|
+
if (ids.length > 0) volatileByIds(ids).then(answerBatch, failBatch);
|
|
209
|
+
else answerBatch([]);
|
|
210
|
+
await Promise.all(work);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
return {
|
|
214
|
+
register(entry) {
|
|
215
|
+
entries.push(entry);
|
|
216
|
+
if (armed) return;
|
|
217
|
+
armed = true;
|
|
218
|
+
schedule(() => void refresh());
|
|
219
|
+
},
|
|
220
|
+
refresh,
|
|
221
|
+
};
|
|
222
|
+
}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import type { ProductCardProduct } from '@eldrajs/ui';
|
|
2
|
+
import { isInternalHref, safeHref } from '../utils/links';
|
|
3
|
+
import { toMinorUnits } from './money';
|
|
4
|
+
import type { StorefrontProductListItem, StorefrontSearchProduct } from './types';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The product shapes a card can be built from: a catalogue list row, which always has a price, or a
|
|
8
|
+
* search result, whose price may be unknown (`StorefrontSearchProduct`).
|
|
9
|
+
*/
|
|
10
|
+
export type ProductCardSource = StorefrontProductListItem | StorefrontSearchProduct;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* The conversion a caller outside a component gets: no currency, so ISO 4217's default two digits —
|
|
14
|
+
* the same scale the `<ProductCard>` reading the value falls back to. Module level, so the fallback
|
|
15
|
+
* path allocates nothing per call and the case has a name.
|
|
16
|
+
*/
|
|
17
|
+
const NO_CURRENCY_MINOR_UNITS = (amount: number): number => toMinorUnits(amount, undefined);
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* `StorefrontProductListItem` → `@eldrajs/ui`'s `ProductCardProduct` — the one mapping
|
|
21
|
+
* `collection-grid`, `product-carousel` and `search` all build their cards through, so the three
|
|
22
|
+
* agree pixel for pixel — `ProductCard` is the shared cell every commerce block renders a product
|
|
23
|
+
* with, always built by `toProductCard()`.
|
|
24
|
+
*
|
|
25
|
+
* `badge` is never read off the input — `ProductCardProduct.badge` is deliberately the caller's
|
|
26
|
+
* own sale/new *decision*, not something the card re-derives, so this is the one place that
|
|
27
|
+
* decision gets made for every commerce block: `{ variant: 'sale' }` exactly when
|
|
28
|
+
* `compareAt > amount`, matching `Price`'s own sale rule verbatim. A future "New" tag (the spec's
|
|
29
|
+
* `dto_ProductListItem` carries no such flag today) is a decision for whoever adds it, not this
|
|
30
|
+
* function.
|
|
31
|
+
*
|
|
32
|
+
* **Units.** Storefront money is major units (`types.ts`) and `ProductCardProduct.price` is minor
|
|
33
|
+
* units, like every other `@eldrajs/ui` money input, so the two prices are converted on the way in.
|
|
34
|
+
* `opts.minorUnits` exists so a block can hand in the conversion already bound to the currency and
|
|
35
|
+
* locale its `<ProductCard>` will resolve (`useMoney().minor`) — which is what every block that
|
|
36
|
+
* renders a card does. The fallback converts with no currency at all, i.e. at ISO 4217's default
|
|
37
|
+
* two digits, the same scale the `<ProductCard>` reading the value falls back to; it is there for a
|
|
38
|
+
* caller outside a component (a mapping test), not for a block.
|
|
39
|
+
*
|
|
40
|
+
* `opts.revalidating` is accepted here and consumed by `toProductCardEntries()` below, the same
|
|
41
|
+
* shape `opts.ratio` has: it is a property of the *page's* refresh, not of one product, so it
|
|
42
|
+
* travels with the card data rather than being remembered separately by each of the three blocks
|
|
43
|
+
* that build cards. `ProductCardProduct` deliberately does not grow a field for it —
|
|
44
|
+
* `@eldrajs/ui` takes it as a prop on the card, beside `loading`, because it is a state the page
|
|
45
|
+
* is in, not a fact about the product.
|
|
46
|
+
*
|
|
47
|
+
* `opts.ratio` is accepted, not consumed: it exists so a caller building a grid of cards has one
|
|
48
|
+
* place to read the aspect ratio it is about to pass to `<ProductCard ratio="…">` alongside this
|
|
49
|
+
* data (`collection-grid`'s 3/4-column grid vs. `product-carousel`'s single ratio), without that
|
|
50
|
+
* choice needing to live on the card's own data. Nothing in the Northwind fixtures varies by ratio
|
|
51
|
+
* today (one `featuredImage` per product, no per-crop variants).
|
|
52
|
+
*
|
|
53
|
+
* **The trust boundary.** `item.url` is storefront-derived — it comes off a gateway response
|
|
54
|
+
* (`app/storefront/gateway.ts`) or the demo fixture, not out of the CMS — and `ProductCard`'s own
|
|
55
|
+
* `url` is required: the card always renders a link, so there is no "render the card without its
|
|
56
|
+
* link" state to fall back to. So this returns `null` for an item whose `url` is not a `safeHref`,
|
|
57
|
+
* meaning "do not render a card for this item at all", and the sanitised href is what the card
|
|
58
|
+
* carries. That is the same rule every CMS-authored href in the theme already follows
|
|
59
|
+
* (`global-constraints.md`: "every `href` passes `safeHref` and renders nothing when it returns
|
|
60
|
+
* `null`") — storefront data used to be the one class of URL that reached the DOM unchecked.
|
|
61
|
+
*
|
|
62
|
+
* Callers normally go through `toProductCardEntries()` below rather than calling this per item.
|
|
63
|
+
*/
|
|
64
|
+
export function toProductCard(
|
|
65
|
+
item: ProductCardSource,
|
|
66
|
+
opts?: ToProductCardOptions
|
|
67
|
+
): ProductCardProduct | null {
|
|
68
|
+
const url = safeHref(item.url);
|
|
69
|
+
if (url === null) return null;
|
|
70
|
+
// The second "do not render a card for this item" rule, and it exists for the same reason as the
|
|
71
|
+
// first: `ProductCardProduct.price` is required, because a commerce card without a price is not a
|
|
72
|
+
// product card, so there is no "render the card without its price" state to fall back to. A
|
|
73
|
+
// search result the storefront could not price (`StorefrontSearchProduct`) therefore gets no card
|
|
74
|
+
// — never one reading the store's own "$0.00". The suggestion panel is the other half of that
|
|
75
|
+
// decision: `SearchResultItem.price` *is* optional, so a row there keeps the product.
|
|
76
|
+
if (item.price === null) return null;
|
|
77
|
+
const minor = opts?.minorUnits ?? NO_CURRENCY_MINOR_UNITS;
|
|
78
|
+
const { amount, compareAt, from } = item.price;
|
|
79
|
+
const isSale = compareAt != null && compareAt > amount;
|
|
80
|
+
return {
|
|
81
|
+
title: item.title,
|
|
82
|
+
url,
|
|
83
|
+
featuredImage: item.featuredImage ?? null,
|
|
84
|
+
price: {
|
|
85
|
+
amount: minor(amount),
|
|
86
|
+
compareAt: compareAt == null ? compareAt : minor(compareAt),
|
|
87
|
+
from,
|
|
88
|
+
},
|
|
89
|
+
rating: item.rating,
|
|
90
|
+
colours: item.colours,
|
|
91
|
+
badge: isSale ? { variant: 'sale' } : null,
|
|
92
|
+
stock: item.stock,
|
|
93
|
+
available: item.available,
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** What a block can tell the card builder beyond the item itself. */
|
|
98
|
+
export interface ToProductCardOptions {
|
|
99
|
+
ratio?: '4x5' | '1x1' | '3x4';
|
|
100
|
+
/** Major → minor units, bound to the block's own currency/locale. Defaults to `toMinorUnits`. */
|
|
101
|
+
minorUnits?: (amount: number) => number;
|
|
102
|
+
/**
|
|
103
|
+
* The card's price and stock line are on screen but fresher ones are on their way — the
|
|
104
|
+
* prerendered page's volatile refresh (`StorefrontResult.revalidating`), or a reload of the list
|
|
105
|
+
* itself over results the visitor can still see. Surfaces as `ProductCardEntry.revalidating`,
|
|
106
|
+
* which the block binds to `<ProductCard :revalidating="…">`. Defaults to `false`.
|
|
107
|
+
*/
|
|
108
|
+
revalidating?: boolean;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/** One product's card data plus what the block needs to render its link correctly. */
|
|
112
|
+
export interface ProductCardEntry {
|
|
113
|
+
/** The storefront item, with `url` replaced by its sanitised (`safeHref`) form. */
|
|
114
|
+
item: ProductCardSource;
|
|
115
|
+
/** Ready for `<ProductCard :product="…">`. */
|
|
116
|
+
product: ProductCardProduct;
|
|
117
|
+
/** `opts.revalidating`, per card — `<ProductCard :revalidating="entry.revalidating">`. */
|
|
118
|
+
revalidating: boolean;
|
|
119
|
+
/**
|
|
120
|
+
* `true` when the destination is same-site, i.e. when the card's link should be routed by
|
|
121
|
+
* passing `app/components/EldraRouterLink.vue` as `link-as`. An off-site product URL (a gateway
|
|
122
|
+
* that returns absolute URLs, say) is a document navigation and must stay a plain `<a>` — handing
|
|
123
|
+
* `<NuxtLink>` an absolute URL asks the router to resolve a route that does not exist.
|
|
124
|
+
*/
|
|
125
|
+
internal: boolean;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* The list form every commerce block builds its card grid/row from: sanitises each item's `url`,
|
|
130
|
+
* drops the items a card cannot be built for — an unusable URL, or no price at all — and says per
|
|
131
|
+
* card whether the link routes.
|
|
132
|
+
*
|
|
133
|
+
* One function rather than a `safeHref` call in each of `collection-grid`, `product-carousel` and
|
|
134
|
+
* `search`: three blocks each deciding this for themselves is exactly the asymmetry that let
|
|
135
|
+
* storefront hrefs reach the DOM unchecked while every CMS-authored href was gated.
|
|
136
|
+
*/
|
|
137
|
+
export function toProductCardEntries(
|
|
138
|
+
items: readonly ProductCardSource[] | null | undefined,
|
|
139
|
+
opts?: ToProductCardOptions
|
|
140
|
+
): ProductCardEntry[] {
|
|
141
|
+
const entries: ProductCardEntry[] = [];
|
|
142
|
+
const revalidating = opts?.revalidating === true;
|
|
143
|
+
for (const item of items ?? []) {
|
|
144
|
+
const product = toProductCard(item, opts);
|
|
145
|
+
if (product === null) continue;
|
|
146
|
+
entries.push({
|
|
147
|
+
item: item.url === product.url ? item : { ...item, url: product.url },
|
|
148
|
+
product,
|
|
149
|
+
revalidating,
|
|
150
|
+
internal: isInternalHref(product.url),
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
return entries;
|
|
154
|
+
}
|