Socket
Socket
Sign inDemoInstall

@lexical/clipboard

Package Overview
Dependencies
Maintainers
6
Versions
171
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.4.1 to 0.5.0

4

clipboard.d.ts

@@ -13,3 +13,4 @@ /**

export declare function $insertDataTransferForRichText(dataTransfer: DataTransfer, selection: RangeSelection | GridSelection, editor: LexicalEditor): void;
interface BaseSerializedNode {
export declare function $insertGeneratedNodes(editor: LexicalEditor, nodes: Array<LexicalNode>, selection: RangeSelection | GridSelection): void;
export interface BaseSerializedNode {
children?: Array<BaseSerializedNode>;

@@ -24,2 +25,1 @@ type: string;

export declare function $generateNodesFromSerializedNodes(serializedNodes: Array<BaseSerializedNode>): Array<LexicalNode>;
export {};

@@ -9,3 +9,3 @@ /** @module @lexical/clipboard */

*/
import { $getHtmlContent, $getLexicalContent, $insertDataTransferForPlainText, $insertDataTransferForRichText } from './clipboard';
export { $getHtmlContent, $getLexicalContent, $insertDataTransferForPlainText, $insertDataTransferForRichText, };
import { $generateJSONFromSelectedNodes, $generateNodesFromSerializedNodes, $getHtmlContent, $getLexicalContent, $insertDataTransferForPlainText, $insertDataTransferForRichText, $insertGeneratedNodes } from './clipboard';
export { $generateJSONFromSelectedNodes, $generateNodesFromSerializedNodes, $getHtmlContent, $getLexicalContent, $insertDataTransferForPlainText, $insertDataTransferForRichText, $insertGeneratedNodes, };

