@@ -12,6 +12,7 @@ import WysiwygInstanceInterface from "wysiwygAdapter";
12
12
import { AdditionalDataConfigInterface } from "../content-type-config.types" ;
13
13
import DataStore from "../data-store" ;
14
14
import checkStageFullScreen from "../utils/check-stage-full-screen" ;
15
+ import delayUntil from "../utils/delay-until" ;
15
16
import pageBuilderHeaderHeight from "../utils/pagebuilder-header-height" ;
16
17
import WysiwygInterface from "./wysiwyg-interface" ;
17
18
@@ -171,36 +172,45 @@ export default class Wysiwyg implements WysiwygInterface {
171
172
172
173
events . trigger ( "stage:interactionStart" ) ;
173
174
175
+ const element = document . querySelector ( `#${ this . elementId } ` ) ;
176
+ if ( ! element ) {
177
+ return ;
178
+ }
179
+
174
180
// Wait for everything else to finish
175
- _ . defer ( ( ) => {
176
- const $inlineToolbar = this . getFixedToolbarContainer ( ) . find ( ".tox-tinymce-inline" ) ;
177
- const self = this ;
178
-
179
- $inlineToolbar . css ( "min-width" , this . config . adapter_config . minToolbarWidth + "px" ) ;
180
-
181
- this . invertInlineEditorToAccommodateOffscreenToolbar ( ) ;
182
-
183
- // Update toolbar when the height changes
184
- this . toolbarHeight = $inlineToolbar . height ( ) ;
185
- if ( $inlineToolbar . length ) {
186
- this . resizeObserver = new ResizeObserver ( ( entries ) => {
187
- for ( const entry of entries ) {
188
- if ( entry . target === $inlineToolbar . get ( 0 )
189
- && entry . target . clientHeight !== self . toolbarHeight
190
- ) {
191
- self . invertInlineEditorToAccommodateOffscreenToolbar ( ) ;
192
- self . toolbarHeight = entry . target . clientHeight ;
181
+ _ . defer ( ( ) => delayUntil (
182
+ ( ) => {
183
+ const $inlineToolbar = this . getFixedToolbarContainer ( ) . find ( ".tox-tinymce-inline" ) ;
184
+ const self = this ;
185
+
186
+ $inlineToolbar . css ( "min-width" , this . config . adapter_config . minToolbarWidth + "px" ) ;
187
+
188
+ this . invertInlineEditorToAccommodateOffscreenToolbar ( ) ;
189
+
190
+ // Update toolbar when the height changes
191
+ this . toolbarHeight = $inlineToolbar . height ( ) ;
192
+ if ( $inlineToolbar . length ) {
193
+ this . resizeObserver = new ResizeObserver ( ( entries ) => {
194
+ for ( const entry of entries ) {
195
+ if ( entry . target === $inlineToolbar . get ( 0 )
196
+ && entry . target . clientHeight !== self . toolbarHeight
197
+ ) {
198
+ self . invertInlineEditorToAccommodateOffscreenToolbar ( ) ;
199
+ self . toolbarHeight = entry . target . clientHeight ;
200
+ }
193
201
}
194
- }
195
- } ) ;
196
- this . resizeObserver . observe ( $inlineToolbar . get ( 0 ) ) ;
197
- }
198
- const dialogContainer = document . querySelector ( `#${ this . elementId } ~ .tox-tinymce-aux` ) ;
199
- if ( ! ! dialogContainer ) {
200
- dialogContainer . setAttribute ( "data-editor-aux" , this . elementId ) ;
201
- document . body . appendChild ( dialogContainer ) ;
202
- }
203
- } ) ;
202
+ } ) ;
203
+ this . resizeObserver . observe ( $inlineToolbar . get ( 0 ) ) ;
204
+ }
205
+ const dialogContainer = document . querySelector ( `#${ this . elementId } ~ .tox-tinymce-aux` ) ;
206
+ if ( ! ! dialogContainer ) {
207
+ dialogContainer . setAttribute ( "data-editor-aux" , this . elementId ) ;
208
+ document . body . appendChild ( dialogContainer ) ;
209
+ }
210
+ } ,
211
+ ( ) => element . classList . contains ( "mce-edit-focus" ) ,
212
+ 10 ,
213
+ ) ) ;
204
214
}
205
215
206
216
/**
0 commit comments