@eldrajs/theme-cli 0.0.0 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +69 -0
- package/LICENSE +21 -0
- package/README.md +26 -1
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +203 -0
- package/dist/index.d.ts +174 -0
- package/dist/index.js +3 -0
- package/dist/validate-C6jB8_Oc.js +510 -0
- package/package.json +50 -2
- package/template/.eldra/block-types.d.ts +429 -0
- package/template/.eldra/manifest.json +9377 -0
- package/template/.eldra/previews.json +36 -0
- package/template/.github/workflows/eldra-deploy.yml +24 -0
- package/template/.gitlab-ci.yml +16 -0
- package/template/.storybook/eldra.ts +123 -0
- package/template/.storybook/i18n.ts +23 -0
- package/template/.storybook/main.ts +59 -0
- package/template/.storybook/nuxt-link-stub.ts +23 -0
- package/template/.storybook/preview.ts +52 -0
- package/template/.storybook/shims-vue.d.ts +10 -0
- package/template/.storybook/virtual-eldra.d.ts +27 -0
- package/template/README.md +288 -0
- package/template/app/app.vue +126 -0
- package/template/app/assets/main.css +404 -0
- package/template/app/components/EldraIcon.vue +66 -0
- package/template/app/components/EldraRouterLink.vue +62 -0
- package/template/app/components/ui/UiImage.stories.ts +30 -0
- package/template/app/components/ui/UiImage.vue +224 -0
- package/template/app/components/ui/__tests__/UiImage.spec.ts +292 -0
- package/template/app/composables/iconComponent.ts +84 -0
- package/template/app/composables/iconFetcher.ts +14 -0
- package/template/app/composables/useBlockData.ts +30 -0
- package/template/app/composables/useEditing.ts +31 -0
- package/template/app/composables/useEldraIcon.ts +46 -0
- package/template/app/composables/useRevalidating.ts +69 -0
- package/template/app/composables/useRichTextScrollRegions.ts +80 -0
- package/template/app/composables/useStorefront.ts +18 -0
- package/template/app/composables/useStorefrontFeedback.ts +49 -0
- package/template/app/composables/useUiId.ts +18 -0
- package/template/app/composables/useWishlist.ts +42 -0
- package/template/app/i18n.d.ts +28 -0
- package/template/app/icons.ts +185 -0
- package/template/app/pages/[...slug].vue +134 -0
- package/template/app/plugins/eldra-i18n.ts +98 -0
- package/template/app/plugins/eldra-storefront.ts +288 -0
- package/template/app/plugins/eldra-ui-messages.ts +112 -0
- package/template/app/storefront/cart.ts +245 -0
- package/template/app/storefront/categories.ts +283 -0
- package/template/app/storefront/collectionSelector.ts +60 -0
- package/template/app/storefront/commerce.ts +58 -0
- package/template/app/storefront/demo.ts +1313 -0
- package/template/app/storefront/facets.ts +476 -0
- package/template/app/storefront/feedback.ts +122 -0
- package/template/app/storefront/gateway.ts +2256 -0
- package/template/app/storefront/history.ts +233 -0
- package/template/app/storefront/money.ts +247 -0
- package/template/app/storefront/options.ts +71 -0
- package/template/app/storefront/prerender.ts +77 -0
- package/template/app/storefront/refresh.ts +222 -0
- package/template/app/storefront/toProductCard.ts +154 -0
- package/template/app/storefront/types.ts +815 -0
- package/template/app/storefront/volatile.ts +211 -0
- package/template/app/templates.ts +544 -0
- package/template/app/utils/classes.ts +40 -0
- package/template/app/utils/links.ts +70 -0
- package/template/app/utils/pageStructure.ts +77 -0
- package/template/app/utils/pageTitle.ts +37 -0
- package/template/app/virtual-eldra.d.ts +12 -0
- package/template/bitbucket-pipelines.yml +19 -0
- package/template/blocks/announcement-bar/Block.vue +203 -0
- package/template/blocks/announcement-bar/__tests__/Block.spec.ts +227 -0
- package/template/blocks/announcement-bar/block.json +45 -0
- package/template/blocks/announcement-bar/mock.json +7 -0
- package/template/blocks/announcement-bar/preview.png +0 -0
- package/template/blocks/article/Block.vue +317 -0
- package/template/blocks/article/__tests__/Block.spec.ts +229 -0
- package/template/blocks/article/block.json +148 -0
- package/template/blocks/article/mock.json +512 -0
- package/template/blocks/article/preview.json +16 -0
- package/template/blocks/article/preview.png +0 -0
- package/template/blocks/article-list/Block.vue +343 -0
- package/template/blocks/article-list/__tests__/Block.spec.ts +279 -0
- package/template/blocks/article-list/block.json +181 -0
- package/template/blocks/article-list/mock.json +68 -0
- package/template/blocks/article-list/preview.json +84 -0
- package/template/blocks/article-list/preview.png +0 -0
- package/template/blocks/breadcrumbs/Block.vue +278 -0
- package/template/blocks/breadcrumbs/__tests__/Block.spec.ts +461 -0
- package/template/blocks/breadcrumbs/block.json +89 -0
- package/template/blocks/breadcrumbs/mock.json +11 -0
- package/template/blocks/breadcrumbs/preview.json +3 -0
- package/template/blocks/breadcrumbs/preview.png +0 -0
- package/template/blocks/cart/Block.vue +372 -0
- package/template/blocks/cart/__tests__/Block.spec.ts +561 -0
- package/template/blocks/cart/__tests__/ShippingBar.spec.ts +78 -0
- package/template/blocks/cart/__tests__/Summary.spec.ts +245 -0
- package/template/blocks/cart/block.json +74 -0
- package/template/blocks/cart/mock.json +11 -0
- package/template/blocks/cart/parts/CartLines.vue +257 -0
- package/template/blocks/cart/parts/ShippingBar.vue +105 -0
- package/template/blocks/cart/parts/Summary.vue +291 -0
- package/template/blocks/cart/preview.png +0 -0
- package/template/blocks/collection-grid/Block.vue +1832 -0
- package/template/blocks/collection-grid/__tests__/Block.spec.ts +3037 -0
- package/template/blocks/collection-grid/__tests__/groups.spec.ts +731 -0
- package/template/blocks/collection-grid/block.json +187 -0
- package/template/blocks/collection-grid/mock.json +23 -0
- package/template/blocks/collection-grid/parts/groups.ts +861 -0
- package/template/blocks/collection-grid/preview.json +7 -0
- package/template/blocks/collection-grid/preview.png +0 -0
- package/template/blocks/collection-header/Block.vue +533 -0
- package/template/blocks/collection-header/__tests__/Block.spec.ts +381 -0
- package/template/blocks/collection-header/block.json +140 -0
- package/template/blocks/collection-header/mock.json +28 -0
- package/template/blocks/collection-header/preview.json +14 -0
- package/template/blocks/collection-header/preview.png +0 -0
- package/template/blocks/contact/Block.vue +621 -0
- package/template/blocks/contact/__tests__/Block.spec.ts +347 -0
- package/template/blocks/contact/block.json +174 -0
- package/template/blocks/contact/mock.json +28 -0
- package/template/blocks/contact/preview.json +9 -0
- package/template/blocks/contact/preview.png +0 -0
- package/template/blocks/cta/Block.vue +383 -0
- package/template/blocks/cta/__tests__/Block.spec.ts +309 -0
- package/template/blocks/cta/block.json +86 -0
- package/template/blocks/cta/mock.json +10 -0
- package/template/blocks/cta/preview.json +9 -0
- package/template/blocks/cta/preview.png +0 -0
- package/template/blocks/faq/Block.vue +254 -0
- package/template/blocks/faq/__tests__/Block.spec.ts +312 -0
- package/template/blocks/faq/block.json +113 -0
- package/template/blocks/faq/mock.json +115 -0
- package/template/blocks/faq/preview.png +0 -0
- package/template/blocks/feature-grid/Block.vue +241 -0
- package/template/blocks/feature-grid/__tests__/Block.spec.ts +311 -0
- package/template/blocks/feature-grid/block.json +106 -0
- package/template/blocks/feature-grid/mock.json +29 -0
- package/template/blocks/feature-grid/preview.json +45 -0
- package/template/blocks/feature-grid/preview.png +0 -0
- package/template/blocks/footer/Block.vue +652 -0
- package/template/blocks/footer/__tests__/Block.spec.ts +700 -0
- package/template/blocks/footer/block.json +240 -0
- package/template/blocks/footer/mock.json +161 -0
- package/template/blocks/footer/preview.png +0 -0
- package/template/blocks/gallery/Block.vue +416 -0
- package/template/blocks/gallery/__tests__/Block.spec.ts +289 -0
- package/template/blocks/gallery/block.json +87 -0
- package/template/blocks/gallery/mock.json +16 -0
- package/template/blocks/gallery/preview.json +64 -0
- package/template/blocks/gallery/preview.png +0 -0
- package/template/blocks/hero/Block.vue +378 -0
- package/template/blocks/hero/__tests__/Block.spec.ts +324 -0
- package/template/blocks/hero/block.json +146 -0
- package/template/blocks/hero/mock.json +11 -0
- package/template/blocks/hero/preview.json +55 -0
- package/template/blocks/hero/preview.png +0 -0
- package/template/blocks/image/Block.vue +232 -0
- package/template/blocks/image/__tests__/Block.spec.ts +224 -0
- package/template/blocks/image/block.json +67 -0
- package/template/blocks/image/mock.json +7 -0
- package/template/blocks/image/preview.json +9 -0
- package/template/blocks/image/preview.png +0 -0
- package/template/blocks/logo-cloud/Block.vue +206 -0
- package/template/blocks/logo-cloud/__tests__/Block.spec.ts +210 -0
- package/template/blocks/logo-cloud/block.json +79 -0
- package/template/blocks/logo-cloud/mock.json +15 -0
- package/template/blocks/logo-cloud/preview.json +92 -0
- package/template/blocks/logo-cloud/preview.png +0 -0
- package/template/blocks/navigation/Block.vue +1348 -0
- package/template/blocks/navigation/__tests__/Block.spec.ts +2030 -0
- package/template/blocks/navigation/block.json +167 -0
- package/template/blocks/navigation/mock.json +191 -0
- package/template/blocks/navigation/preview.png +0 -0
- package/template/blocks/navigation/useMegaMenuKeys.ts +276 -0
- package/template/blocks/newsletter/Block.vue +399 -0
- package/template/blocks/newsletter/__tests__/Block.spec.ts +365 -0
- package/template/blocks/newsletter/block.json +105 -0
- package/template/blocks/newsletter/mock.json +31 -0
- package/template/blocks/newsletter/preview.png +0 -0
- package/template/blocks/order-status/Block.vue +754 -0
- package/template/blocks/order-status/__tests__/Block.spec.ts +515 -0
- package/template/blocks/order-status/block.json +138 -0
- package/template/blocks/order-status/mock.json +19 -0
- package/template/blocks/order-status/preview.png +0 -0
- package/template/blocks/pricing-table/Block.vue +297 -0
- package/template/blocks/pricing-table/__tests__/Block.spec.ts +357 -0
- package/template/blocks/pricing-table/block.json +155 -0
- package/template/blocks/pricing-table/mock.json +47 -0
- package/template/blocks/pricing-table/preview.png +0 -0
- package/template/blocks/product-carousel/Block.vue +459 -0
- package/template/blocks/product-carousel/__tests__/Block.spec.ts +957 -0
- package/template/blocks/product-carousel/block.json +71 -0
- package/template/blocks/product-carousel/mock.json +9 -0
- package/template/blocks/product-carousel/preview.json +7 -0
- package/template/blocks/product-carousel/preview.png +0 -0
- package/template/blocks/product-detail/Block.vue +886 -0
- package/template/blocks/product-detail/__tests__/Block.spec.ts +1495 -0
- package/template/blocks/product-detail/__tests__/stock.spec.ts +119 -0
- package/template/blocks/product-detail/block.json +155 -0
- package/template/blocks/product-detail/mock.json +113 -0
- package/template/blocks/product-detail/parts/Gallery.vue +181 -0
- package/template/blocks/product-detail/parts/StickyBuyBar.vue +99 -0
- package/template/blocks/product-detail/preview.png +0 -0
- package/template/blocks/product-detail/stock.ts +150 -0
- package/template/blocks/quote/Block.vue +206 -0
- package/template/blocks/quote/__tests__/Block.spec.ts +265 -0
- package/template/blocks/quote/block.json +76 -0
- package/template/blocks/quote/mock.json +9 -0
- package/template/blocks/quote/preview.json +16 -0
- package/template/blocks/quote/preview.png +0 -0
- package/template/blocks/rich-text/Block.vue +143 -0
- package/template/blocks/rich-text/__tests__/Block.spec.ts +191 -0
- package/template/blocks/rich-text/block.json +57 -0
- package/template/blocks/rich-text/mock.json +87 -0
- package/template/blocks/rich-text/preview.png +0 -0
- package/template/blocks/search/Block.vue +589 -0
- package/template/blocks/search/PopularChips.vue +40 -0
- package/template/blocks/search/TypeSection.vue +148 -0
- package/template/blocks/search/__tests__/Block.spec.ts +718 -0
- package/template/blocks/search/__tests__/results.spec.ts +166 -0
- package/template/blocks/search/block.json +102 -0
- package/template/blocks/search/mock.json +18 -0
- package/template/blocks/search/preview.png +0 -0
- package/template/blocks/search/results.ts +85 -0
- package/template/blocks/split-content/Block.vue +195 -0
- package/template/blocks/split-content/__tests__/Block.spec.ts +225 -0
- package/template/blocks/split-content/block.json +70 -0
- package/template/blocks/split-content/mock.json +45 -0
- package/template/blocks/split-content/preview.json +58 -0
- package/template/blocks/split-content/preview.png +0 -0
- package/template/blocks/stats/Block.vue +159 -0
- package/template/blocks/stats/__tests__/Block.spec.ts +194 -0
- package/template/blocks/stats/block.json +73 -0
- package/template/blocks/stats/mock.json +12 -0
- package/template/blocks/stats/preview.png +0 -0
- package/template/blocks/tabs/Block.vue +278 -0
- package/template/blocks/tabs/__tests__/Block.spec.ts +303 -0
- package/template/blocks/tabs/block.json +97 -0
- package/template/blocks/tabs/mock.json +129 -0
- package/template/blocks/tabs/preview.json +153 -0
- package/template/blocks/tabs/preview.png +0 -0
- package/template/blocks/team/Block.vue +288 -0
- package/template/blocks/team/__tests__/Block.spec.ts +221 -0
- package/template/blocks/team/block.json +125 -0
- package/template/blocks/team/mock.json +39 -0
- package/template/blocks/team/preview.json +62 -0
- package/template/blocks/team/preview.png +0 -0
- package/template/blocks/testimonials/Block.vue +408 -0
- package/template/blocks/testimonials/__tests__/Block.spec.ts +319 -0
- package/template/blocks/testimonials/block.json +121 -0
- package/template/blocks/testimonials/mock.json +46 -0
- package/template/blocks/testimonials/preview.json +68 -0
- package/template/blocks/testimonials/preview.png +0 -0
- package/template/blocks/timeline/Block.vue +274 -0
- package/template/blocks/timeline/__tests__/Block.spec.ts +310 -0
- package/template/blocks/timeline/block.json +98 -0
- package/template/blocks/timeline/mock.json +27 -0
- package/template/blocks/timeline/preview.png +0 -0
- package/template/blocks/trust-strip/Block.vue +330 -0
- package/template/blocks/trust-strip/__tests__/Block.spec.ts +290 -0
- package/template/blocks/trust-strip/block.json +117 -0
- package/template/blocks/trust-strip/mock.json +37 -0
- package/template/blocks/trust-strip/preview.png +0 -0
- package/template/blocks/video-embed/Block.vue +354 -0
- package/template/blocks/video-embed/__tests__/Block.spec.ts +219 -0
- package/template/blocks/video-embed/__tests__/embed.spec.ts +76 -0
- package/template/blocks/video-embed/block.json +94 -0
- package/template/blocks/video-embed/embed.ts +84 -0
- package/template/blocks/video-embed/mock.json +13 -0
- package/template/blocks/video-embed/preview.json +9 -0
- package/template/blocks/video-embed/preview.png +0 -0
- package/template/blocks/wishlist/Block.vue +367 -0
- package/template/blocks/wishlist/__tests__/Block.spec.ts +508 -0
- package/template/blocks/wishlist/block.json +42 -0
- package/template/blocks/wishlist/mock.json +9 -0
- package/template/blocks/wishlist/preview.png +0 -0
- package/template/i18n/en-US.json +602 -0
- package/template/i18n/is-IS.json +602 -0
- package/template/nuxt.config.ts +148 -0
- package/template/package.json +55 -0
- package/template/pages/article.page.json +731 -0
- package/template/pages/cart.page.json +85 -0
- package/template/pages/category.page.json +133 -0
- package/template/pages/collection.page.json +194 -0
- package/template/pages/home.page.json +353 -0
- package/template/pages/product.page.json +323 -0
- package/template/pages/products.page.json +144 -0
- package/template/pages/search.page.json +83 -0
- package/template/pages/wishlist.page.json +88 -0
- package/template/public/demo/article-cover.svg +1 -0
- package/template/public/demo/article-figure.svg +1 -0
- package/template/public/demo/avatar-1.svg +3 -0
- package/template/public/demo/avatar-2.svg +3 -0
- package/template/public/demo/avatar-3.svg +3 -0
- package/template/public/demo/avatar-4.svg +3 -0
- package/template/public/demo/avatar-5.svg +3 -0
- package/template/public/demo/avatar-6.svg +3 -0
- package/template/public/demo/avatar-7.svg +3 -0
- package/template/public/demo/avatar-8.svg +3 -0
- package/template/public/demo/collection-1.svg +1 -0
- package/template/public/demo/collection-2.svg +1 -0
- package/template/public/demo/cta-split.svg +1 -0
- package/template/public/demo/feature-1.svg +1 -0
- package/template/public/demo/feature-2.svg +1 -0
- package/template/public/demo/feature-3.svg +1 -0
- package/template/public/demo/feature-4.svg +1 -0
- package/template/public/demo/gallery-1.svg +1 -0
- package/template/public/demo/gallery-2.svg +1 -0
- package/template/public/demo/gallery-3.svg +1 -0
- package/template/public/demo/gallery-4.svg +1 -0
- package/template/public/demo/gallery-5.svg +1 -0
- package/template/public/demo/gallery-6.svg +1 -0
- package/template/public/demo/gallery-7.svg +1 -0
- package/template/public/demo/gallery-8.svg +1 -0
- package/template/public/demo/hero-slide-1.svg +1 -0
- package/template/public/demo/hero-slide-2.svg +1 -0
- package/template/public/demo/hero-slide-3.svg +1 -0
- package/template/public/demo/hero-slide-4.svg +1 -0
- package/template/public/demo/hero-wide.svg +1 -0
- package/template/public/demo/hero.svg +1 -0
- package/template/public/demo/logo-1.svg +4 -0
- package/template/public/demo/logo-2.svg +4 -0
- package/template/public/demo/logo-3.svg +4 -0
- package/template/public/demo/logo-4.svg +4 -0
- package/template/public/demo/logo-5.svg +4 -0
- package/template/public/demo/logo-6.svg +4 -0
- package/template/public/demo/logo-7.svg +4 -0
- package/template/public/demo/logo-8.svg +4 -0
- package/template/public/demo/logo.svg +3 -0
- package/template/public/demo/map.svg +1 -0
- package/template/public/demo/poster.svg +1 -0
- package/template/public/demo/product-1.svg +4 -0
- package/template/public/demo/product-10.svg +4 -0
- package/template/public/demo/product-11.svg +4 -0
- package/template/public/demo/product-12.svg +4 -0
- package/template/public/demo/product-2.svg +4 -0
- package/template/public/demo/product-3.svg +4 -0
- package/template/public/demo/product-4.svg +4 -0
- package/template/public/demo/product-5.svg +4 -0
- package/template/public/demo/product-6.svg +4 -0
- package/template/public/demo/product-7.svg +4 -0
- package/template/public/demo/product-8.svg +4 -0
- package/template/public/demo/product-9.svg +4 -0
- package/template/public/demo/product-square-1.svg +4 -0
- package/template/public/demo/product-square-2.svg +4 -0
- package/template/public/demo/product-square-3.svg +4 -0
- package/template/public/demo/product-square-4.svg +4 -0
- package/template/public/demo/product-square-5.svg +4 -0
- package/template/public/demo/product-square-6.svg +4 -0
- package/template/public/demo/quote-portrait.svg +4 -0
- package/template/public/demo/split-1.svg +1 -0
- package/template/public/demo/split-2.svg +1 -0
- package/template/public/demo/split-3.svg +1 -0
- package/template/public/demo/split-4.svg +1 -0
- package/template/public/demo/team-1.svg +4 -0
- package/template/public/demo/team-2.svg +4 -0
- package/template/public/demo/team-3.svg +4 -0
- package/template/public/demo/team-4.svg +4 -0
- package/template/scripts/demo-images.mjs +393 -0
- package/template/scripts/generate-stories.mjs +156 -0
- package/template/scripts/previewHash.mjs +125 -0
- package/template/scripts/previews.mjs +149 -0
- package/template/stories/generated/announcement-bar.stories.ts +44 -0
- package/template/stories/generated/article-list.stories.ts +87 -0
- package/template/stories/generated/article.stories.ts +27 -0
- package/template/stories/generated/breadcrumbs.stories.ts +39 -0
- package/template/stories/generated/cart.stories.ts +38 -0
- package/template/stories/generated/collection-grid.stories.ts +117 -0
- package/template/stories/generated/collection-header.stories.ts +51 -0
- package/template/stories/generated/contact.stories.ts +45 -0
- package/template/stories/generated/cta.stories.ts +51 -0
- package/template/stories/generated/faq.stories.ts +56 -0
- package/template/stories/generated/feature-grid.stories.ts +69 -0
- package/template/stories/generated/footer.stories.ts +50 -0
- package/template/stories/generated/gallery.stories.ts +81 -0
- package/template/stories/generated/hero.stories.ts +75 -0
- package/template/stories/generated/image.stories.ts +99 -0
- package/template/stories/generated/logo-cloud.stories.ts +57 -0
- package/template/stories/generated/navigation.stories.ts +62 -0
- package/template/stories/generated/newsletter.stories.ts +68 -0
- package/template/stories/generated/order-status.stories.ts +32 -0
- package/template/stories/generated/pricing-table.stories.ts +44 -0
- package/template/stories/generated/product-carousel.stories.ts +75 -0
- package/template/stories/generated/product-detail.stories.ts +62 -0
- package/template/stories/generated/quote.stories.ts +69 -0
- package/template/stories/generated/rich-text.stories.ts +50 -0
- package/template/stories/generated/search.stories.ts +56 -0
- package/template/stories/generated/split-content.stories.ts +39 -0
- package/template/stories/generated/stats.stories.ts +68 -0
- package/template/stories/generated/tabs.stories.ts +45 -0
- package/template/stories/generated/team.stories.ts +45 -0
- package/template/stories/generated/testimonials.stories.ts +69 -0
- package/template/stories/generated/timeline.stories.ts +80 -0
- package/template/stories/generated/trust-strip.stories.ts +62 -0
- package/template/stories/generated/video-embed.stories.ts +63 -0
- package/template/stories/generated/wishlist.stories.ts +26 -0
- package/template/stories/pages/article.stories.ts +51 -0
- package/template/stories/pages/cart.stories.ts +56 -0
- package/template/stories/pages/category.stories.ts +56 -0
- package/template/stories/pages/collection.stories.ts +51 -0
- package/template/stories/pages/home.stories.ts +51 -0
- package/template/stories/pages/product.stories.ts +47 -0
- package/template/stories/pages/products.stories.ts +58 -0
- package/template/stories/pages/search.stories.ts +54 -0
- package/template/stories/pages/wishlist.stories.ts +53 -0
- package/template/stories/support/pageBlocks.ts +115 -0
- package/template/test/blocksEmptyData.spec.ts +52 -0
- package/template/test/carouselKeyboard.spec.ts +272 -0
- package/template/test/carouselRing.browser.spec.ts +193 -0
- package/template/test/carouselSlideWidth.browser.spec.ts +102 -0
- package/template/test/cartDrawer.spec.ts +295 -0
- package/template/test/cartToast.spec.ts +86 -0
- package/template/test/countPill.browser.spec.ts +196 -0
- package/template/test/demoImages.spec.ts +140 -0
- package/template/test/deps.spec.ts +102 -0
- package/template/test/eldraIcon.spec.ts +58 -0
- package/template/test/framing.spec.ts +76 -0
- package/template/test/i18n.spec.ts +200 -0
- package/template/test/iconComponent.spec.ts +91 -0
- package/template/test/inlineEditable.spec.ts +334 -0
- package/template/test/localePrefix.spec.ts +342 -0
- package/template/test/mainCss.spec.ts +107 -0
- package/template/test/mockGatewayContract.spec.ts +122 -0
- package/template/test/mocks/blocks.ts +20 -0
- package/template/test/mocks/breakpoints.ts +7 -0
- package/template/test/mocks/manifest.ts +11 -0
- package/template/test/moneyFormatting.spec.ts +89 -0
- package/template/test/pageTitle.spec.ts +49 -0
- package/template/test/pages/article.spec.ts +231 -0
- package/template/test/pages/category.spec.ts +185 -0
- package/template/test/pages/collection.spec.ts +396 -0
- package/template/test/pages/home.spec.ts +295 -0
- package/template/test/pages/hydration.spec.ts +557 -0
- package/template/test/pages/product.spec.ts +396 -0
- package/template/test/pages/seededPages.spec.ts +190 -0
- package/template/test/pages/ssr.spec.ts +393 -0
- package/template/test/prerenderCommerce.spec.ts +134 -0
- package/template/test/prerenderFailure.spec.ts +130 -0
- package/template/test/prerenderRefresh.browser.spec.ts +1431 -0
- package/template/test/previewsFresh.spec.ts +56 -0
- package/template/test/richText.spec.ts +161 -0
- package/template/test/richTextTypography.spec.ts +182 -0
- package/template/test/setup.ts +21 -0
- package/template/test/slugPage.spec.ts +244 -0
- package/template/test/slugPageTemplate.spec.ts +194 -0
- package/template/test/starter.spec.ts +1416 -0
- package/template/test/storefront/cart.spec.ts +404 -0
- package/template/test/storefront/categories.spec.ts +235 -0
- package/template/test/storefront/collectionSelector.spec.ts +74 -0
- package/template/test/storefront/demo.spec.ts +555 -0
- package/template/test/storefront/facets.spec.ts +425 -0
- package/template/test/storefront/feedback.spec.ts +97 -0
- package/template/test/storefront/gateway.spec.ts +2673 -0
- package/template/test/storefront/gatewayCart.spec.ts +289 -0
- package/template/test/storefront/gatewayPrerender.spec.ts +1037 -0
- package/template/test/storefront/history.spec.ts +341 -0
- package/template/test/storefront/money.spec.ts +171 -0
- package/template/test/storefront/toProductCard.spec.ts +138 -0
- package/template/test/storefront/volatile.spec.ts +284 -0
- package/template/test/support/axe.ts +14 -0
- package/template/test/support/dialog.ts +51 -0
- package/template/test/support/hydrate.ts +118 -0
- package/template/test/support/i18nText.ts +11 -0
- package/template/test/support/mockGateway.ts +1017 -0
- package/template/test/support/mountBlock.ts +194 -0
- package/template/test/support/mountPage.spec.ts +72 -0
- package/template/test/support/mountPage.ts +254 -0
- package/template/test/support/mountProbe.client.ts +69 -0
- package/template/test/support/renderSsr.ts +97 -0
- package/template/test/support/staticServer.ts +96 -0
- package/template/test/themeIcons.spec.ts +140 -0
- package/template/test/toastAnnouncement.spec.ts +133 -0
- package/template/test/tokens.spec.ts +102 -0
- package/template/test/uiMessagesPlugin.spec.ts +104 -0
- package/template/test/useBlockData.spec.ts +46 -0
- package/template/test/useEditing.spec.ts +54 -0
- package/template/test/useEldraIcon.spec.ts +126 -0
- package/template/test/useUiId.spec.ts +40 -0
- package/template/tokens.json +149 -0
- package/template/tsconfig.json +3 -0
- package/template/tsconfig.storybook.json +17 -0
- package/template/vitest-axe.d.ts +13 -0
- package/template/vitest.config.ts +44 -0
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { computed } from 'vue';
|
|
3
|
+
import { EldraBlockZone, EldraLayout, getBlockSchemaApiId } from '@eldrajs/theme-vue';
|
|
4
|
+
import { Button, Container, Section } from '@eldrajs/ui';
|
|
5
|
+
import EldraRouterLink from '../components/EldraRouterLink.vue';
|
|
6
|
+
import { useI18n } from 'vue-i18n';
|
|
7
|
+
import { partitionPageBlocks } from '../utils/pageStructure';
|
|
8
|
+
import { pageTitle } from '../utils/pageTitle';
|
|
9
|
+
|
|
10
|
+
const {
|
|
11
|
+
page,
|
|
12
|
+
template,
|
|
13
|
+
entry,
|
|
14
|
+
catalog,
|
|
15
|
+
layout,
|
|
16
|
+
blocks,
|
|
17
|
+
reusableComponentProjection,
|
|
18
|
+
pending,
|
|
19
|
+
error,
|
|
20
|
+
} = useEldraPage();
|
|
21
|
+
const { t } = useI18n();
|
|
22
|
+
|
|
23
|
+
// `/404` is prerendered (see nitro.prerender.routes) so a styled not-found
|
|
24
|
+
// shell exists for static hosts. Without gateway credentials the page-lookup
|
|
25
|
+
// call in useEldraPage() throws before it can resolve "no match", landing in
|
|
26
|
+
// the *error* branch instead of the not-found one. Treat the `/404` route
|
|
27
|
+
// (trailing slashes normalized) as not-found unconditionally so the
|
|
28
|
+
// prerendered artifact — and any real visitor routed there by a host's 404
|
|
29
|
+
// handling — always sees the not-found shell rather than a raw error
|
|
30
|
+
// message. `page === null && template === null` is the ordinary not-found
|
|
31
|
+
// case for any other route (no gateway error, just no match).
|
|
32
|
+
//
|
|
33
|
+
// Branch order below is: pending -> not-found (either reason) -> error ->
|
|
34
|
+
// layout/block zone. The not-found and error conditions are complementary
|
|
35
|
+
// (`error && !isNotFoundRoute` vs. `isNotFoundRoute || (page === null &&
|
|
36
|
+
// template === null)`), so `/404` always wins over a real error, while a
|
|
37
|
+
// real content route's error state is left fully reachable and unweakened.
|
|
38
|
+
const route = useRoute();
|
|
39
|
+
const isNotFoundRoute = computed(() => route.path.replace(/\/+$/, '') === '/404');
|
|
40
|
+
const isNotFound = computed(
|
|
41
|
+
() => isNotFoundRoute.value || (page.value === null && template.value === null)
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
useHead(() => ({
|
|
45
|
+
title: pageTitle({
|
|
46
|
+
isNotFound: isNotFound.value,
|
|
47
|
+
notFoundTitle: t('notFound.title'),
|
|
48
|
+
// A catalog-backed route (a product, a collection) renders through a shared route template
|
|
49
|
+
// whose own title names the template — "Product" on every product page. The object's own
|
|
50
|
+
// title is on the resolved catalog `entry`, which is what the tab, the bookmark and the
|
|
51
|
+
// search result should say.
|
|
52
|
+
catalogTitle: catalog.value === null ? null : entry.value?.data.title,
|
|
53
|
+
documentTitle: (template.value ?? page.value)?.data.title,
|
|
54
|
+
}),
|
|
55
|
+
}));
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* The page's flat block list, cut into the three landmark regions — see
|
|
59
|
+
* `app/utils/pageStructure.ts` for the rule and for why rendering everything inside `<main>`
|
|
60
|
+
* (which is what this template used to do) costs every page its `banner`/`contentinfo` landmarks
|
|
61
|
+
* and makes `app/app.vue`'s "Skip to content" link land *above* the navigation it skips.
|
|
62
|
+
*
|
|
63
|
+
* Three sibling `EldraBlockZone`s, not one: the zone is a stateless renderer (it maps entries to
|
|
64
|
+
* their block component inside a `data-eldra-block` wrapper and holds no per-zone state or
|
|
65
|
+
* registration — see `@eldrajs/theme-vue`'s README and `EldraBlockZone.ts`), and Studio's
|
|
66
|
+
* preview/overlay addresses blocks by those `data-eldra-block` attributes document-wide rather
|
|
67
|
+
* than through a zone container. So editing, selection and live block updates behave exactly as
|
|
68
|
+
* they did with a single zone, whichever region a block ends up in.
|
|
69
|
+
*
|
|
70
|
+
* `EldraLayout` is the exception and stays wholly inside `<main>`: there the arrangement is an
|
|
71
|
+
* authored layout tree whose nodes reference block ids, so the flat list cannot be partitioned
|
|
72
|
+
* without breaking the layout. A layout-driven page therefore has its header/footer blocks inside
|
|
73
|
+
* `<main>` and no `banner`/`contentinfo` — documented in `docs/starter-kit.md` under "Page
|
|
74
|
+
* structure and landmarks"; closing it needs a layout-level region concept in the SDK, not a
|
|
75
|
+
* change here.
|
|
76
|
+
*/
|
|
77
|
+
const structure = computed(() =>
|
|
78
|
+
layout.value === null
|
|
79
|
+
? partitionPageBlocks(blocks.value, getBlockSchemaApiId)
|
|
80
|
+
: // `EldraLayout` already renders every block in `blocks`; splitting any of them out here too
|
|
81
|
+
// would render the header and footer twice.
|
|
82
|
+
{ header: [], main: blocks.value, footer: [] }
|
|
83
|
+
);
|
|
84
|
+
</script>
|
|
85
|
+
|
|
86
|
+
<template>
|
|
87
|
+
<EldraBlockZone v-if="structure.header.length > 0" :blocks="structure.header" />
|
|
88
|
+
<main id="main">
|
|
89
|
+
<Section v-if="pending" spacing="lg">
|
|
90
|
+
<Container width="content">
|
|
91
|
+
<p aria-busy="true">{{ t('loading') }}</p>
|
|
92
|
+
</Container>
|
|
93
|
+
</Section>
|
|
94
|
+
<Section v-else-if="error && !isNotFoundRoute" spacing="lg">
|
|
95
|
+
<Container width="content">
|
|
96
|
+
<p role="alert">{{ error }}</p>
|
|
97
|
+
</Container>
|
|
98
|
+
</Section>
|
|
99
|
+
<Section
|
|
100
|
+
v-else-if="isNotFound"
|
|
101
|
+
spacing="lg"
|
|
102
|
+
labelled-by="not-found-title"
|
|
103
|
+
data-eldra-not-found
|
|
104
|
+
:classes="{ root: 'text-center' }"
|
|
105
|
+
>
|
|
106
|
+
<Container width="narrow">
|
|
107
|
+
<p class="text-muted text-sm font-semibold tracking-widest uppercase">
|
|
108
|
+
{{ t('notFound.eyebrow') }}
|
|
109
|
+
</p>
|
|
110
|
+
<h1
|
|
111
|
+
id="not-found-title"
|
|
112
|
+
class="font-heading mt-2 text-3xl font-semibold tracking-tight sm:text-4xl"
|
|
113
|
+
>
|
|
114
|
+
{{ t('notFound.title') }}
|
|
115
|
+
</h1>
|
|
116
|
+
<p class="text-muted mt-4 text-lg">{{ t('notFound.body') }}</p>
|
|
117
|
+
<!-- `/` is always same-site, so it always routes: `Button`'s `as` hands the href to
|
|
118
|
+
`EldraRouterLink` as `to`, exactly as a `Link` does. -->
|
|
119
|
+
<Button variant="primary" class="mt-8" href="/" :as="EldraRouterLink">{{
|
|
120
|
+
t('notFound.back')
|
|
121
|
+
}}</Button>
|
|
122
|
+
</Container>
|
|
123
|
+
</Section>
|
|
124
|
+
<EldraLayout
|
|
125
|
+
v-else-if="layout !== null"
|
|
126
|
+
:layout="layout"
|
|
127
|
+
:blocks="blocks"
|
|
128
|
+
:reusable-component-projection="reusableComponentProjection"
|
|
129
|
+
:template-entry="entry ?? undefined"
|
|
130
|
+
/>
|
|
131
|
+
<EldraBlockZone v-else :blocks="structure.main" />
|
|
132
|
+
</main>
|
|
133
|
+
<EldraBlockZone v-if="structure.footer.length > 0" :blocks="structure.footer" />
|
|
134
|
+
</template>
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { defineNuxtPlugin } from 'nuxt/app';
|
|
2
|
+
import { inject, watch } from 'vue';
|
|
3
|
+
import { createI18n, type DefineLocaleMessage } from 'vue-i18n';
|
|
4
|
+
import { ELDRA_KEY, type EldraContext } from '@eldrajs/theme-vue';
|
|
5
|
+
import { unflattenMessages } from '@eldrajs/theme-core/i18n';
|
|
6
|
+
import manifest from 'virtual:eldra/manifest';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Installs `vue-i18n` on the Vue app, fed by the theme's own message catalogue
|
|
10
|
+
* (`context.messages`, `@eldrajs/theme-vue`'s `EldraContext['messages']`) —
|
|
11
|
+
* the build-merged/resolved content `@eldrajs/theme-nuxt`'s runtime plugin
|
|
12
|
+
* already assigned to it. Every block calls `useI18n()` from `vue-i18n`
|
|
13
|
+
* directly; there is no wrapper composable here, by design.
|
|
14
|
+
*
|
|
15
|
+
* `context.messages.locales` is flat dotted keys, one record per locale tag
|
|
16
|
+
* (the manifest's own wire shape); `unflattenMessages` turns each into the
|
|
17
|
+
* nested shape vue-i18n's `messages` option expects, the same helper
|
|
18
|
+
* `@eldrajs/theme-vue`'s bridge handler uses for a live override push.
|
|
19
|
+
*
|
|
20
|
+
* **The fallback chain.** `manifest.messages?.defaultLocale` is the *theme's*
|
|
21
|
+
* own declared default locale (`package.json`'s `eldra.defaultLocale`,
|
|
22
|
+
* read straight off `virtual:eldra/manifest` — unaffected by the build's
|
|
23
|
+
* platform merge, unlike `context.messages.defaultLocale`, which by the time
|
|
24
|
+
* a build resolves it names the *organisation's* default locale instead; see
|
|
25
|
+
* `@eldrajs/theme-core/i18n`'s `resolveMessageCatalogue`). The organisation's
|
|
26
|
+
* own default locale is `context.locales?.defaultLocale` — a different
|
|
27
|
+
* concept from either, the site's own routing default — so the chain tries
|
|
28
|
+
* that first, falling through to the theme's shipped default last.
|
|
29
|
+
*
|
|
30
|
+
* **The active locale.** `context.locales?.active` already folds in a Studio
|
|
31
|
+
* preview's own locale override (see `@eldrajs/theme-nuxt`'s
|
|
32
|
+
* `createNuxtEldraLocaleState`); `preview.locale` is the fallback for a
|
|
33
|
+
* context assembled without the locale slice at all, the same two-source
|
|
34
|
+
* order every other locale-aware plugin in this theme reads in
|
|
35
|
+
* (`eldra-ui-messages.ts`).
|
|
36
|
+
*
|
|
37
|
+
* **Bridge updates.** Studio's "Theme texts" page pushes `editor:theme-messages`,
|
|
38
|
+
* which `applyThemeMessages` (`@eldrajs/theme-vue`) applies by replacing
|
|
39
|
+
* `context.messages.locales[tag]` wholesale, locale by locale. The deep watch
|
|
40
|
+
* below re-applies every locale vue-i18n already knows (and adopts a locale it
|
|
41
|
+
* does not yet, which `applyThemeMessages` can also add) through
|
|
42
|
+
* `setLocaleMessage` — so a live edit reaches every block's `t(...)` call with
|
|
43
|
+
* no re-render plumbing of its own, the same reactivity `context.messages`
|
|
44
|
+
* being `reactive(...)` is there for.
|
|
45
|
+
*/
|
|
46
|
+
export default defineNuxtPlugin({
|
|
47
|
+
name: 'eldra-i18n',
|
|
48
|
+
setup(nuxtApp) {
|
|
49
|
+
const context = nuxtApp.vueApp.runWithContext(() =>
|
|
50
|
+
inject<EldraContext | undefined>(ELDRA_KEY, undefined)
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
const themeDefaultLocale = manifest.messages?.defaultLocale ?? 'en-US';
|
|
54
|
+
const orgDefaultLocale = context?.locales?.defaultLocale ?? themeDefaultLocale;
|
|
55
|
+
const activeLocale = (): string =>
|
|
56
|
+
context?.locales?.active ?? context?.preview.locale ?? orgDefaultLocale;
|
|
57
|
+
|
|
58
|
+
// Cast through `DefineLocaleMessage` (`app/i18n.d.ts`'s own schema augmentation): the build's
|
|
59
|
+
// own scan/merge already guarantees every locale here carries the default locale's full key set
|
|
60
|
+
// (`@eldrajs/theme-core/i18n`'s `resolveMessageCatalogue`), which is a build-time fact `unflattenMessages`'s
|
|
61
|
+
// generic `Record<string, unknown>` return type cannot itself express.
|
|
62
|
+
const sourceLocales = context?.messages.locales ?? {};
|
|
63
|
+
const messages = Object.fromEntries(
|
|
64
|
+
Object.keys(sourceLocales).map((tag) => [
|
|
65
|
+
tag,
|
|
66
|
+
unflattenMessages(sourceLocales[tag] ?? {}) as DefineLocaleMessage,
|
|
67
|
+
])
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
const i18n = createI18n({
|
|
71
|
+
legacy: false,
|
|
72
|
+
locale: activeLocale(),
|
|
73
|
+
fallbackLocale: [orgDefaultLocale, themeDefaultLocale],
|
|
74
|
+
messages,
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
nuxtApp.vueApp.use(i18n);
|
|
78
|
+
|
|
79
|
+
if (context !== undefined) {
|
|
80
|
+
watch(activeLocale, (locale) => {
|
|
81
|
+
i18n.global.locale.value = locale;
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
watch(
|
|
85
|
+
() => context.messages.locales,
|
|
86
|
+
(locales) => {
|
|
87
|
+
for (const tag of Object.keys(locales)) {
|
|
88
|
+
i18n.global.setLocaleMessage(
|
|
89
|
+
tag,
|
|
90
|
+
unflattenMessages(locales[tag] ?? {}) as DefineLocaleMessage
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
{ deep: true }
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
},
|
|
98
|
+
});
|
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
import { defineNuxtPlugin, useAsyncData, useRouter, useRuntimeConfig } from 'nuxt/app';
|
|
2
|
+
import { getCurrentInstance, nextTick, reactive, watchEffect } from 'vue';
|
|
3
|
+
import { createEldraClient, type EldraRetryOptions } from '@eldrajs/sdk';
|
|
4
|
+
import {
|
|
5
|
+
STOREFRONT_KEY,
|
|
6
|
+
type StorefrontRoute,
|
|
7
|
+
type StorefrontSource,
|
|
8
|
+
type VolatileSnapshot,
|
|
9
|
+
} from '../storefront/types';
|
|
10
|
+
import { toStorefrontCommerce } from '../storefront/commerce';
|
|
11
|
+
import {
|
|
12
|
+
createGatewayStorefront,
|
|
13
|
+
type StorefrontPrerenderHandle,
|
|
14
|
+
type StorefrontRuntime,
|
|
15
|
+
} from '../storefront/gateway';
|
|
16
|
+
import { createVolatileRefresher } from '../storefront/refresh';
|
|
17
|
+
import {
|
|
18
|
+
prerenderThroughAsyncData,
|
|
19
|
+
type KeyedAsyncData,
|
|
20
|
+
type KeyedAsyncDataOptions,
|
|
21
|
+
} from '../storefront/prerender';
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* The only file under `app/storefront/*`'s orbit that touches Nuxt globals (`useRouter`,
|
|
25
|
+
* `useRouter`, `useRuntimeConfig`) — every block reads `useStorefront()` instead, which never
|
|
26
|
+
* does: the route context it exposes is read-only data, and a block may not read the URL itself.
|
|
27
|
+
*
|
|
28
|
+
* Builds the `@eldrajs/sdk` commerce client the theme-nuxt module does not create for you — that
|
|
29
|
+
* module only creates `@eldrajs/theme-core`'s CMS/Studio-bridge client (`ELDRA_KEY`'s
|
|
30
|
+
* `EldraContext.client`), a different, unrelated `EldraClient` with no `catalog`/`cart`/`search`/
|
|
31
|
+
* `orders` at all. Reuses the same gateway URL and org id the module already resolved onto
|
|
32
|
+
* `runtimeConfig.public.eldra` (`@eldrajs/theme-nuxt`'s `module.ts`) rather than asking a customer
|
|
33
|
+
* to configure the same two values twice.
|
|
34
|
+
*
|
|
35
|
+
* `useEldraPage()` is the module's own auto-import (`@eldrajs/theme-nuxt`), called here for one
|
|
36
|
+
* value: `catalog`, the `{ kind, slug }` a catalog-backed route template resolved for this path.
|
|
37
|
+
* It shares Nuxt's `useAsyncData` cache key with `app/pages/[...slug].vue`'s own call, so the page
|
|
38
|
+
* is still resolved once per route.
|
|
39
|
+
*
|
|
40
|
+
* It is also where the storefront's **prerender/refresh runtime** is implemented, for the same
|
|
41
|
+
* reason: both halves are Nuxt's, and `app/storefront/*` may not import Nuxt.
|
|
42
|
+
*
|
|
43
|
+
* * `prerender` runs a result's first load through `useAsyncData` under a stable key, so
|
|
44
|
+
* `nuxi generate` awaits it and writes the value into `_payload.json`, and the hydrating
|
|
45
|
+
* browser reads it back out instead of fetching it again. A result created *after* hydration —
|
|
46
|
+
* a client navigation, a search as the shopper types — gets `null` and loads live, which is
|
|
47
|
+
* what it always did.
|
|
48
|
+
* * `register` collects the page's results into one batched volatile refresh
|
|
49
|
+
* (`app/storefront/refresh.ts`), fired a tick after the app mounts. Not on the server: a
|
|
50
|
+
* prerender's values are the freshest there are at the moment it runs.
|
|
51
|
+
*
|
|
52
|
+
* The refresh is scheduled off the app's mount rather than off the plugin, because the commerce
|
|
53
|
+
* blocks are lazily imported components: their `setup()` — and therefore the result they create —
|
|
54
|
+
* can run well after the plugin has finished.
|
|
55
|
+
*
|
|
56
|
+
* `formsEndpoint` is this starter's own optional config — `runtimeConfig.public` is read
|
|
57
|
+
* defensively (not through the module's typed `eldra` key) since a customer may not have declared
|
|
58
|
+
* it in `nuxt.config.ts` yet; see `README.md` for where to add it. There is no checkout URL to
|
|
59
|
+
* configure: the platform hosts the checkout page and the SDK reads where from the platform
|
|
60
|
+
* itself.
|
|
61
|
+
*/
|
|
62
|
+
export default defineNuxtPlugin({
|
|
63
|
+
name: 'eldra-storefront',
|
|
64
|
+
setup(nuxtApp) {
|
|
65
|
+
const router = useRouter();
|
|
66
|
+
// The router's **committed** route, not `useRoute()`.
|
|
67
|
+
//
|
|
68
|
+
// `useRoute()` is Nuxt's app-level route, and `NuxtPage` syncs that only once the destination
|
|
69
|
+
// page's `<Suspense>` has resolved (`nuxt/dist/pages/runtime/page.js`, `onResolve`). A page's
|
|
70
|
+
// blocks are lazily imported components created *inside* that pending branch, so every
|
|
71
|
+
// storefront result on the page being navigated to would be created under the route context of
|
|
72
|
+
// the page it replaces: a product page whose `productHandle` is still `null` and whose
|
|
73
|
+
// `collectionHandle` is still the collection the shopper clicked from. That is a result keyed
|
|
74
|
+
// differently from the one the build prerendered — so it misses the payload — and then a
|
|
75
|
+
// second, live read the moment the route catches up.
|
|
76
|
+
//
|
|
77
|
+
// `router.currentRoute` is the destination from the moment the navigation is confirmed, which
|
|
78
|
+
// is before any of that happens.
|
|
79
|
+
const activeRoute = router.currentRoute;
|
|
80
|
+
// The catalog object a route template matched, when this path is served by one
|
|
81
|
+
// (`schemaApiId: 'catalog:product' | 'catalog:collection' | 'catalog:category'`); `null` on
|
|
82
|
+
// every other route.
|
|
83
|
+
const { catalog } = useEldraPage();
|
|
84
|
+
// Which content locale this page is — the locale its path prefix names, or the one a Studio
|
|
85
|
+
// preview is driving (`@eldrajs/theme-nuxt`, auto-imported like `useEldraPage`).
|
|
86
|
+
const activeLocale = useEldraLocale();
|
|
87
|
+
|
|
88
|
+
function firstOf(value: string | string[] | undefined | null): string | null {
|
|
89
|
+
if (Array.isArray(value)) return value[0] ?? null;
|
|
90
|
+
return value ?? null;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const route: StorefrontRoute = reactive({
|
|
94
|
+
productHandle: null,
|
|
95
|
+
collectionHandle: null,
|
|
96
|
+
categorySlug: null,
|
|
97
|
+
categoryPath: null,
|
|
98
|
+
orderToken: null,
|
|
99
|
+
query: null,
|
|
100
|
+
page: 1,
|
|
101
|
+
sort: null,
|
|
102
|
+
columns: null,
|
|
103
|
+
filters: {},
|
|
104
|
+
setQuery(patch: Record<string, string | string[] | null>) {
|
|
105
|
+
const nextQuery: Record<string, string | string[]> = {};
|
|
106
|
+
for (const [key, value] of Object.entries(activeRoute.value.query)) {
|
|
107
|
+
if (value !== null && value !== undefined) nextQuery[key] = value as string | string[];
|
|
108
|
+
}
|
|
109
|
+
for (const [key, value] of Object.entries(patch)) {
|
|
110
|
+
if (value === null) delete nextQuery[key];
|
|
111
|
+
else nextQuery[key] = value;
|
|
112
|
+
}
|
|
113
|
+
void router.push({ query: nextQuery });
|
|
114
|
+
},
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
// Query keys with their own typed `StorefrontRoute` field — everything else lands in
|
|
118
|
+
// `route.filters` (see that field's own doc comment in `types.ts`).
|
|
119
|
+
const RESERVED_QUERY_KEYS = new Set(['q', 'page', 'token', 'sort', 'columns']);
|
|
120
|
+
|
|
121
|
+
// Resolved generically off the current path/query since this starter's own commerce page
|
|
122
|
+
// routes are just `/products/:handle`, `/collections/:handle` and an order
|
|
123
|
+
// status page reading `?token=`/`?q=`/`?page=` — a page can still override `productHandle`/
|
|
124
|
+
// `collectionHandle` with its own field before falling back to this.
|
|
125
|
+
//
|
|
126
|
+
// The product/collection handle has two sources, in this order:
|
|
127
|
+
//
|
|
128
|
+
// 1. The catalog route template that matched (`useEldraPage().catalog`). This is the
|
|
129
|
+
// authoritative one: the template owns its own `routePattern`, so a merchant who seeds or
|
|
130
|
+
// edits it to `/shop/:slug` still gets `productHandle` set, and the pattern's parameter is
|
|
131
|
+
// resolved by the same code that loaded the object.
|
|
132
|
+
// 2. The `/products/` / `/collections/` path prefix, for a path this theme serves without a
|
|
133
|
+
// catalog template behind it — the storefront pages a site has before its first deploy
|
|
134
|
+
// seeds the templates, and the demo/Storybook routes.
|
|
135
|
+
watchEffect(() => {
|
|
136
|
+
const handle = firstOf(activeRoute.value.params.handle as string | string[] | undefined);
|
|
137
|
+
const match = catalog.value;
|
|
138
|
+
if (match === null) {
|
|
139
|
+
route.productHandle = activeRoute.value.path.startsWith('/products/') ? handle : null;
|
|
140
|
+
route.collectionHandle = activeRoute.value.path.startsWith('/collections/') ? handle : null;
|
|
141
|
+
// A **category** has no path-prefix fallback, deliberately: unlike a product or a
|
|
142
|
+
// collection its route is addressed by a whole canonical path, and only the resolution that
|
|
143
|
+
// walked the tree knows which prefix of the URL was the category and whether it was
|
|
144
|
+
// canonical at all. A path this theme serves without a category template behind it is
|
|
145
|
+
// therefore not a category page.
|
|
146
|
+
route.categorySlug = null;
|
|
147
|
+
route.categoryPath = null;
|
|
148
|
+
} else {
|
|
149
|
+
route.productHandle = match.kind === 'product' ? match.slug : null;
|
|
150
|
+
route.collectionHandle = match.kind === 'collection' ? match.slug : null;
|
|
151
|
+
route.categorySlug = match.kind === 'category' ? match.slug : null;
|
|
152
|
+
route.categoryPath = match.kind === 'category' ? (match.path ?? null) : null;
|
|
153
|
+
}
|
|
154
|
+
route.orderToken = firstOf(activeRoute.value.query.token as string | string[] | undefined);
|
|
155
|
+
route.query = firstOf(activeRoute.value.query.q as string | string[] | undefined);
|
|
156
|
+
const page = Number(firstOf(activeRoute.value.query.page as string | string[] | undefined));
|
|
157
|
+
route.page = Number.isFinite(page) && page > 0 ? page : 1;
|
|
158
|
+
route.sort = firstOf(activeRoute.value.query.sort as string | string[] | undefined);
|
|
159
|
+
route.columns = firstOf(activeRoute.value.query.columns as string | string[] | undefined);
|
|
160
|
+
|
|
161
|
+
const filters: Record<string, string[]> = {};
|
|
162
|
+
for (const [key, value] of Object.entries(activeRoute.value.query)) {
|
|
163
|
+
if (RESERVED_QUERY_KEYS.has(key) || value === null || value === undefined) continue;
|
|
164
|
+
filters[key] = Array.isArray(value) ? (value as string[]) : [value as string];
|
|
165
|
+
}
|
|
166
|
+
route.filters = filters;
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
const publicConfig = useRuntimeConfig().public as unknown as {
|
|
170
|
+
eldra?: {
|
|
171
|
+
gatewayUrl?: string;
|
|
172
|
+
orgId?: string;
|
|
173
|
+
commerce?: unknown;
|
|
174
|
+
retry?: EldraRetryOptions | null;
|
|
175
|
+
};
|
|
176
|
+
formsEndpoint?: string;
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
const client = createEldraClient({
|
|
180
|
+
apiBaseUrl: publicConfig.eldra?.gatewayUrl || undefined,
|
|
181
|
+
orgId: publicConfig.eldra?.orgId || undefined,
|
|
182
|
+
// The theme's own retry policy, set once in `nuxt.config.ts`'s `eldra`
|
|
183
|
+
// block and carried here in the runtime config: a prerender of this site
|
|
184
|
+
// reads the catalogue through this client and the pages through
|
|
185
|
+
// @eldrajs/theme-nuxt's, and a rate limit that only one of them waits
|
|
186
|
+
// out still fails the build.
|
|
187
|
+
retry: publicConfig.eldra?.retry ?? undefined,
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
let source: StorefrontSource | null = null;
|
|
191
|
+
|
|
192
|
+
// The blocks' results are created while the app hydrates; the app is mounted once they all
|
|
193
|
+
// are. `nextTick` after that gives every result registered in the same render a seat in the
|
|
194
|
+
// one batch — the point of collecting them at all.
|
|
195
|
+
let mounted = false;
|
|
196
|
+
const afterMount: Array<() => void> = [];
|
|
197
|
+
nuxtApp.hook('app:mounted', () => {
|
|
198
|
+
mounted = true;
|
|
199
|
+
for (const run of afterMount.splice(0)) run();
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
const refresher = createVolatileRefresher(
|
|
203
|
+
(ids: string[]): Promise<VolatileSnapshot[]> =>
|
|
204
|
+
source === null ? Promise.resolve([]) : source.catalog.volatileByIds(ids),
|
|
205
|
+
(run) => {
|
|
206
|
+
const schedule = (): void => void nextTick(run);
|
|
207
|
+
if (mounted) schedule();
|
|
208
|
+
else afterMount.push(schedule);
|
|
209
|
+
}
|
|
210
|
+
);
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Nuxt's own keyed async data, narrowed to the shape `app/storefront/prerender.ts` works
|
|
214
|
+
* against — which is also where the two options that matter, and why, are written down. The
|
|
215
|
+
* cast is the one thing that needs saying here: `useAsyncData` re-describes its data as
|
|
216
|
+
* `PickFrom<T, KeysOf<T>>` for its `pick` option, which tells this caller nothing it does not
|
|
217
|
+
* already know — the value is whatever the load returned.
|
|
218
|
+
*/
|
|
219
|
+
function keyedAsyncData<T>(
|
|
220
|
+
key: string,
|
|
221
|
+
load: () => Promise<T | null>,
|
|
222
|
+
options: KeyedAsyncDataOptions
|
|
223
|
+
): KeyedAsyncData<T> {
|
|
224
|
+
const handle = useAsyncData<T | null>(key, load, options);
|
|
225
|
+
return {
|
|
226
|
+
data: handle.data as unknown as { value: T | null | undefined },
|
|
227
|
+
error: handle.error,
|
|
228
|
+
status: handle.status,
|
|
229
|
+
execute: () => handle.execute(),
|
|
230
|
+
settled: handle,
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
const runtime: StorefrontRuntime = {
|
|
235
|
+
prerender<T>(
|
|
236
|
+
key: string,
|
|
237
|
+
load: () => Promise<T | null>
|
|
238
|
+
): StorefrontPrerenderHandle<T> | null {
|
|
239
|
+
// `useAsyncData` outside a component's `setup()` has no server-prefetch to register on.
|
|
240
|
+
if (getCurrentInstance() === null) return null;
|
|
241
|
+
// After hydration, only when the build actually answered this key. Nuxt's payload plugin
|
|
242
|
+
// loads the destination's `_payload.json` in `router.beforeResolve` and writes every key in
|
|
243
|
+
// it into `nuxtApp.static.data` before the page component exists
|
|
244
|
+
// (`nuxt/dist/app/plugins/payload.client.js`), so on a navigation to a **prerendered**
|
|
245
|
+
// route the answer this result wants is already in memory — reading it back is what makes
|
|
246
|
+
// a client navigation land on real prices instead of a skeleton, and what leaves the page
|
|
247
|
+
// with the same one batched volatile refresh a hard load makes.
|
|
248
|
+
//
|
|
249
|
+
// A key that is not there is a route the build does not have (a preview, a dev server) or
|
|
250
|
+
// a result the build could not know about (a search as the shopper types): it loads live,
|
|
251
|
+
// exactly as it always did, and stays out of the volatile refresh because it has just read
|
|
252
|
+
// the live values itself (`app/storefront/gateway.ts`'s `ranUnderPrerender`).
|
|
253
|
+
if (import.meta.client && !nuxtApp.isHydrating && !(key in nuxtApp.static.data))
|
|
254
|
+
return null;
|
|
255
|
+
return prerenderThroughAsyncData<T>(keyedAsyncData, key, load);
|
|
256
|
+
},
|
|
257
|
+
// Only the browser refreshes: on the server the read that just ran *is* the live value.
|
|
258
|
+
register: import.meta.client ? (entry) => refresher.register(entry) : undefined,
|
|
259
|
+
};
|
|
260
|
+
|
|
261
|
+
source = createGatewayStorefront(client, {
|
|
262
|
+
route,
|
|
263
|
+
// What the store sells in, as the platform published it — the module read it once during the
|
|
264
|
+
// build (`@eldrajs/theme-nuxt`), so a prerendered page already has it. `app/plugins/
|
|
265
|
+
// eldra-ui-messages.ts` provides the currency half to `@eldrajs/ui`; this puts the whole
|
|
266
|
+
// record on `useStorefront()` for the blocks that need the tax-inclusive flag.
|
|
267
|
+
commerce: toStorefrontCommerce(publicConfig.eldra?.commerce),
|
|
268
|
+
// The page's own content locale, read fresh on every call so it follows a language switch.
|
|
269
|
+
// Every catalog, search and order read carries it, and it is part of each result's cache key
|
|
270
|
+
// — see `withContentLocale` in `app/storefront/gateway.ts`.
|
|
271
|
+
//
|
|
272
|
+
// `undefined` for the locale served at `/`, which is the same rule `@eldrajs/theme-nuxt`
|
|
273
|
+
// applies to its own CMS reads (`localeForPath`): that locale's content *is* what the gateway
|
|
274
|
+
// answers without a `locale`, so sending it would change every request every existing site
|
|
275
|
+
// makes without changing one answer — and would change every prerendered payload's keys with
|
|
276
|
+
// it. So a single-locale store, and the default half of a multi-locale one, send exactly what
|
|
277
|
+
// they sent before locales existed.
|
|
278
|
+
locale: () =>
|
|
279
|
+
activeLocale.active === null || activeLocale.active === activeLocale.defaultLocale
|
|
280
|
+
? undefined
|
|
281
|
+
: activeLocale.active,
|
|
282
|
+
formsEndpoint: publicConfig.formsEndpoint,
|
|
283
|
+
runtime,
|
|
284
|
+
});
|
|
285
|
+
|
|
286
|
+
nuxtApp.vueApp.provide(STOREFRONT_KEY, source);
|
|
287
|
+
},
|
|
288
|
+
});
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { defineNuxtPlugin, useRuntimeConfig } from 'nuxt/app';
|
|
2
|
+
import { inject } from 'vue';
|
|
3
|
+
import {
|
|
4
|
+
CURRENCY_KEY,
|
|
5
|
+
LOCALE_KEY,
|
|
6
|
+
MESSAGES_KEY,
|
|
7
|
+
enUS as uiEnUS,
|
|
8
|
+
type UiMessages,
|
|
9
|
+
} from '@eldrajs/ui';
|
|
10
|
+
import { isIS as uiIsIS } from '@eldrajs/ui/messages/is-IS';
|
|
11
|
+
import { ELDRA_KEY, type EldraContext } from '@eldrajs/theme-vue';
|
|
12
|
+
import { toStorefrontCommerce } from '../storefront/commerce';
|
|
13
|
+
|
|
14
|
+
/** The package's own default message set for a content locale — `is-IS` takes its Icelandic entry
|
|
15
|
+
* point, anything else (including `undefined`) keeps the English defaults. Only this plugin's own
|
|
16
|
+
* fallback for a key the active locale's catalogue carries no override of, or a parameterized key
|
|
17
|
+
* (see below) the catalogue cannot carry at all. */
|
|
18
|
+
function uiPackageMessagesFor(locale: string | null | undefined): UiMessages {
|
|
19
|
+
return locale === 'is-IS' ? uiIsIS : uiEnUS;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Gives every `@eldrajs/ui` component below the app the message set for the
|
|
24
|
+
* active content locale (`useEldra().locales.active`, the same source
|
|
25
|
+
* `app/plugins/eldra-i18n.ts`'s `vue-i18n` plugin reads) — so the package's
|
|
26
|
+
* own strings follow the locale the page is served under, and Studio's locale
|
|
27
|
+
* switch, instead of being pinned to English at build time. `preview.locale`
|
|
28
|
+
* is the fallback for a context assembled without the locale slice.
|
|
29
|
+
*
|
|
30
|
+
* The provided object is a set of getters rather than a snapshot. `useMessages`
|
|
31
|
+
* reads the injected object inside a `computed`, so touching `preview.locale`
|
|
32
|
+
* through a getter is what makes the switch reactive — and, unlike a `watch`,
|
|
33
|
+
* it creates no effect that would outlive a server request.
|
|
34
|
+
*
|
|
35
|
+
* The same provide gives the package the content locale its **numbers** are
|
|
36
|
+
* formatted in (`UnitInput`, `CurrencyInput`, `QuantityStepper`, `Price`), as
|
|
37
|
+
* a getter for the same reason, plus the store **currency** `Price` formats
|
|
38
|
+
* amounts in. All three are separate keys on purpose: the strings a component
|
|
39
|
+
* renders, the locale its numbers are formatted in, and the currency its
|
|
40
|
+
* prices are formatted in are three different decisions, and a component's own
|
|
41
|
+
* `locale`/`currency` prop still wins over any of these.
|
|
42
|
+
*
|
|
43
|
+
* **The currency is the platform's, not the locale's.** It comes from the
|
|
44
|
+
* organisation's own commerce settings, which `@eldrajs/theme-nuxt` reads once
|
|
45
|
+
* during the build and puts on `runtimeConfig.public.eldra.commerce`. A store
|
|
46
|
+
* that publishes none provides `undefined`, which `@eldrajs/ui` reads as "this
|
|
47
|
+
* store has no currency" rather than as "nobody wired the provide" — so every
|
|
48
|
+
* price on the page renders as a plain number instead of under a symbol nobody
|
|
49
|
+
* chose, and the package logs nothing. The provide happens either way, which is
|
|
50
|
+
* the part that matters: no provider at all is the case the package warns
|
|
51
|
+
* about. It is read once here, not through a getter: unlike the locale, it
|
|
52
|
+
* cannot change while the page is open.
|
|
53
|
+
*
|
|
54
|
+
* `runWithContext` is how a plugin injects an app-level provide from outside a
|
|
55
|
+
* `setup()` scope: @eldrajs/theme-nuxt's own plugin puts the context on
|
|
56
|
+
* `vueApp` before this one runs. Absent it (nothing else in this theme
|
|
57
|
+
* depends on that ordering) the English defaults stand.
|
|
58
|
+
*
|
|
59
|
+
* **The package's own strings now come from the theme's message catalogue**
|
|
60
|
+
* (`context.messages`, under the `ui.*` namespace — "Kit: the `@eldrajs/ui`
|
|
61
|
+
* message sets go under `ui.*` in the same files"), not from the package's
|
|
62
|
+
* exports directly, so Studio can override one the same way it overrides any
|
|
63
|
+
* other theme text. Only the package's **plain-string** keys can travel that
|
|
64
|
+
* way: `i18n/<tag>.json`'s `ui.*` section holds exactly those (the manifest
|
|
65
|
+
* scanner only accepts string values, so a function could never reach it in
|
|
66
|
+
* the first place). The package's ~40 **parameterized** keys (`closeDrawer`,
|
|
67
|
+
* `reviewCount`, …) are not in the catalogue at all and are not overridable —
|
|
68
|
+
* they keep coming straight from `uiPackageMessagesFor`, functions and all,
|
|
69
|
+
* which is also where a plain-string key falls back to when the active
|
|
70
|
+
* locale's catalogue entry is missing (an organisation locale the theme ships
|
|
71
|
+
* no `ui.*` translation for).
|
|
72
|
+
*/
|
|
73
|
+
export default defineNuxtPlugin({
|
|
74
|
+
name: 'eldra-ui-messages',
|
|
75
|
+
setup(nuxtApp) {
|
|
76
|
+
const context = nuxtApp.vueApp.runWithContext(() =>
|
|
77
|
+
inject<EldraContext | undefined>(ELDRA_KEY, undefined)
|
|
78
|
+
);
|
|
79
|
+
const publicConfig = useRuntimeConfig().public as unknown as {
|
|
80
|
+
eldra?: { commerce?: unknown };
|
|
81
|
+
};
|
|
82
|
+
const currency = toStorefrontCommerce(publicConfig.eldra?.commerce)?.currency;
|
|
83
|
+
// The page's own content locale, read through a getter on every access for the same reason
|
|
84
|
+
// the message getters below exist: it changes when the visitor changes language, and the
|
|
85
|
+
// package reads both inside a `computed`.
|
|
86
|
+
const activeLocale = (): string | undefined =>
|
|
87
|
+
context?.locales?.active ?? context?.preview.locale ?? undefined;
|
|
88
|
+
const messages = {} as UiMessages;
|
|
89
|
+
for (const key of Object.keys(uiEnUS) as (keyof UiMessages)[]) {
|
|
90
|
+
Object.defineProperty(messages, key, {
|
|
91
|
+
enumerable: true,
|
|
92
|
+
get: () => {
|
|
93
|
+
const locale = activeLocale();
|
|
94
|
+
const packageValue = uiPackageMessagesFor(locale)[key];
|
|
95
|
+
if (typeof packageValue === 'function') return packageValue;
|
|
96
|
+
const resolvedLocale = locale ?? context?.messages.defaultLocale;
|
|
97
|
+
const override = resolvedLocale
|
|
98
|
+
? context?.messages.locales[resolvedLocale]?.[`ui.${key}`]
|
|
99
|
+
: undefined;
|
|
100
|
+
return override ?? packageValue;
|
|
101
|
+
},
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
nuxtApp.vueApp.provide(MESSAGES_KEY, messages);
|
|
105
|
+
// The same value is the locale every `Intl` format in the theme runs in — `@eldrajs/ui`'s
|
|
106
|
+
// `Price`/`CurrencyInput` and, through `useEldraUiLocale()`, `app/storefront/money.ts`. So a
|
|
107
|
+
// page served under `/is-IS` prints "2.800 kr." where the same money reads "kr 2,800" on the
|
|
108
|
+
// English one, while the currency itself stays the store's.
|
|
109
|
+
nuxtApp.vueApp.provide(LOCALE_KEY, activeLocale);
|
|
110
|
+
nuxtApp.vueApp.provide(CURRENCY_KEY, currency);
|
|
111
|
+
},
|
|
112
|
+
});
|