@lexical/react 0.46.1-nightly.20260706.0 → 0.46.1-nightly.20260708.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.
Files changed (138) hide show
  1. package/dist/ExtensionComponent.d.ts +1 -1
  2. package/dist/LexicalAutoEmbedPlugin.d.ts +2 -3
  3. package/dist/LexicalAutoLinkPlugin.d.ts +2 -2
  4. package/dist/LexicalBlockWithAlignableContents.d.ts +2 -3
  5. package/dist/LexicalCharacterLimitPlugin.d.ts +1 -1
  6. package/dist/LexicalCharacterLimitPlugin.dev.js +2 -0
  7. package/dist/LexicalCharacterLimitPlugin.dev.mjs +2 -0
  8. package/dist/LexicalCharacterLimitPlugin.prod.js +1 -1
  9. package/dist/LexicalCharacterLimitPlugin.prod.mjs +1 -1
  10. package/dist/LexicalCollaborationContext.prod.js +1 -1
  11. package/dist/LexicalCollaborationContext.prod.mjs +1 -1
  12. package/dist/LexicalCollaborationPlugin.d.ts +5 -5
  13. package/dist/LexicalCollaborationPlugin.dev.js +5 -5
  14. package/dist/LexicalCollaborationPlugin.dev.mjs +5 -5
  15. package/dist/LexicalCollaborationPlugin.prod.js +1 -1
  16. package/dist/LexicalCollaborationPlugin.prod.mjs +1 -1
  17. package/dist/LexicalComposer.d.ts +2 -2
  18. package/dist/LexicalContentEditable.d.ts +1 -1
  19. package/dist/LexicalContentEditable.prod.js +1 -1
  20. package/dist/LexicalContentEditable.prod.mjs +1 -1
  21. package/dist/LexicalDecoratorBlockNode.d.ts +1 -2
  22. package/dist/LexicalDecoratorBlockNode.dev.js +1 -1
  23. package/dist/LexicalDecoratorBlockNode.dev.mjs +2 -2
  24. package/dist/LexicalDecoratorBlockNode.prod.js +1 -1
  25. package/dist/LexicalDecoratorBlockNode.prod.mjs +1 -1
  26. package/dist/LexicalDraggableBlockPlugin.d.ts +1 -2
  27. package/dist/LexicalDraggableBlockPlugin.dev.js +9 -6
  28. package/dist/LexicalDraggableBlockPlugin.dev.mjs +9 -6
  29. package/dist/LexicalDraggableBlockPlugin.prod.js +1 -1
  30. package/dist/LexicalDraggableBlockPlugin.prod.mjs +1 -1
  31. package/dist/LexicalEditorRefPlugin.d.ts +2 -2
  32. package/dist/LexicalEditorRefPlugin.dev.js +1 -0
  33. package/dist/LexicalEditorRefPlugin.dev.mjs +1 -0
  34. package/dist/LexicalErrorBoundary.prod.js +1 -1
  35. package/dist/LexicalErrorBoundary.prod.mjs +1 -1
  36. package/dist/LexicalExtensionComponent.prod.js +1 -1
  37. package/dist/LexicalExtensionComponent.prod.mjs +1 -1
  38. package/dist/LexicalExtensionComposer.d.ts +1 -1
  39. package/dist/LexicalExtensionComposer.prod.js +1 -1
  40. package/dist/LexicalExtensionComposer.prod.mjs +1 -1
  41. package/dist/LexicalExtensionEditorComposer.d.ts +8 -1
  42. package/dist/LexicalExtensionEditorComposer.dev.js +1 -0
  43. package/dist/LexicalExtensionEditorComposer.dev.mjs +1 -0
  44. package/dist/LexicalExtensionEditorComposer.prod.js +1 -1
  45. package/dist/LexicalExtensionEditorComposer.prod.mjs +1 -1
  46. package/dist/LexicalHashtagPlugin.d.ts +1 -1
  47. package/dist/LexicalHorizontalRuleNode.d.ts +2 -2
  48. package/dist/LexicalHorizontalRuleNode.prod.js +1 -1
  49. package/dist/LexicalHorizontalRuleNode.prod.mjs +1 -1
  50. package/dist/LexicalMarkdownShortcutPlugin.d.ts +1 -1
  51. package/dist/LexicalNestedComposer.d.ts +2 -3
  52. package/dist/LexicalNodeContextMenuPlugin.d.ts +2 -2
  53. package/dist/LexicalNodeEventPlugin.d.ts +1 -1
  54. package/dist/LexicalNodeMenuPlugin.d.ts +3 -4
  55. package/dist/LexicalNodeMenuPlugin.dev.js +22 -6
  56. package/dist/LexicalNodeMenuPlugin.dev.mjs +23 -7
  57. package/dist/LexicalNodeMenuPlugin.prod.js +1 -1
  58. package/dist/LexicalNodeMenuPlugin.prod.mjs +1 -1
  59. package/dist/LexicalOnChangePlugin.d.ts +1 -1
  60. package/dist/LexicalReactExtension.dev.js +1 -1
  61. package/dist/LexicalReactExtension.dev.mjs +1 -1
  62. package/dist/LexicalReactExtension.prod.js +2 -2
  63. package/dist/LexicalReactExtension.prod.mjs +2 -2
  64. package/dist/LexicalTableOfContentsPlugin.d.ts +3 -3
  65. package/dist/LexicalTablePlugin.d.ts +1 -1
  66. package/dist/LexicalTreeView.d.ts +3 -3
  67. package/dist/LexicalTreeView.prod.mjs +1 -1
  68. package/dist/LexicalTreeViewExtension.prod.js +1 -1
  69. package/dist/LexicalTreeViewExtension.prod.mjs +1 -1
  70. package/dist/LexicalTypeaheadMenuPlugin.d.ts +3 -4
  71. package/dist/LexicalTypeaheadMenuPlugin.dev.js +22 -6
  72. package/dist/LexicalTypeaheadMenuPlugin.dev.mjs +23 -7
  73. package/dist/LexicalTypeaheadMenuPlugin.prod.js +1 -1
  74. package/dist/LexicalTypeaheadMenuPlugin.prod.mjs +1 -1
  75. package/dist/ReactPluginHostExtension.d.ts +1 -1
  76. package/dist/shared/LegacyDecorators.d.ts +1 -1
  77. package/dist/shared/LexicalMenu.d.ts +2 -3
  78. package/dist/shared/buildEditorComponent.d.ts +1 -1
  79. package/dist/shared/rect.d.ts +1 -1
  80. package/dist/shared/useCanShowPlaceholder.d.ts +1 -1
  81. package/dist/shared/useCharacterLimit.d.ts +1 -1
  82. package/dist/shared/useDecorators.d.ts +1 -1
  83. package/dist/shared/useHistory.d.ts +1 -1
  84. package/dist/shared/usePlainTextSetup.d.ts +1 -1
  85. package/dist/shared/useReactDecorators.d.ts +2 -2
  86. package/dist/shared/useRichTextSetup.d.ts +1 -1
  87. package/dist/shared/useYjsCollaboration.d.ts +5 -5
  88. package/dist/useExtensionComponent.d.ts +8 -1
  89. package/dist/useLexicalExtensionComponent.dev.js +2 -0
  90. package/dist/useLexicalExtensionComponent.dev.mjs +2 -0
  91. package/dist/useLexicalNodeSelection.d.ts +1 -1
  92. package/dist/useLexicalSlotRef.d.ts +2 -2
  93. package/dist/useLexicalTextEntity.d.ts +2 -2
  94. package/package.json +20 -20
  95. package/src/ExtensionComponent.tsx +1 -1
  96. package/src/LexicalAutoEmbedPlugin.tsx +8 -11
  97. package/src/LexicalAutoLinkPlugin.ts +7 -4
  98. package/src/LexicalBlockWithAlignableContents.tsx +3 -4
  99. package/src/LexicalCharacterLimitPlugin.tsx +3 -3
  100. package/src/LexicalCollaborationPlugin.tsx +9 -10
  101. package/src/LexicalComposer.tsx +9 -11
  102. package/src/LexicalContentEditable.tsx +1 -2
  103. package/src/LexicalDecoratorBlockNode.ts +11 -10
  104. package/src/LexicalDraggableBlockPlugin.tsx +17 -9
  105. package/src/LexicalEditorRefPlugin.tsx +3 -2
  106. package/src/LexicalExtensionComposer.tsx +1 -1
  107. package/src/LexicalExtensionEditorComposer.tsx +2 -1
  108. package/src/LexicalHashtagPlugin.ts +1 -3
  109. package/src/LexicalHorizontalRuleNode.tsx +4 -4
  110. package/src/LexicalMarkdownShortcutPlugin.tsx +6 -2
  111. package/src/LexicalNestedComposer.tsx +15 -10
  112. package/src/LexicalNodeContextMenuPlugin.tsx +9 -2
  113. package/src/LexicalNodeEventPlugin.ts +4 -2
  114. package/src/LexicalNodeMenuPlugin.tsx +17 -8
  115. package/src/LexicalOnChangePlugin.ts +1 -3
  116. package/src/LexicalTableOfContentsPlugin.tsx +10 -8
  117. package/src/LexicalTablePlugin.ts +2 -4
  118. package/src/LexicalTreeView.tsx +3 -6
  119. package/src/LexicalTypeaheadMenuPlugin.tsx +21 -15
  120. package/src/ReactPluginHostExtension.tsx +1 -2
  121. package/src/shared/LegacyDecorators.tsx +1 -1
  122. package/src/shared/LexicalContentEditableElement.tsx +9 -2
  123. package/src/shared/LexicalMenu.tsx +20 -10
  124. package/src/shared/buildEditorComponent.tsx +2 -1
  125. package/src/shared/rect.ts +1 -1
  126. package/src/shared/useCanShowPlaceholder.ts +1 -3
  127. package/src/shared/useCharacterLimit.ts +2 -2
  128. package/src/shared/useDecorators.tsx +1 -2
  129. package/src/shared/useHistory.ts +5 -2
  130. package/src/shared/usePlainTextSetup.ts +1 -3
  131. package/src/shared/useReactDecorators.tsx +2 -4
  132. package/src/shared/useRichTextSetup.ts +1 -3
  133. package/src/shared/useYjsCollaboration.tsx +27 -17
  134. package/src/useExtensionComponent.tsx +6 -5
  135. package/src/useLexicalEditable.ts +4 -2
  136. package/src/useLexicalNodeSelection.ts +2 -2
  137. package/src/useLexicalSlotRef.ts +7 -5
  138. package/src/useLexicalTextEntity.ts +2 -5
@@ -5,8 +5,8 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  *
7
7
  */
8
+ import type { AnyLexicalExtension, LexicalExtensionOutput } from 'lexical';
8
9
  import type { ComponentProps } from 'react';
9
- import { type AnyLexicalExtension, type LexicalExtensionOutput } from 'lexical';
10
10
  /**
11
11
  * The lexical:extension prop combined with the props of the given Extension's
12
12
  * output Component.
@@ -5,10 +5,9 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  *
7
7
  */
8
- import type { CommandListenerPriority, LexicalNode } from 'lexical';
9
- import type { JSX } from 'react';
10
8
  import { MenuOption, type MenuRenderFn } from '@lexical/react/LexicalNodeMenuPlugin';
11
- import { LexicalCommand, LexicalEditor } from 'lexical';
9
+ import { type CommandListenerPriority, type LexicalCommand, type LexicalEditor, type LexicalNode } from 'lexical';
10
+ import { type JSX } from 'react';
12
11
  /**
13
12
  * The result of matching a URL for an embed: the matched `url`, an `id`
14
13
  * identifying the embedded resource, and optional provider-specific `data`.
@@ -5,9 +5,9 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  *
7
7
  */
8
- import type { ChangeHandler, LinkMatcher } from '@lexical/link';
9
8
  import type { ElementNode } from 'lexical';
10
- import type { JSX } from 'react';
9
+ import { type ChangeHandler, type LinkMatcher } from '@lexical/link';
10
+ import { type JSX } from 'react';
11
11
  export { type ChangeHandler, createLinkMatcherWithRegExp, type LinkMatcher, } from '@lexical/link';
12
12
  /**
13
13
  * Automatically converts text that matches one of the provided `matchers` into
@@ -5,9 +5,8 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  *
7
7
  */
