UNPKG

@lexical/react

Version:

This package provides Lexical components and hooks for React applications.

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