@lexical/clipboard 0.37.1-nightly.20251023.0 → 0.37.1-nightly.20251027.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
|
@@ -108,8 +108,9 @@ function $insertDataTransferForRichText(dataTransfer, selection, editor) {
|
|
|
108
108
|
const nodes = $generateNodesFromSerializedNodes(payload.nodes);
|
|
109
109
|
return $insertGeneratedNodes(editor, nodes, selection);
|
|
110
110
|
}
|
|
111
|
-
} catch (
|
|
112
|
-
//
|
|
111
|
+
} catch (error) {
|
|
112
|
+
// eslint-disable-next-line no-console
|
|
113
|
+
console.error(error);
|
|
113
114
|
}
|
|
114
115
|
}
|
|
115
116
|
const htmlString = dataTransfer.getData('text/html');
|
|
@@ -124,8 +125,9 @@ function $insertDataTransferForRichText(dataTransfer, selection, editor) {
|
|
|
124
125
|
const dom = parser.parseFromString(trustHTML(htmlString), 'text/html');
|
|
125
126
|
const nodes = html.$generateNodesFromDOM(editor, dom);
|
|
126
127
|
return $insertGeneratedNodes(editor, nodes, selection);
|
|
127
|
-
} catch (
|
|
128
|
-
//
|
|
128
|
+
} catch (error) {
|
|
129
|
+
// eslint-disable-next-line no-console
|
|
130
|
+
console.error(error);
|
|
129
131
|
}
|
|
130
132
|
}
|
|
131
133
|
|
package/LexicalClipboard.dev.mjs
CHANGED
|
@@ -106,8 +106,9 @@ function $insertDataTransferForRichText(dataTransfer, selection, editor) {
|
|
|
106
106
|
const nodes = $generateNodesFromSerializedNodes(payload.nodes);
|
|
107
107
|
return $insertGeneratedNodes(editor, nodes, selection);
|
|
108
108
|
}
|
|
109
|
-
} catch (
|
|
110
|
-
//
|
|
109
|
+
} catch (error) {
|
|
110
|
+
// eslint-disable-next-line no-console
|
|
111
|
+
console.error(error);
|
|
111
112
|
}
|
|
112
113
|
}
|
|
113
114
|
const htmlString = dataTransfer.getData('text/html');
|
|
@@ -122,8 +123,9 @@ function $insertDataTransferForRichText(dataTransfer, selection, editor) {
|
|
|
122
123
|
const dom = parser.parseFromString(trustHTML(htmlString), 'text/html');
|
|
123
124
|
const nodes = $generateNodesFromDOM(editor, dom);
|
|
124
125
|
return $insertGeneratedNodes(editor, nodes, selection);
|
|
125
|
-
} catch (
|
|
126
|
-
//
|
|
126
|
+
} catch (error) {
|
|
127
|
+
// eslint-disable-next-line no-console
|
|
128
|
+
console.error(error);
|
|
127
129
|
}
|
|
128
130
|
}
|
|
129
131
|
|
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,...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(e){if(o.$isRangeSelection(e)&&e.isCollapsed()){const t=e.anchor;let n=null;const r=o.$caretFromPoint(t,"previous");if(r)if(o.$isTextPointCaret(r))n=r.origin;else{const e=o.$getCaretRange(r,o.$getChildCaret(o.$getRoot(),"next").getFlipped());for(const t of e){if(o.$isTextNode(t.origin)){n=t.origin;break}if(o.$isElementNode(t.origin)&&!t.origin.isInline())break}}if(n&&o.$isTextNode(n)){const t=n.getFormat(),o=n.getStyle();e.format===t&&e.style===o||(e.format=t,e.style=o,e.dirty=!0)}}}(n))}function a(e,n,i,l=[]){let s=null===n||i.isSelected(n);const c=o.$isElementNode(i)&&i.excludeFromCopy("html");let d=i;null!==n&&o.$isTextNode(d)&&(d=t.$sliceSelectedTextNodeContent(n,d,"clone"));const u=o.$isElementNode(d)?d.getChildren():[],f=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);o.$isTextNode(d)&&0===d.getTextContentSize()&&(s=!1);for(let t=0;t<u.length;t++){const r=u[t],l=a(e,n,r,f.children);!s&&o.$isElementNode(i)&&l&&i.extractWithChild(r,n,"clone")&&(s=!0)}if(s&&!c)l.push(f);else if(Array.isArray(f.children))for(let e=0;e<f.children.length;e++){const t=f.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 f(e,t,n){if(void 0===n){const t=o.getDOMSelection(e._window),r=o.$getSelection();if(!r||r.isCollapsed())return!1;if(!t)return!1;const i=t.anchorNode,l=t.focusNode;if(null!==i&&null!==l&&!o.isSelectionWithinEditor(e,i,l))return!1;n=g(r)}t.preventDefault();const r=t.clipboardData;return null!==r&&(x(r,n),!0)}const p=[["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 p){const i=r(n,e);null!==i&&(t[o]=i)}}return t}function x(e,t){for(const[n]of p)void 0===t[n]&&e.setData(n,"");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(f(e,t,r))})});const i=e.getRootElement(),l=e._window||window,s=l.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 a=e.registerCommand(o.COPY_COMMAND,o=>(n.objectKlassEquals(o,ClipboardEvent)&&(a(),null!==u&&(l.clearTimeout(u),u=null),t(f(e,o,r))),!0),o.COMMAND_PRIORITY_CRITICAL);u=l.setTimeout(()=>{a(),u=null,t(!1)},50),s.execCommand("copy"),c.remove()})},exports.setLexicalClipboardDataTransfer=x;
|
|
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(e){if(o.$isRangeSelection(e)&&e.isCollapsed()){const t=e.anchor;let n=null;const r=o.$caretFromPoint(t,"previous");if(r)if(o.$isTextPointCaret(r))n=r.origin;else{const e=o.$getCaretRange(r,o.$getChildCaret(o.$getRoot(),"next").getFlipped());for(const t of e){if(o.$isTextNode(t.origin)){n=t.origin;break}if(o.$isElementNode(t.origin)&&!t.origin.isInline())break}}if(n&&o.$isTextNode(n)){const t=n.getFormat(),o=n.getStyle();e.format===t&&e.style===o||(e.format=t,e.style=o,e.dirty=!0)}}}(n))}function a(e,n,i,l=[]){let s=null===n||i.isSelected(n);const c=o.$isElementNode(i)&&i.excludeFromCopy("html");let d=i;null!==n&&o.$isTextNode(d)&&(d=t.$sliceSelectedTextNodeContent(n,d,"clone"));const u=o.$isElementNode(d)?d.getChildren():[],f=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);o.$isTextNode(d)&&0===d.getTextContentSize()&&(s=!1);for(let t=0;t<u.length;t++){const r=u[t],l=a(e,n,r,f.children);!s&&o.$isElementNode(i)&&l&&i.extractWithChild(r,n,"clone")&&(s=!0)}if(s&&!c)l.push(f);else if(Array.isArray(f.children))for(let e=0;e<f.children.length;e++){const t=f.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 f(e,t,n){if(void 0===n){const t=o.getDOMSelection(e._window),r=o.$getSelection();if(!r||r.isCollapsed())return!1;if(!t)return!1;const i=t.anchorNode,l=t.focusNode;if(null!==i&&null!==l&&!o.isSelectionWithinEditor(e,i,l))return!1;n=g(r)}t.preventDefault();const r=t.clipboardData;return null!==r&&(x(r,n),!0)}const p=[["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 p){const i=r(n,e);null!==i&&(t[o]=i)}}return t}function x(e,t){for(const[n]of p)void 0===t[n]&&e.setData(n,"");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){console.error(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){console.error(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(f(e,t,r))})});const i=e.getRootElement(),l=e._window||window,s=l.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 a=e.registerCommand(o.COPY_COMMAND,o=>(n.objectKlassEquals(o,ClipboardEvent)&&(a(),null!==u&&(l.clearTimeout(u),u=null),t(f(e,o,r))),!0),o.COMMAND_PRIORITY_CRITICAL);u=l.setTimeout(()=>{a(),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 o}from"@lexical/selection";import{objectKlassEquals as r}from"@lexical/utils";import{$getSelection as i,$isRangeSelection as l,$createTabNode as s,SELECTION_INSERT_CLIPBOARD_NODES_COMMAND as c,$caretFromPoint as a,$isTextPointCaret as u,$getCaretRange as f,$getChildCaret as d,$getRoot as p,$isTextNode as g,$isElementNode as m,$parseSerializedNode as h,getDOMSelection as x,COPY_COMMAND as y,COMMAND_PRIORITY_CRITICAL as w,isSelectionWithinEditor as T,$getEditor as C}from"lexical";function v(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 D(e,n=i()){return null==n&&v(166),l(n)&&n.isCollapsed()||0===n.getNodes().length?"":t(e,n)}function S(t,e=i()){return null==e&&v(166),l(e)&&e.isCollapsed()||0===e.getNodes().length?null:JSON.stringify(E(t,e))}function N(t,e){const n=t.getData("text/plain")||t.getData("text/uri-list");null!=n&&e.insertRawText(n)}function R(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 A(o,L(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 A(o,e(o,t),n)}catch(t){}const u=a||t.getData("text/uri-list");if(null!=u)if(l(n)){const t=u.split(/(\r?\n|\t)/);""===t[t.length-1]&&t.pop();for(let e=0;e<t.length;e++){const n=i();if(l(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 A(t,e,n){t.dispatchCommand(c,{nodes:e,selection:n})||(n.insertNodes(e),function(t){if(l(t)&&t.isCollapsed()){const e=t.anchor;let n=null;const o=a(e,"previous");if(o)if(u(o))n=o.origin;else{const t=f(o,d(p(),"next").getFlipped());for(const e of t){if(g(e.origin)){n=e.origin;break}if(m(e.origin)&&!e.origin.isInline())break}}if(n&&g(n)){const e=n.getFormat(),o=n.getStyle();t.format===e&&t.style===o||(t.format=e,t.style=o,t.dirty=!0)}}}(n))}function P(t,e,n,r=[]){let i=null===e||n.isSelected(e);const l=m(n)&&n.excludeFromCopy("html");let s=n;null!==e&&g(s)&&(s=o(e,s,"clone"));const c=m(s)?s.getChildren():[],a=function(t){const e=t.exportJSON(),n=t.constructor;if(e.type!==n.getType()&&v(58,n.name),m(t)){const t=e.children;Array.isArray(t)||v(59,n.name)}return e}(s);g(s)&&0===s.getTextContentSize()&&(i=!1);for(let o=0;o<c.length;o++){const r=c[o],l=P(t,e,r,a.children);!i&&m(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 E(t,e){const n=[],o=p().getChildren();for(let r=0;r<o.length;r++){P(t,e,o[r],n)}return{namespace:t._config.namespace,nodes:n}}function L(t){const e=[];for(let o=0;o<t.length;o++){const r=t[o],i=h(r);g(i)&&n(i),e.push(i)}return e}let b=null;async function F(t,e,n){if(null!==b)return!1;if(null!==e)return new Promise((o,r)=>{t.update(()=>{o(M(t,e,n))})});const o=t.getRootElement(),i=t._window||window,l=i.document,s=x(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 s=t.registerCommand(y,o=>(r(o,ClipboardEvent)&&(s(),null!==b&&(i.clearTimeout(b),b=null),e(M(t,o,n))),!0),w);b=i.setTimeout(()=>{s(),b=null,e(!1)},50),l.execCommand("copy"),c.remove()})}function M(t,e,n){if(void 0===n){const e=x(t._window),o=i();if(!o||o.isCollapsed())return!1;if(!e)return!1;const r=e.anchorNode,l=e.focusNode;if(null!==r&&null!==l&&!T(t,r,l))return!1;n=_(o)}e.preventDefault();const o=e.clipboardData;return null!==o&&(J(o,n),!0)}const O=[["text/html",D],["application/x-lexical-editor",S]];function _(t=i()){const e={"text/plain":t?t.getTextContent():""};if(t){const n=C();for(const[o,r]of O){const i=r(n,t);null!==i&&(e[o]=i)}}return e}function J(t,e){for(const[n]of O)void 0===e[n]&&t.setData(n,"");for(const n in e){const o=e[n];void 0!==o&&t.setData(n,o)}}export{E as $generateJSONFromSelectedNodes,L as $generateNodesFromSerializedNodes,_ as $getClipboardDataFromSelection,D as $getHtmlContent,S as $getLexicalContent,N as $insertDataTransferForPlainText,R as $insertDataTransferForRichText,A as $insertGeneratedNodes,F as copyToClipboard,J as setLexicalClipboardDataTransfer};
|
|
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{$getSelection as i,$isRangeSelection as l,$createTabNode as s,SELECTION_INSERT_CLIPBOARD_NODES_COMMAND as c,$caretFromPoint as a,$isTextPointCaret as u,$getCaretRange as f,$getChildCaret as d,$getRoot as p,$isTextNode as g,$isElementNode as m,$parseSerializedNode as h,getDOMSelection as x,COPY_COMMAND as y,COMMAND_PRIORITY_CRITICAL as w,isSelectionWithinEditor as T,$getEditor as C}from"lexical";function v(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 D(e,n=i()){return null==n&&v(166),l(n)&&n.isCollapsed()||0===n.getNodes().length?"":t(e,n)}function S(t,e=i()){return null==e&&v(166),l(e)&&e.isCollapsed()||0===e.getNodes().length?null:JSON.stringify(E(t,e))}function N(t,e){const n=t.getData("text/plain")||t.getData("text/uri-list");null!=n&&e.insertRawText(n)}function R(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 A(o,L(t.nodes),n)}}catch(t){console.error(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 A(o,e(o,t),n)}catch(t){console.error(t)}const u=a||t.getData("text/uri-list");if(null!=u)if(l(n)){const t=u.split(/(\r?\n|\t)/);""===t[t.length-1]&&t.pop();for(let e=0;e<t.length;e++){const n=i();if(l(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 A(t,e,n){t.dispatchCommand(c,{nodes:e,selection:n})||(n.insertNodes(e),function(t){if(l(t)&&t.isCollapsed()){const e=t.anchor;let n=null;const o=a(e,"previous");if(o)if(u(o))n=o.origin;else{const t=f(o,d(p(),"next").getFlipped());for(const e of t){if(g(e.origin)){n=e.origin;break}if(m(e.origin)&&!e.origin.isInline())break}}if(n&&g(n)){const e=n.getFormat(),o=n.getStyle();t.format===e&&t.style===o||(t.format=e,t.style=o,t.dirty=!0)}}}(n))}function P(t,e,n,r=[]){let i=null===e||n.isSelected(e);const l=m(n)&&n.excludeFromCopy("html");let s=n;null!==e&&g(s)&&(s=o(e,s,"clone"));const c=m(s)?s.getChildren():[],a=function(t){const e=t.exportJSON(),n=t.constructor;if(e.type!==n.getType()&&v(58,n.name),m(t)){const t=e.children;Array.isArray(t)||v(59,n.name)}return e}(s);g(s)&&0===s.getTextContentSize()&&(i=!1);for(let o=0;o<c.length;o++){const r=c[o],l=P(t,e,r,a.children);!i&&m(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 E(t,e){const n=[],o=p().getChildren();for(let r=0;r<o.length;r++){P(t,e,o[r],n)}return{namespace:t._config.namespace,nodes:n}}function L(t){const e=[];for(let o=0;o<t.length;o++){const r=t[o],i=h(r);g(i)&&n(i),e.push(i)}return e}let b=null;async function F(t,e,n){if(null!==b)return!1;if(null!==e)return new Promise((o,r)=>{t.update(()=>{o(M(t,e,n))})});const o=t.getRootElement(),i=t._window||window,l=i.document,s=x(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 s=t.registerCommand(y,o=>(r(o,ClipboardEvent)&&(s(),null!==b&&(i.clearTimeout(b),b=null),e(M(t,o,n))),!0),w);b=i.setTimeout(()=>{s(),b=null,e(!1)},50),l.execCommand("copy"),c.remove()})}function M(t,e,n){if(void 0===n){const e=x(t._window),o=i();if(!o||o.isCollapsed())return!1;if(!e)return!1;const r=e.anchorNode,l=e.focusNode;if(null!==r&&null!==l&&!T(t,r,l))return!1;n=_(o)}e.preventDefault();const o=e.clipboardData;return null!==o&&(J(o,n),!0)}const O=[["text/html",D],["application/x-lexical-editor",S]];function _(t=i()){const e={"text/plain":t?t.getTextContent():""};if(t){const n=C();for(const[o,r]of O){const i=r(n,t);null!==i&&(e[o]=i)}}return e}function J(t,e){for(const[n]of O)void 0===e[n]&&t.setData(n,"");for(const n in e){const o=e[n];void 0!==o&&t.setData(n,o)}}export{E as $generateJSONFromSelectedNodes,L as $generateNodesFromSerializedNodes,_ as $getClipboardDataFromSelection,D as $getHtmlContent,S as $getLexicalContent,N as $insertDataTransferForPlainText,R as $insertDataTransferForRichText,A as $insertGeneratedNodes,F as copyToClipboard,J as setLexicalClipboardDataTransfer};
|
package/package.json
CHANGED
|
@@ -9,15 +9,15 @@
|
|
|
9
9
|
"paste"
|
|
10
10
|
],
|
|
11
11
|
"license": "MIT",
|
|
12
|
-
"version": "0.37.1-nightly.
|
|
12
|
+
"version": "0.37.1-nightly.20251027.0",
|
|
13
13
|
"main": "LexicalClipboard.js",
|
|
14
14
|
"types": "index.d.ts",
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@lexical/html": "0.37.1-nightly.
|
|
17
|
-
"@lexical/list": "0.37.1-nightly.
|
|
18
|
-
"@lexical/selection": "0.37.1-nightly.
|
|
19
|
-
"@lexical/utils": "0.37.1-nightly.
|
|
20
|
-
"lexical": "0.37.1-nightly.
|
|
16
|
+
"@lexical/html": "0.37.1-nightly.20251027.0",
|
|
17
|
+
"@lexical/list": "0.37.1-nightly.20251027.0",
|
|
18
|
+
"@lexical/selection": "0.37.1-nightly.20251027.0",
|
|
19
|
+
"@lexical/utils": "0.37.1-nightly.20251027.0",
|
|
20
|
+
"lexical": "0.37.1-nightly.20251027.0"
|
|
21
21
|
},
|
|
22
22
|
"repository": {
|
|
23
23
|
"type": "git",
|