@eldrajs/theme-cli 0.0.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +77 -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-DprFpjV7.js +535 -0
- package/package.json +50 -2
- package/template/.eldra/block-types.d.ts +429 -0
- package/template/.eldra/manifest.json +9378 -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 +53 -0
- package/template/.storybook/shims-vue.d.ts +10 -0
- package/template/.storybook/virtual-eldra.d.ts +32 -0
- package/template/README.md +293 -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 +248 -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 +1492 -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 +156 -0
- package/template/package.json +56 -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/apple-touch-icon.png +0 -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/public/favicon.ico +0 -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 +335 -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 +85 -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 +387 -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 +164 -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 +170 -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 +49 -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,1832 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
/**
|
|
3
|
+
* Collection grid: a collection's products as a filterable, sortable card grid — a sticky filter
|
|
4
|
+
* sidebar from 64rem of the block's own width, a filter drawer below that (and at every width in
|
|
5
|
+
* `drawer-only`) (spec `02-blocks.md` "Collection grid", 3047–3170, over the shared "Product grid"
|
|
6
|
+
* and "Progress bar" parts at 3036–3045).
|
|
7
|
+
*
|
|
8
|
+
* **Where the data comes from.** Everything a shopper sees — cards, prices, filter values, counts,
|
|
9
|
+
* the total — is `useStorefront().catalog.collectionProducts()`; the CMS fields only configure the
|
|
10
|
+
* block and carry the empty-state copy. The collection is the `collection` reference field when an
|
|
11
|
+
* author picked one, else `route.collectionHandle` (the field's own help text: "Leave empty on a
|
|
12
|
+
* collection page to use that collection"). Cards are always built by `toProductCard()`, the
|
|
13
|
+
* one mapping every commerce block shares.
|
|
14
|
+
*
|
|
15
|
+
* **Where the state goes.** Selected filters, sort, columns and page belong in the URL so results
|
|
16
|
+
* can be shared and the back button works (spec Do/Don't), but `blocks/**` may not touch a router:
|
|
17
|
+
* the block writes its state out through `route.setQuery()` — the one writer `StorefrontRoute`
|
|
18
|
+
* exposes — and the page turns that into a URL. It reads back only what that interface can give
|
|
19
|
+
* back: `route.page`, which is what makes the `pages` style's numbered links real navigation rather
|
|
20
|
+
* than component state. Filters, the price range, the sort and the column count are read back the
|
|
21
|
+
* same way — `route.filters` is the generic bag every query key but the five typed ones lands in
|
|
22
|
+
* (`QUERY_KEY` below is this block's own spelling of them) — so a shared URL restores the whole
|
|
23
|
+
* grid state and the prerendered page stays the unfiltered one.
|
|
24
|
+
*
|
|
25
|
+
* **Two requests, not one.** The grid's request is driven by the *applied* selection. The drawer's
|
|
26
|
+
* "Show N products" button needs the count for the *pending* one before it is applied — the spec is
|
|
27
|
+
* explicit both that the number is live and that nothing else on the page may change until the
|
|
28
|
+
* button is pressed (3.2.2) — so a second, `pageSize: 1` request answers only that. Its handle
|
|
29
|
+
* stays `null` until the drawer is first opened, so a page nobody filters on never makes it.
|
|
30
|
+
*
|
|
31
|
+
* **Paging.** `load-more` grows one request's window (`pageSize × pagesLoaded`) so the grid keeps
|
|
32
|
+
* every card already on screen, and hands the count, the decorative progress bar and the button to
|
|
33
|
+
* the package's `LoadMore`. `pages` renders `Pagination` over real `hrefForPage` links routed by
|
|
34
|
+
* `EldraRouterLink`, with `route.page` as the current page; its own `@container` already shows the
|
|
35
|
+
* compact form below 48rem, which is why `compact` is left at its default.
|
|
36
|
+
*
|
|
37
|
+
* The filter groups themselves — and why they are not `Accordion`/`AccordionItem` — are documented
|
|
38
|
+
* in `parts/FilterGroups.vue`.
|
|
39
|
+
*/
|
|
40
|
+
import {
|
|
41
|
+
computed,
|
|
42
|
+
defineComponent,
|
|
43
|
+
h,
|
|
44
|
+
nextTick,
|
|
45
|
+
onMounted,
|
|
46
|
+
onUnmounted,
|
|
47
|
+
ref,
|
|
48
|
+
shallowRef,
|
|
49
|
+
watch,
|
|
50
|
+
type Component,
|
|
51
|
+
type ComputedRef,
|
|
52
|
+
} from 'vue';
|
|
53
|
+
import {
|
|
54
|
+
Badge,
|
|
55
|
+
Button,
|
|
56
|
+
Container,
|
|
57
|
+
Drawer,
|
|
58
|
+
EditorPlaceholder,
|
|
59
|
+
EmptyState,
|
|
60
|
+
FieldWrapper,
|
|
61
|
+
FilterPanel,
|
|
62
|
+
LoadMore,
|
|
63
|
+
Pagination,
|
|
64
|
+
ProductCard,
|
|
65
|
+
Section,
|
|
66
|
+
Select,
|
|
67
|
+
Skeleton,
|
|
68
|
+
VisuallyHidden,
|
|
69
|
+
appliedFilters,
|
|
70
|
+
useMessages,
|
|
71
|
+
type FilterFacet,
|
|
72
|
+
type FilterFacetLayout,
|
|
73
|
+
type FilterSelection as UiFilterSelection,
|
|
74
|
+
type SelectOption,
|
|
75
|
+
} from '@eldrajs/ui';
|
|
76
|
+
import { useEldraLink } from '@eldrajs/theme-vue';
|
|
77
|
+
import { useBlockData } from '../../app/composables/useBlockData';
|
|
78
|
+
import { useEditing } from '../../app/composables/useEditing';
|
|
79
|
+
import { iconComponent } from '../../app/composables/iconComponent';
|
|
80
|
+
import { useRevalidating } from '../../app/composables/useRevalidating';
|
|
81
|
+
import { useStorefront } from '../../app/composables/useStorefront';
|
|
82
|
+
import { useI18n } from 'vue-i18n';
|
|
83
|
+
import { useUiId } from '../../app/composables/useUiId';
|
|
84
|
+
import EldraRouterLink from '../../app/components/EldraRouterLink.vue';
|
|
85
|
+
import { toProductCardEntries } from '../../app/storefront/toProductCard';
|
|
86
|
+
import { useMoney } from '../../app/storefront/money';
|
|
87
|
+
import {
|
|
88
|
+
collectionSelector,
|
|
89
|
+
selectorNeedsPublish,
|
|
90
|
+
selectorSlug,
|
|
91
|
+
} from '../../app/storefront/collectionSelector';
|
|
92
|
+
import type { StorefrontCollectionSelector } from '../../app/storefront/types';
|
|
93
|
+
import { canonicalAvailabilityValues } from '../../app/storefront/facets';
|
|
94
|
+
import { CATALOGUE_PATH } from '../../app/storefront/categories';
|
|
95
|
+
import { categoryHref, safeHref } from '../../app/utils/links';
|
|
96
|
+
import {
|
|
97
|
+
applyPanelSelection,
|
|
98
|
+
buildFilterFacets,
|
|
99
|
+
defaultPriceStep,
|
|
100
|
+
facetSourceMap,
|
|
101
|
+
FIXED_FILTER_SOURCES,
|
|
102
|
+
fitPriceStep,
|
|
103
|
+
formatPriceRange,
|
|
104
|
+
isFilterFieldSource,
|
|
105
|
+
isFilterSource,
|
|
106
|
+
optionKeyOf,
|
|
107
|
+
optionSourceFor,
|
|
108
|
+
panelSelectionFor,
|
|
109
|
+
parsePriceRange,
|
|
110
|
+
usableOptionKey,
|
|
111
|
+
priceSpanOf,
|
|
112
|
+
queryKeyFor,
|
|
113
|
+
spanWithRange,
|
|
114
|
+
toggleKeyOf,
|
|
115
|
+
toggleSourceFor,
|
|
116
|
+
widenPriceSpan,
|
|
117
|
+
type FilterFieldSource,
|
|
118
|
+
type FilterSelection,
|
|
119
|
+
type FilterSource,
|
|
120
|
+
type PriceRange,
|
|
121
|
+
type PriceSpan,
|
|
122
|
+
} from './parts/groups';
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* `Button.iconLeft`, `Select.leadingIcon` and `EmptyState.icon` each take an already-bound icon
|
|
126
|
+
* component, while `EldraIcon` needs a `name` prop bound first. The theme's shared name→component
|
|
127
|
+
* adapter (`app/composables/iconComponent.ts`) builds one and caches it per name at module scope,
|
|
128
|
+
* so a re-render never remounts (and re-fetches) it.
|
|
129
|
+
*/
|
|
130
|
+
/** The filter icon (Filter button and the no-results empty state) and the mobile sort trigger's. */
|
|
131
|
+
const AdjustmentsIcon = iconComponent('adjustments');
|
|
132
|
+
const SortIcon = iconComponent('arrows-sort');
|
|
133
|
+
/**
|
|
134
|
+
* `ProductCard` carries its own `min-w-56` so a card alone never collapses, but a grid track is
|
|
135
|
+
* the width it is: two tracks of 14rem plus a gap do not fit a phone, and the card's minimum
|
|
136
|
+
* would push the second column off the edge. The track decides the width here, as in the carousel.
|
|
137
|
+
*/
|
|
138
|
+
const CARD_CLASSES = { root: 'min-w-0' } as const;
|
|
139
|
+
/** The freshly-inserted editor hint's box icon (spec States, "Empty (freshly inserted)"). */
|
|
140
|
+
const BoxIcon = iconComponent('box');
|
|
141
|
+
|
|
142
|
+
interface SortOptionField {
|
|
143
|
+
option?: string;
|
|
144
|
+
label?: string;
|
|
145
|
+
}
|
|
146
|
+
interface FilterField {
|
|
147
|
+
source?: string;
|
|
148
|
+
label?: string;
|
|
149
|
+
collapsed?: boolean;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
const props = defineProps<{ entry: EldraBlockEntry<'collection-grid'> }>();
|
|
153
|
+
const { data } = useBlockData(props, 'collection-grid');
|
|
154
|
+
const editing = useEditing();
|
|
155
|
+
const { t } = useI18n();
|
|
156
|
+
const storefront = useStorefront();
|
|
157
|
+
const route = storefront.route;
|
|
158
|
+
|
|
159
|
+
const uid = useUiId();
|
|
160
|
+
const drawerId = `collection-grid-drawer-${uid}`;
|
|
161
|
+
/** The drawer foot's own two strings ("Clear all", "Show N products") — the panel's own copy of
|
|
162
|
+
* them is hidden now (see the drawer template below), so this block draws them itself, from the
|
|
163
|
+
* same `@eldrajs/ui` default messages `FilterPanel` would have read, rather than a second copy of
|
|
164
|
+
* the English text in this file's own locale. */
|
|
165
|
+
const filterPanelMessages = useMessages();
|
|
166
|
+
/** The grid's own visually hidden `h2` names the list of cards (spec Accessibility: "The grid has a
|
|
167
|
+
* visually hidden `h2` 'Products'"). */
|
|
168
|
+
const productsHeadingId = `collection-grid-products-${uid}`;
|
|
169
|
+
|
|
170
|
+
type Variant = 'sidebar' | 'drawer-only';
|
|
171
|
+
const variant = computed<Variant>(() =>
|
|
172
|
+
data.value.variant === 'drawer-only' ? 'drawer-only' : 'sidebar'
|
|
173
|
+
);
|
|
174
|
+
const hasSidebar = computed(() => variant.value === 'sidebar');
|
|
175
|
+
|
|
176
|
+
/** The column counts the field, the Select and a shared URL all agree on. */
|
|
177
|
+
const COLUMN_CHOICES = ['2', '3', '4'];
|
|
178
|
+
|
|
179
|
+
const columnsField = computed(() => normaliseChoice(data.value.columns, COLUMN_CHOICES, '3'));
|
|
180
|
+
const pageSize = computed(() =>
|
|
181
|
+
Number(normaliseChoice(data.value.pageSize, ['12', '24', '48'], '24'))
|
|
182
|
+
);
|
|
183
|
+
const isLoadMore = computed(
|
|
184
|
+
() =>
|
|
185
|
+
normaliseChoice(data.value.paginationStyle, ['load-more', 'pages'], 'load-more') === 'load-more'
|
|
186
|
+
);
|
|
187
|
+
const showColumnSelect = computed(() => data.value.showColumnSelect !== false);
|
|
188
|
+
|
|
189
|
+
function normaliseChoice(value: unknown, allowed: string[], fallback: string): string {
|
|
190
|
+
const raw = typeof value === 'string' ? value.trim() : '';
|
|
191
|
+
return allowed.includes(raw) ? raw : fallback;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
// ---------------------------------------------------------------------------------------------
|
|
195
|
+
// The collection
|
|
196
|
+
// ---------------------------------------------------------------------------------------------
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* **What the grid lists**: one collection (the default, and every grid this theme shipped before),
|
|
200
|
+
* the whole catalogue — the `/products` page, where the scope is the store rather than a curated
|
|
201
|
+
* list — or one **category** and everything under it, which is the `/categories/:path*` page.
|
|
202
|
+
*
|
|
203
|
+
* A block-level `select` rather than a meaning overloaded onto an empty `collection`, for the same
|
|
204
|
+
* reason `priceSlider` is one: an empty reference already means "take it from the route", which is
|
|
205
|
+
* exactly what a collection *template* relies on, so reading it as "all products" instead would turn
|
|
206
|
+
* every seeded collection page into the catalogue the moment its route stopped resolving. Adding a
|
|
207
|
+
* value to an existing `select` costs nothing either — the scanner compares type, localization and
|
|
208
|
+
* cardinality, never an enum's members — so the block stays version 3 and no author's configured
|
|
209
|
+
* filter list is retired.
|
|
210
|
+
*
|
|
211
|
+
* The two route-scoped values read the committed route and are **captured at setup**, never watched:
|
|
212
|
+
* a result is keyed by its sources' values at creation, and this block sits on pages that are not
|
|
213
|
+
* category pages, so a live source would re-key the grid onto whatever the shopper clicked towards
|
|
214
|
+
* (`StorefrontResult`'s own "sources final at setup time" rule — `breadcrumbs` captures
|
|
215
|
+
* `route.productHandle` for exactly the same reason).
|
|
216
|
+
*/
|
|
217
|
+
const catalogueScope = computed(() => data.value.scope === 'catalogue');
|
|
218
|
+
const categoryScope = computed(() => data.value.scope === 'category');
|
|
219
|
+
/** The category page's own category: the canonical path the read is scoped by, and the leaf slug
|
|
220
|
+
* the `category` filter group lists the children of. */
|
|
221
|
+
const routeCategoryPath = route.categoryPath;
|
|
222
|
+
const routeCategorySlug = route.categorySlug;
|
|
223
|
+
/** Which category the filter panel should offer the children of — `null` in every other scope, so
|
|
224
|
+
* `facetValuesFor` keeps the whole-tree family it always drew. */
|
|
225
|
+
const categoryScopeSlug = computed(() => (categoryScope.value ? routeCategorySlug : null));
|
|
226
|
+
/** Both scopes that come from the route rather than from a picked collection read the *catalogue*
|
|
227
|
+
* endpoint; only the category one narrows it. */
|
|
228
|
+
const storeWideScope = computed(() => catalogueScope.value || categoryScope.value);
|
|
229
|
+
/**
|
|
230
|
+
* The one request option a category page adds, spread into both read option objects so neither can
|
|
231
|
+
* drift: the scope's own canonical path, which narrows the catalogue read to that category's whole
|
|
232
|
+
* subtree (`StorefrontCatalog.products`). Spread rather than written as `categoryPath: … ??
|
|
233
|
+
* undefined`, so a grid in any other scope sends an options object byte-identical to the one it
|
|
234
|
+
* always sent — and therefore keys the same result the build prerendered.
|
|
235
|
+
*/
|
|
236
|
+
const categoryScopeOption = computed<{ categoryPath?: string }>(() =>
|
|
237
|
+
categoryScope.value && routeCategoryPath !== null ? { categoryPath: routeCategoryPath } : {}
|
|
238
|
+
);
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* Which collection this grid shows. `collection` is the `reference` field an
|
|
242
|
+
* author picks in Studio; it stores the collection's id, so a renamed collection
|
|
243
|
+
* cannot silently empty the block. It replaced a `collectionHandle` string field
|
|
244
|
+
* in version 3 — a handle a merchant retyped went stale the moment the
|
|
245
|
+
* collection was renamed, and the field is not read here any more even when an
|
|
246
|
+
* entry still carries the retired value (Core keeps it as `collectionHandle__v2`
|
|
247
|
+
* and nothing in this theme looks at it). `route.collectionHandle` is the
|
|
248
|
+
* collection template's own segment, the case the field is meant to be left
|
|
249
|
+
* empty for.
|
|
250
|
+
*
|
|
251
|
+
* `collectionSelector` prefers the reference's resolved `slug`, falls back to its
|
|
252
|
+
* bare id (a page builder draft overlay, or a depth-0 read — see
|
|
253
|
+
* `app/storefront/collectionSelector.ts`) and only then to the route: a picked
|
|
254
|
+
* collection overrides it, which is what its help text promises.
|
|
255
|
+
*/
|
|
256
|
+
const selected = computed<StorefrontCollectionSelector | null>(() =>
|
|
257
|
+
collectionSelector(data.value.collection, route.collectionHandle)
|
|
258
|
+
);
|
|
259
|
+
/** The handle, when the collection is known by one. `collection()` below and the
|
|
260
|
+
* `/collections/<slug>` paging links have no other key to work from; the grid
|
|
261
|
+
* itself goes through `selected`, so an id-only collection still loads. */
|
|
262
|
+
const collectionHandle = computed<string | null>(() => selectorSlug(selected.value));
|
|
263
|
+
/**
|
|
264
|
+
* **Whether this grid has a scope to read at all.** The catalogue always has one; a collection has
|
|
265
|
+
* one once a reference is picked or the route resolved a collection; a **category** has one only on
|
|
266
|
+
* a page whose route resolved a category — there is nothing to fall back to, and falling back to
|
|
267
|
+
* the catalogue would answer a category page with the whole store.
|
|
268
|
+
*/
|
|
269
|
+
const hasCollection = computed(() => {
|
|
270
|
+
if (categoryScope.value) return routeCategoryPath !== null;
|
|
271
|
+
return catalogueScope.value || selected.value !== null;
|
|
272
|
+
});
|
|
273
|
+
/** The catalogue needs nothing bound, so there is nothing to hint about; the other two each have
|
|
274
|
+
* their own thing missing, and their own sentence for it. */
|
|
275
|
+
const showNoCollectionHint = computed(
|
|
276
|
+
() => editing.value && !storeWideScope.value && !hasCollection.value
|
|
277
|
+
);
|
|
278
|
+
/** A `category` grid on a page that resolves no category: nothing to pick, so the hint says where
|
|
279
|
+
* the category comes from rather than asking for one. */
|
|
280
|
+
const showNoCategoryHint = computed(
|
|
281
|
+
() => editing.value && categoryScope.value && !hasCollection.value
|
|
282
|
+
);
|
|
283
|
+
|
|
284
|
+
/**
|
|
285
|
+
* The collection's own record, for the section label and the paging links. Never asked for in the
|
|
286
|
+
* catalogue scope — an **empty source**, not a live one, because a result's sources are part of its
|
|
287
|
+
* cache key and a key that resolves differently after hydration misses the payload the build left
|
|
288
|
+
* (`StorefrontResult`'s own rule).
|
|
289
|
+
*/
|
|
290
|
+
const collectionInfoHandle = computed(() => (storeWideScope.value ? null : collectionHandle.value));
|
|
291
|
+
const collection = storefront.catalog.collection(collectionInfoHandle);
|
|
292
|
+
const collectionTitle = computed(
|
|
293
|
+
() => collection.data.value?.title ?? collectionHandle.value ?? ''
|
|
294
|
+
);
|
|
295
|
+
/** Falls back to the plain noun when nothing names the collection yet — an
|
|
296
|
+
* id-only reference has no title and no handle to borrow one from, and an empty
|
|
297
|
+
* `{collection}` would leave the landmark named " products". */
|
|
298
|
+
const sectionLabel = computed(() =>
|
|
299
|
+
storeWideScope.value || collectionTitle.value === ''
|
|
300
|
+
? t('grid.products')
|
|
301
|
+
: t('grid.sectionLabel', { collection: collectionTitle.value })
|
|
302
|
+
);
|
|
303
|
+
|
|
304
|
+
// ---------------------------------------------------------------------------------------------
|
|
305
|
+
// Applied state (sidebar: live) and the drawer's pending copy
|
|
306
|
+
// ---------------------------------------------------------------------------------------------
|
|
307
|
+
|
|
308
|
+
/**
|
|
309
|
+
* Seeded from `route.filters`/`route.sort`/`route.columns` — "a shared URL restores the whole grid
|
|
310
|
+
* state" (spec Do/Don't). From here the block owns this state and writes every change back through
|
|
311
|
+
* `publishState()`; `adoptRouteState()` below is the other direction, for the moves the block does
|
|
312
|
+
* not make itself.
|
|
313
|
+
*/
|
|
314
|
+
/**
|
|
315
|
+
* **The author's own `filters[]` rows**, as sources this block understands — `options` included, which
|
|
316
|
+
* is the one that is not a group but a stand-in for every option key the store has. Read in several
|
|
317
|
+
* places (the groups, the chips, the query keys), and the only place the field's raw shape is
|
|
318
|
+
* validated.
|
|
319
|
+
*
|
|
320
|
+
* An explicit `option:<key>` row whose key would take a query key something else already owns is
|
|
321
|
+
* dropped here, with the same dev warning a facet-sourced one gets (`usableOptionKey`), so the
|
|
322
|
+
* collision is refused wherever it enters rather than in one of the two paths.
|
|
323
|
+
*/
|
|
324
|
+
const filterFields = computed(() =>
|
|
325
|
+
((data.value.filters ?? []) as FilterField[]).filter(
|
|
326
|
+
(row): row is FilterField & { source: FilterFieldSource } => {
|
|
327
|
+
if (!isFilterFieldSource(row.source)) return false;
|
|
328
|
+
const key = optionKeyOf(row.source);
|
|
329
|
+
return key === null || usableOptionKey(key) !== null;
|
|
330
|
+
}
|
|
331
|
+
)
|
|
332
|
+
);
|
|
333
|
+
|
|
334
|
+
/** Whether the author asked for every option key the store has (`options`). */
|
|
335
|
+
const wantsEveryOption = computed(() => filterFields.value.some((row) => row.source === 'options'));
|
|
336
|
+
|
|
337
|
+
/** The option keys the author named themselves — final at setup time, unlike everything else.
|
|
338
|
+
* `filterFields` has already dropped any that collide with a reserved query key. */
|
|
339
|
+
function explicitOptionKeys(): string[] {
|
|
340
|
+
const keys: string[] = [];
|
|
341
|
+
for (const row of filterFields.value) {
|
|
342
|
+
const key = optionKeyOf(row.source);
|
|
343
|
+
if (key !== null && !keys.includes(key)) keys.push(key);
|
|
344
|
+
}
|
|
345
|
+
return keys;
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
/**
|
|
349
|
+
* **The option keys a URL may be read through**, which is the one thing an open-ended source
|
|
350
|
+
* vocabulary costs: there is no closed list to enumerate when reading the query string.
|
|
351
|
+
*
|
|
352
|
+
* A key is readable only when the store is known to have an option for it — an explicit
|
|
353
|
+
* `option:<key>` row, or, under `options`, a key the storefront's facets actually answer. **Not any
|
|
354
|
+
* unknown query key**: `?ref=newsletter` would otherwise become `option:ref`, draw a chip and go out
|
|
355
|
+
* in the request, a filter nobody set and promised to the shopper in their own URL. And never a key
|
|
356
|
+
* another filter or the page's own route state already owns (`usableOptionKey`).
|
|
357
|
+
*
|
|
358
|
+
* The facets are only known after a read has answered, which is exactly when a query string is read
|
|
359
|
+
* anyway: the prerendered page is always the unfiltered one and `adoptRouteState()` is what picks the
|
|
360
|
+
* query up after mount (see its own comment). A key already in the selection stays readable whatever
|
|
361
|
+
* the facets say now, so a later read that cannot describe the family does not silently drop a filter
|
|
362
|
+
* the chips and the URL both show.
|
|
363
|
+
*/
|
|
364
|
+
function readableOptionKeys(selected: FilterSelection): string[] {
|
|
365
|
+
const keys = explicitOptionKeys();
|
|
366
|
+
const add = (key: string | null): void => {
|
|
367
|
+
const usable = usableOptionKey(key);
|
|
368
|
+
if (usable !== null && !keys.includes(usable)) keys.push(usable);
|
|
369
|
+
};
|
|
370
|
+
if (wantsEveryOption.value) {
|
|
371
|
+
for (const option of facets.value?.options ?? []) add(option.key);
|
|
372
|
+
for (const source of Object.keys(selected)) add(optionKeyOf(source));
|
|
373
|
+
}
|
|
374
|
+
return keys;
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
/** Every filter source a query key is read into, price excluded (it has its own two bounds). Every
|
|
378
|
+
* toggle key the store currently answers (`facets.toggles[]`) is managed the same way an option
|
|
379
|
+
* key is — there is no author-facing row for one, so there is no "explicit" half to this list. */
|
|
380
|
+
function managedSources(
|
|
381
|
+
optionKeys: readonly string[],
|
|
382
|
+
toggleKeys: readonly string[]
|
|
383
|
+
): FilterSource[] {
|
|
384
|
+
const out: FilterSource[] = FIXED_FILTER_SOURCES.filter((source) => source !== 'price');
|
|
385
|
+
for (const key of optionKeys) out.push(optionSourceFor(key));
|
|
386
|
+
for (const key of toggleKeys) out.push(toggleSourceFor(key));
|
|
387
|
+
return out;
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
function filterSelectionFromRoute(
|
|
391
|
+
optionKeys: readonly string[],
|
|
392
|
+
toggleKeys: readonly string[]
|
|
393
|
+
): FilterSelection {
|
|
394
|
+
const out: FilterSelection = {};
|
|
395
|
+
for (const source of managedSources(optionKeys, toggleKeys)) {
|
|
396
|
+
const values = route.filters[queryKeyFor(source)];
|
|
397
|
+
if (values === undefined || values.length === 0) continue;
|
|
398
|
+
// `availability` is the one source with a vocabulary of its own rather than the store's, so a
|
|
399
|
+
// spelling from a link shared before the platform's `in_stock`/`out_of_stock` landed is folded
|
|
400
|
+
// into the current one here. The block's own state then only ever holds values the panel
|
|
401
|
+
// offers: an unfolded `in-stock` ticked nothing and rendered an untranslated third checkbox
|
|
402
|
+
// (and chip) beside the two real ones. A value from no vocabulary at all is dropped — the pass
|
|
403
|
+
// ignores it too (`facets.ts`), so a chip for it would promise a filter nothing applies.
|
|
404
|
+
// A toggle is a single yes/no flag rather than a value list: any non-empty query value means
|
|
405
|
+
// on, normalised to the one marker the block's own selection holds for it (`['1']`).
|
|
406
|
+
const next =
|
|
407
|
+
source === 'availability'
|
|
408
|
+
? canonicalAvailabilityValues(values)
|
|
409
|
+
: toggleKeyOf(source) !== null
|
|
410
|
+
? ['1']
|
|
411
|
+
: [...values];
|
|
412
|
+
if (next.length > 0) out[source] = next;
|
|
413
|
+
}
|
|
414
|
+
return out;
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
/**
|
|
418
|
+
* The selection a page is **created** with: the author's own option rows and nothing else, because
|
|
419
|
+
* no read has answered yet — a toggle key is never explicit, so there is none to read at creation
|
|
420
|
+
* either. Everything else arrives through `adoptRouteState()` after mount — which is the same
|
|
421
|
+
* reason the first paint is the unfiltered collection either way.
|
|
422
|
+
*/
|
|
423
|
+
function initialFilterSelection(): FilterSelection {
|
|
424
|
+
return filterSelectionFromRoute(explicitOptionKeys(), []);
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
/** The price range the URL carries, sanitised the way a typed one is. */
|
|
428
|
+
function routePriceRange(): PriceRange {
|
|
429
|
+
return parsePriceRange(route.filters.price?.[0]);
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
const selection = ref<FilterSelection>(initialFilterSelection());
|
|
433
|
+
const initialPrice = routePriceRange();
|
|
434
|
+
const priceMin = ref(initialPrice.min);
|
|
435
|
+
const priceMax = ref(initialPrice.max);
|
|
436
|
+
|
|
437
|
+
/**
|
|
438
|
+
* The author's own sort rows this block's strings can name at all — `data.value.sortOptions` run
|
|
439
|
+
* through `SORT_LABEL`, with no regard yet for what this scope's own read can or cannot honour.
|
|
440
|
+
* `sort`'s own settling below needs exactly this, and nothing more: `data.value` is the block's own
|
|
441
|
+
* field data, so this is the same on the server's render and on whatever reads it before any
|
|
442
|
+
* network call has gone out, which is what lets `sort` reach its final value — stably, with
|
|
443
|
+
* nothing left to correct — before `products` further down even exists. (`sort` feeds
|
|
444
|
+
* `requestOptions`, one of `products`'s own reactive sources, so a `sort.value` write *after*
|
|
445
|
+
* `products` exists is a second, real request under it — seen once, the hard way: a page that
|
|
446
|
+
* should ask for its collection once asked twice, because a later correction changed the very
|
|
447
|
+
* value the first request's key was built from.) The render-facing `sortOptions`, further down,
|
|
448
|
+
* narrows this once the scope has actually answered.
|
|
449
|
+
*/
|
|
450
|
+
const configuredSortOptions = computed<SelectOption[]>(() => {
|
|
451
|
+
const SORT_LABEL: Record<string, string> = {
|
|
452
|
+
featured: t('grid.sortFeatured'),
|
|
453
|
+
'best-selling': t('grid.sortBestSelling'),
|
|
454
|
+
'price-asc': t('grid.sortPriceAsc'),
|
|
455
|
+
'price-desc': t('grid.sortPriceDesc'),
|
|
456
|
+
newest: t('grid.sortNewest'),
|
|
457
|
+
};
|
|
458
|
+
const rows = (data.value.sortOptions ?? []) as SortOptionField[];
|
|
459
|
+
return rows
|
|
460
|
+
.filter((row): row is SortOptionField & { option: string } => {
|
|
461
|
+
return typeof row.option === 'string' && row.option in SORT_LABEL;
|
|
462
|
+
})
|
|
463
|
+
.map((row) => ({
|
|
464
|
+
value: row.option,
|
|
465
|
+
label: (row.label ?? '').trim() || SORT_LABEL[row.option]!,
|
|
466
|
+
}));
|
|
467
|
+
});
|
|
468
|
+
const sort = ref(
|
|
469
|
+
route.sort !== null && configuredSortOptions.value.some((option) => option.value === route.sort)
|
|
470
|
+
? route.sort
|
|
471
|
+
: ''
|
|
472
|
+
);
|
|
473
|
+
watch(
|
|
474
|
+
configuredSortOptions,
|
|
475
|
+
(options) => {
|
|
476
|
+
if (options.length === 0) {
|
|
477
|
+
sort.value = '';
|
|
478
|
+
} else if (!options.some((option) => option.value === sort.value)) {
|
|
479
|
+
sort.value = options[0]!.value;
|
|
480
|
+
}
|
|
481
|
+
},
|
|
482
|
+
{ immediate: true }
|
|
483
|
+
);
|
|
484
|
+
|
|
485
|
+
/** The shopper's own column choice, seeded from `route.columns` (a shared URL) when it names a
|
|
486
|
+
* valid option, else the field's own default — and reset whenever the field's default changes. */
|
|
487
|
+
const columnsChoice = ref(
|
|
488
|
+
route.columns !== null && COLUMN_CHOICES.includes(route.columns)
|
|
489
|
+
? route.columns
|
|
490
|
+
: columnsField.value
|
|
491
|
+
);
|
|
492
|
+
watch(columnsField, (value) => {
|
|
493
|
+
columnsChoice.value = value;
|
|
494
|
+
});
|
|
495
|
+
const columnOptions = computed<SelectOption[]>(() =>
|
|
496
|
+
COLUMN_CHOICES.map((value) => ({ value, label: value }))
|
|
497
|
+
);
|
|
498
|
+
|
|
499
|
+
/** `load-more` grows the window rather than paging; any filter or sort change starts over. */
|
|
500
|
+
const pagesLoaded = ref(1);
|
|
501
|
+
const currentPage = computed(() => {
|
|
502
|
+
const page = Math.trunc(route.page);
|
|
503
|
+
return Number.isFinite(page) && page > 0 ? page : 1;
|
|
504
|
+
});
|
|
505
|
+
|
|
506
|
+
// ---------------------------------------------------------------------------------------------
|
|
507
|
+
// Requests
|
|
508
|
+
// ---------------------------------------------------------------------------------------------
|
|
509
|
+
|
|
510
|
+
/**
|
|
511
|
+
* `filters` as the storefront takes it: one entry per filter source with at least one value, plus
|
|
512
|
+
* the price range as a single `"<min>-<max>"` value with either end allowed to be empty ("no
|
|
513
|
+
* bound"). `undefined` rather than `{}` when nothing is selected, so an unfiltered request looks
|
|
514
|
+
* exactly like one made before any filter existed.
|
|
515
|
+
*/
|
|
516
|
+
function requestFiltersFor(
|
|
517
|
+
values: FilterSelection,
|
|
518
|
+
min: string,
|
|
519
|
+
max: string
|
|
520
|
+
): Record<string, string[]> | undefined {
|
|
521
|
+
const out: Record<string, string[]> = {};
|
|
522
|
+
for (const [source, selected] of Object.entries(values)) {
|
|
523
|
+
if (selected && selected.length > 0) out[source] = [...selected];
|
|
524
|
+
}
|
|
525
|
+
const price = formatPriceRange({ min, max });
|
|
526
|
+
if (price !== null) out.price = [price];
|
|
527
|
+
return Object.keys(out).length > 0 ? out : undefined;
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
const requestFilters = computed(() =>
|
|
531
|
+
requestFiltersFor(selection.value, priceMin.value, priceMax.value)
|
|
532
|
+
);
|
|
533
|
+
|
|
534
|
+
/**
|
|
535
|
+
* How long a sidebar filter/price change waits for a sibling change before the read it drives goes
|
|
536
|
+
* out, so three quick checkbox ticks reach the storefront as one request rather than three
|
|
537
|
+
* superseded ones. One named constant rather than a literal, so the single number that answers
|
|
538
|
+
* "how chainable does this feel" is greppable — and it is the window the drawer's own pending
|
|
539
|
+
* count waits out too.
|
|
540
|
+
*/
|
|
541
|
+
const FILTER_DEBOUNCE_MS = 350;
|
|
542
|
+
|
|
543
|
+
/**
|
|
544
|
+
* Everything the read takes, live — the page window, the sort and the filters, recomputed the
|
|
545
|
+
* instant any of them moves. Nothing reads this directly: `requestOptions` below is the copy the
|
|
546
|
+
* storefront actually sees, and the gap between the two is the debounce.
|
|
547
|
+
*/
|
|
548
|
+
const liveRequestOptions = computed(() => ({
|
|
549
|
+
page: isLoadMore.value ? 1 : currentPage.value,
|
|
550
|
+
pageSize: isLoadMore.value ? pageSize.value * pagesLoaded.value : pageSize.value,
|
|
551
|
+
sort: sort.value === '' ? undefined : sort.value,
|
|
552
|
+
filters: requestFilters.value,
|
|
553
|
+
...categoryScopeOption.value,
|
|
554
|
+
}));
|
|
555
|
+
|
|
556
|
+
/**
|
|
557
|
+
* What the storefront read is actually given: `liveRequestOptions`, mirrored the moment it changes
|
|
558
|
+
* — **unless** the sidebar has armed the window below, in which case the whole object is held back
|
|
559
|
+
* until it expires. The visible state (`selection`, the chips, the price fields, the URL) still
|
|
560
|
+
* writes at once, so nothing the shopper sees waits; only the request is held.
|
|
561
|
+
*
|
|
562
|
+
* **The whole object, not just `filters`.** A sidebar handler's own `publishState()` resets
|
|
563
|
+
* `pagesLoaded` to 1 in the same turn it changes the selection, and that is one of this object's
|
|
564
|
+
* inputs: holding `filters` alone meant a filter ticked after a Load more press fired an immediate
|
|
565
|
+
* read for the reset page window carrying the *old* filters — 24 unfiltered cards replacing the 48
|
|
566
|
+
* the shopper had loaded — and then the debounced one 350 ms later. Two requests, the first thrown
|
|
567
|
+
* away. Mirroring the whole object closes that for every input at once, including the ones that
|
|
568
|
+
* move with no handler of this block's at all (a `pages`-style page link, Back/Forward), which
|
|
569
|
+
* keep reaching the read immediately because nothing is armed when they do.
|
|
570
|
+
*
|
|
571
|
+
* `liveRequestOptions` is a computed, so its value is reference-stable until an input really
|
|
572
|
+
* changes: assigning it when nothing moved is a no-op and asks the storefront nothing.
|
|
573
|
+
*/
|
|
574
|
+
/** Whether a sidebar change is waiting out the window — the first half of `updating`. */
|
|
575
|
+
const debounceArmed = ref(false);
|
|
576
|
+
let filterDebounceTimer: ReturnType<typeof setTimeout> | null = null;
|
|
577
|
+
|
|
578
|
+
const requestOptions = shallowRef(liveRequestOptions.value);
|
|
579
|
+
watch(liveRequestOptions, (value) => {
|
|
580
|
+
if (!debounceArmed.value) requestOptions.value = value;
|
|
581
|
+
});
|
|
582
|
+
|
|
583
|
+
/**
|
|
584
|
+
* Arms the wait. Called by the sidebar's own live path (`onPanelChange`)
|
|
585
|
+
* **before** it changes anything, so the mirror above never sees a half-applied change: a trailing
|
|
586
|
+
* debounce, where each further arm restarts the window rather than queuing a second timer.
|
|
587
|
+
*/
|
|
588
|
+
function armFilterDebounce(): void {
|
|
589
|
+
debounceArmed.value = true;
|
|
590
|
+
if (filterDebounceTimer !== null) clearTimeout(filterDebounceTimer);
|
|
591
|
+
filterDebounceTimer = setTimeout(() => {
|
|
592
|
+
filterDebounceTimer = null;
|
|
593
|
+
debounceArmed.value = false;
|
|
594
|
+
requestOptions.value = liveRequestOptions.value;
|
|
595
|
+
}, FILTER_DEBOUNCE_MS);
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
/** Resolves an armed wait at once — what every immediate-apply change calls (sort, columns, Load
|
|
599
|
+
* more, the drawer's own apply, Clear all, a removed chip), so its own read carries a sidebar
|
|
600
|
+
* change that was still waiting rather than leaving it stranded for another `FILTER_DEBOUNCE_MS`.
|
|
601
|
+
* A no-op when nothing was armed and nothing has changed.
|
|
602
|
+
*
|
|
603
|
+
* **Call it after the handler's own change to a request input, never before.** The assignment is
|
|
604
|
+
* synchronous, so it queues the result's watcher at that point; a request input moved afterwards
|
|
605
|
+
* queues the mirror's watcher behind it, and the read goes out twice in the same tick — once on
|
|
606
|
+
* the half-applied value and once on the final one. Every handler below mutates first for exactly
|
|
607
|
+
* this reason. */
|
|
608
|
+
function flushFilterDebounce(): void {
|
|
609
|
+
if (filterDebounceTimer !== null) {
|
|
610
|
+
clearTimeout(filterDebounceTimer);
|
|
611
|
+
filterDebounceTimer = null;
|
|
612
|
+
}
|
|
613
|
+
debounceArmed.value = false;
|
|
614
|
+
requestOptions.value = liveRequestOptions.value;
|
|
615
|
+
}
|
|
616
|
+
/**
|
|
617
|
+
* The grid's own read, from whichever scope the block is in. Both answer the same
|
|
618
|
+
* `StorefrontCollectionProducts`, so everything below this line — the cards, the count, the facets, the
|
|
619
|
+
* chips, the paging — is written once (`StorefrontCatalog.products`).
|
|
620
|
+
*
|
|
621
|
+
* Which one is **decided at setup and never changes**: `scope` is a field, so a result created under
|
|
622
|
+
* one scope is never re-pointed at the other, and the unused scope's read is never created at all.
|
|
623
|
+
*/
|
|
624
|
+
const products = storeWideScope.value
|
|
625
|
+
? storefront.catalog.products(requestOptions)
|
|
626
|
+
: storefront.catalog.collectionProducts(selected, requestOptions);
|
|
627
|
+
|
|
628
|
+
const items = computed(() => products.data.value?.items ?? []);
|
|
629
|
+
const money = useMoney();
|
|
630
|
+
const total = computed(() => products.data.value?.total ?? 0);
|
|
631
|
+
/** The storefront's own description of the scope it answered from — values, labels, swatches and
|
|
632
|
+
* counts for every group (`CatalogFacets`). `undefined` from a source that cannot describe it. */
|
|
633
|
+
const facets = computed(() => products.data.value?.facets);
|
|
634
|
+
/**
|
|
635
|
+
* The filter sources **this scope** cannot narrow by, as the storefront declares them
|
|
636
|
+
* (`StorefrontCollectionProducts.unfilterable`) — the platform can count the other collections a
|
|
637
|
+
* collection's products are in without being able to ask for the intersection, so a group fed by
|
|
638
|
+
* real counts can still be a filter that does nothing.
|
|
639
|
+
*
|
|
640
|
+
* Their groups and their chips are both dropped below. Nothing is removed from the request or from
|
|
641
|
+
* the query string: the source may be perfectly filterable in another scope, so a shared link stays
|
|
642
|
+
* meaningful, and the storefront that declared it unfilterable is already the one ignoring it.
|
|
643
|
+
*/
|
|
644
|
+
const unfilterableSources = computed(() => new Set(products.data.value?.unfilterable ?? []));
|
|
645
|
+
/**
|
|
646
|
+
* `configuredSortOptions`, minus whichever of them this scope just declared it cannot honour
|
|
647
|
+
* (`StorefrontCollectionProducts.unsortable`) — the platform gateway reads no sales data to order
|
|
648
|
+
* by, on either of its two scopes, so a shopper picking `best-selling` there would see nothing move
|
|
649
|
+
* and the control would look broken. A plain `computed` reading `products.data.value` straight
|
|
650
|
+
* through, same as `unfilterableSources` above: both sides of a hydration read the *same*,
|
|
651
|
+
* already-settled answer at render time (the "one synchronous turn" the server's render and the
|
|
652
|
+
* client's hydration of it share), so this never disagrees with what either one painted. The demo
|
|
653
|
+
* storefront declares nothing, so Storybook and the sample pages keep every option. This is what
|
|
654
|
+
* the template's own `:options` binds to — `sort`'s own settling above never reads it.
|
|
655
|
+
*/
|
|
656
|
+
const sortOptions = computed<SelectOption[]>(() => {
|
|
657
|
+
const unsortable = products.data.value?.unsortable;
|
|
658
|
+
if (unsortable === undefined) return configuredSortOptions.value;
|
|
659
|
+
return configuredSortOptions.value.filter((option) => !unsortable.includes(option.value));
|
|
660
|
+
});
|
|
661
|
+
/**
|
|
662
|
+
* The one correction `configuredSortOptions`'s own settling above could not make, because it
|
|
663
|
+
* cannot know the answer yet: a `sort` already pointed at an id this scope just declared
|
|
664
|
+
* `unsortable` — a URL carrying `?sort=best-selling`, say — falls back here to the first option
|
|
665
|
+
* still offered, the same way an id this grid never configured at all already does. `immediate`,
|
|
666
|
+
* so this is this watch's *own* first, synchronous run (not a later re-trigger of some earlier
|
|
667
|
+
* one), settled the moment `products.data.value` is — which keeps it a no-op, writing nothing and
|
|
668
|
+
* asking nothing again, for every page whose `sort` was never pointed at the one id this matters
|
|
669
|
+
* for in the first place.
|
|
670
|
+
*/
|
|
671
|
+
watch(
|
|
672
|
+
sortOptions,
|
|
673
|
+
(options) => {
|
|
674
|
+
if (options.some((option) => option.value === sort.value)) return;
|
|
675
|
+
// Nothing left to offer — an author who configured only ids this scope declares unsortable.
|
|
676
|
+
// The control is already hidden (`hasSort`), so the only thing left to get right is the
|
|
677
|
+
// request: clear it rather than keep sending an id the same answer just said cannot be
|
|
678
|
+
// honoured. The configured-list watch above settles its own empty case exactly this way.
|
|
679
|
+
sort.value = options.length > 0 ? options[0]!.value : '';
|
|
680
|
+
},
|
|
681
|
+
{ immediate: true }
|
|
682
|
+
);
|
|
683
|
+
const pending = products.pending;
|
|
684
|
+
|
|
685
|
+
/** A collection the storefront could only have found by id, and did not — a
|
|
686
|
+
* picked collection whose draft overlay carries no `slug` yet (`null` data,
|
|
687
|
+
* rather than a real response with no matching products). In the editor say why
|
|
688
|
+
* rather than show an empty grid, since publishing is what fixes it; a live
|
|
689
|
+
* visitor gets the block's own empty state as always. */
|
|
690
|
+
const showUnresolvedCollectionHint = computed(
|
|
691
|
+
() =>
|
|
692
|
+
editing.value &&
|
|
693
|
+
selectorNeedsPublish(selected.value) &&
|
|
694
|
+
!pending.value &&
|
|
695
|
+
products.data.value === null
|
|
696
|
+
);
|
|
697
|
+
|
|
698
|
+
/**
|
|
699
|
+
* Loading a *further* page is not the same state as filtering, and neither of them is the same as
|
|
700
|
+
* having nothing at all. **The prerender contract** (`app/storefront/types.ts`) splits the three:
|
|
701
|
+
*
|
|
702
|
+
* - `showSkeletons` — `pending && no data`: the first load of a grid with nothing on screen yet.
|
|
703
|
+
* Both halves are stated rather than trusting `pending` to imply the second, because a skeleton
|
|
704
|
+
* drawn over results the visitor can already see is precisely the flash this work removed.
|
|
705
|
+
* - `updating` — a sidebar change waiting out its debounce, or the read it drives already in
|
|
706
|
+
* flight (`refreshing`) — over results that *are* on screen: a filter, a sort, a page. The old
|
|
707
|
+
* cards stay exactly where they are and the list pulses between 0.7 and 0.9 opacity, the grid is
|
|
708
|
+
* marked `aria-busy`, and the count reads "Updating…". This is what used to replace the whole
|
|
709
|
+
* grid with skeletons.
|
|
710
|
+
* - `loadingMore` — Load more, where "focus stays on the button" (spec Accessibility): every card
|
|
711
|
+
* stays put, undimmed, the count stays real, and only the button is busy (`LoadMore`'s own
|
|
712
|
+
* `pending`). It latches on the press and clears when the read answers — off `loading`, not
|
|
713
|
+
* `pending`, which no longer rises for a read over data the grid already has and would leave the
|
|
714
|
+
* button spinning for the life of the page.
|
|
715
|
+
*/
|
|
716
|
+
const loading = products.loading;
|
|
717
|
+
const hasData = computed(() => products.data.value !== null);
|
|
718
|
+
const loadingMore = ref(false);
|
|
719
|
+
watch(loading, (value) => {
|
|
720
|
+
if (!value) loadingMore.value = false;
|
|
721
|
+
});
|
|
722
|
+
const showSkeletons = computed(() => pending.value && !hasData.value);
|
|
723
|
+
|
|
724
|
+
/**
|
|
725
|
+
* Both "a fresher value is on its way" states, gated identically: the volatile refresh (money and
|
|
726
|
+
* the stock line, re-read a moment after mount) and a whole read in flight over cards already on
|
|
727
|
+
* screen. `useRevalidating` holds both at `false` until after mount, so the browser's first render
|
|
728
|
+
* is the server's — a hydrating page's result is already `loading` with its payload data in
|
|
729
|
+
* place, and reading either flag straight through would paint `aria-busy`, "Updating…" and dimmed
|
|
730
|
+
* cards the server never wrote.
|
|
731
|
+
*/
|
|
732
|
+
const { any: cardsRevalidating, refreshing } = useRevalidating({
|
|
733
|
+
keys: () => products.revalidating.value,
|
|
734
|
+
refreshing: () => loading.value && hasData.value && !loadingMore.value,
|
|
735
|
+
});
|
|
736
|
+
/**
|
|
737
|
+
* The grid's own "this is about to change" flag: armed the moment a sidebar change is typed or
|
|
738
|
+
* ticked, not only once the debounced read actually goes out — the shopper sees the list is about
|
|
739
|
+
* to move as soon as they touch a control, which is the whole point of showing *something* before
|
|
740
|
+
* the request exists at all. `debounceArmed` is written only by sidebar handlers and is therefore never true
|
|
741
|
+
* during a server render or a hydrating client's first paint, the same way `refreshing` never is.
|
|
742
|
+
*
|
|
743
|
+
* What it draws, and the rules that follow from it:
|
|
744
|
+
*
|
|
745
|
+
* - The card list itself pulses (`UPDATING_PULSE` below) — nothing is drawn **over** it, nothing
|
|
746
|
+
* is added to the DOM, and nothing moves. The sidebar, the chips, the toolbar and the count are
|
|
747
|
+
* outside it and stay at full strength: chaining filter changes is the entire point of the
|
|
748
|
+
* debounce, so the panel has to stay operable and legible while the list is on its way.
|
|
749
|
+
* - The list is marked busy and takes `inert`, so no card can be reached or clicked mid-update,
|
|
750
|
+
* and the count line — a `role="status"` — is what says "Updating…" in words. There is nothing
|
|
751
|
+
* to hide from assistive technology, because there is no extra element at all.
|
|
752
|
+
*/
|
|
753
|
+
const updating = computed(() => debounceArmed.value || refreshing.value);
|
|
754
|
+
|
|
755
|
+
/**
|
|
756
|
+
* The grid's own "a fresher result is on its way" treatment: its opacity eases between 0.7 and
|
|
757
|
+
* 0.9 and back, continuously, for as long as `updating` holds. Declared in
|
|
758
|
+
* `app/assets/main.css` (`eldra-pulse-soft`) beside the theme's other custom utilities rather
|
|
759
|
+
* than inline, so a customer restyles or removes it in one place.
|
|
760
|
+
*
|
|
761
|
+
* Under `prefers-reduced-motion: reduce` the animation is off and the list holds a steady 0.8
|
|
762
|
+
* instead — still visibly waiting, with nothing moving. The pair is written as one constant
|
|
763
|
+
* because Tailwind scans source text for class names: every class here has to appear literally
|
|
764
|
+
* somewhere in this file for the build to emit it.
|
|
765
|
+
*/
|
|
766
|
+
const UPDATING_PULSE =
|
|
767
|
+
'animate-eldra-pulse-soft motion-reduce:animate-none motion-reduce:opacity-80';
|
|
768
|
+
|
|
769
|
+
/**
|
|
770
|
+
* **One visible "this is stale" treatment at a time, never two.** `cardsRevalidating` folds the
|
|
771
|
+
* whole-read `refreshing` *into* its own per-card signal (see `useRevalidating`'s own doc), which
|
|
772
|
+
* is exactly what used to put the dimmed-value-and-spinner treatment on every card during a
|
|
773
|
+
* filter/sort/page read. The grid's own pulse (`updating`, `UPDATING_PULSE`) is the one indicator
|
|
774
|
+
* for that now — dimming every card's two values underneath a pulsing list would double up the
|
|
775
|
+
* same message, and the two dims would multiply — so this masks `cardsRevalidating` back down to
|
|
776
|
+
* the volatile refresh alone (money and the stock line, re-read a moment after mount) whenever
|
|
777
|
+
* `updating` is already showing something. The volatile refresh has nothing to do with `updating`
|
|
778
|
+
* and keeps its own treatment either way.
|
|
779
|
+
*/
|
|
780
|
+
const showCardRefresh = computed(() => !updating.value && cardsRevalidating.value);
|
|
781
|
+
/**
|
|
782
|
+
* The volatile refresh, said once for the whole grid. Each card dims its two values and draws a
|
|
783
|
+
* spinner beside them but passes `announce: false` — a 24-card grid would otherwise hold 48 polite
|
|
784
|
+
* live regions all speaking at once (`@eldrajs/ui`'s `announce` prop) — so this one region is what
|
|
785
|
+
* speaks. The whole-read state has its own words in `countText`, which is why `showCardRefresh`
|
|
786
|
+
* and not `updating` is the condition here.
|
|
787
|
+
*/
|
|
788
|
+
const announcement = computed(() => (showCardRefresh.value ? t('storefront.updatingValues') : ''));
|
|
789
|
+
|
|
790
|
+
/**
|
|
791
|
+
* The cards actually rendered. `toProductCardEntries` (`app/storefront/toProductCard.ts`) is the
|
|
792
|
+
* one place a storefront-derived URL is sanitised: it drops an item whose `url` is not a
|
|
793
|
+
* `safeHref` — `ProductCard`'s link is required, so a linkless card does not exist — and reports
|
|
794
|
+
* per card whether the destination routes (`entry.internal`). `items` stays the raw response for
|
|
795
|
+
* the skeleton count and the "shown N of total" line, which are about the request, not the DOM.
|
|
796
|
+
*/
|
|
797
|
+
const cards = computed(() =>
|
|
798
|
+
toProductCardEntries(items.value, {
|
|
799
|
+
ratio: '4x5',
|
|
800
|
+
minorUnits: money.minor,
|
|
801
|
+
revalidating: showCardRefresh.value,
|
|
802
|
+
})
|
|
803
|
+
);
|
|
804
|
+
|
|
805
|
+
/** The count of skeleton cards: "the grid shows the same number of Skeleton cards" (spec States →
|
|
806
|
+
* Loading), which on the very first load — nothing on screen yet — is the page size. */
|
|
807
|
+
const lastItemCount = ref(0);
|
|
808
|
+
watch(
|
|
809
|
+
items,
|
|
810
|
+
(value) => {
|
|
811
|
+
if (value.length > 0) lastItemCount.value = value.length;
|
|
812
|
+
},
|
|
813
|
+
{ immediate: true }
|
|
814
|
+
);
|
|
815
|
+
const skeletonCount = computed(() =>
|
|
816
|
+
lastItemCount.value > 0 ? lastItemCount.value : pageSize.value
|
|
817
|
+
);
|
|
818
|
+
|
|
819
|
+
// ---------------------------------------------------------------------------------------------
|
|
820
|
+
// Filter groups
|
|
821
|
+
// ---------------------------------------------------------------------------------------------
|
|
822
|
+
|
|
823
|
+
/**
|
|
824
|
+
* A facet's title and hidden `<legend>` — one string, now that `FilterFacet.label` is both (the
|
|
825
|
+
* package draws no separate hidden legend any more).
|
|
826
|
+
*
|
|
827
|
+
* The four fixed sources are the theme's own words. An option's is **the store's**: the facet's own
|
|
828
|
+
* `name` for that key, which is the only place a merchant's "Fabric" exists — with the two keys this
|
|
829
|
+
* theme does have strings for (`size`, `colour`) still preferred, so a store using the ordinary keys
|
|
830
|
+
* reads a translated facet title rather than a raw store string, and so the Icelandic site says
|
|
831
|
+
* "Stærð". A key with no facet name and no string of this theme's falls back to the key itself, which
|
|
832
|
+
* is at least the merchant's own word. A toggle source never reaches here — it is folded into the
|
|
833
|
+
* `availability` facet, which keeps its own label.
|
|
834
|
+
*/
|
|
835
|
+
function defaultFacetLabel(source: FilterSource): string {
|
|
836
|
+
if (source === 'price') return t('grid.price');
|
|
837
|
+
if (source === 'category') return t('grid.legendCategory');
|
|
838
|
+
if (source === 'collection') return t('grid.legendCollection');
|
|
839
|
+
if (source === 'availability') return t('grid.legendAvailability');
|
|
840
|
+
const key = optionKeyOf(source);
|
|
841
|
+
if (key === 'size') return t('grid.legendSize');
|
|
842
|
+
if (key === 'colour') return t('grid.legendColour');
|
|
843
|
+
return optionNames.value.get(key ?? '') ?? key ?? source;
|
|
844
|
+
}
|
|
845
|
+
|
|
846
|
+
/** Each option key's own display name, as the storefront's facets report it. */
|
|
847
|
+
const optionNames = computed(
|
|
848
|
+
() => new Map((facets.value?.options ?? []).map((option) => [option.key, option.name] as const))
|
|
849
|
+
);
|
|
850
|
+
|
|
851
|
+
/** The combined `availability` facet's own values' names: the facets carry counts, never labels —
|
|
852
|
+
* "In stock only" is the one switch row the theme names itself (spec → Variants, `toggle` facet). */
|
|
853
|
+
const availabilityLabels = computed(() => ({
|
|
854
|
+
inStock: t('grid.availabilityInStock'),
|
|
855
|
+
outOfStock: t('grid.availabilityOutOfStock'),
|
|
856
|
+
}));
|
|
857
|
+
|
|
858
|
+
/** The destination of the Size facet's "Size guide" link, resolved from the block's own `link`
|
|
859
|
+
* field through the theme's link resolver — a plain URL, or `undefined` with nothing to link to. */
|
|
860
|
+
const resolveLink = useEldraLink();
|
|
861
|
+
const sizeGuideLink = computed(() => resolveLink(data.value.sizeGuideHref));
|
|
862
|
+
const sizeGuideHref = computed(() => safeHref(sizeGuideLink.value?.href) ?? undefined);
|
|
863
|
+
|
|
864
|
+
/** The Colour facet's own layout: swatch rows (the default) or a swatch grid — the block's
|
|
865
|
+
* `colourLayout` field, top-level per the component's own storage rule (a child under an existing
|
|
866
|
+
* `filters[]` item would force a version bump that retires every author's configured list). */
|
|
867
|
+
const colourLayout = computed<FilterFacetLayout>(() =>
|
|
868
|
+
data.value.colourLayout === 'grid' ? 'grid' : 'list'
|
|
869
|
+
);
|
|
870
|
+
|
|
871
|
+
/**
|
|
872
|
+
* The span the price control works across: **the catalogue's own bounds**, from the facets (spec:
|
|
873
|
+
* "not 0 and a round number"), which are counted with every filter *except* price applied and so
|
|
874
|
+
* stay still while the shopper drags.
|
|
875
|
+
*
|
|
876
|
+
* The fallback, for a storefront that answers no facets, is the span of the loaded products — and
|
|
877
|
+
* that one does move, because narrowing the price narrows the products. `widenPriceSpan` keeps the
|
|
878
|
+
* widest span seen for this collection, so the track cannot ratchet shut around the thumbs; it is
|
|
879
|
+
* dropped when the collection changes, since the next one's prices are its own.
|
|
880
|
+
*/
|
|
881
|
+
const facetPriceSpan = computed<PriceSpan | null>(() => facets.value?.price ?? null);
|
|
882
|
+
const loadedPriceSpan = ref<PriceSpan | null>(null);
|
|
883
|
+
// `immediate`, because the facets can arrive *with* the products and already have no span of their
|
|
884
|
+
// own: the platform omits `price` when the scope minus the price filter holds nothing, and a
|
|
885
|
+
// prerendered page hands this block its answer before the first render. Waiting for a change left
|
|
886
|
+
// the fallback unset and the control spanning 0 to 0.
|
|
887
|
+
watch(
|
|
888
|
+
[facetPriceSpan, items],
|
|
889
|
+
([facet, loaded]) => {
|
|
890
|
+
if (facet !== null) {
|
|
891
|
+
loadedPriceSpan.value = null;
|
|
892
|
+
return;
|
|
893
|
+
}
|
|
894
|
+
loadedPriceSpan.value = widenPriceSpan(loadedPriceSpan.value, priceSpanOf(loaded));
|
|
895
|
+
},
|
|
896
|
+
{ immediate: true }
|
|
897
|
+
);
|
|
898
|
+
watch(selected, () => {
|
|
899
|
+
loadedPriceSpan.value = null;
|
|
900
|
+
});
|
|
901
|
+
const EMPTY_SPAN: PriceSpan = { min: 0, max: 0 };
|
|
902
|
+
const priceSpan = computed<PriceSpan>(() =>
|
|
903
|
+
spanWithRange(facetPriceSpan.value ?? loadedPriceSpan.value ?? EMPTY_SPAN, {
|
|
904
|
+
min: priceMin.value,
|
|
905
|
+
max: priceMax.value,
|
|
906
|
+
})
|
|
907
|
+
);
|
|
908
|
+
|
|
909
|
+
/**
|
|
910
|
+
* The price slider's step: the author's `priceStep`, else one unit of the store currency (ISK 100,
|
|
911
|
+
* USD 1 — `defaultPriceStep`), narrowed to a step this catalogue's own span can actually hold
|
|
912
|
+
* (`fitPriceStep`). A non-positive or non-integer field value is no step at all, so it falls back
|
|
913
|
+
* rather than handing the slider a grid it cannot land on.
|
|
914
|
+
*/
|
|
915
|
+
/**
|
|
916
|
+
* The price group's control: the range slider (the default), or its two typed fields alone — what
|
|
917
|
+
* a store whose prices sit in a few tight clusters a track cannot separate sets.
|
|
918
|
+
*
|
|
919
|
+
* A block-level field rather than one on the `filters[]` row it describes, even though it is about
|
|
920
|
+
* the price group: a new child under an existing list item is a storage-shape change to the
|
|
921
|
+
* scanner (`storageCompatible` compares a list item's children by count and id, so it cannot tell
|
|
922
|
+
* an addition from a replacement), and the version bump it demands makes Core retire every
|
|
923
|
+
* author's configured `filters` list. A top-level addition costs nothing — and there is one price
|
|
924
|
+
* group at most, so the two shapes say the same thing.
|
|
925
|
+
*/
|
|
926
|
+
const priceSlider = computed(() => data.value.priceSlider !== false);
|
|
927
|
+
|
|
928
|
+
const priceStep = computed(() => {
|
|
929
|
+
const own = data.value.priceStep;
|
|
930
|
+
if (typeof own === 'number' && Number.isFinite(own) && own > 0) return own;
|
|
931
|
+
return fitPriceStep(defaultPriceStep(money.currency.value), priceSpan.value);
|
|
932
|
+
});
|
|
933
|
+
|
|
934
|
+
/**
|
|
935
|
+
* **The author's rows expanded into rendered sources**, which is the whole of what `options` means: in
|
|
936
|
+
* its place, one `option:<key>` row per option key the storefront's facets answer, in the facets'
|
|
937
|
+
* order, carrying no label of its own (the group then takes the store's own name for that key).
|
|
938
|
+
*
|
|
939
|
+
* A key an explicit `option:<key>` row already names is **not** expanded again: that row wins, wherever
|
|
940
|
+
* the author put it and whatever they called it. So "Size first, then whatever else this store sells
|
|
941
|
+
* by" is two rows, and the common case — "every option, in the store's order" — is one.
|
|
942
|
+
*/
|
|
943
|
+
const expandedFilterRows = computed<Array<FilterField & { source: FilterSource }>>(() => {
|
|
944
|
+
const explicitKeys = new Set(
|
|
945
|
+
filterFields.value.map((row) => optionKeyOf(row.source)).filter((key) => key !== null)
|
|
946
|
+
);
|
|
947
|
+
const out: Array<FilterField & { source: FilterSource }> = [];
|
|
948
|
+
for (const row of filterFields.value) {
|
|
949
|
+
if (row.source !== 'options') {
|
|
950
|
+
out.push({ ...row, source: row.source });
|
|
951
|
+
continue;
|
|
952
|
+
}
|
|
953
|
+
// The facets' own keys, in the facets' order — plus any key the shopper already has a filter on
|
|
954
|
+
// that the facets have stopped naming. That second half is the standing rule that a group
|
|
955
|
+
// carrying a selection is never dropped out from under an applied filter: facets are computed
|
|
956
|
+
// over the current result set on most backends, so a narrowing filter can remove the very family
|
|
957
|
+
// it was set in, and a group that vanished would leave the shopper no control to undo it.
|
|
958
|
+
for (const key of [
|
|
959
|
+
...(facets.value?.options ?? []).map((option) => option.key),
|
|
960
|
+
...Object.keys(selection.value).map(optionKeyOf),
|
|
961
|
+
]
|
|
962
|
+
.map(usableOptionKey)
|
|
963
|
+
.filter((key): key is string => key !== null)) {
|
|
964
|
+
if (explicitKeys.has(key) || out.some((done) => done.source === optionSourceFor(key))) {
|
|
965
|
+
continue;
|
|
966
|
+
}
|
|
967
|
+
out.push({ ...row, label: undefined, source: optionSourceFor(key) });
|
|
968
|
+
}
|
|
969
|
+
}
|
|
970
|
+
return out;
|
|
971
|
+
});
|
|
972
|
+
|
|
973
|
+
/**
|
|
974
|
+
* **The one call into the adapter.** `buildFilterFacets` (`parts/groups.ts`) turns the author's
|
|
975
|
+
* expanded rows and the storefront's facets into the `FilterFacet[]` `FilterPanel` draws — a source
|
|
976
|
+
* this scope cannot narrow by, or one with nothing to offer, is dropped there, same as it always
|
|
977
|
+
* was. A range with fewer than two distinct values is still included: the package's own
|
|
978
|
+
* `renderableFacets` (inside `FilterPanel`) drops it, so this file does not duplicate that rule.
|
|
979
|
+
*/
|
|
980
|
+
const filterFacets = computed<FilterFacet[]>(() =>
|
|
981
|
+
buildFilterFacets(expandedFilterRows.value, {
|
|
982
|
+
facets: facets.value,
|
|
983
|
+
selection: selection.value,
|
|
984
|
+
availability: availabilityLabels.value,
|
|
985
|
+
categoryScopeSlug: categoryScopeSlug.value,
|
|
986
|
+
unfilterable: unfilterableSources.value,
|
|
987
|
+
labelFor: defaultFacetLabel,
|
|
988
|
+
colourLayout: colourLayout.value,
|
|
989
|
+
sizeGuideHref: sizeGuideHref.value,
|
|
990
|
+
price: {
|
|
991
|
+
min: priceSpan.value.min,
|
|
992
|
+
max: priceSpan.value.max,
|
|
993
|
+
step: priceStep.value,
|
|
994
|
+
slider: priceSlider.value,
|
|
995
|
+
currency: money.currency.value !== undefined,
|
|
996
|
+
...(facets.value?.price?.histogram ? { histogram: facets.value.price.histogram } : {}),
|
|
997
|
+
},
|
|
998
|
+
})
|
|
999
|
+
);
|
|
1000
|
+
|
|
1001
|
+
/** Every rendered source's own `FilterSource`, by the `FilterFacet.id` the panel uses — the reverse
|
|
1002
|
+
* of `queryKeyFor`, for translating the panel's own selection back into the block's internal one
|
|
1003
|
+
* (`applyPanelSelection`, called from `onPanelChange`/`onPendingPanelChange`). */
|
|
1004
|
+
const sourceMap = computed(() => facetSourceMap(expandedFilterRows.value));
|
|
1005
|
+
|
|
1006
|
+
/** This scope's current toggle keys (`facets.toggles[]`), so `applyPanelSelection` can tell a known
|
|
1007
|
+
* toggle apart from an unknown `availability` array member (a stale value nothing lists any more). */
|
|
1008
|
+
const toggleKeySet = computed(
|
|
1009
|
+
() => new Set((facets.value?.toggles ?? []).map((toggle) => toggle.key))
|
|
1010
|
+
);
|
|
1011
|
+
|
|
1012
|
+
/** The sidebar panel's own live (applied) selection, keyed by facet id. One-way: the panel is
|
|
1013
|
+
* controlled from this, and every change it reports comes back through `onPanelChange`. */
|
|
1014
|
+
const panelSelection = computed<UiFilterSelection>(() =>
|
|
1015
|
+
panelSelectionFor(selection.value, { min: priceMin.value, max: priceMax.value }, priceSpan.value)
|
|
1016
|
+
);
|
|
1017
|
+
|
|
1018
|
+
/** The drawer panel's own pending copy of the same view. */
|
|
1019
|
+
const pendingPanelSelection = computed<UiFilterSelection>(() =>
|
|
1020
|
+
panelSelectionFor(
|
|
1021
|
+
pendingSelection.value,
|
|
1022
|
+
{ min: pendingMin.value, max: pendingMax.value },
|
|
1023
|
+
priceSpan.value
|
|
1024
|
+
)
|
|
1025
|
+
);
|
|
1026
|
+
|
|
1027
|
+
/**
|
|
1028
|
+
* The Filter button's own badge count: every applied value (`@eldrajs/ui`'s own `appliedFilters`,
|
|
1029
|
+
* which already excludes a range — a span has no one value a chip could take off) plus one more if
|
|
1030
|
+
* the price range is set, which the button's own count has always included.
|
|
1031
|
+
*/
|
|
1032
|
+
const activeCount = computed(
|
|
1033
|
+
() =>
|
|
1034
|
+
appliedFilters(filterFacets.value, panelSelection.value).length +
|
|
1035
|
+
(priceMin.value !== '' || priceMax.value !== '' ? 1 : 0)
|
|
1036
|
+
);
|
|
1037
|
+
|
|
1038
|
+
/**
|
|
1039
|
+
* The empty-results advice: the author's own `emptyText`, then a sentence naming what is actually
|
|
1040
|
+
* filtered ("Nothing in Oat, size M is in stock right now.", spec States → Empty results). The
|
|
1041
|
+
* value labels, not the chip labels — the sentence reads as prose, not as a list of facet titles.
|
|
1042
|
+
* `appliedFilters` already excludes the price range, same as this sentence always has.
|
|
1043
|
+
*/
|
|
1044
|
+
const emptyTitle = computed(() => (data.value.emptyTitle ?? '').trim() || t('grid.noResultsTitle'));
|
|
1045
|
+
const emptyText = computed(() => {
|
|
1046
|
+
const own = (data.value.emptyText ?? '').trim();
|
|
1047
|
+
const labels = appliedFilters(filterFacets.value, panelSelection.value).map(
|
|
1048
|
+
(filter) => filter.label
|
|
1049
|
+
);
|
|
1050
|
+
const named = labels.length > 0 ? t('grid.nothingIn', { filters: labels.join(', ') }) : '';
|
|
1051
|
+
return [own, named].filter((part) => part !== '').join(' ');
|
|
1052
|
+
});
|
|
1053
|
+
|
|
1054
|
+
// ---------------------------------------------------------------------------------------------
|
|
1055
|
+
// Writing the state out, and the result count
|
|
1056
|
+
// ---------------------------------------------------------------------------------------------
|
|
1057
|
+
|
|
1058
|
+
/**
|
|
1059
|
+
* The block's state as query keys, handed to the page through the one writer a block may call.
|
|
1060
|
+
* `null` clears a key; `page` is always cleared, because any filter, sort or column change starts
|
|
1061
|
+
* the results over (`load-more`'s own window is reset beside it).
|
|
1062
|
+
*/
|
|
1063
|
+
/**
|
|
1064
|
+
* The URL, read back into the block's own state — after mount, and on every later change.
|
|
1065
|
+
*
|
|
1066
|
+
* Three moves change the query without the block doing it: the browser's Back/Forward buttons, a
|
|
1067
|
+
* link to the same collection with a different filter, and — the one that made the deployed site's
|
|
1068
|
+
* filters inert — **arriving with a query on a prerendered page**. Nuxt hydrates a prerendered
|
|
1069
|
+
* route under the *payload's* path, query and all stripped, and only restores the real URL once
|
|
1070
|
+
* the app's `<Suspense>` has resolved (`hasDeferredRoute` in its router plugin). So
|
|
1071
|
+
* `?price=50-150` simply is not in the route while the block is being built: seeding
|
|
1072
|
+
* once left the inputs blank, the request unfiltered and the grid showing everything, under chips
|
|
1073
|
+
* and a URL that said otherwise.
|
|
1074
|
+
*
|
|
1075
|
+
* Adopting it after mount rather than during setup is also what keeps the first paint the server's:
|
|
1076
|
+
* the static HTML is the unfiltered collection, the client renders exactly that, and the filtered
|
|
1077
|
+
* read goes out afterwards — a transition, not a hydration mismatch.
|
|
1078
|
+
*
|
|
1079
|
+
* Every assignment is guarded by an equality check, so the block's own `publishState()` round-trip
|
|
1080
|
+
* (write the URL → the route changes → this reads it back) settles instead of re-requesting.
|
|
1081
|
+
*/
|
|
1082
|
+
function adoptRouteState(): void {
|
|
1083
|
+
// Tracked explicitly rather than inferred from `appliedFilters`' own reference stability: by the
|
|
1084
|
+
// time this watcher runs, `selection`/price may already carry a *sidebar* change this same tick
|
|
1085
|
+
// (`onPanelChange` writes them before `publishState()` echoes them into the route that wakes
|
|
1086
|
+
// this up) — and `flushFilterDebounce()` below must not fire for that round-trip, or it undoes
|
|
1087
|
+
// the arm that very same change just made for a reason this function had nothing to do with.
|
|
1088
|
+
let changed = false;
|
|
1089
|
+
const next = filterSelectionFromRoute(readableOptionKeys(selection.value), [
|
|
1090
|
+
...toggleKeySet.value,
|
|
1091
|
+
]);
|
|
1092
|
+
if (!sameSelection(next, selection.value)) {
|
|
1093
|
+
selection.value = next;
|
|
1094
|
+
changed = true;
|
|
1095
|
+
}
|
|
1096
|
+
const range = routePriceRange();
|
|
1097
|
+
if (range.min !== priceMin.value) {
|
|
1098
|
+
priceMin.value = range.min;
|
|
1099
|
+
changed = true;
|
|
1100
|
+
}
|
|
1101
|
+
if (range.max !== priceMax.value) {
|
|
1102
|
+
priceMax.value = range.max;
|
|
1103
|
+
changed = true;
|
|
1104
|
+
}
|
|
1105
|
+
if (
|
|
1106
|
+
route.sort !== null &&
|
|
1107
|
+
route.sort !== sort.value &&
|
|
1108
|
+
sortOptions.value.some((option) => option.value === route.sort)
|
|
1109
|
+
) {
|
|
1110
|
+
sort.value = route.sort;
|
|
1111
|
+
}
|
|
1112
|
+
if (
|
|
1113
|
+
route.columns !== null &&
|
|
1114
|
+
route.columns !== columnsChoice.value &&
|
|
1115
|
+
COLUMN_CHOICES.includes(route.columns)
|
|
1116
|
+
) {
|
|
1117
|
+
columnsChoice.value = route.columns;
|
|
1118
|
+
}
|
|
1119
|
+
// A query the block did not write (Back/Forward, a shared link, the first adopt on mount)
|
|
1120
|
+
// applies at once — it is not the sidebar's own live path, so it owes nothing to
|
|
1121
|
+
// `FILTER_DEBOUNCE_MS`. Only when *this* function actually changed the applied selection or
|
|
1122
|
+
// price: the block's own `publishState()` round-trip changes neither (the guards above already
|
|
1123
|
+
// settle it instead of re-requesting), so it never manufactures a request nothing asked for —
|
|
1124
|
+
// and, just as importantly, never flushes a debounce some other change armed a moment earlier.
|
|
1125
|
+
if (changed) flushFilterDebounce();
|
|
1126
|
+
}
|
|
1127
|
+
|
|
1128
|
+
/** Two selections holding the same values for the same sources, order included. */
|
|
1129
|
+
function sameSelection(a: FilterSelection, b: FilterSelection): boolean {
|
|
1130
|
+
const sources = new Set([...Object.keys(a), ...Object.keys(b)]) as Set<FilterSource>;
|
|
1131
|
+
for (const source of sources) {
|
|
1132
|
+
const left = a[source] ?? [];
|
|
1133
|
+
const right = b[source] ?? [];
|
|
1134
|
+
if (left.length !== right.length) return false;
|
|
1135
|
+
if (left.some((value, index) => value !== right[index])) return false;
|
|
1136
|
+
}
|
|
1137
|
+
return true;
|
|
1138
|
+
}
|
|
1139
|
+
|
|
1140
|
+
onMounted(() => {
|
|
1141
|
+
adoptRouteState();
|
|
1142
|
+
// The facets are in there because they are what makes an option key *readable* at all
|
|
1143
|
+
// (`readableOptionKeys`): a shared `?fabric=linen` can only be adopted once the store has said it
|
|
1144
|
+
// has a `fabric` option, which is the first read answering.
|
|
1145
|
+
watch(() => [route.filters, route.sort, route.columns, facets.value], adoptRouteState, {
|
|
1146
|
+
deep: true,
|
|
1147
|
+
});
|
|
1148
|
+
});
|
|
1149
|
+
|
|
1150
|
+
function publishState(): void {
|
|
1151
|
+
pagesLoaded.value = 1;
|
|
1152
|
+
const patch: Record<string, string | string[] | null> = {
|
|
1153
|
+
page: null,
|
|
1154
|
+
sort: sort.value === '' ? null : sort.value,
|
|
1155
|
+
columns: columnsChoice.value,
|
|
1156
|
+
price: formatPriceRange({ min: priceMin.value, max: priceMax.value }),
|
|
1157
|
+
};
|
|
1158
|
+
// Every source, selected or not: a key the shopper has just emptied has to be cleared, which a
|
|
1159
|
+
// patch built only from what is selected would leave in the URL for ever. The option keys come
|
|
1160
|
+
// from everything the block knows of — the author's rows, the facets, and the selection itself, so
|
|
1161
|
+
// a key the store has since stopped offering can still be cleared rather than sticking for ever.
|
|
1162
|
+
//
|
|
1163
|
+
// **Every one of those three goes through `usableOptionKey` first**, and this is the place it
|
|
1164
|
+
// matters most: a source whose query key belongs to something else would be *written* here, after
|
|
1165
|
+
// the four keys above, so it lands last and wins. A store with an option keyed `sort` stripped the
|
|
1166
|
+
// shopper's sort out of the URL on every state write; one keyed `category` cleared the category
|
|
1167
|
+
// they had just ticked, which `adoptRouteState` then read back as absent, reverting the tick on
|
|
1168
|
+
// screen. Refusing the key in the three places it is *read* was not enough — the patch is where the
|
|
1169
|
+
// damage was.
|
|
1170
|
+
const sources = new Set<FilterSource>();
|
|
1171
|
+
const add = (source: FilterSource): void => {
|
|
1172
|
+
const key = optionKeyOf(source);
|
|
1173
|
+
if (key !== null && usableOptionKey(key) === null) return;
|
|
1174
|
+
sources.add(source);
|
|
1175
|
+
};
|
|
1176
|
+
for (const source of managedSources(readableOptionKeys(selection.value), [
|
|
1177
|
+
...toggleKeySet.value,
|
|
1178
|
+
])) {
|
|
1179
|
+
add(source);
|
|
1180
|
+
}
|
|
1181
|
+
for (const option of facets.value?.options ?? []) add(optionSourceFor(option.key));
|
|
1182
|
+
for (const toggle of facets.value?.toggles ?? []) add(toggleSourceFor(toggle.key));
|
|
1183
|
+
for (const source of Object.keys(selection.value)) {
|
|
1184
|
+
if (isFilterSource(source)) add(source);
|
|
1185
|
+
}
|
|
1186
|
+
for (const source of sources) {
|
|
1187
|
+
// By its **query key**, not by the source: the price range is already in the patch above as one
|
|
1188
|
+
// `<min>-<max>` string, and nothing may overwrite it with a selection list.
|
|
1189
|
+
if (queryKeyFor(source) === 'price') continue;
|
|
1190
|
+
patch[queryKeyFor(source)] = selection.value[source] ?? null;
|
|
1191
|
+
}
|
|
1192
|
+
route.setQuery(patch);
|
|
1193
|
+
}
|
|
1194
|
+
|
|
1195
|
+
const countText = computed(() => {
|
|
1196
|
+
if (showSkeletons.value || updating.value) return t('grid.updating');
|
|
1197
|
+
if (total.value === 1) return t('grid.oneProduct');
|
|
1198
|
+
return t('grid.nProducts', { count: total.value });
|
|
1199
|
+
});
|
|
1200
|
+
|
|
1201
|
+
const countEl = ref<HTMLElement | null>(null);
|
|
1202
|
+
/** The sidebar and drawer `FilterPanel` instances, for `focusChip`/`focusTitle` after a chip is
|
|
1203
|
+
* removed from inside either one (`onPanelRemove`/`onPendingPanelRemove`). */
|
|
1204
|
+
const sidebarPanelEl = ref<InstanceType<typeof FilterPanel> | null>(null);
|
|
1205
|
+
const drawerPanelEl = ref<InstanceType<typeof FilterPanel> | null>(null);
|
|
1206
|
+
function focusCount(): void {
|
|
1207
|
+
countEl.value?.focus();
|
|
1208
|
+
}
|
|
1209
|
+
|
|
1210
|
+
/**
|
|
1211
|
+
* The applied filters just before the panel's own `change` handler ran — read at the top of
|
|
1212
|
+
* `onPanelChange`/`onPendingPanelChange`, before either mutates `selection`/`pendingSelection`, so
|
|
1213
|
+
* `onPanelRemove`/`onPendingPanelRemove` can still find the removed chip's own index a moment
|
|
1214
|
+
* later: the panel reports `change` and then `remove` synchronously in that order (`FilterPanel`'s
|
|
1215
|
+
* own `onRemoveChip`), so by the time `remove` arrives the state is already the *post*-removal one
|
|
1216
|
+
* and the chip is gone from it. Mirrors the pre-panel code's own `chips.value.findIndex(...)` — an
|
|
1217
|
+
* index taken before the mutation, clamped into the list that remains after it.
|
|
1218
|
+
*/
|
|
1219
|
+
let lastSidebarChips: ReturnType<typeof appliedFilters> = [];
|
|
1220
|
+
let lastPendingChips: ReturnType<typeof appliedFilters> = [];
|
|
1221
|
+
|
|
1222
|
+
// ---------------------------------------------------------------------------------------------
|
|
1223
|
+
// Applying a change
|
|
1224
|
+
// ---------------------------------------------------------------------------------------------
|
|
1225
|
+
|
|
1226
|
+
/**
|
|
1227
|
+
* The sidebar's own live path: the visible selection, the applied chips and the URL all move at
|
|
1228
|
+
* once, but the read this drives waits out `FILTER_DEBOUNCE_MS` so a run of ticks reaches the
|
|
1229
|
+
* storefront as the one request the shopper's last tick deserves. **Armed first**, before anything
|
|
1230
|
+
* moves: `publishState()` resets the page window in the same turn, and that is one of the read's
|
|
1231
|
+
* own inputs — arming afterwards would let it through on its own.
|
|
1232
|
+
*
|
|
1233
|
+
* One handler for every kind of change the panel reports (a checkbox, a switch, a committed range,
|
|
1234
|
+
* a typed field, **Clear all**, a removed chip) — unlike the pre-panel code's separate
|
|
1235
|
+
* `onToggle`/`onRange`, because the panel always reports the *whole* resulting selection rather
|
|
1236
|
+
* than one value at a time, so there is nothing left to apply incrementally.
|
|
1237
|
+
*/
|
|
1238
|
+
function onPanelChange(next: UiFilterSelection): void {
|
|
1239
|
+
lastSidebarChips = appliedFilters(filterFacets.value, panelSelection.value);
|
|
1240
|
+
armFilterDebounce();
|
|
1241
|
+
const applied = applyPanelSelection(next, {
|
|
1242
|
+
sources: sourceMap.value,
|
|
1243
|
+
toggleKeys: toggleKeySet.value,
|
|
1244
|
+
priceSpan: priceSpan.value,
|
|
1245
|
+
appliedPrice: { min: priceMin.value, max: priceMax.value },
|
|
1246
|
+
});
|
|
1247
|
+
selection.value = applied.selection;
|
|
1248
|
+
priceMin.value = applied.price.min;
|
|
1249
|
+
priceMax.value = applied.price.max;
|
|
1250
|
+
publishState();
|
|
1251
|
+
}
|
|
1252
|
+
|
|
1253
|
+
/**
|
|
1254
|
+
* **Clear all**, fired right after `onPanelChange` already ran for the same click (the panel
|
|
1255
|
+
* always emits `change` before `clear`). That first `publishState()` call can still read stale
|
|
1256
|
+
* facets: `requestOptions` is the sidebar's own debounced mirror, so a family a filter had just
|
|
1257
|
+
* narrowed away (no `colour` option, say) has not come back into the unfiltered facets yet, which
|
|
1258
|
+
* means `readableOptionKeys` cannot yet call it readable — so `publishState()`'s own patch never
|
|
1259
|
+
* clears that query key, leaving the old selection to round-trip straight back in through
|
|
1260
|
+
* `adoptRouteState()`. Flushing the debounce brings `facets.value` back in step *before*
|
|
1261
|
+
* publishing again, which is what actually clears every query key — the same ordering `onSort`'s
|
|
1262
|
+
* own comment explains at length, needed here because Clear all is the one path that both empties
|
|
1263
|
+
* the selection and needs that fresher read to publish correctly.
|
|
1264
|
+
*/
|
|
1265
|
+
function onPanelClear(): void {
|
|
1266
|
+
flushFilterDebounce();
|
|
1267
|
+
publishState();
|
|
1268
|
+
}
|
|
1269
|
+
/** Sort applies at once and flushes any sidebar change still waiting out its debounce, so the one
|
|
1270
|
+
* request this triggers carries both. Flushed *before* `publishState()`, not after: that call
|
|
1271
|
+
* reads `facets.value` (through `readableOptionKeys`) to decide which option keys its patch
|
|
1272
|
+
* clears, and a flush is what brings the facets back in step with whatever selection is actually
|
|
1273
|
+
* applied — reading them stale very nearly left a cleared filter's own query key uncleared, since
|
|
1274
|
+
* a facet family a filtered answer had dropped was not yet back in the "readable" set. */
|
|
1275
|
+
function onSort(value: string): void {
|
|
1276
|
+
sort.value = value;
|
|
1277
|
+
flushFilterDebounce();
|
|
1278
|
+
publishState();
|
|
1279
|
+
}
|
|
1280
|
+
/** Columns is layout, not a request parameter — flushed anyway, so a shopper who was mid-filter
|
|
1281
|
+
* when they changed it is not left waiting on a debounce window they have moved past.
|
|
1282
|
+
*
|
|
1283
|
+
* Flushed **last** here, unlike `onSort`: the flush assigns the mirror synchronously, so anything
|
|
1284
|
+
* that changes a request input *after* it queues the mirror's own watcher behind the result's and
|
|
1285
|
+
* the read goes out twice — once on the half-applied value, once on the final one. `onSort` is
|
|
1286
|
+
* safe because `sort.value` is itself a request input and moves first; this handler's own write is
|
|
1287
|
+
* layout only, and the request input it touches is `publishState()`'s page-window reset. It owes
|
|
1288
|
+
* nothing to `onSort`'s facets ordering either, because it changes no filter: `publishState()`
|
|
1289
|
+
* reads the facets to decide which filter query keys to clear, and there is nothing here to
|
|
1290
|
+
* clear. */
|
|
1291
|
+
function onColumns(value: string): void {
|
|
1292
|
+
columnsChoice.value = value;
|
|
1293
|
+
publishState();
|
|
1294
|
+
flushFilterDebounce();
|
|
1295
|
+
}
|
|
1296
|
+
|
|
1297
|
+
/** Spec Acceptance: "after Clear all, [focus lands] on the count." The sidebar panel's own head
|
|
1298
|
+
* draws **Clear all** and moves focus to its own title itself (spec → Behaviour), which is a
|
|
1299
|
+
* sensible place to land right beside the button that was pressed — this is only the empty
|
|
1300
|
+
* state's own **Clear filters** button, a block-drawn control the panel knows nothing about, so
|
|
1301
|
+
* it still has to clear and focus by hand. */
|
|
1302
|
+
async function onClearAll(): Promise<void> {
|
|
1303
|
+
selection.value = {};
|
|
1304
|
+
priceMin.value = '';
|
|
1305
|
+
priceMax.value = '';
|
|
1306
|
+
flushFilterDebounce();
|
|
1307
|
+
publishState();
|
|
1308
|
+
await nextTick();
|
|
1309
|
+
focusCount();
|
|
1310
|
+
}
|
|
1311
|
+
|
|
1312
|
+
/**
|
|
1313
|
+
* `FilterPanel.focusChip(index)` reads its own `chipEls` ref array, which a shrinking `v-for` does
|
|
1314
|
+
* not always re-populate at the chip's *new* index in time for the same tick this fires in (the
|
|
1315
|
+
* surviving chip's remove button keeps its DOM node across the removal, but the ref callback that
|
|
1316
|
+
* records it under the new index is not guaranteed to have run yet). Querying the panel's own root
|
|
1317
|
+
* for the Nth remove button in document order is exactly what a shopper's or a screen reader's own
|
|
1318
|
+
* next stop would be, and does not depend on that internal bookkeeping.
|
|
1319
|
+
*/
|
|
1320
|
+
function focusNthRemoveButton(panel: InstanceType<typeof FilterPanel> | null, index: number): void {
|
|
1321
|
+
const root = (panel as { $el?: Element } | null)?.$el;
|
|
1322
|
+
const button = root?.querySelectorAll('[data-part="removeButton"]')[index];
|
|
1323
|
+
(button as HTMLElement | undefined)?.focus();
|
|
1324
|
+
}
|
|
1325
|
+
|
|
1326
|
+
/**
|
|
1327
|
+
* Spec Acceptance: "After removing a chip, focus lands on the next chip or on the count." Applies
|
|
1328
|
+
* at once, the same as Clear all (`onPanelClear`) and for the same reason: `onPanelChange` has
|
|
1329
|
+
* already run for this same click and may have published over stale facets, so this flushes and
|
|
1330
|
+
* republishes before working out where focus goes — the one thing the panel cannot do itself.
|
|
1331
|
+
*/
|
|
1332
|
+
async function onPanelRemove(removal: { facetId: string; value: string }): Promise<void> {
|
|
1333
|
+
const index = lastSidebarChips.findIndex(
|
|
1334
|
+
(chip) => chip.facetId === removal.facetId && chip.value === removal.value
|
|
1335
|
+
);
|
|
1336
|
+
flushFilterDebounce();
|
|
1337
|
+
publishState();
|
|
1338
|
+
await nextTick();
|
|
1339
|
+
const remaining = appliedFilters(filterFacets.value, panelSelection.value);
|
|
1340
|
+
if (remaining.length === 0 || index < 0) {
|
|
1341
|
+
focusCount();
|
|
1342
|
+
return;
|
|
1343
|
+
}
|
|
1344
|
+
focusNthRemoveButton(sidebarPanelEl.value, Math.min(index, remaining.length - 1));
|
|
1345
|
+
}
|
|
1346
|
+
|
|
1347
|
+
/** Widen the window first, resolve an armed sidebar wait second — the ordering `onColumns` explains
|
|
1348
|
+
* at length. Flushing first assigned the mirror on the old window, and the wider one that followed
|
|
1349
|
+
* queued the mirror behind the result's own watcher: two reads for one press, the first of them
|
|
1350
|
+
* for a window the press had already replaced. */
|
|
1351
|
+
function onLoadMore(): void {
|
|
1352
|
+
loadingMore.value = true;
|
|
1353
|
+
pagesLoaded.value += 1;
|
|
1354
|
+
flushFilterDebounce();
|
|
1355
|
+
}
|
|
1356
|
+
|
|
1357
|
+
// ---------------------------------------------------------------------------------------------
|
|
1358
|
+
// The drawer
|
|
1359
|
+
// ---------------------------------------------------------------------------------------------
|
|
1360
|
+
|
|
1361
|
+
const drawerOpen = ref(false);
|
|
1362
|
+
/** Latches on the first open, so the pending-count request below is never made on a page where
|
|
1363
|
+
* nobody opened the drawer. */
|
|
1364
|
+
const drawerUsed = ref(false);
|
|
1365
|
+
const pendingSelection = ref<FilterSelection>({});
|
|
1366
|
+
const pendingMin = ref('');
|
|
1367
|
+
const pendingMax = ref('');
|
|
1368
|
+
|
|
1369
|
+
const pendingSelected = computed(() => (drawerUsed.value ? selected.value : null));
|
|
1370
|
+
const pendingFilters = computed(() =>
|
|
1371
|
+
requestFiltersFor(pendingSelection.value, pendingMin.value, pendingMax.value)
|
|
1372
|
+
);
|
|
1373
|
+
/** The pending count read's own debounced echo of `pendingFilters` — the same
|
|
1374
|
+
* `FILTER_DEBOUNCE_MS` window the sidebar's live path waits out, so a shopper ticking several
|
|
1375
|
+
* boxes inside the drawer sends the pending-count request once rather than once per tick. */
|
|
1376
|
+
const debouncedPendingFilters = ref(pendingFilters.value);
|
|
1377
|
+
let pendingDebounceTimer: ReturnType<typeof setTimeout> | null = null;
|
|
1378
|
+
|
|
1379
|
+
function armPendingDebounce(): void {
|
|
1380
|
+
if (pendingDebounceTimer !== null) clearTimeout(pendingDebounceTimer);
|
|
1381
|
+
pendingDebounceTimer = setTimeout(() => {
|
|
1382
|
+
pendingDebounceTimer = null;
|
|
1383
|
+
debouncedPendingFilters.value = pendingFilters.value;
|
|
1384
|
+
}, FILTER_DEBOUNCE_MS);
|
|
1385
|
+
}
|
|
1386
|
+
/** Resolves an armed pending wait at once — opening the drawer fresh and Clear all inside it both
|
|
1387
|
+
* call this rather than leaving the count to catch up on its own after a window nobody is
|
|
1388
|
+
* chaining into. */
|
|
1389
|
+
function flushPendingDebounce(): void {
|
|
1390
|
+
if (pendingDebounceTimer !== null) {
|
|
1391
|
+
clearTimeout(pendingDebounceTimer);
|
|
1392
|
+
pendingDebounceTimer = null;
|
|
1393
|
+
}
|
|
1394
|
+
debouncedPendingFilters.value = pendingFilters.value;
|
|
1395
|
+
}
|
|
1396
|
+
|
|
1397
|
+
const pendingOptions = computed(() => ({
|
|
1398
|
+
page: 1,
|
|
1399
|
+
pageSize: 1,
|
|
1400
|
+
sort: sort.value === '' ? undefined : sort.value,
|
|
1401
|
+
filters: debouncedPendingFilters.value,
|
|
1402
|
+
...categoryScopeOption.value,
|
|
1403
|
+
}));
|
|
1404
|
+
const pendingProducts = storeWideScope.value
|
|
1405
|
+
? storefront.catalog.products(pendingOptions)
|
|
1406
|
+
: storefront.catalog.collectionProducts(pendingSelected, pendingOptions);
|
|
1407
|
+
const pendingTotal = computed(() => pendingProducts.data.value?.total ?? total.value);
|
|
1408
|
+
|
|
1409
|
+
function openDrawer(): void {
|
|
1410
|
+
pendingSelection.value = { ...selection.value };
|
|
1411
|
+
pendingMin.value = priceMin.value;
|
|
1412
|
+
pendingMax.value = priceMax.value;
|
|
1413
|
+
drawerUsed.value = true;
|
|
1414
|
+
drawerOpen.value = true;
|
|
1415
|
+
flushPendingDebounce();
|
|
1416
|
+
}
|
|
1417
|
+
/** The drawer's own path: every kind of change the panel reports, applied to the *pending* copy —
|
|
1418
|
+
* nothing here reaches the page until `applyPending()`. */
|
|
1419
|
+
function onPendingPanelChange(next: UiFilterSelection): void {
|
|
1420
|
+
lastPendingChips = appliedFilters(filterFacets.value, pendingPanelSelection.value);
|
|
1421
|
+
const applied = applyPanelSelection(next, {
|
|
1422
|
+
sources: sourceMap.value,
|
|
1423
|
+
toggleKeys: toggleKeySet.value,
|
|
1424
|
+
priceSpan: priceSpan.value,
|
|
1425
|
+
appliedPrice: { min: pendingMin.value, max: pendingMax.value },
|
|
1426
|
+
});
|
|
1427
|
+
pendingSelection.value = applied.selection;
|
|
1428
|
+
pendingMin.value = applied.price.min;
|
|
1429
|
+
pendingMax.value = applied.price.max;
|
|
1430
|
+
armPendingDebounce();
|
|
1431
|
+
}
|
|
1432
|
+
|
|
1433
|
+
/**
|
|
1434
|
+
* The same focus contract as `onPanelRemove`, for a chip removed from inside the drawer — with
|
|
1435
|
+
* nothing left, there is no count to fall back to inside a dialog, so focus is left where the
|
|
1436
|
+
* browser already puts it (the dialog itself, never outside it, because `Drawer` is a true modal).
|
|
1437
|
+
*/
|
|
1438
|
+
async function onPendingPanelRemove(removal: { facetId: string; value: string }): Promise<void> {
|
|
1439
|
+
const index = lastPendingChips.findIndex(
|
|
1440
|
+
(chip) => chip.facetId === removal.facetId && chip.value === removal.value
|
|
1441
|
+
);
|
|
1442
|
+
flushPendingDebounce();
|
|
1443
|
+
await nextTick();
|
|
1444
|
+
const remaining = appliedFilters(filterFacets.value, pendingPanelSelection.value);
|
|
1445
|
+
if (remaining.length === 0 || index < 0) return;
|
|
1446
|
+
focusNthRemoveButton(drawerPanelEl.value, Math.min(index, remaining.length - 1));
|
|
1447
|
+
}
|
|
1448
|
+
|
|
1449
|
+
/** Spec: "Filtering in the drawer changes nothing on the page until **Show N products** is
|
|
1450
|
+
* pressed." This is the only path out of the pending copy into the applied one — applied, like
|
|
1451
|
+
* every other immediate-apply control, so it flushes the main debounce too rather than leaving a
|
|
1452
|
+
* sidebar change the shopper made before opening the drawer stranded. Flushed before
|
|
1453
|
+
* `publishState()` for the same reason `onSort` is. */
|
|
1454
|
+
function applyPending(): void {
|
|
1455
|
+
selection.value = { ...pendingSelection.value };
|
|
1456
|
+
priceMin.value = pendingMin.value;
|
|
1457
|
+
priceMax.value = pendingMax.value;
|
|
1458
|
+
flushFilterDebounce();
|
|
1459
|
+
publishState();
|
|
1460
|
+
drawerOpen.value = false;
|
|
1461
|
+
}
|
|
1462
|
+
|
|
1463
|
+
/**
|
|
1464
|
+
* **Clear all**, from the drawer's own foot (drawn by the Drawer's footer slot now, not the
|
|
1465
|
+
* panel's own hidden copy — see the drawer template below). Reproduces exactly what `FilterPanel`'s
|
|
1466
|
+
* internal Clear all does: `clearedSelection()` is `{}`, and `onPendingPanelChange` is the very
|
|
1467
|
+
* handler the panel's own `change` event already calls, so the pending copy, the price fields and
|
|
1468
|
+
* the pending-count debounce all land exactly where they would have. Focus is left alone, same as
|
|
1469
|
+
* the panel's own drawer-mode Clear all (`onClear(false)`): the browser keeps it on the button.
|
|
1470
|
+
*/
|
|
1471
|
+
function onDrawerClearAll(): void {
|
|
1472
|
+
onPendingPanelChange({});
|
|
1473
|
+
flushPendingDebounce();
|
|
1474
|
+
}
|
|
1475
|
+
|
|
1476
|
+
/** Neither debounce outlives the component — a filter ticked right before navigating away must
|
|
1477
|
+
* not fire a request into a storefront read nothing is listening to any more. */
|
|
1478
|
+
onUnmounted(() => {
|
|
1479
|
+
if (filterDebounceTimer !== null) clearTimeout(filterDebounceTimer);
|
|
1480
|
+
if (pendingDebounceTimer !== null) clearTimeout(pendingDebounceTimer);
|
|
1481
|
+
});
|
|
1482
|
+
|
|
1483
|
+
// ---------------------------------------------------------------------------------------------
|
|
1484
|
+
// Layout
|
|
1485
|
+
// ---------------------------------------------------------------------------------------------
|
|
1486
|
+
|
|
1487
|
+
/**
|
|
1488
|
+
* The shared product grid (spec "Product grid", 3040): 2 columns below 48rem with 2rem × 1rem
|
|
1489
|
+
* gaps; from 48rem 3 (or 2), gaps 3rem × 1.5rem — the 4-column setting shows 3 here; `columns` from
|
|
1490
|
+
* 64rem. Static strings from a lookup, so Tailwind emits every one of them.
|
|
1491
|
+
*/
|
|
1492
|
+
const GRID_COLUMNS: Record<string, string> = {
|
|
1493
|
+
'2': 'grid-cols-2',
|
|
1494
|
+
'3': 'grid-cols-2 @tablet:grid-cols-3',
|
|
1495
|
+
'4': 'grid-cols-2 @tablet:grid-cols-3 @content:grid-cols-4',
|
|
1496
|
+
};
|
|
1497
|
+
const gridClass: ComputedRef<string> = computed(
|
|
1498
|
+
() =>
|
|
1499
|
+
`grid gap-x-4 gap-y-8 @tablet:gap-x-6 @tablet:gap-y-12 ${GRID_COLUMNS[columnsChoice.value] ?? GRID_COLUMNS['3']!}`
|
|
1500
|
+
);
|
|
1501
|
+
|
|
1502
|
+
/** A block whose `filters[]` is empty has nothing to put in a sidebar, a drawer or behind the
|
|
1503
|
+
* Filter button — the "empty optional parts render nothing" rule, so the grid simply gets the
|
|
1504
|
+
* whole width. */
|
|
1505
|
+
const showSidebar = computed(() => hasSidebar.value && filterFacets.value.length > 0);
|
|
1506
|
+
const hasFilters = computed(() => filterFacets.value.length > 0);
|
|
1507
|
+
const hasSort = computed(() => sortOptions.value.length > 0);
|
|
1508
|
+
const showTopBar = computed(() => hasFilters.value || hasSort.value);
|
|
1509
|
+
|
|
1510
|
+
const layoutClass = computed(() =>
|
|
1511
|
+
showSidebar.value
|
|
1512
|
+
? '@content:grid @content:grid-cols-[15rem_1fr] @content:items-start @content:gap-12'
|
|
1513
|
+
: ''
|
|
1514
|
+
);
|
|
1515
|
+
/**
|
|
1516
|
+
* The top bar is the below-64rem control row: the Filter button beside the sort select. From 64rem
|
|
1517
|
+
* the spec hides it outright ("The mobile top bar is hidden") and the toolbar carries Sort by and
|
|
1518
|
+
* Columns instead — which is what the `sidebar` variant does. `drawer-only` has no sidebar, so its
|
|
1519
|
+
* Filter button is the only way into the filters and has to survive at every width; its **sort**
|
|
1520
|
+
* does not, because the toolbar's own sort select is shown from exactly the same 64rem.
|
|
1521
|
+
*
|
|
1522
|
+
* So the two halves are hidden separately rather than the whole bar being kept: the bar itself goes
|
|
1523
|
+
* from 64rem only in `sidebar` (`topBarClass`), and the sort inside it goes from 64rem in **both**
|
|
1524
|
+
* variants (`topBarSortClass`). Exactly one sort control is visible at every width in either
|
|
1525
|
+
* variant — the defect this replaced rendered two of them in `drawer-only` at desktop width, one
|
|
1526
|
+
* piece of state behind two comboboxes both named "Sort by". Container queries are invisible to
|
|
1527
|
+
* jsdom, so these two class strings are what the spec asserts.
|
|
1528
|
+
*/
|
|
1529
|
+
const topBarClass = computed(() =>
|
|
1530
|
+
[
|
|
1531
|
+
'mb-4 grid items-center gap-3',
|
|
1532
|
+
hasFilters.value ? 'grid-cols-[auto_1fr]' : 'grid-cols-1',
|
|
1533
|
+
hasSidebar.value ? '@content:hidden' : '',
|
|
1534
|
+
].join(' ')
|
|
1535
|
+
);
|
|
1536
|
+
/** The top bar's own sort select: never shown from 64rem, where the toolbar's is. */
|
|
1537
|
+
const TOP_BAR_SORT = '@content:hidden';
|
|
1538
|
+
|
|
1539
|
+
const totalPages = computed(() => Math.max(1, Math.ceil(total.value / pageSize.value)));
|
|
1540
|
+
const showPaging = computed(() => !showSkeletons.value && cards.value.length > 0);
|
|
1541
|
+
function hrefForPage(page: number): string {
|
|
1542
|
+
const base = categoryScope.value
|
|
1543
|
+
? categoryHref(routeCategoryPath ?? '')
|
|
1544
|
+
: catalogueScope.value
|
|
1545
|
+
? CATALOGUE_PATH
|
|
1546
|
+
: `/collections/${collectionHandle.value ?? ''}`;
|
|
1547
|
+
return safeHref(page > 1 ? `${base}?page=${page}` : base) ?? base;
|
|
1548
|
+
}
|
|
1549
|
+
</script>
|
|
1550
|
+
|
|
1551
|
+
<template>
|
|
1552
|
+
<Section
|
|
1553
|
+
v-if="hasCollection || showNoCollectionHint || showNoCategoryHint"
|
|
1554
|
+
spacing="none"
|
|
1555
|
+
:aria-label="sectionLabel"
|
|
1556
|
+
:classes="{ root: 'pt-6 pb-[var(--eldra-section-md)]' }"
|
|
1557
|
+
>
|
|
1558
|
+
<Container width="wide">
|
|
1559
|
+
<EditorPlaceholder
|
|
1560
|
+
v-if="showNoCollectionHint"
|
|
1561
|
+
:icon="BoxIcon"
|
|
1562
|
+
:label="t('grid.noCollectionLabel')"
|
|
1563
|
+
:help="t('grid.noCollectionHelp')"
|
|
1564
|
+
/>
|
|
1565
|
+
|
|
1566
|
+
<EditorPlaceholder
|
|
1567
|
+
v-else-if="showNoCategoryHint"
|
|
1568
|
+
:icon="BoxIcon"
|
|
1569
|
+
:label="t('grid.noCategoryLabel')"
|
|
1570
|
+
:help="t('grid.noCategoryHelp')"
|
|
1571
|
+
/>
|
|
1572
|
+
|
|
1573
|
+
<EditorPlaceholder
|
|
1574
|
+
v-else-if="showUnresolvedCollectionHint"
|
|
1575
|
+
:icon="BoxIcon"
|
|
1576
|
+
:label="t('storefront.unresolvedCollectionLabel')"
|
|
1577
|
+
:help="t('storefront.unresolvedCollectionHelp')"
|
|
1578
|
+
/>
|
|
1579
|
+
|
|
1580
|
+
<template v-else>
|
|
1581
|
+
<div :class="layoutClass">
|
|
1582
|
+
<aside
|
|
1583
|
+
v-if="showSidebar"
|
|
1584
|
+
:aria-label="t('grid.filters')"
|
|
1585
|
+
class="@content:block @content:sticky @content:top-[calc(1.5rem_+_var(--eldra-header-height,0px))] hidden"
|
|
1586
|
+
>
|
|
1587
|
+
<!-- The panel's own head (`show-head`, the default) draws a visible "Filters" `h2`
|
|
1588
|
+
right before its `h3` group triggers, which is what keeps a whole-page axe run's
|
|
1589
|
+
`heading-order` rule happy under the page's own `h1` — no hidden heading to add
|
|
1590
|
+
beside it any more. -->
|
|
1591
|
+
<FilterPanel
|
|
1592
|
+
ref="sidebarPanelEl"
|
|
1593
|
+
dense
|
|
1594
|
+
mode="sidebar"
|
|
1595
|
+
show-applied
|
|
1596
|
+
:facets="filterFacets"
|
|
1597
|
+
:model-value="panelSelection"
|
|
1598
|
+
:currency="money.currency.value"
|
|
1599
|
+
:id-prefix="`collection-grid-sidebar-${uid}`"
|
|
1600
|
+
@change="onPanelChange"
|
|
1601
|
+
@clear="onPanelClear"
|
|
1602
|
+
@remove="onPanelRemove"
|
|
1603
|
+
/>
|
|
1604
|
+
</aside>
|
|
1605
|
+
|
|
1606
|
+
<div class="min-w-0">
|
|
1607
|
+
<!-- Top bar: Filter + sort, below 64rem (always in drawer-only). -->
|
|
1608
|
+
<div v-if="showTopBar" :class="topBarClass">
|
|
1609
|
+
<Button
|
|
1610
|
+
v-if="hasFilters"
|
|
1611
|
+
variant="outline"
|
|
1612
|
+
:icon-left="AdjustmentsIcon"
|
|
1613
|
+
:classes="{ container: 'min-h-11' }"
|
|
1614
|
+
aria-haspopup="dialog"
|
|
1615
|
+
:aria-expanded="drawerOpen ? 'true' : 'false'"
|
|
1616
|
+
:aria-controls="drawerId"
|
|
1617
|
+
@click="openDrawer"
|
|
1618
|
+
>
|
|
1619
|
+
{{ t('grid.filter') }}
|
|
1620
|
+
<Badge
|
|
1621
|
+
v-if="activeCount > 0"
|
|
1622
|
+
tone="primary"
|
|
1623
|
+
pill
|
|
1624
|
+
:classes="{ root: 'ms-1' }"
|
|
1625
|
+
:hidden-suffix="t('grid.nActive', { count: activeCount })"
|
|
1626
|
+
>
|
|
1627
|
+
<span aria-hidden="true">{{ activeCount }}</span>
|
|
1628
|
+
</Badge>
|
|
1629
|
+
</Button>
|
|
1630
|
+
<FieldWrapper
|
|
1631
|
+
v-if="hasSort"
|
|
1632
|
+
:label="t('grid.sortBy')"
|
|
1633
|
+
:classes="{ root: TOP_BAR_SORT, label: 'sr-only' }"
|
|
1634
|
+
>
|
|
1635
|
+
<Select
|
|
1636
|
+
:model-value="sort"
|
|
1637
|
+
size="md"
|
|
1638
|
+
:options="sortOptions"
|
|
1639
|
+
:leading-icon="SortIcon"
|
|
1640
|
+
:classes="{ value: 'font-semibold' }"
|
|
1641
|
+
@update:model-value="onSort"
|
|
1642
|
+
/>
|
|
1643
|
+
</FieldWrapper>
|
|
1644
|
+
</div>
|
|
1645
|
+
|
|
1646
|
+
<!-- Toolbar: the count, and Sort by + Columns from 64rem. -->
|
|
1647
|
+
<div class="border-border flex flex-wrap items-center gap-x-6 gap-y-2 border-b pb-4">
|
|
1648
|
+
<p
|
|
1649
|
+
ref="countEl"
|
|
1650
|
+
tabindex="-1"
|
|
1651
|
+
role="status"
|
|
1652
|
+
aria-live="polite"
|
|
1653
|
+
class="text-body-sm text-muted tabular-nums"
|
|
1654
|
+
>
|
|
1655
|
+
{{ countText }}
|
|
1656
|
+
</p>
|
|
1657
|
+
<div class="@content:flex ms-auto hidden items-center gap-6">
|
|
1658
|
+
<FieldWrapper
|
|
1659
|
+
v-if="hasSort"
|
|
1660
|
+
:label="t('grid.sortBy')"
|
|
1661
|
+
:classes="{
|
|
1662
|
+
root: 'flex items-center gap-2',
|
|
1663
|
+
label: 'text-body-sm text-muted mb-0 shrink-0 font-medium',
|
|
1664
|
+
}"
|
|
1665
|
+
>
|
|
1666
|
+
<Select
|
|
1667
|
+
:model-value="sort"
|
|
1668
|
+
size="sm"
|
|
1669
|
+
:options="sortOptions"
|
|
1670
|
+
@update:model-value="onSort"
|
|
1671
|
+
/>
|
|
1672
|
+
</FieldWrapper>
|
|
1673
|
+
<FieldWrapper
|
|
1674
|
+
v-if="showColumnSelect"
|
|
1675
|
+
:label="t('grid.columns')"
|
|
1676
|
+
:classes="{
|
|
1677
|
+
root: 'flex items-center gap-2',
|
|
1678
|
+
label: 'text-body-sm text-muted mb-0 shrink-0 font-medium',
|
|
1679
|
+
}"
|
|
1680
|
+
>
|
|
1681
|
+
<Select
|
|
1682
|
+
:model-value="columnsChoice"
|
|
1683
|
+
size="sm"
|
|
1684
|
+
:options="columnOptions"
|
|
1685
|
+
@update:model-value="onColumns"
|
|
1686
|
+
/>
|
|
1687
|
+
</FieldWrapper>
|
|
1688
|
+
</div>
|
|
1689
|
+
</div>
|
|
1690
|
+
|
|
1691
|
+
<!-- Results. -->
|
|
1692
|
+
<div class="mt-6">
|
|
1693
|
+
<VisuallyHidden as="h2" :id="productsHeadingId">{{
|
|
1694
|
+
t('grid.products')
|
|
1695
|
+
}}</VisuallyHidden>
|
|
1696
|
+
|
|
1697
|
+
<!-- One region for the whole grid, always mounted and empty until there is
|
|
1698
|
+
something to say: a live region inserted with its message already in it is
|
|
1699
|
+
announced unreliably, and the cards deliberately do not announce for themselves
|
|
1700
|
+
(`:announce="false"` below). -->
|
|
1701
|
+
<VisuallyHidden as="p" role="status">{{ announcement }}</VisuallyHidden>
|
|
1702
|
+
|
|
1703
|
+
<ul
|
|
1704
|
+
v-if="showSkeletons"
|
|
1705
|
+
role="list"
|
|
1706
|
+
:aria-labelledby="productsHeadingId"
|
|
1707
|
+
:class="gridClass"
|
|
1708
|
+
aria-hidden="true"
|
|
1709
|
+
>
|
|
1710
|
+
<li v-for="index in skeletonCount" :key="index" class="flex flex-col gap-3">
|
|
1711
|
+
<Skeleton variant="media" ratio="4x5" />
|
|
1712
|
+
<Skeleton variant="text" :lines="2" />
|
|
1713
|
+
</li>
|
|
1714
|
+
</ul>
|
|
1715
|
+
|
|
1716
|
+
<ul
|
|
1717
|
+
v-else-if="cards.length > 0"
|
|
1718
|
+
role="list"
|
|
1719
|
+
:aria-labelledby="productsHeadingId"
|
|
1720
|
+
:aria-busy="updating ? 'true' : undefined"
|
|
1721
|
+
:class="[gridClass, updating ? UPDATING_PULSE : '']"
|
|
1722
|
+
:inert="updating || undefined"
|
|
1723
|
+
>
|
|
1724
|
+
<li v-for="entry in cards" :key="entry.item.handle">
|
|
1725
|
+
<!-- No quick add: the spec's tab order for this block runs straight from the
|
|
1726
|
+
cards to Load more, and a cart action is `product-detail`'s own. -->
|
|
1727
|
+
<ProductCard
|
|
1728
|
+
:product="entry.product"
|
|
1729
|
+
ratio="4x5"
|
|
1730
|
+
:heading-level="3"
|
|
1731
|
+
:classes="CARD_CLASSES"
|
|
1732
|
+
:quick-add="false"
|
|
1733
|
+
:revalidating="entry.revalidating"
|
|
1734
|
+
:announce="false"
|
|
1735
|
+
:link-as="entry.internal ? EldraRouterLink : undefined"
|
|
1736
|
+
/>
|
|
1737
|
+
</li>
|
|
1738
|
+
</ul>
|
|
1739
|
+
|
|
1740
|
+
<EmptyState
|
|
1741
|
+
v-else
|
|
1742
|
+
variant="noResults"
|
|
1743
|
+
:icon="AdjustmentsIcon"
|
|
1744
|
+
:title="emptyTitle"
|
|
1745
|
+
:text="emptyText"
|
|
1746
|
+
:heading-level="3"
|
|
1747
|
+
>
|
|
1748
|
+
<template #actions>
|
|
1749
|
+
<Button variant="primary" @click="onClearAll">
|
|
1750
|
+
{{ t('grid.clearFilters') }}
|
|
1751
|
+
</Button>
|
|
1752
|
+
</template>
|
|
1753
|
+
</EmptyState>
|
|
1754
|
+
</div>
|
|
1755
|
+
|
|
1756
|
+
<!-- Paging. -->
|
|
1757
|
+
<div v-if="showPaging" class="mt-12">
|
|
1758
|
+
<LoadMore
|
|
1759
|
+
v-if="isLoadMore"
|
|
1760
|
+
:shown="cards.length"
|
|
1761
|
+
:total="total"
|
|
1762
|
+
:noun="t('grid.productsNoun')"
|
|
1763
|
+
:pending="loadingMore"
|
|
1764
|
+
@load="onLoadMore"
|
|
1765
|
+
/>
|
|
1766
|
+
<Pagination
|
|
1767
|
+
v-else
|
|
1768
|
+
:page="currentPage"
|
|
1769
|
+
:total-pages="totalPages"
|
|
1770
|
+
:href-for-page="hrefForPage"
|
|
1771
|
+
:link-as="EldraRouterLink"
|
|
1772
|
+
:aria-label="t('grid.pagination')"
|
|
1773
|
+
/>
|
|
1774
|
+
</div>
|
|
1775
|
+
</div>
|
|
1776
|
+
</div>
|
|
1777
|
+
|
|
1778
|
+
<Drawer
|
|
1779
|
+
v-if="hasFilters"
|
|
1780
|
+
:id="drawerId"
|
|
1781
|
+
v-model="drawerOpen"
|
|
1782
|
+
side="right"
|
|
1783
|
+
:title="t('grid.filter')"
|
|
1784
|
+
width="min(24rem, 100%)"
|
|
1785
|
+
:classes="{ footer: 'grid grid-cols-[auto_1fr]' }"
|
|
1786
|
+
>
|
|
1787
|
+
<!-- `show-head false`: the Drawer's own title above is already this panel's heading, so
|
|
1788
|
+
it draws no second one of its own. The panel's own foot is hidden
|
|
1789
|
+
(`classes.foot: 'hidden'`): at 360 it used to sit `static` at the end of the
|
|
1790
|
+
scrolling groups, bottom off-screen in a short viewport, so a shopper had to scroll
|
|
1791
|
+
the whole filter list to find Clear all / Show N products. The Drawer's own `footer`
|
|
1792
|
+
slot below draws the foot instead — a true sibling of the scrolling `body`, outside
|
|
1793
|
+
its `overflow-y-auto`, so it stays pinned at the bottom of the dialog while the
|
|
1794
|
+
groups scroll under it (spec "Filter panel" → Anatomy item 14: "Drawer foot (drawer
|
|
1795
|
+
mode, supplied by the Drawer)"). `classes.footer` turns the Drawer's own flex foot
|
|
1796
|
+
into the spec's 2-column grid (`auto | 1fr`); its `border-t`/`bg-background` are the
|
|
1797
|
+
Drawer's own foot chrome already, which is exactly the top rule and background fill
|
|
1798
|
+
the spec asks for. -->
|
|
1799
|
+
<FilterPanel
|
|
1800
|
+
ref="drawerPanelEl"
|
|
1801
|
+
mode="drawer"
|
|
1802
|
+
:show-head="false"
|
|
1803
|
+
show-applied
|
|
1804
|
+
:facets="filterFacets"
|
|
1805
|
+
:model-value="pendingPanelSelection"
|
|
1806
|
+
:currency="money.currency.value"
|
|
1807
|
+
:result-count="pendingTotal"
|
|
1808
|
+
:id-prefix="`collection-grid-drawer-${uid}`"
|
|
1809
|
+
:classes="{ foot: 'hidden' }"
|
|
1810
|
+
@change="onPendingPanelChange"
|
|
1811
|
+
@clear="flushPendingDebounce"
|
|
1812
|
+
@apply="applyPending"
|
|
1813
|
+
@remove="onPendingPanelRemove"
|
|
1814
|
+
/>
|
|
1815
|
+
|
|
1816
|
+
<template #footer>
|
|
1817
|
+
<Button variant="outline" type="button" @click="onDrawerClearAll">
|
|
1818
|
+
{{ filterPanelMessages.filterPanelClearAll }}
|
|
1819
|
+
</Button>
|
|
1820
|
+
<Button variant="primary" type="button" block @click="applyPending">
|
|
1821
|
+
{{
|
|
1822
|
+
pendingTotal === null
|
|
1823
|
+
? filterPanelMessages.filterPanelShowProducts
|
|
1824
|
+
: filterPanelMessages.filterPanelShowResults(pendingTotal)
|
|
1825
|
+
}}
|
|
1826
|
+
</Button>
|
|
1827
|
+
</template>
|
|
1828
|
+
</Drawer>
|
|
1829
|
+
</template>
|
|
1830
|
+
</Container>
|
|
1831
|
+
</Section>
|
|
1832
|
+
</template>
|