@gem-sdk/core 1.43.0-staging.28 → 1.43.0-staging.29

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 (58) hide show
  1. package/dist/cjs/components/ComponentToolbarPreview.js +10 -0
  2. package/dist/cjs/components/ComponentWrapperPreview.js +1 -0
  3. package/dist/cjs/components/Render.liquid.js +3 -0
  4. package/dist/cjs/components/RenderCustomCode.js +3 -0
  5. package/dist/cjs/components/ai-generator/AIContentGenerator.js +252 -0
  6. package/dist/cjs/components/ai-generator/AIGenContentLoading.js +85 -0
  7. package/dist/cjs/components/ai-generator/components/PickProduct.js +219 -0
  8. package/dist/cjs/components/ai-generator/components/ToneAndVoice.js +77 -0
  9. package/dist/cjs/components/ai-generator/hooks/useCheckingProductInside.js +47 -0
  10. package/dist/cjs/components/ai-generator/hooks/useFlipPopup.js +110 -0
  11. package/dist/cjs/components/ai-generator/hooks/useGettingGenerateRequest.js +37 -0
  12. package/dist/cjs/components/ai-generator/hooks/useListenEventGenerate.js +70 -0
  13. package/dist/cjs/components/ai-generator/icons/AIIcon.js +67 -0
  14. package/dist/cjs/components/ai-generator/icons/CloseIcon.js +19 -0
  15. package/dist/cjs/components/ai-generator/icons/DropdownIcon.js +37 -0
  16. package/dist/cjs/components/ai-generator/icons/SearchIcon.js +21 -0
  17. package/dist/cjs/components/ai-generator/icons/ShowMoreIcon.js +21 -0
  18. package/dist/cjs/components/ai-generator/icons/UpgradeIcon.js +27 -0
  19. package/dist/cjs/components/ai-generator/icons/WarningIcon.js +31 -0
  20. package/dist/cjs/components/constant.js +13 -0
  21. package/dist/cjs/components/resize/Spacing.js +3 -0
  22. package/dist/cjs/components/theme-section/CreateThemeSection.js +3 -0
  23. package/dist/cjs/contexts/ShopContext.js +18 -0
  24. package/dist/cjs/helpers/queries/get-products.js +23 -0
  25. package/dist/cjs/hooks/shop/use-products-query.js +29 -0
  26. package/dist/cjs/hooks/useAnimations.js +3 -0
  27. package/dist/cjs/hooks/useInitialSwatchesOptions.js +3 -0
  28. package/dist/cjs/hooks/useProduct.js +3 -0
  29. package/dist/esm/components/ComponentToolbarPreview.js +10 -0
  30. package/dist/esm/components/ComponentWrapperPreview.js +1 -0
  31. package/dist/esm/components/Render.liquid.js +3 -0
  32. package/dist/esm/components/RenderCustomCode.js +3 -0
  33. package/dist/esm/components/ai-generator/AIContentGenerator.js +250 -0
  34. package/dist/esm/components/ai-generator/AIGenContentLoading.js +83 -0
  35. package/dist/esm/components/ai-generator/components/PickProduct.js +217 -0
  36. package/dist/esm/components/ai-generator/components/ToneAndVoice.js +75 -0
  37. package/dist/esm/components/ai-generator/hooks/useCheckingProductInside.js +45 -0
  38. package/dist/esm/components/ai-generator/hooks/useFlipPopup.js +108 -0
  39. package/dist/esm/components/ai-generator/hooks/useGettingGenerateRequest.js +35 -0
  40. package/dist/esm/components/ai-generator/hooks/useListenEventGenerate.js +68 -0
  41. package/dist/esm/components/ai-generator/icons/AIIcon.js +65 -0
  42. package/dist/esm/components/ai-generator/icons/CloseIcon.js +17 -0
  43. package/dist/esm/components/ai-generator/icons/DropdownIcon.js +34 -0
  44. package/dist/esm/components/ai-generator/icons/SearchIcon.js +19 -0
  45. package/dist/esm/components/ai-generator/icons/ShowMoreIcon.js +19 -0
  46. package/dist/esm/components/ai-generator/icons/UpgradeIcon.js +25 -0
  47. package/dist/esm/components/ai-generator/icons/WarningIcon.js +29 -0
  48. package/dist/esm/components/constant.js +13 -1
  49. package/dist/esm/components/resize/Spacing.js +3 -0
  50. package/dist/esm/components/theme-section/CreateThemeSection.js +3 -0
  51. package/dist/esm/contexts/ShopContext.js +19 -1
  52. package/dist/esm/helpers/queries/get-products.js +23 -1
  53. package/dist/esm/hooks/shop/use-products-query.js +30 -2
  54. package/dist/esm/hooks/useAnimations.js +3 -0
  55. package/dist/esm/hooks/useInitialSwatchesOptions.js +3 -0
  56. package/dist/esm/hooks/useProduct.js +3 -0
  57. package/dist/types/index.d.ts +5 -0
  58. package/package.json +5 -2
