@antscorp/antsomi-ui 1.3.5 → 1.3.7
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/es/assets/images/iphone-top-bar.png +0 -0
- package/es/assets/images/iphone.png +0 -0
- package/es/components/atoms/Input/Input.d.ts +3 -0
- package/es/components/atoms/Input/Input.js +4 -3
- package/es/components/atoms/InputDynamic/EditCaretPositioning.d.ts +2 -0
- package/es/components/atoms/InputDynamic/EditCaretPositioning.js +89 -0
- package/es/components/atoms/InputDynamic/InputDynamic.d.ts +10 -0
- package/es/components/atoms/InputDynamic/InputDynamic.js +516 -0
- package/es/components/atoms/InputDynamic/PopupShortLink.d.ts +16 -0
- package/es/components/atoms/InputDynamic/PopupShortLink.js +85 -0
- package/es/components/atoms/InputDynamic/constants.d.ts +71 -0
- package/es/components/atoms/InputDynamic/constants.js +71 -0
- package/es/components/atoms/InputDynamic/index.d.ts +2 -0
- package/es/components/atoms/InputDynamic/index.js +1 -0
- package/es/components/atoms/InputDynamic/styled.d.ts +13 -0
- package/es/components/atoms/InputDynamic/styled.js +293 -0
- package/es/components/atoms/InputDynamic/types.d.ts +116 -0
- package/es/components/atoms/InputDynamic/types.js +1 -0
- package/es/components/atoms/InputDynamic/utils.d.ts +30 -0
- package/es/components/atoms/InputDynamic/utils.js +874 -0
- package/es/components/atoms/MobileFrame/MobileFrame.d.ts +4 -0
- package/es/components/atoms/MobileFrame/MobileFrame.js +22 -0
- package/es/components/atoms/MobileFrame/constants.d.ts +4 -0
- package/es/components/atoms/MobileFrame/constants.js +4 -0
- package/es/components/atoms/MobileFrame/index.d.ts +2 -0
- package/es/components/atoms/MobileFrame/index.js +1 -0
- package/es/components/atoms/MobileFrame/styled.d.ts +3 -0
- package/es/components/atoms/MobileFrame/styled.js +33 -0
- package/es/components/atoms/Pagination/index.d.ts +1 -0
- package/es/components/atoms/PreviewTabs/PreviewTabs.d.ts +7 -0
- package/es/components/atoms/PreviewTabs/PreviewTabs.js +67 -0
- package/es/components/atoms/PreviewTabs/index.d.ts +2 -0
- package/es/components/atoms/PreviewTabs/index.js +1 -0
- package/es/components/atoms/PreviewTabs/styled.d.ts +6 -0
- package/es/components/atoms/PreviewTabs/styled.js +79 -0
- package/es/components/atoms/RequiredLabel/index.d.ts +1 -0
- package/es/components/atoms/RequiredLabel/index.js +4 -3
- package/es/components/atoms/SlideBar/SlideBar.d.ts +34 -0
- package/es/components/atoms/SlideBar/SlideBar.js +283 -0
- package/es/components/atoms/SlideBar/constants.d.ts +10 -0
- package/es/components/atoms/SlideBar/constants.js +10 -0
- package/es/components/atoms/SlideBar/index.d.ts +1 -0
- package/es/components/atoms/SlideBar/index.js +1 -0
- package/es/components/atoms/SlideBar/styled.d.ts +20 -0
- package/es/components/atoms/SlideBar/styled.js +136 -0
- package/es/components/atoms/index.d.ts +6 -0
- package/es/components/atoms/index.js +4 -0
- package/es/components/common/ConfigProvider/GlobalStyle.js +73 -2
- package/es/components/molecules/AddDynamicContent/AddDynamicContent.d.ts +35 -0
- package/es/components/molecules/AddDynamicContent/AddDynamicContent.js +1248 -0
- package/es/components/molecules/AddDynamicContent/components/DisplayFormat/DisplayFormat.d.ts +12 -0
- package/es/components/molecules/AddDynamicContent/components/DisplayFormat/DisplayFormat.js +25 -0
- package/es/components/molecules/AddDynamicContent/components/DisplayFormat/index.d.ts +3 -0
- package/es/components/molecules/AddDynamicContent/components/DisplayFormat/index.js +3 -0
- package/es/components/molecules/AddDynamicContent/components/FormatDatetime/FormatDatetime.d.ts +19 -0
- package/es/components/molecules/AddDynamicContent/components/FormatDatetime/FormatDatetime.js +100 -0
- package/es/components/molecules/AddDynamicContent/components/FormatDatetime/index.d.ts +1 -0
- package/es/components/molecules/AddDynamicContent/components/FormatDatetime/index.js +1 -0
- package/es/components/molecules/AddDynamicContent/components/FormatNumber/FormatNumber.d.ts +52 -0
- package/es/components/molecules/AddDynamicContent/components/FormatNumber/FormatNumber.js +132 -0
- package/es/components/molecules/AddDynamicContent/components/FormatNumber/index.d.ts +1 -0
- package/es/components/molecules/AddDynamicContent/components/FormatNumber/index.js +1 -0
- package/es/components/molecules/AddDynamicContent/components/index.d.ts +3 -0
- package/es/components/molecules/AddDynamicContent/components/index.js +3 -0
- package/es/components/molecules/AddDynamicContent/constants.d.ts +101 -0
- package/es/components/molecules/AddDynamicContent/constants.js +152 -0
- package/es/components/molecules/AddDynamicContent/currencies.json +1523 -0
- package/es/components/molecules/AddDynamicContent/index.d.ts +2 -0
- package/es/components/molecules/AddDynamicContent/index.js +2 -0
- package/es/components/molecules/AddDynamicContent/styled.d.ts +12 -0
- package/es/components/molecules/AddDynamicContent/styled.js +30 -0
- package/es/components/molecules/AddDynamicContent/types.d.ts +13 -0
- package/es/components/molecules/AddDynamicContent/types.js +1 -0
- package/es/components/molecules/AddDynamicContent/utils.d.ts +41 -0
- package/es/components/molecules/AddDynamicContent/utils.js +396 -0
- package/es/components/molecules/DatePicker/components/AdvancedPicker/AdvancedPicker.js +1 -1
- package/es/components/molecules/Drawer/Drawer.d.ts +5 -1
- package/es/components/molecules/Drawer/Drawer.js +3 -1
- package/es/components/molecules/Drawer/index.d.ts +1 -0
- package/es/components/molecules/EditorScript/EditorScript.d.ts +14 -0
- package/es/components/molecules/EditorScript/EditorScript.js +89 -0
- package/es/components/molecules/EditorScript/index.d.ts +1 -0
- package/es/components/molecules/EditorScript/index.js +1 -0
- package/es/components/molecules/EditorScript/styled.d.ts +1 -0
- package/es/components/molecules/EditorScript/styled.js +3 -0
- package/es/components/molecules/Modal/index.d.ts +1 -0
- package/es/components/molecules/Modal/styled.js +2 -0
- package/es/components/molecules/ModalV2/ModalV2.d.ts +5 -0
- package/es/components/molecules/ModalV2/ModalV2.js +26 -0
- package/es/components/molecules/ModalV2/index.d.ts +2 -0
- package/es/components/molecules/ModalV2/index.js +1 -0
- package/es/components/molecules/ModalV2/styled.d.ts +7 -0
- package/es/components/molecules/ModalV2/styled.js +22 -0
- package/es/components/molecules/PreviewModal/PreviewModal.d.ts +7 -0
- package/es/components/molecules/PreviewModal/PreviewModal.js +30 -0
- package/es/components/molecules/PreviewModal/index.d.ts +2 -0
- package/es/components/molecules/PreviewModal/index.js +1 -0
- package/es/components/molecules/PreviewModal/styled.d.ts +4 -0
- package/es/components/molecules/PreviewModal/styled.js +39 -0
- package/es/components/molecules/ResizeGrid/ResizeGrid.d.ts +3 -0
- package/es/components/molecules/ResizeGrid/ResizeGrid.js +728 -0
- package/es/components/molecules/ResizeGrid/components/Cell/Cell.d.ts +3 -0
- package/es/components/molecules/ResizeGrid/components/Cell/Cell.js +87 -0
- package/es/components/molecules/ResizeGrid/components/Cell/index.d.ts +1 -0
- package/es/components/molecules/ResizeGrid/components/Cell/index.js +1 -0
- package/es/components/molecules/ResizeGrid/components/Cell/styled.d.ts +3 -0
- package/es/components/molecules/ResizeGrid/components/Cell/styled.js +80 -0
- package/es/components/molecules/ResizeGrid/constant.d.ts +35 -0
- package/es/components/molecules/ResizeGrid/constant.js +111 -0
- package/es/components/molecules/ResizeGrid/index.d.ts +2 -0
- package/es/components/molecules/ResizeGrid/index.js +1 -0
- package/es/components/molecules/ResizeGrid/styled.d.ts +10 -0
- package/es/components/molecules/ResizeGrid/styled.js +56 -0
- package/es/components/molecules/ResizeGrid/types.d.ts +147 -0
- package/es/components/molecules/ResizeGrid/types.js +1 -0
- package/es/components/molecules/RichMenu/RichMenuBlock/RichMenuBlock.d.ts +13 -0
- package/es/components/molecules/RichMenu/RichMenuBlock/RichMenuBlock.js +53 -0
- package/es/components/molecules/RichMenu/RichMenuBlock/RichMenuCell/index.d.ts +18 -0
- package/es/components/molecules/RichMenu/RichMenuBlock/RichMenuCell/index.js +110 -0
- package/es/components/molecules/RichMenu/RichMenuBlock/RichMenuCell/styled.d.ts +20 -0
- package/es/components/molecules/RichMenu/RichMenuBlock/RichMenuCell/styled.js +135 -0
- package/es/components/molecules/RichMenu/RichMenuBlock/constants.d.ts +2 -0
- package/es/components/molecules/RichMenu/RichMenuBlock/constants.js +765 -0
- package/es/components/molecules/RichMenu/RichMenuBlock/index.d.ts +3 -0
- package/es/components/molecules/RichMenu/RichMenuBlock/index.js +2 -0
- package/es/components/molecules/RichMenu/RichMenuBlock/styled.d.ts +9 -0
- package/es/components/molecules/RichMenu/RichMenuBlock/styled.js +17 -0
- package/es/components/molecules/RichMenu/RichMenuChatBar/RichMenuChatBar.d.ts +10 -0
- package/es/components/molecules/RichMenu/RichMenuChatBar/RichMenuChatBar.js +32 -0
- package/es/components/molecules/RichMenu/RichMenuChatBar/TypingChat/index.d.ts +6 -0
- package/es/components/molecules/RichMenu/RichMenuChatBar/TypingChat/index.js +15 -0
- package/es/components/molecules/RichMenu/RichMenuChatBar/TypingChat/styled.d.ts +4 -0
- package/es/components/molecules/RichMenu/RichMenuChatBar/TypingChat/styled.js +47 -0
- package/es/components/molecules/RichMenu/RichMenuChatBar/index.d.ts +2 -0
- package/es/components/molecules/RichMenu/RichMenuChatBar/index.js +1 -0
- package/es/components/molecules/RichMenu/RichMenuChatBar/styled.d.ts +9 -0
- package/es/components/molecules/RichMenu/RichMenuChatBar/styled.js +37 -0
- package/es/components/molecules/RichMenu/RichMenuMobileView/RichMenuMobileView.d.ts +10 -0
- package/es/components/molecules/RichMenu/RichMenuMobileView/RichMenuMobileView.js +37 -0
- package/es/components/molecules/RichMenu/RichMenuMobileView/index.d.ts +1 -0
- package/es/components/molecules/RichMenu/RichMenuMobileView/index.js +1 -0
- package/es/components/molecules/RichMenu/RichMenuMobileView/styled.d.ts +6 -0
- package/es/components/molecules/RichMenu/RichMenuMobileView/styled.js +20 -0
- package/es/components/molecules/RichMenu/index.d.ts +3 -0
- package/es/components/molecules/RichMenu/index.js +3 -0
- package/es/components/molecules/TreeSelect/TreeSelect.d.ts +1 -1
- package/es/components/molecules/UploadImage/MediaThumb.d.ts +8 -0
- package/es/components/molecules/UploadImage/MediaThumb.js +15 -0
- package/es/components/molecules/UploadImage/VideoThumbnail.d.ts +4 -0
- package/es/components/molecules/UploadImage/VideoThumbnail.js +43 -0
- package/es/components/molecules/UploadImage/index.d.ts +6 -2
- package/es/components/molecules/UploadImage/index.js +105 -85
- package/es/components/molecules/UploadImage/styled.js +0 -4
- package/es/components/molecules/UploadImage/utils.d.ts +3 -0
- package/es/components/molecules/UploadImage/utils.js +24 -0
- package/es/components/molecules/index.d.ts +8 -1
- package/es/components/molecules/index.js +6 -1
- package/es/constants/index.d.ts +1 -0
- package/es/constants/index.js +1 -0
- package/es/constants/queries.d.ts +14 -0
- package/es/constants/queries.js +21 -0
- package/es/constants/richMenu.d.ts +19 -0
- package/es/constants/richMenu.js +19 -0
- package/es/constants/storybook.d.ts +5 -0
- package/es/constants/storybook.js +12 -0
- package/es/constants/theme.js +5 -0
- package/es/hooks/index.d.ts +1 -0
- package/es/hooks/index.js +1 -0
- package/es/hooks/useDeepCompareEffect.d.ts +1 -0
- package/es/hooks/useDeepCompareEffect.js +21 -0
- package/es/hooks/useDeepCompareMemo.d.ts +2 -0
- package/es/hooks/useDeepCompareMemo.js +21 -0
- package/es/locales/en/translation.json +167 -1
- package/es/locales/i18n.d.ts +167 -0
- package/es/locales/translations.d.ts +166 -0
- package/es/locales/vi/translation.json +2 -1
- package/es/models/BusinessObject.d.ts +116 -0
- package/es/models/BusinessObject.js +113 -0
- package/es/models/Currency.d.ts +9 -0
- package/es/models/Currency.js +10 -0
- package/es/models/CustomFunction.d.ts +19 -0
- package/es/models/CustomFunction.js +25 -0
- package/es/models/DynamicContentAttribute.d.ts +34 -0
- package/es/models/DynamicContentAttribute.js +9 -0
- package/es/models/EventTrackingAttribute.d.ts +11 -0
- package/es/models/EventTrackingAttribute.js +13 -0
- package/es/models/PromotionPool.d.ts +11 -0
- package/es/models/PromotionPool.js +12 -0
- package/es/models/{SavedImage.d.ts → SavedMedia.d.ts} +5 -5
- package/es/models/{SavedImage.js → SavedMedia.js} +3 -3
- package/es/queries/BusinessObject/index.d.ts +6 -0
- package/es/queries/BusinessObject/index.js +6 -0
- package/es/queries/BusinessObject/useGetListAllEvents.d.ts +11 -0
- package/es/queries/BusinessObject/useGetListAllEvents.js +14 -0
- package/es/queries/BusinessObject/useGetListAttributeBO.d.ts +17 -0
- package/es/queries/BusinessObject/useGetListAttributeBO.js +41 -0
- package/es/queries/BusinessObject/useGetListBO.d.ts +6 -0
- package/es/queries/BusinessObject/useGetListBO.js +19 -0
- package/es/queries/BusinessObject/useGetListEventAttr.d.ts +4 -0
- package/es/queries/BusinessObject/useGetListEventAttr.js +15 -0
- package/es/queries/BusinessObject/useGetListPromotionCodeAttr.d.ts +6 -0
- package/es/queries/BusinessObject/useGetListPromotionCodeAttr.js +26 -0
- package/es/queries/BusinessObject/useGetListSourceByEvent.d.ts +13 -0
- package/es/queries/BusinessObject/useGetListSourceByEvent.js +11 -0
- package/es/queries/CustomFunction/index.d.ts +2 -0
- package/es/queries/CustomFunction/index.js +2 -0
- package/es/queries/CustomFunction/useCustomFunction.d.ts +19 -0
- package/es/queries/CustomFunction/useCustomFunction.js +53 -0
- package/es/queries/DynamicContentAttribute/index.d.ts +1 -0
- package/es/queries/DynamicContentAttribute/index.js +1 -0
- package/es/queries/DynamicContentAttribute/useGetDynamicContentAttr.d.ts +10 -0
- package/es/queries/DynamicContentAttribute/useGetDynamicContentAttr.js +21 -0
- package/es/queries/PromotionPool/index.d.ts +1 -0
- package/es/queries/PromotionPool/index.js +1 -0
- package/es/queries/PromotionPool/useGetListPromotionPool.d.ts +9 -0
- package/es/queries/PromotionPool/useGetListPromotionPool.js +62 -0
- package/es/queries/ThirdParty/index.d.ts +1 -0
- package/es/queries/ThirdParty/index.js +1 -0
- package/es/queries/ThirdParty/useGetEventTrackingAttributes.d.ts +14 -0
- package/es/queries/ThirdParty/useGetEventTrackingAttributes.js +15 -0
- package/es/queries/configs.d.ts +4 -0
- package/es/queries/configs.js +13 -0
- package/es/queries/index.d.ts +6 -0
- package/es/queries/index.js +6 -0
- package/es/services/MediaTemplateDesign/BusinessObject/index.d.ts +8 -0
- package/es/services/MediaTemplateDesign/BusinessObject/index.js +100 -0
- package/es/services/MediaTemplateDesign/CustomFunction/index.d.ts +15 -0
- package/es/services/MediaTemplateDesign/CustomFunction/index.js +135 -0
- package/es/services/MediaTemplateDesign/DynamicContentAttribute/index.d.ts +4 -0
- package/es/services/MediaTemplateDesign/DynamicContentAttribute/index.js +39 -0
- package/es/services/MediaTemplateDesign/ListCurrency/index.d.ts +6 -0
- package/es/services/MediaTemplateDesign/ListCurrency/index.js +34 -0
- package/es/services/MediaTemplateDesign/PromotionPool/index.d.ts +3 -0
- package/es/services/MediaTemplateDesign/PromotionPool/index.js +31 -0
- package/es/services/MediaTemplateDesign/UploadFile/index.d.ts +5 -5
- package/es/services/MediaTemplateDesign/UploadFile/index.js +36 -19
- package/es/services/ThirParty/index.d.ts +8 -0
- package/es/services/ThirParty/index.js +26 -0
- package/es/services/index.d.ts +14 -5
- package/es/services/index.js +45 -1
- package/es/test.js +96 -47
- package/es/types/index.d.ts +17 -0
- package/es/types/index.js +2 -1
- package/es/types/richMenu.d.ts +214 -0
- package/es/types/richMenu.js +1 -0
- package/es/types/variables.d.ts +2 -0
- package/es/types/variables.js +1 -0
- package/es/utils/common.d.ts +3 -0
- package/es/utils/common.js +17 -0
- package/es/utils/handleError.d.ts +32 -2
- package/es/utils/handleError.js +42 -4
- package/package.json +17 -5
|
Binary file
|
|
Binary file
|
|
@@ -8,6 +8,9 @@ export interface InputProps extends AntdInputProps {
|
|
|
8
8
|
onAfterChange?: (value: any) => void;
|
|
9
9
|
errorArchive?: string;
|
|
10
10
|
required?: boolean;
|
|
11
|
+
isReverseMask?: boolean;
|
|
12
|
+
labelColor?: string;
|
|
13
|
+
isHideErrMessage?: boolean;
|
|
11
14
|
focused?: boolean;
|
|
12
15
|
errorMsg?: string;
|
|
13
16
|
disableUndo?: boolean;
|
|
@@ -24,7 +24,7 @@ import { StyledInput } from './styled';
|
|
|
24
24
|
const PATH = '@antscorp/antsomi-ui/es/components/atoms/Input/Input.tsx';
|
|
25
25
|
const OriginInput = props => {
|
|
26
26
|
// Props
|
|
27
|
-
const { debounce, errorArchive, required, focused, label, onAfterChange, onChange, errorMsg } = props, restProps = __rest(props, ["debounce", "errorArchive", "required", "focused", "label", "onAfterChange", "onChange", "errorMsg"]);
|
|
27
|
+
const { debounce, errorArchive, required, labelColor, isReverseMask, isHideErrMessage, focused, label, onAfterChange, onChange, errorMsg } = props, restProps = __rest(props, ["debounce", "errorArchive", "required", "labelColor", "isReverseMask", "isHideErrMessage", "focused", "label", "onAfterChange", "onChange", "errorMsg"]);
|
|
28
28
|
// State
|
|
29
29
|
const [value, setValue] = useState(props.value);
|
|
30
30
|
const [isFocused, setFocused] = useState(false);
|
|
@@ -68,7 +68,7 @@ const OriginInput = props => {
|
|
|
68
68
|
};
|
|
69
69
|
const renderRequiredLabel = (label) => {
|
|
70
70
|
if (required) {
|
|
71
|
-
return (React.createElement(RequiredLabel, { color:
|
|
71
|
+
return (React.createElement(RequiredLabel, { isReverseMask: isReverseMask, color: labelColor || '#666666', style: { marginBottom: 5 } }, label));
|
|
72
72
|
}
|
|
73
73
|
return (React.createElement(Text, { color: "#666666", style: { marginBottom: 5 } }, label));
|
|
74
74
|
};
|
|
@@ -84,10 +84,11 @@ const OriginInput = props => {
|
|
|
84
84
|
}
|
|
85
85
|
restProps.onBlur && restProps.onBlur(e);
|
|
86
86
|
}, onChange: onChangeInput }, getPreventKeyboardAction(listDisableActions))),
|
|
87
|
-
restProps.status === 'error' || errorArchive || requiredMsg ? (React.createElement(Text, { color: "#ff4d4f", style: { marginLeft: 8, marginTop: 5 } }, errorMsg || errorArchive || requiredMsg)) : null));
|
|
87
|
+
(restProps.status === 'error' || errorArchive || requiredMsg) && !isHideErrMessage ? (React.createElement(Text, { color: "#ff4d4f", style: { marginLeft: 8, marginTop: 5 } }, errorMsg || errorArchive || requiredMsg)) : null));
|
|
88
88
|
};
|
|
89
89
|
OriginInput.defaultProps = {
|
|
90
90
|
debounce: 400,
|
|
91
|
+
isHideErrMessage: false,
|
|
91
92
|
};
|
|
92
93
|
export const Input = OriginInput;
|
|
93
94
|
Input.TextArea = StyledInput.TextArea;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/* eslint-disable no-cond-assign */
|
|
2
|
+
/* eslint-disable no-plusplus */
|
|
3
|
+
/* eslint-disable one-var */
|
|
4
|
+
/* eslint-disable func-names */
|
|
5
|
+
/* eslint-disable object-shorthand */
|
|
6
|
+
/* eslint-disable prefer-const */
|
|
7
|
+
const EditCaretPositioning = {};
|
|
8
|
+
if (window.getSelection && document.createRange) {
|
|
9
|
+
// saves caret position(s)
|
|
10
|
+
EditCaretPositioning.saveSelection = function (containerEl) {
|
|
11
|
+
var _a;
|
|
12
|
+
try {
|
|
13
|
+
let range = (_a = window === null || window === void 0 ? void 0 : window.getSelection()) === null || _a === void 0 ? void 0 : _a.getRangeAt(0);
|
|
14
|
+
let preSelectionRange = range === null || range === void 0 ? void 0 : range.cloneRange();
|
|
15
|
+
preSelectionRange === null || preSelectionRange === void 0 ? void 0 : preSelectionRange.selectNodeContents(containerEl);
|
|
16
|
+
preSelectionRange === null || preSelectionRange === void 0 ? void 0 : preSelectionRange.setEnd(range === null || range === void 0 ? void 0 : range.startContainer, range === null || range === void 0 ? void 0 : range.startOffset);
|
|
17
|
+
let start = preSelectionRange === null || preSelectionRange === void 0 ? void 0 : preSelectionRange.toString().length;
|
|
18
|
+
return {
|
|
19
|
+
start: start,
|
|
20
|
+
end: start + (range === null || range === void 0 ? void 0 : range.toString().length),
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
catch (e) {
|
|
24
|
+
// eslint-disable-next-line no-console
|
|
25
|
+
console.log('err:>', e);
|
|
26
|
+
}
|
|
27
|
+
return {
|
|
28
|
+
start: 0,
|
|
29
|
+
end: 0,
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
// restores caret position(s)
|
|
33
|
+
EditCaretPositioning.restoreSelection = function (containerEl, savedSel) {
|
|
34
|
+
let charIndex = 0, range = document.createRange();
|
|
35
|
+
range.setStart(containerEl, 0);
|
|
36
|
+
range.collapse(true);
|
|
37
|
+
let nodeStack = [containerEl], node, foundStart = false, stop = false;
|
|
38
|
+
while (!stop && (node = nodeStack.pop())) {
|
|
39
|
+
if (node.nodeType === 3) {
|
|
40
|
+
let nextCharIndex = charIndex + node.length;
|
|
41
|
+
if (!foundStart &&
|
|
42
|
+
savedSel &&
|
|
43
|
+
savedSel.start >= charIndex &&
|
|
44
|
+
savedSel.start <= nextCharIndex) {
|
|
45
|
+
range.setStart(node, savedSel.start - charIndex);
|
|
46
|
+
foundStart = true;
|
|
47
|
+
}
|
|
48
|
+
if (foundStart && savedSel.end >= charIndex && savedSel.end <= nextCharIndex) {
|
|
49
|
+
range.setEnd(node, savedSel.end - charIndex);
|
|
50
|
+
stop = true;
|
|
51
|
+
}
|
|
52
|
+
charIndex = nextCharIndex;
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
let i = node.childNodes.length;
|
|
56
|
+
while (i--) {
|
|
57
|
+
nodeStack.push(node.childNodes[i]);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
let sel = window.getSelection();
|
|
62
|
+
sel === null || sel === void 0 ? void 0 : sel.removeAllRanges();
|
|
63
|
+
sel === null || sel === void 0 ? void 0 : sel.addRange(range);
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
else if (document.selection && document.body.createTextRange) {
|
|
67
|
+
// saves caret position(s)
|
|
68
|
+
EditCaretPositioning.saveSelection = function (containerEl) {
|
|
69
|
+
let selectedTextRange = document.selection.createRange();
|
|
70
|
+
let preSelectionTextRange = document.body.createTextRange();
|
|
71
|
+
preSelectionTextRange.moveToElementText(containerEl);
|
|
72
|
+
preSelectionTextRange.setEndPoint('EndToStart', selectedTextRange);
|
|
73
|
+
let start = preSelectionTextRange.text.length;
|
|
74
|
+
return {
|
|
75
|
+
start: start,
|
|
76
|
+
end: start + selectedTextRange.text.length,
|
|
77
|
+
};
|
|
78
|
+
};
|
|
79
|
+
// restores caret position(s)
|
|
80
|
+
EditCaretPositioning.restoreSelection = function (containerEl, savedSel) {
|
|
81
|
+
let textRange = document.body.createTextRange();
|
|
82
|
+
textRange.moveToElementText(containerEl);
|
|
83
|
+
textRange.collapse(true);
|
|
84
|
+
textRange.moveEnd('character', savedSel.end);
|
|
85
|
+
textRange.moveStart('character', savedSel.start);
|
|
86
|
+
textRange.select();
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
export default EditCaretPositioning;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { InputDynamicProps } from './types';
|
|
3
|
+
export declare const AllowDynamicType: {
|
|
4
|
+
readonly SHORTLINK: "shortlink";
|
|
5
|
+
readonly ADDPERSONALIZATION: "addPersonalization";
|
|
6
|
+
};
|
|
7
|
+
export declare const InputDynamic: {
|
|
8
|
+
(props: InputDynamicProps): React.JSX.Element;
|
|
9
|
+
defaultProps: InputDynamicProps;
|
|
10
|
+
};
|
|
@@ -0,0 +1,516 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-unused-expressions */
|
|
2
|
+
// Libraries
|
|
3
|
+
import React, { useState, useLayoutEffect, useEffect, useRef, useCallback, useMemo, } from 'react';
|
|
4
|
+
import classnames from 'classnames';
|
|
5
|
+
import { has, isEmpty, omit } from 'lodash';
|
|
6
|
+
// Components
|
|
7
|
+
import CaretPositioning from './EditCaretPositioning';
|
|
8
|
+
import { WrapperInputStyle, TooltipHover, DynamicItem } from './styled';
|
|
9
|
+
import { Popover } from 'antd';
|
|
10
|
+
import { AddDynamicContent } from '../../molecules/AddDynamicContent';
|
|
11
|
+
import { PopupShortLink } from './PopupShortLink';
|
|
12
|
+
import Icon from '@antscorp/icons';
|
|
13
|
+
// Utils
|
|
14
|
+
import { getObjectPropSafely, random, safeParse } from '@antscorp/antsomi-ui/es/utils';
|
|
15
|
+
import { convertBreakTag, convertDivToBreakTag, convertHtmlText, genShortLinkValue, getInsertLinkPatternWithAppendSpaceEnd, getInsertPatternWithAppendSpaceEnd, handleUpdateInputPersonalization, initialValue, mapLabelPersonalization, pasteHtmlAtCaret, removeHtmlTag, spacingNonTracking, validateHTMLTags, createElement, getBgColorByContentSourceType, } from './utils';
|
|
16
|
+
// Hooks
|
|
17
|
+
import { useDebounce } from '@antscorp/antsomi-ui/es/hooks/useDebounce';
|
|
18
|
+
// Constants
|
|
19
|
+
import { THEME } from '@antscorp/antsomi-ui/es/constants';
|
|
20
|
+
const PATH = 'src/components/atoms/InputDynamic/InputDynamic.tsx';
|
|
21
|
+
export const AllowDynamicType = {
|
|
22
|
+
SHORTLINK: 'shortlink',
|
|
23
|
+
ADDPERSONALIZATION: 'addPersonalization',
|
|
24
|
+
};
|
|
25
|
+
const defaultProps = {
|
|
26
|
+
value: '',
|
|
27
|
+
isViewMode: false,
|
|
28
|
+
isRealTime: true,
|
|
29
|
+
errors: [],
|
|
30
|
+
ms: 450,
|
|
31
|
+
canMultipleLine: false,
|
|
32
|
+
apiConfig: {
|
|
33
|
+
domain: 'https://sandbox-media-template.antsomi.com/cdp',
|
|
34
|
+
slug: '/api/v1',
|
|
35
|
+
token: '5474r2x214z2a4b403e4y446p4b4t2b4t474j4t2i5',
|
|
36
|
+
accountId: '1600085679',
|
|
37
|
+
userId: '1600085679',
|
|
38
|
+
},
|
|
39
|
+
disabled: false,
|
|
40
|
+
showIndex: true,
|
|
41
|
+
showDisplayFormat: true,
|
|
42
|
+
isShowCustomFunction: true,
|
|
43
|
+
onError: () => { },
|
|
44
|
+
onChange: () => { },
|
|
45
|
+
addMessageToQueue: () => { },
|
|
46
|
+
};
|
|
47
|
+
export const InputDynamic = (props) => {
|
|
48
|
+
const { value, isViewMode, isRealTime, ms, errors, disabledOpts, disabled, canMultipleLine, allowDynamicOptions, showIndex, showDisplayFormat, isShowCustomFunction, apiConfig, onError, onChange, addMessageToQueue, } = props;
|
|
49
|
+
// States
|
|
50
|
+
const [textValue, setTextValue] = useState(initialValue(value));
|
|
51
|
+
const [initSelectedProperties, setInitSelectedProperties] = useState({
|
|
52
|
+
keyTag: 'shortlink_static',
|
|
53
|
+
link: '',
|
|
54
|
+
urlDetected: '',
|
|
55
|
+
});
|
|
56
|
+
const [isShowPopover, setIsShowPopover] = useState(false);
|
|
57
|
+
const [dynamicContent, setDynamicContent] = useState({
|
|
58
|
+
visible: false,
|
|
59
|
+
defaultData: {},
|
|
60
|
+
activeTagId: '',
|
|
61
|
+
contentSources: {
|
|
62
|
+
groups: [],
|
|
63
|
+
expanded: [],
|
|
64
|
+
isLoadingDataBO: false,
|
|
65
|
+
},
|
|
66
|
+
journeySettings: {
|
|
67
|
+
unsubscribeSegmentType: 'customer',
|
|
68
|
+
triggerType: 'event_based',
|
|
69
|
+
triggerEvent: {
|
|
70
|
+
eventActionId: '',
|
|
71
|
+
eventCategoryId: '',
|
|
72
|
+
insightPropertyIds: [],
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
});
|
|
76
|
+
const [popoverOpenShortLink, setPopoverOpenShortLink] = useState(false);
|
|
77
|
+
const [tooltipHoverDebounce, _tooltipHover, setTooltipHover] = useDebounce({ x: 0, y: 0 }, 200);
|
|
78
|
+
// Refs
|
|
79
|
+
const caretPositionRef = useRef(null);
|
|
80
|
+
const timerRef = useRef();
|
|
81
|
+
const personalizationInputRef = useRef(null);
|
|
82
|
+
const isRenderAddDynamicContent = useMemo(() => {
|
|
83
|
+
if (isEmpty(apiConfig) ||
|
|
84
|
+
isEmpty(allowDynamicOptions) ||
|
|
85
|
+
(allowDynamicOptions &&
|
|
86
|
+
allowDynamicOptions.findIndex(dynamicKey => dynamicKey === AllowDynamicType.ADDPERSONALIZATION) === -1))
|
|
87
|
+
return false;
|
|
88
|
+
return true;
|
|
89
|
+
}, [apiConfig, allowDynamicOptions]);
|
|
90
|
+
const onTriggerChange = (event = null) => {
|
|
91
|
+
var _a;
|
|
92
|
+
try {
|
|
93
|
+
let tmp = (_a = personalizationInputRef.current) === null || _a === void 0 ? void 0 : _a.innerHTML;
|
|
94
|
+
if (event !== null) {
|
|
95
|
+
caretPositionRef.current = CaretPositioning.saveSelection(event.currentTarget);
|
|
96
|
+
tmp = event.currentTarget.innerHTML;
|
|
97
|
+
}
|
|
98
|
+
tmp = tmp === null || tmp === void 0 ? void 0 : tmp.replace(
|
|
99
|
+
// replace old non tracking url to detect url
|
|
100
|
+
/<button(?=[^>]*class="insert-word")[^>]*value=['"]#(?:{nontrackurl\()?(https?:\/\/[0-9a-zA-Z-{}|"\./?_=&%:#*@;]+)(?:\)})?['"][^>]*>.*?<\/button>/g, match => {
|
|
101
|
+
const url = match.match(/(https?:\/\/[0-9a-zA-Z-\./?_=&%:#*@;]+)(?![^ ])/);
|
|
102
|
+
if (url) {
|
|
103
|
+
return `<span id="${random(5)}" class="detect-url">${url[1]}</span>`;
|
|
104
|
+
}
|
|
105
|
+
return match; // If no match found, return the original string
|
|
106
|
+
}).replace(
|
|
107
|
+
// replace url to detect url
|
|
108
|
+
/((?<!class="detect-url">|#{shortlink(?:_static)?\(|<span style="line-height: 20px;margin-right: 8px;pointer-events:none;">)\bhttps*:\/\/[0-9a-zA-Z-{}|"\./?_=&%:#*@;]+)/g, match => `<span id="${random(5)}" class="detect-url">${match}</span>`);
|
|
109
|
+
tmp = convertDivToBreakTag(tmp);
|
|
110
|
+
setTextValue(tmp);
|
|
111
|
+
const text = convertHtmlText(tmp, 'raw', {}, {}, 'input', 'add');
|
|
112
|
+
const textConverted = convertBreakTag(text);
|
|
113
|
+
onChange(removeHtmlTag(textConverted));
|
|
114
|
+
}
|
|
115
|
+
catch (error) {
|
|
116
|
+
if (typeof addMessageToQueue === 'function') {
|
|
117
|
+
addMessageToQueue({
|
|
118
|
+
path: 'app/containers/UIDev/UIEditorPersonalization/Input/index.jsx',
|
|
119
|
+
func: 'onTriggerChange',
|
|
120
|
+
data: error,
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
// eslint-disable-next-line no-console
|
|
124
|
+
console.error(error);
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
const handleHidePopover = () => {
|
|
128
|
+
setIsShowPopover(false);
|
|
129
|
+
};
|
|
130
|
+
const handleOpenChangeAddDynamicContent = useCallback((newChange) => {
|
|
131
|
+
setDynamicContent(prev => (Object.assign(Object.assign({}, prev), { visible: newChange })));
|
|
132
|
+
}, []);
|
|
133
|
+
const handleOpenChange = (newOpen) => {
|
|
134
|
+
if (disabled)
|
|
135
|
+
return;
|
|
136
|
+
setDynamicContent(prev => (Object.assign(Object.assign({}, prev), { activeTagId: '' })));
|
|
137
|
+
setIsShowPopover(newOpen);
|
|
138
|
+
};
|
|
139
|
+
const callback = (type, data) => {
|
|
140
|
+
var _a, _b;
|
|
141
|
+
switch (type) {
|
|
142
|
+
case 'REPLACE_DETECTED_URL': {
|
|
143
|
+
const innerHTML = getObjectPropSafely(() => { var _a; return (_a = personalizationInputRef.current) === null || _a === void 0 ? void 0 : _a.innerHTML; }, '');
|
|
144
|
+
if (innerHTML) {
|
|
145
|
+
// remove span url và focus vào vị trí remove để add tag shortlink vào vị trí này.
|
|
146
|
+
const index = Array.from((_a = personalizationInputRef.current) === null || _a === void 0 ? void 0 : _a.childNodes).findIndex((element) => element.id === data.id);
|
|
147
|
+
const range = document.createRange(); // Tạo một đối tượng Range
|
|
148
|
+
const sel = window.getSelection(); // Lấy đối tượng Selection hiện tại
|
|
149
|
+
range.setStart((_b = personalizationInputRef.current) === null || _b === void 0 ? void 0 : _b.childNodes[index], 0); // Đặt điểm bắt đầu của Range
|
|
150
|
+
range.collapse(true); // Thu gọn Range để tập trung vào điểm bắt đầu
|
|
151
|
+
sel === null || sel === void 0 ? void 0 : sel.removeAllRanges(); // Xóa tất cả các Range hiện có
|
|
152
|
+
sel === null || sel === void 0 ? void 0 : sel.addRange(range); // Thêm Range mới vào Selection
|
|
153
|
+
caretPositionRef.current = CaretPositioning.saveSelection(personalizationInputRef.current);
|
|
154
|
+
const newDataUpdate = innerHTML.replace(data.outerHTML, '');
|
|
155
|
+
personalizationInputRef.current.innerHTML = newDataUpdate;
|
|
156
|
+
}
|
|
157
|
+
break;
|
|
158
|
+
}
|
|
159
|
+
default:
|
|
160
|
+
break;
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
const handleChangeInputDebounce = (ms) => {
|
|
164
|
+
clearTimeout(timerRef.current);
|
|
165
|
+
timerRef.current = setTimeout(() => {
|
|
166
|
+
caretPositionRef.current = CaretPositioning.saveSelection(personalizationInputRef.current);
|
|
167
|
+
onTriggerChange();
|
|
168
|
+
}, ms);
|
|
169
|
+
};
|
|
170
|
+
const onPaste = (e) => {
|
|
171
|
+
var _a;
|
|
172
|
+
// cancel paste
|
|
173
|
+
e.preventDefault();
|
|
174
|
+
// get text representation of clipboard
|
|
175
|
+
const text = (e.originalEvent || e).clipboardData.getData('text/plain');
|
|
176
|
+
handleChangeInputDebounce(ms);
|
|
177
|
+
// insert text manually
|
|
178
|
+
document.execCommand('insertHTML', false, text);
|
|
179
|
+
(_a = personalizationInputRef.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
180
|
+
};
|
|
181
|
+
const handleInsertSortLink = (url, type) => {
|
|
182
|
+
try {
|
|
183
|
+
const { id, value: linkValue, label: linkLabel } = genShortLinkValue(url, type);
|
|
184
|
+
setPopoverOpenShortLink(false);
|
|
185
|
+
if (personalizationInputRef.current instanceof HTMLElement) {
|
|
186
|
+
CaretPositioning.restoreSelection(personalizationInputRef.current, caretPositionRef.current);
|
|
187
|
+
pasteHtmlAtCaret(getInsertLinkPatternWithAppendSpaceEnd(id, linkValue, linkLabel), null);
|
|
188
|
+
onTriggerChange();
|
|
189
|
+
caretPositionRef.current = CaretPositioning.saveSelection(personalizationInputRef.current);
|
|
190
|
+
}
|
|
191
|
+
setInitSelectedProperties({ link: '', keyTag: 'shortlink_static', urlDetected: '' });
|
|
192
|
+
}
|
|
193
|
+
catch (err) {
|
|
194
|
+
if (typeof addMessageToQueue === 'function') {
|
|
195
|
+
addMessageToQueue({
|
|
196
|
+
path: 'app/containers/UIDev/UIEditorPersonalization/Input/index.jsx',
|
|
197
|
+
func: 'handleInsertText',
|
|
198
|
+
data: err,
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
};
|
|
203
|
+
const handleCloseAddDynamicContent = () => {
|
|
204
|
+
setDynamicContent(Object.assign(Object.assign({}, dynamicContent), { visible: false }));
|
|
205
|
+
};
|
|
206
|
+
const handleInsertText = (dataObj) => {
|
|
207
|
+
try {
|
|
208
|
+
const id = random(5);
|
|
209
|
+
const { mappingFields = '', type = '', attribute = {}, customFunction = {} } = dataObj;
|
|
210
|
+
const isCustom = type === 'custom';
|
|
211
|
+
const personalizationCode = isCustom ? mappingFields : `#{${mappingFields}||""}`;
|
|
212
|
+
const bgColor = getBgColorByContentSourceType(type);
|
|
213
|
+
const label = getObjectPropSafely(() => isCustom ? customFunction.templateName : attribute.label);
|
|
214
|
+
if (personalizationInputRef.current instanceof HTMLElement) {
|
|
215
|
+
if (dynamicContent.activeTagId) {
|
|
216
|
+
// for case update
|
|
217
|
+
const element = document.getElementById(dynamicContent.activeTagId);
|
|
218
|
+
const child = createElement('em', {
|
|
219
|
+
class: 'editor-icon-remove',
|
|
220
|
+
style: 'color: white;font-style: normal;',
|
|
221
|
+
}, ['x']);
|
|
222
|
+
const newElement = createElement('button', {
|
|
223
|
+
id,
|
|
224
|
+
class: 'insert-word',
|
|
225
|
+
style: `color: white; font-size: inherit; outline: none;border: 1px solid transparent; border-radius: 1.2rem; max-height: 30px; cursor: pointer; backgroundColor: ${bgColor}`,
|
|
226
|
+
contentEditable: 'false',
|
|
227
|
+
value: `${personalizationCode.replace(/\s/gm, ' ')}`,
|
|
228
|
+
}, [
|
|
229
|
+
`${getObjectPropSafely(() => isCustom ? customFunction.templateName : attribute.label)} `,
|
|
230
|
+
child,
|
|
231
|
+
]);
|
|
232
|
+
if (element && element.parentNode) {
|
|
233
|
+
element.parentNode.replaceChild(newElement, element);
|
|
234
|
+
}
|
|
235
|
+
setDynamicContent(prev => (Object.assign(Object.assign({}, prev), { activeTagId: dynamicContent.activeTagId, defaultData: Object.assign(Object.assign({}, (prev.defaultData || {})), { [dynamicContent.activeTagId]: dataObj }), visible: false })));
|
|
236
|
+
onTriggerChange();
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
personalizationInputRef.current.focus();
|
|
240
|
+
CaretPositioning.restoreSelection(personalizationInputRef.current, caretPositionRef.current);
|
|
241
|
+
pasteHtmlAtCaret(getInsertPatternWithAppendSpaceEnd(id, personalizationCode, label, bgColor), null, () => {
|
|
242
|
+
caretPositionRef.current = CaretPositioning.saveSelection(personalizationInputRef.current);
|
|
243
|
+
onTriggerChange();
|
|
244
|
+
});
|
|
245
|
+
setDynamicContent(prev => (Object.assign(Object.assign({}, prev), { activeTagId: id, defaultData: Object.assign(Object.assign({}, (prev.defaultData || {})), { [id]: dataObj }), visible: false })));
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
catch (error) {
|
|
249
|
+
if (typeof addMessageToQueue === 'function') {
|
|
250
|
+
addMessageToQueue({
|
|
251
|
+
path: PATH,
|
|
252
|
+
func: 'handleInsertText',
|
|
253
|
+
data: error,
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
// eslint-disable-next-line no-console
|
|
257
|
+
console.log(error);
|
|
258
|
+
}
|
|
259
|
+
};
|
|
260
|
+
const handleKeyPress = (e) => {
|
|
261
|
+
if (isRealTime) {
|
|
262
|
+
handleChangeInputDebounce(ms);
|
|
263
|
+
}
|
|
264
|
+
if (canMultipleLine)
|
|
265
|
+
return;
|
|
266
|
+
if (+e.charCode === 13) {
|
|
267
|
+
e.preventDefault();
|
|
268
|
+
}
|
|
269
|
+
};
|
|
270
|
+
const getDangerouslySetInnerHTML = (text) => {
|
|
271
|
+
if (text) {
|
|
272
|
+
const regex = /<[^<>]+>/g;
|
|
273
|
+
let tag;
|
|
274
|
+
// eslint-disable-next-line no-cond-assign
|
|
275
|
+
while ((tag = regex.exec(text))) {
|
|
276
|
+
if (!validateHTMLTags.isValidTag(tag[0])) {
|
|
277
|
+
const finalTag = tag[0].replace('<', '<').replace('>', '>');
|
|
278
|
+
text = text.replace(tag[0], finalTag);
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
text = text.replaceAll('\n', '<br>');
|
|
282
|
+
if (spacingNonTracking(text)) {
|
|
283
|
+
return text;
|
|
284
|
+
}
|
|
285
|
+
return safeParse(text, '').concat('<br />');
|
|
286
|
+
}
|
|
287
|
+
return '';
|
|
288
|
+
};
|
|
289
|
+
const toggleShortLinkModal = useCallback(() => {
|
|
290
|
+
setPopoverOpenShortLink(!popoverOpenShortLink);
|
|
291
|
+
}, [popoverOpenShortLink]);
|
|
292
|
+
const handleClickDynamicItem = (e, dynamicKey) => {
|
|
293
|
+
e.stopPropagation();
|
|
294
|
+
handleHidePopover();
|
|
295
|
+
if (dynamicKey === AllowDynamicType.SHORTLINK) {
|
|
296
|
+
toggleShortLinkModal();
|
|
297
|
+
}
|
|
298
|
+
if (dynamicKey === AllowDynamicType.ADDPERSONALIZATION) {
|
|
299
|
+
handleOpenChangeAddDynamicContent(true);
|
|
300
|
+
}
|
|
301
|
+
};
|
|
302
|
+
/**
|
|
303
|
+
* [NOTE:open modal to edit]
|
|
304
|
+
*/
|
|
305
|
+
useEffect(() => {
|
|
306
|
+
const handleClickTag = (e) => {
|
|
307
|
+
try {
|
|
308
|
+
e.stopPropagation();
|
|
309
|
+
if (e.target) {
|
|
310
|
+
const { value = '', id = '' } = e.target;
|
|
311
|
+
const shortLink = value.replace(/#|{|}|/g, '').split('(');
|
|
312
|
+
if (shortLink && shortLink.length >= 2) {
|
|
313
|
+
const link = shortLink[1].substring(0, shortLink[1].length - 1) || '';
|
|
314
|
+
setInitSelectedProperties(prev => (Object.assign(Object.assign({}, prev), { link, keyTag: shortLink[0], urlDetected: e.currentTarget })));
|
|
315
|
+
toggleShortLinkModal();
|
|
316
|
+
}
|
|
317
|
+
else {
|
|
318
|
+
setDynamicContent(prev => (Object.assign(Object.assign({}, prev), { activeTagId: id })));
|
|
319
|
+
handleOpenChangeAddDynamicContent(true);
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
catch (err) {
|
|
324
|
+
// eslint-disable-next-line no-console
|
|
325
|
+
console.log('err', err);
|
|
326
|
+
}
|
|
327
|
+
};
|
|
328
|
+
const listTags = Array.from(document.querySelectorAll('#ants-ui-input-personalization .input-personal .insert-word'));
|
|
329
|
+
if (listTags && listTags.length > 0) {
|
|
330
|
+
listTags.forEach((tag) => {
|
|
331
|
+
tag.addEventListener('click', handleClickTag);
|
|
332
|
+
});
|
|
333
|
+
}
|
|
334
|
+
return () => {
|
|
335
|
+
listTags.forEach((tag) => {
|
|
336
|
+
tag.removeEventListener('click', handleClickTag);
|
|
337
|
+
});
|
|
338
|
+
};
|
|
339
|
+
}, [handleOpenChangeAddDynamicContent, textValue, toggleShortLinkModal]);
|
|
340
|
+
/** Anchor tooltip */
|
|
341
|
+
useEffect(() => {
|
|
342
|
+
let listElement = [];
|
|
343
|
+
const handleMouseOver = (e, targetRect) => {
|
|
344
|
+
e === null || e === void 0 ? void 0 : e.stopPropagation();
|
|
345
|
+
const viewportTop = window.pageYOffset;
|
|
346
|
+
const viewportLeft = window.pageXOffset;
|
|
347
|
+
const offsetWidth = targetRect.width / 2;
|
|
348
|
+
const offsetHeight = targetRect.height / 2;
|
|
349
|
+
const tooltipHeight = 16;
|
|
350
|
+
const x = targetRect.left - viewportLeft + offsetWidth;
|
|
351
|
+
const y = targetRect.top - viewportTop - offsetHeight - tooltipHeight;
|
|
352
|
+
setTooltipHover({
|
|
353
|
+
x,
|
|
354
|
+
y,
|
|
355
|
+
});
|
|
356
|
+
};
|
|
357
|
+
const handleMouseOut = (e) => {
|
|
358
|
+
e === null || e === void 0 ? void 0 : e.stopPropagation();
|
|
359
|
+
setTooltipHover({ x: 0, y: 0 });
|
|
360
|
+
};
|
|
361
|
+
const handleClickDetectUrl = (e) => {
|
|
362
|
+
e === null || e === void 0 ? void 0 : e.stopPropagation();
|
|
363
|
+
setInitSelectedProperties(prev => {
|
|
364
|
+
var _a;
|
|
365
|
+
return (Object.assign(Object.assign({}, prev), { link: ((_a = e === null || e === void 0 ? void 0 : e.currentTarget) === null || _a === void 0 ? void 0 : _a.textContent) || '', urlDetected: e === null || e === void 0 ? void 0 : e.currentTarget }));
|
|
366
|
+
});
|
|
367
|
+
toggleShortLinkModal();
|
|
368
|
+
};
|
|
369
|
+
if (!isViewMode) {
|
|
370
|
+
const elements = document.querySelectorAll('#ants-ui-input-personalization .detect-url');
|
|
371
|
+
listElement = Array.from(elements);
|
|
372
|
+
if (listElement.length) {
|
|
373
|
+
listElement.forEach((element) => {
|
|
374
|
+
element.addEventListener('mouseover', e => handleMouseOver(e, element.getBoundingClientRect()));
|
|
375
|
+
element.addEventListener('mouseout', handleMouseOut);
|
|
376
|
+
/** Open shortlink modal */
|
|
377
|
+
element.addEventListener('click', handleClickDetectUrl);
|
|
378
|
+
});
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
return () => {
|
|
382
|
+
listElement.forEach((element) => {
|
|
383
|
+
element.removeEventListener('mouseover', handleMouseOver);
|
|
384
|
+
element.removeEventListener('mouseout', handleMouseOut);
|
|
385
|
+
});
|
|
386
|
+
};
|
|
387
|
+
}, [textValue, isViewMode, setTooltipHover, toggleShortLinkModal]);
|
|
388
|
+
/** Style & remove for tag shortlink button & icon remove */
|
|
389
|
+
useLayoutEffect(() => {
|
|
390
|
+
// get button Els [x] to create hover and style it
|
|
391
|
+
const iconRemoveEls = document.querySelectorAll('.editor-icon-remove');
|
|
392
|
+
const listIconRemove = iconRemoveEls && Array.from(iconRemoveEls);
|
|
393
|
+
// get button elements
|
|
394
|
+
const buttonElement = document.querySelectorAll('.insert-word');
|
|
395
|
+
const listBtnElement = buttonElement && Array.from(buttonElement);
|
|
396
|
+
const handleRemoveTag = (e) => {
|
|
397
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
398
|
+
if (e && ((_a = e.target) === null || _a === void 0 ? void 0 : _a.nodeName) === 'EM' && ((_b = e.target) === null || _b === void 0 ? void 0 : _b.className) === 'editor-icon-remove') {
|
|
399
|
+
e.stopPropagation();
|
|
400
|
+
if (((_c = e.target) === null || _c === void 0 ? void 0 : _c.parentElement) &&
|
|
401
|
+
has(dynamicContent.defaultData, [(_e = (_d = e.target) === null || _d === void 0 ? void 0 : _d.parentElement) === null || _e === void 0 ? void 0 : _e.id])) {
|
|
402
|
+
setDynamicContent(prev => {
|
|
403
|
+
var _a, _b;
|
|
404
|
+
return (Object.assign(Object.assign({}, prev), { activeTagId: '', defaultData: omit(prev.defaultData, [(_b = (_a = e.target) === null || _a === void 0 ? void 0 : _a.parentElement) === null || _b === void 0 ? void 0 : _b.id]) }));
|
|
405
|
+
});
|
|
406
|
+
}
|
|
407
|
+
(_g = (_f = e.target) === null || _f === void 0 ? void 0 : _f.parentElement) === null || _g === void 0 ? void 0 : _g.remove();
|
|
408
|
+
setTextValue(personalizationInputRef && ((_h = personalizationInputRef.current) === null || _h === void 0 ? void 0 : _h.innerHTML));
|
|
409
|
+
}
|
|
410
|
+
};
|
|
411
|
+
listIconRemove.forEach(eachIcon => {
|
|
412
|
+
eachIcon.addEventListener('click', handleRemoveTag);
|
|
413
|
+
});
|
|
414
|
+
handleUpdateInputPersonalization(listIconRemove, listBtnElement);
|
|
415
|
+
return () => {
|
|
416
|
+
listIconRemove.forEach(eachIcon => {
|
|
417
|
+
eachIcon.removeEventListener('click', handleRemoveTag);
|
|
418
|
+
});
|
|
419
|
+
};
|
|
420
|
+
}, [dynamicContent.defaultData, textValue]);
|
|
421
|
+
useLayoutEffect(() => {
|
|
422
|
+
try {
|
|
423
|
+
// save caret position
|
|
424
|
+
if (!personalizationInputRef.current) {
|
|
425
|
+
return;
|
|
426
|
+
}
|
|
427
|
+
// Perhaps React (whose VDOM gets outdated because we often prevent
|
|
428
|
+
// rerendering) did not update the DOM. So we update it manually now.
|
|
429
|
+
if (caretPositionRef && caretPositionRef.current) {
|
|
430
|
+
CaretPositioning.restoreSelection(personalizationInputRef.current, caretPositionRef.current);
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
catch (error) {
|
|
434
|
+
if (typeof addMessageToQueue === 'function') {
|
|
435
|
+
addMessageToQueue({
|
|
436
|
+
path: PATH,
|
|
437
|
+
func: 'useLayoutEffect',
|
|
438
|
+
data: error,
|
|
439
|
+
});
|
|
440
|
+
}
|
|
441
|
+
if (typeof onError === 'function') {
|
|
442
|
+
onError(error, {
|
|
443
|
+
component: PATH,
|
|
444
|
+
action: 'useLayoutEffect saved caret position',
|
|
445
|
+
args: {},
|
|
446
|
+
});
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
}, [addMessageToQueue, onError, textValue]);
|
|
450
|
+
const renderContentDynamicOptions = () => {
|
|
451
|
+
if (!(allowDynamicOptions === null || allowDynamicOptions === void 0 ? void 0 : allowDynamicOptions.length)) {
|
|
452
|
+
return null;
|
|
453
|
+
}
|
|
454
|
+
return allowDynamicOptions.map((dynamicKey) => (React.createElement(DynamicItem, { key: dynamicKey, onClick: e => handleClickDynamicItem(e, dynamicKey) }, mapLabelPersonalization(dynamicKey))));
|
|
455
|
+
};
|
|
456
|
+
const renderAddPersonalizationView = () => {
|
|
457
|
+
var _a, _b;
|
|
458
|
+
if (isViewMode) {
|
|
459
|
+
return null;
|
|
460
|
+
}
|
|
461
|
+
const isRenderPopover = allowDynamicOptions && (allowDynamicOptions === null || allowDynamicOptions === void 0 ? void 0 : allowDynamicOptions.length) > 1;
|
|
462
|
+
const isOnlyOneOpt = allowDynamicOptions && (allowDynamicOptions === null || allowDynamicOptions === void 0 ? void 0 : allowDynamicOptions.length) === 1;
|
|
463
|
+
const hasOnlyPersonalization = isOnlyOneOpt && (allowDynamicOptions === null || allowDynamicOptions === void 0 ? void 0 : allowDynamicOptions.includes(AllowDynamicType.ADDPERSONALIZATION));
|
|
464
|
+
const hasOnlyShortlink = isOnlyOneOpt && (allowDynamicOptions === null || allowDynamicOptions === void 0 ? void 0 : allowDynamicOptions.includes(AllowDynamicType.SHORTLINK));
|
|
465
|
+
const iconPersonalization = (React.createElement(Icon, { type: "icon-ants-person-alt", onClick: e => {
|
|
466
|
+
e.stopPropagation();
|
|
467
|
+
if (disabled || isRenderPopover)
|
|
468
|
+
return;
|
|
469
|
+
// Open short link modal
|
|
470
|
+
if (hasOnlyShortlink) {
|
|
471
|
+
toggleShortLinkModal();
|
|
472
|
+
}
|
|
473
|
+
else if (hasOnlyPersonalization) {
|
|
474
|
+
// Open Personalization modal
|
|
475
|
+
setDynamicContent(prev => (Object.assign(Object.assign({}, prev), { activeTagId: '', visible: true })));
|
|
476
|
+
}
|
|
477
|
+
else {
|
|
478
|
+
toggleShortLinkModal();
|
|
479
|
+
}
|
|
480
|
+
}, className: "customize-antsomi-profile", style: {
|
|
481
|
+
width: 24,
|
|
482
|
+
height: 24,
|
|
483
|
+
color: disabled ? (_a = THEME.token) === null || _a === void 0 ? void 0 : _a.colorTextDisabled : (_b = THEME.token) === null || _b === void 0 ? void 0 : _b.colorPrimary,
|
|
484
|
+
cursor: disabled ? 'not-allowed' : 'pointer',
|
|
485
|
+
} }));
|
|
486
|
+
if (!isRenderPopover) {
|
|
487
|
+
return iconPersonalization;
|
|
488
|
+
}
|
|
489
|
+
return (React.createElement(Popover, { content: renderContentDynamicOptions(), placement: "bottomLeft", rootClassName: "no-padding-content", trigger: "click", open: isShowPopover, onOpenChange: handleOpenChange }, iconPersonalization));
|
|
490
|
+
};
|
|
491
|
+
return (React.createElement(WrapperInputStyle, { id: "ants-ui-input-personalization" },
|
|
492
|
+
React.createElement("div", { className: classnames({
|
|
493
|
+
'input-wrapper-outter': true,
|
|
494
|
+
'styles-input-wrapper': !isViewMode,
|
|
495
|
+
'input-error': (errors === null || errors === void 0 ? void 0 : errors.length) && (errors === null || errors === void 0 ? void 0 : errors.length) > 0,
|
|
496
|
+
}), style: Object.assign(Object.assign({}, (isViewMode && {
|
|
497
|
+
padding: 0,
|
|
498
|
+
minHeight: 0,
|
|
499
|
+
fontSize: 12,
|
|
500
|
+
border: 'none',
|
|
501
|
+
})), { width: '100%' }), onClick: () => { var _a; return (_a = personalizationInputRef.current) === null || _a === void 0 ? void 0 : _a.focus(); } },
|
|
502
|
+
React.createElement("div", { className: "input-personal", style: {
|
|
503
|
+
display: textValue && textValue !== '<br>' ? 'inline-block' : undefined,
|
|
504
|
+
}, contentEditable: !isViewMode, onBlur: onTriggerChange, onKeyPress: handleKeyPress, ref: personalizationInputRef,
|
|
505
|
+
// eslint-disable-next-line react/no-danger
|
|
506
|
+
dangerouslySetInnerHTML: {
|
|
507
|
+
__html: getDangerouslySetInnerHTML(textValue),
|
|
508
|
+
}, onPaste: onPaste }),
|
|
509
|
+
renderAddPersonalizationView()),
|
|
510
|
+
React.createElement(TooltipHover, { isShow: tooltipHoverDebounce.x > 0 && tooltipHoverDebounce.y > 0, top: tooltipHoverDebounce.y, left: tooltipHoverDebounce.x }, "Click on the link to convert it to a shortlink"),
|
|
511
|
+
popoverOpenShortLink && (React.createElement(PopupShortLink, { open: popoverOpenShortLink, disabledOpts: disabledOpts, onOk: handleInsertSortLink, onClose: toggleShortLinkModal, initSelectedProperties: initSelectedProperties, callback: callback })),
|
|
512
|
+
isRenderAddDynamicContent && (React.createElement(AddDynamicContent, { APIConfig: apiConfig, defaultDynamicIndex: 1, showIndex: showIndex, showDisplayFormat: showDisplayFormat, isShowCustomFunction: isShowCustomFunction, visible: dynamicContent.visible, defaultData: dynamicContent.defaultData[dynamicContent.activeTagId] || {}, journeySettings: dynamicContent.journeySettings, contentSources: dynamicContent.contentSources, onOk: (value) => {
|
|
513
|
+
handleInsertText(value);
|
|
514
|
+
}, onCancel: () => handleCloseAddDynamicContent() }))));
|
|
515
|
+
};
|
|
516
|
+
InputDynamic.defaultProps = defaultProps;
|