@pushwoosh/dumb-components 1.0.53 → 1.0.55
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.
|
@@ -47,21 +47,16 @@ export const RichMessageEditor = ({
|
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
49
|
};
|
|
50
|
-
const insertDynamicContent = editor => {
|
|
50
|
+
const insertDynamicContent = (editor, dc) => {
|
|
51
51
|
const newDC = {
|
|
52
52
|
type: 'dc',
|
|
53
|
-
dc
|
|
54
|
-
tagName: '',
|
|
55
|
-
modifier: 'regular',
|
|
56
|
-
defaultValue: ''
|
|
57
|
-
},
|
|
53
|
+
dc,
|
|
58
54
|
children: [{
|
|
59
55
|
text: ''
|
|
60
56
|
}]
|
|
61
57
|
};
|
|
62
58
|
Transforms.insertNodes(editor, newDC);
|
|
63
59
|
Transforms.select(editor, editor.selection);
|
|
64
|
-
onSelectionChange(editor.selection);
|
|
65
60
|
};
|
|
66
61
|
const clickAwayHandler = usePersistentFunction(() => {
|
|
67
62
|
setShowDrop(undefined);
|
|
@@ -84,45 +79,54 @@ export const RichMessageEditor = ({
|
|
|
84
79
|
onSelectionChange: onSelectionChange
|
|
85
80
|
}, ({
|
|
86
81
|
editor
|
|
87
|
-
}) =>
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
82
|
+
}) => {
|
|
83
|
+
var _getDcByPath;
|
|
84
|
+
return React.createElement(FieldBox, {
|
|
85
|
+
title: title,
|
|
86
|
+
boxRef: rootRef,
|
|
87
|
+
error: error,
|
|
88
|
+
actions: React.createElement(Collapse, {
|
|
89
|
+
expanded: isFocused
|
|
90
|
+
}, React.createElement(Horizontal, {
|
|
91
|
+
"$gap": 8
|
|
92
|
+
}, canUsePersonalization && React.createElement(ImSpan, {
|
|
93
|
+
onClick: () => showDropArea({
|
|
94
|
+
type: 'personalization'
|
|
95
|
+
})
|
|
96
|
+
}, React.createElement(PersonalizationIcon, null), "Personalization"), canUseEmoji && React.createElement(ImSpan, {
|
|
97
|
+
onClick: () => showDropArea({
|
|
98
|
+
type: 'emoji'
|
|
99
|
+
})
|
|
100
|
+
}, React.createElement(EmojiIcon, null), "Emoji")))
|
|
101
|
+
}, React.createElement(SlateEditable, {
|
|
102
|
+
minHeight: minHeight,
|
|
103
|
+
onFocus: () => {
|
|
104
|
+
setIsFocused(true);
|
|
105
|
+
const {
|
|
106
|
+
selection
|
|
107
|
+
} = editor;
|
|
108
|
+
if (selection) {
|
|
109
|
+
onSelectionChange(selection);
|
|
110
|
+
}
|
|
111
111
|
}
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
112
|
+
}), showDrop && React.createElement(DropContent, {
|
|
113
|
+
top: showDrop.yValue,
|
|
114
|
+
left: showDrop.xValue
|
|
115
|
+
}, showDrop.type === 'personalization' && (renderDynamicContent === null || renderDynamicContent === void 0 ? void 0 : renderDynamicContent({
|
|
116
|
+
dc: showDrop.path ? (_getDcByPath = getDcByPath(editor.children, showDrop.path)) === null || _getDcByPath === void 0 ? void 0 : _getDcByPath.dc : undefined,
|
|
117
|
+
onChange: newDC => {
|
|
118
|
+
if (showDrop.path) {
|
|
119
|
+
Transforms.setNodes(editor, {
|
|
120
|
+
dc: newDC
|
|
121
|
+
}, {
|
|
122
|
+
at: showDrop.path
|
|
123
|
+
});
|
|
124
|
+
} else {
|
|
125
|
+
insertDynamicContent(editor, newDC);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
})), showDrop.type === 'emoji' && React.createElement(EmojiPicker, {
|
|
129
|
+
onEmojiSelect: s => editor.insertText(s)
|
|
130
|
+
})));
|
|
131
|
+
});
|
|
128
132
|
};
|
|
@@ -6,7 +6,7 @@ type DropValueCommon = {
|
|
|
6
6
|
};
|
|
7
7
|
export type DropValuePersonalization = {
|
|
8
8
|
type: 'personalization';
|
|
9
|
-
path
|
|
9
|
+
path?: number[];
|
|
10
10
|
};
|
|
11
11
|
export type DropValueEmoji = {
|
|
12
12
|
type: 'emoji';
|
|
@@ -22,7 +22,7 @@ export type RichMessageEditorProps = {
|
|
|
22
22
|
canUseEmoji?: boolean;
|
|
23
23
|
onBlur?: () => void;
|
|
24
24
|
renderDynamicContent?: (props: {
|
|
25
|
-
dc
|
|
25
|
+
dc?: DynamicContent;
|
|
26
26
|
onChange: (newDC: DynamicContent) => void;
|
|
27
27
|
}) => ReactNode;
|
|
28
28
|
};
|
|
@@ -149,8 +149,8 @@ export function content2string(state) {
|
|
|
149
149
|
export function validateContent(value) {
|
|
150
150
|
for (const el of value) {
|
|
151
151
|
if (isElement(el)) {
|
|
152
|
-
if (el.type === 'dc') {
|
|
153
|
-
return
|
|
152
|
+
if (el.type === 'dc' && !el.dc.tagName) {
|
|
153
|
+
return false;
|
|
154
154
|
}
|
|
155
155
|
if (!validateContent(el.children)) {
|
|
156
156
|
return false;
|