@@ -39,6 +39,7 @@ export default {
3939 data () {
4040 return {
4141 imageEditor: null ,
42+ observer: null ,
4243 }
4344 },
4445
@@ -133,14 +134,31 @@ export default {
133134 )
134135 this .imageEditor .render ()
135136 window .addEventListener (' keydown' , this .handleKeydown , true )
136- window .addEventListener (' DOMNodeInserted' , this .handleSfxModal )
137+
138+ this .observer = new MutationObserver ((mutations ) => {
139+ mutations .forEach ((mutation ) => {
140+ if (mutation .type === ' childList' ) {
141+ mutation .addedNodes .forEach ((node ) => {
142+ if (node .classList .contains (' FIE_root' ) || node .classList .contains (' SfxModal-Wrapper' )) {
143+ emit (' viewer:trapElements:changed' , node)
144+ }
145+ })
146+ }
147+ })
148+ })
149+ // using body instead of the editor ref because save modal is not mounted in editor
150+ this .observer .observe (document .body , {
151+ childList: true ,
152+ subtree: true ,
153+ })
137154
138155 },
139156
140157 beforeDestroy () {
141158 if (this .imageEditor ) {
142159 this .imageEditor .terminate ()
143160 }
161+ this .observer .disconnect ()
144162 window .removeEventListener (' keydown' , this .handleKeydown , true )
145163 },
146164
@@ -290,17 +308,6 @@ export default {
290308 }
291309 },
292310
293- /**
294- * Watch out for Modal inject in document root
295- * That way we can adjust the focusTrap
296- *
297- * @param {Event} event Dom insertion event
298- */
299- handleSfxModal (event ) {
300- if (event .target ? .classList && event .target .classList .contains (' SfxModal-Wrapper' )) {
301- emit (' viewer:trapElements:changed' , event .target )
302- }
303- },
304311 },
305312}
306313< / script>
0 commit comments