@fluentui/react-positioning 9.0.0-alpha.9 → 9.0.0-beta.4
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.json +1279 -1
- package/CHANGELOG.md +577 -2
- package/dist/react-positioning.d.ts +95 -27
- package/lib/createArrowStyles.d.ts +27 -0
- package/lib/createArrowStyles.js +75 -0
- package/lib/createArrowStyles.js.map +1 -0
- package/lib/createVirtualElementFromClick.d.ts +6 -0
- package/lib/createVirtualElementFromClick.js +26 -0
- package/lib/createVirtualElementFromClick.js.map +1 -0
- package/lib/index.d.ts +4 -0
- package/lib/index.js +5 -0
- package/lib/index.js.map +1 -1
- package/lib/tsdoc-metadata.json +1 -1
- package/lib/types.d.ts +19 -29
- package/lib/types.js +1 -0
- package/lib/types.js.map +1 -1
- package/lib/usePopper.d.ts +21 -1
- package/lib/usePopper.js +364 -284
- package/lib/usePopper.js.map +1 -1
- package/lib/usePopperMouseTarget.d.ts +11 -0
- package/lib/usePopperMouseTarget.js +40 -0
- package/lib/usePopperMouseTarget.js.map +1 -0
- package/lib/utils/getBasePlacement.d.ts +8 -0
- package/lib/utils/getBasePlacement.js +10 -0
- package/lib/utils/getBasePlacement.js.map +1 -0
- package/lib/utils/getBoundary.d.ts +1 -1
- package/lib/utils/getBoundary.js +15 -11
- package/lib/utils/getBoundary.js.map +1 -1
- package/lib/utils/getReactFiberFromNode.d.ts +0 -1
- 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.d.ts +5 -3
- package/lib/utils/index.js +5 -3
- package/lib/utils/index.js.map +1 -1
- package/lib/utils/mergeArrowOffset.d.ts +10 -0
- package/lib/utils/mergeArrowOffset.js +42 -0
- package/lib/utils/mergeArrowOffset.js.map +1 -0
- package/lib/utils/positioningHelper.d.ts +3 -3
- package/lib/utils/positioningHelper.js +42 -34
- package/lib/utils/positioningHelper.js.map +1 -1
- package/lib/utils/resolvePositioningShorthand.d.ts +2 -0
- package/lib/utils/resolvePositioningShorthand.js +63 -0
- package/lib/utils/resolvePositioningShorthand.js.map +1 -0
- package/lib/utils/useCallbackRef.js +35 -29
- package/lib/utils/useCallbackRef.js.map +1 -1
- package/lib-commonjs/createArrowStyles.d.ts +27 -0
- package/lib-commonjs/createArrowStyles.js +84 -0
- package/lib-commonjs/createArrowStyles.js.map +1 -0
- package/lib-commonjs/createVirtualElementFromClick.d.ts +6 -0
- package/lib-commonjs/createVirtualElementFromClick.js +35 -0
- package/lib-commonjs/createVirtualElementFromClick.js.map +1 -0
- package/lib-commonjs/index.d.ts +4 -0
- package/lib-commonjs/index.js +31 -2
- package/lib-commonjs/index.js.map +1 -1
- package/lib-commonjs/types.d.ts +19 -29
- package/lib-commonjs/types.js +4 -1
- package/lib-commonjs/types.js.map +1 -1
- package/lib-commonjs/usePopper.d.ts +21 -1
- package/lib-commonjs/usePopper.js +378 -287
- package/lib-commonjs/usePopper.js.map +1 -1
- package/lib-commonjs/usePopperMouseTarget.d.ts +11 -0
- package/lib-commonjs/usePopperMouseTarget.js +51 -0
- package/lib-commonjs/usePopperMouseTarget.js.map +1 -0
- package/lib-commonjs/utils/getBasePlacement.d.ts +8 -0
- package/lib-commonjs/utils/getBasePlacement.js +19 -0
- package/lib-commonjs/utils/getBasePlacement.js.map +1 -0
- package/lib-commonjs/utils/getBoundary.d.ts +1 -1
- package/lib-commonjs/utils/getBoundary.js +24 -13
- package/lib-commonjs/utils/getBoundary.js.map +1 -1
- package/lib-commonjs/utils/getReactFiberFromNode.d.ts +0 -1
- package/lib-commonjs/utils/getReactFiberFromNode.js +45 -36
- package/lib-commonjs/utils/getReactFiberFromNode.js.map +1 -1
- package/lib-commonjs/utils/getScrollParent.js +56 -33
- package/lib-commonjs/utils/getScrollParent.js.map +1 -1
- package/lib-commonjs/utils/index.d.ts +5 -3
- package/lib-commonjs/utils/index.js +19 -5
- package/lib-commonjs/utils/index.js.map +1 -1
- package/lib-commonjs/utils/mergeArrowOffset.d.ts +10 -0
- package/lib-commonjs/utils/mergeArrowOffset.js +51 -0
- package/lib-commonjs/utils/mergeArrowOffset.js.map +1 -0
- package/lib-commonjs/utils/positioningHelper.d.ts +3 -3
- package/lib-commonjs/utils/positioningHelper.js +53 -35
- package/lib-commonjs/utils/positioningHelper.js.map +1 -1
- package/lib-commonjs/utils/resolvePositioningShorthand.d.ts +2 -0
- package/lib-commonjs/utils/resolvePositioningShorthand.js +72 -0
- package/lib-commonjs/utils/resolvePositioningShorthand.js.map +1 -0
- package/lib-commonjs/utils/useCallbackRef.js +46 -32
- package/lib-commonjs/utils/useCallbackRef.js.map +1 -1
- package/package.json +13 -10
- package/config/api-extractor.json +0 -3
- package/etc/react-positioning.api.md +0 -70
- package/just.config.ts +0 -3
- package/lib/utils/isBrowser.d.ts +0 -1
- package/lib/utils/isBrowser.js +0 -4
- package/lib/utils/isBrowser.js.map +0 -1
- package/lib-amd/index.d.ts +0 -2
- package/lib-amd/index.js +0 -6
- package/lib-amd/index.js.map +0 -1
- package/lib-amd/types.d.ts +0 -78
- package/lib-amd/types.js +0 -5
- package/lib-amd/types.js.map +0 -1
- package/lib-amd/usePopper.d.ts +0 -15
- package/lib-amd/usePopper.js +0 -281
- package/lib-amd/usePopper.js.map +0 -1
- package/lib-amd/utils/getBoundary.d.ts +0 -6
- package/lib-amd/utils/getBoundary.js +0 -23
- package/lib-amd/utils/getBoundary.js.map +0 -1
- package/lib-amd/utils/getReactFiberFromNode.d.ts +0 -109
- package/lib-amd/utils/getReactFiberFromNode.js +0 -47
- package/lib-amd/utils/getReactFiberFromNode.js.map +0 -1
- package/lib-amd/utils/getScrollParent.d.ts +0 -12
- package/lib-amd/utils/getScrollParent.js +0 -55
- package/lib-amd/utils/getScrollParent.js.map +0 -1
- package/lib-amd/utils/index.d.ts +0 -6
- package/lib-amd/utils/index.js +0 -11
- package/lib-amd/utils/index.js.map +0 -1
- package/lib-amd/utils/isBrowser.d.ts +0 -1
- package/lib-amd/utils/isBrowser.js +0 -8
- package/lib-amd/utils/isBrowser.js.map +0 -1
- package/lib-amd/utils/positioningHelper.d.ts +0 -7
- package/lib-amd/utils/positioningHelper.js +0 -45
- package/lib-amd/utils/positioningHelper.js.map +0 -1
- package/lib-amd/utils/useCallbackRef.d.ts +0 -19
- package/lib-amd/utils/useCallbackRef.js +0 -54
- package/lib-amd/utils/useCallbackRef.js.map +0 -1
- package/lib-commonjs/utils/isBrowser.d.ts +0 -1
- package/lib-commonjs/utils/isBrowser.js +0 -6
- package/lib-commonjs/utils/isBrowser.js.map +0 -1
package/lib-amd/usePopper.js
DELETED
@@ -1,281 +0,0 @@
|
|
1
|
-
define(["require", "exports", "@fluentui/react-utilities", "@fluentui/react-shared-contexts", "./utils/index", "@popperjs/core", "react"], function (require, exports, react_utilities_1, react_shared_contexts_1, index_1, PopperJs, React) {
|
2
|
-
"use strict";
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
4
|
-
//
|
5
|
-
// Dev utils to detect if nodes have "autoFocus" props.
|
6
|
-
//
|
7
|
-
/**
|
8
|
-
* Detects if a passed HTML node has "autoFocus" prop on a React's fiber. Is needed as React handles autofocus behavior
|
9
|
-
* in React DOM and will not pass "autoFocus" to an actual HTML.
|
10
|
-
*/
|
11
|
-
function hasAutofocusProp(node) {
|
12
|
-
var _a;
|
13
|
-
// https://github.com/facebook/react/blob/848bb2426e44606e0a55dfe44c7b3ece33772485/packages/react-dom/src/client/ReactDOMHostConfig.js#L157-L166
|
14
|
-
var isAutoFocusableElement = node.nodeName === 'BUTTON' ||
|
15
|
-
node.nodeName === 'INPUT' ||
|
16
|
-
node.nodeName === 'SELECT' ||
|
17
|
-
node.nodeName === 'TEXTAREA';
|
18
|
-
if (isAutoFocusableElement) {
|
19
|
-
return !!((_a = index_1.getReactFiberFromNode(node)) === null || _a === void 0 ? void 0 : _a.pendingProps.autoFocus);
|
20
|
-
}
|
21
|
-
return false;
|
22
|
-
}
|
23
|
-
function hasAutofocusFilter(node) {
|
24
|
-
return hasAutofocusProp(node) ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP;
|
25
|
-
}
|
26
|
-
/**
|
27
|
-
* Provides a callback to resolve Popper options, it's stable and should be used as a dependency to trigger updates
|
28
|
-
* of Popper options.
|
29
|
-
*
|
30
|
-
* A callback is used there intentionally as some of Popper.js modifiers require DOM nodes (targer, container, arrow)
|
31
|
-
* that can't be resolved properly during an initial rendering.
|
32
|
-
*/
|
33
|
-
function usePopperOptions(options, popperOriginalPositionRef) {
|
34
|
-
var autoSize = options.autoSize, flipBoundary = options.flipBoundary, offset = options.offset, arrowPadding = options.arrowPadding, onStateUpdate = options.onStateUpdate, overflowBoundary = options.overflowBoundary,
|
35
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
36
|
-
unstable_disableTether = options.unstable_disableTether,
|
37
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
38
|
-
unstable_pinned = options.unstable_pinned;
|
39
|
-
var isRtl = react_shared_contexts_1.useFluent().dir === 'rtl';
|
40
|
-
var placement = index_1.getPlacement(options.align, options.position, isRtl);
|
41
|
-
var strategy = options.positionFixed ? 'fixed' : 'absolute';
|
42
|
-
var handleStateUpdate = react_utilities_1.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 ? index_1.applyRtlToOffset(offset) : offset },
|
53
|
-
}
|
54
|
-
: null;
|
55
|
-
}, [offset, isRtl]);
|
56
|
-
return React.useCallback(function (target, container, arrow) {
|
57
|
-
var _a;
|
58
|
-
var scrollParentElement = index_1.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
|
-
* unstable_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
|
-
unstable_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: index_1.getBoundary(container, flipBoundary),
|
115
|
-
},
|
116
|
-
},
|
117
|
-
overflowBoundary && {
|
118
|
-
name: 'preventOverflow',
|
119
|
-
options: {
|
120
|
-
altBoundary: true,
|
121
|
-
boundary: index_1.getBoundary(container, overflowBoundary),
|
122
|
-
},
|
123
|
-
},
|
124
|
-
{
|
125
|
-
name: 'onUpdate',
|
126
|
-
enabled: true,
|
127
|
-
phase: 'afterWrite',
|
128
|
-
fn: handleStateUpdate,
|
129
|
-
},
|
130
|
-
autoSize && {
|
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 applies the max sizes when overflow is detected
|
134
|
-
name: 'applyMaxSize',
|
135
|
-
enabled: true,
|
136
|
-
phase: 'beforeWrite',
|
137
|
-
requiresIfExists: ['offset', 'preventOverflow', 'flip'],
|
138
|
-
options: {
|
139
|
-
altBoundary: true,
|
140
|
-
boundary: index_1.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 = state.placement.split('-')[0];
|
148
|
-
var widthProp = basePlacement === 'left' ? 'left' : 'right';
|
149
|
-
var heightProp = basePlacement === 'top' ? 'top' : 'bottom';
|
150
|
-
if (overflow[widthProp] > 0 && (autoSize === true || autoSize === 'width')) {
|
151
|
-
state.styles.popper.maxWidth = width - overflow[widthProp] - x + "px";
|
152
|
-
}
|
153
|
-
if (overflow[heightProp] > 0 && (autoSize === true || autoSize === 'height')) {
|
154
|
-
state.styles.popper.maxHeight = height - overflow[heightProp] - y + "px";
|
155
|
-
}
|
156
|
-
},
|
157
|
-
},
|
158
|
-
/**
|
159
|
-
* This modifier is necessary in order to render the pointer. Refs are resolved in effects, so it can't be
|
160
|
-
* placed under computed modifiers. Deep merge is not required as this modifier has only these properties.
|
161
|
-
*/
|
162
|
-
{
|
163
|
-
name: 'arrow',
|
164
|
-
enabled: !!arrow,
|
165
|
-
options: { element: arrow, padding: arrowPadding },
|
166
|
-
},
|
167
|
-
].filter(Boolean); // filter boolean conditional spreading values
|
168
|
-
var popperOptions = {
|
169
|
-
modifiers: modifiers,
|
170
|
-
placement: placement,
|
171
|
-
strategy: strategy,
|
172
|
-
onFirstUpdate: function (state) { return handleStateUpdate({ state: state }); },
|
173
|
-
};
|
174
|
-
return popperOptions;
|
175
|
-
}, [
|
176
|
-
autoSize,
|
177
|
-
flipBoundary,
|
178
|
-
offsetModifier,
|
179
|
-
overflowBoundary,
|
180
|
-
arrowPadding,
|
181
|
-
placement,
|
182
|
-
strategy,
|
183
|
-
unstable_disableTether,
|
184
|
-
unstable_pinned,
|
185
|
-
// These can be skipped from deps as they will not ever change
|
186
|
-
handleStateUpdate,
|
187
|
-
popperOriginalPositionRef,
|
188
|
-
]);
|
189
|
-
}
|
190
|
-
/**
|
191
|
-
* Exposes Popper positioning API via React hook. Contains few important differences between an official "react-popper"
|
192
|
-
* package:
|
193
|
-
* - style attributes are applied directly on DOM to avoid re-renders
|
194
|
-
* - refs changes and resolution is handled properly without re-renders
|
195
|
-
* - contains a specific to React fix related to initial positioning when containers have components with managed focus
|
196
|
-
* to avoid focus jumps
|
197
|
-
*/
|
198
|
-
function usePopper(options) {
|
199
|
-
if (options === void 0) { options = {}; }
|
200
|
-
var _a = options.enabled, enabled = _a === void 0 ? true : _a;
|
201
|
-
var isFirstMount = react_utilities_1.useFirstMount();
|
202
|
-
var popperOriginalPositionRef = React.useRef('absolute');
|
203
|
-
var resolvePopperOptions = usePopperOptions(options, popperOriginalPositionRef);
|
204
|
-
var popperInstanceRef = React.useRef(null);
|
205
|
-
var handlePopperUpdate = react_utilities_1.useEventCallback(function () {
|
206
|
-
var _a;
|
207
|
-
(_a = popperInstanceRef.current) === null || _a === void 0 ? void 0 : _a.destroy();
|
208
|
-
popperInstanceRef.current = null;
|
209
|
-
var popperInstance = null;
|
210
|
-
if (index_1.isBrowser() && enabled) {
|
211
|
-
if (targetRef.current && containerRef.current) {
|
212
|
-
popperInstance = PopperJs.createPopper(targetRef.current, containerRef.current, resolvePopperOptions(targetRef.current, containerRef.current, arrowRef.current));
|
213
|
-
}
|
214
|
-
}
|
215
|
-
if (popperInstance) {
|
216
|
-
/**
|
217
|
-
* The patch updates `.forceUpdate()` Popper function which restores the original position before the first
|
218
|
-
* forceUpdate() call. See also "positionStyleFix" modifier in usePopperOptions().
|
219
|
-
*/
|
220
|
-
var originalForceUpdate_1 = popperInstance.forceUpdate;
|
221
|
-
popperInstance.isFirstRun = true;
|
222
|
-
popperInstance.forceUpdate = function () {
|
223
|
-
var _a;
|
224
|
-
if ((_a = popperInstance) === null || _a === void 0 ? void 0 : _a.isFirstRun) {
|
225
|
-
popperInstance.state.elements.popper.style.position = popperOriginalPositionRef.current;
|
226
|
-
popperInstance.isFirstRun = false;
|
227
|
-
}
|
228
|
-
originalForceUpdate_1();
|
229
|
-
};
|
230
|
-
}
|
231
|
-
popperInstanceRef.current = popperInstance;
|
232
|
-
});
|
233
|
-
// Refs are managed by useCallbackRef() to handle ref updates scenarios.
|
234
|
-
//
|
235
|
-
// The first scenario are updates for a targetRef, we can handle it properly only via callback refs, but it causes
|
236
|
-
// re-renders (we would like to avoid them).
|
237
|
-
//
|
238
|
-
// The second problem is related to refs resolution on React's layer: refs are resolved in the same order as effects
|
239
|
-
// that causes an issue when you have a container inside a target, for example: a menu in ChatMessage.
|
240
|
-
//
|
241
|
-
// function ChatMessage(props) {
|
242
|
-
// <div className="message" ref={targetRef}> // 3) ref will be resolved only now, but it's too late already
|
243
|
-
// <Popper target={targetRef}> // 2) create a popper instance
|
244
|
-
// <div className="menu" /> // 1) capture ref from this element
|
245
|
-
// </Popper>
|
246
|
-
// </div>
|
247
|
-
// }
|
248
|
-
//
|
249
|
-
// Check a demo on CodeSandbox: https://codesandbox.io/s/popper-refs-emy60.
|
250
|
-
//
|
251
|
-
// This again can be solved with callback refs. It's not a huge issue as with hooks we are moving popper's creation
|
252
|
-
// to ChatMessage itself, however, without `useCallback()` refs it's still a Pandora box.
|
253
|
-
var targetRef = index_1.useCallbackRef(null, handlePopperUpdate, true);
|
254
|
-
var containerRef = index_1.useCallbackRef(null, handlePopperUpdate, true);
|
255
|
-
var arrowRef = index_1.useCallbackRef(null, handlePopperUpdate, true);
|
256
|
-
React.useImperativeHandle(options.containerRef, function () { return ({
|
257
|
-
updatePosition: function () {
|
258
|
-
var _a;
|
259
|
-
(_a = popperInstanceRef.current) === null || _a === void 0 ? void 0 : _a.update();
|
260
|
-
},
|
261
|
-
}); }, []);
|
262
|
-
react_utilities_1.useIsomorphicLayoutEffect(function () {
|
263
|
-
handlePopperUpdate();
|
264
|
-
return function () {
|
265
|
-
var _a;
|
266
|
-
(_a = popperInstanceRef.current) === null || _a === void 0 ? void 0 : _a.destroy();
|
267
|
-
popperInstanceRef.current = null;
|
268
|
-
};
|
269
|
-
}, [options.enabled]);
|
270
|
-
react_utilities_1.useIsomorphicLayoutEffect(function () {
|
271
|
-
var _a;
|
272
|
-
if (!isFirstMount) {
|
273
|
-
(_a = popperInstanceRef.current) === null || _a === void 0 ? void 0 : _a.setOptions(resolvePopperOptions(targetRef.current, containerRef.current, arrowRef.current));
|
274
|
-
}
|
275
|
-
}, [resolvePopperOptions]);
|
276
|
-
|
277
|
-
return { targetRef: targetRef, containerRef: containerRef, arrowRef: arrowRef };
|
278
|
-
}
|
279
|
-
exports.usePopper = usePopper;
|
280
|
-
});
|
281
|
-
//# sourceMappingURL=usePopper.js.map
|
package/lib-amd/usePopper.js.map
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"usePopper.js","sourceRoot":"../src/","sources":["usePopper.ts"],"names":[],"mappings":";;;IAiBA,EAAE;IACF,uDAAuD;IACvD,EAAE;IAEF;;;OAGG;IACH,SAAS,gBAAgB,CAAC,IAAU;;QAClC,gJAAgJ;QAChJ,IAAM,sBAAsB,GAC1B,IAAI,CAAC,QAAQ,KAAK,QAAQ;YAC1B,IAAI,CAAC,QAAQ,KAAK,OAAO;YACzB,IAAI,CAAC,QAAQ,KAAK,QAAQ;YAC1B,IAAI,CAAC,QAAQ,KAAK,UAAU,CAAC;QAE/B,IAAI,sBAAsB,EAAE;YAC1B,OAAO,CAAC,QAAC,6BAAqB,CAAC,IAAI,CAAC,0CAAE,YAAY,CAAC,SAAS,CAAA,CAAC;SAC9D;QAED,OAAO,KAAK,CAAC;IACf,CAAC;IAED,SAAS,kBAAkB,CAAC,IAAU;QACpC,OAAO,gBAAgB,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,aAAa,CAAC,CAAC,CAAC,UAAU,CAAC,WAAW,CAAC;IACpF,CAAC;IAED;;;;;;OAMG;IACH,SAAS,gBAAgB,CAAC,OAAsB,EAAE,yBAAyD;QAEvG,IAAA,2BAAQ,EACR,mCAAY,EACZ,uBAAM,EACN,mCAAY,EACZ,qCAAa,EACb,2CAAgB;QAChB,gEAAgE;QAChE,uDAAsB;QACtB,gEAAgE;QAChE,yCAAe,CACL;QAEZ,IAAM,KAAK,GAAG,iCAAS,EAAE,CAAC,GAAG,KAAK,KAAK,CAAC;QACxC,IAAM,SAAS,GAAG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oBAEH,aAAO,UAAU,0CAAE,QAAQ,IAAI;wBAC7B,IAAM,IAAI,GAAG,UAAU,CAAC,WAAW,CAAC;wBACpC,sCAAsC;wBACtC,OAAO,CAAC,IAAI,CAAC,WAAW,EAAE,IAAI,CAAC,CAAC;wBAChC,sCAAsC;wBACtC,OAAO,CAAC,IAAI,CACV;4BACE,gGAAgG;4BAChG,qGAAqG;4BACrG,2EAA2E;4BAC3E,uEAAuE;4BACvE,IAAI;4BACJ,yFAAyF;4BACzF,oGAAoG;4BACpG,kGAAkG;4BAClG,WAAW;4BACX,8FAA4F;4BAC5F,6FAA6F;4BAC7F,IAAI;4BACJ,2FAA2F;4BAC3F,2CAA2C;4BAC3C,8EAA8E;yBAC/E,CAAC,IAAI,CAAC,GAAG,CAAC,CACZ,CAAC;qBACH;iBACF;gBACD,mDAAmD;gBACnD,0EAA0E;gBAC1E,uDAAuD;YACzD,CAAC,EAAE,EAAE,CAAC,CAAC;SACR;QAED,OAAO,EAAE,SAAS,WAAA,EAAE,YAAY,cAAA,EAAE,QAAQ,UAAA,EAAE,CAAC;IAC/C,CAAC;IAzJD,8BAyJC","sourcesContent":["import { useEventCallback, useIsomorphicLayoutEffect, useFirstMount } from '@fluentui/react-utilities';\nimport { useFluent } from '@fluentui/react-shared-contexts';\nimport {\n isBrowser,\n getScrollParent,\n applyRtlToOffset,\n getPlacement,\n getReactFiberFromNode,\n getBoundary,\n useCallbackRef,\n} from './utils/index';\nimport * as PopperJs from '@popperjs/core';\nimport * as React from 'react';\n\nimport { PopperOptions } from './types';\ntype PopperInstance = PopperJs.Instance & { isFirstRun?: boolean };\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: PopperOptions, popperOriginalPositionRef: React.MutableRefObject<string>) {\n const {\n autoSize,\n flipBoundary,\n offset,\n arrowPadding,\n onStateUpdate,\n overflowBoundary,\n // eslint-disable-next-line @typescript-eslint/naming-convention\n unstable_disableTether,\n // eslint-disable-next-line @typescript-eslint/naming-convention\n unstable_pinned,\n } = options;\n\n const isRtl = useFluent().dir === 'rtl';\n const placement = getPlacement(options.align, options.position, isRtl);\n const strategy = options.positionFixed ? 'fixed' : 'absolute';\n\n const handleStateUpdate = useEventCallback(({ state }: { state: Partial<PopperJs.State> }) => {\n if (onStateUpdate) {\n onStateUpdate(state);\n }\n });\n\n const offsetModifier = React.useMemo(\n () =>\n offset\n ? {\n name: 'offset',\n options: { offset: isRtl ? applyRtlToOffset(offset) : 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 /**\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 * unstable_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 unstable_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 name: 'onUpdate',\n enabled: true,\n phase: 'afterWrite' as PopperJs.ModifierPhases,\n fn: handleStateUpdate,\n },\n\n autoSize && {\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 applies the max sizes when overflow is detected\n name: 'applyMaxSize',\n enabled: true,\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] = state.placement.split('-');\n\n const widthProp: keyof PopperJs.SideObject = basePlacement === 'left' ? 'left' : 'right';\n const heightProp: keyof PopperJs.SideObject = basePlacement === 'top' ? 'top' : 'bottom';\n\n if (overflow[widthProp] > 0 && (autoSize === true || autoSize === 'width')) {\n state.styles.popper.maxWidth = `${width - overflow[widthProp] - x}px`;\n }\n if (overflow[heightProp] > 0 && (autoSize === true || autoSize === 'height')) {\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 ].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 onFirstUpdate: state => handleStateUpdate({ state }),\n };\n\n return popperOptions;\n },\n [\n autoSize,\n flipBoundary,\n offsetModifier,\n overflowBoundary,\n arrowPadding,\n placement,\n strategy,\n unstable_disableTether,\n unstable_pinned,\n\n // These can be skipped from deps as they will not ever change\n handleStateUpdate,\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 usePopper(\n options: PopperOptions = {},\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 let popperInstance: PopperInstance | null = null;\n\n if (isBrowser() && enabled) {\n if (targetRef.current && containerRef.current) {\n popperInstance = PopperJs.createPopper(\n targetRef.current,\n containerRef.current,\n resolvePopperOptions(targetRef.current, 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 React.useImperativeHandle(\n options.containerRef,\n () => ({\n updatePosition: () => {\n popperInstanceRef.current?.update();\n },\n }),\n [],\n );\n\n useIsomorphicLayoutEffect(() => {\n handlePopperUpdate();\n\n return () => {\n popperInstanceRef.current?.destroy();\n popperInstanceRef.current = null;\n };\n }, [options.enabled]);\n useIsomorphicLayoutEffect(() => {\n if (!isFirstMount) {\n popperInstanceRef.current?.setOptions(\n resolvePopperOptions(targetRef.current, containerRef.current, arrowRef.current),\n );\n }\n }, [resolvePopperOptions]);\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 // eslint-disable-next-line deprecation/deprecation\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"]}
|
@@ -1,6 +0,0 @@
|
|
1
|
-
import * as PopperJs from '@popperjs/core';
|
2
|
-
import { 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,23 +0,0 @@
|
|
1
|
-
define(["require", "exports", "./getScrollParent"], function (require, exports, getScrollParent_1) {
|
2
|
-
"use strict";
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
4
|
-
/**
|
5
|
-
* Allows to mimic a behavior from V1 of Popper and accept `window` and `scrollParent` as strings.
|
6
|
-
*/
|
7
|
-
function getBoundary(element, boundary) {
|
8
|
-
var _a, _b;
|
9
|
-
if (boundary === 'window') {
|
10
|
-
return ((_a = element) === null || _a === void 0 ? void 0 : _a.ownerDocument).documentElement;
|
11
|
-
}
|
12
|
-
if (boundary === 'scrollParent') {
|
13
|
-
var boundariesNode = getScrollParent_1.getScrollParent(element);
|
14
|
-
if (boundariesNode.nodeName === 'BODY') {
|
15
|
-
boundariesNode = ((_b = element) === null || _b === void 0 ? void 0 : _b.ownerDocument).documentElement;
|
16
|
-
}
|
17
|
-
return boundariesNode;
|
18
|
-
}
|
19
|
-
return boundary;
|
20
|
-
}
|
21
|
-
exports.getBoundary = getBoundary;
|
22
|
-
});
|
23
|
-
//# sourceMappingURL=getBoundary.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"getBoundary.js","sourceRoot":"../src/","sources":["utils/getBoundary.ts"],"names":[],"mappings":";;;IAKA;;OAEG;IACH,SAAgB,WAAW,CAAC,OAA2B,EAAE,QAAmB;;QAC1E,IAAI,QAAQ,KAAK,QAAQ,EAAE;YACzB,OAAO,CAAA,MAAA,OAAO,0CAAE,aAAc,CAAA,CAAC,eAAe,CAAC;SAChD;QAED,IAAI,QAAQ,KAAK,cAAc,EAAE;YAC/B,IAAI,cAAc,GAAG,iCAAe,CAAC,OAAO,CAAC,CAAC;YAE9C,IAAI,cAAc,CAAC,QAAQ,KAAK,MAAM,EAAE;gBACtC,cAAc,GAAG,CAAA,MAAA,OAAO,0CAAE,aAAc,CAAA,CAAC,eAAe,CAAC;aAC1D;YAED,OAAO,cAA6B,CAAC;SACtC;QAED,OAAO,QAAQ,CAAC;IAClB,CAAC;IAhBD,kCAgBC","sourcesContent":["import * as PopperJs from '@popperjs/core';\n\nimport { getScrollParent } from './getScrollParent';\nimport { 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 = getScrollParent(element);\n\n if (boundariesNode.nodeName === 'BODY') {\n boundariesNode = element?.ownerDocument!.documentElement;\n }\n\n return boundariesNode as HTMLElement;\n }\n\n return boundary;\n}\n"]}
|
@@ -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,47 +0,0 @@
|
|
1
|
-
define(["require", "exports"], function (require, exports) {
|
2
|
-
"use strict";
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
4
|
-
var WorkTag;
|
5
|
-
(function (WorkTag) {
|
6
|
-
WorkTag[WorkTag["FunctionComponent"] = 0] = "FunctionComponent";
|
7
|
-
WorkTag[WorkTag["ClassComponent"] = 1] = "ClassComponent";
|
8
|
-
WorkTag[WorkTag["IndeterminateComponent"] = 2] = "IndeterminateComponent";
|
9
|
-
WorkTag[WorkTag["HostRoot"] = 3] = "HostRoot";
|
10
|
-
WorkTag[WorkTag["HostPortal"] = 4] = "HostPortal";
|
11
|
-
WorkTag[WorkTag["HostComponent"] = 5] = "HostComponent";
|
12
|
-
WorkTag[WorkTag["HostText"] = 6] = "HostText";
|
13
|
-
WorkTag[WorkTag["Fragment"] = 7] = "Fragment";
|
14
|
-
WorkTag[WorkTag["Mode"] = 8] = "Mode";
|
15
|
-
WorkTag[WorkTag["ContextConsumer"] = 9] = "ContextConsumer";
|
16
|
-
WorkTag[WorkTag["ContextProvider"] = 10] = "ContextProvider";
|
17
|
-
WorkTag[WorkTag["ForwardRef"] = 11] = "ForwardRef";
|
18
|
-
WorkTag[WorkTag["Profiler"] = 12] = "Profiler";
|
19
|
-
WorkTag[WorkTag["SuspenseComponent"] = 13] = "SuspenseComponent";
|
20
|
-
WorkTag[WorkTag["MemoComponent"] = 14] = "MemoComponent";
|
21
|
-
WorkTag[WorkTag["SimpleMemoComponent"] = 15] = "SimpleMemoComponent";
|
22
|
-
WorkTag[WorkTag["LazyComponent"] = 16] = "LazyComponent";
|
23
|
-
WorkTag[WorkTag["IncompleteClassComponent"] = 17] = "IncompleteClassComponent";
|
24
|
-
WorkTag[WorkTag["DehydratedFragment"] = 18] = "DehydratedFragment";
|
25
|
-
WorkTag[WorkTag["SuspenseListComponent"] = 19] = "SuspenseListComponent";
|
26
|
-
WorkTag[WorkTag["FundamentalComponent"] = 20] = "FundamentalComponent";
|
27
|
-
WorkTag[WorkTag["ScopeComponent"] = 21] = "ScopeComponent";
|
28
|
-
})(WorkTag || (WorkTag = {}));
|
29
|
-
function getReactFiberFromNode(elm) {
|
30
|
-
if (!elm) {
|
31
|
-
return null;
|
32
|
-
}
|
33
|
-
for (var k in elm) {
|
34
|
-
// React 16 uses "__reactInternalInstance$" prefix
|
35
|
-
// React 17 uses "__reactFiber$" prefix
|
36
|
-
// https://github.com/facebook/react/pull/18377
|
37
|
-
if (k.indexOf('__reactInternalInstance$') === 0 || k.indexOf('__reactFiber$') === 0) {
|
38
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
39
|
-
// @ts-ignore
|
40
|
-
return elm[k];
|
41
|
-
}
|
42
|
-
}
|
43
|
-
throw new Error('getReactFiber(): Failed to find a React Fiber on a node');
|
44
|
-
}
|
45
|
-
exports.getReactFiberFromNode = getReactFiberFromNode;
|
46
|
-
});
|
47
|
-
//# sourceMappingURL=getReactFiberFromNode.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"getReactFiberFromNode.js","sourceRoot":"../src/","sources":["utils/getReactFiberFromNode.ts"],"names":[],"mappings":";;;IAuEA,IAAK,OAuBJ;IAvBD,WAAK,OAAO;QACV,+DAAqB,CAAA;QACrB,yDAAkB,CAAA;QAClB,yEAA0B,CAAA;QAC1B,6CAAY,CAAA;QACZ,iDAAc,CAAA;QACd,uDAAiB,CAAA;QACjB,6CAAY,CAAA;QACZ,6CAAY,CAAA;QACZ,qCAAQ,CAAA;QACR,2DAAmB,CAAA;QACnB,4DAAoB,CAAA;QACpB,kDAAe,CAAA;QACf,8CAAa,CAAA;QACb,gEAAsB,CAAA;QACtB,wDAAkB,CAAA;QAClB,oEAAwB,CAAA;QACxB,wDAAkB,CAAA;QAClB,8EAA6B,CAAA;QAC7B,kEAAuB,CAAA;QACvB,wEAA0B,CAAA;QAC1B,sEAAyB,CAAA;QACzB,0DAAmB,CAAA;IACrB,CAAC,EAvBI,OAAO,KAAP,OAAO,QAuBX;IA+JD,SAAgB,qBAAqB,CAAC,GAAqB;QACzD,IAAI,CAAC,GAAG,EAAE;YACR,OAAO,IAAI,CAAC;SACb;QAED,KAAK,IAAM,CAAC,IAAI,GAAG,EAAE;YACnB,kDAAkD;YAClD,uCAAuC;YACvC,+CAA+C;YAC/C,IAAI,CAAC,CAAC,OAAO,CAAC,0BAA0B,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,eAAe,CAAC,KAAK,CAAC,EAAE;gBACnF,6DAA6D;gBAC7D,aAAa;gBACb,OAAO,GAAG,CAAC,CAAC,CAAC,CAAC;aACf;SACF;QAED,MAAM,IAAI,KAAK,CAAC,yDAAyD,CAAC,CAAC;IAC7E,CAAC;IAjBD,sDAiBC","sourcesContent":["import * as React from 'react';\n\n// ========================================================\n// react/packages/shared/ReactTypes.js\n// ========================================================\n\ntype ReactEventResponder<E, C> = {\n $$typeof: Symbol | number;\n displayName: string;\n targetEventTypes: null | string[];\n rootEventTypes: null | string[];\n getInitialState: null | ((props: Object) => Object);\n onEvent: null | ((event: E, context: C, props: Object, state: Object) => void);\n onRootEvent: null | ((event: E, context: C, props: Object, state: Object) => void);\n onMount: null | ((context: C, props: Object, state: Object) => void);\n onUnmount: null | ((context: C, props: Object, state: Object) => void);\n};\n\ntype ReactEventResponderInstance<E, C> = {\n fiber: Object;\n props: Object;\n responder: ReactEventResponder<E, C>;\n rootEventTypes: null | Set<string>;\n state: Object;\n};\n\n// ========================================================\n// react/packages/react-reconciler/src/ReactFiberHooks.js\n// ========================================================\n\nexport type HookType =\n | 'useState'\n | 'useReducer'\n | 'useContext'\n | 'useRef'\n | 'useEffect'\n | 'useLayoutEffect'\n | 'useCallback'\n | 'useMemo'\n | 'useImperativeHandle'\n | 'useDebugValue'\n | 'useResponder';\n\ntype ReactProviderType<T> = {\n $$typeof: Symbol | number;\n _context: ReactContext<T>;\n};\n\ntype ReactContext<T> = {\n $$typeof: Symbol | number;\n Consumer: ReactContext<T>;\n Provider: ReactProviderType<T>;\n\n _calculateChangedBits: ((a: T, b: T) => number) | null;\n\n _currentValue: T;\n _currentValue2: T;\n _threadCount: number;\n\n // DEV only\n _currentRenderer?: Object | null;\n _currentRenderer2?: Object | null;\n};\n\ntype ContextDependency<T> = {\n context: ReactContext<T>;\n observedBits: number;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n next: ContextDependency<any> | null;\n};\n\nenum WorkTag {\n FunctionComponent = 0,\n ClassComponent = 1,\n IndeterminateComponent = 2, // Before we know whether it is function or class\n HostRoot = 3, // Root of a host tree. Could be nested inside another node.\n HostPortal = 4, // A subtree. Could be an entry point to a different renderer.\n HostComponent = 5,\n HostText = 6,\n Fragment = 7,\n Mode = 8,\n ContextConsumer = 9,\n ContextProvider = 10,\n ForwardRef = 11,\n Profiler = 12,\n SuspenseComponent = 13,\n MemoComponent = 14,\n SimpleMemoComponent = 15,\n LazyComponent = 16,\n IncompleteClassComponent = 17,\n DehydratedFragment = 18,\n SuspenseListComponent = 19,\n FundamentalComponent = 20,\n ScopeComponent = 21,\n}\n\ntype Source = {\n fileName: string;\n lineNumber: number;\n};\n\ntype ExpirationTime = number;\n\ntype Dependencies = {\n expirationTime: ExpirationTime;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n firstContext: ContextDependency<any> | null;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n responders: Map<ReactEventResponder<any, any>, ReactEventResponderInstance<any, any>> | null;\n};\n\n// ========================================================\n// react/packages/react-reconciler/src/ReactFiber.js\n// ========================================================\n\n// A Fiber is work on a Component that needs to be done or was done. There can\n// be more than one per component.\n\nexport type Fiber = {\n // These first fields are conceptually members of an Instance. This used to\n // be split into a separate type and intersected with the other Fiber fields,\n // but until Flow fixes its intersection bugs, we've merged them into a\n // single type.\n\n // An Instance is shared between all versions of a component. We can easily\n // break this out into a separate object to avoid copying so much to the\n // alternate versions of the tree. We put this on a single object for now to\n // minimize the number of objects created during the initial render.\n\n // Tag identifying the type of fiber.\n tag: WorkTag;\n\n // Unique identifier of this child.\n key: null | string;\n\n // The value of element.type which is used to preserve the identity during\n // reconciliation of this child.\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n elementType: any;\n\n // The resolved function/class/ associated with this fiber.\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n type: any;\n\n // The local state associated with this fiber.\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n stateNode: any;\n\n // Conceptual aliases\n // parent : Instance -> return The parent happens to be the same as the\n // return fiber since we've merged the fiber and instance.\n\n // Remaining fields belong to Fiber\n\n // The Fiber to return to after finishing processing this one.\n // This is effectively the parent, but there can be multiple parents (two)\n // so this is only the parent of the thing we're currently processing.\n // It is conceptually the same as the return address of a stack frame.\n return: Fiber | null;\n\n // Singly Linked List Tree Structure.\n child: Fiber | null;\n sibling: Fiber | null;\n index: number;\n\n // The ref last used to attach this node.\n // I'll avoid adding an owner field for prod and model that as functions.\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ref: React.Ref<any>;\n\n // Input is the data coming into process this fiber. Arguments. Props.\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n pendingProps: any; // This type will be more specific once we overload the tag.\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n memoizedProps: any; // The props used to create the output.\n\n // A queue of state updates and callbacks.\n // updateQueue: UpdateQueue<any> | null,\n\n // The state used to create the output\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n memoizedState: any;\n\n // Dependencies (contexts, events) for this fiber, if it has any\n dependencies: Dependencies | null;\n\n // // Bitfield that describes properties about the fiber and its subtree. E.g.\n // // the ConcurrentMode flag indicates whether the subtree should be async-by-\n // // default. When a fiber is created, it inherits the mode of its\n // // parent. Additional flags can be set at creation time, but after that the\n // // value should remain unchanged throughout the fiber's lifetime, particularly\n // // before its child fibers are created.\n // mode: TypeOfMode\n //\n // // Effect\n // effectTag: SideEffectTag\n\n // Singly linked list fast path to the next fiber with side-effects.\n nextEffect: Fiber | null;\n\n // The first and last fiber with side-effect within this subtree. This allows\n // us to reuse a slice of the linked list when we reuse the work done within\n // this fiber.\n firstEffect: Fiber | null;\n lastEffect: Fiber | null;\n\n // Represents a time in the future by which this work should be completed.\n // Does not include work found in its subtree.\n expirationTime: ExpirationTime;\n\n // This is used to quickly determine if a subtree has no pending changes.\n childExpirationTime: ExpirationTime;\n\n // This is a pooled version of a Fiber. Every fiber that gets updated will\n // eventually have a pair. There are cases when we can clean up pairs to save\n // memory if we need to.\n alternate: Fiber | null;\n\n // Time spent rendering this Fiber and its descendants for the current update.\n // This tells us how well the tree makes use of sCU for memoization.\n // It is reset to 0 each time we render and only updated when we don't bailout.\n // This field is only set when the enableProfilerTimer flag is enabled.\n actualDuration?: number;\n\n // If the Fiber is currently active in the \"render\" phase,\n // This marks the time at which the work began.\n // This field is only set when the enableProfilerTimer flag is enabled.\n actualStartTime?: number;\n\n // Duration of the most recent render time for this Fiber.\n // This value is not updated when we bailout for memoization purposes.\n // This field is only set when the enableProfilerTimer flag is enabled.\n selfBaseDuration?: number;\n\n // Sum of base times for all descendants of this Fiber.\n // This value bubbles up during the \"complete\" phase.\n // This field is only set when the enableProfilerTimer flag is enabled.\n treeBaseDuration?: number;\n\n // Conceptual aliases\n // workInProgress : Fiber -> alternate The alternate used for reuse happens\n // to be the same as work in progress.\n // __DEV__ only\n _debugID?: number;\n _debugSource?: Source | null;\n _debugOwner?: Fiber | null;\n _debugIsCurrentlyTiming?: boolean;\n _debugNeedsRemount?: boolean;\n\n // Used to verify that the order of hooks does not change between renders.\n _debugHookTypes?: HookType[] | null;\n};\n\nexport function getReactFiberFromNode(elm: Node | undefined): Fiber | null {\n if (!elm) {\n return null;\n }\n\n for (const k in elm) {\n // React 16 uses \"__reactInternalInstance$\" prefix\n // React 17 uses \"__reactFiber$\" prefix\n // https://github.com/facebook/react/pull/18377\n if (k.indexOf('__reactInternalInstance$') === 0 || k.indexOf('__reactFiber$') === 0) {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n return elm[k];\n }\n }\n\n throw new Error('getReactFiber(): Failed to find a React Fiber on a node');\n}\n"]}
|
@@ -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;
|
@@ -1,55 +0,0 @@
|
|
1
|
-
define(["require", "exports"], function (require, exports) {
|
2
|
-
"use strict";
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
4
|
-
/**
|
5
|
-
* Returns the parent node or the host of the node argument.
|
6
|
-
* @param node - DOM node.
|
7
|
-
* @returns - parent DOM node.
|
8
|
-
*/
|
9
|
-
exports.getParentNode = function (node) {
|
10
|
-
if (node.nodeName === 'HTML') {
|
11
|
-
return node;
|
12
|
-
}
|
13
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
14
|
-
return node.parentNode || node.host;
|
15
|
-
};
|
16
|
-
/**
|
17
|
-
* Returns CSS styles of the given node.
|
18
|
-
* @param node - DOM node.
|
19
|
-
* @returns - CSS styles.
|
20
|
-
*/
|
21
|
-
var getStyleComputedProperty = function (node) {
|
22
|
-
var _a;
|
23
|
-
if (node.nodeType !== 1) {
|
24
|
-
return {};
|
25
|
-
}
|
26
|
-
var window = (_a = node.ownerDocument) === null || _a === void 0 ? void 0 : _a.defaultView;
|
27
|
-
return window.getComputedStyle(node, null);
|
28
|
-
};
|
29
|
-
/**
|
30
|
-
* Returns the first scrollable parent of the given element.
|
31
|
-
* @param node - DOM node.
|
32
|
-
* @returns - the first scrollable parent.
|
33
|
-
*/
|
34
|
-
exports.getScrollParent = function (node) {
|
35
|
-
// Return body, `getScroll` will take care to get the correct `scrollTop` from it
|
36
|
-
var parentNode = node && exports.getParentNode(node);
|
37
|
-
// eslint-disable-next-line
|
38
|
-
if (!parentNode)
|
39
|
-
return document.body;
|
40
|
-
switch (parentNode.nodeName) {
|
41
|
-
case 'HTML':
|
42
|
-
case 'BODY':
|
43
|
-
return parentNode.ownerDocument.body;
|
44
|
-
case '#document':
|
45
|
-
return parentNode.body;
|
46
|
-
}
|
47
|
-
// If any of the overflow props is defined for the node then we return it as the parent
|
48
|
-
var _a = getStyleComputedProperty(parentNode), overflow = _a.overflow, overflowX = _a.overflowX, overflowY = _a.overflowY;
|
49
|
-
if (/(auto|scroll|overlay)/.test(overflow + overflowY + overflowX)) {
|
50
|
-
return parentNode;
|
51
|
-
}
|
52
|
-
return exports.getScrollParent(parentNode);
|
53
|
-
};
|
54
|
-
});
|
55
|
-
//# sourceMappingURL=getScrollParent.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"getScrollParent.js","sourceRoot":"../src/","sources":["utils/getScrollParent.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OM node.\n * @returns - parent DOM node.\n */\nexport const getParentNode = (node: HTMLElement): HTMLElement => {\n if (node.nodeName === 'HTML') {\n return node;\n }\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n return node.parentNode || (node as any).host;\n};\n\n/**\n * Returns CSS styles of the given node.\n * @param node - DOM node.\n * @returns - CSS styles.\n */\nconst getStyleComputedProperty = (node: HTMLElement): Partial<CSSStyleDeclaration> => {\n if (node.nodeType !== 1) {\n return {};\n }\n\n const window = node.ownerDocument?.defaultView;\n return window!.getComputedStyle(node, null);\n};\n\n/**\n * Returns the first scrollable parent of the given element.\n * @param node - DOM node.\n * @returns - the first scrollable parent.\n */\nexport const getScrollParent = (node: Document | HTMLElement | null): HTMLElement => {\n // Return body, `getScroll` will take care to get the correct `scrollTop` from it\n const parentNode = node && getParentNode(node as HTMLElement);\n // eslint-disable-next-line\n if (!parentNode) return document.body;\n\n switch (parentNode.nodeName) {\n case 'HTML':\n case 'BODY':\n return parentNode.ownerDocument!.body;\n case '#document':\n return ((parentNode as unknown) as Document).body;\n }\n\n // If any of the overflow props is defined for the node then we return it as the parent\n const { overflow, overflowX, overflowY } = getStyleComputedProperty(parentNode);\n if (/(auto|scroll|overlay)/.test(overflow! + overflowY! + overflowX)) {\n return parentNode;\n }\n\n return getScrollParent(parentNode);\n};\n"]}
|