@eldrajs/theme-cli 0.0.0 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +69 -0
- package/LICENSE +21 -0
- package/README.md +26 -1
- 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 +50 -2
- 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,245 @@
|
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
import { flushPromises, mount, type VueWrapper } from '@vue/test-utils';
|
|
3
|
+
import { afterEach, describe, expect, it } from 'vitest';
|
|
4
|
+
import { EldraHttpError } from '@eldrajs/sdk';
|
|
5
|
+
import { useToast } from '@eldrajs/ui';
|
|
6
|
+
import { axe } from '../../../test/support/axe';
|
|
7
|
+
import Summary from '../parts/Summary.vue';
|
|
8
|
+
import { mountOptions } from '../../../test/support/mountBlock';
|
|
9
|
+
import { createDemoStorefront, DEMO_CART_LINES } from '../../../app/storefront/demo';
|
|
10
|
+
import { toStorefrontFailure } from '../../../app/storefront/feedback';
|
|
11
|
+
import { STOREFRONT_KEY, type StorefrontSource } from '../../../app/storefront/types';
|
|
12
|
+
|
|
13
|
+
/** The Northwind cart the spec's page story shows: $210.00 over three lines, over the $80
|
|
14
|
+
* free-shipping threshold, so the demo backend charges nothing for shipping. */
|
|
15
|
+
const SUBTOTAL = '$210.00';
|
|
16
|
+
|
|
17
|
+
const trackedWrappers: VueWrapper[] = [];
|
|
18
|
+
afterEach(() => {
|
|
19
|
+
for (const wrapper of trackedWrappers.splice(0)) wrapper.unmount();
|
|
20
|
+
// `useToast` is a module-level queue in `@eldrajs/ui`; the single app-wide `Toaster` renders it.
|
|
21
|
+
useToast().clear();
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
/** What the app's one `Toaster` would render for this summary's own actions. */
|
|
25
|
+
function toasts(): Array<{ title: string; variant: string }> {
|
|
26
|
+
return useToast().toasts.value.map((item) => ({ title: item.title, variant: item.variant }));
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
async function mountSummary(
|
|
30
|
+
props: Partial<{ showDiscount: boolean; showPaymentIcons: boolean; note: string }> = {}
|
|
31
|
+
): Promise<{ wrapper: VueWrapper; storefront: StorefrontSource }> {
|
|
32
|
+
const storefront = createDemoStorefront({ cartLines: DEMO_CART_LINES });
|
|
33
|
+
const base = mountOptions({ entry: { id: 'cart', data: {} } });
|
|
34
|
+
const wrapper = mount(Summary, {
|
|
35
|
+
props: { headingId: 'cart-summary-test', ...props },
|
|
36
|
+
attachTo: document.body,
|
|
37
|
+
global: {
|
|
38
|
+
...base.global,
|
|
39
|
+
provide: {
|
|
40
|
+
...base.global.provide,
|
|
41
|
+
[STOREFRONT_KEY]: storefront,
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
});
|
|
45
|
+
trackedWrappers.push(wrapper);
|
|
46
|
+
// The store loads its cart on creation (`createCartStore` → `ops.init()`), one microtask out.
|
|
47
|
+
await flushPromises();
|
|
48
|
+
return { wrapper, storefront };
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** The `<dd>` beside the `<dt>` whose text starts with `label`. */
|
|
52
|
+
function valueFor(wrapper: VueWrapper, label: string): string {
|
|
53
|
+
const terms = wrapper.findAll('dt');
|
|
54
|
+
const index = terms.findIndex((term) => term.text().startsWith(label));
|
|
55
|
+
expect(index, `no totals row labelled "${label}"`).toBeGreaterThanOrEqual(0);
|
|
56
|
+
return wrapper.findAll('dd')[index]!.text();
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
async function applyCode(wrapper: VueWrapper, code: string): Promise<void> {
|
|
60
|
+
await wrapper.get('input[name="discountCode"]').setValue(code);
|
|
61
|
+
await wrapper.get('form').trigger('submit');
|
|
62
|
+
await flushPromises();
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
describe('cart summary', () => {
|
|
66
|
+
it('is an aside labelled by its own heading, with no axe violations', async () => {
|
|
67
|
+
const { wrapper } = await mountSummary({ note: 'Taxes calculated at checkout.' });
|
|
68
|
+
const aside = wrapper.get('aside');
|
|
69
|
+
expect(aside.attributes('aria-labelledby')).toBe('cart-summary-test');
|
|
70
|
+
expect(wrapper.get('#cart-summary-test').text()).toBe('Order summary');
|
|
71
|
+
expect(wrapper.text()).toContain('Taxes calculated at checkout.');
|
|
72
|
+
expect(await axe(wrapper.element)).toHaveNoViolations();
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it('shows the store totals, with words where shipping has no amount yet', async () => {
|
|
76
|
+
const { wrapper, storefront } = await mountSummary();
|
|
77
|
+
expect(valueFor(wrapper, 'Subtotal')).toContain(SUBTOTAL);
|
|
78
|
+
expect(valueFor(wrapper, 'Shipping')).toBe('Free');
|
|
79
|
+
expect(valueFor(wrapper, 'Estimated total')).toContain(SUBTOTAL);
|
|
80
|
+
|
|
81
|
+
storefront.cart.totals.value = { ...storefront.cart.totals.value!, shipping: null };
|
|
82
|
+
await flushPromises();
|
|
83
|
+
expect(valueFor(wrapper, 'Shipping')).toBe('Calculated at checkout');
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it('links Check out to the storefront checkout URL', async () => {
|
|
87
|
+
const { wrapper, storefront } = await mountSummary();
|
|
88
|
+
const checkout = wrapper.get('a[href="/checkout/demo-cart"]');
|
|
89
|
+
expect(checkout.text()).toContain('Check out');
|
|
90
|
+
expect(storefront.cart.checkoutUrl.value).toBe('/checkout/demo-cart');
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
describe('discount code', () => {
|
|
94
|
+
it('applies a code typed in any case and reports it as a polite status with a removable chip', async () => {
|
|
95
|
+
const { wrapper } = await mountSummary();
|
|
96
|
+
await applyCode(wrapper, 'winter15');
|
|
97
|
+
|
|
98
|
+
const status = wrapper.get('[role="status"]');
|
|
99
|
+
expect(status.text()).toContain('Applied:');
|
|
100
|
+
expect(status.text()).toContain('WINTER15');
|
|
101
|
+
const remove = status.get('button');
|
|
102
|
+
expect(remove.attributes('aria-label')).toBe('Remove discount code WINTER15');
|
|
103
|
+
// The field is gone now that a code is on the cart; the chip is how it comes back off.
|
|
104
|
+
expect(wrapper.find('input[name="discountCode"]').exists()).toBe(false);
|
|
105
|
+
expect(await axe(wrapper.element)).toHaveNoViolations();
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it('adds a success-coloured discount row naming the code', async () => {
|
|
109
|
+
const { wrapper } = await mountSummary();
|
|
110
|
+
await applyCode(wrapper, 'WINTER15');
|
|
111
|
+
|
|
112
|
+
const terms = wrapper.findAll('dt');
|
|
113
|
+
const index = terms.findIndex((term) => term.text() === 'Discount (WINTER15)');
|
|
114
|
+
expect(index).toBeGreaterThanOrEqual(0);
|
|
115
|
+
const value = wrapper.findAll('dd')[index]!;
|
|
116
|
+
// 10 % of $210.00 in the demo backend, rendered by `Price` with the locale's own minus sign.
|
|
117
|
+
expect(value.text()).toContain('21.00');
|
|
118
|
+
expect(value.get('[data-part="current"]').classes()).toContain('text-success');
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it('takes the code back off the cart from the chip', async () => {
|
|
122
|
+
const { wrapper, storefront } = await mountSummary();
|
|
123
|
+
await applyCode(wrapper, 'WINTER15');
|
|
124
|
+
expect(storefront.cart.totals.value?.discount?.code).toBe('WINTER15');
|
|
125
|
+
|
|
126
|
+
await wrapper.get('[role="status"] button').trigger('click');
|
|
127
|
+
await flushPromises();
|
|
128
|
+
|
|
129
|
+
expect(storefront.cart.totals.value?.discount ?? null).toBeNull();
|
|
130
|
+
expect(wrapper.find('input[name="discountCode"]').exists()).toBe(true);
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Taking an applied code off is a cart mutation, and the chip has no field to annotate: the
|
|
135
|
+
* inline alert above belongs to the entry form, which is not even mounted while a code is
|
|
136
|
+
* applied. So a refusal here is reported the way every other cart mutation's is. Without it the
|
|
137
|
+
* shopper presses remove and the page is byte-identical to a button wired to nothing.
|
|
138
|
+
*/
|
|
139
|
+
it('reports a refused removal in a toast, keeping the chip', async () => {
|
|
140
|
+
const { wrapper, storefront } = await mountSummary();
|
|
141
|
+
await applyCode(wrapper, 'WINTER15');
|
|
142
|
+
storefront.cart.removeDiscount = async () =>
|
|
143
|
+
toStorefrontFailure(
|
|
144
|
+
new EldraHttpError({ status: 409, statusText: 'Conflict' } as Response, {
|
|
145
|
+
code: 'CONFLICT',
|
|
146
|
+
errorId: 'CART_NOT_FOUND',
|
|
147
|
+
})
|
|
148
|
+
);
|
|
149
|
+
|
|
150
|
+
await wrapper.get('[role="status"] button').trigger('click');
|
|
151
|
+
await flushPromises();
|
|
152
|
+
|
|
153
|
+
expect(toasts()).toEqual([
|
|
154
|
+
{ title: 'Your cart is out of date. Reload the page and try again.', variant: 'danger' },
|
|
155
|
+
]);
|
|
156
|
+
// The code is still on the cart, so the chip — not the entry field — is what is rendered.
|
|
157
|
+
expect(wrapper.get('[role="status"]').text()).toContain('WINTER15');
|
|
158
|
+
expect(wrapper.find('input[name="discountCode"]').exists()).toBe(false);
|
|
159
|
+
expect(await axe(wrapper.element)).toHaveNoViolations();
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
it('marks a refused code invalid and explains it in an alert linked by aria-describedby', async () => {
|
|
163
|
+
const { wrapper } = await mountSummary();
|
|
164
|
+
await applyCode(wrapper, 'WINTER51');
|
|
165
|
+
|
|
166
|
+
const input = wrapper.get('input[name="discountCode"]');
|
|
167
|
+
expect(input.attributes('aria-invalid')).toBe('true');
|
|
168
|
+
const errorId = input.attributes('aria-describedby');
|
|
169
|
+
expect(errorId).toBeTruthy();
|
|
170
|
+
const alert = wrapper.get(`#${errorId}`);
|
|
171
|
+
expect(alert.attributes('role')).toBe('alert');
|
|
172
|
+
expect(alert.text()).toBe("WINTER51 isn't a valid code. Check the spelling and try again.");
|
|
173
|
+
expect(await axe(wrapper.element)).toHaveNoViolations();
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
it('does not blame the shopper\u2019s spelling when the request itself failed', async () => {
|
|
177
|
+
const { wrapper, storefront } = await mountSummary();
|
|
178
|
+
// The cart store answers this for anything that threw on the way to the backend
|
|
179
|
+
// (`app/storefront/cart.ts`), with the underlying message left in `cart.error`.
|
|
180
|
+
storefront.cart.applyDiscount = async () => ({ ok: false, reason: 'failed' });
|
|
181
|
+
await applyCode(wrapper, 'WINTER15');
|
|
182
|
+
|
|
183
|
+
const alert = wrapper.get('[role="alert"]');
|
|
184
|
+
expect(alert.text()).toBe(
|
|
185
|
+
"We couldn't reach the store to check that code. Try again in a moment."
|
|
186
|
+
);
|
|
187
|
+
expect(alert.text()).not.toContain('spelling');
|
|
188
|
+
// The code itself was never refused, so the field is not marked invalid.
|
|
189
|
+
const input = wrapper.get('input[name="discountCode"]');
|
|
190
|
+
expect(input.attributes('aria-invalid')).toBeUndefined();
|
|
191
|
+
expect(input.attributes('aria-describedby')).toBe(alert.attributes('id'));
|
|
192
|
+
expect(await axe(wrapper.element)).toHaveNoViolations();
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
it('says so plainly when the store takes no discount codes at all', async () => {
|
|
196
|
+
const { wrapper, storefront } = await mountSummary();
|
|
197
|
+
storefront.cart.applyDiscount = async () => ({ ok: false, reason: 'unsupported' });
|
|
198
|
+
await applyCode(wrapper, 'WINTER15');
|
|
199
|
+
|
|
200
|
+
const alert = wrapper.get('[role="alert"]');
|
|
201
|
+
expect(alert.text()).toBe('Discount codes are not available in this store.');
|
|
202
|
+
expect(wrapper.get('input[name="discountCode"]').attributes('aria-invalid')).toBeUndefined();
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
it('clears the alert as soon as the code is edited', async () => {
|
|
206
|
+
const { wrapper } = await mountSummary();
|
|
207
|
+
await applyCode(wrapper, 'WINTER51');
|
|
208
|
+
expect(wrapper.find('[role="alert"]').exists()).toBe(true);
|
|
209
|
+
|
|
210
|
+
await wrapper.get('input[name="discountCode"]').setValue('WINTER5');
|
|
211
|
+
expect(wrapper.find('[role="alert"]').exists()).toBe(false);
|
|
212
|
+
expect(wrapper.get('input[name="discountCode"]').attributes('aria-invalid')).toBeUndefined();
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
it('ignores a submit with nothing typed', async () => {
|
|
216
|
+
const { wrapper, storefront } = await mountSummary();
|
|
217
|
+
await wrapper.get('form').trigger('submit');
|
|
218
|
+
await flushPromises();
|
|
219
|
+
expect(storefront.cart.totals.value?.discount ?? null).toBeNull();
|
|
220
|
+
expect(wrapper.find('[role="alert"]').exists()).toBe(false);
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
it('is absent when the field is turned off', async () => {
|
|
224
|
+
const { wrapper } = await mountSummary({ showDiscount: false });
|
|
225
|
+
expect(wrapper.find('input[name="discountCode"]').exists()).toBe(false);
|
|
226
|
+
expect(wrapper.find('form').exists()).toBe(false);
|
|
227
|
+
});
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
describe('payment icons', () => {
|
|
231
|
+
it('are one labelled image, not four named marks', async () => {
|
|
232
|
+
const { wrapper } = await mountSummary();
|
|
233
|
+
const image = wrapper.get('[role="img"]');
|
|
234
|
+
expect(image.attributes('aria-label')).toBe(
|
|
235
|
+
'We accept Visa, Mastercard, PayPal and Apple Pay'
|
|
236
|
+
);
|
|
237
|
+
expect(image.findAll('svg')).toHaveLength(4);
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
it('are absent when turned off', async () => {
|
|
241
|
+
const { wrapper } = await mountSummary({ showPaymentIcons: false });
|
|
242
|
+
expect(wrapper.find('[role="img"]').exists()).toBe(false);
|
|
243
|
+
});
|
|
244
|
+
});
|
|
245
|
+
});
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
{
|
|
2
|
+
"apiId": "cart",
|
|
3
|
+
"name": "Cart",
|
|
4
|
+
"description": "The shopper's cart as a slide-in drawer or a full page: editable line items, a free-shipping progress note, discount codes, totals and checkout.",
|
|
5
|
+
"icon": "shopping-bag",
|
|
6
|
+
"category": "commerce",
|
|
7
|
+
"version": 1,
|
|
8
|
+
"fields": [
|
|
9
|
+
{
|
|
10
|
+
"fieldId": "variant",
|
|
11
|
+
"name": "Variant",
|
|
12
|
+
"type": "select",
|
|
13
|
+
"helpText": "drawer opens from the header bag; page is the full cart page.",
|
|
14
|
+
"metadata": {
|
|
15
|
+
"options": ["drawer", "page"]
|
|
16
|
+
},
|
|
17
|
+
"validators": { "required": true }
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
"fieldId": "freeShippingThreshold",
|
|
21
|
+
"name": "Free shipping threshold",
|
|
22
|
+
"type": "string",
|
|
23
|
+
"helpText": "Major units, e.g. 80.00. Empty hides the shipping bar. Must match the backend rules."
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
"fieldId": "showDiscountField",
|
|
27
|
+
"name": "Show discount field",
|
|
28
|
+
"type": "bool",
|
|
29
|
+
"default": true,
|
|
30
|
+
"helpText": "page variant only."
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
"fieldId": "showPaymentIcons",
|
|
34
|
+
"name": "Show payment icons",
|
|
35
|
+
"type": "bool",
|
|
36
|
+
"default": true,
|
|
37
|
+
"helpText": "page variant only."
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
"fieldId": "note",
|
|
41
|
+
"name": "Note",
|
|
42
|
+
"type": "text",
|
|
43
|
+
"localized": true,
|
|
44
|
+
"helpText": "Sits under the totals, e.g. what checkout still adds."
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
"fieldId": "emptyTitle",
|
|
48
|
+
"name": "Empty title",
|
|
49
|
+
"type": "string",
|
|
50
|
+
"localized": true,
|
|
51
|
+
"helpText": "Shown with a shopping-bag icon when the cart has no items."
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
"fieldId": "emptyText",
|
|
55
|
+
"name": "Empty text",
|
|
56
|
+
"type": "text",
|
|
57
|
+
"localized": true,
|
|
58
|
+
"helpText": "One or two sentences with the next step."
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
"fieldId": "emptyLinkLabel",
|
|
62
|
+
"name": "Empty link label",
|
|
63
|
+
"type": "string",
|
|
64
|
+
"localized": true,
|
|
65
|
+
"helpText": "The empty state's primary button, e.g. Continue shopping."
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
"fieldId": "emptyLinkHref",
|
|
69
|
+
"name": "Empty link",
|
|
70
|
+
"type": "string",
|
|
71
|
+
"helpText": "Where the empty state's button goes, e.g. /collections/all."
|
|
72
|
+
}
|
|
73
|
+
]
|
|
74
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
"variant": "drawer",
|
|
3
|
+
"freeShippingThreshold": "80.00",
|
|
4
|
+
"showDiscountField": true,
|
|
5
|
+
"showPaymentIcons": true,
|
|
6
|
+
"note": "Taxes and shipping calculated at checkout.",
|
|
7
|
+
"emptyTitle": "Your cart is empty",
|
|
8
|
+
"emptyText": "Winter knitwear is back in stock, and orders over $80 ship free.",
|
|
9
|
+
"emptyLinkLabel": "Continue shopping",
|
|
10
|
+
"emptyLinkHref": "/collections/all"
|
|
11
|
+
}
|
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
/**
|
|
3
|
+
* The cart's line items: one `<ul>` labelled "Items in your cart", each row a thumbnail, the title
|
|
4
|
+
* as a routed link, the variant, the unit price ("$28.00 each" above quantity 1), the line total, a
|
|
5
|
+
* quantity stepper and a remove button (spec `02-blocks.md` "Cart" → Layout, "Line item").
|
|
6
|
+
*
|
|
7
|
+
* **One grid, two shapes, no viewport query.** Below 48rem of *container* width the row is the
|
|
8
|
+
* spec's `5rem | 1fr | auto` two-row grid (the thumbnail spanning both rows, info and line total on
|
|
9
|
+
* the first, the controls on the second); from 48rem it becomes the page's single `6rem | 1fr |
|
|
10
|
+
* 11rem | 6rem` row. The drawer never reaches that edge: `Block.vue` makes the drawer body itself
|
|
11
|
+
* the `@container` and the panel is at most 26rem wide, so the same classes resolve to the compact
|
|
12
|
+
* shape there at every viewport size — which is why this component needs no "which shell am I in"
|
|
13
|
+
* prop for its layout. The stepper and the remove button follow the same edge: the package's `sm`
|
|
14
|
+
* metrics (2rem) from 48rem, 2.75rem below it (`size-11`, the same utility the package's own
|
|
15
|
+
* `Drawer` close button uses for that edge — spec Acceptance: "Remove
|
|
16
|
+
* buttons and steppers are 2.75rem below 48rem; the sm stepper and remove button are 2rem from
|
|
17
|
+
* 48rem").
|
|
18
|
+
*
|
|
19
|
+
* **The stepper's group name.** `QuantityStepper` names its own buttons ("Decrease quantity,
|
|
20
|
+
* Speckled latte mug" — its `itemName` prop) and its input ("Quantity"), but its root is a plain
|
|
21
|
+
* `<div>`: the package draws no `role="group"` of its own. The spec asks for one named "Quantity,
|
|
22
|
+
* Speckled latte mug", so the theme wraps the stepper in that group rather than reaching into the
|
|
23
|
+
* package; the wrapper also carries the `aria-busy` the spec puts on the stepper while the backend
|
|
24
|
+
* recalculates, alongside the one on the line total.
|
|
25
|
+
*
|
|
26
|
+
* **Removal.** `cart.remove()`, then — once the list has re-rendered — focus moves to the title link
|
|
27
|
+
* of whatever line now sits at the removed row's index (the next item), or the previous one when the
|
|
28
|
+
* last row went; with nothing left, the `removing` event this emits first is what lets `Block.vue`
|
|
29
|
+
* move focus into the empty state's heading instead (spec Accessibility: "After removal, focus moves
|
|
30
|
+
* to the next item's title link, or to the empty-state heading"). Focus is looked up by the surviving line's own id rather
|
|
31
|
+
* than by row position, because the removed row is still in the DOM while its leave transition
|
|
32
|
+
* plays. The Undo toast carries a fixed id, so removing two lines in quick succession replaces the
|
|
33
|
+
* toast in place instead of stacking two — the store keeps a single `lastRemoved` slot, so only the
|
|
34
|
+
* newest removal could be undone anyway. Nothing here focuses the toast: `useToast` only queues it,
|
|
35
|
+
* and the mounted `Toaster` renders it without moving focus.
|
|
36
|
+
*
|
|
37
|
+
* A line whose product has no photo passes an empty `src`, which `UiImage` turns into `Image`'s own
|
|
38
|
+
* "No image" placeholder (spec States, "No image") rather than an `<img>` pointing at nothing; the
|
|
39
|
+
* empty `alt` keeps it decorative, since the title beside it already names the row.
|
|
40
|
+
*
|
|
41
|
+
* The leave transition is a fade rather than a height collapse: a grid row's height is `auto`, and
|
|
42
|
+
* `auto → 0` is not interpolable without inventing a literal max-height, so this animates what can
|
|
43
|
+
* be animated honestly and stays instant under reduced motion (`motion-safe:` only).
|
|
44
|
+
*/
|
|
45
|
+
import { computed, nextTick, ref } from 'vue';
|
|
46
|
+
import { Button, Link, Price, QuantityStepper, VisuallyHidden, useToast } from '@eldrajs/ui';
|
|
47
|
+
import type { StorefrontCartLine } from '../../../app/storefront/types';
|
|
48
|
+
import { useStorefront } from '../../../app/composables/useStorefront';
|
|
49
|
+
import { useStorefrontFeedback } from '../../../app/composables/useStorefrontFeedback';
|
|
50
|
+
import { useI18n } from 'vue-i18n';
|
|
51
|
+
import EldraIcon from '../../../app/components/EldraIcon.vue';
|
|
52
|
+
import EldraRouterLink from '../../../app/components/EldraRouterLink.vue';
|
|
53
|
+
import UiImage from '../../../app/components/ui/UiImage.vue';
|
|
54
|
+
import { isInternalHref, safeHref } from '../../../app/utils/links';
|
|
55
|
+
import { useMoney } from '../../../app/storefront/money';
|
|
56
|
+
|
|
57
|
+
const props = defineProps<{ lines: StorefrontCartLine[] }>();
|
|
58
|
+
|
|
59
|
+
const emit = defineEmits<{
|
|
60
|
+
/**
|
|
61
|
+
* A line is on its way out of the cart, emitted before the store is asked to remove it. The host
|
|
62
|
+
* uses it to tell an empty state caused by a removal — whose heading is then where focus belongs
|
|
63
|
+
* (spec Accessibility) — from an empty cart that simply arrived that way. It cannot be an
|
|
64
|
+
* "emptied" event after the fact: removing the last line unmounts this component with it, and
|
|
65
|
+
* Vue drops an `emit` from an unmounted instance.
|
|
66
|
+
*/
|
|
67
|
+
removing: [];
|
|
68
|
+
}>();
|
|
69
|
+
|
|
70
|
+
const { t } = useI18n();
|
|
71
|
+
/** Line money is major units (`app/storefront/types.ts`); `<Price>` reads minor. */
|
|
72
|
+
const money = useMoney();
|
|
73
|
+
const cart = useStorefront().cart;
|
|
74
|
+
const toast = useToast();
|
|
75
|
+
const feedback = useStorefrontFeedback();
|
|
76
|
+
|
|
77
|
+
const rootEl = ref<HTMLElement | null>(null);
|
|
78
|
+
|
|
79
|
+
/** One shared flag: the store reports a single `pending` for the whole cart rather than one per
|
|
80
|
+
* line, so every stepper and line total reads busy while any update is in flight. */
|
|
81
|
+
const busy = computed(() => (cart.pending.value ? 'true' : undefined));
|
|
82
|
+
|
|
83
|
+
function hrefFor(line: StorefrontCartLine): string | null {
|
|
84
|
+
return safeHref(line.url);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function linkAs(line: StorefrontCartLine): typeof EldraRouterLink | undefined {
|
|
88
|
+
const href = hrefFor(line);
|
|
89
|
+
return href !== null && isInternalHref(href) ? EldraRouterLink : undefined;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function removeLabel(line: StorefrontCartLine): string {
|
|
93
|
+
const variant = line.variantLabel.trim();
|
|
94
|
+
return variant === ''
|
|
95
|
+
? t('cart.removeItem', { title: line.title })
|
|
96
|
+
: t('cart.removeItemVariant', { title: line.title, variant });
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Every refusal is reported (`useStorefrontFeedback`), because none of these controls has anything
|
|
101
|
+
* else to show one with: the stepper springs back to the quantity the store still holds and the row
|
|
102
|
+
* stays exactly where it was, which is indistinguishable from a control that does nothing.
|
|
103
|
+
*/
|
|
104
|
+
async function onQuantity(line: StorefrontCartLine, quantity: number): Promise<void> {
|
|
105
|
+
if (quantity === line.quantity) return;
|
|
106
|
+
const failure = await cart.setQuantity(line.id, quantity);
|
|
107
|
+
if (failure !== null) feedback.report(failure, { id: 'cart-line' });
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** The first control of the row belonging to `lineId` — its title link, or whatever else that row
|
|
111
|
+
* offers should a line ever arrive without a usable URL (`Link` renders plain text without one). */
|
|
112
|
+
function focusLine(lineId: string | undefined): boolean {
|
|
113
|
+
if (lineId === undefined) return false;
|
|
114
|
+
const row = rootEl.value?.querySelector(`[data-line-id="${lineId}"]`);
|
|
115
|
+
const target = row?.querySelector<HTMLElement>('a[href], button, input');
|
|
116
|
+
if (!target) return false;
|
|
117
|
+
target.focus();
|
|
118
|
+
return true;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
async function onRemove(line: StorefrontCartLine, index: number): Promise<void> {
|
|
122
|
+
emit('removing');
|
|
123
|
+
const failure = await cart.remove(line.id);
|
|
124
|
+
if (failure !== null) {
|
|
125
|
+
feedback.report(failure, { id: 'cart-line' });
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
toast.show({
|
|
129
|
+
id: 'cart-line-removed',
|
|
130
|
+
title: t('cart.removed', { title: line.title }),
|
|
131
|
+
action: { label: t('cart.undo'), onActivate: () => void undoRemove() },
|
|
132
|
+
});
|
|
133
|
+
// What is left is read from the store, not from `lines`: that prop only catches up with the
|
|
134
|
+
// store on the host's next render, which is the render being waited for below. With nothing left
|
|
135
|
+
// there is no row to move focus to — the host's own empty state took over, and `removing` (above)
|
|
136
|
+
// is what told it to put focus in its heading.
|
|
137
|
+
const remaining = cart.lines.value;
|
|
138
|
+
await nextTick();
|
|
139
|
+
if (!focusLine(remaining[index]?.id)) focusLine(remaining[index - 1]?.id);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Undo puts the line back locally and re-adds it in the background (`app/storefront/cart.ts`), so a
|
|
144
|
+
* refusal there — the shop sold the last one in between — is the one the shopper is least likely to
|
|
145
|
+
* notice on their own: the row is already back on screen.
|
|
146
|
+
*
|
|
147
|
+
* The removal toast goes with it. It is the toast whose own button was just pressed, so it is
|
|
148
|
+
* still standing (activating an action does not dismiss it, and its timer is paused while focus is
|
|
149
|
+
* inside the stack), and its Undo now has nothing left to restore. Left beside the refusal it would
|
|
150
|
+
* show the shopper two contradictory statements about one line, and a button that does nothing.
|
|
151
|
+
*/
|
|
152
|
+
async function undoRemove(): Promise<void> {
|
|
153
|
+
const failure = await cart.undoRemove();
|
|
154
|
+
if (failure === null) return;
|
|
155
|
+
toast.dismiss('cart-line-removed');
|
|
156
|
+
feedback.report(failure, { id: 'cart-line' });
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/** Spec Layout, "Line item": the two-row compact grid, one row from 48rem of container width. */
|
|
160
|
+
const ROW_CLASS =
|
|
161
|
+
'border-border grid grid-cols-[5rem_1fr_auto] items-start gap-x-3 gap-y-4 border-b py-5 ' +
|
|
162
|
+
'last:border-b-0 @tablet:grid-cols-[6rem_1fr_11rem_6rem] @tablet:items-center @tablet:gap-x-4';
|
|
163
|
+
|
|
164
|
+
/** The compact/`sm` pair the spec's target sizes ask for, per stepper part. */
|
|
165
|
+
const STEPPER_CLASSES = {
|
|
166
|
+
decrease: '@max-tablet:size-11',
|
|
167
|
+
increase: '@max-tablet:size-11',
|
|
168
|
+
input: '@max-tablet:w-11 @max-tablet:text-stepper-value',
|
|
169
|
+
};
|
|
170
|
+
</script>
|
|
171
|
+
|
|
172
|
+
<template>
|
|
173
|
+
<ul ref="rootEl" :aria-label="t('cart.items')" class="min-w-0">
|
|
174
|
+
<TransitionGroup
|
|
175
|
+
leave-active-class="motion-safe:transition-opacity motion-safe:duration-base motion-safe:ease-out"
|
|
176
|
+
leave-to-class="motion-safe:opacity-0"
|
|
177
|
+
>
|
|
178
|
+
<li
|
|
179
|
+
v-for="(line, index) in props.lines"
|
|
180
|
+
:key="line.id"
|
|
181
|
+
:data-line-id="line.id"
|
|
182
|
+
:class="ROW_CLASS"
|
|
183
|
+
>
|
|
184
|
+
<div class="@tablet:row-span-1 col-start-1 row-span-2 row-start-1">
|
|
185
|
+
<UiImage
|
|
186
|
+
:src="line.image?.src ?? ''"
|
|
187
|
+
:alt="line.image?.alt ?? ''"
|
|
188
|
+
aspect="4/5"
|
|
189
|
+
sizes="6rem"
|
|
190
|
+
:classes="{ frame: 'rounded-md' }"
|
|
191
|
+
/>
|
|
192
|
+
</div>
|
|
193
|
+
|
|
194
|
+
<div class="col-start-2 row-start-1 grid min-w-0 gap-0.5">
|
|
195
|
+
<Link
|
|
196
|
+
v-if="hrefFor(line)"
|
|
197
|
+
:href="hrefFor(line) ?? undefined"
|
|
198
|
+
:as="linkAs(line)"
|
|
199
|
+
:underline="false"
|
|
200
|
+
class="text-text text-base font-semibold hover:underline"
|
|
201
|
+
>
|
|
202
|
+
{{ line.title }}
|
|
203
|
+
</Link>
|
|
204
|
+
<p v-else class="text-text text-base font-semibold">{{ line.title }}</p>
|
|
205
|
+
<p v-if="line.variantLabel" class="text-muted text-body-sm">{{ line.variantLabel }}</p>
|
|
206
|
+
<div v-if="line.quantity > 1" class="text-body-sm flex flex-wrap gap-x-1">
|
|
207
|
+
<Price
|
|
208
|
+
:amount="money.minor(line.unitPrice)"
|
|
209
|
+
size="sm"
|
|
210
|
+
:classes="{ root: 'inline', current: 'text-muted' }"
|
|
211
|
+
/>
|
|
212
|
+
<span class="text-muted">{{ t('cart.each') }}</span>
|
|
213
|
+
</div>
|
|
214
|
+
</div>
|
|
215
|
+
|
|
216
|
+
<div
|
|
217
|
+
class="text-text @tablet:col-start-4 col-start-3 row-start-1 justify-self-end text-base font-semibold tabular-nums"
|
|
218
|
+
:aria-busy="busy"
|
|
219
|
+
>
|
|
220
|
+
<VisuallyHidden>{{ t('cart.lineTotal') }}</VisuallyHidden>
|
|
221
|
+
<Price :amount="money.minor(line.lineTotal)" :classes="{ root: 'inline' }" />
|
|
222
|
+
</div>
|
|
223
|
+
|
|
224
|
+
<div
|
|
225
|
+
class="@tablet:col-span-1 @tablet:col-start-3 @tablet:row-start-1 @tablet:justify-self-start col-span-2 col-start-2 row-start-2 flex items-center gap-2"
|
|
226
|
+
>
|
|
227
|
+
<div
|
|
228
|
+
role="group"
|
|
229
|
+
:aria-label="t('cart.quantityFor', { title: line.title })"
|
|
230
|
+
:aria-busy="busy"
|
|
231
|
+
>
|
|
232
|
+
<QuantityStepper
|
|
233
|
+
size="sm"
|
|
234
|
+
:model-value="line.quantity"
|
|
235
|
+
:max="line.max ?? undefined"
|
|
236
|
+
:item-name="line.title"
|
|
237
|
+
:classes="STEPPER_CLASSES"
|
|
238
|
+
@change="(value: number) => void onQuantity(line, value)"
|
|
239
|
+
/>
|
|
240
|
+
</div>
|
|
241
|
+
<Button
|
|
242
|
+
icon-only
|
|
243
|
+
variant="ghost"
|
|
244
|
+
size="sm"
|
|
245
|
+
class="@max-tablet:size-11"
|
|
246
|
+
:label="removeLabel(line)"
|
|
247
|
+
@click="onRemove(line, index)"
|
|
248
|
+
>
|
|
249
|
+
<template #leadingIcon>
|
|
250
|
+
<EldraIcon name="trash" size="sm" />
|
|
251
|
+
</template>
|
|
252
|
+
</Button>
|
|
253
|
+
</div>
|
|
254
|
+
</li>
|
|
255
|
+
</TransitionGroup>
|
|
256
|
+
</ul>
|
|
257
|
+
</template>
|