| 21 | // let count = 0; // TEST |
| 22 | |
| 23 | export class DDDroppable extends DDBaseImplement implements HTMLElementExtendOpt<DDDroppableOpt> { |
| 24 | |
| 25 | public accept: (el: HTMLElement) => boolean; |
| 26 | |
| 27 | constructor(public el: HTMLElement, public option: DDDroppableOpt = {}) { |
| 28 | super(); |
| 29 | // create var event binding so we can easily remove and still look like TS methods (unlike anonymous functions) |
| 30 | this._mouseEnter = this._mouseEnter.bind(this); |
| 31 | this._mouseLeave = this._mouseLeave.bind(this); |
| 32 | this.enable(); |
| 33 | this._setupAccept(); |
| 34 | } |
| 35 | |
| 36 | public on(event: 'drop' | 'dropover' | 'dropout', callback: (event: DragEvent) => void): void { |
| 37 | super.on(event, callback); |
| 38 | } |
| 39 | |
| 40 | public off(event: 'drop' | 'dropover' | 'dropout'): void { |
| 41 | super.off(event); |
| 42 | } |
| 43 | |
| 44 | public enable(): void { |
| 45 | if (this.disabled === false) return; |
| 46 | super.enable(); |
| 47 | this.el.classList.add('ui-droppable'); |
| 48 | this.el.classList.remove('ui-droppable-disabled'); |
| 49 | this.el.addEventListener('mouseenter', this._mouseEnter); |
| 50 | this.el.addEventListener('mouseleave', this._mouseLeave); |
| 51 | if (isTouch) { |
| 52 | this.el.addEventListener('pointerenter', pointerenter); |
| 53 | this.el.addEventListener('pointerleave', pointerleave); |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | public disable(forDestroy = false): void { |
| 58 | if (this.disabled === true) return; |
| 59 | super.disable(); |
| 60 | this.el.classList.remove('ui-droppable'); |
| 61 | if (!forDestroy) this.el.classList.add('ui-droppable-disabled'); |
| 62 | this.el.removeEventListener('mouseenter', this._mouseEnter); |
| 63 | this.el.removeEventListener('mouseleave', this._mouseLeave); |
| 64 | if (isTouch) { |
| 65 | this.el.removeEventListener('pointerenter', pointerenter); |
| 66 | this.el.removeEventListener('pointerleave', pointerleave); |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | public destroy(): void { |
| 71 | this.disable(true); |
| 72 | this.el.classList.remove('ui-droppable'); |
| 73 | this.el.classList.remove('ui-droppable-disabled'); |
| 74 | super.destroy(); |
| 75 | } |
| 76 | |
| 77 | public updateOption(opts: DDDroppableOpt): DDDroppable { |
| 78 | Object.keys(opts).forEach(key => this.option[key] = opts[key]); |
| 79 | this._setupAccept(); |
| 80 | return this; |
nothing calls this directly
no outgoing calls
no test coverage detected