Skip to content

Commit

Permalink
feat: 支持resize最右侧column (#1611)
Browse files Browse the repository at this point in the history
* feat: 支持resize最右侧column

* fix: 添加testing-library/dom dep

* fix: npm源

* fix: npm源

* fix: 切换成dispatchEvent

* fix: testcase fix

Co-authored-by: owen.wjh <[email protected]>
  • Loading branch information
serializedowen and owen.wjh authored Jul 27, 2022
1 parent 8f13911 commit f63bfa2
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 3 deletions.
36 changes: 36 additions & 0 deletions packages/s2-core/__tests__/spreadsheet/table-sheet-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ const options: S2Options = {
};

describe('TableSheet normal spec', () => {

test('scrollWithAnimation with duration and callback', async () => {
const s2 = new TableSheet(getContainer(), dataCfg, options);
s2.render();
Expand Down Expand Up @@ -151,6 +152,41 @@ describe('TableSheet normal spec', () => {
expect(firstColCell.shouldAddVerticalResizeArea()).toBe(true)
expect(firstColCell.getVerticalResizeAreaOffset()).toEqual({ x: 80, y: 0 })

s2.destroy();
});

test('should be able to resize last column', async () => {
const s2 = new TableSheet(getContainer(), dataCfg, options);
s2.render();

await sleep(30);

const { x, width, top } = s2.getCanvasElement().getBoundingClientRect()
s2.getCanvasElement().dispatchEvent(new MouseEvent('mousedown', {
clientX: x + width - 1,
clientY: top + 25,
}))


window.dispatchEvent(new MouseEvent('mousemove', {
clientX: x+ width + 100,
clientY: top + 25,

}))
await sleep(300);

window.dispatchEvent(new MouseEvent('mouseup', {
clientX: x + width + 100,
clientY: top + 25
}))

await sleep(300);

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

expect(lastColumnCell.getMeta().width).toBe(199)
});


});
8 changes: 5 additions & 3 deletions packages/s2-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,15 @@
"lodash": "^4.17.21"
},
"devDependencies": {
"csstype": "^3.0.11",
"@testing-library/dom": "^8.16.0",
"@types/d3-interpolate": "^3.0.1",
"@types/d3-timer": "^3.0.0",
"csstype": "^3.0.11",

"d3-dsv": "^1.1.1",
"tinycolor2": "^1.4.2",
"inquirer": "^8.2.0",
"inquirer-autocomplete-prompt": "^2.0.0"
"inquirer-autocomplete-prompt": "^2.0.0",
"tinycolor2": "^1.4.2"
},
"sideEffects": [
"*.css",
Expand Down
17 changes: 17 additions & 0 deletions packages/s2-core/src/interaction/event-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,23 @@ export class EventController {

if (this.isResizeArea(event)) {
this.spreadsheet.emit(S2Event.LAYOUT_RESIZE_MOUSE_DOWN, event);

// 仅捕获在canvas之外触发的事件 https://github.com/antvis/S2/issues/1592
const resizeMouseMoveCapture = (mouseEvent: MouseEvent) => {
if (!this.spreadsheet.getCanvasElement()) return false;
if (this.spreadsheet.getCanvasElement() !== mouseEvent.target) {

event.clientX = mouseEvent.clientX;
event.clientY = mouseEvent.clientY;
event.originalEvent = mouseEvent
this.spreadsheet.emit(S2Event.LAYOUT_RESIZE_MOUSE_MOVE, event);
}
}

window.addEventListener('mousemove', resizeMouseMoveCapture);
window.addEventListener('mouseup', () => {
window.removeEventListener('mousemove', resizeMouseMoveCapture)
}, { once: true })
return;
}

Expand Down

1 comment on commit f63bfa2

@vercel
Copy link

@vercel vercel bot commented on f63bfa2 Jul 27, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

antvis-s2 – ./s2-site

antvis-s2.vercel.app
antvis-s2-git-master-antv-s2.vercel.app
antvis-s2-antv-s2.vercel.app

Please sign in to comment.