UNPKG

@antv/s2

Version:

effective spreadsheet render core lib

92 lines 4.13 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DataCellClick = void 0; const constant_1 = require("../../../common/constant"); const select_event_1 = require("../../../utils/interaction/select-event"); const is_mobile_1 = require("../../../utils/is-mobile"); const base_event_1 = require("../../base-event"); class DataCellClick extends base_event_1.BaseEvent { bindEvents() { this.bindDataCellClick(); } bindDataCellClick() { this.spreadsheet.on(constant_1.S2Event.DATA_CELL_CLICK, (event) => { var _a, _b; event.stopPropagation(); const { interaction } = this.spreadsheet; interaction.clearHoverTimer(); if (interaction.hasIntercepts([constant_1.InterceptType.CLICK])) { return; } if (this.isLinkFieldText(event.target)) { this.emitLinkFieldClickEvent(event); return; } const cell = this.spreadsheet.getCell(event.target); const meta = cell.getMeta(); if (!meta) { return; } interaction.addIntercepts([constant_1.InterceptType.HOVER]); if (interaction.isSelectedCell(cell)) { // https://developer.mozilla.org/en-US/docs/Web/API/UIEvent/detail,使用 detail 属性来判断是否是双击,双击时不触发选择态 reset if (event.detail === 1 || ((_a = event.nativeEvent) === null || _a === void 0 ? void 0 : _a.detail) === 1 || ((_b = event.originalEvent) === null || _b === void 0 ? void 0 : _b.detail) === 1 || (0, is_mobile_1.isMobile)()) { interaction.reset(); // https://github.com/antvis/S2/issues/2447 interaction.emitSelectEvent({ event, targetCell: cell, interactionName: constant_1.InteractionName.DATA_CELL_CLICK, }); } return; } interaction.changeState({ cells: [(0, select_event_1.getCellMeta)(cell)], stateName: constant_1.InteractionStateName.SELECTED, onUpdateCells: select_event_1.afterSelectDataCells, }); interaction.emitSelectEvent({ event, targetCell: cell, interactionName: constant_1.InteractionName.DATA_CELL_CLICK, cells: [cell], }); this.showTooltip(event, meta); // 点击单元格,高亮对应的行头、列头 interaction.updateDataCellRelevantHeaderCells(constant_1.InteractionStateName.SELECTED, meta); this.spreadsheet.emit(constant_1.S2Event.DATA_CELL_CLICK_TRIGGERED_PRIVATE, cell); }); } showTooltip(event, meta) { const { data, isTotals = false, fieldValue, valueField } = meta; const onlyShowCellText = this.spreadsheet.isTableMode(); const cellData = onlyShowCellText ? Object.assign(Object.assign({}, data), { value: fieldValue, valueField }) : data; const cellInfos = [ cellData || Object.assign(Object.assign({}, meta.rowQuery), meta.colQuery), ]; const operator = this.getTooltipOperator(event); this.spreadsheet.showTooltipWithInfo(event, cellInfos, { isTotals, operator, hideSummary: true, onlyShowCellText, }); } emitLinkFieldClickEvent(event) { const { meta } = this.getCellAppendInfo(event.target); const { valueField: field, data: record } = meta; this.spreadsheet.emit(constant_1.S2Event.GLOBAL_LINK_FIELD_JUMP, { meta: meta, field, record: Object.assign({ rowIndex: meta === null || meta === void 0 ? void 0 : meta.rowIndex }, record), }); } } exports.DataCellClick = DataCellClick; //# sourceMappingURL=data-cell-click.js.map