UNPKG

@antv/s2

Version:

effective spreadsheet render core lib

285 lines (284 loc) 10.2 kB
import { type MergedCell } from '../cell'; import { CellType, InteractionStateName, InterceptType } from '../common/constant'; import type { BrushSelectionOptions, CellMeta, CellScrollToOptions, CellSelectedDetail, ChangeCellOptions, InteractionCellHighlightOptions, InteractionStateInfo, Intercept, MergedCellInfo, S2CellType, ScrollOffsetConfig, ViewMeta } from '../common/interface'; import type { Node } from '../facet/layout/node'; import type { SpreadSheet } from '../sheet-type'; import type { BaseEvent } from './base-event'; import { EventController } from './event-controller'; export declare class RootInteraction { spreadsheet: SpreadSheet; interactions: Map<string, BaseEvent>; intercepts: Set<Intercept>; /** * hover有 keep-hover 态,是个计时器,hover后 800毫秒还在当前 cell 的情况下,该 cell 进入 keep-hover 状态 * 在任何触发点击,或者点击空白区域时,说明已经不是 hover了,因此需要取消这个计时器。 */ private hoverTimer; private drawRafId; eventController: EventController; private defaultState; constructor(spreadsheet: SpreadSheet); /** * 销毁交互 * @example s2.interaction.destroy() */ destroy(): void; /** * 重置交互 * @example s2.interaction.reset() */ reset(): void; private onTriggerInteractionsResetEffect; /** * 设置交互状态 * @example s2.interaction.setState({ stateName: InteractionStateName.SELECTED, cells: [{ "id": "root[&]浙江省[&]舟山市", "colIndex": -1, "rowIndex": 3, "type": "rowCell" }] }) */ setState(interactionStateInfo: InteractionStateInfo): void; /** * 获取交互状态 * @example s2.interaction.getState() */ getState(): InteractionStateInfo; /** * 设置通过交互触发过更新的单元格 * @example s2.interaction.setInteractedCells(dataCell) */ setInteractedCells(cell: S2CellType): void; /** * 获取通过交互触发过更新的单元格 * @example s2.interaction.getInteractedCells() */ getInteractedCells(): S2CellType<ViewMeta>[]; /** * 重置交互状态 * @example s2.interaction.resetState() */ resetState(): void; /** * 获取当前交互状态名 * @example s2.interaction.getCurrentStateName() */ getCurrentStateName(): "selected" | "hover" | "allSelected" | "rowCellBrushSelected" | "colCellBrushSelected" | "dataCellBrushSelected" | "unselected" | "hoverFocus" | "highlight" | "searchResult" | "prepareSelect" | undefined; /** * 是否和当前状态名相同 * @example s2.interaction.isEqualStateName(InteractionStateName.SELECTED) */ isEqualStateName(stateName: `${InteractionStateName}`): boolean; private isStateOf; /** * 是否是选中状态 (含单选,多选,圈选,全选) * @example s2.interaction.isSelectedState() */ isSelectedState(): boolean; /** * 是否是刷选状态 * @example s2.interaction.isBrushSelectedState() */ isBrushSelectedState(): boolean; /** * 是否是全选状态 * @example s2.interaction.isAllSelectedState() */ isAllSelectedState(): boolean; /** * 是否是悬停聚焦状态 * @example s2.interaction.isHoverFocusState() */ isHoverFocusState(): boolean; /** * 是否是悬停状态 * @example s2.interaction.isHoverState() */ isHoverState(): boolean; /** * 是否是激活的单元格 * @example s2.interaction.isActiveCell(cell) */ isActiveCell(cell: S2CellType): boolean; shouldForbidHeaderCellSelected: (selectedCells: CellMeta[]) => boolean; /** * 是否是选中的单元格 * @example s2.interaction.isSelectedCell(cell) */ isSelectedCell(cell: S2CellType): boolean; /** * 获取当前 interaction 记录的 Cells 元信息列表,包括不在可视区域内的格子 * @example s2.interaction.getCells(CellType.DATA_CELL) */ getCells(cellType?: CellType[]): CellMeta[]; /** * 获取已激活单元格 (不含非可视区域) * @example s2.interaction.getActiveCells() */ getActiveCells(): S2CellType[]; getActiveDataCells(): S2CellType[]; getActiveRowCells(): S2CellType[]; getActiveColCells(): S2CellType[]; /** * 清除单元格交互样式 * @example s2.interaction.clearStyleIndependent() */ clearStyleIndependent(): void; /** * 获取未选中的单元格 (不含非可视区域) * @example s2.interaction.getUnSelectedDataCells() */ getUnSelectedDataCells(): import("../cell").DataCell[]; private scrollToCellByMeta; /** * 滚动至指定位置 * @example s2.interaction.scrollTo({ skipScrollEvent: false, offsetX: { value: 100, animate: true }, offsetY: { value: 100, animate: true }, }) */ scrollTo(offsetConfig: ScrollOffsetConfig): void; /** * 滚动至指定单元格节点 * @example s2.interaction.scrollToNode(rowNode, { animate: true, skipScrollEvent: true }) */ scrollToNode(meta: ViewMeta | Node, options?: CellScrollToOptions): void; /** * 滚动至指定单元格 * @example s2.interaction.scrollToNode(rowCell, { animate: true, skipScrollEvent: true }) */ scrollToCell(cell: S2CellType, options?: CellScrollToOptions): void; /** * 滚动至指定单元格 id 对应的位置 * @example s2.interaction.scrollToCellById('root[&]四川省[&]成都市', { animate: true, skipScrollEvent: true }) */ scrollToCellById(id: string, options?: CellScrollToOptions): void; /** * 滚动至顶部 * @example s2.interaction.scrollToTop({ animate: true, skipScrollEvent: true }) */ scrollToTop(options?: CellScrollToOptions): void; /** * 滚动至右边 * @example s2.interaction.scrollToRight({ animate: true, skipScrollEvent: true }) */ scrollToRight(options?: CellScrollToOptions): void; /** * 滚动至底部 * @example s2.interaction.scrollToBottom({ animate: true, skipScrollEvent: true }) */ scrollToBottom(options?: CellScrollToOptions): void; /** * 滚动至左边 * @example s2.interaction.scrollToLeft({ animate: true, skipScrollEvent: true }) */ scrollToLeft(options?: CellScrollToOptions): void; /** * 全选 * @example s2.interaction.selectAll() */ selectAll(): void; /** * 高亮指定单元格 (可视范围内) * @example s2.interaction.highlightCell(dataCell, options) */ highlightCell(cell: S2CellType, options?: CellScrollToOptions): void; /** * 选中指定单元格 (可视范围内) * @example s2.interaction.selectCell(dataCell, options) */ selectCell(cell: S2CellType, options?: CellScrollToOptions): void; /** * 改变指定单元格状态 (如: 选中/高亮/多选等) (可视范围内) * @example s2.interaction.changeCell({ cell: rowCell, stateName: InteractionStateName.SELECTED, isMultiSelection: false, scrollIntoView: false, animate: true, skipScrollEvent: true, }) */ changeCell(options?: ChangeCellOptions): true | undefined; /** * 高亮节点对应的单元格 * @example s2.interaction.highlightNodes([node]) */ highlightNodes: (nodes?: Node[], stateName?: `${InteractionStateName}`) => void; /** * 合并单元格 * @example s2.interaction.mergeCells() */ mergeCells: (cellsInfo?: MergedCellInfo[], hideData?: boolean) => void; /** * 取消合并单元格 * @example s2.interaction.unmergeCell(mergedCell) */ unmergeCell: (removedCell: MergedCell) => void; /** * 隐藏列头 * @example s2.interaction.hideColumns(['city']) */ hideColumns(hiddenColumnFields?: string[], forceRender?: boolean): Promise<void>; private getBrushSelectionInfo; private getDefaultInteractions; private registerInteractions; private registerEventController; draw(): void; clearState(): void; /** * 改变单元格交互状态后,进行更新和重新绘制 * @example s2.interaction.changeState({ cells: [{ id: 'city', colIndex: 1, rowIndex : 2, type: 'rowCell' }], stateName: InteractionStateName.SELECTED, force: false }) */ changeState(interactionStateInfo: InteractionStateInfo): void; /** * 更新所有数值单元格 * @example s2.interaction.updateAllDataCells() */ updateAllDataCells(): void; /** * 更新指定单元格 * @example s2.interaction.updateCells([rowCell, dataCell]) */ updateCells(cells?: S2CellType[]): void; /** * 添加交互拦截 * @example s2.interaction.addIntercepts([InterceptType.HOVER]) */ addIntercepts(interceptTypes?: `${InterceptType}`[]): void; /** * 是否有指定交互拦截 * @example s2.interaction.hasIntercepts([InterceptType.HOVER]) */ hasIntercepts(interceptTypes?: `${InterceptType}`[]): boolean; /** * 移除交互拦截 * @example s2.interaction.removeIntercepts([InterceptType.HOVER]) */ removeIntercepts(interceptTypes?: `${InterceptType}`[]): void; clearHoverTimer(): void; setHoverTimer(timer: number): void; getHoverTimer(): number | null; getSelectedCellHighlight(): InteractionCellHighlightOptions; getHoverAfterScroll(): boolean; getHoverHighlight(): InteractionCellHighlightOptions; getBrushSelection(): BrushSelectionOptions; updateDataCellRelevantHeaderCells(stateName: InteractionStateName, meta: ViewMeta): void; updateDataCellRelevantRowCells(stateName: InteractionStateName, meta: ViewMeta): void; updateDataCellRelevantColCells(stateName: InteractionStateName, meta: ViewMeta): void; emitSelectEvent(options: CellSelectedDetail & { cells?: S2CellType[]; }): void; }