'use client'; import React from 'react'; import type { TTableCellElement } from '@udecode/plate-table'; import { cn, withProps, withRef } from '@udecode/cn'; import { BlockSelectionPlugin, useBlockSelected, } from '@udecode/plate-selection/react'; import { TablePlugin, TableRowPlugin, useTableCellElement, useTableCellElementResizable, } from '@udecode/plate-table/react'; import { PlateElement, useEditorPlugin, useElementSelector, usePluginOption, useReadOnly, } from '@udecode/plate/react'; import { cva } from 'class-variance-authority'; import { blockSelectionVariants } from './block-selection'; import { ResizeHandle } from './resizable'; export const TableCellElement = withRef< typeof PlateElement, { isHeader?: boolean; } >(({ children, className, isHeader, style, ...props }, ref) => { const { api } = useEditorPlugin(TablePlugin); const readOnly = useReadOnly(); const element = props.element as TTableCellElement; const rowId = useElementSelector(([node]) => node.id as string, [], { key: TableRowPlugin.key, }); const isSelectingRow = useBlockSelected(rowId); const isSelectionAreaVisible = usePluginOption( BlockSelectionPlugin, 'isSelectionAreaVisible', ); const { borders, colIndex, colSpan, minHeight, rowIndex, selected, width } = useTableCellElement(); const { bottomProps, hiddenLeft, leftProps, rightProps } = useTableCellElementResizable({ colIndex, colSpan, rowIndex, }); return (
{children}
{!isSelectionAreaVisible && (
{!readOnly && ( <> {!hiddenLeft && ( )}