@lexical/html 0.36.2-nightly.20250926.0 → 0.36.2-nightly.20250930.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 +2 -3
- package/LexicalHtml.dev.mjs +3 -4
- package/LexicalHtml.prod.js +1 -1
- package/LexicalHtml.prod.mjs +1 -1
- package/index.d.ts +1 -1
- package/package.json +4 -4
package/LexicalHtml.dev.js
CHANGED
|
@@ -27,11 +27,10 @@ var lexical = require('lexical');
|
|
|
27
27
|
* or an equivalent library and pass in the document here.
|
|
28
28
|
*/
|
|
29
29
|
function $generateNodesFromDOM(editor, dom) {
|
|
30
|
-
const elements = dom
|
|
30
|
+
const elements = lexical.isDOMDocumentNode(dom) ? dom.body.childNodes : dom.childNodes;
|
|
31
31
|
let lexicalNodes = [];
|
|
32
32
|
const allArtificialNodes = [];
|
|
33
|
-
for (
|
|
34
|
-
const element = elements[i];
|
|
33
|
+
for (const element of elements) {
|
|
35
34
|
if (!IGNORE_TAGS.has(element.nodeName)) {
|
|
36
35
|
const lexicalNode = $createNodesFromDOM(element, editor, allArtificialNodes, false);
|
|
37
36
|
if (lexicalNode !== null) {
|
package/LexicalHtml.dev.mjs
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
|
|
9
9
|
import { $sliceSelectedTextNodeContent } from '@lexical/selection';
|
|
10
10
|
import { isHTMLElement, isBlockDomNode } from '@lexical/utils';
|
|
11
|
-
import { $getRoot, $isElementNode, $cloneWithProperties, $isTextNode, getRegisteredNode, isDocumentFragment, $isRootOrShadowRoot, $isBlockElementNode, $createLineBreakNode, ArtificialNode__DO_NOT_USE, isInlineDomNode, $createParagraphNode } from 'lexical';
|
|
11
|
+
import { isDOMDocumentNode, $getRoot, $isElementNode, $cloneWithProperties, $isTextNode, getRegisteredNode, isDocumentFragment, $isRootOrShadowRoot, $isBlockElementNode, $createLineBreakNode, ArtificialNode__DO_NOT_USE, isInlineDomNode, $createParagraphNode } from 'lexical';
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
@@ -25,11 +25,10 @@ import { $getRoot, $isElementNode, $cloneWithProperties, $isTextNode, getRegiste
|
|
|
25
25
|
* or an equivalent library and pass in the document here.
|
|
26
26
|
*/
|
|
27
27
|
function $generateNodesFromDOM(editor, dom) {
|
|
28
|
-
const elements = dom
|
|
28
|
+
const elements = isDOMDocumentNode(dom) ? dom.body.childNodes : dom.childNodes;
|
|
29
29
|
let lexicalNodes = [];
|
|
30
30
|
const allArtificialNodes = [];
|
|
31
|
-
for (
|
|
32
|
-
const element = elements[i];
|
|
31
|
+
for (const element of elements) {
|
|
33
32
|
if (!IGNORE_TAGS.has(element.nodeName)) {
|
|
34
33
|
const lexicalNode = $createNodesFromDOM(element, editor, allArtificialNodes, false);
|
|
35
34
|
if (lexicalNode !== null) {
|
package/LexicalHtml.prod.js
CHANGED
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
"use strict";var e=require("@lexical/selection"),t=require("@lexical/utils"),n=require("lexical");function o(l,i,r,s=null){let c=null===s||i.isSelected(s);const d=n.$isElementNode(i)&&i.excludeFromCopy("html");let u=i;if(null!==s){let t=n.$cloneWithProperties(i);t=n.$isTextNode(t)&&null!==s?e.$sliceSelectedTextNodeContent(s,t):t,u=t}const a=n.$isElementNode(u)?u.getChildren():[],f=n.getRegisteredNode(l,u.getType());let m;m=f&&void 0!==f.exportDOM?f.exportDOM(l,u):u.exportDOM(l);const{element:h,after:p}=m;if(!h)return!1;const g=document.createDocumentFragment();for(let e=0;e<a.length;e++){const t=a[e],r=o(l,t,g,s);!c&&n.$isElementNode(i)&&r&&i.extractWithChild(t,s,"html")&&(c=!0)}if(c&&!d){if((t.isHTMLElement(h)||n.isDocumentFragment(h))&&h.append(g),r.append(h),p){const e=p.call(u,h);e&&(n.isDocumentFragment(h)?h.replaceChildren(e):h.replaceWith(e))}}else r.append(g);return c}const l=new Set(["STYLE","SCRIPT"]);function i(e,o,s,c,d=new Map,u){let a=[];if(l.has(e.nodeName))return a;let f=null;const m=function(e,t){const{nodeName:n}=e,o=t._htmlConversions.get(n.toLowerCase());let l=null;if(void 0!==o)for(const t of o){const n=t(e);null!==n&&(null===l||(l.priority||0)<=(n.priority||0))&&(l=n)}return null!==l?l.conversion:null}(e,o),h=m?m(e):null;let p=null;if(null!==h){p=h.after;const t=h.node;if(f=Array.isArray(t)?t[t.length-1]:t,null!==f){for(const[,e]of d)if(f=e(f,u),!f)break;f&&a.push(...Array.isArray(t)?t:[f])}null!=h.forChild&&d.set(e.nodeName,h.forChild)}const g=e.childNodes;let N=[];const $=(null==f||!n.$isRootOrShadowRoot(f))&&(null!=f&&n.$isBlockElementNode(f)||c);for(let e=0;e<g.length;e++)N.push(...i(g[e],o,s,$,new Map(d),f));return null!=p&&(N=p(N)),t.isBlockDomNode(e)&&(N=r(e,N,$?()=>{const e=new n.ArtificialNode__DO_NOT_USE;return s.push(e),e}:n.$createParagraphNode)),null==f?N.length>0?a=a.concat(N):t.isBlockDomNode(e)&&function(e){if(null==e.nextSibling||null==e.previousSibling)return!1;return n.isInlineDomNode(e.nextSibling)&&n.isInlineDomNode(e.previousSibling)}(e)&&(a=a.concat(n.$createLineBreakNode())):n.$isElementNode(f)&&f.append(...N),a}function r(e,t,o){const l=e.style.textAlign,i=[];let r=[];for(let e=0;e<t.length;e++){const s=t[e];if(n.$isBlockElementNode(s))l&&!s.getFormat()&&s.setFormat(l),i.push(s);else if(r.push(s),e===t.length-1||e<t.length-1&&n.$isBlockElementNode(t[e+1])){const e=o();e.setFormat(l),e.append(...r),i.push(e),r=[]}}return i}exports.$generateHtmlFromNodes=function(e,t){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 l=document.createElement("div"),i=n.$getRoot().getChildren();for(let n=0;n<i.length;n++){o(e,i[n],l,t)}return l.innerHTML},exports.$generateNodesFromDOM=function(e,t){const o=t
|
|
9
|
+
"use strict";var e=require("@lexical/selection"),t=require("@lexical/utils"),n=require("lexical");function o(l,i,r,s=null){let c=null===s||i.isSelected(s);const d=n.$isElementNode(i)&&i.excludeFromCopy("html");let u=i;if(null!==s){let t=n.$cloneWithProperties(i);t=n.$isTextNode(t)&&null!==s?e.$sliceSelectedTextNodeContent(s,t):t,u=t}const a=n.$isElementNode(u)?u.getChildren():[],f=n.getRegisteredNode(l,u.getType());let m;m=f&&void 0!==f.exportDOM?f.exportDOM(l,u):u.exportDOM(l);const{element:h,after:p}=m;if(!h)return!1;const g=document.createDocumentFragment();for(let e=0;e<a.length;e++){const t=a[e],r=o(l,t,g,s);!c&&n.$isElementNode(i)&&r&&i.extractWithChild(t,s,"html")&&(c=!0)}if(c&&!d){if((t.isHTMLElement(h)||n.isDocumentFragment(h))&&h.append(g),r.append(h),p){const e=p.call(u,h);e&&(n.isDocumentFragment(h)?h.replaceChildren(e):h.replaceWith(e))}}else r.append(g);return c}const l=new Set(["STYLE","SCRIPT"]);function i(e,o,s,c,d=new Map,u){let a=[];if(l.has(e.nodeName))return a;let f=null;const m=function(e,t){const{nodeName:n}=e,o=t._htmlConversions.get(n.toLowerCase());let l=null;if(void 0!==o)for(const t of o){const n=t(e);null!==n&&(null===l||(l.priority||0)<=(n.priority||0))&&(l=n)}return null!==l?l.conversion:null}(e,o),h=m?m(e):null;let p=null;if(null!==h){p=h.after;const t=h.node;if(f=Array.isArray(t)?t[t.length-1]:t,null!==f){for(const[,e]of d)if(f=e(f,u),!f)break;f&&a.push(...Array.isArray(t)?t:[f])}null!=h.forChild&&d.set(e.nodeName,h.forChild)}const g=e.childNodes;let N=[];const $=(null==f||!n.$isRootOrShadowRoot(f))&&(null!=f&&n.$isBlockElementNode(f)||c);for(let e=0;e<g.length;e++)N.push(...i(g[e],o,s,$,new Map(d),f));return null!=p&&(N=p(N)),t.isBlockDomNode(e)&&(N=r(e,N,$?()=>{const e=new n.ArtificialNode__DO_NOT_USE;return s.push(e),e}:n.$createParagraphNode)),null==f?N.length>0?a=a.concat(N):t.isBlockDomNode(e)&&function(e){if(null==e.nextSibling||null==e.previousSibling)return!1;return n.isInlineDomNode(e.nextSibling)&&n.isInlineDomNode(e.previousSibling)}(e)&&(a=a.concat(n.$createLineBreakNode())):n.$isElementNode(f)&&f.append(...N),a}function r(e,t,o){const l=e.style.textAlign,i=[];let r=[];for(let e=0;e<t.length;e++){const s=t[e];if(n.$isBlockElementNode(s))l&&!s.getFormat()&&s.setFormat(l),i.push(s);else if(r.push(s),e===t.length-1||e<t.length-1&&n.$isBlockElementNode(t[e+1])){const e=o();e.setFormat(l),e.append(...r),i.push(e),r=[]}}return i}exports.$generateHtmlFromNodes=function(e,t){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 l=document.createElement("div"),i=n.$getRoot().getChildren();for(let n=0;n<i.length;n++){o(e,i[n],l,t)}return l.innerHTML},exports.$generateNodesFromDOM=function(e,t){const o=n.isDOMDocumentNode(t)?t.body.childNodes:t.childNodes;let r=[];const s=[];for(const t of o)if(!l.has(t.nodeName)){const n=i(t,e,s,!1);null!==n&&(r=r.concat(n))}return function(e){for(const t of e)t.getNextSibling()instanceof n.ArtificialNode__DO_NOT_USE&&t.insertAfter(n.$createLineBreakNode());for(const t of e){const e=t.getChildren();for(const n of e)t.insertBefore(n);t.remove()}}(s),r};
|
package/LexicalHtml.prod.mjs
CHANGED
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import{$sliceSelectedTextNodeContent as e}from"@lexical/selection";import{isHTMLElement as n,isBlockDomNode as t}from"@lexical/utils";import{
|
|
9
|
+
import{$sliceSelectedTextNodeContent as e}from"@lexical/selection";import{isHTMLElement as n,isBlockDomNode as t}from"@lexical/utils";import{isDOMDocumentNode as o,$getRoot as l,$isElementNode as r,$cloneWithProperties as i,$isTextNode as s,getRegisteredNode as c,isDocumentFragment as u,$isRootOrShadowRoot as f,$isBlockElementNode as a,$createLineBreakNode as d,ArtificialNode__DO_NOT_USE as p,isInlineDomNode as h,$createParagraphNode as m}from"lexical";function g(e,n){const t=o(n)?n.body.childNodes:n.childNodes;let l=[];const r=[];for(const n of t)if(!y.has(n.nodeName)){const t=C(n,e,r,!1);null!==t&&(l=l.concat(t))}return function(e){for(const n of e)n.getNextSibling()instanceof p&&n.insertAfter(d());for(const n of e){const e=n.getChildren();for(const t of e)n.insertBefore(t);n.remove()}}(r),l}function x(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++){w(e,o[l],t,n)}return t.innerHTML}function w(t,o,l,f=null){let a=null===f||o.isSelected(f);const d=r(o)&&o.excludeFromCopy("html");let p=o;if(null!==f){let n=i(o);n=s(n)&&null!==f?e(f,n):n,p=n}const h=r(p)?p.getChildren():[],m=c(t,p.getType());let g;g=m&&void 0!==m.exportDOM?m.exportDOM(t,p):p.exportDOM(t);const{element:x,after:y}=g;if(!x)return!1;const C=document.createDocumentFragment();for(let e=0;e<h.length;e++){const n=h[e],l=w(t,n,C,f);!a&&r(o)&&l&&o.extractWithChild(n,f,"html")&&(a=!0)}if(a&&!d){if((n(x)||u(x))&&x.append(C),l.append(x),y){const e=y.call(p,x);e&&(u(x)?x.replaceChildren(e):x.replaceWith(e))}}else l.append(C);return a}const y=new Set(["STYLE","SCRIPT"]);function C(e,n,o,l,i=new Map,s){let c=[];if(y.has(e.nodeName))return c;let u=null;const g=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),x=g?g(e):null;let w=null;if(null!==x){w=x.after;const n=x.node;if(u=Array.isArray(n)?n[n.length-1]:n,null!==u){for(const[,e]of i)if(u=e(u,s),!u)break;u&&c.push(...Array.isArray(n)?n:[u])}null!=x.forChild&&i.set(e.nodeName,x.forChild)}const S=e.childNodes;let v=[];const N=(null==u||!f(u))&&(null!=u&&a(u)||l);for(let e=0;e<S.length;e++)v.push(...C(S[e],n,o,N,new Map(i),u));return null!=w&&(v=w(v)),t(e)&&(v=b(e,v,N?()=>{const e=new p;return o.push(e),e}:m)),null==u?v.length>0?c=c.concat(v):t(e)&&function(e){if(null==e.nextSibling||null==e.previousSibling)return!1;return h(e.nextSibling)&&h(e.previousSibling)}(e)&&(c=c.concat(d())):r(u)&&u.append(...v),c}function b(e,n,t){const o=e.style.textAlign,l=[];let r=[];for(let e=0;e<n.length;e++){const i=n[e];if(a(i))o&&!i.getFormat()&&i.setFormat(o),l.push(i);else if(r.push(i),e===n.length-1||e<n.length-1&&a(n[e+1])){const e=t();e.setFormat(o),e.append(...r),l.push(e),r=[]}}return l}export{x as $generateHtmlFromNodes,g as $generateNodesFromDOM};
|
package/index.d.ts
CHANGED
|
@@ -11,5 +11,5 @@ import type { BaseSelection, LexicalEditor, LexicalNode } from 'lexical';
|
|
|
11
11
|
* DOMParser API to generate a document (see clipboard.ts), but to use in a headless environment you can use JSDom
|
|
12
12
|
* or an equivalent library and pass in the document here.
|
|
13
13
|
*/
|
|
14
|
-
export declare function $generateNodesFromDOM(editor: LexicalEditor, dom: Document): Array<LexicalNode>;
|
|
14
|
+
export declare function $generateNodesFromDOM(editor: LexicalEditor, dom: Document | ParentNode): Array<LexicalNode>;
|
|
15
15
|
export declare function $generateHtmlFromNodes(editor: LexicalEditor, selection?: BaseSelection | null): string;
|
package/package.json
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"html"
|
|
9
9
|
],
|
|
10
10
|
"license": "MIT",
|
|
11
|
-
"version": "0.36.2-nightly.
|
|
11
|
+
"version": "0.36.2-nightly.20250930.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.36.2-nightly.
|
|
21
|
-
"@lexical/utils": "0.36.2-nightly.
|
|
22
|
-
"lexical": "0.36.2-nightly.
|
|
20
|
+
"@lexical/selection": "0.36.2-nightly.20250930.0",
|
|
21
|
+
"@lexical/utils": "0.36.2-nightly.20250930.0",
|
|
22
|
+
"lexical": "0.36.2-nightly.20250930.0"
|
|
23
23
|
},
|
|
24
24
|
"module": "LexicalHtml.mjs",
|
|
25
25
|
"sideEffects": false,
|