@gem-sdk/core 1.42.0 → 1.42.3-dev.64
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.
- package/dist/cjs/components/ComponentToolbarPreview.js +120 -6
- package/dist/cjs/components/ComponentWrapperPreview.js +44 -1
- package/dist/cjs/components/Render.liquid.js +2 -0
- package/dist/cjs/components/RenderCustomCode.js +2 -0
- package/dist/cjs/components/ai-generator/AIContentGenerator.js +205 -0
- package/dist/cjs/components/ai-generator/AIGenContentLoading.js +85 -0
- package/dist/cjs/components/ai-generator/components/PickProduct.js +218 -0
- package/dist/cjs/components/ai-generator/components/ToneAndVoice.js +77 -0
- package/dist/cjs/components/ai-generator/hooks/useCheckingProductInside.js +47 -0
- package/dist/cjs/components/ai-generator/hooks/useFlipPopup.js +110 -0
- package/dist/cjs/components/ai-generator/hooks/useGettingGenerateRequest.js +37 -0
- package/dist/cjs/components/ai-generator/hooks/useListenEventGenerate.js +63 -0
- package/dist/cjs/components/ai-generator/icons/AIIcon.js +67 -0
- package/dist/cjs/components/ai-generator/icons/CloseIcon.js +19 -0
- package/dist/cjs/components/ai-generator/icons/DropdownIcon.js +37 -0
- package/dist/cjs/components/ai-generator/icons/SearchIcon.js +21 -0
- package/dist/cjs/components/ai-generator/icons/ShowMoreIcon.js +21 -0
- package/dist/cjs/components/constant.js +19 -2
- package/dist/cjs/components/resize/Spacing.js +2 -0
- package/dist/cjs/components/theme-section/CreateThemeSection.js +2 -0
- package/dist/cjs/contexts/ArticleContext.js +39 -0
- package/dist/cjs/contexts/ArticleListContext.js +32 -0
- package/dist/cjs/contexts/BuilderPreviewContext.js +11 -6
- package/dist/cjs/contexts/SectionContext.js +1 -0
- package/dist/cjs/helpers/align.js +19 -0
- package/dist/cjs/helpers/carousel.js +7 -10
- package/dist/cjs/helpers/colors.js +1 -1
- package/dist/cjs/helpers/queries/get-products.js +23 -0
- package/dist/cjs/helpers/typography.js +4 -4
- package/dist/cjs/hooks/articles/useArticlesQuery.js +152 -0
- package/dist/cjs/hooks/shop/use-products-query.js +29 -0
- package/dist/cjs/hooks/useAnimations.js +2 -0
- package/dist/cjs/hooks/useInitialSwatchesOptions.js +2 -0
- package/dist/cjs/hooks/useProduct.js +2 -0
- package/dist/cjs/index.js +11 -0
- package/dist/esm/components/ComponentToolbarPreview.js +120 -6
- package/dist/esm/components/ComponentWrapperPreview.js +44 -1
- package/dist/esm/components/Render.liquid.js +2 -0
- package/dist/esm/components/RenderCustomCode.js +2 -0
- package/dist/esm/components/ai-generator/AIContentGenerator.js +203 -0
- package/dist/esm/components/ai-generator/AIGenContentLoading.js +83 -0
- package/dist/esm/components/ai-generator/components/PickProduct.js +216 -0
- package/dist/esm/components/ai-generator/components/ToneAndVoice.js +75 -0
- package/dist/esm/components/ai-generator/hooks/useCheckingProductInside.js +45 -0
- package/dist/esm/components/ai-generator/hooks/useFlipPopup.js +108 -0
- package/dist/esm/components/ai-generator/hooks/useGettingGenerateRequest.js +35 -0
- package/dist/esm/components/ai-generator/hooks/useListenEventGenerate.js +61 -0
- package/dist/esm/components/ai-generator/icons/AIIcon.js +65 -0
- package/dist/esm/components/ai-generator/icons/CloseIcon.js +17 -0
- package/dist/esm/components/ai-generator/icons/DropdownIcon.js +34 -0
- package/dist/esm/components/ai-generator/icons/SearchIcon.js +19 -0
- package/dist/esm/components/ai-generator/icons/ShowMoreIcon.js +19 -0
- package/dist/esm/components/constant.js +19 -3
- package/dist/esm/components/resize/Spacing.js +2 -0
- package/dist/esm/components/theme-section/CreateThemeSection.js +2 -0
- package/dist/esm/contexts/ArticleContext.js +36 -0
- package/dist/esm/contexts/ArticleListContext.js +28 -0
- package/dist/esm/contexts/BuilderPreviewContext.js +11 -6
- package/dist/esm/contexts/SectionContext.js +1 -0
- package/dist/esm/helpers/align.js +17 -0
- package/dist/esm/helpers/carousel.js +7 -10
- package/dist/esm/helpers/colors.js +1 -1
- package/dist/esm/helpers/queries/get-products.js +23 -1
- package/dist/esm/helpers/typography.js +4 -4
- package/dist/esm/hooks/articles/useArticlesQuery.js +149 -0
- package/dist/esm/hooks/shop/use-products-query.js +30 -2
- package/dist/esm/hooks/useAnimations.js +2 -0
- package/dist/esm/hooks/useInitialSwatchesOptions.js +2 -0
- package/dist/esm/hooks/useProduct.js +2 -0
- package/dist/esm/index.js +4 -0
- package/dist/types/index.d.ts +161 -20
- package/package.json +5 -3
|
@@ -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;
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var react = require('react');
|
|
4
|
+
|
|
5
|
+
const useFlipPopup = (isShowPopup, dom)=>{
|
|
6
|
+
const { genTool, genPopup, genPopupHeader, genButtonWrapper } = dom;
|
|
7
|
+
const [popupPositionY, setPopupPositionY] = react.useState('top');
|
|
8
|
+
const [popupPositionX, setPopupPositionX] = react.useState('left');
|
|
9
|
+
const [bodyMaxHeight, setBodyMaxHeight] = react.useState(null);
|
|
10
|
+
const [isValidating, setIsValidating] = react.useState(true);
|
|
11
|
+
const calculateMaxHeight = react.useCallback((currentPopupPositionY)=>{
|
|
12
|
+
const parentOverflow = genTool.current?.closest("[class~='gp-overflow-hidden']");
|
|
13
|
+
if (!parentOverflow || !genTool.current) {
|
|
14
|
+
return {
|
|
15
|
+
positionY: currentPopupPositionY,
|
|
16
|
+
maxHeight: null
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
const parentOverflowPos = parentOverflow.getBoundingClientRect();
|
|
20
|
+
const genToolPos = genTool.current.getBoundingClientRect();
|
|
21
|
+
const genToolHeaderHeight = genPopupHeader.current?.getBoundingClientRect().height || 0;
|
|
22
|
+
const genButtonHeight = genButtonWrapper.current?.getBoundingClientRect().height || 0;
|
|
23
|
+
const DISTANCE = 8;
|
|
24
|
+
const maxHeightForPositionTop = Math.max(parentOverflowPos.bottom - genToolPos.bottom - genToolHeaderHeight - genButtonHeight - DISTANCE, 0);
|
|
25
|
+
const maxHeightForPositionBottom = Math.max(genToolPos.top - parentOverflowPos.top - genToolHeaderHeight - genButtonHeight - DISTANCE, 0);
|
|
26
|
+
if (maxHeightForPositionBottom > maxHeightForPositionTop) {
|
|
27
|
+
return {
|
|
28
|
+
positionY: 'bottom',
|
|
29
|
+
maxHeight: maxHeightForPositionBottom
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
return {
|
|
33
|
+
positionY: 'top',
|
|
34
|
+
maxHeight: maxHeightForPositionTop
|
|
35
|
+
};
|
|
36
|
+
}, [
|
|
37
|
+
genTool,
|
|
38
|
+
genPopupHeader,
|
|
39
|
+
genButtonWrapper
|
|
40
|
+
]);
|
|
41
|
+
const handleChangePopupPositionY = react.useCallback((posY)=>{
|
|
42
|
+
const { positionY: calcPosY, maxHeight } = calculateMaxHeight(posY);
|
|
43
|
+
setPopupPositionY(calcPosY);
|
|
44
|
+
setBodyMaxHeight(maxHeight);
|
|
45
|
+
}, [
|
|
46
|
+
calculateMaxHeight
|
|
47
|
+
]);
|
|
48
|
+
const calculatePopupPositionY = react.useCallback(()=>{
|
|
49
|
+
if (!genTool.current || !genPopup.current) return;
|
|
50
|
+
const viewHeight = window.innerHeight;
|
|
51
|
+
const scrollHeight = document.documentElement.scrollHeight;
|
|
52
|
+
const scrollTop = document.documentElement.scrollTop;
|
|
53
|
+
const toolPos = genTool.current?.getBoundingClientRect();
|
|
54
|
+
const genPopupHeight = genPopup.current?.getBoundingClientRect().height;
|
|
55
|
+
const MIN_DISTANCE = 50;
|
|
56
|
+
if (scrollTop + toolPos.top + genPopupHeight >= scrollHeight - MIN_DISTANCE) {
|
|
57
|
+
handleChangePopupPositionY('bottom');
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
if (toolPos.bottom + genPopupHeight > viewHeight) {
|
|
61
|
+
if (toolPos.top - genPopupHeight < 0) {
|
|
62
|
+
handleChangePopupPositionY('top');
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
handleChangePopupPositionY('bottom');
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
handleChangePopupPositionY('top');
|
|
69
|
+
}, [
|
|
70
|
+
genPopup,
|
|
71
|
+
genTool,
|
|
72
|
+
handleChangePopupPositionY
|
|
73
|
+
]);
|
|
74
|
+
const calculatePopupPositionX = react.useCallback(()=>{
|
|
75
|
+
if (!genTool.current || !genPopup.current) return;
|
|
76
|
+
const viewWidth = window.innerWidth;
|
|
77
|
+
const toolPos = genTool.current?.getBoundingClientRect();
|
|
78
|
+
const genPopupWidth = genPopup.current?.getBoundingClientRect().width;
|
|
79
|
+
if (toolPos.left + genPopupWidth > viewWidth) {
|
|
80
|
+
setPopupPositionX('right');
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
setPopupPositionX('left');
|
|
84
|
+
}, [
|
|
85
|
+
genPopup,
|
|
86
|
+
genTool
|
|
87
|
+
]);
|
|
88
|
+
react.useEffect(()=>{
|
|
89
|
+
if (!isShowPopup) {
|
|
90
|
+
setIsValidating(true);
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
setIsValidating(true);
|
|
94
|
+
calculatePopupPositionY();
|
|
95
|
+
calculatePopupPositionX();
|
|
96
|
+
setIsValidating(false);
|
|
97
|
+
}, [
|
|
98
|
+
isShowPopup,
|
|
99
|
+
calculatePopupPositionX,
|
|
100
|
+
calculatePopupPositionY
|
|
101
|
+
]);
|
|
102
|
+
return {
|
|
103
|
+
isValidating,
|
|
104
|
+
bodyMaxHeight,
|
|
105
|
+
popupPositionY,
|
|
106
|
+
popupPositionX
|
|
107
|
+
};
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
exports.useFlipPopup = useFlipPopup;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var react = require('react');
|
|
4
|
+
|
|
5
|
+
const useGettingGenerateRequest = ()=>{
|
|
6
|
+
const [prompt, setPrompt] = react.useState('');
|
|
7
|
+
const [productName, setProductName] = react.useState('');
|
|
8
|
+
const [tone, setTone] = react.useState('');
|
|
9
|
+
const changePrompt = (value)=>{
|
|
10
|
+
const limit = 200;
|
|
11
|
+
setPrompt(value.slice(0, limit));
|
|
12
|
+
};
|
|
13
|
+
const changeProductName = (value)=>{
|
|
14
|
+
setProductName(value);
|
|
15
|
+
};
|
|
16
|
+
const changeTone = (value)=>{
|
|
17
|
+
setTone(value);
|
|
18
|
+
};
|
|
19
|
+
const getRequestBody = ()=>{
|
|
20
|
+
return {
|
|
21
|
+
prompt,
|
|
22
|
+
productName,
|
|
23
|
+
tone
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
return {
|
|
27
|
+
prompt,
|
|
28
|
+
changePrompt,
|
|
29
|
+
productName,
|
|
30
|
+
changeProductName,
|
|
31
|
+
tone,
|
|
32
|
+
changeTone,
|
|
33
|
+
getRequestBody
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
exports.useGettingGenerateRequest = useGettingGenerateRequest;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var react = require('react');
|
|
4
|
+
|
|
5
|
+
const useListenEventGenerate = (componentInfo)=>{
|
|
6
|
+
const { uid: componentUid, tag: componentTag } = componentInfo;
|
|
7
|
+
const [isGenerating, setIsGenerating] = react.useState(false);
|
|
8
|
+
const onGenerate = (body)=>{
|
|
9
|
+
const eventCreate = new CustomEvent('editor:toolbar:ai-generate-content', {
|
|
10
|
+
bubbles: true,
|
|
11
|
+
detail: {
|
|
12
|
+
componentUid: componentUid,
|
|
13
|
+
componentTag: componentTag,
|
|
14
|
+
genRequest: body
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
window.dispatchEvent(eventCreate);
|
|
18
|
+
setIsGenerating(true);
|
|
19
|
+
onNotifyStatus('loading');
|
|
20
|
+
};
|
|
21
|
+
const onNotifyStatus = (status)=>{
|
|
22
|
+
const eventNotifyStatus = new CustomEvent('editor:ai-generate-content-status', {
|
|
23
|
+
bubbles: true,
|
|
24
|
+
detail: {
|
|
25
|
+
status: status,
|
|
26
|
+
generatingUid: componentUid
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
window.dispatchEvent(eventNotifyStatus);
|
|
30
|
+
};
|
|
31
|
+
const onGenerateContentStatus = react.useCallback((e)=>{
|
|
32
|
+
const detail = e.detail;
|
|
33
|
+
if (detail?.generatingUid === componentUid && detail.status === 'success') {
|
|
34
|
+
setIsGenerating(false);
|
|
35
|
+
}
|
|
36
|
+
}, [
|
|
37
|
+
componentUid
|
|
38
|
+
]);
|
|
39
|
+
const onOpenProductElementSettings = (productElementUid)=>{
|
|
40
|
+
const eventCreate = new CustomEvent('editor:toolbar:open-product-element', {
|
|
41
|
+
bubbles: true,
|
|
42
|
+
detail: {
|
|
43
|
+
productElementUid: productElementUid
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
window.dispatchEvent(eventCreate);
|
|
47
|
+
};
|
|
48
|
+
react.useEffect(()=>{
|
|
49
|
+
window.addEventListener('editor:ai-generate-content-status', onGenerateContentStatus);
|
|
50
|
+
return ()=>{
|
|
51
|
+
window.removeEventListener('editor:ai-generate-content-status', onGenerateContentStatus);
|
|
52
|
+
};
|
|
53
|
+
}, [
|
|
54
|
+
onGenerateContentStatus
|
|
55
|
+
]);
|
|
56
|
+
return {
|
|
57
|
+
isGenerating,
|
|
58
|
+
onGenerate,
|
|
59
|
+
onOpenProductElementSettings
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
exports.useListenEventGenerate = useListenEventGenerate;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
4
|
+
|
|
5
|
+
const AIIcon = ()=>{
|
|
6
|
+
const getRandomId = ()=>{
|
|
7
|
+
return Math.random().toString(36).substring(7);
|
|
8
|
+
};
|
|
9
|
+
const linearGradientId = getRandomId();
|
|
10
|
+
return /*#__PURE__*/ jsxRuntime.jsxs("svg", {
|
|
11
|
+
width: "16",
|
|
12
|
+
height: "16",
|
|
13
|
+
viewBox: "0 0 16 16",
|
|
14
|
+
fill: "none",
|
|
15
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
16
|
+
children: [
|
|
17
|
+
/*#__PURE__*/ jsxRuntime.jsx("path", {
|
|
18
|
+
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",
|
|
19
|
+
fill: `url(#${linearGradientId}_0)`
|
|
20
|
+
}),
|
|
21
|
+
/*#__PURE__*/ jsxRuntime.jsx("path", {
|
|
22
|
+
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",
|
|
23
|
+
fill: `url(#${linearGradientId}_1)`
|
|
24
|
+
}),
|
|
25
|
+
/*#__PURE__*/ jsxRuntime.jsxs("defs", {
|
|
26
|
+
children: [
|
|
27
|
+
/*#__PURE__*/ jsxRuntime.jsxs("linearGradient", {
|
|
28
|
+
id: `${linearGradientId}_0`,
|
|
29
|
+
x1: "15.3433",
|
|
30
|
+
y1: "2.56054",
|
|
31
|
+
x2: "4.24885",
|
|
32
|
+
y2: "1.00838",
|
|
33
|
+
gradientUnits: "userSpaceOnUse",
|
|
34
|
+
children: [
|
|
35
|
+
/*#__PURE__*/ jsxRuntime.jsx("stop", {
|
|
36
|
+
stopColor: "#D8E1FF"
|
|
37
|
+
}),
|
|
38
|
+
/*#__PURE__*/ jsxRuntime.jsx("stop", {
|
|
39
|
+
offset: "1",
|
|
40
|
+
stopColor: "#C8ACFF"
|
|
41
|
+
})
|
|
42
|
+
]
|
|
43
|
+
}),
|
|
44
|
+
/*#__PURE__*/ jsxRuntime.jsxs("linearGradient", {
|
|
45
|
+
id: `${linearGradientId}_1`,
|
|
46
|
+
x1: "15.3433",
|
|
47
|
+
y1: "2.56054",
|
|
48
|
+
x2: "4.24885",
|
|
49
|
+
y2: "1.00838",
|
|
50
|
+
gradientUnits: "userSpaceOnUse",
|
|
51
|
+
children: [
|
|
52
|
+
/*#__PURE__*/ jsxRuntime.jsx("stop", {
|
|
53
|
+
stopColor: "#D8E1FF"
|
|
54
|
+
}),
|
|
55
|
+
/*#__PURE__*/ jsxRuntime.jsx("stop", {
|
|
56
|
+
offset: "1",
|
|
57
|
+
stopColor: "#C8ACFF"
|
|
58
|
+
})
|
|
59
|
+
]
|
|
60
|
+
})
|
|
61
|
+
]
|
|
62
|
+
})
|
|
63
|
+
]
|
|
64
|
+
});
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
exports.AIIcon = AIIcon;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
4
|
+
|
|
5
|
+
const CloseIcon = ()=>{
|
|
6
|
+
return /*#__PURE__*/ jsxRuntime.jsx("svg", {
|
|
7
|
+
width: "16",
|
|
8
|
+
height: "16",
|
|
9
|
+
viewBox: "0 0 16 16",
|
|
10
|
+
fill: "none",
|
|
11
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
12
|
+
children: /*#__PURE__*/ jsxRuntime.jsx("path", {
|
|
13
|
+
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",
|
|
14
|
+
fill: "#F9F9F9"
|
|
15
|
+
})
|
|
16
|
+
});
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
exports.CloseIcon = CloseIcon;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
4
|
+
|
|
5
|
+
const DropdownIcon = ()=>{
|
|
6
|
+
return /*#__PURE__*/ jsxRuntime.jsx("svg", {
|
|
7
|
+
width: "20",
|
|
8
|
+
height: "20",
|
|
9
|
+
viewBox: "0 0 20 20",
|
|
10
|
+
fill: "none",
|
|
11
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
12
|
+
children: /*#__PURE__*/ jsxRuntime.jsx("path", {
|
|
13
|
+
fillRule: "evenodd",
|
|
14
|
+
clipRule: "evenodd",
|
|
15
|
+
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",
|
|
16
|
+
fill: "#F9F9F9"
|
|
17
|
+
})
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
const TickIcon = ()=>{
|
|
21
|
+
return /*#__PURE__*/ jsxRuntime.jsx("svg", {
|
|
22
|
+
width: "20",
|
|
23
|
+
height: "20",
|
|
24
|
+
viewBox: "0 0 20 20",
|
|
25
|
+
fill: "none",
|
|
26
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
27
|
+
children: /*#__PURE__*/ jsxRuntime.jsx("path", {
|
|
28
|
+
fillRule: "evenodd",
|
|
29
|
+
clipRule: "evenodd",
|
|
30
|
+
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",
|
|
31
|
+
fill: "#00C853"
|
|
32
|
+
})
|
|
33
|
+
});
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
exports.DropdownIcon = DropdownIcon;
|
|
37
|
+
exports.TickIcon = TickIcon;
|