@fluentui/react-positioning 0.0.0-nightly-20230321-0440.1 → 0.0.0-nightly-20230322-0439.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.
Files changed (111) hide show
  1. package/.swcrc +30 -0
  2. package/CHANGELOG.json +48 -9
  3. package/CHANGELOG.md +20 -7
  4. package/lib/constants.js.map +1 -1
  5. package/lib/createArrowStyles.js.map +1 -1
  6. package/lib/createPositionManager.js.map +1 -1
  7. package/lib/createVirtualElementFromClick.js +1 -2
  8. package/lib/createVirtualElementFromClick.js.map +1 -1
  9. package/lib/index.js.map +1 -1
  10. package/lib/middleware/coverTarget.js.map +1 -1
  11. package/lib/middleware/flip.js.map +1 -1
  12. package/lib/middleware/index.js.map +1 -1
  13. package/lib/middleware/intersecting.js.map +1 -1
  14. package/lib/middleware/maxSize.js.map +1 -1
  15. package/lib/middleware/offset.js.map +1 -1
  16. package/lib/middleware/shift.js.map +1 -1
  17. package/lib/types.js +1 -1
  18. package/lib/types.js.map +1 -1
  19. package/lib/usePositioning.js +23 -21
  20. package/lib/usePositioning.js.map +1 -1
  21. package/lib/usePositioningMouseTarget.js.map +1 -1
  22. package/lib/utils/debounce.js +1 -2
  23. package/lib/utils/debounce.js.map +1 -1
  24. package/lib/utils/fromFloatingUIPlacement.js.map +1 -1
  25. package/lib/utils/getBoundary.js.map +1 -1
  26. package/lib/utils/getFloatingUIOffset.js.map +1 -1
  27. package/lib/utils/getReactFiberFromNode.js +1 -0
  28. package/lib/utils/getReactFiberFromNode.js.map +1 -1
  29. package/lib/utils/getScrollParent.js +5 -6
  30. package/lib/utils/getScrollParent.js.map +1 -1
  31. package/lib/utils/hasAutoFocusFilter.js +2 -2
  32. package/lib/utils/hasAutoFocusFilter.js.map +1 -1
  33. package/lib/utils/index.js.map +1 -1
  34. package/lib/utils/mergeArrowOffset.js +3 -4
  35. package/lib/utils/mergeArrowOffset.js.map +1 -1
  36. package/lib/utils/parseFloatingUIPlacement.js +1 -2
  37. package/lib/utils/parseFloatingUIPlacement.js.map +1 -1
  38. package/lib/utils/resolvePositioningShorthand.js.map +1 -1
  39. package/lib/utils/toFloatingUIPadding.js.map +1 -1
  40. package/lib/utils/toFloatingUIPlacement.js.map +1 -1
  41. package/lib/utils/toggleScrollListener.js.map +1 -1
  42. package/lib/utils/useCallbackRef.js.map +1 -1
  43. package/lib/utils/writeArrowUpdates.js +1 -2
  44. package/lib/utils/writeArrowUpdates.js.map +1 -1
  45. package/lib/utils/writeContainerupdates.js +4 -4
  46. package/lib/utils/writeContainerupdates.js.map +1 -1
  47. package/lib-commonjs/constants.js +18 -7
  48. package/lib-commonjs/constants.js.map +1 -1
  49. package/lib-commonjs/createArrowStyles.js +60 -88
  50. package/lib-commonjs/createArrowStyles.js.map +1 -1
  51. package/lib-commonjs/createPositionManager.js +103 -117
  52. package/lib-commonjs/createPositionManager.js.map +1 -1
  53. package/lib-commonjs/createVirtualElementFromClick.js +27 -26
  54. package/lib-commonjs/createVirtualElementFromClick.js.map +1 -1
  55. package/lib-commonjs/index.js +24 -51
  56. package/lib-commonjs/index.js.map +1 -1
  57. package/lib-commonjs/middleware/coverTarget.js +34 -37
  58. package/lib-commonjs/middleware/coverTarget.js.map +1 -1
  59. package/lib-commonjs/middleware/flip.js +31 -38
  60. package/lib-commonjs/middleware/flip.js.map +1 -1
  61. package/lib-commonjs/middleware/index.js +10 -9
  62. package/lib-commonjs/middleware/index.js.map +1 -1
  63. package/lib-commonjs/middleware/intersecting.js +24 -22
  64. package/lib-commonjs/middleware/intersecting.js.map +1 -1
  65. package/lib-commonjs/middleware/maxSize.js +34 -40
  66. package/lib-commonjs/middleware/maxSize.js.map +1 -1
  67. package/lib-commonjs/middleware/offset.js +11 -12
  68. package/lib-commonjs/middleware/offset.js.map +1 -1
  69. package/lib-commonjs/middleware/shift.js +29 -37
  70. package/lib-commonjs/middleware/shift.js.map +1 -1
  71. package/lib-commonjs/types.js +5 -2
  72. package/lib-commonjs/types.js.map +1 -1
  73. package/lib-commonjs/usePositioning.js +200 -164
  74. package/lib-commonjs/usePositioning.js.map +1 -1
  75. package/lib-commonjs/usePositioningMouseTarget.js +34 -37
  76. package/lib-commonjs/usePositioningMouseTarget.js.map +1 -1
  77. package/lib-commonjs/utils/debounce.js +22 -21
  78. package/lib-commonjs/utils/debounce.js.map +1 -1
  79. package/lib-commonjs/utils/fromFloatingUIPlacement.js +30 -35
  80. package/lib-commonjs/utils/fromFloatingUIPlacement.js.map +1 -1
  81. package/lib-commonjs/utils/getBoundary.js +21 -22
  82. package/lib-commonjs/utils/getBoundary.js.map +1 -1
  83. package/lib-commonjs/utils/getFloatingUIOffset.js +23 -35
  84. package/lib-commonjs/utils/getFloatingUIOffset.js.map +1 -1
  85. package/lib-commonjs/utils/getReactFiberFromNode.js +45 -41
  86. package/lib-commonjs/utils/getReactFiberFromNode.js.map +1 -1
  87. package/lib-commonjs/utils/getScrollParent.js +52 -56
  88. package/lib-commonjs/utils/getScrollParent.js.map +1 -1
  89. package/lib-commonjs/utils/hasAutoFocusFilter.js +18 -17
  90. package/lib-commonjs/utils/hasAutoFocusFilter.js.map +1 -1
  91. package/lib-commonjs/utils/index.js +19 -18
  92. package/lib-commonjs/utils/index.js.map +1 -1
  93. package/lib-commonjs/utils/mergeArrowOffset.js +33 -32
  94. package/lib-commonjs/utils/mergeArrowOffset.js.map +1 -1
  95. package/lib-commonjs/utils/parseFloatingUIPlacement.js +15 -14
  96. package/lib-commonjs/utils/parseFloatingUIPlacement.js.map +1 -1
  97. package/lib-commonjs/utils/resolvePositioningShorthand.js +63 -61
  98. package/lib-commonjs/utils/resolvePositioningShorthand.js.map +1 -1
  99. package/lib-commonjs/utils/toFloatingUIPadding.js +23 -25
  100. package/lib-commonjs/utils/toFloatingUIPadding.js.map +1 -1
  101. package/lib-commonjs/utils/toFloatingUIPlacement.js +31 -33
  102. package/lib-commonjs/utils/toFloatingUIPlacement.js.map +1 -1
  103. package/lib-commonjs/utils/toggleScrollListener.js +20 -24
  104. package/lib-commonjs/utils/toggleScrollListener.js.map +1 -1
  105. package/lib-commonjs/utils/useCallbackRef.js +39 -53
  106. package/lib-commonjs/utils/useCallbackRef.js.map +1 -1
  107. package/lib-commonjs/utils/writeArrowUpdates.js +19 -24
  108. package/lib-commonjs/utils/writeArrowUpdates.js.map +1 -1
  109. package/lib-commonjs/utils/writeContainerupdates.js +37 -45
  110. package/lib-commonjs/utils/writeContainerupdates.js.map +1 -1
  111. package/package.json +6 -6
