UNPKG

@lexical/react

Version:

This package provides Lexical components and hooks for React applications.

10 lines (8 loc) • 853 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{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};