Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@lexical/clipboard

Package Overview
Dependencies
Maintainers
8
Versions
237
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@lexical/clipboard - npm Package Compare versions

Comparing version 0.12.5 to 0.12.6

104

LexicalClipboard.dev.js

@@ -167,103 +167,13 @@ /**

function $insertGeneratedNodes(editor, nodes, selection) {
const isGridSelection = lexical.DEPRECATED_$isGridSelection(selection);
const isRangeSelection = lexical.$isRangeSelection(selection);
const isSelectionInsideOfGrid = isGridSelection || isRangeSelection && utils.$findMatchingParent(selection.anchor.getNode(), n => lexical.DEPRECATED_$isGridCellNode(n)) !== null && utils.$findMatchingParent(selection.focus.getNode(), n => lexical.DEPRECATED_$isGridCellNode(n)) !== null;
if (isSelectionInsideOfGrid && nodes.length === 1 && lexical.DEPRECATED_$isGridNode(nodes[0])) {
$mergeGridNodesStrategy(nodes, selection, false, editor);
return;
if (!editor.dispatchCommand(lexical.SELECTION_INSERT_CLIPBOARD_NODES_COMMAND, {
nodes,
selection
})) {
selection.insertNodes(nodes);
}
selection.insertNodes(nodes);
return;
}
function $mergeGridNodesStrategy(nodes, selection, isFromLexical, editor) {
if (nodes.length !== 1 || !lexical.DEPRECATED_$isGridNode(nodes[0])) {
{
throw Error(`$mergeGridNodesStrategy: Expected Grid insertion.`);
}
}
const newGrid = nodes[0];
const newGridRows = newGrid.getChildren();
const newColumnCount = newGrid.getFirstChildOrThrow().getChildrenSize();
const newRowCount = newGrid.getChildrenSize();
const gridCellNode = utils.$findMatchingParent(selection.anchor.getNode(), n => lexical.DEPRECATED_$isGridCellNode(n));
const gridRowNode = gridCellNode && utils.$findMatchingParent(gridCellNode, n => lexical.DEPRECATED_$isGridRowNode(n));
const gridNode = gridRowNode && utils.$findMatchingParent(gridRowNode, n => lexical.DEPRECATED_$isGridNode(n));
if (!lexical.DEPRECATED_$isGridCellNode(gridCellNode) || !lexical.DEPRECATED_$isGridRowNode(gridRowNode) || !lexical.DEPRECATED_$isGridNode(gridNode)) {
{
throw Error(`$mergeGridNodesStrategy: Expected selection to be inside of a Grid.`);
}
}
const startY = gridRowNode.getIndexWithinParent();
const stopY = Math.min(gridNode.getChildrenSize() - 1, startY + newRowCount - 1);
const startX = gridCellNode.getIndexWithinParent();
const stopX = Math.min(gridRowNode.getChildrenSize() - 1, startX + newColumnCount - 1);
const fromX = Math.min(startX, stopX);
const fromY = Math.min(startY, stopY);
const toX = Math.max(startX, stopX);
const toY = Math.max(startY, stopY);
const gridRowNodes = gridNode.getChildren();
let newRowIdx = 0;
let newAnchorCellKey;
let newFocusCellKey;
for (let r = fromY; r <= toY; r++) {
const currentGridRowNode = gridRowNodes[r];
if (!lexical.DEPRECATED_$isGridRowNode(currentGridRowNode)) {
{
throw Error(`getNodes: expected to find GridRowNode`);
}
}
const newGridRowNode = newGridRows[newRowIdx];
if (!lexical.DEPRECATED_$isGridRowNode(newGridRowNode)) {
{
throw Error(`getNodes: expected to find GridRowNode`);
}
}
const gridCellNodes = currentGridRowNode.getChildren();
const newGridCellNodes = newGridRowNode.getChildren();
let newColumnIdx = 0;
for (let c = fromX; c <= toX; c++) {
const currentGridCellNode = gridCellNodes[c];
if (!lexical.DEPRECATED_$isGridCellNode(currentGridCellNode)) {
{
throw Error(`getNodes: expected to find GridCellNode`);
}
}
const newGridCellNode = newGridCellNodes[newColumnIdx];
if (!lexical.DEPRECATED_$isGridCellNode(newGridCellNode)) {
{
throw Error(`getNodes: expected to find GridCellNode`);
}
}
if (r === fromY && c === fromX) {
newAnchorCellKey = currentGridCellNode.getKey();
} else if (r === toY && c === toX) {
newFocusCellKey = currentGridCellNode.getKey();
}
const originalChildren = currentGridCellNode.getChildren();
newGridCellNode.getChildren().forEach(child => {
if (lexical.$isTextNode(child)) {
const paragraphNode = lexical.$createParagraphNode();
paragraphNode.append(child);
currentGridCellNode.append(child);
} else {
currentGridCellNode.append(child);
}
});
originalChildren.forEach(n => n.remove());
newColumnIdx++;
}
newRowIdx++;
}
if (newAnchorCellKey && newFocusCellKey) {
const newGridSelection = lexical.DEPRECATED_$createGridSelection();
newGridSelection.set(gridNode.getKey(), newAnchorCellKey, newFocusCellKey);
lexical.$setSelection(newGridSelection);
editor.dispatchCommand(lexical.SELECTION_CHANGE_COMMAND, undefined);
}
}
function exportNodeToJSON(node) {
const serializedNode = node.exportJSON();
const nodeClass = node.constructor;
// @ts-expect-error TODO Replace Class utility type with InstanceType
if (serializedNode.type !== nodeClass.getType()) {

@@ -274,6 +184,4 @@ {

}
// @ts-expect-error TODO Replace Class utility type with InstanceType
const serializedChildren = serializedNode.children;
if (lexical.$isElementNode(node)) {
const serializedChildren = serializedNode.children;
if (!Array.isArray(serializedChildren)) {

@@ -280,0 +188,0 @@ {

26

LexicalClipboard.prod.js

@@ -7,16 +7,12 @@ /**

*/
'use strict';var d=require("@lexical/html"),q=require("@lexical/selection"),r=require("@lexical/utils"),u=require("lexical");function z(a){let b=new URLSearchParams;b.append("code",a);for(let c=1;c<arguments.length;c++)b.append("v",arguments[c]);throw Error(`Minified Lexical error #${a}; visit https://lexical.dev/docs/error?${b} for the full message or `+"use the non-minified dev environment for full errors and additional helpful warnings.");}
let A="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement;function B(a){let b=u.$getSelection();if(null==b)throw Error("Expected valid LexicalSelection");return u.$isRangeSelection(b)&&b.isCollapsed()||0===b.getNodes().length?"":d.$generateHtmlFromNodes(a,b)}
function C(a){let b=u.$getSelection();if(null==b)throw Error("Expected valid LexicalSelection");return u.$isRangeSelection(b)&&b.isCollapsed()||0===b.getNodes().length?null:JSON.stringify(D(a,b))}
function E(a,b,c){let g=u.DEPRECATED_$isGridSelection(c),e=u.$isRangeSelection(c);(g||e&&null!==r.$findMatchingParent(c.anchor.getNode(),h=>u.DEPRECATED_$isGridCellNode(h))&&null!==r.$findMatchingParent(c.focus.getNode(),h=>u.DEPRECATED_$isGridCellNode(h)))&&1===b.length&&u.DEPRECATED_$isGridNode(b[0])?F(b,c,!1,a):c.insertNodes(b)}
function F(a,b,c,g){1===a.length&&u.DEPRECATED_$isGridNode(a[0])||z(42);var e=a[0];a=e.getChildren();c=e.getFirstChildOrThrow().getChildrenSize();var h=e.getChildrenSize(),f=r.$findMatchingParent(b.anchor.getNode(),l=>u.DEPRECATED_$isGridCellNode(l));b=(e=f&&r.$findMatchingParent(f,l=>u.DEPRECATED_$isGridRowNode(l)))&&r.$findMatchingParent(e,l=>u.DEPRECATED_$isGridNode(l));u.DEPRECATED_$isGridCellNode(f)&&u.DEPRECATED_$isGridRowNode(e)&&u.DEPRECATED_$isGridNode(b)||z(43);var k=e.getIndexWithinParent(),
m=Math.min(b.getChildrenSize()-1,k+h-1);h=f.getIndexWithinParent();f=Math.min(e.getChildrenSize()-1,h+c-1);c=Math.min(h,f);e=Math.min(k,m);h=Math.max(h,f);k=Math.max(k,m);m=b.getChildren();f=0;let n,p;for(let l=e;l<=k;l++){var t=m[l];u.DEPRECATED_$isGridRowNode(t)||z(24);var y=a[f];u.DEPRECATED_$isGridRowNode(y)||z(24);t=t.getChildren();y=y.getChildren();let G=0;for(let v=c;v<=h;v++){let w=t[v];u.DEPRECATED_$isGridCellNode(w)||z(25);let H=y[G];u.DEPRECATED_$isGridCellNode(H)||z(25);l===e&&v===c?n=
w.getKey():l===k&&v===h&&(p=w.getKey());let M=w.getChildren();H.getChildren().forEach(x=>{u.$isTextNode(x)&&u.$createParagraphNode().append(x);w.append(x)});M.forEach(x=>x.remove());G++}f++}n&&p&&(a=u.DEPRECATED_$createGridSelection(),a.set(b.getKey(),n,p),u.$setSelection(a),g.dispatchCommand(u.SELECTION_CHANGE_COMMAND,void 0))}
function I(a,b,c,g=[]){let e=null!=b?c.isSelected(b):!0,h=u.$isElementNode(c)&&c.excludeFromCopy("html");var f=c;if(null!==b){var k=q.$cloneWithProperties(c);f=k=u.$isTextNode(k)&&null!=b?q.$sliceSelectedTextNodeContent(b,k):k}let m=u.$isElementNode(f)?f.getChildren():[];var n=f;k=n.exportJSON();var p=n.constructor;k.type!==p.getType()&&z(58,p.name);let t=k.children;u.$isElementNode(n)&&(Array.isArray(t)||z(59,p.name));u.$isTextNode(f)&&(f=f.__text,0<f.length?k.text=f:e=!1);for(f=0;f<m.length;f++)n=
m[f],p=I(a,b,n,k.children),!e&&u.$isElementNode(c)&&p&&c.extractWithChild(n,b,"clone")&&(e=!0);if(e&&!h)g.push(k);else if(Array.isArray(k.children))for(a=0;a<k.children.length;a++)g.push(k.children[a]);return e}function D(a,b){let c=[],g=u.$getRoot().getChildren();for(let e=0;e<g.length;e++)I(a,b,g[e],c);return{namespace:a._config.namespace,nodes:c}}function J(a){let b=[];for(let c=0;c<a.length;c++){let g=u.$parseSerializedNode(a[c]);u.$isTextNode(g)&&q.$addNodeStyle(g);b.push(g)}return b}let K=null;
function L(a,b){var c=A?(a._window||window).getSelection():null;if(!c)return!1;var g=c.anchorNode;c=c.focusNode;if(null!==g&&null!==c&&!u.isSelectionWithinEditor(a,g,c))return!1;b.preventDefault();b=b.clipboardData;g=u.$getSelection();if(null===b||null===g)return!1;c=B(a);a=C(a);let e="";null!==g&&(e=g.getTextContent());null!==c&&b.setData("text/html",c);null!==a&&b.setData("application/x-lexical-editor",a);b.setData("text/plain",e);return!0}exports.$generateJSONFromSelectedNodes=D;
exports.$generateNodesFromSerializedNodes=J;exports.$getHtmlContent=B;exports.$getLexicalContent=C;exports.$insertDataTransferForPlainText=function(a,b){a=a.getData("text/plain")||a.getData("text/uri-list");null!=a&&b.insertRawText(a)};
exports.$insertDataTransferForRichText=function(a,b,c){var g=a.getData("application/x-lexical-editor");if(g)try{let h=JSON.parse(g);if(h.namespace===c._config.namespace&&Array.isArray(h.nodes)){let f=J(h.nodes);return E(c,f,b)}}catch(h){}if(g=a.getData("text/html"))try{var e=(new DOMParser).parseFromString(g,"text/html");let h=d.$generateNodesFromDOM(c,e);return E(c,h,b)}catch(h){}a=a.getData("text/plain")||a.getData("text/uri-list");if(null!=a)if(u.$isRangeSelection(b))for(a=a.split(/(\r?\n|\t)/),
""===a[a.length-1]&&a.pop(),c=0;c<a.length;c++)e=a[c],"\n"===e||"\r\n"===e?b.insertParagraph():"\t"===e?b.insertNodes([u.$createTabNode()]):b.insertText(e);else b.insertRawText(a)};exports.$insertGeneratedNodes=E;
exports.copyToClipboard=async function(a,b){if(null!==K)return!1;if(null!==b)return new Promise(f=>{a.update(()=>{f(L(a,b))})});var c=a.getRootElement();let g=null==a._window?window.document:a._window.document,e=A?(a._window||window).getSelection():null;if(null===c||null===e)return!1;let h=g.createElement("span");h.style.cssText="position: fixed; top: -1000px;";h.append(g.createTextNode("#"));c.append(h);c=new Range;c.setStart(h,0);c.setEnd(h,1);e.removeAllRanges();e.addRange(c);return new Promise(f=>
{let k=a.registerCommand(u.COPY_COMMAND,m=>{r.objectKlassEquals(m,ClipboardEvent)&&(k(),null!==K&&(window.clearTimeout(K),K=null),f(L(a,m)));return!0},u.COMMAND_PRIORITY_CRITICAL);K=window.setTimeout(()=>{k();K=null;f(!1)},50);g.execCommand("copy");h.remove()})}
'use strict';var f=require("@lexical/html"),m=require("@lexical/selection"),q=require("@lexical/utils"),r=require("lexical");function t(a){let b=new URLSearchParams;b.append("code",a);for(let c=1;c<arguments.length;c++)b.append("v",arguments[c]);throw Error(`Minified Lexical error #${a}; visit https://lexical.dev/docs/error?${b} for the full message or `+"use the non-minified dev environment for full errors and additional helpful warnings.");}
let u="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement;function v(a){let b=r.$getSelection();if(null==b)throw Error("Expected valid LexicalSelection");return r.$isRangeSelection(b)&&b.isCollapsed()||0===b.getNodes().length?"":f.$generateHtmlFromNodes(a,b)}
function w(a){let b=r.$getSelection();if(null==b)throw Error("Expected valid LexicalSelection");return r.$isRangeSelection(b)&&b.isCollapsed()||0===b.getNodes().length?null:JSON.stringify(x(a,b))}function y(a,b,c){a.dispatchCommand(r.SELECTION_INSERT_CLIPBOARD_NODES_COMMAND,{nodes:b,selection:c})||c.insertNodes(b)}
function z(a,b,c,d=[]){let e=null!=b?c.isSelected(b):!0,h=r.$isElementNode(c)&&c.excludeFromCopy("html");var g=c;if(null!==b){var k=m.$cloneWithProperties(c);g=k=r.$isTextNode(k)&&null!=b?m.$sliceSelectedTextNodeContent(b,k):k}let n=r.$isElementNode(g)?g.getChildren():[];var l=g;k=l.exportJSON();var p=l.constructor;k.type!==p.getType()&&t(58,p.name);r.$isElementNode(l)&&(Array.isArray(k.children)||t(59,p.name));r.$isTextNode(g)&&(g=g.__text,0<g.length?k.text=g:e=!1);for(g=0;g<n.length;g++)l=n[g],
p=z(a,b,l,k.children),!e&&r.$isElementNode(c)&&p&&c.extractWithChild(l,b,"clone")&&(e=!0);if(e&&!h)d.push(k);else if(Array.isArray(k.children))for(a=0;a<k.children.length;a++)d.push(k.children[a]);return e}function x(a,b){let c=[],d=r.$getRoot().getChildren();for(let e=0;e<d.length;e++)z(a,b,d[e],c);return{namespace:a._config.namespace,nodes:c}}function A(a){let b=[];for(let c=0;c<a.length;c++){let d=r.$parseSerializedNode(a[c]);r.$isTextNode(d)&&m.$addNodeStyle(d);b.push(d)}return b}let B=null;
function C(a,b){var c=u?(a._window||window).getSelection():null;if(!c)return!1;var d=c.anchorNode;c=c.focusNode;if(null!==d&&null!==c&&!r.isSelectionWithinEditor(a,d,c))return!1;b.preventDefault();b=b.clipboardData;d=r.$getSelection();if(null===b||null===d)return!1;c=v(a);a=w(a);let e="";null!==d&&(e=d.getTextContent());null!==c&&b.setData("text/html",c);null!==a&&b.setData("application/x-lexical-editor",a);b.setData("text/plain",e);return!0}exports.$generateJSONFromSelectedNodes=x;
exports.$generateNodesFromSerializedNodes=A;exports.$getHtmlContent=v;exports.$getLexicalContent=w;exports.$insertDataTransferForPlainText=function(a,b){a=a.getData("text/plain")||a.getData("text/uri-list");null!=a&&b.insertRawText(a)};
exports.$insertDataTransferForRichText=function(a,b,c){var d=a.getData("application/x-lexical-editor");if(d)try{let h=JSON.parse(d);if(h.namespace===c._config.namespace&&Array.isArray(h.nodes)){let g=A(h.nodes);return y(c,g,b)}}catch(h){}if(d=a.getData("text/html"))try{var e=(new DOMParser).parseFromString(d,"text/html");let h=f.$generateNodesFromDOM(c,e);return y(c,h,b)}catch(h){}a=a.getData("text/plain")||a.getData("text/uri-list");if(null!=a)if(r.$isRangeSelection(b))for(a=a.split(/(\r?\n|\t)/),
""===a[a.length-1]&&a.pop(),c=0;c<a.length;c++)e=a[c],"\n"===e||"\r\n"===e?b.insertParagraph():"\t"===e?b.insertNodes([r.$createTabNode()]):b.insertText(e);else b.insertRawText(a)};exports.$insertGeneratedNodes=y;
exports.copyToClipboard=async function(a,b){if(null!==B)return!1;if(null!==b)return new Promise(g=>{a.update(()=>{g(C(a,b))})});var c=a.getRootElement();let d=null==a._window?window.document:a._window.document,e=u?(a._window||window).getSelection():null;if(null===c||null===e)return!1;let h=d.createElement("span");h.style.cssText="position: fixed; top: -1000px;";h.append(d.createTextNode("#"));c.append(h);c=new Range;c.setStart(h,0);c.setEnd(h,1);e.removeAllRanges();e.addRange(c);return new Promise(g=>
{let k=a.registerCommand(r.COPY_COMMAND,n=>{q.objectKlassEquals(n,ClipboardEvent)&&(k(),null!==B&&(window.clearTimeout(B),B=null),g(C(a,n)));return!0},r.COMMAND_PRIORITY_CRITICAL);B=window.setTimeout(()=>{k();B=null;g(!1)},50);d.execCommand("copy");h.remove()})}

@@ -12,12 +12,12 @@ {

"license": "MIT",
"version": "0.12.5",
"version": "0.12.6",
"main": "LexicalClipboard.js",
"peerDependencies": {
"lexical": "0.12.5"
"lexical": "0.12.6"
},
"dependencies": {
"@lexical/utils": "0.12.5",
"@lexical/list": "0.12.5",
"@lexical/selection": "0.12.5",
"@lexical/html": "0.12.5"
"@lexical/utils": "0.12.6",
"@lexical/list": "0.12.6",
"@lexical/selection": "0.12.6",
"@lexical/html": "0.12.6"
},

@@ -24,0 +24,0 @@ "repository": {

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc