@geneui/components 3.0.0-next-9bedd8e-12022025 → 3.0.0-next-5cecb1e-17022025
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/Badge.js +1 -1
- package/Button.js +5 -5
- package/Checkbox.js +2 -0
- package/Close-e8302008.js +23 -0
- package/GeneUIProvider.js +1 -1
- package/Info.js +3 -26
- package/InfoOutline-dd2e89d9.js +29 -0
- package/Label.js +2 -0
- package/Pill.js +1 -0
- package/Popover.js +12 -0
- package/ProgressBar.js +2 -0
- package/Tag.js +3 -20
- package/Tooltip.js +3 -3318
- package/components/atoms/Button/Button.d.ts +1 -1
- package/components/atoms/Popover/Helper.d.ts +8 -0
- package/components/atoms/Popover/Popover.d.ts +64 -0
- package/components/atoms/Popover/PopoverBody.d.ts +3 -0
- package/components/atoms/Popover/PopoverFooter.d.ts +3 -0
- package/components/atoms/Popover/PopoverFooterActions.d.ts +3 -0
- package/components/atoms/Popover/index.d.ts +4 -0
- package/floating-ui.react-0485e4db.js +3898 -0
- package/hooks/index.d.ts +1 -0
- package/hooks/useScrollLock/index.d.ts +1 -0
- package/hooks/useScrollLock/useScrollLock.d.ts +7 -0
- package/index-18e397a9.js +342 -0
- package/index.d.ts +2 -0
- package/index.js +5 -1
- package/package.json +1 -1
|
@@ -0,0 +1,3898 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { useLayoutEffect, useEffect, useRef } from 'react';
|
|
3
|
+
import * as ReactDOM from 'react-dom';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Custom positioning reference element.
|
|
7
|
+
* @see https://floating-ui.com/docs/virtual-elements
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
const min = Math.min;
|
|
11
|
+
const max = Math.max;
|
|
12
|
+
const round = Math.round;
|
|
13
|
+
const floor = Math.floor;
|
|
14
|
+
const createCoords = v => ({
|
|
15
|
+
x: v,
|
|
16
|
+
y: v
|
|
17
|
+
});
|
|
18
|
+
const oppositeSideMap = {
|
|
19
|
+
left: 'right',
|
|
20
|
+
right: 'left',
|
|
21
|
+
bottom: 'top',
|
|
22
|
+
top: 'bottom'
|
|
23
|
+
};
|
|
24
|
+
const oppositeAlignmentMap = {
|
|
25
|
+
start: 'end',
|
|
26
|
+
end: 'start'
|
|
27
|
+
};
|
|
28
|
+
function clamp(start, value, end) {
|
|
29
|
+
return max(start, min(value, end));
|
|
30
|
+
}
|
|
31
|
+
function evaluate(value, param) {
|
|
32
|
+
return typeof value === 'function' ? value(param) : value;
|
|
33
|
+
}
|
|
34
|
+
function getSide(placement) {
|
|
35
|
+
return placement.split('-')[0];
|
|
36
|
+
}
|
|
37
|
+
function getAlignment(placement) {
|
|
38
|
+
return placement.split('-')[1];
|
|
39
|
+
}
|
|
40
|
+
function getOppositeAxis(axis) {
|
|
41
|
+
return axis === 'x' ? 'y' : 'x';
|
|
42
|
+
}
|
|
43
|
+
function getAxisLength(axis) {
|
|
44
|
+
return axis === 'y' ? 'height' : 'width';
|
|
45
|
+
}
|
|
46
|
+
function getSideAxis(placement) {
|
|
47
|
+
return ['top', 'bottom'].includes(getSide(placement)) ? 'y' : 'x';
|
|
48
|
+
}
|
|
49
|
+
function getAlignmentAxis(placement) {
|
|
50
|
+
return getOppositeAxis(getSideAxis(placement));
|
|
51
|
+
}
|
|
52
|
+
function getAlignmentSides(placement, rects, rtl) {
|
|
53
|
+
if (rtl === void 0) {
|
|
54
|
+
rtl = false;
|
|
55
|
+
}
|
|
56
|
+
const alignment = getAlignment(placement);
|
|
57
|
+
const alignmentAxis = getAlignmentAxis(placement);
|
|
58
|
+
const length = getAxisLength(alignmentAxis);
|
|
59
|
+
let mainAlignmentSide = alignmentAxis === 'x' ? alignment === (rtl ? 'end' : 'start') ? 'right' : 'left' : alignment === 'start' ? 'bottom' : 'top';
|
|
60
|
+
if (rects.reference[length] > rects.floating[length]) {
|
|
61
|
+
mainAlignmentSide = getOppositePlacement(mainAlignmentSide);
|
|
62
|
+
}
|
|
63
|
+
return [mainAlignmentSide, getOppositePlacement(mainAlignmentSide)];
|
|
64
|
+
}
|
|
65
|
+
function getExpandedPlacements(placement) {
|
|
66
|
+
const oppositePlacement = getOppositePlacement(placement);
|
|
67
|
+
return [getOppositeAlignmentPlacement(placement), oppositePlacement, getOppositeAlignmentPlacement(oppositePlacement)];
|
|
68
|
+
}
|
|
69
|
+
function getOppositeAlignmentPlacement(placement) {
|
|
70
|
+
return placement.replace(/start|end/g, alignment => oppositeAlignmentMap[alignment]);
|
|
71
|
+
}
|
|
72
|
+
function getSideList(side, isStart, rtl) {
|
|
73
|
+
const lr = ['left', 'right'];
|
|
74
|
+
const rl = ['right', 'left'];
|
|
75
|
+
const tb = ['top', 'bottom'];
|
|
76
|
+
const bt = ['bottom', 'top'];
|
|
77
|
+
switch (side) {
|
|
78
|
+
case 'top':
|
|
79
|
+
case 'bottom':
|
|
80
|
+
if (rtl) return isStart ? rl : lr;
|
|
81
|
+
return isStart ? lr : rl;
|
|
82
|
+
case 'left':
|
|
83
|
+
case 'right':
|
|
84
|
+
return isStart ? tb : bt;
|
|
85
|
+
default:
|
|
86
|
+
return [];
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
function getOppositeAxisPlacements(placement, flipAlignment, direction, rtl) {
|
|
90
|
+
const alignment = getAlignment(placement);
|
|
91
|
+
let list = getSideList(getSide(placement), direction === 'start', rtl);
|
|
92
|
+
if (alignment) {
|
|
93
|
+
list = list.map(side => side + "-" + alignment);
|
|
94
|
+
if (flipAlignment) {
|
|
95
|
+
list = list.concat(list.map(getOppositeAlignmentPlacement));
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return list;
|
|
99
|
+
}
|
|
100
|
+
function getOppositePlacement(placement) {
|
|
101
|
+
return placement.replace(/left|right|bottom|top/g, side => oppositeSideMap[side]);
|
|
102
|
+
}
|
|
103
|
+
function expandPaddingObject(padding) {
|
|
104
|
+
return {
|
|
105
|
+
top: 0,
|
|
106
|
+
right: 0,
|
|
107
|
+
bottom: 0,
|
|
108
|
+
left: 0,
|
|
109
|
+
...padding
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
function getPaddingObject(padding) {
|
|
113
|
+
return typeof padding !== 'number' ? expandPaddingObject(padding) : {
|
|
114
|
+
top: padding,
|
|
115
|
+
right: padding,
|
|
116
|
+
bottom: padding,
|
|
117
|
+
left: padding
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
function rectToClientRect(rect) {
|
|
121
|
+
const {
|
|
122
|
+
x,
|
|
123
|
+
y,
|
|
124
|
+
width,
|
|
125
|
+
height
|
|
126
|
+
} = rect;
|
|
127
|
+
return {
|
|
128
|
+
width,
|
|
129
|
+
height,
|
|
130
|
+
top: y,
|
|
131
|
+
left: x,
|
|
132
|
+
right: x + width,
|
|
133
|
+
bottom: y + height,
|
|
134
|
+
x,
|
|
135
|
+
y
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function computeCoordsFromPlacement(_ref, placement, rtl) {
|
|
140
|
+
let {
|
|
141
|
+
reference,
|
|
142
|
+
floating
|
|
143
|
+
} = _ref;
|
|
144
|
+
const sideAxis = getSideAxis(placement);
|
|
145
|
+
const alignmentAxis = getAlignmentAxis(placement);
|
|
146
|
+
const alignLength = getAxisLength(alignmentAxis);
|
|
147
|
+
const side = getSide(placement);
|
|
148
|
+
const isVertical = sideAxis === 'y';
|
|
149
|
+
const commonX = reference.x + reference.width / 2 - floating.width / 2;
|
|
150
|
+
const commonY = reference.y + reference.height / 2 - floating.height / 2;
|
|
151
|
+
const commonAlign = reference[alignLength] / 2 - floating[alignLength] / 2;
|
|
152
|
+
let coords;
|
|
153
|
+
switch (side) {
|
|
154
|
+
case 'top':
|
|
155
|
+
coords = {
|
|
156
|
+
x: commonX,
|
|
157
|
+
y: reference.y - floating.height
|
|
158
|
+
};
|
|
159
|
+
break;
|
|
160
|
+
case 'bottom':
|
|
161
|
+
coords = {
|
|
162
|
+
x: commonX,
|
|
163
|
+
y: reference.y + reference.height
|
|
164
|
+
};
|
|
165
|
+
break;
|
|
166
|
+
case 'right':
|
|
167
|
+
coords = {
|
|
168
|
+
x: reference.x + reference.width,
|
|
169
|
+
y: commonY
|
|
170
|
+
};
|
|
171
|
+
break;
|
|
172
|
+
case 'left':
|
|
173
|
+
coords = {
|
|
174
|
+
x: reference.x - floating.width,
|
|
175
|
+
y: commonY
|
|
176
|
+
};
|
|
177
|
+
break;
|
|
178
|
+
default:
|
|
179
|
+
coords = {
|
|
180
|
+
x: reference.x,
|
|
181
|
+
y: reference.y
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
switch (getAlignment(placement)) {
|
|
185
|
+
case 'start':
|
|
186
|
+
coords[alignmentAxis] -= commonAlign * (rtl && isVertical ? -1 : 1);
|
|
187
|
+
break;
|
|
188
|
+
case 'end':
|
|
189
|
+
coords[alignmentAxis] += commonAlign * (rtl && isVertical ? -1 : 1);
|
|
190
|
+
break;
|
|
191
|
+
}
|
|
192
|
+
return coords;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Computes the `x` and `y` coordinates that will place the floating element
|
|
197
|
+
* next to a given reference element.
|
|
198
|
+
*
|
|
199
|
+
* This export does not have any `platform` interface logic. You will need to
|
|
200
|
+
* write one for the platform you are using Floating UI with.
|
|
201
|
+
*/
|
|
202
|
+
const computePosition$1 = async (reference, floating, config) => {
|
|
203
|
+
const {
|
|
204
|
+
placement = 'bottom',
|
|
205
|
+
strategy = 'absolute',
|
|
206
|
+
middleware = [],
|
|
207
|
+
platform
|
|
208
|
+
} = config;
|
|
209
|
+
const validMiddleware = middleware.filter(Boolean);
|
|
210
|
+
const rtl = await (platform.isRTL == null ? void 0 : platform.isRTL(floating));
|
|
211
|
+
let rects = await platform.getElementRects({
|
|
212
|
+
reference,
|
|
213
|
+
floating,
|
|
214
|
+
strategy
|
|
215
|
+
});
|
|
216
|
+
let {
|
|
217
|
+
x,
|
|
218
|
+
y
|
|
219
|
+
} = computeCoordsFromPlacement(rects, placement, rtl);
|
|
220
|
+
let statefulPlacement = placement;
|
|
221
|
+
let middlewareData = {};
|
|
222
|
+
let resetCount = 0;
|
|
223
|
+
for (let i = 0; i < validMiddleware.length; i++) {
|
|
224
|
+
const {
|
|
225
|
+
name,
|
|
226
|
+
fn
|
|
227
|
+
} = validMiddleware[i];
|
|
228
|
+
const {
|
|
229
|
+
x: nextX,
|
|
230
|
+
y: nextY,
|
|
231
|
+
data,
|
|
232
|
+
reset
|
|
233
|
+
} = await fn({
|
|
234
|
+
x,
|
|
235
|
+
y,
|
|
236
|
+
initialPlacement: placement,
|
|
237
|
+
placement: statefulPlacement,
|
|
238
|
+
strategy,
|
|
239
|
+
middlewareData,
|
|
240
|
+
rects,
|
|
241
|
+
platform,
|
|
242
|
+
elements: {
|
|
243
|
+
reference,
|
|
244
|
+
floating
|
|
245
|
+
}
|
|
246
|
+
});
|
|
247
|
+
x = nextX != null ? nextX : x;
|
|
248
|
+
y = nextY != null ? nextY : y;
|
|
249
|
+
middlewareData = {
|
|
250
|
+
...middlewareData,
|
|
251
|
+
[name]: {
|
|
252
|
+
...middlewareData[name],
|
|
253
|
+
...data
|
|
254
|
+
}
|
|
255
|
+
};
|
|
256
|
+
if (reset && resetCount <= 50) {
|
|
257
|
+
resetCount++;
|
|
258
|
+
if (typeof reset === 'object') {
|
|
259
|
+
if (reset.placement) {
|
|
260
|
+
statefulPlacement = reset.placement;
|
|
261
|
+
}
|
|
262
|
+
if (reset.rects) {
|
|
263
|
+
rects = reset.rects === true ? await platform.getElementRects({
|
|
264
|
+
reference,
|
|
265
|
+
floating,
|
|
266
|
+
strategy
|
|
267
|
+
}) : reset.rects;
|
|
268
|
+
}
|
|
269
|
+
({
|
|
270
|
+
x,
|
|
271
|
+
y
|
|
272
|
+
} = computeCoordsFromPlacement(rects, statefulPlacement, rtl));
|
|
273
|
+
}
|
|
274
|
+
i = -1;
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
return {
|
|
278
|
+
x,
|
|
279
|
+
y,
|
|
280
|
+
placement: statefulPlacement,
|
|
281
|
+
strategy,
|
|
282
|
+
middlewareData
|
|
283
|
+
};
|
|
284
|
+
};
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* Resolves with an object of overflow side offsets that determine how much the
|
|
288
|
+
* element is overflowing a given clipping boundary on each side.
|
|
289
|
+
* - positive = overflowing the boundary by that number of pixels
|
|
290
|
+
* - negative = how many pixels left before it will overflow
|
|
291
|
+
* - 0 = lies flush with the boundary
|
|
292
|
+
* @see https://floating-ui.com/docs/detectOverflow
|
|
293
|
+
*/
|
|
294
|
+
async function detectOverflow(state, options) {
|
|
295
|
+
var _await$platform$isEle;
|
|
296
|
+
if (options === void 0) {
|
|
297
|
+
options = {};
|
|
298
|
+
}
|
|
299
|
+
const {
|
|
300
|
+
x,
|
|
301
|
+
y,
|
|
302
|
+
platform,
|
|
303
|
+
rects,
|
|
304
|
+
elements,
|
|
305
|
+
strategy
|
|
306
|
+
} = state;
|
|
307
|
+
const {
|
|
308
|
+
boundary = 'clippingAncestors',
|
|
309
|
+
rootBoundary = 'viewport',
|
|
310
|
+
elementContext = 'floating',
|
|
311
|
+
altBoundary = false,
|
|
312
|
+
padding = 0
|
|
313
|
+
} = evaluate(options, state);
|
|
314
|
+
const paddingObject = getPaddingObject(padding);
|
|
315
|
+
const altContext = elementContext === 'floating' ? 'reference' : 'floating';
|
|
316
|
+
const element = elements[altBoundary ? altContext : elementContext];
|
|
317
|
+
const clippingClientRect = rectToClientRect(await platform.getClippingRect({
|
|
318
|
+
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))),
|
|
319
|
+
boundary,
|
|
320
|
+
rootBoundary,
|
|
321
|
+
strategy
|
|
322
|
+
}));
|
|
323
|
+
const rect = elementContext === 'floating' ? {
|
|
324
|
+
x,
|
|
325
|
+
y,
|
|
326
|
+
width: rects.floating.width,
|
|
327
|
+
height: rects.floating.height
|
|
328
|
+
} : rects.reference;
|
|
329
|
+
const offsetParent = await (platform.getOffsetParent == null ? void 0 : platform.getOffsetParent(elements.floating));
|
|
330
|
+
const offsetScale = (await (platform.isElement == null ? void 0 : platform.isElement(offsetParent))) ? (await (platform.getScale == null ? void 0 : platform.getScale(offsetParent))) || {
|
|
331
|
+
x: 1,
|
|
332
|
+
y: 1
|
|
333
|
+
} : {
|
|
334
|
+
x: 1,
|
|
335
|
+
y: 1
|
|
336
|
+
};
|
|
337
|
+
const elementClientRect = rectToClientRect(platform.convertOffsetParentRelativeRectToViewportRelativeRect ? await platform.convertOffsetParentRelativeRectToViewportRelativeRect({
|
|
338
|
+
elements,
|
|
339
|
+
rect,
|
|
340
|
+
offsetParent,
|
|
341
|
+
strategy
|
|
342
|
+
}) : rect);
|
|
343
|
+
return {
|
|
344
|
+
top: (clippingClientRect.top - elementClientRect.top + paddingObject.top) / offsetScale.y,
|
|
345
|
+
bottom: (elementClientRect.bottom - clippingClientRect.bottom + paddingObject.bottom) / offsetScale.y,
|
|
346
|
+
left: (clippingClientRect.left - elementClientRect.left + paddingObject.left) / offsetScale.x,
|
|
347
|
+
right: (elementClientRect.right - clippingClientRect.right + paddingObject.right) / offsetScale.x
|
|
348
|
+
};
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
/**
|
|
352
|
+
* Provides data to position an inner element of the floating element so that it
|
|
353
|
+
* appears centered to the reference element.
|
|
354
|
+
* @see https://floating-ui.com/docs/arrow
|
|
355
|
+
*/
|
|
356
|
+
const arrow$3 = options => ({
|
|
357
|
+
name: 'arrow',
|
|
358
|
+
options,
|
|
359
|
+
async fn(state) {
|
|
360
|
+
const {
|
|
361
|
+
x,
|
|
362
|
+
y,
|
|
363
|
+
placement,
|
|
364
|
+
rects,
|
|
365
|
+
platform,
|
|
366
|
+
elements,
|
|
367
|
+
middlewareData
|
|
368
|
+
} = state;
|
|
369
|
+
// Since `element` is required, we don't Partial<> the type.
|
|
370
|
+
const {
|
|
371
|
+
element,
|
|
372
|
+
padding = 0
|
|
373
|
+
} = evaluate(options, state) || {};
|
|
374
|
+
if (element == null) {
|
|
375
|
+
return {};
|
|
376
|
+
}
|
|
377
|
+
const paddingObject = getPaddingObject(padding);
|
|
378
|
+
const coords = {
|
|
379
|
+
x,
|
|
380
|
+
y
|
|
381
|
+
};
|
|
382
|
+
const axis = getAlignmentAxis(placement);
|
|
383
|
+
const length = getAxisLength(axis);
|
|
384
|
+
const arrowDimensions = await platform.getDimensions(element);
|
|
385
|
+
const isYAxis = axis === 'y';
|
|
386
|
+
const minProp = isYAxis ? 'top' : 'left';
|
|
387
|
+
const maxProp = isYAxis ? 'bottom' : 'right';
|
|
388
|
+
const clientProp = isYAxis ? 'clientHeight' : 'clientWidth';
|
|
389
|
+
const endDiff = rects.reference[length] + rects.reference[axis] - coords[axis] - rects.floating[length];
|
|
390
|
+
const startDiff = coords[axis] - rects.reference[axis];
|
|
391
|
+
const arrowOffsetParent = await (platform.getOffsetParent == null ? void 0 : platform.getOffsetParent(element));
|
|
392
|
+
let clientSize = arrowOffsetParent ? arrowOffsetParent[clientProp] : 0;
|
|
393
|
+
|
|
394
|
+
// DOM platform can return `window` as the `offsetParent`.
|
|
395
|
+
if (!clientSize || !(await (platform.isElement == null ? void 0 : platform.isElement(arrowOffsetParent)))) {
|
|
396
|
+
clientSize = elements.floating[clientProp] || rects.floating[length];
|
|
397
|
+
}
|
|
398
|
+
const centerToReference = endDiff / 2 - startDiff / 2;
|
|
399
|
+
|
|
400
|
+
// If the padding is large enough that it causes the arrow to no longer be
|
|
401
|
+
// centered, modify the padding so that it is centered.
|
|
402
|
+
const largestPossiblePadding = clientSize / 2 - arrowDimensions[length] / 2 - 1;
|
|
403
|
+
const minPadding = min(paddingObject[minProp], largestPossiblePadding);
|
|
404
|
+
const maxPadding = min(paddingObject[maxProp], largestPossiblePadding);
|
|
405
|
+
|
|
406
|
+
// Make sure the arrow doesn't overflow the floating element if the center
|
|
407
|
+
// point is outside the floating element's bounds.
|
|
408
|
+
const min$1 = minPadding;
|
|
409
|
+
const max = clientSize - arrowDimensions[length] - maxPadding;
|
|
410
|
+
const center = clientSize / 2 - arrowDimensions[length] / 2 + centerToReference;
|
|
411
|
+
const offset = clamp(min$1, center, max);
|
|
412
|
+
|
|
413
|
+
// If the reference is small enough that the arrow's padding causes it to
|
|
414
|
+
// to point to nothing for an aligned placement, adjust the offset of the
|
|
415
|
+
// floating element itself. To ensure `shift()` continues to take action,
|
|
416
|
+
// a single reset is performed when this is true.
|
|
417
|
+
const shouldAddOffset = !middlewareData.arrow && getAlignment(placement) != null && center !== offset && rects.reference[length] / 2 - (center < min$1 ? minPadding : maxPadding) - arrowDimensions[length] / 2 < 0;
|
|
418
|
+
const alignmentOffset = shouldAddOffset ? center < min$1 ? center - min$1 : center - max : 0;
|
|
419
|
+
return {
|
|
420
|
+
[axis]: coords[axis] + alignmentOffset,
|
|
421
|
+
data: {
|
|
422
|
+
[axis]: offset,
|
|
423
|
+
centerOffset: center - offset - alignmentOffset,
|
|
424
|
+
...(shouldAddOffset && {
|
|
425
|
+
alignmentOffset
|
|
426
|
+
})
|
|
427
|
+
},
|
|
428
|
+
reset: shouldAddOffset
|
|
429
|
+
};
|
|
430
|
+
}
|
|
431
|
+
});
|
|
432
|
+
|
|
433
|
+
/**
|
|
434
|
+
* Optimizes the visibility of the floating element by flipping the `placement`
|
|
435
|
+
* in order to keep it in view when the preferred placement(s) will overflow the
|
|
436
|
+
* clipping boundary. Alternative to `autoPlacement`.
|
|
437
|
+
* @see https://floating-ui.com/docs/flip
|
|
438
|
+
*/
|
|
439
|
+
const flip$2 = function (options) {
|
|
440
|
+
if (options === void 0) {
|
|
441
|
+
options = {};
|
|
442
|
+
}
|
|
443
|
+
return {
|
|
444
|
+
name: 'flip',
|
|
445
|
+
options,
|
|
446
|
+
async fn(state) {
|
|
447
|
+
var _middlewareData$arrow, _middlewareData$flip;
|
|
448
|
+
const {
|
|
449
|
+
placement,
|
|
450
|
+
middlewareData,
|
|
451
|
+
rects,
|
|
452
|
+
initialPlacement,
|
|
453
|
+
platform,
|
|
454
|
+
elements
|
|
455
|
+
} = state;
|
|
456
|
+
const {
|
|
457
|
+
mainAxis: checkMainAxis = true,
|
|
458
|
+
crossAxis: checkCrossAxis = true,
|
|
459
|
+
fallbackPlacements: specifiedFallbackPlacements,
|
|
460
|
+
fallbackStrategy = 'bestFit',
|
|
461
|
+
fallbackAxisSideDirection = 'none',
|
|
462
|
+
flipAlignment = true,
|
|
463
|
+
...detectOverflowOptions
|
|
464
|
+
} = evaluate(options, state);
|
|
465
|
+
|
|
466
|
+
// If a reset by the arrow was caused due to an alignment offset being
|
|
467
|
+
// added, we should skip any logic now since `flip()` has already done its
|
|
468
|
+
// work.
|
|
469
|
+
// https://github.com/floating-ui/floating-ui/issues/2549#issuecomment-1719601643
|
|
470
|
+
if ((_middlewareData$arrow = middlewareData.arrow) != null && _middlewareData$arrow.alignmentOffset) {
|
|
471
|
+
return {};
|
|
472
|
+
}
|
|
473
|
+
const side = getSide(placement);
|
|
474
|
+
const initialSideAxis = getSideAxis(initialPlacement);
|
|
475
|
+
const isBasePlacement = getSide(initialPlacement) === initialPlacement;
|
|
476
|
+
const rtl = await (platform.isRTL == null ? void 0 : platform.isRTL(elements.floating));
|
|
477
|
+
const fallbackPlacements = specifiedFallbackPlacements || (isBasePlacement || !flipAlignment ? [getOppositePlacement(initialPlacement)] : getExpandedPlacements(initialPlacement));
|
|
478
|
+
const hasFallbackAxisSideDirection = fallbackAxisSideDirection !== 'none';
|
|
479
|
+
if (!specifiedFallbackPlacements && hasFallbackAxisSideDirection) {
|
|
480
|
+
fallbackPlacements.push(...getOppositeAxisPlacements(initialPlacement, flipAlignment, fallbackAxisSideDirection, rtl));
|
|
481
|
+
}
|
|
482
|
+
const placements = [initialPlacement, ...fallbackPlacements];
|
|
483
|
+
const overflow = await detectOverflow(state, detectOverflowOptions);
|
|
484
|
+
const overflows = [];
|
|
485
|
+
let overflowsData = ((_middlewareData$flip = middlewareData.flip) == null ? void 0 : _middlewareData$flip.overflows) || [];
|
|
486
|
+
if (checkMainAxis) {
|
|
487
|
+
overflows.push(overflow[side]);
|
|
488
|
+
}
|
|
489
|
+
if (checkCrossAxis) {
|
|
490
|
+
const sides = getAlignmentSides(placement, rects, rtl);
|
|
491
|
+
overflows.push(overflow[sides[0]], overflow[sides[1]]);
|
|
492
|
+
}
|
|
493
|
+
overflowsData = [...overflowsData, {
|
|
494
|
+
placement,
|
|
495
|
+
overflows
|
|
496
|
+
}];
|
|
497
|
+
|
|
498
|
+
// One or more sides is overflowing.
|
|
499
|
+
if (!overflows.every(side => side <= 0)) {
|
|
500
|
+
var _middlewareData$flip2, _overflowsData$filter;
|
|
501
|
+
const nextIndex = (((_middlewareData$flip2 = middlewareData.flip) == null ? void 0 : _middlewareData$flip2.index) || 0) + 1;
|
|
502
|
+
const nextPlacement = placements[nextIndex];
|
|
503
|
+
if (nextPlacement) {
|
|
504
|
+
// Try next placement and re-run the lifecycle.
|
|
505
|
+
return {
|
|
506
|
+
data: {
|
|
507
|
+
index: nextIndex,
|
|
508
|
+
overflows: overflowsData
|
|
509
|
+
},
|
|
510
|
+
reset: {
|
|
511
|
+
placement: nextPlacement
|
|
512
|
+
}
|
|
513
|
+
};
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
// First, find the candidates that fit on the mainAxis side of overflow,
|
|
517
|
+
// then find the placement that fits the best on the main crossAxis side.
|
|
518
|
+
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;
|
|
519
|
+
|
|
520
|
+
// Otherwise fallback.
|
|
521
|
+
if (!resetPlacement) {
|
|
522
|
+
switch (fallbackStrategy) {
|
|
523
|
+
case 'bestFit':
|
|
524
|
+
{
|
|
525
|
+
var _overflowsData$filter2;
|
|
526
|
+
const placement = (_overflowsData$filter2 = overflowsData.filter(d => {
|
|
527
|
+
if (hasFallbackAxisSideDirection) {
|
|
528
|
+
const currentSideAxis = getSideAxis(d.placement);
|
|
529
|
+
return currentSideAxis === initialSideAxis ||
|
|
530
|
+
// Create a bias to the `y` side axis due to horizontal
|
|
531
|
+
// reading directions favoring greater width.
|
|
532
|
+
currentSideAxis === 'y';
|
|
533
|
+
}
|
|
534
|
+
return true;
|
|
535
|
+
}).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$filter2[0];
|
|
536
|
+
if (placement) {
|
|
537
|
+
resetPlacement = placement;
|
|
538
|
+
}
|
|
539
|
+
break;
|
|
540
|
+
}
|
|
541
|
+
case 'initialPlacement':
|
|
542
|
+
resetPlacement = initialPlacement;
|
|
543
|
+
break;
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
if (placement !== resetPlacement) {
|
|
547
|
+
return {
|
|
548
|
+
reset: {
|
|
549
|
+
placement: resetPlacement
|
|
550
|
+
}
|
|
551
|
+
};
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
return {};
|
|
555
|
+
}
|
|
556
|
+
};
|
|
557
|
+
};
|
|
558
|
+
|
|
559
|
+
// For type backwards-compatibility, the `OffsetOptions` type was also
|
|
560
|
+
// Derivable.
|
|
561
|
+
|
|
562
|
+
async function convertValueToCoords(state, options) {
|
|
563
|
+
const {
|
|
564
|
+
placement,
|
|
565
|
+
platform,
|
|
566
|
+
elements
|
|
567
|
+
} = state;
|
|
568
|
+
const rtl = await (platform.isRTL == null ? void 0 : platform.isRTL(elements.floating));
|
|
569
|
+
const side = getSide(placement);
|
|
570
|
+
const alignment = getAlignment(placement);
|
|
571
|
+
const isVertical = getSideAxis(placement) === 'y';
|
|
572
|
+
const mainAxisMulti = ['left', 'top'].includes(side) ? -1 : 1;
|
|
573
|
+
const crossAxisMulti = rtl && isVertical ? -1 : 1;
|
|
574
|
+
const rawValue = evaluate(options, state);
|
|
575
|
+
|
|
576
|
+
// eslint-disable-next-line prefer-const
|
|
577
|
+
let {
|
|
578
|
+
mainAxis,
|
|
579
|
+
crossAxis,
|
|
580
|
+
alignmentAxis
|
|
581
|
+
} = typeof rawValue === 'number' ? {
|
|
582
|
+
mainAxis: rawValue,
|
|
583
|
+
crossAxis: 0,
|
|
584
|
+
alignmentAxis: null
|
|
585
|
+
} : {
|
|
586
|
+
mainAxis: rawValue.mainAxis || 0,
|
|
587
|
+
crossAxis: rawValue.crossAxis || 0,
|
|
588
|
+
alignmentAxis: rawValue.alignmentAxis
|
|
589
|
+
};
|
|
590
|
+
if (alignment && typeof alignmentAxis === 'number') {
|
|
591
|
+
crossAxis = alignment === 'end' ? alignmentAxis * -1 : alignmentAxis;
|
|
592
|
+
}
|
|
593
|
+
return isVertical ? {
|
|
594
|
+
x: crossAxis * crossAxisMulti,
|
|
595
|
+
y: mainAxis * mainAxisMulti
|
|
596
|
+
} : {
|
|
597
|
+
x: mainAxis * mainAxisMulti,
|
|
598
|
+
y: crossAxis * crossAxisMulti
|
|
599
|
+
};
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
/**
|
|
603
|
+
* Modifies the placement by translating the floating element along the
|
|
604
|
+
* specified axes.
|
|
605
|
+
* A number (shorthand for `mainAxis` or distance), or an axes configuration
|
|
606
|
+
* object may be passed.
|
|
607
|
+
* @see https://floating-ui.com/docs/offset
|
|
608
|
+
*/
|
|
609
|
+
const offset$2 = function (options) {
|
|
610
|
+
if (options === void 0) {
|
|
611
|
+
options = 0;
|
|
612
|
+
}
|
|
613
|
+
return {
|
|
614
|
+
name: 'offset',
|
|
615
|
+
options,
|
|
616
|
+
async fn(state) {
|
|
617
|
+
var _middlewareData$offse, _middlewareData$arrow;
|
|
618
|
+
const {
|
|
619
|
+
x,
|
|
620
|
+
y,
|
|
621
|
+
placement,
|
|
622
|
+
middlewareData
|
|
623
|
+
} = state;
|
|
624
|
+
const diffCoords = await convertValueToCoords(state, options);
|
|
625
|
+
|
|
626
|
+
// If the placement is the same and the arrow caused an alignment offset
|
|
627
|
+
// then we don't need to change the positioning coordinates.
|
|
628
|
+
if (placement === ((_middlewareData$offse = middlewareData.offset) == null ? void 0 : _middlewareData$offse.placement) && (_middlewareData$arrow = middlewareData.arrow) != null && _middlewareData$arrow.alignmentOffset) {
|
|
629
|
+
return {};
|
|
630
|
+
}
|
|
631
|
+
return {
|
|
632
|
+
x: x + diffCoords.x,
|
|
633
|
+
y: y + diffCoords.y,
|
|
634
|
+
data: {
|
|
635
|
+
...diffCoords,
|
|
636
|
+
placement
|
|
637
|
+
}
|
|
638
|
+
};
|
|
639
|
+
}
|
|
640
|
+
};
|
|
641
|
+
};
|
|
642
|
+
|
|
643
|
+
/**
|
|
644
|
+
* Optimizes the visibility of the floating element by shifting it in order to
|
|
645
|
+
* keep it in view when it will overflow the clipping boundary.
|
|
646
|
+
* @see https://floating-ui.com/docs/shift
|
|
647
|
+
*/
|
|
648
|
+
const shift$2 = function (options) {
|
|
649
|
+
if (options === void 0) {
|
|
650
|
+
options = {};
|
|
651
|
+
}
|
|
652
|
+
return {
|
|
653
|
+
name: 'shift',
|
|
654
|
+
options,
|
|
655
|
+
async fn(state) {
|
|
656
|
+
const {
|
|
657
|
+
x,
|
|
658
|
+
y,
|
|
659
|
+
placement
|
|
660
|
+
} = state;
|
|
661
|
+
const {
|
|
662
|
+
mainAxis: checkMainAxis = true,
|
|
663
|
+
crossAxis: checkCrossAxis = false,
|
|
664
|
+
limiter = {
|
|
665
|
+
fn: _ref => {
|
|
666
|
+
let {
|
|
667
|
+
x,
|
|
668
|
+
y
|
|
669
|
+
} = _ref;
|
|
670
|
+
return {
|
|
671
|
+
x,
|
|
672
|
+
y
|
|
673
|
+
};
|
|
674
|
+
}
|
|
675
|
+
},
|
|
676
|
+
...detectOverflowOptions
|
|
677
|
+
} = evaluate(options, state);
|
|
678
|
+
const coords = {
|
|
679
|
+
x,
|
|
680
|
+
y
|
|
681
|
+
};
|
|
682
|
+
const overflow = await detectOverflow(state, detectOverflowOptions);
|
|
683
|
+
const crossAxis = getSideAxis(getSide(placement));
|
|
684
|
+
const mainAxis = getOppositeAxis(crossAxis);
|
|
685
|
+
let mainAxisCoord = coords[mainAxis];
|
|
686
|
+
let crossAxisCoord = coords[crossAxis];
|
|
687
|
+
if (checkMainAxis) {
|
|
688
|
+
const minSide = mainAxis === 'y' ? 'top' : 'left';
|
|
689
|
+
const maxSide = mainAxis === 'y' ? 'bottom' : 'right';
|
|
690
|
+
const min = mainAxisCoord + overflow[minSide];
|
|
691
|
+
const max = mainAxisCoord - overflow[maxSide];
|
|
692
|
+
mainAxisCoord = clamp(min, mainAxisCoord, max);
|
|
693
|
+
}
|
|
694
|
+
if (checkCrossAxis) {
|
|
695
|
+
const minSide = crossAxis === 'y' ? 'top' : 'left';
|
|
696
|
+
const maxSide = crossAxis === 'y' ? 'bottom' : 'right';
|
|
697
|
+
const min = crossAxisCoord + overflow[minSide];
|
|
698
|
+
const max = crossAxisCoord - overflow[maxSide];
|
|
699
|
+
crossAxisCoord = clamp(min, crossAxisCoord, max);
|
|
700
|
+
}
|
|
701
|
+
const limitedCoords = limiter.fn({
|
|
702
|
+
...state,
|
|
703
|
+
[mainAxis]: mainAxisCoord,
|
|
704
|
+
[crossAxis]: crossAxisCoord
|
|
705
|
+
});
|
|
706
|
+
return {
|
|
707
|
+
...limitedCoords,
|
|
708
|
+
data: {
|
|
709
|
+
x: limitedCoords.x - x,
|
|
710
|
+
y: limitedCoords.y - y,
|
|
711
|
+
enabled: {
|
|
712
|
+
[mainAxis]: checkMainAxis,
|
|
713
|
+
[crossAxis]: checkCrossAxis
|
|
714
|
+
}
|
|
715
|
+
}
|
|
716
|
+
};
|
|
717
|
+
}
|
|
718
|
+
};
|
|
719
|
+
};
|
|
720
|
+
|
|
721
|
+
function hasWindow() {
|
|
722
|
+
return typeof window !== 'undefined';
|
|
723
|
+
}
|
|
724
|
+
function getNodeName(node) {
|
|
725
|
+
if (isNode(node)) {
|
|
726
|
+
return (node.nodeName || '').toLowerCase();
|
|
727
|
+
}
|
|
728
|
+
// Mocked nodes in testing environments may not be instances of Node. By
|
|
729
|
+
// returning `#document` an infinite loop won't occur.
|
|
730
|
+
// https://github.com/floating-ui/floating-ui/issues/2317
|
|
731
|
+
return '#document';
|
|
732
|
+
}
|
|
733
|
+
function getWindow(node) {
|
|
734
|
+
var _node$ownerDocument;
|
|
735
|
+
return (node == null || (_node$ownerDocument = node.ownerDocument) == null ? void 0 : _node$ownerDocument.defaultView) || window;
|
|
736
|
+
}
|
|
737
|
+
function getDocumentElement(node) {
|
|
738
|
+
var _ref;
|
|
739
|
+
return (_ref = (isNode(node) ? node.ownerDocument : node.document) || window.document) == null ? void 0 : _ref.documentElement;
|
|
740
|
+
}
|
|
741
|
+
function isNode(value) {
|
|
742
|
+
if (!hasWindow()) {
|
|
743
|
+
return false;
|
|
744
|
+
}
|
|
745
|
+
return value instanceof Node || value instanceof getWindow(value).Node;
|
|
746
|
+
}
|
|
747
|
+
function isElement(value) {
|
|
748
|
+
if (!hasWindow()) {
|
|
749
|
+
return false;
|
|
750
|
+
}
|
|
751
|
+
return value instanceof Element || value instanceof getWindow(value).Element;
|
|
752
|
+
}
|
|
753
|
+
function isHTMLElement(value) {
|
|
754
|
+
if (!hasWindow()) {
|
|
755
|
+
return false;
|
|
756
|
+
}
|
|
757
|
+
return value instanceof HTMLElement || value instanceof getWindow(value).HTMLElement;
|
|
758
|
+
}
|
|
759
|
+
function isShadowRoot(value) {
|
|
760
|
+
if (!hasWindow() || typeof ShadowRoot === 'undefined') {
|
|
761
|
+
return false;
|
|
762
|
+
}
|
|
763
|
+
return value instanceof ShadowRoot || value instanceof getWindow(value).ShadowRoot;
|
|
764
|
+
}
|
|
765
|
+
function isOverflowElement(element) {
|
|
766
|
+
const {
|
|
767
|
+
overflow,
|
|
768
|
+
overflowX,
|
|
769
|
+
overflowY,
|
|
770
|
+
display
|
|
771
|
+
} = getComputedStyle$1(element);
|
|
772
|
+
return /auto|scroll|overlay|hidden|clip/.test(overflow + overflowY + overflowX) && !['inline', 'contents'].includes(display);
|
|
773
|
+
}
|
|
774
|
+
function isTableElement(element) {
|
|
775
|
+
return ['table', 'td', 'th'].includes(getNodeName(element));
|
|
776
|
+
}
|
|
777
|
+
function isTopLayer$1(element) {
|
|
778
|
+
return [':popover-open', ':modal'].some(selector => {
|
|
779
|
+
try {
|
|
780
|
+
return element.matches(selector);
|
|
781
|
+
} catch (e) {
|
|
782
|
+
return false;
|
|
783
|
+
}
|
|
784
|
+
});
|
|
785
|
+
}
|
|
786
|
+
function isContainingBlock(elementOrCss) {
|
|
787
|
+
const webkit = isWebKit();
|
|
788
|
+
const css = isElement(elementOrCss) ? getComputedStyle$1(elementOrCss) : elementOrCss;
|
|
789
|
+
|
|
790
|
+
// https://developer.mozilla.org/en-US/docs/Web/CSS/Containing_block#identifying_the_containing_block
|
|
791
|
+
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));
|
|
792
|
+
}
|
|
793
|
+
function getContainingBlock(element) {
|
|
794
|
+
let currentNode = getParentNode(element);
|
|
795
|
+
while (isHTMLElement(currentNode) && !isLastTraversableNode(currentNode)) {
|
|
796
|
+
if (isContainingBlock(currentNode)) {
|
|
797
|
+
return currentNode;
|
|
798
|
+
} else if (isTopLayer$1(currentNode)) {
|
|
799
|
+
return null;
|
|
800
|
+
}
|
|
801
|
+
currentNode = getParentNode(currentNode);
|
|
802
|
+
}
|
|
803
|
+
return null;
|
|
804
|
+
}
|
|
805
|
+
function isWebKit() {
|
|
806
|
+
if (typeof CSS === 'undefined' || !CSS.supports) return false;
|
|
807
|
+
return CSS.supports('-webkit-backdrop-filter', 'none');
|
|
808
|
+
}
|
|
809
|
+
function isLastTraversableNode(node) {
|
|
810
|
+
return ['html', 'body', '#document'].includes(getNodeName(node));
|
|
811
|
+
}
|
|
812
|
+
function getComputedStyle$1(element) {
|
|
813
|
+
return getWindow(element).getComputedStyle(element);
|
|
814
|
+
}
|
|
815
|
+
function getNodeScroll(element) {
|
|
816
|
+
if (isElement(element)) {
|
|
817
|
+
return {
|
|
818
|
+
scrollLeft: element.scrollLeft,
|
|
819
|
+
scrollTop: element.scrollTop
|
|
820
|
+
};
|
|
821
|
+
}
|
|
822
|
+
return {
|
|
823
|
+
scrollLeft: element.scrollX,
|
|
824
|
+
scrollTop: element.scrollY
|
|
825
|
+
};
|
|
826
|
+
}
|
|
827
|
+
function getParentNode(node) {
|
|
828
|
+
if (getNodeName(node) === 'html') {
|
|
829
|
+
return node;
|
|
830
|
+
}
|
|
831
|
+
const result =
|
|
832
|
+
// Step into the shadow DOM of the parent of a slotted node.
|
|
833
|
+
node.assignedSlot ||
|
|
834
|
+
// DOM Element detected.
|
|
835
|
+
node.parentNode ||
|
|
836
|
+
// ShadowRoot detected.
|
|
837
|
+
isShadowRoot(node) && node.host ||
|
|
838
|
+
// Fallback.
|
|
839
|
+
getDocumentElement(node);
|
|
840
|
+
return isShadowRoot(result) ? result.host : result;
|
|
841
|
+
}
|
|
842
|
+
function getNearestOverflowAncestor(node) {
|
|
843
|
+
const parentNode = getParentNode(node);
|
|
844
|
+
if (isLastTraversableNode(parentNode)) {
|
|
845
|
+
return node.ownerDocument ? node.ownerDocument.body : node.body;
|
|
846
|
+
}
|
|
847
|
+
if (isHTMLElement(parentNode) && isOverflowElement(parentNode)) {
|
|
848
|
+
return parentNode;
|
|
849
|
+
}
|
|
850
|
+
return getNearestOverflowAncestor(parentNode);
|
|
851
|
+
}
|
|
852
|
+
function getOverflowAncestors(node, list, traverseIframes) {
|
|
853
|
+
var _node$ownerDocument2;
|
|
854
|
+
if (list === void 0) {
|
|
855
|
+
list = [];
|
|
856
|
+
}
|
|
857
|
+
if (traverseIframes === void 0) {
|
|
858
|
+
traverseIframes = true;
|
|
859
|
+
}
|
|
860
|
+
const scrollableAncestor = getNearestOverflowAncestor(node);
|
|
861
|
+
const isBody = scrollableAncestor === ((_node$ownerDocument2 = node.ownerDocument) == null ? void 0 : _node$ownerDocument2.body);
|
|
862
|
+
const win = getWindow(scrollableAncestor);
|
|
863
|
+
if (isBody) {
|
|
864
|
+
const frameElement = getFrameElement(win);
|
|
865
|
+
return list.concat(win, win.visualViewport || [], isOverflowElement(scrollableAncestor) ? scrollableAncestor : [], frameElement && traverseIframes ? getOverflowAncestors(frameElement) : []);
|
|
866
|
+
}
|
|
867
|
+
return list.concat(scrollableAncestor, getOverflowAncestors(scrollableAncestor, [], traverseIframes));
|
|
868
|
+
}
|
|
869
|
+
function getFrameElement(win) {
|
|
870
|
+
return win.parent && Object.getPrototypeOf(win.parent) ? win.frameElement : null;
|
|
871
|
+
}
|
|
872
|
+
|
|
873
|
+
function activeElement(doc) {
|
|
874
|
+
let activeElement = doc.activeElement;
|
|
875
|
+
while (((_activeElement = activeElement) == null || (_activeElement = _activeElement.shadowRoot) == null ? void 0 : _activeElement.activeElement) != null) {
|
|
876
|
+
var _activeElement;
|
|
877
|
+
activeElement = activeElement.shadowRoot.activeElement;
|
|
878
|
+
}
|
|
879
|
+
return activeElement;
|
|
880
|
+
}
|
|
881
|
+
function contains(parent, child) {
|
|
882
|
+
if (!parent || !child) {
|
|
883
|
+
return false;
|
|
884
|
+
}
|
|
885
|
+
const rootNode = child.getRootNode == null ? void 0 : child.getRootNode();
|
|
886
|
+
|
|
887
|
+
// First, attempt with faster native method
|
|
888
|
+
if (parent.contains(child)) {
|
|
889
|
+
return true;
|
|
890
|
+
}
|
|
891
|
+
|
|
892
|
+
// then fallback to custom implementation with Shadow DOM support
|
|
893
|
+
if (rootNode && isShadowRoot(rootNode)) {
|
|
894
|
+
let next = child;
|
|
895
|
+
while (next) {
|
|
896
|
+
if (parent === next) {
|
|
897
|
+
return true;
|
|
898
|
+
}
|
|
899
|
+
// @ts-ignore
|
|
900
|
+
next = next.parentNode || next.host;
|
|
901
|
+
}
|
|
902
|
+
}
|
|
903
|
+
|
|
904
|
+
// Give up, the result is false
|
|
905
|
+
return false;
|
|
906
|
+
}
|
|
907
|
+
function isSafari() {
|
|
908
|
+
// Chrome DevTools does not complain about navigator.vendor
|
|
909
|
+
return /apple/i.test(navigator.vendor);
|
|
910
|
+
}
|
|
911
|
+
function isMouseLikePointerType(pointerType, strict) {
|
|
912
|
+
// On some Linux machines with Chromium, mouse inputs return a `pointerType`
|
|
913
|
+
// of "pen": https://github.com/floating-ui/floating-ui/issues/2015
|
|
914
|
+
const values = ['mouse', 'pen'];
|
|
915
|
+
if (!strict) {
|
|
916
|
+
values.push('', undefined);
|
|
917
|
+
}
|
|
918
|
+
return values.includes(pointerType);
|
|
919
|
+
}
|
|
920
|
+
function isReactEvent(event) {
|
|
921
|
+
return 'nativeEvent' in event;
|
|
922
|
+
}
|
|
923
|
+
function isRootElement(element) {
|
|
924
|
+
return element.matches('html,body');
|
|
925
|
+
}
|
|
926
|
+
function getDocument(node) {
|
|
927
|
+
return (node == null ? void 0 : node.ownerDocument) || document;
|
|
928
|
+
}
|
|
929
|
+
function isEventTargetWithin(event, node) {
|
|
930
|
+
if (node == null) {
|
|
931
|
+
return false;
|
|
932
|
+
}
|
|
933
|
+
if ('composedPath' in event) {
|
|
934
|
+
return event.composedPath().includes(node);
|
|
935
|
+
}
|
|
936
|
+
|
|
937
|
+
// TS thinks `event` is of type never as it assumes all browsers support composedPath, but browsers without shadow dom don't
|
|
938
|
+
const e = event;
|
|
939
|
+
return e.target != null && node.contains(e.target);
|
|
940
|
+
}
|
|
941
|
+
function getTarget(event) {
|
|
942
|
+
if ('composedPath' in event) {
|
|
943
|
+
return event.composedPath()[0];
|
|
944
|
+
}
|
|
945
|
+
|
|
946
|
+
// TS thinks `event` is of type never as it assumes all browsers support
|
|
947
|
+
// `composedPath()`, but browsers without shadow DOM don't.
|
|
948
|
+
return event.target;
|
|
949
|
+
}
|
|
950
|
+
const TYPEABLE_SELECTOR = "input:not([type='hidden']):not([disabled])," + "[contenteditable]:not([contenteditable='false']),textarea:not([disabled])";
|
|
951
|
+
function isTypeableElement(element) {
|
|
952
|
+
return isHTMLElement(element) && element.matches(TYPEABLE_SELECTOR);
|
|
953
|
+
}
|
|
954
|
+
|
|
955
|
+
/*!
|
|
956
|
+
* tabbable 6.2.0
|
|
957
|
+
* @license MIT, https://github.com/focus-trap/tabbable/blob/master/LICENSE
|
|
958
|
+
*/
|
|
959
|
+
// NOTE: separate `:not()` selectors has broader browser support than the newer
|
|
960
|
+
// `:not([inert], [inert] *)` (Feb 2023)
|
|
961
|
+
// CAREFUL: JSDom does not support `:not([inert] *)` as a selector; using it causes
|
|
962
|
+
// the entire query to fail, resulting in no nodes found, which will break a lot
|
|
963
|
+
// of things... so we have to rely on JS to identify nodes inside an inert container
|
|
964
|
+
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])'];
|
|
965
|
+
var candidateSelector = /* #__PURE__ */candidateSelectors.join(',');
|
|
966
|
+
var NoElement = typeof Element === 'undefined';
|
|
967
|
+
var matches = NoElement ? function () {} : Element.prototype.matches || Element.prototype.msMatchesSelector || Element.prototype.webkitMatchesSelector;
|
|
968
|
+
var getRootNode = !NoElement && Element.prototype.getRootNode ? function (element) {
|
|
969
|
+
var _element$getRootNode;
|
|
970
|
+
return element === null || element === void 0 ? void 0 : (_element$getRootNode = element.getRootNode) === null || _element$getRootNode === void 0 ? void 0 : _element$getRootNode.call(element);
|
|
971
|
+
} : function (element) {
|
|
972
|
+
return element === null || element === void 0 ? void 0 : element.ownerDocument;
|
|
973
|
+
};
|
|
974
|
+
|
|
975
|
+
/**
|
|
976
|
+
* Determines if a node is inert or in an inert ancestor.
|
|
977
|
+
* @param {Element} [node]
|
|
978
|
+
* @param {boolean} [lookUp] If true and `node` is not inert, looks up at ancestors to
|
|
979
|
+
* see if any of them are inert. If false, only `node` itself is considered.
|
|
980
|
+
* @returns {boolean} True if inert itself or by way of being in an inert ancestor.
|
|
981
|
+
* False if `node` is falsy.
|
|
982
|
+
*/
|
|
983
|
+
var isInert = function isInert(node, lookUp) {
|
|
984
|
+
var _node$getAttribute;
|
|
985
|
+
if (lookUp === void 0) {
|
|
986
|
+
lookUp = true;
|
|
987
|
+
}
|
|
988
|
+
// CAREFUL: JSDom does not support inert at all, so we can't use the `HTMLElement.inert`
|
|
989
|
+
// JS API property; we have to check the attribute, which can either be empty or 'true';
|
|
990
|
+
// if it's `null` (not specified) or 'false', it's an active element
|
|
991
|
+
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');
|
|
992
|
+
var inert = inertAtt === '' || inertAtt === 'true';
|
|
993
|
+
|
|
994
|
+
// NOTE: this could also be handled with `node.matches('[inert], :is([inert] *)')`
|
|
995
|
+
// if it weren't for `matches()` not being a function on shadow roots; the following
|
|
996
|
+
// code works for any kind of node
|
|
997
|
+
// CAREFUL: JSDom does not appear to support certain selectors like `:not([inert] *)`
|
|
998
|
+
// so it likely would not support `:is([inert] *)` either...
|
|
999
|
+
var result = inert || lookUp && node && isInert(node.parentNode); // recursive
|
|
1000
|
+
|
|
1001
|
+
return result;
|
|
1002
|
+
};
|
|
1003
|
+
|
|
1004
|
+
/**
|
|
1005
|
+
* Determines if a node's content is editable.
|
|
1006
|
+
* @param {Element} [node]
|
|
1007
|
+
* @returns True if it's content-editable; false if it's not or `node` is falsy.
|
|
1008
|
+
*/
|
|
1009
|
+
var isContentEditable = function isContentEditable(node) {
|
|
1010
|
+
var _node$getAttribute2;
|
|
1011
|
+
// CAREFUL: JSDom does not support the `HTMLElement.isContentEditable` API so we have
|
|
1012
|
+
// to use the attribute directly to check for this, which can either be empty or 'true';
|
|
1013
|
+
// if it's `null` (not specified) or 'false', it's a non-editable element
|
|
1014
|
+
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');
|
|
1015
|
+
return attValue === '' || attValue === 'true';
|
|
1016
|
+
};
|
|
1017
|
+
|
|
1018
|
+
/**
|
|
1019
|
+
* @param {Element} el container to check in
|
|
1020
|
+
* @param {boolean} includeContainer add container to check
|
|
1021
|
+
* @param {(node: Element) => boolean} filter filter candidates
|
|
1022
|
+
* @returns {Element[]}
|
|
1023
|
+
*/
|
|
1024
|
+
var getCandidates = function getCandidates(el, includeContainer, filter) {
|
|
1025
|
+
// even if `includeContainer=false`, we still have to check it for inertness because
|
|
1026
|
+
// if it's inert, all its children are inert
|
|
1027
|
+
if (isInert(el)) {
|
|
1028
|
+
return [];
|
|
1029
|
+
}
|
|
1030
|
+
var candidates = Array.prototype.slice.apply(el.querySelectorAll(candidateSelector));
|
|
1031
|
+
if (includeContainer && matches.call(el, candidateSelector)) {
|
|
1032
|
+
candidates.unshift(el);
|
|
1033
|
+
}
|
|
1034
|
+
candidates = candidates.filter(filter);
|
|
1035
|
+
return candidates;
|
|
1036
|
+
};
|
|
1037
|
+
|
|
1038
|
+
/**
|
|
1039
|
+
* @callback GetShadowRoot
|
|
1040
|
+
* @param {Element} element to check for shadow root
|
|
1041
|
+
* @returns {ShadowRoot|boolean} ShadowRoot if available or boolean indicating if a shadowRoot is attached but not available.
|
|
1042
|
+
*/
|
|
1043
|
+
|
|
1044
|
+
/**
|
|
1045
|
+
* @callback ShadowRootFilter
|
|
1046
|
+
* @param {Element} shadowHostNode the element which contains shadow content
|
|
1047
|
+
* @returns {boolean} true if a shadow root could potentially contain valid candidates.
|
|
1048
|
+
*/
|
|
1049
|
+
|
|
1050
|
+
/**
|
|
1051
|
+
* @typedef {Object} CandidateScope
|
|
1052
|
+
* @property {Element} scopeParent contains inner candidates
|
|
1053
|
+
* @property {Element[]} candidates list of candidates found in the scope parent
|
|
1054
|
+
*/
|
|
1055
|
+
|
|
1056
|
+
/**
|
|
1057
|
+
* @typedef {Object} IterativeOptions
|
|
1058
|
+
* @property {GetShadowRoot|boolean} getShadowRoot true if shadow support is enabled; falsy if not;
|
|
1059
|
+
* if a function, implies shadow support is enabled and either returns the shadow root of an element
|
|
1060
|
+
* or a boolean stating if it has an undisclosed shadow root
|
|
1061
|
+
* @property {(node: Element) => boolean} filter filter candidates
|
|
1062
|
+
* @property {boolean} flatten if true then result will flatten any CandidateScope into the returned list
|
|
1063
|
+
* @property {ShadowRootFilter} shadowRootFilter filter shadow roots;
|
|
1064
|
+
*/
|
|
1065
|
+
|
|
1066
|
+
/**
|
|
1067
|
+
* @param {Element[]} elements list of element containers to match candidates from
|
|
1068
|
+
* @param {boolean} includeContainer add container list to check
|
|
1069
|
+
* @param {IterativeOptions} options
|
|
1070
|
+
* @returns {Array.<Element|CandidateScope>}
|
|
1071
|
+
*/
|
|
1072
|
+
var getCandidatesIteratively = function getCandidatesIteratively(elements, includeContainer, options) {
|
|
1073
|
+
var candidates = [];
|
|
1074
|
+
var elementsToCheck = Array.from(elements);
|
|
1075
|
+
while (elementsToCheck.length) {
|
|
1076
|
+
var element = elementsToCheck.shift();
|
|
1077
|
+
if (isInert(element, false)) {
|
|
1078
|
+
// no need to look up since we're drilling down
|
|
1079
|
+
// anything inside this container will also be inert
|
|
1080
|
+
continue;
|
|
1081
|
+
}
|
|
1082
|
+
if (element.tagName === 'SLOT') {
|
|
1083
|
+
// add shadow dom slot scope (slot itself cannot be focusable)
|
|
1084
|
+
var assigned = element.assignedElements();
|
|
1085
|
+
var content = assigned.length ? assigned : element.children;
|
|
1086
|
+
var nestedCandidates = getCandidatesIteratively(content, true, options);
|
|
1087
|
+
if (options.flatten) {
|
|
1088
|
+
candidates.push.apply(candidates, nestedCandidates);
|
|
1089
|
+
} else {
|
|
1090
|
+
candidates.push({
|
|
1091
|
+
scopeParent: element,
|
|
1092
|
+
candidates: nestedCandidates
|
|
1093
|
+
});
|
|
1094
|
+
}
|
|
1095
|
+
} else {
|
|
1096
|
+
// check candidate element
|
|
1097
|
+
var validCandidate = matches.call(element, candidateSelector);
|
|
1098
|
+
if (validCandidate && options.filter(element) && (includeContainer || !elements.includes(element))) {
|
|
1099
|
+
candidates.push(element);
|
|
1100
|
+
}
|
|
1101
|
+
|
|
1102
|
+
// iterate over shadow content if possible
|
|
1103
|
+
var shadowRoot = element.shadowRoot ||
|
|
1104
|
+
// check for an undisclosed shadow
|
|
1105
|
+
typeof options.getShadowRoot === 'function' && options.getShadowRoot(element);
|
|
1106
|
+
|
|
1107
|
+
// no inert look up because we're already drilling down and checking for inertness
|
|
1108
|
+
// on the way down, so all containers to this root node should have already been
|
|
1109
|
+
// vetted as non-inert
|
|
1110
|
+
var validShadowRoot = !isInert(shadowRoot, false) && (!options.shadowRootFilter || options.shadowRootFilter(element));
|
|
1111
|
+
if (shadowRoot && validShadowRoot) {
|
|
1112
|
+
// add shadow dom scope IIF a shadow root node was given; otherwise, an undisclosed
|
|
1113
|
+
// shadow exists, so look at light dom children as fallback BUT create a scope for any
|
|
1114
|
+
// child candidates found because they're likely slotted elements (elements that are
|
|
1115
|
+
// children of the web component element (which has the shadow), in the light dom, but
|
|
1116
|
+
// slotted somewhere _inside_ the undisclosed shadow) -- the scope is created below,
|
|
1117
|
+
// _after_ we return from this recursive call
|
|
1118
|
+
var _nestedCandidates = getCandidatesIteratively(shadowRoot === true ? element.children : shadowRoot.children, true, options);
|
|
1119
|
+
if (options.flatten) {
|
|
1120
|
+
candidates.push.apply(candidates, _nestedCandidates);
|
|
1121
|
+
} else {
|
|
1122
|
+
candidates.push({
|
|
1123
|
+
scopeParent: element,
|
|
1124
|
+
candidates: _nestedCandidates
|
|
1125
|
+
});
|
|
1126
|
+
}
|
|
1127
|
+
} else {
|
|
1128
|
+
// there's not shadow so just dig into the element's (light dom) children
|
|
1129
|
+
// __without__ giving the element special scope treatment
|
|
1130
|
+
elementsToCheck.unshift.apply(elementsToCheck, element.children);
|
|
1131
|
+
}
|
|
1132
|
+
}
|
|
1133
|
+
}
|
|
1134
|
+
return candidates;
|
|
1135
|
+
};
|
|
1136
|
+
|
|
1137
|
+
/**
|
|
1138
|
+
* @private
|
|
1139
|
+
* Determines if the node has an explicitly specified `tabindex` attribute.
|
|
1140
|
+
* @param {HTMLElement} node
|
|
1141
|
+
* @returns {boolean} True if so; false if not.
|
|
1142
|
+
*/
|
|
1143
|
+
var hasTabIndex = function hasTabIndex(node) {
|
|
1144
|
+
return !isNaN(parseInt(node.getAttribute('tabindex'), 10));
|
|
1145
|
+
};
|
|
1146
|
+
|
|
1147
|
+
/**
|
|
1148
|
+
* Determine the tab index of a given node.
|
|
1149
|
+
* @param {HTMLElement} node
|
|
1150
|
+
* @returns {number} Tab order (negative, 0, or positive number).
|
|
1151
|
+
* @throws {Error} If `node` is falsy.
|
|
1152
|
+
*/
|
|
1153
|
+
var getTabIndex = function getTabIndex(node) {
|
|
1154
|
+
if (!node) {
|
|
1155
|
+
throw new Error('No node provided');
|
|
1156
|
+
}
|
|
1157
|
+
if (node.tabIndex < 0) {
|
|
1158
|
+
// in Chrome, <details/>, <audio controls/> and <video controls/> elements get a default
|
|
1159
|
+
// `tabIndex` of -1 when the 'tabindex' attribute isn't specified in the DOM,
|
|
1160
|
+
// yet they are still part of the regular tab order; in FF, they get a default
|
|
1161
|
+
// `tabIndex` of 0; since Chrome still puts those elements in the regular tab
|
|
1162
|
+
// order, consider their tab index to be 0.
|
|
1163
|
+
// Also browsers do not return `tabIndex` correctly for contentEditable nodes;
|
|
1164
|
+
// so if they don't have a tabindex attribute specifically set, assume it's 0.
|
|
1165
|
+
if ((/^(AUDIO|VIDEO|DETAILS)$/.test(node.tagName) || isContentEditable(node)) && !hasTabIndex(node)) {
|
|
1166
|
+
return 0;
|
|
1167
|
+
}
|
|
1168
|
+
}
|
|
1169
|
+
return node.tabIndex;
|
|
1170
|
+
};
|
|
1171
|
+
|
|
1172
|
+
/**
|
|
1173
|
+
* Determine the tab index of a given node __for sort order purposes__.
|
|
1174
|
+
* @param {HTMLElement} node
|
|
1175
|
+
* @param {boolean} [isScope] True for a custom element with shadow root or slot that, by default,
|
|
1176
|
+
* has tabIndex -1, but needs to be sorted by document order in order for its content to be
|
|
1177
|
+
* inserted into the correct sort position.
|
|
1178
|
+
* @returns {number} Tab order (negative, 0, or positive number).
|
|
1179
|
+
*/
|
|
1180
|
+
var getSortOrderTabIndex = function getSortOrderTabIndex(node, isScope) {
|
|
1181
|
+
var tabIndex = getTabIndex(node);
|
|
1182
|
+
if (tabIndex < 0 && isScope && !hasTabIndex(node)) {
|
|
1183
|
+
return 0;
|
|
1184
|
+
}
|
|
1185
|
+
return tabIndex;
|
|
1186
|
+
};
|
|
1187
|
+
var sortOrderedTabbables = function sortOrderedTabbables(a, b) {
|
|
1188
|
+
return a.tabIndex === b.tabIndex ? a.documentOrder - b.documentOrder : a.tabIndex - b.tabIndex;
|
|
1189
|
+
};
|
|
1190
|
+
var isInput = function isInput(node) {
|
|
1191
|
+
return node.tagName === 'INPUT';
|
|
1192
|
+
};
|
|
1193
|
+
var isHiddenInput = function isHiddenInput(node) {
|
|
1194
|
+
return isInput(node) && node.type === 'hidden';
|
|
1195
|
+
};
|
|
1196
|
+
var isDetailsWithSummary = function isDetailsWithSummary(node) {
|
|
1197
|
+
var r = node.tagName === 'DETAILS' && Array.prototype.slice.apply(node.children).some(function (child) {
|
|
1198
|
+
return child.tagName === 'SUMMARY';
|
|
1199
|
+
});
|
|
1200
|
+
return r;
|
|
1201
|
+
};
|
|
1202
|
+
var getCheckedRadio = function getCheckedRadio(nodes, form) {
|
|
1203
|
+
for (var i = 0; i < nodes.length; i++) {
|
|
1204
|
+
if (nodes[i].checked && nodes[i].form === form) {
|
|
1205
|
+
return nodes[i];
|
|
1206
|
+
}
|
|
1207
|
+
}
|
|
1208
|
+
};
|
|
1209
|
+
var isTabbableRadio = function isTabbableRadio(node) {
|
|
1210
|
+
if (!node.name) {
|
|
1211
|
+
return true;
|
|
1212
|
+
}
|
|
1213
|
+
var radioScope = node.form || getRootNode(node);
|
|
1214
|
+
var queryRadios = function queryRadios(name) {
|
|
1215
|
+
return radioScope.querySelectorAll('input[type="radio"][name="' + name + '"]');
|
|
1216
|
+
};
|
|
1217
|
+
var radioSet;
|
|
1218
|
+
if (typeof window !== 'undefined' && typeof window.CSS !== 'undefined' && typeof window.CSS.escape === 'function') {
|
|
1219
|
+
radioSet = queryRadios(window.CSS.escape(node.name));
|
|
1220
|
+
} else {
|
|
1221
|
+
try {
|
|
1222
|
+
radioSet = queryRadios(node.name);
|
|
1223
|
+
} catch (err) {
|
|
1224
|
+
// eslint-disable-next-line no-console
|
|
1225
|
+
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);
|
|
1226
|
+
return false;
|
|
1227
|
+
}
|
|
1228
|
+
}
|
|
1229
|
+
var checked = getCheckedRadio(radioSet, node.form);
|
|
1230
|
+
return !checked || checked === node;
|
|
1231
|
+
};
|
|
1232
|
+
var isRadio = function isRadio(node) {
|
|
1233
|
+
return isInput(node) && node.type === 'radio';
|
|
1234
|
+
};
|
|
1235
|
+
var isNonTabbableRadio = function isNonTabbableRadio(node) {
|
|
1236
|
+
return isRadio(node) && !isTabbableRadio(node);
|
|
1237
|
+
};
|
|
1238
|
+
|
|
1239
|
+
// determines if a node is ultimately attached to the window's document
|
|
1240
|
+
var isNodeAttached = function isNodeAttached(node) {
|
|
1241
|
+
var _nodeRoot;
|
|
1242
|
+
// The root node is the shadow root if the node is in a shadow DOM; some document otherwise
|
|
1243
|
+
// (but NOT _the_ document; see second 'If' comment below for more).
|
|
1244
|
+
// If rootNode is shadow root, it'll have a host, which is the element to which the shadow
|
|
1245
|
+
// is attached, and the one we need to check if it's in the document or not (because the
|
|
1246
|
+
// shadow, and all nodes it contains, is never considered in the document since shadows
|
|
1247
|
+
// behave like self-contained DOMs; but if the shadow's HOST, which is part of the document,
|
|
1248
|
+
// is hidden, or is not in the document itself but is detached, it will affect the shadow's
|
|
1249
|
+
// visibility, including all the nodes it contains). The host could be any normal node,
|
|
1250
|
+
// or a custom element (i.e. web component). Either way, that's the one that is considered
|
|
1251
|
+
// part of the document, not the shadow root, nor any of its children (i.e. the node being
|
|
1252
|
+
// tested).
|
|
1253
|
+
// To further complicate things, we have to look all the way up until we find a shadow HOST
|
|
1254
|
+
// that is attached (or find none) because the node might be in nested shadows...
|
|
1255
|
+
// If rootNode is not a shadow root, it won't have a host, and so rootNode should be the
|
|
1256
|
+
// document (per the docs) and while it's a Document-type object, that document does not
|
|
1257
|
+
// appear to be the same as the node's `ownerDocument` for some reason, so it's safer
|
|
1258
|
+
// to ignore the rootNode at this point, and use `node.ownerDocument`. Otherwise,
|
|
1259
|
+
// using `rootNode.contains(node)` will _always_ be true we'll get false-positives when
|
|
1260
|
+
// node is actually detached.
|
|
1261
|
+
// NOTE: If `nodeRootHost` or `node` happens to be the `document` itself (which is possible
|
|
1262
|
+
// if a tabbable/focusable node was quickly added to the DOM, focused, and then removed
|
|
1263
|
+
// from the DOM as in https://github.com/focus-trap/focus-trap-react/issues/905), then
|
|
1264
|
+
// `ownerDocument` will be `null`, hence the optional chaining on it.
|
|
1265
|
+
var nodeRoot = node && getRootNode(node);
|
|
1266
|
+
var nodeRootHost = (_nodeRoot = nodeRoot) === null || _nodeRoot === void 0 ? void 0 : _nodeRoot.host;
|
|
1267
|
+
|
|
1268
|
+
// in some cases, a detached node will return itself as the root instead of a document or
|
|
1269
|
+
// shadow root object, in which case, we shouldn't try to look further up the host chain
|
|
1270
|
+
var attached = false;
|
|
1271
|
+
if (nodeRoot && nodeRoot !== node) {
|
|
1272
|
+
var _nodeRootHost, _nodeRootHost$ownerDo, _node$ownerDocument;
|
|
1273
|
+
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));
|
|
1274
|
+
while (!attached && nodeRootHost) {
|
|
1275
|
+
var _nodeRoot2, _nodeRootHost2, _nodeRootHost2$ownerD;
|
|
1276
|
+
// since it's not attached and we have a root host, the node MUST be in a nested shadow DOM,
|
|
1277
|
+
// which means we need to get the host's host and check if that parent host is contained
|
|
1278
|
+
// in (i.e. attached to) the document
|
|
1279
|
+
nodeRoot = getRootNode(nodeRootHost);
|
|
1280
|
+
nodeRootHost = (_nodeRoot2 = nodeRoot) === null || _nodeRoot2 === void 0 ? void 0 : _nodeRoot2.host;
|
|
1281
|
+
attached = !!((_nodeRootHost2 = nodeRootHost) !== null && _nodeRootHost2 !== void 0 && (_nodeRootHost2$ownerD = _nodeRootHost2.ownerDocument) !== null && _nodeRootHost2$ownerD !== void 0 && _nodeRootHost2$ownerD.contains(nodeRootHost));
|
|
1282
|
+
}
|
|
1283
|
+
}
|
|
1284
|
+
return attached;
|
|
1285
|
+
};
|
|
1286
|
+
var isZeroArea = function isZeroArea(node) {
|
|
1287
|
+
var _node$getBoundingClie = node.getBoundingClientRect(),
|
|
1288
|
+
width = _node$getBoundingClie.width,
|
|
1289
|
+
height = _node$getBoundingClie.height;
|
|
1290
|
+
return width === 0 && height === 0;
|
|
1291
|
+
};
|
|
1292
|
+
var isHidden = function isHidden(node, _ref) {
|
|
1293
|
+
var displayCheck = _ref.displayCheck,
|
|
1294
|
+
getShadowRoot = _ref.getShadowRoot;
|
|
1295
|
+
// NOTE: visibility will be `undefined` if node is detached from the document
|
|
1296
|
+
// (see notes about this further down), which means we will consider it visible
|
|
1297
|
+
// (this is legacy behavior from a very long way back)
|
|
1298
|
+
// NOTE: we check this regardless of `displayCheck="none"` because this is a
|
|
1299
|
+
// _visibility_ check, not a _display_ check
|
|
1300
|
+
if (getComputedStyle(node).visibility === 'hidden') {
|
|
1301
|
+
return true;
|
|
1302
|
+
}
|
|
1303
|
+
var isDirectSummary = matches.call(node, 'details>summary:first-of-type');
|
|
1304
|
+
var nodeUnderDetails = isDirectSummary ? node.parentElement : node;
|
|
1305
|
+
if (matches.call(nodeUnderDetails, 'details:not([open]) *')) {
|
|
1306
|
+
return true;
|
|
1307
|
+
}
|
|
1308
|
+
if (!displayCheck || displayCheck === 'full' || displayCheck === 'legacy-full') {
|
|
1309
|
+
if (typeof getShadowRoot === 'function') {
|
|
1310
|
+
// figure out if we should consider the node to be in an undisclosed shadow and use the
|
|
1311
|
+
// 'non-zero-area' fallback
|
|
1312
|
+
var originalNode = node;
|
|
1313
|
+
while (node) {
|
|
1314
|
+
var parentElement = node.parentElement;
|
|
1315
|
+
var rootNode = getRootNode(node);
|
|
1316
|
+
if (parentElement && !parentElement.shadowRoot && getShadowRoot(parentElement) === true // check if there's an undisclosed shadow
|
|
1317
|
+
) {
|
|
1318
|
+
// node has an undisclosed shadow which means we can only treat it as a black box, so we
|
|
1319
|
+
// fall back to a non-zero-area test
|
|
1320
|
+
return isZeroArea(node);
|
|
1321
|
+
} else if (node.assignedSlot) {
|
|
1322
|
+
// iterate up slot
|
|
1323
|
+
node = node.assignedSlot;
|
|
1324
|
+
} else if (!parentElement && rootNode !== node.ownerDocument) {
|
|
1325
|
+
// cross shadow boundary
|
|
1326
|
+
node = rootNode.host;
|
|
1327
|
+
} else {
|
|
1328
|
+
// iterate up normal dom
|
|
1329
|
+
node = parentElement;
|
|
1330
|
+
}
|
|
1331
|
+
}
|
|
1332
|
+
node = originalNode;
|
|
1333
|
+
}
|
|
1334
|
+
// else, `getShadowRoot` might be true, but all that does is enable shadow DOM support
|
|
1335
|
+
// (i.e. it does not also presume that all nodes might have undisclosed shadows); or
|
|
1336
|
+
// it might be a falsy value, which means shadow DOM support is disabled
|
|
1337
|
+
|
|
1338
|
+
// Since we didn't find it sitting in an undisclosed shadow (or shadows are disabled)
|
|
1339
|
+
// now we can just test to see if it would normally be visible or not, provided it's
|
|
1340
|
+
// attached to the main document.
|
|
1341
|
+
// NOTE: We must consider case where node is inside a shadow DOM and given directly to
|
|
1342
|
+
// `isTabbable()` or `isFocusable()` -- regardless of `getShadowRoot` option setting.
|
|
1343
|
+
|
|
1344
|
+
if (isNodeAttached(node)) {
|
|
1345
|
+
// this works wherever the node is: if there's at least one client rect, it's
|
|
1346
|
+
// somehow displayed; it also covers the CSS 'display: contents' case where the
|
|
1347
|
+
// node itself is hidden in place of its contents; and there's no need to search
|
|
1348
|
+
// up the hierarchy either
|
|
1349
|
+
return !node.getClientRects().length;
|
|
1350
|
+
}
|
|
1351
|
+
|
|
1352
|
+
// Else, the node isn't attached to the document, which means the `getClientRects()`
|
|
1353
|
+
// API will __always__ return zero rects (this can happen, for example, if React
|
|
1354
|
+
// is used to render nodes onto a detached tree, as confirmed in this thread:
|
|
1355
|
+
// https://github.com/facebook/react/issues/9117#issuecomment-284228870)
|
|
1356
|
+
//
|
|
1357
|
+
// It also means that even window.getComputedStyle(node).display will return `undefined`
|
|
1358
|
+
// because styles are only computed for nodes that are in the document.
|
|
1359
|
+
//
|
|
1360
|
+
// NOTE: THIS HAS BEEN THE CASE FOR YEARS. It is not new, nor is it caused by tabbable
|
|
1361
|
+
// somehow. Though it was never stated officially, anyone who has ever used tabbable
|
|
1362
|
+
// APIs on nodes in detached containers has actually implicitly used tabbable in what
|
|
1363
|
+
// was later (as of v5.2.0 on Apr 9, 2021) called `displayCheck="none"` mode -- essentially
|
|
1364
|
+
// considering __everything__ to be visible because of the innability to determine styles.
|
|
1365
|
+
//
|
|
1366
|
+
// v6.0.0: As of this major release, the default 'full' option __no longer treats detached
|
|
1367
|
+
// nodes as visible with the 'none' fallback.__
|
|
1368
|
+
if (displayCheck !== 'legacy-full') {
|
|
1369
|
+
return true; // hidden
|
|
1370
|
+
}
|
|
1371
|
+
// else, fallback to 'none' mode and consider the node visible
|
|
1372
|
+
} else if (displayCheck === 'non-zero-area') {
|
|
1373
|
+
// NOTE: Even though this tests that the node's client rect is non-zero to determine
|
|
1374
|
+
// whether it's displayed, and that a detached node will __always__ have a zero-area
|
|
1375
|
+
// client rect, we don't special-case for whether the node is attached or not. In
|
|
1376
|
+
// this mode, we do want to consider nodes that have a zero area to be hidden at all
|
|
1377
|
+
// times, and that includes attached or not.
|
|
1378
|
+
return isZeroArea(node);
|
|
1379
|
+
}
|
|
1380
|
+
|
|
1381
|
+
// visible, as far as we can tell, or per current `displayCheck=none` mode, we assume
|
|
1382
|
+
// it's visible
|
|
1383
|
+
return false;
|
|
1384
|
+
};
|
|
1385
|
+
|
|
1386
|
+
// form fields (nested) inside a disabled fieldset are not focusable/tabbable
|
|
1387
|
+
// unless they are in the _first_ <legend> element of the top-most disabled
|
|
1388
|
+
// fieldset
|
|
1389
|
+
var isDisabledFromFieldset = function isDisabledFromFieldset(node) {
|
|
1390
|
+
if (/^(INPUT|BUTTON|SELECT|TEXTAREA)$/.test(node.tagName)) {
|
|
1391
|
+
var parentNode = node.parentElement;
|
|
1392
|
+
// check if `node` is contained in a disabled <fieldset>
|
|
1393
|
+
while (parentNode) {
|
|
1394
|
+
if (parentNode.tagName === 'FIELDSET' && parentNode.disabled) {
|
|
1395
|
+
// look for the first <legend> among the children of the disabled <fieldset>
|
|
1396
|
+
for (var i = 0; i < parentNode.children.length; i++) {
|
|
1397
|
+
var child = parentNode.children.item(i);
|
|
1398
|
+
// when the first <legend> (in document order) is found
|
|
1399
|
+
if (child.tagName === 'LEGEND') {
|
|
1400
|
+
// if its parent <fieldset> is not nested in another disabled <fieldset>,
|
|
1401
|
+
// return whether `node` is a descendant of its first <legend>
|
|
1402
|
+
return matches.call(parentNode, 'fieldset[disabled] *') ? true : !child.contains(node);
|
|
1403
|
+
}
|
|
1404
|
+
}
|
|
1405
|
+
// the disabled <fieldset> containing `node` has no <legend>
|
|
1406
|
+
return true;
|
|
1407
|
+
}
|
|
1408
|
+
parentNode = parentNode.parentElement;
|
|
1409
|
+
}
|
|
1410
|
+
}
|
|
1411
|
+
|
|
1412
|
+
// else, node's tabbable/focusable state should not be affected by a fieldset's
|
|
1413
|
+
// enabled/disabled state
|
|
1414
|
+
return false;
|
|
1415
|
+
};
|
|
1416
|
+
var isNodeMatchingSelectorFocusable = function isNodeMatchingSelectorFocusable(options, node) {
|
|
1417
|
+
if (node.disabled ||
|
|
1418
|
+
// we must do an inert look up to filter out any elements inside an inert ancestor
|
|
1419
|
+
// because we're limited in the type of selectors we can use in JSDom (see related
|
|
1420
|
+
// note related to `candidateSelectors`)
|
|
1421
|
+
isInert(node) || isHiddenInput(node) || isHidden(node, options) ||
|
|
1422
|
+
// For a details element with a summary, the summary element gets the focus
|
|
1423
|
+
isDetailsWithSummary(node) || isDisabledFromFieldset(node)) {
|
|
1424
|
+
return false;
|
|
1425
|
+
}
|
|
1426
|
+
return true;
|
|
1427
|
+
};
|
|
1428
|
+
var isNodeMatchingSelectorTabbable = function isNodeMatchingSelectorTabbable(options, node) {
|
|
1429
|
+
if (isNonTabbableRadio(node) || getTabIndex(node) < 0 || !isNodeMatchingSelectorFocusable(options, node)) {
|
|
1430
|
+
return false;
|
|
1431
|
+
}
|
|
1432
|
+
return true;
|
|
1433
|
+
};
|
|
1434
|
+
var isValidShadowRootTabbable = function isValidShadowRootTabbable(shadowHostNode) {
|
|
1435
|
+
var tabIndex = parseInt(shadowHostNode.getAttribute('tabindex'), 10);
|
|
1436
|
+
if (isNaN(tabIndex) || tabIndex >= 0) {
|
|
1437
|
+
return true;
|
|
1438
|
+
}
|
|
1439
|
+
// If a custom element has an explicit negative tabindex,
|
|
1440
|
+
// browsers will not allow tab targeting said element's children.
|
|
1441
|
+
return false;
|
|
1442
|
+
};
|
|
1443
|
+
|
|
1444
|
+
/**
|
|
1445
|
+
* @param {Array.<Element|CandidateScope>} candidates
|
|
1446
|
+
* @returns Element[]
|
|
1447
|
+
*/
|
|
1448
|
+
var sortByOrder = function sortByOrder(candidates) {
|
|
1449
|
+
var regularTabbables = [];
|
|
1450
|
+
var orderedTabbables = [];
|
|
1451
|
+
candidates.forEach(function (item, i) {
|
|
1452
|
+
var isScope = !!item.scopeParent;
|
|
1453
|
+
var element = isScope ? item.scopeParent : item;
|
|
1454
|
+
var candidateTabindex = getSortOrderTabIndex(element, isScope);
|
|
1455
|
+
var elements = isScope ? sortByOrder(item.candidates) : element;
|
|
1456
|
+
if (candidateTabindex === 0) {
|
|
1457
|
+
isScope ? regularTabbables.push.apply(regularTabbables, elements) : regularTabbables.push(element);
|
|
1458
|
+
} else {
|
|
1459
|
+
orderedTabbables.push({
|
|
1460
|
+
documentOrder: i,
|
|
1461
|
+
tabIndex: candidateTabindex,
|
|
1462
|
+
item: item,
|
|
1463
|
+
isScope: isScope,
|
|
1464
|
+
content: elements
|
|
1465
|
+
});
|
|
1466
|
+
}
|
|
1467
|
+
});
|
|
1468
|
+
return orderedTabbables.sort(sortOrderedTabbables).reduce(function (acc, sortable) {
|
|
1469
|
+
sortable.isScope ? acc.push.apply(acc, sortable.content) : acc.push(sortable.content);
|
|
1470
|
+
return acc;
|
|
1471
|
+
}, []).concat(regularTabbables);
|
|
1472
|
+
};
|
|
1473
|
+
var tabbable = function tabbable(container, options) {
|
|
1474
|
+
options = options || {};
|
|
1475
|
+
var candidates;
|
|
1476
|
+
if (options.getShadowRoot) {
|
|
1477
|
+
candidates = getCandidatesIteratively([container], options.includeContainer, {
|
|
1478
|
+
filter: isNodeMatchingSelectorTabbable.bind(null, options),
|
|
1479
|
+
flatten: false,
|
|
1480
|
+
getShadowRoot: options.getShadowRoot,
|
|
1481
|
+
shadowRootFilter: isValidShadowRootTabbable
|
|
1482
|
+
});
|
|
1483
|
+
} else {
|
|
1484
|
+
candidates = getCandidates(container, options.includeContainer, isNodeMatchingSelectorTabbable.bind(null, options));
|
|
1485
|
+
}
|
|
1486
|
+
return sortByOrder(candidates);
|
|
1487
|
+
};
|
|
1488
|
+
|
|
1489
|
+
function getCssDimensions(element) {
|
|
1490
|
+
const css = getComputedStyle$1(element);
|
|
1491
|
+
// In testing environments, the `width` and `height` properties are empty
|
|
1492
|
+
// strings for SVG elements, returning NaN. Fallback to `0` in this case.
|
|
1493
|
+
let width = parseFloat(css.width) || 0;
|
|
1494
|
+
let height = parseFloat(css.height) || 0;
|
|
1495
|
+
const hasOffset = isHTMLElement(element);
|
|
1496
|
+
const offsetWidth = hasOffset ? element.offsetWidth : width;
|
|
1497
|
+
const offsetHeight = hasOffset ? element.offsetHeight : height;
|
|
1498
|
+
const shouldFallback = round(width) !== offsetWidth || round(height) !== offsetHeight;
|
|
1499
|
+
if (shouldFallback) {
|
|
1500
|
+
width = offsetWidth;
|
|
1501
|
+
height = offsetHeight;
|
|
1502
|
+
}
|
|
1503
|
+
return {
|
|
1504
|
+
width,
|
|
1505
|
+
height,
|
|
1506
|
+
$: shouldFallback
|
|
1507
|
+
};
|
|
1508
|
+
}
|
|
1509
|
+
|
|
1510
|
+
function unwrapElement(element) {
|
|
1511
|
+
return !isElement(element) ? element.contextElement : element;
|
|
1512
|
+
}
|
|
1513
|
+
|
|
1514
|
+
function getScale(element) {
|
|
1515
|
+
const domElement = unwrapElement(element);
|
|
1516
|
+
if (!isHTMLElement(domElement)) {
|
|
1517
|
+
return createCoords(1);
|
|
1518
|
+
}
|
|
1519
|
+
const rect = domElement.getBoundingClientRect();
|
|
1520
|
+
const {
|
|
1521
|
+
width,
|
|
1522
|
+
height,
|
|
1523
|
+
$
|
|
1524
|
+
} = getCssDimensions(domElement);
|
|
1525
|
+
let x = ($ ? round(rect.width) : rect.width) / width;
|
|
1526
|
+
let y = ($ ? round(rect.height) : rect.height) / height;
|
|
1527
|
+
|
|
1528
|
+
// 0, NaN, or Infinity should always fallback to 1.
|
|
1529
|
+
|
|
1530
|
+
if (!x || !Number.isFinite(x)) {
|
|
1531
|
+
x = 1;
|
|
1532
|
+
}
|
|
1533
|
+
if (!y || !Number.isFinite(y)) {
|
|
1534
|
+
y = 1;
|
|
1535
|
+
}
|
|
1536
|
+
return {
|
|
1537
|
+
x,
|
|
1538
|
+
y
|
|
1539
|
+
};
|
|
1540
|
+
}
|
|
1541
|
+
|
|
1542
|
+
const noOffsets = /*#__PURE__*/createCoords(0);
|
|
1543
|
+
function getVisualOffsets(element) {
|
|
1544
|
+
const win = getWindow(element);
|
|
1545
|
+
if (!isWebKit() || !win.visualViewport) {
|
|
1546
|
+
return noOffsets;
|
|
1547
|
+
}
|
|
1548
|
+
return {
|
|
1549
|
+
x: win.visualViewport.offsetLeft,
|
|
1550
|
+
y: win.visualViewport.offsetTop
|
|
1551
|
+
};
|
|
1552
|
+
}
|
|
1553
|
+
function shouldAddVisualOffsets(element, isFixed, floatingOffsetParent) {
|
|
1554
|
+
if (isFixed === void 0) {
|
|
1555
|
+
isFixed = false;
|
|
1556
|
+
}
|
|
1557
|
+
if (!floatingOffsetParent || isFixed && floatingOffsetParent !== getWindow(element)) {
|
|
1558
|
+
return false;
|
|
1559
|
+
}
|
|
1560
|
+
return isFixed;
|
|
1561
|
+
}
|
|
1562
|
+
|
|
1563
|
+
function getBoundingClientRect(element, includeScale, isFixedStrategy, offsetParent) {
|
|
1564
|
+
if (includeScale === void 0) {
|
|
1565
|
+
includeScale = false;
|
|
1566
|
+
}
|
|
1567
|
+
if (isFixedStrategy === void 0) {
|
|
1568
|
+
isFixedStrategy = false;
|
|
1569
|
+
}
|
|
1570
|
+
const clientRect = element.getBoundingClientRect();
|
|
1571
|
+
const domElement = unwrapElement(element);
|
|
1572
|
+
let scale = createCoords(1);
|
|
1573
|
+
if (includeScale) {
|
|
1574
|
+
if (offsetParent) {
|
|
1575
|
+
if (isElement(offsetParent)) {
|
|
1576
|
+
scale = getScale(offsetParent);
|
|
1577
|
+
}
|
|
1578
|
+
} else {
|
|
1579
|
+
scale = getScale(element);
|
|
1580
|
+
}
|
|
1581
|
+
}
|
|
1582
|
+
const visualOffsets = shouldAddVisualOffsets(domElement, isFixedStrategy, offsetParent) ? getVisualOffsets(domElement) : createCoords(0);
|
|
1583
|
+
let x = (clientRect.left + visualOffsets.x) / scale.x;
|
|
1584
|
+
let y = (clientRect.top + visualOffsets.y) / scale.y;
|
|
1585
|
+
let width = clientRect.width / scale.x;
|
|
1586
|
+
let height = clientRect.height / scale.y;
|
|
1587
|
+
if (domElement) {
|
|
1588
|
+
const win = getWindow(domElement);
|
|
1589
|
+
const offsetWin = offsetParent && isElement(offsetParent) ? getWindow(offsetParent) : offsetParent;
|
|
1590
|
+
let currentWin = win;
|
|
1591
|
+
let currentIFrame = currentWin.frameElement;
|
|
1592
|
+
while (currentIFrame && offsetParent && offsetWin !== currentWin) {
|
|
1593
|
+
const iframeScale = getScale(currentIFrame);
|
|
1594
|
+
const iframeRect = currentIFrame.getBoundingClientRect();
|
|
1595
|
+
const css = getComputedStyle$1(currentIFrame);
|
|
1596
|
+
const left = iframeRect.left + (currentIFrame.clientLeft + parseFloat(css.paddingLeft)) * iframeScale.x;
|
|
1597
|
+
const top = iframeRect.top + (currentIFrame.clientTop + parseFloat(css.paddingTop)) * iframeScale.y;
|
|
1598
|
+
x *= iframeScale.x;
|
|
1599
|
+
y *= iframeScale.y;
|
|
1600
|
+
width *= iframeScale.x;
|
|
1601
|
+
height *= iframeScale.y;
|
|
1602
|
+
x += left;
|
|
1603
|
+
y += top;
|
|
1604
|
+
currentWin = getWindow(currentIFrame);
|
|
1605
|
+
currentIFrame = currentWin.frameElement;
|
|
1606
|
+
}
|
|
1607
|
+
}
|
|
1608
|
+
return rectToClientRect({
|
|
1609
|
+
width,
|
|
1610
|
+
height,
|
|
1611
|
+
x,
|
|
1612
|
+
y
|
|
1613
|
+
});
|
|
1614
|
+
}
|
|
1615
|
+
|
|
1616
|
+
const topLayerSelectors = [':popover-open', ':modal'];
|
|
1617
|
+
function isTopLayer(element) {
|
|
1618
|
+
return topLayerSelectors.some(selector => {
|
|
1619
|
+
try {
|
|
1620
|
+
return element.matches(selector);
|
|
1621
|
+
} catch (e) {
|
|
1622
|
+
return false;
|
|
1623
|
+
}
|
|
1624
|
+
});
|
|
1625
|
+
}
|
|
1626
|
+
|
|
1627
|
+
function convertOffsetParentRelativeRectToViewportRelativeRect(_ref) {
|
|
1628
|
+
let {
|
|
1629
|
+
elements,
|
|
1630
|
+
rect,
|
|
1631
|
+
offsetParent,
|
|
1632
|
+
strategy
|
|
1633
|
+
} = _ref;
|
|
1634
|
+
const isFixed = strategy === 'fixed';
|
|
1635
|
+
const documentElement = getDocumentElement(offsetParent);
|
|
1636
|
+
const topLayer = elements ? isTopLayer(elements.floating) : false;
|
|
1637
|
+
if (offsetParent === documentElement || topLayer && isFixed) {
|
|
1638
|
+
return rect;
|
|
1639
|
+
}
|
|
1640
|
+
let scroll = {
|
|
1641
|
+
scrollLeft: 0,
|
|
1642
|
+
scrollTop: 0
|
|
1643
|
+
};
|
|
1644
|
+
let scale = createCoords(1);
|
|
1645
|
+
const offsets = createCoords(0);
|
|
1646
|
+
const isOffsetParentAnElement = isHTMLElement(offsetParent);
|
|
1647
|
+
if (isOffsetParentAnElement || !isOffsetParentAnElement && !isFixed) {
|
|
1648
|
+
if (getNodeName(offsetParent) !== 'body' || isOverflowElement(documentElement)) {
|
|
1649
|
+
scroll = getNodeScroll(offsetParent);
|
|
1650
|
+
}
|
|
1651
|
+
if (isHTMLElement(offsetParent)) {
|
|
1652
|
+
const offsetRect = getBoundingClientRect(offsetParent);
|
|
1653
|
+
scale = getScale(offsetParent);
|
|
1654
|
+
offsets.x = offsetRect.x + offsetParent.clientLeft;
|
|
1655
|
+
offsets.y = offsetRect.y + offsetParent.clientTop;
|
|
1656
|
+
}
|
|
1657
|
+
}
|
|
1658
|
+
return {
|
|
1659
|
+
width: rect.width * scale.x,
|
|
1660
|
+
height: rect.height * scale.y,
|
|
1661
|
+
x: rect.x * scale.x - scroll.scrollLeft * scale.x + offsets.x,
|
|
1662
|
+
y: rect.y * scale.y - scroll.scrollTop * scale.y + offsets.y
|
|
1663
|
+
};
|
|
1664
|
+
}
|
|
1665
|
+
|
|
1666
|
+
function getClientRects(element) {
|
|
1667
|
+
return Array.from(element.getClientRects());
|
|
1668
|
+
}
|
|
1669
|
+
|
|
1670
|
+
function getWindowScrollBarX(element) {
|
|
1671
|
+
// If <html> has a CSS width greater than the viewport, then this will be
|
|
1672
|
+
// incorrect for RTL.
|
|
1673
|
+
return getBoundingClientRect(getDocumentElement(element)).left + getNodeScroll(element).scrollLeft;
|
|
1674
|
+
}
|
|
1675
|
+
|
|
1676
|
+
// Gets the entire size of the scrollable document area, even extending outside
|
|
1677
|
+
// of the `<html>` and `<body>` rect bounds if horizontally scrollable.
|
|
1678
|
+
function getDocumentRect(element) {
|
|
1679
|
+
const html = getDocumentElement(element);
|
|
1680
|
+
const scroll = getNodeScroll(element);
|
|
1681
|
+
const body = element.ownerDocument.body;
|
|
1682
|
+
const width = max(html.scrollWidth, html.clientWidth, body.scrollWidth, body.clientWidth);
|
|
1683
|
+
const height = max(html.scrollHeight, html.clientHeight, body.scrollHeight, body.clientHeight);
|
|
1684
|
+
let x = -scroll.scrollLeft + getWindowScrollBarX(element);
|
|
1685
|
+
const y = -scroll.scrollTop;
|
|
1686
|
+
if (getComputedStyle$1(body).direction === 'rtl') {
|
|
1687
|
+
x += max(html.clientWidth, body.clientWidth) - width;
|
|
1688
|
+
}
|
|
1689
|
+
return {
|
|
1690
|
+
width,
|
|
1691
|
+
height,
|
|
1692
|
+
x,
|
|
1693
|
+
y
|
|
1694
|
+
};
|
|
1695
|
+
}
|
|
1696
|
+
|
|
1697
|
+
function getViewportRect(element, strategy) {
|
|
1698
|
+
const win = getWindow(element);
|
|
1699
|
+
const html = getDocumentElement(element);
|
|
1700
|
+
const visualViewport = win.visualViewport;
|
|
1701
|
+
let width = html.clientWidth;
|
|
1702
|
+
let height = html.clientHeight;
|
|
1703
|
+
let x = 0;
|
|
1704
|
+
let y = 0;
|
|
1705
|
+
if (visualViewport) {
|
|
1706
|
+
width = visualViewport.width;
|
|
1707
|
+
height = visualViewport.height;
|
|
1708
|
+
const visualViewportBased = isWebKit();
|
|
1709
|
+
if (!visualViewportBased || visualViewportBased && strategy === 'fixed') {
|
|
1710
|
+
x = visualViewport.offsetLeft;
|
|
1711
|
+
y = visualViewport.offsetTop;
|
|
1712
|
+
}
|
|
1713
|
+
}
|
|
1714
|
+
return {
|
|
1715
|
+
width,
|
|
1716
|
+
height,
|
|
1717
|
+
x,
|
|
1718
|
+
y
|
|
1719
|
+
};
|
|
1720
|
+
}
|
|
1721
|
+
|
|
1722
|
+
// Returns the inner client rect, subtracting scrollbars if present.
|
|
1723
|
+
function getInnerBoundingClientRect(element, strategy) {
|
|
1724
|
+
const clientRect = getBoundingClientRect(element, true, strategy === 'fixed');
|
|
1725
|
+
const top = clientRect.top + element.clientTop;
|
|
1726
|
+
const left = clientRect.left + element.clientLeft;
|
|
1727
|
+
const scale = isHTMLElement(element) ? getScale(element) : createCoords(1);
|
|
1728
|
+
const width = element.clientWidth * scale.x;
|
|
1729
|
+
const height = element.clientHeight * scale.y;
|
|
1730
|
+
const x = left * scale.x;
|
|
1731
|
+
const y = top * scale.y;
|
|
1732
|
+
return {
|
|
1733
|
+
width,
|
|
1734
|
+
height,
|
|
1735
|
+
x,
|
|
1736
|
+
y
|
|
1737
|
+
};
|
|
1738
|
+
}
|
|
1739
|
+
function getClientRectFromClippingAncestor(element, clippingAncestor, strategy) {
|
|
1740
|
+
let rect;
|
|
1741
|
+
if (clippingAncestor === 'viewport') {
|
|
1742
|
+
rect = getViewportRect(element, strategy);
|
|
1743
|
+
} else if (clippingAncestor === 'document') {
|
|
1744
|
+
rect = getDocumentRect(getDocumentElement(element));
|
|
1745
|
+
} else if (isElement(clippingAncestor)) {
|
|
1746
|
+
rect = getInnerBoundingClientRect(clippingAncestor, strategy);
|
|
1747
|
+
} else {
|
|
1748
|
+
const visualOffsets = getVisualOffsets(element);
|
|
1749
|
+
rect = {
|
|
1750
|
+
...clippingAncestor,
|
|
1751
|
+
x: clippingAncestor.x - visualOffsets.x,
|
|
1752
|
+
y: clippingAncestor.y - visualOffsets.y
|
|
1753
|
+
};
|
|
1754
|
+
}
|
|
1755
|
+
return rectToClientRect(rect);
|
|
1756
|
+
}
|
|
1757
|
+
function hasFixedPositionAncestor(element, stopNode) {
|
|
1758
|
+
const parentNode = getParentNode(element);
|
|
1759
|
+
if (parentNode === stopNode || !isElement(parentNode) || isLastTraversableNode(parentNode)) {
|
|
1760
|
+
return false;
|
|
1761
|
+
}
|
|
1762
|
+
return getComputedStyle$1(parentNode).position === 'fixed' || hasFixedPositionAncestor(parentNode, stopNode);
|
|
1763
|
+
}
|
|
1764
|
+
|
|
1765
|
+
// A "clipping ancestor" is an `overflow` element with the characteristic of
|
|
1766
|
+
// clipping (or hiding) child elements. This returns all clipping ancestors
|
|
1767
|
+
// of the given element up the tree.
|
|
1768
|
+
function getClippingElementAncestors(element, cache) {
|
|
1769
|
+
const cachedResult = cache.get(element);
|
|
1770
|
+
if (cachedResult) {
|
|
1771
|
+
return cachedResult;
|
|
1772
|
+
}
|
|
1773
|
+
let result = getOverflowAncestors(element, [], false).filter(el => isElement(el) && getNodeName(el) !== 'body');
|
|
1774
|
+
let currentContainingBlockComputedStyle = null;
|
|
1775
|
+
const elementIsFixed = getComputedStyle$1(element).position === 'fixed';
|
|
1776
|
+
let currentNode = elementIsFixed ? getParentNode(element) : element;
|
|
1777
|
+
|
|
1778
|
+
// https://developer.mozilla.org/en-US/docs/Web/CSS/Containing_block#identifying_the_containing_block
|
|
1779
|
+
while (isElement(currentNode) && !isLastTraversableNode(currentNode)) {
|
|
1780
|
+
const computedStyle = getComputedStyle$1(currentNode);
|
|
1781
|
+
const currentNodeIsContaining = isContainingBlock(currentNode);
|
|
1782
|
+
if (!currentNodeIsContaining && computedStyle.position === 'fixed') {
|
|
1783
|
+
currentContainingBlockComputedStyle = null;
|
|
1784
|
+
}
|
|
1785
|
+
const shouldDropCurrentNode = elementIsFixed ? !currentNodeIsContaining && !currentContainingBlockComputedStyle : !currentNodeIsContaining && computedStyle.position === 'static' && !!currentContainingBlockComputedStyle && ['absolute', 'fixed'].includes(currentContainingBlockComputedStyle.position) || isOverflowElement(currentNode) && !currentNodeIsContaining && hasFixedPositionAncestor(element, currentNode);
|
|
1786
|
+
if (shouldDropCurrentNode) {
|
|
1787
|
+
// Drop non-containing blocks.
|
|
1788
|
+
result = result.filter(ancestor => ancestor !== currentNode);
|
|
1789
|
+
} else {
|
|
1790
|
+
// Record last containing block for next iteration.
|
|
1791
|
+
currentContainingBlockComputedStyle = computedStyle;
|
|
1792
|
+
}
|
|
1793
|
+
currentNode = getParentNode(currentNode);
|
|
1794
|
+
}
|
|
1795
|
+
cache.set(element, result);
|
|
1796
|
+
return result;
|
|
1797
|
+
}
|
|
1798
|
+
|
|
1799
|
+
// Gets the maximum area that the element is visible in due to any number of
|
|
1800
|
+
// clipping ancestors.
|
|
1801
|
+
function getClippingRect(_ref) {
|
|
1802
|
+
let {
|
|
1803
|
+
element,
|
|
1804
|
+
boundary,
|
|
1805
|
+
rootBoundary,
|
|
1806
|
+
strategy
|
|
1807
|
+
} = _ref;
|
|
1808
|
+
const elementClippingAncestors = boundary === 'clippingAncestors' ? isTopLayer(element) ? [] : getClippingElementAncestors(element, this._c) : [].concat(boundary);
|
|
1809
|
+
const clippingAncestors = [...elementClippingAncestors, rootBoundary];
|
|
1810
|
+
const firstClippingAncestor = clippingAncestors[0];
|
|
1811
|
+
const clippingRect = clippingAncestors.reduce((accRect, clippingAncestor) => {
|
|
1812
|
+
const rect = getClientRectFromClippingAncestor(element, clippingAncestor, strategy);
|
|
1813
|
+
accRect.top = max(rect.top, accRect.top);
|
|
1814
|
+
accRect.right = min(rect.right, accRect.right);
|
|
1815
|
+
accRect.bottom = min(rect.bottom, accRect.bottom);
|
|
1816
|
+
accRect.left = max(rect.left, accRect.left);
|
|
1817
|
+
return accRect;
|
|
1818
|
+
}, getClientRectFromClippingAncestor(element, firstClippingAncestor, strategy));
|
|
1819
|
+
return {
|
|
1820
|
+
width: clippingRect.right - clippingRect.left,
|
|
1821
|
+
height: clippingRect.bottom - clippingRect.top,
|
|
1822
|
+
x: clippingRect.left,
|
|
1823
|
+
y: clippingRect.top
|
|
1824
|
+
};
|
|
1825
|
+
}
|
|
1826
|
+
|
|
1827
|
+
function getDimensions(element) {
|
|
1828
|
+
const {
|
|
1829
|
+
width,
|
|
1830
|
+
height
|
|
1831
|
+
} = getCssDimensions(element);
|
|
1832
|
+
return {
|
|
1833
|
+
width,
|
|
1834
|
+
height
|
|
1835
|
+
};
|
|
1836
|
+
}
|
|
1837
|
+
|
|
1838
|
+
function getRectRelativeToOffsetParent(element, offsetParent, strategy) {
|
|
1839
|
+
const isOffsetParentAnElement = isHTMLElement(offsetParent);
|
|
1840
|
+
const documentElement = getDocumentElement(offsetParent);
|
|
1841
|
+
const isFixed = strategy === 'fixed';
|
|
1842
|
+
const rect = getBoundingClientRect(element, true, isFixed, offsetParent);
|
|
1843
|
+
let scroll = {
|
|
1844
|
+
scrollLeft: 0,
|
|
1845
|
+
scrollTop: 0
|
|
1846
|
+
};
|
|
1847
|
+
const offsets = createCoords(0);
|
|
1848
|
+
if (isOffsetParentAnElement || !isOffsetParentAnElement && !isFixed) {
|
|
1849
|
+
if (getNodeName(offsetParent) !== 'body' || isOverflowElement(documentElement)) {
|
|
1850
|
+
scroll = getNodeScroll(offsetParent);
|
|
1851
|
+
}
|
|
1852
|
+
if (isOffsetParentAnElement) {
|
|
1853
|
+
const offsetRect = getBoundingClientRect(offsetParent, true, isFixed, offsetParent);
|
|
1854
|
+
offsets.x = offsetRect.x + offsetParent.clientLeft;
|
|
1855
|
+
offsets.y = offsetRect.y + offsetParent.clientTop;
|
|
1856
|
+
} else if (documentElement) {
|
|
1857
|
+
offsets.x = getWindowScrollBarX(documentElement);
|
|
1858
|
+
}
|
|
1859
|
+
}
|
|
1860
|
+
const x = rect.left + scroll.scrollLeft - offsets.x;
|
|
1861
|
+
const y = rect.top + scroll.scrollTop - offsets.y;
|
|
1862
|
+
return {
|
|
1863
|
+
x,
|
|
1864
|
+
y,
|
|
1865
|
+
width: rect.width,
|
|
1866
|
+
height: rect.height
|
|
1867
|
+
};
|
|
1868
|
+
}
|
|
1869
|
+
|
|
1870
|
+
function isStaticPositioned(element) {
|
|
1871
|
+
return getComputedStyle$1(element).position === 'static';
|
|
1872
|
+
}
|
|
1873
|
+
|
|
1874
|
+
function getTrueOffsetParent(element, polyfill) {
|
|
1875
|
+
if (!isHTMLElement(element) || getComputedStyle$1(element).position === 'fixed') {
|
|
1876
|
+
return null;
|
|
1877
|
+
}
|
|
1878
|
+
if (polyfill) {
|
|
1879
|
+
return polyfill(element);
|
|
1880
|
+
}
|
|
1881
|
+
return element.offsetParent;
|
|
1882
|
+
}
|
|
1883
|
+
|
|
1884
|
+
// Gets the closest ancestor positioned element. Handles some edge cases,
|
|
1885
|
+
// such as table ancestors and cross browser bugs.
|
|
1886
|
+
function getOffsetParent(element, polyfill) {
|
|
1887
|
+
const win = getWindow(element);
|
|
1888
|
+
if (isTopLayer(element)) {
|
|
1889
|
+
return win;
|
|
1890
|
+
}
|
|
1891
|
+
if (!isHTMLElement(element)) {
|
|
1892
|
+
let svgOffsetParent = getParentNode(element);
|
|
1893
|
+
while (svgOffsetParent && !isLastTraversableNode(svgOffsetParent)) {
|
|
1894
|
+
if (isElement(svgOffsetParent) && !isStaticPositioned(svgOffsetParent)) {
|
|
1895
|
+
return svgOffsetParent;
|
|
1896
|
+
}
|
|
1897
|
+
svgOffsetParent = getParentNode(svgOffsetParent);
|
|
1898
|
+
}
|
|
1899
|
+
return win;
|
|
1900
|
+
}
|
|
1901
|
+
let offsetParent = getTrueOffsetParent(element, polyfill);
|
|
1902
|
+
while (offsetParent && isTableElement(offsetParent) && isStaticPositioned(offsetParent)) {
|
|
1903
|
+
offsetParent = getTrueOffsetParent(offsetParent, polyfill);
|
|
1904
|
+
}
|
|
1905
|
+
if (offsetParent && isLastTraversableNode(offsetParent) && isStaticPositioned(offsetParent) && !isContainingBlock(offsetParent)) {
|
|
1906
|
+
return win;
|
|
1907
|
+
}
|
|
1908
|
+
return offsetParent || getContainingBlock(element) || win;
|
|
1909
|
+
}
|
|
1910
|
+
|
|
1911
|
+
const getElementRects = async function (data) {
|
|
1912
|
+
const getOffsetParentFn = this.getOffsetParent || getOffsetParent;
|
|
1913
|
+
const getDimensionsFn = this.getDimensions;
|
|
1914
|
+
const floatingDimensions = await getDimensionsFn(data.floating);
|
|
1915
|
+
return {
|
|
1916
|
+
reference: getRectRelativeToOffsetParent(data.reference, await getOffsetParentFn(data.floating), data.strategy),
|
|
1917
|
+
floating: {
|
|
1918
|
+
x: 0,
|
|
1919
|
+
y: 0,
|
|
1920
|
+
width: floatingDimensions.width,
|
|
1921
|
+
height: floatingDimensions.height
|
|
1922
|
+
}
|
|
1923
|
+
};
|
|
1924
|
+
};
|
|
1925
|
+
|
|
1926
|
+
function isRTL(element) {
|
|
1927
|
+
return getComputedStyle$1(element).direction === 'rtl';
|
|
1928
|
+
}
|
|
1929
|
+
|
|
1930
|
+
const platform = {
|
|
1931
|
+
convertOffsetParentRelativeRectToViewportRelativeRect,
|
|
1932
|
+
getDocumentElement,
|
|
1933
|
+
getClippingRect,
|
|
1934
|
+
getOffsetParent,
|
|
1935
|
+
getElementRects,
|
|
1936
|
+
getClientRects,
|
|
1937
|
+
getDimensions,
|
|
1938
|
+
getScale,
|
|
1939
|
+
isElement,
|
|
1940
|
+
isRTL
|
|
1941
|
+
};
|
|
1942
|
+
|
|
1943
|
+
// https://samthor.au/2021/observing-dom/
|
|
1944
|
+
function observeMove(element, onMove) {
|
|
1945
|
+
let io = null;
|
|
1946
|
+
let timeoutId;
|
|
1947
|
+
const root = getDocumentElement(element);
|
|
1948
|
+
function cleanup() {
|
|
1949
|
+
var _io;
|
|
1950
|
+
clearTimeout(timeoutId);
|
|
1951
|
+
(_io = io) == null || _io.disconnect();
|
|
1952
|
+
io = null;
|
|
1953
|
+
}
|
|
1954
|
+
function refresh(skip, threshold) {
|
|
1955
|
+
if (skip === void 0) {
|
|
1956
|
+
skip = false;
|
|
1957
|
+
}
|
|
1958
|
+
if (threshold === void 0) {
|
|
1959
|
+
threshold = 1;
|
|
1960
|
+
}
|
|
1961
|
+
cleanup();
|
|
1962
|
+
const {
|
|
1963
|
+
left,
|
|
1964
|
+
top,
|
|
1965
|
+
width,
|
|
1966
|
+
height
|
|
1967
|
+
} = element.getBoundingClientRect();
|
|
1968
|
+
if (!skip) {
|
|
1969
|
+
onMove();
|
|
1970
|
+
}
|
|
1971
|
+
if (!width || !height) {
|
|
1972
|
+
return;
|
|
1973
|
+
}
|
|
1974
|
+
const insetTop = floor(top);
|
|
1975
|
+
const insetRight = floor(root.clientWidth - (left + width));
|
|
1976
|
+
const insetBottom = floor(root.clientHeight - (top + height));
|
|
1977
|
+
const insetLeft = floor(left);
|
|
1978
|
+
const rootMargin = -insetTop + "px " + -insetRight + "px " + -insetBottom + "px " + -insetLeft + "px";
|
|
1979
|
+
const options = {
|
|
1980
|
+
rootMargin,
|
|
1981
|
+
threshold: max(0, min(1, threshold)) || 1
|
|
1982
|
+
};
|
|
1983
|
+
let isFirstUpdate = true;
|
|
1984
|
+
function handleObserve(entries) {
|
|
1985
|
+
const ratio = entries[0].intersectionRatio;
|
|
1986
|
+
if (ratio !== threshold) {
|
|
1987
|
+
if (!isFirstUpdate) {
|
|
1988
|
+
return refresh();
|
|
1989
|
+
}
|
|
1990
|
+
if (!ratio) {
|
|
1991
|
+
// If the reference is clipped, the ratio is 0. Throttle the refresh
|
|
1992
|
+
// to prevent an infinite loop of updates.
|
|
1993
|
+
timeoutId = setTimeout(() => {
|
|
1994
|
+
refresh(false, 1e-7);
|
|
1995
|
+
}, 1000);
|
|
1996
|
+
} else {
|
|
1997
|
+
refresh(false, ratio);
|
|
1998
|
+
}
|
|
1999
|
+
}
|
|
2000
|
+
isFirstUpdate = false;
|
|
2001
|
+
}
|
|
2002
|
+
|
|
2003
|
+
// Older browsers don't support a `document` as the root and will throw an
|
|
2004
|
+
// error.
|
|
2005
|
+
try {
|
|
2006
|
+
io = new IntersectionObserver(handleObserve, {
|
|
2007
|
+
...options,
|
|
2008
|
+
// Handle <iframe>s
|
|
2009
|
+
root: root.ownerDocument
|
|
2010
|
+
});
|
|
2011
|
+
} catch (e) {
|
|
2012
|
+
io = new IntersectionObserver(handleObserve, options);
|
|
2013
|
+
}
|
|
2014
|
+
io.observe(element);
|
|
2015
|
+
}
|
|
2016
|
+
refresh(true);
|
|
2017
|
+
return cleanup;
|
|
2018
|
+
}
|
|
2019
|
+
|
|
2020
|
+
/**
|
|
2021
|
+
* Automatically updates the position of the floating element when necessary.
|
|
2022
|
+
* Should only be called when the floating element is mounted on the DOM or
|
|
2023
|
+
* visible on the screen.
|
|
2024
|
+
* @returns cleanup function that should be invoked when the floating element is
|
|
2025
|
+
* removed from the DOM or hidden from the screen.
|
|
2026
|
+
* @see https://floating-ui.com/docs/autoUpdate
|
|
2027
|
+
*/
|
|
2028
|
+
function autoUpdate(reference, floating, update, options) {
|
|
2029
|
+
if (options === void 0) {
|
|
2030
|
+
options = {};
|
|
2031
|
+
}
|
|
2032
|
+
const {
|
|
2033
|
+
ancestorScroll = true,
|
|
2034
|
+
ancestorResize = true,
|
|
2035
|
+
elementResize = typeof ResizeObserver === 'function',
|
|
2036
|
+
layoutShift = typeof IntersectionObserver === 'function',
|
|
2037
|
+
animationFrame = false
|
|
2038
|
+
} = options;
|
|
2039
|
+
const referenceEl = unwrapElement(reference);
|
|
2040
|
+
const ancestors = ancestorScroll || ancestorResize ? [...(referenceEl ? getOverflowAncestors(referenceEl) : []), ...getOverflowAncestors(floating)] : [];
|
|
2041
|
+
ancestors.forEach(ancestor => {
|
|
2042
|
+
ancestorScroll && ancestor.addEventListener('scroll', update, {
|
|
2043
|
+
passive: true
|
|
2044
|
+
});
|
|
2045
|
+
ancestorResize && ancestor.addEventListener('resize', update);
|
|
2046
|
+
});
|
|
2047
|
+
const cleanupIo = referenceEl && layoutShift ? observeMove(referenceEl, update) : null;
|
|
2048
|
+
let reobserveFrame = -1;
|
|
2049
|
+
let resizeObserver = null;
|
|
2050
|
+
if (elementResize) {
|
|
2051
|
+
resizeObserver = new ResizeObserver(_ref => {
|
|
2052
|
+
let [firstEntry] = _ref;
|
|
2053
|
+
if (firstEntry && firstEntry.target === referenceEl && resizeObserver) {
|
|
2054
|
+
// Prevent update loops when using the `size` middleware.
|
|
2055
|
+
// https://github.com/floating-ui/floating-ui/issues/1740
|
|
2056
|
+
resizeObserver.unobserve(floating);
|
|
2057
|
+
cancelAnimationFrame(reobserveFrame);
|
|
2058
|
+
reobserveFrame = requestAnimationFrame(() => {
|
|
2059
|
+
var _resizeObserver;
|
|
2060
|
+
(_resizeObserver = resizeObserver) == null || _resizeObserver.observe(floating);
|
|
2061
|
+
});
|
|
2062
|
+
}
|
|
2063
|
+
update();
|
|
2064
|
+
});
|
|
2065
|
+
if (referenceEl && !animationFrame) {
|
|
2066
|
+
resizeObserver.observe(referenceEl);
|
|
2067
|
+
}
|
|
2068
|
+
resizeObserver.observe(floating);
|
|
2069
|
+
}
|
|
2070
|
+
let frameId;
|
|
2071
|
+
let prevRefRect = animationFrame ? getBoundingClientRect(reference) : null;
|
|
2072
|
+
if (animationFrame) {
|
|
2073
|
+
frameLoop();
|
|
2074
|
+
}
|
|
2075
|
+
function frameLoop() {
|
|
2076
|
+
const nextRefRect = getBoundingClientRect(reference);
|
|
2077
|
+
if (prevRefRect && (nextRefRect.x !== prevRefRect.x || nextRefRect.y !== prevRefRect.y || nextRefRect.width !== prevRefRect.width || nextRefRect.height !== prevRefRect.height)) {
|
|
2078
|
+
update();
|
|
2079
|
+
}
|
|
2080
|
+
prevRefRect = nextRefRect;
|
|
2081
|
+
frameId = requestAnimationFrame(frameLoop);
|
|
2082
|
+
}
|
|
2083
|
+
update();
|
|
2084
|
+
return () => {
|
|
2085
|
+
var _resizeObserver2;
|
|
2086
|
+
ancestors.forEach(ancestor => {
|
|
2087
|
+
ancestorScroll && ancestor.removeEventListener('scroll', update);
|
|
2088
|
+
ancestorResize && ancestor.removeEventListener('resize', update);
|
|
2089
|
+
});
|
|
2090
|
+
cleanupIo == null || cleanupIo();
|
|
2091
|
+
(_resizeObserver2 = resizeObserver) == null || _resizeObserver2.disconnect();
|
|
2092
|
+
resizeObserver = null;
|
|
2093
|
+
if (animationFrame) {
|
|
2094
|
+
cancelAnimationFrame(frameId);
|
|
2095
|
+
}
|
|
2096
|
+
};
|
|
2097
|
+
}
|
|
2098
|
+
|
|
2099
|
+
/**
|
|
2100
|
+
* Modifies the placement by translating the floating element along the
|
|
2101
|
+
* specified axes.
|
|
2102
|
+
* A number (shorthand for `mainAxis` or distance), or an axes configuration
|
|
2103
|
+
* object may be passed.
|
|
2104
|
+
* @see https://floating-ui.com/docs/offset
|
|
2105
|
+
*/
|
|
2106
|
+
const offset$1 = offset$2;
|
|
2107
|
+
|
|
2108
|
+
/**
|
|
2109
|
+
* Optimizes the visibility of the floating element by shifting it in order to
|
|
2110
|
+
* keep it in view when it will overflow the clipping boundary.
|
|
2111
|
+
* @see https://floating-ui.com/docs/shift
|
|
2112
|
+
*/
|
|
2113
|
+
const shift$1 = shift$2;
|
|
2114
|
+
|
|
2115
|
+
/**
|
|
2116
|
+
* Optimizes the visibility of the floating element by flipping the `placement`
|
|
2117
|
+
* in order to keep it in view when the preferred placement(s) will overflow the
|
|
2118
|
+
* clipping boundary. Alternative to `autoPlacement`.
|
|
2119
|
+
* @see https://floating-ui.com/docs/flip
|
|
2120
|
+
*/
|
|
2121
|
+
const flip$1 = flip$2;
|
|
2122
|
+
|
|
2123
|
+
/**
|
|
2124
|
+
* Provides data to position an inner element of the floating element so that it
|
|
2125
|
+
* appears centered to the reference element.
|
|
2126
|
+
* @see https://floating-ui.com/docs/arrow
|
|
2127
|
+
*/
|
|
2128
|
+
const arrow$2 = arrow$3;
|
|
2129
|
+
|
|
2130
|
+
/**
|
|
2131
|
+
* Computes the `x` and `y` coordinates that will place the floating element
|
|
2132
|
+
* next to a given reference element.
|
|
2133
|
+
*/
|
|
2134
|
+
const computePosition = (reference, floating, options) => {
|
|
2135
|
+
// This caches the expensive `getClippingElementAncestors` function so that
|
|
2136
|
+
// multiple lifecycle resets re-use the same result. It only lives for a
|
|
2137
|
+
// single call. If other functions become expensive, we can add them as well.
|
|
2138
|
+
const cache = new Map();
|
|
2139
|
+
const mergedOptions = {
|
|
2140
|
+
platform,
|
|
2141
|
+
...options
|
|
2142
|
+
};
|
|
2143
|
+
const platformWithCache = {
|
|
2144
|
+
...mergedOptions.platform,
|
|
2145
|
+
_c: cache
|
|
2146
|
+
};
|
|
2147
|
+
return computePosition$1(reference, floating, {
|
|
2148
|
+
...mergedOptions,
|
|
2149
|
+
platform: platformWithCache
|
|
2150
|
+
});
|
|
2151
|
+
};
|
|
2152
|
+
|
|
2153
|
+
var index$1 = typeof document !== 'undefined' ? useLayoutEffect : useEffect;
|
|
2154
|
+
|
|
2155
|
+
// Fork of `fast-deep-equal` that only does the comparisons we need and compares
|
|
2156
|
+
// functions
|
|
2157
|
+
function deepEqual(a, b) {
|
|
2158
|
+
if (a === b) {
|
|
2159
|
+
return true;
|
|
2160
|
+
}
|
|
2161
|
+
if (typeof a !== typeof b) {
|
|
2162
|
+
return false;
|
|
2163
|
+
}
|
|
2164
|
+
if (typeof a === 'function' && a.toString() === b.toString()) {
|
|
2165
|
+
return true;
|
|
2166
|
+
}
|
|
2167
|
+
let length;
|
|
2168
|
+
let i;
|
|
2169
|
+
let keys;
|
|
2170
|
+
if (a && b && typeof a === 'object') {
|
|
2171
|
+
if (Array.isArray(a)) {
|
|
2172
|
+
length = a.length;
|
|
2173
|
+
if (length !== b.length) return false;
|
|
2174
|
+
for (i = length; i-- !== 0;) {
|
|
2175
|
+
if (!deepEqual(a[i], b[i])) {
|
|
2176
|
+
return false;
|
|
2177
|
+
}
|
|
2178
|
+
}
|
|
2179
|
+
return true;
|
|
2180
|
+
}
|
|
2181
|
+
keys = Object.keys(a);
|
|
2182
|
+
length = keys.length;
|
|
2183
|
+
if (length !== Object.keys(b).length) {
|
|
2184
|
+
return false;
|
|
2185
|
+
}
|
|
2186
|
+
for (i = length; i-- !== 0;) {
|
|
2187
|
+
if (!{}.hasOwnProperty.call(b, keys[i])) {
|
|
2188
|
+
return false;
|
|
2189
|
+
}
|
|
2190
|
+
}
|
|
2191
|
+
for (i = length; i-- !== 0;) {
|
|
2192
|
+
const key = keys[i];
|
|
2193
|
+
if (key === '_owner' && a.$$typeof) {
|
|
2194
|
+
continue;
|
|
2195
|
+
}
|
|
2196
|
+
if (!deepEqual(a[key], b[key])) {
|
|
2197
|
+
return false;
|
|
2198
|
+
}
|
|
2199
|
+
}
|
|
2200
|
+
return true;
|
|
2201
|
+
}
|
|
2202
|
+
return a !== a && b !== b;
|
|
2203
|
+
}
|
|
2204
|
+
|
|
2205
|
+
function getDPR(element) {
|
|
2206
|
+
if (typeof window === 'undefined') {
|
|
2207
|
+
return 1;
|
|
2208
|
+
}
|
|
2209
|
+
const win = element.ownerDocument.defaultView || window;
|
|
2210
|
+
return win.devicePixelRatio || 1;
|
|
2211
|
+
}
|
|
2212
|
+
|
|
2213
|
+
function roundByDPR(element, value) {
|
|
2214
|
+
const dpr = getDPR(element);
|
|
2215
|
+
return Math.round(value * dpr) / dpr;
|
|
2216
|
+
}
|
|
2217
|
+
|
|
2218
|
+
function useLatestRef$1(value) {
|
|
2219
|
+
const ref = React.useRef(value);
|
|
2220
|
+
index$1(() => {
|
|
2221
|
+
ref.current = value;
|
|
2222
|
+
});
|
|
2223
|
+
return ref;
|
|
2224
|
+
}
|
|
2225
|
+
|
|
2226
|
+
/**
|
|
2227
|
+
* Provides data to position a floating element.
|
|
2228
|
+
* @see https://floating-ui.com/docs/useFloating
|
|
2229
|
+
*/
|
|
2230
|
+
function useFloating$1(options) {
|
|
2231
|
+
if (options === void 0) {
|
|
2232
|
+
options = {};
|
|
2233
|
+
}
|
|
2234
|
+
const {
|
|
2235
|
+
placement = 'bottom',
|
|
2236
|
+
strategy = 'absolute',
|
|
2237
|
+
middleware = [],
|
|
2238
|
+
platform,
|
|
2239
|
+
elements: {
|
|
2240
|
+
reference: externalReference,
|
|
2241
|
+
floating: externalFloating
|
|
2242
|
+
} = {},
|
|
2243
|
+
transform = true,
|
|
2244
|
+
whileElementsMounted,
|
|
2245
|
+
open
|
|
2246
|
+
} = options;
|
|
2247
|
+
const [data, setData] = React.useState({
|
|
2248
|
+
x: 0,
|
|
2249
|
+
y: 0,
|
|
2250
|
+
strategy,
|
|
2251
|
+
placement,
|
|
2252
|
+
middlewareData: {},
|
|
2253
|
+
isPositioned: false
|
|
2254
|
+
});
|
|
2255
|
+
const [latestMiddleware, setLatestMiddleware] = React.useState(middleware);
|
|
2256
|
+
if (!deepEqual(latestMiddleware, middleware)) {
|
|
2257
|
+
setLatestMiddleware(middleware);
|
|
2258
|
+
}
|
|
2259
|
+
const [_reference, _setReference] = React.useState(null);
|
|
2260
|
+
const [_floating, _setFloating] = React.useState(null);
|
|
2261
|
+
const setReference = React.useCallback(node => {
|
|
2262
|
+
if (node !== referenceRef.current) {
|
|
2263
|
+
referenceRef.current = node;
|
|
2264
|
+
_setReference(node);
|
|
2265
|
+
}
|
|
2266
|
+
}, []);
|
|
2267
|
+
const setFloating = React.useCallback(node => {
|
|
2268
|
+
if (node !== floatingRef.current) {
|
|
2269
|
+
floatingRef.current = node;
|
|
2270
|
+
_setFloating(node);
|
|
2271
|
+
}
|
|
2272
|
+
}, []);
|
|
2273
|
+
const referenceEl = externalReference || _reference;
|
|
2274
|
+
const floatingEl = externalFloating || _floating;
|
|
2275
|
+
const referenceRef = React.useRef(null);
|
|
2276
|
+
const floatingRef = React.useRef(null);
|
|
2277
|
+
const dataRef = React.useRef(data);
|
|
2278
|
+
const hasWhileElementsMounted = whileElementsMounted != null;
|
|
2279
|
+
const whileElementsMountedRef = useLatestRef$1(whileElementsMounted);
|
|
2280
|
+
const platformRef = useLatestRef$1(platform);
|
|
2281
|
+
const openRef = useLatestRef$1(open);
|
|
2282
|
+
const update = React.useCallback(() => {
|
|
2283
|
+
if (!referenceRef.current || !floatingRef.current) {
|
|
2284
|
+
return;
|
|
2285
|
+
}
|
|
2286
|
+
const config = {
|
|
2287
|
+
placement,
|
|
2288
|
+
strategy,
|
|
2289
|
+
middleware: latestMiddleware
|
|
2290
|
+
};
|
|
2291
|
+
if (platformRef.current) {
|
|
2292
|
+
config.platform = platformRef.current;
|
|
2293
|
+
}
|
|
2294
|
+
computePosition(referenceRef.current, floatingRef.current, config).then(data => {
|
|
2295
|
+
const fullData = {
|
|
2296
|
+
...data,
|
|
2297
|
+
// The floating element's position may be recomputed while it's closed
|
|
2298
|
+
// but still mounted (such as when transitioning out). To ensure
|
|
2299
|
+
// `isPositioned` will be `false` initially on the next open, avoid
|
|
2300
|
+
// setting it to `true` when `open === false` (must be specified).
|
|
2301
|
+
isPositioned: openRef.current !== false
|
|
2302
|
+
};
|
|
2303
|
+
if (isMountedRef.current && !deepEqual(dataRef.current, fullData)) {
|
|
2304
|
+
dataRef.current = fullData;
|
|
2305
|
+
ReactDOM.flushSync(() => {
|
|
2306
|
+
setData(fullData);
|
|
2307
|
+
});
|
|
2308
|
+
}
|
|
2309
|
+
});
|
|
2310
|
+
}, [latestMiddleware, placement, strategy, platformRef, openRef]);
|
|
2311
|
+
index$1(() => {
|
|
2312
|
+
if (open === false && dataRef.current.isPositioned) {
|
|
2313
|
+
dataRef.current.isPositioned = false;
|
|
2314
|
+
setData(data => ({
|
|
2315
|
+
...data,
|
|
2316
|
+
isPositioned: false
|
|
2317
|
+
}));
|
|
2318
|
+
}
|
|
2319
|
+
}, [open]);
|
|
2320
|
+
const isMountedRef = React.useRef(false);
|
|
2321
|
+
index$1(() => {
|
|
2322
|
+
isMountedRef.current = true;
|
|
2323
|
+
return () => {
|
|
2324
|
+
isMountedRef.current = false;
|
|
2325
|
+
};
|
|
2326
|
+
}, []);
|
|
2327
|
+
index$1(() => {
|
|
2328
|
+
if (referenceEl) referenceRef.current = referenceEl;
|
|
2329
|
+
if (floatingEl) floatingRef.current = floatingEl;
|
|
2330
|
+
if (referenceEl && floatingEl) {
|
|
2331
|
+
if (whileElementsMountedRef.current) {
|
|
2332
|
+
return whileElementsMountedRef.current(referenceEl, floatingEl, update);
|
|
2333
|
+
}
|
|
2334
|
+
update();
|
|
2335
|
+
}
|
|
2336
|
+
}, [referenceEl, floatingEl, update, whileElementsMountedRef, hasWhileElementsMounted]);
|
|
2337
|
+
const refs = React.useMemo(() => ({
|
|
2338
|
+
reference: referenceRef,
|
|
2339
|
+
floating: floatingRef,
|
|
2340
|
+
setReference,
|
|
2341
|
+
setFloating
|
|
2342
|
+
}), [setReference, setFloating]);
|
|
2343
|
+
const elements = React.useMemo(() => ({
|
|
2344
|
+
reference: referenceEl,
|
|
2345
|
+
floating: floatingEl
|
|
2346
|
+
}), [referenceEl, floatingEl]);
|
|
2347
|
+
const floatingStyles = React.useMemo(() => {
|
|
2348
|
+
const initialStyles = {
|
|
2349
|
+
position: strategy,
|
|
2350
|
+
left: 0,
|
|
2351
|
+
top: 0
|
|
2352
|
+
};
|
|
2353
|
+
if (!elements.floating) {
|
|
2354
|
+
return initialStyles;
|
|
2355
|
+
}
|
|
2356
|
+
const x = roundByDPR(elements.floating, data.x);
|
|
2357
|
+
const y = roundByDPR(elements.floating, data.y);
|
|
2358
|
+
if (transform) {
|
|
2359
|
+
return {
|
|
2360
|
+
...initialStyles,
|
|
2361
|
+
transform: "translate(" + x + "px, " + y + "px)",
|
|
2362
|
+
...(getDPR(elements.floating) >= 1.5 && {
|
|
2363
|
+
willChange: 'transform'
|
|
2364
|
+
})
|
|
2365
|
+
};
|
|
2366
|
+
}
|
|
2367
|
+
return {
|
|
2368
|
+
position: strategy,
|
|
2369
|
+
left: x,
|
|
2370
|
+
top: y
|
|
2371
|
+
};
|
|
2372
|
+
}, [strategy, transform, elements.floating, data.x, data.y]);
|
|
2373
|
+
return React.useMemo(() => ({
|
|
2374
|
+
...data,
|
|
2375
|
+
update,
|
|
2376
|
+
refs,
|
|
2377
|
+
elements,
|
|
2378
|
+
floatingStyles
|
|
2379
|
+
}), [data, update, refs, elements, floatingStyles]);
|
|
2380
|
+
}
|
|
2381
|
+
|
|
2382
|
+
/**
|
|
2383
|
+
* Provides data to position an inner element of the floating element so that it
|
|
2384
|
+
* appears centered to the reference element.
|
|
2385
|
+
* This wraps the core `arrow` middleware to allow React refs as the element.
|
|
2386
|
+
* @see https://floating-ui.com/docs/arrow
|
|
2387
|
+
*/
|
|
2388
|
+
const arrow$1 = options => {
|
|
2389
|
+
function isRef(value) {
|
|
2390
|
+
return {}.hasOwnProperty.call(value, 'current');
|
|
2391
|
+
}
|
|
2392
|
+
return {
|
|
2393
|
+
name: 'arrow',
|
|
2394
|
+
options,
|
|
2395
|
+
fn(state) {
|
|
2396
|
+
const {
|
|
2397
|
+
element,
|
|
2398
|
+
padding
|
|
2399
|
+
} = typeof options === 'function' ? options(state) : options;
|
|
2400
|
+
if (element && isRef(element)) {
|
|
2401
|
+
if (element.current != null) {
|
|
2402
|
+
return arrow$2({
|
|
2403
|
+
element: element.current,
|
|
2404
|
+
padding
|
|
2405
|
+
}).fn(state);
|
|
2406
|
+
}
|
|
2407
|
+
return {};
|
|
2408
|
+
}
|
|
2409
|
+
if (element) {
|
|
2410
|
+
return arrow$2({
|
|
2411
|
+
element,
|
|
2412
|
+
padding
|
|
2413
|
+
}).fn(state);
|
|
2414
|
+
}
|
|
2415
|
+
return {};
|
|
2416
|
+
}
|
|
2417
|
+
};
|
|
2418
|
+
};
|
|
2419
|
+
|
|
2420
|
+
/**
|
|
2421
|
+
* Modifies the placement by translating the floating element along the
|
|
2422
|
+
* specified axes.
|
|
2423
|
+
* A number (shorthand for `mainAxis` or distance), or an axes configuration
|
|
2424
|
+
* object may be passed.
|
|
2425
|
+
* @see https://floating-ui.com/docs/offset
|
|
2426
|
+
*/
|
|
2427
|
+
const offset = (options, deps) => ({
|
|
2428
|
+
...offset$1(options),
|
|
2429
|
+
options: [options, deps]
|
|
2430
|
+
});
|
|
2431
|
+
|
|
2432
|
+
/**
|
|
2433
|
+
* Optimizes the visibility of the floating element by shifting it in order to
|
|
2434
|
+
* keep it in view when it will overflow the clipping boundary.
|
|
2435
|
+
* @see https://floating-ui.com/docs/shift
|
|
2436
|
+
*/
|
|
2437
|
+
const shift = (options, deps) => ({
|
|
2438
|
+
...shift$1(options),
|
|
2439
|
+
options: [options, deps]
|
|
2440
|
+
});
|
|
2441
|
+
|
|
2442
|
+
/**
|
|
2443
|
+
* Optimizes the visibility of the floating element by flipping the `placement`
|
|
2444
|
+
* in order to keep it in view when the preferred placement(s) will overflow the
|
|
2445
|
+
* clipping boundary. Alternative to `autoPlacement`.
|
|
2446
|
+
* @see https://floating-ui.com/docs/flip
|
|
2447
|
+
*/
|
|
2448
|
+
const flip = (options, deps) => ({
|
|
2449
|
+
...flip$1(options),
|
|
2450
|
+
options: [options, deps]
|
|
2451
|
+
});
|
|
2452
|
+
|
|
2453
|
+
/**
|
|
2454
|
+
* Provides data to position an inner element of the floating element so that it
|
|
2455
|
+
* appears centered to the reference element.
|
|
2456
|
+
* This wraps the core `arrow` middleware to allow React refs as the element.
|
|
2457
|
+
* @see https://floating-ui.com/docs/arrow
|
|
2458
|
+
*/
|
|
2459
|
+
const arrow = (options, deps) => ({
|
|
2460
|
+
...arrow$1(options),
|
|
2461
|
+
options: [options, deps]
|
|
2462
|
+
});
|
|
2463
|
+
|
|
2464
|
+
// https://github.com/mui/material-ui/issues/41190#issuecomment-2040873379
|
|
2465
|
+
const SafeReact = {
|
|
2466
|
+
...React
|
|
2467
|
+
};
|
|
2468
|
+
|
|
2469
|
+
const useInsertionEffect = SafeReact.useInsertionEffect;
|
|
2470
|
+
const useSafeInsertionEffect = useInsertionEffect || (fn => fn());
|
|
2471
|
+
function useEffectEvent(callback) {
|
|
2472
|
+
const ref = React.useRef(() => {
|
|
2473
|
+
if (process.env.NODE_ENV !== "production") {
|
|
2474
|
+
throw new Error('Cannot call an event handler while rendering.');
|
|
2475
|
+
}
|
|
2476
|
+
});
|
|
2477
|
+
useSafeInsertionEffect(() => {
|
|
2478
|
+
ref.current = callback;
|
|
2479
|
+
});
|
|
2480
|
+
return React.useCallback(function () {
|
|
2481
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
2482
|
+
args[_key] = arguments[_key];
|
|
2483
|
+
}
|
|
2484
|
+
return ref.current == null ? void 0 : ref.current(...args);
|
|
2485
|
+
}, []);
|
|
2486
|
+
}
|
|
2487
|
+
|
|
2488
|
+
var index = typeof document !== 'undefined' ? useLayoutEffect : useEffect;
|
|
2489
|
+
|
|
2490
|
+
function _extends() {
|
|
2491
|
+
_extends = Object.assign ? Object.assign.bind() : function (target) {
|
|
2492
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
2493
|
+
var source = arguments[i];
|
|
2494
|
+
for (var key in source) {
|
|
2495
|
+
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
2496
|
+
target[key] = source[key];
|
|
2497
|
+
}
|
|
2498
|
+
}
|
|
2499
|
+
}
|
|
2500
|
+
return target;
|
|
2501
|
+
};
|
|
2502
|
+
return _extends.apply(this, arguments);
|
|
2503
|
+
}
|
|
2504
|
+
|
|
2505
|
+
let serverHandoffComplete = false;
|
|
2506
|
+
let count = 0;
|
|
2507
|
+
const genId = () => // Ensure the id is unique with multiple independent versions of Floating UI
|
|
2508
|
+
// on <React 18
|
|
2509
|
+
"floating-ui-" + Math.random().toString(36).slice(2, 6) + count++;
|
|
2510
|
+
function useFloatingId() {
|
|
2511
|
+
const [id, setId] = React.useState(() => serverHandoffComplete ? genId() : undefined);
|
|
2512
|
+
index(() => {
|
|
2513
|
+
if (id == null) {
|
|
2514
|
+
setId(genId());
|
|
2515
|
+
}
|
|
2516
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
2517
|
+
}, []);
|
|
2518
|
+
React.useEffect(() => {
|
|
2519
|
+
serverHandoffComplete = true;
|
|
2520
|
+
}, []);
|
|
2521
|
+
return id;
|
|
2522
|
+
}
|
|
2523
|
+
const useReactId = SafeReact.useId;
|
|
2524
|
+
|
|
2525
|
+
/**
|
|
2526
|
+
* Uses React 18's built-in `useId()` when available, or falls back to a
|
|
2527
|
+
* slightly less performant (requiring a double render) implementation for
|
|
2528
|
+
* earlier React versions.
|
|
2529
|
+
* @see https://floating-ui.com/docs/react-utils#useid
|
|
2530
|
+
*/
|
|
2531
|
+
const useId = useReactId || useFloatingId;
|
|
2532
|
+
|
|
2533
|
+
let devMessageSet;
|
|
2534
|
+
if (process.env.NODE_ENV !== "production") {
|
|
2535
|
+
devMessageSet = /*#__PURE__*/new Set();
|
|
2536
|
+
}
|
|
2537
|
+
function error() {
|
|
2538
|
+
var _devMessageSet3;
|
|
2539
|
+
for (var _len2 = arguments.length, messages = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
2540
|
+
messages[_key2] = arguments[_key2];
|
|
2541
|
+
}
|
|
2542
|
+
const message = "Floating UI: " + messages.join(' ');
|
|
2543
|
+
if (!((_devMessageSet3 = devMessageSet) != null && _devMessageSet3.has(message))) {
|
|
2544
|
+
var _devMessageSet4;
|
|
2545
|
+
(_devMessageSet4 = devMessageSet) == null || _devMessageSet4.add(message);
|
|
2546
|
+
console.error(message);
|
|
2547
|
+
}
|
|
2548
|
+
}
|
|
2549
|
+
|
|
2550
|
+
function createPubSub() {
|
|
2551
|
+
const map = new Map();
|
|
2552
|
+
return {
|
|
2553
|
+
emit(event, data) {
|
|
2554
|
+
var _map$get;
|
|
2555
|
+
(_map$get = map.get(event)) == null || _map$get.forEach(handler => handler(data));
|
|
2556
|
+
},
|
|
2557
|
+
on(event, listener) {
|
|
2558
|
+
map.set(event, [...(map.get(event) || []), listener]);
|
|
2559
|
+
},
|
|
2560
|
+
off(event, listener) {
|
|
2561
|
+
var _map$get2;
|
|
2562
|
+
map.set(event, ((_map$get2 = map.get(event)) == null ? void 0 : _map$get2.filter(l => l !== listener)) || []);
|
|
2563
|
+
}
|
|
2564
|
+
};
|
|
2565
|
+
}
|
|
2566
|
+
|
|
2567
|
+
const FloatingNodeContext = /*#__PURE__*/React.createContext(null);
|
|
2568
|
+
const FloatingTreeContext = /*#__PURE__*/React.createContext(null);
|
|
2569
|
+
|
|
2570
|
+
/**
|
|
2571
|
+
* Returns the parent node id for nested floating elements, if available.
|
|
2572
|
+
* Returns `null` for top-level floating elements.
|
|
2573
|
+
*/
|
|
2574
|
+
const useFloatingParentNodeId = () => {
|
|
2575
|
+
var _React$useContext;
|
|
2576
|
+
return ((_React$useContext = React.useContext(FloatingNodeContext)) == null ? void 0 : _React$useContext.id) || null;
|
|
2577
|
+
};
|
|
2578
|
+
|
|
2579
|
+
/**
|
|
2580
|
+
* Returns the nearest floating tree context, if available.
|
|
2581
|
+
*/
|
|
2582
|
+
const useFloatingTree = () => React.useContext(FloatingTreeContext);
|
|
2583
|
+
|
|
2584
|
+
function createAttribute(name) {
|
|
2585
|
+
return "data-floating-ui-" + name;
|
|
2586
|
+
}
|
|
2587
|
+
|
|
2588
|
+
function useLatestRef(value) {
|
|
2589
|
+
const ref = useRef(value);
|
|
2590
|
+
index(() => {
|
|
2591
|
+
ref.current = value;
|
|
2592
|
+
});
|
|
2593
|
+
return ref;
|
|
2594
|
+
}
|
|
2595
|
+
|
|
2596
|
+
const safePolygonIdentifier = /*#__PURE__*/createAttribute('safe-polygon');
|
|
2597
|
+
function getDelay(value, prop, pointerType) {
|
|
2598
|
+
if (pointerType && !isMouseLikePointerType(pointerType)) {
|
|
2599
|
+
return 0;
|
|
2600
|
+
}
|
|
2601
|
+
if (typeof value === 'number') {
|
|
2602
|
+
return value;
|
|
2603
|
+
}
|
|
2604
|
+
return value == null ? void 0 : value[prop];
|
|
2605
|
+
}
|
|
2606
|
+
/**
|
|
2607
|
+
* Opens the floating element while hovering over the reference element, like
|
|
2608
|
+
* CSS `:hover`.
|
|
2609
|
+
* @see https://floating-ui.com/docs/useHover
|
|
2610
|
+
*/
|
|
2611
|
+
function useHover(context, props) {
|
|
2612
|
+
if (props === void 0) {
|
|
2613
|
+
props = {};
|
|
2614
|
+
}
|
|
2615
|
+
const {
|
|
2616
|
+
open,
|
|
2617
|
+
onOpenChange,
|
|
2618
|
+
dataRef,
|
|
2619
|
+
events,
|
|
2620
|
+
elements
|
|
2621
|
+
} = context;
|
|
2622
|
+
const {
|
|
2623
|
+
enabled = true,
|
|
2624
|
+
delay = 0,
|
|
2625
|
+
handleClose = null,
|
|
2626
|
+
mouseOnly = false,
|
|
2627
|
+
restMs = 0,
|
|
2628
|
+
move = true
|
|
2629
|
+
} = props;
|
|
2630
|
+
const tree = useFloatingTree();
|
|
2631
|
+
const parentId = useFloatingParentNodeId();
|
|
2632
|
+
const handleCloseRef = useLatestRef(handleClose);
|
|
2633
|
+
const delayRef = useLatestRef(delay);
|
|
2634
|
+
const openRef = useLatestRef(open);
|
|
2635
|
+
const pointerTypeRef = React.useRef();
|
|
2636
|
+
const timeoutRef = React.useRef(-1);
|
|
2637
|
+
const handlerRef = React.useRef();
|
|
2638
|
+
const restTimeoutRef = React.useRef(-1);
|
|
2639
|
+
const blockMouseMoveRef = React.useRef(true);
|
|
2640
|
+
const performedPointerEventsMutationRef = React.useRef(false);
|
|
2641
|
+
const unbindMouseMoveRef = React.useRef(() => {});
|
|
2642
|
+
const isHoverOpen = React.useCallback(() => {
|
|
2643
|
+
var _dataRef$current$open;
|
|
2644
|
+
const type = (_dataRef$current$open = dataRef.current.openEvent) == null ? void 0 : _dataRef$current$open.type;
|
|
2645
|
+
return (type == null ? void 0 : type.includes('mouse')) && type !== 'mousedown';
|
|
2646
|
+
}, [dataRef]);
|
|
2647
|
+
|
|
2648
|
+
// When closing before opening, clear the delay timeouts to cancel it
|
|
2649
|
+
// from showing.
|
|
2650
|
+
React.useEffect(() => {
|
|
2651
|
+
if (!enabled) return;
|
|
2652
|
+
function onOpenChange(_ref) {
|
|
2653
|
+
let {
|
|
2654
|
+
open
|
|
2655
|
+
} = _ref;
|
|
2656
|
+
if (!open) {
|
|
2657
|
+
clearTimeout(timeoutRef.current);
|
|
2658
|
+
clearTimeout(restTimeoutRef.current);
|
|
2659
|
+
blockMouseMoveRef.current = true;
|
|
2660
|
+
}
|
|
2661
|
+
}
|
|
2662
|
+
events.on('openchange', onOpenChange);
|
|
2663
|
+
return () => {
|
|
2664
|
+
events.off('openchange', onOpenChange);
|
|
2665
|
+
};
|
|
2666
|
+
}, [enabled, events]);
|
|
2667
|
+
React.useEffect(() => {
|
|
2668
|
+
if (!enabled) return;
|
|
2669
|
+
if (!handleCloseRef.current) return;
|
|
2670
|
+
if (!open) return;
|
|
2671
|
+
function onLeave(event) {
|
|
2672
|
+
if (isHoverOpen()) {
|
|
2673
|
+
onOpenChange(false, event, 'hover');
|
|
2674
|
+
}
|
|
2675
|
+
}
|
|
2676
|
+
const html = getDocument(elements.floating).documentElement;
|
|
2677
|
+
html.addEventListener('mouseleave', onLeave);
|
|
2678
|
+
return () => {
|
|
2679
|
+
html.removeEventListener('mouseleave', onLeave);
|
|
2680
|
+
};
|
|
2681
|
+
}, [elements.floating, open, onOpenChange, enabled, handleCloseRef, isHoverOpen]);
|
|
2682
|
+
const closeWithDelay = React.useCallback(function (event, runElseBranch, reason) {
|
|
2683
|
+
if (runElseBranch === void 0) {
|
|
2684
|
+
runElseBranch = true;
|
|
2685
|
+
}
|
|
2686
|
+
if (reason === void 0) {
|
|
2687
|
+
reason = 'hover';
|
|
2688
|
+
}
|
|
2689
|
+
const closeDelay = getDelay(delayRef.current, 'close', pointerTypeRef.current);
|
|
2690
|
+
if (closeDelay && !handlerRef.current) {
|
|
2691
|
+
clearTimeout(timeoutRef.current);
|
|
2692
|
+
timeoutRef.current = window.setTimeout(() => onOpenChange(false, event, reason), closeDelay);
|
|
2693
|
+
} else if (runElseBranch) {
|
|
2694
|
+
clearTimeout(timeoutRef.current);
|
|
2695
|
+
onOpenChange(false, event, reason);
|
|
2696
|
+
}
|
|
2697
|
+
}, [delayRef, onOpenChange]);
|
|
2698
|
+
const cleanupMouseMoveHandler = useEffectEvent(() => {
|
|
2699
|
+
unbindMouseMoveRef.current();
|
|
2700
|
+
handlerRef.current = undefined;
|
|
2701
|
+
});
|
|
2702
|
+
const clearPointerEvents = useEffectEvent(() => {
|
|
2703
|
+
if (performedPointerEventsMutationRef.current) {
|
|
2704
|
+
const body = getDocument(elements.floating).body;
|
|
2705
|
+
body.style.pointerEvents = '';
|
|
2706
|
+
body.removeAttribute(safePolygonIdentifier);
|
|
2707
|
+
performedPointerEventsMutationRef.current = false;
|
|
2708
|
+
}
|
|
2709
|
+
});
|
|
2710
|
+
|
|
2711
|
+
// Registering the mouse events on the reference directly to bypass React's
|
|
2712
|
+
// delegation system. If the cursor was on a disabled element and then entered
|
|
2713
|
+
// the reference (no gap), `mouseenter` doesn't fire in the delegation system.
|
|
2714
|
+
React.useEffect(() => {
|
|
2715
|
+
if (!enabled) return;
|
|
2716
|
+
function isClickLikeOpenEvent() {
|
|
2717
|
+
return dataRef.current.openEvent ? ['click', 'mousedown'].includes(dataRef.current.openEvent.type) : false;
|
|
2718
|
+
}
|
|
2719
|
+
function onMouseEnter(event) {
|
|
2720
|
+
clearTimeout(timeoutRef.current);
|
|
2721
|
+
blockMouseMoveRef.current = false;
|
|
2722
|
+
if (mouseOnly && !isMouseLikePointerType(pointerTypeRef.current) || restMs > 0 && !getDelay(delayRef.current, 'open')) {
|
|
2723
|
+
return;
|
|
2724
|
+
}
|
|
2725
|
+
const openDelay = getDelay(delayRef.current, 'open', pointerTypeRef.current);
|
|
2726
|
+
if (openDelay) {
|
|
2727
|
+
timeoutRef.current = window.setTimeout(() => {
|
|
2728
|
+
if (!openRef.current) {
|
|
2729
|
+
onOpenChange(true, event, 'hover');
|
|
2730
|
+
}
|
|
2731
|
+
}, openDelay);
|
|
2732
|
+
} else {
|
|
2733
|
+
onOpenChange(true, event, 'hover');
|
|
2734
|
+
}
|
|
2735
|
+
}
|
|
2736
|
+
function onMouseLeave(event) {
|
|
2737
|
+
if (isClickLikeOpenEvent()) return;
|
|
2738
|
+
unbindMouseMoveRef.current();
|
|
2739
|
+
const doc = getDocument(elements.floating);
|
|
2740
|
+
clearTimeout(restTimeoutRef.current);
|
|
2741
|
+
if (handleCloseRef.current && dataRef.current.floatingContext) {
|
|
2742
|
+
// Prevent clearing `onScrollMouseLeave` timeout.
|
|
2743
|
+
if (!open) {
|
|
2744
|
+
clearTimeout(timeoutRef.current);
|
|
2745
|
+
}
|
|
2746
|
+
handlerRef.current = handleCloseRef.current({
|
|
2747
|
+
...dataRef.current.floatingContext,
|
|
2748
|
+
tree,
|
|
2749
|
+
x: event.clientX,
|
|
2750
|
+
y: event.clientY,
|
|
2751
|
+
onClose() {
|
|
2752
|
+
clearPointerEvents();
|
|
2753
|
+
cleanupMouseMoveHandler();
|
|
2754
|
+
closeWithDelay(event, true, 'safe-polygon');
|
|
2755
|
+
}
|
|
2756
|
+
});
|
|
2757
|
+
const handler = handlerRef.current;
|
|
2758
|
+
doc.addEventListener('mousemove', handler);
|
|
2759
|
+
unbindMouseMoveRef.current = () => {
|
|
2760
|
+
doc.removeEventListener('mousemove', handler);
|
|
2761
|
+
};
|
|
2762
|
+
return;
|
|
2763
|
+
}
|
|
2764
|
+
|
|
2765
|
+
// Allow interactivity without `safePolygon` on touch devices. With a
|
|
2766
|
+
// pointer, a short close delay is an alternative, so it should work
|
|
2767
|
+
// consistently.
|
|
2768
|
+
const shouldClose = pointerTypeRef.current === 'touch' ? !contains(elements.floating, event.relatedTarget) : true;
|
|
2769
|
+
if (shouldClose) {
|
|
2770
|
+
closeWithDelay(event);
|
|
2771
|
+
}
|
|
2772
|
+
}
|
|
2773
|
+
|
|
2774
|
+
// Ensure the floating element closes after scrolling even if the pointer
|
|
2775
|
+
// did not move.
|
|
2776
|
+
// https://github.com/floating-ui/floating-ui/discussions/1692
|
|
2777
|
+
function onScrollMouseLeave(event) {
|
|
2778
|
+
if (isClickLikeOpenEvent()) return;
|
|
2779
|
+
if (!dataRef.current.floatingContext) return;
|
|
2780
|
+
handleCloseRef.current == null || handleCloseRef.current({
|
|
2781
|
+
...dataRef.current.floatingContext,
|
|
2782
|
+
tree,
|
|
2783
|
+
x: event.clientX,
|
|
2784
|
+
y: event.clientY,
|
|
2785
|
+
onClose() {
|
|
2786
|
+
clearPointerEvents();
|
|
2787
|
+
cleanupMouseMoveHandler();
|
|
2788
|
+
closeWithDelay(event);
|
|
2789
|
+
}
|
|
2790
|
+
})(event);
|
|
2791
|
+
}
|
|
2792
|
+
if (isElement(elements.domReference)) {
|
|
2793
|
+
var _elements$floating;
|
|
2794
|
+
const ref = elements.domReference;
|
|
2795
|
+
open && ref.addEventListener('mouseleave', onScrollMouseLeave);
|
|
2796
|
+
(_elements$floating = elements.floating) == null || _elements$floating.addEventListener('mouseleave', onScrollMouseLeave);
|
|
2797
|
+
move && ref.addEventListener('mousemove', onMouseEnter, {
|
|
2798
|
+
once: true
|
|
2799
|
+
});
|
|
2800
|
+
ref.addEventListener('mouseenter', onMouseEnter);
|
|
2801
|
+
ref.addEventListener('mouseleave', onMouseLeave);
|
|
2802
|
+
return () => {
|
|
2803
|
+
var _elements$floating2;
|
|
2804
|
+
open && ref.removeEventListener('mouseleave', onScrollMouseLeave);
|
|
2805
|
+
(_elements$floating2 = elements.floating) == null || _elements$floating2.removeEventListener('mouseleave', onScrollMouseLeave);
|
|
2806
|
+
move && ref.removeEventListener('mousemove', onMouseEnter);
|
|
2807
|
+
ref.removeEventListener('mouseenter', onMouseEnter);
|
|
2808
|
+
ref.removeEventListener('mouseleave', onMouseLeave);
|
|
2809
|
+
};
|
|
2810
|
+
}
|
|
2811
|
+
}, [elements, enabled, context, mouseOnly, restMs, move, closeWithDelay, cleanupMouseMoveHandler, clearPointerEvents, onOpenChange, open, openRef, tree, delayRef, handleCloseRef, dataRef]);
|
|
2812
|
+
|
|
2813
|
+
// Block pointer-events of every element other than the reference and floating
|
|
2814
|
+
// while the floating element is open and has a `handleClose` handler. Also
|
|
2815
|
+
// handles nested floating elements.
|
|
2816
|
+
// https://github.com/floating-ui/floating-ui/issues/1722
|
|
2817
|
+
index(() => {
|
|
2818
|
+
var _handleCloseRef$curre;
|
|
2819
|
+
if (!enabled) return;
|
|
2820
|
+
if (open && (_handleCloseRef$curre = handleCloseRef.current) != null && _handleCloseRef$curre.__options.blockPointerEvents && isHoverOpen()) {
|
|
2821
|
+
performedPointerEventsMutationRef.current = true;
|
|
2822
|
+
const floatingEl = elements.floating;
|
|
2823
|
+
if (isElement(elements.domReference) && floatingEl) {
|
|
2824
|
+
var _tree$nodesRef$curren;
|
|
2825
|
+
const body = getDocument(elements.floating).body;
|
|
2826
|
+
body.setAttribute(safePolygonIdentifier, '');
|
|
2827
|
+
const ref = elements.domReference;
|
|
2828
|
+
const parentFloating = tree == null || (_tree$nodesRef$curren = tree.nodesRef.current.find(node => node.id === parentId)) == null || (_tree$nodesRef$curren = _tree$nodesRef$curren.context) == null ? void 0 : _tree$nodesRef$curren.elements.floating;
|
|
2829
|
+
if (parentFloating) {
|
|
2830
|
+
parentFloating.style.pointerEvents = '';
|
|
2831
|
+
}
|
|
2832
|
+
body.style.pointerEvents = 'none';
|
|
2833
|
+
ref.style.pointerEvents = 'auto';
|
|
2834
|
+
floatingEl.style.pointerEvents = 'auto';
|
|
2835
|
+
return () => {
|
|
2836
|
+
body.style.pointerEvents = '';
|
|
2837
|
+
ref.style.pointerEvents = '';
|
|
2838
|
+
floatingEl.style.pointerEvents = '';
|
|
2839
|
+
};
|
|
2840
|
+
}
|
|
2841
|
+
}
|
|
2842
|
+
}, [enabled, open, parentId, elements, tree, handleCloseRef, isHoverOpen]);
|
|
2843
|
+
index(() => {
|
|
2844
|
+
if (!open) {
|
|
2845
|
+
pointerTypeRef.current = undefined;
|
|
2846
|
+
cleanupMouseMoveHandler();
|
|
2847
|
+
clearPointerEvents();
|
|
2848
|
+
}
|
|
2849
|
+
}, [open, cleanupMouseMoveHandler, clearPointerEvents]);
|
|
2850
|
+
React.useEffect(() => {
|
|
2851
|
+
return () => {
|
|
2852
|
+
cleanupMouseMoveHandler();
|
|
2853
|
+
clearTimeout(timeoutRef.current);
|
|
2854
|
+
clearTimeout(restTimeoutRef.current);
|
|
2855
|
+
clearPointerEvents();
|
|
2856
|
+
};
|
|
2857
|
+
}, [enabled, elements.domReference, cleanupMouseMoveHandler, clearPointerEvents]);
|
|
2858
|
+
const reference = React.useMemo(() => {
|
|
2859
|
+
function setPointerRef(event) {
|
|
2860
|
+
pointerTypeRef.current = event.pointerType;
|
|
2861
|
+
}
|
|
2862
|
+
return {
|
|
2863
|
+
onPointerDown: setPointerRef,
|
|
2864
|
+
onPointerEnter: setPointerRef,
|
|
2865
|
+
onMouseMove(event) {
|
|
2866
|
+
const {
|
|
2867
|
+
nativeEvent
|
|
2868
|
+
} = event;
|
|
2869
|
+
function handleMouseMove() {
|
|
2870
|
+
if (!blockMouseMoveRef.current && !openRef.current) {
|
|
2871
|
+
onOpenChange(true, nativeEvent, 'hover');
|
|
2872
|
+
}
|
|
2873
|
+
}
|
|
2874
|
+
if (mouseOnly && !isMouseLikePointerType(pointerTypeRef.current)) {
|
|
2875
|
+
return;
|
|
2876
|
+
}
|
|
2877
|
+
if (open || restMs === 0) {
|
|
2878
|
+
return;
|
|
2879
|
+
}
|
|
2880
|
+
clearTimeout(restTimeoutRef.current);
|
|
2881
|
+
if (pointerTypeRef.current === 'touch') {
|
|
2882
|
+
handleMouseMove();
|
|
2883
|
+
} else {
|
|
2884
|
+
restTimeoutRef.current = window.setTimeout(handleMouseMove, restMs);
|
|
2885
|
+
}
|
|
2886
|
+
}
|
|
2887
|
+
};
|
|
2888
|
+
}, [mouseOnly, onOpenChange, open, openRef, restMs]);
|
|
2889
|
+
const floating = React.useMemo(() => ({
|
|
2890
|
+
onMouseEnter() {
|
|
2891
|
+
clearTimeout(timeoutRef.current);
|
|
2892
|
+
},
|
|
2893
|
+
onMouseLeave(event) {
|
|
2894
|
+
closeWithDelay(event.nativeEvent, false);
|
|
2895
|
+
}
|
|
2896
|
+
}), [closeWithDelay]);
|
|
2897
|
+
return React.useMemo(() => enabled ? {
|
|
2898
|
+
reference,
|
|
2899
|
+
floating
|
|
2900
|
+
} : {}, [enabled, reference, floating]);
|
|
2901
|
+
}
|
|
2902
|
+
|
|
2903
|
+
function getChildren(nodes, id) {
|
|
2904
|
+
let allChildren = nodes.filter(node => {
|
|
2905
|
+
var _node$context;
|
|
2906
|
+
return node.parentId === id && ((_node$context = node.context) == null ? void 0 : _node$context.open);
|
|
2907
|
+
});
|
|
2908
|
+
let currentChildren = allChildren;
|
|
2909
|
+
while (currentChildren.length) {
|
|
2910
|
+
currentChildren = nodes.filter(node => {
|
|
2911
|
+
var _currentChildren;
|
|
2912
|
+
return (_currentChildren = currentChildren) == null ? void 0 : _currentChildren.some(n => {
|
|
2913
|
+
var _node$context2;
|
|
2914
|
+
return node.parentId === n.id && ((_node$context2 = node.context) == null ? void 0 : _node$context2.open);
|
|
2915
|
+
});
|
|
2916
|
+
});
|
|
2917
|
+
allChildren = allChildren.concat(currentChildren);
|
|
2918
|
+
}
|
|
2919
|
+
return allChildren;
|
|
2920
|
+
}
|
|
2921
|
+
|
|
2922
|
+
const getTabbableOptions = () => ({
|
|
2923
|
+
getShadowRoot: true,
|
|
2924
|
+
displayCheck:
|
|
2925
|
+
// JSDOM does not support the `tabbable` library. To solve this we can
|
|
2926
|
+
// check if `ResizeObserver` is a real function (not polyfilled), which
|
|
2927
|
+
// determines if the current environment is JSDOM-like.
|
|
2928
|
+
typeof ResizeObserver === 'function' && ResizeObserver.toString().includes('[native code]') ? 'full' : 'none'
|
|
2929
|
+
});
|
|
2930
|
+
function getTabbableIn(container, direction) {
|
|
2931
|
+
const allTabbable = tabbable(container, getTabbableOptions());
|
|
2932
|
+
if (direction === 'prev') {
|
|
2933
|
+
allTabbable.reverse();
|
|
2934
|
+
}
|
|
2935
|
+
const activeIndex = allTabbable.indexOf(activeElement(getDocument(container)));
|
|
2936
|
+
const nextTabbableElements = allTabbable.slice(activeIndex + 1);
|
|
2937
|
+
return nextTabbableElements[0];
|
|
2938
|
+
}
|
|
2939
|
+
function getNextTabbable() {
|
|
2940
|
+
return getTabbableIn(document.body, 'next');
|
|
2941
|
+
}
|
|
2942
|
+
function getPreviousTabbable() {
|
|
2943
|
+
return getTabbableIn(document.body, 'prev');
|
|
2944
|
+
}
|
|
2945
|
+
function isOutsideEvent(event, container) {
|
|
2946
|
+
const containerElement = container || event.currentTarget;
|
|
2947
|
+
const relatedTarget = event.relatedTarget;
|
|
2948
|
+
return !relatedTarget || !contains(containerElement, relatedTarget);
|
|
2949
|
+
}
|
|
2950
|
+
function disableFocusInside(container) {
|
|
2951
|
+
const tabbableElements = tabbable(container, getTabbableOptions());
|
|
2952
|
+
tabbableElements.forEach(element => {
|
|
2953
|
+
element.dataset.tabindex = element.getAttribute('tabindex') || '';
|
|
2954
|
+
element.setAttribute('tabindex', '-1');
|
|
2955
|
+
});
|
|
2956
|
+
}
|
|
2957
|
+
function enableFocusInside(container) {
|
|
2958
|
+
const elements = container.querySelectorAll('[data-tabindex]');
|
|
2959
|
+
elements.forEach(element => {
|
|
2960
|
+
const tabindex = element.dataset.tabindex;
|
|
2961
|
+
delete element.dataset.tabindex;
|
|
2962
|
+
if (tabindex) {
|
|
2963
|
+
element.setAttribute('tabindex', tabindex);
|
|
2964
|
+
} else {
|
|
2965
|
+
element.removeAttribute('tabindex');
|
|
2966
|
+
}
|
|
2967
|
+
});
|
|
2968
|
+
}
|
|
2969
|
+
|
|
2970
|
+
// See Diego Haz's Sandbox for making this logic work well on Safari/iOS:
|
|
2971
|
+
// https://codesandbox.io/s/tabbable-portal-f4tng?file=/src/FocusTrap.tsx
|
|
2972
|
+
|
|
2973
|
+
const HIDDEN_STYLES = {
|
|
2974
|
+
border: 0,
|
|
2975
|
+
clip: 'rect(0 0 0 0)',
|
|
2976
|
+
height: '1px',
|
|
2977
|
+
margin: '-1px',
|
|
2978
|
+
overflow: 'hidden',
|
|
2979
|
+
padding: 0,
|
|
2980
|
+
position: 'fixed',
|
|
2981
|
+
whiteSpace: 'nowrap',
|
|
2982
|
+
width: '1px',
|
|
2983
|
+
top: 0,
|
|
2984
|
+
left: 0
|
|
2985
|
+
};
|
|
2986
|
+
let timeoutId;
|
|
2987
|
+
function setActiveElementOnTab(event) {
|
|
2988
|
+
if (event.key === 'Tab') {
|
|
2989
|
+
event.target;
|
|
2990
|
+
clearTimeout(timeoutId);
|
|
2991
|
+
}
|
|
2992
|
+
}
|
|
2993
|
+
const FocusGuard = /*#__PURE__*/React.forwardRef(function FocusGuard(props, ref) {
|
|
2994
|
+
const [role, setRole] = React.useState();
|
|
2995
|
+
index(() => {
|
|
2996
|
+
if (isSafari()) {
|
|
2997
|
+
// Unlike other screen readers such as NVDA and JAWS, the virtual cursor
|
|
2998
|
+
// on VoiceOver does trigger the onFocus event, so we can use the focus
|
|
2999
|
+
// trap element. On Safari, only buttons trigger the onFocus event.
|
|
3000
|
+
// NB: "group" role in the Sandbox no longer appears to work, must be a
|
|
3001
|
+
// button role.
|
|
3002
|
+
setRole('button');
|
|
3003
|
+
}
|
|
3004
|
+
document.addEventListener('keydown', setActiveElementOnTab);
|
|
3005
|
+
return () => {
|
|
3006
|
+
document.removeEventListener('keydown', setActiveElementOnTab);
|
|
3007
|
+
};
|
|
3008
|
+
}, []);
|
|
3009
|
+
const restProps = {
|
|
3010
|
+
ref,
|
|
3011
|
+
tabIndex: 0,
|
|
3012
|
+
// Role is only for VoiceOver
|
|
3013
|
+
role,
|
|
3014
|
+
'aria-hidden': role ? undefined : true,
|
|
3015
|
+
[createAttribute('focus-guard')]: '',
|
|
3016
|
+
style: HIDDEN_STYLES
|
|
3017
|
+
};
|
|
3018
|
+
return /*#__PURE__*/React.createElement("span", _extends({}, props, restProps));
|
|
3019
|
+
});
|
|
3020
|
+
|
|
3021
|
+
const PortalContext = /*#__PURE__*/React.createContext(null);
|
|
3022
|
+
const attr = /*#__PURE__*/createAttribute('portal');
|
|
3023
|
+
/**
|
|
3024
|
+
* @see https://floating-ui.com/docs/FloatingPortal#usefloatingportalnode
|
|
3025
|
+
*/
|
|
3026
|
+
function useFloatingPortalNode(props) {
|
|
3027
|
+
if (props === void 0) {
|
|
3028
|
+
props = {};
|
|
3029
|
+
}
|
|
3030
|
+
const {
|
|
3031
|
+
id,
|
|
3032
|
+
root
|
|
3033
|
+
} = props;
|
|
3034
|
+
const uniqueId = useId();
|
|
3035
|
+
const portalContext = usePortalContext();
|
|
3036
|
+
const [portalNode, setPortalNode] = React.useState(null);
|
|
3037
|
+
const portalNodeRef = React.useRef(null);
|
|
3038
|
+
index(() => {
|
|
3039
|
+
return () => {
|
|
3040
|
+
portalNode == null || portalNode.remove();
|
|
3041
|
+
// Allow the subsequent layout effects to create a new node on updates.
|
|
3042
|
+
// The portal node will still be cleaned up on unmount.
|
|
3043
|
+
// https://github.com/floating-ui/floating-ui/issues/2454
|
|
3044
|
+
queueMicrotask(() => {
|
|
3045
|
+
portalNodeRef.current = null;
|
|
3046
|
+
});
|
|
3047
|
+
};
|
|
3048
|
+
}, [portalNode]);
|
|
3049
|
+
index(() => {
|
|
3050
|
+
// Wait for the uniqueId to be generated before creating the portal node in
|
|
3051
|
+
// React <18 (using `useFloatingId` instead of the native `useId`).
|
|
3052
|
+
// https://github.com/floating-ui/floating-ui/issues/2778
|
|
3053
|
+
if (!uniqueId) return;
|
|
3054
|
+
if (portalNodeRef.current) return;
|
|
3055
|
+
const existingIdRoot = id ? document.getElementById(id) : null;
|
|
3056
|
+
if (!existingIdRoot) return;
|
|
3057
|
+
const subRoot = document.createElement('div');
|
|
3058
|
+
subRoot.id = uniqueId;
|
|
3059
|
+
subRoot.setAttribute(attr, '');
|
|
3060
|
+
existingIdRoot.appendChild(subRoot);
|
|
3061
|
+
portalNodeRef.current = subRoot;
|
|
3062
|
+
setPortalNode(subRoot);
|
|
3063
|
+
}, [id, uniqueId]);
|
|
3064
|
+
index(() => {
|
|
3065
|
+
if (!uniqueId) return;
|
|
3066
|
+
if (portalNodeRef.current) return;
|
|
3067
|
+
let container = root || (portalContext == null ? void 0 : portalContext.portalNode);
|
|
3068
|
+
if (container && !isElement(container)) container = container.current;
|
|
3069
|
+
container = container || document.body;
|
|
3070
|
+
let idWrapper = null;
|
|
3071
|
+
if (id) {
|
|
3072
|
+
idWrapper = document.createElement('div');
|
|
3073
|
+
idWrapper.id = id;
|
|
3074
|
+
container.appendChild(idWrapper);
|
|
3075
|
+
}
|
|
3076
|
+
const subRoot = document.createElement('div');
|
|
3077
|
+
subRoot.id = uniqueId;
|
|
3078
|
+
subRoot.setAttribute(attr, '');
|
|
3079
|
+
container = idWrapper || container;
|
|
3080
|
+
container.appendChild(subRoot);
|
|
3081
|
+
portalNodeRef.current = subRoot;
|
|
3082
|
+
setPortalNode(subRoot);
|
|
3083
|
+
}, [id, root, uniqueId, portalContext]);
|
|
3084
|
+
return portalNode;
|
|
3085
|
+
}
|
|
3086
|
+
/**
|
|
3087
|
+
* Portals the floating element into a given container element — by default,
|
|
3088
|
+
* outside of the app root and into the body.
|
|
3089
|
+
* This is necessary to ensure the floating element can appear outside any
|
|
3090
|
+
* potential parent containers that cause clipping (such as `overflow: hidden`),
|
|
3091
|
+
* while retaining its location in the React tree.
|
|
3092
|
+
* @see https://floating-ui.com/docs/FloatingPortal
|
|
3093
|
+
*/
|
|
3094
|
+
function FloatingPortal(props) {
|
|
3095
|
+
const {
|
|
3096
|
+
children,
|
|
3097
|
+
id,
|
|
3098
|
+
root = null,
|
|
3099
|
+
preserveTabOrder = true
|
|
3100
|
+
} = props;
|
|
3101
|
+
const portalNode = useFloatingPortalNode({
|
|
3102
|
+
id,
|
|
3103
|
+
root
|
|
3104
|
+
});
|
|
3105
|
+
const [focusManagerState, setFocusManagerState] = React.useState(null);
|
|
3106
|
+
const beforeOutsideRef = React.useRef(null);
|
|
3107
|
+
const afterOutsideRef = React.useRef(null);
|
|
3108
|
+
const beforeInsideRef = React.useRef(null);
|
|
3109
|
+
const afterInsideRef = React.useRef(null);
|
|
3110
|
+
const modal = focusManagerState == null ? void 0 : focusManagerState.modal;
|
|
3111
|
+
const open = focusManagerState == null ? void 0 : focusManagerState.open;
|
|
3112
|
+
const shouldRenderGuards =
|
|
3113
|
+
// The FocusManager and therefore floating element are currently open/
|
|
3114
|
+
// rendered.
|
|
3115
|
+
!!focusManagerState &&
|
|
3116
|
+
// Guards are only for non-modal focus management.
|
|
3117
|
+
!focusManagerState.modal &&
|
|
3118
|
+
// Don't render if unmount is transitioning.
|
|
3119
|
+
focusManagerState.open && preserveTabOrder && !!(root || portalNode);
|
|
3120
|
+
|
|
3121
|
+
// https://codesandbox.io/s/tabbable-portal-f4tng?file=/src/TabbablePortal.tsx
|
|
3122
|
+
React.useEffect(() => {
|
|
3123
|
+
if (!portalNode || !preserveTabOrder || modal) {
|
|
3124
|
+
return;
|
|
3125
|
+
}
|
|
3126
|
+
|
|
3127
|
+
// Make sure elements inside the portal element are tabbable only when the
|
|
3128
|
+
// portal has already been focused, either by tabbing into a focus trap
|
|
3129
|
+
// element outside or using the mouse.
|
|
3130
|
+
function onFocus(event) {
|
|
3131
|
+
if (portalNode && isOutsideEvent(event)) {
|
|
3132
|
+
const focusing = event.type === 'focusin';
|
|
3133
|
+
const manageFocus = focusing ? enableFocusInside : disableFocusInside;
|
|
3134
|
+
manageFocus(portalNode);
|
|
3135
|
+
}
|
|
3136
|
+
}
|
|
3137
|
+
// Listen to the event on the capture phase so they run before the focus
|
|
3138
|
+
// trap elements onFocus prop is called.
|
|
3139
|
+
portalNode.addEventListener('focusin', onFocus, true);
|
|
3140
|
+
portalNode.addEventListener('focusout', onFocus, true);
|
|
3141
|
+
return () => {
|
|
3142
|
+
portalNode.removeEventListener('focusin', onFocus, true);
|
|
3143
|
+
portalNode.removeEventListener('focusout', onFocus, true);
|
|
3144
|
+
};
|
|
3145
|
+
}, [portalNode, preserveTabOrder, modal]);
|
|
3146
|
+
React.useEffect(() => {
|
|
3147
|
+
if (!portalNode) return;
|
|
3148
|
+
if (open) return;
|
|
3149
|
+
enableFocusInside(portalNode);
|
|
3150
|
+
}, [open, portalNode]);
|
|
3151
|
+
return /*#__PURE__*/React.createElement(PortalContext.Provider, {
|
|
3152
|
+
value: React.useMemo(() => ({
|
|
3153
|
+
preserveTabOrder,
|
|
3154
|
+
beforeOutsideRef,
|
|
3155
|
+
afterOutsideRef,
|
|
3156
|
+
beforeInsideRef,
|
|
3157
|
+
afterInsideRef,
|
|
3158
|
+
portalNode,
|
|
3159
|
+
setFocusManagerState
|
|
3160
|
+
}), [preserveTabOrder, portalNode])
|
|
3161
|
+
}, shouldRenderGuards && portalNode && /*#__PURE__*/React.createElement(FocusGuard, {
|
|
3162
|
+
"data-type": "outside",
|
|
3163
|
+
ref: beforeOutsideRef,
|
|
3164
|
+
onFocus: event => {
|
|
3165
|
+
if (isOutsideEvent(event, portalNode)) {
|
|
3166
|
+
var _beforeInsideRef$curr;
|
|
3167
|
+
(_beforeInsideRef$curr = beforeInsideRef.current) == null || _beforeInsideRef$curr.focus();
|
|
3168
|
+
} else {
|
|
3169
|
+
const prevTabbable = getPreviousTabbable() || (focusManagerState == null ? void 0 : focusManagerState.refs.domReference.current);
|
|
3170
|
+
prevTabbable == null || prevTabbable.focus();
|
|
3171
|
+
}
|
|
3172
|
+
}
|
|
3173
|
+
}), shouldRenderGuards && portalNode && /*#__PURE__*/React.createElement("span", {
|
|
3174
|
+
"aria-owns": portalNode.id,
|
|
3175
|
+
style: HIDDEN_STYLES
|
|
3176
|
+
}), portalNode && /*#__PURE__*/ReactDOM.createPortal(children, portalNode), shouldRenderGuards && portalNode && /*#__PURE__*/React.createElement(FocusGuard, {
|
|
3177
|
+
"data-type": "outside",
|
|
3178
|
+
ref: afterOutsideRef,
|
|
3179
|
+
onFocus: event => {
|
|
3180
|
+
if (isOutsideEvent(event, portalNode)) {
|
|
3181
|
+
var _afterInsideRef$curre;
|
|
3182
|
+
(_afterInsideRef$curre = afterInsideRef.current) == null || _afterInsideRef$curre.focus();
|
|
3183
|
+
} else {
|
|
3184
|
+
const nextTabbable = getNextTabbable() || (focusManagerState == null ? void 0 : focusManagerState.refs.domReference.current);
|
|
3185
|
+
nextTabbable == null || nextTabbable.focus();
|
|
3186
|
+
(focusManagerState == null ? void 0 : focusManagerState.closeOnFocusOut) && (focusManagerState == null ? void 0 : focusManagerState.onOpenChange(false, event.nativeEvent, 'focus-out'));
|
|
3187
|
+
}
|
|
3188
|
+
}
|
|
3189
|
+
}));
|
|
3190
|
+
}
|
|
3191
|
+
const usePortalContext = () => React.useContext(PortalContext);
|
|
3192
|
+
|
|
3193
|
+
const FOCUSABLE_ATTRIBUTE = 'data-floating-ui-focusable';
|
|
3194
|
+
|
|
3195
|
+
function isButtonTarget(event) {
|
|
3196
|
+
return isHTMLElement(event.target) && event.target.tagName === 'BUTTON';
|
|
3197
|
+
}
|
|
3198
|
+
function isSpaceIgnored(element) {
|
|
3199
|
+
return isTypeableElement(element);
|
|
3200
|
+
}
|
|
3201
|
+
/**
|
|
3202
|
+
* Opens or closes the floating element when clicking the reference element.
|
|
3203
|
+
* @see https://floating-ui.com/docs/useClick
|
|
3204
|
+
*/
|
|
3205
|
+
function useClick(context, props) {
|
|
3206
|
+
if (props === void 0) {
|
|
3207
|
+
props = {};
|
|
3208
|
+
}
|
|
3209
|
+
const {
|
|
3210
|
+
open,
|
|
3211
|
+
onOpenChange,
|
|
3212
|
+
dataRef,
|
|
3213
|
+
elements: {
|
|
3214
|
+
domReference
|
|
3215
|
+
}
|
|
3216
|
+
} = context;
|
|
3217
|
+
const {
|
|
3218
|
+
enabled = true,
|
|
3219
|
+
event: eventOption = 'click',
|
|
3220
|
+
toggle = true,
|
|
3221
|
+
ignoreMouse = false,
|
|
3222
|
+
keyboardHandlers = true
|
|
3223
|
+
} = props;
|
|
3224
|
+
const pointerTypeRef = React.useRef();
|
|
3225
|
+
const didKeyDownRef = React.useRef(false);
|
|
3226
|
+
const reference = React.useMemo(() => ({
|
|
3227
|
+
onPointerDown(event) {
|
|
3228
|
+
pointerTypeRef.current = event.pointerType;
|
|
3229
|
+
},
|
|
3230
|
+
onMouseDown(event) {
|
|
3231
|
+
const pointerType = pointerTypeRef.current;
|
|
3232
|
+
|
|
3233
|
+
// Ignore all buttons except for the "main" button.
|
|
3234
|
+
// https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/button
|
|
3235
|
+
if (event.button !== 0) return;
|
|
3236
|
+
if (eventOption === 'click') return;
|
|
3237
|
+
if (isMouseLikePointerType(pointerType, true) && ignoreMouse) return;
|
|
3238
|
+
if (open && toggle && (dataRef.current.openEvent ? dataRef.current.openEvent.type === 'mousedown' : true)) {
|
|
3239
|
+
onOpenChange(false, event.nativeEvent, 'click');
|
|
3240
|
+
} else {
|
|
3241
|
+
// Prevent stealing focus from the floating element
|
|
3242
|
+
event.preventDefault();
|
|
3243
|
+
onOpenChange(true, event.nativeEvent, 'click');
|
|
3244
|
+
}
|
|
3245
|
+
},
|
|
3246
|
+
onClick(event) {
|
|
3247
|
+
const pointerType = pointerTypeRef.current;
|
|
3248
|
+
if (eventOption === 'mousedown' && pointerTypeRef.current) {
|
|
3249
|
+
pointerTypeRef.current = undefined;
|
|
3250
|
+
return;
|
|
3251
|
+
}
|
|
3252
|
+
if (isMouseLikePointerType(pointerType, true) && ignoreMouse) return;
|
|
3253
|
+
if (open && toggle && (dataRef.current.openEvent ? dataRef.current.openEvent.type === 'click' : true)) {
|
|
3254
|
+
onOpenChange(false, event.nativeEvent, 'click');
|
|
3255
|
+
} else {
|
|
3256
|
+
onOpenChange(true, event.nativeEvent, 'click');
|
|
3257
|
+
}
|
|
3258
|
+
},
|
|
3259
|
+
onKeyDown(event) {
|
|
3260
|
+
pointerTypeRef.current = undefined;
|
|
3261
|
+
if (event.defaultPrevented || !keyboardHandlers || isButtonTarget(event)) {
|
|
3262
|
+
return;
|
|
3263
|
+
}
|
|
3264
|
+
if (event.key === ' ' && !isSpaceIgnored(domReference)) {
|
|
3265
|
+
// Prevent scrolling
|
|
3266
|
+
event.preventDefault();
|
|
3267
|
+
didKeyDownRef.current = true;
|
|
3268
|
+
}
|
|
3269
|
+
if (event.key === 'Enter') {
|
|
3270
|
+
if (open && toggle) {
|
|
3271
|
+
onOpenChange(false, event.nativeEvent, 'click');
|
|
3272
|
+
} else {
|
|
3273
|
+
onOpenChange(true, event.nativeEvent, 'click');
|
|
3274
|
+
}
|
|
3275
|
+
}
|
|
3276
|
+
},
|
|
3277
|
+
onKeyUp(event) {
|
|
3278
|
+
if (event.defaultPrevented || !keyboardHandlers || isButtonTarget(event) || isSpaceIgnored(domReference)) {
|
|
3279
|
+
return;
|
|
3280
|
+
}
|
|
3281
|
+
if (event.key === ' ' && didKeyDownRef.current) {
|
|
3282
|
+
didKeyDownRef.current = false;
|
|
3283
|
+
if (open && toggle) {
|
|
3284
|
+
onOpenChange(false, event.nativeEvent, 'click');
|
|
3285
|
+
} else {
|
|
3286
|
+
onOpenChange(true, event.nativeEvent, 'click');
|
|
3287
|
+
}
|
|
3288
|
+
}
|
|
3289
|
+
}
|
|
3290
|
+
}), [dataRef, domReference, eventOption, ignoreMouse, keyboardHandlers, onOpenChange, open, toggle]);
|
|
3291
|
+
return React.useMemo(() => enabled ? {
|
|
3292
|
+
reference
|
|
3293
|
+
} : {}, [enabled, reference]);
|
|
3294
|
+
}
|
|
3295
|
+
|
|
3296
|
+
const bubbleHandlerKeys = {
|
|
3297
|
+
pointerdown: 'onPointerDown',
|
|
3298
|
+
mousedown: 'onMouseDown',
|
|
3299
|
+
click: 'onClick'
|
|
3300
|
+
};
|
|
3301
|
+
const captureHandlerKeys = {
|
|
3302
|
+
pointerdown: 'onPointerDownCapture',
|
|
3303
|
+
mousedown: 'onMouseDownCapture',
|
|
3304
|
+
click: 'onClickCapture'
|
|
3305
|
+
};
|
|
3306
|
+
const normalizeProp = normalizable => {
|
|
3307
|
+
var _normalizable$escapeK, _normalizable$outside;
|
|
3308
|
+
return {
|
|
3309
|
+
escapeKey: typeof normalizable === 'boolean' ? normalizable : (_normalizable$escapeK = normalizable == null ? void 0 : normalizable.escapeKey) != null ? _normalizable$escapeK : false,
|
|
3310
|
+
outsidePress: typeof normalizable === 'boolean' ? normalizable : (_normalizable$outside = normalizable == null ? void 0 : normalizable.outsidePress) != null ? _normalizable$outside : true
|
|
3311
|
+
};
|
|
3312
|
+
};
|
|
3313
|
+
/**
|
|
3314
|
+
* Closes the floating element when a dismissal is requested — by default, when
|
|
3315
|
+
* the user presses the `escape` key or outside of the floating element.
|
|
3316
|
+
* @see https://floating-ui.com/docs/useDismiss
|
|
3317
|
+
*/
|
|
3318
|
+
function useDismiss(context, props) {
|
|
3319
|
+
if (props === void 0) {
|
|
3320
|
+
props = {};
|
|
3321
|
+
}
|
|
3322
|
+
const {
|
|
3323
|
+
open,
|
|
3324
|
+
onOpenChange,
|
|
3325
|
+
elements,
|
|
3326
|
+
dataRef
|
|
3327
|
+
} = context;
|
|
3328
|
+
const {
|
|
3329
|
+
enabled = true,
|
|
3330
|
+
escapeKey = true,
|
|
3331
|
+
outsidePress: unstable_outsidePress = true,
|
|
3332
|
+
outsidePressEvent = 'pointerdown',
|
|
3333
|
+
referencePress = false,
|
|
3334
|
+
referencePressEvent = 'pointerdown',
|
|
3335
|
+
ancestorScroll = false,
|
|
3336
|
+
bubbles,
|
|
3337
|
+
capture
|
|
3338
|
+
} = props;
|
|
3339
|
+
const tree = useFloatingTree();
|
|
3340
|
+
const outsidePressFn = useEffectEvent(typeof unstable_outsidePress === 'function' ? unstable_outsidePress : () => false);
|
|
3341
|
+
const outsidePress = typeof unstable_outsidePress === 'function' ? outsidePressFn : unstable_outsidePress;
|
|
3342
|
+
const insideReactTreeRef = React.useRef(false);
|
|
3343
|
+
const endedOrStartedInsideRef = React.useRef(false);
|
|
3344
|
+
const {
|
|
3345
|
+
escapeKey: escapeKeyBubbles,
|
|
3346
|
+
outsidePress: outsidePressBubbles
|
|
3347
|
+
} = normalizeProp(bubbles);
|
|
3348
|
+
const {
|
|
3349
|
+
escapeKey: escapeKeyCapture,
|
|
3350
|
+
outsidePress: outsidePressCapture
|
|
3351
|
+
} = normalizeProp(capture);
|
|
3352
|
+
const closeOnEscapeKeyDown = useEffectEvent(event => {
|
|
3353
|
+
var _dataRef$current$floa;
|
|
3354
|
+
if (!open || !enabled || !escapeKey || event.key !== 'Escape') {
|
|
3355
|
+
return;
|
|
3356
|
+
}
|
|
3357
|
+
const nodeId = (_dataRef$current$floa = dataRef.current.floatingContext) == null ? void 0 : _dataRef$current$floa.nodeId;
|
|
3358
|
+
const children = tree ? getChildren(tree.nodesRef.current, nodeId) : [];
|
|
3359
|
+
if (!escapeKeyBubbles) {
|
|
3360
|
+
event.stopPropagation();
|
|
3361
|
+
if (children.length > 0) {
|
|
3362
|
+
let shouldDismiss = true;
|
|
3363
|
+
children.forEach(child => {
|
|
3364
|
+
var _child$context;
|
|
3365
|
+
if ((_child$context = child.context) != null && _child$context.open && !child.context.dataRef.current.__escapeKeyBubbles) {
|
|
3366
|
+
shouldDismiss = false;
|
|
3367
|
+
return;
|
|
3368
|
+
}
|
|
3369
|
+
});
|
|
3370
|
+
if (!shouldDismiss) {
|
|
3371
|
+
return;
|
|
3372
|
+
}
|
|
3373
|
+
}
|
|
3374
|
+
}
|
|
3375
|
+
onOpenChange(false, isReactEvent(event) ? event.nativeEvent : event, 'escape-key');
|
|
3376
|
+
});
|
|
3377
|
+
const closeOnEscapeKeyDownCapture = useEffectEvent(event => {
|
|
3378
|
+
var _getTarget2;
|
|
3379
|
+
const callback = () => {
|
|
3380
|
+
var _getTarget;
|
|
3381
|
+
closeOnEscapeKeyDown(event);
|
|
3382
|
+
(_getTarget = getTarget(event)) == null || _getTarget.removeEventListener('keydown', callback);
|
|
3383
|
+
};
|
|
3384
|
+
(_getTarget2 = getTarget(event)) == null || _getTarget2.addEventListener('keydown', callback);
|
|
3385
|
+
});
|
|
3386
|
+
const closeOnPressOutside = useEffectEvent(event => {
|
|
3387
|
+
var _dataRef$current$floa2;
|
|
3388
|
+
// Given developers can stop the propagation of the synthetic event,
|
|
3389
|
+
// we can only be confident with a positive value.
|
|
3390
|
+
const insideReactTree = insideReactTreeRef.current;
|
|
3391
|
+
insideReactTreeRef.current = false;
|
|
3392
|
+
|
|
3393
|
+
// When click outside is lazy (`click` event), handle dragging.
|
|
3394
|
+
// Don't close if:
|
|
3395
|
+
// - The click started inside the floating element.
|
|
3396
|
+
// - The click ended inside the floating element.
|
|
3397
|
+
const endedOrStartedInside = endedOrStartedInsideRef.current;
|
|
3398
|
+
endedOrStartedInsideRef.current = false;
|
|
3399
|
+
if (outsidePressEvent === 'click' && endedOrStartedInside) {
|
|
3400
|
+
return;
|
|
3401
|
+
}
|
|
3402
|
+
if (insideReactTree) {
|
|
3403
|
+
return;
|
|
3404
|
+
}
|
|
3405
|
+
if (typeof outsidePress === 'function' && !outsidePress(event)) {
|
|
3406
|
+
return;
|
|
3407
|
+
}
|
|
3408
|
+
const target = getTarget(event);
|
|
3409
|
+
const inertSelector = "[" + createAttribute('inert') + "]";
|
|
3410
|
+
const markers = getDocument(elements.floating).querySelectorAll(inertSelector);
|
|
3411
|
+
let targetRootAncestor = isElement(target) ? target : null;
|
|
3412
|
+
while (targetRootAncestor && !isLastTraversableNode(targetRootAncestor)) {
|
|
3413
|
+
const nextParent = getParentNode(targetRootAncestor);
|
|
3414
|
+
if (isLastTraversableNode(nextParent) || !isElement(nextParent)) {
|
|
3415
|
+
break;
|
|
3416
|
+
}
|
|
3417
|
+
targetRootAncestor = nextParent;
|
|
3418
|
+
}
|
|
3419
|
+
|
|
3420
|
+
// Check if the click occurred on a third-party element injected after the
|
|
3421
|
+
// floating element rendered.
|
|
3422
|
+
if (markers.length && isElement(target) && !isRootElement(target) &&
|
|
3423
|
+
// Clicked on a direct ancestor (e.g. FloatingOverlay).
|
|
3424
|
+
!contains(target, elements.floating) &&
|
|
3425
|
+
// If the target root element contains none of the markers, then the
|
|
3426
|
+
// element was injected after the floating element rendered.
|
|
3427
|
+
Array.from(markers).every(marker => !contains(targetRootAncestor, marker))) {
|
|
3428
|
+
return;
|
|
3429
|
+
}
|
|
3430
|
+
|
|
3431
|
+
// Check if the click occurred on the scrollbar
|
|
3432
|
+
if (isHTMLElement(target) && floating) {
|
|
3433
|
+
// In Firefox, `target.scrollWidth > target.clientWidth` for inline
|
|
3434
|
+
// elements.
|
|
3435
|
+
const canScrollX = target.clientWidth > 0 && target.scrollWidth > target.clientWidth;
|
|
3436
|
+
const canScrollY = target.clientHeight > 0 && target.scrollHeight > target.clientHeight;
|
|
3437
|
+
let xCond = canScrollY && event.offsetX > target.clientWidth;
|
|
3438
|
+
|
|
3439
|
+
// In some browsers it is possible to change the <body> (or window)
|
|
3440
|
+
// scrollbar to the left side, but is very rare and is difficult to
|
|
3441
|
+
// check for. Plus, for modal dialogs with backdrops, it is more
|
|
3442
|
+
// important that the backdrop is checked but not so much the window.
|
|
3443
|
+
if (canScrollY) {
|
|
3444
|
+
const isRTL = getComputedStyle$1(target).direction === 'rtl';
|
|
3445
|
+
if (isRTL) {
|
|
3446
|
+
xCond = event.offsetX <= target.offsetWidth - target.clientWidth;
|
|
3447
|
+
}
|
|
3448
|
+
}
|
|
3449
|
+
if (xCond || canScrollX && event.offsetY > target.clientHeight) {
|
|
3450
|
+
return;
|
|
3451
|
+
}
|
|
3452
|
+
}
|
|
3453
|
+
const nodeId = (_dataRef$current$floa2 = dataRef.current.floatingContext) == null ? void 0 : _dataRef$current$floa2.nodeId;
|
|
3454
|
+
const targetIsInsideChildren = tree && getChildren(tree.nodesRef.current, nodeId).some(node => {
|
|
3455
|
+
var _node$context;
|
|
3456
|
+
return isEventTargetWithin(event, (_node$context = node.context) == null ? void 0 : _node$context.elements.floating);
|
|
3457
|
+
});
|
|
3458
|
+
if (isEventTargetWithin(event, elements.floating) || isEventTargetWithin(event, elements.domReference) || targetIsInsideChildren) {
|
|
3459
|
+
return;
|
|
3460
|
+
}
|
|
3461
|
+
const children = tree ? getChildren(tree.nodesRef.current, nodeId) : [];
|
|
3462
|
+
if (children.length > 0) {
|
|
3463
|
+
let shouldDismiss = true;
|
|
3464
|
+
children.forEach(child => {
|
|
3465
|
+
var _child$context2;
|
|
3466
|
+
if ((_child$context2 = child.context) != null && _child$context2.open && !child.context.dataRef.current.__outsidePressBubbles) {
|
|
3467
|
+
shouldDismiss = false;
|
|
3468
|
+
return;
|
|
3469
|
+
}
|
|
3470
|
+
});
|
|
3471
|
+
if (!shouldDismiss) {
|
|
3472
|
+
return;
|
|
3473
|
+
}
|
|
3474
|
+
}
|
|
3475
|
+
onOpenChange(false, event, 'outside-press');
|
|
3476
|
+
});
|
|
3477
|
+
const closeOnPressOutsideCapture = useEffectEvent(event => {
|
|
3478
|
+
var _getTarget4;
|
|
3479
|
+
const callback = () => {
|
|
3480
|
+
var _getTarget3;
|
|
3481
|
+
closeOnPressOutside(event);
|
|
3482
|
+
(_getTarget3 = getTarget(event)) == null || _getTarget3.removeEventListener(outsidePressEvent, callback);
|
|
3483
|
+
};
|
|
3484
|
+
(_getTarget4 = getTarget(event)) == null || _getTarget4.addEventListener(outsidePressEvent, callback);
|
|
3485
|
+
});
|
|
3486
|
+
React.useEffect(() => {
|
|
3487
|
+
if (!open || !enabled) {
|
|
3488
|
+
return;
|
|
3489
|
+
}
|
|
3490
|
+
dataRef.current.__escapeKeyBubbles = escapeKeyBubbles;
|
|
3491
|
+
dataRef.current.__outsidePressBubbles = outsidePressBubbles;
|
|
3492
|
+
function onScroll(event) {
|
|
3493
|
+
onOpenChange(false, event, 'ancestor-scroll');
|
|
3494
|
+
}
|
|
3495
|
+
const doc = getDocument(elements.floating);
|
|
3496
|
+
escapeKey && doc.addEventListener('keydown', escapeKeyCapture ? closeOnEscapeKeyDownCapture : closeOnEscapeKeyDown, escapeKeyCapture);
|
|
3497
|
+
outsidePress && doc.addEventListener(outsidePressEvent, outsidePressCapture ? closeOnPressOutsideCapture : closeOnPressOutside, outsidePressCapture);
|
|
3498
|
+
let ancestors = [];
|
|
3499
|
+
if (ancestorScroll) {
|
|
3500
|
+
if (isElement(elements.domReference)) {
|
|
3501
|
+
ancestors = getOverflowAncestors(elements.domReference);
|
|
3502
|
+
}
|
|
3503
|
+
if (isElement(elements.floating)) {
|
|
3504
|
+
ancestors = ancestors.concat(getOverflowAncestors(elements.floating));
|
|
3505
|
+
}
|
|
3506
|
+
if (!isElement(elements.reference) && elements.reference && elements.reference.contextElement) {
|
|
3507
|
+
ancestors = ancestors.concat(getOverflowAncestors(elements.reference.contextElement));
|
|
3508
|
+
}
|
|
3509
|
+
}
|
|
3510
|
+
|
|
3511
|
+
// Ignore the visual viewport for scrolling dismissal (allow pinch-zoom)
|
|
3512
|
+
ancestors = ancestors.filter(ancestor => {
|
|
3513
|
+
var _doc$defaultView;
|
|
3514
|
+
return ancestor !== ((_doc$defaultView = doc.defaultView) == null ? void 0 : _doc$defaultView.visualViewport);
|
|
3515
|
+
});
|
|
3516
|
+
ancestors.forEach(ancestor => {
|
|
3517
|
+
ancestor.addEventListener('scroll', onScroll, {
|
|
3518
|
+
passive: true
|
|
3519
|
+
});
|
|
3520
|
+
});
|
|
3521
|
+
return () => {
|
|
3522
|
+
escapeKey && doc.removeEventListener('keydown', escapeKeyCapture ? closeOnEscapeKeyDownCapture : closeOnEscapeKeyDown, escapeKeyCapture);
|
|
3523
|
+
outsidePress && doc.removeEventListener(outsidePressEvent, outsidePressCapture ? closeOnPressOutsideCapture : closeOnPressOutside, outsidePressCapture);
|
|
3524
|
+
ancestors.forEach(ancestor => {
|
|
3525
|
+
ancestor.removeEventListener('scroll', onScroll);
|
|
3526
|
+
});
|
|
3527
|
+
};
|
|
3528
|
+
}, [dataRef, elements, escapeKey, outsidePress, outsidePressEvent, open, onOpenChange, ancestorScroll, enabled, escapeKeyBubbles, outsidePressBubbles, closeOnEscapeKeyDown, escapeKeyCapture, closeOnEscapeKeyDownCapture, closeOnPressOutside, outsidePressCapture, closeOnPressOutsideCapture]);
|
|
3529
|
+
React.useEffect(() => {
|
|
3530
|
+
insideReactTreeRef.current = false;
|
|
3531
|
+
}, [outsidePress, outsidePressEvent]);
|
|
3532
|
+
const reference = React.useMemo(() => ({
|
|
3533
|
+
onKeyDown: closeOnEscapeKeyDown,
|
|
3534
|
+
[bubbleHandlerKeys[referencePressEvent]]: event => {
|
|
3535
|
+
if (referencePress) {
|
|
3536
|
+
onOpenChange(false, event.nativeEvent, 'reference-press');
|
|
3537
|
+
}
|
|
3538
|
+
}
|
|
3539
|
+
}), [closeOnEscapeKeyDown, onOpenChange, referencePress, referencePressEvent]);
|
|
3540
|
+
const floating = React.useMemo(() => ({
|
|
3541
|
+
onKeyDown: closeOnEscapeKeyDown,
|
|
3542
|
+
onMouseDown() {
|
|
3543
|
+
endedOrStartedInsideRef.current = true;
|
|
3544
|
+
},
|
|
3545
|
+
onMouseUp() {
|
|
3546
|
+
endedOrStartedInsideRef.current = true;
|
|
3547
|
+
},
|
|
3548
|
+
[captureHandlerKeys[outsidePressEvent]]: () => {
|
|
3549
|
+
insideReactTreeRef.current = true;
|
|
3550
|
+
}
|
|
3551
|
+
}), [closeOnEscapeKeyDown, outsidePressEvent]);
|
|
3552
|
+
return React.useMemo(() => enabled ? {
|
|
3553
|
+
reference,
|
|
3554
|
+
floating
|
|
3555
|
+
} : {}, [enabled, reference, floating]);
|
|
3556
|
+
}
|
|
3557
|
+
|
|
3558
|
+
function useFloatingRootContext(options) {
|
|
3559
|
+
const {
|
|
3560
|
+
open = false,
|
|
3561
|
+
onOpenChange: onOpenChangeProp,
|
|
3562
|
+
elements: elementsProp
|
|
3563
|
+
} = options;
|
|
3564
|
+
const floatingId = useId();
|
|
3565
|
+
const dataRef = React.useRef({});
|
|
3566
|
+
const [events] = React.useState(() => createPubSub());
|
|
3567
|
+
const nested = useFloatingParentNodeId() != null;
|
|
3568
|
+
if (process.env.NODE_ENV !== "production") {
|
|
3569
|
+
const optionDomReference = elementsProp.reference;
|
|
3570
|
+
if (optionDomReference && !isElement(optionDomReference)) {
|
|
3571
|
+
error('Cannot pass a virtual element to the `elements.reference` option,', 'as it must be a real DOM element. Use `refs.setPositionReference()`', 'instead.');
|
|
3572
|
+
}
|
|
3573
|
+
}
|
|
3574
|
+
const [positionReference, setPositionReference] = React.useState(elementsProp.reference);
|
|
3575
|
+
const onOpenChange = useEffectEvent((open, event, reason) => {
|
|
3576
|
+
dataRef.current.openEvent = open ? event : undefined;
|
|
3577
|
+
events.emit('openchange', {
|
|
3578
|
+
open,
|
|
3579
|
+
event,
|
|
3580
|
+
reason,
|
|
3581
|
+
nested
|
|
3582
|
+
});
|
|
3583
|
+
onOpenChangeProp == null || onOpenChangeProp(open, event, reason);
|
|
3584
|
+
});
|
|
3585
|
+
const refs = React.useMemo(() => ({
|
|
3586
|
+
setPositionReference
|
|
3587
|
+
}), []);
|
|
3588
|
+
const elements = React.useMemo(() => ({
|
|
3589
|
+
reference: positionReference || elementsProp.reference || null,
|
|
3590
|
+
floating: elementsProp.floating || null,
|
|
3591
|
+
domReference: elementsProp.reference
|
|
3592
|
+
}), [positionReference, elementsProp.reference, elementsProp.floating]);
|
|
3593
|
+
return React.useMemo(() => ({
|
|
3594
|
+
dataRef,
|
|
3595
|
+
open,
|
|
3596
|
+
onOpenChange,
|
|
3597
|
+
elements,
|
|
3598
|
+
events,
|
|
3599
|
+
floatingId,
|
|
3600
|
+
refs
|
|
3601
|
+
}), [open, onOpenChange, elements, events, floatingId, refs]);
|
|
3602
|
+
}
|
|
3603
|
+
|
|
3604
|
+
/**
|
|
3605
|
+
* Provides data to position a floating element and context to add interactions.
|
|
3606
|
+
* @see https://floating-ui.com/docs/useFloating
|
|
3607
|
+
*/
|
|
3608
|
+
function useFloating(options) {
|
|
3609
|
+
if (options === void 0) {
|
|
3610
|
+
options = {};
|
|
3611
|
+
}
|
|
3612
|
+
const {
|
|
3613
|
+
nodeId
|
|
3614
|
+
} = options;
|
|
3615
|
+
const internalRootContext = useFloatingRootContext({
|
|
3616
|
+
...options,
|
|
3617
|
+
elements: {
|
|
3618
|
+
reference: null,
|
|
3619
|
+
floating: null,
|
|
3620
|
+
...options.elements
|
|
3621
|
+
}
|
|
3622
|
+
});
|
|
3623
|
+
const rootContext = options.rootContext || internalRootContext;
|
|
3624
|
+
const computedElements = rootContext.elements;
|
|
3625
|
+
const [_domReference, setDomReference] = React.useState(null);
|
|
3626
|
+
const [positionReference, _setPositionReference] = React.useState(null);
|
|
3627
|
+
const optionDomReference = computedElements == null ? void 0 : computedElements.reference;
|
|
3628
|
+
const domReference = optionDomReference || _domReference;
|
|
3629
|
+
const domReferenceRef = React.useRef(null);
|
|
3630
|
+
const tree = useFloatingTree();
|
|
3631
|
+
index(() => {
|
|
3632
|
+
if (domReference) {
|
|
3633
|
+
domReferenceRef.current = domReference;
|
|
3634
|
+
}
|
|
3635
|
+
}, [domReference]);
|
|
3636
|
+
const position = useFloating$1({
|
|
3637
|
+
...options,
|
|
3638
|
+
elements: {
|
|
3639
|
+
...computedElements,
|
|
3640
|
+
...(positionReference && {
|
|
3641
|
+
reference: positionReference
|
|
3642
|
+
})
|
|
3643
|
+
}
|
|
3644
|
+
});
|
|
3645
|
+
const setPositionReference = React.useCallback(node => {
|
|
3646
|
+
const computedPositionReference = isElement(node) ? {
|
|
3647
|
+
getBoundingClientRect: () => node.getBoundingClientRect(),
|
|
3648
|
+
contextElement: node
|
|
3649
|
+
} : node;
|
|
3650
|
+
// Store the positionReference in state if the DOM reference is specified externally via the
|
|
3651
|
+
// `elements.reference` option. This ensures that it won't be overridden on future renders.
|
|
3652
|
+
_setPositionReference(computedPositionReference);
|
|
3653
|
+
position.refs.setReference(computedPositionReference);
|
|
3654
|
+
}, [position.refs]);
|
|
3655
|
+
const setReference = React.useCallback(node => {
|
|
3656
|
+
if (isElement(node) || node === null) {
|
|
3657
|
+
domReferenceRef.current = node;
|
|
3658
|
+
setDomReference(node);
|
|
3659
|
+
}
|
|
3660
|
+
|
|
3661
|
+
// Backwards-compatibility for passing a virtual element to `reference`
|
|
3662
|
+
// after it has set the DOM reference.
|
|
3663
|
+
if (isElement(position.refs.reference.current) || position.refs.reference.current === null ||
|
|
3664
|
+
// Don't allow setting virtual elements using the old technique back to
|
|
3665
|
+
// `null` to support `positionReference` + an unstable `reference`
|
|
3666
|
+
// callback ref.
|
|
3667
|
+
node !== null && !isElement(node)) {
|
|
3668
|
+
position.refs.setReference(node);
|
|
3669
|
+
}
|
|
3670
|
+
}, [position.refs]);
|
|
3671
|
+
const refs = React.useMemo(() => ({
|
|
3672
|
+
...position.refs,
|
|
3673
|
+
setReference,
|
|
3674
|
+
setPositionReference,
|
|
3675
|
+
domReference: domReferenceRef
|
|
3676
|
+
}), [position.refs, setReference, setPositionReference]);
|
|
3677
|
+
const elements = React.useMemo(() => ({
|
|
3678
|
+
...position.elements,
|
|
3679
|
+
domReference: domReference
|
|
3680
|
+
}), [position.elements, domReference]);
|
|
3681
|
+
const context = React.useMemo(() => ({
|
|
3682
|
+
...position,
|
|
3683
|
+
...rootContext,
|
|
3684
|
+
refs,
|
|
3685
|
+
elements,
|
|
3686
|
+
nodeId
|
|
3687
|
+
}), [position, refs, elements, nodeId, rootContext]);
|
|
3688
|
+
index(() => {
|
|
3689
|
+
rootContext.dataRef.current.floatingContext = context;
|
|
3690
|
+
const node = tree == null ? void 0 : tree.nodesRef.current.find(node => node.id === nodeId);
|
|
3691
|
+
if (node) {
|
|
3692
|
+
node.context = context;
|
|
3693
|
+
}
|
|
3694
|
+
});
|
|
3695
|
+
return React.useMemo(() => ({
|
|
3696
|
+
...position,
|
|
3697
|
+
context,
|
|
3698
|
+
refs,
|
|
3699
|
+
elements
|
|
3700
|
+
}), [position, refs, elements, context]);
|
|
3701
|
+
}
|
|
3702
|
+
|
|
3703
|
+
const ACTIVE_KEY = 'active';
|
|
3704
|
+
const SELECTED_KEY = 'selected';
|
|
3705
|
+
function mergeProps(userProps, propsList, elementKey) {
|
|
3706
|
+
const map = new Map();
|
|
3707
|
+
const isItem = elementKey === 'item';
|
|
3708
|
+
let domUserProps = userProps;
|
|
3709
|
+
if (isItem && userProps) {
|
|
3710
|
+
const {
|
|
3711
|
+
[ACTIVE_KEY]: _,
|
|
3712
|
+
[SELECTED_KEY]: __,
|
|
3713
|
+
...validProps
|
|
3714
|
+
} = userProps;
|
|
3715
|
+
domUserProps = validProps;
|
|
3716
|
+
}
|
|
3717
|
+
return {
|
|
3718
|
+
...(elementKey === 'floating' && {
|
|
3719
|
+
tabIndex: -1,
|
|
3720
|
+
[FOCUSABLE_ATTRIBUTE]: ''
|
|
3721
|
+
}),
|
|
3722
|
+
...domUserProps,
|
|
3723
|
+
...propsList.map(value => {
|
|
3724
|
+
const propsOrGetProps = value ? value[elementKey] : null;
|
|
3725
|
+
if (typeof propsOrGetProps === 'function') {
|
|
3726
|
+
return userProps ? propsOrGetProps(userProps) : null;
|
|
3727
|
+
}
|
|
3728
|
+
return propsOrGetProps;
|
|
3729
|
+
}).concat(userProps).reduce((acc, props) => {
|
|
3730
|
+
if (!props) {
|
|
3731
|
+
return acc;
|
|
3732
|
+
}
|
|
3733
|
+
Object.entries(props).forEach(_ref => {
|
|
3734
|
+
let [key, value] = _ref;
|
|
3735
|
+
if (isItem && [ACTIVE_KEY, SELECTED_KEY].includes(key)) {
|
|
3736
|
+
return;
|
|
3737
|
+
}
|
|
3738
|
+
if (key.indexOf('on') === 0) {
|
|
3739
|
+
if (!map.has(key)) {
|
|
3740
|
+
map.set(key, []);
|
|
3741
|
+
}
|
|
3742
|
+
if (typeof value === 'function') {
|
|
3743
|
+
var _map$get;
|
|
3744
|
+
(_map$get = map.get(key)) == null || _map$get.push(value);
|
|
3745
|
+
acc[key] = function () {
|
|
3746
|
+
var _map$get2;
|
|
3747
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
3748
|
+
args[_key] = arguments[_key];
|
|
3749
|
+
}
|
|
3750
|
+
return (_map$get2 = map.get(key)) == null ? void 0 : _map$get2.map(fn => fn(...args)).find(val => val !== undefined);
|
|
3751
|
+
};
|
|
3752
|
+
}
|
|
3753
|
+
} else {
|
|
3754
|
+
acc[key] = value;
|
|
3755
|
+
}
|
|
3756
|
+
});
|
|
3757
|
+
return acc;
|
|
3758
|
+
}, {})
|
|
3759
|
+
};
|
|
3760
|
+
}
|
|
3761
|
+
/**
|
|
3762
|
+
* Merges an array of interaction hooks' props into prop getters, allowing
|
|
3763
|
+
* event handler functions to be composed together without overwriting one
|
|
3764
|
+
* another.
|
|
3765
|
+
* @see https://floating-ui.com/docs/useInteractions
|
|
3766
|
+
*/
|
|
3767
|
+
function useInteractions(propsList) {
|
|
3768
|
+
if (propsList === void 0) {
|
|
3769
|
+
propsList = [];
|
|
3770
|
+
}
|
|
3771
|
+
const referenceDeps = propsList.map(key => key == null ? void 0 : key.reference);
|
|
3772
|
+
const floatingDeps = propsList.map(key => key == null ? void 0 : key.floating);
|
|
3773
|
+
const itemDeps = propsList.map(key => key == null ? void 0 : key.item);
|
|
3774
|
+
const getReferenceProps = React.useCallback(userProps => mergeProps(userProps, propsList, 'reference'),
|
|
3775
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
3776
|
+
referenceDeps);
|
|
3777
|
+
const getFloatingProps = React.useCallback(userProps => mergeProps(userProps, propsList, 'floating'),
|
|
3778
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
3779
|
+
floatingDeps);
|
|
3780
|
+
const getItemProps = React.useCallback(userProps => mergeProps(userProps, propsList, 'item'),
|
|
3781
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
3782
|
+
itemDeps);
|
|
3783
|
+
return React.useMemo(() => ({
|
|
3784
|
+
getReferenceProps,
|
|
3785
|
+
getFloatingProps,
|
|
3786
|
+
getItemProps
|
|
3787
|
+
}), [getReferenceProps, getFloatingProps, getItemProps]);
|
|
3788
|
+
}
|
|
3789
|
+
|
|
3790
|
+
const componentRoleToAriaRoleMap = /*#__PURE__*/new Map([['select', 'listbox'], ['combobox', 'listbox'], ['label', false]]);
|
|
3791
|
+
|
|
3792
|
+
/**
|
|
3793
|
+
* Adds base screen reader props to the reference and floating elements for a
|
|
3794
|
+
* given floating element `role`.
|
|
3795
|
+
* @see https://floating-ui.com/docs/useRole
|
|
3796
|
+
*/
|
|
3797
|
+
function useRole(context, props) {
|
|
3798
|
+
var _componentRoleToAriaR;
|
|
3799
|
+
if (props === void 0) {
|
|
3800
|
+
props = {};
|
|
3801
|
+
}
|
|
3802
|
+
const {
|
|
3803
|
+
open,
|
|
3804
|
+
floatingId
|
|
3805
|
+
} = context;
|
|
3806
|
+
const {
|
|
3807
|
+
enabled = true,
|
|
3808
|
+
role = 'dialog'
|
|
3809
|
+
} = props;
|
|
3810
|
+
const ariaRole = (_componentRoleToAriaR = componentRoleToAriaRoleMap.get(role)) != null ? _componentRoleToAriaR : role;
|
|
3811
|
+
const referenceId = useId();
|
|
3812
|
+
const parentId = useFloatingParentNodeId();
|
|
3813
|
+
const isNested = parentId != null;
|
|
3814
|
+
const reference = React.useMemo(() => {
|
|
3815
|
+
if (ariaRole === 'tooltip' || role === 'label') {
|
|
3816
|
+
return {
|
|
3817
|
+
["aria-" + (role === 'label' ? 'labelledby' : 'describedby')]: open ? floatingId : undefined
|
|
3818
|
+
};
|
|
3819
|
+
}
|
|
3820
|
+
return {
|
|
3821
|
+
'aria-expanded': open ? 'true' : 'false',
|
|
3822
|
+
'aria-haspopup': ariaRole === 'alertdialog' ? 'dialog' : ariaRole,
|
|
3823
|
+
'aria-controls': open ? floatingId : undefined,
|
|
3824
|
+
...(ariaRole === 'listbox' && {
|
|
3825
|
+
role: 'combobox'
|
|
3826
|
+
}),
|
|
3827
|
+
...(ariaRole === 'menu' && {
|
|
3828
|
+
id: referenceId
|
|
3829
|
+
}),
|
|
3830
|
+
...(ariaRole === 'menu' && isNested && {
|
|
3831
|
+
role: 'menuitem'
|
|
3832
|
+
}),
|
|
3833
|
+
...(role === 'select' && {
|
|
3834
|
+
'aria-autocomplete': 'none'
|
|
3835
|
+
}),
|
|
3836
|
+
...(role === 'combobox' && {
|
|
3837
|
+
'aria-autocomplete': 'list'
|
|
3838
|
+
})
|
|
3839
|
+
};
|
|
3840
|
+
}, [ariaRole, floatingId, isNested, open, referenceId, role]);
|
|
3841
|
+
const floating = React.useMemo(() => {
|
|
3842
|
+
const floatingProps = {
|
|
3843
|
+
id: floatingId,
|
|
3844
|
+
...(ariaRole && {
|
|
3845
|
+
role: ariaRole
|
|
3846
|
+
})
|
|
3847
|
+
};
|
|
3848
|
+
if (ariaRole === 'tooltip' || role === 'label') {
|
|
3849
|
+
return floatingProps;
|
|
3850
|
+
}
|
|
3851
|
+
return {
|
|
3852
|
+
...floatingProps,
|
|
3853
|
+
...(ariaRole === 'menu' && {
|
|
3854
|
+
'aria-labelledby': referenceId
|
|
3855
|
+
})
|
|
3856
|
+
};
|
|
3857
|
+
}, [ariaRole, floatingId, referenceId, role]);
|
|
3858
|
+
const item = React.useCallback(_ref => {
|
|
3859
|
+
let {
|
|
3860
|
+
active,
|
|
3861
|
+
selected
|
|
3862
|
+
} = _ref;
|
|
3863
|
+
const commonProps = {
|
|
3864
|
+
role: 'option',
|
|
3865
|
+
...(active && {
|
|
3866
|
+
id: floatingId + "-option"
|
|
3867
|
+
})
|
|
3868
|
+
};
|
|
3869
|
+
|
|
3870
|
+
// For `menu`, we are unable to tell if the item is a `menuitemradio`
|
|
3871
|
+
// or `menuitemcheckbox`. For backwards-compatibility reasons, also
|
|
3872
|
+
// avoid defaulting to `menuitem` as it may overwrite custom role props.
|
|
3873
|
+
switch (role) {
|
|
3874
|
+
case 'select':
|
|
3875
|
+
return {
|
|
3876
|
+
...commonProps,
|
|
3877
|
+
'aria-selected': active && selected
|
|
3878
|
+
};
|
|
3879
|
+
case 'combobox':
|
|
3880
|
+
{
|
|
3881
|
+
return {
|
|
3882
|
+
...commonProps,
|
|
3883
|
+
...(active && {
|
|
3884
|
+
'aria-selected': true
|
|
3885
|
+
})
|
|
3886
|
+
};
|
|
3887
|
+
}
|
|
3888
|
+
}
|
|
3889
|
+
return {};
|
|
3890
|
+
}, [floatingId, role]);
|
|
3891
|
+
return React.useMemo(() => enabled ? {
|
|
3892
|
+
reference,
|
|
3893
|
+
floating,
|
|
3894
|
+
item
|
|
3895
|
+
} : {}, [enabled, reference, floating, item]);
|
|
3896
|
+
}
|
|
3897
|
+
|
|
3898
|
+
export { FloatingPortal as F, arrow as a, autoUpdate as b, useDismiss as c, useClick as d, useRole as e, flip as f, useInteractions as g, offset$2 as h, flip$2 as i, shift$2 as j, useHover as k, offset as o, platform as p, shift as s, useFloating as u };
|