@fluentui/react-positioning 9.5.13 → 9.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (132) hide show
  1. package/CHANGELOG.json +45 -1
  2. package/CHANGELOG.md +25 -2
  3. package/dist/index.d.ts +6 -1
  4. package/lib/constants.js +0 -1
  5. package/lib/constants.js.map +1 -1
  6. package/lib/createArrowStyles.js +47 -55
  7. package/lib/createArrowStyles.js.map +1 -1
  8. package/lib/createPositionManager.js +95 -108
  9. package/lib/createPositionManager.js.map +1 -1
  10. package/lib/createVirtualElementFromClick.js +18 -19
  11. package/lib/createVirtualElementFromClick.js.map +1 -1
  12. package/lib/index.js +0 -1
  13. package/lib/index.js.map +1 -1
  14. package/lib/middleware/coverTarget.js +26 -32
  15. package/lib/middleware/coverTarget.js.map +1 -1
  16. package/lib/middleware/flip.js +22 -32
  17. package/lib/middleware/flip.js.map +1 -1
  18. package/lib/middleware/index.js +0 -1
  19. package/lib/middleware/index.js.map +1 -1
  20. package/lib/middleware/intersecting.js +16 -17
  21. package/lib/middleware/intersecting.js.map +1 -1
  22. package/lib/middleware/maxSize.js +25 -34
  23. package/lib/middleware/maxSize.js.map +1 -1
  24. package/lib/middleware/offset.js +3 -5
  25. package/lib/middleware/offset.js.map +1 -1
  26. package/lib/middleware/shift.js +21 -30
  27. package/lib/middleware/shift.js.map +1 -1
  28. package/lib/types.js +0 -1
  29. package/lib/types.js.map +1 -1
  30. package/lib/usePositioning.js +188 -154
  31. package/lib/usePositioning.js.map +1 -1
  32. package/lib/usePositioningMouseTarget.js +24 -23
  33. package/lib/usePositioningMouseTarget.js.map +1 -1
  34. package/lib/utils/debounce.js +13 -14
  35. package/lib/utils/debounce.js.map +1 -1
  36. package/lib/utils/fromFloatingUIPlacement.js +23 -28
  37. package/lib/utils/fromFloatingUIPlacement.js.map +1 -1
  38. package/lib/utils/getBoundary.js +14 -16
  39. package/lib/utils/getBoundary.js.map +1 -1
  40. package/lib/utils/getFloatingUIOffset.js +16 -27
  41. package/lib/utils/getFloatingUIOffset.js.map +1 -1
  42. package/lib/utils/getReactFiberFromNode.js +36 -37
  43. package/lib/utils/getReactFiberFromNode.js.map +1 -1
  44. package/lib/utils/getScrollParent.js +35 -42
  45. package/lib/utils/getScrollParent.js.map +1 -1
  46. package/lib/utils/hasAutoFocusFilter.js +9 -11
  47. package/lib/utils/hasAutoFocusFilter.js.map +1 -1
  48. package/lib/utils/index.js +0 -1
  49. package/lib/utils/index.js.map +1 -1
  50. package/lib/utils/mergeArrowOffset.js +24 -25
  51. package/lib/utils/mergeArrowOffset.js.map +1 -1
  52. package/lib/utils/parseFloatingUIPlacement.js +6 -7
  53. package/lib/utils/parseFloatingUIPlacement.js.map +1 -1
  54. package/lib/utils/resolvePositioningShorthand.js +55 -56
  55. package/lib/utils/resolvePositioningShorthand.js.map +1 -1
  56. package/lib/utils/toFloatingUIPadding.js +16 -21
  57. package/lib/utils/toFloatingUIPadding.js.map +1 -1
  58. package/lib/utils/toFloatingUIPlacement.js +25 -27
  59. package/lib/utils/toFloatingUIPlacement.js.map +1 -1
  60. package/lib/utils/toggleScrollListener.js +12 -14
  61. package/lib/utils/toggleScrollListener.js.map +1 -1
  62. package/lib/utils/useCallbackRef.js +30 -32
  63. package/lib/utils/useCallbackRef.js.map +1 -1
  64. package/lib/utils/writeArrowUpdates.js +10 -17
  65. package/lib/utils/writeArrowUpdates.js.map +1 -1
  66. package/lib/utils/writeContainerupdates.js +39 -39
  67. package/lib/utils/writeContainerupdates.js.map +1 -1
  68. package/lib-commonjs/constants.js +1 -3
  69. package/lib-commonjs/constants.js.map +1 -1
  70. package/lib-commonjs/createArrowStyles.js +1 -3
  71. package/lib-commonjs/createArrowStyles.js.map +1 -1
  72. package/lib-commonjs/createPositionManager.js +4 -5
  73. package/lib-commonjs/createPositionManager.js.map +1 -1
  74. package/lib-commonjs/createVirtualElementFromClick.js +1 -3
  75. package/lib-commonjs/createVirtualElementFromClick.js.map +1 -1
  76. package/lib-commonjs/index.js +0 -3
  77. package/lib-commonjs/index.js.map +1 -1
  78. package/lib-commonjs/middleware/coverTarget.js +1 -3
  79. package/lib-commonjs/middleware/coverTarget.js.map +1 -1
  80. package/lib-commonjs/middleware/flip.js +1 -3
  81. package/lib-commonjs/middleware/flip.js.map +1 -1
  82. package/lib-commonjs/middleware/index.js +0 -3
  83. package/lib-commonjs/middleware/index.js.map +1 -1
  84. package/lib-commonjs/middleware/intersecting.js +1 -3
  85. package/lib-commonjs/middleware/intersecting.js.map +1 -1
  86. package/lib-commonjs/middleware/maxSize.js +1 -3
  87. package/lib-commonjs/middleware/maxSize.js.map +1 -1
  88. package/lib-commonjs/middleware/offset.js +1 -3
  89. package/lib-commonjs/middleware/offset.js.map +1 -1
  90. package/lib-commonjs/middleware/shift.js +1 -3
  91. package/lib-commonjs/middleware/shift.js.map +1 -1
  92. package/lib-commonjs/types.js +0 -3
  93. package/lib-commonjs/types.js.map +1 -1
  94. package/lib-commonjs/usePositioning.js +6 -6
  95. package/lib-commonjs/usePositioning.js.map +1 -1
  96. package/lib-commonjs/usePositioningMouseTarget.js +1 -3
  97. package/lib-commonjs/usePositioningMouseTarget.js.map +1 -1
  98. package/lib-commonjs/utils/debounce.js +1 -3
  99. package/lib-commonjs/utils/debounce.js.map +1 -1
  100. package/lib-commonjs/utils/fromFloatingUIPlacement.js +1 -3
  101. package/lib-commonjs/utils/fromFloatingUIPlacement.js.map +1 -1
  102. package/lib-commonjs/utils/getBoundary.js +1 -3
  103. package/lib-commonjs/utils/getBoundary.js.map +1 -1
  104. package/lib-commonjs/utils/getFloatingUIOffset.js +1 -3
  105. package/lib-commonjs/utils/getFloatingUIOffset.js.map +1 -1
  106. package/lib-commonjs/utils/getReactFiberFromNode.js +1 -3
  107. package/lib-commonjs/utils/getReactFiberFromNode.js.map +1 -1
  108. package/lib-commonjs/utils/getScrollParent.js +1 -3
  109. package/lib-commonjs/utils/getScrollParent.js.map +1 -1
  110. package/lib-commonjs/utils/hasAutoFocusFilter.js +1 -3
  111. package/lib-commonjs/utils/hasAutoFocusFilter.js.map +1 -1
  112. package/lib-commonjs/utils/index.js +0 -3
  113. package/lib-commonjs/utils/index.js.map +1 -1
  114. package/lib-commonjs/utils/mergeArrowOffset.js +1 -3
  115. package/lib-commonjs/utils/mergeArrowOffset.js.map +1 -1
  116. package/lib-commonjs/utils/parseFloatingUIPlacement.js +1 -3
  117. package/lib-commonjs/utils/parseFloatingUIPlacement.js.map +1 -1
  118. package/lib-commonjs/utils/resolvePositioningShorthand.js +1 -3
  119. package/lib-commonjs/utils/resolvePositioningShorthand.js.map +1 -1
  120. package/lib-commonjs/utils/toFloatingUIPadding.js +1 -3
  121. package/lib-commonjs/utils/toFloatingUIPadding.js.map +1 -1
  122. package/lib-commonjs/utils/toFloatingUIPlacement.js +1 -3
  123. package/lib-commonjs/utils/toFloatingUIPlacement.js.map +1 -1
  124. package/lib-commonjs/utils/toggleScrollListener.js +1 -3
  125. package/lib-commonjs/utils/toggleScrollListener.js.map +1 -1
  126. package/lib-commonjs/utils/useCallbackRef.js +1 -3
  127. package/lib-commonjs/utils/useCallbackRef.js.map +1 -1
  128. package/lib-commonjs/utils/writeArrowUpdates.js +1 -3
  129. package/lib-commonjs/utils/writeArrowUpdates.js.map +1 -1
  130. package/lib-commonjs/utils/writeContainerupdates.js +12 -5
  131. package/lib-commonjs/utils/writeContainerupdates.js.map +1 -1
  132. package/package.json +3 -3
