@react-fabric/lexical 1.0.0-beta.6 → 1.0.0-beta.60

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.
Files changed (76) hide show
  1. package/{src/editor/Lexical.module.css → css/_lexical.css} +8 -4
  2. package/css/styles.css +24 -0
  3. package/dist/cjs/node_modules/@lexical/clipboard/LexicalClipboard.dev.js +62 -20
  4. package/dist/cjs/node_modules/@lexical/clipboard/LexicalClipboard.js +1 -1
  5. package/dist/cjs/node_modules/@lexical/clipboard/LexicalClipboard.prod.js +11 -11
  6. package/dist/cjs/node_modules/@lexical/code/LexicalCode.dev.js +643 -245
  7. package/dist/cjs/node_modules/@lexical/code/LexicalCode.js +1 -1
  8. package/dist/cjs/node_modules/@lexical/code/LexicalCode.prod.js +29 -22
  9. package/dist/cjs/node_modules/@lexical/html/LexicalHtml.dev.js +13 -6
  10. package/dist/cjs/node_modules/@lexical/html/LexicalHtml.js +1 -1
  11. package/dist/cjs/node_modules/@lexical/html/LexicalHtml.prod.js +3 -3
  12. package/dist/cjs/node_modules/@lexical/link/LexicalLink.dev.js +242 -141
  13. package/dist/cjs/node_modules/@lexical/link/LexicalLink.js +1 -1
  14. package/dist/cjs/node_modules/@lexical/link/LexicalLink.prod.js +11 -10
  15. package/dist/cjs/node_modules/@lexical/list/LexicalList.dev.js +594 -255
  16. package/dist/cjs/node_modules/@lexical/list/LexicalList.js +1 -1
  17. package/dist/cjs/node_modules/@lexical/list/LexicalList.prod.js +23 -16
  18. package/dist/cjs/node_modules/@lexical/rich-text/LexicalRichText.dev.js +102 -53
  19. package/dist/cjs/node_modules/@lexical/rich-text/LexicalRichText.js +1 -1
  20. package/dist/cjs/node_modules/@lexical/rich-text/LexicalRichText.prod.js +10 -10
  21. package/dist/cjs/node_modules/@lexical/selection/LexicalSelection.dev.js +275 -194
  22. package/dist/cjs/node_modules/@lexical/selection/LexicalSelection.js +5 -1
  23. package/dist/cjs/node_modules/@lexical/selection/LexicalSelection.prod.js +28 -18
  24. package/dist/cjs/node_modules/@lexical/table/LexicalTable.dev.js +2293 -878
  25. package/dist/cjs/node_modules/@lexical/table/LexicalTable.js +1 -1
  26. package/dist/cjs/node_modules/@lexical/table/LexicalTable.prod.js +53 -40
  27. package/dist/cjs/node_modules/@lexical/utils/LexicalUtils.dev.js +471 -193
  28. package/dist/cjs/node_modules/@lexical/utils/LexicalUtils.js +13 -1
  29. package/dist/cjs/node_modules/@lexical/utils/LexicalUtils.prod.js +47 -32
  30. package/dist/cjs/node_modules/prismjs/prism.js +1 -1
  31. package/dist/cjs/packages/lexical/src/components/StickyComponent.js +1 -1
  32. package/dist/cjs/packages/lexical/src/editor/LexicalEditor.js +30 -5
  33. package/dist/cjs/packages/lexical/src/hooks/useFormatWatcher.js +86 -83
  34. package/dist/cjs/packages/lexical/src/plugins/ToolbarPlugin.js +25 -17
  35. package/dist/esm/node_modules/@lexical/clipboard/LexicalClipboard.dev.js +62 -20
  36. package/dist/esm/node_modules/@lexical/clipboard/LexicalClipboard.js +1 -1
  37. package/dist/esm/node_modules/@lexical/clipboard/LexicalClipboard.prod.js +3 -3
  38. package/dist/esm/node_modules/@lexical/code/LexicalCode.dev.js +637 -246
  39. package/dist/esm/node_modules/@lexical/code/LexicalCode.js +1 -1
  40. package/dist/esm/node_modules/@lexical/code/LexicalCode.prod.js +4 -4
  41. package/dist/esm/node_modules/@lexical/html/LexicalHtml.dev.js +14 -7
  42. package/dist/esm/node_modules/@lexical/html/LexicalHtml.js +1 -1
  43. package/dist/esm/node_modules/@lexical/html/LexicalHtml.prod.js +3 -3
  44. package/dist/esm/node_modules/@lexical/link/LexicalLink.dev.js +244 -144
  45. package/dist/esm/node_modules/@lexical/link/LexicalLink.js +1 -1
  46. package/dist/esm/node_modules/@lexical/link/LexicalLink.prod.js +4 -4
  47. package/dist/esm/node_modules/@lexical/list/LexicalList.dev.js +590 -257
  48. package/dist/esm/node_modules/@lexical/list/LexicalList.js +1 -1
  49. package/dist/esm/node_modules/@lexical/list/LexicalList.prod.js +5 -4
  50. package/dist/esm/node_modules/@lexical/rich-text/LexicalRichText.dev.js +104 -55
  51. package/dist/esm/node_modules/@lexical/rich-text/LexicalRichText.js +1 -1
  52. package/dist/esm/node_modules/@lexical/rich-text/LexicalRichText.prod.js +4 -4
  53. package/dist/esm/node_modules/@lexical/selection/LexicalSelection.dev.js +267 -196
  54. package/dist/esm/node_modules/@lexical/selection/LexicalSelection.js +4 -2
  55. package/dist/esm/node_modules/@lexical/selection/LexicalSelection.prod.js +4 -4
  56. package/dist/esm/node_modules/@lexical/table/LexicalTable.dev.js +2283 -881
  57. package/dist/esm/node_modules/@lexical/table/LexicalTable.js +1 -1
  58. package/dist/esm/node_modules/@lexical/table/LexicalTable.prod.js +4 -4
  59. package/dist/esm/node_modules/@lexical/utils/LexicalUtils.dev.js +457 -194
  60. package/dist/esm/node_modules/@lexical/utils/LexicalUtils.js +8 -2
  61. package/dist/esm/node_modules/@lexical/utils/LexicalUtils.prod.js +3 -3
  62. package/dist/esm/node_modules/prismjs/prism.js +1 -1
  63. package/dist/esm/packages/lexical/src/components/StickyComponent.js +1 -1
  64. package/dist/esm/packages/lexical/src/editor/LexicalEditor.js +30 -5
  65. package/dist/esm/packages/lexical/src/hooks/useFormatWatcher.js +88 -85
  66. package/dist/esm/packages/lexical/src/plugins/ToolbarPlugin.js +25 -17
  67. package/dist/types/editor/LexicalEditor.d.ts +25 -0
  68. package/dist/types/hooks/useFormatWatcher.d.ts +2 -2
  69. package/dist/types/nodes/StickyNode.d.ts +0 -1
  70. package/package.json +14 -13
  71. package/src/components/StickyComponent.tsx +2 -2
  72. package/src/editor/LexicalEditor.tsx +57 -26
  73. package/src/hooks/useFormatWatcher.ts +35 -31
  74. package/src/plugins/ToolbarPlugin.tsx +27 -17
  75. package/dist/cjs/editor/Lexical.module.css +0 -1
  76. package/dist/esm/editor/Lexical.module.css +0 -1
