@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.
Files changed (206) hide show
  1. package/dist/cjs/components/AddOn.js +7 -7
  2. package/dist/cjs/components/ComponentWrapper.js +14 -8
  3. package/dist/cjs/components/ComponentWrapperPreview.js +55 -46
  4. package/dist/cjs/components/Empty.js +1 -1
  5. package/dist/cjs/components/Render.js +50 -13
  6. package/dist/cjs/components/Render.liquid.js +81 -57
  7. package/dist/cjs/components/RenderBlock.js +41 -8
  8. package/dist/cjs/components/RenderPreview.js +51 -13
  9. package/dist/cjs/components/RenderSection.js +11 -7
  10. package/dist/cjs/components/constant.js +24 -24
  11. package/dist/cjs/contexts/AddonContext.js +25 -14
  12. package/dist/cjs/contexts/BuilderComponent.js +23 -19
  13. package/dist/cjs/contexts/BuilderContext.js +25 -19
  14. package/dist/cjs/contexts/BuilderPreviewContext.js +349 -341
  15. package/dist/cjs/contexts/CartLineContext.js +19 -14
  16. package/dist/cjs/contexts/CollectionContext.js +21 -13
  17. package/dist/cjs/contexts/ProductContext.js +136 -115
  18. package/dist/cjs/contexts/ProductListContext.js +21 -13
  19. package/dist/cjs/contexts/SectionContext.js +41 -37
  20. package/dist/cjs/contexts/ShopContext.js +49 -31
  21. package/dist/cjs/graphql/fragments/analytic.generated.js +1 -1
  22. package/dist/cjs/graphql/fragments/collection-detail.generated.js +1 -1
  23. package/dist/cjs/graphql/fragments/collection-product.generated.js +1 -1
  24. package/dist/cjs/graphql/fragments/custom-code.generated.js +1 -1
  25. package/dist/cjs/graphql/fragments/data-seo.generated.js +1 -1
  26. package/dist/cjs/graphql/fragments/media.generated.js +1 -1
  27. package/dist/cjs/graphql/fragments/product-little.generated.js +1 -1
  28. package/dist/cjs/graphql/fragments/product-option-value.generated.js +1 -1
  29. package/dist/cjs/graphql/fragments/product-option.generated.js +1 -1
  30. package/dist/cjs/graphql/fragments/product.generated.js +1 -1
  31. package/dist/cjs/graphql/fragments/published-custom-section.generated.js +1 -1
  32. package/dist/cjs/graphql/fragments/published-page-section.generated.js +1 -1
  33. package/dist/cjs/graphql/fragments/published-theme-page.generated.js +1 -1
  34. package/dist/cjs/graphql/fragments/published-theme-style.generated.js +1 -1
  35. package/dist/cjs/graphql/fragments/selected-option.generated.js +1 -1
  36. package/dist/cjs/graphql/fragments/variant.generated.js +1 -1
  37. package/dist/cjs/graphql/mutations/page-view-up.generated.js +1 -1
  38. package/dist/cjs/graphql/queries/products.generated.js +1 -1
  39. package/dist/cjs/graphql/queries/store-property.generated.js +1 -1
  40. package/dist/cjs/helpers/GlobalEvent.js +12 -10
  41. package/dist/cjs/helpers/background.js +96 -96
  42. package/dist/cjs/helpers/borders.js +123 -127
  43. package/dist/cjs/helpers/clone-deep.js +1 -1
  44. package/dist/cjs/helpers/cls.js +11 -15
  45. package/dist/cjs/helpers/colors.js +121 -156
  46. package/dist/cjs/helpers/compose-advance-style.js +115 -121
  47. package/dist/cjs/helpers/constant.js +16 -11
  48. package/dist/cjs/helpers/css-variable.js +2 -2
  49. package/dist/cjs/helpers/email.js +3 -3
  50. package/dist/cjs/helpers/flatten-connection.js +4 -5
  51. package/dist/cjs/helpers/get-resonsive-value.js +24 -25
  52. package/dist/cjs/helpers/get-shortname.js +87 -87
  53. package/dist/cjs/helpers/is-browser.js +2 -2
  54. package/dist/cjs/helpers/is-defined.js +2 -2
  55. package/dist/cjs/helpers/is-empty-children.js +2 -2
  56. package/dist/cjs/helpers/layout.js +9 -10
  57. package/dist/cjs/helpers/load-script.js +26 -27
  58. package/dist/cjs/helpers/make-style.js +77 -86
  59. package/dist/cjs/helpers/normalize-builder-data.js +18 -12
  60. package/dist/cjs/helpers/prefetch-queries.js +72 -52
  61. package/dist/cjs/helpers/product.js +25 -29
  62. package/dist/cjs/helpers/queries/get-collection.js +179 -167
  63. package/dist/cjs/helpers/queries/get-product-by-slug.js +103 -94
  64. package/dist/cjs/helpers/queries/get-product.js +121 -106
  65. package/dist/cjs/helpers/queries/get-products.js +137 -125
  66. package/dist/cjs/helpers/radius.js +78 -81
  67. package/dist/cjs/helpers/render.js +56 -56
  68. package/dist/cjs/helpers/shadow.js +38 -38
  69. package/dist/cjs/helpers/size.js +12 -13
  70. package/dist/cjs/helpers/spacing.js +35 -37
  71. package/dist/cjs/helpers/tracking/fpixel.js +21 -22
  72. package/dist/cjs/helpers/tracking/gtag.js +84 -90
  73. package/dist/cjs/helpers/tracking/tiktokpixel.js +12 -12
  74. package/dist/cjs/helpers/typography.js +2 -2
  75. package/dist/cjs/hooks/cart/use-add-to-cart.js +10 -10
  76. package/dist/cjs/hooks/cart/use-cart-data.js +18 -16
  77. package/dist/cjs/hooks/cart/use-cart-discount-codes-update.js +10 -10
  78. package/dist/cjs/hooks/cart/use-cart-note-update.js +10 -10
  79. package/dist/cjs/hooks/cart/use-create-cart.js +12 -12
  80. package/dist/cjs/hooks/cart/use-remove-cart-item.js +10 -10
  81. package/dist/cjs/hooks/cart/use-update-cart-item.js +10 -10
  82. package/dist/cjs/hooks/shop/use-collection-query.js +12 -6
  83. package/dist/cjs/hooks/shop/use-product-query.js +12 -6
  84. package/dist/cjs/hooks/shop/use-products-query.js +14 -6
  85. package/dist/cjs/hooks/shop.js +86 -67
  86. package/dist/cjs/hooks/use-current-device.js +14 -16
  87. package/dist/cjs/hooks/use-lazy-video.js +7 -7
  88. package/dist/cjs/hooks/useCartId.js +35 -27
  89. package/dist/cjs/hooks/useCartLine.js +2 -2
  90. package/dist/cjs/hooks/useCartUI.js +37 -31
  91. package/dist/cjs/hooks/useCollection.js +2 -2
  92. package/dist/cjs/hooks/useFetchHandle.js +6 -6
  93. package/dist/cjs/hooks/useFormatMoney.js +11 -7
  94. package/dist/cjs/hooks/useIsomorphicLayoutEffect.js +1 -1
  95. package/dist/cjs/hooks/useLoadScript.js +22 -20
  96. package/dist/cjs/hooks/useMoney.js +59 -42
  97. package/dist/cjs/hooks/usePrevious.js +12 -10
  98. package/dist/cjs/hooks/useProduct.js +93 -69
  99. package/dist/cjs/hooks/useProductList.js +11 -11
  100. package/dist/cjs/hooks/useSuspenseFetch.js +20 -17
  101. package/dist/cjs/hooks/useSwatchesOptions.js +32 -30
  102. package/dist/cjs/types/global-style.js +9 -2
  103. package/dist/esm/components/AddOn.js +7 -7
  104. package/dist/esm/components/ComponentWrapper.js +14 -8
  105. package/dist/esm/components/ComponentWrapperPreview.js +55 -46
  106. package/dist/esm/components/Empty.js +1 -1
  107. package/dist/esm/components/Render.js +50 -13
  108. package/dist/esm/components/Render.liquid.js +81 -57
  109. package/dist/esm/components/RenderBlock.js +41 -8
  110. package/dist/esm/components/RenderPreview.js +51 -13
  111. package/dist/esm/components/RenderSection.js +11 -7
  112. package/dist/esm/components/constant.js +24 -24
  113. package/dist/esm/contexts/AddonContext.js +26 -15
  114. package/dist/esm/contexts/BuilderComponent.js +24 -20
  115. package/dist/esm/contexts/BuilderContext.js +26 -20
  116. package/dist/esm/contexts/BuilderPreviewContext.js +350 -342
  117. package/dist/esm/contexts/CartLineContext.js +20 -15
  118. package/dist/esm/contexts/CollectionContext.js +22 -14
  119. package/dist/esm/contexts/ProductContext.js +137 -116
  120. package/dist/esm/contexts/ProductListContext.js +22 -14
  121. package/dist/esm/contexts/SectionContext.js +42 -38
  122. package/dist/esm/contexts/ShopContext.js +50 -32
  123. package/dist/esm/graphql/fragments/analytic.generated.js +1 -1
  124. package/dist/esm/graphql/fragments/collection-detail.generated.js +1 -1
  125. package/dist/esm/graphql/fragments/collection-product.generated.js +1 -1
  126. package/dist/esm/graphql/fragments/custom-code.generated.js +1 -1
  127. package/dist/esm/graphql/fragments/data-seo.generated.js +1 -1
  128. package/dist/esm/graphql/fragments/media.generated.js +1 -1
  129. package/dist/esm/graphql/fragments/product-little.generated.js +1 -1
  130. package/dist/esm/graphql/fragments/product-option-value.generated.js +1 -1
  131. package/dist/esm/graphql/fragments/product-option.generated.js +1 -1
  132. package/dist/esm/graphql/fragments/product.generated.js +1 -1
  133. package/dist/esm/graphql/fragments/published-custom-section.generated.js +1 -1
  134. package/dist/esm/graphql/fragments/published-page-section.generated.js +1 -1
  135. package/dist/esm/graphql/fragments/published-theme-page.generated.js +1 -1
  136. package/dist/esm/graphql/fragments/published-theme-style.generated.js +1 -1
  137. package/dist/esm/graphql/fragments/selected-option.generated.js +1 -1
  138. package/dist/esm/graphql/fragments/variant.generated.js +1 -1
  139. package/dist/esm/graphql/mutations/page-view-up.generated.js +1 -1
  140. package/dist/esm/graphql/queries/products.generated.js +1 -1
  141. package/dist/esm/graphql/queries/store-property.generated.js +1 -1
  142. package/dist/esm/helpers/GlobalEvent.js +12 -10
  143. package/dist/esm/helpers/background.js +96 -96
  144. package/dist/esm/helpers/borders.js +123 -127
  145. package/dist/esm/helpers/clone-deep.js +1 -1
  146. package/dist/esm/helpers/cls.js +11 -15
  147. package/dist/esm/helpers/colors.js +121 -156
  148. package/dist/esm/helpers/compose-advance-style.js +115 -121
  149. package/dist/esm/helpers/constant.js +16 -11
  150. package/dist/esm/helpers/css-variable.js +2 -2
  151. package/dist/esm/helpers/email.js +3 -3
  152. package/dist/esm/helpers/flatten-connection.js +4 -5
  153. package/dist/esm/helpers/get-resonsive-value.js +24 -25
  154. package/dist/esm/helpers/get-shortname.js +87 -87
  155. package/dist/esm/helpers/is-browser.js +2 -2
  156. package/dist/esm/helpers/is-defined.js +2 -2
  157. package/dist/esm/helpers/is-empty-children.js +2 -2
  158. package/dist/esm/helpers/layout.js +9 -10
  159. package/dist/esm/helpers/load-script.js +26 -27
  160. package/dist/esm/helpers/make-style.js +77 -86
  161. package/dist/esm/helpers/normalize-builder-data.js +18 -12
  162. package/dist/esm/helpers/prefetch-queries.js +72 -52
  163. package/dist/esm/helpers/product.js +25 -29
  164. package/dist/esm/helpers/queries/get-collection.js +179 -167
  165. package/dist/esm/helpers/queries/get-product-by-slug.js +103 -94
  166. package/dist/esm/helpers/queries/get-product.js +121 -106
  167. package/dist/esm/helpers/queries/get-products.js +137 -125
  168. package/dist/esm/helpers/radius.js +78 -81
  169. package/dist/esm/helpers/render.js +56 -56
  170. package/dist/esm/helpers/shadow.js +38 -38
  171. package/dist/esm/helpers/size.js +12 -13
  172. package/dist/esm/helpers/spacing.js +35 -37
  173. package/dist/esm/helpers/tracking/fpixel.js +21 -22
  174. package/dist/esm/helpers/tracking/gtag.js +84 -90
  175. package/dist/esm/helpers/tracking/tiktokpixel.js +12 -12
  176. package/dist/esm/helpers/typography.js +2 -2
  177. package/dist/esm/hooks/cart/use-add-to-cart.js +10 -10
  178. package/dist/esm/hooks/cart/use-cart-data.js +18 -16
  179. package/dist/esm/hooks/cart/use-cart-discount-codes-update.js +10 -10
  180. package/dist/esm/hooks/cart/use-cart-note-update.js +10 -10
  181. package/dist/esm/hooks/cart/use-create-cart.js +12 -12
  182. package/dist/esm/hooks/cart/use-remove-cart-item.js +10 -10
  183. package/dist/esm/hooks/cart/use-update-cart-item.js +10 -10
  184. package/dist/esm/hooks/shop/use-collection-query.js +12 -6
  185. package/dist/esm/hooks/shop/use-product-query.js +12 -6
  186. package/dist/esm/hooks/shop/use-products-query.js +14 -6
  187. package/dist/esm/hooks/shop.js +86 -67
  188. package/dist/esm/hooks/use-current-device.js +14 -16
  189. package/dist/esm/hooks/use-lazy-video.js +7 -7
  190. package/dist/esm/hooks/useCartId.js +35 -27
  191. package/dist/esm/hooks/useCartLine.js +2 -2
  192. package/dist/esm/hooks/useCartUI.js +37 -31
  193. package/dist/esm/hooks/useCollection.js +2 -2
  194. package/dist/esm/hooks/useFetchHandle.js +6 -6
  195. package/dist/esm/hooks/useFormatMoney.js +11 -7
  196. package/dist/esm/hooks/useIsomorphicLayoutEffect.js +1 -1
  197. package/dist/esm/hooks/useLoadScript.js +22 -20
  198. package/dist/esm/hooks/useMoney.js +59 -42
  199. package/dist/esm/hooks/usePrevious.js +12 -10
  200. package/dist/esm/hooks/useProduct.js +93 -70
  201. package/dist/esm/hooks/useProductList.js +11 -11
  202. package/dist/esm/hooks/useSuspenseFetch.js +20 -17
  203. package/dist/esm/hooks/useSwatchesOptions.js +32 -30
  204. package/dist/esm/types/global-style.js +9 -2
  205. package/dist/types/index.d.ts +24 -2
  206. package/package.json +1 -1
