@thorprovider/storefront 0.15.2 → 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.
Files changed (34) hide show
  1. package/README.md +1 -1
  2. package/assets/templates/app/app/[[...slug]]/page.tsx +4 -0
  3. package/assets/templates/app/lib/__STOREFRONT__/header-universal.ts +112 -33
  4. package/assets/templates/app/lib/__STOREFRONT__/registry.tsx +236 -71
  5. package/assets/templates/app/lib/__STOREFRONT__/spec/index.ts +37 -1
  6. package/assets/templates/app/lib/__STOREFRONT__/state.core.ts +6 -0
  7. package/assets/templates/app/lib/__STOREFRONT__/views/sections/schema.universal-banner.ts +2 -1
  8. package/assets/templates/app/lib/__STOREFRONT__/views/sections/universal-banner.client.tsx +4 -1
  9. package/assets/templates/app/public/demo/accessories.svg +7 -0
  10. package/assets/templates/app/public/demo/dresses.svg +6 -0
  11. package/assets/templates/app/public/demo/furniture.svg +9 -0
  12. package/assets/templates/app/public/demo/home.svg +8 -0
  13. package/assets/templates/app/public/demo/jackets.svg +11 -0
  14. package/assets/templates/app/public/demo/promo-invierno.svg +8 -0
  15. package/assets/templates/features/checkout/state.ts +2 -0
  16. package/assets/templates/views/category/assembly/slots/filter/CategoryListing/element.part +1 -0
  17. package/assets/templates/views/category/assembly/slots/filter/CategoryListing/registry.part +2 -0
  18. package/assets/templates/views/category/content.ts +1 -0
  19. package/assets/templates/views/category/index.tsx +1 -0
  20. package/assets/templates/views/category/registry.tsx +2 -0
  21. package/assets/templates/views/category/schema.ts +2 -0
  22. package/assets/templates/views/checkout/checkout-commerce-hosted.tsx +19 -0
  23. package/assets/templates/views/checkout/registry.tsx +22 -5
  24. package/assets/templates/views/home/assembly/slots/hero/UniversalBanner/registry.part +6 -1
  25. package/assets/templates/views/home/content.ts +5 -1
  26. package/assets/templates/views/home/props.ts +8 -1
  27. package/assets/templates/views/home/registry.tsx +6 -1
  28. package/assets/templates/views/home/schema.ts +2 -1
  29. package/package.json +1 -1
  30. package/scripts/candidate.mjs +2 -2
  31. package/scripts/env-file.mjs +5 -0
  32. package/scripts/reconcile.mjs +4 -1
  33. package/scripts/render-templates.mjs +106 -1
  34. package/skills/sf-view-gen/assets/templates/views/sections/schema.universal-banner.ts +1 -1