8
- import type { ElementFormatType, NodeKey } from 'lexical';
9
- import type { JSX } from 'react';
10
- import { ReactNode } from 'react';
8
+ import { type ElementFormatType, type NodeKey } from 'lexical';
9
+ import { type JSX, type ReactNode } from 'react';
11
10
  type Props = Readonly<{
12
11
  children: ReactNode;
13
12
  format?: ElementFormatType | null;
@@ -5,7 +5,7 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  *
7
7
  */
8
- import type { JSX } from 'react';
8
+ import { type JSX } from 'react';
9
9
  /**
10
10
  * Tracks the length of the editor's text content against `maxLength` and
11
11
  * renders the number of remaining characters, marking any overflowing text so
@@ -255,10 +255,12 @@ function $mergePrevious(overflowNode) {
255
255
  const CHARACTER_LIMIT = 5;
256
256
  let textEncoderInstance = null;
257
257
  function textEncoder() {
258
+ // eslint-disable-next-line no-restricted-syntax
258
259
  if (window.TextEncoder === undefined) {
259
260
  return null;
260
261
  }
261
262
  if (textEncoderInstance === null) {
263
+ // eslint-disable-next-line no-restricted-syntax
262
264
  textEncoderInstance = new window.TextEncoder();
263
265
  }
264
266
  return textEncoderInstance;
@@ -253,10 +253,12 @@ function $mergePrevious(overflowNode) {
253
253
  const CHARACTER_LIMIT = 5;
254
254
  let textEncoderInstance = null;
255
255
  function textEncoder() {
256
+ // eslint-disable-next-line no-restricted-syntax
256
257
  if (window.TextEncoder === undefined) {
257
258
  return null;
258
259
  }
259
260
  if (textEncoderInstance === null) {
261
+ // eslint-disable-next-line no-restricted-syntax
260
262
  textEncoderInstance = new window.TextEncoder();
261
263
  }
262
264
  return textEncoderInstance;
@@ -6,5 +6,5 @@
6
6
  *
7
7
  */
8
8
 
9
- "use strict";var e=require("@lexical/react/LexicalComposerContext"),t=require("react"),n=require("@lexical/overflow"),r=require("@lexical/text"),i=require("@lexical/utils"),o=require("lexical"),s=require("react/jsx-runtime");function l(e,s,l=Object.freeze({})){const{strlen:f=e=>e.length,remainingCharacters:g=()=>{}}=l;t.useEffect(()=>{e.hasNodes([n.OverflowNode])||function(e,...t){const n=new URL("https://lexical.dev/docs/error"),r=new URLSearchParams;r.append("code",e);for(const e of t)r.append("v",e);throw n.search=r.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.`)}(57)},[e]),t.useEffect(()=>{let t=e.read("latest",r.$rootTextContent),l=0;return o.mergeRegister(e.registerTextContentListener(e=>{t=e}),e.registerUpdateListener(({dirtyLeaves:r,dirtyElements:u})=>{const d=e.isComposing(),h=r.size>0||u.size>0;if(d||!h)return;const m=f(t),x=m>s||null!==l&&l>s;if(g(s-m),null===l||x){const r=function(e,t,n){let r=0,i=0;if("function"==typeof Intl.Segmenter){const o=(new Intl.Segmenter).segment(e);for(const{segment:e}of o){const o=i+n(e);if(o>t)break;i=o,r+=e.length}}else{const o=Array.from(e),s=o.length;for(let e=0;e<s;e++){const s=o[e],l=i+n(s);if(l>t)break;i=l,r+=s.length}}return r}(t,s,f);e.update(()=>{!function(e){const t=i.$dfsWithSlots(),r=t.length;let s=0;for(let l=0;l<r;l+=1){const{node:r}=t[l],f=o.$isLeafNode(r)&&null!==o.$getSlotHost(r),g=o.$isLeafNode(r)&&!f&&!o.$findMatchingParent(r,n.$isOverflowNode);if(n.$isOverflowNode(r)){const t=s;if(s+r.getTextContentSize()<=e){const e=r.getParent(),t=r.getPreviousSibling(),n=r.getNextSibling();i.$unwrapNode(r);const s=o.$getSelection();!o.$isRangeSelection(s)||s.anchor.getNode().isAttached()&&s.focus.getNode().isAttached()||(o.$isTextNode(t)?t.select():o.$isTextNode(n)?n.select():null!==e&&e.select())}else if(t<e){const n=r.getFirstDescendant(),s=t+(null!==n?n.getTextContentSize():0);(o.$isTextNode(n)&&n.isSimpleText()||s<=e)&&i.$unwrapNode(r)}}else if(f)s+=r.getTextContentSize();else if(g){const t=s;if(s+=r.getTextContentSize(),s>e&&!n.$isOverflowNode(r.getParent())){const n=o.$getSelection();let i;if(t<e&&o.$isTextNode(r)&&r.isSimpleText()){const[,n]=r.splitText(e-t);i=c(n)}else i=c(r);null!==n&&o.$setSelection(n),a(i)}}}}(r)},{tag:o.HISTORY_MERGE_TAG})}l=m}),e.registerCommand(o.DELETE_CHARACTER_COMMAND,e=>{const t=o.$getSelection();if(!o.$isRangeSelection(t))return!1;const n=t.anchor.getNode().getParent(),r=n?n.getParent():null,i=r?r.getNextSibling():null;return t.deleteCharacter(e),r&&r.isEmpty()?r.remove():o.$isElementNode(i)&&i.isEmpty()&&i.remove(),!0},o.COMMAND_PRIORITY_LOW))},[e,s,g,f])}function c(e){const t=n.$createOverflowNode();return e.replace(t),t.append(e),t}function a(e){const t=e.getPreviousSibling();if(!n.$isOverflowNode(t))return;const r=e.getFirstChild(),i=t.getChildren(),s=i.length;if(null===r)e.append(...i);else for(let e=0;e<s;e++)r.insertBefore(i[e]);const l=o.$getSelection();if(o.$isRangeSelection(l)){const n=l.anchor,r=n.getNode(),i=l.focus,o=n.getNode();r.is(t)?n.set(e.getKey(),n.offset,"element"):r.is(e)&&n.set(e.getKey(),s+n.offset,"element"),o.is(t)?i.set(e.getKey(),i.offset,"element"):o.is(e)&&i.set(e.getKey(),s+i.offset,"element")}t.remove()}let f=null;function g(e){const t=void 0===window.TextEncoder?null:(null===f&&(f=new window.TextEncoder),f);if(null===t){const t=encodeURIComponent(e).match(/%[89ABab]/g);return e.length+(t?t.length:0)}return t.encode(e).length}function u({remainingCharacters:e}){/*#__PURE__*/
9
+ "use strict";var e=require("@lexical/react/LexicalComposerContext"),t=require("react"),n=require("@lexical/overflow"),r=require("@lexical/text"),i=require("@lexical/utils"),o=require("lexical"),s=require("react/jsx-runtime");function l(e,s,l=Object.freeze({})){const{strlen:f=e=>e.length,remainingCharacters:g=()=>{}}=l;t.useEffect(()=>{e.hasNodes([n.OverflowNode])||function(e,...t){const n=new URL("https://lexical.dev/docs/error"),r=new URLSearchParams;r.append("code",e);for(const e of t)r.append("v",e);throw n.search=r.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.`)}(57)},[e]),t.useEffect(()=>{let t=e.read("latest",r.$rootTextContent),l=0;return o.mergeRegister(e.registerTextContentListener(e=>{t=e}),e.registerUpdateListener(({dirtyLeaves:r,dirtyElements:u})=>{const d=e.isComposing(),h=r.size>0||u.size>0;if(d||!h)return;const m=f(t),x=m>s||null!==l&&l>s;if(g(s-m),null===l||x){const r=function(e,t,n){let r=0,i=0;if("function"==typeof Intl.Segmenter){const o=(new Intl.Segmenter).segment(e);for(const{segment:e}of o){const o=i+n(e);if(o>t)break;i=o,r+=e.length}}else{const o=Array.from(e),s=o.length;for(let e=0;e<s;e++){const s=o[e],l=i+n(s);if(l>t)break;i=l,r+=s.length}}return r}(t,s,f);e.update(()=>{!function(e){const t=i.$dfsWithSlots(),r=t.length;let s=0;for(let l=0;l<r;l+=1){const{node:r}=t[l],f=o.$isLeafNode(r)&&null!==o.$getSlotHost(r),g=o.$isLeafNode(r)&&!f&&!o.$findMatchingParent(r,n.$isOverflowNode);if(n.$isOverflowNode(r)){const t=s;if(s+r.getTextContentSize()<=e){const e=r.getParent(),t=r.getPreviousSibling(),n=r.getNextSibling();i.$unwrapNode(r);const s=o.$getSelection();!o.$isRangeSelection(s)||s.anchor.getNode().isAttached()&&s.focus.getNode().isAttached()||(o.$isTextNode(t)?t.select():o.$isTextNode(n)?n.select():null!==e&&e.select())}else if(t<e){const n=r.getFirstDescendant(),s=t+(null!==n?n.getTextContentSize():0);(o.$isTextNode(n)&&n.isSimpleText()||s<=e)&&i.$unwrapNode(r)}}else if(f)s+=r.getTextContentSize();else if(g){const t=s;if(s+=r.getTextContentSize(),s>e&&!n.$isOverflowNode(r.getParent())){const n=o.$getSelection();let i;if(t<e&&o.$isTextNode(r)&&r.isSimpleText()){const[,n]=r.splitText(e-t);i=c(n)}else i=c(r);null!==n&&o.$setSelection(n),a(i)}}}}(r)},{tag:o.HISTORY_MERGE_TAG})}l=m}),e.registerCommand(o.DELETE_CHARACTER_COMMAND,e=>{const t=o.$getSelection();if(!o.$isRangeSelection(t))return!1;const n=t.anchor.getNode().getParent(),r=n?n.getParent():null,i=r?r.getNextSibling():null;return t.deleteCharacter(e),r&&r.isEmpty()?r.remove():o.$isElementNode(i)&&i.isEmpty()&&i.remove(),!0},o.COMMAND_PRIORITY_LOW))},[e,s,g,f])}function c(e){const t=n.$createOverflowNode();return e.replace(t),t.append(e),t}function a(e){const t=e.getPreviousSibling();if(!n.$isOverflowNode(t))return;const r=e.getFirstChild(),i=t.getChildren(),s=i.length;if(null===r)e.append(...i);else for(let e=0;e<s;e++)r.insertBefore(i[e]);const l=o.$getSelection();if(o.$isRangeSelection(l)){const n=l.anchor,r=n.getNode(),i=l.focus,o=n.getNode();r.is(t)?n.set(e.getKey(),n.offset,"element"):r.is(e)&&n.set(e.getKey(),s+n.offset,"element"),o.is(t)?i.set(e.getKey(),i.offset,"element"):o.is(e)&&i.set(e.getKey(),s+i.offset,"element")}t.remove()}let f=null;function g(e){const t=void 0===window.TextEncoder?null:(null===f&&(f=new window.TextEncoder),f);if(null===t){const t=encodeURIComponent(e).match(/%[89ABab]/g);return e.length+(t?t.length:0)}return t.encode(e).length}function u({remainingCharacters:e}){
10
10
  return s.jsx("span",{className:"characters-limit "+(e<0?"characters-limit-exceeded":""),children:e})}exports.CharacterLimitPlugin=function({charset:n="UTF-16",maxLength:r=5,renderer:i=u}){const[o]=e.useLexicalComposerContext(),[s,c]=t.useState(r),a=t.useMemo(()=>({remainingCharacters:c,strlen:e=>{if("UTF-8"===n)return g(e);if("UTF-16"===n)return e.length;throw new Error("Unrecognized charset")}}),[n]);return l(o,r,a),i({remainingCharacters:s})};
@@ -6,5 +6,5 @@
6
6
  *
7
7
  */
8
8
 
9
- import{useLexicalComposerContext as e}from"@lexical/react/LexicalComposerContext";import{useEffect as t,useState as n,useMemo as r}from"react";import{OverflowNode as o,$isOverflowNode as i,$createOverflowNode as s}from"@lexical/overflow";import{$rootTextContent as l}from"@lexical/text";import{$dfsWithSlots as c,$unwrapNode as a}from"@lexical/utils";import{mergeRegister as f,HISTORY_MERGE_TAG as g,DELETE_CHARACTER_COMMAND as m,$getSelection as u,$isRangeSelection as d,$isElementNode as h,COMMAND_PRIORITY_LOW as p,$isLeafNode as x,$getSlotHost as C,$findMatchingParent as S,$isTextNode as v,$setSelection as w}from"lexical";import{jsx as T}from"react/jsx-runtime";function y(e,n,r=Object.freeze({})){const{strlen:s=e=>e.length,remainingCharacters:T=()=>{}}=r;t(()=>{e.hasNodes([o])||function(e,...t){const n=new URL("https://lexical.dev/docs/error"),r=new URLSearchParams;r.append("code",e);for(const e of t)r.append("v",e);throw n.search=r.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.`)}(57)},[e]),t(()=>{let t=e.read("latest",l),r=0;return f(e.registerTextContentListener(e=>{t=e}),e.registerUpdateListener(({dirtyLeaves:o,dirtyElements:l})=>{const f=e.isComposing(),m=o.size>0||l.size>0;if(f||!m)return;const h=s(t),p=h>n||null!==r&&r>n;if(T(n-h),null===r||p){const r=function(e,t,n){let r=0,o=0;if("function"==typeof Intl.Segmenter){const i=(new Intl.Segmenter).segment(e);for(const{segment:e}of i){const i=o+n(e);if(i>t)break;o=i,r+=e.length}}else{const i=Array.from(e),s=i.length;for(let e=0;e<s;e++){const s=i[e],l=o+n(s);if(l>t)break;o=l,r+=s.length}}return r}(t,n,s);e.update(()=>{!function(e){const t=c(),n=t.length;let r=0;for(let o=0;o<n;o+=1){const{node:n}=t[o],s=x(n)&&null!==C(n),l=x(n)&&!s&&!S(n,i);if(i(n)){const t=r;if(r+n.getTextContentSize()<=e){const e=n.getParent(),t=n.getPreviousSibling(),r=n.getNextSibling();a(n);const o=u();!d(o)||o.anchor.getNode().isAttached()&&o.focus.getNode().isAttached()||(v(t)?t.select():v(r)?r.select():null!==e&&e.select())}else if(t<e){const r=n.getFirstDescendant(),o=t+(null!==r?r.getTextContentSize():0);(v(r)&&r.isSimpleText()||o<=e)&&a(n)}}else if(s)r+=n.getTextContentSize();else if(l){const t=r;if(r+=n.getTextContentSize(),r>e&&!i(n.getParent())){const r=u();let o;if(t<e&&v(n)&&n.isSimpleText()){const[,r]=n.splitText(e-t);o=N(r)}else o=N(n);null!==r&&w(r),b(o)}}}}(r)},{tag:g})}r=h}),e.registerCommand(m,e=>{const t=u();if(!d(t))return!1;const n=t.anchor.getNode().getParent(),r=n?n.getParent():null,o=r?r.getNextSibling():null;return t.deleteCharacter(e),r&&r.isEmpty()?r.remove():h(o)&&o.isEmpty()&&o.remove(),!0},p))},[e,n,T,s])}function N(e){const t=s();return e.replace(t),t.append(e),t}function b(e){const t=e.getPreviousSibling();if(!i(t))return;const n=e.getFirstChild(),r=t.getChildren(),o=r.length;if(null===n)e.append(...r);else for(let e=0;e<o;e++)n.insertBefore(r[e]);const s=u();if(d(s)){const n=s.anchor,r=n.getNode(),i=s.focus,l=n.getNode();r.is(t)?n.set(e.getKey(),n.offset,"element"):r.is(e)&&n.set(e.getKey(),o+n.offset,"element"),l.is(t)?i.set(e.getKey(),i.offset,"element"):l.is(e)&&i.set(e.getKey(),o+i.offset,"element")}t.remove()}let z=null;function L(e){const t=void 0===window.TextEncoder?null:(null===z&&(z=new window.TextEncoder),z);if(null===t){const t=encodeURIComponent(e).match(/%[89ABab]/g);return e.length+(t?t.length:0)}return t.encode(e).length}function U({remainingCharacters:e}){/*#__PURE__*/
9
+ import{useLexicalComposerContext as e}from"@lexical/react/LexicalComposerContext";import{useEffect as t,useState as n,useMemo as r}from"react";import{OverflowNode as o,$isOverflowNode as i,$createOverflowNode as s}from"@lexical/overflow";import{$rootTextContent as l}from"@lexical/text";import{$dfsWithSlots as c,$unwrapNode as a}from"@lexical/utils";import{mergeRegister as f,HISTORY_MERGE_TAG as g,DELETE_CHARACTER_COMMAND as m,$getSelection as u,$isRangeSelection as d,$isElementNode as h,COMMAND_PRIORITY_LOW as p,$isLeafNode as x,$getSlotHost as C,$findMatchingParent as S,$isTextNode as v,$setSelection as w}from"lexical";import{jsx as T}from"react/jsx-runtime";function y(e,n,r=Object.freeze({})){const{strlen:s=e=>e.length,remainingCharacters:T=()=>{}}=r;t(()=>{e.hasNodes([o])||function(e,...t){const n=new URL("https://lexical.dev/docs/error"),r=new URLSearchParams;r.append("code",e);for(const e of t)r.append("v",e);throw n.search=r.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.`)}(57)},[e]),t(()=>{let t=e.read("latest",l),r=0;return f(e.registerTextContentListener(e=>{t=e}),e.registerUpdateListener(({dirtyLeaves:o,dirtyElements:l})=>{const f=e.isComposing(),m=o.size>0||l.size>0;if(f||!m)return;const h=s(t),p=h>n||null!==r&&r>n;if(T(n-h),null===r||p){const r=function(e,t,n){let r=0,o=0;if("function"==typeof Intl.Segmenter){const i=(new Intl.Segmenter).segment(e);for(const{segment:e}of i){const i=o+n(e);if(i>t)break;o=i,r+=e.length}}else{const i=Array.from(e),s=i.length;for(let e=0;e<s;e++){const s=i[e],l=o+n(s);if(l>t)break;o=l,r+=s.length}}return r}(t,n,s);e.update(()=>{!function(e){const t=c(),n=t.length;let r=0;for(let o=0;o<n;o+=1){const{node:n}=t[o],s=x(n)&&null!==C(n),l=x(n)&&!s&&!S(n,i);if(i(n)){const t=r;if(r+n.getTextContentSize()<=e){const e=n.getParent(),t=n.getPreviousSibling(),r=n.getNextSibling();a(n);const o=u();!d(o)||o.anchor.getNode().isAttached()&&o.focus.getNode().isAttached()||(v(t)?t.select():v(r)?r.select():null!==e&&e.select())}else if(t<e){const r=n.getFirstDescendant(),o=t+(null!==r?r.getTextContentSize():0);(v(r)&&r.isSimpleText()||o<=e)&&a(n)}}else if(s)r+=n.getTextContentSize();else if(l){const t=r;if(r+=n.getTextContentSize(),r>e&&!i(n.getParent())){const r=u();let o;if(t<e&&v(n)&&n.isSimpleText()){const[,r]=n.splitText(e-t);o=N(r)}else o=N(n);null!==r&&w(r),b(o)}}}}(r)},{tag:g})}r=h}),e.registerCommand(m,e=>{const t=u();if(!d(t))return!1;const n=t.anchor.getNode().getParent(),r=n?n.getParent():null,o=r?r.getNextSibling():null;return t.deleteCharacter(e),r&&r.isEmpty()?r.remove():h(o)&&o.isEmpty()&&o.remove(),!0},p))},[e,n,T,s])}function N(e){const t=s();return e.replace(t),t.append(e),t}function b(e){const t=e.getPreviousSibling();if(!i(t))return;const n=e.getFirstChild(),r=t.getChildren(),o=r.length;if(null===n)e.append(...r);else for(let e=0;e<o;e++)n.insertBefore(r[e]);const s=u();if(d(s)){const n=s.anchor,r=n.getNode(),i=s.focus,l=n.getNode();r.is(t)?n.set(e.getKey(),n.offset,"element"):r.is(e)&&n.set(e.getKey(),o+n.offset,"element"),l.is(t)?i.set(e.getKey(),i.offset,"element"):l.is(e)&&i.set(e.getKey(),o+i.offset,"element")}t.remove()}let z=null;function L(e){const t=void 0===window.TextEncoder?null:(null===z&&(z=new window.TextEncoder),z);if(null===t){const t=encodeURIComponent(e).match(/%[89ABab]/g);return e.length+(t?t.length:0)}return t.encode(e).length}function U({remainingCharacters:e}){
10
10
  return T("span",{className:"characters-limit "+(e<0?"characters-limit-exceeded":""),children:e})}function E({charset:t="UTF-16",maxLength:o=5,renderer:i=U}){const[s]=e(),[l,c]=n(o);return y(s,o,r(()=>({remainingCharacters:c,strlen:e=>{if("UTF-8"===t)return L(e);if("UTF-16"===t)return e.length;throw new Error("Unrecognized charset")}}),[t])),i({remainingCharacters:l})}export{E as CharacterLimitPlugin};
