'use client'; import React from 'react'; import { cn, useComposedRef, withRef } from '@udecode/cn'; import { PathApi } from '@udecode/plate'; import { useDraggable, useDropLine } from '@udecode/plate-dnd'; import { BlockSelectionPlugin } from '@udecode/plate-selection/react'; import { PlateElement, useEditorRef, useElement, usePluginOption, useReadOnly, useSelected, } from '@udecode/plate/react'; import { GripVertical } from 'lucide-react'; import { Button } from './button'; export const TableRowElement = withRef( ({ children, className, ...props }, ref) => { const { element } = props; const readOnly = useReadOnly(); const selected = useSelected(); const editor = useEditorRef(); const isSelectionAreaVisible = usePluginOption( BlockSelectionPlugin, 'isSelectionAreaVisible', ); const hasControls = !readOnly && !isSelectionAreaVisible; const { isDragging, previewRef, handleRef } = useDraggable({ element, type: element.type, canDropNode: ({ dragEntry, dropEntry }) => PathApi.equals( PathApi.parent(dragEntry[1]), PathApi.parent(dropEntry[1]), ), onDropHandler: (_, { dragItem }) => { const dragElement = (dragItem as any).element; if (dragElement) { editor.tf.select(dragElement); } }, }); return ( {hasControls && ( )} {children} ); }, ); function RowDragHandle({ dragRef }: { dragRef: React.Ref }) { const editor = useEditorRef(); const element = useElement(); return ( ); } function DropLine() { const { dropLine } = useDropLine(); if (!dropLine) return null; return (
); }