@merchi/cart 1.4.64 → 1.4.66

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.
@@ -19,7 +19,7 @@ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length)
19
19
  function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
20
20
  function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
21
21
  import * as React from 'react';
22
- import { createContext, useContext, useEffect, useRef, useState } from 'react';
22
+ import { createContext, useContext, useEffect, useLayoutEffect, useRef, useState } from 'react';
23
23
  import { faCheckCircle, faExclamationTriangle, faInfoCircle } from '@fortawesome/free-solid-svg-icons';
24
24
  import { makeCart, makeCartItem, stripeIsValidAndActive } from './utilities/cart';
25
25
  import { cartEmbed } from './utilities/helpers';
@@ -38,6 +38,7 @@ import { isAutomatedClient } from './utilities/automatedClient';
38
38
  import { canReplaceMissingCart } from './utilities/cartLoadFailure';
39
39
  import { appendJobSourceToFormData, captureAndReadJobSource, cartNeedsSourceUpdate, jobSourceFieldsForApi } from './utilities/job_source';
40
40
  import { jsx as _jsx } from "react/jsx-runtime";
41
+ var useCartBindingsEffect = typeof window === 'undefined' ? useEffect : useLayoutEffect;
41
42
  var CartContext = /*#__PURE__*/createContext({
42
43
  cart: {},
43
44
  cartClient: {},
@@ -903,11 +904,11 @@ var CartProvider = function CartProvider(_ref) {
903
904
  }
904
905
  function _getMerchiCartValues() {
905
906
  _getMerchiCartValues = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee1() {
906
- var _ref4, cartItems, currency, subtotalCost, taxAmount, totalCost, cartItemsCount;
907
+ var _ref3, cartItems, currency, subtotalCost, taxAmount, totalCost, cartItemsCount;
907
908
  return _regenerator().w(function (_context1) {
908
909
  while (1) switch (_context1.n) {
909
910
  case 0:
910
- _ref4 = cart, cartItems = _ref4.cartItems, currency = _ref4.currency, subtotalCost = _ref4.subtotalCost, taxAmount = _ref4.taxAmount, totalCost = _ref4.totalCost;
911
+ _ref3 = cart, cartItems = _ref3.cartItems, currency = _ref3.currency, subtotalCost = _ref3.subtotalCost, taxAmount = _ref3.taxAmount, totalCost = _ref3.totalCost;
911
912
  cartItemsCount = cartItems ? cartItems.length : 0;
912
913
  return _context1.a(2, {
913
914
  cart: cart,
@@ -1124,27 +1125,45 @@ var CartProvider = function CartProvider(_ref) {
1124
1125
  }
1125
1126
  };
1126
1127
 
1127
- // Set a global toggle function for cart wrapper
1128
- if (typeof window !== 'undefined') {
1129
- window.addCartItem = addCartItem;
1130
- window.toggleCartOpen = toggleCartModal;
1131
- window.getCart = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2() {
1132
- return _regenerator().w(function (_context2) {
1133
- while (1) switch (_context2.n) {
1134
- case 0:
1135
- _context2.n = 1;
1136
- return actionGetMerchiCart();
1137
- case 1:
1138
- return _context2.a(2);
1128
+ // Publish only committed providers. Suspense can discard render-time state,
1129
+ // so exposing these closures during render can strand a successful cart POST.
1130
+ useCartBindingsEffect(function () {
1131
+ var bindings = {
1132
+ addCartItem: addCartItem,
1133
+ toggleCartOpen: toggleCartModal,
1134
+ getCart: function () {
1135
+ var _getCart2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2() {
1136
+ return _regenerator().w(function (_context2) {
1137
+ while (1) switch (_context2.n) {
1138
+ case 0:
1139
+ _context2.n = 1;
1140
+ return actionGetMerchiCart();
1141
+ case 1:
1142
+ return _context2.a(2);
1143
+ }
1144
+ }, _callee2);
1145
+ }));
1146
+ function getCart() {
1147
+ return _getCart2.apply(this, arguments);
1139
1148
  }
1140
- }, _callee2);
1141
- }));
1142
- window.getMerchiCartValues = getMerchiCartValues;
1143
- window.isMerchiCartFetching = isMerchiCartFetching;
1144
- window.setCartComplete = setCartComplete;
1145
- window.refetchCart = refetchCart;
1146
- window.createCartAndCookie = requestNewCart;
1147
- }
1149
+ return getCart;
1150
+ }(),
1151
+ getMerchiCartValues: getMerchiCartValues,
1152
+ isMerchiCartFetching: isMerchiCartFetching,
1153
+ setCartComplete: setCartComplete,
1154
+ refetchCart: refetchCart,
1155
+ createCartAndCookie: requestNewCart
1156
+ };
1157
+ Object.assign(window, bindings);
1158
+ return function () {
1159
+ for (var _i = 0, _Object$entries = Object.entries(bindings); _i < _Object$entries.length; _i++) {
1160
+ var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
1161
+ name = _Object$entries$_i[0],
1162
+ binding = _Object$entries$_i[1];
1163
+ if (window[name] === binding) delete window[name];
1164
+ }
1165
+ };
1166
+ });
1148
1167
  useEffect(function () {
1149
1168
  persistTestCheckoutFlag();
1150
1169
  if (domainId) actionGetMerchiCart(!isAutomatedClient());