@@ -6,5 +6,5 @@
6
6
  *
7
7
  */
8
8
 
9
- "use strict";var r=require("react"),e=require("react/jsx-runtime");const o=[["Cat","rgb(125, 50, 0)"],["Dog","rgb(100, 0, 0)"],["Rabbit","rgb(150, 0, 0)"],["Frog","rgb(200, 0, 0)"],["Fox","rgb(200, 75, 0)"],["Hedgehog","rgb(0, 75, 0)"],["Pigeon","rgb(0, 125, 0)"],["Squirrel","rgb(75, 100, 0)"],["Bear","rgb(125, 100, 0)"],["Tiger","rgb(0, 0, 150)"],["Leopard","rgb(0, 0, 200)"],["Zebra","rgb(0, 0, 250)"],["Wolf","rgb(0, 100, 150)"],["Owl","rgb(0, 100, 100)"],["Gull","rgb(100, 0, 100)"],["Squid","rgb(150, 0, 150)"]],n=o[Math.floor(Math.random()*o.length)],t=/*#__PURE__*/r.createContext(null);function l(){return{color:n[1],isCollabActive:!1,name:n[0],yjsDocMap:new Map}}const a=l();exports.CollaborationContext=t,exports.LexicalCollaboration=function({children:o}){const n=r.useMemo(()=>l(),[]);/*#__PURE__*/
9
+ "use strict";var r=require("react"),e=require("react/jsx-runtime");const o=[["Cat","rgb(125, 50, 0)"],["Dog","rgb(100, 0, 0)"],["Rabbit","rgb(150, 0, 0)"],["Frog","rgb(200, 0, 0)"],["Fox","rgb(200, 75, 0)"],["Hedgehog","rgb(0, 75, 0)"],["Pigeon","rgb(0, 125, 0)"],["Squirrel","rgb(75, 100, 0)"],["Bear","rgb(125, 100, 0)"],["Tiger","rgb(0, 0, 150)"],["Leopard","rgb(0, 0, 200)"],["Zebra","rgb(0, 0, 250)"],["Wolf","rgb(0, 100, 150)"],["Owl","rgb(0, 100, 100)"],["Gull","rgb(100, 0, 100)"],["Squid","rgb(150, 0, 150)"]],n=o[Math.floor(Math.random()*o.length)],t=/*#__PURE__*/r.createContext(null);function l(){return{color:n[1],isCollabActive:!1,name:n[0],yjsDocMap:new Map}}const a=l();exports.CollaborationContext=t,exports.LexicalCollaboration=function({children:o}){const n=r.useMemo(()=>l(),[]);
10
10
  return e.jsx(t.Provider,{value:n,children:o})},exports.useCollaborationContext=function(e,o){let n=r.useContext(t);return null==n&&function(r,...e){const o=new URL("https://lexical.dev/docs/error"),n=new URLSearchParams;n.append("code",r);for(const r of e)n.append("v",r);o.search=n.toString(),console.warn(`Minified Lexical warning #${r}; visit ${o.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}(319),n=n??a,null!=e&&(n.name=e),null!=o&&(n.color=o),n};
@@ -6,5 +6,5 @@
6
6
  *
7
7
  */
8
8
 
9
- import{createContext as r,useMemo as n,useContext as e}from"react";import{jsx as o}from"react/jsx-runtime";const t=[["Cat","rgb(125, 50, 0)"],["Dog","rgb(100, 0, 0)"],["Rabbit","rgb(150, 0, 0)"],["Frog","rgb(200, 0, 0)"],["Fox","rgb(200, 75, 0)"],["Hedgehog","rgb(0, 75, 0)"],["Pigeon","rgb(0, 125, 0)"],["Squirrel","rgb(75, 100, 0)"],["Bear","rgb(125, 100, 0)"],["Tiger","rgb(0, 0, 150)"],["Leopard","rgb(0, 0, 200)"],["Zebra","rgb(0, 0, 250)"],["Wolf","rgb(0, 100, 150)"],["Owl","rgb(0, 100, 100)"],["Gull","rgb(100, 0, 100)"],["Squid","rgb(150, 0, 150)"]],i=t[Math.floor(Math.random()*t.length)],l=/*#__PURE__*/r(null);function a(){return{color:i[1],isCollabActive:!1,name:i[0],yjsDocMap:new Map}}const g=a();function c({children:r}){const e=n(()=>a(),[]);/*#__PURE__*/
9
+ import{createContext as r,useMemo as n,useContext as e}from"react";import{jsx as o}from"react/jsx-runtime";const t=[["Cat","rgb(125, 50, 0)"],["Dog","rgb(100, 0, 0)"],["Rabbit","rgb(150, 0, 0)"],["Frog","rgb(200, 0, 0)"],["Fox","rgb(200, 75, 0)"],["Hedgehog","rgb(0, 75, 0)"],["Pigeon","rgb(0, 125, 0)"],["Squirrel","rgb(75, 100, 0)"],["Bear","rgb(125, 100, 0)"],["Tiger","rgb(0, 0, 150)"],["Leopard","rgb(0, 0, 200)"],["Zebra","rgb(0, 0, 250)"],["Wolf","rgb(0, 100, 150)"],["Owl","rgb(0, 100, 100)"],["Gull","rgb(100, 0, 100)"],["Squid","rgb(150, 0, 150)"]],i=t[Math.floor(Math.random()*t.length)],l=/*#__PURE__*/r(null);function a(){return{color:i[1],isCollabActive:!1,name:i[0],yjsDocMap:new Map}}const g=a();function c({children:r}){const e=n(()=>a(),[]);
10
10
  return o(l.Provider,{value:e,children:r})}function b(r,n){let o=e(l);return null==o&&function(r,...n){const e=new URL("https://lexical.dev/docs/error"),o=new URLSearchParams;o.append("code",r);for(const r of n)o.append("v",r);e.search=o.toString(),console.warn(`Minified Lexical warning #${r}; visit ${e.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}(319),o=o??g,null!=r&&(o.name=r),null!=n&&(o.color=n),o}export{l as CollaborationContext,c as LexicalCollaboration,b as useCollaborationContext};
@@ -5,11 +5,11 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  *
7
7
  */
8
- import type { JSX } from 'react';
9
- import { ExcludedProperties, Provider, SyncCursorPositionsFn } from '@lexical/yjs';
10
- import { Doc } from 'yjs';
11
- import { InitialEditorStateType } from './LexicalComposer';
12
- import { CursorsContainerRef } from './shared/useYjsCollaboration';
8
+ import type { InitialEditorStateType } from './LexicalComposer';
9
+ import type { Doc } from 'yjs';
10
+ import { type ExcludedProperties, type Provider, type SyncCursorPositionsFn } from '@lexical/yjs';
11
+ import { type JSX } from 'react';
12
+ import { type CursorsContainerRef } from './shared/useYjsCollaboration';
13
13
  type ProviderFactory = (id: string, yjsDocMap: Map<string, Doc>) => Provider;
14
14
  type CollaborationPluginProps = {
15
15
  id: string;
@@ -311,7 +311,9 @@ function useYjsCursors(binding, cursorsContainerRef) {
311
311
  };
312
312
  return /*#__PURE__*/reactDom.createPortal(/*#__PURE__*/jsxRuntime.jsx("div", {
313
313
  ref: ref
314
- }), cursorsContainerRef && cursorsContainerRef.current || document.body);
314
+ }),
315
+ // eslint-disable-next-line no-restricted-syntax
316
+ cursorsContainerRef && cursorsContainerRef.current || document.body);
315
317
  }, [binding, cursorsContainerRef]);
316
318
  }
317
319
  function useYjsFocusTracking(editor, provider, name, color, awarenessData) {
@@ -419,10 +421,8 @@ function initializeEditor(editor, initialEditorState) {
419
421
  } else {
420
422
  const paragraph = lexical.$createParagraphNode();
421
423
  root.append(paragraph);
422
- const {
423
- activeElement
424
- } = document;
425
- if (lexical.$getSelection() !== null || activeElement !== null && activeElement === editor.getRootElement()) {
424
+ const rootElement = editor.getRootElement();
425
+ if (lexical.$getSelection() !== null || rootElement !== null && lexical.getActiveElement(rootElement) === rootElement) {
426
426
  paragraph.select();
427
427
  }
428
428
  }
@@ -297,7 +297,9 @@ function useYjsCursors(binding, cursorsContainerRef) {
297
297
  };
298
298
  return /*#__PURE__*/createPortal(/*#__PURE__*/jsx("div", {
299
299
  ref: ref
300
- }), cursorsContainerRef && cursorsContainerRef.current || document.body);
300
+ }),
301
+ // eslint-disable-next-line no-restricted-syntax
302
+ cursorsContainerRef && cursorsContainerRef.current || document.body);
301
303
  }, [binding, cursorsContainerRef]);
302
304
  }
