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