@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.
- package/dist/LexicalClearEditorPlugin.dev.js +1 -1
- package/dist/LexicalClearEditorPlugin.dev.mjs +1 -1
- package/dist/LexicalCollaborationPlugin.dev.js +4 -6
- package/dist/LexicalCollaborationPlugin.dev.mjs +5 -7
- package/dist/LexicalCollaborationPlugin.prod.js +1 -1
- package/dist/LexicalCollaborationPlugin.prod.mjs +1 -1
- package/dist/LexicalComposer.dev.js +1 -1
- package/dist/LexicalComposer.dev.mjs +1 -1
- package/dist/LexicalContentEditable.dev.js +1 -1
- package/dist/LexicalContentEditable.dev.mjs +1 -1
- package/dist/LexicalDraggableBlockPlugin.dev.js +5 -10
- package/dist/LexicalDraggableBlockPlugin.dev.mjs +6 -11
- package/dist/LexicalDraggableBlockPlugin.prod.js +1 -1
- package/dist/LexicalDraggableBlockPlugin.prod.mjs +1 -1
- package/dist/LexicalNodeContextMenuPlugin.dev.js +1 -2
- package/dist/LexicalNodeContextMenuPlugin.dev.mjs +2 -3
- package/dist/LexicalNodeContextMenuPlugin.prod.js +1 -1
- package/dist/LexicalNodeContextMenuPlugin.prod.mjs +1 -1
- package/dist/LexicalNodeEventPlugin.dev.js +1 -2
- package/dist/LexicalNodeEventPlugin.dev.mjs +2 -3
- package/dist/LexicalNodeEventPlugin.prod.js +1 -1
- package/dist/LexicalNodeEventPlugin.prod.mjs +1 -1
- package/dist/LexicalNodeMenuPlugin.dev.js +33 -67
- package/dist/LexicalNodeMenuPlugin.dev.mjs +12 -46
- package/dist/LexicalNodeMenuPlugin.prod.js +1 -1
- package/dist/LexicalNodeMenuPlugin.prod.mjs +1 -1
- package/dist/LexicalOnChangePlugin.dev.js +1 -1
- package/dist/LexicalOnChangePlugin.dev.mjs +1 -1
- package/dist/LexicalPlainTextPlugin.dev.js +1 -1
- package/dist/LexicalPlainTextPlugin.dev.mjs +1 -1
- package/dist/LexicalRichTextPlugin.dev.js +1 -1
- package/dist/LexicalRichTextPlugin.dev.mjs +1 -1
- package/dist/LexicalTypeaheadMenuPlugin.dev.js +33 -67
- package/dist/LexicalTypeaheadMenuPlugin.dev.mjs +12 -46
- package/dist/LexicalTypeaheadMenuPlugin.prod.js +1 -1
- package/dist/LexicalTypeaheadMenuPlugin.prod.mjs +1 -1
- package/dist/useLexicalAriaLiveRegion.d.ts +13 -0
- package/dist/useLexicalAriaLiveRegion.dev.js +38 -0
- package/dist/useLexicalAriaLiveRegion.dev.mjs +36 -0
- package/dist/useLexicalAriaLiveRegion.js +11 -0
- package/dist/{shared/reactPatches.d.ts → useLexicalAriaLiveRegion.js.flow} +3 -1
- package/dist/useLexicalAriaLiveRegion.mjs +12 -0
- package/dist/useLexicalAriaLiveRegion.node.mjs +10 -0
- package/dist/useLexicalAriaLiveRegion.prod.js +9 -0
- package/dist/useLexicalAriaLiveRegion.prod.mjs +9 -0
- package/dist/useLexicalEditable.dev.js +1 -1
- package/dist/useLexicalEditable.dev.mjs +1 -1
- package/dist/useLexicalFocusManagerRef.d.ts +26 -0
- package/dist/useLexicalFocusManagerRef.dev.js +59 -0
- package/dist/useLexicalFocusManagerRef.dev.mjs +57 -0
- package/dist/useLexicalFocusManagerRef.js +11 -0
- package/dist/useLexicalFocusManagerRef.js.flow +16 -0
- package/dist/useLexicalFocusManagerRef.mjs +12 -0
- package/dist/useLexicalFocusManagerRef.node.mjs +10 -0
- package/dist/useLexicalFocusManagerRef.prod.js +9 -0
- package/dist/useLexicalFocusManagerRef.prod.mjs +9 -0
- package/dist/useLexicalFocusTrapRef.d.ts +33 -0
- package/dist/useLexicalFocusTrapRef.dev.js +72 -0
- package/dist/useLexicalFocusTrapRef.dev.mjs +70 -0
- package/dist/useLexicalFocusTrapRef.js +11 -0
- package/dist/useLexicalFocusTrapRef.js.flow +16 -0
- package/dist/useLexicalFocusTrapRef.mjs +12 -0
- package/dist/useLexicalFocusTrapRef.node.mjs +10 -0
- package/dist/useLexicalFocusTrapRef.prod.js +9 -0
- package/dist/useLexicalFocusTrapRef.prod.mjs +9 -0
- package/dist/useLexicalIsTextContentEmpty.dev.js +1 -1
- package/dist/useLexicalIsTextContentEmpty.dev.mjs +1 -1
- package/dist/useLexicalRovingTabIndexRef.d.ts +26 -0
- package/dist/useLexicalRovingTabIndexRef.dev.js +61 -0
- package/dist/useLexicalRovingTabIndexRef.dev.mjs +59 -0
- package/dist/useLexicalRovingTabIndexRef.js +11 -0
- package/dist/useLexicalRovingTabIndexRef.js.flow +19 -0
- package/dist/useLexicalRovingTabIndexRef.mjs +12 -0
- package/dist/useLexicalRovingTabIndexRef.node.mjs +10 -0
- package/dist/useLexicalRovingTabIndexRef.prod.js +9 -0
- package/dist/useLexicalRovingTabIndexRef.prod.mjs +9 -0
- package/dist/useLexicalSubscription.dev.js +1 -1
- package/dist/useLexicalSubscription.dev.mjs +1 -1
- package/package.json +166 -21
- package/src/LexicalDraggableBlockPlugin.tsx +7 -11
- package/src/LexicalNodeContextMenuPlugin.tsx +7 -4
- package/src/LexicalNodeEventPlugin.ts +11 -4
- package/src/LexicalNodeMenuPlugin.tsx +1 -2
- package/src/LexicalTypeaheadMenuPlugin.tsx +1 -2
- package/src/shared/LexicalMenu.tsx +18 -21
- package/src/shared/useLayoutEffect.ts +1 -1
- package/src/shared/useYjsCollaboration.tsx +5 -7
- package/src/useLexicalAriaLiveRegion.ts +31 -0
- package/src/useLexicalFocusManagerRef.ts +56 -0
- package/src/useLexicalFocusTrapRef.ts +73 -0
- package/src/useLexicalRovingTabIndexRef.ts +60 -0
- 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 >=
|
|
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 >=
|
|
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
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
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
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
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"),
|
|
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
|
|
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 >=
|
|
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 >=
|
|
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 >=
|
|
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 >=
|
|
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
|
-
|
|
405
|
-
|
|
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
|
-
|
|
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
|
|
403
|
-
|
|
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
|
|
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),
|
|
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
|
|
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
|
-
|
|
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
|
|
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[
|
|
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{
|
|
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
|
-
|
|
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
|
|
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(
|
|
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{
|
|
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};
|