From 4cdf08549e2994155cf5e07226c75768c117d521 Mon Sep 17 00:00:00 2001 From: fangsmile <892739385@qq.com> Date: Fri, 15 Nov 2024 18:55:23 +0800 Subject: [PATCH 1/2] fix: when up on canvas blank area not drag position rightly #2831 --- packages/vtable/src/event/helper.ts | 36 +++++++++++++++++++ .../src/event/listener/container-dom.ts | 35 +++--------------- .../vtable/src/event/listener/table-group.ts | 29 ++------------- packages/vtable/src/state/cell-move/index.ts | 2 +- 4 files changed, 45 insertions(+), 57 deletions(-) create mode 100644 packages/vtable/src/event/helper.ts diff --git a/packages/vtable/src/event/helper.ts b/packages/vtable/src/event/helper.ts new file mode 100644 index 000000000..2eaef2184 --- /dev/null +++ b/packages/vtable/src/event/helper.ts @@ -0,0 +1,36 @@ +import { TABLE_EVENT_TYPE } from '../core/TABLE_EVENT_TYPE'; +import type { ListTableAPI } from '../ts-types'; +import type { BaseTableAPI } from '../ts-types/base-table'; + +export function fireMoveColEventListeners(table: BaseTableAPI, endMoveColSuccess: boolean, e: Event) { + if ( + endMoveColSuccess && + table.stateManager.columnMove?.colSource !== -1 && + table.stateManager.columnMove?.rowSource !== -1 && + table.stateManager.columnMove?.colTarget !== -1 && + table.stateManager.columnMove?.rowTarget !== -1 + ) { + // 下面触发CHANGE_HEADER_POSITION 区别于pointerup + if ((table as any).hasListeners(TABLE_EVENT_TYPE.CHANGE_HEADER_POSITION)) { + table.fireListeners(TABLE_EVENT_TYPE.CHANGE_HEADER_POSITION, { + target: { col: table.stateManager.columnMove.colTarget, row: table.stateManager.columnMove.rowTarget }, + source: { + col: table.stateManager.columnMove.colSource, + row: table.stateManager.columnMove.rowSource + }, + event: e + }); + } + } else if (!endMoveColSuccess) { + if ((table as any).hasListeners(TABLE_EVENT_TYPE.CHANGE_HEADER_POSITION_FAIL)) { + table.fireListeners(TABLE_EVENT_TYPE.CHANGE_HEADER_POSITION_FAIL, { + target: { col: table.stateManager.columnMove.colTarget, row: table.stateManager.columnMove.rowTarget }, + source: { + col: table.stateManager.columnMove.colSource, + row: table.stateManager.columnMove.rowSource + }, + event: e + }); + } + } +} diff --git a/packages/vtable/src/event/listener/container-dom.ts b/packages/vtable/src/event/listener/container-dom.ts index caaba5a86..3e367d5d1 100644 --- a/packages/vtable/src/event/listener/container-dom.ts +++ b/packages/vtable/src/event/listener/container-dom.ts @@ -9,6 +9,7 @@ import type { EventManager } from '../event'; import { getPixelRatio } from '../../tools/pixel-ratio'; import { endResizeCol, endResizeRow } from './table-group'; import { isCellDisableSelect } from '../../state/select/is-cell-select-highlight'; +import { fireMoveColEventListeners } from '../helper'; export function bindContainerDomListener(eventManager: EventManager) { const table = eventManager.table; const stateManager = table.stateManager; @@ -572,36 +573,7 @@ export function bindContainerDomListener(eventManager: EventManager) { endResizeRow(table); } else if (stateManager.isMoveCol()) { const endMoveColSuccess = table.stateManager.endMoveCol(); - if ( - endMoveColSuccess && - table.stateManager.columnMove?.colSource !== -1 && - table.stateManager.columnMove?.rowSource !== -1 && - table.stateManager.columnMove?.colTarget !== -1 && - table.stateManager.columnMove?.rowTarget !== -1 - ) { - // 下面触发CHANGE_HEADER_POSITION 区别于pointerup - if ((table as any).hasListeners(TABLE_EVENT_TYPE.CHANGE_HEADER_POSITION)) { - table.fireListeners(TABLE_EVENT_TYPE.CHANGE_HEADER_POSITION, { - target: { col: table.stateManager.columnMove.colTarget, row: table.stateManager.columnMove.rowTarget }, - source: { - col: table.stateManager.columnMove.colSource, - row: table.stateManager.columnMove.rowSource - }, - event: e - }); - } - } else if (!endMoveColSuccess) { - if ((table as any).hasListeners(TABLE_EVENT_TYPE.CHANGE_HEADER_POSITION_FAIL)) { - table.fireListeners(TABLE_EVENT_TYPE.CHANGE_HEADER_POSITION_FAIL, { - target: { col: table.stateManager.columnMove.colTarget, row: table.stateManager.columnMove.rowTarget }, - source: { - col: table.stateManager.columnMove.colSource, - row: table.stateManager.columnMove.rowSource - }, - event: e - }); - } - } + fireMoveColEventListeners(table, endMoveColSuccess, e); } else if (stateManager.isSelecting()) { if (table.stateManager.select?.ranges?.length) { const lastCol = table.stateManager.select.ranges[table.stateManager.select.ranges.length - 1].end.col; @@ -637,6 +609,9 @@ export function bindContainerDomListener(eventManager: EventManager) { endResizeCol(table); } else if (stateManager.interactionState === 'grabing' && stateManager.isResizeRow()) { endResizeRow(table); + } else if (stateManager.isMoveCol()) { + const endMoveColSuccess = table.stateManager.endMoveCol(); + fireMoveColEventListeners(table, endMoveColSuccess, e); } }; eventManager.globalEventListeners.push({ diff --git a/packages/vtable/src/event/listener/table-group.ts b/packages/vtable/src/event/listener/table-group.ts index 0e2215c89..b1364fbad 100644 --- a/packages/vtable/src/event/listener/table-group.ts +++ b/packages/vtable/src/event/listener/table-group.ts @@ -23,6 +23,7 @@ import { getCellMergeInfo } from '../../scenegraph/utils/get-cell-merge'; import type { CheckBox, CheckboxAttributes, Radio } from '@visactor/vrender-components'; import { ResizeColumnHotSpotSize } from '../../tools/global'; import { handleWhell } from '../scroll'; +import { fireMoveColEventListeners } from '../helper'; export function bindTableGroupListener(eventManager: EventManager) { const table = eventManager.table; const stateManager = table.stateManager; @@ -597,33 +598,9 @@ export function bindTableGroupListener(eventManager: EventManager) { } else if (stateManager.isResizeRow()) { endResizeRow(table); } else if (stateManager.isMoveCol()) { - const eventArgsSet: SceneEvent = getCellEventArgsSet(e); + // const eventArgsSet: SceneEvent = getCellEventArgsSet(e); const endMoveColSuccess = table.stateManager.endMoveCol(); - if ( - endMoveColSuccess && - eventArgsSet.eventArgs && - (table as any).hasListeners(TABLE_EVENT_TYPE.CHANGE_HEADER_POSITION) - ) { - table.fireListeners(TABLE_EVENT_TYPE.CHANGE_HEADER_POSITION, { - target: { col: eventArgsSet.eventArgs.col, row: eventArgsSet.eventArgs.row }, - source: { - col: table.stateManager.columnMove.colSource, - row: table.stateManager.columnMove.rowSource - }, - event: e.nativeEvent - }); - } else if (!endMoveColSuccess) { - if ((table as any).hasListeners(TABLE_EVENT_TYPE.CHANGE_HEADER_POSITION_FAIL)) { - table.fireListeners(TABLE_EVENT_TYPE.CHANGE_HEADER_POSITION_FAIL, { - target: { col: table.stateManager.columnMove.colTarget, row: table.stateManager.columnMove.rowTarget }, - source: { - col: table.stateManager.columnMove.colSource, - row: table.stateManager.columnMove.rowSource - }, - event: e - }); - } - } + fireMoveColEventListeners(table, endMoveColSuccess, e.nativeEvent); } else if (stateManager.isSelecting()) { table.stateManager.endSelectCells(); if (table.stateManager.isFillHandle()) { diff --git a/packages/vtable/src/state/cell-move/index.ts b/packages/vtable/src/state/cell-move/index.ts index c36392c40..be41f3dbd 100644 --- a/packages/vtable/src/state/cell-move/index.ts +++ b/packages/vtable/src/state/cell-move/index.ts @@ -282,9 +282,9 @@ export function endMoveCol(state: StateManager): boolean { return false; } } + state.columnMove.moving = false; setTimeout(() => { //触发事件 CHANGE_HEADER_POSITION 还需要用到这些值 所以延迟清理 - state.columnMove.moving = false; delete state.columnMove.colSource; delete state.columnMove.rowSource; delete state.columnMove.colTarget; From 64b4c60a09d278ad8a149be882bcd88455f26aea Mon Sep 17 00:00:00 2001 From: fangsmile <892739385@qq.com> Date: Fri, 15 Nov 2024 18:55:37 +0800 Subject: [PATCH 2/2] docs: update changlog of rush --- .../2831-bug-drag-row-error_2024-11-15-10-55.json | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 common/changes/@visactor/vtable/2831-bug-drag-row-error_2024-11-15-10-55.json diff --git a/common/changes/@visactor/vtable/2831-bug-drag-row-error_2024-11-15-10-55.json b/common/changes/@visactor/vtable/2831-bug-drag-row-error_2024-11-15-10-55.json new file mode 100644 index 000000000..e7289a59a --- /dev/null +++ b/common/changes/@visactor/vtable/2831-bug-drag-row-error_2024-11-15-10-55.json @@ -0,0 +1,11 @@ +{ + "changes": [ + { + "comment": "fix: when up on canvas blank area not drag position rightly #2831\n\n", + "type": "none", + "packageName": "@visactor/vtable" + } + ], + "packageName": "@visactor/vtable", + "email": "892739385@qq.com" +} \ No newline at end of file