@@ -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;
@@ -420,6 +424,9 @@ const ComponentToolbarPreview = (props)=>{
420
424
  props.tag === 'Section' && !props.isThemeSection && isEnableCreateThemeSection() && !props.isShopifySection && getIndexSection() < SECTION_LIMIT && /*#__PURE__*/ jsxRuntime.jsx(CreateThemeSection.CreateThemeSection, {
421
425
  ...props
422
426
  }),
427
+ !props.isShopifySection && constant.ableGenerateContentElements.includes(props.tag) && /*#__PURE__*/ jsxRuntime.jsx(AIContentGenerator.AIContentGenerator, {
428
+ ...props
429
+ }),
423
430
  props.tag == 'Sticky' && /*#__PURE__*/ jsxRuntime.jsx("div", {
424
431
  "data-toolbar-zoom-out": true,
425
432
  onClick: (e)=>onZoomOut(e),
@@ -538,6 +545,9 @@ const ComponentToolbarPreview = (props)=>{
538
545
  })
539
546
  ]
540
547
  }),
548
+ constant.ableGenerateContentElements.includes(props.tag) && /*#__PURE__*/ jsxRuntime.jsx(AIGenContentLoading.AIGenContentLoading, {
549
+ ...props
550
+ }),
541
551
  /*#__PURE__*/ jsxRuntime.jsx(Resize.default, {
542
552
  ...props
543
553
  })
@@ -14,6 +14,7 @@ require('swr');
14
14
  require('@gem-sdk/adapter-shopify');
15
15
  require('swr/mutation');
16
16
  var shop = require('../hooks/shop.js');
17
+ require('swr/infinite');
17
18
  require('vanilla-lazyload');
18
19
  require('../hooks/useCartUI.js');
19
20
  var cls = require('../helpers/cls.js');
