@lexical/react 0.46.1-nightly.20260702.0 → 0.46.1-nightly.20260706.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 (92) hide show
  1. package/dist/LexicalClearEditorPlugin.dev.js +1 -1
  2. package/dist/LexicalClearEditorPlugin.dev.mjs +1 -1
  3. package/dist/LexicalCollaborationPlugin.dev.js +4 -6
  4. package/dist/LexicalCollaborationPlugin.dev.mjs +5 -7
  5. package/dist/LexicalCollaborationPlugin.prod.js +1 -1
  6. package/dist/LexicalCollaborationPlugin.prod.mjs +1 -1
  7. package/dist/LexicalComposer.dev.js +1 -1
  8. package/dist/LexicalComposer.dev.mjs +1 -1
  9. package/dist/LexicalContentEditable.dev.js +1 -1
  10. package/dist/LexicalContentEditable.dev.mjs +1 -1
  11. package/dist/LexicalDraggableBlockPlugin.dev.js +5 -10
  12. package/dist/LexicalDraggableBlockPlugin.dev.mjs +6 -11
  13. package/dist/LexicalDraggableBlockPlugin.prod.js +1 -1
  14. package/dist/LexicalDraggableBlockPlugin.prod.mjs +1 -1
  15. package/dist/LexicalNodeContextMenuPlugin.dev.js +1 -2
  16. package/dist/LexicalNodeContextMenuPlugin.dev.mjs +2 -3
  17. package/dist/LexicalNodeContextMenuPlugin.prod.js +1 -1
  18. package/dist/LexicalNodeContextMenuPlugin.prod.mjs +1 -1
  19. package/dist/LexicalNodeEventPlugin.dev.js +1 -2
  20. package/dist/LexicalNodeEventPlugin.dev.mjs +2 -3
  21. package/dist/LexicalNodeEventPlugin.prod.js +1 -1
  22. package/dist/LexicalNodeEventPlugin.prod.mjs +1 -1
  23. package/dist/LexicalNodeMenuPlugin.dev.js +33 -67
  24. package/dist/LexicalNodeMenuPlugin.dev.mjs +12 -46
  25. package/dist/LexicalNodeMenuPlugin.prod.js +1 -1
  26. package/dist/LexicalNodeMenuPlugin.prod.mjs +1 -1
  27. package/dist/LexicalOnChangePlugin.dev.js +1 -1
  28. package/dist/LexicalOnChangePlugin.dev.mjs +1 -1
  29. package/dist/LexicalPlainTextPlugin.dev.js +1 -1
  30. package/dist/LexicalPlainTextPlugin.dev.mjs +1 -1
  31. package/dist/LexicalRichTextPlugin.dev.js +1 -1
  32. package/dist/LexicalRichTextPlugin.dev.mjs +1 -1
  33. package/dist/LexicalTypeaheadMenuPlugin.dev.js +33 -67
  34. package/dist/LexicalTypeaheadMenuPlugin.dev.mjs +12 -46
  35. package/dist/LexicalTypeaheadMenuPlugin.prod.js +1 -1
  36. package/dist/LexicalTypeaheadMenuPlugin.prod.mjs +1 -1
  37. package/dist/useLexicalAriaLiveRegion.d.ts +13 -0
  38. package/dist/useLexicalAriaLiveRegion.dev.js +38 -0
  39. package/dist/useLexicalAriaLiveRegion.dev.mjs +36 -0
  40. package/dist/useLexicalAriaLiveRegion.js +11 -0
  41. package/dist/{shared/reactPatches.d.ts → useLexicalAriaLiveRegion.js.flow} +3 -1
  42. package/dist/useLexicalAriaLiveRegion.mjs +12 -0
  43. package/dist/useLexicalAriaLiveRegion.node.mjs +10 -0
  44. package/dist/useLexicalAriaLiveRegion.prod.js +9 -0
  45. package/dist/useLexicalAriaLiveRegion.prod.mjs +9 -0
  46. package/dist/useLexicalEditable.dev.js +1 -1
  47. package/dist/useLexicalEditable.dev.mjs +1 -1
  48. package/dist/useLexicalFocusManagerRef.d.ts +26 -0
  49. package/dist/useLexicalFocusManagerRef.dev.js +59 -0
  50. package/dist/useLexicalFocusManagerRef.dev.mjs +57 -0
  51. package/dist/useLexicalFocusManagerRef.js +11 -0
  52. package/dist/useLexicalFocusManagerRef.js.flow +16 -0
  53. package/dist/useLexicalFocusManagerRef.mjs +12 -0
  54. package/dist/useLexicalFocusManagerRef.node.mjs +10 -0
  55. package/dist/useLexicalFocusManagerRef.prod.js +9 -0
  56. package/dist/useLexicalFocusManagerRef.prod.mjs +9 -0
  57. package/dist/useLexicalFocusTrapRef.d.ts +33 -0
  58. package/dist/useLexicalFocusTrapRef.dev.js +72 -0
  59. package/dist/useLexicalFocusTrapRef.dev.mjs +70 -0
  60. package/dist/useLexicalFocusTrapRef.js +11 -0
  61. package/dist/useLexicalFocusTrapRef.js.flow +16 -0
  62. package/dist/useLexicalFocusTrapRef.mjs +12 -0
  63. package/dist/useLexicalFocusTrapRef.node.mjs +10 -0
  64. package/dist/useLexicalFocusTrapRef.prod.js +9 -0
  65. package/dist/useLexicalFocusTrapRef.prod.mjs +9 -0
  66. package/dist/useLexicalIsTextContentEmpty.dev.js +1 -1
  67. package/dist/useLexicalIsTextContentEmpty.dev.mjs +1 -1
  68. package/dist/useLexicalRovingTabIndexRef.d.ts +26 -0
  69. package/dist/useLexicalRovingTabIndexRef.dev.js +61 -0
  70. package/dist/useLexicalRovingTabIndexRef.dev.mjs +59 -0
  71. package/dist/useLexicalRovingTabIndexRef.js +11 -0
  72. package/dist/useLexicalRovingTabIndexRef.js.flow +19 -0
  73. package/dist/useLexicalRovingTabIndexRef.mjs +12 -0
  74. package/dist/useLexicalRovingTabIndexRef.node.mjs +10 -0
  75. package/dist/useLexicalRovingTabIndexRef.prod.js +9 -0
  76. package/dist/useLexicalRovingTabIndexRef.prod.mjs +9 -0
  77. package/dist/useLexicalSubscription.dev.js +1 -1
  78. package/dist/useLexicalSubscription.dev.mjs +1 -1
  79. package/package.json +166 -21
  80. package/src/LexicalDraggableBlockPlugin.tsx +7 -11
  81. package/src/LexicalNodeContextMenuPlugin.tsx +7 -4
  82. package/src/LexicalNodeEventPlugin.ts +11 -4
  83. package/src/LexicalNodeMenuPlugin.tsx +1 -2
  84. package/src/LexicalTypeaheadMenuPlugin.tsx +1 -2
  85. package/src/shared/LexicalMenu.tsx +18 -21
  86. package/src/shared/useLayoutEffect.ts +1 -1
  87. package/src/shared/useYjsCollaboration.tsx +5 -7
  88. package/src/useLexicalAriaLiveRegion.ts +31 -0
  89. package/src/useLexicalFocusManagerRef.ts +56 -0
  90. package/src/useLexicalFocusTrapRef.ts +73 -0
  91. package/src/useLexicalRovingTabIndexRef.ts +60 -0
  92. package/src/shared/reactPatches.ts +0 -22
@@ -23,7 +23,7 @@ var react = require('react');
23
23
 
24
24
 
25
25
  // This workaround is no longer necessary in React 19,
26
- // but we currently support React >=17.x
26
+ // but we currently support React >=18.x
27
27
  // https://github.com/facebook/react/pull/26395
28
28
  const useLayoutEffectImpl = lexical.CAN_USE_DOM ? react.useLayoutEffect : react.useEffect;
29
29
 
@@ -21,7 +21,7 @@ import { useLayoutEffect, useEffect } from 'react';
21
21
 
22
22
 
23
23
  // This workaround is no longer necessary in React 19,
24
- // but we currently support React >=17.x
24
+ // but we currently support React >=18.x
25
25
  // https://github.com/facebook/react/pull/26395
26
26
  const useLayoutEffectImpl = CAN_USE_DOM ? useLayoutEffect : useEffect;
27
27
 
@@ -281,12 +281,10 @@ function useProvider(editor, provider, name, color, isReloadingDoc, awarenessDat
281
281
  // Use both beforeunload and pagehide for maximum browser compatibility
282
282
  // beforeunload: fires before page unloads (may be cancelable)
283
283
  // pagehide: fires when page is being unloaded (more reliable, especially on mobile)
284
- window.addEventListener('beforeunload', clearAwarenessState);
285
- window.addEventListener('pagehide', clearAwarenessState);
286
- return () => {
287
- window.removeEventListener('beforeunload', clearAwarenessState);
288
- window.removeEventListener('pagehide', clearAwarenessState);
289
- };
284
+ return lexical.registerEventListeners(window, {
285
+ beforeunload: clearAwarenessState,
286
+ pagehide: clearAwarenessState
287
+ });
290
288
  }, [provider]);
291
289
  }
