@fluentui/react-positioning 9.0.0-nightly.d730088d7f.0 → 9.0.0-rc.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (117) hide show
  1. package/CHANGELOG.json +457 -12
  2. package/CHANGELOG.md +209 -72
  3. package/dist/index.d.ts +247 -0
  4. package/{lib → dist}/tsdoc-metadata.json +0 -0
  5. package/lib/createArrowStyles.js +87 -0
  6. package/lib/createArrowStyles.js.map +1 -0
  7. package/lib/createVirtualElementFromClick.js +19 -15
  8. package/lib/createVirtualElementFromClick.js.map +1 -1
  9. package/lib/index.js +4 -4
  10. package/lib/index.js.map +1 -1
  11. package/lib/isIntersectingModifier.js +26 -0
  12. package/lib/isIntersectingModifier.js.map +1 -0
  13. package/lib/types.js.map +1 -1
  14. package/lib/usePositioning.js +408 -0
  15. package/lib/usePositioning.js.map +1 -0
  16. package/lib/usePositioningMouseTarget.js +40 -0
  17. package/lib/usePositioningMouseTarget.js.map +1 -0
  18. package/lib/utils/fromPopperPlacement.js +40 -0
  19. package/lib/utils/fromPopperPlacement.js.map +1 -0
  20. package/lib/utils/getBoundary.js +15 -10
  21. package/lib/utils/getBoundary.js.map +1 -1
  22. package/lib/utils/getPopperOffset.js +44 -0
  23. package/lib/utils/getPopperOffset.js.map +1 -0
  24. package/lib/utils/getReactFiberFromNode.js +39 -35
  25. package/lib/utils/getReactFiberFromNode.js.map +1 -1
  26. package/lib/utils/getScrollParent.js +46 -32
  27. package/lib/utils/getScrollParent.js.map +1 -1
  28. package/lib/utils/index.js +1 -1
  29. package/lib/utils/index.js.map +1 -1
  30. package/lib/utils/mergeArrowOffset.js +31 -25
  31. package/lib/utils/mergeArrowOffset.js.map +1 -1
  32. package/lib/utils/parsePopperPlacement.js +14 -0
  33. package/lib/utils/parsePopperPlacement.js.map +1 -0
  34. package/lib/utils/positioningHelper.js +42 -34
  35. package/lib/utils/positioningHelper.js.map +1 -1
  36. package/lib/utils/resolvePositioningShorthand.js +58 -20
  37. package/lib/utils/resolvePositioningShorthand.js.map +1 -1
  38. package/lib/utils/useCallbackRef.js +35 -29
  39. package/lib/utils/useCallbackRef.js.map +1 -1
  40. package/lib-commonjs/createArrowStyles.js +100 -0
  41. package/lib-commonjs/createArrowStyles.js.map +1 -0
  42. package/lib-commonjs/createVirtualElementFromClick.js +25 -16
  43. package/lib-commonjs/createVirtualElementFromClick.js.map +1 -1
  44. package/lib-commonjs/index.js +62 -10
  45. package/lib-commonjs/index.js.map +1 -1
  46. package/lib-commonjs/isIntersectingModifier.js +34 -0
  47. package/lib-commonjs/isIntersectingModifier.js.map +1 -0
  48. package/lib-commonjs/types.js +4 -1
  49. package/lib-commonjs/types.js.map +1 -1
  50. package/lib-commonjs/usePositioning.js +424 -0
  51. package/lib-commonjs/usePositioning.js.map +1 -0
  52. package/lib-commonjs/usePositioningMouseTarget.js +51 -0
  53. package/lib-commonjs/usePositioningMouseTarget.js.map +1 -0
  54. package/lib-commonjs/utils/fromPopperPlacement.js +50 -0
  55. package/lib-commonjs/utils/fromPopperPlacement.js.map +1 -0
  56. package/lib-commonjs/utils/getBoundary.js +23 -12
  57. package/lib-commonjs/utils/getBoundary.js.map +1 -1
  58. package/lib-commonjs/utils/getPopperOffset.js +54 -0
  59. package/lib-commonjs/utils/getPopperOffset.js.map +1 -0
  60. package/lib-commonjs/utils/getReactFiberFromNode.js +44 -36
  61. package/lib-commonjs/utils/getReactFiberFromNode.js.map +1 -1
  62. package/lib-commonjs/utils/getScrollParent.js +53 -33
  63. package/lib-commonjs/utils/getScrollParent.js.map +1 -1
  64. package/lib-commonjs/utils/index.js +15 -3
  65. package/lib-commonjs/utils/index.js.map +1 -1
  66. package/lib-commonjs/utils/mergeArrowOffset.js +37 -26
  67. package/lib-commonjs/utils/mergeArrowOffset.js.map +1 -1
  68. package/lib-commonjs/utils/parsePopperPlacement.js +23 -0
  69. package/lib-commonjs/utils/parsePopperPlacement.js.map +1 -0
  70. package/lib-commonjs/utils/positioningHelper.js +50 -35
  71. package/lib-commonjs/utils/positioningHelper.js.map +1 -1
  72. package/lib-commonjs/utils/resolvePositioningShorthand.js +66 -23
  73. package/lib-commonjs/utils/resolvePositioningShorthand.js.map +1 -1
  74. package/lib-commonjs/utils/useCallbackRef.js +45 -32
  75. package/lib-commonjs/utils/useCallbackRef.js.map +1 -1
  76. package/package.json +17 -14
  77. package/dist/react-positioning.d.ts +0 -143
  78. package/lib/createVirtualElementFromClick.d.ts +0 -6
  79. package/lib/index.d.ts +0 -5
  80. package/lib/types.d.ts +0 -68
  81. package/lib/usePopper.d.ts +0 -35
  82. package/lib/usePopper.js +0 -357
  83. package/lib/usePopper.js.map +0 -1
  84. package/lib/usePopperMouseTarget.d.ts +0 -11
  85. package/lib/usePopperMouseTarget.js +0 -34
  86. package/lib/usePopperMouseTarget.js.map +0 -1
  87. package/lib/utils/getBasePlacement.d.ts +0 -8
  88. package/lib/utils/getBasePlacement.js +0 -10
  89. package/lib/utils/getBasePlacement.js.map +0 -1
  90. package/lib/utils/getBoundary.d.ts +0 -6
  91. package/lib/utils/getReactFiberFromNode.d.ts +0 -109
  92. package/lib/utils/getScrollParent.d.ts +0 -12
  93. package/lib/utils/index.d.ts +0 -8
  94. package/lib/utils/mergeArrowOffset.d.ts +0 -10
  95. package/lib/utils/positioningHelper.d.ts +0 -7
  96. package/lib/utils/resolvePositioningShorthand.d.ts +0 -2
  97. package/lib/utils/useCallbackRef.d.ts +0 -19
  98. package/lib-commonjs/createVirtualElementFromClick.d.ts +0 -6
  99. package/lib-commonjs/index.d.ts +0 -5
  100. package/lib-commonjs/types.d.ts +0 -68
  101. package/lib-commonjs/usePopper.d.ts +0 -35
  102. package/lib-commonjs/usePopper.js +0 -361
  103. package/lib-commonjs/usePopper.js.map +0 -1
  104. package/lib-commonjs/usePopperMouseTarget.d.ts +0 -11
  105. package/lib-commonjs/usePopperMouseTarget.js +0 -38
  106. package/lib-commonjs/usePopperMouseTarget.js.map +0 -1
  107. package/lib-commonjs/utils/getBasePlacement.d.ts +0 -8
  108. package/lib-commonjs/utils/getBasePlacement.js +0 -14
  109. package/lib-commonjs/utils/getBasePlacement.js.map +0 -1
  110. package/lib-commonjs/utils/getBoundary.d.ts +0 -6
  111. package/lib-commonjs/utils/getReactFiberFromNode.d.ts +0 -109
  112. package/lib-commonjs/utils/getScrollParent.d.ts +0 -12
  113. package/lib-commonjs/utils/index.d.ts +0 -8
  114. package/lib-commonjs/utils/mergeArrowOffset.d.ts +0 -10
  115. package/lib-commonjs/utils/positioningHelper.d.ts +0 -7
  116. package/lib-commonjs/utils/resolvePositioningShorthand.d.ts +0 -2
  117. package/lib-commonjs/utils/useCallbackRef.d.ts +0 -19
