-
Notifications
You must be signed in to change notification settings - Fork 4.3k
/
Copy pathindex.js
42 lines (35 loc) · 1.1 KB
/
index.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
/**
* WordPress dependencies
*/
import { useEffect } from '@wordpress/element';
import { useSelect, useDispatch } from '@wordpress/data';
import { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor';
/**
* Internal dependencies
*/
import { store as editSiteStore } from '../../store';
import { unlock } from '../../lock-unlock';
const { useGlobalStylesOutput } = unlock( blockEditorPrivateApis );
function useGlobalStylesRenderer() {
const [ styles, settings ] = useGlobalStylesOutput();
const { getSettings } = useSelect( editSiteStore );
const { updateSettings } = useDispatch( editSiteStore );
useEffect( () => {
if ( ! styles || ! settings ) {
return;
}
const currentStoreSettings = getSettings();
const nonGlobalStyles = Object.values(
currentStoreSettings.styles ?? []
).filter( ( style ) => ! style.isGlobalStyles );
updateSettings( {
...currentStoreSettings,
styles: [ ...nonGlobalStyles, ...styles ],
__experimentalFeatures: settings,
} );
}, [ styles, settings ] );
}
export function GlobalStylesRenderer() {
useGlobalStylesRenderer();
return null;
}