292
290
  function useAwareness(binding, provider, selectionHighlight) {
@@ -11,7 +11,7 @@ import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext
11
11
  import { syncCursorPositions, syncLexicalUpdateToYjs, createUndoManager, setLocalStateFocus, createBindingV2__EXPERIMENTAL, CLEAR_DIFF_VERSIONS_COMMAND__EXPERIMENTAL, syncYjsStateToLexicalV2__EXPERIMENTAL, DIFF_VERSIONS_COMMAND__EXPERIMENTAL, renderSnapshot__EXPERIMENTAL, syncLexicalUpdateToYjsV2__EXPERIMENTAL, syncYjsChangesToLexical, initLocalState, TOGGLE_CONNECT_COMMAND, syncYjsChangesToLexicalV2__EXPERIMENTAL, removeCursorHighlightRule, CONNECTED_COMMAND, createBinding } from '@lexical/yjs';
12
12
  import * as React from 'react';
13
13
  import { useRef, useCallback, useEffect, useMemo, useState } from 'react';
14
- import { SKIP_COLLAB_TAG, mergeRegister, FOCUS_COMMAND, COMMAND_PRIORITY_EDITOR, BLUR_COMMAND, $getRoot, HISTORY_MERGE_TAG, $createParagraphNode, $getSelection, getActiveElement, UNDO_COMMAND, REDO_COMMAND, CAN_UNDO_COMMAND, CAN_REDO_COMMAND } from 'lexical';
14
+ import { SKIP_COLLAB_TAG, mergeRegister, FOCUS_COMMAND, COMMAND_PRIORITY_EDITOR, BLUR_COMMAND, $getRoot, HISTORY_MERGE_TAG, $createParagraphNode, $getSelection, getActiveElement, registerEventListeners, UNDO_COMMAND, REDO_COMMAND, CAN_UNDO_COMMAND, CAN_REDO_COMMAND } from 'lexical';
15
15
  import { createPortal } from 'react-dom';
16
16
  import { UndoManager } from 'yjs';
17
17
  import { jsx, Fragment } from 'react/jsx-runtime';
@@ -267,12 +267,10 @@ function useProvider(editor, provider, name, color, isReloadingDoc, awarenessDat
267
267
  // Use both beforeunload and pagehide for maximum browser compatibility
268
268
  // beforeunload: fires before page unloads (may be cancelable)
269
269
  // pagehide: fires when page is being unloaded (more reliable, especially on mobile)
270
- window.addEventListener('beforeunload', clearAwarenessState);
271
- window.addEventListener('pagehide', clearAwarenessState);
272
- return () => {
273
- window.removeEventListener('beforeunload', clearAwarenessState);
274
- window.removeEventListener('pagehide', clearAwarenessState);
275
- };
270
+ return registerEventListeners(window, {
271
+ beforeunload: clearAwarenessState,
272
+ pagehide: clearAwarenessState
273
+ });
276
274
  }, [provider]);
277
275
  }
