@lexical/clipboard 0.14.5 → 0.16.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 +13 -7
- package/LexicalClipboard.dev.mjs +13 -7
- package/LexicalClipboard.js +2 -0
- package/LexicalClipboard.mjs +2 -0
- package/LexicalClipboard.node.mjs +2 -0
- package/LexicalClipboard.prod.js +13 -11
- package/LexicalClipboard.prod.mjs +3 -1
- package/package.json +6 -6
package/LexicalClipboard.dev.js
CHANGED
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
*
|
|
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
|
*/
|
|
8
|
+
|
|
7
9
|
'use strict';
|
|
8
10
|
|
|
9
11
|
var html = require('@lexical/html');
|
|
@@ -28,6 +30,7 @@ const CAN_USE_DOM = typeof window !== 'undefined' && typeof window.document !==
|
|
|
28
30
|
* LICENSE file in the root directory of this source tree.
|
|
29
31
|
*
|
|
30
32
|
*/
|
|
33
|
+
|
|
31
34
|
const getDOMSelection = targetWindow => CAN_USE_DOM ? (targetWindow || window).getSelection() : null;
|
|
32
35
|
|
|
33
36
|
/**
|
|
@@ -138,13 +141,16 @@ function $insertDataTransferForRichText(dataTransfer, selection, editor) {
|
|
|
138
141
|
parts.pop();
|
|
139
142
|
}
|
|
140
143
|
for (let i = 0; i < parts.length; i++) {
|
|
141
|
-
const
|
|
142
|
-
if (
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
144
|
+
const currentSelection = lexical.$getSelection();
|
|
145
|
+
if (lexical.$isRangeSelection(currentSelection)) {
|
|
146
|
+
const part = parts[i];
|
|
147
|
+
if (part === '\n' || part === '\r\n') {
|
|
148
|
+
currentSelection.insertParagraph();
|
|
149
|
+
} else if (part === '\t') {
|
|
150
|
+
currentSelection.insertNodes([lexical.$createTabNode()]);
|
|
151
|
+
} else {
|
|
152
|
+
currentSelection.insertText(part);
|
|
153
|
+
}
|
|
148
154
|
}
|
|
149
155
|
}
|
|
150
156
|
} else {
|
package/LexicalClipboard.dev.mjs
CHANGED
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
*
|
|
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
|
*/
|
|
8
|
+
|
|
7
9
|
import { $generateHtmlFromNodes, $generateNodesFromDOM } from '@lexical/html';
|
|
8
10
|
import { $addNodeStyle, $cloneWithProperties, $sliceSelectedTextNodeContent } from '@lexical/selection';
|
|
9
11
|
import { objectKlassEquals } from '@lexical/utils';
|
|
@@ -26,6 +28,7 @@ const CAN_USE_DOM = typeof window !== 'undefined' && typeof window.document !==
|
|
|
26
28
|
* LICENSE file in the root directory of this source tree.
|
|
27
29
|
*
|
|
28
30
|
*/
|
|
31
|
+
|
|
29
32
|
const getDOMSelection = targetWindow => CAN_USE_DOM ? (targetWindow || window).getSelection() : null;
|
|
30
33
|
|
|
31
34
|
/**
|
|
@@ -136,13 +139,16 @@ function $insertDataTransferForRichText(dataTransfer, selection, editor) {
|
|
|
136
139
|
parts.pop();
|
|
137
140
|
}
|
|
138
141
|
for (let i = 0; i < parts.length; i++) {
|
|
139
|
-
const
|
|
140
|
-
if (
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
142
|
+
const currentSelection = $getSelection();
|
|
143
|
+
if ($isRangeSelection(currentSelection)) {
|
|
144
|
+
const part = parts[i];
|
|
145
|
+
if (part === '\n' || part === '\r\n') {
|
|
146
|
+
currentSelection.insertParagraph();
|
|
147
|
+
} else if (part === '\t') {
|
|
148
|
+
currentSelection.insertNodes([$createTabNode()]);
|
|
149
|
+
} else {
|
|
150
|
+
currentSelection.insertText(part);
|
|
151
|
+
}
|
|
146
152
|
}
|
|
147
153
|
}
|
|
148
154
|
} else {
|
package/LexicalClipboard.js
CHANGED
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
*
|
|
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
|
*/
|
|
8
|
+
|
|
7
9
|
'use strict'
|
|
8
10
|
const LexicalClipboard = process.env.NODE_ENV === 'development' ? require('./LexicalClipboard.dev.js') : require('./LexicalClipboard.prod.js');
|
|
9
11
|
module.exports = LexicalClipboard;
|
package/LexicalClipboard.mjs
CHANGED
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
*
|
|
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
|
*/
|
|
8
|
+
|
|
7
9
|
import * as modDev from './LexicalClipboard.dev.mjs';
|
|
8
10
|
import * as modProd from './LexicalClipboard.prod.mjs';
|
|
9
11
|
const mod = process.env.NODE_ENV === 'development' ? modDev : modProd;
|
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
*
|
|
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
|
*/
|
|
8
|
+
|
|
7
9
|
const mod = await (process.env.NODE_ENV === 'development' ? import('./LexicalClipboard.dev.mjs') : import('./LexicalClipboard.prod.mjs'));
|
|
8
10
|
export const $generateJSONFromSelectedNodes = mod.$generateJSONFromSelectedNodes;
|
|
9
11
|
export const $generateNodesFromSerializedNodes = mod.$generateNodesFromSerializedNodes;
|
package/LexicalClipboard.prod.js
CHANGED
|
@@ -3,15 +3,17 @@
|
|
|
3
3
|
*
|
|
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
|
*/
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
function w(a){let b=
|
|
10
|
-
function
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
exports.$
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
8
|
+
|
|
9
|
+
'use strict';var f=require("@lexical/html"),m=require("@lexical/selection"),n=require("@lexical/utils"),p=require("lexical"),t;function u(a){let b=new URLSearchParams;b.append("code",a);for(let c=1;c<arguments.length;c++)b.append("v",arguments[c]);throw Error(`Minified Lexical error #${a}; visit https://lexical.dev/docs/error?${b} for the full message or `+"use the non-minified dev environment for full errors and additional helpful warnings.");}
|
|
10
|
+
t=u&&u.__esModule&&Object.prototype.hasOwnProperty.call(u,"default")?u["default"]:u;let v="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement;function w(a){let b=p.$getSelection();null==b&&t(166);return p.$isRangeSelection(b)&&b.isCollapsed()||0===b.getNodes().length?"":f.$generateHtmlFromNodes(a,b)}
|
|
11
|
+
function x(a){let b=p.$getSelection();null==b&&t(166);return p.$isRangeSelection(b)&&b.isCollapsed()||0===b.getNodes().length?null:JSON.stringify(y(a,b))}function z(a,b,c){a.dispatchCommand(p.SELECTION_INSERT_CLIPBOARD_NODES_COMMAND,{nodes:b,selection:c})||c.insertNodes(b)}
|
|
12
|
+
function A(a,b,c,d=[]){let e=null!==b?c.isSelected(b):!0,h=p.$isElementNode(c)&&c.excludeFromCopy("html");var g=c;if(null!==b){var k=m.$cloneWithProperties(c);g=k=p.$isTextNode(k)&&null!==b?m.$sliceSelectedTextNodeContent(b,k):k}let q=p.$isElementNode(g)?g.getChildren():[];var l=g;k=l.exportJSON();var r=l.constructor;k.type!==r.getType()&&t(58,r.name);p.$isElementNode(l)&&(Array.isArray(k.children)||t(59,r.name));p.$isTextNode(g)&&(g=g.__text,0<g.length?k.text=g:e=!1);for(g=0;g<q.length;g++)l=q[g],
|
|
13
|
+
r=A(a,b,l,k.children),!e&&p.$isElementNode(c)&&r&&c.extractWithChild(l,b,"clone")&&(e=!0);if(e&&!h)d.push(k);else if(Array.isArray(k.children))for(a=0;a<k.children.length;a++)d.push(k.children[a]);return e}function y(a,b){let c=[],d=p.$getRoot().getChildren();for(let e=0;e<d.length;e++)A(a,b,d[e],c);return{namespace:a._config.namespace,nodes:c}}function B(a){let b=[];for(let c=0;c<a.length;c++){let d=p.$parseSerializedNode(a[c]);p.$isTextNode(d)&&m.$addNodeStyle(d);b.push(d)}return b}let C=null;
|
|
14
|
+
function D(a,b){var c=v?(a._window||window).getSelection():null;if(!c)return!1;var d=c.anchorNode;c=c.focusNode;if(null!==d&&null!==c&&!p.isSelectionWithinEditor(a,d,c))return!1;b.preventDefault();b=b.clipboardData;d=p.$getSelection();if(null===b||null===d)return!1;c=w(a);a=x(a);let e="";null!==d&&(e=d.getTextContent());null!==c&&b.setData("text/html",c);null!==a&&b.setData("application/x-lexical-editor",a);b.setData("text/plain",e);return!0}exports.$generateJSONFromSelectedNodes=y;
|
|
15
|
+
exports.$generateNodesFromSerializedNodes=B;exports.$getHtmlContent=w;exports.$getLexicalContent=x;exports.$insertDataTransferForPlainText=function(a,b){a=a.getData("text/plain")||a.getData("text/uri-list");null!=a&&b.insertRawText(a)};
|
|
16
|
+
exports.$insertDataTransferForRichText=function(a,b,c){var d=a.getData("application/x-lexical-editor");if(d)try{let h=JSON.parse(d);if(h.namespace===c._config.namespace&&Array.isArray(h.nodes)){let g=B(h.nodes);return z(c,g,b)}}catch(h){}if(d=a.getData("text/html"))try{var e=(new DOMParser).parseFromString(d,"text/html");let h=f.$generateNodesFromDOM(c,e);return z(c,h,b)}catch(h){}a=a.getData("text/plain")||a.getData("text/uri-list");if(null!=a)if(p.$isRangeSelection(b))for(b=a.split(/(\r?\n|\t)/),
|
|
17
|
+
""===b[b.length-1]&&b.pop(),a=0;a<b.length;a++)c=p.$getSelection(),p.$isRangeSelection(c)&&(e=b[a],"\n"===e||"\r\n"===e?c.insertParagraph():"\t"===e?c.insertNodes([p.$createTabNode()]):c.insertText(e));else b.insertRawText(a)};exports.$insertGeneratedNodes=z;
|
|
18
|
+
exports.copyToClipboard=async function(a,b){if(null!==C)return!1;if(null!==b)return new Promise(g=>{a.update(()=>{g(D(a,b))})});var c=a.getRootElement();let d=null==a._window?window.document:a._window.document,e=v?(a._window||window).getSelection():null;if(null===c||null===e)return!1;let h=d.createElement("span");h.style.cssText="position: fixed; top: -1000px;";h.append(d.createTextNode("#"));c.append(h);c=new Range;c.setStart(h,0);c.setEnd(h,1);e.removeAllRanges();e.addRange(c);return new Promise(g=>
|
|
19
|
+
{let k=a.registerCommand(p.COPY_COMMAND,q=>{n.objectKlassEquals(q,ClipboardEvent)&&(k(),null!==C&&(window.clearTimeout(C),C=null),g(D(a,q)));return!0},p.COMMAND_PRIORITY_CRITICAL);C=window.setTimeout(()=>{k();C=null;g(!1)},50);d.execCommand("copy");h.remove()})}
|
|
@@ -3,5 +3,7 @@
|
|
|
3
3
|
*
|
|
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
|
*/
|
|
7
|
-
|
|
8
|
+
|
|
9
|
+
import{$generateHtmlFromNodes as t,$generateNodesFromDOM as e}from"@lexical/html";import{$addNodeStyle as n,$cloneWithProperties as o,$sliceSelectedTextNodeContent as l}from"@lexical/selection";import{objectKlassEquals as r}from"@lexical/utils";import{$getSelection as i,$isRangeSelection as s,$createTabNode as a,SELECTION_INSERT_CLIPBOARD_NODES_COMMAND as c,$getRoot as u,$parseSerializedNode as d,$isTextNode as f,COPY_COMMAND as p,COMMAND_PRIORITY_CRITICAL as m,isSelectionWithinEditor as h,$isElementNode as g}from"lexical";function x(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var w=x((function(t){const e=new URLSearchParams;e.append("code",t);for(let t=1;t<arguments.length;t++)e.append("v",arguments[t]);throw Error(`Minified Lexical error #${t}; visit https://lexical.dev/docs/error?${e} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}));const y="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement,v=t=>y?(t||window).getSelection():null;function D(e){const n=i();return null==n&&w(166),s(n)&&n.isCollapsed()||0===n.getNodes().length?"":t(e,n)}function C(t){const e=i();return null==e&&w(166),s(e)&&e.isCollapsed()||0===e.getNodes().length?null:JSON.stringify(A(t,e))}function N(t,e){const n=t.getData("text/plain")||t.getData("text/uri-list");null!=n&&e.insertRawText(n)}function _(t,n,o){const l=t.getData("application/x-lexical-editor");if(l)try{const t=JSON.parse(l);if(t.namespace===o._config.namespace&&Array.isArray(t.nodes)){return T(o,R(t.nodes),n)}}catch(t){}const r=t.getData("text/html");if(r)try{const t=(new DOMParser).parseFromString(r,"text/html");return T(o,e(o,t),n)}catch(t){}const c=t.getData("text/plain")||t.getData("text/uri-list");if(null!=c)if(s(n)){const t=c.split(/(\r?\n|\t)/);""===t[t.length-1]&&t.pop();for(let e=0;e<t.length;e++){const n=i();if(s(n)){const o=t[e];"\n"===o||"\r\n"===o?n.insertParagraph():"\t"===o?n.insertNodes([a()]):n.insertText(o)}}}else n.insertRawText(c)}function T(t,e,n){t.dispatchCommand(c,{nodes:e,selection:n})||n.insertNodes(e)}function S(t,e,n,r=[]){let i=null===e||n.isSelected(e);const s=g(n)&&n.excludeFromCopy("html");let a=n;if(null!==e){let t=o(n);t=f(t)&&null!==e?l(e,t):t,a=t}const c=g(a)?a.getChildren():[],u=function(t){const e=t.exportJSON(),n=t.constructor;if(e.type!==n.getType()&&w(58,n.name),g(t)){const t=e.children;Array.isArray(t)||w(59,n.name)}return e}(a);if(f(a)){const t=a.__text;t.length>0?u.text=t:i=!1}for(let o=0;o<c.length;o++){const l=c[o],r=S(t,e,l,u.children);!i&&g(n)&&r&&n.extractWithChild(l,e,"clone")&&(i=!0)}if(i&&!s)r.push(u);else if(Array.isArray(u.children))for(let t=0;t<u.children.length;t++){const e=u.children[t];r.push(e)}return i}function A(t,e){const n=[],o=u().getChildren();for(let l=0;l<o.length;l++){S(t,e,o[l],n)}return{namespace:t._config.namespace,nodes:n}}function R(t){const e=[];for(let o=0;o<t.length;o++){const l=t[o],r=d(l);f(r)&&n(r),e.push(r)}return e}let E=null;async function O(t,e){if(null!==E)return!1;if(null!==e)return new Promise(((n,o)=>{t.update((()=>{n(P(t,e))}))}));const n=t.getRootElement(),o=null==t._window?window.document:t._window.document,l=v(t._window);if(null===n||null===l)return!1;const i=o.createElement("span");i.style.cssText="position: fixed; top: -1000px;",i.append(o.createTextNode("#")),n.append(i);const s=new Range;return s.setStart(i,0),s.setEnd(i,1),l.removeAllRanges(),l.addRange(s),new Promise(((e,n)=>{const l=t.registerCommand(p,(n=>(r(n,ClipboardEvent)&&(l(),null!==E&&(window.clearTimeout(E),E=null),e(P(t,n))),!0)),m);E=window.setTimeout((()=>{l(),E=null,e(!1)}),50),o.execCommand("copy"),i.remove()}))}function P(t,e){const n=v(t._window);if(!n)return!1;const o=n.anchorNode,l=n.focusNode;if(null!==o&&null!==l&&!h(t,o,l))return!1;e.preventDefault();const r=e.clipboardData,s=i();if(null===r||null===s)return!1;const a=D(t),c=C(t);let u="";return null!==s&&(u=s.getTextContent()),null!==a&&r.setData("text/html",a),null!==c&&r.setData("application/x-lexical-editor",c),r.setData("text/plain",u),!0}export{A as $generateJSONFromSelectedNodes,R as $generateNodesFromSerializedNodes,D as $getHtmlContent,C as $getLexicalContent,N as $insertDataTransferForPlainText,_ as $insertDataTransferForRichText,T as $insertGeneratedNodes,O as copyToClipboard};
|
package/package.json
CHANGED
|
@@ -9,15 +9,15 @@
|
|
|
9
9
|
"paste"
|
|
10
10
|
],
|
|
11
11
|
"license": "MIT",
|
|
12
|
-
"version": "0.
|
|
12
|
+
"version": "0.16.0",
|
|
13
13
|
"main": "LexicalClipboard.js",
|
|
14
14
|
"types": "index.d.ts",
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@lexical/html": "0.
|
|
17
|
-
"@lexical/list": "0.
|
|
18
|
-
"@lexical/selection": "0.
|
|
19
|
-
"@lexical/utils": "0.
|
|
20
|
-
"lexical": "0.
|
|
16
|
+
"@lexical/html": "0.16.0",
|
|
17
|
+
"@lexical/list": "0.16.0",
|
|
18
|
+
"@lexical/selection": "0.16.0",
|
|
19
|
+
"@lexical/utils": "0.16.0",
|
|
20
|
+
"lexical": "0.16.0"
|
|
21
21
|
},
|
|
22
22
|
"repository": {
|
|
23
23
|
"type": "git",
|