@flozy/editor 5.4.0 → 5.4.2

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.
@@ -20,12 +20,18 @@ const handleTableCell = (el, children) => {
20
20
  }
21
21
  };
22
22
  };
23
- const PARA_WRAP = ["A"];
23
+ 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"];
24
24
  const paragraphType = el => {
25
25
  const {
26
26
  childNodes = []
27
27
  } = el || {};
28
- const isHavingText = childNodes?.length ? Array.from(childNodes)?.find(child => child?.nodeType === 3 || TEXT_TAGS[child?.nodeName] || PARA_WRAP.includes(child.nodeName)) : null;
28
+
29
+ // if anyone of the child node is text node or wrapped with inline tags, it is considered to be an paragraph node
30
+ const isHavingText = childNodes?.length ? Array.from(childNodes)?.some(child => {
31
+ const isTextNode = child?.nodeType === 3;
32
+ const isHavingInlineTags = TEXT_TAGS[child?.nodeName] || INLINE_TAGS.includes(child.nodeName);
33
+ return isTextNode || isHavingInlineTags;
34
+ }) : null;
29
35
  return isHavingText ? {
30
36
  type: "paragraph"
31
37
  } : {};
@@ -124,11 +130,10 @@ const TEXT_TAGS = {
124
130
  }),
125
131
  U: () => ({
126
132
  underline: true
127
- }),
128
- B: () => ({
129
- bold: true
130
133
  })
134
+ // B: () => ({ bold: true }),
131
135
  };
136
+
132
137
  const deserialize = el => {
133
138
  if (el.nodeType === 3) {
134
139
  const match = /\r|\n/.exec(el.textContent);
@@ -148,12 +153,9 @@ const deserialize = el => {
148
153
  }
149
154
  let children = Array.from(parent.childNodes).map(deserialize).flat();
150
155
  if (children.length === 0) {
151
- children = {
152
- type: "paragraph",
153
- children: [{
154
- text: ""
155
- }]
156
- };
156
+ children = [{
157
+ text: ""
158
+ }];
157
159
  }
158
160
  if (el.nodeName === "BODY") {
159
161
  return jsx("fragment", {}, children);
@@ -169,7 +171,14 @@ const deserialize = el => {
169
171
  }
170
172
  if (TEXT_TAGS[nodeName]) {
171
173
  const attrs = TEXT_TAGS[nodeName](el);
172
- return children.map(child => jsx("text", attrs, child));
174
+ return children.map(child => {
175
+ if (child?.type) {
176
+ // 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
177
+ return child;
178
+ } else {
179
+ return jsx("text", attrs, child);
180
+ }
181
+ });
173
182
  }
174
183
  return children;
175
184
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flozy/editor",
3
- "version": "5.4.0",
3
+ "version": "5.4.2",
4
4
  "description": "An Editor for flozy app brain",
5
5
  "files": [
6
6
  "dist"