@eldrajs/theme-cli 0.0.0 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +69 -0
- package/LICENSE +21 -0
- package/README.md +26 -1
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +203 -0
- package/dist/index.d.ts +174 -0
- package/dist/index.js +3 -0
- package/dist/validate-C6jB8_Oc.js +510 -0
- package/package.json +50 -2
- package/template/.eldra/block-types.d.ts +429 -0
- package/template/.eldra/manifest.json +9377 -0
- package/template/.eldra/previews.json +36 -0
- package/template/.github/workflows/eldra-deploy.yml +24 -0
- package/template/.gitlab-ci.yml +16 -0
- package/template/.storybook/eldra.ts +123 -0
- package/template/.storybook/i18n.ts +23 -0
- package/template/.storybook/main.ts +59 -0
- package/template/.storybook/nuxt-link-stub.ts +23 -0
- package/template/.storybook/preview.ts +52 -0
- package/template/.storybook/shims-vue.d.ts +10 -0
- package/template/.storybook/virtual-eldra.d.ts +27 -0
- package/template/README.md +288 -0
- package/template/app/app.vue +126 -0
- package/template/app/assets/main.css +404 -0
- package/template/app/components/EldraIcon.vue +66 -0
- package/template/app/components/EldraRouterLink.vue +62 -0
- package/template/app/components/ui/UiImage.stories.ts +30 -0
- package/template/app/components/ui/UiImage.vue +224 -0
- package/template/app/components/ui/__tests__/UiImage.spec.ts +292 -0
- package/template/app/composables/iconComponent.ts +84 -0
- package/template/app/composables/iconFetcher.ts +14 -0
- package/template/app/composables/useBlockData.ts +30 -0
- package/template/app/composables/useEditing.ts +31 -0
- package/template/app/composables/useEldraIcon.ts +46 -0
- package/template/app/composables/useRevalidating.ts +69 -0
- package/template/app/composables/useRichTextScrollRegions.ts +80 -0
- package/template/app/composables/useStorefront.ts +18 -0
- package/template/app/composables/useStorefrontFeedback.ts +49 -0
- package/template/app/composables/useUiId.ts +18 -0
- package/template/app/composables/useWishlist.ts +42 -0
- package/template/app/i18n.d.ts +28 -0
- package/template/app/icons.ts +185 -0
- package/template/app/pages/[...slug].vue +134 -0
- package/template/app/plugins/eldra-i18n.ts +98 -0
- package/template/app/plugins/eldra-storefront.ts +288 -0
- package/template/app/plugins/eldra-ui-messages.ts +112 -0
- package/template/app/storefront/cart.ts +245 -0
- package/template/app/storefront/categories.ts +283 -0
- package/template/app/storefront/collectionSelector.ts +60 -0
- package/template/app/storefront/commerce.ts +58 -0
- package/template/app/storefront/demo.ts +1313 -0
- package/template/app/storefront/facets.ts +476 -0
- package/template/app/storefront/feedback.ts +122 -0
- package/template/app/storefront/gateway.ts +2256 -0
- package/template/app/storefront/history.ts +233 -0
- package/template/app/storefront/money.ts +247 -0
- package/template/app/storefront/options.ts +71 -0
- package/template/app/storefront/prerender.ts +77 -0
- package/template/app/storefront/refresh.ts +222 -0
- package/template/app/storefront/toProductCard.ts +154 -0
- package/template/app/storefront/types.ts +815 -0
- package/template/app/storefront/volatile.ts +211 -0
- package/template/app/templates.ts +544 -0
- package/template/app/utils/classes.ts +40 -0
- package/template/app/utils/links.ts +70 -0
- package/template/app/utils/pageStructure.ts +77 -0
- package/template/app/utils/pageTitle.ts +37 -0
- package/template/app/virtual-eldra.d.ts +12 -0
- package/template/bitbucket-pipelines.yml +19 -0
- package/template/blocks/announcement-bar/Block.vue +203 -0
- package/template/blocks/announcement-bar/__tests__/Block.spec.ts +227 -0
- package/template/blocks/announcement-bar/block.json +45 -0
- package/template/blocks/announcement-bar/mock.json +7 -0
- package/template/blocks/announcement-bar/preview.png +0 -0
- package/template/blocks/article/Block.vue +317 -0
- package/template/blocks/article/__tests__/Block.spec.ts +229 -0
- package/template/blocks/article/block.json +148 -0
- package/template/blocks/article/mock.json +512 -0
- package/template/blocks/article/preview.json +16 -0
- package/template/blocks/article/preview.png +0 -0
- package/template/blocks/article-list/Block.vue +343 -0
- package/template/blocks/article-list/__tests__/Block.spec.ts +279 -0
- package/template/blocks/article-list/block.json +181 -0
- package/template/blocks/article-list/mock.json +68 -0
- package/template/blocks/article-list/preview.json +84 -0
- package/template/blocks/article-list/preview.png +0 -0
- package/template/blocks/breadcrumbs/Block.vue +278 -0
- package/template/blocks/breadcrumbs/__tests__/Block.spec.ts +461 -0
- package/template/blocks/breadcrumbs/block.json +89 -0
- package/template/blocks/breadcrumbs/mock.json +11 -0
- package/template/blocks/breadcrumbs/preview.json +3 -0
- package/template/blocks/breadcrumbs/preview.png +0 -0
- package/template/blocks/cart/Block.vue +372 -0
- package/template/blocks/cart/__tests__/Block.spec.ts +561 -0
- package/template/blocks/cart/__tests__/ShippingBar.spec.ts +78 -0
- package/template/blocks/cart/__tests__/Summary.spec.ts +245 -0
- package/template/blocks/cart/block.json +74 -0
- package/template/blocks/cart/mock.json +11 -0
- package/template/blocks/cart/parts/CartLines.vue +257 -0
- package/template/blocks/cart/parts/ShippingBar.vue +105 -0
- package/template/blocks/cart/parts/Summary.vue +291 -0
- package/template/blocks/cart/preview.png +0 -0
- package/template/blocks/collection-grid/Block.vue +1832 -0
- package/template/blocks/collection-grid/__tests__/Block.spec.ts +3037 -0
- package/template/blocks/collection-grid/__tests__/groups.spec.ts +731 -0
- package/template/blocks/collection-grid/block.json +187 -0
- package/template/blocks/collection-grid/mock.json +23 -0
- package/template/blocks/collection-grid/parts/groups.ts +861 -0
- package/template/blocks/collection-grid/preview.json +7 -0
- package/template/blocks/collection-grid/preview.png +0 -0
- package/template/blocks/collection-header/Block.vue +533 -0
- package/template/blocks/collection-header/__tests__/Block.spec.ts +381 -0
- package/template/blocks/collection-header/block.json +140 -0
- package/template/blocks/collection-header/mock.json +28 -0
- package/template/blocks/collection-header/preview.json +14 -0
- package/template/blocks/collection-header/preview.png +0 -0
- package/template/blocks/contact/Block.vue +621 -0
- package/template/blocks/contact/__tests__/Block.spec.ts +347 -0
- package/template/blocks/contact/block.json +174 -0
- package/template/blocks/contact/mock.json +28 -0
- package/template/blocks/contact/preview.json +9 -0
- package/template/blocks/contact/preview.png +0 -0
- package/template/blocks/cta/Block.vue +383 -0
- package/template/blocks/cta/__tests__/Block.spec.ts +309 -0
- package/template/blocks/cta/block.json +86 -0
- package/template/blocks/cta/mock.json +10 -0
- package/template/blocks/cta/preview.json +9 -0
- package/template/blocks/cta/preview.png +0 -0
- package/template/blocks/faq/Block.vue +254 -0
- package/template/blocks/faq/__tests__/Block.spec.ts +312 -0
- package/template/blocks/faq/block.json +113 -0
- package/template/blocks/faq/mock.json +115 -0
- package/template/blocks/faq/preview.png +0 -0
- package/template/blocks/feature-grid/Block.vue +241 -0
- package/template/blocks/feature-grid/__tests__/Block.spec.ts +311 -0
- package/template/blocks/feature-grid/block.json +106 -0
- package/template/blocks/feature-grid/mock.json +29 -0
- package/template/blocks/feature-grid/preview.json +45 -0
- package/template/blocks/feature-grid/preview.png +0 -0
- package/template/blocks/footer/Block.vue +652 -0
- package/template/blocks/footer/__tests__/Block.spec.ts +700 -0
- package/template/blocks/footer/block.json +240 -0
- package/template/blocks/footer/mock.json +161 -0
- package/template/blocks/footer/preview.png +0 -0
- package/template/blocks/gallery/Block.vue +416 -0
- package/template/blocks/gallery/__tests__/Block.spec.ts +289 -0
- package/template/blocks/gallery/block.json +87 -0
- package/template/blocks/gallery/mock.json +16 -0
- package/template/blocks/gallery/preview.json +64 -0
- package/template/blocks/gallery/preview.png +0 -0
- package/template/blocks/hero/Block.vue +378 -0
- package/template/blocks/hero/__tests__/Block.spec.ts +324 -0
- package/template/blocks/hero/block.json +146 -0
- package/template/blocks/hero/mock.json +11 -0
- package/template/blocks/hero/preview.json +55 -0
- package/template/blocks/hero/preview.png +0 -0
- package/template/blocks/image/Block.vue +232 -0
- package/template/blocks/image/__tests__/Block.spec.ts +224 -0
- package/template/blocks/image/block.json +67 -0
- package/template/blocks/image/mock.json +7 -0
- package/template/blocks/image/preview.json +9 -0
- package/template/blocks/image/preview.png +0 -0
- package/template/blocks/logo-cloud/Block.vue +206 -0
- package/template/blocks/logo-cloud/__tests__/Block.spec.ts +210 -0
- package/template/blocks/logo-cloud/block.json +79 -0
- package/template/blocks/logo-cloud/mock.json +15 -0
- package/template/blocks/logo-cloud/preview.json +92 -0
- package/template/blocks/logo-cloud/preview.png +0 -0
- package/template/blocks/navigation/Block.vue +1348 -0
- package/template/blocks/navigation/__tests__/Block.spec.ts +2030 -0
- package/template/blocks/navigation/block.json +167 -0
- package/template/blocks/navigation/mock.json +191 -0
- package/template/blocks/navigation/preview.png +0 -0
- package/template/blocks/navigation/useMegaMenuKeys.ts +276 -0
- package/template/blocks/newsletter/Block.vue +399 -0
- package/template/blocks/newsletter/__tests__/Block.spec.ts +365 -0
- package/template/blocks/newsletter/block.json +105 -0
- package/template/blocks/newsletter/mock.json +31 -0
- package/template/blocks/newsletter/preview.png +0 -0
- package/template/blocks/order-status/Block.vue +754 -0
- package/template/blocks/order-status/__tests__/Block.spec.ts +515 -0
- package/template/blocks/order-status/block.json +138 -0
- package/template/blocks/order-status/mock.json +19 -0
- package/template/blocks/order-status/preview.png +0 -0
- package/template/blocks/pricing-table/Block.vue +297 -0
- package/template/blocks/pricing-table/__tests__/Block.spec.ts +357 -0
- package/template/blocks/pricing-table/block.json +155 -0
- package/template/blocks/pricing-table/mock.json +47 -0
- package/template/blocks/pricing-table/preview.png +0 -0
- package/template/blocks/product-carousel/Block.vue +459 -0
- package/template/blocks/product-carousel/__tests__/Block.spec.ts +957 -0
- package/template/blocks/product-carousel/block.json +71 -0
- package/template/blocks/product-carousel/mock.json +9 -0
- package/template/blocks/product-carousel/preview.json +7 -0
- package/template/blocks/product-carousel/preview.png +0 -0
- package/template/blocks/product-detail/Block.vue +886 -0
- package/template/blocks/product-detail/__tests__/Block.spec.ts +1495 -0
- package/template/blocks/product-detail/__tests__/stock.spec.ts +119 -0
- package/template/blocks/product-detail/block.json +155 -0
- package/template/blocks/product-detail/mock.json +113 -0
- package/template/blocks/product-detail/parts/Gallery.vue +181 -0
- package/template/blocks/product-detail/parts/StickyBuyBar.vue +99 -0
- package/template/blocks/product-detail/preview.png +0 -0
- package/template/blocks/product-detail/stock.ts +150 -0
- package/template/blocks/quote/Block.vue +206 -0
- package/template/blocks/quote/__tests__/Block.spec.ts +265 -0
- package/template/blocks/quote/block.json +76 -0
- package/template/blocks/quote/mock.json +9 -0
- package/template/blocks/quote/preview.json +16 -0
- package/template/blocks/quote/preview.png +0 -0
- package/template/blocks/rich-text/Block.vue +143 -0
- package/template/blocks/rich-text/__tests__/Block.spec.ts +191 -0
- package/template/blocks/rich-text/block.json +57 -0
- package/template/blocks/rich-text/mock.json +87 -0
- package/template/blocks/rich-text/preview.png +0 -0
- package/template/blocks/search/Block.vue +589 -0
- package/template/blocks/search/PopularChips.vue +40 -0
- package/template/blocks/search/TypeSection.vue +148 -0
- package/template/blocks/search/__tests__/Block.spec.ts +718 -0
- package/template/blocks/search/__tests__/results.spec.ts +166 -0
- package/template/blocks/search/block.json +102 -0
- package/template/blocks/search/mock.json +18 -0
- package/template/blocks/search/preview.png +0 -0
- package/template/blocks/search/results.ts +85 -0
- package/template/blocks/split-content/Block.vue +195 -0
- package/template/blocks/split-content/__tests__/Block.spec.ts +225 -0
- package/template/blocks/split-content/block.json +70 -0
- package/template/blocks/split-content/mock.json +45 -0
- package/template/blocks/split-content/preview.json +58 -0
- package/template/blocks/split-content/preview.png +0 -0
- package/template/blocks/stats/Block.vue +159 -0
- package/template/blocks/stats/__tests__/Block.spec.ts +194 -0
- package/template/blocks/stats/block.json +73 -0
- package/template/blocks/stats/mock.json +12 -0
- package/template/blocks/stats/preview.png +0 -0
- package/template/blocks/tabs/Block.vue +278 -0
- package/template/blocks/tabs/__tests__/Block.spec.ts +303 -0
- package/template/blocks/tabs/block.json +97 -0
- package/template/blocks/tabs/mock.json +129 -0
- package/template/blocks/tabs/preview.json +153 -0
- package/template/blocks/tabs/preview.png +0 -0
- package/template/blocks/team/Block.vue +288 -0
- package/template/blocks/team/__tests__/Block.spec.ts +221 -0
- package/template/blocks/team/block.json +125 -0
- package/template/blocks/team/mock.json +39 -0
- package/template/blocks/team/preview.json +62 -0
- package/template/blocks/team/preview.png +0 -0
- package/template/blocks/testimonials/Block.vue +408 -0
- package/template/blocks/testimonials/__tests__/Block.spec.ts +319 -0
- package/template/blocks/testimonials/block.json +121 -0
- package/template/blocks/testimonials/mock.json +46 -0
- package/template/blocks/testimonials/preview.json +68 -0
- package/template/blocks/testimonials/preview.png +0 -0
- package/template/blocks/timeline/Block.vue +274 -0
- package/template/blocks/timeline/__tests__/Block.spec.ts +310 -0
- package/template/blocks/timeline/block.json +98 -0
- package/template/blocks/timeline/mock.json +27 -0
- package/template/blocks/timeline/preview.png +0 -0
- package/template/blocks/trust-strip/Block.vue +330 -0
- package/template/blocks/trust-strip/__tests__/Block.spec.ts +290 -0
- package/template/blocks/trust-strip/block.json +117 -0
- package/template/blocks/trust-strip/mock.json +37 -0
- package/template/blocks/trust-strip/preview.png +0 -0
- package/template/blocks/video-embed/Block.vue +354 -0
- package/template/blocks/video-embed/__tests__/Block.spec.ts +219 -0
- package/template/blocks/video-embed/__tests__/embed.spec.ts +76 -0
- package/template/blocks/video-embed/block.json +94 -0
- package/template/blocks/video-embed/embed.ts +84 -0
- package/template/blocks/video-embed/mock.json +13 -0
- package/template/blocks/video-embed/preview.json +9 -0
- package/template/blocks/video-embed/preview.png +0 -0
- package/template/blocks/wishlist/Block.vue +367 -0
- package/template/blocks/wishlist/__tests__/Block.spec.ts +508 -0
- package/template/blocks/wishlist/block.json +42 -0
- package/template/blocks/wishlist/mock.json +9 -0
- package/template/blocks/wishlist/preview.png +0 -0
- package/template/i18n/en-US.json +602 -0
- package/template/i18n/is-IS.json +602 -0
- package/template/nuxt.config.ts +148 -0
- package/template/package.json +55 -0
- package/template/pages/article.page.json +731 -0
- package/template/pages/cart.page.json +85 -0
- package/template/pages/category.page.json +133 -0
- package/template/pages/collection.page.json +194 -0
- package/template/pages/home.page.json +353 -0
- package/template/pages/product.page.json +323 -0
- package/template/pages/products.page.json +144 -0
- package/template/pages/search.page.json +83 -0
- package/template/pages/wishlist.page.json +88 -0
- package/template/public/demo/article-cover.svg +1 -0
- package/template/public/demo/article-figure.svg +1 -0
- package/template/public/demo/avatar-1.svg +3 -0
- package/template/public/demo/avatar-2.svg +3 -0
- package/template/public/demo/avatar-3.svg +3 -0
- package/template/public/demo/avatar-4.svg +3 -0
- package/template/public/demo/avatar-5.svg +3 -0
- package/template/public/demo/avatar-6.svg +3 -0
- package/template/public/demo/avatar-7.svg +3 -0
- package/template/public/demo/avatar-8.svg +3 -0
- package/template/public/demo/collection-1.svg +1 -0
- package/template/public/demo/collection-2.svg +1 -0
- package/template/public/demo/cta-split.svg +1 -0
- package/template/public/demo/feature-1.svg +1 -0
- package/template/public/demo/feature-2.svg +1 -0
- package/template/public/demo/feature-3.svg +1 -0
- package/template/public/demo/feature-4.svg +1 -0
- package/template/public/demo/gallery-1.svg +1 -0
- package/template/public/demo/gallery-2.svg +1 -0
- package/template/public/demo/gallery-3.svg +1 -0
- package/template/public/demo/gallery-4.svg +1 -0
- package/template/public/demo/gallery-5.svg +1 -0
- package/template/public/demo/gallery-6.svg +1 -0
- package/template/public/demo/gallery-7.svg +1 -0
- package/template/public/demo/gallery-8.svg +1 -0
- package/template/public/demo/hero-slide-1.svg +1 -0
- package/template/public/demo/hero-slide-2.svg +1 -0
- package/template/public/demo/hero-slide-3.svg +1 -0
- package/template/public/demo/hero-slide-4.svg +1 -0
- package/template/public/demo/hero-wide.svg +1 -0
- package/template/public/demo/hero.svg +1 -0
- package/template/public/demo/logo-1.svg +4 -0
- package/template/public/demo/logo-2.svg +4 -0
- package/template/public/demo/logo-3.svg +4 -0
- package/template/public/demo/logo-4.svg +4 -0
- package/template/public/demo/logo-5.svg +4 -0
- package/template/public/demo/logo-6.svg +4 -0
- package/template/public/demo/logo-7.svg +4 -0
- package/template/public/demo/logo-8.svg +4 -0
- package/template/public/demo/logo.svg +3 -0
- package/template/public/demo/map.svg +1 -0
- package/template/public/demo/poster.svg +1 -0
- package/template/public/demo/product-1.svg +4 -0
- package/template/public/demo/product-10.svg +4 -0
- package/template/public/demo/product-11.svg +4 -0
- package/template/public/demo/product-12.svg +4 -0
- package/template/public/demo/product-2.svg +4 -0
- package/template/public/demo/product-3.svg +4 -0
- package/template/public/demo/product-4.svg +4 -0
- package/template/public/demo/product-5.svg +4 -0
- package/template/public/demo/product-6.svg +4 -0
- package/template/public/demo/product-7.svg +4 -0
- package/template/public/demo/product-8.svg +4 -0
- package/template/public/demo/product-9.svg +4 -0
- package/template/public/demo/product-square-1.svg +4 -0
- package/template/public/demo/product-square-2.svg +4 -0
- package/template/public/demo/product-square-3.svg +4 -0
- package/template/public/demo/product-square-4.svg +4 -0
- package/template/public/demo/product-square-5.svg +4 -0
- package/template/public/demo/product-square-6.svg +4 -0
- package/template/public/demo/quote-portrait.svg +4 -0
- package/template/public/demo/split-1.svg +1 -0
- package/template/public/demo/split-2.svg +1 -0
- package/template/public/demo/split-3.svg +1 -0
- package/template/public/demo/split-4.svg +1 -0
- package/template/public/demo/team-1.svg +4 -0
- package/template/public/demo/team-2.svg +4 -0
- package/template/public/demo/team-3.svg +4 -0
- package/template/public/demo/team-4.svg +4 -0
- package/template/scripts/demo-images.mjs +393 -0
- package/template/scripts/generate-stories.mjs +156 -0
- package/template/scripts/previewHash.mjs +125 -0
- package/template/scripts/previews.mjs +149 -0
- package/template/stories/generated/announcement-bar.stories.ts +44 -0
- package/template/stories/generated/article-list.stories.ts +87 -0
- package/template/stories/generated/article.stories.ts +27 -0
- package/template/stories/generated/breadcrumbs.stories.ts +39 -0
- package/template/stories/generated/cart.stories.ts +38 -0
- package/template/stories/generated/collection-grid.stories.ts +117 -0
- package/template/stories/generated/collection-header.stories.ts +51 -0
- package/template/stories/generated/contact.stories.ts +45 -0
- package/template/stories/generated/cta.stories.ts +51 -0
- package/template/stories/generated/faq.stories.ts +56 -0
- package/template/stories/generated/feature-grid.stories.ts +69 -0
- package/template/stories/generated/footer.stories.ts +50 -0
- package/template/stories/generated/gallery.stories.ts +81 -0
- package/template/stories/generated/hero.stories.ts +75 -0
- package/template/stories/generated/image.stories.ts +99 -0
- package/template/stories/generated/logo-cloud.stories.ts +57 -0
- package/template/stories/generated/navigation.stories.ts +62 -0
- package/template/stories/generated/newsletter.stories.ts +68 -0
- package/template/stories/generated/order-status.stories.ts +32 -0
- package/template/stories/generated/pricing-table.stories.ts +44 -0
- package/template/stories/generated/product-carousel.stories.ts +75 -0
- package/template/stories/generated/product-detail.stories.ts +62 -0
- package/template/stories/generated/quote.stories.ts +69 -0
- package/template/stories/generated/rich-text.stories.ts +50 -0
- package/template/stories/generated/search.stories.ts +56 -0
- package/template/stories/generated/split-content.stories.ts +39 -0
- package/template/stories/generated/stats.stories.ts +68 -0
- package/template/stories/generated/tabs.stories.ts +45 -0
- package/template/stories/generated/team.stories.ts +45 -0
- package/template/stories/generated/testimonials.stories.ts +69 -0
- package/template/stories/generated/timeline.stories.ts +80 -0
- package/template/stories/generated/trust-strip.stories.ts +62 -0
- package/template/stories/generated/video-embed.stories.ts +63 -0
- package/template/stories/generated/wishlist.stories.ts +26 -0
- package/template/stories/pages/article.stories.ts +51 -0
- package/template/stories/pages/cart.stories.ts +56 -0
- package/template/stories/pages/category.stories.ts +56 -0
- package/template/stories/pages/collection.stories.ts +51 -0
- package/template/stories/pages/home.stories.ts +51 -0
- package/template/stories/pages/product.stories.ts +47 -0
- package/template/stories/pages/products.stories.ts +58 -0
- package/template/stories/pages/search.stories.ts +54 -0
- package/template/stories/pages/wishlist.stories.ts +53 -0
- package/template/stories/support/pageBlocks.ts +115 -0
- package/template/test/blocksEmptyData.spec.ts +52 -0
- package/template/test/carouselKeyboard.spec.ts +272 -0
- package/template/test/carouselRing.browser.spec.ts +193 -0
- package/template/test/carouselSlideWidth.browser.spec.ts +102 -0
- package/template/test/cartDrawer.spec.ts +295 -0
- package/template/test/cartToast.spec.ts +86 -0
- package/template/test/countPill.browser.spec.ts +196 -0
- package/template/test/demoImages.spec.ts +140 -0
- package/template/test/deps.spec.ts +102 -0
- package/template/test/eldraIcon.spec.ts +58 -0
- package/template/test/framing.spec.ts +76 -0
- package/template/test/i18n.spec.ts +200 -0
- package/template/test/iconComponent.spec.ts +91 -0
- package/template/test/inlineEditable.spec.ts +334 -0
- package/template/test/localePrefix.spec.ts +342 -0
- package/template/test/mainCss.spec.ts +107 -0
- package/template/test/mockGatewayContract.spec.ts +122 -0
- package/template/test/mocks/blocks.ts +20 -0
- package/template/test/mocks/breakpoints.ts +7 -0
- package/template/test/mocks/manifest.ts +11 -0
- package/template/test/moneyFormatting.spec.ts +89 -0
- package/template/test/pageTitle.spec.ts +49 -0
- package/template/test/pages/article.spec.ts +231 -0
- package/template/test/pages/category.spec.ts +185 -0
- package/template/test/pages/collection.spec.ts +396 -0
- package/template/test/pages/home.spec.ts +295 -0
- package/template/test/pages/hydration.spec.ts +557 -0
- package/template/test/pages/product.spec.ts +396 -0
- package/template/test/pages/seededPages.spec.ts +190 -0
- package/template/test/pages/ssr.spec.ts +393 -0
- package/template/test/prerenderCommerce.spec.ts +134 -0
- package/template/test/prerenderFailure.spec.ts +130 -0
- package/template/test/prerenderRefresh.browser.spec.ts +1431 -0
- package/template/test/previewsFresh.spec.ts +56 -0
- package/template/test/richText.spec.ts +161 -0
- package/template/test/richTextTypography.spec.ts +182 -0
- package/template/test/setup.ts +21 -0
- package/template/test/slugPage.spec.ts +244 -0
- package/template/test/slugPageTemplate.spec.ts +194 -0
- package/template/test/starter.spec.ts +1416 -0
- package/template/test/storefront/cart.spec.ts +404 -0
- package/template/test/storefront/categories.spec.ts +235 -0
- package/template/test/storefront/collectionSelector.spec.ts +74 -0
- package/template/test/storefront/demo.spec.ts +555 -0
- package/template/test/storefront/facets.spec.ts +425 -0
- package/template/test/storefront/feedback.spec.ts +97 -0
- package/template/test/storefront/gateway.spec.ts +2673 -0
- package/template/test/storefront/gatewayCart.spec.ts +289 -0
- package/template/test/storefront/gatewayPrerender.spec.ts +1037 -0
- package/template/test/storefront/history.spec.ts +341 -0
- package/template/test/storefront/money.spec.ts +171 -0
- package/template/test/storefront/toProductCard.spec.ts +138 -0
- package/template/test/storefront/volatile.spec.ts +284 -0
- package/template/test/support/axe.ts +14 -0
- package/template/test/support/dialog.ts +51 -0
- package/template/test/support/hydrate.ts +118 -0
- package/template/test/support/i18nText.ts +11 -0
- package/template/test/support/mockGateway.ts +1017 -0
- package/template/test/support/mountBlock.ts +194 -0
- package/template/test/support/mountPage.spec.ts +72 -0
- package/template/test/support/mountPage.ts +254 -0
- package/template/test/support/mountProbe.client.ts +69 -0
- package/template/test/support/renderSsr.ts +97 -0
- package/template/test/support/staticServer.ts +96 -0
- package/template/test/themeIcons.spec.ts +140 -0
- package/template/test/toastAnnouncement.spec.ts +133 -0
- package/template/test/tokens.spec.ts +102 -0
- package/template/test/uiMessagesPlugin.spec.ts +104 -0
- package/template/test/useBlockData.spec.ts +46 -0
- package/template/test/useEditing.spec.ts +54 -0
- package/template/test/useEldraIcon.spec.ts +126 -0
- package/template/test/useUiId.spec.ts +40 -0
- package/template/tokens.json +149 -0
- package/template/tsconfig.json +3 -0
- package/template/tsconfig.storybook.json +17 -0
- package/template/vitest-axe.d.ts +13 -0
- package/template/vitest.config.ts +44 -0
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { toSearchBarResults } from '../results';
|
|
3
|
+
import { formatMoney } from '../../../app/storefront/money';
|
|
4
|
+
import type {
|
|
5
|
+
StorefrontProductListItem,
|
|
6
|
+
StorefrontSearchResponse,
|
|
7
|
+
} from '../../../app/storefront/types';
|
|
8
|
+
|
|
9
|
+
function product(overrides: Partial<StorefrontProductListItem> = {}): StorefrontProductListItem {
|
|
10
|
+
return {
|
|
11
|
+
handle: 'linen-napkins',
|
|
12
|
+
title: 'Linen napkins, set of 4',
|
|
13
|
+
url: '/products/linen-napkins',
|
|
14
|
+
featuredImage: { src: '/demo/product-1.svg', alt: 'Linen napkins' },
|
|
15
|
+
price: { amount: 40, compareAt: null },
|
|
16
|
+
stock: 'in',
|
|
17
|
+
available: true,
|
|
18
|
+
productId: 'linen-napkins',
|
|
19
|
+
...overrides,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function response(overrides: Partial<StorefrontSearchResponse> = {}): StorefrontSearchResponse {
|
|
24
|
+
return {
|
|
25
|
+
query: 'linen',
|
|
26
|
+
total: 17,
|
|
27
|
+
products: [],
|
|
28
|
+
articles: [],
|
|
29
|
+
pages: [],
|
|
30
|
+
suggestion: null,
|
|
31
|
+
...overrides,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* What `useMoney().format` hands the mapper on a real page: the store's own currency, resolved in
|
|
37
|
+
* the block's `setup()`. The mapper is pure and takes the formatter, so this spec says which
|
|
38
|
+
* currency it is formatting in rather than inheriting one from a module-level default.
|
|
39
|
+
*/
|
|
40
|
+
const formatPrice = (amount: number): string => formatMoney(amount, 'USD');
|
|
41
|
+
|
|
42
|
+
describe('toSearchBarResults', () => {
|
|
43
|
+
/**
|
|
44
|
+
* `undefined`, not an empty shape. `SearchBar` reads an absent `results` as "nothing yet" (no
|
|
45
|
+
* panel, and its loading view past 300ms) and a `{ total: 0 }` shape as "nothing found" — so
|
|
46
|
+
* answering the no-response case with the latter is what made the panel say "No results" for the
|
|
47
|
+
* whole time the request for the query was in flight.
|
|
48
|
+
*/
|
|
49
|
+
it('answers undefined — not an empty, zero-total shape — for a null response', () => {
|
|
50
|
+
expect(toSearchBarResults(null, 3, formatPrice)).toBeUndefined();
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it('maps products, articles and pages into the SearchBar contract, carrying the backend total', () => {
|
|
54
|
+
const result = toSearchBarResults(
|
|
55
|
+
response({
|
|
56
|
+
total: 3,
|
|
57
|
+
products: [product()],
|
|
58
|
+
articles: [
|
|
59
|
+
{
|
|
60
|
+
title: 'How to wash and store linen',
|
|
61
|
+
href: '/journal/how-to-wash-and-store-linen',
|
|
62
|
+
category: 'Care guide',
|
|
63
|
+
readingTime: '4 min read',
|
|
64
|
+
image: { src: '/demo/product-1.svg', alt: 'Linen' },
|
|
65
|
+
},
|
|
66
|
+
],
|
|
67
|
+
pages: [
|
|
68
|
+
{
|
|
69
|
+
title: 'Materials',
|
|
70
|
+
href: '/pages/materials',
|
|
71
|
+
path: 'northwindgoods.com/pages/materials',
|
|
72
|
+
snippet: 'Where our linen, wool and stoneware come from.',
|
|
73
|
+
},
|
|
74
|
+
],
|
|
75
|
+
}),
|
|
76
|
+
3,
|
|
77
|
+
formatPrice
|
|
78
|
+
);
|
|
79
|
+
|
|
80
|
+
expect(result.total).toBe(3);
|
|
81
|
+
expect(result.collections).toEqual([]);
|
|
82
|
+
expect(result.products).toEqual([
|
|
83
|
+
{
|
|
84
|
+
id: 'linen-napkins',
|
|
85
|
+
title: 'Linen napkins, set of 4',
|
|
86
|
+
href: '/products/linen-napkins',
|
|
87
|
+
price: '$40.00',
|
|
88
|
+
image: '/demo/product-1.svg',
|
|
89
|
+
imageAlt: 'Linen napkins',
|
|
90
|
+
},
|
|
91
|
+
]);
|
|
92
|
+
expect(result.articles).toEqual([
|
|
93
|
+
{
|
|
94
|
+
id: 'article-0',
|
|
95
|
+
title: 'How to wash and store linen',
|
|
96
|
+
href: '/journal/how-to-wash-and-store-linen',
|
|
97
|
+
image: '/demo/product-1.svg',
|
|
98
|
+
imageAlt: 'Linen',
|
|
99
|
+
},
|
|
100
|
+
]);
|
|
101
|
+
expect(result.pages).toEqual([{ id: 'page-0', title: 'Materials', href: '/pages/materials' }]);
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
it('caps each group at suggestionsPerGroup', () => {
|
|
105
|
+
const products = Array.from({ length: 6 }, (_, i) =>
|
|
106
|
+
product({ handle: `product-${i}`, productId: `product-${i}` })
|
|
107
|
+
);
|
|
108
|
+
const articles = Array.from({ length: 6 }, (_, i) => ({
|
|
109
|
+
title: `Story ${i}`,
|
|
110
|
+
href: `/journal/story-${i}`,
|
|
111
|
+
category: 'Journal',
|
|
112
|
+
readingTime: '4 min read',
|
|
113
|
+
}));
|
|
114
|
+
const pages = Array.from({ length: 6 }, (_, i) => ({
|
|
115
|
+
title: `Page ${i}`,
|
|
116
|
+
href: `/pages/page-${i}`,
|
|
117
|
+
path: `northwindgoods.com/pages/page-${i}`,
|
|
118
|
+
snippet: 'A page.',
|
|
119
|
+
}));
|
|
120
|
+
|
|
121
|
+
const result = toSearchBarResults(response({ products, articles, pages }), 2, formatPrice);
|
|
122
|
+
expect(result.products).toHaveLength(2);
|
|
123
|
+
expect(result.articles).toHaveLength(2);
|
|
124
|
+
expect(result.pages).toHaveLength(2);
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
it('ranks sold-out products last, before the suggestionsPerGroup cap is applied', () => {
|
|
128
|
+
const soldOut = product({
|
|
129
|
+
handle: 'sold-out',
|
|
130
|
+
productId: 'sold-out',
|
|
131
|
+
stock: 'out',
|
|
132
|
+
available: false,
|
|
133
|
+
});
|
|
134
|
+
const inStockA = product({ handle: 'in-stock-a', productId: 'in-stock-a' });
|
|
135
|
+
const inStockB = product({ handle: 'in-stock-b', productId: 'in-stock-b' });
|
|
136
|
+
|
|
137
|
+
const result = toSearchBarResults(
|
|
138
|
+
response({ products: [soldOut, inStockA, inStockB] }),
|
|
139
|
+
3,
|
|
140
|
+
formatPrice
|
|
141
|
+
);
|
|
142
|
+
expect(result.products.map((item) => item.id)).toEqual([
|
|
143
|
+
'in-stock-a',
|
|
144
|
+
'in-stock-b',
|
|
145
|
+
'sold-out',
|
|
146
|
+
]);
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
it('drops a sold-out product from the cap entirely when enough in-stock ones fill it', () => {
|
|
150
|
+
const soldOut = product({
|
|
151
|
+
handle: 'sold-out',
|
|
152
|
+
productId: 'sold-out',
|
|
153
|
+
stock: 'out',
|
|
154
|
+
available: false,
|
|
155
|
+
});
|
|
156
|
+
const inStockA = product({ handle: 'in-stock-a', productId: 'in-stock-a' });
|
|
157
|
+
const inStockB = product({ handle: 'in-stock-b', productId: 'in-stock-b' });
|
|
158
|
+
|
|
159
|
+
const result = toSearchBarResults(
|
|
160
|
+
response({ products: [soldOut, inStockA, inStockB] }),
|
|
161
|
+
2,
|
|
162
|
+
formatPrice
|
|
163
|
+
);
|
|
164
|
+
expect(result.products.map((item) => item.id)).toEqual(['in-stock-a', 'in-stock-b']);
|
|
165
|
+
});
|
|
166
|
+
});
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
{
|
|
2
|
+
"apiId": "search",
|
|
3
|
+
"name": "Search",
|
|
4
|
+
"description": "The search results page: a field with live suggestions, a results page mixing products and content, and a helpful no-results state.",
|
|
5
|
+
"icon": "search",
|
|
6
|
+
"category": "commerce",
|
|
7
|
+
"version": 1,
|
|
8
|
+
"fields": [
|
|
9
|
+
{
|
|
10
|
+
"fieldId": "variant",
|
|
11
|
+
"name": "Variant",
|
|
12
|
+
"type": "select",
|
|
13
|
+
"helpText": "results-page is the full page. field-only is just the field and its panel, for the header search overlay and the 404 page.",
|
|
14
|
+
"metadata": { "options": ["results-page", "field-only"] },
|
|
15
|
+
"validators": { "required": true }
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
"fieldId": "heading",
|
|
19
|
+
"name": "Heading",
|
|
20
|
+
"type": "string",
|
|
21
|
+
"isTitle": true,
|
|
22
|
+
"localized": true,
|
|
23
|
+
"helpText": "Optional, e.g. \"Search the shop\". Use {query} for the shopper's search text. Hidden in field-only."
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
"fieldId": "placeholder",
|
|
27
|
+
"name": "Placeholder",
|
|
28
|
+
"type": "string",
|
|
29
|
+
"localized": true,
|
|
30
|
+
"helpText": "The field's placeholder text."
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
"fieldId": "types",
|
|
34
|
+
"name": "Result types",
|
|
35
|
+
"type": "list",
|
|
36
|
+
"helpText": "Which result groups show, in what order. Products, Journal and Pages by default.",
|
|
37
|
+
"metadata": {
|
|
38
|
+
"item": {
|
|
39
|
+
"fieldId": "item",
|
|
40
|
+
"name": "Type",
|
|
41
|
+
"type": "composite",
|
|
42
|
+
"metadata": {
|
|
43
|
+
"fields": [
|
|
44
|
+
{
|
|
45
|
+
"fieldId": "type",
|
|
46
|
+
"name": "Type",
|
|
47
|
+
"type": "select",
|
|
48
|
+
"metadata": { "options": ["products", "journal", "pages"] },
|
|
49
|
+
"validators": { "required": true }
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
"fieldId": "label",
|
|
53
|
+
"name": "Label",
|
|
54
|
+
"type": "string",
|
|
55
|
+
"localized": true,
|
|
56
|
+
"helpText": "Overrides the group name."
|
|
57
|
+
}
|
|
58
|
+
]
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
"fieldId": "suggestionsPerGroup",
|
|
65
|
+
"name": "Suggestions per group",
|
|
66
|
+
"type": "select",
|
|
67
|
+
"helpText": "3 is the default.",
|
|
68
|
+
"metadata": { "options": ["2", "3", "4"] }
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
"fieldId": "popularSearches",
|
|
72
|
+
"name": "Popular searches",
|
|
73
|
+
"type": "list",
|
|
74
|
+
"helpText": "Chips shown when the field is focused but empty, and on the no-results page.",
|
|
75
|
+
"metadata": {
|
|
76
|
+
"item": {
|
|
77
|
+
"fieldId": "item",
|
|
78
|
+
"name": "Popular search",
|
|
79
|
+
"type": "composite",
|
|
80
|
+
"metadata": {
|
|
81
|
+
"fields": [
|
|
82
|
+
{
|
|
83
|
+
"fieldId": "label",
|
|
84
|
+
"name": "Label",
|
|
85
|
+
"type": "string",
|
|
86
|
+
"localized": true,
|
|
87
|
+
"helpText": "e.g. \"Merino\".",
|
|
88
|
+
"validators": { "required": true }
|
|
89
|
+
}
|
|
90
|
+
]
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
"fieldId": "noResultsCollection",
|
|
97
|
+
"name": "No-results collection",
|
|
98
|
+
"type": "string",
|
|
99
|
+
"helpText": "Collection handle shown under \"Customers love these\"."
|
|
100
|
+
}
|
|
101
|
+
]
|
|
102
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"variant": "results-page",
|
|
3
|
+
"heading": "Results for “{query}”",
|
|
4
|
+
"placeholder": "Search knitwear, ceramics, journal…",
|
|
5
|
+
"types": [
|
|
6
|
+
{ "type": "products", "label": "Products" },
|
|
7
|
+
{ "type": "journal", "label": "Journal" },
|
|
8
|
+
{ "type": "pages", "label": "Pages" }
|
|
9
|
+
],
|
|
10
|
+
"suggestionsPerGroup": "3",
|
|
11
|
+
"popularSearches": [
|
|
12
|
+
{ "label": "Merino" },
|
|
13
|
+
{ "label": "Mugs" },
|
|
14
|
+
{ "label": "Tea towels" },
|
|
15
|
+
{ "label": "Gift cards" }
|
|
16
|
+
],
|
|
17
|
+
"noResultsCollection": "best-sellers"
|
|
18
|
+
}
|
|
Binary file
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import type { SearchResultItem, SearchResults } from '@eldrajs/ui';
|
|
2
|
+
import type { StorefrontSearchProduct, StorefrontSearchResponse } from '../../app/storefront/types';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Spec "Search results page" → Do/Don't: "Don't show sold-out products at the top of suggestions.
|
|
6
|
+
* Rank them last." A stable sort (available/in-stock first, sold out last) run before the
|
|
7
|
+
* `suggestionsPerGroup` cap below, so a sold-out item only displaces an in-stock one when there
|
|
8
|
+
* genuinely aren't enough of the latter to fill the group.
|
|
9
|
+
*/
|
|
10
|
+
function isSoldOut(product: StorefrontSearchProduct): boolean {
|
|
11
|
+
return product.available === false || product.stock === 'out';
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function rankProducts(products: StorefrontSearchProduct[]): StorefrontSearchProduct[] {
|
|
15
|
+
const inStock = products.filter((product) => !isSoldOut(product));
|
|
16
|
+
const soldOut = products.filter(isSoldOut);
|
|
17
|
+
return [...inStock, ...soldOut];
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Maps a `search.run()` response into `@eldrajs/ui`'s `SearchBar` `results` contract
|
|
22
|
+
* (`products`/`collections`/`articles`/`pages`/`total`) for the block's own combobox panel —
|
|
23
|
+
* never re-implemented, only fed. Each group is capped by the block's own `suggestionsPerGroup`
|
|
24
|
+
* field (spec "Search results page" → Field → layout mapping: "`suggestionsPerGroup` → options
|
|
25
|
+
* per group"); `SearchBar` applies its own further per-group caps on top (4 products, 3 for the
|
|
26
|
+
* combined "journal and help" group) when this cap is left higher than those.
|
|
27
|
+
*
|
|
28
|
+
* `collections` is always empty: the storefront's `search.run()` response
|
|
29
|
+
* (`StorefrontSearchResponse`) carries no collections group, and this block's own `types` field
|
|
30
|
+
* only ever offers products, journal and pages.
|
|
31
|
+
*
|
|
32
|
+
* `total` is the *whole* result count the backend reports, not the number of rows returned here —
|
|
33
|
+
* matching `SearchResults.total`'s own contract (the "See all N results" row reads it directly).
|
|
34
|
+
*
|
|
35
|
+
* **No response, no results object.** `undefined` is `SearchBar`'s "nothing yet" — it shows no panel
|
|
36
|
+
* and, past 300ms, its loading view. An empty shape with `total: 0` is its "nothing found", which is
|
|
37
|
+
* a different and wrong answer while the read for the query is still in flight: that is what put
|
|
38
|
+
* "No results for “bowl”" under the field for the whole second it took to answer.
|
|
39
|
+
*
|
|
40
|
+
* `formatPrice` is the block's own `useMoney().format` — the store's currency and the page's
|
|
41
|
+
* locale, resolved where a composable can be called. This function is pure, so it takes the
|
|
42
|
+
* formatter rather than reaching for the currency itself: the currency is the platform's, provided
|
|
43
|
+
* to the component tree, and nothing outside a `setup()` can read it.
|
|
44
|
+
*/
|
|
45
|
+
export function toSearchBarResults(
|
|
46
|
+
response: StorefrontSearchResponse | null,
|
|
47
|
+
suggestionsPerGroup: number,
|
|
48
|
+
formatPrice: (amount: number) => string
|
|
49
|
+
): SearchResults | undefined {
|
|
50
|
+
if (response === null) return undefined;
|
|
51
|
+
|
|
52
|
+
const products: SearchResultItem[] = rankProducts(response.products)
|
|
53
|
+
.slice(0, suggestionsPerGroup)
|
|
54
|
+
.map((product) => ({
|
|
55
|
+
id: product.productId,
|
|
56
|
+
title: product.title,
|
|
57
|
+
href: product.url,
|
|
58
|
+
// `SearchResultItem.price` is optional, so a product this storefront could not price keeps its
|
|
59
|
+
// row and loses only the price. Formatting a `null` as a number would print the store's own
|
|
60
|
+
// "$0.00" — a real price, and the wrong one (`StorefrontSearchProduct`).
|
|
61
|
+
price: product.price === null ? undefined : formatPrice(product.price.amount),
|
|
62
|
+
image: product.featuredImage?.src,
|
|
63
|
+
imageAlt: product.featuredImage?.alt,
|
|
64
|
+
}));
|
|
65
|
+
|
|
66
|
+
const articles: SearchResultItem[] = response.articles
|
|
67
|
+
.slice(0, suggestionsPerGroup)
|
|
68
|
+
.map((article, index) => ({
|
|
69
|
+
id: `article-${index}`,
|
|
70
|
+
title: article.title,
|
|
71
|
+
href: article.href,
|
|
72
|
+
image: article.image?.src,
|
|
73
|
+
imageAlt: article.image?.alt,
|
|
74
|
+
}));
|
|
75
|
+
|
|
76
|
+
const pages: SearchResultItem[] = response.pages
|
|
77
|
+
.slice(0, suggestionsPerGroup)
|
|
78
|
+
.map((page, index) => ({
|
|
79
|
+
id: `page-${index}`,
|
|
80
|
+
title: page.title,
|
|
81
|
+
href: page.href,
|
|
82
|
+
}));
|
|
83
|
+
|
|
84
|
+
return { products, collections: [], articles, pages, total: response.total };
|
|
85
|
+
}
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
/**
|
|
3
|
+
* A story told in rows of image and text that alternate sides (spec `02-blocks.md` "Split content",
|
|
4
|
+
* lines 974–1070) — "our process"/"about the materials" sections. There is no `variant`: the
|
|
5
|
+
* alternation itself is the design, and `startWith` only flips which side the *first* row's image
|
|
6
|
+
* takes (`image-left` or `image-right`); every following row alternates from there.
|
|
7
|
+
*
|
|
8
|
+
* **Source order vs. visual order (spec → Keyboard & accessibility, 1.3.2).** Every row's markup
|
|
9
|
+
* below puts the image (or, in the editor, its placeholder) before the text column, in that fixed
|
|
10
|
+
* order — never swapped per row. The left/right alternation is done entirely with the CSS grid
|
|
11
|
+
* `order` property (`imageOrderClass`/`textOrderClass`), which only ever changes *visual* position,
|
|
12
|
+
* never DOM order — so tab/reading order is "image, then text" in every row, on every screen,
|
|
13
|
+
* whichever side is showing, exactly the spec's own requirement. `rowGridColsClass` supplies the
|
|
14
|
+
* matching column-width pair: the image's own track is always `7fr` and the text's `5fr`, whichever
|
|
15
|
+
* physical column each currently occupies (spec → Layout, "48–64rem": "odd rows are 7fr 5fr (image
|
|
16
|
+
* left) and even rows are 5fr 7fr (image right)").
|
|
17
|
+
*
|
|
18
|
+
* A row with no `image` (an author's deliberate choice — spec → States, "No image": "single column,
|
|
19
|
+
* text max 40rem") drops the grid entirely and renders the text alone; the same emptiness in the
|
|
20
|
+
* editor (`useEditing()`) instead shows an `EditorPlaceholder` in the image's place so there is
|
|
21
|
+
* still something to click to add one (the same pattern `hero`'s own image slot uses).
|
|
22
|
+
*
|
|
23
|
+
* `rows[].text` is optional rich text with a small toolbar (bold/italic/link/undo/redo only — no
|
|
24
|
+
* headings or lists, per the field's own `metadata.toolbar`), rendered through `EldraRichText` with
|
|
25
|
+
* no `api-id`: like `faq`'s own per-item `answer` field, `rows[].text` lives one level inside a list
|
|
26
|
+
* item, and `useEldraBlockField`/`isBlockFieldLocalized` only resolve a field's `localized` flag by
|
|
27
|
+
* matching a flat top-level `fieldId` — there is no nested-path addressing, so passing `api-id`
|
|
28
|
+
* here would silently (and wrongly) resolve `localized: false` regardless of the manifest. See
|
|
29
|
+
* `blocks/faq/Block.vue`'s own comment for the full reasoning.
|
|
30
|
+
*
|
|
31
|
+
* `useRichTextScrollRegions` is applied once, to a ref around the whole `<ol>`, rather than once per
|
|
32
|
+
* row: its own contract only needs a ref that *contains* every rendered rich-text root (it wraps
|
|
33
|
+
* every `<table>`/marks every `<pre>` under whatever element it is given — see that composable's
|
|
34
|
+
* doc comment), and a `<ol>` full of `EldraRichText` roots shares one common ancestor here, so one
|
|
35
|
+
* call covers every row's rich text at once.
|
|
36
|
+
*/
|
|
37
|
+
import { computed, ref } from 'vue';
|
|
38
|
+
import { Container, EditorPlaceholder, Link, Section } from '@eldrajs/ui';
|
|
39
|
+
import { EldraRichText } from '@eldrajs/theme-vue';
|
|
40
|
+
import { DEFAULT_IMAGE_FRAMING, type ImageFraming } from '@eldrajs/theme-vue';
|
|
41
|
+
import { useBlockData } from '../../app/composables/useBlockData';
|
|
42
|
+
import { useEditing } from '../../app/composables/useEditing';
|
|
43
|
+
import { useRichTextScrollRegions } from '../../app/composables/useRichTextScrollRegions';
|
|
44
|
+
import { useI18n } from 'vue-i18n';
|
|
45
|
+
import EldraRouterLink from '../../app/components/EldraRouterLink.vue';
|
|
46
|
+
import UiImage from '../../app/components/ui/UiImage.vue';
|
|
47
|
+
import { isInternalHref, safeHref } from '../../app/utils/links';
|
|
48
|
+
|
|
49
|
+
type Side = 'image-left' | 'image-right';
|
|
50
|
+
|
|
51
|
+
interface SplitContentRow {
|
|
52
|
+
image?: { url: string; altText?: string | null; framing?: ImageFraming | null } | null;
|
|
53
|
+
eyebrow?: string;
|
|
54
|
+
heading?: string;
|
|
55
|
+
text?: { content?: unknown[] } | null;
|
|
56
|
+
linkLabel?: string;
|
|
57
|
+
href?: string;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const props = defineProps<{ entry: EldraBlockEntry<'split-content'> }>();
|
|
61
|
+
const { data, entryId } = useBlockData(props, 'split-content');
|
|
62
|
+
const editing = useEditing();
|
|
63
|
+
const { t } = useI18n();
|
|
64
|
+
|
|
65
|
+
const startWith = computed<Side>(() => data.value.startWith ?? 'image-left');
|
|
66
|
+
const rows = computed<SplitContentRow[]>(() => data.value.rows ?? []);
|
|
67
|
+
|
|
68
|
+
function oppositeSide(side: Side): Side {
|
|
69
|
+
return side === 'image-left' ? 'image-right' : 'image-left';
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** Row 1 takes `startWith`'s side; every row after that alternates — see the module doc comment. */
|
|
73
|
+
function rowSide(index: number): Side {
|
|
74
|
+
return index % 2 === 0 ? startWith.value : oppositeSide(startWith.value);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function rowHasImage(row: SplitContentRow): boolean {
|
|
78
|
+
return Boolean(row.image);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function rowFraming(row: SplitContentRow): ImageFraming | undefined {
|
|
82
|
+
return row.image?.framing ?? DEFAULT_IMAGE_FRAMING;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** The image's own column is always `7fr`, wherever it lands — see the module doc comment. */
|
|
86
|
+
function rowGridColsClass(index: number): string {
|
|
87
|
+
return rowSide(index) === 'image-left'
|
|
88
|
+
? '@tablet:grid-cols-[7fr_5fr]'
|
|
89
|
+
: '@tablet:grid-cols-[5fr_7fr]';
|
|
90
|
+
}
|
|
91
|
+
/** The image is always first in the DOM (see the template); `order` only ever needs to move it —
|
|
92
|
+
* the text column's own class is just its mirror. */
|
|
93
|
+
function imageOrderClass(index: number): string {
|
|
94
|
+
return rowSide(index) === 'image-right' ? '@tablet:order-2' : '';
|
|
95
|
+
}
|
|
96
|
+
function textOrderClass(index: number): string {
|
|
97
|
+
return rowSide(index) === 'image-right' ? '@tablet:order-1' : '';
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function rowHref(row: SplitContentRow): string | null {
|
|
101
|
+
return safeHref(row.href);
|
|
102
|
+
}
|
|
103
|
+
function rowHasLink(row: SplitContentRow): boolean {
|
|
104
|
+
return Boolean(row.linkLabel) && rowHref(row) !== null;
|
|
105
|
+
}
|
|
106
|
+
function rowLinkAs(row: SplitContentRow): typeof EldraRouterLink | undefined {
|
|
107
|
+
const href = rowHref(row);
|
|
108
|
+
return href !== null && isInternalHref(href) ? EldraRouterLink : undefined;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/** An optional rich-text field with nothing written yet is an empty TipTap doc (or absent
|
|
112
|
+
* entirely) — either way, no paragraph content to render. */
|
|
113
|
+
function rowHasText(row: SplitContentRow): boolean {
|
|
114
|
+
return Array.isArray(row.text?.content) && row.text!.content!.length > 0;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const rowsRoot = ref<HTMLElement | null>(null);
|
|
118
|
+
useRichTextScrollRegions(rowsRoot, (caption) => caption ?? t('splitContent.richTextTableLabel'));
|
|
119
|
+
</script>
|
|
120
|
+
|
|
121
|
+
<template>
|
|
122
|
+
<Section spacing="md" :aria-label="t('splitContent.label')">
|
|
123
|
+
<Container width="wide">
|
|
124
|
+
<ol ref="rowsRoot" role="list" class="@tablet:gap-16 grid gap-12">
|
|
125
|
+
<li
|
|
126
|
+
v-for="(row, index) in rows"
|
|
127
|
+
:key="index"
|
|
128
|
+
class="@tablet:gap-12 @content:gap-16 grid items-center gap-6"
|
|
129
|
+
:class="rowHasImage(row) ? rowGridColsClass(index) : ''"
|
|
130
|
+
>
|
|
131
|
+
<UiImage
|
|
132
|
+
v-if="rowHasImage(row)"
|
|
133
|
+
:src="row.image!.url"
|
|
134
|
+
:alt="row.image!.altText ?? ''"
|
|
135
|
+
:framing="rowFraming(row)"
|
|
136
|
+
:entry-id="entryId"
|
|
137
|
+
:field-path="`rows.${index}.image`"
|
|
138
|
+
aspect="4/3"
|
|
139
|
+
rounded="xl"
|
|
140
|
+
:class="imageOrderClass(index)"
|
|
141
|
+
/>
|
|
142
|
+
<EditorPlaceholder
|
|
143
|
+
v-else-if="editing"
|
|
144
|
+
inline
|
|
145
|
+
:label="t('splitContent.imageHintLabel')"
|
|
146
|
+
:classes="{ root: 'aspect-[4/3] w-full rounded-xl bg-surface-strong' }"
|
|
147
|
+
:class="imageOrderClass(index)"
|
|
148
|
+
/>
|
|
149
|
+
|
|
150
|
+
<div
|
|
151
|
+
class="grid gap-4"
|
|
152
|
+
:class="[rowHasImage(row) ? 'max-w-[30rem]' : 'max-w-[40rem]', textOrderClass(index)]"
|
|
153
|
+
>
|
|
154
|
+
<p v-if="row.eyebrow" class="text-overline text-accent">{{ row.eyebrow }}</p>
|
|
155
|
+
<h2
|
|
156
|
+
v-if="row.heading"
|
|
157
|
+
class="font-heading text-text @tablet:text-h2 text-[1.625rem] leading-[1.15] font-bold tracking-[-0.015em]"
|
|
158
|
+
>
|
|
159
|
+
{{ row.heading }}
|
|
160
|
+
</h2>
|
|
161
|
+
<EditorPlaceholder
|
|
162
|
+
v-else-if="editing"
|
|
163
|
+
inline
|
|
164
|
+
:label="t('splitContent.headingHintLabel')"
|
|
165
|
+
:help="t('splitContent.headingHintHelp')"
|
|
166
|
+
/>
|
|
167
|
+
|
|
168
|
+
<!-- Each row's own heading above is an `h2`, so the row text's headings start at
|
|
169
|
+
`h3`. (`rows[].text`'s `metadata.toolbar` offers no heading control today, but the
|
|
170
|
+
floor costs nothing and survives a toolbar change.) -->
|
|
171
|
+
<EldraRichText
|
|
172
|
+
v-if="rowHasText(row)"
|
|
173
|
+
class="prose-eldra text-body-lg text-muted [&>*+*]:mt-3"
|
|
174
|
+
:entry-id="entryId"
|
|
175
|
+
:field="`rows.${index}.text`"
|
|
176
|
+
:doc="row.text"
|
|
177
|
+
:min-heading-level="3"
|
|
178
|
+
/>
|
|
179
|
+
|
|
180
|
+
<Link
|
|
181
|
+
v-if="rowHasLink(row)"
|
|
182
|
+
:href="rowHref(row)!"
|
|
183
|
+
:as="rowLinkAs(row)"
|
|
184
|
+
variant="standalone"
|
|
185
|
+
arrow
|
|
186
|
+
:classes="{ root: 'mt-1 text-lg' }"
|
|
187
|
+
>
|
|
188
|
+
{{ row.linkLabel }}
|
|
189
|
+
</Link>
|
|
190
|
+
</div>
|
|
191
|
+
</li>
|
|
192
|
+
</ol>
|
|
193
|
+
</Container>
|
|
194
|
+
</Section>
|
|
195
|
+
</template>
|