UNPKG

@antv/s2

Version:

effective spreadsheet render core lib

53 lines 2.26 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.setState = exports.clearState = void 0; const lodash_1 = require("lodash"); const constant_1 = require("../../common/constant"); /** * @desc clear the interaction state information * @param spreadsheet sheet instance */ const clearState = (spreadsheet) => { var _a; const activeIcons = spreadsheet.store.get('visibleActionIcons'); const allInteractedCells = spreadsheet.interaction.getInteractedCells(); const cellMetas = spreadsheet.interaction.getState().cells; // 如果都处于初始化状态 不需要clear if ((0, lodash_1.isEmpty)(allInteractedCells) && (0, lodash_1.isEmpty)(cellMetas) && (0, lodash_1.isEmpty)(activeIcons)) { return false; } (0, lodash_1.forEach)(activeIcons, (icon) => { icon.toggleVisibility(false); }); spreadsheet.store.set('visibleActionIcons', []); (0, lodash_1.forEach)(allInteractedCells, (cell) => { cell.hideInteractionShape(); }); spreadsheet.interaction.resetState(); if ((_a = spreadsheet.options.interaction) === null || _a === void 0 ? void 0 : _a.selectedCellsSpotlight) { const unSelectedCells = spreadsheet.interaction.getUnSelectedDataCells() || []; (0, lodash_1.forEach)(unSelectedCells, (cell) => { cell.clearUnselectedState(); }); } return true; }; exports.clearState = clearState; /** * @desc set the interaction state information * @param spreadsheet sheet instance * @param interactionStateInfo */ const setState = (spreadsheet, interactionStateInfo) => { const stateName = interactionStateInfo === null || interactionStateInfo === void 0 ? void 0 : interactionStateInfo.stateName; if (!spreadsheet.interaction.isEqualStateName(stateName)) { // There can only be one state in the table. When the stateName is inconsistent with the state in the stateInfo, the previously stored state should be cleared. (0, exports.clearState)(spreadsheet); spreadsheet.hideTooltip(); spreadsheet.store.set(constant_1.INTERACTION_STATE_INFO_KEY, interactionStateInfo); } }; exports.setState = setState; //# sourceMappingURL=state-controller.js.map