278
276
  function useAwareness(binding, provider, selectionHighlight) {
@@ -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"),n=require("react"),r=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(n);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=n.useRef(!1),D=n.useCallback(()=>{const{root:t}=d;u&&t.isEmpty()&&0===t._xmlText._length&&_(e,m)},[d,e,m,u]);return n.useEffect(()=>{const{root:t}=d,n=(e,t)=>{const n=t.origin;if(n!==d){const t=n instanceof a.UndoManager;o.syncYjsChangesToLexical(d,s,e,t,M)}};t.getSharedType().observeDeep(n);const c=e.registerUpdateListener(({prevEditorState:e,editorState:t,dirtyLeaves:n,dirtyElements:a,normalizedNodes:c,tags:i})=>{i.has(r.SKIP_COLLAB_TAG)||o.syncLexicalUpdateToYjs(d,s,e,t,a,n,c,i)});return()=>{t.getSharedType().unobserveDeep(n),c()}},[d,s,e,C,c,t,M]),n.useEffect(()=>{const n=n=>{!function(e,t){if(e.update(()=>{const e=r.$getRoot();e.clear(),e.select()},{tag:r.SKIP_COLLAB_TAG}),null==t.cursors)return;const n=t.cursors;if(null==n)return;const s=t.cursorsContainer;if(null==s)return;for(const e of n.values()){const n=e.selection;if(null!==n){null!==n.highlight&&(CSS.highlights.delete(n.highlightName),o.removeCursorHighlightRule(t,n.highlightName)),n.caret.parentNode===s&&s.removeChild(n.caret);for(const e of n.selections)e.parentNode===s&&s.removeChild(e);e.selection=null}}}(e,d),C(n),c.set(t,n),O.current=!0},a=()=>{O.current=!1};return s.on("reload",n),s.on("sync",a),()=>{s.off("reload",n),s.off("sync",a)}},[d,s,e,C,c,t]),f(e,s,i,l,O,h,D),E(d,s,R),g(d,p)}function f(e,t,s,a,c,i,l){const u=n.useCallback(()=>t.connect(),[t]),d=n.useCallback(()=>{try{t.disconnect()}catch(e){}},[t]);n.useEffect(()=>{const n=({status:t})=>{e.dispatchCommand(o.CONNECTED_COMMAND,"connected"===t)},f=e=>{e&&!1===c.current&&l&&l()},E=e.getRootElement();o.initLocalState(t,s,a,null!==E&&r.getActiveElement(E)===E,i||{}),t.on("status",n),t.on("sync",f);const g=u();return()=>{!1===c.current&&(g?g.then(d):d()),t.off("sync",f),t.off("status",n)}},[e,t,s,a,c,i,l,u,d]),n.useEffect(()=>e.registerCommand(o.TOGGLE_CONNECT_COMMAND,e=>(e?(console.log("Collaboration connected!"),u()):(console.log("Collaboration disconnected!"),d()),!0),r.COMMAND_PRIORITY_EDITOR),[u,d,e]),n.useEffect(()=>{const e=()=>{try{t.awareness.setLocalState(null)}catch(e){}};return window.addEventListener("beforeunload",e),window.addEventListener("pagehide",e),()=>{window.removeEventListener("beforeunload",e),window.removeEventListener("pagehide",e)}},[t])}function E(e,t,r){n.useEffect(()=>{const{awareness:n}=t,s=()=>{o.syncCursorPositions(e,t,{selectionHighlight:r})};return n.on("update",s),()=>{n.off("update",s)}},[e,t,r])}function g(e,t){return n.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){n.useEffect(()=>r.mergeRegister(e.registerCommand(r.FOCUS_COMMAND,()=>(o.setLocalStateFocus(t,s,a,!0,c||{}),!1),r.COMMAND_PRIORITY_EDITOR),e.registerCommand(r.BLUR_COMMAND,()=>(o.setLocalStateFocus(t,s,a,!1,c||{}),!1),r.COMMAND_PRIORITY_EDITOR)),[a,e,s,t,c])}function p(e,t){n.useEffect(()=>r.mergeRegister(e.registerCommand(r.UNDO_COMMAND,()=>(t.undo(),!0),r.COMMAND_PRIORITY_EDITOR),e.registerCommand(r.REDO_COMMAND,()=>(t.redo(),!0),r.COMMAND_PRIORITY_EDITOR))),n.useEffect(()=>{const o=e;return o[u]=t,()=>{o[u]===t&&delete o[u]}},[e,t]);const o=n.useCallback(()=>{t.clear()},[t]);return l.useEffect(()=>{const o=()=>{e.dispatchCommand(r.CAN_UNDO_COMMAND,t.undoStack.length>0),e.dispatchCommand(r.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=r.$getRoot();if(o.isEmpty())if(t)switch(typeof t){case"string":{const o=e.parseEditorState(t);e.setEditorState(o,{tag:r.HISTORY_MERGE_TAG});break}case"object":e.setEditorState(t,{tag:r.HISTORY_MERGE_TAG});break;case"function":e.update(()=>{r.$getRoot().isEmpty()&&t(e)},{tag:r.HISTORY_MERGE_TAG})}else{const t=r.$createParagraphNode();o.append(t);const{activeElement:n}=document;(null!==r.$getSelection()||null!==n&&n===e.getRootElement())&&t.select()}},{tag:r.HISTORY_MERGE_TAG})}function m({editor:e,id:t,provider:r,yjsDocMap:s,name:a,color:c,shouldBootstrap:i,cursorsContainerRef:l,initialEditorState:u,awarenessData:f,collabContext:E,binding:g,setDoc:_,syncCursorPositionsFn:m,selectionHighlight:h}){const M=d(e,t,r,s,a,c,i,g,_,l,u,f,m,h);return function(e,t){p(e,n.useMemo(()=>o.createUndoManager(t,t.root.getSharedType()),[t]))}(e,g),C(e,r,a,c,f),M}const h=(e,t)=>{n.useEffect(()=>(e.isCollabActive=!0,()=>{null==t._parentEditor&&(e.isCollabActive=!1)}),[e,t])};exports.CollaborationPlugin=function({id:r,providerFactory:s,shouldBootstrap:a,username:i,cursorColor:l,cursorsContainerRef:u,initialEditorState:d,excludedProperties:f,awarenessData:E,syncCursorPositionsFn:g,selectionHighlight:C}){const p=n.useRef(!1),_=n.useRef(!1),M=e.useCollaborationContext(i,l),{yjsDocMap:R,name:O,color:D}=M,[T]=t.useLexicalComposerContext();h(M,T);const[N,S]=n.useState(),[A,I]=n.useState();n.useEffect(()=>{if(_.current)return;_.current=!0;const e=s(r,R);return S(e),I(R.get(r)),()=>{e.disconnect()}},[r,s,R]);const[y,L]=n.useState();return n.useEffect(()=>{if(!N)return;if(p.current)return;p.current=!0;const e=o.createBinding(T,N,r,A||R.get(r),R,f);return L(e),()=>{e.root.destroy(e)}},[T,N,r,R,A,f]),N&&y?/*#__PURE__*/c.jsx(m,{awarenessData:E,binding:y,collabContext:M,color:D,cursorsContainerRef:u,editor:T,id:r,initialEditorState:d,name:O,provider:N,setDoc:I,shouldBootstrap:a,yjsDocMap:R,syncCursorPositionsFn:g,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:g,excludedProperties:C,rootName:p,selectionHighlight:m=!1,__shouldBootstrapUnsafe:h}=d,M=n.useMemo(()=>({current:!1}),[]),R=n.useMemo(()=>o.createBindingV2__EXPERIMENTAL(e,t,s,i,{excludedProperties:C,rootName:p}),[e,t,s,i,C,p]);n.useEffect(()=>(i.set(t,s),()=>{i.delete(t)}),[s,i,t]);const O=n.useCallback(()=>{const{root:t}=R;h&&0===t._length&&_(e)},[R,e,h]),[D,T]=n.useState();return n.useEffect(()=>{r.mergeRegister(e.registerCommand(o.CLEAR_DIFF_VERSIONS_COMMAND__EXPERIMENTAL,()=>(T(null),o.syncYjsStateToLexicalV2__EXPERIMENTAL(R,c),!0),r.COMMAND_PRIORITY_EDITOR),e.registerCommand(o.DIFF_VERSIONS_COMMAND__EXPERIMENTAL,({prevSnapshot:e,snapshot:t})=>(T({prevSnapshot:e,snapshot:t}),!0),r.COMMAND_PRIORITY_EDITOR))},[e,R,c]),n.useEffect(()=>{const{root:t}=R;if(D)return void o.renderSnapshot__EXPERIMENTAL(R,D.snapshot,D.prevSnapshot);const n=(e,t)=>{const n=t.origin;if(n!==R){const r=n instanceof a.UndoManager;o.syncYjsChangesToLexicalV2__EXPERIMENTAL(R,c,e,t,r)}};t.observeDeep(n);const s=e.registerUpdateListener(({prevEditorState:e,editorState:t,dirtyElements:n,dirtyLeaves:s,normalizedNodes:a,tags:i})=>{i.has(r.SKIP_COLLAB_TAG)||o.syncLexicalUpdateToYjsV2__EXPERIMENTAL(R,c,e,t,n,s,a,i)});return()=>{t.unobserveDeep(n),s()}},[R,c,e,D]),f(e,c,l,u,M,g,O),E(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,n.useMemo(()=>o.createUndoManager(t,t.root),[t]))}(A,I),C(A,i,N,S,R),g(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{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)};
@@ -6,4 +6,4 @@
6
6
  *
7
7
  */
8
8
 
9
- import{useCollaborationContext as e}from"@lexical/react/LexicalCollaborationContext";import{useLexicalComposerContext as t}from"@lexical/react/LexicalComposerContext";import{syncCursorPositions as o,syncLexicalUpdateToYjs as n,createUndoManager as r,setLocalStateFocus as s,createBindingV2__EXPERIMENTAL as i,CLEAR_DIFF_VERSIONS_COMMAND__EXPERIMENTAL as a,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 E,useCallback as S,useEffect as b,useMemo as x,useState as w}from"react";import{SKIP_COLLAB_TAG as D,mergeRegister as L,FOCUS_COMMAND as k,COMMAND_PRIORITY_EDITOR as _,BLUR_COMMAND as j,$getRoot as N,HISTORY_MERGE_TAG as P,$createParagraphNode as H,$getSelection as B,getActiveElement as R,UNDO_COMMAND as U,REDO_COMMAND as M,CAN_UNDO_COMMAND as F,CAN_REDO_COMMAND as T}from"lexical";import{createPortal as z}from"react-dom";import{UndoManager as A}from"yjs";import{jsx as q,Fragment as G}from"react/jsx-runtime";const I=Symbol.for("@lexical/yjs/UndoManager");function J(e,t,r,s,i,a,c,l,d,u,m,f,g=o,C=!1){const y=E(!1),v=S(()=>{const{root:t}=l;c&&t.isEmpty()&&0===t._xmlText._length&&X(e,m)},[l,e,m,c]);return b(()=>{const{root:t}=l,o=(e,t)=>{const o=t.origin;if(o!==l){p(l,r,e,o instanceof A,g)}};t.getSharedType().observeDeep(o);const s=e.registerUpdateListener(({prevEditorState:e,editorState:t,dirtyLeaves:o,dirtyElements:s,normalizedNodes:i,tags:a})=>{a.has(D)||n(l,r,e,t,s,o,i,a)});return()=>{t.getSharedType().unobserveDeep(o),s()}},[l,r,e,d,s,t,g]),b(()=>{const o=o=>{!function(e,t){if(e.update(()=>{const e=N();e.clear(),e.select()},{tag:D}),null==t.cursors)return;const o=t.cursors;if(null==o)return;const n=t.cursorsContainer;if(null==n)return;for(const e of o.values()){const o=e.selection;if(null!==o){null!==o.highlight&&(CSS.highlights.delete(o.highlightName),h(t,o.highlightName)),o.caret.parentNode===n&&n.removeChild(o.caret);for(const e of o.selections)e.parentNode===n&&n.removeChild(e);e.selection=null}}}(e,l),d(o),s.set(t,o),y.current=!0},n=()=>{y.current=!1};return r.on("reload",o),r.on("sync",n),()=>{r.off("reload",o),r.off("sync",n)}},[l,r,e,d,s,t]),K(e,r,i,a,y,f,v),O(l,r,C),Q(l,u)}function K(e,t,o,n,r,s,i){const a=S(()=>t.connect(),[t]),c=S(()=>{try{t.disconnect()}catch(e){}},[t]);b(()=>{const l=({status:t})=>{e.dispatchCommand(C,"connected"===t)},d=e=>{e&&!1===r.current&&i&&i()},u=e.getRootElement();m(t,o,n,null!==u&&R(u)===u,s||{}),t.on("status",l),t.on("sync",d);const p=a();return()=>{!1===r.current&&(p?p.then(c):c()),t.off("sync",d),t.off("status",l)}},[e,t,o,n,r,s,i,a,c]),b(()=>e.registerCommand(f,e=>(e?(console.log("Collaboration connected!"),a()):(console.log("Collaboration disconnected!"),c()),!0),_),[a,c,e]),b(()=>{const e=()=>{try{t.awareness.setLocalState(null)}catch(e){}};return window.addEventListener("beforeunload",e),window.addEventListener("pagehide",e),()=>{window.removeEventListener("beforeunload",e),window.removeEventListener("pagehide",e)}},[t])}function O(e,t,n){b(()=>{const{awareness:r}=t,s=()=>{o(e,t,{selectionHighlight:n})};return r.on("update",s),()=>{r.off("update",s)}},[e,t,n])}function Q(e,t){return x(()=>/*#__PURE__*/z(/*#__PURE__*/q("div",{ref:t=>{e.cursorsContainer=t}}),t&&t.current||document.body),[e,t])}function V(e,t,o,n,r){b(()=>L(e.registerCommand(k,()=>(s(t,o,n,!0,r||{}),!1),_),e.registerCommand(j,()=>(s(t,o,n,!1,r||{}),!1),_)),[n,e,o,t,r])}function W(e,t){b(()=>L(e.registerCommand(U,()=>(t.undo(),!0),_),e.registerCommand(M,()=>(t.redo(),!0),_))),b(()=>{const o=e;return o[I]=t,()=>{o[I]===t&&delete o[I]}},[e,t]);const o=S(()=>{t.clear()},[t]);return v.useEffect(()=>{const o=()=>{e.dispatchCommand(F,t.undoStack.length>0),e.dispatchCommand(T,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 X(e,t){e.update(()=>{const o=N();if(o.isEmpty())if(t)switch(typeof t){case"string":{const o=e.parseEditorState(t);e.setEditorState(o,{tag:P});break}case"object":e.setEditorState(t,{tag:P});break;case"function":e.update(()=>{N().isEmpty()&&t(e)},{tag:P})}else{const t=H();o.append(t);const{activeElement:n}=document;(null!==B()||null!==n&&n===e.getRootElement())&&t.select()}},{tag:P})}function Y({id:o,providerFactory:n,shouldBootstrap:r,username:s,cursorColor:i,cursorsContainerRef:a,initialEditorState:c,excludedProperties:l,awarenessData:d,syncCursorPositionsFn:u,selectionHighlight:p}){const m=E(!1),f=E(!1),g=e(s,i),{yjsDocMap:h,name:C,color:v}=g,[S]=t();ee(g,S);const[x,D]=w(),[L,k]=w();b(()=>{if(f.current)return;f.current=!0;const e=n(o,h);return D(e),k(h.get(o)),()=>{e.disconnect()}},[o,n,h]);const[_,j]=w();return b(()=>{if(!x)return;if(m.current)return;m.current=!0;const e=y(S,x,o,L||h.get(o),h,l);return j(e),()=>{e.root.destroy(e)}},[S,x,o,h,L,l]),x&&_?/*#__PURE__*/q(Z,{awarenessData:d,binding:_,collabContext:g,color:v,cursorsContainerRef:a,editor:S,id:o,initialEditorState:c,name:C,provider:x,setDoc:k,shouldBootstrap:r,yjsDocMap:h,syncCursorPositionsFn:u,selectionHighlight:p}):/*#__PURE__*/q(G,{})}function Z({editor:e,id:t,provider:o,yjsDocMap:n,name:s,color:i,shouldBootstrap:a,cursorsContainerRef:c,initialEditorState:l,awarenessData:d,collabContext:u,binding:p,setDoc:m,syncCursorPositionsFn:f,selectionHighlight:g}){const h=J(e,t,o,n,s,i,a,p,m,c,l,d,f,g);return function(e,t){W(e,x(()=>r(t,t.root.getSharedType()),[t]))}(e,p),V(e,o,s,i,d),h}function $({id:o,doc:n,provider:s,__shouldBootstrapUnsafe:p,username:m,cursorColor:f,cursorsContainerRef:h,excludedProperties:C,awarenessData:y,selectionHighlight:v}){const E=e(m,f),{yjsDocMap:k,name:j,color:N}=E,[P]=t();ee(E,P);const H=function(e,t,o,n,r,s,p,m={}){const{awarenessData:f,excludedProperties:h,rootName:C,selectionHighlight:y=!1,__shouldBootstrapUnsafe:v}=m,E=x(()=>({current:!1}),[]),k=x(()=>i(e,t,o,r,{excludedProperties:h,rootName:C}),[e,t,o,r,h,C]);b(()=>(r.set(t,o),()=>{r.delete(t)}),[o,r,t]);const j=S(()=>{const{root:t}=k;v&&0===t._length&&X(e)},[k,e,v]),[N,P]=w();return b(()=>{L(e.registerCommand(a,()=>(P(null),c(k,n),!0),_),e.registerCommand(l,({prevSnapshot:e,snapshot:t})=>(P({prevSnapshot:e,snapshot:t}),!0),_))},[e,k,n]),b(()=>{const{root:t}=k;if(N)return void d(k,N.snapshot,N.prevSnapshot);const o=(e,t)=>{const o=t.origin;o!==k&&g(k,n,e,t,o instanceof A)};t.observeDeep(o);const r=e.registerUpdateListener(({prevEditorState:e,editorState:t,dirtyElements:o,dirtyLeaves:r,normalizedNodes:s,tags:i})=>{i.has(D)||u(k,n,e,t,o,r,s,i)});return()=>{t.unobserveDeep(o),r()}},[k,n,e,N]),K(e,n,s,p,E,f,j),O(k,n,y),k}(P,o,n,s,k,j,N,{__shouldBootstrapUnsafe:p,awarenessData:y,excludedProperties:C,selectionHighlight:v});return function(e,t){W(e,x(()=>r(t,t.root),[t]))}(P,H),V(P,s,j,N,y),Q(H,h)}const ee=(e,t)=>{b(()=>(e.isCollabActive=!0,()=>{null==t._parentEditor&&(e.isCollabActive=!1)}),[e,t])};export{Y as CollaborationPlugin,$ 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 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};
@@ -23,7 +23,7 @@ var jsxRuntime = require('react/jsx-runtime');
23
23
 
24
24
 
25
25
  // This workaround is no longer necessary in React 19,
26
- // but we currently support React >=17.x
26
+ // but we currently support React >=18.x
27
27
  // https://github.com/facebook/react/pull/26395
28
28
  const useLayoutEffectImpl = lexical.CAN_USE_DOM ? react.useLayoutEffect : react.useEffect;
29
29
 
@@ -21,7 +21,7 @@ import { jsx } from 'react/jsx-runtime';
21
21
 
22
22
 
23
23
  // This workaround is no longer necessary in React 19,
24
- // but we currently support React >=17.x
24
+ // but we currently support React >=18.x
25
25
  // https://github.com/facebook/react/pull/26395
26
26
  const useLayoutEffectImpl = CAN_USE_DOM ? useLayoutEffect : useEffect;
27
27
 
@@ -44,7 +44,7 @@ function mergeRefs(...refs) {
44
44
 
45
45
 
46
46
  // This workaround is no longer necessary in React 19,
47
- // but we currently support React >=17.x
47
+ // but we currently support React >=18.x
48
48
  // https://github.com/facebook/react/pull/26395
49
49
  const useLayoutEffectImpl = lexical.CAN_USE_DOM ? react.useLayoutEffect : react.useEffect;
50
50
 
@@ -42,7 +42,7 @@ function mergeRefs(...refs) {
42
42
 
43
43
 
44
44
  // This workaround is no longer necessary in React 19,
45
- // but we currently support React >=17.x
45
+ // but we currently support React >=18.x
46
46
  // https://github.com/facebook/react/pull/26395
47
47
  const useLayoutEffectImpl = CAN_USE_DOM ? useLayoutEffect : useEffect;
48
48
 
@@ -401,15 +401,11 @@ function useDraggableBlockMenu(editor, anchorElem, menuRef, targetLineRef, isEdi
401
401
  setDraggableBlockElem(null);
402
402
  }
403
403
  if (scrollerElem != null) {
404
- scrollerElem.addEventListener('mousemove', onMouseMove);
405
- scrollerElem.addEventListener('mouseleave', onMouseLeave);
404
+ return lexical.registerEventListeners(scrollerElem, {
405
+ mouseleave: onMouseLeave,
406
+ mousemove: onMouseMove
407
+ });
406
408
  }
407
- return () => {
408
- if (scrollerElem != null) {
409
- scrollerElem.removeEventListener('mousemove', onMouseMove);
410
- scrollerElem.removeEventListener('mouseleave', onMouseLeave);
411
- }
412
- };
413
409
  }, [scrollerElem, anchorElem, editor, isOnMenu, setDraggableBlockElem]);
414
410
  react.useEffect(() => {
415
411
  const zoomLevel = utils.calculateZoomLevel(editor.getRootElement(), true);
@@ -536,8 +532,7 @@ function useDraggableBlockMenu(editor, anchorElem, menuRef, targetLineRef, isEdi
536
532
  }
537
533
  }
538
534
  if (rootElement) {
539
- rootElement.addEventListener('blur', onBlur, true);
540
- return () => rootElement.removeEventListener('blur', onBlur, true);
535
+ return lexical.registerEventListener(rootElement, 'blur', onBlur, true);
541
536
  }
542
537
  }),
543
538
  // Intercept BLUR_COMMAND if focus is on the menu (fallback in case event propagation wasn't stopped)
@@ -9,7 +9,7 @@
9
9
  import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
10
10
  import { eventFiles } from '@lexical/rich-text';
11
11
  import { calculateZoomLevel } from '@lexical/utils';
12
- import { getParentElement, mergeRegister, DRAGOVER_COMMAND, COMMAND_PRIORITY_LOW, DROP_COMMAND, COMMAND_PRIORITY_HIGH, IS_FIREFOX, BLUR_COMMAND, getActiveElementDeep, getRootOwnerDocument, isHTMLElement, $getSelection, getComposedEventTarget, $getNodeByKey, $getNearestNodeFromDOMNode, $onUpdate, getActiveElement, $getRoot } from 'lexical';
12
+ import { getParentElement, registerEventListeners, mergeRegister, DRAGOVER_COMMAND, COMMAND_PRIORITY_LOW, DROP_COMMAND, COMMAND_PRIORITY_HIGH, IS_FIREFOX, registerEventListener, BLUR_COMMAND, getActiveElementDeep, getRootOwnerDocument, isHTMLElement, $getSelection, getComposedEventTarget, $getNodeByKey, $getNearestNodeFromDOMNode, $onUpdate, getActiveElement, $getRoot } from 'lexical';
13
13
  import { useRef, useState, useCallback, useEffect } from 'react';
14
14
  import { createPortal } from 'react-dom';
15
15
  import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
@@ -399,15 +399,11 @@ function useDraggableBlockMenu(editor, anchorElem, menuRef, targetLineRef, isEdi
399
399
  setDraggableBlockElem(null);
400
400
  }
401
401
  if (scrollerElem != null) {
402
- scrollerElem.addEventListener('mousemove', onMouseMove);
403
- scrollerElem.addEventListener('mouseleave', onMouseLeave);
402
+ return registerEventListeners(scrollerElem, {
403
+ mouseleave: onMouseLeave,
404
+ mousemove: onMouseMove
405
+ });
404
406
  }
405
- return () => {
406
- if (scrollerElem != null) {
407
- scrollerElem.removeEventListener('mousemove', onMouseMove);
408
- scrollerElem.removeEventListener('mouseleave', onMouseLeave);
409
- }
410
- };
411
407
  }, [scrollerElem, anchorElem, editor, isOnMenu, setDraggableBlockElem]);
412
408
  useEffect(() => {
413
409
  const zoomLevel = calculateZoomLevel(editor.getRootElement(), true);
@@ -534,8 +530,7 @@ function useDraggableBlockMenu(editor, anchorElem, menuRef, targetLineRef, isEdi
534
530
  }
535
531
  }
536
532
  if (rootElement) {
537
- rootElement.addEventListener('blur', onBlur, true);
538
- return () => rootElement.removeEventListener('blur', onBlur, true);
533
+ return registerEventListener(rootElement, 'blur', onBlur, true);
539
534
  }
540
535
  }),
541
536
  // Intercept BLUR_COMMAND if focus is on the menu (fallback in case event propagation wasn't stopped)
@@ -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),d=new l(r.x/f,r.y/f),p=a.fromDOM(i),{marginTop:_,marginBottom:y}=g(i),R=p.generateNewRect({bottom:p.bottom+y,left:s.left,right:s.right,top:p.top-_}),{result:E,reason:{isOnTopSide:v,isOnBottomSide:x}}=R.contains(d);if(E){m=i,u=t;break}0===h&&(h=v?-1:x?1:1/0),t+=h}}),m}function h(t,l,a,u,h,f,d,p,_){const y=o.getParentElement(l),R=r.useRef(!1),[E,v]=r.useState(null),x=r.useCallback(t=>{v(t),_&&_(t)},[_]);return r.useEffect(()=>{function e(e){const n=o.getComposedEventTarget(e);if(!o.isHTMLElement(n))return void x(null);if(p(n))return;const r=m(l,t,e);x(r)}function n(){x(null)}return null!=y&&(y.addEventListener("mousemove",e),y.addEventListener("mouseleave",n)),()=>{null!=y&&(y.removeEventListener("mousemove",e),y.removeEventListener("mouseleave",n))}},[y,l,t,p,x]),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)`}(E,a.current,l,e)},[t,l,E,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 d=o.$getNearestNodeFromDOMNode(f);if(!d)return!1;if(d===h)return o.IS_FIREFOX&&t.focus(),!0;const p=f.getBoundingClientRect().top;return a/n.calculateZoomLevel(u)>=p?d.insertAfter(h):d.insertBefore(h),x(null),o.IS_FIREFOX&&o.$onUpdate(()=>{t.focus()}),!0}(r),o.COMMAND_PRIORITY_HIGH))},[l,t,u,x]),r.useEffect(()=>{if(o.IS_FIREFOX&&h)return o.mergeRegister(t.registerRootListener(e=>{function n(n){const r=n.relatedTarget;o.isHTMLElement(r)&&p(r)&&(e&&(e.focus({preventScroll:!0}),t.update(()=>{const t=o.$getSelection();null===t||t.dirty||(t.dirty=!0)})),n.stopImmediatePropagation())}if(e)return e.addEventListener("blur",n,!0),()=>e.removeEventListener("blur",n,!0)}),t.registerCommand(o.BLUR_COMMAND,()=>{const e=t.getRootElement(),n=o.getActiveElementDeep(o.getRootOwnerDocument(e));return!!(e&&o.isHTMLElement(n)&&p(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,p]),/*#__PURE__*/i.createPortal(/*#__PURE__*/s.jsxs(s.Fragment,{children:[/*#__PURE__*/s.jsx("div",{draggable:!0,onDragStart:function(e){const n=e.dataTransfer;if(!n||!E)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,E);let r="";if(t.update(()=>{const t=o.$getNearestNodeFromDOMNode(E);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}),d]}),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,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)};
@@ -6,4 +6,4 @@
6
6
  *
7
7
  */
8
8
 
9
- import{useLexicalComposerContext as t}from"@lexical/react/LexicalComposerContext";import{eventFiles as e}from"@lexical/rich-text";import{calculateZoomLevel as n}from"@lexical/utils";import{getParentElement as r,mergeRegister as o,DRAGOVER_COMMAND as i,COMMAND_PRIORITY_LOW as s,DROP_COMMAND as l,COMMAND_PRIORITY_HIGH as a,IS_FIREFOX as c,BLUR_COMMAND as u,getActiveElementDeep as m,getRootOwnerDocument as h,isHTMLElement as g,$getSelection as f,getComposedEventTarget as p,$getNodeByKey as d,$getNearestNodeFromDOMNode as y,$onUpdate as _,getActiveElement as x,$getRoot as b}from"lexical";import{useRef as v,useState as T,useCallback as B,useEffect as C}from"react";import{createPortal as R}from"react-dom";import{jsxs as w,Fragment as D,jsx as E}from"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 S{_left;_top;_right;_bottom;constructor(t,e,n,r){const[o,i]=e<=r?[e,r]:[r,e],[s,l]=t<=n?[t,n]:[n,t];this._top=o,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:r}){return t===this._top&&n===this._bottom&&e===this._left&&r===this._right}contains(t){if(t instanceof L){const{x:e,y:n}=t,r=n<this._top,o=n>this._bottom,i=e<this._left,s=e>this._right;return{reason:{isOnBottomSide:o,isOnLeftSide:i,isOnRightSide:s,isOnTopSide:r},result:!(r||o||i||s)}}{const{top:e,left:n,bottom:r,right:o}=t;return e>=this._top&&e<=this._bottom&&r>=this._top&&r<=this._bottom&&n>=this._left&&n<=this._right&&o>=this._left&&o<=this._right}}intersectsWith(t){const{left:e,top:n,width:r,height:o}=t,{left:i,top:s,width:l,height:a}=this;return(e+r>=i+l?e+r:i+l)-(e<=i?e:i)<=r+l&&(n+o>=s+a?n+o:s+a)-(n<=s?n:s)<=o+a}generateNewRect({left:t=this.left,top:e=this.top,right:n=this.right,bottom:r=this.bottom}){return new S(t,e,n,r)}static fromLTRB(t,e,n,r){return new S(t,e,n,r)}static fromLWTH(t,e,n,r){return new S(t,n,t+e,n+r)}static fromPoints(t,e){const{y:n,x:r}=t,{y:o,x:i}=e;return S.fromLTRB(r,n,i,o)}static fromDOM(t){const{top:e,width:n,left:r,height:o}=t.getBoundingClientRect();return S.fromLWTH(r,n,e,o)}}const M="application/x-lexical-drag-block";let O=1/0;function K(t){const e=(t,e)=>t?parseFloat(window.getComputedStyle(t)[e]):0,{marginTop:n,marginBottom:r}=window.getComputedStyle(t),o=e(t.previousElementSibling,"marginBottom"),i=e(t.nextElementSibling,"marginTop"),s=Math.max(parseFloat(n),o);return{marginBottom:Math.max(parseFloat(r),i),marginTop:s}}function Y(t,e,r,o=!1){const i=t.getBoundingClientRect(),s=function(t){return t.read("latest",()=>b().getChildrenKeys())}(e);let l=null;return e.read("latest",()=>{if(o){const[t,o]=[e.getElementByKey(s[0]),e.getElementByKey(s[s.length-1])],[i,a]=[null!=t?t.getBoundingClientRect():void 0,null!=o?o.getBoundingClientRect():void 0];if(i&&a){const e=n(t),s=n(o);if(r.y/e<i.top?l=t:r.y/s>a.bottom&&(l=o),l)return}}let t=0===(a=s.length)?1/0:O>=0&&O<a?O:Math.floor(a/2);var a;let c=0;for(;t>=0&&t<s.length;){const o=s[t],a=e.getElementByKey(o);if(null===a)break;const u=n(a),m=new L(r.x/u,r.y/u),h=S.fromDOM(a),{marginTop:g,marginBottom:f}=K(a),p=h.generateNewRect({bottom:h.bottom+f,left:i.left,right:i.right,top:h.top-g}),{result:d,reason:{isOnTopSide:y,isOnBottomSide:_}}=p.contains(m);if(d){l=a,O=t;break}0===c&&(c=y?-1:_?1:1/0),t+=c}}),l}function H(t,b,L,S,O,H,N,k,q){const F=r(b),I=v(!1),[W,X]=T(null),P=B(t=>{X(t),q&&q(t)},[q]);return C(()=>{function e(e){const n=p(e);if(!g(n))return void P(null);if(k(n))return;const r=Y(b,t,e);P(r)}function n(){P(null)}return null!=F&&(F.addEventListener("mousemove",e),F.addEventListener("mouseleave",n)),()=>{null!=F&&(F.removeEventListener("mousemove",e),F.removeEventListener("mouseleave",n))}},[F,b,t,k,P]),C(()=>{const e=n(t.getRootElement(),!0);L.current&&function(t,e,n,r){if(!t)return void(e.style.display="none");const o=t.getBoundingClientRect(),i=window.getComputedStyle(t),s=e.getBoundingClientRect(),l=n.getBoundingClientRect();let a=parseInt(i.lineHeight,10);isNaN(a)&&(a=o.bottom-o.top);const c=(o.top+(a-(s.height||a))/2-l.top+n.scrollTop)/r;e.style.display="flex",e.style.opacity="1",e.style.transform=`translate(4px, ${c}px)`}(W,L.current,b,e)},[t,b,W,L]),C(()=>{function r(r){if(!I.current)return!1;const[o]=e(r);if(o)return!1;const i=r.pageY,s=p(r);if(!g(s))return!1;const l=Y(b,t,r,!0),a=S.current;return null!==l&&null!==a&&(function(t,e,n,r){const{top:o,height:i}=e.getBoundingClientRect(),{top:s,width:l}=r.getBoundingClientRect(),{marginTop:a,marginBottom:c}=K(e);let u=o;n>=o?u+=i+c/2:u-=a/2;const m=u-s-2+r.scrollTop;t.style.transform=`translate(24px, ${m}px)`,t.style.width=l-48+"px",t.style.opacity=".4"}(a,l,i/n(s),b),r.preventDefault(),!0)}return o(t.registerCommand(i,t=>r(t),s),t.registerCommand(l,r=>function(r){if(!I.current)return!1;const[o]=e(r);if(o)return!1;const{dataTransfer:i,pageY:s}=r,l=p(r),a=null!=i?i.getData(M):"",u=d(a);if(!u)return!1;if(!g(l))return!1;const m=Y(b,t,r,!0);if(!m)return!1;const h=y(m);if(!h)return!1;if(h===u)return c&&t.focus(),!0;const f=m.getBoundingClientRect().top;return s/n(l)>=f?h.insertAfter(u):h.insertBefore(u),P(null),c&&_(()=>{t.focus()}),!0}(r),a))},[b,t,S,P]),C(()=>{if(c&&O)return o(t.registerRootListener(e=>{function n(n){const r=n.relatedTarget;g(r)&&k(r)&&(e&&(e.focus({preventScroll:!0}),t.update(()=>{const t=f();null===t||t.dirty||(t.dirty=!0)})),n.stopImmediatePropagation())}if(e)return e.addEventListener("blur",n,!0),()=>e.removeEventListener("blur",n,!0)}),t.registerCommand(u,()=>{const e=t.getRootElement(),n=m(h(e));return!!(e&&g(n)&&k(n))&&(e.focus({preventScroll:!0}),t.update(()=>{const t=f();null===t||t.dirty||(t.dirty=!0)}),!0)},a))},[t,O,k]),/*#__PURE__*/R(/*#__PURE__*/w(D,{children:[/*#__PURE__*/E("div",{draggable:!0,onDragStart:function(e){const n=e.dataTransfer;if(!n||!W)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,W);let r="";if(t.update(()=>{const t=y(W);t&&(r=t.getKey())}),I.current=!0,n.setData(M,r),c){const e=t.getRootElement();null!==e&&x(e)!==e&&(e.focus({preventScroll:!0}),t.update(()=>{const t=f();null===t||t.dirty||(t.dirty=!0)}))}},onDragEnd:function(){var e;I.current=!1,(e=S.current)&&(e.style.opacity="0",e.style.transform="translate(-10000px, -10000px)"),c&&t.focus()},children:O&&H}),N]}),b)}function N({anchorElem:e=document.body,menuRef:n,targetLineRef:r,menuComponent:o,targetLineComponent:i,isOnMenu:s,onElementChanged:l}){const[a]=t();return H(a,e,n,r,a._editable,o,i,s,l)}export{N as DraggableBlockPlugin_EXPERIMENTAL};
9
+ import{useLexicalComposerContext as t}from"@lexical/react/LexicalComposerContext";import{eventFiles as e}from"@lexical/rich-text";import{calculateZoomLevel as n}from"@lexical/utils";import{getParentElement as o,registerEventListeners as r,mergeRegister as i,DRAGOVER_COMMAND as s,COMMAND_PRIORITY_LOW as l,DROP_COMMAND as a,COMMAND_PRIORITY_HIGH as c,IS_FIREFOX as u,registerEventListener as h,BLUR_COMMAND as g,getActiveElementDeep as m,getRootOwnerDocument as f,isHTMLElement as p,$getSelection as d,getComposedEventTarget as y,$getNodeByKey as _,$getNearestNodeFromDOMNode as x,$onUpdate as b,getActiveElement as T,$getRoot as B}from"lexical";import{useRef as C,useState as R,useCallback as w,useEffect as D}from"react";import{createPortal as S}from"react-dom";import{jsxs as v,Fragment as M,jsx as E}from"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 O{_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 O(t,e,n,o)}static fromLTRB(t,e,n,o){return new O(t,e,n,o)}static fromLWTH(t,e,n,o){return new O(t,n,t+e,n+o)}static fromPoints(t,e){const{y:n,x:o}=t,{y:r,x:i}=e;return O.fromLTRB(o,n,i,r)}static fromDOM(t){const{top:e,width:n,left:o,height:r}=t.getBoundingClientRect();return O.fromLWTH(o,n,e,r)}}const K="application/x-lexical-drag-block";let Y=1/0;function H(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 N(t,e,o,r=!1){const i=t.getBoundingClientRect(),s=function(t){return t.read("latest",()=>B().getChildrenKeys())}(e);let l=null;return e.read("latest",()=>{if(r){const[t,r]=[e.getElementByKey(s[0]),e.getElementByKey(s[s.length-1])],[i,a]=[null!=t?t.getBoundingClientRect():void 0,null!=r?r.getBoundingClientRect():void 0];if(i&&a){const e=n(t),s=n(r);if(o.y/e<i.top?l=t:o.y/s>a.bottom&&(l=r),l)return}}let t=0===(a=s.length)?1/0:Y>=0&&Y<a?Y:Math.floor(a/2);var a;let c=0;for(;t>=0&&t<s.length;){const r=s[t],a=e.getElementByKey(r);if(null===a)break;const u=n(a),h=new L(o.x/u,o.y/u),g=O.fromDOM(a),{marginTop:m,marginBottom:f}=H(a),p=g.generateNewRect({bottom:g.bottom+f,left:i.left,right:i.right,top:g.top-m}),{result:d,reason:{isOnTopSide:y,isOnBottomSide:_}}=p.contains(h);if(d){l=a,Y=t;break}0===c&&(c=y?-1:_?1:1/0),t+=c}}),l}function k(t,B,L,O,Y,k,q,F,I){const W=o(B),X=C(!1),[P,$]=R(null),j=w(t=>{$(t),I&&I(t)},[I]);return D(()=>{if(null!=W)return r(W,{mouseleave:function(){j(null)},mousemove:function(e){const n=y(e);if(!p(n))return void j(null);if(F(n))return;const o=N(B,t,e);j(o)}})},[W,B,t,F,j]),D(()=>{const e=n(t.getRootElement(),!0);L.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)`}(P,L.current,B,e)},[t,B,P,L]),D(()=>{function o(o){if(!X.current)return!1;const[r]=e(o);if(r)return!1;const i=o.pageY,s=y(o);if(!p(s))return!1;const l=N(B,t,o,!0),a=O.current;return null!==l&&null!==a&&(function(t,e,n,o){const{top:r,height:i}=e.getBoundingClientRect(),{top:s,width:l}=o.getBoundingClientRect(),{marginTop:a,marginBottom:c}=H(e);let u=r;n>=r?u+=i+c/2:u-=a/2;const h=u-s-2+o.scrollTop;t.style.transform=`translate(24px, ${h}px)`,t.style.width=l-48+"px",t.style.opacity=".4"}(a,l,i/n(s),B),o.preventDefault(),!0)}return i(t.registerCommand(s,t=>o(t),l),t.registerCommand(a,o=>function(o){if(!X.current)return!1;const[r]=e(o);if(r)return!1;const{dataTransfer:i,pageY:s}=o,l=y(o),a=null!=i?i.getData(K):"",c=_(a);if(!c)return!1;if(!p(l))return!1;const h=N(B,t,o,!0);if(!h)return!1;const g=x(h);if(!g)return!1;if(g===c)return u&&t.focus(),!0;const m=h.getBoundingClientRect().top;return s/n(l)>=m?g.insertAfter(c):g.insertBefore(c),j(null),u&&b(()=>{t.focus()}),!0}(o),c))},[B,t,O,j]),D(()=>{if(u&&Y)return i(t.registerRootListener(e=>{if(e)return h(e,"blur",function(n){const o=n.relatedTarget;p(o)&&F(o)&&(e&&(e.focus({preventScroll:!0}),t.update(()=>{const t=d();null===t||t.dirty||(t.dirty=!0)})),n.stopImmediatePropagation())},!0)}),t.registerCommand(g,()=>{const e=t.getRootElement(),n=m(f(e));return!!(e&&p(n)&&F(n))&&(e.focus({preventScroll:!0}),t.update(()=>{const t=d();null===t||t.dirty||(t.dirty=!0)}),!0)},c))},[t,Y,F]),/*#__PURE__*/S(/*#__PURE__*/v(M,{children:[/*#__PURE__*/E("div",{draggable:!0,onDragStart:function(e){const n=e.dataTransfer;if(!n||!P)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,P);let o="";if(t.update(()=>{const t=x(P);t&&(o=t.getKey())}),X.current=!0,n.setData(K,o),u){const e=t.getRootElement();null!==e&&T(e)!==e&&(e.focus({preventScroll:!0}),t.update(()=>{const t=d();null===t||t.dirty||(t.dirty=!0)}))}},onDragEnd:function(){var e;X.current=!1,(e=O.current)&&(e.style.opacity="0",e.style.transform="translate(-10000px, -10000px)"),u&&t.focus()},children:Y&&k}),q]}),B)}function q({anchorElem:e=document.body,menuRef:n,targetLineRef:o,menuComponent:r,targetLineComponent:i,isOnMenu:s,onElementChanged:l}){const[a]=t();return k(a,e,n,o,a._editable,r,i,s,l)}export{q as DraggableBlockPlugin_EXPERIMENTAL};
@@ -218,8 +218,7 @@ const NodeContextMenuPlugin = /*#__PURE__*/react.forwardRef(({
218
218
  }
219
219
  return editor.registerRootListener(rootElement => {
220
220
  if (rootElement !== null) {
221
- rootElement.addEventListener('contextmenu', onContextMenu);
222
- return () => rootElement.removeEventListener('contextmenu', onContextMenu);
221
+ return lexical.registerEventListener(rootElement, 'contextmenu', onContextMenu);
223
222
  }
224
223
  });
225
224
  }, [items, itemClassName, separatorClassName, refs, editor]);
