import { buildCsvDownloadItem, buildPngDownloadItem, type DownloadItem, } from '../actions/download' import { tableDataToCsv } from './helpers' import type { TableColumn, TableWidgetData } from './types' /** * Download menu items for the Table widget. Always includes a CSV item * that pulls the latest data from the widget store via `getData()` (so * locked / sorted / filtered state is honored); headers come from * `column.label`, cells from `row[column.id]`. When `getCaptureEl` is * supplied, prepends a PNG item that rasterises the captured element via * `html2canvas`. */ export function createTableDownloadConfig(opts: { filename: string getData: () => TableWidgetData columns: readonly TableColumn[] getCaptureEl?: () => HTMLElement | null pngPixelRatio?: number pngBackgroundColor?: string | null }): DownloadItem[] { const items: DownloadItem[] = [] if (opts.getCaptureEl) { items.push( buildPngDownloadItem({ filename: opts.filename, getCaptureEl: opts.getCaptureEl, pixelRatio: opts.pngPixelRatio, backgroundColor: opts.pngBackgroundColor, }), ) } items.push( buildCsvDownloadItem({ filename: opts.filename, getCsv: () => tableDataToCsv(opts.getData(), opts.columns), }), ) return items }