11import AbstractPlugin from 'shared/AbstractPlugin' ;
22import { requestNextAnimationFrame } from 'shared/utils' ;
33
4- const onMirrorCreated = Symbol ( 'onMirrorCreated' ) ;
5- const onMirrorDestroy = Symbol ( 'onMirrorDestroy' ) ;
6- const onDragOver = Symbol ( 'onDragOver' ) ;
7- const resize = Symbol ( 'resize' ) ;
4+ import {
5+ DragOverEvent ,
6+ DragOverContainerEvent ,
7+ isDragOverEvent ,
8+ } from '../../Draggable/DragEvent' ;
89
910/**
1011 * ResizeMirror default options
@@ -20,24 +21,17 @@ export const defaultOptions = {};
2021 * @extends AbstractPlugin
2122 */
2223export default class ResizeMirror extends AbstractPlugin {
24+ private lastWidth : number ;
25+ private lastHeight : number ;
26+ private mirror : HTMLElement | null ;
2327 /**
2428 * ResizeMirror constructor.
2529 * @constructs ResizeMirror
2630 * @param {Draggable } draggable - Draggable instance
2731 */
28- constructor ( draggable ) {
32+ constructor ( draggable : any ) {
2933 super ( draggable ) ;
3034
31- /**
32- * ResizeMirror options
33- * @property {Object } options
34- * @type {Object }
35- */
36- this . options = {
37- ...defaultOptions ,
38- ...this . getOptions ( ) ,
39- } ;
40-
4135 /**
4236 * ResizeMirror remembers the last width when resizing the mirror
4337 * to avoid additional writes to the DOM
@@ -58,30 +52,30 @@ export default class ResizeMirror extends AbstractPlugin {
5852 */
5953 this . mirror = null ;
6054
61- this [ onMirrorCreated ] = this [ onMirrorCreated ] . bind ( this ) ;
62- this [ onMirrorDestroy ] = this [ onMirrorDestroy ] . bind ( this ) ;
63- this [ onDragOver ] = this [ onDragOver ] . bind ( this ) ;
55+ this . onMirrorCreated = this . onMirrorCreated . bind ( this ) ;
56+ this . onMirrorDestroy = this . onMirrorDestroy . bind ( this ) ;
57+ this . onDragOver = this . onDragOver . bind ( this ) ;
6458 }
6559
6660 /**
6761 * Attaches plugins event listeners
6862 */
6963 attach ( ) {
7064 this . draggable
71- . on ( 'mirror:created' , this [ onMirrorCreated ] )
72- . on ( 'drag:over' , this [ onDragOver ] )
73- . on ( 'drag:over:container' , this [ onDragOver ] ) ;
65+ . on ( 'mirror:created' , this . onMirrorCreated )
66+ . on ( 'drag:over' , this . onDragOver )
67+ . on ( 'drag:over:container' , this . onDragOver ) ;
7468 }
7569
7670 /**
7771 * Detaches plugins event listeners
7872 */
7973 detach ( ) {
8074 this . draggable
81- . off ( 'mirror:created' , this [ onMirrorCreated ] )
82- . off ( 'mirror:destroy' , this [ onMirrorDestroy ] )
83- . off ( 'drag:over' , this [ onDragOver ] )
84- . off ( 'drag:over:container' , this [ onDragOver ] ) ;
75+ . off ( 'mirror:created' , this . onMirrorCreated )
76+ . off ( 'mirror:destroy' , this . onMirrorDestroy )
77+ . off ( 'drag:over' , this . onDragOver )
78+ . off ( 'drag:over:container' , this . onDragOver ) ;
8579 }
8680
8781 /**
@@ -97,7 +91,7 @@ export default class ResizeMirror extends AbstractPlugin {
9791 * @param {MirrorCreatedEvent } mirrorEvent
9892 * @private
9993 */
100- [ onMirrorCreated ] ( { mirror} ) {
94+ private onMirrorCreated ( { mirror} : any ) {
10195 this . mirror = mirror ;
10296 }
10397
@@ -106,7 +100,7 @@ export default class ResizeMirror extends AbstractPlugin {
106100 * @param {MirrorDestroyEvent } mirrorEvent
107101 * @private
108102 */
109- [ onMirrorDestroy ] ( ) {
103+ private onMirrorDestroy ( ) {
110104 this . mirror = null ;
111105 }
112106
@@ -115,25 +109,32 @@ export default class ResizeMirror extends AbstractPlugin {
115109 * @param {DragOverEvent | DragOverContainer } dragEvent
116110 * @private
117111 */
118- [ onDragOver ] ( dragEvent ) {
119- this [ resize ] ( dragEvent ) ;
112+ private onDragOver ( dragEvent : DragOverEvent | DragOverContainerEvent ) {
113+ this . resize ( dragEvent ) ;
120114 }
121115
122116 /**
123117 * Resize function for
124118 * @param {DragOverEvent | DragOverContainer } dragEvent
125119 * @private
126120 */
127- [ resize ] ( { overContainer , over } ) {
121+ private resize ( dragEvent : DragOverEvent | DragOverContainerEvent ) {
128122 requestAnimationFrame ( ( ) => {
129- if ( ! this . mirror . parentNode ) {
123+ let over : HTMLElement | null = null ;
124+ const { overContainer} = dragEvent ;
125+
126+ if ( this . mirror == null || this . mirror . parentNode == null ) {
130127 return ;
131128 }
132129
133130 if ( this . mirror . parentNode !== overContainer ) {
134131 overContainer . appendChild ( this . mirror ) ;
135132 }
136133
134+ if ( isDragOverEvent ( dragEvent ) ) {
135+ over = dragEvent . over ;
136+ }
137+
137138 const overElement =
138139 over ||
139140 this . draggable . getDraggableElementsForContainer ( overContainer ) [ 0 ] ;
@@ -146,8 +147,9 @@ export default class ResizeMirror extends AbstractPlugin {
146147 const overRect = overElement . getBoundingClientRect ( ) ;
147148
148149 if (
149- this . lastHeight === overRect . height &&
150- this . lastWidth === overRect . width
150+ this . mirror == null ||
151+ ( this . lastHeight === overRect . height &&
152+ this . lastWidth === overRect . width )
151153 ) {
152154 return ;
153155 }
0 commit comments