@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
@@ -1,68 +0,0 @@
1
- import * as PopperJs from '@popperjs/core';
2
- import * as React from 'react';
3
- export declare type OffsetFunctionParam = {
4
- popper: PopperJs.Rect;
5
- reference: PopperJs.Rect;
6
- placement: PopperJs.Placement;
7
- };
8
- export declare type OffsetFunction = (param: OffsetFunctionParam) => [number | null | undefined, number | null | undefined];
9
- export declare type Offset = OffsetFunction | [number | null | undefined, number | null | undefined];
10
- export declare type Position = 'above' | 'below' | 'before' | 'after';
11
- export declare type Alignment = 'top' | 'bottom' | 'start' | 'end' | 'center';
12
- export declare type AutoSize = 'height' | 'height-always' | 'width' | 'width-always' | 'always' | boolean;
13
- export declare type Boundary = PopperJs.Boundary | 'scrollParent' | 'window';
14
- export declare type PopperRefHandle = {
15
- updatePosition: () => void;
16
- };
17
- export declare type PopperVirtualElement = PopperJs.VirtualElement;
18
- export interface PositioningProps {
19
- /** Alignment for the component. Only has an effect if used with the @see position option */
20
- align?: Alignment;
21
- /** The element which will define the boundaries of the popper position for the flip behavior. */
22
- flipBoundary?: Boundary;
23
- /** The element which will define the boundaries of the popper position for the overflow behavior. */
24
- overflowBoundary?: Boundary;
25
- /** An imperative handle to Popper methods. */
26
- popperRef?: React.Ref<PopperRefHandle>;
27
- /**
28
- * Position for the component. Position has higher priority than align. If position is vertical ('above' | 'below')
29
- * and align is also vertical ('top' | 'bottom') or if both position and align are horizontal ('before' | 'after'
30
- * and 'start' | 'end' respectively),
31
- * then provided value for 'align' will be ignored and 'center' will be used instead.
32
- */
33
- position?: Position;
34
- /**
35
- * Lets you displace a popper element from its reference element.
36
- * This can be useful if you need to apply some margin between them or if you need to fine tune the
37
- * position according to some custom logic.
38
- */
39
- offset?: Offset;
40
- /**
41
- * Defines padding between the corner of the popup element and the arrow.
42
- * Use to prevent the arrow from overlapping a rounded corner, for example.
43
- */
44
- arrowPadding?: number;
45
- /**
46
- * Applies max-height and max-width on popper to fit it within the available space in viewport.
47
- * true enables this for both width and height when overflow happens.
48
- * 'always' applies `max-height`/`max-width` regardless of overflow.
49
- * 'height' applies `max-height` when overflow happens, and 'width' for `max-width`
50
- * `height-always` applies `max-height` regardless of overflow, and 'width-always' for always applying `max-width`
51
- */
52
- autoSize?: AutoSize;
53
- /**
54
- * Manual override for popper target. Useful for scenarios where a component accepts user prop to override target
55
- */
56
- target?: HTMLElement | PopperVirtualElement | null;
57
- /**
58
- * Modifies position and alignment to cover the target
59
- */
60
- coverTarget?: boolean;
61
- /**
62
- * Disables automatic repositioning of the component; it will always be placed according to the values of `align` and
63
- * `position` props, regardless of the size of the component, the reference element or the viewport.
64
- */
65
- pinned?: boolean;
66
- }
67
- export declare type PositioningShorthandValue = 'above' | 'above-start' | 'above-end' | 'below' | 'below-start' | 'below-end' | 'before' | 'before-top' | 'before-bottom' | 'after' | 'after-top' | 'after-bottom';
68
- export declare type PositioningShorthand = PositioningProps | PositioningShorthandValue;
@@ -1,35 +0,0 @@
1
- import * as PopperJs from '@popperjs/core';
2
- import * as React from 'react';
3
- import type { PositioningProps } from './types';
4
- interface PopperOptions extends PositioningProps {
5
- /**
6
- * If false, delays Popper's creation.
7
- * @default true
8
- */
9
- enabled?: boolean;
10
- onStateUpdate?: (state: Partial<PopperJs.State>) => void;
11
- /**
12
- * Enables the Popper box to position itself in 'fixed' mode (default value is position: 'absolute')
13
- * @default false
14
- */
15
- positionFixed?: boolean;
16
- /**
17
- * When the reference element or the viewport is outside viewport allows a popper element to be fully in viewport.
18
- * "all" enables this behavior for all axis.
19
- */
20
- unstable_disableTether?: boolean | 'all';
21
- }
22
- /**
23
- * Exposes Popper positioning API via React hook. Contains few important differences between an official "react-popper"
24
- * package:
25
- * - style attributes are applied directly on DOM to avoid re-renders
26
- * - refs changes and resolution is handled properly without re-renders
27
- * - contains a specific to React fix related to initial positioning when containers have components with managed focus
28
- * to avoid focus jumps
29
- */
30
- export declare function usePopper(options?: PopperOptions): {
31
- targetRef: React.MutableRefObject<any>;
32
- containerRef: React.MutableRefObject<any>;
33
- arrowRef: React.MutableRefObject<any>;
34
- };
35
- export {};
@@ -1,361 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.usePopper = void 0;
4
- var react_utilities_1 = require("@fluentui/react-utilities");
5
- var react_shared_contexts_1 = require("@fluentui/react-shared-contexts");
6
- var index_1 = require("./utils/index");
7
- var PopperJs = require("@popperjs/core");
8
- var React = require("react");
9
- //
10
- // Dev utils to detect if nodes have "autoFocus" props.
11
- //
12
- /**
13
- * Detects if a passed HTML node has "autoFocus" prop on a React's fiber. Is needed as React handles autofocus behavior
14
- * in React DOM and will not pass "autoFocus" to an actual HTML.
15
- */
16
- function hasAutofocusProp(node) {
17
- var _a;
18
- // https://github.com/facebook/react/blob/848bb2426e44606e0a55dfe44c7b3ece33772485/packages/react-dom/src/client/ReactDOMHostConfig.js#L157-L166
19
- var isAutoFocusableElement = node.nodeName === 'BUTTON' ||
20
- node.nodeName === 'INPUT' ||
21
- node.nodeName === 'SELECT' ||
22
- node.nodeName === 'TEXTAREA';
23
- if (isAutoFocusableElement) {
24
- return !!((_a = index_1.getReactFiberFromNode(node)) === null || _a === void 0 ? void 0 : _a.pendingProps.autoFocus);
25
- }
26
- return false;
27
- }
28
- function hasAutofocusFilter(node) {
29
- return hasAutofocusProp(node) ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP;
30
- }
31
- /**
32
- * Provides a callback to resolve Popper options, it's stable and should be used as a dependency to trigger updates
33
- * of Popper options.
34
- *
35
- * A callback is used there intentionally as some of Popper.js modifiers require DOM nodes (targer, container, arrow)
36
- * that can't be resolved properly during an initial rendering.
37
- */
38
- function usePopperOptions(options, popperOriginalPositionRef) {
39
- var arrowPadding = options.arrowPadding, autoSize = options.autoSize, coverTarget = options.coverTarget, flipBoundary = options.flipBoundary, offset = options.offset, onStateUpdate = options.onStateUpdate, overflowBoundary = options.overflowBoundary,
40
- // eslint-disable-next-line @typescript-eslint/naming-convention
41
- unstable_disableTether = options.unstable_disableTether, pinned = options.pinned;
42
- var isRtl = react_shared_contexts_1.useFluent().dir === 'rtl';
43
- var placement = index_1.getPlacement(options.align, options.position, isRtl);
44
- var strategy = options.positionFixed ? 'fixed' : 'absolute';
45
- var handleStateUpdate = react_utilities_1.useEventCallback(function (_a) {
46
- var state = _a.state;
47
- if (onStateUpdate) {
48
- onStateUpdate(state);
49
- }
50
- });
51
- var offsetModifier = React.useMemo(function () {
52
- return offset
53
- ? {
54
- name: 'offset',
55
- options: { offset: isRtl ? index_1.applyRtlToOffset(offset) : offset },
56
- }
57
- : null;
58
- }, [offset, isRtl]);
59
- return React.useCallback(function (target, container, arrow) {
60
- var _a;
61
- var scrollParentElement = index_1.getScrollParent(container);
62
- var hasScrollableElement = scrollParentElement
63
- ? scrollParentElement !== ((_a = scrollParentElement.ownerDocument) === null || _a === void 0 ? void 0 : _a.body)
64
- : false;
65
- var modifiers = [
66
- /**
67
- * We are setting the position to `fixed` in the first effect to prevent scroll jumps in case of the content
68
- * with managed focus. Modifier sets the position to `fixed` before all other modifier effects. Another part of
69
- * a patch modifies ".forceUpdate()" directly after a Popper will be created.
70
- */
71
- {
72
- name: 'positionStyleFix',
73
- enabled: true,
74
- phase: 'afterWrite',
75
- effect: function (_a) {
76
- var state = _a.state, instance = _a.instance;
77
- // ".isFirstRun" is a part of our patch, on a first evaluation it will "undefined"
78
- // should be disabled for subsequent runs as it breaks positioning for them
79
- if (instance.isFirstRun !== false) {
80
- popperOriginalPositionRef.current = state.elements.popper.style.position;
81
- state.elements.popper.style.position = 'fixed';
82
- }
83
- return function () { return undefined; };
84
- },
85
- requires: [],
86
- },
87
- { name: 'flip', options: { flipVariations: true } },
88
- /**
89
- * pinned disables the flip modifier by setting flip.enabled to false; this
90
- * disables automatic repositioning of the popper box; it will always be placed according to
91
- * the values of `align` and `position` props, regardless of the size of the component, the
92
- * reference element or the viewport.
93
- */
94
- pinned && { name: 'flip', enabled: false },
95
- /**
96
- * When the popper box is placed in the context of a scrollable element, we need to set
97
- * preventOverflow.escapeWithReference to true and flip.boundariesElement to 'scrollParent'
98
- * (default is 'viewport') so that the popper box will stick with the targetRef when we
99
- * scroll targetRef out of the viewport.
100
- */
101
- hasScrollableElement && { name: 'flip', options: { boundary: 'clippingParents' } },
102
- hasScrollableElement && { name: 'preventOverflow', options: { boundary: 'clippingParents' } },
103
- offsetModifier,
104
- /**
105
- * This modifier is necessary to retain behaviour from popper v1 where untethered poppers are allowed by
106
- * default. i.e. popper is still rendered fully in the viewport even if anchor element is no longer in the
107
- * viewport.
108
- */
109
- unstable_disableTether && {
110
- name: 'preventOverflow',
111
- options: { altAxis: unstable_disableTether === 'all', tether: false },
112
- },
113
- flipBoundary && {
114
- name: 'flip',
115
- options: {
116
- altBoundary: true,
117
- boundary: index_1.getBoundary(container, flipBoundary),
118
- },
119
- },
120
- overflowBoundary && {
121
- name: 'preventOverflow',
122
- options: {
123
- altBoundary: true,
124
- boundary: index_1.getBoundary(container, overflowBoundary),
125
- },
126
- },
127
- {
128
- name: 'onUpdate',
129
- enabled: true,
130
- phase: 'afterWrite',
131
- fn: handleStateUpdate,
132
- },
133
- {
134
- // Similar code as popper-maxsize-modifier: https://github.com/atomiks/popper.js/blob/master/src/modifiers/maxSize.js
135
- // popper-maxsize-modifier only calculates the max sizes.
136
- // This modifier can apply max sizes always, or apply the max sizes only when overflow is detected
137
- name: 'applyMaxSize',
138
- enabled: !!autoSize,
139
- phase: 'beforeWrite',
140
- requiresIfExists: ['offset', 'preventOverflow', 'flip'],
141
- options: {
142
- altBoundary: true,
143
- boundary: index_1.getBoundary(container, overflowBoundary),
144
- },
145
- fn: function (_a) {
146
- var state = _a.state, modifierOptions = _a.options;
147
- var overflow = PopperJs.detectOverflow(state, modifierOptions);
148
- var _b = state.modifiersData.preventOverflow || { x: 0, y: 0 }, x = _b.x, y = _b.y;
149
- var _c = state.rects.popper, width = _c.width, height = _c.height;
150
- var basePlacement = index_1.getBasePlacement(state.placement);
151
- var widthProp = basePlacement === 'left' ? 'left' : 'right';
152
- var heightProp = basePlacement === 'top' ? 'top' : 'bottom';
153
- var applyMaxWidth = autoSize === 'always' ||
154
- autoSize === 'width-always' ||
155
- (overflow[widthProp] > 0 && (autoSize === true || autoSize === 'width'));
156
- var applyMaxHeight = autoSize === 'always' ||
157
- autoSize === 'height-always' ||
158
- (overflow[heightProp] > 0 && (autoSize === true || autoSize === 'height'));
159
- if (applyMaxWidth) {
160
- state.styles.popper.maxWidth = width - overflow[widthProp] - x + "px";
161
- }
162
- if (applyMaxHeight) {
163
- state.styles.popper.maxHeight = height - overflow[heightProp] - y + "px";
164
- }
165
- },
166
- },
167
- /**
168
- * This modifier is necessary in order to render the pointer. Refs are resolved in effects, so it can't be
169
- * placed under computed modifiers. Deep merge is not required as this modifier has only these properties.
170
- */
171
- {
172
- name: 'arrow',
173
- enabled: !!arrow,
174
- options: { element: arrow, padding: arrowPadding },
175
- },
176
- /**
177
- * Modifies popper offsets to cover the reference rect, but still keep edge alignment
178
- */
179
- {
180
- name: 'coverTarget',
181
- enabled: !!coverTarget,
182
- phase: 'main',
183
- requiresIfExists: ['offset', 'preventOverflow', 'flip'],
184
- fn: function (_a) {
185
- var state = _a.state;
186
- var basePlacement = index_1.getBasePlacement(state.placement);
187
- switch (basePlacement) {
188
- case 'bottom':
189
- state.modifiersData.popperOffsets.y -= state.rects.reference.height;
190
- break;
191
- case 'top':
192
- state.modifiersData.popperOffsets.y += state.rects.reference.height;
193
- break;
194
- case 'left':
195
- state.modifiersData.popperOffsets.x += state.rects.reference.width;
196
- break;
197
- case 'right':
198
- state.modifiersData.popperOffsets.x -= state.rects.reference.width;
199
- break;
200
- }
201
- },
202
- },
203
- ].filter(Boolean); // filter boolean conditional spreading values
204
- var popperOptions = {
205
- modifiers: modifiers,
206
- placement: placement,
207
- strategy: strategy,
208
- onFirstUpdate: function (state) { return handleStateUpdate({ state: state }); },
209
- };
210
- return popperOptions;
211
- }, [
212
- arrowPadding,
213
- autoSize,
214
- coverTarget,
215
- flipBoundary,
216
- offsetModifier,
217
- overflowBoundary,
218
- placement,
219
- strategy,
220
- unstable_disableTether,
221
- pinned,
222
- // These can be skipped from deps as they will not ever change
223
- handleStateUpdate,
224
- popperOriginalPositionRef,
225
- ]);
226
- }
227
- /**
228
- * Exposes Popper positioning API via React hook. Contains few important differences between an official "react-popper"
229
- * package:
230
- * - style attributes are applied directly on DOM to avoid re-renders
231
- * - refs changes and resolution is handled properly without re-renders
232
- * - contains a specific to React fix related to initial positioning when containers have components with managed focus
233
- * to avoid focus jumps
234
- */
235
- function usePopper(options) {
236
- if (options === void 0) { options = {}; }
237
- var _a = options.enabled, enabled = _a === void 0 ? true : _a;
238
- var isFirstMount = react_utilities_1.useFirstMount();
239
- var popperOriginalPositionRef = React.useRef('absolute');
240
- var resolvePopperOptions = usePopperOptions(options, popperOriginalPositionRef);
241
- var popperInstanceRef = React.useRef(null);
242
- var handlePopperUpdate = react_utilities_1.useEventCallback(function () {
243
- var _a;
244
- (_a = popperInstanceRef.current) === null || _a === void 0 ? void 0 : _a.destroy();
245
- popperInstanceRef.current = null;
246
- var _b = options.target, target = _b === void 0 ? targetRef.current : _b;
247
- var popperInstance = null;
248
- if (react_utilities_1.canUseDOM() && enabled) {
249
- if (target && containerRef.current) {
250
- popperInstance = PopperJs.createPopper(target, containerRef.current, resolvePopperOptions(target, containerRef.current, arrowRef.current));
251
- }
252
- }
253
- if (popperInstance) {
254
- /**
255
- * The patch updates `.forceUpdate()` Popper function which restores the original position before the first
256
- * forceUpdate() call. See also "positionStyleFix" modifier in usePopperOptions().
257
- */
258
- var originalForceUpdate_1 = popperInstance.forceUpdate;
259
- popperInstance.isFirstRun = true;
260
- popperInstance.forceUpdate = function () {
261
- if (popperInstance === null || popperInstance === void 0 ? void 0 : popperInstance.isFirstRun) {
262
- popperInstance.state.elements.popper.style.position = popperOriginalPositionRef.current;
263
- popperInstance.isFirstRun = false;
264
- }
265
- originalForceUpdate_1();
266
- };
267
- }
268
- popperInstanceRef.current = popperInstance;
269
- });
270
- // Refs are managed by useCallbackRef() to handle ref updates scenarios.
271
- //
272
- // The first scenario are updates for a targetRef, we can handle it properly only via callback refs, but it causes
273
- // re-renders (we would like to avoid them).
274
- //
275
- // The second problem is related to refs resolution on React's layer: refs are resolved in the same order as effects
276
- // that causes an issue when you have a container inside a target, for example: a menu in ChatMessage.
277
- //
278
- // function ChatMessage(props) {
279
- // <div className="message" ref={targetRef}> // 3) ref will be resolved only now, but it's too late already
280
- // <Popper target={targetRef}> // 2) create a popper instance
281
- // <div className="menu" /> // 1) capture ref from this element
282
- // </Popper>
283
- // </div>
284
- // }
285
- //
286
- // Check a demo on CodeSandbox: https://codesandbox.io/s/popper-refs-emy60.
287
- //
288
- // This again can be solved with callback refs. It's not a huge issue as with hooks we are moving popper's creation
289
- // to ChatMessage itself, however, without `useCallback()` refs it's still a Pandora box.
290
- var targetRef = index_1.useCallbackRef(null, handlePopperUpdate, true);
291
- var containerRef = index_1.useCallbackRef(null, handlePopperUpdate, true);
292
- var arrowRef = index_1.useCallbackRef(null, handlePopperUpdate, true);
293
- React.useImperativeHandle(options.popperRef, function () { return ({
294
- updatePosition: function () {
295
- var _a;
296
- (_a = popperInstanceRef.current) === null || _a === void 0 ? void 0 : _a.update();
297
- },
298
- }); }, []);
299
- react_utilities_1.useIsomorphicLayoutEffect(function () {
300
- handlePopperUpdate();
301
- return function () {
302
- var _a;
303
- (_a = popperInstanceRef.current) === null || _a === void 0 ? void 0 : _a.destroy();
304
- popperInstanceRef.current = null;
305
- };
306
- }, [handlePopperUpdate, options.enabled, options.target]);
307
- react_utilities_1.useIsomorphicLayoutEffect(function () {
308
- var _a;
309
- if (!isFirstMount) {
310
- (_a = popperInstanceRef.current) === null || _a === void 0 ? void 0 : _a.setOptions(resolvePopperOptions(options.target || targetRef.current, containerRef.current, arrowRef.current));
311
- }
312
- },
313
- // Missing deps:
314
- // options.target - The useIsomorphicLayoutEffect before this will create a new popper instance if target changes
315
- // isFirstMount - Should never change after mount
316
- // arrowRef, containerRef, targetRef - Stable between renders
317
- // eslint-disable-next-line react-hooks/exhaustive-deps
318
- [resolvePopperOptions]);
319
- if (process.env.NODE_ENV !== 'production') {
320
- // This checked should run only in development mode
321
- // eslint-disable-next-line react-hooks/rules-of-hooks
322
- React.useEffect(function () {
323
- var _a;
324
- if (containerRef.current) {
325
- var contentNode = containerRef.current;
326
- var treeWalker = (_a = contentNode.ownerDocument) === null || _a === void 0 ? void 0 : _a.createTreeWalker(contentNode, NodeFilter.SHOW_ELEMENT, {
327
- acceptNode: hasAutofocusFilter,
328
- });
329
- while (treeWalker === null || treeWalker === void 0 ? void 0 : treeWalker.nextNode()) {
330
- var node = treeWalker.currentNode;
331
- // eslint-disable-next-line no-console
332
- console.warn('<Popper>:', node);
333
- // eslint-disable-next-line no-console
334
- console.warn([
335
- '<Popper>: ^ this node contains "autoFocus" prop on a React element. This can break the initial',
336
- 'positioning of an element and cause a window jump effect. This issue occurs because React polyfills',
337
- '"autoFocus" behavior to solve inconsistencies between different browsers:',
338
- 'https://github.com/facebook/react/issues/11851#issuecomment-351787078',
339
- '\n',
340
- 'However, ".focus()" in this case occurs before any other React effects will be executed',
341
- '(React.useEffect(), componentDidMount(), etc.) and we can not prevent this behavior. If you really',
342
- 'want to use "autoFocus" please add "position: fixed" to styles of the element that is wrapped by',
343
- '"Popper".',
344
- "In general, it's not recommended to use \"autoFocus\" as it may break accessibility aspects:",
345
- 'https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/master/docs/rules/no-autofocus.md',
346
- '\n',
347
- 'We suggest to use the "trapFocus" prop on Fluent components or a catch "ref" and then use',
348
- '"ref.current.focus" in React.useEffect():',
349
- 'https://reactjs.org/docs/refs-and-the-dom.html#adding-a-ref-to-a-dom-element',
350
- ].join(' '));
351
- }
352
- }
353
- // We run this check once, no need to add deps here
354
- // TODO: Should be rework to handle options.enabled and contentRef updates
355
- // eslint-disable-next-line react-hooks/exhaustive-deps
356
- }, []);
357
- }
358
- return { targetRef: targetRef, containerRef: containerRef, arrowRef: arrowRef };
359
- }
360
- exports.usePopper = usePopper;
361
- //# sourceMappingURL=usePopper.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"usePopper.js","sourceRoot":"","sources":["../src/usePopper.ts"],"names":[],"mappings":";;;AAAA,6DAAkH;AAClH,yEAA4D;AAC5D,uCAQuB;AACvB,yCAA2C;AAC3C,6BAA+B;AA4B/B,EAAE;AACF,uDAAuD;AACvD,EAAE;AAEF;;;GAGG;AACH,SAAS,gBAAgB,CAAC,IAAU;;IAClC,gJAAgJ;IAChJ,IAAM,sBAAsB,GAC1B,IAAI,CAAC,QAAQ,KAAK,QAAQ;QAC1B,IAAI,CAAC,QAAQ,KAAK,OAAO;QACzB,IAAI,CAAC,QAAQ,KAAK,QAAQ;QAC1B,IAAI,CAAC,QAAQ,KAAK,UAAU,CAAC;IAE/B,IAAI,sBAAsB,EAAE;QAC1B,OAAO,CAAC,QAAC,6BAAqB,CAAC,IAAI,CAAC,0CAAE,YAAY,CAAC,SAAS,CAAA,CAAC;KAC9D;IAED,OAAO,KAAK,CAAC;AACf,CAAC;AAED,SAAS,kBAAkB,CAAC,IAAU;IACpC,OAAO,gBAAgB,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,aAAa,CAAC,CAAC,CAAC,UAAU,CAAC,WAAW,CAAC;AACpF,CAAC;AAED;;;;;;GAMG;A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,CAAC,EAAE,EAAE,CAAC,CAAC;KACR;IAED,OAAO,EAAE,SAAS,WAAA,EAAE,YAAY,cAAA,EAAE,QAAQ,UAAA,EAAE,CAAC;AAC/C,CAAC;AAlKD,8BAkKC"}
@@ -1,11 +0,0 @@
1
- import * as React from 'react';
2
- import * as PopperJs from '@popperjs/core';
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
- export declare const usePopperMouseTarget: (initialState?: PopperJs.VirtualElement | (() => PopperJs.VirtualElement) | undefined) => readonly [PopperJs.VirtualElement | undefined, (event: React.MouseEvent | MouseEvent | undefined | null) => void];
@@ -1,38 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.usePopperMouseTarget = void 0;
4
- var React = require("react");
5
- var createVirtualElementFromClick_1 = require("./createVirtualElementFromClick");
6
- /**
7
- * A state hook that manages a popper virtual element from mouseevents.
8
- * Useful for scenarios where a component needs to be positioned by mouse click (e.g. contextmenu)
9
- * React synthetic events are not persisted by this hook
10
- *
11
- * @param initialState - initializes a user provided state similare to useState
12
- * @returns state and dispatcher for a Popper virtual element that uses native/synthetic mouse events
13
- */
14
- var usePopperMouseTarget = function (initialState) {
15
- var _a = React.useState(initialState), virtualElement = _a[0], setVirtualElement = _a[1];
16
- var setVirtualMouseTarget = function (event) {
17
- if (event === undefined || event === null) {
18
- setVirtualElement(undefined);
19
- return;
20
- }
21
- var mouseevent;
22
- if (!(event instanceof MouseEvent)) {
23
- mouseevent = event.nativeEvent;
24
- }
25
- else {
26
- mouseevent = event;
27
- }
28
- if (!(mouseevent instanceof MouseEvent) && process.env.NODE_ENV !== 'production') {
29
- // eslint-disable-next-line no-console
30
- console.error('usePopperMouseTarget should only be used with MouseEvent');
31
- }
32
- var contextTarget = createVirtualElementFromClick_1.createVirtualElementFromClick(mouseevent);
33
- setVirtualElement(contextTarget);
34
- };
35
- return [virtualElement, setVirtualMouseTarget];
36
- };
37
- exports.usePopperMouseTarget = usePopperMouseTarget;
38
- //# sourceMappingURL=usePopperMouseTarget.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"usePopperMouseTarget.js","sourceRoot":"","sources":["../src/usePopperMouseTarget.ts"],"names":[],"mappings":";;;AAAA,6BAA+B;AAC/B,iFAAgF;AAGhF;;;;;;;GAOG;AACI,IAAM,oBAAoB,GAAG,UAAC,YAAwE;IACrG,IAAA,KAAsC,KAAK,CAAC,QAAQ,CAAsC,YAAY,CAAC,EAAtG,cAAc,QAAA,EAAE,iBAAiB,QAAqE,CAAC;IAE9G,IAAM,qBAAqB,GAAG,UAAC,KAAuD;QACpF,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,IAAI,EAAE;YACzC,iBAAiB,CAAC,SAAS,CAAC,CAAC;YAC7B,OAAO;SACR;QAED,IAAI,UAAsB,CAAC;QAC3B,IAAI,CAAC,CAAC,KAAK,YAAY,UAAU,CAAC,EAAE;YAClC,UAAU,GAAG,KAAK,CAAC,WAAW,CAAC;SAChC;aAAM;YACL,UAAU,GAAG,KAAK,CAAC;SACpB;QAED,IAAI,CAAC,CAAC,UAAU,YAAY,UAAU,CAAC,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,EAAE;YAChF,sCAAsC;YACtC,OAAO,CAAC,KAAK,CAAC,0DAA0D,CAAC,CAAC;SAC3E;QAED,IAAM,aAAa,GAAG,6DAA6B,CAAC,UAAU,CAAC,CAAC;QAChE,iBAAiB,CAAC,aAAa,CAAC,CAAC;IACnC,CAAC,CAAC;IAEF,OAAO,CAAC,cAAc,EAAE,qBAAqB,CAAU,CAAC;AAC1D,CAAC,CAAC;AA1BW,QAAA,oBAAoB,wBA0B/B"}
@@ -1,8 +0,0 @@
1
- import * as PopperJs from '@popperjs/core';
2
- /**
3
- * Returns the base placement value
4
- * @param placement - the popper placement (i.e. bottom-start)
5
- *
6
- * @returns bottom-start -> bottom
7
- */
8
- export declare function getBasePlacement(placement: PopperJs.Placement): PopperJs.BasePlacement;
@@ -1,14 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getBasePlacement = void 0;
4
- /**
5
- * Returns the base placement value
6
- * @param placement - the popper placement (i.e. bottom-start)
7
- *
8
- * @returns bottom-start -> bottom
9
- */
10
- function getBasePlacement(placement) {
11
- return placement.split('-')[0];
12
- }
13
- exports.getBasePlacement = getBasePlacement;
14
- //# sourceMappingURL=getBasePlacement.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"getBasePlacement.js","sourceRoot":"","sources":["../../src/utils/getBasePlacement.ts"],"names":[],"mappings":";;;AAEA;;;;;GAKG;AACH,SAAgB,gBAAgB,CAAC,SAA6B;IAC5D,OAAO,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAA2B,CAAC;AAC3D,CAAC;AAFD,4CAEC"}
@@ -1,6 +0,0 @@
1
- import * as PopperJs from '@popperjs/core';
2
- import type { Boundary } from '../types';
3
- /**
4
- * Allows to mimic a behavior from V1 of Popper and accept `window` and `scrollParent` as strings.
5
- */
6
- export declare function getBoundary(element: HTMLElement | null, boundary?: Boundary): PopperJs.Boundary | undefined;