@@ -310,6 +310,16 @@ function initButton(sfHost, inInspector) {
310310 inInspector,
311311 } , "*" ) ;
312312 }
313+ if ( e . data . mouseX ) {
314+ let boundingClientRect = popupEl . getBoundingClientRect ( ) ;
315+ let evt = new CustomEvent ( "mousemove" , { bubbles : true , cancelable : false } ) ;
316+ evt . clientX = e . data . mouseX + boundingClientRect . left ;
317+ evt . clientY = e . data . mouseY + boundingClientRect . top ;
318+ onResizeMove ( evt ) ;
319+ }
320+ if ( e . data . trackMouseMove == false ) {
321+ endResizeMove ( { skipMessage : true } ) ;
322+ }
313323 if ( e . data . insextClosePopup ) {
314324 closePopup ( ) ;
315325 } "field-api-name" ;
@@ -362,21 +372,42 @@ function initButton(sfHost, inInspector) {
362372 popupHeight = resizeHeight - ( resizeY - event . clientY ) ;
363373 }
364374 let popupWidth = resizeWidth - ( event . clientX - resizeX ) ;
375+ let boundingClientRect = popupEl . getBoundingClientRect ( ) ;
376+ if ( popupHeight > window . innerHeight - boundingClientRect . top - 50 ) {
377+ popupHeight = window . innerHeight - boundingClientRect . top - 50 ;
378+ }
379+ if ( popupWidth > window . innerWidth - 50 ) {
380+ popupWidth = window . innerWidth - 50 ;
381+ }
382+ if ( popupHeight < 0 ) {
383+ popupHeight = 50 ;
384+ }
385+ if ( popupWidth < 0 ) {
386+ popupWidth = 50 ;
387+ }
365388 localStorage . setItem ( "popupWidth" , popupWidth ) ;
366389 localStorage . setItem ( "popupHeight" , popupHeight ) ;
367390 popupWrapper . style . width = popupWidth + "px" ;
368391 popupWrapper . style . height = popupHeight + "px" ;
369392 }
370393 }
371- function endResizeMove ( ) {
394+ function endResizeMove ( evt ) {
372395 window . removeEventListener ( "mousemove" , onResizeMove ) ;
373396 window . removeEventListener ( "mouseup" , endResizeMove ) ;
397+ if ( ! evt . skipMessage ) {
398+ popupEl . contentWindow . postMessage ( {
399+ trackMouseMove : false
400+ } , "*" ) ;
401+ }
374402 resizeX = 0 ;
375403 resizeY = 0 ;
376404 }
377405 popupWrapper . addEventListener ( "mousedown" , ( ) => {
378406 window . addEventListener ( "mousemove" , onResizeMove ) ;
379407 window . addEventListener ( "mouseup" , endResizeMove ) ;
408+ popupEl . contentWindow . postMessage ( {
409+ trackMouseMove : true
410+ } , "*" ) ;
380411 } ) ;
381412
382413
0 commit comments