@lexical/html 0.9.2 → 0.11.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.
@@ -17,8 +17,8 @@ var lexical = require('lexical');
17
17
  */
18
18
 
19
19
  function $generateNodesFromDOM(editor, dom) {
20
- let lexicalNodes = [];
21
20
  const elements = dom.body ? dom.body.childNodes : [];
21
+ let lexicalNodes = [];
22
22
 
23
23
  for (let i = 0; i < elements.length; i++) {
24
24
  const element = elements[i];
@@ -52,7 +52,7 @@ function $generateHtmlFromNodes(editor, selection) {
52
52
  }
53
53
 
54
54
  function $appendNodesToHTML(editor, currentNode, parentElement, selection$1 = null) {
55
- let shouldInclude = selection$1 != null ? currentNode.isSelected() : true;
55
+ let shouldInclude = selection$1 != null ? currentNode.isSelected(selection$1) : true;
56
56
  const shouldExclude = lexical.$isElementNode(currentNode) && currentNode.excludeFromCopy('html');
57
57
  let target = currentNode;
58
58
 
@@ -122,7 +122,7 @@ function getConversionFunction(domNode, editor) {
122
122
 
123
123
  const IGNORE_TAGS = new Set(['STYLE', 'SCRIPT']);
124
124
 
125
- function $createNodesFromDOM(node, editor, forChildMap = new Map(), parentLexicalNode, preformatted = false) {
125
+ function $createNodesFromDOM(node, editor, forChildMap = new Map(), parentLexicalNode) {
126
126
  let lexicalNodes = [];
127
127
 
128
128
  if (IGNORE_TAGS.has(node.nodeName)) {
@@ -131,12 +131,13 @@ function $createNodesFromDOM(node, editor, forChildMap = new Map(), parentLexica
131
131
 
132
132
  let currentLexicalNode = null;
133
133
  const transformFunction = getConversionFunction(node, editor);
134
- const transformOutput = transformFunction ? transformFunction(node, undefined, preformatted) : null;
134
+ const transformOutput = transformFunction ? transformFunction(node) : null;
135
135
  let postTransform = null;
136
136
 
137
137
  if (transformOutput !== null) {
138
138
  postTransform = transformOutput.after;
139
- currentLexicalNode = transformOutput.node;
139
+ const transformNodes = transformOutput.node;
140
+ currentLexicalNode = Array.isArray(transformNodes) ? transformNodes[transformNodes.length - 1] : transformNodes;
140
141
 
141
142
  if (currentLexicalNode !== null) {
142
143
  for (const [, forChildFunction] of forChildMap) {
@@ -148,7 +149,7 @@ function $createNodesFromDOM(node, editor, forChildMap = new Map(), parentLexica
148
149
  }
149
150
 
150
151
  if (currentLexicalNode) {
151
- lexicalNodes.push(currentLexicalNode);
152
+ lexicalNodes.push(...(Array.isArray(transformNodes) ? transformNodes : [currentLexicalNode]));
152
153
  }
153
154
  }
154
155
 
@@ -163,7 +164,7 @@ function $createNodesFromDOM(node, editor, forChildMap = new Map(), parentLexica
163
164
  let childLexicalNodes = [];
164
165
 
165
166
  for (let i = 0; i < children.length; i++) {
166
- childLexicalNodes.push(...$createNodesFromDOM(children[i], editor, new Map(forChildMap), currentLexicalNode, preformatted || (transformOutput && transformOutput.preformatted) === true));
167
+ childLexicalNodes.push(...$createNodesFromDOM(children[i], editor, new Map(forChildMap), currentLexicalNode));
167
168
  }
168
169
 
169
170
  if (postTransform != null) {
@@ -17,6 +17,12 @@ import type {
17
17
  GridSelection,
18
18
  } from 'lexical';
19
19
 
20
+ export type FindCachedParentDOMNode = (
21
+ node: Node,
22
+ searchFn: FindCachedParentDOMNodeSearchFn,
23
+ ) => null | Node;
24
+ export type FindCachedParentDOMNodeSearchFn = (node: Node) => boolean;
25
+
20
26
  declare export function $generateHtmlFromNodes(
21
27
  editor: LexicalEditor,
22
28
  selection?: RangeSelection | NodeSelection | GridSelection | null,
@@ -4,9 +4,10 @@
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 n=require("@lexical/selection"),q=require("lexical");
8
- function r(c,d,h,a=null){let e=null!=a?d.isSelected():!0,m=q.$isElementNode(d)&&d.excludeFromCopy("html");var b=d;null!==a&&(b=n.$cloneWithProperties(d),b=q.$isTextNode(b)&&null!=a?n.$sliceSelectedTextNodeContent(a,b):b);let f=q.$isElementNode(b)?b.getChildren():[],{element:k,after:g}=b.exportDOM(c);if(!k)return!1;let l=document.createDocumentFragment();for(let p=0;p<f.length;p++){let t=f[p],w=r(c,t,l,a);!e&&q.$isElementNode(d)&&w&&d.extractWithChild(t,a,"html")&&(e=!0)}e&&!m?(k.append(l),h.append(k),
9
- g&&(c=g.call(b,k))&&k.replaceWith(c)):h.append(l);return e}let u=new Set(["STYLE","SCRIPT"]);
10
- function v(c,d,h=new Map,a,e=!1){let m=[];if(u.has(c.nodeName))return m;let b=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;b=g.node;if(null!==b){for(var [,l]of h)if(b=l(b,a),!b)break;b&&m.push(b)}null!=g.forChild&&h.set(c.nodeName,g.forChild)}c=c.childNodes;a=[];for(l=0;l<c.length;l++)a.push(...v(c[l],d,
11
- new Map(h),b,e||!0===(g&&g.preformatted)));null!=f&&(a=f(a));null==b?m=m.concat(a):q.$isElementNode(b)&&b.append(...a);return m}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"),a=q.$getRoot().getChildren();for(let e=0;e<a.length;e++)r(c,a[e],h,d);return h.innerHTML};
12
- exports.$generateNodesFromDOM=function(c,d){let h=[];d=d.body?d.body.childNodes:[];for(let e=0;e<d.length;e++){var a=d[e];u.has(a.nodeName)||(a=v(a,c),null!==a&&(h=h.concat(a)))}return h}
7
+ 'use strict';var m=require("@lexical/selection"),q=require("lexical");
8
+ function r(c,d,h,a=null){let e=null!=a?d.isSelected(a):!0,k=q.$isElementNode(d)&&d.excludeFromCopy("html");var f=d;null!==a&&(f=m.$cloneWithProperties(d),f=q.$isTextNode(f)&&null!=a?m.$sliceSelectedTextNodeContent(a,f):f);let g=q.$isElementNode(f)?f.getChildren():[],{element:b,after:l}=f.exportDOM(c);if(!b)return!1;let n=document.createDocumentFragment();for(let p=0;p<g.length;p++){let t=g[p],w=r(c,t,n,a);!e&&q.$isElementNode(d)&&w&&d.extractWithChild(t,a,"html")&&(e=!0)}e&&!k?(b.append(n),h.append(b),
9
+ l&&(c=l.call(f,b))&&b.replaceWith(c)):h.append(n);return e}let u=new Set(["STYLE","SCRIPT"]);
10
+ function v(c,d,h=new Map,a){let e=[];if(u.has(c.nodeName))return e;let k=null;var f,{nodeName:g}=c,b=d._htmlConversions.get(g.toLowerCase());g=null;if(void 0!==b)for(f of b)b=f(c),null!==b&&(null===g||g.priority<b.priority)&&(g=b);g=(f=null!==g?g.conversion:null)?f(c):null;f=null;if(null!==g){f=g.after;b=g.node;k=Array.isArray(b)?b[b.length-1]:b;if(null!==k){for(var [,l]of h)if(k=l(k,a),!k)break;k&&e.push(...(Array.isArray(b)?b:[k]))}null!=g.forChild&&h.set(c.nodeName,g.forChild)}c=c.childNodes;a=
11
+ [];for(l=0;l<c.length;l++)a.push(...v(c[l],d,new Map(h),k));null!=f&&(a=f(a));null==k?e=e.concat(a):q.$isElementNode(k)&&k.append(...a);return e}
12
+ 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"),a=q.$getRoot().getChildren();for(let e=0;e<a.length;e++)r(c,a[e],h,d);return h.innerHTML};
13
+ exports.$generateNodesFromDOM=function(c,d){d=d.body?d.body.childNodes:[];let h=[];for(let e=0;e<d.length;e++){var a=d[e];u.has(a.nodeName)||(a=v(a,c),null!==a&&(h=h.concat(a)))}return h}
package/package.json CHANGED
@@ -8,10 +8,10 @@
8
8
  "html"
9
9
  ],
10
10
  "license": "MIT",
11
- "version": "0.9.2",
11
+ "version": "0.11.0",
12
12
  "main": "LexicalHtml.js",
13
13
  "peerDependencies": {
14
- "lexical": "0.9.2"
14
+ "lexical": "0.11.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.9.2"
22
+ "@lexical/selection": "0.11.0"
23
23
  }
24
24
  }