@gem-sdk/core 1.41.0-dev.20 → 1.41.0-dev.26

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 (52) 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 +2 -0
  4. package/dist/cjs/components/RenderCustomCode.js +2 -0
  5. package/dist/cjs/components/ai-generator/AIContentGenerator.js +189 -0
  6. package/dist/cjs/components/ai-generator/AIGenContentLoading.js +57 -0
  7. package/dist/cjs/components/ai-generator/components/PickProduct.js +218 -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 +70 -0
  11. package/dist/cjs/components/ai-generator/hooks/useGettingGenerateRequest.js +37 -0
  12. package/dist/cjs/components/ai-generator/hooks/useListenEventGenerate.js +63 -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/constant.js +13 -0
  19. package/dist/cjs/components/resize/Spacing.js +2 -0
  20. package/dist/cjs/components/theme-section/CreateThemeSection.js +2 -0
  21. package/dist/cjs/helpers/queries/get-products.js +60 -2
  22. package/dist/cjs/hooks/shop/use-products-query.js +29 -0
  23. package/dist/cjs/hooks/useAnimations.js +2 -0
  24. package/dist/cjs/hooks/useInitialSwatchesOptions.js +2 -0
  25. package/dist/cjs/hooks/useProduct.js +2 -0
  26. package/dist/esm/components/ComponentToolbarPreview.js +10 -0
  27. package/dist/esm/components/ComponentWrapperPreview.js +1 -0
  28. package/dist/esm/components/Render.liquid.js +2 -0
  29. package/dist/esm/components/RenderCustomCode.js +2 -0
  30. package/dist/esm/components/ai-generator/AIContentGenerator.js +187 -0
  31. package/dist/esm/components/ai-generator/AIGenContentLoading.js +55 -0
  32. package/dist/esm/components/ai-generator/components/PickProduct.js +216 -0
  33. package/dist/esm/components/ai-generator/components/ToneAndVoice.js +75 -0
  34. package/dist/esm/components/ai-generator/hooks/useCheckingProductInside.js +45 -0
  35. package/dist/esm/components/ai-generator/hooks/useFlipPopup.js +68 -0
  36. package/dist/esm/components/ai-generator/hooks/useGettingGenerateRequest.js +35 -0
  37. package/dist/esm/components/ai-generator/hooks/useListenEventGenerate.js +61 -0
  38. package/dist/esm/components/ai-generator/icons/AIIcon.js +65 -0
  39. package/dist/esm/components/ai-generator/icons/CloseIcon.js +17 -0
  40. package/dist/esm/components/ai-generator/icons/DropdownIcon.js +34 -0
  41. package/dist/esm/components/ai-generator/icons/SearchIcon.js +19 -0
  42. package/dist/esm/components/ai-generator/icons/ShowMoreIcon.js +19 -0
  43. package/dist/esm/components/constant.js +13 -1
  44. package/dist/esm/components/resize/Spacing.js +2 -0
  45. package/dist/esm/components/theme-section/CreateThemeSection.js +2 -0
  46. package/dist/esm/helpers/queries/get-products.js +60 -3
  47. package/dist/esm/hooks/shop/use-products-query.js +30 -2
  48. package/dist/esm/hooks/useAnimations.js +2 -0
  49. package/dist/esm/hooks/useInitialSwatchesOptions.js +2 -0
  50. package/dist/esm/hooks/useProduct.js +2 -0
  51. package/dist/types/index.d.ts +2 -1
  52. package/package.json +3 -3
@@ -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,13 @@ 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');
17
19
  var composeAdvanceStyle = require('../helpers/compose-advance-style.js');
18
20
  var convert = require('../helpers/convert.js');
19
21
  var render = require('../helpers/render.js');
@@ -11,10 +11,12 @@ 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');
18
20
  require('../helpers/convert.js');
19
21
 
