e-virt-table
Version:
A powerful data table based on canvas. You can use it as data grid、Microsoft Excel or Google sheets. It supports virtual scroll、cell edit etc.
96 lines • 3.08 kB
JavaScript
export default class EventBrowser {
constructor(ctx) {
Object.defineProperty(this, "eventTasks", {
enumerable: true,
configurable: true,
writable: true,
value: new Map()
});
Object.defineProperty(this, "ctx", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
this.ctx = ctx;
this.init();
}
init() {
this.bind(window, 'resize', this.handleResize.bind(this));
this.bind(window, 'mouseup', this.handleMouseUp.bind(this));
this.bind(window, 'mousemove', this.handleMousemove.bind(this));
this.bind(this.ctx.stageElement, 'click', this.handleClick.bind(this));
this.bind(window, 'keydown', this.handleKeydown.bind(this));
this.bind(this.ctx.stageElement, 'wheel', this.handleWheel.bind(this));
this.bind(this.ctx.stageElement, 'contextmenu', this.handleContextMenu.bind(this));
this.bind(this.ctx.stageElement, 'mousedown', this.handleMouseDown.bind(this));
this.bind(this.ctx.stageElement, 'dblclick', this.handleDblclick.bind(this));
this.bind(this.ctx.stageElement, 'mouseover', this.handleMouseover.bind(this));
this.bind(this.ctx.stageElement, 'mouseout', this.handleMouseout.bind(this));
}
destroy() {
this.eventTasks.forEach((fn, event) => {
this.unbind(window, event, fn);
});
this.eventTasks.clear();
}
handleResize(e) {
this.ctx.emit('resetHeader', e);
this.ctx.emit('resize', e);
}
handleMouseDown(e) {
const _e = e;
if (_e.button === 0) {
this.ctx.mousedown = true;
}
this.ctx.emit('mousedown', e);
}
handleMousemove(e) {
this.ctx.emit('mousemove', e);
}
handleMouseUp(e) {
const _e = e;
if (_e.button === 0) {
this.ctx.mousedown = false;
}
this.ctx.emit('mouseup', e);
}
handleClick(e) {
this.ctx.emit('click', e);
}
handleKeydown(e) {
const { ENABLE_KEYBOARD } = this.ctx.config;
if (!ENABLE_KEYBOARD)
return;
if (!this.ctx.isTarget()) {
return;
}
this.ctx.emit('keydown', e);
}
handleWheel(e) {
this.ctx.emit('wheel', e);
}
handleContextMenu(e) {
this.ctx.emit('contextMenu', e);
}
handleMouseover(e) {
this.ctx.isInsideTargetContainer = true;
this.ctx.emit('mouseover', e);
}
handleMouseout(e) {
this.ctx.isInsideTargetContainer = false;
this.ctx.emit('mouseout', e);
}
handleDblclick(e) {
this.ctx.emit('dblclick', e);
}
bind(target, name, fn, options) {
target.addEventListener(name, fn, options);
this.eventTasks.set(name, fn);
}
unbind(target, name, fn) {
target.removeEventListener(name, fn);
this.eventTasks.delete(name);
}
}
//# sourceMappingURL=EventBrowser.js.map