// Rôle : fournit l'outil tableau avec cellules libres, formules simples et échange TSV. import { useMemo } from "react"; import { ModuleTextExchangeConfiguration } from "./ModuleConfiguration.jsx"; import { columnIndexToName, evaluateTable } from "./tableFormulaEngine.js"; import { TableGrid } from "./TableGrid.jsx"; import { TableToolbar } from "./TableToolbar.jsx"; import { DEFAULT_COLUMNS, DEFAULT_ROWS, cleanCells, cleanLabels, getRowHeaderWidth, getColumnWidths } from "./tableUtils.js"; import { useTableInteractions } from "./useTableInteractions.js"; export function TableModule({ toolboxId, moduleId, context, configurationTarget }) { const rawData = context.getModuleData(toolboxId, moduleId, { rows: DEFAULT_ROWS, columns: DEFAULT_COLUMNS, cells: {} }); const data = useMemo(() => context.normalizeTableData(rawData), [context, rawData]); const textContent = context.moduleText?.table || {}; const evaluatedCells = useMemo(() => evaluateTable(data.cells, data), [data]); const columnWidths = useMemo(() => getColumnWidths(data, evaluatedCells), [data, evaluatedCells]); const rowHeaderWidth = useMemo(() => getRowHeaderWidth(data), [data]); function save(nextData) { context.setModuleData(toolboxId, moduleId, nextData, "table"); } function resize(rows, columns) { save({ rows, columns, cells: cleanCells(data.cells, rows, columns), rowLabels: cleanLabels(data.rowLabels, rows, (rowIndex) => rowIndex + 1), columnLabels: cleanLabels(data.columnLabels, columns, columnIndexToName) }); } function setColumnLabel(columnIndex, value) { const nextLabels = { ...data.columnLabels }; const nextValue = String(value || "").slice(0, 80); if (nextValue.trim() && nextValue !== columnIndexToName(columnIndex)) { nextLabels[columnIndex] = nextValue; } else { delete nextLabels[columnIndex]; } save({ ...data, columnLabels: nextLabels }); } function setRowLabel(rowIndex, value) { const nextLabels = { ...data.rowLabels }; const nextValue = String(value || "").slice(0, 80); if (nextValue.trim() && nextValue !== String(rowIndex + 1)) { nextLabels[rowIndex] = nextValue; } else { delete nextLabels[rowIndex]; } save({ ...data, rowLabels: nextLabels }); } const tableInteractions = useTableInteractions({ data, context, textContent, evaluatedCells, save }); return (