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

@lexical/clipboard

Package Overview
Dependencies
Maintainers
6
Versions
236
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.7.6 to 0.7.7

73

LexicalClipboard.dev.js

@@ -10,3 +10,2 @@ /**

var html = require('@lexical/html');
var list = require('@lexical/list');
var selection = require('@lexical/selection');

@@ -27,3 +26,5 @@ var utils = require('@lexical/utils');

if (selection == null) {
throw new Error('Expected valid LexicalSelection');
{
throw Error(`Expected valid LexicalSelection`);
}
} // If we haven't selected anything

@@ -44,3 +45,5 @@

if (selection == null) {
throw new Error('Expected valid LexicalSelection');
{
throw Error(`Expected valid LexicalSelection`);
}
} // If we haven't selected anything

@@ -72,5 +75,5 @@

return $insertGeneratedNodes(editor, nodes, selection);
} // eslint-disable-next-line no-empty
} catch {}
}
} catch {// Fail silently.
}
}

@@ -85,4 +88,5 @@

const nodes = html.$generateNodesFromDOM(editor, dom);
return $insertGeneratedNodes(editor, nodes, selection); // eslint-disable-next-line no-empty
} catch {}
return $insertGeneratedNodes(editor, nodes, selection);
} catch {// Fail silently.
}
} // Multi-line plain text in rich text mode pasted as separate paragraphs

@@ -127,30 +131,10 @@ // instead of single paragraph with linebreaks.

let currentBlock = null;
let list$1 = 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
*/
if (list.$isListItemNode(node)) {
if (list$1 == null) {
list$1 = list.$createListNode('bullet');
topLevelBlocks.push(list$1);
}
list$1.append(node);
continue;
} else if (list$1 != null) {
list$1 = null;
}
const isLineBreakNode = lexical.$isLineBreakNode(node);
if (isLineBreakNode || lexical.$isDecoratorNode(node) && node.isInline() || lexical.$isElementNode(node) && node.isInline() || lexical.$isTextNode(node)) {
if (isLineBreakNode || lexical.$isDecoratorNode(node) && node.isInline() || lexical.$isElementNode(node) && node.isInline() || lexical.$isTextNode(node) || node.isParentRequired()) {
if (currentBlock === null) {
currentBlock = lexical.$createParagraphNode();
currentBlock = node.createParentElementNode();
topLevelBlocks.push(currentBlock); // In the case of LineBreakNode, we just need to

@@ -317,3 +301,3 @@ // add an empty ParagraphNode to the topLevelBlocks.

function $appendNodesToJSON(editor, selection$1, currentNode, targetArray = []) {
let shouldInclude = selection$1 != null ? currentNode.isSelected() : true;
let shouldInclude = selection$1 != null ? currentNode.isSelected(selection$1) : true;
const shouldExclude = lexical.$isElementNode(currentNode) && currentNode.excludeFromCopy('html');

@@ -337,3 +321,11 @@ let target = currentNode;

if (lexical.$isTextNode(target)) {
serializedNode.text = target.__text;
const text = target.__text; // If an uncollapsed selection ends or starts at the end of a line of specialized,
// TextNodes, such as code tokens, we will get a 'blank' TextNode here, i.e., one
// with text of length 0. We don't want this, it makes a confusing mess. Reset!
if (text.length > 0) {
serializedNode.text = text;
} else {
shouldInclude = false;
}
}

@@ -458,10 +450,23 @@

function $copyToClipboardEvent(editor, event) {
const domSelection = window.getSelection();
if (!domSelection) {
return false;
}
const anchorDOM = domSelection.anchorNode;
const focusDOM = domSelection.focusNode;
if (anchorDOM !== null && focusDOM !== null && !lexical.isSelectionWithinEditor(editor, anchorDOM, focusDOM)) {
return false;
}
event.preventDefault();
const clipboardData = event.clipboardData;
const selection = lexical.$getSelection();
if (clipboardData === null) {
if (clipboardData === null || selection === null) {
return false;
}
const selection = lexical.$getSelection();
const htmlString = $getHtmlContent(editor);

@@ -468,0 +473,0 @@ const lexicalString = $getLexicalContent(editor);

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

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

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

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

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

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