@fluentui/react-portal 9.2.1 → 9.2.2
Sign up to get free protection for your applications and to get access to all the features.
- package/.swcrc +30 -0
- package/CHANGELOG.json +40 -1
- package/CHANGELOG.md +15 -2
- package/lib/Portal.js.map +1 -1
- package/lib/components/Portal/Portal.js +1 -0
- package/lib/components/Portal/Portal.js.map +1 -1
- package/lib/components/Portal/Portal.types.js +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.map +1 -1
- package/lib/components/Portal/usePortal.js.map +1 -1
- package/lib/components/Portal/usePortalMountNode.js.map +1 -1
- package/lib/index.js.map +1 -1
- package/lib/virtualParent/elementContains.js.map +1 -1
- package/lib/virtualParent/getParent.js.map +1 -1
- package/lib/virtualParent/index.js.map +1 -1
- package/lib/virtualParent/isVirtualElement.js +1 -2
- package/lib/virtualParent/isVirtualElement.js.map +1 -1
- package/lib/virtualParent/setVirtualParent.js +1 -2
- package/lib/virtualParent/setVirtualParent.js.map +1 -1
- package/lib/virtualParent/types.js.map +1 -1
- package/lib-commonjs/Portal.js +5 -4
- package/lib-commonjs/Portal.js.map +1 -1
- package/lib-commonjs/components/Portal/Portal.js +14 -14
- package/lib-commonjs/components/Portal/Portal.js.map +1 -1
- package/lib-commonjs/components/Portal/Portal.types.js +5 -2
- package/lib-commonjs/components/Portal/Portal.types.js.map +1 -1
- package/lib-commonjs/components/Portal/index.js +8 -7
- package/lib-commonjs/components/Portal/index.js.map +1 -1
- package/lib-commonjs/components/Portal/renderPortal.js +15 -15
- package/lib-commonjs/components/Portal/renderPortal.js.map +1 -1
- package/lib-commonjs/components/Portal/usePortal.js +56 -55
- package/lib-commonjs/components/Portal/usePortal.js.map +1 -1
- package/lib-commonjs/components/Portal/usePortalMountNode.js +86 -68
- package/lib-commonjs/components/Portal/usePortalMountNode.js.map +1 -1
- package/lib-commonjs/index.js +17 -34
- package/lib-commonjs/index.js.map +1 -1
- package/lib-commonjs/virtualParent/elementContains.js +26 -30
- package/lib-commonjs/virtualParent/elementContains.js.map +1 -1
- package/lib-commonjs/virtualParent/getParent.js +19 -22
- package/lib-commonjs/virtualParent/getParent.js.map +1 -1
- package/lib-commonjs/virtualParent/index.js +6 -5
- package/lib-commonjs/virtualParent/index.js.map +1 -1
- package/lib-commonjs/virtualParent/isVirtualElement.js +11 -10
- package/lib-commonjs/virtualParent/isVirtualElement.js.map +1 -1
- package/lib-commonjs/virtualParent/setVirtualParent.js +18 -17
- package/lib-commonjs/virtualParent/setVirtualParent.js.map +1 -1
- package/lib-commonjs/virtualParent/types.js +3 -2
- package/lib-commonjs/virtualParent/types.js.map +1 -1
- package/package.json +7 -6
- package/lib-amd/components/Portal/Portal.js +0 -16
- package/lib-amd/components/Portal/Portal.js.map +0 -1
- package/lib-amd/components/Portal/Portal.types.js +0 -5
- package/lib-amd/components/Portal/Portal.types.js.map +0 -1
- package/lib-amd/components/Portal/index.js +0 -9
- package/lib-amd/components/Portal/index.js.map +0 -1
- package/lib-amd/components/Portal/renderPortal.js +0 -13
- package/lib-amd/components/Portal/renderPortal.js.map +0 -1
- package/lib-amd/components/Portal/usePortal.js +0 -48
- package/lib-amd/components/Portal/usePortal.js.map +0 -1
- package/lib-amd/components/Portal/usePortalMountNode.js +0 -67
- package/lib-amd/components/Portal/usePortalMountNode.js.map +0 -1
- package/lib-amd/index.js +0 -11
- package/lib-amd/index.js.map +0 -1
- package/lib-amd/virtualParent/elementContains.js +0 -36
- package/lib-amd/virtualParent/elementContains.js.map +0 -1
- package/lib-amd/virtualParent/getParent.js +0 -30
- package/lib-amd/virtualParent/getParent.js.map +0 -1
- package/lib-amd/virtualParent/index.js +0 -7
- package/lib-amd/virtualParent/index.js.map +0 -1
- package/lib-amd/virtualParent/isVirtualElement.js +0 -13
- package/lib-amd/virtualParent/isVirtualElement.js.map +0 -1
- package/lib-amd/virtualParent/setVirtualParent.js +0 -23
- package/lib-amd/virtualParent/setVirtualParent.js.map +0 -1
- package/lib-amd/virtualParent/types.js +0 -5
- package/lib-amd/virtualParent/types.js.map +0 -1
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"Portal.types.js","sourceRoot":"","sources":["../../../../../../../../../packages/react-components/react-portal/src/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 | { element?: HTMLElement | null; className?: string };\n};\n\nexport type PortalState = Pick<PortalProps, 'children'> & {\n mountNode: HTMLElement | null | undefined;\n\n /**\n * Ref to the root span element as virtual parent\n */\n virtualParentRootRef: React.MutableRefObject<HTMLSpanElement | null>;\n};\n"]}
|
@@ -1,9 +0,0 @@
|
|
1
|
-
define(["require", "exports", "tslib", "./Portal", "./Portal.types", "./renderPortal", "./usePortal"], function (require, exports, tslib_1, Portal_1, Portal_types_1, renderPortal_1, usePortal_1) {
|
2
|
-
"use strict";
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
4
|
-
tslib_1.__exportStar(Portal_1, exports);
|
5
|
-
tslib_1.__exportStar(Portal_types_1, exports);
|
6
|
-
tslib_1.__exportStar(renderPortal_1, exports);
|
7
|
-
tslib_1.__exportStar(usePortal_1, exports);
|
8
|
-
});
|
9
|
-
//# sourceMappingURL=index.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../../../../packages/react-components/react-portal/src/components/Portal/index.ts"],"names":[],"mappings":";;;IAAA,wCAAyB;IACzB,8CAA+B;IAC/B,8CAA+B;IAC/B,2CAA4B","sourcesContent":["export * from './Portal';\nexport * from './Portal.types';\nexport * from './renderPortal';\nexport * from './usePortal';\n"]}
|
@@ -1,13 +0,0 @@
|
|
1
|
-
define(["require", "exports", "react-dom", "react"], function (require, exports, ReactDOM, React) {
|
2
|
-
"use strict";
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
4
|
-
exports.renderPortal_unstable = void 0;
|
5
|
-
/**
|
6
|
-
* Render the final JSX of Portal
|
7
|
-
*/
|
8
|
-
var renderPortal_unstable = function (state) {
|
9
|
-
return (React.createElement("span", { hidden: true, ref: state.virtualParentRootRef }, state.mountNode && ReactDOM.createPortal(state.children, state.mountNode)));
|
10
|
-
};
|
11
|
-
exports.renderPortal_unstable = renderPortal_unstable;
|
12
|
-
});
|
13
|
-
//# sourceMappingURL=renderPortal.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"renderPortal.js","sourceRoot":"","sources":["../../../../../../../../../packages/react-components/react-portal/src/components/Portal/renderPortal.tsx"],"names":[],"mappings":";;;;IAIA;;OAEG;IACI,IAAM,qBAAqB,GAAG,UAAC,KAAkB;QACtD,OAAO,CACL,8BAAM,MAAM,QAAC,GAAG,EAAE,KAAK,CAAC,oBAAoB,IACzC,KAAK,CAAC,SAAS,IAAI,QAAQ,CAAC,YAAY,CAAC,KAAK,CAAC,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC,CACrE,CACR,CAAC;IACJ,CAAC,CAAC;IANW,QAAA,qBAAqB,yBAMhC","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.mountNode && ReactDOM.createPortal(state.children, state.mountNode)}\n </span>\n );\n};\n"]}
|
@@ -1,48 +0,0 @@
|
|
1
|
-
define(["require", "exports", "@fluentui/react-utilities", "react", "../../virtualParent/index", "./usePortalMountNode"], function (require, exports, react_utilities_1, React, index_1, usePortalMountNode_1) {
|
2
|
-
"use strict";
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
4
|
-
exports.usePortal_unstable = exports.toMountNodeProps = void 0;
|
5
|
-
function toMountNodeProps(mountNode) {
|
6
|
-
if (react_utilities_1.isHTMLElement(mountNode)) {
|
7
|
-
return { element: mountNode };
|
8
|
-
}
|
9
|
-
if (typeof mountNode === 'object') {
|
10
|
-
if (mountNode === null) {
|
11
|
-
return { element: null };
|
12
|
-
}
|
13
|
-
return mountNode;
|
14
|
-
}
|
15
|
-
return {};
|
16
|
-
}
|
17
|
-
exports.toMountNodeProps = toMountNodeProps;
|
18
|
-
/**
|
19
|
-
* Create the state required to render Portal.
|
20
|
-
*
|
21
|
-
* The returned state can be modified with hooks such as usePortalStyles, before being passed to renderPortal_unstable.
|
22
|
-
*
|
23
|
-
* @param props - props from this instance of Portal
|
24
|
-
*/
|
25
|
-
var usePortal_unstable = function (props) {
|
26
|
-
var _a = toMountNodeProps(props.mountNode), element = _a.element, className = _a.className;
|
27
|
-
var virtualParentRootRef = React.useRef(null);
|
28
|
-
var fallbackElement = usePortalMountNode_1.usePortalMountNode({ disabled: !!element, className: className });
|
29
|
-
var state = {
|
30
|
-
children: props.children,
|
31
|
-
mountNode: element !== null && element !== void 0 ? element : fallbackElement,
|
32
|
-
virtualParentRootRef: virtualParentRootRef,
|
33
|
-
};
|
34
|
-
React.useEffect(function () {
|
35
|
-
if (state.virtualParentRootRef.current && state.mountNode) {
|
36
|
-
index_1.setVirtualParent(state.mountNode, state.virtualParentRootRef.current);
|
37
|
-
}
|
38
|
-
return function () {
|
39
|
-
if (state.mountNode) {
|
40
|
-
index_1.setVirtualParent(state.mountNode, undefined);
|
41
|
-
}
|
42
|
-
};
|
43
|
-
}, [state.virtualParentRootRef, state.mountNode]);
|
44
|
-
return state;
|
45
|
-
};
|
46
|
-
exports.usePortal_unstable = usePortal_unstable;
|
47
|
-
});
|
48
|
-
//# sourceMappingURL=usePortal.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"usePortal.js","sourceRoot":"","sources":["../../../../../../../../../packages/react-components/react-portal/src/components/Portal/usePortal.ts"],"names":[],"mappings":";;;;IAOA,SAAgB,gBAAgB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S,CAAC,CAAC,CAAC;QAElD,OAAO,KAAK,CAAC;IACf,CAAC,CAAC;IAxBW,QAAA,kBAAkB,sBAwB7B","sourcesContent":["import { isHTMLElement } from '@fluentui/react-utilities';\nimport * as React from 'react';\n\nimport { setVirtualParent } from '../../virtualParent/index';\nimport { usePortalMountNode } from './usePortalMountNode';\nimport type { PortalProps, PortalState } from './Portal.types';\n\nexport function toMountNodeProps(mountNode: PortalProps['mountNode']): {\n element?: HTMLElement | null;\n className?: string;\n} {\n if (isHTMLElement(mountNode)) {\n return { element: mountNode };\n }\n\n if (typeof mountNode === 'object') {\n if (mountNode === null) {\n return { element: null };\n }\n\n return mountNode;\n }\n\n return {};\n}\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 { element, className } = toMountNodeProps(props.mountNode);\n\n const virtualParentRootRef = React.useRef<HTMLSpanElement>(null);\n const fallbackElement = usePortalMountNode({ disabled: !!element, className });\n\n const state: PortalState = {\n children: props.children,\n mountNode: element ?? fallbackElement,\n virtualParentRootRef,\n };\n\n React.useEffect(() => {\n if (state.virtualParentRootRef.current && state.mountNode) {\n setVirtualParent(state.mountNode, state.virtualParentRootRef.current);\n }\n return () => {\n if (state.mountNode) {\n setVirtualParent(state.mountNode, undefined);\n }\n };\n }, [state.virtualParentRootRef, state.mountNode]);\n\n return state;\n};\n"]}
|
@@ -1,67 +0,0 @@
|
|
1
|
-
define(["require", "exports", "react", "@fluentui/react-shared-contexts", "@griffel/react", "@fluentui/react-tabster", "use-disposable"], function (require, exports, React, react_shared_contexts_1, react_1, react_tabster_1, use_disposable_1) {
|
2
|
-
"use strict";
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
4
|
-
exports.usePortalMountNode = void 0;
|
5
|
-
var useInsertionEffect = React['useInsertion' + 'Effect'];
|
6
|
-
var useStyles = react_1.makeStyles({
|
7
|
-
root: {
|
8
|
-
position: 'relative',
|
9
|
-
zIndex: 1000000,
|
10
|
-
},
|
11
|
-
});
|
12
|
-
/**
|
13
|
-
* Creates a new element on a "document.body" to mount portals.
|
14
|
-
*/
|
15
|
-
var usePortalMountNode = function (options) {
|
16
|
-
var _a = react_shared_contexts_1.useFluent_unstable(), targetDocument = _a.targetDocument, dir = _a.dir;
|
17
|
-
var focusVisibleRef = react_tabster_1.useFocusVisible();
|
18
|
-
var classes = useStyles();
|
19
|
-
var themeClassName = react_shared_contexts_1.useThemeClassName_unstable();
|
20
|
-
var className = react_1.mergeClasses(themeClassName, classes.root, options.className);
|
21
|
-
var element = use_disposable_1.useDisposable(function () {
|
22
|
-
if (targetDocument === undefined || options.disabled) {
|
23
|
-
return [null, function () { return null; }];
|
24
|
-
}
|
25
|
-
var newElement = targetDocument.createElement('div');
|
26
|
-
targetDocument.body.appendChild(newElement);
|
27
|
-
return [newElement, function () { return newElement.remove(); }];
|
28
|
-
}, [targetDocument]);
|
29
|
-
if (useInsertionEffect) {
|
30
|
-
// eslint-disable-next-line react-hooks/rules-of-hooks
|
31
|
-
useInsertionEffect(function () {
|
32
|
-
var _a;
|
33
|
-
if (!element) {
|
34
|
-
return;
|
35
|
-
}
|
36
|
-
var classesToApply = className.split(' ').filter(Boolean);
|
37
|
-
(_a = element.classList).add.apply(_a, classesToApply);
|
38
|
-
element.setAttribute('dir', dir);
|
39
|
-
focusVisibleRef.current = element;
|
40
|
-
return function () {
|
41
|
-
var _a;
|
42
|
-
(_a = element.classList).remove.apply(_a, classesToApply);
|
43
|
-
element.removeAttribute('dir');
|
44
|
-
};
|
45
|
-
}, [className, dir, element, focusVisibleRef]);
|
46
|
-
}
|
47
|
-
else {
|
48
|
-
// This useMemo call is intentional for React 17
|
49
|
-
// We don't want to re-create the portal element when its attributes change.
|
50
|
-
// This also should not be done in an effect because, changing the value of css variables
|
51
|
-
// after initial mount can trigger interesting CSS side effects like transitions.
|
52
|
-
// eslint-disable-next-line react-hooks/rules-of-hooks
|
53
|
-
React.useMemo(function () {
|
54
|
-
if (!element) {
|
55
|
-
return;
|
56
|
-
}
|
57
|
-
// Force replace all classes
|
58
|
-
element.className = className;
|
59
|
-
element.setAttribute('dir', dir);
|
60
|
-
focusVisibleRef.current = element;
|
61
|
-
}, [className, dir, element, focusVisibleRef]);
|
62
|
-
}
|
63
|
-
return element;
|
64
|
-
};
|
65
|
-
exports.usePortalMountNode = usePortalMountNode;
|
66
|
-
});
|
67
|
-
//# sourceMappingURL=usePortalMountNode.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"usePortalMountNode.js","sourceRoot":"","sources":["../../../../../../../../../packages/react-components/react-portal/src/components/Portal/usePortalMountNode.ts"],"names":[],"mappings":";;;;IASA,IAAM,kBAAkB,GAAI,KAAe,CAAC,cAAc,GAAG,QAAQ,CAA6C,CAAC;IAWnH,IAAM,SAAS,GAAG,kBAAU,CAAC;QAC3B,IAAI,EAAE;YACJ,QAAQ,EAAE,UAAU;YACpB,MAAM,EAAE,OAAO;SAChB;KACF,CAAC,CAAC;IAEH;;OAEG;IACI,IAAM,kBAAkB,GAAG,UAAC,OAAkC;QAC7D,IAAA,KAA0B,0CAAS,EAAE,EAAnC,cAAc,oBAAA,EAAE,GAAG,SAAgB,CAAC;QAC5C,IAAM,eAAe,GAAG,+BAAe,EAAgE,CAAC;QACxG,IAAM,OAAO,GAAG,SAAS,EAAE,CAAC;QAC5B,IAAM,cAAc,GAAG,kDAAiB,EAAE,CAAC;QAE3C,IAAM,SAAS,GAAG,oBAAY,CAAC,cAAc,EAAE,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC;QAEhF,IAAM,OAAO,GAAG,8BAAa,CAAC;YAC5B,IAAI,cAAc,KAAK,SAAS,IAAI,OAAO,CAAC,QAAQ,EAAE;gBACpD,OAAO,CAAC,IAAI,EAAE,cAAM,OAAA,IAAI,EAAJ,CAAI,CAAC,CAAC;a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YACpC,CAAC,EAAE,CAAC,SAAS,EAAE,GAAG,EAAE,OAAO,EAAE,eAAe,CAAC,CAAC,CAAC;SAChD;QAED,OAAO,OAAO,CAAC;IACjB,CAAC,CAAC;IAvDW,QAAA,kBAAkB,sBAuD7B","sourcesContent":["import * as React from 'react';\nimport {\n useThemeClassName_unstable as useThemeClassName,\n useFluent_unstable as useFluent,\n} from '@fluentui/react-shared-contexts';\nimport { makeStyles, mergeClasses } from '@griffel/react';\nimport { useFocusVisible } from '@fluentui/react-tabster';\nimport { useDisposable } from 'use-disposable';\n\nconst useInsertionEffect = (React as never)['useInsertion' + 'Effect'] as typeof React.useLayoutEffect | undefined;\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 className?: string;\n};\n\nconst useStyles = makeStyles({\n root: {\n position: 'relative',\n zIndex: 1000000,\n },\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 { targetDocument, dir } = useFluent();\n const focusVisibleRef = useFocusVisible<HTMLDivElement>() as React.MutableRefObject<HTMLElement | null>;\n const classes = useStyles();\n const themeClassName = useThemeClassName();\n\n const className = mergeClasses(themeClassName, classes.root, options.className);\n\n const element = useDisposable(() => {\n if (targetDocument === undefined || options.disabled) {\n return [null, () => null];\n }\n\n const newElement = targetDocument.createElement('div');\n targetDocument.body.appendChild(newElement);\n return [newElement, () => newElement.remove()];\n }, [targetDocument]);\n\n if (useInsertionEffect) {\n // eslint-disable-next-line react-hooks/rules-of-hooks\n useInsertionEffect(() => {\n if (!element) {\n return;\n }\n\n const classesToApply = className.split(' ').filter(Boolean);\n\n element.classList.add(...classesToApply);\n element.setAttribute('dir', dir);\n focusVisibleRef.current = element;\n\n return () => {\n element.classList.remove(...classesToApply);\n element.removeAttribute('dir');\n };\n }, [className, dir, element, focusVisibleRef]);\n } else {\n // This useMemo call is intentional for React 17\n // We don't want to re-create the portal element when its attributes change.\n // This also should not be done in an effect because, changing the value of css variables\n // after initial mount can trigger interesting CSS side effects like transitions.\n // eslint-disable-next-line react-hooks/rules-of-hooks\n React.useMemo(() => {\n if (!element) {\n return;\n }\n\n // Force replace all classes\n element.className = className;\n element.setAttribute('dir', dir);\n focusVisibleRef.current = element;\n }, [className, dir, element, focusVisibleRef]);\n }\n\n return element;\n};\n"]}
|
package/lib-amd/index.js
DELETED
@@ -1,11 +0,0 @@
|
|
1
|
-
define(["require", "exports", "./components/Portal/index", "./virtualParent/index"], function (require, exports, index_1, index_2) {
|
2
|
-
"use strict";
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
4
|
-
exports.setVirtualParent = exports.elementContains = exports.usePortal_unstable = exports.renderPortal_unstable = exports.Portal = void 0;
|
5
|
-
Object.defineProperty(exports, "Portal", { enumerable: true, get: function () { return index_1.Portal; } });
|
6
|
-
Object.defineProperty(exports, "renderPortal_unstable", { enumerable: true, get: function () { return index_1.renderPortal_unstable; } });
|
7
|
-
Object.defineProperty(exports, "usePortal_unstable", { enumerable: true, get: function () { return index_1.usePortal_unstable; } });
|
8
|
-
Object.defineProperty(exports, "elementContains", { enumerable: true, get: function () { return index_2.elementContains; } });
|
9
|
-
Object.defineProperty(exports, "setVirtualParent", { enumerable: true, get: function () { return index_2.setVirtualParent; } });
|
10
|
-
});
|
11
|
-
//# sourceMappingURL=index.js.map
|
package/lib-amd/index.js.map
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../../packages/react-components/react-portal/src/index.ts"],"names":[],"mappings":";;;;IAAS,+FAAA,MAAM,OAAA;IAAE,8GAAA,qBAAqB,OAAA;IAAE,2GAAA,kBAAkB,OAAA;IAEjD,wGAAA,eAAe,OAAA;IAAE,yGAAA,gBAAgB,OAAA","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"]}
|
@@ -1,36 +0,0 @@
|
|
1
|
-
define(["require", "exports", "./getParent"], function (require, exports, getParent_1) {
|
2
|
-
"use strict";
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
4
|
-
exports.elementContains = void 0;
|
5
|
-
/**
|
6
|
-
* Similar functionality to `element.contains` DOM API for use without of order DOM elements that
|
7
|
-
* checks the virtual parent hierarchy. If a virtual parents exists, it is chosen over the actual parent
|
8
|
-
*
|
9
|
-
* @returns true if the child can find the parent in its virtual hierarchy
|
10
|
-
*/
|
11
|
-
function elementContains(parent, child) {
|
12
|
-
if (!parent || !child) {
|
13
|
-
return false;
|
14
|
-
}
|
15
|
-
if (parent === child) {
|
16
|
-
return true;
|
17
|
-
}
|
18
|
-
else {
|
19
|
-
// Tracks references of nodes that have been visited to prevent infinite loops
|
20
|
-
var set = new WeakSet();
|
21
|
-
while (child) {
|
22
|
-
var nextParent = getParent_1.getParent(child, {
|
23
|
-
skipVirtual: set.has(child),
|
24
|
-
});
|
25
|
-
set.add(child);
|
26
|
-
if (nextParent === parent) {
|
27
|
-
return true;
|
28
|
-
}
|
29
|
-
child = nextParent;
|
30
|
-
}
|
31
|
-
}
|
32
|
-
return false;
|
33
|
-
}
|
34
|
-
exports.elementContains = elementContains;
|
35
|
-
});
|
36
|
-
//# sourceMappingURL=elementContains.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"elementContains.js","sourceRoot":"","sources":["../../../../../../../../packages/react-components/react-portal/src/virtualParent/elementContains.ts"],"names":[],"mappings":";;;;IAEA;;;;;OAKG;IACH,SAAgB,eAAe,CAAC,MAAmB,EAAE,KAAkB;QACrE,IAAI,CAAC,MAAM,IAAI,CAAC,KAAK,EAAE;YACrB,OAAO,KAAK,CAAC;SACd;QAED,IAAI,MAAM,KAAK,KAAK,EAAE;YACpB,OAAO,IAAI,CAAC;SACb;aAAM;YACL,8EAA8E;YAC9E,IAAM,GAAG,GAAG,IAAI,OAAO,EAAQ,CAAC;YAEhC,OAAO,KAAK,EAAE;gBACZ,IAAM,UAAU,GAAgB,qBAAS,CAAC,KAAK,EAAE;oBAC/C,WAAW,EAAE,GAAG,CAAC,GAAG,CAAC,KAAK,CAAC;iBAC5B,CAAC,CAAC;gBACH,GAAG,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;gBAEf,IAAI,UAAU,KAAK,MAAM,EAAE;oBACzB,OAAO,IAAI,CAAC;iBACb;gBAED,KAAK,GAAG,UAAU,CAAC;aACpB;SACF;QAED,OAAO,KAAK,CAAC;IACf,CAAC;IA1BD,0CA0BC","sourcesContent":["import { getParent } from './getParent';\n\n/**\n * Similar functionality to `element.contains` DOM API for use without 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: Node | null, child: Node | null): boolean {\n if (!parent || !child) {\n return false;\n }\n\n if (parent === child) {\n return true;\n } else {\n // Tracks references of nodes that have been visited to prevent infinite loops\n const set = new WeakSet<Node>();\n\n while (child) {\n const nextParent: Node | null = getParent(child, {\n skipVirtual: set.has(child),\n });\n set.add(child);\n\n if (nextParent === parent) {\n return true;\n }\n\n child = nextParent;\n }\n }\n\n return false;\n}\n"]}
|
@@ -1,30 +0,0 @@
|
|
1
|
-
define(["require", "exports", "./isVirtualElement"], function (require, exports, isVirtualElement_1) {
|
2
|
-
"use strict";
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
4
|
-
exports.getParent = void 0;
|
5
|
-
/**
|
6
|
-
* Gets the virtual parent given the child element, if it exists.
|
7
|
-
*/
|
8
|
-
function getVirtualParent(child) {
|
9
|
-
return isVirtualElement_1.isVirtualElement(child) ? child._virtual.parent || null : null;
|
10
|
-
}
|
11
|
-
/**
|
12
|
-
* Gets the element which is the parent of a given element.
|
13
|
-
* This method prefers the virtual parent over real DOM parent when present.
|
14
|
-
*/
|
15
|
-
function getParent(child, options) {
|
16
|
-
if (options === void 0) { options = {}; }
|
17
|
-
if (!child) {
|
18
|
-
return null;
|
19
|
-
}
|
20
|
-
if (!options.skipVirtual) {
|
21
|
-
var virtualParent = getVirtualParent(child);
|
22
|
-
if (virtualParent) {
|
23
|
-
return virtualParent;
|
24
|
-
}
|
25
|
-
}
|
26
|
-
return (child === null || child === void 0 ? void 0 : child.parentNode) || null;
|
27
|
-
}
|
28
|
-
exports.getParent = getParent;
|
29
|
-
});
|
30
|
-
//# sourceMappingURL=getParent.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"getParent.js","sourceRoot":"","sources":["../../../../../../../../packages/react-components/react-portal/src/virtualParent/getParent.ts"],"names":[],"mappings":";;;;IASA;;OAEG;IACH,SAAS,gBAAgB,CAAC,KAAW;QACnC,OAAO,mCAAgB,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,MAAM,IAAI,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC;IACxE,CAAC;IAED;;;OAGG;IACH,SAAgB,SAAS,CAAC,KAAkB,EAAE,OAA8B;QAA9B,wBAAA,EAAA,YAA8B;QAC1E,IAAI,CAAC,KAAK,EAAE;YACV,OAAO,IAAI,CAAC;SACb;QAED,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE;YACxB,IAAM,aAAa,GAAG,gBAAgB,CAAC,KAAK,CAAC,CAAC;YAE9C,IAAI,aAAa,EAAE;gBACjB,OAAO,aAAa,CAAC;aACtB;SACF;QAED,OAAO,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,UAAU,KAAI,IAAI,CAAC;IACnC,CAAC;IAdD,8BAcC","sourcesContent":["import { isVirtualElement } from './isVirtualElement';\n\ntype GetParentOptions = {\n /**\n * Indicates if getParent() should ignore a virtual parent.\n */\n skipVirtual?: boolean;\n};\n\n/**\n * Gets the virtual parent given the child element, if it exists.\n */\nfunction getVirtualParent(child: Node): Node | null {\n return isVirtualElement(child) ? child._virtual.parent || null : null;\n}\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: Node | null, options: GetParentOptions = {}): Node | null {\n if (!child) {\n return null;\n }\n\n if (!options.skipVirtual) {\n const virtualParent = getVirtualParent(child);\n\n if (virtualParent) {\n return virtualParent;\n }\n }\n\n return child?.parentNode || null;\n}\n"]}
|
@@ -1,7 +0,0 @@
|
|
1
|
-
define(["require", "exports", "tslib", "./elementContains", "./setVirtualParent"], function (require, exports, tslib_1, elementContains_1, setVirtualParent_1) {
|
2
|
-
"use strict";
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
4
|
-
tslib_1.__exportStar(elementContains_1, exports);
|
5
|
-
tslib_1.__exportStar(setVirtualParent_1, exports);
|
6
|
-
});
|
7
|
-
//# sourceMappingURL=index.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../../../packages/react-components/react-portal/src/virtualParent/index.ts"],"names":[],"mappings":";;;IAAA,iDAAkC;IAClC,kDAAmC","sourcesContent":["export * from './elementContains';\nexport * from './setVirtualParent';\n"]}
|
@@ -1,13 +0,0 @@
|
|
1
|
-
define(["require", "exports"], function (require, exports) {
|
2
|
-
"use strict";
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
4
|
-
exports.isVirtualElement = void 0;
|
5
|
-
/**
|
6
|
-
* Determines whether or not an element has the virtual hierarchy extension.
|
7
|
-
*/
|
8
|
-
function isVirtualElement(element) {
|
9
|
-
return element && !!element._virtual;
|
10
|
-
}
|
11
|
-
exports.isVirtualElement = isVirtualElement;
|
12
|
-
});
|
13
|
-
//# sourceMappingURL=isVirtualElement.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"isVirtualElement.js","sourceRoot":"","sources":["../../../../../../../../packages/react-components/react-portal/src/virtualParent/isVirtualElement.ts"],"names":[],"mappings":";;;;IAEA;;OAEG;IACH,SAAgB,gBAAgB,CAAC,OAA8B;QAC7D,OAAO,OAAO,IAAI,CAAC,CAAkB,OAAQ,CAAC,QAAQ,CAAC;IACzD,CAAC;IAFD,4CAEC","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: Node | VirtualElement): element is VirtualElement {\n return element && !!(<VirtualElement>element)._virtual;\n}\n"]}
|
@@ -1,23 +0,0 @@
|
|
1
|
-
define(["require", "exports"], function (require, exports) {
|
2
|
-
"use strict";
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
4
|
-
exports.setVirtualParent = void 0;
|
5
|
-
/**
|
6
|
-
* Sets the virtual parent of an element.
|
7
|
-
*
|
8
|
-
* @param child - Theme element to set the virtual parent
|
9
|
-
* @param parent - The virtual parent, use `undefined` to remove a virtual parent relationship
|
10
|
-
*/
|
11
|
-
function setVirtualParent(child, parent) {
|
12
|
-
if (!child) {
|
13
|
-
return;
|
14
|
-
}
|
15
|
-
var virtualChild = child;
|
16
|
-
if (!virtualChild._virtual) {
|
17
|
-
virtualChild._virtual = {};
|
18
|
-
}
|
19
|
-
virtualChild._virtual.parent = parent;
|
20
|
-
}
|
21
|
-
exports.setVirtualParent = setVirtualParent;
|
22
|
-
});
|
23
|
-
//# sourceMappingURL=setVirtualParent.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"setVirtualParent.js","sourceRoot":"","sources":["../../../../../../../../packages/react-components/react-portal/src/virtualParent/setVirtualParent.ts"],"names":[],"mappings":";;;;IAEA;;;;;OAKG;IACH,SAAgB,gBAAgB,CAAC,KAAW,EAAE,MAAa;QACzD,IAAI,CAAC,KAAK,EAAE;YACV,OAAO;SACR;QAED,IAAM,YAAY,GAAG,KAAuB,CAAC;QAE7C,IAAI,CAAC,YAAY,CAAC,QAAQ,EAAE;YAC1B,YAAY,CAAC,QAAQ,GAAG,EAAE,CAAC;SAC5B;QAED,YAAY,CAAC,QAAQ,CAAC,MAAM,GAAG,MAAM,CAAC;IACxC,CAAC;IAZD,4CAYC","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: Node, parent?: Node): void {\n if (!child) {\n return;\n }\n\n const virtualChild = child as VirtualElement;\n\n if (!virtualChild._virtual) {\n virtualChild._virtual = {};\n }\n\n virtualChild._virtual.parent = parent;\n}\n"]}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../../../../packages/react-components/react-portal/src/virtualParent/types.ts"],"names":[],"mappings":"","sourcesContent":["export interface VirtualElement extends Node {\n _virtual: {\n parent?: Node;\n };\n}\n"]}
|