PluginProbe
Extendify / 3.1.6
Extendify v3.1.6
3.2.1 3.2.0 3.1.6 3.1.5 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.6 3.0.5 3.0.4 trunk 0.1.0 0.10.0 0.10.1 0.10.2 0.11.0 0.11.1 0.2.0 0.3.0 0.3.1 0.4.0 0.5.0 0.6.0 All 127 releases
extendify / src / Shared / hooks / gutenberg.js

gutenberg.js in Extendify 3.1.6, at src/Shared/hooks/gutenberg.js

33 lines 1010 B
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { store as blockEditorStore } from '@wordpress/block-editor';
2 import { subscribe, useSelect } from '@wordpress/data';
3 import { store as editorStore } from '@wordpress/editor';
4 import { useEffect, useState } from '@wordpress/element';
5
6 //** This hook checks if the editor is interactive yet */
7 export const useEditorReady = () => {
8 const [isEditorReady, setIsEditorReady] = useState(false);
9 const blocksReady = useSelect(
10 (select) =>
11 select(blockEditorStore).__unstableIsEditorReady ||
12 select(blockEditorStore).getBlockCount() > 0 ||
13 select(blockEditorStore).getSelectedBlockClientId(),
14 );
15 const editorReady = useSelect(
16 (select) =>
17 select(editorStore).__unstableIsEditorReady ||
18 select(editorStore).isCleanNewPost(),
19 );
20 // TODO: do we need to wait on the iframe?
21
22 useEffect(() => {
23 const unsubscribe = subscribe(() => {
24 if (blocksReady || editorReady) {
25 setIsEditorReady(true);
26 unsubscribe();
27 }
28 });
29 }, [blocksReady, editorReady]);
30
31 return isEditorReady;
32 };
33