@fluentui/react-positioning 9.5.4 → 9.5.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (175) hide show
  1. package/.swcrc +30 -0
  2. package/CHANGELOG.json +55 -1
  3. package/CHANGELOG.md +24 -2
  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 +7 -6
  112. package/lib-amd/constants.js +0 -10
  113. package/lib-amd/constants.js.map +0 -1
  114. package/lib-amd/createArrowStyles.js +0 -62
  115. package/lib-amd/createArrowStyles.js.map +0 -1
  116. package/lib-amd/createPositionManager.js +0 -97
  117. package/lib-amd/createPositionManager.js.map +0 -1
  118. package/lib-amd/createVirtualElementFromClick.js +0 -32
  119. package/lib-amd/createVirtualElementFromClick.js.map +0 -1
  120. package/lib-amd/index.js +0 -13
  121. package/lib-amd/index.js.map +0 -1
  122. package/lib-amd/middleware/coverTarget.js +0 -32
  123. package/lib-amd/middleware/coverTarget.js.map +0 -1
  124. package/lib-amd/middleware/flip.js +0 -19
  125. package/lib-amd/middleware/flip.js.map +0 -1
  126. package/lib-amd/middleware/index.js +0 -11
  127. package/lib-amd/middleware/index.js.map +0 -1
  128. package/lib-amd/middleware/intersecting.js +0 -33
  129. package/lib-amd/middleware/intersecting.js.map +0 -1
  130. package/lib-amd/middleware/maxSize.js +0 -33
  131. package/lib-amd/middleware/maxSize.js.map +0 -1
  132. package/lib-amd/middleware/offset.js +0 -14
  133. package/lib-amd/middleware/offset.js.map +0 -1
  134. package/lib-amd/middleware/shift.js +0 -17
  135. package/lib-amd/middleware/shift.js.map +0 -1
  136. package/lib-amd/types.js +0 -5
  137. package/lib-amd/types.js.map +0 -1
  138. package/lib-amd/usePositioning.js +0 -161
  139. package/lib-amd/usePositioning.js.map +0 -1
  140. package/lib-amd/usePositioningMouseTarget.js +0 -39
  141. package/lib-amd/usePositioningMouseTarget.js.map +0 -1
  142. package/lib-amd/utils/debounce.js +0 -27
  143. package/lib-amd/utils/debounce.js.map +0 -1
  144. package/lib-amd/utils/fromFloatingUIPlacement.js +0 -37
  145. package/lib-amd/utils/fromFloatingUIPlacement.js.map +0 -1
  146. package/lib-amd/utils/getBoundary.js +0 -26
  147. package/lib-amd/utils/getBoundary.js.map +0 -1
  148. package/lib-amd/utils/getFloatingUIOffset.js +0 -25
  149. package/lib-amd/utils/getFloatingUIOffset.js.map +0 -1
  150. package/lib-amd/utils/getReactFiberFromNode.js +0 -48
  151. package/lib-amd/utils/getReactFiberFromNode.js.map +0 -1
  152. package/lib-amd/utils/getScrollParent.js +0 -64
  153. package/lib-amd/utils/getScrollParent.js.map +0 -1
  154. package/lib-amd/utils/hasAutoFocusFilter.js +0 -31
  155. package/lib-amd/utils/hasAutoFocusFilter.js.map +0 -1
  156. package/lib-amd/utils/index.js +0 -20
  157. package/lib-amd/utils/index.js.map +0 -1
  158. package/lib-amd/utils/mergeArrowOffset.js +0 -38
  159. package/lib-amd/utils/mergeArrowOffset.js.map +0 -1
  160. package/lib-amd/utils/parseFloatingUIPlacement.js +0 -20
  161. package/lib-amd/utils/parseFloatingUIPlacement.js.map +0 -1
  162. package/lib-amd/utils/resolvePositioningShorthand.js +0 -31
  163. package/lib-amd/utils/resolvePositioningShorthand.js.map +0 -1
  164. package/lib-amd/utils/toFloatingUIPadding.js +0 -25
  165. package/lib-amd/utils/toFloatingUIPadding.js.map +0 -1
  166. package/lib-amd/utils/toFloatingUIPlacement.js +0 -40
  167. package/lib-amd/utils/toFloatingUIPlacement.js.map +0 -1
  168. package/lib-amd/utils/toggleScrollListener.js +0 -26
  169. package/lib-amd/utils/toggleScrollListener.js.map +0 -1
  170. package/lib-amd/utils/useCallbackRef.js +0 -55
  171. package/lib-amd/utils/useCallbackRef.js.map +0 -1
  172. package/lib-amd/utils/writeArrowUpdates.js +0 -21
  173. package/lib-amd/utils/writeArrowUpdates.js.map +0 -1
  174. package/lib-amd/utils/writeContainerupdates.js +0 -41
  175. package/lib-amd/utils/writeContainerupdates.js.map +0 -1
