"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// packages/block-editor/src/components/provider/index.js
var provider_exports = {};
__export(provider_exports, {
  BlockEditorProvider: () => BlockEditorProvider,
  ExperimentalBlockEditorProvider: () => ExperimentalBlockEditorProvider,
  default: () => provider_default
});
module.exports = __toCommonJS(provider_exports);
var import_data = require("@wordpress/data");
var import_element = require("@wordpress/element");
var import_components = require("@wordpress/components");
var import_upload_media = require("@wordpress/upload-media");
var import_with_registry_provider = __toESM(require("./with-registry-provider"));
var import_use_block_sync = __toESM(require("./use-block-sync"));
var import_store = require("../../store");
var import_block_refs_provider = require("./block-refs-provider");
var import_lock_unlock = require("../../lock-unlock");
var import_keyboard_shortcuts = __toESM(require("../keyboard-shortcuts"));
var import_use_media_upload_settings = __toESM(require("./use-media-upload-settings"));
var import_jsx_runtime = require("react/jsx-runtime");
var noop = () => {
};
function mediaUpload(registry, {
  allowedTypes,
  additionalData = {},
  filesList,
  onError = noop,
  onFileChange,
  onSuccess,
  onBatchSuccess
}) {
  void registry.dispatch(import_upload_media.store).addItems({
    files: filesList,
    onChange: onFileChange,
    onSuccess,
    onBatchSuccess,
    onError: ({ message }) => onError(message),
    additionalData,
    allowedTypes
  });
}
var ExperimentalBlockEditorProvider = (0, import_with_registry_provider.default)(
  (props) => {
    const {
      settings: _settings,
      registry,
      stripExperimentalSettings = false
    } = props;
    const mediaUploadSettings = (0, import_use_media_upload_settings.default)(_settings);
    let settings = _settings;
    if (window.__experimentalMediaProcessing && _settings.mediaUpload) {
      settings = (0, import_element.useMemo)(
        () => ({
          ..._settings,
          mediaUpload: mediaUpload.bind(null, registry)
        }),
        [_settings, registry]
      );
    }
    const { __experimentalUpdateSettings } = (0, import_lock_unlock.unlock)(
      (0, import_data.useDispatch)(import_store.store)
    );
    (0, import_element.useEffect)(() => {
      __experimentalUpdateSettings(
        {
          ...settings,
          __internalIsInitialized: true
        },
        {
          stripExperimentalSettings,
          reset: true
        }
      );
    }, [
      settings,
      stripExperimentalSettings,
      __experimentalUpdateSettings
    ]);
    (0, import_use_block_sync.default)(props);
    const children = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_components.SlotFillProvider, { passthrough: true, children: [
      !settings?.isPreviewMode && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_keyboard_shortcuts.default.Register, {}),
      /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_block_refs_provider.BlockRefsProvider, { children: props.children })
    ] });
    if (window.__experimentalMediaProcessing) {
      return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
        import_upload_media.MediaUploadProvider,
        {
          settings: mediaUploadSettings,
          useSubRegistry: false,
          children
        }
      );
    }
    return children;
  }
);
var BlockEditorProvider = (props) => {
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ExperimentalBlockEditorProvider, { ...props, stripExperimentalSettings: true, children: props.children });
};
var provider_default = BlockEditorProvider;
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  BlockEditorProvider,
  ExperimentalBlockEditorProvider
});
//# sourceMappingURL=index.js.map
