@wordpress/components
Version:
UI components for WordPress.
84 lines (83 loc) • 3.33 kB
JavaScript
;
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_element = require("@wordpress/element");
let _wordpress_compose = require("@wordpress/compose");
let _wordpress_deprecated = require("@wordpress/deprecated");
_wordpress_deprecated = __toESM(_wordpress_deprecated);
let react_jsx_runtime = require("react/jsx-runtime");
// packages/components/src/higher-order/with-focus-return/index.tsx
/**
* Returns true if the given object is component-like. An object is component-
* like if it is an instance of wp.element.Component, or is a function.
*
* @param object Object to test.
*
* @return Whether object is component-like.
*/
function isComponentLike(object) {
return object instanceof _wordpress_element.Component || typeof object === "function";
}
/**
* Higher Order Component used to be used to wrap disposable elements like
* sidebars, modals, dropdowns. When mounting the wrapped component, we track a
* reference to the current active element so we know where to restore focus
* when the component is unmounted.
*
* @param options The component to be enhanced with
* focus return behavior, or an object
* describing the component and the
* focus return characteristics.
*
* @return Higher Order Component with the focus restoration behaviour.
*/
var with_focus_return_default = (0, _wordpress_compose.createHigherOrderComponent)((options) => {
const HoC = ({ onFocusReturn } = {}) => (WrappedComponent) => {
const WithFocusReturn = (props) => {
const ref = (0, _wordpress_compose.useFocusReturn)(onFocusReturn);
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
ref,
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(WrappedComponent, { ...props })
});
};
return WithFocusReturn;
};
if (isComponentLike(options)) {
const WrappedComponent = options;
return HoC()(WrappedComponent);
}
return HoC(options);
}, "withFocusReturn");
const Provider = ({ children }) => {
(0, _wordpress_deprecated.default)("wp.components.FocusReturnProvider component", {
since: "5.7",
hint: "This provider is not used anymore. You can just remove it from your codebase"
});
return children;
};
exports.Provider = Provider;
exports.default = with_focus_return_default;
//# sourceMappingURL=index.cjs.map