@gem-sdk/core 1.23.0 → 1.23.1

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 (50) hide show
  1. package/dist/cjs/components/ComponentToolbarPreview.js +443 -0
  2. package/dist/cjs/components/ComponentWrapper.js +25 -8
  3. package/dist/cjs/components/ComponentWrapperPreview.js +37 -4
  4. package/dist/cjs/components/Render.liquid.js +8 -0
  5. package/dist/cjs/components/RenderCustomCode.js +2 -0
  6. package/dist/cjs/components/resize/Resize.js +16 -0
  7. package/dist/cjs/components/resize/Spacing.js +132 -0
  8. package/dist/cjs/components/src/product/helpers/variant-presets.js +56 -0
  9. package/dist/cjs/components/theme-section/CreateThemeSection.js +117 -0
  10. package/dist/cjs/components/theme-section/ThemeSectionStatus.js +36 -0
  11. package/dist/cjs/components/theme-section/ThemeSectionTooltip.js +102 -0
  12. package/dist/cjs/components/toolbar/Tooltip.js +22 -0
  13. package/dist/cjs/contexts/BuilderPreviewContext.js +36 -4
  14. package/dist/cjs/contexts/ShopContext.js +10 -0
  15. package/dist/cjs/graphql/queries/product-value-label.generated.js +11 -0
  16. package/dist/cjs/helpers/background.js +64 -5
  17. package/dist/cjs/helpers/filter-toolbar-preview.js +14 -0
  18. package/dist/cjs/helpers/is-empty-children.js +4 -1
  19. package/dist/cjs/helpers/make-style.js +8 -0
  20. package/dist/cjs/helpers/size.js +54 -0
  21. package/dist/cjs/helpers/typography.js +10 -9
  22. package/dist/cjs/hooks/useInitialSwatchesOptions.js +113 -0
  23. package/dist/cjs/hooks/useProduct.js +10 -3
  24. package/dist/cjs/index.js +10 -0
  25. package/dist/esm/components/ComponentToolbarPreview.js +441 -0
  26. package/dist/esm/components/ComponentWrapper.js +26 -9
  27. package/dist/esm/components/ComponentWrapperPreview.js +38 -5
  28. package/dist/esm/components/Render.liquid.js +8 -0
  29. package/dist/esm/components/RenderCustomCode.js +2 -0
  30. package/dist/esm/components/resize/Resize.js +12 -0
  31. package/dist/esm/components/resize/Spacing.js +128 -0
  32. package/dist/esm/components/src/product/helpers/variant-presets.js +54 -0
  33. package/dist/esm/components/theme-section/CreateThemeSection.js +115 -0
  34. package/dist/esm/components/theme-section/ThemeSectionStatus.js +34 -0
  35. package/dist/esm/components/theme-section/ThemeSectionTooltip.js +100 -0
  36. package/dist/esm/components/toolbar/Tooltip.js +18 -0
  37. package/dist/esm/contexts/BuilderPreviewContext.js +36 -4
  38. package/dist/esm/contexts/ShopContext.js +10 -0
  39. package/dist/esm/graphql/queries/product-value-label.generated.js +9 -0
  40. package/dist/esm/helpers/background.js +64 -6
  41. package/dist/esm/helpers/filter-toolbar-preview.js +9 -0
  42. package/dist/esm/helpers/is-empty-children.js +4 -1
  43. package/dist/esm/helpers/make-style.js +8 -1
  44. package/dist/esm/helpers/size.js +51 -1
  45. package/dist/esm/helpers/typography.js +10 -9
  46. package/dist/esm/hooks/useInitialSwatchesOptions.js +109 -0
  47. package/dist/esm/hooks/useProduct.js +10 -3
  48. package/dist/esm/index.js +5 -3
  49. package/dist/types/index.d.ts +96 -10
  50. package/package.json +2 -2
@@ -3,9 +3,12 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var react = require('react');
6
+ var ComponentToolbarPreview = require('../components/ComponentToolbarPreview.js');
6
7
 
7
8
  const isEmptyChildren = (children)=>{
8
- return react.Children.count(children) < 1 || !children;
9
+ let arrChild = react.Children.toArray(children);
10
+ arrChild = arrChild.filter((child)=>child?.type != ComponentToolbarPreview.ComponentToolbarPreview);
11
+ return react.Children.count(arrChild) < 1 || !children;
9
12
  };
