@lexical/react
Version:
This package provides Lexical components and hooks for React applications.
10 lines (8 loc) • 890 B
JavaScript
/**
* 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.
*
*/
;var e=require("@lexical/react/LexicalComposerContext"),t=require("@lexical/utils"),n=require("lexical"),r=require("react");const o=new Set(["mouseenter","mouseleave"]);exports.NodeEventPlugin=function({nodeType:i,eventType:s,eventListener:u}){const[c]=e.useLexicalComposerContext(),l=r.useRef(u);return l.current=u,r.useEffect((()=>{const e=o.has(s),r=r=>{c.update((()=>{const o=n.$getNearestNodeFromDOMNode(r.target);if(null!==o){const n=e?o instanceof i?o:null:t.$findMatchingParent(o,(e=>e instanceof i));if(null!==n)return void l.current(r,c,n.getKey())}}))};return c.registerRootListener(((t,n)=>{t&&t.addEventListener(s,r,e),n&&n.removeEventListener(s,r,e)}))}),[c,i]),null};