@lexical/clipboard 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.
@@ -53,7 +53,7 @@ function $getLexicalContent(editor) {
53
53
  return JSON.stringify($generateJSONFromSelectedNodes(editor, selection));
54
54
  }
55
55
  function $insertDataTransferForPlainText(dataTransfer, selection) {
56
- const text = dataTransfer.getData('text/plain');
56
+ const text = dataTransfer.getData('text/plain') || dataTransfer.getData('text/uri-list');
57
57
 
58
58
  if (text != null) {
59
59
  selection.insertRawText(text);
@@ -86,20 +86,25 @@ function $insertDataTransferForRichText(dataTransfer, selection, editor) {
86
86
  }
87
87
  } // Multi-line plain text in rich text mode pasted as separate paragraphs
88
88
  // instead of single paragraph with linebreaks.
89
+ // Webkit-specific: Supports read 'text/uri-list' in clipboard.
89
90
 
90
91
 
91
- const text = dataTransfer.getData('text/plain');
92
+ const text = dataTransfer.getData('text/plain') || dataTransfer.getData('text/uri-list');
92
93
 
93
94
  if (text != null) {
94
95
  if (lexical.$isRangeSelection(selection)) {
95
- const lines = text.split(/\r?\n/);
96
- const linesLength = lines.length;
96
+ const parts = text.split(/(\r?\n|\t)/);
97
+ const partsLength = parts.length;
97
98
 
98
- for (let i = 0; i < linesLength; i++) {
99
- selection.insertText(lines[i]);
99
+ for (let i = 0; i < partsLength; i++) {
100
+ const part = parts[i];
100
101
 
101
- if (i < linesLength - 1) {
102
+ if (part === '\n' || part === '\r\n') {
102
103
  selection.insertParagraph();
104
+ } else if (part === '\t') {
105
+ selection.insertNodes([lexical.$createTabNode()]);
106
+ } else {
107
+ selection.insertText(part);
103
108
  }
104
109
  }
105
110
  } else {
@@ -7,15 +7,15 @@
7
7
  '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.");}
8
8
  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))}
9
9
  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)}
