import { IRowWithCell } from '../SpreadSheetProvider/index.data'; import { IColumn, IRow, ICell, ID, ICellNN } from '../index.data'; import { dissoc, idMap } from 'valor-app-utils'; import * as R from 'rambda'; /** * 从输入的sheet, 提取符合store标准的rows, 用于initStore * @param sheet * @startI 新生的行, i 的开始点 * */ export function normalizeRows( sheet: { rows: IRowWithCell[]; columns: IColumn[] }, startI = 0, ): IRow[] { return sheet.rows .map((row, i) => { return { ...row, i: i + startI, cellIds: row.cells!.map(it => (it ? it.id : null)) }; }) .map(row => dissoc(row, 'cells')); } // 从输入的sheet, 提取符合store标准的cells, 用于initStore // 同时将 type export function normalizeCellIdMap( sheet: { rows: IRowWithCell[]; columns: IColumn[] }, startI = 0, ): Record { const cellss = sheet.rows.map((row, i) => row .cells!.map((cell, j) => cell ? { ...cell!, i: i + startI, j, rowId: row.id, type: cell.type || sheet.columns[j].type } : null, ) .filter(Boolean), ); return idMap(R.flatten(cellss)) as any; }