@lexical/react
Version:
This package provides Lexical components and hooks for React applications.
10 lines (8 loc) • 1.09 kB
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/extension"),r=require("@lexical/react/LexicalComposerContext"),l=require("@lexical/table"),s=require("react");exports.TablePlugin=function({hasCellMerge:a=!0,hasCellBackgroundColor:t=!0,hasTabHandler:o=!0,hasHorizontalScroll:i=!1,hasNestedTables:n=!1}){const[c]=r.useLexicalComposerContext();s.useEffect(()=>{l.$isScrollableTablesActive(c)!==i&&(l.setScrollableTablesActive(c,i),c.registerNodeTransform(l.TableNode,()=>{})())},[c,i]);const u=s.useMemo(()=>e.signal(!1),[]);return u.peek()!==n&&(u.value=n),s.useEffect(()=>l.registerTablePlugin(c,{hasNestedTables:u}),[c,u]),s.useEffect(()=>l.registerTableSelectionObserver(c,o),[c,o]),s.useEffect(()=>{if(!a)return l.registerTableCellUnmergeTransform(c)},[c,a]),s.useEffect(()=>{if(!t)return c.registerNodeTransform(l.TableCellNode,e=>{null!==e.getBackgroundColor()&&e.setBackgroundColor(null)})},[c,t,a]),null};