-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Expand file tree
/
Copy pathuse-block-editor-settings.native.js
More file actions
42 lines (37 loc) · 1.19 KB
/
use-block-editor-settings.native.js
File metadata and controls
42 lines (37 loc) · 1.19 KB
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
/**
* WordPress dependencies
*/
import { useMemo } from '@wordpress/element';
import { useSelect } from '@wordpress/data';
import { store as coreStore } from '@wordpress/core-data';
/**
* Internal dependencies
*/
import useBlockEditorSettings from './use-block-editor-settings.js';
function useNativeBlockEditorSettings( settings, hasTemplate ) {
const capabilities = settings.capabilities ?? {};
const editorSettings = useBlockEditorSettings( settings, hasTemplate );
const supportReusableBlock = capabilities.reusableBlock === true;
const { reusableBlocks } = useSelect(
( select ) => ( {
reusableBlocks: supportReusableBlock
? select( coreStore ).getEntityRecords(
'postType',
'wp_block',
// Unbounded queries are not supported on native so as a workaround, we set per_page with the maximum value that native version can handle.
// Related issue: https://github.com/wordpress-mobile/gutenberg-mobile/issues/2661
{ per_page: 100 }
)
: [],
} ),
[ supportReusableBlock ]
);
return useMemo(
() => ( {
...editorSettings,
__experimentalReusableBlocks: reusableBlocks,
} ),
[ reusableBlocks ]
);
}
export default useNativeBlockEditorSettings;