diff --git a/packages/s2-core/__tests__/unit/interaction/root-spec.ts b/packages/s2-core/__tests__/unit/interaction/root-spec.ts index 1e16145102..8402192475 100644 --- a/packages/s2-core/__tests__/unit/interaction/root-spec.ts +++ b/packages/s2-core/__tests__/unit/interaction/root-spec.ts @@ -13,13 +13,13 @@ import { MergedCell, } from '@/index'; import { Store } from '@/common/store'; -import { mergeCells, unmergeCell } from '@/utils/interaction/merge-cells'; +import { mergeCell, unmergeCell } from '@/utils/interaction/merge-cell'; jest.mock('@/sheet-type'); jest.mock('@/interaction/event-controller'); -jest.mock('@/utils/interaction/merge-cells', () => { +jest.mock('@/utils/interaction/merge-cell', () => { return { - mergeCells: jest.fn(), + mergeCell: jest.fn(), unmergeCell: jest.fn(), }; }); @@ -100,7 +100,7 @@ describe('RootInteraction Tests', () => { test('should call merge cells', () => { rootInteraction.mergeCells(); - expect(mergeCells).toBeCalled(); + expect(mergeCell).toBeCalled(); }); test('should call cancel mergedCell', () => { diff --git a/packages/s2-core/__tests__/unit/utils/merge-cells.spec.ts b/packages/s2-core/__tests__/unit/utils/merge-cell.spec.ts similarity index 100% rename from packages/s2-core/__tests__/unit/utils/merge-cells.spec.ts rename to packages/s2-core/__tests__/unit/utils/merge-cell.spec.ts diff --git a/packages/s2-core/src/cell/merged-cell.ts b/packages/s2-core/src/cell/merged-cell.ts index e642315b92..50ca1354b9 100644 --- a/packages/s2-core/src/cell/merged-cell.ts +++ b/packages/s2-core/src/cell/merged-cell.ts @@ -2,7 +2,7 @@ import { isEmpty, isObject } from 'lodash'; import { CellTypes } from '../common/constant'; import { ViewMeta } from '../common/interface'; import { DataCell } from './data-cell'; -import { getPolygonPoints } from '@/utils/interaction/merge-cells'; +import { getPolygonPoints } from '@/utils/interaction/merge-cell'; import { SpreadSheet } from '@/sheet-type'; import { S2CellType } from '@/common/interface/interaction'; import { renderPolygon } from '@/utils/g-renders'; diff --git a/packages/s2-core/src/common/constant/interaction.ts b/packages/s2-core/src/common/constant/interaction.ts index 55ae2d35dc..7a08be243a 100644 --- a/packages/s2-core/src/common/constant/interaction.ts +++ b/packages/s2-core/src/common/constant/interaction.ts @@ -6,7 +6,7 @@ export enum InteractionName { HOVER = 'hover', BRUSH_SELECTION = 'brushSelection', COL_ROW_RESIZE = 'rowColResize', - COL_ROW_MULTI_SELECTION = 'colRowMultiSelection', + DATA_CELL_MULTI_SELECTION = 'dataCellMultiSelection', COL_ROW_SHIFT_MULTI_SELECTION = 'colRowShiftMultiSelection', } diff --git a/packages/s2-core/src/facet/base-facet.ts b/packages/s2-core/src/facet/base-facet.ts index 89d20b0ef0..3a0abb722e 100644 --- a/packages/s2-core/src/facet/base-facet.ts +++ b/packages/s2-core/src/facet/base-facet.ts @@ -59,7 +59,7 @@ import type { S2CellType, FrameConfig, } from '@/common/interface'; -import { updateMergedCells } from '@/utils/interaction/merge-cells'; +import { updateMergedCells } from '@/utils/interaction/merge-cell'; import { PanelIndexes, diffPanelIndexes } from '@/utils/indexes'; export abstract class BaseFacet { diff --git a/packages/s2-core/src/interaction/base-interaction/click/index.ts b/packages/s2-core/src/interaction/base-interaction/click/index.ts index f802f7181a..63cc849228 100644 --- a/packages/s2-core/src/interaction/base-interaction/click/index.ts +++ b/packages/s2-core/src/interaction/base-interaction/click/index.ts @@ -1,4 +1,4 @@ export { DataCellClick } from './data-cell-click'; -export { MergedCellsClick } from './merged-cells-click'; +export { MergedCellClick } from './merged-cell-click'; export { RowColumnClick } from './row-column-click'; export { RowTextClick } from './row-text-click'; diff --git a/packages/s2-core/src/interaction/base-interaction/click/merged-cells-click.ts b/packages/s2-core/src/interaction/base-interaction/click/merged-cell-click.ts similarity index 87% rename from packages/s2-core/src/interaction/base-interaction/click/merged-cells-click.ts rename to packages/s2-core/src/interaction/base-interaction/click/merged-cell-click.ts index 7e25bc4f66..eae4520b46 100644 --- a/packages/s2-core/src/interaction/base-interaction/click/merged-cells-click.ts +++ b/packages/s2-core/src/interaction/base-interaction/click/merged-cell-click.ts @@ -2,7 +2,7 @@ import { Event } from '@antv/g-canvas'; import { BaseEvent, BaseEventImplement } from '../../base-event'; import { InterceptType, S2Event } from '@/common/constant'; -export class MergedCellsClick extends BaseEvent implements BaseEventImplement { +export class MergedCellClick extends BaseEvent implements BaseEventImplement { public bindEvents() { this.bindDataCellClick(); } diff --git a/packages/s2-core/src/interaction/root.ts b/packages/s2-core/src/interaction/root.ts index bdb9312aed..4d656f07d0 100644 --- a/packages/s2-core/src/interaction/root.ts +++ b/packages/s2-core/src/interaction/root.ts @@ -1,7 +1,7 @@ -import { concat, filter, forEach, isEmpty } from 'lodash'; +import { concat, filter, find, forEach, isEmpty, map } from 'lodash'; import { DataCellClick, - MergedCellsClick, + MergedCellClick, RowColumnClick, RowTextClick, } from './base-interaction/click'; @@ -31,7 +31,7 @@ import { SpreadSheet } from '@/sheet-type'; import { getAllPanelDataCell } from '@/utils/getAllPanelDataCell'; import { clearState, setState } from '@/utils/interaction/state-controller'; import { isMobile } from '@/utils/is-mobile'; -import { mergeCells, unmergeCell } from '@/utils/interaction/merge-cells'; +import { mergeCell, unmergeCell } from '@/utils/interaction/merge-cell'; export class RootInteraction { public spreadsheet: SpreadSheet; @@ -131,7 +131,11 @@ export class RootInteraction { // 获取 cells 中在可视区域内的实例列表 public getActiveCells() { const ids = this.getCells().map((item) => item.id); - return this.getAllCells().filter((cell) => ids.includes(cell.getMeta().id)); + const allCells = this.getAllCells(); + // 这里的顺序要以 ids 中的顺序为准,代表点击 cell 的顺序 + return map(ids, (id) => + find(allCells, (cell) => cell?.getMeta()?.id === id), + ).filter((cell) => cell); // 去除 undefined } public clearStyleIndependent() { @@ -218,7 +222,7 @@ export class RootInteraction { }; public mergeCells = (cellsInfo?: MergedCellInfo[], hideData?: boolean) => { - mergeCells(this.spreadsheet, cellsInfo, hideData); + mergeCell(this.spreadsheet, cellsInfo, hideData); }; public unmergeCell = (removedCells: MergedCell) => { @@ -250,7 +254,7 @@ export class RootInteraction { ); this.interactions.set( InteractionName.MERGED_CELLS_CLICK, - new MergedCellsClick(this.spreadsheet), + new MergedCellClick(this.spreadsheet), ); this.interactions.set( InteractionName.HOVER, @@ -267,7 +271,7 @@ export class RootInteraction { new RowColumnResize(this.spreadsheet), ); this.interactions.set( - InteractionName.COL_ROW_MULTI_SELECTION, + InteractionName.DATA_CELL_MULTI_SELECTION, new DataCellMultiSelection(this.spreadsheet), ); this.interactions.set( diff --git a/packages/s2-core/src/utils/interaction/index.ts b/packages/s2-core/src/utils/interaction/index.ts index 499d0e154a..14ef299ba1 100644 --- a/packages/s2-core/src/utils/interaction/index.ts +++ b/packages/s2-core/src/utils/interaction/index.ts @@ -1,5 +1,5 @@ export * from './formatter'; export * from './hover-event'; -export * from './merge-cells'; +export * from './merge-cell'; export * from './select-event'; export * from './state-controller'; diff --git a/packages/s2-core/src/utils/interaction/merge-cells.ts b/packages/s2-core/src/utils/interaction/merge-cell.ts similarity index 99% rename from packages/s2-core/src/utils/interaction/merge-cells.ts rename to packages/s2-core/src/utils/interaction/merge-cell.ts index 5bcb8c7cca..77508154fe 100644 --- a/packages/s2-core/src/utils/interaction/merge-cells.ts +++ b/packages/s2-core/src/utils/interaction/merge-cell.ts @@ -214,7 +214,7 @@ export const getActiveCellsInfo = (sheet: SpreadSheet) => { * @param cellsInfo * @param hideData */ -export const mergeCells = ( +export const mergeCell = ( sheet: SpreadSheet, cellsInfo?: MergedCellInfo[], hideData?: boolean, diff --git a/packages/s2-core/src/utils/interaction/state-controller.ts b/packages/s2-core/src/utils/interaction/state-controller.ts index b4e50d67b5..5136916688 100644 --- a/packages/s2-core/src/utils/interaction/state-controller.ts +++ b/packages/s2-core/src/utils/interaction/state-controller.ts @@ -33,8 +33,8 @@ export const clearState = (spreadsheet: SpreadSheet) => { /** * @desc set the interaction state information - * @param stateName the name of interaction state * @param spreadsheet sheet instance + * @param interactionStateInfo */ export const setState = ( spreadsheet: SpreadSheet, diff --git a/s2-site/docs/api/components/header.zh.md b/s2-site/docs/api/components/header.zh.md index 79207d325d..13a09c855a 100644 --- a/s2-site/docs/api/components/header.zh.md +++ b/s2-site/docs/api/components/header.zh.md @@ -1,5 +1,5 @@ --- -title: 表头 header +title: 表头 order: 4 --- diff --git a/s2-site/docs/common/header.zh.md b/s2-site/docs/common/header.zh.md index bcf8336bea..67db804c15 100644 --- a/s2-site/docs/common/header.zh.md +++ b/s2-site/docs/common/header.zh.md @@ -1,5 +1,5 @@ --- -title: 表头 Header +title: 表头 order: 0 --- diff --git a/s2-site/docs/manual/advanced/interaction/merge-cell.zh.md b/s2-site/docs/manual/advanced/interaction/merge-cell.zh.md index 109bd27103..e7ab3f1271 100644 --- a/s2-site/docs/manual/advanced/interaction/merge-cell.zh.md +++ b/s2-site/docs/manual/advanced/interaction/merge-cell.zh.md @@ -5,7 +5,7 @@ order: 5 在表格中将两个或多个连续的单元格合并为一个单元格。用户可根据业务要求,在看数或展示时实现分类分析。 -![mergeCellGif](https://gw.alipayobjects.com/mdn/rms_56cbb2/afts/img/A*uzxfQ71t8D4AAAAAAAAAAAAAARQnAQ) +![mergeCellGif](https://gw.alipayobjects.com/zos/antfincdn/Eq9WwyC2g/merge-cell.gif) ## 快速上手 @@ -277,31 +277,6 @@ const s2DataConfig = { data: res.data, meta: res.meta }; -// 将单元格合并操作集成到未合并单元格的 tooltip 操作中 -const TooltipContent = ( - -); - -// 将取消单元格合并操作集成到合并单元格的 tooltip 操作中 -const mergedCellsTooltip = (mergedCell: MergedCell) => ( -