Skip to content

Commit

Permalink
Merge branch 'master' into issue-2071
Browse files Browse the repository at this point in the history
  • Loading branch information
d2FuZ3h1ZG9uZw authored Jul 7, 2023
2 parents 9004a49 + 2d85d57 commit 864ca68
Show file tree
Hide file tree
Showing 14 changed files with 89 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Array [
"extra": undefined,
"field": "province",
"height": 30,
"id": "",
"id": "province",
"inCollapseNode": undefined,
"isCollapsed": undefined,
"isGrandTotals": undefined,
Expand Down Expand Up @@ -39,7 +39,7 @@ Array [
"extra": undefined,
"field": "city",
"height": 30,
"id": "",
"id": "city",
"inCollapseNode": undefined,
"isCollapsed": undefined,
"isGrandTotals": undefined,
Expand Down Expand Up @@ -102,7 +102,7 @@ Array [
"extra": undefined,
"field": "province",
"height": 30,
"id": "",
"id": "province",
"inCollapseNode": undefined,
"isCollapsed": undefined,
"isGrandTotals": undefined,
Expand Down Expand Up @@ -131,7 +131,7 @@ Array [
"extra": undefined,
"field": "city",
"height": 30,
"id": "",
"id": "city",
"inCollapseNode": undefined,
"isCollapsed": undefined,
"isGrandTotals": undefined,
Expand Down Expand Up @@ -165,7 +165,7 @@ Array [
"extra": undefined,
"field": undefined,
"height": 30,
"id": "",
"id": "province/city/数值",
"inCollapseNode": undefined,
"isCollapsed": undefined,
"isGrandTotals": undefined,
Expand Down Expand Up @@ -228,7 +228,7 @@ Array [
"extra": undefined,
"field": undefined,
"height": 30,
"id": "",
"id": "province/city/数值",
"inCollapseNode": undefined,
"isCollapsed": undefined,
"isGrandTotals": undefined,
Expand Down Expand Up @@ -262,7 +262,7 @@ Array [
"extra": undefined,
"field": "province",
"height": 30,
"id": "",
"id": "province",
"inCollapseNode": undefined,
"isCollapsed": undefined,
"isGrandTotals": undefined,
Expand Down Expand Up @@ -291,7 +291,7 @@ Array [
"extra": undefined,
"field": "city",
"height": 30,
"id": "",
"id": "city",
"inCollapseNode": undefined,
"isCollapsed": undefined,
"isGrandTotals": undefined,
Expand Down Expand Up @@ -354,7 +354,7 @@ Array [
"extra": undefined,
"field": "province",
"height": 30,
"id": "",
"id": "province",
"inCollapseNode": undefined,
"isCollapsed": undefined,
"isGrandTotals": undefined,
Expand Down Expand Up @@ -383,7 +383,7 @@ Array [
"extra": undefined,
"field": "city",
"height": 30,
"id": "",
"id": "city",
"inCollapseNode": undefined,
"isCollapsed": undefined,
"isGrandTotals": undefined,
Expand Down Expand Up @@ -417,7 +417,7 @@ Array [
"extra": undefined,
"field": undefined,
"height": 30,
"id": "",
"id": "province/city",
"inCollapseNode": undefined,
"isCollapsed": undefined,
"isGrandTotals": undefined,
Expand Down Expand Up @@ -480,7 +480,7 @@ Array [
"extra": undefined,
"field": undefined,
"height": 30,
"id": "",
"id": "province/city",
"inCollapseNode": undefined,
"isCollapsed": undefined,
"isGrandTotals": undefined,
Expand Down Expand Up @@ -514,7 +514,7 @@ Array [
"extra": undefined,
"field": "province",
"height": 30,
"id": "",
"id": "province",
"inCollapseNode": undefined,
"isCollapsed": undefined,
"isGrandTotals": undefined,
Expand Down Expand Up @@ -543,7 +543,7 @@ Array [
"extra": undefined,
"field": "city",
"height": 30,
"id": "",
"id": "city",
"inCollapseNode": undefined,
"isCollapsed": undefined,
"isGrandTotals": undefined,
Expand Down Expand Up @@ -606,7 +606,7 @@ Array [
"extra": undefined,
"field": "province",
"height": 30,
"id": "",
"id": "province",
"inCollapseNode": undefined,
"isCollapsed": undefined,
"isGrandTotals": undefined,
Expand Down Expand Up @@ -635,7 +635,7 @@ Array [
"extra": undefined,
"field": "city",
"height": 30,
"id": "",
"id": "city",
"inCollapseNode": undefined,
"isCollapsed": undefined,
"isGrandTotals": undefined,
Expand Down Expand Up @@ -669,7 +669,7 @@ Array [
"extra": undefined,
"field": undefined,
"height": 30,
"id": "",
"id": "province/city",
"inCollapseNode": undefined,
"isCollapsed": undefined,
"isGrandTotals": undefined,
Expand Down Expand Up @@ -732,7 +732,7 @@ Array [
"extra": undefined,
"field": undefined,
"height": 30,
"id": "",
"id": "province/city",
"inCollapseNode": undefined,
"isCollapsed": undefined,
"isGrandTotals": undefined,
Expand Down
15 changes: 10 additions & 5 deletions packages/s2-core/__tests__/spreadsheet/table-sheet-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,15 @@ describe('TableSheet normal spec', () => {

await sleep(30);

let columnNodes = s2.getColumnNodes();
let lastColumnCell = columnNodes[columnNodes.length - 1]
.belongsCell as ColCell;
const startCellWidth = lastColumnCell.getMeta().width;

const { x, width, top } = s2.getCanvasElement().getBoundingClientRect();
s2.getCanvasElement().dispatchEvent(
new MouseEvent('mousedown', {
clientX: x + width - 1,
clientX: x + width,
clientY: top + 25,
}),
);
Expand All @@ -207,11 +212,11 @@ describe('TableSheet normal spec', () => {

await sleep(300);

const columnNodes = s2.getColumnNodes();
const lastColumnCell = columnNodes[columnNodes.length - 1]
.belongsCell as ColCell;
columnNodes = s2.getColumnNodes();
lastColumnCell = columnNodes[columnNodes.length - 1].belongsCell as ColCell;
const endCellWidth = lastColumnCell.getMeta().width;

expect(lastColumnCell.getMeta().width).toBe(199);
expect(endCellWidth - startCellWidth).toBe(100);
});

test('should render link shape', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,13 +199,16 @@ describe('Interaction Row Column Resize Tests', () => {
{
offsetX: 10,
offsetY: 20,
clientX: 10,
clientY: 20,
},
resizeInfo,
);

expect(s2.store.get('resized')).toBeFalsy();
expect(rowColumnResizeInstance.resizeStartPosition).toStrictEqual({
offsetX: 10,
clientX: 10,
});
expect(getStartGuideLine().attr('path')).toStrictEqual([
['M', 2, 2],
Expand Down Expand Up @@ -312,12 +315,15 @@ describe('Interaction Row Column Resize Tests', () => {
{
offsetX: 10,
offsetY: 20,
clientX: 10,
clientY: 20,
},
resizeInfo,
);

expect(rowColumnResizeInstance.resizeStartPosition).toStrictEqual({
offsetY: 20,
clientY: 20,
});
expect(getStartGuideLine().attr('path')).toStrictEqual([
['M', 2, 2],
Expand Down Expand Up @@ -605,6 +611,8 @@ describe('Interaction Row Column Resize Tests', () => {
{
offsetX: 10,
offsetY: 20,
clientX: 10,
clientY: 20,
},
resizeInfo,
);
Expand All @@ -614,6 +622,8 @@ describe('Interaction Row Column Resize Tests', () => {
{
offsetX: 20,
offsetY: 20,
clientX: 20,
clientY: 20,
},
resizeInfo,
);
Expand Down
4 changes: 1 addition & 3 deletions packages/s2-core/src/cell/corner-cell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import {
} from '../utils/interaction/resize';
import { isIPhoneX } from '../utils/is-mobile';
import { getEllipsisText, getEmptyPlaceholder } from '../utils/text';
import { i18n } from './../common/i18n';
import { shouldAddResizeArea } from './../utils/interaction/resize';
import { HeaderCell } from './header-cell';

Expand All @@ -54,8 +53,6 @@ export class CornerCell extends HeaderCell {
return CellTypes.CORNER_CELL;
}

public update() {}

protected initCell() {
super.initCell();
this.resetTextAndConditionIconShapes();
Expand All @@ -66,6 +63,7 @@ export class CornerCell extends HeaderCell {
this.drawActionIcons();
this.drawBorderShape();
this.drawResizeArea();
this.update();
}

/**
Expand Down
2 changes: 2 additions & 0 deletions packages/s2-core/src/cell/header-cell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -395,9 +395,11 @@ export abstract class HeaderCell extends BaseCell<Node> {
const { interaction } = this.spreadsheet;
const stateInfo = interaction?.getState();
const cells = interaction?.getCells([
CellTypes.CORNER_CELL,
CellTypes.COL_CELL,
CellTypes.ROW_CELL,
]);

if (!first(cells)) {
return;
}
Expand Down
2 changes: 2 additions & 0 deletions packages/s2-core/src/common/interface/resize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ export interface ResizeGuideLinePosition {
export interface ResizePosition {
offsetX?: number;
offsetY?: number;
clientX?: number;
clientY?: number;
}

export interface ResizeDetail {
Expand Down
6 changes: 3 additions & 3 deletions packages/s2-core/src/facet/header/corner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ export class CornerHeader extends BaseHeader<CornerHeaderConfig> {

const cNode: Node = new Node({
key: '',
id: '',
id: cornerText,
value: cornerText,
});
cNode.x = position.x + seriesNumberWidth;
Expand All @@ -154,7 +154,7 @@ export class CornerHeader extends BaseHeader<CornerHeaderConfig> {
const field = rows[rowNode.level];
const cNode: Node = new Node({
key: field,
id: '',
id: field,
value: dataSet.getFieldName(field),
});

Expand All @@ -176,7 +176,7 @@ export class CornerHeader extends BaseHeader<CornerHeaderConfig> {
const field = columns[colNode.level];
const cNode: Node = new Node({
key: field,
id: '',
id: field,
value: dataSet.getFieldName(field),
});
cNode.x = position.x;
Expand Down
3 changes: 1 addition & 2 deletions packages/s2-core/src/interaction/base-interaction/hover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,7 @@ export class HoverEvent extends BaseEvent implements BaseEventImplement {

public bindCornerCellHover() {
this.spreadsheet.on(S2Event.CORNER_CELL_HOVER, (event: CanvasEvent) => {
const cell = this.spreadsheet.getCell(event.target);
this.showEllipsisTooltip(event, cell);
this.handleHeaderHover(event);
});
}
}
1 change: 1 addition & 0 deletions packages/s2-core/src/interaction/range-selection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ export class RangeSelection extends BaseEvent implements BaseEventImplement {
stateName: InteractionStateName.SELECTED,
});
} else {
interaction.removeIntercepts([InterceptType.HOVER]);
this.spreadsheet.store.set('lastClickedCell', cell);
}

Expand Down
12 changes: 7 additions & 5 deletions packages/s2-core/src/interaction/row-column-resize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import {
InterceptType,
MIN_CELL_HEIGHT,
MIN_CELL_WIDTH,
ResizeAreaEffect,
ResizeDirectionType,
ResizeType,
RESIZE_END_GUIDE_LINE_ID,
RESIZE_MASK_ID,
RESIZE_START_GUIDE_LINE_ID,
ResizeAreaEffect,
ResizeDirectionType,
ResizeType,
S2Event,
} from '../common/constant';
import type {
Expand Down Expand Up @@ -137,6 +137,7 @@ export class RowColumnResize extends BaseEvent implements BaseEventImplement {
['L', offsetX + width, guideLineMaxHeight],
]);
this.resizeStartPosition.offsetX = event.offsetX;
this.resizeStartPosition.clientX = event.clientX;
return;
}

Expand All @@ -149,6 +150,7 @@ export class RowColumnResize extends BaseEvent implements BaseEventImplement {
['L', guideLineMaxWidth, offsetY + height],
]);
this.resizeStartPosition.offsetY = event.offsetY;
this.resizeStartPosition.clientY = event.clientY;
}

private bindMouseDown() {
Expand Down Expand Up @@ -425,7 +427,7 @@ export class RowColumnResize extends BaseEvent implements BaseEventImplement {
guideLineStart: ResizeGuideLinePath,
guideLineEnd: ResizeGuideLinePath,
) {
let offsetX = originalEvent.offsetX - this.resizeStartPosition.offsetX;
let offsetX = originalEvent.clientX - this.resizeStartPosition.clientX;
if (resizeInfo.width + offsetX < MIN_CELL_WIDTH) {
// 禁止拖到最小宽度
offsetX = -(resizeInfo.width - MIN_CELL_WIDTH);
Expand All @@ -447,7 +449,7 @@ export class RowColumnResize extends BaseEvent implements BaseEventImplement {
guideLineStart: ResizeGuideLinePath,
guideLineEnd: ResizeGuideLinePath,
) {
let offsetY = originalEvent.offsetY - this.resizeStartPosition.offsetY;
let offsetY = originalEvent.clientY - this.resizeStartPosition.clientY;

if (resizeInfo.height + offsetY < MIN_CELL_HEIGHT) {
offsetY = -(resizeInfo.height - MIN_CELL_HEIGHT);
Expand Down
Loading

0 comments on commit 864ca68

Please sign in to comment.