@@ -8,7 +8,7 @@
8
8
 
9
9
  import { useFloating, autoUpdate, offset, flip, shift, useRole, useDismiss, useListNavigation, useTypeahead, useInteractions, FloatingPortal, FloatingOverlay, FloatingFocusManager } from '@floating-ui/react';
10
10
  import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
11
- import { $getNearestNodeFromDOMNode, $getRoot } from 'lexical';
11
+ import { registerEventListener, $getNearestNodeFromDOMNode, $getRoot } from 'lexical';
12
12
  import { forwardRef, useState, useRef, useEffect, createElement } from 'react';
13
13
  import { jsx, jsxs } from 'react/jsx-runtime';
14
14
 
@@ -216,8 +216,7 @@ const NodeContextMenuPlugin = /*#__PURE__*/forwardRef(({
216
216
  }
217
217
  return editor.registerRootListener(rootElement => {
218
218
  if (rootElement !== null) {
219
- rootElement.addEventListener('contextmenu', onContextMenu);
220
- return () => rootElement.removeEventListener('contextmenu', onContextMenu);
219
+ return registerEventListener(rootElement, 'contextmenu', onContextMenu);
221
220
  }
222
221
  });
223
222
  }, [items, itemClassName, separatorClassName, refs, editor]);
@@ -6,4 +6,4 @@
6
6
  *
