import { StatusPriority } from "@tooee/layout"; import { Table, formatTableCell } from "@tooee/renderers"; import type { TableRow } from "@tooee/renderers"; import { useMemo } from "react"; import type { ReactNode } from "react"; import { useContentDocument } from "../../hooks/use-content-document.js"; import { getTextContent } from "../../types.js"; import type { TableContent } from "../../types.js"; import { ViewScreen } from "../view-screen.js"; import type { SubviewProps } from "./types.js"; interface TableSubviewProps extends SubviewProps { content: TableContent; } export const TableSubview = function TableSubview({ content, decorations, actions, ...screen }: TableSubviewProps): ReactNode { const textContent = useMemo(() => getTextContent(content), [content]); const { columns, rows } = content; const adapter = useMemo( () => ({ getText: (row: TableRow) => columns.map((column) => formatTableCell(row[column.key])).join("\t"), }), [columns] ); const { document, showLineNumbers, statusItems } = useContentDocument( rows, adapter, { actions, content, decorations, textContent }, { multiSelect: true, statusItems: [ { label: "Format:", priority: StatusPriority.content, value: content.format }, { label: "Rows:", priority: StatusPriority.content, value: String(rows.length) }, { label: "Cols:", priority: StatusPriority.content, value: String(columns.length) }, ], } ); return ( ); };