@thorprovider/storefront 0.15.1 → 0.15.3
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/README.md +1 -1
- package/assets/templates/app/app/[[...slug]]/page.tsx +16 -4
- package/assets/templates/app/lib/__STOREFRONT__/header-universal.ts +373 -0
- package/assets/templates/app/lib/__STOREFRONT__/registry.tsx +143 -11
- package/assets/templates/app/lib/__STOREFRONT__/schema.ts +52 -0
- package/assets/templates/app/lib/__STOREFRONT__/shell/content.ts +43 -0
- package/assets/templates/app/lib/__STOREFRONT__/shell/props.ts +4 -0
- package/assets/templates/app/lib/__STOREFRONT__/spec/index.ts +22 -40
- package/assets/templates/app/lib/__STOREFRONT__/views/sections/header-universal.client.tsx +33 -0
- package/assets/templates/app/lib/__STOREFRONT__/views/sections/header-universal.tsx +16 -0
- package/assets/templates/app/lib/__STOREFRONT__/views/sections/index.ts +2 -1
- package/assets/templates/app/lib/__STOREFRONT__/views/sections/schema.header-universal.ts +360 -0
- package/assets/templates/app/lib/__STOREFRONT__/views/sections/schema.universal-banner.ts +1 -0
- package/assets/templates/app/lib/__STOREFRONT__/views/sections/universal-banner.client.tsx +4 -1
- package/assets/templates/app/public/demo/accessories.svg +7 -0
- package/assets/templates/app/public/demo/dresses.svg +6 -0
- package/assets/templates/app/public/demo/furniture.svg +9 -0
- package/assets/templates/app/public/demo/home.svg +8 -0
- package/assets/templates/app/public/demo/jackets.svg +11 -0
- package/assets/templates/app/public/demo/promo-invierno.svg +8 -0
- package/assets/templates/features/checkout/state.ts +2 -0
- package/assets/templates/views/category/assembly/slots/filter/CategoryListing/element.part +1 -0
- package/assets/templates/views/category/assembly/slots/filter/CategoryListing/registry.part +2 -0
- package/assets/templates/views/category/content.ts +1 -0
- package/assets/templates/views/category/index.tsx +1 -0
- package/assets/templates/views/category/registry.tsx +2 -0
- package/assets/templates/views/category/schema.ts +2 -0
- package/assets/templates/views/checkout/checkout-commerce-hosted.tsx +19 -0
- package/assets/templates/views/checkout/registry.tsx +22 -5
- package/assets/templates/views/home/assembly/slots/hero/UniversalBanner/registry.part +6 -1
- package/assets/templates/views/home/content.ts +2 -0
- package/assets/templates/views/home/props.ts +8 -1
- package/assets/templates/views/home/registry.tsx +6 -1
- package/assets/templates/views/home/schema.ts +1 -0
- package/package.json +1 -1
- package/recipes/sections.json +18 -0
- package/scripts/candidate.mjs +2 -2
- package/scripts/env-file.mjs +5 -0
- package/scripts/file-classes.mjs +7 -2
- package/scripts/reconcile.mjs +4 -1
- package/scripts/render-templates.mjs +106 -1
- package/skills/sf-view-gen/assets/recipes/sections.json +18 -0
- package/skills/sf-view-gen/assets/templates/views/sections/header-universal.client.tsx +33 -0
- package/skills/sf-view-gen/assets/templates/views/sections/header-universal.tsx +16 -0
- package/skills/sf-view-gen/assets/templates/views/sections/schema.header-universal.ts +360 -0
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
import { z } from 'zod'
|
|
8
8
|
|
|
9
9
|
import { footerContentSchema } from './footer-content'
|
|
10
|
+
import { universalMainMenuDataSchema } from './views/sections/schema.universal-main-menu'
|
|
10
11
|
|
|
11
12
|
export const ctaSchema = z.object({
|
|
12
13
|
label: z.string(),
|
|
@@ -126,6 +127,40 @@ export const accountMenuItemSchema = z.object({
|
|
|
126
127
|
icon: z.enum(['orders', 'wishlist', 'addresses', 'settings']).optional(),
|
|
127
128
|
})
|
|
128
129
|
|
|
130
|
+
// Chrome copy mirror of the block's `StorefrontNavbarLabels` (quality baseline
|
|
131
|
+
// D3). Plain strings only; every field optional so an omitted label keeps the
|
|
132
|
+
// block's shipped English default. `{count}`/`{name}` tokens are filled by the
|
|
133
|
+
// block, so they survive serialization untouched.
|
|
134
|
+
export const storefrontNavbarLabelsSchema = z.object({
|
|
135
|
+
openMenu: z.string().optional(),
|
|
136
|
+
storeNav: z.string().optional(),
|
|
137
|
+
account: z.string().optional(),
|
|
138
|
+
search: z.string().optional(),
|
|
139
|
+
loadingAccount: z.string().optional(),
|
|
140
|
+
accountRetry: z.string().optional(),
|
|
141
|
+
accountUnavailableTitle: z.string().optional(),
|
|
142
|
+
accountMenu: z.string().optional(),
|
|
143
|
+
help: z.string().optional(),
|
|
144
|
+
signOut: z.string().optional(),
|
|
145
|
+
cartCount: z.string().optional(),
|
|
146
|
+
cartCountOne: z.string().optional(),
|
|
147
|
+
cartContains: z.string().optional(),
|
|
148
|
+
cartContainsOne: z.string().optional(),
|
|
149
|
+
cartTitle: z.string().optional(),
|
|
150
|
+
cartClose: z.string().optional(),
|
|
151
|
+
decreaseQuantity: z.string().optional(),
|
|
152
|
+
increaseQuantity: z.string().optional(),
|
|
153
|
+
remove: z.string().optional(),
|
|
154
|
+
removeItem: z.string().optional(),
|
|
155
|
+
emptyTitle: z.string().optional(),
|
|
156
|
+
emptyDescription: z.string().optional(),
|
|
157
|
+
continueShopping: z.string().optional(),
|
|
158
|
+
subtotal: z.string().optional(),
|
|
159
|
+
shippingTaxes: z.string().optional(),
|
|
160
|
+
checkout: z.string().optional(),
|
|
161
|
+
viewCart: z.string().optional(),
|
|
162
|
+
})
|
|
163
|
+
|
|
129
164
|
export const storefrontNavbarPropsSchema = z.object({
|
|
130
165
|
storeCategories: z.array(navCategorySchema),
|
|
131
166
|
shippingNote: z.string().optional(),
|
|
@@ -145,6 +180,8 @@ export const storefrontNavbarPropsSchema = z.object({
|
|
|
145
180
|
// Held global search (E2 task 5.4): the generated shell opts out of the
|
|
146
181
|
// navbar search control while no verified global search contract exists.
|
|
147
182
|
showSearch: z.boolean().optional(),
|
|
183
|
+
// Chrome copy in the store language, from the user-owned shell seam.
|
|
184
|
+
labels: storefrontNavbarLabelsSchema.optional(),
|
|
148
185
|
})
|
|
149
186
|
|
|
150
187
|
export const bannerPropsSchema = z.object({
|
|
@@ -153,6 +190,8 @@ export const bannerPropsSchema = z.object({
|
|
|
153
190
|
href: z.string(),
|
|
154
191
|
linkLabel: z.string(),
|
|
155
192
|
avatars: z.array(z.string()).optional(),
|
|
193
|
+
// Dismiss copy in the store language; the block defaults to English.
|
|
194
|
+
dismissLabel: z.string().optional(),
|
|
156
195
|
})
|
|
157
196
|
|
|
158
197
|
export const productGridPropsSchema = z.object({
|
|
@@ -204,3 +243,16 @@ export const mobileBottomNavPropsSchema = z.object({
|
|
|
204
243
|
ariaLabel: z.string().optional(),
|
|
205
244
|
className: z.string().optional(),
|
|
206
245
|
})
|
|
246
|
+
|
|
247
|
+
// The universal header's shell props. The config and labels are authored in
|
|
248
|
+
// the shell data module (`../header-universal`) and the runtime `HeaderContext`
|
|
249
|
+
// is built from the site name and the host-fed menu, so the shell only declares
|
|
250
|
+
// the serializable chrome: the site name, the menu data, and the user-owned
|
|
251
|
+
// brand seam (wordmark accent + surface class). `menu` is optional so a failed
|
|
252
|
+
// catalog read still renders the wordmark.
|
|
253
|
+
export const universalHeaderShellPropsSchema = z.object({
|
|
254
|
+
siteName: z.string(),
|
|
255
|
+
menu: universalMainMenuDataSchema.optional(),
|
|
256
|
+
logoAccent: shellAccentSchema.optional(),
|
|
257
|
+
className: z.string().optional(),
|
|
258
|
+
})
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
// the footer content contract, not here: `GET /store/footer` is what a backend
|
|
15
15
|
// implements, and `../footer-content.ts` documents its shape and defaults.
|
|
16
16
|
|
|
17
|
+
import type { StorefrontNavbarLabels } from '@thorprovider/blocks'
|
|
17
18
|
import type { FooterContent } from '../footer-content'
|
|
18
19
|
|
|
19
20
|
export interface ShellAccent {
|
|
@@ -59,6 +60,48 @@ export const navbarClassName: string | undefined = undefined
|
|
|
59
60
|
*/
|
|
60
61
|
export const footerClassName: string | undefined = undefined
|
|
61
62
|
|
|
63
|
+
/**
|
|
64
|
+
* Accessible name of the announcement banner's dismiss control. The block
|
|
65
|
+
* defaults to English; the generated store speaks Spanish from here.
|
|
66
|
+
*/
|
|
67
|
+
export const bannerDismissLabel: string = 'Cerrar anuncio'
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Chrome copy for the navbar and its cart sheet (header, search, account,
|
|
71
|
+
* cart count, sheet actions). The blocks default to English; the generated
|
|
72
|
+
* store speaks Spanish from here. `{count}`/`{name}` are filled by the block;
|
|
73
|
+
* keep them in any translation. Omit a key to keep the block's default.
|
|
74
|
+
*/
|
|
75
|
+
export const navbarLabels: StorefrontNavbarLabels = {
|
|
76
|
+
openMenu: 'Abrir menú',
|
|
77
|
+
storeNav: 'Tienda',
|
|
78
|
+
account: 'Cuenta',
|
|
79
|
+
search: 'Buscar productos',
|
|
80
|
+
loadingAccount: 'Cargando sesión de cuenta',
|
|
81
|
+
accountRetry: 'Reintentar sesión de cuenta',
|
|
82
|
+
accountUnavailableTitle: 'Sesión de cuenta no disponible',
|
|
83
|
+
accountMenu: 'Menú de cuenta de {name}',
|
|
84
|
+
help: 'Ayuda y soporte',
|
|
85
|
+
signOut: 'Cerrar sesión',
|
|
86
|
+
cartCount: 'Carrito, {count} artículos',
|
|
87
|
+
cartCountOne: 'Carrito, {count} artículo',
|
|
88
|
+
cartContains: 'El carrito contiene {count} artículos',
|
|
89
|
+
cartContainsOne: 'El carrito contiene {count} artículo',
|
|
90
|
+
cartTitle: 'Carrito',
|
|
91
|
+
cartClose: 'Cerrar',
|
|
92
|
+
decreaseQuantity: 'Disminuir cantidad',
|
|
93
|
+
increaseQuantity: 'Aumentar cantidad',
|
|
94
|
+
remove: 'Quitar',
|
|
95
|
+
removeItem: 'Quitar {name} del carrito',
|
|
96
|
+
emptyTitle: 'Tu carrito está vacío',
|
|
97
|
+
emptyDescription: 'Cuando agregues algo, aparecerá aquí.',
|
|
98
|
+
continueShopping: 'Seguir comprando',
|
|
99
|
+
subtotal: 'Subtotal',
|
|
100
|
+
shippingTaxes: 'El envío y los impuestos se calculan al finalizar la compra.',
|
|
101
|
+
checkout: 'Finalizar compra',
|
|
102
|
+
viewCart: 'Ver carrito',
|
|
103
|
+
}
|
|
104
|
+
|
|
62
105
|
/** Neutral footer brand description. No delivery/shipping promise. */
|
|
63
106
|
export const brandDescription: string =
|
|
64
107
|
'Catálogo en línea de productos para tu hogar y tu negocio.'
|
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
linkColumns,
|
|
13
13
|
logoAccent,
|
|
14
14
|
navbarClassName,
|
|
15
|
+
navbarLabels,
|
|
15
16
|
shippingNote,
|
|
16
17
|
} from './content'
|
|
17
18
|
import { footerContentDefaults } from '../footer-content'
|
|
@@ -19,6 +20,9 @@ import { footerContentDefaults } from '../footer-content'
|
|
|
19
20
|
export const navbarShellProps = {
|
|
20
21
|
logoAccent,
|
|
21
22
|
className: navbarClassName,
|
|
23
|
+
// Chrome copy in the store language; the blocks keep English defaults for
|
|
24
|
+
// consumers that supply nothing (quality baseline D3).
|
|
25
|
+
labels: navbarLabels,
|
|
22
26
|
// Optional utility-strip note. Empty by default, so the strip renders only
|
|
23
27
|
// once a real note (or a utility link) is configured.
|
|
24
28
|
shippingNote,
|
|
@@ -6,8 +6,12 @@ import type { NextAppSpec } from '@json-render/next'
|
|
|
6
6
|
import { storefrontInitialState } from '../state'
|
|
7
7
|
import { views } from '../views'
|
|
8
8
|
import { footerShellProps, navbarShellProps } from '../shell/props'
|
|
9
|
-
import { mobileBottomNavItems } from '../shell/content'
|
|
10
|
-
import {
|
|
9
|
+
import { bannerDismissLabel, mobileBottomNavItems } from '../shell/content'
|
|
10
|
+
import {
|
|
11
|
+
checkoutAvailable,
|
|
12
|
+
mountedFeatureConfigs,
|
|
13
|
+
mountedFeatureNames,
|
|
14
|
+
} from '../composition'
|
|
11
15
|
import type { StorefrontElement } from './types'
|
|
12
16
|
|
|
13
17
|
export type { StorefrontElement }
|
|
@@ -52,16 +56,11 @@ const navigabilityConfig = (mountedFeatureConfigs['navigability'] ?? {}) as {
|
|
|
52
56
|
}
|
|
53
57
|
const showBackToTop = navigabilityConfig.showBackToTop !== false
|
|
54
58
|
|
|
55
|
-
//
|
|
56
|
-
//
|
|
57
|
-
//
|
|
58
|
-
//
|
|
59
|
-
//
|
|
60
|
-
const authMounted = mountedFeatureNames.includes('customer-auth')
|
|
61
|
-
const DEFAULT_ACCOUNT_MENU_ITEMS = [
|
|
62
|
-
{ label: 'Pedidos', href: '/account', icon: 'orders' as const },
|
|
63
|
-
]
|
|
64
|
-
|
|
59
|
+
// The universal header replaces the canonical sticky navbar as the shell's
|
|
60
|
+
// navigation: its menu IS the universal main menu (ghost trigger, container
|
|
61
|
+
// anchor) and it carries no horizontal category strip. The wordmark accent and
|
|
62
|
+
// surface class still come from the user-owned shell seam (`navbarShellProps`,
|
|
63
|
+
// spread last).
|
|
65
64
|
const shellElements: Record<string, StorefrontElement> = {
|
|
66
65
|
// Navigability chrome, present only when the feature is installed. The skip
|
|
67
66
|
// link is the first focusable element (rendered before the notices); the
|
|
@@ -102,26 +101,20 @@ const shellElements: Record<string, StorefrontElement> = {
|
|
|
102
101
|
message: 'Descubre el catálogo de __SITE_NAME__.',
|
|
103
102
|
href: '/categories',
|
|
104
103
|
linkLabel: 'Ver catálogo',
|
|
104
|
+
// Dismiss copy comes from the user-owned shell seam, like the navbar
|
|
105
|
+
// labels; the block itself defaults to English.
|
|
106
|
+
dismissLabel: bannerDismissLabel,
|
|
105
107
|
},
|
|
106
108
|
visible: { $state: '/bannerDismissed', not: true },
|
|
107
109
|
on: { dismissBanner: { action: 'dismissBanner' } },
|
|
108
110
|
},
|
|
109
|
-
|
|
110
|
-
type: '
|
|
111
|
+
'universal-header': {
|
|
112
|
+
type: 'HeaderUniversal',
|
|
111
113
|
props: {
|
|
112
|
-
|
|
113
|
-
//
|
|
114
|
-
//
|
|
115
|
-
|
|
116
|
-
utilityLinks: [],
|
|
117
|
-
logoText: '__SITE_NAME__',
|
|
118
|
-
logoHref: '/',
|
|
119
|
-
// Gated account defaults, injected BEFORE the shell spread so an authored
|
|
120
|
-
// `accountHref`/`accountMenuItems` in the user-owned shell wins. A
|
|
121
|
-
// non-adopter passes neither and keeps its baseline chrome exactly.
|
|
122
|
-
...(authMounted
|
|
123
|
-
? { accountHref: '/account', accountMenuItems: DEFAULT_ACCOUNT_MENU_ITEMS }
|
|
124
|
-
: {}),
|
|
114
|
+
siteName: '__SITE_NAME__',
|
|
115
|
+
// The menu is the storefront's real catalog taxonomy, built server-side
|
|
116
|
+
// in the catch-all page and carried through state.
|
|
117
|
+
menu: { $state: '/headerMenu' },
|
|
125
118
|
// Optional wordmark accent and surface classes, configured in the
|
|
126
119
|
// user-owned shell seam. Spread last so merchant edits win.
|
|
127
120
|
...navbarShellProps,
|
|
@@ -129,18 +122,7 @@ const shellElements: Record<string, StorefrontElement> = {
|
|
|
129
122
|
on: {
|
|
130
123
|
openCart: { action: 'openCart' },
|
|
131
124
|
goToCart: { action: 'goToCart' },
|
|
132
|
-
goToCheckout: { action: 'goToCheckout' },
|
|
133
|
-
applyQuantityDelta: { action: 'applyQuantityDelta' },
|
|
134
|
-
removeFromCart: { action: 'removeFromCart' },
|
|
135
|
-
// The account sign-out and retry reuse customer-auth's existing `logout`
|
|
136
|
-
// and `retryAccountSession` actions (the latter is what the account
|
|
137
|
-
// boundary emits too); wired only while the capability is mounted.
|
|
138
|
-
...(authMounted
|
|
139
|
-
? {
|
|
140
|
-
logout: { action: 'logout' },
|
|
141
|
-
retryAccountSession: { action: 'retryAccountSession' },
|
|
142
|
-
}
|
|
143
|
-
: {}),
|
|
125
|
+
...(checkoutAvailable ? { goToCheckout: { action: 'goToCheckout' } } : {}),
|
|
144
126
|
},
|
|
145
127
|
},
|
|
146
128
|
footer: {
|
|
@@ -176,7 +158,7 @@ export const __STOREFRONT_CAMEL__Spec: NextAppSpec = {
|
|
|
176
158
|
? { chrome: ['skipToContent', 'backToTop', 'mobileBottomNav'] }
|
|
177
159
|
: {}),
|
|
178
160
|
notices: ['notice'],
|
|
179
|
-
header: ['banner', '
|
|
161
|
+
header: ['banner', 'universal-header'],
|
|
180
162
|
footer: ['footer'],
|
|
181
163
|
},
|
|
182
164
|
children: ['slot'],
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
// Optional section fragment: header-universal (mirrors recipes/sections.json) — client registry.
|
|
4
|
+
// The matching server-side catalog lives in header-universal.tsx. @thorprovider/blocks ships a
|
|
5
|
+
// 'use client' boundary, but this fragment keeps the explicit client boundary so
|
|
6
|
+
// the section composes identically in any consumer graph.
|
|
7
|
+
|
|
8
|
+
import { useRouter } from 'next/navigation'
|
|
9
|
+
import { HeaderUniversal } from '@thorprovider/blocks'
|
|
10
|
+
import { universalHeaderPropsSchema } from './schema.header-universal'
|
|
11
|
+
import type { ViewRegistry } from '../types'
|
|
12
|
+
|
|
13
|
+
export const headerUniversalRegistry: ViewRegistry = {
|
|
14
|
+
HeaderUniversal: ({ props }) => {
|
|
15
|
+
const router = useRouter()
|
|
16
|
+
const parsed = universalHeaderPropsSchema.parse(props)
|
|
17
|
+
return (
|
|
18
|
+
<HeaderUniversal
|
|
19
|
+
config={parsed.config}
|
|
20
|
+
context={parsed.context}
|
|
21
|
+
labels={parsed.labels}
|
|
22
|
+
breakpoint={parsed.breakpoint}
|
|
23
|
+
className={parsed.className}
|
|
24
|
+
onAction={(action) => {
|
|
25
|
+
if (action.name === 'navigate') {
|
|
26
|
+
const href = action.payload?.href
|
|
27
|
+
if (typeof href === 'string' && href.startsWith('/')) router.push(href)
|
|
28
|
+
}
|
|
29
|
+
}}
|
|
30
|
+
/>
|
|
31
|
+
)
|
|
32
|
+
},
|
|
33
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// Optional section fragment: header-universal (mirrors recipes/sections.json)
|
|
2
|
+
// Server-side part: element type + zod catalog entry. The component mappings
|
|
3
|
+
// live in header-universal.client.tsx ('use client') and are composed via composeSections.
|
|
4
|
+
|
|
5
|
+
import { universalHeaderPropsSchema } from './schema.header-universal'
|
|
6
|
+
|
|
7
|
+
export const headerUniversalSection = {
|
|
8
|
+
elementType: 'HeaderUniversal',
|
|
9
|
+
catalog: {
|
|
10
|
+
HeaderUniversal: {
|
|
11
|
+
props: universalHeaderPropsSchema,
|
|
12
|
+
description: 'HeaderUniversal presentation section (delivery header-universal).',
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
registryModule: './header-universal.client',
|
|
16
|
+
}
|
|
@@ -9,13 +9,14 @@ import type { ViewCatalogEntry } from '../types'
|
|
|
9
9
|
import { checkoutCommerceV1Section } from './checkout-commerce-v1'
|
|
10
10
|
import { ctaSection } from './cta'
|
|
11
11
|
import { faqSection } from './faq'
|
|
12
|
+
import { headerUniversalSection } from './header-universal'
|
|
12
13
|
import { marketplaceProductCardSection } from './marketplace-product-card'
|
|
13
14
|
import { megaMenuUniversalSection } from './mega-menu-universal'
|
|
14
15
|
import { productsSection } from './products'
|
|
15
16
|
import { universalBannerSection } from './universal-banner'
|
|
16
17
|
import { universalMainMenuSection } from './universal-main-menu'
|
|
17
18
|
|
|
18
|
-
export const sectionModules = [checkoutCommerceV1Section, faqSection, ctaSection, marketplaceProductCardSection, megaMenuUniversalSection, productsSection, universalBannerSection, universalMainMenuSection] as const
|
|
19
|
+
export const sectionModules = [checkoutCommerceV1Section, faqSection, headerUniversalSection, ctaSection, marketplaceProductCardSection, megaMenuUniversalSection, productsSection, universalBannerSection, universalMainMenuSection] as const
|
|
19
20
|
|
|
20
21
|
export const sectionCatalog: Record<string, ViewCatalogEntry> = Object.assign(
|
|
21
22
|
{},
|
|
@@ -0,0 +1,360 @@
|
|
|
1
|
+
// Optional section fragment: header-universal (mirrors recipes/sections.json) — shared contract.
|
|
2
|
+
// Zod mirror of the HeaderUniversal block contract (delivery header-universal),
|
|
3
|
+
// shared by the server catalog (header-universal.tsx) and the client registry
|
|
4
|
+
// (header-universal.client.tsx). The React-only callback (`onAction`) is
|
|
5
|
+
// intentionally excluded; the runtime commerce data (`context.cart`,
|
|
6
|
+
// `context.account`, …) is carried through `context` exactly as the host feeds
|
|
7
|
+
// it, so the section serializes the same shape the block renders.
|
|
8
|
+
|
|
9
|
+
import { z } from 'zod'
|
|
10
|
+
import { universalMainMenuDataSchema } from './schema.universal-main-menu'
|
|
11
|
+
|
|
12
|
+
const surfaceToken = z.enum(['transparent', 'background', 'card', 'muted', 'primary', 'accent'])
|
|
13
|
+
const accentToken = z.enum(['none', 'primary', 'accent', 'success'])
|
|
14
|
+
const densityToken = z.enum(['compact', 'comfortable'])
|
|
15
|
+
const radiusToken = z.enum(['none', 'sm', 'md', 'lg', 'xl'])
|
|
16
|
+
const spaceToken = z.enum(['none', 'xs', 'sm', 'md', 'lg', 'xl'])
|
|
17
|
+
const heightToken = z.enum(['xs', 'sm', 'md', 'lg', 'xl'])
|
|
18
|
+
const borderToken = z.enum(['none', 'bottom', 'top', 'all'])
|
|
19
|
+
const shadowToken = z.enum(['none', 'sm', 'md'])
|
|
20
|
+
const positionToken = z.enum(['static', 'sticky', 'fixed'])
|
|
21
|
+
const breakpointToken = z.enum(['base', 'md', '2xl'])
|
|
22
|
+
const zoneName = z.enum(['start', 'center', 'end'])
|
|
23
|
+
const presetId = z.enum(['commerce', 'minimal', 'marketplace', 'b2b', 'checkout', 'landing'])
|
|
24
|
+
const contextKind = z.enum(['guest', 'authenticated', 'b2b', 'checkout', 'landing'])
|
|
25
|
+
const pageKind = z.enum(['home', 'category', 'product', 'checkout', 'account', 'landing'])
|
|
26
|
+
|
|
27
|
+
const moduleType = z.enum([
|
|
28
|
+
'logo',
|
|
29
|
+
'navigation',
|
|
30
|
+
'search',
|
|
31
|
+
'cart',
|
|
32
|
+
'account',
|
|
33
|
+
'wishlist',
|
|
34
|
+
'region',
|
|
35
|
+
'language',
|
|
36
|
+
'location',
|
|
37
|
+
'organization',
|
|
38
|
+
'announcement',
|
|
39
|
+
'promotion-progress',
|
|
40
|
+
'support',
|
|
41
|
+
'notifications',
|
|
42
|
+
'spacer',
|
|
43
|
+
'divider',
|
|
44
|
+
'text-label',
|
|
45
|
+
'custom-link',
|
|
46
|
+
'custom-button',
|
|
47
|
+
'icon-action',
|
|
48
|
+
'main-menu',
|
|
49
|
+
])
|
|
50
|
+
|
|
51
|
+
const capabilityId = z.enum([
|
|
52
|
+
'catalog',
|
|
53
|
+
'catalog-search',
|
|
54
|
+
'checkout',
|
|
55
|
+
'customer-account',
|
|
56
|
+
'saved-items',
|
|
57
|
+
'reviews',
|
|
58
|
+
'recommendations',
|
|
59
|
+
'newsletter',
|
|
60
|
+
'b2b',
|
|
61
|
+
'notifications',
|
|
62
|
+
'promotions',
|
|
63
|
+
'locations',
|
|
64
|
+
])
|
|
65
|
+
|
|
66
|
+
const headerActionName = z.enum([
|
|
67
|
+
'navigate',
|
|
68
|
+
'openCart',
|
|
69
|
+
'closeCart',
|
|
70
|
+
'goToCart',
|
|
71
|
+
'goToCheckout',
|
|
72
|
+
'openSearch',
|
|
73
|
+
'closeSearch',
|
|
74
|
+
'openAccount',
|
|
75
|
+
'closeAccount',
|
|
76
|
+
'openNotifications',
|
|
77
|
+
'login',
|
|
78
|
+
'register',
|
|
79
|
+
'logout',
|
|
80
|
+
'selectRegion',
|
|
81
|
+
'selectLanguage',
|
|
82
|
+
'selectLocation',
|
|
83
|
+
'selectOrganization',
|
|
84
|
+
'openComponent',
|
|
85
|
+
'closeComponent',
|
|
86
|
+
'changeCartQuantity',
|
|
87
|
+
'removeCartLine',
|
|
88
|
+
'selectNotification',
|
|
89
|
+
'dismissAnnouncement',
|
|
90
|
+
])
|
|
91
|
+
|
|
92
|
+
const modulePropsSchema = z.record(z.union([z.string(), z.number(), z.boolean()]))
|
|
93
|
+
|
|
94
|
+
const themeSchema = z.object({
|
|
95
|
+
surface: surfaceToken,
|
|
96
|
+
accent: accentToken,
|
|
97
|
+
density: densityToken,
|
|
98
|
+
radius: radiusToken,
|
|
99
|
+
})
|
|
100
|
+
|
|
101
|
+
const behaviorSchema = z.object({
|
|
102
|
+
position: positionToken,
|
|
103
|
+
transparent: z.boolean(),
|
|
104
|
+
overHero: z.boolean(),
|
|
105
|
+
scrolledSurface: z.boolean(),
|
|
106
|
+
compactOnScroll: z.boolean(),
|
|
107
|
+
hideOnScrollDown: z.boolean(),
|
|
108
|
+
showOnScrollUp: z.boolean(),
|
|
109
|
+
threshold: z.number(),
|
|
110
|
+
zIndex: z.number(),
|
|
111
|
+
reducedMotion: z.boolean(),
|
|
112
|
+
})
|
|
113
|
+
|
|
114
|
+
const rowStyleSchema = z.object({
|
|
115
|
+
minHeight: heightToken,
|
|
116
|
+
maxHeight: z.union([heightToken, z.literal('none')]),
|
|
117
|
+
paddingX: spaceToken,
|
|
118
|
+
paddingY: spaceToken,
|
|
119
|
+
gap: spaceToken,
|
|
120
|
+
align: z.enum(['start', 'center', 'end']),
|
|
121
|
+
justify: z.enum(['start', 'center', 'between', 'end']),
|
|
122
|
+
maxWidth: z.enum(['full', 'sm', 'md', 'lg', 'xl']),
|
|
123
|
+
surface: surfaceToken,
|
|
124
|
+
border: borderToken,
|
|
125
|
+
shadow: shadowToken,
|
|
126
|
+
separator: z.boolean(),
|
|
127
|
+
})
|
|
128
|
+
|
|
129
|
+
const headerActionSchema = z.object({
|
|
130
|
+
name: headerActionName,
|
|
131
|
+
payload: modulePropsSchema.optional(),
|
|
132
|
+
})
|
|
133
|
+
|
|
134
|
+
const moduleSchema = z.object({
|
|
135
|
+
id: z.string(),
|
|
136
|
+
type: moduleType,
|
|
137
|
+
enabled: z.boolean(),
|
|
138
|
+
requires: capabilityId.optional(),
|
|
139
|
+
props: modulePropsSchema,
|
|
140
|
+
style: z
|
|
141
|
+
.object({
|
|
142
|
+
surface: surfaceToken.optional(),
|
|
143
|
+
size: z.enum(['sm', 'md', 'lg']).optional(),
|
|
144
|
+
emphasis: z.enum(['none', 'accent']).optional(),
|
|
145
|
+
})
|
|
146
|
+
.optional(),
|
|
147
|
+
visibility: z
|
|
148
|
+
.object({
|
|
149
|
+
breakpoints: z.array(breakpointToken).optional(),
|
|
150
|
+
contexts: z.array(contextKind).optional(),
|
|
151
|
+
})
|
|
152
|
+
.optional(),
|
|
153
|
+
responsive: z
|
|
154
|
+
.record(
|
|
155
|
+
breakpointToken,
|
|
156
|
+
z.object({
|
|
157
|
+
row: z.string().optional(),
|
|
158
|
+
zone: zoneName.optional(),
|
|
159
|
+
order: z.number().optional(),
|
|
160
|
+
hidden: z.boolean().optional(),
|
|
161
|
+
props: modulePropsSchema.optional(),
|
|
162
|
+
}),
|
|
163
|
+
)
|
|
164
|
+
.optional(),
|
|
165
|
+
bindings: z.record(z.string(), z.string()).optional(),
|
|
166
|
+
actions: z.record(z.string(), headerActionSchema).optional(),
|
|
167
|
+
})
|
|
168
|
+
|
|
169
|
+
const rowSchema = rowStyleSchema.extend({
|
|
170
|
+
id: z.string(),
|
|
171
|
+
enabled: z.boolean(),
|
|
172
|
+
zones: z.record(zoneName, z.array(z.string())),
|
|
173
|
+
responsive: z
|
|
174
|
+
.record(
|
|
175
|
+
breakpointToken,
|
|
176
|
+
rowStyleSchema
|
|
177
|
+
.partial()
|
|
178
|
+
.extend({
|
|
179
|
+
zones: z.record(zoneName, z.array(z.string()).optional()).optional(),
|
|
180
|
+
hidden: z.boolean().optional(),
|
|
181
|
+
}),
|
|
182
|
+
)
|
|
183
|
+
.optional(),
|
|
184
|
+
})
|
|
185
|
+
|
|
186
|
+
const visibilityRuleSchema = z.object({
|
|
187
|
+
id: z.string(),
|
|
188
|
+
target: z.object({
|
|
189
|
+
rows: z.array(z.string()).optional(),
|
|
190
|
+
modules: z.array(z.string()).optional(),
|
|
191
|
+
}),
|
|
192
|
+
when: z.object({
|
|
193
|
+
capability: capabilityId.optional(),
|
|
194
|
+
context: contextKind.optional(),
|
|
195
|
+
page: pageKind.optional(),
|
|
196
|
+
from: z.string().optional(),
|
|
197
|
+
to: z.string().optional(),
|
|
198
|
+
}),
|
|
199
|
+
mode: z.literal('hide'),
|
|
200
|
+
})
|
|
201
|
+
|
|
202
|
+
export const headerConfigSchema = z.object({
|
|
203
|
+
schemaVersion: z.number(),
|
|
204
|
+
id: z.string(),
|
|
205
|
+
name: z.string(),
|
|
206
|
+
preset: presetId,
|
|
207
|
+
theme: themeSchema,
|
|
208
|
+
behavior: behaviorSchema,
|
|
209
|
+
layout: z.array(rowSchema),
|
|
210
|
+
modules: z.array(moduleSchema),
|
|
211
|
+
capabilities: z.record(capabilityId, z.boolean().optional()),
|
|
212
|
+
visibilityRules: z.array(visibilityRuleSchema),
|
|
213
|
+
fallbacks: z.object({
|
|
214
|
+
missingCapability: z.enum(['hide', 'placeholder']),
|
|
215
|
+
missingImage: z.enum(['fallback', 'label']),
|
|
216
|
+
missingAction: z.enum(['disable', 'hide']),
|
|
217
|
+
}),
|
|
218
|
+
analytics: z.object({ events: z.array(z.string()) }).optional(),
|
|
219
|
+
})
|
|
220
|
+
|
|
221
|
+
const moneySchema = z.object({ amount: z.string(), currencyCode: z.string() })
|
|
222
|
+
|
|
223
|
+
const brandSchema = z.object({
|
|
224
|
+
name: z.string(),
|
|
225
|
+
href: z.string(),
|
|
226
|
+
logo: z.string().optional(),
|
|
227
|
+
logoLight: z.string().optional(),
|
|
228
|
+
logoDark: z.string().optional(),
|
|
229
|
+
accent: z.string().optional(),
|
|
230
|
+
})
|
|
231
|
+
|
|
232
|
+
const cartStateKind = z.enum(['ready', 'empty', 'loading', 'error'])
|
|
233
|
+
const accountStateKind = z.enum(['guest', 'authenticated', 'loading', 'expired', 'error'])
|
|
234
|
+
|
|
235
|
+
const cartLineSchema = z.object({
|
|
236
|
+
id: z.string(),
|
|
237
|
+
name: z.string(),
|
|
238
|
+
price: z.number(),
|
|
239
|
+
quantity: z.number(),
|
|
240
|
+
variant: z.string().optional(),
|
|
241
|
+
image: z.string().optional(),
|
|
242
|
+
unitPrice: moneySchema.optional(),
|
|
243
|
+
lineTotal: moneySchema.optional(),
|
|
244
|
+
})
|
|
245
|
+
|
|
246
|
+
const headerCartSchema = z.object({
|
|
247
|
+
state: cartStateKind,
|
|
248
|
+
lines: z.array(cartLineSchema),
|
|
249
|
+
totals: z
|
|
250
|
+
.object({
|
|
251
|
+
subtotal: moneySchema,
|
|
252
|
+
total: moneySchema,
|
|
253
|
+
discount: moneySchema.optional(),
|
|
254
|
+
tax: moneySchema.optional(),
|
|
255
|
+
shipping: moneySchema.optional(),
|
|
256
|
+
})
|
|
257
|
+
.optional(),
|
|
258
|
+
quantity: z.number(),
|
|
259
|
+
lineCount: z.number(),
|
|
260
|
+
currency: z.string(),
|
|
261
|
+
shippingGroups: z.number(),
|
|
262
|
+
shippingNote: z.string().optional(),
|
|
263
|
+
subtotalUnavailableLabel: z.string(),
|
|
264
|
+
promotions: z.array(z.string()),
|
|
265
|
+
error: z.string().optional(),
|
|
266
|
+
})
|
|
267
|
+
|
|
268
|
+
const accountUserSchema = z.object({
|
|
269
|
+
email: z.string(),
|
|
270
|
+
name: z.string(),
|
|
271
|
+
initials: z.string(),
|
|
272
|
+
avatar: z.string().optional(),
|
|
273
|
+
})
|
|
274
|
+
|
|
275
|
+
const accountMenuItemSchema = z.object({
|
|
276
|
+
label: z.string(),
|
|
277
|
+
href: z.string(),
|
|
278
|
+
icon: z.enum(['orders', 'wishlist', 'addresses', 'settings']).optional(),
|
|
279
|
+
description: z.string().optional(),
|
|
280
|
+
})
|
|
281
|
+
|
|
282
|
+
const headerAccountSchema = z.object({
|
|
283
|
+
state: accountStateKind,
|
|
284
|
+
user: accountUserSchema.optional(),
|
|
285
|
+
menu: z.array(accountMenuItemSchema),
|
|
286
|
+
error: z.string().optional(),
|
|
287
|
+
})
|
|
288
|
+
|
|
289
|
+
const headerContextSchema = z.object({
|
|
290
|
+
brand: brandSchema,
|
|
291
|
+
menu: universalMainMenuDataSchema.optional(),
|
|
292
|
+
cart: headerCartSchema,
|
|
293
|
+
account: headerAccountSchema,
|
|
294
|
+
wishlist: z.object({ count: z.number(), lists: z.number() }),
|
|
295
|
+
regions: z.object({
|
|
296
|
+
activeId: z.string(),
|
|
297
|
+
options: z.array(z.object({ id: z.string(), label: z.string(), currencyCode: z.string() })),
|
|
298
|
+
}),
|
|
299
|
+
languages: z.object({
|
|
300
|
+
activeCode: z.string(),
|
|
301
|
+
options: z.array(z.object({ code: z.string(), label: z.string() })),
|
|
302
|
+
}),
|
|
303
|
+
locations: z.object({
|
|
304
|
+
activeId: z.string().optional(),
|
|
305
|
+
enabled: z.boolean(),
|
|
306
|
+
options: z.array(z.object({ id: z.string(), label: z.string(), detail: z.string().optional() })),
|
|
307
|
+
}),
|
|
308
|
+
organization: z
|
|
309
|
+
.object({
|
|
310
|
+
activeId: z.string(),
|
|
311
|
+
options: z.array(
|
|
312
|
+
z.object({
|
|
313
|
+
id: z.string(),
|
|
314
|
+
name: z.string(),
|
|
315
|
+
role: z.string(),
|
|
316
|
+
permissions: z.array(z.string()),
|
|
317
|
+
}),
|
|
318
|
+
),
|
|
319
|
+
})
|
|
320
|
+
.optional(),
|
|
321
|
+
announcements: z.array(
|
|
322
|
+
z.object({
|
|
323
|
+
id: z.string(),
|
|
324
|
+
message: z.string(),
|
|
325
|
+
href: z.string().optional(),
|
|
326
|
+
linkLabel: z.string().optional(),
|
|
327
|
+
tone: z.enum(['info', 'accent', 'muted']),
|
|
328
|
+
from: z.string().optional(),
|
|
329
|
+
to: z.string().optional(),
|
|
330
|
+
dismissible: z.boolean(),
|
|
331
|
+
}),
|
|
332
|
+
),
|
|
333
|
+
promotion: z
|
|
334
|
+
.object({
|
|
335
|
+
state: z.enum(['not-eligible', 'in-progress', 'complete']),
|
|
336
|
+
threshold: z.string().optional(),
|
|
337
|
+
current: z.string().optional(),
|
|
338
|
+
remaining: z.string().optional(),
|
|
339
|
+
message: z.string().optional(),
|
|
340
|
+
})
|
|
341
|
+
.optional(),
|
|
342
|
+
notifications: z.object({
|
|
343
|
+
available: z.boolean(),
|
|
344
|
+
unread: z.number(),
|
|
345
|
+
items: z.array(z.object({ id: z.string(), title: z.string(), href: z.string(), read: z.boolean() })),
|
|
346
|
+
}),
|
|
347
|
+
openComponents: z.array(z.string()),
|
|
348
|
+
now: z.string(),
|
|
349
|
+
capabilities: z.record(capabilityId, z.boolean().optional()),
|
|
350
|
+
context: contextKind,
|
|
351
|
+
page: pageKind,
|
|
352
|
+
})
|
|
353
|
+
|
|
354
|
+
export const universalHeaderPropsSchema = z.object({
|
|
355
|
+
config: headerConfigSchema,
|
|
356
|
+
context: headerContextSchema,
|
|
357
|
+
labels: z.record(z.string(), z.record(z.string(), z.string())).optional(),
|
|
358
|
+
breakpoint: breakpointToken.optional(),
|
|
359
|
+
className: z.string().optional(),
|
|
360
|
+
})
|