10
- 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))}
11
- 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(),
12
- 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=
13
- 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))}
14
- 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),
15
- !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;
10
+ function H(a,b){let c=[],f=null;for(let e=0;e<a.length;e++){let h=a[e],g=t.$isLineBreakNode(h);if(g||t.$isDecoratorNode(h)&&h.isInline()||t.$isElementNode(h)&&h.isInline()||t.$isTextNode(h)||h.isParentRequired()){if(null===f&&(f=h.createParentElementNode(),c.push(f),g))continue;null!==f&&f.append(h)}else c.push(h),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))}
11
+ 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 h=e.getChildrenSize(),g=r.$findMatchingParent(b.anchor.getNode(),l=>t.DEPRECATED_$isGridCellNode(l));b=(e=g&&r.$findMatchingParent(g,l=>t.DEPRECATED_$isGridRowNode(l)))&&r.$findMatchingParent(e,l=>t.DEPRECATED_$isGridNode(l));t.DEPRECATED_$isGridCellNode(g)&&t.DEPRECATED_$isGridRowNode(e)&&t.DEPRECATED_$isGridNode(b)||z(43);var k=e.getIndexWithinParent(),
12
+ p=Math.min(b.getChildrenSize()-1,k+h-1);h=g.getIndexWithinParent();g=Math.min(e.getChildrenSize()-1,h+c-1);c=Math.min(h,g);e=Math.min(k,p);h=Math.max(h,g);k=Math.max(k,p);p=b.getChildren();g=0;let m,q;for(let l=e;l<=k;l++){var x=p[l];t.DEPRECATED_$isGridRowNode(x)||z(24);var y=a[g];t.DEPRECATED_$isGridRowNode(y)||z(24);x=x.getChildren();y=y.getChildren();let F=0;for(let u=c;u<=h;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=
13
+ v.getKey():l===k&&u===h&&(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++}g++}m&&q&&(a=t.DEPRECATED_$createGridSelection(),a.set(b.getKey(),m,q),t.$setSelection(a),f.dispatchCommand(t.SELECTION_CHANGE_COMMAND,void 0))}
14
+ function I(a,b,c,f=[]){let e=null!=b?c.isSelected(b):!0,h=t.$isElementNode(c)&&c.excludeFromCopy("html");var g=c;if(null!==b){var k=n.$cloneWithProperties(c);g=k=t.$isTextNode(k)&&null!=b?n.$sliceSelectedTextNodeContent(b,k):k}let p=t.$isElementNode(g)?g.getChildren():[];var m=g;k=m.exportJSON();k.type!==m.constructor.getType()&&z(58);var q=k.children;t.$isElementNode(m)&&(Array.isArray(q)||z(59));t.$isTextNode(g)&&(g=g.__text,0<g.length?k.text=g:e=!1);for(g=0;g<p.length;g++)m=p[g],q=I(a,b,m,k.children),
15
+ !e&&t.$isElementNode(c)&&q&&c.extractWithChild(m,b,"clone")&&(e=!0);if(e&&!h)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;
16
16
  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;
17
- exports.$generateNodesFromSerializedNodes=J;exports.$getHtmlContent=A;exports.$getLexicalContent=B;exports.$insertDataTransferForPlainText=function(a,b){a=a.getData("text/plain");null!=a&&b.insertRawText(a)};
18
- 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]),
19
- e<c-1&&b.insertParagraph();else b.insertRawText(a)};exports.$insertGeneratedNodes=D;
20
- exports.copyToClipboard=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
21
- 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()})}
17
+ exports.$generateNodesFromSerializedNodes=J;exports.$getHtmlContent=A;exports.$getLexicalContent=B;exports.$insertDataTransferForPlainText=function(a,b){a=a.getData("text/plain")||a.getData("text/uri-list");null!=a&&b.insertRawText(a)};
18
+ 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 k=J(g.nodes);return D(c,k,b)}}catch{}if(f=a.getData("text/html"))try{var e=(new DOMParser).parseFromString(f,"text/html"),h=d.$generateNodesFromDOM(c,e);return D(c,h,b)}catch{}a=a.getData("text/plain")||a.getData("text/uri-list");if(null!=a)if(t.$isRangeSelection(b))for(a=a.split(/(\r?\n|\t)/),c=a.length,
19
+ e=0;e<c;e++)h=a[e],"\n"===h||"\r\n"===h?b.insertParagraph():"\t"===h?b.insertNodes([t.$createTabNode()]):b.insertText(h);else b.insertRawText(a)};exports.$insertGeneratedNodes=D;
20
+ exports.copyToClipboard=async function(a,b){if(null!==K)return!1;if(null!==b)return new Promise(h=>{a.update(()=>{h(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(h=>{let g=a.registerCommand(t.COPY_COMMAND,k=>{k instanceof
21
+ ClipboardEvent&&(g(),null!==K&&(window.clearTimeout(K),K=null),h(L(a,k)));return!0},t.COMMAND_PRIORITY_CRITICAL);K=window.setTimeout(()=>{g();K=null;h(!1)},50);document.execCommand("copy");e.remove()})}
package/package.json CHANGED
@@ -9,16 +9,16 @@
9
9
  "paste"
10
10
  ],
11
11
  "license": "MIT",
12
- "version": "0.9.2",
12
+ "version": "0.11.0",
13
13
  "main": "LexicalClipboard.js",
14
14
  "peerDependencies": {
15
- "lexical": "0.9.2"
15
+ "lexical": "0.11.0"
16
16
  },
17
17
  "dependencies": {
18
- "@lexical/utils": "0.9.2",
19
- "@lexical/list": "0.9.2",
20
- "@lexical/selection": "0.9.2",
21
- "@lexical/html": "0.9.2"
18
+ "@lexical/utils": "0.11.0",
19
+ "@lexical/list": "0.11.0",
20
+ "@lexical/selection": "0.11.0",
21
+ "@lexical/html": "0.11.0"
22
22
  },
23
23
  "repository": {
24
24
  "type": "git",