@thorprovider/storefront 0.4.0 → 0.6.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/README.md +3 -1
- package/assets/templates/app/app/[[...slug]]/page.tsx +19 -1
- package/assets/templates/app/lib/__STOREFRONT__/commerce.ts +20 -30
- package/assets/templates/app/lib/__STOREFRONT__/composition.ts +1 -1
- package/assets/templates/app/lib/__STOREFRONT__/registry.tsx +15 -13
- package/assets/templates/app/lib/__STOREFRONT__/schema.ts +34 -4
- package/assets/templates/app/lib/__STOREFRONT__/shell/props.ts +1 -1
- package/assets/templates/app/lib/__STOREFRONT__/state.core.ts +14 -15
- package/assets/templates/app/lib/__STOREFRONT__/views/sections/testimonials.tsx +26 -19
- package/assets/templates/features/checkout/state.ts +0 -5
- package/assets/templates/views/account/content.ts +14 -3
- package/assets/templates/views/account/index.tsx +1 -1
- package/assets/templates/views/account/registry.tsx +135 -104
- package/assets/templates/views/account/schema.ts +26 -6
- package/assets/templates/views/category/assembly/assembly.json +1 -1
- package/assets/templates/views/category/assembly/index.skeleton.tsx +11 -7
- package/assets/templates/views/category/assembly/registry.skeleton.tsx +8 -8
- package/assets/templates/views/category/assembly/slots/filter/CategoryListing/catalog.part +5 -0
- package/assets/templates/views/category/assembly/slots/filter/{CategoryFilter2 → CategoryListing}/element.part +5 -3
- package/assets/templates/views/category/assembly/slots/filter/{CategoryFilter2 → CategoryListing}/registry.part +9 -5
- package/assets/templates/views/category/content.ts +2 -1
- package/assets/templates/views/category/index.tsx +19 -13
- package/assets/templates/views/category/props.ts +1 -1
- package/assets/templates/views/category/registry.tsx +17 -13
- package/assets/templates/views/category/schema.ts +48 -21
- package/assets/templates/views/checkout/content.ts +60 -0
- package/assets/templates/views/checkout/props.ts +4 -5
- package/assets/templates/views/checkout/registry.tsx +10 -6
- package/assets/templates/views/checkout/schema.ts +10 -16
- package/assets/templates/views/home/assembly/index.skeleton.tsx +0 -2
- package/assets/templates/views/home/index.tsx +0 -2
- package/assets/templates/views/product/registry.tsx +112 -14
- package/assets/templates/views/product/schema.ts +42 -7
- package/bin/storefront.js +21 -0
- package/examples/merchandising/category-led.json +1 -1
- package/examples/merchandising/collection-led.json +1 -1
- package/package.json +2 -1
- package/recipes/archetypes.json +27 -27
- package/recipes/catalog.json +43 -105
- package/recipes/features.json +2 -2
- package/recipes/recipes.json +10 -16
- package/recipes/sections.json +2 -2
- package/scripts/candidate.mjs +263 -6
- package/scripts/composers.mjs +2 -2
- package/scripts/logical-controls.mjs +4 -4
- package/scripts/operation-registry.mjs +1 -1
- package/scripts/view-assembly.mjs +2 -2
- package/skills/sf-view-gen/assets/recipes/archetypes.json +27 -27
- package/skills/sf-view-gen/assets/recipes/catalog.json +43 -105
- package/skills/sf-view-gen/assets/recipes/features.json +2 -2
- package/skills/sf-view-gen/assets/recipes/recipes.json +10 -16
- package/skills/sf-view-gen/assets/recipes/sections.json +2 -2
- package/skills/sf-view-gen/assets/templates/views/sections/schema.testimonials.ts +21 -11
- package/skills/sf-view-gen/assets/templates/views/sections/testimonials.client.tsx +2 -8
- package/assets/templates/views/category/assembly/slots/filter/CategoryFilter2/catalog.part +0 -5
|
@@ -12,9 +12,14 @@
|
|
|
12
12
|
// HTML, or logs. Only the non-secret result (customer/error) is stored.
|
|
13
13
|
|
|
14
14
|
import { useCallback, useEffect, useRef } from 'react'
|
|
15
|
+
import type { ReactNode } from 'react'
|
|
15
16
|
import { Button } from '@thorprovider/blocks/ui/button'
|
|
16
|
-
import
|
|
17
|
-
import
|
|
17
|
+
import { LoginPage, OrderHistory, formatMoney } from '@thorprovider/blocks'
|
|
18
|
+
import type {
|
|
19
|
+
OrderHistoryLabels,
|
|
20
|
+
OrderHistoryOrder,
|
|
21
|
+
OrderHistoryStatusTone,
|
|
22
|
+
} from '@thorprovider/blocks'
|
|
18
23
|
import SignUpBlock from '@thorprovider/blocks/blocks/application/signup-forms/signup-page-1'
|
|
19
24
|
import { useStateStore } from '@json-render/react'
|
|
20
25
|
import type { Customer } from '@thorprovider/types'
|
|
@@ -48,6 +53,28 @@ function AuthNotice({ pending, error }: { pending: boolean; error: string | null
|
|
|
48
53
|
)
|
|
49
54
|
}
|
|
50
55
|
|
|
56
|
+
// The page side of the auth contract. The blocks render only the form: they no
|
|
57
|
+
// longer paint a viewport-height surface, declare a page landmark, or centre
|
|
58
|
+
// themselves, because a generated storefront mounts them inside the default
|
|
59
|
+
// chrome (notice + banner + navbar + footer) and the page — not the block — owns
|
|
60
|
+
// the viewport. This wrapper is the extracted shell, kept so the shopper-visible
|
|
61
|
+
// result of every auth surface is unchanged. It lives in a derived template
|
|
62
|
+
// (CLI-owned) and stays theme-driven: the backdrop uses the same semantic
|
|
63
|
+
// tokens, so dark mode and any preset resolve here too.
|
|
64
|
+
function AuthCanvas({ stack = false, children }: { stack?: boolean; children: ReactNode }) {
|
|
65
|
+
return (
|
|
66
|
+
<section
|
|
67
|
+
className={`from-background to-muted/50 relative isolate flex min-h-dvh w-full items-center justify-center overflow-hidden bg-linear-to-br ${stack ? 'flex-col' : ''}`}
|
|
68
|
+
>
|
|
69
|
+
<div
|
|
70
|
+
className={`relative z-10 container mx-auto flex min-h-dvh items-center justify-center px-4 py-12 ${stack ? 'flex-col' : ''}`}
|
|
71
|
+
>
|
|
72
|
+
{children}
|
|
73
|
+
</div>
|
|
74
|
+
</section>
|
|
75
|
+
)
|
|
76
|
+
}
|
|
77
|
+
|
|
51
78
|
// Neutral pending surface shown while a cross-tab/foreground reconciliation is
|
|
52
79
|
// in flight (task 4.2). It replaces the previously held identity/orders so no
|
|
53
80
|
// stale private data is presented as current during the server round-trip; it
|
|
@@ -66,43 +93,39 @@ function ReconcilingStatus() {
|
|
|
66
93
|
)
|
|
67
94
|
}
|
|
68
95
|
|
|
69
|
-
// The
|
|
70
|
-
//
|
|
71
|
-
//
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
}
|
|
80
|
-
interface BlockOrder {
|
|
81
|
-
id: string
|
|
82
|
-
date: string
|
|
83
|
-
status: string
|
|
84
|
-
total: string
|
|
85
|
-
items: BlockOrderItem[]
|
|
96
|
+
// Backend order status → badge tone. The status model belongs to the host (the
|
|
97
|
+
// block never compares a status string), so this map is the storefront's own
|
|
98
|
+
// vocabulary; an unknown status keeps the neutral tone and its own label, so no
|
|
99
|
+
// state is invented and no order is mislabelled.
|
|
100
|
+
const ORDER_STATUS_TONES: Record<string, OrderHistoryStatusTone> = {
|
|
101
|
+
pending: 'outline',
|
|
102
|
+
processing: 'secondary',
|
|
103
|
+
completed: 'default',
|
|
104
|
+
cancelled: 'destructive',
|
|
105
|
+
refunded: 'outline',
|
|
86
106
|
}
|
|
87
107
|
|
|
88
|
-
// Map a backend-sourced account order row to the block
|
|
89
|
-
//
|
|
90
|
-
//
|
|
91
|
-
//
|
|
92
|
-
|
|
93
|
-
function toBlockOrder(order: AccountOrderView): BlockOrder {
|
|
108
|
+
// Map a backend-sourced account order row to the canonical block contract.
|
|
109
|
+
// `id` is the REAL backend order id: it is the React key AND the value the block
|
|
110
|
+
// reports, so selection needs no number→id map. Amounts stay canonical `Money`
|
|
111
|
+
// and an absent image/variant is omitted rather than serialized as ''.
|
|
112
|
+
function toOrderHistoryOrder(order: AccountOrderView): OrderHistoryOrder {
|
|
94
113
|
return {
|
|
95
|
-
id: order.
|
|
114
|
+
id: order.id,
|
|
115
|
+
number: order.number,
|
|
96
116
|
date: order.date,
|
|
97
|
-
status:
|
|
117
|
+
status: {
|
|
118
|
+
label: order.status,
|
|
119
|
+
tone: ORDER_STATUS_TONES[order.status] ?? 'secondary',
|
|
120
|
+
},
|
|
98
121
|
total: order.total,
|
|
99
122
|
items: order.items.map((item) => ({
|
|
100
123
|
id: item.id,
|
|
101
124
|
name: item.name,
|
|
102
|
-
image: item.image
|
|
103
|
-
details: item.variant
|
|
104
|
-
price: item.lineTotal,
|
|
125
|
+
...(item.image === undefined ? {} : { image: item.image }),
|
|
126
|
+
...(item.variant === undefined ? {} : { details: item.variant }),
|
|
105
127
|
quantity: item.quantity,
|
|
128
|
+
lineTotal: item.lineTotal,
|
|
106
129
|
})),
|
|
107
130
|
}
|
|
108
131
|
}
|
|
@@ -112,14 +135,20 @@ function toBlockOrder(order: AccountOrderView): BlockOrder {
|
|
|
112
135
|
// the selection so the detail is dismissible (a real open/close cycle, no
|
|
113
136
|
// navigation and no second destination).
|
|
114
137
|
function OrderDetail({ order, onClose }: { order: AccountOrderView; onClose: () => void }) {
|
|
138
|
+
// Amounts are formatted at the display site from their own currency; an
|
|
139
|
+
// amount the backend did not supply (or supplied malformed) renders the
|
|
140
|
+
// unavailable marker, never a fabricated zero.
|
|
141
|
+
const amount = (value: AccountOrderView['total']) => formatMoney(value) ?? '—'
|
|
115
142
|
const totals = (
|
|
116
143
|
[
|
|
117
144
|
{ label: 'Subtotal', value: order.subtotal },
|
|
118
145
|
{ label: 'Impuestos', value: order.tax },
|
|
119
146
|
{ label: 'Envío', value: order.shipping },
|
|
120
147
|
{ label: 'Total', value: order.total },
|
|
121
|
-
] as { label: string; value?:
|
|
122
|
-
).filter(
|
|
148
|
+
] as { label: string; value?: AccountOrderView['total'] }[]
|
|
149
|
+
).filter(
|
|
150
|
+
(row): row is { label: string; value: AccountOrderView['total'] } => row.value !== undefined,
|
|
151
|
+
)
|
|
123
152
|
return (
|
|
124
153
|
<div className="mx-auto w-full max-w-7xl px-4 pb-12 sm:px-6 lg:px-8">
|
|
125
154
|
<div className="rounded-lg border p-6">
|
|
@@ -147,7 +176,7 @@ function OrderDetail({ order, onClose }: { order: AccountOrderView; onClose: ()
|
|
|
147
176
|
) : null}
|
|
148
177
|
<span className="text-muted-foreground"> × {item.quantity}</span>
|
|
149
178
|
</span>
|
|
150
|
-
<span>{item.lineTotal}</span>
|
|
179
|
+
<span>{amount(item.lineTotal)}</span>
|
|
151
180
|
</li>
|
|
152
181
|
))}
|
|
153
182
|
</ul>
|
|
@@ -155,7 +184,7 @@ function OrderDetail({ order, onClose }: { order: AccountOrderView; onClose: ()
|
|
|
155
184
|
{totals.map((row) => (
|
|
156
185
|
<div key={row.label} className="flex justify-between">
|
|
157
186
|
<dt className="text-muted-foreground">{row.label}</dt>
|
|
158
|
-
<dd>{row.value}</dd>
|
|
187
|
+
<dd>{amount(row.value)}</dd>
|
|
159
188
|
</div>
|
|
160
189
|
))}
|
|
161
190
|
</dl>
|
|
@@ -188,26 +217,30 @@ export const registry: ViewRegistry = {
|
|
|
188
217
|
them, and `display: contents` leaves the layout untouched. The
|
|
189
218
|
shared lifecycle also drops a same-tick duplicate before React
|
|
190
219
|
re-renders, so no duplicate request is issued in the interim. */}
|
|
191
|
-
<
|
|
192
|
-
<
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
220
|
+
<AuthCanvas>
|
|
221
|
+
<fieldset disabled={pending} aria-busy={pending} className="contents">
|
|
222
|
+
<LoginPage
|
|
223
|
+
presentation="card"
|
|
224
|
+
logoText={parsed.logoText}
|
|
225
|
+
welcomeTitleLabel={parsed.welcomeTitleLabel}
|
|
226
|
+
welcomeDescriptionLabel={parsed.welcomeDescriptionLabel}
|
|
227
|
+
emailLabel={parsed.emailLabel}
|
|
228
|
+
passwordLabel={parsed.passwordLabel}
|
|
229
|
+
signInLabel={parsed.signInLabel}
|
|
230
|
+
createAccountLabel={parsed.createAccountLabel}
|
|
231
|
+
rememberMeLabel="Recuérdame"
|
|
232
|
+
// The credentials stay in the block's local state and go straight to
|
|
233
|
+
// the shared lifecycle (which calls the Server Action); they are never
|
|
234
|
+
// written to the store. The lifecycle owns pending/error, the
|
|
235
|
+
// generation guard, duplicate prevention, and the server refresh, so
|
|
236
|
+
// the mounted form is never remounted and its input survives a failure.
|
|
237
|
+
onSubmit={(data) => {
|
|
238
|
+
void lifecycle.login({ email: data.email, password: data.password })
|
|
239
|
+
}}
|
|
240
|
+
onCreateAccount={() => emit('showRegister')}
|
|
241
|
+
/>
|
|
242
|
+
</fieldset>
|
|
243
|
+
</AuthCanvas>
|
|
211
244
|
</>
|
|
212
245
|
)
|
|
213
246
|
},
|
|
@@ -222,28 +255,30 @@ export const registry: ViewRegistry = {
|
|
|
222
255
|
<AuthNotice pending={pending} error={error} />
|
|
223
256
|
{/* Same native pending-disable as the login form (the block exposes no
|
|
224
257
|
pending prop); input values persist across a failed mutation. */}
|
|
225
|
-
<
|
|
226
|
-
<
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
258
|
+
<AuthCanvas stack>
|
|
259
|
+
<fieldset disabled={pending} aria-busy={pending} className="contents">
|
|
260
|
+
<SignUpBlock
|
|
261
|
+
logoText={parsed.logoText}
|
|
262
|
+
createAccountTitleLabel={parsed.createAccountTitleLabel}
|
|
263
|
+
createAccountDescriptionLabel={parsed.createAccountDescriptionLabel}
|
|
264
|
+
fullNameLabel={parsed.fullNameLabel}
|
|
265
|
+
emailLabel={parsed.emailLabel}
|
|
266
|
+
passwordLabel={parsed.passwordLabel}
|
|
267
|
+
createAccountLabel={parsed.createAccountLabel}
|
|
268
|
+
signInLabel={parsed.signInLabel}
|
|
269
|
+
onSubmit={(data) => {
|
|
270
|
+
const parts = data.fullName.trim().split(/\s+/).filter(Boolean)
|
|
271
|
+
void lifecycle.register({
|
|
272
|
+
email: data.email,
|
|
273
|
+
password: data.password,
|
|
274
|
+
firstName: parts[0] ?? '',
|
|
275
|
+
lastName: parts.slice(1).join(' '),
|
|
276
|
+
})
|
|
277
|
+
}}
|
|
278
|
+
onSignIn={() => emit('showLogin')}
|
|
279
|
+
/>
|
|
280
|
+
</fieldset>
|
|
281
|
+
</AuthCanvas>
|
|
247
282
|
</>
|
|
248
283
|
)
|
|
249
284
|
},
|
|
@@ -295,12 +330,14 @@ export const registry: ViewRegistry = {
|
|
|
295
330
|
* identity's page lands (a render guard, never the clear mechanism).
|
|
296
331
|
*
|
|
297
332
|
* The backend's real `count` drives pagination, so a page length is never
|
|
298
|
-
* presented as the total
|
|
299
|
-
*
|
|
300
|
-
*
|
|
301
|
-
*
|
|
302
|
-
*
|
|
303
|
-
*
|
|
333
|
+
* presented as the total — the block receives one page and renders exactly it.
|
|
334
|
+
* Selection is keyed by the REAL backend order id, which the canonical
|
|
335
|
+
* `OrderHistory` block reports from `onViewOrder(id)`, and the detail is
|
|
336
|
+
* assembled from the fetched row; the selection id survives paging (returning
|
|
337
|
+
* to the order's page reopens it) and is dismissible with the inline close
|
|
338
|
+
* control. A failed page load shows an actionable retry that re-runs the SAME
|
|
339
|
+
* page (never a fabricated empty history). No token is read, stored, or
|
|
340
|
+
* rendered here.
|
|
304
341
|
*/
|
|
305
342
|
AccountOrders: ({ props }) => {
|
|
306
343
|
const { state, set, getSnapshot } = useStateStore()
|
|
@@ -416,8 +453,14 @@ export const registry: ViewRegistry = {
|
|
|
416
453
|
typeof state.accountSelectedOrderId === 'string' ? state.accountSelectedOrderId : null
|
|
417
454
|
// Selection is keyed by the REAL backend order id, never the display number.
|
|
418
455
|
const selected = selectedId ? orders.find((order) => order.id === selectedId) ?? null : null
|
|
419
|
-
// The block
|
|
420
|
-
|
|
456
|
+
// The canonical block's labels, with the legacy per-key copy (still present in
|
|
457
|
+
// user-owned `content.ts` of an older store) folded in front of them.
|
|
458
|
+
const labels: Partial<OrderHistoryLabels> = {
|
|
459
|
+
...(parsed.labels ?? {}),
|
|
460
|
+
...(parsed.titleLabel === undefined ? {} : { title: parsed.titleLabel }),
|
|
461
|
+
...(parsed.descriptionLabel === undefined ? {} : { description: parsed.descriptionLabel }),
|
|
462
|
+
...(parsed.emptyLabel === undefined ? {} : { emptyLabel: parsed.emptyLabel }),
|
|
463
|
+
}
|
|
421
464
|
|
|
422
465
|
// A reconciliation in flight (task 4.2) hides the held rows rather than
|
|
423
466
|
// presenting them as current. This component stays MOUNTED (its `loadedKeyRef`
|
|
@@ -460,29 +503,17 @@ export const registry: ViewRegistry = {
|
|
|
460
503
|
</div>
|
|
461
504
|
)
|
|
462
505
|
}
|
|
463
|
-
if (orders.length === 0) {
|
|
464
|
-
return (
|
|
465
|
-
<p
|
|
466
|
-
role="status"
|
|
467
|
-
className="text-muted-foreground mx-auto max-w-7xl px-4 py-8 text-sm"
|
|
468
|
-
>
|
|
469
|
-
{parsed.emptyLabel ?? 'Aún no tienes pedidos.'}
|
|
470
|
-
</p>
|
|
471
|
-
)
|
|
472
|
-
}
|
|
473
506
|
const totalPages = Math.max(1, Math.ceil(count / pageSize))
|
|
474
507
|
return (
|
|
475
508
|
<>
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
set('/accountSelectedOrderId', backendIdByBlockId.get(order.id) ?? null)
|
|
485
|
-
}
|
|
509
|
+
{/* The empty history is the block's own state (`labels.emptyLabel`), so
|
|
510
|
+
there is one empty implementation and no fabricated order. Selection
|
|
511
|
+
is reported by backend order id — no number→id map. */}
|
|
512
|
+
<OrderHistory
|
|
513
|
+
orders={orders.map(toOrderHistoryOrder)}
|
|
514
|
+
presentation="cards"
|
|
515
|
+
labels={labels}
|
|
516
|
+
onViewOrder={(id) => set('/accountSelectedOrderId', id)}
|
|
486
517
|
/>
|
|
487
518
|
{count > pageSize ? (
|
|
488
519
|
<div className="mx-auto flex w-full max-w-7xl items-center justify-between gap-4 px-4 pb-6 sm:px-6 lg:px-8">
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
|
|
10
10
|
import { z } from 'zod'
|
|
11
11
|
|
|
12
|
-
// Mirrors the
|
|
12
|
+
// Mirrors the canonical LoginPage optional props. Every prop is optional with a neutral
|
|
13
13
|
// default in the block, so the curated view forwards only the labels it owns.
|
|
14
14
|
export const accountLoginPropsSchema = z.object({
|
|
15
15
|
logoText: z.string().optional(),
|
|
@@ -33,15 +33,35 @@ export const accountRegisterPropsSchema = z.object({
|
|
|
33
33
|
signInLabel: z.string().optional(),
|
|
34
34
|
})
|
|
35
35
|
|
|
36
|
-
// Mirrors the
|
|
37
|
-
// explicit loading/
|
|
36
|
+
// Mirrors the canonical `OrderHistory` label contract the curated view forwards
|
|
37
|
+
// (`labels: Partial<OrderHistoryLabels>`), plus the explicit loading/error copy
|
|
38
|
+
// the registry renders when the block itself cannot be shown. The legacy
|
|
39
|
+
// `titleLabel`/`descriptionLabel`/`emptyLabel` keys are still accepted because
|
|
40
|
+
// `content.ts` is user-owned and survives `sync`; the registry folds them into
|
|
41
|
+
// `labels` instead of dropping a store's copy.
|
|
42
|
+
export const accountOrdersLabelsSchema = z.object({
|
|
43
|
+
title: z.string().optional(),
|
|
44
|
+
description: z.string().optional(),
|
|
45
|
+
orderLabel: z.string().optional(),
|
|
46
|
+
placedOnLabel: z.string().optional(),
|
|
47
|
+
quantityLabel: z.string().optional(),
|
|
48
|
+
totalLabel: z.string().optional(),
|
|
49
|
+
viewOrderLabel: z.string().optional(),
|
|
50
|
+
trackOrderLabel: z.string().optional(),
|
|
51
|
+
amountUnavailableLabel: z.string().optional(),
|
|
52
|
+
emptyLabel: z.string().optional(),
|
|
53
|
+
})
|
|
54
|
+
|
|
38
55
|
export const accountOrdersPropsSchema = z.object({
|
|
56
|
+
labels: accountOrdersLabelsSchema.optional(),
|
|
57
|
+
errorLabel: z.string().optional(),
|
|
58
|
+
loadingLabel: z.string().optional(),
|
|
59
|
+
/** @deprecated Folded into `labels.title`; kept for existing user content. */
|
|
39
60
|
titleLabel: z.string().optional(),
|
|
61
|
+
/** @deprecated Folded into `labels.description`; kept for existing user content. */
|
|
40
62
|
descriptionLabel: z.string().optional(),
|
|
41
|
-
|
|
63
|
+
/** @deprecated Folded into `labels.emptyLabel`; kept for existing user content. */
|
|
42
64
|
emptyLabel: z.string().optional(),
|
|
43
|
-
errorLabel: z.string().optional(),
|
|
44
|
-
loadingLabel: z.string().optional(),
|
|
45
65
|
})
|
|
46
66
|
|
|
47
67
|
// The headless bootstrap and the signed-in panel read their data from the
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"view": "category",
|
|
3
3
|
"slots": [
|
|
4
4
|
{ "id": "category.breadcrumb", "slot": "breadcrumb", "default": "Breadcrumb" },
|
|
5
|
-
{ "id": "category.filter", "slot": "filter", "default": "
|
|
5
|
+
{ "id": "category.filter", "slot": "filter", "default": "CategoryListing" },
|
|
6
6
|
{
|
|
7
7
|
"id": "category.productCard",
|
|
8
8
|
"slot": "productCard",
|
|
@@ -4,10 +4,10 @@
|
|
|
4
4
|
// module imports them as data so the RSC graph never evaluates @json-render/react
|
|
5
5
|
// on the server. Registered by importing it in ../index.ts. Recipe: recipes.json -> "category".
|
|
6
6
|
//
|
|
7
|
-
// E2 task 6.1: the category listing is ONE controlled `
|
|
7
|
+
// E2 task 6.1: the category listing is ONE controlled `CategoryListing` — the
|
|
8
8
|
// base listing slot `category.filter`, always present. The optional
|
|
9
9
|
// `catalog-search` / `category-filters` features are control contributions to
|
|
10
|
-
// that single block (logical mounts `category.search` / `category
|
|
10
|
+
// that single block (logical mounts `category.search` / `category-listing`),
|
|
11
11
|
// never a second listing/controller. Their visibility and config are read from
|
|
12
12
|
// the installed manifest (`mountedFeatures` / `mountedFeatureConfigs`) that
|
|
13
13
|
// `sync` derives from `storefront.config.json`; no loader is hand-edited to add
|
|
@@ -21,7 +21,7 @@ import {
|
|
|
21
21
|
getCollectionOptions,
|
|
22
22
|
loadCategoryListing,
|
|
23
23
|
mapCatalogOutcomeToStatus,
|
|
24
|
-
|
|
24
|
+
mapCatalogResultsToCategoryListing,
|
|
25
25
|
} from '@thorprovider/runtime/commerce'
|
|
26
26
|
import { getDataSource, getStoreContext, isRealMode } from '../../store-context'
|
|
27
27
|
import { mountedFeatureConfigs, mountedFeatureNames, mountedFeatures } from '../../composition'
|
|
@@ -29,10 +29,10 @@ import { pageRoot } from '../../spec/page-root'
|
|
|
29
29
|
import type { StorefrontElement } from '../../spec/types'
|
|
30
30
|
import type { ViewModule } from '../types'
|
|
31
31
|
import { registry } from './registry'
|
|
32
|
-
import { categoryBreadcrumbProps,
|
|
33
|
-
import { breadcrumbPropsSchema,
|
|
32
|
+
import { categoryBreadcrumbProps, categoryListingProps } from './props'
|
|
33
|
+
import { breadcrumbPropsSchema, categoryListingPropsSchema } from './schema'@@SECTION_IMPORTS@@
|
|
34
34
|
|
|
35
|
-
// The single controlled `
|
|
35
|
+
// The single controlled `CategoryListing` base listing. The search/filter
|
|
36
36
|
// controls are shown only when the matching feature is installed; the base
|
|
37
37
|
// listing always owns the route scope, `sort`, `page`, `pageSize`, the products,
|
|
38
38
|
// and pagination.
|
|
@@ -79,6 +79,8 @@ const emptyFilterState = () => ({
|
|
|
79
79
|
categoryFilterCategories: [],
|
|
80
80
|
categoryFilterCollections: [],
|
|
81
81
|
categoryFilterPriceRange: undefined,
|
|
82
|
+
categoryFilterSelectedFacets: {} as Record<string, string[]>,
|
|
83
|
+
categoryFilterFacets: [],
|
|
82
84
|
breadcrumbItems: [] as { label: string; href?: string }[],
|
|
83
85
|
})
|
|
84
86
|
|
|
@@ -197,7 +199,7 @@ export const category: ViewModule = {
|
|
|
197
199
|
}))
|
|
198
200
|
: []
|
|
199
201
|
const collections = allCollections.length > 0 ? allCollections : undefined
|
|
200
|
-
const presentation =
|
|
202
|
+
const presentation = mapCatalogResultsToCategoryListing({
|
|
201
203
|
query: listing.query,
|
|
202
204
|
results: listing.results,
|
|
203
205
|
// A scoped listing (`/categories/<handle>`) must not offer the
|
|
@@ -236,6 +238,8 @@ export const category: ViewModule = {
|
|
|
236
238
|
categoryFilterCategories: presentation.categories ?? [],
|
|
237
239
|
categoryFilterCollections: presentation.collections ?? [],
|
|
238
240
|
categoryFilterPriceRange: presentation.priceRange,
|
|
241
|
+
categoryFilterSelectedFacets: presentation.selectedFacets ?? {},
|
|
242
|
+
categoryFilterFacets: presentation.facets ?? [],
|
|
239
243
|
}
|
|
240
244
|
} catch (error) {
|
|
241
245
|
return {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use client'
|
|
2
2
|
|
|
3
3
|
// Thor Commerce view registry fragment: category
|
|
4
|
-
// The category view's single client boundary: one controlled `
|
|
4
|
+
// The category view's single client boundary: one controlled `CategoryListing`
|
|
5
5
|
// (the base listing slot `category.filter`). Search/filters/sort/pagination are
|
|
6
6
|
// URL-backed: the block emits a change, this registry rewrites the URL through
|
|
7
7
|
// the pure `buildCategoryQueryHref` seam, and the server loader re-seeds the
|
|
@@ -9,12 +9,12 @@
|
|
|
9
9
|
// the client. The search and filter controls are only present because the
|
|
10
10
|
// installed manifest enabled them; the block never adds a second listing.
|
|
11
11
|
|
|
12
|
-
import
|
|
12
|
+
import CategoryListingBlock from '@thorprovider/blocks/blocks/e-commerce/category-filters/category-listing'
|
|
13
13
|
import type {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
} from '@thorprovider/blocks/blocks/e-commerce/category-filters/category-
|
|
14
|
+
CategoryListingActiveFilter,
|
|
15
|
+
CategoryListingFilters,
|
|
16
|
+
CategoryListingProps,
|
|
17
|
+
} from '@thorprovider/blocks/blocks/e-commerce/category-filters/category-listing'
|
|
18
18
|
@@BLOCK_IMPORTS@@@@SECTION_REGISTRY_IMPORTS@@
|
|
19
19
|
import { buildCategoryQueryHref, catalogHistoryMode, type CategoryQueryChange } from '@thorprovider/runtime/commerce'
|
|
20
20
|
import type { CatalogFeatureName } from '@thorprovider/runtime/contracts'
|
|
@@ -23,9 +23,9 @@ import { usePathname, useRouter } from 'next/navigation'
|
|
|
23
23
|
import type { ViewRegistry } from '../types'
|
|
24
24
|
|
|
25
25
|
// The generated view module injects the installed-feature context as an element
|
|
26
|
-
// prop (task 4.11); it is composition context, not a `
|
|
26
|
+
// prop (task 4.11); it is composition context, not a `CategoryListing` prop, so
|
|
27
27
|
// it is read separately from the block props.
|
|
28
|
-
type
|
|
28
|
+
type CategoryListingRegistryProps = CategoryListingProps & {
|
|
29
29
|
mountedFeatures?: readonly CatalogFeatureName[]
|
|
30
30
|
}
|
|
31
31
|
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
'category.filter': {
|
|
2
|
-
type: '
|
|
2
|
+
type: 'CategoryListing',
|
|
3
3
|
props: {
|
|
4
4
|
// User-owned copy first, so a customization can be overridden by the
|
|
5
5
|
// feature config (search placeholder) and the derived state bindings.
|
|
6
|
-
...
|
|
6
|
+
...categoryListingProps,
|
|
7
7
|
showSearch: hasSearch,
|
|
8
8
|
showFilters: hasFilters,
|
|
9
9
|
showSort: true,
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
: {}),
|
|
14
14
|
// Composition context for generated navigation (task 4.11): the client
|
|
15
15
|
// registry drops a removed feature's owned orphan parameters on a UI
|
|
16
|
-
// action. Read separately from the block props; never a `
|
|
16
|
+
// action. Read separately from the block props; never a `CategoryListing`
|
|
17
17
|
// prop and never bound to state.
|
|
18
18
|
mountedFeatures,
|
|
19
19
|
products: { $state: '/categoryFilterProducts' },
|
|
@@ -30,5 +30,7 @@
|
|
|
30
30
|
categories: { $state: '/categoryFilterCategories' },
|
|
31
31
|
collections: { $state: '/categoryFilterCollections' },
|
|
32
32
|
priceRange: { $state: '/categoryFilterPriceRange' },
|
|
33
|
+
selectedFacets: { $state: '/categoryFilterSelectedFacets' },
|
|
34
|
+
facets: { $state: '/categoryFilterFacets' },
|
|
33
35
|
},
|
|
34
36
|
},
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
CategoryListing: ({ props, emit }) => {
|
|
2
2
|
const router = useRouter()
|
|
3
3
|
const pathname = usePathname()
|
|
4
4
|
const { set } = useStateStore()
|
|
5
|
-
const p = props as unknown as
|
|
5
|
+
const p = props as unknown as CategoryListingRegistryProps
|
|
6
6
|
|
|
7
7
|
// Minimal `updateURL` seam (task 6.1; task 5.2 verified the criterion and is
|
|
8
8
|
// complete): apply one change to the current browser URL and let the server
|
|
@@ -24,7 +24,8 @@
|
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
return (
|
|
27
|
-
<
|
|
27
|
+
<CategoryListingBlock
|
|
28
|
+
presentation={p.presentation}
|
|
28
29
|
products={p.products}
|
|
29
30
|
categories={p.categories}
|
|
30
31
|
collections={p.collections}
|
|
@@ -42,6 +43,9 @@
|
|
|
42
43
|
selectedPage={p.selectedPage}
|
|
43
44
|
selectedPageSize={p.selectedPageSize}
|
|
44
45
|
selectedPriceRange={p.selectedPriceRange}
|
|
46
|
+
selectedFacets={p.selectedFacets}
|
|
47
|
+
facets={p.facets}
|
|
48
|
+
viewOptions={p.viewOptions}
|
|
45
49
|
status={p.status}
|
|
46
50
|
activeFilters={p.activeFilters}
|
|
47
51
|
filtersTitle={p.filtersTitle}
|
|
@@ -53,13 +57,13 @@
|
|
|
53
57
|
onSortChange={(sort) => apply({ kind: 'sort', sort })}
|
|
54
58
|
onPageChange={(page) => apply({ kind: 'page', page })}
|
|
55
59
|
onPageSizeChange={(size) => apply({ kind: 'pageSize', pageSize: size })}
|
|
56
|
-
onFilterChange={(filters:
|
|
60
|
+
onFilterChange={(filters: CategoryListingFilters) =>
|
|
57
61
|
apply({ kind: 'filters', categories: filters.categories, collections: filters.collections ?? [] })
|
|
58
62
|
}
|
|
59
63
|
onClearFilters={() => apply({ kind: 'clearFilters' })}
|
|
60
64
|
onRepair={(remove) => apply({ kind: 'repair', remove })}
|
|
61
65
|
onRetry={() => router.refresh()}
|
|
62
|
-
onRemoveFilter={(filter:
|
|
66
|
+
onRemoveFilter={(filter: CategoryListingActiveFilter) =>
|
|
63
67
|
apply({ kind: 'removeFilter', filter })
|
|
64
68
|
}
|
|
65
69
|
onProductClick={(product) => {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Thor Commerce view content: category
|
|
2
2
|
// User-owned view content — listing copy for the single controlled
|
|
3
|
-
// `
|
|
3
|
+
// `CategoryListing`. Reconcile seeds this file once and never rewrites it; the
|
|
4
4
|
// derived view module (./index.tsx) imports it and wires it into the element
|
|
5
5
|
// tree, so your edits here survive `storefront sync` and unit removal. Plain
|
|
6
6
|
// data only: no React and no server imports.
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
// set (`getCatalogSortKeys`), never from assumed global price sorts.
|
|
10
10
|
|
|
11
11
|
export const filterContent = {
|
|
12
|
+
presentation: 'sidebar' as const,
|
|
12
13
|
filtersTitle: 'Filtros',
|
|
13
14
|
searchLabel: 'Buscar',
|
|
14
15
|
searchPlaceholder: 'Buscar productos',
|