@contentful/field-editor-rich-text 3.22.0 → 3.22.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.
- package/dist/cjs/plugins/DeserializeDocx/cleanHtmlEmptyElements.js +36 -0
- package/dist/cjs/plugins/DeserializeDocx/createDeserializeDocxPlugin.js +2 -1
- package/dist/esm/plugins/DeserializeDocx/cleanHtmlEmptyElements.js +26 -0
- package/dist/esm/plugins/DeserializeDocx/createDeserializeDocxPlugin.js +2 -1
- package/dist/types/plugins/DeserializeDocx/cleanHtmlEmptyElements.d.ts +2 -0
- package/package.json +4 -4
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "cleanHtmlEmptyElements", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return cleanHtmlEmptyElements;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _platecommon = require("@udecode/plate-common");
|
|
12
|
+
const ALLOWED_EMPTY_ELEMENTS = new Set([
|
|
13
|
+
'BR',
|
|
14
|
+
'IMG',
|
|
15
|
+
'TH',
|
|
16
|
+
'TD',
|
|
17
|
+
'SPAN'
|
|
18
|
+
]);
|
|
19
|
+
const isEmpty = (element)=>{
|
|
20
|
+
return !ALLOWED_EMPTY_ELEMENTS.has(element.nodeName) && !element.innerHTML.trim();
|
|
21
|
+
};
|
|
22
|
+
const removeIfEmpty = (element)=>{
|
|
23
|
+
if (isEmpty(element)) {
|
|
24
|
+
const { parentElement } = element;
|
|
25
|
+
element.remove();
|
|
26
|
+
if (parentElement) {
|
|
27
|
+
removeIfEmpty(parentElement);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
const cleanHtmlEmptyElements = (rootNode)=>{
|
|
32
|
+
(0, _platecommon.traverseHtmlElements)(rootNode, (element)=>{
|
|
33
|
+
removeIfEmpty(element);
|
|
34
|
+
return true;
|
|
35
|
+
});
|
|
36
|
+
};
|
|
@@ -10,6 +10,7 @@ Object.defineProperty(exports, "createDeserializeDocxPlugin", {
|
|
|
10
10
|
});
|
|
11
11
|
const _platecommon = require("@udecode/plate-common");
|
|
12
12
|
const _plateserializerdocx = require("@udecode/plate-serializer-docx");
|
|
13
|
+
const _cleanHtmlEmptyElements = require("./cleanHtmlEmptyElements");
|
|
13
14
|
const createDeserializeDocxPlugin = ()=>(0, _plateserializerdocx.createDeserializeDocxPlugin)({
|
|
14
15
|
inject: {
|
|
15
16
|
pluginsByKey: {
|
|
@@ -25,7 +26,7 @@ const createDeserializeDocxPlugin = ()=>(0, _plateserializerdocx.createDeseriali
|
|
|
25
26
|
}
|
|
26
27
|
(0, _plateserializerdocx.cleanDocxFootnotes)(body);
|
|
27
28
|
(0, _plateserializerdocx.cleanDocxImageElements)(document, rtf, body);
|
|
28
|
-
(0,
|
|
29
|
+
(0, _cleanHtmlEmptyElements.cleanHtmlEmptyElements)(body);
|
|
29
30
|
(0, _plateserializerdocx.cleanDocxEmptyParagraphs)(body);
|
|
30
31
|
(0, _plateserializerdocx.cleanDocxQuotes)(body);
|
|
31
32
|
(0, _plateserializerdocx.cleanDocxSpans)(body);
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { traverseHtmlElements } from '@udecode/plate-common';
|
|
2
|
+
const ALLOWED_EMPTY_ELEMENTS = new Set([
|
|
3
|
+
'BR',
|
|
4
|
+
'IMG',
|
|
5
|
+
'TH',
|
|
6
|
+
'TD',
|
|
7
|
+
'SPAN'
|
|
8
|
+
]);
|
|
9
|
+
const isEmpty = (element)=>{
|
|
10
|
+
return !ALLOWED_EMPTY_ELEMENTS.has(element.nodeName) && !element.innerHTML.trim();
|
|
11
|
+
};
|
|
12
|
+
const removeIfEmpty = (element)=>{
|
|
13
|
+
if (isEmpty(element)) {
|
|
14
|
+
const { parentElement } = element;
|
|
15
|
+
element.remove();
|
|
16
|
+
if (parentElement) {
|
|
17
|
+
removeIfEmpty(parentElement);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
export const cleanHtmlEmptyElements = (rootNode)=>{
|
|
22
|
+
traverseHtmlElements(rootNode, (element)=>{
|
|
23
|
+
removeIfEmpty(element);
|
|
24
|
+
return true;
|
|
25
|
+
});
|
|
26
|
+
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { KEY_DESERIALIZE_HTML, cleanHtmlBrElements,
|
|
1
|
+
import { KEY_DESERIALIZE_HTML, cleanHtmlBrElements, cleanHtmlFontElements, cleanHtmlLinkElements, cleanHtmlTextNodes, copyBlockMarksToSpanChild, postCleanHtml, preCleanHtml } from '@udecode/plate-common';
|
|
2
2
|
import { cleanDocxBrComments, cleanDocxEmptyParagraphs, cleanDocxFootnotes, cleanDocxImageElements, cleanDocxListElements, cleanDocxQuotes, cleanDocxSpans, createDeserializeDocxPlugin as originalCreateDeserializeDocxPlugin, isDocxContent } from '@udecode/plate-serializer-docx';
|
|
3
|
+
import { cleanHtmlEmptyElements } from './cleanHtmlEmptyElements';
|
|
3
4
|
export const createDeserializeDocxPlugin = ()=>originalCreateDeserializeDocxPlugin({
|
|
4
5
|
inject: {
|
|
5
6
|
pluginsByKey: {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentful/field-editor-rich-text",
|
|
3
|
-
"version": "3.22.
|
|
3
|
+
"version": "3.22.2",
|
|
4
4
|
"source": "./src/index.tsx",
|
|
5
5
|
"main": "dist/cjs/index.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -44,8 +44,8 @@
|
|
|
44
44
|
"@contentful/f36-icons": "^4.1.1",
|
|
45
45
|
"@contentful/f36-tokens": "^4.0.0",
|
|
46
46
|
"@contentful/f36-utils": "^4.19.0",
|
|
47
|
-
"@contentful/field-editor-reference": "^5.28.
|
|
48
|
-
"@contentful/field-editor-shared": "^1.5.
|
|
47
|
+
"@contentful/field-editor-reference": "^5.28.1",
|
|
48
|
+
"@contentful/field-editor-shared": "^1.5.1",
|
|
49
49
|
"@contentful/rich-text-plain-text-renderer": "^16.0.4",
|
|
50
50
|
"@contentful/rich-text-types": "16.3.0",
|
|
51
51
|
"@popperjs/core": "^2.11.5",
|
|
@@ -86,5 +86,5 @@
|
|
|
86
86
|
"publishConfig": {
|
|
87
87
|
"registry": "https://npm.pkg.github.com/"
|
|
88
88
|
},
|
|
89
|
-
"gitHead": "
|
|
89
|
+
"gitHead": "60fd3c2f5a58f4d42886b5f952ce3cc1aec71833"
|
|
90
90
|
}
|