@lexical/clipboard 0.26.0 → 0.27.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
CHANGED
|
@@ -21,6 +21,12 @@ var lexical = require('lexical');
|
|
|
21
21
|
*
|
|
22
22
|
*/
|
|
23
23
|
|
|
24
|
+
// Do not require this module directly! Use normal `invariant` calls.
|
|
25
|
+
|
|
26
|
+
function formatDevErrorMessage(message) {
|
|
27
|
+
throw new Error(message);
|
|
28
|
+
}
|
|
29
|
+
|
|
24
30
|
/**
|
|
25
31
|
* Returns the *currently selected* Lexical content as an HTML string, relying on the
|
|
26
32
|
* logic defined in the exportDOM methods on the LexicalNode classes. Note that
|
|
@@ -34,7 +40,7 @@ var lexical = require('lexical');
|
|
|
34
40
|
function $getHtmlContent(editor, selection = lexical.$getSelection()) {
|
|
35
41
|
if (selection == null) {
|
|
36
42
|
{
|
|
37
|
-
|
|
43
|
+
formatDevErrorMessage(`Expected valid LexicalSelection`);
|
|
38
44
|
}
|
|
39
45
|
}
|
|
40
46
|
|
|
@@ -58,7 +64,7 @@ function $getHtmlContent(editor, selection = lexical.$getSelection()) {
|
|
|
58
64
|
function $getLexicalContent(editor, selection = lexical.$getSelection()) {
|
|
59
65
|
if (selection == null) {
|
|
60
66
|
{
|
|
61
|
-
|
|
67
|
+
formatDevErrorMessage(`Expected valid LexicalSelection`);
|
|
62
68
|
}
|
|
63
69
|
}
|
|
64
70
|
|
|
@@ -185,14 +191,14 @@ function exportNodeToJSON(node) {
|
|
|
185
191
|
const nodeClass = node.constructor;
|
|
186
192
|
if (serializedNode.type !== nodeClass.getType()) {
|
|
187
193
|
{
|
|
188
|
-
|
|
194
|
+
formatDevErrorMessage(`LexicalNode: Node ${nodeClass.name} does not implement .exportJSON().`);
|
|
189
195
|
}
|
|
190
196
|
}
|
|
191
197
|
if (lexical.$isElementNode(node)) {
|
|
192
198
|
const serializedChildren = serializedNode.children;
|
|
193
199
|
if (!Array.isArray(serializedChildren)) {
|
|
194
200
|
{
|
|
195
|
-
|
|
201
|
+
formatDevErrorMessage(`LexicalNode: Node ${nodeClass.name} is an element but .exportJSON() does not have a children array.`);
|
|
196
202
|
}
|
|
197
203
|
}
|
|
198
204
|
}
|
package/LexicalClipboard.dev.mjs
CHANGED
|
@@ -19,6 +19,12 @@ import { $isRangeSelection, $getSelection, $createTabNode, SELECTION_INSERT_CLIP
|
|
|
19
19
|
*
|
|
20
20
|
*/
|
|
21
21
|
|
|
22
|
+
// Do not require this module directly! Use normal `invariant` calls.
|
|
23
|
+
|
|
24
|
+
function formatDevErrorMessage(message) {
|
|
25
|
+
throw new Error(message);
|
|
26
|
+
}
|
|
27
|
+
|
|
22
28
|
/**
|
|
23
29
|
* Returns the *currently selected* Lexical content as an HTML string, relying on the
|
|
24
30
|
* logic defined in the exportDOM methods on the LexicalNode classes. Note that
|
|
@@ -32,7 +38,7 @@ import { $isRangeSelection, $getSelection, $createTabNode, SELECTION_INSERT_CLIP
|
|
|
32
38
|
function $getHtmlContent(editor, selection = $getSelection()) {
|
|
33
39
|
if (selection == null) {
|
|
34
40
|
{
|
|
35
|
-
|
|
41
|
+
formatDevErrorMessage(`Expected valid LexicalSelection`);
|
|
36
42
|
}
|
|
37
43
|
}
|
|
38
44
|
|
|
@@ -56,7 +62,7 @@ function $getHtmlContent(editor, selection = $getSelection()) {
|
|
|
56
62
|
function $getLexicalContent(editor, selection = $getSelection()) {
|
|
57
63
|
if (selection == null) {
|
|
58
64
|
{
|
|
59
|
-
|
|
65
|
+
formatDevErrorMessage(`Expected valid LexicalSelection`);
|
|
60
66
|
}
|
|
61
67
|
}
|
|
62
68
|
|
|
@@ -183,14 +189,14 @@ function exportNodeToJSON(node) {
|
|
|
183
189
|
const nodeClass = node.constructor;
|
|
184
190
|
if (serializedNode.type !== nodeClass.getType()) {
|
|
185
191
|
{
|
|
186
|
-
|
|
192
|
+
formatDevErrorMessage(`LexicalNode: Node ${nodeClass.name} does not implement .exportJSON().`);
|
|
187
193
|
}
|
|
188
194
|
}
|
|
189
195
|
if ($isElementNode(node)) {
|
|
190
196
|
const serializedChildren = serializedNode.children;
|
|
191
197
|
if (!Array.isArray(serializedChildren)) {
|
|
192
198
|
{
|
|
193
|
-
|
|
199
|
+
formatDevErrorMessage(`LexicalNode: Node ${nodeClass.name} is an element but .exportJSON() does not have a children array.`);
|
|
194
200
|
}
|
|
195
201
|
}
|
|
196
202
|
}
|
package/LexicalClipboard.prod.js
CHANGED
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
"use strict";var e=require("@lexical/html"),t=require("@lexical/selection"),n=require("@lexical/utils"),o=require("lexical");function r(e){
|
|
9
|
+
"use strict";var e=require("@lexical/html"),t=require("@lexical/selection"),n=require("@lexical/utils"),o=require("lexical");function r(e,...t){const n=new URL("https://lexical.dev/docs/error"),o=new URLSearchParams;o.append("code",e);for(const e of t)o.append("v",e);throw n.search=o.toString(),Error(`Minified Lexical error #${e}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}function i(t,n=o.$getSelection()){return null==n&&r(166),o.$isRangeSelection(n)&&n.isCollapsed()||0===n.getNodes().length?"":e.$generateHtmlFromNodes(t,n)}function l(e,t=o.$getSelection()){return null==t&&r(166),o.$isRangeSelection(t)&&t.isCollapsed()||0===t.getNodes().length?null:JSON.stringify(c(e,t))}function s(e,t,n){e.dispatchCommand(o.SELECTION_INSERT_CLIPBOARD_NODES_COMMAND,{nodes:t,selection:n})||n.insertNodes(t)}function a(e,n,i,l=[]){let s=null===n||i.isSelected(n);const c=o.$isElementNode(i)&&i.excludeFromCopy("html");let d=i;if(null!==n){let e=o.$cloneWithProperties(i);e=o.$isTextNode(e)&&null!==n?t.$sliceSelectedTextNodeContent(n,e):e,d=e}const u=o.$isElementNode(d)?d.getChildren():[],p=function(e){const t=e.exportJSON(),n=e.constructor;if(t.type!==n.getType()&&r(58,n.name),o.$isElementNode(e)){const e=t.children;Array.isArray(e)||r(59,n.name)}return t}(d);if(o.$isTextNode(d)){const e=d.__text;e.length>0?p.text=e:s=!1}for(let t=0;t<u.length;t++){const r=u[t],l=a(e,n,r,p.children);!s&&o.$isElementNode(i)&&l&&i.extractWithChild(r,n,"clone")&&(s=!0)}if(s&&!c)l.push(p);else if(Array.isArray(p.children))for(let e=0;e<p.children.length;e++){const t=p.children[e];l.push(t)}return s}function c(e,t){const n=[],r=o.$getRoot().getChildren();for(let o=0;o<r.length;o++){a(e,t,r[o],n)}return{namespace:e._config.namespace,nodes:n}}function d(e){const n=[];for(let r=0;r<e.length;r++){const i=e[r],l=o.$parseSerializedNode(i);o.$isTextNode(l)&&t.$addNodeStyle(l),n.push(l)}return n}let u=null;function p(e,t,n){if(void 0===n){const t=o.getDOMSelection(e._window);if(!t)return!1;const r=t.anchorNode,i=t.focusNode;if(null!==r&&null!==i&&!o.isSelectionWithinEditor(e,r,i))return!1;const l=o.$getSelection();if(null===l)return!1;n=g(l)}t.preventDefault();const r=t.clipboardData;return null!==r&&(x(r,n),!0)}const f=[["text/html",i],["application/x-lexical-editor",l]];function g(e=o.$getSelection()){const t={"text/plain":e?e.getTextContent():""};if(e){const n=o.$getEditor();for(const[o,r]of f){const i=r(n,e);null!==i&&(t[o]=i)}}return t}function x(e,t){for(const n in t){const o=t[n];void 0!==o&&e.setData(n,o)}}exports.$generateJSONFromSelectedNodes=c,exports.$generateNodesFromSerializedNodes=d,exports.$getClipboardDataFromSelection=g,exports.$getHtmlContent=i,exports.$getLexicalContent=l,exports.$insertDataTransferForPlainText=function(e,t){const n=e.getData("text/plain")||e.getData("text/uri-list");null!=n&&t.insertRawText(n)},exports.$insertDataTransferForRichText=function(t,n,r){const i=t.getData("application/x-lexical-editor");if(i)try{const e=JSON.parse(i);if(e.namespace===r._config.namespace&&Array.isArray(e.nodes)){return s(r,d(e.nodes),n)}}catch(e){}const l=t.getData("text/html"),a=t.getData("text/plain");if(l&&a!==l)try{const t=(new DOMParser).parseFromString(function(e){if(window.trustedTypes&&window.trustedTypes.createPolicy){return window.trustedTypes.createPolicy("lexical",{createHTML:e=>e}).createHTML(e)}return e}(l),"text/html");return s(r,e.$generateNodesFromDOM(r,t),n)}catch(e){}const c=a||t.getData("text/uri-list");if(null!=c)if(o.$isRangeSelection(n)){const e=c.split(/(\r?\n|\t)/);""===e[e.length-1]&&e.pop();for(let t=0;t<e.length;t++){const n=o.$getSelection();if(o.$isRangeSelection(n)){const r=e[t];"\n"===r||"\r\n"===r?n.insertParagraph():"\t"===r?n.insertNodes([o.$createTabNode()]):n.insertText(r)}}}else n.insertRawText(c)},exports.$insertGeneratedNodes=s,exports.copyToClipboard=async function(e,t,r){if(null!==u)return!1;if(null!==t)return new Promise(((n,o)=>{e.update((()=>{n(p(e,t,r))}))}));const i=e.getRootElement(),l=e._window||window,s=window.document,a=o.getDOMSelection(l);if(null===i||null===a)return!1;const c=s.createElement("span");c.style.cssText="position: fixed; top: -1000px;",c.append(s.createTextNode("#")),i.append(c);const d=new Range;return d.setStart(c,0),d.setEnd(c,1),a.removeAllRanges(),a.addRange(d),new Promise(((t,i)=>{const l=e.registerCommand(o.COPY_COMMAND,(o=>(n.objectKlassEquals(o,ClipboardEvent)&&(l(),null!==u&&(window.clearTimeout(u),u=null),t(p(e,o,r))),!0)),o.COMMAND_PRIORITY_CRITICAL);u=window.setTimeout((()=>{l(),u=null,t(!1)}),50),s.execCommand("copy"),c.remove()}))},exports.setLexicalClipboardDataTransfer=x;
|
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import{$generateHtmlFromNodes as t,$generateNodesFromDOM as e}from"@lexical/html";import{$addNodeStyle as n,$sliceSelectedTextNodeContent as
|
|
9
|
+
import{$generateHtmlFromNodes as t,$generateNodesFromDOM as e}from"@lexical/html";import{$addNodeStyle as n,$sliceSelectedTextNodeContent as o}from"@lexical/selection";import{objectKlassEquals as r}from"@lexical/utils";import{$isRangeSelection as i,$getSelection as l,$createTabNode as s,SELECTION_INSERT_CLIPBOARD_NODES_COMMAND as c,$getRoot as a,$parseSerializedNode as u,$isTextNode as d,getDOMSelection as f,COPY_COMMAND as p,COMMAND_PRIORITY_CRITICAL as m,isSelectionWithinEditor as h,$getEditor as g,$isElementNode as x,$cloneWithProperties as w}from"lexical";function y(t,...e){const n=new URL("https://lexical.dev/docs/error"),o=new URLSearchParams;o.append("code",t);for(const t of e)o.append("v",t);throw n.search=o.toString(),Error(`Minified Lexical error #${t}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}function T(e,n=l()){return null==n&&y(166),i(n)&&n.isCollapsed()||0===n.getNodes().length?"":t(e,n)}function v(t,e=l()){return null==e&&y(166),i(e)&&e.isCollapsed()||0===e.getNodes().length?null:JSON.stringify(R(t,e))}function C(t,e){const n=t.getData("text/plain")||t.getData("text/uri-list");null!=n&&e.insertRawText(n)}function D(t,n,o){const r=t.getData("application/x-lexical-editor");if(r)try{const t=JSON.parse(r);if(t.namespace===o._config.namespace&&Array.isArray(t.nodes)){return N(o,A(t.nodes),n)}}catch(t){}const c=t.getData("text/html"),a=t.getData("text/plain");if(c&&a!==c)try{const t=(new DOMParser).parseFromString(function(t){if(window.trustedTypes&&window.trustedTypes.createPolicy){return window.trustedTypes.createPolicy("lexical",{createHTML:t=>t}).createHTML(t)}return t}(c),"text/html");return N(o,e(o,t),n)}catch(t){}const u=a||t.getData("text/uri-list");if(null!=u)if(i(n)){const t=u.split(/(\r?\n|\t)/);""===t[t.length-1]&&t.pop();for(let e=0;e<t.length;e++){const n=l();if(i(n)){const o=t[e];"\n"===o||"\r\n"===o?n.insertParagraph():"\t"===o?n.insertNodes([s()]):n.insertText(o)}}}else n.insertRawText(u)}function N(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 l=x(n)&&n.excludeFromCopy("html");let s=n;if(null!==e){let t=w(n);t=d(t)&&null!==e?o(e,t):t,s=t}const c=x(s)?s.getChildren():[],a=function(t){const e=t.exportJSON(),n=t.constructor;if(e.type!==n.getType()&&y(58,n.name),x(t)){const t=e.children;Array.isArray(t)||y(59,n.name)}return e}(s);if(d(s)){const t=s.__text;t.length>0?a.text=t:i=!1}for(let o=0;o<c.length;o++){const r=c[o],l=S(t,e,r,a.children);!i&&x(n)&&l&&n.extractWithChild(r,e,"clone")&&(i=!0)}if(i&&!l)r.push(a);else if(Array.isArray(a.children))for(let t=0;t<a.children.length;t++){const e=a.children[t];r.push(e)}return i}function R(t,e){const n=[],o=a().getChildren();for(let r=0;r<o.length;r++){S(t,e,o[r],n)}return{namespace:t._config.namespace,nodes:n}}function A(t){const e=[];for(let o=0;o<t.length;o++){const r=t[o],i=u(r);d(i)&&n(i),e.push(i)}return e}let P=null;async function _(t,e,n){if(null!==P)return!1;if(null!==e)return new Promise(((o,r)=>{t.update((()=>{o(E(t,e,n))}))}));const o=t.getRootElement(),i=t._window||window,l=window.document,s=f(i);if(null===o||null===s)return!1;const c=l.createElement("span");c.style.cssText="position: fixed; top: -1000px;",c.append(l.createTextNode("#")),o.append(c);const a=new Range;return a.setStart(c,0),a.setEnd(c,1),s.removeAllRanges(),s.addRange(a),new Promise(((e,o)=>{const i=t.registerCommand(p,(o=>(r(o,ClipboardEvent)&&(i(),null!==P&&(window.clearTimeout(P),P=null),e(E(t,o,n))),!0)),m);P=window.setTimeout((()=>{i(),P=null,e(!1)}),50),l.execCommand("copy"),c.remove()}))}function E(t,e,n){if(void 0===n){const e=f(t._window);if(!e)return!1;const o=e.anchorNode,r=e.focusNode;if(null!==o&&null!==r&&!h(t,o,r))return!1;const i=l();if(null===i)return!1;n=M(i)}e.preventDefault();const o=e.clipboardData;return null!==o&&(O(o,n),!0)}const L=[["text/html",T],["application/x-lexical-editor",v]];function M(t=l()){const e={"text/plain":t?t.getTextContent():""};if(t){const n=g();for(const[o,r]of L){const i=r(n,t);null!==i&&(e[o]=i)}}return e}function O(t,e){for(const n in e){const o=e[n];void 0!==o&&t.setData(n,o)}}export{R as $generateJSONFromSelectedNodes,A as $generateNodesFromSerializedNodes,M as $getClipboardDataFromSelection,T as $getHtmlContent,v as $getLexicalContent,C as $insertDataTransferForPlainText,D as $insertDataTransferForRichText,N as $insertGeneratedNodes,_ as copyToClipboard,O as setLexicalClipboardDataTransfer};
|
package/package.json
CHANGED
|
@@ -9,15 +9,15 @@
|
|
|
9
9
|
"paste"
|
|
10
10
|
],
|
|
11
11
|
"license": "MIT",
|
|
12
|
-
"version": "0.
|
|
12
|
+
"version": "0.27.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.27.0",
|
|
17
|
+
"@lexical/list": "0.27.0",
|
|
18
|
+
"@lexical/selection": "0.27.0",
|
|
19
|
+
"@lexical/utils": "0.27.0",
|
|
20
|
+
"lexical": "0.27.0"
|
|
21
21
|
},
|
|
22
22
|
"repository": {
|
|
23
23
|
"type": "git",
|