@artisanpack-ui/ecommerce-storefront-react 0.0.0-stage → 1.0.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.
Files changed (98) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +67 -2
  3. package/dist/Addresses-D3ESHG3L.mjs +27 -0
  4. package/dist/Addresses-D3ESHG3L.mjs.map +1 -0
  5. package/dist/CategoryShow-OAGROEMA.mjs +12 -0
  6. package/dist/CategoryShow-OAGROEMA.mjs.map +1 -0
  7. package/dist/Claim-CJ4UOAUD.mjs +22 -0
  8. package/dist/Claim-CJ4UOAUD.mjs.map +1 -0
  9. package/dist/Confirmation-TLMMBPWS.mjs +20 -0
  10. package/dist/Confirmation-TLMMBPWS.mjs.map +1 -0
  11. package/dist/Dashboard-ARXORMTL.mjs +24 -0
  12. package/dist/Dashboard-ARXORMTL.mjs.map +1 -0
  13. package/dist/Downloads-CEQBY7JO.mjs +25 -0
  14. package/dist/Downloads-CEQBY7JO.mjs.map +1 -0
  15. package/dist/Index-KRR3Q7EJ.mjs +12 -0
  16. package/dist/Index-KRR3Q7EJ.mjs.map +1 -0
  17. package/dist/Index-RLQFEBTX.mjs +22 -0
  18. package/dist/Index-RLQFEBTX.mjs.map +1 -0
  19. package/dist/Index-WDJYGR5Q.mjs +12 -0
  20. package/dist/Index-WDJYGR5Q.mjs.map +1 -0
  21. package/dist/Index-XYU5QLUT.mjs +23 -0
  22. package/dist/Index-XYU5QLUT.mjs.map +1 -0
  23. package/dist/Lookup-QNUQKUID.mjs +19 -0
  24. package/dist/Lookup-QNUQKUID.mjs.map +1 -0
  25. package/dist/OrderShow-RYTP62YA.mjs +27 -0
  26. package/dist/OrderShow-RYTP62YA.mjs.map +1 -0
  27. package/dist/Orders-LZW57GE6.mjs +25 -0
  28. package/dist/Orders-LZW57GE6.mjs.map +1 -0
  29. package/dist/Profile-ZAAWFCAL.mjs +25 -0
  30. package/dist/Profile-ZAAWFCAL.mjs.map +1 -0
  31. package/dist/Show-LFWUO3KR.mjs +14 -0
  32. package/dist/Show-LFWUO3KR.mjs.map +1 -0
  33. package/dist/TagShow-FXKXRGY2.mjs +12 -0
  34. package/dist/TagShow-FXKXRGY2.mjs.map +1 -0
  35. package/dist/chunk-5UUNH3EH.mjs +1888 -0
  36. package/dist/chunk-5UUNH3EH.mjs.map +1 -0
  37. package/dist/chunk-A3MMQ2RY.mjs +183 -0
  38. package/dist/chunk-A3MMQ2RY.mjs.map +1 -0
  39. package/dist/chunk-ABGPTZ3Q.mjs +198 -0
  40. package/dist/chunk-ABGPTZ3Q.mjs.map +1 -0
  41. package/dist/chunk-BJ3FJFZQ.mjs +32 -0
  42. package/dist/chunk-BJ3FJFZQ.mjs.map +1 -0
  43. package/dist/chunk-BSASRFQ7.mjs +89 -0
  44. package/dist/chunk-BSASRFQ7.mjs.map +1 -0
  45. package/dist/chunk-CGCW3555.mjs +148 -0
  46. package/dist/chunk-CGCW3555.mjs.map +1 -0
  47. package/dist/chunk-DWR23FJD.mjs +643 -0
  48. package/dist/chunk-DWR23FJD.mjs.map +1 -0
  49. package/dist/chunk-ENY3MH2W.mjs +148 -0
  50. package/dist/chunk-ENY3MH2W.mjs.map +1 -0
  51. package/dist/chunk-EWJLRWPO.mjs +280 -0
  52. package/dist/chunk-EWJLRWPO.mjs.map +1 -0
  53. package/dist/chunk-FL5XL3ET.mjs +212 -0
  54. package/dist/chunk-FL5XL3ET.mjs.map +1 -0
  55. package/dist/chunk-FOOP6UK3.mjs +218 -0
  56. package/dist/chunk-FOOP6UK3.mjs.map +1 -0
  57. package/dist/chunk-HCC7GTVO.mjs +115 -0
  58. package/dist/chunk-HCC7GTVO.mjs.map +1 -0
  59. package/dist/chunk-HXZMY3GE.mjs +2331 -0
  60. package/dist/chunk-HXZMY3GE.mjs.map +1 -0
  61. package/dist/chunk-IOL2YQ62.mjs +109 -0
  62. package/dist/chunk-IOL2YQ62.mjs.map +1 -0
  63. package/dist/chunk-JH7SFSZA.mjs +104 -0
  64. package/dist/chunk-JH7SFSZA.mjs.map +1 -0
  65. package/dist/chunk-JJOPX4PI.mjs +205 -0
  66. package/dist/chunk-JJOPX4PI.mjs.map +1 -0
  67. package/dist/chunk-LT3GG7YQ.mjs +32 -0
  68. package/dist/chunk-LT3GG7YQ.mjs.map +1 -0
  69. package/dist/chunk-MZFULGDI.mjs +267 -0
  70. package/dist/chunk-MZFULGDI.mjs.map +1 -0
  71. package/dist/chunk-O4WPMMSH.mjs +58 -0
  72. package/dist/chunk-O4WPMMSH.mjs.map +1 -0
  73. package/dist/chunk-OU3WYFIH.mjs +397 -0
  74. package/dist/chunk-OU3WYFIH.mjs.map +1 -0
  75. package/dist/chunk-P3NIV4YG.mjs +998 -0
  76. package/dist/chunk-P3NIV4YG.mjs.map +1 -0
  77. package/dist/chunk-PEBBSZ5R.mjs +201 -0
  78. package/dist/chunk-PEBBSZ5R.mjs.map +1 -0
  79. package/dist/chunk-T5OWL6EG.mjs +73 -0
  80. package/dist/chunk-T5OWL6EG.mjs.map +1 -0
  81. package/dist/chunk-THPUK35U.mjs +132 -0
  82. package/dist/chunk-THPUK35U.mjs.map +1 -0
  83. package/dist/chunk-TPOKMH5E.mjs +142 -0
  84. package/dist/chunk-TPOKMH5E.mjs.map +1 -0
  85. package/dist/chunk-VX5TEJNU.mjs +1898 -0
  86. package/dist/chunk-VX5TEJNU.mjs.map +1 -0
  87. package/dist/chunk-WUL34MB2.mjs +268 -0
  88. package/dist/chunk-WUL34MB2.mjs.map +1 -0
  89. package/dist/chunk-WYGOMIZK.mjs +140 -0
  90. package/dist/chunk-WYGOMIZK.mjs.map +1 -0
  91. package/dist/chunk-Y2IOBBN7.mjs +127 -0
  92. package/dist/chunk-Y2IOBBN7.mjs.map +1 -0
  93. package/dist/chunk-Y5BRPEHA.mjs +54 -0
  94. package/dist/chunk-Y5BRPEHA.mjs.map +1 -0
  95. package/dist/index.d.ts +4607 -0
  96. package/dist/index.mjs +1515 -0
  97. package/dist/index.mjs.map +1 -0
  98. package/package.json +112 -4
