@fluentui/react-portal 9.0.0-nightly.f81b28ceb3.1 → 9.0.0-rc.11
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.json +494 -16
- package/CHANGELOG.md +219 -73
- package/dist/{react-portal.d.ts → index.d.ts} +11 -11
- package/{lib → dist}/tsdoc-metadata.json +0 -0
- package/lib/Portal.js.map +1 -1
- package/lib/components/Portal/Portal.js +8 -6
- package/lib/components/Portal/Portal.js.map +1 -1
- package/lib/components/Portal/Portal.types.js.map +1 -1
- package/lib/components/Portal/index.js.map +1 -1
- package/lib/components/Portal/renderPortal.js +6 -2
- package/lib/components/Portal/renderPortal.js.map +1 -1
- package/lib/components/Portal/usePortal.js +23 -17
- package/lib/components/Portal/usePortal.js.map +1 -1
- package/lib/components/Portal/usePortalMountNode.js +27 -21
- package/lib/components/Portal/usePortalMountNode.js.map +1 -1
- package/lib/index.js +1 -1
- package/lib/index.js.map +1 -1
- package/lib/virtualParent/elementContains.js +18 -14
- package/lib/virtualParent/elementContains.js.map +1 -1
- package/lib/virtualParent/getParent.js +2 -1
- package/lib/virtualParent/getParent.js.map +1 -1
- package/lib/virtualParent/getVirtualParent.js +8 -5
- package/lib/virtualParent/getVirtualParent.js.map +1 -1
- package/lib/virtualParent/index.js.map +1 -1
- package/lib/virtualParent/isVirtualElement.js +1 -1
- package/lib/virtualParent/isVirtualElement.js.map +1 -1
- package/lib/virtualParent/setVirtualParent.js +11 -8
- package/lib/virtualParent/setVirtualParent.js.map +1 -1
- package/lib/virtualParent/types.js.map +1 -1
- package/lib-commonjs/Portal.js +7 -2
- package/lib-commonjs/Portal.js.map +1 -1
- package/lib-commonjs/components/Portal/Portal.js +16 -7
- package/lib-commonjs/components/Portal/Portal.js.map +1 -1
- package/lib-commonjs/components/Portal/Portal.types.js +4 -1
- package/lib-commonjs/components/Portal/Portal.types.js.map +1 -1
- package/lib-commonjs/components/Portal/index.js +10 -2
- package/lib-commonjs/components/Portal/index.js.map +1 -1
- package/lib-commonjs/components/Portal/renderPortal.js +18 -7
- package/lib-commonjs/components/Portal/renderPortal.js.map +1 -1
- package/lib-commonjs/components/Portal/usePortal.js +39 -24
- package/lib-commonjs/components/Portal/usePortal.js.map +1 -1
- package/lib-commonjs/components/Portal/usePortalMountNode.js +41 -26
- package/lib-commonjs/components/Portal/usePortalMountNode.js.map +1 -1
- package/lib-commonjs/index.js +41 -7
- package/lib-commonjs/index.js.map +1 -1
- package/lib-commonjs/virtualParent/elementContains.js +26 -16
- package/lib-commonjs/virtualParent/elementContains.js.map +1 -1
- package/lib-commonjs/virtualParent/getParent.js +10 -3
- package/lib-commonjs/virtualParent/getParent.js.map +1 -1
- package/lib-commonjs/virtualParent/getVirtualParent.js +16 -7
- package/lib-commonjs/virtualParent/getVirtualParent.js.map +1 -1
- package/lib-commonjs/virtualParent/index.js +11 -2
- package/lib-commonjs/virtualParent/index.js.map +1 -1
- package/lib-commonjs/virtualParent/isVirtualElement.js +7 -2
- package/lib-commonjs/virtualParent/isVirtualElement.js.map +1 -1
- package/lib-commonjs/virtualParent/setVirtualParent.js +17 -9
- package/lib-commonjs/virtualParent/setVirtualParent.js.map +1 -1
- package/lib-commonjs/virtualParent/types.js +4 -1
- package/lib-commonjs/virtualParent/types.js.map +1 -1
- package/package.json +17 -22
- package/lib/Portal.d.ts +0 -1
- package/lib/common/isConformant.d.ts +0 -4
- package/lib/common/isConformant.js +0 -9
- package/lib/common/isConformant.js.map +0 -1
- package/lib/components/Portal/Portal.d.ts +0 -6
- package/lib/components/Portal/Portal.types.d.ts +0 -21
- package/lib/components/Portal/index.d.ts +0 -4
- package/lib/components/Portal/renderPortal.d.ts +0 -6
- package/lib/components/Portal/usePortal.d.ts +0 -9
- package/lib/components/Portal/usePortalMountNode.d.ts +0 -10
- package/lib/index.d.ts +0 -2
- package/lib/virtualParent/elementContains.d.ts +0 -7
- package/lib/virtualParent/getParent.d.ts +0 -5
- package/lib/virtualParent/getVirtualParent.d.ts +0 -4
- package/lib/virtualParent/index.d.ts +0 -5
- package/lib/virtualParent/isVirtualElement.d.ts +0 -5
- package/lib/virtualParent/setVirtualParent.d.ts +0 -7
- package/lib/virtualParent/types.d.ts +0 -5
- package/lib-commonjs/Portal.d.ts +0 -1
- package/lib-commonjs/common/isConformant.d.ts +0 -4
- package/lib-commonjs/common/isConformant.js +0 -13
- package/lib-commonjs/common/isConformant.js.map +0 -1
- package/lib-commonjs/components/Portal/Portal.d.ts +0 -6
- package/lib-commonjs/components/Portal/Portal.types.d.ts +0 -21
- package/lib-commonjs/components/Portal/index.d.ts +0 -4
- package/lib-commonjs/components/Portal/renderPortal.d.ts +0 -6
- package/lib-commonjs/components/Portal/usePortal.d.ts +0 -9
- package/lib-commonjs/components/Portal/usePortalMountNode.d.ts +0 -10
- package/lib-commonjs/index.d.ts +0 -2
- package/lib-commonjs/virtualParent/elementContains.d.ts +0 -7
- package/lib-commonjs/virtualParent/getParent.d.ts +0 -5
- package/lib-commonjs/virtualParent/getVirtualParent.d.ts +0 -4
- package/lib-commonjs/virtualParent/index.d.ts +0 -5
- package/lib-commonjs/virtualParent/isVirtualElement.d.ts +0 -5
- package/lib-commonjs/virtualParent/setVirtualParent.d.ts +0 -7
- package/lib-commonjs/virtualParent/types.d.ts +0 -5
@@ -9,25 +9,25 @@ import * as React_2 from 'react';
|
|
9
9
|
export declare function elementContains(parent: HTMLElement | null, child: HTMLElement | null): boolean;
|
10
10
|
|
11
11
|
/**
|
12
|
-
*
|
12
|
+
* A portal provides a way to render children into a DOM node
|
13
|
+
* that exists outside the DOM hierarchy of the parent component.
|
13
14
|
*/
|
14
15
|
export declare const Portal: React_2.FC<PortalProps>;
|
15
16
|
|
16
|
-
export declare type
|
17
|
+
export declare type PortalProps = {
|
17
18
|
/**
|
18
19
|
* React children
|
19
20
|
*/
|
20
|
-
children
|
21
|
+
children?: React_2.ReactNode;
|
21
22
|
/**
|
22
23
|
* Where the portal children are mounted on DOM
|
23
|
-
*
|
24
|
+
*
|
25
|
+
* @default a new element on document.body without any styling
|
24
26
|
*/
|
25
|
-
mountNode
|
27
|
+
mountNode?: HTMLElement | null;
|
26
28
|
};
|
27
29
|
|
28
|
-
export declare type
|
29
|
-
|
30
|
-
export declare type PortalState = PortalCommons & {
|
30
|
+
export declare type PortalState = Pick<PortalProps, 'children'> & Required<Pick<PortalProps, 'mountNode'>> & {
|
31
31
|
/** Indicates if a Portal should be rendered. */
|
32
32
|
shouldRender: boolean;
|
33
33
|
/**
|
@@ -39,7 +39,7 @@ export declare type PortalState = PortalCommons & {
|
|
39
39
|
/**
|
40
40
|
* Render the final JSX of Portal
|
41
41
|
*/
|
42
|
-
export declare const
|
42
|
+
export declare const renderPortal_unstable: (state: PortalState) => React_2.ReactElement;
|
43
43
|
|
44
44
|
/**
|
45
45
|
* Sets the virtual parent of an element.
|
@@ -52,10 +52,10 @@ export declare function setVirtualParent(child: HTMLElement, parent?: HTMLElemen
|
|
52
52
|
/**
|
53
53
|
* Create the state required to render Portal.
|
54
54
|
*
|
55
|
-
* The returned state can be modified with hooks such as usePortalStyles, before being passed to
|
55
|
+
* The returned state can be modified with hooks such as usePortalStyles, before being passed to renderPortal_unstable.
|
56
56
|
*
|
57
57
|
* @param props - props from this instance of Portal
|
58
58
|
*/
|
59
|
-
export declare const
|
59
|
+
export declare const usePortal_unstable: (props: PortalProps) => PortalState;
|
60
60
|
|
61
61
|
export { }
|
File without changes
|
package/lib/Portal.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"Portal.js","sourceRoot":"","sources":["
|
1
|
+
{"version":3,"file":"Portal.js","sourceRoot":"../src/","sources":["Portal.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAC","sourcesContent":["export * from './components/Portal/index';\n"]}
|
@@ -1,11 +1,13 @@
|
|
1
|
-
import {
|
2
|
-
import {
|
1
|
+
import { usePortal_unstable } from './usePortal';
|
2
|
+
import { renderPortal_unstable } from './renderPortal';
|
3
3
|
/**
|
4
|
-
*
|
4
|
+
* A portal provides a way to render children into a DOM node
|
5
|
+
* that exists outside the DOM hierarchy of the parent component.
|
5
6
|
*/
|
6
|
-
|
7
|
-
|
8
|
-
|
7
|
+
|
8
|
+
export const Portal = props => {
|
9
|
+
const state = usePortal_unstable(props);
|
10
|
+
return renderPortal_unstable(state);
|
9
11
|
};
|
10
12
|
Portal.displayName = 'Portal';
|
11
13
|
//# sourceMappingURL=Portal.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"
|
1
|
+
{"version":3,"sources":["components/Portal/Portal.tsx"],"names":[],"mappings":"AAEA,SAAS,kBAAT,QAAmC,aAAnC;AACA,SAAS,qBAAT,QAAsC,gBAAtC;AAGA;;;AAGG;;AACH,OAAO,MAAM,MAAM,GAA0B,KAAK,IAAG;AACnD,QAAM,KAAK,GAAG,kBAAkB,CAAC,KAAD,CAAhC;AAEA,SAAO,qBAAqB,CAAC,KAAD,CAA5B;AACD,CAJM;AAMP,MAAM,CAAC,WAAP,GAAqB,QAArB","sourcesContent":["import * as React from 'react';\n\nimport { usePortal_unstable } from './usePortal';\nimport { renderPortal_unstable } from './renderPortal';\nimport type { PortalProps } from './Portal.types';\n\n/**\n * A portal provides a way to render children into a DOM node\n * that exists outside the DOM hierarchy of the parent component.\n */\nexport const Portal: React.FC<PortalProps> = props => {\n const state = usePortal_unstable(props);\n\n return renderPortal_unstable(state);\n};\n\nPortal.displayName = 'Portal';\n"],"sourceRoot":"../src/"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"Portal.types.js","sourceRoot":"","sources":["
|
1
|
+
{"version":3,"file":"Portal.types.js","sourceRoot":"../src/","sources":["components/Portal/Portal.types.ts"],"names":[],"mappings":"","sourcesContent":["import * as React from 'react';\n\nexport type PortalProps = {\n /**\n * React children\n */\n children?: React.ReactNode;\n\n /**\n * Where the portal children are mounted on DOM\n *\n * @default a new element on document.body without any styling\n */\n mountNode?: HTMLElement | null;\n};\n\nexport type PortalState = Pick<PortalProps, 'children'> &\n Required<Pick<PortalProps, 'mountNode'>> & {\n /** Indicates if a Portal should be rendered. */\n shouldRender: boolean;\n\n /**\n * Ref to the root span element as virtual parent\n */\n virtualParentRootRef: React.MutableRefObject<HTMLSpanElement | null>;\n };\n"]}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"../src/","sources":["components/Portal/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC","sourcesContent":["export * from './Portal';\nexport * from './Portal.types';\nexport * from './renderPortal';\nexport * from './usePortal';\n"]}
|
@@ -3,7 +3,11 @@ import * as React from 'react';
|
|
3
3
|
/**
|
4
4
|
* Render the final JSX of Portal
|
5
5
|
*/
|
6
|
-
|
7
|
-
|
6
|
+
|
7
|
+
export const renderPortal_unstable = state => {
|
8
|
+
return /*#__PURE__*/React.createElement("span", {
|
9
|
+
hidden: true,
|
10
|
+
ref: state.virtualParentRootRef
|
11
|
+
}, state.shouldRender && state.mountNode && /*#__PURE__*/ReactDOM.createPortal(state.children, state.mountNode));
|
8
12
|
};
|
9
13
|
//# sourceMappingURL=renderPortal.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"
|
1
|
+
{"version":3,"sources":["components/Portal/renderPortal.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,QAAZ,MAA0B,WAA1B;AACA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AAGA;;AAEG;;AACH,OAAO,MAAM,qBAAqB,GAAI,KAAD,IAA2C;AAC9E,sBACE,KAAA,CAAA,aAAA,CAAA,MAAA,EAAA;AAAM,IAAA,MAAM,EAAA,IAAZ;AAAa,IAAA,GAAG,EAAE,KAAK,CAAC;AAAxB,GAAA,EACG,KAAK,CAAC,YAAN,IAAsB,KAAK,CAAC,SAA5B,iBAAyC,QAAQ,CAAC,YAAT,CAAsB,KAAK,CAAC,QAA5B,EAAsC,KAAK,CAAC,SAA5C,CAD5C,CADF;AAKD,CANM","sourcesContent":["import * as ReactDOM from 'react-dom';\nimport * as React from 'react';\nimport type { PortalState } from './Portal.types';\n\n/**\n * Render the final JSX of Portal\n */\nexport const renderPortal_unstable = (state: PortalState): React.ReactElement => {\n return (\n <span hidden ref={state.virtualParentRootRef}>\n {state.shouldRender && state.mountNode && ReactDOM.createPortal(state.children, state.mountNode)}\n </span>\n );\n};\n"],"sourceRoot":"../src/"}
|
@@ -5,25 +5,31 @@ import { setVirtualParent } from '../../virtualParent/index';
|
|
5
5
|
/**
|
6
6
|
* Create the state required to render Portal.
|
7
7
|
*
|
8
|
-
* The returned state can be modified with hooks such as usePortalStyles, before being passed to
|
8
|
+
* The returned state can be modified with hooks such as usePortalStyles, before being passed to renderPortal_unstable.
|
9
9
|
*
|
10
10
|
* @param props - props from this instance of Portal
|
11
11
|
*/
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
12
|
+
|
13
|
+
export const usePortal_unstable = props => {
|
14
|
+
const {
|
15
|
+
children,
|
16
|
+
mountNode
|
17
|
+
} = props;
|
18
|
+
const virtualParentRootRef = React.useRef(null);
|
19
|
+
const fallbackMountNode = usePortalMountNode({
|
20
|
+
disabled: !!mountNode
|
21
|
+
});
|
22
|
+
const state = {
|
23
|
+
children,
|
24
|
+
mountNode: mountNode !== null && mountNode !== void 0 ? mountNode : fallbackMountNode,
|
25
|
+
shouldRender: !useIsSSR(),
|
26
|
+
virtualParentRootRef
|
27
|
+
};
|
28
|
+
React.useEffect(() => {
|
29
|
+
if (state.virtualParentRootRef.current && state.mountNode) {
|
30
|
+
setVirtualParent(state.mountNode, state.virtualParentRootRef.current);
|
31
|
+
}
|
32
|
+
}, [state.virtualParentRootRef, state.mountNode]);
|
33
|
+
return state;
|
28
34
|
};
|
29
35
|
//# sourceMappingURL=usePortal.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"
|
1
|
+
{"version":3,"sources":["components/Portal/usePortal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SAAS,QAAT,QAAyB,2BAAzB;AACA,SAAS,kBAAT,QAAmC,sBAAnC;AACA,SAAS,gBAAT,QAAiC,2BAAjC;AAGA;;;;;;AAMG;;AACH,OAAO,MAAM,kBAAkB,GAAI,KAAD,IAAoC;AACpE,QAAM;AAAE,IAAA,QAAF;AAAY,IAAA;AAAZ,MAA0B,KAAhC;AAEA,QAAM,oBAAoB,GAAG,KAAK,CAAC,MAAN,CAA8B,IAA9B,CAA7B;AACA,QAAM,iBAAiB,GAAG,kBAAkB,CAAC;AAAE,IAAA,QAAQ,EAAE,CAAC,CAAC;AAAd,GAAD,CAA5C;AAEA,QAAM,KAAK,GAAgB;AACzB,IAAA,QADyB;AAEzB,IAAA,SAAS,EAAE,SAAS,KAAA,IAAT,IAAA,SAAS,KAAA,KAAA,CAAT,GAAA,SAAA,GAAa,iBAFC;AAGzB,IAAA,YAAY,EAAE,CAAC,QAAQ,EAHE;AAIzB,IAAA;AAJyB,GAA3B;AAOA,EAAA,KAAK,CAAC,SAAN,CAAgB,MAAK;AACnB,QAAI,KAAK,CAAC,oBAAN,CAA2B,OAA3B,IAAsC,KAAK,CAAC,SAAhD,EAA2D;AACzD,MAAA,gBAAgB,CAAC,KAAK,CAAC,SAAP,EAAkB,KAAK,CAAC,oBAAN,CAA2B,OAA7C,CAAhB;AACD;AACF,GAJD,EAIG,CAAC,KAAK,CAAC,oBAAP,EAA6B,KAAK,CAAC,SAAnC,CAJH;AAMA,SAAO,KAAP;AACD,CApBM","sourcesContent":["import * as React from 'react';\nimport { useIsSSR } from '@fluentui/react-utilities';\nimport { usePortalMountNode } from './usePortalMountNode';\nimport { setVirtualParent } from '../../virtualParent/index';\nimport type { PortalProps, PortalState } from './Portal.types';\n\n/**\n * Create the state required to render Portal.\n *\n * The returned state can be modified with hooks such as usePortalStyles, before being passed to renderPortal_unstable.\n *\n * @param props - props from this instance of Portal\n */\nexport const usePortal_unstable = (props: PortalProps): PortalState => {\n const { children, mountNode } = props;\n\n const virtualParentRootRef = React.useRef<HTMLSpanElement>(null);\n const fallbackMountNode = usePortalMountNode({ disabled: !!mountNode });\n\n const state: PortalState = {\n children,\n mountNode: mountNode ?? fallbackMountNode,\n shouldRender: !useIsSSR(),\n virtualParentRootRef,\n };\n\n React.useEffect(() => {\n if (state.virtualParentRootRef.current && state.mountNode) {\n setVirtualParent(state.mountNode, state.virtualParentRootRef.current);\n }\n }, [state.virtualParentRootRef, state.mountNode]);\n\n return state;\n};\n"],"sourceRoot":"../src/"}
|
@@ -5,26 +5,32 @@ import { useKeyboardNavAttribute } from '@fluentui/react-tabster';
|
|
5
5
|
/**
|
6
6
|
* Creates a new element on a document.body to mount portals
|
7
7
|
*/
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
return
|
8
|
+
|
9
|
+
export const usePortalMountNode = options => {
|
10
|
+
const themeClassName = useThemeClassName();
|
11
|
+
const {
|
12
|
+
targetDocument,
|
13
|
+
dir
|
14
|
+
} = useFluent();
|
15
|
+
const element = React.useMemo(() => {
|
16
|
+
if (targetDocument === undefined || options.disabled) {
|
17
|
+
return null;
|
18
|
+
}
|
19
|
+
|
20
|
+
const newElement = targetDocument.createElement('div');
|
21
|
+
newElement.setAttribute('class', themeClassName);
|
22
|
+
newElement.setAttribute('dir', dir);
|
23
|
+
targetDocument.body.appendChild(newElement);
|
24
|
+
return newElement;
|
25
|
+
}, [targetDocument, themeClassName, dir, options.disabled]);
|
26
|
+
useKeyboardNavAttribute().current = element;
|
27
|
+
useIsomorphicLayoutEffect(() => {
|
28
|
+
return () => {
|
29
|
+
var _a;
|
30
|
+
|
31
|
+
(_a = element === null || element === void 0 ? void 0 : element.parentElement) === null || _a === void 0 ? void 0 : _a.removeChild(element);
|
32
|
+
};
|
33
|
+
}, [element]);
|
34
|
+
return element;
|
29
35
|
};
|
30
36
|
//# sourceMappingURL=usePortalMountNode.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"
|
1
|
+
{"version":3,"sources":["components/Portal/usePortalMountNode.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SAAS,yBAAT,QAA0C,2BAA1C;AACA,SAAS,iBAAT,EAA4B,SAA5B,QAA6C,iCAA7C;AACA,SAAS,uBAAT,QAAwC,yBAAxC;AASA;;AAEG;;AACH,OAAO,MAAM,kBAAkB,GAAI,OAAD,IAA2D;AAC3F,QAAM,cAAc,GAAG,iBAAiB,EAAxC;AACA,QAAM;AAAE,IAAA,cAAF;AAAkB,IAAA;AAAlB,MAA0B,SAAS,EAAzC;AAEA,QAAM,OAAO,GAAG,KAAK,CAAC,OAAN,CAAc,MAAK;AACjC,QAAI,cAAc,KAAK,SAAnB,IAAgC,OAAO,CAAC,QAA5C,EAAsD;AACpD,aAAO,IAAP;AACD;;AAED,UAAM,UAAU,GAAG,cAAc,CAAC,aAAf,CAA6B,KAA7B,CAAnB;AACA,IAAA,UAAU,CAAC,YAAX,CAAwB,OAAxB,EAAiC,cAAjC;AACA,IAAA,UAAU,CAAC,YAAX,CAAwB,KAAxB,EAA+B,GAA/B;AACA,IAAA,cAAc,CAAC,IAAf,CAAoB,WAApB,CAAgC,UAAhC;AAEA,WAAO,UAAP;AACD,GAXe,EAWb,CAAC,cAAD,EAAiB,cAAjB,EAAiC,GAAjC,EAAsC,OAAO,CAAC,QAA9C,CAXa,CAAhB;AAaC,EAAA,uBAAuB,GAA2C,OAAlE,GAA4E,OAA5E;AAED,EAAA,yBAAyB,CAAC,MAAK;AAC7B,WAAO,MAAK;;;AACV,OAAA,EAAA,GAAA,OAAO,KAAA,IAAP,IAAA,OAAO,KAAA,KAAA,CAAP,GAAO,KAAA,CAAP,GAAA,OAAO,CAAE,aAAT,MAAsB,IAAtB,IAAsB,EAAA,KAAA,KAAA,CAAtB,GAAsB,KAAA,CAAtB,GAAsB,EAAA,CAAE,WAAF,CAAc,OAAd,CAAtB;AACD,KAFD;AAGD,GAJwB,EAItB,CAAC,OAAD,CAJsB,CAAzB;AAMA,SAAO,OAAP;AACD,CA1BM","sourcesContent":["import * as React from 'react';\nimport { useIsomorphicLayoutEffect } from '@fluentui/react-utilities';\nimport { useThemeClassName, useFluent } from '@fluentui/react-shared-contexts';\nimport { useKeyboardNavAttribute } from '@fluentui/react-tabster';\n\nexport type UsePortalMountNodeOptions = {\n /**\n * Since hooks cannot be called conditionally use this flag to disable creating the node\n */\n disabled?: boolean;\n};\n\n/**\n * Creates a new element on a document.body to mount portals\n */\nexport const usePortalMountNode = (options: UsePortalMountNodeOptions): HTMLElement | null => {\n const themeClassName = useThemeClassName();\n const { targetDocument, dir } = useFluent();\n\n const element = React.useMemo(() => {\n if (targetDocument === undefined || options.disabled) {\n return null;\n }\n\n const newElement = targetDocument.createElement('div');\n newElement.setAttribute('class', themeClassName);\n newElement.setAttribute('dir', dir);\n targetDocument.body.appendChild(newElement);\n\n return newElement;\n }, [targetDocument, themeClassName, dir, options.disabled]);\n\n (useKeyboardNavAttribute() as React.MutableRefObject<HTMLElement>).current = element!;\n\n useIsomorphicLayoutEffect(() => {\n return () => {\n element?.parentElement?.removeChild(element);\n };\n }, [element]);\n\n return element;\n};\n"],"sourceRoot":"../src/"}
|
package/lib/index.js
CHANGED
package/lib/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"../src/","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,qBAAqB,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAE9F,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC","sourcesContent":["export { Portal, renderPortal_unstable, usePortal_unstable } from './components/Portal/index';\nexport type { PortalProps, PortalState } from './components/Portal/index';\nexport { elementContains, setVirtualParent } from './virtualParent/index';\n"]}
|
@@ -5,22 +5,26 @@ import { getParent } from './getParent';
|
|
5
5
|
*
|
6
6
|
* @returns true if the child can find the parent in its virtual hierarchy
|
7
7
|
*/
|
8
|
+
|
8
9
|
export function elementContains(parent, child) {
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
10
|
+
if (!parent || !child) {
|
11
|
+
return false;
|
12
|
+
}
|
13
|
+
|
14
|
+
if (parent === child) {
|
15
|
+
return true;
|
16
|
+
} else {
|
17
|
+
while (child) {
|
18
|
+
const nextParent = getParent(child);
|
19
|
+
|
20
|
+
if (nextParent === parent) {
|
13
21
|
return true;
|
22
|
+
}
|
23
|
+
|
24
|
+
child = nextParent;
|
14
25
|
}
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
if (nextParent === parent) {
|
19
|
-
return true;
|
20
|
-
}
|
21
|
-
child = nextParent;
|
22
|
-
}
|
23
|
-
}
|
24
|
-
return false;
|
26
|
+
}
|
27
|
+
|
28
|
+
return false;
|
25
29
|
}
|
26
30
|
//# sourceMappingURL=elementContains.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"
|
1
|
+
{"version":3,"sources":["virtualParent/elementContains.ts"],"names":[],"mappings":"AAAA,SAAS,SAAT,QAA0B,aAA1B;AACA;;;;;AAKG;;AACH,OAAM,SAAU,eAAV,CAA0B,MAA1B,EAAsD,KAAtD,EAA+E;AACnF,MAAI,CAAC,MAAD,IAAW,CAAC,KAAhB,EAAuB;AACrB,WAAO,KAAP;AACD;;AAED,MAAI,MAAM,KAAK,KAAf,EAAsB;AACpB,WAAO,IAAP;AACD,GAFD,MAEO;AACL,WAAO,KAAP,EAAc;AACZ,YAAM,UAAU,GAAuB,SAAS,CAAC,KAAD,CAAhD;;AAEA,UAAI,UAAU,KAAK,MAAnB,EAA2B;AACzB,eAAO,IAAP;AACD;;AAED,MAAA,KAAK,GAAG,UAAR;AACD;AACF;;AAED,SAAO,KAAP;AACD","sourcesContent":["import { getParent } from './getParent';\n/**\n * Similar functionality to `element.contains` DOM API for use with out of order DOM elements that\n * checks the virtual parent hierarchy. If a virtual parents exists, it is chosen over the actual parent\n *\n * @returns true if the child can find the parent in its virtual hierarchy\n */\nexport function elementContains(parent: HTMLElement | null, child: HTMLElement | null): boolean {\n if (!parent || !child) {\n return false;\n }\n\n if (parent === child) {\n return true;\n } else {\n while (child) {\n const nextParent: HTMLElement | null = getParent(child);\n\n if (nextParent === parent) {\n return true;\n }\n\n child = nextParent;\n }\n }\n\n return false;\n}\n"],"sourceRoot":"../src/"}
|
@@ -3,7 +3,8 @@ import { getVirtualParent } from './getVirtualParent';
|
|
3
3
|
* Gets the element which is the parent of a given element.
|
4
4
|
* This method prefers the virtual parent over real DOM parent when present.
|
5
5
|
*/
|
6
|
+
|
6
7
|
export function getParent(child) {
|
7
|
-
|
8
|
+
return child && getVirtualParent(child) || (child === null || child === void 0 ? void 0 : child.parentNode);
|
8
9
|
}
|
9
10
|
//# sourceMappingURL=getParent.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"
|
1
|
+
{"version":3,"sources":["virtualParent/getParent.ts"],"names":[],"mappings":"AAAA,SAAS,gBAAT,QAAiC,oBAAjC;AAEA;;;AAGG;;AACH,OAAM,SAAU,SAAV,CAAoB,KAApB,EAA6C;AACjD,SAAQ,KAAK,IAAI,gBAAgB,CAAC,KAAD,CAA1B,KAAuC,KAAK,KAAA,IAAL,IAAA,KAAK,KAAA,KAAA,CAAL,GAAK,KAAA,CAAL,GAAA,KAAK,CAAE,UAA9C,CAAP;AACD","sourcesContent":["import { getVirtualParent } from './getVirtualParent';\n\n/**\n * Gets the element which is the parent of a given element.\n * This method prefers the virtual parent over real DOM parent when present.\n */\nexport function getParent(child: HTMLElement | null): HTMLElement | null {\n return (child && getVirtualParent(child)) || (child?.parentNode as HTMLElement | null);\n}\n"],"sourceRoot":"../src/"}
|
@@ -2,11 +2,14 @@ import { isVirtualElement } from './isVirtualElement';
|
|
2
2
|
/**
|
3
3
|
* Gets the virtual parent given the child element, if it exists.
|
4
4
|
*/
|
5
|
+
|
5
6
|
export function getVirtualParent(child) {
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
7
|
+
let parent;
|
8
|
+
|
9
|
+
if (isVirtualElement(child)) {
|
10
|
+
parent = child._virtual.parent;
|
11
|
+
}
|
12
|
+
|
13
|
+
return parent;
|
11
14
|
}
|
12
15
|
//# sourceMappingURL=getVirtualParent.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"
|
1
|
+
{"version":3,"sources":["virtualParent/getVirtualParent.ts"],"names":[],"mappings":"AAAA,SAAS,gBAAT,QAAiC,oBAAjC;AACA;;AAEG;;AACH,OAAM,SAAU,gBAAV,CAA2B,KAA3B,EAA6C;AACjD,MAAI,MAAJ;;AACA,MAAI,gBAAgB,CAAC,KAAD,CAApB,EAA6B;AAC3B,IAAA,MAAM,GAAG,KAAK,CAAC,QAAN,CAAe,MAAxB;AACD;;AACD,SAAO,MAAP;AACD","sourcesContent":["import { isVirtualElement } from './isVirtualElement';\n/**\n * Gets the virtual parent given the child element, if it exists.\n */\nexport function getVirtualParent(child: HTMLElement): HTMLElement | undefined {\n let parent: HTMLElement | undefined;\n if (isVirtualElement(child)) {\n parent = child._virtual.parent;\n }\n return parent;\n}\n"],"sourceRoot":"../src/"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"../src/","sources":["virtualParent/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,aAAa,CAAC;AAC5B,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC","sourcesContent":["export * from './elementContains';\nexport * from './getParent';\nexport * from './getVirtualParent';\nexport * from './isVirtualElement';\nexport * from './setVirtualParent';\n"]}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"
|
1
|
+
{"version":3,"sources":["virtualParent/isVirtualElement.ts"],"names":[],"mappings":"AAEA;;AAEG;AACH,OAAM,SAAU,gBAAV,CAA2B,OAA3B,EAAgE;AACpE,SAAO,OAAO,IAAI,CAAC,CAAkB,OAAQ,CAAC,QAA9C;AACD","sourcesContent":["import type { VirtualElement } from './types';\n\n/**\n * Determines whether or not an element has the virtual hierarchy extension.\n */\nexport function isVirtualElement(element: HTMLElement | VirtualElement): element is VirtualElement {\n return element && !!(<VirtualElement>element)._virtual;\n}\n"],"sourceRoot":"../src/"}
|
@@ -5,13 +5,16 @@
|
|
5
5
|
* @param parent - The virtual parent, use `undefined` to remove a virtual parent relationship
|
6
6
|
*/
|
7
7
|
export function setVirtualParent(child, parent) {
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
virtualChild._virtual
|
8
|
+
if (!child) {
|
9
|
+
return;
|
10
|
+
}
|
11
|
+
|
12
|
+
const virtualChild = child;
|
13
|
+
|
14
|
+
if (!virtualChild._virtual) {
|
15
|
+
virtualChild._virtual = {};
|
16
|
+
}
|
17
|
+
|
18
|
+
virtualChild._virtual.parent = parent || undefined;
|
16
19
|
}
|
17
20
|
//# sourceMappingURL=setVirtualParent.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"
|
1
|
+
{"version":3,"sources":["virtualParent/setVirtualParent.ts"],"names":[],"mappings":"AAEA;;;;;AAKG;AACH,OAAM,SAAU,gBAAV,CAA2B,KAA3B,EAA+C,MAA/C,EAAmE;AACvE,MAAI,CAAC,KAAL,EAAY;AACV;AACD;;AAED,QAAM,YAAY,GAAmB,KAArC;;AAEA,MAAI,CAAC,YAAY,CAAC,QAAlB,EAA4B;AAC1B,IAAA,YAAY,CAAC,QAAb,GAAwB,EAAxB;AACD;;AAED,EAAA,YAAY,CAAC,QAAb,CAAsB,MAAtB,GAA+B,MAAM,IAAI,SAAzC;AACD","sourcesContent":["import type { VirtualElement } from './types';\n\n/**\n * Sets the virtual parent of an element.\n *\n * @param child - Theme element to set the virtual parent\n * @param parent - The virtual parent, use `undefined` to remove a virtual parent relationship\n */\nexport function setVirtualParent(child: HTMLElement, parent?: HTMLElement): void {\n if (!child) {\n return;\n }\n\n const virtualChild = <VirtualElement>child;\n\n if (!virtualChild._virtual) {\n virtualChild._virtual = {};\n }\n\n virtualChild._virtual.parent = parent || undefined;\n}\n"],"sourceRoot":"../src/"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"../src/","sources":["virtualParent/types.ts"],"names":[],"mappings":"","sourcesContent":["export interface VirtualElement extends HTMLElement {\n _virtual: {\n parent?: HTMLElement;\n };\n}\n"]}
|
package/lib-commonjs/Portal.js
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
"use strict";
|
2
|
-
|
3
|
-
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
|
7
|
+
const tslib_1 = /*#__PURE__*/require("tslib");
|
8
|
+
|
4
9
|
tslib_1.__exportStar(require("./components/Portal/index"), exports);
|
5
10
|
//# sourceMappingURL=Portal.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"
|
1
|
+
{"version":3,"sources":["Portal.ts"],"names":[],"mappings":";;;;;;;;AAAA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,2BAAA,CAAA,EAAA,OAAA","sourcesContent":["export * from './components/Portal/index';\n"],"sourceRoot":"../src/"}
|
@@ -1,15 +1,24 @@
|
|
1
1
|
"use strict";
|
2
|
-
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
3
6
|
exports.Portal = void 0;
|
4
|
-
|
5
|
-
|
7
|
+
|
8
|
+
const usePortal_1 = /*#__PURE__*/require("./usePortal");
|
9
|
+
|
10
|
+
const renderPortal_1 = /*#__PURE__*/require("./renderPortal");
|
6
11
|
/**
|
7
|
-
*
|
12
|
+
* A portal provides a way to render children into a DOM node
|
13
|
+
* that exists outside the DOM hierarchy of the parent component.
|
8
14
|
*/
|
9
|
-
|
10
|
-
|
11
|
-
|
15
|
+
|
16
|
+
|
17
|
+
const Portal = props => {
|
18
|
+
const state = usePortal_1.usePortal_unstable(props);
|
19
|
+
return renderPortal_1.renderPortal_unstable(state);
|
12
20
|
};
|
21
|
+
|
13
22
|
exports.Portal = Portal;
|
14
23
|
exports.Portal.displayName = 'Portal';
|
15
24
|
//# sourceMappingURL=Portal.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"
|
1
|
+
{"version":3,"sources":["components/Portal/Portal.tsx"],"names":[],"mappings":";;;;;;;AAEA,MAAA,WAAA,gBAAA,OAAA,CAAA,aAAA,CAAA;;AACA,MAAA,cAAA,gBAAA,OAAA,CAAA,gBAAA,CAAA;AAGA;;;AAGG;;;AACI,MAAM,MAAM,GAA0B,KAAK,IAAG;AACnD,QAAM,KAAK,GAAG,WAAA,CAAA,kBAAA,CAAmB,KAAnB,CAAd;AAEA,SAAO,cAAA,CAAA,qBAAA,CAAsB,KAAtB,CAAP;AACD,CAJM;;AAAM,OAAA,CAAA,MAAA,GAAM,MAAN;AAMb,OAAA,CAAA,MAAA,CAAO,WAAP,GAAqB,QAArB","sourcesContent":["import * as React from 'react';\n\nimport { usePortal_unstable } from './usePortal';\nimport { renderPortal_unstable } from './renderPortal';\nimport type { PortalProps } from './Portal.types';\n\n/**\n * A portal provides a way to render children into a DOM node\n * that exists outside the DOM hierarchy of the parent component.\n */\nexport const Portal: React.FC<PortalProps> = props => {\n const state = usePortal_unstable(props);\n\n return renderPortal_unstable(state);\n};\n\nPortal.displayName = 'Portal';\n"],"sourceRoot":"../src/"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","sourceRoot":"../src/"}
|
@@ -1,8 +1,16 @@
|
|
1
1
|
"use strict";
|
2
|
-
|
3
|
-
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
|
7
|
+
const tslib_1 = /*#__PURE__*/require("tslib");
|
8
|
+
|
4
9
|
tslib_1.__exportStar(require("./Portal"), exports);
|
10
|
+
|
5
11
|
tslib_1.__exportStar(require("./Portal.types"), exports);
|
12
|
+
|
6
13
|
tslib_1.__exportStar(require("./renderPortal"), exports);
|
14
|
+
|
7
15
|
tslib_1.__exportStar(require("./usePortal"), exports);
|
8
16
|
//# sourceMappingURL=index.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"
|
1
|
+
{"version":3,"sources":["components/Portal/index.ts"],"names":[],"mappings":";;;;;;;;AAAA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,UAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,gBAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,gBAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,aAAA,CAAA,EAAA,OAAA","sourcesContent":["export * from './Portal';\nexport * from './Portal.types';\nexport * from './renderPortal';\nexport * from './usePortal';\n"],"sourceRoot":"../src/"}
|
@@ -1,13 +1,24 @@
|
|
1
1
|
"use strict";
|
2
|
-
|
3
|
-
exports
|
4
|
-
|
5
|
-
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.renderPortal_unstable = void 0;
|
7
|
+
|
8
|
+
const ReactDOM = /*#__PURE__*/require("react-dom");
|
9
|
+
|
10
|
+
const React = /*#__PURE__*/require("react");
|
6
11
|
/**
|
7
12
|
* Render the final JSX of Portal
|
8
13
|
*/
|
9
|
-
|
10
|
-
|
14
|
+
|
15
|
+
|
16
|
+
const renderPortal_unstable = state => {
|
17
|
+
return React.createElement("span", {
|
18
|
+
hidden: true,
|
19
|
+
ref: state.virtualParentRootRef
|
20
|
+
}, state.shouldRender && state.mountNode && ReactDOM.createPortal(state.children, state.mountNode));
|
11
21
|
};
|
12
|
-
|
22
|
+
|
23
|
+
exports.renderPortal_unstable = renderPortal_unstable;
|
13
24
|
//# sourceMappingURL=renderPortal.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"
|
1
|
+
{"version":3,"sources":["components/Portal/renderPortal.tsx"],"names":[],"mappings":";;;;;;;AAAA,MAAA,QAAA,gBAAA,OAAA,CAAA,WAAA,CAAA;;AACA,MAAA,KAAA,gBAAA,OAAA,CAAA,OAAA,CAAA;AAGA;;AAEG;;;AACI,MAAM,qBAAqB,GAAI,KAAD,IAA2C;AAC9E,SACE,KAAA,CAAA,aAAA,CAAA,MAAA,EAAA;AAAM,IAAA,MAAM,EAAA,IAAZ;AAAa,IAAA,GAAG,EAAE,KAAK,CAAC;AAAxB,GAAA,EACG,KAAK,CAAC,YAAN,IAAsB,KAAK,CAAC,SAA5B,IAAyC,QAAQ,CAAC,YAAT,CAAsB,KAAK,CAAC,QAA5B,EAAsC,KAAK,CAAC,SAA5C,CAD5C,CADF;AAKD,CANM;;AAAM,OAAA,CAAA,qBAAA,GAAqB,qBAArB","sourcesContent":["import * as ReactDOM from 'react-dom';\nimport * as React from 'react';\nimport type { PortalState } from './Portal.types';\n\n/**\n * Render the final JSX of Portal\n */\nexport const renderPortal_unstable = (state: PortalState): React.ReactElement => {\n return (\n <span hidden ref={state.virtualParentRootRef}>\n {state.shouldRender && state.mountNode && ReactDOM.createPortal(state.children, state.mountNode)}\n </span>\n );\n};\n"],"sourceRoot":"../src/"}
|