UNPKG

@wordpress/components

Version:
8 lines (7 loc) 2.96 kB
{ "version": 3, "sources": ["../../../src/higher-order/with-focus-return/index.tsx"], "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { Component } from '@wordpress/element';\nimport { createHigherOrderComponent, useFocusReturn } from '@wordpress/compose';\nimport deprecated from '@wordpress/deprecated';\n\n/**\n * Returns true if the given object is component-like. An object is component-\n * like if it is an instance of wp.element.Component, or is a function.\n *\n * @param object Object to test.\n *\n * @return Whether object is component-like.\n */\nimport { jsx as _jsx } from \"react/jsx-runtime\";\nfunction isComponentLike(object) {\n return object instanceof Component || typeof object === 'function';\n}\n/**\n * Higher Order Component used to be used to wrap disposable elements like\n * sidebars, modals, dropdowns. When mounting the wrapped component, we track a\n * reference to the current active element so we know where to restore focus\n * when the component is unmounted.\n *\n * @param options The component to be enhanced with\n * focus return behavior, or an object\n * describing the component and the\n * focus return characteristics.\n *\n * @return Higher Order Component with the focus restoration behaviour.\n */\nexport default createHigherOrderComponent(\n// @ts-expect-error TODO: Reconcile with intended `createHigherOrderComponent` types\noptions => {\n const HoC = ({\n onFocusReturn\n } = {}) => WrappedComponent => {\n const WithFocusReturn = props => {\n const ref = useFocusReturn(onFocusReturn);\n return /*#__PURE__*/_jsx(\"div\", {\n ref: ref,\n children: /*#__PURE__*/_jsx(WrappedComponent, {\n ...props\n })\n });\n };\n return WithFocusReturn;\n };\n if (isComponentLike(options)) {\n const WrappedComponent = options;\n return HoC()(WrappedComponent);\n }\n return HoC(options);\n}, 'withFocusReturn');\nexport const Provider = ({\n children\n}) => {\n deprecated('wp.components.FocusReturnProvider component', {\n since: '5.7',\n hint: 'This provider is not used anymore. You can just remove it from your codebase'\n });\n return children;\n};"], "mappings": ";AAGA,SAAS,iBAAiB;AAC1B,SAAS,4BAA4B,sBAAsB;AAC3D,OAAO,gBAAgB;AAUvB,SAAS,OAAO,YAAY;AAC5B,SAAS,gBAAgB,QAAQ;AAC/B,SAAO,kBAAkB,aAAa,OAAO,WAAW;AAC1D;AAcA,IAAO,4BAAQ;AAAA;AAAA,EAEf,aAAW;AACT,UAAM,MAAM,CAAC;AAAA,MACX;AAAA,IACF,IAAI,CAAC,MAAM,sBAAoB;AAC7B,YAAM,kBAAkB,WAAS;AAC/B,cAAM,MAAM,eAAe,aAAa;AACxC,eAAoB,qBAAK,OAAO;AAAA,UAC9B;AAAA,UACA,UAAuB,qBAAK,kBAAkB;AAAA,YAC5C,GAAG;AAAA,UACL,CAAC;AAAA,QACH,CAAC;AAAA,MACH;AACA,aAAO;AAAA,IACT;AACA,QAAI,gBAAgB,OAAO,GAAG;AAC5B,YAAM,mBAAmB;AACzB,aAAO,IAAI,EAAE,gBAAgB;AAAA,IAC/B;AACA,WAAO,IAAI,OAAO;AAAA,EACpB;AAAA,EAAG;AAAiB;AACb,IAAM,WAAW,CAAC;AAAA,EACvB;AACF,MAAM;AACJ,aAAW,+CAA+C;AAAA,IACxD,OAAO;AAAA,IACP,MAAM;AAAA,EACR,CAAC;AACD,SAAO;AACT;", "names": [] }