+ "content": "'use client';\n\nimport React from 'react';\n\nimport type { TColumnElement } from '@udecode/plate-layout';\n\nimport { cn, useComposedRef, withRef } from '@udecode/cn';\nimport { PathApi } from '@udecode/plate';\nimport { useDraggable, useDropLine } from '@udecode/plate-dnd';\nimport { ResizableProvider } from '@udecode/plate-resizable';\nimport { BlockSelectionPlugin } from '@udecode/plate-selection/react';\nimport {\n PlateElement,\n usePluginOption,\n useReadOnly,\n withHOC,\n} from '@udecode/plate/react';\nimport { GripHorizontal } from 'lucide-react';\n\nimport { Button } from './button';\nimport {\n Tooltip,\n TooltipContent,\n TooltipPortal,\n TooltipProvider,\n TooltipTrigger,\n} from './tooltip';\n\nexport const ColumnElement = withHOC(\n ResizableProvider,\n withRef<typeof PlateElement>(({ children, className, ...props }, ref) => {\n const { width } = props.element as TColumnElement;\n const readOnly = useReadOnly();\n const isSelectionAreaVisible = usePluginOption(\n BlockSelectionPlugin,\n 'isSelectionAreaVisible'\n );\n\n const { isDragging, previewRef, handleRef } = useDraggable({\n element: props.element,\n orientation: 'horizontal',\n type: 'column',\n canDropNode: ({ dragEntry, dropEntry }) =>\n PathApi.equals(\n PathApi.parent(dragEntry[1]),\n PathApi.parent(dropEntry[1])\n ),\n });\n\n return (\n <div className=\"group/column relative\" style={{ width: width ?? '100%' }}>\n {!readOnly && !isSelectionAreaVisible && (\n <div\n ref={handleRef}\n className={cn(\n 'absolute top-2 left-1/2 z-50 -translate-x-1/2 -translate-y-1/2',\n 'pointer-events-auto flex items-center',\n 'opacity-0 transition-opacity group-hover/column:opacity-100'\n )}\n >\n <ColumnDragHandle />\n </div>\n )}\n\n <PlateElement\n ref={useComposedRef(ref, previewRef)}\n className={cn(\n className,\n 'h-full px-2 pt-2 group-first/column:pl-0 group-last/column:pr-0'\n )}\n {...props}\n >\n <div\n className={cn(\n 'relative h-full border border-transparent p-1.5',\n !readOnly && 'rounded-lg border-dashed border-border',\n isDragging && 'opacity-50'\n )}\n >\n {children}\n\n {!readOnly && !isSelectionAreaVisible && <DropLine />}\n </div>\n </PlateElement>\n </div>\n );\n })\n);\n\nconst ColumnDragHandle = React.memo(() => {\n return (\n <TooltipProvider>\n <Tooltip>\n <TooltipTrigger asChild>\n <Button size=\"none\" variant=\"ghost\" className=\"h-5 px-1\">\n <GripHorizontal\n className=\"size-4 text-muted-foreground\"\n onClick={(event) => {\n event.stopPropagation();\n event.preventDefault();\n }}\n />\n </Button>\n </TooltipTrigger>\n <TooltipPortal>\n <TooltipContent>Drag to move column</TooltipContent>\n </TooltipPortal>\n </Tooltip>\n </TooltipProvider>\n );\n});\n\nconst DropLine = React.forwardRef<\n HTMLDivElement,\n React.HTMLAttributes<HTMLDivElement>\n>(({ className, ...props }, ref) => {\n const { dropLine } = useDropLine({ orientation: 'horizontal' });\n\n if (!dropLine) return null;\n\n return (\n <div\n ref={ref}\n {...props}\n className={cn(\n 'slate-dropLine',\n 'absolute bg-brand/50',\n dropLine === 'left' &&\n 'inset-y-0 left-[-10.5px] w-1 group-first/column:-left-1',\n dropLine === 'right' &&\n 'inset-y-0 right-[-11px] w-1 group-last/column:-right-1',\n className\n )}\n />\n );\n});\n",
0 commit comments