@@ -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":["../src/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,GAAG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5B,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,aAAaO,OAAO,EAAEN,SAASM,OAAO,CAAC;YACtE;QACF,CAAC;IACH,GAAG;QAACL;QAASC;KAA0B;IACvC,MAAMY,oBAAoBC,IAAAA,gCAAgB,EAACN,CAAAA,SAAU;QACnDX,kBAAkBQ,OAAO,GAAGG;QAC5BL;IACF;IACAT,OAAMqB,mBAAmB,CAACvB,QA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E,IAAG,EACJ,GAAGC,IAAAA,uCAAS;IACb,MAAMC,QAAQF,QAAQ;IACtB,MAAMG,WAAWN,gBAAgB,UAAU,UAAU;IACrD,OAAOhE,OAAMU,WAAW,CAAC,CAACO,WAAWC,QAAU;QAC7C,MAAMqD,uBAAuBC,IAAAA,sBAAe,EAACvD;QAC7C,MAAMwD,aAAa;YAACf,UAAUgB,IAAAA,kBAAgB,EAAChB;YAASF,eAAemB,IAAAA,uBAAqB;YAAI,CAACf,UAAUgB,IAAAA,gBAAc,EAAC;gBACxH3D;gBACAwC;gBACAc;gBACAF;gBACAH;YACF;YAAIW,IAAAA,iBAAe,EAAC;gBAClB5D;gBACAsD;gBACAZ;gBACAI;gBACAE;gBACAI;YACF;YAAId,YAAYuB,IAAAA,mBAAiB,EAACvB,UAAU;gBAC1CtC;gBACA0C;YACF;YAAIoB,IAAAA,wBAAsB;YAAI7D,SAAS8D,IAAAA,UAAe,EAAC;gBACrDC,SAAS/D;gBACTgE,SAAS5B;YACX;YAAI6B,IAAAA,SAAc,EAAC;gBACjBb,UAAU;YACZ;YAAIa,IAAAA,SAAc,EAAC;gBACjBb,UAAU;YACZ;SAAG,CAACc,MAAM,CAACC;QACX,MAAMC,YAAYC,IAAAA,4BAAqB,EAAClC,OAAOQ,UAAUQ;QACzD,OAAO;YACLiB;YACAb;YACAH;QACF;IACF,GAAG;QAACjB;QAAOC;QAAcC;QAAUC;QAAaO;QAAeN;QAAcY;QAAOX;QAAQC;QAAkBC;QAAQC;QAAUS;QAAUL;QAAyBC;KAAkB;AACvL,EACA,0CAA0C"}
@@ -1,41 +1,38 @@
1
1
  "use strict";
2
-
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":["../src/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
@@ -1 +1 @@
1
- {"version":3,"names":["debounce","fn","pending","Promise","resolve","then","undefined","exports"],"sources":["../src/packages/react-components/react-positioning/src/utils/debounce.ts"],"sourcesContent":["/**\n * Promise microtask debouncer used by Popper.js v2\n * This is no longer exported in Floating UI (Popper.js v3)\n * https://github.com/floating-ui/floating-ui/blob/v2.x/src/utils/debounce.js\n * @param fn function that will be debounced\n */\nexport function debounce<T>(fn: Function): () => Promise<T> {\n let pending: Promise<T> | undefined;\n return () => {\n if (!pending) {\n pending = new Promise<T>(resolve => {\n Promise.resolve().then(() => {\n pending = undefined;\n resolve(fn());\n });\n });\n }\n\n return pending;\n };\n}\n"],"mappings":";;;;;;AAAA;;;;;;AAMA,SAAgBA,QAAQA,CAAIC,EAAY;EACtC,IAAIC,OAA+B;EACnC,OAAO,MAAK;IACV,IAAI,CAACA,OAAO,EAAE;MACZA,OAAO,GAAG,IAAIC,OAAO,CAAIC,OAAO,IAAG;QACjCD,OAAO,CAACC,OAAO,EAAE,CAACC,IAAI,CAAC,MAAK;UAC1BH,OAAO,GAAGI,SAAS;UACnBF,OAAO,CAACH,EAAE,EAAE,CAAC;QACf,CAAC,CAAC;MACJ,CAAC,CAAC;;IAGJ,OAAOC,OAAO;EAChB,CAAC;AACH;AAdAK,OAAA,CAAAP,QAAA,GAAAA,QAAA"}
1
+ {"version":3,"sources":["../../lib/utils/debounce.js"],"sourcesContent":["/**\n * Promise microtask debouncer used by Popper.js v2\n * This is no longer exported in Floating UI (Popper.js v3)\n * https://github.com/floating-ui/floating-ui/blob/v2.x/src/utils/debounce.js\n * @param fn function that will be debounced\n */export function debounce(fn) {\n let pending;\n return () => {\n if (!pending) {\n pending = new Promise(resolve => {\n Promise.resolve().then(() => {\n pending = undefined;\n resolve(fn());\n });\n });\n }\n return pending;\n };\n}\n//# sourceMappingURL=debounce.js.map"],"names":["debounce","fn","pending","Promise","resolve","then","undefined"],"mappings":"AAAA;;;;;CAKC;;;;+BAAkBA;;aAAAA;;AAAT,SAASA,SAASC,EAAE,EAAE;IAC9B,IAAIC;IACJ,OAAO,IAAM;QACX,IAAI,CAACA,SAAS;YACZA,UAAU,IAAIC,QAAQC,CAAAA,UAAW;gBAC/BD,QAAQC,OAAO,GAAGC,IAAI,CAAC,IAAM;oBAC3BH,UAAUI;oBACVF,QAAQH;gBACV;YACF;QACF,CAAC;QACD,OAAOC;IACT;AACF,EACA,oCAAoC"}