@@ -1,6 +1,9 @@
1
1
  "use strict";
2
-
3
2
  Object.defineProperty(exports, "__esModule", {
4
- value: true
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,"names":[],"sources":["../../../../../../../packages/react-components/react-positioning/src/types.ts"],"sourcesContent":["import * as React from 'react';\n\ntype Rect = {\n width: number;\n height: number;\n x: number;\n y: number;\n};\n\nexport type OffsetFunctionParam = {\n positionedRect: Rect;\n targetRect: Rect;\n position: Position;\n alignment?: Alignment;\n};\n\nexport type TargetElement = HTMLElement | PositioningVirtualElement;\n\n/**\n * @internal\n */\nexport interface UsePositioningOptions extends PositioningProps {\n /**\n * If false, does not position anything\n */\n enabled?: boolean;\n}\n\n/**\n * @internal\n */\nexport interface PositionManager {\n updatePosition: () => void;\n dispose: () => void;\n}\n\nexport interface UsePositioningReturn {\n // React refs are supposed to be contravariant\n // (allows a more general type to be passed rather than a more specific one)\n // However, Typescript currently can't infer that fact for refs\n // See https://github.com/microsoft/TypeScript/issues/30748 for more information\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n targetRef: React.MutableRefObject<any>;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n containerRef: React.MutableRefObject<any>;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n arrowRef: React.MutableRefObject<any>;\n}\n\nexport type OffsetObject = { crossAxis?: number; mainAxis: number };\n\nexport type OffsetShorthand = number;\n\nexport type OffsetFunction = (param: OffsetFunctionParam) => OffsetObject | OffsetShorthand;\n\nexport type Offset = OffsetFunction | OffsetObject | OffsetShorthand;\n\nexport type Position = 'above' | 'below' | 'before' | 'after';\nexport type Alignment = 'top' | 'bottom' | 'start' | 'end' | 'center';\n\nexport type AutoSize = 'height' | 'height-always' | 'width' | 'width-always' | 'always' | boolean;\n\nexport type Boundary = HTMLElement | Array<HTMLElement> | 'clippingParents' | 'scrollParent' | 'window';\n\nexport type PositioningImperativeRef = {\n /**\n * Updates the position imperatively.\n * Useful when the position of the target changes from other factors than scrolling of window resize.\n */\n updatePosition: () => void;\n\n /**\n * Sets the target and updates positioning imperatively.\n * Useful for avoiding double renders with the target option.\n */\n setTarget: (target: TargetElement) => void;\n};\n\nexport type PositioningVirtualElement = {\n getBoundingClientRect: () => {\n x: number;\n y: number;\n top: number;\n left: number;\n bottom: number;\n right: number;\n width: number;\n height: number;\n };\n contextElement?: Element;\n};\n\nexport type SetVirtualMouseTarget = (event: React.MouseEvent | MouseEvent | undefined | null) => void;\n\nexport interface PositioningOptions {\n /** Alignment for the component. Only has an effect if used with the @see position option */\n align?: Alignment;\n\n /** The element which will define the boundaries of the positioned element for the flip behavior. */\n flipBoundary?: Boundary | null;\n\n /** The element which will define the boundaries of the positioned element for the overflow behavior. */\n overflowBoundary?: Boundary | null;\n\n /**\n * Applies a padding to the overflow bounadry, so that overflow is detected earlier before the\n * positioned surface hits the overflow boundary.\n */\n overflowBoundaryPadding?: number | Partial<{ top: number; end: number; bottom: number; start: number }>;\n\n /**\n * Position for the component. Position has higher priority than align. If position is vertical ('above' | 'below')\n * and align is also vertical ('top' | 'bottom') or if both position and align are horizontal ('before' | 'after'\n * and 'start' | 'end' respectively),\n * then provided value for 'align' will be ignored and 'center' will be used instead.\n */\n position?: Position;\n\n /**\n * Enables the position element to be positioned with 'fixed' (default value is position: 'absolute')\n * @default false\n */\n positionFixed?: boolean;\n\n /**\n * Lets you displace a positioned element from its reference element.\n * This can be useful if you need to apply some margin between them or if you need to fine tune the\n * position according to some custom logic.\n */\n offset?: Offset;\n\n /**\n * Defines padding between the corner of the popup element and the arrow.\n * Use to prevent the arrow from overlapping a rounded corner, for example.\n */\n arrowPadding?: number;\n\n /**\n * Applies max-height and max-width on the positioned element to fit it within the available space in viewport.\n * true enables this for both width and height when overflow happens.\n * 'always' applies `max-height`/`max-width` regardless of overflow.\n * 'height' applies `max-height` when overflow happens, and 'width' for `max-width`\n * `height-always` applies `max-height` regardless of overflow, and 'width-always' for always applying `max-width`\n */\n autoSize?: AutoSize;\n\n /**\n * Modifies position and alignment to cover the target\n */\n coverTarget?: boolean;\n\n /**\n * Disables automatic repositioning of the component; it will always be placed according to the values of `align` and\n * `position` props, regardless of the size of the component, the reference element or the viewport.\n */\n pinned?: boolean;\n\n /**\n * When the reference element or the viewport is outside viewport allows a positioned element to be fully in viewport.\n * \"all\" enables this behavior for all axis.\n */\n // eslint-disable-next-line @typescript-eslint/naming-convention\n unstable_disableTether?: boolean | 'all';\n\n /**\n * If flip fails to stop the positioned element from overflowing\n * its boundaries, use a specified fallback positions.\n */\n fallbackPositions?: PositioningShorthandValue[];\n}\n\nexport interface PositioningProps\n extends Pick<\n PositioningOptions,\n | 'align'\n | 'flipBoundary'\n | 'overflowBoundary'\n | 'overflowBoundaryPadding'\n | 'position'\n | 'offset'\n | 'arrowPadding'\n | 'autoSize'\n | 'coverTarget'\n | 'pinned'\n > {\n /** An imperative handle to Popper methods. */\n positioningRef?: React.Ref<PositioningImperativeRef>;\n\n /**\n * Manual override for the target element. Useful for scenarios where a component accepts user prop to override target\n */\n target?: TargetElement | null;\n}\n\nexport type PositioningShorthandValue =\n | 'above'\n | 'above-start'\n | 'above-end'\n | 'below'\n | 'below-start'\n | 'below-end'\n | 'before'\n | 'before-top'\n | 'before-bottom'\n | 'after'\n | 'after-top'\n | 'after-bottom';\n\nexport type PositioningShorthand = PositioningProps | PositioningShorthandValue;\n"],"mappings":""}
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,210 @@
1
1
  "use strict";
2
-
3
2
  Object.defineProperty(exports, "__esModule", {
4
- value: true
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "usePositioning", {
6
+ enumerable: true,
7
+ get: ()=>usePositioning
5
8
  });
6
- exports.usePositioning = void 0;
7
- const dom_1 = /*#__PURE__*/require("@floating-ui/dom");
8
- const react_shared_contexts_1 = /*#__PURE__*/require("@fluentui/react-shared-contexts");
9
- const react_utilities_1 = /*#__PURE__*/require("@fluentui/react-utilities");
10
- const React = /*#__PURE__*/require("react");
11
- const utils_1 = /*#__PURE__*/require("./utils");
12
- const middleware_1 = /*#__PURE__*/require("./middleware");
13
- const createPositionManager_1 = /*#__PURE__*/require("./createPositionManager");
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
- 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 {
24
- enabled = true
25
- } = options;
26
- const resolvePositioningOptions = usePositioningOptions(options);
27
- const updatePositionManager = React.useCallback(() => {
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
- // We run this check once, no need to add deps here
89
- // TODO: Should be rework to handle options.enabled and contentRef updates
90
- // eslint-disable-next-line react-hooks/exhaustive-deps
91
- }, []);
92
- }
93
- const setTarget = utils_1.useCallbackRef(null, target => {
94
- if (targetRef.current !== target) {
95
- targetRef.current = target;
96
- updatePositionManager();
97
- }
98
- });
99
- const setContainer = utils_1.useCallbackRef(null, container => {
100
- if (containerRef.current !== container) {
101
- containerRef.current = container;
102
- updatePositionManager();
103
- }
104
- });
105
- const setArrow = utils_1.useCallbackRef(null, arrow => {
106
- if (arrowRef.current !== arrow) {
107
- arrowRef.current = arrow;
108
- updatePositionManager();
29
+ managerRef.current = null;
30
+ var _overrideTargetRef_current;
31
+ const target = (_overrideTargetRef_current = overrideTargetRef.current) !== null && _overrideTargetRef_current !== void 0 ? _overrideTargetRef_current : targetRef.current;
32
+ if (enabled && (0, _reactUtilities.canUseDOM)() && target && containerRef.current) {
33
+ managerRef.current = (0, _createPositionManager.createPositionManager)({
34
+ container: containerRef.current,
35
+ target,
36
+ arrow: arrowRef.current,
37
+ ...resolvePositioningOptions(containerRef.current, arrowRef.current)
38
+ });
39
+ }
40
+ }, [
41
+ enabled,
42
+ resolvePositioningOptions
43
+ ]);
44
+ const setOverrideTarget = (0, _reactUtilities.useEventCallback)((target)=>{
45
+ overrideTargetRef.current = target;
46
+ updatePositionManager();
47
+ });
48
+ _react.useImperativeHandle(options.positioningRef, ()=>{
49
+ return {
50
+ updatePosition: ()=>{
51
+ var _managerRef_current;
52
+ return (_managerRef_current = managerRef.current) === null || _managerRef_current === void 0 ? void 0 : _managerRef_current.updatePosition();
53
+ },
54
+ setTarget: (target)=>{
55
+ if (options.target && process.env.NODE_ENV !== 'production') {
56
+ const err = new Error();
57
+ // eslint-disable-next-line no-console
58
+ console.warn('Imperative setTarget should not be used at the same time as target option');
59
+ // eslint-disable-next-line no-console
60
+ console.warn(err.stack);
61
+ }
62
+ setOverrideTarget(target);
63
+ }
64
+ };
65
+ }, [
66
+ options.target,
67
+ setOverrideTarget
68
+ ]);
69
+ (0, _reactUtilities.useIsomorphicLayoutEffect)(()=>{
70
+ var _options_target;
71
+ setOverrideTarget((_options_target = options.target) !== null && _options_target !== void 0 ? _options_target : null);
72
+ }, [
73
+ options.target,
74
+ setOverrideTarget
75
+ ]);
76
+ (0, _reactUtilities.useIsomorphicLayoutEffect)(()=>{
77
+ updatePositionManager();
78
+ }, [
79
+ updatePositionManager
80
+ ]);
81
+ if (process.env.NODE_ENV !== 'production') {
82
+ // This checked should run only in development mode
83
+ // eslint-disable-next-line react-hooks/rules-of-hooks
84
+ _react.useEffect(()=>{
85
+ if (containerRef.current) {
86
+ var _contentNode_ownerDocument;
87
+ const contentNode = containerRef.current;
88
+ const treeWalker = (_contentNode_ownerDocument = contentNode.ownerDocument) === null || _contentNode_ownerDocument === void 0 ? void 0 : _contentNode_ownerDocument.createTreeWalker(contentNode, NodeFilter.SHOW_ELEMENT, {
89
+ acceptNode: _utils.hasAutofocusFilter
90
+ });
91
+ while(treeWalker.nextNode()){
92
+ const node = treeWalker.currentNode;
93
+ // eslint-disable-next-line no-console
94
+ console.warn('<Popper>:', node);
95
+ // eslint-disable-next-line no-console
96
+ console.warn([
97
+ '<Popper>: ^ this node contains "autoFocus" prop on a React element. This can break the initial',
98
+ 'positioning of an element and cause a window jump effect. This issue occurs because React polyfills',
99
+ '"autoFocus" behavior to solve inconsistencies between different browsers:',
100
+ 'https://github.com/facebook/react/issues/11851#issuecomment-351787078',
101
+ '\n',
102
+ 'However, ".focus()" in this case occurs before any other React effects will be executed',
103
+ '(React.useEffect(), componentDidMount(), etc.) and we can not prevent this behavior. If you really',
104
+ 'want to use "autoFocus" please add "position: fixed" to styles of the element that is wrapped by',
105
+ '"Popper".',
106
+ `In general, it's not recommended to use "autoFocus" as it may break accessibility aspects:`,
107
+ 'https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/master/docs/rules/no-autofocus.md',
108
+ '\n',
109
+ 'We suggest to use the "trapFocus" prop on Fluent components or a catch "ref" and then use',
110
+ '"ref.current.focus" in React.useEffect():',
111
+ 'https://reactjs.org/docs/refs-and-the-dom.html#adding-a-ref-to-a-dom-element'
112
+ ].join(' '));
113
+ }
114
+ }
115
+ // We run this check once, no need to add deps here
116
+ // TODO: Should be rework to handle options.enabled and contentRef updates
117
+ // eslint-disable-next-line react-hooks/exhaustive-deps
118
+ }, []);
109
119
  }
110
- });
111
- // Let users use callback refs so they feel like 'normal' DOM refs
112
- return {
113
- targetRef: setTarget,
114
- containerRef: setContainer,
115
- arrowRef: setArrow
116
- };
117
- }
118
- exports.usePositioning = usePositioning;
119
- function usePositioningOptions(options) {
120
- const {
121
- align,
122
- arrowPadding,
123
- autoSize,
124
- coverTarget,
125
- flipBoundary,
126
- offset,
127
- overflowBoundary,
128
- pinned,
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);
120
+ const setTarget = (0, _utils.useCallbackRef)(null, (target)=>{
121
+ if (targetRef.current !== target) {
122
+ targetRef.current = target;
123
+ updatePositionManager();
124
+ }
125
+ });
126
+ const setContainer = (0, _utils.useCallbackRef)(null, (container)=>{
127
+ if (containerRef.current !== container) {
128
+ containerRef.current = container;
129
+ updatePositionManager();
130
+ }
131
+ });
132
+ const setArrow = (0, _utils.useCallbackRef)(null, (arrow)=>{
133
+ if (arrowRef.current !== arrow) {
134
+ arrowRef.current = arrow;
135
+ updatePositionManager();
136
+ }
137
+ });
138
+ // Let users use callback refs so they feel like 'normal' DOM refs
167
139
  return {
168
- placement,
169
- middleware,
170
- strategy
140
+ targetRef: setTarget,
141
+ containerRef: setContainer,
142
+ arrowRef: setArrow
171
143
  };
172
- }, [align, arrowPadding, autoSize, coverTarget, disableTether, flipBoundary, isRtl, offset, overflowBoundary, pinned, position, strategy, overflowBoundaryPadding, fallbackPositions]);
173
144
  }
