UNPKG

@wordpress/components

Version:
73 lines (72 loc) • 2.86 kB
"use strict"; Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } }); // \0rolldown/runtime.js 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 __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) { key = keys[i]; if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: ((k) => from[k]).bind(null, key), enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod)); let _wordpress_compose = require("@wordpress/compose"); let _wordpress_element = require("@wordpress/element"); let __context_ts = require("./context.cjs"); __context_ts = __toESM(__context_ts); let ___style_provider_index_tsx = require("../style-provider/index.cjs"); ___style_provider_index_tsx = __toESM(___style_provider_index_tsx); let react_jsx_runtime = require("react/jsx-runtime"); // packages/components/src/slot-fill/fill.tsx function Fill({ name, children }) { const registry = (0, _wordpress_element.useContext)(__context_ts.default); const instanceRef = (0, _wordpress_element.useRef)({}); const childrenRef = (0, _wordpress_element.useRef)(children); (0, _wordpress_element.useLayoutEffect)(() => { childrenRef.current = children; }, [children]); (0, _wordpress_element.useLayoutEffect)(() => { const instance = instanceRef.current; registry.registerFill(name, { instance, children: childrenRef.current }); return () => registry.unregisterFill(name, instance); }, [registry, name]); (0, _wordpress_element.useLayoutEffect)(() => { registry.updateFill(name, { instance: instanceRef.current, children }); }, [ registry, name, children ]); const slot = (0, _wordpress_compose.useObservableValue)(registry.slots, name); if (!slot) return null; if (slot.type === "children") return null; const portalEl = slot.ref.current; if (!portalEl) return null; const wrappedChildren = typeof children === "function" ? children(slot.fillProps ?? {}) : children; return (0, _wordpress_element.createPortal)(/* @__PURE__ */ (0, react_jsx_runtime.jsx)(___style_provider_index_tsx.default, { document: portalEl.ownerDocument, children: wrappedChildren }), portalEl); } exports.default = Fill; //# sourceMappingURL=fill.cjs.map