-
Notifications
You must be signed in to change notification settings - Fork 4.2k
/
use-should-iframe.js
49 lines (45 loc) · 1.35 KB
/
use-should-iframe.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/**
* WordPress dependencies
*/
import { store as editorStore } from '@wordpress/editor';
import { useSelect } from '@wordpress/data';
import { store as blocksStore } from '@wordpress/blocks';
import { store as blockEditorStore } from '@wordpress/block-editor';
/**
* Internal dependencies
*/
import { unlock } from '../../lock-unlock';
const isGutenbergPlugin = globalThis.IS_GUTENBERG_PLUGIN ? true : false;
export function useShouldIframe() {
const {
isBlockBasedTheme,
hasV3BlocksOnly,
isEditingTemplateOrPattern,
isZoomOutMode,
deviceType,
} = useSelect( ( select ) => {
const { getEditorSettings, getCurrentPostType, getDeviceType } =
select( editorStore );
const { isZoomOut } = unlock( select( blockEditorStore ) );
const { getBlockTypes } = select( blocksStore );
const editorSettings = getEditorSettings();
return {
isBlockBasedTheme: editorSettings.__unstableIsBlockBasedTheme,
hasV3BlocksOnly: getBlockTypes().every( ( type ) => {
return type.apiVersion >= 3;
} ),
isEditingTemplateOrPattern: [ 'wp_template', 'wp_block' ].includes(
getCurrentPostType()
),
isZoomOutMode: isZoomOut(),
deviceType: getDeviceType(),
};
}, [] );
return (
hasV3BlocksOnly ||
( isGutenbergPlugin && isBlockBasedTheme ) ||
isEditingTemplateOrPattern ||
isZoomOutMode ||
[ 'Tablet', 'Mobile' ].includes( deviceType )
);
}