"use client"; import { useTranslation } from "react-i18next"; import type { ReactNode, Ref } from "react"; import { useResponsiveBreakpoint } from "@/hooks/use-responsive-breakpoint"; import { canResizeColumnBoundary, MIN_MARKDOWN_COLUMN_WIDTH } from "@/lib/markdown/table-resize"; import { useMarkdownTableResize } from "./use-markdown-table-resize"; type ResizableMarkdownTableProps = { children?: ReactNode; renderWrapper?: (props: { children: ReactNode; className: string; elementRef: Ref; }) => ReactNode; }; export function ResizableMarkdownTable({ children, renderWrapper }: ResizableMarkdownTableProps) { const { t } = useTranslation(); const { isFinePointer, isMobile } = useResponsiveBreakpoint(); const resizeEnabled = isFinePointer && !isMobile; const resize = useMarkdownTableResize(resizeEnabled); const displayedWidths = resize.columnWidths ?? resize.geometry?.columnWidths; const tableContent = ( <> {resize.columnWidths && ( {resize.columnWidths.map((width, index) => ( ))} )} {children}
{resizeEnabled && resize.geometry?.boundaries.map((left, index) => { const leftWidth = displayedWidths?.[index]; const rightWidth = displayedWidths?.[index + 1]; if ( !displayedWidths || leftWidth === undefined || rightWidth === undefined || !canResizeColumnBoundary(displayedWidths, index) ) { return null; } return (