UNPKG

@visactor/vtable

Version:

canvas table width high performance

97 lines (88 loc) 5.86 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: !0 }), exports.changeRadioOrder = exports.setCellRadioState = exports.syncRadioState = exports.getCellRadioState = exports.setRadioState = void 0; const vutils_1 = require("@visactor/vutils"); 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 ? (0, vutils_1.isNumber)(indexInCell) ? (state.radioState[field] = {}, state.radioState[field][dataIndex] = indexInCell) : state.radioState[field] = dataIndex : (state.radioState[field] || (state.radioState[field] = {}), (0, vutils_1.isNumber)(indexInCell) ? state.radioState[field][dataIndex] = indexInCell : state.radioState[field][dataIndex] = !0); } } 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 ((0, vutils_1.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 ((0, vutils_1.isNumber)(columnState)) { if (columnState === dataIndex) return !0; } else if ((0, vutils_1.isObject)(columnState)) { const cellState = columnState[dataIndex]; if ((0, vutils_1.isNumber)(cellState)) return cellState; } } return !1; } 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 (!(0, vutils_1.isValid)(state.radioState[field]) && isChecked) return (0, vutils_1.isNumber)(indexInCell) ? (state.radioState[field] = {}, state.radioState[field][dataIndex] = indexInCell) : state.radioState[field] = dataIndex, !0; if ((0, vutils_1.isNumber)(state.radioState[field]) && !(0, vutils_1.isNumber)(indexInCell)) return state.radioState[field] === dataIndex; if ((0, vutils_1.isNumber)(state.radioState[field]) && (0, vutils_1.isNumber)(indexInCell)) return !1; if ((0, vutils_1.isObject)(state.radioState[field]) && !(0, vutils_1.isNumber)(indexInCell)) return !1; if ((0, vutils_1.isObject)(state.radioState[field]) && (0, vutils_1.isNumber)(indexInCell)) return state.radioState[field][dataIndex] === indexInCell; } else if ("cell" === type) { if (!(0, vutils_1.isValid)(state.radioState[field]) && isChecked) return state.radioState[field] = {}, (0, vutils_1.isNumber)(indexInCell) ? state.radioState[field][dataIndex] = indexInCell : state.radioState[field][dataIndex] = !0, !0; if (!(0, vutils_1.isValid)(null === (_a = state.radioState[field]) || void 0 === _a ? void 0 : _a[dataIndex]) && isChecked) return (0, vutils_1.isNumber)(indexInCell) ? state.radioState[field][dataIndex] = indexInCell : state.radioState[field][dataIndex] = !0, !0; if ((0, vutils_1.isBoolean)(null === (_b = state.radioState[field]) || void 0 === _b ? void 0 : _b[dataIndex]) && !(0, vutils_1.isNumber)(indexInCell)) return state.radioState[field][dataIndex]; if ((0, vutils_1.isBoolean)(null === (_c = state.radioState[field]) || void 0 === _c ? void 0 : _c[dataIndex]) && (0, vutils_1.isNumber)(indexInCell)) return !1; if ((0, vutils_1.isNumber)(null === (_d = state.radioState[field]) || void 0 === _d ? void 0 : _d[dataIndex]) && !(0, vutils_1.isNumber)(indexInCell)) return !1; if ((0, vutils_1.isNumber)(null === (_e = state.radioState[field]) || void 0 === _e ? void 0 : _e[dataIndex]) && (0, vutils_1.isNumber)(indexInCell)) return state.radioState[field][dataIndex] === indexInCell; } } return isChecked; } function setCellRadioState(col, row, index, table) { const cellGoup = table.scenegraph.getCell(col, row); if (cellGoup) if ((0, vutils_1.isNumber)(index)) { const radio = cellGoup.getChildAt(index); null == radio || radio._handlePointerUp(); } else { const radio = cellGoup.getChildByName("radio"); null == radio || radio._handlePointerUp(); } } 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; } } exports.setRadioState = setRadioState, exports.getCellRadioState = getCellRadioState, exports.syncRadioState = syncRadioState, exports.setCellRadioState = setCellRadioState, exports.changeRadioOrder = changeRadioOrder; //# sourceMappingURL=radio.js.map