@@ -0,0 +1,998 @@
1
+ import {
2
+ Swatches
3
+ } from "./chunk-IOL2YQ62.mjs";
4
+ import {
5
+ ProductCard
6
+ } from "./chunk-ABGPTZ3Q.mjs";
7
+ import {
8
+ useStorefrontRouter
9
+ } from "./chunk-TPOKMH5E.mjs";
10
+ import {
11
+ EmptyState,
12
+ cx,
13
+ useStorefront
14
+ } from "./chunk-VX5TEJNU.mjs";
15
+
16
+ // src/components/PriceRange.tsx
17
+ import { __ } from "@artisanpack-ui/ecommerce-storefront-core";
18
+ import { Input, Range } from "@artisanpack-ui/react";
19
+ import { useEffect, useRef, useState } from "react";
20
+ import { jsx, jsxs } from "react/jsx-runtime";
21
+ function PriceRange({
22
+ range,
23
+ label = null,
24
+ idPrefix = "ec-price-range",
25
+ onValueChange,
26
+ debounce = 400,
27
+ className
28
+ }) {
29
+ const { min, max, step, divisor, decimals, currency, symbol } = range;
30
+ const [bounds, setBounds] = useState({ from: range.from, to: range.to });
31
+ const timer = useRef(void 0);
32
+ const root = useRef(null);
33
+ const latestOnValueChange = useRef(onValueChange);
34
+ useEffect(() => {
35
+ latestOnValueChange.current = onValueChange;
36
+ });
37
+ const [typed, setTyped] = useState({
38
+ from: null,
39
+ to: null
40
+ });
41
+ const [given, setGiven] = useState({ from: range.from, to: range.to });
42
+ if (given.from !== range.from || given.to !== range.to) {
43
+ setGiven({ from: range.from, to: range.to });
44
+ setBounds({ from: range.from, to: range.to });
45
+ }
46
+ useEffect(() => () => clearTimeout(timer.current), []);
47
+ const low = Math.min(max, Math.max(min, bounds.from ?? min));
48
+ const high = Math.max(low, Math.min(max, bounds.to ?? max));
49
+ const major = (amount) => (amount / divisor).toFixed(decimals);
50
+ const money = (amount) => {
51
+ try {
52
+ return new Intl.NumberFormat(document.documentElement.lang || void 0, {
53
+ style: "currency",
54
+ currency
55
+ }).format(amount / divisor);
56
+ } catch {
57
+ return String(amount / divisor);
58
+ }
59
+ };
60
+ useEffect(() => {
61
+ root.current?.querySelectorAll("input[data-thumb]").forEach((thumb) => {
62
+ thumb.setAttribute("aria-valuetext", money("start" === thumb.dataset.thumb ? low : high));
63
+ });
64
+ });
65
+ const send = (next) => {
66
+ clearTimeout(timer.current);
67
+ timer.current = setTimeout(() => latestOnValueChange.current?.(next), debounce);
68
+ };
69
+ const update = (next) => {
70
+ setBounds(next);
71
+ send(next);
72
+ };
73
+ const fromValue = (value) => {
74
+ const clamped = Math.max(min, Math.min(value, high));
75
+ return clamped <= min ? null : clamped;
76
+ };
77
+ const toValue = (value) => {
78
+ const clamped = Math.min(max, Math.max(value, low));
79
+ return clamped >= max ? null : clamped;
80
+ };
81
+ const settle = (bound) => {
82
+ const raw = typed[bound];
83
+ setTyped((current) => ({ ...current, [bound]: null }));
84
+ if (null === raw) {
85
+ return;
86
+ }
87
+ const amount = Number.parseFloat(raw.replace(",", "."));
88
+ if (!Number.isFinite(amount)) {
89
+ return;
90
+ }
91
+ const minor = min + Math.round((amount * divisor - min) / step) * step;
92
+ update(
93
+ "from" === bound ? { from: fromValue(minor), to: bounds.to } : { from: bounds.from, to: toValue(minor) }
94
+ );
95
+ };
96
+ const input = (bound) => /* @__PURE__ */ jsx(
97
+ Input,
98
+ {
99
+ id: `${idPrefix}-${"from" === bound ? "min" : "max"}`,
100
+ type: "number",
101
+ inputMode: "decimal",
102
+ size: "sm",
103
+ prefix: symbol,
104
+ min: min / divisor,
105
+ max: max / divisor,
106
+ step: step / divisor,
107
+ "aria-label": "from" === bound ? __("Lowest price") : __("Highest price"),
108
+ value: typed[bound] ?? major("from" === bound ? low : high),
109
+ className: "ec-price-range__input",
110
+ onValueChange: (value) => setTyped((current) => ({ ...current, [bound]: value })),
111
+ onBlur: () => settle(bound),
112
+ onKeyDown: (event) => {
113
+ if ("Enter" === event.key) {
114
+ event.preventDefault();
115
+ settle(bound);
116
+ }
117
+ },
118
+ ..."from" === bound ? { "data-price-min": "" } : { "data-price-max": "" }
119
+ }
120
+ );
121
+ return /* @__PURE__ */ jsxs("fieldset", { ref: root, className: cx("ec-price-range", className), "data-price-range": "", children: [
122
+ null !== label ? /* @__PURE__ */ jsx("legend", { id: `${idPrefix}-legend`, className: "ec-price-range__legend", children: label }) : null,
123
+ /* @__PURE__ */ jsx(
124
+ Range,
125
+ {
126
+ dual: true,
127
+ showValue: "never",
128
+ min,
129
+ max,
130
+ step,
131
+ value: [low, high],
132
+ thumbLabels: { start: __("Lowest price"), end: __("Highest price") },
133
+ "aria-labelledby": null !== label ? `${idPrefix}-legend` : void 0,
134
+ id: `${idPrefix}-range`,
135
+ className: "ec-price-range__slider",
136
+ onValueChange: (value) => {
137
+ const [start, end] = Array.isArray(value) ? value : [min, value];
138
+ update({ from: fromValue(start ?? min), to: toValue(end ?? max) });
139
+ },
140
+ "data-price-slider": ""
141
+ }
142
+ ),
143
+ /* @__PURE__ */ jsxs("div", { className: "ec-price-range__inputs", children: [
144
+ input("from"),
145
+ /* @__PURE__ */ jsx("span", { className: "ec-price-range__to", "aria-hidden": "true", children: __("to") }),
146
+ input("to")
147
+ ] })
148
+ ] });
149
+ }
150
+
151
+ // src/catalog/listingState.ts
152
+ function append(pairs, key, value) {
153
+ if (null === value || void 0 === value) {
154
+ return;
155
+ }
156
+ if (Array.isArray(value)) {
157
+ value.forEach((item, index) => append(pairs, `${key}[${index}]`, item));
158
+ return;
159
+ }
160
+ if ("object" === typeof value) {
161
+ for (const [child, item] of Object.entries(value)) {
162
+ append(pairs, `${key}[${child}]`, item);
163
+ }
164
+ return;
165
+ }
166
+ pairs.push(`${encodeURIComponent(key)}=${encodeURIComponent(String(value))}`);
167
+ }
168
+ function buildQuery(query) {
169
+ const pairs = [];
170
+ for (const [key, value] of Object.entries(query)) {
171
+ append(pairs, key, value);
172
+ }
173
+ return pairs.join("&");
174
+ }
175
+ function listingUrl(base, query) {
176
+ const search = buildQuery(query);
177
+ return "" === search ? base : `${base}?${search}`;
178
+ }
179
+ function choiceValue(state, group) {
180
+ switch (group.type) {
181
+ case "category":
182
+ return state.category ?? "";
183
+ case "tag":
184
+ return state.tag ?? "";
185
+ case "rating":
186
+ return String(state.rating ?? 0);
187
+ default:
188
+ return "";
189
+ }
190
+ }
191
+ function optionValues(state, group) {
192
+ if ("attribute" === group.type) {
193
+ return state.attr?.[group.attribute ?? group.key.replace(/^attr\./, "")] ?? [];
194
+ }
195
+ if ("custom-options" === group.type) {
196
+ const value = state.f?.[group.key];
197
+ return Array.isArray(value) ? value : [];
198
+ }
199
+ return [];
200
+ }
201
+ function toggleValue(state, group) {
202
+ if ("toggle" === group.type) {
203
+ return "1" === state[group.key];
204
+ }
205
+ if ("custom-toggle" === group.type) {
206
+ return "1" === state.f?.[group.key];
207
+ }
208
+ return false;
209
+ }
210
+ function tidy(state) {
211
+ const next = { ...state };
212
+ if (void 0 !== next.attr && 0 === Object.keys(next.attr).length) {
213
+ delete next.attr;
214
+ }
215
+ if (void 0 !== next.f && 0 === Object.keys(next.f).length) {
216
+ delete next.f;
217
+ }
218
+ return next;
219
+ }
220
+ function withChoice(state, group, value) {
221
+ const next = { ...state };
222
+ if ("category" === group.type || "tag" === group.type) {
223
+ if ("" === value) {
224
+ delete next[group.type];
225
+ } else {
226
+ next[group.type] = value;
227
+ }
228
+ } else if ("rating" === group.type) {
229
+ const stars = Number.parseInt(value, 10);
230
+ if (Number.isFinite(stars) && stars > 0) {
231
+ next.rating = stars;
232
+ } else {
233
+ delete next.rating;
234
+ }
235
+ }
236
+ return next;
237
+ }
238
+ function withOption(state, group, value, checked) {
239
+ const current = optionValues(state, group).filter((item) => item !== value);
240
+ const values = checked ? [...current, value] : current;
241
+ if ("attribute" === group.type) {
242
+ const key = group.attribute ?? group.key.replace(/^attr\./, "");
243
+ const attr = { ...state.attr ?? {} };
244
+ if (0 === values.length) {
245
+ delete attr[key];
246
+ } else {
247
+ attr[key] = values;
248
+ }
249
+ return tidy({ ...state, attr });
250
+ }
251
+ if ("custom-options" === group.type) {
252
+ const f = { ...state.f ?? {} };
253
+ if (0 === values.length) {
254
+ delete f[group.key];
255
+ } else {
256
+ f[group.key] = values;
257
+ }
258
+ return tidy({ ...state, f });
259
+ }
260
+ return state;
261
+ }
262
+ function withToggle(state, group, on) {
263
+ if ("toggle" === group.type) {
264
+ const next = { ...state };
265
+ if (on) {
266
+ next[group.key] = "1";
267
+ } else {
268
+ delete next[group.key];
269
+ }
270
+ return next;
271
+ }
272
+ if ("custom-toggle" === group.type) {
273
+ const f = { ...state.f ?? {} };
274
+ if (on) {
275
+ f[group.key] = "1";
276
+ } else {
277
+ delete f[group.key];
278
+ }
279
+ return tidy({ ...state, f });
280
+ }
281
+ return state;
282
+ }
283
+ function withPrice(state, from, to, currency) {
284
+ const next = { ...state };
285
+ delete next.price_min;
286
+ delete next.price_max;
287
+ delete next.price_currency;
288
+ if (null !== from) {
289
+ next.price_min = from;
290
+ }
291
+ if (null !== to) {
292
+ next.price_max = to;
293
+ }
294
+ if (null !== from || null !== to) {
295
+ next.price_currency = currency;
296
+ }
297
+ return next;
298
+ }
299
+
300
+ // src/catalog/CatalogFilters.tsx
301
+ import {
302
+ __ as __2,
303
+ subunit
304
+ } from "@artisanpack-ui/ecommerce-storefront-core";
305
+ import { Toggle } from "@artisanpack-ui/react";
306
+ import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
307
+ function idFragment(key) {
308
+ return key.replace(/[^A-Za-z0-9_-]/g, "-");
309
+ }
310
+ function currencySymbol(currency, locale) {
311
+ try {
312
+ const lang = void 0 === locale || "" === locale ? void 0 : locale.replace("_", "-");
313
+ return new Intl.NumberFormat(lang, { style: "currency", currency }).formatToParts(0).find((part) => "currency" === part.type)?.value ?? currency;
314
+ } catch {
315
+ return currency;
316
+ }
317
+ }
318
+ function priceRangeFor(group, locale) {
319
+ let decimals = 2;
320
+ try {
321
+ decimals = subunit(group.currency);
322
+ } catch {
323
+ decimals = 2;
324
+ }
325
+ return {
326
+ min: group.min,
327
+ max: group.max,
328
+ step: group.step,
329
+ from: group.from,
330
+ to: group.to,
331
+ currency: group.currency,
332
+ decimals,
333
+ divisor: 10 ** decimals,
334
+ symbol: currencySymbol(group.currency, locale)
335
+ };
336
+ }
337
+ function swatchFor(option, selected) {
338
+ return {
339
+ value: option.value,
340
+ label: option.label,
341
+ color: option.color ?? null,
342
+ image: option.image ?? null,
343
+ count: option.count,
344
+ meta: null,
345
+ selected,
346
+ disabled: option.disabled,
347
+ soldOut: false,
348
+ reason: null
349
+ };
350
+ }
351
+ function ChoiceGroup({
352
+ group,
353
+ groupId,
354
+ value,
355
+ onChoice
356
+ }) {
357
+ const rating = "rating" === group.type;
358
+ const options = [
359
+ {
360
+ value: rating ? "0" : "",
361
+ label: rating ? __2("All ratings") : __2("All"),
362
+ count: null,
363
+ selected: false,
364
+ disabled: false,
365
+ depth: 0
366
+ },
367
+ ...group.options
368
+ ];
369
+ return /* @__PURE__ */ jsxs2(
370
+ "fieldset",
371
+ {
372
+ className: "apui-radio-group ec-filters__options",
373
+ id: groupId,
374
+ "data-orientation": "vertical",
375
+ "data-variant": "default",
376
+ children: [
377
+ /* @__PURE__ */ jsx2("legend", { "data-scope": "radio-group", "data-part": "label", className: "ec-filters__legend", children: group.label }),
378
+ /* @__PURE__ */ jsx2("div", { "data-scope": "radio-group", "data-part": "items", children: options.map((option, index) => /* @__PURE__ */ jsxs2(
379
+ "label",
380
+ {
381
+ "data-scope": "radio-group",
382
+ "data-part": "item",
383
+ className: "ec-filters__option",
384
+ "data-depth": Math.min(4, Math.max(0, Math.trunc(option.depth ?? 0))),
385
+ "data-disabled": option.disabled ? "" : void 0,
386
+ children: [
387
+ /* @__PURE__ */ jsxs2("span", { "data-scope": "radio-group", "data-part": "box", children: [
388
+ /* @__PURE__ */ jsx2(
389
+ "input",
390
+ {
391
+ type: "radio",
392
+ "data-scope": "radio-group",
393
+ "data-part": "control",
394
+ id: `${groupId}-${index}`,
395
+ name: groupId,
396
+ value: option.value,
397
+ checked: value === option.value,
398
+ disabled: option.disabled,
399
+ onChange: () => onChoice(group, option.value)
400
+ }
401
+ ),
402
+ /* @__PURE__ */ jsx2("span", { "data-scope": "radio-group", "data-part": "indicator", "aria-hidden": "true" })
403
+ ] }),
404
+ /* @__PURE__ */ jsx2("span", { "data-scope": "radio-group", "data-part": "item-text", children: option.label }),
405
+ null !== option.count ? /* @__PURE__ */ jsx2("span", { "data-scope": "radio-group", "data-part": "item-meta", className: "ec-filters__count", children: option.count }) : null
406
+ ]
407
+ },
408
+ `${groupId}-${option.value}`
409
+ )) })
410
+ ]
411
+ }
412
+ );
413
+ }
414
+ function CatalogFilters({
415
+ groups,
416
+ state,
417
+ idPrefix,
418
+ onChoice,
419
+ onOption,
420
+ onToggle,
421
+ onPrice
422
+ }) {
423
+ const { locale } = useStorefront();
424
+ const control = (group, groupId) => {
425
+ switch (group.type) {
426
+ case "category":
427
+ case "tag":
428
+ case "rating":
429
+ return /* @__PURE__ */ jsx2(
430
+ ChoiceGroup,
431
+ {
432
+ group,
433
+ groupId,
434
+ value: choiceValue(state, group),
435
+ onChoice
436
+ }
437
+ );
438
+ case "price":
439
+ return /* @__PURE__ */ jsx2(
440
+ PriceRange,
441
+ {
442
+ range: priceRangeFor(
443
+ {
444
+ ...group,
445
+ from: state.price_min ?? null,
446
+ to: state.price_max ?? null
447
+ },
448
+ locale
449
+ ),
450
+ label: group.label,
451
+ idPrefix: groupId,
452
+ onValueChange: (value) => onPrice(group, value)
453
+ }
454
+ );
455
+ case "attribute":
456
+ case "custom-options":
457
+ return /* @__PURE__ */ jsx2(
458
+ Swatches,
459
+ {
460
+ name: groupId,
461
+ legend: group.label,
462
+ options: group.options.map(
463
+ (option) => swatchFor(option, optionValues(state, group).includes(option.value))
464
+ ),
465
+ multiple: true,
466
+ idPrefix: groupId,
467
+ onValueChange: (value, checked) => onOption(group, value, checked)
468
+ }
469
+ );
470
+ default:
471
+ return /* @__PURE__ */ jsx2(
472
+ Toggle,
473
+ {
474
+ id: groupId,
475
+ label: null === group.count ? group.label : __2(":label (:count)", { label: group.label, count: group.count }),
476
+ size: "sm",
477
+ checked: toggleValue(state, group),
478
+ onCheckedChange: (on) => onToggle(group, on),
479
+ disabled: group.disabled,
480
+ className: "ec-filters__toggle"
481
+ }
482
+ );
483
+ }
484
+ };
485
+ return /* @__PURE__ */ jsx2("div", { className: "ec-filters", "data-catalog-filters": idPrefix, children: groups.map((group) => {
486
+ const groupId = `${idPrefix}-${idFragment(group.key)}`;
487
+ return /* @__PURE__ */ jsx2("div", { className: "ec-filters__group", "data-filter-group": group.key, children: control(group, groupId) }, groupId);
488
+ }) });
489
+ }
490
+
491
+ // src/catalog/useQuickAdd.ts
492
+ import { useState as useState2 } from "react";
493
+ function useQuickAdd(url) {
494
+ const [pending, setPending] = useState2(null);
495
+ const visits = useStorefrontRouter();
496
+ return {
497
+ pending,
498
+ add: (card) => {
499
+ if (null === url || null !== pending) {
500
+ return;
501
+ }
502
+ visits.post(
503
+ url,
504
+ { product_id: card.id },
505
+ {
506
+ preserveScroll: true,
507
+ preserveState: true,
508
+ onStart: () => setPending(card.id),
509
+ onFinish: () => setPending(null)
510
+ }
511
+ );
512
+ }
513
+ };
514
+ }
515
+
516
+ // src/catalog/CatalogListing.tsx
517
+ import {
518
+ __ as __3,
519
+ trans_choice
520
+ } from "@artisanpack-ui/ecommerce-storefront-core";
521
+ import {
522
+ Button,
523
+ Card,
524
+ Drawer,
525
+ Icon,
526
+ Link,
527
+ Pagination,
528
+ Select,
529
+ Skeleton
530
+ } from "@artisanpack-ui/react";
531
+ import { useEffect as useEffect2, useRef as useRef2, useState as useState3 } from "react";
532
+ import { Fragment, jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
533
+ function sameState(a, b) {
534
+ return listingUrl("", a) === listingUrl("", b);
535
+ }
536
+ function CatalogListing({
537
+ listing,
538
+ resultsLabel,
539
+ emptyState = null,
540
+ browseUrl = null,
541
+ debounce = 300,
542
+ loading = false
543
+ }) {
544
+ const [draft, setDraft] = useState3(listing.state);
545
+ const [given, setGiven] = useState3(listing.state);
546
+ const [busy, setBusy] = useState3(false);
547
+ const [drawerOpen, setDrawerOpen] = useState3(false);
548
+ const timer = useRef2(void 0);
549
+ const busyTimer = useRef2(void 0);
550
+ const focusAfter = useRef2(null);
551
+ const root = useRef2(null);
552
+ const filtersButton = useRef2(null);
553
+ const drawer = useRef2(null);
554
+ const [drawerId, setDrawerId] = useState3(void 0);
555
+ const quickAdd = useQuickAdd(listing.addToCartUrl);
556
+ const visits = useStorefrontRouter();
557
+ const latestDraft = useRef2(draft);
558
+ if (!sameState(given, listing.state)) {
559
+ setGiven(listing.state);
560
+ setDraft(listing.state);
561
+ }
562
+ useEffect2(() => {
563
+ latestDraft.current = draft;
564
+ }, [draft]);
565
+ useEffect2(
566
+ () => () => {
567
+ clearTimeout(timer.current);
568
+ clearTimeout(busyTimer.current);
569
+ },
570
+ []
571
+ );
572
+ useEffect2(() => {
573
+ setDrawerId(drawer.current?.id || void 0);
574
+ }, [drawerOpen]);
575
+ useEffect2(() => {
576
+ const target = focusAfter.current;
577
+ if (null === target || null === root.current) {
578
+ return;
579
+ }
580
+ focusAfter.current = null;
581
+ if (null !== document.activeElement && document.body !== document.activeElement) {
582
+ return;
583
+ }
584
+ const chips = Array.from(root.current.querySelectorAll("[data-active-filter]"));
585
+ let next = null;
586
+ if ("apply" === target) {
587
+ next = document.querySelector("[data-filters-apply]");
588
+ } else if ("number" === typeof target && chips.length > 0) {
589
+ next = chips[Math.min(target, chips.length - 1)] ?? null;
590
+ }
591
+ (next ?? root.current.querySelector("[data-results-count]"))?.focus();
592
+ }, [listing]);
593
+ const visit = (url, focus = null) => {
594
+ clearTimeout(timer.current);
595
+ focusAfter.current = focus;
596
+ visits.get(
597
+ url,
598
+ {},
599
+ {
600
+ preserveState: true,
601
+ preserveScroll: true,
602
+ onStart: () => {
603
+ clearTimeout(busyTimer.current);
604
+ busyTimer.current = setTimeout(() => setBusy(true), 200);
605
+ },
606
+ onFinish: () => {
607
+ clearTimeout(busyTimer.current);
608
+ setBusy(false);
609
+ }
610
+ }
611
+ );
612
+ };
613
+ const change = (next) => {
614
+ latestDraft.current = next;
615
+ setDraft(next);
616
+ clearTimeout(timer.current);
617
+ timer.current = setTimeout(() => visit(listingUrl(listing.urls.base, next)), debounce);
618
+ };
619
+ const filters = {
620
+ onChoice: (group, value) => change(withChoice(latestDraft.current, group, value)),
621
+ onOption: (group, value, checked) => change(withOption(latestDraft.current, group, value, checked)),
622
+ onToggle: (group, on) => change(withToggle(latestDraft.current, group, on)),
623
+ // The price range already waits for the shopper to stop.
624
+ onPrice: (_group, value) => {
625
+ const next = withPrice(latestDraft.current, value.from, value.to, listing.currency);
626
+ latestDraft.current = next;
627
+ setDraft(next);
628
+ visit(listingUrl(listing.urls.base, next));
629
+ }
630
+ };
631
+ const clearFilters = (focus) => visit(listing.urls.clear, focus);
632
+ const hasFilters = listing.groups.length > 0;
633
+ const activeCount = listing.activeFilters.length;
634
+ const total = listing.total;
635
+ const products = listing.products;
636
+ const headingLevel = null !== listing.heading ? 3 : 2;
637
+ const label = resultsLabel ?? trans_choice(":count product|:count products", total, { count: total });
638
+ const card = (product) => /* @__PURE__ */ jsx3(
639
+ ProductCard,
640
+ {
641
+ card: { ...product, headingLevel },
642
+ onQuickAdd: quickAdd.add,
643
+ quickAddPending: quickAdd.pending === product.id
644
+ }
645
+ );
646
+ const filterGroups = (idPrefix) => /* @__PURE__ */ jsx3(CatalogFilters, { groups: listing.groups, state: draft, idPrefix, ...filters });
647
+ return /* @__PURE__ */ jsxs3(
648
+ "section",
649
+ {
650
+ ref: root,
651
+ className: "ec-catalog",
652
+ "data-ecommerce-catalog": "",
653
+ "aria-labelledby": null !== listing.heading ? "ecommerce-catalog-heading" : void 0,
654
+ "aria-label": null === listing.heading ? __3("Products") : void 0,
655
+ children: [
656
+ null !== listing.heading ? /* @__PURE__ */ jsx3("h2", { id: "ecommerce-catalog-heading", className: "ec-catalog__title", children: listing.heading }) : null,
657
+ /* @__PURE__ */ jsxs3("div", { className: "ec-catalog__layout", "data-with-filters": hasFilters ? "" : void 0, children: [
658
+ hasFilters ? /* @__PURE__ */ jsxs3(
659
+ "section",
660
+ {
661
+ className: "ec-catalog__sidebar",
662
+ "aria-labelledby": "ecommerce-catalog-filters-heading",
663
+ "data-filters-sidebar": "",
664
+ children: [
665
+ /* @__PURE__ */ jsxs3("div", { className: "ec-catalog__sidebar-header", children: [
666
+ /* @__PURE__ */ jsx3("h2", { id: "ecommerce-catalog-filters-heading", className: "ec-catalog__sidebar-title", children: __3("Filters") }),
667
+ 0 !== activeCount ? /* @__PURE__ */ jsx3(
668
+ Link,
669
+ {
670
+ href: listing.urls.clear,
671
+ onClick: (event) => {
672
+ event.preventDefault();
673
+ clearFilters("count");
674
+ },
675
+ "data-sidebar-clear-filters": "",
676
+ children: __3("Clear all")
677
+ }
678
+ ) : null
679
+ ] }),
680
+ filterGroups("ecommerce-filters-sidebar")
681
+ ]
682
+ }
683
+ ) : null,
684
+ /* @__PURE__ */ jsxs3("div", { className: "ec-catalog__main", children: [
685
+ /* @__PURE__ */ jsxs3("div", { className: "ec-catalog__toolbar", children: [
686
+ /* @__PURE__ */ jsx3(
687
+ "p",
688
+ {
689
+ className: "ec-catalog__count",
690
+ role: "status",
691
+ "aria-live": "polite",
692
+ "aria-atomic": "true",
693
+ tabIndex: -1,
694
+ "data-results-count": "",
695
+ children: label
696
+ }
697
+ ),
698
+ /* @__PURE__ */ jsxs3("div", { className: "ec-catalog__controls", children: [
699
+ hasFilters ? /* @__PURE__ */ jsx3("div", { className: "ec-catalog__filters-button", children: /* @__PURE__ */ jsx3(
700
+ Button,
701
+ {
702
+ ref: filtersButton,
703
+ variant: "outline",
704
+ color: "neutral",
705
+ size: "sm",
706
+ leadingIcon: "sliders-horizontal",
707
+ "aria-haspopup": "dialog",
708
+ "aria-controls": drawerId,
709
+ onClick: () => setDrawerOpen(true),
710
+ "data-filters-open": "",
711
+ children: 0 === activeCount ? __3("Filters") : __3("Filters (:count)", { count: activeCount })
712
+ }
713
+ ) }) : null,
714
+ total > 0 ? /* @__PURE__ */ jsxs3(Fragment, { children: [
715
+ /* @__PURE__ */ jsx3(
716
+ Select,
717
+ {
718
+ placeholder: "",
719
+ id: "ecommerce-catalog-sort",
720
+ label: __3("Sort by"),
721
+ options: listing.sorts,
722
+ value: listing.sort,
723
+ onValueChange: (value) => visit(listingUrl(listing.urls.base, { ...draft, sort: String(value) })),
724
+ size: "sm",
725
+ className: "ec-catalog__select ec-catalog__sort"
726
+ }
727
+ ),
728
+ /* @__PURE__ */ jsx3(
729
+ Select,
730
+ {
731
+ placeholder: "",
732
+ id: "ecommerce-catalog-per-page",
733
+ label: __3("Per page"),
734
+ options: listing.perPageValues.map((value) => ({
735
+ value: String(value),
736
+ label: String(value)
737
+ })),
738
+ value: String(listing.perPage),
739
+ onValueChange: (value) => visit(
740
+ listingUrl(listing.urls.base, {
741
+ ...draft,
742
+ per_page: Number.parseInt(String(value), 10)
743
+ })
744
+ ),
745
+ size: "sm",
746
+ className: "ec-catalog__select ec-catalog__per-page"
747
+ }
748
+ )
749
+ ] }) : null
750
+ ] })
751
+ ] }),
752
+ 0 !== activeCount ? /* @__PURE__ */ jsxs3(
753
+ "div",
754
+ {
755
+ className: "ec-catalog__chips",
756
+ role: "group",
757
+ "aria-label": __3("Active filters"),
758
+ "data-active-filters": "",
759
+ children: [
760
+ listing.activeFilters.map((filter, index) => /* @__PURE__ */ jsxs3(
761
+ "button",
762
+ {
763
+ type: "button",
764
+ className: "ec-chip",
765
+ "data-variant": "filter",
766
+ "aria-label": __3("Remove filter: :filter", { filter: filter.label }),
767
+ onClick: () => visit(filter.removeUrl, index),
768
+ "data-active-filter": filter.group,
769
+ children: [
770
+ /* @__PURE__ */ jsx3("span", { children: filter.label }),
771
+ /* @__PURE__ */ jsx3(Icon, { name: "x", className: "ec-chip__icon", "aria-hidden": "true" })
772
+ ]
773
+ },
774
+ `${filter.group}-${filter.value ?? ""}`
775
+ )),
776
+ /* @__PURE__ */ jsx3(
777
+ Button,
778
+ {
779
+ variant: "ghost",
780
+ color: "neutral",
781
+ size: "sm",
782
+ onClick: () => clearFilters("count"),
783
+ "data-clear-filters": "",
784
+ children: __3("Clear all")
785
+ }
786
+ )
787
+ ]
788
+ }
789
+ ) : null,
790
+ 0 === products.length ? null !== emptyState ? /* @__PURE__ */ jsxs3(
791
+ EmptyState,
792
+ {
793
+ icon: emptyState.icon,
794
+ title: emptyState.title,
795
+ description: emptyState.description,
796
+ card: true,
797
+ "data-empty-reason": emptyState.key,
798
+ children: [
799
+ emptyState.tips.length > 0 ? /* @__PURE__ */ jsx3("ul", { className: "ec-catalog__tips", "data-search-tips": "", children: emptyState.tips.map((tip) => /* @__PURE__ */ jsx3("li", { children: tip }, tip)) }) : null,
800
+ listing.filtered ? /* @__PURE__ */ jsx3(Button, { color: "primary", onClick: () => clearFilters("count"), children: __3("Clear filters") }) : null,
801
+ ("no-results" === emptyState.key || "unavailable" === emptyState.key) && null !== browseUrl ? /* @__PURE__ */ jsx3(Button, { variant: "outline", color: "neutral", href: browseUrl, "data-search-browse": "", children: __3("Browse all products") }) : null
802
+ ]
803
+ }
804
+ ) : listing.filtered ? /* @__PURE__ */ jsx3(
805
+ EmptyState,
806
+ {
807
+ icon: "funnel",
808
+ title: __3("No products match your filters"),
809
+ description: __3("Try removing a filter or two."),
810
+ card: true,
811
+ "data-empty-reason": "no-match",
812
+ children: /* @__PURE__ */ jsx3(
813
+ Button,
814
+ {
815
+ color: "primary",
816
+ onClick: () => clearFilters("count"),
817
+ "data-empty-clear-filters": "",
818
+ children: __3("Clear filters")
819
+ }
820
+ )
821
+ }
822
+ ) : /* @__PURE__ */ jsx3(
823
+ EmptyState,
824
+ {
825
+ icon: "shopping-bag",
826
+ title: __3("No products to show"),
827
+ description: __3("There are no products here yet. Check back soon."),
828
+ card: true,
829
+ "data-empty-reason": "empty"
830
+ }
831
+ ) : /* @__PURE__ */ jsxs3(Fragment, { children: [
832
+ /* @__PURE__ */ jsxs3(
833
+ "div",
834
+ {
835
+ className: "ec-catalog__results",
836
+ "aria-busy": busy || loading ? "true" : void 0,
837
+ "data-catalog-results": "",
838
+ children: [
839
+ /* @__PURE__ */ jsx3(
840
+ "ul",
841
+ {
842
+ role: "list",
843
+ className: "ec-catalog__grid",
844
+ "data-wide": hasFilters ? void 0 : "",
845
+ "data-catalog-grid": "",
846
+ children: products.map((product) => /* @__PURE__ */ jsx3("li", { className: "ec-catalog__item", children: card(product) }, product.id))
847
+ }
848
+ ),
849
+ /* @__PURE__ */ jsx3(
850
+ "ul",
851
+ {
852
+ role: "list",
853
+ className: "ec-catalog__grid ec-catalog__skeleton",
854
+ "data-wide": hasFilters ? void 0 : "",
855
+ "aria-hidden": "true",
856
+ "data-skeleton": "card",
857
+ "data-catalog-skeleton": "",
858
+ children: Array.from({ length: Math.min(6, products.length) }, (_, index) => /* @__PURE__ */ jsx3("li", { className: "ec-catalog__item", children: /* @__PURE__ */ jsxs3(
859
+ Card,
860
+ {
861
+ className: "ec-skeleton-card",
862
+ media: /* @__PURE__ */ jsx3(Skeleton, { className: "ec-skeleton-card__media" }),
863
+ children: [
864
+ /* @__PURE__ */ jsx3(
865
+ Skeleton,
866
+ {
867
+ shape: "text",
868
+ className: "ec-skeleton-card__line",
869
+ "data-length": "medium"
870
+ }
871
+ ),
872
+ /* @__PURE__ */ jsx3(
873
+ Skeleton,
874
+ {
875
+ shape: "text",
876
+ className: "ec-skeleton-card__line",
877
+ "data-length": "long"
878
+ }
879
+ ),
880
+ /* @__PURE__ */ jsx3(
881
+ Skeleton,
882
+ {
883
+ shape: "text",
884
+ className: "ec-skeleton-card__line",
885
+ "data-length": "short"
886
+ }
887
+ ),
888
+ /* @__PURE__ */ jsx3(Skeleton, { className: "ec-skeleton-card__button" })
889
+ ]
890
+ }
891
+ ) }, index))
892
+ }
893
+ )
894
+ ]
895
+ }
896
+ ),
897
+ /* @__PURE__ */ jsx3("div", { className: "ec-catalog__pagination", children: /* @__PURE__ */ jsx3(
898
+ Pagination,
899
+ {
900
+ page: listing.pagination.currentPage,
901
+ pageCount: listing.pagination.lastPage,
902
+ total: listing.pagination.total,
903
+ perPage: listing.pagination.perPage,
904
+ summary: true,
905
+ summaryLabel: __3("Showing {from} to {to} of {total} results"),
906
+ onPageChange: (page) => visit(
907
+ listingUrl(listing.urls.base, {
908
+ ...listing.state,
909
+ ...page > 1 ? { page } : {}
910
+ })
911
+ )
912
+ }
913
+ ) })
914
+ ] })
915
+ ] })
916
+ ] }),
917
+ hasFilters ? /* @__PURE__ */ jsx3(
918
+ Drawer,
919
+ {
920
+ ref: drawer,
921
+ side: "start",
922
+ id: "ecommerce-catalog-filters-drawer",
923
+ size: "sm",
924
+ title: __3("Filters"),
925
+ description: 0 === activeCount ? void 0 : trans_choice(":count applied|:count applied", activeCount, { count: activeCount }),
926
+ closeLabel: __3("Close filters"),
927
+ open: drawerOpen,
928
+ onOpenChange: (open) => {
929
+ setDrawerOpen(open);
930
+ if (!open) {
931
+ filtersButton.current?.focus();
932
+ }
933
+ },
934
+ footer: /* @__PURE__ */ jsxs3(Fragment, { children: [
935
+ 0 !== activeCount ? /* @__PURE__ */ jsx3(
936
+ Button,
937
+ {
938
+ variant: "ghost",
939
+ color: "neutral",
940
+ onClick: () => clearFilters("apply"),
941
+ "data-drawer-clear-filters": "",
942
+ children: __3("Clear all")
943
+ }
944
+ ) : null,
945
+ /* @__PURE__ */ jsx3(
946
+ Button,
947
+ {
948
+ color: "primary",
949
+ onClick: () => {
950
+ setDrawerOpen(false);
951
+ filtersButton.current?.focus();
952
+ },
953
+ "data-filters-apply": "",
954
+ children: trans_choice("Show :count product|Show :count products", total, { count: total })
955
+ }
956
+ )
957
+ ] }),
958
+ "data-filters-drawer": "",
959
+ children: filterGroups("ecommerce-filters-drawer")
960
+ }
961
+ ) : null
962
+ ]
963
+ }
964
+ );
965
+ }
966
+
967
+ // src/catalog/StorefrontBreadcrumbs.tsx
968
+ import { __ as __4 } from "@artisanpack-ui/ecommerce-storefront-core";
969
+ import { Breadcrumbs } from "@artisanpack-ui/react";
970
+ import { jsx as jsx4 } from "react/jsx-runtime";
971
+ function StorefrontBreadcrumbs({ items }) {
972
+ return /* @__PURE__ */ jsx4(
973
+ Breadcrumbs,
974
+ {
975
+ items: items.map((item) => ({ label: item.label, href: item.url ?? void 0 })),
976
+ label: __4("Breadcrumb")
977
+ }
978
+ );
979
+ }
980
+
981
+ export {
982
+ PriceRange,
983
+ buildQuery,
984
+ listingUrl,
985
+ choiceValue,
986
+ optionValues,
987
+ toggleValue,
988
+ withChoice,
989
+ withOption,
990
+ withToggle,
991
+ withPrice,
992
+ priceRangeFor,
993
+ CatalogFilters,
994
+ useQuickAdd,
995
+ CatalogListing,
996
+ StorefrontBreadcrumbs
997
+ };
998
+ //# sourceMappingURL=chunk-P3NIV4YG.mjs.map