@lexical/clipboard 0.10.0 → 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.
- package/LexicalClipboard.dev.js +12 -7
- package/LexicalClipboard.prod.js +11 -11
- package/package.json +6 -6
package/LexicalClipboard.dev.js
CHANGED
|
@@ -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
|
|
96
|
-
const
|
|
96
|
+
const parts = text.split(/(\r?\n|\t)/);
|
|
97
|
+
const partsLength = parts.length;
|
|
97
98
|
|
|
98
|
-
for (let i = 0; i <
|
|
99
|
-
|
|
99
|
+
for (let i = 0; i < partsLength; i++) {
|
|
100
|
+
const part = parts[i];
|
|
100
101
|
|
|
101
|
-
if (
|
|
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 {
|
package/LexicalClipboard.prod.js
CHANGED
|
@@ -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
|
|
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
|
|
12
|
-
p=Math.min(b.getChildrenSize()-1,k+
|
|
13
|
-
v.getKey():l===k&&u===
|
|
14
|
-
function I(a,b,c,f=[]){let e=null!=b?c.isSelected(b):!0,
|
|
15
|
-
!e&&t.$isElementNode(c)&&q&&c.extractWithChild(m,b,"clone")&&(e=!0);if(e&&!
|
|
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
|
|
19
|
-
e<c
|
|
20
|
-
exports.copyToClipboard=async function(a,b){if(null!==K)return!1;if(null!==b)return new Promise(
|
|
21
|
-
ClipboardEvent&&(
|
|
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.
|
|
12
|
+
"version": "0.11.0",
|
|
13
13
|
"main": "LexicalClipboard.js",
|
|
14
14
|
"peerDependencies": {
|
|
15
|
-
"lexical": "0.
|
|
15
|
+
"lexical": "0.11.0"
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@lexical/utils": "0.
|
|
19
|
-
"@lexical/list": "0.
|
|
20
|
-
"@lexical/selection": "0.
|
|
21
|
-
"@lexical/html": "0.
|
|
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",
|