@gem-sdk/core 1.42.0 → 1.42.3-dev.63

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 (72) hide show
  1. package/dist/cjs/components/ComponentToolbarPreview.js +54 -6
  2. package/dist/cjs/components/ComponentWrapperPreview.js +44 -1
  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 +205 -0
  6. package/dist/cjs/components/ai-generator/AIGenContentLoading.js +85 -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 +110 -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 +19 -2
  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/contexts/ArticleContext.js +39 -0
  22. package/dist/cjs/contexts/ArticleListContext.js +32 -0
  23. package/dist/cjs/contexts/BuilderPreviewContext.js +11 -6
  24. package/dist/cjs/contexts/SectionContext.js +1 -0
  25. package/dist/cjs/helpers/align.js +19 -0
  26. package/dist/cjs/helpers/carousel.js +7 -10
  27. package/dist/cjs/helpers/colors.js +1 -1
  28. package/dist/cjs/helpers/queries/get-products.js +23 -0
  29. package/dist/cjs/helpers/typography.js +4 -4
  30. package/dist/cjs/hooks/articles/useArticlesQuery.js +152 -0
  31. package/dist/cjs/hooks/shop/use-products-query.js +29 -0
  32. package/dist/cjs/hooks/useAnimations.js +2 -0
  33. package/dist/cjs/hooks/useInitialSwatchesOptions.js +2 -0
  34. package/dist/cjs/hooks/useProduct.js +2 -0
  35. package/dist/cjs/index.js +11 -0
  36. package/dist/esm/components/ComponentToolbarPreview.js +54 -6
  37. package/dist/esm/components/ComponentWrapperPreview.js +44 -1
  38. package/dist/esm/components/Render.liquid.js +2 -0
  39. package/dist/esm/components/RenderCustomCode.js +2 -0
  40. package/dist/esm/components/ai-generator/AIContentGenerator.js +203 -0
  41. package/dist/esm/components/ai-generator/AIGenContentLoading.js +83 -0
  42. package/dist/esm/components/ai-generator/components/PickProduct.js +216 -0
  43. package/dist/esm/components/ai-generator/components/ToneAndVoice.js +75 -0
  44. package/dist/esm/components/ai-generator/hooks/useCheckingProductInside.js +45 -0
  45. package/dist/esm/components/ai-generator/hooks/useFlipPopup.js +108 -0
  46. package/dist/esm/components/ai-generator/hooks/useGettingGenerateRequest.js +35 -0
  47. package/dist/esm/components/ai-generator/hooks/useListenEventGenerate.js +61 -0
  48. package/dist/esm/components/ai-generator/icons/AIIcon.js +65 -0
  49. package/dist/esm/components/ai-generator/icons/CloseIcon.js +17 -0
  50. package/dist/esm/components/ai-generator/icons/DropdownIcon.js +34 -0
  51. package/dist/esm/components/ai-generator/icons/SearchIcon.js +19 -0
  52. package/dist/esm/components/ai-generator/icons/ShowMoreIcon.js +19 -0
  53. package/dist/esm/components/constant.js +19 -3
  54. package/dist/esm/components/resize/Spacing.js +2 -0
  55. package/dist/esm/components/theme-section/CreateThemeSection.js +2 -0
  56. package/dist/esm/contexts/ArticleContext.js +36 -0
  57. package/dist/esm/contexts/ArticleListContext.js +28 -0
  58. package/dist/esm/contexts/BuilderPreviewContext.js +11 -6
  59. package/dist/esm/contexts/SectionContext.js +1 -0
  60. package/dist/esm/helpers/align.js +17 -0
  61. package/dist/esm/helpers/carousel.js +7 -10
  62. package/dist/esm/helpers/colors.js +1 -1
  63. package/dist/esm/helpers/queries/get-products.js +23 -1
  64. package/dist/esm/helpers/typography.js +4 -4
  65. package/dist/esm/hooks/articles/useArticlesQuery.js +149 -0
  66. package/dist/esm/hooks/shop/use-products-query.js +30 -2
  67. package/dist/esm/hooks/useAnimations.js +2 -0
  68. package/dist/esm/hooks/useInitialSwatchesOptions.js +2 -0
  69. package/dist/esm/hooks/useProduct.js +2 -0
  70. package/dist/esm/index.js +4 -0
  71. package/dist/types/index.d.ts +161 -20
  72. package/package.json +5 -3
