@gem-sdk/core 1.5.17 → 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 +92 -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 +92 -69
  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
@@ -2,16 +2,18 @@
2
2
 
3
3
  var react = require('react');
4
4
 
5
- const usePrevious = (value) => {
6
- // The ref object is a generic container whose current property is mutable ...
7
- // ... and can hold any value, similar to an instance property on a class
8
- const ref = react.useRef();
9
- // Store current value in ref
10
- react.useEffect(() => {
11
- ref.current = value;
12
- }, [value]); // Only re-run if value changes
13
- // Return previous value (happens before update in useEffect above)
14
- return ref.current;
5
+ const usePrevious = (value)=>{
6
+ // The ref object is a generic container whose current property is mutable ...
7
+ // ... and can hold any value, similar to an instance property on a class
8
+ const ref = react.useRef();
9
+ // Store current value in ref
10
+ react.useEffect(()=>{
11
+ ref.current = value;
12
+ }, [
13
+ value
14
+ ]); // Only re-run if value changes
15
+ // Return previous value (happens before update in useEffect above)
16
+ return ref.current;
15
17
  };
16
18
 
17
19
  exports.usePrevious = usePrevious;
@@ -7,75 +7,98 @@ require('swr');
7
7
  var product = require('../helpers/product.js');
8
8
  require('../helpers/convert.js');
9
9
 
10
- const useUniqProductID = () => {
11
- return ProductContext.useProductStore((s) => s.uiqueId);
12
- };
13
- const useProduct = () => {
14
- return ProductContext.useProductStore((s) => s.product);
15
- };
16
- const useFeaturedImageGlobal = () => {
17
- return ProductContext.useProductStore((s) => s.featuredImageGlobal);
18
- };
19
- const useProductProperties = () => {
20
- return ProductContext.useProductStore((s) => s.properties);
21
- };
22
- const useQuantity = () => {
23
- const quantity = ProductContext.useProductStore((s) => s.quantity);
24
- const decrement = ProductContext.useProductStore((s) => s.decrementQuantity);
25
- const increment = ProductContext.useProductStore((s) => s.incrementQuantity);
26
- const updateQuantity = ProductContext.useProductStore((s) => s.setQuantity);
27
- const reset = react.useCallback(() => {
28
- updateQuantity(1);
29
- }, [updateQuantity]);
30
- return react.useMemo(() => ({ quantity, increment, decrement, reset, setQuantity: updateQuantity }), [decrement, increment, quantity, reset, updateQuantity]);
31
- };
32
- const useSelectedOption = () => {
33
- const setSelectedOption = ProductContext.useProductStore((s) => s.setSelectedOption);
34
- const selectedOptions = ProductContext.useProductStore((s) => s.selectedOptions);
35
- const forceSelectedOption = ProductContext.useProductStore((s) => s.forceSelectedOption);
36
- const updateOption = react.useCallback((optionId, optionValue) => {
37
- setSelectedOption(optionId, optionValue);
38
- }, [setSelectedOption]);
39
- return react.useMemo(() => ({
40
- selectedOptions,
41
- setSelectedOption: updateOption,
42
- forceSelectedOption,
43
- }), [selectedOptions, updateOption, forceSelectedOption]);
44
- };
45
- const useVariants = () => {
46
- const variants = ProductContext.useProductStore((s) => s.product?.variants);
47
- return flattenConnection.flattenConnection(variants);
48
- };
49
- const useVariant = (id) => {
50
- const variants = useVariants();
51
- return react.useMemo(() => variants?.find((v) => v?.id === id), [id, variants]);
52
- };
53
- const useCurrentVariant = () => {
54
- const { selectedOptions } = useSelectedOption();
55
- const variants = useVariants();
56
- return react.useMemo(() => product.getSelectedVariant(variants, selectedOptions), [selectedOptions, variants]);
57
- };
58
- function checkInStock(variant) {
59
- if (!variant)
60
- return false;
61
- return ((variant?.inventoryQuantity && variant.inventoryQuantity > 0) ||
62
- !variant?.manageInventory ||
63
- variant.inventoryPolicy === 'continue');
64
- }
65
- const useCurrentVariantInStock = () => {
66
- const currentVariant = useCurrentVariant();
67
- const isInStock = checkInStock(currentVariant);
68
- return isInStock;
69
- };
70
- const useVariantOutStock = (optionId, optionValue) => {
71
- const { selectedOptions } = useSelectedOption();
72
- const variants = useVariants();
73
- const matchedVariant = product.getSelectedVariant(variants, {
74
- ...selectedOptions,
75
- [optionId]: optionValue,
76
- });
77
- const isInStock = checkInStock(matchedVariant);
78
- return !isInStock;
10
+ const useUniqProductID = ()=>{
11
+ return ProductContext.useProductStore((s)=>s.uiqueId);
12
+ };
13
+ const useProduct = ()=>{
14
+ return ProductContext.useProductStore((s)=>s.product);
15
+ };
16
+ const useFeaturedImageGlobal = ()=>{
17
+ return ProductContext.useProductStore((s)=>s.featuredImageGlobal);
18
+ };
19
+ const useProductProperties = ()=>{
20
+ return ProductContext.useProductStore((s)=>s.properties);
21
+ };
22
+ const useQuantity = ()=>{
23
+ const quantity = ProductContext.useProductStore((s)=>s.quantity);
24
+ const decrement = ProductContext.useProductStore((s)=>s.decrementQuantity);
25
+ const increment = ProductContext.useProductStore((s)=>s.incrementQuantity);
26
+ const updateQuantity = ProductContext.useProductStore((s)=>s.setQuantity);
27
+ const reset = react.useCallback(()=>{
28
+ updateQuantity(1);
29
+ }, [
30
+ updateQuantity
31
+ ]);
32
+ return react.useMemo(()=>({
33
+ quantity,
34
+ increment,
35
+ decrement,
36
+ reset,
37
+ setQuantity: updateQuantity
38
+ }), [
39
+ decrement,
40
+ increment,
41
+ quantity,
42
+ reset,
43
+ updateQuantity
44
+ ]);
45
+ };
46
+ const useSelectedOption = ()=>{
47
+ const setSelectedOption = ProductContext.useProductStore((s)=>s.setSelectedOption);
48
+ const selectedOptions = ProductContext.useProductStore((s)=>s.selectedOptions);
49
+ const forceSelectedOption = ProductContext.useProductStore((s)=>s.forceSelectedOption);
50
+ const updateOption = react.useCallback((optionId, optionValue)=>{
51
+ setSelectedOption(optionId, optionValue);
52
+ }, [
53
+ setSelectedOption
54
+ ]);
55
+ return react.useMemo(()=>({
56
+ selectedOptions,
57
+ setSelectedOption: updateOption,
58
+ forceSelectedOption
59
+ }), [
60
+ selectedOptions,
61
+ updateOption,
62
+ forceSelectedOption
63
+ ]);
64
+ };
65
+ const useVariants = ()=>{
66
+ const variants = ProductContext.useProductStore((s)=>s.product?.variants);
67
+ return flattenConnection.flattenConnection(variants);
68
+ };
69
+ const useVariant = (id)=>{
70
+ const variants = useVariants();
71
+ return react.useMemo(()=>variants?.find((v)=>v?.id === id), [
72
+ id,
73
+ variants
74
+ ]);
75
+ };
76
+ const useCurrentVariant = ()=>{
77
+ const { selectedOptions } = useSelectedOption();
78
+ const variants = useVariants();
79
+ return react.useMemo(()=>product.getSelectedVariant(variants, selectedOptions), [
80
+ selectedOptions,
81
+ variants
82
+ ]);
83
+ };
84
+ function checkInStock(variant) {
85
+ if (!variant) return false;
86
+ return variant?.inventoryQuantity && variant.inventoryQuantity > 0 || !variant?.manageInventory || variant.inventoryPolicy === 'continue';
87
+ }
88
+ const useCurrentVariantInStock = ()=>{
89
+ const currentVariant = useCurrentVariant();
90
+ const isInStock = checkInStock(currentVariant);
91
+ return isInStock;
92
+ };
93
+ const useVariantOutStock = (optionId, optionValue)=>{
94
+ const { selectedOptions } = useSelectedOption();
95
+ const variants = useVariants();
96
+ const matchedVariant = product.getSelectedVariant(variants, {
97
+ ...selectedOptions,
98
+ [optionId]: optionValue
99
+ });
100
+ const isInStock = checkInStock(matchedVariant);
101
+ return !isInStock;
79
102
  };
80
103
 
81
104
  exports.checkInStock = checkInStock;
@@ -2,17 +2,17 @@
2
2
 
3
3
  var ProductListContext = require('../contexts/ProductListContext.js');
4
4
 
5
- const useProductList = () => {
6
- return ProductListContext.useProductListStore((s) => s.collection);
7
- };
8
- const useProductListProducts = () => {
9
- return ProductListContext.useProductListStore((s) => s.products);
10
- };
11
- const useProductListSettings = () => {
12
- return ProductListContext.useProductListStore((s) => s.settings);
13
- };
14
- const useProductListStyles = () => {
15
- return ProductListContext.useProductListStore((s) => s.styles);
5
+ const useProductList = ()=>{
6
+ return ProductListContext.useProductListStore((s)=>s.collection);
7
+ };
8
+ const useProductListProducts = ()=>{
9
+ return ProductListContext.useProductListStore((s)=>s.products);
10
+ };
11
+ const useProductListSettings = ()=>{
12
+ return ProductListContext.useProductListStore((s)=>s.settings);
13
+ };
14
+ const useProductListStyles = ()=>{
15
+ return ProductListContext.useProductListStore((s)=>s.styles);
16
16
  };
17
17
 
18
18
  exports.useProductList = useProductList;
@@ -2,23 +2,26 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- const cache = new Map();
6
- const useSuspenseFetch = (key, promise) => {
7
- const value = cache.get(key) || { status: 'new', data: null };
8
- if (value.status === 'resolved') {
9
- return { data: value.data };
10
- }
11
- promise()
12
- .then((data) => {
13
- value.status = 'resolved';
14
- value.data = data;
15
- cache.set(key, value);
16
- })
17
- .catch(() => {
18
- value.status = 'error';
19
- value.data = null;
20
- });
21
- throw promise();
5
+ const cache = new Map();
6
+ const useSuspenseFetch = (key, promise)=>{
7
+ const value = cache.get(key) || {
8
+ status: 'new',
9
+ data: null
10
+ };
11
+ if (value.status === 'resolved') {
12
+ return {
13
+ data: value.data
14
+ };
15
+ }
16
+ promise().then((data)=>{
17
+ value.status = 'resolved';
18
+ value.data = data;
19
+ cache.set(key, value);
20
+ }).catch(()=>{
21
+ value.status = 'error';
22
+ value.data = null;
23
+ });
24
+ throw promise();
22
25
  };
23
26
 
24
27
  exports.default = useSuspenseFetch;
@@ -4,36 +4,38 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var shop = require('./shop.js');
6
6
 
7
- const initialSwatchOptionValue = {
8
- label: '',
9
- colors: [],
10
- imageUrl: '',
11
- };
12
- const initialGlobalSwatchesData = {
13
- optionTitle: '',
14
- optionType: '',
15
- optionValues: [],
16
- };
17
- const useSwatchesOptions = (options) => {
18
- const { swatches } = shop.useSwatches();
19
- if (!options)
20
- return [];
21
- return options?.map((option) => {
22
- const swatchOption = swatches?.find((sw) => sw?.optionTitle === option?.name) || { ...initialGlobalSwatchesData };
23
- return {
24
- ...option,
25
- optionType: swatchOption ? swatchOption.optionType : '',
26
- values: option.values?.map((val) => {
27
- const swatchValue = (swatchOption &&
28
- swatchOption?.optionValues?.find((swatOp) => swatOp?.label === val?.label)) || { ...initialSwatchOptionValue };
29
- return {
30
- ...val,
31
- colors: swatchValue?.colors || [],
32
- imageUrl: swatchValue?.imageUrl || '',
33
- };
34
- }),
35
- };
36
- });
7
+ const initialSwatchOptionValue = {
8
+ label: '',
9
+ colors: [],
10
+ imageUrl: ''
11
+ };
12
+ const initialGlobalSwatchesData = {
13
+ optionTitle: '',
14
+ optionType: '',
15
+ optionValues: []
16
+ };
17
+ const useSwatchesOptions = (options)=>{
18
+ const { swatches } = shop.useSwatches();
19
+ if (!options) return [];
20
+ return options?.map((option)=>{
21
+ const swatchOption = swatches?.find((sw)=>sw?.optionTitle === option?.name) || {
22
+ ...initialGlobalSwatchesData
23
+ };
24
+ return {
25
+ ...option,
26
+ optionType: swatchOption ? swatchOption.optionType : '',
27
+ values: option.values?.map((val)=>{
28
+ const swatchValue = swatchOption && swatchOption?.optionValues?.find((swatOp)=>swatOp?.label === val?.label) || {
29
+ ...initialSwatchOptionValue
30
+ };
31
+ return {
32
+ ...val,
33
+ colors: swatchValue?.colors || [],
34
+ imageUrl: swatchValue?.imageUrl || ''
35
+ };
36
+ })
37
+ };
38
+ });
37
39
  };
38
40
 
39
41
  exports.default = useSwatchesOptions;
@@ -1,7 +1,14 @@
1
1
  'use strict';
2
2
 
3
- const OptionNormalStyle = ['radio_buttons', 'dropdown'];
4
- const OptionSpecialStyle = ['color', 'image', 'rectangle_list'];
3
+ const OptionNormalStyle = [
4
+ 'radio_buttons',
5
+ 'dropdown'
6
+ ];
7
+ const OptionSpecialStyle = [
8
+ 'color',
9
+ 'image',
10
+ 'rectangle_list'
11
+ ];
5
12
 
6
13
  exports.OptionNormalStyle = OptionNormalStyle;
7
14
  exports.OptionSpecialStyle = OptionSpecialStyle;
@@ -2,13 +2,13 @@ import { jsx } from 'react/jsx-runtime';
2
2
  import { useAddon } from '../contexts/AddonContext.js';
3
3
  import { usePluginEnable } from '../hooks/shop.js';
4
4
 
5
- const AddOn = ({ name }) => {
6
- const Comp = useAddon(name);
7
- const plugins = usePluginEnable();
8
- if (!plugins?.includes(name)) {
9
- return null;
10
- }
11
- return jsx(Comp, {});
5
+ const AddOn = ({ name })=>{
6
+ const Comp = useAddon(name);
7
+ const plugins = usePluginEnable();
8
+ if (!plugins?.includes(name)) {
9
+ return null;
10
+ }
11
+ return /*#__PURE__*/ jsx(Comp, {});
12
12
  };
13
13
 
14
14
  export { AddOn as default };
@@ -3,14 +3,20 @@ import { isValidElement } from 'react';
3
3
  import { composeAdvanceStyle } from '../helpers/compose-advance-style.js';
4
4
  import { disableWrap } from './constant.js';
5
5
 
6
- const ComponentWrapper = ({ children, ...props }) => {
7
- if (props.type === 'section')
8
- return null;
9
- const style = composeAdvanceStyle(props.advanced, props.tag);
10
- if (disableWrap.includes(props.tag) && isValidElement(children)) {
11
- return jsx(children.type, { ...children.props, ...{ style } });
12
- }
13
- return (jsx("div", { style: style, className: `${props.uid}`, children: children }));
6
+ const ComponentWrapper = ({ children , ...props })=>{
7
+ if (props.type === 'section') return null;
8
+ const style = composeAdvanceStyle(props.advanced, props.tag);
9
+ if (disableWrap.includes(props.tag) && /*#__PURE__*/ isValidElement(children)) {
10
+ return /*#__PURE__*/ jsx(children.type, {
11
+ ...children.props,
12
+ style
13
+ });
14
+ }
15
+ return /*#__PURE__*/ jsx("div", {
16
+ style: style,
17
+ className: `${props.uid}`,
18
+ children: children
19
+ });
14
20
  };
15
21
 
16
22
  export { ComponentWrapper as default };
@@ -3,52 +3,61 @@ import { isValidElement } from 'react';
3
3
  import { composeAdvanceStyle } from '../helpers/compose-advance-style.js';
4
4
  import { disableWrap } from './constant.js';
5
5
 
6
- const ComponentWrapperPreview = ({ children, ...props }) => {
7
- if (props.type === 'section') {
8
- return null;
9
- }
10
- const customProps = {};
11
- // Build editor configs
12
- if (props.editorConfigs) {
13
- const editorConfigs = props.editorConfigs;
14
- if (editorConfigs.placeholder?.notAppendBeforeAfter) {
15
- customProps['data-placeholder-not-append-before-after'] = true;
16
- }
17
- if (editorConfigs.toolbar?.parent) {
18
- customProps['data-toolbar-parent'] = true;
19
- }
20
- if (editorConfigs.component?.noDelete) {
21
- customProps['data-component-no-delete'] = true;
22
- }
23
- if (editorConfigs.component?.noDuplicate) {
24
- customProps['data-component-no-duplicate'] = true;
25
- }
26
- if (editorConfigs.component?.noDragDrop) {
27
- customProps['data-component-no-drag-drop'] = true;
28
- }
29
- if (editorConfigs.component?.noSetting) {
30
- customProps['data-component-no-setting'] = true;
31
- }
32
- if (editorConfigs.toolbar?.hide) {
33
- customProps['data-toolbar-hide'] = true;
34
- }
35
- if (editorConfigs.slots?.children) {
36
- customProps['data-slots-children'] = true;
37
- }
38
- }
39
- const style = composeAdvanceStyle(props.advanced, props.tag);
40
- const builderAttrs = {
41
- ...customProps,
42
- 'data-uid': props.uid,
43
- 'data-component-type': 'component',
44
- 'data-component-tag': props.tag,
45
- 'data-component-label': props.label,
46
- };
47
- if (disableWrap.includes(props.tag) && isValidElement(children)) {
48
- return jsx(children.type, { ...children.props, ...{ style, builderAttrs } });
49
- }
50
- // Render
51
- return (jsx("div", { style: style, className: `${props.uid}`, ...builderAttrs, children: children }));
6
+ const ComponentWrapperPreview = ({ children , ...props })=>{
7
+ if (props.type === 'section') {
8
+ return null;
9
+ }
10
+ const customProps = {};
11
+ // Build editor configs
12
+ if (props.editorConfigs) {
13
+ const editorConfigs = props.editorConfigs;
14
+ if (editorConfigs.placeholder?.notAppendBeforeAfter) {
15
+ customProps['data-placeholder-not-append-before-after'] = true;
16
+ }
17
+ if (editorConfigs.toolbar?.parent) {
18
+ customProps['data-toolbar-parent'] = true;
19
+ }
20
+ if (editorConfigs.component?.noDelete) {
21
+ customProps['data-component-no-delete'] = true;
22
+ }
23
+ if (editorConfigs.component?.noDuplicate) {
24
+ customProps['data-component-no-duplicate'] = true;
25
+ }
26
+ if (editorConfigs.component?.noDragDrop) {
27
+ customProps['data-component-no-drag-drop'] = true;
28
+ }
29
+ if (editorConfigs.component?.noSetting) {
30
+ customProps['data-component-no-setting'] = true;
31
+ }
32
+ if (editorConfigs.toolbar?.hide) {
33
+ customProps['data-toolbar-hide'] = true;
34
+ }
35
+ if (editorConfigs.slots?.children) {
36
+ customProps['data-slots-children'] = true;
37
+ }
38
+ }
39
+ const style = composeAdvanceStyle(props.advanced, props.tag);
40
+ const builderAttrs = {
41
+ ...customProps,
42
+ 'data-uid': props.uid,
43
+ 'data-component-type': 'component',
44
+ 'data-component-tag': props.tag,
45
+ 'data-component-label': props.label
46
+ };
47
+ if (disableWrap.includes(props.tag) && /*#__PURE__*/ isValidElement(children)) {
48
+ return /*#__PURE__*/ jsx(children.type, {
49
+ ...children.props,
50
+ style,
51
+ builderAttrs
52
+ });
53
+ }
54
+ // Render
55
+ return /*#__PURE__*/ jsx("div", {
56
+ style: style,
57
+ className: `${props.uid}`,
58
+ ...builderAttrs,
59
+ children: children
60
+ });
52
61
  };
53
62
 
54
63
  export { ComponentWrapperPreview as default };
@@ -1,3 +1,3 @@
1
- const Empty = () => null;
1
+ const Empty = ()=>null;
2
2
 
3
3
  export { Empty as default };
@@ -6,19 +6,56 @@ import { useBuilderStore } from '../contexts/BuilderContext.js';
6
6
  import ComponentWrapper from './ComponentWrapper.js';
7
7
  import RenderSectionMemo from './RenderSection.js';
8
8
 
9
- const Render = ({ uid, ...passProps }) => {
10
- const item = useBuilderStore((s) => s.getItem(uid));
11
- const Component = useBuilderComponent(item?.tag);
12
- if (!item)
13
- return null;
14
- if (item?.type === 'section') {
15
- return jsx(RenderSectionMemo, { sectionId: item.uid });
16
- }
17
- else {
18
- return (jsx(ErrorBoundary, { fallbackRender: ({ error, resetErrorBoundary }) => (jsxs(Fragment, { children: [jsx("span", { "aria-label": "Error message", children: error.message }), jsx("button", { type: "button", onClick: resetErrorBoundary, children: "Try again" })] })), children: jsx(ComponentWrapper, { ...item, children: item?.childrens?.length ? (jsx(Component, { builderProps: { uid, builderData: item }, styles: item.styles, setting: item.settings, ...passProps, children: item.childrens.map((id) => (jsx(RenderMemo, { uid: id }, id))) })) : (jsx(Component, { builderProps: { uid, builderData: item }, styles: item.styles, setting: item.settings, ...passProps })) }) }, item.uid));
19
- }
20
- };
21
- const RenderMemo = memo(Render);
9
+ const Render = ({ uid , ...passProps })=>{
10
+ const item = useBuilderStore((s)=>s.getItem(uid));
11
+ const Component = useBuilderComponent(item?.tag);
12
+ if (!item) return null;
13
+ if (item?.type === 'section') {
14
+ return /*#__PURE__*/ jsx(RenderSectionMemo, {
15
+ sectionId: item.uid
16
+ });
17
+ } else {
18
+ return /*#__PURE__*/ jsx(ErrorBoundary, {
19
+ fallbackRender: ({ error , resetErrorBoundary })=>/*#__PURE__*/ jsxs(Fragment, {
20
+ children: [
21
+ /*#__PURE__*/ jsx("span", {
22
+ "aria-label": "Error message",
23
+ children: error.message
24
+ }),
25
+ /*#__PURE__*/ jsx("button", {
26
+ type: "button",
27
+ onClick: resetErrorBoundary,
28
+ children: "Try again"
29
+ })
30
+ ]
31
+ }),
32
+ children: /*#__PURE__*/ jsx(ComponentWrapper, {
33
+ ...item,
34
+ children: item?.childrens?.length ? /*#__PURE__*/ jsx(Component, {
35
+ builderProps: {
36
+ uid,
37
+ builderData: item
38
+ },
39
+ styles: item.styles,
40
+ setting: item.settings,
41
+ ...passProps,
42
+ children: item.childrens.map((id)=>/*#__PURE__*/ jsx(RenderMemo, {
43
+ uid: id
44
+ }, id))
45
+ }) : /*#__PURE__*/ jsx(Component, {
46
+ builderProps: {
47
+ uid,
48
+ builderData: item
49
+ },
50
+ styles: item.styles,
51
+ setting: item.settings,
52
+ ...passProps
53
+ })
54
+ })
55
+ }, item.uid);
56
+ }
57
+ };
58
+ const RenderMemo = /*#__PURE__*/ memo(Render);
22
59
  RenderMemo.displayName = 'RenderMemo';
23
60
 
24
61
  export { RenderMemo as default };