@gem-sdk/core 1.43.2 → 1.43.3-staging.36

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 (64) hide show
  1. package/dist/cjs/components/ComponentAnimation.js +17 -0
  2. package/dist/cjs/components/ComponentToolbarPreview.js +124 -5
  3. package/dist/cjs/components/ComponentWrapperPreview.js +48 -5
  4. package/dist/cjs/components/Render.liquid.js +3 -0
  5. package/dist/cjs/components/RenderCustomCode.js +3 -0
  6. package/dist/cjs/components/ai-generator/AIContentGenerator.js +252 -0
  7. package/dist/cjs/components/ai-generator/AIGenContentLoading.js +85 -0
  8. package/dist/cjs/components/ai-generator/components/PickProduct.js +219 -0
  9. package/dist/cjs/components/ai-generator/components/ToneAndVoice.js +77 -0
  10. package/dist/cjs/components/ai-generator/hooks/useCheckingProductInside.js +47 -0
  11. package/dist/cjs/components/ai-generator/hooks/useFlipPopup.js +110 -0
  12. package/dist/cjs/components/ai-generator/hooks/useGettingGenerateRequest.js +37 -0
  13. package/dist/cjs/components/ai-generator/hooks/useListenEventGenerate.js +70 -0
  14. package/dist/cjs/components/ai-generator/icons/AIIcon.js +67 -0
  15. package/dist/cjs/components/ai-generator/icons/CloseIcon.js +19 -0
  16. package/dist/cjs/components/ai-generator/icons/DropdownIcon.js +37 -0
  17. package/dist/cjs/components/ai-generator/icons/SearchIcon.js +21 -0
  18. package/dist/cjs/components/ai-generator/icons/ShowMoreIcon.js +21 -0
  19. package/dist/cjs/components/ai-generator/icons/UpgradeIcon.js +27 -0
  20. package/dist/cjs/components/ai-generator/icons/WarningIcon.js +31 -0
  21. package/dist/cjs/components/constant.js +13 -0
  22. package/dist/cjs/components/resize/Spacing.js +21 -11
  23. package/dist/cjs/components/theme-section/CreateThemeSection.js +3 -0
  24. package/dist/cjs/contexts/BuilderPreviewContext.js +6 -5
  25. package/dist/cjs/contexts/ShopContext.js +18 -0
  26. package/dist/cjs/helpers/queries/get-products.js +23 -0
  27. package/dist/cjs/hooks/shop/use-products-query.js +29 -0
  28. package/dist/cjs/hooks/use-current-device.js +11 -2
  29. package/dist/cjs/hooks/useAnimations.js +3 -0
  30. package/dist/cjs/hooks/useInitialSwatchesOptions.js +3 -0
  31. package/dist/cjs/hooks/useProduct.js +3 -0
  32. package/dist/esm/components/ComponentAnimation.js +13 -0
  33. package/dist/esm/components/ComponentToolbarPreview.js +124 -5
  34. package/dist/esm/components/ComponentWrapperPreview.js +48 -5
  35. package/dist/esm/components/Render.liquid.js +3 -0
  36. package/dist/esm/components/RenderCustomCode.js +3 -0
  37. package/dist/esm/components/ai-generator/AIContentGenerator.js +250 -0
  38. package/dist/esm/components/ai-generator/AIGenContentLoading.js +83 -0
  39. package/dist/esm/components/ai-generator/components/PickProduct.js +217 -0
  40. package/dist/esm/components/ai-generator/components/ToneAndVoice.js +75 -0
  41. package/dist/esm/components/ai-generator/hooks/useCheckingProductInside.js +45 -0
  42. package/dist/esm/components/ai-generator/hooks/useFlipPopup.js +108 -0
  43. package/dist/esm/components/ai-generator/hooks/useGettingGenerateRequest.js +35 -0
  44. package/dist/esm/components/ai-generator/hooks/useListenEventGenerate.js +68 -0
  45. package/dist/esm/components/ai-generator/icons/AIIcon.js +65 -0
  46. package/dist/esm/components/ai-generator/icons/CloseIcon.js +17 -0
  47. package/dist/esm/components/ai-generator/icons/DropdownIcon.js +34 -0
  48. package/dist/esm/components/ai-generator/icons/SearchIcon.js +19 -0
  49. package/dist/esm/components/ai-generator/icons/ShowMoreIcon.js +19 -0
  50. package/dist/esm/components/ai-generator/icons/UpgradeIcon.js +25 -0
  51. package/dist/esm/components/ai-generator/icons/WarningIcon.js +29 -0
  52. package/dist/esm/components/constant.js +13 -1
  53. package/dist/esm/components/resize/Spacing.js +21 -11
  54. package/dist/esm/components/theme-section/CreateThemeSection.js +3 -0
  55. package/dist/esm/contexts/BuilderPreviewContext.js +6 -5
  56. package/dist/esm/contexts/ShopContext.js +19 -1
  57. package/dist/esm/helpers/queries/get-products.js +23 -1
  58. package/dist/esm/hooks/shop/use-products-query.js +30 -2
  59. package/dist/esm/hooks/use-current-device.js +11 -2
  60. package/dist/esm/hooks/useAnimations.js +3 -0
  61. package/dist/esm/hooks/useInitialSwatchesOptions.js +3 -0
  62. package/dist/esm/hooks/useProduct.js +3 -0
  63. package/dist/types/index.d.ts +11 -2
  64. package/package.json +6 -3
@@ -0,0 +1,17 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var jsxRuntime = require('react/jsx-runtime');
6
+ var react = require('react');
7
+ var useApplyAnimation = require('../hooks/animation/useApplyAnimation.js');
8
+
9
+ const ComponentAnimation = ({ ...props })=>{
10
+ useApplyAnimation.default({
11
+ props
12
+ });
13
+ return /*#__PURE__*/ jsxRuntime.jsx(jsxRuntime.Fragment, {});
14
+ };
15
+ var ComponentAnimation$1 = /*#__PURE__*/ react.memo(ComponentAnimation);
16
+
17
+ exports.default = ComponentAnimation$1;
@@ -10,6 +10,7 @@ var ShopContext = require('../contexts/ShopContext.js');
10
10
  require('@gem-sdk/adapter-shopify');