@@ -0,0 +1,408 @@
1
+ import { useEventCallback, useIsomorphicLayoutEffect, useFirstMount, canUseDOM } from '@fluentui/react-utilities';
2
+ import { useFluent } from '@fluentui/react-shared-contexts';
3
+ import * as PopperJs from '@popperjs/core';
4
+ import * as React from 'react';
5
+ import { isIntersectingModifier } from './isIntersectingModifier';
6
+ import { getScrollParent, applyRtlToOffset, getPlacement, getReactFiberFromNode, getBoundary, useCallbackRef, parsePopperPlacement } from './utils/index';
7
+ import { getPopperOffset } from './utils/getPopperOffset'; //
8
+ // Dev utils to detect if nodes have "autoFocus" props.
9
+ //
10
+
11
+ /**
12
+ * Detects if a passed HTML node has "autoFocus" prop on a React's fiber. Is needed as React handles autofocus behavior
13
+ * in React DOM and will not pass "autoFocus" to an actual HTML.
14
+ */
15
+
16
+ function hasAutofocusProp(node) {
17
+ var _a; // https://github.com/facebook/react/blob/848bb2426e44606e0a55dfe44c7b3ece33772485/packages/react-dom/src/client/ReactDOMHostConfig.js#L157-L166
18
+
19
+
20
+ const isAutoFocusableElement = node.nodeName === 'BUTTON' || node.nodeName === 'INPUT' || node.nodeName === 'SELECT' || node.nodeName === 'TEXTAREA';
21
+
22
+ if (isAutoFocusableElement) {
23
+ return !!((_a = getReactFiberFromNode(node)) === null || _a === void 0 ? void 0 : _a.pendingProps.autoFocus);
24
+ }
25
+
26
+ return false;
27
+ }
28
+
29
+ function hasAutofocusFilter(node) {
30
+ return hasAutofocusProp(node) ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP;
31
+ }
32
+ /**
33
+ * Provides a callback to resolve Popper options, it's stable and should be used as a dependency to trigger updates
34
+ * of Popper options.
35
+ *
36
+ * A callback is used there intentionally as some of Popper.js modifiers require DOM nodes (targer, container, arrow)
37
+ * that can't be resolved properly during an initial rendering.
38
+ */
39
+
40
+
41
+ function usePopperOptions(options, popperOriginalPositionRef) {
42
+ const {
43
+ align,
44
+ arrowPadding,
45
+ autoSize,
46
+ coverTarget,
47
+ flipBoundary,
48
+ offset,
49
+ overflowBoundary,
50
+ pinned,
51
+ position,
52
+ positionFixed,
53
+ // eslint-disable-next-line @typescript-eslint/naming-convention
54
+ unstable_disableTether
55
+ } = options;
56
+ const isRtl = useFluent().dir === 'rtl';
57
+ const placement = getPlacement(align, position, isRtl);
58
+ const strategy = positionFixed ? 'fixed' : 'absolute';
59
+ const offsetModifier = React.useMemo(() => offset ? {
60
+ name: 'offset',
61
+ options: {
62
+ offset: isRtl ? applyRtlToOffset(getPopperOffset(offset)) : getPopperOffset(offset)
63
+ }
64
+ } : null, [offset, isRtl]);
65
+ return React.useCallback((target, container, arrow) => {
66
+ var _a;
67
+
68
+ const scrollParentElement = getScrollParent(container);
69
+ const hasScrollableElement = scrollParentElement ? scrollParentElement !== ((_a = scrollParentElement.ownerDocument) === null || _a === void 0 ? void 0 : _a.body) : false;
70
+ const modifiers = [isIntersectingModifier,
71
+ /**
72
+ * We are setting the position to `fixed` in the first effect to prevent scroll jumps in case of the content
73
+ * with managed focus. Modifier sets the position to `fixed` before all other modifier effects. Another part of
74
+ * a patch modifies ".forceUpdate()" directly after a Popper will be created.
75
+ */
76
+ {
77
+ name: 'positionStyleFix',
78
+ enabled: true,
79
+ phase: 'afterWrite',
80
+ effect: ({
81
+ state,
82
+ instance
83
+ }) => {
84
+ // ".isFirstRun" is a part of our patch, on a first evaluation it will "undefined"
85
+ // should be disabled for subsequent runs as it breaks positioning for them
86
+ if (instance.isFirstRun !== false) {
87
+ popperOriginalPositionRef.current = state.elements.popper.style.position;
88
+ state.elements.popper.style.position = 'fixed';
89
+ }
90
+
91
+ return () => undefined;
92
+ },
93
+ requires: []
94
+ }, {
95
+ name: 'flip',
96
+ options: {
97
+ flipVariations: true
98
+ }
99
+ },
100
+ /**
101
+ * pinned disables the flip modifier by setting flip.enabled to false; this
102
+ * disables automatic repositioning of the popper box; it will always be placed according to
103
+ * the values of `align` and `position` props, regardless of the size of the component, the
104
+ * reference element or the viewport.
105
+ */
106
+ pinned && {
107
+ name: 'flip',
108
+ enabled: false
109
+ },
110
+ /**
111
+ * When the popper box is placed in the context of a scrollable element, we need to set
112
+ * preventOverflow.escapeWithReference to true and flip.boundariesElement to 'scrollParent'
113
+ * (default is 'viewport') so that the popper box will stick with the targetRef when we
114
+ * scroll targetRef out of the viewport.
115
+ */
116
+ hasScrollableElement && {
117
+ name: 'flip',
118
+ options: {
119
+ boundary: 'clippingParents'
120
+ }
121
+ }, hasScrollableElement && {
122
+ name: 'preventOverflow',
123
+ options: {
124
+ boundary: 'clippingParents'
125
+ }
126
+ }, offsetModifier,
127
+ /**
128
+ * This modifier is necessary to retain behaviour from popper v1 where untethered poppers are allowed by
129
+ * default. i.e. popper is still rendered fully in the viewport even if anchor element is no longer in the
130
+ * viewport.
131
+ */
132
+ unstable_disableTether && {
133
+ name: 'preventOverflow',
134
+ options: {
135
+ altAxis: unstable_disableTether === 'all',
136
+ tether: false
137
+ }
138
+ }, flipBoundary && {
139
+ name: 'flip',
140
+ options: {
141
+ altBoundary: true,
142
+ boundary: getBoundary(container, flipBoundary)
143
+ }
144
+ }, overflowBoundary && {
145
+ name: 'preventOverflow',
146
+ options: {
147
+ altBoundary: true,
148
+ boundary: getBoundary(container, overflowBoundary)
149
+ }
150
+ }, {
151
+ // Similar code as popper-maxsize-modifier: https://github.com/atomiks/popper.js/blob/master/src/modifiers/maxSize.js
152
+ // popper-maxsize-modifier only calculates the max sizes.
153
+ // This modifier can apply max sizes always, or apply the max sizes only when overflow is detected
154
+ name: 'applyMaxSize',
155
+ enabled: !!autoSize,
156
+ phase: 'beforeWrite',
157
+ requiresIfExists: ['offset', 'preventOverflow', 'flip'],
158
+ options: {
159
+ altBoundary: true,
160
+ boundary: getBoundary(container, overflowBoundary)
161
+ },
162
+
163
+ fn({
164
+ state,
165
+ options: modifierOptions
166
+ }) {
167
+ const overflow = PopperJs.detectOverflow(state, modifierOptions);
168
+ const {
169
+ x,
170
+ y
171
+ } = state.modifiersData.preventOverflow || {
172
+ x: 0,
173
+ y: 0
174
+ };
175
+ const {
176
+ width,
177
+ height
178
+ } = state.rects.popper;
179
+ const basePlacement = parsePopperPlacement(state.placement).basePlacement;
180
+ const widthProp = basePlacement === 'left' ? 'left' : 'right';
181
+ const heightProp = basePlacement === 'top' ? 'top' : 'bottom';
182
+ const applyMaxWidth = autoSize === 'always' || autoSize === 'width-always' || overflow[widthProp] > 0 && (autoSize === true || autoSize === 'width');
183
+ const applyMaxHeight = autoSize === 'always' || autoSize === 'height-always' || overflow[heightProp] > 0 && (autoSize === true || autoSize === 'height');
184
+
185
+ if (applyMaxWidth) {
186
+ state.styles.popper.maxWidth = `${width - overflow[widthProp] - x}px`;
187
+ }
188
+
189
+ if (applyMaxHeight) {
190
+ state.styles.popper.maxHeight = `${height - overflow[heightProp] - y}px`;
191
+ }
192
+ }
193
+
194
+ },
195
+ /**
196
+ * This modifier is necessary in order to render the pointer. Refs are resolved in effects, so it can't be
197
+ * placed under computed modifiers. Deep merge is not required as this modifier has only these properties.
198
+ */
199
+ {
200
+ name: 'arrow',
201
+ enabled: !!arrow,
202
+ options: {
203
+ element: arrow,
204
+ padding: arrowPadding
205
+ }
206
+ },
207
+ /**
208
+ * Modifies popper offsets to cover the reference rect, but still keep edge alignment
209
+ */
210
+ {
211
+ name: 'coverTarget',
212
+ enabled: !!coverTarget,
213
+ phase: 'main',
214
+ requiresIfExists: ['offset', 'preventOverflow', 'flip'],
215
+
216
+ fn({
217
+ state
218
+ }) {
219
+ const basePlacement = parsePopperPlacement(state.placement).basePlacement;
220
+
221
+ switch (basePlacement) {
222
+ case 'bottom':
223
+ state.modifiersData.popperOffsets.y -= state.rects.reference.height;
224
+ break;
225
+
226
+ case 'top':
227
+ state.modifiersData.popperOffsets.y += state.rects.reference.height;
228
+ break;
229
+
230
+ case 'left':
231
+ state.modifiersData.popperOffsets.x += state.rects.reference.width;
232
+ break;
233
+
234
+ case 'right':
235
+ state.modifiersData.popperOffsets.x -= state.rects.reference.width;
236
+ break;
237
+ }
238
+ }
239
+
240
+ }].filter(Boolean); // filter boolean conditional spreading values
241
+
242
+ const popperOptions = {
243
+ modifiers,
244
+ placement,
245
+ strategy
246
+ };
247
+ return popperOptions;
248
+ }, [arrowPadding, autoSize, coverTarget, flipBoundary, offsetModifier, overflowBoundary, placement, strategy, unstable_disableTether, pinned, // These can be skipped from deps as they will not ever change
249
+ popperOriginalPositionRef]);
250
+ }
251
+ /**
252
+ * Exposes Popper positioning API via React hook. Contains few important differences between an official "react-popper"
253
+ * package:
254
+ * - style attributes are applied directly on DOM to avoid re-renders
255
+ * - refs changes and resolution is handled properly without re-renders
256
+ * - contains a specific to React fix related to initial positioning when containers have components with managed focus
257
+ * to avoid focus jumps
258
+ */
259
+
260
+
261
+ export function usePositioning(options = {}) {
262
+ const {
263
+ enabled = true
264
+ } = options;
265
+ const isFirstMount = useFirstMount();
266
+ const popperOriginalPositionRef = React.useRef('absolute');
267
+ const resolvePopperOptions = usePopperOptions(options, popperOriginalPositionRef);
268
+ const popperInstanceRef = React.useRef(null);
269
+ const handlePopperUpdate = useEventCallback(() => {
270
+ var _a, _b;
271
+
272
+ (_a = popperInstanceRef.current) === null || _a === void 0 ? void 0 : _a.destroy();
273
+ popperInstanceRef.current = null;
274
+ const target = (_b = overrideTargetRef.current) !== null && _b !== void 0 ? _b : targetRef.current;
275
+ let popperInstance = null;
276
+
277
+ if (canUseDOM() && enabled) {
278
+ if (target && containerRef.current) {
279
+ popperInstance = PopperJs.createPopper(target, containerRef.current, resolvePopperOptions(target, containerRef.current, arrowRef.current));
280
+ }
281
+ }
282
+
283
+ if (popperInstance) {
284
+ /**
285
+ * The patch updates `.forceUpdate()` Popper function which restores the original position before the first
286
+ * forceUpdate() call. See also "positionStyleFix" modifier in usePopperOptions().
287
+ */
288
+ const originalForceUpdate = popperInstance.forceUpdate;
289
+ popperInstance.isFirstRun = true;
290
+
291
+ popperInstance.forceUpdate = () => {
292
+ if (popperInstance === null || popperInstance === void 0 ? void 0 : popperInstance.isFirstRun) {
293
+ popperInstance.state.elements.popper.style.position = popperOriginalPositionRef.current;
294
+ popperInstance.isFirstRun = false;
295
+ }
296
+
297
+ originalForceUpdate();
298
+ };
299
+ }
300
+
301
+ popperInstanceRef.current = popperInstance;
302
+ }); // Refs are managed by useCallbackRef() to handle ref updates scenarios.
303
+ //
304
+ // The first scenario are updates for a targetRef, we can handle it properly only via callback refs, but it causes
305
+ // re-renders (we would like to avoid them).
306
+ //
307
+ // The second problem is related to refs resolution on React's layer: refs are resolved in the same order as effects
308
+ // that causes an issue when you have a container inside a target, for example: a menu in ChatMessage.
309
+ //
310
+ // function ChatMessage(props) {
311
+ // <div className="message" ref={targetRef}> // 3) ref will be resolved only now, but it's too late already
312
+ // <Popper target={targetRef}> // 2) create a popper instance
313
+ // <div className="menu" /> // 1) capture ref from this element
314
+ // </Popper>
315
+ // </div>
316
+ // }
317
+ //
318
+ // Check a demo on CodeSandbox: https://codesandbox.io/s/popper-refs-emy60.
319
+ //
320
+ // This again can be solved with callback refs. It's not a huge issue as with hooks we are moving popper's creation
321
+ // to ChatMessage itself, however, without `useCallback()` refs it's still a Pandora box.
322
+
323
+ const targetRef = useCallbackRef(null, handlePopperUpdate, true);
324
+ const containerRef = useCallbackRef(null, handlePopperUpdate, true);
325
+ const arrowRef = useCallbackRef(null, handlePopperUpdate, true); // Stores external target from options.target or setTarget
326
+
327
+ const overrideTargetRef = useCallbackRef(null, handlePopperUpdate, true);
328
+ React.useImperativeHandle(options.positioningRef, () => ({
329
+ updatePosition: () => {
330
+ var _a;
331
+
332
+ (_a = popperInstanceRef.current) === null || _a === void 0 ? void 0 : _a.update();
333
+ },
334
+ setTarget: target => {
335
+ if (options.target && process.env.NODE_ENV !== 'production') {
336
+ const err = new Error(); // eslint-disable-next-line no-console
337
+
338
+ console.warn('Imperative setTarget should not be used at the same time as target option'); // eslint-disable-next-line no-console
339
+
340
+ console.warn(err.stack);
341
+ }
342
+
343
+ overrideTargetRef.current = target;
344
+ }
345
+ }), // Missing deps:
346
+ // options.target - only used for a runtime warning
347
+ // targetRef - Stable between renders
348
+ // eslint-disable-next-line react-hooks/exhaustive-deps
349
+ []);
350
+ useIsomorphicLayoutEffect(() => {
351
+ if (options.target) {
352
+ overrideTargetRef.current = options.target;
353
+ }
354
+ }, [options.target, overrideTargetRef]);
355
+ useIsomorphicLayoutEffect(() => {
356
+ handlePopperUpdate();
357
+ return () => {
358
+ var _a;
359
+
360
+ (_a = popperInstanceRef.current) === null || _a === void 0 ? void 0 : _a.destroy();
361
+ popperInstanceRef.current = null;
362
+ };
363
+ }, [handlePopperUpdate, options.enabled]);
364
+ useIsomorphicLayoutEffect(() => {
365
+ var _a, _b;
366
+
367
+ if (!isFirstMount) {
368
+ (_a = popperInstanceRef.current) === null || _a === void 0 ? void 0 : _a.setOptions(resolvePopperOptions((_b = overrideTargetRef.current) !== null && _b !== void 0 ? _b : targetRef.current, containerRef.current, arrowRef.current));
369
+ }
370
+ }, // Missing deps:
371
+ // isFirstMount - Should never change after mount
372
+ // arrowRef, containerRef, targetRef - Stable between renders
373
+ // eslint-disable-next-line react-hooks/exhaustive-deps
374
+ [resolvePopperOptions]);
375
+
376
+ if (process.env.NODE_ENV !== 'production') {
377
+ // This checked should run only in development mode
378
+ // eslint-disable-next-line react-hooks/rules-of-hooks
379
+ React.useEffect(() => {
380
+ var _a;
381
+
382
+ if (containerRef.current) {
383
+ const contentNode = containerRef.current;
384
+ const treeWalker = (_a = contentNode.ownerDocument) === null || _a === void 0 ? void 0 : _a.createTreeWalker(contentNode, NodeFilter.SHOW_ELEMENT, {
385
+ acceptNode: hasAutofocusFilter
386
+ });
387
+
388
+ while (treeWalker === null || treeWalker === void 0 ? void 0 : treeWalker.nextNode()) {
389
+ const node = treeWalker.currentNode; // eslint-disable-next-line no-console
390
+
391
+ console.warn('<Popper>:', node); // eslint-disable-next-line no-console
392
+
393
+ 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(' '));
394
+ }
395
+ } // We run this check once, no need to add deps here
396
+ // TODO: Should be rework to handle options.enabled and contentRef updates
397
+ // eslint-disable-next-line react-hooks/exhaustive-deps
398
+
399
+ }, []);
400
+ }
401
+
402
+ return {
403
+ targetRef,
404
+ containerRef,
405
+ arrowRef
406
+ };
407
+ }
408
+ //# sourceMappingURL=usePositioning.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["usePositioning.ts"],"names":[],"mappings":"AAAA,SAAS,gBAAT,EAA2B,yBAA3B,EAAsD,aAAtD,EAAqE,SAArE,QAAsF,2BAAtF;AACA,SAAS,SAAT,QAA0B,iCAA1B;AACA,OAAO,KAAK,QAAZ,M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,CAE7B;;AACA,UAAA,OAAO,CAAC,IAAR,CAAa,WAAb,EAA0B,IAA1B,EAH6B,CAI7B;;AACA,UAAA,OAAO,CAAC,IAAR,CACE,CACE,gGADF,EAEE,qGAFF,EAGE,2EAHF,EAIE,uEAJF,EAKE,IALF,EAME,yFANF,EAOE,oGAPF,EAQE,kGARF,EASE,WATF,EAUE,4FAVF,EAWE,6FAXF,EAYE,IAZF,EAaE,2FAbF,EAcE,2CAdF,EAeE,8EAfF,EAgBE,IAhBF,CAgBO,GAhBP,CADF;AAmBD;AACF,OAhCkB,CAiCnB;AACA;AACA;;AACD,KApCD,EAoCG,EApCH;AAqCD;;AAED,SAAO;AAAE,IAAA,SAAF;AAAa,IAAA,YAAb;AAA2B,IAAA;AAA3B,GAAP;AACD","sourcesContent":["import { useEventCallback, useIsomorphicLayoutEffect, useFirstMount, canUseDOM } from '@fluentui/react-utilities';\nimport { useFluent } from '@fluentui/react-shared-contexts';\nimport * as PopperJs from '@popperjs/core';\nimport * as React from 'react';\n\nimport { isIntersectingModifier } from './isIntersectingModifier';\nimport {\n getScrollParent,\n applyRtlToOffset,\n getPlacement,\n getReactFiberFromNode,\n getBoundary,\n useCallbackRef,\n parsePopperPlacement,\n} from './utils/index';\nimport type { PositioningVirtualElement, PositioningOptions, PositioningProps } from './types';\nimport { getPopperOffset } from './utils/getPopperOffset';\n\ntype PopperInstance = PopperJs.Instance & { isFirstRun?: boolean };\n\ninterface UsePopperOptions extends PositioningProps {\n /**\n * If false, delays Popper's creation.\n * @default true\n */\n enabled?: boolean;\n}\n\n//\n// Dev utils to detect if nodes have \"autoFocus\" props.\n//\n\n/**\n * Detects if a passed HTML node has \"autoFocus\" prop on a React's fiber. Is needed as React handles autofocus behavior\n * in React DOM and will not pass \"autoFocus\" to an actual HTML.\n */\nfunction hasAutofocusProp(node: Node): boolean {\n // https://github.com/facebook/react/blob/848bb2426e44606e0a55dfe44c7b3ece33772485/packages/react-dom/src/client/ReactDOMHostConfig.js#L157-L166\n const isAutoFocusableElement =\n node.nodeName === 'BUTTON' ||\n node.nodeName === 'INPUT' ||\n node.nodeName === 'SELECT' ||\n node.nodeName === 'TEXTAREA';\n\n if (isAutoFocusableElement) {\n return !!getReactFiberFromNode(node)?.pendingProps.autoFocus;\n }\n\n return false;\n}\n\nfunction hasAutofocusFilter(node: Node) {\n return hasAutofocusProp(node) ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP;\n}\n\n/**\n * Provides a callback to resolve Popper options, it's stable and should be used as a dependency to trigger updates\n * of Popper options.\n *\n * A callback is used there intentionally as some of Popper.js modifiers require DOM nodes (targer, container, arrow)\n * that can't be resolved properly during an initial rendering.\n */\nfunction usePopperOptions(options: PositioningOptions, popperOriginalPositionRef: React.MutableRefObject<string>) {\n const {\n align,\n arrowPadding,\n autoSize,\n coverTarget,\n flipBoundary,\n offset,\n overflowBoundary,\n pinned,\n position,\n positionFixed,\n // eslint-disable-next-line @typescript-eslint/naming-convention\n unstable_disableTether,\n } = options;\n\n const isRtl = useFluent().dir === 'rtl';\n const placement = getPlacement(align, position, isRtl);\n const strategy = positionFixed ? 'fixed' : 'absolute';\n\n const offsetModifier = React.useMemo(\n () =>\n offset\n ? {\n name: 'offset',\n options: { offset: isRtl ? applyRtlToOffset(getPopperOffset(offset)) : getPopperOffset(offset) },\n }\n : null,\n [offset, isRtl],\n );\n\n return React.useCallback(\n (\n target: HTMLElement | PopperJs.VirtualElement | null,\n container: HTMLElement | null,\n arrow: HTMLElement | null,\n ): PopperJs.Options => {\n const scrollParentElement: HTMLElement = getScrollParent(container);\n const hasScrollableElement = scrollParentElement\n ? scrollParentElement !== scrollParentElement.ownerDocument?.body\n : false;\n\n const modifiers: PopperJs.Options['modifiers'] = [\n isIntersectingModifier,\n\n /**\n * We are setting the position to `fixed` in the first effect to prevent scroll jumps in case of the content\n * with managed focus. Modifier sets the position to `fixed` before all other modifier effects. Another part of\n * a patch modifies \".forceUpdate()\" directly after a Popper will be created.\n */\n {\n name: 'positionStyleFix',\n enabled: true,\n phase: 'afterWrite' as PopperJs.ModifierPhases,\n effect: ({ state, instance }: { state: PopperJs.State; instance: PopperInstance }) => {\n // \".isFirstRun\" is a part of our patch, on a first evaluation it will \"undefined\"\n // should be disabled for subsequent runs as it breaks positioning for them\n if (instance.isFirstRun !== false) {\n popperOriginalPositionRef.current = state.elements.popper.style.position;\n state.elements.popper.style.position = 'fixed';\n }\n\n return () => undefined;\n },\n requires: [],\n },\n\n { name: 'flip', options: { flipVariations: true } },\n\n /**\n * pinned disables the flip modifier by setting flip.enabled to false; this\n * disables automatic repositioning of the popper box; it will always be placed according to\n * the values of `align` and `position` props, regardless of the size of the component, the\n * reference element or the viewport.\n */\n pinned && { name: 'flip', enabled: false },\n\n /**\n * When the popper box is placed in the context of a scrollable element, we need to set\n * preventOverflow.escapeWithReference to true and flip.boundariesElement to 'scrollParent'\n * (default is 'viewport') so that the popper box will stick with the targetRef when we\n * scroll targetRef out of the viewport.\n */\n hasScrollableElement && { name: 'flip', options: { boundary: 'clippingParents' } },\n hasScrollableElement && { name: 'preventOverflow', options: { boundary: 'clippingParents' } },\n\n offsetModifier,\n\n /**\n * This modifier is necessary to retain behaviour from popper v1 where untethered poppers are allowed by\n * default. i.e. popper is still rendered fully in the viewport even if anchor element is no longer in the\n * viewport.\n */\n unstable_disableTether && {\n name: 'preventOverflow',\n options: { altAxis: unstable_disableTether === 'all', tether: false },\n },\n\n flipBoundary && {\n name: 'flip',\n options: {\n altBoundary: true,\n boundary: getBoundary(container, flipBoundary),\n },\n },\n overflowBoundary && {\n name: 'preventOverflow',\n options: {\n altBoundary: true,\n boundary: getBoundary(container, overflowBoundary),\n },\n },\n\n {\n // Similar code as popper-maxsize-modifier: https://github.com/atomiks/popper.js/blob/master/src/modifiers/maxSize.js\n // popper-maxsize-modifier only calculates the max sizes.\n // This modifier can apply max sizes always, or apply the max sizes only when overflow is detected\n name: 'applyMaxSize',\n enabled: !!autoSize,\n phase: 'beforeWrite' as PopperJs.ModifierPhases,\n requiresIfExists: ['offset', 'preventOverflow', 'flip'],\n options: {\n altBoundary: true,\n boundary: getBoundary(container, overflowBoundary),\n },\n fn({ state, options: modifierOptions }: PopperJs.ModifierArguments<{}>) {\n const overflow = PopperJs.detectOverflow(state, modifierOptions);\n const { x, y } = state.modifiersData.preventOverflow || { x: 0, y: 0 };\n const { width, height } = state.rects.popper;\n const basePlacement = parsePopperPlacement(state.placement).basePlacement;\n\n const widthProp: keyof PopperJs.SideObject = basePlacement === 'left' ? 'left' : 'right';\n const heightProp: keyof PopperJs.SideObject = basePlacement === 'top' ? 'top' : 'bottom';\n\n const applyMaxWidth =\n autoSize === 'always' ||\n autoSize === 'width-always' ||\n (overflow[widthProp] > 0 && (autoSize === true || autoSize === 'width'));\n const applyMaxHeight =\n autoSize === 'always' ||\n autoSize === 'height-always' ||\n (overflow[heightProp] > 0 && (autoSize === true || autoSize === 'height'));\n\n if (applyMaxWidth) {\n state.styles.popper.maxWidth = `${width - overflow[widthProp] - x}px`;\n }\n if (applyMaxHeight) {\n state.styles.popper.maxHeight = `${height - overflow[heightProp] - y}px`;\n }\n },\n },\n\n /**\n * This modifier is necessary in order to render the pointer. Refs are resolved in effects, so it can't be\n * placed under computed modifiers. Deep merge is not required as this modifier has only these properties.\n */\n {\n name: 'arrow',\n enabled: !!arrow,\n options: { element: arrow, padding: arrowPadding },\n },\n\n /**\n * Modifies popper offsets to cover the reference rect, but still keep edge alignment\n */\n {\n name: 'coverTarget',\n enabled: !!coverTarget,\n phase: 'main',\n requiresIfExists: ['offset', 'preventOverflow', 'flip'],\n fn({ state }: PopperJs.ModifierArguments<{}>) {\n const basePlacement = parsePopperPlacement(state.placement).basePlacement;\n switch (basePlacement) {\n case 'bottom':\n state.modifiersData.popperOffsets!.y -= state.rects.reference.height;\n break;\n case 'top':\n state.modifiersData.popperOffsets!.y += state.rects.reference.height;\n break;\n case 'left':\n state.modifiersData.popperOffsets!.x += state.rects.reference.width;\n break;\n case 'right':\n state.modifiersData.popperOffsets!.x -= state.rects.reference.width;\n break;\n }\n },\n },\n ].filter(Boolean) as PopperJs.Options['modifiers']; // filter boolean conditional spreading values\n\n const popperOptions: PopperJs.Options = {\n modifiers,\n\n placement,\n strategy,\n };\n\n return popperOptions;\n },\n [\n arrowPadding,\n autoSize,\n coverTarget,\n flipBoundary,\n offsetModifier,\n overflowBoundary,\n placement,\n strategy,\n unstable_disableTether,\n pinned,\n\n // These can be skipped from deps as they will not ever change\n popperOriginalPositionRef,\n ],\n );\n}\n\n/**\n * Exposes Popper positioning API via React hook. Contains few important differences between an official \"react-popper\"\n * package:\n * - style attributes are applied directly on DOM to avoid re-renders\n * - refs changes and resolution is handled properly without re-renders\n * - contains a specific to React fix related to initial positioning when containers have components with managed focus\n * to avoid focus jumps\n */\nexport function usePositioning(\n options: UsePopperOptions = {},\n): {\n // React refs are supposed to be contravariant\n // (allows a more general type to be passed rather than a more specific one)\n // However, Typescript currently can't infer that fact for refs\n // See https://github.com/microsoft/TypeScript/issues/30748 for more information\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n targetRef: React.MutableRefObject<any>;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n containerRef: React.MutableRefObject<any>;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n arrowRef: React.MutableRefObject<any>;\n} {\n const { enabled = true } = options;\n const isFirstMount = useFirstMount();\n\n const popperOriginalPositionRef = React.useRef<string>('absolute');\n const resolvePopperOptions = usePopperOptions(options, popperOriginalPositionRef);\n\n const popperInstanceRef = React.useRef<PopperInstance | null>(null);\n\n const handlePopperUpdate = useEventCallback(() => {\n popperInstanceRef.current?.destroy();\n popperInstanceRef.current = null;\n\n const target = overrideTargetRef.current ?? targetRef.current;\n\n let popperInstance: PopperInstance | null = null;\n\n if (canUseDOM() && enabled) {\n if (target && containerRef.current) {\n popperInstance = PopperJs.createPopper(\n target,\n containerRef.current,\n resolvePopperOptions(target, containerRef.current, arrowRef.current),\n );\n }\n }\n\n if (popperInstance) {\n /**\n * The patch updates `.forceUpdate()` Popper function which restores the original position before the first\n * forceUpdate() call. See also \"positionStyleFix\" modifier in usePopperOptions().\n */\n const originalForceUpdate = popperInstance.forceUpdate;\n\n popperInstance.isFirstRun = true;\n popperInstance.forceUpdate = () => {\n if (popperInstance?.isFirstRun) {\n popperInstance.state.elements.popper.style.position = popperOriginalPositionRef.current;\n popperInstance.isFirstRun = false;\n }\n\n originalForceUpdate();\n };\n }\n\n popperInstanceRef.current = popperInstance;\n });\n\n // Refs are managed by useCallbackRef() to handle ref updates scenarios.\n //\n // The first scenario are updates for a targetRef, we can handle it properly only via callback refs, but it causes\n // re-renders (we would like to avoid them).\n //\n // The second problem is related to refs resolution on React's layer: refs are resolved in the same order as effects\n // that causes an issue when you have a container inside a target, for example: a menu in ChatMessage.\n //\n // function ChatMessage(props) {\n // <div className=\"message\" ref={targetRef}> // 3) ref will be resolved only now, but it's too late already\n // <Popper target={targetRef}> // 2) create a popper instance\n // <div className=\"menu\" /> // 1) capture ref from this element\n // </Popper>\n // </div>\n // }\n //\n // Check a demo on CodeSandbox: https://codesandbox.io/s/popper-refs-emy60.\n //\n // This again can be solved with callback refs. It's not a huge issue as with hooks we are moving popper's creation\n // to ChatMessage itself, however, without `useCallback()` refs it's still a Pandora box.\n const targetRef = useCallbackRef<HTMLElement | PopperJs.VirtualElement | null>(null, handlePopperUpdate, true);\n const containerRef = useCallbackRef<HTMLElement | null>(null, handlePopperUpdate, true);\n const arrowRef = useCallbackRef<HTMLElement | null>(null, handlePopperUpdate, true);\n\n // Stores external target from options.target or setTarget\n const overrideTargetRef = useCallbackRef<HTMLElement | PositioningVirtualElement | null>(\n null,\n handlePopperUpdate,\n true,\n );\n\n React.useImperativeHandle(\n options.positioningRef,\n () => ({\n updatePosition: () => {\n popperInstanceRef.current?.update();\n },\n setTarget: (target: HTMLElement | PositioningVirtualElement) => {\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 overrideTargetRef.current = target;\n },\n }),\n // Missing deps:\n // options.target - only used for a runtime warning\n // targetRef - Stable between renders\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [],\n );\n\n useIsomorphicLayoutEffect(() => {\n if (options.target) {\n overrideTargetRef.current = options.target;\n }\n }, [options.target, overrideTargetRef]);\n useIsomorphicLayoutEffect(() => {\n handlePopperUpdate();\n\n return () => {\n popperInstanceRef.current?.destroy();\n popperInstanceRef.current = null;\n };\n }, [handlePopperUpdate, options.enabled]);\n useIsomorphicLayoutEffect(\n () => {\n if (!isFirstMount) {\n popperInstanceRef.current?.setOptions(\n resolvePopperOptions(overrideTargetRef.current ?? targetRef.current, containerRef.current, arrowRef.current),\n );\n }\n },\n // Missing deps:\n // isFirstMount - Should never change after mount\n // arrowRef, containerRef, targetRef - Stable between renders\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [resolvePopperOptions],\n );\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 return { targetRef, containerRef, arrowRef };\n}\n"],"sourceRoot":"../src/"}
@@ -0,0 +1,40 @@
1
+ import * as React from 'react';
2
+ import { createVirtualElementFromClick } from './createVirtualElementFromClick';
3
+ /**
4
+ * A state hook that manages a popper virtual element from mouseevents.
5
+ * Useful for scenarios where a component needs to be positioned by mouse click (e.g. contextmenu)
6
+ * React synthetic events are not persisted by this hook
7
+ *
8
+ * @param initialState - initializes a user provided state similare to useState
9
+ * @returns state and dispatcher for a Popper virtual element that uses native/synthetic mouse events
10
+ */
11
+
12
+ export const usePositioningMouseTarget = initialState => {
13
+ const [virtualElement, setVirtualElement] = React.useState(initialState);
14
+
15
+ const setVirtualMouseTarget = event => {
16
+ if (event === undefined || event === null) {
17
+ setVirtualElement(undefined);
18
+ return;
19
+ }
20
+
21
+ let mouseevent;
22
+
23
+ if (!(event instanceof MouseEvent)) {
24
+ mouseevent = event.nativeEvent;
25
+ } else {
26
+ mouseevent = event;
27
+ }
28
+
29
+ if (!(mouseevent instanceof MouseEvent) && process.env.NODE_ENV !== 'production') {
30
+ // eslint-disable-next-line no-console
31
+ console.error('usePositioningMouseTarget should only be used with MouseEvent');
32
+ }
33
+
34
+ const contextTarget = createVirtualElementFromClick(mouseevent);
35
+ setVirtualElement(contextTarget);
36
+ };
37
+
38
+ return [virtualElement, setVirtualMouseTarget];
39
+ };
40
+ //# sourceMappingURL=usePositioningMouseTarget.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["usePositioningMouseTarget.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SAAS,6BAAT,QAA8C,iCAA9C;AAGA;;;;;;;AAOG;;AACH,OAAO,MAAM,yBAAyB,GACpC,YADuC,IAErC;AACF,QAAM,CAAC,cAAD,EAAiB,iBAAjB,IAAsC,KAAK,CAAC,QAAN,CAAsD,YAAtD,CAA5C;;AAEA,QAAM,qBAAqB,GAAI,KAAD,IAA4D;AACxF,QAAI,KAAK,KAAK,SAAV,IAAuB,KAAK,KAAK,IAArC,EAA2C;AACzC,MAAA,iBAAiB,CAAC,SAAD,CAAjB;AACA;AACD;;AAED,QAAI,UAAJ;;AACA,QAAI,EAAE,KAAK,YAAY,UAAnB,CAAJ,EAAoC;AAClC,MAAA,UAAU,GAAG,KAAK,CAAC,WAAnB;AACD,KAFD,MAEO;AACL,MAAA,UAAU,GAAG,KAAb;AACD;;AAED,QAAI,EAAE,UAAU,YAAY,UAAxB,KAAuC,OAAO,CAAC,GAAR,CAAY,QAAZ,KAAyB,YAApE,EAAkF;AAChF;AACA,MAAA,OAAO,CAAC,KAAR,CAAc,+DAAd;AACD;;AAED,UAAM,aAAa,GAAG,6BAA6B,CAAC,UAAD,CAAnD;AACA,IAAA,iBAAiB,CAAC,aAAD,CAAjB;AACD,GApBD;;AAsBA,SAAO,CAAC,cAAD,EAAiB,qBAAjB,CAAP;AACD,CA5BM","sourcesContent":["import * as React from 'react';\nimport { createVirtualElementFromClick } from './createVirtualElementFromClick';\nimport { PositioningVirtualElement } from './types';\n\n/**\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 = (event: React.MouseEvent | MouseEvent | undefined | null) => {\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"],"sourceRoot":"../src/"}
@@ -0,0 +1,40 @@
1
+ import { parsePopperPlacement } from './parsePopperPlacement';
2
+ const positionMap = {
3
+ top: 'above',
4
+ bottom: 'below',
5
+ right: 'after',
6
+ left: 'before'
7
+ };
8
+
9
+ const getAlignmentMap = position => {
10
+ if (position === 'above' || position === 'below') {
11
+ return {
12
+ start: 'start',
13
+ end: 'end'
14
+ };
15
+ }
16
+
17
+ return {
18
+ start: 'top',
19
+ end: 'bottom'
20
+ };
21
+ };
22
+ /**
23
+ * Maps Popper.js placement to positioning values
24
+ * @see positioningHelper.test.ts for expected placement values
25
+ */
26
+
27
+
28
+ export const fromPopperPlacement = placement => {
29
+ const {
30
+ basePlacement,
31
+ alignment: popperAlignment
32
+ } = parsePopperPlacement(placement);
33
+ const position = positionMap[basePlacement];
34
+ const alignment = popperAlignment && getAlignmentMap(position)[popperAlignment];
35
+ return {
36
+ position,
37
+ alignment
38
+ };
39
+ };
40
+ //# sourceMappingURL=fromPopperPlacement.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["utils/fromPopperPlacement.ts"],"names":[],"mappings":"AAEA,SAAS,oBAAT,QAAqC,wBAArC;AAEA,MAAM,WAAW,GAAG;AAClB,EAAA,GAAG,EAAE,OADa;AAElB,EAAA,MAAM,EAAE,OAFU;AAGlB,EAAA,KAAK,EAAE,OAHW;AAIlB,EAAA,IAAI,EAAE;AAJY,CAApB;;AAOA,MAAM,eAAe,GAAI,QAAD,IAA2D;AACjF,MAAI,QAAQ,KAAK,OAAb,IAAwB,QAAQ,KAAK,OAAzC,EAAkD;AAChD,WAAO;AACL,MAAA,KAAK,EAAE,OADF;AAEL,MAAA,GAAG,EAAE;AAFA,KAAP;AAID;;AAED,SAAO;AACL,IAAA,KAAK,EAAE,KADF;AAEL,IAAA,GAAG,EAAE;AAFA,GAAP;AAID,CAZD;AAcA;;;AAGG;;;AACH,OAAO,MAAM,mBAAmB,GAAI,SAAD,IAAwE;AACzG,QAAM;AAAE,IAAA,aAAF;AAAiB,IAAA,SAAS,EAAE;AAA5B,MAAgD,oBAAoB,CAAC,SAAD,CAA1E;AACA,QAAM,QAAQ,GAAG,WAAW,CAAC,aAAD,CAA5B;AACA,QAAM,SAAS,GAAG,eAAe,IAAI,eAAe,CAAC,QAAD,CAAf,CAA0B,eAA1B,CAArC;AAEA,SAAO;AAAE,IAAA,QAAF;AAAY,IAAA;AAAZ,GAAP;AACD,CANM","sourcesContent":["import type { Variation as PopperAlignment, Placement } from '@popperjs/core';\nimport type { Alignment, Position } from '../types';\nimport { parsePopperPlacement } from './parsePopperPlacement';\n\nconst positionMap = {\n top: 'above',\n bottom: 'below',\n right: 'after',\n left: 'before',\n} as const;\n\nconst getAlignmentMap = (position: Position): Record<PopperAlignment, 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 Popper.js placement to positioning values\n * @see positioningHelper.test.ts for expected placement values\n */\nexport const fromPopperPlacement = (placement: Placement): { position: Position; alignment?: Alignment } => {\n const { basePlacement, alignment: popperAlignment } = parsePopperPlacement(placement);\n const position = positionMap[basePlacement];\n const alignment = popperAlignment && getAlignmentMap(position)[popperAlignment];\n\n return { position, alignment };\n};\n"],"sourceRoot":"../src/"}
@@ -2,17 +2,22 @@ import { getScrollParent } from './getScrollParent';
2
2
  /**
3
3
  * Allows to mimic a behavior from V1 of Popper and accept `window` and `scrollParent` as strings.
4
4
  */
