@eldrajs/theme-cli 0.0.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +77 -0
- package/LICENSE +21 -0
- package/README.md +26 -1
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +203 -0
- package/dist/index.d.ts +174 -0
- package/dist/index.js +3 -0
- package/dist/validate-DprFpjV7.js +535 -0
- package/package.json +50 -2
- package/template/.eldra/block-types.d.ts +429 -0
- package/template/.eldra/manifest.json +9378 -0
- package/template/.eldra/previews.json +36 -0
- package/template/.github/workflows/eldra-deploy.yml +24 -0
- package/template/.gitlab-ci.yml +16 -0
- package/template/.storybook/eldra.ts +123 -0
- package/template/.storybook/i18n.ts +23 -0
- package/template/.storybook/main.ts +59 -0
- package/template/.storybook/nuxt-link-stub.ts +23 -0
- package/template/.storybook/preview.ts +53 -0
- package/template/.storybook/shims-vue.d.ts +10 -0
- package/template/.storybook/virtual-eldra.d.ts +32 -0
- package/template/README.md +293 -0
- package/template/app/app.vue +126 -0
- package/template/app/assets/main.css +404 -0
- package/template/app/components/EldraIcon.vue +66 -0
- package/template/app/components/EldraRouterLink.vue +62 -0
- package/template/app/components/ui/UiImage.stories.ts +30 -0
- package/template/app/components/ui/UiImage.vue +224 -0
- package/template/app/components/ui/__tests__/UiImage.spec.ts +292 -0
- package/template/app/composables/iconComponent.ts +84 -0
- package/template/app/composables/iconFetcher.ts +14 -0
- package/template/app/composables/useBlockData.ts +30 -0
- package/template/app/composables/useEditing.ts +31 -0
- package/template/app/composables/useEldraIcon.ts +46 -0
- package/template/app/composables/useRevalidating.ts +69 -0
- package/template/app/composables/useRichTextScrollRegions.ts +80 -0
- package/template/app/composables/useStorefront.ts +18 -0
- package/template/app/composables/useStorefrontFeedback.ts +49 -0
- package/template/app/composables/useUiId.ts +18 -0
- package/template/app/composables/useWishlist.ts +42 -0
- package/template/app/i18n.d.ts +28 -0
- package/template/app/icons.ts +185 -0
- package/template/app/pages/[...slug].vue +134 -0
- package/template/app/plugins/eldra-i18n.ts +98 -0
- package/template/app/plugins/eldra-storefront.ts +288 -0
- package/template/app/plugins/eldra-ui-messages.ts +112 -0
- package/template/app/storefront/cart.ts +245 -0
- package/template/app/storefront/categories.ts +283 -0
- package/template/app/storefront/collectionSelector.ts +60 -0
- package/template/app/storefront/commerce.ts +58 -0
- package/template/app/storefront/demo.ts +1313 -0
- package/template/app/storefront/facets.ts +476 -0
- package/template/app/storefront/feedback.ts +122 -0
- package/template/app/storefront/gateway.ts +2256 -0
- package/template/app/storefront/history.ts +233 -0
- package/template/app/storefront/money.ts +248 -0
- package/template/app/storefront/options.ts +71 -0
- package/template/app/storefront/prerender.ts +77 -0
- package/template/app/storefront/refresh.ts +222 -0
- package/template/app/storefront/toProductCard.ts +154 -0
- package/template/app/storefront/types.ts +815 -0
- package/template/app/storefront/volatile.ts +211 -0
- package/template/app/templates.ts +544 -0
- package/template/app/utils/classes.ts +40 -0
- package/template/app/utils/links.ts +70 -0
- package/template/app/utils/pageStructure.ts +77 -0
- package/template/app/utils/pageTitle.ts +37 -0
- package/template/app/virtual-eldra.d.ts +12 -0
- package/template/bitbucket-pipelines.yml +19 -0
- package/template/blocks/announcement-bar/Block.vue +203 -0
- package/template/blocks/announcement-bar/__tests__/Block.spec.ts +227 -0
- package/template/blocks/announcement-bar/block.json +45 -0
- package/template/blocks/announcement-bar/mock.json +7 -0
- package/template/blocks/announcement-bar/preview.png +0 -0
- package/template/blocks/article/Block.vue +317 -0
- package/template/blocks/article/__tests__/Block.spec.ts +229 -0
- package/template/blocks/article/block.json +148 -0
- package/template/blocks/article/mock.json +512 -0
- package/template/blocks/article/preview.json +16 -0
- package/template/blocks/article/preview.png +0 -0
- package/template/blocks/article-list/Block.vue +343 -0
- package/template/blocks/article-list/__tests__/Block.spec.ts +279 -0
- package/template/blocks/article-list/block.json +181 -0
- package/template/blocks/article-list/mock.json +68 -0
- package/template/blocks/article-list/preview.json +84 -0
- package/template/blocks/article-list/preview.png +0 -0
- package/template/blocks/breadcrumbs/Block.vue +278 -0
- package/template/blocks/breadcrumbs/__tests__/Block.spec.ts +461 -0
- package/template/blocks/breadcrumbs/block.json +89 -0
- package/template/blocks/breadcrumbs/mock.json +11 -0
- package/template/blocks/breadcrumbs/preview.json +3 -0
- package/template/blocks/breadcrumbs/preview.png +0 -0
- package/template/blocks/cart/Block.vue +372 -0
- package/template/blocks/cart/__tests__/Block.spec.ts +561 -0
- package/template/blocks/cart/__tests__/ShippingBar.spec.ts +78 -0
- package/template/blocks/cart/__tests__/Summary.spec.ts +245 -0
- package/template/blocks/cart/block.json +74 -0
- package/template/blocks/cart/mock.json +11 -0
- package/template/blocks/cart/parts/CartLines.vue +257 -0
- package/template/blocks/cart/parts/ShippingBar.vue +105 -0
- package/template/blocks/cart/parts/Summary.vue +291 -0
- package/template/blocks/cart/preview.png +0 -0
- package/template/blocks/collection-grid/Block.vue +1832 -0
- package/template/blocks/collection-grid/__tests__/Block.spec.ts +3037 -0
- package/template/blocks/collection-grid/__tests__/groups.spec.ts +731 -0
- package/template/blocks/collection-grid/block.json +187 -0
- package/template/blocks/collection-grid/mock.json +23 -0
- package/template/blocks/collection-grid/parts/groups.ts +861 -0
- package/template/blocks/collection-grid/preview.json +7 -0
- package/template/blocks/collection-grid/preview.png +0 -0
- package/template/blocks/collection-header/Block.vue +533 -0
- package/template/blocks/collection-header/__tests__/Block.spec.ts +381 -0
- package/template/blocks/collection-header/block.json +140 -0
- package/template/blocks/collection-header/mock.json +28 -0
- package/template/blocks/collection-header/preview.json +14 -0
- package/template/blocks/collection-header/preview.png +0 -0
- package/template/blocks/contact/Block.vue +621 -0
- package/template/blocks/contact/__tests__/Block.spec.ts +347 -0
- package/template/blocks/contact/block.json +174 -0
- package/template/blocks/contact/mock.json +28 -0
- package/template/blocks/contact/preview.json +9 -0
- package/template/blocks/contact/preview.png +0 -0
- package/template/blocks/cta/Block.vue +383 -0
- package/template/blocks/cta/__tests__/Block.spec.ts +309 -0
- package/template/blocks/cta/block.json +86 -0
- package/template/blocks/cta/mock.json +10 -0
- package/template/blocks/cta/preview.json +9 -0
- package/template/blocks/cta/preview.png +0 -0
- package/template/blocks/faq/Block.vue +254 -0
- package/template/blocks/faq/__tests__/Block.spec.ts +312 -0
- package/template/blocks/faq/block.json +113 -0
- package/template/blocks/faq/mock.json +115 -0
- package/template/blocks/faq/preview.png +0 -0
- package/template/blocks/feature-grid/Block.vue +241 -0
- package/template/blocks/feature-grid/__tests__/Block.spec.ts +311 -0
- package/template/blocks/feature-grid/block.json +106 -0
- package/template/blocks/feature-grid/mock.json +29 -0
- package/template/blocks/feature-grid/preview.json +45 -0
- package/template/blocks/feature-grid/preview.png +0 -0
- package/template/blocks/footer/Block.vue +652 -0
- package/template/blocks/footer/__tests__/Block.spec.ts +700 -0
- package/template/blocks/footer/block.json +240 -0
- package/template/blocks/footer/mock.json +161 -0
- package/template/blocks/footer/preview.png +0 -0
- package/template/blocks/gallery/Block.vue +416 -0
- package/template/blocks/gallery/__tests__/Block.spec.ts +289 -0
- package/template/blocks/gallery/block.json +87 -0
- package/template/blocks/gallery/mock.json +16 -0
- package/template/blocks/gallery/preview.json +64 -0
- package/template/blocks/gallery/preview.png +0 -0
- package/template/blocks/hero/Block.vue +378 -0
- package/template/blocks/hero/__tests__/Block.spec.ts +324 -0
- package/template/blocks/hero/block.json +146 -0
- package/template/blocks/hero/mock.json +11 -0
- package/template/blocks/hero/preview.json +55 -0
- package/template/blocks/hero/preview.png +0 -0
- package/template/blocks/image/Block.vue +232 -0
- package/template/blocks/image/__tests__/Block.spec.ts +224 -0
- package/template/blocks/image/block.json +67 -0
- package/template/blocks/image/mock.json +7 -0
- package/template/blocks/image/preview.json +9 -0
- package/template/blocks/image/preview.png +0 -0
- package/template/blocks/logo-cloud/Block.vue +206 -0
- package/template/blocks/logo-cloud/__tests__/Block.spec.ts +210 -0
- package/template/blocks/logo-cloud/block.json +79 -0
- package/template/blocks/logo-cloud/mock.json +15 -0
- package/template/blocks/logo-cloud/preview.json +92 -0
- package/template/blocks/logo-cloud/preview.png +0 -0
- package/template/blocks/navigation/Block.vue +1348 -0
- package/template/blocks/navigation/__tests__/Block.spec.ts +2030 -0
- package/template/blocks/navigation/block.json +167 -0
- package/template/blocks/navigation/mock.json +191 -0
- package/template/blocks/navigation/preview.png +0 -0
- package/template/blocks/navigation/useMegaMenuKeys.ts +276 -0
- package/template/blocks/newsletter/Block.vue +399 -0
- package/template/blocks/newsletter/__tests__/Block.spec.ts +365 -0
- package/template/blocks/newsletter/block.json +105 -0
- package/template/blocks/newsletter/mock.json +31 -0
- package/template/blocks/newsletter/preview.png +0 -0
- package/template/blocks/order-status/Block.vue +754 -0
- package/template/blocks/order-status/__tests__/Block.spec.ts +515 -0
- package/template/blocks/order-status/block.json +138 -0
- package/template/blocks/order-status/mock.json +19 -0
- package/template/blocks/order-status/preview.png +0 -0
- package/template/blocks/pricing-table/Block.vue +297 -0
- package/template/blocks/pricing-table/__tests__/Block.spec.ts +357 -0
- package/template/blocks/pricing-table/block.json +155 -0
- package/template/blocks/pricing-table/mock.json +47 -0
- package/template/blocks/pricing-table/preview.png +0 -0
- package/template/blocks/product-carousel/Block.vue +459 -0
- package/template/blocks/product-carousel/__tests__/Block.spec.ts +957 -0
- package/template/blocks/product-carousel/block.json +71 -0
- package/template/blocks/product-carousel/mock.json +9 -0
- package/template/blocks/product-carousel/preview.json +7 -0
- package/template/blocks/product-carousel/preview.png +0 -0
- package/template/blocks/product-detail/Block.vue +886 -0
- package/template/blocks/product-detail/__tests__/Block.spec.ts +1492 -0
- package/template/blocks/product-detail/__tests__/stock.spec.ts +119 -0
- package/template/blocks/product-detail/block.json +155 -0
- package/template/blocks/product-detail/mock.json +113 -0
- package/template/blocks/product-detail/parts/Gallery.vue +181 -0
- package/template/blocks/product-detail/parts/StickyBuyBar.vue +99 -0
- package/template/blocks/product-detail/preview.png +0 -0
- package/template/blocks/product-detail/stock.ts +150 -0
- package/template/blocks/quote/Block.vue +206 -0
- package/template/blocks/quote/__tests__/Block.spec.ts +265 -0
- package/template/blocks/quote/block.json +76 -0
- package/template/blocks/quote/mock.json +9 -0
- package/template/blocks/quote/preview.json +16 -0
- package/template/blocks/quote/preview.png +0 -0
- package/template/blocks/rich-text/Block.vue +143 -0
- package/template/blocks/rich-text/__tests__/Block.spec.ts +191 -0
- package/template/blocks/rich-text/block.json +57 -0
- package/template/blocks/rich-text/mock.json +87 -0
- package/template/blocks/rich-text/preview.png +0 -0
- package/template/blocks/search/Block.vue +589 -0
- package/template/blocks/search/PopularChips.vue +40 -0
- package/template/blocks/search/TypeSection.vue +148 -0
- package/template/blocks/search/__tests__/Block.spec.ts +718 -0
- package/template/blocks/search/__tests__/results.spec.ts +166 -0
- package/template/blocks/search/block.json +102 -0
- package/template/blocks/search/mock.json +18 -0
- package/template/blocks/search/preview.png +0 -0
- package/template/blocks/search/results.ts +85 -0
- package/template/blocks/split-content/Block.vue +195 -0
- package/template/blocks/split-content/__tests__/Block.spec.ts +225 -0
- package/template/blocks/split-content/block.json +70 -0
- package/template/blocks/split-content/mock.json +45 -0
- package/template/blocks/split-content/preview.json +58 -0
- package/template/blocks/split-content/preview.png +0 -0
- package/template/blocks/stats/Block.vue +159 -0
- package/template/blocks/stats/__tests__/Block.spec.ts +194 -0
- package/template/blocks/stats/block.json +73 -0
- package/template/blocks/stats/mock.json +12 -0
- package/template/blocks/stats/preview.png +0 -0
- package/template/blocks/tabs/Block.vue +278 -0
- package/template/blocks/tabs/__tests__/Block.spec.ts +303 -0
- package/template/blocks/tabs/block.json +97 -0
- package/template/blocks/tabs/mock.json +129 -0
- package/template/blocks/tabs/preview.json +153 -0
- package/template/blocks/tabs/preview.png +0 -0
- package/template/blocks/team/Block.vue +288 -0
- package/template/blocks/team/__tests__/Block.spec.ts +221 -0
- package/template/blocks/team/block.json +125 -0
- package/template/blocks/team/mock.json +39 -0
- package/template/blocks/team/preview.json +62 -0
- package/template/blocks/team/preview.png +0 -0
- package/template/blocks/testimonials/Block.vue +408 -0
- package/template/blocks/testimonials/__tests__/Block.spec.ts +319 -0
- package/template/blocks/testimonials/block.json +121 -0
- package/template/blocks/testimonials/mock.json +46 -0
- package/template/blocks/testimonials/preview.json +68 -0
- package/template/blocks/testimonials/preview.png +0 -0
- package/template/blocks/timeline/Block.vue +274 -0
- package/template/blocks/timeline/__tests__/Block.spec.ts +310 -0
- package/template/blocks/timeline/block.json +98 -0
- package/template/blocks/timeline/mock.json +27 -0
- package/template/blocks/timeline/preview.png +0 -0
- package/template/blocks/trust-strip/Block.vue +330 -0
- package/template/blocks/trust-strip/__tests__/Block.spec.ts +290 -0
- package/template/blocks/trust-strip/block.json +117 -0
- package/template/blocks/trust-strip/mock.json +37 -0
- package/template/blocks/trust-strip/preview.png +0 -0
- package/template/blocks/video-embed/Block.vue +354 -0
- package/template/blocks/video-embed/__tests__/Block.spec.ts +219 -0
- package/template/blocks/video-embed/__tests__/embed.spec.ts +76 -0
- package/template/blocks/video-embed/block.json +94 -0
- package/template/blocks/video-embed/embed.ts +84 -0
- package/template/blocks/video-embed/mock.json +13 -0
- package/template/blocks/video-embed/preview.json +9 -0
- package/template/blocks/video-embed/preview.png +0 -0
- package/template/blocks/wishlist/Block.vue +367 -0
- package/template/blocks/wishlist/__tests__/Block.spec.ts +508 -0
- package/template/blocks/wishlist/block.json +42 -0
- package/template/blocks/wishlist/mock.json +9 -0
- package/template/blocks/wishlist/preview.png +0 -0
- package/template/i18n/en-US.json +602 -0
- package/template/i18n/is-IS.json +602 -0
- package/template/nuxt.config.ts +156 -0
- package/template/package.json +56 -0
- package/template/pages/article.page.json +731 -0
- package/template/pages/cart.page.json +85 -0
- package/template/pages/category.page.json +133 -0
- package/template/pages/collection.page.json +194 -0
- package/template/pages/home.page.json +353 -0
- package/template/pages/product.page.json +323 -0
- package/template/pages/products.page.json +144 -0
- package/template/pages/search.page.json +83 -0
- package/template/pages/wishlist.page.json +88 -0
- package/template/public/apple-touch-icon.png +0 -0
- package/template/public/demo/article-cover.svg +1 -0
- package/template/public/demo/article-figure.svg +1 -0
- package/template/public/demo/avatar-1.svg +3 -0
- package/template/public/demo/avatar-2.svg +3 -0
- package/template/public/demo/avatar-3.svg +3 -0
- package/template/public/demo/avatar-4.svg +3 -0
- package/template/public/demo/avatar-5.svg +3 -0
- package/template/public/demo/avatar-6.svg +3 -0
- package/template/public/demo/avatar-7.svg +3 -0
- package/template/public/demo/avatar-8.svg +3 -0
- package/template/public/demo/collection-1.svg +1 -0
- package/template/public/demo/collection-2.svg +1 -0
- package/template/public/demo/cta-split.svg +1 -0
- package/template/public/demo/feature-1.svg +1 -0
- package/template/public/demo/feature-2.svg +1 -0
- package/template/public/demo/feature-3.svg +1 -0
- package/template/public/demo/feature-4.svg +1 -0
- package/template/public/demo/gallery-1.svg +1 -0
- package/template/public/demo/gallery-2.svg +1 -0
- package/template/public/demo/gallery-3.svg +1 -0
- package/template/public/demo/gallery-4.svg +1 -0
- package/template/public/demo/gallery-5.svg +1 -0
- package/template/public/demo/gallery-6.svg +1 -0
- package/template/public/demo/gallery-7.svg +1 -0
- package/template/public/demo/gallery-8.svg +1 -0
- package/template/public/demo/hero-slide-1.svg +1 -0
- package/template/public/demo/hero-slide-2.svg +1 -0
- package/template/public/demo/hero-slide-3.svg +1 -0
- package/template/public/demo/hero-slide-4.svg +1 -0
- package/template/public/demo/hero-wide.svg +1 -0
- package/template/public/demo/hero.svg +1 -0
- package/template/public/demo/logo-1.svg +4 -0
- package/template/public/demo/logo-2.svg +4 -0
- package/template/public/demo/logo-3.svg +4 -0
- package/template/public/demo/logo-4.svg +4 -0
- package/template/public/demo/logo-5.svg +4 -0
- package/template/public/demo/logo-6.svg +4 -0
- package/template/public/demo/logo-7.svg +4 -0
- package/template/public/demo/logo-8.svg +4 -0
- package/template/public/demo/logo.svg +3 -0
- package/template/public/demo/map.svg +1 -0
- package/template/public/demo/poster.svg +1 -0
- package/template/public/demo/product-1.svg +4 -0
- package/template/public/demo/product-10.svg +4 -0
- package/template/public/demo/product-11.svg +4 -0
- package/template/public/demo/product-12.svg +4 -0
- package/template/public/demo/product-2.svg +4 -0
- package/template/public/demo/product-3.svg +4 -0
- package/template/public/demo/product-4.svg +4 -0
- package/template/public/demo/product-5.svg +4 -0
- package/template/public/demo/product-6.svg +4 -0
- package/template/public/demo/product-7.svg +4 -0
- package/template/public/demo/product-8.svg +4 -0
- package/template/public/demo/product-9.svg +4 -0
- package/template/public/demo/product-square-1.svg +4 -0
- package/template/public/demo/product-square-2.svg +4 -0
- package/template/public/demo/product-square-3.svg +4 -0
- package/template/public/demo/product-square-4.svg +4 -0
- package/template/public/demo/product-square-5.svg +4 -0
- package/template/public/demo/product-square-6.svg +4 -0
- package/template/public/demo/quote-portrait.svg +4 -0
- package/template/public/demo/split-1.svg +1 -0
- package/template/public/demo/split-2.svg +1 -0
- package/template/public/demo/split-3.svg +1 -0
- package/template/public/demo/split-4.svg +1 -0
- package/template/public/demo/team-1.svg +4 -0
- package/template/public/demo/team-2.svg +4 -0
- package/template/public/demo/team-3.svg +4 -0
- package/template/public/demo/team-4.svg +4 -0
- package/template/public/favicon.ico +0 -0
- package/template/scripts/demo-images.mjs +393 -0
- package/template/scripts/generate-stories.mjs +156 -0
- package/template/scripts/previewHash.mjs +125 -0
- package/template/scripts/previews.mjs +149 -0
- package/template/stories/generated/announcement-bar.stories.ts +44 -0
- package/template/stories/generated/article-list.stories.ts +87 -0
- package/template/stories/generated/article.stories.ts +27 -0
- package/template/stories/generated/breadcrumbs.stories.ts +39 -0
- package/template/stories/generated/cart.stories.ts +38 -0
- package/template/stories/generated/collection-grid.stories.ts +117 -0
- package/template/stories/generated/collection-header.stories.ts +51 -0
- package/template/stories/generated/contact.stories.ts +45 -0
- package/template/stories/generated/cta.stories.ts +51 -0
- package/template/stories/generated/faq.stories.ts +56 -0
- package/template/stories/generated/feature-grid.stories.ts +69 -0
- package/template/stories/generated/footer.stories.ts +50 -0
- package/template/stories/generated/gallery.stories.ts +81 -0
- package/template/stories/generated/hero.stories.ts +75 -0
- package/template/stories/generated/image.stories.ts +99 -0
- package/template/stories/generated/logo-cloud.stories.ts +57 -0
- package/template/stories/generated/navigation.stories.ts +62 -0
- package/template/stories/generated/newsletter.stories.ts +68 -0
- package/template/stories/generated/order-status.stories.ts +32 -0
- package/template/stories/generated/pricing-table.stories.ts +44 -0
- package/template/stories/generated/product-carousel.stories.ts +75 -0
- package/template/stories/generated/product-detail.stories.ts +62 -0
- package/template/stories/generated/quote.stories.ts +69 -0
- package/template/stories/generated/rich-text.stories.ts +50 -0
- package/template/stories/generated/search.stories.ts +56 -0
- package/template/stories/generated/split-content.stories.ts +39 -0
- package/template/stories/generated/stats.stories.ts +68 -0
- package/template/stories/generated/tabs.stories.ts +45 -0
- package/template/stories/generated/team.stories.ts +45 -0
- package/template/stories/generated/testimonials.stories.ts +69 -0
- package/template/stories/generated/timeline.stories.ts +80 -0
- package/template/stories/generated/trust-strip.stories.ts +62 -0
- package/template/stories/generated/video-embed.stories.ts +63 -0
- package/template/stories/generated/wishlist.stories.ts +26 -0
- package/template/stories/pages/article.stories.ts +51 -0
- package/template/stories/pages/cart.stories.ts +56 -0
- package/template/stories/pages/category.stories.ts +56 -0
- package/template/stories/pages/collection.stories.ts +51 -0
- package/template/stories/pages/home.stories.ts +51 -0
- package/template/stories/pages/product.stories.ts +47 -0
- package/template/stories/pages/products.stories.ts +58 -0
- package/template/stories/pages/search.stories.ts +54 -0
- package/template/stories/pages/wishlist.stories.ts +53 -0
- package/template/stories/support/pageBlocks.ts +115 -0
- package/template/test/blocksEmptyData.spec.ts +52 -0
- package/template/test/carouselKeyboard.spec.ts +272 -0
- package/template/test/carouselRing.browser.spec.ts +193 -0
- package/template/test/carouselSlideWidth.browser.spec.ts +102 -0
- package/template/test/cartDrawer.spec.ts +295 -0
- package/template/test/cartToast.spec.ts +86 -0
- package/template/test/countPill.browser.spec.ts +196 -0
- package/template/test/demoImages.spec.ts +140 -0
- package/template/test/deps.spec.ts +102 -0
- package/template/test/eldraIcon.spec.ts +58 -0
- package/template/test/framing.spec.ts +76 -0
- package/template/test/i18n.spec.ts +200 -0
- package/template/test/iconComponent.spec.ts +91 -0
- package/template/test/inlineEditable.spec.ts +335 -0
- package/template/test/localePrefix.spec.ts +342 -0
- package/template/test/mainCss.spec.ts +107 -0
- package/template/test/mockGatewayContract.spec.ts +122 -0
- package/template/test/mocks/blocks.ts +20 -0
- package/template/test/mocks/breakpoints.ts +7 -0
- package/template/test/mocks/manifest.ts +11 -0
- package/template/test/moneyFormatting.spec.ts +85 -0
- package/template/test/pageTitle.spec.ts +49 -0
- package/template/test/pages/article.spec.ts +231 -0
- package/template/test/pages/category.spec.ts +185 -0
- package/template/test/pages/collection.spec.ts +396 -0
- package/template/test/pages/home.spec.ts +295 -0
- package/template/test/pages/hydration.spec.ts +557 -0
- package/template/test/pages/product.spec.ts +396 -0
- package/template/test/pages/seededPages.spec.ts +190 -0
- package/template/test/pages/ssr.spec.ts +387 -0
- package/template/test/prerenderCommerce.spec.ts +134 -0
- package/template/test/prerenderFailure.spec.ts +130 -0
- package/template/test/prerenderRefresh.browser.spec.ts +1431 -0
- package/template/test/previewsFresh.spec.ts +56 -0
- package/template/test/richText.spec.ts +164 -0
- package/template/test/richTextTypography.spec.ts +182 -0
- package/template/test/setup.ts +21 -0
- package/template/test/slugPage.spec.ts +244 -0
- package/template/test/slugPageTemplate.spec.ts +194 -0
- package/template/test/starter.spec.ts +1416 -0
- package/template/test/storefront/cart.spec.ts +404 -0
- package/template/test/storefront/categories.spec.ts +235 -0
- package/template/test/storefront/collectionSelector.spec.ts +74 -0
- package/template/test/storefront/demo.spec.ts +555 -0
- package/template/test/storefront/facets.spec.ts +425 -0
- package/template/test/storefront/feedback.spec.ts +97 -0
- package/template/test/storefront/gateway.spec.ts +2673 -0
- package/template/test/storefront/gatewayCart.spec.ts +289 -0
- package/template/test/storefront/gatewayPrerender.spec.ts +1037 -0
- package/template/test/storefront/history.spec.ts +341 -0
- package/template/test/storefront/money.spec.ts +170 -0
- package/template/test/storefront/toProductCard.spec.ts +138 -0
- package/template/test/storefront/volatile.spec.ts +284 -0
- package/template/test/support/axe.ts +14 -0
- package/template/test/support/dialog.ts +51 -0
- package/template/test/support/hydrate.ts +118 -0
- package/template/test/support/i18nText.ts +11 -0
- package/template/test/support/mockGateway.ts +1017 -0
- package/template/test/support/mountBlock.ts +194 -0
- package/template/test/support/mountPage.spec.ts +72 -0
- package/template/test/support/mountPage.ts +254 -0
- package/template/test/support/mountProbe.client.ts +69 -0
- package/template/test/support/renderSsr.ts +97 -0
- package/template/test/support/staticServer.ts +96 -0
- package/template/test/themeIcons.spec.ts +140 -0
- package/template/test/toastAnnouncement.spec.ts +133 -0
- package/template/test/tokens.spec.ts +102 -0
- package/template/test/uiMessagesPlugin.spec.ts +104 -0
- package/template/test/useBlockData.spec.ts +49 -0
- package/template/test/useEditing.spec.ts +54 -0
- package/template/test/useEldraIcon.spec.ts +126 -0
- package/template/test/useUiId.spec.ts +40 -0
- package/template/tokens.json +149 -0
- package/template/tsconfig.json +3 -0
- package/template/tsconfig.storybook.json +17 -0
- package/template/vitest-axe.d.ts +13 -0
- package/template/vitest.config.ts +44 -0
|
@@ -0,0 +1,544 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { fileURLToPath } from 'node:url';
|
|
3
|
+
import type {
|
|
4
|
+
DeclaredPageSeed,
|
|
5
|
+
DeclaredSeed,
|
|
6
|
+
DeclaredTemplateSeed,
|
|
7
|
+
DeclaredTemplateSeedBlock,
|
|
8
|
+
ManifestTemplateRoles,
|
|
9
|
+
} from '@eldrajs/vite-plugin-theme';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* The default pages and route templates this theme seeds a site with on its
|
|
13
|
+
* first deploy, built from the sample pages in `pages/*.page.json` so there is
|
|
14
|
+
* exactly one copy of the starter's product, collection, category, home, cart,
|
|
15
|
+
* wishlist and search page — the one Storybook renders
|
|
16
|
+
* (`stories/pages/*.stories.ts`), the one `test/pages/*.spec.ts` exercises, and
|
|
17
|
+
* the one a merchant lands in the page builder with.
|
|
18
|
+
*
|
|
19
|
+
* Read at config time only: `nuxt.config.ts` passes the result to
|
|
20
|
+
* `eldra.templates` / `eldra.templateRoles`, which
|
|
21
|
+
* `@eldrajs/vite-plugin-theme` validates and writes into
|
|
22
|
+
* `.eldra/manifest.json`; Core seeds from that on deploy. Nothing here ships
|
|
23
|
+
* in the browser bundle, which is why `node:fs` is fine in an `app/` file
|
|
24
|
+
* (nothing under `app/` imports this module — only `nuxt.config.ts` and the
|
|
25
|
+
* starter's own tests do).
|
|
26
|
+
*
|
|
27
|
+
* Three shapes leave this file:
|
|
28
|
+
*
|
|
29
|
+
* - `starterTemplates()` — one seed per template. Its `blocks` are the
|
|
30
|
+
* fixture's blocks **minus** `navigation` and `footer`: those two travel
|
|
31
|
+
* separately as roles (below) and the scanner's `header`/`footer` switches
|
|
32
|
+
* (default true) place them around every seed, so Core resolves them to the
|
|
33
|
+
* site's own reusable components rather than seeding a second copy per page.
|
|
34
|
+
* A catalog seed also drops everything that names the fixture's own product or
|
|
35
|
+
* collection (`CATALOG_SEED_SHAPE`, `CATALOG_SEED_DROPPED_ITEMS`), binding the
|
|
36
|
+
* fields the routed object carries itself, so each page renders the object its
|
|
37
|
+
* route resolved.
|
|
38
|
+
* - `starterPages()` — one **page** seed per fixture that declares
|
|
39
|
+
* `page: { slug }` rather than backing a route template: `/cart`,
|
|
40
|
+
* `/wishlist` and `/search`, which used to be code routes under `app/pages/`
|
|
41
|
+
* and are now documents a merchant composes. Their blocks are the fixture's
|
|
42
|
+
* minus the same two roles, and the one block the page exists for carries
|
|
43
|
+
* `required: true`, so Core creates its layout node locked and an author can
|
|
44
|
+
* reorder it and edit its copy but never delete it.
|
|
45
|
+
* - `starterTemplateRoles()` — the `navigation` and `footer` block data behind
|
|
46
|
+
* those roles, taken from the home page fixture (every fixture carries the
|
|
47
|
+
* same header and footer).
|
|
48
|
+
*
|
|
49
|
+
* `starterSeeds()` is the two seed halves in one list, which is what
|
|
50
|
+
* `eldra.templates` takes (`nuxt.config.ts` and `.storybook/main.ts` both pass
|
|
51
|
+
* it, so the `.eldra/manifest.json` the two builds write is the same file).
|
|
52
|
+
*
|
|
53
|
+
* Both run their block data through `stripSeedMedia`, because a seed is the
|
|
54
|
+
* write Core makes on deploy and the CMS only accepts `{ assetId: <uuid> }`
|
|
55
|
+
* for a media field — exactly the rule `mock.json` obeys. The sample pages
|
|
56
|
+
* carry demo imagery (`{ assetId: "demo-hero", url, altText, … }`) for
|
|
57
|
+
* Storybook and the page specs, and that cannot be seeded.
|
|
58
|
+
*/
|
|
59
|
+
|
|
60
|
+
/** The block a role's data comes from, and the block a seed therefore drops. */
|
|
61
|
+
const ROLE_BLOCKS = { header: 'navigation', footer: 'footer' } as const;
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* How a **catalog** seed differs from the sample page it is built from, per
|
|
65
|
+
* block.
|
|
66
|
+
*
|
|
67
|
+
* A sample page names one product and one collection — that is what makes it a
|
|
68
|
+
* realistic page — and a route template must name none: it renders whatever
|
|
69
|
+
* object its `:slug` resolved to. Every field below either says which object to
|
|
70
|
+
* show (a product handle, a collection reference), or repeats the fixture's own
|
|
71
|
+
* copy for it (a title, a description, a trail, a link into its category), so a
|
|
72
|
+
* seed drops it and, where the routed object carries the same thing, binds the
|
|
73
|
+
* field to it instead:
|
|
74
|
+
*
|
|
75
|
+
* - `strip` — dropped outright. The commerce blocks read the route when their
|
|
76
|
+
* own field is empty (`storefront.route.productHandle` /
|
|
77
|
+
* `collectionHandle`, the "field wins, route is the fallback" contract each
|
|
78
|
+
* block's own `helpText` describes), and the editorial fields fall back to the
|
|
79
|
+
* storefront object the same way.
|
|
80
|
+
* - `emptyLists` — emptied rather than dropped, for a list whose items are the
|
|
81
|
+
* fixture's own levels or links and where an empty list is a shape the block
|
|
82
|
+
* already renders (`breadcrumbs`' `trail`, which still shows the Home crumb
|
|
83
|
+
* from `showHome`; `collection-header`'s `subcollections`).
|
|
84
|
+
* - `templates` — the text templates the seed's layout node carries, so the
|
|
85
|
+
* block shows the routed object's own value (`{{ title }}` resolves against
|
|
86
|
+
* the catalog projection `@eldrajs/theme-nuxt` binds a catalog route to).
|
|
87
|
+
*
|
|
88
|
+
* `product-carousel` appears here for the **product** seed only — its `related`
|
|
89
|
+
* variant reads the route — while the home seed keeps its `sourceCollection`,
|
|
90
|
+
* because `/` has no route context to fall back to and the carousel has no route
|
|
91
|
+
* fallback at all. That seed names the collection by slug
|
|
92
|
+
* (`{ "_type": "collection", "slug": "the-winter-edit" }`), the only form a
|
|
93
|
+
* theme can ship: Core resolves it against the organisation's own catalog on
|
|
94
|
+
* deploy, and leaves the field empty when nothing matches.
|
|
95
|
+
*
|
|
96
|
+
* Two fields are stripped without a binding on purpose. `collection-header`'s
|
|
97
|
+
* `description` is rich text and a text template renders a string, so there is
|
|
98
|
+
* nothing to bind it to; the block already falls back to the collection's own
|
|
99
|
+
* description, which is the same value. `product-carousel`'s `viewAllHref`
|
|
100
|
+
* points at the fixture product's category, and no projection path holds the
|
|
101
|
+
* routed product's category URL.
|
|
102
|
+
*
|
|
103
|
+
* The **category** seed needs no shape of its own: it reuses the same three
|
|
104
|
+
* entries (`breadcrumbs`, `collection-header`, `collection-grid`), and every one
|
|
105
|
+
* of them says the same thing about a category as about a collection — drop the
|
|
106
|
+
* fixture's own object and bind the routed one's `{{ title }}`. The category's
|
|
107
|
+
* own ancestors, children and products are read from the route rather than
|
|
108
|
+
* bound, so there is nothing more for a seed to say.
|
|
109
|
+
*/
|
|
110
|
+
const CATALOG_SEED_SHAPE: Readonly<
|
|
111
|
+
Record<
|
|
112
|
+
string,
|
|
113
|
+
{
|
|
114
|
+
strip?: readonly string[];
|
|
115
|
+
emptyLists?: readonly string[];
|
|
116
|
+
templates?: Readonly<Record<string, string>>;
|
|
117
|
+
}
|
|
118
|
+
>
|
|
119
|
+
> = {
|
|
120
|
+
breadcrumbs: {
|
|
121
|
+
strip: ['currentTitle'],
|
|
122
|
+
emptyLists: ['trail'],
|
|
123
|
+
templates: { currentTitle: '{{ title }}' },
|
|
124
|
+
},
|
|
125
|
+
'product-detail': { strip: ['productHandle'] },
|
|
126
|
+
'product-carousel': { strip: ['viewAllHref'] },
|
|
127
|
+
'collection-header': {
|
|
128
|
+
strip: ['collection', 'title', 'description'],
|
|
129
|
+
emptyLists: ['trail', 'subcollections'],
|
|
130
|
+
templates: { title: '{{ title }}' },
|
|
131
|
+
},
|
|
132
|
+
'collection-grid': { strip: ['collection'] },
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* List items a catalog seed drops, named by the item field a reader recognises
|
|
137
|
+
* them by. One case today: `product-detail`'s "Details" tab is the fixture
|
|
138
|
+
* product's own description ("extra-fine Merino…, 17.5 micron, model is 180 cm")
|
|
139
|
+
* — copy about one product, in a tab every product would show. The block has no
|
|
140
|
+
* other place for a product description, so the seeded template keeps only the
|
|
141
|
+
* store-wide tabs (Shipping, Returns). Binding `tabs.0.body` to the routed
|
|
142
|
+
* product's `description` was the alternative and was not taken: a binding into
|
|
143
|
+
* a list index fails the whole layout render once an editor reorders or removes
|
|
144
|
+
* that tab, which is not a failure mode to seed a merchant's product page with.
|
|
145
|
+
*/
|
|
146
|
+
const CATALOG_SEED_DROPPED_ITEMS: Readonly<
|
|
147
|
+
Record<string, { list: string; itemField: string; values: readonly string[] }>
|
|
148
|
+
> = {
|
|
149
|
+
'product-detail': { list: 'tabs', itemField: 'label', values: ['Details'] },
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Title is the *template's* name in Studio's template list, not the sample
|
|
154
|
+
* page's own title — `pages/collection.page.json` is titled "The winter edit",
|
|
155
|
+
* which names one collection rather than the template every collection renders
|
|
156
|
+
* through.
|
|
157
|
+
*/
|
|
158
|
+
const SEEDS: ReadonlyArray<{
|
|
159
|
+
fixture: string;
|
|
160
|
+
routePattern: string;
|
|
161
|
+
schemaApiId: DeclaredTemplateSeed['schemaApiId'];
|
|
162
|
+
title: string;
|
|
163
|
+
}> = [
|
|
164
|
+
{
|
|
165
|
+
fixture: 'product',
|
|
166
|
+
routePattern: '/products/:slug',
|
|
167
|
+
schemaApiId: 'catalog:product',
|
|
168
|
+
title: 'Product',
|
|
169
|
+
},
|
|
170
|
+
{
|
|
171
|
+
fixture: 'collection',
|
|
172
|
+
routePattern: '/collections/:slug',
|
|
173
|
+
schemaApiId: 'catalog:collection',
|
|
174
|
+
title: 'Collection',
|
|
175
|
+
},
|
|
176
|
+
// A category is addressed by its **canonical path** — the slugs of its ancestors, root first,
|
|
177
|
+
// then its own — so its pattern's trailing parameter is the catch-all `:path*` rather than
|
|
178
|
+
// `:slug`, and the route resolves `/categories/billinn/bilstolar` and nothing else for it
|
|
179
|
+
// (canonical only, no redirects).
|
|
180
|
+
{
|
|
181
|
+
fixture: 'category',
|
|
182
|
+
routePattern: '/categories/:path*',
|
|
183
|
+
schemaApiId: 'catalog:category',
|
|
184
|
+
title: 'Category',
|
|
185
|
+
},
|
|
186
|
+
{ fixture: 'home', routePattern: '/', schemaApiId: 'home', title: 'Home' },
|
|
187
|
+
];
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* The fixtures that seed a **page** rather than a route template, and — for
|
|
191
|
+
* each — the one block the page exists for, whose node Core creates locked.
|
|
192
|
+
*
|
|
193
|
+
* Naming the block rather than reading a flag out of the fixture keeps the
|
|
194
|
+
* fixture a plain page document: `pages/cart.page.json` is the same shape a CMS
|
|
195
|
+
* page has, and "this one cannot be deleted" is a fact about the seed, not
|
|
196
|
+
* about the page a merchant ends up editing.
|
|
197
|
+
*/
|
|
198
|
+
const PAGE_SEEDS: ReadonlyArray<{ fixture: string; required: string }> = [
|
|
199
|
+
{ fixture: 'cart', required: 'cart' },
|
|
200
|
+
{ fixture: 'wishlist', required: 'wishlist' },
|
|
201
|
+
{ fixture: 'search', required: 'search' },
|
|
202
|
+
// `/products` — the catalogue. A **page**, not a route template, which is also what keeps it from
|
|
203
|
+
// colliding with the product template's `/products/:slug`: `resolveRoute` matches an exact static
|
|
204
|
+
// page before it tries any pattern (`@eldrajs/theme-core`'s `dynamicRoute.ts`), so the two coexist
|
|
205
|
+
// and the page wins its own path. Its grid is the required block: a catalogue page without the
|
|
206
|
+
// catalogue is not a page a merchant should be able to empty by accident.
|
|
207
|
+
{ fixture: 'products', required: 'collection-grid' },
|
|
208
|
+
];
|
|
209
|
+
|
|
210
|
+
/** Every seed `eldra.templates` carries: the route templates, then the pages. */
|
|
211
|
+
export function starterSeeds(): DeclaredSeed[] {
|
|
212
|
+
return [...starterTemplates(), ...starterPages()];
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* The seeded pages, in manifest declaration order.
|
|
217
|
+
*
|
|
218
|
+
* A page seed has no layout: its entry list **is** the page, in the fixture's
|
|
219
|
+
* own block order, and Core lays it out in one column. So unlike a template
|
|
220
|
+
* seed — which drops the two role blocks and lets the scanner's
|
|
221
|
+
* `header`/`footer` switches frame the generated layout — this maps each of
|
|
222
|
+
* them to a *region placement* where it stands: `navigation` becomes
|
|
223
|
+
* `{ role: 'header' }` and `footer` becomes `{ role: 'footer' }`, keeping the
|
|
224
|
+
* announcement bar above the header exactly as the fixture has it. Their block
|
|
225
|
+
* data still travels once, as `starterTemplateRoles()`, and Core resolves each
|
|
226
|
+
* placement to the site's own reusable component, so every seeded page and
|
|
227
|
+
* template shares one header and one footer.
|
|
228
|
+
*
|
|
229
|
+
* The slug and title come from the fixture itself rather than from a second
|
|
230
|
+
* table, so `pages/cart.page.json` is the only place `/cart`'s own identity is
|
|
231
|
+
* written down.
|
|
232
|
+
*/
|
|
233
|
+
export function starterPages(): DeclaredPageSeed[] {
|
|
234
|
+
return PAGE_SEEDS.map((seed) => {
|
|
235
|
+
const fixture = pageFixture(seed.fixture);
|
|
236
|
+
if (fixture.page === undefined) {
|
|
237
|
+
throw new Error(
|
|
238
|
+
`pages/${seed.fixture}.page.json seeds a page, so it must declare "page": { "slug": … }`
|
|
239
|
+
);
|
|
240
|
+
}
|
|
241
|
+
if (!fixture.blocks.some((block) => block.apiId === seed.required)) {
|
|
242
|
+
throw new Error(
|
|
243
|
+
`pages/${seed.fixture}.page.json must carry a "${seed.required}" block — it is the block ` +
|
|
244
|
+
'the page exists for, and the seed marks its node required'
|
|
245
|
+
);
|
|
246
|
+
}
|
|
247
|
+
return {
|
|
248
|
+
page: { slug: fixture.page.slug },
|
|
249
|
+
title: fixture.title,
|
|
250
|
+
blocks: fixture.blocks.map((block) => {
|
|
251
|
+
const role = roleOf(block.apiId);
|
|
252
|
+
if (role !== null) return { role };
|
|
253
|
+
return {
|
|
254
|
+
apiId: block.apiId,
|
|
255
|
+
data: stripSeedMedia(block.data, blockFields(block.apiId), block.apiId),
|
|
256
|
+
...(block.apiId === seed.required ? { required: true as const } : {}),
|
|
257
|
+
};
|
|
258
|
+
}),
|
|
259
|
+
};
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
/** The seed templates, in manifest declaration order. */
|
|
264
|
+
export function starterTemplates(): DeclaredTemplateSeed[] {
|
|
265
|
+
return SEEDS.map((seed) => ({
|
|
266
|
+
routePattern: seed.routePattern,
|
|
267
|
+
schemaApiId: seed.schemaApiId,
|
|
268
|
+
title: seed.title,
|
|
269
|
+
// `header`/`footer` are left at their default (true), so the generated
|
|
270
|
+
// layout is one column: header role, the blocks below in fixture order,
|
|
271
|
+
// footer role.
|
|
272
|
+
blocks: pageFixture(seed.fixture)
|
|
273
|
+
.blocks.filter((block) => !isRoleBlock(block.apiId))
|
|
274
|
+
.map((block) => seedBlock(block, seed.schemaApiId !== 'home')),
|
|
275
|
+
}));
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* One fixture block as a seed block: its data with everything that names the
|
|
280
|
+
* fixture's own product or collection removed (catalog templates only — see
|
|
281
|
+
* `CATALOG_SEED_SHAPE` and `CATALOG_SEED_DROPPED_ITEMS`), then the media strip
|
|
282
|
+
* every seed goes through, plus the template bindings its layout node carries.
|
|
283
|
+
*/
|
|
284
|
+
function seedBlock(block: PageFixtureBlock, catalogRoute: boolean): DeclaredTemplateSeedBlock {
|
|
285
|
+
const data = { ...block.data };
|
|
286
|
+
const shape = catalogRoute ? CATALOG_SEED_SHAPE[block.apiId] : undefined;
|
|
287
|
+
for (const fieldId of shape?.strip ?? []) delete data[fieldId];
|
|
288
|
+
for (const fieldId of shape?.emptyLists ?? []) {
|
|
289
|
+
if (Array.isArray(data[fieldId])) data[fieldId] = [];
|
|
290
|
+
}
|
|
291
|
+
const dropped = catalogRoute ? CATALOG_SEED_DROPPED_ITEMS[block.apiId] : undefined;
|
|
292
|
+
if (dropped !== undefined && Array.isArray(data[dropped.list])) {
|
|
293
|
+
data[dropped.list] = (data[dropped.list] as unknown[]).filter(
|
|
294
|
+
(item) => !(isRecord(item) && dropped.values.includes(String(item[dropped.itemField])))
|
|
295
|
+
);
|
|
296
|
+
}
|
|
297
|
+
return {
|
|
298
|
+
id: block.id,
|
|
299
|
+
apiId: block.apiId,
|
|
300
|
+
data: stripSeedMedia(data, blockFields(block.apiId), block.apiId),
|
|
301
|
+
...(shape?.templates === undefined ? {} : { templates: { ...shape.templates } }),
|
|
302
|
+
};
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
/** The `header`/`footer` block data every seed's layout places. */
|
|
306
|
+
export function starterTemplateRoles(): ManifestTemplateRoles {
|
|
307
|
+
const home = pageFixture('home');
|
|
308
|
+
const role = (apiId: string): { apiId: string; data: Record<string, unknown> } => {
|
|
309
|
+
const block = home.blocks.find((candidate) => candidate.apiId === apiId);
|
|
310
|
+
if (block === undefined) {
|
|
311
|
+
throw new Error(`pages/home.page.json declares no "${apiId}" block to seed the role from`);
|
|
312
|
+
}
|
|
313
|
+
return { apiId, data: stripSeedMedia(block.data, blockFields(apiId), apiId) };
|
|
314
|
+
};
|
|
315
|
+
return { header: role(ROLE_BLOCKS.header), footer: role(ROLE_BLOCKS.footer) };
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
/**
|
|
319
|
+
* A copy of `data` with every media value the CMS would refuse removed, walked
|
|
320
|
+
* against the block's own field types so a media field nested in a `composite`
|
|
321
|
+
* or a `list` (`navigation`'s `links[].features[].image`, `hero`'s
|
|
322
|
+
* `slides[].image`) is reached too — the same walk
|
|
323
|
+
* `@eldrajs/vite-plugin-theme`'s `checkSeedMedia` reports on, which is what
|
|
324
|
+
* `eldra-theme validate` applies to `mock.json`.
|
|
325
|
+
*
|
|
326
|
+
* A write-valid value (`{ assetId: <uuid>, framing? }`) is kept: a theme that
|
|
327
|
+
* seeds a real asset id keeps it. Everything else is dropped rather than
|
|
328
|
+
* blanked, because absent is what the CMS accepts for a media field and what
|
|
329
|
+
* every `mock.json` already does. The input is never mutated.
|
|
330
|
+
*
|
|
331
|
+
* **A seed block is created *published*, so it must satisfy publish validation
|
|
332
|
+
* too, not just the write-side media rule** — and a published entry cannot omit
|
|
333
|
+
* a value for a `required` field. So a required media field that has no
|
|
334
|
+
* write-valid value left after the strip is not something this can shrug at:
|
|
335
|
+
*
|
|
336
|
+
* - Inside a **list item**, the item is dropped. The list is the only unit that
|
|
337
|
+
* can be removed without inventing data, and a shorter list is a shape the
|
|
338
|
+
* block already renders (`hero`'s four demo `slides[]` all require an image,
|
|
339
|
+
* so the seeded hero gets `slides: []` — which is what its `mock.json`
|
|
340
|
+
* carries too).
|
|
341
|
+
* - Anywhere else — at the top level of the block, or inside a non-list
|
|
342
|
+
* `composite` — there is nothing to drop, so the **block is unseedable** and
|
|
343
|
+
* this throws, naming the block and the field. `starterTemplates()` therefore
|
|
344
|
+
* cannot emit a seed Core would refuse to publish; it fails the build
|
|
345
|
+
* instead. No block in this starter has such a field today, which is exactly
|
|
346
|
+
* why the guard has to be here rather than in a reviewer's head.
|
|
347
|
+
*/
|
|
348
|
+
export function stripSeedMedia(
|
|
349
|
+
data: Record<string, unknown>,
|
|
350
|
+
fields: readonly ManifestField[],
|
|
351
|
+
apiId: string
|
|
352
|
+
): Record<string, unknown> {
|
|
353
|
+
const copy = structuredClone(data);
|
|
354
|
+
const missing = stripInto(copy, fields);
|
|
355
|
+
if (missing !== null) {
|
|
356
|
+
throw new Error(
|
|
357
|
+
`${apiId}: cannot be seeded — the required media field "${missing}" has no write-valid ` +
|
|
358
|
+
`value, and a seed block is created published. Give it a real {assetId: <uuid>}, move ` +
|
|
359
|
+
`the field into a list item, or drop its "required" validator.`
|
|
360
|
+
);
|
|
361
|
+
}
|
|
362
|
+
return copy;
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
/** One field of a block's `block.json`, as the manifest carries it verbatim. */
|
|
366
|
+
export interface ManifestField {
|
|
367
|
+
fieldId: string;
|
|
368
|
+
type: string;
|
|
369
|
+
validators?: { required?: boolean; [key: string]: unknown };
|
|
370
|
+
metadata?: {
|
|
371
|
+
multiple?: boolean;
|
|
372
|
+
fields?: ManifestField[];
|
|
373
|
+
item?: ManifestField;
|
|
374
|
+
[key: string]: unknown;
|
|
375
|
+
};
|
|
376
|
+
[key: string]: unknown;
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
interface PageFixtureBlock {
|
|
380
|
+
id: string;
|
|
381
|
+
apiId: string;
|
|
382
|
+
data: Record<string, unknown>;
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
interface PageFixture {
|
|
386
|
+
/** The sample page's own template name — documentation, for a fixture that
|
|
387
|
+
* backs a route template or no seed at all. */
|
|
388
|
+
template?: string;
|
|
389
|
+
/** Set instead of `template` by a fixture that seeds a static **page**: the
|
|
390
|
+
* slug it is created at (`cart` → `/cart`). */
|
|
391
|
+
page?: { slug: string };
|
|
392
|
+
title: string;
|
|
393
|
+
blocks: PageFixtureBlock[];
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
const UUID_PATTERN = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
397
|
+
const MEDIA_VALUE_KEYS = new Set(['assetId', 'framing']);
|
|
398
|
+
|
|
399
|
+
function isRoleBlock(apiId: string): boolean {
|
|
400
|
+
return roleOf(apiId) !== null;
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
/** Which page region a fixture block *is*, or null for an ordinary block. */
|
|
404
|
+
function roleOf(apiId: string): 'header' | 'footer' | null {
|
|
405
|
+
if (apiId === ROLE_BLOCKS.header) return 'header';
|
|
406
|
+
if (apiId === ROLE_BLOCKS.footer) return 'footer';
|
|
407
|
+
return null;
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
/**
|
|
411
|
+
* Strips `data` in place and returns the path of the first **required** media
|
|
412
|
+
* field left without a write-valid value, or `null`. A list item that reports
|
|
413
|
+
* one is dropped here — that is the only place a missing required value can be
|
|
414
|
+
* resolved without inventing data — so a non-null return always means the
|
|
415
|
+
* caller has nothing left to drop.
|
|
416
|
+
*/
|
|
417
|
+
function stripInto(
|
|
418
|
+
data: Record<string, unknown>,
|
|
419
|
+
fields: readonly ManifestField[],
|
|
420
|
+
prefix = ''
|
|
421
|
+
): string | null {
|
|
422
|
+
for (const field of fields) {
|
|
423
|
+
const fieldId = field.fieldId;
|
|
424
|
+
if (typeof fieldId !== 'string' || fieldId === '') continue;
|
|
425
|
+
const path = prefix === '' ? fieldId : `${prefix}.${fieldId}`;
|
|
426
|
+
const metadata = isRecord(field.metadata) ? field.metadata : {};
|
|
427
|
+
|
|
428
|
+
if (field.type === 'media') {
|
|
429
|
+
// Checked even when the key is absent: a required media field the
|
|
430
|
+
// fixture never set is just as unpublishable as one this strips.
|
|
431
|
+
if (Object.hasOwn(data, fieldId)) {
|
|
432
|
+
const value = data[fieldId];
|
|
433
|
+
if (metadata.multiple === true && Array.isArray(value))
|
|
434
|
+
keepValidMedia(data, fieldId, value);
|
|
435
|
+
else if (!isWriteValidMedia(value)) delete data[fieldId];
|
|
436
|
+
}
|
|
437
|
+
if (isRequired(field) && !Object.hasOwn(data, fieldId)) return path;
|
|
438
|
+
continue;
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
if (!Object.hasOwn(data, fieldId)) continue;
|
|
442
|
+
const value = data[fieldId];
|
|
443
|
+
|
|
444
|
+
if (field.type === 'composite') {
|
|
445
|
+
// No unit to drop here — a composite is one value, so a missing required
|
|
446
|
+
// media inside it travels up to the nearest list item, or out of the block.
|
|
447
|
+
if (isRecord(value)) {
|
|
448
|
+
const missing = stripInto(value, fieldList(metadata.fields), path);
|
|
449
|
+
if (missing !== null) return missing;
|
|
450
|
+
}
|
|
451
|
+
continue;
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
if (field.type === 'list') {
|
|
455
|
+
const item = isRecord(metadata.item) ? (metadata.item as ManifestField) : null;
|
|
456
|
+
if (item === null || !Array.isArray(value)) continue;
|
|
457
|
+
if (item.type === 'media') {
|
|
458
|
+
// A required media *item* means every member must be valid, and an
|
|
459
|
+
// invalid one is simply not kept — `keepValidMedia` already does that.
|
|
460
|
+
keepValidMedia(data, fieldId, value);
|
|
461
|
+
continue;
|
|
462
|
+
}
|
|
463
|
+
const itemFields =
|
|
464
|
+
item.type === 'composite'
|
|
465
|
+
? fieldList(isRecord(item.metadata) ? item.metadata.fields : undefined)
|
|
466
|
+
: [];
|
|
467
|
+
if (itemFields.length === 0) continue;
|
|
468
|
+
const kept: unknown[] = [];
|
|
469
|
+
for (const entry of value) {
|
|
470
|
+
if (!isRecord(entry)) {
|
|
471
|
+
kept.push(entry);
|
|
472
|
+
continue;
|
|
473
|
+
}
|
|
474
|
+
// A list item whose required media cannot survive the strip is dropped
|
|
475
|
+
// whole: the item is the smallest thing that can go, and a shorter list
|
|
476
|
+
// is a shape the block already renders.
|
|
477
|
+
if (stripInto(entry, itemFields, `${path}[]`) === null) kept.push(entry);
|
|
478
|
+
}
|
|
479
|
+
data[fieldId] = kept;
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
return null;
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
/** Keep only the write-valid members of a multi-value media field; a field
|
|
486
|
+
* left with nothing is dropped rather than seeded as an empty list, so it
|
|
487
|
+
* reads exactly like a media field a `mock.json` omits. */
|
|
488
|
+
function keepValidMedia(data: Record<string, unknown>, fieldId: string, value: unknown[]): void {
|
|
489
|
+
const kept = value.filter(isWriteValidMedia);
|
|
490
|
+
if (kept.length === 0) delete data[fieldId];
|
|
491
|
+
else data[fieldId] = kept;
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
function isRequired(field: ManifestField): boolean {
|
|
495
|
+
const validators = field.validators;
|
|
496
|
+
return isRecord(validators) && validators.required === true;
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
/** The one media shape the CMS accepts on write — the rule
|
|
500
|
+
* `@eldrajs/vite-plugin-theme` enforces for `mock.json` and for seeds. */
|
|
501
|
+
function isWriteValidMedia(value: unknown): boolean {
|
|
502
|
+
if (!isRecord(value)) return false;
|
|
503
|
+
return (
|
|
504
|
+
Object.keys(value).every((key) => MEDIA_VALUE_KEYS.has(key)) &&
|
|
505
|
+
typeof value.assetId === 'string' &&
|
|
506
|
+
UUID_PATTERN.test(value.assetId)
|
|
507
|
+
);
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
function fieldList(value: unknown): ManifestField[] {
|
|
511
|
+
return Array.isArray(value) ? (value as ManifestField[]) : [];
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
515
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
const fixtures = new Map<string, PageFixture>();
|
|
519
|
+
const fields = new Map<string, ManifestField[]>();
|
|
520
|
+
|
|
521
|
+
function pageFixture(name: string): PageFixture {
|
|
522
|
+
let fixture = fixtures.get(name);
|
|
523
|
+
if (fixture === undefined) {
|
|
524
|
+
fixture = readJson<PageFixture>(`../pages/${name}.page.json`);
|
|
525
|
+
fixtures.set(name, fixture);
|
|
526
|
+
}
|
|
527
|
+
return fixture;
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
/** A block's declared fields, read straight from its `block.json` — the
|
|
531
|
+
* scanner copies them into the manifest verbatim, so these *are* the manifest
|
|
532
|
+
* field types the media walk needs. */
|
|
533
|
+
function blockFields(apiId: string): ManifestField[] {
|
|
534
|
+
let declared = fields.get(apiId);
|
|
535
|
+
if (declared === undefined) {
|
|
536
|
+
declared = fieldList(readJson<{ fields?: unknown }>(`../blocks/${apiId}/block.json`).fields);
|
|
537
|
+
fields.set(apiId, declared);
|
|
538
|
+
}
|
|
539
|
+
return declared;
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
function readJson<T>(relative: string): T {
|
|
543
|
+
return JSON.parse(readFileSync(fileURLToPath(new URL(relative, import.meta.url)), 'utf8')) as T;
|
|
544
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The one shared Tailwind class recipe left in the theme: the focus ring for
|
|
3
|
+
* the elements this starter still draws itself.
|
|
4
|
+
*
|
|
5
|
+
* Buttons, links and form controls come from `@eldrajs/ui` now and carry the
|
|
6
|
+
* package's own `eldra-focus` ring (drawn from `--eldra-color-focus` /
|
|
7
|
+
* `--eldra-color-focus-inner`, see `tokens.json`), so the recipes that used
|
|
8
|
+
* to live here — `buttonBase`, `buttonVariants`, `buttonSizes`, `inputBase` —
|
|
9
|
+
* are gone with the primitives that used them. What is left is the `gallery`
|
|
10
|
+
* block's own image triggers, which open the package's `Lightbox` on click
|
|
11
|
+
* (`blocks/gallery/Block.vue`) — the one interactive element left in this
|
|
12
|
+
* starter that is not a package component and so does not already carry
|
|
13
|
+
* `eldra-focus` on its own.
|
|
14
|
+
*/
|
|
15
|
+
export const focusRing =
|
|
16
|
+
'focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary focus-visible:ring-offset-2 focus-visible:ring-offset-background';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* The ring drawn inside the element's box, for a control whose parent clips its overflow (the
|
|
20
|
+
* `video-embed` block's play button fills a rounded, `overflow-hidden` 16:9 frame, so an offset
|
|
21
|
+
* ring outside its edge would be cut away entirely and keyboard focus would be invisible). This is
|
|
22
|
+
* the package's own two-tone inset utility rather than a `ring-*` recipe: the button sits over
|
|
23
|
+
* arbitrary poster imagery, and a single-colour ring has no guaranteed contrast against a photo.
|
|
24
|
+
*/
|
|
25
|
+
export const focusRingInset = 'eldra-focus-inset';
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* The ring for a control the theme draws as a *shape with the real input inside it* — the
|
|
29
|
+
* `collection-grid` block's colour swatch, where a 1.5rem dot carries a native
|
|
30
|
+
* `<input type="checkbox">` stretched invisibly over it, so `focus-visible:` on the drawn shape
|
|
31
|
+
* would never match (the input has focus, the dot is what a keyboard user sees).
|
|
32
|
+
*
|
|
33
|
+
* This is the package's own pair rather than a `ring-*` recipe, for two reasons the swatch cannot
|
|
34
|
+
* work around: `eldra-focus-proxy` is `:has(:focus-visible)`, the only variant that moves the ring
|
|
35
|
+
* from the focused input onto the shape around it, and the input is `opacity-0` — which would take
|
|
36
|
+
* a ring drawn on the input itself down with it. Drawn outside the shape's border box, it also
|
|
37
|
+
* clears the swatch's own 2px checked ring for free (the same geometry `VariantPicker`'s swatches
|
|
38
|
+
* use in the package).
|
|
39
|
+
*/
|
|
40
|
+
export const focusRingProxy = 'eldra-focus eldra-focus-proxy';
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The kit's own href allowlist, re-exported under the name this theme's blocks
|
|
3
|
+
* already call: ordinary site links are allowed, executable and opaque URL
|
|
4
|
+
* schemes are not. One implementation, in `@eldrajs/theme-core`, so a block
|
|
5
|
+
* and the link resolver can never disagree about what is safe.
|
|
6
|
+
*/
|
|
7
|
+
export { safeLinkHref as safeHref } from '@eldrajs/theme-core/links';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* A destination the site itself owns — a path (`/shop`) or an in-page hash
|
|
11
|
+
* (`#main`). These are the links that should route client-side, which is what
|
|
12
|
+
* `@eldrajs/ui`'s `Link` does when it is given Nuxt's `<NuxtLink>` as `as`
|
|
13
|
+
* (see `app/components/EldraRouterLink.vue`); everything else (an absolute URL,
|
|
14
|
+
* `mailto:`, `tel:`) is a document navigation and stays a plain `<a>`.
|
|
15
|
+
*
|
|
16
|
+
* Call it on the output of `safeHref`, never on a raw field value.
|
|
17
|
+
*/
|
|
18
|
+
export function isInternalHref(href: string): boolean {
|
|
19
|
+
return href.startsWith('/') || href.startsWith('#');
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* The site's own search results page — the page `pages/search.page.json` seeds, and
|
|
24
|
+
* `@eldrajs/ui`'s `SearchBar`/`SearchModal` default `action`.
|
|
25
|
+
*
|
|
26
|
+
* Named here rather than in each block because **two** blocks point at it: the `search` block (its
|
|
27
|
+
* own form, its popular-search chips, its "see all" link) and the `navigation` block (the header's
|
|
28
|
+
* inline field, the search overlay's form, and the overlay's "See all N results" row, which
|
|
29
|
+
* `SearchModal` builds from the `action` it is given). They have to agree about the path, and —
|
|
30
|
+
* since both must prefix it for the page's own locale — about the fact that there is exactly one
|
|
31
|
+
* path to prefix.
|
|
32
|
+
*
|
|
33
|
+
* Put it through `useEldraLocale().path()` at the point of use. These are form actions and library
|
|
34
|
+
* hrefs with no `EldraRouterLink` in their path, so nothing else will do it for them.
|
|
35
|
+
*/
|
|
36
|
+
export const SEARCH_PATH = '/search';
|
|
37
|
+
|
|
38
|
+
/** One query's URL on that page: what a chip, a "see all" row and a submit all resolve to. */
|
|
39
|
+
export function searchQueryHref(query: string): string {
|
|
40
|
+
return `${SEARCH_PATH}?q=${encodeURIComponent(query)}`;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* The site's own **category page** — the route template `pages/category.page.json` seeds,
|
|
45
|
+
* `/categories/:path*`.
|
|
46
|
+
*
|
|
47
|
+
* Named here beside `SEARCH_PATH` rather than in each caller because four surfaces point at it: a
|
|
48
|
+
* product's breadcrumb trail and `product-detail`'s category label (both through the trail the
|
|
49
|
+
* storefront builds), the category page's own breadcrumbs, and `collection-header`'s strip of
|
|
50
|
+
* child-category chips. They have to agree about the path, and — since each is prefixed for the
|
|
51
|
+
* page's own locale — about the fact that there is exactly one path to prefix.
|
|
52
|
+
*/
|
|
53
|
+
export const CATEGORIES_PATH = '/categories';
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* One category's page, from its **canonical path**: the slugs of its ancestors, root first, then its
|
|
57
|
+
* own, joined with `/` and with no leading slash (`billinn/bilstolar`). That is the only path the
|
|
58
|
+
* route answers — canonical only, no redirects — so a caller must hand this a whole path and never a
|
|
59
|
+
* leaf slug; `app/storefront/categories.ts`'s `pathOf` is where one comes from.
|
|
60
|
+
*
|
|
61
|
+
* Each segment is encoded separately, so the separators survive and a slug carrying a space or a
|
|
62
|
+
* non-ASCII letter still addresses its own segment. Locale-aware the same way `searchQueryHref` is:
|
|
63
|
+
* it returns the site-relative path, and the active locale's prefix is added where it is used —
|
|
64
|
+
* `EldraRouterLink` does it for every same-site link this theme renders.
|
|
65
|
+
*/
|
|
66
|
+
export function categoryHref(path: string): string {
|
|
67
|
+
const segments = path.split('/').filter((segment) => segment !== '');
|
|
68
|
+
if (segments.length === 0) return CATEGORIES_PATH;
|
|
69
|
+
return `${CATEGORIES_PATH}/${segments.map((segment) => encodeURIComponent(segment)).join('/')}`;
|
|
70
|
+
}
|