20
22
  const RenderCustomCode = ({ uid, advanced })=>{
@@ -0,0 +1,189 @@
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 PickProduct = require('./components/PickProduct.js');
9
+ var ToneAndVoice = require('./components/ToneAndVoice.js');
10
+ var classNames = require('classnames');
11
+ var useListenEventGenerate = require('./hooks/useListenEventGenerate.js');
12
+ var useGettingGenerateRequest = require('./hooks/useGettingGenerateRequest.js');
13
+ var useFlipPopup = require('./hooks/useFlipPopup.js');
14
+ var useCheckingProductInside = require('./hooks/useCheckingProductInside.js');
15
+
16
+ const AIContentGenerator = ({ ...props })=>{
17
+ const [isShowPopup, setIsShowPopup] = react.useState(false);
18
+ const [isShowMore, setIsShowMore] = react.useState(false);
19
+ const genTool = react.useRef(null);
20
+ const genPopup = react.useRef(null);
21
+ const { popupPositionX, popupPositionY, isValidating: isValidatingFlipPopup } = useFlipPopup.useFlipPopup(isShowPopup, {
22
+ genTool,
23
+ genPopup
24
+ });
25
+ const { isGenerating, onGenerate, onOpenProductElementSettings } = useListenEventGenerate.useListenEventGenerate({
26
+ uid: props.uid,
27
+ tag: String(props.tag)
28
+ });
29
+ const { getRequestBody, prompt, changeProductName, changePrompt, changeTone } = useGettingGenerateRequest.useGettingGenerateRequest();
30
+ const { productElement, checkSectionHasProduct } = useCheckingProductInside.useCheckingProductInside(genTool);
31
+ const togglePopup = ()=>{
32
+ setIsShowPopup(!isShowPopup);
33
+ };
34
+ const hidePopup = ()=>{
35
+ setIsShowPopup(false);
36
+ };
37
+ const onChangePrompt = (e)=>{
38
+ changePrompt(e.target.value);
39
+ };
40
+ const onActiveComponent = react.useCallback((e)=>{
41
+ const detail = e.detail;
42
+ if (detail?.componentUid !== props.uid) {
43
+ hidePopup();
44
+ return;
45
+ }
46
+ checkSectionHasProduct();
47
+ }, [
48
+ props.uid,
49
+ checkSectionHasProduct
50
+ ]);
51
+ const toggleShowMore = ()=>{
52
+ setIsShowMore(!isShowMore);
53
+ };
54
+ const handleGenerateContent = ()=>{
55
+ const body = getRequestBody();
56
+ onGenerate(body);
57
+ };
58
+ const handleOpenProductSetting = ()=>{
59
+ onOpenProductElementSettings(productElement.uid ?? '');
60
+ };
61
+ react.useEffect(()=>{
62
+ if (!isGenerating) {
63
+ hidePopup();
64
+ }
65
+ }, [
66
+ isGenerating
67
+ ]);
68
+ react.useEffect(()=>{
69
+ if (productElement.productId) {
70
+ setIsShowMore(false);
71
+ return;
72
+ }
73
+ setIsShowMore(true);
74
+ }, [
75
+ productElement
76
+ ]);
77
+ react.useEffect(()=>{
78
+ window.addEventListener('editor:active-component', onActiveComponent);
79
+ return ()=>{
80
+ window.removeEventListener('editor:active-component', onActiveComponent);
81
+ };
82
+ }, [
83
+ onActiveComponent
84
+ ]);
85
+ return /*#__PURE__*/ jsxRuntime.jsxs("div", {
86
+ className: "gp-relative",
87
+ ref: genTool,
88
+ children: [
89
+ /*#__PURE__*/ jsxRuntime.jsx("div", {
90
+ className: "gp-gen-content-toolbar gp-border-r-[#6a6a6a] gp-border-r gp-pr-1 gp-mr-1",
91
+ children: /*#__PURE__*/ jsxRuntime.jsxs("button", {
92
+ className: "gp-p-1 gp-text-xs gp-flex gp-gap-1 gp-items-center gp-rounded-md hover:gp-bg-[#3B3B3B] gp-font-medium",
93
+ onClick: togglePopup,
94
+ children: [
95
+ /*#__PURE__*/ jsxRuntime.jsx(AIIcon.AIIcon, {}),
96
+ "AI Content"
97
+ ]
98
+ })
99
+ }),
100
+ /*#__PURE__*/ jsxRuntime.jsxs("div", {
101
+ className: classNames({
102
+ 'gp-hidden': !isShowPopup,
103
+ 'gp-right-0': props.tag === 'Section' || popupPositionX === 'right',
104
+ 'gp-left-0': popupPositionX === 'left' && props.tag !== 'Section',
105
+ 'gp-top-8': popupPositionY === 'top',
106
+ 'gp-bottom-8': popupPositionY === 'bottom',
107
+ '!gp-visible': !isValidatingFlipPopup
108
+ }, 'gp-absolute gp-invisible gp-rounded-lg gp-bg-[#151515] gp-p-4 gp-w-[312px] !gp-max-w-[312px] !gp-cursor-default'),
109
+ ref: genPopup,
110
+ children: [
111
+ /*#__PURE__*/ jsxRuntime.jsxs("div", {
112
+ className: "gp-flex gp-items-center gp-justify-between gp-mb-4",
113
+ children: [
114
+ /*#__PURE__*/ jsxRuntime.jsx("span", {
115
+ className: "gp-font-medium gp-text-sm",
116
+ children: "Write with GemAI"
117
+ }),
118
+ /*#__PURE__*/ jsxRuntime.jsx("button", {
119
+ className: "gp-p-2 gp-cursor-pointer hover:gp-bg-[#3B3B3B] gp-rounded-md",
120
+ onClick: hidePopup,
121
+ children: /*#__PURE__*/ jsxRuntime.jsx(CloseIcon.CloseIcon, {})
122
+ })
123
+ ]
124
+ }),
125
+ /*#__PURE__*/ jsxRuntime.jsxs("div", {
126
+ className: "gp-mt-2 gp-text-left",
127
+ children: [
128
+ /*#__PURE__*/ jsxRuntime.jsx("div", {
129
+ className: "gp-mb-4",
130
+ children: /*#__PURE__*/ jsxRuntime.jsx("span", {
131
+ className: "gp-text-xs",
132
+ children: "What would you like to describe here?"
133
+ })
134
+ }),
135
+ /*#__PURE__*/ jsxRuntime.jsx("div", {
136
+ className: "gp-mb-4 gp-flex",
137
+ children: /*#__PURE__*/ jsxRuntime.jsx("textarea", {
138
+ 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",
139
+ placeholder: "e.g: Generate feature benefits",
140
+ rows: 4,
141
+ value: prompt,
142
+ onChange: onChangePrompt
143
+ })
144
+ }),
145
+ /*#__PURE__*/ jsxRuntime.jsxs("div", {
146
+ className: classNames({
147
+ 'gp-hidden': !isShowMore
148
+ }, 'gp-mb-4 gp-gap-4 gp-flex gp-flex-col'),
149
+ children: [
150
+ /*#__PURE__*/ jsxRuntime.jsx(ToneAndVoice.ToneAndVoice, {
151
+ changeToneAndVoice: changeTone
152
+ }),
153
+ /*#__PURE__*/ jsxRuntime.jsx(PickProduct.PickProduct, {
154
+ changeProductName: changeProductName,
155
+ openProductSetting: handleOpenProductSetting,
156
+ productId: productElement.productId
157
+ })
158
+ ]
159
+ }),
160
+ /*#__PURE__*/ jsxRuntime.jsx("div", {
161
+ className: "gp-mb-4",
162
+ children: /*#__PURE__*/ jsxRuntime.jsxs("button", {
163
+ 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",
164
+ onClick: toggleShowMore,
165
+ children: [
166
+ "Show more",
167
+ /*#__PURE__*/ jsxRuntime.jsx("span", {
168
+ className: classNames({
169
+ 'gp-rotate-180': isShowMore
170
+ }),
171
+ children: /*#__PURE__*/ jsxRuntime.jsx(ShowMoreIcon.ShowMoreIcon, {})
172
+ })
173
+ ]
174
+ })
175
+ }),
176
+ /*#__PURE__*/ jsxRuntime.jsx("button", {
177
+ 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",
178
+ onClick: handleGenerateContent,
179
+ children: isGenerating ? 'Generating...' : 'Generate'
180
+ })
181
+ ]
182
+ })
183
+ ]
184
+ })
185
+ ]
186
+ });
187
+ };
188
+
189
+ exports.AIContentGenerator = AIContentGenerator;
@@ -0,0 +1,57 @@
1
+ 'use strict';
2
+
3
+ var jsxRuntime = require('react/jsx-runtime');
4
+ var react = require('react');
5
+
6
+ const AIGenContentLoading = ({ ...props })=>{
7
+ const [isGenerating, setIsGenerating] = react.useState(false);
8
+ const [numDots, setNumDots] = react.useState(1);
9
+ const dotIncreaseInterval = react.useRef(null);
10
+ const onGenerateContentStatus = react.useCallback((e)=>{
11
+ const detail = e.detail;
12
+ if (detail?.generatingUid !== props.uid) {
13
+ return;
14
+ }
15
+ if (detail.status === 'loading') {
16
+ setIsGenerating(true);
17
+ return;
18
+ }
19
+ if (detail.status === 'success') {
20
+ setIsGenerating(false);
21
+ return;
22
+ }
23
+ }, [
24
+ props.uid
25
+ ]);
26
+ react.useEffect(()=>{
27
+ if (isGenerating) {
28
+ dotIncreaseInterval.current = setInterval(()=>{
29
+ setNumDots((prev)=>prev === 3 ? 1 : prev + 1);
30
+ }, 500);
31
+ return;
32
+ }
33
+ if (dotIncreaseInterval.current) clearInterval(dotIncreaseInterval.current);
34
+ }, [
35
+ isGenerating
36
+ ]);
37
+ react.useEffect(()=>{
38
+ window.addEventListener('editor:ai-generate-content-status', onGenerateContentStatus);
39
+ return ()=>{
40
+ window.removeEventListener('editor:ai-generate-content-status', onGenerateContentStatus);
41
+ };
42
+ }, [
43
+ onGenerateContentStatus
44
+ ]);
45
+ return isGenerating ? /*#__PURE__*/ jsxRuntime.jsx("div", {
46
+ 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",
47
+ children: /*#__PURE__*/ jsxRuntime.jsxs("span", {
48
+ className: "gp-font-medium",
49
+ children: [
50
+ "Generating",
51
+ Array.from(Array(numDots).keys()).map(()=>'.')
52
+ ]
53
+ })
54
+ }) : null;
55
+ };
56
+
57
+ exports.AIGenContentLoading = AIGenContentLoading;
@@ -0,0 +1,218 @@
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('../../../helpers/convert.js');
18
+
19
+ const PickProduct = (props)=>{
20
+ const LIMIT_PRODUCTS = 8;
21
+ const [productVariables, setProductVariables] = react.useState(!props.productId ? {
22
+ first: LIMIT_PRODUCTS
23
+ } : undefined);
24
+ const { data: productList, isLoading: isLoadingGetProducts, isValidating: isValidatingGetProducts, size: productsSize, setSize: setProductsSize } = useProductsQuery.useListProductQuery(productVariables, {
25
+ revalidateFirstPage: false
26
+ });
27
+ const { data: sectionProduct } = useProductQuery.useProductQuery(props.productId);
28
+ const [activeProduct, setActiveProduct] = react.useState();
29
+ const [isShowChooseProduct, setIsShowChooseProduct] = react.useState(false);
30
+ const debounceSearch = react.useRef(null);
31
+ const debounceScroll = react.useRef(null);
32
+ const toggleChooseProduct = ()=>{
33
+ if (props.productId) return;
34
+ setIsShowChooseProduct(!isShowChooseProduct);
35
+ };
36
+ const chooseProduct = (product)=>{
37
+ setActiveProduct(product);
38
+ setIsShowChooseProduct(false);
39
+ };
40
+ const searchProduct = (e)=>{
41
+ debounceSearch.current && clearTimeout(debounceSearch.current);
42
+ debounceSearch.current = setTimeout(()=>{
43
+ const searchValue = e.target.value ?? '';
44
+ if (searchValue) {
45
+ setProductVariables({
46
+ first: LIMIT_PRODUCTS,
47
+ where: {
48
+ titleContainsFold: searchValue
49
+ }
50
+ });
51
+ return;
52
+ }
53
+ setProductVariables({
54
+ first: LIMIT_PRODUCTS
55
+ });
56
+ }, 200);
57
+ };
58
+ const handleOpenProductElementSettings = ()=>{
59
+ props.openProductSetting();
60
+ };
61
+ const handleLoadMore = (e)=>{
62
+ const target = e.target;
63
+ if (target.scrollHeight - target.scrollTop === target.clientHeight) {
64
+ debounceScroll.current && clearTimeout(debounceScroll.current);
65
+ debounceScroll.current = setTimeout(()=>{
66
+ setProductsSize(productsSize + 1);
67
+ }, 50);
68
+ }
69
+ };
70
+ const products = react.useMemo(()=>{
71
+ return productList?.reduce((acc, curr)=>{
72
+ return [
73
+ ...acc,
74
+ ...curr.products?.edges ?? []
75
+ ];
76
+ }, []) ?? [];
77
+ }, [
78
+ productList
79
+ ]);
80
+ react.useEffect(()=>{
81
+ if (products.length && !activeProduct && !props.productId) {
82
+ const firstProduct = products[0]?.node;
83
+ if (!firstProduct) return;
84
+ setActiveProduct({
85
+ id: firstProduct?.id,
86
+ name: firstProduct?.title,
87
+ image: firstProduct.featuredImage?.src
88
+ });
89
+ }
90
+ }, [
91
+ products,
92
+ activeProduct,
93
+ props.productId
94
+ ]);
95
+ react.useEffect(()=>{
96
+ if (activeProduct && activeProduct.name) {
97
+ props.changeProductName(activeProduct.name);
98
+ }
99
+ }, [
100
+ activeProduct,
101
+ props
102
+ ]);
103
+ react.useEffect(()=>{
104
+ if (sectionProduct) {
105
+ setActiveProduct({
106
+ id: sectionProduct.id,
107
+ name: sectionProduct.title,
108
+ image: sectionProduct.featuredImage?.src
109
+ });
110
+ }
111
+ }, [
112
+ sectionProduct
113
+ ]);
114
+ return /*#__PURE__*/ jsxRuntime.jsxs("div", {
115
+ className: "gp-flex gp-flex-col gp-gap-2",
116
+ children: [
117
+ /*#__PURE__*/ jsxRuntime.jsx("p", {
118
+ className: "gp-py-2 gp-text-xs",
119
+ children: "Product"
120
+ }),
121
+ /*#__PURE__*/ jsxRuntime.jsxs("div", {
122
+ className: "gp-relative",
123
+ children: [
124
+ !isLoadingGetProducts || activeProduct ? /*#__PURE__*/ jsxRuntime.jsxs("button", {
125
+ className: classNames({
126
+ 'gp-cursor-default': props.productId
127
+ }, 'gp-flex gp-gap-2 gp-items-center gp-w-full gp-p-2 gp-rounded-lg gp-bg-[#333333] gp-text-xs'),
128
+ onClick: toggleChooseProduct,
129
+ children: [
130
+ /*#__PURE__*/ jsxRuntime.jsx("img", {
131
+ className: "gp-rounded-lg gp-w-10 gp-h-10",
132
+ src: activeProduct?.image,
133
+ alt: "product_image"
134
+ }),
135
+ /*#__PURE__*/ jsxRuntime.jsx("span", {
136
+ className: "gp-truncate gp-max-w-[210px]",
137
+ children: activeProduct?.name
138
+ })
139
+ ]
140
+ }) : /*#__PURE__*/ jsxRuntime.jsx("div", {
141
+ children: /*#__PURE__*/ jsxRuntime.jsx("span", {
142
+ className: "gp-text-xs",
143
+ children: "Getting products..."
144
+ })
145
+ }),
146
+ props.productId && /*#__PURE__*/ jsxRuntime.jsx("div", {
147
+ className: "gp-mt-2 gp-text-xs",
148
+ children: /*#__PURE__*/ jsxRuntime.jsxs("p", {
149
+ children: [
150
+ "You can manage it in",
151
+ ' ',
152
+ /*#__PURE__*/ jsxRuntime.jsx("button", {
153
+ className: "gp-text-[#8AA4FF] gp-cursor-pointer hover:gp-underline",
154
+ onClick: handleOpenProductElementSettings,
155
+ children: "Product element"
156
+ })
157
+ ]
158
+ })
159
+ }),
160
+ isShowChooseProduct && /*#__PURE__*/ jsxRuntime.jsxs("div", {
161
+ 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",
162
+ children: [
163
+ /*#__PURE__*/ jsxRuntime.jsxs("div", {
164
+ className: "gp-flex gp-items-center gp-gap-2 gp-p-2",
165
+ children: [
166
+ /*#__PURE__*/ jsxRuntime.jsx(SearchIcon.SearchIcon, {}),
167
+ /*#__PURE__*/ jsxRuntime.jsx("input", {
168
+ className: "gp-bg-transparent gp-w-full focus-visible:!gp-outline-none gp-text-xs",
169
+ placeholder: "Search product...",
170
+ onChange: searchProduct
171
+ })
172
+ ]
173
+ }),
174
+ /*#__PURE__*/ jsxRuntime.jsxs("div", {
175
+ className: "gp-max-h-[168px] gp-overflow-auto scrollbar:gp-w-1 scrollbar-thumb:gp-bg-[#999] scrollbar-thumb:gp-rounded-xl",
176
+ onScroll: handleLoadMore,
177
+ children: [
178
+ products?.map((item)=>{
179
+ return /*#__PURE__*/ jsxRuntime.jsxs("button", {
180
+ className: "gp-flex gp-p-2 hover:gp-bg-[#3B3B3B] gp-rounded-lg gp-cursor-pointer gp-gap-2 gp-items-center",
181
+ onClick: ()=>{
182
+ chooseProduct({
183
+ id: item.node?.id,
184
+ name: item.node?.title,
185
+ image: item.node?.featuredImage?.src
186
+ });
187
+ },
188
+ children: [
189
+ /*#__PURE__*/ jsxRuntime.jsx("img", {
190
+ className: "gp-rounded-lg gp-w-10 gp-h-10",
191
+ src: item.node?.featuredImage?.src,
192
+ alt: "product_image"
193
+ }),
194
+ /*#__PURE__*/ jsxRuntime.jsx("span", {
195
+ className: "gp-truncate gp-max-w-[210px] gp-text-xs",
196
+ children: item.node?.title
197
+ })
198
+ ]
199
+ }, item.node?.id);
200
+ }),
201
+ isLoadingGetProducts || isValidatingGetProducts && /*#__PURE__*/ jsxRuntime.jsx("div", {
202
+ className: "gp-p-2",
203
+ children: /*#__PURE__*/ jsxRuntime.jsx("span", {
204
+ className: "gp-text-xs",
205
+ children: "Getting products..."
206
+ })
207
+ })
208
+ ]
209
+ })
210
+ ]
211
+ })
212
+ ]
213
+ })
214
+ ]
215
+ });
216
+ };
217
+
218
+ exports.PickProduct = PickProduct;
@@ -0,0 +1,77 @@
1
+ 'use strict';
2
+
3
+ var jsxRuntime = require('react/jsx-runtime');
4
+ var react = require('react');
5
+ var DropdownIcon = require('../icons/DropdownIcon.js');
6
+ var classNames = require('classnames');
7
+
8
+ const ToneAndVoice = (props)=>{
9
+ const listToneAndVoice = [
10
+ 'Persuasive',
11
+ 'Friendly',
12
+ 'Professional',
13
+ 'Casual'
14
+ ];
15
+ const [tone, setTone] = react.useState(listToneAndVoice[0]);
16
+ const [isShow, setIsShow] = react.useState(false);
17
+ const toggle = ()=>{
18
+ setIsShow(!isShow);
19
+ };
20
+ const setValue = (value)=>{
21
+ setTone(value);
22
+ setIsShow(false);
23
+ };
24
+ react.useEffect(()=>{
25
+ tone && props.changeToneAndVoice(tone);
26
+ }, [
27
+ tone,
28
+ props
29
+ ]);
30
+ return /*#__PURE__*/ jsxRuntime.jsx("div", {
31
+ children: /*#__PURE__*/ jsxRuntime.jsxs("div", {
32
+ className: "gp-flex gp-flex-col gp-gap-2",
33
+ children: [
34
+ /*#__PURE__*/ jsxRuntime.jsx("p", {
35
+ className: "gp-py-2 gp-text-xs",
36
+ children: "Tone and Voice"
37
+ }),
38
+ /*#__PURE__*/ jsxRuntime.jsxs("div", {
39
+ className: "gp-relative",
40
+ children: [
41
+ /*#__PURE__*/ jsxRuntime.jsxs("button", {
42
+ className: "gp-flex gp-justify-between gp-items-center gp-w-full gp-p-2 gp-rounded-lg gp-bg-[#333333] gp-text-xs",
43
+ onClick: toggle,
44
+ children: [
45
+ tone,
46
+ /*#__PURE__*/ jsxRuntime.jsx(DropdownIcon.DropdownIcon, {})
47
+ ]
48
+ }),
49
+ isShow ? /*#__PURE__*/ jsxRuntime.jsx("div", {
50
+ className: "gp-absolute gp-w-full gp-top-10 gp-left-0 gp-rounded-lg gp-bg-[#333333] gp-p-2 gp-flex gp-flex-col gp-gap-2 gp-z-10",
51
+ children: listToneAndVoice.map((item)=>{
52
+ return /*#__PURE__*/ jsxRuntime.jsxs("button", {
53
+ className: "gp-flex gp-p-2 hover:gp-bg-[#3B3B3B] gp-rounded-lg gp-cursor-pointer gp-gap-3 gp-items-center",
54
+ onClick: ()=>setValue(item),
55
+ children: [
56
+ /*#__PURE__*/ jsxRuntime.jsx("div", {
57
+ className: classNames({
58
+ 'gp-invisible': tone !== item
59
+ }),
60
+ children: /*#__PURE__*/ jsxRuntime.jsx(DropdownIcon.TickIcon, {})
61
+ }),
62
+ /*#__PURE__*/ jsxRuntime.jsx("span", {
63
+ className: "gp-text-xs",
64
+ children: item
65
+ })
66
+ ]
67
+ }, item);
68
+ })
69
+ }) : null
70
+ ]
71
+ })
72
+ ]
73
+ })
74
+ });
75
+ };
76
+
77
+ exports.ToneAndVoice = ToneAndVoice;
@@ -0,0 +1,47 @@
1
+ 'use strict';
2
+
3
+ var react = require('react');
4
+
5
+ const useCheckingProductInside = (genTool, options)=>{
6
+ const [productElement, setProductElement] = react.useState({});
7
+ const checkSectionHasProduct = react.useCallback(()=>{
8
+ if (!genTool.current) {
9
+ setProductElement({
10
+ productId: '',
11
+ uid: ''
12
+ });
13
+ return;
14
+ }
15
+ const sectionEl = genTool.current?.closest('[data-component-tag="Section"]');
16
+ const productEl = sectionEl?.querySelector('[data-product-id]:not([data-product-id=""])');
17
+ const productId = productEl?.getAttribute('data-product-id');
18
+ const productElUid = productEl?.getAttribute('data-uid');
19
+ const productListOutSideProduct = productEl?.closest('[data-component-tag="ProductList"]');
20
+ if (productListOutSideProduct || !productId) {
21
+ setProductElement({
22
+ productId: '',
23
+ uid: ''
24
+ });
25
+ return;
26
+ }
27
+ setProductElement({
28
+ productId: productId ? 'gid://shopify/Product/' + productId : '',
29
+ uid: productElUid ?? ''
30
+ });
31
+ }, [
32
+ genTool
33
+ ]);
34
+ react.useEffect(()=>{
35
+ if (!options?.isEnabled) return;
36
+ checkSectionHasProduct();
37
+ }, [
38
+ options?.isEnabled,
39
+ checkSectionHasProduct
40
+ ]);
41
+ return {
42
+ productElement,
43
+ checkSectionHasProduct
44
+ };
45
+ };
46
+
47
+ exports.useCheckingProductInside = useCheckingProductInside;