11
11
  require('swr');
12
12
  require('swr/mutation');
13
+ require('swr/infinite');
13
14
  require('vanilla-lazyload');
14
15
  require('../hooks/useCartUI.js');
15
16
  var CreateThemeSection = require('./theme-section/CreateThemeSection.js');
@@ -17,6 +18,9 @@ var Tooltip = require('./toolbar/Tooltip.js');
17
18
  var ThemeSectionStatus = require('./theme-section/ThemeSectionStatus.js');
18
19
  var Resize = require('./resize/Resize.js');
19
20
  var useToolbarPostPurchase = require('../hooks/useToolbarPostPurchase.js');
21
+ var constant = require('./constant.js');
22
+ var AIContentGenerator = require('./ai-generator/AIContentGenerator.js');
23
+ var AIGenContentLoading = require('./ai-generator/AIGenContentLoading.js');
20
24
  require('../helpers/convert.js');
21
25
 
22
26
  const SECTION_LIMIT = 25;
@@ -30,6 +34,8 @@ const isSection = (el)=>{
30
34
  };
31
35
  const ComponentToolbarPreview = (props)=>{
32
36
  const isThemeSection = props.isThemeSection;
37
+ const isShopifySection = props.isShopifySection;
38
+ const storefrontUrl = ShopContext.useShopStore((s)=>s.storefrontUrl);
33
39
  const editingPageType = ShopContext.useShopStore((s)=>s.pageType);
34
40
  const getParents = BuilderPreviewContext.useBuilderPreviewStore((s)=>s.getParents);
35
41
  const root = BuilderPreviewContext.useBuilderPreviewStore((s)=>s.getItem('ROOT'));
@@ -40,6 +46,7 @@ const ComponentToolbarPreview = (props)=>{
40
46
  const [parents, setParents] = react.useState([]);
41
47
  const [deleteTooltipPosition, setDeleteTooltipPosition] = react.useState('top');
42
48
  const [isDisableDelete, setIsUnableDelete] = react.useState(false);
49
+ const [parentProductUid, setParentProductUid] = react.useState('');
43
50
  const [tooltipText, setTooltipText] = react.useState({
44
51
  width: '',
45
52
  text: ''
@@ -49,6 +56,11 @@ const ComponentToolbarPreview = (props)=>{
49
56
  editingPageType
50
57
  ]);
51
58
  const { checkDisableDelete, getTooltipText, checkDisableDuplicate } = useToolbarPostPurchase.usePostPurchase(props.uid, props.tag || '');
59
+ const editProductElementList = [
60
+ 'Product Title',
61
+ 'Product Description',
62
+ 'Product Price'
63
+ ];
52
64
  const isOverToolbarPosition = (el, parent)=>{
53
65
  const parentLength = parents.length;
54
66
  const rect = el.getBoundingClientRect();
@@ -79,6 +91,27 @@ const ComponentToolbarPreview = (props)=>{
79
91
  }, [
80
92
  props.tag
81
93
  ]);
94
+ const productId = react.useMemo(()=>{
95
+ const ele = document.querySelector(`[data-uid="${parentProductUid}"]`);
96
+ return ele?.getAttribute('data-product-id');
97
+ }, [
98
+ parentProductUid
99
+ ]);
100
+ const shopName = react.useMemo(()=>{
101
+ const pattern = /^(?:https?:\/\/)?([^/]+)\.myshopify\.com/;
102
+ if (storefrontUrl) {
103
+ return storefrontUrl.match(pattern)?.[1];
104
+ }
105
+ return '';
106
+ }, [
107
+ storefrontUrl
108
+ ]);
109
+ const shopifyEditLink = react.useMemo(()=>{
110
+ return productId ? `https://admin.shopify.com/store/${shopName}/products/${productId}` : '';
111
+ }, [
112
+ productId,
113
+ shopName
114
+ ]);
82
115
  // Get parents
83
116
  const onActiveComponent = react.useCallback((e)=>{
84
117
  const detail = e.detail;
@@ -97,6 +130,10 @@ const ComponentToolbarPreview = (props)=>{
97
130
  return true;
98
131
  }).slice(0, 3);
99
132
  setParents(currentParents);
133
+ const parentFindUid = currentParents.find((item)=>item.tag === 'Product')?.uid;
134
+ if (parentFindUid) {
135
+ setParentProductUid(parentFindUid);
136
+ }
100
137
  } else {
101
138
  setParents([]);
102
139
  setIsShowParent(false);
@@ -168,6 +205,9 @@ const ComponentToolbarPreview = (props)=>{
168
205
  });
169
206
  window.dispatchEvent(event);
170
207
  };
208
+ const goToShopifyEditLink = ()=>{
209
+ window.open(shopifyEditLink, '_blank');
210
+ };
171
211
  const onDelete = (e)=>{
172
212
  e.preventDefault();
173
213
  e.stopPropagation();
@@ -175,7 +215,8 @@ const ComponentToolbarPreview = (props)=>{
175
215
  bubbles: true,
176
216
  detail: {
177
217
  componentUid: props.uid,
178
- isThemeSection: isThemeSection
218
+ isThemeSection,
219
+ isShopifySection
179
220
  }
180
221
  });
181
222
  window.dispatchEvent(event);
@@ -191,7 +232,8 @@ const ComponentToolbarPreview = (props)=>{
191
232
  bubbles: true,
192
233
  detail: {
193
234
  componentUid: props.uid,
194
- isThemeSection: isThemeSection
235
+ isThemeSection,
236
+ isShopifySection
195
237
  }
196
238
  });
197
239
  window.dispatchEvent(event);
@@ -240,6 +282,9 @@ const ComponentToolbarPreview = (props)=>{
240
282
  return false;
241
283
  };
242
284
  const getSectionName = ()=>{
285
+ if (isShopifySection) {
286
+ return props.name?.includes('Shopify section:') ? props.name : `Shopify section: ${props.name}`;
287
+ }
243
288
  const checkRenamedSection = props.name && props.name === `Section ${props.uid}`;
244
289
  if (getSectionNumber() >= SECTION_LIMIT - 5) {
245
290
  return `${checkRenamedSection ? 'Section' : props?.name} ${getIndexSection() + 1}/${SECTION_LIMIT}`;
@@ -256,6 +301,7 @@ const ComponentToolbarPreview = (props)=>{
256
301
  "data-toolbar": true,
257
302
  "data-toolbar-section": props.tag == 'Section',
258
303
  "data-toolbar-theme-section": props.tag == 'Section' && !!isThemeSection || isThemeSectionEditor,
304
+ "data-toolbar-shopify-section": props.tag == 'Section' && !!isShopifySection,
259
305
  "data-toolbar-limit": getIndexSection() >= SECTION_LIMIT,
260
306
  children: [
261
307
  /*#__PURE__*/ jsxRuntime.jsxs("div", {
@@ -298,9 +344,39 @@ const ComponentToolbarPreview = (props)=>{
298
344
  ]
299
345
  })
300
346
  }),
301
- props.tag == 'Section' ? /*#__PURE__*/ jsxRuntime.jsx("div", {
347
+ props.tag == 'Section' ? /*#__PURE__*/ jsxRuntime.jsxs("div", {
302
348
  "data-toolbar-name": true,
303
- children: getSectionName()
349
+ children: [
350
+ getSectionName(),
351
+ props.isShopifySection && !props.isShopifyVisibility && /*#__PURE__*/ jsxRuntime.jsxs("svg", {
352
+ "data-toolbar-visibility": true,
353
+ width: "20",
354
+ height: "20",
355
+ viewBox: "0 0 20 20",
356
+ fill: "none",
357
+ xmlns: "http://www.w3.org/2000/svg",
358
+ children: [
359
+ /*#__PURE__*/ jsxRuntime.jsx("path", {
360
+ fillRule: "evenodd",
361
+ clipRule: "evenodd",
362
+ d: "M13.1252 9.99773C13.1243 8.27226 11.7248 6.87423 9.99935 6.87506C8.27386 6.87561 6.87518 8.27455 6.87518 10.0001C6.87518 11.7259 8.27429 13.1251 10.0002 13.1251C11.7257 13.1251 13.125 11.727 13.1252 10.0011V9.99773ZM9.99985 8.12506C11.035 8.12451 11.8746 8.96322 11.8752 9.99839V10.0004C11.8752 11.0357 11.0359 11.8751 10.0002 11.8751C8.96465 11.8751 8.12518 11.0356 8.12518 10.0001C8.12518 8.96472 8.96451 8.12533 9.99985 8.12506Z",
363
+ fill: "#F9F9F9"
364
+ }),
365
+ /*#__PURE__*/ jsxRuntime.jsx("path", {
366
+ fillRule: "evenodd",
367
+ clipRule: "evenodd",
368
+ d: "M9.99885 4.37593C5.66421 4.37604 2.80603 7.64523 1.79548 9.00983C1.35636 9.60279 1.35918 10.4 1.80012 10.9902C2.81706 12.3514 5.69374 15.6241 9.99886 15.6241C14.3806 15.6241 17.2194 12.3452 18.2168 10.9808C18.6473 10.392 18.6442 9.60472 18.211 9.01902C17.2056 7.65938 14.3429 4.37583 9.99885 4.37593ZM2.80002 9.75374C3.77049 8.44326 6.30207 5.62602 9.99888 5.62593C13.7041 5.62585 16.24 8.45598 17.206 9.76225C17.3146 9.9091 17.3149 10.0965 17.2077 10.2431C16.254 11.5477 13.7416 14.3741 9.99886 14.3741C6.33149 14.3741 3.78173 11.5541 2.80152 10.242C2.69021 10.0931 2.69001 9.90229 2.80002 9.75374Z",
369
+ fill: "#F9F9F9"
370
+ }),
371
+ /*#__PURE__*/ jsxRuntime.jsx("path", {
372
+ fillRule: "evenodd",
373
+ clipRule: "evenodd",
374
+ d: "M18.0763 3.26988C18.3415 3.58809 18.2985 4.06101 17.9803 4.32619L2.98032 16.8262C2.66211 17.0914 2.18919 17.0484 1.92402 16.7302C1.65884 16.412 1.70184 15.939 2.02004 15.6739L17.02 3.17385C17.3383 2.90868 17.8112 2.95167 18.0763 3.26988Z",
375
+ fill: "#F9F9F9"
376
+ })
377
+ ]
378
+ })
379
+ ]
304
380
  }) : /*#__PURE__*/ jsxRuntime.jsx("div", {
305
381
  "data-toolbar-name": true,
306
382
  children: toolbarName()
@@ -380,7 +456,10 @@ const ComponentToolbarPreview = (props)=>{
380
456
  ]
381
457
  }, parent.uid);
382
458
  }),
383
- props.tag === 'Section' && !props.isThemeSection && isEnableCreateThemeSection() && getIndexSection() < SECTION_LIMIT && /*#__PURE__*/ jsxRuntime.jsx(CreateThemeSection.CreateThemeSection, {
459
+ props.tag === 'Section' && !props.isThemeSection && isEnableCreateThemeSection() && !props.isShopifySection && getIndexSection() < SECTION_LIMIT && /*#__PURE__*/ jsxRuntime.jsx(CreateThemeSection.CreateThemeSection, {
460
+ ...props
461
+ }),
462
+ !props.isShopifySection && constant.ableGenerateContentElements.includes(props.tag) && /*#__PURE__*/ jsxRuntime.jsx(AIContentGenerator.AIContentGenerator, {
384
463
  ...props
385
464
  }),
386
465
  props.tag == 'Sticky' && /*#__PURE__*/ jsxRuntime.jsx("div", {
@@ -401,6 +480,42 @@ const ComponentToolbarPreview = (props)=>{
401
480
  })
402
481
  })
403
482
  }),
483
+ editProductElementList.includes(toolbarName() ?? '') && /*#__PURE__*/ jsxRuntime.jsx(Tooltip.default, {
484
+ "data-toolbar-title": true,
485
+ enable: true,
486
+ "data-toolbar-disable": false,
487
+ text: "Edit content in Shopify",
488
+ position: "top",
489
+ onClick: goToShopifyEditLink,
490
+ "aria-hidden": "true",
491
+ children: /*#__PURE__*/ jsxRuntime.jsxs("svg", {
492
+ width: "16",
493
+ height: "16",
494
+ viewBox: "0 0 16 16",
495
+ fill: "none",
496
+ xmlns: "http://www.w3.org/2000/svg",
497
+ children: [
498
+ /*#__PURE__*/ jsxRuntime.jsx("path", {
499
+ fillRule: "evenodd",
500
+ clipRule: "evenodd",
501
+ d: "M8.61129 2.47348C8.61129 2.47348 8.47099 2.51557 8.23248 2.59274C8.19039 2.46647 8.13427 2.30512 8.05009 2.15079C7.78352 1.6387 7.39068 1.37212 6.91366 1.36511C6.87858 1.36511 6.85052 1.36511 6.81545 1.37212C6.80843 1.36511 6.80142 1.35634 6.7944 1.34757C6.78739 1.3388 6.78037 1.33003 6.77336 1.32302C6.56992 1.09854 6.30335 0.993314 5.98768 1.00033C5.37737 1.02137 4.76706 1.46332 4.269 2.249C3.91825 2.80319 3.65869 3.49767 3.58153 4.03082C3.38823 4.09074 3.21092 4.14586 3.05516 4.19429C2.64595 4.32151 2.3851 4.40261 2.37494 4.40261C2.01718 4.51485 2.01016 4.52888 1.96106 4.85859C1.92598 5.11113 1 12.2945 1 12.2945L7.14764 13.3583C7.18955 13.118 7.30454 12.8953 7.47848 12.7214L8.70249 11.4974V2.45945C8.66741 2.45945 8.63234 2.46647 8.61129 2.47348ZM6.82948 3.02767L6.62554 3.09101C6.27515 3.19989 5.90094 3.31617 5.5317 3.42752C5.65797 2.94349 5.89648 2.46647 6.19111 2.15079C6.30335 2.03154 6.45067 1.90527 6.63306 1.8281C6.80142 2.18587 6.83649 2.68393 6.82948 3.02767ZM5.99469 1.4072C6.13499 1.4072 6.26126 1.43526 6.36649 1.50541C6.19813 1.58959 6.0438 1.71586 5.88947 1.87721C5.50364 2.29109 5.202 2.94349 5.08274 3.56783C4.74459 3.66991 4.41804 3.77199 4.10838 3.8688L4.01646 3.89753C4.22691 2.90841 5.05468 1.43526 5.99469 1.4072ZM4.80214 7.0122C4.81874 7.26957 5.09737 7.44833 5.43473 7.66478C5.95252 7.99699 6.60867 8.41798 6.66813 9.3482C6.7453 10.5548 6.02977 11.3826 4.99154 11.4457C3.7569 11.5229 3.06943 10.7933 3.06943 10.7933L3.32899 9.67791C3.32899 9.67791 4.01646 10.197 4.56363 10.1619C4.92139 10.1409 5.04767 9.84627 5.04065 9.64283C5.01607 9.26796 4.73308 9.06671 4.41569 8.84101C4.00848 8.55142 3.54465 8.22157 3.49735 7.4331C3.42018 6.24756 4.19885 5.05501 5.91051 4.94277C6.57694 4.90068 6.91366 5.06904 6.91366 5.06904L6.52082 6.53518C6.52082 6.53518 6.08589 6.33876 5.56678 6.36682C4.80915 6.41592 4.79512 6.89294 4.80214 7.0122ZM7.23635 2.9014C7.22934 2.59274 7.19426 2.15781 7.04695 1.78601C7.50994 1.87721 7.74143 2.39632 7.83964 2.71199C7.70008 2.75665 7.54275 2.80575 7.37118 2.8593L7.23635 2.9014Z",
502
+ fill: "currentColor"
503
+ }),
504
+ /*#__PURE__*/ jsxRuntime.jsx("path", {
505
+ d: "M10.7719 3.44156C10.7757 3.47543 11.1733 6.16931 11.541 8.65883L8.95503 11.2448V2.57871C9.16548 2.78214 9.71265 3.31528 9.71265 3.31528C9.71265 3.31528 10.6106 3.32931 10.6597 3.33633C10.7088 3.34334 10.7649 3.37842 10.7719 3.44156Z",
506
+ fill: "currentColor"
507
+ }),
508
+ /*#__PURE__*/ jsxRuntime.jsx("path", {
509
+ d: "M14.8056 8.644L14.0424 7.88088C13.7832 7.62163 13.3629 7.62163 13.1036 7.88088L12.1519 8.83258L13.8539 10.5345L14.8056 9.58282C15.0648 9.32357 15.0648 8.90325 14.8056 8.644Z",
510
+ fill: "currentColor"
511
+ }),
512
+ /*#__PURE__*/ jsxRuntime.jsx("path", {
513
+ d: "M7.85018 13.0942L11.6419 9.30246L13.3438 11.0044L9.55212 14.7961C9.43782 14.9104 9.28573 14.9791 9.1244 14.9892L7.93427 15.0641C7.73484 15.0767 7.56961 14.9114 7.58216 14.712L7.65706 13.5219C7.66721 13.3606 7.73588 13.2085 7.85018 13.0942Z",
514
+ fill: "currentColor"
515
+ })
516
+ ]
517
+ })
518
+ }),
404
519
  /*#__PURE__*/ jsxRuntime.jsx(Tooltip.default, {
405
520
  enable: props.tag == 'Section' && getSectionNumber() >= SECTION_LIMIT,
406
521
  text: "Page has reached Shopify’s 25 section-limit",
@@ -454,6 +569,7 @@ const ComponentToolbarPreview = (props)=>{
454
569
  "data-outline": true,
455
570
  "data-outline-section": props.tag == 'Section',
456
571
  "data-outline-theme-section": props.tag == 'Section' && !!isThemeSection || isThemeSectionEditor,
572
+ "data-outline-shopify-section": props.tag == 'Section' && !!isShopifySection,
457
573
  "data-outline-limit": getIndexSection() >= SECTION_LIMIT
458
574
  }, 'outline-' + props.uid),
459
575
  props.tag == 'Section' && !isThemeSectionEditor && /*#__PURE__*/ jsxRuntime.jsxs(jsxRuntime.Fragment, {
@@ -500,6 +616,9 @@ const ComponentToolbarPreview = (props)=>{
500
616
  })
501
617
  ]
502
618
  }),
619
+ constant.ableGenerateContentElements.includes(props.tag) && /*#__PURE__*/ jsxRuntime.jsx(AIGenContentLoading.AIGenContentLoading, {
620
+ ...props
621
+ }),
503
622
  /*#__PURE__*/ jsxRuntime.jsx(Resize.default, {
504
623
  ...props
505
624
  })
@@ -8,15 +8,17 @@ var composeAdvanceStyle = require('../helpers/compose-advance-style.js');
8
8
  var constant = require('./constant.js');
9
9
  var RenderCustomCode = require('./RenderCustomCode.js');
10
10
  var ComponentToolbarPreview = require('./ComponentToolbarPreview.js');
11
- var useApplyAnimation = require('../hooks/animation/useApplyAnimation.js');
12
11
  require('zustand');
13
12
  require('swr');
14
13
  require('@gem-sdk/adapter-shopify');
15
14
  require('swr/mutation');
16
15
  var shop = require('../hooks/shop.js');
16
+ require('swr/infinite');
17
17
  require('vanilla-lazyload');
18
18
  require('../hooks/useCartUI.js');
19
+ var cls = require('../helpers/cls.js');
19
20
  require('../helpers/convert.js');
21
+ var ComponentAnimation = require('./ComponentAnimation.js');
20
22
 
21
23
  const ComponentWrapperPreview = ({ children, ...props })=>{
22
24
  react.useEffect(()=>{
@@ -30,9 +32,6 @@ const ComponentWrapperPreview = ({ children, ...props })=>{
30
32
  }, [
31
33
  props.uid
32
34
  ]);
33
- useApplyAnimation.default({
34
- props
35
- });
36
35
  const pageType = shop.usePageType();
37
36
  if (props.type === 'section') {
38
37
  return null;
@@ -41,6 +40,10 @@ const ComponentWrapperPreview = ({ children, ...props })=>{
41
40
  if (props.tag === 'Section' && props.isThemeSection) {
42
41
  customProps['data-theme-section'] = true;
43
42
  }
43
+ if (props.tag === 'Section' && props.isShopifySection) {
44
+ customProps['data-shopify-section'] = true;
45
+ customProps['data-toolbar-wrap'] = true;
46
+ }
44
47
  // Build editor configs
45
48
  if (props.editorConfigs) {
46
49
  const editorConfigs = props.editorConfigs;
@@ -95,6 +98,40 @@ const ComponentWrapperPreview = ({ children, ...props })=>{
95
98
  'data-component-label': props.label,
96
99
  'data-not-droppable': isNotDroppable(props.tag)
97
100
  };
101
+ const ShopifySection = ({ name, visibility })=>{
102
+ return /*#__PURE__*/ jsxRuntime.jsxs("div", {
103
+ className: cls.cls('gp-flex gp-items-center gp-justify-center gp-gap-[8px] gp-bg-[#F4F4F4] gp-p-[16px] gp-border gp-border-[#D6D6D6]', {
104
+ 'gp-opacity-60': !visibility
105
+ }),
106
+ children: [
107
+ /*#__PURE__*/ jsxRuntime.jsxs("svg", {
108
+ width: "24",
109
+ height: "24",
110
+ viewBox: "0 0 24 24",
111
+ fill: "none",
112
+ xmlns: "http://www.w3.org/2000/svg",
113
+ children: [
114
+ /*#__PURE__*/ jsxRuntime.jsx("path", {
115
+ d: "M19.1475 5.16194C19.1416 5.1148 19.1197 5.0713 19.0857 5.03911C19.0516 5.00692 19.0076 4.9881 18.9614 4.98597C18.8835 4.98597 17.3469 4.95397 17.3469 4.95397C17.3469 4.95397 16.0588 3.67419 15.9342 3.5311C15.8104 3.40312 15.5619 3.43512 15.4684 3.46711L14.8166 3.67508C14.7361 3.40491 14.6323 3.14259 14.5067 2.89121C14.0566 1.99536 13.3727 1.51544 12.5659 1.51544C12.5044 1.51544 12.4577 1.51544 12.3954 1.53144C12.3642 1.49945 12.3486 1.46745 12.3175 1.45145C11.9608 1.06752 11.5107 0.875552 10.967 0.891549C9.92824 0.923543 8.88772 1.70741 8.03419 3.08318C7.44467 4.05901 6.99453 5.27392 6.8543 6.21776C5.65969 6.6017 4.82087 6.87365 4.79057 6.87365C4.18461 7.06562 4.16903 7.08161 4.09199 7.67351C4.06082 8.12144 2.47754 20.7415 2.47754 20.7415L15.7636 23.1091L21.522 21.6374C21.5064 21.6374 19.1631 5.27392 19.1475 5.16194ZM14.1492 3.89904C13.8062 4.00572 13.4648 4.11772 13.1251 4.23498C13.1251 3.69108 13.0472 2.92321 12.8143 2.28331C13.6064 2.41129 13.9942 3.33914 14.1492 3.89904ZM12.4265 4.44206C11.7279 4.66602 10.9679 4.90598 10.207 5.14594C10.4243 4.29808 10.8277 3.46623 11.3245 2.90632C11.533 2.66965 11.7863 2.47913 12.069 2.34641C12.3806 2.9712 12.4421 3.85105 12.4265 4.44206ZM10.9982 1.61143C11.2466 1.61143 11.4483 1.65942 11.6197 1.7874C11.3127 1.95192 11.0387 2.17444 10.8121 2.44329C10.1455 3.17916 9.63305 4.31408 9.43135 5.4179C8.79423 5.62586 8.17356 5.81783 7.61521 5.9938C7.98744 4.25009 9.39933 1.65942 10.9982 1.61143Z",
116
+ fill: "#95BF47"
117
+ }),
118
+ /*#__PURE__*/ jsxRuntime.jsx("path", {
119
+ d: "M18.9647 4.94709C18.8851 4.94709 17.3155 4.91503 17.3155 4.91503C17.3155 4.91503 15.9981 3.63242 15.8716 3.48812C15.8261 3.43951 15.7635 3.41074 15.6973 3.40796V23.1094L21.5828 21.6344L19.1709 5.12345C19.1399 5.01122 19.0444 4.94709 18.9647 4.94709Z",
120
+ fill: "#5E8E3E"
121
+ }),
122
+ /*#__PURE__*/ jsxRuntime.jsx("path", {
123
+ d: "M13.0575 8.51577L12.3029 10.8908C12.3029 10.8908 11.4602 10.5663 10.4599 10.6253C8.98595 10.6991 8.98595 11.4809 8.98595 11.6727C9.07404 12.7348 12.39 12.9709 12.5828 15.4631C12.7238 17.4251 11.3545 18.7675 9.35396 18.8708C6.96778 18.9733 5.65137 17.7939 5.65137 17.7939L6.16032 15.9794C6.16032 15.9794 7.49435 16.8203 8.5465 16.7613C9.23162 16.7318 9.4949 16.245 9.45967 15.9204C9.35396 14.5337 6.65165 14.6223 6.47645 12.3365C6.33551 10.4188 7.82712 8.48626 11.1265 8.30924C12.4076 8.23548 13.0575 8.51577 13.0575 8.51577Z",
124
+ fill: "white"
125
+ })
126
+ ]
127
+ }),
128
+ /*#__PURE__*/ jsxRuntime.jsx("span", {
129
+ className: "gp-text-[#212121] gp-text-[14px] gp-leading-[24px] gp-font-medium",
130
+ children: name
131
+ })
132
+ ]
133
+ });
134
+ };
98
135
  if (constant.disableWrap.includes(props.tag) && /*#__PURE__*/ react.isValidElement(children)) {
99
136
  return /*#__PURE__*/ jsxRuntime.jsxs(jsxRuntime.Fragment, {
100
137
  children: [
@@ -109,7 +146,10 @@ const ComponentWrapperPreview = ({ children, ...props })=>{
109
146
  builderAttrs,
110
147
  advanced,
111
148
  children: [
112
- children.props['children'],
149
+ props.isShopifySection ? /*#__PURE__*/ jsxRuntime.jsx(ShopifySection, {
150
+ name: props.name ?? '',
151
+ visibility: !!props.isShopifyVisibility
152
+ }) : children.props['children'],
113
153
  /*#__PURE__*/ jsxRuntime.jsx(ComponentToolbarPreview.default, {
114
154
  ...props
115
155
  })
@@ -121,6 +161,9 @@ const ComponentWrapperPreview = ({ children, ...props })=>{
121
161
  // Render
122
162
  return /*#__PURE__*/ jsxRuntime.jsxs(jsxRuntime.Fragment, {
123
163
  children: [
164
+ /*#__PURE__*/ jsxRuntime.jsx(ComponentAnimation.default, {
165
+ ...props
166
+ }),
124
167
  /*#__PURE__*/ jsxRuntime.jsx(RenderCustomCode.default, {
125
168
  uid: props.uid,
126
169
  advanced: advanced
@@ -9,11 +9,14 @@ require('zustand');
9
9
  require('swr');
10
10
  require('@gem-sdk/adapter-shopify');
11
11
  require('swr/mutation');
12
+ require('swr/infinite');
12
13
  require('vanilla-lazyload');
13
14
  require('../hooks/useCartUI.js');
14
15
  require('react-transition-group');
15
16
  require('@gem-sdk/core');
16
17
  var constant = require('./constant.js');
18
+ require('classnames');
19
+ require('dayjs');
17
20
  var composeAdvanceStyle = require('../helpers/compose-advance-style.js');
18
21
  var convert = require('../helpers/convert.js');
19
22
  var render = require('../helpers/render.js');
@@ -11,10 +11,13 @@ require('swr');
11
11
  require('@gem-sdk/adapter-shopify');
12
12
  require('swr/mutation');
13
13
  var shop = require('../hooks/shop.js');
14
+ require('swr/infinite');
14
15
  require('vanilla-lazyload');
15
16
  require('../hooks/useCartUI.js');
16
17
  require('react-transition-group');
17
18
  require('@gem-sdk/core');
19
+ require('classnames');
20
+ require('dayjs');
18
21
  require('../helpers/convert.js');
19
22
 
20
23
  const RenderCustomCode = ({ uid, advanced })=>{
@@ -0,0 +1,252 @@
1
+ 'use strict';
2
+
3
+ var jsxRuntime = require('react/jsx-runtime');
4
+ var react = require('react');
5
+ var AIIcon = require('./icons/AIIcon.js');
6
+ var CloseIcon = require('./icons/CloseIcon.js');
7
+ var ShowMoreIcon = require('./icons/ShowMoreIcon.js');
8
+ var WarningIcon = require('./icons/WarningIcon.js');
9
+ var UpgradeIcon = require('./icons/UpgradeIcon.js');
10
+ var PickProduct = require('./components/PickProduct.js');
11
+ var ToneAndVoice = require('./components/ToneAndVoice.js');
12
+ var classNames = require('classnames');
13
+ var useListenEventGenerate = require('./hooks/useListenEventGenerate.js');
14
+ var useGettingGenerateRequest = require('./hooks/useGettingGenerateRequest.js');
15
+ var useFlipPopup = require('./hooks/useFlipPopup.js');
16
+ var useCheckingProductInside = require('./hooks/useCheckingProductInside.js');
17
+ require('zustand');
18
+ var ShopContext = require('../../contexts/ShopContext.js');
19
+ require('@gem-sdk/adapter-shopify');
20
+ require('swr');
21
+ require('swr/mutation');
22
+ require('swr/infinite');
23
+ require('vanilla-lazyload');
24
+ require('../../hooks/useCartUI.js');
25
+ require('react-transition-group');
26
+ require('@gem-sdk/core');
27
+ var dayjs = require('dayjs');
28
+ require('../../helpers/convert.js');
29
+
30
+ const AIContentGenerator = ({ ...props })=>{
31
+ const [isShowPopup, setIsShowPopup] = react.useState(false);
32
+ const [isShowMore, setIsShowMore] = react.useState(false);
33
+ const genTool = react.useRef(null);
34
+ const genPopup = react.useRef(null);
35
+ const genPopupHeader = react.useRef(null);
36
+ const genButtonWrapper = react.useRef(null);
37
+ const nextMonth = dayjs().add(1, 'month').startOf('month').format('DD MMM');
38
+ const { popupPositionX, popupPositionY, isValidating: isValidatingFlipPopup, bodyMaxHeight: popupBodyMaxHeight } = useFlipPopup.useFlipPopup(isShowPopup, {
39
+ genTool,
40
+ genPopup,
41
+ genPopupHeader,
42
+ genButtonWrapper
43
+ });
44
+ const { isGenerating, onGenerate, onOpenProductElementSettings, goToPricing } = useListenEventGenerate.useListenEventGenerate({
45
+ uid: props.uid,
46
+ tag: String(props.tag)
47
+ });
48
+ const { getRequestBody, prompt, changeProductName, changePrompt, changeTone } = useGettingGenerateRequest.useGettingGenerateRequest();
49
+ const { productElement, checkSectionHasProduct } = useCheckingProductInside.useCheckingProductInside(genTool);
50
+ const generateLimitation = ShopContext.useShopStore((s)=>s.generateContentLimitation);
51
+ const togglePopup = ()=>{
52
+ setIsShowPopup(!isShowPopup);
53
+ };
54
+ const hidePopup = ()=>{
55
+ setIsShowPopup(false);
56
+ };
57
+ const onChangePrompt = (e)=>{
58
+ changePrompt(e.target.value);
59
+ };
60
+ const onActiveComponent = react.useCallback((e)=>{
61
+ const detail = e.detail;
62
+ if (detail?.componentUid !== props.uid) {
63
+ hidePopup();
64
+ return;
65
+ }
66
+ checkSectionHasProduct();
67
+ }, [
68
+ props.uid,
69
+ checkSectionHasProduct
70
+ ]);
71
+ const toggleShowMore = ()=>{
72
+ setIsShowMore(!isShowMore);
73
+ };
74
+ const handleGenerateContent = ()=>{
75
+ const body = getRequestBody();
76
+ onGenerate(body);
77
+ hidePopup();
78
+ };
79
+ const handleOpenProductSetting = ()=>{
80
+ onOpenProductElementSettings(productElement.uid ?? '');
81
+ };
82
+ react.useEffect(()=>{
83
+ if (!isGenerating) {
84
+ hidePopup();
85
+ }
86
+ }, [
87
+ isGenerating
88
+ ]);
89
+ react.useEffect(()=>{
90
+ if (productElement.productId) {
91
+ setIsShowMore(false);
92
+ return;
93
+ }
94
+ setIsShowMore(true);
95
+ }, [
96
+ productElement
97
+ ]);
98
+ react.useEffect(()=>{
99
+ window.addEventListener('editor:active-component', onActiveComponent);
100
+ return ()=>{
101
+ window.removeEventListener('editor:active-component', onActiveComponent);
102
+ };
103
+ }, [
104
+ onActiveComponent
105
+ ]);
106
+ return /*#__PURE__*/ jsxRuntime.jsxs("div", {
107
+ className: "gp-relative",
108
+ ref: genTool,
109
+ children: [
110
+ /*#__PURE__*/ jsxRuntime.jsx("div", {
111
+ className: "gp-gen-content-toolbar gp-border-r-[#6a6a6a] gp-border-r gp-pr-1 gp-mr-1",
112
+ children: /*#__PURE__*/ jsxRuntime.jsxs("button", {
113
+ className: classNames({
114
+ 'gp-bg-[#3B3B3B]': isShowPopup
115
+ }, 'gp-p-1 gp-text-xs gp-flex gp-gap-1 gp-items-center gp-rounded-md hover:gp-bg-[#3B3B3B] gp-font-medium'),
116
+ onClick: togglePopup,
117
+ children: [
118
+ /*#__PURE__*/ jsxRuntime.jsx(AIIcon.AIIcon, {}),
119
+ "AI Content"
120
+ ]
121
+ })
122
+ }),
123
+ /*#__PURE__*/ jsxRuntime.jsxs("div", {
124
+ className: classNames({
125
+ 'gp-hidden': !isShowPopup,
126
+ 'gp-right-0': props.tag === 'Section' || popupPositionX === 'right',
127
+ 'gp-left-0': popupPositionX === 'left' && props.tag !== 'Section',
128
+ 'gp-top-8': popupPositionY === 'top',
129
+ 'gp-bottom-8': popupPositionY === 'bottom',
130
+ '!gp-visible': !isValidatingFlipPopup
131
+ }, 'gp-absolute gp-invisible gp-rounded-lg gp-bg-[#151515] gp-w-[312px] !gp-max-w-[312px] !gp-cursor-default'),
132
+ ref: genPopup,
133
+ children: [
134
+ /*#__PURE__*/ jsxRuntime.jsxs("div", {
135
+ className: "gp-flex gp-items-center gp-justify-between gp-px-4 gp-py-[10px]",
136
+ ref: genPopupHeader,
137
+ children: [
138
+ /*#__PURE__*/ jsxRuntime.jsx("span", {
139
+ className: "gp-font-medium gp-text-sm",
140
+ children: "Write with GemAI"
141
+ }),
142
+ /*#__PURE__*/ jsxRuntime.jsx("button", {
143
+ className: "gp-p-2 gp-cursor-pointer hover:gp-bg-[#3B3B3B] gp-rounded-md",
144
+ onClick: hidePopup,
145
+ children: /*#__PURE__*/ jsxRuntime.jsx(CloseIcon.CloseIcon, {})
146
+ })
147
+ ]
148
+ }),
149
+ /*#__PURE__*/ jsxRuntime.jsx("div", {
150
+ className: classNames({
151
+ 'gp-overflow-auto': popupBodyMaxHeight !== null
152
+ }, 'gp-pt-2 gp-text-left gp-px-4 scrollbar:gp-w-1 scrollbar-thumb:gp-bg-[#999] scrollbar-thumb:gp-rounded-xl'),
153
+ style: {
154
+ maxHeight: popupBodyMaxHeight !== null ? `${popupBodyMaxHeight}px` : 'auto'
155
+ },
156
+ children: generateLimitation?.isAllow ? /*#__PURE__*/ jsxRuntime.jsxs(jsxRuntime.Fragment, {
157
+ children: [
158
+ /*#__PURE__*/ jsxRuntime.jsx("div", {
159
+ className: "gp-mb-4",
160
+ children: /*#__PURE__*/ jsxRuntime.jsx("span", {
161
+ className: "gp-text-xs",
162
+ children: "What would you like to describe here?"
163
+ })
164
+ }),
165
+ /*#__PURE__*/ jsxRuntime.jsx("div", {
166
+ className: "gp-mb-4 gp-flex",
167
+ children: /*#__PURE__*/ jsxRuntime.jsx("textarea", {
168
+ className: "gp-p-2 gp-bg-[#333333] gp-rounded-lg gp-w-full gp-text-xs gp-text-white placeholder:gp-text-[#AAAAAA] gp-resize-none focus-visible:gp-outline-none",
169
+ placeholder: "e.g: generate feature benefits",
170
+ rows: 4,
171
+ value: prompt,
172
+ onChange: onChangePrompt
173
+ })
174
+ }),
175
+ /*#__PURE__*/ jsxRuntime.jsxs("div", {
176
+ className: classNames({
177
+ 'gp-hidden': !isShowMore
178
+ }, 'gp-mb-4 gp-gap-4 gp-flex gp-flex-col'),
179
+ children: [
180
+ /*#__PURE__*/ jsxRuntime.jsx(ToneAndVoice.ToneAndVoice, {
181
+ changeToneAndVoice: changeTone
182
+ }),
183
+ /*#__PURE__*/ jsxRuntime.jsx(PickProduct.PickProduct, {
184
+ changeProductName: changeProductName,
185
+ openProductSetting: handleOpenProductSetting,
186
+ productId: productElement.productId
187
+ })
188
+ ]
189
+ }),
190
+ /*#__PURE__*/ jsxRuntime.jsx("div", {
191
+ children: /*#__PURE__*/ jsxRuntime.jsxs("button", {
192
+ className: "gp-flex gp-justify-center gp-items-center gp-w-full gp-bg-[#333333] gp-py-2 gp-rounded-lg gp-gap-2 gp-text-xs gp-font-medium",
193
+ onClick: toggleShowMore,
194
+ children: [
195
+ "Show more",
196
+ /*#__PURE__*/ jsxRuntime.jsx("span", {
197
+ className: classNames({
198
+ 'gp-rotate-180': isShowMore
199
+ }),
200
+ children: /*#__PURE__*/ jsxRuntime.jsx(ShowMoreIcon.ShowMoreIcon, {})
201
+ })
202
+ ]
203
+ })
204
+ })
205
+ ]
206
+ }) : /*#__PURE__*/ jsxRuntime.jsxs("div", {
207
+ className: "gp-flex gp-gap-2 gp-p-3 gp-rounded-xl gp-bg-[#FDB913] gp-bg-opacity-20",
208
+ children: [
209
+ /*#__PURE__*/ jsxRuntime.jsx("div", {
210
+ className: "gp-flex-none gp-w-7 gp-h-7 gp-rounded-lg gp-bg-[#FFB800] gp-flex gp-justify-center gp-items-center",
211
+ children: /*#__PURE__*/ jsxRuntime.jsx(WarningIcon.WarningIcon, {})
212
+ }),
213
+ /*#__PURE__*/ jsxRuntime.jsxs("p", {
214
+ className: "gp-text-xs gp-whitespace-normal",
215
+ children: [
216
+ "You've reached ",
217
+ generateLimitation?.maxGenerateCount,
218
+ "/",
219
+ generateLimitation?.maxGenerateCount,
220
+ " rewrites of your AI generative this month.",
221
+ /*#__PURE__*/ jsxRuntime.jsx("br", {}),
222
+ "Resets on ",
223
+ nextMonth,
224
+ "."
225
+ ]
226
+ })
227
+ ]
228
+ })
229
+ }),
230
+ /*#__PURE__*/ jsxRuntime.jsx("div", {
231
+ className: "gp-p-4",
232
+ ref: genButtonWrapper,
233
+ children: generateLimitation?.isAllow ? /*#__PURE__*/ jsxRuntime.jsx("button", {
234
+ className: "gp-rounded-lg gp-w-full gp-text-xs gp-font-medium gp-bg-gradient-to-tl gp-from-[#3C38E1] gp-to-[#874CFD] gp-py-2",
235
+ onClick: handleGenerateContent,
236
+ children: isGenerating ? 'Generating...' : 'Generate'
237
+ }) : /*#__PURE__*/ jsxRuntime.jsxs("button", {
238
+ className: "gp-flex gp-items-center gp-gap-2 gp-justify-center gp-rounded-lg gp-w-full gp-text-xs gp-font-medium gp-bg-gradient-to-tl gp-from-[#3C38E1] gp-to-[#874CFD] gp-py-2",
239
+ onClick: goToPricing,
240
+ children: [
241
+ /*#__PURE__*/ jsxRuntime.jsx(UpgradeIcon.UpgradeIcon, {}),
242
+ generateLimitation?.nextQuota ? `Upgrade to generate ${generateLimitation?.nextQuota} rewrites` : 'You have reached limit this month'
243
+ ]
244
+ })
245
+ })
246
+ ]
247
+ })
248
+ ]
249
+ });
250
+ };
251
+
252
+ exports.AIContentGenerator = AIContentGenerator;