@@ -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;
@@ -0,0 +1,85 @@
1
+ 'use strict';
2
+
3
+ var jsxRuntime = require('react/jsx-runtime');
4
+ var react = require('react');
5
+ var AIIcon = require('./icons/AIIcon.js');
6
+
7
+ function getRandomArbitrary(min, max) {
8
+ const randomNum = Math.random();
9
+ return randomNum * (max - min) + min;
10
+ }
11
+ const AIGenContentLoading = ({ ...props })=>{
12
+ const [isGenerating, setIsGenerating] = react.useState(false);
13
+ const [time, setTime] = react.useState(0);
14
+ const interval = react.useRef(null);
15
+ const onGenerateContentStatus = react.useCallback((e)=>{
16
+ const detail = e.detail;
17
+ if (detail?.generatingUid !== props.uid) {
18
+ return;
19
+ }
20
+ if (detail.status === 'loading') {
21
+ setIsGenerating(true);
22
+ return;
23
+ }
24
+ if (detail.status === 'success') {
25
+ setIsGenerating(false);
26
+ return;
27
+ }
28
+ }, [
29
+ props.uid
30
+ ]);
31
+ react.useEffect(()=>{
32
+ if (isGenerating) {
33
+ handleFakeLoading();
34
+ } else {
35
+ setTime(0);
36
+ }
37
+ return ()=>{
38
+ interval.current && clearInterval(interval.current);
39
+ };
40
+ }, [
41
+ isGenerating
42
+ ]);
43
+ const handleFakeLoading = ()=>{
44
+ setTime(0);
45
+ interval.current = setInterval(()=>{
46
+ setTime((time)=>{
47
+ const randomNum = getRandomArbitrary(0, 6);
48
+ return time >= 580 ? time : time + randomNum;
49
+ });
50
+ }, 50);
51
+ };
52
+ react.useEffect(()=>{
53
+ window.addEventListener('editor:ai-generate-content-status', onGenerateContentStatus);
54
+ return ()=>{
55
+ window.removeEventListener('editor:ai-generate-content-status', onGenerateContentStatus);
56
+ };
57
+ }, [
58
+ onGenerateContentStatus
59
+ ]);
60
+ return isGenerating ? /*#__PURE__*/ jsxRuntime.jsxs("div", {
61
+ className: "gp-absolute gp-top-0 gp-left-0 gp-w-full gp-h-full gp-bg-white gp-bg-opacity-70 gp-flex gp-justify-center gp-items-center gp-z-100 gp-gap-2",
62
+ children: [
63
+ /*#__PURE__*/ jsxRuntime.jsx("div", {
64
+ className: "gp-absolute gp-left-0 gp-top-0 gp-z-2 gp-flex gp-h-full gp-w-full",
65
+ children: /*#__PURE__*/ jsxRuntime.jsxs("div", {
66
+ className: `gp-relative gp-h-[2px] gp-w-full gp-overflow-hidden gp-rounded-md`,
67
+ children: [
68
+ /*#__PURE__*/ jsxRuntime.jsx("div", {
69
+ className: "gp-absolute gp-h-full gp-w-full gp-rounded-md gp-bg-[#F4F4F4]"
70
+ }),
71
+ /*#__PURE__*/ jsxRuntime.jsx("div", {
72
+ className: "gps-image-to-layout-progress-bar gp-absolute gp-h-full gp-rounded-md gp-transition-all",
73
+ style: {
74
+ width: `${time / 600 * 100}%`
75
+ }
76
+ })
77
+ ]
78
+ })
79
+ }),
80
+ /*#__PURE__*/ jsxRuntime.jsx(AIIcon.AIIcon, {})
81
+ ]
82
+ }) : null;
83
+ };
84
+
85
+ exports.AIGenContentLoading = AIGenContentLoading;
@@ -0,0 +1,219 @@
1
+ 'use strict';
2
+
3
+ var jsxRuntime = require('react/jsx-runtime');
4
+ var react = require('react');
5
+ var SearchIcon = require('../icons/SearchIcon.js');
6
+ var useProductsQuery = require('../../../hooks/shop/use-products-query.js');
7
+ var classNames = require('classnames');
8
+ require('zustand');
9
+ require('swr');
10
+ require('@gem-sdk/adapter-shopify');
11
+ require('swr/mutation');
12
+ var useProductQuery = require('../../../hooks/shop/use-product-query.js');
13
+ require('vanilla-lazyload');
14
+ require('../../../hooks/useCartUI.js');
15
+ require('react-transition-group');
16
+ require('@gem-sdk/core');
17
+ require('dayjs');
18
+ require('../../../helpers/convert.js');
19
+
20
+ const PickProduct = (props)=>{
21
+ const LIMIT_PRODUCTS = 8;
22
+ const [productVariables, setProductVariables] = react.useState(!props.productId ? {
23
+ first: LIMIT_PRODUCTS
24
+ } : undefined);
25
+ const { data: productList, isLoading: isLoadingGetProducts, isValidating: isValidatingGetProducts, size: productsSize, setSize: setProductsSize } = useProductsQuery.useListProductQuery(productVariables, {
26
+ revalidateFirstPage: false
27
+ });
28
+ const { data: sectionProduct } = useProductQuery.useProductQuery(props.productId);
29
+ const [activeProduct, setActiveProduct] = react.useState();
30
+ const [isShowChooseProduct, setIsShowChooseProduct] = react.useState(false);
31
+ const debounceSearch = react.useRef(null);
32
+ const debounceScroll = react.useRef(null);
33
+ const toggleChooseProduct = ()=>{
34
+ if (props.productId) return;
35
+ setIsShowChooseProduct(!isShowChooseProduct);
36
+ };
37
+ const chooseProduct = (product)=>{
38
+ setActiveProduct(product);
39
+ setIsShowChooseProduct(false);
40
+ };
41
+ const searchProduct = (e)=>{
42
+ debounceSearch.current && clearTimeout(debounceSearch.current);
43
+ debounceSearch.current = setTimeout(()=>{
44
+ const searchValue = e.target.value ?? '';
45
+ if (searchValue) {
46
+ setProductVariables({
47
+ first: LIMIT_PRODUCTS,
48
+ where: {
49
+ titleContainsFold: searchValue
50
+ }
51
+ });
52
+ return;
53
+ }
54
+ setProductVariables({
55
+ first: LIMIT_PRODUCTS
56
+ });
57
+ }, 200);
58
+ };
59
+ const handleOpenProductElementSettings = ()=>{
60
+ props.openProductSetting();
61
+ };
62
+ const handleLoadMore = (e)=>{
63
+ const target = e.target;
64
+ if (target.scrollHeight - target.scrollTop === target.clientHeight) {
65
+ debounceScroll.current && clearTimeout(debounceScroll.current);
66
+ debounceScroll.current = setTimeout(()=>{
67
+ setProductsSize(productsSize + 1);
68
+ }, 50);
69
+ }
70
+ };
71
+ const products = react.useMemo(()=>{
72
+ return productList?.reduce((acc, curr)=>{
73
+ return [
74
+ ...acc,
75
+ ...curr.products?.edges ?? []
76
+ ];
77
+ }, []) ?? [];
78
+ }, [
79
+ productList
80
+ ]);
81
+ react.useEffect(()=>{
82
+ if (products.length && !activeProduct && !props.productId) {
83
+ const firstProduct = products[0]?.node;
84
+ if (!firstProduct) return;
85
+ setActiveProduct({
86
+ id: firstProduct?.id,
87
+ name: firstProduct?.title,
88
+ image: firstProduct.featuredImage?.src
89
+ });
90
+ }
91
+ }, [
92
+ products,
93
+ activeProduct,
94
+ props.productId
95
+ ]);
96
+ react.useEffect(()=>{
97
+ if (activeProduct && activeProduct.name) {
98
+ props.changeProductName(activeProduct.name);
99
+ }
100
+ }, [
101
+ activeProduct,
102
+ props
103
+ ]);
104
+ react.useEffect(()=>{
105
+ if (sectionProduct) {
106
+ setActiveProduct({
107
+ id: sectionProduct.id,
108
+ name: sectionProduct.title,
109
+ image: sectionProduct.featuredImage?.src
110
+ });
111
+ }
112
+ }, [
113
+ sectionProduct
114
+ ]);
115
+ return /*#__PURE__*/ jsxRuntime.jsxs("div", {
116
+ className: "gp-flex gp-flex-col gp-gap-2",
117
+ children: [
118
+ /*#__PURE__*/ jsxRuntime.jsx("p", {
119
+ className: "gp-py-2 gp-text-xs",
120
+ children: "Product"
121
+ }),
122
+ /*#__PURE__*/ jsxRuntime.jsxs("div", {
123
+ className: "gp-relative",
124
+ children: [
125
+ !isLoadingGetProducts || activeProduct ? /*#__PURE__*/ jsxRuntime.jsxs("button", {
126
+ className: classNames({
127
+ 'gp-cursor-default': props.productId
128
+ }, 'gp-flex gp-gap-2 gp-items-center gp-w-full gp-p-2 gp-rounded-lg gp-bg-[#333333] gp-text-xs'),
129
+ onClick: toggleChooseProduct,
130
+ children: [
131
+ /*#__PURE__*/ jsxRuntime.jsx("img", {
132
+ className: "gp-rounded-lg gp-w-10 gp-h-10",
133
+ src: activeProduct?.image,
134
+ alt: "product_image"
135
+ }),
136
+ /*#__PURE__*/ jsxRuntime.jsx("span", {
137
+ className: "gp-truncate gp-max-w-[210px]",
138
+ children: activeProduct?.name
139
+ })
140
+ ]
141
+ }) : /*#__PURE__*/ jsxRuntime.jsx("div", {
142
+ children: /*#__PURE__*/ jsxRuntime.jsx("span", {
143
+ className: "gp-text-xs",
144
+ children: "Getting products..."
145
+ })
146
+ }),
147
+ props.productId && /*#__PURE__*/ jsxRuntime.jsx("div", {
148
+ className: "gp-mt-2 gp-text-xs",
149
+ children: /*#__PURE__*/ jsxRuntime.jsxs("p", {
150
+ children: [
151
+ "You can manage it in",
152
+ ' ',
153
+ /*#__PURE__*/ jsxRuntime.jsx("button", {
154
+ className: "gp-text-[#8AA4FF] gp-cursor-pointer hover:gp-underline",
155
+ onClick: handleOpenProductElementSettings,
156
+ children: "Product element"
157
+ })
158
+ ]
159
+ })
160
+ }),
161
+ isShowChooseProduct && /*#__PURE__*/ jsxRuntime.jsxs("div", {
162
+ className: "gp-absolute gp-w-full gp-top-16 gp-left-0 gp-rounded-lg gp-bg-[#333333] gp-p-2 gp-flex gp-flex-col gp-gap-2 gp-z-10",
163
+ children: [
164
+ /*#__PURE__*/ jsxRuntime.jsxs("div", {
165
+ className: "gp-flex gp-items-center gp-gap-2 gp-p-2",
166
+ children: [
167
+ /*#__PURE__*/ jsxRuntime.jsx(SearchIcon.SearchIcon, {}),
168
+ /*#__PURE__*/ jsxRuntime.jsx("input", {
169
+ className: "gp-bg-transparent gp-w-full focus-visible:!gp-outline-none gp-text-xs",
170
+ placeholder: "Search product...",
171
+ onChange: searchProduct
172
+ })
173
+ ]
174
+ }),
175
+ /*#__PURE__*/ jsxRuntime.jsxs("div", {
176
+ className: "gp-max-h-[168px] gp-overflow-auto scrollbar:gp-w-1 scrollbar-thumb:gp-bg-[#999] scrollbar-thumb:gp-rounded-xl",
177
+ onScroll: handleLoadMore,
178
+ children: [
179
+ products?.map((item)=>{
180
+ return /*#__PURE__*/ jsxRuntime.jsxs("button", {
181
+ className: "gp-flex gp-p-2 hover:gp-bg-[#3B3B3B] gp-rounded-lg gp-cursor-pointer gp-gap-2 gp-items-center",
182
+ onClick: ()=>{
183
+ chooseProduct({
184
+ id: item.node?.id,
185
+ name: item.node?.title,
186
+ image: item.node?.featuredImage?.src
187
+ });
188
+ },
189
+ children: [
190
+ /*#__PURE__*/ jsxRuntime.jsx("img", {
191
+ className: "gp-rounded-lg gp-w-10 gp-h-10",
192
+ src: item.node?.featuredImage?.src,
193
+ alt: "product_image"
194
+ }),
195
+ /*#__PURE__*/ jsxRuntime.jsx("span", {
196
+ className: "gp-truncate gp-max-w-[210px] gp-text-xs",
197
+ children: item.node?.title
198
+ })
199
+ ]
200
+ }, item.node?.id);
201
+ }),
202
+ isLoadingGetProducts || isValidatingGetProducts && /*#__PURE__*/ jsxRuntime.jsx("div", {
203
+ className: "gp-p-2",
204
+ children: /*#__PURE__*/ jsxRuntime.jsx("span", {
205
+ className: "gp-text-xs",
206
+ children: "Getting products..."
207
+ })
208
+ })
209
+ ]
210
+ })
211
+ ]
212
+ })
213
+ ]
214
+ })
215
+ ]
216
+ });
217
+ };
218
+
219
+ exports.PickProduct = PickProduct;