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