UNPKG

@atlaskit/editor-core

Version:

A package contains Atlassian editor core functionality

51 lines 1.92 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var tslib_1 = require("tslib"); var ReactDOM = require("react-dom"); var React = require("react"); var react_1 = require("react"); var Portal = (function (_super) { tslib_1.__extends(Portal, _super); function Portal() { return _super !== null && _super.apply(this, arguments) || this; } Portal.prototype.renderPortalContent = function (children) { return (React.createElement("div", null, children)); }; Portal.prototype.renderPortal = function (props) { if (!props.mountTo) { return; } if (!this.target) { this.target = document.createElement('div'); props.mountTo.appendChild(this.target); } ReactDOM.unstable_renderSubtreeIntoContainer(this, this.renderPortalContent(props.children), this.target); }; Portal.prototype.componentWillUnmount = function () { var _this = this; // Asynchronously unmounts subtree, otherwise there might be errors when child component calls setState, // but it has already been unmounted by Portal. setTimeout(function () { if (_this.target && _this.target.parentElement) { ReactDOM.unmountComponentAtNode(_this.target); _this.target.parentElement.removeChild(_this.target); } }, 0); }; Portal.prototype.componentWillReceiveProps = function (nextProps) { this.renderPortal(nextProps); }; Portal.prototype.componentDidMount = function () { this.renderPortal(this.props); }; Portal.prototype.render = function () { if (!this.props.mountTo) { return this.renderPortalContent(this.props.children); } return null; }; return Portal; }(react_1.PureComponent)); exports.default = Portal; //# sourceMappingURL=index.js.map