@flozy/editor 5.4.1 → 5.4.3
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.
@@ -17,12 +17,20 @@ const handleTableCell = (el, children) => {
|
|
17
17
|
overwriteChild: wrapChild
|
18
18
|
};
|
19
19
|
};
|
20
|
-
const
|
20
|
+
const INLINE_TAGS = ["A", "ABBR", "B", "BDO", "CITE", "CODE", "DATA", "DEL", "DFN", "IMG", "INS", "KBD", "LABEL", "MARK", "Q", "SAMP", "SMALL", "SPAN", "SUB", "SUP", "TIME", "VAR"];
|
21
|
+
|
22
|
+
// to avoid nested paragraph to resolve performace issue
|
21
23
|
const paragraphType = el => {
|
22
24
|
const {
|
23
25
|
childNodes = []
|
24
26
|
} = el || {};
|
25
|
-
|
27
|
+
|
28
|
+
// if anyone of the child node is text node or wrapped with inline tags, it is considered to be an paragraph node
|
29
|
+
const isHavingText = childNodes?.length ? Array.from(childNodes)?.some(child => {
|
30
|
+
const isTextNode = child?.nodeType === 3;
|
31
|
+
const isHavingInlineTags = TEXT_TAGS[child?.nodeName] || INLINE_TAGS.includes(child.nodeName);
|
32
|
+
return isTextNode || isHavingInlineTags;
|
33
|
+
}) : null;
|
26
34
|
return isHavingText ? {
|
27
35
|
type: "paragraph"
|
28
36
|
} : {};
|
@@ -121,11 +129,10 @@ const TEXT_TAGS = {
|
|
121
129
|
}),
|
122
130
|
U: () => ({
|
123
131
|
underline: true
|
124
|
-
}),
|
125
|
-
B: () => ({
|
126
|
-
bold: true
|
127
132
|
})
|
133
|
+
// B: () => ({ bold: true }),
|
128
134
|
};
|
135
|
+
|
129
136
|
const deserialize = el => {
|
130
137
|
if (el.nodeType === 3) {
|
131
138
|
const match = /\r|\n/.exec(el.textContent);
|
@@ -145,12 +152,9 @@ const deserialize = el => {
|
|
145
152
|
}
|
146
153
|
let children = Array.from(parent.childNodes).map(deserialize).flat();
|
147
154
|
if (children.length === 0) {
|
148
|
-
children = {
|
149
|
-
|
150
|
-
|
151
|
-
text: ""
|
152
|
-
}]
|
153
|
-
};
|
155
|
+
children = [{
|
156
|
+
text: ""
|
157
|
+
}];
|
154
158
|
}
|
155
159
|
if (el.nodeName === "BODY") {
|
156
160
|
return jsx("fragment", {}, children);
|
@@ -166,7 +170,14 @@ const deserialize = el => {
|
|
166
170
|
}
|
167
171
|
if (TEXT_TAGS[nodeName]) {
|
168
172
|
const attrs = TEXT_TAGS[nodeName](el);
|
169
|
-
return children.map(child =>
|
173
|
+
return children.map(child => {
|
174
|
+
if (child?.type) {
|
175
|
+
// if any list elements (like ul, ol... tags) is wrapped inside the TEXT_TAGS, we will return child as it is, else return it as text node
|
176
|
+
return child;
|
177
|
+
} else {
|
178
|
+
return jsx("text", attrs, child);
|
179
|
+
}
|
180
|
+
});
|
170
181
|
}
|
171
182
|
return children;
|
172
183
|
};
|