1
1
import AbstractPlugin from 'shared/AbstractPlugin' ;
2
2
import { requestNextAnimationFrame } from 'shared/utils' ;
3
3
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' ;
8
9
9
10
/**
10
11
* ResizeMirror default options
@@ -20,24 +21,17 @@ export const defaultOptions = {};
20
21
* @extends AbstractPlugin
21
22
*/
22
23
export default class ResizeMirror extends AbstractPlugin {
24
+ private lastWidth : number ;
25
+ private lastHeight : number ;
26
+ private mirror : HTMLElement | null ;
23
27
/**
24
28
* ResizeMirror constructor.
25
29
* @constructs ResizeMirror
26
30
* @param {Draggable } draggable - Draggable instance
27
31
*/
28
- constructor ( draggable ) {
32
+ constructor ( draggable : any ) {
29
33
super ( draggable ) ;
30
34
31
- /**
32
- * ResizeMirror options
33
- * @property {Object } options
34
- * @type {Object }
35
- */
36
- this . options = {
37
- ...defaultOptions ,
38
- ...this . getOptions ( ) ,
39
- } ;
40
-
41
35
/**
42
36
* ResizeMirror remembers the last width when resizing the mirror
43
37
* to avoid additional writes to the DOM
@@ -58,30 +52,30 @@ export default class ResizeMirror extends AbstractPlugin {
58
52
*/
59
53
this . mirror = null ;
60
54
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 ) ;
64
58
}
65
59
66
60
/**
67
61
* Attaches plugins event listeners
68
62
*/
69
63
attach ( ) {
70
64
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 ) ;
74
68
}
75
69
76
70
/**
77
71
* Detaches plugins event listeners
78
72
*/
79
73
detach ( ) {
80
74
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 ) ;
85
79
}
86
80
87
81
/**
@@ -97,7 +91,7 @@ export default class ResizeMirror extends AbstractPlugin {
97
91
* @param {MirrorCreatedEvent } mirrorEvent
98
92
* @private
99
93
*/
100
- [ onMirrorCreated ] ( { mirror} ) {
94
+ private onMirrorCreated ( { mirror} : any ) {
101
95
this . mirror = mirror ;
102
96
}
103
97
@@ -106,7 +100,7 @@ export default class ResizeMirror extends AbstractPlugin {
106
100
* @param {MirrorDestroyEvent } mirrorEvent
107
101
* @private
108
102
*/
109
- [ onMirrorDestroy ] ( ) {
103
+ private onMirrorDestroy ( ) {
110
104
this . mirror = null ;
111
105
}
112
106
@@ -115,25 +109,32 @@ export default class ResizeMirror extends AbstractPlugin {
115
109
* @param {DragOverEvent | DragOverContainer } dragEvent
116
110
* @private
117
111
*/
118
- [ onDragOver ] ( dragEvent ) {
119
- this [ resize ] ( dragEvent ) ;
112
+ private onDragOver ( dragEvent : DragOverEvent | DragOverContainerEvent ) {
113
+ this . resize ( dragEvent ) ;
120
114
}
121
115
122
116
/**
123
117
* Resize function for
124
118
* @param {DragOverEvent | DragOverContainer } dragEvent
125
119
* @private
126
120
*/
127
- [ resize ] ( { overContainer , over } ) {
121
+ private resize ( dragEvent : DragOverEvent | DragOverContainerEvent ) {
128
122
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 ) {
130
127
return ;
131
128
}
132
129
133
130
if ( this . mirror . parentNode !== overContainer ) {
134
131
overContainer . appendChild ( this . mirror ) ;
135
132
}
136
133
134
+ if ( isDragOverEvent ( dragEvent ) ) {
135
+ over = dragEvent . over ;
136
+ }
137
+
137
138
const overElement =
138
139
over ||
139
140
this . draggable . getDraggableElementsForContainer ( overContainer ) [ 0 ] ;
@@ -146,8 +147,9 @@ export default class ResizeMirror extends AbstractPlugin {
146
147
const overRect = overElement . getBoundingClientRect ( ) ;
147
148
148
149
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 )
151
153
) {
152
154
return ;
153
155
}
0 commit comments