@lexical/clipboard
Advanced tools
Comparing version 0.23.2-nightly.20250114.0 to 0.23.2-nightly.20250115.0
@@ -9,13 +9,2 @@ /** | ||
'use strict';var e=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.");} | ||
t=u&&u.__esModule&&Object.prototype.hasOwnProperty.call(u,"default")?u["default"]:u;function v(a,b=p.$getSelection()){null==b&&t(166);return p.$isRangeSelection(b)&&b.isCollapsed()||0===b.getNodes().length?"":e.$generateHtmlFromNodes(a,b)}function w(a,b=p.$getSelection()){null==b&&t(166);return p.$isRangeSelection(b)&&b.isCollapsed()||0===b.getNodes().length?null:JSON.stringify(x(a,b))} | ||
function y(a){return window.trustedTypes&&window.trustedTypes.createPolicy?window.trustedTypes.createPolicy("lexical",{createHTML:b=>b}).createHTML(a):a}function z(a,b,c){a.dispatchCommand(p.SELECTION_INSERT_CLIPBOARD_NODES_COMMAND,{nodes:b,selection:c})||c.insertNodes(b)} | ||
function A(a,b,c,d=[]){let f=null!==b?c.isSelected(b):!0,k=p.$isElementNode(c)&&c.excludeFromCopy("html");var g=c;if(null!==b){var h=p.$cloneWithProperties(c);g=h=p.$isTextNode(h)&&null!==b?m.$sliceSelectedTextNodeContent(b,h):h}let q=p.$isElementNode(g)?g.getChildren():[];var l=g;h=l.exportJSON();var r=l.constructor;h.type!==r.getType()&&t(58,r.name);p.$isElementNode(l)&&(Array.isArray(h.children)||t(59,r.name));p.$isTextNode(g)&&(g=g.__text,0<g.length?h.text=g:f=!1);for(g=0;g<q.length;g++)l=q[g], | ||
r=A(a,b,l,h.children),!f&&p.$isElementNode(c)&&r&&c.extractWithChild(l,b,"clone")&&(f=!0);if(f&&!k)d.push(h);else if(Array.isArray(h.children))for(a=0;a<h.children.length;a++)d.push(h.children[a]);return f}function x(a,b){let c=[],d=p.$getRoot().getChildren();for(let f=0;f<d.length;f++)A(a,b,d[f],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; | ||
function D(a,b,c){if(void 0===c){var d=p.getDOMSelection(a._window);if(!d)return!1;c=d.anchorNode;d=d.focusNode;if(null!==c&&null!==d&&!p.isSelectionWithinEditor(a,c,d))return!1;a=p.$getSelection();if(null===a)return!1;c=E(a)}b.preventDefault();b=b.clipboardData;if(null===b)return!1;F(b,c);return!0}let G=[["text/html",v],["application/x-lexical-editor",w]]; | ||
function E(a=p.$getSelection()){let b={"text/plain":a?a.getTextContent():""};if(a){let c=p.$getEditor();for(let [d,f]of G){let k=f(c,a);null!==k&&(b[d]=k)}}return b}function F(a,b){for(let c in b){let d=b[c];void 0!==d&&a.setData(c,d)}}exports.$generateJSONFromSelectedNodes=x;exports.$generateNodesFromSerializedNodes=B;exports.$getClipboardDataFromSelection=E;exports.$getHtmlContent=v;exports.$getLexicalContent=w; | ||
exports.$insertDataTransferForPlainText=function(a,b){a=a.getData("text/plain")||a.getData("text/uri-list");null!=a&&b.insertRawText(a)}; | ||
exports.$insertDataTransferForRichText=function(a,b,c){var d=a.getData("application/x-lexical-editor");if(d)try{let k=JSON.parse(d);if(k.namespace===c._config.namespace&&Array.isArray(k.nodes)){let g=B(k.nodes);return z(c,g,b)}}catch(k){}if(d=a.getData("text/html"))try{var f=(new DOMParser).parseFromString(y(d),"text/html");let k=e.$generateNodesFromDOM(c,f);return z(c,k,b)}catch(k){}a=a.getData("text/plain")||a.getData("text/uri-list");if(null!=a)if(p.$isRangeSelection(b))for(b=a.split(/(\r?\n|\t)/), | ||
""===b[b.length-1]&&b.pop(),a=0;a<b.length;a++)c=p.$getSelection(),p.$isRangeSelection(c)&&(f=b[a],"\n"===f||"\r\n"===f?c.insertParagraph():"\t"===f?c.insertNodes([p.$createTabNode()]):c.insertText(f));else b.insertRawText(a)};exports.$insertGeneratedNodes=z; | ||
exports.copyToClipboard=async function(a,b,c){if(null!==C)return!1;if(null!==b)return new Promise(h=>{a.update(()=>{h(D(a,b,c))})});var d=a.getRootElement();let f=window.document,k=p.getDOMSelection(a._window||window);if(null===d||null===k)return!1;let g=f.createElement("span");g.style.cssText="position: fixed; top: -1000px;";g.append(f.createTextNode("#"));d.append(g);d=new Range;d.setStart(g,0);d.setEnd(g,1);k.removeAllRanges();k.addRange(d);return new Promise(h=>{let q=a.registerCommand(p.COPY_COMMAND, | ||
l=>{n.objectKlassEquals(l,ClipboardEvent)&&(q(),null!==C&&(window.clearTimeout(C),C=null),h(D(a,l,c)));return!0},p.COMMAND_PRIORITY_CRITICAL);C=window.setTimeout(()=>{q();C=null;h(!1)},50);f.execCommand("copy");g.remove()})};exports.setLexicalClipboardDataTransfer=F | ||
"use strict";var e=require("@lexical/html"),t=require("@lexical/selection"),n=require("@lexical/utils"),o=require("lexical");function r(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var i=r((function(e){const t=new URLSearchParams;t.append("code",e);for(let e=1;e<arguments.length;e++)t.append("v",arguments[e]);throw Error(`Minified Lexical error #${e}; visit https://lexical.dev/docs/error?${t} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}));function l(t,n=o.$getSelection()){return null==n&&i(166),o.$isRangeSelection(n)&&n.isCollapsed()||0===n.getNodes().length?"":e.$generateHtmlFromNodes(t,n)}function s(e,t=o.$getSelection()){return null==t&&i(166),o.$isRangeSelection(t)&&t.isCollapsed()||0===t.getNodes().length?null:JSON.stringify(d(e,t))}function a(e,t,n){e.dispatchCommand(o.SELECTION_INSERT_CLIPBOARD_NODES_COMMAND,{nodes:t,selection:n})||n.insertNodes(t)}function c(e,n,r,l=[]){let s=null===n||r.isSelected(n);const a=o.$isElementNode(r)&&r.excludeFromCopy("html");let d=r;if(null!==n){let e=o.$cloneWithProperties(r);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()&&i(58,n.name),o.$isElementNode(e)){const e=t.children;Array.isArray(e)||i(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 i=u[t],l=c(e,n,i,p.children);!s&&o.$isElementNode(r)&&l&&r.extractWithChild(i,n,"clone")&&(s=!0)}if(s&&!a)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 d(e,t){const n=[],r=o.$getRoot().getChildren();for(let o=0;o<r.length;o++){c(e,t,r[o],n)}return{namespace:e._config.namespace,nodes:n}}function u(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 p=null;function f(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=x(l)}t.preventDefault();const r=t.clipboardData;return null!==r&&(m(r,n),!0)}const g=[["text/html",l],["application/x-lexical-editor",s]];function x(e=o.$getSelection()){const t={"text/plain":e?e.getTextContent():""};if(e){const n=o.$getEditor();for(const[o,r]of g){const i=r(n,e);null!==i&&(t[o]=i)}}return t}function m(e,t){for(const n in t){const o=t[n];void 0!==o&&e.setData(n,o)}}exports.$generateJSONFromSelectedNodes=d,exports.$generateNodesFromSerializedNodes=u,exports.$getClipboardDataFromSelection=x,exports.$getHtmlContent=l,exports.$getLexicalContent=s,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 a(r,u(e.nodes),n)}}catch(e){}const l=t.getData("text/html");if(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 a(r,e.$generateNodesFromDOM(r,t),n)}catch(e){}const s=t.getData("text/plain")||t.getData("text/uri-list");if(null!=s)if(o.$isRangeSelection(n)){const e=s.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(s)},exports.$insertGeneratedNodes=a,exports.copyToClipboard=async function(e,t,r){if(null!==p)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=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!==p&&(window.clearTimeout(p),p=null),t(f(e,o,r))),!0)),o.COMMAND_PRIORITY_CRITICAL);p=window.setTimeout((()=>{l(),p=null,t(!1)}),50),s.execCommand("copy"),c.remove()}))},exports.setLexicalClipboardDataTransfer=m; |
@@ -12,11 +12,11 @@ { | ||
"license": "MIT", | ||
"version": "0.23.2-nightly.20250114.0", | ||
"version": "0.23.2-nightly.20250115.0", | ||
"main": "LexicalClipboard.js", | ||
"types": "index.d.ts", | ||
"dependencies": { | ||
"@lexical/html": "0.23.2-nightly.20250114.0", | ||
"@lexical/list": "0.23.2-nightly.20250114.0", | ||
"@lexical/selection": "0.23.2-nightly.20250114.0", | ||
"@lexical/utils": "0.23.2-nightly.20250114.0", | ||
"lexical": "0.23.2-nightly.20250114.0" | ||
"@lexical/html": "0.23.2-nightly.20250115.0", | ||
"@lexical/list": "0.23.2-nightly.20250115.0", | ||
"@lexical/selection": "0.23.2-nightly.20250115.0", | ||
"@lexical/utils": "0.23.2-nightly.20250115.0", | ||
"lexical": "0.23.2-nightly.20250115.0" | ||
}, | ||
@@ -23,0 +23,0 @@ "repository": { |
55457
1036
+ Added@lexical/html@0.23.2-nightly.20250115.0(transitive)
+ Added@lexical/list@0.23.2-nightly.20250115.0(transitive)
+ Added@lexical/selection@0.23.2-nightly.20250115.0(transitive)
+ Added@lexical/table@0.23.2-nightly.20250115.0(transitive)
+ Added@lexical/utils@0.23.2-nightly.20250115.0(transitive)
+ Addedlexical@0.23.2-nightly.20250115.0(transitive)
- Removed@lexical/html@0.23.2-nightly.20250114.0(transitive)
- Removed@lexical/list@0.23.2-nightly.20250114.0(transitive)
- Removed@lexical/selection@0.23.2-nightly.20250114.0(transitive)
- Removed@lexical/table@0.23.2-nightly.20250114.0(transitive)
- Removed@lexical/utils@0.23.2-nightly.20250114.0(transitive)
- Removedlexical@0.23.2-nightly.20250114.0(transitive)