@shopify/hydrogen-react 2022.7.0 → 2022.10.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 -5
- package/dist/dev/CartProvider.cjs +485 -0
- package/dist/dev/CartProvider.cjs.map +1 -0
- package/dist/dev/CartProvider.js +485 -0
- package/dist/dev/CartProvider.js.map +1 -0
- package/dist/dev/MediaFile.cjs.map +1 -1
- package/dist/dev/MediaFile.js.map +1 -1
- package/dist/dev/Metafield.cjs +2 -2
- package/dist/dev/Metafield.cjs.map +1 -1
- package/dist/dev/Metafield.js.map +1 -1
- package/dist/dev/ModelViewer.cjs +4 -4
- package/dist/dev/ModelViewer.cjs.map +1 -1
- package/dist/dev/Money.cjs.map +1 -1
- package/dist/dev/Money.js.map +1 -1
- package/dist/dev/ProductPrice.cjs.map +1 -1
- package/dist/dev/ProductPrice.js.map +1 -1
- package/dist/dev/ProductProvider.cjs +14 -14
- package/dist/dev/ProductProvider.cjs.map +1 -1
- package/dist/dev/ShopPayButton.cjs.map +1 -1
- package/dist/dev/ShopPayButton.js.map +1 -1
- package/dist/dev/ShopifyProvider.cjs +4 -4
- package/dist/dev/ShopifyProvider.cjs.map +1 -1
- package/dist/dev/Video.cjs +2 -2
- package/dist/dev/_virtual/index.cjs +5 -0
- package/dist/dev/_virtual/index.cjs.map +1 -0
- package/dist/dev/_virtual/index.js +5 -0
- package/dist/dev/_virtual/index.js.map +1 -0
- package/dist/dev/_virtual/use-sync-external-store-shim.development.cjs +5 -0
- package/dist/dev/_virtual/use-sync-external-store-shim.development.cjs.map +1 -0
- package/dist/dev/_virtual/use-sync-external-store-shim.development.js +5 -0
- package/dist/dev/_virtual/use-sync-external-store-shim.development.js.map +1 -0
- package/dist/dev/_virtual/use-sync-external-store-shim.production.min.cjs +5 -0
- package/dist/dev/_virtual/use-sync-external-store-shim.production.min.cjs.map +1 -0
- package/dist/dev/_virtual/use-sync-external-store-shim.production.min.js +5 -0
- package/dist/dev/_virtual/use-sync-external-store-shim.production.min.js.map +1 -0
- package/dist/dev/_virtual/with-selector.cjs +5 -0
- package/dist/dev/_virtual/with-selector.cjs.map +1 -0
- package/dist/dev/_virtual/with-selector.development.cjs +5 -0
- package/dist/dev/_virtual/with-selector.development.cjs.map +1 -0
- package/dist/dev/_virtual/with-selector.development.js +5 -0
- package/dist/dev/_virtual/with-selector.development.js.map +1 -0
- package/dist/dev/_virtual/with-selector.js +5 -0
- package/dist/dev/_virtual/with-selector.js.map +1 -0
- package/dist/dev/_virtual/with-selector.production.min.cjs +5 -0
- package/dist/dev/_virtual/with-selector.production.min.cjs.map +1 -0
- package/dist/dev/_virtual/with-selector.production.min.js +5 -0
- package/dist/dev/_virtual/with-selector.production.min.js.map +1 -0
- package/dist/dev/cart-constants.cjs +17 -0
- package/dist/dev/cart-constants.cjs.map +1 -0
- package/dist/dev/cart-constants.js +17 -0
- package/dist/dev/cart-constants.js.map +1 -0
- package/dist/dev/cart-hooks.cjs +48 -0
- package/dist/dev/cart-hooks.cjs.map +1 -0
- package/dist/dev/cart-hooks.js +48 -0
- package/dist/dev/cart-hooks.js.map +1 -0
- package/dist/dev/cart-queries.cjs +114 -0
- package/dist/dev/cart-queries.cjs.map +1 -0
- package/dist/dev/cart-queries.js +114 -0
- package/dist/dev/cart-queries.js.map +1 -0
- package/dist/dev/flatten-connection.cjs +6 -0
- package/dist/dev/flatten-connection.cjs.map +1 -1
- package/dist/dev/flatten-connection.js +6 -0
- package/dist/dev/flatten-connection.js.map +1 -1
- package/dist/dev/index.cjs +3 -0
- package/dist/dev/index.cjs.map +1 -1
- package/dist/dev/index.js +3 -0
- package/dist/dev/index.js.map +1 -1
- package/dist/dev/load-script.cjs +3 -3
- package/dist/dev/load-script.cjs.map +1 -1
- package/dist/dev/node_modules/@xstate/fsm/es/index.cjs +158 -0
- package/dist/dev/node_modules/@xstate/fsm/es/index.cjs.map +1 -0
- package/dist/dev/node_modules/@xstate/fsm/es/index.js +159 -0
- package/dist/dev/node_modules/@xstate/fsm/es/index.js.map +1 -0
- package/dist/dev/node_modules/@xstate/react/es/fsm.cjs +94 -0
- package/dist/dev/node_modules/@xstate/react/es/fsm.cjs.map +1 -0
- package/dist/dev/node_modules/@xstate/react/es/fsm.js +94 -0
- package/dist/dev/node_modules/@xstate/react/es/fsm.js.map +1 -0
- package/dist/dev/node_modules/@xstate/react/es/useConstant.cjs +30 -0
- package/dist/dev/node_modules/@xstate/react/es/useConstant.cjs.map +1 -0
- package/dist/dev/node_modules/@xstate/react/es/useConstant.js +12 -0
- package/dist/dev/node_modules/@xstate/react/es/useConstant.js.map +1 -0
- package/dist/dev/node_modules/use-isomorphic-layout-effect/dist/use-isomorphic-layout-effect.browser.esm.cjs +5 -0
- package/dist/dev/node_modules/use-isomorphic-layout-effect/dist/use-isomorphic-layout-effect.browser.esm.cjs.map +1 -0
- package/dist/dev/node_modules/use-isomorphic-layout-effect/dist/use-isomorphic-layout-effect.browser.esm.js +6 -0
- package/dist/dev/node_modules/use-isomorphic-layout-effect/dist/use-isomorphic-layout-effect.browser.esm.js.map +1 -0
- package/dist/dev/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.development.cjs +107 -0
- package/dist/dev/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.development.cjs.map +1 -0
- package/dist/dev/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.development.js +105 -0
- package/dist/dev/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.development.js.map +1 -0
- package/dist/dev/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.production.min.cjs +74 -0
- package/dist/dev/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.production.min.cjs.map +1 -0
- package/dist/dev/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.production.min.js +72 -0
- package/dist/dev/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.production.min.js.map +1 -0
- package/dist/dev/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.development.cjs +138 -0
- package/dist/dev/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.development.cjs.map +1 -0
- package/dist/dev/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.development.js +136 -0
- package/dist/dev/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.development.js.map +1 -0
- package/dist/dev/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.production.min.cjs +60 -0
- package/dist/dev/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.production.min.cjs.map +1 -0
- package/dist/dev/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.production.min.js +58 -0
- package/dist/dev/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.production.min.js.map +1 -0
- package/dist/dev/node_modules/use-sync-external-store/shim/index.cjs +21 -0
- package/dist/dev/node_modules/use-sync-external-store/shim/index.cjs.map +1 -0
- package/dist/dev/node_modules/use-sync-external-store/shim/index.js +21 -0
- package/dist/dev/node_modules/use-sync-external-store/shim/index.js.map +1 -0
- package/dist/dev/node_modules/use-sync-external-store/shim/with-selector.cjs +12 -0
- package/dist/dev/node_modules/use-sync-external-store/shim/with-selector.cjs.map +1 -0
- package/dist/dev/node_modules/use-sync-external-store/shim/with-selector.js +11 -0
- package/dist/dev/node_modules/use-sync-external-store/shim/with-selector.js.map +1 -0
- package/dist/dev/node_modules/worktop/cookie/index.cjs +27 -0
- package/dist/dev/node_modules/worktop/cookie/index.cjs.map +1 -0
- package/dist/dev/node_modules/worktop/cookie/index.js +27 -0
- package/dist/dev/node_modules/worktop/cookie/index.js.map +1 -0
- package/dist/dev/storefront-api-constants.cjs +1 -1
- package/dist/dev/storefront-api-constants.cjs.map +1 -1
- package/dist/dev/storefront-api-constants.js +1 -1
- package/dist/dev/storefront-api-constants.js.map +1 -1
- package/dist/dev/useCartAPIStateMachine.cjs +326 -0
- package/dist/dev/useCartAPIStateMachine.cjs.map +1 -0
- package/dist/dev/useCartAPIStateMachine.js +326 -0
- package/dist/dev/useCartAPIStateMachine.js.map +1 -0
- package/dist/dev/useCartActions.cjs +123 -0
- package/dist/dev/useCartActions.cjs.map +1 -0
- package/dist/dev/useCartActions.js +123 -0
- package/dist/dev/useCartActions.js.map +1 -0
- package/dist/dev/useMoney.cjs +5 -5
- package/dist/dev/useMoney.cjs.map +1 -1
- package/dist/prod/CartProvider.cjs +485 -0
- package/dist/prod/CartProvider.cjs.map +1 -0
- package/dist/prod/CartProvider.js +485 -0
- package/dist/prod/CartProvider.js.map +1 -0
- package/dist/prod/MediaFile.cjs.map +1 -1
- package/dist/prod/MediaFile.js.map +1 -1
- package/dist/prod/Metafield.cjs +2 -2
- package/dist/prod/Metafield.cjs.map +1 -1
- package/dist/prod/Metafield.js.map +1 -1
- package/dist/prod/ModelViewer.cjs +4 -4
- package/dist/prod/ModelViewer.cjs.map +1 -1
- package/dist/prod/Money.cjs.map +1 -1
- package/dist/prod/Money.js.map +1 -1
- package/dist/prod/ProductPrice.cjs.map +1 -1
- package/dist/prod/ProductPrice.js.map +1 -1
- package/dist/prod/ProductProvider.cjs +14 -14
- package/dist/prod/ProductProvider.cjs.map +1 -1
- package/dist/prod/ShopPayButton.cjs.map +1 -1
- package/dist/prod/ShopPayButton.js.map +1 -1
- package/dist/prod/ShopifyProvider.cjs +4 -4
- package/dist/prod/ShopifyProvider.cjs.map +1 -1
- package/dist/prod/Video.cjs +2 -2
- package/dist/prod/_virtual/index.cjs +5 -0
- package/dist/prod/_virtual/index.cjs.map +1 -0
- package/dist/prod/_virtual/index.js +5 -0
- package/dist/prod/_virtual/index.js.map +1 -0
- package/dist/prod/_virtual/use-sync-external-store-shim.development.cjs +5 -0
- package/dist/prod/_virtual/use-sync-external-store-shim.development.cjs.map +1 -0
- package/dist/prod/_virtual/use-sync-external-store-shim.development.js +5 -0
- package/dist/prod/_virtual/use-sync-external-store-shim.development.js.map +1 -0
- package/dist/prod/_virtual/use-sync-external-store-shim.production.min.cjs +5 -0
- package/dist/prod/_virtual/use-sync-external-store-shim.production.min.cjs.map +1 -0
- package/dist/prod/_virtual/use-sync-external-store-shim.production.min.js +5 -0
- package/dist/prod/_virtual/use-sync-external-store-shim.production.min.js.map +1 -0
- package/dist/prod/_virtual/with-selector.cjs +5 -0
- package/dist/prod/_virtual/with-selector.cjs.map +1 -0
- package/dist/prod/_virtual/with-selector.development.cjs +5 -0
- package/dist/prod/_virtual/with-selector.development.cjs.map +1 -0
- package/dist/prod/_virtual/with-selector.development.js +5 -0
- package/dist/prod/_virtual/with-selector.development.js.map +1 -0
- package/dist/prod/_virtual/with-selector.js +5 -0
- package/dist/prod/_virtual/with-selector.js.map +1 -0
- package/dist/prod/_virtual/with-selector.production.min.cjs +5 -0
- package/dist/prod/_virtual/with-selector.production.min.cjs.map +1 -0
- package/dist/prod/_virtual/with-selector.production.min.js +5 -0
- package/dist/prod/_virtual/with-selector.production.min.js.map +1 -0
- package/dist/prod/cart-constants.cjs +17 -0
- package/dist/prod/cart-constants.cjs.map +1 -0
- package/dist/prod/cart-constants.js +17 -0
- package/dist/prod/cart-constants.js.map +1 -0
- package/dist/prod/cart-hooks.cjs +48 -0
- package/dist/prod/cart-hooks.cjs.map +1 -0
- package/dist/prod/cart-hooks.js +48 -0
- package/dist/prod/cart-hooks.js.map +1 -0
- package/dist/prod/cart-queries.cjs +114 -0
- package/dist/prod/cart-queries.cjs.map +1 -0
- package/dist/prod/cart-queries.js +114 -0
- package/dist/prod/cart-queries.js.map +1 -0
- package/dist/prod/flatten-connection.cjs +7 -0
- package/dist/prod/flatten-connection.cjs.map +1 -1
- package/dist/prod/flatten-connection.js +7 -0
- package/dist/prod/flatten-connection.js.map +1 -1
- package/dist/prod/index.cjs +3 -0
- package/dist/prod/index.cjs.map +1 -1
- package/dist/prod/index.js +3 -0
- package/dist/prod/index.js.map +1 -1
- package/dist/prod/load-script.cjs +3 -3
- package/dist/prod/load-script.cjs.map +1 -1
- package/dist/prod/node_modules/@xstate/fsm/es/index.cjs +158 -0
- package/dist/prod/node_modules/@xstate/fsm/es/index.cjs.map +1 -0
- package/dist/prod/node_modules/@xstate/fsm/es/index.js +159 -0
- package/dist/prod/node_modules/@xstate/fsm/es/index.js.map +1 -0
- package/dist/prod/node_modules/@xstate/react/es/fsm.cjs +94 -0
- package/dist/prod/node_modules/@xstate/react/es/fsm.cjs.map +1 -0
- package/dist/prod/node_modules/@xstate/react/es/fsm.js +94 -0
- package/dist/prod/node_modules/@xstate/react/es/fsm.js.map +1 -0
- package/dist/prod/node_modules/@xstate/react/es/useConstant.cjs +30 -0
- package/dist/prod/node_modules/@xstate/react/es/useConstant.cjs.map +1 -0
- package/dist/prod/node_modules/@xstate/react/es/useConstant.js +12 -0
- package/dist/prod/node_modules/@xstate/react/es/useConstant.js.map +1 -0
- package/dist/prod/node_modules/use-isomorphic-layout-effect/dist/use-isomorphic-layout-effect.browser.esm.cjs +5 -0
- package/dist/prod/node_modules/use-isomorphic-layout-effect/dist/use-isomorphic-layout-effect.browser.esm.cjs.map +1 -0
- package/dist/prod/node_modules/use-isomorphic-layout-effect/dist/use-isomorphic-layout-effect.browser.esm.js +6 -0
- package/dist/prod/node_modules/use-isomorphic-layout-effect/dist/use-isomorphic-layout-effect.browser.esm.js.map +1 -0
- package/dist/prod/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.development.cjs +107 -0
- package/dist/prod/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.development.cjs.map +1 -0
- package/dist/prod/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.development.js +105 -0
- package/dist/prod/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.development.js.map +1 -0
- package/dist/prod/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.production.min.cjs +74 -0
- package/dist/prod/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.production.min.cjs.map +1 -0
- package/dist/prod/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.production.min.js +72 -0
- package/dist/prod/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.production.min.js.map +1 -0
- package/dist/prod/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.development.cjs +138 -0
- package/dist/prod/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.development.cjs.map +1 -0
- package/dist/prod/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.development.js +136 -0
- package/dist/prod/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.development.js.map +1 -0
- package/dist/prod/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.production.min.cjs +60 -0
- package/dist/prod/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.production.min.cjs.map +1 -0
- package/dist/prod/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.production.min.js +58 -0
- package/dist/prod/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.production.min.js.map +1 -0
- package/dist/prod/node_modules/use-sync-external-store/shim/index.cjs +21 -0
- package/dist/prod/node_modules/use-sync-external-store/shim/index.cjs.map +1 -0
- package/dist/prod/node_modules/use-sync-external-store/shim/index.js +21 -0
- package/dist/prod/node_modules/use-sync-external-store/shim/index.js.map +1 -0
- package/dist/prod/node_modules/use-sync-external-store/shim/with-selector.cjs +12 -0
- package/dist/prod/node_modules/use-sync-external-store/shim/with-selector.cjs.map +1 -0
- package/dist/prod/node_modules/use-sync-external-store/shim/with-selector.js +11 -0
- package/dist/prod/node_modules/use-sync-external-store/shim/with-selector.js.map +1 -0
- package/dist/prod/node_modules/worktop/cookie/index.cjs +27 -0
- package/dist/prod/node_modules/worktop/cookie/index.cjs.map +1 -0
- package/dist/prod/node_modules/worktop/cookie/index.js +27 -0
- package/dist/prod/node_modules/worktop/cookie/index.js.map +1 -0
- package/dist/prod/storefront-api-constants.cjs +1 -1
- package/dist/prod/storefront-api-constants.cjs.map +1 -1
- package/dist/prod/storefront-api-constants.js +1 -1
- package/dist/prod/storefront-api-constants.js.map +1 -1
- package/dist/prod/useCartAPIStateMachine.cjs +326 -0
- package/dist/prod/useCartAPIStateMachine.cjs.map +1 -0
- package/dist/prod/useCartAPIStateMachine.js +326 -0
- package/dist/prod/useCartAPIStateMachine.js.map +1 -0
- package/dist/prod/useCartActions.cjs +123 -0
- package/dist/prod/useCartActions.cjs.map +1 -0
- package/dist/prod/useCartActions.js +123 -0
- package/dist/prod/useCartActions.js.map +1 -0
- package/dist/prod/useMoney.cjs +5 -5
- package/dist/prod/useMoney.cjs.map +1 -1
- package/dist/types/CartProvider.d.ts +61 -0
- package/dist/types/MediaFile.d.ts +0 -1
- package/dist/types/Money.d.ts +1 -1
- package/dist/types/ProductPrice.d.ts +0 -1
- package/dist/types/cart-constants.d.ts +8 -0
- package/dist/types/cart-hooks.d.ts +24 -0
- package/dist/types/cart-queries.d.ts +10 -0
- package/dist/types/cart-types.d.ts +289 -0
- package/dist/types/flatten-connection.d.ts +3 -1
- package/dist/types/index.d.cts +2 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/storefront-api-constants.d.ts +1 -1
- package/dist/types/storefront-api-types.d.ts +278 -73
- package/dist/types/useCartAPIStateMachine.d.ts +25 -0
- package/dist/types/useCartActions.d.ts +64 -0
- package/dist/umd/hydrogen-react.dev.js +1815 -109
- package/dist/umd/hydrogen-react.dev.js.map +1 -1
- package/dist/umd/hydrogen-react.prod.js +239 -2
- package/dist/umd/hydrogen-react.prod.js.map +1 -1
- package/package.json +24 -12
- package/storefront.schema.json +1 -1
|
@@ -2,28 +2,1796 @@
|
|
|
2
2
|
typeof exports === "object" && typeof module !== "undefined" ? factory(exports, require("react")) : typeof define === "function" && define.amd ? define(["exports", "react"], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory(global.hydrogenreact = {}, global.React));
|
|
3
3
|
})(this, function(exports2, React) {
|
|
4
4
|
"use strict";
|
|
5
|
-
const _interopDefaultLegacy = (
|
|
6
|
-
function _interopNamespace(
|
|
7
|
-
if (
|
|
8
|
-
return
|
|
9
|
-
const
|
|
10
|
-
if (
|
|
11
|
-
for (const k in
|
|
5
|
+
const _interopDefaultLegacy = (e2) => e2 && typeof e2 === "object" && "default" in e2 ? e2 : { default: e2 };
|
|
6
|
+
function _interopNamespace(e2) {
|
|
7
|
+
if (e2 && e2.__esModule)
|
|
8
|
+
return e2;
|
|
9
|
+
const n2 = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
10
|
+
if (e2) {
|
|
11
|
+
for (const k in e2) {
|
|
12
12
|
if (k !== "default") {
|
|
13
|
-
const d = Object.getOwnPropertyDescriptor(
|
|
14
|
-
Object.defineProperty(
|
|
13
|
+
const d = Object.getOwnPropertyDescriptor(e2, k);
|
|
14
|
+
Object.defineProperty(n2, k, d.get ? d : {
|
|
15
15
|
enumerable: true,
|
|
16
|
-
get: () =>
|
|
16
|
+
get: () => e2[k]
|
|
17
17
|
});
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
|
-
|
|
22
|
-
return Object.freeze(
|
|
21
|
+
n2.default = e2;
|
|
22
|
+
return Object.freeze(n2);
|
|
23
23
|
}
|
|
24
24
|
const React__default = /* @__PURE__ */ _interopDefaultLegacy(React);
|
|
25
25
|
const React__namespace = /* @__PURE__ */ _interopNamespace(React);
|
|
26
|
-
|
|
26
|
+
/*! *****************************************************************************
|
|
27
|
+
Copyright (c) Microsoft Corporation.
|
|
28
|
+
|
|
29
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
30
|
+
purpose with or without fee is hereby granted.
|
|
31
|
+
|
|
32
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
33
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
34
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
35
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
36
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
37
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
38
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
39
|
+
***************************************************************************** */
|
|
40
|
+
function t(t2, n2) {
|
|
41
|
+
var e2 = "function" == typeof Symbol && t2[Symbol.iterator];
|
|
42
|
+
if (!e2)
|
|
43
|
+
return t2;
|
|
44
|
+
var r2, i2, o2 = e2.call(t2), a2 = [];
|
|
45
|
+
try {
|
|
46
|
+
for (; (void 0 === n2 || n2-- > 0) && !(r2 = o2.next()).done; )
|
|
47
|
+
a2.push(r2.value);
|
|
48
|
+
} catch (t3) {
|
|
49
|
+
i2 = { error: t3 };
|
|
50
|
+
} finally {
|
|
51
|
+
try {
|
|
52
|
+
r2 && !r2.done && (e2 = o2.return) && e2.call(o2);
|
|
53
|
+
} finally {
|
|
54
|
+
if (i2)
|
|
55
|
+
throw i2.error;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return a2;
|
|
59
|
+
}
|
|
60
|
+
var n;
|
|
61
|
+
!function(t2) {
|
|
62
|
+
t2[t2.NotStarted = 0] = "NotStarted", t2[t2.Running = 1] = "Running", t2[t2.Stopped = 2] = "Stopped";
|
|
63
|
+
}(n || (n = {}));
|
|
64
|
+
var e = { type: "xstate.init" };
|
|
65
|
+
function r(t2) {
|
|
66
|
+
return void 0 === t2 ? [] : [].concat(t2);
|
|
67
|
+
}
|
|
68
|
+
function i(t2) {
|
|
69
|
+
return { type: "xstate.assign", assignment: t2 };
|
|
70
|
+
}
|
|
71
|
+
function o(t2, n2) {
|
|
72
|
+
return "string" == typeof (t2 = "string" == typeof t2 && n2 && n2[t2] ? n2[t2] : t2) ? { type: t2 } : "function" == typeof t2 ? { type: t2.name, exec: t2 } : t2;
|
|
73
|
+
}
|
|
74
|
+
function a(t2) {
|
|
75
|
+
return function(n2) {
|
|
76
|
+
return t2 === n2;
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
function u$1(t2) {
|
|
80
|
+
return "string" == typeof t2 ? { type: t2 } : t2;
|
|
81
|
+
}
|
|
82
|
+
function c(t2, n2) {
|
|
83
|
+
return { value: t2, context: n2, actions: [], changed: false, matches: a(t2) };
|
|
84
|
+
}
|
|
85
|
+
function f(t2, n2, e2) {
|
|
86
|
+
var r2 = n2, i2 = false;
|
|
87
|
+
return [t2.filter(function(t3) {
|
|
88
|
+
if ("xstate.assign" === t3.type) {
|
|
89
|
+
i2 = true;
|
|
90
|
+
var n3 = Object.assign({}, r2);
|
|
91
|
+
return "function" == typeof t3.assignment ? n3 = t3.assignment(r2, e2) : Object.keys(t3.assignment).forEach(function(i3) {
|
|
92
|
+
n3[i3] = "function" == typeof t3.assignment[i3] ? t3.assignment[i3](r2, e2) : t3.assignment[i3];
|
|
93
|
+
}), r2 = n3, false;
|
|
94
|
+
}
|
|
95
|
+
return true;
|
|
96
|
+
}), r2, i2];
|
|
97
|
+
}
|
|
98
|
+
function s(n2, i2) {
|
|
99
|
+
void 0 === i2 && (i2 = {});
|
|
100
|
+
var s2 = t(f(r(n2.states[n2.initial].entry).map(function(t2) {
|
|
101
|
+
return o(t2, i2.actions);
|
|
102
|
+
}), n2.context, e), 2), l2 = s2[0], v2 = s2[1], y = { config: n2, _options: i2, initialState: { value: n2.initial, actions: l2, context: v2, matches: a(n2.initial) }, transition: function(e2, i3) {
|
|
103
|
+
var s3, l3, v3 = "string" == typeof e2 ? { value: e2, context: n2.context } : e2, p = v3.value, g2 = v3.context, d = u$1(i3), x = n2.states[p];
|
|
104
|
+
if (x.on) {
|
|
105
|
+
var m = r(x.on[d.type]);
|
|
106
|
+
try {
|
|
107
|
+
for (var h = function(t2) {
|
|
108
|
+
var n3 = "function" == typeof Symbol && Symbol.iterator, e3 = n3 && t2[n3], r2 = 0;
|
|
109
|
+
if (e3)
|
|
110
|
+
return e3.call(t2);
|
|
111
|
+
if (t2 && "number" == typeof t2.length)
|
|
112
|
+
return { next: function() {
|
|
113
|
+
return t2 && r2 >= t2.length && (t2 = void 0), { value: t2 && t2[r2++], done: !t2 };
|
|
114
|
+
} };
|
|
115
|
+
throw new TypeError(n3 ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
116
|
+
}(m), b = h.next(); !b.done; b = h.next()) {
|
|
117
|
+
var S = b.value;
|
|
118
|
+
if (void 0 === S)
|
|
119
|
+
return c(p, g2);
|
|
120
|
+
var w = "string" == typeof S ? { target: S } : S, j = w.target, E = w.actions, R = void 0 === E ? [] : E, N = w.cond, O = void 0 === N ? function() {
|
|
121
|
+
return true;
|
|
122
|
+
} : N, _ = void 0 === j, k = null != j ? j : p, T = n2.states[k];
|
|
123
|
+
if (O(g2, d)) {
|
|
124
|
+
var q = t(f((_ ? r(R) : [].concat(x.exit, R, T.entry).filter(function(t2) {
|
|
125
|
+
return t2;
|
|
126
|
+
})).map(function(t2) {
|
|
127
|
+
return o(t2, y._options.actions);
|
|
128
|
+
}), g2, d), 3), z = q[0], A = q[1], B = q[2], C = null != j ? j : p;
|
|
129
|
+
return { value: C, context: A, actions: z, changed: j !== p || z.length > 0 || B, matches: a(C) };
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
} catch (t2) {
|
|
133
|
+
s3 = { error: t2 };
|
|
134
|
+
} finally {
|
|
135
|
+
try {
|
|
136
|
+
b && !b.done && (l3 = h.return) && l3.call(h);
|
|
137
|
+
} finally {
|
|
138
|
+
if (s3)
|
|
139
|
+
throw s3.error;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
return c(p, g2);
|
|
144
|
+
} };
|
|
145
|
+
return y;
|
|
146
|
+
}
|
|
147
|
+
var l = function(t2, n2) {
|
|
148
|
+
return t2.actions.forEach(function(e2) {
|
|
149
|
+
var r2 = e2.exec;
|
|
150
|
+
return r2 && r2(t2.context, n2);
|
|
151
|
+
});
|
|
152
|
+
};
|
|
153
|
+
function v(t2) {
|
|
154
|
+
var r2 = t2.initialState, i2 = n.NotStarted, o2 = /* @__PURE__ */ new Set(), c2 = { _machine: t2, send: function(e2) {
|
|
155
|
+
i2 === n.Running && (r2 = t2.transition(r2, e2), l(r2, u$1(e2)), o2.forEach(function(t3) {
|
|
156
|
+
return t3(r2);
|
|
157
|
+
}));
|
|
158
|
+
}, subscribe: function(t3) {
|
|
159
|
+
return o2.add(t3), t3(r2), { unsubscribe: function() {
|
|
160
|
+
return o2.delete(t3);
|
|
161
|
+
} };
|
|
162
|
+
}, start: function(o3) {
|
|
163
|
+
if (o3) {
|
|
164
|
+
var u2 = "object" == typeof o3 ? o3 : { context: t2.config.context, value: o3 };
|
|
165
|
+
r2 = { value: u2.value, actions: [], context: u2.context, matches: a(u2.value) };
|
|
166
|
+
} else
|
|
167
|
+
r2 = t2.initialState;
|
|
168
|
+
return i2 = n.Running, l(r2, e), c2;
|
|
169
|
+
}, stop: function() {
|
|
170
|
+
return i2 = n.Stopped, o2.clear(), c2;
|
|
171
|
+
}, get state() {
|
|
172
|
+
return r2;
|
|
173
|
+
}, get status() {
|
|
174
|
+
return i2;
|
|
175
|
+
} };
|
|
176
|
+
return c2;
|
|
177
|
+
}
|
|
178
|
+
var index = React.useLayoutEffect;
|
|
179
|
+
var withSelector = { exports: {} };
|
|
180
|
+
var withSelector_production_min = {};
|
|
181
|
+
var shim = { exports: {} };
|
|
182
|
+
var useSyncExternalStoreShim_production_min = {};
|
|
183
|
+
/**
|
|
184
|
+
* @license React
|
|
185
|
+
* use-sync-external-store-shim.production.min.js
|
|
186
|
+
*
|
|
187
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
188
|
+
*
|
|
189
|
+
* This source code is licensed under the MIT license found in the
|
|
190
|
+
* LICENSE file in the root directory of this source tree.
|
|
191
|
+
*/
|
|
192
|
+
var hasRequiredUseSyncExternalStoreShim_production_min;
|
|
193
|
+
function requireUseSyncExternalStoreShim_production_min() {
|
|
194
|
+
if (hasRequiredUseSyncExternalStoreShim_production_min)
|
|
195
|
+
return useSyncExternalStoreShim_production_min;
|
|
196
|
+
hasRequiredUseSyncExternalStoreShim_production_min = 1;
|
|
197
|
+
var e2 = React__default.default;
|
|
198
|
+
function h(a2, b) {
|
|
199
|
+
return a2 === b && (0 !== a2 || 1 / a2 === 1 / b) || a2 !== a2 && b !== b;
|
|
200
|
+
}
|
|
201
|
+
var k = "function" === typeof Object.is ? Object.is : h, l2 = e2.useState, m = e2.useEffect, n2 = e2.useLayoutEffect, p = e2.useDebugValue;
|
|
202
|
+
function q(a2, b) {
|
|
203
|
+
var d = b(), f2 = l2({ inst: { value: d, getSnapshot: b } }), c2 = f2[0].inst, g2 = f2[1];
|
|
204
|
+
n2(function() {
|
|
205
|
+
c2.value = d;
|
|
206
|
+
c2.getSnapshot = b;
|
|
207
|
+
r2(c2) && g2({ inst: c2 });
|
|
208
|
+
}, [a2, d, b]);
|
|
209
|
+
m(function() {
|
|
210
|
+
r2(c2) && g2({ inst: c2 });
|
|
211
|
+
return a2(function() {
|
|
212
|
+
r2(c2) && g2({ inst: c2 });
|
|
213
|
+
});
|
|
214
|
+
}, [a2]);
|
|
215
|
+
p(d);
|
|
216
|
+
return d;
|
|
217
|
+
}
|
|
218
|
+
function r2(a2) {
|
|
219
|
+
var b = a2.getSnapshot;
|
|
220
|
+
a2 = a2.value;
|
|
221
|
+
try {
|
|
222
|
+
var d = b();
|
|
223
|
+
return !k(a2, d);
|
|
224
|
+
} catch (f2) {
|
|
225
|
+
return true;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
function t2(a2, b) {
|
|
229
|
+
return b();
|
|
230
|
+
}
|
|
231
|
+
var u2 = "undefined" === typeof window || "undefined" === typeof window.document || "undefined" === typeof window.document.createElement ? t2 : q;
|
|
232
|
+
useSyncExternalStoreShim_production_min.useSyncExternalStore = void 0 !== e2.useSyncExternalStore ? e2.useSyncExternalStore : u2;
|
|
233
|
+
return useSyncExternalStoreShim_production_min;
|
|
234
|
+
}
|
|
235
|
+
var useSyncExternalStoreShim_development = {};
|
|
236
|
+
/**
|
|
237
|
+
* @license React
|
|
238
|
+
* use-sync-external-store-shim.development.js
|
|
239
|
+
*
|
|
240
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
241
|
+
*
|
|
242
|
+
* This source code is licensed under the MIT license found in the
|
|
243
|
+
* LICENSE file in the root directory of this source tree.
|
|
244
|
+
*/
|
|
245
|
+
var hasRequiredUseSyncExternalStoreShim_development;
|
|
246
|
+
function requireUseSyncExternalStoreShim_development() {
|
|
247
|
+
if (hasRequiredUseSyncExternalStoreShim_development)
|
|
248
|
+
return useSyncExternalStoreShim_development;
|
|
249
|
+
hasRequiredUseSyncExternalStoreShim_development = 1;
|
|
250
|
+
if (process.env.NODE_ENV !== "production") {
|
|
251
|
+
(function() {
|
|
252
|
+
if (typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== "undefined" && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart === "function") {
|
|
253
|
+
__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error());
|
|
254
|
+
}
|
|
255
|
+
var React2 = React__default.default;
|
|
256
|
+
var ReactSharedInternals = React2.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
|
|
257
|
+
function error(format) {
|
|
258
|
+
{
|
|
259
|
+
{
|
|
260
|
+
for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
|
|
261
|
+
args[_key2 - 1] = arguments[_key2];
|
|
262
|
+
}
|
|
263
|
+
printWarning("error", format, args);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
function printWarning(level, format, args) {
|
|
268
|
+
{
|
|
269
|
+
var ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame;
|
|
270
|
+
var stack = ReactDebugCurrentFrame.getStackAddendum();
|
|
271
|
+
if (stack !== "") {
|
|
272
|
+
format += "%s";
|
|
273
|
+
args = args.concat([stack]);
|
|
274
|
+
}
|
|
275
|
+
var argsWithFormat = args.map(function(item) {
|
|
276
|
+
return String(item);
|
|
277
|
+
});
|
|
278
|
+
argsWithFormat.unshift("Warning: " + format);
|
|
279
|
+
Function.prototype.apply.call(console[level], console, argsWithFormat);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
function is(x, y) {
|
|
283
|
+
return x === y && (x !== 0 || 1 / x === 1 / y) || x !== x && y !== y;
|
|
284
|
+
}
|
|
285
|
+
var objectIs = typeof Object.is === "function" ? Object.is : is;
|
|
286
|
+
var useState = React2.useState, useEffect = React2.useEffect, useLayoutEffect = React2.useLayoutEffect, useDebugValue = React2.useDebugValue;
|
|
287
|
+
var didWarnOld18Alpha = false;
|
|
288
|
+
var didWarnUncachedGetSnapshot = false;
|
|
289
|
+
function useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot) {
|
|
290
|
+
{
|
|
291
|
+
if (!didWarnOld18Alpha) {
|
|
292
|
+
if (React2.startTransition !== void 0) {
|
|
293
|
+
didWarnOld18Alpha = true;
|
|
294
|
+
error("You are using an outdated, pre-release alpha of React 18 that does not support useSyncExternalStore. The use-sync-external-store shim will not work correctly. Upgrade to a newer pre-release.");
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
var value = getSnapshot();
|
|
299
|
+
{
|
|
300
|
+
if (!didWarnUncachedGetSnapshot) {
|
|
301
|
+
var cachedValue = getSnapshot();
|
|
302
|
+
if (!objectIs(value, cachedValue)) {
|
|
303
|
+
error("The result of getSnapshot should be cached to avoid an infinite loop");
|
|
304
|
+
didWarnUncachedGetSnapshot = true;
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
var _useState = useState({
|
|
309
|
+
inst: {
|
|
310
|
+
value,
|
|
311
|
+
getSnapshot
|
|
312
|
+
}
|
|
313
|
+
}), inst = _useState[0].inst, forceUpdate = _useState[1];
|
|
314
|
+
useLayoutEffect(function() {
|
|
315
|
+
inst.value = value;
|
|
316
|
+
inst.getSnapshot = getSnapshot;
|
|
317
|
+
if (checkIfSnapshotChanged(inst)) {
|
|
318
|
+
forceUpdate({
|
|
319
|
+
inst
|
|
320
|
+
});
|
|
321
|
+
}
|
|
322
|
+
}, [subscribe, value, getSnapshot]);
|
|
323
|
+
useEffect(function() {
|
|
324
|
+
if (checkIfSnapshotChanged(inst)) {
|
|
325
|
+
forceUpdate({
|
|
326
|
+
inst
|
|
327
|
+
});
|
|
328
|
+
}
|
|
329
|
+
var handleStoreChange = function() {
|
|
330
|
+
if (checkIfSnapshotChanged(inst)) {
|
|
331
|
+
forceUpdate({
|
|
332
|
+
inst
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
};
|
|
336
|
+
return subscribe(handleStoreChange);
|
|
337
|
+
}, [subscribe]);
|
|
338
|
+
useDebugValue(value);
|
|
339
|
+
return value;
|
|
340
|
+
}
|
|
341
|
+
function checkIfSnapshotChanged(inst) {
|
|
342
|
+
var latestGetSnapshot = inst.getSnapshot;
|
|
343
|
+
var prevValue = inst.value;
|
|
344
|
+
try {
|
|
345
|
+
var nextValue = latestGetSnapshot();
|
|
346
|
+
return !objectIs(prevValue, nextValue);
|
|
347
|
+
} catch (error2) {
|
|
348
|
+
return true;
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
function useSyncExternalStore$1(subscribe, getSnapshot, getServerSnapshot) {
|
|
352
|
+
return getSnapshot();
|
|
353
|
+
}
|
|
354
|
+
var canUseDOM = !!(typeof window !== "undefined" && typeof window.document !== "undefined" && typeof window.document.createElement !== "undefined");
|
|
355
|
+
var isServerEnvironment = !canUseDOM;
|
|
356
|
+
var shim2 = isServerEnvironment ? useSyncExternalStore$1 : useSyncExternalStore;
|
|
357
|
+
var useSyncExternalStore$2 = React2.useSyncExternalStore !== void 0 ? React2.useSyncExternalStore : shim2;
|
|
358
|
+
useSyncExternalStoreShim_development.useSyncExternalStore = useSyncExternalStore$2;
|
|
359
|
+
if (typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== "undefined" && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop === "function") {
|
|
360
|
+
__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(new Error());
|
|
361
|
+
}
|
|
362
|
+
})();
|
|
363
|
+
}
|
|
364
|
+
return useSyncExternalStoreShim_development;
|
|
365
|
+
}
|
|
366
|
+
var hasRequiredShim;
|
|
367
|
+
function requireShim() {
|
|
368
|
+
if (hasRequiredShim)
|
|
369
|
+
return shim.exports;
|
|
370
|
+
hasRequiredShim = 1;
|
|
371
|
+
(function(module2) {
|
|
372
|
+
if (process.env.NODE_ENV === "production") {
|
|
373
|
+
module2.exports = requireUseSyncExternalStoreShim_production_min();
|
|
374
|
+
} else {
|
|
375
|
+
module2.exports = requireUseSyncExternalStoreShim_development();
|
|
376
|
+
}
|
|
377
|
+
})(shim);
|
|
378
|
+
return shim.exports;
|
|
379
|
+
}
|
|
380
|
+
/**
|
|
381
|
+
* @license React
|
|
382
|
+
* use-sync-external-store-shim/with-selector.production.min.js
|
|
383
|
+
*
|
|
384
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
385
|
+
*
|
|
386
|
+
* This source code is licensed under the MIT license found in the
|
|
387
|
+
* LICENSE file in the root directory of this source tree.
|
|
388
|
+
*/
|
|
389
|
+
var hasRequiredWithSelector_production_min;
|
|
390
|
+
function requireWithSelector_production_min() {
|
|
391
|
+
if (hasRequiredWithSelector_production_min)
|
|
392
|
+
return withSelector_production_min;
|
|
393
|
+
hasRequiredWithSelector_production_min = 1;
|
|
394
|
+
var h = React__default.default, n2 = requireShim();
|
|
395
|
+
function p(a2, b) {
|
|
396
|
+
return a2 === b && (0 !== a2 || 1 / a2 === 1 / b) || a2 !== a2 && b !== b;
|
|
397
|
+
}
|
|
398
|
+
var q = "function" === typeof Object.is ? Object.is : p, r2 = n2.useSyncExternalStore, t2 = h.useRef, u2 = h.useEffect, v2 = h.useMemo, w = h.useDebugValue;
|
|
399
|
+
withSelector_production_min.useSyncExternalStoreWithSelector = function(a2, b, e2, l2, g2) {
|
|
400
|
+
var c2 = t2(null);
|
|
401
|
+
if (null === c2.current) {
|
|
402
|
+
var f2 = { hasValue: false, value: null };
|
|
403
|
+
c2.current = f2;
|
|
404
|
+
} else
|
|
405
|
+
f2 = c2.current;
|
|
406
|
+
c2 = v2(function() {
|
|
407
|
+
function a3(a4) {
|
|
408
|
+
if (!c3) {
|
|
409
|
+
c3 = true;
|
|
410
|
+
d2 = a4;
|
|
411
|
+
a4 = l2(a4);
|
|
412
|
+
if (void 0 !== g2 && f2.hasValue) {
|
|
413
|
+
var b2 = f2.value;
|
|
414
|
+
if (g2(b2, a4))
|
|
415
|
+
return k = b2;
|
|
416
|
+
}
|
|
417
|
+
return k = a4;
|
|
418
|
+
}
|
|
419
|
+
b2 = k;
|
|
420
|
+
if (q(d2, a4))
|
|
421
|
+
return b2;
|
|
422
|
+
var e3 = l2(a4);
|
|
423
|
+
if (void 0 !== g2 && g2(b2, e3))
|
|
424
|
+
return b2;
|
|
425
|
+
d2 = a4;
|
|
426
|
+
return k = e3;
|
|
427
|
+
}
|
|
428
|
+
var c3 = false, d2, k, m = void 0 === e2 ? null : e2;
|
|
429
|
+
return [function() {
|
|
430
|
+
return a3(b());
|
|
431
|
+
}, null === m ? void 0 : function() {
|
|
432
|
+
return a3(m());
|
|
433
|
+
}];
|
|
434
|
+
}, [b, e2, l2, g2]);
|
|
435
|
+
var d = r2(a2, c2[0], c2[1]);
|
|
436
|
+
u2(function() {
|
|
437
|
+
f2.hasValue = true;
|
|
438
|
+
f2.value = d;
|
|
439
|
+
}, [d]);
|
|
440
|
+
w(d);
|
|
441
|
+
return d;
|
|
442
|
+
};
|
|
443
|
+
return withSelector_production_min;
|
|
444
|
+
}
|
|
445
|
+
var withSelector_development = {};
|
|
446
|
+
/**
|
|
447
|
+
* @license React
|
|
448
|
+
* use-sync-external-store-shim/with-selector.development.js
|
|
449
|
+
*
|
|
450
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
451
|
+
*
|
|
452
|
+
* This source code is licensed under the MIT license found in the
|
|
453
|
+
* LICENSE file in the root directory of this source tree.
|
|
454
|
+
*/
|
|
455
|
+
var hasRequiredWithSelector_development;
|
|
456
|
+
function requireWithSelector_development() {
|
|
457
|
+
if (hasRequiredWithSelector_development)
|
|
458
|
+
return withSelector_development;
|
|
459
|
+
hasRequiredWithSelector_development = 1;
|
|
460
|
+
if (process.env.NODE_ENV !== "production") {
|
|
461
|
+
(function() {
|
|
462
|
+
if (typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== "undefined" && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart === "function") {
|
|
463
|
+
__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error());
|
|
464
|
+
}
|
|
465
|
+
var React2 = React__default.default;
|
|
466
|
+
var shim2 = requireShim();
|
|
467
|
+
function is(x, y) {
|
|
468
|
+
return x === y && (x !== 0 || 1 / x === 1 / y) || x !== x && y !== y;
|
|
469
|
+
}
|
|
470
|
+
var objectIs = typeof Object.is === "function" ? Object.is : is;
|
|
471
|
+
var useSyncExternalStore = shim2.useSyncExternalStore;
|
|
472
|
+
var useRef = React2.useRef, useEffect = React2.useEffect, useMemo = React2.useMemo, useDebugValue = React2.useDebugValue;
|
|
473
|
+
function useSyncExternalStoreWithSelector(subscribe, getSnapshot, getServerSnapshot, selector, isEqual2) {
|
|
474
|
+
var instRef = useRef(null);
|
|
475
|
+
var inst;
|
|
476
|
+
if (instRef.current === null) {
|
|
477
|
+
inst = {
|
|
478
|
+
hasValue: false,
|
|
479
|
+
value: null
|
|
480
|
+
};
|
|
481
|
+
instRef.current = inst;
|
|
482
|
+
} else {
|
|
483
|
+
inst = instRef.current;
|
|
484
|
+
}
|
|
485
|
+
var _useMemo = useMemo(function() {
|
|
486
|
+
var hasMemo = false;
|
|
487
|
+
var memoizedSnapshot;
|
|
488
|
+
var memoizedSelection;
|
|
489
|
+
var memoizedSelector = function(nextSnapshot) {
|
|
490
|
+
if (!hasMemo) {
|
|
491
|
+
hasMemo = true;
|
|
492
|
+
memoizedSnapshot = nextSnapshot;
|
|
493
|
+
var _nextSelection = selector(nextSnapshot);
|
|
494
|
+
if (isEqual2 !== void 0) {
|
|
495
|
+
if (inst.hasValue) {
|
|
496
|
+
var currentSelection = inst.value;
|
|
497
|
+
if (isEqual2(currentSelection, _nextSelection)) {
|
|
498
|
+
memoizedSelection = currentSelection;
|
|
499
|
+
return currentSelection;
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
memoizedSelection = _nextSelection;
|
|
504
|
+
return _nextSelection;
|
|
505
|
+
}
|
|
506
|
+
var prevSnapshot = memoizedSnapshot;
|
|
507
|
+
var prevSelection = memoizedSelection;
|
|
508
|
+
if (objectIs(prevSnapshot, nextSnapshot)) {
|
|
509
|
+
return prevSelection;
|
|
510
|
+
}
|
|
511
|
+
var nextSelection = selector(nextSnapshot);
|
|
512
|
+
if (isEqual2 !== void 0 && isEqual2(prevSelection, nextSelection)) {
|
|
513
|
+
return prevSelection;
|
|
514
|
+
}
|
|
515
|
+
memoizedSnapshot = nextSnapshot;
|
|
516
|
+
memoizedSelection = nextSelection;
|
|
517
|
+
return nextSelection;
|
|
518
|
+
};
|
|
519
|
+
var maybeGetServerSnapshot = getServerSnapshot === void 0 ? null : getServerSnapshot;
|
|
520
|
+
var getSnapshotWithSelector = function() {
|
|
521
|
+
return memoizedSelector(getSnapshot());
|
|
522
|
+
};
|
|
523
|
+
var getServerSnapshotWithSelector = maybeGetServerSnapshot === null ? void 0 : function() {
|
|
524
|
+
return memoizedSelector(maybeGetServerSnapshot());
|
|
525
|
+
};
|
|
526
|
+
return [getSnapshotWithSelector, getServerSnapshotWithSelector];
|
|
527
|
+
}, [getSnapshot, getServerSnapshot, selector, isEqual2]), getSelection = _useMemo[0], getServerSelection = _useMemo[1];
|
|
528
|
+
var value = useSyncExternalStore(subscribe, getSelection, getServerSelection);
|
|
529
|
+
useEffect(function() {
|
|
530
|
+
inst.hasValue = true;
|
|
531
|
+
inst.value = value;
|
|
532
|
+
}, [value]);
|
|
533
|
+
useDebugValue(value);
|
|
534
|
+
return value;
|
|
535
|
+
}
|
|
536
|
+
withSelector_development.useSyncExternalStoreWithSelector = useSyncExternalStoreWithSelector;
|
|
537
|
+
if (typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== "undefined" && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop === "function") {
|
|
538
|
+
__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(new Error());
|
|
539
|
+
}
|
|
540
|
+
})();
|
|
541
|
+
}
|
|
542
|
+
return withSelector_development;
|
|
543
|
+
}
|
|
544
|
+
(function(module2) {
|
|
545
|
+
if (process.env.NODE_ENV === "production") {
|
|
546
|
+
module2.exports = requireWithSelector_production_min();
|
|
547
|
+
} else {
|
|
548
|
+
module2.exports = requireWithSelector_development();
|
|
549
|
+
}
|
|
550
|
+
})(withSelector);
|
|
551
|
+
function useConstant(fn) {
|
|
552
|
+
var ref = React__namespace.useRef();
|
|
553
|
+
if (!ref.current) {
|
|
554
|
+
ref.current = { v: fn() };
|
|
555
|
+
}
|
|
556
|
+
return ref.current.v;
|
|
557
|
+
}
|
|
558
|
+
var __read = globalThis && globalThis.__read || function(o2, n2) {
|
|
559
|
+
var m = typeof Symbol === "function" && o2[Symbol.iterator];
|
|
560
|
+
if (!m)
|
|
561
|
+
return o2;
|
|
562
|
+
var i2 = m.call(o2), r2, ar = [], e2;
|
|
563
|
+
try {
|
|
564
|
+
while ((n2 === void 0 || n2-- > 0) && !(r2 = i2.next()).done)
|
|
565
|
+
ar.push(r2.value);
|
|
566
|
+
} catch (error) {
|
|
567
|
+
e2 = { error };
|
|
568
|
+
} finally {
|
|
569
|
+
try {
|
|
570
|
+
if (r2 && !r2.done && (m = i2["return"]))
|
|
571
|
+
m.call(i2);
|
|
572
|
+
} finally {
|
|
573
|
+
if (e2)
|
|
574
|
+
throw e2.error;
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
return ar;
|
|
578
|
+
};
|
|
579
|
+
function identity(a2) {
|
|
580
|
+
return a2;
|
|
581
|
+
}
|
|
582
|
+
var getServiceState = function(service) {
|
|
583
|
+
var currentValue;
|
|
584
|
+
service.subscribe(function(state) {
|
|
585
|
+
currentValue = state;
|
|
586
|
+
}).unsubscribe();
|
|
587
|
+
return currentValue;
|
|
588
|
+
};
|
|
589
|
+
function useMachine(stateMachine, options) {
|
|
590
|
+
var persistedStateRef = React.useRef();
|
|
591
|
+
if (process.env.NODE_ENV !== "production") {
|
|
592
|
+
var _a = __read(React.useState(stateMachine), 1), initialMachine = _a[0];
|
|
593
|
+
if (stateMachine !== initialMachine) {
|
|
594
|
+
console.warn("Machine given to `useMachine` has changed between renders. This is not supported and might lead to unexpected results.\nPlease make sure that you pass the same Machine as argument each time.");
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
var _b = __read(useConstant(function() {
|
|
598
|
+
var queue2 = [];
|
|
599
|
+
var service2 = v(s(stateMachine.config, options ? options : stateMachine._options));
|
|
600
|
+
var send = service2.send;
|
|
601
|
+
service2.send = function(event) {
|
|
602
|
+
if (service2.status === n.NotStarted) {
|
|
603
|
+
queue2.push(event);
|
|
604
|
+
return;
|
|
605
|
+
}
|
|
606
|
+
send(event);
|
|
607
|
+
persistedStateRef.current = service2.state;
|
|
608
|
+
};
|
|
609
|
+
return [service2, queue2];
|
|
610
|
+
}), 2), service = _b[0], queue = _b[1];
|
|
611
|
+
index(function() {
|
|
612
|
+
if (options) {
|
|
613
|
+
service._machine._options = options;
|
|
614
|
+
}
|
|
615
|
+
});
|
|
616
|
+
var useServiceResult = useService(service);
|
|
617
|
+
React.useEffect(function() {
|
|
618
|
+
service.start(persistedStateRef.current);
|
|
619
|
+
queue.forEach(service.send);
|
|
620
|
+
persistedStateRef.current = service.state;
|
|
621
|
+
return function() {
|
|
622
|
+
service.stop();
|
|
623
|
+
};
|
|
624
|
+
}, []);
|
|
625
|
+
return useServiceResult;
|
|
626
|
+
}
|
|
627
|
+
var isEqual = function(_prevState, nextState) {
|
|
628
|
+
return nextState.changed === false;
|
|
629
|
+
};
|
|
630
|
+
function useService(service) {
|
|
631
|
+
var getSnapshot = React.useCallback(function() {
|
|
632
|
+
return getServiceState(service);
|
|
633
|
+
}, [service]);
|
|
634
|
+
var subscribe = React.useCallback(function(handleStoreChange) {
|
|
635
|
+
var unsubscribe = service.subscribe(handleStoreChange).unsubscribe;
|
|
636
|
+
return unsubscribe;
|
|
637
|
+
}, [service]);
|
|
638
|
+
var storeSnapshot = withSelector.exports.useSyncExternalStoreWithSelector(subscribe, getSnapshot, getSnapshot, identity, isEqual);
|
|
639
|
+
return [storeSnapshot, service.send, service];
|
|
640
|
+
}
|
|
641
|
+
function flattenConnection(connection) {
|
|
642
|
+
if (!connection) {
|
|
643
|
+
const noConnectionErr = `flattenConnection(): needs a 'connection' to flatten, but received '${connection}' instead`;
|
|
644
|
+
{
|
|
645
|
+
throw new Error(noConnectionErr);
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
if (connection.nodes) {
|
|
649
|
+
return connection.nodes;
|
|
650
|
+
}
|
|
651
|
+
if (connection.edges) {
|
|
652
|
+
return connection.edges.map((edge) => {
|
|
653
|
+
if (!(edge == null ? void 0 : edge.node)) {
|
|
654
|
+
throw new Error("Connection edges must contain nodes");
|
|
655
|
+
}
|
|
656
|
+
return edge.node;
|
|
657
|
+
});
|
|
658
|
+
}
|
|
659
|
+
{
|
|
660
|
+
console.warn(
|
|
661
|
+
`The connection did not contain either "nodes" or "edges.node". A empty array will be returned in its place.`
|
|
662
|
+
);
|
|
663
|
+
}
|
|
664
|
+
return [];
|
|
665
|
+
}
|
|
666
|
+
const CartLineAdd = (cartFragment) => `
|
|
667
|
+
mutation CartLineAdd($cartId: ID!, $lines: [CartLineInput!]!, $numCartLines: Int = 250, $country: CountryCode = ZZ) @inContext(country: $country) {
|
|
668
|
+
cartLinesAdd(cartId: $cartId, lines: $lines) {
|
|
669
|
+
cart {
|
|
670
|
+
...CartFragment
|
|
671
|
+
}
|
|
672
|
+
}
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
${cartFragment}
|
|
676
|
+
`;
|
|
677
|
+
const CartCreate = (cartFragment) => `
|
|
678
|
+
mutation CartCreate($input: CartInput!, $numCartLines: Int = 250, $country: CountryCode = ZZ) @inContext(country: $country) {
|
|
679
|
+
cartCreate(input: $input) {
|
|
680
|
+
cart {
|
|
681
|
+
...CartFragment
|
|
682
|
+
}
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
${cartFragment}
|
|
687
|
+
`;
|
|
688
|
+
const CartLineRemove = (cartFragment) => `
|
|
689
|
+
mutation CartLineRemove($cartId: ID!, $lines: [ID!]!, $numCartLines: Int = 250, $country: CountryCode = ZZ) @inContext(country: $country) {
|
|
690
|
+
cartLinesRemove(cartId: $cartId, lineIds: $lines) {
|
|
691
|
+
cart {
|
|
692
|
+
...CartFragment
|
|
693
|
+
}
|
|
694
|
+
}
|
|
695
|
+
}
|
|
696
|
+
|
|
697
|
+
${cartFragment}
|
|
698
|
+
`;
|
|
699
|
+
const CartLineUpdate = (cartFragment) => `
|
|
700
|
+
mutation CartLineUpdate($cartId: ID!, $lines: [CartLineUpdateInput!]!, $numCartLines: Int = 250, $country: CountryCode = ZZ) @inContext(country: $country) {
|
|
701
|
+
cartLinesUpdate(cartId: $cartId, lines: $lines) {
|
|
702
|
+
cart {
|
|
703
|
+
...CartFragment
|
|
704
|
+
}
|
|
705
|
+
}
|
|
706
|
+
}
|
|
707
|
+
|
|
708
|
+
${cartFragment}
|
|
709
|
+
`;
|
|
710
|
+
const CartNoteUpdate = (cartFragment) => `
|
|
711
|
+
mutation CartNoteUpdate($cartId: ID!, $note: String, $numCartLines: Int = 250, $country: CountryCode = ZZ) @inContext(country: $country) {
|
|
712
|
+
cartNoteUpdate(cartId: $cartId, note: $note) {
|
|
713
|
+
cart {
|
|
714
|
+
...CartFragment
|
|
715
|
+
}
|
|
716
|
+
}
|
|
717
|
+
}
|
|
718
|
+
|
|
719
|
+
${cartFragment}
|
|
720
|
+
`;
|
|
721
|
+
const CartBuyerIdentityUpdate = (cartFragment) => `
|
|
722
|
+
mutation CartBuyerIdentityUpdate(
|
|
723
|
+
$cartId: ID!
|
|
724
|
+
$buyerIdentity: CartBuyerIdentityInput!
|
|
725
|
+
$numCartLines: Int = 250
|
|
726
|
+
$country: CountryCode = ZZ
|
|
727
|
+
) @inContext(country: $country) {
|
|
728
|
+
cartBuyerIdentityUpdate(cartId: $cartId, buyerIdentity: $buyerIdentity) {
|
|
729
|
+
cart {
|
|
730
|
+
...CartFragment
|
|
731
|
+
}
|
|
732
|
+
}
|
|
733
|
+
}
|
|
734
|
+
|
|
735
|
+
${cartFragment}
|
|
736
|
+
`;
|
|
737
|
+
const CartAttributesUpdate = (cartFragment) => `
|
|
738
|
+
mutation CartAttributesUpdate($attributes: [AttributeInput!]!, $cartId: ID!, $numCartLines: Int = 250, $country: CountryCode = ZZ) @inContext(country: $country) {
|
|
739
|
+
cartAttributesUpdate(attributes: $attributes, cartId: $cartId) {
|
|
740
|
+
cart {
|
|
741
|
+
...CartFragment
|
|
742
|
+
}
|
|
743
|
+
}
|
|
744
|
+
}
|
|
745
|
+
|
|
746
|
+
${cartFragment}
|
|
747
|
+
`;
|
|
748
|
+
const CartDiscountCodesUpdate = (cartFragment) => `
|
|
749
|
+
mutation CartDiscountCodesUpdate($cartId: ID!, $discountCodes: [String!], $numCartLines: Int = 250, $country: CountryCode = ZZ) @inContext(country: $country) {
|
|
750
|
+
cartDiscountCodesUpdate(cartId: $cartId, discountCodes: $discountCodes) {
|
|
751
|
+
cart {
|
|
752
|
+
...CartFragment
|
|
753
|
+
}
|
|
754
|
+
}
|
|
755
|
+
}
|
|
756
|
+
|
|
757
|
+
${cartFragment}
|
|
758
|
+
`;
|
|
759
|
+
const CartQuery = (cartFragment) => `
|
|
760
|
+
query CartQuery($id: ID!, $numCartLines: Int = 250, $country: CountryCode = ZZ) @inContext(country: $country) {
|
|
761
|
+
cart(id: $id) {
|
|
762
|
+
...CartFragment
|
|
763
|
+
}
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
${cartFragment}
|
|
767
|
+
`;
|
|
768
|
+
const SFAPI_VERSION = "2022-10";
|
|
769
|
+
var _jsxFileName$b = "/home/runner/work/hydrogen-ui/hydrogen-ui/packages/react/src/ShopifyProvider.tsx";
|
|
770
|
+
const ShopifyContext = React.createContext({
|
|
771
|
+
storeDomain: "test.myshopify.com",
|
|
772
|
+
storefrontToken: "abc123",
|
|
773
|
+
storefrontApiVersion: SFAPI_VERSION,
|
|
774
|
+
country: {
|
|
775
|
+
isoCode: "US"
|
|
776
|
+
},
|
|
777
|
+
language: {
|
|
778
|
+
isoCode: "EN"
|
|
779
|
+
},
|
|
780
|
+
locale: "EN-US"
|
|
781
|
+
});
|
|
782
|
+
function ShopifyProvider({
|
|
783
|
+
children,
|
|
784
|
+
shopifyConfig
|
|
785
|
+
}) {
|
|
786
|
+
if (!shopifyConfig) {
|
|
787
|
+
throw new Error(`The 'shopifyConfig' prop must be passed to '<ShopifyProvider/>'`);
|
|
788
|
+
}
|
|
789
|
+
if (shopifyConfig.storefrontApiVersion !== SFAPI_VERSION) {
|
|
790
|
+
console.warn(`This version of Hydrogen-UI is built for Shopify's Storefront API version ${SFAPI_VERSION}, but it looks like you're using version ${shopifyConfig.storefrontApiVersion}. There may be issues or bugs if you use a mismatched version of Hydrogen-UI and the Storefront API.`);
|
|
791
|
+
}
|
|
792
|
+
const finalConfig = React.useMemo(() => ({
|
|
793
|
+
...shopifyConfig,
|
|
794
|
+
storeDomain: shopifyConfig.storeDomain.replace(/^https?:\/\//, "")
|
|
795
|
+
}), [shopifyConfig]);
|
|
796
|
+
return /* @__PURE__ */ React__default.default.createElement(ShopifyContext.Provider, {
|
|
797
|
+
value: finalConfig,
|
|
798
|
+
__self: this,
|
|
799
|
+
__source: {
|
|
800
|
+
fileName: _jsxFileName$b,
|
|
801
|
+
lineNumber: 49,
|
|
802
|
+
columnNumber: 5
|
|
803
|
+
}
|
|
804
|
+
}, children);
|
|
805
|
+
}
|
|
806
|
+
function useShop() {
|
|
807
|
+
const shopContext = React.useContext(ShopifyContext);
|
|
808
|
+
if (!shopContext) {
|
|
809
|
+
throw new Error(`'useShop()' must be a descendent of <ShopifyProvider/>`);
|
|
810
|
+
}
|
|
811
|
+
return shopContext;
|
|
812
|
+
}
|
|
813
|
+
const CART_ID_STORAGE_KEY = "shopifyCartId";
|
|
814
|
+
const STOREFRONT_API_PUBLIC_TOKEN_HEADER = "X-Shopify-Storefront-Access-Token";
|
|
815
|
+
const SHOPIFY_STOREFRONT_ID_HEADER = "Shopify-Storefront-Id";
|
|
816
|
+
const SHOPIFY_STOREFRONT_Y_HEADER = "Shopify-Storefront-Y";
|
|
817
|
+
const SHOPIFY_STOREFRONT_S_HEADER = "Shopify-Storefront-S";
|
|
818
|
+
const SHOPIFY_Y = "_shopify_y";
|
|
819
|
+
const SHOPIFY_S = "_shopify_s";
|
|
820
|
+
var g = /* @__PURE__ */ new Set([
|
|
821
|
+
"domain",
|
|
822
|
+
"path",
|
|
823
|
+
"max-age",
|
|
824
|
+
"expires",
|
|
825
|
+
"samesite",
|
|
826
|
+
"secure",
|
|
827
|
+
"httponly"
|
|
828
|
+
]);
|
|
829
|
+
function u(a2) {
|
|
830
|
+
let r2 = {}, e2, t2, n2 = 0, m = a2.split(/;\s*/g), s2, i2;
|
|
831
|
+
for (; n2 < m.length; n2++)
|
|
832
|
+
if (t2 = m[n2], e2 = t2.indexOf("="), ~e2) {
|
|
833
|
+
if (s2 = t2.substring(0, e2++).trim(), i2 = t2.substring(e2).trim(), i2[0] === '"' && (i2 = i2.substring(1, i2.length - 1)), ~i2.indexOf("%"))
|
|
834
|
+
try {
|
|
835
|
+
i2 = decodeURIComponent(i2);
|
|
836
|
+
} catch (f2) {
|
|
837
|
+
}
|
|
838
|
+
g.has(t2 = s2.toLowerCase()) ? t2 === "expires" ? r2.expires = new Date(i2) : t2 === "max-age" ? r2.maxage = +i2 : r2[t2] = i2 : r2[s2] = i2;
|
|
839
|
+
} else
|
|
840
|
+
(s2 = t2.trim().toLowerCase()) && (s2 === "httponly" || s2 === "secure") && (r2[s2] = true);
|
|
841
|
+
return r2;
|
|
842
|
+
}
|
|
843
|
+
function useCartFetch() {
|
|
844
|
+
const {
|
|
845
|
+
storeDomain,
|
|
846
|
+
storefrontApiVersion,
|
|
847
|
+
storefrontToken,
|
|
848
|
+
storefrontId
|
|
849
|
+
} = useShop();
|
|
850
|
+
return React.useCallback(({
|
|
851
|
+
query,
|
|
852
|
+
variables
|
|
853
|
+
}) => {
|
|
854
|
+
const headers = {
|
|
855
|
+
"Content-Type": "application/json",
|
|
856
|
+
"X-SDK-Variant": "hydrogen",
|
|
857
|
+
"X-SDK-Version": storefrontApiVersion,
|
|
858
|
+
[STOREFRONT_API_PUBLIC_TOKEN_HEADER]: storefrontToken
|
|
859
|
+
};
|
|
860
|
+
if (storefrontId) {
|
|
861
|
+
headers[SHOPIFY_STOREFRONT_ID_HEADER] = storefrontId;
|
|
862
|
+
}
|
|
863
|
+
const cookieData = u(document.cookie);
|
|
864
|
+
if (cookieData[SHOPIFY_Y] && cookieData[SHOPIFY_S]) {
|
|
865
|
+
headers[SHOPIFY_STOREFRONT_Y_HEADER] = cookieData[SHOPIFY_Y];
|
|
866
|
+
headers[SHOPIFY_STOREFRONT_S_HEADER] = cookieData[SHOPIFY_S];
|
|
867
|
+
}
|
|
868
|
+
return fetch(`https://${storeDomain}/api/${storefrontApiVersion}/graphql.json`, {
|
|
869
|
+
method: "POST",
|
|
870
|
+
headers,
|
|
871
|
+
body: JSON.stringify({
|
|
872
|
+
query: query.toString(),
|
|
873
|
+
variables
|
|
874
|
+
})
|
|
875
|
+
}).then((res) => res.json()).catch((error) => {
|
|
876
|
+
return {
|
|
877
|
+
data: void 0,
|
|
878
|
+
errors: error.toString()
|
|
879
|
+
};
|
|
880
|
+
});
|
|
881
|
+
}, [storeDomain, storefrontApiVersion, storefrontToken, storefrontId]);
|
|
882
|
+
}
|
|
883
|
+
function useCartActions({
|
|
884
|
+
numCartLines,
|
|
885
|
+
cartFragment,
|
|
886
|
+
countryCode = "US"
|
|
887
|
+
}) {
|
|
888
|
+
const fetchCart = useCartFetch();
|
|
889
|
+
const cartFetch = React.useCallback((cartId) => {
|
|
890
|
+
return fetchCart({
|
|
891
|
+
query: CartQuery(cartFragment),
|
|
892
|
+
variables: {
|
|
893
|
+
id: cartId,
|
|
894
|
+
numCartLines,
|
|
895
|
+
country: countryCode
|
|
896
|
+
}
|
|
897
|
+
});
|
|
898
|
+
}, [fetchCart, cartFragment, numCartLines, countryCode]);
|
|
899
|
+
const cartCreate = React.useCallback((cart) => {
|
|
900
|
+
return fetchCart({
|
|
901
|
+
query: CartCreate(cartFragment),
|
|
902
|
+
variables: {
|
|
903
|
+
input: cart,
|
|
904
|
+
numCartLines,
|
|
905
|
+
country: countryCode
|
|
906
|
+
}
|
|
907
|
+
});
|
|
908
|
+
}, [cartFragment, countryCode, fetchCart, numCartLines]);
|
|
909
|
+
const cartLineAdd = React.useCallback((cartId, lines) => {
|
|
910
|
+
return fetchCart({
|
|
911
|
+
query: CartLineAdd(cartFragment),
|
|
912
|
+
variables: {
|
|
913
|
+
cartId,
|
|
914
|
+
lines,
|
|
915
|
+
numCartLines,
|
|
916
|
+
country: countryCode
|
|
917
|
+
}
|
|
918
|
+
});
|
|
919
|
+
}, [cartFragment, countryCode, fetchCart, numCartLines]);
|
|
920
|
+
const cartLineUpdate = React.useCallback((cartId, lines) => {
|
|
921
|
+
return fetchCart({
|
|
922
|
+
query: CartLineUpdate(cartFragment),
|
|
923
|
+
variables: {
|
|
924
|
+
cartId,
|
|
925
|
+
lines,
|
|
926
|
+
numCartLines,
|
|
927
|
+
country: countryCode
|
|
928
|
+
}
|
|
929
|
+
});
|
|
930
|
+
}, [cartFragment, countryCode, fetchCart, numCartLines]);
|
|
931
|
+
const cartLineRemove = React.useCallback((cartId, lines) => {
|
|
932
|
+
return fetchCart({
|
|
933
|
+
query: CartLineRemove(cartFragment),
|
|
934
|
+
variables: {
|
|
935
|
+
cartId,
|
|
936
|
+
lines,
|
|
937
|
+
numCartLines,
|
|
938
|
+
country: countryCode
|
|
939
|
+
}
|
|
940
|
+
});
|
|
941
|
+
}, [cartFragment, countryCode, fetchCart, numCartLines]);
|
|
942
|
+
const noteUpdate = React.useCallback((cartId, note) => {
|
|
943
|
+
return fetchCart({
|
|
944
|
+
query: CartNoteUpdate(cartFragment),
|
|
945
|
+
variables: {
|
|
946
|
+
cartId,
|
|
947
|
+
note,
|
|
948
|
+
numCartLines,
|
|
949
|
+
country: countryCode
|
|
950
|
+
}
|
|
951
|
+
});
|
|
952
|
+
}, [fetchCart, cartFragment, numCartLines, countryCode]);
|
|
953
|
+
const buyerIdentityUpdate = React.useCallback((cartId, buyerIdentity) => {
|
|
954
|
+
return fetchCart({
|
|
955
|
+
query: CartBuyerIdentityUpdate(cartFragment),
|
|
956
|
+
variables: {
|
|
957
|
+
cartId,
|
|
958
|
+
buyerIdentity,
|
|
959
|
+
numCartLines,
|
|
960
|
+
country: countryCode
|
|
961
|
+
}
|
|
962
|
+
});
|
|
963
|
+
}, [cartFragment, countryCode, fetchCart, numCartLines]);
|
|
964
|
+
const cartAttributesUpdate = React.useCallback((cartId, attributes) => {
|
|
965
|
+
return fetchCart({
|
|
966
|
+
query: CartAttributesUpdate(cartFragment),
|
|
967
|
+
variables: {
|
|
968
|
+
cartId,
|
|
969
|
+
attributes,
|
|
970
|
+
numCartLines,
|
|
971
|
+
country: countryCode
|
|
972
|
+
}
|
|
973
|
+
});
|
|
974
|
+
}, [cartFragment, countryCode, fetchCart, numCartLines]);
|
|
975
|
+
const discountCodesUpdate = React.useCallback((cartId, discountCodes) => {
|
|
976
|
+
return fetchCart({
|
|
977
|
+
query: CartDiscountCodesUpdate(cartFragment),
|
|
978
|
+
variables: {
|
|
979
|
+
cartId,
|
|
980
|
+
discountCodes,
|
|
981
|
+
numCartLines,
|
|
982
|
+
country: countryCode
|
|
983
|
+
}
|
|
984
|
+
});
|
|
985
|
+
}, [cartFragment, countryCode, fetchCart, numCartLines]);
|
|
986
|
+
return React.useMemo(() => ({
|
|
987
|
+
cartFetch,
|
|
988
|
+
cartCreate,
|
|
989
|
+
cartLineAdd,
|
|
990
|
+
cartLineUpdate,
|
|
991
|
+
cartLineRemove,
|
|
992
|
+
noteUpdate,
|
|
993
|
+
buyerIdentityUpdate,
|
|
994
|
+
cartAttributesUpdate,
|
|
995
|
+
discountCodesUpdate,
|
|
996
|
+
cartFragment
|
|
997
|
+
}), [cartFetch, cartCreate, cartLineAdd, cartLineUpdate, cartLineRemove, noteUpdate, buyerIdentityUpdate, cartAttributesUpdate, discountCodesUpdate, cartFragment]);
|
|
998
|
+
}
|
|
999
|
+
function invokeCart(action, options) {
|
|
1000
|
+
return {
|
|
1001
|
+
entry: [...(options == null ? void 0 : options.entryActions) || [], "onCartActionEntry", "onCartActionOptimisticUI", action],
|
|
1002
|
+
on: {
|
|
1003
|
+
RESOLVE: {
|
|
1004
|
+
target: (options == null ? void 0 : options.resolveTarget) || "idle",
|
|
1005
|
+
actions: [i({
|
|
1006
|
+
prevCart: (context) => context == null ? void 0 : context.cart,
|
|
1007
|
+
cart: (_, event) => {
|
|
1008
|
+
var _a;
|
|
1009
|
+
return (_a = event == null ? void 0 : event.payload) == null ? void 0 : _a.cart;
|
|
1010
|
+
},
|
|
1011
|
+
rawCartResult: (_, event) => {
|
|
1012
|
+
var _a;
|
|
1013
|
+
return (_a = event == null ? void 0 : event.payload) == null ? void 0 : _a.rawCartResult;
|
|
1014
|
+
},
|
|
1015
|
+
errors: (_) => void 0
|
|
1016
|
+
})]
|
|
1017
|
+
},
|
|
1018
|
+
ERROR: {
|
|
1019
|
+
target: (options == null ? void 0 : options.errorTarget) || "error",
|
|
1020
|
+
actions: [i({
|
|
1021
|
+
prevCart: (context) => context == null ? void 0 : context.cart,
|
|
1022
|
+
cart: (context) => context == null ? void 0 : context.lastValidCart,
|
|
1023
|
+
errors: (_, event) => {
|
|
1024
|
+
var _a;
|
|
1025
|
+
return (_a = event == null ? void 0 : event.payload) == null ? void 0 : _a.errors;
|
|
1026
|
+
}
|
|
1027
|
+
})]
|
|
1028
|
+
},
|
|
1029
|
+
CART_COMPLETED: {
|
|
1030
|
+
target: "cartCompleted",
|
|
1031
|
+
actions: i({
|
|
1032
|
+
prevCart: (_) => void 0,
|
|
1033
|
+
cart: (_) => void 0,
|
|
1034
|
+
lastValidCart: (_) => void 0,
|
|
1035
|
+
errors: (_) => void 0
|
|
1036
|
+
})
|
|
1037
|
+
}
|
|
1038
|
+
},
|
|
1039
|
+
exit: ["onCartActionComplete", ...(options == null ? void 0 : options.exitActions) || []]
|
|
1040
|
+
};
|
|
1041
|
+
}
|
|
1042
|
+
const INITIALIZING_CART_EVENTS = {
|
|
1043
|
+
CART_FETCH: {
|
|
1044
|
+
target: "cartFetching"
|
|
1045
|
+
},
|
|
1046
|
+
CART_CREATE: {
|
|
1047
|
+
target: "cartCreating"
|
|
1048
|
+
},
|
|
1049
|
+
CART_SET: {
|
|
1050
|
+
target: "idle",
|
|
1051
|
+
actions: [i({
|
|
1052
|
+
rawCartResult: (_, event) => event.payload.cart,
|
|
1053
|
+
cart: (_, event) => cartFromGraphQL(event.payload.cart)
|
|
1054
|
+
})]
|
|
1055
|
+
}
|
|
1056
|
+
};
|
|
1057
|
+
const UPDATING_CART_EVENTS = {
|
|
1058
|
+
CARTLINE_ADD: {
|
|
1059
|
+
target: "cartLineAdding"
|
|
1060
|
+
},
|
|
1061
|
+
CARTLINE_UPDATE: {
|
|
1062
|
+
target: "cartLineUpdating"
|
|
1063
|
+
},
|
|
1064
|
+
CARTLINE_REMOVE: {
|
|
1065
|
+
target: "cartLineRemoving"
|
|
1066
|
+
},
|
|
1067
|
+
NOTE_UPDATE: {
|
|
1068
|
+
target: "noteUpdating"
|
|
1069
|
+
},
|
|
1070
|
+
BUYER_IDENTITY_UPDATE: {
|
|
1071
|
+
target: "buyerIdentityUpdating"
|
|
1072
|
+
},
|
|
1073
|
+
CART_ATTRIBUTES_UPDATE: {
|
|
1074
|
+
target: "cartAttributesUpdating"
|
|
1075
|
+
},
|
|
1076
|
+
DISCOUNT_CODES_UPDATE: {
|
|
1077
|
+
target: "discountCodesUpdating"
|
|
1078
|
+
}
|
|
1079
|
+
};
|
|
1080
|
+
function createCartMachine(initialCart) {
|
|
1081
|
+
return s({
|
|
1082
|
+
id: "Cart",
|
|
1083
|
+
initial: initialCart ? "idle" : "uninitialized",
|
|
1084
|
+
context: {
|
|
1085
|
+
cart: initialCart && cartFromGraphQL(initialCart)
|
|
1086
|
+
},
|
|
1087
|
+
states: {
|
|
1088
|
+
uninitialized: {
|
|
1089
|
+
on: INITIALIZING_CART_EVENTS
|
|
1090
|
+
},
|
|
1091
|
+
cartCompleted: {
|
|
1092
|
+
on: INITIALIZING_CART_EVENTS
|
|
1093
|
+
},
|
|
1094
|
+
initializationError: {
|
|
1095
|
+
on: INITIALIZING_CART_EVENTS
|
|
1096
|
+
},
|
|
1097
|
+
idle: {
|
|
1098
|
+
on: {
|
|
1099
|
+
...INITIALIZING_CART_EVENTS,
|
|
1100
|
+
...UPDATING_CART_EVENTS
|
|
1101
|
+
}
|
|
1102
|
+
},
|
|
1103
|
+
error: {
|
|
1104
|
+
on: {
|
|
1105
|
+
...INITIALIZING_CART_EVENTS,
|
|
1106
|
+
...UPDATING_CART_EVENTS
|
|
1107
|
+
}
|
|
1108
|
+
},
|
|
1109
|
+
cartFetching: invokeCart("cartFetchAction", {
|
|
1110
|
+
errorTarget: "initializationError"
|
|
1111
|
+
}),
|
|
1112
|
+
cartCreating: invokeCart("cartCreateAction", {
|
|
1113
|
+
errorTarget: "initializationError"
|
|
1114
|
+
}),
|
|
1115
|
+
cartLineRemoving: invokeCart("cartLineRemoveAction"),
|
|
1116
|
+
cartLineUpdating: invokeCart("cartLineUpdateAction"),
|
|
1117
|
+
cartLineAdding: invokeCart("cartLineAddAction"),
|
|
1118
|
+
noteUpdating: invokeCart("noteUpdateAction"),
|
|
1119
|
+
buyerIdentityUpdating: invokeCart("buyerIdentityUpdateAction"),
|
|
1120
|
+
cartAttributesUpdating: invokeCart("cartAttributesUpdateAction"),
|
|
1121
|
+
discountCodesUpdating: invokeCart("discountCodesUpdateAction")
|
|
1122
|
+
}
|
|
1123
|
+
});
|
|
1124
|
+
}
|
|
1125
|
+
function useCartAPIStateMachine({
|
|
1126
|
+
numCartLines,
|
|
1127
|
+
onCartActionEntry,
|
|
1128
|
+
onCartActionOptimisticUI,
|
|
1129
|
+
onCartActionComplete,
|
|
1130
|
+
data: cart,
|
|
1131
|
+
cartFragment,
|
|
1132
|
+
countryCode
|
|
1133
|
+
}) {
|
|
1134
|
+
const {
|
|
1135
|
+
cartFetch,
|
|
1136
|
+
cartCreate,
|
|
1137
|
+
cartLineAdd,
|
|
1138
|
+
cartLineUpdate,
|
|
1139
|
+
cartLineRemove,
|
|
1140
|
+
noteUpdate,
|
|
1141
|
+
buyerIdentityUpdate,
|
|
1142
|
+
cartAttributesUpdate,
|
|
1143
|
+
discountCodesUpdate
|
|
1144
|
+
} = useCartActions({
|
|
1145
|
+
numCartLines,
|
|
1146
|
+
cartFragment,
|
|
1147
|
+
countryCode
|
|
1148
|
+
});
|
|
1149
|
+
const cartMachine = React.useMemo(() => createCartMachine(cart), [cart]);
|
|
1150
|
+
const [state, send, service] = useMachine(cartMachine, {
|
|
1151
|
+
actions: {
|
|
1152
|
+
cartFetchAction: async (_, event) => {
|
|
1153
|
+
var _a;
|
|
1154
|
+
if (event.type !== "CART_FETCH")
|
|
1155
|
+
return;
|
|
1156
|
+
const {
|
|
1157
|
+
data,
|
|
1158
|
+
errors
|
|
1159
|
+
} = await cartFetch((_a = event == null ? void 0 : event.payload) == null ? void 0 : _a.cartId);
|
|
1160
|
+
const resultEvent = eventFromFetchResult(event, data == null ? void 0 : data.cart, errors);
|
|
1161
|
+
send(resultEvent);
|
|
1162
|
+
},
|
|
1163
|
+
cartCreateAction: async (_, event) => {
|
|
1164
|
+
var _a;
|
|
1165
|
+
if (event.type !== "CART_CREATE")
|
|
1166
|
+
return;
|
|
1167
|
+
const {
|
|
1168
|
+
data,
|
|
1169
|
+
errors
|
|
1170
|
+
} = await cartCreate(event == null ? void 0 : event.payload);
|
|
1171
|
+
const resultEvent = eventFromFetchResult(event, (_a = data == null ? void 0 : data.cartCreate) == null ? void 0 : _a.cart, errors);
|
|
1172
|
+
send(resultEvent);
|
|
1173
|
+
},
|
|
1174
|
+
cartLineAddAction: async (context, event) => {
|
|
1175
|
+
var _a, _b;
|
|
1176
|
+
if (event.type !== "CARTLINE_ADD" || !((_a = context == null ? void 0 : context.cart) == null ? void 0 : _a.id))
|
|
1177
|
+
return;
|
|
1178
|
+
const {
|
|
1179
|
+
data,
|
|
1180
|
+
errors
|
|
1181
|
+
} = await cartLineAdd(context.cart.id, event.payload.lines);
|
|
1182
|
+
const resultEvent = eventFromFetchResult(event, (_b = data == null ? void 0 : data.cartLinesAdd) == null ? void 0 : _b.cart, errors);
|
|
1183
|
+
send(resultEvent);
|
|
1184
|
+
},
|
|
1185
|
+
cartLineUpdateAction: async (context, event) => {
|
|
1186
|
+
var _a, _b;
|
|
1187
|
+
if (event.type !== "CARTLINE_UPDATE" || !((_a = context == null ? void 0 : context.cart) == null ? void 0 : _a.id))
|
|
1188
|
+
return;
|
|
1189
|
+
const {
|
|
1190
|
+
data,
|
|
1191
|
+
errors
|
|
1192
|
+
} = await cartLineUpdate(context.cart.id, event.payload.lines);
|
|
1193
|
+
const resultEvent = eventFromFetchResult(event, (_b = data == null ? void 0 : data.cartLinesUpdate) == null ? void 0 : _b.cart, errors);
|
|
1194
|
+
send(resultEvent);
|
|
1195
|
+
},
|
|
1196
|
+
cartLineRemoveAction: async (context, event) => {
|
|
1197
|
+
var _a, _b;
|
|
1198
|
+
if (event.type !== "CARTLINE_REMOVE" || !((_a = context == null ? void 0 : context.cart) == null ? void 0 : _a.id))
|
|
1199
|
+
return;
|
|
1200
|
+
const {
|
|
1201
|
+
data,
|
|
1202
|
+
errors
|
|
1203
|
+
} = await cartLineRemove(context.cart.id, event.payload.lines);
|
|
1204
|
+
const resultEvent = eventFromFetchResult(event, (_b = data == null ? void 0 : data.cartLinesRemove) == null ? void 0 : _b.cart, errors);
|
|
1205
|
+
send(resultEvent);
|
|
1206
|
+
},
|
|
1207
|
+
noteUpdateAction: async (context, event) => {
|
|
1208
|
+
var _a, _b;
|
|
1209
|
+
if (event.type !== "NOTE_UPDATE" || !((_a = context == null ? void 0 : context.cart) == null ? void 0 : _a.id))
|
|
1210
|
+
return;
|
|
1211
|
+
const {
|
|
1212
|
+
data,
|
|
1213
|
+
errors
|
|
1214
|
+
} = await noteUpdate(context.cart.id, event.payload.note);
|
|
1215
|
+
const resultEvent = eventFromFetchResult(event, (_b = data == null ? void 0 : data.cartNoteUpdate) == null ? void 0 : _b.cart, errors);
|
|
1216
|
+
send(resultEvent);
|
|
1217
|
+
},
|
|
1218
|
+
buyerIdentityUpdateAction: async (context, event) => {
|
|
1219
|
+
var _a, _b;
|
|
1220
|
+
if (event.type !== "BUYER_IDENTITY_UPDATE" || !((_a = context == null ? void 0 : context.cart) == null ? void 0 : _a.id))
|
|
1221
|
+
return;
|
|
1222
|
+
const {
|
|
1223
|
+
data,
|
|
1224
|
+
errors
|
|
1225
|
+
} = await buyerIdentityUpdate(context.cart.id, event.payload.buyerIdentity);
|
|
1226
|
+
const resultEvent = eventFromFetchResult(event, (_b = data == null ? void 0 : data.cartBuyerIdentityUpdate) == null ? void 0 : _b.cart, errors);
|
|
1227
|
+
send(resultEvent);
|
|
1228
|
+
},
|
|
1229
|
+
cartAttributesUpdateAction: async (context, event) => {
|
|
1230
|
+
var _a, _b;
|
|
1231
|
+
if (event.type !== "CART_ATTRIBUTES_UPDATE" || !((_a = context == null ? void 0 : context.cart) == null ? void 0 : _a.id))
|
|
1232
|
+
return;
|
|
1233
|
+
const {
|
|
1234
|
+
data,
|
|
1235
|
+
errors
|
|
1236
|
+
} = await cartAttributesUpdate(context.cart.id, event.payload.attributes);
|
|
1237
|
+
const resultEvent = eventFromFetchResult(event, (_b = data == null ? void 0 : data.cartAttributesUpdate) == null ? void 0 : _b.cart, errors);
|
|
1238
|
+
send(resultEvent);
|
|
1239
|
+
},
|
|
1240
|
+
discountCodesUpdateAction: async (context, event) => {
|
|
1241
|
+
var _a, _b;
|
|
1242
|
+
if (event.type !== "DISCOUNT_CODES_UPDATE" || !((_a = context == null ? void 0 : context.cart) == null ? void 0 : _a.id))
|
|
1243
|
+
return;
|
|
1244
|
+
const {
|
|
1245
|
+
data,
|
|
1246
|
+
errors
|
|
1247
|
+
} = await discountCodesUpdate(context.cart.id, event.payload.discountCodes);
|
|
1248
|
+
const resultEvent = eventFromFetchResult(event, (_b = data == null ? void 0 : data.cartDiscountCodesUpdate) == null ? void 0 : _b.cart, errors);
|
|
1249
|
+
send(resultEvent);
|
|
1250
|
+
},
|
|
1251
|
+
...onCartActionEntry && {
|
|
1252
|
+
onCartActionEntry: (context, event) => {
|
|
1253
|
+
if (isCartActionEvent(event)) {
|
|
1254
|
+
onCartActionEntry(context, event);
|
|
1255
|
+
}
|
|
1256
|
+
}
|
|
1257
|
+
},
|
|
1258
|
+
...onCartActionOptimisticUI && {
|
|
1259
|
+
onCartActionOptimisticUI: i((context, event) => {
|
|
1260
|
+
return onCartActionOptimisticUI(context, event);
|
|
1261
|
+
})
|
|
1262
|
+
},
|
|
1263
|
+
...onCartActionComplete && {
|
|
1264
|
+
onCartActionComplete: (context, event) => {
|
|
1265
|
+
if (isCartFetchResultEvent(event)) {
|
|
1266
|
+
onCartActionComplete(context, event);
|
|
1267
|
+
}
|
|
1268
|
+
}
|
|
1269
|
+
}
|
|
1270
|
+
}
|
|
1271
|
+
});
|
|
1272
|
+
return React.useMemo(() => [state, send, service], [state, send, service]);
|
|
1273
|
+
}
|
|
1274
|
+
function cartFromGraphQL(cart) {
|
|
1275
|
+
var _a;
|
|
1276
|
+
return {
|
|
1277
|
+
...cart,
|
|
1278
|
+
lines: flattenConnection(cart == null ? void 0 : cart.lines),
|
|
1279
|
+
note: (_a = cart.note) != null ? _a : void 0
|
|
1280
|
+
};
|
|
1281
|
+
}
|
|
1282
|
+
function eventFromFetchResult(cartActionEvent, cart, errors) {
|
|
1283
|
+
if (errors) {
|
|
1284
|
+
return {
|
|
1285
|
+
type: "ERROR",
|
|
1286
|
+
payload: {
|
|
1287
|
+
errors,
|
|
1288
|
+
cartActionEvent
|
|
1289
|
+
}
|
|
1290
|
+
};
|
|
1291
|
+
}
|
|
1292
|
+
if (!cart) {
|
|
1293
|
+
return {
|
|
1294
|
+
type: "CART_COMPLETED",
|
|
1295
|
+
payload: {
|
|
1296
|
+
cartActionEvent
|
|
1297
|
+
}
|
|
1298
|
+
};
|
|
1299
|
+
}
|
|
1300
|
+
return {
|
|
1301
|
+
type: "RESOLVE",
|
|
1302
|
+
payload: {
|
|
1303
|
+
cart: cartFromGraphQL(cart),
|
|
1304
|
+
rawCartResult: cart,
|
|
1305
|
+
cartActionEvent
|
|
1306
|
+
}
|
|
1307
|
+
};
|
|
1308
|
+
}
|
|
1309
|
+
function isCartActionEvent(event) {
|
|
1310
|
+
return event.type === "CART_CREATE" || event.type === "CARTLINE_ADD" || event.type === "CARTLINE_UPDATE" || event.type === "CARTLINE_REMOVE" || event.type === "NOTE_UPDATE" || event.type === "BUYER_IDENTITY_UPDATE" || event.type === "CART_ATTRIBUTES_UPDATE" || event.type === "DISCOUNT_CODES_UPDATE";
|
|
1311
|
+
}
|
|
1312
|
+
function isCartFetchResultEvent(event) {
|
|
1313
|
+
return event.type === "RESOLVE" || event.type === "ERROR" || event.type === "CART_COMPLETED";
|
|
1314
|
+
}
|
|
1315
|
+
var _jsxFileName$a = "/home/runner/work/hydrogen-ui/hydrogen-ui/packages/react/src/CartProvider.tsx";
|
|
1316
|
+
const CartContext = React.createContext(null);
|
|
1317
|
+
function useCart() {
|
|
1318
|
+
const context = React.useContext(CartContext);
|
|
1319
|
+
if (!context) {
|
|
1320
|
+
throw new Error("Expected a Cart Context, but no Cart Context was found");
|
|
1321
|
+
}
|
|
1322
|
+
return context;
|
|
1323
|
+
}
|
|
1324
|
+
function CartProvider({
|
|
1325
|
+
children,
|
|
1326
|
+
numCartLines,
|
|
1327
|
+
onCreate,
|
|
1328
|
+
onLineAdd,
|
|
1329
|
+
onLineRemove,
|
|
1330
|
+
onLineUpdate,
|
|
1331
|
+
onNoteUpdate,
|
|
1332
|
+
onBuyerIdentityUpdate,
|
|
1333
|
+
onAttributesUpdate,
|
|
1334
|
+
onDiscountCodesUpdate,
|
|
1335
|
+
onCreateComplete,
|
|
1336
|
+
onLineAddComplete,
|
|
1337
|
+
onLineRemoveComplete,
|
|
1338
|
+
onLineUpdateComplete,
|
|
1339
|
+
onNoteUpdateComplete,
|
|
1340
|
+
onBuyerIdentityUpdateComplete,
|
|
1341
|
+
onAttributesUpdateComplete,
|
|
1342
|
+
onDiscountCodesUpdateComplete,
|
|
1343
|
+
data: cart,
|
|
1344
|
+
cartFragment = defaultCartFragment,
|
|
1345
|
+
customerAccessToken,
|
|
1346
|
+
countryCode = "US"
|
|
1347
|
+
}) {
|
|
1348
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
1349
|
+
if (countryCode)
|
|
1350
|
+
countryCode = countryCode.toUpperCase();
|
|
1351
|
+
const [prevCountryCode, setPrevCountryCode] = React.useState(countryCode);
|
|
1352
|
+
const [prevCustomerAccessToken, setPrevCustomerAccessToken] = React.useState(customerAccessToken);
|
|
1353
|
+
const customerOverridesCountryCode = React.useRef(false);
|
|
1354
|
+
if (prevCountryCode !== countryCode || prevCustomerAccessToken !== customerAccessToken) {
|
|
1355
|
+
setPrevCountryCode(countryCode);
|
|
1356
|
+
setPrevCustomerAccessToken(customerAccessToken);
|
|
1357
|
+
customerOverridesCountryCode.current = false;
|
|
1358
|
+
}
|
|
1359
|
+
const [cartState, cartSend] = useCartAPIStateMachine({
|
|
1360
|
+
numCartLines,
|
|
1361
|
+
data: cart,
|
|
1362
|
+
cartFragment,
|
|
1363
|
+
countryCode,
|
|
1364
|
+
onCartActionEntry(context, event) {
|
|
1365
|
+
try {
|
|
1366
|
+
switch (event.type) {
|
|
1367
|
+
case "CART_CREATE":
|
|
1368
|
+
return onCreate == null ? void 0 : onCreate();
|
|
1369
|
+
case "CARTLINE_ADD":
|
|
1370
|
+
return onLineAdd == null ? void 0 : onLineAdd();
|
|
1371
|
+
case "CARTLINE_REMOVE":
|
|
1372
|
+
return onLineRemove == null ? void 0 : onLineRemove();
|
|
1373
|
+
case "CARTLINE_UPDATE":
|
|
1374
|
+
return onLineUpdate == null ? void 0 : onLineUpdate();
|
|
1375
|
+
case "NOTE_UPDATE":
|
|
1376
|
+
return onNoteUpdate == null ? void 0 : onNoteUpdate();
|
|
1377
|
+
case "BUYER_IDENTITY_UPDATE":
|
|
1378
|
+
return onBuyerIdentityUpdate == null ? void 0 : onBuyerIdentityUpdate();
|
|
1379
|
+
case "CART_ATTRIBUTES_UPDATE":
|
|
1380
|
+
return onAttributesUpdate == null ? void 0 : onAttributesUpdate();
|
|
1381
|
+
case "DISCOUNT_CODES_UPDATE":
|
|
1382
|
+
return onDiscountCodesUpdate == null ? void 0 : onDiscountCodesUpdate();
|
|
1383
|
+
}
|
|
1384
|
+
} catch (error) {
|
|
1385
|
+
console.error("Cart entry action failed", error);
|
|
1386
|
+
}
|
|
1387
|
+
},
|
|
1388
|
+
onCartActionOptimisticUI(context, event) {
|
|
1389
|
+
var _a2, _b2, _c2, _d2;
|
|
1390
|
+
if (!(context == null ? void 0 : context.cart))
|
|
1391
|
+
return {
|
|
1392
|
+
cart: void 0
|
|
1393
|
+
};
|
|
1394
|
+
switch (event.type) {
|
|
1395
|
+
case "CARTLINE_REMOVE":
|
|
1396
|
+
return {
|
|
1397
|
+
...context,
|
|
1398
|
+
lastValidCart: context.cart,
|
|
1399
|
+
cart: {
|
|
1400
|
+
...context.cart,
|
|
1401
|
+
lines: (_b2 = (_a2 = context == null ? void 0 : context.cart) == null ? void 0 : _a2.lines) == null ? void 0 : _b2.filter((line) => (line == null ? void 0 : line.id) && !event.payload.lines.includes(line == null ? void 0 : line.id))
|
|
1402
|
+
}
|
|
1403
|
+
};
|
|
1404
|
+
case "CARTLINE_UPDATE":
|
|
1405
|
+
return {
|
|
1406
|
+
...context,
|
|
1407
|
+
lastValidCart: context.cart,
|
|
1408
|
+
cart: {
|
|
1409
|
+
...context.cart,
|
|
1410
|
+
lines: (_d2 = (_c2 = context == null ? void 0 : context.cart) == null ? void 0 : _c2.lines) == null ? void 0 : _d2.map((line) => {
|
|
1411
|
+
const updatedLine = event.payload.lines.find(({
|
|
1412
|
+
id
|
|
1413
|
+
}) => id === (line == null ? void 0 : line.id));
|
|
1414
|
+
if (updatedLine && updatedLine.quantity) {
|
|
1415
|
+
return {
|
|
1416
|
+
...line,
|
|
1417
|
+
quantity: updatedLine.quantity
|
|
1418
|
+
};
|
|
1419
|
+
}
|
|
1420
|
+
return line;
|
|
1421
|
+
})
|
|
1422
|
+
}
|
|
1423
|
+
};
|
|
1424
|
+
}
|
|
1425
|
+
return {
|
|
1426
|
+
cart: context.cart ? {
|
|
1427
|
+
...context.cart
|
|
1428
|
+
} : void 0
|
|
1429
|
+
};
|
|
1430
|
+
},
|
|
1431
|
+
onCartActionComplete(context, event) {
|
|
1432
|
+
const cartActionEvent = event.payload.cartActionEvent;
|
|
1433
|
+
try {
|
|
1434
|
+
switch (event.type) {
|
|
1435
|
+
case "RESOLVE":
|
|
1436
|
+
switch (cartActionEvent.type) {
|
|
1437
|
+
case "CART_CREATE":
|
|
1438
|
+
return onCreateComplete == null ? void 0 : onCreateComplete();
|
|
1439
|
+
case "CARTLINE_ADD":
|
|
1440
|
+
return onLineAddComplete == null ? void 0 : onLineAddComplete();
|
|
1441
|
+
case "CARTLINE_REMOVE":
|
|
1442
|
+
return onLineRemoveComplete == null ? void 0 : onLineRemoveComplete();
|
|
1443
|
+
case "CARTLINE_UPDATE":
|
|
1444
|
+
return onLineUpdateComplete == null ? void 0 : onLineUpdateComplete();
|
|
1445
|
+
case "NOTE_UPDATE":
|
|
1446
|
+
return onNoteUpdateComplete == null ? void 0 : onNoteUpdateComplete();
|
|
1447
|
+
case "BUYER_IDENTITY_UPDATE":
|
|
1448
|
+
if (countryCodeNotUpdated(context, cartActionEvent)) {
|
|
1449
|
+
customerOverridesCountryCode.current = true;
|
|
1450
|
+
}
|
|
1451
|
+
return onBuyerIdentityUpdateComplete == null ? void 0 : onBuyerIdentityUpdateComplete();
|
|
1452
|
+
case "CART_ATTRIBUTES_UPDATE":
|
|
1453
|
+
return onAttributesUpdateComplete == null ? void 0 : onAttributesUpdateComplete();
|
|
1454
|
+
case "DISCOUNT_CODES_UPDATE":
|
|
1455
|
+
return onDiscountCodesUpdateComplete == null ? void 0 : onDiscountCodesUpdateComplete();
|
|
1456
|
+
}
|
|
1457
|
+
}
|
|
1458
|
+
} catch (error) {
|
|
1459
|
+
console.error("onCartActionComplete failed", error);
|
|
1460
|
+
}
|
|
1461
|
+
}
|
|
1462
|
+
});
|
|
1463
|
+
const cartReady = React.useRef(false);
|
|
1464
|
+
const cartCompleted = cartState.matches("cartCompleted");
|
|
1465
|
+
const countryChanged = (cartState.value === "idle" || cartState.value === "error" || cartState.value === "cartCompleted") && countryCode !== ((_c = (_b = (_a = cartState == null ? void 0 : cartState.context) == null ? void 0 : _a.cart) == null ? void 0 : _b.buyerIdentity) == null ? void 0 : _c.countryCode) && !cartState.context.errors;
|
|
1466
|
+
const fetchingFromStorage = React.useRef(false);
|
|
1467
|
+
React.useEffect(() => {
|
|
1468
|
+
if (!cartReady.current && !fetchingFromStorage.current) {
|
|
1469
|
+
if (!cart && storageAvailable("localStorage")) {
|
|
1470
|
+
fetchingFromStorage.current = true;
|
|
1471
|
+
try {
|
|
1472
|
+
const cartId = window.localStorage.getItem(CART_ID_STORAGE_KEY);
|
|
1473
|
+
if (cartId) {
|
|
1474
|
+
cartSend({
|
|
1475
|
+
type: "CART_FETCH",
|
|
1476
|
+
payload: {
|
|
1477
|
+
cartId
|
|
1478
|
+
}
|
|
1479
|
+
});
|
|
1480
|
+
}
|
|
1481
|
+
} catch (error) {
|
|
1482
|
+
console.warn("error fetching cartId");
|
|
1483
|
+
console.warn(error);
|
|
1484
|
+
}
|
|
1485
|
+
}
|
|
1486
|
+
cartReady.current = true;
|
|
1487
|
+
}
|
|
1488
|
+
}, [cart, cartReady, cartSend]);
|
|
1489
|
+
React.useEffect(() => {
|
|
1490
|
+
if (!countryChanged || customerOverridesCountryCode.current)
|
|
1491
|
+
return;
|
|
1492
|
+
cartSend({
|
|
1493
|
+
type: "BUYER_IDENTITY_UPDATE",
|
|
1494
|
+
payload: {
|
|
1495
|
+
buyerIdentity: {
|
|
1496
|
+
countryCode,
|
|
1497
|
+
customerAccessToken
|
|
1498
|
+
}
|
|
1499
|
+
}
|
|
1500
|
+
});
|
|
1501
|
+
}, [countryCode, customerAccessToken, countryChanged, customerOverridesCountryCode, cartSend]);
|
|
1502
|
+
const onCartReadySend = React.useCallback((cartEvent) => {
|
|
1503
|
+
if (!cartReady.current) {
|
|
1504
|
+
return console.warn("Cart isn't ready yet");
|
|
1505
|
+
}
|
|
1506
|
+
cartSend(cartEvent);
|
|
1507
|
+
}, [cartSend]);
|
|
1508
|
+
React.useEffect(() => {
|
|
1509
|
+
var _a2, _b2, _c2;
|
|
1510
|
+
if (((_b2 = (_a2 = cartState == null ? void 0 : cartState.context) == null ? void 0 : _a2.cart) == null ? void 0 : _b2.id) && storageAvailable("localStorage")) {
|
|
1511
|
+
try {
|
|
1512
|
+
window.localStorage.setItem(CART_ID_STORAGE_KEY, (_c2 = cartState.context.cart) == null ? void 0 : _c2.id);
|
|
1513
|
+
} catch (error) {
|
|
1514
|
+
console.warn("Failed to save cartId to localStorage", error);
|
|
1515
|
+
}
|
|
1516
|
+
}
|
|
1517
|
+
}, [(_e = (_d = cartState == null ? void 0 : cartState.context) == null ? void 0 : _d.cart) == null ? void 0 : _e.id]);
|
|
1518
|
+
React.useEffect(() => {
|
|
1519
|
+
if (cartCompleted && storageAvailable("localStorage")) {
|
|
1520
|
+
try {
|
|
1521
|
+
window.localStorage.removeItem(CART_ID_STORAGE_KEY);
|
|
1522
|
+
} catch (error) {
|
|
1523
|
+
console.warn("Failed to delete cartId from localStorage", error);
|
|
1524
|
+
}
|
|
1525
|
+
}
|
|
1526
|
+
}, [cartCompleted]);
|
|
1527
|
+
const cartCreate = React.useCallback((cartInput) => {
|
|
1528
|
+
var _a2, _b2;
|
|
1529
|
+
if (countryCode && !((_a2 = cartInput.buyerIdentity) == null ? void 0 : _a2.countryCode)) {
|
|
1530
|
+
if (cartInput.buyerIdentity == null) {
|
|
1531
|
+
cartInput.buyerIdentity = {};
|
|
1532
|
+
}
|
|
1533
|
+
cartInput.buyerIdentity.countryCode = countryCode;
|
|
1534
|
+
}
|
|
1535
|
+
if (customerAccessToken && !((_b2 = cartInput.buyerIdentity) == null ? void 0 : _b2.customerAccessToken)) {
|
|
1536
|
+
if (cartInput.buyerIdentity == null) {
|
|
1537
|
+
cartInput.buyerIdentity = {};
|
|
1538
|
+
}
|
|
1539
|
+
cartInput.buyerIdentity.customerAccessToken = customerAccessToken;
|
|
1540
|
+
}
|
|
1541
|
+
onCartReadySend({
|
|
1542
|
+
type: "CART_CREATE",
|
|
1543
|
+
payload: cartInput
|
|
1544
|
+
});
|
|
1545
|
+
}, [countryCode, customerAccessToken, onCartReadySend]);
|
|
1546
|
+
const cartDisplayState = useDelayedStateUntilHydration(cartState);
|
|
1547
|
+
const cartContextValue = React.useMemo(() => {
|
|
1548
|
+
var _a2, _b2, _c2, _d2, _e2, _f2;
|
|
1549
|
+
return {
|
|
1550
|
+
...(_b2 = (_a2 = cartDisplayState == null ? void 0 : cartDisplayState.context) == null ? void 0 : _a2.cart) != null ? _b2 : {
|
|
1551
|
+
lines: [],
|
|
1552
|
+
attributes: []
|
|
1553
|
+
},
|
|
1554
|
+
status: transposeStatus(cartDisplayState.value),
|
|
1555
|
+
error: (_c2 = cartDisplayState == null ? void 0 : cartDisplayState.context) == null ? void 0 : _c2.errors,
|
|
1556
|
+
totalQuantity: (_f2 = (_e2 = (_d2 = cartDisplayState == null ? void 0 : cartDisplayState.context) == null ? void 0 : _d2.cart) == null ? void 0 : _e2.totalQuantity) != null ? _f2 : 0,
|
|
1557
|
+
cartCreate,
|
|
1558
|
+
linesAdd(lines) {
|
|
1559
|
+
var _a3, _b3;
|
|
1560
|
+
if ((_b3 = (_a3 = cartDisplayState == null ? void 0 : cartDisplayState.context) == null ? void 0 : _a3.cart) == null ? void 0 : _b3.id) {
|
|
1561
|
+
onCartReadySend({
|
|
1562
|
+
type: "CARTLINE_ADD",
|
|
1563
|
+
payload: {
|
|
1564
|
+
lines
|
|
1565
|
+
}
|
|
1566
|
+
});
|
|
1567
|
+
} else {
|
|
1568
|
+
cartCreate({
|
|
1569
|
+
lines
|
|
1570
|
+
});
|
|
1571
|
+
}
|
|
1572
|
+
},
|
|
1573
|
+
linesRemove(lines) {
|
|
1574
|
+
onCartReadySend({
|
|
1575
|
+
type: "CARTLINE_REMOVE",
|
|
1576
|
+
payload: {
|
|
1577
|
+
lines
|
|
1578
|
+
}
|
|
1579
|
+
});
|
|
1580
|
+
},
|
|
1581
|
+
linesUpdate(lines) {
|
|
1582
|
+
onCartReadySend({
|
|
1583
|
+
type: "CARTLINE_UPDATE",
|
|
1584
|
+
payload: {
|
|
1585
|
+
lines
|
|
1586
|
+
}
|
|
1587
|
+
});
|
|
1588
|
+
},
|
|
1589
|
+
noteUpdate(note) {
|
|
1590
|
+
onCartReadySend({
|
|
1591
|
+
type: "NOTE_UPDATE",
|
|
1592
|
+
payload: {
|
|
1593
|
+
note
|
|
1594
|
+
}
|
|
1595
|
+
});
|
|
1596
|
+
},
|
|
1597
|
+
buyerIdentityUpdate(buyerIdentity) {
|
|
1598
|
+
onCartReadySend({
|
|
1599
|
+
type: "BUYER_IDENTITY_UPDATE",
|
|
1600
|
+
payload: {
|
|
1601
|
+
buyerIdentity
|
|
1602
|
+
}
|
|
1603
|
+
});
|
|
1604
|
+
},
|
|
1605
|
+
cartAttributesUpdate(attributes) {
|
|
1606
|
+
onCartReadySend({
|
|
1607
|
+
type: "CART_ATTRIBUTES_UPDATE",
|
|
1608
|
+
payload: {
|
|
1609
|
+
attributes
|
|
1610
|
+
}
|
|
1611
|
+
});
|
|
1612
|
+
},
|
|
1613
|
+
discountCodesUpdate(discountCodes) {
|
|
1614
|
+
onCartReadySend({
|
|
1615
|
+
type: "DISCOUNT_CODES_UPDATE",
|
|
1616
|
+
payload: {
|
|
1617
|
+
discountCodes
|
|
1618
|
+
}
|
|
1619
|
+
});
|
|
1620
|
+
},
|
|
1621
|
+
cartFragment
|
|
1622
|
+
};
|
|
1623
|
+
}, [cartCreate, (_f = cartDisplayState == null ? void 0 : cartDisplayState.context) == null ? void 0 : _f.cart, (_g = cartDisplayState == null ? void 0 : cartDisplayState.context) == null ? void 0 : _g.errors, cartDisplayState.value, cartFragment, onCartReadySend]);
|
|
1624
|
+
return /* @__PURE__ */ React__default.default.createElement(CartContext.Provider, {
|
|
1625
|
+
value: cartContextValue,
|
|
1626
|
+
__self: this,
|
|
1627
|
+
__source: {
|
|
1628
|
+
fileName: _jsxFileName$a,
|
|
1629
|
+
lineNumber: 425,
|
|
1630
|
+
columnNumber: 5
|
|
1631
|
+
}
|
|
1632
|
+
}, children);
|
|
1633
|
+
}
|
|
1634
|
+
function transposeStatus(status) {
|
|
1635
|
+
switch (status) {
|
|
1636
|
+
case "uninitialized":
|
|
1637
|
+
case "initializationError":
|
|
1638
|
+
return "uninitialized";
|
|
1639
|
+
case "idle":
|
|
1640
|
+
case "cartCompleted":
|
|
1641
|
+
case "error":
|
|
1642
|
+
return "idle";
|
|
1643
|
+
case "cartFetching":
|
|
1644
|
+
return "fetching";
|
|
1645
|
+
case "cartCreating":
|
|
1646
|
+
return "creating";
|
|
1647
|
+
case "cartLineAdding":
|
|
1648
|
+
case "cartLineRemoving":
|
|
1649
|
+
case "cartLineUpdating":
|
|
1650
|
+
case "noteUpdating":
|
|
1651
|
+
case "buyerIdentityUpdating":
|
|
1652
|
+
case "cartAttributesUpdating":
|
|
1653
|
+
case "discountCodesUpdating":
|
|
1654
|
+
return "updating";
|
|
1655
|
+
}
|
|
1656
|
+
}
|
|
1657
|
+
function useDelayedStateUntilHydration(state) {
|
|
1658
|
+
const [isPending, startTransition] = React.useTransition();
|
|
1659
|
+
const [delayedState, setDelayedState] = React.useState(state);
|
|
1660
|
+
const firstTimePending = React.useRef(false);
|
|
1661
|
+
if (isPending) {
|
|
1662
|
+
firstTimePending.current = true;
|
|
1663
|
+
}
|
|
1664
|
+
const firstTimePendingFinished = React.useRef(false);
|
|
1665
|
+
if (!isPending && firstTimePending.current) {
|
|
1666
|
+
firstTimePendingFinished.current = true;
|
|
1667
|
+
}
|
|
1668
|
+
React.useEffect(() => {
|
|
1669
|
+
startTransition(() => {
|
|
1670
|
+
if (!firstTimePendingFinished.current) {
|
|
1671
|
+
setDelayedState(state);
|
|
1672
|
+
}
|
|
1673
|
+
});
|
|
1674
|
+
}, [state]);
|
|
1675
|
+
const displayState = firstTimePendingFinished.current ? state : delayedState;
|
|
1676
|
+
return displayState;
|
|
1677
|
+
}
|
|
1678
|
+
function storageAvailable(type) {
|
|
1679
|
+
let storage;
|
|
1680
|
+
try {
|
|
1681
|
+
storage = window[type];
|
|
1682
|
+
const x = "__storage_test__";
|
|
1683
|
+
storage.setItem(x, x);
|
|
1684
|
+
storage.removeItem(x);
|
|
1685
|
+
return true;
|
|
1686
|
+
} catch (e2) {
|
|
1687
|
+
return e2 instanceof DOMException && (e2.code === 22 || e2.code === 1014 || e2.name === "QuotaExceededError" || e2.name === "NS_ERROR_DOM_QUOTA_REACHED") && storage && storage.length !== 0;
|
|
1688
|
+
}
|
|
1689
|
+
}
|
|
1690
|
+
function countryCodeNotUpdated(context, event) {
|
|
1691
|
+
var _a, _b;
|
|
1692
|
+
return event.payload.buyerIdentity.countryCode && ((_b = (_a = context.cart) == null ? void 0 : _a.buyerIdentity) == null ? void 0 : _b.countryCode) !== event.payload.buyerIdentity.countryCode;
|
|
1693
|
+
}
|
|
1694
|
+
const defaultCartFragment = `
|
|
1695
|
+
fragment CartFragment on Cart {
|
|
1696
|
+
id
|
|
1697
|
+
checkoutUrl
|
|
1698
|
+
totalQuantity
|
|
1699
|
+
buyerIdentity {
|
|
1700
|
+
countryCode
|
|
1701
|
+
customer {
|
|
1702
|
+
id
|
|
1703
|
+
email
|
|
1704
|
+
firstName
|
|
1705
|
+
lastName
|
|
1706
|
+
displayName
|
|
1707
|
+
}
|
|
1708
|
+
email
|
|
1709
|
+
phone
|
|
1710
|
+
}
|
|
1711
|
+
lines(first: $numCartLines) {
|
|
1712
|
+
edges {
|
|
1713
|
+
node {
|
|
1714
|
+
id
|
|
1715
|
+
quantity
|
|
1716
|
+
attributes {
|
|
1717
|
+
key
|
|
1718
|
+
value
|
|
1719
|
+
}
|
|
1720
|
+
cost {
|
|
1721
|
+
totalAmount {
|
|
1722
|
+
amount
|
|
1723
|
+
currencyCode
|
|
1724
|
+
}
|
|
1725
|
+
compareAtAmountPerQuantity {
|
|
1726
|
+
amount
|
|
1727
|
+
currencyCode
|
|
1728
|
+
}
|
|
1729
|
+
}
|
|
1730
|
+
merchandise {
|
|
1731
|
+
... on ProductVariant {
|
|
1732
|
+
id
|
|
1733
|
+
availableForSale
|
|
1734
|
+
compareAtPriceV2 {
|
|
1735
|
+
...MoneyFragment
|
|
1736
|
+
}
|
|
1737
|
+
priceV2 {
|
|
1738
|
+
...MoneyFragment
|
|
1739
|
+
}
|
|
1740
|
+
requiresShipping
|
|
1741
|
+
title
|
|
1742
|
+
image {
|
|
1743
|
+
...ImageFragment
|
|
1744
|
+
}
|
|
1745
|
+
product {
|
|
1746
|
+
handle
|
|
1747
|
+
title
|
|
1748
|
+
}
|
|
1749
|
+
selectedOptions {
|
|
1750
|
+
name
|
|
1751
|
+
value
|
|
1752
|
+
}
|
|
1753
|
+
}
|
|
1754
|
+
}
|
|
1755
|
+
}
|
|
1756
|
+
}
|
|
1757
|
+
}
|
|
1758
|
+
cost {
|
|
1759
|
+
subtotalAmount {
|
|
1760
|
+
...MoneyFragment
|
|
1761
|
+
}
|
|
1762
|
+
totalAmount {
|
|
1763
|
+
...MoneyFragment
|
|
1764
|
+
}
|
|
1765
|
+
totalDutyAmount {
|
|
1766
|
+
...MoneyFragment
|
|
1767
|
+
}
|
|
1768
|
+
totalTaxAmount {
|
|
1769
|
+
...MoneyFragment
|
|
1770
|
+
}
|
|
1771
|
+
}
|
|
1772
|
+
note
|
|
1773
|
+
attributes {
|
|
1774
|
+
key
|
|
1775
|
+
value
|
|
1776
|
+
}
|
|
1777
|
+
discountCodes {
|
|
1778
|
+
code
|
|
1779
|
+
}
|
|
1780
|
+
}
|
|
1781
|
+
|
|
1782
|
+
fragment MoneyFragment on MoneyV2 {
|
|
1783
|
+
currencyCode
|
|
1784
|
+
amount
|
|
1785
|
+
}
|
|
1786
|
+
fragment ImageFragment on Image {
|
|
1787
|
+
id
|
|
1788
|
+
url
|
|
1789
|
+
altText
|
|
1790
|
+
width
|
|
1791
|
+
height
|
|
1792
|
+
}
|
|
1793
|
+
`;
|
|
1794
|
+
var _jsxFileName$9 = "/home/runner/work/hydrogen-ui/hydrogen-ui/packages/react/src/ExternalVideo.tsx";
|
|
27
1795
|
function ExternalVideo(props) {
|
|
28
1796
|
var _a, _b;
|
|
29
1797
|
const {
|
|
@@ -58,31 +1826,12 @@
|
|
|
58
1826
|
loading,
|
|
59
1827
|
__self: this,
|
|
60
1828
|
__source: {
|
|
61
|
-
fileName: _jsxFileName$
|
|
1829
|
+
fileName: _jsxFileName$9,
|
|
62
1830
|
lineNumber: 56,
|
|
63
1831
|
columnNumber: 5
|
|
64
1832
|
}
|
|
65
1833
|
});
|
|
66
1834
|
}
|
|
67
|
-
function flattenConnection(connection) {
|
|
68
|
-
if (connection.nodes) {
|
|
69
|
-
return connection.nodes;
|
|
70
|
-
}
|
|
71
|
-
if (connection.edges) {
|
|
72
|
-
return connection.edges.map((edge) => {
|
|
73
|
-
if (!(edge == null ? void 0 : edge.node)) {
|
|
74
|
-
throw new Error("Connection edges must contain nodes");
|
|
75
|
-
}
|
|
76
|
-
return edge.node;
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
{
|
|
80
|
-
console.warn(
|
|
81
|
-
`The connection did not contain either "nodes" or "edges.node". A empty array will be returned in its place.`
|
|
82
|
-
);
|
|
83
|
-
}
|
|
84
|
-
return [];
|
|
85
|
-
}
|
|
86
1835
|
const PRODUCTION_CDN_HOSTNAMES = [
|
|
87
1836
|
"cdn.shopify.com",
|
|
88
1837
|
"cdn.shopifycdn.net",
|
|
@@ -156,7 +1905,7 @@
|
|
|
156
1905
|
}
|
|
157
1906
|
return { width: null, height: null };
|
|
158
1907
|
}
|
|
159
|
-
var _jsxFileName$
|
|
1908
|
+
var _jsxFileName$8 = "/home/runner/work/hydrogen-ui/hydrogen-ui/packages/react/src/Image.tsx";
|
|
160
1909
|
function Image({
|
|
161
1910
|
data,
|
|
162
1911
|
width,
|
|
@@ -225,7 +1974,7 @@
|
|
|
225
1974
|
decoding,
|
|
226
1975
|
__self: this,
|
|
227
1976
|
__source: {
|
|
228
|
-
fileName: _jsxFileName$
|
|
1977
|
+
fileName: _jsxFileName$8,
|
|
229
1978
|
lineNumber: 150,
|
|
230
1979
|
columnNumber: 5
|
|
231
1980
|
}
|
|
@@ -261,7 +2010,7 @@
|
|
|
261
2010
|
scale
|
|
262
2011
|
})} ${size}w`).join(", ");
|
|
263
2012
|
}
|
|
264
|
-
var _jsxFileName$
|
|
2013
|
+
var _jsxFileName$7 = "/home/runner/work/hydrogen-ui/hydrogen-ui/packages/react/src/Video.tsx";
|
|
265
2014
|
function Video(props) {
|
|
266
2015
|
var _a, _b;
|
|
267
2016
|
const {
|
|
@@ -288,7 +2037,7 @@
|
|
|
288
2037
|
poster: posterUrl,
|
|
289
2038
|
__self: this,
|
|
290
2039
|
__source: {
|
|
291
|
-
fileName: _jsxFileName$
|
|
2040
|
+
fileName: _jsxFileName$7,
|
|
292
2041
|
lineNumber: 42,
|
|
293
2042
|
columnNumber: 5
|
|
294
2043
|
}
|
|
@@ -303,7 +2052,7 @@
|
|
|
303
2052
|
type: source.mimeType,
|
|
304
2053
|
__self: this,
|
|
305
2054
|
__source: {
|
|
306
|
-
fileName: _jsxFileName$
|
|
2055
|
+
fileName: _jsxFileName$7,
|
|
307
2056
|
lineNumber: 54,
|
|
308
2057
|
columnNumber: 11
|
|
309
2058
|
}
|
|
@@ -356,7 +2105,7 @@
|
|
|
356
2105
|
}, [url, stringifiedOptions, options]);
|
|
357
2106
|
return status;
|
|
358
2107
|
}
|
|
359
|
-
var _jsxFileName$
|
|
2108
|
+
var _jsxFileName$6 = "/home/runner/work/hydrogen-ui/hydrogen-ui/packages/react/src/ModelViewer.tsx";
|
|
360
2109
|
function ModelViewer(props) {
|
|
361
2110
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
362
2111
|
const [modelViewer, setModelViewer] = React.useState(void 0);
|
|
@@ -494,13 +2243,13 @@
|
|
|
494
2243
|
scale: passthroughProps.scale,
|
|
495
2244
|
__self: this,
|
|
496
2245
|
__source: {
|
|
497
|
-
fileName: _jsxFileName$
|
|
2246
|
+
fileName: _jsxFileName$6,
|
|
498
2247
|
lineNumber: 222,
|
|
499
2248
|
columnNumber: 5
|
|
500
2249
|
}
|
|
501
2250
|
}, children);
|
|
502
2251
|
}
|
|
503
|
-
var _jsxFileName$
|
|
2252
|
+
var _jsxFileName$5 = "/home/runner/work/hydrogen-ui/hydrogen-ui/packages/react/src/MediaFile.tsx";
|
|
504
2253
|
function MediaFile({
|
|
505
2254
|
data,
|
|
506
2255
|
mediaOptions,
|
|
@@ -520,8 +2269,8 @@
|
|
|
520
2269
|
data: data.image,
|
|
521
2270
|
__self: this,
|
|
522
2271
|
__source: {
|
|
523
|
-
fileName: _jsxFileName$
|
|
524
|
-
lineNumber:
|
|
2272
|
+
fileName: _jsxFileName$5,
|
|
2273
|
+
lineNumber: 50,
|
|
525
2274
|
columnNumber: 9
|
|
526
2275
|
}
|
|
527
2276
|
});
|
|
@@ -533,8 +2282,8 @@
|
|
|
533
2282
|
data,
|
|
534
2283
|
__self: this,
|
|
535
2284
|
__source: {
|
|
536
|
-
fileName: _jsxFileName$
|
|
537
|
-
lineNumber:
|
|
2285
|
+
fileName: _jsxFileName$5,
|
|
2286
|
+
lineNumber: 59,
|
|
538
2287
|
columnNumber: 9
|
|
539
2288
|
}
|
|
540
2289
|
});
|
|
@@ -546,8 +2295,8 @@
|
|
|
546
2295
|
data,
|
|
547
2296
|
__self: this,
|
|
548
2297
|
__source: {
|
|
549
|
-
fileName: _jsxFileName$
|
|
550
|
-
lineNumber:
|
|
2298
|
+
fileName: _jsxFileName$5,
|
|
2299
|
+
lineNumber: 64,
|
|
551
2300
|
columnNumber: 9
|
|
552
2301
|
}
|
|
553
2302
|
});
|
|
@@ -559,8 +2308,8 @@
|
|
|
559
2308
|
data,
|
|
560
2309
|
__self: this,
|
|
561
2310
|
__source: {
|
|
562
|
-
fileName: _jsxFileName$
|
|
563
|
-
lineNumber:
|
|
2311
|
+
fileName: _jsxFileName$5,
|
|
2312
|
+
lineNumber: 73,
|
|
564
2313
|
columnNumber: 9
|
|
565
2314
|
}
|
|
566
2315
|
});
|
|
@@ -573,51 +2322,6 @@
|
|
|
573
2322
|
}
|
|
574
2323
|
}
|
|
575
2324
|
}
|
|
576
|
-
const SFAPI_VERSION = "2022-07";
|
|
577
|
-
var _jsxFileName$5 = "/home/runner/work/hydrogen-ui/hydrogen-ui/packages/react/src/ShopifyProvider.tsx";
|
|
578
|
-
const ShopifyContext = React.createContext({
|
|
579
|
-
storeDomain: "test.myshopify.com",
|
|
580
|
-
storefrontToken: "abc123",
|
|
581
|
-
storefrontApiVersion: SFAPI_VERSION,
|
|
582
|
-
country: {
|
|
583
|
-
isoCode: "US"
|
|
584
|
-
},
|
|
585
|
-
language: {
|
|
586
|
-
isoCode: "EN"
|
|
587
|
-
},
|
|
588
|
-
locale: "EN-US"
|
|
589
|
-
});
|
|
590
|
-
function ShopifyProvider({
|
|
591
|
-
children,
|
|
592
|
-
shopifyConfig
|
|
593
|
-
}) {
|
|
594
|
-
if (!shopifyConfig) {
|
|
595
|
-
throw new Error(`The 'shopifyConfig' prop must be passed to '<ShopifyProvider/>'`);
|
|
596
|
-
}
|
|
597
|
-
if (shopifyConfig.storefrontApiVersion !== SFAPI_VERSION) {
|
|
598
|
-
console.warn(`This version of Hydrogen-UI is built for Shopify's Storefront API version ${SFAPI_VERSION}, but it looks like you're using version ${shopifyConfig.storefrontApiVersion}. There may be issues or bugs if you use a mismatched version of Hydrogen-UI and the Storefront API.`);
|
|
599
|
-
}
|
|
600
|
-
const finalConfig = React.useMemo(() => ({
|
|
601
|
-
...shopifyConfig,
|
|
602
|
-
storeDomain: shopifyConfig.storeDomain.replace(/^https?:\/\//, "")
|
|
603
|
-
}), [shopifyConfig]);
|
|
604
|
-
return /* @__PURE__ */ React__default.default.createElement(ShopifyContext.Provider, {
|
|
605
|
-
value: finalConfig,
|
|
606
|
-
__self: this,
|
|
607
|
-
__source: {
|
|
608
|
-
fileName: _jsxFileName$5,
|
|
609
|
-
lineNumber: 49,
|
|
610
|
-
columnNumber: 5
|
|
611
|
-
}
|
|
612
|
-
}, children);
|
|
613
|
-
}
|
|
614
|
-
function useShop() {
|
|
615
|
-
const shopContext = React.useContext(ShopifyContext);
|
|
616
|
-
if (!shopContext) {
|
|
617
|
-
throw new Error(`'useShop()' must be a descendent of <ShopifyProvider/>`);
|
|
618
|
-
}
|
|
619
|
-
return shopContext;
|
|
620
|
-
}
|
|
621
2325
|
var _jsxFileName$4 = "/home/runner/work/hydrogen-ui/hydrogen-ui/packages/react/src/Metafield.tsx";
|
|
622
2326
|
function Metafield(props) {
|
|
623
2327
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
@@ -771,15 +2475,15 @@
|
|
|
771
2475
|
__self: this,
|
|
772
2476
|
__source: {
|
|
773
2477
|
fileName: _jsxFileName$4,
|
|
774
|
-
lineNumber:
|
|
2478
|
+
lineNumber: 154,
|
|
775
2479
|
columnNumber: 9
|
|
776
2480
|
}
|
|
777
|
-
}, refArray.map((ref,
|
|
778
|
-
key: `${ref != null ? ref : ""}-${
|
|
2481
|
+
}, refArray.map((ref, index2) => /* @__PURE__ */ React__default.default.createElement("li", {
|
|
2482
|
+
key: `${ref != null ? ref : ""}-${index2}`,
|
|
779
2483
|
__self: this,
|
|
780
2484
|
__source: {
|
|
781
2485
|
fileName: _jsxFileName$4,
|
|
782
|
-
lineNumber:
|
|
2486
|
+
lineNumber: 158,
|
|
783
2487
|
columnNumber: 13
|
|
784
2488
|
}
|
|
785
2489
|
}, ref)));
|
|
@@ -793,7 +2497,7 @@
|
|
|
793
2497
|
__self: this,
|
|
794
2498
|
__source: {
|
|
795
2499
|
fileName: _jsxFileName$4,
|
|
796
|
-
lineNumber:
|
|
2500
|
+
lineNumber: 167,
|
|
797
2501
|
columnNumber: 11
|
|
798
2502
|
}
|
|
799
2503
|
}) : null;
|
|
@@ -805,7 +2509,7 @@
|
|
|
805
2509
|
__self: this,
|
|
806
2510
|
__source: {
|
|
807
2511
|
fileName: _jsxFileName$4,
|
|
808
|
-
lineNumber:
|
|
2512
|
+
lineNumber: 172,
|
|
809
2513
|
columnNumber: 11
|
|
810
2514
|
}
|
|
811
2515
|
}, /* @__PURE__ */ React__default.default.createElement(Image, {
|
|
@@ -813,7 +2517,7 @@
|
|
|
813
2517
|
__self: this,
|
|
814
2518
|
__source: {
|
|
815
2519
|
fileName: _jsxFileName$4,
|
|
816
|
-
lineNumber:
|
|
2520
|
+
lineNumber: 173,
|
|
817
2521
|
columnNumber: 13
|
|
818
2522
|
}
|
|
819
2523
|
})) : null;
|
|
@@ -825,7 +2529,7 @@
|
|
|
825
2529
|
__self: this,
|
|
826
2530
|
__source: {
|
|
827
2531
|
fileName: _jsxFileName$4,
|
|
828
|
-
lineNumber:
|
|
2532
|
+
lineNumber: 178,
|
|
829
2533
|
columnNumber: 16
|
|
830
2534
|
}
|
|
831
2535
|
});
|
|
@@ -838,7 +2542,7 @@
|
|
|
838
2542
|
__self: this,
|
|
839
2543
|
__source: {
|
|
840
2544
|
fileName: _jsxFileName$4,
|
|
841
|
-
lineNumber:
|
|
2545
|
+
lineNumber: 185,
|
|
842
2546
|
columnNumber: 5
|
|
843
2547
|
}
|
|
844
2548
|
}, (_i = parsedMetafield.value) == null ? void 0 : _i.toString());
|
|
@@ -898,9 +2602,9 @@
|
|
|
898
2602
|
}
|
|
899
2603
|
function parseJSON(json) {
|
|
900
2604
|
if (String(json).includes("__proto__")) {
|
|
901
|
-
return JSON.parse(json, (k,
|
|
2605
|
+
return JSON.parse(json, (k, v2) => {
|
|
902
2606
|
if (k !== "__proto__")
|
|
903
|
-
return
|
|
2607
|
+
return v2;
|
|
904
2608
|
});
|
|
905
2609
|
}
|
|
906
2610
|
return JSON.parse(json);
|
|
@@ -1141,7 +2845,7 @@
|
|
|
1141
2845
|
__self: this,
|
|
1142
2846
|
__source: {
|
|
1143
2847
|
fileName: _jsxFileName$2,
|
|
1144
|
-
lineNumber:
|
|
2848
|
+
lineNumber: 81,
|
|
1145
2849
|
columnNumber: 7
|
|
1146
2850
|
}
|
|
1147
2851
|
});
|
|
@@ -1152,7 +2856,7 @@
|
|
|
1152
2856
|
__self: this,
|
|
1153
2857
|
__source: {
|
|
1154
2858
|
fileName: _jsxFileName$2,
|
|
1155
|
-
lineNumber:
|
|
2859
|
+
lineNumber: 85,
|
|
1156
2860
|
columnNumber: 10
|
|
1157
2861
|
}
|
|
1158
2862
|
});
|
|
@@ -1361,7 +3065,7 @@
|
|
|
1361
3065
|
__self: this,
|
|
1362
3066
|
__source: {
|
|
1363
3067
|
fileName: _jsxFileName,
|
|
1364
|
-
lineNumber:
|
|
3068
|
+
lineNumber: 90,
|
|
1365
3069
|
columnNumber: 5
|
|
1366
3070
|
}
|
|
1367
3071
|
}, shopPayLoadedStatus === "done" && /* @__PURE__ */ React__default.default.createElement("shop-pay-button", {
|
|
@@ -1370,7 +3074,7 @@
|
|
|
1370
3074
|
__self: this,
|
|
1371
3075
|
__source: {
|
|
1372
3076
|
fileName: _jsxFileName,
|
|
1373
|
-
lineNumber:
|
|
3077
|
+
lineNumber: 92,
|
|
1374
3078
|
columnNumber: 9
|
|
1375
3079
|
}
|
|
1376
3080
|
}));
|
|
@@ -1449,6 +3153,7 @@
|
|
|
1449
3153
|
}
|
|
1450
3154
|
};
|
|
1451
3155
|
}
|
|
3156
|
+
exports2.CartProvider = CartProvider;
|
|
1452
3157
|
exports2.ExternalVideo = ExternalVideo;
|
|
1453
3158
|
exports2.Image = Image;
|
|
1454
3159
|
exports2.MediaFile = MediaFile;
|
|
@@ -1464,6 +3169,7 @@
|
|
|
1464
3169
|
exports2.flattenConnection = flattenConnection;
|
|
1465
3170
|
exports2.parseMetafield = parseMetafield;
|
|
1466
3171
|
exports2.parseMetafieldValue = parseMetafieldValue;
|
|
3172
|
+
exports2.useCart = useCart;
|
|
1467
3173
|
exports2.useMoney = useMoney;
|
|
1468
3174
|
exports2.useProduct = useProduct;
|
|
1469
3175
|
exports2.useShop = useShop;
|