UNPKG

@wordpress/block-editor

Version:
54 lines (45 loc) 1.36 kB
/** * WordPress dependencies */ import { useDispatch } from '@wordpress/data'; import { useEffect } from '@wordpress/element'; /** * Internal dependencies */ import withRegistryProvider from './with-registry-provider'; import useBlockSync from './use-block-sync'; import { store as blockEditorStore } from '../../store'; import { BlockRefsProvider } from './block-refs-provider'; import { unlock } from '../../lock-unlock'; /** @typedef {import('@wordpress/data').WPDataRegistry} WPDataRegistry */ export const ExperimentalBlockEditorProvider = withRegistryProvider( ( props ) => { const { children, settings, stripExperimentalSettings = false } = props; const { __experimentalUpdateSettings } = unlock( useDispatch( blockEditorStore ) ); useEffect( () => { __experimentalUpdateSettings( { ...settings, __internalIsInitialized: true, }, stripExperimentalSettings ); }, [ settings ] ); // Syncs the entity provider with changes in the block-editor store. useBlockSync( props ); return <BlockRefsProvider>{ children }</BlockRefsProvider>; } ); export const BlockEditorProvider = ( props ) => { return ( <ExperimentalBlockEditorProvider { ...props } stripExperimentalSettings={ true } > { props.children } </ExperimentalBlockEditorProvider> ); }; export default BlockEditorProvider;