UNPKG

@wordpress/block-editor

Version:
62 lines (60 loc) 2.71 kB
"use strict"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; 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 __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // packages/block-editor/src/components/provider/with-registry-provider.js var with_registry_provider_exports = {}; __export(with_registry_provider_exports, { default: () => with_registry_provider_default }); module.exports = __toCommonJS(with_registry_provider_exports); var import_element = require("@wordpress/element"); var import_data = require("@wordpress/data"); var import_compose = require("@wordpress/compose"); var import_store = require("../../store/index.cjs"); var import_constants = require("../../store/constants.cjs"); var import_jsx_runtime = require("react/jsx-runtime"); function getSubRegistry(subRegistries, registry, useSubRegistry) { if (!useSubRegistry) { return registry; } let subRegistry = subRegistries.get(registry); if (!subRegistry) { subRegistry = (0, import_data.createRegistry)({}, registry); subRegistry.registerStore(import_constants.STORE_NAME, import_store.storeConfig); subRegistries.set(registry, subRegistry); } return subRegistry; } var withRegistryProvider = (0, import_compose.createHigherOrderComponent)( (WrappedComponent) => ({ useSubRegistry = true, ...props }) => { const registry = (0, import_data.useRegistry)(); const [subRegistries] = (0, import_element.useState)(() => /* @__PURE__ */ new WeakMap()); const subRegistry = getSubRegistry( subRegistries, registry, useSubRegistry ); if (subRegistry === registry) { return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(WrappedComponent, { registry, ...props }); } return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_data.RegistryProvider, { value: subRegistry, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(WrappedComponent, { registry: subRegistry, ...props }) }); }, "withRegistryProvider" ); var with_registry_provider_default = withRegistryProvider; //# sourceMappingURL=with-registry-provider.cjs.map