7
7
  */
8
8
 
9
- "use strict";var e=require("@floating-ui/react"),t=require("@lexical/react/LexicalComposerContext"),s=require("lexical"),n=require("react"),i=require("react/jsx-runtime");class a{key;ref;constructor(e){this.key=e,this.ref={current:null},this.setRefElement=this.setRefElement.bind(this)}setRefElement(e){this.ref={current:e}}}const o=/*#__PURE__*/n.forwardRef(({className:e,disabled:t,...s},n)=>/*#__PURE__*/i.jsx("hr",{className:e})),r=/*#__PURE__*/n.forwardRef(({className:e,label:t,disabled:s,icon:n,...a},o)=>/*#__PURE__*/i.jsxs("button",{...a,className:e,ref:o,role:"menuitem",disabled:s,children:[n,t]})),l=/*#__PURE__*/n.forwardRef(({items:a,className:l,itemClassName:c,separatorClassName:u},d)=>{const[m]=t.useLexicalComposerContext(),[p,h]=n.useState(null),[f,x]=n.useState(!1),g=n.useRef([]),y=n.useRef([]),{refs:N,floatingStyles:b,context:k}=e.useFloating({middleware:[e.offset({alignmentAxis:4,mainAxis:5}),e.flip({fallbackPlacements:["left-start"]}),e.shift({padding:10})],onOpenChange:x,open:f,placement:"right-start",strategy:"fixed",whileElementsMounted:e.autoUpdate}),w=e.useRole(k,{role:"menu"}),$=e.useDismiss(k),C=e.useListNavigation(k,{activeIndex:p,listRef:g,onNavigate:h}),R=e.useTypeahead(k,{activeIndex:p,enabled:f,listRef:y,onMatch:h}),{getFloatingProps:O,getItemProps:v}=e.useInteractions([w,$,C,R]),[S,E]=n.useState([]);return n.useEffect(()=>{function e(e){e.preventDefault(),N.setPositionReference({getBoundingClientRect:()=>({bottom:e.clientY,height:0,left:e.clientX,right:e.clientX,top:e.clientY,width:0,x:e.clientX,y:e.clientY})});let t=[];a&&m.read(()=>{const n=s.$getNearestNodeFromDOMNode(e.target)??s.$getRoot();n&&(t=a.filter(e=>!e.$showOn||e.$showOn(n)))});const n=t.map((e,t)=>"separator"===e.type?{className:u,key:e.key+"-"+t,type:e.type}:{className:c,disabled:e.disabled,icon:e.icon,key:e.key,label:e.title,onClick:()=>m.update(()=>e.$onSelect()),title:e.title,type:e.type});y.current=n.map(e=>e.key),E(n),x(!0)}return m.registerRootListener(t=>{if(null!==t)return t.addEventListener("contextmenu",e),()=>t.removeEventListener("contextmenu",e)})},[a,c,u,N,m]),/*#__PURE__*/i.jsx(e.FloatingPortal,{children:f&&/*#__PURE__*/i.jsx(e.FloatingOverlay,{lockScroll:!0,children:/*#__PURE__*/i.jsx(e.FloatingFocusManager,{context:k,initialFocus:N.floating,children:/*#__PURE__*/i.jsx("div",{className:l,ref:N.setFloating,style:b,...O(),children:S.map((e,t)=>"item"===e.type?/*#__PURE__*/n.createElement(r,{...v({...e,onClick(){e.onClick(),x(!1)},onMouseUp(){e.onClick(),x(!1)},ref(e){g.current[t]=e},tabIndex:p===t?0:-1}),key:e.key}):"separator"===e.type?/*#__PURE__*/n.createElement(o,{...v({...e,ref(e){g.current[t]=e},tabIndex:p===t?0:-1}),key:e.key}):void 0)})})})})});exports.NodeContextMenuOption=class extends a{type;title;icon;disabled;$onSelect;$showOn;constructor(e,t){super(e),this.type="item",this.title=e,this.disabled=t.disabled??!1,this.icon=t.icon??null,this.$onSelect=t.$onSelect,t.$showOn&&(this.$showOn=t.$showOn)}},exports.NodeContextMenuPlugin=l,exports.NodeContextMenuSeparator=class extends a{type;$showOn;constructor(e){super("_separator"),this.type="separator",e&&e.$showOn&&(this.$showOn=e.$showOn)}};
9
+ "use strict";var e=require("@floating-ui/react"),t=require("@lexical/react/LexicalComposerContext"),s=require("lexical"),n=require("react"),i=require("react/jsx-runtime");class a{key;ref;constructor(e){this.key=e,this.ref={current:null},this.setRefElement=this.setRefElement.bind(this)}setRefElement(e){this.ref={current:e}}}const o=/*#__PURE__*/n.forwardRef(({className:e,disabled:t,...s},n)=>/*#__PURE__*/i.jsx("hr",{className:e})),r=/*#__PURE__*/n.forwardRef(({className:e,label:t,disabled:s,icon:n,...a},o)=>/*#__PURE__*/i.jsxs("button",{...a,className:e,ref:o,role:"menuitem",disabled:s,children:[n,t]})),l=/*#__PURE__*/n.forwardRef(({items:a,className:l,itemClassName:c,separatorClassName:u},d)=>{const[p]=t.useLexicalComposerContext(),[h,f]=n.useState(null),[m,x]=n.useState(!1),g=n.useRef([]),y=n.useRef([]),{refs:N,floatingStyles:b,context:k}=e.useFloating({middleware:[e.offset({alignmentAxis:4,mainAxis:5}),e.flip({fallbackPlacements:["left-start"]}),e.shift({padding:10})],onOpenChange:x,open:m,placement:"right-start",strategy:"fixed",whileElementsMounted:e.autoUpdate}),w=e.useRole(k,{role:"menu"}),$=e.useDismiss(k),C=e.useListNavigation(k,{activeIndex:h,listRef:g,onNavigate:f}),R=e.useTypeahead(k,{activeIndex:h,enabled:m,listRef:y,onMatch:f}),{getFloatingProps:O,getItemProps:v}=e.useInteractions([w,$,C,R]),[S,F]=n.useState([]);return n.useEffect(()=>{function e(e){e.preventDefault(),N.setPositionReference({getBoundingClientRect:()=>({bottom:e.clientY,height:0,left:e.clientX,right:e.clientX,top:e.clientY,width:0,x:e.clientX,y:e.clientY})});let t=[];a&&p.read(()=>{const n=s.$getNearestNodeFromDOMNode(e.target)??s.$getRoot();n&&(t=a.filter(e=>!e.$showOn||e.$showOn(n)))});const n=t.map((e,t)=>"separator"===e.type?{className:u,key:e.key+"-"+t,type:e.type}:{className:c,disabled:e.disabled,icon:e.icon,key:e.key,label:e.title,onClick:()=>p.update(()=>e.$onSelect()),title:e.title,type:e.type});y.current=n.map(e=>e.key),F(n),x(!0)}return p.registerRootListener(t=>{if(null!==t)return s.registerEventListener(t,"contextmenu",e)})},[a,c,u,N,p]),/*#__PURE__*/i.jsx(e.FloatingPortal,{children:m&&/*#__PURE__*/i.jsx(e.FloatingOverlay,{lockScroll:!0,children:/*#__PURE__*/i.jsx(e.FloatingFocusManager,{context:k,initialFocus:N.floating,children:/*#__PURE__*/i.jsx("div",{className:l,ref:N.setFloating,style:b,...O(),children:S.map((e,t)=>"item"===e.type?/*#__PURE__*/n.createElement(r,{...v({...e,onClick(){e.onClick(),x(!1)},onMouseUp(){e.onClick(),x(!1)},ref(e){g.current[t]=e},tabIndex:h===t?0:-1}),key:e.key}):"separator"===e.type?/*#__PURE__*/n.createElement(o,{...v({...e,ref(e){g.current[t]=e},tabIndex:h===t?0:-1}),key:e.key}):void 0)})})})})});exports.NodeContextMenuOption=class extends a{type;title;icon;disabled;$onSelect;$showOn;constructor(e,t){super(e),this.type="item",this.title=e,this.disabled=t.disabled??!1,this.icon=t.icon??null,this.$onSelect=t.$onSelect,t.$showOn&&(this.$showOn=t.$showOn)}},exports.NodeContextMenuPlugin=l,exports.NodeContextMenuSeparator=class extends a{type;$showOn;constructor(e){super("_separator"),this.type="separator",e&&e.$showOn&&(this.$showOn=e.$showOn)}};
@@ -6,4 +6,4 @@
6
6
  *
