@seafile/sea-email-editor 0.0.10-beta → 0.0.10-beta1
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.
|
@@ -10,7 +10,7 @@ var _typeOf = _interopRequireDefault(require("type-of"));
|
|
|
10
10
|
var _constants = require("./constants");
|
|
11
11
|
var _rules = _interopRequireDefault(require("./rules"));
|
|
12
12
|
var _helper = require("./helper");
|
|
13
|
-
var
|
|
13
|
+
var _dom = require("../../utils/dom");
|
|
14
14
|
const generateDefaultValue = () => {
|
|
15
15
|
return [{
|
|
16
16
|
id: _slugid.default.nice(),
|
|
@@ -149,13 +149,8 @@ const formatElementNodes = nodes => {
|
|
|
149
149
|
return nodes;
|
|
150
150
|
};
|
|
151
151
|
const deserializeHtml = html => {
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
}
|
|
155
|
-
if (typeof html !== 'string') return generateDefaultValue();
|
|
156
|
-
const parsed = new DOMParser().parseFromString(html.replace('\n', '').replace(' ', ''), 'text/html');
|
|
157
|
-
const fragment = parsed.body;
|
|
158
|
-
fragment.querySelectorAll('style, title').forEach(el => el.remove());
|
|
152
|
+
const fragment = (0, _dom.sanitizeHTMLContent)(html);
|
|
153
|
+
if (!fragment) return generateDefaultValue();
|
|
159
154
|
const children = Array.from(fragment.childNodes);
|
|
160
155
|
let nodes = [];
|
|
161
156
|
nodes = deserializeElements(children, true);
|
|
@@ -13,6 +13,7 @@ const paragraphRule = (element, parseChild) => {
|
|
|
13
13
|
nodeName,
|
|
14
14
|
childNodes
|
|
15
15
|
} = element;
|
|
16
|
+
// article
|
|
16
17
|
if ((nodeName === 'DIV' || nodeName === 'ARTICLE') && element.parentElement.nodeName !== 'LI') {
|
|
17
18
|
if (childNodes.length === 0) {
|
|
18
19
|
const node = {
|
|
@@ -25,10 +26,14 @@ const paragraphRule = (element, parseChild) => {
|
|
|
25
26
|
};
|
|
26
27
|
return (0, _helper.mergeElementOther2SlateNode)(element, node);
|
|
27
28
|
}
|
|
29
|
+
const children = parseChild(childNodes);
|
|
28
30
|
const node = {
|
|
29
31
|
id: _slugid.default.nice(),
|
|
30
32
|
type: _constants.PARAGRAPH,
|
|
31
|
-
children:
|
|
33
|
+
children: children.length === 0 ? [{
|
|
34
|
+
id: _slugid.default.nice(),
|
|
35
|
+
text: ''
|
|
36
|
+
}] : children
|
|
32
37
|
};
|
|
33
38
|
return (0, _helper.mergeElementOther2SlateNode)(element, node);
|
|
34
39
|
}
|
package/dist/utils/dom.js
CHANGED
|
@@ -8,7 +8,8 @@ exports.getTarget = exports.getEventClassName = exports.getDataAttr = exports.ca
|
|
|
8
8
|
exports.hasClass = hasClass;
|
|
9
9
|
exports.isNearBottom = exports.isInputOrEditorActive = void 0;
|
|
10
10
|
exports.removeClass = removeClass;
|
|
11
|
-
exports.removeClassName = void 0;
|
|
11
|
+
exports.sanitizeHTMLContent = exports.removeClassName = void 0;
|
|
12
|
+
var _typeDetection = require("./type-detection");
|
|
12
13
|
const canUseDOM = exports.canUseDOM = !!(typeof window !== 'undefined' && window.document && window.document.createElement);
|
|
13
14
|
const getEventClassName = e => {
|
|
14
15
|
// svg mouseEvent event.target.className is an object
|
|
@@ -130,4 +131,28 @@ const isNearBottom = function (element) {
|
|
|
130
131
|
const distanceToBottom = scrollHeight - (scrollTop + clientHeight);
|
|
131
132
|
return distanceToBottom <= threshold;
|
|
132
133
|
};
|
|
133
|
-
exports.isNearBottom = isNearBottom;
|
|
134
|
+
exports.isNearBottom = isNearBottom;
|
|
135
|
+
const removeCommentNodes = node => {
|
|
136
|
+
for (let i = node.childNodes.length - 1; i >= 0; i--) {
|
|
137
|
+
const child = node.childNodes[i];
|
|
138
|
+
if (child.nodeType === Node.COMMENT_NODE) {
|
|
139
|
+
node.removeChild(child);
|
|
140
|
+
} else if (child.nodeType === Node.ELEMENT_NODE) {
|
|
141
|
+
removeCommentNodes(child);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
const sanitizeHTMLContent = function () {
|
|
146
|
+
let html = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
|
|
147
|
+
if ((0, _typeDetection.isNumber)(html)) {
|
|
148
|
+
html = String(html);
|
|
149
|
+
}
|
|
150
|
+
if (!(0, _typeDetection.isString)(html)) return null;
|
|
151
|
+
const sanitizedHTML = html.replace(/<!--([\s\S]*?)-->/g, '').replace(/<style\b[^>]*>[\s\S]*?<\/style>/gi, '').replace(/<title\b[^>]*>[\s\S]*?<\/title>/gi, '').replace(/<script\b[^>]*>[\s\S]*?<\/script>/gi, '').replace(/\s*[\n\t]\s*/g, '');
|
|
152
|
+
const parsed = new DOMParser().parseFromString(sanitizedHTML, 'text/html');
|
|
153
|
+
const body = parsed.body;
|
|
154
|
+
body.querySelectorAll('style, title, script').forEach(el => el.remove());
|
|
155
|
+
removeCommentNodes(body);
|
|
156
|
+
return body;
|
|
157
|
+
};
|
|
158
|
+
exports.sanitizeHTMLContent = sanitizeHTMLContent;
|
package/package.json
CHANGED