@lexical/clipboard 0.2.5 → 0.2.6

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.
@@ -6,7 +6,12 @@
6
6
  *
7
7
  */
8
8
 
9
- import type {LexicalEditor, RangeSelection} from 'lexical';
9
+ import type {
10
+ GridSelection,
11
+ LexicalEditor,
12
+ NodeSelection,
13
+ RangeSelection,
14
+ } from 'lexical';
10
15
 
11
16
  /*
12
17
  * Rich Text
@@ -14,11 +19,11 @@ import type {LexicalEditor, RangeSelection} from 'lexical';
14
19
 
15
20
  export function $insertDataTransferForRichText(
16
21
  dataTransfer: DataTransfer,
17
- selection: RangeSelection,
22
+ selection: RangeSelection | GridSelection | NodeSelection,
18
23
  editor: LexicalEditor,
19
24
  ): void;
20
25
 
21
- export function getHtmlContent(editor: LexicalEditor): string;
26
+ export function $getHtmlContent(editor: LexicalEditor): string;
22
27
  export function $getLexicalContent(editor: LexicalEditor): string;
23
28
 
24
29
  /*
@@ -19,110 +19,176 @@ var lexical = require('lexical');
19
19
  *
20
20
  */
21
21
  const IGNORE_TAGS = new Set(['STYLE']);