10
13
 
11
14
  exports.default = isEmptyChildren;
@@ -75,6 +75,13 @@ const makeWidth = (widthValue, fullWidthValue)=>{
75
75
  mobile: getVal('mobile', widthValue, fullWidthValue)
76
76
  };
77
77
  };
78
+ const makeGlobalSizeWidthResponsive = (globalSize)=>{
79
+ return {
80
+ '--w': globalSize?.desktop?.width,
81
+ '--w-tablet': globalSize?.tablet?.width,
82
+ '--w-mobile': globalSize?.mobile?.width
83
+ };
84
+ };
78
85
  const makeHeight = (heighValue, autoHeight)=>{
79
86
  const getVal = (deviceValue, heighValue, autoHeight)=>{
80
87
  const heightVal = heighValue?.[deviceValue];
@@ -128,6 +135,7 @@ const makeLineClamp = (lineClampValue, hasLineClampValue)=>{
128
135
  };
129
136
 
130
137
  exports.makeAspectRatio = makeAspectRatio;
138
+ exports.makeGlobalSizeWidthResponsive = makeGlobalSizeWidthResponsive;
131
139
  exports.makeHeight = makeHeight;
132
140
  exports.makeLineClamp = makeLineClamp;
133
141
  exports.makeStyle = makeStyle;
@@ -1,5 +1,6 @@
1
1
  'use strict';
2
2
 
3
+ var makeStyle = require('./make-style.js');
3
4
  var constant = require('./constant.js');
4
5
 
5
6
  function getCustomSizeCSSByDevice(size, device) {
@@ -29,7 +30,60 @@ const composeSizeCss = (spacing)=>{
29
30
  ${sizeVerti ? `padding-top: ${sizeVerti}; padding-bottom: ${sizeVerti};` : undefined}
30
31
  `;
31
32
  };
33
+ const makeGlobalSize = (globalSize)=>{
34
+ return {
35
+ width: makeStyleWithDefault('w', getWidthHeightGlobalSize('width', globalSize), {
36
+ desktop: '--g-ct-w',
37
+ tablet: '--g-ct-w',
38
+ mobile: '--g-ct-w'
39
+ }),
40
+ height: makeStyle.makeStyleResponsive('h', getWidthHeightGlobalSize('height', globalSize)),
41
+ padding: getPaddingGlobalSize(globalSize)
42
+ };
43
+ };
44
+ const makeStyleWithDefault = (name, value, defaultVal)=>{
45
+ return {
46
+ [`--${name}`]: value?.desktop === 'default' ? `var(${defaultVal?.desktop})` : value?.desktop,
47
+ [`--${name}-tablet`]: value?.tablet === 'default' ? `var(${defaultVal?.tablet})` : value?.tablet,
48
+ [`--${name}-mobile`]: value?.mobile === 'default' ? `var(${defaultVal?.mobile})` : value?.mobile
49
+ };
50
+ };
51
+ const getWidthHeightGlobalSize = (type, globalSize)=>{
52
+ if (!globalSize) return {};
53
+ const data = {
54
+ desktop: globalSize?.desktop?.[type],
55
+ tablet: globalSize?.tablet?.[type],
56
+ mobile: globalSize?.mobile?.[type]
57
+ };
58
+ if (data.desktop === undefined) {
59
+ data.desktop = 'auto';
60
+ }
61
+ if (data.tablet === undefined) {
62
+ data.tablet = data.desktop;
63
+ }
64
+ if (data.mobile === undefined) {
65
+ data.mobile = data.tablet;
66
+ }
67
+ return data;
68
+ };
69
+ function getCustomPaddingSizeCSSByDevice(globalSize, device) {
70
+ if (!globalSize || !device) return {};
71
+ const suffix = constant.devicesMapping[device] ?? '';
72
+ return {
73
+ [`--pl${suffix}`]: globalSize?.[device]?.padding?.left,
74
+ [`--pr${suffix}`]: globalSize?.[device]?.padding?.right,
75
+ [`--pt${suffix}`]: globalSize?.[device]?.padding?.top,
76
+ [`--pb${suffix}`]: globalSize?.[device]?.padding?.bottom
77
+ };
78
+ }
79
+ const getPaddingGlobalSize = (globalSize)=>{
80
+ return Object.assign({}, getCustomPaddingSizeCSSByDevice(globalSize, 'desktop'), getCustomPaddingSizeCSSByDevice(globalSize, 'tablet'), getCustomPaddingSizeCSSByDevice(globalSize, 'mobile'));
81
+ };
32
82
 
33
83
  exports.composeSize = composeSize;
34
84
  exports.composeSizeCss = composeSizeCss;
35
85
  exports.genSizeClass = genSizeClass;
86
+ exports.getPaddingGlobalSize = getPaddingGlobalSize;
87
+ exports.getWidthHeightGlobalSize = getWidthHeightGlobalSize;
88
+ exports.makeGlobalSize = makeGlobalSize;
89
+ exports.makeStyleWithDefault = makeStyleWithDefault;
@@ -18,20 +18,21 @@ const composeTypographyCss = (typography)=>{
18
18
  ${lineHeight ? `line-height: ${lineHeight};` : ''}
19
19
  `;
20
20
  };
21
- const composeTypographyV2Css = (typography)=>{
21
+ const composeTypographyV2Css = (typography, isImportant)=>{
22
22
  const typographyCustom = typography?.custom;
23
23
  const { fontFamily, fontSize, fontWeight, lineHeight, letterSpacing } = typographyCustom ?? {};
24
24
  const typographyAttrs = typography?.attrs;
25
25
  const { bold, italic, underline, transform } = typographyAttrs ?? {};
26
+ const composeImportant = isImportant ? '!important' : '';
26
27
  return `
27
- ${fontFamily ? `font-family: var(--g-font-${fontFamily}, ${fontFamily});` : ''}
28
- ${fontSize?.desktop ? `font-size: ${fontSize?.desktop};` : ''}
29
- ${bold ? `font-weight: bold;` : fontWeight ? `font-weight: ${fontWeight};` : ''}
30
- ${letterSpacing ? `letter-spacing: ${letterSpacing};` : ''}
31
- ${lineHeight ? `line-height: ${lineHeight};` : ''}
32
- ${italic ? `font-style: italic;` : ''}
33
- ${underline ? `text-decoration-line: underline;` : ''}
34
- ${transform ? `text-transform: ${transform};` : ''}
28
+ ${fontFamily ? `font-family: var(--g-font-${fontFamily}, ${fontFamily}) ${composeImportant};` : ''}
29
+ ${fontSize?.desktop ? `font-size: ${fontSize?.desktop} ${composeImportant};` : ''}
30
+ ${bold ? `font-weight: bold;` : fontWeight ? `font-weight: ${fontWeight} ${composeImportant};` : ''}
31
+ ${letterSpacing ? `letter-spacing: ${letterSpacing} ${composeImportant};` : ''}
32
+ ${lineHeight ? `line-height: ${lineHeight} ${composeImportant};` : ''}
33
+ ${italic ? `font-style: italic${composeImportant};` : ''}
34
+ ${underline ? `text-decoration-line: underline ${composeImportant};` : ''}
35
+ ${transform ? `text-transform: ${transform} ${composeImportant};` : ''}
35
36
  `;
36
37
  };
37
38
  function getCustomCSSByDevice(typography, device) {
@@ -0,0 +1,113 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var useSWR = require('swr');
6
+ var productValueLabel_generated = require('../graphql/queries/product-value-label.generated.js');
7
+ var variantPresets = require('../components/src/product/helpers/variant-presets.js');
8
+ var shop = require('./shop.js');
9
+ var useFetchHandle = require('./useFetchHandle.js');
10
+ var ShopContext = require('../contexts/ShopContext.js');
11
+
12
+ let swatchChange = false;
13
+ let colorChange = false;
14
+ const useInitialSwatchesOptions = (options)=>{
15
+ const fetcher = useFetchHandle.useFetchHandle();
16
+ const changeSwatches = ShopContext.useShopStore((s)=>s.changeSwatches);
17
+ const { swatches } = shop.useSwatches();
18
+ const { data: productOptionName } = useSWR([
19
+ '/query/productOptionName',
20
+ {}
21
+ ], async ()=>fetchProductValueLabel(fetcher), {
22
+ revalidateOnMount: true
23
+ });
24
+ const swatchesTitleList = [];
25
+ swatches?.forEach((el)=>{
26
+ swatchesTitleList.push(el.optionTitle);
27
+ });
28
+ productOptionName?.productOptionName?.forEach((el)=>{
29
+ if (!swatchesTitleList.includes(el)) {
30
+ swatchChange = true;
31
+ swatches?.push({
32
+ optionTitle: el,
33
+ optionType: 'rectangle_list',
34
+ optionValues: []
35
+ });
36
+ }
37
+ });
38
+ if (!options) return [];
39
+ setDefaultSwatches(swatches, options);
40
+ if (swatches?.length && (swatchChange || colorChange)) {
41
+ window?.parent?.postMessage?.(JSON.stringify({
42
+ type: 'update-swatches',
43
+ swatches
44
+ }), '*');
45
+ changeSwatches(swatches);
46
+ }
47
+ };
48
+ const getColorDefault = (label, color)=>{
49
+ const colorByLabel = label ? variantPresets.colorPreset[label.toLocaleLowerCase()] : undefined;
50
+ const colorArray = colorByLabel ? [
51
+ colorByLabel
52
+ ] : [];
53
+ const firstColor = color?.[0];
54
+ if (!firstColor && colorArray.length) colorChange = true;
55
+ return firstColor ? [
56
+ firstColor
57
+ ] : colorArray;
58
+ };
59
+ const getProductOptionsLabelByName = (options, name)=>{
60
+ const labels = [];
61
+ const optionByName = options.find((op)=>op.name === name);
62
+ optionByName?.values.forEach((val)=>{
63
+ labels.push(val.label ?? '');
64
+ });
65
+ return labels;
66
+ };
67
+ const getSwatchesOptionsLabel = (options)=>{
68
+ const labels = [];
69
+ options.forEach((op)=>{
70
+ labels.push(op.label ?? '');
71
+ return;
72
+ });
73
+ return labels;
74
+ };
75
+ const setDefaultSwatches = (swatches, options)=>{
76
+ if (swatches) {
77
+ swatches?.map((sw)=>{
78
+ const productLabels = getProductOptionsLabelByName(options, sw.optionTitle);
79
+ const swLabels = getSwatchesOptionsLabel(sw.optionValues);
80
+ productLabels.forEach((label)=>{
81
+ if (!swLabels.includes(label)) {
82
+ sw.optionValues.push({
83
+ label,
84
+ colors: getColorDefault(label),
85
+ imageUrl: ''
86
+ });
87
+ }
88
+ });
89
+ sw.optionValues = sw.optionValues.map((op)=>{
90
+ if (op.imageUrl === undefined) swatchChange = true;
91
+ return {
92
+ label: op.label ?? '',
93
+ colors: getColorDefault(op.label, op.colors),
94
+ imageUrl: op.imageUrl ?? ''
95
+ };
96
+ });
97
+ });
98
+ }
99
+ return swatches;
100
+ };
101
+ const fetchProductValueLabel = async (fetcher)=>{
102
+ const initVariables = {};
103
+ const query = async (variables)=>{
104
+ const response = await fetcher([
105
+ productValueLabel_generated.ProductOptionNameDocument,
106
+ variables
107
+ ]);
108
+ return response;
109
+ };
110
+ return query(initVariables);
111
+ };
112
+
113
+ exports.default = useInitialSwatchesOptions;
@@ -3,10 +3,18 @@
3
3
  var react = require('react');
4
4
  var ProductContext = require('../contexts/ProductContext.js');
5
5
  var flattenConnection = require('../helpers/flatten-connection.js');
6
+ require('react/jsx-runtime');
7
+ require('zustand');
6
8
  require('swr');
9
+ require('@gem-sdk/adapter-shopify');
10
+ require('swr/mutation');
11
+ require('vanilla-lazyload');
12
+ require('./useCartUI.js');
13
+ var variant = require('../helpers/variant.js');
14
+ require('react-transition-group');
15
+ require('@gem-sdk/core');
7
16
  var product = require('../helpers/product.js');
8
17
  require('../helpers/convert.js');
9
- var variant = require('../helpers/variant.js');
10
18
 
11
19
  const useUniqProductID = ()=>{
12
20
  return ProductContext.useProductStore((s)=>s.uiqueId);
@@ -141,8 +149,7 @@ const useCurrentVariant = ()=>{
141
149
  };
142
150
  const useCurrentVariantInStock = ()=>{
143
151
  const currentVariant = useCurrentVariant();
144
- const isInStock = variant.checkInStock(currentVariant);
145
- return isInStock;
152
+ return variant.checkInStock(currentVariant);
146
153
  };
147
154
  const useVariantOutStock = (optionId, optionValue)=>{
148
155
  const { selectedOptions } = useSelectedOption();
package/dist/cjs/index.js CHANGED
@@ -32,6 +32,7 @@ var GlobalEvent = require('./helpers/GlobalEvent.js');
32
32
  var isBrowser = require('./helpers/is-browser.js');
33
33
  var isSafari = require('./helpers/is-safari.js');
34
34
  var isEmptyChildren = require('./helpers/is-empty-children.js');
35
+ var filterToolbarPreview = require('./helpers/filter-toolbar-preview.js');
35
36
  var makeStyle = require('./helpers/make-style.js');
36
37
  var normalizeBuilderData = require('./helpers/normalize-builder-data.js');
37
38
  var prefetchQueries = require('./helpers/prefetch-queries.js');
@@ -83,6 +84,7 @@ var useProduct = require('./hooks/useProduct.js');
83
84
  var useProductList = require('./hooks/useProductList.js');
84
85
  var useSuspenseFetch = require('./hooks/useSuspenseFetch.js');
85
86
  var useSwatchesOptions = require('./hooks/useSwatchesOptions.js');
87
+ var useInitialSwatchesOptions = require('./hooks/useInitialSwatchesOptions.js');
86
88
  var shop$1 = require('./types/shop.js');
87
89
  var globalStyle = require('./types/global-style.js');
88
90
  var getCollection = require('./helpers/queries/get-collection.js');
@@ -147,7 +149,9 @@ exports.globalEvent = GlobalEvent.default;
147
149
  exports.isBrowser = isBrowser.default;
148
150
  exports.isSafari = isSafari.default;
149
151
  exports.isEmptyChildren = isEmptyChildren.isEmptyChildren;
152
+ exports.filterToolbarPreview = filterToolbarPreview.filterToolbarPreview;
150
153
  exports.makeAspectRatio = makeStyle.makeAspectRatio;
154
+ exports.makeGlobalSizeWidthResponsive = makeStyle.makeGlobalSizeWidthResponsive;
151
155
  exports.makeHeight = makeStyle.makeHeight;
152
156
  exports.makeLineClamp = makeStyle.makeLineClamp;
153
157
  exports.makeStyle = makeStyle.makeStyle;
@@ -214,12 +218,17 @@ exports.isLocalEnv = convert.isLocalEnv;
214
218
  exports.composeSize = size.composeSize;
215
219
  exports.composeSizeCss = size.composeSizeCss;
216
220
  exports.genSizeClass = size.genSizeClass;
221
+ exports.getPaddingGlobalSize = size.getPaddingGlobalSize;
222
+ exports.getWidthHeightGlobalSize = size.getWidthHeightGlobalSize;
223
+ exports.makeGlobalSize = size.makeGlobalSize;
224
+ exports.makeStyleWithDefault = size.makeStyleWithDefault;
217
225
  exports.composeShadowCss = shadow.composeShadowCss;
218
226
  exports.getStyleShadow = shadow.getStyleShadow;
219
227
  exports.getStyleShadowState = shadow.getStyleShadowState;
220
228
  exports.parseValueWithUnit = shadow.parseValueWithUnit;
221
229
  exports.composeBackgroundCss = background.composeBackgroundCss;
222
230
  exports.getStyleBackgroundByDevice = background.getStyleBackgroundByDevice;
231
+ exports.makeFixedBgAttachment = background.makeFixedBgAttachment;
223
232
  exports.generateCollectionQueryKey = query.generateCollectionQueryKey;
224
233
  exports.generateProductQueryKey = query.generateProductQueryKey;
225
234
  exports.generateProductsQueryKey = query.generateProductsQueryKey;
@@ -284,6 +293,7 @@ exports.useProductListSettings = useProductList.useProductListSettings;
284
293
  exports.useProductListStyles = useProductList.useProductListStyles;
285
294
  exports.useSuspenseFetch = useSuspenseFetch.default;
286
295
  exports.useSwatchesOptions = useSwatchesOptions.default;
296
+ exports.useInitialSwatchesOptions = useInitialSwatchesOptions.default;
287
297
  exports.ShopType = shop$1;
288
298
  exports.OptionNormalStyle = globalStyle.OptionNormalStyle;
289
299
  exports.OptionSpecialStyle = globalStyle.OptionSpecialStyle;