@lexical/html 0.4.1 → 0.5.1-next.0
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/LexicalHtml.dev.js +18 -15
- package/LexicalHtml.prod.js +6 -6
- package/README.md +1 -2
- package/package.json +3 -3
package/LexicalHtml.dev.js
CHANGED
|
@@ -36,7 +36,7 @@ function $generateNodesFromDOM(editor, dom) {
|
|
|
36
36
|
return lexicalNodes;
|
|
37
37
|
}
|
|
38
38
|
function $generateHtmlFromNodes(editor, selection) {
|
|
39
|
-
if (document
|
|
39
|
+
if (typeof document === 'undefined' || typeof window === 'undefined') {
|
|
40
40
|
throw new Error('To use $generateHtmlFromNodes in headless mode please initialize a headless browser implementation such as JSDom before calling this function.');
|
|
41
41
|
}
|
|
42
42
|
|
|
@@ -46,25 +46,28 @@ function $generateHtmlFromNodes(editor, selection) {
|
|
|
46
46
|
|
|
47
47
|
for (let i = 0; i < topLevelChildren.length; i++) {
|
|
48
48
|
const topLevelNode = topLevelChildren[i];
|
|
49
|
-
|
|
50
|
-
if (selection !== undefined) {
|
|
51
|
-
$appendNodesToHTML(editor, selection, topLevelNode, container);
|
|
52
|
-
}
|
|
49
|
+
$appendNodesToHTML(editor, topLevelNode, container, selection);
|
|
53
50
|
}
|
|
54
51
|
|
|
55
52
|
return container.innerHTML;
|
|
56
53
|
}
|
|
57
54
|
|
|
58
|
-
function $appendNodesToHTML(editor, selection$1
|
|
55
|
+
function $appendNodesToHTML(editor, currentNode, parentElement, selection$1 = null) {
|
|
59
56
|
let shouldInclude = selection$1 != null ? currentNode.isSelected() : true;
|
|
60
57
|
const shouldExclude = lexical.$isElementNode(currentNode) && currentNode.excludeFromCopy('html');
|
|
61
|
-
let
|
|
62
|
-
|
|
63
|
-
|
|
58
|
+
let target = currentNode;
|
|
59
|
+
|
|
60
|
+
if (selection$1 !== null) {
|
|
61
|
+
let clone = selection.$cloneWithProperties(currentNode);
|
|
62
|
+
clone = lexical.$isTextNode(clone) && selection$1 != null ? selection.$sliceSelectedTextNodeContent(selection$1, clone) : clone;
|
|
63
|
+
target = clone;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const children = lexical.$isElementNode(target) ? target.getChildren() : [];
|
|
64
67
|
const {
|
|
65
68
|
element,
|
|
66
69
|
after
|
|
67
|
-
} =
|
|
70
|
+
} = target.exportDOM(editor);
|
|
68
71
|
|
|
69
72
|
if (!element) {
|
|
70
73
|
return false;
|
|
@@ -74,7 +77,7 @@ function $appendNodesToHTML(editor, selection$1, currentNode, parentElement) {
|
|
|
74
77
|
|
|
75
78
|
for (let i = 0; i < children.length; i++) {
|
|
76
79
|
const childNode = children[i];
|
|
77
|
-
const shouldIncludeChild = $appendNodesToHTML(editor,
|
|
80
|
+
const shouldIncludeChild = $appendNodesToHTML(editor, childNode, fragment, selection$1);
|
|
78
81
|
|
|
79
82
|
if (!shouldInclude && lexical.$isElementNode(currentNode) && shouldIncludeChild && currentNode.extractWithChild(childNode, selection$1, 'html')) {
|
|
80
83
|
shouldInclude = true;
|
|
@@ -86,7 +89,7 @@ function $appendNodesToHTML(editor, selection$1, currentNode, parentElement) {
|
|
|
86
89
|
parentElement.append(element);
|
|
87
90
|
|
|
88
91
|
if (after) {
|
|
89
|
-
const newElement = after.call(
|
|
92
|
+
const newElement = after.call(target, element);
|
|
90
93
|
if (newElement) element.replaceWith(newElement);
|
|
91
94
|
}
|
|
92
95
|
} else {
|
|
@@ -120,7 +123,7 @@ function getConversionFunction(domNode, editor) {
|
|
|
120
123
|
|
|
121
124
|
const IGNORE_TAGS = new Set(['STYLE']);
|
|
122
125
|
|
|
123
|
-
function $createNodesFromDOM(node, editor, forChildMap = new Map(), parentLexicalNode) {
|
|
126
|
+
function $createNodesFromDOM(node, editor, forChildMap = new Map(), parentLexicalNode, preformatted = false) {
|
|
124
127
|
let lexicalNodes = [];
|
|
125
128
|
|
|
126
129
|
if (IGNORE_TAGS.has(node.nodeName)) {
|
|
@@ -129,7 +132,7 @@ function $createNodesFromDOM(node, editor, forChildMap = new Map(), parentLexica
|
|
|
129
132
|
|
|
130
133
|
let currentLexicalNode = null;
|
|
131
134
|
const transformFunction = getConversionFunction(node, editor);
|
|
132
|
-
const transformOutput = transformFunction ? transformFunction(node) : null;
|
|
135
|
+
const transformOutput = transformFunction ? transformFunction(node, undefined, preformatted) : null;
|
|
133
136
|
let postTransform = null;
|
|
134
137
|
|
|
135
138
|
if (transformOutput !== null) {
|
|
@@ -161,7 +164,7 @@ function $createNodesFromDOM(node, editor, forChildMap = new Map(), parentLexica
|
|
|
161
164
|
let childLexicalNodes = [];
|
|
162
165
|
|
|
163
166
|
for (let i = 0; i < children.length; i++) {
|
|
164
|
-
childLexicalNodes.push(...$createNodesFromDOM(children[i], editor, new Map(forChildMap), currentLexicalNode));
|
|
167
|
+
childLexicalNodes.push(...$createNodesFromDOM(children[i], editor, new Map(forChildMap), currentLexicalNode, preformatted || (transformOutput && transformOutput.preformatted) === true));
|
|
165
168
|
}
|
|
166
169
|
|
|
167
170
|
if (postTransform != null) {
|
package/LexicalHtml.prod.js
CHANGED
|
@@ -4,9 +4,9 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
'use strict';var
|
|
8
|
-
function r(c,d,
|
|
9
|
-
h.append(
|
|
10
|
-
function v(c,d,
|
|
11
|
-
null!=f&&(
|
|
12
|
-
exports.$generateNodesFromDOM=function(c,d){let
|
|
7
|
+
'use strict';var n=require("@lexical/selection"),q=require("lexical");
|
|
8
|
+
function r(c,d,h,b=null){let e=null!=b?d.isSelected():!0,l=q.$isElementNode(d)&&d.excludeFromCopy("html");var a=d;null!==b&&(a=n.$cloneWithProperties(d),a=q.$isTextNode(a)&&null!=b?n.$sliceSelectedTextNodeContent(b,a):a);let f=q.$isElementNode(a)?a.getChildren():[],{element:k,after:g}=a.exportDOM(c);if(!k)return!1;let m=new DocumentFragment;for(let p=0;p<f.length;p++){let t=f[p],w=r(c,t,m,b);!e&&q.$isElementNode(d)&&w&&d.extractWithChild(t,b,"html")&&(e=!0)}e&&!l?(k.append(m),h.append(k),g&&(c=g.call(a,
|
|
9
|
+
k))&&k.replaceWith(c)):h.append(m);return e}let u=new Set(["STYLE"]);
|
|
10
|
+
function v(c,d,h=new Map,b,e=!1){let l=[];if(u.has(c.nodeName))return l;let a=null;var {nodeName:f}=c,k=d._htmlConversions.get(f.toLowerCase());f=null;if(void 0!==k)for(g of k)k=g(c),null!==k&&(null===f||f.priority<k.priority)&&(f=k);var g=(g=null!==f?f.conversion:null)?g(c,void 0,e):null;f=null;if(null!==g){f=g.after;a=g.node;if(null!==a){for(var [,m]of h)if(a=m(a,b),!a)break;a&&l.push(a)}null!=g.forChild&&h.set(c.nodeName,g.forChild)}c=c.childNodes;b=[];for(m=0;m<c.length;m++)b.push(...v(c[m],d,
|
|
11
|
+
new Map(h),a,e||!0===(g&&g.preformatted)));null!=f&&(b=f(b));null==a?l=l.concat(b):q.$isElementNode(a)&&a.append(...b);return l}exports.$generateHtmlFromNodes=function(c,d){if("undefined"===typeof document||"undefined"===typeof window)throw Error("To use $generateHtmlFromNodes in headless mode please initialize a headless browser implementation such as JSDom before calling this function.");let h=document.createElement("div"),b=q.$getRoot().getChildren();for(let e=0;e<b.length;e++)r(c,b[e],h,d);return h.innerHTML};
|
|
12
|
+
exports.$generateNodesFromDOM=function(c,d){let h=[];d=d.body?Array.from(d.body.childNodes):[];let b=d.length;for(let l=0;l<b;l++){var e=d[l];u.has(e.nodeName)||(e=v(e,c),null!==e&&(h=h.concat(e)))}return h}
|
package/README.md
CHANGED
package/package.json
CHANGED
|
@@ -8,10 +8,10 @@
|
|
|
8
8
|
"html"
|
|
9
9
|
],
|
|
10
10
|
"license": "MIT",
|
|
11
|
-
"version": "0.
|
|
11
|
+
"version": "0.5.1-next.0",
|
|
12
12
|
"main": "LexicalHtml.js",
|
|
13
13
|
"peerDependencies": {
|
|
14
|
-
"lexical": "0.
|
|
14
|
+
"lexical": "0.5.1-next.0"
|
|
15
15
|
},
|
|
16
16
|
"repository": {
|
|
17
17
|
"type": "git",
|
|
@@ -19,6 +19,6 @@
|
|
|
19
19
|
"directory": "packages/lexical-html"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@lexical/selection": "0.
|
|
22
|
+
"@lexical/selection": "0.5.1-next.0"
|
|
23
23
|
}
|
|
24
24
|
}
|