@@ -104,7 +104,6 @@ /**

}
function $insertGeneratedNodes(editor, nodes, selection) {
const isSelectionInsideOfGrid = lexical.$isGridSelection(selection) || utils.$findMatchingParent(selection.anchor.getNode(), n => lexical.$isGridCellNode(n)) !== null && utils.$findMatchingParent(selection.focus.getNode(), n => lexical.$isGridCellNode(n)) !== null;
const isSelectionInsideOfGrid = lexical.DEPRECATED_$isGridSelection(selection) || 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.$isGridNode(nodes[0])) {
if (isSelectionInsideOfGrid && nodes.length === 1 && lexical.DEPRECATED_$isGridNode(nodes[0])) {
$mergeGridNodesStrategy(nodes, selection, false, editor);

@@ -145,3 +144,3 @@ return;

if (lexical.$isDecoratorNode(node) && !node.isTopLevel() || lexical.$isElementNode(node) && node.isInline() || lexical.$isTextNode(node) || lexical.$isLineBreakNode(node)) {
if (lexical.$isDecoratorNode(node) && node.isInline() || lexical.$isElementNode(node) && node.isInline() || lexical.$isTextNode(node) || lexical.$isLineBreakNode(node)) {
if (currentBlock === null) {

@@ -163,7 +162,7 @@ currentBlock = lexical.$createParagraphNode();

selection.insertNodes(topLevelBlocks);
} else if (lexical.$isGridSelection(selection)) {
} else if (lexical.DEPRECATED_$isGridSelection(selection)) {
// If there's an active grid selection and a non grid is pasted, add to the anchor.
const anchorCell = selection.anchor.getNode();
if (!lexical.$isGridCellNode(anchorCell)) {
if (!lexical.DEPRECATED_$isGridCellNode(anchorCell)) {
{

@@ -179,3 +178,3 @@ throw Error(`Expected Grid Cell in Grid Selection`);

function $mergeGridNodesStrategy(nodes, selection, isFromLexical, editor) {
if (nodes.length !== 1 || !lexical.$isGridNode(nodes[0])) {
if (nodes.length !== 1 || !lexical.DEPRECATED_$isGridNode(nodes[0])) {
{

@@ -190,7 +189,7 @@ throw Error(`$mergeGridNodesStrategy: Expected Grid insertion.`);

const newRowCount = newGrid.getChildrenSize();
const gridCellNode = utils.$findMatchingParent(selection.anchor.getNode(), n => lexical.$isGridCellNode(n));
const gridRowNode = gridCellNode && utils.$findMatchingParent(gridCellNode, n => lexical.$isGridRowNode(n));
const gridNode = gridRowNode && utils.$findMatchingParent(gridRowNode, n => lexical.$isGridNode(n));
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.$isGridCellNode(gridCellNode) || !lexical.$isGridRowNode(gridRowNode) || !lexical.$isGridNode(gridNode)) {
if (!lexical.DEPRECATED_$isGridCellNode(gridCellNode) || !lexical.DEPRECATED_$isGridRowNode(gridRowNode) || !lexical.DEPRECATED_$isGridNode(gridNode)) {
{

@@ -217,3 +216,3 @@ throw Error(`$mergeGridNodesStrategy: Expected selection to be inside of a Grid.`);

if (!lexical.$isGridRowNode(currentGridRowNode)) {
if (!lexical.DEPRECATED_$isGridRowNode(currentGridRowNode)) {
{

@@ -226,3 +225,3 @@ throw Error(`getNodes: expected to find GridRowNode`);

if (!lexical.$isGridRowNode(newGridRowNode)) {
if (!lexical.DEPRECATED_$isGridRowNode(newGridRowNode)) {
{

@@ -240,3 +239,3 @@ throw Error(`getNodes: expected to find GridRowNode`);

if (!lexical.$isGridCellNode(currentGridCellNode)) {
if (!lexical.DEPRECATED_$isGridCellNode(currentGridCellNode)) {
{

@@ -249,3 +248,3 @@ throw Error(`getNodes: expected to find GridCellNode`);

if (!lexical.$isGridCellNode(newGridCellNode)) {
if (!lexical.DEPRECATED_$isGridCellNode(newGridCellNode)) {
{

@@ -280,3 +279,3 @@ throw Error(`getNodes: expected to find GridCellNode`);

if (newAnchorCellKey && newFocusCellKey) {
const newGridSelection = lexical.$createGridSelection();
const newGridSelection = lexical.DEPRECATED_$createGridSelection();
newGridSelection.set(gridNode.getKey(), newAnchorCellKey, newFocusCellKey);

@@ -315,6 +314,12 @@ lexical.$setSelection(newGridSelection);

const shouldExclude = lexical.$isElementNode(currentNode) && currentNode.excludeFromCopy('html');
let clone = selection.$cloneWithProperties(currentNode);
clone = lexical.$isTextNode(clone) && selection$1 != null ? selection.$sliceSelectedTextNodeContent(selection$1, clone) : clone;
const children = lexical.$isElementNode(clone) ? clone.getChildren() : [];
const serializedNode = exportNodeToJSON(clone); // TODO: TextNode calls getTextContent() (NOT node.__text) within it's exportJSON method
let target = currentNode;
if (selection$1 !== null) {
let clone = selection.$cloneWithProperties(currentNode);
clone = lexical.$isTextNode(clone) && selection$1 != null ? selection.$sliceSelectedTextNodeContent(selection$1, clone) : clone;
target = clone;
}
const children = lexical.$isElementNode(target) ? target.getChildren() : [];
const serializedNode = exportNodeToJSON(target); // TODO: TextNode calls getTextContent() (NOT node.__text) within it's exportJSON method
// which uses getLatest() to get the text from the original node with the same key.

@@ -326,4 +331,4 @@ // This is a deeper issue with the word "clone" here, it's still a reference to the

if (lexical.$isTextNode(clone)) {
serializedNode.text = clone.__text;
if (lexical.$isTextNode(target)) {
serializedNode.text = target.__text;
}

@@ -384,2 +389,4 @@

exports.$generateJSONFromSelectedNodes = $generateJSONFromSelectedNodes;
exports.$generateNodesFromSerializedNodes = $generateNodesFromSerializedNodes;
exports.$getHtmlContent = $getHtmlContent;

@@ -389,1 +396,2 @@ exports.$getLexicalContent = $getLexicalContent;

exports.$insertDataTransferForRichText = $insertDataTransferForRichText;
exports.$insertGeneratedNodes = $insertGeneratedNodes;

@@ -7,13 +7,14 @@ /**

*/
'use strict';var d=require("@lexical/html"),p=require("@lexical/list"),r=require("@lexical/selection"),y=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,c,e){(z.$isGridSelection(e)||null!==y.$findMatchingParent(e.anchor.getNode(),g=>z.$isGridCellNode(g))&&null!==y.$findMatchingParent(e.focus.getNode(),g=>z.$isGridCellNode(g)))&&1===c.length&&z.$isGridNode(c[0])?E(c,e,!1,a):F(c,e)}
function F(a,c){let e=[],g=null,f=null;for(let h=0;h<a.length;h++){let b=a[h];p.$isListItemNode(b)?(null==f&&(f=p.$createListNode("bullet"),e.push(f)),f.append(b)):(null!=f&&(f=null),z.$isDecoratorNode(b)&&!b.isTopLevel()||z.$isElementNode(b)&&b.isInline()||z.$isTextNode(b)||z.$isLineBreakNode(b)?(null===g&&(g=z.$createParagraphNode(),e.push(g)),null!==g&&g.append(b)):(e.push(b),g=null))}z.$isRangeSelection(c)?c.insertNodes(e):z.$isGridSelection(c)&&(a=c.anchor.getNode(),z.$isGridCellNode(a)||A(41),
a.append(...e))}
function E(a,c,e,g){1===a.length&&z.$isGridNode(a[0])||A(42);var f=a[0];a=f.getChildren();e=f.getFirstChildOrThrow().getChildrenSize();var h=f.getChildrenSize(),b=y.$findMatchingParent(c.anchor.getNode(),m=>z.$isGridCellNode(m));c=(f=b&&y.$findMatchingParent(b,m=>z.$isGridRowNode(m)))&&y.$findMatchingParent(f,m=>z.$isGridNode(m));z.$isGridCellNode(b)&&z.$isGridRowNode(f)&&z.$isGridNode(c)||A(43);var k=f.getIndexWithinParent(),n=Math.min(c.getChildrenSize()-1,k+h-1);h=b.getIndexWithinParent();b=Math.min(f.getChildrenSize()-
1,h+e-1);e=Math.min(h,b);f=Math.min(k,n);h=Math.max(h,b);k=Math.max(k,n);n=c.getChildren();b=0;let l,q;for(let m=f;m<=k;m++){var w=n[m];z.$isGridRowNode(w)||A(24);var x=a[b];z.$isGridRowNode(x)||A(24);w=w.getChildren();x=x.getChildren();let C=0;for(let t=e;t<=h;t++){let u=w[t];z.$isGridCellNode(u)||A(25);let D=x[C];z.$isGridCellNode(D)||A(25);m===f&&t===e?l=u.getKey():m===k&&t===h&&(q=u.getKey());let H=u.getChildren();D.getChildren().forEach(v=>{z.$isTextNode(v)&&z.$createParagraphNode().append(v);
u.append(v)});H.forEach(v=>v.remove());C++}b++}l&&q&&(a=z.$createGridSelection(),a.set(c.getKey(),l,q),z.$setSelection(a),g.dispatchCommand(z.SELECTION_CHANGE_COMMAND,void 0))}
function G(a,c,e,g=[]){let f=null!=c?e.isSelected():!0,h=z.$isElementNode(e)&&e.excludeFromCopy("html");var b=r.$cloneWithProperties(e);b=z.$isTextNode(b)&&null!=c?r.$sliceSelectedTextNodeContent(c,b):b;let k=z.$isElementNode(b)?b.getChildren():[];var n=b;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(b)&&(l.text=b.__text);for(b=0;b<k.length;b++)n=k[b],q=G(a,c,n,l.children),!f&&z.$isElementNode(e)&&q&&e.extractWithChild(n,
c,"clone")&&(f=!0);if(f&&!h)g.push(l);else if(Array.isArray(l.children))for(a=0;a<l.children.length;a++)g.push(l.children[a]);return f}exports.$getHtmlContent=function(a){let c=z.$getSelection();if(null==c)throw Error("Expected valid LexicalSelection");return z.$isRangeSelection(c)&&c.isCollapsed()||0===c.getNodes().length?null:d.$generateHtmlFromNodes(a,c)};
exports.$getLexicalContent=function(a){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,g=e.stringify;let f=[],h=z.$getRoot().getChildren();for(let b=0;b<h.length;b++)G(a,c,h[b],f);return g.call(e,{namespace:a._config.namespace,nodes:f})};exports.$insertDataTransferForPlainText=function(a,c){a=a.getData("text/plain");null!=a&&c.insertRawText(a)};
exports.$insertDataTransferForRichText=function(a,c,e){var g=a.getData("application/x-lexical-editor");if(g)try{var f=JSON.parse(g);if(f.namespace===e._config.namespace&&Array.isArray(f.nodes)){var h=f.nodes;g=[];for(f=0;f<h.length;f++){let k=z.$parseSerializedNode(h[f]);z.$isTextNode(k)&&r.$addNodeStyle(k);g.push(k)}return B(e,g,c)}}catch{}if(h=a.getData("text/html"))try{var b=(new DOMParser).parseFromString(h,"text/html");let k=d.$generateNodesFromDOM(e,b);return B(e,k,c)}catch{}a=a.getData("text/plain");
if(null!=a)if(z.$isRangeSelection(c))for(a=a.split(/\r?\n/),e=a.length,b=0;b<e;b++)c.insertText(a[b]),b<e-1&&c.insertParagraph();else c.insertRawText(a)}
'use strict';var c=require("@lexical/html"),n=require("@lexical/list"),r=require("@lexical/selection"),y=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,b,d){(z.DEPRECATED_$isGridSelection(d)||null!==y.$findMatchingParent(d.anchor.getNode(),g=>z.DEPRECATED_$isGridCellNode(g))&&null!==y.$findMatchingParent(d.focus.getNode(),g=>z.DEPRECATED_$isGridCellNode(g)))&&1===b.length&&z.DEPRECATED_$isGridNode(b[0])?E(b,d,!1,a):F(b,d)}
function F(a,b){let d=[],g=null,e=null;for(let h=0;h<a.length;h++){let f=a[h];n.$isListItemNode(f)?(null==e&&(e=n.$createListNode("bullet"),d.push(e)),e.append(f)):(null!=e&&(e=null),z.$isDecoratorNode(f)&&f.isInline()||z.$isElementNode(f)&&f.isInline()||z.$isTextNode(f)||z.$isLineBreakNode(f)?(null===g&&(g=z.$createParagraphNode(),d.push(g)),null!==g&&g.append(f)):(d.push(f),g=null))}z.$isRangeSelection(b)?b.insertNodes(d):z.DEPRECATED_$isGridSelection(b)&&(a=b.anchor.getNode(),z.DEPRECATED_$isGridCellNode(a)||
A(41),a.append(...d))}
function E(a,b,d,g){1===a.length&&z.DEPRECATED_$isGridNode(a[0])||A(42);var e=a[0];a=e.getChildren();d=e.getFirstChildOrThrow().getChildrenSize();var h=e.getChildrenSize(),f=y.$findMatchingParent(b.anchor.getNode(),l=>z.DEPRECATED_$isGridCellNode(l));b=(e=f&&y.$findMatchingParent(f,l=>z.DEPRECATED_$isGridRowNode(l)))&&y.$findMatchingParent(e,l=>z.DEPRECATED_$isGridNode(l));z.DEPRECATED_$isGridCellNode(f)&&z.DEPRECATED_$isGridRowNode(e)&&z.DEPRECATED_$isGridNode(b)||A(43);var k=e.getIndexWithinParent(),
p=Math.min(b.getChildrenSize()-1,k+h-1);h=f.getIndexWithinParent();f=Math.min(e.getChildrenSize()-1,h+d-1);d=Math.min(h,f);e=Math.min(k,p);h=Math.max(h,f);k=Math.max(k,p);p=b.getChildren();f=0;let m,q;for(let l=e;l<=k;l++){var w=p[l];z.DEPRECATED_$isGridRowNode(w)||A(24);var x=a[f];z.DEPRECATED_$isGridRowNode(x)||A(24);w=w.getChildren();x=x.getChildren();let C=0;for(let t=d;t<=h;t++){let u=w[t];z.DEPRECATED_$isGridCellNode(u)||A(25);let D=x[C];z.DEPRECATED_$isGridCellNode(D)||A(25);l===e&&t===d?m=
u.getKey():l===k&&t===h&&(q=u.getKey());let J=u.getChildren();D.getChildren().forEach(v=>{z.$isTextNode(v)&&z.$createParagraphNode().append(v);u.append(v)});J.forEach(v=>v.remove());C++}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 G(a,b,d,g=[]){let e=null!=b?d.isSelected():!0,h=z.$isElementNode(d)&&d.excludeFromCopy("html");var f=d;if(null!==b){var k=r.$cloneWithProperties(d);f=k=z.$isTextNode(k)&&null!=b?r.$sliceSelectedTextNodeContent(b,k):k}let p=z.$isElementNode(f)?f.getChildren():[];var m=f;k=m.exportJSON();k.type!==m.constructor.getType()&&A(58);var q=k.children;z.$isElementNode(m)&&(Array.isArray(q)||A(59));z.$isTextNode(f)&&(k.text=f.__text);for(f=0;f<p.length;f++)m=p[f],q=G(a,b,m,k.children),!e&&z.$isElementNode(d)&&
q&&d.extractWithChild(m,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 H(a,b){let d=[],g=z.$getRoot().getChildren();for(let e=0;e<g.length;e++)G(a,b,g[e],d);return{namespace:a._config.namespace,nodes:d}}function I(a){let b=[];for(let d=0;d<a.length;d++){let g=z.$parseSerializedNode(a[d]);z.$isTextNode(g)&&r.$addNodeStyle(g);b.push(g)}return b}exports.$generateJSONFromSelectedNodes=H;
exports.$generateNodesFromSerializedNodes=I;exports.$getHtmlContent=function(a){let b=z.$getSelection();if(null==b)throw Error("Expected valid LexicalSelection");return z.$isRangeSelection(b)&&b.isCollapsed()||0===b.getNodes().length?null:c.$generateHtmlFromNodes(a,b)};exports.$getLexicalContent=function(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(H(a,b))};
exports.$insertDataTransferForPlainText=function(a,b){a=a.getData("text/plain");null!=a&&b.insertRawText(a)};
exports.$insertDataTransferForRichText=function(a,b,d){var g=a.getData("application/x-lexical-editor");if(g)try{let h=JSON.parse(g);if(h.namespace===d._config.namespace&&Array.isArray(h.nodes)){let f=I(h.nodes);return B(d,f,b)}}catch{}if(g=a.getData("text/html"))try{var e=(new DOMParser).parseFromString(g,"text/html");let h=c.$generateNodesFromDOM(d,e);return B(d,h,b)}catch{}a=a.getData("text/plain");if(null!=a)if(z.$isRangeSelection(b))for(a=a.split(/\r?\n/),d=a.length,e=0;e<d;e++)b.insertText(a[e]),
e<d-1&&b.insertParagraph();else b.insertRawText(a)};exports.$insertGeneratedNodes=B

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

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

@@ -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