@lexical/html 0.3.3 → 0.3.6
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 +11 -10
- package/LexicalHtml.prod.js +6 -6
- package/index.d.ts +15 -0
- package/package.json +2 -2
- package/LexicalHtml.d.ts +0 -25
package/LexicalHtml.dev.js
CHANGED
|
@@ -52,7 +52,10 @@ function $generateHtmlFromNodes(editor, selection) {
|
|
|
52
52
|
|
|
53
53
|
for (let i = 0; i < topLevelChildren.length; i++) {
|
|
54
54
|
const topLevelNode = topLevelChildren[i];
|
|
55
|
-
|
|
55
|
+
|
|
56
|
+
if (selection !== undefined) {
|
|
57
|
+
$appendNodesToHTML(editor, selection, topLevelNode, container);
|
|
58
|
+
}
|
|
56
59
|
}
|
|
57
60
|
|
|
58
61
|
return container.innerHTML;
|
|
@@ -103,21 +106,19 @@ function getConversionFunction(domNode, editor) {
|
|
|
103
106
|
const {
|
|
104
107
|
nodeName
|
|
105
108
|
} = domNode;
|
|
106
|
-
|
|
107
|
-
const
|
|
108
|
-
|
|
109
|
+
|
|
110
|
+
const cachedConversions = editor._htmlConversions.get(nodeName.toLowerCase());
|
|
111
|
+
|
|
109
112
|
let currentConversion = null;
|
|
110
113
|
|
|
111
114
|
if (cachedConversions !== undefined) {
|
|
112
|
-
|
|
115
|
+
for (const cachedConversion of cachedConversions) {
|
|
113
116
|
const domConversion = cachedConversion(domNode);
|
|
114
117
|
|
|
115
|
-
if (domConversion !== null) {
|
|
116
|
-
|
|
117
|
-
currentConversion = domConversion;
|
|
118
|
-
}
|
|
118
|
+
if (domConversion !== null && (currentConversion === null || currentConversion.priority < domConversion.priority)) {
|
|
119
|
+
currentConversion = domConversion;
|
|
119
120
|
}
|
|
120
|
-
}
|
|
121
|
+
}
|
|
121
122
|
}
|
|
122
123
|
|
|
123
124
|
return currentConversion !== null ? currentConversion.conversion : 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
|
|
9
|
-
|
|
10
|
-
function
|
|
11
|
-
exports.$generateHtmlFromNodes=function(c,d){if(null==document||null==window)throw Error("To use $generateHtmlFromNodes in headless mode please initialize a headless browser implementation such as JSDom before calling this function.");let
|
|
12
|
-
exports.$generateNodesFromDOM=function(c,d){let
|
|
7
|
+
'use strict';var m=require("@lexical/selection"),q=require("lexical");
|
|
8
|
+
function r(c,d,e,h){let a=null!=d?e.isSelected():!0,b=q.$isElementNode(e)&&e.excludeFromCopy("html"),f=m.$cloneWithProperties(e);f=q.$isTextNode(f)&&null!=d?m.$sliceSelectedTextNodeContent(d,f):f;let g=q.$isElementNode(f)?f.getChildren():[],{element:k,after:l}=f.exportDOM(c);if(!k)return!1;let n=new DocumentFragment;for(let p=0;p<g.length;p++){let t=g[p],w=r(c,d,t,n);!a&&q.$isElementNode(e)&&w&&e.extractWithChild(t,d,"html")&&(a=!0)}a&&!b?(k.append(n),h.append(k),l&&(c=l.call(f,k))&&k.replaceWith(c)):
|
|
9
|
+
h.append(n);return a}let u=new Set(["STYLE"]);
|
|
10
|
+
function v(c,d,e=new Map,h){let a=[];if(u.has(c.nodeName))return a;let b=null;var f,{nodeName:g}=c,k=d._htmlConversions.get(g.toLowerCase());g=null;if(void 0!==k)for(f of k)k=f(c),null!==k&&(null===g||g.priority<k.priority)&&(g=k);g=(f=null!==g?g.conversion:null)?f(c):null;f=null;if(null!==g){f=g.after;b=g.node;if(null!==b){for(var [,l]of e)if(b=l(b,h),!b)break;b&&a.push(b)}null!=g.forChild&&e.set(c.nodeName,g.forChild)}c=c.childNodes;h=[];for(l=0;l<c.length;l++)h.push(...v(c[l],d,new Map(e),b));
|
|
11
|
+
null!=f&&(h=f(h));null==b?a=a.concat(h):q.$isElementNode(b)&&b.append(...h);return a}exports.$generateHtmlFromNodes=function(c,d){if(null==document||null==window)throw Error("To use $generateHtmlFromNodes in headless mode please initialize a headless browser implementation such as JSDom before calling this function.");let e=document.createElement("div"),h=q.$getRoot().getChildren();for(let a=0;a<h.length;a++){let b=h[a];void 0!==d&&r(c,d,b,e)}return e.innerHTML};
|
|
12
|
+
exports.$generateNodesFromDOM=function(c,d){let e=[];d=d.body?Array.from(d.body.childNodes):[];let h=d.length;for(let b=0;b<h;b++){var a=d[b];u.has(a.nodeName)||(a=v(a,c),null!==a&&(e=e.concat(a)))}return e}
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
import type { GridSelection, LexicalEditor, LexicalNode, NodeSelection, RangeSelection } from 'lexical';
|
|
9
|
+
/**
|
|
10
|
+
* How you parse your html string to get a document is left up to you. In the browser you can use the native
|
|
11
|
+
* DOMParser API to generate a document (see clipboard.ts), but to use in a headless environment you can use JSDom
|
|
12
|
+
* or an equivilant library and pass in the document here.
|
|
13
|
+
*/
|
|
14
|
+
export declare function $generateNodesFromDOM(editor: LexicalEditor, dom: Document): Array<LexicalNode>;
|
|
15
|
+
export declare function $generateHtmlFromNodes(editor: LexicalEditor, selection?: RangeSelection | NodeSelection | GridSelection | null): string;
|
package/package.json
CHANGED
package/LexicalHtml.d.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the MIT license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import type {
|
|
10
|
-
LexicalEditor,
|
|
11
|
-
LexicalNode,
|
|
12
|
-
RangeSelection,
|
|
13
|
-
NodeSelection,
|
|
14
|
-
GridSelection,
|
|
15
|
-
} from 'lexical';
|
|
16
|
-
|
|
17
|
-
export function $generateHtmlFromNodes(
|
|
18
|
-
editor: LexicalEditor,
|
|
19
|
-
selection?: RangeSelection | NodeSelection | GridSelection | null,
|
|
20
|
-
): string;
|
|
21
|
-
|
|
22
|
-
export function $generateNodesFromDOM(
|
|
23
|
-
editor: LexicalEditor,
|
|
24
|
-
dom: Document,
|
|
25
|
-
): Array<LexicalNode>;
|