@atlaskit/portal 5.3.2 → 5.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -0
- package/dist/cjs/internal/components/internal-portal-new.js +35 -14
- package/dist/cjs/internal/components/internal-portal.js +11 -1
- package/dist/cjs/internal/utils/portal-dom-utils.js +13 -2
- package/dist/cjs/portal.js +7 -3
- package/dist/es2019/internal/components/internal-portal-new.js +36 -15
- package/dist/es2019/internal/components/internal-portal.js +10 -1
- package/dist/es2019/internal/utils/portal-dom-utils.js +12 -1
- package/dist/es2019/portal.js +6 -3
- package/dist/esm/internal/components/internal-portal-new.js +36 -15
- package/dist/esm/internal/components/internal-portal.js +11 -1
- package/dist/esm/internal/utils/portal-dom-utils.js +12 -1
- package/dist/esm/portal.js +7 -3
- package/dist/types/internal/components/internal-portal-new.d.ts +1 -0
- package/dist/types/internal/components/internal-portal.d.ts +1 -0
- package/dist/types/internal/utils/portal-dom-utils.d.ts +1 -0
- package/dist/types/portal.d.ts +1 -1
- package/dist/types/types.d.ts +4 -0
- package/dist/types-ts4.5/internal/components/internal-portal-new.d.ts +1 -0
- package/dist/types-ts4.5/internal/components/internal-portal.d.ts +1 -0
- package/dist/types-ts4.5/internal/utils/portal-dom-utils.d.ts +1 -0
- package/dist/types-ts4.5/portal.d.ts +1 -1
- package/dist/types-ts4.5/types.d.ts +4 -0
- package/package.json +12 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @atlaskit/portal
|
|
2
2
|
|
|
3
|
+
## 5.4.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`02483200273ec`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/02483200273ec) -
|
|
8
|
+
Enrol all Design System UI packages into the React Compiler with platform gating via
|
|
9
|
+
isReactCompilerActivePlatform.
|
|
10
|
+
- Updated dependencies
|
|
11
|
+
|
|
12
|
+
## 5.4.0
|
|
13
|
+
|
|
14
|
+
### Minor Changes
|
|
15
|
+
|
|
16
|
+
- [`399dfa9f10273`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/399dfa9f10273) -
|
|
17
|
+
[ux] Added an `isClosed` property that closes the portal cleanly and unmounts it
|
|
18
|
+
|
|
3
19
|
## 5.3.2
|
|
4
20
|
|
|
5
21
|
### Patch Changes
|
|
@@ -10,32 +10,53 @@ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/sli
|
|
|
10
10
|
var _react = _interopRequireWildcard(require("react"));
|
|
11
11
|
var _reactDom = require("react-dom");
|
|
12
12
|
var _appProvider = require("@atlaskit/app-provider");
|
|
13
|
+
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
13
14
|
var _useIsomorphicLayoutEffect = require("../hooks/use-isomorphic-layout-effect");
|
|
14
15
|
var _portalDomUtils = require("../utils/portal-dom-utils");
|
|
15
16
|
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
|
|
16
17
|
function InternalPortalNew(props) {
|
|
17
18
|
var zIndex = props.zIndex,
|
|
18
|
-
children = props.children
|
|
19
|
+
children = props.children,
|
|
20
|
+
isClosed = props.isClosed;
|
|
19
21
|
var _useState = (0, _react.useState)(null),
|
|
20
22
|
_useState2 = (0, _slicedToArray2.default)(_useState, 2),
|
|
21
23
|
atlaskitPortal = _useState2[0],
|
|
22
24
|
setAtlaskitPortal = _useState2[1];
|
|
23
25
|
var colorMode = (0, _appProvider.useColorMode)();
|
|
24
26
|
(0, _useIsomorphicLayoutEffect.useIsomorphicLayoutEffect)(function () {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
27
|
+
if ((0, _platformFeatureFlags.fg)('import_into_jsm_in_template_gallery_killswitch')) {
|
|
28
|
+
if (!isClosed) {
|
|
29
|
+
var tempPortalContainer = (0, _portalDomUtils.createAtlaskitPortal)(zIndex);
|
|
30
|
+
setAtlaskitPortal(tempPortalContainer);
|
|
31
|
+
var portalParent = (0, _portalDomUtils.createPortalParent)();
|
|
32
|
+
if (!tempPortalContainer || !portalParent) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
portalParent.appendChild(tempPortalContainer);
|
|
36
|
+
return function () {
|
|
37
|
+
if (portalParent) {
|
|
38
|
+
portalParent.removeChild(tempPortalContainer);
|
|
39
|
+
!portalParent.hasChildNodes() && (0, _portalDomUtils.removePortalParent)(portalParent);
|
|
40
|
+
}
|
|
41
|
+
setAtlaskitPortal(null);
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
} else {
|
|
45
|
+
var _tempPortalContainer = (0, _portalDomUtils.createAtlaskitPortal)(zIndex);
|
|
46
|
+
setAtlaskitPortal(_tempPortalContainer);
|
|
47
|
+
var _portalParent = (0, _portalDomUtils.createPortalParent)();
|
|
48
|
+
if (!_tempPortalContainer || !_portalParent) {
|
|
49
|
+
return;
|
|
35
50
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
51
|
+
_portalParent.appendChild(_tempPortalContainer);
|
|
52
|
+
return function () {
|
|
53
|
+
if (_tempPortalContainer) {
|
|
54
|
+
_portalParent.removeChild(_tempPortalContainer);
|
|
55
|
+
}
|
|
56
|
+
setAtlaskitPortal(null);
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
}, [zIndex, isClosed, _platformFeatureFlags.fg]);
|
|
39
60
|
|
|
40
61
|
/**
|
|
41
62
|
* We wrap portal children with a Suspense boundary because in React 18 concurrent,
|
|
@@ -8,11 +8,14 @@ exports.default = InternalPortal;
|
|
|
8
8
|
var _react = _interopRequireWildcard(require("react"));
|
|
9
9
|
var _reactDom = require("react-dom");
|
|
10
10
|
var _appProvider = require("@atlaskit/app-provider");
|
|
11
|
+
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
11
12
|
var _portalDomUtils = require("../utils/portal-dom-utils");
|
|
12
13
|
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
|
|
13
14
|
function InternalPortal(props) {
|
|
14
15
|
var zIndex = props.zIndex,
|
|
15
|
-
children = props.children
|
|
16
|
+
children = props.children,
|
|
17
|
+
_props$isClosed = props.isClosed,
|
|
18
|
+
isClosed = _props$isClosed === void 0 ? false : _props$isClosed;
|
|
16
19
|
var container = (0, _react.useMemo)(function () {
|
|
17
20
|
return (0, _portalDomUtils.createContainer)(zIndex);
|
|
18
21
|
}, [zIndex]);
|
|
@@ -23,6 +26,13 @@ function InternalPortal(props) {
|
|
|
23
26
|
// For any further changes, ensure that the container does not have a
|
|
24
27
|
// parent besides the portal parent.
|
|
25
28
|
(0, _portalDomUtils.appendPortalContainerIfNotAppended)(container);
|
|
29
|
+
(0, _react.useEffect)(function () {
|
|
30
|
+
if ((0, _platformFeatureFlags.fg)('import_into_jsm_in_template_gallery_killswitch')) {
|
|
31
|
+
if (isClosed) {
|
|
32
|
+
(0, _portalDomUtils.removePortalContainer)(container);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}, [isClosed, container]);
|
|
26
36
|
(0, _react.useEffect)(function () {
|
|
27
37
|
return function () {
|
|
28
38
|
(0, _portalDomUtils.removePortalContainer)(container);
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.removePortalContainer = exports.createPortalParent = exports.createContainer = exports.createAtlaskitPortal = exports.appendPortalContainerIfNotAppended = void 0;
|
|
6
|
+
exports.removePortalParent = exports.removePortalContainer = exports.createPortalParent = exports.createContainer = exports.createAtlaskitPortal = exports.appendPortalContainerIfNotAppended = void 0;
|
|
7
7
|
var _constants = require("../constants");
|
|
8
8
|
/**
|
|
9
9
|
* Creates a new portal container element with provided z-index and class name 'atlaskit-portal',
|
|
@@ -50,7 +50,10 @@ var getPortalParent = function getPortalParent() {
|
|
|
50
50
|
* @param {HTMLDivElement | undefined} container - portal container to be removed from portal parent container
|
|
51
51
|
*/
|
|
52
52
|
var removePortalContainer = exports.removePortalContainer = function removePortalContainer(container) {
|
|
53
|
-
getPortalParent()
|
|
53
|
+
var parent = getPortalParent();
|
|
54
|
+
if (parent.contains(container)) {
|
|
55
|
+
parent.removeChild(container);
|
|
56
|
+
}
|
|
54
57
|
};
|
|
55
58
|
|
|
56
59
|
/**
|
|
@@ -90,4 +93,12 @@ var createPortalParent = exports.createPortalParent = function createPortalParen
|
|
|
90
93
|
return parentElement;
|
|
91
94
|
}
|
|
92
95
|
return;
|
|
96
|
+
};
|
|
97
|
+
var removePortalParent = exports.removePortalParent = function removePortalParent(parentElement) {
|
|
98
|
+
if (isDocumentDefined()) {
|
|
99
|
+
if (parentElement) {
|
|
100
|
+
var _getBody3;
|
|
101
|
+
(_getBody3 = getBody()) === null || _getBody3 === void 0 || _getBody3.removeChild(parentElement);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
93
104
|
};
|
package/dist/cjs/portal.js
CHANGED
|
@@ -16,12 +16,16 @@ function Portal(_ref) {
|
|
|
16
16
|
zIndex = _ref$zIndex === void 0 ? 0 : _ref$zIndex,
|
|
17
17
|
children = _ref.children,
|
|
18
18
|
_ref$mountStrategy = _ref.mountStrategy,
|
|
19
|
-
mountStrategy = _ref$mountStrategy === void 0 ? 'effect' : _ref$mountStrategy
|
|
19
|
+
mountStrategy = _ref$mountStrategy === void 0 ? 'effect' : _ref$mountStrategy,
|
|
20
|
+
_ref$isClosed = _ref.isClosed,
|
|
21
|
+
isClosed = _ref$isClosed === void 0 ? false : _ref$isClosed;
|
|
20
22
|
var isSubsequentRender = (0, _useIsSubsequentRender.default)(mountStrategy);
|
|
21
23
|
(0, _usePortalEvent.default)(zIndex);
|
|
22
24
|
return !(0, _platformFeatureFlags.fg)('platform_design_system_team_portal_logic_r18_fix') ? isSubsequentRender ? /*#__PURE__*/_react.default.createElement(_internalPortal.default, {
|
|
23
|
-
zIndex: zIndex
|
|
25
|
+
zIndex: zIndex,
|
|
26
|
+
isClosed: isClosed
|
|
24
27
|
}, children) : null : /*#__PURE__*/_react.default.createElement(_internalPortalNew.default, {
|
|
25
|
-
zIndex: zIndex
|
|
28
|
+
zIndex: zIndex,
|
|
29
|
+
isClosed: isClosed
|
|
26
30
|
}, children);
|
|
27
31
|
}
|
|
@@ -1,30 +1,51 @@
|
|
|
1
1
|
import React, { Suspense, useState } from 'react';
|
|
2
2
|
import { createPortal } from 'react-dom';
|
|
3
3
|
import { ThemeProvider, useColorMode } from '@atlaskit/app-provider';
|
|
4
|
+
import { fg } from '@atlaskit/platform-feature-flags';
|
|
4
5
|
import { useIsomorphicLayoutEffect } from '../hooks/use-isomorphic-layout-effect';
|
|
5
|
-
import { createAtlaskitPortal, createPortalParent } from '../utils/portal-dom-utils';
|
|
6
|
+
import { createAtlaskitPortal, createPortalParent, removePortalParent } from '../utils/portal-dom-utils';
|
|
6
7
|
export default function InternalPortalNew(props) {
|
|
7
8
|
const {
|
|
8
9
|
zIndex,
|
|
9
|
-
children
|
|
10
|
+
children,
|
|
11
|
+
isClosed
|
|
10
12
|
} = props;
|
|
11
13
|
const [atlaskitPortal, setAtlaskitPortal] = useState(null);
|
|
12
14
|
const colorMode = useColorMode();
|
|
13
15
|
useIsomorphicLayoutEffect(() => {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
16
|
+
if (fg('import_into_jsm_in_template_gallery_killswitch')) {
|
|
17
|
+
if (!isClosed) {
|
|
18
|
+
let tempPortalContainer = createAtlaskitPortal(zIndex);
|
|
19
|
+
setAtlaskitPortal(tempPortalContainer);
|
|
20
|
+
const portalParent = createPortalParent();
|
|
21
|
+
if (!tempPortalContainer || !portalParent) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
portalParent.appendChild(tempPortalContainer);
|
|
25
|
+
return () => {
|
|
26
|
+
if (portalParent) {
|
|
27
|
+
portalParent.removeChild(tempPortalContainer);
|
|
28
|
+
!portalParent.hasChildNodes() && removePortalParent(portalParent);
|
|
29
|
+
}
|
|
30
|
+
setAtlaskitPortal(null);
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
} else {
|
|
34
|
+
const tempPortalContainer = createAtlaskitPortal(zIndex);
|
|
35
|
+
setAtlaskitPortal(tempPortalContainer);
|
|
36
|
+
const portalParent = createPortalParent();
|
|
37
|
+
if (!tempPortalContainer || !portalParent) {
|
|
38
|
+
return;
|
|
24
39
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
40
|
+
portalParent.appendChild(tempPortalContainer);
|
|
41
|
+
return () => {
|
|
42
|
+
if (tempPortalContainer) {
|
|
43
|
+
portalParent.removeChild(tempPortalContainer);
|
|
44
|
+
}
|
|
45
|
+
setAtlaskitPortal(null);
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
}, [zIndex, isClosed, fg]);
|
|
28
49
|
|
|
29
50
|
/**
|
|
30
51
|
* We wrap portal children with a Suspense boundary because in React 18 concurrent,
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import React, { useEffect, useMemo } from 'react';
|
|
2
2
|
import { createPortal } from 'react-dom';
|
|
3
3
|
import { ThemeProvider, useColorMode } from '@atlaskit/app-provider';
|
|
4
|
+
import { fg } from '@atlaskit/platform-feature-flags';
|
|
4
5
|
import { appendPortalContainerIfNotAppended, createContainer, removePortalContainer } from '../utils/portal-dom-utils';
|
|
5
6
|
export default function InternalPortal(props) {
|
|
6
7
|
const {
|
|
7
8
|
zIndex,
|
|
8
|
-
children
|
|
9
|
+
children,
|
|
10
|
+
isClosed = false
|
|
9
11
|
} = props;
|
|
10
12
|
const container = useMemo(() => createContainer(zIndex), [zIndex]);
|
|
11
13
|
const colorMode = useColorMode();
|
|
@@ -15,6 +17,13 @@ export default function InternalPortal(props) {
|
|
|
15
17
|
// For any further changes, ensure that the container does not have a
|
|
16
18
|
// parent besides the portal parent.
|
|
17
19
|
appendPortalContainerIfNotAppended(container);
|
|
20
|
+
useEffect(() => {
|
|
21
|
+
if (fg('import_into_jsm_in_template_gallery_killswitch')) {
|
|
22
|
+
if (isClosed) {
|
|
23
|
+
removePortalContainer(container);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}, [isClosed, container]);
|
|
18
27
|
useEffect(() => {
|
|
19
28
|
return () => {
|
|
20
29
|
removePortalContainer(container);
|
|
@@ -45,7 +45,10 @@ const getPortalParent = () => {
|
|
|
45
45
|
* @param {HTMLDivElement | undefined} container - portal container to be removed from portal parent container
|
|
46
46
|
*/
|
|
47
47
|
export const removePortalContainer = container => {
|
|
48
|
-
getPortalParent()
|
|
48
|
+
const parent = getPortalParent();
|
|
49
|
+
if (parent.contains(container)) {
|
|
50
|
+
parent.removeChild(container);
|
|
51
|
+
}
|
|
49
52
|
};
|
|
50
53
|
|
|
51
54
|
/**
|
|
@@ -85,4 +88,12 @@ export const createPortalParent = () => {
|
|
|
85
88
|
return parentElement;
|
|
86
89
|
}
|
|
87
90
|
return;
|
|
91
|
+
};
|
|
92
|
+
export const removePortalParent = parentElement => {
|
|
93
|
+
if (isDocumentDefined()) {
|
|
94
|
+
if (parentElement) {
|
|
95
|
+
var _getBody3;
|
|
96
|
+
(_getBody3 = getBody()) === null || _getBody3 === void 0 ? void 0 : _getBody3.removeChild(parentElement);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
88
99
|
};
|
package/dist/es2019/portal.js
CHANGED
|
@@ -7,13 +7,16 @@ import useFirePortalEvent from './internal/hooks/use-portal-event';
|
|
|
7
7
|
export default function Portal({
|
|
8
8
|
zIndex = 0,
|
|
9
9
|
children,
|
|
10
|
-
mountStrategy = 'effect'
|
|
10
|
+
mountStrategy = 'effect',
|
|
11
|
+
isClosed = false
|
|
11
12
|
}) {
|
|
12
13
|
const isSubsequentRender = useIsSubsequentRender(mountStrategy);
|
|
13
14
|
useFirePortalEvent(zIndex);
|
|
14
15
|
return !fg('platform_design_system_team_portal_logic_r18_fix') ? isSubsequentRender ? /*#__PURE__*/React.createElement(InternalPortal, {
|
|
15
|
-
zIndex: zIndex
|
|
16
|
+
zIndex: zIndex,
|
|
17
|
+
isClosed: isClosed
|
|
16
18
|
}, children) : null : /*#__PURE__*/React.createElement(InternalPortalNew, {
|
|
17
|
-
zIndex: zIndex
|
|
19
|
+
zIndex: zIndex,
|
|
20
|
+
isClosed: isClosed
|
|
18
21
|
}, children);
|
|
19
22
|
}
|
|
@@ -2,31 +2,52 @@ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
|
2
2
|
import React, { Suspense, useState } from 'react';
|
|
3
3
|
import { createPortal } from 'react-dom';
|
|
4
4
|
import { ThemeProvider, useColorMode } from '@atlaskit/app-provider';
|
|
5
|
+
import { fg } from '@atlaskit/platform-feature-flags';
|
|
5
6
|
import { useIsomorphicLayoutEffect } from '../hooks/use-isomorphic-layout-effect';
|
|
6
|
-
import { createAtlaskitPortal, createPortalParent } from '../utils/portal-dom-utils';
|
|
7
|
+
import { createAtlaskitPortal, createPortalParent, removePortalParent } from '../utils/portal-dom-utils';
|
|
7
8
|
export default function InternalPortalNew(props) {
|
|
8
9
|
var zIndex = props.zIndex,
|
|
9
|
-
children = props.children
|
|
10
|
+
children = props.children,
|
|
11
|
+
isClosed = props.isClosed;
|
|
10
12
|
var _useState = useState(null),
|
|
11
13
|
_useState2 = _slicedToArray(_useState, 2),
|
|
12
14
|
atlaskitPortal = _useState2[0],
|
|
13
15
|
setAtlaskitPortal = _useState2[1];
|
|
14
16
|
var colorMode = useColorMode();
|
|
15
17
|
useIsomorphicLayoutEffect(function () {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
18
|
+
if (fg('import_into_jsm_in_template_gallery_killswitch')) {
|
|
19
|
+
if (!isClosed) {
|
|
20
|
+
var tempPortalContainer = createAtlaskitPortal(zIndex);
|
|
21
|
+
setAtlaskitPortal(tempPortalContainer);
|
|
22
|
+
var portalParent = createPortalParent();
|
|
23
|
+
if (!tempPortalContainer || !portalParent) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
portalParent.appendChild(tempPortalContainer);
|
|
27
|
+
return function () {
|
|
28
|
+
if (portalParent) {
|
|
29
|
+
portalParent.removeChild(tempPortalContainer);
|
|
30
|
+
!portalParent.hasChildNodes() && removePortalParent(portalParent);
|
|
31
|
+
}
|
|
32
|
+
setAtlaskitPortal(null);
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
} else {
|
|
36
|
+
var _tempPortalContainer = createAtlaskitPortal(zIndex);
|
|
37
|
+
setAtlaskitPortal(_tempPortalContainer);
|
|
38
|
+
var _portalParent = createPortalParent();
|
|
39
|
+
if (!_tempPortalContainer || !_portalParent) {
|
|
40
|
+
return;
|
|
26
41
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
42
|
+
_portalParent.appendChild(_tempPortalContainer);
|
|
43
|
+
return function () {
|
|
44
|
+
if (_tempPortalContainer) {
|
|
45
|
+
_portalParent.removeChild(_tempPortalContainer);
|
|
46
|
+
}
|
|
47
|
+
setAtlaskitPortal(null);
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
}, [zIndex, isClosed, fg]);
|
|
30
51
|
|
|
31
52
|
/**
|
|
32
53
|
* We wrap portal children with a Suspense boundary because in React 18 concurrent,
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import React, { useEffect, useMemo } from 'react';
|
|
2
2
|
import { createPortal } from 'react-dom';
|
|
3
3
|
import { ThemeProvider, useColorMode } from '@atlaskit/app-provider';
|
|
4
|
+
import { fg } from '@atlaskit/platform-feature-flags';
|
|
4
5
|
import { appendPortalContainerIfNotAppended, createContainer, removePortalContainer } from '../utils/portal-dom-utils';
|
|
5
6
|
export default function InternalPortal(props) {
|
|
6
7
|
var zIndex = props.zIndex,
|
|
7
|
-
children = props.children
|
|
8
|
+
children = props.children,
|
|
9
|
+
_props$isClosed = props.isClosed,
|
|
10
|
+
isClosed = _props$isClosed === void 0 ? false : _props$isClosed;
|
|
8
11
|
var container = useMemo(function () {
|
|
9
12
|
return createContainer(zIndex);
|
|
10
13
|
}, [zIndex]);
|
|
@@ -15,6 +18,13 @@ export default function InternalPortal(props) {
|
|
|
15
18
|
// For any further changes, ensure that the container does not have a
|
|
16
19
|
// parent besides the portal parent.
|
|
17
20
|
appendPortalContainerIfNotAppended(container);
|
|
21
|
+
useEffect(function () {
|
|
22
|
+
if (fg('import_into_jsm_in_template_gallery_killswitch')) {
|
|
23
|
+
if (isClosed) {
|
|
24
|
+
removePortalContainer(container);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}, [isClosed, container]);
|
|
18
28
|
useEffect(function () {
|
|
19
29
|
return function () {
|
|
20
30
|
removePortalContainer(container);
|
|
@@ -45,7 +45,10 @@ var getPortalParent = function getPortalParent() {
|
|
|
45
45
|
* @param {HTMLDivElement | undefined} container - portal container to be removed from portal parent container
|
|
46
46
|
*/
|
|
47
47
|
export var removePortalContainer = function removePortalContainer(container) {
|
|
48
|
-
getPortalParent()
|
|
48
|
+
var parent = getPortalParent();
|
|
49
|
+
if (parent.contains(container)) {
|
|
50
|
+
parent.removeChild(container);
|
|
51
|
+
}
|
|
49
52
|
};
|
|
50
53
|
|
|
51
54
|
/**
|
|
@@ -85,4 +88,12 @@ export var createPortalParent = function createPortalParent() {
|
|
|
85
88
|
return parentElement;
|
|
86
89
|
}
|
|
87
90
|
return;
|
|
91
|
+
};
|
|
92
|
+
export var removePortalParent = function removePortalParent(parentElement) {
|
|
93
|
+
if (isDocumentDefined()) {
|
|
94
|
+
if (parentElement) {
|
|
95
|
+
var _getBody3;
|
|
96
|
+
(_getBody3 = getBody()) === null || _getBody3 === void 0 || _getBody3.removeChild(parentElement);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
88
99
|
};
|
package/dist/esm/portal.js
CHANGED
|
@@ -9,12 +9,16 @@ export default function Portal(_ref) {
|
|
|
9
9
|
zIndex = _ref$zIndex === void 0 ? 0 : _ref$zIndex,
|
|
10
10
|
children = _ref.children,
|
|
11
11
|
_ref$mountStrategy = _ref.mountStrategy,
|
|
12
|
-
mountStrategy = _ref$mountStrategy === void 0 ? 'effect' : _ref$mountStrategy
|
|
12
|
+
mountStrategy = _ref$mountStrategy === void 0 ? 'effect' : _ref$mountStrategy,
|
|
13
|
+
_ref$isClosed = _ref.isClosed,
|
|
14
|
+
isClosed = _ref$isClosed === void 0 ? false : _ref$isClosed;
|
|
13
15
|
var isSubsequentRender = useIsSubsequentRender(mountStrategy);
|
|
14
16
|
useFirePortalEvent(zIndex);
|
|
15
17
|
return !fg('platform_design_system_team_portal_logic_r18_fix') ? isSubsequentRender ? /*#__PURE__*/React.createElement(InternalPortal, {
|
|
16
|
-
zIndex: zIndex
|
|
18
|
+
zIndex: zIndex,
|
|
19
|
+
isClosed: isClosed
|
|
17
20
|
}, children) : null : /*#__PURE__*/React.createElement(InternalPortalNew, {
|
|
18
|
-
zIndex: zIndex
|
|
21
|
+
zIndex: zIndex,
|
|
22
|
+
isClosed: isClosed
|
|
19
23
|
}, children);
|
|
20
24
|
}
|
|
@@ -17,3 +17,4 @@ export declare const removePortalContainer: (container: HTMLDivElement) => void;
|
|
|
17
17
|
export declare const appendPortalContainerIfNotAppended: (container: HTMLDivElement) => void;
|
|
18
18
|
export declare const createAtlaskitPortal: (zIndex: number | string) => HTMLDivElement | undefined;
|
|
19
19
|
export declare const createPortalParent: () => Element | undefined;
|
|
20
|
+
export declare const removePortalParent: (parentElement: Element) => void;
|
package/dist/types/portal.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import type { PortalProps } from './types';
|
|
3
|
-
export default function Portal({ zIndex, children, mountStrategy, }: PortalProps): React.JSX.Element | null;
|
|
3
|
+
export default function Portal({ zIndex, children, mountStrategy, isClosed, }: PortalProps): React.JSX.Element | null;
|
package/dist/types/types.d.ts
CHANGED
|
@@ -11,6 +11,10 @@ export interface PortalProps {
|
|
|
11
11
|
* Note: UseLayoutEffect can lead to performance issues and is discouraged.
|
|
12
12
|
*/
|
|
13
13
|
mountStrategy?: MountStrategy;
|
|
14
|
+
/**
|
|
15
|
+
* Whether the portal is closed.
|
|
16
|
+
*/
|
|
17
|
+
isClosed?: boolean;
|
|
14
18
|
}
|
|
15
19
|
/**
|
|
16
20
|
* Custom event object that will be fired when Atlassian Portal component is mounted and unmounted
|
|
@@ -17,3 +17,4 @@ export declare const removePortalContainer: (container: HTMLDivElement) => void;
|
|
|
17
17
|
export declare const appendPortalContainerIfNotAppended: (container: HTMLDivElement) => void;
|
|
18
18
|
export declare const createAtlaskitPortal: (zIndex: number | string) => HTMLDivElement | undefined;
|
|
19
19
|
export declare const createPortalParent: () => Element | undefined;
|
|
20
|
+
export declare const removePortalParent: (parentElement: Element) => void;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import type { PortalProps } from './types';
|
|
3
|
-
export default function Portal({ zIndex, children, mountStrategy, }: PortalProps): React.JSX.Element | null;
|
|
3
|
+
export default function Portal({ zIndex, children, mountStrategy, isClosed, }: PortalProps): React.JSX.Element | null;
|
|
@@ -11,6 +11,10 @@ export interface PortalProps {
|
|
|
11
11
|
* Note: UseLayoutEffect can lead to performance issues and is discouraged.
|
|
12
12
|
*/
|
|
13
13
|
mountStrategy?: MountStrategy;
|
|
14
|
+
/**
|
|
15
|
+
* Whether the portal is closed.
|
|
16
|
+
*/
|
|
17
|
+
isClosed?: boolean;
|
|
14
18
|
}
|
|
15
19
|
/**
|
|
16
20
|
* Custom event object that will be fired when Atlassian Portal component is mounted and unmounted
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/portal",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.4.1",
|
|
4
4
|
"description": "A wrapper for rendering components in React portals.",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"registry": "https://registry.npmjs.org/"
|
|
@@ -25,6 +25,13 @@
|
|
|
25
25
|
],
|
|
26
26
|
"atlaskit:src": "src/index.tsx",
|
|
27
27
|
"atlassian": {
|
|
28
|
+
"react-compiler": {
|
|
29
|
+
"enabled": true,
|
|
30
|
+
"gating": {
|
|
31
|
+
"source": "@atlassian/react-compiler-gating",
|
|
32
|
+
"importSpecifierName": "isReactCompilerActivePlatform"
|
|
33
|
+
}
|
|
34
|
+
},
|
|
28
35
|
"team": "Design System Team",
|
|
29
36
|
"website": {
|
|
30
37
|
"name": "Portal",
|
|
@@ -60,6 +67,7 @@
|
|
|
60
67
|
"@atlaskit/tokens": "^11.4.0",
|
|
61
68
|
"@atlaskit/tooltip": "^21.1.0",
|
|
62
69
|
"@atlassian/feature-flags-test-utils": "^1.0.0",
|
|
70
|
+
"@atlassian/react-compiler-gating": "workspace:^",
|
|
63
71
|
"@atlassian/ssr-tests": "workspace:^",
|
|
64
72
|
"@atlassian/structured-docs-types": "workspace:^",
|
|
65
73
|
"@compiled/react": "^0.20.0",
|
|
@@ -96,6 +104,9 @@
|
|
|
96
104
|
"platform-feature-flags": {
|
|
97
105
|
"platform_design_system_team_portal_logic_r18_fix": {
|
|
98
106
|
"type": "boolean"
|
|
107
|
+
},
|
|
108
|
+
"import_into_jsm_in_template_gallery_killswitch": {
|
|
109
|
+
"type": "boolean"
|
|
99
110
|
}
|
|
100
111
|
}
|
|
101
112
|
}
|