@@ -0,0 +1,216 @@
1
+ import { jsxs, jsx } from 'react/jsx-runtime';
2
+ import { useState, useRef, useMemo, useEffect } from 'react';
3
+ import { SearchIcon } from '../icons/SearchIcon.js';
4
+ import { useListProductQuery } from '../../../hooks/shop/use-products-query.js';
5
+ import classNames from 'classnames';
6
+ import 'zustand';
7
+ import 'swr';
8
+ import '@gem-sdk/adapter-shopify';
9
+ import 'swr/mutation';
10
+ import { useProductQuery } from '../../../hooks/shop/use-product-query.js';
11
+ import 'vanilla-lazyload';
12
+ import '../../../hooks/useCartUI.js';
13
+ import 'react-transition-group';
14
+ import '@gem-sdk/core';
15
+ import '../../../helpers/convert.js';
16
+
17
+ const PickProduct = (props)=>{
18
+ const LIMIT_PRODUCTS = 8;
19
+ const [productVariables, setProductVariables] = useState(!props.productId ? {
20
+ first: LIMIT_PRODUCTS
21
+ } : undefined);
22
+ const { data: productList, isLoading: isLoadingGetProducts, isValidating: isValidatingGetProducts, size: productsSize, setSize: setProductsSize } = useListProductQuery(productVariables, {
23
+ revalidateFirstPage: false
24
+ });
25
+ const { data: sectionProduct } = useProductQuery(props.productId);
26
+ const [activeProduct, setActiveProduct] = useState();
27
+ const [isShowChooseProduct, setIsShowChooseProduct] = useState(false);
28
+ const debounceSearch = useRef(null);
29
+ const debounceScroll = useRef(null);
30
+ const toggleChooseProduct = ()=>{
31
+ if (props.productId) return;
32
+ setIsShowChooseProduct(!isShowChooseProduct);
33
+ };
34
+ const chooseProduct = (product)=>{
35
+ setActiveProduct(product);
36
+ setIsShowChooseProduct(false);
37
+ };
38
+ const searchProduct = (e)=>{
39
+ debounceSearch.current && clearTimeout(debounceSearch.current);
40
+ debounceSearch.current = setTimeout(()=>{
41
+ const searchValue = e.target.value ?? '';
42
+ if (searchValue) {
43
+ setProductVariables({
44
+ first: LIMIT_PRODUCTS,
45
+ where: {
46
+ titleContainsFold: searchValue
47
+ }
48
+ });
49
+ return;
50
+ }
51
+ setProductVariables({
52
+ first: LIMIT_PRODUCTS
53
+ });
54
+ }, 200);
55
+ };
56
+ const handleOpenProductElementSettings = ()=>{
57
+ props.openProductSetting();
58
+ };
59
+ const handleLoadMore = (e)=>{
60
+ const target = e.target;
61
+ if (target.scrollHeight - target.scrollTop === target.clientHeight) {
62
+ debounceScroll.current && clearTimeout(debounceScroll.current);
63
+ debounceScroll.current = setTimeout(()=>{
64
+ setProductsSize(productsSize + 1);
65
+ }, 50);
66
+ }
67
+ };
68
+ const products = useMemo(()=>{
69
+ return productList?.reduce((acc, curr)=>{
70
+ return [
71
+ ...acc,
72
+ ...curr.products?.edges ?? []
73
+ ];
74
+ }, []) ?? [];
75
+ }, [
76
+ productList
77
+ ]);
78
+ useEffect(()=>{
79
+ if (products.length && !activeProduct && !props.productId) {
80
+ const firstProduct = products[0]?.node;
81
+ if (!firstProduct) return;
82
+ setActiveProduct({
83
+ id: firstProduct?.id,
84
+ name: firstProduct?.title,
85
+ image: firstProduct.featuredImage?.src
86
+ });
87
+ }
88
+ }, [
89
+ products,
90
+ activeProduct,
91
+ props.productId
92
+ ]);
93
+ useEffect(()=>{
94
+ if (activeProduct && activeProduct.name) {
95
+ props.changeProductName(activeProduct.name);
96
+ }
97
+ }, [
98
+ activeProduct,
99
+ props
100
+ ]);
101
+ useEffect(()=>{
102
+ if (sectionProduct) {
103
+ setActiveProduct({
104
+ id: sectionProduct.id,
105
+ name: sectionProduct.title,
106
+ image: sectionProduct.featuredImage?.src
107
+ });
108
+ }
109
+ }, [
110
+ sectionProduct
111
+ ]);
112
+ return /*#__PURE__*/ jsxs("div", {
113
+ className: "gp-flex gp-flex-col gp-gap-2",
114
+ children: [
115
+ /*#__PURE__*/ jsx("p", {
116
+ className: "gp-py-2 gp-text-xs",
117
+ children: "Product"
118
+ }),
119
+ /*#__PURE__*/ jsxs("div", {
120
+ className: "gp-relative",
121
+ children: [
122
+ !isLoadingGetProducts || activeProduct ? /*#__PURE__*/ jsxs("button", {
123
+ className: classNames({
124
+ 'gp-cursor-default': props.productId
125
+ }, 'gp-flex gp-gap-2 gp-items-center gp-w-full gp-p-2 gp-rounded-lg gp-bg-[#333333] gp-text-xs'),
126
+ onClick: toggleChooseProduct,
127
+ children: [
128
+ /*#__PURE__*/ jsx("img", {
129
+ className: "gp-rounded-lg gp-w-10 gp-h-10",
130
+ src: activeProduct?.image,
131
+ alt: "product_image"
132
+ }),
133
+ /*#__PURE__*/ jsx("span", {
134
+ className: "gp-truncate gp-max-w-[210px]",
135
+ children: activeProduct?.name
136
+ })
137
+ ]
138
+ }) : /*#__PURE__*/ jsx("div", {
139
+ children: /*#__PURE__*/ jsx("span", {
140
+ className: "gp-text-xs",
141
+ children: "Getting products..."
142
+ })
143
+ }),
144
+ props.productId && /*#__PURE__*/ jsx("div", {
145
+ className: "gp-mt-2 gp-text-xs",
146
+ children: /*#__PURE__*/ jsxs("p", {
147
+ children: [
148
+ "You can manage it in",
149
+ ' ',
150
+ /*#__PURE__*/ jsx("button", {
151
+ className: "gp-text-[#8AA4FF] gp-cursor-pointer hover:gp-underline",
152
+ onClick: handleOpenProductElementSettings,
153
+ children: "Product element"
154
+ })
155
+ ]
156
+ })
157
+ }),
158
+ isShowChooseProduct && /*#__PURE__*/ jsxs("div", {
159
+ 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",
160
+ children: [
161
+ /*#__PURE__*/ jsxs("div", {
162
+ className: "gp-flex gp-items-center gp-gap-2 gp-p-2",
163
+ children: [
164
+ /*#__PURE__*/ jsx(SearchIcon, {}),
165
+ /*#__PURE__*/ jsx("input", {
166
+ className: "gp-bg-transparent gp-w-full focus-visible:!gp-outline-none gp-text-xs",
167
+ placeholder: "Search product...",
168
+ onChange: searchProduct
169
+ })
170
+ ]
171
+ }),
172
+ /*#__PURE__*/ jsxs("div", {
173
+ className: "gp-max-h-[168px] gp-overflow-auto scrollbar:gp-w-1 scrollbar-thumb:gp-bg-[#999] scrollbar-thumb:gp-rounded-xl",
174
+ onScroll: handleLoadMore,
175
+ children: [
176
+ products?.map((item)=>{
177
+ return /*#__PURE__*/ jsxs("button", {
178
+ className: "gp-flex gp-p-2 hover:gp-bg-[#3B3B3B] gp-rounded-lg gp-cursor-pointer gp-gap-2 gp-items-center",
179
+ onClick: ()=>{
180
+ chooseProduct({
181
+ id: item.node?.id,
182
+ name: item.node?.title,
183
+ image: item.node?.featuredImage?.src
184
+ });
185
+ },
186
+ children: [
187
+ /*#__PURE__*/ jsx("img", {
188
+ className: "gp-rounded-lg gp-w-10 gp-h-10",
189
+ src: item.node?.featuredImage?.src,
190
+ alt: "product_image"
191
+ }),
192
+ /*#__PURE__*/ jsx("span", {
193
+ className: "gp-truncate gp-max-w-[210px] gp-text-xs",
194
+ children: item.node?.title
195
+ })
196
+ ]
197
+ }, item.node?.id);
198
+ }),
199
+ isLoadingGetProducts || isValidatingGetProducts && /*#__PURE__*/ jsx("div", {
200
+ className: "gp-p-2",
201
+ children: /*#__PURE__*/ jsx("span", {
202
+ className: "gp-text-xs",
203
+ children: "Getting products..."
204
+ })
205
+ })
206
+ ]
207
+ })
208
+ ]
209
+ })
210
+ ]
211
+ })
212
+ ]
213
+ });
214
+ };
215
+
216
+ export { PickProduct };
@@ -0,0 +1,75 @@
1
+ import { jsx, jsxs } from 'react/jsx-runtime';
2
+ import { useState, useEffect } from 'react';
3
+ import { DropdownIcon, TickIcon } from '../icons/DropdownIcon.js';
4
+ import classNames from 'classnames';
5
+
6
+ const ToneAndVoice = (props)=>{
7
+ const listToneAndVoice = [
8
+ 'Persuasive',
9
+ 'Friendly',
10
+ 'Professional',
11
+ 'Casual'
12
+ ];
13
+ const [tone, setTone] = useState(listToneAndVoice[0]);
14
+ const [isShow, setIsShow] = useState(false);
15
+ const toggle = ()=>{
16
+ setIsShow(!isShow);
17
+ };
18
+ const setValue = (value)=>{
19
+ setTone(value);
20
+ setIsShow(false);
21
+ };
22
+ useEffect(()=>{
23
+ tone && props.changeToneAndVoice(tone);
24
+ }, [
25
+ tone,
26
+ props
27
+ ]);
28
+ return /*#__PURE__*/ jsx("div", {
29
+ children: /*#__PURE__*/ jsxs("div", {
30
+ className: "gp-flex gp-flex-col gp-gap-2",
31
+ children: [
32
+ /*#__PURE__*/ jsx("p", {
33
+ className: "gp-py-2 gp-text-xs",
34
+ children: "Tone and Voice"
35
+ }),
36
+ /*#__PURE__*/ jsxs("div", {
37
+ className: "gp-relative",
38
+ children: [
39
+ /*#__PURE__*/ jsxs("button", {
40
+ className: "gp-flex gp-justify-between gp-items-center gp-w-full gp-p-2 gp-rounded-lg gp-bg-[#333333] gp-text-xs",
41
+ onClick: toggle,
42
+ children: [
43
+ tone,
44
+ /*#__PURE__*/ jsx(DropdownIcon, {})
45
+ ]
46
+ }),
47
+ isShow ? /*#__PURE__*/ jsx("div", {
48
+ 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",
49
+ children: listToneAndVoice.map((item)=>{
50
+ return /*#__PURE__*/ jsxs("button", {
51
+ className: "gp-flex gp-p-2 hover:gp-bg-[#3B3B3B] gp-rounded-lg gp-cursor-pointer gp-gap-3 gp-items-center",
52
+ onClick: ()=>setValue(item),
53
+ children: [
54
+ /*#__PURE__*/ jsx("div", {
55
+ className: classNames({
56
+ 'gp-invisible': tone !== item
57
+ }),
58
+ children: /*#__PURE__*/ jsx(TickIcon, {})
59
+ }),
60
+ /*#__PURE__*/ jsx("span", {
61
+ className: "gp-text-xs",
62
+ children: item
63
+ })
64
+ ]
65
+ }, item);
66
+ })
67
+ }) : null
68
+ ]
69
+ })
70
+ ]
71
+ })
72
+ });
73
+ };
74
+
75
+ export { ToneAndVoice };
@@ -0,0 +1,45 @@
1
+ import { useState, useCallback, useEffect } from 'react';
2
+
3
+ const useCheckingProductInside = (genTool, options)=>{
4
+ const [productElement, setProductElement] = useState({});
5
+ const checkSectionHasProduct = useCallback(()=>{
6
+ if (!genTool.current) {
7
+ setProductElement({
8
+ productId: '',
9
+ uid: ''
10
+ });
11
+ return;
12
+ }
13
+ const sectionEl = genTool.current?.closest('[data-component-tag="Section"]');
14
+ const productEl = sectionEl?.querySelector('[data-product-id]:not([data-product-id=""])');
15
+ const productId = productEl?.getAttribute('data-product-id');
16
+ const productElUid = productEl?.getAttribute('data-uid');
17
+ const productListOutSideProduct = productEl?.closest('[data-component-tag="ProductList"]');
18
+ if (productListOutSideProduct || !productId) {
19
+ setProductElement({
20
+ productId: '',
21
+ uid: ''
22
+ });
23
+ return;
24
+ }
25
+ setProductElement({
26
+ productId: productId ? 'gid://shopify/Product/' + productId : '',
27
+ uid: productElUid ?? ''
28
+ });
29
+ }, [
30
+ genTool
31
+ ]);
32
+ useEffect(()=>{
33
+ if (!options?.isEnabled) return;
34
+ checkSectionHasProduct();
35
+ }, [
36
+ options?.isEnabled,
37
+ checkSectionHasProduct
38
+ ]);
39
+ return {
40
+ productElement,
41
+ checkSectionHasProduct
42
+ };
43
+ };
44
+
45
+ export { useCheckingProductInside };
@@ -0,0 +1,108 @@
1
+ import { useState, useCallback, useEffect } from 'react';
2
+
3
+ const useFlipPopup = (isShowPopup, dom)=>{
4
+ const { genTool, genPopup, genPopupHeader, genButtonWrapper } = dom;
5
+ const [popupPositionY, setPopupPositionY] = useState('top');
6
+ const [popupPositionX, setPopupPositionX] = useState('left');
7
+ const [bodyMaxHeight, setBodyMaxHeight] = useState(null);
8
+ const [isValidating, setIsValidating] = useState(true);
9
+ const calculateMaxHeight = useCallback((currentPopupPositionY)=>{
10
+ const parentOverflow = genTool.current?.closest("[class~='gp-overflow-hidden']");
11
+ if (!parentOverflow || !genTool.current) {
12
+ return {
13
+ positionY: currentPopupPositionY,
14
+ maxHeight: null
15
+ };
16
+ }
17
+ const parentOverflowPos = parentOverflow.getBoundingClientRect();
18
+ const genToolPos = genTool.current.getBoundingClientRect();
19
+ const genToolHeaderHeight = genPopupHeader.current?.getBoundingClientRect().height || 0;
20
+ const genButtonHeight = genButtonWrapper.current?.getBoundingClientRect().height || 0;
21
+ const DISTANCE = 8;
22
+ const maxHeightForPositionTop = Math.max(parentOverflowPos.bottom - genToolPos.bottom - genToolHeaderHeight - genButtonHeight - DISTANCE, 0);
23
+ const maxHeightForPositionBottom = Math.max(genToolPos.top - parentOverflowPos.top - genToolHeaderHeight - genButtonHeight - DISTANCE, 0);
24
+ if (maxHeightForPositionBottom > maxHeightForPositionTop) {
25
+ return {
26
+ positionY: 'bottom',
27
+ maxHeight: maxHeightForPositionBottom
28
+ };
29
+ }
30
+ return {
31
+ positionY: 'top',
32
+ maxHeight: maxHeightForPositionTop
33
+ };
34
+ }, [
35
+ genTool,
36
+ genPopupHeader,
37
+ genButtonWrapper
38
+ ]);
39
+ const handleChangePopupPositionY = useCallback((posY)=>{
40
+ const { positionY: calcPosY, maxHeight } = calculateMaxHeight(posY);
41
+ setPopupPositionY(calcPosY);
42
+ setBodyMaxHeight(maxHeight);
43
+ }, [
44
+ calculateMaxHeight
45
+ ]);
46
+ const calculatePopupPositionY = useCallback(()=>{
47
+ if (!genTool.current || !genPopup.current) return;
48
+ const viewHeight = window.innerHeight;
49
+ const scrollHeight = document.documentElement.scrollHeight;
50
+ const scrollTop = document.documentElement.scrollTop;
51
+ const toolPos = genTool.current?.getBoundingClientRect();
52
+ const genPopupHeight = genPopup.current?.getBoundingClientRect().height;
53
+ const MIN_DISTANCE = 50;
54
+ if (scrollTop + toolPos.top + genPopupHeight >= scrollHeight - MIN_DISTANCE) {
55
+ handleChangePopupPositionY('bottom');
56
+ return;
57
+ }
58
+ if (toolPos.bottom + genPopupHeight > viewHeight) {
59
+ if (toolPos.top - genPopupHeight < 0) {
60
+ handleChangePopupPositionY('top');
61
+ return;
62
+ }
63
+ handleChangePopupPositionY('bottom');
64
+ return;
65
+ }
66
+ handleChangePopupPositionY('top');
67
+ }, [
68
+ genPopup,
69
+ genTool,
70
+ handleChangePopupPositionY
71
+ ]);
72
+ const calculatePopupPositionX = useCallback(()=>{
73
+ if (!genTool.current || !genPopup.current) return;
74
+ const viewWidth = window.innerWidth;
75
+ const toolPos = genTool.current?.getBoundingClientRect();
76
+ const genPopupWidth = genPopup.current?.getBoundingClientRect().width;
77
+ if (toolPos.left + genPopupWidth > viewWidth) {
78
+ setPopupPositionX('right');
79
+ return;
80
+ }
81
+ setPopupPositionX('left');
82
+ }, [
83
+ genPopup,
84
+ genTool
85
+ ]);
86
+ useEffect(()=>{
87
+ if (!isShowPopup) {
88
+ setIsValidating(true);
89
+ return;
90
+ }
91
+ setIsValidating(true);
92
+ calculatePopupPositionY();
93
+ calculatePopupPositionX();
94
+ setIsValidating(false);
95
+ }, [
96
+ isShowPopup,
97
+ calculatePopupPositionX,
98
+ calculatePopupPositionY
99
+ ]);
100
+ return {
101
+ isValidating,
102
+ bodyMaxHeight,
103
+ popupPositionY,
104
+ popupPositionX
105
+ };
106
+ };
107
+
108
+ export { useFlipPopup };
@@ -0,0 +1,35 @@
1
+ import { useState } from 'react';
2
+
3
+ const useGettingGenerateRequest = ()=>{
4
+ const [prompt, setPrompt] = useState('');
5
+ const [productName, setProductName] = useState('');
6
+ const [tone, setTone] = useState('');
7
+ const changePrompt = (value)=>{
8
+ const limit = 200;
9
+ setPrompt(value.slice(0, limit));
10
+ };
11
+ const changeProductName = (value)=>{
12
+ setProductName(value);
13
+ };
14
+ const changeTone = (value)=>{
15
+ setTone(value);
16
+ };
17
+ const getRequestBody = ()=>{
18
+ return {
19
+ prompt,
20
+ productName,
21
+ tone
22
+ };
23
+ };
24
+ return {
25
+ prompt,
26
+ changePrompt,
27
+ productName,
28
+ changeProductName,
29
+ tone,
30
+ changeTone,
31
+ getRequestBody
32
+ };
33
+ };
34
+
35
+ export { useGettingGenerateRequest };
@@ -0,0 +1,61 @@
1
+ import { useState, useCallback, useEffect } from 'react';
2
+
3
+ const useListenEventGenerate = (componentInfo)=>{
4
+ const { uid: componentUid, tag: componentTag } = componentInfo;
5
+ const [isGenerating, setIsGenerating] = useState(false);
6
+ const onGenerate = (body)=>{
7
+ const eventCreate = new CustomEvent('editor:toolbar:ai-generate-content', {
8
+ bubbles: true,
9
+ detail: {
10
+ componentUid: componentUid,
11
+ componentTag: componentTag,
12
+ genRequest: body
13
+ }
14
+ });
15
+ window.dispatchEvent(eventCreate);
16
+ setIsGenerating(true);
17
+ onNotifyStatus('loading');
18
+ };
19
+ const onNotifyStatus = (status)=>{
20
+ const eventNotifyStatus = new CustomEvent('editor:ai-generate-content-status', {
21
+ bubbles: true,
22
+ detail: {
23
+ status: status,
24
+ generatingUid: componentUid
25
+ }
26
+ });
27
+ window.dispatchEvent(eventNotifyStatus);
28
+ };
29
+ const onGenerateContentStatus = useCallback((e)=>{
30
+ const detail = e.detail;
31
+ if (detail?.generatingUid === componentUid && detail.status === 'success') {
32
+ setIsGenerating(false);
33
+ }
34
+ }, [
35
+ componentUid
36
+ ]);
37
+ const onOpenProductElementSettings = (productElementUid)=>{
38
+ const eventCreate = new CustomEvent('editor:toolbar:open-product-element', {
39
+ bubbles: true,
40
+ detail: {
41
+ productElementUid: productElementUid
42
+ }
43
+ });
44
+ window.dispatchEvent(eventCreate);
45
+ };
46
+ useEffect(()=>{
47
+ window.addEventListener('editor:ai-generate-content-status', onGenerateContentStatus);
48
+ return ()=>{
49
+ window.removeEventListener('editor:ai-generate-content-status', onGenerateContentStatus);
50
+ };
51
+ }, [
52
+ onGenerateContentStatus
53
+ ]);
54
+ return {
55
+ isGenerating,
56
+ onGenerate,
57
+ onOpenProductElementSettings
58
+ };
59
+ };
60
+
61
+ export { useListenEventGenerate };
@@ -0,0 +1,65 @@
1
+ import { jsxs, jsx } from 'react/jsx-runtime';
2
+
3
+ const AIIcon = ()=>{
4
+ const getRandomId = ()=>{
5
+ return Math.random().toString(36).substring(7);
6
+ };
7
+ const linearGradientId = getRandomId();
8
+ return /*#__PURE__*/ jsxs("svg", {
9
+ width: "16",
10
+ height: "16",
11
+ viewBox: "0 0 16 16",
12
+ fill: "none",
13
+ xmlns: "http://www.w3.org/2000/svg",
14
+ children: [
15
+ /*#__PURE__*/ jsx("path", {
16
+ d: "M11.6363 2.67137C11.5886 2.52361 11.3795 2.52361 11.3318 2.67137L11.1133 3.34797C11.0352 3.58971 10.8469 3.78 10.606 3.86067L9.93715 4.08465C9.79156 4.1334 9.79156 4.33933 9.93715 4.38809L10.606 4.61207C10.8469 4.69273 11.0352 4.88302 11.1133 5.12477L11.3318 5.80137C11.3795 5.94913 11.5886 5.94913 11.6363 5.80137L11.8549 5.12477C11.933 4.88302 12.1212 4.69273 12.3621 4.61207L13.031 4.38809C13.1766 4.33933 13.1766 4.1334 13.031 4.08465L12.3621 3.86067C12.1212 3.78 11.933 3.58971 11.8549 3.34797L11.6363 2.67137Z",
17
+ fill: `url(#${linearGradientId}_0)`
18
+ }),
19
+ /*#__PURE__*/ jsx("path", {
20
+ d: "M7.61245 3.30705C7.54086 3.08541 7.22728 3.08541 7.15569 3.30705L6.39541 5.6608C6.16115 6.38604 5.59636 6.9569 4.87367 7.19891L2.56369 7.97242C2.3453 8.04555 2.34531 8.35445 2.5637 8.42758L4.87367 9.2011C5.59636 9.4431 6.16115 10.014 6.39541 10.7392L7.15569 13.093C7.22728 13.3146 7.54086 13.3146 7.61245 13.093L8.37273 10.7392C8.60699 10.014 9.17178 9.4431 9.89447 9.2011L12.2044 8.42758C12.4228 8.35445 12.4228 8.04555 12.2044 7.97242L9.89447 7.1989C9.17178 6.9569 8.60699 6.38604 8.37273 5.6608L7.61245 3.30705Z",
21
+ fill: `url(#${linearGradientId}_1)`
22
+ }),
23
+ /*#__PURE__*/ jsxs("defs", {
24
+ children: [
25
+ /*#__PURE__*/ jsxs("linearGradient", {
26
+ id: `${linearGradientId}_0`,
27
+ x1: "15.3433",
28
+ y1: "2.56054",
29
+ x2: "4.24885",
30
+ y2: "1.00838",
31
+ gradientUnits: "userSpaceOnUse",
32
+ children: [
33
+ /*#__PURE__*/ jsx("stop", {
34
+ stopColor: "#D8E1FF"
35
+ }),
36
+ /*#__PURE__*/ jsx("stop", {
37
+ offset: "1",
38
+ stopColor: "#C8ACFF"
39
+ })
40
+ ]
41
+ }),
42
+ /*#__PURE__*/ jsxs("linearGradient", {
43
+ id: `${linearGradientId}_1`,
44
+ x1: "15.3433",
45
+ y1: "2.56054",
46
+ x2: "4.24885",
47
+ y2: "1.00838",
48
+ gradientUnits: "userSpaceOnUse",
49
+ children: [
50
+ /*#__PURE__*/ jsx("stop", {
51
+ stopColor: "#D8E1FF"
52
+ }),
53
+ /*#__PURE__*/ jsx("stop", {
54
+ offset: "1",
55
+ stopColor: "#C8ACFF"
56
+ })
57
+ ]
58
+ })
59
+ ]
60
+ })
61
+ ]
62
+ });
63
+ };
64
+
65
+ export { AIIcon };
@@ -0,0 +1,17 @@
1
+ import { jsx } from 'react/jsx-runtime';
2
+
3
+ const CloseIcon = ()=>{
4
+ return /*#__PURE__*/ jsx("svg", {
5
+ width: "16",
6
+ height: "16",
7
+ viewBox: "0 0 16 16",
8
+ fill: "none",
9
+ xmlns: "http://www.w3.org/2000/svg",
10
+ children: /*#__PURE__*/ jsx("path", {
11
+ d: "M11.1755 12.0243C11.4099 12.2586 11.7898 12.2586 12.0241 12.0243C12.2584 11.79 12.2584 11.4101 12.0241 11.1757L8.84833 8L12.0241 4.82427C12.2584 4.58995 12.2584 4.21005 12.0241 3.97574C11.7898 3.74142 11.4099 3.74142 11.1755 3.97574L7.9998 7.15148L4.82407 3.97574C4.58975 3.74142 4.20986 3.74142 3.97554 3.97574C3.74123 4.21005 3.74123 4.58995 3.97554 4.82427L7.15128 8L3.97554 11.1757C3.74123 11.4101 3.74123 11.79 3.97554 12.0243C4.20986 12.2586 4.58975 12.2586 4.82407 12.0243L7.9998 8.84853L11.1755 12.0243Z",
12
+ fill: "#F9F9F9"
13
+ })
14
+ });
15
+ };
16
+
17
+ export { CloseIcon };
@@ -0,0 +1,34 @@
1
+ import { jsx } from 'react/jsx-runtime';
2
+
3
+ const DropdownIcon = ()=>{
4
+ return /*#__PURE__*/ jsx("svg", {
5
+ width: "20",
6
+ height: "20",
7
+ viewBox: "0 0 20 20",
8
+ fill: "none",
9
+ xmlns: "http://www.w3.org/2000/svg",
10
+ children: /*#__PURE__*/ jsx("path", {
11
+ fillRule: "evenodd",
12
+ clipRule: "evenodd",
13
+ d: "M5.13313 7.62204C5.31064 7.45932 5.59845 7.45932 5.77596 7.62204L10 11.4941L14.224 7.62204C14.4016 7.45932 14.6894 7.45932 14.8669 7.62204C15.0444 7.78476 15.0444 8.04858 14.8669 8.21129L10.3214 12.378C10.1439 12.5407 9.8561 12.5407 9.67859 12.378L5.13313 8.21129C4.95562 8.04858 4.95562 7.78476 5.13313 7.62204Z",
14
+ fill: "#F9F9F9"
15
+ })
16
+ });
17
+ };
18
+ const TickIcon = ()=>{
19
+ return /*#__PURE__*/ jsx("svg", {
20
+ width: "20",
21
+ height: "20",
22
+ viewBox: "0 0 20 20",
23
+ fill: "none",
24
+ xmlns: "http://www.w3.org/2000/svg",
25
+ children: /*#__PURE__*/ jsx("path", {
26
+ fillRule: "evenodd",
27
+ clipRule: "evenodd",
28
+ d: "M15.8415 5.1766C16.0528 5.41207 16.0528 5.79383 15.8415 6.0293L7.95016 14.8234C7.84869 14.9365 7.71107 15 7.56757 15C7.42408 15 7.28645 14.9365 7.18499 14.8234L4.15846 11.4505C3.94717 11.215 3.94718 10.8333 4.15848 10.5978C4.36978 10.3623 4.71236 10.3623 4.92365 10.5978L7.56759 13.5443L15.0764 5.1766C15.2877 4.94113 15.6302 4.94113 15.8415 5.1766Z",
29
+ fill: "#00C853"
30
+ })
31
+ });
32
+ };
33
+
34
+ export { DropdownIcon, TickIcon };