@asteby/storefront-react 0.26.1 → 0.28.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 +7 -2
- package/dist/account-server.cjs +533 -83
- package/dist/account-server.cjs.map +1 -1
- package/dist/account-server.d.cts +13 -2
- package/dist/account-server.d.ts +13 -2
- package/dist/account-server.js +23 -6
- package/dist/account-server.js.map +1 -1
- package/dist/account.cjs +572 -96
- package/dist/account.cjs.map +1 -1
- package/dist/account.d.cts +82 -45
- package/dist/account.d.ts +82 -45
- package/dist/account.js +53 -14
- package/dist/account.js.map +1 -1
- package/dist/checkout.cjs +114 -38
- package/dist/checkout.cjs.map +1 -1
- package/dist/checkout.d.cts +24 -1
- package/dist/checkout.d.ts +24 -1
- package/dist/checkout.js +114 -38
- package/dist/checkout.js.map +1 -1
- package/dist/chunk-BXKV2KWZ.js +291 -0
- package/dist/chunk-BXKV2KWZ.js.map +1 -0
- package/dist/chunk-LIUEQENV.js +156 -0
- package/dist/chunk-LIUEQENV.js.map +1 -0
- package/dist/voucher-document-FWH4DQ5N.js +72 -0
- package/dist/voucher-document-FWH4DQ5N.js.map +1 -0
- package/dist/voucher-pdf-LQC333AB.js +213 -0
- package/dist/voucher-pdf-LQC333AB.js.map +1 -0
- package/package.json +1 -1
- package/dist/chunk-TXEYBDFG.js +0 -182
- package/dist/chunk-TXEYBDFG.js.map +0 -1
- package/dist/voucher-document-SFWJCLTN.js +0 -124
- package/dist/voucher-document-SFWJCLTN.js.map +0 -1
package/dist/checkout.cjs
CHANGED
|
@@ -243,7 +243,8 @@ var ES2 = {
|
|
|
243
243
|
phoneHint: "Solo para la paqueter\xEDa, por si necesita contactarte.",
|
|
244
244
|
lookupFilled: "Completamos estado y ciudad con tu c\xF3digo postal.",
|
|
245
245
|
provinceLocked: "Definido por tu c\xF3digo postal",
|
|
246
|
-
changePostalCode: "Cambiar c\xF3digo postal"
|
|
246
|
+
changePostalCode: "Cambiar c\xF3digo postal",
|
|
247
|
+
resolvedPlace: "Entrega en"
|
|
247
248
|
};
|
|
248
249
|
var EN2 = {
|
|
249
250
|
email: "Email",
|
|
@@ -265,7 +266,8 @@ var EN2 = {
|
|
|
265
266
|
phoneHint: "Only for the carrier, in case they need to reach you.",
|
|
266
267
|
lookupFilled: "We filled in state and city from your postal code.",
|
|
267
268
|
provinceLocked: "Set by your postal code",
|
|
268
|
-
changePostalCode: "Change postal code"
|
|
269
|
+
changePostalCode: "Change postal code",
|
|
270
|
+
resolvedPlace: "Delivering to"
|
|
269
271
|
};
|
|
270
272
|
function addressFieldsMessages(locale, overrides) {
|
|
271
273
|
const base = (locale ?? "es-MX").toLowerCase().startsWith("en") ? EN2 : ES2;
|
|
@@ -324,8 +326,11 @@ var ADDRESS_FILL_EVENT_FLAG = "sfSynthetic";
|
|
|
324
326
|
function isAddressFillEvent(event) {
|
|
325
327
|
return event[ADDRESS_FILL_EVENT_FLAG] === true;
|
|
326
328
|
}
|
|
329
|
+
var SR_ONLY = { position: "absolute", width: 1, height: 1, overflow: "hidden", clip: "rect(0 0 0 0)", whiteSpace: "nowrap" };
|
|
330
|
+
var sameText = (a, b) => fold(a) === fold(b);
|
|
331
|
+
var fold = (v) => v.normalize("NFD").replace(/[\u0300-\u036f]/g, "").trim().toLowerCase();
|
|
327
332
|
function AddressFields(props) {
|
|
328
|
-
const { defaults, names = {}, errors = {}, countryCode, provinces, postalCode, lookupPostalCode, lockProvinceOnFill = true, locale, messages, fieldMessages: fm, classNames: cx = {}, children } = props;
|
|
333
|
+
const { defaults, names = {}, errors = {}, countryCode, provinces, postalCode, lookupPostalCode, lockProvinceOnFill = true, hideResolvedFields = true, locale, messages, fieldMessages: fm, classNames: cx = {}, children } = props;
|
|
329
334
|
const showNeighborhood = props.neighborhood ?? true;
|
|
330
335
|
const showReference = props.reference ?? true;
|
|
331
336
|
const m = addressFieldsMessages(locale, messages);
|
|
@@ -336,6 +341,9 @@ function AddressFields(props) {
|
|
|
336
341
|
const [filled, setFilled] = react.useState(false);
|
|
337
342
|
const [provinceLocked, setProvinceLocked] = react.useState(false);
|
|
338
343
|
const [coloniaSelect, setColoniaSelect] = react.useState(false);
|
|
344
|
+
const [resolved, setResolved] = react.useState(null);
|
|
345
|
+
const resolvedRef = react.useRef(false);
|
|
346
|
+
const [defaultsStale, setDefaultsStale] = react.useState(false);
|
|
339
347
|
const coloniaSelectRef = react.useRef(false);
|
|
340
348
|
const coloniaCarry = react.useRef(null);
|
|
341
349
|
const lastZip = react.useRef(null);
|
|
@@ -370,6 +378,7 @@ function AddressFields(props) {
|
|
|
370
378
|
if (!form) return;
|
|
371
379
|
const locked = form.querySelector('[data-sf-locked="1"]');
|
|
372
380
|
const touched = [];
|
|
381
|
+
if (resolvedRef.current) setDefaultsStale(true);
|
|
373
382
|
if (locked) {
|
|
374
383
|
unlockField(locked);
|
|
375
384
|
touched.push(locked);
|
|
@@ -387,9 +396,32 @@ function AddressFields(props) {
|
|
|
387
396
|
el.dispatchEvent(event);
|
|
388
397
|
}
|
|
389
398
|
lastZip.current = null;
|
|
399
|
+
resolvedRef.current = false;
|
|
400
|
+
setResolved(null);
|
|
390
401
|
setProvinceLocked(false);
|
|
391
402
|
setFilled(false);
|
|
392
403
|
};
|
|
404
|
+
const resolveHidden = (info, form) => {
|
|
405
|
+
if (!form || !info.province || !info.city) return null;
|
|
406
|
+
if ((info.cities?.length ?? 0) > 1) return null;
|
|
407
|
+
let province = info.province.trim();
|
|
408
|
+
let provinceCode = null;
|
|
409
|
+
if (provinces && provinces.length) {
|
|
410
|
+
const hit = provinces.find((p) => sameText(p.name, province) || !!p.code && sameText(p.code, province));
|
|
411
|
+
if (!hit) return null;
|
|
412
|
+
province = hit.name;
|
|
413
|
+
provinceCode = hit.code ?? null;
|
|
414
|
+
}
|
|
415
|
+
const city = info.city.trim();
|
|
416
|
+
if (!province || !city) return null;
|
|
417
|
+
const theirs = (name, value) => {
|
|
418
|
+
const el = form.elements.namedItem(name);
|
|
419
|
+
if (!el || "length" in el && !(el instanceof HTMLSelectElement)) return false;
|
|
420
|
+
return !!el.value && el.dataset.sfAutofilled !== "1" && !sameText(el.value, value);
|
|
421
|
+
};
|
|
422
|
+
if (theirs(n("province"), province) || theirs(n("city"), city)) return null;
|
|
423
|
+
return { province, provinceCode, city, place: info.municipality?.trim() || city };
|
|
424
|
+
};
|
|
393
425
|
const runLookup = (zip) => {
|
|
394
426
|
const lookup = lookupRef.current;
|
|
395
427
|
if (!lookup || !zip || zip === lastZip.current) return;
|
|
@@ -420,8 +452,14 @@ function AddressFields(props) {
|
|
|
420
452
|
}
|
|
421
453
|
return true;
|
|
422
454
|
};
|
|
423
|
-
const
|
|
424
|
-
|
|
455
|
+
const resolution = hideResolvedFields ? resolveHidden(info, form) : null;
|
|
456
|
+
if (resolution) {
|
|
457
|
+
resolvedRef.current = true;
|
|
458
|
+
setDefaultsStale(true);
|
|
459
|
+
setResolved(resolution);
|
|
460
|
+
}
|
|
461
|
+
const a = resolution ? false : fill2(n("province"), info.province, lockProvinceOnFill);
|
|
462
|
+
const b = resolution ? false : fill2(n("city"), info.city);
|
|
425
463
|
const only = info.neighborhoods?.length === 1 ? info.neighborhoods[0] : null;
|
|
426
464
|
const c = showNeighborhood ? fill2(n("neighborhood"), only) : false;
|
|
427
465
|
setColonias(info.neighborhoods ?? []);
|
|
@@ -439,7 +477,7 @@ function AddressFields(props) {
|
|
|
439
477
|
}
|
|
440
478
|
coloniaSelectRef.current = wantSelect;
|
|
441
479
|
setColoniaSelect(wantSelect);
|
|
442
|
-
setFilled(a || b || c || carried);
|
|
480
|
+
setFilled(!resolution && (a || b || c || carried));
|
|
443
481
|
});
|
|
444
482
|
},
|
|
445
483
|
() => {
|
|
@@ -465,7 +503,20 @@ function AddressFields(props) {
|
|
|
465
503
|
const zip = defaults?.zip;
|
|
466
504
|
if (zip) runLookup(zip);
|
|
467
505
|
}, []);
|
|
468
|
-
const
|
|
506
|
+
const firstRender = react.useRef(true);
|
|
507
|
+
react.useEffect(() => {
|
|
508
|
+
if (firstRender.current) {
|
|
509
|
+
firstRender.current = false;
|
|
510
|
+
return;
|
|
511
|
+
}
|
|
512
|
+
const form = zipRef.current?.closest("form");
|
|
513
|
+
const el = (resolved ? form?.querySelector('input[type="hidden"][data-sf-resolved-field="city"]') : null) ?? zipRef.current?.querySelector("input");
|
|
514
|
+
if (!el) return;
|
|
515
|
+
const event = new Event("input", { bubbles: true });
|
|
516
|
+
Object.defineProperty(event, ADDRESS_FILL_EVENT_FLAG, { value: true });
|
|
517
|
+
el.dispatchEvent(event);
|
|
518
|
+
}, [resolved]);
|
|
519
|
+
const hasLock = (root) => resolvedRef.current || !!root?.closest("form")?.querySelector('[data-sf-locked="1"]');
|
|
469
520
|
const changeZip = () => {
|
|
470
521
|
releaseLookup();
|
|
471
522
|
const zipEl = zipRef.current?.querySelector("input");
|
|
@@ -482,35 +533,61 @@ function AddressFields(props) {
|
|
|
482
533
|
/* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", "data-sf-change-zip": "", onClick: changeZip, style: { background: "none", border: 0, padding: 0, font: "inherit", color: "inherit", textDecoration: "underline", cursor: "pointer" }, children: m.changePostalCode })
|
|
483
534
|
] }) : void 0;
|
|
484
535
|
const numericZip = postalCode?.inputMode === "numeric";
|
|
536
|
+
const showResolved = !!resolved && !errors[n("province")] && !errors[n("city")];
|
|
537
|
+
const startOf = (key) => resolved ? resolved[key] : defaultsStale ? "" : defaults?.[key] ?? "";
|
|
485
538
|
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
486
|
-
/* @__PURE__ */ jsxRuntime.
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
539
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { ref: zipRef, className: join(cx.half), "data-sf-zip": true, children: [
|
|
540
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
541
|
+
CheckoutField,
|
|
542
|
+
{
|
|
543
|
+
...common,
|
|
544
|
+
name: n("zip"),
|
|
545
|
+
label: m.zip,
|
|
546
|
+
autoComplete: "postal-code",
|
|
547
|
+
inputMode: postalCode?.inputMode ?? "text",
|
|
548
|
+
...postalCode?.pattern ? { pattern: postalCode.pattern } : {},
|
|
549
|
+
...postalCode?.maxLength ? { maxLength: postalCode.maxLength } : {},
|
|
550
|
+
...postalCode?.title ? { title: postalCode.title } : {},
|
|
551
|
+
...numericZip ? { autoCapitalize: "none" } : {},
|
|
552
|
+
defaultValue: defaults?.zip ?? "",
|
|
553
|
+
error: errors[n("zip")] ?? null,
|
|
554
|
+
classNames: { ...cx, root: cx.root },
|
|
555
|
+
onInput: (e) => {
|
|
556
|
+
const v = e.currentTarget.value.trim();
|
|
557
|
+
if (v !== lastZip.current && hasLock(zipRef.current)) releaseLookup();
|
|
558
|
+
if (postalCode?.maxLength && v.length === postalCode.maxLength) runLookup(v);
|
|
559
|
+
},
|
|
560
|
+
onBlur: (e) => runLookup(e.currentTarget.value.trim())
|
|
561
|
+
}
|
|
562
|
+
),
|
|
563
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { "data-sf-resolved": showResolved ? "" : void 0, className: showResolved || filled ? join(cx.hint) : void 0, children: [
|
|
564
|
+
/* @__PURE__ */ jsxRuntime.jsx("p", { role: "status", "aria-live": "polite", "data-sf-zip-status": true, style: showResolved || filled ? showResolved ? { display: "inline", margin: 0 } : void 0 : SR_ONLY, children: showResolved && resolved ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
565
|
+
/* @__PURE__ */ jsxRuntime.jsxs("span", { style: SR_ONLY, children: [
|
|
566
|
+
m.resolvedPlace,
|
|
567
|
+
" "
|
|
568
|
+
] }),
|
|
569
|
+
/* @__PURE__ */ jsxRuntime.jsxs("span", { "data-sf-resolved-place": true, children: [
|
|
570
|
+
resolved.place,
|
|
571
|
+
", ",
|
|
572
|
+
resolved.province
|
|
573
|
+
] })
|
|
574
|
+
] }) : filled ? m.lookupFilled : "" }),
|
|
575
|
+
showResolved ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
576
|
+
" \xB7 ",
|
|
577
|
+
/* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", "data-sf-change-zip": "", onClick: changeZip, style: { background: "none", border: 0, padding: 0, font: "inherit", color: "inherit", textDecoration: "underline", cursor: "pointer" }, children: m.changePostalCode })
|
|
578
|
+
] }) : null
|
|
579
|
+
] })
|
|
580
|
+
] }),
|
|
581
|
+
showResolved && resolved ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
582
|
+
/* @__PURE__ */ jsxRuntime.jsx("input", { type: "hidden", name: n("province"), value: resolved.province, "data-sf-resolved-field": "province" }),
|
|
583
|
+
resolved.provinceCode ? /* @__PURE__ */ jsxRuntime.jsx("input", { type: "hidden", name: n("province_code"), value: resolved.provinceCode, "data-sf-resolved-field": "province_code" }) : null,
|
|
584
|
+
/* @__PURE__ */ jsxRuntime.jsx("input", { type: "hidden", name: n("city"), value: resolved.city, "data-sf-resolved-field": "city" })
|
|
585
|
+
] }) : null,
|
|
586
|
+
showResolved ? null : provinces && provinces.length ? /* @__PURE__ */ jsxRuntime.jsxs(CheckoutField, { ...common, as: "select", name: n("province"), label: m.province, autoComplete: "address-level1", defaultValue: startOf("province"), error: errors[n("province")] ?? null, classNames: field(cx, "half"), hint: provinceHint, children: [
|
|
510
587
|
/* @__PURE__ */ jsxRuntime.jsx("option", { value: "", disabled: true, children: m.provincePlaceholder }),
|
|
511
588
|
provinces.map((p) => /* @__PURE__ */ jsxRuntime.jsx("option", { value: p.name, children: p.name }, p.code ?? p.name))
|
|
512
|
-
] }) : /* @__PURE__ */ jsxRuntime.jsx(CheckoutField, { ...common, name: n("province"), label: m.province, autoComplete: "address-level1", defaultValue:
|
|
513
|
-
/* @__PURE__ */ jsxRuntime.jsx(CheckoutField, { ...common, name: n("city"), label: m.city, autoComplete: "address-level2", defaultValue:
|
|
589
|
+
] }) : /* @__PURE__ */ jsxRuntime.jsx(CheckoutField, { ...common, name: n("province"), label: m.province, autoComplete: "address-level1", defaultValue: startOf("province"), error: errors[n("province")] ?? null, classNames: field(cx, "half"), hint: provinceHint }),
|
|
590
|
+
showResolved ? null : /* @__PURE__ */ jsxRuntime.jsx(CheckoutField, { ...common, name: n("city"), label: m.city, autoComplete: "address-level2", defaultValue: startOf("city"), error: errors[n("city")] ?? null, classNames: field(cx, "half") }),
|
|
514
591
|
showNeighborhood && coloniaSelect ? /* @__PURE__ */ jsxRuntime.jsxs(
|
|
515
592
|
CheckoutField,
|
|
516
593
|
{
|
|
@@ -543,7 +620,6 @@ function AddressFields(props) {
|
|
|
543
620
|
}
|
|
544
621
|
) : null,
|
|
545
622
|
colonias.length && !coloniaSelect ? /* @__PURE__ */ jsxRuntime.jsx("datalist", { id: listId, children: colonias.map((c) => /* @__PURE__ */ jsxRuntime.jsx("option", { value: c }, c)) }) : null,
|
|
546
|
-
/* @__PURE__ */ jsxRuntime.jsx("p", { role: "status", "aria-live": "polite", "data-sf-zip-status": true, style: filled ? void 0 : { position: "absolute", width: 1, height: 1, overflow: "hidden", clip: "rect(0 0 0 0)", whiteSpace: "nowrap" }, className: filled ? join(cx.hint, cx.wide) : void 0, children: filled ? m.lookupFilled : "" }),
|
|
547
623
|
/* @__PURE__ */ jsxRuntime.jsx(CheckoutField, { ...common, name: n("address1"), label: m.address1, autoComplete: "address-line1", defaultValue: defaults?.address1 ?? "", error: errors[n("address1")] ?? null, hint: m.address1Hint, classNames: field(cx, "wide") }),
|
|
548
624
|
/* @__PURE__ */ jsxRuntime.jsx(CheckoutField, { ...common, name: n("address2"), label: m.address2, autoComplete: "address-line2", optional: true, defaultValue: defaults?.address2 ?? "", error: errors[n("address2")] ?? null, classNames: field(cx, "half") }),
|
|
549
625
|
showReference ? /* @__PURE__ */ jsxRuntime.jsx(CheckoutField, { ...common, name: n("reference"), label: m.reference, optional: true, defaultValue: defaults?.reference ?? "", error: errors[n("reference")] ?? null, hint: m.referenceHint, classNames: field(cx, "wide"), maxLength: 200 }) : null,
|
|
@@ -1310,7 +1386,7 @@ function matchRate(previous, rates) {
|
|
|
1310
1386
|
}
|
|
1311
1387
|
return rates.find((r) => sameCarrier(r) && norm3(r.title) === norm3(previous.title)) ?? null;
|
|
1312
1388
|
}
|
|
1313
|
-
var
|
|
1389
|
+
var SR_ONLY2 = { position: "absolute", width: 1, height: 1, overflow: "hidden", clip: "rect(0 0 0 0)", whiteSpace: "nowrap" };
|
|
1314
1390
|
var useHydrated = () => react.useSyncExternalStore(
|
|
1315
1391
|
() => () => {
|
|
1316
1392
|
},
|
|
@@ -1397,7 +1473,7 @@ function DeliveryOptions(props) {
|
|
|
1397
1473
|
) : null,
|
|
1398
1474
|
/* @__PURE__ */ jsxRuntime.jsxs("span", { className: cx.body, "data-sf-delivery-body": true, children: [
|
|
1399
1475
|
/* @__PURE__ */ jsxRuntime.jsx("span", { className: cx.title, "data-sf-delivery-title": true, children: carrier ? opts.grouped ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
1400
|
-
/* @__PURE__ */ jsxRuntime.jsxs("span", { style:
|
|
1476
|
+
/* @__PURE__ */ jsxRuntime.jsxs("span", { style: SR_ONLY2, children: [
|
|
1401
1477
|
carrier,
|
|
1402
1478
|
" "
|
|
1403
1479
|
] }),
|
|
@@ -1418,8 +1494,8 @@ function DeliveryOptions(props) {
|
|
|
1418
1494
|
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: cx.root, "data-sf-delivery": true, "data-layout": layout, "aria-busy": loading || void 0, children: [
|
|
1419
1495
|
partial && !errorText ? /* @__PURE__ */ jsxRuntime.jsx("p", { role: "status", className: cx.partial, "data-sf-delivery-partial": true, children: m.partial }) : null,
|
|
1420
1496
|
requoted ? /* @__PURE__ */ jsxRuntime.jsx("p", { role: "status", className: cx.partial, "data-sf-delivery-requoted": true, children: m.requoted }) : null,
|
|
1421
|
-
loading ? /* @__PURE__ */ jsxRuntime.jsx("span", { style:
|
|
1422
|
-
props.announceReady && !loading && rates.length > 0 ? /* @__PURE__ */ jsxRuntime.jsx("span", { style:
|
|
1497
|
+
loading ? /* @__PURE__ */ jsxRuntime.jsx("span", { style: SR_ONLY2, role: "status", "data-sf-delivery-loading": true, children: m.loading }) : null,
|
|
1498
|
+
props.announceReady && !loading && rates.length > 0 ? /* @__PURE__ */ jsxRuntime.jsx("span", { style: SR_ONLY2, role: "status", "data-sf-delivery-ready": true, children: freeRate ? m.freeShipping : m.ratesReady.replace("{n}", String(rates.length)) }) : null,
|
|
1423
1499
|
errorText && rates.length === 0 && !loading ? /* @__PURE__ */ jsxRuntime.jsxs("div", { role: "alert", className: cx.error, "data-sf-delivery-error": true, children: [
|
|
1424
1500
|
/* @__PURE__ */ jsxRuntime.jsx("p", { children: errorText }),
|
|
1425
1501
|
onRetry ? /* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", className: cx.retry, onClick: onRetry, "data-sf-delivery-retry": true, children: m.retry }) : null
|