@lexical/clipboard 0.2.8 → 0.3.1

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.
@@ -24,7 +24,6 @@ export function $insertDataTransferForRichText(
24
24
  ): void;
25
25
 
26
26
  export function $getHtmlContent(editor: LexicalEditor): string;
27
- export function $getLexicalContent(editor: LexicalEditor): string;
28
27
 
29
28
  /*
30
29
  * Plain Text
@@ -6,7 +6,7 @@
6
6
  */
7
7
  'use strict';
8
8
 
9
- var selection = require('@lexical/selection');
9
+ var html = require('@lexical/html');
10
10
  var utils = require('@lexical/utils');
11
11
  var lexical = require('lexical');
12
12
 
@@ -16,9 +16,7 @@ var lexical = require('lexical');
16
16
  * This source code is licensed under the MIT license found in the
17
17
  * LICENSE file in the root directory of this source tree.
18
18
  *
19
- *
20
19
  */
21
- const IGNORE_TAGS = new Set(['STYLE']);
22
20
  function $getHtmlContent(editor) {
23
21
  const selection = lexical.$getSelection();
24
22
 
@@ -31,171 +29,7 @@ function $getHtmlContent(editor) {
31
29
  return null;
32
30
  }
33
31
 
34
- return $convertSelectedContentToHtml(editor, selection);
35
- }
36
- function $appendSelectedNodesToHTML(editor, selection$1, currentNode, parentElement) {
37
- let shouldInclude = currentNode.isSelected();
38
- const shouldExclude = lexical.$isElementNode(currentNode) && currentNode.excludeFromCopy('html');
39
- let clone = selection.$cloneWithProperties(currentNode);
40
- clone = lexical.$isTextNode(clone) ? $splitClonedTextNode(selection$1, clone) : clone;
41
- const children = lexical.$isElementNode(clone) ? clone.getChildren() : [];
42
- const {
43
- element,
44
- after
45
- } = clone.exportDOM(editor);
46
-
47
- if (!element) {
48
- return false;
49
- }
50
-
51
- const fragment = new DocumentFragment();
52
-
53
- for (let i = 0; i < children.length; i++) {
54
- const childNode = children[i];
55
- const shouldIncludeChild = $appendSelectedNodesToHTML(editor, selection$1, childNode, fragment);
56
-
57
- if (!shouldInclude && lexical.$isElementNode(currentNode) && shouldIncludeChild && currentNode.extractWithChild(childNode, selection$1, 'html')) {
58
- shouldInclude = true;
59
- }
60
- }
61
-
62
- if (shouldInclude && !shouldExclude) {
63
- element.append(fragment);
64
- parentElement.append(element);
65
-
66
- if (after) {
67
- const newElement = after.call(clone, element);
68
- if (newElement) element.replaceWith(newElement);
69
- }
70
- } else {
71
- parentElement.append(fragment);
72
- }
73
-
74
- return shouldInclude;
75
- }
76
- function $convertSelectedContentToHtml(editor, selection) {
77
- const container = document.createElement('div');
78
- const root = lexical.$getRoot();
79
- const topLevelChildren = root.getChildren();
80
-
81
- for (let i = 0; i < topLevelChildren.length; i++) {
82
- const topLevelNode = topLevelChildren[i];
83
- $appendSelectedNodesToHTML(editor, selection, topLevelNode, container);
84
- }
85
-
86
- return container.innerHTML;
87
- }
88
- function $appendSelectedNodesToClone(editor, selection$1, currentNode, nodeMap, range, shouldIncludeInRange = true) {
89
- let shouldInclude = currentNode.isSelected();
90
- const shouldExclude = lexical.$isElementNode(currentNode) && currentNode.excludeFromCopy('clone');
91
- let clone = selection.$cloneWithProperties(currentNode);
92
- clone = lexical.$isTextNode(clone) ? $splitClonedTextNode(selection$1, clone) : clone;
93
- const children = lexical.$isElementNode(clone) ? clone.getChildren() : [];
94
- const nodeKeys = [];
95
- let shouldIncludeChildrenInRange = shouldIncludeInRange;
96
-
97
- if (shouldInclude && !shouldExclude) {
98
- nodeMap.set(clone.getKey(), clone);
99
-
100
- if (shouldIncludeInRange) {
101
- shouldIncludeChildrenInRange = false;
102
- }
103
- }
104
-
105
- for (let i = 0; i < children.length; i++) {
106
- const childNode = children[i];
107
- const childNodeKeys = $appendSelectedNodesToClone(editor, selection$1, childNode, nodeMap, range, shouldIncludeChildrenInRange);
108
-
109
- for (let j = 0; j < childNodeKeys.length; j++) {
110
- const childNodeKey = childNodeKeys[j];
111
- nodeKeys.push(childNodeKey);
112
- }
113
-
114
- if (!shouldInclude && lexical.$isElementNode(currentNode) && nodeKeys.includes(childNode.getKey()) && currentNode.extractWithChild(childNode, selection$1, 'clone')) {
115
- shouldInclude = true;
116
- }
117
- } // The tree is later built using $generateNodes which works
118
- // by going through the nodes specified in the "range" & their children
119
- // while filtering out nodes not found in the "nodeMap".
120
- // This gets complicated when we want to "exclude" a node but
121
- // keep it's children i.e. a MarkNode and it's Text children.
122
- // The solution is to check if there's a cloned parent already in our map and
123
- // splice the current node's children into the nearest parent.
124
- // If there is no parent in the map already, the children will be added to the
125
- // top level range be default.
126
-
127
-
128
- if (lexical.$isElementNode(clone) && shouldExclude && shouldInclude) {
129
- let nearestClonedParent;
130
- let idxWithinClonedParent;
131
- let prev = clone;
132
- let curr = clone.getParent();
133
- const root = lexical.$getRoot();
134
-
135
- while (curr != null && !curr.is(root)) {
136
- if (nodeMap.has(curr.getKey()) || curr.extractWithChild(currentNode, selection$1, 'clone')) {
137
- nearestClonedParent = selection.$cloneWithProperties(curr);
138
- idxWithinClonedParent = prev.getIndexWithinParent();
139
- nodeMap.set(nearestClonedParent.getKey(), nearestClonedParent);
140
- break;
141
- }
142
-
143
- prev = curr;
144
- curr = curr.getParent();
145
- } // Add children to nearest cloned parent at the correct position.
146
-
147
-
148
- if (lexical.$isElementNode(nearestClonedParent) && idxWithinClonedParent != null) {
149
- nearestClonedParent.__children.splice(idxWithinClonedParent, 1, ...clone.__children);
150
- }
151
- }
152
-
153
- if (shouldInclude && !shouldExclude) {
154
- if (!nodeMap.has(clone.getKey())) {
155
- nodeMap.set(clone.getKey(), clone);
156
- }
157
-
158
- if (shouldIncludeInRange) {
159
- return [clone.getKey()];
160
- }
161
- }
162
-
163
- return shouldIncludeChildrenInRange ? nodeKeys : [];
164
- }
165
- function $cloneSelectedContent(editor, selection) {
166
- const root = lexical.$getRoot();
167
- const nodeMap = new Map();
168
- const range = [];
169
- const topLevelChildren = root.getChildren();
170
-
171
- for (let i = 0; i < topLevelChildren.length; i++) {
172
- const topLevelNode = topLevelChildren[i];
173
- const childNodeKeys = $appendSelectedNodesToClone(editor, selection, topLevelNode, nodeMap, range, true);
174
-
175
- for (let j = 0; j < childNodeKeys.length; j++) {
176
- const childNodeKey = childNodeKeys[j];
177
- range.push(childNodeKey);
178
- }
179
- }
180
-
181
- return {
182
- nodeMap: Array.from(nodeMap),
183
- range
184
- };
185
- }
186
- function $getLexicalContent(editor) {
187
- const selection = lexical.$getSelection();
188
-
189
- if (selection !== null) {
190
- const namespace = editor._config.namespace;
191
- const state = $cloneSelectedContent(editor, selection);
192
- return JSON.stringify({
193
- namespace,
194
- state
195
- });
196
- }
197
-
198
- return null;
32
+ return html.$generateHtmlFromNodes(editor, selection);
199
33
  }
