import EventSystem from './EventSystem'; export default class Mouse extends EventSystem{ constructor(container = window){ super() this.container = container; } handler(e) { switch(e.button){ case 0: this.emit('LeftDown',e); break; case 2: this.emit('RightDown',e); break; default: console.log('sss') break; } } dropHandler(event) { let data = event.dataTransfer.getData('MyObject'); this.emit('Drop', { event, data }); } droppable(droppable = true) { this.isDroppable = droppable; return this; } cancel(e) { e.preventDefault(); } listen(){ console.log(this) this.container.addEventListener('mousedown', this.handler.bind(this)); if(this.isDroppable) { this.container.addEventListener('dragover', this.cancel); this.container.addEventListener('drop', this.dropHandler.bind(this)); } return this; } }