@atlaskit/portal
Advanced tools
Comparing version 2.0.2 to 3.0.0
# @atlaskit/portal | ||
## 2.0.2 | ||
## 3.0.0 | ||
### Major Changes | ||
- [dacfb81ca1](https://bitbucket.org/atlassian/atlaskit-mk-2/commits/dacfb81ca1): | ||
- @atlaskit/portal has been converted to Typescript. Typescript consumers will now get static type safety. Flow types are no longer provided. No API or behavioural changes. | ||
- Updated dependencies [06c5cccf9d](https://bitbucket.org/atlassian/atlaskit-mk-2/commits/06c5cccf9d): | ||
@@ -5,0 +10,0 @@ - @atlaskit/icon@17.1.2 |
@@ -1,8 +0,2 @@ | ||
import _classCallCheck from "@babel/runtime/helpers/classCallCheck"; | ||
import _createClass from "@babel/runtime/helpers/createClass"; | ||
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn"; | ||
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf"; | ||
import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized"; | ||
import _inherits from "@babel/runtime/helpers/inherits"; | ||
import _defineProperty from "@babel/runtime/helpers/defineProperty"; | ||
import * as tslib_1 from "tslib"; | ||
import React from 'react'; | ||
@@ -12,131 +6,91 @@ import ReactDOM from 'react-dom'; | ||
import { canUseDOM } from 'exenv'; | ||
var createContainer = function createContainer(zIndex) { | ||
var container = document.createElement('div'); | ||
container.setAttribute('class', 'atlaskit-portal'); | ||
container.setAttribute('style', "z-index: ".concat(zIndex, ";")); | ||
return container; | ||
var createContainer = function (zIndex) { | ||
var container = document.createElement('div'); | ||
container.setAttribute('class', 'atlaskit-portal'); | ||
container.setAttribute('style', "z-index: " + zIndex + ";"); | ||
return container; | ||
}; | ||
var body = function body() { | ||
invariant(document && document.body, 'cannot find document.body'); | ||
return document.body; | ||
var body = function () { | ||
invariant(document && document.body, 'cannot find document.body'); | ||
return document.body; | ||
}; | ||
var portalParent = function portalParent() { | ||
var parentElement = document.querySelector('body > .atlaskit-portal-container'); | ||
if (!parentElement) { | ||
var parent = document.createElement('div'); | ||
parent.setAttribute('class', 'atlaskit-portal-container'); | ||
parent.setAttribute('style', "display: flex;"); | ||
body().appendChild(parent); | ||
return parent; | ||
} | ||
return parentElement; | ||
}; // This is a generic component does two things: | ||
var portalParent = function () { | ||
var parentElement = document.querySelector('body > .atlaskit-portal-container'); | ||
if (!parentElement) { | ||
var parent_1 = document.createElement('div'); | ||
parent_1.setAttribute('class', 'atlaskit-portal-container'); | ||
parent_1.setAttribute('style', "display: flex;"); | ||
body().appendChild(parent_1); | ||
return parent_1; | ||
} | ||
return parentElement; | ||
}; | ||
// This is a generic component does two things: | ||
// 1. Portals it's children using React.createPortal | ||
// 2. Creates the DOM node container for the portal based on props | ||
// 3. Ensures DOM the container creates it's own stacking context | ||
var Portal = | ||
/*#__PURE__*/ | ||
function (_React$Component) { | ||
_inherits(Portal, _React$Component); | ||
function Portal() { | ||
var _getPrototypeOf2; | ||
var _this; | ||
_classCallCheck(this, Portal); | ||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
var Portal = /** @class */ (function (_super) { | ||
tslib_1.__extends(Portal, _super); | ||
function Portal() { | ||
var _this = _super !== null && _super.apply(this, arguments) || this; | ||
_this.state = { | ||
container: canUseDOM ? createContainer(_this.props.zIndex) : undefined, | ||
portalIsMounted: false, | ||
}; | ||
return _this; | ||
} | ||
_this = _possibleConstructorReturn(this, (_getPrototypeOf2 = _getPrototypeOf(Portal)).call.apply(_getPrototypeOf2, [this].concat(args))); | ||
_defineProperty(_assertThisInitialized(_this), "state", { | ||
container: canUseDOM ? createContainer(_this.props.zIndex) : undefined, | ||
portalIsMounted: false | ||
}); | ||
return _this; | ||
} | ||
_createClass(Portal, [{ | ||
key: "componentDidUpdate", | ||
value: function componentDidUpdate(prevProps, prevState) { | ||
var container = this.state.container; | ||
var zIndex = this.props.zIndex; | ||
if (container && prevProps.zIndex !== zIndex) { | ||
var newContainer = createContainer(zIndex); | ||
portalParent().replaceChild(container, newContainer); // eslint-disable-next-line react/no-did-update-set-state | ||
Portal.prototype.componentDidUpdate = function (prevProps, prevState) { | ||
var container = this.state.container; | ||
var zIndex = this.props.zIndex; | ||
if (container && prevProps.zIndex !== zIndex) { | ||
var newContainer = createContainer(zIndex); | ||
portalParent().replaceChild(container, newContainer); | ||
// eslint-disable-next-line react/no-did-update-set-state | ||
this.setState({ container: newContainer }); | ||
} | ||
else if (!prevState.container && container) { | ||
// SSR path | ||
portalParent().appendChild(container); | ||
} | ||
}; | ||
Portal.prototype.componentDidMount = function () { | ||
var container = this.state.container; | ||
var zIndex = this.props.zIndex; | ||
if (container) { | ||
portalParent().appendChild(container); | ||
} | ||
else { | ||
// SSR path | ||
var newContainer = createContainer(zIndex); | ||
// eslint-disable-next-line react/no-did-mount-set-state | ||
this.setState({ container: newContainer }); | ||
} | ||
// eslint-disable-next-line react/no-did-mount-set-state | ||
this.setState({ | ||
container: newContainer | ||
portalIsMounted: true, | ||
}); | ||
} else if (!prevState.container && container) { | ||
// SSR path | ||
portalParent().appendChild(container); | ||
} | ||
} | ||
}, { | ||
key: "componentDidMount", | ||
value: function componentDidMount() { | ||
var container = this.state.container; | ||
var zIndex = this.props.zIndex; | ||
if (container) { | ||
portalParent().appendChild(container); | ||
} else { | ||
// SSR path | ||
var newContainer = createContainer(zIndex); // eslint-disable-next-line react/no-did-mount-set-state | ||
this.setState({ | ||
container: newContainer | ||
}); | ||
} // eslint-disable-next-line react/no-did-mount-set-state | ||
this.setState({ | ||
portalIsMounted: true | ||
}); | ||
} | ||
}, { | ||
key: "componentWillUnmount", | ||
value: function componentWillUnmount() { | ||
var container = this.state.container; | ||
if (container) { | ||
portalParent().removeChild(container); // clean up parent element if there are no more portals | ||
var portals = !!document.querySelector('body > .atlaskit-portal-container > .atlaskit-portal'); | ||
if (!portals) { | ||
body().removeChild(portalParent()); | ||
}; | ||
Portal.prototype.componentWillUnmount = function () { | ||
var container = this.state.container; | ||
if (container) { | ||
portalParent().removeChild(container); | ||
// clean up parent element if there are no more portals | ||
var portals = !!document.querySelector('body > .atlaskit-portal-container > .atlaskit-portal'); | ||
if (!portals) { | ||
body().removeChild(portalParent()); | ||
} | ||
} | ||
} | ||
} | ||
}, { | ||
key: "render", | ||
value: function render() { | ||
var _this$state = this.state, | ||
container = _this$state.container, | ||
portalIsMounted = _this$state.portalIsMounted; | ||
return container && portalIsMounted ? ReactDOM.createPortal(this.props.children, container) : null; | ||
} | ||
}]); | ||
return Portal; | ||
}(React.Component); | ||
_defineProperty(Portal, "defaultProps", { | ||
zIndex: 0 | ||
}); | ||
export default Portal; | ||
}; | ||
Portal.prototype.render = function () { | ||
var _a = this.state, container = _a.container, portalIsMounted = _a.portalIsMounted; | ||
return container && portalIsMounted | ||
? ReactDOM.createPortal(this.props.children, container) | ||
: null; | ||
}; | ||
Portal.defaultProps = { | ||
zIndex: 0, | ||
}; | ||
return Portal; | ||
}(React.Component)); | ||
export default Portal; | ||
//# sourceMappingURL=Portal.js.map |
{ | ||
"name": "@atlaskit/portal", | ||
"version": "2.0.2", | ||
"version": "3.0.0", | ||
"sideEffects": false | ||
} |
@@ -1,1 +0,2 @@ | ||
export { default } from './components/Portal'; | ||
export { default } from './components/Portal'; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@atlaskit/portal", | ||
"version": "2.0.2", | ||
"version": "3.0.0", | ||
"description": "Atlaskit wrapper for rendering components in React portals", | ||
@@ -8,3 +8,4 @@ "repository": "https://bitbucket.org/atlassian/atlaskit-mk-2", | ||
"module": "index.js", | ||
"atlaskit:src": "src/index.js", | ||
"types": "index.d.ts", | ||
"atlaskit:src": "src/index.ts", | ||
"sideEffects": false, | ||
@@ -34,3 +35,3 @@ "author": "Atlassian Pty Ltd", | ||
"@atlaskit/docs": "^8.0.0", | ||
"@atlaskit/flag": "^12.0.0", | ||
"@atlaskit/flag": "^12.0.2", | ||
"@atlaskit/icon": "^17.1.2", | ||
@@ -40,3 +41,3 @@ "@atlaskit/inline-dialog": "^11.0.0", | ||
"@atlaskit/onboarding": "^8.0.2", | ||
"@atlaskit/tooltip": "^14.0.0", | ||
"@atlaskit/tooltip": "^14.0.1", | ||
"@atlaskit/visual-regression": "^0.1.0", | ||
@@ -43,0 +44,0 @@ "enzyme": "^3.7.0", |
{ | ||
"name": "@atlaskit/portal", | ||
"version": "2.0.2", | ||
"version": "3.0.0", | ||
"sideEffects": false | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
20664
16
203
1