1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- "use strict";
-
- exports.__esModule = true;
- exports.default = void 0;
-
- var _propTypes = _interopRequireDefault(require("prop-types"));
-
- var _componentOrElement = _interopRequireDefault(require("prop-types-extra/lib/componentOrElement"));
-
- var _inDOM = _interopRequireDefault(require("dom-helpers/util/inDOM"));
-
- var _ownerDocument = _interopRequireDefault(require("dom-helpers/ownerDocument"));
-
- var _react = _interopRequireDefault(require("react"));
-
- var _reactDom = _interopRequireDefault(require("react-dom"));
-
- var _getContainer = _interopRequireDefault(require("./utils/getContainer"));
-
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
-
- function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
-
- function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; }
-
- var propTypes = {
- /**
- * A Node, Component instance, or function that returns either. The `container` will have the Portal children
- * appended to it.
- */
- container: _propTypes.default.oneOfType([_componentOrElement.default, _propTypes.default.func]),
- onContainerResolved: _propTypes.default.func
- };
-
- var WaitForContainer =
- /*#__PURE__*/
- function (_React$Component) {
- _inheritsLoose(WaitForContainer, _React$Component);
-
- function WaitForContainer() {
- var _this;
-
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
- args[_key] = arguments[_key];
- }
-
- _this = _React$Component.call.apply(_React$Component, [this].concat(args)) || this;
- if (!_inDOM.default) return _assertThisInitialized(_this);
- var container = _this.props.container;
- if (typeof container === 'function') container = container();
-
- if (container && !_reactDom.default.findDOMNode(container)) {
- // The container is a React component that has not yet been rendered.
- // Don't set the container node yet.
- return _assertThisInitialized(_this);
- }
-
- _this.setContainer(container);
-
- return _this;
- }
-
- var _proto = WaitForContainer.prototype;
-
- _proto.UNSAFE_componentWillReceiveProps = function UNSAFE_componentWillReceiveProps(nextProps) {
- if (nextProps.container !== this.props.container) {
- this.setContainer(nextProps.container);
- }
- };
-
- _proto.componentDidMount = function componentDidMount() {
- if (!this._container) {
- this.setContainer(this.props.container);
- this.forceUpdate(this.props.onContainerResolved);
- } else if (this.props.onContainerResolved) {
- this.props.onContainerResolved();
- }
- };
-
- _proto.componentWillUnmount = function componentWillUnmount() {
- this._container = null;
- };
-
- _proto.setContainer = function setContainer(container) {
- this._container = (0, _getContainer.default)(container, (0, _ownerDocument.default)().body);
- };
-
- _proto.render = function render() {
- return this._container ? this.props.children(this._container) : null;
- };
-
- return WaitForContainer;
- }(_react.default.Component);
-
- WaitForContainer.propTypes = propTypes;
- var _default = WaitForContainer;
- exports.default = _default;
- module.exports = exports.default;
|