@eldrajs/theme-cli 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +69 -0
- package/LICENSE +21 -0
- package/README.md +27 -2
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +203 -0
- package/dist/index.d.ts +174 -0
- package/dist/index.js +3 -0
- package/dist/validate-C6jB8_Oc.js +510 -0
- package/package.json +56 -3
- package/template/.eldra/block-types.d.ts +429 -0
- package/template/.eldra/manifest.json +9377 -0
- package/template/.eldra/previews.json +36 -0
- package/template/.github/workflows/eldra-deploy.yml +24 -0
- package/template/.gitlab-ci.yml +16 -0
- package/template/.storybook/eldra.ts +123 -0
- package/template/.storybook/i18n.ts +23 -0
- package/template/.storybook/main.ts +59 -0
- package/template/.storybook/nuxt-link-stub.ts +23 -0
- package/template/.storybook/preview.ts +52 -0
- package/template/.storybook/shims-vue.d.ts +10 -0
- package/template/.storybook/virtual-eldra.d.ts +27 -0
- package/template/README.md +288 -0
- package/template/app/app.vue +126 -0
- package/template/app/assets/main.css +404 -0
- package/template/app/components/EldraIcon.vue +66 -0
- package/template/app/components/EldraRouterLink.vue +62 -0
- package/template/app/components/ui/UiImage.stories.ts +30 -0
- package/template/app/components/ui/UiImage.vue +224 -0
- package/template/app/components/ui/__tests__/UiImage.spec.ts +292 -0
- package/template/app/composables/iconComponent.ts +84 -0
- package/template/app/composables/iconFetcher.ts +14 -0
- package/template/app/composables/useBlockData.ts +30 -0
- package/template/app/composables/useEditing.ts +31 -0
- package/template/app/composables/useEldraIcon.ts +46 -0
- package/template/app/composables/useRevalidating.ts +69 -0
- package/template/app/composables/useRichTextScrollRegions.ts +80 -0
- package/template/app/composables/useStorefront.ts +18 -0
- package/template/app/composables/useStorefrontFeedback.ts +49 -0
- package/template/app/composables/useUiId.ts +18 -0
- package/template/app/composables/useWishlist.ts +42 -0
- package/template/app/i18n.d.ts +28 -0
- package/template/app/icons.ts +185 -0
- package/template/app/pages/[...slug].vue +134 -0
- package/template/app/plugins/eldra-i18n.ts +98 -0
- package/template/app/plugins/eldra-storefront.ts +288 -0
- package/template/app/plugins/eldra-ui-messages.ts +112 -0
- package/template/app/storefront/cart.ts +245 -0
- package/template/app/storefront/categories.ts +283 -0
- package/template/app/storefront/collectionSelector.ts +60 -0
- package/template/app/storefront/commerce.ts +58 -0
- package/template/app/storefront/demo.ts +1313 -0
- package/template/app/storefront/facets.ts +476 -0
- package/template/app/storefront/feedback.ts +122 -0
- package/template/app/storefront/gateway.ts +2256 -0
- package/template/app/storefront/history.ts +233 -0
- package/template/app/storefront/money.ts +247 -0
- package/template/app/storefront/options.ts +71 -0
- package/template/app/storefront/prerender.ts +77 -0
- package/template/app/storefront/refresh.ts +222 -0
- package/template/app/storefront/toProductCard.ts +154 -0
- package/template/app/storefront/types.ts +815 -0
- package/template/app/storefront/volatile.ts +211 -0
- package/template/app/templates.ts +544 -0
- package/template/app/utils/classes.ts +40 -0
- package/template/app/utils/links.ts +70 -0
- package/template/app/utils/pageStructure.ts +77 -0
- package/template/app/utils/pageTitle.ts +37 -0
- package/template/app/virtual-eldra.d.ts +12 -0
- package/template/bitbucket-pipelines.yml +19 -0
- package/template/blocks/announcement-bar/Block.vue +203 -0
- package/template/blocks/announcement-bar/__tests__/Block.spec.ts +227 -0
- package/template/blocks/announcement-bar/block.json +45 -0
- package/template/blocks/announcement-bar/mock.json +7 -0
- package/template/blocks/announcement-bar/preview.png +0 -0
- package/template/blocks/article/Block.vue +317 -0
- package/template/blocks/article/__tests__/Block.spec.ts +229 -0
- package/template/blocks/article/block.json +148 -0
- package/template/blocks/article/mock.json +512 -0
- package/template/blocks/article/preview.json +16 -0
- package/template/blocks/article/preview.png +0 -0
- package/template/blocks/article-list/Block.vue +343 -0
- package/template/blocks/article-list/__tests__/Block.spec.ts +279 -0
- package/template/blocks/article-list/block.json +181 -0
- package/template/blocks/article-list/mock.json +68 -0
- package/template/blocks/article-list/preview.json +84 -0
- package/template/blocks/article-list/preview.png +0 -0
- package/template/blocks/breadcrumbs/Block.vue +278 -0
- package/template/blocks/breadcrumbs/__tests__/Block.spec.ts +461 -0
- package/template/blocks/breadcrumbs/block.json +89 -0
- package/template/blocks/breadcrumbs/mock.json +11 -0
- package/template/blocks/breadcrumbs/preview.json +3 -0
- package/template/blocks/breadcrumbs/preview.png +0 -0
- package/template/blocks/cart/Block.vue +372 -0
- package/template/blocks/cart/__tests__/Block.spec.ts +561 -0
- package/template/blocks/cart/__tests__/ShippingBar.spec.ts +78 -0
- package/template/blocks/cart/__tests__/Summary.spec.ts +245 -0
- package/template/blocks/cart/block.json +74 -0
- package/template/blocks/cart/mock.json +11 -0
- package/template/blocks/cart/parts/CartLines.vue +257 -0
- package/template/blocks/cart/parts/ShippingBar.vue +105 -0
- package/template/blocks/cart/parts/Summary.vue +291 -0
- package/template/blocks/cart/preview.png +0 -0
- package/template/blocks/collection-grid/Block.vue +1832 -0
- package/template/blocks/collection-grid/__tests__/Block.spec.ts +3037 -0
- package/template/blocks/collection-grid/__tests__/groups.spec.ts +731 -0
- package/template/blocks/collection-grid/block.json +187 -0
- package/template/blocks/collection-grid/mock.json +23 -0
- package/template/blocks/collection-grid/parts/groups.ts +861 -0
- package/template/blocks/collection-grid/preview.json +7 -0
- package/template/blocks/collection-grid/preview.png +0 -0
- package/template/blocks/collection-header/Block.vue +533 -0
- package/template/blocks/collection-header/__tests__/Block.spec.ts +381 -0
- package/template/blocks/collection-header/block.json +140 -0
- package/template/blocks/collection-header/mock.json +28 -0
- package/template/blocks/collection-header/preview.json +14 -0
- package/template/blocks/collection-header/preview.png +0 -0
- package/template/blocks/contact/Block.vue +621 -0
- package/template/blocks/contact/__tests__/Block.spec.ts +347 -0
- package/template/blocks/contact/block.json +174 -0
- package/template/blocks/contact/mock.json +28 -0
- package/template/blocks/contact/preview.json +9 -0
- package/template/blocks/contact/preview.png +0 -0
- package/template/blocks/cta/Block.vue +383 -0
- package/template/blocks/cta/__tests__/Block.spec.ts +309 -0
- package/template/blocks/cta/block.json +86 -0
- package/template/blocks/cta/mock.json +10 -0
- package/template/blocks/cta/preview.json +9 -0
- package/template/blocks/cta/preview.png +0 -0
- package/template/blocks/faq/Block.vue +254 -0
- package/template/blocks/faq/__tests__/Block.spec.ts +312 -0
- package/template/blocks/faq/block.json +113 -0
- package/template/blocks/faq/mock.json +115 -0
- package/template/blocks/faq/preview.png +0 -0
- package/template/blocks/feature-grid/Block.vue +241 -0
- package/template/blocks/feature-grid/__tests__/Block.spec.ts +311 -0
- package/template/blocks/feature-grid/block.json +106 -0
- package/template/blocks/feature-grid/mock.json +29 -0
- package/template/blocks/feature-grid/preview.json +45 -0
- package/template/blocks/feature-grid/preview.png +0 -0
- package/template/blocks/footer/Block.vue +652 -0
- package/template/blocks/footer/__tests__/Block.spec.ts +700 -0
- package/template/blocks/footer/block.json +240 -0
- package/template/blocks/footer/mock.json +161 -0
- package/template/blocks/footer/preview.png +0 -0
- package/template/blocks/gallery/Block.vue +416 -0
- package/template/blocks/gallery/__tests__/Block.spec.ts +289 -0
- package/template/blocks/gallery/block.json +87 -0
- package/template/blocks/gallery/mock.json +16 -0
- package/template/blocks/gallery/preview.json +64 -0
- package/template/blocks/gallery/preview.png +0 -0
- package/template/blocks/hero/Block.vue +378 -0
- package/template/blocks/hero/__tests__/Block.spec.ts +324 -0
- package/template/blocks/hero/block.json +146 -0
- package/template/blocks/hero/mock.json +11 -0
- package/template/blocks/hero/preview.json +55 -0
- package/template/blocks/hero/preview.png +0 -0
- package/template/blocks/image/Block.vue +232 -0
- package/template/blocks/image/__tests__/Block.spec.ts +224 -0
- package/template/blocks/image/block.json +67 -0
- package/template/blocks/image/mock.json +7 -0
- package/template/blocks/image/preview.json +9 -0
- package/template/blocks/image/preview.png +0 -0
- package/template/blocks/logo-cloud/Block.vue +206 -0
- package/template/blocks/logo-cloud/__tests__/Block.spec.ts +210 -0
- package/template/blocks/logo-cloud/block.json +79 -0
- package/template/blocks/logo-cloud/mock.json +15 -0
- package/template/blocks/logo-cloud/preview.json +92 -0
- package/template/blocks/logo-cloud/preview.png +0 -0
- package/template/blocks/navigation/Block.vue +1348 -0
- package/template/blocks/navigation/__tests__/Block.spec.ts +2030 -0
- package/template/blocks/navigation/block.json +167 -0
- package/template/blocks/navigation/mock.json +191 -0
- package/template/blocks/navigation/preview.png +0 -0
- package/template/blocks/navigation/useMegaMenuKeys.ts +276 -0
- package/template/blocks/newsletter/Block.vue +399 -0
- package/template/blocks/newsletter/__tests__/Block.spec.ts +365 -0
- package/template/blocks/newsletter/block.json +105 -0
- package/template/blocks/newsletter/mock.json +31 -0
- package/template/blocks/newsletter/preview.png +0 -0
- package/template/blocks/order-status/Block.vue +754 -0
- package/template/blocks/order-status/__tests__/Block.spec.ts +515 -0
- package/template/blocks/order-status/block.json +138 -0
- package/template/blocks/order-status/mock.json +19 -0
- package/template/blocks/order-status/preview.png +0 -0
- package/template/blocks/pricing-table/Block.vue +297 -0
- package/template/blocks/pricing-table/__tests__/Block.spec.ts +357 -0
- package/template/blocks/pricing-table/block.json +155 -0
- package/template/blocks/pricing-table/mock.json +47 -0
- package/template/blocks/pricing-table/preview.png +0 -0
- package/template/blocks/product-carousel/Block.vue +459 -0
- package/template/blocks/product-carousel/__tests__/Block.spec.ts +957 -0
- package/template/blocks/product-carousel/block.json +71 -0
- package/template/blocks/product-carousel/mock.json +9 -0
- package/template/blocks/product-carousel/preview.json +7 -0
- package/template/blocks/product-carousel/preview.png +0 -0
- package/template/blocks/product-detail/Block.vue +886 -0
- package/template/blocks/product-detail/__tests__/Block.spec.ts +1495 -0
- package/template/blocks/product-detail/__tests__/stock.spec.ts +119 -0
- package/template/blocks/product-detail/block.json +155 -0
- package/template/blocks/product-detail/mock.json +113 -0
- package/template/blocks/product-detail/parts/Gallery.vue +181 -0
- package/template/blocks/product-detail/parts/StickyBuyBar.vue +99 -0
- package/template/blocks/product-detail/preview.png +0 -0
- package/template/blocks/product-detail/stock.ts +150 -0
- package/template/blocks/quote/Block.vue +206 -0
- package/template/blocks/quote/__tests__/Block.spec.ts +265 -0
- package/template/blocks/quote/block.json +76 -0
- package/template/blocks/quote/mock.json +9 -0
- package/template/blocks/quote/preview.json +16 -0
- package/template/blocks/quote/preview.png +0 -0
- package/template/blocks/rich-text/Block.vue +143 -0
- package/template/blocks/rich-text/__tests__/Block.spec.ts +191 -0
- package/template/blocks/rich-text/block.json +57 -0
- package/template/blocks/rich-text/mock.json +87 -0
- package/template/blocks/rich-text/preview.png +0 -0
- package/template/blocks/search/Block.vue +589 -0
- package/template/blocks/search/PopularChips.vue +40 -0
- package/template/blocks/search/TypeSection.vue +148 -0
- package/template/blocks/search/__tests__/Block.spec.ts +718 -0
- package/template/blocks/search/__tests__/results.spec.ts +166 -0
- package/template/blocks/search/block.json +102 -0
- package/template/blocks/search/mock.json +18 -0
- package/template/blocks/search/preview.png +0 -0
- package/template/blocks/search/results.ts +85 -0
- package/template/blocks/split-content/Block.vue +195 -0
- package/template/blocks/split-content/__tests__/Block.spec.ts +225 -0
- package/template/blocks/split-content/block.json +70 -0
- package/template/blocks/split-content/mock.json +45 -0
- package/template/blocks/split-content/preview.json +58 -0
- package/template/blocks/split-content/preview.png +0 -0
- package/template/blocks/stats/Block.vue +159 -0
- package/template/blocks/stats/__tests__/Block.spec.ts +194 -0
- package/template/blocks/stats/block.json +73 -0
- package/template/blocks/stats/mock.json +12 -0
- package/template/blocks/stats/preview.png +0 -0
- package/template/blocks/tabs/Block.vue +278 -0
- package/template/blocks/tabs/__tests__/Block.spec.ts +303 -0
- package/template/blocks/tabs/block.json +97 -0
- package/template/blocks/tabs/mock.json +129 -0
- package/template/blocks/tabs/preview.json +153 -0
- package/template/blocks/tabs/preview.png +0 -0
- package/template/blocks/team/Block.vue +288 -0
- package/template/blocks/team/__tests__/Block.spec.ts +221 -0
- package/template/blocks/team/block.json +125 -0
- package/template/blocks/team/mock.json +39 -0
- package/template/blocks/team/preview.json +62 -0
- package/template/blocks/team/preview.png +0 -0
- package/template/blocks/testimonials/Block.vue +408 -0
- package/template/blocks/testimonials/__tests__/Block.spec.ts +319 -0
- package/template/blocks/testimonials/block.json +121 -0
- package/template/blocks/testimonials/mock.json +46 -0
- package/template/blocks/testimonials/preview.json +68 -0
- package/template/blocks/testimonials/preview.png +0 -0
- package/template/blocks/timeline/Block.vue +274 -0
- package/template/blocks/timeline/__tests__/Block.spec.ts +310 -0
- package/template/blocks/timeline/block.json +98 -0
- package/template/blocks/timeline/mock.json +27 -0
- package/template/blocks/timeline/preview.png +0 -0
- package/template/blocks/trust-strip/Block.vue +330 -0
- package/template/blocks/trust-strip/__tests__/Block.spec.ts +290 -0
- package/template/blocks/trust-strip/block.json +117 -0
- package/template/blocks/trust-strip/mock.json +37 -0
- package/template/blocks/trust-strip/preview.png +0 -0
- package/template/blocks/video-embed/Block.vue +354 -0
- package/template/blocks/video-embed/__tests__/Block.spec.ts +219 -0
- package/template/blocks/video-embed/__tests__/embed.spec.ts +76 -0
- package/template/blocks/video-embed/block.json +94 -0
- package/template/blocks/video-embed/embed.ts +84 -0
- package/template/blocks/video-embed/mock.json +13 -0
- package/template/blocks/video-embed/preview.json +9 -0
- package/template/blocks/video-embed/preview.png +0 -0
- package/template/blocks/wishlist/Block.vue +367 -0
- package/template/blocks/wishlist/__tests__/Block.spec.ts +508 -0
- package/template/blocks/wishlist/block.json +42 -0
- package/template/blocks/wishlist/mock.json +9 -0
- package/template/blocks/wishlist/preview.png +0 -0
- package/template/i18n/en-US.json +602 -0
- package/template/i18n/is-IS.json +602 -0
- package/template/nuxt.config.ts +148 -0
- package/template/package.json +55 -0
- package/template/pages/article.page.json +731 -0
- package/template/pages/cart.page.json +85 -0
- package/template/pages/category.page.json +133 -0
- package/template/pages/collection.page.json +194 -0
- package/template/pages/home.page.json +353 -0
- package/template/pages/product.page.json +323 -0
- package/template/pages/products.page.json +144 -0
- package/template/pages/search.page.json +83 -0
- package/template/pages/wishlist.page.json +88 -0
- package/template/public/demo/article-cover.svg +1 -0
- package/template/public/demo/article-figure.svg +1 -0
- package/template/public/demo/avatar-1.svg +3 -0
- package/template/public/demo/avatar-2.svg +3 -0
- package/template/public/demo/avatar-3.svg +3 -0
- package/template/public/demo/avatar-4.svg +3 -0
- package/template/public/demo/avatar-5.svg +3 -0
- package/template/public/demo/avatar-6.svg +3 -0
- package/template/public/demo/avatar-7.svg +3 -0
- package/template/public/demo/avatar-8.svg +3 -0
- package/template/public/demo/collection-1.svg +1 -0
- package/template/public/demo/collection-2.svg +1 -0
- package/template/public/demo/cta-split.svg +1 -0
- package/template/public/demo/feature-1.svg +1 -0
- package/template/public/demo/feature-2.svg +1 -0
- package/template/public/demo/feature-3.svg +1 -0
- package/template/public/demo/feature-4.svg +1 -0
- package/template/public/demo/gallery-1.svg +1 -0
- package/template/public/demo/gallery-2.svg +1 -0
- package/template/public/demo/gallery-3.svg +1 -0
- package/template/public/demo/gallery-4.svg +1 -0
- package/template/public/demo/gallery-5.svg +1 -0
- package/template/public/demo/gallery-6.svg +1 -0
- package/template/public/demo/gallery-7.svg +1 -0
- package/template/public/demo/gallery-8.svg +1 -0
- package/template/public/demo/hero-slide-1.svg +1 -0
- package/template/public/demo/hero-slide-2.svg +1 -0
- package/template/public/demo/hero-slide-3.svg +1 -0
- package/template/public/demo/hero-slide-4.svg +1 -0
- package/template/public/demo/hero-wide.svg +1 -0
- package/template/public/demo/hero.svg +1 -0
- package/template/public/demo/logo-1.svg +4 -0
- package/template/public/demo/logo-2.svg +4 -0
- package/template/public/demo/logo-3.svg +4 -0
- package/template/public/demo/logo-4.svg +4 -0
- package/template/public/demo/logo-5.svg +4 -0
- package/template/public/demo/logo-6.svg +4 -0
- package/template/public/demo/logo-7.svg +4 -0
- package/template/public/demo/logo-8.svg +4 -0
- package/template/public/demo/logo.svg +3 -0
- package/template/public/demo/map.svg +1 -0
- package/template/public/demo/poster.svg +1 -0
- package/template/public/demo/product-1.svg +4 -0
- package/template/public/demo/product-10.svg +4 -0
- package/template/public/demo/product-11.svg +4 -0
- package/template/public/demo/product-12.svg +4 -0
- package/template/public/demo/product-2.svg +4 -0
- package/template/public/demo/product-3.svg +4 -0
- package/template/public/demo/product-4.svg +4 -0
- package/template/public/demo/product-5.svg +4 -0
- package/template/public/demo/product-6.svg +4 -0
- package/template/public/demo/product-7.svg +4 -0
- package/template/public/demo/product-8.svg +4 -0
- package/template/public/demo/product-9.svg +4 -0
- package/template/public/demo/product-square-1.svg +4 -0
- package/template/public/demo/product-square-2.svg +4 -0
- package/template/public/demo/product-square-3.svg +4 -0
- package/template/public/demo/product-square-4.svg +4 -0
- package/template/public/demo/product-square-5.svg +4 -0
- package/template/public/demo/product-square-6.svg +4 -0
- package/template/public/demo/quote-portrait.svg +4 -0
- package/template/public/demo/split-1.svg +1 -0
- package/template/public/demo/split-2.svg +1 -0
- package/template/public/demo/split-3.svg +1 -0
- package/template/public/demo/split-4.svg +1 -0
- package/template/public/demo/team-1.svg +4 -0
- package/template/public/demo/team-2.svg +4 -0
- package/template/public/demo/team-3.svg +4 -0
- package/template/public/demo/team-4.svg +4 -0
- package/template/scripts/demo-images.mjs +393 -0
- package/template/scripts/generate-stories.mjs +156 -0
- package/template/scripts/previewHash.mjs +125 -0
- package/template/scripts/previews.mjs +149 -0
- package/template/stories/generated/announcement-bar.stories.ts +44 -0
- package/template/stories/generated/article-list.stories.ts +87 -0
- package/template/stories/generated/article.stories.ts +27 -0
- package/template/stories/generated/breadcrumbs.stories.ts +39 -0
- package/template/stories/generated/cart.stories.ts +38 -0
- package/template/stories/generated/collection-grid.stories.ts +117 -0
- package/template/stories/generated/collection-header.stories.ts +51 -0
- package/template/stories/generated/contact.stories.ts +45 -0
- package/template/stories/generated/cta.stories.ts +51 -0
- package/template/stories/generated/faq.stories.ts +56 -0
- package/template/stories/generated/feature-grid.stories.ts +69 -0
- package/template/stories/generated/footer.stories.ts +50 -0
- package/template/stories/generated/gallery.stories.ts +81 -0
- package/template/stories/generated/hero.stories.ts +75 -0
- package/template/stories/generated/image.stories.ts +99 -0
- package/template/stories/generated/logo-cloud.stories.ts +57 -0
- package/template/stories/generated/navigation.stories.ts +62 -0
- package/template/stories/generated/newsletter.stories.ts +68 -0
- package/template/stories/generated/order-status.stories.ts +32 -0
- package/template/stories/generated/pricing-table.stories.ts +44 -0
- package/template/stories/generated/product-carousel.stories.ts +75 -0
- package/template/stories/generated/product-detail.stories.ts +62 -0
- package/template/stories/generated/quote.stories.ts +69 -0
- package/template/stories/generated/rich-text.stories.ts +50 -0
- package/template/stories/generated/search.stories.ts +56 -0
- package/template/stories/generated/split-content.stories.ts +39 -0
- package/template/stories/generated/stats.stories.ts +68 -0
- package/template/stories/generated/tabs.stories.ts +45 -0
- package/template/stories/generated/team.stories.ts +45 -0
- package/template/stories/generated/testimonials.stories.ts +69 -0
- package/template/stories/generated/timeline.stories.ts +80 -0
- package/template/stories/generated/trust-strip.stories.ts +62 -0
- package/template/stories/generated/video-embed.stories.ts +63 -0
- package/template/stories/generated/wishlist.stories.ts +26 -0
- package/template/stories/pages/article.stories.ts +51 -0
- package/template/stories/pages/cart.stories.ts +56 -0
- package/template/stories/pages/category.stories.ts +56 -0
- package/template/stories/pages/collection.stories.ts +51 -0
- package/template/stories/pages/home.stories.ts +51 -0
- package/template/stories/pages/product.stories.ts +47 -0
- package/template/stories/pages/products.stories.ts +58 -0
- package/template/stories/pages/search.stories.ts +54 -0
- package/template/stories/pages/wishlist.stories.ts +53 -0
- package/template/stories/support/pageBlocks.ts +115 -0
- package/template/test/blocksEmptyData.spec.ts +52 -0
- package/template/test/carouselKeyboard.spec.ts +272 -0
- package/template/test/carouselRing.browser.spec.ts +193 -0
- package/template/test/carouselSlideWidth.browser.spec.ts +102 -0
- package/template/test/cartDrawer.spec.ts +295 -0
- package/template/test/cartToast.spec.ts +86 -0
- package/template/test/countPill.browser.spec.ts +196 -0
- package/template/test/demoImages.spec.ts +140 -0
- package/template/test/deps.spec.ts +102 -0
- package/template/test/eldraIcon.spec.ts +58 -0
- package/template/test/framing.spec.ts +76 -0
- package/template/test/i18n.spec.ts +200 -0
- package/template/test/iconComponent.spec.ts +91 -0
- package/template/test/inlineEditable.spec.ts +334 -0
- package/template/test/localePrefix.spec.ts +342 -0
- package/template/test/mainCss.spec.ts +107 -0
- package/template/test/mockGatewayContract.spec.ts +122 -0
- package/template/test/mocks/blocks.ts +20 -0
- package/template/test/mocks/breakpoints.ts +7 -0
- package/template/test/mocks/manifest.ts +11 -0
- package/template/test/moneyFormatting.spec.ts +89 -0
- package/template/test/pageTitle.spec.ts +49 -0
- package/template/test/pages/article.spec.ts +231 -0
- package/template/test/pages/category.spec.ts +185 -0
- package/template/test/pages/collection.spec.ts +396 -0
- package/template/test/pages/home.spec.ts +295 -0
- package/template/test/pages/hydration.spec.ts +557 -0
- package/template/test/pages/product.spec.ts +396 -0
- package/template/test/pages/seededPages.spec.ts +190 -0
- package/template/test/pages/ssr.spec.ts +393 -0
- package/template/test/prerenderCommerce.spec.ts +134 -0
- package/template/test/prerenderFailure.spec.ts +130 -0
- package/template/test/prerenderRefresh.browser.spec.ts +1431 -0
- package/template/test/previewsFresh.spec.ts +56 -0
- package/template/test/richText.spec.ts +161 -0
- package/template/test/richTextTypography.spec.ts +182 -0
- package/template/test/setup.ts +21 -0
- package/template/test/slugPage.spec.ts +244 -0
- package/template/test/slugPageTemplate.spec.ts +194 -0
- package/template/test/starter.spec.ts +1416 -0
- package/template/test/storefront/cart.spec.ts +404 -0
- package/template/test/storefront/categories.spec.ts +235 -0
- package/template/test/storefront/collectionSelector.spec.ts +74 -0
- package/template/test/storefront/demo.spec.ts +555 -0
- package/template/test/storefront/facets.spec.ts +425 -0
- package/template/test/storefront/feedback.spec.ts +97 -0
- package/template/test/storefront/gateway.spec.ts +2673 -0
- package/template/test/storefront/gatewayCart.spec.ts +289 -0
- package/template/test/storefront/gatewayPrerender.spec.ts +1037 -0
- package/template/test/storefront/history.spec.ts +341 -0
- package/template/test/storefront/money.spec.ts +171 -0
- package/template/test/storefront/toProductCard.spec.ts +138 -0
- package/template/test/storefront/volatile.spec.ts +284 -0
- package/template/test/support/axe.ts +14 -0
- package/template/test/support/dialog.ts +51 -0
- package/template/test/support/hydrate.ts +118 -0
- package/template/test/support/i18nText.ts +11 -0
- package/template/test/support/mockGateway.ts +1017 -0
- package/template/test/support/mountBlock.ts +194 -0
- package/template/test/support/mountPage.spec.ts +72 -0
- package/template/test/support/mountPage.ts +254 -0
- package/template/test/support/mountProbe.client.ts +69 -0
- package/template/test/support/renderSsr.ts +97 -0
- package/template/test/support/staticServer.ts +96 -0
- package/template/test/themeIcons.spec.ts +140 -0
- package/template/test/toastAnnouncement.spec.ts +133 -0
- package/template/test/tokens.spec.ts +102 -0
- package/template/test/uiMessagesPlugin.spec.ts +104 -0
- package/template/test/useBlockData.spec.ts +46 -0
- package/template/test/useEditing.spec.ts +54 -0
- package/template/test/useEldraIcon.spec.ts +126 -0
- package/template/test/useUiId.spec.ts +40 -0
- package/template/tokens.json +149 -0
- package/template/tsconfig.json +3 -0
- package/template/tsconfig.storybook.json +17 -0
- package/template/vitest-axe.d.ts +13 -0
- package/template/vitest.config.ts +44 -0
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
import { mount } from '@vue/test-utils';
|
|
3
|
+
import { describe, expect, it } from 'vitest';
|
|
4
|
+
import { ELDRA_KEY } from '@eldrajs/theme-vue';
|
|
5
|
+
import { axe } from '../../../test/support/axe';
|
|
6
|
+
import Block from '../Block.vue';
|
|
7
|
+
import mock from '../mock.json';
|
|
8
|
+
import { mountOptions } from '../../../test/support/mountBlock';
|
|
9
|
+
|
|
10
|
+
/** Stats has no media fields, so — unlike most rebuilt blocks — there is no `preview.json` to
|
|
11
|
+
* merge on top of `mock.json`. `mock.json` itself is therefore the block's one full ("merged")
|
|
12
|
+
* content fixture; `bare` below is the genuinely minimal one, only the fields the block requires. */
|
|
13
|
+
const bare = {
|
|
14
|
+
heading: 'What customers say',
|
|
15
|
+
items: [
|
|
16
|
+
{ value: '38', label: 'Independent makers' },
|
|
17
|
+
{ value: '12', label: 'Years trading' },
|
|
18
|
+
],
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
function mountBlock(data: Record<string, unknown>, options: { editing?: boolean } = {}) {
|
|
22
|
+
const opts = mountOptions({ entry: { id: 'e1', data } });
|
|
23
|
+
if (options.editing) {
|
|
24
|
+
const context = opts.global.provide[ELDRA_KEY] as {
|
|
25
|
+
preview: { active: boolean; mode: string };
|
|
26
|
+
};
|
|
27
|
+
context.preview.active = true;
|
|
28
|
+
context.preview.mode = 'edit';
|
|
29
|
+
}
|
|
30
|
+
return mount(Block, opts);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
describe('stats block', () => {
|
|
34
|
+
it('renders the full mock.json content with no axe violations', async () => {
|
|
35
|
+
const wrapper = mountBlock(mock);
|
|
36
|
+
expect(wrapper.text()).toContain(mock.heading);
|
|
37
|
+
expect(wrapper.text()).toContain(mock.intro);
|
|
38
|
+
for (const item of mock.items) {
|
|
39
|
+
expect(wrapper.text()).toContain(item.value);
|
|
40
|
+
expect(wrapper.text()).toContain(item.label);
|
|
41
|
+
}
|
|
42
|
+
expect(await axe(wrapper.element)).toHaveNoViolations();
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it('renders the bare, required-fields-only content with no axe violations', async () => {
|
|
46
|
+
const wrapper = mountBlock(bare);
|
|
47
|
+
expect(wrapper.text()).toContain(bare.heading);
|
|
48
|
+
for (const item of bare.items) {
|
|
49
|
+
expect(wrapper.text()).toContain(item.value);
|
|
50
|
+
expect(wrapper.text()).toContain(item.label);
|
|
51
|
+
}
|
|
52
|
+
expect(await axe(wrapper.element)).toHaveNoViolations();
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it.each(['row', 'split'] as const)(
|
|
56
|
+
'renders the %s variant with no axe violations',
|
|
57
|
+
async (variant) => {
|
|
58
|
+
const wrapper = mountBlock({ ...mock, variant });
|
|
59
|
+
expect(wrapper.findAll('li')).toHaveLength(mock.items.length);
|
|
60
|
+
expect(await axe(wrapper.element)).toHaveNoViolations();
|
|
61
|
+
}
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
it.each(['primary', 'accent'] as const)(
|
|
65
|
+
'renders the %s section background with no axe violations',
|
|
66
|
+
async (sectionBackground) => {
|
|
67
|
+
const wrapper = mountBlock({ ...mock, sectionBackground });
|
|
68
|
+
expect(await axe(wrapper.element)).toHaveNoViolations();
|
|
69
|
+
}
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
it('renders the block root as a labelled <section> that measures its own width (@container)', () => {
|
|
73
|
+
const wrapper = mountBlock(mock);
|
|
74
|
+
const section = wrapper.get('section');
|
|
75
|
+
expect(section.classes()).toContain('@container');
|
|
76
|
+
expect(section.attributes('aria-labelledby')).toBeTruthy();
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it('the heading is an h2, the figures are a <ul>, and each value comes before its label', () => {
|
|
80
|
+
const wrapper = mountBlock(mock);
|
|
81
|
+
const heading = wrapper.get('h2');
|
|
82
|
+
expect(heading.text()).toBe(mock.heading);
|
|
83
|
+
const list = wrapper.get('ul');
|
|
84
|
+
expect(
|
|
85
|
+
heading.element.compareDocumentPosition(list.element) & Node.DOCUMENT_POSITION_FOLLOWING
|
|
86
|
+
).toBeTruthy();
|
|
87
|
+
const items = list.findAll('li');
|
|
88
|
+
expect(items).toHaveLength(mock.items.length);
|
|
89
|
+
items.forEach((item, index) => {
|
|
90
|
+
const paragraphs = item.findAll('p');
|
|
91
|
+
expect(paragraphs).toHaveLength(2);
|
|
92
|
+
expect(paragraphs[0]!.text()).toBe(mock.items[index]!.value);
|
|
93
|
+
expect(paragraphs[1]!.text()).toBe(mock.items[index]!.label);
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
it('has no focusable parts: nothing in the block is a tab stop', () => {
|
|
98
|
+
const wrapper = mountBlock(mock);
|
|
99
|
+
expect(wrapper.findAll('a, button, input, [tabindex]')).toHaveLength(0);
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
it('renders 8 items as 8 list items', () => {
|
|
103
|
+
const items = Array.from({ length: 8 }, (_, index) => ({
|
|
104
|
+
value: String(index + 1),
|
|
105
|
+
label: `Figure ${index + 1}`,
|
|
106
|
+
}));
|
|
107
|
+
const wrapper = mountBlock({ ...mock, items });
|
|
108
|
+
expect(wrapper.findAll('li')).toHaveLength(8);
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
it('a single item spans the full width', () => {
|
|
112
|
+
const wrapper = mountBlock({ ...mock, items: [mock.items[0]!] });
|
|
113
|
+
const items = wrapper.findAll('li');
|
|
114
|
+
expect(items).toHaveLength(1);
|
|
115
|
+
expect(items[0]!.classes()).toContain('col-span-full');
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
it('does not span the full width when there is more than one item', () => {
|
|
119
|
+
const wrapper = mountBlock({ ...mock, items: mock.items.slice(0, 2) });
|
|
120
|
+
for (const item of wrapper.findAll('li')) {
|
|
121
|
+
expect(item.classes()).not.toContain('col-span-full');
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
it('a 7-character value gets the wrap-anywhere class', () => {
|
|
126
|
+
const wrapper = mountBlock({ ...mock, items: [{ value: '1234567', label: 'Long figure' }] });
|
|
127
|
+
const value = wrapper.get('li p');
|
|
128
|
+
expect(value.text()).toBe('1234567');
|
|
129
|
+
expect(value.classes()).toContain('wrap-anywhere');
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
it('has no transition or animation class anywhere in the block', () => {
|
|
133
|
+
const wrapper = mountBlock(mock);
|
|
134
|
+
const classes = wrapper.element.querySelectorAll('*');
|
|
135
|
+
for (const element of classes) {
|
|
136
|
+
for (const className of element.classList) {
|
|
137
|
+
expect(className.startsWith('transition-')).toBe(false);
|
|
138
|
+
expect(className.startsWith('animate-')).toBe(false);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
it('an item with an empty value is not rendered live', () => {
|
|
144
|
+
const wrapper = mountBlock({
|
|
145
|
+
...mock,
|
|
146
|
+
items: [...mock.items, { value: '', label: 'Not yet filled in' }],
|
|
147
|
+
});
|
|
148
|
+
expect(wrapper.findAll('li')).toHaveLength(mock.items.length);
|
|
149
|
+
expect(wrapper.text()).not.toContain('Not yet filled in');
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
it('shows the heading hint only in the editor when heading is empty, with no axe violations', async () => {
|
|
153
|
+
const data = { ...mock, heading: '' };
|
|
154
|
+
const live = mountBlock(data);
|
|
155
|
+
expect(live.text()).not.toContain('Add a heading');
|
|
156
|
+
expect(live.find('h2').exists()).toBe(false);
|
|
157
|
+
|
|
158
|
+
const editing = mountBlock(data, { editing: true });
|
|
159
|
+
expect(editing.text()).toContain('Add a heading');
|
|
160
|
+
expect(await axe(editing.element)).toHaveNoViolations();
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
it('shows the intro hint only in the editor when intro is empty', () => {
|
|
164
|
+
const data = { ...mock, intro: '' };
|
|
165
|
+
const live = mountBlock(data);
|
|
166
|
+
expect(live.text()).not.toContain('Add an intro');
|
|
167
|
+
|
|
168
|
+
const editing = mountBlock(data, { editing: true });
|
|
169
|
+
expect(editing.text()).toContain('Add an intro (optional)');
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
it('does not render an intro paragraph at all when intro is empty, live', () => {
|
|
173
|
+
const wrapper = mountBlock({ ...mock, intro: '' });
|
|
174
|
+
expect(wrapper.findAll('p').some((p) => p.text() === mock.intro)).toBe(false);
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
it('shows a per-item hint in the editor for an empty item, and renders it live as nothing', async () => {
|
|
178
|
+
const data = { ...mock, items: [{ value: '', label: '' }] };
|
|
179
|
+
const live = mountBlock(data);
|
|
180
|
+
expect(live.findAll('li')).toHaveLength(0);
|
|
181
|
+
|
|
182
|
+
const editing = mountBlock(data, { editing: true });
|
|
183
|
+
expect(editing.findAll('li')).toHaveLength(1);
|
|
184
|
+
expect(editing.text()).toContain('Add a figure');
|
|
185
|
+
expect(await axe(editing.element)).toHaveNoViolations();
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
it('defaults sectionBackground to none when unset', () => {
|
|
189
|
+
const { sectionBackground: _omit, ...withoutBackground } = mock;
|
|
190
|
+
const wrapper = mountBlock(withoutBackground);
|
|
191
|
+
const section = wrapper.get('section');
|
|
192
|
+
expect(section.attributes('data-section-bg')).toBe('none');
|
|
193
|
+
});
|
|
194
|
+
});
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
{
|
|
2
|
+
"apiId": "stats",
|
|
3
|
+
"name": "Stats",
|
|
4
|
+
"description": "Two to four real, checkable figures with short labels that back up the brand story.",
|
|
5
|
+
"icon": "chart-bar",
|
|
6
|
+
"category": "marketing",
|
|
7
|
+
"version": 1,
|
|
8
|
+
"fields": [
|
|
9
|
+
{
|
|
10
|
+
"fieldId": "variant",
|
|
11
|
+
"name": "Variant",
|
|
12
|
+
"type": "select",
|
|
13
|
+
"helpText": "row is the default.",
|
|
14
|
+
"metadata": { "options": ["row", "split"] },
|
|
15
|
+
"validators": { "required": true }
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
"fieldId": "heading",
|
|
19
|
+
"name": "Heading",
|
|
20
|
+
"type": "string",
|
|
21
|
+
"isTitle": true,
|
|
22
|
+
"localized": true,
|
|
23
|
+
"helpText": "Rendered as an h2. Up to about 60 characters.",
|
|
24
|
+
"validators": { "required": true, "maxLength": 60 }
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
"fieldId": "intro",
|
|
28
|
+
"name": "Intro",
|
|
29
|
+
"type": "text",
|
|
30
|
+
"localized": true,
|
|
31
|
+
"helpText": "One or two sentences. Hidden when empty."
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
"fieldId": "items",
|
|
35
|
+
"name": "Items",
|
|
36
|
+
"type": "list",
|
|
37
|
+
"helpText": "2-4 recommended; 1-8 supported.",
|
|
38
|
+
"metadata": {
|
|
39
|
+
"item": {
|
|
40
|
+
"fieldId": "item",
|
|
41
|
+
"name": "Figure",
|
|
42
|
+
"type": "composite",
|
|
43
|
+
"metadata": {
|
|
44
|
+
"fields": [
|
|
45
|
+
{
|
|
46
|
+
"fieldId": "value",
|
|
47
|
+
"name": "Value",
|
|
48
|
+
"type": "string",
|
|
49
|
+
"helpText": "The figure as it should read: 38, 4.8, 140k, 96%. Units belong in the value, not the label.",
|
|
50
|
+
"validators": { "required": true, "maxLength": 6 }
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
"fieldId": "label",
|
|
54
|
+
"name": "Label",
|
|
55
|
+
"type": "string",
|
|
56
|
+
"localized": true,
|
|
57
|
+
"helpText": "What the figure counts and where it comes from.",
|
|
58
|
+
"validators": { "required": true, "maxLength": 60 }
|
|
59
|
+
}
|
|
60
|
+
]
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
"fieldId": "sectionBackground",
|
|
67
|
+
"name": "Section background",
|
|
68
|
+
"type": "select",
|
|
69
|
+
"helpText": "none is the default. surface works well for split.",
|
|
70
|
+
"metadata": { "options": ["none", "surface", "surface-strong", "primary", "accent"] }
|
|
71
|
+
}
|
|
72
|
+
]
|
|
73
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"variant": "row",
|
|
3
|
+
"heading": "Small workshop, long memory",
|
|
4
|
+
"intro": "We started with one loom and a folding table. Everything we sell is still made by people we know by name, and we still read every review.",
|
|
5
|
+
"items": [
|
|
6
|
+
{ "value": "38", "label": "Independent makers, from Shetland to the Kyoto hills" },
|
|
7
|
+
{ "value": "12", "label": "Years since our first market stall" },
|
|
8
|
+
{ "value": "4.8", "label": "Average rating across 9,214 verified reviews" },
|
|
9
|
+
{ "value": "140k", "label": "Mugs, bowls and blankets sent out since 2014" }
|
|
10
|
+
],
|
|
11
|
+
"sectionBackground": "none"
|
|
12
|
+
}
|
|
Binary file
|
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
/**
|
|
3
|
+
* Tabs: related content — care guides, materials, "how it works" by product type — grouped into
|
|
4
|
+
* tabs, each with a heading, rich text, an optional image and a link (spec `02-blocks.md` "Tabs",
|
|
5
|
+
* 2194–2300). Use for 2 to 6 parallel topics; sequential steps belong in Timeline, questions in
|
|
6
|
+
* FAQ. No `variant` field — the underline tab list is the only composition.
|
|
7
|
+
*
|
|
8
|
+
* **Never an accordion.** `@eldrajs/ui`'s `Tabs`/`Tab`/`TabPanel` own the roles, roving tabindex,
|
|
9
|
+
* arrow/Home/End keys and the underline indicator at every width (spec → "Mobile behaviour: tabs
|
|
10
|
+
* scroll sideways, not an accordion"). Below 48rem of block width the tab row bleeds past the
|
|
11
|
+
* `Container`'s own gutter with a matching negative margin, inline padding and scroll padding —
|
|
12
|
+
* `--eldra-gutter-mobile`, the exact variable `Container.vue` itself reads for that breakpoint, is
|
|
13
|
+
* what `tabListClasses` below reads too, since no `-mx-*` bleed precedent exists elsewhere in
|
|
14
|
+
* `blocks/*` to follow instead.
|
|
15
|
+
*
|
|
16
|
+
* **Accessible name.** `Tabs` exposes only an `ariaLabel` prop for the tablist itself — there is no
|
|
17
|
+
* `aria-labelledby`-style prop the way `Section`'s own `labelledBy` works (see `packages/ui/src/
|
|
18
|
+
* components/tabs/types.ts`) — so the tablist's accessible name is the heading's own text passed
|
|
19
|
+
* as plain `ariaLabel`, while `Section` is still `labelled-by` the same heading `id` for the
|
|
20
|
+
* block's own landmark name, exactly like every other rebuilt block.
|
|
21
|
+
*
|
|
22
|
+
* **`defaultTab`.** The spec's own `defaultTab` select can't enumerate a dynamic tab list, so the
|
|
23
|
+
* field is a 1-based `int` (`block.json`), clamped into `[1, tabs.length]` here and turned into a
|
|
24
|
+
* zero-based tab value that seeds `Tabs`' `v-model` once, read synchronously at setup — the same
|
|
25
|
+
* one-shot-seed idea `faq`'s own `itemOpen()` uses for `AccordionItem`, except this one must be a
|
|
26
|
+
* real two-way `v-model`, not a one-way `:model-value`: `useControllableModel` (`@eldrajs/ui`)
|
|
27
|
+
* treats any *defined* `modelValue` as fully controlled and stops mirroring further selections into
|
|
28
|
+
* the value its own `selectedValue` getter reads, so a one-way bind would freeze the display on the
|
|
29
|
+
* initial tab forever the moment a real click or arrow key fired `select()`.
|
|
30
|
+
*
|
|
31
|
+
* `tabs[].body` is full rich text rendered through `EldraRichText` with no `api-id`, for the same
|
|
32
|
+
* reason `faq`'s `items[].answer` and `split-content`'s `rows[].text` have none —
|
|
33
|
+
* `useEldraBlockField`/`isBlockFieldLocalized` only resolve a flat, top-level `fieldId`, and
|
|
34
|
+
* `tabs[].body` lives one level inside a `list` item.
|
|
35
|
+
*
|
|
36
|
+
* "Live site renders nothing without tabs" (spec → States, "Empty (freshly inserted)"): the whole
|
|
37
|
+
* `<Section>` gates on `hasTabs || editing`. The editor's own empty-state hint is a single,
|
|
38
|
+
* non-interactive placeholder tab ("Tab 1") plus a placeholder panel — not a real `Tabs` instance
|
|
39
|
+
* with zero real tabs, which would have nothing to mark `aria-selected` and nothing for arrow keys
|
|
40
|
+
* to move between — so that branch is plain, `aria-hidden` decorative markup, never the package
|
|
41
|
+
* component fed an empty list.
|
|
42
|
+
*/
|
|
43
|
+
import { computed, ref, watch } from 'vue';
|
|
44
|
+
import { Container, EditorPlaceholder, Link, Section, Tab, TabPanel, Tabs } from '@eldrajs/ui';
|
|
45
|
+
import type { SectionBackground } from '@eldrajs/ui';
|
|
46
|
+
import { DEFAULT_IMAGE_FRAMING, EldraRichText, type ImageFraming } from '@eldrajs/theme-vue';
|
|
47
|
+
import { useBlockData } from '../../app/composables/useBlockData';
|
|
48
|
+
import { useEditing } from '../../app/composables/useEditing';
|
|
49
|
+
import { useRichTextScrollRegions } from '../../app/composables/useRichTextScrollRegions';
|
|
50
|
+
import { useI18n } from 'vue-i18n';
|
|
51
|
+
import { useUiId } from '../../app/composables/useUiId';
|
|
52
|
+
import EldraRouterLink from '../../app/components/EldraRouterLink.vue';
|
|
53
|
+
import UiImage from '../../app/components/ui/UiImage.vue';
|
|
54
|
+
import { isInternalHref, safeHref } from '../../app/utils/links';
|
|
55
|
+
|
|
56
|
+
interface TabItem {
|
|
57
|
+
label?: string;
|
|
58
|
+
heading?: string;
|
|
59
|
+
body?: { content?: unknown[] } | null;
|
|
60
|
+
image?: { url: string; altText?: string | null; framing?: ImageFraming | null } | null;
|
|
61
|
+
linkLabel?: string;
|
|
62
|
+
href?: string;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const props = defineProps<{ entry: EldraBlockEntry<'tabs'> }>();
|
|
66
|
+
const { data, entryId } = useBlockData(props, 'tabs');
|
|
67
|
+
const editing = useEditing();
|
|
68
|
+
const { t } = useI18n();
|
|
69
|
+
|
|
70
|
+
const uiId = useUiId();
|
|
71
|
+
const headingId = `tabs-heading-${uiId}`;
|
|
72
|
+
|
|
73
|
+
const heading = computed(() => (data.value.heading ?? '').trim());
|
|
74
|
+
const hasHeading = computed(() => heading.value !== '');
|
|
75
|
+
const showHeadingHint = computed(() => editing.value && !hasHeading.value);
|
|
76
|
+
const headingClass =
|
|
77
|
+
'font-heading text-[1.625rem] leading-[1.15] font-bold tracking-[-0.015em] @tablet:text-h2';
|
|
78
|
+
|
|
79
|
+
const intro = computed(() => (data.value.intro ?? '').trim());
|
|
80
|
+
const hasIntro = computed(() => intro.value !== '');
|
|
81
|
+
const showIntroHint = computed(() => editing.value && !hasIntro.value);
|
|
82
|
+
|
|
83
|
+
const tabs = computed<TabItem[]>(() => data.value.tabs ?? []);
|
|
84
|
+
const hasTabs = computed(() => tabs.value.length > 0);
|
|
85
|
+
|
|
86
|
+
const sectionBackground = computed<SectionBackground>(() => data.value.sectionBackground ?? 'none');
|
|
87
|
+
|
|
88
|
+
function tabValue(index: number): string {
|
|
89
|
+
return String(index);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** Clamps the 1-based `defaultTab` field into `[1, tabs.length]` and returns the matching
|
|
93
|
+
* zero-based index — see the module doc comment for why this only ever runs once, at setup. */
|
|
94
|
+
function clampedDefaultIndex(): number {
|
|
95
|
+
const count = tabs.value.length;
|
|
96
|
+
if (count === 0) return 0;
|
|
97
|
+
const raw = data.value.defaultTab;
|
|
98
|
+
const requested = typeof raw === 'number' && Number.isFinite(raw) ? Math.trunc(raw) : 1;
|
|
99
|
+
return Math.min(Math.max(requested, 1), count) - 1;
|
|
100
|
+
}
|
|
101
|
+
const selectedTab = ref(tabValue(clampedDefaultIndex()));
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* `selectedTab` only ever *seeds* `Tabs`' `v-model` at setup (see the module doc comment on
|
|
105
|
+
* `clampedDefaultIndex`) — it is never re-derived from `tabs` afterwards, so an editor removing
|
|
106
|
+
* tabs (Studio's live preview re-renders this block with a shorter `tabs` list on every edit)
|
|
107
|
+
* could leave it pointing at an index that no longer exists: no `Tab`/`TabPanel` renders for it,
|
|
108
|
+
* nothing is marked `aria-selected`, and the tablist briefly has no selection at all. This watches
|
|
109
|
+
* the tab *count* (not the list identity, which changes on every keystroke inside an existing
|
|
110
|
+
* tab's own fields) and clamps `selectedTab` back into range the moment it shrinks below it,
|
|
111
|
+
* keeping the same relative position rather than jumping to a fixed tab.
|
|
112
|
+
*/
|
|
113
|
+
watch(
|
|
114
|
+
() => tabs.value.length,
|
|
115
|
+
(count) => {
|
|
116
|
+
if (count === 0) return;
|
|
117
|
+
const currentIndex = Number(selectedTab.value);
|
|
118
|
+
if (!Number.isFinite(currentIndex) || currentIndex > count - 1) {
|
|
119
|
+
selectedTab.value = tabValue(Math.min(Math.max(currentIndex, 0), count - 1));
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
);
|
|
123
|
+
|
|
124
|
+
function tabHasImage(tab: TabItem): boolean {
|
|
125
|
+
return Boolean(tab.image);
|
|
126
|
+
}
|
|
127
|
+
function tabImageFraming(tab: TabItem): ImageFraming | undefined {
|
|
128
|
+
return tab.image?.framing ?? DEFAULT_IMAGE_FRAMING;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function tabHref(tab: TabItem): string | null {
|
|
132
|
+
return safeHref(tab.href);
|
|
133
|
+
}
|
|
134
|
+
function tabHasLink(tab: TabItem): boolean {
|
|
135
|
+
return Boolean(tab.linkLabel) && tabHref(tab) !== null;
|
|
136
|
+
}
|
|
137
|
+
function tabLinkAs(tab: TabItem): typeof EldraRouterLink | undefined {
|
|
138
|
+
const href = tabHref(tab);
|
|
139
|
+
return href !== null && isInternalHref(href) ? EldraRouterLink : undefined;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/** Spec → Layout: "panel heading 1.5rem (1.25rem below 48rem)" — the block-heading bracket-value
|
|
143
|
+
* pattern every rebuilt block already uses for its own `h2` (see `headingClass` above), stepped
|
|
144
|
+
* down to `text-h3`'s own numbers (`--eldra-text-h3-*`, `packages/ui/src/styles/tokens.css`) at
|
|
145
|
+
* 48rem instead of `text-h2`'s. Line height is `leading-tight` (Tailwind's `1.25`), matching
|
|
146
|
+
* `--eldra-text-h3-line: 1.25` exactly — `text-h3`'s own token, not the rich-text typography
|
|
147
|
+
* table's unrelated 1.3 for an in-body `h3` (a different scale, spec "Rich-text typography
|
|
148
|
+
* (shared)"); the same `leading-tight` convention every other rebuilt block's bracket-value
|
|
149
|
+
* heading already uses (`cta`, `cart`, `newsletter`). */
|
|
150
|
+
const panelHeadingClass =
|
|
151
|
+
'font-heading text-[1.25rem] leading-tight font-semibold tracking-[-0.01em] @tablet:text-h3';
|
|
152
|
+
|
|
153
|
+
/** Spec → Layout: "the tab row bleeds to the container edges" below 48rem — negative gutter
|
|
154
|
+
* margin plus matching inline and scroll padding, reset once the row sits inside the container
|
|
155
|
+
* from 48rem. `--eldra-gutter-mobile` is the same variable `Container.vue` itself reads for its
|
|
156
|
+
* own mobile gutter; no `-mx-*` bleed precedent exists elsewhere in `blocks/*` to follow instead. */
|
|
157
|
+
const tabListClasses = {
|
|
158
|
+
list:
|
|
159
|
+
'-mx-[var(--eldra-gutter-mobile)] px-[var(--eldra-gutter-mobile)] ' +
|
|
160
|
+
'scroll-px-[var(--eldra-gutter-mobile)] @tablet:mx-0 @tablet:px-0 @tablet:scroll-px-0',
|
|
161
|
+
};
|
|
162
|
+
/** Spec → Layout: "Panel: 2rem top padding." `TabPanel`'s own baked-in default is 1.5rem (see that
|
|
163
|
+
* component's own doc comment) — overridden through the package's sanctioned per-part `classes`
|
|
164
|
+
* prop, never by patching the component itself. */
|
|
165
|
+
const tabPanelClasses = { panel: 'pt-8' };
|
|
166
|
+
|
|
167
|
+
/** Image | copy grid, only when the panel has an image (spec → Layout): stacked below 48rem, two
|
|
168
|
+
* equal columns 48–64rem, `7fr`/`5fr` from 64rem — the same gap steps `split-content`'s own row
|
|
169
|
+
* grid uses for its 48–64rem/64rem+ breakpoints. */
|
|
170
|
+
const IMAGE_PANEL_GRID =
|
|
171
|
+
'gap-6 @tablet:grid-cols-2 @tablet:items-center @tablet:gap-12 @content:grid-cols-[7fr_5fr] @content:gap-16';
|
|
172
|
+
|
|
173
|
+
const panelsRoot = ref<HTMLElement | null>(null);
|
|
174
|
+
useRichTextScrollRegions(panelsRoot, (caption) => caption ?? t('tabsBlock.richTextTableLabel'));
|
|
175
|
+
</script>
|
|
176
|
+
|
|
177
|
+
<template>
|
|
178
|
+
<Section
|
|
179
|
+
v-if="hasTabs || editing"
|
|
180
|
+
:background="sectionBackground"
|
|
181
|
+
spacing="md"
|
|
182
|
+
:labelled-by="headingId"
|
|
183
|
+
>
|
|
184
|
+
<Container width="content">
|
|
185
|
+
<div class="flex flex-col gap-3">
|
|
186
|
+
<h2 v-if="hasHeading" :id="headingId" :class="headingClass">{{ heading }}</h2>
|
|
187
|
+
<EditorPlaceholder
|
|
188
|
+
v-else-if="showHeadingHint"
|
|
189
|
+
:id="headingId"
|
|
190
|
+
inline
|
|
191
|
+
:label="t('tabsBlock.headingHintLabel')"
|
|
192
|
+
/>
|
|
193
|
+
<p v-if="hasIntro" class="text-muted text-body-lg">{{ intro }}</p>
|
|
194
|
+
<EditorPlaceholder
|
|
195
|
+
v-else-if="showIntroHint"
|
|
196
|
+
inline
|
|
197
|
+
:label="t('tabsBlock.introHintLabel')"
|
|
198
|
+
/>
|
|
199
|
+
</div>
|
|
200
|
+
|
|
201
|
+
<div ref="panelsRoot" class="mt-8">
|
|
202
|
+
<Tabs
|
|
203
|
+
v-if="hasTabs"
|
|
204
|
+
v-model="selectedTab"
|
|
205
|
+
variant="underline"
|
|
206
|
+
:ariaLabel="heading"
|
|
207
|
+
activation="auto"
|
|
208
|
+
:classes="tabListClasses"
|
|
209
|
+
>
|
|
210
|
+
<template #tabs>
|
|
211
|
+
<Tab
|
|
212
|
+
v-for="(tab, index) in tabs"
|
|
213
|
+
:key="index"
|
|
214
|
+
:value="tabValue(index)"
|
|
215
|
+
:title="tab.label"
|
|
216
|
+
/>
|
|
217
|
+
</template>
|
|
218
|
+
<TabPanel
|
|
219
|
+
v-for="(tab, index) in tabs"
|
|
220
|
+
:key="index"
|
|
221
|
+
:value="tabValue(index)"
|
|
222
|
+
:classes="tabPanelClasses"
|
|
223
|
+
>
|
|
224
|
+
<div class="grid" :class="tabHasImage(tab) ? IMAGE_PANEL_GRID : ''">
|
|
225
|
+
<UiImage
|
|
226
|
+
v-if="tabHasImage(tab)"
|
|
227
|
+
:src="tab.image!.url"
|
|
228
|
+
:alt="tab.image!.altText ?? ''"
|
|
229
|
+
:framing="tabImageFraming(tab)"
|
|
230
|
+
:entry-id="entryId"
|
|
231
|
+
:field-path="`tabs.${index}.image`"
|
|
232
|
+
aspect="4/3"
|
|
233
|
+
rounded="xl"
|
|
234
|
+
/>
|
|
235
|
+
<div class="flex flex-col gap-4" :class="tabHasImage(tab) ? '' : 'max-w-[40rem]'">
|
|
236
|
+
<h3 :class="panelHeadingClass">{{ tab.heading }}</h3>
|
|
237
|
+
<!-- The panel's own `tab.heading` above is an `h3` (under the block's `h2`), so
|
|
238
|
+
the body's headings start at `h4`. Floored at 4, not 3: an `h3` here would sit
|
|
239
|
+
level with the panel's own title rather than under it. -->
|
|
240
|
+
<EldraRichText
|
|
241
|
+
class="prose-eldra [&>*+*]:mt-3"
|
|
242
|
+
:entry-id="entryId"
|
|
243
|
+
:field="`tabs.${index}.body`"
|
|
244
|
+
:doc="tab.body"
|
|
245
|
+
:min-heading-level="4"
|
|
246
|
+
/>
|
|
247
|
+
<Link
|
|
248
|
+
v-if="tabHasLink(tab)"
|
|
249
|
+
:href="tabHref(tab)!"
|
|
250
|
+
:as="tabLinkAs(tab)"
|
|
251
|
+
variant="standalone"
|
|
252
|
+
arrow
|
|
253
|
+
>
|
|
254
|
+
{{ tab.linkLabel }}
|
|
255
|
+
</Link>
|
|
256
|
+
</div>
|
|
257
|
+
</div>
|
|
258
|
+
</TabPanel>
|
|
259
|
+
</Tabs>
|
|
260
|
+
|
|
261
|
+
<template v-else-if="editing">
|
|
262
|
+
<div class="border-border flex min-h-[2.75rem] items-center border-b" aria-hidden="true">
|
|
263
|
+
<span
|
|
264
|
+
class="border-primary text-body-sm text-text border-b-[0.1875rem] px-4 py-2 font-semibold"
|
|
265
|
+
>
|
|
266
|
+
{{ t('tabsBlock.tabPlaceholderLabel') }}
|
|
267
|
+
</span>
|
|
268
|
+
</div>
|
|
269
|
+
<EditorPlaceholder
|
|
270
|
+
class="mt-6"
|
|
271
|
+
:label="t('tabsBlock.itemHintLabel')"
|
|
272
|
+
:help="t('tabsBlock.itemHintHelp')"
|
|
273
|
+
/>
|
|
274
|
+
</template>
|
|
275
|
+
</div>
|
|
276
|
+
</Container>
|
|
277
|
+
</Section>
|
|
278
|
+
</template>
|