Skip to content

Commit

Permalink
Merge pull request #778 from VisActor/771-bug-edit-cell-bug
Browse files Browse the repository at this point in the history
771 bug edit cell bug
  • Loading branch information
fangsmile authored Dec 21, 2023
2 parents f6dd274 + b4693bb commit 83d65a2
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 59 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"changes": [
{
"comment": "fix: edit bug #771\n\n",
"type": "none",
"packageName": "@visactor/vtable"
}
],
"packageName": "@visactor/vtable",
"email": "[email protected]"
}
4 changes: 2 additions & 2 deletions packages/vtable/examples/list/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const generatePersons = count => {
};

export function createTable() {
const records = generatePersons(1000);
const records = generatePersons(1000000);
const columns: VTable.ColumnsDefine = [
{
field: '',
Expand Down Expand Up @@ -316,7 +316,7 @@ export function createTable() {
bottomFrozenRowCount: 2,
rightFrozenColCount: 2,
overscrollBehavior: 'none',
// autoWrapText: true,
autoWrapText: true,
heightMode: 'autoHeight'
// widthMode: 'adaptive'
};
Expand Down
12 changes: 4 additions & 8 deletions packages/vtable/src/edit/edit-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,6 @@ export class EditManeger {
this.startEditCell(col, row);
}
});
document.body.addEventListener('pointerdown', (e: PointerEvent) => {
const target = e.target;
if (this.editingEditor && !this.editingEditor.targetIsOnEditor(target as HTMLElement)) {
this.completeEdit();
}
});

handler.on(this.table.getElement(), 'wheel', (e: WheelEvent) => {
this.completeEdit();
Expand Down Expand Up @@ -86,8 +80,10 @@ export class EditManeger {
);
}
}
completeEdit() {
if (this.editingEditor) {
/** 如果是事件触发调用该接口 请传入原始事件对象 将判断事件对象是否在编辑器本身上面 来处理是否结束编辑 */
completeEdit(e?: any) {
const target = e?.target;
if (this.editingEditor && (!target || (target && !this.editingEditor.targetIsOnEditor(target as HTMLElement)))) {
const changedValue = this.editingEditor.getValue();
(this.table as ListTableAPI).changeCellValue(this.editCell.col, this.editCell.row, changedValue);
this.editingEditor.exit();
Expand Down
19 changes: 2 additions & 17 deletions packages/vtable/src/event/listener/scroll-bar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,7 @@ export function bindScrollBarListener(eventManager: EventManager) {
if (stateManager.interactionState !== InteractionState.scrolling) {
stateManager.updateInteractionState(InteractionState.scrolling);
}
const eventArgsSet: SceneEvent = getCellEventArgsSet(e);
if (
scenegraph.table.stateManager.menu.isShow &&
(eventArgsSet.eventArgs?.target as any) !== scenegraph.table.stateManager.residentHoverIcon?.icon
) {
scenegraph.table.stateManager.hideMenu();
}

scenegraph.table.stateManager.hideMenu();
(scenegraph.table as ListTableAPI).editorManager?.completeEdit();
});
scenegraph.component.vScrollBar.addEventListener('pointerup', () => {
Expand All @@ -64,15 +57,7 @@ export function bindScrollBarListener(eventManager: EventManager) {
if (stateManager.interactionState !== InteractionState.scrolling) {
stateManager.updateInteractionState(InteractionState.scrolling);
}

const eventArgsSet: SceneEvent = getCellEventArgsSet(e);
if (
scenegraph.table.stateManager.menu.isShow &&
(eventArgsSet.eventArgs?.target as any) !== scenegraph.table.stateManager.residentHoverIcon?.icon
) {
scenegraph.table.stateManager.hideMenu();
}

scenegraph.table.stateManager.hideMenu();
(scenegraph.table as ListTableAPI).editorManager?.completeEdit();
});
scenegraph.component.hScrollBar.addEventListener('pointerup', () => {
Expand Down
20 changes: 14 additions & 6 deletions packages/vtable/src/event/listener/table-group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export function bindTableGroupListener(eventManager: EventManager) {
const table = eventManager.table;
const stateManager = table.stateManager;

// 有被阻止冒泡的场景 就触发不到这里的事件了
document.body.addEventListener('pointerdown', e => {
console.log('body pointerdown');
table.eventManager.LastBodyPointerXY = { x: e.x, y: e.y };
Expand Down Expand Up @@ -280,7 +281,13 @@ export function bindTableGroupListener(eventManager: EventManager) {
});
}
});
/**
* 两种场景会触发这里的pointerupoutside
* 1. 鼠标down和up的场景树节点不一样
* 2. 点击到非stage的(非canvas) 其他dom节点
*/
table.scenegraph.tableGroup.addEventListener('pointerupoutside', (e: FederatedPointerEvent) => {
console.log('pointerupoutside');
const eventArgsSet: SceneEvent = getCellEventArgsSet(e);
if (stateManager.menu.isShow && (eventArgsSet.eventArgs?.target as any) !== stateManager.residentHoverIcon?.icon) {
setTimeout(() => {
Expand Down Expand Up @@ -330,9 +337,7 @@ export function bindTableGroupListener(eventManager: EventManager) {
}
}
}
if ((table as ListTableAPI).editorManager) {
(table as ListTableAPI).editorManager.completeEdit();
}
(table as ListTableAPI).editorManager?.completeEdit(e.nativeEvent);
stateManager.updateInteractionState(InteractionState.default);
eventManager.dealTableHover();
//点击到表格外部不需要取消选中状态
Expand Down Expand Up @@ -362,10 +367,12 @@ export function bindTableGroupListener(eventManager: EventManager) {
table.scenegraph.updateChartState(null);
}
// 处理menu
if (stateManager.menu.isShow && (eventArgsSet.eventArgs?.target as any) !== stateManager.residentHoverIcon?.icon) {
if ((eventArgsSet.eventArgs?.target as any) !== stateManager.residentHoverIcon?.icon) {
// 点击在menu外,且不是下拉菜单的icon,移除menu
stateManager.hideMenu();
}
(table as ListTableAPI).editorManager?.completeEdit(e.nativeEvent);

const hitIcon = (eventArgsSet?.eventArgs?.target as any)?.role?.startsWith('icon')
? eventArgsSet.eventArgs.target
: undefined;
Expand Down Expand Up @@ -601,12 +608,13 @@ export function bindTableGroupListener(eventManager: EventManager) {
}
}
});
// click outside
// stage 的pointerdown监听 如果点击在表格内部 是会被阻止点的tableGroup的pointerdown 监听有stopPropagation
table.scenegraph.stage.addEventListener('pointerdown', (e: FederatedPointerEvent) => {
const eventArgsSet: SceneEvent = getCellEventArgsSet(e);
if (stateManager.menu.isShow && (eventArgsSet.eventArgs?.target as any) !== stateManager.residentHoverIcon?.icon) {
if ((eventArgsSet.eventArgs?.target as any) !== stateManager.residentHoverIcon?.icon) {
stateManager.hideMenu();
}
(table as ListTableAPI).editorManager?.completeEdit(e.nativeEvent);
});
// click outside
table.scenegraph.stage.addEventListener('pointertap', (e: FederatedPointerEvent) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/vtable/src/scenegraph/icon/icon-update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ export function resetResidentHoverIcon(col: number, row: number, scene: Scenegra
(icon: Icon) => icon.attribute.funcType === IconFuncTypeEnum.dropDown,
// dealer
(icon: Icon) => {
icon.setAttribute('visibleTime', (icon as any).oldVisibleTime);
(icon as any).oldVisibleTime && icon.setAttribute('visibleTime', (icon as any).oldVisibleTime);
icon.setAttribute('opacity', icon.attribute.visibleTime === 'always' ? 1 : 0);
},
scene
Expand Down
17 changes: 9 additions & 8 deletions packages/vtable/src/state/select/update-position.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ export function updateSelectPosition(
start: { col, row: cellRange.start.row },
end: { col: table.colCount - 1, row: cellRange.end.row }
});
} else {
} else if (col >= 0 && row >= 0) {
state.select.ranges.push({
start: { col, row },
end: { col, row }
Expand All @@ -143,13 +143,14 @@ export function updateSelectPosition(
cellPos.col = col;
cellPos.row = row;
// scenegraph.setCellNormalStyle(col, row);
const currentRange = state.select.ranges[state.select.ranges.length - 1];
scenegraph.updateCellSelectBorder(
currentRange.start.col,
currentRange.start.row,
currentRange.end.col,
currentRange.end.row
);
const currentRange = state.select.ranges?.[state.select.ranges.length - 1];
currentRange &&
scenegraph.updateCellSelectBorder(
currentRange.start.col,
currentRange.start.row,
currentRange.end.col,
currentRange.end.row
);
}
} else if (interactionState === InteractionState.grabing && !table.stateManager.isResizeCol()) {
// 可能有cellPosStart从-1开始grabing的情况
Expand Down
36 changes: 19 additions & 17 deletions packages/vtable/src/state/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -841,23 +841,25 @@ export class StateManager {
}

hideMenu() {
this.table.fireListeners(TABLE_EVENT_TYPE.DROPDOWN_MENU_CLEAR, null);
this.table.fireListeners(TABLE_EVENT_TYPE.HIDE_MENU, null);
this.menu.isShow = false;
this.table.scenegraph.component.menu.detach();
if (this.residentHoverIcon) {
this.table.scenegraph.setIconNormalStyle(
this.residentHoverIcon.icon,
this.residentHoverIcon.col,
this.residentHoverIcon.row
);
// this.residentHoverIcon.icon.setAttribute('visibleTime', (this.residentHoverIcon.icon as any).oldVisibleTime);
// this.residentHoverIcon.icon.setAttribute(
// 'opacity',
// this.residentHoverIcon.icon.attribute.visibleTime === 'always' ? 1 : 0
// );
this.table.scenegraph.resetResidentHoverIcon(this.residentHoverIcon.col, this.residentHoverIcon.row);
this.residentHoverIcon = null;
if (this.menu.isShow) {
this.table.fireListeners(TABLE_EVENT_TYPE.DROPDOWN_MENU_CLEAR, null);
this.table.fireListeners(TABLE_EVENT_TYPE.HIDE_MENU, null);
this.menu.isShow = false;
this.table.scenegraph.component.menu.detach();
if (this.residentHoverIcon) {
this.table.scenegraph.setIconNormalStyle(
this.residentHoverIcon.icon,
this.residentHoverIcon.col,
this.residentHoverIcon.row
);
// this.residentHoverIcon.icon.setAttribute('visibleTime', (this.residentHoverIcon.icon as any).oldVisibleTime);
// this.residentHoverIcon.icon.setAttribute(
// 'opacity',
// this.residentHoverIcon.icon.attribute.visibleTime === 'always' ? 1 : 0
// );
this.table.scenegraph.resetResidentHoverIcon(this.residentHoverIcon.col, this.residentHoverIcon.row);
this.residentHoverIcon = null;
}
}
}

Expand Down

0 comments on commit 83d65a2

Please sign in to comment.