200
34
  function $insertDataTransferForPlainText(dataTransfer, selection) {
201
35
  const text = dataTransfer.getData('text/plain');
@@ -205,38 +39,14 @@ function $insertDataTransferForPlainText(dataTransfer, selection) {
205
39
  }
206
40
  }
207
41
  function $insertDataTransferForRichText(dataTransfer, selection, editor) {
208
- const lexicalNodesString = dataTransfer.getData('application/x-lexical-editor');
209
42
  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;
210
-
211
- if (lexicalNodesString) {
212
- const namespace = editor._config.namespace;
213
-
214
- try {
215
- const lexicalClipboardData = JSON.parse(lexicalNodesString);
216
-
217
- if (lexicalClipboardData.namespace === namespace) {
218
- const nodeRange = lexicalClipboardData.state;
219
- const nodes = $generateNodes(nodeRange);
220
-
221
- if (isSelectionInsideOfGrid && nodes.length === 1 && lexical.$isGridNode(nodes[0])) {
222
- $mergeGridNodesStrategy(nodes, selection, false, editor);
223
- return;
224
- }
225
-
226
- $basicInsertStrategy(nodes, selection, true);
227
- return;
228
- }
229
- } catch (e) {// Malformed, missing nodes..
230
- }
231
- }
232
-
233
43
  const textHtmlMimeType = 'text/html';
234
44
  const htmlString = dataTransfer.getData(textHtmlMimeType);
235
45
 
236
46
  if (htmlString) {
237
47
  const parser = new DOMParser();
238
48
  const dom = parser.parseFromString(htmlString, textHtmlMimeType);
239
- const nodes = $generateNodesFromDOM(dom, editor);
49
+ const nodes = html.$generateNodesFromDOM(editor, dom);
240
50
 
241
51
  if (isSelectionInsideOfGrid && nodes.length === 1 && lexical.$isGridNode(nodes[0])) {
242
52
  $mergeGridNodesStrategy(nodes, selection, false, editor);
@@ -261,7 +71,7 @@ function $basicInsertStrategy(nodes, selection, isFromLexical) {
261
71
  for (let i = 0; i < nodes.length; i++) {
262
72
  const node = nodes[i];
263
73
 
264
- if (!lexical.$isElementNode(node) || node.isInline()) {
74
+ if (lexical.$isDecoratorNode(node) && !node.isTopLevel() || lexical.$isElementNode(node) && node.isInline() || lexical.$isTextNode(node) || lexical.$isLineBreakNode(node)) {
265
75
  if (currentBlock === null) {
266
76
  currentBlock = lexical.$createParagraphNode();
267
77
  topLevelBlocks.push(currentBlock);
@@ -396,175 +206,10 @@ function $mergeGridNodesStrategy(nodes, selection, isFromLexical, editor) {
396
206
  const newGridSelection = lexical.$createGridSelection();
397
207
  newGridSelection.set(gridNode.getKey(), newAnchorCellKey, newFocusCellKey);
398
208
  lexical.$setSelection(newGridSelection);
399
- editor.dispatchCommand(lexical.SELECTION_CHANGE_COMMAND);
209
+ editor.dispatchCommand(lexical.SELECTION_CHANGE_COMMAND, undefined);
400
210
  }
401
211
  }
402
212
 
403
- function $generateNodes(nodeRange) {
404
- const {
405
- range,
406
- nodeMap
407
- } = nodeRange;
408
- const parsedNodeMap = new Map(nodeMap);
409
- const nodes = [];
410
-
411
- for (let i = 0; i < range.length; i++) {
412
- const key = range[i];
413
- const parsedNode = parsedNodeMap.get(key);
414
-
415
- if (parsedNode !== undefined) {
416
- const node = lexical.$createNodeFromParse(parsedNode, parsedNodeMap);
417
- nodes.push(node);
418
- }
419
- }
420
-
421
- return nodes;
422
- }
423
-
424
- function getConversionFunction(domNode, editor) {
425
- const {
426
- nodeName
427
- } = domNode;
428
-
429
- const cachedConversions = editor._htmlConversions.get(nodeName.toLowerCase());
430
-
431
- let currentConversion = null;
432
-
433
- if (cachedConversions !== undefined) {
434
- cachedConversions.forEach(cachedConversion => {
435
- const domConversion = cachedConversion(domNode);
436
-
437
- if (domConversion !== null) {
438
- if (currentConversion === null || currentConversion.priority < domConversion.priority) {
439
- currentConversion = domConversion;
440
- }
441
- }
442
- });
443
- }
444
-
445
- return currentConversion !== null ? currentConversion.conversion : null;
446
- }
447
-
448
- function $createNodesFromDOM(node, editor, forChildMap = new Map(), parentLexicalNode) {
449
- let lexicalNodes = [];
450
-
451
- if (IGNORE_TAGS.has(node.nodeName)) {
452
- return lexicalNodes;
453
- }
454
-
455
- let currentLexicalNode = null;
456
- const transformFunction = getConversionFunction(node, editor);
457
- const transformOutput = transformFunction ? transformFunction(node) : null;
458
- let postTransform = null;
459
-
460
- if (transformOutput !== null) {
461
- postTransform = transformOutput.after;
462
- currentLexicalNode = transformOutput.node;
463
-
464
- if (currentLexicalNode !== null) {
465
- for (const [, forChildFunction] of forChildMap) {
466
- currentLexicalNode = forChildFunction(currentLexicalNode, parentLexicalNode);
467
-
468
- if (!currentLexicalNode) {
469
- break;
470
- }
471
- }
472
-
473
- if (currentLexicalNode) {
474
- lexicalNodes.push(currentLexicalNode);
475
- }
476
- }
477
-
478
- if (transformOutput.forChild != null) {
479
- forChildMap.set(node.nodeName, transformOutput.forChild);
480
- }
481
- } // If the DOM node doesn't have a transformer, we don't know what
482
- // to do with it but we still need to process any childNodes.
483
-
484
-
485
- const children = node.childNodes;
486
- let childLexicalNodes = [];
487
-
488
- for (let i = 0; i < children.length; i++) {
489
- childLexicalNodes.push(...$createNodesFromDOM(children[i], editor, forChildMap, currentLexicalNode));
490
- }
491
-
492
- if (postTransform != null) {
493
- childLexicalNodes = postTransform(childLexicalNodes);
494
- }
495
-
496
- if (currentLexicalNode == null) {
497
- // If it hasn't been converted to a LexicalNode, we hoist its children
498
- // up to the same level as it.
499
- lexicalNodes = lexicalNodes.concat(childLexicalNodes);
500
- } else {
501
- if (lexical.$isElementNode(currentLexicalNode)) {
502
- // If the current node is a ElementNode after conversion,
503
- // we can append all the children to it.
504
- currentLexicalNode.append(...childLexicalNodes);
505
- }
506
- }
507
-
508
- return lexicalNodes;
509
- }
510
-
511
- function $generateNodesFromDOM(dom, editor) {
512
- let lexicalNodes = [];
513
- const elements = dom.body ? Array.from(dom.body.childNodes) : [];
514
- const elementsLength = elements.length;
515
-
516
- for (let i = 0; i < elementsLength; i++) {
517
- const element = elements[i];
518
-
519
- if (!IGNORE_TAGS.has(element.nodeName)) {
520
- const lexicalNode = $createNodesFromDOM(element, editor);
521
-
522
- if (lexicalNode !== null) {
523
- lexicalNodes = lexicalNodes.concat(lexicalNode);
524
- }
525
- }
526
- }
527
-
528
- return lexicalNodes;
529
- }
530
- function $splitClonedTextNode(selection, clone) {
531
- if (clone.isSelected() && !clone.isSegmented() && !clone.isToken() && (lexical.$isRangeSelection(selection) || lexical.$isGridSelection(selection))) {
532
- const anchorNode = selection.anchor.getNode();
533
- const focusNode = selection.focus.getNode();
534
- const isAnchor = clone.is(anchorNode);
535
- const isFocus = clone.is(focusNode);
536
-
537
- if (isAnchor || isFocus) {
538
- const isBackward = selection.isBackward();
539
- const [anchorOffset, focusOffset] = selection.getCharacterOffsets();
540
- const isSame = anchorNode.is(focusNode);
541
- const isFirst = clone.is(isBackward ? focusNode : anchorNode);
542
- const isLast = clone.is(isBackward ? anchorNode : focusNode);
543
- let startOffset = 0;
544
- let endOffset = undefined;
545
-
546
- if (isSame) {
547
- startOffset = anchorOffset > focusOffset ? focusOffset : anchorOffset;
548
- endOffset = anchorOffset > focusOffset ? anchorOffset : focusOffset;
549
- } else if (isFirst) {
550
- const offset = isBackward ? focusOffset : anchorOffset;
551
- startOffset = offset;
552
- endOffset = undefined;
553
- } else if (isLast) {
554
- const offset = isBackward ? anchorOffset : focusOffset;
555
- startOffset = 0;
556
- endOffset = offset;
557
- }
558
-
559
- clone.__text = clone.__text.slice(startOffset, endOffset);
560
- return clone;
561
- }
562
- }
563
-
564
- return clone;
565
- }
566
-
567
213
  exports.$getHtmlContent = $getHtmlContent;
568
- exports.$getLexicalContent = $getLexicalContent;
569
214
  exports.$insertDataTransferForPlainText = $insertDataTransferForPlainText;
570
215
  exports.$insertDataTransferForRichText = $insertDataTransferForRichText;
@@ -25,7 +25,6 @@ declare export function $insertDataTransferForRichText(
25
25
  ): void;
26
26
 
27
27
  declare export function $getHtmlContent(editor: LexicalEditor): string;
28
- declare export function $getLexicalContent(editor: LexicalEditor): string;
29
28
 
30
29
  /*
31
30
  * Plain Text
@@ -4,19 +4,9 @@
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
- var h=require("@lexical/selection"),u=require("@lexical/utils"),v=require("lexical");function z(a){throw Error(`Minified Lexical error #${a}; see codes.json for the full message or `+"use the non-minified dev environment for full errors and additional helpful warnings.");}const A=new Set(["STYLE"]);
8
- function B(a,c,d,e){let b=d.isSelected();const f=v.$isElementNode(d)&&d.excludeFromCopy("html");let g=h.$cloneWithProperties(d);g=v.$isTextNode(g)?C(c,g):g;const l=v.$isElementNode(g)?g.getChildren():[],{element:k,after:q}=g.exportDOM(a);if(!k)return!1;const r=new DocumentFragment;for(let p=0;p<l.length;p++){const n=l[p],m=B(a,c,n,r);!b&&v.$isElementNode(d)&&m&&d.extractWithChild(n,c,"html")&&(b=!0)}b&&!f?(k.append(r),e.append(k),q&&(a=q.call(g,k))&&k.replaceWith(a)):e.append(r);return b}
9
- function D(a,c,d,e,b,f=!0){let g=d.isSelected();const l=v.$isElementNode(d)&&d.excludeFromCopy("clone");let k=h.$cloneWithProperties(d);k=v.$isTextNode(k)?C(c,k):k;var q=v.$isElementNode(k)?k.getChildren():[];const r=[];let p=f;g&&!l&&(e.set(k.getKey(),k),f&&(p=!1));for(let n=0;n<q.length;n++){const m=q[n],w=D(a,c,m,e,b,p);for(let t=0;t<w.length;t++)r.push(w[t]);!g&&v.$isElementNode(d)&&r.includes(m.getKey())&&d.extractWithChild(m,c,"clone")&&(g=!0)}if(v.$isElementNode(k)&&l&&g){let n,m;a=k;b=k.getParent();
10
- for(q=v.$getRoot();null!=b&&!b.is(q);){if(e.has(b.getKey())||b.extractWithChild(d,c,"clone")){n=h.$cloneWithProperties(b);m=a.getIndexWithinParent();e.set(n.getKey(),n);break}a=b;b=b.getParent()}v.$isElementNode(n)&&null!=m&&n.__children.splice(m,1,...k.__children)}return g&&!l&&(e.has(k.getKey())||e.set(k.getKey(),k),f)?[k.getKey()]:p?r:[]}function E(a,c){a=a.getData("text/plain");null!=a&&c.insertRawText(a)}
11
- function F(a,c,d){if(!d){d=[];let e=null;for(let b=0;b<a.length;b++){const f=a[b];!v.$isElementNode(f)||f.isInline()?(null===e&&(e=v.$createParagraphNode(),d.push(e)),null!==e&&e.append(f)):(d.push(f),e=null)}a=d}v.$isRangeSelection(c)?c.insertNodes(a):v.$isGridSelection(c)&&(c=c.anchor.getNode(),v.$isGridCellNode(c)||z(15),c.append(...a))}
12
- function G(a,c,d,e){1===a.length&&v.$isGridNode(a[0])||z(16);var b=a[0];a=b.getChildren();d=b.getFirstChildOrThrow().getChildrenSize();var f=b.getChildrenSize(),g=u.$findMatchingParent(c.anchor.getNode(),m=>v.$isGridCellNode(m));c=(b=g&&u.$findMatchingParent(g,m=>v.$isGridRowNode(m)))&&u.$findMatchingParent(b,m=>v.$isGridNode(m));v.$isGridCellNode(g)&&v.$isGridRowNode(b)&&v.$isGridNode(c)||z(17);var l=b.getIndexWithinParent(),k=Math.min(c.getChildrenSize()-1,l+f-1);f=g.getIndexWithinParent();g=Math.min(b.getChildrenSize()-
13
- 1,f+d-1);d=Math.min(f,g);b=Math.min(l,k);f=Math.max(f,g);l=Math.max(l,k);k=c.getChildren();g=0;let q,r;for(let m=b;m<=l;m++){var p=k[m];v.$isGridRowNode(p)||z(18);var n=a[g];v.$isGridRowNode(n)||z(18);p=p.getChildren();n=n.getChildren();let w=0;for(let t=d;t<=f;t++){const x=p[t];v.$isGridCellNode(x)||z(19);const H=n[w];v.$isGridCellNode(H)||z(19);m===b&&t===d?q=x.getKey():m===l&&t===f&&(r=x.getKey());const J=x.getChildren();H.getChildren().forEach(y=>{v.$isTextNode(y)&&v.$createParagraphNode().append(y);
14
- x.append(y)});J.forEach(y=>y.remove());w++}g++}q&&r&&(a=v.$createGridSelection(),a.set(c.getKey(),q,r),v.$setSelection(a),e.dispatchCommand(v.SELECTION_CHANGE_COMMAND))}function I(a){const {range:c,nodeMap:d}=a;a=new Map(d);const e=[];for(let f=0;f<c.length;f++){var b=a.get(c[f]);void 0!==b&&(b=v.$createNodeFromParse(b,a),e.push(b))}return e}
15
- function K(a,c){const {nodeName:d}=a;c=c._htmlConversions.get(d.toLowerCase());let e=null;void 0!==c&&c.forEach(b=>{b=b(a);null!==b&&(null===e||e.priority<b.priority)&&(e=b)});return null!==e?e.conversion:null}
16
- function L(a,c,d=new Map,e){let b=[];if(A.has(a.nodeName))return b;let f=null;var g=K(a,c);const l=g?g(a):null;g=null;if(null!==l){g=l.after;f=l.node;if(null!==f){for(var [,k]of d)if(f=k(f,e),!f)break;f&&b.push(f)}null!=l.forChild&&d.set(a.nodeName,l.forChild)}a=a.childNodes;e=[];for(k=0;k<a.length;k++)e.push(...L(a[k],c,d,f));null!=g&&(e=g(e));null==f?b=b.concat(e):v.$isElementNode(f)&&f.append(...e);return b}
17
- function M(a,c){let d=[];a=a.body?Array.from(a.body.childNodes):[];const e=a.length;for(let f=0;f<e;f++){var b=a[f];A.has(b.nodeName)||(b=L(b,c),null!==b&&(d=d.concat(b)))}return d}
18
- function C(a,c){if(c.isSelected()&&!c.isSegmented()&&!c.isToken()&&(v.$isRangeSelection(a)||v.$isGridSelection(a))){var d=a.anchor.getNode(),e=a.focus.getNode(),b=c.is(d),f=c.is(e);if(b||f){b=a.isBackward();const [g,l]=a.getCharacterOffsets();a=d.is(e);f=c.is(b?e:d);e=c.is(b?d:e);d=0;let k=void 0;a?(d=g>l?l:g,k=g>l?g:l):f?(d=b?l:g,k=void 0):e&&(b=b?g:l,d=0,k=b);c.__text=c.__text.slice(d,k)}}return c}
19
- exports.$getHtmlContent=function(a){const c=v.$getSelection();if(null==c)throw Error("Expected valid LexicalSelection");if(v.$isRangeSelection(c)&&c.isCollapsed()||0===c.getNodes().length)return null;const d=document.createElement("div"),e=v.$getRoot().getChildren();for(let b=0;b<e.length;b++)B(a,c,e[b],d);return d.innerHTML};
20
- exports.$getLexicalContent=function(a){const c=v.$getSelection();if(null!==c){const e=a._config.namespace;var d=v.$getRoot();const b=new Map,f=[];d=d.getChildren();for(let g=0;g<d.length;g++){const l=D(a,c,d[g],b,f,!0);for(let k=0;k<l.length;k++)f.push(l[k])}a={nodeMap:Array.from(b),range:f};return JSON.stringify({namespace:e,state:a})}return null};exports.$insertDataTransferForPlainText=E;
21
- exports.$insertDataTransferForRichText=function(a,c,d){var e=a.getData("application/x-lexical-editor");const b=v.$isGridSelection(c)||null!==u.$findMatchingParent(c.anchor.getNode(),f=>v.$isGridCellNode(f))&&null!==u.$findMatchingParent(c.focus.getNode(),f=>v.$isGridCellNode(f));if(e){const f=d._config.namespace;try{const g=JSON.parse(e);if(g.namespace===f){const l=I(g.state);if(b&&1===l.length&&v.$isGridNode(l[0])){G(l,c,!1,d);return}F(l,c,!0);return}}catch(g){}}(e=a.getData("text/html"))?(a=(new DOMParser).parseFromString(e,
22
- "text/html"),a=M(a,d),b&&1===a.length&&v.$isGridNode(a[0])?G(a,c,!1,d):F(a,c,!1)):E(a,c)};
7
+ 'use strict';var b=require("@lexical/html"),l=require("@lexical/utils"),n=require("lexical");function y(a){throw Error(`Minified Lexical error #${a}; see codes.json for the full message or `+"use the non-minified dev environment for full errors and additional helpful warnings.");}function z(a,c){a=a.getData("text/plain");null!=a&&c.insertRawText(a)}
8
+ function C(a,c,f){if(!f){f=[];let h=null;for(let e=0;e<a.length;e++){let d=a[e];n.$isDecoratorNode(d)&&!d.isTopLevel()||n.$isElementNode(d)&&d.isInline()||n.$isTextNode(d)||n.$isLineBreakNode(d)?(null===h&&(h=n.$createParagraphNode(),f.push(h)),null!==h&&h.append(d)):(f.push(d),h=null)}a=f}n.$isRangeSelection(c)?c.insertNodes(a):n.$isGridSelection(c)&&(c=c.anchor.getNode(),n.$isGridCellNode(c)||y(41),c.append(...a))}
9
+ function D(a,c,f,h){1===a.length&&n.$isGridNode(a[0])||y(42);var e=a[0];a=e.getChildren();f=e.getFirstChildOrThrow().getChildrenSize();var d=e.getChildrenSize(),k=l.$findMatchingParent(c.anchor.getNode(),g=>n.$isGridCellNode(g));c=(e=k&&l.$findMatchingParent(k,g=>n.$isGridRowNode(g)))&&l.$findMatchingParent(e,g=>n.$isGridNode(g));n.$isGridCellNode(k)&&n.$isGridRowNode(e)&&n.$isGridNode(c)||y(43);var m=e.getIndexWithinParent(),t=Math.min(c.getChildrenSize()-1,m+d-1);d=k.getIndexWithinParent();k=Math.min(e.getChildrenSize()-
10
+ 1,d+f-1);f=Math.min(d,k);e=Math.min(m,t);d=Math.max(d,k);m=Math.max(m,t);t=c.getChildren();k=0;let w,x;for(let g=e;g<=m;g++){var u=t[g];n.$isGridRowNode(u)||y(24);var v=a[k];n.$isGridRowNode(v)||y(24);u=u.getChildren();v=v.getChildren();let A=0;for(let p=f;p<=d;p++){let q=u[p];n.$isGridCellNode(q)||y(25);let B=v[A];n.$isGridCellNode(B)||y(25);g===e&&p===f?w=q.getKey():g===m&&p===d&&(x=q.getKey());let E=q.getChildren();B.getChildren().forEach(r=>{n.$isTextNode(r)&&n.$createParagraphNode().append(r);
11
+ q.append(r)});E.forEach(r=>r.remove());A++}k++}w&&x&&(a=n.$createGridSelection(),a.set(c.getKey(),w,x),n.$setSelection(a),h.dispatchCommand(n.SELECTION_CHANGE_COMMAND,void 0))}exports.$getHtmlContent=function(a){let c=n.$getSelection();if(null==c)throw Error("Expected valid LexicalSelection");return n.$isRangeSelection(c)&&c.isCollapsed()||0===c.getNodes().length?null:b.$generateHtmlFromNodes(a,c)};exports.$insertDataTransferForPlainText=z;
12
+ exports.$insertDataTransferForRichText=function(a,c,f){let h=n.$isGridSelection(c)||null!==l.$findMatchingParent(c.anchor.getNode(),d=>n.$isGridCellNode(d))&&null!==l.$findMatchingParent(c.focus.getNode(),d=>n.$isGridCellNode(d)),e=a.getData("text/html");e?(a=(new DOMParser).parseFromString(e,"text/html"),a=b.$generateNodesFromDOM(f,a),h&&1===a.length&&n.$isGridNode(a[0])?D(a,c,!1,f):C(a,c,!1)):z(a,c)}
package/package.json CHANGED
@@ -9,14 +9,15 @@
9
9
  "paste"
10
10
  ],
11
11
  "license": "MIT",
12
- "version": "0.2.8",
12
+ "version": "0.3.1",
13
13
  "main": "LexicalClipboard.js",
14
14
  "peerDependencies": {
15
- "lexical": "0.2.8"
15
+ "lexical": "0.3.1"
16
16
  },
17
17
  "dependencies": {
18
- "@lexical/utils": "0.2.8",
19
- "@lexical/selection": "0.2.8"
18
+ "@lexical/utils": "0.3.1",
19
+ "@lexical/selection": "0.3.1",
20
+ "@lexical/html": "0.3.1"
20
21
  },
21
22
  "repository": {
22
23
  "type": "git",