package/README.md CHANGED
@@ -144,7 +144,7 @@ yarn dev
144
144
  ```
145
145
 
146
146
  A fresh `create` seeds `home` + `cart` (home hero/benefits/category sections, a
147
- navbar-owned cart sheet, a standalone `/cart` review route). Pass `--starter` to
147
+ header-owned cart sheet, a standalone `/cart` review route). Pass `--starter` to
148
148
  seed the full curated composition instead — every curated view and feature, read
149
149
  from the registry, held units excluded. Everything renders with only
150
150
  `@thorprovider/blocks` (UI) and `@thorprovider/adapters` (data). Then grow it by asking
@@ -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,15 +26,16 @@ 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
  /**
32
- * The starter header. The demo feeds the commerce surface the starter can
33
- * honestly render: the announcement, the search field, the account/wishlist/
34
- * cart accesses and the main menu. The horizontal category strip (`navigation`)
35
- * and the region/language/support accesses stay off — the starter feeds no data
36
- * for them, and the support module's default `/help` action is a route the
37
- * scaffold does not serve.
33
+ * The starter header. The storefront feeds the commerce surface it can
34
+ * honestly render: the announcement, search field, account/wishlist/cart
35
+ * accesses and main menu. The cart count and action bind to the live cart in
36
+ * the shell registry. The horizontal category strip (`navigation`) and the
37
+ * region/language/support accesses stay off because the starter feeds no data
38
+ * for them and `/help` is not a served route.
38
39
  */
39
40
  export function createStorefrontHeaderConfig(): HeaderConfig {
40
41
  const base = createDefaultConfig()
@@ -56,20 +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) => {
67
- if (module.id !== 'search') return module
68
- // The demo search is always a bar (never the icon fallback): the block
69
- // measures its container client-side, so the server render would
70
- // otherwise fall back to the base-breakpoint icon and the search field
71
- // copy would never appear in the SSR HTML.
72
- return { ...module, responsive: undefined }
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
+ }
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.
92
+ return {
93
+ ...module,
94
+ actions: { ...module.actions, click: { name: 'openCart' } },
95
+ }
96
+ }
97
+ return module
73
98
  }),
74
99
  wishlistModule,
75
100
  ]
@@ -126,6 +151,39 @@ export const storefrontHeaderLabels: Record<string, Record<string, string>> = {
126
151
  announcement: { link: 'Ver más' },
127
152
  }
128
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
+
129
187
  /** The live-catalog menu labels: the trigger is `Menú`, the rest are required. */
130
188
  const HEADER_MENU_LABELS: UniversalMainMenuData['labels'] = {
131
189
  menuTrigger: 'Menú',
@@ -241,11 +299,12 @@ const DEMO_MENU_CATEGORIES: UniversalMainMenuItem[] = [
241
299
  href: '/categories/jackets',
242
300
  description: 'Outerwear and layering pieces.',
243
301
  count: 12,
302
+ image: { src: '/demo/jackets.svg', alt: 'Jackets' },
244
303
  badge: { label: 'Nuevo', tone: 'accent' },
245
304
  children: [
246
- { id: 'demo-jackets-quilted', label: 'Quilted', href: '/categories/jackets', count: 6 },
247
- { id: 'demo-jackets-coats', label: 'Coats', href: '/categories/dresses', count: 4 },
248
- { id: 'demo-jackets-layers', label: 'Light layers', href: '/categories/accessories', count: 2 },
305
+ { id: 'demo-jackets-quilted', label: 'Quilted', href: '/categories/jackets', count: 6, image: { src: '/demo/jackets.svg', alt: 'Quilted' } },
306
+ { id: 'demo-jackets-coats', label: 'Coats', href: '/categories/dresses', count: 4, image: { src: '/demo/jackets.svg', alt: 'Coats' } },
307
+ { id: 'demo-jackets-layers', label: 'Light layers', href: '/categories/accessories', count: 2, image: { src: '/demo/jackets.svg', alt: 'Light layers' } },
249
308
  ],
250
309
  },
251
310
  {
@@ -254,6 +313,7 @@ const DEMO_MENU_CATEGORIES: UniversalMainMenuItem[] = [
254
313
  href: '/categories/dresses',
255
314
  description: 'Editorial silhouettes for seasonal collections.',
256
315
  count: 9,
316
+ image: { src: '/demo/dresses.svg', alt: 'Dresses' },
257
317
  },
258
318
  {
259
319
  id: 'demo-home',
@@ -261,6 +321,7 @@ const DEMO_MENU_CATEGORIES: UniversalMainMenuItem[] = [
261
321
  href: '/categories/home',
262
322
  description: 'Decor and living objects for lifestyle layouts.',
263
323
  count: 14,
324
+ image: { src: '/demo/home.svg', alt: 'Home' },
264
325
  },
265
326
  {
266
327
  id: 'demo-accessories',
@@ -268,6 +329,7 @@ const DEMO_MENU_CATEGORIES: UniversalMainMenuItem[] = [
268
329
  href: '/categories/accessories',
269
330
  description: 'Complementary products for cart and bundle flows.',
270
331
  count: 7,
332
+ image: { src: '/demo/accessories.svg', alt: 'Accessories' },
271
333
  },
272
334
  {
273
335
  id: 'demo-furniture',
@@ -275,6 +337,7 @@ const DEMO_MENU_CATEGORIES: UniversalMainMenuItem[] = [
275
337
  href: '/categories/furniture',
276
338
  description: 'Statement pieces for the home, including oversized and fragile deliveries.',
277
339
  count: 5,
340
+ image: { src: '/demo/furniture.svg', alt: 'Furniture' },
278
341
  badge: { label: '-30%', tone: 'promo' },
279
342
  },
280
343
  ]
@@ -287,6 +350,7 @@ const DEMO_PROMOTION: UniversalMainMenuData['promotion'] = {
287
350
  description: 'Lana virgen y lino lavado, tejidos en talleres locales.',
288
351
  href: '/categories/home',
289
352
  ctaLabel: 'Ver la colección',
353
+ image: { src: '/demo/promo-invierno.svg', alt: 'Textiles que abrigan la casa' },
290
354
  }
291
355
 
292
356
  /**
@@ -304,36 +368,51 @@ export function buildDemoHeaderMenu(): UniversalMainMenuData {
304
368
  }
305
369
  }
306
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
+
307
383
  /**
308
- * The runtime context the shell feeds the header. This is the clearly-labelled
309
- * DEMO state: the announcement, cart badge (3), wishlist count (4) and account
310
- * access are demo copy fed so the full design-B header renders in the starter —
311
- * never a real commerce read. Region/language stay empty (their modules are
312
- * removed from the config, so nothing reads them). The live catalog/menu seam
313
- * is the `menu` argument (built by the host from the real taxonomy or the demo
314
- * 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).
315
390
  */
316
391
  export function buildHeaderContext(
317
392
  siteName: string,
318
393
  menu?: UniversalMainMenuData,
319
394
  accent?: string,
395
+ runtime?: HeaderRuntimeSeed,
320
396
  ): HeaderContext {
397
+ const cart = runtime?.cart
321
398
  return {
322
399
  brand: { name: siteName, href: '/', ...(accent ? { accent } : {}) },
323
400
  menu,
324
401
  cart: {
325
402
  state: 'ready',
326
- // Demo badge count only: no real cart lines are fabricated.
403
+ // No line snapshots are fabricated: the header badge reads the counts the
404
+ // host supplies from the authoritative cart.
327
405
  lines: [],
328
- quantity: 3,
329
- lineCount: 0,
330
- currency: 'EUR',
406
+ quantity: cart?.quantity ?? 0,
407
+ lineCount: cart?.lineCount ?? 0,
408
+ currency: cart?.currency ?? 'EUR',
331
409
  shippingGroups: 0,
332
410
  subtotalUnavailableLabel: 'Envío calculado al finalizar la compra',
333
411
  promotions: [],
412
+ ...(cart?.error ? { error: cart.error } : {}),
334
413
  },
335
- account: { state: 'guest', menu: [] },
336
- wishlist: { count: 4, lists: 1 },
414
+ account: runtime?.account ?? { state: 'guest', menu: [] },
415
+ wishlist: { count: runtime?.wishlistCount ?? 0, lists: runtime?.wishlistCount ? 1 : 0 },
337
416
  regions: { activeId: '', options: [] },
338
417
  languages: { activeCode: '', options: [] },
339
418
  locations: { enabled: false, options: [] },