@@ -23,14 +23,18 @@
23
23
 
24
24
  /* stylelint-disable custom-property-pattern */
25
25
 
26
- @layer util {
27
- .lexicalEditor,
28
- .lexicalToolbar {
26
+ @layer utilities {
27
+ .fabric-lexicalEditor,
28
+ .fabric-lexicalToolbar {
29
29
  width: 21cm;
30
30
  margin: 0 auto;
31
+
32
+ .fabric-inputWrapper {
33
+ outline: none;
34
+ }
31
35
  }
32
36
 
33
- .lexicalEditor :global {
37
+ .fabric-lexicalEditor {
34
38
  .editor-container.editor-container.editor-container {
35
39
  /* stylelint-disable-next-line font-family-no-missing-generic-family-keyword */
36
40
  font-family: "Sakkal Majalla";
package/css/styles.css ADDED
@@ -0,0 +1,24 @@
1
+ /*
2
+ * React Fabric
3
+ * @version: 1.0.0
4
+ *
5
+ *
6
+ * The MIT License (MIT)
7
+ * Copyright (c) 2025 Adarsh Pastakia
8
+ *
9
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
10
+ * and associated documentation files (the "Software"), to deal in the Software without restriction,
11
+ * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
12
+ * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
13
+ * subject to the following conditions:
14
+ *
15
+ * The above copyright notice and this permission notice shall be included in all copies or substantial
16
+ * portions of the Software.
17
+ *
18
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
19
+ * TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ */
23
+
24
+ @import "./_lexical.css";
@@ -22,17 +22,12 @@ var lexical = require('lexical');
22
22
  *
23
23
  */
24
24
 
25
- const CAN_USE_DOM = typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined';
25
+ // Do not require this module directly! Use normal `invariant` calls.
26
26
 
27
- /**
28
- * Copyright (c) Meta Platforms, Inc. and affiliates.
29
- *
30
- * This source code is licensed under the MIT license found in the
31
- * LICENSE file in the root directory of this source tree.
32
- *
33
- */
27
+ function formatDevErrorMessage(message) {
28
+ throw new Error(message);
29
+ }
34
30
 
35
- const getDOMSelection = targetWindow => CAN_USE_DOM ? (targetWindow || window).getSelection() : null;
36
31
  /**
37
32
  * Returns the *currently selected* Lexical content as an HTML string, relying on the
38
33
  * logic defined in the exportDOM methods on the LexicalNode classes. Note that
@@ -46,7 +41,7 @@ const getDOMSelection = targetWindow => CAN_USE_DOM ? (targetWindow || window).g
46
41
  function $getHtmlContent(editor, selection = lexical.$getSelection()) {
47
42
  if (selection == null) {
48
43
  {
49
- throw Error(`Expected valid LexicalSelection`);
44
+ formatDevErrorMessage(`Expected valid LexicalSelection`);
50
45
  }
51
46
  }
52
47
 
@@ -70,7 +65,7 @@ function $getHtmlContent(editor, selection = lexical.$getSelection()) {
70
65
  function $getLexicalContent(editor, selection = lexical.$getSelection()) {
71
66
  if (selection == null) {
72
67
  {
73
- throw Error(`Expected valid LexicalSelection`);
68
+ formatDevErrorMessage(`Expected valid LexicalSelection`);
74
69
  }
75
70
  }
76
71
 
@@ -119,10 +114,15 @@ function $insertDataTransferForRichText(dataTransfer, selection, editor) {
119
114
  }
120
115
  }
121
116
  const htmlString = dataTransfer.getData('text/html');
122
- if (htmlString) {
117
+ const plainString = dataTransfer.getData('text/plain');
118
+
119
+ // Skip HTML handling if it matches the plain text representation.
120
+ // This avoids unnecessary processing for plain text strings created by
121
+ // iOS Safari autocorrect, which incorrectly includes a `text/html` type.
122
+ if (htmlString && plainString !== htmlString) {
123
123
  try {
124
124
  const parser = new DOMParser();
125
- const dom = parser.parseFromString(htmlString, 'text/html');
125
+ const dom = parser.parseFromString(trustHTML(htmlString), 'text/html');
126
126
  const nodes = LexicalHtml.$generateNodesFromDOM(editor, dom);
127
127
  return $insertGeneratedNodes(editor, nodes, selection);
128
128
  } catch (_unused2) {
@@ -133,7 +133,7 @@ function $insertDataTransferForRichText(dataTransfer, selection, editor) {
133
133
  // Multi-line plain text in rich text mode pasted as separate paragraphs
134
134
  // instead of single paragraph with linebreaks.
135
135
  // Webkit-specific: Supports read 'text/uri-list' in clipboard.
136
- const text = dataTransfer.getData('text/plain') || dataTransfer.getData('text/uri-list');
136
+ const text = plainString || dataTransfer.getData('text/uri-list');
137
137
  if (text != null) {
138
138
  if (lexical.$isRangeSelection(selection)) {
139
139
  const parts = text.split(/(\r?\n|\t)/);
@@ -158,6 +158,15 @@ function $insertDataTransferForRichText(dataTransfer, selection, editor) {
158
158
  }
159
159
  }
160
160
  }
161
+ function trustHTML(html) {
162
+ if (window.trustedTypes && window.trustedTypes.createPolicy) {
163
+ const policy = window.trustedTypes.createPolicy('lexical', {
164
+ createHTML: input => input
165
+ });
166
+ return policy.createHTML(html);
167
+ }
168
+ return html;
169
+ }
161
170
 
162
171
  /**
163
172
  * Inserts Lexical nodes into the editor using different strategies depending on
@@ -175,22 +184,54 @@ function $insertGeneratedNodes(editor, nodes, selection) {
175
184
  selection
176
185
  })) {
177
186
  selection.insertNodes(nodes);
187
+ $updateSelectionOnInsert(selection);
178
188
  }
179
189
  return;
180
190
  }
191
+ function $updateSelectionOnInsert(selection) {
192
+ if (lexical.$isRangeSelection(selection) && selection.isCollapsed()) {
193
+ const anchor = selection.anchor;
194
+ let nodeToInspect = null;
195
+ const anchorCaret = lexical.$caretFromPoint(anchor, 'previous');
196
+ if (anchorCaret) {
197
+ if (lexical.$isTextPointCaret(anchorCaret)) {
198
+ nodeToInspect = anchorCaret.origin;
199
+ } else {
200
+ const range = lexical.$getCaretRange(anchorCaret, lexical.$getChildCaret(lexical.$getRoot(), 'next').getFlipped());
201
+ for (const caret of range) {
202
+ if (lexical.$isTextNode(caret.origin)) {
203
+ nodeToInspect = caret.origin;
204
+ break;
205
+ } else if (lexical.$isElementNode(caret.origin) && !caret.origin.isInline()) {
206
+ break;
207
+ }
208
+ }
209
+ }
210
+ }
211
+ if (nodeToInspect && lexical.$isTextNode(nodeToInspect)) {
212
+ const newFormat = nodeToInspect.getFormat();
213
+ const newStyle = nodeToInspect.getStyle();
214
+ if (selection.format !== newFormat || selection.style !== newStyle) {
215
+ selection.format = newFormat;
216
+ selection.style = newStyle;
217
+ selection.dirty = true;
218
+ }
219
+ }
220
+ }
221
+ }
181
222
  function exportNodeToJSON(node) {
182
223
  const serializedNode = node.exportJSON();
183
224
  const nodeClass = node.constructor;
184
225
  if (serializedNode.type !== nodeClass.getType()) {
185
226
  {
186
- throw Error(`LexicalNode: Node ${nodeClass.name} does not implement .exportJSON().`);
227
+ formatDevErrorMessage(`LexicalNode: Node ${nodeClass.name} does not implement .exportJSON().`);
187
228
  }
188
229
  }
189
230
  if (lexical.$isElementNode(node)) {
190
231
  const serializedChildren = serializedNode.children;
191
232
  if (!Array.isArray(serializedChildren)) {
192
233
  {
193
- throw Error(`LexicalNode: Node ${nodeClass.name} is an element but .exportJSON() does not have a children array.`);
234
+ formatDevErrorMessage(`LexicalNode: Node ${nodeClass.name} is an element but .exportJSON() does not have a children array.`);
194
235
  }
195
236
  }
196
237
  }
@@ -266,7 +307,7 @@ function $generateJSONFromSelectedNodes(editor, selection) {
266
307
  }
267
308
 
268
309
  /**
269
- * This method takes an array of objects conforming to the BaseSeralizedNode interface and returns
310
+ * This method takes an array of objects conforming to the BaseSerializedNode interface and returns
270
311
  * an Array containing instances of the corresponding LexicalNode classes registered on the editor.
271
312
  * Normally, you'd get an Array of BaseSerialized nodes from {@link $generateJSONFromSelectedNodes}
272
313
  *
@@ -313,8 +354,9 @@ async function copyToClipboard(editor, event, data) {
313
354
  });
314
355
  }
315
356
  const rootElement = editor.getRootElement();
316
- const windowDocument = editor._window == null ? window.document : editor._window.document;
317
- const domSelection = getDOMSelection(editor._window);
357
+ const editorWindow = editor._window || window;
358
+ const windowDocument = window.document;
359
+ const domSelection = lexical.getDOMSelection(editorWindow);
318
360
  if (rootElement === null || domSelection === null) {
319
361
  return false;
320
362
  }
@@ -355,7 +397,7 @@ async function copyToClipboard(editor, event, data) {
355
397
  // TODO shouldn't pass editor (pass namespace directly)
356
398
  function $copyToClipboardEvent(editor, event, data) {
357
399
  if (data === undefined) {
358
- const domSelection = getDOMSelection(editor._window);
400
+ const domSelection = lexical.getDOMSelection(editor._window);
359
401
  if (!domSelection) {
360
402
  return false;
361
403
  }
@@ -11,7 +11,7 @@ var LexicalClipboard_prod = require('./LexicalClipboard.prod.js');
11
11
  *
12
12
  */
13
13
 
14
- const mod = process.env.NODE_ENV === 'development' ? LexicalClipboard_dev : LexicalClipboard_prod;
14
+ const mod = process.env.NODE_ENV !== 'production' ? LexicalClipboard_dev : LexicalClipboard_prod;
15
15
  const $getClipboardDataFromSelection = mod.$getClipboardDataFromSelection;
16
16
  const $insertDataTransferForRichText = mod.$insertDataTransferForRichText;
17
17
  const copyToClipboard = mod.copyToClipboard;
@@ -13,15 +13,15 @@ var lexical = require('lexical');
13
13
  *
14
14
  */
15
15
 
16
- function w(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var y=w((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 v="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement,C=t=>v?(t||window).getSelection():null;function D(e,n=lexical.$getSelection()){return null==n&&y(166),lexical.$isRangeSelection(n)&&n.isCollapsed()||0===n.getNodes().length?"":LexicalHtml.$generateHtmlFromNodes(e,n)}function N(t,e=lexical.$getSelection()){return null==e&&y(166),lexical.$isRangeSelection(e)&&e.isCollapsed()||0===e.getNodes().length?null:JSON.stringify(R(t,e))}function _(t,e){const n=t.getData("text/plain")||t.getData("text/uri-list");null!=n&&e.insertRawText(n);}function T(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 S(o,E(t.nodes),n)}}catch(t){}const s=t.getData("text/html");if(s)try{const t=(new DOMParser).parseFromString(s,"text/html");return S(o,LexicalHtml.$generateNodesFromDOM(o,t),n)}catch(t){}const a=t.getData("text/plain")||t.getData("text/uri-list");if(null!=a)if(lexical.$isRangeSelection(n)){const t=a.split(/(\r?\n|\t)/);""===t[t.length-1]&&t.pop();for(let e=0;e<t.length;e++){const n=lexical.$getSelection();if(lexical.$isRangeSelection(n)){const o=t[e];"\n"===o||"\r\n"===o?n.insertParagraph():"\t"===o?n.insertNodes([lexical.$createTabNode()]):n.insertText(o);}}}else n.insertRawText(a);}function S(t,e,n){t.dispatchCommand(lexical.SELECTION_INSERT_CLIPBOARD_NODES_COMMAND,{nodes:e,selection:n})||n.insertNodes(e);}function A(t,e,n,r=[]){let l=null===e||n.isSelected(e);const i=lexical.$isElementNode(n)&&n.excludeFromCopy("html");let c=n;if(null!==e){let t=lexical.$cloneWithProperties(n);t=lexical.$isTextNode(t)&&null!==e?LexicalSelection.$sliceSelectedTextNodeContent(e,t):t,c=t;}const s=lexical.$isElementNode(c)?c.getChildren():[],a=function(t){const e=t.exportJSON(),n=t.constructor;if(e.type!==n.getType()&&y(58,n.name),lexical.$isElementNode(t)){const t=e.children;Array.isArray(t)||y(59,n.name);}return e}(c);if(lexical.$isTextNode(c)){const t=c.__text;t.length>0?a.text=t:l=!1;}for(let o=0;o<s.length;o++){const r=s[o],i=A(t,e,r,a.children);!l&&lexical.$isElementNode(n)&&i&&n.extractWithChild(r,e,"clone")&&(l=!0);}if(l&&!i)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 l}function R(t,e){const n=[],o=lexical.$getRoot().getChildren();for(let r=0;r<o.length;r++){A(t,e,o[r],n);}return {namespace:t._config.namespace,nodes:n}}function E(t){const e=[];for(let o=0;o<t.length;o++){const r=t[o],l=lexical.$parseSerializedNode(r);lexical.$isTextNode(l)&&LexicalSelection.$addNodeStyle(l),e.push(l);}return e}let O=null;async function P(t,e,n){if(null!==O)return !1;if(null!==e)return new Promise(((o,r)=>{t.update((()=>{o(b(t,e,n));}));}));const o=t.getRootElement(),l=null==t._window?window.document:t._window.document,i=C(t._window);if(null===o||null===i)return !1;const c=l.createElement("span");c.style.cssText="position: fixed; top: -1000px;",c.append(l.createTextNode("#")),o.append(c);const s=new Range;return s.setStart(c,0),s.setEnd(c,1),i.removeAllRanges(),i.addRange(s),new Promise(((e,o)=>{const i=t.registerCommand(lexical.COPY_COMMAND,(o=>(LexicalUtils.objectKlassEquals(o,ClipboardEvent)&&(i(),null!==O&&(window.clearTimeout(O),O=null),e(b(t,o,n))),!0)),lexical.COMMAND_PRIORITY_CRITICAL);O=window.setTimeout((()=>{i(),O=null,e(!1);}),50),l.execCommand("copy"),c.remove();}))}function b(t,e,n){if(void 0===n){const e=C(t._window);if(!e)return !1;const o=e.anchorNode,r=e.focusNode;if(null!==o&&null!==r&&!lexical.isSelectionWithinEditor(t,o,r))return !1;const l=lexical.$getSelection();if(null===l)return !1;n=M(l);}e.preventDefault();const o=e.clipboardData;return null!==o&&(F(o,n),!0)}const J=[["text/html",D],["application/x-lexical-editor",N]];function M(t=lexical.$getSelection()){const e={"text/plain":t?t.getTextContent():""};if(t){const n=lexical.$getEditor();for(const[o,r]of J){const l=r(n,t);null!==l&&(e[o]=l);}}return e}function F(t,e){for(const n in e){const o=e[n];void 0!==o&&t.setData(n,o);}}
16
+ 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=lexical.$getSelection()){return null==n&&D(166),lexical.$isRangeSelection(n)&&n.isCollapsed()||0===n.getNodes().length?"":LexicalHtml.$generateHtmlFromNodes(e,n)}function S(t,e=lexical.$getSelection()){return null==e&&D(166),lexical.$isRangeSelection(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,LexicalHtml.$generateNodesFromDOM(o,t),n)}catch(t){}const u=a||t.getData("text/uri-list");if(null!=u)if(lexical.$isRangeSelection(n)){const t=u.split(/(\r?\n|\t)/);""===t[t.length-1]&&t.pop();for(let e=0;e<t.length;e++){const n=lexical.$getSelection();if(lexical.$isRangeSelection(n)){const o=t[e];"\n"===o||"\r\n"===o?n.insertParagraph():"\t"===o?n.insertNodes([lexical.$createTabNode()]):n.insertText(o);}}}else n.insertRawText(u);}function P(t,e,n){t.dispatchCommand(lexical.SELECTION_INSERT_CLIPBOARD_NODES_COMMAND,{nodes:e,selection:n})||(n.insertNodes(e),function(t){if(lexical.$isRangeSelection(t)&&t.isCollapsed()){const e=t.anchor;let n=null;const o=lexical.$caretFromPoint(e,"previous");if(o)if(lexical.$isTextPointCaret(o))n=o.origin;else {const t=lexical.$getCaretRange(o,lexical.$getChildCaret(lexical.$getRoot(),"next").getFlipped());for(const e of t){if(lexical.$isTextNode(e.origin)){n=e.origin;break}if(lexical.$isElementNode(e.origin)&&!e.origin.isInline())break}}if(n&&lexical.$isTextNode(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=lexical.$isElementNode(n)&&n.excludeFromCopy("html");let s=n;if(null!==e){let t=lexical.$cloneWithProperties(n);t=lexical.$isTextNode(t)&&null!==e?LexicalSelection.$sliceSelectedTextNodeContent(e,t):t,s=t;}const c=lexical.$isElementNode(s)?s.getChildren():[],a=function(t){const e=t.exportJSON(),n=t.constructor;if(e.type!==n.getType()&&D(58,n.name),lexical.$isElementNode(t)){const t=e.children;Array.isArray(t)||D(59,n.name);}return e}(s);if(lexical.$isTextNode(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&&lexical.$isElementNode(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=lexical.$getRoot().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=lexical.$parseSerializedNode(r);lexical.$isTextNode(i)&&LexicalSelection.$addNodeStyle(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=lexical.getDOMSelection(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(lexical.COPY_COMMAND,(o=>(LexicalUtils.objectKlassEquals(o,ClipboardEvent)&&(i(),null!==b&&(window.clearTimeout(b),b=null),e(M(t,o,n))),!0)),lexical.COMMAND_PRIORITY_CRITICAL);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=lexical.getDOMSelection(t._window);if(!e)return !1;const o=e.anchorNode,r=e.focusNode;if(null!==o&&null!==r&&!lexical.isSelectionWithinEditor(t,o,r))return !1;const i=lexical.$getSelection();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=lexical.$getSelection()){const e={"text/plain":t?t.getTextContent():""};if(t){const n=lexical.$getEditor();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);}}
17
17
 
18
- exports.$generateJSONFromSelectedNodes = R;
19
- exports.$generateNodesFromSerializedNodes = E;
20
- exports.$getClipboardDataFromSelection = M;
21
- exports.$getHtmlContent = D;
22
- exports.$getLexicalContent = N;
23
- exports.$insertDataTransferForPlainText = _;
24
- exports.$insertDataTransferForRichText = T;
25
- exports.$insertGeneratedNodes = S;
26
- exports.copyToClipboard = P;
27
- exports.setLexicalClipboardDataTransfer = F;
18
+ exports.$generateJSONFromSelectedNodes = E;
19
+ exports.$generateNodesFromSerializedNodes = L;
20
+ exports.$getClipboardDataFromSelection = J;
21
+ exports.$getHtmlContent = N;
22
+ exports.$getLexicalContent = S;
23
+ exports.$insertDataTransferForPlainText = R;
24
+ exports.$insertDataTransferForRichText = A;
25
+ exports.$insertGeneratedNodes = P;
26
+ exports.copyToClipboard = F;
27
+ exports.setLexicalClipboardDataTransfer = k;