import { getRowByCell } from './row'; import { ID, IStoreState, IColumn, IColumnWithCells } from '../../index.data'; export function getColumn(state: IStoreState, id: ID): IColumn { return state.columns.find(col => col.id + '' === id + '')!; } export function getColumnj(state: IStoreState, colId: ID): number { return state.columns.findIndex(col => col.id === colId || col.id + '' === colId + ''); } export function getColumnByIndex(state: IStoreState, index: number): IColumn { return state.columns.find(col => col.j === index)!; } export function getColumnWithCellsByIndex(state: IStoreState, j: number): IColumnWithCells { const column = state.columns[j]; const cells = state.rows .map(row => row.cellIds![j]) .map(cellId => (cellId ? state.cells[cellId] : null)); return Object.assign({}, column, { cells }); } export function getColumnByCell(state: IStoreState, cellId: ID) { const row = getRowByCell(state, cellId); const j = row.cellIds!.indexOf(cellId); return state.columns[j]; }