@lexical/html 0.3.2 → 0.3.5
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 +3 -3
- package/LexicalHtml.prod.js +5 -5
- package/index.d.ts +15 -0
- package/package.json +2 -2
- package/LexicalHtml.d.ts +0 -25
package/LexicalHtml.dev.js
CHANGED
|
@@ -103,9 +103,9 @@ function getConversionFunction(domNode, editor) {
|
|
|
103
103
|
const {
|
|
104
104
|
nodeName
|
|
105
105
|
} = domNode;
|
|
106
|
-
|
|
107
|
-
const
|
|
108
|
-
|
|
106
|
+
|
|
107
|
+
const cachedConversions = editor._htmlConversions.get(nodeName.toLowerCase());
|
|
108
|
+
|
|
109
109
|
let currentConversion = null;
|
|
110
110
|
|
|
111
111
|
if (cachedConversions !== undefined) {
|
package/LexicalHtml.prod.js
CHANGED
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
'use strict';var l=require("@lexical/selection"),p=require("lexical");
|
|
8
|
-
function q(
|
|
9
|
-
|
|
10
|
-
function x(
|
|
11
|
-
exports.$generateHtmlFromNodes=function(
|
|
12
|
-
exports.$generateNodesFromDOM=function(
|
|
8
|
+
function q(d,b,e,c){let a=null!=b?e.isSelected():!0,f=p.$isElementNode(e)&&e.excludeFromCopy("html"),g=l.$cloneWithProperties(e);g=p.$isTextNode(g)&&null!=b?l.$sliceSelectedTextNodeContent(b,g):g;let k=p.$isElementNode(g)?g.getChildren():[],{element:h,after:r}=g.exportDOM(d);if(!h)return!1;let m=new DocumentFragment;for(let n=0;n<k.length;n++){let t=k[n],w=q(d,b,t,m);!a&&p.$isElementNode(e)&&w&&e.extractWithChild(t,b,"html")&&(a=!0)}a&&!f?(h.append(m),c.append(h),r&&(d=r.call(g,h))&&h.replaceWith(d)):
|
|
9
|
+
c.append(m);return a}function u(d,b){let {nodeName:e}=d;b=b._htmlConversions.get(e.toLowerCase());let c=null;void 0!==b&&b.forEach(a=>{a=a(d);null!==a&&(null===c||c.priority<a.priority)&&(c=a)});return null!==c?c.conversion:null}let v=new Set(["STYLE"]);
|
|
10
|
+
function x(d,b,e=new Map,c){let a=[];if(v.has(d.nodeName))return a;let f=null;var g=u(d,b);let k=g?g(d):null;g=null;if(null!==k){g=k.after;f=k.node;if(null!==f){for(var [,h]of e)if(f=h(f,c),!f)break;f&&a.push(f)}null!=k.forChild&&e.set(d.nodeName,k.forChild)}d=d.childNodes;c=[];for(h=0;h<d.length;h++)c.push(...x(d[h],b,new Map(e),f));null!=g&&(c=g(c));null==f?a=a.concat(c):p.$isElementNode(f)&&f.append(...c);return a}
|
|
11
|
+
exports.$generateHtmlFromNodes=function(d,b){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"),c=p.$getRoot().getChildren();for(let a=0;a<c.length;a++)q(d,b,c[a],e);return e.innerHTML};
|
|
12
|
+
exports.$generateNodesFromDOM=function(d,b){let e=[];b=b.body?Array.from(b.body.childNodes):[];let c=b.length;for(let f=0;f<c;f++){var a=b[f];v.has(a.nodeName)||(a=x(a,d),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>;
|