@lexical/clipboard
Advanced tools
Comparing version 0.3.3 to 0.3.4
@@ -10,2 +10,3 @@ /** | ||
var html = require('@lexical/html'); | ||
var list = require('@lexical/list'); | ||
var selection = require('@lexical/selection'); | ||
@@ -92,39 +93,50 @@ var utils = require('@lexical/utils'); | ||
$basicInsertStrategy(nodes, selection, false); | ||
$basicInsertStrategy(nodes, selection); | ||
return; | ||
} | ||
function $basicInsertStrategy(nodes, selection, isFromLexical) { | ||
let nodesToInsert; | ||
function $basicInsertStrategy(nodes, selection) { | ||
// Wrap text and inline nodes in paragraph nodes so we have all blocks at the top-level | ||
const topLevelBlocks = []; | ||
let currentBlock = null; | ||
let list$1 = null; | ||
if (!isFromLexical) { | ||
// Wrap text and inline nodes in paragraph nodes so we have all blocks at the top-level | ||
const topLevelBlocks = []; | ||
let currentBlock = null; | ||
for (let i = 0; i < nodes.length; i++) { | ||
const node = nodes[i]; | ||
/** | ||
* There's no good way to add this to importDOM or importJSON directly, | ||
* so this is here in order to safely correct faulty clipboard data | ||
* that we can't control and avoid crashing the app. | ||
* https://github.com/facebook/lexical/issues/2405 | ||
*/ | ||
for (let i = 0; i < nodes.length; i++) { | ||
const node = nodes[i]; | ||
if (list.$isListItemNode(node)) { | ||
if (list$1 == null) { | ||
list$1 = list.$createListNode('bullet'); | ||
topLevelBlocks.push(list$1); | ||
} | ||
if (lexical.$isDecoratorNode(node) && !node.isTopLevel() || lexical.$isElementNode(node) && node.isInline() || lexical.$isTextNode(node) || lexical.$isLineBreakNode(node)) { | ||
if (currentBlock === null) { | ||
currentBlock = lexical.$createParagraphNode(); | ||
topLevelBlocks.push(currentBlock); | ||
} | ||
list$1.append(node); | ||
continue; | ||
} else if (list$1 != null) { | ||
list$1 = null; | ||
} | ||
if (currentBlock !== null) { | ||
currentBlock.append(node); | ||
} | ||
} else { | ||
topLevelBlocks.push(node); | ||
currentBlock = null; | ||
if (lexical.$isDecoratorNode(node) && !node.isTopLevel() || lexical.$isElementNode(node) && node.isInline() || lexical.$isTextNode(node) || lexical.$isLineBreakNode(node)) { | ||
if (currentBlock === null) { | ||
currentBlock = lexical.$createParagraphNode(); | ||
topLevelBlocks.push(currentBlock); | ||
} | ||
if (currentBlock !== null) { | ||
currentBlock.append(node); | ||
} | ||
} else { | ||
topLevelBlocks.push(node); | ||
currentBlock = null; | ||
} | ||
nodesToInsert = topLevelBlocks; | ||
} else { | ||
nodesToInsert = nodes; | ||
} | ||
if (lexical.$isRangeSelection(selection)) { | ||
selection.insertNodes(nodesToInsert); | ||
selection.insertNodes(topLevelBlocks); | ||
} else if (lexical.$isGridSelection(selection)) { | ||
@@ -140,3 +152,3 @@ // If there's an active grid selection and a non grid is pasted, add to the anchor. | ||
anchorCell.append(...nodesToInsert); | ||
anchorCell.append(...topLevelBlocks); | ||
} | ||
@@ -331,3 +343,9 @@ } | ||
const serializedNode = serializedNodes[i]; | ||
nodes.push(lexical.$parseSerializedNode(serializedNode)); | ||
const node = lexical.$parseSerializedNode(serializedNode); | ||
if (lexical.$isTextNode(node)) { | ||
selection.$addNodeStyle(node); | ||
} | ||
nodes.push(node); | ||
} | ||
@@ -334,0 +352,0 @@ |
@@ -7,11 +7,12 @@ /** | ||
*/ | ||
'use strict';var b=require("@lexical/html"),p=require("@lexical/selection"),t=require("@lexical/utils"),y=require("lexical");function z(c){throw Error(`Minified Lexical error #${c}; see codes.json for the full message or `+"use the non-minified dev environment for full errors and additional helpful warnings.");}function A(c,a){c=c.getData("text/plain");null!=c&&a.insertRawText(c)} | ||
function B(c,a,d){(y.$isGridSelection(d)||null!==t.$findMatchingParent(d.anchor.getNode(),h=>y.$isGridCellNode(h))&&null!==t.$findMatchingParent(d.focus.getNode(),h=>y.$isGridCellNode(h)))&&1===a.length&&y.$isGridNode(a[0])?E(a,d,!1,c):F(a,d,!1)} | ||
function F(c,a,d){if(!d){d=[];let h=null;for(let g=0;g<c.length;g++){let f=c[g];y.$isDecoratorNode(f)&&!f.isTopLevel()||y.$isElementNode(f)&&f.isInline()||y.$isTextNode(f)||y.$isLineBreakNode(f)?(null===h&&(h=y.$createParagraphNode(),d.push(h)),null!==h&&h.append(f)):(d.push(f),h=null)}c=d}y.$isRangeSelection(a)?a.insertNodes(c):y.$isGridSelection(a)&&(a=a.anchor.getNode(),y.$isGridCellNode(a)||z(41),a.append(...c))} | ||
function E(c,a,d,h){1===c.length&&y.$isGridNode(c[0])||z(42);var g=c[0];c=g.getChildren();d=g.getFirstChildOrThrow().getChildrenSize();var f=g.getChildrenSize(),e=t.$findMatchingParent(a.anchor.getNode(),l=>y.$isGridCellNode(l));a=(g=e&&t.$findMatchingParent(e,l=>y.$isGridRowNode(l)))&&t.$findMatchingParent(g,l=>y.$isGridNode(l));y.$isGridCellNode(e)&&y.$isGridRowNode(g)&&y.$isGridNode(a)||z(43);var m=g.getIndexWithinParent(),n=Math.min(a.getChildrenSize()-1,m+f-1);f=e.getIndexWithinParent();e=Math.min(g.getChildrenSize()- | ||
1,f+d-1);d=Math.min(f,e);g=Math.min(m,n);f=Math.max(f,e);m=Math.max(m,n);n=a.getChildren();e=0;let k,q;for(let l=g;l<=m;l++){var r=n[l];y.$isGridRowNode(r)||z(24);var x=c[e];y.$isGridRowNode(x)||z(24);r=r.getChildren();x=x.getChildren();let C=0;for(let u=d;u<=f;u++){let v=r[u];y.$isGridCellNode(v)||z(25);let D=x[C];y.$isGridCellNode(D)||z(25);l===g&&u===d?k=v.getKey():l===m&&u===f&&(q=v.getKey());let H=v.getChildren();D.getChildren().forEach(w=>{y.$isTextNode(w)&&y.$createParagraphNode().append(w); | ||
v.append(w)});H.forEach(w=>w.remove());C++}e++}k&&q&&(c=y.$createGridSelection(),c.set(a.getKey(),k,q),y.$setSelection(c),h.dispatchCommand(y.SELECTION_CHANGE_COMMAND,void 0))} | ||
function G(c,a,d,h){let g=null!=a?d.isSelected():!0,f=y.$isElementNode(d)&&d.excludeFromCopy("html");var e=p.$cloneWithProperties(d);e=y.$isTextNode(e)&&null!=a?p.$sliceSelectedTextNodeContent(a,e):e;let m=y.$isElementNode(e)?e.getChildren():[];var n=e;let k=n.exportJSON();var q=n.constructor;k.type!==q.getType()&&z(58,q.name);let r=k.children;y.$isElementNode(n)&&(Array.isArray(r)||z(59,q.name));y.$isTextNode(e)&&(k.text=e.__text);for(e=0;e<m.length;e++)n=m[e],q=G(c,a,n,k.children),!g&&y.$isElementNode(d)&& | ||
q&&d.extractWithChild(n,a,"clone")&&(g=!0);if(g&&!f)h.push(k);else if(Array.isArray(k.children))for(c=0;c<k.children.length;c++)h.push(k.children[c]);return g}exports.$getHtmlContent=function(c){let a=y.$getSelection();if(null==a)throw Error("Expected valid LexicalSelection");return y.$isRangeSelection(a)&&a.isCollapsed()||0===a.getNodes().length?null:b.$generateHtmlFromNodes(c,a)}; | ||
exports.$getLexicalContent=function(c){let a=y.$getSelection();if(null==a)throw Error("Expected valid LexicalSelection");if(y.$isRangeSelection(a)&&a.isCollapsed()||0===a.getNodes().length)return null;var d=JSON,h=d.stringify;let g=[],f=y.$getRoot().getChildren();for(let e=0;e<f.length;e++)G(c,a,f[e],g);return h.call(d,{namespace:c._config.namespace,nodes:g})};exports.$insertDataTransferForPlainText=A; | ||
exports.$insertDataTransferForRichText=function(c,a,d){let h=c.getData("text/html");var g=c.getData("application/x-lexical-editor");if(g)try{var f=JSON.parse(g);if(f.namespace===d._config.namespace&&Array.isArray(f.nodes)){var e=f.nodes;g=[];for(f=0;f<e.length;f++)g.push(y.$parseSerializedNode(e[f]));return B(d,g,a)}}catch{}if(h)try{let m=(new DOMParser).parseFromString(h,"text/html");return B(d,b.$generateNodesFromDOM(d,m),a)}catch{}A(c,a)} | ||
'use strict';var b=require("@lexical/html"),p=require("@lexical/list"),r=require("@lexical/selection"),y=require("@lexical/utils"),z=require("lexical");function A(d){throw Error(`Minified Lexical error #${d}; see codes.json for the full message or `+"use the non-minified dev environment for full errors and additional helpful warnings.");}function B(d,c){d=d.getData("text/plain");null!=d&&c.insertRawText(d)} | ||
function C(d,c,e){(z.$isGridSelection(e)||null!==y.$findMatchingParent(e.anchor.getNode(),h=>z.$isGridCellNode(h))&&null!==y.$findMatchingParent(e.focus.getNode(),h=>z.$isGridCellNode(h)))&&1===c.length&&z.$isGridNode(c[0])?F(c,e,!1,d):G(c,e)} | ||
function G(d,c){let e=[],h=null,f=null;for(let g=0;g<d.length;g++){let a=d[g];p.$isListItemNode(a)?(null==f&&(f=p.$createListNode("bullet"),e.push(f)),f.append(a)):(null!=f&&(f=null),z.$isDecoratorNode(a)&&!a.isTopLevel()||z.$isElementNode(a)&&a.isInline()||z.$isTextNode(a)||z.$isLineBreakNode(a)?(null===h&&(h=z.$createParagraphNode(),e.push(h)),null!==h&&h.append(a)):(e.push(a),h=null))}z.$isRangeSelection(c)?c.insertNodes(e):z.$isGridSelection(c)&&(d=c.anchor.getNode(),z.$isGridCellNode(d)||A(41), | ||
d.append(...e))} | ||
function F(d,c,e,h){1===d.length&&z.$isGridNode(d[0])||A(42);var f=d[0];d=f.getChildren();e=f.getFirstChildOrThrow().getChildrenSize();var g=f.getChildrenSize(),a=y.$findMatchingParent(c.anchor.getNode(),m=>z.$isGridCellNode(m));c=(f=a&&y.$findMatchingParent(a,m=>z.$isGridRowNode(m)))&&y.$findMatchingParent(f,m=>z.$isGridNode(m));z.$isGridCellNode(a)&&z.$isGridRowNode(f)&&z.$isGridNode(c)||A(43);var k=f.getIndexWithinParent(),n=Math.min(c.getChildrenSize()-1,k+g-1);g=a.getIndexWithinParent();a=Math.min(f.getChildrenSize()- | ||
1,g+e-1);e=Math.min(g,a);f=Math.min(k,n);g=Math.max(g,a);k=Math.max(k,n);n=c.getChildren();a=0;let l,q;for(let m=f;m<=k;m++){var w=n[m];z.$isGridRowNode(w)||A(24);var x=d[a];z.$isGridRowNode(x)||A(24);w=w.getChildren();x=x.getChildren();let D=0;for(let t=e;t<=g;t++){let u=w[t];z.$isGridCellNode(u)||A(25);let E=x[D];z.$isGridCellNode(E)||A(25);m===f&&t===e?l=u.getKey():m===k&&t===g&&(q=u.getKey());let I=u.getChildren();E.getChildren().forEach(v=>{z.$isTextNode(v)&&z.$createParagraphNode().append(v); | ||
u.append(v)});I.forEach(v=>v.remove());D++}a++}l&&q&&(d=z.$createGridSelection(),d.set(c.getKey(),l,q),z.$setSelection(d),h.dispatchCommand(z.SELECTION_CHANGE_COMMAND,void 0))} | ||
function H(d,c,e,h){let f=null!=c?e.isSelected():!0,g=z.$isElementNode(e)&&e.excludeFromCopy("html");var a=r.$cloneWithProperties(e);a=z.$isTextNode(a)&&null!=c?r.$sliceSelectedTextNodeContent(c,a):a;let k=z.$isElementNode(a)?a.getChildren():[];var n=a;let l=n.exportJSON();l.type!==n.constructor.getType()&&A(58);var q=l.children;z.$isElementNode(n)&&(Array.isArray(q)||A(59));z.$isTextNode(a)&&(l.text=a.__text);for(a=0;a<k.length;a++)n=k[a],q=H(d,c,n,l.children),!f&&z.$isElementNode(e)&&q&&e.extractWithChild(n, | ||
c,"clone")&&(f=!0);if(f&&!g)h.push(l);else if(Array.isArray(l.children))for(d=0;d<l.children.length;d++)h.push(l.children[d]);return f}exports.$getHtmlContent=function(d){let c=z.$getSelection();if(null==c)throw Error("Expected valid LexicalSelection");return z.$isRangeSelection(c)&&c.isCollapsed()||0===c.getNodes().length?null:b.$generateHtmlFromNodes(d,c)}; | ||
exports.$getLexicalContent=function(d){let c=z.$getSelection();if(null==c)throw Error("Expected valid LexicalSelection");if(z.$isRangeSelection(c)&&c.isCollapsed()||0===c.getNodes().length)return null;var e=JSON,h=e.stringify;let f=[],g=z.$getRoot().getChildren();for(let a=0;a<g.length;a++)H(d,c,g[a],f);return h.call(e,{namespace:d._config.namespace,nodes:f})};exports.$insertDataTransferForPlainText=B; | ||
exports.$insertDataTransferForRichText=function(d,c,e){let h=d.getData("text/html");var f=d.getData("application/x-lexical-editor");if(f)try{var g=JSON.parse(f);if(g.namespace===e._config.namespace&&Array.isArray(g.nodes)){var a=g.nodes;f=[];for(g=0;g<a.length;g++){let k=z.$parseSerializedNode(a[g]);z.$isTextNode(k)&&r.$addNodeStyle(k);f.push(k)}return C(e,f,c)}}catch{}if(h)try{let k=(new DOMParser).parseFromString(h,"text/html");return C(e,b.$generateNodesFromDOM(e,k),c)}catch{}B(d,c)} |
@@ -12,11 +12,11 @@ { | ||
"license": "MIT", | ||
"version": "0.3.3", | ||
"version": "0.3.4", | ||
"main": "LexicalClipboard.js", | ||
"peerDependencies": { | ||
"lexical": "0.3.3" | ||
"lexical": "0.3.4" | ||
}, | ||
"dependencies": { | ||
"@lexical/utils": "0.3.3", | ||
"@lexical/selection": "0.3.3", | ||
"@lexical/html": "0.3.3" | ||
"@lexical/utils": "0.3.4", | ||
"@lexical/selection": "0.3.4", | ||
"@lexical/html": "0.3.4" | ||
}, | ||
@@ -23,0 +23,0 @@ "repository": { |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
21062
9
356
1
+ Added@lexical/html@0.3.4(transitive)
+ Added@lexical/list@0.3.4(transitive)
+ Added@lexical/selection@0.3.4(transitive)
+ Added@lexical/table@0.3.4(transitive)
+ Added@lexical/utils@0.3.4(transitive)
+ Addedlexical@0.3.4(transitive)
- Removed@lexical/html@0.3.3(transitive)
- Removed@lexical/list@0.3.3(transitive)
- Removed@lexical/selection@0.3.3(transitive)
- Removed@lexical/table@0.3.3(transitive)
- Removed@lexical/utils@0.3.3(transitive)
- Removedlexical@0.3.3(transitive)
Updated@lexical/html@0.3.4
Updated@lexical/selection@0.3.4
Updated@lexical/utils@0.3.4