@lexical/html 0.14.4 → 0.15.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 +58 -3
- package/LexicalHtml.dev.mjs +60 -5
- package/LexicalHtml.js +2 -0
- package/LexicalHtml.mjs +2 -0
- package/LexicalHtml.node.mjs +2 -0
- package/LexicalHtml.prod.js +9 -7
- package/LexicalHtml.prod.mjs +3 -1
- package/package.json +4 -4
package/LexicalHtml.dev.js
CHANGED
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
*
|
|
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
|
*/
|
|
8
|
+
|
|
7
9
|
'use strict';
|
|
8
10
|
|
|
9
11
|
var selection = require('@lexical/selection');
|
|
@@ -18,6 +20,7 @@ var lexical = require('lexical');
|
|
|
18
20
|
*
|
|
19
21
|
*/
|
|
20
22
|
|
|
23
|
+
|
|
21
24
|
/**
|
|
22
25
|
* How you parse your html string to get a document is left up to you. In the browser you can use the native
|
|
23
26
|
* DOMParser API to generate a document (see clipboard.ts), but to use in a headless environment you can use JSDom
|
|
@@ -26,15 +29,17 @@ var lexical = require('lexical');
|
|
|
26
29
|
function $generateNodesFromDOM(editor, dom) {
|
|
27
30
|
const elements = dom.body ? dom.body.childNodes : [];
|
|
28
31
|
let lexicalNodes = [];
|
|
32
|
+
const allArtificialNodes = [];
|
|
29
33
|
for (let i = 0; i < elements.length; i++) {
|
|
30
34
|
const element = elements[i];
|
|
31
35
|
if (!IGNORE_TAGS.has(element.nodeName)) {
|
|
32
|
-
const lexicalNode = $createNodesFromDOM(element, editor);
|
|
36
|
+
const lexicalNode = $createNodesFromDOM(element, editor, allArtificialNodes, false);
|
|
33
37
|
if (lexicalNode !== null) {
|
|
34
38
|
lexicalNodes = lexicalNodes.concat(lexicalNode);
|
|
35
39
|
}
|
|
36
40
|
}
|
|
37
41
|
}
|
|
42
|
+
$unwrapArtificalNodes(allArtificialNodes);
|
|
38
43
|
return lexicalNodes;
|
|
39
44
|
}
|
|
40
45
|
function $generateHtmlFromNodes(editor, selection) {
|
|
@@ -117,7 +122,7 @@ function getConversionFunction(domNode, editor) {
|
|
|
117
122
|
return currentConversion !== null ? currentConversion.conversion : null;
|
|
118
123
|
}
|
|
119
124
|
const IGNORE_TAGS = new Set(['STYLE', 'SCRIPT']);
|
|
120
|
-
function $createNodesFromDOM(node, editor, forChildMap = new Map(), parentLexicalNode) {
|
|
125
|
+
function $createNodesFromDOM(node, editor, allArtificialNodes, hasBlockAncestorLexicalNode, forChildMap = new Map(), parentLexicalNode) {
|
|
121
126
|
let lexicalNodes = [];
|
|
122
127
|
if (IGNORE_TAGS.has(node.nodeName)) {
|
|
123
128
|
return lexicalNodes;
|
|
@@ -150,12 +155,24 @@ function $createNodesFromDOM(node, editor, forChildMap = new Map(), parentLexica
|
|
|
150
155
|
// to do with it but we still need to process any childNodes.
|
|
151
156
|
const children = node.childNodes;
|
|
152
157
|
let childLexicalNodes = [];
|
|
158
|
+
const hasBlockAncestorLexicalNodeForChildren = currentLexicalNode != null && lexical.$isRootOrShadowRoot(currentLexicalNode) ? false : currentLexicalNode != null && lexical.$isBlockElementNode(currentLexicalNode) || hasBlockAncestorLexicalNode;
|
|
153
159
|
for (let i = 0; i < children.length; i++) {
|
|
154
|
-
childLexicalNodes.push(...$createNodesFromDOM(children[i], editor, new Map(forChildMap), currentLexicalNode));
|
|
160
|
+
childLexicalNodes.push(...$createNodesFromDOM(children[i], editor, allArtificialNodes, hasBlockAncestorLexicalNodeForChildren, new Map(forChildMap), currentLexicalNode));
|
|
155
161
|
}
|
|
156
162
|
if (postTransform != null) {
|
|
157
163
|
childLexicalNodes = postTransform(childLexicalNodes);
|
|
158
164
|
}
|
|
165
|
+
if (utils.isBlockDomNode(node)) {
|
|
166
|
+
if (!hasBlockAncestorLexicalNodeForChildren) {
|
|
167
|
+
childLexicalNodes = wrapContinuousInlines(node, childLexicalNodes, lexical.$createParagraphNode);
|
|
168
|
+
} else {
|
|
169
|
+
childLexicalNodes = wrapContinuousInlines(node, childLexicalNodes, () => {
|
|
170
|
+
const artificialNode = new lexical.ArtificialNode__DO_NOT_USE();
|
|
171
|
+
allArtificialNodes.push(artificialNode);
|
|
172
|
+
return artificialNode;
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
}
|
|
159
176
|
if (currentLexicalNode == null) {
|
|
160
177
|
// If it hasn't been converted to a LexicalNode, we hoist its children
|
|
161
178
|
// up to the same level as it.
|
|
@@ -169,6 +186,44 @@ function $createNodesFromDOM(node, editor, forChildMap = new Map(), parentLexica
|
|
|
169
186
|
}
|
|
170
187
|
return lexicalNodes;
|
|
171
188
|
}
|
|
189
|
+
function wrapContinuousInlines(domNode, nodes, createWrapperFn) {
|
|
190
|
+
const textAlign = domNode.style.textAlign;
|
|
191
|
+
const out = [];
|
|
192
|
+
let continuousInlines = [];
|
|
193
|
+
// wrap contiguous inline child nodes in para
|
|
194
|
+
for (let i = 0; i < nodes.length; i++) {
|
|
195
|
+
const node = nodes[i];
|
|
196
|
+
if (lexical.$isBlockElementNode(node)) {
|
|
197
|
+
node.setFormat(textAlign);
|
|
198
|
+
out.push(node);
|
|
199
|
+
} else {
|
|
200
|
+
continuousInlines.push(node);
|
|
201
|
+
if (i === nodes.length - 1 || i < nodes.length - 1 && lexical.$isBlockElementNode(nodes[i + 1])) {
|
|
202
|
+
const wrapper = createWrapperFn();
|
|
203
|
+
wrapper.setFormat(textAlign);
|
|
204
|
+
wrapper.append(...continuousInlines);
|
|
205
|
+
out.push(wrapper);
|
|
206
|
+
continuousInlines = [];
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
return out;
|
|
211
|
+
}
|
|
212
|
+
function $unwrapArtificalNodes(allArtificialNodes) {
|
|
213
|
+
for (const node of allArtificialNodes) {
|
|
214
|
+
if (node.getNextSibling() instanceof lexical.ArtificialNode__DO_NOT_USE) {
|
|
215
|
+
node.insertAfter(lexical.$createLineBreakNode());
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
// Replace artificial node with it's children
|
|
219
|
+
for (const node of allArtificialNodes) {
|
|
220
|
+
const children = node.getChildren();
|
|
221
|
+
for (const child of children) {
|
|
222
|
+
node.insertBefore(child);
|
|
223
|
+
}
|
|
224
|
+
node.remove();
|
|
225
|
+
}
|
|
226
|
+
}
|
|
172
227
|
|
|
173
228
|
exports.$generateHtmlFromNodes = $generateHtmlFromNodes;
|
|
174
229
|
exports.$generateNodesFromDOM = $generateNodesFromDOM;
|
package/LexicalHtml.dev.mjs
CHANGED
|
@@ -3,10 +3,12 @@
|
|
|
3
3
|
*
|
|
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
|
*/
|
|
8
|
+
|
|
7
9
|
import { $cloneWithProperties, $sliceSelectedTextNodeContent } from '@lexical/selection';
|
|
8
|
-
import { isHTMLElement } from '@lexical/utils';
|
|
9
|
-
import { $getRoot, $isElementNode, $isTextNode } from 'lexical';
|
|
10
|
+
import { isHTMLElement, isBlockDomNode } from '@lexical/utils';
|
|
11
|
+
import { $getRoot, $isElementNode, $isTextNode, $isRootOrShadowRoot, $isBlockElementNode, ArtificialNode__DO_NOT_USE, $createLineBreakNode, $createParagraphNode } from 'lexical';
|
|
10
12
|
|
|
11
13
|
/**
|
|
12
14
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
@@ -16,6 +18,7 @@ import { $getRoot, $isElementNode, $isTextNode } from 'lexical';
|
|
|
16
18
|
*
|
|
17
19
|
*/
|
|
18
20
|
|
|
21
|
+
|
|
19
22
|
/**
|
|
20
23
|
* How you parse your html string to get a document is left up to you. In the browser you can use the native
|
|
21
24
|
* DOMParser API to generate a document (see clipboard.ts), but to use in a headless environment you can use JSDom
|
|
@@ -24,15 +27,17 @@ import { $getRoot, $isElementNode, $isTextNode } from 'lexical';
|
|
|
24
27
|
function $generateNodesFromDOM(editor, dom) {
|
|
25
28
|
const elements = dom.body ? dom.body.childNodes : [];
|
|
26
29
|
let lexicalNodes = [];
|
|
30
|
+
const allArtificialNodes = [];
|
|
27
31
|
for (let i = 0; i < elements.length; i++) {
|
|
28
32
|
const element = elements[i];
|
|
29
33
|
if (!IGNORE_TAGS.has(element.nodeName)) {
|
|
30
|
-
const lexicalNode = $createNodesFromDOM(element, editor);
|
|
34
|
+
const lexicalNode = $createNodesFromDOM(element, editor, allArtificialNodes, false);
|
|
31
35
|
if (lexicalNode !== null) {
|
|
32
36
|
lexicalNodes = lexicalNodes.concat(lexicalNode);
|
|
33
37
|
}
|
|
34
38
|
}
|
|
35
39
|
}
|
|
40
|
+
$unwrapArtificalNodes(allArtificialNodes);
|
|
36
41
|
return lexicalNodes;
|
|
37
42
|
}
|
|
38
43
|
function $generateHtmlFromNodes(editor, selection) {
|
|
@@ -115,7 +120,7 @@ function getConversionFunction(domNode, editor) {
|
|
|
115
120
|
return currentConversion !== null ? currentConversion.conversion : null;
|
|
116
121
|
}
|
|
117
122
|
const IGNORE_TAGS = new Set(['STYLE', 'SCRIPT']);
|
|
118
|
-
function $createNodesFromDOM(node, editor, forChildMap = new Map(), parentLexicalNode) {
|
|
123
|
+
function $createNodesFromDOM(node, editor, allArtificialNodes, hasBlockAncestorLexicalNode, forChildMap = new Map(), parentLexicalNode) {
|
|
119
124
|
let lexicalNodes = [];
|
|
120
125
|
if (IGNORE_TAGS.has(node.nodeName)) {
|
|
121
126
|
return lexicalNodes;
|
|
@@ -148,12 +153,24 @@ function $createNodesFromDOM(node, editor, forChildMap = new Map(), parentLexica
|
|
|
148
153
|
// to do with it but we still need to process any childNodes.
|
|
149
154
|
const children = node.childNodes;
|
|
150
155
|
let childLexicalNodes = [];
|
|
156
|
+
const hasBlockAncestorLexicalNodeForChildren = currentLexicalNode != null && $isRootOrShadowRoot(currentLexicalNode) ? false : currentLexicalNode != null && $isBlockElementNode(currentLexicalNode) || hasBlockAncestorLexicalNode;
|
|
151
157
|
for (let i = 0; i < children.length; i++) {
|
|
152
|
-
childLexicalNodes.push(...$createNodesFromDOM(children[i], editor, new Map(forChildMap), currentLexicalNode));
|
|
158
|
+
childLexicalNodes.push(...$createNodesFromDOM(children[i], editor, allArtificialNodes, hasBlockAncestorLexicalNodeForChildren, new Map(forChildMap), currentLexicalNode));
|
|
153
159
|
}
|
|
154
160
|
if (postTransform != null) {
|
|
155
161
|
childLexicalNodes = postTransform(childLexicalNodes);
|
|
156
162
|
}
|
|
163
|
+
if (isBlockDomNode(node)) {
|
|
164
|
+
if (!hasBlockAncestorLexicalNodeForChildren) {
|
|
165
|
+
childLexicalNodes = wrapContinuousInlines(node, childLexicalNodes, $createParagraphNode);
|
|
166
|
+
} else {
|
|
167
|
+
childLexicalNodes = wrapContinuousInlines(node, childLexicalNodes, () => {
|
|
168
|
+
const artificialNode = new ArtificialNode__DO_NOT_USE();
|
|
169
|
+
allArtificialNodes.push(artificialNode);
|
|
170
|
+
return artificialNode;
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
}
|
|
157
174
|
if (currentLexicalNode == null) {
|
|
158
175
|
// If it hasn't been converted to a LexicalNode, we hoist its children
|
|
159
176
|
// up to the same level as it.
|
|
@@ -167,5 +184,43 @@ function $createNodesFromDOM(node, editor, forChildMap = new Map(), parentLexica
|
|
|
167
184
|
}
|
|
168
185
|
return lexicalNodes;
|
|
169
186
|
}
|
|
187
|
+
function wrapContinuousInlines(domNode, nodes, createWrapperFn) {
|
|
188
|
+
const textAlign = domNode.style.textAlign;
|
|
189
|
+
const out = [];
|
|
190
|
+
let continuousInlines = [];
|
|
191
|
+
// wrap contiguous inline child nodes in para
|
|
192
|
+
for (let i = 0; i < nodes.length; i++) {
|
|
193
|
+
const node = nodes[i];
|
|
194
|
+
if ($isBlockElementNode(node)) {
|
|
195
|
+
node.setFormat(textAlign);
|
|
196
|
+
out.push(node);
|
|
197
|
+
} else {
|
|
198
|
+
continuousInlines.push(node);
|
|
199
|
+
if (i === nodes.length - 1 || i < nodes.length - 1 && $isBlockElementNode(nodes[i + 1])) {
|
|
200
|
+
const wrapper = createWrapperFn();
|
|
201
|
+
wrapper.setFormat(textAlign);
|
|
202
|
+
wrapper.append(...continuousInlines);
|
|
203
|
+
out.push(wrapper);
|
|
204
|
+
continuousInlines = [];
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
return out;
|
|
209
|
+
}
|
|
210
|
+
function $unwrapArtificalNodes(allArtificialNodes) {
|
|
211
|
+
for (const node of allArtificialNodes) {
|
|
212
|
+
if (node.getNextSibling() instanceof ArtificialNode__DO_NOT_USE) {
|
|
213
|
+
node.insertAfter($createLineBreakNode());
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
// Replace artificial node with it's children
|
|
217
|
+
for (const node of allArtificialNodes) {
|
|
218
|
+
const children = node.getChildren();
|
|
219
|
+
for (const child of children) {
|
|
220
|
+
node.insertBefore(child);
|
|
221
|
+
}
|
|
222
|
+
node.remove();
|
|
223
|
+
}
|
|
224
|
+
}
|
|
170
225
|
|
|
171
226
|
export { $generateHtmlFromNodes, $generateNodesFromDOM };
|
package/LexicalHtml.js
CHANGED
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
*
|
|
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
|
*/
|
|
8
|
+
|
|
7
9
|
'use strict'
|
|
8
10
|
const LexicalHtml = process.env.NODE_ENV === 'development' ? require('./LexicalHtml.dev.js') : require('./LexicalHtml.prod.js');
|
|
9
11
|
module.exports = LexicalHtml;
|
package/LexicalHtml.mjs
CHANGED
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
*
|
|
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
|
*/
|
|
8
|
+
|
|
7
9
|
import * as modDev from './LexicalHtml.dev.mjs';
|
|
8
10
|
import * as modProd from './LexicalHtml.prod.mjs';
|
|
9
11
|
const mod = process.env.NODE_ENV === 'development' ? modDev : modProd;
|
package/LexicalHtml.node.mjs
CHANGED
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
*
|
|
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
|
*/
|
|
8
|
+
|
|
7
9
|
const mod = await (process.env.NODE_ENV === 'development' ? import('./LexicalHtml.dev.mjs') : import('./LexicalHtml.prod.mjs'));
|
|
8
10
|
export const $generateHtmlFromNodes = mod.$generateHtmlFromNodes;
|
|
9
11
|
export const $generateNodesFromDOM = mod.$generateNodesFromDOM;
|
package/LexicalHtml.prod.js
CHANGED
|
@@ -3,11 +3,13 @@
|
|
|
3
3
|
*
|
|
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
|
*/
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
a=[];for(l=0;l<c.length;l++)
|
|
12
|
-
|
|
13
|
-
exports.$
|
|
8
|
+
|
|
9
|
+
'use strict';var m=require("@lexical/selection"),q=require("@lexical/utils"),r=require("lexical");
|
|
10
|
+
function t(b,a,f,e=null){let g=null!==e?a.isSelected(e):!0,c=r.$isElementNode(a)&&a.excludeFromCopy("html");var d=a;null!==e&&(d=m.$cloneWithProperties(a),d=r.$isTextNode(d)&&null!==e?m.$sliceSelectedTextNodeContent(e,d):d);let h=r.$isElementNode(d)?d.getChildren():[];var k=b._nodes.get(d.getType());k=k&&void 0!==k.exportDOM?k.exportDOM(b,d):d.exportDOM(b);let {element:l,after:n}=k;if(!l)return!1;k=document.createDocumentFragment();for(let p=0;p<h.length;p++){let u=h[p],y=t(b,u,k,e);!g&&r.$isElementNode(a)&&
|
|
11
|
+
y&&a.extractWithChild(u,e,"html")&&(g=!0)}g&&!c?(q.isHTMLElement(l)&&l.append(k),f.append(l),n&&(b=n.call(d,l))&&l.replaceWith(b)):f.append(k);return g}function v(b,a){var {nodeName:f}=b;f=a._htmlConversions.get(f.toLowerCase());a=null;if(void 0!==f)for(let e of f)f=e(b),null!==f&&(null===a||(a.priority||0)<(f.priority||0))&&(a=f);return null!==a?a.conversion:null}let w=new Set(["STYLE","SCRIPT"]);
|
|
12
|
+
function x(b,a,f,e,g=new Map,c){let d=[];if(w.has(b.nodeName))return d;let h=null;var k=v(b,a),l=k?k(b):null;k=null;if(null!==l){k=l.after;let p=l.node;h=Array.isArray(p)?p[p.length-1]:p;if(null!==h){for(var [,n]of g)if(h=n(h,c),!h)break;h&&d.push(...(Array.isArray(p)?p:[h]))}null!=l.forChild&&g.set(b.nodeName,l.forChild)}c=b.childNodes;n=[];e=null!=h&&r.$isRootOrShadowRoot(h)?!1:null!=h&&r.$isBlockElementNode(h)||e;for(l=0;l<c.length;l++)n.push(...x(c[l],a,f,e,new Map(g),h));null!=k&&(n=k(n));q.isBlockDomNode(b)&&
|
|
13
|
+
(n=e?z(b,n,()=>{let p=new r.ArtificialNode__DO_NOT_USE;f.push(p);return p}):z(b,n,r.$createParagraphNode));null==h?d=d.concat(n):r.$isElementNode(h)&&h.append(...n);return d}function z(b,a,f){b=b.style.textAlign;let e=[],g=[];for(let d=0;d<a.length;d++){var c=a[d];if(r.$isBlockElementNode(c))c.setFormat(b),e.push(c);else if(g.push(c),d===a.length-1||d<a.length-1&&r.$isBlockElementNode(a[d+1]))c=f(),c.setFormat(b),c.append(...g),e.push(c),g=[]}return e}
|
|
14
|
+
exports.$generateHtmlFromNodes=function(b,a){if("undefined"===typeof document||"undefined"===typeof window&&"undefined"===typeof global.window)throw Error("To use $generateHtmlFromNodes in headless mode please initialize a headless browser implementation such as JSDom before calling this function.");let f=document.createElement("div"),e=r.$getRoot().getChildren();for(let g=0;g<e.length;g++)t(b,e[g],f,a);return f.innerHTML};
|
|
15
|
+
exports.$generateNodesFromDOM=function(b,a){let f=a.body?a.body.childNodes:[];a=[];let e=[];for(let c=0;c<f.length;c++){var g=f[c];w.has(g.nodeName)||(g=x(g,b,e,!1),null!==g&&(a=a.concat(g)))}for(let c of e)c.getNextSibling()instanceof r.ArtificialNode__DO_NOT_USE&&c.insertAfter(r.$createLineBreakNode());for(let c of e){b=c.getChildren();for(let d of b)c.insertBefore(d);c.remove()}return a}
|
package/LexicalHtml.prod.mjs
CHANGED
|
@@ -3,5 +3,7 @@
|
|
|
3
3
|
*
|
|
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
|
*/
|
|
7
|
-
|
|
8
|
+
|
|
9
|
+
import{$cloneWithProperties as e,$sliceSelectedTextNodeContent as n}from"@lexical/selection";import{isHTMLElement as t,isBlockDomNode as o}from"@lexical/utils";import{$getRoot as l,$isElementNode as r,$isTextNode as i,$isRootOrShadowRoot as s,$isBlockElementNode as c,ArtificialNode__DO_NOT_USE as u,$createLineBreakNode as f,$createParagraphNode as a}from"lexical";function d(e,n){const t=n.body?n.body.childNodes:[];let o=[];const l=[];for(let n=0;n<t.length;n++){const r=t[n];if(!m.has(r.nodeName)){const n=g(r,e,l,!1);null!==n&&(o=o.concat(n))}}return function(e){for(const n of e)n.getNextSibling()instanceof u&&n.insertAfter(f());for(const n of e){const e=n.getChildren();for(const t of e)n.insertBefore(t);n.remove()}}(l),o}function h(e,n){if("undefined"==typeof document||"undefined"==typeof window&&void 0===global.window)throw new Error("To use $generateHtmlFromNodes in headless mode please initialize a headless browser implementation such as JSDom before calling this function.");const t=document.createElement("div"),o=l().getChildren();for(let l=0;l<o.length;l++){p(e,o[l],t,n)}return t.innerHTML}function p(o,l,s,c=null){let u=null===c||l.isSelected(c);const f=r(l)&&l.excludeFromCopy("html");let a=l;if(null!==c){let t=e(l);t=i(t)&&null!==c?n(c,t):t,a=t}const d=r(a)?a.getChildren():[],h=o._nodes.get(a.getType());let m;m=h&&void 0!==h.exportDOM?h.exportDOM(o,a):a.exportDOM(o);const{element:g,after:y}=m;if(!g)return!1;const w=document.createDocumentFragment();for(let e=0;e<d.length;e++){const n=d[e],t=p(o,n,w,c);!u&&r(l)&&t&&l.extractWithChild(n,c,"html")&&(u=!0)}if(u&&!f){if(t(g)&&g.append(w),s.append(g),y){const e=y.call(a,g);e&&g.replaceWith(e)}}else s.append(w);return u}const m=new Set(["STYLE","SCRIPT"]);function g(e,n,t,l,i=new Map,f){let d=[];if(m.has(e.nodeName))return d;let h=null;const p=function(e,n){const{nodeName:t}=e,o=n._htmlConversions.get(t.toLowerCase());let l=null;if(void 0!==o)for(const n of o){const t=n(e);null!==t&&(null===l||(l.priority||0)<(t.priority||0))&&(l=t)}return null!==l?l.conversion:null}(e,n),w=p?p(e):null;let x=null;if(null!==w){x=w.after;const n=w.node;if(h=Array.isArray(n)?n[n.length-1]:n,null!==h){for(const[,e]of i)if(h=e(h,f),!h)break;h&&d.push(...Array.isArray(n)?n:[h])}null!=w.forChild&&i.set(e.nodeName,w.forChild)}const C=e.childNodes;let N=[];const b=(null==h||!s(h))&&(null!=h&&c(h)||l);for(let e=0;e<C.length;e++)N.push(...g(C[e],n,t,b,new Map(i),h));return null!=x&&(N=x(N)),o(e)&&(N=y(e,N,b?()=>{const e=new u;return t.push(e),e}:a)),null==h?d=d.concat(N):r(h)&&h.append(...N),d}function y(e,n,t){const o=e.style.textAlign,l=[];let r=[];for(let e=0;e<n.length;e++){const i=n[e];if(c(i))i.setFormat(o),l.push(i);else if(r.push(i),e===n.length-1||e<n.length-1&&c(n[e+1])){const e=t();e.setFormat(o),e.append(...r),l.push(e),r=[]}}return l}export{h as $generateHtmlFromNodes,d as $generateNodesFromDOM};
|
package/package.json
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"html"
|
|
9
9
|
],
|
|
10
10
|
"license": "MIT",
|
|
11
|
-
"version": "0.
|
|
11
|
+
"version": "0.15.0",
|
|
12
12
|
"main": "LexicalHtml.js",
|
|
13
13
|
"types": "index.d.ts",
|
|
14
14
|
"repository": {
|
|
@@ -17,9 +17,9 @@
|
|
|
17
17
|
"directory": "packages/lexical-html"
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@lexical/selection": "0.
|
|
21
|
-
"@lexical/utils": "0.
|
|
22
|
-
"lexical": "0.
|
|
20
|
+
"@lexical/selection": "0.15.0",
|
|
21
|
+
"@lexical/utils": "0.15.0",
|
|
22
|
+
"lexical": "0.15.0"
|
|
23
23
|
},
|
|
24
24
|
"module": "LexicalHtml.mjs",
|
|
25
25
|
"sideEffects": false,
|