@wix/site-ui 1.30.0 → 1.32.0
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/dist/1268.js +99 -0
- package/dist/1279.js +7 -0
- package/dist/1457.js +10 -0
- package/dist/1477.js +106 -0
- package/dist/1500.js +111 -0
- package/dist/167.js +6 -0
- package/dist/2274.js +34 -0
- package/dist/2287.js +17 -0
- package/dist/2418.js +31 -0
- package/dist/2801.js +20 -0
- package/dist/285.js +86 -0
- package/dist/2861.js +6 -0
- package/dist/3020.js +7 -0
- package/dist/3021.js +72 -0
- package/dist/3056.js +229 -0
- package/dist/3140.js +4 -0
- package/dist/3248.js +307 -0
- package/dist/3296.js +4 -0
- package/dist/3319.js +400 -0
- package/dist/3395.js +4 -0
- package/dist/3485.js +854 -0
- package/dist/353.js +14 -0
- package/dist/3670.js +418 -0
- package/dist/3829.js +113 -0
- package/dist/4026.js +12 -0
- package/dist/4143.js +46 -0
- package/dist/42.js +32 -0
- package/dist/4281.js +30 -0
- package/dist/4346.js +2 -0
- package/dist/4388.js +418 -0
- package/dist/4490.js +32 -0
- package/dist/4495.js +9 -0
- package/dist/4549.js +24 -0
- package/dist/4586.js +41 -0
- package/dist/4586.js.LICENSE.txt +19 -0
- package/dist/4707.js +19 -0
- package/dist/4723.js +7 -0
- package/dist/4745.js +7 -0
- package/dist/4768.js +35 -0
- package/dist/4922.js +15 -0
- package/dist/5036.js +17 -0
- package/dist/5085.js +20 -0
- package/dist/5299.js +597 -0
- package/dist/5659.js +4 -0
- package/dist/5778.js +10 -0
- package/dist/5864.js +86 -0
- package/dist/5992.js +913 -0
- package/dist/5992.js.LICENSE.txt +19 -0
- package/dist/6003.js +10 -0
- package/dist/6046.js +29 -0
- package/dist/6089.js +2355 -0
- package/dist/6107.js +10 -0
- package/dist/6247.js +20 -0
- package/dist/6270.js +487 -0
- package/dist/6329.js +32 -0
- package/dist/6330.js +30 -0
- package/dist/6499.js +7 -0
- package/dist/6535.js +71 -0
- package/dist/6588.js +382 -0
- package/dist/6706.js +16 -0
- package/dist/6825.js +7 -0
- package/dist/6882.js +1562 -0
- package/dist/6914.js +30 -0
- package/dist/7021.js +13 -0
- package/dist/7366.js +83 -0
- package/dist/7373.js +25 -0
- package/dist/7541.js +25 -0
- package/dist/7564.js +10 -0
- package/dist/7642.js +20 -0
- package/dist/7725.js +10 -0
- package/dist/7871.js +38 -0
- package/dist/8052.js +352 -0
- package/dist/8106.js +238 -0
- package/dist/8171.js +346 -0
- package/dist/8225.js +21 -0
- package/dist/8272.js +333 -0
- package/dist/8527.js +58 -0
- package/dist/8724.js +10 -0
- package/dist/8750.js +1920 -0
- package/dist/8758.js +43 -0
- package/dist/880.js +149 -0
- package/dist/8935.js +8 -0
- package/dist/8960.js +22 -0
- package/dist/8971.js +40 -0
- package/dist/8979.js +10 -0
- package/dist/8996.js +71 -0
- package/dist/904.js +121 -0
- package/dist/9048.js +52 -0
- package/dist/9087.js +256 -0
- package/dist/9189.js +158 -0
- package/dist/9255.js +136 -0
- package/dist/9352.js +148 -0
- package/dist/951.js +22 -0
- package/dist/9635.js +22 -0
- package/dist/9829.js +4 -0
- package/dist/9863.js +8 -0
- package/dist/Accordion/index.d.ts +569 -12
- package/dist/Accordion/index.js +423 -8
- package/dist/AlertDialog/index.d.ts +1417 -18
- package/dist/AlertDialog/index.js +34 -14
- package/dist/Autocomplete/index.d.ts +1861 -38
- package/dist/Autocomplete/index.js +98 -24
- package/dist/Avatar/index.d.ts +129 -7
- package/dist/Avatar/index.js +149 -6
- package/dist/Breadcrumbs/index.d.ts +960 -7
- package/dist/Breadcrumbs/index.js +5 -5
- package/dist/Button/index.d.ts +88 -6
- package/dist/Button/index.js +27 -3
- package/dist/Checkbox/index.d.ts +425 -5
- package/dist/Checkbox/index.js +45 -5
- package/dist/CheckboxGroup/index.d.ts +318 -3
- package/dist/CheckboxGroup/index.js +166 -3
- package/dist/Collapsible/index.d.ts +377 -7
- package/dist/Collapsible/index.js +160 -6
- package/dist/Combobox/index.d.ts +1984 -48
- package/dist/Combobox/index.js +352 -29
- package/dist/ContextMenu/index.d.ts +2340 -36
- package/dist/ContextMenu/index.js +197 -22
- package/dist/Dialog/index.d.ts +1355 -18
- package/dist/Dialog/index.js +16 -14
- package/dist/Drawer/index.d.ts +1653 -18
- package/dist/Drawer/index.js +2797 -20
- package/dist/Field/index.d.ts +655 -15
- package/dist/Field/index.js +677 -10
- package/dist/Fieldset/index.d.ts +94 -5
- package/dist/Fieldset/index.js +68 -5
- package/dist/Form/index.d.ts +331 -2
- package/dist/Form/index.js +106 -3
- package/dist/Input/index.d.ts +692 -3
- package/dist/Input/index.js +10 -3
- package/dist/Menu/index.d.ts +2301 -36
- package/dist/Menu/index.js +365 -26
- package/dist/Menubar/index.d.ts +2301 -3
- package/dist/Menubar/index.js +105 -3
- package/dist/Meter/index.d.ts +175 -11
- package/dist/Meter/index.js +129 -9
- package/dist/NavigationMenu/index.d.ts +978 -28
- package/dist/NavigationMenu/index.js +1034 -17
- package/dist/NumberField/index.d.ts +612 -15
- package/dist/NumberField/index.js +1409 -11
- package/dist/Popover/index.d.ts +1655 -20
- package/dist/Popover/index.js +792 -17
- package/dist/PreviewCard/index.d.ts +1523 -14
- package/dist/PreviewCard/index.js +679 -14
- package/dist/Progress/index.d.ts +183 -11
- package/dist/Progress/index.js +181 -9
- package/dist/Radio/index.d.ts +185 -6
- package/dist/Radio/index.js +253 -6
- package/dist/RadioGroup/index.d.ts +341 -2
- package/dist/RadioGroup/index.js +154 -3
- package/dist/ScrollArea/index.d.ts +265 -13
- package/dist/ScrollArea/index.js +892 -10
- package/dist/Select/index.d.ts +1493 -38
- package/dist/Select/index.js +1824 -23
- package/dist/Separator/index.d.ts +80 -6
- package/dist/Separator/index.js +3 -3
- package/dist/Slider/index.d.ts +678 -16
- package/dist/Slider/index.js +1199 -11
- package/dist/Switch/index.d.ts +393 -5
- package/dist/Switch/index.js +208 -6
- package/dist/Tabs/index.d.ts +523 -12
- package/dist/Tabs/index.js +685 -9
- package/dist/Toggle/index.d.ts +305 -2
- package/dist/Toggle/index.js +76 -3
- package/dist/ToggleGroup/index.d.ts +316 -2
- package/dist/ToggleGroup/index.js +102 -3
- package/dist/Toolbar/index.d.ts +282 -13
- package/dist/Toolbar/index.js +230 -9
- package/dist/Tooltip/index.d.ts +1572 -14
- package/dist/Tooltip/index.js +965 -14
- package/dist/index.d.ts +12749 -652
- package/dist/rslib-runtime.js +18 -0
- package/package.json +3 -3
package/dist/3485.js
ADDED
|
@@ -0,0 +1,854 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useMergedRefs, NOOP } from "./8272.js";
|
|
3
|
+
import { getWindow, isOverflowElement, getNodeName, isShadowRoot, isHTMLElement } from "./3829.js";
|
|
4
|
+
import { ownerDocument } from "./9829.js";
|
|
5
|
+
import { getTarget, contains, activeElement } from "./4549.js";
|
|
6
|
+
import { CLICK_TRIGGER_IDENTIFIER, FocusGuard_FocusGuard, focusable, getPreviousTabbable, isTabbable, isOutsideEvent, tabbable, usePortalContext, getNextTabbable } from "./4388.js";
|
|
7
|
+
import { useStableCallback } from "./7541.js";
|
|
8
|
+
import { getFloatingFocusElement, isTypeableCombobox, isTypeableElement } from "./8758.js";
|
|
9
|
+
import { useValueAsRef } from "./4707.js";
|
|
10
|
+
import { useFloatingTree } from "./285.js";
|
|
11
|
+
import { Timeout, useTimeout } from "./42.js";
|
|
12
|
+
import { useAnimationFrame, AnimationFrame } from "./8996.js";
|
|
13
|
+
import { stopEvent, isVirtualPointerEvent, isVirtualClick } from "./6330.js";
|
|
14
|
+
import { addEventListener } from "./4723.js";
|
|
15
|
+
import { mergeCleanups } from "./4495.js";
|
|
16
|
+
import { getNodeAncestors, getNodeChildren, createAttribute } from "./5992.js";
|
|
17
|
+
import { resolveRef } from "./880.js";
|
|
18
|
+
import { isElementVisible } from "./3319.js";
|
|
19
|
+
import { createChangeEventDetails } from "./4768.js";
|
|
20
|
+
import { focusOut, triggerHover, outsidePress } from "./2418.js";
|
|
21
|
+
import { useIsoLayoutEffect } from "./6499.js";
|
|
22
|
+
import { isIOS, isWebKit } from "./8971.js";
|
|
23
|
+
import { useValueChanged } from "./2801.js";
|
|
24
|
+
import * as __rspack_external_react from "react";
|
|
25
|
+
let rafId = 0;
|
|
26
|
+
function enqueueFocus(el, options = {}) {
|
|
27
|
+
const { preventScroll = false, sync = false, shouldFocus } = options;
|
|
28
|
+
cancelAnimationFrame(rafId);
|
|
29
|
+
function exec() {
|
|
30
|
+
if (shouldFocus && !shouldFocus()) return;
|
|
31
|
+
el?.focus({
|
|
32
|
+
preventScroll
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
if (sync) {
|
|
36
|
+
exec();
|
|
37
|
+
return NOOP;
|
|
38
|
+
}
|
|
39
|
+
const currentRafId = requestAnimationFrame(exec);
|
|
40
|
+
rafId = currentRafId;
|
|
41
|
+
return ()=>{
|
|
42
|
+
if (rafId === currentRafId) {
|
|
43
|
+
cancelAnimationFrame(currentRafId);
|
|
44
|
+
rafId = 0;
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
const counters = {
|
|
49
|
+
inert: new WeakMap(),
|
|
50
|
+
'aria-hidden': new WeakMap()
|
|
51
|
+
};
|
|
52
|
+
const markerName = 'data-base-ui-inert';
|
|
53
|
+
const uncontrolledElementsSets = {
|
|
54
|
+
inert: new WeakSet(),
|
|
55
|
+
'aria-hidden': new WeakSet()
|
|
56
|
+
};
|
|
57
|
+
let markerCounterMap = new WeakMap();
|
|
58
|
+
let lockCount = 0;
|
|
59
|
+
function getUncontrolledElementsSet(controlAttribute) {
|
|
60
|
+
return uncontrolledElementsSets[controlAttribute];
|
|
61
|
+
}
|
|
62
|
+
function unwrapHost(node) {
|
|
63
|
+
if (!node) return null;
|
|
64
|
+
return isShadowRoot(node) ? node.host : unwrapHost(node.parentNode);
|
|
65
|
+
}
|
|
66
|
+
const correctElements = (parent, targets)=>targets.map((target)=>{
|
|
67
|
+
if (parent.contains(target)) return target;
|
|
68
|
+
const correctedTarget = unwrapHost(target);
|
|
69
|
+
if (parent.contains(correctedTarget)) return correctedTarget;
|
|
70
|
+
return null;
|
|
71
|
+
}).filter((x)=>null != x);
|
|
72
|
+
const buildKeepSet = (targets)=>{
|
|
73
|
+
const keep = new Set();
|
|
74
|
+
targets.forEach((target)=>{
|
|
75
|
+
let node = target;
|
|
76
|
+
while(node && !keep.has(node)){
|
|
77
|
+
keep.add(node);
|
|
78
|
+
node = node.parentNode;
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
return keep;
|
|
82
|
+
};
|
|
83
|
+
const collectOutsideElements = (root, keepElements, stopElements)=>{
|
|
84
|
+
const outside = [];
|
|
85
|
+
const walk = (parent)=>{
|
|
86
|
+
if (!parent || stopElements.has(parent)) return;
|
|
87
|
+
Array.from(parent.children).forEach((node)=>{
|
|
88
|
+
if ("script" === getNodeName(node)) return;
|
|
89
|
+
if (keepElements.has(node)) walk(node);
|
|
90
|
+
else outside.push(node);
|
|
91
|
+
});
|
|
92
|
+
};
|
|
93
|
+
walk(root);
|
|
94
|
+
return outside;
|
|
95
|
+
};
|
|
96
|
+
function applyAttributeToOthers(uncorrectedAvoidElements, body, ariaHidden, inert, { mark = true, markerIgnoreElements = [] }) {
|
|
97
|
+
const controlAttribute = inert ? 'inert' : ariaHidden ? 'aria-hidden' : null;
|
|
98
|
+
let counterMap = null;
|
|
99
|
+
let uncontrolledElementsSet = null;
|
|
100
|
+
const avoidElements = correctElements(body, uncorrectedAvoidElements);
|
|
101
|
+
const markerIgnoreTargets = mark ? correctElements(body, markerIgnoreElements) : [];
|
|
102
|
+
const markerIgnoreSet = new Set(markerIgnoreTargets);
|
|
103
|
+
const markerTargets = mark ? collectOutsideElements(body, buildKeepSet(avoidElements), new Set(avoidElements)).filter((target)=>!markerIgnoreSet.has(target)) : [];
|
|
104
|
+
const hiddenElements = [];
|
|
105
|
+
const markedElements = [];
|
|
106
|
+
if (controlAttribute) {
|
|
107
|
+
const map = counters[controlAttribute];
|
|
108
|
+
const currentUncontrolledElementsSet = getUncontrolledElementsSet(controlAttribute);
|
|
109
|
+
uncontrolledElementsSet = currentUncontrolledElementsSet;
|
|
110
|
+
counterMap = map;
|
|
111
|
+
const ariaLiveElements = correctElements(body, Array.from(body.querySelectorAll('[aria-live]')));
|
|
112
|
+
const controlElements = avoidElements.concat(ariaLiveElements);
|
|
113
|
+
const controlTargets = collectOutsideElements(body, buildKeepSet(controlElements), new Set(controlElements));
|
|
114
|
+
controlTargets.forEach((node)=>{
|
|
115
|
+
const attr = node.getAttribute(controlAttribute);
|
|
116
|
+
const alreadyHidden = null !== attr && 'false' !== attr;
|
|
117
|
+
const counterValue = (map.get(node) || 0) + 1;
|
|
118
|
+
map.set(node, counterValue);
|
|
119
|
+
hiddenElements.push(node);
|
|
120
|
+
if (1 === counterValue && alreadyHidden) currentUncontrolledElementsSet.add(node);
|
|
121
|
+
if (!alreadyHidden) node.setAttribute(controlAttribute, 'inert' === controlAttribute ? '' : 'true');
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
if (mark) markerTargets.forEach((node)=>{
|
|
125
|
+
const markerValue = (markerCounterMap.get(node) || 0) + 1;
|
|
126
|
+
markerCounterMap.set(node, markerValue);
|
|
127
|
+
markedElements.push(node);
|
|
128
|
+
if (1 === markerValue) node.setAttribute(markerName, '');
|
|
129
|
+
});
|
|
130
|
+
lockCount += 1;
|
|
131
|
+
return ()=>{
|
|
132
|
+
if (counterMap) hiddenElements.forEach((element)=>{
|
|
133
|
+
const currentCounterValue = counterMap.get(element) || 0;
|
|
134
|
+
const counterValue = currentCounterValue - 1;
|
|
135
|
+
counterMap.set(element, counterValue);
|
|
136
|
+
if (!counterValue) {
|
|
137
|
+
if (!uncontrolledElementsSet?.has(element) && controlAttribute) element.removeAttribute(controlAttribute);
|
|
138
|
+
uncontrolledElementsSet?.delete(element);
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
if (mark) markedElements.forEach((element)=>{
|
|
142
|
+
const markerValue = (markerCounterMap.get(element) || 0) - 1;
|
|
143
|
+
markerCounterMap.set(element, markerValue);
|
|
144
|
+
if (!markerValue) element.removeAttribute(markerName);
|
|
145
|
+
});
|
|
146
|
+
lockCount -= 1;
|
|
147
|
+
if (!lockCount) {
|
|
148
|
+
counters.inert = new WeakMap();
|
|
149
|
+
counters['aria-hidden'] = new WeakMap();
|
|
150
|
+
uncontrolledElementsSets.inert = new WeakSet();
|
|
151
|
+
uncontrolledElementsSets['aria-hidden'] = new WeakSet();
|
|
152
|
+
markerCounterMap = new WeakMap();
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
function markOthers(avoidElements, options = {}) {
|
|
157
|
+
const { ariaHidden = false, inert = false, mark = true, markerIgnoreElements = [] } = options;
|
|
158
|
+
const body = ownerDocument(avoidElements[0]).body;
|
|
159
|
+
return applyAttributeToOthers(avoidElements, body, ariaHidden, inert, {
|
|
160
|
+
mark,
|
|
161
|
+
markerIgnoreElements
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
function getEventType(event, lastInteractionType) {
|
|
165
|
+
const win = getWindow(getTarget(event));
|
|
166
|
+
if (event instanceof win.KeyboardEvent) return 'keyboard';
|
|
167
|
+
if (event instanceof win.FocusEvent) return lastInteractionType || 'keyboard';
|
|
168
|
+
if ('pointerType' in event) return event.pointerType || 'keyboard';
|
|
169
|
+
if ('touches' in event) return 'touch';
|
|
170
|
+
if (event instanceof win.MouseEvent) return lastInteractionType || (0 === event.detail ? 'keyboard' : 'mouse');
|
|
171
|
+
return '';
|
|
172
|
+
}
|
|
173
|
+
const LIST_LIMIT = 20;
|
|
174
|
+
let previouslyFocusedElements = [];
|
|
175
|
+
function clearDisconnectedPreviouslyFocusedElements() {
|
|
176
|
+
previouslyFocusedElements = previouslyFocusedElements.filter((entry)=>entry.deref()?.isConnected);
|
|
177
|
+
}
|
|
178
|
+
function addPreviouslyFocusedElement(element) {
|
|
179
|
+
clearDisconnectedPreviouslyFocusedElements();
|
|
180
|
+
if (element && 'body' !== getNodeName(element)) {
|
|
181
|
+
previouslyFocusedElements.push(new WeakRef(element));
|
|
182
|
+
if (previouslyFocusedElements.length > LIST_LIMIT) previouslyFocusedElements = previouslyFocusedElements.slice(-LIST_LIMIT);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
function getPreviouslyFocusedElement() {
|
|
186
|
+
clearDisconnectedPreviouslyFocusedElements();
|
|
187
|
+
return previouslyFocusedElements[previouslyFocusedElements.length - 1]?.deref();
|
|
188
|
+
}
|
|
189
|
+
function getFirstTabbableElement(container) {
|
|
190
|
+
if (!container) return null;
|
|
191
|
+
if (isTabbable(container)) return container;
|
|
192
|
+
return tabbable(container)[0] || container;
|
|
193
|
+
}
|
|
194
|
+
function handleTabIndex(floatingFocusElement, orderRef) {
|
|
195
|
+
if (floatingFocusElement.hasAttribute('tabindex') && !floatingFocusElement.hasAttribute('data-tabindex')) return;
|
|
196
|
+
if (!orderRef.current.includes('floating') && !floatingFocusElement.getAttribute('role')?.includes('dialog')) return;
|
|
197
|
+
const focusableElements = focusable(floatingFocusElement);
|
|
198
|
+
const tabbableContent = focusableElements.filter((element)=>{
|
|
199
|
+
const dataTabIndex = element.getAttribute('data-tabindex') || '';
|
|
200
|
+
return isTabbable(element) || element.hasAttribute('data-tabindex') && !dataTabIndex.startsWith('-');
|
|
201
|
+
});
|
|
202
|
+
const tabIndex = floatingFocusElement.getAttribute('tabindex');
|
|
203
|
+
if (orderRef.current.includes('floating') || 0 === tabbableContent.length) {
|
|
204
|
+
if ('0' !== tabIndex) floatingFocusElement.setAttribute('tabindex', '0');
|
|
205
|
+
} else if ('-1' !== tabIndex || floatingFocusElement.hasAttribute('data-tabindex') && '-1' !== floatingFocusElement.getAttribute('data-tabindex')) {
|
|
206
|
+
floatingFocusElement.setAttribute('tabindex', '-1');
|
|
207
|
+
floatingFocusElement.setAttribute('data-tabindex', '-1');
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
function FloatingFocusManager(props) {
|
|
211
|
+
const { context, children, disabled = false, initialFocus = true, returnFocus = true, restoreFocus = false, modal = true, closeOnFocusOut = true, openInteractionType = '', nextFocusableElement, previousFocusableElement, beforeContentFocusGuardRef, externalTree, getInsideElements } = props;
|
|
212
|
+
const store = 'rootStore' in context ? context.rootStore : context;
|
|
213
|
+
const open = store.useState('open');
|
|
214
|
+
const domReference = store.useState('domReferenceElement');
|
|
215
|
+
const floating = store.useState('floatingElement');
|
|
216
|
+
const { events, dataRef } = store.context;
|
|
217
|
+
const getNodeId = useStableCallback(()=>dataRef.current.floatingContext?.nodeId);
|
|
218
|
+
const ignoreInitialFocus = false === initialFocus;
|
|
219
|
+
const isUntrappedTypeableCombobox = isTypeableCombobox(domReference) && ignoreInitialFocus;
|
|
220
|
+
const orderRef = __rspack_external_react.useRef([
|
|
221
|
+
'content'
|
|
222
|
+
]);
|
|
223
|
+
const initialFocusRef = useValueAsRef(initialFocus);
|
|
224
|
+
const returnFocusRef = useValueAsRef(returnFocus);
|
|
225
|
+
const openInteractionTypeRef = useValueAsRef(openInteractionType);
|
|
226
|
+
const tree = useFloatingTree(externalTree);
|
|
227
|
+
const portalContext = usePortalContext();
|
|
228
|
+
const preventReturnFocusRef = __rspack_external_react.useRef(false);
|
|
229
|
+
const isPointerDownRef = __rspack_external_react.useRef(false);
|
|
230
|
+
const pointerDownOutsideRef = __rspack_external_react.useRef(false);
|
|
231
|
+
const lastFocusedTabbableRef = __rspack_external_react.useRef(null);
|
|
232
|
+
const closeTypeRef = __rspack_external_react.useRef('');
|
|
233
|
+
const lastInteractionTypeRef = __rspack_external_react.useRef('');
|
|
234
|
+
const beforeGuardRef = __rspack_external_react.useRef(null);
|
|
235
|
+
const afterGuardRef = __rspack_external_react.useRef(null);
|
|
236
|
+
const mergedBeforeGuardRef = useMergedRefs(beforeGuardRef, beforeContentFocusGuardRef, portalContext?.beforeInsideRef);
|
|
237
|
+
const mergedAfterGuardRef = useMergedRefs(afterGuardRef, portalContext?.afterInsideRef);
|
|
238
|
+
const blurTimeout = useTimeout();
|
|
239
|
+
const pointerDownTimeout = useTimeout();
|
|
240
|
+
const restoreFocusFrame = useAnimationFrame();
|
|
241
|
+
const isInsidePortal = null != portalContext;
|
|
242
|
+
const floatingFocusElement = getFloatingFocusElement(floating);
|
|
243
|
+
const getTabbableContent = useStableCallback((container = floatingFocusElement)=>container ? tabbable(container) : []);
|
|
244
|
+
const getResolvedInsideElements = useStableCallback(()=>getInsideElements?.().filter((element)=>null != element) ?? []);
|
|
245
|
+
__rspack_external_react.useEffect(()=>{
|
|
246
|
+
if (disabled || !modal) return;
|
|
247
|
+
function onKeyDown(event) {
|
|
248
|
+
if ('Tab' === event.key) {
|
|
249
|
+
if (contains(floatingFocusElement, activeElement(ownerDocument(floatingFocusElement))) && 0 === getTabbableContent().length && !isUntrappedTypeableCombobox) stopEvent(event);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
const doc = ownerDocument(floatingFocusElement);
|
|
253
|
+
return addEventListener(doc, 'keydown', onKeyDown);
|
|
254
|
+
}, [
|
|
255
|
+
disabled,
|
|
256
|
+
floatingFocusElement,
|
|
257
|
+
modal,
|
|
258
|
+
isUntrappedTypeableCombobox,
|
|
259
|
+
getTabbableContent
|
|
260
|
+
]);
|
|
261
|
+
__rspack_external_react.useEffect(()=>{
|
|
262
|
+
if (disabled || !open) return;
|
|
263
|
+
const doc = ownerDocument(floatingFocusElement);
|
|
264
|
+
function clearPointerDownOutside() {
|
|
265
|
+
pointerDownOutsideRef.current = false;
|
|
266
|
+
}
|
|
267
|
+
function onPointerDown(event) {
|
|
268
|
+
const target = getTarget(event);
|
|
269
|
+
const insideElements = getResolvedInsideElements();
|
|
270
|
+
const pointerTargetInside = contains(floating, target) || contains(domReference, target) || contains(portalContext?.portalNode, target) || insideElements.some((element)=>element === target || contains(element, target));
|
|
271
|
+
pointerDownOutsideRef.current = !pointerTargetInside;
|
|
272
|
+
lastInteractionTypeRef.current = event.pointerType || 'keyboard';
|
|
273
|
+
if (target?.closest(`[${CLICK_TRIGGER_IDENTIFIER}]`)) isPointerDownRef.current = true;
|
|
274
|
+
}
|
|
275
|
+
function onKeyDown() {
|
|
276
|
+
lastInteractionTypeRef.current = 'keyboard';
|
|
277
|
+
}
|
|
278
|
+
return mergeCleanups(addEventListener(doc, 'pointerdown', onPointerDown, true), addEventListener(doc, 'pointerup', clearPointerDownOutside, true), addEventListener(doc, 'pointercancel', clearPointerDownOutside, true), addEventListener(doc, 'keydown', onKeyDown, true));
|
|
279
|
+
}, [
|
|
280
|
+
disabled,
|
|
281
|
+
floating,
|
|
282
|
+
domReference,
|
|
283
|
+
floatingFocusElement,
|
|
284
|
+
open,
|
|
285
|
+
portalContext,
|
|
286
|
+
getResolvedInsideElements
|
|
287
|
+
]);
|
|
288
|
+
__rspack_external_react.useEffect(()=>{
|
|
289
|
+
if (disabled || !closeOnFocusOut) return;
|
|
290
|
+
const doc = ownerDocument(floatingFocusElement);
|
|
291
|
+
function handlePointerDown() {
|
|
292
|
+
isPointerDownRef.current = true;
|
|
293
|
+
pointerDownTimeout.start(0, ()=>{
|
|
294
|
+
isPointerDownRef.current = false;
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
function handleFocusIn(event) {
|
|
298
|
+
const target = getTarget(event);
|
|
299
|
+
if (isTabbable(target)) lastFocusedTabbableRef.current = target;
|
|
300
|
+
}
|
|
301
|
+
function handleFocusOutside(event) {
|
|
302
|
+
const relatedTarget = event.relatedTarget;
|
|
303
|
+
const currentTarget = event.currentTarget;
|
|
304
|
+
const target = getTarget(event);
|
|
305
|
+
queueMicrotask(()=>{
|
|
306
|
+
const nodeId = getNodeId();
|
|
307
|
+
const triggers = store.context.triggerElements;
|
|
308
|
+
const insideElements = getResolvedInsideElements();
|
|
309
|
+
const isRelatedFocusGuard = relatedTarget?.hasAttribute(createAttribute('focus-guard')) && [
|
|
310
|
+
beforeGuardRef.current,
|
|
311
|
+
afterGuardRef.current,
|
|
312
|
+
portalContext?.beforeInsideRef.current,
|
|
313
|
+
portalContext?.afterInsideRef.current,
|
|
314
|
+
portalContext?.beforeOutsideRef.current,
|
|
315
|
+
portalContext?.afterOutsideRef.current,
|
|
316
|
+
resolveRef(previousFocusableElement),
|
|
317
|
+
resolveRef(nextFocusableElement)
|
|
318
|
+
].includes(relatedTarget);
|
|
319
|
+
const movedToUnrelatedNode = !(contains(domReference, relatedTarget) || contains(floating, relatedTarget) || contains(relatedTarget, floating) || contains(portalContext?.portalNode, relatedTarget) || insideElements.some((element)=>element === relatedTarget || contains(element, relatedTarget)) || null != relatedTarget && triggers.hasElement(relatedTarget) || triggers.hasMatchingElement((trigger)=>contains(trigger, relatedTarget)) || isRelatedFocusGuard || tree && (getNodeChildren(tree.nodesRef.current, nodeId).find((node)=>contains(node.context?.elements.floating, relatedTarget) || contains(node.context?.elements.domReference, relatedTarget)) || getNodeAncestors(tree.nodesRef.current, nodeId).find((node)=>[
|
|
320
|
+
node.context?.elements.floating,
|
|
321
|
+
getFloatingFocusElement(node.context?.elements.floating)
|
|
322
|
+
].includes(relatedTarget) || node.context?.elements.domReference === relatedTarget)));
|
|
323
|
+
if (currentTarget === domReference && floatingFocusElement) handleTabIndex(floatingFocusElement, orderRef);
|
|
324
|
+
if (restoreFocus && currentTarget !== domReference && !isElementVisible(target) && activeElement(doc) === doc.body) {
|
|
325
|
+
if (isHTMLElement(floatingFocusElement)) {
|
|
326
|
+
floatingFocusElement.focus();
|
|
327
|
+
if ('popup' === restoreFocus) return void restoreFocusFrame.request(()=>{
|
|
328
|
+
floatingFocusElement.focus();
|
|
329
|
+
});
|
|
330
|
+
}
|
|
331
|
+
const tabbableContent = getTabbableContent();
|
|
332
|
+
const prevTabbable = lastFocusedTabbableRef.current;
|
|
333
|
+
const nodeToFocus = (prevTabbable && tabbableContent.includes(prevTabbable) ? prevTabbable : null) || tabbableContent[tabbableContent.length - 1] || floatingFocusElement;
|
|
334
|
+
if (isHTMLElement(nodeToFocus)) nodeToFocus.focus();
|
|
335
|
+
}
|
|
336
|
+
if (dataRef.current.insideReactTree) {
|
|
337
|
+
dataRef.current.insideReactTree = false;
|
|
338
|
+
return;
|
|
339
|
+
}
|
|
340
|
+
if ((isUntrappedTypeableCombobox ? true : !modal) && relatedTarget && movedToUnrelatedNode && !isPointerDownRef.current && (isUntrappedTypeableCombobox || relatedTarget !== getPreviouslyFocusedElement())) {
|
|
341
|
+
preventReturnFocusRef.current = true;
|
|
342
|
+
store.setOpen(false, createChangeEventDetails(focusOut, event));
|
|
343
|
+
}
|
|
344
|
+
});
|
|
345
|
+
}
|
|
346
|
+
function markInsideReactTree() {
|
|
347
|
+
if (pointerDownOutsideRef.current) return;
|
|
348
|
+
dataRef.current.insideReactTree = true;
|
|
349
|
+
blurTimeout.start(0, ()=>{
|
|
350
|
+
dataRef.current.insideReactTree = false;
|
|
351
|
+
});
|
|
352
|
+
}
|
|
353
|
+
const domReferenceElement = isHTMLElement(domReference) ? domReference : null;
|
|
354
|
+
if (!floating && !domReferenceElement) return;
|
|
355
|
+
return mergeCleanups(domReferenceElement && addEventListener(domReferenceElement, 'focusout', handleFocusOutside), domReferenceElement && addEventListener(domReferenceElement, 'pointerdown', handlePointerDown), floating && addEventListener(floating, 'focusin', handleFocusIn), floating && addEventListener(floating, 'focusout', handleFocusOutside), floating && portalContext && addEventListener(floating, 'focusout', markInsideReactTree, true));
|
|
356
|
+
}, [
|
|
357
|
+
disabled,
|
|
358
|
+
domReference,
|
|
359
|
+
floating,
|
|
360
|
+
floatingFocusElement,
|
|
361
|
+
modal,
|
|
362
|
+
tree,
|
|
363
|
+
portalContext,
|
|
364
|
+
store,
|
|
365
|
+
closeOnFocusOut,
|
|
366
|
+
restoreFocus,
|
|
367
|
+
getTabbableContent,
|
|
368
|
+
isUntrappedTypeableCombobox,
|
|
369
|
+
getNodeId,
|
|
370
|
+
orderRef,
|
|
371
|
+
dataRef,
|
|
372
|
+
blurTimeout,
|
|
373
|
+
pointerDownTimeout,
|
|
374
|
+
restoreFocusFrame,
|
|
375
|
+
nextFocusableElement,
|
|
376
|
+
previousFocusableElement,
|
|
377
|
+
getResolvedInsideElements
|
|
378
|
+
]);
|
|
379
|
+
__rspack_external_react.useEffect(()=>{
|
|
380
|
+
if (disabled || !floating || !open) return;
|
|
381
|
+
const portalNodes = Array.from(portalContext?.portalNode?.querySelectorAll(`[${createAttribute('portal')}]`) || []);
|
|
382
|
+
const ancestors = tree ? getNodeAncestors(tree.nodesRef.current, getNodeId()) : [];
|
|
383
|
+
const rootAncestorComboboxDomReference = ancestors.find((node)=>isTypeableCombobox(node.context?.elements.domReference || null))?.context?.elements.domReference;
|
|
384
|
+
const controlInsideElements = [
|
|
385
|
+
floating,
|
|
386
|
+
...portalNodes,
|
|
387
|
+
beforeGuardRef.current,
|
|
388
|
+
afterGuardRef.current,
|
|
389
|
+
portalContext?.beforeOutsideRef.current,
|
|
390
|
+
portalContext?.afterOutsideRef.current,
|
|
391
|
+
...getResolvedInsideElements()
|
|
392
|
+
];
|
|
393
|
+
const insideElements = [
|
|
394
|
+
...controlInsideElements,
|
|
395
|
+
rootAncestorComboboxDomReference,
|
|
396
|
+
resolveRef(previousFocusableElement),
|
|
397
|
+
resolveRef(nextFocusableElement),
|
|
398
|
+
isUntrappedTypeableCombobox ? domReference : null
|
|
399
|
+
].filter((x)=>null != x);
|
|
400
|
+
const ariaHiddenCleanup = markOthers(insideElements, {
|
|
401
|
+
ariaHidden: modal || isUntrappedTypeableCombobox,
|
|
402
|
+
mark: false
|
|
403
|
+
});
|
|
404
|
+
const markerInsideElements = [
|
|
405
|
+
floating,
|
|
406
|
+
...portalNodes
|
|
407
|
+
].filter((x)=>null != x);
|
|
408
|
+
const markerCleanup = markOthers(markerInsideElements);
|
|
409
|
+
return ()=>{
|
|
410
|
+
markerCleanup();
|
|
411
|
+
ariaHiddenCleanup();
|
|
412
|
+
};
|
|
413
|
+
}, [
|
|
414
|
+
open,
|
|
415
|
+
disabled,
|
|
416
|
+
domReference,
|
|
417
|
+
floating,
|
|
418
|
+
modal,
|
|
419
|
+
portalContext,
|
|
420
|
+
isUntrappedTypeableCombobox,
|
|
421
|
+
tree,
|
|
422
|
+
getNodeId,
|
|
423
|
+
nextFocusableElement,
|
|
424
|
+
previousFocusableElement,
|
|
425
|
+
getResolvedInsideElements
|
|
426
|
+
]);
|
|
427
|
+
useIsoLayoutEffect(()=>{
|
|
428
|
+
if (!open || disabled || !isHTMLElement(floatingFocusElement)) return;
|
|
429
|
+
const doc = ownerDocument(floatingFocusElement);
|
|
430
|
+
const previouslyFocusedElement = activeElement(doc);
|
|
431
|
+
queueMicrotask(()=>{
|
|
432
|
+
const initialFocusValueOrFn = initialFocusRef.current;
|
|
433
|
+
const resolvedInitialFocus = 'function' == typeof initialFocusValueOrFn ? initialFocusValueOrFn(openInteractionTypeRef.current || '') : initialFocusValueOrFn;
|
|
434
|
+
if (void 0 === resolvedInitialFocus || false === resolvedInitialFocus) return;
|
|
435
|
+
const focusAlreadyInsideFloatingEl = contains(floatingFocusElement, previouslyFocusedElement);
|
|
436
|
+
if (focusAlreadyInsideFloatingEl) return;
|
|
437
|
+
let focusableElements = null;
|
|
438
|
+
const getDefaultFocusElement = ()=>{
|
|
439
|
+
if (null == focusableElements) focusableElements = getTabbableContent(floatingFocusElement);
|
|
440
|
+
return focusableElements[0] || floatingFocusElement;
|
|
441
|
+
};
|
|
442
|
+
let elToFocus;
|
|
443
|
+
elToFocus = true === resolvedInitialFocus || null === resolvedInitialFocus ? getDefaultFocusElement() : resolveRef(resolvedInitialFocus);
|
|
444
|
+
elToFocus = elToFocus || getDefaultFocusElement();
|
|
445
|
+
const hadFocusInside = contains(floatingFocusElement, activeElement(doc));
|
|
446
|
+
enqueueFocus(elToFocus, {
|
|
447
|
+
preventScroll: elToFocus === floatingFocusElement,
|
|
448
|
+
shouldFocus () {
|
|
449
|
+
if (hadFocusInside) return true;
|
|
450
|
+
const currentActiveElement = activeElement(doc);
|
|
451
|
+
const focusMovedInside = currentActiveElement !== elToFocus && contains(floatingFocusElement, currentActiveElement);
|
|
452
|
+
return !focusMovedInside;
|
|
453
|
+
}
|
|
454
|
+
});
|
|
455
|
+
});
|
|
456
|
+
}, [
|
|
457
|
+
disabled,
|
|
458
|
+
open,
|
|
459
|
+
floatingFocusElement,
|
|
460
|
+
getTabbableContent,
|
|
461
|
+
initialFocusRef,
|
|
462
|
+
openInteractionTypeRef
|
|
463
|
+
]);
|
|
464
|
+
useIsoLayoutEffect(()=>{
|
|
465
|
+
if (disabled || !floatingFocusElement) return;
|
|
466
|
+
const doc = ownerDocument(floatingFocusElement);
|
|
467
|
+
const previouslyFocusedElement = activeElement(doc);
|
|
468
|
+
addPreviouslyFocusedElement(previouslyFocusedElement);
|
|
469
|
+
function onOpenChangeLocal(details) {
|
|
470
|
+
if (!details.open) closeTypeRef.current = getEventType(details.nativeEvent, lastInteractionTypeRef.current);
|
|
471
|
+
if (details.reason === triggerHover && 'mouseleave' === details.nativeEvent.type) preventReturnFocusRef.current = true;
|
|
472
|
+
if (details.reason !== outsidePress) return;
|
|
473
|
+
if (details.nested) preventReturnFocusRef.current = false;
|
|
474
|
+
else if (isVirtualClick(details.nativeEvent) || isVirtualPointerEvent(details.nativeEvent)) preventReturnFocusRef.current = false;
|
|
475
|
+
else {
|
|
476
|
+
let isPreventScrollSupported = false;
|
|
477
|
+
ownerDocument(floatingFocusElement).createElement('div').focus({
|
|
478
|
+
get preventScroll () {
|
|
479
|
+
isPreventScrollSupported = true;
|
|
480
|
+
return false;
|
|
481
|
+
}
|
|
482
|
+
});
|
|
483
|
+
if (isPreventScrollSupported) preventReturnFocusRef.current = false;
|
|
484
|
+
else preventReturnFocusRef.current = true;
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
events.on('openchange', onOpenChangeLocal);
|
|
488
|
+
function getReturnElement() {
|
|
489
|
+
const returnFocusValueOrFn = returnFocusRef.current;
|
|
490
|
+
let resolvedReturnFocusValue = 'function' == typeof returnFocusValueOrFn ? returnFocusValueOrFn(closeTypeRef.current) : returnFocusValueOrFn;
|
|
491
|
+
if (void 0 === resolvedReturnFocusValue || false === resolvedReturnFocusValue) return null;
|
|
492
|
+
if (null === resolvedReturnFocusValue) resolvedReturnFocusValue = true;
|
|
493
|
+
if ('boolean' == typeof resolvedReturnFocusValue) {
|
|
494
|
+
if (domReference?.isConnected) return domReference;
|
|
495
|
+
return getPreviouslyFocusedElement() || null;
|
|
496
|
+
}
|
|
497
|
+
const fallback = domReference?.isConnected ? domReference : getPreviouslyFocusedElement();
|
|
498
|
+
return resolveRef(resolvedReturnFocusValue) || fallback || null;
|
|
499
|
+
}
|
|
500
|
+
return ()=>{
|
|
501
|
+
events.off('openchange', onOpenChangeLocal);
|
|
502
|
+
const activeEl = activeElement(doc);
|
|
503
|
+
const insideElements = getResolvedInsideElements();
|
|
504
|
+
const isFocusInsideFloatingTree = contains(floating, activeEl) || insideElements.some((element)=>element === activeEl || contains(element, activeEl)) || tree && getNodeChildren(tree.nodesRef.current, getNodeId(), false).some((node)=>contains(node.context?.elements.floating, activeEl));
|
|
505
|
+
const returnFocusValueOrFn = returnFocusRef.current;
|
|
506
|
+
const returnElement = getReturnElement();
|
|
507
|
+
queueMicrotask(()=>{
|
|
508
|
+
const tabbableReturnElement = getFirstTabbableElement(returnElement);
|
|
509
|
+
const hasExplicitReturnFocus = 'boolean' != typeof returnFocusValueOrFn;
|
|
510
|
+
if (returnFocusValueOrFn && !preventReturnFocusRef.current && isHTMLElement(tabbableReturnElement) && (hasExplicitReturnFocus || tabbableReturnElement === activeEl || activeEl === doc.body ? true : isFocusInsideFloatingTree)) tabbableReturnElement.focus({
|
|
511
|
+
preventScroll: true
|
|
512
|
+
});
|
|
513
|
+
preventReturnFocusRef.current = false;
|
|
514
|
+
});
|
|
515
|
+
};
|
|
516
|
+
}, [
|
|
517
|
+
disabled,
|
|
518
|
+
floating,
|
|
519
|
+
floatingFocusElement,
|
|
520
|
+
returnFocusRef,
|
|
521
|
+
events,
|
|
522
|
+
tree,
|
|
523
|
+
domReference,
|
|
524
|
+
getNodeId,
|
|
525
|
+
getResolvedInsideElements
|
|
526
|
+
]);
|
|
527
|
+
useIsoLayoutEffect(()=>{
|
|
528
|
+
if (!isWebKit || open || !floating) return;
|
|
529
|
+
const activeEl = activeElement(ownerDocument(floating));
|
|
530
|
+
if (!isHTMLElement(activeEl) || !isTypeableElement(activeEl)) return;
|
|
531
|
+
if (contains(floating, activeEl)) activeEl.blur();
|
|
532
|
+
}, [
|
|
533
|
+
open,
|
|
534
|
+
floating
|
|
535
|
+
]);
|
|
536
|
+
useIsoLayoutEffect(()=>{
|
|
537
|
+
if (disabled || !portalContext) return;
|
|
538
|
+
portalContext.setFocusManagerState({
|
|
539
|
+
modal,
|
|
540
|
+
closeOnFocusOut,
|
|
541
|
+
open,
|
|
542
|
+
onOpenChange: store.setOpen,
|
|
543
|
+
domReference
|
|
544
|
+
});
|
|
545
|
+
return ()=>{
|
|
546
|
+
portalContext.setFocusManagerState(null);
|
|
547
|
+
};
|
|
548
|
+
}, [
|
|
549
|
+
disabled,
|
|
550
|
+
portalContext,
|
|
551
|
+
modal,
|
|
552
|
+
open,
|
|
553
|
+
store,
|
|
554
|
+
closeOnFocusOut,
|
|
555
|
+
domReference
|
|
556
|
+
]);
|
|
557
|
+
useIsoLayoutEffect(()=>{
|
|
558
|
+
if (disabled || !floatingFocusElement) return;
|
|
559
|
+
handleTabIndex(floatingFocusElement, orderRef);
|
|
560
|
+
return ()=>{
|
|
561
|
+
queueMicrotask(clearDisconnectedPreviouslyFocusedElements);
|
|
562
|
+
};
|
|
563
|
+
}, [
|
|
564
|
+
disabled,
|
|
565
|
+
floatingFocusElement,
|
|
566
|
+
orderRef
|
|
567
|
+
]);
|
|
568
|
+
const shouldRenderGuards = !disabled && (modal ? !isUntrappedTypeableCombobox : true) && (isInsidePortal || modal);
|
|
569
|
+
return /*#__PURE__*/ jsxs(__rspack_external_react.Fragment, {
|
|
570
|
+
children: [
|
|
571
|
+
shouldRenderGuards && /*#__PURE__*/ jsx(FocusGuard_FocusGuard, {
|
|
572
|
+
"data-type": "inside",
|
|
573
|
+
ref: mergedBeforeGuardRef,
|
|
574
|
+
onFocus: (event)=>{
|
|
575
|
+
if (modal) {
|
|
576
|
+
const els = getTabbableContent();
|
|
577
|
+
enqueueFocus(els[els.length - 1]);
|
|
578
|
+
} else if (portalContext?.portalNode) {
|
|
579
|
+
preventReturnFocusRef.current = false;
|
|
580
|
+
if (isOutsideEvent(event, portalContext.portalNode)) {
|
|
581
|
+
const nextTabbable = getNextTabbable(domReference);
|
|
582
|
+
nextTabbable?.focus();
|
|
583
|
+
} else resolveRef(previousFocusableElement ?? portalContext.beforeOutsideRef)?.focus();
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
}),
|
|
587
|
+
children,
|
|
588
|
+
shouldRenderGuards && /*#__PURE__*/ jsx(FocusGuard_FocusGuard, {
|
|
589
|
+
"data-type": "inside",
|
|
590
|
+
ref: mergedAfterGuardRef,
|
|
591
|
+
onFocus: (event)=>{
|
|
592
|
+
if (modal) enqueueFocus(getTabbableContent()[0]);
|
|
593
|
+
else if (portalContext?.portalNode) {
|
|
594
|
+
if (closeOnFocusOut) preventReturnFocusRef.current = true;
|
|
595
|
+
if (isOutsideEvent(event, portalContext.portalNode)) {
|
|
596
|
+
const prevTabbable = getPreviousTabbable(domReference);
|
|
597
|
+
prevTabbable?.focus();
|
|
598
|
+
} else resolveRef(nextFocusableElement ?? portalContext.afterOutsideRef)?.focus();
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
})
|
|
602
|
+
]
|
|
603
|
+
});
|
|
604
|
+
}
|
|
605
|
+
function useEnhancedClickHandler(handler) {
|
|
606
|
+
const lastClickInteractionTypeRef = __rspack_external_react.useRef('');
|
|
607
|
+
const handlePointerDown = __rspack_external_react.useCallback((event)=>{
|
|
608
|
+
if (event.defaultPrevented) return;
|
|
609
|
+
lastClickInteractionTypeRef.current = event.pointerType;
|
|
610
|
+
handler(event, event.pointerType);
|
|
611
|
+
}, [
|
|
612
|
+
handler
|
|
613
|
+
]);
|
|
614
|
+
const handleClick = __rspack_external_react.useCallback((event)=>{
|
|
615
|
+
if (0 === event.detail) return void handler(event, 'keyboard');
|
|
616
|
+
'pointerType' in event ? handler(event, event.pointerType) : handler(event, lastClickInteractionTypeRef.current);
|
|
617
|
+
lastClickInteractionTypeRef.current = '';
|
|
618
|
+
}, [
|
|
619
|
+
handler
|
|
620
|
+
]);
|
|
621
|
+
return {
|
|
622
|
+
onClick: handleClick,
|
|
623
|
+
onPointerDown: handlePointerDown
|
|
624
|
+
};
|
|
625
|
+
}
|
|
626
|
+
function useOpenMethodTriggerProps(open, setOpenMethod) {
|
|
627
|
+
const handleTriggerClick = useStableCallback((_, interactionType)=>{
|
|
628
|
+
const isOpen = 'function' == typeof open ? open() : open;
|
|
629
|
+
if (!isOpen) setOpenMethod(interactionType || (isIOS ? 'touch' : ''));
|
|
630
|
+
});
|
|
631
|
+
const { onClick, onPointerDown } = useEnhancedClickHandler(handleTriggerClick);
|
|
632
|
+
return __rspack_external_react.useMemo(()=>({
|
|
633
|
+
onClick,
|
|
634
|
+
onPointerDown
|
|
635
|
+
}), [
|
|
636
|
+
onClick,
|
|
637
|
+
onPointerDown
|
|
638
|
+
]);
|
|
639
|
+
}
|
|
640
|
+
function useOpenInteractionType(open) {
|
|
641
|
+
const [openMethod, setOpenMethod] = __rspack_external_react.useState(null);
|
|
642
|
+
const triggerProps = useOpenMethodTriggerProps(open, setOpenMethod);
|
|
643
|
+
useValueChanged(open, (previousOpen)=>{
|
|
644
|
+
if (previousOpen && !open) setOpenMethod(null);
|
|
645
|
+
});
|
|
646
|
+
return __rspack_external_react.useMemo(()=>({
|
|
647
|
+
openMethod,
|
|
648
|
+
triggerProps
|
|
649
|
+
}), [
|
|
650
|
+
openMethod,
|
|
651
|
+
triggerProps
|
|
652
|
+
]);
|
|
653
|
+
}
|
|
654
|
+
let originalHtmlStyles = {};
|
|
655
|
+
let originalBodyStyles = {};
|
|
656
|
+
let originalHtmlScrollBehavior = '';
|
|
657
|
+
function hasInsetScrollbars(referenceElement) {
|
|
658
|
+
if ("u" < typeof document) return false;
|
|
659
|
+
const doc = ownerDocument(referenceElement);
|
|
660
|
+
const win = getWindow(doc);
|
|
661
|
+
return win.innerWidth - doc.documentElement.clientWidth > 0;
|
|
662
|
+
}
|
|
663
|
+
function supportsStableScrollbarGutter(referenceElement) {
|
|
664
|
+
const supported = "u" > typeof CSS && CSS.supports && CSS.supports('scrollbar-gutter', 'stable');
|
|
665
|
+
if (!supported || "u" < typeof document) return false;
|
|
666
|
+
const doc = ownerDocument(referenceElement);
|
|
667
|
+
const html = doc.documentElement;
|
|
668
|
+
const body = doc.body;
|
|
669
|
+
const scrollContainer = isOverflowElement(html) ? html : body;
|
|
670
|
+
const originalScrollContainerOverflowY = scrollContainer.style.overflowY;
|
|
671
|
+
const originalHtmlStyleGutter = html.style.scrollbarGutter;
|
|
672
|
+
html.style.scrollbarGutter = 'stable';
|
|
673
|
+
scrollContainer.style.overflowY = 'scroll';
|
|
674
|
+
const before = scrollContainer.offsetWidth;
|
|
675
|
+
scrollContainer.style.overflowY = 'hidden';
|
|
676
|
+
const after = scrollContainer.offsetWidth;
|
|
677
|
+
scrollContainer.style.overflowY = originalScrollContainerOverflowY;
|
|
678
|
+
html.style.scrollbarGutter = originalHtmlStyleGutter;
|
|
679
|
+
return before === after;
|
|
680
|
+
}
|
|
681
|
+
function preventScrollOverlayScrollbars(referenceElement) {
|
|
682
|
+
const doc = ownerDocument(referenceElement);
|
|
683
|
+
const html = doc.documentElement;
|
|
684
|
+
const body = doc.body;
|
|
685
|
+
const elementToLock = isOverflowElement(html) ? html : body;
|
|
686
|
+
const originalElementToLockStyles = {
|
|
687
|
+
overflowY: elementToLock.style.overflowY,
|
|
688
|
+
overflowX: elementToLock.style.overflowX
|
|
689
|
+
};
|
|
690
|
+
Object.assign(elementToLock.style, {
|
|
691
|
+
overflowY: 'hidden',
|
|
692
|
+
overflowX: 'hidden'
|
|
693
|
+
});
|
|
694
|
+
return ()=>{
|
|
695
|
+
Object.assign(elementToLock.style, originalElementToLockStyles);
|
|
696
|
+
};
|
|
697
|
+
}
|
|
698
|
+
function preventScrollInsetScrollbars(referenceElement) {
|
|
699
|
+
const doc = ownerDocument(referenceElement);
|
|
700
|
+
const html = doc.documentElement;
|
|
701
|
+
const body = doc.body;
|
|
702
|
+
const win = getWindow(html);
|
|
703
|
+
let scrollTop = 0;
|
|
704
|
+
let scrollLeft = 0;
|
|
705
|
+
let updateGutterOnly = false;
|
|
706
|
+
const resizeFrame = AnimationFrame.create();
|
|
707
|
+
if (isWebKit && (win.visualViewport?.scale ?? 1) !== 1) return ()=>{};
|
|
708
|
+
function lockScroll() {
|
|
709
|
+
const htmlStyles = win.getComputedStyle(html);
|
|
710
|
+
const bodyStyles = win.getComputedStyle(body);
|
|
711
|
+
const htmlScrollbarGutterValue = htmlStyles.scrollbarGutter || '';
|
|
712
|
+
const hasBothEdges = htmlScrollbarGutterValue.includes('both-edges');
|
|
713
|
+
const scrollbarGutterValue = hasBothEdges ? 'stable both-edges' : 'stable';
|
|
714
|
+
scrollTop = html.scrollTop;
|
|
715
|
+
scrollLeft = html.scrollLeft;
|
|
716
|
+
originalHtmlStyles = {
|
|
717
|
+
scrollbarGutter: html.style.scrollbarGutter,
|
|
718
|
+
overflowY: html.style.overflowY,
|
|
719
|
+
overflowX: html.style.overflowX
|
|
720
|
+
};
|
|
721
|
+
originalHtmlScrollBehavior = html.style.scrollBehavior;
|
|
722
|
+
originalBodyStyles = {
|
|
723
|
+
position: body.style.position,
|
|
724
|
+
height: body.style.height,
|
|
725
|
+
width: body.style.width,
|
|
726
|
+
boxSizing: body.style.boxSizing,
|
|
727
|
+
overflowY: body.style.overflowY,
|
|
728
|
+
overflowX: body.style.overflowX,
|
|
729
|
+
scrollBehavior: body.style.scrollBehavior
|
|
730
|
+
};
|
|
731
|
+
const isScrollableY = html.scrollHeight > html.clientHeight;
|
|
732
|
+
const isScrollableX = html.scrollWidth > html.clientWidth;
|
|
733
|
+
const hasConstantOverflowY = 'scroll' === htmlStyles.overflowY || 'scroll' === bodyStyles.overflowY;
|
|
734
|
+
const hasConstantOverflowX = 'scroll' === htmlStyles.overflowX || 'scroll' === bodyStyles.overflowX;
|
|
735
|
+
const scrollbarWidth = Math.max(0, win.innerWidth - body.clientWidth);
|
|
736
|
+
const scrollbarHeight = Math.max(0, win.innerHeight - body.clientHeight);
|
|
737
|
+
const marginY = parseFloat(bodyStyles.marginTop) + parseFloat(bodyStyles.marginBottom);
|
|
738
|
+
const marginX = parseFloat(bodyStyles.marginLeft) + parseFloat(bodyStyles.marginRight);
|
|
739
|
+
const elementToLock = isOverflowElement(html) ? html : body;
|
|
740
|
+
updateGutterOnly = supportsStableScrollbarGutter(referenceElement);
|
|
741
|
+
if (updateGutterOnly) {
|
|
742
|
+
html.style.scrollbarGutter = scrollbarGutterValue;
|
|
743
|
+
elementToLock.style.overflowY = 'hidden';
|
|
744
|
+
elementToLock.style.overflowX = 'hidden';
|
|
745
|
+
return;
|
|
746
|
+
}
|
|
747
|
+
Object.assign(html.style, {
|
|
748
|
+
scrollbarGutter: scrollbarGutterValue,
|
|
749
|
+
overflowY: 'hidden',
|
|
750
|
+
overflowX: 'hidden'
|
|
751
|
+
});
|
|
752
|
+
if (isScrollableY || hasConstantOverflowY) html.style.overflowY = 'scroll';
|
|
753
|
+
if (isScrollableX || hasConstantOverflowX) html.style.overflowX = 'scroll';
|
|
754
|
+
Object.assign(body.style, {
|
|
755
|
+
position: 'relative',
|
|
756
|
+
height: marginY || scrollbarHeight ? `calc(100dvh - ${marginY + scrollbarHeight}px)` : '100dvh',
|
|
757
|
+
width: marginX || scrollbarWidth ? `calc(100vw - ${marginX + scrollbarWidth}px)` : '100vw',
|
|
758
|
+
boxSizing: 'border-box',
|
|
759
|
+
overflow: 'hidden',
|
|
760
|
+
scrollBehavior: 'unset'
|
|
761
|
+
});
|
|
762
|
+
body.scrollTop = scrollTop;
|
|
763
|
+
body.scrollLeft = scrollLeft;
|
|
764
|
+
html.setAttribute('data-base-ui-scroll-locked', '');
|
|
765
|
+
html.style.scrollBehavior = 'unset';
|
|
766
|
+
}
|
|
767
|
+
function cleanup() {
|
|
768
|
+
Object.assign(html.style, originalHtmlStyles);
|
|
769
|
+
Object.assign(body.style, originalBodyStyles);
|
|
770
|
+
if (!updateGutterOnly) {
|
|
771
|
+
html.scrollTop = scrollTop;
|
|
772
|
+
html.scrollLeft = scrollLeft;
|
|
773
|
+
html.removeAttribute('data-base-ui-scroll-locked');
|
|
774
|
+
html.style.scrollBehavior = originalHtmlScrollBehavior;
|
|
775
|
+
}
|
|
776
|
+
}
|
|
777
|
+
function handleResize() {
|
|
778
|
+
cleanup();
|
|
779
|
+
resizeFrame.request(lockScroll);
|
|
780
|
+
}
|
|
781
|
+
lockScroll();
|
|
782
|
+
const unsubscribeResize = addEventListener(win, 'resize', handleResize);
|
|
783
|
+
return ()=>{
|
|
784
|
+
resizeFrame.cancel();
|
|
785
|
+
cleanup();
|
|
786
|
+
if ('function' == typeof win.removeEventListener) unsubscribeResize();
|
|
787
|
+
};
|
|
788
|
+
}
|
|
789
|
+
class ScrollLocker {
|
|
790
|
+
lockCount = 0;
|
|
791
|
+
restore = null;
|
|
792
|
+
timeoutLock = Timeout.create();
|
|
793
|
+
timeoutUnlock = Timeout.create();
|
|
794
|
+
acquire(referenceElement) {
|
|
795
|
+
this.lockCount += 1;
|
|
796
|
+
if (1 === this.lockCount && null === this.restore) this.timeoutLock.start(0, ()=>this.lock(referenceElement));
|
|
797
|
+
return this.release;
|
|
798
|
+
}
|
|
799
|
+
release = ()=>{
|
|
800
|
+
this.lockCount -= 1;
|
|
801
|
+
if (0 === this.lockCount && this.restore) this.timeoutUnlock.start(0, this.unlock);
|
|
802
|
+
};
|
|
803
|
+
unlock = ()=>{
|
|
804
|
+
if (0 === this.lockCount && this.restore) {
|
|
805
|
+
this.restore?.();
|
|
806
|
+
this.restore = null;
|
|
807
|
+
}
|
|
808
|
+
};
|
|
809
|
+
lock(referenceElement) {
|
|
810
|
+
if (0 === this.lockCount || null !== this.restore) return;
|
|
811
|
+
const doc = ownerDocument(referenceElement);
|
|
812
|
+
const html = doc.documentElement;
|
|
813
|
+
const htmlOverflowY = getWindow(html).getComputedStyle(html).overflowY;
|
|
814
|
+
if ('hidden' === htmlOverflowY || 'clip' === htmlOverflowY) {
|
|
815
|
+
this.restore = NOOP;
|
|
816
|
+
return;
|
|
817
|
+
}
|
|
818
|
+
const hasOverlayScrollbars = isIOS || !hasInsetScrollbars(referenceElement);
|
|
819
|
+
this.restore = hasOverlayScrollbars ? preventScrollOverlayScrollbars(referenceElement) : preventScrollInsetScrollbars(referenceElement);
|
|
820
|
+
}
|
|
821
|
+
}
|
|
822
|
+
const SCROLL_LOCKER = new ScrollLocker();
|
|
823
|
+
function useScrollLock(enabled = true, referenceElement = null) {
|
|
824
|
+
useIsoLayoutEffect(()=>{
|
|
825
|
+
if (!enabled) return;
|
|
826
|
+
return SCROLL_LOCKER.acquire(referenceElement);
|
|
827
|
+
}, [
|
|
828
|
+
enabled,
|
|
829
|
+
referenceElement
|
|
830
|
+
]);
|
|
831
|
+
}
|
|
832
|
+
const InternalBackdrop_InternalBackdrop = /*#__PURE__*/ __rspack_external_react.forwardRef(function(props, ref) {
|
|
833
|
+
const { cutout, ...otherProps } = props;
|
|
834
|
+
let clipPath;
|
|
835
|
+
if (cutout) {
|
|
836
|
+
const rect = cutout.getBoundingClientRect();
|
|
837
|
+
clipPath = `polygon(0% 0%,100% 0%,100% 100%,0% 100%,0% 0%,${rect.left}px ${rect.top}px,${rect.left}px ${rect.bottom}px,${rect.right}px ${rect.bottom}px,${rect.right}px ${rect.top}px,${rect.left}px ${rect.top}px)`;
|
|
838
|
+
}
|
|
839
|
+
return /*#__PURE__*/ jsx("div", {
|
|
840
|
+
ref: ref,
|
|
841
|
+
role: "presentation",
|
|
842
|
+
"data-base-ui-inert": "",
|
|
843
|
+
...otherProps,
|
|
844
|
+
style: {
|
|
845
|
+
position: 'fixed',
|
|
846
|
+
inset: 0,
|
|
847
|
+
userSelect: 'none',
|
|
848
|
+
WebkitUserSelect: 'none',
|
|
849
|
+
clipPath
|
|
850
|
+
}
|
|
851
|
+
});
|
|
852
|
+
});
|
|
853
|
+
if ("production" !== process.env.NODE_ENV) InternalBackdrop_InternalBackdrop.displayName = "InternalBackdrop";
|
|
854
|
+
export { FloatingFocusManager, InternalBackdrop_InternalBackdrop, enqueueFocus, useOpenInteractionType, useOpenMethodTriggerProps, useScrollLock };
|