@develemit/storefront 0.4.0 → 0.7.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/dist/index.js CHANGED
@@ -399,7 +399,7 @@ function F(e = "sf-cart") {
399
399
  }
400
400
  // src/cart/cart-provider.tsx
401
401
  var I = n(null), L = F();
402
- function R({ storage: e = L, children: t }) {
402
+ function ee({ storage: e = L, children: t }) {
403
403
  let [n, i] = s(M, A), [u, f] = l(!1), [p, m] = l(!1), h = c(n);
404
404
  a(() => {
405
405
  h.current = n;
@@ -457,20 +457,81 @@ function R({ storage: e = L, children: t }) {
457
457
  children: t
458
458
  });
459
459
  }
460
- function z() {
460
+ function R() {
461
461
  let e = i(I);
462
462
  if (!e) throw Error("useCart must be used inside <CartProvider>");
463
463
  return e;
464
464
  }
465
+ // src/components/cart-summary/discount-types.ts
466
+ var z = {
467
+ toggle: "Have a code?",
468
+ field: "Discount code",
469
+ apply: "Apply",
470
+ remove: "Remove",
471
+ line: "Discount",
472
+ unavailable: "We could not check that code. Please try again.",
473
+ reasons: {
474
+ not_found: "That code is not valid.",
475
+ inactive: "That code is not valid.",
476
+ not_started: "That code is not active yet.",
477
+ expired: "That code has expired.",
478
+ min_subtotal: "Your cart is below the minimum for that code.",
479
+ exhausted: "That code is no longer available.",
480
+ currency: "That code does not apply to this cart."
481
+ }
482
+ };
483
+ function B(e, t) {
484
+ return t?.[e] ?? z.reasons[e];
485
+ }
486
+ // src/cart/use-checkout.ts
487
+ var V = {
488
+ outOfStock: "Some items just sold or are on hold, so we removed them from your cart.",
489
+ unavailable: "Checkout is unavailable right now. Please try again."
490
+ }, te = (e) => window.location.assign(e);
491
+ function ne({ startCheckout: e, onRedirect: t = te, onDiscountInvalid: n, labels: i }) {
492
+ let a = R(), [o, s] = l(!1), [c, u] = l(null), { lines: d, remove: f } = a, p = {
493
+ ...V,
494
+ ...i
495
+ };
496
+ return {
497
+ checkout: r(async (r = {}) => {
498
+ s(!0), u(null);
499
+ try {
500
+ let i = await e(d.map((e) => ({
501
+ productId: e.productId,
502
+ quantity: e.quantity
503
+ })), r);
504
+ if ("url" in i) {
505
+ t(i.url);
506
+ return;
507
+ }
508
+ i.error === "discount_invalid" ? (u(B(i.reason, p.discountReasons)), n?.(i.reason)) : (i.productIds.forEach(f), u(p.outOfStock));
509
+ } catch {
510
+ u(p.unavailable);
511
+ }
512
+ s(!1);
513
+ }, [
514
+ e,
515
+ t,
516
+ n,
517
+ d,
518
+ f,
519
+ i
520
+ ]),
521
+ busy: o,
522
+ message: c,
523
+ clearMessage: r(() => u(null), [])
524
+ };
525
+ }
465
526
  // src/components/add-to-cart-button/add-to-cart-button.tsx
466
- var B = {
527
+ var H = {
467
528
  add: "Add to cart",
468
529
  inCart: "In your cart",
469
530
  unavailable: "Unavailable"
470
531
  };
471
- function V({ product: e, labels: t, openOnAdd: n = !0, className: r }) {
472
- let i = z(), a = {
473
- ...B,
532
+ function U({ product: e, labels: t, openOnAdd: n = !0, className: r }) {
533
+ let i = R(), a = {
534
+ ...H,
474
535
  ...t
475
536
  }, o = i.lines.find((t) => t.productId === e.id)?.quantity ?? 0, s = e.availability !== "available", c = o >= e.quantity, l = !i.hydrated || s || c, u = s ? a.unavailable : c ? a.inCart : a.add;
476
537
  function f() {
@@ -494,13 +555,13 @@ function V({ product: e, labels: t, openOnAdd: n = !0, className: r }) {
494
555
  });
495
556
  }
496
557
  // src/components/cart-line-item/cart-line-item.tsx
497
- var H = {
558
+ var W = {
498
559
  remove: "Remove",
499
560
  quantity: "Quantity"
500
561
  };
501
- function U({ line: t, labels: n }) {
502
- let { remove: r, setQuantity: i } = z(), { locale: a, renderLink: o, renderImage: s, hrefs: c } = y(), l = {
503
- ...H,
562
+ function G({ line: t, labels: n }) {
563
+ let { remove: r, setQuantity: i } = R(), { locale: a, renderLink: o, renderImage: s, hrefs: c } = y(), l = {
564
+ ...W,
504
565
  ...n
505
566
  }, u = t.maxQuantity > 1;
506
567
  return /* @__PURE__ */ f("li", {
@@ -544,17 +605,17 @@ function U({ line: t, labels: n }) {
544
605
  });
545
606
  }
546
607
  // src/lib/parse-duration.ts
547
- function W(e) {
608
+ function K(e) {
548
609
  let t = /^\s*(-?\d*\.?\d+)\s*(ms|s)\s*$/.exec(e);
549
610
  if (!t) return 0;
550
611
  let n = Number(t[1]);
551
612
  return Math.max(0, t[2] === "s" ? n * 1e3 : n);
552
613
  }
553
614
  // src/components/cart-drawer/use-drawer-presence.ts
554
- function G(e, t) {
615
+ function q(e, t) {
555
616
  let [n, r] = l(0), [i, o] = l(e), [s, c] = l(!1);
556
617
  return i !== e && (o(e), c(!e && n > 0)), a(() => {
557
- e && t.current && r(W(getComputedStyle(t.current).getPropertyValue("--sf-motion-duration")));
618
+ e && t.current && r(K(getComputedStyle(t.current).getPropertyValue("--sf-motion-duration")));
558
619
  }, [e, t]), a(() => {
559
620
  if (!s) return;
560
621
  let e = setTimeout(() => c(!1), n);
@@ -565,7 +626,7 @@ function G(e, t) {
565
626
  };
566
627
  }
567
628
  // src/components/cart-summary/discount-field.tsx
568
- function K({ labels: t, applied: n, error: r, pending: i, currency: a, locale: o, onApply: s, onRemove: c }) {
629
+ function J({ labels: t, applied: n, error: r, pending: i, currency: a, locale: o, onApply: s, onRemove: c }) {
569
630
  let [u, p] = l(!1), [m, h] = l("");
570
631
  function g(e) {
571
632
  e.preventDefault();
@@ -622,27 +683,9 @@ function K({ labels: t, applied: n, error: r, pending: i, currency: a, locale: o
622
683
  })]
623
684
  });
624
685
  }
625
- // src/components/cart-summary/discount-types.ts
626
- var q = {
627
- toggle: "Have a code?",
628
- field: "Discount code",
629
- apply: "Apply",
630
- remove: "Remove",
631
- line: "Discount",
632
- unavailable: "We could not check that code. Please try again.",
633
- reasons: {
634
- not_found: "That code is not valid.",
635
- inactive: "That code is not valid.",
636
- not_started: "That code is not active yet.",
637
- expired: "That code has expired.",
638
- min_subtotal: "Your cart is below the minimum for that code.",
639
- exhausted: "That code is no longer available.",
640
- currency: "That code does not apply to this cart."
641
- }
642
- };
643
686
  // src/components/cart-summary/use-discount.ts
644
- function J(e) {
645
- let { lines: t } = z(), n = t.map((e) => ({
687
+ function Y(e) {
688
+ let { lines: t } = R(), n = t.map((e) => ({
646
689
  productId: e.productId,
647
690
  quantity: e.quantity
648
691
  })), i = n.map((e) => `${e.productId}:${e.quantity}`).join(","), [o, s] = l(null), [u, d] = l(null), [f, p] = l(!1), m = c({
@@ -701,12 +744,12 @@ function J(e) {
701
744
  };
702
745
  }
703
746
  // src/components/cart-summary/cart-summary.tsx
704
- function Y({ onCheckout: t, checkoutLabel: n = "Checkout", checkoutDisabled: r = !1, labels: i, discount: a }) {
705
- let o = z(), { locale: s } = y(), c = i?.subtotal ?? "Subtotal", l = J(a), u = {
706
- ...q,
747
+ function X({ onCheckout: t, checkoutLabel: n = "Checkout", checkoutDisabled: r = !1, labels: i, discount: a }) {
748
+ let o = R(), { locale: s } = y(), c = i?.subtotal ?? "Subtotal", l = Y(a), u = {
749
+ ...z,
707
750
  ...i?.discount,
708
751
  reasons: {
709
- ...q.reasons,
752
+ ...z.reasons,
710
753
  ...i?.discount?.reasons
711
754
  }
712
755
  };
@@ -720,7 +763,7 @@ function Y({ onCheckout: t, checkoutLabel: n = "Checkout", checkoutDisabled: r =
720
763
  children: e(o.subtotalCents, o.currency ?? "USD", s)
721
764
  })]
722
765
  }),
723
- a && o.lines.length > 0 && /* @__PURE__ */ d(K, {
766
+ a && o.lines.length > 0 && /* @__PURE__ */ d(J, {
724
767
  labels: u,
725
768
  currency: o.currency ?? "USD",
726
769
  locale: s,
@@ -741,20 +784,20 @@ function Y({ onCheckout: t, checkoutLabel: n = "Checkout", checkoutDisabled: r =
741
784
  });
742
785
  }
743
786
  // src/components/cart-drawer/cart-drawer.tsx
744
- var X = {
787
+ var Z = {
745
788
  title: "Your cart",
746
789
  close: "Close",
747
790
  empty: "Your cart is empty."
748
- }, Z = "a[href], button:not([disabled]), input:not([disabled]), [tabindex]:not([tabindex=\"-1\"])";
749
- function Q({ labels: e, summary: t, slots: n }) {
750
- let r = z(), i = {
751
- ...X,
791
+ }, Q = "a[href], button:not([disabled]), input:not([disabled]), [tabindex]:not([tabindex=\"-1\"])";
792
+ function re({ labels: e, summary: t, slots: n }) {
793
+ let r = R(), i = {
794
+ ...Z,
752
795
  ...e
753
- }, o = c(null), s = c(null), { isOpen: l } = r, p = G(l, s);
796
+ }, o = c(null), s = c(null), { isOpen: l } = r, p = q(l, s);
754
797
  if (a(() => {
755
798
  if (!l) return;
756
799
  let e = document.activeElement;
757
- return o.current?.querySelector(Z)?.focus(), () => e?.focus();
800
+ return o.current?.querySelector(Q)?.focus(), () => e?.focus();
758
801
  }, [l]), !p.mounted) return null;
759
802
  function m(e) {
760
803
  if (e.key === "Escape") {
@@ -762,7 +805,7 @@ function Q({ labels: e, summary: t, slots: n }) {
762
805
  return;
763
806
  }
764
807
  if (e.key !== "Tab") return;
765
- let t = Array.from(o.current?.querySelectorAll(Z) ?? []);
808
+ let t = Array.from(o.current?.querySelectorAll(Q) ?? []);
766
809
  if (t.length === 0) return;
767
810
  let n = t[0], i = t[t.length - 1];
768
811
  e.shiftKey && document.activeElement === n ? (e.preventDefault(), i.focus()) : !e.shiftKey && document.activeElement === i && (e.preventDefault(), n.focus());
@@ -803,9 +846,9 @@ function Q({ labels: e, summary: t, slots: n }) {
803
846
  }) : /* @__PURE__ */ f(u, { children: [
804
847
  /* @__PURE__ */ d("ul", {
805
848
  className: "sf-drawer__lines",
806
- children: r.lines.map((e) => /* @__PURE__ */ d(U, { line: e }, e.productId))
849
+ children: r.lines.map((e) => /* @__PURE__ */ d(G, { line: e }, e.productId))
807
850
  }),
808
- /* @__PURE__ */ d(Y, { ...t }),
851
+ /* @__PURE__ */ d(X, { ...t }),
809
852
  n?.summaryNote && /* @__PURE__ */ d("div", {
810
853
  className: "sf-drawer__note",
811
854
  children: n.summaryNote
@@ -815,8 +858,8 @@ function Q({ labels: e, summary: t, slots: n }) {
815
858
  });
816
859
  }
817
860
  // src/components/cart-button/cart-button.tsx
818
- function $({ label: e = "Cart", className: t, icon: n, labelHidden: r = !1, hideZeroCount: i = !1 }) {
819
- let a = z(), o = a.hydrated ? a.itemCount : 0, s = !(i && o === 0), c = s ? r ? `${e}, ${a.itemCount} items` : void 0 : `${e}, empty`;
861
+ function ie({ label: e = "Cart", className: t, icon: n, labelHidden: r = !1, hideZeroCount: i = !1 }) {
862
+ let a = R(), o = a.hydrated ? a.itemCount : 0, s = !(i && o === 0), c = s ? r ? `${e}, ${a.itemCount} items` : void 0 : `${e}, empty`;
820
863
  return /* @__PURE__ */ f("button", {
821
864
  type: "button",
822
865
  className: ["sf-cart-button", t].filter(Boolean).join(" "),
@@ -837,6 +880,146 @@ function $({ label: e = "Cart", className: t, icon: n, labelHidden: r = !1, hide
837
880
  ]
838
881
  });
839
882
  }
840
- export { V as AddToCartButton, S as AvailabilityBadge, $ as CartButton, Q as CartDrawer, U as CartLineItem, R as CartProvider, Y as CartSummary, T as CategoryFilter, k as FeaturedProducts, b as PriceTag, C as ProductCard, O as ProductDetailView, E as ProductGallery, w as ProductGrid, D as ShopView, v as StorefrontProvider, j as addLine, M as cartReducer, B as defaultAddToCartLabels, x as defaultAvailabilityLabels, X as defaultCartDrawerLabels, H as defaultCartLineItemLabels, A as emptyCart, e as formatPrice, P as itemCount, F as localStorageCartStorage, t as sortForDisplay, N as subtotalCents, h as themeToCssVars, z as useCart, y as useStorefront };
883
+ // src/components/checkout-success/labels.ts
884
+ var $ = {
885
+ heading: "Order received",
886
+ summaryHeading: "Order summary",
887
+ reference: "Order {id}",
888
+ continue: "Continue shopping",
889
+ subtotal: "Subtotal",
890
+ discount: "Discount",
891
+ shipping: "Shipping",
892
+ total: "Total",
893
+ shipTo: "Ship to",
894
+ tracking: "Track",
895
+ status: {
896
+ pending: "We're confirming your payment and will email you once it's done.",
897
+ paid: "Payment received. Thank you!",
898
+ shipped: "Your order is on its way.",
899
+ cancelled: "This checkout was cancelled.",
900
+ expired: "This checkout expired before payment.",
901
+ refunded: "This order has been refunded.",
902
+ needs_attention: "We couldn't confirm one of your items. We'll be in touch about a refund."
903
+ }
904
+ };
905
+ // src/components/checkout-success/checkout-success-view.tsx
906
+ function ae(e) {
907
+ let t = [
908
+ e.city,
909
+ e.state,
910
+ e.postalCode
911
+ ].filter(Boolean).join(" ");
912
+ return [
913
+ e.name,
914
+ e.line1,
915
+ e.line2,
916
+ t,
917
+ e.country
918
+ ].filter((e) => !!e);
919
+ }
920
+ function oe({ order: t, locale: n, labels: r, className: i, slots: a, showReference: o, showSummaryHeading: s, continueHref: c, renderLink: l }) {
921
+ let u = {
922
+ ...$,
923
+ ...r,
924
+ status: {
925
+ ...$.status,
926
+ ...r?.status
927
+ }
928
+ }, p = (r) => e(r, t.currency, n), m = t.shippingAddress ? ae(t.shippingAddress) : [], { fulfillment: h } = t, g = {
929
+ href: c ?? "",
930
+ className: "sf-checkout-success__continue",
931
+ children: u.continue
932
+ }, _ = c ? l ? l(g) : /* @__PURE__ */ d("a", { ...g }) : null, v = a?.actions ?? _;
933
+ return /* @__PURE__ */ f("section", {
934
+ className: ["sf-checkout-success", i].filter(Boolean).join(" "),
935
+ "data-status": t.status,
936
+ children: [
937
+ /* @__PURE__ */ d("h1", {
938
+ className: "sf-checkout-success__heading",
939
+ children: u.heading
940
+ }),
941
+ o && /* @__PURE__ */ d("p", {
942
+ className: "sf-checkout-success__reference",
943
+ children: u.reference.replace("{id}", t.id)
944
+ }),
945
+ a?.header,
946
+ /* @__PURE__ */ d("p", {
947
+ className: "sf-checkout-success__status",
948
+ children: u.status[t.status]
949
+ }),
950
+ s && /* @__PURE__ */ d("h2", {
951
+ className: "sf-checkout-success__summary-heading",
952
+ children: u.summaryHeading
953
+ }),
954
+ a?.beforeLines,
955
+ /* @__PURE__ */ d("ul", {
956
+ className: "sf-checkout-success__lines",
957
+ children: t.items.map((e) => /* @__PURE__ */ f("li", {
958
+ className: "sf-checkout-success__line",
959
+ children: [/* @__PURE__ */ f("span", { children: [
960
+ e.name,
961
+ " × ",
962
+ e.quantity
963
+ ] }), /* @__PURE__ */ d("span", { children: p(e.priceCents * e.quantity) })]
964
+ }, e.productId))
965
+ }),
966
+ /* @__PURE__ */ f("dl", {
967
+ className: "sf-checkout-success__totals",
968
+ children: [
969
+ /* @__PURE__ */ f("div", {
970
+ className: "sf-checkout-success__row",
971
+ children: [/* @__PURE__ */ d("dt", { children: u.subtotal }), /* @__PURE__ */ d("dd", { children: p(t.subtotalCents) })]
972
+ }),
973
+ t.discountCents > 0 && /* @__PURE__ */ f("div", {
974
+ className: "sf-checkout-success__row sf-checkout-success__row--discount",
975
+ "data-discount": !0,
976
+ children: [/* @__PURE__ */ f("dt", { children: [u.discount, t.discountCode && ` (${t.discountCode})`] }), /* @__PURE__ */ f("dd", { children: ["−", p(t.discountCents)] })]
977
+ }),
978
+ t.shippingLabel && /* @__PURE__ */ f("div", {
979
+ className: "sf-checkout-success__row",
980
+ children: [/* @__PURE__ */ f("dt", { children: [
981
+ u.shipping,
982
+ " (",
983
+ t.shippingLabel,
984
+ ")"
985
+ ] }), /* @__PURE__ */ d("dd", { children: p(t.shippingCents) })]
986
+ }),
987
+ /* @__PURE__ */ f("div", {
988
+ className: "sf-checkout-success__row sf-checkout-success__row--total",
989
+ children: [/* @__PURE__ */ d("dt", { children: u.total }), /* @__PURE__ */ d("dd", { children: p(t.totalCents) })]
990
+ })
991
+ ]
992
+ }),
993
+ a?.afterTotals,
994
+ m.length > 0 && /* @__PURE__ */ f("address", {
995
+ className: "sf-checkout-success__address",
996
+ children: [/* @__PURE__ */ d("strong", { children: u.shipTo }), m.map((e) => /* @__PURE__ */ d("span", { children: e }, e))]
997
+ }),
998
+ h?.trackingNumber && /* @__PURE__ */ f("p", {
999
+ className: "sf-checkout-success__tracking",
1000
+ children: [h.carrier && `${h.carrier} · `, h.trackingUrl ? /* @__PURE__ */ f("a", {
1001
+ href: h.trackingUrl,
1002
+ children: [
1003
+ u.tracking,
1004
+ " ",
1005
+ h.trackingNumber
1006
+ ]
1007
+ }) : h.trackingNumber]
1008
+ }),
1009
+ v && /* @__PURE__ */ d("div", {
1010
+ className: "sf-checkout-success__actions",
1011
+ children: v
1012
+ })
1013
+ ]
1014
+ });
1015
+ }
1016
+ // src/cart/clear-cart-on-mount.tsx
1017
+ function se() {
1018
+ let { hydrated: e, clear: t } = R(), n = c(!1);
1019
+ return a(() => {
1020
+ e && !n.current && (n.current = !0, t());
1021
+ }, [e, t]), null;
1022
+ }
1023
+ export { U as AddToCartButton, S as AvailabilityBadge, ie as CartButton, re as CartDrawer, G as CartLineItem, ee as CartProvider, X as CartSummary, T as CategoryFilter, oe as CheckoutSuccessView, se as ClearCartOnMount, k as FeaturedProducts, b as PriceTag, C as ProductCard, O as ProductDetailView, E as ProductGallery, w as ProductGrid, D as ShopView, v as StorefrontProvider, j as addLine, M as cartReducer, H as defaultAddToCartLabels, x as defaultAvailabilityLabels, Z as defaultCartDrawerLabels, W as defaultCartLineItemLabels, V as defaultCheckoutLabels, $ as defaultCheckoutSuccessLabels, B as discountReasonMessage, A as emptyCart, e as formatPrice, P as itemCount, F as localStorageCartStorage, t as sortForDisplay, N as subtotalCents, h as themeToCssVars, R as useCart, ne as useCheckout, y as useStorefront };
841
1024
 
842
1025
  //# sourceMappingURL=index.js.map