@@ -33,6 +33,9 @@ function RemoteFunctions(config = {}) {
3333 // we need this so that we can remove click styling from the previous element when a new element is clicked
3434 let previouslyClickedElement = null ;
3535
36+ // we store references to interaction blocker event handlers so we can remove them when switching modes
37+ let _interactionBlockerHandlers = null ;
38+
3639 var req , timeout ;
3740 var animateHighlight = function ( time ) {
3841 if ( req ) {
@@ -3920,39 +3923,67 @@ function RemoteFunctions(config = {}) {
39203923 * but we exclude all the phoenix interal elements
39213924 * we call this function from inside registerHandlers
39223925 */
3926+ /**
3927+ * Central event blocker for edit mode
3928+ * Blocks all user page interactions but allows Phoenix UI to work
3929+ * Stores handler references so they can be removed when switching modes
3930+ */
39233931 function registerInteractionBlocker ( ) {
3932+ // Create an object to store handler references
3933+ _interactionBlockerHandlers = { } ;
3934+
39243935 const eventsToBlock = [ "click" , "dblclick" , "mousedown" , "mouseup" ] ;
39253936
39263937 eventsToBlock . forEach ( eventType => {
3927- window . document . addEventListener ( eventType , function ( event ) {
3938+ // Create a named handler function so we can remove it later
3939+ const handler = function ( event ) {
39283940 const element = event . target ;
39293941
3930- // whitelist: phoenix internal elements
3942+ // WHITELIST: Allow Phoenix internal UI elements to work normally
39313943 if ( element . closest ( "[data-phcode-internal-c15r5a9]" ) ) {
39323944 return ;
39333945 }
39343946
3947+ // BLOCK: Kill all user page interactions in edit mode
39353948 event . preventDefault ( ) ;
39363949 event . stopImmediatePropagation ( ) ;
39373950
3938- // handling the click and double click.
3939- // on click we just call the selectElement as it handles everything
3940- // on doubleClick we just need to call the startEditing
3951+ // HANDLE: Process clicks and double-clicks for element selection/editing
39413952 if ( eventType === "click" ) {
3942- // event detail is 2 for double clicks
3953+ // Skip click handling on the second click of a double-click
3954+ // event.detail = 1 for first click, 2 for second click (during double-click)
39433955 if ( event . detail !== 2 ) {
39443956 _selectElement ( element ) ;
3945- activateHoverLock ( ) ; // we add hover lock on LP clicks
3957+ activateHoverLock ( ) ;
39463958 }
39473959 } else if ( eventType === "dblclick" ) {
39483960 if ( isElementEditable ( element ) && _shouldShowEditTextOption ( element ) ) {
39493961 startEditing ( element ) ;
39503962 }
39513963 }
3952- } , true ) ; // true is for capture phase
3964+ } ;
3965+
3966+ // Store the handler reference
3967+ _interactionBlockerHandlers [ eventType ] = handler ;
3968+
3969+ // Register the handler in capture phase
3970+ window . document . addEventListener ( eventType , handler , true ) ;
39533971 } ) ;
39543972 }
39553973
3974+ /**
3975+ * this function is to remove all the interaction blocker
3976+ * this is needed when user is in preview/highlight mode
3977+ */
3978+ function unregisterInteractionBlocker ( ) {
3979+ if ( _interactionBlockerHandlers ) {
3980+ Object . keys ( _interactionBlockerHandlers ) . forEach ( eventType => {
3981+ window . document . removeEventListener ( eventType , _interactionBlockerHandlers [ eventType ] , true ) ;
3982+ } ) ;
3983+ _interactionBlockerHandlers = null ;
3984+ }
3985+ }
3986+
39563987 function onKeyUp ( event ) {
39573988 if ( _setup && ! _validEvent ( event ) ) {
39583989 window . document . removeEventListener ( "keyup" , onKeyUp ) ;
@@ -4838,6 +4869,7 @@ function RemoteFunctions(config = {}) {
48384869 window . document . removeEventListener ( "drop" , onDrop ) ;
48394870 window . document . removeEventListener ( "dragleave" , onDragLeave ) ;
48404871 window . document . removeEventListener ( "keydown" , onKeyDown ) ;
4872+ unregisterInteractionBlocker ( ) ;
48414873
48424874 if ( config . isProUser ) {
48434875 // Initialize hover highlight with Chrome-like colors
0 commit comments