import { pType } from "../../../../../base/specs.js";
import { TableDesc } from "../../../../../../table-utils/table-desc.js";
export const clearCells = (params) => {
    return (state, dispatch) => {
        const table = state.doc.nodeAt(params.tablePos);
        const tableDesc = table && TableDesc.create(table)?.bind(params.tablePos);
        if (!tableDesc)
            return false;
        if (!dispatch)
            return true;
        const { tr } = state;
        const paragraph = pType(state.schema);
        const clear = (cells) => {
            for (const pos of cells) {
                if (pos.type !== 'real')
                    continue;
                tr.replaceWith(tr.mapping.map(pos.from + 1), tr.mapping.map(pos.to - 1), paragraph.create());
            }
        };
        if (params.rows) {
            for (const rowIdx of params.rows) {
                const cellsPos = tableDesc.getPosForRowCells(rowIdx);
                clear(cellsPos);
            }
        }
        if (params.cols) {
            for (const colIdx of params.cols) {
                const cellsPos = tableDesc.getPosForColumn(colIdx);
                clear(cellsPos);
            }
        }
        if (tr.docChanged)
            dispatch(tr);
        return true;
    };
};
//# sourceMappingURL=clear-cells.js.map
