UNPKG

@visactor/vtable

Version:

canvas table width high performance

81 lines (75 loc) 5 kB
import { isBoolean, isNumber, isObject, isValid } from "@visactor/vutils"; export function setRadioState(col, row, field, type, indexInCell, state) { const recordIndex = state.table.getRecordShowIndexByCell(col, row); if (recordIndex >= 0) { const dataIndex = state.table.dataSource.getIndexKey(recordIndex); "column" === type ? isNumber(indexInCell) ? (state.radioState[field] = {}, state.radioState[field][dataIndex] = indexInCell) : state.radioState[field] = dataIndex : (state.radioState[field] || (state.radioState[field] = {}), isNumber(indexInCell) ? state.radioState[field][dataIndex] = indexInCell : state.radioState[field][dataIndex] = !0); } } export function getCellRadioState(col, row, table) { var _a; const define = table.getBodyColumnDefine(col, row), field = null == define ? void 0 : define.field, cellType = table.getCellType(col, row); if (isValid(field) && "radio" === cellType) { const dataIndex = table.dataSource.getIndexKey(table.getRecordShowIndexByCell(col, row)), columnState = null === (_a = table.stateManager.radioState) || void 0 === _a ? void 0 : _a[field]; if (isNumber(columnState)) { if (columnState === dataIndex) return !0; } else if (isObject(columnState)) { const cellState = columnState[dataIndex]; if (isNumber(cellState)) return cellState; } } return !1; } export function syncRadioState(col, row, field, type, indexInCell, isChecked, state) { var _a, _b, _c, _d, _e; const recordIndex = state.table.getRecordShowIndexByCell(col, row); if (recordIndex >= 0) { const dataIndex = state.table.dataSource.getIndexKey(recordIndex); if ("column" === type) { if (!isValid(state.radioState[field]) && isChecked) return isNumber(indexInCell) ? (state.radioState[field] = {}, state.radioState[field][dataIndex] = indexInCell) : state.radioState[field] = dataIndex, !0; if (isNumber(state.radioState[field]) && !isNumber(indexInCell)) return state.radioState[field] === dataIndex; if (isNumber(state.radioState[field]) && isNumber(indexInCell)) return !1; if (isObject(state.radioState[field]) && !isNumber(indexInCell)) return !1; if (isObject(state.radioState[field]) && isNumber(indexInCell)) return state.radioState[field][dataIndex] === indexInCell; } else if ("cell" === type) { if (!isValid(state.radioState[field]) && isChecked) return state.radioState[field] = {}, isNumber(indexInCell) ? state.radioState[field][dataIndex] = indexInCell : state.radioState[field][dataIndex] = !0, !0; if (!isValid(null === (_a = state.radioState[field]) || void 0 === _a ? void 0 : _a[dataIndex]) && isChecked) return isNumber(indexInCell) ? state.radioState[field][dataIndex] = indexInCell : state.radioState[field][dataIndex] = !0, !0; if (isBoolean(null === (_b = state.radioState[field]) || void 0 === _b ? void 0 : _b[dataIndex]) && !isNumber(indexInCell)) return state.radioState[field][dataIndex]; if (isBoolean(null === (_c = state.radioState[field]) || void 0 === _c ? void 0 : _c[dataIndex]) && isNumber(indexInCell)) return !1; if (isNumber(null === (_d = state.radioState[field]) || void 0 === _d ? void 0 : _d[dataIndex]) && !isNumber(indexInCell)) return !1; if (isNumber(null === (_e = state.radioState[field]) || void 0 === _e ? void 0 : _e[dataIndex]) && isNumber(indexInCell)) return state.radioState[field][dataIndex] === indexInCell; } } return isChecked; } export function setCellRadioState(col, row, index, table) { const cellGoup = table.scenegraph.getCell(col, row); if (cellGoup) if (isNumber(index)) { const radio = cellGoup.getChildAt(index); null == radio || radio._handlePointerUp(); } else { const radio = cellGoup.getChildByName("radio"); null == radio || radio._handlePointerUp(); } } export function changeRadioOrder(sourceIndex, targetIndex, state) { const {radioState: radioState, table: table} = state; if (table.internalProps.transpose ? (sourceIndex = table.getRecordShowIndexByCell(sourceIndex, 0), targetIndex = table.getRecordShowIndexByCell(targetIndex, 0)) : (sourceIndex = table.getRecordShowIndexByCell(0, sourceIndex), targetIndex = table.getRecordShowIndexByCell(0, targetIndex)), sourceIndex > targetIndex) { const sourceRecord = radioState[sourceIndex]; for (let i = sourceIndex; i > targetIndex; i--) radioState[i] = radioState[i - 1]; radioState[targetIndex] = sourceRecord; } else if (sourceIndex < targetIndex) { const sourceRecord = radioState[sourceIndex]; for (let i = sourceIndex; i < targetIndex; i++) radioState[i] = radioState[i + 1]; radioState[targetIndex] = sourceRecord; } } //# sourceMappingURL=radio.js.map