@@ -7,163 +7,197 @@ import { shift as shiftMiddleware, flip as flipMiddleware, coverTarget as coverT
7
7
  import { createPositionManager } from './createPositionManager';
8
8
  /**
9
9
  * @internal
10
- */
11
- export function usePositioning(options) {
12
- const managerRef = React.useRef(null);
13
- const targetRef = React.useRef(null);
14
- const overrideTargetRef = React.useRef(null);
15
- const containerRef = React.useRef(null);
16
- const arrowRef = React.useRef(null);
17
- const {
18
- enabled = true
19
- } = options;
20
- const resolvePositioningOptions = usePositioningOptions(options);
21
- const updatePositionManager = React.useCallback(() => {
22
- if (managerRef.current) {
23
- managerRef.current.dispose();
24
- }
25
- managerRef.current = null;
26
- var _overrideTargetRef_current;
27
- const target = (_overrideTargetRef_current = overrideTargetRef.current) !== null && _overrideTargetRef_current !== void 0 ? _overrideTargetRef_current : targetRef.current;
28
- if (enabled && canUseDOM() && target && containerRef.current) {
29
- managerRef.current = createPositionManager({
30
- container: containerRef.current,
31
- target,
32
- arrow: arrowRef.current,
33
- ...resolvePositioningOptions(containerRef.current, arrowRef.current)
34
- });
35
- }
36
- }, [enabled, resolvePositioningOptions]);
37
- const setOverrideTarget = useEventCallback(target => {
38
- overrideTargetRef.current = target;
39
- updatePositionManager();
40
- });
41
- React.useImperativeHandle(options.positioningRef, () => {
42
- return {
43
- updatePosition: () => {
44
- var _managerRef_current;
45
- return (_managerRef_current = managerRef.current) === null || _managerRef_current === void 0 ? void 0 : _managerRef_current.updatePosition();
46
- },
47
- setTarget: target => {
48
- if (options.target && process.env.NODE_ENV !== 'production') {
49
- const err = new Error();
50
- // eslint-disable-next-line no-console
51
- console.warn('Imperative setTarget should not be used at the same time as target option');
52
- // eslint-disable-next-line no-console
53
- console.warn(err.stack);
10
+ */ export function usePositioning(options) {
11
+ const managerRef = React.useRef(null);
12
+ const targetRef = React.useRef(null);
13
+ const overrideTargetRef = React.useRef(null);
14
+ const containerRef = React.useRef(null);
15
+ const arrowRef = React.useRef(null);
16
+ const { enabled =true } = options;
17
+ const resolvePositioningOptions = usePositioningOptions(options);
18
+ const updatePositionManager = React.useCallback(()=>{
19
+ if (managerRef.current) {
20
+ managerRef.current.dispose();
54
21
  }
55
- setOverrideTarget(target);
56
- }
57
- };
58
- }, [options.target, setOverrideTarget]);
59
- useIsomorphicLayoutEffect(() => {
60
- var _options_target;
61
- setOverrideTarget((_options_target = options.target) !== null && _options_target !== void 0 ? _options_target : null);
62
- }, [options.target, setOverrideTarget]);
63
- useIsomorphicLayoutEffect(() => {
64
- updatePositionManager();
65
- }, [updatePositionManager]);
66
- if (process.env.NODE_ENV !== 'production') {
67
- // This checked should run only in development mode
68
- // eslint-disable-next-line react-hooks/rules-of-hooks
69
- React.useEffect(() => {
70
- if (containerRef.current) {
71
- var _contentNode_ownerDocument;
72
- const contentNode = containerRef.current;
73
- const treeWalker = (_contentNode_ownerDocument = contentNode.ownerDocument) === null || _contentNode_ownerDocument === void 0 ? void 0 : _contentNode_ownerDocument.createTreeWalker(contentNode, NodeFilter.SHOW_ELEMENT, {
74
- acceptNode: hasAutofocusFilter
75
- });
76
- while (treeWalker.nextNode()) {
77
- const node = treeWalker.currentNode;
78
- // eslint-disable-next-line no-console
79
- console.warn('<Popper>:', node);
80
- // eslint-disable-next-line no-console
81
- 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(' '));
22
+ managerRef.current = null;
23
+ var _overrideTargetRef_current;
24
+ const target = (_overrideTargetRef_current = overrideTargetRef.current) !== null && _overrideTargetRef_current !== void 0 ? _overrideTargetRef_current : targetRef.current;
25
+ if (enabled && canUseDOM() && target && containerRef.current) {
26
+ managerRef.current = createPositionManager({
27
+ container: containerRef.current,
28
+ target,
29
+ arrow: arrowRef.current,
30
+ ...resolvePositioningOptions(containerRef.current, arrowRef.current)
31
+ });
82
32
  }
83
- }
84
- // We run this check once, no need to add deps here
85
- // TODO: Should be rework to handle options.enabled and contentRef updates
86
- // eslint-disable-next-line react-hooks/exhaustive-deps
87
- }, []);
88
- }
89
- const setTarget = useCallbackRef(null, target => {
90
- if (targetRef.current !== target) {
91
- targetRef.current = target;
92
- updatePositionManager();
33
+ }, [
34
+ enabled,
35
+ resolvePositioningOptions
36
+ ]);
37
+ const setOverrideTarget = useEventCallback((target)=>{
38
+ overrideTargetRef.current = target;
39
+ updatePositionManager();
40
+ });
41
+ React.useImperativeHandle(options.positioningRef, ()=>{
42
+ return {
43
+ updatePosition: ()=>{
44
+ var _managerRef_current;
45
+ return (_managerRef_current = managerRef.current) === null || _managerRef_current === void 0 ? void 0 : _managerRef_current.updatePosition();
46
+ },
47
+ setTarget: (target)=>{
48
+ if (options.target && process.env.NODE_ENV !== 'production') {
49
+ const err = new Error();
50
+ // eslint-disable-next-line no-console
51
+ console.warn('Imperative setTarget should not be used at the same time as target option');
52
+ // eslint-disable-next-line no-console
53
+ console.warn(err.stack);
54
+ }
55
+ setOverrideTarget(target);
56
+ }
57
+ };
58
+ }, [
59
+ options.target,
60
+ setOverrideTarget
61
+ ]);
62
+ useIsomorphicLayoutEffect(()=>{
63
+ var _options_target;
64
+ setOverrideTarget((_options_target = options.target) !== null && _options_target !== void 0 ? _options_target : null);
65
+ }, [
66
+ options.target,
67
+ setOverrideTarget
68
+ ]);
69
+ useIsomorphicLayoutEffect(()=>{
70
+ updatePositionManager();
71
+ }, [
72
+ updatePositionManager
73
+ ]);
74
+ if (process.env.NODE_ENV !== 'production') {
75
+ // This checked should run only in development mode
76
+ // eslint-disable-next-line react-hooks/rules-of-hooks
77
+ React.useEffect(()=>{
78
+ if (containerRef.current) {
79
+ var _contentNode_ownerDocument;
80
+ const contentNode = containerRef.current;
81
+ const treeWalker = (_contentNode_ownerDocument = contentNode.ownerDocument) === null || _contentNode_ownerDocument === void 0 ? void 0 : _contentNode_ownerDocument.createTreeWalker(contentNode, NodeFilter.SHOW_ELEMENT, {
82
+ acceptNode: hasAutofocusFilter
83
+ });
84
+ while(treeWalker.nextNode()){
85
+ const node = treeWalker.currentNode;
86
+ // eslint-disable-next-line no-console
87
+ console.warn('<Popper>:', node);
88
+ // eslint-disable-next-line no-console
89
+ console.warn([
90
+ '<Popper>: ^ this node contains "autoFocus" prop on a React element. This can break the initial',
91
+ 'positioning of an element and cause a window jump effect. This issue occurs because React polyfills',
92
+ '"autoFocus" behavior to solve inconsistencies between different browsers:',
93
+ 'https://github.com/facebook/react/issues/11851#issuecomment-351787078',
94
+ '\n',
95
+ 'However, ".focus()" in this case occurs before any other React effects will be executed',
96
+ '(React.useEffect(), componentDidMount(), etc.) and we can not prevent this behavior. If you really',
97
+ 'want to use "autoFocus" please add "position: fixed" to styles of the element that is wrapped by',
98
+ '"Popper".',
99
+ `In general, it's not recommended to use "autoFocus" as it may break accessibility aspects:`,
100
+ 'https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/master/docs/rules/no-autofocus.md',
101
+ '\n',
102
+ 'We suggest to use the "trapFocus" prop on Fluent components or a catch "ref" and then use',
103
+ '"ref.current.focus" in React.useEffect():',
104
+ 'https://reactjs.org/docs/refs-and-the-dom.html#adding-a-ref-to-a-dom-element'
105
+ ].join(' '));
106
+ }
107
+ }
108
+ // We run this check once, no need to add deps here
109
+ // TODO: Should be rework to handle options.enabled and contentRef updates
110
+ // eslint-disable-next-line react-hooks/exhaustive-deps
111
+ }, []);
93
112
  }
94
- });
95
- const setContainer = useCallbackRef(null, container => {
96
- if (containerRef.current !== container) {
97
- containerRef.current = container;
98
- updatePositionManager();
99
- }
100
- });
101
- const setArrow = useCallbackRef(null, arrow => {
102
- if (arrowRef.current !== arrow) {
103
- arrowRef.current = arrow;
104
- updatePositionManager();
105
- }
106
- });
107
- // Let users use callback refs so they feel like 'normal' DOM refs
108
- return {
109
- targetRef: setTarget,
110
- containerRef: setContainer,
111
- arrowRef: setArrow
112
- };
113
- }
114
- function usePositioningOptions(options) {
115
- const {
116
- align,
117
- arrowPadding,
118
- autoSize,
119
- coverTarget,
120
- flipBoundary,
121
- offset,
122
- overflowBoundary,
123
- pinned,
124
- position,
125
- unstable_disableTether: disableTether,
126
- positionFixed,
127
- overflowBoundaryPadding,
128
- fallbackPositions
129
- } = options;
130
- const {
131
- dir
132
- } = useFluent();
133
- const isRtl = dir === 'rtl';
134
- const strategy = positionFixed ? 'fixed' : 'absolute';
135
- return React.useCallback((container, arrow) => {
136
- const hasScrollableElement = hasScrollParent(container);
137
- const middleware = [offset && offsetMiddleware(offset), coverTarget && coverTargetMiddleware(), !pinned && flipMiddleware({
138
- container,
139
- flipBoundary,
140
- hasScrollableElement,
141
- isRtl,
142
- fallbackPositions
143
- }), shiftMiddleware({
144
- container,
145
- hasScrollableElement,
146
- overflowBoundary,
147
- disableTether,
148
- overflowBoundaryPadding,
149
- isRtl
150
- }), autoSize && maxSizeMiddleware(autoSize, {
151
- container,
152
- overflowBoundary
153
- }), intersectingMiddleware(), arrow && arrowMiddleware({
154
- element: arrow,
155
- padding: arrowPadding
156
- }), hideMiddleware({
157
- strategy: 'referenceHidden'
158
- }), hideMiddleware({
159
- strategy: 'escaped'
160
- })].filter(Boolean);
161
- const placement = toFloatingUIPlacement(align, position, isRtl);
113
+ const setTarget = useCallbackRef(null, (target)=>{
114
+ if (targetRef.current !== target) {
115
+ targetRef.current = target;
116
+ updatePositionManager();
117
+ }
118
+ });
119
+ const setContainer = useCallbackRef(null, (container)=>{
120
+ if (containerRef.current !== container) {
121
+ containerRef.current = container;
122
+ updatePositionManager();
123
+ }
124
+ });
125
+ const setArrow = useCallbackRef(null, (arrow)=>{
126
+ if (arrowRef.current !== arrow) {
127
+ arrowRef.current = arrow;
128
+ updatePositionManager();
129
+ }
130
+ });
131
+ // Let users use callback refs so they feel like 'normal' DOM refs
162
132
  return {
163
- placement,
164
- middleware,
165
- strategy
133
+ targetRef: setTarget,
134
+ containerRef: setContainer,
135
+ arrowRef: setArrow
166
136
  };
167
- }, [align, arrowPadding, autoSize, coverTarget, disableTether, flipBoundary, isRtl, offset, overflowBoundary, pinned, position, strategy, overflowBoundaryPadding, fallbackPositions]);
168
137
  }
169
- //# sourceMappingURL=usePositioning.js.map
138
+ function usePositioningOptions(options) {
139
+ const { align , arrowPadding , autoSize , coverTarget , flipBoundary , offset , overflowBoundary , pinned , position , unstable_disableTether: disableTether , positionFixed , overflowBoundaryPadding , fallbackPositions , useTransform } = options;
140
+ const { dir } = useFluent();
141
+ const isRtl = dir === 'rtl';
142
+ const strategy = positionFixed ? 'fixed' : 'absolute';
143
+ return React.useCallback((container, arrow)=>{
144
+ const hasScrollableElement = hasScrollParent(container);
145
+ const middleware = [
146
+ offset && offsetMiddleware(offset),
147
+ coverTarget && coverTargetMiddleware(),
148
+ !pinned && flipMiddleware({
149
+ container,
150
+ flipBoundary,
151
+ hasScrollableElement,
152
+ isRtl,
153
+ fallbackPositions
154
+ }),
155
+ shiftMiddleware({
156
+ container,
157
+ hasScrollableElement,
158
+ overflowBoundary,
159
+ disableTether,
160
+ overflowBoundaryPadding,
161
+ isRtl
162
+ }),
163
+ autoSize && maxSizeMiddleware(autoSize, {
164
+ container,
165
+ overflowBoundary
166
+ }),
167
+ intersectingMiddleware(),
168
+ arrow && arrowMiddleware({
169
+ element: arrow,
170
+ padding: arrowPadding
171
+ }),
172
+ hideMiddleware({
173
+ strategy: 'referenceHidden'
174
+ }),
175
+ hideMiddleware({
176
+ strategy: 'escaped'
177
+ })
178
+ ].filter(Boolean);
179
+ const placement = toFloatingUIPlacement(align, position, isRtl);
180
+ return {
181
+ placement,
182
+ middleware,
183
+ strategy,
184
+ useTransform
185
+ };
186
+ }, [
187
+ align,
188
+ arrowPadding,
189
+ autoSize,
190
+ coverTarget,
191
+ disableTether,
192
+ flipBoundary,
193
+ isRtl,
194
+ offset,
195
+ overflowBoundary,
196
+ pinned,
197
+ position,
198
+ strategy,
199
+ overflowBoundaryPadding,
200
+ fallbackPositions,
201
+ useTransform
202
+ ]);
203
+ }
@@ -1 +1 @@
1
- {"version":3,"names":["hide","hideMiddleware","arrow","arrowMiddleware","useFluent_unstable","useFluent","canUseDOM","useEventCallback","useIsomorphicLayoutEffect","React","useCallbackRef","toFloatingUIPlacement","hasAutofocusFilter","hasScrollParent","shift","shiftMiddleware","flip","flipMiddleware","coverTarget","coverTargetMiddleware","maxSize","maxSizeMiddleware","offset","offsetMiddleware","intersecting","intersectingMiddleware","createPositionManager","usePositioning","options","managerRef","useRef","targetRef","overrideTargetRef","containerRef","arrowRef","enabled","resolvePositioningOptions","usePositioningOptions","updatePositionManager","useCallback","current","dispose","_overrideTargetRef_current","target","container","setOverrideTarget","useImperativeHandle","positioningRef","updatePosition","_managerRef_current","setTarget","process","env","NODE_ENV","err","Error","console","warn","stack","_options_target","useEffect","_contentNode_ownerDocument","contentNode","treeWalker","ownerDocument","createTreeWalker","NodeFilter","SHOW_ELEMENT","acceptNode","nextNode","node","currentNode","join","setContainer","setArrow","align","arrowPadding","autoSize","flipBoundary","overflowBoundary","pinned","position","unstable_disableTether","disableTether","positionFixed","overflowBoundaryPadding","fallbackPositions","dir","isRtl","strategy","hasScrollableElement","middleware","element","padding","filter","Boolean","placement"],"sources":["../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,SAASA,IAAA,IAAQC,cAAc,EAAEC,KAAA,IAASC,eAAe,QAAQ;AAEjE,SAASC,kBAAA,IAAsBC,SAAS,QAAQ;AAChD,SAASC,SAAS,EAAEC,gBAAgB,EAAEC,yBAAyB,QAAQ;AACvE,YAAYC,KAAA,MAAW;AAQvB,SAASC,cAAc,EAAEC,qBAAqB,EAAEC,kBAAkB,EAAEC,eAAe,QAAQ;AAC3F,SACEC,KAAA,IAASC,eAAe,EACxBC,IAAA,IAAQC,cAAc,EACtBC,WA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AAA;MACAF;IACF;EACF,GACA,CACEd,KAAA,EACAC,YAAA,EACAC,QAAA,EACA3D,WAAA,EACAiE,aAAA,EACAL,YAAA,EACAU,KAAA,EACAlE,MAAA,EACAyD,gBAAA,EACAC,MAAA,EACAC,QAAA,EACAQ,QAAA,EACAJ,uBAAA,EACAC,iBAAA,CACD;AAEL"}
1
+ {"version":3,"sources":["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 useTransform,\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 useTransform,\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 useTransform,\n ],\n );\n}\n"],"names":["hide","hideMiddleware","arrow","arrowMiddleware","useFluent_unstable","useFluent","canUseDOM","useEventCallback","useIsomorphicLayoutEffect","React","useCallbackRef","toFloatingUIPlacement","hasAutofocusFilter","hasScrollParent","shift","shiftMiddleware","flip","flipMiddleware","coverTarget","coverTargetMiddleware","maxSize","maxSizeMiddleware","offset","offsetMiddleware","intersecting","intersectingMiddleware","createPositionManager","usePositioning","options","managerRef","useRef","targetRef","overrideTargetRef","containerRef","arrowRef","enabled","resolvePositioningOptions","usePositioningOptions","updatePositionManager","useCallback","current","dispose","target","container","setOverrideTarget","useImperativeHandle","positioningRef","updatePosition","setTarget","process","env","NODE_ENV","err","Error","console","warn","stack","useEffect","contentNode","treeWalker","ownerDocument","createTreeWalker","NodeFilter","SHOW_ELEMENT","acceptNode","nextNode","node","currentNode","join","setContainer","setArrow","align","arrowPadding","autoSize","flipBoundary","overflowBoundary","pinned","position","unstable_disableTether","disableTether","positionFixed","overflowBoundaryPadding","fallbackPositions","useTransform","dir","isRtl","strategy","hasScrollableElement","middleware","element","padding","filter","Boolean","placement"],"mappings":"AAAA,SAASA,QAAQC,cAAc,EAAEC,SAASC,eAAe,QAAQ,mBAAmB;AAEpF,SAASC,sBAAsBC,SAAS,QAAQ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AAQ;IACtB,MAAME,WAAqBN,gBAAgB,UAAU,UAAU;IAE/D,OAAOvE,MAAM8B,WAAW,CACtB,CAACI,WAA+BzC,QAA8B;QAC5D,MAAMqF,uBAAuB1E,gBAAgB8B;QAE7C,MAAM6C,aAAa;YACjBlE,UAAUC,iBAAiBD;YAC3BJ,eAAeC;YACf,CAACyD,UAAU3D,eAAe;gBAAE0B;gBAAW+B;gBAAca;gBAAsBF;gBAAOH;YAAkB;YACpGnE,gBAAgB;gBACd4B;gBACA4C;gBACAZ;gBACAI;gBACAE;gBACAI;YACF;YACAZ,YAAYpD,kBAAkBoD,UAAU;gBAAE9B;gBAAWgC;YAAiB;YACtElD;YACAvB,SAASC,gBAAgB;gBAAEsF,SAASvF;gBAAOwF,SAASlB;YAAa;YACjEvE,eAAe;gBAAEqF,UAAU;YAAkB;YAC7CrF,eAAe;gBAAEqF,UAAU;YAAU;SACtC,CAACK,MAAM,CAACC;QAET,MAAMC,YAAYlF,sBAAsB4D,OAAOM,UAAUQ;QAEzD,OAAO;YACLQ;YACAL;YACAF;YACAH;QACF;IACF,GACA;QACEZ;QACAC;QACAC;QACAvD;QACA6D;QACAL;QACAW;QACA/D;QACAqD;QACAC;QACAC;QACAS;QACAL;QACAC;QACAC;KACD;AAEL"}
@@ -8,27 +8,28 @@ import { createVirtualElementFromClick } from './createVirtualElementFromClick';
8
8
  *
9
9
  * @param initialState - initializes a user provided state similare to useState
10
10
  * @returns state and dispatcher for a Popper virtual element that uses native/synthetic mouse events
11
- */
12
- export 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 = createVirtualElementFromClick(mouseevent);
30
- setVirtualElement(contextTarget);
31
- };
32
- return [virtualElement, setVirtualMouseTarget];
11
+ */ export const usePositioningMouseTarget = (initialState)=>{
12
+ const [virtualElement, setVirtualElement] = React.useState(initialState);
13
+ const setVirtualMouseTarget = (event)=>{
14
+ if (event === undefined || event === null) {
15
+ setVirtualElement(undefined);
16
+ return;
17
+ }
18
+ let mouseevent;
19
+ if (!(event instanceof MouseEvent)) {
20
+ mouseevent = event.nativeEvent;
21
+ } else {
22
+ mouseevent = event;
23
+ }
24
+ if (!(mouseevent instanceof MouseEvent) && process.env.NODE_ENV !== 'production') {
25
+ // eslint-disable-next-line no-console
26
+ console.error('usePositioningMouseTarget should only be used with MouseEvent');
27
+ }
28
+ const contextTarget = createVirtualElementFromClick(mouseevent);
29
+ setVirtualElement(contextTarget);
30
+ };
31
+ return [
32
+ virtualElement,
33
+ setVirtualMouseTarget
34
+ ];
33
35
  };
34
- //# sourceMappingURL=usePositioningMouseTarget.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["React","createVirtualElementFromClick","usePositioningMouseTarget","initialState","virtualElement","setVirtualElement","useState","setVirtualMouseTarget","event","undefined","mouseevent","MouseEvent","nativeEvent","process","env","NODE_ENV","console","error","contextTarget"],"sources":["../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,YAAYA,KAAA,MAAW;AACvB,SAASC,6BAA6B,QAAQ;AAG9C;;;;;;;;;AASA,OAAO,MAAMC,yBAAA,GACXC,YAAA,IACG;EACH,MAAM,CAACC,cAAA,EAAgBC,iBAAA,CAAkB,GAAGL,KAAA,CAAMM,QAAQ,CAAwCH,YAAA;EAElG,MAAMI,qBAAA,GAA+CC,KAAA,IAAS;IAC5D,IAAIA,KAAA,KAAUC,SAAA,IAAaD,KAAA,KAAU,IAAI,EAAE;MACzCH,iBAAA,CAAkBI,SAAA;MAClB;IACF;IAEA,IAAIC,UAAA;IACJ,IAAI,EAAEF,KAAA,YAAiBG,UAAS,GAAI;MAClCD,UAAA,GAAaF,KAAA,CAAMI,WAAW;IAChC,OAAO;MACLF,UAAA,GAAaF,KAAA;IACf;IAEA,IAAI,EAAEE,UAAA,YAAsBC,UAAS,KAAME,OAAA,CAAQC,GAAG,CAACC,QAAQ,KAAK,cAAc;MAChF;MACAC,OAAA,CAAQC,KAAK,CAAC;IAChB;IAEA,MAAMC,aAAA,GAAgBjB,6BAAA,CAA8BS,UAAA;IACpDL,iBAAA,CAAkBa,aAAA;EACpB;EAEA,OAAO,CAACd,cAAA,EAAgBG,qBAAA,CAAsB;AAChD"}
1
+ {"version":3,"sources":["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"],"names":["React","createVirtualElementFromClick","usePositioningMouseTarget","initialState","virtualElement","setVirtualElement","useState","setVirtualMouseTarget","event","undefined","mouseevent","MouseEvent","nativeEvent","process","env","NODE_ENV","console","error","contextTarget"],"mappings":"AAAA,YAAYA,WAAW,QAAQ;AAC/B,SAASC,6BAA6B,QAAQ,kCAAkC;AAGhF;;;;;;;;CAQC,GACD,OAAO,MAAMC,4BAA4B,CACvCC,eACG;IACH,MAAM,CAACC,gBAAgBC,kBAAkB,GAAGL,MAAMM,QAAQ,CAAwCH;IAElG,MAAMI,wBAA+CC,CAAAA,QAAS;QAC5D,IAAIA,UAAUC,aAAaD,UAAU,IAAI,EAAE;YACzCH,kBAAkBI;YAClB;QACF,CAAC;QAED,IAAIC;QACJ,IAAI,CAAEF,CAAAA,iBAAiBG,UAAS,GAAI;YAClCD,aAAaF,MAAMI,WAAW;QAChC,OAAO;YACLF,aAAaF;QACf,CAAC;QAED,IAAI,CAAEE,CAAAA,sBAAsBC,UAAS,KAAME,QAAQC,GAAG,CAACC,QAAQ,KAAK,cAAc;YAChF,sCAAsC;YACtCC,QAAQC,KAAK,CAAC;QAChB,CAAC;QAED,MAAMC,gBAAgBjB,8BAA8BS;QACpDL,kBAAkBa;IACpB;IAEA,OAAO;QAACd;QAAgBG;KAAsB;AAChD,EAAE"}
@@ -3,18 +3,17 @@
3
3
  * This is no longer exported in Floating UI (Popper.js v3)
4
4
  * https://github.com/floating-ui/floating-ui/blob/v2.x/src/utils/debounce.js
5
5
  * @param fn function that will be debounced
6
- */export function debounce(fn) {
7
- let pending;
8
- return () => {
9
- if (!pending) {
10
- pending = new Promise(resolve => {
11
- Promise.resolve().then(() => {
12
- pending = undefined;
13
- resolve(fn());
14
- });
15
- });
16
- }
17
- return pending;
18
- };
6
+ */ export function debounce(fn) {
7
+ let pending;
8
+ return ()=>{
9
+ if (!pending) {
10
+ pending = new Promise((resolve)=>{
11
+ Promise.resolve().then(()=>{
12
+ pending = undefined;
13
+ resolve(fn());
14
+ });
15
+ });
16
+ }
17
+ return pending;
18
+ };
19
19
  }
20
- //# sourceMappingURL=debounce.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["debounce","fn","pending","Promise","resolve","then","undefined"],"sources":["../../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;;;;;GAMA,OAAO,SAASA,SAAYC,EAAY,EAAoB;EAC1D,IAAIC,OAAA;EACJ,OAAO,MAAM;IACX,IAAI,CAACA,OAAA,EAAS;MACZA,OAAA,GAAU,IAAIC,OAAA,CAAWC,OAAA,IAAW;QAClCD,OAAA,CAAQC,OAAO,GAAGC,IAAI,CAAC,MAAM;UAC3BH,OAAA,GAAUI,SAAA;UACVF,OAAA,CAAQH,EAAA;QACV;MACF;IACF;IAEA,OAAOC,OAAA;EACT;AACF"}
1
+ {"version":3,"sources":["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"],"names":["debounce","fn","pending","Promise","resolve","then","undefined"],"mappings":"AAAA;;;;;CAKC,GACD,OAAO,SAASA,SAAYC,EAAY,EAAoB;IAC1D,IAAIC;IACJ,OAAO,IAAM;QACX,IAAI,CAACA,SAAS;YACZA,UAAU,IAAIC,QAAWC,CAAAA,UAAW;gBAClCD,QAAQC,OAAO,GAAGC,IAAI,CAAC,IAAM;oBAC3BH,UAAUI;oBACVF,QAAQH;gBACV;YACF;QACF,CAAC;QAED,OAAOC;IACT;AACF,CAAC"}
@@ -1,38 +1,33 @@
1
1
  import { parseFloatingUIPlacement } from './parseFloatingUIPlacement';
2
- const getPositionMap = () => ({
3
- top: 'above',
4
- bottom: 'below',
5
- right: 'after',
6
- left: 'before'
7
- });
2
+ const getPositionMap = ()=>({
3
+ top: 'above',
4
+ bottom: 'below',
5
+ right: 'after',
6
+ left: 'before'
7
+ });
8
8
  // Floating UI automatically flips alignment
9
9
  // https://github.com/floating-ui/floating-ui/issues/1563
10
- const getAlignmentMap = position => {
11
- if (position === 'above' || position === 'below') {
10
+ const getAlignmentMap = (position)=>{
11
+ if (position === 'above' || position === 'below') {
12
+ return {
13
+ start: 'start',
14
+ end: 'end'
15
+ };
16
+ }
12
17
  return {
13
- start: 'start',
14
- end: 'end'
18
+ start: 'top',
19
+ end: 'bottom'
15
20
  };
16
- }
17
- return {
18
- start: 'top',
19
- end: 'bottom'
20
- };
21
21
  };
22
22
  /**
23
23
  * Maps Floating UI placement to positioning values
24
24
  * @see positioningHelper.test.ts for expected placement values
25
- */
26
- export const fromFloatingUIPlacement = placement => {
27
- const {
28
- side,
29
- alignment: floatingUIAlignment
30
- } = parseFloatingUIPlacement(placement);
31
- const position = getPositionMap()[side];
32
- const alignment = floatingUIAlignment && getAlignmentMap(position)[floatingUIAlignment];
33
- return {
34
- position,
35
- alignment
36
- };
25
+ */ export const fromFloatingUIPlacement = (placement)=>{
26
+ const { side , alignment: floatingUIAlignment } = parseFloatingUIPlacement(placement);
27
+ const position = getPositionMap()[side];
28
+ const alignment = floatingUIAlignment && getAlignmentMap(position)[floatingUIAlignment];
29
+ return {
30
+ position,
31
+ alignment
32
+ };
37
33
  };
38
- //# sourceMappingURL=fromFloatingUIPlacement.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["parseFloatingUIPlacement","getPositionMap","top","bottom","right","left","getAlignmentMap","position","start","end","fromFloatingUIPlacement","placement","side","alignment","floatingUIAlignment"],"sources":["../../src/utils/fromFloatingUIPlacement.ts"],"sourcesContent":["import type { Side, Alignment as FloatingUIAlignment, Placement } from '@floating-ui/dom';\nimport type { Alignment, Position } from '../types';\nimport { parseFloatingUIPlacement } from './parseFloatingUIPlacement';\n\nconst getPositionMap = (): Record<Side, Position> => ({\n top: 'above',\n bottom: 'below',\n right: 'after',\n left: 'before',\n});\n\n// Floating UI automatically flips alignment\n// https://github.com/floating-ui/floating-ui/issues/1563\nconst getAlignmentMap = (position: Position): Record<FloatingUIAlignment, Alignment> => {\n if (position === 'above' || position === 'below') {\n return {\n start: 'start',\n end: 'end',\n };\n }\n\n return {\n start: 'top',\n end: 'bottom',\n };\n};\n\n/**\n * Maps Floating UI placement to positioning values\n * @see positioningHelper.test.ts for expected placement values\n */\nexport const fromFloatingUIPlacement = (placement: Placement): { position: Position; alignment?: Alignment } => {\n const { side, alignment: floatingUIAlignment } = parseFloatingUIPlacement(placement);\n const position = getPositionMap()[side];\n const alignment = floatingUIAlignment && getAlignmentMap(position)[floatingUIAlignment];\n\n return { position, alignment };\n};\n"],"mappings":"AAEA,SAASA,wBAAwB,QAAQ;AAEzC,MAAMC,cAAA,GAAiBA,CAAA,MAA+B;EACpDC,GAAA,EAAK;EACLC,MAAA,EAAQ;EACRC,KAAA,EAAO;EACPC,IAAA,EAAM;AACR;AAEA;AACA;AACA,MAAMC,eAAA,GAAmBC,QAAA,IAA+D;EACtF,IAAIA,QAAA,KAAa,WAAWA,QAAA,KAAa,SAAS;IAChD,OAAO;MACLC,KAAA,EAAO;MACPC,GAAA,EAAK;IACP;EACF;EAEA,OAAO;IACLD,KAAA,EAAO;IACPC,GAAA,EAAK;EACP;AACF;AAEA;;;;AAIA,OAAO,MAAMC,uBAAA,GAA2BC,SAAA,IAAwE;EAC9G,MAAM;IAAEC,IAAA;IAAMC,SAAA,EAAWC;EAAmB,CAAE,GAAGd,wBAAA,CAAyBW,SAAA;EAC1E,MAAMJ,QAAA,GAAWN,cAAA,EAAgB,CAACW,IAAA,CAAK;EACvC,MAAMC,SAAA,GAAYC,mBAAA,IAAuBR,eAAA,CAAgBC,QAAA,CAAS,CAACO,mBAAA,CAAoB;EAEvF,OAAO;IAAEP,QAAA;IAAUM;EAAU;AAC/B"}
1
+ {"version":3,"sources":["fromFloatingUIPlacement.ts"],"sourcesContent":["import type { Side, Alignment as FloatingUIAlignment, Placement } from '@floating-ui/dom';\nimport type { Alignment, Position } from '../types';\nimport { parseFloatingUIPlacement } from './parseFloatingUIPlacement';\n\nconst getPositionMap = (): Record<Side, Position> => ({\n top: 'above',\n bottom: 'below',\n right: 'after',\n left: 'before',\n});\n\n// Floating UI automatically flips alignment\n// https://github.com/floating-ui/floating-ui/issues/1563\nconst getAlignmentMap = (position: Position): Record<FloatingUIAlignment, Alignment> => {\n if (position === 'above' || position === 'below') {\n return {\n start: 'start',\n end: 'end',\n };\n }\n\n return {\n start: 'top',\n end: 'bottom',\n };\n};\n\n/**\n * Maps Floating UI placement to positioning values\n * @see positioningHelper.test.ts for expected placement values\n */\nexport const fromFloatingUIPlacement = (placement: Placement): { position: Position; alignment?: Alignment } => {\n const { side, alignment: floatingUIAlignment } = parseFloatingUIPlacement(placement);\n const position = getPositionMap()[side];\n const alignment = floatingUIAlignment && getAlignmentMap(position)[floatingUIAlignment];\n\n return { position, alignment };\n};\n"],"names":["parseFloatingUIPlacement","getPositionMap","top","bottom","right","left","getAlignmentMap","position","start","end","fromFloatingUIPlacement","placement","side","alignment","floatingUIAlignment"],"mappings":"AAEA,SAASA,wBAAwB,QAAQ,6BAA6B;AAEtE,MAAMC,iBAAiB,IAA+B,CAAA;QACpDC,KAAK;QACLC,QAAQ;QACRC,OAAO;QACPC,MAAM;IACR,CAAA;AAEA,4CAA4C;AAC5C,yDAAyD;AACzD,MAAMC,kBAAkB,CAACC,WAA+D;IACtF,IAAIA,aAAa,WAAWA,aAAa,SAAS;QAChD,OAAO;YACLC,OAAO;YACPC,KAAK;QACP;IACF,CAAC;IAED,OAAO;QACLD,OAAO;QACPC,KAAK;IACP;AACF;AAEA;;;CAGC,GACD,OAAO,MAAMC,0BAA0B,CAACC,YAAwE;IAC9G,MAAM,EAAEC,KAAI,EAAEC,WAAWC,oBAAmB,EAAE,GAAGd,yBAAyBW;IAC1E,MAAMJ,WAAWN,gBAAgB,CAACW,KAAK;IACvC,MAAMC,YAAYC,uBAAuBR,gBAAgBC,SAAS,CAACO,oBAAoB;IAEvF,OAAO;QAAEP;QAAUM;IAAU;AAC/B,EAAE"}