@fluentui/react-positioning 9.0.0-nightly.f81b28ceb3.1 → 9.0.0-rc.11
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.json +494 -10
- package/CHANGELOG.md +221 -71
- package/dist/index.d.ts +247 -0
- package/{lib → dist}/tsdoc-metadata.json +0 -0
- package/lib/createArrowStyles.js +87 -0
- package/lib/createArrowStyles.js.map +1 -0
- package/lib/createVirtualElementFromClick.js +19 -15
- package/lib/createVirtualElementFromClick.js.map +1 -1
- package/lib/index.js +4 -4
- package/lib/index.js.map +1 -1
- package/lib/isIntersectingModifier.js +26 -0
- package/lib/isIntersectingModifier.js.map +1 -0
- package/lib/types.js.map +1 -1
- package/lib/usePositioning.js +408 -0
- package/lib/usePositioning.js.map +1 -0
- package/lib/usePositioningMouseTarget.js +40 -0
- package/lib/usePositioningMouseTarget.js.map +1 -0
- package/lib/utils/fromPopperPlacement.js +40 -0
- package/lib/utils/fromPopperPlacement.js.map +1 -0
- package/lib/utils/getBoundary.js +15 -10
- package/lib/utils/getBoundary.js.map +1 -1
- package/lib/utils/getPopperOffset.js +44 -0
- package/lib/utils/getPopperOffset.js.map +1 -0
- package/lib/utils/getReactFiberFromNode.js +39 -35
- package/lib/utils/getReactFiberFromNode.js.map +1 -1
- package/lib/utils/getScrollParent.js +46 -32
- package/lib/utils/getScrollParent.js.map +1 -1
- package/lib/utils/index.js +1 -1
- package/lib/utils/index.js.map +1 -1
- package/lib/utils/mergeArrowOffset.js +31 -25
- package/lib/utils/mergeArrowOffset.js.map +1 -1
- package/lib/utils/parsePopperPlacement.js +14 -0
- package/lib/utils/parsePopperPlacement.js.map +1 -0
- package/lib/utils/positioningHelper.js +42 -34
- package/lib/utils/positioningHelper.js.map +1 -1
- package/lib/utils/resolvePositioningShorthand.js +58 -20
- package/lib/utils/resolvePositioningShorthand.js.map +1 -1
- package/lib/utils/useCallbackRef.js +35 -29
- package/lib/utils/useCallbackRef.js.map +1 -1
- package/lib-commonjs/createArrowStyles.js +100 -0
- package/lib-commonjs/createArrowStyles.js.map +1 -0
- package/lib-commonjs/createVirtualElementFromClick.js +25 -16
- package/lib-commonjs/createVirtualElementFromClick.js.map +1 -1
- package/lib-commonjs/index.js +62 -10
- package/lib-commonjs/index.js.map +1 -1
- package/lib-commonjs/isIntersectingModifier.js +34 -0
- package/lib-commonjs/isIntersectingModifier.js.map +1 -0
- package/lib-commonjs/types.js +4 -1
- package/lib-commonjs/types.js.map +1 -1
- package/lib-commonjs/usePositioning.js +424 -0
- package/lib-commonjs/usePositioning.js.map +1 -0
- package/lib-commonjs/usePositioningMouseTarget.js +51 -0
- package/lib-commonjs/usePositioningMouseTarget.js.map +1 -0
- package/lib-commonjs/utils/fromPopperPlacement.js +50 -0
- package/lib-commonjs/utils/fromPopperPlacement.js.map +1 -0
- package/lib-commonjs/utils/getBoundary.js +23 -12
- package/lib-commonjs/utils/getBoundary.js.map +1 -1
- package/lib-commonjs/utils/getPopperOffset.js +54 -0
- package/lib-commonjs/utils/getPopperOffset.js.map +1 -0
- package/lib-commonjs/utils/getReactFiberFromNode.js +44 -36
- package/lib-commonjs/utils/getReactFiberFromNode.js.map +1 -1
- package/lib-commonjs/utils/getScrollParent.js +53 -33
- package/lib-commonjs/utils/getScrollParent.js.map +1 -1
- package/lib-commonjs/utils/index.js +15 -3
- package/lib-commonjs/utils/index.js.map +1 -1
- package/lib-commonjs/utils/mergeArrowOffset.js +37 -26
- package/lib-commonjs/utils/mergeArrowOffset.js.map +1 -1
- package/lib-commonjs/utils/parsePopperPlacement.js +23 -0
- package/lib-commonjs/utils/parsePopperPlacement.js.map +1 -0
- package/lib-commonjs/utils/positioningHelper.js +50 -35
- package/lib-commonjs/utils/positioningHelper.js.map +1 -1
- package/lib-commonjs/utils/resolvePositioningShorthand.js +66 -23
- package/lib-commonjs/utils/resolvePositioningShorthand.js.map +1 -1
- package/lib-commonjs/utils/useCallbackRef.js +45 -32
- package/lib-commonjs/utils/useCallbackRef.js.map +1 -1
- package/package.json +17 -14
- package/dist/react-positioning.d.ts +0 -143
- package/lib/createVirtualElementFromClick.d.ts +0 -6
- package/lib/index.d.ts +0 -5
- package/lib/types.d.ts +0 -68
- package/lib/usePopper.d.ts +0 -35
- package/lib/usePopper.js +0 -357
- package/lib/usePopper.js.map +0 -1
- package/lib/usePopperMouseTarget.d.ts +0 -11
- package/lib/usePopperMouseTarget.js +0 -34
- package/lib/usePopperMouseTarget.js.map +0 -1
- package/lib/utils/getBasePlacement.d.ts +0 -8
- package/lib/utils/getBasePlacement.js +0 -10
- package/lib/utils/getBasePlacement.js.map +0 -1
- package/lib/utils/getBoundary.d.ts +0 -6
- package/lib/utils/getReactFiberFromNode.d.ts +0 -109
- package/lib/utils/getScrollParent.d.ts +0 -12
- package/lib/utils/index.d.ts +0 -8
- package/lib/utils/mergeArrowOffset.d.ts +0 -10
- package/lib/utils/positioningHelper.d.ts +0 -7
- package/lib/utils/resolvePositioningShorthand.d.ts +0 -2
- package/lib/utils/useCallbackRef.d.ts +0 -19
- package/lib-commonjs/createVirtualElementFromClick.d.ts +0 -6
- package/lib-commonjs/index.d.ts +0 -5
- package/lib-commonjs/types.d.ts +0 -68
- package/lib-commonjs/usePopper.d.ts +0 -35
- package/lib-commonjs/usePopper.js +0 -361
- package/lib-commonjs/usePopper.js.map +0 -1
- package/lib-commonjs/usePopperMouseTarget.d.ts +0 -11
- package/lib-commonjs/usePopperMouseTarget.js +0 -38
- package/lib-commonjs/usePopperMouseTarget.js.map +0 -1
- package/lib-commonjs/utils/getBasePlacement.d.ts +0 -8
- package/lib-commonjs/utils/getBasePlacement.js +0 -14
- package/lib-commonjs/utils/getBasePlacement.js.map +0 -1
- package/lib-commonjs/utils/getBoundary.d.ts +0 -6
- package/lib-commonjs/utils/getReactFiberFromNode.d.ts +0 -109
- package/lib-commonjs/utils/getScrollParent.d.ts +0 -12
- package/lib-commonjs/utils/index.d.ts +0 -8
- package/lib-commonjs/utils/mergeArrowOffset.d.ts +0 -10
- package/lib-commonjs/utils/positioningHelper.d.ts +0 -7
- package/lib-commonjs/utils/resolvePositioningShorthand.d.ts +0 -2
- package/lib-commonjs/utils/useCallbackRef.d.ts +0 -19
package/lib/usePopper.js
DELETED
@@ -1,357 +0,0 @@
|
|
1
|
-
import { useEventCallback, useIsomorphicLayoutEffect, useFirstMount, canUseDOM } from '@fluentui/react-utilities';
|
2
|
-
import { useFluent } from '@fluentui/react-shared-contexts';
|
3
|
-
import { getScrollParent, applyRtlToOffset, getPlacement, getReactFiberFromNode, getBoundary, useCallbackRef, getBasePlacement, } from './utils/index';
|
4
|
-
import * as PopperJs from '@popperjs/core';
|
5
|
-
import * as React from 'react';
|
6
|
-
//
|
7
|
-
// Dev utils to detect if nodes have "autoFocus" props.
|
8
|
-
//
|
9
|
-
/**
|
10
|
-
* Detects if a passed HTML node has "autoFocus" prop on a React's fiber. Is needed as React handles autofocus behavior
|
11
|
-
* in React DOM and will not pass "autoFocus" to an actual HTML.
|
12
|
-
*/
|
13
|
-
function hasAutofocusProp(node) {
|
14
|
-
var _a;
|
15
|
-
// https://github.com/facebook/react/blob/848bb2426e44606e0a55dfe44c7b3ece33772485/packages/react-dom/src/client/ReactDOMHostConfig.js#L157-L166
|
16
|
-
var isAutoFocusableElement = node.nodeName === 'BUTTON' ||
|
17
|
-
node.nodeName === 'INPUT' ||
|
18
|
-
node.nodeName === 'SELECT' ||
|
19
|
-
node.nodeName === 'TEXTAREA';
|
20
|
-
if (isAutoFocusableElement) {
|
21
|
-
return !!((_a = getReactFiberFromNode(node)) === null || _a === void 0 ? void 0 : _a.pendingProps.autoFocus);
|
22
|
-
}
|
23
|
-
return false;
|
24
|
-
}
|
25
|
-
function hasAutofocusFilter(node) {
|
26
|
-
return hasAutofocusProp(node) ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP;
|
27
|
-
}
|
28
|
-
/**
|
29
|
-
* Provides a callback to resolve Popper options, it's stable and should be used as a dependency to trigger updates
|
30
|
-
* of Popper options.
|
31
|
-
*
|
32
|
-
* A callback is used there intentionally as some of Popper.js modifiers require DOM nodes (targer, container, arrow)
|
33
|
-
* that can't be resolved properly during an initial rendering.
|
34
|
-
*/
|
35
|
-
function usePopperOptions(options, popperOriginalPositionRef) {
|
36
|
-
var arrowPadding = options.arrowPadding, autoSize = options.autoSize, coverTarget = options.coverTarget, flipBoundary = options.flipBoundary, offset = options.offset, onStateUpdate = options.onStateUpdate, overflowBoundary = options.overflowBoundary,
|
37
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
38
|
-
unstable_disableTether = options.unstable_disableTether, pinned = options.pinned;
|
39
|
-
var isRtl = useFluent().dir === 'rtl';
|
40
|
-
var placement = getPlacement(options.align, options.position, isRtl);
|
41
|
-
var strategy = options.positionFixed ? 'fixed' : 'absolute';
|
42
|
-
var handleStateUpdate = useEventCallback(function (_a) {
|
43
|
-
var state = _a.state;
|
44
|
-
if (onStateUpdate) {
|
45
|
-
onStateUpdate(state);
|
46
|
-
}
|
47
|
-
});
|
48
|
-
var offsetModifier = React.useMemo(function () {
|
49
|
-
return offset
|
50
|
-
? {
|
51
|
-
name: 'offset',
|
52
|
-
options: { offset: isRtl ? applyRtlToOffset(offset) : offset },
|
53
|
-
}
|
54
|
-
: null;
|
55
|
-
}, [offset, isRtl]);
|
56
|
-
return React.useCallback(function (target, container, arrow) {
|
57
|
-
var _a;
|
58
|
-
var scrollParentElement = getScrollParent(container);
|
59
|
-
var hasScrollableElement = scrollParentElement
|
60
|
-
? scrollParentElement !== ((_a = scrollParentElement.ownerDocument) === null || _a === void 0 ? void 0 : _a.body)
|
61
|
-
: false;
|
62
|
-
var modifiers = [
|
63
|
-
/**
|
64
|
-
* We are setting the position to `fixed` in the first effect to prevent scroll jumps in case of the content
|
65
|
-
* with managed focus. Modifier sets the position to `fixed` before all other modifier effects. Another part of
|
66
|
-
* a patch modifies ".forceUpdate()" directly after a Popper will be created.
|
67
|
-
*/
|
68
|
-
{
|
69
|
-
name: 'positionStyleFix',
|
70
|
-
enabled: true,
|
71
|
-
phase: 'afterWrite',
|
72
|
-
effect: function (_a) {
|
73
|
-
var state = _a.state, instance = _a.instance;
|
74
|
-
// ".isFirstRun" is a part of our patch, on a first evaluation it will "undefined"
|
75
|
-
// should be disabled for subsequent runs as it breaks positioning for them
|
76
|
-
if (instance.isFirstRun !== false) {
|
77
|
-
popperOriginalPositionRef.current = state.elements.popper.style.position;
|
78
|
-
state.elements.popper.style.position = 'fixed';
|
79
|
-
}
|
80
|
-
return function () { return undefined; };
|
81
|
-
},
|
82
|
-
requires: [],
|
83
|
-
},
|
84
|
-
{ name: 'flip', options: { flipVariations: true } },
|
85
|
-
/**
|
86
|
-
* pinned disables the flip modifier by setting flip.enabled to false; this
|
87
|
-
* disables automatic repositioning of the popper box; it will always be placed according to
|
88
|
-
* the values of `align` and `position` props, regardless of the size of the component, the
|
89
|
-
* reference element or the viewport.
|
90
|
-
*/
|
91
|
-
pinned && { name: 'flip', enabled: false },
|
92
|
-
/**
|
93
|
-
* When the popper box is placed in the context of a scrollable element, we need to set
|
94
|
-
* preventOverflow.escapeWithReference to true and flip.boundariesElement to 'scrollParent'
|
95
|
-
* (default is 'viewport') so that the popper box will stick with the targetRef when we
|
96
|
-
* scroll targetRef out of the viewport.
|
97
|
-
*/
|
98
|
-
hasScrollableElement && { name: 'flip', options: { boundary: 'clippingParents' } },
|
99
|
-
hasScrollableElement && { name: 'preventOverflow', options: { boundary: 'clippingParents' } },
|
100
|
-
offsetModifier,
|
101
|
-
/**
|
102
|
-
* This modifier is necessary to retain behaviour from popper v1 where untethered poppers are allowed by
|
103
|
-
* default. i.e. popper is still rendered fully in the viewport even if anchor element is no longer in the
|
104
|
-
* viewport.
|
105
|
-
*/
|
106
|
-
unstable_disableTether && {
|
107
|
-
name: 'preventOverflow',
|
108
|
-
options: { altAxis: unstable_disableTether === 'all', tether: false },
|
109
|
-
},
|
110
|
-
flipBoundary && {
|
111
|
-
name: 'flip',
|
112
|
-
options: {
|
113
|
-
altBoundary: true,
|
114
|
-
boundary: getBoundary(container, flipBoundary),
|
115
|
-
},
|
116
|
-
},
|
117
|
-
overflowBoundary && {
|
118
|
-
name: 'preventOverflow',
|
119
|
-
options: {
|
120
|
-
altBoundary: true,
|
121
|
-
boundary: getBoundary(container, overflowBoundary),
|
122
|
-
},
|
123
|
-
},
|
124
|
-
{
|
125
|
-
name: 'onUpdate',
|
126
|
-
enabled: true,
|
127
|
-
phase: 'afterWrite',
|
128
|
-
fn: handleStateUpdate,
|
129
|
-
},
|
130
|
-
{
|
131
|
-
// Similar code as popper-maxsize-modifier: https://github.com/atomiks/popper.js/blob/master/src/modifiers/maxSize.js
|
132
|
-
// popper-maxsize-modifier only calculates the max sizes.
|
133
|
-
// This modifier can apply max sizes always, or apply the max sizes only when overflow is detected
|
134
|
-
name: 'applyMaxSize',
|
135
|
-
enabled: !!autoSize,
|
136
|
-
phase: 'beforeWrite',
|
137
|
-
requiresIfExists: ['offset', 'preventOverflow', 'flip'],
|
138
|
-
options: {
|
139
|
-
altBoundary: true,
|
140
|
-
boundary: getBoundary(container, overflowBoundary),
|
141
|
-
},
|
142
|
-
fn: function (_a) {
|
143
|
-
var state = _a.state, modifierOptions = _a.options;
|
144
|
-
var overflow = PopperJs.detectOverflow(state, modifierOptions);
|
145
|
-
var _b = state.modifiersData.preventOverflow || { x: 0, y: 0 }, x = _b.x, y = _b.y;
|
146
|
-
var _c = state.rects.popper, width = _c.width, height = _c.height;
|
147
|
-
var basePlacement = getBasePlacement(state.placement);
|
148
|
-
var widthProp = basePlacement === 'left' ? 'left' : 'right';
|
149
|
-
var heightProp = basePlacement === 'top' ? 'top' : 'bottom';
|
150
|
-
var applyMaxWidth = autoSize === 'always' ||
|
151
|
-
autoSize === 'width-always' ||
|
152
|
-
(overflow[widthProp] > 0 && (autoSize === true || autoSize === 'width'));
|
153
|
-
var applyMaxHeight = autoSize === 'always' ||
|
154
|
-
autoSize === 'height-always' ||
|
155
|
-
(overflow[heightProp] > 0 && (autoSize === true || autoSize === 'height'));
|
156
|
-
if (applyMaxWidth) {
|
157
|
-
state.styles.popper.maxWidth = width - overflow[widthProp] - x + "px";
|
158
|
-
}
|
159
|
-
if (applyMaxHeight) {
|
160
|
-
state.styles.popper.maxHeight = height - overflow[heightProp] - y + "px";
|
161
|
-
}
|
162
|
-
},
|
163
|
-
},
|
164
|
-
/**
|
165
|
-
* This modifier is necessary in order to render the pointer. Refs are resolved in effects, so it can't be
|
166
|
-
* placed under computed modifiers. Deep merge is not required as this modifier has only these properties.
|
167
|
-
*/
|
168
|
-
{
|
169
|
-
name: 'arrow',
|
170
|
-
enabled: !!arrow,
|
171
|
-
options: { element: arrow, padding: arrowPadding },
|
172
|
-
},
|
173
|
-
/**
|
174
|
-
* Modifies popper offsets to cover the reference rect, but still keep edge alignment
|
175
|
-
*/
|
176
|
-
{
|
177
|
-
name: 'coverTarget',
|
178
|
-
enabled: !!coverTarget,
|
179
|
-
phase: 'main',
|
180
|
-
requiresIfExists: ['offset', 'preventOverflow', 'flip'],
|
181
|
-
fn: function (_a) {
|
182
|
-
var state = _a.state;
|
183
|
-
var basePlacement = getBasePlacement(state.placement);
|
184
|
-
switch (basePlacement) {
|
185
|
-
case 'bottom':
|
186
|
-
state.modifiersData.popperOffsets.y -= state.rects.reference.height;
|
187
|
-
break;
|
188
|
-
case 'top':
|
189
|
-
state.modifiersData.popperOffsets.y += state.rects.reference.height;
|
190
|
-
break;
|
191
|
-
case 'left':
|
192
|
-
state.modifiersData.popperOffsets.x += state.rects.reference.width;
|
193
|
-
break;
|
194
|
-
case 'right':
|
195
|
-
state.modifiersData.popperOffsets.x -= state.rects.reference.width;
|
196
|
-
break;
|
197
|
-
}
|
198
|
-
},
|
199
|
-
},
|
200
|
-
].filter(Boolean); // filter boolean conditional spreading values
|
201
|
-
var popperOptions = {
|
202
|
-
modifiers: modifiers,
|
203
|
-
placement: placement,
|
204
|
-
strategy: strategy,
|
205
|
-
onFirstUpdate: function (state) { return handleStateUpdate({ state: state }); },
|
206
|
-
};
|
207
|
-
return popperOptions;
|
208
|
-
}, [
|
209
|
-
arrowPadding,
|
210
|
-
autoSize,
|
211
|
-
coverTarget,
|
212
|
-
flipBoundary,
|
213
|
-
offsetModifier,
|
214
|
-
overflowBoundary,
|
215
|
-
placement,
|
216
|
-
strategy,
|
217
|
-
unstable_disableTether,
|
218
|
-
pinned,
|
219
|
-
// These can be skipped from deps as they will not ever change
|
220
|
-
handleStateUpdate,
|
221
|
-
popperOriginalPositionRef,
|
222
|
-
]);
|
223
|
-
}
|
224
|
-
/**
|
225
|
-
* Exposes Popper positioning API via React hook. Contains few important differences between an official "react-popper"
|
226
|
-
* package:
|
227
|
-
* - style attributes are applied directly on DOM to avoid re-renders
|
228
|
-
* - refs changes and resolution is handled properly without re-renders
|
229
|
-
* - contains a specific to React fix related to initial positioning when containers have components with managed focus
|
230
|
-
* to avoid focus jumps
|
231
|
-
*/
|
232
|
-
export function usePopper(options) {
|
233
|
-
if (options === void 0) { options = {}; }
|
234
|
-
var _a = options.enabled, enabled = _a === void 0 ? true : _a;
|
235
|
-
var isFirstMount = useFirstMount();
|
236
|
-
var popperOriginalPositionRef = React.useRef('absolute');
|
237
|
-
var resolvePopperOptions = usePopperOptions(options, popperOriginalPositionRef);
|
238
|
-
var popperInstanceRef = React.useRef(null);
|
239
|
-
var handlePopperUpdate = useEventCallback(function () {
|
240
|
-
var _a;
|
241
|
-
(_a = popperInstanceRef.current) === null || _a === void 0 ? void 0 : _a.destroy();
|
242
|
-
popperInstanceRef.current = null;
|
243
|
-
var _b = options.target, target = _b === void 0 ? targetRef.current : _b;
|
244
|
-
var popperInstance = null;
|
245
|
-
if (canUseDOM() && enabled) {
|
246
|
-
if (target && containerRef.current) {
|
247
|
-
popperInstance = PopperJs.createPopper(target, containerRef.current, resolvePopperOptions(target, containerRef.current, arrowRef.current));
|
248
|
-
}
|
249
|
-
}
|
250
|
-
if (popperInstance) {
|
251
|
-
/**
|
252
|
-
* The patch updates `.forceUpdate()` Popper function which restores the original position before the first
|
253
|
-
* forceUpdate() call. See also "positionStyleFix" modifier in usePopperOptions().
|
254
|
-
*/
|
255
|
-
var originalForceUpdate_1 = popperInstance.forceUpdate;
|
256
|
-
popperInstance.isFirstRun = true;
|
257
|
-
popperInstance.forceUpdate = function () {
|
258
|
-
if (popperInstance === null || popperInstance === void 0 ? void 0 : popperInstance.isFirstRun) {
|
259
|
-
popperInstance.state.elements.popper.style.position = popperOriginalPositionRef.current;
|
260
|
-
popperInstance.isFirstRun = false;
|
261
|
-
}
|
262
|
-
originalForceUpdate_1();
|
263
|
-
};
|
264
|
-
}
|
265
|
-
popperInstanceRef.current = popperInstance;
|
266
|
-
});
|
267
|
-
// Refs are managed by useCallbackRef() to handle ref updates scenarios.
|
268
|
-
//
|
269
|
-
// The first scenario are updates for a targetRef, we can handle it properly only via callback refs, but it causes
|
270
|
-
// re-renders (we would like to avoid them).
|
271
|
-
//
|
272
|
-
// The second problem is related to refs resolution on React's layer: refs are resolved in the same order as effects
|
273
|
-
// that causes an issue when you have a container inside a target, for example: a menu in ChatMessage.
|
274
|
-
//
|
275
|
-
// function ChatMessage(props) {
|
276
|
-
// <div className="message" ref={targetRef}> // 3) ref will be resolved only now, but it's too late already
|
277
|
-
// <Popper target={targetRef}> // 2) create a popper instance
|
278
|
-
// <div className="menu" /> // 1) capture ref from this element
|
279
|
-
// </Popper>
|
280
|
-
// </div>
|
281
|
-
// }
|
282
|
-
//
|
283
|
-
// Check a demo on CodeSandbox: https://codesandbox.io/s/popper-refs-emy60.
|
284
|
-
//
|
285
|
-
// This again can be solved with callback refs. It's not a huge issue as with hooks we are moving popper's creation
|
286
|
-
// to ChatMessage itself, however, without `useCallback()` refs it's still a Pandora box.
|
287
|
-
var targetRef = useCallbackRef(null, handlePopperUpdate, true);
|
288
|
-
var containerRef = useCallbackRef(null, handlePopperUpdate, true);
|
289
|
-
var arrowRef = useCallbackRef(null, handlePopperUpdate, true);
|
290
|
-
React.useImperativeHandle(options.popperRef, function () { return ({
|
291
|
-
updatePosition: function () {
|
292
|
-
var _a;
|
293
|
-
(_a = popperInstanceRef.current) === null || _a === void 0 ? void 0 : _a.update();
|
294
|
-
},
|
295
|
-
}); }, []);
|
296
|
-
useIsomorphicLayoutEffect(function () {
|
297
|
-
handlePopperUpdate();
|
298
|
-
return function () {
|
299
|
-
var _a;
|
300
|
-
(_a = popperInstanceRef.current) === null || _a === void 0 ? void 0 : _a.destroy();
|
301
|
-
popperInstanceRef.current = null;
|
302
|
-
};
|
303
|
-
}, [handlePopperUpdate, options.enabled, options.target]);
|
304
|
-
useIsomorphicLayoutEffect(function () {
|
305
|
-
var _a;
|
306
|
-
if (!isFirstMount) {
|
307
|
-
(_a = popperInstanceRef.current) === null || _a === void 0 ? void 0 : _a.setOptions(resolvePopperOptions(options.target || targetRef.current, containerRef.current, arrowRef.current));
|
308
|
-
}
|
309
|
-
},
|
310
|
-
// Missing deps:
|
311
|
-
// options.target - The useIsomorphicLayoutEffect before this will create a new popper instance if target changes
|
312
|
-
// isFirstMount - Should never change after mount
|
313
|
-
// arrowRef, containerRef, targetRef - Stable between renders
|
314
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
315
|
-
[resolvePopperOptions]);
|
316
|
-
if (process.env.NODE_ENV !== 'production') {
|
317
|
-
// This checked should run only in development mode
|
318
|
-
// eslint-disable-next-line react-hooks/rules-of-hooks
|
319
|
-
React.useEffect(function () {
|
320
|
-
var _a;
|
321
|
-
if (containerRef.current) {
|
322
|
-
var contentNode = containerRef.current;
|
323
|
-
var treeWalker = (_a = contentNode.ownerDocument) === null || _a === void 0 ? void 0 : _a.createTreeWalker(contentNode, NodeFilter.SHOW_ELEMENT, {
|
324
|
-
acceptNode: hasAutofocusFilter,
|
325
|
-
});
|
326
|
-
while (treeWalker === null || treeWalker === void 0 ? void 0 : treeWalker.nextNode()) {
|
327
|
-
var node = treeWalker.currentNode;
|
328
|
-
// eslint-disable-next-line no-console
|
329
|
-
console.warn('<Popper>:', node);
|
330
|
-
// eslint-disable-next-line no-console
|
331
|
-
console.warn([
|
332
|
-
'<Popper>: ^ this node contains "autoFocus" prop on a React element. This can break the initial',
|
333
|
-
'positioning of an element and cause a window jump effect. This issue occurs because React polyfills',
|
334
|
-
'"autoFocus" behavior to solve inconsistencies between different browsers:',
|
335
|
-
'https://github.com/facebook/react/issues/11851#issuecomment-351787078',
|
336
|
-
'\n',
|
337
|
-
'However, ".focus()" in this case occurs before any other React effects will be executed',
|
338
|
-
'(React.useEffect(), componentDidMount(), etc.) and we can not prevent this behavior. If you really',
|
339
|
-
'want to use "autoFocus" please add "position: fixed" to styles of the element that is wrapped by',
|
340
|
-
'"Popper".',
|
341
|
-
"In general, it's not recommended to use \"autoFocus\" as it may break accessibility aspects:",
|
342
|
-
'https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/master/docs/rules/no-autofocus.md',
|
343
|
-
'\n',
|
344
|
-
'We suggest to use the "trapFocus" prop on Fluent components or a catch "ref" and then use',
|
345
|
-
'"ref.current.focus" in React.useEffect():',
|
346
|
-
'https://reactjs.org/docs/refs-and-the-dom.html#adding-a-ref-to-a-dom-element',
|
347
|
-
].join(' '));
|
348
|
-
}
|
349
|
-
}
|
350
|
-
// We run this check once, no need to add deps here
|
351
|
-
// TODO: Should be rework to handle options.enabled and contentRef updates
|
352
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
353
|
-
}, []);
|
354
|
-
}
|
355
|
-
return { targetRef: targetRef, containerRef: containerRef, arrowRef: arrowRef };
|
356
|
-
}
|
357
|
-
//# sourceMappingURL=usePopper.js.map
|
package/lib/usePopper.js.map
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"usePopper.js","sourceRoot":"","sources":["../src/usePopper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,yBAAyB,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAClH,OAAO,EAAE,SAAS,EAAE,MAAM,iCAAiC,CAAC;AAC5D,OAAO,EAC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ACd,IAAI,YAAY,CAAC,OAAO,EAAE;gBACxB,IAAM,WAAW,GAAG,YAAY,CAAC,OAAO,CAAC;gBACzC,IAAM,UAAU,SAAG,WAAW,CAAC,aAAa,0CAAE,gBAAgB,CAAC,WAAW,EAAE,UAAU,CAAC,YAAY,EAAE;oBACnG,UAAU,EAAE,kBAAkB;iBAC/B,CAAC,CAAC;gBAEH,OAAO,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,QAAQ,IAAI;oBAC7B,IAAM,IAAI,GAAG,UAAU,CAAC,WAAW,CAAC;oBACpC,sCAAsC;oBACtC,OAAO,CAAC,IAAI,CAAC,WAAW,EAAE,IAAI,CAAC,CAAC;oBAChC,sCAAsC;oBACtC,OAAO,CAAC,IAAI,CACV;wBACE,gGAAgG;wBAChG,qGAAqG;wBACrG,2EAA2E;wBAC3E,uEAAuE;wBACvE,IAAI;wBACJ,yFAAyF;wBACzF,oGAAoG;wBACpG,kGAAkG;wBAClG,WAAW;wBACX,8FAA4F;wBAC5F,6FAA6F;wBAC7F,IAAI;wBACJ,2FAA2F;wBAC3F,2CAA2C;wBAC3C,8EAA8E;qBAC/E,CAAC,IAAI,CAAC,GAAG,CAAC,CACZ,CAAC;iBACH;aACF;YACD,mDAAmD;YACnD,0EAA0E;YAC1E,uDAAuD;QACzD,CAAC,EAAE,EAAE,CAAC,CAAC;KACR;IAED,OAAO,EAAE,SAAS,WAAA,EAAE,YAAY,cAAA,EAAE,QAAQ,UAAA,EAAE,CAAC;AAC/C,CAAC"}
|
@@ -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,34 +0,0 @@
|
|
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
|
-
export var usePopperMouseTarget = function (initialState) {
|
12
|
-
var _a = React.useState(initialState), virtualElement = _a[0], setVirtualElement = _a[1];
|
13
|
-
var setVirtualMouseTarget = function (event) {
|
14
|
-
if (event === undefined || event === null) {
|
15
|
-
setVirtualElement(undefined);
|
16
|
-
return;
|
17
|
-
}
|
18
|
-
var mouseevent;
|
19
|
-
if (!(event instanceof MouseEvent)) {
|
20
|
-
mouseevent = event.nativeEvent;
|
21
|
-
}
|
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('usePopperMouseTarget should only be used with MouseEvent');
|
28
|
-
}
|
29
|
-
var contextTarget = createVirtualElementFromClick(mouseevent);
|
30
|
-
setVirtualElement(contextTarget);
|
31
|
-
};
|
32
|
-
return [virtualElement, setVirtualMouseTarget];
|
33
|
-
};
|
34
|
-
//# sourceMappingURL=usePopperMouseTarget.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"usePopperMouseTarget.js","sourceRoot":"","sources":["../src/usePopperMouseTarget.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,6BAA6B,EAAE,MAAM,iCAAiC,CAAC;AAGhF;;;;;;;GAOG;AACH,MAAM,CAAC,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,6BAA6B,CAAC,UAAU,CAAC,CAAC;QAChE,iBAAiB,CAAC,aAAa,CAAC,CAAC;IACnC,CAAC,CAAC;IAEF,OAAO,CAAC,cAAc,EAAE,qBAAqB,CAAU,CAAC;AAC1D,CAAC,CAAC"}
|
@@ -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,10 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* Returns the base placement value
|
3
|
-
* @param placement - the popper placement (i.e. bottom-start)
|
4
|
-
*
|
5
|
-
* @returns bottom-start -> bottom
|
6
|
-
*/
|
7
|
-
export function getBasePlacement(placement) {
|
8
|
-
return placement.split('-')[0];
|
9
|
-
}
|
10
|
-
//# sourceMappingURL=getBasePlacement.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"getBasePlacement.js","sourceRoot":"","sources":["../../src/utils/getBasePlacement.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,MAAM,UAAU,gBAAgB,CAAC,SAA6B;IAC5D,OAAO,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAA2B,CAAC;AAC3D,CAAC"}
|
@@ -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;
|
@@ -1,109 +0,0 @@
|
|
1
|
-
/// <reference types="custom-global" />
|
2
|
-
import * as React from 'react';
|
3
|
-
declare type ReactEventResponder<E, C> = {
|
4
|
-
$$typeof: Symbol | number;
|
5
|
-
displayName: string;
|
6
|
-
targetEventTypes: null | string[];
|
7
|
-
rootEventTypes: null | string[];
|
8
|
-
getInitialState: null | ((props: Object) => Object);
|
9
|
-
onEvent: null | ((event: E, context: C, props: Object, state: Object) => void);
|
10
|
-
onRootEvent: null | ((event: E, context: C, props: Object, state: Object) => void);
|
11
|
-
onMount: null | ((context: C, props: Object, state: Object) => void);
|
12
|
-
onUnmount: null | ((context: C, props: Object, state: Object) => void);
|
13
|
-
};
|
14
|
-
declare type ReactEventResponderInstance<E, C> = {
|
15
|
-
fiber: Object;
|
16
|
-
props: Object;
|
17
|
-
responder: ReactEventResponder<E, C>;
|
18
|
-
rootEventTypes: null | Set<string>;
|
19
|
-
state: Object;
|
20
|
-
};
|
21
|
-
export declare type HookType = 'useState' | 'useReducer' | 'useContext' | 'useRef' | 'useEffect' | 'useLayoutEffect' | 'useCallback' | 'useMemo' | 'useImperativeHandle' | 'useDebugValue' | 'useResponder';
|
22
|
-
declare type ReactProviderType<T> = {
|
23
|
-
$$typeof: Symbol | number;
|
24
|
-
_context: ReactContext<T>;
|
25
|
-
};
|
26
|
-
declare type ReactContext<T> = {
|
27
|
-
$$typeof: Symbol | number;
|
28
|
-
Consumer: ReactContext<T>;
|
29
|
-
Provider: ReactProviderType<T>;
|
30
|
-
_calculateChangedBits: ((a: T, b: T) => number) | null;
|
31
|
-
_currentValue: T;
|
32
|
-
_currentValue2: T;
|
33
|
-
_threadCount: number;
|
34
|
-
_currentRenderer?: Object | null;
|
35
|
-
_currentRenderer2?: Object | null;
|
36
|
-
};
|
37
|
-
declare type ContextDependency<T> = {
|
38
|
-
context: ReactContext<T>;
|
39
|
-
observedBits: number;
|
40
|
-
next: ContextDependency<any> | null;
|
41
|
-
};
|
42
|
-
declare enum WorkTag {
|
43
|
-
FunctionComponent = 0,
|
44
|
-
ClassComponent = 1,
|
45
|
-
IndeterminateComponent = 2,
|
46
|
-
HostRoot = 3,
|
47
|
-
HostPortal = 4,
|
48
|
-
HostComponent = 5,
|
49
|
-
HostText = 6,
|
50
|
-
Fragment = 7,
|
51
|
-
Mode = 8,
|
52
|
-
ContextConsumer = 9,
|
53
|
-
ContextProvider = 10,
|
54
|
-
ForwardRef = 11,
|
55
|
-
Profiler = 12,
|
56
|
-
SuspenseComponent = 13,
|
57
|
-
MemoComponent = 14,
|
58
|
-
SimpleMemoComponent = 15,
|
59
|
-
LazyComponent = 16,
|
60
|
-
IncompleteClassComponent = 17,
|
61
|
-
DehydratedFragment = 18,
|
62
|
-
SuspenseListComponent = 19,
|
63
|
-
FundamentalComponent = 20,
|
64
|
-
ScopeComponent = 21
|
65
|
-
}
|
66
|
-
declare type Source = {
|
67
|
-
fileName: string;
|
68
|
-
lineNumber: number;
|
69
|
-
};
|
70
|
-
declare type ExpirationTime = number;
|
71
|
-
declare type Dependencies = {
|
72
|
-
expirationTime: ExpirationTime;
|
73
|
-
firstContext: ContextDependency<any> | null;
|
74
|
-
responders: Map<ReactEventResponder<any, any>, ReactEventResponderInstance<any, any>> | null;
|
75
|
-
};
|
76
|
-
export declare type Fiber = {
|
77
|
-
tag: WorkTag;
|
78
|
-
key: null | string;
|
79
|
-
elementType: any;
|
80
|
-
type: any;
|
81
|
-
stateNode: any;
|
82
|
-
return: Fiber | null;
|
83
|
-
child: Fiber | null;
|
84
|
-
sibling: Fiber | null;
|
85
|
-
index: number;
|
86
|
-
ref: React.Ref<any>;
|
87
|
-
pendingProps: any;
|
88
|
-
memoizedProps: any;
|
89
|
-
memoizedState: any;
|
90
|
-
dependencies: Dependencies | null;
|
91
|
-
nextEffect: Fiber | null;
|
92
|
-
firstEffect: Fiber | null;
|
93
|
-
lastEffect: Fiber | null;
|
94
|
-
expirationTime: ExpirationTime;
|
95
|
-
childExpirationTime: ExpirationTime;
|
96
|
-
alternate: Fiber | null;
|
97
|
-
actualDuration?: number;
|
98
|
-
actualStartTime?: number;
|
99
|
-
selfBaseDuration?: number;
|
100
|
-
treeBaseDuration?: number;
|
101
|
-
_debugID?: number;
|
102
|
-
_debugSource?: Source | null;
|
103
|
-
_debugOwner?: Fiber | null;
|
104
|
-
_debugIsCurrentlyTiming?: boolean;
|
105
|
-
_debugNeedsRemount?: boolean;
|
106
|
-
_debugHookTypes?: HookType[] | null;
|
107
|
-
};
|
108
|
-
export declare function getReactFiberFromNode(elm: Node | undefined): Fiber | null;
|
109
|
-
export {};
|
@@ -1,12 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* Returns the parent node or the host of the node argument.
|
3
|
-
* @param node - DOM node.
|
4
|
-
* @returns - parent DOM node.
|
5
|
-
*/
|
6
|
-
export declare const getParentNode: (node: HTMLElement) => HTMLElement;
|
7
|
-
/**
|
8
|
-
* Returns the first scrollable parent of the given element.
|
9
|
-
* @param node - DOM node.
|
10
|
-
* @returns - the first scrollable parent.
|
11
|
-
*/
|
12
|
-
export declare const getScrollParent: (node: Document | HTMLElement | null) => HTMLElement;
|
package/lib/utils/index.d.ts
DELETED
@@ -1,8 +0,0 @@
|
|
1
|
-
export * from './getBasePlacement';
|
2
|
-
export * from './getBoundary';
|
3
|
-
export * from './getReactFiberFromNode';
|
4
|
-
export * from './getScrollParent';
|
5
|
-
export * from './mergeArrowOffset';
|
6
|
-
export * from './positioningHelper';
|
7
|
-
export * from './resolvePositioningShorthand';
|
8
|
-
export * from './useCallbackRef';
|
@@ -1,10 +0,0 @@
|
|
1
|
-
import type { Offset } from '../types';
|
2
|
-
/**
|
3
|
-
* Generally when adding an arrow to popper, it's necessary to offset the position of the popper by the
|
4
|
-
* height of the arrow. A simple utility to merge a provided offset with an arrow height to return the final offset
|
5
|
-
*
|
6
|
-
* @param userOffset - The offset provided by the user
|
7
|
-
* @param arrowHeight - The height of the arrow in px
|
8
|
-
* @returns User offset augmented with arrow height
|
9
|
-
*/
|
10
|
-
export declare function mergeArrowOffset(userOffset: Offset | undefined | null, arrowHeight: number): Offset;
|
@@ -1,7 +0,0 @@
|
|
1
|
-
import * as PopperJs from '@popperjs/core';
|
2
|
-
import type { Offset } from '../types';
|
3
|
-
/**
|
4
|
-
* @see positioninHelper.test.ts for expected placement values
|
5
|
-
*/
|
6
|
-
export declare const getPlacement: (align?: "top" | "bottom" | "start" | "end" | "center" | undefined, position?: "above" | "below" | "before" | "after" | undefined, rtl?: boolean | undefined) => PopperJs.Placement;
|
7
|
-
export declare const applyRtlToOffset: (offset: Offset | undefined) => Offset | undefined;
|
@@ -1,19 +0,0 @@
|
|
1
|
-
import * as React from 'react';
|
2
|
-
/**
|
3
|
-
* Creates a MutableRef with ref change callback. Is useful as React.useRef() doesn't notify you when its content
|
4
|
-
* changes and mutating the .current property doesn't cause a re-render. An opt-out will be use a callback ref via
|
5
|
-
* React.useState(), but it will cause re-renders always.
|
6
|
-
*
|
7
|
-
* https://reactjs.org/docs/hooks-reference.html#useref
|
8
|
-
* https://github.com/theKashey/use-callback-ref#usecallbackref---to-replace-reactuseref
|
9
|
-
*
|
10
|
-
* @param initialValue - initial ref value
|
11
|
-
* @param callback - a callback to run when value changes
|
12
|
-
* @param skipInitialResolve - a flag to skip an initial ref report
|
13
|
-
*
|
14
|
-
* @example
|
15
|
-
* const ref = useCallbackRef(0, (newValue, oldValue) => console.log(oldValue, '->', newValue);
|
16
|
-
* ref.current = 1;
|
17
|
-
* // prints 0 -> 1
|
18
|
-
*/
|
19
|
-
export declare function useCallbackRef<T>(initialValue: T | null, callback: (newValue: T | null, lastValue: T | null) => void, skipInitialResolve?: boolean): React.MutableRefObject<T | null>;
|
@@ -1,6 +0,0 @@
|
|
1
|
-
import type { PopperVirtualElement } from './types';
|
2
|
-
/**
|
3
|
-
* Creates a virtual element based on the position of a click event
|
4
|
-
* Can be used as a target for popper in scenarios such as context menus
|
5
|
-
*/
|
6
|
-
export declare function createVirtualElementFromClick(nativeEvent: MouseEvent): PopperVirtualElement;
|