diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 2905791ec2..f7ab65d367 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -12,7 +12,7 @@ jobs: # runs-on: macos-latest # (目前 macos-latest 对应的是 Big Sur 11, macos-12 对应 Monterey 12) # macOS 3-core CPU, 其他 2-core CPU # > macos-14 会导致 CI 的测试卡死, 没有任何报错!!! - runs-on: macos-13 + runs-on: macos-14 if: "!contains(github.event.head_commit.message, '[skip ci]')" strategy: matrix: diff --git a/packages/s2-core/CHANGELOG.md b/packages/s2-core/CHANGELOG.md index eac517fe0c..22a246db72 100644 --- a/packages/s2-core/CHANGELOG.md +++ b/packages/s2-core/CHANGELOG.md @@ -1,3 +1,18 @@ +# [@antv/s2-v2.1.3](https://github.com/antvis/S2/compare/@antv/s2-v2.1.2...@antv/s2-v2.1.3) (2024-12-09) + + +### Bug Fixes + +* 修复手动排序在单行头且维值相似的场景不生效 ([#3019](https://github.com/antvis/S2/issues/3019)) ([6221958](https://github.com/antvis/S2/commit/6221958ddc4113384260f82fd54f768077168287)) +* 选中事件增加 event 信息 ([#3021](https://github.com/antvis/S2/issues/3021)) ([291c727](https://github.com/antvis/S2/commit/291c727959d496f5210a2bc47bcdb0919080defa)) + +# [@antv/s2-v2.1.2](https://github.com/antvis/S2/compare/@antv/s2-v2.1.1...@antv/s2-v2.1.2) (2024-12-06) + + +### Bug Fixes + +* 修复明细表自定义行高时多行文本未自适应调整 ([#3017](https://github.com/antvis/S2/issues/3017)) ([8a55fa6](https://github.com/antvis/S2/commit/8a55fa6be4d3030845b54f5f11e752e31d9919e1)) + # [@antv/s2-v2.1.1](https://github.com/antvis/S2/compare/@antv/s2-v2.1.0...@antv/s2-v2.1.1) (2024-12-04) diff --git a/packages/s2-core/__tests__/spreadsheet/corner-spec.ts b/packages/s2-core/__tests__/spreadsheet/corner-spec.ts index 338d5dc26b..10a95d0b43 100644 --- a/packages/s2-core/__tests__/spreadsheet/corner-spec.ts +++ b/packages/s2-core/__tests__/spreadsheet/corner-spec.ts @@ -275,6 +275,7 @@ describe('PivotSheet Corner Tests', () => { expect(selected).toHaveBeenCalledWith(s2.interaction.getActiveCells(), { interactionName: 'cornerCellClick', targetCell: expect.anything(), + event: expect.anything(), }); // 取消选中 @@ -286,6 +287,7 @@ describe('PivotSheet Corner Tests', () => { expect(selected).toHaveBeenCalledWith([], { interactionName: 'cornerCellClick', targetCell: expect.anything(), + event: expect.anything(), }); getCellSpy.mockClear(); diff --git a/packages/s2-core/__tests__/unit/interaction/base-interaction/click/data-cell-click-spec.ts b/packages/s2-core/__tests__/unit/interaction/base-interaction/click/data-cell-click-spec.ts index aff0f8da5f..e9a62ae853 100644 --- a/packages/s2-core/__tests__/unit/interaction/base-interaction/click/data-cell-click-spec.ts +++ b/packages/s2-core/__tests__/unit/interaction/base-interaction/click/data-cell-click-spec.ts @@ -92,6 +92,7 @@ describe('Interaction Data Cell Click Tests', () => { expect(selected).toHaveBeenCalledWith([mockCellInfo.mockCell], { interactionName: 'dataCellClick', targetCell: s2.getCell(), + event: expect.anything(), }); }); @@ -115,6 +116,7 @@ describe('Interaction Data Cell Click Tests', () => { expect(selected).toHaveBeenCalledWith([], { interactionName: 'dataCellClick', targetCell: s2.getCell(), + event: expect.anything(), }); }); diff --git a/packages/s2-core/__tests__/unit/interaction/base-interaction/click/row-column-click-spec.ts b/packages/s2-core/__tests__/unit/interaction/base-interaction/click/row-column-click-spec.ts index c75f1d308e..1f9516e6e7 100644 --- a/packages/s2-core/__tests__/unit/interaction/base-interaction/click/row-column-click-spec.ts +++ b/packages/s2-core/__tests__/unit/interaction/base-interaction/click/row-column-click-spec.ts @@ -179,6 +179,7 @@ describe('Interaction Row & Column Cell Click Tests', () => { expect(selected).toHaveBeenCalledWith([mockCell], { interactionName: 'rowCellClick', targetCell: s2.getCell(), + event: expect.anything(), }); // 取消选中 @@ -189,7 +190,7 @@ describe('Interaction Row & Column Cell Click Tests', () => { expect(s2.interaction.getState().cells).toEqual([]); expect(s2.showTooltipWithInfo).toHaveBeenCalled(); expect(selected).toHaveBeenCalled(); - expect(s2.interaction.hasIntercepts([InterceptType.HOVER])).toBeFalse(); + expect(s2.interaction.hasIntercepts([InterceptType.HOVER])).toBeFalsy(); getInteractedCellsSpy.mockRestore(); }, @@ -243,6 +244,7 @@ describe('Interaction Row & Column Cell Click Tests', () => { expect(selected).toHaveBeenCalledWith([mockCell], { interactionName: 'rowCellClick', targetCell: s2.getCell(), + event: expect.anything(), }); }, ); diff --git a/packages/s2-core/__tests__/unit/interaction/data-cell-multi-selection-spec.ts b/packages/s2-core/__tests__/unit/interaction/data-cell-multi-selection-spec.ts index a226f050d4..b05b9b70e7 100644 --- a/packages/s2-core/__tests__/unit/interaction/data-cell-multi-selection-spec.ts +++ b/packages/s2-core/__tests__/unit/interaction/data-cell-multi-selection-spec.ts @@ -121,6 +121,7 @@ describe('Interaction Data Cell Multi Selection Tests', () => { { interactionName: 'dataCellMultiSelection', targetCell: s2.getCell(), + event: expect.anything(), }, ); diff --git a/packages/s2-core/__tests__/unit/interaction/event-controller-spec.ts b/packages/s2-core/__tests__/unit/interaction/event-controller-spec.ts index 0ffc98d561..7166055f6c 100644 --- a/packages/s2-core/__tests__/unit/interaction/event-controller-spec.ts +++ b/packages/s2-core/__tests__/unit/interaction/event-controller-spec.ts @@ -573,6 +573,7 @@ describe('Interaction Event Controller Tests', () => { expect(selected).toHaveBeenCalledWith([], { interactionName: 'globalReset', targetCell: null, + event: expect.anything(), }); expect(reset).toHaveBeenCalled(); expect(spreadsheet.interaction.reset).toHaveBeenCalled(); @@ -600,6 +601,7 @@ describe('Interaction Event Controller Tests', () => { expect(selected).toHaveBeenCalledWith([], { interactionName: 'globalReset', targetCell: null, + event: expect.anything(), }); expect(reset).toHaveBeenCalled(); expect(spreadsheet.interaction.reset).toHaveBeenCalled(); diff --git a/packages/s2-core/__tests__/unit/interaction/range-selection-spec.ts b/packages/s2-core/__tests__/unit/interaction/range-selection-spec.ts index 6175a1c439..0a179ac2b6 100644 --- a/packages/s2-core/__tests__/unit/interaction/range-selection-spec.ts +++ b/packages/s2-core/__tests__/unit/interaction/range-selection-spec.ts @@ -205,6 +205,7 @@ describe('Interaction Range Selection Tests', () => { expect(selected).toHaveBeenCalledWith(activeCells, { interactionName: 'rangeSelection', targetCell: s2.getCell(), + event: expect.anything(), }); expect( s2.interaction.hasIntercepts([InterceptType.CLICK, InterceptType.HOVER]), @@ -290,6 +291,7 @@ describe('Interaction Range Selection Tests', () => { expect(selected).toHaveBeenCalledWith(activeCells, { interactionName: 'rangeSelection', targetCell: s2.getCell(), + event: expect.anything(), }); expect( s2.interaction.hasIntercepts([InterceptType.CLICK, InterceptType.HOVER]), diff --git a/packages/s2-core/__tests__/unit/utils/sort-action-spec.ts b/packages/s2-core/__tests__/unit/utils/sort-action-spec.ts index ca1afcb811..59ef2ac5ce 100644 --- a/packages/s2-core/__tests__/unit/utils/sort-action-spec.ts +++ b/packages/s2-core/__tests__/unit/utils/sort-action-spec.ts @@ -211,6 +211,30 @@ describe('Sort By Custom Test', () => { 'Wednesday[&]afternoon', ]); }); + + test('sort by custom with semblable value', () => { + const params = { + originValues: [ + '我也是测1试', + '我是测试', + '我也是测试', + '我也是测试1', + '我也是1测试', + '测试', + ], + sortByValues: ['测试', '我是测试'], + }; + + // 原来的处理是 endsWith 去模糊匹配维值, 导致其他维值会排序到最上方 + expect(sortByCustom(params)).toEqual([ + '测试', + '我是测试', + '我也是测1试', + '我也是测试', + '我也是测试1', + '我也是1测试', + ]); + }); }); }); diff --git a/packages/s2-core/package.json b/packages/s2-core/package.json index 3b67dd8cba..4b7e332502 100644 --- a/packages/s2-core/package.json +++ b/packages/s2-core/package.json @@ -1,6 +1,6 @@ { "name": "@antv/s2", - "version": "2.1.1", + "version": "2.1.3", "private": false, "description": "effective spreadsheet render core lib", "keywords": [ diff --git a/packages/s2-core/src/common/interface/emitter.ts b/packages/s2-core/src/common/interface/emitter.ts index 219ac0226d..61ee22a844 100644 --- a/packages/s2-core/src/common/interface/emitter.ts +++ b/packages/s2-core/src/common/interface/emitter.ts @@ -44,10 +44,16 @@ export interface CellSelectedDetail { * 触发选中的交互名 */ interactionName?: `${InteractionName}`; + /** * 触发选中的单元格 */ targetCell?: S2CellType | null; + + /** + * 触发选中的事件对象 + */ + event?: CanvasEvent | KeyboardEvent | Event | null; } export type CellSelectedHandler = ( diff --git a/packages/s2-core/src/common/interface/interaction.ts b/packages/s2-core/src/common/interface/interaction.ts index 2b35e86dd9..bb55652e5f 100644 --- a/packages/s2-core/src/common/interface/interaction.ts +++ b/packages/s2-core/src/common/interface/interaction.ts @@ -116,6 +116,11 @@ export interface ChangeCellOptions extends CellScrollToOptions { * @default true */ scrollIntoView?: boolean; + + /** + * 触发事件对象 + */ + event?: FederatedPointerEvent; } export type InteractionConstructor = new ( diff --git a/packages/s2-core/src/interaction/base-interaction/click/corner-cell-click.ts b/packages/s2-core/src/interaction/base-interaction/click/corner-cell-click.ts index 344bedab50..9c8031dd8c 100644 --- a/packages/s2-core/src/interaction/base-interaction/click/corner-cell-click.ts +++ b/packages/s2-core/src/interaction/base-interaction/click/corner-cell-click.ts @@ -115,8 +115,9 @@ export class CornerCellClick extends BaseEvent implements BaseEventImplement { }); } - private emitSelectEvent(targetCell: S2CellType) { + private emitSelectEvent(event: CanvasEvent, targetCell: S2CellType) { this.spreadsheet.interaction.emitSelectEvent({ + event, targetCell, interactionName: InteractionName.CORNER_CELL_CLICK, }); @@ -130,7 +131,7 @@ export class CornerCellClick extends BaseEvent implements BaseEventImplement { if (sample && interaction.isSelectedCell(sample)) { interaction.reset(); - this.emitSelectEvent(cornerCell); + this.emitSelectEvent(event, cornerCell); return; } @@ -148,7 +149,7 @@ export class CornerCellClick extends BaseEvent implements BaseEventImplement { cornerCell?.updateByState(InteractionStateName.SELECTED); this.showTooltip(event); - this.emitSelectEvent(cornerCell); + this.emitSelectEvent(event, cornerCell); } private showTooltip(event: CanvasEvent) { diff --git a/packages/s2-core/src/interaction/base-interaction/click/data-cell-click.ts b/packages/s2-core/src/interaction/base-interaction/click/data-cell-click.ts index 16b4f45c04..57414b4f8f 100644 --- a/packages/s2-core/src/interaction/base-interaction/click/data-cell-click.ts +++ b/packages/s2-core/src/interaction/base-interaction/click/data-cell-click.ts @@ -60,6 +60,7 @@ export class DataCellClick extends BaseEvent implements BaseEventImplement { // https://github.com/antvis/S2/issues/2447 interaction.emitSelectEvent({ + event, targetCell: cell, interactionName: InteractionName.DATA_CELL_CLICK, }); @@ -74,6 +75,7 @@ export class DataCellClick extends BaseEvent implements BaseEventImplement { onUpdateCells: afterSelectDataCells, }); interaction.emitSelectEvent({ + event, targetCell: cell, interactionName: InteractionName.DATA_CELL_CLICK, cells: [cell], diff --git a/packages/s2-core/src/interaction/base-interaction/click/row-column-click.ts b/packages/s2-core/src/interaction/base-interaction/click/row-column-click.ts index bfd2d8604c..fcbac51fe7 100644 --- a/packages/s2-core/src/interaction/base-interaction/click/row-column-click.ts +++ b/packages/s2-core/src/interaction/base-interaction/click/row-column-click.ts @@ -114,6 +114,7 @@ export class RowColumnClick extends BaseEvent implements BaseEventImplement { : InteractionName.COL_CELL_CLICK; const success = interaction.changeCell({ + event, cell, isMultiSelection, interactionName: isMultiSelection diff --git a/packages/s2-core/src/interaction/brush-selection/base-brush-selection.ts b/packages/s2-core/src/interaction/brush-selection/base-brush-selection.ts index 21e42aaf02..c90f19f0bf 100644 --- a/packages/s2-core/src/interaction/brush-selection/base-brush-selection.ts +++ b/packages/s2-core/src/interaction/brush-selection/base-brush-selection.ts @@ -698,7 +698,7 @@ export class BaseBrushSelection if (this.isValidBrushSelection()) { this.addBrushIntercepts(); - this.updateSelectedCells(); + this.updateSelectedCells(event); const tooltipData = getCellsTooltipData(this.spreadsheet); @@ -819,7 +819,8 @@ export class BaseBrushSelection protected bindMouseMove() {} - protected updateSelectedCells() {} + // eslint-disable-next-line @typescript-eslint/no-unused-vars + protected updateSelectedCells(event: MouseEvent) {} protected getPrepareSelectMaskPosition(brushRange: BrushRange): PointLike { return { diff --git a/packages/s2-core/src/interaction/brush-selection/col-brush-selection.ts b/packages/s2-core/src/interaction/brush-selection/col-brush-selection.ts index 87ca5b20ab..2f905c818b 100644 --- a/packages/s2-core/src/interaction/brush-selection/col-brush-selection.ts +++ b/packages/s2-core/src/interaction/brush-selection/col-brush-selection.ts @@ -99,7 +99,7 @@ export class ColCellBrushSelection extends BaseBrushSelection { } // 最终刷选的 cell - protected updateSelectedCells() { + protected updateSelectedCells(event: MouseEvent) { const { interaction, facet } = this.spreadsheet; interaction.changeState({ @@ -114,6 +114,7 @@ export class ColCellBrushSelection extends BaseBrushSelection { S2Event.COL_CELL_BRUSH_SELECTION, this.brushRangeCells, { + event, targetCell: this.brushRangeCells[0], interactionName: InteractionName.COL_CELL_BRUSH_SELECTION, }, diff --git a/packages/s2-core/src/interaction/brush-selection/data-cell-brush-selection.ts b/packages/s2-core/src/interaction/brush-selection/data-cell-brush-selection.ts index ee8eb3179b..729022cf3d 100644 --- a/packages/s2-core/src/interaction/brush-selection/data-cell-brush-selection.ts +++ b/packages/s2-core/src/interaction/brush-selection/data-cell-brush-selection.ts @@ -100,7 +100,7 @@ export class DataCellBrushSelection extends BaseBrushSelection { }; // 最终刷选的 cell - protected updateSelectedCells() { + protected updateSelectedCells(event: MouseEvent) { const brushRange = this.getBrushRange(); const selectedCellMetas = this.getSelectedCellMetas(brushRange); @@ -117,6 +117,7 @@ export class DataCellBrushSelection extends BaseBrushSelection { S2Event.DATA_CELL_BRUSH_SELECTION, scrollBrushRangeCells, { + event, targetCell: scrollBrushRangeCells[0], interactionName: InteractionName.DATA_CELL_BRUSH_SELECTION, }, diff --git a/packages/s2-core/src/interaction/brush-selection/row-brush-selection.ts b/packages/s2-core/src/interaction/brush-selection/row-brush-selection.ts index 9a27fec4ba..c49c50a241 100644 --- a/packages/s2-core/src/interaction/brush-selection/row-brush-selection.ts +++ b/packages/s2-core/src/interaction/brush-selection/row-brush-selection.ts @@ -96,7 +96,7 @@ export class RowCellBrushSelection extends BaseBrushSelection { }; // 最终刷选的 cells - protected updateSelectedCells() { + protected updateSelectedCells(event: MouseEvent) { const selectedRowNodes = this.getSelectedRowNodes(); const scrollBrushRangeCells = this.getScrollBrushRangeCells(selectedRowNodes); @@ -112,6 +112,7 @@ export class RowCellBrushSelection extends BaseBrushSelection { S2Event.ROW_CELL_BRUSH_SELECTION, scrollBrushRangeCells, { + event, targetCell: scrollBrushRangeCells[0], interactionName: InteractionName.ROW_CELL_BRUSH_SELECTION, }, diff --git a/packages/s2-core/src/interaction/data-cell-multi-selection.ts b/packages/s2-core/src/interaction/data-cell-multi-selection.ts index a451c41533..e51c54a322 100644 --- a/packages/s2-core/src/interaction/data-cell-multi-selection.ts +++ b/packages/s2-core/src/interaction/data-cell-multi-selection.ts @@ -98,6 +98,7 @@ export class DataCellMultiSelection interaction.clearState(); this.spreadsheet.hideTooltip(); interaction.emitSelectEvent({ + event, targetCell: cell, interactionName: InteractionName.DATA_CELL_MULTI_SELECTION, }); @@ -114,6 +115,7 @@ export class DataCellMultiSelection onUpdateCells: afterSelectDataCells, }); interaction.emitSelectEvent({ + event, targetCell: cell, interactionName: InteractionName.DATA_CELL_MULTI_SELECTION, }); diff --git a/packages/s2-core/src/interaction/event-controller.ts b/packages/s2-core/src/interaction/event-controller.ts index 595f8968ef..c2d61bb555 100644 --- a/packages/s2-core/src/interaction/event-controller.ts +++ b/packages/s2-core/src/interaction/event-controller.ts @@ -199,6 +199,7 @@ export class EventController { S2Event.GLOBAL_SELECTED, interaction.getActiveCells(), { + event, targetCell: null, interactionName: InteractionName.GLOBAL_RESET, }, diff --git a/packages/s2-core/src/interaction/range-selection.ts b/packages/s2-core/src/interaction/range-selection.ts index 2e6450f116..3e16c0e014 100644 --- a/packages/s2-core/src/interaction/range-selection.ts +++ b/packages/s2-core/src/interaction/range-selection.ts @@ -126,6 +126,7 @@ export class RangeSelection extends BaseEvent implements BaseEventImplement { ); interaction.emitSelectEvent({ targetCell: cell, + event, interactionName: InteractionName.RANGE_SELECTION, }); }); @@ -189,8 +190,8 @@ export class RangeSelection extends BaseEvent implements BaseEventImplement { const selectedCellIds = groupSelectedCells(selectedCells); interaction.updateCells(facet.getHeaderCells(selectedCellIds)); - interaction.emitSelectEvent({ + event, targetCell: cell, interactionName: InteractionName.RANGE_SELECTION, }); diff --git a/packages/s2-core/src/interaction/root.ts b/packages/s2-core/src/interaction/root.ts index 2502dddaa0..a5c0fdca63 100644 --- a/packages/s2-core/src/interaction/root.ts +++ b/packages/s2-core/src/interaction/root.ts @@ -581,6 +581,7 @@ export class RootInteraction { */ public changeCell(options: ChangeCellOptions = {} as ChangeCellOptions) { const { + event, cell, stateName = InteractionStateName.SELECTED, interactionName, @@ -628,6 +629,7 @@ export class RootInteraction { if (isEmpty(selectedCells)) { this.reset(); this.emitSelectEvent({ + event, targetCell: cell, interactionName, }); @@ -670,6 +672,7 @@ export class RootInteraction { // 由于绘制的顺序问题, 交互背景图层展示后, 会遮挡边框, 需要让边框展示在前面. this.spreadsheet.facet.centerFrame?.toFront(); this.emitSelectEvent({ + event, targetCell: cell, interactionName, }); diff --git a/packages/s2-core/src/interaction/selected-cell-move.ts b/packages/s2-core/src/interaction/selected-cell-move.ts index c9d912737f..dc7c792476 100644 --- a/packages/s2-core/src/interaction/selected-cell-move.ts +++ b/packages/s2-core/src/interaction/selected-cell-move.ts @@ -145,6 +145,7 @@ export class SelectedCellMove extends BaseEvent implements BaseEventImplement { cells: selectedCells, }); spreadsheet.interaction.emitSelectEvent({ + event, interactionName: InteractionName.SELECTED_CELL_MOVE, }); this.spreadsheet.emit(S2Event.DATA_CELL_SELECT_MOVE, selectedCells); diff --git a/packages/s2-core/src/utils/interaction/select-event.ts b/packages/s2-core/src/utils/interaction/select-event.ts index 1259f9f9be..d960b0727e 100644 --- a/packages/s2-core/src/utils/interaction/select-event.ts +++ b/packages/s2-core/src/utils/interaction/select-event.ts @@ -40,16 +40,6 @@ export const getCellMeta = (cell: S2CellType): CellMeta => { }; }; -// export const selectCells = (spreadsheet: SpreadSheet, cells: CellMeta[]) => { -// const { interaction } = spreadsheet; - -// interaction.changeState({ -// stateName: InteractionStateName.SELECTED, -// cells, -// }); -// spreadsheet.emit(S2Event.GLOBAL_SELECTED, interaction.getActiveCells()); -// }; - export function getRangeIndex( start: T, end: T, diff --git a/packages/s2-core/src/utils/sort-action.ts b/packages/s2-core/src/utils/sort-action.ts index 171b00ceec..da5ccf36b0 100644 --- a/packages/s2-core/src/utils/sort-action.ts +++ b/packages/s2-core/src/utils/sort-action.ts @@ -1,12 +1,12 @@ import { compact, - endsWith, flatMap, includes, indexOf, isEmpty, isNil, keys, + last, map, sortBy, split, @@ -108,8 +108,10 @@ export const sortByCustom = (params: SortActionParams): string[] => { const { sortByValues = [], originValues = [] } = params; // 从 originValues 中过滤出所有包含 sortByValue 的 id - const idWithPre = originValues.filter((originItem) => - sortByValues.find((value) => endsWith(originItem, value)), + const idWithPre = originValues.filter((originValue) => + sortByValues.find((value) => { + return last(split(originValue, NODE_ID_SEPARATOR)) === value; + }), ); // 将 id 拆分为父节点和目标节点 const idListWithPre = idWithPre.map((idStr) => { diff --git a/packages/s2-react/CHANGELOG.md b/packages/s2-react/CHANGELOG.md index a9a4128277..d12126d6c0 100644 --- a/packages/s2-react/CHANGELOG.md +++ b/packages/s2-react/CHANGELOG.md @@ -1,3 +1,10 @@ +# [@antv/s2-react-v2.1.2](https://github.com/antvis/S2/compare/@antv/s2-react-v2.1.1...@antv/s2-react-v2.1.2) (2024-12-06) + + +### Bug Fixes + +* 修复手动调用 showTooltip 不展示菜单的问题 ([d8afe27](https://github.com/antvis/S2/commit/d8afe2723ba731c220a1dcd8be22afd8d63aed8e)) + # [@antv/s2-react-v2.1.1](https://github.com/antvis/S2/compare/@antv/s2-react-v2.1.0...@antv/s2-react-v2.1.1) (2024-12-04) diff --git a/packages/s2-react/package.json b/packages/s2-react/package.json index 66d7fec7ea..1659ef2023 100644 --- a/packages/s2-react/package.json +++ b/packages/s2-react/package.json @@ -1,6 +1,6 @@ { "name": "@antv/s2-react", - "version": "2.1.1", + "version": "2.1.2", "private": false, "description": "use S2 with react", "keywords": [ diff --git a/packages/s2-react/playground/config.tsx b/packages/s2-react/playground/config.tsx index 7503c06ee2..932b4b5917 100644 --- a/packages/s2-react/playground/config.tsx +++ b/packages/s2-react/playground/config.tsx @@ -284,6 +284,9 @@ export const S2TooltipOptions: SheetComponentOptions['tooltip'] = { key: 'custom-a', label: '操作1', icon: 'Trend', + visible: (cell) => { + return cell instanceof DataCell; + }, onClick: (info, cell) => { console.log('操作1点击:', info, cell); }, @@ -302,25 +305,6 @@ export const S2TooltipOptions: SheetComponentOptions['tooltip'] = { key: 'custom-b', label: '操作2', icon: 'EyeOutlined', - onClick: (info, cell) => { - console.log('操作2点击:', info, cell); - }, - }, - { - key: 'custom-c', - label: '操作3', - icon: 'EyeOutlined', - visible: (cell) => { - return cell instanceof DataCell; - }, - onClick: (info, cell) => { - console.log('操作3点击:', info, cell); - }, - }, - { - key: 'custom-d', - label: '操作4', - icon: 'EyeOutlined', visible: (cell) => { // 叶子节点才显示 const meta = cell.getMeta(); @@ -328,7 +312,7 @@ export const S2TooltipOptions: SheetComponentOptions['tooltip'] = { return meta.isLeaf; }, onClick: (info, cell) => { - console.log('操作4点击:', info, cell); + console.log('操作2点击:', info, cell); }, }, ], diff --git a/packages/s2-react/src/components/tooltip/custom-tooltip.tsx b/packages/s2-react/src/components/tooltip/custom-tooltip.tsx index 12c6c7f605..07f622bc5b 100644 --- a/packages/s2-react/src/components/tooltip/custom-tooltip.tsx +++ b/packages/s2-react/src/components/tooltip/custom-tooltip.tsx @@ -1,7 +1,8 @@ /* eslint-disable import/order */ /* eslint-disable import/no-extraneous-dependencies */ // eslint-disable-next-line prettier/prettier -import { BaseTooltip, isMobile, SpreadSheet } from '@antv/s2'; +import { BaseTooltip, customMerge, isMobile, SpreadSheet } from '@antv/s2'; +import { omit } from 'lodash'; import React from 'react'; import { forceClearContent, @@ -32,7 +33,8 @@ export class CustomTooltip extends BaseTooltip< renderContent() { // 配置级 s2.options.tooltip.content = '' - const { content: contentFromOptions } = this.spreadsheet.options.tooltip!; + const { content: contentFromOptions, operation } = + this.spreadsheet.options.tooltip!; // 方法级 s2.showTooltip({ content: '' }) const showOptions = this.options; const cell = this.spreadsheet.getCell(showOptions?.event?.target); @@ -40,11 +42,20 @@ export class CustomTooltip extends BaseTooltip< const content = (showOptions?.content ?? contentFromOptions) as React.ReactNode; - const tooltipProps: TooltipRenderProps = { - ...showOptions, - cell, - content, - }; + const tooltipProps = customMerge( + { + options: { + operator: { + menu: omit(operation?.menu, 'items'), + }, + }, + }, + { + ...showOptions, + cell, + content, + }, + ); if (showOptions?.options?.forceRender) { this.forceClearContent(); diff --git a/s2-site/docs/common/interaction.zh.md b/s2-site/docs/common/interaction.zh.md index 5f88a0ec5f..bfba535e98 100644 --- a/s2-site/docs/common/interaction.zh.md +++ b/s2-site/docs/common/interaction.zh.md @@ -93,6 +93,7 @@ interface ScrollSpeedRatio { | -- | -- | -- | -- | --- | | interactionName | 触发选中的交互名 | [InteractionName](#interactionname) | | | | targetCell | 触发选中的单元格 | [S2CellType](/api/basic-class/base-cell) | | | +| event | 触发选中的事件对象 | `FederatedPointerEvent \| Event \| KeyboardEvent` | | | ### InterceptType