@lexical/clipboard 0.1.16 → 0.1.19
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/LICENSE +1 -1
- package/LexicalClipboard.d.ts +31 -0
- package/LexicalClipboard.dev.js +26 -10
- package/LexicalClipboard.js.flow +32 -0
- package/LexicalClipboard.prod.js +5 -5
- package/package.json +4 -8
package/LICENSE
CHANGED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import type {LexicalEditor, RangeSelection} from 'lexical';
|
|
10
|
+
|
|
11
|
+
/*
|
|
12
|
+
* Rich Text
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
export function $insertDataTransferForRichText(
|
|
16
|
+
dataTransfer: DataTransfer,
|
|
17
|
+
selection: RangeSelection,
|
|
18
|
+
editor: LexicalEditor,
|
|
19
|
+
): void;
|
|
20
|
+
|
|
21
|
+
export function getHtmlContent(editor: LexicalEditor): string;
|
|
22
|
+
export function $getLexicalContent(editor: LexicalEditor): string;
|
|
23
|
+
|
|
24
|
+
/*
|
|
25
|
+
* Plain Text
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
export function $insertDataTransferForPlainText(
|
|
29
|
+
dataTransfer: DataTransfer,
|
|
30
|
+
selection: RangeSelection,
|
|
31
|
+
): void;
|
package/LexicalClipboard.dev.js
CHANGED
|
@@ -29,6 +29,7 @@ var getDOMSelection = getSelection;
|
|
|
29
29
|
*
|
|
30
30
|
*
|
|
31
31
|
*/
|
|
32
|
+
const IGNORE_TAGS = new Set(['STYLE']);
|
|
32
33
|
function getHtmlContent(editor) {
|
|
33
34
|
const domSelection = getDOMSelection(); // If we haven't selected a range, then don't copy anything
|
|
34
35
|
|
|
@@ -52,9 +53,10 @@ function $getLexicalContent(editor) {
|
|
|
52
53
|
|
|
53
54
|
if (selection$1 !== null) {
|
|
54
55
|
const namespace = editor._config.namespace;
|
|
56
|
+
const state = selection.$cloneContents(selection$1);
|
|
55
57
|
return JSON.stringify({
|
|
56
58
|
namespace,
|
|
57
|
-
state
|
|
59
|
+
state
|
|
58
60
|
});
|
|
59
61
|
}
|
|
60
62
|
|
|
@@ -167,8 +169,13 @@ function getConversionFunction(domNode, editor) {
|
|
|
167
169
|
return currentConversion !== null ? currentConversion.conversion : null;
|
|
168
170
|
}
|
|
169
171
|
|
|
170
|
-
function $createNodesFromDOM(node, editor, forChildMap = new Map()) {
|
|
172
|
+
function $createNodesFromDOM(node, editor, forChildMap = new Map(), parentLexicalNode) {
|
|
171
173
|
let lexicalNodes = [];
|
|
174
|
+
|
|
175
|
+
if (IGNORE_TAGS.has(node.nodeName)) {
|
|
176
|
+
return lexicalNodes;
|
|
177
|
+
}
|
|
178
|
+
|
|
172
179
|
let currentLexicalNode = null;
|
|
173
180
|
const transformFunction = getConversionFunction(node, editor);
|
|
174
181
|
const transformOutput = transformFunction ? transformFunction(node) : null;
|
|
@@ -179,11 +186,16 @@ function $createNodesFromDOM(node, editor, forChildMap = new Map()) {
|
|
|
179
186
|
currentLexicalNode = transformOutput.node;
|
|
180
187
|
|
|
181
188
|
if (currentLexicalNode !== null) {
|
|
182
|
-
|
|
183
|
-
|
|
189
|
+
for (const [, forChildFunction] of forChildMap) {
|
|
190
|
+
currentLexicalNode = forChildFunction(currentLexicalNode, parentLexicalNode);
|
|
191
|
+
|
|
192
|
+
if (!currentLexicalNode) {
|
|
193
|
+
break;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
184
196
|
|
|
185
|
-
|
|
186
|
-
|
|
197
|
+
if (currentLexicalNode) {
|
|
198
|
+
lexicalNodes.push(currentLexicalNode);
|
|
187
199
|
}
|
|
188
200
|
}
|
|
189
201
|
|
|
@@ -198,7 +210,7 @@ function $createNodesFromDOM(node, editor, forChildMap = new Map()) {
|
|
|
198
210
|
let childLexicalNodes = [];
|
|
199
211
|
|
|
200
212
|
for (let i = 0; i < children.length; i++) {
|
|
201
|
-
childLexicalNodes.push(...$createNodesFromDOM(children[i], editor, forChildMap));
|
|
213
|
+
childLexicalNodes.push(...$createNodesFromDOM(children[i], editor, forChildMap, currentLexicalNode));
|
|
202
214
|
}
|
|
203
215
|
|
|
204
216
|
if (postTransform != null) {
|
|
@@ -226,10 +238,14 @@ function $generateNodesFromDOM(dom, editor) {
|
|
|
226
238
|
const elementsLength = elements.length;
|
|
227
239
|
|
|
228
240
|
for (let i = 0; i < elementsLength; i++) {
|
|
229
|
-
const
|
|
241
|
+
const element = elements[i];
|
|
230
242
|
|
|
231
|
-
if (
|
|
232
|
-
|
|
243
|
+
if (!IGNORE_TAGS.has(element.nodeName)) {
|
|
244
|
+
const lexicalNode = $createNodesFromDOM(element, editor);
|
|
245
|
+
|
|
246
|
+
if (lexicalNode !== null) {
|
|
247
|
+
lexicalNodes = lexicalNodes.concat(lexicalNode);
|
|
248
|
+
}
|
|
233
249
|
}
|
|
234
250
|
}
|
|
235
251
|
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
* @flow strict
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import type {LexicalEditor, RangeSelection} from 'lexical';
|
|
11
|
+
|
|
12
|
+
/*
|
|
13
|
+
* Rich Text
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
declare export function $insertDataTransferForRichText(
|
|
17
|
+
dataTransfer: DataTransfer,
|
|
18
|
+
selection: RangeSelection,
|
|
19
|
+
editor: LexicalEditor,
|
|
20
|
+
): void;
|
|
21
|
+
|
|
22
|
+
declare export function getHtmlContent(editor: LexicalEditor): string;
|
|
23
|
+
declare export function $getLexicalContent(editor: LexicalEditor): string;
|
|
24
|
+
|
|
25
|
+
/*
|
|
26
|
+
* Plain Text
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
declare export function $insertDataTransferForPlainText(
|
|
30
|
+
dataTransfer: DataTransfer,
|
|
31
|
+
selection: RangeSelection,
|
|
32
|
+
): void;
|
package/LexicalClipboard.prod.js
CHANGED
|
@@ -4,8 +4,8 @@
|
|
|
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 l=require("@lexical/selection"),m=require("lexical");
|
|
8
|
-
function
|
|
9
|
-
exports.$getLexicalContent=function(a){
|
|
10
|
-
exports.$insertDataTransferForRichText=function(a,
|
|
11
|
-
b.length;for(
|
|
7
|
+
var l=require("@lexical/selection"),m=require("lexical");const n=new Set(["STYLE"]);function p(a,d){a=a.getData("text/plain");null!=a&&d.insertRawText(a)}function r(a,d){const {nodeName:h}=a;d=d._htmlConversions.get(h.toLowerCase());let c=null;void 0!==d&&d.forEach(e=>{e=e(a);null!==e&&(null===c||c.priority<e.priority)&&(c=e)});return null!==c?c.conversion:null}
|
|
8
|
+
function t(a,d,h=new Map,c){let e=[];if(n.has(a.nodeName))return e;let b=null;var g=r(a,d);const f=g?g(a):null;g=null;if(null!==f){g=f.after;b=f.node;if(null!==b){for(var [,k]of h)if(b=k(b,c),!b)break;b&&e.push(b)}null!=f.forChild&&h.set(a.nodeName,f.forChild)}a=a.childNodes;c=[];for(k=0;k<a.length;k++)c.push(...t(a[k],d,h,b));null!=g&&(c=g(c));null==b?e=e.concat(c):m.$isElementNode(b)&&b.append(...c);return e}
|
|
9
|
+
exports.$getLexicalContent=function(a){var d=m.$getSelection();return null!==d?(a=a._config.namespace,d=l.$cloneContents(d),JSON.stringify({namespace:a,state:d})):null};exports.$insertDataTransferForPlainText=p;
|
|
10
|
+
exports.$insertDataTransferForRichText=function(a,d,h){var c=a.getData("application/x-lexical-editor");if(c){var e=h._config.namespace;try{const k=JSON.parse(c);if(k.namespace===e){const {range:q,nodeMap:u}=k.state;var b=new Map(u);c=[];for(e=0;e<q.length;e++){var g=b.get(q[e]);if(void 0!==g){var f=m.$createNodeFromParse(g,b);c.push(f)}}d.insertNodes(c);return}}catch(k){}}if(b=a.getData("text/html")){b=(new DOMParser).parseFromString(b,"text/html");a=[];b=b.body?Array.from(b.body.childNodes):[];g=
|
|
11
|
+
b.length;for(f=0;f<g;f++)c=b[f],n.has(c.nodeName)||(c=t(c,h),null!==c&&(a=a.concat(c)));h=a;a=[];b=null;for(g=0;g<h.length;g++)f=h[g],!m.$isElementNode(f)||f.isInline()?(null===b&&(b=m.$createParagraphNode(),a.push(b)),null!==b&&b.append(f)):(a.push(f),b=null);d.insertNodes(a)}else p(a,d)};exports.getHtmlContent=function(){var a=window.getSelection();if(a.isCollapsed)return null;var d=a.getRangeAt(0);return d?(a=document.createElement("div"),d=d.cloneContents(),a.appendChild(d),a.innerHTML):null};
|
package/package.json
CHANGED
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lexical/clipboard",
|
|
3
|
-
"author": {
|
|
4
|
-
"name": "Dominic Gannaway",
|
|
5
|
-
"email": "dg@domgan.com"
|
|
6
|
-
},
|
|
7
3
|
"description": "This package provides the copy/paste functionality for Lexical.",
|
|
8
4
|
"keywords": [
|
|
9
5
|
"lexical",
|
|
@@ -13,14 +9,14 @@
|
|
|
13
9
|
"paste"
|
|
14
10
|
],
|
|
15
11
|
"license": "MIT",
|
|
16
|
-
"version": "0.1.
|
|
12
|
+
"version": "0.1.19",
|
|
17
13
|
"main": "LexicalClipboard.js",
|
|
18
14
|
"peerDependencies": {
|
|
19
|
-
"lexical": "0.1.
|
|
15
|
+
"lexical": "0.1.19"
|
|
20
16
|
},
|
|
21
17
|
"dependencies": {
|
|
22
|
-
"@lexical/utils": "0.1.
|
|
23
|
-
"@lexical/selection": "0.1.
|
|
18
|
+
"@lexical/utils": "0.1.19",
|
|
19
|
+
"@lexical/selection": "0.1.19"
|
|
24
20
|
},
|
|
25
21
|
"repository": {
|
|
26
22
|
"type": "git",
|