@geneui/components 2.16.0-canary-36aab18-26082024 → 2.16.0-canary-7598c7a-11092024
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ActionableList/index.js +4 -5
- package/AdvancedSearch/index.js +3 -4
- package/Alert/index.js +1 -1
- package/Breadcrumb/index.js +2 -3
- package/Card/index.js +2 -3
- package/CardList/index.js +7 -8
- package/{CellMeasurerCache-b172f99b.js → CellMeasurerCache-e50d357a.js} +1 -1
- package/Charts/index.js +1 -1
- package/Checkbox/index.js +3 -3
- package/CheckboxGroup/index.js +3 -3
- package/CheckboxGroupWithSearch/index.js +2 -3
- package/ComboBox/index.js +3 -3
- package/Copy/index.js +3 -3
- package/Counter/index.js +2 -3
- package/DateFilter/index.js +3 -4
- package/DatePickerInput/index.js +4 -5
- package/Drawer/index.js +3 -3
- package/Dropdown/index.js +5 -6
- package/Editor/index.js +1 -1
- package/ExtendedInput/index.js +3 -3
- package/Form/index.js +5 -6
- package/FormableCheckbox/index.js +4 -4
- package/FormableDatePicker/index.js +5 -6
- package/FormableDropdown/index.js +5 -6
- package/FormableEditor/index.js +2 -2
- package/{FormableHOC-b26c5b16.js → FormableHOC-8c6104f7.js} +1 -1
- package/FormableMultiSelectDropdown/index.js +5 -6
- package/FormableNumberInput/index.js +4 -4
- package/FormableRadio/index.js +2 -2
- package/FormableSwitcher/index.js +2 -2
- package/FormableTextInput/index.js +4 -4
- package/FormableUploader/index.js +3 -4
- package/GeneUIProvider/index.js +1 -0
- package/Grid/index.js +1 -1
- package/Holder/index.js +2 -3
- package/Image/index.js +5 -6
- package/ImagePreview/index.js +2 -3
- package/InteractiveWidget/index.js +2 -3
- package/Menu/index.js +3 -3
- package/MobilePopup/index.js +3 -3
- package/Modal/index.js +1 -1
- package/ModuleTitle/index.js +3 -3
- package/NavigationMenu/index.js +4 -4
- package/Notification/index.js +1 -1
- package/Option/index.js +3 -3
- package/Overlay/index.js +2 -3
- package/Overspread/index.js +5 -6
- package/Pagination/index.js +2 -3
- package/Popover/index.js +409 -4
- package/PopoverV2/index.js +2 -2
- package/Products/index.js +1 -1
- package/Profile/index.js +2 -3
- package/Radio/index.js +1 -1
- package/RadioGroup/index.js +1 -1
- package/Range/index.js +1 -1
- package/Scrollbar/index.js +1 -1
- package/Search/index.js +3 -3
- package/SearchWithDropdown/index.js +5 -6
- package/Section/index.js +1 -1
- package/Slider/index.js +3 -3
- package/Status/index.js +4 -4
- package/Steps/index.js +4 -4
- package/SuggestionList/index.js +1 -1
- package/Switcher/index.js +1 -1
- package/Table/index.js +14 -15
- package/TableCompositions/index.js +8 -9
- package/Tag/index.js +1 -1
- package/Textarea/index.js +3 -3
- package/TimePicker/index.js +35 -30
- package/Title/index.js +1 -1
- package/Toaster/index.js +1 -1
- package/Tooltip/index.js +10 -153
- package/TransferList/index.js +4 -5
- package/Uploader/index.js +2 -3
- package/ValidatableCheckbox/index.js +3 -3
- package/ValidatableDatePicker/index.js +4 -5
- package/ValidatableDropdown/index.js +4 -5
- package/ValidatableElements/index.js +4 -5
- package/ValidatableMultiSelectDropdown/index.js +4 -5
- package/ValidatableNumberInput/index.js +3 -3
- package/ValidatableRadio/index.js +1 -1
- package/ValidatableSwitcher/index.js +1 -1
- package/ValidatableTextInput/index.js +3 -3
- package/ValidatableTimeInput/index.js +3 -3
- package/ValidatableUploader/index.js +2 -3
- package/Widget/index.js +2 -3
- package/{configs-1fb8eed2.js → configs-00612ce0.js} +1 -1
- package/hooks/useDeviceType.js +1 -1
- package/{index-1beae3bb.js → index-071d6646.js} +3 -3
- package/index-17958262.js +3064 -0
- package/{index-18431aad.js → index-808e4e0e.js} +1 -1
- package/{index-617ffc3a.js → index-ac01f546.js} +6 -5
- package/index.js +9 -10
- package/lib/atoms/Button/Button.d.ts +1 -1
- package/lib/molecules/Tooltip/Tooltip.d.ts +62 -0
- package/lib/molecules/Tooltip/index.d.ts +1 -0
- package/package.json +2 -1
- package/{react-beautiful-dnd.esm-04c14563.js → react-beautiful-dnd.esm-899f6ed9.js} +2 -1
- package/{index-b1e429a7.js → redux-b3e598ca.js} +1 -272
- package/Popover-f4d1cac0.js +0 -411
|
@@ -0,0 +1,3064 @@
|
|
|
1
|
+
import { _ as __rest } from './tslib.es6-f211516f.js';
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import React__default, { useLayoutEffect, useEffect, useContext, useState, Children, Fragment, cloneElement } from 'react';
|
|
4
|
+
import * as ReactDOM from 'react-dom';
|
|
5
|
+
import { n as noop } from './index-a0e4e333.js';
|
|
6
|
+
import useDeviceType from './hooks/useDeviceType.js';
|
|
7
|
+
import { GeneUIDesignSystemContext } from './GeneUIProvider/index.js';
|
|
8
|
+
import { s as styleInject } from './style-inject.es-746bb8ed.js';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Custom positioning reference element.
|
|
12
|
+
* @see https://floating-ui.com/docs/virtual-elements
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
const min = Math.min;
|
|
16
|
+
const max = Math.max;
|
|
17
|
+
const round = Math.round;
|
|
18
|
+
const floor = Math.floor;
|
|
19
|
+
const createCoords = v => ({
|
|
20
|
+
x: v,
|
|
21
|
+
y: v
|
|
22
|
+
});
|
|
23
|
+
const oppositeSideMap = {
|
|
24
|
+
left: 'right',
|
|
25
|
+
right: 'left',
|
|
26
|
+
bottom: 'top',
|
|
27
|
+
top: 'bottom'
|
|
28
|
+
};
|
|
29
|
+
const oppositeAlignmentMap = {
|
|
30
|
+
start: 'end',
|
|
31
|
+
end: 'start'
|
|
32
|
+
};
|
|
33
|
+
function clamp(start, value, end) {
|
|
34
|
+
return max(start, min(value, end));
|
|
35
|
+
}
|
|
36
|
+
function evaluate(value, param) {
|
|
37
|
+
return typeof value === 'function' ? value(param) : value;
|
|
38
|
+
}
|
|
39
|
+
function getSide(placement) {
|
|
40
|
+
return placement.split('-')[0];
|
|
41
|
+
}
|
|
42
|
+
function getAlignment(placement) {
|
|
43
|
+
return placement.split('-')[1];
|
|
44
|
+
}
|
|
45
|
+
function getOppositeAxis(axis) {
|
|
46
|
+
return axis === 'x' ? 'y' : 'x';
|
|
47
|
+
}
|
|
48
|
+
function getAxisLength(axis) {
|
|
49
|
+
return axis === 'y' ? 'height' : 'width';
|
|
50
|
+
}
|
|
51
|
+
function getSideAxis(placement) {
|
|
52
|
+
return ['top', 'bottom'].includes(getSide(placement)) ? 'y' : 'x';
|
|
53
|
+
}
|
|
54
|
+
function getAlignmentAxis(placement) {
|
|
55
|
+
return getOppositeAxis(getSideAxis(placement));
|
|
56
|
+
}
|
|
57
|
+
function getAlignmentSides(placement, rects, rtl) {
|
|
58
|
+
if (rtl === void 0) {
|
|
59
|
+
rtl = false;
|
|
60
|
+
}
|
|
61
|
+
const alignment = getAlignment(placement);
|
|
62
|
+
const alignmentAxis = getAlignmentAxis(placement);
|
|
63
|
+
const length = getAxisLength(alignmentAxis);
|
|
64
|
+
let mainAlignmentSide = alignmentAxis === 'x' ? alignment === (rtl ? 'end' : 'start') ? 'right' : 'left' : alignment === 'start' ? 'bottom' : 'top';
|
|
65
|
+
if (rects.reference[length] > rects.floating[length]) {
|
|
66
|
+
mainAlignmentSide = getOppositePlacement(mainAlignmentSide);
|
|
67
|
+
}
|
|
68
|
+
return [mainAlignmentSide, getOppositePlacement(mainAlignmentSide)];
|
|
69
|
+
}
|
|
70
|
+
function getExpandedPlacements(placement) {
|
|
71
|
+
const oppositePlacement = getOppositePlacement(placement);
|
|
72
|
+
return [getOppositeAlignmentPlacement(placement), oppositePlacement, getOppositeAlignmentPlacement(oppositePlacement)];
|
|
73
|
+
}
|
|
74
|
+
function getOppositeAlignmentPlacement(placement) {
|
|
75
|
+
return placement.replace(/start|end/g, alignment => oppositeAlignmentMap[alignment]);
|
|
76
|
+
}
|
|
77
|
+
function getSideList(side, isStart, rtl) {
|
|
78
|
+
const lr = ['left', 'right'];
|
|
79
|
+
const rl = ['right', 'left'];
|
|
80
|
+
const tb = ['top', 'bottom'];
|
|
81
|
+
const bt = ['bottom', 'top'];
|
|
82
|
+
switch (side) {
|
|
83
|
+
case 'top':
|
|
84
|
+
case 'bottom':
|
|
85
|
+
if (rtl) return isStart ? rl : lr;
|
|
86
|
+
return isStart ? lr : rl;
|
|
87
|
+
case 'left':
|
|
88
|
+
case 'right':
|
|
89
|
+
return isStart ? tb : bt;
|
|
90
|
+
default:
|
|
91
|
+
return [];
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
function getOppositeAxisPlacements(placement, flipAlignment, direction, rtl) {
|
|
95
|
+
const alignment = getAlignment(placement);
|
|
96
|
+
let list = getSideList(getSide(placement), direction === 'start', rtl);
|
|
97
|
+
if (alignment) {
|
|
98
|
+
list = list.map(side => side + "-" + alignment);
|
|
99
|
+
if (flipAlignment) {
|
|
100
|
+
list = list.concat(list.map(getOppositeAlignmentPlacement));
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return list;
|
|
104
|
+
}
|
|
105
|
+
function getOppositePlacement(placement) {
|
|
106
|
+
return placement.replace(/left|right|bottom|top/g, side => oppositeSideMap[side]);
|
|
107
|
+
}
|
|
108
|
+
function expandPaddingObject(padding) {
|
|
109
|
+
return {
|
|
110
|
+
top: 0,
|
|
111
|
+
right: 0,
|
|
112
|
+
bottom: 0,
|
|
113
|
+
left: 0,
|
|
114
|
+
...padding
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
function getPaddingObject(padding) {
|
|
118
|
+
return typeof padding !== 'number' ? expandPaddingObject(padding) : {
|
|
119
|
+
top: padding,
|
|
120
|
+
right: padding,
|
|
121
|
+
bottom: padding,
|
|
122
|
+
left: padding
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
function rectToClientRect(rect) {
|
|
126
|
+
const {
|
|
127
|
+
x,
|
|
128
|
+
y,
|
|
129
|
+
width,
|
|
130
|
+
height
|
|
131
|
+
} = rect;
|
|
132
|
+
return {
|
|
133
|
+
width,
|
|
134
|
+
height,
|
|
135
|
+
top: y,
|
|
136
|
+
left: x,
|
|
137
|
+
right: x + width,
|
|
138
|
+
bottom: y + height,
|
|
139
|
+
x,
|
|
140
|
+
y
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function computeCoordsFromPlacement(_ref, placement, rtl) {
|
|
145
|
+
let {
|
|
146
|
+
reference,
|
|
147
|
+
floating
|
|
148
|
+
} = _ref;
|
|
149
|
+
const sideAxis = getSideAxis(placement);
|
|
150
|
+
const alignmentAxis = getAlignmentAxis(placement);
|
|
151
|
+
const alignLength = getAxisLength(alignmentAxis);
|
|
152
|
+
const side = getSide(placement);
|
|
153
|
+
const isVertical = sideAxis === 'y';
|
|
154
|
+
const commonX = reference.x + reference.width / 2 - floating.width / 2;
|
|
155
|
+
const commonY = reference.y + reference.height / 2 - floating.height / 2;
|
|
156
|
+
const commonAlign = reference[alignLength] / 2 - floating[alignLength] / 2;
|
|
157
|
+
let coords;
|
|
158
|
+
switch (side) {
|
|
159
|
+
case 'top':
|
|
160
|
+
coords = {
|
|
161
|
+
x: commonX,
|
|
162
|
+
y: reference.y - floating.height
|
|
163
|
+
};
|
|
164
|
+
break;
|
|
165
|
+
case 'bottom':
|
|
166
|
+
coords = {
|
|
167
|
+
x: commonX,
|
|
168
|
+
y: reference.y + reference.height
|
|
169
|
+
};
|
|
170
|
+
break;
|
|
171
|
+
case 'right':
|
|
172
|
+
coords = {
|
|
173
|
+
x: reference.x + reference.width,
|
|
174
|
+
y: commonY
|
|
175
|
+
};
|
|
176
|
+
break;
|
|
177
|
+
case 'left':
|
|
178
|
+
coords = {
|
|
179
|
+
x: reference.x - floating.width,
|
|
180
|
+
y: commonY
|
|
181
|
+
};
|
|
182
|
+
break;
|
|
183
|
+
default:
|
|
184
|
+
coords = {
|
|
185
|
+
x: reference.x,
|
|
186
|
+
y: reference.y
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
switch (getAlignment(placement)) {
|
|
190
|
+
case 'start':
|
|
191
|
+
coords[alignmentAxis] -= commonAlign * (rtl && isVertical ? -1 : 1);
|
|
192
|
+
break;
|
|
193
|
+
case 'end':
|
|
194
|
+
coords[alignmentAxis] += commonAlign * (rtl && isVertical ? -1 : 1);
|
|
195
|
+
break;
|
|
196
|
+
}
|
|
197
|
+
return coords;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* Computes the `x` and `y` coordinates that will place the floating element
|
|
202
|
+
* next to a given reference element.
|
|
203
|
+
*
|
|
204
|
+
* This export does not have any `platform` interface logic. You will need to
|
|
205
|
+
* write one for the platform you are using Floating UI with.
|
|
206
|
+
*/
|
|
207
|
+
const computePosition$1 = async (reference, floating, config) => {
|
|
208
|
+
const {
|
|
209
|
+
placement = 'bottom',
|
|
210
|
+
strategy = 'absolute',
|
|
211
|
+
middleware = [],
|
|
212
|
+
platform
|
|
213
|
+
} = config;
|
|
214
|
+
const validMiddleware = middleware.filter(Boolean);
|
|
215
|
+
const rtl = await (platform.isRTL == null ? void 0 : platform.isRTL(floating));
|
|
216
|
+
let rects = await platform.getElementRects({
|
|
217
|
+
reference,
|
|
218
|
+
floating,
|
|
219
|
+
strategy
|
|
220
|
+
});
|
|
221
|
+
let {
|
|
222
|
+
x,
|
|
223
|
+
y
|
|
224
|
+
} = computeCoordsFromPlacement(rects, placement, rtl);
|
|
225
|
+
let statefulPlacement = placement;
|
|
226
|
+
let middlewareData = {};
|
|
227
|
+
let resetCount = 0;
|
|
228
|
+
for (let i = 0; i < validMiddleware.length; i++) {
|
|
229
|
+
const {
|
|
230
|
+
name,
|
|
231
|
+
fn
|
|
232
|
+
} = validMiddleware[i];
|
|
233
|
+
const {
|
|
234
|
+
x: nextX,
|
|
235
|
+
y: nextY,
|
|
236
|
+
data,
|
|
237
|
+
reset
|
|
238
|
+
} = await fn({
|
|
239
|
+
x,
|
|
240
|
+
y,
|
|
241
|
+
initialPlacement: placement,
|
|
242
|
+
placement: statefulPlacement,
|
|
243
|
+
strategy,
|
|
244
|
+
middlewareData,
|
|
245
|
+
rects,
|
|
246
|
+
platform,
|
|
247
|
+
elements: {
|
|
248
|
+
reference,
|
|
249
|
+
floating
|
|
250
|
+
}
|
|
251
|
+
});
|
|
252
|
+
x = nextX != null ? nextX : x;
|
|
253
|
+
y = nextY != null ? nextY : y;
|
|
254
|
+
middlewareData = {
|
|
255
|
+
...middlewareData,
|
|
256
|
+
[name]: {
|
|
257
|
+
...middlewareData[name],
|
|
258
|
+
...data
|
|
259
|
+
}
|
|
260
|
+
};
|
|
261
|
+
if (reset && resetCount <= 50) {
|
|
262
|
+
resetCount++;
|
|
263
|
+
if (typeof reset === 'object') {
|
|
264
|
+
if (reset.placement) {
|
|
265
|
+
statefulPlacement = reset.placement;
|
|
266
|
+
}
|
|
267
|
+
if (reset.rects) {
|
|
268
|
+
rects = reset.rects === true ? await platform.getElementRects({
|
|
269
|
+
reference,
|
|
270
|
+
floating,
|
|
271
|
+
strategy
|
|
272
|
+
}) : reset.rects;
|
|
273
|
+
}
|
|
274
|
+
({
|
|
275
|
+
x,
|
|
276
|
+
y
|
|
277
|
+
} = computeCoordsFromPlacement(rects, statefulPlacement, rtl));
|
|
278
|
+
}
|
|
279
|
+
i = -1;
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
return {
|
|
283
|
+
x,
|
|
284
|
+
y,
|
|
285
|
+
placement: statefulPlacement,
|
|
286
|
+
strategy,
|
|
287
|
+
middlewareData
|
|
288
|
+
};
|
|
289
|
+
};
|
|
290
|
+
|
|
291
|
+
/**
|
|
292
|
+
* Resolves with an object of overflow side offsets that determine how much the
|
|
293
|
+
* element is overflowing a given clipping boundary on each side.
|
|
294
|
+
* - positive = overflowing the boundary by that number of pixels
|
|
295
|
+
* - negative = how many pixels left before it will overflow
|
|
296
|
+
* - 0 = lies flush with the boundary
|
|
297
|
+
* @see https://floating-ui.com/docs/detectOverflow
|
|
298
|
+
*/
|
|
299
|
+
async function detectOverflow(state, options) {
|
|
300
|
+
var _await$platform$isEle;
|
|
301
|
+
if (options === void 0) {
|
|
302
|
+
options = {};
|
|
303
|
+
}
|
|
304
|
+
const {
|
|
305
|
+
x,
|
|
306
|
+
y,
|
|
307
|
+
platform,
|
|
308
|
+
rects,
|
|
309
|
+
elements,
|
|
310
|
+
strategy
|
|
311
|
+
} = state;
|
|
312
|
+
const {
|
|
313
|
+
boundary = 'clippingAncestors',
|
|
314
|
+
rootBoundary = 'viewport',
|
|
315
|
+
elementContext = 'floating',
|
|
316
|
+
altBoundary = false,
|
|
317
|
+
padding = 0
|
|
318
|
+
} = evaluate(options, state);
|
|
319
|
+
const paddingObject = getPaddingObject(padding);
|
|
320
|
+
const altContext = elementContext === 'floating' ? 'reference' : 'floating';
|
|
321
|
+
const element = elements[altBoundary ? altContext : elementContext];
|
|
322
|
+
const clippingClientRect = rectToClientRect(await platform.getClippingRect({
|
|
323
|
+
element: ((_await$platform$isEle = await (platform.isElement == null ? void 0 : platform.isElement(element))) != null ? _await$platform$isEle : true) ? element : element.contextElement || (await (platform.getDocumentElement == null ? void 0 : platform.getDocumentElement(elements.floating))),
|
|
324
|
+
boundary,
|
|
325
|
+
rootBoundary,
|
|
326
|
+
strategy
|
|
327
|
+
}));
|
|
328
|
+
const rect = elementContext === 'floating' ? {
|
|
329
|
+
...rects.floating,
|
|
330
|
+
x,
|
|
331
|
+
y
|
|
332
|
+
} : rects.reference;
|
|
333
|
+
const offsetParent = await (platform.getOffsetParent == null ? void 0 : platform.getOffsetParent(elements.floating));
|
|
334
|
+
const offsetScale = (await (platform.isElement == null ? void 0 : platform.isElement(offsetParent))) ? (await (platform.getScale == null ? void 0 : platform.getScale(offsetParent))) || {
|
|
335
|
+
x: 1,
|
|
336
|
+
y: 1
|
|
337
|
+
} : {
|
|
338
|
+
x: 1,
|
|
339
|
+
y: 1
|
|
340
|
+
};
|
|
341
|
+
const elementClientRect = rectToClientRect(platform.convertOffsetParentRelativeRectToViewportRelativeRect ? await platform.convertOffsetParentRelativeRectToViewportRelativeRect({
|
|
342
|
+
elements,
|
|
343
|
+
rect,
|
|
344
|
+
offsetParent,
|
|
345
|
+
strategy
|
|
346
|
+
}) : rect);
|
|
347
|
+
return {
|
|
348
|
+
top: (clippingClientRect.top - elementClientRect.top + paddingObject.top) / offsetScale.y,
|
|
349
|
+
bottom: (elementClientRect.bottom - clippingClientRect.bottom + paddingObject.bottom) / offsetScale.y,
|
|
350
|
+
left: (clippingClientRect.left - elementClientRect.left + paddingObject.left) / offsetScale.x,
|
|
351
|
+
right: (elementClientRect.right - clippingClientRect.right + paddingObject.right) / offsetScale.x
|
|
352
|
+
};
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
/**
|
|
356
|
+
* Optimizes the visibility of the floating element by flipping the `placement`
|
|
357
|
+
* in order to keep it in view when the preferred placement(s) will overflow the
|
|
358
|
+
* clipping boundary. Alternative to `autoPlacement`.
|
|
359
|
+
* @see https://floating-ui.com/docs/flip
|
|
360
|
+
*/
|
|
361
|
+
const flip = function (options) {
|
|
362
|
+
if (options === void 0) {
|
|
363
|
+
options = {};
|
|
364
|
+
}
|
|
365
|
+
return {
|
|
366
|
+
name: 'flip',
|
|
367
|
+
options,
|
|
368
|
+
async fn(state) {
|
|
369
|
+
var _middlewareData$arrow, _middlewareData$flip;
|
|
370
|
+
const {
|
|
371
|
+
placement,
|
|
372
|
+
middlewareData,
|
|
373
|
+
rects,
|
|
374
|
+
initialPlacement,
|
|
375
|
+
platform,
|
|
376
|
+
elements
|
|
377
|
+
} = state;
|
|
378
|
+
const {
|
|
379
|
+
mainAxis: checkMainAxis = true,
|
|
380
|
+
crossAxis: checkCrossAxis = true,
|
|
381
|
+
fallbackPlacements: specifiedFallbackPlacements,
|
|
382
|
+
fallbackStrategy = 'bestFit',
|
|
383
|
+
fallbackAxisSideDirection = 'none',
|
|
384
|
+
flipAlignment = true,
|
|
385
|
+
...detectOverflowOptions
|
|
386
|
+
} = evaluate(options, state);
|
|
387
|
+
|
|
388
|
+
// If a reset by the arrow was caused due to an alignment offset being
|
|
389
|
+
// added, we should skip any logic now since `flip()` has already done its
|
|
390
|
+
// work.
|
|
391
|
+
// https://github.com/floating-ui/floating-ui/issues/2549#issuecomment-1719601643
|
|
392
|
+
if ((_middlewareData$arrow = middlewareData.arrow) != null && _middlewareData$arrow.alignmentOffset) {
|
|
393
|
+
return {};
|
|
394
|
+
}
|
|
395
|
+
const side = getSide(placement);
|
|
396
|
+
const isBasePlacement = getSide(initialPlacement) === initialPlacement;
|
|
397
|
+
const rtl = await (platform.isRTL == null ? void 0 : platform.isRTL(elements.floating));
|
|
398
|
+
const fallbackPlacements = specifiedFallbackPlacements || (isBasePlacement || !flipAlignment ? [getOppositePlacement(initialPlacement)] : getExpandedPlacements(initialPlacement));
|
|
399
|
+
if (!specifiedFallbackPlacements && fallbackAxisSideDirection !== 'none') {
|
|
400
|
+
fallbackPlacements.push(...getOppositeAxisPlacements(initialPlacement, flipAlignment, fallbackAxisSideDirection, rtl));
|
|
401
|
+
}
|
|
402
|
+
const placements = [initialPlacement, ...fallbackPlacements];
|
|
403
|
+
const overflow = await detectOverflow(state, detectOverflowOptions);
|
|
404
|
+
const overflows = [];
|
|
405
|
+
let overflowsData = ((_middlewareData$flip = middlewareData.flip) == null ? void 0 : _middlewareData$flip.overflows) || [];
|
|
406
|
+
if (checkMainAxis) {
|
|
407
|
+
overflows.push(overflow[side]);
|
|
408
|
+
}
|
|
409
|
+
if (checkCrossAxis) {
|
|
410
|
+
const sides = getAlignmentSides(placement, rects, rtl);
|
|
411
|
+
overflows.push(overflow[sides[0]], overflow[sides[1]]);
|
|
412
|
+
}
|
|
413
|
+
overflowsData = [...overflowsData, {
|
|
414
|
+
placement,
|
|
415
|
+
overflows
|
|
416
|
+
}];
|
|
417
|
+
|
|
418
|
+
// One or more sides is overflowing.
|
|
419
|
+
if (!overflows.every(side => side <= 0)) {
|
|
420
|
+
var _middlewareData$flip2, _overflowsData$filter;
|
|
421
|
+
const nextIndex = (((_middlewareData$flip2 = middlewareData.flip) == null ? void 0 : _middlewareData$flip2.index) || 0) + 1;
|
|
422
|
+
const nextPlacement = placements[nextIndex];
|
|
423
|
+
if (nextPlacement) {
|
|
424
|
+
// Try next placement and re-run the lifecycle.
|
|
425
|
+
return {
|
|
426
|
+
data: {
|
|
427
|
+
index: nextIndex,
|
|
428
|
+
overflows: overflowsData
|
|
429
|
+
},
|
|
430
|
+
reset: {
|
|
431
|
+
placement: nextPlacement
|
|
432
|
+
}
|
|
433
|
+
};
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
// First, find the candidates that fit on the mainAxis side of overflow,
|
|
437
|
+
// then find the placement that fits the best on the main crossAxis side.
|
|
438
|
+
let resetPlacement = (_overflowsData$filter = overflowsData.filter(d => d.overflows[0] <= 0).sort((a, b) => a.overflows[1] - b.overflows[1])[0]) == null ? void 0 : _overflowsData$filter.placement;
|
|
439
|
+
|
|
440
|
+
// Otherwise fallback.
|
|
441
|
+
if (!resetPlacement) {
|
|
442
|
+
switch (fallbackStrategy) {
|
|
443
|
+
case 'bestFit':
|
|
444
|
+
{
|
|
445
|
+
var _overflowsData$map$so;
|
|
446
|
+
const placement = (_overflowsData$map$so = overflowsData.map(d => [d.placement, d.overflows.filter(overflow => overflow > 0).reduce((acc, overflow) => acc + overflow, 0)]).sort((a, b) => a[1] - b[1])[0]) == null ? void 0 : _overflowsData$map$so[0];
|
|
447
|
+
if (placement) {
|
|
448
|
+
resetPlacement = placement;
|
|
449
|
+
}
|
|
450
|
+
break;
|
|
451
|
+
}
|
|
452
|
+
case 'initialPlacement':
|
|
453
|
+
resetPlacement = initialPlacement;
|
|
454
|
+
break;
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
if (placement !== resetPlacement) {
|
|
458
|
+
return {
|
|
459
|
+
reset: {
|
|
460
|
+
placement: resetPlacement
|
|
461
|
+
}
|
|
462
|
+
};
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
return {};
|
|
466
|
+
}
|
|
467
|
+
};
|
|
468
|
+
};
|
|
469
|
+
|
|
470
|
+
// For type backwards-compatibility, the `OffsetOptions` type was also
|
|
471
|
+
// Derivable.
|
|
472
|
+
|
|
473
|
+
async function convertValueToCoords(state, options) {
|
|
474
|
+
const {
|
|
475
|
+
placement,
|
|
476
|
+
platform,
|
|
477
|
+
elements
|
|
478
|
+
} = state;
|
|
479
|
+
const rtl = await (platform.isRTL == null ? void 0 : platform.isRTL(elements.floating));
|
|
480
|
+
const side = getSide(placement);
|
|
481
|
+
const alignment = getAlignment(placement);
|
|
482
|
+
const isVertical = getSideAxis(placement) === 'y';
|
|
483
|
+
const mainAxisMulti = ['left', 'top'].includes(side) ? -1 : 1;
|
|
484
|
+
const crossAxisMulti = rtl && isVertical ? -1 : 1;
|
|
485
|
+
const rawValue = evaluate(options, state);
|
|
486
|
+
let {
|
|
487
|
+
mainAxis,
|
|
488
|
+
crossAxis,
|
|
489
|
+
alignmentAxis
|
|
490
|
+
} = typeof rawValue === 'number' ? {
|
|
491
|
+
mainAxis: rawValue,
|
|
492
|
+
crossAxis: 0,
|
|
493
|
+
alignmentAxis: null
|
|
494
|
+
} : {
|
|
495
|
+
mainAxis: 0,
|
|
496
|
+
crossAxis: 0,
|
|
497
|
+
alignmentAxis: null,
|
|
498
|
+
...rawValue
|
|
499
|
+
};
|
|
500
|
+
if (alignment && typeof alignmentAxis === 'number') {
|
|
501
|
+
crossAxis = alignment === 'end' ? alignmentAxis * -1 : alignmentAxis;
|
|
502
|
+
}
|
|
503
|
+
return isVertical ? {
|
|
504
|
+
x: crossAxis * crossAxisMulti,
|
|
505
|
+
y: mainAxis * mainAxisMulti
|
|
506
|
+
} : {
|
|
507
|
+
x: mainAxis * mainAxisMulti,
|
|
508
|
+
y: crossAxis * crossAxisMulti
|
|
509
|
+
};
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
/**
|
|
513
|
+
* Modifies the placement by translating the floating element along the
|
|
514
|
+
* specified axes.
|
|
515
|
+
* A number (shorthand for `mainAxis` or distance), or an axes configuration
|
|
516
|
+
* object may be passed.
|
|
517
|
+
* @see https://floating-ui.com/docs/offset
|
|
518
|
+
*/
|
|
519
|
+
const offset = function (options) {
|
|
520
|
+
if (options === void 0) {
|
|
521
|
+
options = 0;
|
|
522
|
+
}
|
|
523
|
+
return {
|
|
524
|
+
name: 'offset',
|
|
525
|
+
options,
|
|
526
|
+
async fn(state) {
|
|
527
|
+
var _middlewareData$offse, _middlewareData$arrow;
|
|
528
|
+
const {
|
|
529
|
+
x,
|
|
530
|
+
y,
|
|
531
|
+
placement,
|
|
532
|
+
middlewareData
|
|
533
|
+
} = state;
|
|
534
|
+
const diffCoords = await convertValueToCoords(state, options);
|
|
535
|
+
|
|
536
|
+
// If the placement is the same and the arrow caused an alignment offset
|
|
537
|
+
// then we don't need to change the positioning coordinates.
|
|
538
|
+
if (placement === ((_middlewareData$offse = middlewareData.offset) == null ? void 0 : _middlewareData$offse.placement) && (_middlewareData$arrow = middlewareData.arrow) != null && _middlewareData$arrow.alignmentOffset) {
|
|
539
|
+
return {};
|
|
540
|
+
}
|
|
541
|
+
return {
|
|
542
|
+
x: x + diffCoords.x,
|
|
543
|
+
y: y + diffCoords.y,
|
|
544
|
+
data: {
|
|
545
|
+
...diffCoords,
|
|
546
|
+
placement
|
|
547
|
+
}
|
|
548
|
+
};
|
|
549
|
+
}
|
|
550
|
+
};
|
|
551
|
+
};
|
|
552
|
+
|
|
553
|
+
/**
|
|
554
|
+
* Optimizes the visibility of the floating element by shifting it in order to
|
|
555
|
+
* keep it in view when it will overflow the clipping boundary.
|
|
556
|
+
* @see https://floating-ui.com/docs/shift
|
|
557
|
+
*/
|
|
558
|
+
const shift = function (options) {
|
|
559
|
+
if (options === void 0) {
|
|
560
|
+
options = {};
|
|
561
|
+
}
|
|
562
|
+
return {
|
|
563
|
+
name: 'shift',
|
|
564
|
+
options,
|
|
565
|
+
async fn(state) {
|
|
566
|
+
const {
|
|
567
|
+
x,
|
|
568
|
+
y,
|
|
569
|
+
placement
|
|
570
|
+
} = state;
|
|
571
|
+
const {
|
|
572
|
+
mainAxis: checkMainAxis = true,
|
|
573
|
+
crossAxis: checkCrossAxis = false,
|
|
574
|
+
limiter = {
|
|
575
|
+
fn: _ref => {
|
|
576
|
+
let {
|
|
577
|
+
x,
|
|
578
|
+
y
|
|
579
|
+
} = _ref;
|
|
580
|
+
return {
|
|
581
|
+
x,
|
|
582
|
+
y
|
|
583
|
+
};
|
|
584
|
+
}
|
|
585
|
+
},
|
|
586
|
+
...detectOverflowOptions
|
|
587
|
+
} = evaluate(options, state);
|
|
588
|
+
const coords = {
|
|
589
|
+
x,
|
|
590
|
+
y
|
|
591
|
+
};
|
|
592
|
+
const overflow = await detectOverflow(state, detectOverflowOptions);
|
|
593
|
+
const crossAxis = getSideAxis(getSide(placement));
|
|
594
|
+
const mainAxis = getOppositeAxis(crossAxis);
|
|
595
|
+
let mainAxisCoord = coords[mainAxis];
|
|
596
|
+
let crossAxisCoord = coords[crossAxis];
|
|
597
|
+
if (checkMainAxis) {
|
|
598
|
+
const minSide = mainAxis === 'y' ? 'top' : 'left';
|
|
599
|
+
const maxSide = mainAxis === 'y' ? 'bottom' : 'right';
|
|
600
|
+
const min = mainAxisCoord + overflow[minSide];
|
|
601
|
+
const max = mainAxisCoord - overflow[maxSide];
|
|
602
|
+
mainAxisCoord = clamp(min, mainAxisCoord, max);
|
|
603
|
+
}
|
|
604
|
+
if (checkCrossAxis) {
|
|
605
|
+
const minSide = crossAxis === 'y' ? 'top' : 'left';
|
|
606
|
+
const maxSide = crossAxis === 'y' ? 'bottom' : 'right';
|
|
607
|
+
const min = crossAxisCoord + overflow[minSide];
|
|
608
|
+
const max = crossAxisCoord - overflow[maxSide];
|
|
609
|
+
crossAxisCoord = clamp(min, crossAxisCoord, max);
|
|
610
|
+
}
|
|
611
|
+
const limitedCoords = limiter.fn({
|
|
612
|
+
...state,
|
|
613
|
+
[mainAxis]: mainAxisCoord,
|
|
614
|
+
[crossAxis]: crossAxisCoord
|
|
615
|
+
});
|
|
616
|
+
return {
|
|
617
|
+
...limitedCoords,
|
|
618
|
+
data: {
|
|
619
|
+
x: limitedCoords.x - x,
|
|
620
|
+
y: limitedCoords.y - y
|
|
621
|
+
}
|
|
622
|
+
};
|
|
623
|
+
}
|
|
624
|
+
};
|
|
625
|
+
};
|
|
626
|
+
|
|
627
|
+
function getNodeName(node) {
|
|
628
|
+
if (isNode(node)) {
|
|
629
|
+
return (node.nodeName || '').toLowerCase();
|
|
630
|
+
}
|
|
631
|
+
// Mocked nodes in testing environments may not be instances of Node. By
|
|
632
|
+
// returning `#document` an infinite loop won't occur.
|
|
633
|
+
// https://github.com/floating-ui/floating-ui/issues/2317
|
|
634
|
+
return '#document';
|
|
635
|
+
}
|
|
636
|
+
function getWindow(node) {
|
|
637
|
+
var _node$ownerDocument;
|
|
638
|
+
return (node == null || (_node$ownerDocument = node.ownerDocument) == null ? void 0 : _node$ownerDocument.defaultView) || window;
|
|
639
|
+
}
|
|
640
|
+
function getDocumentElement(node) {
|
|
641
|
+
var _ref;
|
|
642
|
+
return (_ref = (isNode(node) ? node.ownerDocument : node.document) || window.document) == null ? void 0 : _ref.documentElement;
|
|
643
|
+
}
|
|
644
|
+
function isNode(value) {
|
|
645
|
+
return value instanceof Node || value instanceof getWindow(value).Node;
|
|
646
|
+
}
|
|
647
|
+
function isElement(value) {
|
|
648
|
+
return value instanceof Element || value instanceof getWindow(value).Element;
|
|
649
|
+
}
|
|
650
|
+
function isHTMLElement(value) {
|
|
651
|
+
return value instanceof HTMLElement || value instanceof getWindow(value).HTMLElement;
|
|
652
|
+
}
|
|
653
|
+
function isShadowRoot(value) {
|
|
654
|
+
// Browsers without `ShadowRoot` support.
|
|
655
|
+
if (typeof ShadowRoot === 'undefined') {
|
|
656
|
+
return false;
|
|
657
|
+
}
|
|
658
|
+
return value instanceof ShadowRoot || value instanceof getWindow(value).ShadowRoot;
|
|
659
|
+
}
|
|
660
|
+
function isOverflowElement(element) {
|
|
661
|
+
const {
|
|
662
|
+
overflow,
|
|
663
|
+
overflowX,
|
|
664
|
+
overflowY,
|
|
665
|
+
display
|
|
666
|
+
} = getComputedStyle$1(element);
|
|
667
|
+
return /auto|scroll|overlay|hidden|clip/.test(overflow + overflowY + overflowX) && !['inline', 'contents'].includes(display);
|
|
668
|
+
}
|
|
669
|
+
function isTableElement(element) {
|
|
670
|
+
return ['table', 'td', 'th'].includes(getNodeName(element));
|
|
671
|
+
}
|
|
672
|
+
function isTopLayer$1(element) {
|
|
673
|
+
return [':popover-open', ':modal'].some(selector => {
|
|
674
|
+
try {
|
|
675
|
+
return element.matches(selector);
|
|
676
|
+
} catch (e) {
|
|
677
|
+
return false;
|
|
678
|
+
}
|
|
679
|
+
});
|
|
680
|
+
}
|
|
681
|
+
function isContainingBlock(elementOrCss) {
|
|
682
|
+
const webkit = isWebKit();
|
|
683
|
+
const css = isElement(elementOrCss) ? getComputedStyle$1(elementOrCss) : elementOrCss;
|
|
684
|
+
|
|
685
|
+
// https://developer.mozilla.org/en-US/docs/Web/CSS/Containing_block#identifying_the_containing_block
|
|
686
|
+
return css.transform !== 'none' || css.perspective !== 'none' || (css.containerType ? css.containerType !== 'normal' : false) || !webkit && (css.backdropFilter ? css.backdropFilter !== 'none' : false) || !webkit && (css.filter ? css.filter !== 'none' : false) || ['transform', 'perspective', 'filter'].some(value => (css.willChange || '').includes(value)) || ['paint', 'layout', 'strict', 'content'].some(value => (css.contain || '').includes(value));
|
|
687
|
+
}
|
|
688
|
+
function getContainingBlock(element) {
|
|
689
|
+
let currentNode = getParentNode(element);
|
|
690
|
+
while (isHTMLElement(currentNode) && !isLastTraversableNode(currentNode)) {
|
|
691
|
+
if (isContainingBlock(currentNode)) {
|
|
692
|
+
return currentNode;
|
|
693
|
+
} else if (isTopLayer$1(currentNode)) {
|
|
694
|
+
return null;
|
|
695
|
+
}
|
|
696
|
+
currentNode = getParentNode(currentNode);
|
|
697
|
+
}
|
|
698
|
+
return null;
|
|
699
|
+
}
|
|
700
|
+
function isWebKit() {
|
|
701
|
+
if (typeof CSS === 'undefined' || !CSS.supports) return false;
|
|
702
|
+
return CSS.supports('-webkit-backdrop-filter', 'none');
|
|
703
|
+
}
|
|
704
|
+
function isLastTraversableNode(node) {
|
|
705
|
+
return ['html', 'body', '#document'].includes(getNodeName(node));
|
|
706
|
+
}
|
|
707
|
+
function getComputedStyle$1(element) {
|
|
708
|
+
return getWindow(element).getComputedStyle(element);
|
|
709
|
+
}
|
|
710
|
+
function getNodeScroll(element) {
|
|
711
|
+
if (isElement(element)) {
|
|
712
|
+
return {
|
|
713
|
+
scrollLeft: element.scrollLeft,
|
|
714
|
+
scrollTop: element.scrollTop
|
|
715
|
+
};
|
|
716
|
+
}
|
|
717
|
+
return {
|
|
718
|
+
scrollLeft: element.scrollX,
|
|
719
|
+
scrollTop: element.scrollY
|
|
720
|
+
};
|
|
721
|
+
}
|
|
722
|
+
function getParentNode(node) {
|
|
723
|
+
if (getNodeName(node) === 'html') {
|
|
724
|
+
return node;
|
|
725
|
+
}
|
|
726
|
+
const result =
|
|
727
|
+
// Step into the shadow DOM of the parent of a slotted node.
|
|
728
|
+
node.assignedSlot ||
|
|
729
|
+
// DOM Element detected.
|
|
730
|
+
node.parentNode ||
|
|
731
|
+
// ShadowRoot detected.
|
|
732
|
+
isShadowRoot(node) && node.host ||
|
|
733
|
+
// Fallback.
|
|
734
|
+
getDocumentElement(node);
|
|
735
|
+
return isShadowRoot(result) ? result.host : result;
|
|
736
|
+
}
|
|
737
|
+
function getNearestOverflowAncestor(node) {
|
|
738
|
+
const parentNode = getParentNode(node);
|
|
739
|
+
if (isLastTraversableNode(parentNode)) {
|
|
740
|
+
return node.ownerDocument ? node.ownerDocument.body : node.body;
|
|
741
|
+
}
|
|
742
|
+
if (isHTMLElement(parentNode) && isOverflowElement(parentNode)) {
|
|
743
|
+
return parentNode;
|
|
744
|
+
}
|
|
745
|
+
return getNearestOverflowAncestor(parentNode);
|
|
746
|
+
}
|
|
747
|
+
function getOverflowAncestors(node, list, traverseIframes) {
|
|
748
|
+
var _node$ownerDocument2;
|
|
749
|
+
if (list === void 0) {
|
|
750
|
+
list = [];
|
|
751
|
+
}
|
|
752
|
+
if (traverseIframes === void 0) {
|
|
753
|
+
traverseIframes = true;
|
|
754
|
+
}
|
|
755
|
+
const scrollableAncestor = getNearestOverflowAncestor(node);
|
|
756
|
+
const isBody = scrollableAncestor === ((_node$ownerDocument2 = node.ownerDocument) == null ? void 0 : _node$ownerDocument2.body);
|
|
757
|
+
const win = getWindow(scrollableAncestor);
|
|
758
|
+
if (isBody) {
|
|
759
|
+
const frameElement = getFrameElement(win);
|
|
760
|
+
return list.concat(win, win.visualViewport || [], isOverflowElement(scrollableAncestor) ? scrollableAncestor : [], frameElement && traverseIframes ? getOverflowAncestors(frameElement) : []);
|
|
761
|
+
}
|
|
762
|
+
return list.concat(scrollableAncestor, getOverflowAncestors(scrollableAncestor, [], traverseIframes));
|
|
763
|
+
}
|
|
764
|
+
function getFrameElement(win) {
|
|
765
|
+
return win.parent && Object.getPrototypeOf(win.parent) ? win.frameElement : null;
|
|
766
|
+
}
|
|
767
|
+
|
|
768
|
+
function activeElement(doc) {
|
|
769
|
+
let activeElement = doc.activeElement;
|
|
770
|
+
while (((_activeElement = activeElement) == null || (_activeElement = _activeElement.shadowRoot) == null ? void 0 : _activeElement.activeElement) != null) {
|
|
771
|
+
var _activeElement;
|
|
772
|
+
activeElement = activeElement.shadowRoot.activeElement;
|
|
773
|
+
}
|
|
774
|
+
return activeElement;
|
|
775
|
+
}
|
|
776
|
+
function contains(parent, child) {
|
|
777
|
+
if (!parent || !child) {
|
|
778
|
+
return false;
|
|
779
|
+
}
|
|
780
|
+
const rootNode = child.getRootNode == null ? void 0 : child.getRootNode();
|
|
781
|
+
|
|
782
|
+
// First, attempt with faster native method
|
|
783
|
+
if (parent.contains(child)) {
|
|
784
|
+
return true;
|
|
785
|
+
}
|
|
786
|
+
|
|
787
|
+
// then fallback to custom implementation with Shadow DOM support
|
|
788
|
+
if (rootNode && isShadowRoot(rootNode)) {
|
|
789
|
+
let next = child;
|
|
790
|
+
while (next) {
|
|
791
|
+
if (parent === next) {
|
|
792
|
+
return true;
|
|
793
|
+
}
|
|
794
|
+
// @ts-ignore
|
|
795
|
+
next = next.parentNode || next.host;
|
|
796
|
+
}
|
|
797
|
+
}
|
|
798
|
+
|
|
799
|
+
// Give up, the result is false
|
|
800
|
+
return false;
|
|
801
|
+
}
|
|
802
|
+
function isSafari() {
|
|
803
|
+
// Chrome DevTools does not complain about navigator.vendor
|
|
804
|
+
return /apple/i.test(navigator.vendor);
|
|
805
|
+
}
|
|
806
|
+
function getDocument(node) {
|
|
807
|
+
return (node == null ? void 0 : node.ownerDocument) || document;
|
|
808
|
+
}
|
|
809
|
+
|
|
810
|
+
/*!
|
|
811
|
+
* tabbable 6.2.0
|
|
812
|
+
* @license MIT, https://github.com/focus-trap/tabbable/blob/master/LICENSE
|
|
813
|
+
*/
|
|
814
|
+
// NOTE: separate `:not()` selectors has broader browser support than the newer
|
|
815
|
+
// `:not([inert], [inert] *)` (Feb 2023)
|
|
816
|
+
// CAREFUL: JSDom does not support `:not([inert] *)` as a selector; using it causes
|
|
817
|
+
// the entire query to fail, resulting in no nodes found, which will break a lot
|
|
818
|
+
// of things... so we have to rely on JS to identify nodes inside an inert container
|
|
819
|
+
var candidateSelectors = ['input:not([inert])', 'select:not([inert])', 'textarea:not([inert])', 'a[href]:not([inert])', 'button:not([inert])', '[tabindex]:not(slot):not([inert])', 'audio[controls]:not([inert])', 'video[controls]:not([inert])', '[contenteditable]:not([contenteditable="false"]):not([inert])', 'details>summary:first-of-type:not([inert])', 'details:not([inert])'];
|
|
820
|
+
var candidateSelector = /* #__PURE__ */candidateSelectors.join(',');
|
|
821
|
+
var NoElement = typeof Element === 'undefined';
|
|
822
|
+
var matches = NoElement ? function () {} : Element.prototype.matches || Element.prototype.msMatchesSelector || Element.prototype.webkitMatchesSelector;
|
|
823
|
+
var getRootNode = !NoElement && Element.prototype.getRootNode ? function (element) {
|
|
824
|
+
var _element$getRootNode;
|
|
825
|
+
return element === null || element === void 0 ? void 0 : (_element$getRootNode = element.getRootNode) === null || _element$getRootNode === void 0 ? void 0 : _element$getRootNode.call(element);
|
|
826
|
+
} : function (element) {
|
|
827
|
+
return element === null || element === void 0 ? void 0 : element.ownerDocument;
|
|
828
|
+
};
|
|
829
|
+
|
|
830
|
+
/**
|
|
831
|
+
* Determines if a node is inert or in an inert ancestor.
|
|
832
|
+
* @param {Element} [node]
|
|
833
|
+
* @param {boolean} [lookUp] If true and `node` is not inert, looks up at ancestors to
|
|
834
|
+
* see if any of them are inert. If false, only `node` itself is considered.
|
|
835
|
+
* @returns {boolean} True if inert itself or by way of being in an inert ancestor.
|
|
836
|
+
* False if `node` is falsy.
|
|
837
|
+
*/
|
|
838
|
+
var isInert = function isInert(node, lookUp) {
|
|
839
|
+
var _node$getAttribute;
|
|
840
|
+
if (lookUp === void 0) {
|
|
841
|
+
lookUp = true;
|
|
842
|
+
}
|
|
843
|
+
// CAREFUL: JSDom does not support inert at all, so we can't use the `HTMLElement.inert`
|
|
844
|
+
// JS API property; we have to check the attribute, which can either be empty or 'true';
|
|
845
|
+
// if it's `null` (not specified) or 'false', it's an active element
|
|
846
|
+
var inertAtt = node === null || node === void 0 ? void 0 : (_node$getAttribute = node.getAttribute) === null || _node$getAttribute === void 0 ? void 0 : _node$getAttribute.call(node, 'inert');
|
|
847
|
+
var inert = inertAtt === '' || inertAtt === 'true';
|
|
848
|
+
|
|
849
|
+
// NOTE: this could also be handled with `node.matches('[inert], :is([inert] *)')`
|
|
850
|
+
// if it weren't for `matches()` not being a function on shadow roots; the following
|
|
851
|
+
// code works for any kind of node
|
|
852
|
+
// CAREFUL: JSDom does not appear to support certain selectors like `:not([inert] *)`
|
|
853
|
+
// so it likely would not support `:is([inert] *)` either...
|
|
854
|
+
var result = inert || lookUp && node && isInert(node.parentNode); // recursive
|
|
855
|
+
|
|
856
|
+
return result;
|
|
857
|
+
};
|
|
858
|
+
|
|
859
|
+
/**
|
|
860
|
+
* Determines if a node's content is editable.
|
|
861
|
+
* @param {Element} [node]
|
|
862
|
+
* @returns True if it's content-editable; false if it's not or `node` is falsy.
|
|
863
|
+
*/
|
|
864
|
+
var isContentEditable = function isContentEditable(node) {
|
|
865
|
+
var _node$getAttribute2;
|
|
866
|
+
// CAREFUL: JSDom does not support the `HTMLElement.isContentEditable` API so we have
|
|
867
|
+
// to use the attribute directly to check for this, which can either be empty or 'true';
|
|
868
|
+
// if it's `null` (not specified) or 'false', it's a non-editable element
|
|
869
|
+
var attValue = node === null || node === void 0 ? void 0 : (_node$getAttribute2 = node.getAttribute) === null || _node$getAttribute2 === void 0 ? void 0 : _node$getAttribute2.call(node, 'contenteditable');
|
|
870
|
+
return attValue === '' || attValue === 'true';
|
|
871
|
+
};
|
|
872
|
+
|
|
873
|
+
/**
|
|
874
|
+
* @param {Element} el container to check in
|
|
875
|
+
* @param {boolean} includeContainer add container to check
|
|
876
|
+
* @param {(node: Element) => boolean} filter filter candidates
|
|
877
|
+
* @returns {Element[]}
|
|
878
|
+
*/
|
|
879
|
+
var getCandidates = function getCandidates(el, includeContainer, filter) {
|
|
880
|
+
// even if `includeContainer=false`, we still have to check it for inertness because
|
|
881
|
+
// if it's inert, all its children are inert
|
|
882
|
+
if (isInert(el)) {
|
|
883
|
+
return [];
|
|
884
|
+
}
|
|
885
|
+
var candidates = Array.prototype.slice.apply(el.querySelectorAll(candidateSelector));
|
|
886
|
+
if (includeContainer && matches.call(el, candidateSelector)) {
|
|
887
|
+
candidates.unshift(el);
|
|
888
|
+
}
|
|
889
|
+
candidates = candidates.filter(filter);
|
|
890
|
+
return candidates;
|
|
891
|
+
};
|
|
892
|
+
|
|
893
|
+
/**
|
|
894
|
+
* @callback GetShadowRoot
|
|
895
|
+
* @param {Element} element to check for shadow root
|
|
896
|
+
* @returns {ShadowRoot|boolean} ShadowRoot if available or boolean indicating if a shadowRoot is attached but not available.
|
|
897
|
+
*/
|
|
898
|
+
|
|
899
|
+
/**
|
|
900
|
+
* @callback ShadowRootFilter
|
|
901
|
+
* @param {Element} shadowHostNode the element which contains shadow content
|
|
902
|
+
* @returns {boolean} true if a shadow root could potentially contain valid candidates.
|
|
903
|
+
*/
|
|
904
|
+
|
|
905
|
+
/**
|
|
906
|
+
* @typedef {Object} CandidateScope
|
|
907
|
+
* @property {Element} scopeParent contains inner candidates
|
|
908
|
+
* @property {Element[]} candidates list of candidates found in the scope parent
|
|
909
|
+
*/
|
|
910
|
+
|
|
911
|
+
/**
|
|
912
|
+
* @typedef {Object} IterativeOptions
|
|
913
|
+
* @property {GetShadowRoot|boolean} getShadowRoot true if shadow support is enabled; falsy if not;
|
|
914
|
+
* if a function, implies shadow support is enabled and either returns the shadow root of an element
|
|
915
|
+
* or a boolean stating if it has an undisclosed shadow root
|
|
916
|
+
* @property {(node: Element) => boolean} filter filter candidates
|
|
917
|
+
* @property {boolean} flatten if true then result will flatten any CandidateScope into the returned list
|
|
918
|
+
* @property {ShadowRootFilter} shadowRootFilter filter shadow roots;
|
|
919
|
+
*/
|
|
920
|
+
|
|
921
|
+
/**
|
|
922
|
+
* @param {Element[]} elements list of element containers to match candidates from
|
|
923
|
+
* @param {boolean} includeContainer add container list to check
|
|
924
|
+
* @param {IterativeOptions} options
|
|
925
|
+
* @returns {Array.<Element|CandidateScope>}
|
|
926
|
+
*/
|
|
927
|
+
var getCandidatesIteratively = function getCandidatesIteratively(elements, includeContainer, options) {
|
|
928
|
+
var candidates = [];
|
|
929
|
+
var elementsToCheck = Array.from(elements);
|
|
930
|
+
while (elementsToCheck.length) {
|
|
931
|
+
var element = elementsToCheck.shift();
|
|
932
|
+
if (isInert(element, false)) {
|
|
933
|
+
// no need to look up since we're drilling down
|
|
934
|
+
// anything inside this container will also be inert
|
|
935
|
+
continue;
|
|
936
|
+
}
|
|
937
|
+
if (element.tagName === 'SLOT') {
|
|
938
|
+
// add shadow dom slot scope (slot itself cannot be focusable)
|
|
939
|
+
var assigned = element.assignedElements();
|
|
940
|
+
var content = assigned.length ? assigned : element.children;
|
|
941
|
+
var nestedCandidates = getCandidatesIteratively(content, true, options);
|
|
942
|
+
if (options.flatten) {
|
|
943
|
+
candidates.push.apply(candidates, nestedCandidates);
|
|
944
|
+
} else {
|
|
945
|
+
candidates.push({
|
|
946
|
+
scopeParent: element,
|
|
947
|
+
candidates: nestedCandidates
|
|
948
|
+
});
|
|
949
|
+
}
|
|
950
|
+
} else {
|
|
951
|
+
// check candidate element
|
|
952
|
+
var validCandidate = matches.call(element, candidateSelector);
|
|
953
|
+
if (validCandidate && options.filter(element) && (includeContainer || !elements.includes(element))) {
|
|
954
|
+
candidates.push(element);
|
|
955
|
+
}
|
|
956
|
+
|
|
957
|
+
// iterate over shadow content if possible
|
|
958
|
+
var shadowRoot = element.shadowRoot ||
|
|
959
|
+
// check for an undisclosed shadow
|
|
960
|
+
typeof options.getShadowRoot === 'function' && options.getShadowRoot(element);
|
|
961
|
+
|
|
962
|
+
// no inert look up because we're already drilling down and checking for inertness
|
|
963
|
+
// on the way down, so all containers to this root node should have already been
|
|
964
|
+
// vetted as non-inert
|
|
965
|
+
var validShadowRoot = !isInert(shadowRoot, false) && (!options.shadowRootFilter || options.shadowRootFilter(element));
|
|
966
|
+
if (shadowRoot && validShadowRoot) {
|
|
967
|
+
// add shadow dom scope IIF a shadow root node was given; otherwise, an undisclosed
|
|
968
|
+
// shadow exists, so look at light dom children as fallback BUT create a scope for any
|
|
969
|
+
// child candidates found because they're likely slotted elements (elements that are
|
|
970
|
+
// children of the web component element (which has the shadow), in the light dom, but
|
|
971
|
+
// slotted somewhere _inside_ the undisclosed shadow) -- the scope is created below,
|
|
972
|
+
// _after_ we return from this recursive call
|
|
973
|
+
var _nestedCandidates = getCandidatesIteratively(shadowRoot === true ? element.children : shadowRoot.children, true, options);
|
|
974
|
+
if (options.flatten) {
|
|
975
|
+
candidates.push.apply(candidates, _nestedCandidates);
|
|
976
|
+
} else {
|
|
977
|
+
candidates.push({
|
|
978
|
+
scopeParent: element,
|
|
979
|
+
candidates: _nestedCandidates
|
|
980
|
+
});
|
|
981
|
+
}
|
|
982
|
+
} else {
|
|
983
|
+
// there's not shadow so just dig into the element's (light dom) children
|
|
984
|
+
// __without__ giving the element special scope treatment
|
|
985
|
+
elementsToCheck.unshift.apply(elementsToCheck, element.children);
|
|
986
|
+
}
|
|
987
|
+
}
|
|
988
|
+
}
|
|
989
|
+
return candidates;
|
|
990
|
+
};
|
|
991
|
+
|
|
992
|
+
/**
|
|
993
|
+
* @private
|
|
994
|
+
* Determines if the node has an explicitly specified `tabindex` attribute.
|
|
995
|
+
* @param {HTMLElement} node
|
|
996
|
+
* @returns {boolean} True if so; false if not.
|
|
997
|
+
*/
|
|
998
|
+
var hasTabIndex = function hasTabIndex(node) {
|
|
999
|
+
return !isNaN(parseInt(node.getAttribute('tabindex'), 10));
|
|
1000
|
+
};
|
|
1001
|
+
|
|
1002
|
+
/**
|
|
1003
|
+
* Determine the tab index of a given node.
|
|
1004
|
+
* @param {HTMLElement} node
|
|
1005
|
+
* @returns {number} Tab order (negative, 0, or positive number).
|
|
1006
|
+
* @throws {Error} If `node` is falsy.
|
|
1007
|
+
*/
|
|
1008
|
+
var getTabIndex = function getTabIndex(node) {
|
|
1009
|
+
if (!node) {
|
|
1010
|
+
throw new Error('No node provided');
|
|
1011
|
+
}
|
|
1012
|
+
if (node.tabIndex < 0) {
|
|
1013
|
+
// in Chrome, <details/>, <audio controls/> and <video controls/> elements get a default
|
|
1014
|
+
// `tabIndex` of -1 when the 'tabindex' attribute isn't specified in the DOM,
|
|
1015
|
+
// yet they are still part of the regular tab order; in FF, they get a default
|
|
1016
|
+
// `tabIndex` of 0; since Chrome still puts those elements in the regular tab
|
|
1017
|
+
// order, consider their tab index to be 0.
|
|
1018
|
+
// Also browsers do not return `tabIndex` correctly for contentEditable nodes;
|
|
1019
|
+
// so if they don't have a tabindex attribute specifically set, assume it's 0.
|
|
1020
|
+
if ((/^(AUDIO|VIDEO|DETAILS)$/.test(node.tagName) || isContentEditable(node)) && !hasTabIndex(node)) {
|
|
1021
|
+
return 0;
|
|
1022
|
+
}
|
|
1023
|
+
}
|
|
1024
|
+
return node.tabIndex;
|
|
1025
|
+
};
|
|
1026
|
+
|
|
1027
|
+
/**
|
|
1028
|
+
* Determine the tab index of a given node __for sort order purposes__.
|
|
1029
|
+
* @param {HTMLElement} node
|
|
1030
|
+
* @param {boolean} [isScope] True for a custom element with shadow root or slot that, by default,
|
|
1031
|
+
* has tabIndex -1, but needs to be sorted by document order in order for its content to be
|
|
1032
|
+
* inserted into the correct sort position.
|
|
1033
|
+
* @returns {number} Tab order (negative, 0, or positive number).
|
|
1034
|
+
*/
|
|
1035
|
+
var getSortOrderTabIndex = function getSortOrderTabIndex(node, isScope) {
|
|
1036
|
+
var tabIndex = getTabIndex(node);
|
|
1037
|
+
if (tabIndex < 0 && isScope && !hasTabIndex(node)) {
|
|
1038
|
+
return 0;
|
|
1039
|
+
}
|
|
1040
|
+
return tabIndex;
|
|
1041
|
+
};
|
|
1042
|
+
var sortOrderedTabbables = function sortOrderedTabbables(a, b) {
|
|
1043
|
+
return a.tabIndex === b.tabIndex ? a.documentOrder - b.documentOrder : a.tabIndex - b.tabIndex;
|
|
1044
|
+
};
|
|
1045
|
+
var isInput = function isInput(node) {
|
|
1046
|
+
return node.tagName === 'INPUT';
|
|
1047
|
+
};
|
|
1048
|
+
var isHiddenInput = function isHiddenInput(node) {
|
|
1049
|
+
return isInput(node) && node.type === 'hidden';
|
|
1050
|
+
};
|
|
1051
|
+
var isDetailsWithSummary = function isDetailsWithSummary(node) {
|
|
1052
|
+
var r = node.tagName === 'DETAILS' && Array.prototype.slice.apply(node.children).some(function (child) {
|
|
1053
|
+
return child.tagName === 'SUMMARY';
|
|
1054
|
+
});
|
|
1055
|
+
return r;
|
|
1056
|
+
};
|
|
1057
|
+
var getCheckedRadio = function getCheckedRadio(nodes, form) {
|
|
1058
|
+
for (var i = 0; i < nodes.length; i++) {
|
|
1059
|
+
if (nodes[i].checked && nodes[i].form === form) {
|
|
1060
|
+
return nodes[i];
|
|
1061
|
+
}
|
|
1062
|
+
}
|
|
1063
|
+
};
|
|
1064
|
+
var isTabbableRadio = function isTabbableRadio(node) {
|
|
1065
|
+
if (!node.name) {
|
|
1066
|
+
return true;
|
|
1067
|
+
}
|
|
1068
|
+
var radioScope = node.form || getRootNode(node);
|
|
1069
|
+
var queryRadios = function queryRadios(name) {
|
|
1070
|
+
return radioScope.querySelectorAll('input[type="radio"][name="' + name + '"]');
|
|
1071
|
+
};
|
|
1072
|
+
var radioSet;
|
|
1073
|
+
if (typeof window !== 'undefined' && typeof window.CSS !== 'undefined' && typeof window.CSS.escape === 'function') {
|
|
1074
|
+
radioSet = queryRadios(window.CSS.escape(node.name));
|
|
1075
|
+
} else {
|
|
1076
|
+
try {
|
|
1077
|
+
radioSet = queryRadios(node.name);
|
|
1078
|
+
} catch (err) {
|
|
1079
|
+
// eslint-disable-next-line no-console
|
|
1080
|
+
console.error('Looks like you have a radio button with a name attribute containing invalid CSS selector characters and need the CSS.escape polyfill: %s', err.message);
|
|
1081
|
+
return false;
|
|
1082
|
+
}
|
|
1083
|
+
}
|
|
1084
|
+
var checked = getCheckedRadio(radioSet, node.form);
|
|
1085
|
+
return !checked || checked === node;
|
|
1086
|
+
};
|
|
1087
|
+
var isRadio = function isRadio(node) {
|
|
1088
|
+
return isInput(node) && node.type === 'radio';
|
|
1089
|
+
};
|
|
1090
|
+
var isNonTabbableRadio = function isNonTabbableRadio(node) {
|
|
1091
|
+
return isRadio(node) && !isTabbableRadio(node);
|
|
1092
|
+
};
|
|
1093
|
+
|
|
1094
|
+
// determines if a node is ultimately attached to the window's document
|
|
1095
|
+
var isNodeAttached = function isNodeAttached(node) {
|
|
1096
|
+
var _nodeRoot;
|
|
1097
|
+
// The root node is the shadow root if the node is in a shadow DOM; some document otherwise
|
|
1098
|
+
// (but NOT _the_ document; see second 'If' comment below for more).
|
|
1099
|
+
// If rootNode is shadow root, it'll have a host, which is the element to which the shadow
|
|
1100
|
+
// is attached, and the one we need to check if it's in the document or not (because the
|
|
1101
|
+
// shadow, and all nodes it contains, is never considered in the document since shadows
|
|
1102
|
+
// behave like self-contained DOMs; but if the shadow's HOST, which is part of the document,
|
|
1103
|
+
// is hidden, or is not in the document itself but is detached, it will affect the shadow's
|
|
1104
|
+
// visibility, including all the nodes it contains). The host could be any normal node,
|
|
1105
|
+
// or a custom element (i.e. web component). Either way, that's the one that is considered
|
|
1106
|
+
// part of the document, not the shadow root, nor any of its children (i.e. the node being
|
|
1107
|
+
// tested).
|
|
1108
|
+
// To further complicate things, we have to look all the way up until we find a shadow HOST
|
|
1109
|
+
// that is attached (or find none) because the node might be in nested shadows...
|
|
1110
|
+
// If rootNode is not a shadow root, it won't have a host, and so rootNode should be the
|
|
1111
|
+
// document (per the docs) and while it's a Document-type object, that document does not
|
|
1112
|
+
// appear to be the same as the node's `ownerDocument` for some reason, so it's safer
|
|
1113
|
+
// to ignore the rootNode at this point, and use `node.ownerDocument`. Otherwise,
|
|
1114
|
+
// using `rootNode.contains(node)` will _always_ be true we'll get false-positives when
|
|
1115
|
+
// node is actually detached.
|
|
1116
|
+
// NOTE: If `nodeRootHost` or `node` happens to be the `document` itself (which is possible
|
|
1117
|
+
// if a tabbable/focusable node was quickly added to the DOM, focused, and then removed
|
|
1118
|
+
// from the DOM as in https://github.com/focus-trap/focus-trap-react/issues/905), then
|
|
1119
|
+
// `ownerDocument` will be `null`, hence the optional chaining on it.
|
|
1120
|
+
var nodeRoot = node && getRootNode(node);
|
|
1121
|
+
var nodeRootHost = (_nodeRoot = nodeRoot) === null || _nodeRoot === void 0 ? void 0 : _nodeRoot.host;
|
|
1122
|
+
|
|
1123
|
+
// in some cases, a detached node will return itself as the root instead of a document or
|
|
1124
|
+
// shadow root object, in which case, we shouldn't try to look further up the host chain
|
|
1125
|
+
var attached = false;
|
|
1126
|
+
if (nodeRoot && nodeRoot !== node) {
|
|
1127
|
+
var _nodeRootHost, _nodeRootHost$ownerDo, _node$ownerDocument;
|
|
1128
|
+
attached = !!((_nodeRootHost = nodeRootHost) !== null && _nodeRootHost !== void 0 && (_nodeRootHost$ownerDo = _nodeRootHost.ownerDocument) !== null && _nodeRootHost$ownerDo !== void 0 && _nodeRootHost$ownerDo.contains(nodeRootHost) || node !== null && node !== void 0 && (_node$ownerDocument = node.ownerDocument) !== null && _node$ownerDocument !== void 0 && _node$ownerDocument.contains(node));
|
|
1129
|
+
while (!attached && nodeRootHost) {
|
|
1130
|
+
var _nodeRoot2, _nodeRootHost2, _nodeRootHost2$ownerD;
|
|
1131
|
+
// since it's not attached and we have a root host, the node MUST be in a nested shadow DOM,
|
|
1132
|
+
// which means we need to get the host's host and check if that parent host is contained
|
|
1133
|
+
// in (i.e. attached to) the document
|
|
1134
|
+
nodeRoot = getRootNode(nodeRootHost);
|
|
1135
|
+
nodeRootHost = (_nodeRoot2 = nodeRoot) === null || _nodeRoot2 === void 0 ? void 0 : _nodeRoot2.host;
|
|
1136
|
+
attached = !!((_nodeRootHost2 = nodeRootHost) !== null && _nodeRootHost2 !== void 0 && (_nodeRootHost2$ownerD = _nodeRootHost2.ownerDocument) !== null && _nodeRootHost2$ownerD !== void 0 && _nodeRootHost2$ownerD.contains(nodeRootHost));
|
|
1137
|
+
}
|
|
1138
|
+
}
|
|
1139
|
+
return attached;
|
|
1140
|
+
};
|
|
1141
|
+
var isZeroArea = function isZeroArea(node) {
|
|
1142
|
+
var _node$getBoundingClie = node.getBoundingClientRect(),
|
|
1143
|
+
width = _node$getBoundingClie.width,
|
|
1144
|
+
height = _node$getBoundingClie.height;
|
|
1145
|
+
return width === 0 && height === 0;
|
|
1146
|
+
};
|
|
1147
|
+
var isHidden = function isHidden(node, _ref) {
|
|
1148
|
+
var displayCheck = _ref.displayCheck,
|
|
1149
|
+
getShadowRoot = _ref.getShadowRoot;
|
|
1150
|
+
// NOTE: visibility will be `undefined` if node is detached from the document
|
|
1151
|
+
// (see notes about this further down), which means we will consider it visible
|
|
1152
|
+
// (this is legacy behavior from a very long way back)
|
|
1153
|
+
// NOTE: we check this regardless of `displayCheck="none"` because this is a
|
|
1154
|
+
// _visibility_ check, not a _display_ check
|
|
1155
|
+
if (getComputedStyle(node).visibility === 'hidden') {
|
|
1156
|
+
return true;
|
|
1157
|
+
}
|
|
1158
|
+
var isDirectSummary = matches.call(node, 'details>summary:first-of-type');
|
|
1159
|
+
var nodeUnderDetails = isDirectSummary ? node.parentElement : node;
|
|
1160
|
+
if (matches.call(nodeUnderDetails, 'details:not([open]) *')) {
|
|
1161
|
+
return true;
|
|
1162
|
+
}
|
|
1163
|
+
if (!displayCheck || displayCheck === 'full' || displayCheck === 'legacy-full') {
|
|
1164
|
+
if (typeof getShadowRoot === 'function') {
|
|
1165
|
+
// figure out if we should consider the node to be in an undisclosed shadow and use the
|
|
1166
|
+
// 'non-zero-area' fallback
|
|
1167
|
+
var originalNode = node;
|
|
1168
|
+
while (node) {
|
|
1169
|
+
var parentElement = node.parentElement;
|
|
1170
|
+
var rootNode = getRootNode(node);
|
|
1171
|
+
if (parentElement && !parentElement.shadowRoot && getShadowRoot(parentElement) === true // check if there's an undisclosed shadow
|
|
1172
|
+
) {
|
|
1173
|
+
// node has an undisclosed shadow which means we can only treat it as a black box, so we
|
|
1174
|
+
// fall back to a non-zero-area test
|
|
1175
|
+
return isZeroArea(node);
|
|
1176
|
+
} else if (node.assignedSlot) {
|
|
1177
|
+
// iterate up slot
|
|
1178
|
+
node = node.assignedSlot;
|
|
1179
|
+
} else if (!parentElement && rootNode !== node.ownerDocument) {
|
|
1180
|
+
// cross shadow boundary
|
|
1181
|
+
node = rootNode.host;
|
|
1182
|
+
} else {
|
|
1183
|
+
// iterate up normal dom
|
|
1184
|
+
node = parentElement;
|
|
1185
|
+
}
|
|
1186
|
+
}
|
|
1187
|
+
node = originalNode;
|
|
1188
|
+
}
|
|
1189
|
+
// else, `getShadowRoot` might be true, but all that does is enable shadow DOM support
|
|
1190
|
+
// (i.e. it does not also presume that all nodes might have undisclosed shadows); or
|
|
1191
|
+
// it might be a falsy value, which means shadow DOM support is disabled
|
|
1192
|
+
|
|
1193
|
+
// Since we didn't find it sitting in an undisclosed shadow (or shadows are disabled)
|
|
1194
|
+
// now we can just test to see if it would normally be visible or not, provided it's
|
|
1195
|
+
// attached to the main document.
|
|
1196
|
+
// NOTE: We must consider case where node is inside a shadow DOM and given directly to
|
|
1197
|
+
// `isTabbable()` or `isFocusable()` -- regardless of `getShadowRoot` option setting.
|
|
1198
|
+
|
|
1199
|
+
if (isNodeAttached(node)) {
|
|
1200
|
+
// this works wherever the node is: if there's at least one client rect, it's
|
|
1201
|
+
// somehow displayed; it also covers the CSS 'display: contents' case where the
|
|
1202
|
+
// node itself is hidden in place of its contents; and there's no need to search
|
|
1203
|
+
// up the hierarchy either
|
|
1204
|
+
return !node.getClientRects().length;
|
|
1205
|
+
}
|
|
1206
|
+
|
|
1207
|
+
// Else, the node isn't attached to the document, which means the `getClientRects()`
|
|
1208
|
+
// API will __always__ return zero rects (this can happen, for example, if React
|
|
1209
|
+
// is used to render nodes onto a detached tree, as confirmed in this thread:
|
|
1210
|
+
// https://github.com/facebook/react/issues/9117#issuecomment-284228870)
|
|
1211
|
+
//
|
|
1212
|
+
// It also means that even window.getComputedStyle(node).display will return `undefined`
|
|
1213
|
+
// because styles are only computed for nodes that are in the document.
|
|
1214
|
+
//
|
|
1215
|
+
// NOTE: THIS HAS BEEN THE CASE FOR YEARS. It is not new, nor is it caused by tabbable
|
|
1216
|
+
// somehow. Though it was never stated officially, anyone who has ever used tabbable
|
|
1217
|
+
// APIs on nodes in detached containers has actually implicitly used tabbable in what
|
|
1218
|
+
// was later (as of v5.2.0 on Apr 9, 2021) called `displayCheck="none"` mode -- essentially
|
|
1219
|
+
// considering __everything__ to be visible because of the innability to determine styles.
|
|
1220
|
+
//
|
|
1221
|
+
// v6.0.0: As of this major release, the default 'full' option __no longer treats detached
|
|
1222
|
+
// nodes as visible with the 'none' fallback.__
|
|
1223
|
+
if (displayCheck !== 'legacy-full') {
|
|
1224
|
+
return true; // hidden
|
|
1225
|
+
}
|
|
1226
|
+
// else, fallback to 'none' mode and consider the node visible
|
|
1227
|
+
} else if (displayCheck === 'non-zero-area') {
|
|
1228
|
+
// NOTE: Even though this tests that the node's client rect is non-zero to determine
|
|
1229
|
+
// whether it's displayed, and that a detached node will __always__ have a zero-area
|
|
1230
|
+
// client rect, we don't special-case for whether the node is attached or not. In
|
|
1231
|
+
// this mode, we do want to consider nodes that have a zero area to be hidden at all
|
|
1232
|
+
// times, and that includes attached or not.
|
|
1233
|
+
return isZeroArea(node);
|
|
1234
|
+
}
|
|
1235
|
+
|
|
1236
|
+
// visible, as far as we can tell, or per current `displayCheck=none` mode, we assume
|
|
1237
|
+
// it's visible
|
|
1238
|
+
return false;
|
|
1239
|
+
};
|
|
1240
|
+
|
|
1241
|
+
// form fields (nested) inside a disabled fieldset are not focusable/tabbable
|
|
1242
|
+
// unless they are in the _first_ <legend> element of the top-most disabled
|
|
1243
|
+
// fieldset
|
|
1244
|
+
var isDisabledFromFieldset = function isDisabledFromFieldset(node) {
|
|
1245
|
+
if (/^(INPUT|BUTTON|SELECT|TEXTAREA)$/.test(node.tagName)) {
|
|
1246
|
+
var parentNode = node.parentElement;
|
|
1247
|
+
// check if `node` is contained in a disabled <fieldset>
|
|
1248
|
+
while (parentNode) {
|
|
1249
|
+
if (parentNode.tagName === 'FIELDSET' && parentNode.disabled) {
|
|
1250
|
+
// look for the first <legend> among the children of the disabled <fieldset>
|
|
1251
|
+
for (var i = 0; i < parentNode.children.length; i++) {
|
|
1252
|
+
var child = parentNode.children.item(i);
|
|
1253
|
+
// when the first <legend> (in document order) is found
|
|
1254
|
+
if (child.tagName === 'LEGEND') {
|
|
1255
|
+
// if its parent <fieldset> is not nested in another disabled <fieldset>,
|
|
1256
|
+
// return whether `node` is a descendant of its first <legend>
|
|
1257
|
+
return matches.call(parentNode, 'fieldset[disabled] *') ? true : !child.contains(node);
|
|
1258
|
+
}
|
|
1259
|
+
}
|
|
1260
|
+
// the disabled <fieldset> containing `node` has no <legend>
|
|
1261
|
+
return true;
|
|
1262
|
+
}
|
|
1263
|
+
parentNode = parentNode.parentElement;
|
|
1264
|
+
}
|
|
1265
|
+
}
|
|
1266
|
+
|
|
1267
|
+
// else, node's tabbable/focusable state should not be affected by a fieldset's
|
|
1268
|
+
// enabled/disabled state
|
|
1269
|
+
return false;
|
|
1270
|
+
};
|
|
1271
|
+
var isNodeMatchingSelectorFocusable = function isNodeMatchingSelectorFocusable(options, node) {
|
|
1272
|
+
if (node.disabled ||
|
|
1273
|
+
// we must do an inert look up to filter out any elements inside an inert ancestor
|
|
1274
|
+
// because we're limited in the type of selectors we can use in JSDom (see related
|
|
1275
|
+
// note related to `candidateSelectors`)
|
|
1276
|
+
isInert(node) || isHiddenInput(node) || isHidden(node, options) ||
|
|
1277
|
+
// For a details element with a summary, the summary element gets the focus
|
|
1278
|
+
isDetailsWithSummary(node) || isDisabledFromFieldset(node)) {
|
|
1279
|
+
return false;
|
|
1280
|
+
}
|
|
1281
|
+
return true;
|
|
1282
|
+
};
|
|
1283
|
+
var isNodeMatchingSelectorTabbable = function isNodeMatchingSelectorTabbable(options, node) {
|
|
1284
|
+
if (isNonTabbableRadio(node) || getTabIndex(node) < 0 || !isNodeMatchingSelectorFocusable(options, node)) {
|
|
1285
|
+
return false;
|
|
1286
|
+
}
|
|
1287
|
+
return true;
|
|
1288
|
+
};
|
|
1289
|
+
var isValidShadowRootTabbable = function isValidShadowRootTabbable(shadowHostNode) {
|
|
1290
|
+
var tabIndex = parseInt(shadowHostNode.getAttribute('tabindex'), 10);
|
|
1291
|
+
if (isNaN(tabIndex) || tabIndex >= 0) {
|
|
1292
|
+
return true;
|
|
1293
|
+
}
|
|
1294
|
+
// If a custom element has an explicit negative tabindex,
|
|
1295
|
+
// browsers will not allow tab targeting said element's children.
|
|
1296
|
+
return false;
|
|
1297
|
+
};
|
|
1298
|
+
|
|
1299
|
+
/**
|
|
1300
|
+
* @param {Array.<Element|CandidateScope>} candidates
|
|
1301
|
+
* @returns Element[]
|
|
1302
|
+
*/
|
|
1303
|
+
var sortByOrder = function sortByOrder(candidates) {
|
|
1304
|
+
var regularTabbables = [];
|
|
1305
|
+
var orderedTabbables = [];
|
|
1306
|
+
candidates.forEach(function (item, i) {
|
|
1307
|
+
var isScope = !!item.scopeParent;
|
|
1308
|
+
var element = isScope ? item.scopeParent : item;
|
|
1309
|
+
var candidateTabindex = getSortOrderTabIndex(element, isScope);
|
|
1310
|
+
var elements = isScope ? sortByOrder(item.candidates) : element;
|
|
1311
|
+
if (candidateTabindex === 0) {
|
|
1312
|
+
isScope ? regularTabbables.push.apply(regularTabbables, elements) : regularTabbables.push(element);
|
|
1313
|
+
} else {
|
|
1314
|
+
orderedTabbables.push({
|
|
1315
|
+
documentOrder: i,
|
|
1316
|
+
tabIndex: candidateTabindex,
|
|
1317
|
+
item: item,
|
|
1318
|
+
isScope: isScope,
|
|
1319
|
+
content: elements
|
|
1320
|
+
});
|
|
1321
|
+
}
|
|
1322
|
+
});
|
|
1323
|
+
return orderedTabbables.sort(sortOrderedTabbables).reduce(function (acc, sortable) {
|
|
1324
|
+
sortable.isScope ? acc.push.apply(acc, sortable.content) : acc.push(sortable.content);
|
|
1325
|
+
return acc;
|
|
1326
|
+
}, []).concat(regularTabbables);
|
|
1327
|
+
};
|
|
1328
|
+
var tabbable = function tabbable(container, options) {
|
|
1329
|
+
options = options || {};
|
|
1330
|
+
var candidates;
|
|
1331
|
+
if (options.getShadowRoot) {
|
|
1332
|
+
candidates = getCandidatesIteratively([container], options.includeContainer, {
|
|
1333
|
+
filter: isNodeMatchingSelectorTabbable.bind(null, options),
|
|
1334
|
+
flatten: false,
|
|
1335
|
+
getShadowRoot: options.getShadowRoot,
|
|
1336
|
+
shadowRootFilter: isValidShadowRootTabbable
|
|
1337
|
+
});
|
|
1338
|
+
} else {
|
|
1339
|
+
candidates = getCandidates(container, options.includeContainer, isNodeMatchingSelectorTabbable.bind(null, options));
|
|
1340
|
+
}
|
|
1341
|
+
return sortByOrder(candidates);
|
|
1342
|
+
};
|
|
1343
|
+
|
|
1344
|
+
function getCssDimensions(element) {
|
|
1345
|
+
const css = getComputedStyle$1(element);
|
|
1346
|
+
// In testing environments, the `width` and `height` properties are empty
|
|
1347
|
+
// strings for SVG elements, returning NaN. Fallback to `0` in this case.
|
|
1348
|
+
let width = parseFloat(css.width) || 0;
|
|
1349
|
+
let height = parseFloat(css.height) || 0;
|
|
1350
|
+
const hasOffset = isHTMLElement(element);
|
|
1351
|
+
const offsetWidth = hasOffset ? element.offsetWidth : width;
|
|
1352
|
+
const offsetHeight = hasOffset ? element.offsetHeight : height;
|
|
1353
|
+
const shouldFallback = round(width) !== offsetWidth || round(height) !== offsetHeight;
|
|
1354
|
+
if (shouldFallback) {
|
|
1355
|
+
width = offsetWidth;
|
|
1356
|
+
height = offsetHeight;
|
|
1357
|
+
}
|
|
1358
|
+
return {
|
|
1359
|
+
width,
|
|
1360
|
+
height,
|
|
1361
|
+
$: shouldFallback
|
|
1362
|
+
};
|
|
1363
|
+
}
|
|
1364
|
+
|
|
1365
|
+
function unwrapElement(element) {
|
|
1366
|
+
return !isElement(element) ? element.contextElement : element;
|
|
1367
|
+
}
|
|
1368
|
+
|
|
1369
|
+
function getScale(element) {
|
|
1370
|
+
const domElement = unwrapElement(element);
|
|
1371
|
+
if (!isHTMLElement(domElement)) {
|
|
1372
|
+
return createCoords(1);
|
|
1373
|
+
}
|
|
1374
|
+
const rect = domElement.getBoundingClientRect();
|
|
1375
|
+
const {
|
|
1376
|
+
width,
|
|
1377
|
+
height,
|
|
1378
|
+
$
|
|
1379
|
+
} = getCssDimensions(domElement);
|
|
1380
|
+
let x = ($ ? round(rect.width) : rect.width) / width;
|
|
1381
|
+
let y = ($ ? round(rect.height) : rect.height) / height;
|
|
1382
|
+
|
|
1383
|
+
// 0, NaN, or Infinity should always fallback to 1.
|
|
1384
|
+
|
|
1385
|
+
if (!x || !Number.isFinite(x)) {
|
|
1386
|
+
x = 1;
|
|
1387
|
+
}
|
|
1388
|
+
if (!y || !Number.isFinite(y)) {
|
|
1389
|
+
y = 1;
|
|
1390
|
+
}
|
|
1391
|
+
return {
|
|
1392
|
+
x,
|
|
1393
|
+
y
|
|
1394
|
+
};
|
|
1395
|
+
}
|
|
1396
|
+
|
|
1397
|
+
const noOffsets = /*#__PURE__*/createCoords(0);
|
|
1398
|
+
function getVisualOffsets(element) {
|
|
1399
|
+
const win = getWindow(element);
|
|
1400
|
+
if (!isWebKit() || !win.visualViewport) {
|
|
1401
|
+
return noOffsets;
|
|
1402
|
+
}
|
|
1403
|
+
return {
|
|
1404
|
+
x: win.visualViewport.offsetLeft,
|
|
1405
|
+
y: win.visualViewport.offsetTop
|
|
1406
|
+
};
|
|
1407
|
+
}
|
|
1408
|
+
function shouldAddVisualOffsets(element, isFixed, floatingOffsetParent) {
|
|
1409
|
+
if (isFixed === void 0) {
|
|
1410
|
+
isFixed = false;
|
|
1411
|
+
}
|
|
1412
|
+
if (!floatingOffsetParent || isFixed && floatingOffsetParent !== getWindow(element)) {
|
|
1413
|
+
return false;
|
|
1414
|
+
}
|
|
1415
|
+
return isFixed;
|
|
1416
|
+
}
|
|
1417
|
+
|
|
1418
|
+
function getBoundingClientRect(element, includeScale, isFixedStrategy, offsetParent) {
|
|
1419
|
+
if (includeScale === void 0) {
|
|
1420
|
+
includeScale = false;
|
|
1421
|
+
}
|
|
1422
|
+
if (isFixedStrategy === void 0) {
|
|
1423
|
+
isFixedStrategy = false;
|
|
1424
|
+
}
|
|
1425
|
+
const clientRect = element.getBoundingClientRect();
|
|
1426
|
+
const domElement = unwrapElement(element);
|
|
1427
|
+
let scale = createCoords(1);
|
|
1428
|
+
if (includeScale) {
|
|
1429
|
+
if (offsetParent) {
|
|
1430
|
+
if (isElement(offsetParent)) {
|
|
1431
|
+
scale = getScale(offsetParent);
|
|
1432
|
+
}
|
|
1433
|
+
} else {
|
|
1434
|
+
scale = getScale(element);
|
|
1435
|
+
}
|
|
1436
|
+
}
|
|
1437
|
+
const visualOffsets = shouldAddVisualOffsets(domElement, isFixedStrategy, offsetParent) ? getVisualOffsets(domElement) : createCoords(0);
|
|
1438
|
+
let x = (clientRect.left + visualOffsets.x) / scale.x;
|
|
1439
|
+
let y = (clientRect.top + visualOffsets.y) / scale.y;
|
|
1440
|
+
let width = clientRect.width / scale.x;
|
|
1441
|
+
let height = clientRect.height / scale.y;
|
|
1442
|
+
if (domElement) {
|
|
1443
|
+
const win = getWindow(domElement);
|
|
1444
|
+
const offsetWin = offsetParent && isElement(offsetParent) ? getWindow(offsetParent) : offsetParent;
|
|
1445
|
+
let currentWin = win;
|
|
1446
|
+
let currentIFrame = currentWin.frameElement;
|
|
1447
|
+
while (currentIFrame && offsetParent && offsetWin !== currentWin) {
|
|
1448
|
+
const iframeScale = getScale(currentIFrame);
|
|
1449
|
+
const iframeRect = currentIFrame.getBoundingClientRect();
|
|
1450
|
+
const css = getComputedStyle$1(currentIFrame);
|
|
1451
|
+
const left = iframeRect.left + (currentIFrame.clientLeft + parseFloat(css.paddingLeft)) * iframeScale.x;
|
|
1452
|
+
const top = iframeRect.top + (currentIFrame.clientTop + parseFloat(css.paddingTop)) * iframeScale.y;
|
|
1453
|
+
x *= iframeScale.x;
|
|
1454
|
+
y *= iframeScale.y;
|
|
1455
|
+
width *= iframeScale.x;
|
|
1456
|
+
height *= iframeScale.y;
|
|
1457
|
+
x += left;
|
|
1458
|
+
y += top;
|
|
1459
|
+
currentWin = getWindow(currentIFrame);
|
|
1460
|
+
currentIFrame = currentWin.frameElement;
|
|
1461
|
+
}
|
|
1462
|
+
}
|
|
1463
|
+
return rectToClientRect({
|
|
1464
|
+
width,
|
|
1465
|
+
height,
|
|
1466
|
+
x,
|
|
1467
|
+
y
|
|
1468
|
+
});
|
|
1469
|
+
}
|
|
1470
|
+
|
|
1471
|
+
const topLayerSelectors = [':popover-open', ':modal'];
|
|
1472
|
+
function isTopLayer(floating) {
|
|
1473
|
+
return topLayerSelectors.some(selector => {
|
|
1474
|
+
try {
|
|
1475
|
+
return floating.matches(selector);
|
|
1476
|
+
} catch (e) {
|
|
1477
|
+
return false;
|
|
1478
|
+
}
|
|
1479
|
+
});
|
|
1480
|
+
}
|
|
1481
|
+
|
|
1482
|
+
function convertOffsetParentRelativeRectToViewportRelativeRect(_ref) {
|
|
1483
|
+
let {
|
|
1484
|
+
elements,
|
|
1485
|
+
rect,
|
|
1486
|
+
offsetParent,
|
|
1487
|
+
strategy
|
|
1488
|
+
} = _ref;
|
|
1489
|
+
const isFixed = strategy === 'fixed';
|
|
1490
|
+
const documentElement = getDocumentElement(offsetParent);
|
|
1491
|
+
const topLayer = elements ? isTopLayer(elements.floating) : false;
|
|
1492
|
+
if (offsetParent === documentElement || topLayer && isFixed) {
|
|
1493
|
+
return rect;
|
|
1494
|
+
}
|
|
1495
|
+
let scroll = {
|
|
1496
|
+
scrollLeft: 0,
|
|
1497
|
+
scrollTop: 0
|
|
1498
|
+
};
|
|
1499
|
+
let scale = createCoords(1);
|
|
1500
|
+
const offsets = createCoords(0);
|
|
1501
|
+
const isOffsetParentAnElement = isHTMLElement(offsetParent);
|
|
1502
|
+
if (isOffsetParentAnElement || !isOffsetParentAnElement && !isFixed) {
|
|
1503
|
+
if (getNodeName(offsetParent) !== 'body' || isOverflowElement(documentElement)) {
|
|
1504
|
+
scroll = getNodeScroll(offsetParent);
|
|
1505
|
+
}
|
|
1506
|
+
if (isHTMLElement(offsetParent)) {
|
|
1507
|
+
const offsetRect = getBoundingClientRect(offsetParent);
|
|
1508
|
+
scale = getScale(offsetParent);
|
|
1509
|
+
offsets.x = offsetRect.x + offsetParent.clientLeft;
|
|
1510
|
+
offsets.y = offsetRect.y + offsetParent.clientTop;
|
|
1511
|
+
}
|
|
1512
|
+
}
|
|
1513
|
+
return {
|
|
1514
|
+
width: rect.width * scale.x,
|
|
1515
|
+
height: rect.height * scale.y,
|
|
1516
|
+
x: rect.x * scale.x - scroll.scrollLeft * scale.x + offsets.x,
|
|
1517
|
+
y: rect.y * scale.y - scroll.scrollTop * scale.y + offsets.y
|
|
1518
|
+
};
|
|
1519
|
+
}
|
|
1520
|
+
|
|
1521
|
+
function getClientRects(element) {
|
|
1522
|
+
return Array.from(element.getClientRects());
|
|
1523
|
+
}
|
|
1524
|
+
|
|
1525
|
+
function getWindowScrollBarX(element) {
|
|
1526
|
+
// If <html> has a CSS width greater than the viewport, then this will be
|
|
1527
|
+
// incorrect for RTL.
|
|
1528
|
+
return getBoundingClientRect(getDocumentElement(element)).left + getNodeScroll(element).scrollLeft;
|
|
1529
|
+
}
|
|
1530
|
+
|
|
1531
|
+
// Gets the entire size of the scrollable document area, even extending outside
|
|
1532
|
+
// of the `<html>` and `<body>` rect bounds if horizontally scrollable.
|
|
1533
|
+
function getDocumentRect(element) {
|
|
1534
|
+
const html = getDocumentElement(element);
|
|
1535
|
+
const scroll = getNodeScroll(element);
|
|
1536
|
+
const body = element.ownerDocument.body;
|
|
1537
|
+
const width = max(html.scrollWidth, html.clientWidth, body.scrollWidth, body.clientWidth);
|
|
1538
|
+
const height = max(html.scrollHeight, html.clientHeight, body.scrollHeight, body.clientHeight);
|
|
1539
|
+
let x = -scroll.scrollLeft + getWindowScrollBarX(element);
|
|
1540
|
+
const y = -scroll.scrollTop;
|
|
1541
|
+
if (getComputedStyle$1(body).direction === 'rtl') {
|
|
1542
|
+
x += max(html.clientWidth, body.clientWidth) - width;
|
|
1543
|
+
}
|
|
1544
|
+
return {
|
|
1545
|
+
width,
|
|
1546
|
+
height,
|
|
1547
|
+
x,
|
|
1548
|
+
y
|
|
1549
|
+
};
|
|
1550
|
+
}
|
|
1551
|
+
|
|
1552
|
+
function getViewportRect(element, strategy) {
|
|
1553
|
+
const win = getWindow(element);
|
|
1554
|
+
const html = getDocumentElement(element);
|
|
1555
|
+
const visualViewport = win.visualViewport;
|
|
1556
|
+
let width = html.clientWidth;
|
|
1557
|
+
let height = html.clientHeight;
|
|
1558
|
+
let x = 0;
|
|
1559
|
+
let y = 0;
|
|
1560
|
+
if (visualViewport) {
|
|
1561
|
+
width = visualViewport.width;
|
|
1562
|
+
height = visualViewport.height;
|
|
1563
|
+
const visualViewportBased = isWebKit();
|
|
1564
|
+
if (!visualViewportBased || visualViewportBased && strategy === 'fixed') {
|
|
1565
|
+
x = visualViewport.offsetLeft;
|
|
1566
|
+
y = visualViewport.offsetTop;
|
|
1567
|
+
}
|
|
1568
|
+
}
|
|
1569
|
+
return {
|
|
1570
|
+
width,
|
|
1571
|
+
height,
|
|
1572
|
+
x,
|
|
1573
|
+
y
|
|
1574
|
+
};
|
|
1575
|
+
}
|
|
1576
|
+
|
|
1577
|
+
// Returns the inner client rect, subtracting scrollbars if present.
|
|
1578
|
+
function getInnerBoundingClientRect(element, strategy) {
|
|
1579
|
+
const clientRect = getBoundingClientRect(element, true, strategy === 'fixed');
|
|
1580
|
+
const top = clientRect.top + element.clientTop;
|
|
1581
|
+
const left = clientRect.left + element.clientLeft;
|
|
1582
|
+
const scale = isHTMLElement(element) ? getScale(element) : createCoords(1);
|
|
1583
|
+
const width = element.clientWidth * scale.x;
|
|
1584
|
+
const height = element.clientHeight * scale.y;
|
|
1585
|
+
const x = left * scale.x;
|
|
1586
|
+
const y = top * scale.y;
|
|
1587
|
+
return {
|
|
1588
|
+
width,
|
|
1589
|
+
height,
|
|
1590
|
+
x,
|
|
1591
|
+
y
|
|
1592
|
+
};
|
|
1593
|
+
}
|
|
1594
|
+
function getClientRectFromClippingAncestor(element, clippingAncestor, strategy) {
|
|
1595
|
+
let rect;
|
|
1596
|
+
if (clippingAncestor === 'viewport') {
|
|
1597
|
+
rect = getViewportRect(element, strategy);
|
|
1598
|
+
} else if (clippingAncestor === 'document') {
|
|
1599
|
+
rect = getDocumentRect(getDocumentElement(element));
|
|
1600
|
+
} else if (isElement(clippingAncestor)) {
|
|
1601
|
+
rect = getInnerBoundingClientRect(clippingAncestor, strategy);
|
|
1602
|
+
} else {
|
|
1603
|
+
const visualOffsets = getVisualOffsets(element);
|
|
1604
|
+
rect = {
|
|
1605
|
+
...clippingAncestor,
|
|
1606
|
+
x: clippingAncestor.x - visualOffsets.x,
|
|
1607
|
+
y: clippingAncestor.y - visualOffsets.y
|
|
1608
|
+
};
|
|
1609
|
+
}
|
|
1610
|
+
return rectToClientRect(rect);
|
|
1611
|
+
}
|
|
1612
|
+
function hasFixedPositionAncestor(element, stopNode) {
|
|
1613
|
+
const parentNode = getParentNode(element);
|
|
1614
|
+
if (parentNode === stopNode || !isElement(parentNode) || isLastTraversableNode(parentNode)) {
|
|
1615
|
+
return false;
|
|
1616
|
+
}
|
|
1617
|
+
return getComputedStyle$1(parentNode).position === 'fixed' || hasFixedPositionAncestor(parentNode, stopNode);
|
|
1618
|
+
}
|
|
1619
|
+
|
|
1620
|
+
// A "clipping ancestor" is an `overflow` element with the characteristic of
|
|
1621
|
+
// clipping (or hiding) child elements. This returns all clipping ancestors
|
|
1622
|
+
// of the given element up the tree.
|
|
1623
|
+
function getClippingElementAncestors(element, cache) {
|
|
1624
|
+
const cachedResult = cache.get(element);
|
|
1625
|
+
if (cachedResult) {
|
|
1626
|
+
return cachedResult;
|
|
1627
|
+
}
|
|
1628
|
+
let result = getOverflowAncestors(element, [], false).filter(el => isElement(el) && getNodeName(el) !== 'body');
|
|
1629
|
+
let currentContainingBlockComputedStyle = null;
|
|
1630
|
+
const elementIsFixed = getComputedStyle$1(element).position === 'fixed';
|
|
1631
|
+
let currentNode = elementIsFixed ? getParentNode(element) : element;
|
|
1632
|
+
|
|
1633
|
+
// https://developer.mozilla.org/en-US/docs/Web/CSS/Containing_block#identifying_the_containing_block
|
|
1634
|
+
while (isElement(currentNode) && !isLastTraversableNode(currentNode)) {
|
|
1635
|
+
const computedStyle = getComputedStyle$1(currentNode);
|
|
1636
|
+
const currentNodeIsContaining = isContainingBlock(currentNode);
|
|
1637
|
+
if (!currentNodeIsContaining && computedStyle.position === 'fixed') {
|
|
1638
|
+
currentContainingBlockComputedStyle = null;
|
|
1639
|
+
}
|
|
1640
|
+
const shouldDropCurrentNode = elementIsFixed ? !currentNodeIsContaining && !currentContainingBlockComputedStyle : !currentNodeIsContaining && computedStyle.position === 'static' && !!currentContainingBlockComputedStyle && ['absolute', 'fixed'].includes(currentContainingBlockComputedStyle.position) || isOverflowElement(currentNode) && !currentNodeIsContaining && hasFixedPositionAncestor(element, currentNode);
|
|
1641
|
+
if (shouldDropCurrentNode) {
|
|
1642
|
+
// Drop non-containing blocks.
|
|
1643
|
+
result = result.filter(ancestor => ancestor !== currentNode);
|
|
1644
|
+
} else {
|
|
1645
|
+
// Record last containing block for next iteration.
|
|
1646
|
+
currentContainingBlockComputedStyle = computedStyle;
|
|
1647
|
+
}
|
|
1648
|
+
currentNode = getParentNode(currentNode);
|
|
1649
|
+
}
|
|
1650
|
+
cache.set(element, result);
|
|
1651
|
+
return result;
|
|
1652
|
+
}
|
|
1653
|
+
|
|
1654
|
+
// Gets the maximum area that the element is visible in due to any number of
|
|
1655
|
+
// clipping ancestors.
|
|
1656
|
+
function getClippingRect(_ref) {
|
|
1657
|
+
let {
|
|
1658
|
+
element,
|
|
1659
|
+
boundary,
|
|
1660
|
+
rootBoundary,
|
|
1661
|
+
strategy
|
|
1662
|
+
} = _ref;
|
|
1663
|
+
const elementClippingAncestors = boundary === 'clippingAncestors' ? getClippingElementAncestors(element, this._c) : [].concat(boundary);
|
|
1664
|
+
const clippingAncestors = [...elementClippingAncestors, rootBoundary];
|
|
1665
|
+
const firstClippingAncestor = clippingAncestors[0];
|
|
1666
|
+
const clippingRect = clippingAncestors.reduce((accRect, clippingAncestor) => {
|
|
1667
|
+
const rect = getClientRectFromClippingAncestor(element, clippingAncestor, strategy);
|
|
1668
|
+
accRect.top = max(rect.top, accRect.top);
|
|
1669
|
+
accRect.right = min(rect.right, accRect.right);
|
|
1670
|
+
accRect.bottom = min(rect.bottom, accRect.bottom);
|
|
1671
|
+
accRect.left = max(rect.left, accRect.left);
|
|
1672
|
+
return accRect;
|
|
1673
|
+
}, getClientRectFromClippingAncestor(element, firstClippingAncestor, strategy));
|
|
1674
|
+
return {
|
|
1675
|
+
width: clippingRect.right - clippingRect.left,
|
|
1676
|
+
height: clippingRect.bottom - clippingRect.top,
|
|
1677
|
+
x: clippingRect.left,
|
|
1678
|
+
y: clippingRect.top
|
|
1679
|
+
};
|
|
1680
|
+
}
|
|
1681
|
+
|
|
1682
|
+
function getDimensions(element) {
|
|
1683
|
+
const {
|
|
1684
|
+
width,
|
|
1685
|
+
height
|
|
1686
|
+
} = getCssDimensions(element);
|
|
1687
|
+
return {
|
|
1688
|
+
width,
|
|
1689
|
+
height
|
|
1690
|
+
};
|
|
1691
|
+
}
|
|
1692
|
+
|
|
1693
|
+
function getRectRelativeToOffsetParent(element, offsetParent, strategy) {
|
|
1694
|
+
const isOffsetParentAnElement = isHTMLElement(offsetParent);
|
|
1695
|
+
const documentElement = getDocumentElement(offsetParent);
|
|
1696
|
+
const isFixed = strategy === 'fixed';
|
|
1697
|
+
const rect = getBoundingClientRect(element, true, isFixed, offsetParent);
|
|
1698
|
+
let scroll = {
|
|
1699
|
+
scrollLeft: 0,
|
|
1700
|
+
scrollTop: 0
|
|
1701
|
+
};
|
|
1702
|
+
const offsets = createCoords(0);
|
|
1703
|
+
if (isOffsetParentAnElement || !isOffsetParentAnElement && !isFixed) {
|
|
1704
|
+
if (getNodeName(offsetParent) !== 'body' || isOverflowElement(documentElement)) {
|
|
1705
|
+
scroll = getNodeScroll(offsetParent);
|
|
1706
|
+
}
|
|
1707
|
+
if (isOffsetParentAnElement) {
|
|
1708
|
+
const offsetRect = getBoundingClientRect(offsetParent, true, isFixed, offsetParent);
|
|
1709
|
+
offsets.x = offsetRect.x + offsetParent.clientLeft;
|
|
1710
|
+
offsets.y = offsetRect.y + offsetParent.clientTop;
|
|
1711
|
+
} else if (documentElement) {
|
|
1712
|
+
offsets.x = getWindowScrollBarX(documentElement);
|
|
1713
|
+
}
|
|
1714
|
+
}
|
|
1715
|
+
const x = rect.left + scroll.scrollLeft - offsets.x;
|
|
1716
|
+
const y = rect.top + scroll.scrollTop - offsets.y;
|
|
1717
|
+
return {
|
|
1718
|
+
x,
|
|
1719
|
+
y,
|
|
1720
|
+
width: rect.width,
|
|
1721
|
+
height: rect.height
|
|
1722
|
+
};
|
|
1723
|
+
}
|
|
1724
|
+
|
|
1725
|
+
function getTrueOffsetParent(element, polyfill) {
|
|
1726
|
+
if (!isHTMLElement(element) || getComputedStyle$1(element).position === 'fixed') {
|
|
1727
|
+
return null;
|
|
1728
|
+
}
|
|
1729
|
+
if (polyfill) {
|
|
1730
|
+
return polyfill(element);
|
|
1731
|
+
}
|
|
1732
|
+
return element.offsetParent;
|
|
1733
|
+
}
|
|
1734
|
+
|
|
1735
|
+
// Gets the closest ancestor positioned element. Handles some edge cases,
|
|
1736
|
+
// such as table ancestors and cross browser bugs.
|
|
1737
|
+
function getOffsetParent(element, polyfill) {
|
|
1738
|
+
const window = getWindow(element);
|
|
1739
|
+
if (!isHTMLElement(element) || isTopLayer(element)) {
|
|
1740
|
+
return window;
|
|
1741
|
+
}
|
|
1742
|
+
let offsetParent = getTrueOffsetParent(element, polyfill);
|
|
1743
|
+
while (offsetParent && isTableElement(offsetParent) && getComputedStyle$1(offsetParent).position === 'static') {
|
|
1744
|
+
offsetParent = getTrueOffsetParent(offsetParent, polyfill);
|
|
1745
|
+
}
|
|
1746
|
+
if (offsetParent && (getNodeName(offsetParent) === 'html' || getNodeName(offsetParent) === 'body' && getComputedStyle$1(offsetParent).position === 'static' && !isContainingBlock(offsetParent))) {
|
|
1747
|
+
return window;
|
|
1748
|
+
}
|
|
1749
|
+
return offsetParent || getContainingBlock(element) || window;
|
|
1750
|
+
}
|
|
1751
|
+
|
|
1752
|
+
const getElementRects = async function (data) {
|
|
1753
|
+
const getOffsetParentFn = this.getOffsetParent || getOffsetParent;
|
|
1754
|
+
const getDimensionsFn = this.getDimensions;
|
|
1755
|
+
return {
|
|
1756
|
+
reference: getRectRelativeToOffsetParent(data.reference, await getOffsetParentFn(data.floating), data.strategy),
|
|
1757
|
+
floating: {
|
|
1758
|
+
x: 0,
|
|
1759
|
+
y: 0,
|
|
1760
|
+
...(await getDimensionsFn(data.floating))
|
|
1761
|
+
}
|
|
1762
|
+
};
|
|
1763
|
+
};
|
|
1764
|
+
|
|
1765
|
+
function isRTL(element) {
|
|
1766
|
+
return getComputedStyle$1(element).direction === 'rtl';
|
|
1767
|
+
}
|
|
1768
|
+
|
|
1769
|
+
const platform = {
|
|
1770
|
+
convertOffsetParentRelativeRectToViewportRelativeRect,
|
|
1771
|
+
getDocumentElement,
|
|
1772
|
+
getClippingRect,
|
|
1773
|
+
getOffsetParent,
|
|
1774
|
+
getElementRects,
|
|
1775
|
+
getClientRects,
|
|
1776
|
+
getDimensions,
|
|
1777
|
+
getScale,
|
|
1778
|
+
isElement,
|
|
1779
|
+
isRTL
|
|
1780
|
+
};
|
|
1781
|
+
|
|
1782
|
+
// https://samthor.au/2021/observing-dom/
|
|
1783
|
+
function observeMove(element, onMove) {
|
|
1784
|
+
let io = null;
|
|
1785
|
+
let timeoutId;
|
|
1786
|
+
const root = getDocumentElement(element);
|
|
1787
|
+
function cleanup() {
|
|
1788
|
+
var _io;
|
|
1789
|
+
clearTimeout(timeoutId);
|
|
1790
|
+
(_io = io) == null || _io.disconnect();
|
|
1791
|
+
io = null;
|
|
1792
|
+
}
|
|
1793
|
+
function refresh(skip, threshold) {
|
|
1794
|
+
if (skip === void 0) {
|
|
1795
|
+
skip = false;
|
|
1796
|
+
}
|
|
1797
|
+
if (threshold === void 0) {
|
|
1798
|
+
threshold = 1;
|
|
1799
|
+
}
|
|
1800
|
+
cleanup();
|
|
1801
|
+
const {
|
|
1802
|
+
left,
|
|
1803
|
+
top,
|
|
1804
|
+
width,
|
|
1805
|
+
height
|
|
1806
|
+
} = element.getBoundingClientRect();
|
|
1807
|
+
if (!skip) {
|
|
1808
|
+
onMove();
|
|
1809
|
+
}
|
|
1810
|
+
if (!width || !height) {
|
|
1811
|
+
return;
|
|
1812
|
+
}
|
|
1813
|
+
const insetTop = floor(top);
|
|
1814
|
+
const insetRight = floor(root.clientWidth - (left + width));
|
|
1815
|
+
const insetBottom = floor(root.clientHeight - (top + height));
|
|
1816
|
+
const insetLeft = floor(left);
|
|
1817
|
+
const rootMargin = -insetTop + "px " + -insetRight + "px " + -insetBottom + "px " + -insetLeft + "px";
|
|
1818
|
+
const options = {
|
|
1819
|
+
rootMargin,
|
|
1820
|
+
threshold: max(0, min(1, threshold)) || 1
|
|
1821
|
+
};
|
|
1822
|
+
let isFirstUpdate = true;
|
|
1823
|
+
function handleObserve(entries) {
|
|
1824
|
+
const ratio = entries[0].intersectionRatio;
|
|
1825
|
+
if (ratio !== threshold) {
|
|
1826
|
+
if (!isFirstUpdate) {
|
|
1827
|
+
return refresh();
|
|
1828
|
+
}
|
|
1829
|
+
if (!ratio) {
|
|
1830
|
+
timeoutId = setTimeout(() => {
|
|
1831
|
+
refresh(false, 1e-7);
|
|
1832
|
+
}, 100);
|
|
1833
|
+
} else {
|
|
1834
|
+
refresh(false, ratio);
|
|
1835
|
+
}
|
|
1836
|
+
}
|
|
1837
|
+
isFirstUpdate = false;
|
|
1838
|
+
}
|
|
1839
|
+
|
|
1840
|
+
// Older browsers don't support a `document` as the root and will throw an
|
|
1841
|
+
// error.
|
|
1842
|
+
try {
|
|
1843
|
+
io = new IntersectionObserver(handleObserve, {
|
|
1844
|
+
...options,
|
|
1845
|
+
// Handle <iframe>s
|
|
1846
|
+
root: root.ownerDocument
|
|
1847
|
+
});
|
|
1848
|
+
} catch (e) {
|
|
1849
|
+
io = new IntersectionObserver(handleObserve, options);
|
|
1850
|
+
}
|
|
1851
|
+
io.observe(element);
|
|
1852
|
+
}
|
|
1853
|
+
refresh(true);
|
|
1854
|
+
return cleanup;
|
|
1855
|
+
}
|
|
1856
|
+
|
|
1857
|
+
/**
|
|
1858
|
+
* Automatically updates the position of the floating element when necessary.
|
|
1859
|
+
* Should only be called when the floating element is mounted on the DOM or
|
|
1860
|
+
* visible on the screen.
|
|
1861
|
+
* @returns cleanup function that should be invoked when the floating element is
|
|
1862
|
+
* removed from the DOM or hidden from the screen.
|
|
1863
|
+
* @see https://floating-ui.com/docs/autoUpdate
|
|
1864
|
+
*/
|
|
1865
|
+
function autoUpdate(reference, floating, update, options) {
|
|
1866
|
+
if (options === void 0) {
|
|
1867
|
+
options = {};
|
|
1868
|
+
}
|
|
1869
|
+
const {
|
|
1870
|
+
ancestorScroll = true,
|
|
1871
|
+
ancestorResize = true,
|
|
1872
|
+
elementResize = typeof ResizeObserver === 'function',
|
|
1873
|
+
layoutShift = typeof IntersectionObserver === 'function',
|
|
1874
|
+
animationFrame = false
|
|
1875
|
+
} = options;
|
|
1876
|
+
const referenceEl = unwrapElement(reference);
|
|
1877
|
+
const ancestors = ancestorScroll || ancestorResize ? [...(referenceEl ? getOverflowAncestors(referenceEl) : []), ...getOverflowAncestors(floating)] : [];
|
|
1878
|
+
ancestors.forEach(ancestor => {
|
|
1879
|
+
ancestorScroll && ancestor.addEventListener('scroll', update, {
|
|
1880
|
+
passive: true
|
|
1881
|
+
});
|
|
1882
|
+
ancestorResize && ancestor.addEventListener('resize', update);
|
|
1883
|
+
});
|
|
1884
|
+
const cleanupIo = referenceEl && layoutShift ? observeMove(referenceEl, update) : null;
|
|
1885
|
+
let reobserveFrame = -1;
|
|
1886
|
+
let resizeObserver = null;
|
|
1887
|
+
if (elementResize) {
|
|
1888
|
+
resizeObserver = new ResizeObserver(_ref => {
|
|
1889
|
+
let [firstEntry] = _ref;
|
|
1890
|
+
if (firstEntry && firstEntry.target === referenceEl && resizeObserver) {
|
|
1891
|
+
// Prevent update loops when using the `size` middleware.
|
|
1892
|
+
// https://github.com/floating-ui/floating-ui/issues/1740
|
|
1893
|
+
resizeObserver.unobserve(floating);
|
|
1894
|
+
cancelAnimationFrame(reobserveFrame);
|
|
1895
|
+
reobserveFrame = requestAnimationFrame(() => {
|
|
1896
|
+
var _resizeObserver;
|
|
1897
|
+
(_resizeObserver = resizeObserver) == null || _resizeObserver.observe(floating);
|
|
1898
|
+
});
|
|
1899
|
+
}
|
|
1900
|
+
update();
|
|
1901
|
+
});
|
|
1902
|
+
if (referenceEl && !animationFrame) {
|
|
1903
|
+
resizeObserver.observe(referenceEl);
|
|
1904
|
+
}
|
|
1905
|
+
resizeObserver.observe(floating);
|
|
1906
|
+
}
|
|
1907
|
+
let frameId;
|
|
1908
|
+
let prevRefRect = animationFrame ? getBoundingClientRect(reference) : null;
|
|
1909
|
+
if (animationFrame) {
|
|
1910
|
+
frameLoop();
|
|
1911
|
+
}
|
|
1912
|
+
function frameLoop() {
|
|
1913
|
+
const nextRefRect = getBoundingClientRect(reference);
|
|
1914
|
+
if (prevRefRect && (nextRefRect.x !== prevRefRect.x || nextRefRect.y !== prevRefRect.y || nextRefRect.width !== prevRefRect.width || nextRefRect.height !== prevRefRect.height)) {
|
|
1915
|
+
update();
|
|
1916
|
+
}
|
|
1917
|
+
prevRefRect = nextRefRect;
|
|
1918
|
+
frameId = requestAnimationFrame(frameLoop);
|
|
1919
|
+
}
|
|
1920
|
+
update();
|
|
1921
|
+
return () => {
|
|
1922
|
+
var _resizeObserver2;
|
|
1923
|
+
ancestors.forEach(ancestor => {
|
|
1924
|
+
ancestorScroll && ancestor.removeEventListener('scroll', update);
|
|
1925
|
+
ancestorResize && ancestor.removeEventListener('resize', update);
|
|
1926
|
+
});
|
|
1927
|
+
cleanupIo == null || cleanupIo();
|
|
1928
|
+
(_resizeObserver2 = resizeObserver) == null || _resizeObserver2.disconnect();
|
|
1929
|
+
resizeObserver = null;
|
|
1930
|
+
if (animationFrame) {
|
|
1931
|
+
cancelAnimationFrame(frameId);
|
|
1932
|
+
}
|
|
1933
|
+
};
|
|
1934
|
+
}
|
|
1935
|
+
|
|
1936
|
+
/**
|
|
1937
|
+
* Computes the `x` and `y` coordinates that will place the floating element
|
|
1938
|
+
* next to a given reference element.
|
|
1939
|
+
*/
|
|
1940
|
+
const computePosition = (reference, floating, options) => {
|
|
1941
|
+
// This caches the expensive `getClippingElementAncestors` function so that
|
|
1942
|
+
// multiple lifecycle resets re-use the same result. It only lives for a
|
|
1943
|
+
// single call. If other functions become expensive, we can add them as well.
|
|
1944
|
+
const cache = new Map();
|
|
1945
|
+
const mergedOptions = {
|
|
1946
|
+
platform,
|
|
1947
|
+
...options
|
|
1948
|
+
};
|
|
1949
|
+
const platformWithCache = {
|
|
1950
|
+
...mergedOptions.platform,
|
|
1951
|
+
_c: cache
|
|
1952
|
+
};
|
|
1953
|
+
return computePosition$1(reference, floating, {
|
|
1954
|
+
...mergedOptions,
|
|
1955
|
+
platform: platformWithCache
|
|
1956
|
+
});
|
|
1957
|
+
};
|
|
1958
|
+
|
|
1959
|
+
var index$1 = typeof document !== 'undefined' ? useLayoutEffect : useEffect;
|
|
1960
|
+
|
|
1961
|
+
// Fork of `fast-deep-equal` that only does the comparisons we need and compares
|
|
1962
|
+
// functions
|
|
1963
|
+
function deepEqual(a, b) {
|
|
1964
|
+
if (a === b) {
|
|
1965
|
+
return true;
|
|
1966
|
+
}
|
|
1967
|
+
if (typeof a !== typeof b) {
|
|
1968
|
+
return false;
|
|
1969
|
+
}
|
|
1970
|
+
if (typeof a === 'function' && a.toString() === b.toString()) {
|
|
1971
|
+
return true;
|
|
1972
|
+
}
|
|
1973
|
+
let length;
|
|
1974
|
+
let i;
|
|
1975
|
+
let keys;
|
|
1976
|
+
if (a && b && typeof a === 'object') {
|
|
1977
|
+
if (Array.isArray(a)) {
|
|
1978
|
+
length = a.length;
|
|
1979
|
+
if (length !== b.length) return false;
|
|
1980
|
+
for (i = length; i-- !== 0;) {
|
|
1981
|
+
if (!deepEqual(a[i], b[i])) {
|
|
1982
|
+
return false;
|
|
1983
|
+
}
|
|
1984
|
+
}
|
|
1985
|
+
return true;
|
|
1986
|
+
}
|
|
1987
|
+
keys = Object.keys(a);
|
|
1988
|
+
length = keys.length;
|
|
1989
|
+
if (length !== Object.keys(b).length) {
|
|
1990
|
+
return false;
|
|
1991
|
+
}
|
|
1992
|
+
for (i = length; i-- !== 0;) {
|
|
1993
|
+
if (!{}.hasOwnProperty.call(b, keys[i])) {
|
|
1994
|
+
return false;
|
|
1995
|
+
}
|
|
1996
|
+
}
|
|
1997
|
+
for (i = length; i-- !== 0;) {
|
|
1998
|
+
const key = keys[i];
|
|
1999
|
+
if (key === '_owner' && a.$$typeof) {
|
|
2000
|
+
continue;
|
|
2001
|
+
}
|
|
2002
|
+
if (!deepEqual(a[key], b[key])) {
|
|
2003
|
+
return false;
|
|
2004
|
+
}
|
|
2005
|
+
}
|
|
2006
|
+
return true;
|
|
2007
|
+
}
|
|
2008
|
+
return a !== a && b !== b;
|
|
2009
|
+
}
|
|
2010
|
+
|
|
2011
|
+
function getDPR(element) {
|
|
2012
|
+
if (typeof window === 'undefined') {
|
|
2013
|
+
return 1;
|
|
2014
|
+
}
|
|
2015
|
+
const win = element.ownerDocument.defaultView || window;
|
|
2016
|
+
return win.devicePixelRatio || 1;
|
|
2017
|
+
}
|
|
2018
|
+
|
|
2019
|
+
function roundByDPR(element, value) {
|
|
2020
|
+
const dpr = getDPR(element);
|
|
2021
|
+
return Math.round(value * dpr) / dpr;
|
|
2022
|
+
}
|
|
2023
|
+
|
|
2024
|
+
function useLatestRef(value) {
|
|
2025
|
+
const ref = React.useRef(value);
|
|
2026
|
+
index$1(() => {
|
|
2027
|
+
ref.current = value;
|
|
2028
|
+
});
|
|
2029
|
+
return ref;
|
|
2030
|
+
}
|
|
2031
|
+
|
|
2032
|
+
/**
|
|
2033
|
+
* Provides data to position a floating element.
|
|
2034
|
+
* @see https://floating-ui.com/docs/useFloating
|
|
2035
|
+
*/
|
|
2036
|
+
function useFloating$1(options) {
|
|
2037
|
+
if (options === void 0) {
|
|
2038
|
+
options = {};
|
|
2039
|
+
}
|
|
2040
|
+
const {
|
|
2041
|
+
placement = 'bottom',
|
|
2042
|
+
strategy = 'absolute',
|
|
2043
|
+
middleware = [],
|
|
2044
|
+
platform,
|
|
2045
|
+
elements: {
|
|
2046
|
+
reference: externalReference,
|
|
2047
|
+
floating: externalFloating
|
|
2048
|
+
} = {},
|
|
2049
|
+
transform = true,
|
|
2050
|
+
whileElementsMounted,
|
|
2051
|
+
open
|
|
2052
|
+
} = options;
|
|
2053
|
+
const [data, setData] = React.useState({
|
|
2054
|
+
x: 0,
|
|
2055
|
+
y: 0,
|
|
2056
|
+
strategy,
|
|
2057
|
+
placement,
|
|
2058
|
+
middlewareData: {},
|
|
2059
|
+
isPositioned: false
|
|
2060
|
+
});
|
|
2061
|
+
const [latestMiddleware, setLatestMiddleware] = React.useState(middleware);
|
|
2062
|
+
if (!deepEqual(latestMiddleware, middleware)) {
|
|
2063
|
+
setLatestMiddleware(middleware);
|
|
2064
|
+
}
|
|
2065
|
+
const [_reference, _setReference] = React.useState(null);
|
|
2066
|
+
const [_floating, _setFloating] = React.useState(null);
|
|
2067
|
+
const setReference = React.useCallback(node => {
|
|
2068
|
+
if (node !== referenceRef.current) {
|
|
2069
|
+
referenceRef.current = node;
|
|
2070
|
+
_setReference(node);
|
|
2071
|
+
}
|
|
2072
|
+
}, []);
|
|
2073
|
+
const setFloating = React.useCallback(node => {
|
|
2074
|
+
if (node !== floatingRef.current) {
|
|
2075
|
+
floatingRef.current = node;
|
|
2076
|
+
_setFloating(node);
|
|
2077
|
+
}
|
|
2078
|
+
}, []);
|
|
2079
|
+
const referenceEl = externalReference || _reference;
|
|
2080
|
+
const floatingEl = externalFloating || _floating;
|
|
2081
|
+
const referenceRef = React.useRef(null);
|
|
2082
|
+
const floatingRef = React.useRef(null);
|
|
2083
|
+
const dataRef = React.useRef(data);
|
|
2084
|
+
const hasWhileElementsMounted = whileElementsMounted != null;
|
|
2085
|
+
const whileElementsMountedRef = useLatestRef(whileElementsMounted);
|
|
2086
|
+
const platformRef = useLatestRef(platform);
|
|
2087
|
+
const update = React.useCallback(() => {
|
|
2088
|
+
if (!referenceRef.current || !floatingRef.current) {
|
|
2089
|
+
return;
|
|
2090
|
+
}
|
|
2091
|
+
const config = {
|
|
2092
|
+
placement,
|
|
2093
|
+
strategy,
|
|
2094
|
+
middleware: latestMiddleware
|
|
2095
|
+
};
|
|
2096
|
+
if (platformRef.current) {
|
|
2097
|
+
config.platform = platformRef.current;
|
|
2098
|
+
}
|
|
2099
|
+
computePosition(referenceRef.current, floatingRef.current, config).then(data => {
|
|
2100
|
+
const fullData = {
|
|
2101
|
+
...data,
|
|
2102
|
+
isPositioned: true
|
|
2103
|
+
};
|
|
2104
|
+
if (isMountedRef.current && !deepEqual(dataRef.current, fullData)) {
|
|
2105
|
+
dataRef.current = fullData;
|
|
2106
|
+
ReactDOM.flushSync(() => {
|
|
2107
|
+
setData(fullData);
|
|
2108
|
+
});
|
|
2109
|
+
}
|
|
2110
|
+
});
|
|
2111
|
+
}, [latestMiddleware, placement, strategy, platformRef]);
|
|
2112
|
+
index$1(() => {
|
|
2113
|
+
if (open === false && dataRef.current.isPositioned) {
|
|
2114
|
+
dataRef.current.isPositioned = false;
|
|
2115
|
+
setData(data => ({
|
|
2116
|
+
...data,
|
|
2117
|
+
isPositioned: false
|
|
2118
|
+
}));
|
|
2119
|
+
}
|
|
2120
|
+
}, [open]);
|
|
2121
|
+
const isMountedRef = React.useRef(false);
|
|
2122
|
+
index$1(() => {
|
|
2123
|
+
isMountedRef.current = true;
|
|
2124
|
+
return () => {
|
|
2125
|
+
isMountedRef.current = false;
|
|
2126
|
+
};
|
|
2127
|
+
}, []);
|
|
2128
|
+
index$1(() => {
|
|
2129
|
+
if (referenceEl) referenceRef.current = referenceEl;
|
|
2130
|
+
if (floatingEl) floatingRef.current = floatingEl;
|
|
2131
|
+
if (referenceEl && floatingEl) {
|
|
2132
|
+
if (whileElementsMountedRef.current) {
|
|
2133
|
+
return whileElementsMountedRef.current(referenceEl, floatingEl, update);
|
|
2134
|
+
}
|
|
2135
|
+
update();
|
|
2136
|
+
}
|
|
2137
|
+
}, [referenceEl, floatingEl, update, whileElementsMountedRef, hasWhileElementsMounted]);
|
|
2138
|
+
const refs = React.useMemo(() => ({
|
|
2139
|
+
reference: referenceRef,
|
|
2140
|
+
floating: floatingRef,
|
|
2141
|
+
setReference,
|
|
2142
|
+
setFloating
|
|
2143
|
+
}), [setReference, setFloating]);
|
|
2144
|
+
const elements = React.useMemo(() => ({
|
|
2145
|
+
reference: referenceEl,
|
|
2146
|
+
floating: floatingEl
|
|
2147
|
+
}), [referenceEl, floatingEl]);
|
|
2148
|
+
const floatingStyles = React.useMemo(() => {
|
|
2149
|
+
const initialStyles = {
|
|
2150
|
+
position: strategy,
|
|
2151
|
+
left: 0,
|
|
2152
|
+
top: 0
|
|
2153
|
+
};
|
|
2154
|
+
if (!elements.floating) {
|
|
2155
|
+
return initialStyles;
|
|
2156
|
+
}
|
|
2157
|
+
const x = roundByDPR(elements.floating, data.x);
|
|
2158
|
+
const y = roundByDPR(elements.floating, data.y);
|
|
2159
|
+
if (transform) {
|
|
2160
|
+
return {
|
|
2161
|
+
...initialStyles,
|
|
2162
|
+
transform: "translate(" + x + "px, " + y + "px)",
|
|
2163
|
+
...(getDPR(elements.floating) >= 1.5 && {
|
|
2164
|
+
willChange: 'transform'
|
|
2165
|
+
})
|
|
2166
|
+
};
|
|
2167
|
+
}
|
|
2168
|
+
return {
|
|
2169
|
+
position: strategy,
|
|
2170
|
+
left: x,
|
|
2171
|
+
top: y
|
|
2172
|
+
};
|
|
2173
|
+
}, [strategy, transform, elements.floating, data.x, data.y]);
|
|
2174
|
+
return React.useMemo(() => ({
|
|
2175
|
+
...data,
|
|
2176
|
+
update,
|
|
2177
|
+
refs,
|
|
2178
|
+
elements,
|
|
2179
|
+
floatingStyles
|
|
2180
|
+
}), [data, update, refs, elements, floatingStyles]);
|
|
2181
|
+
}
|
|
2182
|
+
|
|
2183
|
+
// https://github.com/mui/material-ui/issues/41190#issuecomment-2040873379
|
|
2184
|
+
const SafeReact = {
|
|
2185
|
+
...React
|
|
2186
|
+
};
|
|
2187
|
+
|
|
2188
|
+
const useInsertionEffect = SafeReact.useInsertionEffect;
|
|
2189
|
+
const useSafeInsertionEffect = useInsertionEffect || (fn => fn());
|
|
2190
|
+
function useEffectEvent(callback) {
|
|
2191
|
+
const ref = React.useRef(() => {
|
|
2192
|
+
if (process.env.NODE_ENV !== "production") {
|
|
2193
|
+
throw new Error('Cannot call an event handler while rendering.');
|
|
2194
|
+
}
|
|
2195
|
+
});
|
|
2196
|
+
useSafeInsertionEffect(() => {
|
|
2197
|
+
ref.current = callback;
|
|
2198
|
+
});
|
|
2199
|
+
return React.useCallback(function () {
|
|
2200
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
2201
|
+
args[_key] = arguments[_key];
|
|
2202
|
+
}
|
|
2203
|
+
return ref.current == null ? void 0 : ref.current(...args);
|
|
2204
|
+
}, []);
|
|
2205
|
+
}
|
|
2206
|
+
|
|
2207
|
+
var index = typeof document !== 'undefined' ? useLayoutEffect : useEffect;
|
|
2208
|
+
|
|
2209
|
+
function _extends() {
|
|
2210
|
+
_extends = Object.assign ? Object.assign.bind() : function (target) {
|
|
2211
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
2212
|
+
var source = arguments[i];
|
|
2213
|
+
for (var key in source) {
|
|
2214
|
+
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
2215
|
+
target[key] = source[key];
|
|
2216
|
+
}
|
|
2217
|
+
}
|
|
2218
|
+
}
|
|
2219
|
+
return target;
|
|
2220
|
+
};
|
|
2221
|
+
return _extends.apply(this, arguments);
|
|
2222
|
+
}
|
|
2223
|
+
|
|
2224
|
+
let serverHandoffComplete = false;
|
|
2225
|
+
let count = 0;
|
|
2226
|
+
const genId = () => // Ensure the id is unique with multiple independent versions of Floating UI
|
|
2227
|
+
// on <React 18
|
|
2228
|
+
"floating-ui-" + Math.random().toString(36).slice(2, 6) + count++;
|
|
2229
|
+
function useFloatingId() {
|
|
2230
|
+
const [id, setId] = React.useState(() => serverHandoffComplete ? genId() : undefined);
|
|
2231
|
+
index(() => {
|
|
2232
|
+
if (id == null) {
|
|
2233
|
+
setId(genId());
|
|
2234
|
+
}
|
|
2235
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
2236
|
+
}, []);
|
|
2237
|
+
React.useEffect(() => {
|
|
2238
|
+
serverHandoffComplete = true;
|
|
2239
|
+
}, []);
|
|
2240
|
+
return id;
|
|
2241
|
+
}
|
|
2242
|
+
const useReactId = SafeReact.useId;
|
|
2243
|
+
|
|
2244
|
+
/**
|
|
2245
|
+
* Uses React 18's built-in `useId()` when available, or falls back to a
|
|
2246
|
+
* slightly less performant (requiring a double render) implementation for
|
|
2247
|
+
* earlier React versions.
|
|
2248
|
+
* @see https://floating-ui.com/docs/react-utils#useid
|
|
2249
|
+
*/
|
|
2250
|
+
const useId = useReactId || useFloatingId;
|
|
2251
|
+
|
|
2252
|
+
let devMessageSet;
|
|
2253
|
+
if (process.env.NODE_ENV !== "production") {
|
|
2254
|
+
devMessageSet = /*#__PURE__*/new Set();
|
|
2255
|
+
}
|
|
2256
|
+
function error() {
|
|
2257
|
+
var _devMessageSet3;
|
|
2258
|
+
for (var _len2 = arguments.length, messages = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
2259
|
+
messages[_key2] = arguments[_key2];
|
|
2260
|
+
}
|
|
2261
|
+
const message = "Floating UI: " + messages.join(' ');
|
|
2262
|
+
if (!((_devMessageSet3 = devMessageSet) != null && _devMessageSet3.has(message))) {
|
|
2263
|
+
var _devMessageSet4;
|
|
2264
|
+
(_devMessageSet4 = devMessageSet) == null || _devMessageSet4.add(message);
|
|
2265
|
+
console.error(message);
|
|
2266
|
+
}
|
|
2267
|
+
}
|
|
2268
|
+
|
|
2269
|
+
function createPubSub() {
|
|
2270
|
+
const map = new Map();
|
|
2271
|
+
return {
|
|
2272
|
+
emit(event, data) {
|
|
2273
|
+
var _map$get;
|
|
2274
|
+
(_map$get = map.get(event)) == null || _map$get.forEach(handler => handler(data));
|
|
2275
|
+
},
|
|
2276
|
+
on(event, listener) {
|
|
2277
|
+
map.set(event, [...(map.get(event) || []), listener]);
|
|
2278
|
+
},
|
|
2279
|
+
off(event, listener) {
|
|
2280
|
+
var _map$get2;
|
|
2281
|
+
map.set(event, ((_map$get2 = map.get(event)) == null ? void 0 : _map$get2.filter(l => l !== listener)) || []);
|
|
2282
|
+
}
|
|
2283
|
+
};
|
|
2284
|
+
}
|
|
2285
|
+
|
|
2286
|
+
const FloatingNodeContext = /*#__PURE__*/React.createContext(null);
|
|
2287
|
+
const FloatingTreeContext = /*#__PURE__*/React.createContext(null);
|
|
2288
|
+
|
|
2289
|
+
/**
|
|
2290
|
+
* Returns the parent node id for nested floating elements, if available.
|
|
2291
|
+
* Returns `null` for top-level floating elements.
|
|
2292
|
+
*/
|
|
2293
|
+
const useFloatingParentNodeId = () => {
|
|
2294
|
+
var _React$useContext;
|
|
2295
|
+
return ((_React$useContext = React.useContext(FloatingNodeContext)) == null ? void 0 : _React$useContext.id) || null;
|
|
2296
|
+
};
|
|
2297
|
+
|
|
2298
|
+
/**
|
|
2299
|
+
* Returns the nearest floating tree context, if available.
|
|
2300
|
+
*/
|
|
2301
|
+
const useFloatingTree = () => React.useContext(FloatingTreeContext);
|
|
2302
|
+
|
|
2303
|
+
function createAttribute(name) {
|
|
2304
|
+
return "data-floating-ui-" + name;
|
|
2305
|
+
}
|
|
2306
|
+
|
|
2307
|
+
const getTabbableOptions = () => ({
|
|
2308
|
+
getShadowRoot: true,
|
|
2309
|
+
displayCheck:
|
|
2310
|
+
// JSDOM does not support the `tabbable` library. To solve this we can
|
|
2311
|
+
// check if `ResizeObserver` is a real function (not polyfilled), which
|
|
2312
|
+
// determines if the current environment is JSDOM-like.
|
|
2313
|
+
typeof ResizeObserver === 'function' && ResizeObserver.toString().includes('[native code]') ? 'full' : 'none'
|
|
2314
|
+
});
|
|
2315
|
+
function getTabbableIn(container, direction) {
|
|
2316
|
+
const allTabbable = tabbable(container, getTabbableOptions());
|
|
2317
|
+
if (direction === 'prev') {
|
|
2318
|
+
allTabbable.reverse();
|
|
2319
|
+
}
|
|
2320
|
+
const activeIndex = allTabbable.indexOf(activeElement(getDocument(container)));
|
|
2321
|
+
const nextTabbableElements = allTabbable.slice(activeIndex + 1);
|
|
2322
|
+
return nextTabbableElements[0];
|
|
2323
|
+
}
|
|
2324
|
+
function getNextTabbable() {
|
|
2325
|
+
return getTabbableIn(document.body, 'next');
|
|
2326
|
+
}
|
|
2327
|
+
function getPreviousTabbable() {
|
|
2328
|
+
return getTabbableIn(document.body, 'prev');
|
|
2329
|
+
}
|
|
2330
|
+
function isOutsideEvent(event, container) {
|
|
2331
|
+
const containerElement = container || event.currentTarget;
|
|
2332
|
+
const relatedTarget = event.relatedTarget;
|
|
2333
|
+
return !relatedTarget || !contains(containerElement, relatedTarget);
|
|
2334
|
+
}
|
|
2335
|
+
function disableFocusInside(container) {
|
|
2336
|
+
const tabbableElements = tabbable(container, getTabbableOptions());
|
|
2337
|
+
tabbableElements.forEach(element => {
|
|
2338
|
+
element.dataset.tabindex = element.getAttribute('tabindex') || '';
|
|
2339
|
+
element.setAttribute('tabindex', '-1');
|
|
2340
|
+
});
|
|
2341
|
+
}
|
|
2342
|
+
function enableFocusInside(container) {
|
|
2343
|
+
const elements = container.querySelectorAll('[data-tabindex]');
|
|
2344
|
+
elements.forEach(element => {
|
|
2345
|
+
const tabindex = element.dataset.tabindex;
|
|
2346
|
+
delete element.dataset.tabindex;
|
|
2347
|
+
if (tabindex) {
|
|
2348
|
+
element.setAttribute('tabindex', tabindex);
|
|
2349
|
+
} else {
|
|
2350
|
+
element.removeAttribute('tabindex');
|
|
2351
|
+
}
|
|
2352
|
+
});
|
|
2353
|
+
}
|
|
2354
|
+
|
|
2355
|
+
// See Diego Haz's Sandbox for making this logic work well on Safari/iOS:
|
|
2356
|
+
// https://codesandbox.io/s/tabbable-portal-f4tng?file=/src/FocusTrap.tsx
|
|
2357
|
+
|
|
2358
|
+
const HIDDEN_STYLES = {
|
|
2359
|
+
border: 0,
|
|
2360
|
+
clip: 'rect(0 0 0 0)',
|
|
2361
|
+
height: '1px',
|
|
2362
|
+
margin: '-1px',
|
|
2363
|
+
overflow: 'hidden',
|
|
2364
|
+
padding: 0,
|
|
2365
|
+
position: 'fixed',
|
|
2366
|
+
whiteSpace: 'nowrap',
|
|
2367
|
+
width: '1px',
|
|
2368
|
+
top: 0,
|
|
2369
|
+
left: 0
|
|
2370
|
+
};
|
|
2371
|
+
let timeoutId;
|
|
2372
|
+
function setActiveElementOnTab(event) {
|
|
2373
|
+
if (event.key === 'Tab') {
|
|
2374
|
+
event.target;
|
|
2375
|
+
clearTimeout(timeoutId);
|
|
2376
|
+
}
|
|
2377
|
+
}
|
|
2378
|
+
const FocusGuard = /*#__PURE__*/React.forwardRef(function FocusGuard(props, ref) {
|
|
2379
|
+
const [role, setRole] = React.useState();
|
|
2380
|
+
index(() => {
|
|
2381
|
+
if (isSafari()) {
|
|
2382
|
+
// Unlike other screen readers such as NVDA and JAWS, the virtual cursor
|
|
2383
|
+
// on VoiceOver does trigger the onFocus event, so we can use the focus
|
|
2384
|
+
// trap element. On Safari, only buttons trigger the onFocus event.
|
|
2385
|
+
// NB: "group" role in the Sandbox no longer appears to work, must be a
|
|
2386
|
+
// button role.
|
|
2387
|
+
setRole('button');
|
|
2388
|
+
}
|
|
2389
|
+
document.addEventListener('keydown', setActiveElementOnTab);
|
|
2390
|
+
return () => {
|
|
2391
|
+
document.removeEventListener('keydown', setActiveElementOnTab);
|
|
2392
|
+
};
|
|
2393
|
+
}, []);
|
|
2394
|
+
const restProps = {
|
|
2395
|
+
ref,
|
|
2396
|
+
tabIndex: 0,
|
|
2397
|
+
// Role is only for VoiceOver
|
|
2398
|
+
role,
|
|
2399
|
+
'aria-hidden': role ? undefined : true,
|
|
2400
|
+
[createAttribute('focus-guard')]: '',
|
|
2401
|
+
style: HIDDEN_STYLES
|
|
2402
|
+
};
|
|
2403
|
+
return /*#__PURE__*/React.createElement("span", _extends({}, props, restProps));
|
|
2404
|
+
});
|
|
2405
|
+
|
|
2406
|
+
const PortalContext = /*#__PURE__*/React.createContext(null);
|
|
2407
|
+
const attr = /*#__PURE__*/createAttribute('portal');
|
|
2408
|
+
/**
|
|
2409
|
+
* @see https://floating-ui.com/docs/FloatingPortal#usefloatingportalnode
|
|
2410
|
+
*/
|
|
2411
|
+
function useFloatingPortalNode(props) {
|
|
2412
|
+
if (props === void 0) {
|
|
2413
|
+
props = {};
|
|
2414
|
+
}
|
|
2415
|
+
const {
|
|
2416
|
+
id,
|
|
2417
|
+
root
|
|
2418
|
+
} = props;
|
|
2419
|
+
const uniqueId = useId();
|
|
2420
|
+
const portalContext = usePortalContext();
|
|
2421
|
+
const [portalNode, setPortalNode] = React.useState(null);
|
|
2422
|
+
const portalNodeRef = React.useRef(null);
|
|
2423
|
+
index(() => {
|
|
2424
|
+
return () => {
|
|
2425
|
+
portalNode == null || portalNode.remove();
|
|
2426
|
+
// Allow the subsequent layout effects to create a new node on updates.
|
|
2427
|
+
// The portal node will still be cleaned up on unmount.
|
|
2428
|
+
// https://github.com/floating-ui/floating-ui/issues/2454
|
|
2429
|
+
queueMicrotask(() => {
|
|
2430
|
+
portalNodeRef.current = null;
|
|
2431
|
+
});
|
|
2432
|
+
};
|
|
2433
|
+
}, [portalNode]);
|
|
2434
|
+
index(() => {
|
|
2435
|
+
// Wait for the uniqueId to be generated before creating the portal node in
|
|
2436
|
+
// React <18 (using `useFloatingId` instead of the native `useId`).
|
|
2437
|
+
// https://github.com/floating-ui/floating-ui/issues/2778
|
|
2438
|
+
if (!uniqueId) return;
|
|
2439
|
+
if (portalNodeRef.current) return;
|
|
2440
|
+
const existingIdRoot = id ? document.getElementById(id) : null;
|
|
2441
|
+
if (!existingIdRoot) return;
|
|
2442
|
+
const subRoot = document.createElement('div');
|
|
2443
|
+
subRoot.id = uniqueId;
|
|
2444
|
+
subRoot.setAttribute(attr, '');
|
|
2445
|
+
existingIdRoot.appendChild(subRoot);
|
|
2446
|
+
portalNodeRef.current = subRoot;
|
|
2447
|
+
setPortalNode(subRoot);
|
|
2448
|
+
}, [id, uniqueId]);
|
|
2449
|
+
index(() => {
|
|
2450
|
+
if (!uniqueId) return;
|
|
2451
|
+
if (portalNodeRef.current) return;
|
|
2452
|
+
let container = root || (portalContext == null ? void 0 : portalContext.portalNode);
|
|
2453
|
+
if (container && !isElement(container)) container = container.current;
|
|
2454
|
+
container = container || document.body;
|
|
2455
|
+
let idWrapper = null;
|
|
2456
|
+
if (id) {
|
|
2457
|
+
idWrapper = document.createElement('div');
|
|
2458
|
+
idWrapper.id = id;
|
|
2459
|
+
container.appendChild(idWrapper);
|
|
2460
|
+
}
|
|
2461
|
+
const subRoot = document.createElement('div');
|
|
2462
|
+
subRoot.id = uniqueId;
|
|
2463
|
+
subRoot.setAttribute(attr, '');
|
|
2464
|
+
container = idWrapper || container;
|
|
2465
|
+
container.appendChild(subRoot);
|
|
2466
|
+
portalNodeRef.current = subRoot;
|
|
2467
|
+
setPortalNode(subRoot);
|
|
2468
|
+
}, [id, root, uniqueId, portalContext]);
|
|
2469
|
+
return portalNode;
|
|
2470
|
+
}
|
|
2471
|
+
/**
|
|
2472
|
+
* Portals the floating element into a given container element — by default,
|
|
2473
|
+
* outside of the app root and into the body.
|
|
2474
|
+
* This is necessary to ensure the floating element can appear outside any
|
|
2475
|
+
* potential parent containers that cause clipping (such as `overflow: hidden`),
|
|
2476
|
+
* while retaining its location in the React tree.
|
|
2477
|
+
* @see https://floating-ui.com/docs/FloatingPortal
|
|
2478
|
+
*/
|
|
2479
|
+
function FloatingPortal(props) {
|
|
2480
|
+
const {
|
|
2481
|
+
children,
|
|
2482
|
+
id,
|
|
2483
|
+
root = null,
|
|
2484
|
+
preserveTabOrder = true
|
|
2485
|
+
} = props;
|
|
2486
|
+
const portalNode = useFloatingPortalNode({
|
|
2487
|
+
id,
|
|
2488
|
+
root
|
|
2489
|
+
});
|
|
2490
|
+
const [focusManagerState, setFocusManagerState] = React.useState(null);
|
|
2491
|
+
const beforeOutsideRef = React.useRef(null);
|
|
2492
|
+
const afterOutsideRef = React.useRef(null);
|
|
2493
|
+
const beforeInsideRef = React.useRef(null);
|
|
2494
|
+
const afterInsideRef = React.useRef(null);
|
|
2495
|
+
const modal = focusManagerState == null ? void 0 : focusManagerState.modal;
|
|
2496
|
+
const open = focusManagerState == null ? void 0 : focusManagerState.open;
|
|
2497
|
+
const shouldRenderGuards =
|
|
2498
|
+
// The FocusManager and therefore floating element are currently open/
|
|
2499
|
+
// rendered.
|
|
2500
|
+
!!focusManagerState &&
|
|
2501
|
+
// Guards are only for non-modal focus management.
|
|
2502
|
+
!focusManagerState.modal &&
|
|
2503
|
+
// Don't render if unmount is transitioning.
|
|
2504
|
+
focusManagerState.open && preserveTabOrder && !!(root || portalNode);
|
|
2505
|
+
|
|
2506
|
+
// https://codesandbox.io/s/tabbable-portal-f4tng?file=/src/TabbablePortal.tsx
|
|
2507
|
+
React.useEffect(() => {
|
|
2508
|
+
if (!portalNode || !preserveTabOrder || modal) {
|
|
2509
|
+
return;
|
|
2510
|
+
}
|
|
2511
|
+
|
|
2512
|
+
// Make sure elements inside the portal element are tabbable only when the
|
|
2513
|
+
// portal has already been focused, either by tabbing into a focus trap
|
|
2514
|
+
// element outside or using the mouse.
|
|
2515
|
+
function onFocus(event) {
|
|
2516
|
+
if (portalNode && isOutsideEvent(event)) {
|
|
2517
|
+
const focusing = event.type === 'focusin';
|
|
2518
|
+
const manageFocus = focusing ? enableFocusInside : disableFocusInside;
|
|
2519
|
+
manageFocus(portalNode);
|
|
2520
|
+
}
|
|
2521
|
+
}
|
|
2522
|
+
// Listen to the event on the capture phase so they run before the focus
|
|
2523
|
+
// trap elements onFocus prop is called.
|
|
2524
|
+
portalNode.addEventListener('focusin', onFocus, true);
|
|
2525
|
+
portalNode.addEventListener('focusout', onFocus, true);
|
|
2526
|
+
return () => {
|
|
2527
|
+
portalNode.removeEventListener('focusin', onFocus, true);
|
|
2528
|
+
portalNode.removeEventListener('focusout', onFocus, true);
|
|
2529
|
+
};
|
|
2530
|
+
}, [portalNode, preserveTabOrder, modal]);
|
|
2531
|
+
React.useEffect(() => {
|
|
2532
|
+
if (!portalNode) return;
|
|
2533
|
+
if (open) return;
|
|
2534
|
+
enableFocusInside(portalNode);
|
|
2535
|
+
}, [open, portalNode]);
|
|
2536
|
+
return /*#__PURE__*/React.createElement(PortalContext.Provider, {
|
|
2537
|
+
value: React.useMemo(() => ({
|
|
2538
|
+
preserveTabOrder,
|
|
2539
|
+
beforeOutsideRef,
|
|
2540
|
+
afterOutsideRef,
|
|
2541
|
+
beforeInsideRef,
|
|
2542
|
+
afterInsideRef,
|
|
2543
|
+
portalNode,
|
|
2544
|
+
setFocusManagerState
|
|
2545
|
+
}), [preserveTabOrder, portalNode])
|
|
2546
|
+
}, shouldRenderGuards && portalNode && /*#__PURE__*/React.createElement(FocusGuard, {
|
|
2547
|
+
"data-type": "outside",
|
|
2548
|
+
ref: beforeOutsideRef,
|
|
2549
|
+
onFocus: event => {
|
|
2550
|
+
if (isOutsideEvent(event, portalNode)) {
|
|
2551
|
+
var _beforeInsideRef$curr;
|
|
2552
|
+
(_beforeInsideRef$curr = beforeInsideRef.current) == null || _beforeInsideRef$curr.focus();
|
|
2553
|
+
} else {
|
|
2554
|
+
const prevTabbable = getPreviousTabbable() || (focusManagerState == null ? void 0 : focusManagerState.refs.domReference.current);
|
|
2555
|
+
prevTabbable == null || prevTabbable.focus();
|
|
2556
|
+
}
|
|
2557
|
+
}
|
|
2558
|
+
}), shouldRenderGuards && portalNode && /*#__PURE__*/React.createElement("span", {
|
|
2559
|
+
"aria-owns": portalNode.id,
|
|
2560
|
+
style: HIDDEN_STYLES
|
|
2561
|
+
}), portalNode && /*#__PURE__*/ReactDOM.createPortal(children, portalNode), shouldRenderGuards && portalNode && /*#__PURE__*/React.createElement(FocusGuard, {
|
|
2562
|
+
"data-type": "outside",
|
|
2563
|
+
ref: afterOutsideRef,
|
|
2564
|
+
onFocus: event => {
|
|
2565
|
+
if (isOutsideEvent(event, portalNode)) {
|
|
2566
|
+
var _afterInsideRef$curre;
|
|
2567
|
+
(_afterInsideRef$curre = afterInsideRef.current) == null || _afterInsideRef$curre.focus();
|
|
2568
|
+
} else {
|
|
2569
|
+
const nextTabbable = getNextTabbable() || (focusManagerState == null ? void 0 : focusManagerState.refs.domReference.current);
|
|
2570
|
+
nextTabbable == null || nextTabbable.focus();
|
|
2571
|
+
(focusManagerState == null ? void 0 : focusManagerState.closeOnFocusOut) && (focusManagerState == null ? void 0 : focusManagerState.onOpenChange(false, event.nativeEvent, 'focus-out'));
|
|
2572
|
+
}
|
|
2573
|
+
}
|
|
2574
|
+
}));
|
|
2575
|
+
}
|
|
2576
|
+
const usePortalContext = () => React.useContext(PortalContext);
|
|
2577
|
+
|
|
2578
|
+
function useFloatingRootContext(options) {
|
|
2579
|
+
const {
|
|
2580
|
+
open = false,
|
|
2581
|
+
onOpenChange: onOpenChangeProp,
|
|
2582
|
+
elements: elementsProp
|
|
2583
|
+
} = options;
|
|
2584
|
+
const floatingId = useId();
|
|
2585
|
+
const dataRef = React.useRef({});
|
|
2586
|
+
const [events] = React.useState(() => createPubSub());
|
|
2587
|
+
const nested = useFloatingParentNodeId() != null;
|
|
2588
|
+
if (process.env.NODE_ENV !== "production") {
|
|
2589
|
+
const optionDomReference = elementsProp.reference;
|
|
2590
|
+
if (optionDomReference && !isElement(optionDomReference)) {
|
|
2591
|
+
error('Cannot pass a virtual element to the `elements.reference` option,', 'as it must be a real DOM element. Use `refs.setPositionReference()`', 'instead.');
|
|
2592
|
+
}
|
|
2593
|
+
}
|
|
2594
|
+
const [positionReference, setPositionReference] = React.useState(elementsProp.reference);
|
|
2595
|
+
const onOpenChange = useEffectEvent((open, event, reason) => {
|
|
2596
|
+
dataRef.current.openEvent = open ? event : undefined;
|
|
2597
|
+
events.emit('openchange', {
|
|
2598
|
+
open,
|
|
2599
|
+
event,
|
|
2600
|
+
reason,
|
|
2601
|
+
nested
|
|
2602
|
+
});
|
|
2603
|
+
onOpenChangeProp == null || onOpenChangeProp(open, event, reason);
|
|
2604
|
+
});
|
|
2605
|
+
const refs = React.useMemo(() => ({
|
|
2606
|
+
setPositionReference
|
|
2607
|
+
}), []);
|
|
2608
|
+
const elements = React.useMemo(() => ({
|
|
2609
|
+
reference: positionReference || elementsProp.reference || null,
|
|
2610
|
+
floating: elementsProp.floating || null,
|
|
2611
|
+
domReference: elementsProp.reference
|
|
2612
|
+
}), [positionReference, elementsProp.reference, elementsProp.floating]);
|
|
2613
|
+
return React.useMemo(() => ({
|
|
2614
|
+
dataRef,
|
|
2615
|
+
open,
|
|
2616
|
+
onOpenChange,
|
|
2617
|
+
elements,
|
|
2618
|
+
events,
|
|
2619
|
+
floatingId,
|
|
2620
|
+
refs
|
|
2621
|
+
}), [open, onOpenChange, elements, events, floatingId, refs]);
|
|
2622
|
+
}
|
|
2623
|
+
|
|
2624
|
+
/**
|
|
2625
|
+
* Provides data to position a floating element and context to add interactions.
|
|
2626
|
+
* @see https://floating-ui.com/docs/useFloating
|
|
2627
|
+
*/
|
|
2628
|
+
function useFloating(options) {
|
|
2629
|
+
if (options === void 0) {
|
|
2630
|
+
options = {};
|
|
2631
|
+
}
|
|
2632
|
+
const {
|
|
2633
|
+
nodeId
|
|
2634
|
+
} = options;
|
|
2635
|
+
const internalRootContext = useFloatingRootContext({
|
|
2636
|
+
...options,
|
|
2637
|
+
elements: {
|
|
2638
|
+
reference: null,
|
|
2639
|
+
floating: null,
|
|
2640
|
+
...options.elements
|
|
2641
|
+
}
|
|
2642
|
+
});
|
|
2643
|
+
const rootContext = options.rootContext || internalRootContext;
|
|
2644
|
+
const computedElements = rootContext.elements;
|
|
2645
|
+
const [_domReference, setDomReference] = React.useState(null);
|
|
2646
|
+
const [positionReference, _setPositionReference] = React.useState(null);
|
|
2647
|
+
const optionDomReference = computedElements == null ? void 0 : computedElements.reference;
|
|
2648
|
+
const domReference = optionDomReference || _domReference;
|
|
2649
|
+
const domReferenceRef = React.useRef(null);
|
|
2650
|
+
const tree = useFloatingTree();
|
|
2651
|
+
index(() => {
|
|
2652
|
+
if (domReference) {
|
|
2653
|
+
domReferenceRef.current = domReference;
|
|
2654
|
+
}
|
|
2655
|
+
}, [domReference]);
|
|
2656
|
+
const position = useFloating$1({
|
|
2657
|
+
...options,
|
|
2658
|
+
elements: {
|
|
2659
|
+
...computedElements,
|
|
2660
|
+
...(positionReference && {
|
|
2661
|
+
reference: positionReference
|
|
2662
|
+
})
|
|
2663
|
+
}
|
|
2664
|
+
});
|
|
2665
|
+
const setPositionReference = React.useCallback(node => {
|
|
2666
|
+
const computedPositionReference = isElement(node) ? {
|
|
2667
|
+
getBoundingClientRect: () => node.getBoundingClientRect(),
|
|
2668
|
+
contextElement: node
|
|
2669
|
+
} : node;
|
|
2670
|
+
// Store the positionReference in state if the DOM reference is specified externally via the
|
|
2671
|
+
// `elements.reference` option. This ensures that it won't be overridden on future renders.
|
|
2672
|
+
_setPositionReference(computedPositionReference);
|
|
2673
|
+
position.refs.setReference(computedPositionReference);
|
|
2674
|
+
}, [position.refs]);
|
|
2675
|
+
const setReference = React.useCallback(node => {
|
|
2676
|
+
if (isElement(node) || node === null) {
|
|
2677
|
+
domReferenceRef.current = node;
|
|
2678
|
+
setDomReference(node);
|
|
2679
|
+
}
|
|
2680
|
+
|
|
2681
|
+
// Backwards-compatibility for passing a virtual element to `reference`
|
|
2682
|
+
// after it has set the DOM reference.
|
|
2683
|
+
if (isElement(position.refs.reference.current) || position.refs.reference.current === null ||
|
|
2684
|
+
// Don't allow setting virtual elements using the old technique back to
|
|
2685
|
+
// `null` to support `positionReference` + an unstable `reference`
|
|
2686
|
+
// callback ref.
|
|
2687
|
+
node !== null && !isElement(node)) {
|
|
2688
|
+
position.refs.setReference(node);
|
|
2689
|
+
}
|
|
2690
|
+
}, [position.refs]);
|
|
2691
|
+
const refs = React.useMemo(() => ({
|
|
2692
|
+
...position.refs,
|
|
2693
|
+
setReference,
|
|
2694
|
+
setPositionReference,
|
|
2695
|
+
domReference: domReferenceRef
|
|
2696
|
+
}), [position.refs, setReference, setPositionReference]);
|
|
2697
|
+
const elements = React.useMemo(() => ({
|
|
2698
|
+
...position.elements,
|
|
2699
|
+
domReference: domReference
|
|
2700
|
+
}), [position.elements, domReference]);
|
|
2701
|
+
const context = React.useMemo(() => ({
|
|
2702
|
+
...position,
|
|
2703
|
+
...rootContext,
|
|
2704
|
+
refs,
|
|
2705
|
+
elements,
|
|
2706
|
+
nodeId
|
|
2707
|
+
}), [position, refs, elements, nodeId, rootContext]);
|
|
2708
|
+
index(() => {
|
|
2709
|
+
rootContext.dataRef.current.floatingContext = context;
|
|
2710
|
+
const node = tree == null ? void 0 : tree.nodesRef.current.find(node => node.id === nodeId);
|
|
2711
|
+
if (node) {
|
|
2712
|
+
node.context = context;
|
|
2713
|
+
}
|
|
2714
|
+
});
|
|
2715
|
+
return React.useMemo(() => ({
|
|
2716
|
+
...position,
|
|
2717
|
+
context,
|
|
2718
|
+
refs,
|
|
2719
|
+
elements
|
|
2720
|
+
}), [position, refs, elements, context]);
|
|
2721
|
+
}
|
|
2722
|
+
|
|
2723
|
+
var reactIsExports = {};
|
|
2724
|
+
var reactIs = {
|
|
2725
|
+
get exports(){ return reactIsExports; },
|
|
2726
|
+
set exports(v){ reactIsExports = v; },
|
|
2727
|
+
};
|
|
2728
|
+
|
|
2729
|
+
var reactIs_production_min = {};
|
|
2730
|
+
|
|
2731
|
+
/** @license React v17.0.2
|
|
2732
|
+
* react-is.production.min.js
|
|
2733
|
+
*
|
|
2734
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
2735
|
+
*
|
|
2736
|
+
* This source code is licensed under the MIT license found in the
|
|
2737
|
+
* LICENSE file in the root directory of this source tree.
|
|
2738
|
+
*/
|
|
2739
|
+
|
|
2740
|
+
var hasRequiredReactIs_production_min;
|
|
2741
|
+
|
|
2742
|
+
function requireReactIs_production_min () {
|
|
2743
|
+
if (hasRequiredReactIs_production_min) return reactIs_production_min;
|
|
2744
|
+
hasRequiredReactIs_production_min = 1;
|
|
2745
|
+
var b=60103,c=60106,d=60107,e=60108,f=60114,g=60109,h=60110,k=60112,l=60113,m=60120,n=60115,p=60116,q=60121,r=60122,u=60117,v=60129,w=60131;
|
|
2746
|
+
if("function"===typeof Symbol&&Symbol.for){var x=Symbol.for;b=x("react.element");c=x("react.portal");d=x("react.fragment");e=x("react.strict_mode");f=x("react.profiler");g=x("react.provider");h=x("react.context");k=x("react.forward_ref");l=x("react.suspense");m=x("react.suspense_list");n=x("react.memo");p=x("react.lazy");q=x("react.block");r=x("react.server.block");u=x("react.fundamental");v=x("react.debug_trace_mode");w=x("react.legacy_hidden");}
|
|
2747
|
+
function y(a){if("object"===typeof a&&null!==a){var t=a.$$typeof;switch(t){case b:switch(a=a.type,a){case d:case f:case e:case l:case m:return a;default:switch(a=a&&a.$$typeof,a){case h:case k:case p:case n:case g:return a;default:return t}}case c:return t}}}var z=g,A=b,B=k,C=d,D=p,E=n,F=c,G=f,H=e,I=l;reactIs_production_min.ContextConsumer=h;reactIs_production_min.ContextProvider=z;reactIs_production_min.Element=A;reactIs_production_min.ForwardRef=B;reactIs_production_min.Fragment=C;reactIs_production_min.Lazy=D;reactIs_production_min.Memo=E;reactIs_production_min.Portal=F;reactIs_production_min.Profiler=G;reactIs_production_min.StrictMode=H;
|
|
2748
|
+
reactIs_production_min.Suspense=I;reactIs_production_min.isAsyncMode=function(){return !1};reactIs_production_min.isConcurrentMode=function(){return !1};reactIs_production_min.isContextConsumer=function(a){return y(a)===h};reactIs_production_min.isContextProvider=function(a){return y(a)===g};reactIs_production_min.isElement=function(a){return "object"===typeof a&&null!==a&&a.$$typeof===b};reactIs_production_min.isForwardRef=function(a){return y(a)===k};reactIs_production_min.isFragment=function(a){return y(a)===d};reactIs_production_min.isLazy=function(a){return y(a)===p};reactIs_production_min.isMemo=function(a){return y(a)===n};
|
|
2749
|
+
reactIs_production_min.isPortal=function(a){return y(a)===c};reactIs_production_min.isProfiler=function(a){return y(a)===f};reactIs_production_min.isStrictMode=function(a){return y(a)===e};reactIs_production_min.isSuspense=function(a){return y(a)===l};reactIs_production_min.isValidElementType=function(a){return "string"===typeof a||"function"===typeof a||a===d||a===f||a===v||a===e||a===l||a===m||a===w||"object"===typeof a&&null!==a&&(a.$$typeof===p||a.$$typeof===n||a.$$typeof===g||a.$$typeof===h||a.$$typeof===k||a.$$typeof===u||a.$$typeof===q||a[0]===r)?!0:!1};
|
|
2750
|
+
reactIs_production_min.typeOf=y;
|
|
2751
|
+
return reactIs_production_min;
|
|
2752
|
+
}
|
|
2753
|
+
|
|
2754
|
+
var reactIs_development = {};
|
|
2755
|
+
|
|
2756
|
+
/** @license React v17.0.2
|
|
2757
|
+
* react-is.development.js
|
|
2758
|
+
*
|
|
2759
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
2760
|
+
*
|
|
2761
|
+
* This source code is licensed under the MIT license found in the
|
|
2762
|
+
* LICENSE file in the root directory of this source tree.
|
|
2763
|
+
*/
|
|
2764
|
+
|
|
2765
|
+
var hasRequiredReactIs_development;
|
|
2766
|
+
|
|
2767
|
+
function requireReactIs_development () {
|
|
2768
|
+
if (hasRequiredReactIs_development) return reactIs_development;
|
|
2769
|
+
hasRequiredReactIs_development = 1;
|
|
2770
|
+
|
|
2771
|
+
if (process.env.NODE_ENV !== "production") {
|
|
2772
|
+
(function() {
|
|
2773
|
+
|
|
2774
|
+
// ATTENTION
|
|
2775
|
+
// When adding new symbols to this file,
|
|
2776
|
+
// Please consider also adding to 'react-devtools-shared/src/backend/ReactSymbols'
|
|
2777
|
+
// The Symbol used to tag the ReactElement-like types. If there is no native Symbol
|
|
2778
|
+
// nor polyfill, then a plain number is used for performance.
|
|
2779
|
+
var REACT_ELEMENT_TYPE = 0xeac7;
|
|
2780
|
+
var REACT_PORTAL_TYPE = 0xeaca;
|
|
2781
|
+
var REACT_FRAGMENT_TYPE = 0xeacb;
|
|
2782
|
+
var REACT_STRICT_MODE_TYPE = 0xeacc;
|
|
2783
|
+
var REACT_PROFILER_TYPE = 0xead2;
|
|
2784
|
+
var REACT_PROVIDER_TYPE = 0xeacd;
|
|
2785
|
+
var REACT_CONTEXT_TYPE = 0xeace;
|
|
2786
|
+
var REACT_FORWARD_REF_TYPE = 0xead0;
|
|
2787
|
+
var REACT_SUSPENSE_TYPE = 0xead1;
|
|
2788
|
+
var REACT_SUSPENSE_LIST_TYPE = 0xead8;
|
|
2789
|
+
var REACT_MEMO_TYPE = 0xead3;
|
|
2790
|
+
var REACT_LAZY_TYPE = 0xead4;
|
|
2791
|
+
var REACT_BLOCK_TYPE = 0xead9;
|
|
2792
|
+
var REACT_SERVER_BLOCK_TYPE = 0xeada;
|
|
2793
|
+
var REACT_FUNDAMENTAL_TYPE = 0xead5;
|
|
2794
|
+
var REACT_DEBUG_TRACING_MODE_TYPE = 0xeae1;
|
|
2795
|
+
var REACT_LEGACY_HIDDEN_TYPE = 0xeae3;
|
|
2796
|
+
|
|
2797
|
+
if (typeof Symbol === 'function' && Symbol.for) {
|
|
2798
|
+
var symbolFor = Symbol.for;
|
|
2799
|
+
REACT_ELEMENT_TYPE = symbolFor('react.element');
|
|
2800
|
+
REACT_PORTAL_TYPE = symbolFor('react.portal');
|
|
2801
|
+
REACT_FRAGMENT_TYPE = symbolFor('react.fragment');
|
|
2802
|
+
REACT_STRICT_MODE_TYPE = symbolFor('react.strict_mode');
|
|
2803
|
+
REACT_PROFILER_TYPE = symbolFor('react.profiler');
|
|
2804
|
+
REACT_PROVIDER_TYPE = symbolFor('react.provider');
|
|
2805
|
+
REACT_CONTEXT_TYPE = symbolFor('react.context');
|
|
2806
|
+
REACT_FORWARD_REF_TYPE = symbolFor('react.forward_ref');
|
|
2807
|
+
REACT_SUSPENSE_TYPE = symbolFor('react.suspense');
|
|
2808
|
+
REACT_SUSPENSE_LIST_TYPE = symbolFor('react.suspense_list');
|
|
2809
|
+
REACT_MEMO_TYPE = symbolFor('react.memo');
|
|
2810
|
+
REACT_LAZY_TYPE = symbolFor('react.lazy');
|
|
2811
|
+
REACT_BLOCK_TYPE = symbolFor('react.block');
|
|
2812
|
+
REACT_SERVER_BLOCK_TYPE = symbolFor('react.server.block');
|
|
2813
|
+
REACT_FUNDAMENTAL_TYPE = symbolFor('react.fundamental');
|
|
2814
|
+
symbolFor('react.scope');
|
|
2815
|
+
symbolFor('react.opaque.id');
|
|
2816
|
+
REACT_DEBUG_TRACING_MODE_TYPE = symbolFor('react.debug_trace_mode');
|
|
2817
|
+
symbolFor('react.offscreen');
|
|
2818
|
+
REACT_LEGACY_HIDDEN_TYPE = symbolFor('react.legacy_hidden');
|
|
2819
|
+
}
|
|
2820
|
+
|
|
2821
|
+
// Filter certain DOM attributes (e.g. src, href) if their values are empty strings.
|
|
2822
|
+
|
|
2823
|
+
var enableScopeAPI = false; // Experimental Create Event Handle API.
|
|
2824
|
+
|
|
2825
|
+
function isValidElementType(type) {
|
|
2826
|
+
if (typeof type === 'string' || typeof type === 'function') {
|
|
2827
|
+
return true;
|
|
2828
|
+
} // Note: typeof might be other than 'symbol' or 'number' (e.g. if it's a polyfill).
|
|
2829
|
+
|
|
2830
|
+
|
|
2831
|
+
if (type === REACT_FRAGMENT_TYPE || type === REACT_PROFILER_TYPE || type === REACT_DEBUG_TRACING_MODE_TYPE || type === REACT_STRICT_MODE_TYPE || type === REACT_SUSPENSE_TYPE || type === REACT_SUSPENSE_LIST_TYPE || type === REACT_LEGACY_HIDDEN_TYPE || enableScopeAPI ) {
|
|
2832
|
+
return true;
|
|
2833
|
+
}
|
|
2834
|
+
|
|
2835
|
+
if (typeof type === 'object' && type !== null) {
|
|
2836
|
+
if (type.$$typeof === REACT_LAZY_TYPE || type.$$typeof === REACT_MEMO_TYPE || type.$$typeof === REACT_PROVIDER_TYPE || type.$$typeof === REACT_CONTEXT_TYPE || type.$$typeof === REACT_FORWARD_REF_TYPE || type.$$typeof === REACT_FUNDAMENTAL_TYPE || type.$$typeof === REACT_BLOCK_TYPE || type[0] === REACT_SERVER_BLOCK_TYPE) {
|
|
2837
|
+
return true;
|
|
2838
|
+
}
|
|
2839
|
+
}
|
|
2840
|
+
|
|
2841
|
+
return false;
|
|
2842
|
+
}
|
|
2843
|
+
|
|
2844
|
+
function typeOf(object) {
|
|
2845
|
+
if (typeof object === 'object' && object !== null) {
|
|
2846
|
+
var $$typeof = object.$$typeof;
|
|
2847
|
+
|
|
2848
|
+
switch ($$typeof) {
|
|
2849
|
+
case REACT_ELEMENT_TYPE:
|
|
2850
|
+
var type = object.type;
|
|
2851
|
+
|
|
2852
|
+
switch (type) {
|
|
2853
|
+
case REACT_FRAGMENT_TYPE:
|
|
2854
|
+
case REACT_PROFILER_TYPE:
|
|
2855
|
+
case REACT_STRICT_MODE_TYPE:
|
|
2856
|
+
case REACT_SUSPENSE_TYPE:
|
|
2857
|
+
case REACT_SUSPENSE_LIST_TYPE:
|
|
2858
|
+
return type;
|
|
2859
|
+
|
|
2860
|
+
default:
|
|
2861
|
+
var $$typeofType = type && type.$$typeof;
|
|
2862
|
+
|
|
2863
|
+
switch ($$typeofType) {
|
|
2864
|
+
case REACT_CONTEXT_TYPE:
|
|
2865
|
+
case REACT_FORWARD_REF_TYPE:
|
|
2866
|
+
case REACT_LAZY_TYPE:
|
|
2867
|
+
case REACT_MEMO_TYPE:
|
|
2868
|
+
case REACT_PROVIDER_TYPE:
|
|
2869
|
+
return $$typeofType;
|
|
2870
|
+
|
|
2871
|
+
default:
|
|
2872
|
+
return $$typeof;
|
|
2873
|
+
}
|
|
2874
|
+
|
|
2875
|
+
}
|
|
2876
|
+
|
|
2877
|
+
case REACT_PORTAL_TYPE:
|
|
2878
|
+
return $$typeof;
|
|
2879
|
+
}
|
|
2880
|
+
}
|
|
2881
|
+
|
|
2882
|
+
return undefined;
|
|
2883
|
+
}
|
|
2884
|
+
var ContextConsumer = REACT_CONTEXT_TYPE;
|
|
2885
|
+
var ContextProvider = REACT_PROVIDER_TYPE;
|
|
2886
|
+
var Element = REACT_ELEMENT_TYPE;
|
|
2887
|
+
var ForwardRef = REACT_FORWARD_REF_TYPE;
|
|
2888
|
+
var Fragment = REACT_FRAGMENT_TYPE;
|
|
2889
|
+
var Lazy = REACT_LAZY_TYPE;
|
|
2890
|
+
var Memo = REACT_MEMO_TYPE;
|
|
2891
|
+
var Portal = REACT_PORTAL_TYPE;
|
|
2892
|
+
var Profiler = REACT_PROFILER_TYPE;
|
|
2893
|
+
var StrictMode = REACT_STRICT_MODE_TYPE;
|
|
2894
|
+
var Suspense = REACT_SUSPENSE_TYPE;
|
|
2895
|
+
var hasWarnedAboutDeprecatedIsAsyncMode = false;
|
|
2896
|
+
var hasWarnedAboutDeprecatedIsConcurrentMode = false; // AsyncMode should be deprecated
|
|
2897
|
+
|
|
2898
|
+
function isAsyncMode(object) {
|
|
2899
|
+
{
|
|
2900
|
+
if (!hasWarnedAboutDeprecatedIsAsyncMode) {
|
|
2901
|
+
hasWarnedAboutDeprecatedIsAsyncMode = true; // Using console['warn'] to evade Babel and ESLint
|
|
2902
|
+
|
|
2903
|
+
console['warn']('The ReactIs.isAsyncMode() alias has been deprecated, ' + 'and will be removed in React 18+.');
|
|
2904
|
+
}
|
|
2905
|
+
}
|
|
2906
|
+
|
|
2907
|
+
return false;
|
|
2908
|
+
}
|
|
2909
|
+
function isConcurrentMode(object) {
|
|
2910
|
+
{
|
|
2911
|
+
if (!hasWarnedAboutDeprecatedIsConcurrentMode) {
|
|
2912
|
+
hasWarnedAboutDeprecatedIsConcurrentMode = true; // Using console['warn'] to evade Babel and ESLint
|
|
2913
|
+
|
|
2914
|
+
console['warn']('The ReactIs.isConcurrentMode() alias has been deprecated, ' + 'and will be removed in React 18+.');
|
|
2915
|
+
}
|
|
2916
|
+
}
|
|
2917
|
+
|
|
2918
|
+
return false;
|
|
2919
|
+
}
|
|
2920
|
+
function isContextConsumer(object) {
|
|
2921
|
+
return typeOf(object) === REACT_CONTEXT_TYPE;
|
|
2922
|
+
}
|
|
2923
|
+
function isContextProvider(object) {
|
|
2924
|
+
return typeOf(object) === REACT_PROVIDER_TYPE;
|
|
2925
|
+
}
|
|
2926
|
+
function isElement(object) {
|
|
2927
|
+
return typeof object === 'object' && object !== null && object.$$typeof === REACT_ELEMENT_TYPE;
|
|
2928
|
+
}
|
|
2929
|
+
function isForwardRef(object) {
|
|
2930
|
+
return typeOf(object) === REACT_FORWARD_REF_TYPE;
|
|
2931
|
+
}
|
|
2932
|
+
function isFragment(object) {
|
|
2933
|
+
return typeOf(object) === REACT_FRAGMENT_TYPE;
|
|
2934
|
+
}
|
|
2935
|
+
function isLazy(object) {
|
|
2936
|
+
return typeOf(object) === REACT_LAZY_TYPE;
|
|
2937
|
+
}
|
|
2938
|
+
function isMemo(object) {
|
|
2939
|
+
return typeOf(object) === REACT_MEMO_TYPE;
|
|
2940
|
+
}
|
|
2941
|
+
function isPortal(object) {
|
|
2942
|
+
return typeOf(object) === REACT_PORTAL_TYPE;
|
|
2943
|
+
}
|
|
2944
|
+
function isProfiler(object) {
|
|
2945
|
+
return typeOf(object) === REACT_PROFILER_TYPE;
|
|
2946
|
+
}
|
|
2947
|
+
function isStrictMode(object) {
|
|
2948
|
+
return typeOf(object) === REACT_STRICT_MODE_TYPE;
|
|
2949
|
+
}
|
|
2950
|
+
function isSuspense(object) {
|
|
2951
|
+
return typeOf(object) === REACT_SUSPENSE_TYPE;
|
|
2952
|
+
}
|
|
2953
|
+
|
|
2954
|
+
reactIs_development.ContextConsumer = ContextConsumer;
|
|
2955
|
+
reactIs_development.ContextProvider = ContextProvider;
|
|
2956
|
+
reactIs_development.Element = Element;
|
|
2957
|
+
reactIs_development.ForwardRef = ForwardRef;
|
|
2958
|
+
reactIs_development.Fragment = Fragment;
|
|
2959
|
+
reactIs_development.Lazy = Lazy;
|
|
2960
|
+
reactIs_development.Memo = Memo;
|
|
2961
|
+
reactIs_development.Portal = Portal;
|
|
2962
|
+
reactIs_development.Profiler = Profiler;
|
|
2963
|
+
reactIs_development.StrictMode = StrictMode;
|
|
2964
|
+
reactIs_development.Suspense = Suspense;
|
|
2965
|
+
reactIs_development.isAsyncMode = isAsyncMode;
|
|
2966
|
+
reactIs_development.isConcurrentMode = isConcurrentMode;
|
|
2967
|
+
reactIs_development.isContextConsumer = isContextConsumer;
|
|
2968
|
+
reactIs_development.isContextProvider = isContextProvider;
|
|
2969
|
+
reactIs_development.isElement = isElement;
|
|
2970
|
+
reactIs_development.isForwardRef = isForwardRef;
|
|
2971
|
+
reactIs_development.isFragment = isFragment;
|
|
2972
|
+
reactIs_development.isLazy = isLazy;
|
|
2973
|
+
reactIs_development.isMemo = isMemo;
|
|
2974
|
+
reactIs_development.isPortal = isPortal;
|
|
2975
|
+
reactIs_development.isProfiler = isProfiler;
|
|
2976
|
+
reactIs_development.isStrictMode = isStrictMode;
|
|
2977
|
+
reactIs_development.isSuspense = isSuspense;
|
|
2978
|
+
reactIs_development.isValidElementType = isValidElementType;
|
|
2979
|
+
reactIs_development.typeOf = typeOf;
|
|
2980
|
+
})();
|
|
2981
|
+
}
|
|
2982
|
+
return reactIs_development;
|
|
2983
|
+
}
|
|
2984
|
+
|
|
2985
|
+
(function (module) {
|
|
2986
|
+
|
|
2987
|
+
if (process.env.NODE_ENV === 'production') {
|
|
2988
|
+
module.exports = requireReactIs_production_min();
|
|
2989
|
+
} else {
|
|
2990
|
+
module.exports = requireReactIs_development();
|
|
2991
|
+
}
|
|
2992
|
+
} (reactIs));
|
|
2993
|
+
|
|
2994
|
+
var css_248z = "[data-gene-ui-version=\"2.15.0\"] .tooltip-c-p{pointer-events:none;z-index:10}[data-gene-ui-version=\"2.15.0\"] .s-small .tooltip-c-p{padding:1.5rem}[data-gene-ui-version=\"2.15.0\"] .tooltip-wrapper{max-width:inherit}[data-gene-ui-version=\"2.15.0\"] .tooltip-content{background:rgba(var(--background-sc-rgb),.6);border-radius:.4rem;color:rgba(var(--background-rgb),.7);font:600 1.2rem/1.6rem var(--font-family);max-width:20rem;padding:.6rem 1rem;word-break:break-word}[data-gene-ui-version=\"2.15.0\"] .tooltip-content>*+*{margin:.2rem 0 0}[data-gene-ui-version=\"2.15.0\"] .s-small .tooltip-content{font:600 1rem/1.4rem var(--font-family);padding:.6rem .8rem}[data-gene-ui-version=\"2.15.0\"] .tooltip-title{color:var(--background)}";
|
|
2995
|
+
styleInject(css_248z);
|
|
2996
|
+
|
|
2997
|
+
const positions = ['top', 'right', 'bottom', 'left'];
|
|
2998
|
+
const FindAndMergeRef = (children, childProps, componentRef) => Children.map(children, (el, i) => {
|
|
2999
|
+
const newProps = Object.assign(Object.assign({}, childProps), { onClick: (e) => childProps === null || childProps === void 0 ? void 0 : childProps.onClick(e, el), ref: i === 0 ? componentRef : {} });
|
|
3000
|
+
if ((el === null || el === void 0 ? void 0 : el.type) === Fragment && el.props.children) {
|
|
3001
|
+
return FindAndMergeRef(el.props.children, childProps, componentRef);
|
|
3002
|
+
}
|
|
3003
|
+
if (reactIsExports.isForwardRef(el)) {
|
|
3004
|
+
return FindAndMergeRef(el.type.render(el.props), newProps, componentRef);
|
|
3005
|
+
}
|
|
3006
|
+
if (typeof (el === null || el === void 0 ? void 0 : el.type) === 'string') {
|
|
3007
|
+
return cloneElement(el, newProps);
|
|
3008
|
+
}
|
|
3009
|
+
if (typeof (el === null || el === void 0 ? void 0 : el.type) === 'function') {
|
|
3010
|
+
return FindAndMergeRef(el.type(el.props), newProps, componentRef);
|
|
3011
|
+
}
|
|
3012
|
+
return cloneElement(el, newProps);
|
|
3013
|
+
});
|
|
3014
|
+
const Tooltip = (_a) => {
|
|
3015
|
+
var { children, position = 'top', size = 'default', style, text, title, customPosition, alwaysShow, disableReposition = false, onClick = noop, padding = 5, screenType = 'desktop', isVisible = true } = _a, props = __rest(_a, ["children", "position", "size", "style", "text", "title", "customPosition", "alwaysShow", "disableReposition", "onClick", "padding", "screenType", "isVisible"]);
|
|
3016
|
+
// @ts-ignore
|
|
3017
|
+
const { geneUIProviderRef } = useContext(GeneUIDesignSystemContext);
|
|
3018
|
+
const { isMobile } = useDeviceType(screenType);
|
|
3019
|
+
const [isPopoverOpen, setIsPopoverState] = useState(false);
|
|
3020
|
+
const mouseEnterHandler = () => !alwaysShow && setIsPopoverState(true);
|
|
3021
|
+
const mouseLeaveHandler = () => {
|
|
3022
|
+
!alwaysShow && setIsPopoverState(false);
|
|
3023
|
+
};
|
|
3024
|
+
const { refs, floatingStyles, context } = useFloating({
|
|
3025
|
+
open: alwaysShow || isPopoverOpen,
|
|
3026
|
+
placement: position,
|
|
3027
|
+
middleware: [
|
|
3028
|
+
offset(padding),
|
|
3029
|
+
flip({
|
|
3030
|
+
fallbackAxisSideDirection: 'none',
|
|
3031
|
+
fallbackPlacements: positions,
|
|
3032
|
+
mainAxis: !disableReposition
|
|
3033
|
+
}),
|
|
3034
|
+
shift(),
|
|
3035
|
+
{
|
|
3036
|
+
name: 'getCustomPosition',
|
|
3037
|
+
fn: () => customPosition
|
|
3038
|
+
? {
|
|
3039
|
+
x: customPosition === null || customPosition === void 0 ? void 0 : customPosition.left,
|
|
3040
|
+
y: customPosition === null || customPosition === void 0 ? void 0 : customPosition.top
|
|
3041
|
+
}
|
|
3042
|
+
: {}
|
|
3043
|
+
}
|
|
3044
|
+
],
|
|
3045
|
+
whileElementsMounted: autoUpdate
|
|
3046
|
+
});
|
|
3047
|
+
const checkNudged = ({ nudgedLeft, nudgedTop }) => (isMobile ? !(nudgedTop || nudgedLeft) : true);
|
|
3048
|
+
const childProps = {
|
|
3049
|
+
onMouseEnter: mouseEnterHandler,
|
|
3050
|
+
onMouseLeave: mouseLeaveHandler,
|
|
3051
|
+
onClick: (e, el) => {
|
|
3052
|
+
const { onClick: onClickHandler } = el === null || el === void 0 ? void 0 : el.props;
|
|
3053
|
+
typeof onClickHandler === 'function' && onClickHandler(e);
|
|
3054
|
+
onClick(e);
|
|
3055
|
+
}
|
|
3056
|
+
};
|
|
3057
|
+
return (React__default.createElement(React__default.Fragment, null,
|
|
3058
|
+
FindAndMergeRef(children, childProps, refs.setReference),
|
|
3059
|
+
isVisible && (alwaysShow || isPopoverOpen) && (React__default.createElement(FloatingPortal, { root: geneUIProviderRef.current }, checkNudged({ nudgedLeft: context.x, nudgedTop: context.y }) && (React__default.createElement("div", Object.assign({ className: `tooltip-c-p s-${size} ${position}`, ref: refs.setFloating, style: Object.assign(Object.assign({}, style), floatingStyles) }, props), (title || text) && (React__default.createElement("div", { className: "tooltip-content" },
|
|
3060
|
+
title && React__default.createElement("div", { className: "tooltip-title" }, title),
|
|
3061
|
+
text && React__default.createElement("div", { className: "tooltip-text" }, text)))))))));
|
|
3062
|
+
};
|
|
3063
|
+
|
|
3064
|
+
export { Tooltip as T, reactIsExports as r };
|