22
- function getHtmlContent(editor) {
23
- const selection$1 = lexical.$getSelection();
22
+ function $getHtmlContent(editor) {
23
+ const selection = lexical.$getSelection();
24
24
 
25
- if (selection$1 == null) {
25
+ if (selection == null) {
26
26
  throw new Error('Expected valid LexicalSelection');
27
27
  } // If we haven't selected anything
28
28
 
29
29
 
30
- if (lexical.$isRangeSelection(selection$1) && selection$1.isCollapsed() || selection$1.getNodes().length === 0) {
30
+ if (lexical.$isRangeSelection(selection) && selection.isCollapsed() || selection.getNodes().length === 0) {
31
31
  return null;
32
32
  }
33
33
 
34
- const state = selection.$cloneContents(selection$1);
35
- return $convertSelectedLexicalContentToHtml(editor, selection$1, state);
34
+ return $convertSelectedContentToHtml(editor, selection);
36
35
  }
37
- function $convertSelectedLexicalNodeToHTMLElement(editor, selection, node) {
38
- let nodeToConvert = node;
39
-
40
- if (lexical.$isRangeSelection(selection) || lexical.$isGridSelection(selection)) {
41
- const anchorNode = selection.anchor.getNode();
42
- const focusNode = selection.focus.getNode();
43
- const isAnchor = node.is(anchorNode);
44
- const isFocus = node.is(focusNode);
45
-
46
- if (lexical.$isTextNode(node) && (isAnchor || isFocus)) {
47
- const [anchorOffset, focusOffset] = selection.getCharacterOffsets();
48
- const isBackward = selection.isBackward();
49
- const isSame = anchorNode.is(focusNode);
50
- const isFirst = node.is(isBackward ? focusNode : anchorNode);
51
- const isLast = node.is(isBackward ? anchorNode : focusNode);
52
-
53
- if (isSame) {
54
- const startOffset = anchorOffset > focusOffset ? focusOffset : anchorOffset;
55
- const endOffset = anchorOffset > focusOffset ? anchorOffset : focusOffset;
56
- const splitNodes = node.splitText(startOffset, endOffset);
57
- nodeToConvert = startOffset === 0 ? splitNodes[0] : splitNodes[1];
58
- } else if (isFirst) {
59
- const offset = isBackward ? focusOffset : anchorOffset;
60
- const splitNodes = node.splitText(offset);
61
- nodeToConvert = offset === 0 ? splitNodes[0] : splitNodes[1];
62
- } else if (isLast) {
63
- const offset = isBackward ? anchorOffset : focusOffset;
64
- const splitNodes = node.splitText(offset);
65
- nodeToConvert = splitNodes[0];
66
- }
67
- }
68
- }
69
-
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() : [];
70
42
  const {
71
43
  element,
72
44
  after
73
- } = nodeToConvert.exportDOM(editor);
74
- if (!element) return null;
75
- const children = lexical.$isElementNode(nodeToConvert) ? nodeToConvert.getChildren() : [];
45
+ } = clone.exportDOM(editor);
46
+
47
+ if (!element) {
48
+ return false;
49
+ }
50
+
51
+ const fragment = new DocumentFragment();
76
52
 
77
53
  for (let i = 0; i < children.length; i++) {
78
54
  const childNode = children[i];
55
+ const shouldIncludeChild = $appendSelectedNodesToHTML(editor, selection$1, childNode, fragment);
79
56
 
80
- if (childNode.isSelected()) {
81
- const newElement = $convertSelectedLexicalNodeToHTMLElement(editor, selection, childNode);
82
- if (newElement) element.append(newElement);
57
+ if (!shouldInclude && lexical.$isElementNode(currentNode) && shouldIncludeChild && currentNode.extractWithChild(childNode, selection$1, 'html')) {
58
+ shouldInclude = true;
83
59
  }
84
60
  }
85
61
 
86
- return after ? after.call(nodeToConvert, element) : element;
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;
87
75
  }
88
- function $convertSelectedLexicalContentToHtml(editor, selection, state) {
76
+ function $convertSelectedContentToHtml(editor, selection) {
89
77
  const container = document.createElement('div');
78
+ const root = lexical.$getRoot();
79
+ const topLevelChildren = root.getChildren();
90
80
 
91
- for (let i = 0; i < state.range.length; i++) {
92
- const nodeKey = state.range[i];
93
- const node = lexical.$getNodeByKey(nodeKey);
81
+ for (let i = 0; i < topLevelChildren.length; i++) {
82
+ const topLevelNode = topLevelChildren[i];
83
+ $appendSelectedNodesToHTML(editor, selection, topLevelNode, container);
84
+ }
94
85
 
95
- if (node) {
96
- const element = $convertSelectedLexicalNodeToHTMLElement(editor, selection, node);
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
+ }
97
104
 
98
- if (element) {
99
- // It might be the case that the node is an element node
100
- // and we're not directly selecting it, but we are selecting
101
- // some of its children. So we'll need to extract that out
102
- // separately.
103
- if (node.isSelected()) {
104
- container.append(element);
105
- } else {
106
- let childNode = element.firstChild;
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);
107
108
 
108
- while (childNode != null) {
109
- const nextSibling = childNode.nextSibling;
110
- container.append(childNode);
111
- childNode = nextSibling;
112
- }
113
- }
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;
114
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);
115
150
  }
116
151
  }
117
152
 
118
- return container.innerHTML;
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
+ };
119
185
  }
120
186
  function $getLexicalContent(editor) {
121
- const selection$1 = lexical.$getSelection();
187
+ const selection = lexical.$getSelection();
122
188
 
123
- if (selection$1 !== null) {
189
+ if (selection !== null) {
124
190
  const namespace = editor._config.namespace;
125
- const state = selection.$cloneContents(selection$1);
191
+ const state = $cloneSelectedContent(editor, selection);
126
192
  return JSON.stringify({
127
193
  namespace,
128
194
  state
@@ -461,8 +527,44 @@ function $generateNodesFromDOM(dom, editor) {
461
527
 
462
528
  return lexicalNodes;
463
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
+ }
464
566
 
567
+ exports.$getHtmlContent = $getHtmlContent;
465
568
  exports.$getLexicalContent = $getLexicalContent;
466
569
  exports.$insertDataTransferForPlainText = $insertDataTransferForPlainText;
467
570
  exports.$insertDataTransferForRichText = $insertDataTransferForRichText;
468
- exports.getHtmlContent = getHtmlContent;
@@ -7,7 +7,12 @@
7
7
  * @flow strict
8
8
  */
9
9
 
10
- import type {LexicalEditor, RangeSelection} from 'lexical';
10
+ import type {
11
+ GridSelection,
12
+ LexicalEditor,
13
+ NodeSelection,
14
+ RangeSelection,
15
+ } from 'lexical';
11
16
 
12
17
  /*
13
18
  * Rich Text
@@ -15,11 +20,11 @@ import type {LexicalEditor, RangeSelection} from 'lexical';
15
20
 
16
21
  declare export function $insertDataTransferForRichText(
17
22
  dataTransfer: DataTransfer,
18
- selection: RangeSelection,
23
+ selection: RangeSelection | GridSelection | NodeSelection,
19
24
  editor: LexicalEditor,
20
25
  ): void;
21
26
 
22
- declare export function getHtmlContent(editor: LexicalEditor): string;
27
+ declare export function $getHtmlContent(editor: LexicalEditor): string;
23
28
  declare export function $getLexicalContent(editor: LexicalEditor): string;
24
29
 
25
30
  /*
@@ -4,16 +4,19 @@
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 g=require("@lexical/selection"),t=require("@lexical/utils"),x=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.");}const z=new Set(["STYLE"]);
8
- function A(a,c,e){var f=e;if(x.$isRangeSelection(c)||x.$isGridSelection(c)){var b=c.anchor.getNode(),d=c.focus.getNode(),h=e.is(b),k=e.is(d);if(x.$isTextNode(e)&&(h||k)){const [p,m]=c.getCharacterOffsets();h=c.isBackward();k=b.is(d);const q=e.is(h?d:b);b=e.is(h?b:d);k?(f=p>m?m:p,e=e.splitText(f,p>m?p:m),f=0===f?e[0]:e[1]):q?(f=h?m:p,e=e.splitText(f),f=0===f?e[0]:e[1]):b&&(f=e.splitText(h?p:m)[0])}}const {element:l,after:r}=f.exportDOM(a);if(!l)return null;e=x.$isElementNode(f)?f.getChildren():[];
9
- for(b=0;b<e.length;b++)d=e[b],d.isSelected()&&(d=A(a,c,d))&&l.append(d);return r?r.call(f,l):l}function B(a,c){a=a.getData("text/plain");null!=a&&c.insertRawText(a)}
10
- function C(a,c,e){if(!e){e=[];let f=null;for(let b=0;b<a.length;b++){const d=a[b];!x.$isElementNode(d)||d.isInline()?(null===f&&(f=x.$createParagraphNode(),e.push(f)),null!==f&&f.append(d)):(e.push(d),f=null)}a=e}if(x.$isRangeSelection(c))c.insertNodes(a);else if(x.$isGridSelection(c)){c=c.anchor.getNode();if(!x.$isGridCellNode(c))throw Error("Expected Grid Cell in Grid Selection");c.append(...a)}}
11
- function D(a,c,e,f){if(1!==a.length||!x.$isGridNode(a[0]))throw Error("$mergeGridNodesStrategy: Expected Grid insertion.");var b=a[0];a=b.getChildren();e=b.getFirstChildOrThrow().getChildrenSize();var d=b.getChildrenSize(),h=t.$findMatchingParent(c.anchor.getNode(),n=>x.$isGridCellNode(n));c=(b=h&&t.$findMatchingParent(h,n=>x.$isGridRowNode(n)))&&t.$findMatchingParent(b,n=>x.$isGridNode(n));if(!x.$isGridCellNode(h)||!x.$isGridRowNode(b)||!x.$isGridNode(c))throw Error("$mergeGridNodesStrategy: Expected selection to be inside of a Grid.");
12
- var k=b.getIndexWithinParent(),l=Math.min(c.getChildrenSize()-1,k+d-1);d=h.getIndexWithinParent();h=Math.min(b.getChildrenSize()-1,d+e-1);e=Math.min(d,h);b=Math.min(k,l);d=Math.max(d,h);k=Math.max(k,l);l=c.getChildren();h=0;let r,p;for(let n=b;n<=k;n++){var m=l[n];x.$isGridRowNode(m)||y(77);var q=a[h];x.$isGridRowNode(q)||y(77);m=m.getChildren();q=q.getChildren();let E=0;for(let u=e;u<=d;u++){const v=m[u];x.$isGridCellNode(v)||y(78);const F=q[E];x.$isGridCellNode(F)||y(78);n===b&&u===e?r=v.getKey():
13
- n===k&&u===d&&(p=v.getKey());const H=v.getChildren();F.getChildren().forEach(w=>{x.$isTextNode(w)&&x.$createParagraphNode().append(w);v.append(w)});H.forEach(w=>w.remove());E++}h++}r&&p&&(a=x.$createGridSelection(),a.set(c.getKey(),r,p),x.$setSelection(a),f.dispatchCommand(x.SELECTION_CHANGE_COMMAND))}function G(a){const {range:c,nodeMap:e}=a;a=new Map(e);const f=[];for(let d=0;d<c.length;d++){var b=a.get(c[d]);void 0!==b&&(b=x.$createNodeFromParse(b,a),f.push(b))}return f}
14
- function I(a,c){const {nodeName:e}=a;c=c._htmlConversions.get(e.toLowerCase());let f=null;void 0!==c&&c.forEach(b=>{b=b(a);null!==b&&(null===f||f.priority<b.priority)&&(f=b)});return null!==f?f.conversion:null}
15
- function J(a,c,e=new Map,f){let b=[];if(z.has(a.nodeName))return b;let d=null;var h=I(a,c);const k=h?h(a):null;h=null;if(null!==k){h=k.after;d=k.node;if(null!==d){for(var [,l]of e)if(d=l(d,f),!d)break;d&&b.push(d)}null!=k.forChild&&e.set(a.nodeName,k.forChild)}a=a.childNodes;f=[];for(l=0;l<a.length;l++)f.push(...J(a[l],c,e,d));null!=h&&(f=h(f));null==d?b=b.concat(f):x.$isElementNode(d)&&d.append(...f);return b}
16
- function K(a,c){let e=[];a=a.body?Array.from(a.body.childNodes):[];const f=a.length;for(let d=0;d<f;d++){var b=a[d];z.has(b.nodeName)||(b=J(b,c),null!==b&&(e=e.concat(b)))}return e}exports.$getLexicalContent=function(a){var c=x.$getSelection();return null!==c?(a=a._config.namespace,c=g.$cloneContents(c),JSON.stringify({namespace:a,state:c})):null};exports.$insertDataTransferForPlainText=B;
17
- exports.$insertDataTransferForRichText=function(a,c,e){var f=a.getData("application/x-lexical-editor");const b=x.$isGridSelection(c)||null!==t.$findMatchingParent(c.anchor.getNode(),d=>x.$isGridCellNode(d))&&null!==t.$findMatchingParent(c.focus.getNode(),d=>x.$isGridCellNode(d));if(f){const d=e._config.namespace;try{const h=JSON.parse(f);if(h.namespace===d){const k=G(h.state);if(b&&1===k.length&&x.$isGridNode(k[0])){D(k,c,!1,e);return}C(k,c,!0);return}}catch(h){}}(f=a.getData("text/html"))?(a=(new DOMParser).parseFromString(f,
18
- "text/html"),a=K(a,e),b&&1===a.length&&x.$isGridNode(a[0])?D(a,c,!1,e):C(a,c,!1)):B(a,c)};
19
- exports.getHtmlContent=function(a){const c=x.$getSelection();if(null==c)throw Error("Expected valid LexicalSelection");if(x.$isRangeSelection(c)&&c.isCollapsed()||0===c.getNodes().length)return null;var e=g.$cloneContents(c);const f=document.createElement("div");for(let h=0;h<e.range.length;h++){var b=x.$getNodeByKey(e.range[h]);if(b){var d=A(a,c,b);if(d)if(b.isSelected())f.append(d);else for(b=d.firstChild;null!=b;)d=b.nextSibling,f.append(b),b=d}}return f.innerHTML};
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)};
package/package.json CHANGED
@@ -9,14 +9,14 @@
9
9
  "paste"
10
10
  ],
11
11
  "license": "MIT",
12
- "version": "0.2.5",
12
+ "version": "0.2.6",
13
13
  "main": "LexicalClipboard.js",
14
14
  "peerDependencies": {
15
- "lexical": "0.2.5"
15
+ "lexical": "0.2.6"
16
16
  },
17
17
  "dependencies": {
18
- "@lexical/utils": "0.2.5",
19
- "@lexical/selection": "0.2.5"
18
+ "@lexical/utils": "0.2.6",
19
+ "@lexical/selection": "0.2.6"
20
20
  },
21
21
  "repository": {
22
22
  "type": "git",