@lexical/clipboard 0.4.0 → 0.5.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 +30 -22
- package/LexicalClipboard.prod.js +13 -12
- package/clipboard.d.ts +2 -2
- package/index.d.ts +2 -2
- package/package.json +6 -6
package/LexicalClipboard.dev.js
CHANGED
|
@@ -101,11 +101,10 @@ function $insertDataTransferForRichText(dataTransfer, selection, editor) {
|
|
|
101
101
|
}
|
|
102
102
|
}
|
|
103
103
|
}
|
|
104
|
-
|
|
105
104
|
function $insertGeneratedNodes(editor, nodes, selection) {
|
|
106
|
-
const isSelectionInsideOfGrid = lexical
|
|
105
|
+
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;
|
|
107
106
|
|
|
108
|
-
if (isSelectionInsideOfGrid && nodes.length === 1 && lexical
|
|
107
|
+
if (isSelectionInsideOfGrid && nodes.length === 1 && lexical.DEPRECATED_$isGridNode(nodes[0])) {
|
|
109
108
|
$mergeGridNodesStrategy(nodes, selection, false, editor);
|
|
110
109
|
return;
|
|
111
110
|
}
|
|
@@ -141,7 +140,7 @@ function $basicInsertStrategy(nodes, selection) {
|
|
|
141
140
|
list$1 = null;
|
|
142
141
|
}
|
|
143
142
|
|
|
144
|
-
if (lexical.$isDecoratorNode(node) &&
|
|
143
|
+
if (lexical.$isDecoratorNode(node) && node.isInline() || lexical.$isElementNode(node) && node.isInline() || lexical.$isTextNode(node) || lexical.$isLineBreakNode(node)) {
|
|
145
144
|
if (currentBlock === null) {
|
|
146
145
|
currentBlock = lexical.$createParagraphNode();
|
|
147
146
|
topLevelBlocks.push(currentBlock);
|
|
@@ -158,11 +157,11 @@ function $basicInsertStrategy(nodes, selection) {
|
|
|
158
157
|
|
|
159
158
|
if (lexical.$isRangeSelection(selection)) {
|
|
160
159
|
selection.insertNodes(topLevelBlocks);
|
|
161
|
-
} else if (lexical
|
|
160
|
+
} else if (lexical.DEPRECATED_$isGridSelection(selection)) {
|
|
162
161
|
// If there's an active grid selection and a non grid is pasted, add to the anchor.
|
|
163
162
|
const anchorCell = selection.anchor.getNode();
|
|
164
163
|
|
|
165
|
-
if (!lexical
|
|
164
|
+
if (!lexical.DEPRECATED_$isGridCellNode(anchorCell)) {
|
|
166
165
|
{
|
|
167
166
|
throw Error(`Expected Grid Cell in Grid Selection`);
|
|
168
167
|
}
|
|
@@ -173,7 +172,7 @@ function $basicInsertStrategy(nodes, selection) {
|
|
|
173
172
|
}
|
|
174
173
|
|
|
175
174
|
function $mergeGridNodesStrategy(nodes, selection, isFromLexical, editor) {
|
|
176
|
-
if (nodes.length !== 1 || !lexical
|
|
175
|
+
if (nodes.length !== 1 || !lexical.DEPRECATED_$isGridNode(nodes[0])) {
|
|
177
176
|
{
|
|
178
177
|
throw Error(`$mergeGridNodesStrategy: Expected Grid insertion.`);
|
|
179
178
|
}
|
|
@@ -183,11 +182,11 @@ function $mergeGridNodesStrategy(nodes, selection, isFromLexical, editor) {
|
|
|
183
182
|
const newGridRows = newGrid.getChildren();
|
|
184
183
|
const newColumnCount = newGrid.getFirstChildOrThrow().getChildrenSize();
|
|
185
184
|
const newRowCount = newGrid.getChildrenSize();
|
|
186
|
-
const gridCellNode = utils.$findMatchingParent(selection.anchor.getNode(), n => lexical
|
|
187
|
-
const gridRowNode = gridCellNode && utils.$findMatchingParent(gridCellNode, n => lexical
|
|
188
|
-
const gridNode = gridRowNode && utils.$findMatchingParent(gridRowNode, n => lexical
|
|
185
|
+
const gridCellNode = utils.$findMatchingParent(selection.anchor.getNode(), n => lexical.DEPRECATED_$isGridCellNode(n));
|
|
186
|
+
const gridRowNode = gridCellNode && utils.$findMatchingParent(gridCellNode, n => lexical.DEPRECATED_$isGridRowNode(n));
|
|
187
|
+
const gridNode = gridRowNode && utils.$findMatchingParent(gridRowNode, n => lexical.DEPRECATED_$isGridNode(n));
|
|
189
188
|
|
|
190
|
-
if (!lexical
|
|
189
|
+
if (!lexical.DEPRECATED_$isGridCellNode(gridCellNode) || !lexical.DEPRECATED_$isGridRowNode(gridRowNode) || !lexical.DEPRECATED_$isGridNode(gridNode)) {
|
|
191
190
|
{
|
|
192
191
|
throw Error(`$mergeGridNodesStrategy: Expected selection to be inside of a Grid.`);
|
|
193
192
|
}
|
|
@@ -209,7 +208,7 @@ function $mergeGridNodesStrategy(nodes, selection, isFromLexical, editor) {
|
|
|
209
208
|
for (let r = fromY; r <= toY; r++) {
|
|
210
209
|
const currentGridRowNode = gridRowNodes[r];
|
|
211
210
|
|
|
212
|
-
if (!lexical
|
|
211
|
+
if (!lexical.DEPRECATED_$isGridRowNode(currentGridRowNode)) {
|
|
213
212
|
{
|
|
214
213
|
throw Error(`getNodes: expected to find GridRowNode`);
|
|
215
214
|
}
|
|
@@ -217,7 +216,7 @@ function $mergeGridNodesStrategy(nodes, selection, isFromLexical, editor) {
|
|
|
217
216
|
|
|
218
217
|
const newGridRowNode = newGridRows[newRowIdx];
|
|
219
218
|
|
|
220
|
-
if (!lexical
|
|
219
|
+
if (!lexical.DEPRECATED_$isGridRowNode(newGridRowNode)) {
|
|
221
220
|
{
|
|
222
221
|
throw Error(`getNodes: expected to find GridRowNode`);
|
|
223
222
|
}
|
|
@@ -230,7 +229,7 @@ function $mergeGridNodesStrategy(nodes, selection, isFromLexical, editor) {
|
|
|
230
229
|
for (let c = fromX; c <= toX; c++) {
|
|
231
230
|
const currentGridCellNode = gridCellNodes[c];
|
|
232
231
|
|
|
233
|
-
if (!lexical
|
|
232
|
+
if (!lexical.DEPRECATED_$isGridCellNode(currentGridCellNode)) {
|
|
234
233
|
{
|
|
235
234
|
throw Error(`getNodes: expected to find GridCellNode`);
|
|
236
235
|
}
|
|
@@ -238,7 +237,7 @@ function $mergeGridNodesStrategy(nodes, selection, isFromLexical, editor) {
|
|
|
238
237
|
|
|
239
238
|
const newGridCellNode = newGridCellNodes[newColumnIdx];
|
|
240
239
|
|
|
241
|
-
if (!lexical
|
|
240
|
+
if (!lexical.DEPRECATED_$isGridCellNode(newGridCellNode)) {
|
|
242
241
|
{
|
|
243
242
|
throw Error(`getNodes: expected to find GridCellNode`);
|
|
244
243
|
}
|
|
@@ -268,7 +267,7 @@ function $mergeGridNodesStrategy(nodes, selection, isFromLexical, editor) {
|
|
|
268
267
|
}
|
|
269
268
|
|
|
270
269
|
if (newAnchorCellKey && newFocusCellKey) {
|
|
271
|
-
const newGridSelection = lexical
|
|
270
|
+
const newGridSelection = lexical.DEPRECATED_$createGridSelection();
|
|
272
271
|
newGridSelection.set(gridNode.getKey(), newAnchorCellKey, newFocusCellKey);
|
|
273
272
|
lexical.$setSelection(newGridSelection);
|
|
274
273
|
editor.dispatchCommand(lexical.SELECTION_CHANGE_COMMAND, undefined);
|
|
@@ -302,18 +301,24 @@ function exportNodeToJSON(node) {
|
|
|
302
301
|
function $appendNodesToJSON(editor, selection$1, currentNode, targetArray = []) {
|
|
303
302
|
let shouldInclude = selection$1 != null ? currentNode.isSelected() : true;
|
|
304
303
|
const shouldExclude = lexical.$isElementNode(currentNode) && currentNode.excludeFromCopy('html');
|
|
305
|
-
let
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
304
|
+
let target = currentNode;
|
|
305
|
+
|
|
306
|
+
if (selection$1 !== null) {
|
|
307
|
+
let clone = selection.$cloneWithProperties(currentNode);
|
|
308
|
+
clone = lexical.$isTextNode(clone) && selection$1 != null ? selection.$sliceSelectedTextNodeContent(selection$1, clone) : clone;
|
|
309
|
+
target = clone;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
const children = lexical.$isElementNode(target) ? target.getChildren() : [];
|
|
313
|
+
const serializedNode = exportNodeToJSON(target); // TODO: TextNode calls getTextContent() (NOT node.__text) within it's exportJSON method
|
|
309
314
|
// which uses getLatest() to get the text from the original node with the same key.
|
|
310
315
|
// This is a deeper issue with the word "clone" here, it's still a reference to the
|
|
311
316
|
// same node as far as the LexicalEditor is concerned since it shares a key.
|
|
312
317
|
// We need a way to create a clone of a Node in memory with it's own key, but
|
|
313
318
|
// until then this hack will work for the selected text extract use case.
|
|
314
319
|
|
|
315
|
-
if (lexical.$isTextNode(
|
|
316
|
-
serializedNode.text =
|
|
320
|
+
if (lexical.$isTextNode(target)) {
|
|
321
|
+
serializedNode.text = target.__text;
|
|
317
322
|
}
|
|
318
323
|
|
|
319
324
|
for (let i = 0; i < children.length; i++) {
|
|
@@ -369,7 +374,10 @@ function $generateNodesFromSerializedNodes(serializedNodes) {
|
|
|
369
374
|
return nodes;
|
|
370
375
|
}
|
|
371
376
|
|
|
377
|
+
exports.$generateJSONFromSelectedNodes = $generateJSONFromSelectedNodes;
|
|
378
|
+
exports.$generateNodesFromSerializedNodes = $generateNodesFromSerializedNodes;
|
|
372
379
|
exports.$getHtmlContent = $getHtmlContent;
|
|
373
380
|
exports.$getLexicalContent = $getLexicalContent;
|
|
374
381
|
exports.$insertDataTransferForPlainText = $insertDataTransferForPlainText;
|
|
375
382
|
exports.$insertDataTransferForRichText = $insertDataTransferForRichText;
|
|
383
|
+
exports.$insertGeneratedNodes = $insertGeneratedNodes;
|
package/LexicalClipboard.prod.js
CHANGED
|
@@ -4,15 +4,16 @@
|
|
|
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
|
-
function B(a,
|
|
9
|
-
function F(a,
|
|
10
|
-
a.append(...
|
|
11
|
-
function E(a,
|
|
12
|
-
1,h
|
|
13
|
-
u.append(v)});
|
|
14
|
-
function G(a,
|
|
15
|
-
|
|
16
|
-
exports.$
|
|
17
|
-
exports.$
|
|
18
|
-
if(null!=a)if(z.$isRangeSelection(
|
|
7
|
+
'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.");}
|
|
8
|
+
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)}
|
|
9
|
+
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)||
|
|
10
|
+
A(41),a.append(...d))}
|
|
11
|
+
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(),
|
|
12
|
+
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=
|
|
13
|
+
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))}
|
|
14
|
+
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)&&
|
|
15
|
+
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;
|
|
16
|
+
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))};
|
|
17
|
+
exports.$insertDataTransferForPlainText=function(a,b){a=a.getData("text/plain");null!=a&&b.insertRawText(a)};
|
|
18
|
+
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]),
|
|
19
|
+
e<d-1&&b.insertParagraph();else b.insertRawText(a)};exports.$insertGeneratedNodes=B
|
package/clipboard.d.ts
CHANGED
|
@@ -10,7 +10,8 @@ export declare function $getHtmlContent(editor: LexicalEditor): string | null;
|
|
|
10
10
|
export declare function $getLexicalContent(editor: LexicalEditor): string | null;
|
|
11
11
|
export declare function $insertDataTransferForPlainText(dataTransfer: DataTransfer, selection: RangeSelection | GridSelection): void;
|
|
12
12
|
export declare function $insertDataTransferForRichText(dataTransfer: DataTransfer, selection: RangeSelection | GridSelection, editor: LexicalEditor): void;
|
|
13
|
-
|
|
13
|
+
export declare function $insertGeneratedNodes(editor: LexicalEditor, nodes: Array<LexicalNode>, selection: RangeSelection | GridSelection): void;
|
|
14
|
+
export interface BaseSerializedNode {
|
|
14
15
|
children?: Array<BaseSerializedNode>;
|
|
15
16
|
type: string;
|
|
16
17
|
version: number;
|
|
@@ -20,4 +21,3 @@ export declare function $generateJSONFromSelectedNodes<SerializedNode extends Ba
|
|
|
20
21
|
nodes: Array<SerializedNode>;
|
|
21
22
|
};
|
|
22
23
|
export declare function $generateNodesFromSerializedNodes(serializedNodes: Array<BaseSerializedNode>): Array<LexicalNode>;
|
|
23
|
-
export {};
|
package/index.d.ts
CHANGED
|
@@ -6,5 +6,5 @@
|
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*
|
|
8
8
|
*/
|
|
9
|
-
import { $getHtmlContent, $getLexicalContent, $insertDataTransferForPlainText, $insertDataTransferForRichText } from './clipboard';
|
|
10
|
-
export { $getHtmlContent, $getLexicalContent, $insertDataTransferForPlainText, $insertDataTransferForRichText, };
|
|
9
|
+
import { $generateJSONFromSelectedNodes, $generateNodesFromSerializedNodes, $getHtmlContent, $getLexicalContent, $insertDataTransferForPlainText, $insertDataTransferForRichText, $insertGeneratedNodes } from './clipboard';
|
|
10
|
+
export { $generateJSONFromSelectedNodes, $generateNodesFromSerializedNodes, $getHtmlContent, $getLexicalContent, $insertDataTransferForPlainText, $insertDataTransferForRichText, $insertGeneratedNodes, };
|
package/package.json
CHANGED
|
@@ -9,16 +9,16 @@
|
|
|
9
9
|
"paste"
|
|
10
10
|
],
|
|
11
11
|
"license": "MIT",
|
|
12
|
-
"version": "0.
|
|
12
|
+
"version": "0.5.0",
|
|
13
13
|
"main": "LexicalClipboard.js",
|
|
14
14
|
"peerDependencies": {
|
|
15
|
-
"lexical": "0.
|
|
15
|
+
"lexical": "0.5.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.5.0",
|
|
19
|
+
"@lexical/list": "0.5.0",
|
|
20
|
+
"@lexical/selection": "0.5.0",
|
|
21
|
+
"@lexical/html": "0.5.0"
|
|
22
22
|
},
|
|
23
23
|
"repository": {
|
|
24
24
|
"type": "git",
|