@atlaskit/portal 4.7.0 → 4.9.0

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 CHANGED
@@ -1,5 +1,29 @@
1
1
  # @atlaskit/portal
2
2
 
3
+ ## 4.9.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#129038](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/129038)
8
+ [`7524331eed2c5`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/7524331eed2c5) -
9
+ New Portal logic for React 18 concurrent renderer behind a feature flag
10
+
11
+ ## 4.8.0
12
+
13
+ ### Minor Changes
14
+
15
+ - [#127511](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/127511)
16
+ [`db30e29344013`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/db30e29344013) -
17
+ Widening range of `react` and `react-dom` peer dependencies from `^16.8.0 || ^17.0.0 || ~18.2.0`
18
+ to the wider range of ``^16.8.0 || ^17.0.0 || ^18.0.0` (where applicable).
19
+
20
+ This change has been done to enable usage of `react@18.3` as well as to have a consistent peer
21
+ dependency range for `react` and `react-dom` for `/platform` packages.
22
+
23
+ ### Patch Changes
24
+
25
+ - Updated dependencies
26
+
3
27
  ## 4.7.0
4
28
 
5
29
  ### Minor Changes
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.default = InternalPortalNew;
8
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
9
+ var _react = require("react");
10
+ var _reactDom = require("react-dom");
11
+ var _useIsomorphicLayoutEffect = require("../hooks/use-isomorphic-layout-effect");
12
+ var _portalDomUtils = require("../utils/portal-dom-utils");
13
+ function InternalPortalNew(props) {
14
+ var zIndex = props.zIndex,
15
+ children = props.children;
16
+ var _useState = (0, _react.useState)(null),
17
+ _useState2 = (0, _slicedToArray2.default)(_useState, 2),
18
+ atlaskitPortal = _useState2[0],
19
+ setAtlaskitPortal = _useState2[1];
20
+ (0, _useIsomorphicLayoutEffect.useIsomorphicLayoutEffect)(function () {
21
+ var tempPortalContainer = (0, _portalDomUtils.createAtlaskitPortal)(zIndex);
22
+ setAtlaskitPortal(tempPortalContainer);
23
+ var portalParent = (0, _portalDomUtils.createPortalParent)();
24
+ if (!tempPortalContainer || !portalParent) {
25
+ return;
26
+ }
27
+ portalParent.appendChild(tempPortalContainer);
28
+ return function () {
29
+ if (tempPortalContainer) {
30
+ portalParent.removeChild(tempPortalContainer);
31
+ }
32
+ setAtlaskitPortal(null);
33
+ };
34
+ }, [zIndex]);
35
+ return atlaskitPortal ? /*#__PURE__*/(0, _reactDom.createPortal)(children, atlaskitPortal) : null;
36
+ }
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.removePortalContainer = exports.createContainer = exports.appendPortalContainerIfNotAppended = void 0;
6
+ exports.removePortalContainer = exports.isDocumentDefined = 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',
@@ -61,4 +61,31 @@ var appendPortalContainerIfNotAppended = exports.appendPortalContainerIfNotAppen
61
61
  if (!container.parentElement) {
62
62
  getPortalParent().appendChild(container);
63
63
  }
64
+ };
65
+ var isDocumentDefined = exports.isDocumentDefined = function isDocumentDefined() {
66
+ return document !== undefined;
67
+ };
68
+ var createAtlaskitPortal = exports.createAtlaskitPortal = function createAtlaskitPortal(zIndex) {
69
+ //atlaskit-portal div
70
+ if (isDocumentDefined()) {
71
+ var atlaskitportal = document.createElement('div');
72
+ atlaskitportal.className = _constants.portalClassName;
73
+ atlaskitportal.style.zIndex = "".concat(zIndex);
74
+ return atlaskitportal;
75
+ }
76
+ };
77
+ var createPortalParent = exports.createPortalParent = function createPortalParent() {
78
+ //atlaskit-portal-container div
79
+ if (isDocumentDefined()) {
80
+ var parentElement = document.querySelector(_constants.portalParentSelector);
81
+ if (!parentElement) {
82
+ var _getBody2;
83
+ var parent = document.createElement('div');
84
+ parent.className = _constants.portalParentClassName;
85
+ parent.style.display = 'flex';
86
+ (_getBody2 = getBody()) === null || _getBody2 === void 0 || _getBody2.appendChild(parent);
87
+ return parent;
88
+ }
89
+ return parentElement;
90
+ }
64
91
  };
@@ -6,7 +6,9 @@ Object.defineProperty(exports, "__esModule", {
6
6
  });
7
7
  exports.default = Portal;
8
8
  var _react = _interopRequireDefault(require("react"));
9
+ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
9
10
  var _internalPortal = _interopRequireDefault(require("./internal/components/internal-portal"));
11
+ var _internalPortalNew = _interopRequireDefault(require("./internal/components/internal-portal-new"));
10
12
  var _useIsSubsequentRender = _interopRequireDefault(require("./internal/hooks/use-is-subsequent-render"));
11
13
  var _usePortalEvent = _interopRequireDefault(require("./internal/hooks/use-portal-event"));
12
14
  function Portal(_ref) {
@@ -17,7 +19,11 @@ function Portal(_ref) {
17
19
  mountStrategy = _ref$mountStrategy === void 0 ? 'effect' : _ref$mountStrategy;
18
20
  var isSubsequentRender = (0, _useIsSubsequentRender.default)(mountStrategy);
19
21
  (0, _usePortalEvent.default)(zIndex);
20
- return isSubsequentRender ? /*#__PURE__*/_react.default.createElement(_internalPortal.default, {
22
+
23
+ // eslint-disable-next-line @atlaskit/platform/ensure-feature-flag-prefix
24
+ return !(0, _platformFeatureFlags.fg)('dsp-19516-design-system-portal-logic-update') ? isSubsequentRender ? /*#__PURE__*/_react.default.createElement(_internalPortal.default, {
25
+ zIndex: zIndex
26
+ }, children) : null : /*#__PURE__*/_react.default.createElement(_internalPortalNew.default, {
21
27
  zIndex: zIndex
22
- }, children) : null;
28
+ }, children);
23
29
  }
@@ -0,0 +1,27 @@
1
+ import { useState } from 'react';
2
+ import { createPortal } from 'react-dom';
3
+ import { useIsomorphicLayoutEffect } from '../hooks/use-isomorphic-layout-effect';
4
+ import { createAtlaskitPortal, createPortalParent } from '../utils/portal-dom-utils';
5
+ export default function InternalPortalNew(props) {
6
+ const {
7
+ zIndex,
8
+ children
9
+ } = props;
10
+ const [atlaskitPortal, setAtlaskitPortal] = useState(null);
11
+ useIsomorphicLayoutEffect(() => {
12
+ const tempPortalContainer = createAtlaskitPortal(zIndex);
13
+ setAtlaskitPortal(tempPortalContainer);
14
+ const portalParent = createPortalParent();
15
+ if (!tempPortalContainer || !portalParent) {
16
+ return;
17
+ }
18
+ portalParent.appendChild(tempPortalContainer);
19
+ return () => {
20
+ if (tempPortalContainer) {
21
+ portalParent.removeChild(tempPortalContainer);
22
+ }
23
+ setAtlaskitPortal(null);
24
+ };
25
+ }, [zIndex]);
26
+ return atlaskitPortal ? /*#__PURE__*/createPortal(children, atlaskitPortal) : null;
27
+ }
@@ -56,4 +56,31 @@ export const appendPortalContainerIfNotAppended = container => {
56
56
  if (!container.parentElement) {
57
57
  getPortalParent().appendChild(container);
58
58
  }
59
+ };
60
+ export const isDocumentDefined = () => {
61
+ return document !== undefined;
62
+ };
63
+ export const createAtlaskitPortal = zIndex => {
64
+ //atlaskit-portal div
65
+ if (isDocumentDefined()) {
66
+ const atlaskitportal = document.createElement('div');
67
+ atlaskitportal.className = portalClassName;
68
+ atlaskitportal.style.zIndex = `${zIndex}`;
69
+ return atlaskitportal;
70
+ }
71
+ };
72
+ export const createPortalParent = () => {
73
+ //atlaskit-portal-container div
74
+ if (isDocumentDefined()) {
75
+ const parentElement = document.querySelector(portalParentSelector);
76
+ if (!parentElement) {
77
+ var _getBody2;
78
+ const parent = document.createElement('div');
79
+ parent.className = portalParentClassName;
80
+ parent.style.display = 'flex';
81
+ (_getBody2 = getBody()) === null || _getBody2 === void 0 ? void 0 : _getBody2.appendChild(parent);
82
+ return parent;
83
+ }
84
+ return parentElement;
85
+ }
59
86
  };
@@ -1,5 +1,7 @@
1
1
  import React from 'react';
2
+ import { fg } from '@atlaskit/platform-feature-flags';
2
3
  import InternalPortal from './internal/components/internal-portal';
4
+ import InternalPortalNew from './internal/components/internal-portal-new';
3
5
  import useIsSubsequentRender from './internal/hooks/use-is-subsequent-render';
4
6
  import useFirePortalEvent from './internal/hooks/use-portal-event';
5
7
  export default function Portal({
@@ -9,7 +11,11 @@ export default function Portal({
9
11
  }) {
10
12
  const isSubsequentRender = useIsSubsequentRender(mountStrategy);
11
13
  useFirePortalEvent(zIndex);
12
- return isSubsequentRender ? /*#__PURE__*/React.createElement(InternalPortal, {
14
+
15
+ // eslint-disable-next-line @atlaskit/platform/ensure-feature-flag-prefix
16
+ return !fg('dsp-19516-design-system-portal-logic-update') ? isSubsequentRender ? /*#__PURE__*/React.createElement(InternalPortal, {
13
17
  zIndex: zIndex
14
- }, children) : null;
18
+ }, children) : null : /*#__PURE__*/React.createElement(InternalPortalNew, {
19
+ zIndex: zIndex
20
+ }, children);
15
21
  }
@@ -0,0 +1,29 @@
1
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
+ import { useState } from 'react';
3
+ import { createPortal } from 'react-dom';
4
+ import { useIsomorphicLayoutEffect } from '../hooks/use-isomorphic-layout-effect';
5
+ import { createAtlaskitPortal, createPortalParent } from '../utils/portal-dom-utils';
6
+ export default function InternalPortalNew(props) {
7
+ var zIndex = props.zIndex,
8
+ children = props.children;
9
+ var _useState = useState(null),
10
+ _useState2 = _slicedToArray(_useState, 2),
11
+ atlaskitPortal = _useState2[0],
12
+ setAtlaskitPortal = _useState2[1];
13
+ useIsomorphicLayoutEffect(function () {
14
+ var tempPortalContainer = createAtlaskitPortal(zIndex);
15
+ setAtlaskitPortal(tempPortalContainer);
16
+ var portalParent = createPortalParent();
17
+ if (!tempPortalContainer || !portalParent) {
18
+ return;
19
+ }
20
+ portalParent.appendChild(tempPortalContainer);
21
+ return function () {
22
+ if (tempPortalContainer) {
23
+ portalParent.removeChild(tempPortalContainer);
24
+ }
25
+ setAtlaskitPortal(null);
26
+ };
27
+ }, [zIndex]);
28
+ return atlaskitPortal ? /*#__PURE__*/createPortal(children, atlaskitPortal) : null;
29
+ }
@@ -56,4 +56,31 @@ export var appendPortalContainerIfNotAppended = function appendPortalContainerIf
56
56
  if (!container.parentElement) {
57
57
  getPortalParent().appendChild(container);
58
58
  }
59
+ };
60
+ export var isDocumentDefined = function isDocumentDefined() {
61
+ return document !== undefined;
62
+ };
63
+ export var createAtlaskitPortal = function createAtlaskitPortal(zIndex) {
64
+ //atlaskit-portal div
65
+ if (isDocumentDefined()) {
66
+ var atlaskitportal = document.createElement('div');
67
+ atlaskitportal.className = portalClassName;
68
+ atlaskitportal.style.zIndex = "".concat(zIndex);
69
+ return atlaskitportal;
70
+ }
71
+ };
72
+ export var createPortalParent = function createPortalParent() {
73
+ //atlaskit-portal-container div
74
+ if (isDocumentDefined()) {
75
+ var parentElement = document.querySelector(portalParentSelector);
76
+ if (!parentElement) {
77
+ var _getBody2;
78
+ var parent = document.createElement('div');
79
+ parent.className = portalParentClassName;
80
+ parent.style.display = 'flex';
81
+ (_getBody2 = getBody()) === null || _getBody2 === void 0 || _getBody2.appendChild(parent);
82
+ return parent;
83
+ }
84
+ return parentElement;
85
+ }
59
86
  };
@@ -1,5 +1,7 @@
1
1
  import React from 'react';
2
+ import { fg } from '@atlaskit/platform-feature-flags';
2
3
  import InternalPortal from './internal/components/internal-portal';
4
+ import InternalPortalNew from './internal/components/internal-portal-new';
3
5
  import useIsSubsequentRender from './internal/hooks/use-is-subsequent-render';
4
6
  import useFirePortalEvent from './internal/hooks/use-portal-event';
5
7
  export default function Portal(_ref) {
@@ -10,7 +12,11 @@ export default function Portal(_ref) {
10
12
  mountStrategy = _ref$mountStrategy === void 0 ? 'effect' : _ref$mountStrategy;
11
13
  var isSubsequentRender = useIsSubsequentRender(mountStrategy);
12
14
  useFirePortalEvent(zIndex);
13
- return isSubsequentRender ? /*#__PURE__*/React.createElement(InternalPortal, {
15
+
16
+ // eslint-disable-next-line @atlaskit/platform/ensure-feature-flag-prefix
17
+ return !fg('dsp-19516-design-system-portal-logic-update') ? isSubsequentRender ? /*#__PURE__*/React.createElement(InternalPortal, {
14
18
  zIndex: zIndex
15
- }, children) : null;
19
+ }, children) : null : /*#__PURE__*/React.createElement(InternalPortalNew, {
20
+ zIndex: zIndex
21
+ }, children);
16
22
  }
@@ -0,0 +1,7 @@
1
+ /// <reference types="react" />
2
+ interface InternalPortalProps {
3
+ children: React.ReactNode;
4
+ zIndex: number | string;
5
+ }
6
+ export default function InternalPortalNew(props: InternalPortalProps): import("react").ReactPortal | null;
7
+ export {};
@@ -15,3 +15,6 @@ export declare const removePortalContainer: (container: HTMLDivElement) => void;
15
15
  * @param {HTMLDivElement | undefined} container - portal container to be added to portal parent container
16
16
  */
17
17
  export declare const appendPortalContainerIfNotAppended: (container: HTMLDivElement) => void;
18
+ export declare const isDocumentDefined: () => boolean;
19
+ export declare const createAtlaskitPortal: (zIndex: number | string) => HTMLDivElement | undefined;
20
+ export declare const createPortalParent: () => Element | undefined;
@@ -0,0 +1,7 @@
1
+ /// <reference types="react" />
2
+ interface InternalPortalProps {
3
+ children: React.ReactNode;
4
+ zIndex: number | string;
5
+ }
6
+ export default function InternalPortalNew(props: InternalPortalProps): import("react").ReactPortal | null;
7
+ export {};
@@ -15,3 +15,6 @@ export declare const removePortalContainer: (container: HTMLDivElement) => void;
15
15
  * @param {HTMLDivElement | undefined} container - portal container to be added to portal parent container
16
16
  */
17
17
  export declare const appendPortalContainerIfNotAppended: (container: HTMLDivElement) => void;
18
+ export declare const isDocumentDefined: () => boolean;
19
+ export declare const createAtlaskitPortal: (zIndex: number | string) => HTMLDivElement | undefined;
20
+ export declare const createPortalParent: () => Element | undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/portal",
3
- "version": "4.7.0",
3
+ "version": "4.9.0",
4
4
  "description": "A wrapper for rendering components in React portals.",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -39,22 +39,24 @@
39
39
  ".": "./src/index.tsx"
40
40
  },
41
41
  "dependencies": {
42
- "@atlaskit/theme": "^12.11.0",
42
+ "@atlaskit/platform-feature-flags": "^0.3.0",
43
+ "@atlaskit/theme": "^12.12.0",
43
44
  "@babel/runtime": "^7.0.0"
44
45
  },
45
46
  "peerDependencies": {
46
- "react": "^16.8.0 || ^17.0.0 || ~18.2.0",
47
- "react-dom": "^16.8.0 || ^17.0.0 || ~18.2.0"
47
+ "react": "^16.8.0 || ^17.0.0 || ^18.0.0",
48
+ "react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0"
48
49
  },
49
50
  "devDependencies": {
50
51
  "@af/accessibility-testing": "*",
51
52
  "@af/integration-testing": "*",
52
- "@atlaskit/ds-lib": "^2.3.0",
53
- "@atlaskit/modal-dialog": "^12.14.0",
53
+ "@atlaskit/ds-lib": "^2.4.0",
54
+ "@atlaskit/modal-dialog": "^12.15.0",
54
55
  "@atlaskit/ssr": "*",
55
- "@atlaskit/tokens": "^1.57.0",
56
- "@atlaskit/tooltip": "^18.6.0",
56
+ "@atlaskit/tokens": "^1.58.0",
57
+ "@atlaskit/tooltip": "^18.7.0",
57
58
  "@atlaskit/visual-regression": "*",
59
+ "@atlassian/feature-flags-test-utils": "^0.2.0",
58
60
  "@emotion/react": "^11.7.1",
59
61
  "@testing-library/react": "^12.1.5",
60
62
  "@testing-library/react-hooks": "^8.0.1",
@@ -88,5 +90,10 @@
88
90
  ]
89
91
  }
90
92
  },
91
- "homepage": "https://atlassian.design/components/portal/"
93
+ "homepage": "https://atlassian.design/components/portal/",
94
+ "platform-feature-flags": {
95
+ "dsp-19516-design-system-portal-logic-update": {
96
+ "type": "boolean"
97
+ }
98
+ }
92
99
  }