/**
 * WordPress dependencies
 */
import { useDispatch } from '@wordpress/data';
import { useEffect } from '@wordpress/element';
import { SlotFillProvider } from '@wordpress/components';

/**
 * 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';
import KeyboardShortcuts from '../keyboard-shortcuts';

/** @typedef {import('@wordpress/data').WPDataRegistry} WPDataRegistry */
import { jsx as _jsx } from "react/jsx-runtime";
import { jsxs as _jsxs } from "react/jsx-runtime";
export const ExperimentalBlockEditorProvider = withRegistryProvider(props => {
  const {
    children,
    settings,
    stripExperimentalSettings = false
  } = props;
  const {
    __experimentalUpdateSettings
  } = unlock(useDispatch(blockEditorStore));
  useEffect(() => {
    __experimentalUpdateSettings({
      ...settings,
      __internalIsInitialized: true
    }, {
      stripExperimentalSettings,
      reset: true
    });
  }, [settings, stripExperimentalSettings, __experimentalUpdateSettings]);

  // Syncs the entity provider with changes in the block-editor store.
  useBlockSync(props);
  return /*#__PURE__*/_jsxs(SlotFillProvider, {
    passthrough: true,
    children: [!settings?.__unstableIsPreviewMode && /*#__PURE__*/_jsx(KeyboardShortcuts.Register, {}), /*#__PURE__*/_jsx(BlockRefsProvider, {
      children: children
    })]
  });
});
export const BlockEditorProvider = props => {
  return /*#__PURE__*/_jsx(ExperimentalBlockEditorProvider, {
    ...props,
    stripExperimentalSettings: true,
    children: props.children
  });
};
export default BlockEditorProvider;
//# sourceMappingURL=index.js.map