-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Node-aware Context Menu Items #5791
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
@@ -199,10 +203,32 @@ export default function ContextMenuPlugin(): JSX.Element { | |||
[editor], | |||
); | |||
|
|||
const onWillOpen = (event: MouseEvent) => { | |||
let newOptions = defaultOptions; | |||
editor.update(() => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should probably be a read that returns the node type, then call an update onClick
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$getNearestNodeFromDOMNode works only inside editor.update(), unsure on why this is the case.
@@ -97,6 +99,9 @@ export function LexicalContextMenuPlugin<TOption extends MenuOption>({ | |||
const handleContextMenu = useCallback( | |||
(event: MouseEvent) => { | |||
event.preventDefault(); | |||
if (onWillOpen) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we be strict with the check here, like for onOpen and onClose?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated
Expose a 'onWillOpen' method that passes the 'contextmenu' mouse event, so users can do their logic what items should end up in the context menu before it's rendered. Have added an example for 'Link node', that appends an item to 'Remove Link' when a link node is right-clicked. Also fixed wrong positioning of the context menu when the page is scrolled.