@lexical/clipboard 0.32.2-nightly.20250703.0 → 0.33.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.
@@ -183,9 +183,41 @@ function $insertGeneratedNodes(editor, nodes, selection) {
183
183
  selection
184
184
  })) {
185
185
  selection.insertNodes(nodes);
186
+ $updateSelectionOnInsert(selection);
186
187
  }
187
188
  return;
188
189
  }
190
+ function $updateSelectionOnInsert(selection) {
191
+ if (lexical.$isRangeSelection(selection) && selection.isCollapsed()) {
192
+ const anchor = selection.anchor;
193
+ let nodeToInspect = null;
194
+ const anchorCaret = lexical.$caretFromPoint(anchor, 'previous');
195
+ if (anchorCaret) {
196
+ if (lexical.$isTextPointCaret(anchorCaret)) {
197
+ nodeToInspect = anchorCaret.origin;
198
+ } else {
199
+ const range = lexical.$getCaretRange(anchorCaret, lexical.$getChildCaret(lexical.$getRoot(), 'next').getFlipped());
200
+ for (const caret of range) {
201
+ if (lexical.$isTextNode(caret.origin)) {
202
+ nodeToInspect = caret.origin;
203
+ break;
204
+ } else if (lexical.$isElementNode(caret.origin) && !caret.origin.isInline()) {
205
+ break;
206
+ }
207
+ }
208
+ }
209
+ }
210
+ if (nodeToInspect && lexical.$isTextNode(nodeToInspect)) {
211
+ const newFormat = nodeToInspect.getFormat();
212
+ const newStyle = nodeToInspect.getStyle();
213
+ if (selection.format !== newFormat || selection.style !== newStyle) {
214
+ selection.format = newFormat;
215
+ selection.style = newStyle;
216
+ selection.dirty = true;
217
+ }
218
+ }
219
+ }
220
+ }
189
221
  function exportNodeToJSON(node) {
190
222
  const serializedNode = node.exportJSON();
191
223
  const nodeClass = node.constructor;
@@ -9,7 +9,7 @@
9
9
  import { $generateHtmlFromNodes, $generateNodesFromDOM } from '@lexical/html';
10
10
  import { $addNodeStyle, $sliceSelectedTextNodeContent } from '@lexical/selection';
11
11
  import { objectKlassEquals } from '@lexical/utils';
12
- import { $isRangeSelection, $getSelection, $createTabNode, SELECTION_INSERT_CLIPBOARD_NODES_COMMAND, $getRoot, $parseSerializedNode, $isTextNode, getDOMSelection, COPY_COMMAND, COMMAND_PRIORITY_CRITICAL, isSelectionWithinEditor, $getEditor, $isElementNode, $cloneWithProperties } from 'lexical';
12
+ import { $isRangeSelection, $getSelection, $createTabNode, SELECTION_INSERT_CLIPBOARD_NODES_COMMAND, $caretFromPoint, $isTextPointCaret, $getCaretRange, $getChildCaret, $getRoot, $isTextNode, $isElementNode, $parseSerializedNode, getDOMSelection, COPY_COMMAND, COMMAND_PRIORITY_CRITICAL, isSelectionWithinEditor, $getEditor, $cloneWithProperties } from 'lexical';
13
13
 
14
14
  /**
15
15
  * Copyright (c) Meta Platforms, Inc. and affiliates.
@@ -181,9 +181,41 @@ function $insertGeneratedNodes(editor, nodes, selection) {
181
181
  selection
182
182
  })) {
183
183
  selection.insertNodes(nodes);
184
+ $updateSelectionOnInsert(selection);
184
185
  }
185
186
  return;
186
187
  }
188
+ function $updateSelectionOnInsert(selection) {
189
+ if ($isRangeSelection(selection) && selection.isCollapsed()) {
190
+ const anchor = selection.anchor;
191
+ let nodeToInspect = null;
192
+ const anchorCaret = $caretFromPoint(anchor, 'previous');
193
+ if (anchorCaret) {
194
+ if ($isTextPointCaret(anchorCaret)) {
195
+ nodeToInspect = anchorCaret.origin;
196
+ } else {
197
+ const range = $getCaretRange(anchorCaret, $getChildCaret($getRoot(), 'next').getFlipped());
198
+ for (const caret of range) {
199
+ if ($isTextNode(caret.origin)) {
200
+ nodeToInspect = caret.origin;
201
+ break;
202
+ } else if ($isElementNode(caret.origin) && !caret.origin.isInline()) {
203
+ break;
204
+ }
205
+ }
206
+ }
207
+ }
208
+ if (nodeToInspect && $isTextNode(nodeToInspect)) {
209
+ const newFormat = nodeToInspect.getFormat();
210
+ const newStyle = nodeToInspect.getStyle();
211
+ if (selection.format !== newFormat || selection.style !== newStyle) {
212
+ selection.format = newFormat;
213
+ selection.style = newStyle;
214
+ selection.dirty = true;
215
+ }
216
+ }
217
+ }
218
+ }
187
219
  function exportNodeToJSON(node) {
188
220
  const serializedNode = node.exportJSON();
189
221
  const nodeClass = node.constructor;
@@ -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 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;
9
+ "use strict";var e=require("@lexical/html"),t=require("@lexical/selection"),n=require("@lexical/utils"),o=require("lexical");function i(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 r(t,n=o.$getSelection()){return null==n&&i(166),o.$isRangeSelection(n)&&n.isCollapsed()||0===n.getNodes().length?"":e.$generateHtmlFromNodes(t,n)}function l(e,t=o.$getSelection()){return null==t&&i(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 i=o.$caretFromPoint(t,"previous");if(i)if(o.$isTextPointCaret(i))n=i.origin;else{const e=o.$getCaretRange(i,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,r,l=[]){let s=null===n||r.isSelected(n);const c=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():[],f=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?f.text=e:s=!1}for(let t=0;t<u.length;t++){const i=u[t],l=a(e,n,i,f.children);!s&&o.$isElementNode(r)&&l&&r.extractWithChild(i,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=[],i=o.$getRoot().getChildren();for(let o=0;o<i.length;o++){a(e,t,i[o],n)}return{namespace:e._config.namespace,nodes:n}}function d(e){const n=[];for(let i=0;i<e.length;i++){const r=e[i],l=o.$parseSerializedNode(r);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);if(!t)return!1;const i=t.anchorNode,r=t.focusNode;if(null!==i&&null!==r&&!o.isSelectionWithinEditor(e,i,r))return!1;const l=o.$getSelection();if(null===l)return!1;n=g(l)}t.preventDefault();const i=t.clipboardData;return null!==i&&(x(i,n),!0)}const p=[["text/html",r],["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,i]of p){const r=i(n,e);null!==r&&(t[o]=r)}}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=r,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,i){const r=t.getData("application/x-lexical-editor");if(r)try{const e=JSON.parse(r);if(e.namespace===i._config.namespace&&Array.isArray(e.nodes)){return s(i,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(i,e.$generateNodesFromDOM(i,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 i=e[t];"\n"===i||"\r\n"===i?n.insertParagraph():"\t"===i?n.insertNodes([o.$createTabNode()]):n.insertText(i)}}}else n.insertRawText(c)},exports.$insertGeneratedNodes=s,exports.copyToClipboard=async function(e,t,i){if(null!==u)return!1;if(null!==t)return new Promise(((n,o)=>{e.update((()=>{n(f(e,t,i))}))}));const r=e.getRootElement(),l=e._window||window,s=window.document,a=o.getDOMSelection(l);if(null===r||null===a)return!1;const c=s.createElement("span");c.style.cssText="position: fixed; top: -1000px;",c.append(s.createTextNode("#")),r.append(c);const d=new Range;return d.setStart(c,0),d.setEnd(c,1),a.removeAllRanges(),a.addRange(d),new Promise(((t,r)=>{const l=e.registerCommand(o.COPY_COMMAND,(o=>(n.objectKlassEquals(o,ClipboardEvent)&&(l(),null!==u&&(window.clearTimeout(u),u=null),t(f(e,o,i))),!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 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};
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,$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 w,COMMAND_PRIORITY_CRITICAL as y,isSelectionWithinEditor as T,$getEditor as v,$cloneWithProperties as C}from"lexical";function D(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 N(e,n=l()){return null==n&&D(166),i(n)&&n.isCollapsed()||0===n.getNodes().length?"":t(e,n)}function S(t,e=l()){return null==e&&D(166),i(e)&&e.isCollapsed()||0===e.getNodes().length?null:JSON.stringify(E(t,e))}function R(t,e){const n=t.getData("text/plain")||t.getData("text/uri-list");null!=n&&e.insertRawText(n)}function A(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 P(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 P(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 P(t,e,n){t.dispatchCommand(c,{nodes:e,selection:n})||(n.insertNodes(e),function(t){if(i(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 _(t,e,n,r=[]){let i=null===e||n.isSelected(e);const l=m(n)&&n.excludeFromCopy("html");let s=n;if(null!==e){let t=C(n);t=g(t)&&null!==e?o(e,t):t,s=t}const c=m(s)?s.getChildren():[],a=function(t){const e=t.exportJSON(),n=t.constructor;if(e.type!==n.getType()&&D(58,n.name),m(t)){const t=e.children;Array.isArray(t)||D(59,n.name)}return e}(s);if(g(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=_(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++){_(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=window.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 i=t.registerCommand(w,(o=>(r(o,ClipboardEvent)&&(i(),null!==b&&(window.clearTimeout(b),b=null),e(M(t,o,n))),!0)),y);b=window.setTimeout((()=>{i(),b=null,e(!1)}),50),l.execCommand("copy"),c.remove()}))}function M(t,e,n){if(void 0===n){const e=x(t._window);if(!e)return!1;const o=e.anchorNode,r=e.focusNode;if(null!==o&&null!==r&&!T(t,o,r))return!1;const i=l();if(null===i)return!1;n=J(i)}e.preventDefault();const o=e.clipboardData;return null!==o&&(k(o,n),!0)}const O=[["text/html",N],["application/x-lexical-editor",S]];function J(t=l()){const e={"text/plain":t?t.getTextContent():""};if(t){const n=v();for(const[o,r]of O){const i=r(n,t);null!==i&&(e[o]=i)}}return e}function k(t,e){for(const n in e){const o=e[n];void 0!==o&&t.setData(n,o)}}export{E as $generateJSONFromSelectedNodes,L as $generateNodesFromSerializedNodes,J as $getClipboardDataFromSelection,N as $getHtmlContent,S as $getLexicalContent,R as $insertDataTransferForPlainText,A as $insertDataTransferForRichText,P as $insertGeneratedNodes,F as copyToClipboard,k as setLexicalClipboardDataTransfer};
package/package.json CHANGED
@@ -9,15 +9,15 @@
9
9
  "paste"
10
10
  ],
11
11
  "license": "MIT",
12
- "version": "0.32.2-nightly.20250703.0",
12
+ "version": "0.33.0",
13
13
  "main": "LexicalClipboard.js",
14
14
  "types": "index.d.ts",
15
15
  "dependencies": {
16
- "@lexical/html": "0.32.2-nightly.20250703.0",
17
- "@lexical/list": "0.32.2-nightly.20250703.0",
18
- "@lexical/selection": "0.32.2-nightly.20250703.0",
19
- "@lexical/utils": "0.32.2-nightly.20250703.0",
20
- "lexical": "0.32.2-nightly.20250703.0"
16
+ "@lexical/html": "0.33.0",
17
+ "@lexical/list": "0.33.0",
18
+ "@lexical/selection": "0.33.0",
19
+ "@lexical/utils": "0.33.0",
20
+ "lexical": "0.33.0"
21
21
  },
22
22
  "repository": {
23
23
  "type": "git",