@thorprovider/storefront 0.13.2 → 0.14.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/assets/templates/app/lib/__STOREFRONT__/views/sections/products.client.tsx +1 -0
- package/assets/templates/app/lib/__STOREFRONT__/views/sections/schema.products.ts +6 -0
- package/assets/templates/views/home/assembly/assembly.json +2 -2
- package/assets/templates/views/home/content.ts +56 -2
- package/assets/templates/views/home/data.ts +13 -3
- package/assets/templates/views/home/index.tsx +9 -9
- package/assets/templates/views/home/registry.tsx +17 -17
- package/package.json +1 -1
- package/recipes/recipes.json +22 -4
- package/scripts/candidate.mjs +8 -6
- package/scripts/view-assembly.mjs +26 -5
- package/skills/sf-view-gen/assets/recipes/recipes.json +22 -4
- package/skills/sf-view-gen/assets/templates/views/sections/products.client.tsx +53 -1
- package/skills/sf-view-gen/assets/templates/views/sections/schema.products.ts +6 -0
|
@@ -112,6 +112,7 @@ export const productsRegistry: ViewRegistry = {
|
|
|
112
112
|
<div ref={containerRef}>
|
|
113
113
|
{parsed.variant === 'ProductSlider' ? (
|
|
114
114
|
<UniversalProductSlider
|
|
115
|
+
{...(parsed.sliderPreset ? { variant: parsed.sliderPreset } : {})}
|
|
115
116
|
header={{
|
|
116
117
|
title: parsed.heading ?? 'Productos',
|
|
117
118
|
...(parsed.description ? { description: parsed.description } : {}),
|
|
@@ -33,6 +33,12 @@ export const productsPropsSchema = z.object({
|
|
|
33
33
|
objective: z.string().optional(),
|
|
34
34
|
ctaLabel: z.string().optional(),
|
|
35
35
|
ctaHref: z.string().optional(),
|
|
36
|
+
// Optional rail presentation, independent of the section variant: the same
|
|
37
|
+
// `ProductSlider` mount can read as a plain rail, a deals band, an editorial
|
|
38
|
+
// spread… Only the slider variant consumes it; the grid presentations ignore it.
|
|
39
|
+
sliderPreset: z
|
|
40
|
+
.enum(['classic', 'category', 'featured', 'deals', 'compact', 'editorial'])
|
|
41
|
+
.optional(),
|
|
36
42
|
})
|
|
37
43
|
|
|
38
44
|
export type ProductsProps = z.infer<typeof productsPropsSchema>
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
"view": "home",
|
|
3
3
|
"slots": [
|
|
4
4
|
{ "id": "home.hero", "slot": "hero", "default": "UniversalBanner" },
|
|
5
|
-
{ "id": "home.
|
|
6
|
-
{ "id": "home.
|
|
5
|
+
{ "id": "home.categories", "slot": "categories", "default": "CategoryGrid" },
|
|
6
|
+
{ "id": "home.benefits", "slot": "benefits", "default": "cards" }
|
|
7
7
|
],
|
|
8
8
|
"sections": {
|
|
9
9
|
"faq": {
|
|
@@ -380,6 +380,31 @@ export const heroBannerData = {
|
|
|
380
380
|
},
|
|
381
381
|
}
|
|
382
382
|
|
|
383
|
+
/**
|
|
384
|
+
* Mid-page campaign band (the `universal-banner` section instance). It reuses
|
|
385
|
+
* the hero campaign — same banners, same real destinations and price claims — but
|
|
386
|
+
* refs only the two campaign tiles and lays them out as a wide pair, so the page
|
|
387
|
+
* changes tone between merch rails without inventing a second campaign.
|
|
388
|
+
*/
|
|
389
|
+
export const bandBannerData = {
|
|
390
|
+
...heroBannerData,
|
|
391
|
+
config: {
|
|
392
|
+
...heroBannerData.config,
|
|
393
|
+
blockId: 'home-campaign-band',
|
|
394
|
+
name: 'Banda de campaña',
|
|
395
|
+
refs: [
|
|
396
|
+
{ bannerId: 'banner-nuevas-llegadas' },
|
|
397
|
+
{ bannerId: 'banner-guia-regalo' },
|
|
398
|
+
],
|
|
399
|
+
layout: {
|
|
400
|
+
...heroBannerData.config.layout,
|
|
401
|
+
columns: { base: 1, md: 2, '2xl': 2 },
|
|
402
|
+
spans: [1, 1],
|
|
403
|
+
maxHeight: 'lg',
|
|
404
|
+
},
|
|
405
|
+
},
|
|
406
|
+
}
|
|
407
|
+
|
|
383
408
|
/**
|
|
384
409
|
* Editorial section instance content, keyed by the section instance id the
|
|
385
410
|
* manifest persists (`views[].sections[].id`, e.g. `home-faq-1`). The derived
|
|
@@ -389,10 +414,39 @@ export const heroBannerData = {
|
|
|
389
414
|
* the section's neutral default.
|
|
390
415
|
*/
|
|
391
416
|
export const sectionContent: Record<string, Record<string, unknown>> = {
|
|
417
|
+
// Marketplace rail order, seeded by the home recipe: best sellers prove demand,
|
|
418
|
+
// the campaign band changes the tone, deals carry urgency, and arrivals give
|
|
419
|
+
// the returning visitor something new. Every id is minted by the manifest and
|
|
420
|
+
// stable, so removing a section never rewrites this file.
|
|
392
421
|
'home-products-1': {
|
|
393
|
-
heading: 'Los más vendidos
|
|
394
|
-
description: '
|
|
422
|
+
heading: 'Los más vendidos',
|
|
423
|
+
description: 'Lo que más se está llevando, con precio y descuento reales de catálogo.',
|
|
395
424
|
ctaLabel: 'Ver todo el catálogo',
|
|
396
425
|
ctaHref: '/categories',
|
|
397
426
|
},
|
|
427
|
+
'home-universal-banner-1': {
|
|
428
|
+
data: bandBannerData,
|
|
429
|
+
},
|
|
430
|
+
'home-products-2': {
|
|
431
|
+
heading: 'Ofertas de la semana',
|
|
432
|
+
description: 'Piezas rebajadas del catálogo, con el descuento a la vista.',
|
|
433
|
+
ctaLabel: 'Ver rebajas',
|
|
434
|
+
ctaHref: '/categories',
|
|
435
|
+
// Presentation preset, not the section variant: `deals` adds the muted
|
|
436
|
+
// surface and the discount/compare-at badges to every card in the rail.
|
|
437
|
+
sliderPreset: 'deals',
|
|
438
|
+
},
|
|
439
|
+
'home-products-3': {
|
|
440
|
+
heading: 'Recién llegado',
|
|
441
|
+
description: 'Las últimas incorporaciones de la temporada, antes que nadie.',
|
|
442
|
+
ctaLabel: 'Ver novedades',
|
|
443
|
+
ctaHref: '/categories',
|
|
444
|
+
},
|
|
445
|
+
'home-cta-1': {
|
|
446
|
+
badgeText: 'Compra sencilla',
|
|
447
|
+
title: 'Un catálogo, un carrito, cero sorpresas',
|
|
448
|
+
description: 'Precios claros, stock real y devoluciones sin letra pequeña.',
|
|
449
|
+
primaryCta: { label: 'Explorar el catálogo', href: '/categories' },
|
|
450
|
+
secondaryCta: { label: 'Ver novedades', href: '/categories' },
|
|
451
|
+
},
|
|
398
452
|
}
|
|
@@ -22,12 +22,22 @@ export function toNavCategories(
|
|
|
22
22
|
// state. Entries whose id is no longer referenced by the composition are kept
|
|
23
23
|
// but never queried, so re-adding the section with the same id restores them.
|
|
24
24
|
export const sectionSources: Record<string, unknown> = {
|
|
25
|
-
//
|
|
26
|
-
//
|
|
27
|
-
//
|
|
25
|
+
// Three rails, three buying reasons, one component. Each id is minted by the
|
|
26
|
+
// home recipe's `defaultSections` seed, and each selection is a canonical
|
|
27
|
+
// catalog collection resolved through the runtime catalog bridge.
|
|
28
28
|
'home-products-1': {
|
|
29
29
|
kind: 'products',
|
|
30
30
|
query: { collections: ['best-sellers'], pageSize: 8 },
|
|
31
31
|
maxItems: 8,
|
|
32
32
|
},
|
|
33
|
+
'home-products-2': {
|
|
34
|
+
kind: 'products',
|
|
35
|
+
query: { collections: ['sale'], pageSize: 8 },
|
|
36
|
+
maxItems: 8,
|
|
37
|
+
},
|
|
38
|
+
'home-products-3': {
|
|
39
|
+
kind: 'products',
|
|
40
|
+
query: { collections: ['new-arrivals'], pageSize: 8 },
|
|
41
|
+
maxItems: 8,
|
|
42
|
+
},
|
|
33
43
|
}
|
|
@@ -31,15 +31,15 @@ const elements: Record<string, StorefrontElement> = {
|
|
|
31
31
|
type: 'UniversalBanner',
|
|
32
32
|
props: homeProps.heroBannerProps,
|
|
33
33
|
},
|
|
34
|
-
'home.benefits': {
|
|
35
|
-
type: 'Feature',
|
|
36
|
-
props: benefitsProps,
|
|
37
|
-
},
|
|
38
34
|
'home.categories': {
|
|
39
35
|
type: 'CategoryGrid',
|
|
40
36
|
props: categoriesProps,
|
|
41
37
|
on: { openCategory: { action: 'openCategory' } },
|
|
42
38
|
},
|
|
39
|
+
'home.benefits': {
|
|
40
|
+
type: 'Feature',
|
|
41
|
+
props: benefitsProps,
|
|
42
|
+
},
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
const catalog = {
|
|
@@ -47,10 +47,6 @@ const catalog = {
|
|
|
47
47
|
props: homeSchemas.universalBannerPropsSchema,
|
|
48
48
|
description: 'Campaign banner collection (presentations: single, grid, carousel).',
|
|
49
49
|
},
|
|
50
|
-
Feature: {
|
|
51
|
-
props: featurePropsSchema,
|
|
52
|
-
description: 'Benefit highlights.',
|
|
53
|
-
},
|
|
54
50
|
CategoryGrid: {
|
|
55
51
|
props: categoryGridPropsSchema,
|
|
56
52
|
description: 'Category listing that renders category cells.',
|
|
@@ -59,6 +55,10 @@ const catalog = {
|
|
|
59
55
|
props: categoryCardPropsSchema,
|
|
60
56
|
description: 'One category cell, without listing section chrome.',
|
|
61
57
|
},
|
|
58
|
+
Feature: {
|
|
59
|
+
props: featurePropsSchema,
|
|
60
|
+
description: 'Benefit highlights.',
|
|
61
|
+
},
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
export const home: ViewModule = {
|
|
@@ -74,7 +74,7 @@ export const home: ViewModule = {
|
|
|
74
74
|
title: 'Inicio',
|
|
75
75
|
description: 'Descubre los productos de __SITE_NAME__.',
|
|
76
76
|
},
|
|
77
|
-
entry: pageRoot('home', ['home.hero', 'home.
|
|
77
|
+
entry: pageRoot('home', ['home.hero', 'home.categories', 'home.benefits'], elements),
|
|
78
78
|
},
|
|
79
79
|
loader: {
|
|
80
80
|
home: async () => {
|
|
@@ -37,23 +37,6 @@ export const registry: ViewRegistry = {
|
|
|
37
37
|
}, [])
|
|
38
38
|
return <UniversalBannerBlock data={{ ...parsed.data, now }} />
|
|
39
39
|
},
|
|
40
|
-
Feature: ({ props }) => {
|
|
41
|
-
const feature = featureSchemas.featureCardsSpecSchema.parse({
|
|
42
|
-
...props,
|
|
43
|
-
presentation: 'cards',
|
|
44
|
-
})
|
|
45
|
-
return (
|
|
46
|
-
<FeatureBlock
|
|
47
|
-
items={feature.items.map((item) => ({ ...item, icon: resolveIcon(item.icon) }))}
|
|
48
|
-
presentation='cards'
|
|
49
|
-
badge={feature.badge}
|
|
50
|
-
title={feature.title}
|
|
51
|
-
description={feature.description}
|
|
52
|
-
ctaLabel={feature.ctaLabel}
|
|
53
|
-
learnMoreLabel={feature.learnMoreLabel}
|
|
54
|
-
/>
|
|
55
|
-
)
|
|
56
|
-
},
|
|
57
40
|
CategoryCard: ({ props, emit }) => {
|
|
58
41
|
const { set } = useStateStore()
|
|
59
42
|
const card = categoryCardPropsSchema.parse(props)
|
|
@@ -85,4 +68,21 @@ export const registry: ViewRegistry = {
|
|
|
85
68
|
/>
|
|
86
69
|
)
|
|
87
70
|
},
|
|
71
|
+
Feature: ({ props }) => {
|
|
72
|
+
const feature = featureSchemas.featureCardsSpecSchema.parse({
|
|
73
|
+
...props,
|
|
74
|
+
presentation: 'cards',
|
|
75
|
+
})
|
|
76
|
+
return (
|
|
77
|
+
<FeatureBlock
|
|
78
|
+
items={feature.items.map((item) => ({ ...item, icon: resolveIcon(item.icon) }))}
|
|
79
|
+
presentation='cards'
|
|
80
|
+
badge={feature.badge}
|
|
81
|
+
title={feature.title}
|
|
82
|
+
description={feature.description}
|
|
83
|
+
ctaLabel={feature.ctaLabel}
|
|
84
|
+
learnMoreLabel={feature.learnMoreLabel}
|
|
85
|
+
/>
|
|
86
|
+
)
|
|
87
|
+
},
|
|
88
88
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thorprovider/storefront",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.0",
|
|
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",
|
package/recipes/recipes.json
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
{
|
|
6
6
|
"name": "home",
|
|
7
7
|
"mvp": true,
|
|
8
|
-
"description": "
|
|
8
|
+
"description": "Marketplace-style landing page: campaign hero, category departments, merchandising rails, trust band, and a closing call to action",
|
|
9
9
|
"route": "/",
|
|
10
10
|
"loader": "home",
|
|
11
11
|
"requiredDataKeys": [
|
|
@@ -42,8 +42,8 @@
|
|
|
42
42
|
],
|
|
43
43
|
"registeredSlots": [
|
|
44
44
|
"hero",
|
|
45
|
-
"
|
|
46
|
-
"
|
|
45
|
+
"categories",
|
|
46
|
+
"benefits"
|
|
47
47
|
],
|
|
48
48
|
"allowedSections": [
|
|
49
49
|
"faq",
|
|
@@ -59,10 +59,28 @@
|
|
|
59
59
|
{
|
|
60
60
|
"type": "products",
|
|
61
61
|
"variant": "ProductSlider",
|
|
62
|
+
"after": "categories"
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
"type": "universal-banner",
|
|
66
|
+
"after": "categories"
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
"type": "products",
|
|
70
|
+
"variant": "ProductSlider",
|
|
71
|
+
"after": "categories"
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
"type": "products",
|
|
75
|
+
"variant": "ProductSlider",
|
|
76
|
+
"after": "categories"
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
"type": "cta",
|
|
62
80
|
"after": "benefits"
|
|
63
81
|
}
|
|
64
82
|
],
|
|
65
|
-
"maxSections":
|
|
83
|
+
"maxSections": 5
|
|
66
84
|
},
|
|
67
85
|
{
|
|
68
86
|
"name": "product",
|
package/scripts/candidate.mjs
CHANGED
|
@@ -433,13 +433,15 @@ export function verifyRegistryArtifact({
|
|
|
433
433
|
|
|
434
434
|
/**
|
|
435
435
|
* `npm publish` returns before every registry edge serves the artifacts. A
|
|
436
|
-
* mirror that is still replicating answers 404 for a version that exists, so
|
|
437
|
-
*
|
|
438
|
-
*
|
|
439
|
-
*
|
|
440
|
-
*
|
|
436
|
+
* mirror that is still replicating answers 404 for a version that exists, so a
|
|
437
|
+
* freshly published pin can look unpublished for a moment.
|
|
438
|
+
*
|
|
439
|
+
* This window stays short on purpose: `create` runs interactively, and a pin
|
|
440
|
+
* that is genuinely missing must fail in seconds, not minutes. The release gate
|
|
441
|
+
* does not rely on it — `scripts/release/wait-for-registry.mjs` holds the run
|
|
442
|
+
* until every pin resolves before acceptance starts.
|
|
441
443
|
*/
|
|
442
|
-
export const REGISTRY_RETRY = Object.freeze({ attempts:
|
|
444
|
+
export const REGISTRY_RETRY = Object.freeze({ attempts: 2, delayMs: 2000 })
|
|
443
445
|
|
|
444
446
|
const defaultSleep = (ms) => new Promise((done) => setTimeout(done, ms))
|
|
445
447
|
|
|
@@ -205,6 +205,16 @@ function renderDataBoundElement(entry, def) {
|
|
|
205
205
|
].join('\n')
|
|
206
206
|
}
|
|
207
207
|
|
|
208
|
+
/**
|
|
209
|
+
* Element type of a rendered element part (`type: 'UniversalBanner'`). The
|
|
210
|
+
* fragment is source text, so the type is read from it; the derived registry
|
|
211
|
+
* keys its bindings by that name.
|
|
212
|
+
*/
|
|
213
|
+
function partElementType(part) {
|
|
214
|
+
const match = /type:\s*'([^']+)'/.exec(part)
|
|
215
|
+
return match ? match[1] : null
|
|
216
|
+
}
|
|
217
|
+
|
|
208
218
|
/**
|
|
209
219
|
* Assemble a view's derived `index.tsx` and `registry.tsx` from the view's
|
|
210
220
|
* single ordered composition (E3 task 5.1).
|
|
@@ -266,7 +276,10 @@ export function assembleView(templateDir, selection = {}, sections = null) {
|
|
|
266
276
|
if (slot.nested === true) continue
|
|
267
277
|
const variant = resolved[slot.slot]
|
|
268
278
|
const fragmentDir = path.join(slotsDir, slot.slot, variant)
|
|
269
|
-
|
|
279
|
+
const elementPart = readPart(fragmentDir, 'element.part')
|
|
280
|
+
elements.push(elementPart)
|
|
281
|
+
const slotElementType = partElementType(elementPart)
|
|
282
|
+
if (slotElementType) registryTypes.add(slotElementType)
|
|
270
283
|
catalog.push(readPart(fragmentDir, 'catalog.part'))
|
|
271
284
|
registry.push(readPart(fragmentDir, 'registry.part'))
|
|
272
285
|
// A fragment may declare no per-variant binding when its block import is
|
|
@@ -290,16 +303,24 @@ export function assembleView(templateDir, selection = {}, sections = null) {
|
|
|
290
303
|
? renderDataBoundElement(entry, def)
|
|
291
304
|
: renderEditorialElement(entry, def),
|
|
292
305
|
)
|
|
293
|
-
registry.push(renderEditorialRegistry(entry, def))
|
|
294
306
|
// A registry binding is keyed by the element type, so several instances of
|
|
295
307
|
// the same section type (for example two `products` sections on one view)
|
|
296
308
|
// share a single registry entry. Emitting one per instance would produce
|
|
297
309
|
// duplicate object keys in the derived `registry.tsx`.
|
|
298
|
-
|
|
299
|
-
|
|
310
|
+
//
|
|
311
|
+
// The same holds across the slot/section boundary: an element type is a
|
|
312
|
+
// host-global name, and the first binding for it wins. A section whose
|
|
313
|
+
// element type equals a registered slot's (a campaign band on a home whose
|
|
314
|
+
// hero already renders `UniversalBanner`) therefore reuses that binding
|
|
315
|
+
// instead of shadowing it, and contributes no second import.
|
|
316
|
+
const reusesExistingBinding = registryTypes.has(def.elementType)
|
|
317
|
+
if (!reusesExistingBinding) {
|
|
318
|
+
registryTypes.add(def.elementType)
|
|
319
|
+
registry.push(renderEditorialRegistry(entry, def))
|
|
320
|
+
sectionRegistryImports.set(def.registryModule, def.registryExport)
|
|
321
|
+
}
|
|
300
322
|
slotIds.push(tsStringLiteral(entry.id))
|
|
301
323
|
sectionPropsModules.add(def.propsModule ?? './content')
|
|
302
|
-
sectionRegistryImports.set(def.registryModule, def.registryExport)
|
|
303
324
|
if (def.dataBound === true) dataBoundIds.push(tsStringLiteral(entry.id))
|
|
304
325
|
}
|
|
305
326
|
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
{
|
|
6
6
|
"name": "home",
|
|
7
7
|
"mvp": true,
|
|
8
|
-
"description": "
|
|
8
|
+
"description": "Marketplace-style landing page: campaign hero, category departments, merchandising rails, trust band, and a closing call to action",
|
|
9
9
|
"route": "/",
|
|
10
10
|
"loader": "home",
|
|
11
11
|
"requiredDataKeys": [
|
|
@@ -42,8 +42,8 @@
|
|
|
42
42
|
],
|
|
43
43
|
"registeredSlots": [
|
|
44
44
|
"hero",
|
|
45
|
-
"
|
|
46
|
-
"
|
|
45
|
+
"categories",
|
|
46
|
+
"benefits"
|
|
47
47
|
],
|
|
48
48
|
"allowedSections": [
|
|
49
49
|
"faq",
|
|
@@ -59,10 +59,28 @@
|
|
|
59
59
|
{
|
|
60
60
|
"type": "products",
|
|
61
61
|
"variant": "ProductSlider",
|
|
62
|
+
"after": "categories"
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
"type": "universal-banner",
|
|
66
|
+
"after": "categories"
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
"type": "products",
|
|
70
|
+
"variant": "ProductSlider",
|
|
71
|
+
"after": "categories"
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
"type": "products",
|
|
75
|
+
"variant": "ProductSlider",
|
|
76
|
+
"after": "categories"
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
"type": "cta",
|
|
62
80
|
"after": "benefits"
|
|
63
81
|
}
|
|
64
82
|
],
|
|
65
|
-
"maxSections":
|
|
83
|
+
"maxSections": 5
|
|
66
84
|
},
|
|
67
85
|
{
|
|
68
86
|
"name": "product",
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
// `variant`. The selection and resolved products arrive through the view state;
|
|
8
8
|
// this boundary only validates them and wires navigation/purchase callbacks.
|
|
9
9
|
|
|
10
|
+
import { UniversalProductSlider, type UniversalProductSliderProps } from '@thorprovider/blocks'
|
|
10
11
|
import { ProductGrid as ProductGridBlock } from '@thorprovider/blocks/blocks/e-commerce/product-list/product-grid'
|
|
11
12
|
import ProductShowcase1Block from '@thorprovider/blocks/blocks/e-commerce/product-list/product-showcase-1'
|
|
12
13
|
import type { ProductPresentation } from '@thorprovider/blocks/contracts'
|
|
@@ -15,6 +16,27 @@ import { useSectionObservation } from '../../section-observation'
|
|
|
15
16
|
import { productsPropsSchema, type ProductsStatus } from './schema.products'
|
|
16
17
|
import type { ViewRegistry } from '../types'
|
|
17
18
|
|
|
19
|
+
// The merchandising rail reads the same resolved selection as the grid, so the
|
|
20
|
+
// only translation is the presentation shape. Host-owned state (navigation and
|
|
21
|
+
// purchase callbacks) is mapped back to the source product by id, which keeps
|
|
22
|
+
// `lastClicked` and the cart actions identical across variants.
|
|
23
|
+
type SliderProductProp = UniversalProductSliderProps['products'][number]
|
|
24
|
+
|
|
25
|
+
function toSliderProduct(product: ProductPresentation): SliderProductProp {
|
|
26
|
+
return {
|
|
27
|
+
id: product.id,
|
|
28
|
+
name: product.title,
|
|
29
|
+
...(product.image ? { image: product.image } : {}),
|
|
30
|
+
...(product.imageAlt ? { imageAlt: product.imageAlt } : {}),
|
|
31
|
+
...(product.href ? { href: product.href } : {}),
|
|
32
|
+
price: product.price,
|
|
33
|
+
...(product.compareAtPrice ? { compareAtPrice: product.compareAtPrice } : {}),
|
|
34
|
+
...(product.rating === undefined ? {} : { rating: product.rating }),
|
|
35
|
+
...(product.badge ? { badge: product.badge } : {}),
|
|
36
|
+
...(product.inStock === false ? { availability: 'out-of-stock' as const } : {}),
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
18
40
|
// Truthful, actionable messages for the non-`ready` states. A failed or
|
|
19
41
|
// unconfigured section never fabricates products.
|
|
20
42
|
function sectionStatusMessage(status: ProductsStatus): string {
|
|
@@ -82,9 +104,39 @@ export const productsRegistry: ViewRegistry = {
|
|
|
82
104
|
onProductClick: openProduct,
|
|
83
105
|
}
|
|
84
106
|
|
|
107
|
+
// The rail's callbacks are typed with its own product shape; map back to the
|
|
108
|
+
// resolved presentation so both variants share one host action path.
|
|
109
|
+
const byId = new Map(parsed.products.map((product) => [String(product.id), product]))
|
|
110
|
+
|
|
85
111
|
return (
|
|
86
112
|
<div ref={containerRef}>
|
|
87
|
-
{parsed.variant === '
|
|
113
|
+
{parsed.variant === 'ProductSlider' ? (
|
|
114
|
+
<UniversalProductSlider
|
|
115
|
+
{...(parsed.sliderPreset ? { variant: parsed.sliderPreset } : {})}
|
|
116
|
+
header={{
|
|
117
|
+
title: parsed.heading ?? 'Productos',
|
|
118
|
+
...(parsed.description ? { description: parsed.description } : {}),
|
|
119
|
+
...(parsed.ctaLabel
|
|
120
|
+
? {
|
|
121
|
+
action: {
|
|
122
|
+
label: parsed.ctaLabel,
|
|
123
|
+
...(parsed.ctaHref ? { href: parsed.ctaHref } : {}),
|
|
124
|
+
variant: 'link' as const,
|
|
125
|
+
},
|
|
126
|
+
}
|
|
127
|
+
: {}),
|
|
128
|
+
}}
|
|
129
|
+
products={parsed.products.map(toSliderProduct)}
|
|
130
|
+
onAddToCart={(product) => {
|
|
131
|
+
const source = byId.get(String(product.id))
|
|
132
|
+
if (source) addToCart(source)
|
|
133
|
+
}}
|
|
134
|
+
onProductClick={(product) => {
|
|
135
|
+
const source = byId.get(String(product.id))
|
|
136
|
+
if (source) openProduct(source)
|
|
137
|
+
}}
|
|
138
|
+
/>
|
|
139
|
+
) : parsed.variant === 'ProductShowcase1' ? (
|
|
88
140
|
<ProductShowcase1Block
|
|
89
141
|
{...shared}
|
|
90
142
|
heading={parsed.heading}
|
|
@@ -33,6 +33,12 @@ export const productsPropsSchema = z.object({
|
|
|
33
33
|
objective: z.string().optional(),
|
|
34
34
|
ctaLabel: z.string().optional(),
|
|
35
35
|
ctaHref: z.string().optional(),
|
|
36
|
+
// Optional rail presentation, independent of the section variant: the same
|
|
37
|
+
// `ProductSlider` mount can read as a plain rail, a deals band, an editorial
|
|
38
|
+
// spread… Only the slider variant consumes it; the grid presentations ignore it.
|
|
39
|
+
sliderPreset: z
|
|
40
|
+
.enum(['classic', 'category', 'featured', 'deals', 'compact', 'editorial'])
|
|
41
|
+
.optional(),
|
|
36
42
|
})
|
|
37
43
|
|
|
38
44
|
export type ProductsProps = z.infer<typeof productsPropsSchema>
|