@fluentui/react-positioning 0.0.0-nightly-20230316-0427.1 → 0.0.0-nightly-20230317-1454.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/.swcrc +39 -0
- package/CHANGELOG.json +24 -9
- package/CHANGELOG.md +16 -7
- package/lib/constants.js +4 -4
- package/lib/constants.js.map +1 -1
- package/lib/createArrowStyles.js +19 -19
- package/lib/createArrowStyles.js.map +1 -1
- package/lib/createPositionManager.js +13 -13
- package/lib/createPositionManager.js.map +1 -1
- package/lib/createVirtualElementFromClick.js +1 -2
- package/lib/createVirtualElementFromClick.js.map +1 -1
- package/lib/index.js +5 -5
- package/lib/index.js.map +1 -1
- package/lib/middleware/coverTarget.js +6 -6
- package/lib/middleware/coverTarget.js.map +1 -1
- package/lib/middleware/flip.js +4 -4
- package/lib/middleware/flip.js.map +1 -1
- package/lib/middleware/index.js +6 -6
- package/lib/middleware/index.js.map +1 -1
- package/lib/middleware/intersecting.js +2 -2
- package/lib/middleware/intersecting.js.map +1 -1
- package/lib/middleware/maxSize.js +8 -8
- package/lib/middleware/maxSize.js.map +1 -1
- package/lib/middleware/offset.js +2 -2
- package/lib/middleware/offset.js.map +1 -1
- package/lib/middleware/shift.js +5 -5
- package/lib/middleware/shift.js.map +1 -1
- package/lib/types.js +1 -1
- package/lib/types.js.map +1 -1
- package/lib/usePositioning.js +20 -26
- package/lib/usePositioning.js.map +1 -1
- package/lib/usePositioningMouseTarget.js +4 -4
- package/lib/usePositioningMouseTarget.js.map +1 -1
- package/lib/utils/debounce.js +1 -2
- package/lib/utils/debounce.js.map +1 -1
- package/lib/utils/fromFloatingUIPlacement.js +10 -10
- package/lib/utils/fromFloatingUIPlacement.js.map +1 -1
- package/lib/utils/getBoundary.js +8 -8
- package/lib/utils/getBoundary.js.map +1 -1
- package/lib/utils/getFloatingUIOffset.js +2 -2
- package/lib/utils/getFloatingUIOffset.js.map +1 -1
- package/lib/utils/getReactFiberFromNode.js +3 -2
- package/lib/utils/getReactFiberFromNode.js.map +1 -1
- package/lib/utils/getScrollParent.js +7 -10
- package/lib/utils/getScrollParent.js.map +1 -1
- package/lib/utils/hasAutoFocusFilter.js +3 -4
- package/lib/utils/hasAutoFocusFilter.js.map +1 -1
- package/lib/utils/index.js +15 -15
- package/lib/utils/index.js.map +1 -1
- package/lib/utils/mergeArrowOffset.js +6 -8
- package/lib/utils/mergeArrowOffset.js.map +1 -1
- package/lib/utils/parseFloatingUIPlacement.js +2 -3
- package/lib/utils/parseFloatingUIPlacement.js.map +1 -1
- package/lib/utils/resolvePositioningShorthand.js +33 -33
- package/lib/utils/resolvePositioningShorthand.js.map +1 -1
- package/lib/utils/toFloatingUIPadding.js +3 -3
- package/lib/utils/toFloatingUIPadding.js.map +1 -1
- package/lib/utils/toFloatingUIPlacement.js +11 -11
- package/lib/utils/toFloatingUIPlacement.js.map +1 -1
- package/lib/utils/toggleScrollListener.js +4 -4
- package/lib/utils/toggleScrollListener.js.map +1 -1
- package/lib/utils/useCallbackRef.js +2 -2
- package/lib/utils/useCallbackRef.js.map +1 -1
- package/lib/utils/writeArrowUpdates.js +1 -2
- package/lib/utils/writeArrowUpdates.js.map +1 -1
- package/lib/utils/writeContainerupdates.js +7 -8
- package/lib/utils/writeContainerupdates.js.map +1 -1
- package/lib-commonjs/constants.js +18 -7
- package/lib-commonjs/constants.js.map +1 -1
- package/lib-commonjs/createArrowStyles.js +60 -88
- package/lib-commonjs/createArrowStyles.js.map +1 -1
- package/lib-commonjs/createPositionManager.js +103 -117
- package/lib-commonjs/createPositionManager.js.map +1 -1
- package/lib-commonjs/createVirtualElementFromClick.js +27 -26
- package/lib-commonjs/createVirtualElementFromClick.js.map +1 -1
- package/lib-commonjs/index.js +24 -51
- package/lib-commonjs/index.js.map +1 -1
- package/lib-commonjs/middleware/coverTarget.js +34 -37
- package/lib-commonjs/middleware/coverTarget.js.map +1 -1
- package/lib-commonjs/middleware/flip.js +31 -38
- package/lib-commonjs/middleware/flip.js.map +1 -1
- package/lib-commonjs/middleware/index.js +10 -9
- package/lib-commonjs/middleware/index.js.map +1 -1
- package/lib-commonjs/middleware/intersecting.js +24 -22
- package/lib-commonjs/middleware/intersecting.js.map +1 -1
- package/lib-commonjs/middleware/maxSize.js +34 -40
- package/lib-commonjs/middleware/maxSize.js.map +1 -1
- package/lib-commonjs/middleware/offset.js +11 -12
- package/lib-commonjs/middleware/offset.js.map +1 -1
- package/lib-commonjs/middleware/shift.js +29 -37
- package/lib-commonjs/middleware/shift.js.map +1 -1
- package/lib-commonjs/types.js +5 -2
- package/lib-commonjs/types.js.map +1 -1
- package/lib-commonjs/usePositioning.js +192 -164
- package/lib-commonjs/usePositioning.js.map +1 -1
- package/lib-commonjs/usePositioningMouseTarget.js +34 -37
- package/lib-commonjs/usePositioningMouseTarget.js.map +1 -1
- package/lib-commonjs/utils/debounce.js +22 -21
- package/lib-commonjs/utils/debounce.js.map +1 -1
- package/lib-commonjs/utils/fromFloatingUIPlacement.js +30 -35
- package/lib-commonjs/utils/fromFloatingUIPlacement.js.map +1 -1
- package/lib-commonjs/utils/getBoundary.js +21 -22
- package/lib-commonjs/utils/getBoundary.js.map +1 -1
- package/lib-commonjs/utils/getFloatingUIOffset.js +23 -35
- package/lib-commonjs/utils/getFloatingUIOffset.js.map +1 -1
- package/lib-commonjs/utils/getReactFiberFromNode.js +45 -41
- package/lib-commonjs/utils/getReactFiberFromNode.js.map +1 -1
- package/lib-commonjs/utils/getScrollParent.js +50 -56
- package/lib-commonjs/utils/getScrollParent.js.map +1 -1
- package/lib-commonjs/utils/hasAutoFocusFilter.js +17 -17
- package/lib-commonjs/utils/hasAutoFocusFilter.js.map +1 -1
- package/lib-commonjs/utils/index.js +19 -18
- package/lib-commonjs/utils/index.js.map +1 -1
- package/lib-commonjs/utils/mergeArrowOffset.js +32 -32
- package/lib-commonjs/utils/mergeArrowOffset.js.map +1 -1
- package/lib-commonjs/utils/parseFloatingUIPlacement.js +15 -14
- package/lib-commonjs/utils/parseFloatingUIPlacement.js.map +1 -1
- package/lib-commonjs/utils/resolvePositioningShorthand.js +63 -61
- package/lib-commonjs/utils/resolvePositioningShorthand.js.map +1 -1
- package/lib-commonjs/utils/toFloatingUIPadding.js +23 -25
- package/lib-commonjs/utils/toFloatingUIPadding.js.map +1 -1
- package/lib-commonjs/utils/toFloatingUIPlacement.js +31 -33
- package/lib-commonjs/utils/toFloatingUIPlacement.js.map +1 -1
- package/lib-commonjs/utils/toggleScrollListener.js +20 -24
- package/lib-commonjs/utils/toggleScrollListener.js.map +1 -1
- package/lib-commonjs/utils/useCallbackRef.js +39 -53
- package/lib-commonjs/utils/useCallbackRef.js.map +1 -1
- package/lib-commonjs/utils/writeArrowUpdates.js +19 -24
- package/lib-commonjs/utils/writeArrowUpdates.js.map +1 -1
- package/lib-commonjs/utils/writeContainerupdates.js +36 -45
- package/lib-commonjs/utils/writeContainerupdates.js.map +1 -1
- package/package.json +6 -6
|
@@ -1,42 +1,34 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
2
|
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "shift", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: ()=>shift
|
|
5
8
|
});
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
const index_1 = /*#__PURE__*/require("../utils/index");
|
|
9
|
-
/**
|
|
10
|
-
* Wraps the floating UI shift middleware for easier usage of our options
|
|
11
|
-
*/
|
|
9
|
+
const _dom = require("@floating-ui/dom");
|
|
10
|
+
const _index = require("../utils/index");
|
|
12
11
|
function shift(options) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
...(overflowBoundary && {
|
|
36
|
-
altBoundary: true,
|
|
37
|
-
boundary: index_1.getBoundary(container, overflowBoundary)
|
|
38
|
-
})
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
exports.shift = shift;
|
|
12
|
+
const { hasScrollableElement , disableTether , overflowBoundary , container , overflowBoundaryPadding , isRtl } = options;
|
|
13
|
+
return (0, _dom.shift)({
|
|
14
|
+
...hasScrollableElement && {
|
|
15
|
+
boundary: "clippingAncestors"
|
|
16
|
+
},
|
|
17
|
+
...disableTether && {
|
|
18
|
+
crossAxis: disableTether === "all",
|
|
19
|
+
limiter: (0, _dom.limitShift)({
|
|
20
|
+
crossAxis: disableTether !== "all",
|
|
21
|
+
mainAxis: false
|
|
22
|
+
})
|
|
23
|
+
},
|
|
24
|
+
...overflowBoundaryPadding && {
|
|
25
|
+
padding: (0, _index.toFloatingUIPadding)(overflowBoundaryPadding, isRtl)
|
|
26
|
+
},
|
|
27
|
+
...overflowBoundary && {
|
|
28
|
+
altBoundary: true,
|
|
29
|
+
boundary: (0, _index.getBoundary)(container, overflowBoundary)
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
} //# sourceMappingURL=shift.js.map
|
|
33
|
+
|
|
42
34
|
//# sourceMappingURL=shift.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"sources":["../../lib/middleware/shift.js"],"sourcesContent":["import { shift as baseShift, limitShift } from \"@floating-ui/dom\";\nimport { getBoundary, toFloatingUIPadding } from \"../utils/index\";\n/**\n * Wraps the floating UI shift middleware for easier usage of our options\n */\nexport function shift(options) {\n const {\n hasScrollableElement,\n disableTether,\n overflowBoundary,\n container,\n overflowBoundaryPadding,\n isRtl\n } = options;\n return baseShift({\n ...(hasScrollableElement && {\n boundary: \"clippingAncestors\"\n }),\n ...(disableTether && {\n crossAxis: disableTether === \"all\",\n limiter: limitShift({\n crossAxis: disableTether !== \"all\",\n mainAxis: false\n })\n }),\n ...(overflowBoundaryPadding && {\n padding: toFloatingUIPadding(overflowBoundaryPadding, isRtl)\n }),\n ...(overflowBoundary && {\n altBoundary: true,\n boundary: getBoundary(container, overflowBoundary)\n })\n });\n}\n//# sourceMappingURL=shift.js.map"],"names":["shift","options","hasScrollableElement","disableTether","overflowBoundary","container","overflowBoundaryPadding","isRtl","baseShift","boundary","crossAxis","limiter","limitShift","mainAxis","padding","toFloatingUIPadding","altBoundary","getBoundary"],"mappings":";;;;+BAKgBA;;aAAAA;;qBAL+B;uBACE;AAI1C,SAASA,MAAMC,OAAO,EAAE;IAC7B,MAAM,EACJC,qBAAoB,EACpBC,cAAa,EACbC,iBAAgB,EAChBC,UAAS,EACTC,wBAAuB,EACvBC,MAAK,EACN,GAAGN;IACJ,OAAOO,IAAAA,UAAS,EAAC;QACf,GAAIN,wBAAwB;YAC1BO,UAAU;QACZ,CAAC;QACD,GAAIN,iBAAiB;YACnBO,WAAWP,kBAAkB;YAC7BQ,SAASC,IAAAA,eAAU,EAAC;gBAClBF,WAAWP,kBAAkB;gBAC7BU,UAAU,KAAK;YACjB;QACF,CAAC;QACD,GAAIP,2BAA2B;YAC7BQ,SAASC,IAAAA,0BAAmB,EAACT,yBAAyBC;QACxD,CAAC;QACD,GAAIH,oBAAoB;YACtBY,aAAa,IAAI;YACjBP,UAAUQ,IAAAA,kBAAW,EAACZ,WAAWD;QACnC,CAAC;IACH;AACF,EACA,iCAAiC"}
|
package/lib-commonjs/types.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
2
|
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
|
|
3
|
+
value: true
|
|
5
4
|
});
|
|
5
|
+
const _interopRequireWildcard = require("@swc/helpers/lib/_interop_require_wildcard.js").default;
|
|
6
|
+
const _react = /*#__PURE__*/ _interopRequireWildcard(require("react"));
|
|
7
|
+
//# sourceMappingURL=types.js.map
|
|
8
|
+
|
|
6
9
|
//# sourceMappingURL=types.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"sources":["../lib/types.js"],"sourcesContent":["import * as React from \"react\";\n//# sourceMappingURL=types.js.map"],"names":[],"mappings":";;;;;6DAAuB;CACvB,iCAAiC"}
|
|
@@ -1,174 +1,202 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
2
|
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "usePositioning", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: ()=>usePositioning
|
|
5
8
|
});
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
/**
|
|
15
|
-
* @internal
|
|
16
|
-
*/
|
|
9
|
+
const _interopRequireWildcard = require("@swc/helpers/lib/_interop_require_wildcard.js").default;
|
|
10
|
+
const _dom = require("@floating-ui/dom");
|
|
11
|
+
const _reactSharedContexts = require("@fluentui/react-shared-contexts");
|
|
12
|
+
const _reactUtilities = require("@fluentui/react-utilities");
|
|
13
|
+
const _react = /*#__PURE__*/ _interopRequireWildcard(require("react"));
|
|
14
|
+
const _utils = require("./utils");
|
|
15
|
+
const _middleware = require("./middleware");
|
|
16
|
+
const _createPositionManager = require("./createPositionManager");
|
|
17
17
|
function usePositioning(options) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
var _a;
|
|
29
|
-
if (managerRef.current) {
|
|
30
|
-
managerRef.current.dispose();
|
|
31
|
-
}
|
|
32
|
-
managerRef.current = null;
|
|
33
|
-
const target = (_a = overrideTargetRef.current) !== null && _a !== void 0 ? _a : targetRef.current;
|
|
34
|
-
if (enabled && react_utilities_1.canUseDOM() && target && containerRef.current) {
|
|
35
|
-
managerRef.current = createPositionManager_1.createPositionManager({
|
|
36
|
-
container: containerRef.current,
|
|
37
|
-
target,
|
|
38
|
-
arrow: arrowRef.current,
|
|
39
|
-
...resolvePositioningOptions(containerRef.current, arrowRef.current)
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
}, [enabled, resolvePositioningOptions]);
|
|
43
|
-
const setOverrideTarget = react_utilities_1.useEventCallback(target => {
|
|
44
|
-
overrideTargetRef.current = target;
|
|
45
|
-
updatePositionManager();
|
|
46
|
-
});
|
|
47
|
-
React.useImperativeHandle(options.positioningRef, () => ({
|
|
48
|
-
updatePosition: () => {
|
|
49
|
-
var _a;
|
|
50
|
-
return (_a = managerRef.current) === null || _a === void 0 ? void 0 : _a.updatePosition();
|
|
51
|
-
},
|
|
52
|
-
setTarget: target => {
|
|
53
|
-
if (options.target && process.env.NODE_ENV !== 'production') {
|
|
54
|
-
const err = new Error();
|
|
55
|
-
// eslint-disable-next-line no-console
|
|
56
|
-
console.warn('Imperative setTarget should not be used at the same time as target option');
|
|
57
|
-
// eslint-disable-next-line no-console
|
|
58
|
-
console.warn(err.stack);
|
|
59
|
-
}
|
|
60
|
-
setOverrideTarget(target);
|
|
61
|
-
}
|
|
62
|
-
}), [options.target, setOverrideTarget]);
|
|
63
|
-
react_utilities_1.useIsomorphicLayoutEffect(() => {
|
|
64
|
-
var _a;
|
|
65
|
-
setOverrideTarget((_a = options.target) !== null && _a !== void 0 ? _a : null);
|
|
66
|
-
}, [options.target, setOverrideTarget]);
|
|
67
|
-
react_utilities_1.useIsomorphicLayoutEffect(() => {
|
|
68
|
-
updatePositionManager();
|
|
69
|
-
}, [updatePositionManager]);
|
|
70
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
71
|
-
// This checked should run only in development mode
|
|
72
|
-
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
73
|
-
React.useEffect(() => {
|
|
74
|
-
var _a;
|
|
75
|
-
if (containerRef.current) {
|
|
76
|
-
const contentNode = containerRef.current;
|
|
77
|
-
const treeWalker = (_a = contentNode.ownerDocument) === null || _a === void 0 ? void 0 : _a.createTreeWalker(contentNode, NodeFilter.SHOW_ELEMENT, {
|
|
78
|
-
acceptNode: utils_1.hasAutofocusFilter
|
|
79
|
-
});
|
|
80
|
-
while (treeWalker.nextNode()) {
|
|
81
|
-
const node = treeWalker.currentNode;
|
|
82
|
-
// eslint-disable-next-line no-console
|
|
83
|
-
console.warn('<Popper>:', node);
|
|
84
|
-
// eslint-disable-next-line no-console
|
|
85
|
-
console.warn(['<Popper>: ^ this node contains "autoFocus" prop on a React element. This can break the initial', 'positioning of an element and cause a window jump effect. This issue occurs because React polyfills', '"autoFocus" behavior to solve inconsistencies between different browsers:', 'https://github.com/facebook/react/issues/11851#issuecomment-351787078', '\n', 'However, ".focus()" in this case occurs before any other React effects will be executed', '(React.useEffect(), componentDidMount(), etc.) and we can not prevent this behavior. If you really', 'want to use "autoFocus" please add "position: fixed" to styles of the element that is wrapped by', '"Popper".', `In general, it's not recommended to use "autoFocus" as it may break accessibility aspects:`, 'https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/master/docs/rules/no-autofocus.md', '\n', 'We suggest to use the "trapFocus" prop on Fluent components or a catch "ref" and then use', '"ref.current.focus" in React.useEffect():', 'https://reactjs.org/docs/refs-and-the-dom.html#adding-a-ref-to-a-dom-element'].join(' '));
|
|
18
|
+
const managerRef = _react.useRef(null);
|
|
19
|
+
const targetRef = _react.useRef(null);
|
|
20
|
+
const overrideTargetRef = _react.useRef(null);
|
|
21
|
+
const containerRef = _react.useRef(null);
|
|
22
|
+
const arrowRef = _react.useRef(null);
|
|
23
|
+
const { enabled =true } = options;
|
|
24
|
+
const resolvePositioningOptions = usePositioningOptions(options);
|
|
25
|
+
const updatePositionManager = _react.useCallback(()=>{
|
|
26
|
+
if (managerRef.current) {
|
|
27
|
+
managerRef.current.dispose();
|
|
86
28
|
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
29
|
+
managerRef.current = null;
|
|
30
|
+
const target = overrideTargetRef.current ?? targetRef.current;
|
|
31
|
+
if (enabled && (0, _reactUtilities.canUseDOM)() && target && containerRef.current) {
|
|
32
|
+
managerRef.current = (0, _createPositionManager.createPositionManager)({
|
|
33
|
+
container: containerRef.current,
|
|
34
|
+
target,
|
|
35
|
+
arrow: arrowRef.current,
|
|
36
|
+
...resolvePositioningOptions(containerRef.current, arrowRef.current)
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
}, [
|
|
40
|
+
enabled,
|
|
41
|
+
resolvePositioningOptions
|
|
42
|
+
]);
|
|
43
|
+
const setOverrideTarget = (0, _reactUtilities.useEventCallback)((target)=>{
|
|
44
|
+
overrideTargetRef.current = target;
|
|
45
|
+
updatePositionManager();
|
|
46
|
+
});
|
|
47
|
+
_react.useImperativeHandle(options.positioningRef, ()=>({
|
|
48
|
+
updatePosition: ()=>managerRef.current?.updatePosition(),
|
|
49
|
+
setTarget: (target)=>{
|
|
50
|
+
if (options.target && process.env.NODE_ENV !== "production") {
|
|
51
|
+
const err = new Error();
|
|
52
|
+
// eslint-disable-next-line no-console
|
|
53
|
+
console.warn("Imperative setTarget should not be used at the same time as target option");
|
|
54
|
+
// eslint-disable-next-line no-console
|
|
55
|
+
console.warn(err.stack);
|
|
56
|
+
}
|
|
57
|
+
setOverrideTarget(target);
|
|
58
|
+
}
|
|
59
|
+
}), [
|
|
60
|
+
options.target,
|
|
61
|
+
setOverrideTarget
|
|
62
|
+
]);
|
|
63
|
+
(0, _reactUtilities.useIsomorphicLayoutEffect)(()=>{
|
|
64
|
+
setOverrideTarget(options.target ?? null);
|
|
65
|
+
}, [
|
|
66
|
+
options.target,
|
|
67
|
+
setOverrideTarget
|
|
68
|
+
]);
|
|
69
|
+
(0, _reactUtilities.useIsomorphicLayoutEffect)(()=>{
|
|
70
|
+
updatePositionManager();
|
|
71
|
+
}, [
|
|
72
|
+
updatePositionManager
|
|
73
|
+
]);
|
|
74
|
+
if (process.env.NODE_ENV !== "production") {
|
|
75
|
+
// This checked should run only in development mode
|
|
76
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
77
|
+
_react.useEffect(()=>{
|
|
78
|
+
if (containerRef.current) {
|
|
79
|
+
const contentNode = containerRef.current;
|
|
80
|
+
const treeWalker = contentNode.ownerDocument?.createTreeWalker(contentNode, NodeFilter.SHOW_ELEMENT, {
|
|
81
|
+
acceptNode: _utils.hasAutofocusFilter
|
|
82
|
+
});
|
|
83
|
+
while(treeWalker.nextNode()){
|
|
84
|
+
const node = treeWalker.currentNode;
|
|
85
|
+
// eslint-disable-next-line no-console
|
|
86
|
+
console.warn("<Popper>:", node);
|
|
87
|
+
// eslint-disable-next-line no-console
|
|
88
|
+
console.warn([
|
|
89
|
+
'<Popper>: ^ this node contains "autoFocus" prop on a React element. This can break the initial',
|
|
90
|
+
"positioning of an element and cause a window jump effect. This issue occurs because React polyfills",
|
|
91
|
+
'"autoFocus" behavior to solve inconsistencies between different browsers:',
|
|
92
|
+
"https://github.com/facebook/react/issues/11851#issuecomment-351787078",
|
|
93
|
+
"\n",
|
|
94
|
+
'However, ".focus()" in this case occurs before any other React effects will be executed',
|
|
95
|
+
"(React.useEffect(), componentDidMount(), etc.) and we can not prevent this behavior. If you really",
|
|
96
|
+
'want to use "autoFocus" please add "position: fixed" to styles of the element that is wrapped by',
|
|
97
|
+
'"Popper".',
|
|
98
|
+
`In general, it's not recommended to use "autoFocus" as it may break accessibility aspects:`,
|
|
99
|
+
"https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/master/docs/rules/no-autofocus.md",
|
|
100
|
+
"\n",
|
|
101
|
+
'We suggest to use the "trapFocus" prop on Fluent components or a catch "ref" and then use',
|
|
102
|
+
'"ref.current.focus" in React.useEffect():',
|
|
103
|
+
"https://reactjs.org/docs/refs-and-the-dom.html#adding-a-ref-to-a-dom-element"
|
|
104
|
+
].join(" "));
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
// We run this check once, no need to add deps here
|
|
108
|
+
// TODO: Should be rework to handle options.enabled and contentRef updates
|
|
109
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
110
|
+
}, []);
|
|
109
111
|
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
position,
|
|
130
|
-
unstable_disableTether: disableTether,
|
|
131
|
-
positionFixed,
|
|
132
|
-
overflowBoundaryPadding,
|
|
133
|
-
fallbackPositions
|
|
134
|
-
} = options;
|
|
135
|
-
const {
|
|
136
|
-
dir
|
|
137
|
-
} = react_shared_contexts_1.useFluent_unstable();
|
|
138
|
-
const isRtl = dir === 'rtl';
|
|
139
|
-
const strategy = positionFixed ? 'fixed' : 'absolute';
|
|
140
|
-
return React.useCallback((container, arrow) => {
|
|
141
|
-
const hasScrollableElement = utils_1.hasScrollParent(container);
|
|
142
|
-
const middleware = [offset && middleware_1.offset(offset), coverTarget && middleware_1.coverTarget(), !pinned && middleware_1.flip({
|
|
143
|
-
container,
|
|
144
|
-
flipBoundary,
|
|
145
|
-
hasScrollableElement,
|
|
146
|
-
isRtl,
|
|
147
|
-
fallbackPositions
|
|
148
|
-
}), middleware_1.shift({
|
|
149
|
-
container,
|
|
150
|
-
hasScrollableElement,
|
|
151
|
-
overflowBoundary,
|
|
152
|
-
disableTether,
|
|
153
|
-
overflowBoundaryPadding,
|
|
154
|
-
isRtl
|
|
155
|
-
}), autoSize && middleware_1.maxSize(autoSize, {
|
|
156
|
-
container,
|
|
157
|
-
overflowBoundary
|
|
158
|
-
}), middleware_1.intersecting(), arrow && dom_1.arrow({
|
|
159
|
-
element: arrow,
|
|
160
|
-
padding: arrowPadding
|
|
161
|
-
}), dom_1.hide({
|
|
162
|
-
strategy: 'referenceHidden'
|
|
163
|
-
}), dom_1.hide({
|
|
164
|
-
strategy: 'escaped'
|
|
165
|
-
})].filter(Boolean);
|
|
166
|
-
const placement = utils_1.toFloatingUIPlacement(align, position, isRtl);
|
|
112
|
+
const setTarget = (0, _utils.useCallbackRef)(null, (target)=>{
|
|
113
|
+
if (targetRef.current !== target) {
|
|
114
|
+
targetRef.current = target;
|
|
115
|
+
updatePositionManager();
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
const setContainer = (0, _utils.useCallbackRef)(null, (container)=>{
|
|
119
|
+
if (containerRef.current !== container) {
|
|
120
|
+
containerRef.current = container;
|
|
121
|
+
updatePositionManager();
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
const setArrow = (0, _utils.useCallbackRef)(null, (arrow)=>{
|
|
125
|
+
if (arrowRef.current !== arrow) {
|
|
126
|
+
arrowRef.current = arrow;
|
|
127
|
+
updatePositionManager();
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
// Let users use callback refs so they feel like 'normal' DOM refs
|
|
167
131
|
return {
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
132
|
+
targetRef: setTarget,
|
|
133
|
+
containerRef: setContainer,
|
|
134
|
+
arrowRef: setArrow
|
|
171
135
|
};
|
|
172
|
-
}, [align, arrowPadding, autoSize, coverTarget, disableTether, flipBoundary, isRtl, offset, overflowBoundary, pinned, position, strategy, overflowBoundaryPadding, fallbackPositions]);
|
|
173
136
|
}
|
|
137
|
+
function usePositioningOptions(options) {
|
|
138
|
+
const { align , arrowPadding , autoSize , coverTarget , flipBoundary , offset , overflowBoundary , pinned , position , unstable_disableTether: disableTether , positionFixed , overflowBoundaryPadding , fallbackPositions } = options;
|
|
139
|
+
const { dir } = (0, _reactSharedContexts.useFluent_unstable)();
|
|
140
|
+
const isRtl = dir === "rtl";
|
|
141
|
+
const strategy = positionFixed ? "fixed" : "absolute";
|
|
142
|
+
return _react.useCallback((container, arrow)=>{
|
|
143
|
+
const hasScrollableElement = (0, _utils.hasScrollParent)(container);
|
|
144
|
+
const middleware = [
|
|
145
|
+
offset && (0, _middleware.offset)(offset),
|
|
146
|
+
coverTarget && (0, _middleware.coverTarget)(),
|
|
147
|
+
!pinned && (0, _middleware.flip)({
|
|
148
|
+
container,
|
|
149
|
+
flipBoundary,
|
|
150
|
+
hasScrollableElement,
|
|
151
|
+
isRtl,
|
|
152
|
+
fallbackPositions
|
|
153
|
+
}),
|
|
154
|
+
(0, _middleware.shift)({
|
|
155
|
+
container,
|
|
156
|
+
hasScrollableElement,
|
|
157
|
+
overflowBoundary,
|
|
158
|
+
disableTether,
|
|
159
|
+
overflowBoundaryPadding,
|
|
160
|
+
isRtl
|
|
161
|
+
}),
|
|
162
|
+
autoSize && (0, _middleware.maxSize)(autoSize, {
|
|
163
|
+
container,
|
|
164
|
+
overflowBoundary
|
|
165
|
+
}),
|
|
166
|
+
(0, _middleware.intersecting)(),
|
|
167
|
+
arrow && (0, _dom.arrow)({
|
|
168
|
+
element: arrow,
|
|
169
|
+
padding: arrowPadding
|
|
170
|
+
}),
|
|
171
|
+
(0, _dom.hide)({
|
|
172
|
+
strategy: "referenceHidden"
|
|
173
|
+
}),
|
|
174
|
+
(0, _dom.hide)({
|
|
175
|
+
strategy: "escaped"
|
|
176
|
+
})
|
|
177
|
+
].filter(Boolean);
|
|
178
|
+
const placement = (0, _utils.toFloatingUIPlacement)(align, position, isRtl);
|
|
179
|
+
return {
|
|
180
|
+
placement,
|
|
181
|
+
middleware,
|
|
182
|
+
strategy
|
|
183
|
+
};
|
|
184
|
+
}, [
|
|
185
|
+
align,
|
|
186
|
+
arrowPadding,
|
|
187
|
+
autoSize,
|
|
188
|
+
coverTarget,
|
|
189
|
+
disableTether,
|
|
190
|
+
flipBoundary,
|
|
191
|
+
isRtl,
|
|
192
|
+
offset,
|
|
193
|
+
overflowBoundary,
|
|
194
|
+
pinned,
|
|
195
|
+
position,
|
|
196
|
+
strategy,
|
|
197
|
+
overflowBoundaryPadding,
|
|
198
|
+
fallbackPositions
|
|
199
|
+
]);
|
|
200
|
+
} //# sourceMappingURL=usePositioning.js.map
|
|
201
|
+
|
|
174
202
|
//# sourceMappingURL=usePositioning.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["dom_1","require","react_shared_contexts_1","react_utilities_1","React","utils_1","middleware_1","createPositionManager_1","usePositioning","options","managerRef","useRef","targetRef","overrideTargetRef","containerRef","arrowRef","enabled","resolvePositioningOptions","usePositioningOptions","updatePositionManager","useCallback","current","dispose","target","_a","canUseDOM","createPositionManager","container","arrow","setOverrideTarget","useEventCallback","useImperativeHandle","positioningRef","updatePosition","setTarget","process","env","NODE_ENV","err","Error","console","warn","stack","useIsomorphicLayoutEffect","useEffect","contentNode","treeWalker","ownerDocument","createTreeWalker","NodeFilter","SHOW_ELEMENT","acceptNode","hasAutofocusFilter","nextNode","node","currentNode","join","useCallbackRef","setContainer","setArrow","exports","align","arrowPadding","autoSize","coverTarget","flipBoundary","offset","overflowBoundary","pinned","position","unstable_disableTether","disableTether","positionFixed","overflowBoundaryPadding","fallbackPositions","dir","useFluent_unstable","isRtl","strategy","hasScrollableElement","hasScrollParent","middleware","flip","shift","maxSize","intersecting","element","padding","hide","filter","Boolean","placement","toFloatingUIPlacement"],"sources":["../../../../../../../packages/react-components/react-positioning/src/usePositioning.ts"],"sourcesContent":["import { hide as hideMiddleware, arrow as arrowMiddleware } from '@floating-ui/dom';\nimport type { Middleware, Strategy } from '@floating-ui/dom';\nimport { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';\nimport { canUseDOM, useEventCallback, useIsomorphicLayoutEffect } from '@fluentui/react-utilities';\nimport * as React from 'react';\nimport type {\n PositioningOptions,\n PositioningProps,\n PositionManager,\n TargetElement,\n UsePositioningReturn,\n} from './types';\nimport { useCallbackRef, toFloatingUIPlacement, hasAutofocusFilter, hasScrollParent } from './utils';\nimport {\n shift as shiftMiddleware,\n flip as flipMiddleware,\n coverTarget as coverTargetMiddleware,\n maxSize as maxSizeMiddleware,\n offset as offsetMiddleware,\n intersecting as intersectingMiddleware,\n} from './middleware';\nimport { createPositionManager } from './createPositionManager';\n\n/**\n * @internal\n */\nexport function usePositioning(options: UsePositioningOptions): UsePositioningReturn {\n const managerRef = React.useRef<PositionManager | null>(null);\n const targetRef = React.useRef<TargetElement | null>(null);\n const overrideTargetRef = React.useRef<TargetElement | null>(null);\n const containerRef = React.useRef<HTMLElement | null>(null);\n const arrowRef = React.useRef<HTMLElement | null>(null);\n\n const { enabled = true } = options;\n const resolvePositioningOptions = usePositioningOptions(options);\n const updatePositionManager = React.useCallback(() => {\n if (managerRef.current) {\n managerRef.current.dispose();\n }\n managerRef.current = null;\n\n const target = overrideTargetRef.current ?? targetRef.current;\n\n if (enabled && canUseDOM() && target && containerRef.current) {\n managerRef.current = createPositionManager({\n container: containerRef.current,\n target,\n arrow: arrowRef.current,\n ...resolvePositioningOptions(containerRef.current, arrowRef.current),\n });\n }\n }, [enabled, resolvePositioningOptions]);\n\n const setOverrideTarget = useEventCallback((target: TargetElement | null) => {\n overrideTargetRef.current = target;\n updatePositionManager();\n });\n\n React.useImperativeHandle(\n options.positioningRef,\n () => ({\n updatePosition: () => managerRef.current?.updatePosition(),\n setTarget: (target: TargetElement) => {\n if (options.target && process.env.NODE_ENV !== 'production') {\n const err = new Error();\n // eslint-disable-next-line no-console\n console.warn('Imperative setTarget should not be used at the same time as target option');\n // eslint-disable-next-line no-console\n console.warn(err.stack);\n }\n\n setOverrideTarget(target);\n },\n }),\n [options.target, setOverrideTarget],\n );\n\n useIsomorphicLayoutEffect(() => {\n setOverrideTarget(options.target ?? null);\n }, [options.target, setOverrideTarget]);\n\n useIsomorphicLayoutEffect(() => {\n updatePositionManager();\n }, [updatePositionManager]);\n\n if (process.env.NODE_ENV !== 'production') {\n // This checked should run only in development mode\n // eslint-disable-next-line react-hooks/rules-of-hooks\n React.useEffect(() => {\n if (containerRef.current) {\n const contentNode = containerRef.current;\n const treeWalker = contentNode.ownerDocument?.createTreeWalker(contentNode, NodeFilter.SHOW_ELEMENT, {\n acceptNode: hasAutofocusFilter,\n });\n\n while (treeWalker.nextNode()) {\n const node = treeWalker.currentNode;\n // eslint-disable-next-line no-console\n console.warn('<Popper>:', node);\n // eslint-disable-next-line no-console\n console.warn(\n [\n '<Popper>: ^ this node contains \"autoFocus\" prop on a React element. This can break the initial',\n 'positioning of an element and cause a window jump effect. This issue occurs because React polyfills',\n '\"autoFocus\" behavior to solve inconsistencies between different browsers:',\n 'https://github.com/facebook/react/issues/11851#issuecomment-351787078',\n '\\n',\n 'However, \".focus()\" in this case occurs before any other React effects will be executed',\n '(React.useEffect(), componentDidMount(), etc.) and we can not prevent this behavior. If you really',\n 'want to use \"autoFocus\" please add \"position: fixed\" to styles of the element that is wrapped by',\n '\"Popper\".',\n `In general, it's not recommended to use \"autoFocus\" as it may break accessibility aspects:`,\n 'https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/master/docs/rules/no-autofocus.md',\n '\\n',\n 'We suggest to use the \"trapFocus\" prop on Fluent components or a catch \"ref\" and then use',\n '\"ref.current.focus\" in React.useEffect():',\n 'https://reactjs.org/docs/refs-and-the-dom.html#adding-a-ref-to-a-dom-element',\n ].join(' '),\n );\n }\n }\n // We run this check once, no need to add deps here\n // TODO: Should be rework to handle options.enabled and contentRef updates\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n }\n\n const setTarget = useCallbackRef<TargetElement>(null, target => {\n if (targetRef.current !== target) {\n targetRef.current = target;\n updatePositionManager();\n }\n });\n\n const setContainer = useCallbackRef<HTMLElement | null>(null, container => {\n if (containerRef.current !== container) {\n containerRef.current = container;\n updatePositionManager();\n }\n });\n\n const setArrow = useCallbackRef<HTMLElement | null>(null, arrow => {\n if (arrowRef.current !== arrow) {\n arrowRef.current = arrow;\n updatePositionManager();\n }\n });\n\n // Let users use callback refs so they feel like 'normal' DOM refs\n return { targetRef: setTarget, containerRef: setContainer, arrowRef: setArrow };\n}\n\ninterface UsePositioningOptions extends PositioningProps, Pick<PositioningOptions, 'fallbackPositions' | 'pinned'> {\n /**\n * If false, does not position anything\n */\n enabled?: boolean;\n}\n\nfunction usePositioningOptions(options: PositioningOptions) {\n const {\n align,\n arrowPadding,\n autoSize,\n coverTarget,\n flipBoundary,\n offset,\n overflowBoundary,\n pinned,\n position,\n unstable_disableTether: disableTether,\n positionFixed,\n overflowBoundaryPadding,\n fallbackPositions,\n } = options;\n\n const { dir } = useFluent();\n const isRtl = dir === 'rtl';\n const strategy: Strategy = positionFixed ? 'fixed' : 'absolute';\n\n return React.useCallback(\n (container: HTMLElement | null, arrow: HTMLElement | null) => {\n const hasScrollableElement = hasScrollParent(container);\n\n const middleware = [\n offset && offsetMiddleware(offset),\n coverTarget && coverTargetMiddleware(),\n !pinned && flipMiddleware({ container, flipBoundary, hasScrollableElement, isRtl, fallbackPositions }),\n shiftMiddleware({\n container,\n hasScrollableElement,\n overflowBoundary,\n disableTether,\n overflowBoundaryPadding,\n isRtl,\n }),\n autoSize && maxSizeMiddleware(autoSize, { container, overflowBoundary }),\n intersectingMiddleware(),\n arrow && arrowMiddleware({ element: arrow, padding: arrowPadding }),\n hideMiddleware({ strategy: 'referenceHidden' }),\n hideMiddleware({ strategy: 'escaped' }),\n ].filter(Boolean) as Middleware[];\n\n const placement = toFloatingUIPlacement(align, position, isRtl);\n\n return {\n placement,\n middleware,\n strategy,\n };\n },\n [\n align,\n arrowPadding,\n autoSize,\n coverTarget,\n disableTether,\n flipBoundary,\n isRtl,\n offset,\n overflowBoundary,\n pinned,\n position,\n strategy,\n overflowBoundaryPadding,\n fallbackPositions,\n ],\n );\n}\n"],"mappings":";;;;;;AAAA,MAAAA,KAAA,gBAAAC,OAAA;AAEA,MAAAC,uBAAA,gBAAAD,OAAA;AACA,MAAAE,iBAAA,gBAAAF,OAAA;AACA,MAAAG,KAAA,gBAAAH,OAAA;AAQA,MAAAI,OAAA,gBAAAJ,OAAA;AACA,MAAAK,YAAA,gBAAAL,OAAA;AAQA,MAAAM,uBAAA,gBAAAN,OAAA;AAEA;;;AAGA,SAAgBO,cAAcA,CAACC,OAA8B;EAC3D,MAAMC,UAAU,GAAGN,KAAK,CAACO,MAAM,CAAyB,IAAI,CAAC;EAC7D,MAAMC,SAAS,GAAGR,KAAK,CAACO,MAAM,CAAuB,IAAI,CAAC;EAC1D,MAAME,iBAAiB,GAAGT,KAAK,CAACO,MAAM,CAAuB,IAAI,CAAC;EAClE,MAAMG,YAAY,GAAGV,KAAK,CAACO,MAAM,CAAqB,IAAI,CAAC;EAC3D,MAAMI,QAAQ,GAAGX,KAAK,CAACO,MAAM,CAAqB,IAAI,CAAC;EAEvD,MAAM;IAAEK,OAAO,GAAG;EAAI,CAAE,GAAGP,OAAO;EAClC,MAAMQ,yBAAyB,GAAGC,qBAAqB,CAACT,OAAO,CAAC;EAChE,MAAMU,qBAAqB,GAAGf,KAAK,CAACgB,WAAW,CAAC,MAAK;;IACnD,IAAIV,UAAU,CAACW,OAAO,EAAE;MACtBX,UAAU,CAACW,OAAO,CAACC,OAAO,EAAE;;IAE9BZ,UAAU,CAACW,OAAO,GAAG,IAAI;IAEzB,MAAME,MAAM,GAAG,CAAAC,EAAA,GAAAX,iBAAiB,CAACQ,OAAO,cAAAG,EAAA,cAAAA,EAAA,GAAIZ,SAAS,CAACS,OAAO;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AQ,EACRS,QAAQ,EACRL,uBAAuB,EACvBC,iBAAiB,CAClB,CACF;AACH"}
|
|
1
|
+
{"version":3,"sources":["../lib/usePositioning.js"],"sourcesContent":["import { hide as hideMiddleware, arrow as arrowMiddleware } from \"@floating-ui/dom\";\nimport { useFluent_unstable as useFluent } from \"@fluentui/react-shared-contexts\";\nimport { canUseDOM, useEventCallback, useIsomorphicLayoutEffect } from \"@fluentui/react-utilities\";\nimport * as React from \"react\";\nimport { useCallbackRef, toFloatingUIPlacement, hasAutofocusFilter, hasScrollParent } from \"./utils\";\nimport { shift as shiftMiddleware, flip as flipMiddleware, coverTarget as coverTargetMiddleware, maxSize as maxSizeMiddleware, offset as offsetMiddleware, intersecting as intersectingMiddleware } from \"./middleware\";\nimport { createPositionManager } from \"./createPositionManager\";\n/**\n * @internal\n */\nexport function usePositioning(options) {\n const managerRef = React.useRef(null);\n const targetRef = React.useRef(null);\n const overrideTargetRef = React.useRef(null);\n const containerRef = React.useRef(null);\n const arrowRef = React.useRef(null);\n const {\n enabled = true\n } = options;\n const resolvePositioningOptions = usePositioningOptions(options);\n const updatePositionManager = React.useCallback(() => {\n if (managerRef.current) {\n managerRef.current.dispose();\n }\n managerRef.current = null;\n const target = overrideTargetRef.current ?? targetRef.current;\n if (enabled && canUseDOM() && target && containerRef.current) {\n managerRef.current = createPositionManager({\n container: containerRef.current,\n target,\n arrow: arrowRef.current,\n ...resolvePositioningOptions(containerRef.current, arrowRef.current)\n });\n }\n }, [enabled, resolvePositioningOptions]);\n const setOverrideTarget = useEventCallback(target => {\n overrideTargetRef.current = target;\n updatePositionManager();\n });\n React.useImperativeHandle(options.positioningRef, () => ({\n updatePosition: () => managerRef.current?.updatePosition(),\n setTarget: target => {\n if (options.target && process.env.NODE_ENV !== \"production\") {\n const err = new Error();\n // eslint-disable-next-line no-console\n console.warn(\"Imperative setTarget should not be used at the same time as target option\");\n // eslint-disable-next-line no-console\n console.warn(err.stack);\n }\n setOverrideTarget(target);\n }\n }), [options.target, setOverrideTarget]);\n useIsomorphicLayoutEffect(() => {\n setOverrideTarget(options.target ?? null);\n }, [options.target, setOverrideTarget]);\n useIsomorphicLayoutEffect(() => {\n updatePositionManager();\n }, [updatePositionManager]);\n if (process.env.NODE_ENV !== \"production\") {\n // This checked should run only in development mode\n // eslint-disable-next-line react-hooks/rules-of-hooks\n React.useEffect(() => {\n if (containerRef.current) {\n const contentNode = containerRef.current;\n const treeWalker = contentNode.ownerDocument?.createTreeWalker(contentNode, NodeFilter.SHOW_ELEMENT, {\n acceptNode: hasAutofocusFilter\n });\n while (treeWalker.nextNode()) {\n const node = treeWalker.currentNode;\n // eslint-disable-next-line no-console\n console.warn(\"<Popper>:\", node);\n // eslint-disable-next-line no-console\n console.warn(['<Popper>: ^ this node contains \"autoFocus\" prop on a React element. This can break the initial', \"positioning of an element and cause a window jump effect. This issue occurs because React polyfills\", '\"autoFocus\" behavior to solve inconsistencies between different browsers:', \"https://github.com/facebook/react/issues/11851#issuecomment-351787078\", \"\\n\", 'However, \".focus()\" in this case occurs before any other React effects will be executed', \"(React.useEffect(), componentDidMount(), etc.) and we can not prevent this behavior. If you really\", 'want to use \"autoFocus\" please add \"position: fixed\" to styles of the element that is wrapped by', '\"Popper\".', `In general, it's not recommended to use \"autoFocus\" as it may break accessibility aspects:`, \"https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/master/docs/rules/no-autofocus.md\", \"\\n\", 'We suggest to use the \"trapFocus\" prop on Fluent components or a catch \"ref\" and then use', '\"ref.current.focus\" in React.useEffect():', \"https://reactjs.org/docs/refs-and-the-dom.html#adding-a-ref-to-a-dom-element\"].join(\" \"));\n }\n }\n // We run this check once, no need to add deps here\n // TODO: Should be rework to handle options.enabled and contentRef updates\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n }\n const setTarget = useCallbackRef(null, target => {\n if (targetRef.current !== target) {\n targetRef.current = target;\n updatePositionManager();\n }\n });\n const setContainer = useCallbackRef(null, container => {\n if (containerRef.current !== container) {\n containerRef.current = container;\n updatePositionManager();\n }\n });\n const setArrow = useCallbackRef(null, arrow => {\n if (arrowRef.current !== arrow) {\n arrowRef.current = arrow;\n updatePositionManager();\n }\n });\n // Let users use callback refs so they feel like 'normal' DOM refs\n return {\n targetRef: setTarget,\n containerRef: setContainer,\n arrowRef: setArrow\n };\n}\nfunction usePositioningOptions(options) {\n const {\n align,\n arrowPadding,\n autoSize,\n coverTarget,\n flipBoundary,\n offset,\n overflowBoundary,\n pinned,\n position,\n unstable_disableTether: disableTether,\n positionFixed,\n overflowBoundaryPadding,\n fallbackPositions\n } = options;\n const {\n dir\n } = useFluent();\n const isRtl = dir === \"rtl\";\n const strategy = positionFixed ? \"fixed\" : \"absolute\";\n return React.useCallback((container, arrow) => {\n const hasScrollableElement = hasScrollParent(container);\n const middleware = [offset && offsetMiddleware(offset), coverTarget && coverTargetMiddleware(), !pinned && flipMiddleware({\n container,\n flipBoundary,\n hasScrollableElement,\n isRtl,\n fallbackPositions\n }), shiftMiddleware({\n container,\n hasScrollableElement,\n overflowBoundary,\n disableTether,\n overflowBoundaryPadding,\n isRtl\n }), autoSize && maxSizeMiddleware(autoSize, {\n container,\n overflowBoundary\n }), intersectingMiddleware(), arrow && arrowMiddleware({\n element: arrow,\n padding: arrowPadding\n }), hideMiddleware({\n strategy: \"referenceHidden\"\n }), hideMiddleware({\n strategy: \"escaped\"\n })].filter(Boolean);\n const placement = toFloatingUIPlacement(align, position, isRtl);\n return {\n placement,\n middleware,\n strategy\n };\n }, [align, arrowPadding, autoSize, coverTarget, disableTether, flipBoundary, isRtl, offset, overflowBoundary, pinned, position, strategy, overflowBoundaryPadding, fallbackPositions]);\n}\n//# sourceMappingURL=usePositioning.js.map"],"names":["usePositioning","options","managerRef","React","useRef","targetRef","overrideTargetRef","containerRef","arrowRef","enabled","resolvePositioningOptions","usePositioningOptions","updatePositionManager","useCallback","current","dispose","target","canUseDOM","createPositionManager","container","arrow","setOverrideTarget","useEventCallback","useImperativeHandle","positioningRef","updatePosition","setTarget","process","env","NODE_ENV","err","Error","console","warn","stack","useIsomorphicLayoutEffect","useEffect","contentNode","treeWalker","ownerDocument","createTreeWalker","NodeFilter","SHOW_ELEMENT","acceptNode","hasAutofocusFilter","nextNode","node","currentNode","join","useCallbackRef","setContainer","setArrow","align","arrowPadding","autoSize","coverTarget","flipBoundary","offset","overflowBoundary","pinned","position","unstable_disableTether","disableTether","positionFixed","overflowBoundaryPadding","fallbackPositions","dir","useFluent","isRtl","strategy","hasScrollableElement","hasScrollParent","middleware","offsetMiddleware","coverTargetMiddleware","flipMiddleware","shiftMiddleware","maxSizeMiddleware","intersectingMiddleware","arrowMiddleware","element","padding","hideMiddleware","filter","Boolean","placement","toFloatingUIPlacement"],"mappings":";;;;+BAUgBA;;aAAAA;;;qBAViD;qCACjB;gCACuB;6DAChD;uBACoE;4BAC8G;uCACnK;AAI/B,SAASA,eAAeC,OAAO,EAAE;IACtC,MAAMC,aAAaC,OAAMC,MAAM,CAAC,IAAI;IACpC,MAAMC,YAAYF,OAAMC,MAAM,CAAC,IAAI;IACnC,MAAME,oBAAoBH,OAAMC,MAAM,CAAC,IAAI;IAC3C,MAAMG,eAAeJ,OAAMC,MAAM,CAAC,IAAI;IACtC,MAAMI,WAAWL,OAAMC,MAAM,CAAC,IAAI;IAClC,MAAM,EACJK,SAAU,IAAI,CAAA,EACf,GAAGR;IACJ,MAAMS,4BAA4BC,sBAAsBV;IACxD,MAAMW,wBAAwBT,OAAMU,WAAW,CAAC,IAAM;QACpD,IAAIX,WAAWY,OAAO,EAAE;YACtBZ,WAAWY,OAAO,CAACC,OAAO;QAC5B,CAAC;QACDb,WAAWY,OAAO,GAAG,IAAI;QACzB,MAAME,SAASV,kBAAkBQ,OAAO,IAAIT,UAAUS,OAAO;QAC7D,IAAIL,WAAWQ,IAAAA,yBAAS,OAAMD,UAAUT,aAAaO,OAAO,EAAE;YAC5DZ,WAAWY,OAAO,GAAGI,IAAAA,4CAAqB,EAAC;gBACzCC,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