'use client'; import React from 'react'; import type { TColumnElement } from '@udecode/plate-layout'; import { cn, useComposedRef, withRef } from '@udecode/cn'; import { PathApi } from '@udecode/plate'; import { useDraggable, useDropLine } from '@udecode/plate-dnd'; import { ResizableProvider } from '@udecode/plate-resizable'; import { BlockSelectionPlugin } from '@udecode/plate-selection/react'; import { PlateElement, usePluginOption, useReadOnly, withHOC, } from '@udecode/plate/react'; import { GripHorizontal } from 'lucide-react'; import { Button } from './button'; import { Tooltip, TooltipContent, TooltipPortal, TooltipProvider, TooltipTrigger, } from './tooltip'; export const ColumnElement = withHOC( ResizableProvider, withRef(({ children, className, ...props }, ref) => { const { width } = props.element as TColumnElement; const readOnly = useReadOnly(); const isSelectionAreaVisible = usePluginOption( BlockSelectionPlugin, 'isSelectionAreaVisible', ); const { isDragging, previewRef, handleRef } = useDraggable({ element: props.element, orientation: 'horizontal', type: 'column', canDropNode: ({ dragEntry, dropEntry }) => PathApi.equals( PathApi.parent(dragEntry[1]), PathApi.parent(dropEntry[1]), ), }); return (
{!readOnly && !isSelectionAreaVisible && (
)}
{children} {!readOnly && !isSelectionAreaVisible && }
); }), ); const ColumnDragHandle = React.memo(() => { return ( Drag to move column ); }); ColumnDragHandle.displayName = 'ColumnDragHandle'; const DropLine = React.forwardRef< HTMLDivElement, React.HTMLAttributes >(({ className, ...props }, ref) => { const { dropLine } = useDropLine({ orientation: 'horizontal' }); if (!dropLine) return null; return (
); }); DropLine.displayName = 'DropLine';