@thorprovider/storefront 0.15.3 → 0.15.4

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.
@@ -72,6 +72,10 @@ export default async function Page({
72
72
  const initialState = {
73
73
  ...(data.initialState ?? {}),
74
74
  navCategories,
75
+ // The universal header binds its menu to `/headerMenu`; seeding it here is
76
+ // what makes the navigation render at all. Without it the header falls back
77
+ // to no menu and the trigger never appears.
78
+ headerMenu,
75
79
  // The shopper locale is resolved server-side (env-backed) and seeded for
76
80
  // every route so the client registries build the same money formatter the
77
81
  // shell's `<html lang>` uses. `getStoreLocale` never throws, so a
@@ -26,6 +26,7 @@ import type {
26
26
  HeaderModule,
27
27
  } from '@thorprovider/blocks/blocks/designs/header-universal/contracts'
28
28
  import type { UniversalMainMenuData, UniversalMainMenuItem } from '@thorprovider/blocks'
29
+ import type { AccountMenuItem } from '@thorprovider/blocks'
29
30
  import type { ProductCategory } from '@thorprovider/types'
30
31
 
31
32
  /**
@@ -56,26 +57,44 @@ export function createStorefrontHeaderConfig(): HeaderConfig {
56
57
  enabled: true,
57
58
  requires: 'saved-items',
58
59
  props: { showCount: true },
59
- // The starter has no dedicated wishlist route; the icon navigates to the
60
- // account surface where saved items live.
61
- actions: { click: { name: 'navigate', payload: { href: '/account' } } },
60
+ // The starter has no wishlist surface and no wishlist route, so the module
61
+ // declares NO click action: the block renders the heart visible but
62
+ // disabled (`moduleClickAction` has no fallback). Pointing it at `/account`
63
+ // sent guests to a login and signed-in shoppers to their account panel,
64
+ // which is not what a wishlist affordance means. Once a real saved-items
65
+ // surface exists, give this module an action again.
62
66
  }
63
- const modules = [
67
+ const modules: HeaderModule[] = [
64
68
  ...base.modules
65
69
  .filter((module) => kept.has(module.id))
66
- .map((module) => {
70
+ .map((module): HeaderModule => {
71
+ if (module.id === 'search') {
72
+ // The demo search is always a bar (never the icon fallback): the block
73
+ // measures its container client-side, so the server render would
74
+ // otherwise fall back to the base-breakpoint icon and the search field
75
+ // copy would never appear in the SSR HTML. Its click opens the host's
76
+ // global search surface (`universal-search`).
77
+ return { ...module, responsive: undefined }
78
+ }
79
+ if (module.id === 'account') {
80
+ // The account access opens the host's account lateral instead of
81
+ // jumping straight to the account page: the surface carries the
82
+ // session state (guest sign-in vs. signed-in identity + sign out).
83
+ return {
84
+ ...module,
85
+ actions: { click: { name: 'openComponent', payload: { target: 'universal-account' } } },
86
+ }
87
+ }
67
88
  if (module.id === 'cart') {
89
+ // The cart access opens the shared live cart lateral instead of
90
+ // navigating: the sheet reads the same authoritative cart the badge
91
+ // does, so the shopper reviews and mutates lines in place.
68
92
  return {
69
93
  ...module,
70
94
  actions: { ...module.actions, click: { name: 'openCart' } },
71
95
  }
72
96
  }
73
- if (module.id !== 'search') return module
74
- // The demo search is always a bar (never the icon fallback): the block
75
- // measures its container client-side, so the server render would
76
- // otherwise fall back to the base-breakpoint icon and the search field
77
- // copy would never appear in the SSR HTML.
78
- return { ...module, responsive: undefined }
97
+ return module
79
98
  }),
80
99
  wishlistModule,
81
100
  ]
@@ -132,6 +151,39 @@ export const storefrontHeaderLabels: Record<string, Record<string, string>> = {
132
151
  announcement: { link: 'Ver más' },
133
152
  }
134
153
 
154
+ /** Account destinations offered by the header's account lateral. The scaffold
155
+ * serves one account page; every destination lives there. */
156
+ export const storefrontAccountMenuItems: AccountMenuItem[] = [
157
+ {
158
+ label: 'Mi cuenta',
159
+ href: '/account',
160
+ icon: 'settings',
161
+ description: 'Perfil, pedidos y direcciones',
162
+ },
163
+ ]
164
+
165
+ /** Copy for the shared cart lateral that the navbar label set does not carry. */
166
+ export const storefrontCartDrawerLabels = {
167
+ retryLabel: 'Reintentar',
168
+ }
169
+
170
+ /** Copy for the account lateral opened by the header's account module. */
171
+ export const storefrontAccountDrawerLabels = {
172
+ title: 'Tu cuenta',
173
+ closeLabel: 'Cerrar cuenta',
174
+ guestDescription: 'Inicia sesión para ver tus pedidos, direcciones y datos personales.',
175
+ signInLabel: 'Iniciar sesión',
176
+ signOutLabel: 'Cerrar sesión',
177
+ }
178
+
179
+ /** Copy for the global search dialog opened by the header's search module. */
180
+ export const storefrontSearchDialogLabels = {
181
+ title: 'Buscar en la tienda',
182
+ label: 'Buscar productos, marcas o SKU',
183
+ submitLabel: 'Buscar',
184
+ description: 'Escribe un producto, marca o SKU y pulsa Enter.',
185
+ }
186
+
135
187
  /** The live-catalog menu labels: the trigger is `Menú`, the rest are required. */
136
188
  const HEADER_MENU_LABELS: UniversalMainMenuData['labels'] = {
137
189
  menuTrigger: 'Menú',
@@ -316,34 +368,51 @@ export function buildDemoHeaderMenu(): UniversalMainMenuData {
316
368
  }
317
369
  }
318
370
 
371
+ /** Real chrome data the host reads from its store; absent fields stay neutral. */
372
+ export interface HeaderRuntimeSeed {
373
+ cart?: {
374
+ quantity: number
375
+ lineCount: number
376
+ currency?: string
377
+ error?: string
378
+ }
379
+ account?: HeaderContext['account']
380
+ wishlistCount?: number
381
+ }
382
+
319
383
  /**
320
- * Runtime context the shell feeds the header. The cart quantity comes from the
321
- * live storefront state; announcement and wishlist remain clearly-labelled
322
- * demonstration content. Region/language stay empty (their modules are removed
323
- * from the config, so nothing reads them). The live catalog/menu seam is the
324
- * `menu` argument (built from the real taxonomy or the demo taxonomy above).
384
+ * The runtime context the shell feeds the header. The host passes what it
385
+ * actually knows (the live cart badge, the resolved session); anything it does
386
+ * not supply stays neutral rather than inventing a demo count. Region/language
387
+ * stay empty (their modules are removed from the config). The live catalog/menu
388
+ * seam is the `menu` argument (built by the host from the real taxonomy or the
389
+ * demo taxonomy above).
325
390
  */
326
391
  export function buildHeaderContext(
327
392
  siteName: string,
328
393
  menu?: UniversalMainMenuData,
329
394
  accent?: string,
330
- cartQuantity = 0,
395
+ runtime?: HeaderRuntimeSeed,
331
396
  ): HeaderContext {
397
+ const cart = runtime?.cart
332
398
  return {
333
399
  brand: { name: siteName, href: '/', ...(accent ? { accent } : {}) },
334
400
  menu,
335
401
  cart: {
336
402
  state: 'ready',
403
+ // No line snapshots are fabricated: the header badge reads the counts the
404
+ // host supplies from the authoritative cart.
337
405
  lines: [],
338
- quantity: cartQuantity,
339
- lineCount: 0,
340
- currency: 'EUR',
406
+ quantity: cart?.quantity ?? 0,
407
+ lineCount: cart?.lineCount ?? 0,
408
+ currency: cart?.currency ?? 'EUR',
341
409
  shippingGroups: 0,
342
410
  subtotalUnavailableLabel: 'Envío calculado al finalizar la compra',
343
411
  promotions: [],
412
+ ...(cart?.error ? { error: cart.error } : {}),
344
413
  },
345
- account: { state: 'guest', menu: [] },
346
- wishlist: { count: 4, lists: 1 },
414
+ account: runtime?.account ?? { state: 'guest', menu: [] },
415
+ wishlist: { count: runtime?.wishlistCount ?? 0, lists: runtime?.wishlistCount ? 1 : 0 },
347
416
  regions: { activeId: '', options: [] },
348
417
  languages: { activeCode: '', options: [] },
349
418
  locations: { enabled: false, options: [] },
@@ -15,12 +15,11 @@ import { usePathname } from 'next/navigation'
15
15
  import { BackToTop as BackToTopBlock } from '@thorprovider/blocks/blocks/e-commerce/navigation/back-to-top'
16
16
  import { MobileBottomNav as MobileBottomNavBlock } from '@thorprovider/blocks/blocks/e-commerce/navigation/mobile-bottom-nav'
17
17
  import { SkipToContent as SkipToContentBlock } from '@thorprovider/blocks/blocks/e-commerce/navigation/skip-to-content'
18
- import { StorefrontNavbarCartSheet } from '@thorprovider/blocks/blocks/e-commerce/navigation/storefront-navbar-cart-sheet'
19
18
  import Banner1 from '@thorprovider/blocks/blocks/marketing/banners/banner-1'
20
- import { HeaderUniversal, Navbar, StorefrontNavbar, UniversalFooter } from '@thorprovider/blocks'
19
+ import { HeaderUniversal, Navbar, StorefrontAccountDrawer, StorefrontCartDrawer, StorefrontNavbar, StorefrontSearchDialog, UniversalFooter } from '@thorprovider/blocks'
21
20
  import { ProductGrid as ProductGridBlock } from '@thorprovider/blocks/blocks/e-commerce/product-list/product-grid'
22
- import { Sheet, SheetContent, SheetHeader, SheetTitle } from '@thorprovider/blocks/ui/sheet'
23
21
  import type { BackToTopProps } from '@thorprovider/blocks/blocks/e-commerce/navigation/back-to-top'
22
+ import type { CartSheetState } from '@thorprovider/blocks/blocks/e-commerce/navigation/storefront-navbar-cart-sheet'
24
23
  import type { MobileBottomNavProps } from '@thorprovider/blocks/blocks/e-commerce/navigation/mobile-bottom-nav'
25
24
  import type { SkipToContentProps } from '@thorprovider/blocks/blocks/e-commerce/navigation/skip-to-content'
26
25
  import { isAvailableMoney } from '@thorprovider/blocks/contracts'
@@ -32,7 +31,7 @@ import { useStorefrontHandlers } from './handlers'
32
31
  import { cartViewAvailable, checkoutAvailable, mountedFeatureNames } from './composition'
33
32
  import { accountStoreUser } from './account-user.core'
34
33
  import { toUniversalFooterProps } from './footer-content'
35
- import { buildHeaderContext, createStorefrontHeaderConfig, storefrontHeaderLabels } from './header-universal'
34
+ import { buildHeaderContext, createStorefrontHeaderConfig, storefrontAccountDrawerLabels, storefrontAccountMenuItems, storefrontCartDrawerLabels, storefrontHeaderLabels, storefrontSearchDialogLabels } from './header-universal'
36
35
  import { navbarLabels } from './shell/content'
37
36
  import type { AccountIdentity, AccountResolution } from './account-session.core'
38
37
  import {
@@ -72,11 +71,36 @@ function toNavCartItems(cart: CartLineState[]): NavCartItem[] {
72
71
  }))
73
72
  }
74
73
 
75
- function StorefrontCartSheet({ emit }: { emit: (event: string) => void }) {
74
+ // Chrome copy for the shared cart lateral. The block keeps English defaults for
75
+ // consumers that supply nothing; the generated store speaks Spanish from the
76
+ // user-owned shell content.
77
+ const cartSheetLabels = {
78
+ decreaseLabel: navbarLabels.decreaseQuantity,
79
+ increaseLabel: navbarLabels.increaseQuantity,
80
+ removeLabel: navbarLabels.remove,
81
+ removeItemLabel: navbarLabels.removeItem,
82
+ emptyTitleLabel: navbarLabels.emptyTitle,
83
+ emptyDescriptionLabel: navbarLabels.emptyDescription,
84
+ continueShoppingLabel: navbarLabels.continueShopping,
85
+ subtotalLabel: navbarLabels.subtotal,
86
+ shippingTaxesLabel: navbarLabels.shippingTaxes,
87
+ checkoutLabel: navbarLabels.checkout,
88
+ viewCartLabel: navbarLabels.viewCart,
89
+ }
90
+
91
+ /**
92
+ * The one cart wiring every shell chrome surface shares: the legacy
93
+ * `StorefrontNavbar` and the universal header render the same authoritative cart
94
+ * and open it through the same shared `cartOpen` state, so a successful add
95
+ * opens whichever surface the shell mounts. Checkout stays offered only when the
96
+ * required backend amounts are present and valid (AC-CART-4.4 / UC-CART-7).
97
+ */
98
+ function useShellCart(emit: (event: string) => void) {
76
99
  const { state, set } = useStateStore()
77
100
  const cart = (state.cart ?? []) as CartLineState[]
78
101
  const totals = state.cartTotals as CartTotalsState | null
79
- const cartQuantity = cart.reduce((quantity, line) => quantity + line.quantity, 0)
102
+ // One money formatter for the whole shell, built from the shopper locale the
103
+ // catch-all host seeded (the same locale as `<html lang>`).
80
104
  const storeLocale =
81
105
  typeof state.storeLocale === 'string' && state.storeLocale.trim() !== ''
82
106
  ? state.storeLocale
@@ -85,66 +109,38 @@ function StorefrontCartSheet({ emit }: { emit: (event: string) => void }) {
85
109
  const cartError = typeof state.cartError === 'string' ? state.cartError : undefined
86
110
  const readError = typeof state.cartReadError === 'string' ? state.cartReadError : undefined
87
111
  const errorLabel = cartError ?? readError
88
- const cartState = state.cartPending ? 'pending' : errorLabel ? 'error' : 'idle'
112
+ const cartState: CartSheetState = state.cartPending ? 'pending' : errorLabel ? 'error' : 'idle'
89
113
  const amountsValid =
90
114
  cart.every((line) => isAvailableMoney(line.lineTotal)) &&
91
115
  totals !== null &&
92
116
  isAvailableMoney(totals.subtotal) &&
93
117
  isAvailableMoney(totals.total)
94
-
95
- return (
96
- <Sheet
97
- open={state.cartOpen === true}
98
- onOpenChange={(open) => set('/cartOpen', open)}
99
- >
100
- <SheetContent
101
- side='right'
102
- className='flex w-full max-w-sm flex-col gap-0 p-0'
103
- closeLabel={navbarLabels.cartClose}
104
- >
105
- <SheetHeader className='border-border border-b'>
106
- <SheetTitle className='text-left text-base'>
107
- {cartQuantity > 0
108
- ? `${navbarLabels.cartTitle} (${cartQuantity})`
109
- : navbarLabels.cartTitle}
110
- </SheetTitle>
111
- </SheetHeader>
112
- <StorefrontNavbarCartSheet
113
- items={toNavCartItems(cart)}
114
- onQtyChange={(id, delta) => {
115
- set('/qtyDelta', { id, delta })
116
- emit('applyQuantityDelta')
117
- }}
118
- onRemove={(id) => {
119
- set('/lastRemoved', id)
120
- emit('removeFromCart')
121
- }}
122
- subtotal={totals?.subtotal}
123
- formatMoney={formatMoney}
124
- onCheckout={() => emit('goToCheckout')}
125
- onViewCart={() => emit('goToCart')}
126
- canonical
127
- state={cartState}
128
- errorLabel={errorLabel}
129
- onRetry={() => emit('refreshCart')}
130
- checkoutUnavailable={!checkoutAvailable}
131
- checkoutDisabled={cartState !== 'idle' || cart.length === 0 || !amountsValid}
132
- viewCartUnavailable={!cartViewAvailable}
133
- decreaseLabel={navbarLabels.decreaseQuantity}
134
- increaseLabel={navbarLabels.increaseQuantity}
135
- removeLabel={navbarLabels.remove}
136
- removeItemLabel={navbarLabels.removeItem}
137
- emptyTitleLabel={navbarLabels.emptyTitle}
138
- emptyDescriptionLabel={navbarLabels.emptyDescription}
139
- continueShoppingLabel={navbarLabels.continueShopping}
140
- subtotalLabel={navbarLabels.subtotal}
141
- shippingTaxesLabel={navbarLabels.shippingTaxes}
142
- checkoutLabel={navbarLabels.checkout}
143
- viewCartLabel={navbarLabels.viewCart}
144
- />
145
- </SheetContent>
146
- </Sheet>
147
- )
118
+ return {
119
+ items: toNavCartItems(cart),
120
+ subtotal: totals?.subtotal,
121
+ formatMoney,
122
+ errorLabel,
123
+ cartState,
124
+ quantity: cart.reduce((total, line) => total + line.quantity, 0),
125
+ lineCount: cart.length,
126
+ currency: totals?.subtotal?.currencyCode ?? 'EUR',
127
+ open: state.cartOpen === true,
128
+ setOpen: (open: boolean) => set('/cartOpen', open),
129
+ checkoutUnavailable: !checkoutAvailable,
130
+ checkoutDisabled: cartState !== 'idle' || cart.length === 0 || !amountsValid,
131
+ viewCartUnavailable: !cartViewAvailable,
132
+ onViewCart: () => emit('goToCart'),
133
+ onCheckout: () => emit('goToCheckout'),
134
+ onRetry: () => emit('refreshCart'),
135
+ onQtyChange: (id: string, delta: number) => {
136
+ set('/qtyDelta', { id, delta })
137
+ emit('applyQuantityDelta')
138
+ },
139
+ onRemove: (id: string) => {
140
+ set('/lastRemoved', id)
141
+ emit('removeFromCart')
142
+ },
143
+ }
148
144
  }
149
145
 
150
146
  const baseComponents = {
@@ -156,9 +152,12 @@ const baseComponents = {
156
152
  // main content reserves bottom padding so the fixed bar never obscures it.
157
153
  const hasBottomNav = mountedFeatureNames.includes('navigability')
158
154
  // Central dismissal: any route or history change closes the shared cart
159
- // lateral, so it never lingers across navigation (forward/back included).
155
+ // lateral and the header's account/search surfaces, so they never linger
156
+ // across navigation (forward/back included).
160
157
  useEffect(() => {
161
158
  set('/cartOpen', false)
159
+ set('/accountOpen', false)
160
+ set('/searchOpen', false)
162
161
  }, [pathname, set])
163
162
  return (
164
163
  <div className="flex min-h-screen flex-col">
@@ -233,7 +232,7 @@ const baseComponents = {
233
232
  },
234
233
  StorefrontNavbar: ({ props, emit }: { props: Record<string, unknown>; emit: (event: string) => void }) => {
235
234
  const parsed = storefrontNavbarPropsSchema.parse(props)
236
- const { state, set } = useStateStore()
235
+ const { state } = useStateStore()
237
236
  // The one session→chrome bridge. It reads the shared account state the
238
237
  // lifecycle seeds/writes directly from the store (never importing the
239
238
  // lifecycle module, so an unmounted customer-auth leaves no account wiring in
@@ -244,28 +243,9 @@ const baseComponents = {
244
243
  const accountResolution = (
245
244
  typeof state.accountResolution === 'string' ? state.accountResolution : 'unresolved'
246
245
  ) as AccountResolution | 'unresolved'
247
- const cart = (state.cart ?? []) as CartLineState[]
248
- const totals = state.cartTotals as CartTotalsState | null
249
- // One money formatter for the whole shell, built from the shopper locale
250
- // the catch-all host seeded (the same locale as `<html lang>`). The navbar
251
- // forwards it to the cart sheet, so every chrome money surface agrees.
252
- const storeLocale =
253
- typeof state.storeLocale === 'string' && state.storeLocale.trim() !== ''
254
- ? state.storeLocale
255
- : DEFAULT_STORE_LOCALE
256
- const formatMoney = createStoreMoneyFormatter(storeLocale)
257
- const cartError = typeof state.cartError === 'string' ? state.cartError : undefined
258
- const readError = typeof state.cartReadError === 'string' ? state.cartReadError : undefined
259
- const errorLabel = cartError ?? readError
260
- const cartState = state.cartPending ? 'pending' : errorLabel ? 'error' : 'idle'
261
- // Checkout is offered only when the required backend amounts are present and
262
- // valid: a missing/malformed subtotal, total, or line amount blocks it, while
263
- // an undetermined shipping amount does not (AC-CART-4.4 / UC-CART-7).
264
- const amountsValid =
265
- cart.every((line) => isAvailableMoney(line.lineTotal)) &&
266
- totals !== null &&
267
- isAvailableMoney(totals.subtotal) &&
268
- isAvailableMoney(totals.total)
246
+ // One shared lateral: visibility is driven by the shared `cartOpen` state (a
247
+ // successful add opens it; navigation dismisses it).
248
+ const cart = useShellCart(emit)
269
249
  return (
270
250
  <StorefrontNavbar
271
251
  storeCategories={parsed.storeCategories}
@@ -305,68 +285,105 @@ const baseComponents = {
305
285
  // search is presented while the contract is unverified; the user-owned
306
286
  // shell seam may opt in with `showSearch: true`.
307
287
  showSearch={parsed.showSearch ?? false}
308
- items={toNavCartItems(cart)}
309
- subtotal={totals?.subtotal}
310
- formatMoney={formatMoney}
311
- // One shared lateral: visibility is driven by the shared `cartOpen`
312
- // state (a successful add opens it; navigation dismisses it). The
313
- // canonical line amounts and lifecycle states come from the same cart
314
- // state the standalone `/cart` view reads.
288
+ items={cart.items}
289
+ subtotal={cart.subtotal}
290
+ formatMoney={cart.formatMoney}
315
291
  canonicalCart
316
- cartState={cartState}
317
- cartErrorLabel={errorLabel}
318
- onCartRetry={() => emit('refreshCart')}
319
- cartOpen={state.cartOpen === true}
320
- onCartOpenChange={(open) => set('/cartOpen', open)}
321
- checkoutUnavailable={!checkoutAvailable}
322
- checkoutDisabled={cartState !== 'idle' || cart.length === 0 || !amountsValid}
323
- viewCartUnavailable={!cartViewAvailable}
324
- onViewCart={() => emit('goToCart')}
325
- onCheckout={() => emit('goToCheckout')}
326
- onQtyChange={(id, delta) => {
327
- set('/qtyDelta', { id, delta })
328
- emit('applyQuantityDelta')
329
- }}
330
- onRemove={(id) => {
331
- set('/lastRemoved', id)
332
- emit('removeFromCart')
333
- }}
292
+ cartState={cart.cartState}
293
+ cartErrorLabel={cart.errorLabel}
294
+ onCartRetry={cart.onRetry}
295
+ cartOpen={cart.open}
296
+ onCartOpenChange={cart.setOpen}
297
+ checkoutUnavailable={cart.checkoutUnavailable}
298
+ checkoutDisabled={cart.checkoutDisabled}
299
+ viewCartUnavailable={cart.viewCartUnavailable}
300
+ onViewCart={cart.onViewCart}
301
+ onCheckout={cart.onCheckout}
302
+ onQtyChange={cart.onQtyChange}
303
+ onRemove={cart.onRemove}
334
304
  />
335
305
  )
336
306
  },
337
- HeaderUniversal: ({
338
- props,
339
- emit,
340
- }: {
341
- props: Record<string, unknown>
342
- emit: (event: string) => void
343
- }) => {
307
+ HeaderUniversal: ({ props, emit }: { props: Record<string, unknown>; emit: (event: string) => void }) => {
344
308
  const parsed = universalHeaderShellPropsSchema.parse(props)
345
309
  const { navigate } = useNextApp()
346
- const { state } = useStateStore()
347
- const cart = (state.cart ?? []) as CartLineState[]
348
- const cartQuantity = cart.reduce((quantity, line) => quantity + line.quantity, 0)
310
+ const { state, set } = useStateStore()
311
+ const pathname = usePathname()
349
312
  const config = createStorefrontHeaderConfig()
313
+ // Session→chrome bridge, gated on the mounted capability exactly like the
314
+ // legacy navbar: an unmounted customer-auth leaves no account wiring here.
315
+ const authMounted = mountedFeatureNames.includes('customer-auth')
316
+ const identity = (state.accountCustomer ?? null) as AccountIdentity | null
317
+ const user = authMounted ? accountStoreUser(identity) ?? undefined : undefined
318
+ const cart = useShellCart(emit)
319
+ // The header badge reads the authoritative cart, never a demo count.
350
320
  const context = buildHeaderContext(
351
321
  parsed.siteName,
352
322
  parsed.menu,
353
323
  parsed.logoAccent?.text.trim() || undefined,
354
- cartQuantity,
324
+ {
325
+ cart: {
326
+ quantity: cart.quantity,
327
+ lineCount: cart.lineCount,
328
+ currency: cart.currency,
329
+ ...(cart.errorLabel ? { error: cart.errorLabel } : {}),
330
+ },
331
+ account: user
332
+ ? { state: 'authenticated', user, menu: storefrontAccountMenuItems }
333
+ : { state: 'guest', menu: [] },
334
+ },
355
335
  )
336
+ // The cart module announces its count from the same authoritative quantity
337
+ // the badge reads (never the design demo count).
356
338
  const cartLabel = (
357
- cartQuantity === 1 ? navbarLabels.cartCountOne : navbarLabels.cartCount
358
- ).replace('{count}', String(cartQuantity))
339
+ cart.quantity === 1 ? navbarLabels.cartCountOne : navbarLabels.cartCount
340
+ ).replace('{count}', String(cart.quantity))
359
341
  const labels = { ...storefrontHeaderLabels, cart: { label: cartLabel } }
360
- // Header navigation stays client-side. The commerce action opens the shared
361
- // cart state, which is rendered by the sheet mounted beside this header.
342
+ // The header mounts the three lateral surfaces, so it owns their dismissal.
343
+ // `Layout` resets them on a pathname change too, but that reset only exists
344
+ // while the shell layout is mounted and lands a frame after the route does;
345
+ // a lateral opened from here must never outlive the page it was opened on.
346
+ useEffect(() => {
347
+ set('/accountOpen', false)
348
+ set('/cartOpen', false)
349
+ set('/searchOpen', false)
350
+ }, [pathname, set])
351
+ // The block prevents the default anchor navigation and emits `navigate`
352
+ // instead, so the host resolves it to client navigation (the logo and every
353
+ // menu destination). `openComponent` targets are the header's lateral
354
+ // surfaces, mounted below with the header element: no dead affordance is
355
+ // rendered.
362
356
  const handleAction = (action: {
363
357
  name: string
364
358
  payload?: Record<string, string | number | boolean>
365
359
  }) => {
366
360
  if (action.name === 'navigate' && typeof action.payload?.href === 'string') {
361
+ // Close first, so the destination never paints underneath an open
362
+ // lateral and no layer outlives the route that opened it.
363
+ set('/accountOpen', false)
364
+ set('/cartOpen', false)
365
+ set('/searchOpen', false)
367
366
  navigate(action.payload.href)
368
- } else if (action.name === 'openCart') {
367
+ return
368
+ }
369
+ // The cart module opens the shared live cart state: the lateral mounted
370
+ // beside this header reads the same store, so the action reaches the sheet
371
+ // through the shell handler instead of a second, private sheet.
372
+ if (action.name === 'openCart') {
369
373
  emit('openCart')
374
+ return
375
+ }
376
+ if (action.name !== 'openComponent') return
377
+ switch (action.payload?.target) {
378
+ case 'universal-cart':
379
+ set('/cartOpen', true)
380
+ break
381
+ case 'universal-account':
382
+ set('/accountOpen', true)
383
+ break
384
+ case 'universal-search':
385
+ set('/searchOpen', true)
386
+ break
370
387
  }
371
388
  }
372
389
  return (
@@ -378,7 +395,61 @@ const baseComponents = {
378
395
  className={parsed.className}
379
396
  onAction={handleAction}
380
397
  />
381
- <StorefrontCartSheet emit={emit} />
398
+ <StorefrontCartDrawer
399
+ open={cart.open}
400
+ onOpenChange={cart.setOpen}
401
+ title={navbarLabels.cartTitle}
402
+ closeLabel={navbarLabels.cartClose}
403
+ items={cart.items}
404
+ subtotal={cart.subtotal}
405
+ formatMoney={cart.formatMoney}
406
+ canonical
407
+ state={cart.cartState}
408
+ errorLabel={cart.errorLabel}
409
+ retryLabel={storefrontCartDrawerLabels.retryLabel}
410
+ onRetry={cart.onRetry}
411
+ onContinueShopping={() => {
412
+ // The sheet closes itself; a continue-shopping click also leaves the
413
+ // product context for the catalog, so the affordance does something
414
+ // the shopper can see instead of only dismissing the lateral.
415
+ cart.setOpen(false)
416
+ navigate('/categories')
417
+ }}
418
+ checkoutUnavailable={cart.checkoutUnavailable}
419
+ checkoutDisabled={cart.checkoutDisabled}
420
+ viewCartUnavailable={cart.viewCartUnavailable}
421
+ onCheckout={cart.onCheckout}
422
+ onViewCart={cart.onViewCart}
423
+ onQtyChange={cart.onQtyChange}
424
+ onRemove={cart.onRemove}
425
+ {...cartSheetLabels}
426
+ />
427
+ <StorefrontAccountDrawer
428
+ open={state.accountOpen === true}
429
+ onOpenChange={(open) => set('/accountOpen', open)}
430
+ user={user}
431
+ items={storefrontAccountMenuItems}
432
+ // The guest CTA is a shell navigation, like the logo and every menu
433
+ // destination. A plain `signInHref` anchor would leave the document
434
+ // for `/account` while the lateral was still open on top of it, so the
435
+ // host closes the surface and routes instead.
436
+ onSignIn={() => {
437
+ set('/accountOpen', false)
438
+ navigate(storefrontAccountMenuItems[0]?.href ?? '/account')
439
+ }}
440
+ onSignOut={authMounted ? () => emit('logout') : undefined}
441
+ pending={authMounted && (state.accountPending === true || state.accountReconciling === true)}
442
+ {...storefrontAccountDrawerLabels}
443
+ />
444
+ <StorefrontSearchDialog
445
+ open={state.searchOpen === true}
446
+ onOpenChange={(open) => set('/searchOpen', open)}
447
+ onSubmit={(query) => {
448
+ set('/searchOpen', false)
449
+ navigate(`/categories?search=${encodeURIComponent(query)}`)
450
+ }}
451
+ {...storefrontSearchDialogLabels}
452
+ />
382
453
  </>
383
454
  )
384
455
  },
@@ -7,11 +7,7 @@ import { storefrontInitialState } from '../state'
7
7
  import { views } from '../views'
8
8
  import { footerShellProps, navbarShellProps } from '../shell/props'
9
9
  import { bannerDismissLabel, mobileBottomNavItems } from '../shell/content'
10
- import {
11
- checkoutAvailable,
12
- mountedFeatureConfigs,
13
- mountedFeatureNames,
14
- } from '../composition'
10
+ import { checkoutAvailable, mountedFeatureConfigs, mountedFeatureNames } from '../composition'
15
11
  import type { StorefrontElement } from './types'
16
12
 
17
13
  export type { StorefrontElement }
@@ -51,6 +47,35 @@ const routes = Object.fromEntries(
51
47
  // boundary), so a removed feature leaves no dangling skip link, back-to-top, or
52
48
  // bottom navigation behind.
53
49
  const hasNavigability = mountedFeatureNames.includes('navigability')
50
+
51
+ /**
52
+ * The events the shell header's registry component emits, bound to the shell's
53
+ * registered handlers. json-render only resolves an emitted event when the
54
+ * element declares it (`element.on`): an undeclared event is silently dropped.
55
+ * That is why every action the header's cart and account surfaces dispatch must
56
+ * appear here, and why feature-owned actions are bound only when their feature is
57
+ * installed (an absent handler would be an unknown action).
58
+ */
59
+ export function headerSurfaceEvents(
60
+ mounted: readonly string[],
61
+ ): NonNullable<StorefrontElement['on']> {
62
+ return {
63
+ // The header's cart module opens the shared live cart lateral through the
64
+ // shell's `openCart` handler, so the surface is the one the shell mounts.
65
+ openCart: { action: 'openCart' },
66
+ goToCart: { action: 'goToCart' },
67
+ refreshCart: { action: 'refreshCart' },
68
+ applyQuantityDelta: { action: 'applyQuantityDelta' },
69
+ removeFromCart: { action: 'removeFromCart' },
70
+ ...(checkoutAvailable ? { goToCheckout: { action: 'goToCheckout' } } : {}),
71
+ ...(mounted.includes('customer-auth')
72
+ ? {
73
+ logout: { action: 'logout' },
74
+ retryAccountSession: { action: 'retryAccountSession' },
75
+ }
76
+ : {}),
77
+ }
78
+ }
54
79
  const navigabilityConfig = (mountedFeatureConfigs['navigability'] ?? {}) as {
55
80
  showBackToTop?: boolean
56
81
  }
@@ -119,11 +144,13 @@ const shellElements: Record<string, StorefrontElement> = {
119
144
  // user-owned shell seam. Spread last so merchant edits win.
120
145
  ...navbarShellProps,
121
146
  },
122
- on: {
123
- openCart: { action: 'openCart' },
124
- goToCart: { action: 'goToCart' },
125
- ...(checkoutAvailable ? { goToCheckout: { action: 'goToCheckout' } } : {}),
126
- },
147
+ // The header's lateral surfaces (cart, account, search) dispatch through the
148
+ // shell's registered handlers. json-render resolves an emitted event ONLY
149
+ // when the element declares it here: an undeclared event is silently
150
+ // dropped, which is why the cart action, checkout/view-cart,
151
+ // quantity/remove and sign-out must be bound. Feature-owned handlers are
152
+ // bound only when their feature is installed.
153
+ on: headerSurfaceEvents(mountedFeatureNames),
127
154
  },
128
155
  footer: {
129
156
  type: 'Footer',
@@ -218,6 +218,10 @@ export interface StorefrontCoreState {
218
218
  /** Visible real-mode failure; null when the data loaded. */
219
219
  dataError: string | null
220
220
  cartOpen: boolean
221
+ /** Account lateral visibility, owned by the header's account module. */
222
+ accountOpen: boolean
223
+ /** Global search dialog visibility, owned by the header's search module. */
224
+ searchOpen: boolean
221
225
  // ---- cart (backend-authoritative) ----
222
226
  cart: CartLineState[]
223
227
  cartTotals: CartTotalsState | null
@@ -279,6 +283,8 @@ export const storefrontCoreState: StorefrontCoreState = {
279
283
  storeLocale: DEFAULT_STORE_LOCALE,
280
284
  dataError: null,
281
285
  cartOpen: false,
286
+ accountOpen: false,
287
+ searchOpen: false,
282
288
  cart: [],
283
289
  cartTotals: null,
284
290
  cartId: null,
@@ -169,7 +169,7 @@ export const universalBannerDataSchema = z.object({
169
169
  layout: z.object({
170
170
  gapX: z.enum(["sm", "md", "lg", "xl", "none"]),
171
171
  gapY: z.enum(["sm", "md", "lg", "xl", "none"]),
172
- maxWidth: z.enum(["full", "sm", "md", "lg", "xl"]),
172
+ maxWidth: z.enum(["full", "page", "sm", "md", "lg", "xl"]),
173
173
  maxHeight: z.enum(["sm", "md", "lg", "xl", "none"]),
174
174
  align: z.enum(["center", "start", "end"]),
175
175
  radius: z.enum(["md", "lg", "xl", "none", "2xl"]),
@@ -295,7 +295,9 @@ export const heroBannerData = {
295
295
  spans: [2, 1, 1, 1, 1],
296
296
  gapX: 'md',
297
297
  gapY: 'md',
298
- maxWidth: 'full',
298
+ // The banner shares the page column with the product rail and the rest of
299
+ // the sections instead of running to the viewport edges.
300
+ maxWidth: 'page',
299
301
  // Caps every cell at 384px, which is the hero's height in its two-column
300
302
  // cell. The tiles keep their 224px floor, so the wall stays near 630px.
301
303
  maxHeight: 'xl',
@@ -282,7 +282,7 @@ export const universalBannerDataSchema = z.object({
282
282
  layout: z.object({
283
283
  gapX: z.enum(['sm', 'md', 'lg', 'xl', 'none']),
284
284
  gapY: z.enum(['sm', 'md', 'lg', 'xl', 'none']),
285
- maxWidth: z.enum(['full', 'sm', 'md', 'lg', 'xl']),
285
+ maxWidth: z.enum(['full', 'page', 'sm', 'md', 'lg', 'xl']),
286
286
  maxHeight: z.enum(['sm', 'md', 'lg', 'xl', 'none']),
287
287
  align: z.enum(['center', 'start', 'end']),
288
288
  radius: z.enum(['md', 'lg', 'xl', 'none', '2xl']),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thorprovider/storefront",
3
- "version": "0.15.3",
3
+ "version": "0.15.4",
4
4
  "description": "Deterministic storefront scaffolder and installable OpenCode skill suite for Thor Commerce (Next.js, @thorprovider/blocks, @thorprovider/adapters, Medusa)",
5
5
  "type": "module",
6
6
  "bin": "bin/storefront.js",
@@ -169,7 +169,7 @@ export const universalBannerDataSchema = z.object({
169
169
  layout: z.object({
170
170
  gapX: z.enum(["sm", "md", "lg", "xl", "none"]),
171
171
  gapY: z.enum(["sm", "md", "lg", "xl", "none"]),
172
- maxWidth: z.enum(["full", "sm", "md", "lg", "xl"]),
172
+ maxWidth: z.enum(["full", "page", "sm", "md", "lg", "xl"]),
173
173
  maxHeight: z.enum(["sm", "md", "lg", "xl", "none"]),
174
174
  align: z.enum(["center", "start", "end"]),
175
175
  radius: z.enum(["md", "lg", "xl", "none", "2xl"]),