Skip to content

Commit

Permalink
Merge pull request #761 from VisActor/760-bug-dropdown_menu_click
Browse files Browse the repository at this point in the history
760 bug dropdown menu click
  • Loading branch information
fangsmile authored Dec 19, 2023
2 parents 14f3447 + 01872d0 commit bd132ef
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 23 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"changes": [
{
"comment": "fix: dropdown_menu_click trigger #760\n\n",
"type": "none",
"packageName": "@visactor/vtable"
}
],
"packageName": "@visactor/vtable",
"email": "[email protected]"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"changes": [
{
"comment": "fix: dblclick occur error #758\n\n",
"type": "none",
"packageName": "@visactor/vtable"
}
],
"packageName": "@visactor/vtable",
"email": "[email protected]"
}
5 changes: 4 additions & 1 deletion packages/vtable/examples/interactive/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,10 @@ export function createTable() {
// instance.showDropDownMenu(col, row, {
// content: ['a', 'b']
// });

instance.on('dropdown_menu_click', args => {
console.log('dropdown_menu_click', args);
instance.setDropDownMenuHighlight([args]);
});
// 只为了方便控制太调试用,不要拷贝
window.tableInstance = instance;
}
33 changes: 18 additions & 15 deletions packages/vtable/src/core/BaseTable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2784,21 +2784,24 @@ export abstract class BaseTable extends EventTarget implements BaseTableAPI {
}
/** 获取单元格的基本信息 目前主要组织单元格信息给事件传递给用户的参数使用 */
getCellInfo(col: number, row: number): Omit<MousePointerCellEvent, 'target'> {
const colDef = this.isHeader(col, row) ? this.getHeaderDefine(col, row) : this.getBodyColumnDefine(col, row);
return {
col,
row,
field: this.getHeaderField(col, row),
cellHeaderPaths: this.internalProps.layoutMap.getCellHeaderPaths(col, row),
title: colDef?.title,
cellType: colDef?.cellType ? (typeof colDef.cellType === 'string' ? colDef.cellType : 'progressbar') : 'text',
originData: this.getCellOriginRecord(col, row),
cellRange: this.getCellRangeRelativeRect({ col, row }),
value: this.getCellValue(col, row),
dataValue: this.getCellOriginValue(col, row),
cellLocation: this.getCellLocation(col, row),
scaleRatio: this.canvas.getBoundingClientRect().width / this.canvas.offsetWidth
};
if (col >= 0 && row >= 0) {
const colDef = this.isHeader(col, row) ? this.getHeaderDefine(col, row) : this.getBodyColumnDefine(col, row);
return {
col,
row,
field: this.getHeaderField(col, row),
cellHeaderPaths: this.internalProps.layoutMap.getCellHeaderPaths(col, row),
title: colDef?.title,
cellType: colDef?.cellType ? (typeof colDef.cellType === 'string' ? colDef.cellType : 'progressbar') : 'text',
originData: this.getCellOriginRecord(col, row),
cellRange: this.getCellRangeRelativeRect({ col, row }),
value: this.getCellValue(col, row),
dataValue: this.getCellOriginValue(col, row),
cellLocation: this.getCellLocation(col, row),
scaleRatio: this.canvas.getBoundingClientRect().width / this.canvas.offsetWidth
};
}
return undefined;
}
/** @private */
_hasField(field: FieldDef, col: number, row: number): boolean {
Expand Down
23 changes: 16 additions & 7 deletions packages/vtable/src/event/listener/table-group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,9 @@ export function bindTableGroupListener(eventManager: EventManager) {
table.scenegraph.tableGroup.addEventListener('pointerupoutside', (e: FederatedPointerEvent) => {
const eventArgsSet: SceneEvent = getCellEventArgsSet(e);
if (stateManager.menu.isShow && (eventArgsSet.eventArgs?.target as any) !== stateManager.residentHoverIcon?.icon) {
stateManager.hideMenu();
setTimeout(() => {
stateManager.menu.isShow && stateManager.hideMenu();
}, 0);
}
// 同pointerup中的逻辑
if (stateManager.isResizeCol()) {
Expand Down Expand Up @@ -721,13 +723,20 @@ function endResizeCol(table: BaseTableAPI) {

function dblclickHandler(e: FederatedPointerEvent, table: BaseTableAPI) {
const eventArgsSet: SceneEvent = getCellEventArgsSet(e);
const bounds = eventArgsSet.eventArgs.targetCell.globalAABBBounds;
const { col, row } = eventArgsSet.eventArgs;
let col = -1;
let row = -1;
if (eventArgsSet.eventArgs) {
col = eventArgsSet.eventArgs.col;
row = eventArgsSet.eventArgs.row;
}
const value = table.getCellValue(col, row);
table.internalProps.focusControl.setFocusRect(
new Rect(bounds.x1 + table.scrollLeft, bounds.y1 + table.scrollTop, bounds.x2 - bounds.x1, bounds.y2 - bounds.y1),
value
);

const bounds = eventArgsSet.eventArgs?.targetCell?.globalAABBBounds;
bounds &&
table.internalProps.focusControl.setFocusRect(
new Rect(bounds.x1 + table.scrollLeft, bounds.y1 + table.scrollTop, bounds.x2 - bounds.x1, bounds.y2 - bounds.y1),
value
);
if ((table as any).hasListeners(TABLE_EVENT_TYPE.DBLCLICK_CELL)) {
const cellInfo = table.getCellInfo(col, row);
let icon;
Expand Down

0 comments on commit bd132ef

Please sign in to comment.