@lexical/clipboard 0.12.5 → 0.13.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 +8 -100
- package/LexicalClipboard.js.flow +2 -4
- package/LexicalClipboard.prod.js +11 -15
- package/package.json +6 -6
package/LexicalClipboard.dev.js
CHANGED
|
@@ -164,116 +164,24 @@ function $insertDataTransferForRichText(dataTransfer, selection, editor) {
|
|
|
164
164
|
* @param selection The selection to insert the nodes into.
|
|
165
165
|
*/
|
|
166
166
|
function $insertGeneratedNodes(editor, nodes, selection) {
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
return;
|
|
167
|
+
if (!editor.dispatchCommand(lexical.SELECTION_INSERT_CLIPBOARD_NODES_COMMAND, {
|
|
168
|
+
nodes,
|
|
169
|
+
selection
|
|
170
|
+
})) {
|
|
171
|
+
selection.insertNodes(nodes);
|
|
173
172
|
}
|
|
174
|
-
selection.insertNodes(nodes);
|
|
175
173
|
return;
|
|
176
174
|
}
|
|
177
|
-
function $mergeGridNodesStrategy(nodes, selection, isFromLexical, editor) {
|
|
178
|
-
if (nodes.length !== 1 || !lexical.DEPRECATED_$isGridNode(nodes[0])) {
|
|
179
|
-
{
|
|
180
|
-
throw Error(`$mergeGridNodesStrategy: Expected Grid insertion.`);
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
const newGrid = nodes[0];
|
|
184
|
-
const newGridRows = newGrid.getChildren();
|
|
185
|
-
const newColumnCount = newGrid.getFirstChildOrThrow().getChildrenSize();
|
|
186
|
-
const newRowCount = newGrid.getChildrenSize();
|
|
187
|
-
const gridCellNode = utils.$findMatchingParent(selection.anchor.getNode(), n => lexical.DEPRECATED_$isGridCellNode(n));
|
|
188
|
-
const gridRowNode = gridCellNode && utils.$findMatchingParent(gridCellNode, n => lexical.DEPRECATED_$isGridRowNode(n));
|
|
189
|
-
const gridNode = gridRowNode && utils.$findMatchingParent(gridRowNode, n => lexical.DEPRECATED_$isGridNode(n));
|
|
190
|
-
if (!lexical.DEPRECATED_$isGridCellNode(gridCellNode) || !lexical.DEPRECATED_$isGridRowNode(gridRowNode) || !lexical.DEPRECATED_$isGridNode(gridNode)) {
|
|
191
|
-
{
|
|
192
|
-
throw Error(`$mergeGridNodesStrategy: Expected selection to be inside of a Grid.`);
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
const startY = gridRowNode.getIndexWithinParent();
|
|
196
|
-
const stopY = Math.min(gridNode.getChildrenSize() - 1, startY + newRowCount - 1);
|
|
197
|
-
const startX = gridCellNode.getIndexWithinParent();
|
|
198
|
-
const stopX = Math.min(gridRowNode.getChildrenSize() - 1, startX + newColumnCount - 1);
|
|
199
|
-
const fromX = Math.min(startX, stopX);
|
|
200
|
-
const fromY = Math.min(startY, stopY);
|
|
201
|
-
const toX = Math.max(startX, stopX);
|
|
202
|
-
const toY = Math.max(startY, stopY);
|
|
203
|
-
const gridRowNodes = gridNode.getChildren();
|
|
204
|
-
let newRowIdx = 0;
|
|
205
|
-
let newAnchorCellKey;
|
|
206
|
-
let newFocusCellKey;
|
|
207
|
-
for (let r = fromY; r <= toY; r++) {
|
|
208
|
-
const currentGridRowNode = gridRowNodes[r];
|
|
209
|
-
if (!lexical.DEPRECATED_$isGridRowNode(currentGridRowNode)) {
|
|
210
|
-
{
|
|
211
|
-
throw Error(`getNodes: expected to find GridRowNode`);
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
const newGridRowNode = newGridRows[newRowIdx];
|
|
215
|
-
if (!lexical.DEPRECATED_$isGridRowNode(newGridRowNode)) {
|
|
216
|
-
{
|
|
217
|
-
throw Error(`getNodes: expected to find GridRowNode`);
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
const gridCellNodes = currentGridRowNode.getChildren();
|
|
221
|
-
const newGridCellNodes = newGridRowNode.getChildren();
|
|
222
|
-
let newColumnIdx = 0;
|
|
223
|
-
for (let c = fromX; c <= toX; c++) {
|
|
224
|
-
const currentGridCellNode = gridCellNodes[c];
|
|
225
|
-
if (!lexical.DEPRECATED_$isGridCellNode(currentGridCellNode)) {
|
|
226
|
-
{
|
|
227
|
-
throw Error(`getNodes: expected to find GridCellNode`);
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
const newGridCellNode = newGridCellNodes[newColumnIdx];
|
|
231
|
-
if (!lexical.DEPRECATED_$isGridCellNode(newGridCellNode)) {
|
|
232
|
-
{
|
|
233
|
-
throw Error(`getNodes: expected to find GridCellNode`);
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
if (r === fromY && c === fromX) {
|
|
237
|
-
newAnchorCellKey = currentGridCellNode.getKey();
|
|
238
|
-
} else if (r === toY && c === toX) {
|
|
239
|
-
newFocusCellKey = currentGridCellNode.getKey();
|
|
240
|
-
}
|
|
241
|
-
const originalChildren = currentGridCellNode.getChildren();
|
|
242
|
-
newGridCellNode.getChildren().forEach(child => {
|
|
243
|
-
if (lexical.$isTextNode(child)) {
|
|
244
|
-
const paragraphNode = lexical.$createParagraphNode();
|
|
245
|
-
paragraphNode.append(child);
|
|
246
|
-
currentGridCellNode.append(child);
|
|
247
|
-
} else {
|
|
248
|
-
currentGridCellNode.append(child);
|
|
249
|
-
}
|
|
250
|
-
});
|
|
251
|
-
originalChildren.forEach(n => n.remove());
|
|
252
|
-
newColumnIdx++;
|
|
253
|
-
}
|
|
254
|
-
newRowIdx++;
|
|
255
|
-
}
|
|
256
|
-
if (newAnchorCellKey && newFocusCellKey) {
|
|
257
|
-
const newGridSelection = lexical.DEPRECATED_$createGridSelection();
|
|
258
|
-
newGridSelection.set(gridNode.getKey(), newAnchorCellKey, newFocusCellKey);
|
|
259
|
-
lexical.$setSelection(newGridSelection);
|
|
260
|
-
editor.dispatchCommand(lexical.SELECTION_CHANGE_COMMAND, undefined);
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
175
|
function exportNodeToJSON(node) {
|
|
264
176
|
const serializedNode = node.exportJSON();
|
|
265
177
|
const nodeClass = node.constructor;
|
|
266
|
-
|
|
267
|
-
// @ts-expect-error TODO Replace Class utility type with InstanceType
|
|
268
178
|
if (serializedNode.type !== nodeClass.getType()) {
|
|
269
179
|
{
|
|
270
180
|
throw Error(`LexicalNode: Node ${nodeClass.name} does not implement .exportJSON().`);
|
|
271
181
|
}
|
|
272
182
|
}
|
|
273
|
-
|
|
274
|
-
// @ts-expect-error TODO Replace Class utility type with InstanceType
|
|
275
|
-
const serializedChildren = serializedNode.children;
|
|
276
183
|
if (lexical.$isElementNode(node)) {
|
|
184
|
+
const serializedChildren = serializedNode.children;
|
|
277
185
|
if (!Array.isArray(serializedChildren)) {
|
|
278
186
|
{
|
|
279
187
|
throw Error(`LexicalNode: Node ${nodeClass.name} is an element but .exportJSON() does not have a children array.`);
|
|
@@ -283,12 +191,12 @@ function exportNodeToJSON(node) {
|
|
|
283
191
|
return serializedNode;
|
|
284
192
|
}
|
|
285
193
|
function $appendNodesToJSON(editor, selection$1, currentNode, targetArray = []) {
|
|
286
|
-
let shouldInclude = selection$1
|
|
194
|
+
let shouldInclude = selection$1 !== null ? currentNode.isSelected(selection$1) : true;
|
|
287
195
|
const shouldExclude = lexical.$isElementNode(currentNode) && currentNode.excludeFromCopy('html');
|
|
288
196
|
let target = currentNode;
|
|
289
197
|
if (selection$1 !== null) {
|
|
290
198
|
let clone = selection.$cloneWithProperties(currentNode);
|
|
291
|
-
clone = lexical.$isTextNode(clone) && selection$1
|
|
199
|
+
clone = lexical.$isTextNode(clone) && selection$1 !== null ? selection.$sliceSelectedTextNodeContent(selection$1, clone) : clone;
|
|
292
200
|
target = clone;
|
|
293
201
|
}
|
|
294
202
|
const children = lexical.$isElementNode(target) ? target.getChildren() : [];
|
package/LexicalClipboard.js.flow
CHANGED
|
@@ -10,8 +10,6 @@
|
|
|
10
10
|
import type {
|
|
11
11
|
BaseSelection,
|
|
12
12
|
LexicalEditor,
|
|
13
|
-
INTERNAL_PointSelection,
|
|
14
|
-
GridSelection,
|
|
15
13
|
RangeSelection,
|
|
16
14
|
LexicalNode,
|
|
17
15
|
} from 'lexical';
|
|
@@ -22,7 +20,7 @@ import type {
|
|
|
22
20
|
|
|
23
21
|
declare export function $insertDataTransferForRichText(
|
|
24
22
|
dataTransfer: DataTransfer,
|
|
25
|
-
selection:
|
|
23
|
+
selection: BaseSelection,
|
|
26
24
|
editor: LexicalEditor,
|
|
27
25
|
): void;
|
|
28
26
|
|
|
@@ -34,7 +32,7 @@ declare export function $getLexicalContent(
|
|
|
34
32
|
declare export function $insertGeneratedNodes(
|
|
35
33
|
editor: LexicalEditor,
|
|
36
34
|
nodes: Array<LexicalNode>,
|
|
37
|
-
selection:
|
|
35
|
+
selection: BaseSelection,
|
|
38
36
|
): void;
|
|
39
37
|
/*
|
|
40
38
|
* Plain Text
|
package/LexicalClipboard.prod.js
CHANGED
|
@@ -4,18 +4,14 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
'use strict';var
|
|
8
|
-
let
|
|
9
|
-
function
|
|
10
|
-
function
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
function
|
|
15
|
-
|
|
16
|
-
function
|
|
17
|
-
|
|
18
|
-
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)/),
|
|
19
|
-
""===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;
|
|
20
|
-
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=>
|
|
21
|
-
{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()})}
|
|
7
|
+
'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.");}
|
|
8
|
+
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)}
|
|
9
|
+
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)}
|
|
10
|
+
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],
|
|
11
|
+
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;
|
|
12
|
+
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;
|
|
13
|
+
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)};
|
|
14
|
+
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)/),
|
|
15
|
+
""===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;
|
|
16
|
+
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=>
|
|
17
|
+
{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()})}
|
package/package.json
CHANGED
|
@@ -9,16 +9,16 @@
|
|
|
9
9
|
"paste"
|
|
10
10
|
],
|
|
11
11
|
"license": "MIT",
|
|
12
|
-
"version": "0.
|
|
12
|
+
"version": "0.13.0",
|
|
13
13
|
"main": "LexicalClipboard.js",
|
|
14
14
|
"peerDependencies": {
|
|
15
|
-
"lexical": "0.
|
|
15
|
+
"lexical": "0.13.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.13.0",
|
|
19
|
+
"@lexical/list": "0.13.0",
|
|
20
|
+
"@lexical/selection": "0.13.0",
|
|
21
|
+
"@lexical/html": "0.13.0"
|
|
22
22
|
},
|
|
23
23
|
"repository": {
|
|
24
24
|
"type": "git",
|