@seafile/sea-email-editor 0.0.13 → 0.0.14

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.
@@ -11,6 +11,7 @@ var _constants = require("./constants");
11
11
  var _rules = _interopRequireDefault(require("./rules"));
12
12
  var _helper = require("./helper");
13
13
  var _dom = require("../../utils/dom");
14
+ var _constants2 = require("../../extension/constants");
14
15
  const generateDefaultValue = () => {
15
16
  return [{
16
17
  id: _slugid.default.nice(),
@@ -107,12 +108,75 @@ const deserializeElements = function () {
107
108
  // return node;
108
109
  // };
109
110
 
111
+ // Split block-level children out of a paragraph-like node into siblings.
112
+ // Recursively processes children of any block node to flatten nested structures.
113
+ const flattenNestedBlockChildren = (children, parentNode) => {
114
+ const result = [];
115
+ let inlineChildren = [];
116
+ for (const child of children) {
117
+ if (child.type && _constants.TOP_LEVEL_TYPES.includes(child.type)) {
118
+ if (inlineChildren.length > 0) {
119
+ result.push({
120
+ id: _slugid.default.nice(),
121
+ type: parentNode.type,
122
+ children: inlineChildren
123
+ });
124
+ inlineChildren = [];
125
+ }
126
+ // If this block child itself has children with nested blocks, recurse
127
+ if (Array.isArray(child.children) && child.children.some(c => c.type && _constants.TOP_LEVEL_TYPES.includes(c.type))) {
128
+ const flattened = flattenNestedBlockChildren(child.children, {
129
+ type: _constants2.ElementTypes.PARAGRAPH
130
+ });
131
+ // Paragraph types cannot contain block children — spread as siblings
132
+ if (child.type === _constants2.ElementTypes.PARAGRAPH || child.type === _constants2.ElementTypes.P) {
133
+ result.push(...flattened);
134
+ } else {
135
+ result.push({
136
+ ...child,
137
+ children: flattened
138
+ });
139
+ }
140
+ } else {
141
+ result.push(child);
142
+ }
143
+ } else {
144
+ inlineChildren.push(child);
145
+ }
146
+ }
147
+ if (inlineChildren.length > 0) {
148
+ result.push({
149
+ id: _slugid.default.nice(),
150
+ type: parentNode.type,
151
+ children: inlineChildren
152
+ });
153
+ }
154
+ return result;
155
+ };
110
156
  const formatElementNodes = nodes => {
111
157
  if (nodes.length === 0) {
112
158
  return generateDefaultValue();
113
159
  }
114
160
  nodes = nodes.reduce((memo, node) => {
115
161
  if (_constants.TOP_LEVEL_TYPES.includes(node.type)) {
162
+ // If a paragraph-like node contains nested block-level children,
163
+ // split them into sibling relationships
164
+ if ((node.type === _constants2.ElementTypes.PARAGRAPH || node.type === _constants2.ElementTypes.P) && Array.isArray(node.children) && node.children.some(child => child.type && _constants.TOP_LEVEL_TYPES.includes(child.type))) {
165
+ const flattened = flattenNestedBlockChildren(node.children, node);
166
+ memo.push(...flattened);
167
+ return memo;
168
+ }
169
+
170
+ // Blockquote may also contain nested paragraphs that need flattening
171
+ if (node.type === _constants2.ElementTypes.BLOCKQUOTE && Array.isArray(node.children) && node.children.some(child => child.type && _constants.TOP_LEVEL_TYPES.includes(child.type))) {
172
+ memo.push({
173
+ ...node,
174
+ children: flattenNestedBlockChildren(node.children, {
175
+ type: _constants2.ElementTypes.PARAGRAPH
176
+ })
177
+ });
178
+ return memo;
179
+ }
116
180
  memo.push(node);
117
181
  }
118
182
  if (node.type === _constants.LIST_ITEM) {
package/dist/utils/dom.js CHANGED
@@ -142,14 +142,26 @@ const removeInvalidNodes = root => {
142
142
  elementsToRemove.forEach(element => {
143
143
  element.remove();
144
144
  });
145
- for (let i = root.childNodes.length - 1; i >= 0; i--) {
146
- const child = root.childNodes[i];
145
+ const children = Array.from(root.childNodes);
146
+ let prevWasBr = false;
147
+ children.forEach(child => {
147
148
  if (child.nodeType === Node.COMMENT_NODE) {
148
149
  root.removeChild(child);
149
150
  } else if (child.nodeType === Node.ELEMENT_NODE) {
150
- removeInvalidNodes(child);
151
+ if (child.nodeName === 'BR') {
152
+ if (prevWasBr) {
153
+ root.removeChild(child);
154
+ } else {
155
+ prevWasBr = true;
156
+ }
157
+ } else {
158
+ prevWasBr = false;
159
+ removeInvalidNodes(child);
160
+ }
161
+ } else {
162
+ prevWasBr = false;
151
163
  }
152
- }
164
+ });
153
165
  };
154
166
  const stripCSSComments = function () {
155
167
  let cssText = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seafile/sea-email-editor",
3
- "version": "0.0.13",
3
+ "version": "0.0.14",
4
4
  "description": "A Slate-based rich email editor with HTML, markdown, tables, images, links, and block plugins.",
5
5
  "main": "dist/index.js",
6
6
  "dependencies": {