@@ -4,20 +4,25 @@ var jsxRuntime = require('react/jsx-runtime');
4
4
  var zustand = require('zustand');
5
5
  var react = require('react');
6
6
 
7
- const CartLineContext = react.createContext(null);
8
- const createCartLineStore = (data) => zustand.createStore(() => ({
9
- ...data,
10
- }));
11
- const CartLineProvider = ({ children, line }) => {
12
- return (jsxRuntime.jsx(CartLineContext.Provider, { value: createCartLineStore({ line }), children: children }, `${line.id}-${line.quantity}`));
13
- };
14
- // export const useCartLineStore = useStore;
15
- const useCartLineStore = (selector, equalityFn) => {
16
- const store = react.useContext(CartLineContext);
17
- if (!store) {
18
- throw new Error('useCartLineStore must be used within a CartLineProvider');
19
- }
20
- return zustand.useStore(store, selector, equalityFn);
7
+ const CartLineContext = /*#__PURE__*/ react.createContext(null);
8
+ const createCartLineStore = (data)=>zustand.createStore(()=>({
9
+ ...data
10
+ }));
11
+ const CartLineProvider = ({ children , line })=>{
12
+ return /*#__PURE__*/ jsxRuntime.jsx(CartLineContext.Provider, {
13
+ value: createCartLineStore({
14
+ line
15
+ }),
16
+ children: children
17
+ }, `${line.id}-${line.quantity}`);
18
+ };
19
+ // export const useCartLineStore = useStore;
20
+ const useCartLineStore = (selector, equalityFn)=>{
21
+ const store = react.useContext(CartLineContext);
22
+ if (!store) {
23
+ throw new Error('useCartLineStore must be used within a CartLineProvider');
24
+ }
25
+ return zustand.useStore(store, selector, equalityFn);
21
26
  };
22
27
 
23
28
  exports.CartLineProvider = CartLineProvider;
@@ -4,19 +4,27 @@ var jsxRuntime = require('react/jsx-runtime');
4
4
  var react = require('react');
5
5
  var zustand = require('zustand');
6
6
 
7
- const CollectionListContext = react.createContext(null);
8
- const createCollectionProvider = (data) => zustand.createStore(() => ({
9
- ...data,
10
- }));
11
- const CollectionProvider = ({ children, collection, products, settings, styles, }) => {
12
- return (jsxRuntime.jsx(CollectionListContext.Provider, { value: createCollectionProvider({ products, collection, settings, styles }), children: children }, collection?.id));
13
- };
14
- const useCollectionStore = (selector, equalityFn) => {
15
- const store = react.useContext(CollectionListContext);
16
- if (!store) {
17
- throw new Error('useCollectionStore must be used within a useCollectionStore');
18
- }
19
- return zustand.useStore(store, selector, equalityFn);
7
+ const CollectionListContext = /*#__PURE__*/ react.createContext(null);
8
+ const createCollectionProvider = (data)=>zustand.createStore(()=>({
9
+ ...data
10
+ }));
11
+ const CollectionProvider = ({ children , collection , products , settings , styles })=>{
12
+ return /*#__PURE__*/ jsxRuntime.jsx(CollectionListContext.Provider, {
13
+ value: createCollectionProvider({
14
+ products,
15
+ collection,
16
+ settings,
17
+ styles
18
+ }),
19
+ children: children
20
+ }, collection?.id);
21
+ };
22
+ const useCollectionStore = (selector, equalityFn)=>{
23
+ const store = react.useContext(CollectionListContext);
24
+ if (!store) {
25
+ throw new Error('useCollectionStore must be used within a useCollectionStore');
26
+ }
27
+ return zustand.useStore(store, selector, equalityFn);
20
28
  };
21
29
 
22
30
  exports.CollectionListContext = CollectionListContext;
@@ -5,121 +5,142 @@ var zustand = require('zustand');
5
5
  var react = require('react');
6
6
  var flattenConnection = require('../helpers/flatten-connection.js');
7
7
 
8
- // const { Provider, useStore } = createContext<StoreApi<ProductContextProps>>();
9
- const ProductContext = react.createContext(null);
10
- const createProductStoreProvider = (data) => zustand.createStore((set, get) => ({
11
- ...data,
12
- updateProperty: (name, data) => {
13
- set((state) => {
14
- return {
15
- properties: state.properties?.map((v) => {
16
- if (v.key === name) {
17
- return { ...v, ...data };
18
- }
19
- return v;
20
- }),
21
- };
22
- });
23
- },
24
- addProperty: (data) => {
25
- const properties = get().properties;
26
- if (!properties?.some((v) => v.key === data.key)) {
27
- set((state) => ({ properties: [...(state.properties ?? []), data] }));
28
- }
29
- },
30
- removeProperty: (name) => {
31
- set((state) => ({ properties: state.properties?.filter((v) => v.key !== name) }));
32
- },
33
- setQuantity: (num) => {
34
- set({
35
- quantity: num > 0 ? num : 1,
36
- });
37
- },
38
- setProductFeaturedImage: (image) => {
39
- set({
40
- featuredImageGlobal: image,
41
- });
42
- },
43
- incrementQuantity: () => {
44
- set((state) => {
45
- const quantity = state.quantity ?? 1;
46
- return {
47
- quantity: quantity + 1,
48
- };
49
- });
50
- },
51
- decrementQuantity: () => {
52
- set((state) => {
53
- const quantity = state.quantity ?? 1;
54
- return {
55
- quantity: quantity > 2 ? quantity - 1 : 1,
56
- };
57
- });
58
- },
59
- setSelectedOption: (optionId, optionValue) => {
60
- set((state) => {
61
- if (optionId && optionValue) {
62
- return {
63
- selectedOptions: {
64
- ...state?.selectedOptions,
65
- [optionId]: optionValue,
66
- },
67
- };
68
- }
69
- return state;
70
- });
71
- },
72
- forceSelectedOption: (value) => {
73
- set((state) => {
74
- return {
75
- selectedOptions: {
76
- ...state?.selectedOptions,
77
- ...value,
78
- },
79
- };
80
- });
81
- },
82
- updateIsSubmit: (value) => {
83
- set({
84
- isSubmit: value,
85
- });
86
- },
87
- }));
88
- const ProductProvider = ({ children, product, initialVariantId, quantity = 1, }) => {
89
- const uiqueId = react.useId();
90
- const store = react.useMemo(() => {
91
- let selectedOptions = {};
92
- let featuredImageGlobal = undefined;
93
- if (product) {
94
- const variants = flattenConnection.flattenConnection(product.variants);
95
- const firstVariant = flattenConnection.flattenConnection(product.variants)[0];
96
- const initialVariant = variants.find((v) => v?.id === initialVariantId) ?? firstVariant;
97
- selectedOptions = initialVariant?.selectedOptions.reduce((acc, option) => {
98
- if (option.name) {
99
- return { ...acc, [option.name]: option.value };
100
- }
101
- return acc;
102
- }, {});
103
- featuredImageGlobal =
104
- product.medias?.edges.find((v) => v.node?.id === initialVariant?.mediaId)?.node ??
105
- product.featuredImage;
106
- }
107
- return createProductStoreProvider({
108
- product,
109
- quantity,
110
- selectedOptions,
111
- uiqueId,
112
- featuredImageGlobal,
113
- });
114
- }, [initialVariantId, product, quantity, uiqueId]);
115
- return (jsxRuntime.jsx(ProductContext.Provider, { value: store, children: jsxRuntime.jsx(jsxRuntime.Fragment, { children: children }) }));
116
- };
117
- const useProductStore = (selector, equalityFn) => {
118
- const store = react.useContext(ProductContext);
119
- if (!store) {
120
- throw new Error('Element of product must be used inside a Product');
121
- }
122
- return zustand.useStore(store, selector, equalityFn);
8
+ // const { Provider, useStore } = createContext<StoreApi<ProductContextProps>>();
9
+ const ProductContext = /*#__PURE__*/ react.createContext(null);
10
+ const createProductStoreProvider = (data)=>zustand.createStore((set, get)=>({
11
+ ...data,
12
+ updateProperty: (name, data)=>{
13
+ set((state)=>{
14
+ return {
15
+ properties: state.properties?.map((v)=>{
16
+ if (v.key === name) {
17
+ return {
18
+ ...v,
19
+ ...data
20
+ };
21
+ }
22
+ return v;
23
+ })
24
+ };
25
+ });
26
+ },
27
+ addProperty: (data)=>{
28
+ const properties = get().properties;
29
+ if (!properties?.some((v)=>v.key === data.key)) {
30
+ set((state)=>({
31
+ properties: [
32
+ ...state.properties ?? [],
33
+ data
34
+ ]
35
+ }));
36
+ }
37
+ },
38
+ removeProperty: (name)=>{
39
+ set((state)=>({
40
+ properties: state.properties?.filter((v)=>v.key !== name)
41
+ }));
42
+ },
43
+ setQuantity: (num)=>{
44
+ set({
45
+ quantity: num > 0 ? num : 1
46
+ });
47
+ },
48
+ setProductFeaturedImage: (image)=>{
49
+ set({
50
+ featuredImageGlobal: image
51
+ });
52
+ },
53
+ incrementQuantity: ()=>{
54
+ set((state)=>{
55
+ const quantity = state.quantity ?? 1;
56
+ return {
57
+ quantity: quantity + 1
58
+ };
59
+ });
60
+ },
61
+ decrementQuantity: ()=>{
62
+ set((state)=>{
63
+ const quantity = state.quantity ?? 1;
64
+ return {
65
+ quantity: quantity > 2 ? quantity - 1 : 1
66
+ };
67
+ });
68
+ },
69
+ setSelectedOption: (optionId, optionValue)=>{
70
+ set((state)=>{
71
+ if (optionId && optionValue) {
72
+ return {
73
+ selectedOptions: {
74
+ ...state?.selectedOptions,
75
+ [optionId]: optionValue
76
+ }
77
+ };
78
+ }
79
+ return state;
80
+ });
81
+ },
82
+ forceSelectedOption: (value)=>{
83
+ set((state)=>{
84
+ return {
85
+ selectedOptions: {
86
+ ...state?.selectedOptions,
87
+ ...value
88
+ }
89
+ };
90
+ });
91
+ },
92
+ updateIsSubmit: (value)=>{
93
+ set({
94
+ isSubmit: value
95
+ });
96
+ }
97
+ }));
98
+ const ProductProvider = ({ children , product , initialVariantId , quantity =1 })=>{
99
+ const uiqueId = react.useId();
100
+ const store = react.useMemo(()=>{
101
+ let selectedOptions = {};
102
+ let featuredImageGlobal = undefined;
103
+ if (product) {
104
+ const variants = flattenConnection.flattenConnection(product.variants);
105
+ const firstVariant = flattenConnection.flattenConnection(product.variants)[0];
106
+ const initialVariant = variants.find((v)=>v?.id === initialVariantId) ?? firstVariant;
107
+ selectedOptions = initialVariant?.selectedOptions.reduce((acc, option)=>{
108
+ if (option.name) {
109
+ return {
110
+ ...acc,
111
+ [option.name]: option.value
112
+ };
113
+ }
114
+ return acc;
115
+ }, {});
116
+ featuredImageGlobal = product.medias?.edges.find((v)=>v.node?.id === initialVariant?.mediaId)?.node ?? product.featuredImage;
117
+ }
118
+ return createProductStoreProvider({
119
+ product,
120
+ quantity,
121
+ selectedOptions,
122
+ uiqueId,
123
+ featuredImageGlobal
124
+ });
125
+ }, [
126
+ initialVariantId,
127
+ product,
128
+ quantity,
129
+ uiqueId
130
+ ]);
131
+ return /*#__PURE__*/ jsxRuntime.jsx(ProductContext.Provider, {
132
+ value: store,
133
+ children: /*#__PURE__*/ jsxRuntime.jsx(jsxRuntime.Fragment, {
134
+ children: children
135
+ })
136
+ });
137
+ };
138
+ const useProductStore = (selector, equalityFn)=>{
139
+ const store = react.useContext(ProductContext);
140
+ if (!store) {
141
+ throw new Error('Element of product must be used inside a Product');
142
+ }
143
+ return zustand.useStore(store, selector, equalityFn);
123
144
  };
124
145
 
125
146
  exports.ProductProvider = ProductProvider;
@@ -4,19 +4,27 @@ var jsxRuntime = require('react/jsx-runtime');
4
4
  var react = require('react');
5
5
  var zustand = require('zustand');
6
6
 
7
- const ProductListContext = react.createContext(null);
8
- const createProductListProvider = (data) => zustand.createStore(() => ({
9
- ...data,
10
- }));
11
- const ProductListProvider = ({ children, collection, products, settings, styles, }) => {
12
- return (jsxRuntime.jsx(ProductListContext.Provider, { value: createProductListProvider({ products, collection, settings, styles }), children: children }));
13
- };
14
- const useProductListStore = (selector, equalityFn) => {
15
- const store = react.useContext(ProductListContext);
16
- if (!store) {
17
- throw new Error('useProductListStore must be used within a useProductListStore');
18
- }
19
- return zustand.useStore(store, selector, equalityFn);
7
+ const ProductListContext = /*#__PURE__*/ react.createContext(null);
8
+ const createProductListProvider = (data)=>zustand.createStore(()=>({
9
+ ...data
10
+ }));
11
+ const ProductListProvider = ({ children , collection , products , settings , styles })=>{
12
+ return /*#__PURE__*/ jsxRuntime.jsx(ProductListContext.Provider, {
13
+ value: createProductListProvider({
14
+ products,
15
+ collection,
16
+ settings,
17
+ styles
18
+ }),
19
+ children: children
20
+ });
21
+ };
22
+ const useProductListStore = (selector, equalityFn)=>{
23
+ const store = react.useContext(ProductListContext);
24
+ if (!store) {
25
+ throw new Error('useProductListStore must be used within a useProductListStore');
26
+ }
27
+ return zustand.useStore(store, selector, equalityFn);
20
28
  };
21
29
 
22
30
  exports.ProductListContext = ProductListContext;
@@ -6,43 +6,47 @@ var react = require('react');
6
6
  var cloneDeep = require('../helpers/clone-deep.js');
7
7
  var normalizeBuilderData = require('../helpers/normalize-builder-data.js');
8
8
 
9
- const SectionContext = react.createContext(null);
10
- const createSectionProvider = (data) => zustand.createStore((set, get) => ({
11
- data: data ?? {},
12
- getSection: (id) => {
13
- const section = get().data[id];
14
- return section ?? undefined;
15
- },
16
- addSection: (id, data) => {
17
- const item = normalizeBuilderData.normalizeBuilderData(data);
18
- set((prev) => ({
19
- data: {
20
- ...prev.data,
21
- [id]: cloneDeep.cloneDeep(item),
22
- },
23
- }));
24
- },
25
- removeSection: (id) => {
26
- set((prev) => {
27
- const { [id]: _, ...rest } = prev.data;
28
- return {
29
- data: rest,
30
- };
31
- });
32
- },
33
- }));
34
- const SectionProvider = ({ children, data, ...passProps }) => {
35
- return (jsxRuntime.jsx(SectionContext.Provider, { ...passProps, value: createSectionProvider(data), children: children }));
36
- };
37
- // export const useSectionStore = useStore;
38
- const useSectionStore = (selector, equalityFn) => {
39
- const store = react.useContext(SectionContext);
40
- if (!store) {
41
- throw new Error('useSectionStore must be used within a SectionProvider');
42
- }
43
- return zustand.useStore(store, selector, equalityFn);
44
- };
45
- const useSection = (id) => useSectionStore((s) => s.getSection(id));
9
+ const SectionContext = /*#__PURE__*/ react.createContext(null);
10
+ const createSectionProvider = (data)=>zustand.createStore((set, get)=>({
11
+ data: data ?? {},
12
+ getSection: (id)=>{
13
+ const section = get().data[id];
14
+ return section ?? undefined;
15
+ },
16
+ addSection: (id, data)=>{
17
+ const item = normalizeBuilderData.normalizeBuilderData(data);
18
+ set((prev)=>({
19
+ data: {
20
+ ...prev.data,
21
+ [id]: cloneDeep.cloneDeep(item)
22
+ }
23
+ }));
24
+ },
25
+ removeSection: (id)=>{
26
+ set((prev)=>{
27
+ const { [id]: _ , ...rest } = prev.data;
28
+ return {
29
+ data: rest
30
+ };
31
+ });
32
+ }
33
+ }));
34
+ const SectionProvider = ({ children , data , ...passProps })=>{
35
+ return /*#__PURE__*/ jsxRuntime.jsx(SectionContext.Provider, {
36
+ ...passProps,
37
+ value: createSectionProvider(data),
38
+ children: children
39
+ });
40
+ };
41
+ // export const useSectionStore = useStore;
42
+ const useSectionStore = (selector, equalityFn)=>{
43
+ const store = react.useContext(SectionContext);
44
+ if (!store) {
45
+ throw new Error('useSectionStore must be used within a SectionProvider');
46
+ }
47
+ return zustand.useStore(store, selector, equalityFn);
48
+ };
49
+ const useSection = (id)=>useSectionStore((s)=>s.getSection(id));
46
50
 
47
51
  exports.SectionProvider = SectionProvider;
48
52
  exports.useSection = useSection;
@@ -6,37 +6,55 @@ var zustand = require('zustand');
6
6
  var react = require('react');
7
7
  var AddonContext = require('./AddonContext.js');
8
8
 
9
- const ShopContext = react.createContext(null);
10
- const createShopStoreProvider = (data) => zustand.createStore((set) => ({
11
- mobileOnly: false,
12
- ...data,
13
- changeLocale: (locale) => {
14
- set({ locale });
15
- },
16
- changeCurrency: (currency) => {
17
- set({ currency });
18
- },
19
- changeSwatches: (swatches) => {
20
- set({ swatches });
21
- },
22
- changeStorefrontInfo: ({ url, token }) => {
23
- set({
24
- storefrontUrl: url,
25
- storefrontToken: token,
26
- });
27
- },
28
- }));
29
- const ShopProvider = ({ children, addons, storeOption, queryOption, ...passProps }) => {
30
- const store = react.useMemo(() => createShopStoreProvider(storeOption), [storeOption]);
31
- return (jsxRuntime.jsx(AddonContext.AddonProvider, { components: addons, children: jsxRuntime.jsx(useSWR.SWRConfig, { value: queryOption, children: jsxRuntime.jsx(ShopContext.Provider, { ...passProps, value: store, children: children }, JSON.stringify(storeOption)) }) }));
32
- };
33
- // export const useShopStore = useStore;
34
- const useShopStore = (selector, equalityFn) => {
35
- const store = react.useContext(ShopContext);
36
- if (!store) {
37
- throw new Error('useShopStore must be used within a ShopProvider');
38
- }
39
- return zustand.useStore(store, selector, equalityFn);
9
+ const ShopContext = /*#__PURE__*/ react.createContext(null);
10
+ const createShopStoreProvider = (data)=>zustand.createStore((set)=>({
11
+ mobileOnly: false,
12
+ ...data,
13
+ changeLocale: (locale)=>{
14
+ set({
15
+ locale
16
+ });
17
+ },
18
+ changeCurrency: (currency)=>{
19
+ set({
20
+ currency
21
+ });
22
+ },
23
+ changeSwatches: (swatches)=>{
24
+ set({
25
+ swatches
26
+ });
27
+ },
28
+ changeStorefrontInfo: ({ url , token })=>{
29
+ set({
30
+ storefrontUrl: url,
31
+ storefrontToken: token
32
+ });
33
+ }
34
+ }));
35
+ const ShopProvider = ({ children , addons , storeOption , queryOption , ...passProps })=>{
36
+ const store = react.useMemo(()=>createShopStoreProvider(storeOption), [
37
+ storeOption
38
+ ]);
39
+ return /*#__PURE__*/ jsxRuntime.jsx(AddonContext.AddonProvider, {
40
+ components: addons,
41
+ children: /*#__PURE__*/ jsxRuntime.jsx(useSWR.SWRConfig, {
42
+ value: queryOption,
43
+ children: /*#__PURE__*/ jsxRuntime.jsx(ShopContext.Provider, {
44
+ ...passProps,
45
+ value: store,
46
+ children: children
47
+ }, JSON.stringify(storeOption))
48
+ })
49
+ });
50
+ };
51
+ // export const useShopStore = useStore;
52
+ const useShopStore = (selector, equalityFn)=>{
53
+ const store = react.useContext(ShopContext);
54
+ if (!store) {
55
+ throw new Error('useShopStore must be used within a ShopProvider');
56
+ }
57
+ return zustand.useStore(store, selector, equalityFn);
40
58
  };
41
59
 
42
60
  exports.ShopProvider = ShopProvider;
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- const AnalyticSelect = `
3
+ /* eslint-disable */ const AnalyticSelect = `
4
4
  fragment AnalyticSelect on Analytic {
5
5
  fbPixelID
6
6
  gaTrackingID
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- const CollectionDetailSelect = `
3
+ /* eslint-disable */ const CollectionDetailSelect = `
4
4
  fragment CollectionDetailSelect on Collection {
5
5
  id
6
6
  baseID
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- const CollectionProductSelect = `
3
+ /* eslint-disable */ const CollectionProductSelect = `
4
4
  fragment CollectionProductSelect on Collection {
5
5
  ...CollectionDetailSelect
6
6
  products(
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- const CustomCodeSelect = `
3
+ /* eslint-disable */ const CustomCodeSelect = `
4
4
  fragment CustomCodeSelect on CustomCode {
5
5
  body
6
6
  header
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- const DataSeoSelect = `
3
+ /* eslint-disable */ const DataSeoSelect = `
4
4
  fragment DataSEOSelect on DataSEO {
5
5
  id
6
6
  key
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- const MediaSelect = `
3
+ /* eslint-disable */ const MediaSelect = `
4
4
  fragment MediaSelect on Media {
5
5
  id
6
6
  contentType
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- const ProductLittleSelect = `
3
+ /* eslint-disable */ const ProductLittleSelect = `
4
4
  fragment ProductLittleSelect on Product {
5
5
  id
6
6
  title
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- const ProductOptionValueSelect = `
3
+ /* eslint-disable */ const ProductOptionValueSelect = `
4
4
  fragment ProductOptionValueSelect on ProductOptionValue {
5
5
  id
6
6
  label
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- const ProductOptionSelect = `
3
+ /* eslint-disable */ const ProductOptionSelect = `
4
4
  fragment ProductOptionSelect on ProductOption {
5
5
  id
6
6
  name
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- const ProductSelect = `
3
+ /* eslint-disable */ const ProductSelect = `
4
4
  fragment ProductSelect on Product {
5
5
  ...ProductLittleSelect
6
6
  medias(first: $firstMedia, after: $afterMedia, orderBy: $orderByMedia) {