7
7
  */
8
8
 
9
- import{useFloating as e,autoUpdate as t,offset as n,flip as s,shift as i,useRole as l,useDismiss as o,useListNavigation as r,useTypeahead as a,useInteractions as c,FloatingPortal as m,FloatingOverlay as d,FloatingFocusManager as h}from"@floating-ui/react";import{useLexicalComposerContext as p}from"@lexical/react/LexicalComposerContext";import{$getNearestNodeFromDOMNode as u,$getRoot as f}from"lexical";import{forwardRef as y,useState as x,useRef as g,useEffect as b,createElement as k}from"react";import{jsx as $,jsxs as w}from"react/jsx-runtime";class N{key;ref;constructor(e){this.key=e,this.ref={current:null},this.setRefElement=this.setRefElement.bind(this)}setRefElement(e){this.ref={current:e}}}class O extends N{type;title;icon;disabled;$onSelect;$showOn;constructor(e,t){super(e),this.type="item",this.title=e,this.disabled=t.disabled??!1,this.icon=t.icon??null,this.$onSelect=t.$onSelect,t.$showOn&&(this.$showOn=t.$showOn)}}class C extends N{type;$showOn;constructor(e){super("_separator"),this.type="separator",e&&e.$showOn&&(this.$showOn=e.$showOn)}}const v=/*#__PURE__*/y(({className:e,disabled:t,...n},s)=>/*#__PURE__*/$("hr",{className:e})),R=/*#__PURE__*/y(({className:e,label:t,disabled:n,icon:s,...i},l)=>/*#__PURE__*/w("button",{...i,className:e,ref:l,role:"menuitem",disabled:n,children:[s,t]})),E=/*#__PURE__*/y(({items:y,className:w,itemClassName:N,separatorClassName:O},C)=>{const[E]=p(),[S,I]=x(null),[L,P]=x(!1),F=g([]),M=g([]),{refs:X,floatingStyles:Y,context:A}=e({middleware:[n({alignmentAxis:4,mainAxis:5}),s({fallbackPlacements:["left-start"]}),i({padding:10})],onOpenChange:P,open:L,placement:"right-start",strategy:"fixed",whileElementsMounted:t}),j=l(A,{role:"menu"}),B=o(A),D=r(A,{activeIndex:S,listRef:F,onNavigate:I}),U=a(A,{activeIndex:S,enabled:L,listRef:M,onMatch:I}),{getFloatingProps:_,getItemProps:q}=c([j,B,D,U]),[z,G]=x([]);return b(()=>{function e(e){e.preventDefault(),X.setPositionReference({getBoundingClientRect:()=>({bottom:e.clientY,height:0,left:e.clientX,right:e.clientX,top:e.clientY,width:0,x:e.clientX,y:e.clientY})});let t=[];y&&E.read(()=>{const n=u(e.target)??f();n&&(t=y.filter(e=>!e.$showOn||e.$showOn(n)))});const n=t.map((e,t)=>"separator"===e.type?{className:O,key:e.key+"-"+t,type:e.type}:{className:N,disabled:e.disabled,icon:e.icon,key:e.key,label:e.title,onClick:()=>E.update(()=>e.$onSelect()),title:e.title,type:e.type});M.current=n.map(e=>e.key),G(n),P(!0)}return E.registerRootListener(t=>{if(null!==t)return t.addEventListener("contextmenu",e),()=>t.removeEventListener("contextmenu",e)})},[y,N,O,X,E]),/*#__PURE__*/$(m,{children:L&&/*#__PURE__*/$(d,{lockScroll:!0,children:/*#__PURE__*/$(h,{context:A,initialFocus:X.floating,children:/*#__PURE__*/$("div",{className:w,ref:X.setFloating,style:Y,..._(),children:z.map((e,t)=>"item"===e.type?/*#__PURE__*/k(R,{...q({...e,onClick(){e.onClick(),P(!1)},onMouseUp(){e.onClick(),P(!1)},ref(e){F.current[t]=e},tabIndex:S===t?0:-1}),key:e.key}):"separator"===e.type?/*#__PURE__*/k(v,{...q({...e,ref(e){F.current[t]=e},tabIndex:S===t?0:-1}),key:e.key}):void 0)})})})})});export{O as NodeContextMenuOption,E as NodeContextMenuPlugin,C as NodeContextMenuSeparator};
9
+ import{useFloating as e,autoUpdate as t,offset as n,flip as s,shift as i,useRole as l,useDismiss as o,useListNavigation as r,useTypeahead as a,useInteractions as c,FloatingPortal as m,FloatingOverlay as d,FloatingFocusManager as h}from"@floating-ui/react";import{useLexicalComposerContext as p}from"@lexical/react/LexicalComposerContext";import{registerEventListener as f,$getNearestNodeFromDOMNode as u,$getRoot as y}from"lexical";import{forwardRef as g,useState as x,useRef as b,useEffect as k,createElement as $}from"react";import{jsx as w,jsxs as N}from"react/jsx-runtime";class O{key;ref;constructor(e){this.key=e,this.ref={current:null},this.setRefElement=this.setRefElement.bind(this)}setRefElement(e){this.ref={current:e}}}class C extends O{type;title;icon;disabled;$onSelect;$showOn;constructor(e,t){super(e),this.type="item",this.title=e,this.disabled=t.disabled??!1,this.icon=t.icon??null,this.$onSelect=t.$onSelect,t.$showOn&&(this.$showOn=t.$showOn)}}class R extends O{type;$showOn;constructor(e){super("_separator"),this.type="separator",e&&e.$showOn&&(this.$showOn=e.$showOn)}}const v=/*#__PURE__*/g(({className:e,disabled:t,...n},s)=>/*#__PURE__*/w("hr",{className:e})),S=/*#__PURE__*/g(({className:e,label:t,disabled:n,icon:s,...i},l)=>/*#__PURE__*/N("button",{...i,className:e,ref:l,role:"menuitem",disabled:n,children:[s,t]})),I=/*#__PURE__*/g(({items:g,className:N,itemClassName:O,separatorClassName:C},R)=>{const[I]=p(),[E,P]=x(null),[F,M]=x(!1),X=b([]),Y=b([]),{refs:A,floatingStyles:L,context:j}=e({middleware:[n({alignmentAxis:4,mainAxis:5}),s({fallbackPlacements:["left-start"]}),i({padding:10})],onOpenChange:M,open:F,placement:"right-start",strategy:"fixed",whileElementsMounted:t}),B=l(j,{role:"menu"}),D=o(j),U=r(j,{activeIndex:E,listRef:X,onNavigate:P}),_=a(j,{activeIndex:E,enabled:F,listRef:Y,onMatch:P}),{getFloatingProps:q,getItemProps:z}=c([B,D,U,_]),[G,H]=x([]);return k(()=>{function e(e){e.preventDefault(),A.setPositionReference({getBoundingClientRect:()=>({bottom:e.clientY,height:0,left:e.clientX,right:e.clientX,top:e.clientY,width:0,x:e.clientX,y:e.clientY})});let t=[];g&&I.read(()=>{const n=u(e.target)??y();n&&(t=g.filter(e=>!e.$showOn||e.$showOn(n)))});const n=t.map((e,t)=>"separator"===e.type?{className:C,key:e.key+"-"+t,type:e.type}:{className:O,disabled:e.disabled,icon:e.icon,key:e.key,label:e.title,onClick:()=>I.update(()=>e.$onSelect()),title:e.title,type:e.type});Y.current=n.map(e=>e.key),H(n),M(!0)}return I.registerRootListener(t=>{if(null!==t)return f(t,"contextmenu",e)})},[g,O,C,A,I]),/*#__PURE__*/w(m,{children:F&&/*#__PURE__*/w(d,{lockScroll:!0,children:/*#__PURE__*/w(h,{context:j,initialFocus:A.floating,children:/*#__PURE__*/w("div",{className:N,ref:A.setFloating,style:L,...q(),children:G.map((e,t)=>"item"===e.type?/*#__PURE__*/$(S,{...z({...e,onClick(){e.onClick(),M(!1)},onMouseUp(){e.onClick(),M(!1)},ref(e){X.current[t]=e},tabIndex:E===t?0:-1}),key:e.key}):"separator"===e.type?/*#__PURE__*/$(v,{...z({...e,ref(e){X.current[t]=e},tabIndex:E===t?0:-1}),key:e.key}):void 0)})})})})});export{C as NodeContextMenuOption,I as NodeContextMenuPlugin,R as NodeContextMenuSeparator};
@@ -54,8 +54,7 @@ function NodeEventPlugin({
54
54
  };
55
55
  return editor.registerRootListener(rootElement => {
56
56
  if (rootElement) {
57
- rootElement.addEventListener(eventType, onEvent, isCaptured);
58
- return () => rootElement.removeEventListener(eventType, onEvent, isCaptured);
57
+ return lexical.registerEventListener(rootElement, eventType, onEvent, isCaptured);
59
58
  }
60
59
  });
61
60
  // We intentionally don't respect changes to eventType.
@@ -7,7 +7,7 @@
7
7
  */
8
8
 
9
9
  import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
10
- import { $getNearestNodeFromDOMNode, $findMatchingParent } from 'lexical';
10
+ import { registerEventListener, $getNearestNodeFromDOMNode, $findMatchingParent } from 'lexical';
11
11
  import { useRef, useEffect } from 'react';
12
12
 
13
13
  /**
@@ -52,8 +52,7 @@ function NodeEventPlugin({
52
52
  };
53
53
  return editor.registerRootListener(rootElement => {
54
54
  if (rootElement) {
55
- rootElement.addEventListener(eventType, onEvent, isCaptured);
56
- return () => rootElement.removeEventListener(eventType, onEvent, isCaptured);
55
+ return registerEventListener(rootElement, eventType, onEvent, isCaptured);
57
56
  }
58
57
  });
59
58
  // We intentionally don't respect changes to eventType.
@@ -6,4 +6,4 @@
6
6
  *
7
7
  */
8
8
 
9
- "use strict";var e=require("@lexical/react/LexicalComposerContext"),t=require("lexical"),n=require("react");const r=new Set(["mouseenter","mouseleave"]);exports.NodeEventPlugin=function({nodeType:o,eventType:s,eventListener:i}){const[u]=e.useLexicalComposerContext(),c=n.useRef(i);return c.current=i,n.useEffect(()=>{const e=r.has(s),n=n=>{u.update(()=>{const r=t.$getNearestNodeFromDOMNode(n.target);if(null!==r){const s=e?r instanceof o?r:null:t.$findMatchingParent(r,e=>e instanceof o);if(null!==s)return void c.current(n,u,s.getKey())}})};return u.registerRootListener(t=>{if(t)return t.addEventListener(s,n,e),()=>t.removeEventListener(s,n,e)})},[u,o]),null};
9
+ "use strict";var e=require("@lexical/react/LexicalComposerContext"),t=require("lexical"),n=require("react");const r=new Set(["mouseenter","mouseleave"]);exports.NodeEventPlugin=function({nodeType:o,eventType:s,eventListener:i}){const[u]=e.useLexicalComposerContext(),c=n.useRef(i);return c.current=i,n.useEffect(()=>{const e=r.has(s),n=n=>{u.update(()=>{const r=t.$getNearestNodeFromDOMNode(n.target);if(null!==r){const s=e?r instanceof o?r:null:t.$findMatchingParent(r,e=>e instanceof o);if(null!==s)return void c.current(n,u,s.getKey())}})};return u.registerRootListener(r=>{if(r)return t.registerEventListener(r,s,n,e)})},[u,o]),null};
@@ -6,4 +6,4 @@
6
6
  *
7
7
  */
8
8
 
9
- import{useLexicalComposerContext as e}from"@lexical/react/LexicalComposerContext";import{$getNearestNodeFromDOMNode as t,$findMatchingParent as n}from"lexical";import{useRef as r,useEffect as o}from"react";const i=new Set(["mouseenter","mouseleave"]);function s({nodeType:s,eventType:c,eventListener:l}){const[u]=e(),a=r(l);return a.current=l,o(()=>{const e=i.has(c),r=r=>{u.update(()=>{const o=t(r.target);if(null!==o){const t=e?o instanceof s?o:null:n(o,e=>e instanceof s);if(null!==t)return void a.current(r,u,t.getKey())}})};return u.registerRootListener(t=>{if(t)return t.addEventListener(c,r,e),()=>t.removeEventListener(c,r,e)})},[u,s]),null}export{s as NodeEventPlugin};
9
+ import{useLexicalComposerContext as e}from"@lexical/react/LexicalComposerContext";import{registerEventListener as t,$getNearestNodeFromDOMNode as n,$findMatchingParent as r}from"lexical";import{useRef as o,useEffect as i}from"react";const c=new Set(["mouseenter","mouseleave"]);function l({nodeType:l,eventType:s,eventListener:u}){const[a]=e(),f=o(u);return f.current=u,i(()=>{const e=c.has(s),o=t=>{a.update(()=>{const o=n(t.target);if(null!==o){const n=e?o instanceof l?o:null:r(o,e=>e instanceof l);if(null!==n)return void f.current(t,a,n.getKey())}})};return a.registerRootListener(n=>{if(n)return t(n,s,o,e)})},[a,l]),null}export{l as NodeEventPlugin};