145
+ function usePositioningOptions(options) {
146
+ const { align , arrowPadding , autoSize , coverTarget , flipBoundary , offset , overflowBoundary , pinned , position , unstable_disableTether: disableTether , positionFixed , overflowBoundaryPadding , fallbackPositions } = options;
147
+ const { dir } = (0, _reactSharedContexts.useFluent_unstable)();
148
+ const isRtl = dir === 'rtl';
149
+ const strategy = positionFixed ? 'fixed' : 'absolute';
150
+ return _react.useCallback((container, arrow)=>{
151
+ const hasScrollableElement = (0, _utils.hasScrollParent)(container);
152
+ const middleware = [
153
+ offset && (0, _middleware.offset)(offset),
154
+ coverTarget && (0, _middleware.coverTarget)(),
155
+ !pinned && (0, _middleware.flip)({
156
+ container,
157
+ flipBoundary,
158
+ hasScrollableElement,
159
+ isRtl,
160
+ fallbackPositions
161
+ }),
162
+ (0, _middleware.shift)({
163
+ container,
164
+ hasScrollableElement,
165
+ overflowBoundary,
166
+ disableTether,
167
+ overflowBoundaryPadding,
168
+ isRtl
169
+ }),
170
+ autoSize && (0, _middleware.maxSize)(autoSize, {
171
+ container,
172
+ overflowBoundary
173
+ }),
174
+ (0, _middleware.intersecting)(),
175
+ arrow && (0, _dom.arrow)({
176
+ element: arrow,
177
+ padding: arrowPadding
178
+ }),
179
+ (0, _dom.hide)({
180
+ strategy: 'referenceHidden'
181
+ }),
182
+ (0, _dom.hide)({
183
+ strategy: 'escaped'
184
+ })
185
+ ].filter(Boolean);
186
+ const placement = (0, _utils.toFloatingUIPlacement)(align, position, isRtl);
187
+ return {
188
+ placement,
189
+ middleware,
190
+ strategy
191
+ };
192
+ }, [
193
+ align,
194
+ arrowPadding,
195
+ autoSize,
196
+ coverTarget,
197
+ disableTether,
198
+ flipBoundary,
199
+ isRtl,
200
+ offset,
201
+ overflowBoundary,
202
+ pinned,
203
+ position,
204
+ strategy,
205
+ overflowBoundaryPadding,
206
+ fallbackPositions
207
+ ]);
208
+ } //# sourceMappingURL=usePositioning.js.map
209
+
174
210
  //# 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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gBAAgB;MAChBI,aAAa;MACbE,uBAAuB;MACvBI;KACD,CAAC,EACFd,QAAQ,IAAIzD,YAAA,CAAA8E,OAAiB,CAACrB,QAAQ,EAAE;MAAEpC,SAAS;MAAEwC;IAAgB,CAAE,CAAC,EACxE7D,YAAA,CAAA+E,YAAsB,EAAE,EACxBzD,KAAK,IAAI5B,KAAA,CAAA4B,KAAe,CAAC;MAAE0D,OAAO,EAAE1D,KAAK;MAAE2D,OAAO,EAAEzB;IAAY,CAAE,CAAC,EACnE9D,KAAA,CAAAwF,IAAc,CAAC;MAAEV,QAAQ,EAAE;IAAiB,CAAE,CAAC,EAC/C9E,KAAA,CAAAwF,IAAc,CAAC;MAAEV,QAAQ,EAAE;IAAS,CAAE,CAAC,CACxC,CAACW,MAAM,CAACC,OAAO,CAAiB;IAEjC,MAAMC,SAAS,GAAGtF,OAAA,CAAAuF,qBAAqB,CAAC/B,KAAK,EAAEQ,QAAQ,EAAEQ,KAAK,CAAC;IAE/D,OAAO;MACLc,SAAS;MACTV,UAAU;MACVH;KACD;EACH,CAAC,EACD,CACEjB,KAAK,EACLC,YAAY,EACZC,QAAQ,EACRC,WAAW,EACXO,aAAa,EACbN,YAAY,EACZY,KAAK,EACLX,MAAM,EACNC,gBAAgB,EAChBC,MAAM,EACNC,QAAQ,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 var _overrideTargetRef_current;\n const target = (_overrideTargetRef_current = overrideTargetRef.current) !== null && _overrideTargetRef_current !== void 0 ? _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 return {\n updatePosition: () => {\n var _managerRef_current;\n return (_managerRef_current = managerRef.current) === null || _managerRef_current === void 0 ? void 0 : _managerRef_current.updatePosition();\n },\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 };\n }, [options.target, setOverrideTarget]);\n useIsomorphicLayoutEffect(() => {\n var _options_target;\n setOverrideTarget((_options_target = options.target) !== null && _options_target !== void 0 ? _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 var _contentNode_ownerDocument;\n const contentNode = containerRef.current;\n const treeWalker = (_contentNode_ownerDocument = contentNode.ownerDocument) === null || _contentNode_ownerDocument === void 0 ? void 0 : _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","_overrideTargetRef_current","target","canUseDOM","createPositionManager","container","arrow","setOverrideTarget","useEventCallback","useImperativeHandle","positioningRef","updatePosition","_managerRef_current","setTarget","process","env","NODE_ENV","err","Error","console","warn","stack","useIsomorphicLayoutEffect","_options_target","useEffect","_contentNode_ownerDocument","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,IAAIE;QACJ,MAAMC,SAAS,AAACD,CAAAA,6BAA6BV,kBAAkBQ,OAAO,AAAD,MAAO,IAAI,IAAIE,+BAA+B,KAAK,IAAIA,6BAA6BX,UAAUS,OAAO;QAC1K,IAAIL,WAAWS,IAAAA,yBAAS,OAAMD,UAAUV,aAAaO,OAAO,EAAE;YAC5DZ,WAAWY,OAAO,GAAGK,IAAAA,4CAAqB,EAAC;gBACzCC,WAAWb,aAAaO,OAAO;gBAC/BG;gBACAI,OAAOb,SAASM,OAAO;gBACvB,GAAGJ,0BAA0BH,aAAa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
