@gem-sdk/core 1.5.15 → 1.5.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/components/AddOn.js +7 -7
- package/dist/cjs/components/ComponentWrapper.js +14 -8
- package/dist/cjs/components/ComponentWrapperPreview.js +55 -46
- package/dist/cjs/components/Empty.js +1 -1
- package/dist/cjs/components/Render.js +50 -13
- package/dist/cjs/components/Render.liquid.js +81 -57
- package/dist/cjs/components/RenderBlock.js +41 -8
- package/dist/cjs/components/RenderPreview.js +51 -13
- package/dist/cjs/components/RenderSection.js +11 -7
- package/dist/cjs/components/constant.js +24 -24
- package/dist/cjs/contexts/AddonContext.js +25 -14
- package/dist/cjs/contexts/BuilderComponent.js +23 -19
- package/dist/cjs/contexts/BuilderContext.js +25 -19
- package/dist/cjs/contexts/BuilderPreviewContext.js +349 -341
- package/dist/cjs/contexts/CartLineContext.js +19 -14
- package/dist/cjs/contexts/CollectionContext.js +21 -13
- package/dist/cjs/contexts/ProductContext.js +136 -115
- package/dist/cjs/contexts/ProductListContext.js +21 -13
- package/dist/cjs/contexts/SectionContext.js +41 -37
- package/dist/cjs/contexts/ShopContext.js +49 -31
- package/dist/cjs/graphql/fragments/analytic.generated.js +1 -1
- package/dist/cjs/graphql/fragments/collection-detail.generated.js +1 -1
- package/dist/cjs/graphql/fragments/collection-product.generated.js +1 -1
- package/dist/cjs/graphql/fragments/custom-code.generated.js +1 -1
- package/dist/cjs/graphql/fragments/data-seo.generated.js +1 -1
- package/dist/cjs/graphql/fragments/media.generated.js +1 -1
- package/dist/cjs/graphql/fragments/product-little.generated.js +1 -1
- package/dist/cjs/graphql/fragments/product-option-value.generated.js +1 -1
- package/dist/cjs/graphql/fragments/product-option.generated.js +1 -1
- package/dist/cjs/graphql/fragments/product.generated.js +1 -1
- package/dist/cjs/graphql/fragments/published-custom-section.generated.js +1 -1
- package/dist/cjs/graphql/fragments/published-page-section.generated.js +1 -1
- package/dist/cjs/graphql/fragments/published-theme-page.generated.js +1 -1
- package/dist/cjs/graphql/fragments/published-theme-style.generated.js +1 -1
- package/dist/cjs/graphql/fragments/selected-option.generated.js +1 -1
- package/dist/cjs/graphql/fragments/variant.generated.js +1 -1
- package/dist/cjs/graphql/mutations/page-view-up.generated.js +1 -1
- package/dist/cjs/graphql/queries/products.generated.js +1 -1
- package/dist/cjs/graphql/queries/store-property.generated.js +1 -1
- package/dist/cjs/helpers/GlobalEvent.js +12 -10
- package/dist/cjs/helpers/background.js +96 -96
- package/dist/cjs/helpers/borders.js +123 -127
- package/dist/cjs/helpers/clone-deep.js +1 -1
- package/dist/cjs/helpers/cls.js +11 -15
- package/dist/cjs/helpers/colors.js +121 -156
- package/dist/cjs/helpers/compose-advance-style.js +115 -121
- package/dist/cjs/helpers/constant.js +16 -11
- package/dist/cjs/helpers/css-variable.js +2 -2
- package/dist/cjs/helpers/email.js +3 -3
- package/dist/cjs/helpers/flatten-connection.js +4 -5
- package/dist/cjs/helpers/get-resonsive-value.js +24 -25
- package/dist/cjs/helpers/get-shortname.js +87 -87
- package/dist/cjs/helpers/is-browser.js +2 -2
- package/dist/cjs/helpers/is-defined.js +2 -2
- package/dist/cjs/helpers/is-empty-children.js +2 -2
- package/dist/cjs/helpers/layout.js +9 -10
- package/dist/cjs/helpers/load-script.js +26 -27
- package/dist/cjs/helpers/make-style.js +77 -86
- package/dist/cjs/helpers/normalize-builder-data.js +18 -12
- package/dist/cjs/helpers/prefetch-queries.js +72 -52
- package/dist/cjs/helpers/product.js +25 -29
- package/dist/cjs/helpers/queries/get-collection.js +179 -167
- package/dist/cjs/helpers/queries/get-product-by-slug.js +103 -94
- package/dist/cjs/helpers/queries/get-product.js +121 -106
- package/dist/cjs/helpers/queries/get-products.js +137 -125
- package/dist/cjs/helpers/radius.js +78 -81
- package/dist/cjs/helpers/render.js +56 -56
- package/dist/cjs/helpers/shadow.js +38 -38
- package/dist/cjs/helpers/size.js +12 -13
- package/dist/cjs/helpers/spacing.js +35 -37
- package/dist/cjs/helpers/tracking/fpixel.js +21 -22
- package/dist/cjs/helpers/tracking/gtag.js +84 -90
- package/dist/cjs/helpers/tracking/tiktokpixel.js +12 -12
- package/dist/cjs/helpers/typography.js +2 -2
- package/dist/cjs/hooks/cart/use-add-to-cart.js +10 -10
- package/dist/cjs/hooks/cart/use-cart-data.js +18 -16
- package/dist/cjs/hooks/cart/use-cart-discount-codes-update.js +10 -10
- package/dist/cjs/hooks/cart/use-cart-note-update.js +10 -10
- package/dist/cjs/hooks/cart/use-create-cart.js +12 -12
- package/dist/cjs/hooks/cart/use-remove-cart-item.js +10 -10
- package/dist/cjs/hooks/cart/use-update-cart-item.js +10 -10
- package/dist/cjs/hooks/shop/use-collection-query.js +12 -6
- package/dist/cjs/hooks/shop/use-product-query.js +12 -6
- package/dist/cjs/hooks/shop/use-products-query.js +14 -6
- package/dist/cjs/hooks/shop.js +86 -67
- package/dist/cjs/hooks/use-current-device.js +14 -16
- package/dist/cjs/hooks/use-lazy-video.js +7 -7
- package/dist/cjs/hooks/useCartId.js +35 -27
- package/dist/cjs/hooks/useCartLine.js +2 -2
- package/dist/cjs/hooks/useCartUI.js +37 -31
- package/dist/cjs/hooks/useCollection.js +2 -2
- package/dist/cjs/hooks/useFetchHandle.js +6 -6
- package/dist/cjs/hooks/useFormatMoney.js +11 -7
- package/dist/cjs/hooks/useIsomorphicLayoutEffect.js +1 -1
- package/dist/cjs/hooks/useLoadScript.js +22 -20
- package/dist/cjs/hooks/useMoney.js +59 -42
- package/dist/cjs/hooks/usePrevious.js +12 -10
- package/dist/cjs/hooks/useProduct.js +93 -69
- package/dist/cjs/hooks/useProductList.js +11 -11
- package/dist/cjs/hooks/useSuspenseFetch.js +20 -17
- package/dist/cjs/hooks/useSwatchesOptions.js +32 -30
- package/dist/cjs/types/global-style.js +9 -2
- package/dist/esm/components/AddOn.js +7 -7
- package/dist/esm/components/ComponentWrapper.js +14 -8
- package/dist/esm/components/ComponentWrapperPreview.js +55 -46
- package/dist/esm/components/Empty.js +1 -1
- package/dist/esm/components/Render.js +50 -13
- package/dist/esm/components/Render.liquid.js +81 -57
- package/dist/esm/components/RenderBlock.js +41 -8
- package/dist/esm/components/RenderPreview.js +51 -13
- package/dist/esm/components/RenderSection.js +11 -7
- package/dist/esm/components/constant.js +24 -24
- package/dist/esm/contexts/AddonContext.js +26 -15
- package/dist/esm/contexts/BuilderComponent.js +24 -20
- package/dist/esm/contexts/BuilderContext.js +26 -20
- package/dist/esm/contexts/BuilderPreviewContext.js +350 -342
- package/dist/esm/contexts/CartLineContext.js +20 -15
- package/dist/esm/contexts/CollectionContext.js +22 -14
- package/dist/esm/contexts/ProductContext.js +137 -116
- package/dist/esm/contexts/ProductListContext.js +22 -14
- package/dist/esm/contexts/SectionContext.js +42 -38
- package/dist/esm/contexts/ShopContext.js +50 -32
- package/dist/esm/graphql/fragments/analytic.generated.js +1 -1
- package/dist/esm/graphql/fragments/collection-detail.generated.js +1 -1
- package/dist/esm/graphql/fragments/collection-product.generated.js +1 -1
- package/dist/esm/graphql/fragments/custom-code.generated.js +1 -1
- package/dist/esm/graphql/fragments/data-seo.generated.js +1 -1
- package/dist/esm/graphql/fragments/media.generated.js +1 -1
- package/dist/esm/graphql/fragments/product-little.generated.js +1 -1
- package/dist/esm/graphql/fragments/product-option-value.generated.js +1 -1
- package/dist/esm/graphql/fragments/product-option.generated.js +1 -1
- package/dist/esm/graphql/fragments/product.generated.js +1 -1
- package/dist/esm/graphql/fragments/published-custom-section.generated.js +1 -1
- package/dist/esm/graphql/fragments/published-page-section.generated.js +1 -1
- package/dist/esm/graphql/fragments/published-theme-page.generated.js +1 -1
- package/dist/esm/graphql/fragments/published-theme-style.generated.js +1 -1
- package/dist/esm/graphql/fragments/selected-option.generated.js +1 -1
- package/dist/esm/graphql/fragments/variant.generated.js +1 -1
- package/dist/esm/graphql/mutations/page-view-up.generated.js +1 -1
- package/dist/esm/graphql/queries/products.generated.js +1 -1
- package/dist/esm/graphql/queries/store-property.generated.js +1 -1
- package/dist/esm/helpers/GlobalEvent.js +12 -10
- package/dist/esm/helpers/background.js +96 -96
- package/dist/esm/helpers/borders.js +123 -127
- package/dist/esm/helpers/clone-deep.js +1 -1
- package/dist/esm/helpers/cls.js +11 -15
- package/dist/esm/helpers/colors.js +121 -156
- package/dist/esm/helpers/compose-advance-style.js +115 -121
- package/dist/esm/helpers/constant.js +16 -11
- package/dist/esm/helpers/css-variable.js +2 -2
- package/dist/esm/helpers/email.js +3 -3
- package/dist/esm/helpers/flatten-connection.js +4 -5
- package/dist/esm/helpers/get-resonsive-value.js +24 -25
- package/dist/esm/helpers/get-shortname.js +87 -87
- package/dist/esm/helpers/is-browser.js +2 -2
- package/dist/esm/helpers/is-defined.js +2 -2
- package/dist/esm/helpers/is-empty-children.js +2 -2
- package/dist/esm/helpers/layout.js +9 -10
- package/dist/esm/helpers/load-script.js +26 -27
- package/dist/esm/helpers/make-style.js +77 -86
- package/dist/esm/helpers/normalize-builder-data.js +18 -12
- package/dist/esm/helpers/prefetch-queries.js +72 -52
- package/dist/esm/helpers/product.js +25 -29
- package/dist/esm/helpers/queries/get-collection.js +179 -167
- package/dist/esm/helpers/queries/get-product-by-slug.js +103 -94
- package/dist/esm/helpers/queries/get-product.js +121 -106
- package/dist/esm/helpers/queries/get-products.js +137 -125
- package/dist/esm/helpers/radius.js +78 -81
- package/dist/esm/helpers/render.js +56 -56
- package/dist/esm/helpers/shadow.js +38 -38
- package/dist/esm/helpers/size.js +12 -13
- package/dist/esm/helpers/spacing.js +35 -37
- package/dist/esm/helpers/tracking/fpixel.js +21 -22
- package/dist/esm/helpers/tracking/gtag.js +84 -90
- package/dist/esm/helpers/tracking/tiktokpixel.js +12 -12
- package/dist/esm/helpers/typography.js +2 -2
- package/dist/esm/hooks/cart/use-add-to-cart.js +10 -10
- package/dist/esm/hooks/cart/use-cart-data.js +18 -16
- package/dist/esm/hooks/cart/use-cart-discount-codes-update.js +10 -10
- package/dist/esm/hooks/cart/use-cart-note-update.js +10 -10
- package/dist/esm/hooks/cart/use-create-cart.js +12 -12
- package/dist/esm/hooks/cart/use-remove-cart-item.js +10 -10
- package/dist/esm/hooks/cart/use-update-cart-item.js +10 -10
- package/dist/esm/hooks/shop/use-collection-query.js +12 -6
- package/dist/esm/hooks/shop/use-product-query.js +12 -6
- package/dist/esm/hooks/shop/use-products-query.js +14 -6
- package/dist/esm/hooks/shop.js +86 -67
- package/dist/esm/hooks/use-current-device.js +14 -16
- package/dist/esm/hooks/use-lazy-video.js +7 -7
- package/dist/esm/hooks/useCartId.js +35 -27
- package/dist/esm/hooks/useCartLine.js +2 -2
- package/dist/esm/hooks/useCartUI.js +37 -31
- package/dist/esm/hooks/useCollection.js +2 -2
- package/dist/esm/hooks/useFetchHandle.js +6 -6
- package/dist/esm/hooks/useFormatMoney.js +11 -7
- package/dist/esm/hooks/useIsomorphicLayoutEffect.js +1 -1
- package/dist/esm/hooks/useLoadScript.js +22 -20
- package/dist/esm/hooks/useMoney.js +59 -42
- package/dist/esm/hooks/usePrevious.js +12 -10
- package/dist/esm/hooks/useProduct.js +93 -70
- package/dist/esm/hooks/useProductList.js +11 -11
- package/dist/esm/hooks/useSuspenseFetch.js +20 -17
- package/dist/esm/hooks/useSwatchesOptions.js +32 -30
- package/dist/esm/types/global-style.js +9 -2
- package/dist/types/index.d.ts +24 -2
- package/package.json +1 -1
|
@@ -1,21 +1,26 @@
|
|
|
1
1
|
import { jsx } from 'react/jsx-runtime';
|
|
2
2
|
import { useStore, createStore } from 'zustand';
|
|
3
|
-
import {
|
|
3
|
+
import { useContext, createContext } from 'react';
|
|
4
4
|
|
|
5
|
-
const CartLineContext = createContext(null);
|
|
6
|
-
const createCartLineStore = (data)
|
|
7
|
-
|
|
8
|
-
}));
|
|
9
|
-
const CartLineProvider = ({ children, line
|
|
10
|
-
return
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
5
|
+
const CartLineContext = /*#__PURE__*/ createContext(null);
|
|
6
|
+
const createCartLineStore = (data)=>createStore(()=>({
|
|
7
|
+
...data
|
|
8
|
+
}));
|
|
9
|
+
const CartLineProvider = ({ children , line })=>{
|
|
10
|
+
return /*#__PURE__*/ jsx(CartLineContext.Provider, {
|
|
11
|
+
value: createCartLineStore({
|
|
12
|
+
line
|
|
13
|
+
}),
|
|
14
|
+
children: children
|
|
15
|
+
}, `${line.id}-${line.quantity}`);
|
|
16
|
+
};
|
|
17
|
+
// export const useCartLineStore = useStore;
|
|
18
|
+
const useCartLineStore = (selector, equalityFn)=>{
|
|
19
|
+
const store = useContext(CartLineContext);
|
|
20
|
+
if (!store) {
|
|
21
|
+
throw new Error('useCartLineStore must be used within a CartLineProvider');
|
|
22
|
+
}
|
|
23
|
+
return useStore(store, selector, equalityFn);
|
|
19
24
|
};
|
|
20
25
|
|
|
21
26
|
export { CartLineProvider, useCartLineStore };
|
|
@@ -1,20 +1,28 @@
|
|
|
1
1
|
import { jsx } from 'react/jsx-runtime';
|
|
2
|
-
import {
|
|
2
|
+
import { useContext, createContext } from 'react';
|
|
3
3
|
import { useStore, createStore } from 'zustand';
|
|
4
4
|
|
|
5
|
-
const CollectionListContext = createContext(null);
|
|
6
|
-
const createCollectionProvider = (data)
|
|
7
|
-
|
|
8
|
-
}));
|
|
9
|
-
const CollectionProvider = ({ children, collection, products, settings, styles
|
|
10
|
-
return
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
5
|
+
const CollectionListContext = /*#__PURE__*/ createContext(null);
|
|
6
|
+
const createCollectionProvider = (data)=>createStore(()=>({
|
|
7
|
+
...data
|
|
8
|
+
}));
|
|
9
|
+
const CollectionProvider = ({ children , collection , products , settings , styles })=>{
|
|
10
|
+
return /*#__PURE__*/ jsx(CollectionListContext.Provider, {
|
|
11
|
+
value: createCollectionProvider({
|
|
12
|
+
products,
|
|
13
|
+
collection,
|
|
14
|
+
settings,
|
|
15
|
+
styles
|
|
16
|
+
}),
|
|
17
|
+
children: children
|
|
18
|
+
}, collection?.id);
|
|
19
|
+
};
|
|
20
|
+
const useCollectionStore = (selector, equalityFn)=>{
|
|
21
|
+
const store = useContext(CollectionListContext);
|
|
22
|
+
if (!store) {
|
|
23
|
+
throw new Error('useCollectionStore must be used within a useCollectionStore');
|
|
24
|
+
}
|
|
25
|
+
return useStore(store, selector, equalityFn);
|
|
18
26
|
};
|
|
19
27
|
|
|
20
28
|
export { CollectionListContext, CollectionProvider, useCollectionStore };
|
|
@@ -1,123 +1,144 @@
|
|
|
1
1
|
import { jsx, Fragment } from 'react/jsx-runtime';
|
|
2
2
|
import { useStore, createStore } from 'zustand';
|
|
3
|
-
import {
|
|
3
|
+
import { useId, useMemo, useContext, createContext } from 'react';
|
|
4
4
|
import { flattenConnection } from '../helpers/flatten-connection.js';
|
|
5
5
|
|
|
6
|
-
// const { Provider, useStore } = createContext<StoreApi<ProductContextProps>>();
|
|
7
|
-
const ProductContext = createContext(null);
|
|
8
|
-
const createProductStoreProvider = (data)
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
6
|
+
// const { Provider, useStore } = createContext<StoreApi<ProductContextProps>>();
|
|
7
|
+
const ProductContext = /*#__PURE__*/ createContext(null);
|
|
8
|
+
const createProductStoreProvider = (data)=>createStore((set, get)=>({
|
|
9
|
+
...data,
|
|
10
|
+
updateProperty: (name, data)=>{
|
|
11
|
+
set((state)=>{
|
|
12
|
+
return {
|
|
13
|
+
properties: state.properties?.map((v)=>{
|
|
14
|
+
if (v.key === name) {
|
|
15
|
+
return {
|
|
16
|
+
...v,
|
|
17
|
+
...data
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
return v;
|
|
21
|
+
})
|
|
22
|
+
};
|
|
23
|
+
});
|
|
24
|
+
},
|
|
25
|
+
addProperty: (data)=>{
|
|
26
|
+
const properties = get().properties;
|
|
27
|
+
if (!properties?.some((v)=>v.key === data.key)) {
|
|
28
|
+
set((state)=>({
|
|
29
|
+
properties: [
|
|
30
|
+
...state.properties ?? [],
|
|
31
|
+
data
|
|
32
|
+
]
|
|
33
|
+
}));
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
removeProperty: (name)=>{
|
|
37
|
+
set((state)=>({
|
|
38
|
+
properties: state.properties?.filter((v)=>v.key !== name)
|
|
39
|
+
}));
|
|
40
|
+
},
|
|
41
|
+
setQuantity: (num)=>{
|
|
42
|
+
set({
|
|
43
|
+
quantity: num > 0 ? num : 1
|
|
44
|
+
});
|
|
45
|
+
},
|
|
46
|
+
setProductFeaturedImage: (image)=>{
|
|
47
|
+
set({
|
|
48
|
+
featuredImageGlobal: image
|
|
49
|
+
});
|
|
50
|
+
},
|
|
51
|
+
incrementQuantity: ()=>{
|
|
52
|
+
set((state)=>{
|
|
53
|
+
const quantity = state.quantity ?? 1;
|
|
54
|
+
return {
|
|
55
|
+
quantity: quantity + 1
|
|
56
|
+
};
|
|
57
|
+
});
|
|
58
|
+
},
|
|
59
|
+
decrementQuantity: ()=>{
|
|
60
|
+
set((state)=>{
|
|
61
|
+
const quantity = state.quantity ?? 1;
|
|
62
|
+
return {
|
|
63
|
+
quantity: quantity > 2 ? quantity - 1 : 1
|
|
64
|
+
};
|
|
65
|
+
});
|
|
66
|
+
},
|
|
67
|
+
setSelectedOption: (optionId, optionValue)=>{
|
|
68
|
+
set((state)=>{
|
|
69
|
+
if (optionId && optionValue) {
|
|
70
|
+
return {
|
|
71
|
+
selectedOptions: {
|
|
72
|
+
...state?.selectedOptions,
|
|
73
|
+
[optionId]: optionValue
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
return state;
|
|
78
|
+
});
|
|
79
|
+
},
|
|
80
|
+
forceSelectedOption: (value)=>{
|
|
81
|
+
set((state)=>{
|
|
82
|
+
return {
|
|
83
|
+
selectedOptions: {
|
|
84
|
+
...state?.selectedOptions,
|
|
85
|
+
...value
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
});
|
|
89
|
+
},
|
|
90
|
+
updateIsSubmit: (value)=>{
|
|
91
|
+
set({
|
|
92
|
+
isSubmit: value
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
}));
|
|
96
|
+
const ProductProvider = ({ children , product , initialVariantId , quantity =1 })=>{
|
|
97
|
+
const uiqueId = useId();
|
|
98
|
+
const store = useMemo(()=>{
|
|
99
|
+
let selectedOptions = {};
|
|
100
|
+
let featuredImageGlobal = undefined;
|
|
101
|
+
if (product) {
|
|
102
|
+
const variants = flattenConnection(product.variants);
|
|
103
|
+
const firstVariant = flattenConnection(product.variants)[0];
|
|
104
|
+
const initialVariant = variants.find((v)=>v?.id === initialVariantId) ?? firstVariant;
|
|
105
|
+
selectedOptions = initialVariant?.selectedOptions.reduce((acc, option)=>{
|
|
106
|
+
if (option.name) {
|
|
107
|
+
return {
|
|
108
|
+
...acc,
|
|
109
|
+
[option.name]: option.value
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
return acc;
|
|
113
|
+
}, {});
|
|
114
|
+
featuredImageGlobal = product.medias?.edges.find((v)=>v.node?.id === initialVariant?.mediaId)?.node ?? product.featuredImage;
|
|
115
|
+
}
|
|
116
|
+
return createProductStoreProvider({
|
|
117
|
+
product,
|
|
118
|
+
quantity,
|
|
119
|
+
selectedOptions,
|
|
120
|
+
uiqueId,
|
|
121
|
+
featuredImageGlobal
|
|
122
|
+
});
|
|
123
|
+
}, [
|
|
124
|
+
initialVariantId,
|
|
125
|
+
product,
|
|
126
|
+
quantity,
|
|
127
|
+
uiqueId
|
|
128
|
+
]);
|
|
129
|
+
return /*#__PURE__*/ jsx(ProductContext.Provider, {
|
|
130
|
+
value: store,
|
|
131
|
+
children: /*#__PURE__*/ jsx(Fragment, {
|
|
132
|
+
children: children
|
|
133
|
+
})
|
|
134
|
+
});
|
|
135
|
+
};
|
|
136
|
+
const useProductStore = (selector, equalityFn)=>{
|
|
137
|
+
const store = useContext(ProductContext);
|
|
138
|
+
if (!store) {
|
|
139
|
+
throw new Error('Element of product must be used inside a Product');
|
|
140
|
+
}
|
|
141
|
+
return useStore(store, selector, equalityFn);
|
|
121
142
|
};
|
|
122
143
|
|
|
123
144
|
export { ProductProvider, useProductStore };
|
|
@@ -1,20 +1,28 @@
|
|
|
1
1
|
import { jsx } from 'react/jsx-runtime';
|
|
2
|
-
import {
|
|
2
|
+
import { useContext, createContext } from 'react';
|
|
3
3
|
import { useStore, createStore } from 'zustand';
|
|
4
4
|
|
|
5
|
-
const ProductListContext = createContext(null);
|
|
6
|
-
const createProductListProvider = (data)
|
|
7
|
-
|
|
8
|
-
}));
|
|
9
|
-
const ProductListProvider = ({ children, collection, products, settings, styles
|
|
10
|
-
return
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
5
|
+
const ProductListContext = /*#__PURE__*/ createContext(null);
|
|
6
|
+
const createProductListProvider = (data)=>createStore(()=>({
|
|
7
|
+
...data
|
|
8
|
+
}));
|
|
9
|
+
const ProductListProvider = ({ children , collection , products , settings , styles })=>{
|
|
10
|
+
return /*#__PURE__*/ jsx(ProductListContext.Provider, {
|
|
11
|
+
value: createProductListProvider({
|
|
12
|
+
products,
|
|
13
|
+
collection,
|
|
14
|
+
settings,
|
|
15
|
+
styles
|
|
16
|
+
}),
|
|
17
|
+
children: children
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
const useProductListStore = (selector, equalityFn)=>{
|
|
21
|
+
const store = useContext(ProductListContext);
|
|
22
|
+
if (!store) {
|
|
23
|
+
throw new Error('useProductListStore must be used within a useProductListStore');
|
|
24
|
+
}
|
|
25
|
+
return useStore(store, selector, equalityFn);
|
|
18
26
|
};
|
|
19
27
|
|
|
20
28
|
export { ProductListContext, ProductListProvider, useProductListStore };
|
|
@@ -1,45 +1,49 @@
|
|
|
1
1
|
import { jsx } from 'react/jsx-runtime';
|
|
2
2
|
import { useStore, createStore } from 'zustand';
|
|
3
|
-
import {
|
|
3
|
+
import { useContext, createContext } from 'react';
|
|
4
4
|
import { cloneDeep } from '../helpers/clone-deep.js';
|
|
5
5
|
import { normalizeBuilderData } from '../helpers/normalize-builder-data.js';
|
|
6
6
|
|
|
7
|
-
const SectionContext = createContext(null);
|
|
8
|
-
const createSectionProvider = (data)
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}));
|
|
32
|
-
const SectionProvider = ({ children, data, ...passProps })
|
|
33
|
-
return
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
7
|
+
const SectionContext = /*#__PURE__*/ createContext(null);
|
|
8
|
+
const createSectionProvider = (data)=>createStore((set, get)=>({
|
|
9
|
+
data: data ?? {},
|
|
10
|
+
getSection: (id)=>{
|
|
11
|
+
const section = get().data[id];
|
|
12
|
+
return section ?? undefined;
|
|
13
|
+
},
|
|
14
|
+
addSection: (id, data)=>{
|
|
15
|
+
const item = normalizeBuilderData(data);
|
|
16
|
+
set((prev)=>({
|
|
17
|
+
data: {
|
|
18
|
+
...prev.data,
|
|
19
|
+
[id]: cloneDeep(item)
|
|
20
|
+
}
|
|
21
|
+
}));
|
|
22
|
+
},
|
|
23
|
+
removeSection: (id)=>{
|
|
24
|
+
set((prev)=>{
|
|
25
|
+
const { [id]: _ , ...rest } = prev.data;
|
|
26
|
+
return {
|
|
27
|
+
data: rest
|
|
28
|
+
};
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
}));
|
|
32
|
+
const SectionProvider = ({ children , data , ...passProps })=>{
|
|
33
|
+
return /*#__PURE__*/ jsx(SectionContext.Provider, {
|
|
34
|
+
...passProps,
|
|
35
|
+
value: createSectionProvider(data),
|
|
36
|
+
children: children
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
// export const useSectionStore = useStore;
|
|
40
|
+
const useSectionStore = (selector, equalityFn)=>{
|
|
41
|
+
const store = useContext(SectionContext);
|
|
42
|
+
if (!store) {
|
|
43
|
+
throw new Error('useSectionStore must be used within a SectionProvider');
|
|
44
|
+
}
|
|
45
|
+
return useStore(store, selector, equalityFn);
|
|
46
|
+
};
|
|
47
|
+
const useSection = (id)=>useSectionStore((s)=>s.getSection(id));
|
|
44
48
|
|
|
45
49
|
export { SectionProvider, useSection, useSectionStore };
|
|
@@ -1,40 +1,58 @@
|
|
|
1
1
|
import { jsx } from 'react/jsx-runtime';
|
|
2
2
|
import { SWRConfig } from 'swr';
|
|
3
3
|
import { useStore, createStore } from 'zustand';
|
|
4
|
-
import {
|
|
4
|
+
import { useMemo, useContext, createContext } from 'react';
|
|
5
5
|
import { AddonProvider } from './AddonContext.js';
|
|
6
6
|
|
|
7
|
-
const ShopContext = createContext(null);
|
|
8
|
-
const createShopStoreProvider = (data)
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
})
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
return
|
|
7
|
+
const ShopContext = /*#__PURE__*/ createContext(null);
|
|
8
|
+
const createShopStoreProvider = (data)=>createStore((set)=>({
|
|
9
|
+
mobileOnly: false,
|
|
10
|
+
...data,
|
|
11
|
+
changeLocale: (locale)=>{
|
|
12
|
+
set({
|
|
13
|
+
locale
|
|
14
|
+
});
|
|
15
|
+
},
|
|
16
|
+
changeCurrency: (currency)=>{
|
|
17
|
+
set({
|
|
18
|
+
currency
|
|
19
|
+
});
|
|
20
|
+
},
|
|
21
|
+
changeSwatches: (swatches)=>{
|
|
22
|
+
set({
|
|
23
|
+
swatches
|
|
24
|
+
});
|
|
25
|
+
},
|
|
26
|
+
changeStorefrontInfo: ({ url , token })=>{
|
|
27
|
+
set({
|
|
28
|
+
storefrontUrl: url,
|
|
29
|
+
storefrontToken: token
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
}));
|
|
33
|
+
const ShopProvider = ({ children , addons , storeOption , queryOption , ...passProps })=>{
|
|
34
|
+
const store = useMemo(()=>createShopStoreProvider(storeOption), [
|
|
35
|
+
storeOption
|
|
36
|
+
]);
|
|
37
|
+
return /*#__PURE__*/ jsx(AddonProvider, {
|
|
38
|
+
components: addons,
|
|
39
|
+
children: /*#__PURE__*/ jsx(SWRConfig, {
|
|
40
|
+
value: queryOption,
|
|
41
|
+
children: /*#__PURE__*/ jsx(ShopContext.Provider, {
|
|
42
|
+
...passProps,
|
|
43
|
+
value: store,
|
|
44
|
+
children: children
|
|
45
|
+
}, JSON.stringify(storeOption))
|
|
46
|
+
})
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
// export const useShopStore = useStore;
|
|
50
|
+
const useShopStore = (selector, equalityFn)=>{
|
|
51
|
+
const store = useContext(ShopContext);
|
|
52
|
+
if (!store) {
|
|
53
|
+
throw new Error('useShopStore must be used within a ShopProvider');
|
|
54
|
+
}
|
|
55
|
+
return useStore(store, selector, equalityFn);
|
|
38
56
|
};
|
|
39
57
|
|
|
40
58
|
export { ShopProvider, useShopStore };
|