@lexical/clipboard 0.2.5 → 0.2.8
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.d.ts +8 -3
- package/LexicalClipboard.dev.js +174 -72
- package/LexicalClipboard.js.flow +8 -3
- package/LexicalClipboard.prod.js +16 -13
- package/package.json +4 -4
package/LexicalClipboard.d.ts
CHANGED
|
@@ -6,7 +6,12 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import type {
|
|
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
|
/*
|
package/LexicalClipboard.dev.js
CHANGED
|
@@ -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
|
|
22
|
+
function $getHtmlContent(editor) {
|
|
23
|
+
const selection = lexical.$getSelection();
|
|
24
24
|
|
|
25
|
-
if (selection
|
|
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
|
|
30
|
+
if (lexical.$isRangeSelection(selection) && selection.isCollapsed() || selection.getNodes().length === 0) {
|
|
31
31
|
return null;
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
|
|
35
|
-
return $convertSelectedLexicalContentToHtml(editor, selection$1, state);
|
|
34
|
+
return $convertSelectedContentToHtml(editor, selection);
|
|
36
35
|
}
|
|
37
|
-
function $
|
|
38
|
-
let
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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
|
-
} =
|
|
74
|
-
|
|
75
|
-
|
|
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 (
|
|
81
|
-
|
|
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
|
-
|
|
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 $
|
|
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 <
|
|
92
|
-
const
|
|
93
|
-
|
|
81
|
+
for (let i = 0; i < topLevelChildren.length; i++) {
|
|
82
|
+
const topLevelNode = topLevelChildren[i];
|
|
83
|
+
$appendSelectedNodesToHTML(editor, selection, topLevelNode, container);
|
|
84
|
+
}
|
|
94
85
|
|
|
95
|
-
|
|
96
|
-
|
|
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
|
-
|
|
99
|
-
|
|
100
|
-
|
|
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
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
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
|
-
|
|
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
|
|
187
|
+
const selection = lexical.$getSelection();
|
|
122
188
|
|
|
123
|
-
if (selection
|
|
189
|
+
if (selection !== null) {
|
|
124
190
|
const namespace = editor._config.namespace;
|
|
125
|
-
const state =
|
|
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;
|
package/LexicalClipboard.js.flow
CHANGED
|
@@ -7,7 +7,12 @@
|
|
|
7
7
|
* @flow strict
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
import type {
|
|
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
|
/*
|
package/LexicalClipboard.prod.js
CHANGED
|
@@ -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
|
|
8
|
-
function
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
function
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
function I(a
|
|
15
|
-
function
|
|
16
|
-
function
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
exports
|
|
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.
|
|
12
|
+
"version": "0.2.8",
|
|
13
13
|
"main": "LexicalClipboard.js",
|
|
14
14
|
"peerDependencies": {
|
|
15
|
-
"lexical": "0.2.
|
|
15
|
+
"lexical": "0.2.8"
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@lexical/utils": "0.2.
|
|
19
|
-
"@lexical/selection": "0.2.
|
|
18
|
+
"@lexical/utils": "0.2.8",
|
|
19
|
+
"@lexical/selection": "0.2.8"
|
|
20
20
|
},
|
|
21
21
|
"repository": {
|
|
22
22
|
"type": "git",
|