3
2
  Object.defineProperty(exports, "__esModule", {
4
- value: true
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "usePositioningMouseTarget", {
6
+ enumerable: true,
7
+ get: ()=>usePositioningMouseTarget
5
8
  });
6
- exports.usePositioningMouseTarget = void 0;
7
- const React = /*#__PURE__*/require("react");
8
- const createVirtualElementFromClick_1 = /*#__PURE__*/require("./createVirtualElementFromClick");
9
- /**
10
- * @internal
11
- * A state hook that manages a popper virtual element from mouseevents.
12
- * Useful for scenarios where a component needs to be positioned by mouse click (e.g. contextmenu)
13
- * React synthetic events are not persisted by this hook
14
- *
15
- * @param initialState - initializes a user provided state similare to useState
16
- * @returns state and dispatcher for a Popper virtual element that uses native/synthetic mouse events
17
- */
18
- const usePositioningMouseTarget = initialState => {
19
- const [virtualElement, setVirtualElement] = React.useState(initialState);
20
- const setVirtualMouseTarget = event => {
21
- if (event === undefined || event === null) {
22
- setVirtualElement(undefined);
23
- return;
24
- }
25
- let mouseevent;
26
- if (!(event instanceof MouseEvent)) {
27
- mouseevent = event.nativeEvent;
28
- } else {
29
- mouseevent = event;
30
- }
31
- if (!(mouseevent instanceof MouseEvent) && process.env.NODE_ENV !== 'production') {
32
- // eslint-disable-next-line no-console
33
- console.error('usePositioningMouseTarget should only be used with MouseEvent');
34
- }
35
- const contextTarget = createVirtualElementFromClick_1.createVirtualElementFromClick(mouseevent);
36
- setVirtualElement(contextTarget);
37
- };
38
- return [virtualElement, setVirtualMouseTarget];
39
- };
40
- exports.usePositioningMouseTarget = usePositioningMouseTarget;
9
+ const _interopRequireWildcard = require("@swc/helpers/lib/_interop_require_wildcard.js").default;
10
+ const _react = /*#__PURE__*/ _interopRequireWildcard(require("react"));
11
+ const _createVirtualElementFromClick = require("./createVirtualElementFromClick");
12
+ const usePositioningMouseTarget = (initialState)=>{
13
+ const [virtualElement, setVirtualElement] = _react.useState(initialState);
14
+ const setVirtualMouseTarget = (event)=>{
15
+ if (event === undefined || event === null) {
16
+ setVirtualElement(undefined);
17
+ return;
18
+ }
19
+ let mouseevent;
20
+ if (!(event instanceof MouseEvent)) {
21
+ mouseevent = event.nativeEvent;
22
+ } else {
23
+ mouseevent = event;
24
+ }
25
+ if (!(mouseevent instanceof MouseEvent) && process.env.NODE_ENV !== 'production') {
26
+ // eslint-disable-next-line no-console
27
+ console.error('usePositioningMouseTarget should only be used with MouseEvent');
28
+ }
29
+ const contextTarget = (0, _createVirtualElementFromClick.createVirtualElementFromClick)(mouseevent);
30
+ setVirtualElement(contextTarget);
31
+ };
32
+ return [
33
+ virtualElement,
34
+ setVirtualMouseTarget
35
+ ];
36
+ }; //# sourceMappingURL=usePositioningMouseTarget.js.map
37
+
41
38
  //# sourceMappingURL=usePositioningMouseTarget.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["React","require","createVirtualElementFromClick_1","usePositioningMouseTarget","initialState","virtualElement","setVirtualElement","useState","setVirtualMouseTarget","event","undefined","mouseevent","MouseEvent","nativeEvent","process","env","NODE_ENV","console","error","contextTarget","createVirtualElementFromClick","exports"],"sources":["../../../../../../../packages/react-components/react-positioning/src/usePositioningMouseTarget.ts"],"sourcesContent":["import * as React from 'react';\nimport { createVirtualElementFromClick } from './createVirtualElementFromClick';\nimport { PositioningVirtualElement, SetVirtualMouseTarget } from './types';\n\n/**\n * @internal\n * A state hook that manages a popper virtual element from mouseevents.\n * Useful for scenarios where a component needs to be positioned by mouse click (e.g. contextmenu)\n * React synthetic events are not persisted by this hook\n *\n * @param initialState - initializes a user provided state similare to useState\n * @returns state and dispatcher for a Popper virtual element that uses native/synthetic mouse events\n */\nexport const usePositioningMouseTarget = (\n initialState?: PositioningVirtualElement | (() => PositioningVirtualElement),\n) => {\n const [virtualElement, setVirtualElement] = React.useState<PositioningVirtualElement | undefined>(initialState);\n\n const setVirtualMouseTarget: SetVirtualMouseTarget = event => {\n if (event === undefined || event === null) {\n setVirtualElement(undefined);\n return;\n }\n\n let mouseevent: MouseEvent;\n if (!(event instanceof MouseEvent)) {\n mouseevent = event.nativeEvent;\n } else {\n mouseevent = event;\n }\n\n if (!(mouseevent instanceof MouseEvent) && process.env.NODE_ENV !== 'production') {\n // eslint-disable-next-line no-console\n console.error('usePositioningMouseTarget should only be used with MouseEvent');\n }\n\n const contextTarget = createVirtualElementFromClick(mouseevent);\n setVirtualElement(contextTarget);\n };\n\n return [virtualElement, setVirtualMouseTarget] as const;\n};\n"],"mappings":";;;;;;AAAA,MAAAA,KAAA,gBAAAC,OAAA;AACA,MAAAC,+BAAA,gBAAAD,OAAA;AAGA;;;;;;;;;AASO,MAAME,yBAAyB,GACpCC,YAA4E,IAC1E;EACF,MAAM,CAACC,cAAc,EAAEC,iBAAiB,CAAC,GAAGN,KAAK,CAACO,QAAQ,CAAwCH,YAAY,CAAC;EAE/G,MAAMI,qBAAqB,GAA0BC,KAAK,IAAG;IAC3D,IAAIA,KAAK,KAAKC,SAAS,IAAID,KAAK,KAAK,IAAI,EAAE;MACzCH,iBAAiB,CAACI,SAAS,CAAC;MAC5B;;IAGF,IAAIC,UAAsB;IAC1B,IAAI,EAAEF,KAAK,YAAYG,UAAU,CAAC,EAAE;MAClCD,UAAU,GAAGF,KAAK,CAACI,WAAW;KAC/B,MAAM;MACLF,UAAU,GAAGF,KAAK;;IAGpB,IAAI,EAAEE,UAAU,YAAYC,UAAU,CAAC,IAAIE,OAAO,CAACC,GAAG,CAACC,QAAQ,KAAK,YAAY,EAAE;MAChF;MACAC,OAAO,CAACC,KAAK,CAAC,+DAA+D,CAAC;;IAGhF,MAAMC,aAAa,GAAGjB,+BAAA,CAAAkB,6BAA6B,CAACT,UAAU,CAAC;IAC/DL,iBAAiB,CAACa,aAAa,CAAC;EAClC,CAAC;EAED,OAAO,CAACd,cAAc,EAAEG,qBAAqB,CAAU;AACzD,CAAC;AA5BYa,OAAA,CAAAlB,yBAAyB,GAAAA,yBAAA"}
1
+ {"version":3,"sources":["../lib/usePositioningMouseTarget.js"],"sourcesContent":["import * as React from 'react';\nimport { createVirtualElementFromClick } from './createVirtualElementFromClick';\n/**\n * @internal\n * A state hook that manages a popper virtual element from mouseevents.\n * Useful for scenarios where a component needs to be positioned by mouse click (e.g. contextmenu)\n * React synthetic events are not persisted by this hook\n *\n * @param initialState - initializes a user provided state similare to useState\n * @returns state and dispatcher for a Popper virtual element that uses native/synthetic mouse events\n */\nexport const usePositioningMouseTarget = initialState => {\n const [virtualElement, setVirtualElement] = React.useState(initialState);\n const setVirtualMouseTarget = event => {\n if (event === undefined || event === null) {\n setVirtualElement(undefined);\n return;\n }\n let mouseevent;\n if (!(event instanceof MouseEvent)) {\n mouseevent = event.nativeEvent;\n } else {\n mouseevent = event;\n }\n if (!(mouseevent instanceof MouseEvent) && process.env.NODE_ENV !== 'production') {\n // eslint-disable-next-line no-console\n console.error('usePositioningMouseTarget should only be used with MouseEvent');\n }\n const contextTarget = createVirtualElementFromClick(mouseevent);\n setVirtualElement(contextTarget);\n };\n return [virtualElement, setVirtualMouseTarget];\n};\n//# sourceMappingURL=usePositioningMouseTarget.js.map"],"names":["usePositioningMouseTarget","initialState","virtualElement","setVirtualElement","React","useState","setVirtualMouseTarget","event","undefined","mouseevent","MouseEvent","nativeEvent","process","env","NODE_ENV","console","error","contextTarget","createVirtualElementFromClick"],"mappings":";;;;+BAWaA;;aAAAA;;;6DAXU;+CACuB;AAUvC,MAAMA,4BAA4BC,CAAAA,eAAgB;IACvD,MAAM,CAACC,gBAAgBC,kBAAkB,GAAGC,OAAMC,QAAQ,CAACJ;IAC3D,MAAMK,wBAAwBC,CAAAA,QAAS;QACrC,IAAIA,UAAUC,aAAaD,UAAU,IAAI,EAAE;YACzCJ,kBAAkBK;YAClB;QACF,CAAC;QACD,IAAIC;QACJ,IAAI,CAAEF,CAAAA,iBAAiBG,UAAS,GAAI;YAClCD,aAAaF,MAAMI,WAAW;QAChC,OAAO;YACLF,aAAaF;QACf,CAAC;QACD,IAAI,CAAEE,CAAAA,sBAAsBC,UAAS,KAAME,QAAQC,GAAG,CAACC,QAAQ,KAAK,cAAc;YAChF,sCAAsC;YACtCC,QAAQC,KAAK,CAAC;QAChB,CAAC;QACD,MAAMC,gBAAgBC,IAAAA,4DAA6B,EAACT;QACpDN,kBAAkBc;IACpB;IACA,OAAO;QAACf;QAAgBI;KAAsB;AAChD,GACA,qDAAqD"}
@@ -1,28 +1,29 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.debounce = void 0;
7
1
  /**
8
2
  * Promise microtask debouncer used by Popper.js v2
9
3
  * This is no longer exported in Floating UI (Popper.js v3)
10
4
  * https://github.com/floating-ui/floating-ui/blob/v2.x/src/utils/debounce.js
11
5
  * @param fn function that will be debounced
12
- */
6
+ */ "use strict";
7
+ Object.defineProperty(exports, "__esModule", {
8
+ value: true
9
+ });
10
+ Object.defineProperty(exports, "debounce", {
11
+ enumerable: true,
12
+ get: ()=>debounce
13
+ });
13
14
  function debounce(fn) {
14
- let pending;
15
- return () => {
16
- if (!pending) {
17
- pending = new Promise(resolve => {
18
- Promise.resolve().then(() => {
19
- pending = undefined;
20
- resolve(fn());
21
- });
22
- });
23
- }
24
- return pending;
25
- };
26
- }
27
- exports.debounce = debounce;
15
+ let pending;
16
+ return ()=>{
17
+ if (!pending) {
18
+ pending = new Promise((resolve)=>{
19
+ Promise.resolve().then(()=>{
20
+ pending = undefined;
21
+ resolve(fn());
22
+ });
23
+ });
24
+ }
25
+ return pending;
26
+ };
27
+ } //# sourceMappingURL=debounce.js.map
28
+
28
29
  //# sourceMappingURL=debounce.js.map