303
305
  function useYjsFocusTracking(editor, provider, name, color, awarenessData) {
@@ -405,10 +407,8 @@ function initializeEditor(editor, initialEditorState) {
405
407
  } else {
406
408
  const paragraph = $createParagraphNode();
407
409
  root.append(paragraph);
408
- const {
409
- activeElement
410
- } = document;
411
- if ($getSelection() !== null || activeElement !== null && activeElement === editor.getRootElement()) {
410
+ const rootElement = editor.getRootElement();
411
+ if ($getSelection() !== null || rootElement !== null && getActiveElement(rootElement) === rootElement) {
412
412
  paragraph.select();
413
413
  }
414
414
  }
@@ -6,4 +6,4 @@
6
6
  *
7
7
  */
8
8
 
9
- "use strict";var e=require("@lexical/react/LexicalCollaborationContext"),t=require("@lexical/react/LexicalComposerContext"),o=require("@lexical/yjs"),r=require("react"),n=require("lexical"),s=require("react-dom"),a=require("yjs"),c=require("react/jsx-runtime");function i(e){var t=Object.create(null);if(e)for(var o in e)t[o]=e[o];return t.default=e,t}var l=/*#__PURE__*/i(r);const u=Symbol.for("@lexical/yjs/UndoManager");function d(e,t,s,c,i,l,u,d,C,p,m,h,M=o.syncCursorPositions,R=!1){const O=r.useRef(!1),D=r.useCallback(()=>{const{root:t}=d;u&&t.isEmpty()&&0===t._xmlText._length&&_(e,m)},[d,e,m,u]);return r.useEffect(()=>{const{root:t}=d,r=(e,t)=>{const r=t.origin;if(r!==d){const t=r instanceof a.UndoManager;o.syncYjsChangesToLexical(d,s,e,t,M)}};t.getSharedType().observeDeep(r);const c=e.registerUpdateListener(({prevEditorState:e,editorState:t,dirtyLeaves:r,dirtyElements:a,normalizedNodes:c,tags:i})=>{i.has(n.SKIP_COLLAB_TAG)||o.syncLexicalUpdateToYjs(d,s,e,t,a,r,c,i)});return()=>{t.getSharedType().unobserveDeep(r),c()}},[d,s,e,C,c,t,M]),r.useEffect(()=>{const r=r=>{!function(e,t){if(e.update(()=>{const e=n.$getRoot();e.clear(),e.select()},{tag:n.SKIP_COLLAB_TAG}),null==t.cursors)return;const r=t.cursors;if(null==r)return;const s=t.cursorsContainer;if(null==s)return;for(const e of r.values()){const r=e.selection;if(null!==r){null!==r.highlight&&(CSS.highlights.delete(r.highlightName),o.removeCursorHighlightRule(t,r.highlightName)),r.caret.parentNode===s&&s.removeChild(r.caret);for(const e of r.selections)e.parentNode===s&&s.removeChild(e);e.selection=null}}}(e,d),C(r),c.set(t,r),O.current=!0},a=()=>{O.current=!1};return s.on("reload",r),s.on("sync",a),()=>{s.off("reload",r),s.off("sync",a)}},[d,s,e,C,c,t]),f(e,s,i,l,O,h,D),g(d,s,R),E(d,p)}function f(e,t,s,a,c,i,l){const u=r.useCallback(()=>t.connect(),[t]),d=r.useCallback(()=>{try{t.disconnect()}catch(e){}},[t]);r.useEffect(()=>{const r=({status:t})=>{e.dispatchCommand(o.CONNECTED_COMMAND,"connected"===t)},f=e=>{e&&!1===c.current&&l&&l()},g=e.getRootElement();o.initLocalState(t,s,a,null!==g&&n.getActiveElement(g)===g,i||{}),t.on("status",r),t.on("sync",f);const E=u();return()=>{!1===c.current&&(E?E.then(d):d()),t.off("sync",f),t.off("status",r)}},[e,t,s,a,c,i,l,u,d]),r.useEffect(()=>e.registerCommand(o.TOGGLE_CONNECT_COMMAND,e=>(e?(console.log("Collaboration connected!"),u()):(console.log("Collaboration disconnected!"),d()),!0),n.COMMAND_PRIORITY_EDITOR),[u,d,e]),r.useEffect(()=>{const e=()=>{try{t.awareness.setLocalState(null)}catch(e){}};return n.registerEventListeners(window,{beforeunload:e,pagehide:e})},[t])}function g(e,t,n){r.useEffect(()=>{const{awareness:r}=t,s=()=>{o.syncCursorPositions(e,t,{selectionHighlight:n})};return r.on("update",s),()=>{r.off("update",s)}},[e,t,n])}function E(e,t){return r.useMemo(()=>/*#__PURE__*/s.createPortal(/*#__PURE__*/c.jsx("div",{ref:t=>{e.cursorsContainer=t}}),t&&t.current||document.body),[e,t])}function C(e,t,s,a,c){r.useEffect(()=>n.mergeRegister(e.registerCommand(n.FOCUS_COMMAND,()=>(o.setLocalStateFocus(t,s,a,!0,c||{}),!1),n.COMMAND_PRIORITY_EDITOR),e.registerCommand(n.BLUR_COMMAND,()=>(o.setLocalStateFocus(t,s,a,!1,c||{}),!1),n.COMMAND_PRIORITY_EDITOR)),[a,e,s,t,c])}function p(e,t){r.useEffect(()=>n.mergeRegister(e.registerCommand(n.UNDO_COMMAND,()=>(t.undo(),!0),n.COMMAND_PRIORITY_EDITOR),e.registerCommand(n.REDO_COMMAND,()=>(t.redo(),!0),n.COMMAND_PRIORITY_EDITOR))),r.useEffect(()=>{const o=e;return o[u]=t,()=>{o[u]===t&&delete o[u]}},[e,t]);const o=r.useCallback(()=>{t.clear()},[t]);return l.useEffect(()=>{const o=()=>{e.dispatchCommand(n.CAN_UNDO_COMMAND,t.undoStack.length>0),e.dispatchCommand(n.CAN_REDO_COMMAND,t.redoStack.length>0)};return t.on("stack-item-added",o),t.on("stack-item-popped",o),t.on("stack-cleared",o),()=>{t.off("stack-item-added",o),t.off("stack-item-popped",o),t.off("stack-cleared",o)}},[e,t]),o}function _(e,t){e.update(()=>{const o=n.$getRoot();if(o.isEmpty())if(t)switch(typeof t){case"string":{const o=e.parseEditorState(t);e.setEditorState(o,{tag:n.HISTORY_MERGE_TAG});break}case"object":e.setEditorState(t,{tag:n.HISTORY_MERGE_TAG});break;case"function":e.update(()=>{n.$getRoot().isEmpty()&&t(e)},{tag:n.HISTORY_MERGE_TAG})}else{const t=n.$createParagraphNode();o.append(t);const{activeElement:r}=document;(null!==n.$getSelection()||null!==r&&r===e.getRootElement())&&t.select()}},{tag:n.HISTORY_MERGE_TAG})}function m({editor:e,id:t,provider:n,yjsDocMap:s,name:a,color:c,shouldBootstrap:i,cursorsContainerRef:l,initialEditorState:u,awarenessData:f,collabContext:g,binding:E,setDoc:_,syncCursorPositionsFn:m,selectionHighlight:h}){const M=d(e,t,n,s,a,c,i,E,_,l,u,f,m,h);return function(e,t){p(e,r.useMemo(()=>o.createUndoManager(t,t.root.getSharedType()),[t]))}(e,E),C(e,n,a,c,f),M}const h=(e,t)=>{r.useEffect(()=>(e.isCollabActive=!0,()=>{null==t._parentEditor&&(e.isCollabActive=!1)}),[e,t])};exports.CollaborationPlugin=function({id:n,providerFactory:s,shouldBootstrap:a,username:i,cursorColor:l,cursorsContainerRef:u,initialEditorState:d,excludedProperties:f,awarenessData:g,syncCursorPositionsFn:E,selectionHighlight:C}){const p=r.useRef(!1),_=r.useRef(!1),M=e.useCollaborationContext(i,l),{yjsDocMap:R,name:O,color:D}=M,[T]=t.useLexicalComposerContext();h(M,T);const[N,S]=r.useState(),[A,I]=r.useState();r.useEffect(()=>{if(_.current)return;_.current=!0;const e=s(n,R);return S(e),I(R.get(n)),()=>{e.disconnect()}},[n,s,R]);const[y,x]=r.useState();return r.useEffect(()=>{if(!N)return;if(p.current)return;p.current=!0;const e=o.createBinding(T,N,n,A||R.get(n),R,f);return x(e),()=>{e.root.destroy(e)}},[T,N,n,R,A,f]),N&&y?/*#__PURE__*/c.jsx(m,{awarenessData:g,binding:y,collabContext:M,color:D,cursorsContainerRef:u,editor:T,id:n,initialEditorState:d,name:O,provider:N,setDoc:I,shouldBootstrap:a,yjsDocMap:R,syncCursorPositionsFn:E,selectionHighlight:C}):/*#__PURE__*/c.jsx(c.Fragment,{})},exports.CollaborationPluginV2__EXPERIMENTAL=function({id:s,doc:c,provider:i,__shouldBootstrapUnsafe:l,username:u,cursorColor:d,cursorsContainerRef:m,excludedProperties:M,awarenessData:R,selectionHighlight:O}){const D=e.useCollaborationContext(u,d),{yjsDocMap:T,name:N,color:S}=D,[A]=t.useLexicalComposerContext();h(D,A);const I=function(e,t,s,c,i,l,u,d={}){const{awarenessData:E,excludedProperties:C,rootName:p,selectionHighlight:m=!1,__shouldBootstrapUnsafe:h}=d,M=r.useMemo(()=>({current:!1}),[]),R=r.useMemo(()=>o.createBindingV2__EXPERIMENTAL(e,t,s,i,{excludedProperties:C,rootName:p}),[e,t,s,i,C,p]);r.useEffect(()=>(i.set(t,s),()=>{i.delete(t)}),[s,i,t]);const O=r.useCallback(()=>{const{root:t}=R;h&&0===t._length&&_(e)},[R,e,h]),[D,T]=r.useState();return r.useEffect(()=>{n.mergeRegister(e.registerCommand(o.CLEAR_DIFF_VERSIONS_COMMAND__EXPERIMENTAL,()=>(T(null),o.syncYjsStateToLexicalV2__EXPERIMENTAL(R,c),!0),n.COMMAND_PRIORITY_EDITOR),e.registerCommand(o.DIFF_VERSIONS_COMMAND__EXPERIMENTAL,({prevSnapshot:e,snapshot:t})=>(T({prevSnapshot:e,snapshot:t}),!0),n.COMMAND_PRIORITY_EDITOR))},[e,R,c]),r.useEffect(()=>{const{root:t}=R;if(D)return void o.renderSnapshot__EXPERIMENTAL(R,D.snapshot,D.prevSnapshot);const r=(e,t)=>{const r=t.origin;if(r!==R){const n=r instanceof a.UndoManager;o.syncYjsChangesToLexicalV2__EXPERIMENTAL(R,c,e,t,n)}};t.observeDeep(r);const s=e.registerUpdateListener(({prevEditorState:e,editorState:t,dirtyElements:r,dirtyLeaves:s,normalizedNodes:a,tags:i})=>{i.has(n.SKIP_COLLAB_TAG)||o.syncLexicalUpdateToYjsV2__EXPERIMENTAL(R,c,e,t,r,s,a,i)});return()=>{t.unobserveDeep(r),s()}},[R,c,e,D]),f(e,c,l,u,M,E,O),g(R,c,m),R}(A,s,c,i,T,N,S,{__shouldBootstrapUnsafe:l,awarenessData:R,excludedProperties:M,selectionHighlight:O});return function(e,t){p(e,r.useMemo(()=>o.createUndoManager(t,t.root),[t]))}(A,I),C(A,i,N,S,R),E(I,m)};
9
+ "use strict";var e=require("@lexical/react/LexicalCollaborationContext"),t=require("@lexical/react/LexicalComposerContext"),o=require("@lexical/yjs"),r=require("react"),n=require("lexical"),s=require("react-dom"),a=require("yjs"),c=require("react/jsx-runtime");function i(e){var t=Object.create(null);if(e)for(var o in e)t[o]=e[o];return t.default=e,t}var l=/*#__PURE__*/i(r);const u=Symbol.for("@lexical/yjs/UndoManager");function d(e,t,s,c,i,l,u,d,C,p,m,h,M=o.syncCursorPositions,R=!1){const O=r.useRef(!1),D=r.useCallback(()=>{const{root:t}=d;u&&t.isEmpty()&&0===t._xmlText._length&&_(e,m)},[d,e,m,u]);return r.useEffect(()=>{const{root:t}=d,r=(e,t)=>{const r=t.origin;if(r!==d){const t=r instanceof a.UndoManager;o.syncYjsChangesToLexical(d,s,e,t,M)}};t.getSharedType().observeDeep(r);const c=e.registerUpdateListener(({prevEditorState:e,editorState:t,dirtyLeaves:r,dirtyElements:a,normalizedNodes:c,tags:i})=>{i.has(n.SKIP_COLLAB_TAG)||o.syncLexicalUpdateToYjs(d,s,e,t,a,r,c,i)});return()=>{t.getSharedType().unobserveDeep(r),c()}},[d,s,e,C,c,t,M]),r.useEffect(()=>{const r=r=>{!function(e,t){if(e.update(()=>{const e=n.$getRoot();e.clear(),e.select()},{tag:n.SKIP_COLLAB_TAG}),null==t.cursors)return;const r=t.cursors;if(null==r)return;const s=t.cursorsContainer;if(null==s)return;for(const e of r.values()){const r=e.selection;if(null!==r){null!==r.highlight&&(CSS.highlights.delete(r.highlightName),o.removeCursorHighlightRule(t,r.highlightName)),r.caret.parentNode===s&&s.removeChild(r.caret);for(const e of r.selections)e.parentNode===s&&s.removeChild(e);e.selection=null}}}(e,d),C(r),c.set(t,r),O.current=!0},a=()=>{O.current=!1};return s.on("reload",r),s.on("sync",a),()=>{s.off("reload",r),s.off("sync",a)}},[d,s,e,C,c,t]),f(e,s,i,l,O,h,D),g(d,s,R),E(d,p)}function f(e,t,s,a,c,i,l){const u=r.useCallback(()=>t.connect(),[t]),d=r.useCallback(()=>{try{t.disconnect()}catch(e){}},[t]);r.useEffect(()=>{const r=({status:t})=>{e.dispatchCommand(o.CONNECTED_COMMAND,"connected"===t)},f=e=>{e&&!1===c.current&&l&&l()},g=e.getRootElement();o.initLocalState(t,s,a,null!==g&&n.getActiveElement(g)===g,i||{}),t.on("status",r),t.on("sync",f);const E=u();return()=>{!1===c.current&&(E?E.then(d):d()),t.off("sync",f),t.off("status",r)}},[e,t,s,a,c,i,l,u,d]),r.useEffect(()=>e.registerCommand(o.TOGGLE_CONNECT_COMMAND,e=>(e?(console.log("Collaboration connected!"),u()):(console.log("Collaboration disconnected!"),d()),!0),n.COMMAND_PRIORITY_EDITOR),[u,d,e]),r.useEffect(()=>{const e=()=>{try{t.awareness.setLocalState(null)}catch(e){}};return n.registerEventListeners(window,{beforeunload:e,pagehide:e})},[t])}function g(e,t,n){r.useEffect(()=>{const{awareness:r}=t,s=()=>{o.syncCursorPositions(e,t,{selectionHighlight:n})};return r.on("update",s),()=>{r.off("update",s)}},[e,t,n])}function E(e,t){return r.useMemo(()=>/*#__PURE__*/s.createPortal(/*#__PURE__*/c.jsx("div",{ref:t=>{e.cursorsContainer=t}}),t&&t.current||document.body),[e,t])}function C(e,t,s,a,c){r.useEffect(()=>n.mergeRegister(e.registerCommand(n.FOCUS_COMMAND,()=>(o.setLocalStateFocus(t,s,a,!0,c||{}),!1),n.COMMAND_PRIORITY_EDITOR),e.registerCommand(n.BLUR_COMMAND,()=>(o.setLocalStateFocus(t,s,a,!1,c||{}),!1),n.COMMAND_PRIORITY_EDITOR)),[a,e,s,t,c])}function p(e,t){r.useEffect(()=>n.mergeRegister(e.registerCommand(n.UNDO_COMMAND,()=>(t.undo(),!0),n.COMMAND_PRIORITY_EDITOR),e.registerCommand(n.REDO_COMMAND,()=>(t.redo(),!0),n.COMMAND_PRIORITY_EDITOR))),r.useEffect(()=>{const o=e;return o[u]=t,()=>{o[u]===t&&delete o[u]}},[e,t]);const o=r.useCallback(()=>{t.clear()},[t]);return l.useEffect(()=>{const o=()=>{e.dispatchCommand(n.CAN_UNDO_COMMAND,t.undoStack.length>0),e.dispatchCommand(n.CAN_REDO_COMMAND,t.redoStack.length>0)};return t.on("stack-item-added",o),t.on("stack-item-popped",o),t.on("stack-cleared",o),()=>{t.off("stack-item-added",o),t.off("stack-item-popped",o),t.off("stack-cleared",o)}},[e,t]),o}function _(e,t){e.update(()=>{const o=n.$getRoot();if(o.isEmpty())if(t)switch(typeof t){case"string":{const o=e.parseEditorState(t);e.setEditorState(o,{tag:n.HISTORY_MERGE_TAG});break}case"object":e.setEditorState(t,{tag:n.HISTORY_MERGE_TAG});break;case"function":e.update(()=>{n.$getRoot().isEmpty()&&t(e)},{tag:n.HISTORY_MERGE_TAG})}else{const t=n.$createParagraphNode();o.append(t);const r=e.getRootElement();(null!==n.$getSelection()||null!==r&&n.getActiveElement(r)===r)&&t.select()}},{tag:n.HISTORY_MERGE_TAG})}function m({editor:e,id:t,provider:n,yjsDocMap:s,name:a,color:c,shouldBootstrap:i,cursorsContainerRef:l,initialEditorState:u,awarenessData:f,collabContext:g,binding:E,setDoc:_,syncCursorPositionsFn:m,selectionHighlight:h}){const M=d(e,t,n,s,a,c,i,E,_,l,u,f,m,h);return function(e,t){p(e,r.useMemo(()=>o.createUndoManager(t,t.root.getSharedType()),[t]))}(e,E),C(e,n,a,c,f),M}const h=(e,t)=>{r.useEffect(()=>(e.isCollabActive=!0,()=>{null==t._parentEditor&&(e.isCollabActive=!1)}),[e,t])};exports.CollaborationPlugin=function({id:n,providerFactory:s,shouldBootstrap:a,username:i,cursorColor:l,cursorsContainerRef:u,initialEditorState:d,excludedProperties:f,awarenessData:g,syncCursorPositionsFn:E,selectionHighlight:C}){const p=r.useRef(!1),_=r.useRef(!1),M=e.useCollaborationContext(i,l),{yjsDocMap:R,name:O,color:D}=M,[T]=t.useLexicalComposerContext();h(M,T);const[N,S]=r.useState(),[A,I]=r.useState();r.useEffect(()=>{if(_.current)return;_.current=!0;const e=s(n,R);return S(e),I(R.get(n)),()=>{e.disconnect()}},[n,s,R]);const[y,x]=r.useState();return r.useEffect(()=>{if(!N)return;if(p.current)return;p.current=!0;const e=o.createBinding(T,N,n,A||R.get(n),R,f);return x(e),()=>{e.root.destroy(e)}},[T,N,n,R,A,f]),N&&y?/*#__PURE__*/c.jsx(m,{awarenessData:g,binding:y,collabContext:M,color:D,cursorsContainerRef:u,editor:T,id:n,initialEditorState:d,name:O,provider:N,setDoc:I,shouldBootstrap:a,yjsDocMap:R,syncCursorPositionsFn:E,selectionHighlight:C}):/*#__PURE__*/c.jsx(c.Fragment,{})},exports.CollaborationPluginV2__EXPERIMENTAL=function({id:s,doc:c,provider:i,__shouldBootstrapUnsafe:l,username:u,cursorColor:d,cursorsContainerRef:m,excludedProperties:M,awarenessData:R,selectionHighlight:O}){const D=e.useCollaborationContext(u,d),{yjsDocMap:T,name:N,color:S}=D,[A]=t.useLexicalComposerContext();h(D,A);const I=function(e,t,s,c,i,l,u,d={}){const{awarenessData:E,excludedProperties:C,rootName:p,selectionHighlight:m=!1,__shouldBootstrapUnsafe:h}=d,M=r.useMemo(()=>({current:!1}),[]),R=r.useMemo(()=>o.createBindingV2__EXPERIMENTAL(e,t,s,i,{excludedProperties:C,rootName:p}),[e,t,s,i,C,p]);r.useEffect(()=>(i.set(t,s),()=>{i.delete(t)}),[s,i,t]);const O=r.useCallback(()=>{const{root:t}=R;h&&0===t._length&&_(e)},[R,e,h]),[D,T]=r.useState();return r.useEffect(()=>{n.mergeRegister(e.registerCommand(o.CLEAR_DIFF_VERSIONS_COMMAND__EXPERIMENTAL,()=>(T(null),o.syncYjsStateToLexicalV2__EXPERIMENTAL(R,c),!0),n.COMMAND_PRIORITY_EDITOR),e.registerCommand(o.DIFF_VERSIONS_COMMAND__EXPERIMENTAL,({prevSnapshot:e,snapshot:t})=>(T({prevSnapshot:e,snapshot:t}),!0),n.COMMAND_PRIORITY_EDITOR))},[e,R,c]),r.useEffect(()=>{const{root:t}=R;if(D)return void o.renderSnapshot__EXPERIMENTAL(R,D.snapshot,D.prevSnapshot);const r=(e,t)=>{const r=t.origin;if(r!==R){const n=r instanceof a.UndoManager;o.syncYjsChangesToLexicalV2__EXPERIMENTAL(R,c,e,t,n)}};t.observeDeep(r);const s=e.registerUpdateListener(({prevEditorState:e,editorState:t,dirtyElements:r,dirtyLeaves:s,normalizedNodes:a,tags:i})=>{i.has(n.SKIP_COLLAB_TAG)||o.syncLexicalUpdateToYjsV2__EXPERIMENTAL(R,c,e,t,r,s,a,i)});return()=>{t.unobserveDeep(r),s()}},[R,c,e,D]),f(e,c,l,u,M,E,O),g(R,c,m),R}(A,s,c,i,T,N,S,{__shouldBootstrapUnsafe:l,awarenessData:R,excludedProperties:M,selectionHighlight:O});return function(e,t){p(e,r.useMemo(()=>o.createUndoManager(t,t.root),[t]))}(A,I),C(A,i,N,S,R),E(I,m)};
@@ -6,4 +6,4 @@
6
6
  *
7
7
  */
8
8
 
9
- import{useCollaborationContext as t}from"@lexical/react/LexicalCollaborationContext";import{useLexicalComposerContext as e}from"@lexical/react/LexicalComposerContext";import{syncCursorPositions as o,syncLexicalUpdateToYjs as r,createUndoManager as n,setLocalStateFocus as s,createBindingV2__EXPERIMENTAL as a,CLEAR_DIFF_VERSIONS_COMMAND__EXPERIMENTAL as i,syncYjsStateToLexicalV2__EXPERIMENTAL as c,DIFF_VERSIONS_COMMAND__EXPERIMENTAL as l,renderSnapshot__EXPERIMENTAL as d,syncLexicalUpdateToYjsV2__EXPERIMENTAL as u,syncYjsChangesToLexical as p,initLocalState as m,TOGGLE_CONNECT_COMMAND as f,syncYjsChangesToLexicalV2__EXPERIMENTAL as g,removeCursorHighlightRule as h,CONNECTED_COMMAND as C,createBinding as y}from"@lexical/yjs";import*as v from"react";import{useRef as S,useCallback as x,useEffect as b,useMemo as E,useState as D}from"react";import{SKIP_COLLAB_TAG as w,mergeRegister as k,FOCUS_COMMAND as _,COMMAND_PRIORITY_EDITOR as j,BLUR_COMMAND as N,$getRoot as P,HISTORY_MERGE_TAG as H,$createParagraphNode as L,$getSelection as B,getActiveElement as R,registerEventListeners as U,UNDO_COMMAND as M,REDO_COMMAND as F,CAN_UNDO_COMMAND as T,CAN_REDO_COMMAND as z}from"lexical";import{createPortal as A}from"react-dom";import{UndoManager as q}from"yjs";import{jsx as G,Fragment as I}from"react/jsx-runtime";const J=Symbol.for("@lexical/yjs/UndoManager");function K(t,e,n,s,a,i,c,l,d,u,m,f,g=o,C=!1){const y=S(!1),v=x(()=>{const{root:e}=l;c&&e.isEmpty()&&0===e._xmlText._length&&Y(t,m)},[l,t,m,c]);return b(()=>{const{root:e}=l,o=(t,e)=>{const o=e.origin;if(o!==l){p(l,n,t,o instanceof q,g)}};e.getSharedType().observeDeep(o);const s=t.registerUpdateListener(({prevEditorState:t,editorState:e,dirtyLeaves:o,dirtyElements:s,normalizedNodes:a,tags:i})=>{i.has(w)||r(l,n,t,e,s,o,a,i)});return()=>{e.getSharedType().unobserveDeep(o),s()}},[l,n,t,d,s,e,g]),b(()=>{const o=o=>{!function(t,e){if(t.update(()=>{const t=P();t.clear(),t.select()},{tag:w}),null==e.cursors)return;const o=e.cursors;if(null==o)return;const r=e.cursorsContainer;if(null==r)return;for(const t of o.values()){const o=t.selection;if(null!==o){null!==o.highlight&&(CSS.highlights.delete(o.highlightName),h(e,o.highlightName)),o.caret.parentNode===r&&r.removeChild(o.caret);for(const t of o.selections)t.parentNode===r&&r.removeChild(t);t.selection=null}}}(t,l),d(o),s.set(e,o),y.current=!0},r=()=>{y.current=!1};return n.on("reload",o),n.on("sync",r),()=>{n.off("reload",o),n.off("sync",r)}},[l,n,t,d,s,e]),O(t,n,a,i,y,f,v),Q(l,n,C),V(l,u)}function O(t,e,o,r,n,s,a){const i=x(()=>e.connect(),[e]),c=x(()=>{try{e.disconnect()}catch(t){}},[e]);b(()=>{const l=({status:e})=>{t.dispatchCommand(C,"connected"===e)},d=t=>{t&&!1===n.current&&a&&a()},u=t.getRootElement();m(e,o,r,null!==u&&R(u)===u,s||{}),e.on("status",l),e.on("sync",d);const p=i();return()=>{!1===n.current&&(p?p.then(c):c()),e.off("sync",d),e.off("status",l)}},[t,e,o,r,n,s,a,i,c]),b(()=>t.registerCommand(f,t=>(t?(console.log("Collaboration connected!"),i()):(console.log("Collaboration disconnected!"),c()),!0),j),[i,c,t]),b(()=>{const t=()=>{try{e.awareness.setLocalState(null)}catch(t){}};return U(window,{beforeunload:t,pagehide:t})},[e])}function Q(t,e,r){b(()=>{const{awareness:n}=e,s=()=>{o(t,e,{selectionHighlight:r})};return n.on("update",s),()=>{n.off("update",s)}},[t,e,r])}function V(t,e){return E(()=>/*#__PURE__*/A(/*#__PURE__*/G("div",{ref:e=>{t.cursorsContainer=e}}),e&&e.current||document.body),[t,e])}function W(t,e,o,r,n){b(()=>k(t.registerCommand(_,()=>(s(e,o,r,!0,n||{}),!1),j),t.registerCommand(N,()=>(s(e,o,r,!1,n||{}),!1),j)),[r,t,o,e,n])}function X(t,e){b(()=>k(t.registerCommand(M,()=>(e.undo(),!0),j),t.registerCommand(F,()=>(e.redo(),!0),j))),b(()=>{const o=t;return o[J]=e,()=>{o[J]===e&&delete o[J]}},[t,e]);const o=x(()=>{e.clear()},[e]);return v.useEffect(()=>{const o=()=>{t.dispatchCommand(T,e.undoStack.length>0),t.dispatchCommand(z,e.redoStack.length>0)};return e.on("stack-item-added",o),e.on("stack-item-popped",o),e.on("stack-cleared",o),()=>{e.off("stack-item-added",o),e.off("stack-item-popped",o),e.off("stack-cleared",o)}},[t,e]),o}function Y(t,e){t.update(()=>{const o=P();if(o.isEmpty())if(e)switch(typeof e){case"string":{const o=t.parseEditorState(e);t.setEditorState(o,{tag:H});break}case"object":t.setEditorState(e,{tag:H});break;case"function":t.update(()=>{P().isEmpty()&&e(t)},{tag:H})}else{const e=L();o.append(e);const{activeElement:r}=document;(null!==B()||null!==r&&r===t.getRootElement())&&e.select()}},{tag:H})}function Z({id:o,providerFactory:r,shouldBootstrap:n,username:s,cursorColor:a,cursorsContainerRef:i,initialEditorState:c,excludedProperties:l,awarenessData:d,syncCursorPositionsFn:u,selectionHighlight:p}){const m=S(!1),f=S(!1),g=t(s,a),{yjsDocMap:h,name:C,color:v}=g,[x]=e();et(g,x);const[E,w]=D(),[k,_]=D();b(()=>{if(f.current)return;f.current=!0;const t=r(o,h);return w(t),_(h.get(o)),()=>{t.disconnect()}},[o,r,h]);const[j,N]=D();return b(()=>{if(!E)return;if(m.current)return;m.current=!0;const t=y(x,E,o,k||h.get(o),h,l);return N(t),()=>{t.root.destroy(t)}},[x,E,o,h,k,l]),E&&j?/*#__PURE__*/G($,{awarenessData:d,binding:j,collabContext:g,color:v,cursorsContainerRef:i,editor:x,id:o,initialEditorState:c,name:C,provider:E,setDoc:_,shouldBootstrap:n,yjsDocMap:h,syncCursorPositionsFn:u,selectionHighlight:p}):/*#__PURE__*/G(I,{})}function $({editor:t,id:e,provider:o,yjsDocMap:r,name:s,color:a,shouldBootstrap:i,cursorsContainerRef:c,initialEditorState:l,awarenessData:d,collabContext:u,binding:p,setDoc:m,syncCursorPositionsFn:f,selectionHighlight:g}){const h=K(t,e,o,r,s,a,i,p,m,c,l,d,f,g);return function(t,e){X(t,E(()=>n(e,e.root.getSharedType()),[e]))}(t,p),W(t,o,s,a,d),h}function tt({id:o,doc:r,provider:s,__shouldBootstrapUnsafe:p,username:m,cursorColor:f,cursorsContainerRef:h,excludedProperties:C,awarenessData:y,selectionHighlight:v}){const S=t(m,f),{yjsDocMap:_,name:N,color:P}=S,[H]=e();et(S,H);const L=function(t,e,o,r,n,s,p,m={}){const{awarenessData:f,excludedProperties:h,rootName:C,selectionHighlight:y=!1,__shouldBootstrapUnsafe:v}=m,S=E(()=>({current:!1}),[]),_=E(()=>a(t,e,o,n,{excludedProperties:h,rootName:C}),[t,e,o,n,h,C]);b(()=>(n.set(e,o),()=>{n.delete(e)}),[o,n,e]);const N=x(()=>{const{root:e}=_;v&&0===e._length&&Y(t)},[_,t,v]),[P,H]=D();return b(()=>{k(t.registerCommand(i,()=>(H(null),c(_,r),!0),j),t.registerCommand(l,({prevSnapshot:t,snapshot:e})=>(H({prevSnapshot:t,snapshot:e}),!0),j))},[t,_,r]),b(()=>{const{root:e}=_;if(P)return void d(_,P.snapshot,P.prevSnapshot);const o=(t,e)=>{const o=e.origin;o!==_&&g(_,r,t,e,o instanceof q)};e.observeDeep(o);const n=t.registerUpdateListener(({prevEditorState:t,editorState:e,dirtyElements:o,dirtyLeaves:n,normalizedNodes:s,tags:a})=>{a.has(w)||u(_,r,t,e,o,n,s,a)});return()=>{e.unobserveDeep(o),n()}},[_,r,t,P]),O(t,r,s,p,S,f,N),Q(_,r,y),_}(H,o,r,s,_,N,P,{__shouldBootstrapUnsafe:p,awarenessData:y,excludedProperties:C,selectionHighlight:v});return function(t,e){X(t,E(()=>n(e,e.root),[e]))}(H,L),W(H,s,N,P,y),V(L,h)}const et=(t,e)=>{b(()=>(t.isCollabActive=!0,()=>{null==e._parentEditor&&(t.isCollabActive=!1)}),[t,e])};export{Z as CollaborationPlugin,tt as CollaborationPluginV2__EXPERIMENTAL};
9
+ import{useCollaborationContext as t}from"@lexical/react/LexicalCollaborationContext";import{useLexicalComposerContext as e}from"@lexical/react/LexicalComposerContext";import{syncCursorPositions as o,syncLexicalUpdateToYjs as r,createUndoManager as n,setLocalStateFocus as s,createBindingV2__EXPERIMENTAL as a,CLEAR_DIFF_VERSIONS_COMMAND__EXPERIMENTAL as i,syncYjsStateToLexicalV2__EXPERIMENTAL as c,DIFF_VERSIONS_COMMAND__EXPERIMENTAL as l,renderSnapshot__EXPERIMENTAL as d,syncLexicalUpdateToYjsV2__EXPERIMENTAL as u,syncYjsChangesToLexical as p,initLocalState as f,TOGGLE_CONNECT_COMMAND as m,syncYjsChangesToLexicalV2__EXPERIMENTAL as g,removeCursorHighlightRule as h,CONNECTED_COMMAND as C,createBinding as y}from"@lexical/yjs";import*as v from"react";import{useRef as S,useCallback as x,useEffect as b,useMemo as E,useState as D}from"react";import{SKIP_COLLAB_TAG as w,mergeRegister as k,FOCUS_COMMAND as _,COMMAND_PRIORITY_EDITOR as j,BLUR_COMMAND as N,$getRoot as P,HISTORY_MERGE_TAG as H,$createParagraphNode as L,$getSelection as B,getActiveElement as R,registerEventListeners as U,UNDO_COMMAND as M,REDO_COMMAND as F,CAN_UNDO_COMMAND as T,CAN_REDO_COMMAND as z}from"lexical";import{createPortal as A}from"react-dom";import{UndoManager as q}from"yjs";import{jsx as G,Fragment as I}from"react/jsx-runtime";const J=Symbol.for("@lexical/yjs/UndoManager");function K(t,e,n,s,a,i,c,l,d,u,f,m,g=o,C=!1){const y=S(!1),v=x(()=>{const{root:e}=l;c&&e.isEmpty()&&0===e._xmlText._length&&Y(t,f)},[l,t,f,c]);return b(()=>{const{root:e}=l,o=(t,e)=>{const o=e.origin;if(o!==l){p(l,n,t,o instanceof q,g)}};e.getSharedType().observeDeep(o);const s=t.registerUpdateListener(({prevEditorState:t,editorState:e,dirtyLeaves:o,dirtyElements:s,normalizedNodes:a,tags:i})=>{i.has(w)||r(l,n,t,e,s,o,a,i)});return()=>{e.getSharedType().unobserveDeep(o),s()}},[l,n,t,d,s,e,g]),b(()=>{const o=o=>{!function(t,e){if(t.update(()=>{const t=P();t.clear(),t.select()},{tag:w}),null==e.cursors)return;const o=e.cursors;if(null==o)return;const r=e.cursorsContainer;if(null==r)return;for(const t of o.values()){const o=t.selection;if(null!==o){null!==o.highlight&&(CSS.highlights.delete(o.highlightName),h(e,o.highlightName)),o.caret.parentNode===r&&r.removeChild(o.caret);for(const t of o.selections)t.parentNode===r&&r.removeChild(t);t.selection=null}}}(t,l),d(o),s.set(e,o),y.current=!0},r=()=>{y.current=!1};return n.on("reload",o),n.on("sync",r),()=>{n.off("reload",o),n.off("sync",r)}},[l,n,t,d,s,e]),O(t,n,a,i,y,m,v),Q(l,n,C),V(l,u)}function O(t,e,o,r,n,s,a){const i=x(()=>e.connect(),[e]),c=x(()=>{try{e.disconnect()}catch(t){}},[e]);b(()=>{const l=({status:e})=>{t.dispatchCommand(C,"connected"===e)},d=t=>{t&&!1===n.current&&a&&a()},u=t.getRootElement();f(e,o,r,null!==u&&R(u)===u,s||{}),e.on("status",l),e.on("sync",d);const p=i();return()=>{!1===n.current&&(p?p.then(c):c()),e.off("sync",d),e.off("status",l)}},[t,e,o,r,n,s,a,i,c]),b(()=>t.registerCommand(m,t=>(t?(console.log("Collaboration connected!"),i()):(console.log("Collaboration disconnected!"),c()),!0),j),[i,c,t]),b(()=>{const t=()=>{try{e.awareness.setLocalState(null)}catch(t){}};return U(window,{beforeunload:t,pagehide:t})},[e])}function Q(t,e,r){b(()=>{const{awareness:n}=e,s=()=>{o(t,e,{selectionHighlight:r})};return n.on("update",s),()=>{n.off("update",s)}},[t,e,r])}function V(t,e){return E(()=>/*#__PURE__*/A(/*#__PURE__*/G("div",{ref:e=>{t.cursorsContainer=e}}),e&&e.current||document.body),[t,e])}function W(t,e,o,r,n){b(()=>k(t.registerCommand(_,()=>(s(e,o,r,!0,n||{}),!1),j),t.registerCommand(N,()=>(s(e,o,r,!1,n||{}),!1),j)),[r,t,o,e,n])}function X(t,e){b(()=>k(t.registerCommand(M,()=>(e.undo(),!0),j),t.registerCommand(F,()=>(e.redo(),!0),j))),b(()=>{const o=t;return o[J]=e,()=>{o[J]===e&&delete o[J]}},[t,e]);const o=x(()=>{e.clear()},[e]);return v.useEffect(()=>{const o=()=>{t.dispatchCommand(T,e.undoStack.length>0),t.dispatchCommand(z,e.redoStack.length>0)};return e.on("stack-item-added",o),e.on("stack-item-popped",o),e.on("stack-cleared",o),()=>{e.off("stack-item-added",o),e.off("stack-item-popped",o),e.off("stack-cleared",o)}},[t,e]),o}function Y(t,e){t.update(()=>{const o=P();if(o.isEmpty())if(e)switch(typeof e){case"string":{const o=t.parseEditorState(e);t.setEditorState(o,{tag:H});break}case"object":t.setEditorState(e,{tag:H});break;case"function":t.update(()=>{P().isEmpty()&&e(t)},{tag:H})}else{const e=L();o.append(e);const r=t.getRootElement();(null!==B()||null!==r&&R(r)===r)&&e.select()}},{tag:H})}function Z({id:o,providerFactory:r,shouldBootstrap:n,username:s,cursorColor:a,cursorsContainerRef:i,initialEditorState:c,excludedProperties:l,awarenessData:d,syncCursorPositionsFn:u,selectionHighlight:p}){const f=S(!1),m=S(!1),g=t(s,a),{yjsDocMap:h,name:C,color:v}=g,[x]=e();et(g,x);const[E,w]=D(),[k,_]=D();b(()=>{if(m.current)return;m.current=!0;const t=r(o,h);return w(t),_(h.get(o)),()=>{t.disconnect()}},[o,r,h]);const[j,N]=D();return b(()=>{if(!E)return;if(f.current)return;f.current=!0;const t=y(x,E,o,k||h.get(o),h,l);return N(t),()=>{t.root.destroy(t)}},[x,E,o,h,k,l]),E&&j?/*#__PURE__*/G($,{awarenessData:d,binding:j,collabContext:g,color:v,cursorsContainerRef:i,editor:x,id:o,initialEditorState:c,name:C,provider:E,setDoc:_,shouldBootstrap:n,yjsDocMap:h,syncCursorPositionsFn:u,selectionHighlight:p}):/*#__PURE__*/G(I,{})}function $({editor:t,id:e,provider:o,yjsDocMap:r,name:s,color:a,shouldBootstrap:i,cursorsContainerRef:c,initialEditorState:l,awarenessData:d,collabContext:u,binding:p,setDoc:f,syncCursorPositionsFn:m,selectionHighlight:g}){const h=K(t,e,o,r,s,a,i,p,f,c,l,d,m,g);return function(t,e){X(t,E(()=>n(e,e.root.getSharedType()),[e]))}(t,p),W(t,o,s,a,d),h}function tt({id:o,doc:r,provider:s,__shouldBootstrapUnsafe:p,username:f,cursorColor:m,cursorsContainerRef:h,excludedProperties:C,awarenessData:y,selectionHighlight:v}){const S=t(f,m),{yjsDocMap:_,name:N,color:P}=S,[H]=e();et(S,H);const L=function(t,e,o,r,n,s,p,f={}){const{awarenessData:m,excludedProperties:h,rootName:C,selectionHighlight:y=!1,__shouldBootstrapUnsafe:v}=f,S=E(()=>({current:!1}),[]),_=E(()=>a(t,e,o,n,{excludedProperties:h,rootName:C}),[t,e,o,n,h,C]);b(()=>(n.set(e,o),()=>{n.delete(e)}),[o,n,e]);const N=x(()=>{const{root:e}=_;v&&0===e._length&&Y(t)},[_,t,v]),[P,H]=D();return b(()=>{k(t.registerCommand(i,()=>(H(null),c(_,r),!0),j),t.registerCommand(l,({prevSnapshot:t,snapshot:e})=>(H({prevSnapshot:t,snapshot:e}),!0),j))},[t,_,r]),b(()=>{const{root:e}=_;if(P)return void d(_,P.snapshot,P.prevSnapshot);const o=(t,e)=>{const o=e.origin;o!==_&&g(_,r,t,e,o instanceof q)};e.observeDeep(o);const n=t.registerUpdateListener(({prevEditorState:t,editorState:e,dirtyElements:o,dirtyLeaves:n,normalizedNodes:s,tags:a})=>{a.has(w)||u(_,r,t,e,o,n,s,a)});return()=>{e.unobserveDeep(o),n()}},[_,r,t,P]),O(t,r,s,p,S,m,N),Q(_,r,y),_}(H,o,r,s,_,N,P,{__shouldBootstrapUnsafe:p,awarenessData:y,excludedProperties:C,selectionHighlight:v});return function(t,e){X(t,E(()=>n(e,e.root),[e]))}(H,L),W(H,s,N,P,y),V(L,h)}const et=(t,e)=>{b(()=>(t.isCollabActive=!0,()=>{null==e._parentEditor&&(t.isCollabActive=!1)}),[t,e])};export{Z as CollaborationPlugin,tt as CollaborationPluginV2__EXPERIMENTAL};
@@ -5,9 +5,9 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  *
7
7
  */
8
- import type { JSX } from 'react';
9
- import { EditorState, EditorThemeClasses, HTMLConfig, Klass, LexicalEditor, LexicalNode, LexicalNodeReplacement } from 'lexical';
8
+ import { type EditorState, type EditorThemeClasses, type HTMLConfig, type Klass, type LexicalEditor, type LexicalNode, type LexicalNodeReplacement } from 'lexical';
10
9
  import * as React from 'react';
10
+ import { type JSX } from 'react';
11
11
  /**
12
12
  * The initial editor state accepted by {@link LexicalComposer} via
13
13
  * `initialConfig.editorState`. Each variant is handled differently:
@@ -5,7 +5,7 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  *
7
7
  */
8
- import type { JSX } from 'react';
8
+ import { type JSX } from 'react';
9
9
  import { ContentEditableElement, type ContentEditableElementProps } from './shared/LexicalContentEditableElement';
10
10
  export { ContentEditableElement, type ContentEditableElementProps };
11
11
  /**
@@ -6,5 +6,5 @@
6
6
  *
7
7
  */
8
8
 
9
- "use strict";var e=require("@lexical/react/LexicalComposerContext"),t=require("react"),a=require("lexical"),r=require("react/jsx-runtime"),i=require("@lexical/text");const n=a.CAN_USE_DOM?t.useLayoutEffect:t.useEffect;function l({editor:e,ariaActiveDescendant:a,ariaAutoComplete:i,ariaControls:l,ariaDescribedBy:o,ariaErrorMessage:s,ariaExpanded:u,ariaInvalid:d,ariaLabel:c,ariaLabelledBy:f,ariaMultiline:b,ariaOwns:x,ariaRequired:m,autoCapitalize:E,className:p,id:C,role:v="textbox",spellCheck:y=!0,style:g,tabIndex:L,"data-testid":h,...w},q){const[j,R]=t.useState(e.isEditable()),D=t.useCallback(t=>{t&&t.ownerDocument&&t.ownerDocument.defaultView?e.setRootElement(t):e.setRootElement(null)},[e]),S=t.useMemo(()=>function(...e){return t=>{for(const a of e)"function"==typeof a?a(t):null!=a&&(a.current=t)}}(q,D),[D,q]);return n(()=>(R(e.isEditable()),e.registerEditableListener(e=>{R(e)})),[e]),/*#__PURE__*/r.jsx("div",{"aria-activedescendant":j?a:void 0,"aria-autocomplete":j?i:"none","aria-controls":j?l:void 0,"aria-describedby":o,...null!=s?{"aria-errormessage":s}:{},"aria-expanded":j&&"combobox"===v?!!u:void 0,...null!=d?{"aria-invalid":d}:{},"aria-label":c,"aria-labelledby":f,"aria-multiline":b,"aria-owns":j?x:void 0,"aria-readonly":!j||void 0,"aria-required":m,autoCapitalize:E,className:p,contentEditable:j,"data-testid":h,id:C,ref:S,role:v,spellCheck:y,style:g,tabIndex:L,...w})}const o=/*#__PURE__*/t.forwardRef(l);function s(e){return e.read("latest",i.$canShowPlaceholderCurry(e.isComposing()))}const u=/*#__PURE__*/t.forwardRef(d);function d(t,a){const{placeholder:i,...n}=t,[l]=e.useLexicalComposerContext();/*#__PURE__*/
9
+ "use strict";var e=require("@lexical/react/LexicalComposerContext"),t=require("react"),a=require("lexical"),r=require("react/jsx-runtime"),i=require("@lexical/text");const n=a.CAN_USE_DOM?t.useLayoutEffect:t.useEffect;function l({editor:e,ariaActiveDescendant:a,ariaAutoComplete:i,ariaControls:l,ariaDescribedBy:o,ariaErrorMessage:s,ariaExpanded:u,ariaInvalid:d,ariaLabel:c,ariaLabelledBy:f,ariaMultiline:b,ariaOwns:x,ariaRequired:m,autoCapitalize:E,className:p,id:C,role:v="textbox",spellCheck:y=!0,style:g,tabIndex:L,"data-testid":h,...w},q){const[j,R]=t.useState(e.isEditable()),D=t.useCallback(t=>{t&&t.ownerDocument&&t.ownerDocument.defaultView?e.setRootElement(t):e.setRootElement(null)},[e]),S=t.useMemo(()=>function(...e){return t=>{for(const a of e)"function"==typeof a?a(t):null!=a&&(a.current=t)}}(q,D),[D,q]);return n(()=>(R(e.isEditable()),e.registerEditableListener(e=>{R(e)})),[e]),/*#__PURE__*/r.jsx("div",{"aria-activedescendant":j?a:void 0,"aria-autocomplete":j?i:"none","aria-controls":j?l:void 0,"aria-describedby":o,...null!=s?{"aria-errormessage":s}:{},"aria-expanded":j&&"combobox"===v?!!u:void 0,...null!=d?{"aria-invalid":d}:{},"aria-label":c,"aria-labelledby":f,"aria-multiline":b,"aria-owns":j?x:void 0,"aria-readonly":!j||void 0,"aria-required":m,autoCapitalize:E,className:p,contentEditable:j,"data-testid":h,id:C,ref:S,role:v,spellCheck:y,style:g,tabIndex:L,...w})}const o=/*#__PURE__*/t.forwardRef(l);function s(e){return e.read("latest",i.$canShowPlaceholderCurry(e.isComposing()))}const u=/*#__PURE__*/t.forwardRef(d);function d(t,a){const{placeholder:i,...n}=t,[l]=e.useLexicalComposerContext();
10
10
  return r.jsxs(r.Fragment,{children:[/*#__PURE__*/r.jsx(o,{editor:l,...n,ref:a}),null!=i&&/*#__PURE__*/r.jsx(c,{editor:l,content:i})]})}function c({content:e,editor:i}){const l=function(e){const[r,i]=t.useState(()=>s(e));return n(()=>{function t(){const t=s(e);i(t)}return t(),a.mergeRegister(e.registerUpdateListener(()=>{t()}),e.registerEditableListener(()=>{t()}))},[e]),r}(i),[o,u]=t.useState(i.isEditable());if(t.useLayoutEffect(()=>(u(i.isEditable()),i.registerEditableListener(e=>{u(e)})),[i]),!l)return null;let d=null;return"function"==typeof e?d=e(o):null!==e&&(d=e),null===d?null:/*#__PURE__*/r.jsx("div",{"aria-hidden":!0,children:d})}exports.ContentEditable=u,exports.ContentEditableElement=o;
@@ -6,5 +6,5 @@
6
6
  *
7
7
  */
8
8
 
9
- import{useLexicalComposerContext as e}from"@lexical/react/LexicalComposerContext";import{useLayoutEffect as t,useEffect as i,forwardRef as a,useState as r,useCallback as n,useMemo as o}from"react";import{CAN_USE_DOM as l,mergeRegister as d}from"lexical";import{jsx as s,jsxs as c,Fragment as u}from"react/jsx-runtime";import{$canShowPlaceholderCurry as m}from"@lexical/text";const f=l?t:i;function b({editor:e,ariaActiveDescendant:t,ariaAutoComplete:i,ariaControls:a,ariaDescribedBy:l,ariaErrorMessage:d,ariaExpanded:c,ariaInvalid:u,ariaLabel:m,ariaLabelledBy:b,ariaMultiline:p,ariaOwns:x,ariaRequired:E,autoCapitalize:v,className:y,id:C,role:g="textbox",spellCheck:L=!0,style:h,tabIndex:w,"data-testid":D,...I},R){const[k,q]=r(e.isEditable()),z=n(t=>{t&&t.ownerDocument&&t.ownerDocument.defaultView?e.setRootElement(t):e.setRootElement(null)},[e]),A=o(()=>function(...e){return t=>{for(const i of e)"function"==typeof i?i(t):null!=i&&(i.current=t)}}(R,z),[z,R]);return f(()=>(q(e.isEditable()),e.registerEditableListener(e=>{q(e)})),[e]),/*#__PURE__*/s("div",{"aria-activedescendant":k?t:void 0,"aria-autocomplete":k?i:"none","aria-controls":k?a:void 0,"aria-describedby":l,...null!=d?{"aria-errormessage":d}:{},"aria-expanded":k&&"combobox"===g?!!c:void 0,...null!=u?{"aria-invalid":u}:{},"aria-label":m,"aria-labelledby":b,"aria-multiline":p,"aria-owns":k?x:void 0,"aria-readonly":!k||void 0,"aria-required":E,autoCapitalize:v,className:y,contentEditable:k,"data-testid":D,id:C,ref:A,role:g,spellCheck:L,style:h,tabIndex:w,...I})}const p=/*#__PURE__*/a(b);function x(e){return e.read("latest",m(e.isComposing()))}const E=/*#__PURE__*/a(v);function v(t,i){const{placeholder:a,...r}=t,[n]=e();/*#__PURE__*/
9
+ import{useLexicalComposerContext as e}from"@lexical/react/LexicalComposerContext";import{useLayoutEffect as t,useEffect as i,forwardRef as a,useState as r,useCallback as n,useMemo as o}from"react";import{CAN_USE_DOM as l,mergeRegister as d}from"lexical";import{jsx as s,jsxs as c,Fragment as u}from"react/jsx-runtime";import{$canShowPlaceholderCurry as m}from"@lexical/text";const f=l?t:i;function b({editor:e,ariaActiveDescendant:t,ariaAutoComplete:i,ariaControls:a,ariaDescribedBy:l,ariaErrorMessage:d,ariaExpanded:c,ariaInvalid:u,ariaLabel:m,ariaLabelledBy:b,ariaMultiline:p,ariaOwns:x,ariaRequired:E,autoCapitalize:v,className:y,id:C,role:g="textbox",spellCheck:L=!0,style:h,tabIndex:w,"data-testid":D,...I},R){const[k,q]=r(e.isEditable()),z=n(t=>{t&&t.ownerDocument&&t.ownerDocument.defaultView?e.setRootElement(t):e.setRootElement(null)},[e]),A=o(()=>function(...e){return t=>{for(const i of e)"function"==typeof i?i(t):null!=i&&(i.current=t)}}(R,z),[z,R]);return f(()=>(q(e.isEditable()),e.registerEditableListener(e=>{q(e)})),[e]),/*#__PURE__*/s("div",{"aria-activedescendant":k?t:void 0,"aria-autocomplete":k?i:"none","aria-controls":k?a:void 0,"aria-describedby":l,...null!=d?{"aria-errormessage":d}:{},"aria-expanded":k&&"combobox"===g?!!c:void 0,...null!=u?{"aria-invalid":u}:{},"aria-label":m,"aria-labelledby":b,"aria-multiline":p,"aria-owns":k?x:void 0,"aria-readonly":!k||void 0,"aria-required":E,autoCapitalize:v,className:y,contentEditable:k,"data-testid":D,id:C,ref:A,role:g,spellCheck:L,style:h,tabIndex:w,...I})}const p=/*#__PURE__*/a(b);function x(e){return e.read("latest",m(e.isComposing()))}const E=/*#__PURE__*/a(v);function v(t,i){const{placeholder:a,...r}=t,[n]=e();
10
10
  return c(u,{children:[/*#__PURE__*/s(p,{editor:n,...r,ref:i}),null!=a&&/*#__PURE__*/s(y,{editor:n,content:a})]})}function y({content:e,editor:i}){const a=function(e){const[t,i]=r(()=>x(e));return f(()=>{function t(){const t=x(e);i(t)}return t(),d(e.registerUpdateListener(()=>{t()}),e.registerEditableListener(()=>{t()}))},[e]),t}(i),[n,o]=r(i.isEditable());if(t(()=>(o(i.isEditable()),i.registerEditableListener(e=>{o(e)})),[i]),!a)return null;let l=null;return"function"==typeof e?l=e(n):null!==e&&(l=e),null===l?null:/*#__PURE__*/s("div",{"aria-hidden":!0,children:l})}export{E as ContentEditable,p as ContentEditableElement};
@@ -5,9 +5,8 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  *
7
7
  */
8
- import type { ElementFormatType, LexicalNode, LexicalUpdateJSON, NodeKey, SerializedLexicalNode, Spread } from 'lexical';
9
8
  import type { JSX } from 'react';
10
- import { DecoratorNode } from 'lexical';
9
+ import { DecoratorNode, type ElementFormatType, type LexicalNode, type LexicalUpdateJSON, type NodeKey, type SerializedLexicalNode, type Spread } from 'lexical';
11
10
  /**
12
11
  * The serialized form of a {@link DecoratorBlockNode}: the base serialized node
13
12
  * data plus the block's element `format` (alignment).
@@ -54,7 +54,7 @@ class DecoratorBlockNode extends lexical.DecoratorNode {
54
54
  return false;
55
55
  }
56
56
  createDOM() {
57
- return document.createElement('div');
57
+ return lexical.$getDocument().createElement('div');
58
58
  }
59
59
  updateDOM() {
60
60
  return false;
@@ -6,7 +6,7 @@
6
6
  *
7
7
  */
8
8
 
9
- import { DecoratorNode } from 'lexical';
9
+ import { DecoratorNode, $getDocument } from 'lexical';
10
10
 
11
11
  /**
12
12
  * Copyright (c) Meta Platforms, Inc. and affiliates.
@@ -52,7 +52,7 @@ class DecoratorBlockNode extends DecoratorNode {
52
52
  return false;
53
53
  }
54
54
  createDOM() {
55
- return document.createElement('div');
55
+ return $getDocument().createElement('div');
56
56
  }
57
57
  updateDOM() {
58
58
  return false;
@@ -6,4 +6,4 @@
6
6
  *
7
7
  */
8
8
 
9
- "use strict";var r=require("lexical");class t extends r.DecoratorNode{__format;constructor(r,t){super(t),this.__format=r||""}afterCloneFrom(r){super.afterCloneFrom(r),this.__format=r.__format}exportJSON(){return{...super.exportJSON(),format:this.__format||""}}updateFromJSON(r){return super.updateFromJSON(r).setFormat(r.format||"")}canIndent(){return!1}createDOM(){return document.createElement("div")}updateDOM(){return!1}setFormat(r){const t=this.getWritable();return t.__format=r,t}getFormat(){return this.getLatest().__format}isInline(){return!1}}exports.$isDecoratorBlockNode=function(r){return r instanceof t},exports.DecoratorBlockNode=t;
9
+ "use strict";var t=require("lexical");class r extends t.DecoratorNode{__format;constructor(t,r){super(r),this.__format=t||""}afterCloneFrom(t){super.afterCloneFrom(t),this.__format=t.__format}exportJSON(){return{...super.exportJSON(),format:this.__format||""}}updateFromJSON(t){return super.updateFromJSON(t).setFormat(t.format||"")}canIndent(){return!1}createDOM(){return t.$getDocument().createElement("div")}updateDOM(){return!1}setFormat(t){const r=this.getWritable();return r.__format=t,r}getFormat(){return this.getLatest().__format}isInline(){return!1}}exports.$isDecoratorBlockNode=function(t){return t instanceof r},exports.DecoratorBlockNode=r;
@@ -6,4 +6,4 @@
6
6
  *
7
7
  */
8
8
 
9
- import{DecoratorNode as t}from"lexical";class r extends t{__format;constructor(t,r){super(r),this.__format=t||""}afterCloneFrom(t){super.afterCloneFrom(t),this.__format=t.__format}exportJSON(){return{...super.exportJSON(),format:this.__format||""}}updateFromJSON(t){return super.updateFromJSON(t).setFormat(t.format||"")}canIndent(){return!1}createDOM(){return document.createElement("div")}updateDOM(){return!1}setFormat(t){const r=this.getWritable();return r.__format=t,r}getFormat(){return this.getLatest().__format}isInline(){return!1}}function e(t){return t instanceof r}export{e as $isDecoratorBlockNode,r as DecoratorBlockNode};
9
+ import{DecoratorNode as t,$getDocument as r}from"lexical";class e extends t{__format;constructor(t,r){super(r),this.__format=t||""}afterCloneFrom(t){super.afterCloneFrom(t),this.__format=t.__format}exportJSON(){return{...super.exportJSON(),format:this.__format||""}}updateFromJSON(t){return super.updateFromJSON(t).setFormat(t.format||"")}canIndent(){return!1}createDOM(){return r().createElement("div")}updateDOM(){return!1}setFormat(t){const r=this.getWritable();return r.__format=t,r}getFormat(){return this.getLatest().__format}isInline(){return!1}}function o(t){return t instanceof e}export{o as $isDecoratorBlockNode,e as DecoratorBlockNode};
@@ -5,8 +5,7 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  *
7
7
  */
8
- import type { JSX } from 'react';
9
- import { ReactNode } from 'react';
8
+ import { type JSX, type ReactNode } from 'react';
10
9
  /**
11
10
  * Renders a draggable handle and drop-target line that let users reorder
12
11
  * top-level blocks by dragging. You supply the handle and target-line elements
@@ -226,11 +226,12 @@ function getTopLevelNodeKeys(editor) {
226
226
  return editor.read('latest', () => lexical.$getRoot().getChildrenKeys());
227
227
  }
228
228
  function getCollapsedMargins(elem) {
229
- const getMargin = (element, margin) => element ? parseFloat(window.getComputedStyle(element)[margin]) : 0;
229
+ const view = elem.ownerDocument.defaultView;
230
+ const getMargin = (element, margin) => element && view ? parseFloat(view.getComputedStyle(element)[margin]) : 0;
230
231
  const {
231
- marginTop,
232
- marginBottom
233
- } = window.getComputedStyle(elem);
232
+ marginTop = '0',
233
+ marginBottom = '0'
234
+ } = view ? view.getComputedStyle(elem) : {};
234
235
  const prevElemSiblingMarginBottom = getMargin(elem.previousElementSibling, 'marginBottom');
235
236
  const nextElemSiblingMarginTop = getMargin(elem.nextElementSibling, 'marginTop');
236
237
  const collapsedTopMargin = Math.max(parseFloat(marginTop), prevElemSiblingMarginBottom);
@@ -315,12 +316,13 @@ function setMenuPosition(targetElem, floatingElem, anchorElem, zoomLevel) {
315
316
  return;
316
317
  }
317
318
  const targetRect = targetElem.getBoundingClientRect();
318
- const targetStyle = window.getComputedStyle(targetElem);
319
+ const targetView = targetElem.ownerDocument.defaultView;
320
+ const targetStyle = targetView ? targetView.getComputedStyle(targetElem) : null;
319
321
  const floatingElemRect = floatingElem.getBoundingClientRect();
320
322
  const anchorElementRect = anchorElem.getBoundingClientRect();
321
323
 
322
324
  // top left
323
- let targetCalculateHeight = parseInt(targetStyle.lineHeight, 10);
325
+ let targetCalculateHeight = targetStyle ? parseInt(targetStyle.lineHeight, 10) : NaN;
324
326
  if (isNaN(targetCalculateHeight)) {
325
327
  // middle
326
328
  targetCalculateHeight = targetRect.bottom - targetRect.top;
@@ -629,6 +631,7 @@ function useDraggableBlockMenu(editor, anchorElem, menuRef, targetLineRef, isEdi
629
631
  * @returns A portal containing the drag handle and target line.
630
632
  */
631
633
  function DraggableBlockPlugin_EXPERIMENTAL({
634
+ // eslint-disable-next-line no-restricted-syntax
632
635
  anchorElem = document.body,
633
636
  menuRef,
634
637
  targetLineRef,
@@ -224,11 +224,12 @@ function getTopLevelNodeKeys(editor) {
224
224
  return editor.read('latest', () => $getRoot().getChildrenKeys());
225
225
  }
226
226
  function getCollapsedMargins(elem) {
227
- const getMargin = (element, margin) => element ? parseFloat(window.getComputedStyle(element)[margin]) : 0;
227
+ const view = elem.ownerDocument.defaultView;
228
+ const getMargin = (element, margin) => element && view ? parseFloat(view.getComputedStyle(element)[margin]) : 0;
228
229
  const {
229
- marginTop,
230
- marginBottom
231
- } = window.getComputedStyle(elem);
230
+ marginTop = '0',
231
+ marginBottom = '0'
232
+ } = view ? view.getComputedStyle(elem) : {};
232
233
  const prevElemSiblingMarginBottom = getMargin(elem.previousElementSibling, 'marginBottom');
233
234
  const nextElemSiblingMarginTop = getMargin(elem.nextElementSibling, 'marginTop');
234
235
  const collapsedTopMargin = Math.max(parseFloat(marginTop), prevElemSiblingMarginBottom);
@@ -313,12 +314,13 @@ function setMenuPosition(targetElem, floatingElem, anchorElem, zoomLevel) {
313
314
  return;
314
315
  }
315
316
  const targetRect = targetElem.getBoundingClientRect();
316
- const targetStyle = window.getComputedStyle(targetElem);
317
+ const targetView = targetElem.ownerDocument.defaultView;
318
+ const targetStyle = targetView ? targetView.getComputedStyle(targetElem) : null;
317
319
  const floatingElemRect = floatingElem.getBoundingClientRect();
318
320
  const anchorElementRect = anchorElem.getBoundingClientRect();
319
321
 
320
322
  // top left
321
- let targetCalculateHeight = parseInt(targetStyle.lineHeight, 10);
323
+ let targetCalculateHeight = targetStyle ? parseInt(targetStyle.lineHeight, 10) : NaN;
322
324
  if (isNaN(targetCalculateHeight)) {
323
325
  // middle
324
326
  targetCalculateHeight = targetRect.bottom - targetRect.top;
@@ -627,6 +629,7 @@ function useDraggableBlockMenu(editor, anchorElem, menuRef, targetLineRef, isEdi
627
629
  * @returns A portal containing the drag handle and target line.
628
630
  */
629
631
  function DraggableBlockPlugin_EXPERIMENTAL({
632
+ // eslint-disable-next-line no-restricted-syntax
630
633
  anchorElem = document.body,
631
634
  menuRef,
632
635
  targetLineRef,
@@ -6,4 +6,4 @@
6
6
  *
7
7
  */
8
8
 
9
- "use strict";var t=require("@lexical/react/LexicalComposerContext"),e=require("@lexical/rich-text"),n=require("@lexical/utils"),o=require("lexical"),r=require("react"),i=require("react-dom"),s=require("react/jsx-runtime");class l{_x;_y;constructor(t,e){this._x=t,this._y=e}get x(){return this._x}get y(){return this._y}equals({x:t,y:e}){return this.x===t&&this.y===e}calcDeltaXTo({x:t}){return this.x-t}calcDeltaYTo({y:t}){return this.y-t}calcHorizontalDistanceTo(t){return Math.abs(this.calcDeltaXTo(t))}calcVerticalDistance(t){return Math.abs(this.calcDeltaYTo(t))}calcDistanceTo(t){return Math.sqrt(Math.pow(this.calcDeltaXTo(t),2)+Math.pow(this.calcDeltaYTo(t),2))}}class a{_left;_top;_right;_bottom;constructor(t,e,n,o){const[r,i]=e<=o?[e,o]:[o,e],[s,l]=t<=n?[t,n]:[n,t];this._top=r,this._right=l,this._left=s,this._bottom=i}get top(){return this._top}get right(){return this._right}get bottom(){return this._bottom}get left(){return this._left}get width(){return Math.abs(this._left-this._right)}get height(){return Math.abs(this._bottom-this._top)}equals({top:t,left:e,bottom:n,right:o}){return t===this._top&&n===this._bottom&&e===this._left&&o===this._right}contains(t){if(t instanceof l){const{x:e,y:n}=t,o=n<this._top,r=n>this._bottom,i=e<this._left,s=e>this._right;return{reason:{isOnBottomSide:r,isOnLeftSide:i,isOnRightSide:s,isOnTopSide:o},result:!(o||r||i||s)}}{const{top:e,left:n,bottom:o,right:r}=t;return e>=this._top&&e<=this._bottom&&o>=this._top&&o<=this._bottom&&n>=this._left&&n<=this._right&&r>=this._left&&r<=this._right}}intersectsWith(t){const{left:e,top:n,width:o,height:r}=t,{left:i,top:s,width:l,height:a}=this;return(e+o>=i+l?e+o:i+l)-(e<=i?e:i)<=o+l&&(n+r>=s+a?n+r:s+a)-(n<=s?n:s)<=r+a}generateNewRect({left:t=this.left,top:e=this.top,right:n=this.right,bottom:o=this.bottom}){return new a(t,e,n,o)}static fromLTRB(t,e,n,o){return new a(t,e,n,o)}static fromLWTH(t,e,n,o){return new a(t,n,t+e,n+o)}static fromPoints(t,e){const{y:n,x:o}=t,{y:r,x:i}=e;return a.fromLTRB(o,n,i,r)}static fromDOM(t){const{top:e,width:n,left:o,height:r}=t.getBoundingClientRect();return a.fromLWTH(o,n,e,r)}}const c="application/x-lexical-drag-block";let u=1/0;function g(t){const e=(t,e)=>t?parseFloat(window.getComputedStyle(t)[e]):0,{marginTop:n,marginBottom:o}=window.getComputedStyle(t),r=e(t.previousElementSibling,"marginBottom"),i=e(t.nextElementSibling,"marginTop"),s=Math.max(parseFloat(n),r);return{marginBottom:Math.max(parseFloat(o),i),marginTop:s}}function m(t,e,r,i=!1){const s=t.getBoundingClientRect(),c=function(t){return t.read("latest",()=>o.$getRoot().getChildrenKeys())}(e);let m=null;return e.read("latest",()=>{if(i){const[t,o]=[e.getElementByKey(c[0]),e.getElementByKey(c[c.length-1])],[i,s]=[null!=t?t.getBoundingClientRect():void 0,null!=o?o.getBoundingClientRect():void 0];if(i&&s){const e=n.calculateZoomLevel(t),l=n.calculateZoomLevel(o);if(r.y/e<i.top?m=t:r.y/l>s.bottom&&(m=o),m)return}}let t=0===(o=c.length)?1/0:u>=0&&u<o?u:Math.floor(o/2);var o;let h=0;for(;t>=0&&t<c.length;){const o=c[t],i=e.getElementByKey(o);if(null===i)break;const f=n.calculateZoomLevel(i),p=new l(r.x/f,r.y/f),d=a.fromDOM(i),{marginTop:_,marginBottom:y}=g(i),R=d.generateNewRect({bottom:d.bottom+y,left:s.left,right:s.right,top:d.top-_}),{result:x,reason:{isOnTopSide:E,isOnBottomSide:T}}=R.contains(p);if(x){m=i,u=t;break}0===h&&(h=E?-1:T?1:1/0),t+=h}}),m}function h(t,l,a,u,h,f,p,d,_){const y=o.getParentElement(l),R=r.useRef(!1),[x,E]=r.useState(null),T=r.useCallback(t=>{E(t),_&&_(t)},[_]);return r.useEffect(()=>{if(null!=y)return o.registerEventListeners(y,{mouseleave:function(){T(null)},mousemove:function(e){const n=o.getComposedEventTarget(e);if(!o.isHTMLElement(n))return void T(null);if(d(n))return;const r=m(l,t,e);T(r)}})},[y,l,t,d,T]),r.useEffect(()=>{const e=n.calculateZoomLevel(t.getRootElement(),!0);a.current&&function(t,e,n,o){if(!t)return void(e.style.display="none");const r=t.getBoundingClientRect(),i=window.getComputedStyle(t),s=e.getBoundingClientRect(),l=n.getBoundingClientRect();let a=parseInt(i.lineHeight,10);isNaN(a)&&(a=r.bottom-r.top);const c=(r.top+(a-(s.height||a))/2-l.top+n.scrollTop)/o;e.style.display="flex",e.style.opacity="1",e.style.transform=`translate(4px, ${c}px)`}(x,a.current,l,e)},[t,l,x,a]),r.useEffect(()=>{function r(r){if(!R.current)return!1;const[i]=e.eventFiles(r);if(i)return!1;const s=r.pageY,a=o.getComposedEventTarget(r);if(!o.isHTMLElement(a))return!1;const c=m(l,t,r,!0),h=u.current;return null!==c&&null!==h&&(function(t,e,n,o){const{top:r,height:i}=e.getBoundingClientRect(),{top:s,width:l}=o.getBoundingClientRect(),{marginTop:a,marginBottom:c}=g(e);let u=r;n>=r?u+=i+c/2:u-=a/2;const m=u-s-2+o.scrollTop;t.style.transform=`translate(24px, ${m}px)`,t.style.width=l-48+"px",t.style.opacity=".4"}(h,c,s/n.calculateZoomLevel(a),l),r.preventDefault(),!0)}return o.mergeRegister(t.registerCommand(o.DRAGOVER_COMMAND,t=>r(t),o.COMMAND_PRIORITY_LOW),t.registerCommand(o.DROP_COMMAND,r=>function(r){if(!R.current)return!1;const[i]=e.eventFiles(r);if(i)return!1;const{dataTransfer:s,pageY:a}=r,u=o.getComposedEventTarget(r),g=null!=s?s.getData(c):"",h=o.$getNodeByKey(g);if(!h)return!1;if(!o.isHTMLElement(u))return!1;const f=m(l,t,r,!0);if(!f)return!1;const p=o.$getNearestNodeFromDOMNode(f);if(!p)return!1;if(p===h)return o.IS_FIREFOX&&t.focus(),!0;const d=f.getBoundingClientRect().top;return a/n.calculateZoomLevel(u)>=d?p.insertAfter(h):p.insertBefore(h),T(null),o.IS_FIREFOX&&o.$onUpdate(()=>{t.focus()}),!0}(r),o.COMMAND_PRIORITY_HIGH))},[l,t,u,T]),r.useEffect(()=>{if(o.IS_FIREFOX&&h)return o.mergeRegister(t.registerRootListener(e=>{if(e)return o.registerEventListener(e,"blur",function(n){const r=n.relatedTarget;o.isHTMLElement(r)&&d(r)&&(e&&(e.focus({preventScroll:!0}),t.update(()=>{const t=o.$getSelection();null===t||t.dirty||(t.dirty=!0)})),n.stopImmediatePropagation())},!0)}),t.registerCommand(o.BLUR_COMMAND,()=>{const e=t.getRootElement(),n=o.getActiveElementDeep(o.getRootOwnerDocument(e));return!!(e&&o.isHTMLElement(n)&&d(n))&&(e.focus({preventScroll:!0}),t.update(()=>{const t=o.$getSelection();null===t||t.dirty||(t.dirty=!0)}),!0)},o.COMMAND_PRIORITY_HIGH))},[t,h,d]),/*#__PURE__*/i.createPortal(/*#__PURE__*/s.jsxs(s.Fragment,{children:[/*#__PURE__*/s.jsx("div",{draggable:!0,onDragStart:function(e){const n=e.dataTransfer;if(!n||!x)return;!function(t,e){const{transform:n}=e.style;e.style.transform="translateZ(0)",t.setDragImage(e,0,0),setTimeout(()=>{e.style.transform=n})}(n,x);let r="";if(t.update(()=>{const t=o.$getNearestNodeFromDOMNode(x);t&&(r=t.getKey())}),R.current=!0,n.setData(c,r),o.IS_FIREFOX){const e=t.getRootElement();null!==e&&o.getActiveElement(e)!==e&&(e.focus({preventScroll:!0}),t.update(()=>{const t=o.$getSelection();null===t||t.dirty||(t.dirty=!0)}))}},onDragEnd:function(){var e;R.current=!1,(e=u.current)&&(e.style.opacity="0",e.style.transform="translate(-10000px, -10000px)"),o.IS_FIREFOX&&t.focus()},children:h&&f}),p]}),l)}exports.DraggableBlockPlugin_EXPERIMENTAL=function({anchorElem:e=document.body,menuRef:n,targetLineRef:o,menuComponent:r,targetLineComponent:i,isOnMenu:s,onElementChanged:l}){const[a]=t.useLexicalComposerContext();return h(a,e,n,o,a._editable,r,i,s,l)};
9
+ "use strict";var t=require("@lexical/react/LexicalComposerContext"),e=require("@lexical/rich-text"),n=require("@lexical/utils"),o=require("lexical"),r=require("react"),i=require("react-dom"),s=require("react/jsx-runtime");class l{_x;_y;constructor(t,e){this._x=t,this._y=e}get x(){return this._x}get y(){return this._y}equals({x:t,y:e}){return this.x===t&&this.y===e}calcDeltaXTo({x:t}){return this.x-t}calcDeltaYTo({y:t}){return this.y-t}calcHorizontalDistanceTo(t){return Math.abs(this.calcDeltaXTo(t))}calcVerticalDistance(t){return Math.abs(this.calcDeltaYTo(t))}calcDistanceTo(t){return Math.sqrt(Math.pow(this.calcDeltaXTo(t),2)+Math.pow(this.calcDeltaYTo(t),2))}}class a{_left;_top;_right;_bottom;constructor(t,e,n,o){const[r,i]=e<=o?[e,o]:[o,e],[s,l]=t<=n?[t,n]:[n,t];this._top=r,this._right=l,this._left=s,this._bottom=i}get top(){return this._top}get right(){return this._right}get bottom(){return this._bottom}get left(){return this._left}get width(){return Math.abs(this._left-this._right)}get height(){return Math.abs(this._bottom-this._top)}equals({top:t,left:e,bottom:n,right:o}){return t===this._top&&n===this._bottom&&e===this._left&&o===this._right}contains(t){if(t instanceof l){const{x:e,y:n}=t,o=n<this._top,r=n>this._bottom,i=e<this._left,s=e>this._right;return{reason:{isOnBottomSide:r,isOnLeftSide:i,isOnRightSide:s,isOnTopSide:o},result:!(o||r||i||s)}}{const{top:e,left:n,bottom:o,right:r}=t;return e>=this._top&&e<=this._bottom&&o>=this._top&&o<=this._bottom&&n>=this._left&&n<=this._right&&r>=this._left&&r<=this._right}}intersectsWith(t){const{left:e,top:n,width:o,height:r}=t,{left:i,top:s,width:l,height:a}=this;return(e+o>=i+l?e+o:i+l)-(e<=i?e:i)<=o+l&&(n+r>=s+a?n+r:s+a)-(n<=s?n:s)<=r+a}generateNewRect({left:t=this.left,top:e=this.top,right:n=this.right,bottom:o=this.bottom}){return new a(t,e,n,o)}static fromLTRB(t,e,n,o){return new a(t,e,n,o)}static fromLWTH(t,e,n,o){return new a(t,n,t+e,n+o)}static fromPoints(t,e){const{y:n,x:o}=t,{y:r,x:i}=e;return a.fromLTRB(o,n,i,r)}static fromDOM(t){const{top:e,width:n,left:o,height:r}=t.getBoundingClientRect();return a.fromLWTH(o,n,e,r)}}const c="application/x-lexical-drag-block";let u=1/0;function g(t){const e=t.ownerDocument.defaultView,n=(t,n)=>t&&e?parseFloat(e.getComputedStyle(t)[n]):0,{marginTop:o="0",marginBottom:r="0"}=e?e.getComputedStyle(t):{},i=n(t.previousElementSibling,"marginBottom"),s=n(t.nextElementSibling,"marginTop"),l=Math.max(parseFloat(o),i);return{marginBottom:Math.max(parseFloat(r),s),marginTop:l}}function m(t,e,r,i=!1){const s=t.getBoundingClientRect(),c=function(t){return t.read("latest",()=>o.$getRoot().getChildrenKeys())}(e);let m=null;return e.read("latest",()=>{if(i){const[t,o]=[e.getElementByKey(c[0]),e.getElementByKey(c[c.length-1])],[i,s]=[null!=t?t.getBoundingClientRect():void 0,null!=o?o.getBoundingClientRect():void 0];if(i&&s){const e=n.calculateZoomLevel(t),l=n.calculateZoomLevel(o);if(r.y/e<i.top?m=t:r.y/l>s.bottom&&(m=o),m)return}}let t=0===(o=c.length)?1/0:u>=0&&u<o?u:Math.floor(o/2);var o;let h=0;for(;t>=0&&t<c.length;){const o=c[t],i=e.getElementByKey(o);if(null===i)break;const f=n.calculateZoomLevel(i),p=new l(r.x/f,r.y/f),d=a.fromDOM(i),{marginTop:_,marginBottom:y}=g(i),R=d.generateNewRect({bottom:d.bottom+y,left:s.left,right:s.right,top:d.top-_}),{result:x,reason:{isOnTopSide:E,isOnBottomSide:T}}=R.contains(p);if(x){m=i,u=t;break}0===h&&(h=E?-1:T?1:1/0),t+=h}}),m}function h(t,l,a,u,h,f,p,d,_){const y=o.getParentElement(l),R=r.useRef(!1),[x,E]=r.useState(null),T=r.useCallback(t=>{E(t),_&&_(t)},[_]);return r.useEffect(()=>{if(null!=y)return o.registerEventListeners(y,{mouseleave:function(){T(null)},mousemove:function(e){const n=o.getComposedEventTarget(e);if(!o.isHTMLElement(n))return void T(null);if(d(n))return;const r=m(l,t,e);T(r)}})},[y,l,t,d,T]),r.useEffect(()=>{const e=n.calculateZoomLevel(t.getRootElement(),!0);a.current&&function(t,e,n,o){if(!t)return void(e.style.display="none");const r=t.getBoundingClientRect(),i=t.ownerDocument.defaultView,s=i?i.getComputedStyle(t):null,l=e.getBoundingClientRect(),a=n.getBoundingClientRect();let c=s?parseInt(s.lineHeight,10):NaN;isNaN(c)&&(c=r.bottom-r.top);const u=(r.top+(c-(l.height||c))/2-a.top+n.scrollTop)/o;e.style.display="flex",e.style.opacity="1",e.style.transform=`translate(4px, ${u}px)`}(x,a.current,l,e)},[t,l,x,a]),r.useEffect(()=>{function r(r){if(!R.current)return!1;const[i]=e.eventFiles(r);if(i)return!1;const s=r.pageY,a=o.getComposedEventTarget(r);if(!o.isHTMLElement(a))return!1;const c=m(l,t,r,!0),h=u.current;return null!==c&&null!==h&&(function(t,e,n,o){const{top:r,height:i}=e.getBoundingClientRect(),{top:s,width:l}=o.getBoundingClientRect(),{marginTop:a,marginBottom:c}=g(e);let u=r;n>=r?u+=i+c/2:u-=a/2;const m=u-s-2+o.scrollTop;t.style.transform=`translate(24px, ${m}px)`,t.style.width=l-48+"px",t.style.opacity=".4"}(h,c,s/n.calculateZoomLevel(a),l),r.preventDefault(),!0)}return o.mergeRegister(t.registerCommand(o.DRAGOVER_COMMAND,t=>r(t),o.COMMAND_PRIORITY_LOW),t.registerCommand(o.DROP_COMMAND,r=>function(r){if(!R.current)return!1;const[i]=e.eventFiles(r);if(i)return!1;const{dataTransfer:s,pageY:a}=r,u=o.getComposedEventTarget(r),g=null!=s?s.getData(c):"",h=o.$getNodeByKey(g);if(!h)return!1;if(!o.isHTMLElement(u))return!1;const f=m(l,t,r,!0);if(!f)return!1;const p=o.$getNearestNodeFromDOMNode(f);if(!p)return!1;if(p===h)return o.IS_FIREFOX&&t.focus(),!0;const d=f.getBoundingClientRect().top;return a/n.calculateZoomLevel(u)>=d?p.insertAfter(h):p.insertBefore(h),T(null),o.IS_FIREFOX&&o.$onUpdate(()=>{t.focus()}),!0}(r),o.COMMAND_PRIORITY_HIGH))},[l,t,u,T]),r.useEffect(()=>{if(o.IS_FIREFOX&&h)return o.mergeRegister(t.registerRootListener(e=>{if(e)return o.registerEventListener(e,"blur",function(n){const r=n.relatedTarget;o.isHTMLElement(r)&&d(r)&&(e&&(e.focus({preventScroll:!0}),t.update(()=>{const t=o.$getSelection();null===t||t.dirty||(t.dirty=!0)})),n.stopImmediatePropagation())},!0)}),t.registerCommand(o.BLUR_COMMAND,()=>{const e=t.getRootElement(),n=o.getActiveElementDeep(o.getRootOwnerDocument(e));return!!(e&&o.isHTMLElement(n)&&d(n))&&(e.focus({preventScroll:!0}),t.update(()=>{const t=o.$getSelection();null===t||t.dirty||(t.dirty=!0)}),!0)},o.COMMAND_PRIORITY_HIGH))},[t,h,d]),/*#__PURE__*/i.createPortal(/*#__PURE__*/s.jsxs(s.Fragment,{children:[/*#__PURE__*/s.jsx("div",{draggable:!0,onDragStart:function(e){const n=e.dataTransfer;if(!n||!x)return;!function(t,e){const{transform:n}=e.style;e.style.transform="translateZ(0)",t.setDragImage(e,0,0),setTimeout(()=>{e.style.transform=n})}(n,x);let r="";if(t.update(()=>{const t=o.$getNearestNodeFromDOMNode(x);t&&(r=t.getKey())}),R.current=!0,n.setData(c,r),o.IS_FIREFOX){const e=t.getRootElement();null!==e&&o.getActiveElement(e)!==e&&(e.focus({preventScroll:!0}),t.update(()=>{const t=o.$getSelection();null===t||t.dirty||(t.dirty=!0)}))}},onDragEnd:function(){var e;R.current=!1,(e=u.current)&&(e.style.opacity="0",e.style.transform="translate(-10000px, -10000px)"),o.IS_FIREFOX&&t.focus()},children:h&&f}),p]}),l)}exports.DraggableBlockPlugin_EXPERIMENTAL=function({anchorElem:e=document.body,menuRef:n,targetLineRef:o,menuComponent:r,targetLineComponent:i,isOnMenu:s,onElementChanged:l}){const[a]=t.useLexicalComposerContext();return h(a,e,n,o,a._editable,r,i,s,l)};