Skip to content

Commit

Permalink
Merge branch 'antvis:next' into tree-line
Browse files Browse the repository at this point in the history
  • Loading branch information
gb853940223 authored Dec 10, 2024
2 parents 82c81ef + 8fca772 commit 9aa3ba0
Show file tree
Hide file tree
Showing 31 changed files with 125 additions and 53 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
15 changes: 15 additions & 0 deletions packages/s2-core/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)


Expand Down
2 changes: 2 additions & 0 deletions packages/s2-core/__tests__/spreadsheet/corner-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ describe('PivotSheet Corner Tests', () => {
expect(selected).toHaveBeenCalledWith(s2.interaction.getActiveCells(), {
interactionName: 'cornerCellClick',
targetCell: expect.anything(),
event: expect.anything(),
});

// 取消选中
Expand All @@ -286,6 +287,7 @@ describe('PivotSheet Corner Tests', () => {
expect(selected).toHaveBeenCalledWith([], {
interactionName: 'cornerCellClick',
targetCell: expect.anything(),
event: expect.anything(),
});

getCellSpy.mockClear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ describe('Interaction Data Cell Click Tests', () => {
expect(selected).toHaveBeenCalledWith([mockCellInfo.mockCell], {
interactionName: 'dataCellClick',
targetCell: s2.getCell(),
event: expect.anything(),
});
});

Expand All @@ -115,6 +116,7 @@ describe('Interaction Data Cell Click Tests', () => {
expect(selected).toHaveBeenCalledWith([], {
interactionName: 'dataCellClick',
targetCell: s2.getCell(),
event: expect.anything(),
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ describe('Interaction Row & Column Cell Click Tests', () => {
expect(selected).toHaveBeenCalledWith([mockCell], {
interactionName: 'rowCellClick',
targetCell: s2.getCell(),
event: expect.anything(),
});

// 取消选中
Expand All @@ -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();
},
Expand Down Expand Up @@ -243,6 +244,7 @@ describe('Interaction Row & Column Cell Click Tests', () => {
expect(selected).toHaveBeenCalledWith([mockCell], {
interactionName: 'rowCellClick',
targetCell: s2.getCell(),
event: expect.anything(),
});
},
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ describe('Interaction Data Cell Multi Selection Tests', () => {
{
interactionName: 'dataCellMultiSelection',
targetCell: s2.getCell(),
event: expect.anything(),
},
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]),
Expand Down Expand Up @@ -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]),
Expand Down
24 changes: 24 additions & 0 deletions packages/s2-core/__tests__/unit/utils/sort-action-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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测试',
]);
});
});
});

Expand Down
2 changes: 1 addition & 1 deletion packages/s2-core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@antv/s2",
"version": "2.1.1",
"version": "2.1.3",
"private": false,
"description": "effective spreadsheet render core lib",
"keywords": [
Expand Down
6 changes: 6 additions & 0 deletions packages/s2-core/src/common/interface/emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,16 @@ export interface CellSelectedDetail {
* 触发选中的交互名
*/
interactionName?: `${InteractionName}`;

/**
* 触发选中的单元格
*/
targetCell?: S2CellType | null;

/**
* 触发选中的事件对象
*/
event?: CanvasEvent | KeyboardEvent | Event | null;
}

export type CellSelectedHandler = (
Expand Down
5 changes: 5 additions & 0 deletions packages/s2-core/src/common/interface/interaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@ export interface ChangeCellOptions extends CellScrollToOptions {
* @default true
*/
scrollIntoView?: boolean;

/**
* 触发事件对象
*/
event?: FederatedPointerEvent;
}

export type InteractionConstructor = new (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
Expand All @@ -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;
}
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
Expand All @@ -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],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ export class RowColumnClick extends BaseEvent implements BaseEventImplement {
: InteractionName.COL_CELL_CLICK;

const success = interaction.changeCell({
event,
cell,
isMultiSelection,
interactionName: isMultiSelection
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -698,7 +698,7 @@ export class BaseBrushSelection

if (this.isValidBrushSelection()) {
this.addBrushIntercepts();
this.updateSelectedCells();
this.updateSelectedCells(event);

const tooltipData = getCellsTooltipData(this.spreadsheet);

Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export class ColCellBrushSelection extends BaseBrushSelection {
}

// 最终刷选的 cell
protected updateSelectedCells() {
protected updateSelectedCells(event: MouseEvent) {
const { interaction, facet } = this.spreadsheet;

interaction.changeState({
Expand All @@ -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,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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,
},
Expand Down
2 changes: 2 additions & 0 deletions packages/s2-core/src/interaction/data-cell-multi-selection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ export class DataCellMultiSelection
interaction.clearState();
this.spreadsheet.hideTooltip();
interaction.emitSelectEvent({
event,
targetCell: cell,
interactionName: InteractionName.DATA_CELL_MULTI_SELECTION,
});
Expand All @@ -114,6 +115,7 @@ export class DataCellMultiSelection
onUpdateCells: afterSelectDataCells,
});
interaction.emitSelectEvent({
event,
targetCell: cell,
interactionName: InteractionName.DATA_CELL_MULTI_SELECTION,
});
Expand Down
1 change: 1 addition & 0 deletions packages/s2-core/src/interaction/event-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ export class EventController {
S2Event.GLOBAL_SELECTED,
interaction.getActiveCells(),
{
event,
targetCell: null,
interactionName: InteractionName.GLOBAL_RESET,
},
Expand Down
3 changes: 2 additions & 1 deletion packages/s2-core/src/interaction/range-selection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ export class RangeSelection extends BaseEvent implements BaseEventImplement {
);
interaction.emitSelectEvent({
targetCell: cell,
event,
interactionName: InteractionName.RANGE_SELECTION,
});
});
Expand Down Expand Up @@ -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,
});
Expand Down
3 changes: 3 additions & 0 deletions packages/s2-core/src/interaction/root.ts
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,7 @@ export class RootInteraction {
*/
public changeCell(options: ChangeCellOptions = {} as ChangeCellOptions) {
const {
event,
cell,
stateName = InteractionStateName.SELECTED,
interactionName,
Expand Down Expand Up @@ -628,6 +629,7 @@ export class RootInteraction {
if (isEmpty(selectedCells)) {
this.reset();
this.emitSelectEvent({
event,
targetCell: cell,
interactionName,
});
Expand Down Expand Up @@ -670,6 +672,7 @@ export class RootInteraction {
// 由于绘制的顺序问题, 交互背景图层展示后, 会遮挡边框, 需要让边框展示在前面.
this.spreadsheet.facet.centerFrame?.toFront();
this.emitSelectEvent({
event,
targetCell: cell,
interactionName,
});
Expand Down
1 change: 1 addition & 0 deletions packages/s2-core/src/interaction/selected-cell-move.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading

0 comments on commit 9aa3ba0

Please sign in to comment.