add selection by mouse over

This commit is contained in:
Sergey Krylov 2022-07-11 21:04:39 +05:00
parent 2b053a9d47
commit 09ff3a751d
2 changed files with 26 additions and 1 deletions

View File

@ -14,13 +14,16 @@ export class Table extends ExcelComponent {
static className = 'excel__table';
private selection: TableSelection;
private isMouseDowned: boolean;
constructor($root: Dom, options: ComponentOptionsType) {
super($root, {
...options,
name: 'Table',
eventListeners: ['mousedown', 'keydown', 'input'],
eventListeners: ['mousedown', 'keydown', 'input', 'mouseover', 'mouseup'],
});
this.isMouseDowned = false;
}
toHTML(): string {
@ -123,6 +126,7 @@ export class Table extends ExcelComponent {
};
onMousedown(event: MouseEvent) {
this.isMouseDowned = true;
selectHandler(event, this.selection, this.emitSelectCallback.bind(this));
this.resizeTable(event);
}
@ -134,4 +138,12 @@ export class Table extends ExcelComponent {
onInput(event: InputEvent) {
this.updateCurrentText((event.target as HTMLElement).innerText);
}
onMouseover(event: MouseEvent) {
this.isMouseDowned && selectHandler(event, this.selection);
}
onMouseup() {
this.isMouseDowned = false;
}
}

View File

@ -8,10 +8,17 @@ export function selectHandler(event: MouseEvent | KeyboardEvent, selection: Tabl
onMouseDownHandler();
break;
}
case 'keydown': {
onKeyDownHandler();
break;
}
case 'mouseover': {
onMouseOverHandler();
break;
}
default: break;
}
@ -99,4 +106,10 @@ export function selectHandler(event: MouseEvent | KeyboardEvent, selection: Tabl
selection.selectByCellId({ row, col });
}
function onMouseOverHandler() {
if (selection.current.$el) {
selection.selectTo($((event as any).toElement));
}
}
}