5
+
5
6
  export function getBoundary(element, boundary) {
6
- if (boundary === 'window') {
7
- return element === null || element === void 0 ? void 0 : element.ownerDocument.documentElement;
7
+ if (boundary === 'window') {
8
+ return element === null || element === void 0 ? void 0 : element.ownerDocument.documentElement;
9
+ }
10
+
11
+ if (boundary === 'scrollParent') {
12
+ let boundariesNode = getScrollParent(element);
13
+
14
+ if (boundariesNode.nodeName === 'BODY') {
15
+ boundariesNode = element === null || element === void 0 ? void 0 : element.ownerDocument.documentElement;
8
16
  }
9
- if (boundary === 'scrollParent') {
10
- var boundariesNode = getScrollParent(element);
11
- if (boundariesNode.nodeName === 'BODY') {
12
- boundariesNode = element === null || element === void 0 ? void 0 : element.ownerDocument.documentElement;
13
- }
14
- return boundariesNode;
15
- }
16
- return boundary;
17
+
18
+ return boundariesNode;
19
+ }
20
+
21
+ return boundary;
17
22
  }
18
23
  //# sourceMappingURL=getBoundary.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"getBoundary.js","sourceRoot":"","sources":["../../src/utils/getBoundary.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAGpD;;GAEG;AACH,MAAM,UAAU,WAAW,CAAC,OAA2B,EAAE,QAAmB;IAC1E,IAAI,QAAQ,KAAK,QAAQ,EAAE;QACzB,OAAO,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,aAAa,CAAE,eAAe,CAAC;KAChD;IAED,IAAI,QAAQ,KAAK,cAAc,EAAE;QAC/B,IAAI,cAAc,GAA4B,eAAe,CAAC,OAAO,CAAC,CAAC;QAEvE,IAAI,cAAc,CAAC,QAAQ,KAAK,MAAM,EAAE;YACtC,cAAc,GAAG,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,aAAa,CAAE,eAAe,CAAC;SAC1D;QAED,OAAO,cAAc,CAAC;KACvB;IAED,OAAO,QAAQ,CAAC;AAClB,CAAC"}
1
+ {"version":3,"sources":["utils/getBoundary.ts"],"names":[],"mappings":"AAEA,SAAS,eAAT,QAAgC,mBAAhC;AAGA;;AAEG;;AACH,OAAM,SAAU,WAAV,CAAsB,OAAtB,EAAmD,QAAnD,EAAsE;AAC1E,MAAI,QAAQ,KAAK,QAAjB,EAA2B;AACzB,WAAO,OAAO,KAAA,IAAP,IAAA,OAAO,KAAA,KAAA,CAAP,GAAO,KAAA,CAAP,GAAA,OAAO,CAAE,aAAT,CAAwB,eAA/B;AACD;;AAED,MAAI,QAAQ,KAAK,cAAjB,EAAiC;AAC/B,QAAI,cAAc,GAA4B,eAAe,CAAC,OAAD,CAA7D;;AAEA,QAAI,cAAc,CAAC,QAAf,KAA4B,MAAhC,EAAwC;AACtC,MAAA,cAAc,GAAG,OAAO,KAAA,IAAP,IAAA,OAAO,KAAA,KAAA,CAAP,GAAO,KAAA,CAAP,GAAA,OAAO,CAAE,aAAT,CAAwB,eAAzC;AACD;;AAED,WAAO,cAAP;AACD;;AAED,SAAO,QAAP;AACD","sourcesContent":["import * as PopperJs from '@popperjs/core';\n\nimport { getScrollParent } from './getScrollParent';\nimport type { Boundary } from '../types';\n\n/**\n * Allows to mimic a behavior from V1 of Popper and accept `window` and `scrollParent` as strings.\n */\nexport function getBoundary(element: HTMLElement | null, boundary?: Boundary): PopperJs.Boundary | undefined {\n if (boundary === 'window') {\n return element?.ownerDocument!.documentElement;\n }\n\n if (boundary === 'scrollParent') {\n let boundariesNode: HTMLElement | undefined = getScrollParent(element);\n\n if (boundariesNode.nodeName === 'BODY') {\n boundariesNode = element?.ownerDocument!.documentElement;\n }\n\n return boundariesNode;\n }\n\n return boundary;\n}\n"],"sourceRoot":"../src/"}
@@ -0,0 +1,44 @@
1
+ import { fromPopperPlacement } from './fromPopperPlacement';
2
+ /**
3
+ * Shim to transform offset values from this library to Popper.js
4
+ * @param rawOffset Offset from this library
5
+ * @returns An offset value compatible with Popper.js
6
+ */
7
+
8
+ export function getPopperOffset(rawOffset) {
9
+ if (rawOffset === undefined || rawOffset === null) {
10
+ return rawOffset;
11
+ }
12
+
13
+ if (typeof rawOffset === 'number') {
14
+ return [0, rawOffset];
15
+ }
16
+
17
+ if (typeof rawOffset === 'object') {
18
+ return [rawOffset.crossAxis, rawOffset.mainAxis];
19
+ }
20
+
21
+ return ({
22
+ popper,
23
+ reference,
24
+ placement
25
+ }) => {
26
+ const {
27
+ position,
28
+ alignment
29
+ } = fromPopperPlacement(placement);
30
+ const computedOffset = rawOffset({
31
+ positionedRect: popper,
32
+ targetRect: reference,
33
+ position,
34
+ alignment
35
+ });
36
+
37
+ if (typeof computedOffset === 'number') {
38
+ return [0, computedOffset];
39
+ }
40
+
41
+ return [computedOffset.crossAxis, computedOffset.mainAxis];
42
+ };
43
+ }
44
+ //# sourceMappingURL=getPopperOffset.js.map