UNPKG

@lexical/react

Version:

This package provides Lexical components and hooks for React applications.

10 lines (8 loc) 904 B
/** * Copyright (c) Meta Platforms, Inc. and affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * */ import{useLexicalComposerContext as e}from"@lexical/react/LexicalComposerContext";import{$findMatchingParent as t}from"@lexical/utils";import{$getNearestNodeFromDOMNode as n}from"lexical";import{useRef as r,useEffect as o}from"react";const i=new Set(["mouseenter","mouseleave"]);function l({nodeType:l,eventType:s,eventListener:c}){const[u]=e(),a=r(c);return a.current=c,o((()=>{const e=i.has(s),r=r=>{u.update((()=>{const o=n(r.target);if(null!==o){const n=e?o instanceof l?o:null:t(o,(e=>e instanceof l));if(null!==n)return void a.current(r,u,n.getKey())}}))};return u.registerRootListener(((t,n)=>{t&&t.addEventListener(s,r,e),n&&n.removeEventListener(s,r,e)}))}),[u,l]),null}export{l as NodeEventPlugin};