UNPKG

@lexical/react

Version:

This package provides Lexical components and hooks for React applications.

10 lines (8 loc) • 1.19 kB
/** * 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{signal as e}from"@lexical/extension";import{useLexicalComposerContext as r}from"@lexical/react/LexicalComposerContext";import{$isScrollableTablesActive as o,setScrollableTablesActive as t,TableNode as l,registerTablePlugin as a,registerTableSelectionObserver as s,registerTableCellUnmergeTransform as n,TableCellNode as i}from"@lexical/table";import{useEffect as c,useState as u}from"react";function m({hasCellMerge:e=!0,hasCellBackgroundColor:u=!0,hasTabHandler:m=!0,hasHorizontalScroll:f=!1,hasNestedTables:h=!1,hasFitNestedTables:g=!1}){const[p]=r();c(()=>{o(p)!==f&&(t(p,f),p.registerNodeTransform(l,()=>{})())},[p,f]);const x=d(h),C=d(g);return c(()=>a(p,{hasFitNestedTables:C,hasNestedTables:x}),[p,x,C]),c(()=>s(p,m),[p,m]),c(()=>{if(!e)return n(p)},[p,e]),c(()=>{if(!u)return p.registerNodeTransform(i,e=>{null!==e.getBackgroundColor()&&e.setBackgroundColor(null)})},[p,u,e]),null}function d(r){const[o]=u(()=>e(r));return o.peek()!==r&&(o.value=r),o}export{m as TablePlugin};