@flozy/editor 3.6.5 → 3.6.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/dist/Editor/ChatEditor.js +202 -0
- package/dist/Editor/CommonEditor.js +166 -109
- package/dist/Editor/Elements/AppHeader/AppHeader.js +39 -15
- package/dist/Editor/Elements/Button/EditorButton.js +25 -14
- package/dist/Editor/Elements/Color Picker/ColorButtons.js +60 -17
- package/dist/Editor/Elements/Color Picker/ColorPicker.css +25 -1
- package/dist/Editor/Elements/Color Picker/ColorPicker.js +4 -4
- package/dist/Editor/Elements/Color Picker/Styles.js +2 -1
- package/dist/Editor/Elements/Embed/Frames/ImageFrame.js +1 -0
- package/dist/Editor/Elements/Emoji/EmojiButton.js +2 -2
- package/dist/Editor/Elements/Emoji/EmojiPicker.js +16 -0
- package/dist/Editor/Elements/Form/Workflow/UserInputs.js +2 -1
- package/dist/Editor/Elements/Grid/Grid.js +2 -0
- package/dist/Editor/Elements/Grid/GridItem.js +3 -1
- package/dist/Editor/Elements/Link/Link.js +6 -1
- package/dist/Editor/Elements/Link/LinkButton.js +4 -2
- package/dist/Editor/Elements/Link/LinkPopup.js +11 -3
- package/dist/Editor/Elements/Link/LinkPopupStyles.js +28 -0
- package/dist/Editor/Elements/Table/TableCell.js +1 -1
- package/dist/Editor/MiniEditor.js +3 -1
- package/dist/Editor/Toolbar/Basic/index.js +4 -2
- package/dist/Editor/Toolbar/FormatTools/Dropdown.js +26 -2
- package/dist/Editor/Toolbar/FormatTools/MarkButton.js +2 -2
- package/dist/Editor/Toolbar/FormatTools/TextSize.js +5 -11
- package/dist/Editor/Toolbar/PopupTool/MiniTextFormat/SelectFontSize.js +4 -11
- package/dist/Editor/Toolbar/PopupTool/MiniTextFormat/SelectTypography.js +213 -86
- package/dist/Editor/Toolbar/PopupTool/MiniTextFormat/index.js +2 -1
- package/dist/Editor/Toolbar/PopupTool/PopupToolStyle.js +20 -13
- package/dist/Editor/Toolbar/PopupTool/TextFormat.js +52 -7
- package/dist/Editor/Toolbar/PopupTool/ThemeTextFormat.js +438 -0
- package/dist/Editor/Toolbar/PopupTool/index.js +9 -2
- package/dist/Editor/Toolbar/toolbarGroups.js +48 -6
- package/dist/Editor/assets/svg/ThemeIcons.js +291 -0
- package/dist/Editor/common/ColorPickerButton.js +25 -9
- package/dist/Editor/common/CustomColorPicker/index.js +106 -0
- package/dist/Editor/common/CustomColorPicker/style.js +53 -0
- package/dist/Editor/common/CustomDialog/index.js +94 -0
- package/dist/Editor/common/CustomDialog/style.js +67 -0
- package/dist/Editor/common/CustomSelect.js +33 -0
- package/dist/Editor/common/DnD/DragHandleButton.js +1 -1
- package/dist/Editor/common/Icon.js +30 -2
- package/dist/Editor/common/LinkSettings/NavComponents.js +54 -20
- package/dist/Editor/common/Shorthands/elements.js +54 -0
- package/dist/Editor/common/StyleBuilder/buttonStyle.js +4 -2
- package/dist/Editor/common/StyleBuilder/fieldTypes/bannerSpacing.js +13 -3
- package/dist/Editor/common/StyleBuilder/fieldTypes/borderRadius.js +15 -7
- package/dist/Editor/common/StyleBuilder/fieldTypes/color.js +31 -7
- package/dist/Editor/common/StyleBuilder/fieldTypes/fontSize.js +13 -4
- package/dist/Editor/common/StyleBuilder/fieldTypes/textOptions.js +14 -4
- package/dist/Editor/common/StyleBuilder/index.js +1 -1
- package/dist/Editor/helper/theme.js +190 -4
- package/dist/Editor/hooks/useEditorTheme.js +139 -0
- package/dist/Editor/hooks/useMouseMove.js +4 -1
- package/dist/Editor/plugins/withEmbeds.js +1 -1
- package/dist/Editor/plugins/withHTML.js +47 -5
- package/dist/Editor/plugins/withTable.js +1 -1
- package/dist/Editor/theme/ThemeList.js +50 -173
- package/dist/Editor/theme/index.js +144 -0
- package/dist/Editor/themeSettings/ActiveTheme.js +72 -0
- package/dist/Editor/themeSettings/buttons/index.js +290 -0
- package/dist/Editor/themeSettings/buttons/style.js +21 -0
- package/dist/Editor/themeSettings/colorTheme/index.js +290 -0
- package/dist/Editor/themeSettings/colorTheme/style.js +77 -0
- package/dist/Editor/themeSettings/fonts/PreviewElement.js +123 -0
- package/dist/Editor/themeSettings/fonts/index.js +213 -0
- package/dist/Editor/themeSettings/fonts/style.js +44 -0
- package/dist/Editor/themeSettings/icons.js +60 -0
- package/dist/Editor/themeSettings/index.js +320 -0
- package/dist/Editor/themeSettings/style.js +152 -0
- package/dist/Editor/themeSettingsAI/icons.js +96 -0
- package/dist/Editor/themeSettingsAI/index.js +356 -0
- package/dist/Editor/themeSettingsAI/saveTheme.js +190 -0
- package/dist/Editor/themeSettingsAI/style.js +247 -0
- package/dist/Editor/utils/SlateUtilityFunctions.js +157 -25
- package/dist/Editor/utils/button.js +1 -17
- package/dist/Editor/utils/chatEditor/SlateUtilityFunctions.js +361 -0
- package/dist/Editor/utils/font.js +40 -37
- package/dist/Editor/utils/helper.js +83 -22
- package/dist/Editor/utils/serializeToHTML.js +25 -13
- package/dist/index.js +5 -1
- package/package.json +1 -1
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ReactEditor } from "slate-react";
|
|
2
|
+
import { fontFamilyMap, sizeMap } from "../utils/font";
|
|
3
|
+
import { Editor, Node } from "slate";
|
|
2
4
|
export const breakpoints = {
|
|
3
5
|
small: 0,
|
|
4
6
|
mobile: 600,
|
|
@@ -27,7 +29,7 @@ const overrideValues = (value, ot) => {
|
|
|
27
29
|
return Object.keys(value).reduce((a, b) => {
|
|
28
30
|
return {
|
|
29
31
|
...a,
|
|
30
|
-
[b]: overrides[ot] ? overrides[ot](value[b]) : value
|
|
32
|
+
[b]: overrides[ot] ? overrides[ot](value[b], value) : value
|
|
31
33
|
};
|
|
32
34
|
}, {});
|
|
33
35
|
};
|
|
@@ -44,7 +46,15 @@ const overrides = {
|
|
|
44
46
|
overrideReSizeH: val => {
|
|
45
47
|
return `${val?.height}px`;
|
|
46
48
|
},
|
|
47
|
-
overrideBorderRadius: val => {
|
|
49
|
+
overrideBorderRadius: (val, breakpointValues) => {
|
|
50
|
+
if (!val?.topLeft) {
|
|
51
|
+
Object.values(breakpointValues || {}).forEach(v => {
|
|
52
|
+
if (v) {
|
|
53
|
+
// Applying the values from breakpoints that exist to those that do not have
|
|
54
|
+
val = v;
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
}
|
|
48
58
|
return `${val?.topLeft}px ${val?.topRight}px ${val?.bottomLeft}px ${val?.bottomRight}px`;
|
|
49
59
|
}
|
|
50
60
|
};
|
|
@@ -97,4 +107,180 @@ export const getTRBLBreakPoints = (value, breakpoint) => {
|
|
|
97
107
|
} catch (err) {
|
|
98
108
|
console.log(err);
|
|
99
109
|
}
|
|
100
|
-
};
|
|
110
|
+
};
|
|
111
|
+
export function getElementStyle(editor, element, stylePropertyName) {
|
|
112
|
+
try {
|
|
113
|
+
const path = ReactEditor.findPath(editor, element);
|
|
114
|
+
if (path?.length) {
|
|
115
|
+
const currentEle = Node.get(editor, path);
|
|
116
|
+
const dom = ReactEditor.toDOMNode(editor, currentEle);
|
|
117
|
+
const editorBtn = dom?.querySelector("button.theme-element");
|
|
118
|
+
const elementStyle = window.getComputedStyle(editorBtn);
|
|
119
|
+
const style = elementStyle[stylePropertyName];
|
|
120
|
+
if (stylePropertyName === "fontFamily") {
|
|
121
|
+
const val = Object.entries(fontFamilyMap).find(([key, value]) => value === style)?.[0];
|
|
122
|
+
return val;
|
|
123
|
+
}
|
|
124
|
+
return style;
|
|
125
|
+
}
|
|
126
|
+
} catch (err) {
|
|
127
|
+
// console.log(err);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
export function getTextSizeVal(editor) {
|
|
131
|
+
try {
|
|
132
|
+
const currentNode = Node.get(editor, editor.selection.anchor.path);
|
|
133
|
+
const currentElement = ReactEditor.toDOMNode(editor, currentNode);
|
|
134
|
+
if (currentElement) {
|
|
135
|
+
const element = document.querySelector('span[data-slate-string="true"]');
|
|
136
|
+
const computedStyle = window.getComputedStyle(element);
|
|
137
|
+
return computedStyle.getPropertyValue("font-size") || "";
|
|
138
|
+
}
|
|
139
|
+
} catch (err) {
|
|
140
|
+
// console.log(err);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
export function getVariableValue(val) {
|
|
144
|
+
const bodyElement = document.body;
|
|
145
|
+
const computedStyle = getComputedStyle(bodyElement);
|
|
146
|
+
const [, variableName] = val?.match(/var\((--[^)]+)\)/) || [];
|
|
147
|
+
const varValue = computedStyle.getPropertyValue(variableName).trim();
|
|
148
|
+
return varValue;
|
|
149
|
+
}
|
|
150
|
+
export const textThemeFields = ["fontFamily", "fontSize", "color", "bold", "italic"
|
|
151
|
+
// "underline",
|
|
152
|
+
// "strikethrough",
|
|
153
|
+
];
|
|
154
|
+
|
|
155
|
+
const themeElements = ["headingOne", "headingTwo", "headingThree", "headingFour", "headingFive", "headingSix", "paragraphOne", "paragraphTwo", "paragraphThree"];
|
|
156
|
+
export const isTextCustomized = editor => {
|
|
157
|
+
try {
|
|
158
|
+
if (editor.selection) {
|
|
159
|
+
const currentElement = Node.parent(editor, editor?.selection?.anchor?.path);
|
|
160
|
+
if (!currentElement) {
|
|
161
|
+
return false;
|
|
162
|
+
}
|
|
163
|
+
const {
|
|
164
|
+
children,
|
|
165
|
+
type
|
|
166
|
+
} = currentElement;
|
|
167
|
+
if (!themeElements.includes(type)) {
|
|
168
|
+
return false;
|
|
169
|
+
}
|
|
170
|
+
if (children?.length > 1) {
|
|
171
|
+
return true;
|
|
172
|
+
}
|
|
173
|
+
const customized = textThemeFields.some(field => {
|
|
174
|
+
const element = children[0] || {};
|
|
175
|
+
const value = element[field];
|
|
176
|
+
if (field === "fontSize") {
|
|
177
|
+
return Object.keys(value || {}).length;
|
|
178
|
+
} else {
|
|
179
|
+
return value;
|
|
180
|
+
}
|
|
181
|
+
});
|
|
182
|
+
return customized;
|
|
183
|
+
} else {
|
|
184
|
+
return null;
|
|
185
|
+
}
|
|
186
|
+
} catch (err) {
|
|
187
|
+
return null;
|
|
188
|
+
}
|
|
189
|
+
};
|
|
190
|
+
const addToTheme = (field, value, element) => {
|
|
191
|
+
switch (field) {
|
|
192
|
+
case "fontFamily":
|
|
193
|
+
return {
|
|
194
|
+
fontFamily: fontFamilyMap[value]
|
|
195
|
+
};
|
|
196
|
+
case "fontSize":
|
|
197
|
+
return {
|
|
198
|
+
fontSize: value?.lg
|
|
199
|
+
};
|
|
200
|
+
case "color":
|
|
201
|
+
return {
|
|
202
|
+
color: value
|
|
203
|
+
};
|
|
204
|
+
case "bold":
|
|
205
|
+
return {
|
|
206
|
+
fontWeight: "bold"
|
|
207
|
+
};
|
|
208
|
+
case "italic":
|
|
209
|
+
return {
|
|
210
|
+
fontStyle: "italic"
|
|
211
|
+
};
|
|
212
|
+
// case "underline":
|
|
213
|
+
// case "strikethrough":
|
|
214
|
+
// let textDecoration = "";
|
|
215
|
+
|
|
216
|
+
// if (element.underline) {
|
|
217
|
+
// textDecoration = "underline";
|
|
218
|
+
// }
|
|
219
|
+
|
|
220
|
+
// if (element.strikethrough) {
|
|
221
|
+
// textDecoration += " strikethrough";
|
|
222
|
+
// }
|
|
223
|
+
|
|
224
|
+
// return { textDecoration };
|
|
225
|
+
default:
|
|
226
|
+
return {};
|
|
227
|
+
}
|
|
228
|
+
};
|
|
229
|
+
const MAP_TEXT_THEME_FIELD = {
|
|
230
|
+
headingOne: "h1",
|
|
231
|
+
headingTwo: "h2",
|
|
232
|
+
headingThree: "h3",
|
|
233
|
+
headingFour: "h4",
|
|
234
|
+
headingFive: "h5",
|
|
235
|
+
headingSix: "h6",
|
|
236
|
+
paragraphOne: "para1",
|
|
237
|
+
paragraphTwo: "para2",
|
|
238
|
+
paragraphThree: "para3"
|
|
239
|
+
};
|
|
240
|
+
export const saveToTheme = editor => {
|
|
241
|
+
try {
|
|
242
|
+
if (editor.selection) {
|
|
243
|
+
const currentElement = Node.parent(editor, editor?.selection?.anchor?.path);
|
|
244
|
+
if (!currentElement) {
|
|
245
|
+
return false;
|
|
246
|
+
}
|
|
247
|
+
const {
|
|
248
|
+
children
|
|
249
|
+
} = currentElement;
|
|
250
|
+
if (children?.length > 1) {
|
|
251
|
+
return true;
|
|
252
|
+
}
|
|
253
|
+
let theme = {};
|
|
254
|
+
textThemeFields.forEach(field => {
|
|
255
|
+
const element = children[0] || {};
|
|
256
|
+
const value = element[field];
|
|
257
|
+
let style = {};
|
|
258
|
+
let isValueExist = false;
|
|
259
|
+
if (value) {
|
|
260
|
+
isValueExist = true;
|
|
261
|
+
if (field === "fontSize") {
|
|
262
|
+
isValueExist = !!Object.keys(value).length;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
if (isValueExist) {
|
|
266
|
+
style = addToTheme(field, value, element);
|
|
267
|
+
}
|
|
268
|
+
theme = {
|
|
269
|
+
...theme,
|
|
270
|
+
...style
|
|
271
|
+
};
|
|
272
|
+
});
|
|
273
|
+
textThemeFields.forEach(field => {
|
|
274
|
+
Editor.removeMark(editor, field);
|
|
275
|
+
});
|
|
276
|
+
return {
|
|
277
|
+
field: MAP_TEXT_THEME_FIELD[currentElement?.type],
|
|
278
|
+
theme
|
|
279
|
+
};
|
|
280
|
+
}
|
|
281
|
+
} catch (err) {
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
};
|
|
285
|
+
export const HEADING_THEME_FIELDS = ["h1", "h2", "h3", "h4", "h5", "h6"];
|
|
286
|
+
export const PARAGRAPH_THEME_FIELDS = ["para1", "para2", "para3"];
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { useSlate } from "slate-react";
|
|
2
|
+
import { defaultTheme } from "../theme";
|
|
3
|
+
import { getPageSettings, updatePageSettings } from "../utils/pageSettings";
|
|
4
|
+
import { HEADING_THEME_FIELDS, PARAGRAPH_THEME_FIELDS } from "../helper/theme";
|
|
5
|
+
const MAP_FIELDS = {
|
|
6
|
+
HEADING: HEADING_THEME_FIELDS,
|
|
7
|
+
PARAGRAPH: PARAGRAPH_THEME_FIELDS
|
|
8
|
+
};
|
|
9
|
+
function getUpdatePayload(prevTheme = {}, update, actionData) {
|
|
10
|
+
const {
|
|
11
|
+
action,
|
|
12
|
+
fieldName
|
|
13
|
+
} = actionData || {};
|
|
14
|
+
const {
|
|
15
|
+
theme: prev
|
|
16
|
+
} = prevTheme;
|
|
17
|
+
let theme = {};
|
|
18
|
+
let themeProps = {};
|
|
19
|
+
switch (action) {
|
|
20
|
+
case "THEME_CHANGE":
|
|
21
|
+
theme = update;
|
|
22
|
+
break;
|
|
23
|
+
case "CSS_VAR_CHANGE":
|
|
24
|
+
const prevCssVars = prev?.cssVars || {};
|
|
25
|
+
const prevValue = prevCssVars[fieldName] || {};
|
|
26
|
+
themeProps = {
|
|
27
|
+
...(prev || {}),
|
|
28
|
+
cssVars: {
|
|
29
|
+
...prevCssVars,
|
|
30
|
+
[fieldName]: {
|
|
31
|
+
...prevValue,
|
|
32
|
+
...update
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
theme = {
|
|
37
|
+
...prevTheme,
|
|
38
|
+
theme: themeProps
|
|
39
|
+
};
|
|
40
|
+
break;
|
|
41
|
+
case "ELEMENT_PROPS_CHANGE":
|
|
42
|
+
const prevEleProps = prev?.elementProps || {};
|
|
43
|
+
const prevEleValue = prevEleProps[fieldName] || {};
|
|
44
|
+
themeProps = {
|
|
45
|
+
...(prev || {}),
|
|
46
|
+
elementProps: {
|
|
47
|
+
...prevEleProps,
|
|
48
|
+
[fieldName]: {
|
|
49
|
+
...prevEleValue,
|
|
50
|
+
...update
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
theme = {
|
|
55
|
+
...prevTheme,
|
|
56
|
+
theme: themeProps
|
|
57
|
+
};
|
|
58
|
+
break;
|
|
59
|
+
case "OTHER_PROPS_CHANGE":
|
|
60
|
+
themeProps = {
|
|
61
|
+
...(prev || {}),
|
|
62
|
+
otherProps: {
|
|
63
|
+
...(prev.otherProps || {}),
|
|
64
|
+
...update
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
theme = {
|
|
68
|
+
...prevTheme,
|
|
69
|
+
theme: themeProps
|
|
70
|
+
};
|
|
71
|
+
break;
|
|
72
|
+
case "FONT_CHANGE":
|
|
73
|
+
const {
|
|
74
|
+
elementProps = {},
|
|
75
|
+
otherProps = {}
|
|
76
|
+
} = prev;
|
|
77
|
+
const fields = MAP_FIELDS[actionData?.fieldType];
|
|
78
|
+
const headingUpdate = {};
|
|
79
|
+
fields?.forEach(field => {
|
|
80
|
+
const prevHeadingData = elementProps[field];
|
|
81
|
+
headingUpdate[field] = {
|
|
82
|
+
...prevHeadingData,
|
|
83
|
+
...update
|
|
84
|
+
};
|
|
85
|
+
});
|
|
86
|
+
themeProps = {
|
|
87
|
+
...(prev || {}),
|
|
88
|
+
elementProps: {
|
|
89
|
+
...elementProps,
|
|
90
|
+
...headingUpdate
|
|
91
|
+
},
|
|
92
|
+
otherProps: {
|
|
93
|
+
...otherProps,
|
|
94
|
+
headingFontFamily: update?.fontFamily
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
theme = {
|
|
98
|
+
...prevTheme,
|
|
99
|
+
theme: themeProps
|
|
100
|
+
};
|
|
101
|
+
break;
|
|
102
|
+
default:
|
|
103
|
+
theme = {
|
|
104
|
+
...prevTheme,
|
|
105
|
+
...(update || {})
|
|
106
|
+
};
|
|
107
|
+
break;
|
|
108
|
+
}
|
|
109
|
+
return theme;
|
|
110
|
+
}
|
|
111
|
+
const updateTheme = (editor, pageSt, update, actionData) => {
|
|
112
|
+
const {
|
|
113
|
+
pageProps
|
|
114
|
+
} = pageSt || {};
|
|
115
|
+
const {
|
|
116
|
+
theme
|
|
117
|
+
} = pageProps || {};
|
|
118
|
+
updatePageSettings(editor, {
|
|
119
|
+
...(pageProps || {}),
|
|
120
|
+
theme: getUpdatePayload(theme, update, actionData)
|
|
121
|
+
});
|
|
122
|
+
};
|
|
123
|
+
export const useEditorTheme = () => {
|
|
124
|
+
const editor = useSlate();
|
|
125
|
+
const {
|
|
126
|
+
element: pageSt
|
|
127
|
+
} = getPageSettings(editor) || {};
|
|
128
|
+
const {
|
|
129
|
+
pageProps
|
|
130
|
+
} = pageSt || {};
|
|
131
|
+
const {
|
|
132
|
+
theme
|
|
133
|
+
} = pageProps || {};
|
|
134
|
+
return {
|
|
135
|
+
selectedTheme: theme?.theme || defaultTheme?.theme,
|
|
136
|
+
updateTheme: (update, actionData) => updateTheme(editor, pageSt, update, actionData),
|
|
137
|
+
theme
|
|
138
|
+
};
|
|
139
|
+
};
|
|
@@ -29,6 +29,7 @@ export const EditorProvider = ({
|
|
|
29
29
|
const path = event?.target?.getAttribute("data-path");
|
|
30
30
|
const [popupType, setPopupType] = useState(""); // opened popup name in the editor will be stored
|
|
31
31
|
const [openAI, setOpenAI] = useState("");
|
|
32
|
+
const [selectedTheme, setSelectedTheme] = useState({});
|
|
32
33
|
const onDrop = () => {
|
|
33
34
|
setDrop(drop + 1);
|
|
34
35
|
};
|
|
@@ -55,7 +56,9 @@ export const EditorProvider = ({
|
|
|
55
56
|
popupType,
|
|
56
57
|
setPopupType,
|
|
57
58
|
openAI,
|
|
58
|
-
setOpenAI
|
|
59
|
+
setOpenAI,
|
|
60
|
+
selectedTheme,
|
|
61
|
+
setSelectedTheme
|
|
59
62
|
},
|
|
60
63
|
children: children
|
|
61
64
|
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Transforms, Path, Node } from "slate";
|
|
2
|
-
const AvoidCopying = ["headingOne", "headingTwo", "headingThree", "blockquote"];
|
|
2
|
+
const AvoidCopying = ["headingOne", "headingTwo", "headingThree", "headingFour", "headingFive", "headingSix", "paragraphOne", "paragraphTwo", "paragraphThree", "blockquote"];
|
|
3
3
|
const withEmbeds = editor => {
|
|
4
4
|
const {
|
|
5
5
|
isVoid,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Transforms, Editor, Element, Node } from "slate";
|
|
1
|
+
import { Transforms, Editor, Element, Node, Path } from "slate";
|
|
2
2
|
import deserialize from "../helper/deserialize";
|
|
3
3
|
import { decodeAndParseBase64 } from "../utils/helper";
|
|
4
4
|
const avoidDefaultInsert = ["table", "grid"];
|
|
@@ -15,7 +15,7 @@ const loopChildren = (children = [], defaultInsert) => {
|
|
|
15
15
|
}
|
|
16
16
|
return defaultInsert;
|
|
17
17
|
};
|
|
18
|
-
const getCurrentElement = editor => {
|
|
18
|
+
export const getCurrentElement = editor => {
|
|
19
19
|
try {
|
|
20
20
|
if (editor.selection) {
|
|
21
21
|
return Node.parent(editor, editor?.selection?.anchor?.path);
|
|
@@ -26,6 +26,48 @@ const getCurrentElement = editor => {
|
|
|
26
26
|
return null;
|
|
27
27
|
}
|
|
28
28
|
};
|
|
29
|
+
const getCurrentElementText = editor => {
|
|
30
|
+
try {
|
|
31
|
+
if (editor.selection) {
|
|
32
|
+
return Editor.string(editor, editor?.selection?.anchor?.path);
|
|
33
|
+
} else {
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
} catch (err) {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
const insertAtNextNode = (editor, formattedFragment) => {
|
|
41
|
+
try {
|
|
42
|
+
const {
|
|
43
|
+
selection
|
|
44
|
+
} = editor;
|
|
45
|
+
if (selection) {
|
|
46
|
+
const parentPath = Path.parent(editor?.selection?.anchor?.path);
|
|
47
|
+
const nextPath = Path.next(parentPath);
|
|
48
|
+
Transforms.insertNodes(editor, {
|
|
49
|
+
type: "paragraph",
|
|
50
|
+
children: [{
|
|
51
|
+
text: ""
|
|
52
|
+
}]
|
|
53
|
+
}, {
|
|
54
|
+
at: nextPath
|
|
55
|
+
});
|
|
56
|
+
Transforms.insertFragment(editor, formattedFragment, {
|
|
57
|
+
at: nextPath
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
} catch (err) {
|
|
61
|
+
console.log(err);
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
const handleInsert = (editor, defaultInsert, fragment = []) => {
|
|
65
|
+
if (getCurrentElementText(editor) && fragment.some(f => f.type === "table")) {
|
|
66
|
+
insertAtNextNode(editor, fragment);
|
|
67
|
+
} else {
|
|
68
|
+
defaultInsert();
|
|
69
|
+
}
|
|
70
|
+
};
|
|
29
71
|
const formatFragment = {
|
|
30
72
|
"list-item": fragment => {
|
|
31
73
|
let refactorFragment = [];
|
|
@@ -64,11 +106,11 @@ const withHtml = editor => {
|
|
|
64
106
|
const currentEl = getCurrentElement(editor);
|
|
65
107
|
const eltype = currentEl?.type;
|
|
66
108
|
if (slateHTML && !formatFragment[eltype]) {
|
|
109
|
+
const decoded = decodeAndParseBase64(slateHTML);
|
|
67
110
|
const [tableNode] = Editor.nodes(editor, {
|
|
68
111
|
match: n => !Editor.isEditor(n) && Element.isElement(n) && n.type === "table"
|
|
69
112
|
});
|
|
70
113
|
if (tableNode && tableNode[0]) {
|
|
71
|
-
const decoded = decodeAndParseBase64(slateHTML);
|
|
72
114
|
const defaultInsert = loopChildren(decoded, true);
|
|
73
115
|
if (defaultInsert) {
|
|
74
116
|
insertData(data);
|
|
@@ -79,7 +121,7 @@ const withHtml = editor => {
|
|
|
79
121
|
Transforms.insertText(editor, text);
|
|
80
122
|
}
|
|
81
123
|
} else {
|
|
82
|
-
insertData(data);
|
|
124
|
+
handleInsert(editor, () => insertData(data), decoded);
|
|
83
125
|
}
|
|
84
126
|
} else if (html) {
|
|
85
127
|
const parsed = new DOMParser().parseFromString(html, "text/html");
|
|
@@ -96,7 +138,7 @@ const withHtml = editor => {
|
|
|
96
138
|
}
|
|
97
139
|
const fragment = deserialize(parsed.body);
|
|
98
140
|
const formattedFragment = formatFragment[eltype] ? formatFragment[eltype](fragment) : fragment;
|
|
99
|
-
Transforms.insertFragment(editor, formattedFragment);
|
|
141
|
+
handleInsert(editor, () => Transforms.insertFragment(editor, formattedFragment), formattedFragment);
|
|
100
142
|
return;
|
|
101
143
|
} else {
|
|
102
144
|
insertData(data);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Editor, Range, Point, Element, Transforms, Node } from "slate";
|
|
2
2
|
import { TableUtil, createTableCell } from "../utils/table";
|
|
3
|
-
const NON_DELETABLE_BLOCKS = ["table-cell", "carousel-item"];
|
|
3
|
+
const NON_DELETABLE_BLOCKS = ["table-cell", "carousel-item", "page-settings"];
|
|
4
4
|
const withTable = editor => {
|
|
5
5
|
const {
|
|
6
6
|
deleteBackward,
|