@@ -217,12 +217,30 @@ class Popover extends Popup {
217217 _width ?: string ;
218218 _height ?: string ;
219219
220+ _resizeMouseMoveHandler : ( e : MouseEvent ) => void ;
221+ _resizeMouseUpHandler : ( e : MouseEvent ) => void ;
222+ _y ?: number ;
223+ _x ?: number ;
224+ _isRTL ?: boolean ;
225+ _initialX ?: number ;
226+ _initialY ?: number ;
227+ _initialWidth ?: number ;
228+ _initialHeight ?: number ;
229+ _initialTop ?: number ;
230+ _initialLeft ?: number ;
231+ _minWidth ?: number ;
232+ _cachedMinHeight ?: number ;
233+ _draggedOrResized = false ;
234+
220235 static get VIEWPORT_MARGIN ( ) {
221236 return 10 ; // px
222237 }
223238
224239 constructor ( ) {
225240 super ( ) ;
241+
242+ this . _resizeMouseMoveHandler = this . _onResizeMouseMove . bind ( this ) ;
243+ this . _resizeMouseUpHandler = this . _onResizeMouseUp . bind ( this ) ;
226244 }
227245
228246 /**
@@ -873,6 +891,131 @@ class Popover extends Popup {
873891
874892 return this . horizontalAlign ;
875893 }
894+
895+ get _showResizeHandle ( ) {
896+ return this . resizable && this . onDesktop ;
897+ }
898+
899+ _onResizeMouseDown ( e : MouseEvent ) {
900+ if ( ! this . resizable ) {
901+ return ;
902+ }
903+
904+ e . preventDefault ( ) ;
905+
906+ const {
907+ top,
908+ left,
909+ } = this . getBoundingClientRect ( ) ;
910+ const {
911+ width,
912+ height,
913+ minWidth,
914+ } = window . getComputedStyle ( this ) ;
915+
916+ this . _initialX = e . clientX ;
917+ this . _initialY = e . clientY ;
918+ this . _initialWidth = Number . parseFloat ( width ) ;
919+ this . _initialHeight = Number . parseFloat ( height ) ;
920+ this . _initialTop = top ;
921+ this . _initialLeft = left ;
922+ this . _minWidth = Number . parseFloat ( minWidth ) ;
923+ // this._cachedMinHeight = this._minHeight;
924+
925+ Object . assign ( this . style , {
926+ top : `${ top } px` ,
927+ left : `${ left } px` ,
928+ } ) ;
929+
930+ this . _draggedOrResized = true ;
931+ this . _attachMouseResizeHandlers ( ) ;
932+ }
933+
934+ _onResizeMouseMove ( e : MouseEvent ) {
935+ const { clientX, clientY } = e ;
936+
937+ let newWidth ,
938+ newLeft ;
939+
940+ if ( this . _isRTL ) {
941+ newWidth = clamp (
942+ this . _initialWidth ! - ( clientX - this . _initialX ! ) ,
943+ this . _minWidth ! ,
944+ this . _initialLeft ! + this . _initialWidth ! ,
945+ ) ;
946+
947+ // check if width is changed to avoid "left" jumping when max width is reached
948+ Object . assign ( this . style , {
949+ width : `${ newWidth } px` ,
950+ } ) ;
951+
952+ const deltaWidth = newWidth - this . getBoundingClientRect ( ) . width ;
953+ const rightEdge = this . _initialLeft ! + this . _initialWidth ! + deltaWidth ;
954+
955+ newLeft = clamp (
956+ rightEdge - newWidth ,
957+ 0 ,
958+ rightEdge - this . _minWidth ! ,
959+ ) ;
960+ } else {
961+ newWidth = clamp (
962+ this . _initialWidth ! + ( clientX - this . _initialX ! ) ,
963+ this . _minWidth ! ,
964+ window . innerWidth - this . _initialLeft ! ,
965+ ) ;
966+ }
967+
968+ const newHeight = clamp (
969+ this . _initialHeight ! + ( clientY - this . _initialY ! ) ,
970+ this . _cachedMinHeight ! ,
971+ window . innerHeight - this . _initialTop ! ,
972+ ) ;
973+
974+ Object . assign ( this . style , {
975+ height : `${ newHeight } px` ,
976+ width : `${ newWidth } px` ,
977+ left : this . _isRTL ? `${ newLeft } px` : undefined ,
978+ } ) ;
979+ }
980+
981+ _onResizeMouseUp ( ) {
982+ delete this . _initialX ;
983+ delete this . _initialY ;
984+ delete this . _initialWidth ;
985+ delete this . _initialHeight ;
986+ delete this . _initialTop ;
987+ delete this . _initialLeft ;
988+ delete this . _minWidth ;
989+ delete this . _cachedMinHeight ;
990+
991+ this . _detachMouseResizeHandlers ( ) ;
992+ }
993+
994+ _handleDragStart ( e : DragEvent ) {
995+ if ( this . draggable ) {
996+ e . preventDefault ( ) ;
997+ }
998+ }
999+
1000+ _attachMouseResizeHandlers ( ) {
1001+ window . addEventListener ( "mousemove" , this . _resizeMouseMoveHandler ) ;
1002+ window . addEventListener ( "mouseup" , this . _resizeMouseUpHandler ) ;
1003+ this . addEventListener ( "ui5-before-close" , this . _revertSize , { once : true } ) ;
1004+ }
1005+
1006+ _detachMouseResizeHandlers ( ) {
1007+ window . removeEventListener ( "mousemove" , this . _resizeMouseMoveHandler ) ;
1008+ window . removeEventListener ( "mouseup" , this . _resizeMouseUpHandler ) ;
1009+ }
1010+
1011+ _revertSize = ( ) => {
1012+ Object . assign ( this . style , {
1013+ top : "" ,
1014+ left : "" ,
1015+ width : "" ,
1016+ height : "" ,
1017+ } ) ;
1018+ }
8761019}
8771020
8781021const instanceOfPopover = ( object : any ) : object is Popover => {
0 commit comments