File tree 1 file changed +14
-7
lines changed
projects/plugins/jetpack/extensions/shared 1 file changed +14
-7
lines changed Original file line number Diff line number Diff line change 1
1
import { select , subscribe } from '@wordpress/data' ;
2
2
3
+ /**
4
+ * Checks if the editor is ready by verifying if it's a clean new post or has blocks.
5
+ *
6
+ * @return {boolean } Whether the editor is ready.
7
+ */
8
+ const isEditorReady = ( ) => {
9
+ return (
10
+ select ( 'core/editor' ) . isCleanNewPost ( ) || select ( 'core/block-editor' ) . getBlocks ( ) . length > 0
11
+ ) ;
12
+ } ;
13
+
3
14
/**
4
15
* Indicates if the block editor has been initialized.
5
16
*
6
17
* @return {Promise } Promise that resolves when the editor has been initialized.
7
18
*/
8
19
export const waitForEditor = async ( ) =>
9
20
new Promise ( resolve => {
10
- // Resolve immediately if it's a clean new post or has blocks
11
- if (
12
- select ( 'core/editor' ) . isCleanNewPost ( ) ||
13
- select ( 'core/block-editor' ) . getBlocks ( ) . length > 0
14
- ) {
21
+ // Resolve immediately if editor is ready
22
+ if ( isEditorReady ( ) ) {
15
23
resolve ( ) ;
16
24
return ;
17
25
}
@@ -23,8 +31,7 @@ export const waitForEditor = async () =>
23
31
} , 2000 ) ;
24
32
25
33
const unsubscribe = subscribe ( ( ) => {
26
- const blocks = select ( 'core/block-editor' ) . getBlocks ( ) ;
27
- if ( blocks . length > 0 ) {
34
+ if ( isEditorReady ( ) ) {
28
35
clearTimeout ( timeoutId ) ;
29
36
unsubscribe ( ) ;
30
37
resolve ( ) ;
You can’t perform that action at this time.
0 commit comments