3
3
* Copyright (c) 2017 - 2025 Vaadin Ltd.
4
4
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
*/
6
- import { eventInWindow , getMouseOrFirstTouchEvent } from './vaadin-dialog-utils.js' ;
6
+ import { DialogManager , eventInWindow , getMouseOrFirstTouchEvent } from './vaadin-dialog-utils.js' ;
7
+
7
8
/**
8
9
* @polymerMixin
9
10
*/
@@ -26,8 +27,10 @@ export const DialogResizableMixin = (superClass) =>
26
27
/** @protected */
27
28
ready ( ) {
28
29
super . ready ( ) ;
29
- this . _originalBounds = { } ;
30
- this . _originalMouseCoords = { } ;
30
+
31
+ // Get or create an instance of manager
32
+ this . __manager = DialogManager . create ( this ) ;
33
+
31
34
this . _resizeListeners = { start : { } , resize : { } , stop : { } } ;
32
35
this . _addResizeListeners ( ) ;
33
36
}
@@ -65,15 +68,12 @@ export const DialogResizableMixin = (superClass) =>
65
68
if ( e . button === 0 || e . touches ) {
66
69
e . preventDefault ( ) ;
67
70
68
- this . _originalBounds = this . $ . overlay . getBounds ( ) ;
69
- const event = getMouseOrFirstTouchEvent ( e ) ;
70
- this . _originalMouseCoords = { top : event . pageY , left : event . pageX } ;
71
71
window . addEventListener ( 'mousemove' , this . _resizeListeners . resize [ direction ] ) ;
72
72
window . addEventListener ( 'touchmove' , this . _resizeListeners . resize [ direction ] ) ;
73
73
window . addEventListener ( 'mouseup' , this . _resizeListeners . stop [ direction ] ) ;
74
74
window . addEventListener ( 'touchend' , this . _resizeListeners . stop [ direction ] ) ;
75
- this . $ . overlay . setBounds ( this . _originalBounds ) ;
76
- this . $ . overlay . setAttribute ( 'has-bounds-set' , '' ) ;
75
+
76
+ this . __manager . handleEvent ( e ) ;
77
77
}
78
78
}
79
79
@@ -86,34 +86,38 @@ export const DialogResizableMixin = (superClass) =>
86
86
const event = getMouseOrFirstTouchEvent ( e ) ;
87
87
if ( eventInWindow ( event ) ) {
88
88
const minimumSize = 40 ;
89
+ const { height : boundsHeight , width : boundsWidth , top : boundsTop , left : boundsLeft } = this . __manager . bounds ;
90
+ const eventX = this . __manager . getEventX ( event ) ;
91
+ const eventY = this . __manager . getEventY ( event ) ;
92
+
89
93
resizer . split ( '' ) . forEach ( ( direction ) => {
90
94
switch ( direction ) {
91
95
case 'n' : {
92
- const height = this . _originalBounds . height - ( event . pageY - this . _originalMouseCoords . top ) ;
93
- const top = this . _originalBounds . top + ( event . pageY - this . _originalMouseCoords . top ) ;
96
+ const height = boundsHeight - eventY ;
97
+ const top = boundsTop + eventY ;
94
98
if ( height > minimumSize ) {
95
99
this . top = top ;
96
100
this . height = height ;
97
101
}
98
102
break ;
99
103
}
100
104
case 'e' : {
101
- const width = this . _originalBounds . width + ( event . pageX - this . _originalMouseCoords . left ) ;
105
+ const width = boundsWidth + eventX ;
102
106
if ( width > minimumSize ) {
103
107
this . width = width ;
104
108
}
105
109
break ;
106
110
}
107
111
case 's' : {
108
- const height = this . _originalBounds . height + ( event . pageY - this . _originalMouseCoords . top ) ;
112
+ const height = boundsHeight + eventY ;
109
113
if ( height > minimumSize ) {
110
114
this . height = height ;
111
115
}
112
116
break ;
113
117
}
114
118
case 'w' : {
115
- const width = this . _originalBounds . width - ( event . pageX - this . _originalMouseCoords . left ) ;
116
- const left = this . _originalBounds . left + ( event . pageX - this . _originalMouseCoords . left ) ;
119
+ const width = boundsWidth - eventX ;
120
+ const left = boundsLeft + eventX ;
117
121
if ( width > minimumSize ) {
118
122
this . left = left ;
119
123
this . width = width ;
0 commit comments