@soomo/react-text-annotator 3.0.0-staging.5 → 3.0.0-staging.50
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/TextAnnotator.d.ts +3 -3
- package/dist/TextAnnotator.d.ts.map +1 -1
- package/dist/TextAnnotatorPlugin.d.ts +1 -1
- package/dist/TextAnnotatorPopup/TextAnnotatorPopup.d.ts +16 -0
- package/dist/TextAnnotatorPopup/TextAnnotatorPopup.d.ts.map +1 -0
- package/dist/TextAnnotatorPopup/index.d.ts +2 -0
- package/dist/TextAnnotatorPopup/index.d.ts.map +1 -0
- package/dist/hooks/index.d.ts +2 -0
- package/dist/hooks/index.d.ts.map +1 -0
- package/dist/hooks/useAnnouncePopupNavigation.d.ts +10 -0
- package/dist/hooks/useAnnouncePopupNavigation.d.ts.map +1 -0
- package/dist/index.d.ts +7 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/react-text-annotator.css +31 -1
- package/dist/react-text-annotator.es.js +11 -8
- package/dist/react-text-annotator.es.js.map +1 -1
- package/dist/react-text-annotator.es10.js +486 -34
- package/dist/react-text-annotator.es10.js.map +1 -1
- package/dist/react-text-annotator.es11.js +1406 -822
- package/dist/react-text-annotator.es11.js.map +1 -1
- package/dist/react-text-annotator.es13.js +241 -2
- package/dist/react-text-annotator.es13.js.map +1 -1
- package/dist/react-text-annotator.es14.js +560 -105
- package/dist/react-text-annotator.es14.js.map +1 -1
- package/dist/react-text-annotator.es15.js +54 -299
- package/dist/react-text-annotator.es15.js.map +1 -1
- package/dist/react-text-annotator.es16.js +38 -51
- package/dist/react-text-annotator.es16.js.map +1 -1
- package/dist/react-text-annotator.es17.js +2 -20
- package/dist/react-text-annotator.es17.js.map +1 -1
- package/dist/react-text-annotator.es18.js +34 -0
- package/dist/react-text-annotator.es18.js.map +1 -0
- package/dist/react-text-annotator.es19.js +901 -0
- package/dist/react-text-annotator.es19.js.map +1 -0
- package/dist/react-text-annotator.es2.js +2 -2
- package/dist/{react-text-annotator.es12.js → react-text-annotator.es20.js} +1 -1
- package/dist/react-text-annotator.es20.js.map +1 -0
- package/dist/react-text-annotator.es21.js +5 -0
- package/dist/react-text-annotator.es21.js.map +1 -0
- package/dist/react-text-annotator.es22.js +117 -0
- package/dist/react-text-annotator.es22.js.map +1 -0
- package/dist/react-text-annotator.es23.js +312 -0
- package/dist/react-text-annotator.es23.js.map +1 -0
- package/dist/react-text-annotator.es24.js +61 -0
- package/dist/react-text-annotator.es24.js.map +1 -0
- package/dist/react-text-annotator.es25.js +23 -0
- package/dist/react-text-annotator.es25.js.map +1 -0
- package/dist/react-text-annotator.es26.js +130 -0
- package/dist/react-text-annotator.es26.js.map +1 -0
- package/dist/react-text-annotator.es27.js +155 -0
- package/dist/react-text-annotator.es27.js.map +1 -0
- package/dist/react-text-annotator.es28.js +314 -0
- package/dist/react-text-annotator.es28.js.map +1 -0
- package/dist/react-text-annotator.es29.js +152 -0
- package/dist/react-text-annotator.es29.js.map +1 -0
- package/dist/react-text-annotator.es3.js +2 -2
- package/dist/react-text-annotator.es30.js +563 -0
- package/dist/react-text-annotator.es30.js.map +1 -0
- package/dist/react-text-annotator.es4.js +38 -28
- package/dist/react-text-annotator.es4.js.map +1 -1
- package/dist/react-text-annotator.es5.js +22 -47
- package/dist/react-text-annotator.es5.js.map +1 -1
- package/dist/react-text-annotator.es6.js +129 -10
- package/dist/react-text-annotator.es6.js.map +1 -1
- package/dist/react-text-annotator.es7.js +181 -1
- package/dist/react-text-annotator.es7.js.map +1 -1
- package/dist/react-text-annotator.es8.js +9 -487
- package/dist/react-text-annotator.es8.js.map +1 -1
- package/dist/tei/TEIAnnotator.d.ts +2 -2
- package/package.json +22 -14
- package/dist/TextAnnotatorPopup.d.ts +0 -14
- package/dist/TextAnnotatorPopup.d.ts.map +0 -1
- package/dist/react-text-annotator.es12.js.map +0 -1
- package/dist/react-text-annotator.es9.js +0 -5
- package/dist/react-text-annotator.es9.js.map +0 -1
|
@@ -1,887 +1,1471 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
*
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
var ReactDebugCurrentFrame2 = ReactSharedInternals.ReactDebugCurrentFrame;
|
|
59
|
-
var stack = ReactDebugCurrentFrame2.getStackAddendum();
|
|
60
|
-
if (stack !== "") {
|
|
61
|
-
format += "%s";
|
|
62
|
-
args = args.concat([stack]);
|
|
63
|
-
}
|
|
64
|
-
var argsWithFormat = args.map(function(item) {
|
|
65
|
-
return String(item);
|
|
66
|
-
});
|
|
67
|
-
argsWithFormat.unshift("Warning: " + format);
|
|
68
|
-
Function.prototype.apply.call(console[level], console, argsWithFormat);
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { useLayoutEffect, useEffect, useRef } from "react";
|
|
3
|
+
import { isTypeableCombobox, getDocument, activeElement, contains, isVirtualClick, isVirtualPointerEvent, isSafari, stopEvent, getTarget, isReactEvent, isRootElement, isEventTargetWithin } from "./react-text-annotator.es26.js";
|
|
4
|
+
import { isHTMLElement, isElement, getOverflowAncestors, getNodeName, isLastTraversableNode, getParentNode, getComputedStyle } from "./react-text-annotator.es27.js";
|
|
5
|
+
import { tabbable, isTabbable } from "./react-text-annotator.es28.js";
|
|
6
|
+
import * as ReactDOM from "react-dom";
|
|
7
|
+
import { useFloating as useFloating$1 } from "./react-text-annotator.es13.js";
|
|
8
|
+
import { flip, inline, offset, shift } from "./react-text-annotator.es13.js";
|
|
9
|
+
const SafeReact = {
|
|
10
|
+
...React
|
|
11
|
+
};
|
|
12
|
+
const useInsertionEffect = SafeReact.useInsertionEffect;
|
|
13
|
+
const useSafeInsertionEffect = useInsertionEffect || ((fn) => fn());
|
|
14
|
+
function useEffectEvent(callback) {
|
|
15
|
+
const ref = React.useRef(() => {
|
|
16
|
+
if (process.env.NODE_ENV !== "production") {
|
|
17
|
+
throw new Error("Cannot call an event handler while rendering.");
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
useSafeInsertionEffect(() => {
|
|
21
|
+
ref.current = callback;
|
|
22
|
+
});
|
|
23
|
+
return React.useCallback(function() {
|
|
24
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
25
|
+
args[_key] = arguments[_key];
|
|
26
|
+
}
|
|
27
|
+
return ref.current == null ? void 0 : ref.current(...args);
|
|
28
|
+
}, []);
|
|
29
|
+
}
|
|
30
|
+
let rafId = 0;
|
|
31
|
+
function enqueueFocus(el, options) {
|
|
32
|
+
if (options === void 0) {
|
|
33
|
+
options = {};
|
|
34
|
+
}
|
|
35
|
+
const {
|
|
36
|
+
preventScroll = false,
|
|
37
|
+
cancelPrevious = true,
|
|
38
|
+
sync = false
|
|
39
|
+
} = options;
|
|
40
|
+
cancelPrevious && cancelAnimationFrame(rafId);
|
|
41
|
+
const exec = () => el == null ? void 0 : el.focus({
|
|
42
|
+
preventScroll
|
|
43
|
+
});
|
|
44
|
+
if (sync) {
|
|
45
|
+
exec();
|
|
46
|
+
} else {
|
|
47
|
+
rafId = requestAnimationFrame(exec);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
var index = typeof document !== "undefined" ? useLayoutEffect : useEffect;
|
|
51
|
+
function _extends() {
|
|
52
|
+
_extends = Object.assign ? Object.assign.bind() : function(target) {
|
|
53
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
54
|
+
var source = arguments[i];
|
|
55
|
+
for (var key in source) {
|
|
56
|
+
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
57
|
+
target[key] = source[key];
|
|
69
58
|
}
|
|
70
59
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
60
|
+
}
|
|
61
|
+
return target;
|
|
62
|
+
};
|
|
63
|
+
return _extends.apply(this, arguments);
|
|
64
|
+
}
|
|
65
|
+
let serverHandoffComplete = false;
|
|
66
|
+
let count = 0;
|
|
67
|
+
const genId = () => (
|
|
68
|
+
// Ensure the id is unique with multiple independent versions of Floating UI
|
|
69
|
+
// on <React 18
|
|
70
|
+
"floating-ui-" + Math.random().toString(36).slice(2, 6) + count++
|
|
71
|
+
);
|
|
72
|
+
function useFloatingId() {
|
|
73
|
+
const [id, setId] = React.useState(() => serverHandoffComplete ? genId() : void 0);
|
|
74
|
+
index(() => {
|
|
75
|
+
if (id == null) {
|
|
76
|
+
setId(genId());
|
|
77
|
+
}
|
|
78
|
+
}, []);
|
|
79
|
+
React.useEffect(() => {
|
|
80
|
+
serverHandoffComplete = true;
|
|
81
|
+
}, []);
|
|
82
|
+
return id;
|
|
83
|
+
}
|
|
84
|
+
const useReactId = SafeReact.useId;
|
|
85
|
+
const useId = useReactId || useFloatingId;
|
|
86
|
+
let devMessageSet;
|
|
87
|
+
if (process.env.NODE_ENV !== "production") {
|
|
88
|
+
devMessageSet = /* @__PURE__ */ new Set();
|
|
89
|
+
}
|
|
90
|
+
function error() {
|
|
91
|
+
var _devMessageSet3;
|
|
92
|
+
for (var _len2 = arguments.length, messages = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
93
|
+
messages[_key2] = arguments[_key2];
|
|
94
|
+
}
|
|
95
|
+
const message = "Floating UI: " + messages.join(" ");
|
|
96
|
+
if (!((_devMessageSet3 = devMessageSet) != null && _devMessageSet3.has(message))) {
|
|
97
|
+
var _devMessageSet4;
|
|
98
|
+
(_devMessageSet4 = devMessageSet) == null || _devMessageSet4.add(message);
|
|
99
|
+
console.error(message);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
function createPubSub() {
|
|
103
|
+
const map = /* @__PURE__ */ new Map();
|
|
104
|
+
return {
|
|
105
|
+
emit(event, data) {
|
|
106
|
+
var _map$get;
|
|
107
|
+
(_map$get = map.get(event)) == null || _map$get.forEach((handler) => handler(data));
|
|
108
|
+
},
|
|
109
|
+
on(event, listener) {
|
|
110
|
+
map.set(event, [...map.get(event) || [], listener]);
|
|
111
|
+
},
|
|
112
|
+
off(event, listener) {
|
|
113
|
+
var _map$get2;
|
|
114
|
+
map.set(event, ((_map$get2 = map.get(event)) == null ? void 0 : _map$get2.filter((l) => l !== listener)) || []);
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
const FloatingNodeContext = /* @__PURE__ */ React.createContext(null);
|
|
119
|
+
const FloatingTreeContext = /* @__PURE__ */ React.createContext(null);
|
|
120
|
+
const useFloatingParentNodeId = () => {
|
|
121
|
+
var _React$useContext;
|
|
122
|
+
return ((_React$useContext = React.useContext(FloatingNodeContext)) == null ? void 0 : _React$useContext.id) || null;
|
|
123
|
+
};
|
|
124
|
+
const useFloatingTree = () => React.useContext(FloatingTreeContext);
|
|
125
|
+
function createAttribute(name) {
|
|
126
|
+
return "data-floating-ui-" + name;
|
|
127
|
+
}
|
|
128
|
+
function useLatestRef(value) {
|
|
129
|
+
const ref = useRef(value);
|
|
130
|
+
index(() => {
|
|
131
|
+
ref.current = value;
|
|
132
|
+
});
|
|
133
|
+
return ref;
|
|
134
|
+
}
|
|
135
|
+
function getAncestors(nodes, id) {
|
|
136
|
+
var _nodes$find;
|
|
137
|
+
let allAncestors = [];
|
|
138
|
+
let currentParentId = (_nodes$find = nodes.find((node) => node.id === id)) == null ? void 0 : _nodes$find.parentId;
|
|
139
|
+
while (currentParentId) {
|
|
140
|
+
const currentNode = nodes.find((node) => node.id === currentParentId);
|
|
141
|
+
currentParentId = currentNode == null ? void 0 : currentNode.parentId;
|
|
142
|
+
if (currentNode) {
|
|
143
|
+
allAncestors = allAncestors.concat(currentNode);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
return allAncestors;
|
|
147
|
+
}
|
|
148
|
+
function getChildren(nodes, id) {
|
|
149
|
+
let allChildren = nodes.filter((node) => {
|
|
150
|
+
var _node$context;
|
|
151
|
+
return node.parentId === id && ((_node$context = node.context) == null ? void 0 : _node$context.open);
|
|
152
|
+
});
|
|
153
|
+
let currentChildren = allChildren;
|
|
154
|
+
while (currentChildren.length) {
|
|
155
|
+
currentChildren = nodes.filter((node) => {
|
|
156
|
+
var _currentChildren;
|
|
157
|
+
return (_currentChildren = currentChildren) == null ? void 0 : _currentChildren.some((n) => {
|
|
158
|
+
var _node$context2;
|
|
159
|
+
return node.parentId === n.id && ((_node$context2 = node.context) == null ? void 0 : _node$context2.open);
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
allChildren = allChildren.concat(currentChildren);
|
|
163
|
+
}
|
|
164
|
+
return allChildren;
|
|
165
|
+
}
|
|
166
|
+
let counterMap = /* @__PURE__ */ new WeakMap();
|
|
167
|
+
let uncontrolledElementsSet = /* @__PURE__ */ new WeakSet();
|
|
168
|
+
let markerMap = {};
|
|
169
|
+
let lockCount = 0;
|
|
170
|
+
const supportsInert = () => typeof HTMLElement !== "undefined" && "inert" in HTMLElement.prototype;
|
|
171
|
+
const unwrapHost = (node) => node && (node.host || unwrapHost(node.parentNode));
|
|
172
|
+
const correctElements = (parent, targets) => targets.map((target) => {
|
|
173
|
+
if (parent.contains(target)) {
|
|
174
|
+
return target;
|
|
175
|
+
}
|
|
176
|
+
const correctedTarget = unwrapHost(target);
|
|
177
|
+
if (parent.contains(correctedTarget)) {
|
|
178
|
+
return correctedTarget;
|
|
179
|
+
}
|
|
180
|
+
return null;
|
|
181
|
+
}).filter((x) => x != null);
|
|
182
|
+
function applyAttributeToOthers(uncorrectedAvoidElements, body, ariaHidden, inert) {
|
|
183
|
+
const markerName = "data-floating-ui-inert";
|
|
184
|
+
const controlAttribute = inert ? "inert" : ariaHidden ? "aria-hidden" : null;
|
|
185
|
+
const avoidElements = correctElements(body, uncorrectedAvoidElements);
|
|
186
|
+
const elementsToKeep = /* @__PURE__ */ new Set();
|
|
187
|
+
const elementsToStop = new Set(avoidElements);
|
|
188
|
+
const hiddenElements = [];
|
|
189
|
+
if (!markerMap[markerName]) {
|
|
190
|
+
markerMap[markerName] = /* @__PURE__ */ new WeakMap();
|
|
191
|
+
}
|
|
192
|
+
const markerCounter = markerMap[markerName];
|
|
193
|
+
avoidElements.forEach(keep);
|
|
194
|
+
deep(body);
|
|
195
|
+
elementsToKeep.clear();
|
|
196
|
+
function keep(el) {
|
|
197
|
+
if (!el || elementsToKeep.has(el)) {
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
elementsToKeep.add(el);
|
|
201
|
+
el.parentNode && keep(el.parentNode);
|
|
202
|
+
}
|
|
203
|
+
function deep(parent) {
|
|
204
|
+
if (!parent || elementsToStop.has(parent)) {
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
[].forEach.call(parent.children, (node) => {
|
|
208
|
+
if (getNodeName(node) === "script") return;
|
|
209
|
+
if (elementsToKeep.has(node)) {
|
|
210
|
+
deep(node);
|
|
211
|
+
} else {
|
|
212
|
+
const attr2 = controlAttribute ? node.getAttribute(controlAttribute) : null;
|
|
213
|
+
const alreadyHidden = attr2 !== null && attr2 !== "false";
|
|
214
|
+
const counterValue = (counterMap.get(node) || 0) + 1;
|
|
215
|
+
const markerValue = (markerCounter.get(node) || 0) + 1;
|
|
216
|
+
counterMap.set(node, counterValue);
|
|
217
|
+
markerCounter.set(node, markerValue);
|
|
218
|
+
hiddenElements.push(node);
|
|
219
|
+
if (counterValue === 1 && alreadyHidden) {
|
|
220
|
+
uncontrolledElementsSet.add(node);
|
|
83
221
|
}
|
|
84
|
-
if (
|
|
85
|
-
|
|
222
|
+
if (markerValue === 1) {
|
|
223
|
+
node.setAttribute(markerName, "");
|
|
86
224
|
}
|
|
87
|
-
if (
|
|
88
|
-
|
|
89
|
-
// types supported by any Flight configuration anywhere since
|
|
90
|
-
// we don't know which Flight build this will end up being used
|
|
91
|
-
// with.
|
|
92
|
-
type.$$typeof === REACT_MODULE_REFERENCE || type.getModuleId !== void 0) {
|
|
93
|
-
return true;
|
|
94
|
-
}
|
|
225
|
+
if (!alreadyHidden && controlAttribute) {
|
|
226
|
+
node.setAttribute(controlAttribute, "true");
|
|
95
227
|
}
|
|
96
|
-
return false;
|
|
97
228
|
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
lockCount++;
|
|
232
|
+
return () => {
|
|
233
|
+
hiddenElements.forEach((element) => {
|
|
234
|
+
const counterValue = (counterMap.get(element) || 0) - 1;
|
|
235
|
+
const markerValue = (markerCounter.get(element) || 0) - 1;
|
|
236
|
+
counterMap.set(element, counterValue);
|
|
237
|
+
markerCounter.set(element, markerValue);
|
|
238
|
+
if (!counterValue) {
|
|
239
|
+
if (!uncontrolledElementsSet.has(element) && controlAttribute) {
|
|
240
|
+
element.removeAttribute(controlAttribute);
|
|
102
241
|
}
|
|
103
|
-
|
|
104
|
-
return functionName !== "" ? wrapperName + "(" + functionName + ")" : wrapperName;
|
|
242
|
+
uncontrolledElementsSet.delete(element);
|
|
105
243
|
}
|
|
106
|
-
|
|
107
|
-
|
|
244
|
+
if (!markerValue) {
|
|
245
|
+
element.removeAttribute(markerName);
|
|
108
246
|
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
prevGroupCollapsed = console.groupCollapsed;
|
|
189
|
-
prevGroupEnd = console.groupEnd;
|
|
190
|
-
var props = {
|
|
191
|
-
configurable: true,
|
|
192
|
-
enumerable: true,
|
|
193
|
-
value: disabledLog,
|
|
194
|
-
writable: true
|
|
195
|
-
};
|
|
196
|
-
Object.defineProperties(console, {
|
|
197
|
-
info: props,
|
|
198
|
-
log: props,
|
|
199
|
-
warn: props,
|
|
200
|
-
error: props,
|
|
201
|
-
group: props,
|
|
202
|
-
groupCollapsed: props,
|
|
203
|
-
groupEnd: props
|
|
204
|
-
});
|
|
205
|
-
}
|
|
206
|
-
disabledDepth++;
|
|
207
|
-
}
|
|
247
|
+
});
|
|
248
|
+
lockCount--;
|
|
249
|
+
if (!lockCount) {
|
|
250
|
+
counterMap = /* @__PURE__ */ new WeakMap();
|
|
251
|
+
counterMap = /* @__PURE__ */ new WeakMap();
|
|
252
|
+
uncontrolledElementsSet = /* @__PURE__ */ new WeakSet();
|
|
253
|
+
markerMap = {};
|
|
254
|
+
}
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
function markOthers(avoidElements, ariaHidden, inert) {
|
|
258
|
+
if (ariaHidden === void 0) {
|
|
259
|
+
ariaHidden = false;
|
|
260
|
+
}
|
|
261
|
+
if (inert === void 0) {
|
|
262
|
+
inert = false;
|
|
263
|
+
}
|
|
264
|
+
const body = getDocument(avoidElements[0]).body;
|
|
265
|
+
return applyAttributeToOthers(avoidElements.concat(Array.from(body.querySelectorAll("[aria-live]"))), body, ariaHidden, inert);
|
|
266
|
+
}
|
|
267
|
+
const getTabbableOptions = () => ({
|
|
268
|
+
getShadowRoot: true,
|
|
269
|
+
displayCheck: (
|
|
270
|
+
// JSDOM does not support the `tabbable` library. To solve this we can
|
|
271
|
+
// check if `ResizeObserver` is a real function (not polyfilled), which
|
|
272
|
+
// determines if the current environment is JSDOM-like.
|
|
273
|
+
typeof ResizeObserver === "function" && ResizeObserver.toString().includes("[native code]") ? "full" : "none"
|
|
274
|
+
)
|
|
275
|
+
});
|
|
276
|
+
function getTabbableIn(container, direction) {
|
|
277
|
+
const allTabbable = tabbable(container, getTabbableOptions());
|
|
278
|
+
if (direction === "prev") {
|
|
279
|
+
allTabbable.reverse();
|
|
280
|
+
}
|
|
281
|
+
const activeIndex = allTabbable.indexOf(activeElement(getDocument(container)));
|
|
282
|
+
const nextTabbableElements = allTabbable.slice(activeIndex + 1);
|
|
283
|
+
return nextTabbableElements[0];
|
|
284
|
+
}
|
|
285
|
+
function getNextTabbable() {
|
|
286
|
+
return getTabbableIn(document.body, "next");
|
|
287
|
+
}
|
|
288
|
+
function getPreviousTabbable() {
|
|
289
|
+
return getTabbableIn(document.body, "prev");
|
|
290
|
+
}
|
|
291
|
+
function isOutsideEvent(event, container) {
|
|
292
|
+
const containerElement = container || event.currentTarget;
|
|
293
|
+
const relatedTarget = event.relatedTarget;
|
|
294
|
+
return !relatedTarget || !contains(containerElement, relatedTarget);
|
|
295
|
+
}
|
|
296
|
+
function disableFocusInside(container) {
|
|
297
|
+
const tabbableElements = tabbable(container, getTabbableOptions());
|
|
298
|
+
tabbableElements.forEach((element) => {
|
|
299
|
+
element.dataset.tabindex = element.getAttribute("tabindex") || "";
|
|
300
|
+
element.setAttribute("tabindex", "-1");
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
function enableFocusInside(container) {
|
|
304
|
+
const elements = container.querySelectorAll("[data-tabindex]");
|
|
305
|
+
elements.forEach((element) => {
|
|
306
|
+
const tabindex = element.dataset.tabindex;
|
|
307
|
+
delete element.dataset.tabindex;
|
|
308
|
+
if (tabindex) {
|
|
309
|
+
element.setAttribute("tabindex", tabindex);
|
|
310
|
+
} else {
|
|
311
|
+
element.removeAttribute("tabindex");
|
|
312
|
+
}
|
|
313
|
+
});
|
|
314
|
+
}
|
|
315
|
+
function getClosestTabbableElement(tabbableElements, element, floating) {
|
|
316
|
+
const elementIndex = tabbableElements.indexOf(element);
|
|
317
|
+
function traverseTabbableElements(next2) {
|
|
318
|
+
const attr2 = createAttribute("focus-guard");
|
|
319
|
+
let index2 = elementIndex + (next2 ? 1 : 0);
|
|
320
|
+
let currentElement = tabbableElements[index2];
|
|
321
|
+
while (currentElement && (!currentElement.isConnected || currentElement.hasAttribute(attr2) || contains(floating, currentElement))) {
|
|
322
|
+
if (next2) {
|
|
323
|
+
index2++;
|
|
324
|
+
} else {
|
|
325
|
+
index2--;
|
|
208
326
|
}
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
327
|
+
currentElement = tabbableElements[index2];
|
|
328
|
+
}
|
|
329
|
+
return currentElement;
|
|
330
|
+
}
|
|
331
|
+
const next = traverseTabbableElements(true);
|
|
332
|
+
if (next) {
|
|
333
|
+
return next;
|
|
334
|
+
}
|
|
335
|
+
return traverseTabbableElements(false);
|
|
336
|
+
}
|
|
337
|
+
const HIDDEN_STYLES = {
|
|
338
|
+
border: 0,
|
|
339
|
+
clip: "rect(0 0 0 0)",
|
|
340
|
+
height: "1px",
|
|
341
|
+
margin: "-1px",
|
|
342
|
+
overflow: "hidden",
|
|
343
|
+
padding: 0,
|
|
344
|
+
position: "fixed",
|
|
345
|
+
whiteSpace: "nowrap",
|
|
346
|
+
width: "1px",
|
|
347
|
+
top: 0,
|
|
348
|
+
left: 0
|
|
349
|
+
};
|
|
350
|
+
let timeoutId;
|
|
351
|
+
function setActiveElementOnTab(event) {
|
|
352
|
+
if (event.key === "Tab") {
|
|
353
|
+
event.target;
|
|
354
|
+
clearTimeout(timeoutId);
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
const FocusGuard = /* @__PURE__ */ React.forwardRef(function FocusGuard2(props, ref) {
|
|
358
|
+
const [role, setRole] = React.useState();
|
|
359
|
+
index(() => {
|
|
360
|
+
if (isSafari()) {
|
|
361
|
+
setRole("button");
|
|
362
|
+
}
|
|
363
|
+
document.addEventListener("keydown", setActiveElementOnTab);
|
|
364
|
+
return () => {
|
|
365
|
+
document.removeEventListener("keydown", setActiveElementOnTab);
|
|
366
|
+
};
|
|
367
|
+
}, []);
|
|
368
|
+
const restProps = {
|
|
369
|
+
ref,
|
|
370
|
+
tabIndex: 0,
|
|
371
|
+
// Role is only for VoiceOver
|
|
372
|
+
role,
|
|
373
|
+
"aria-hidden": role ? void 0 : true,
|
|
374
|
+
[createAttribute("focus-guard")]: "",
|
|
375
|
+
style: HIDDEN_STYLES
|
|
376
|
+
};
|
|
377
|
+
return /* @__PURE__ */ React.createElement("span", _extends({}, props, restProps));
|
|
378
|
+
});
|
|
379
|
+
const PortalContext = /* @__PURE__ */ React.createContext(null);
|
|
380
|
+
const attr = /* @__PURE__ */ createAttribute("portal");
|
|
381
|
+
function useFloatingPortalNode(props) {
|
|
382
|
+
if (props === void 0) {
|
|
383
|
+
props = {};
|
|
384
|
+
}
|
|
385
|
+
const {
|
|
386
|
+
id,
|
|
387
|
+
root
|
|
388
|
+
} = props;
|
|
389
|
+
const uniqueId = useId();
|
|
390
|
+
const portalContext = usePortalContext();
|
|
391
|
+
const [portalNode, setPortalNode] = React.useState(null);
|
|
392
|
+
const portalNodeRef = React.useRef(null);
|
|
393
|
+
index(() => {
|
|
394
|
+
return () => {
|
|
395
|
+
portalNode == null || portalNode.remove();
|
|
396
|
+
queueMicrotask(() => {
|
|
397
|
+
portalNodeRef.current = null;
|
|
398
|
+
});
|
|
399
|
+
};
|
|
400
|
+
}, [portalNode]);
|
|
401
|
+
index(() => {
|
|
402
|
+
if (!uniqueId) return;
|
|
403
|
+
if (portalNodeRef.current) return;
|
|
404
|
+
const existingIdRoot = id ? document.getElementById(id) : null;
|
|
405
|
+
if (!existingIdRoot) return;
|
|
406
|
+
const subRoot = document.createElement("div");
|
|
407
|
+
subRoot.id = uniqueId;
|
|
408
|
+
subRoot.setAttribute(attr, "");
|
|
409
|
+
existingIdRoot.appendChild(subRoot);
|
|
410
|
+
portalNodeRef.current = subRoot;
|
|
411
|
+
setPortalNode(subRoot);
|
|
412
|
+
}, [id, uniqueId]);
|
|
413
|
+
index(() => {
|
|
414
|
+
if (!uniqueId) return;
|
|
415
|
+
if (portalNodeRef.current) return;
|
|
416
|
+
let container = root || (portalContext == null ? void 0 : portalContext.portalNode);
|
|
417
|
+
if (container && !isElement(container)) container = container.current;
|
|
418
|
+
container = container || document.body;
|
|
419
|
+
let idWrapper = null;
|
|
420
|
+
if (id) {
|
|
421
|
+
idWrapper = document.createElement("div");
|
|
422
|
+
idWrapper.id = id;
|
|
423
|
+
container.appendChild(idWrapper);
|
|
424
|
+
}
|
|
425
|
+
const subRoot = document.createElement("div");
|
|
426
|
+
subRoot.id = uniqueId;
|
|
427
|
+
subRoot.setAttribute(attr, "");
|
|
428
|
+
container = idWrapper || container;
|
|
429
|
+
container.appendChild(subRoot);
|
|
430
|
+
portalNodeRef.current = subRoot;
|
|
431
|
+
setPortalNode(subRoot);
|
|
432
|
+
}, [id, root, uniqueId, portalContext]);
|
|
433
|
+
return portalNode;
|
|
434
|
+
}
|
|
435
|
+
function FloatingPortal(props) {
|
|
436
|
+
const {
|
|
437
|
+
children,
|
|
438
|
+
id,
|
|
439
|
+
root = null,
|
|
440
|
+
preserveTabOrder = true
|
|
441
|
+
} = props;
|
|
442
|
+
const portalNode = useFloatingPortalNode({
|
|
443
|
+
id,
|
|
444
|
+
root
|
|
445
|
+
});
|
|
446
|
+
const [focusManagerState, setFocusManagerState] = React.useState(null);
|
|
447
|
+
const beforeOutsideRef = React.useRef(null);
|
|
448
|
+
const afterOutsideRef = React.useRef(null);
|
|
449
|
+
const beforeInsideRef = React.useRef(null);
|
|
450
|
+
const afterInsideRef = React.useRef(null);
|
|
451
|
+
const modal = focusManagerState == null ? void 0 : focusManagerState.modal;
|
|
452
|
+
const open = focusManagerState == null ? void 0 : focusManagerState.open;
|
|
453
|
+
const shouldRenderGuards = (
|
|
454
|
+
// The FocusManager and therefore floating element are currently open/
|
|
455
|
+
// rendered.
|
|
456
|
+
!!focusManagerState && // Guards are only for non-modal focus management.
|
|
457
|
+
!focusManagerState.modal && // Don't render if unmount is transitioning.
|
|
458
|
+
focusManagerState.open && preserveTabOrder && !!(root || portalNode)
|
|
459
|
+
);
|
|
460
|
+
React.useEffect(() => {
|
|
461
|
+
if (!portalNode || !preserveTabOrder || modal) {
|
|
462
|
+
return;
|
|
463
|
+
}
|
|
464
|
+
function onFocus(event) {
|
|
465
|
+
if (portalNode && isOutsideEvent(event)) {
|
|
466
|
+
const focusing = event.type === "focusin";
|
|
467
|
+
const manageFocus = focusing ? enableFocusInside : disableFocusInside;
|
|
468
|
+
manageFocus(portalNode);
|
|
246
469
|
}
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
470
|
+
}
|
|
471
|
+
portalNode.addEventListener("focusin", onFocus, true);
|
|
472
|
+
portalNode.addEventListener("focusout", onFocus, true);
|
|
473
|
+
return () => {
|
|
474
|
+
portalNode.removeEventListener("focusin", onFocus, true);
|
|
475
|
+
portalNode.removeEventListener("focusout", onFocus, true);
|
|
476
|
+
};
|
|
477
|
+
}, [portalNode, preserveTabOrder, modal]);
|
|
478
|
+
React.useEffect(() => {
|
|
479
|
+
if (!portalNode) return;
|
|
480
|
+
if (open) return;
|
|
481
|
+
enableFocusInside(portalNode);
|
|
482
|
+
}, [open, portalNode]);
|
|
483
|
+
return /* @__PURE__ */ React.createElement(PortalContext.Provider, {
|
|
484
|
+
value: React.useMemo(() => ({
|
|
485
|
+
preserveTabOrder,
|
|
486
|
+
beforeOutsideRef,
|
|
487
|
+
afterOutsideRef,
|
|
488
|
+
beforeInsideRef,
|
|
489
|
+
afterInsideRef,
|
|
490
|
+
portalNode,
|
|
491
|
+
setFocusManagerState
|
|
492
|
+
}), [preserveTabOrder, portalNode])
|
|
493
|
+
}, shouldRenderGuards && portalNode && /* @__PURE__ */ React.createElement(FocusGuard, {
|
|
494
|
+
"data-type": "outside",
|
|
495
|
+
ref: beforeOutsideRef,
|
|
496
|
+
onFocus: (event) => {
|
|
497
|
+
if (isOutsideEvent(event, portalNode)) {
|
|
498
|
+
var _beforeInsideRef$curr;
|
|
499
|
+
(_beforeInsideRef$curr = beforeInsideRef.current) == null || _beforeInsideRef$curr.focus();
|
|
500
|
+
} else {
|
|
501
|
+
const prevTabbable = getPreviousTabbable() || (focusManagerState == null ? void 0 : focusManagerState.refs.domReference.current);
|
|
502
|
+
prevTabbable == null || prevTabbable.focus();
|
|
261
503
|
}
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
504
|
+
}
|
|
505
|
+
}), shouldRenderGuards && portalNode && /* @__PURE__ */ React.createElement("span", {
|
|
506
|
+
"aria-owns": portalNode.id,
|
|
507
|
+
style: HIDDEN_STYLES
|
|
508
|
+
}), portalNode && /* @__PURE__ */ ReactDOM.createPortal(children, portalNode), shouldRenderGuards && portalNode && /* @__PURE__ */ React.createElement(FocusGuard, {
|
|
509
|
+
"data-type": "outside",
|
|
510
|
+
ref: afterOutsideRef,
|
|
511
|
+
onFocus: (event) => {
|
|
512
|
+
if (isOutsideEvent(event, portalNode)) {
|
|
513
|
+
var _afterInsideRef$curre;
|
|
514
|
+
(_afterInsideRef$curre = afterInsideRef.current) == null || _afterInsideRef$curre.focus();
|
|
515
|
+
} else {
|
|
516
|
+
const nextTabbable = getNextTabbable() || (focusManagerState == null ? void 0 : focusManagerState.refs.domReference.current);
|
|
517
|
+
nextTabbable == null || nextTabbable.focus();
|
|
518
|
+
(focusManagerState == null ? void 0 : focusManagerState.closeOnFocusOut) && (focusManagerState == null ? void 0 : focusManagerState.onOpenChange(false, event.nativeEvent, "focus-out"));
|
|
267
519
|
}
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
520
|
+
}
|
|
521
|
+
}));
|
|
522
|
+
}
|
|
523
|
+
const usePortalContext = () => React.useContext(PortalContext);
|
|
524
|
+
const FOCUSABLE_ATTRIBUTE = "data-floating-ui-focusable";
|
|
525
|
+
function getFloatingFocusElement(floatingElement) {
|
|
526
|
+
if (!floatingElement) {
|
|
527
|
+
return null;
|
|
528
|
+
}
|
|
529
|
+
return floatingElement.hasAttribute(FOCUSABLE_ATTRIBUTE) ? floatingElement : floatingElement.querySelector("[" + FOCUSABLE_ATTRIBUTE + "]") || floatingElement;
|
|
530
|
+
}
|
|
531
|
+
const LIST_LIMIT = 20;
|
|
532
|
+
let previouslyFocusedElements = [];
|
|
533
|
+
function addPreviouslyFocusedElement(element) {
|
|
534
|
+
previouslyFocusedElements = previouslyFocusedElements.filter((el) => el.isConnected);
|
|
535
|
+
let tabbableEl = element;
|
|
536
|
+
if (!tabbableEl || getNodeName(tabbableEl) === "body") return;
|
|
537
|
+
if (!isTabbable(tabbableEl, getTabbableOptions())) {
|
|
538
|
+
const tabbableChild = tabbable(tabbableEl, getTabbableOptions())[0];
|
|
539
|
+
if (tabbableChild) {
|
|
540
|
+
tabbableEl = tabbableChild;
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
previouslyFocusedElements.push(tabbableEl);
|
|
544
|
+
if (previouslyFocusedElements.length > LIST_LIMIT) {
|
|
545
|
+
previouslyFocusedElements = previouslyFocusedElements.slice(-LIST_LIMIT);
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
function getPreviouslyFocusedElement() {
|
|
549
|
+
return previouslyFocusedElements.slice().reverse().find((el) => el.isConnected);
|
|
550
|
+
}
|
|
551
|
+
const VisuallyHiddenDismiss = /* @__PURE__ */ React.forwardRef(function VisuallyHiddenDismiss2(props, ref) {
|
|
552
|
+
return /* @__PURE__ */ React.createElement("button", _extends({}, props, {
|
|
553
|
+
type: "button",
|
|
554
|
+
ref,
|
|
555
|
+
tabIndex: -1,
|
|
556
|
+
style: HIDDEN_STYLES
|
|
557
|
+
}));
|
|
558
|
+
});
|
|
559
|
+
function FloatingFocusManager(props) {
|
|
560
|
+
const {
|
|
561
|
+
context,
|
|
562
|
+
children,
|
|
563
|
+
disabled = false,
|
|
564
|
+
order = ["content"],
|
|
565
|
+
guards: _guards = true,
|
|
566
|
+
initialFocus = 0,
|
|
567
|
+
returnFocus = true,
|
|
568
|
+
restoreFocus = false,
|
|
569
|
+
modal = true,
|
|
570
|
+
visuallyHiddenDismiss = false,
|
|
571
|
+
closeOnFocusOut = true
|
|
572
|
+
} = props;
|
|
573
|
+
const {
|
|
574
|
+
open,
|
|
575
|
+
refs,
|
|
576
|
+
nodeId,
|
|
577
|
+
onOpenChange,
|
|
578
|
+
events,
|
|
579
|
+
dataRef,
|
|
580
|
+
floatingId,
|
|
581
|
+
elements: {
|
|
582
|
+
domReference,
|
|
583
|
+
floating
|
|
584
|
+
}
|
|
585
|
+
} = context;
|
|
586
|
+
const ignoreInitialFocus = typeof initialFocus === "number" && initialFocus < 0;
|
|
587
|
+
const isUntrappedTypeableCombobox = isTypeableCombobox(domReference) && ignoreInitialFocus;
|
|
588
|
+
const guards = supportsInert() ? _guards : true;
|
|
589
|
+
const orderRef = useLatestRef(order);
|
|
590
|
+
const initialFocusRef = useLatestRef(initialFocus);
|
|
591
|
+
const returnFocusRef = useLatestRef(returnFocus);
|
|
592
|
+
const tree = useFloatingTree();
|
|
593
|
+
const portalContext = usePortalContext();
|
|
594
|
+
const startDismissButtonRef = React.useRef(null);
|
|
595
|
+
const endDismissButtonRef = React.useRef(null);
|
|
596
|
+
const preventReturnFocusRef = React.useRef(false);
|
|
597
|
+
const isPointerDownRef = React.useRef(false);
|
|
598
|
+
const tabbableIndexRef = React.useRef(-1);
|
|
599
|
+
const isInsidePortal = portalContext != null;
|
|
600
|
+
const floatingFocusElement = getFloatingFocusElement(floating);
|
|
601
|
+
const getTabbableContent = useEffectEvent(function(container) {
|
|
602
|
+
if (container === void 0) {
|
|
603
|
+
container = floatingFocusElement;
|
|
604
|
+
}
|
|
605
|
+
return container ? tabbable(container, getTabbableOptions()) : [];
|
|
606
|
+
});
|
|
607
|
+
const getTabbableElements = useEffectEvent((container) => {
|
|
608
|
+
const content = getTabbableContent(container);
|
|
609
|
+
return orderRef.current.map((type) => {
|
|
610
|
+
if (domReference && type === "reference") {
|
|
611
|
+
return domReference;
|
|
612
|
+
}
|
|
613
|
+
if (floatingFocusElement && type === "floating") {
|
|
614
|
+
return floatingFocusElement;
|
|
615
|
+
}
|
|
616
|
+
return content;
|
|
617
|
+
}).filter(Boolean).flat();
|
|
618
|
+
});
|
|
619
|
+
React.useEffect(() => {
|
|
620
|
+
preventReturnFocusRef.current = false;
|
|
621
|
+
}, [disabled]);
|
|
622
|
+
React.useEffect(() => {
|
|
623
|
+
if (disabled) return;
|
|
624
|
+
if (!modal) return;
|
|
625
|
+
function onKeyDown(event) {
|
|
626
|
+
if (event.key === "Tab") {
|
|
627
|
+
if (contains(floatingFocusElement, activeElement(getDocument(floatingFocusElement))) && getTabbableContent().length === 0 && !isUntrappedTypeableCombobox) {
|
|
628
|
+
stopEvent(event);
|
|
287
629
|
}
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
set: function() {
|
|
295
|
-
throw Error();
|
|
296
|
-
}
|
|
297
|
-
});
|
|
298
|
-
if (typeof Reflect === "object" && Reflect.construct) {
|
|
299
|
-
try {
|
|
300
|
-
Reflect.construct(Fake, []);
|
|
301
|
-
} catch (x) {
|
|
302
|
-
control = x;
|
|
303
|
-
}
|
|
304
|
-
Reflect.construct(fn, [], Fake);
|
|
305
|
-
} else {
|
|
306
|
-
try {
|
|
307
|
-
Fake.call();
|
|
308
|
-
} catch (x) {
|
|
309
|
-
control = x;
|
|
310
|
-
}
|
|
311
|
-
fn.call(Fake.prototype);
|
|
312
|
-
}
|
|
630
|
+
const els = getTabbableElements();
|
|
631
|
+
const target = getTarget(event);
|
|
632
|
+
if (orderRef.current[0] === "reference" && target === domReference) {
|
|
633
|
+
stopEvent(event);
|
|
634
|
+
if (event.shiftKey) {
|
|
635
|
+
enqueueFocus(els[els.length - 1]);
|
|
313
636
|
} else {
|
|
314
|
-
|
|
315
|
-
throw Error();
|
|
316
|
-
} catch (x) {
|
|
317
|
-
control = x;
|
|
318
|
-
}
|
|
319
|
-
fn();
|
|
320
|
-
}
|
|
321
|
-
} catch (sample) {
|
|
322
|
-
if (sample && control && typeof sample.stack === "string") {
|
|
323
|
-
var sampleLines = sample.stack.split("\n");
|
|
324
|
-
var controlLines = control.stack.split("\n");
|
|
325
|
-
var s = sampleLines.length - 1;
|
|
326
|
-
var c = controlLines.length - 1;
|
|
327
|
-
while (s >= 1 && c >= 0 && sampleLines[s] !== controlLines[c]) {
|
|
328
|
-
c--;
|
|
329
|
-
}
|
|
330
|
-
for (; s >= 1 && c >= 0; s--, c--) {
|
|
331
|
-
if (sampleLines[s] !== controlLines[c]) {
|
|
332
|
-
if (s !== 1 || c !== 1) {
|
|
333
|
-
do {
|
|
334
|
-
s--;
|
|
335
|
-
c--;
|
|
336
|
-
if (c < 0 || sampleLines[s] !== controlLines[c]) {
|
|
337
|
-
var _frame = "\n" + sampleLines[s].replace(" at new ", " at ");
|
|
338
|
-
if (fn.displayName && _frame.includes("<anonymous>")) {
|
|
339
|
-
_frame = _frame.replace("<anonymous>", fn.displayName);
|
|
340
|
-
}
|
|
341
|
-
{
|
|
342
|
-
if (typeof fn === "function") {
|
|
343
|
-
componentFrameCache.set(fn, _frame);
|
|
344
|
-
}
|
|
345
|
-
}
|
|
346
|
-
return _frame;
|
|
347
|
-
}
|
|
348
|
-
} while (s >= 1 && c >= 0);
|
|
349
|
-
}
|
|
350
|
-
break;
|
|
351
|
-
}
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
} finally {
|
|
355
|
-
reentry = false;
|
|
356
|
-
{
|
|
357
|
-
ReactCurrentDispatcher.current = previousDispatcher;
|
|
358
|
-
reenableLogs();
|
|
359
|
-
}
|
|
360
|
-
Error.prepareStackTrace = previousPrepareStackTrace;
|
|
361
|
-
}
|
|
362
|
-
var name = fn ? fn.displayName || fn.name : "";
|
|
363
|
-
var syntheticFrame = name ? describeBuiltInComponentFrame(name) : "";
|
|
364
|
-
{
|
|
365
|
-
if (typeof fn === "function") {
|
|
366
|
-
componentFrameCache.set(fn, syntheticFrame);
|
|
637
|
+
enqueueFocus(els[1]);
|
|
367
638
|
}
|
|
368
639
|
}
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
{
|
|
373
|
-
return describeNativeComponentFrame(fn, false);
|
|
640
|
+
if (orderRef.current[1] === "floating" && target === floatingFocusElement && event.shiftKey) {
|
|
641
|
+
stopEvent(event);
|
|
642
|
+
enqueueFocus(els[0]);
|
|
374
643
|
}
|
|
375
644
|
}
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
645
|
+
}
|
|
646
|
+
const doc = getDocument(floatingFocusElement);
|
|
647
|
+
doc.addEventListener("keydown", onKeyDown);
|
|
648
|
+
return () => {
|
|
649
|
+
doc.removeEventListener("keydown", onKeyDown);
|
|
650
|
+
};
|
|
651
|
+
}, [disabled, domReference, floatingFocusElement, modal, orderRef, isUntrappedTypeableCombobox, getTabbableContent, getTabbableElements]);
|
|
652
|
+
React.useEffect(() => {
|
|
653
|
+
if (disabled) return;
|
|
654
|
+
if (!floating) return;
|
|
655
|
+
function handleFocusIn(event) {
|
|
656
|
+
const target = getTarget(event);
|
|
657
|
+
const tabbableContent = getTabbableContent();
|
|
658
|
+
const tabbableIndex = tabbableContent.indexOf(target);
|
|
659
|
+
if (tabbableIndex !== -1) {
|
|
660
|
+
tabbableIndexRef.current = tabbableIndex;
|
|
379
661
|
}
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
try {
|
|
409
|
-
return describeUnknownElementTypeFrameInDEV(init(payload), source, ownerFn);
|
|
410
|
-
} catch (x) {
|
|
411
|
-
}
|
|
412
|
-
}
|
|
662
|
+
}
|
|
663
|
+
floating.addEventListener("focusin", handleFocusIn);
|
|
664
|
+
return () => {
|
|
665
|
+
floating.removeEventListener("focusin", handleFocusIn);
|
|
666
|
+
};
|
|
667
|
+
}, [disabled, floating, getTabbableContent]);
|
|
668
|
+
React.useEffect(() => {
|
|
669
|
+
if (disabled) return;
|
|
670
|
+
if (!closeOnFocusOut) return;
|
|
671
|
+
function handlePointerDown() {
|
|
672
|
+
isPointerDownRef.current = true;
|
|
673
|
+
setTimeout(() => {
|
|
674
|
+
isPointerDownRef.current = false;
|
|
675
|
+
});
|
|
676
|
+
}
|
|
677
|
+
function handleFocusOutside(event) {
|
|
678
|
+
const relatedTarget = event.relatedTarget;
|
|
679
|
+
queueMicrotask(() => {
|
|
680
|
+
const movedToUnrelatedNode = !(contains(domReference, relatedTarget) || contains(floating, relatedTarget) || contains(relatedTarget, floating) || contains(portalContext == null ? void 0 : portalContext.portalNode, relatedTarget) || relatedTarget != null && relatedTarget.hasAttribute(createAttribute("focus-guard")) || tree && (getChildren(tree.nodesRef.current, nodeId).find((node) => {
|
|
681
|
+
var _node$context, _node$context2;
|
|
682
|
+
return contains((_node$context = node.context) == null ? void 0 : _node$context.elements.floating, relatedTarget) || contains((_node$context2 = node.context) == null ? void 0 : _node$context2.elements.domReference, relatedTarget);
|
|
683
|
+
}) || getAncestors(tree.nodesRef.current, nodeId).find((node) => {
|
|
684
|
+
var _node$context3, _node$context4;
|
|
685
|
+
return ((_node$context3 = node.context) == null ? void 0 : _node$context3.elements.floating) === relatedTarget || ((_node$context4 = node.context) == null ? void 0 : _node$context4.elements.domReference) === relatedTarget;
|
|
686
|
+
})));
|
|
687
|
+
if (restoreFocus && movedToUnrelatedNode && activeElement(getDocument(floatingFocusElement)) === getDocument(floatingFocusElement).body) {
|
|
688
|
+
if (isHTMLElement(floatingFocusElement)) {
|
|
689
|
+
floatingFocusElement.focus();
|
|
413
690
|
}
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
var ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame;
|
|
420
|
-
function setCurrentlyValidatingElement(element) {
|
|
421
|
-
{
|
|
422
|
-
if (element) {
|
|
423
|
-
var owner = element._owner;
|
|
424
|
-
var stack = describeUnknownElementTypeFrameInDEV(element.type, element._source, owner ? owner.type : null);
|
|
425
|
-
ReactDebugCurrentFrame.setExtraStackFrame(stack);
|
|
426
|
-
} else {
|
|
427
|
-
ReactDebugCurrentFrame.setExtraStackFrame(null);
|
|
691
|
+
const prevTabbableIndex = tabbableIndexRef.current;
|
|
692
|
+
const tabbableContent = getTabbableContent();
|
|
693
|
+
const nodeToFocus = tabbableContent[prevTabbableIndex] || tabbableContent[tabbableContent.length - 1] || floatingFocusElement;
|
|
694
|
+
if (isHTMLElement(nodeToFocus)) {
|
|
695
|
+
nodeToFocus.focus();
|
|
428
696
|
}
|
|
429
697
|
}
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
for (var typeSpecName in typeSpecs) {
|
|
435
|
-
if (has(typeSpecs, typeSpecName)) {
|
|
436
|
-
var error$1 = void 0;
|
|
437
|
-
try {
|
|
438
|
-
if (typeof typeSpecs[typeSpecName] !== "function") {
|
|
439
|
-
var err = Error((componentName || "React class") + ": " + location + " type `" + typeSpecName + "` is invalid; it must be a function, usually from the `prop-types` package, but received `" + typeof typeSpecs[typeSpecName] + "`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");
|
|
440
|
-
err.name = "Invariant Violation";
|
|
441
|
-
throw err;
|
|
442
|
-
}
|
|
443
|
-
error$1 = typeSpecs[typeSpecName](values, typeSpecName, componentName, location, null, "SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED");
|
|
444
|
-
} catch (ex) {
|
|
445
|
-
error$1 = ex;
|
|
446
|
-
}
|
|
447
|
-
if (error$1 && !(error$1 instanceof Error)) {
|
|
448
|
-
setCurrentlyValidatingElement(element);
|
|
449
|
-
error("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).", componentName || "React class", location, typeSpecName, typeof error$1);
|
|
450
|
-
setCurrentlyValidatingElement(null);
|
|
451
|
-
}
|
|
452
|
-
if (error$1 instanceof Error && !(error$1.message in loggedTypeFailures)) {
|
|
453
|
-
loggedTypeFailures[error$1.message] = true;
|
|
454
|
-
setCurrentlyValidatingElement(element);
|
|
455
|
-
error("Failed %s type: %s", location, error$1.message);
|
|
456
|
-
setCurrentlyValidatingElement(null);
|
|
457
|
-
}
|
|
458
|
-
}
|
|
459
|
-
}
|
|
698
|
+
if ((isUntrappedTypeableCombobox ? true : !modal) && relatedTarget && movedToUnrelatedNode && !isPointerDownRef.current && // Fix React 18 Strict Mode returnFocus due to double rendering.
|
|
699
|
+
relatedTarget !== getPreviouslyFocusedElement()) {
|
|
700
|
+
preventReturnFocusRef.current = true;
|
|
701
|
+
onOpenChange(false, event, "focus-out");
|
|
460
702
|
}
|
|
703
|
+
});
|
|
704
|
+
}
|
|
705
|
+
if (floating && isHTMLElement(domReference)) {
|
|
706
|
+
domReference.addEventListener("focusout", handleFocusOutside);
|
|
707
|
+
domReference.addEventListener("pointerdown", handlePointerDown);
|
|
708
|
+
floating.addEventListener("focusout", handleFocusOutside);
|
|
709
|
+
return () => {
|
|
710
|
+
domReference.removeEventListener("focusout", handleFocusOutside);
|
|
711
|
+
domReference.removeEventListener("pointerdown", handlePointerDown);
|
|
712
|
+
floating.removeEventListener("focusout", handleFocusOutside);
|
|
713
|
+
};
|
|
714
|
+
}
|
|
715
|
+
}, [disabled, domReference, floating, floatingFocusElement, modal, nodeId, tree, portalContext, onOpenChange, closeOnFocusOut, restoreFocus, getTabbableContent, isUntrappedTypeableCombobox]);
|
|
716
|
+
React.useEffect(() => {
|
|
717
|
+
var _portalContext$portal;
|
|
718
|
+
if (disabled) return;
|
|
719
|
+
const portalNodes = Array.from((portalContext == null || (_portalContext$portal = portalContext.portalNode) == null ? void 0 : _portalContext$portal.querySelectorAll("[" + createAttribute("portal") + "]")) || []);
|
|
720
|
+
if (floating) {
|
|
721
|
+
const insideElements = [floating, ...portalNodes, startDismissButtonRef.current, endDismissButtonRef.current, orderRef.current.includes("reference") || isUntrappedTypeableCombobox ? domReference : null].filter((x) => x != null);
|
|
722
|
+
const cleanup = modal || isUntrappedTypeableCombobox ? markOthers(insideElements, guards, !guards) : markOthers(insideElements);
|
|
723
|
+
return () => {
|
|
724
|
+
cleanup();
|
|
725
|
+
};
|
|
726
|
+
}
|
|
727
|
+
}, [disabled, domReference, floating, modal, orderRef, portalContext, isUntrappedTypeableCombobox, guards]);
|
|
728
|
+
index(() => {
|
|
729
|
+
if (disabled || !isHTMLElement(floatingFocusElement)) return;
|
|
730
|
+
const doc = getDocument(floatingFocusElement);
|
|
731
|
+
const previouslyFocusedElement = activeElement(doc);
|
|
732
|
+
queueMicrotask(() => {
|
|
733
|
+
const focusableElements = getTabbableElements(floatingFocusElement);
|
|
734
|
+
const initialFocusValue = initialFocusRef.current;
|
|
735
|
+
const elToFocus = (typeof initialFocusValue === "number" ? focusableElements[initialFocusValue] : initialFocusValue.current) || floatingFocusElement;
|
|
736
|
+
const focusAlreadyInsideFloatingEl = contains(floatingFocusElement, previouslyFocusedElement);
|
|
737
|
+
if (!ignoreInitialFocus && !focusAlreadyInsideFloatingEl && open) {
|
|
738
|
+
enqueueFocus(elToFocus, {
|
|
739
|
+
preventScroll: elToFocus === floatingFocusElement
|
|
740
|
+
});
|
|
461
741
|
}
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
742
|
+
});
|
|
743
|
+
}, [disabled, open, floatingFocusElement, ignoreInitialFocus, getTabbableElements, initialFocusRef]);
|
|
744
|
+
index(() => {
|
|
745
|
+
if (disabled || !floatingFocusElement) return;
|
|
746
|
+
let preventReturnFocusScroll = false;
|
|
747
|
+
const doc = getDocument(floatingFocusElement);
|
|
748
|
+
const previouslyFocusedElement = activeElement(doc);
|
|
749
|
+
const contextData = dataRef.current;
|
|
750
|
+
let openEvent = contextData.openEvent;
|
|
751
|
+
const domReference2 = refs.domReference.current;
|
|
752
|
+
addPreviouslyFocusedElement(previouslyFocusedElement);
|
|
753
|
+
function onOpenChange2(_ref) {
|
|
754
|
+
let {
|
|
755
|
+
open: open2,
|
|
756
|
+
reason,
|
|
757
|
+
event,
|
|
758
|
+
nested
|
|
759
|
+
} = _ref;
|
|
760
|
+
if (open2) {
|
|
761
|
+
openEvent = event;
|
|
465
762
|
}
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
var hasToStringTag = typeof Symbol === "function" && Symbol.toStringTag;
|
|
469
|
-
var type = hasToStringTag && value[Symbol.toStringTag] || value.constructor.name || "Object";
|
|
470
|
-
return type;
|
|
471
|
-
}
|
|
763
|
+
if (reason === "escape-key" && refs.domReference.current) {
|
|
764
|
+
addPreviouslyFocusedElement(refs.domReference.current);
|
|
472
765
|
}
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
try {
|
|
476
|
-
testStringCoercion(value);
|
|
477
|
-
return false;
|
|
478
|
-
} catch (e) {
|
|
479
|
-
return true;
|
|
480
|
-
}
|
|
481
|
-
}
|
|
766
|
+
if (reason === "hover" && event.type === "mouseleave") {
|
|
767
|
+
preventReturnFocusRef.current = true;
|
|
482
768
|
}
|
|
483
|
-
|
|
484
|
-
|
|
769
|
+
if (reason !== "outside-press") return;
|
|
770
|
+
if (nested) {
|
|
771
|
+
preventReturnFocusRef.current = false;
|
|
772
|
+
preventReturnFocusScroll = true;
|
|
773
|
+
} else {
|
|
774
|
+
preventReturnFocusRef.current = !(isVirtualClick(event) || isVirtualPointerEvent(event));
|
|
485
775
|
}
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
776
|
+
}
|
|
777
|
+
events.on("openchange", onOpenChange2);
|
|
778
|
+
return () => {
|
|
779
|
+
events.off("openchange", onOpenChange2);
|
|
780
|
+
const activeEl = activeElement(doc);
|
|
781
|
+
const isFocusInsideFloatingTree = contains(floating, activeEl) || tree && getChildren(tree.nodesRef.current, nodeId).some((node) => {
|
|
782
|
+
var _node$context5;
|
|
783
|
+
return contains((_node$context5 = node.context) == null ? void 0 : _node$context5.elements.floating, activeEl);
|
|
784
|
+
});
|
|
785
|
+
const shouldFocusReference = isFocusInsideFloatingTree || openEvent && ["click", "mousedown"].includes(openEvent.type);
|
|
786
|
+
if (shouldFocusReference && refs.domReference.current) {
|
|
787
|
+
addPreviouslyFocusedElement(refs.domReference.current);
|
|
493
788
|
}
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
};
|
|
501
|
-
var specialPropKeyWarningShown;
|
|
502
|
-
var specialPropRefWarningShown;
|
|
503
|
-
var didWarnAboutStringRefs;
|
|
504
|
-
{
|
|
505
|
-
didWarnAboutStringRefs = {};
|
|
506
|
-
}
|
|
507
|
-
function hasValidRef(config) {
|
|
508
|
-
{
|
|
509
|
-
if (hasOwnProperty.call(config, "ref")) {
|
|
510
|
-
var getter = Object.getOwnPropertyDescriptor(config, "ref").get;
|
|
511
|
-
if (getter && getter.isReactWarning) {
|
|
512
|
-
return false;
|
|
513
|
-
}
|
|
514
|
-
}
|
|
515
|
-
}
|
|
516
|
-
return config.ref !== void 0;
|
|
517
|
-
}
|
|
518
|
-
function hasValidKey(config) {
|
|
519
|
-
{
|
|
520
|
-
if (hasOwnProperty.call(config, "key")) {
|
|
521
|
-
var getter = Object.getOwnPropertyDescriptor(config, "key").get;
|
|
522
|
-
if (getter && getter.isReactWarning) {
|
|
523
|
-
return false;
|
|
524
|
-
}
|
|
525
|
-
}
|
|
789
|
+
const returnContextElement = domReference2 || previouslyFocusedElement;
|
|
790
|
+
const tabbableElements = tabbable(getDocument(returnContextElement).body, getTabbableOptions());
|
|
791
|
+
queueMicrotask(() => {
|
|
792
|
+
let returnElement = getPreviouslyFocusedElement();
|
|
793
|
+
if (!returnElement && isHTMLElement(returnContextElement) && floating) {
|
|
794
|
+
returnElement = getClosestTabbableElement(tabbableElements, returnContextElement, floating);
|
|
526
795
|
}
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
}
|
|
796
|
+
if (
|
|
797
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
798
|
+
returnFocusRef.current && !preventReturnFocusRef.current && isHTMLElement(returnElement) && // If the focus moved somewhere else after mount, avoid returning focus
|
|
799
|
+
// since it likely entered a different element which should be
|
|
800
|
+
// respected: https://github.com/floating-ui/floating-ui/issues/2607
|
|
801
|
+
(returnElement !== activeEl && activeEl !== doc.body ? isFocusInsideFloatingTree : true)
|
|
802
|
+
) {
|
|
803
|
+
returnElement.focus({
|
|
804
|
+
preventScroll: preventReturnFocusScroll
|
|
805
|
+
});
|
|
538
806
|
}
|
|
807
|
+
});
|
|
808
|
+
};
|
|
809
|
+
}, [disabled, floating, floatingFocusElement, returnFocusRef, dataRef, refs, events, tree, nodeId]);
|
|
810
|
+
index(() => {
|
|
811
|
+
if (disabled) return;
|
|
812
|
+
if (!portalContext) return;
|
|
813
|
+
portalContext.setFocusManagerState({
|
|
814
|
+
modal,
|
|
815
|
+
closeOnFocusOut,
|
|
816
|
+
open,
|
|
817
|
+
onOpenChange,
|
|
818
|
+
refs
|
|
819
|
+
});
|
|
820
|
+
return () => {
|
|
821
|
+
portalContext.setFocusManagerState(null);
|
|
822
|
+
};
|
|
823
|
+
}, [disabled, portalContext, modal, open, onOpenChange, refs, closeOnFocusOut]);
|
|
824
|
+
index(() => {
|
|
825
|
+
if (disabled) return;
|
|
826
|
+
if (!floatingFocusElement) return;
|
|
827
|
+
if (typeof MutationObserver !== "function") return;
|
|
828
|
+
if (ignoreInitialFocus) return;
|
|
829
|
+
const handleMutation = () => {
|
|
830
|
+
const tabIndex = floatingFocusElement.getAttribute("tabindex");
|
|
831
|
+
const tabbableContent = getTabbableContent();
|
|
832
|
+
const activeEl = activeElement(getDocument(floating));
|
|
833
|
+
const tabbableIndex = tabbableContent.indexOf(activeEl);
|
|
834
|
+
if (tabbableIndex !== -1) {
|
|
835
|
+
tabbableIndexRef.current = tabbableIndex;
|
|
539
836
|
}
|
|
540
|
-
|
|
541
|
-
{
|
|
542
|
-
|
|
543
|
-
if (!specialPropKeyWarningShown) {
|
|
544
|
-
specialPropKeyWarningShown = true;
|
|
545
|
-
error("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)", displayName);
|
|
546
|
-
}
|
|
547
|
-
};
|
|
548
|
-
warnAboutAccessingKey.isReactWarning = true;
|
|
549
|
-
Object.defineProperty(props, "key", {
|
|
550
|
-
get: warnAboutAccessingKey,
|
|
551
|
-
configurable: true
|
|
552
|
-
});
|
|
837
|
+
if (orderRef.current.includes("floating") || activeEl !== refs.domReference.current && tabbableContent.length === 0) {
|
|
838
|
+
if (tabIndex !== "0") {
|
|
839
|
+
floatingFocusElement.setAttribute("tabindex", "0");
|
|
553
840
|
}
|
|
841
|
+
} else if (tabIndex !== "-1") {
|
|
842
|
+
floatingFocusElement.setAttribute("tabindex", "-1");
|
|
554
843
|
}
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
844
|
+
};
|
|
845
|
+
handleMutation();
|
|
846
|
+
const observer = new MutationObserver(handleMutation);
|
|
847
|
+
observer.observe(floatingFocusElement, {
|
|
848
|
+
childList: true,
|
|
849
|
+
subtree: true,
|
|
850
|
+
attributes: true
|
|
851
|
+
});
|
|
852
|
+
return () => {
|
|
853
|
+
observer.disconnect();
|
|
854
|
+
};
|
|
855
|
+
}, [disabled, floating, floatingFocusElement, refs, orderRef, getTabbableContent, ignoreInitialFocus]);
|
|
856
|
+
function renderDismissButton(location) {
|
|
857
|
+
if (disabled || !visuallyHiddenDismiss || !modal) {
|
|
858
|
+
return null;
|
|
859
|
+
}
|
|
860
|
+
return /* @__PURE__ */ React.createElement(VisuallyHiddenDismiss, {
|
|
861
|
+
ref: location === "start" ? startDismissButtonRef : endDismissButtonRef,
|
|
862
|
+
onClick: (event) => onOpenChange(false, event.nativeEvent)
|
|
863
|
+
}, typeof visuallyHiddenDismiss === "string" ? visuallyHiddenDismiss : "Dismiss");
|
|
864
|
+
}
|
|
865
|
+
const shouldRenderGuards = !disabled && guards && (modal ? !isUntrappedTypeableCombobox : true) && (isInsidePortal || modal);
|
|
866
|
+
return /* @__PURE__ */ React.createElement(React.Fragment, null, shouldRenderGuards && /* @__PURE__ */ React.createElement(FocusGuard, {
|
|
867
|
+
"data-type": "inside",
|
|
868
|
+
ref: portalContext == null ? void 0 : portalContext.beforeInsideRef,
|
|
869
|
+
onFocus: (event) => {
|
|
870
|
+
if (modal) {
|
|
871
|
+
const els = getTabbableElements();
|
|
872
|
+
enqueueFocus(order[0] === "reference" ? els[0] : els[els.length - 1]);
|
|
873
|
+
} else if (portalContext != null && portalContext.preserveTabOrder && portalContext.portalNode) {
|
|
874
|
+
preventReturnFocusRef.current = false;
|
|
875
|
+
if (isOutsideEvent(event, portalContext.portalNode)) {
|
|
876
|
+
const nextTabbable = getNextTabbable() || domReference;
|
|
877
|
+
nextTabbable == null || nextTabbable.focus();
|
|
878
|
+
} else {
|
|
879
|
+
var _portalContext$before;
|
|
880
|
+
(_portalContext$before = portalContext.beforeOutsideRef.current) == null || _portalContext$before.focus();
|
|
568
881
|
}
|
|
569
882
|
}
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
_owner: owner
|
|
581
|
-
};
|
|
582
|
-
{
|
|
583
|
-
element._store = {};
|
|
584
|
-
Object.defineProperty(element._store, "validated", {
|
|
585
|
-
configurable: false,
|
|
586
|
-
enumerable: false,
|
|
587
|
-
writable: true,
|
|
588
|
-
value: false
|
|
589
|
-
});
|
|
590
|
-
Object.defineProperty(element, "_self", {
|
|
591
|
-
configurable: false,
|
|
592
|
-
enumerable: false,
|
|
593
|
-
writable: false,
|
|
594
|
-
value: self
|
|
595
|
-
});
|
|
596
|
-
Object.defineProperty(element, "_source", {
|
|
597
|
-
configurable: false,
|
|
598
|
-
enumerable: false,
|
|
599
|
-
writable: false,
|
|
600
|
-
value: source
|
|
601
|
-
});
|
|
602
|
-
if (Object.freeze) {
|
|
603
|
-
Object.freeze(element.props);
|
|
604
|
-
Object.freeze(element);
|
|
605
|
-
}
|
|
883
|
+
}
|
|
884
|
+
}), !isUntrappedTypeableCombobox && renderDismissButton("start"), children, renderDismissButton("end"), shouldRenderGuards && /* @__PURE__ */ React.createElement(FocusGuard, {
|
|
885
|
+
"data-type": "inside",
|
|
886
|
+
ref: portalContext == null ? void 0 : portalContext.afterInsideRef,
|
|
887
|
+
onFocus: (event) => {
|
|
888
|
+
if (modal) {
|
|
889
|
+
enqueueFocus(getTabbableElements()[0]);
|
|
890
|
+
} else if (portalContext != null && portalContext.preserveTabOrder && portalContext.portalNode) {
|
|
891
|
+
if (closeOnFocusOut) {
|
|
892
|
+
preventReturnFocusRef.current = true;
|
|
606
893
|
}
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
{
|
|
611
|
-
var
|
|
612
|
-
|
|
613
|
-
var key = null;
|
|
614
|
-
var ref = null;
|
|
615
|
-
if (maybeKey !== void 0) {
|
|
616
|
-
{
|
|
617
|
-
checkKeyStringCoercion(maybeKey);
|
|
618
|
-
}
|
|
619
|
-
key = "" + maybeKey;
|
|
620
|
-
}
|
|
621
|
-
if (hasValidKey(config)) {
|
|
622
|
-
{
|
|
623
|
-
checkKeyStringCoercion(config.key);
|
|
624
|
-
}
|
|
625
|
-
key = "" + config.key;
|
|
626
|
-
}
|
|
627
|
-
if (hasValidRef(config)) {
|
|
628
|
-
ref = config.ref;
|
|
629
|
-
warnIfStringRefCannotBeAutoConverted(config, self);
|
|
630
|
-
}
|
|
631
|
-
for (propName in config) {
|
|
632
|
-
if (hasOwnProperty.call(config, propName) && !RESERVED_PROPS.hasOwnProperty(propName)) {
|
|
633
|
-
props[propName] = config[propName];
|
|
634
|
-
}
|
|
635
|
-
}
|
|
636
|
-
if (type && type.defaultProps) {
|
|
637
|
-
var defaultProps = type.defaultProps;
|
|
638
|
-
for (propName in defaultProps) {
|
|
639
|
-
if (props[propName] === void 0) {
|
|
640
|
-
props[propName] = defaultProps[propName];
|
|
641
|
-
}
|
|
642
|
-
}
|
|
643
|
-
}
|
|
644
|
-
if (key || ref) {
|
|
645
|
-
var displayName = typeof type === "function" ? type.displayName || type.name || "Unknown" : type;
|
|
646
|
-
if (key) {
|
|
647
|
-
defineKeyPropWarningGetter(props, displayName);
|
|
648
|
-
}
|
|
649
|
-
if (ref) {
|
|
650
|
-
defineRefPropWarningGetter(props, displayName);
|
|
651
|
-
}
|
|
652
|
-
}
|
|
653
|
-
return ReactElement(type, key, ref, self, source, ReactCurrentOwner.current, props);
|
|
894
|
+
if (isOutsideEvent(event, portalContext.portalNode)) {
|
|
895
|
+
const prevTabbable = getPreviousTabbable() || domReference;
|
|
896
|
+
prevTabbable == null || prevTabbable.focus();
|
|
897
|
+
} else {
|
|
898
|
+
var _portalContext$afterO;
|
|
899
|
+
(_portalContext$afterO = portalContext.afterOutsideRef.current) == null || _portalContext$afterO.focus();
|
|
654
900
|
}
|
|
655
901
|
}
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
902
|
+
}
|
|
903
|
+
}));
|
|
904
|
+
}
|
|
905
|
+
const bubbleHandlerKeys = {
|
|
906
|
+
pointerdown: "onPointerDown",
|
|
907
|
+
mousedown: "onMouseDown",
|
|
908
|
+
click: "onClick"
|
|
909
|
+
};
|
|
910
|
+
const captureHandlerKeys = {
|
|
911
|
+
pointerdown: "onPointerDownCapture",
|
|
912
|
+
mousedown: "onMouseDownCapture",
|
|
913
|
+
click: "onClickCapture"
|
|
914
|
+
};
|
|
915
|
+
const normalizeProp = (normalizable) => {
|
|
916
|
+
var _normalizable$escapeK, _normalizable$outside;
|
|
917
|
+
return {
|
|
918
|
+
escapeKey: typeof normalizable === "boolean" ? normalizable : (_normalizable$escapeK = normalizable == null ? void 0 : normalizable.escapeKey) != null ? _normalizable$escapeK : false,
|
|
919
|
+
outsidePress: typeof normalizable === "boolean" ? normalizable : (_normalizable$outside = normalizable == null ? void 0 : normalizable.outsidePress) != null ? _normalizable$outside : true
|
|
920
|
+
};
|
|
921
|
+
};
|
|
922
|
+
function useDismiss(context, props) {
|
|
923
|
+
if (props === void 0) {
|
|
924
|
+
props = {};
|
|
925
|
+
}
|
|
926
|
+
const {
|
|
927
|
+
open,
|
|
928
|
+
onOpenChange,
|
|
929
|
+
elements,
|
|
930
|
+
dataRef
|
|
931
|
+
} = context;
|
|
932
|
+
const {
|
|
933
|
+
enabled = true,
|
|
934
|
+
escapeKey = true,
|
|
935
|
+
outsidePress: unstable_outsidePress = true,
|
|
936
|
+
outsidePressEvent = "pointerdown",
|
|
937
|
+
referencePress = false,
|
|
938
|
+
referencePressEvent = "pointerdown",
|
|
939
|
+
ancestorScroll = false,
|
|
940
|
+
bubbles,
|
|
941
|
+
capture
|
|
942
|
+
} = props;
|
|
943
|
+
const tree = useFloatingTree();
|
|
944
|
+
const outsidePressFn = useEffectEvent(typeof unstable_outsidePress === "function" ? unstable_outsidePress : () => false);
|
|
945
|
+
const outsidePress = typeof unstable_outsidePress === "function" ? outsidePressFn : unstable_outsidePress;
|
|
946
|
+
const insideReactTreeRef = React.useRef(false);
|
|
947
|
+
const endedOrStartedInsideRef = React.useRef(false);
|
|
948
|
+
const {
|
|
949
|
+
escapeKey: escapeKeyBubbles,
|
|
950
|
+
outsidePress: outsidePressBubbles
|
|
951
|
+
} = normalizeProp(bubbles);
|
|
952
|
+
const {
|
|
953
|
+
escapeKey: escapeKeyCapture,
|
|
954
|
+
outsidePress: outsidePressCapture
|
|
955
|
+
} = normalizeProp(capture);
|
|
956
|
+
const closeOnEscapeKeyDown = useEffectEvent((event) => {
|
|
957
|
+
var _dataRef$current$floa;
|
|
958
|
+
if (!open || !enabled || !escapeKey || event.key !== "Escape") {
|
|
959
|
+
return;
|
|
960
|
+
}
|
|
961
|
+
const nodeId = (_dataRef$current$floa = dataRef.current.floatingContext) == null ? void 0 : _dataRef$current$floa.nodeId;
|
|
962
|
+
const children = tree ? getChildren(tree.nodesRef.current, nodeId) : [];
|
|
963
|
+
if (!escapeKeyBubbles) {
|
|
964
|
+
event.stopPropagation();
|
|
965
|
+
if (children.length > 0) {
|
|
966
|
+
let shouldDismiss = true;
|
|
967
|
+
children.forEach((child) => {
|
|
968
|
+
var _child$context;
|
|
969
|
+
if ((_child$context = child.context) != null && _child$context.open && !child.context.dataRef.current.__escapeKeyBubbles) {
|
|
970
|
+
shouldDismiss = false;
|
|
971
|
+
return;
|
|
666
972
|
}
|
|
973
|
+
});
|
|
974
|
+
if (!shouldDismiss) {
|
|
975
|
+
return;
|
|
667
976
|
}
|
|
668
977
|
}
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
978
|
+
}
|
|
979
|
+
onOpenChange(false, isReactEvent(event) ? event.nativeEvent : event, "escape-key");
|
|
980
|
+
});
|
|
981
|
+
const closeOnEscapeKeyDownCapture = useEffectEvent((event) => {
|
|
982
|
+
var _getTarget2;
|
|
983
|
+
const callback = () => {
|
|
984
|
+
var _getTarget;
|
|
985
|
+
closeOnEscapeKeyDown(event);
|
|
986
|
+
(_getTarget = getTarget(event)) == null || _getTarget.removeEventListener("keydown", callback);
|
|
987
|
+
};
|
|
988
|
+
(_getTarget2 = getTarget(event)) == null || _getTarget2.addEventListener("keydown", callback);
|
|
989
|
+
});
|
|
990
|
+
const closeOnPressOutside = useEffectEvent((event) => {
|
|
991
|
+
var _dataRef$current$floa2;
|
|
992
|
+
const insideReactTree = insideReactTreeRef.current;
|
|
993
|
+
insideReactTreeRef.current = false;
|
|
994
|
+
const endedOrStartedInside = endedOrStartedInsideRef.current;
|
|
995
|
+
endedOrStartedInsideRef.current = false;
|
|
996
|
+
if (outsidePressEvent === "click" && endedOrStartedInside) {
|
|
997
|
+
return;
|
|
998
|
+
}
|
|
999
|
+
if (insideReactTree) {
|
|
1000
|
+
return;
|
|
1001
|
+
}
|
|
1002
|
+
if (typeof outsidePress === "function" && !outsidePress(event)) {
|
|
1003
|
+
return;
|
|
1004
|
+
}
|
|
1005
|
+
const target = getTarget(event);
|
|
1006
|
+
const inertSelector = "[" + createAttribute("inert") + "]";
|
|
1007
|
+
const markers = getDocument(elements.floating).querySelectorAll(inertSelector);
|
|
1008
|
+
let targetRootAncestor = isElement(target) ? target : null;
|
|
1009
|
+
while (targetRootAncestor && !isLastTraversableNode(targetRootAncestor)) {
|
|
1010
|
+
const nextParent = getParentNode(targetRootAncestor);
|
|
1011
|
+
if (isLastTraversableNode(nextParent) || !isElement(nextParent)) {
|
|
1012
|
+
break;
|
|
672
1013
|
}
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
1014
|
+
targetRootAncestor = nextParent;
|
|
1015
|
+
}
|
|
1016
|
+
if (markers.length && isElement(target) && !isRootElement(target) && // Clicked on a direct ancestor (e.g. FloatingOverlay).
|
|
1017
|
+
!contains(target, elements.floating) && // If the target root element contains none of the markers, then the
|
|
1018
|
+
// element was injected after the floating element rendered.
|
|
1019
|
+
Array.from(markers).every((marker) => !contains(targetRootAncestor, marker))) {
|
|
1020
|
+
return;
|
|
1021
|
+
}
|
|
1022
|
+
if (isHTMLElement(target) && floating) {
|
|
1023
|
+
const canScrollX = target.clientWidth > 0 && target.scrollWidth > target.clientWidth;
|
|
1024
|
+
const canScrollY = target.clientHeight > 0 && target.scrollHeight > target.clientHeight;
|
|
1025
|
+
let xCond = canScrollY && event.offsetX > target.clientWidth;
|
|
1026
|
+
if (canScrollY) {
|
|
1027
|
+
const isRTL = getComputedStyle(target).direction === "rtl";
|
|
1028
|
+
if (isRTL) {
|
|
1029
|
+
xCond = event.offsetX <= target.offsetWidth - target.clientWidth;
|
|
676
1030
|
}
|
|
677
1031
|
}
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
if (ReactCurrentOwner$1.current) {
|
|
681
|
-
var name = getComponentNameFromType(ReactCurrentOwner$1.current.type);
|
|
682
|
-
if (name) {
|
|
683
|
-
return "\n\nCheck the render method of `" + name + "`.";
|
|
684
|
-
}
|
|
685
|
-
}
|
|
686
|
-
return "";
|
|
687
|
-
}
|
|
1032
|
+
if (xCond || canScrollX && event.offsetY > target.clientHeight) {
|
|
1033
|
+
return;
|
|
688
1034
|
}
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
1035
|
+
}
|
|
1036
|
+
const nodeId = (_dataRef$current$floa2 = dataRef.current.floatingContext) == null ? void 0 : _dataRef$current$floa2.nodeId;
|
|
1037
|
+
const targetIsInsideChildren = tree && getChildren(tree.nodesRef.current, nodeId).some((node) => {
|
|
1038
|
+
var _node$context;
|
|
1039
|
+
return isEventTargetWithin(event, (_node$context = node.context) == null ? void 0 : _node$context.elements.floating);
|
|
1040
|
+
});
|
|
1041
|
+
if (isEventTargetWithin(event, elements.floating) || isEventTargetWithin(event, elements.domReference) || targetIsInsideChildren) {
|
|
1042
|
+
return;
|
|
1043
|
+
}
|
|
1044
|
+
const children = tree ? getChildren(tree.nodesRef.current, nodeId) : [];
|
|
1045
|
+
if (children.length > 0) {
|
|
1046
|
+
let shouldDismiss = true;
|
|
1047
|
+
children.forEach((child) => {
|
|
1048
|
+
var _child$context2;
|
|
1049
|
+
if ((_child$context2 = child.context) != null && _child$context2.open && !child.context.dataRef.current.__outsidePressBubbles) {
|
|
1050
|
+
shouldDismiss = false;
|
|
1051
|
+
return;
|
|
692
1052
|
}
|
|
1053
|
+
});
|
|
1054
|
+
if (!shouldDismiss) {
|
|
1055
|
+
return;
|
|
693
1056
|
}
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
1057
|
+
}
|
|
1058
|
+
onOpenChange(false, event, "outside-press");
|
|
1059
|
+
});
|
|
1060
|
+
const closeOnPressOutsideCapture = useEffectEvent((event) => {
|
|
1061
|
+
var _getTarget4;
|
|
1062
|
+
const callback = () => {
|
|
1063
|
+
var _getTarget3;
|
|
1064
|
+
closeOnPressOutside(event);
|
|
1065
|
+
(_getTarget3 = getTarget(event)) == null || _getTarget3.removeEventListener(outsidePressEvent, callback);
|
|
1066
|
+
};
|
|
1067
|
+
(_getTarget4 = getTarget(event)) == null || _getTarget4.addEventListener(outsidePressEvent, callback);
|
|
1068
|
+
});
|
|
1069
|
+
React.useEffect(() => {
|
|
1070
|
+
if (!open || !enabled) {
|
|
1071
|
+
return;
|
|
1072
|
+
}
|
|
1073
|
+
dataRef.current.__escapeKeyBubbles = escapeKeyBubbles;
|
|
1074
|
+
dataRef.current.__outsidePressBubbles = outsidePressBubbles;
|
|
1075
|
+
function onScroll(event) {
|
|
1076
|
+
onOpenChange(false, event, "ancestor-scroll");
|
|
1077
|
+
}
|
|
1078
|
+
const doc = getDocument(elements.floating);
|
|
1079
|
+
escapeKey && doc.addEventListener("keydown", escapeKeyCapture ? closeOnEscapeKeyDownCapture : closeOnEscapeKeyDown, escapeKeyCapture);
|
|
1080
|
+
outsidePress && doc.addEventListener(outsidePressEvent, outsidePressCapture ? closeOnPressOutsideCapture : closeOnPressOutside, outsidePressCapture);
|
|
1081
|
+
let ancestors = [];
|
|
1082
|
+
if (ancestorScroll) {
|
|
1083
|
+
if (isElement(elements.domReference)) {
|
|
1084
|
+
ancestors = getOverflowAncestors(elements.domReference);
|
|
706
1085
|
}
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
if (!element._store || element._store.validated || element.key != null) {
|
|
710
|
-
return;
|
|
711
|
-
}
|
|
712
|
-
element._store.validated = true;
|
|
713
|
-
var currentComponentErrorInfo = getCurrentComponentErrorInfo(parentType);
|
|
714
|
-
if (ownerHasKeyUseWarning[currentComponentErrorInfo]) {
|
|
715
|
-
return;
|
|
716
|
-
}
|
|
717
|
-
ownerHasKeyUseWarning[currentComponentErrorInfo] = true;
|
|
718
|
-
var childOwner = "";
|
|
719
|
-
if (element && element._owner && element._owner !== ReactCurrentOwner$1.current) {
|
|
720
|
-
childOwner = " It was passed a child from " + getComponentNameFromType(element._owner.type) + ".";
|
|
721
|
-
}
|
|
722
|
-
setCurrentlyValidatingElement$1(element);
|
|
723
|
-
error('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.', currentComponentErrorInfo, childOwner);
|
|
724
|
-
setCurrentlyValidatingElement$1(null);
|
|
725
|
-
}
|
|
1086
|
+
if (isElement(elements.floating)) {
|
|
1087
|
+
ancestors = ancestors.concat(getOverflowAncestors(elements.floating));
|
|
726
1088
|
}
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
if (typeof node !== "object") {
|
|
730
|
-
return;
|
|
731
|
-
}
|
|
732
|
-
if (isArray(node)) {
|
|
733
|
-
for (var i = 0; i < node.length; i++) {
|
|
734
|
-
var child = node[i];
|
|
735
|
-
if (isValidElement(child)) {
|
|
736
|
-
validateExplicitKey(child, parentType);
|
|
737
|
-
}
|
|
738
|
-
}
|
|
739
|
-
} else if (isValidElement(node)) {
|
|
740
|
-
if (node._store) {
|
|
741
|
-
node._store.validated = true;
|
|
742
|
-
}
|
|
743
|
-
} else if (node) {
|
|
744
|
-
var iteratorFn = getIteratorFn(node);
|
|
745
|
-
if (typeof iteratorFn === "function") {
|
|
746
|
-
if (iteratorFn !== node.entries) {
|
|
747
|
-
var iterator = iteratorFn.call(node);
|
|
748
|
-
var step;
|
|
749
|
-
while (!(step = iterator.next()).done) {
|
|
750
|
-
if (isValidElement(step.value)) {
|
|
751
|
-
validateExplicitKey(step.value, parentType);
|
|
752
|
-
}
|
|
753
|
-
}
|
|
754
|
-
}
|
|
755
|
-
}
|
|
756
|
-
}
|
|
757
|
-
}
|
|
1089
|
+
if (!isElement(elements.reference) && elements.reference && elements.reference.contextElement) {
|
|
1090
|
+
ancestors = ancestors.concat(getOverflowAncestors(elements.reference.contextElement));
|
|
758
1091
|
}
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
}
|
|
786
|
-
}
|
|
1092
|
+
}
|
|
1093
|
+
ancestors = ancestors.filter((ancestor) => {
|
|
1094
|
+
var _doc$defaultView;
|
|
1095
|
+
return ancestor !== ((_doc$defaultView = doc.defaultView) == null ? void 0 : _doc$defaultView.visualViewport);
|
|
1096
|
+
});
|
|
1097
|
+
ancestors.forEach((ancestor) => {
|
|
1098
|
+
ancestor.addEventListener("scroll", onScroll, {
|
|
1099
|
+
passive: true
|
|
1100
|
+
});
|
|
1101
|
+
});
|
|
1102
|
+
return () => {
|
|
1103
|
+
escapeKey && doc.removeEventListener("keydown", escapeKeyCapture ? closeOnEscapeKeyDownCapture : closeOnEscapeKeyDown, escapeKeyCapture);
|
|
1104
|
+
outsidePress && doc.removeEventListener(outsidePressEvent, outsidePressCapture ? closeOnPressOutsideCapture : closeOnPressOutside, outsidePressCapture);
|
|
1105
|
+
ancestors.forEach((ancestor) => {
|
|
1106
|
+
ancestor.removeEventListener("scroll", onScroll);
|
|
1107
|
+
});
|
|
1108
|
+
};
|
|
1109
|
+
}, [dataRef, elements, escapeKey, outsidePress, outsidePressEvent, open, onOpenChange, ancestorScroll, enabled, escapeKeyBubbles, outsidePressBubbles, closeOnEscapeKeyDown, escapeKeyCapture, closeOnEscapeKeyDownCapture, closeOnPressOutside, outsidePressCapture, closeOnPressOutsideCapture]);
|
|
1110
|
+
React.useEffect(() => {
|
|
1111
|
+
insideReactTreeRef.current = false;
|
|
1112
|
+
}, [outsidePress, outsidePressEvent]);
|
|
1113
|
+
const reference = React.useMemo(() => ({
|
|
1114
|
+
onKeyDown: closeOnEscapeKeyDown,
|
|
1115
|
+
[bubbleHandlerKeys[referencePressEvent]]: (event) => {
|
|
1116
|
+
if (referencePress) {
|
|
1117
|
+
onOpenChange(false, event.nativeEvent, "reference-press");
|
|
787
1118
|
}
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
1119
|
+
}
|
|
1120
|
+
}), [closeOnEscapeKeyDown, onOpenChange, referencePress, referencePressEvent]);
|
|
1121
|
+
const floating = React.useMemo(() => ({
|
|
1122
|
+
onKeyDown: closeOnEscapeKeyDown,
|
|
1123
|
+
onMouseDown() {
|
|
1124
|
+
endedOrStartedInsideRef.current = true;
|
|
1125
|
+
},
|
|
1126
|
+
onMouseUp() {
|
|
1127
|
+
endedOrStartedInsideRef.current = true;
|
|
1128
|
+
},
|
|
1129
|
+
[captureHandlerKeys[outsidePressEvent]]: () => {
|
|
1130
|
+
insideReactTreeRef.current = true;
|
|
1131
|
+
}
|
|
1132
|
+
}), [closeOnEscapeKeyDown, outsidePressEvent]);
|
|
1133
|
+
return React.useMemo(() => enabled ? {
|
|
1134
|
+
reference,
|
|
1135
|
+
floating
|
|
1136
|
+
} : {}, [enabled, reference, floating]);
|
|
1137
|
+
}
|
|
1138
|
+
function useFloatingRootContext(options) {
|
|
1139
|
+
const {
|
|
1140
|
+
open = false,
|
|
1141
|
+
onOpenChange: onOpenChangeProp,
|
|
1142
|
+
elements: elementsProp
|
|
1143
|
+
} = options;
|
|
1144
|
+
const floatingId = useId();
|
|
1145
|
+
const dataRef = React.useRef({});
|
|
1146
|
+
const [events] = React.useState(() => createPubSub());
|
|
1147
|
+
const nested = useFloatingParentNodeId() != null;
|
|
1148
|
+
if (process.env.NODE_ENV !== "production") {
|
|
1149
|
+
const optionDomReference = elementsProp.reference;
|
|
1150
|
+
if (optionDomReference && !isElement(optionDomReference)) {
|
|
1151
|
+
error("Cannot pass a virtual element to the `elements.reference` option,", "as it must be a real DOM element. Use `refs.setPositionReference()`", "instead.");
|
|
1152
|
+
}
|
|
1153
|
+
}
|
|
1154
|
+
const [positionReference, setPositionReference] = React.useState(elementsProp.reference);
|
|
1155
|
+
const onOpenChange = useEffectEvent((open2, event, reason) => {
|
|
1156
|
+
dataRef.current.openEvent = open2 ? event : void 0;
|
|
1157
|
+
events.emit("openchange", {
|
|
1158
|
+
open: open2,
|
|
1159
|
+
event,
|
|
1160
|
+
reason,
|
|
1161
|
+
nested
|
|
1162
|
+
});
|
|
1163
|
+
onOpenChangeProp == null || onOpenChangeProp(open2, event, reason);
|
|
1164
|
+
});
|
|
1165
|
+
const refs = React.useMemo(() => ({
|
|
1166
|
+
setPositionReference
|
|
1167
|
+
}), []);
|
|
1168
|
+
const elements = React.useMemo(() => ({
|
|
1169
|
+
reference: positionReference || elementsProp.reference || null,
|
|
1170
|
+
floating: elementsProp.floating || null,
|
|
1171
|
+
domReference: elementsProp.reference
|
|
1172
|
+
}), [positionReference, elementsProp.reference, elementsProp.floating]);
|
|
1173
|
+
return React.useMemo(() => ({
|
|
1174
|
+
dataRef,
|
|
1175
|
+
open,
|
|
1176
|
+
onOpenChange,
|
|
1177
|
+
elements,
|
|
1178
|
+
events,
|
|
1179
|
+
floatingId,
|
|
1180
|
+
refs
|
|
1181
|
+
}), [open, onOpenChange, elements, events, floatingId, refs]);
|
|
1182
|
+
}
|
|
1183
|
+
function useFloating(options) {
|
|
1184
|
+
if (options === void 0) {
|
|
1185
|
+
options = {};
|
|
1186
|
+
}
|
|
1187
|
+
const {
|
|
1188
|
+
nodeId
|
|
1189
|
+
} = options;
|
|
1190
|
+
const internalRootContext = useFloatingRootContext({
|
|
1191
|
+
...options,
|
|
1192
|
+
elements: {
|
|
1193
|
+
reference: null,
|
|
1194
|
+
floating: null,
|
|
1195
|
+
...options.elements
|
|
1196
|
+
}
|
|
1197
|
+
});
|
|
1198
|
+
const rootContext = options.rootContext || internalRootContext;
|
|
1199
|
+
const computedElements = rootContext.elements;
|
|
1200
|
+
const [_domReference, setDomReference] = React.useState(null);
|
|
1201
|
+
const [positionReference, _setPositionReference] = React.useState(null);
|
|
1202
|
+
const optionDomReference = computedElements == null ? void 0 : computedElements.reference;
|
|
1203
|
+
const domReference = optionDomReference || _domReference;
|
|
1204
|
+
const domReferenceRef = React.useRef(null);
|
|
1205
|
+
const tree = useFloatingTree();
|
|
1206
|
+
index(() => {
|
|
1207
|
+
if (domReference) {
|
|
1208
|
+
domReferenceRef.current = domReference;
|
|
1209
|
+
}
|
|
1210
|
+
}, [domReference]);
|
|
1211
|
+
const position = useFloating$1({
|
|
1212
|
+
...options,
|
|
1213
|
+
elements: {
|
|
1214
|
+
...computedElements,
|
|
1215
|
+
...positionReference && {
|
|
1216
|
+
reference: positionReference
|
|
806
1217
|
}
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
1218
|
+
}
|
|
1219
|
+
});
|
|
1220
|
+
const setPositionReference = React.useCallback((node) => {
|
|
1221
|
+
const computedPositionReference = isElement(node) ? {
|
|
1222
|
+
getBoundingClientRect: () => node.getBoundingClientRect(),
|
|
1223
|
+
contextElement: node
|
|
1224
|
+
} : node;
|
|
1225
|
+
_setPositionReference(computedPositionReference);
|
|
1226
|
+
position.refs.setReference(computedPositionReference);
|
|
1227
|
+
}, [position.refs]);
|
|
1228
|
+
const setReference = React.useCallback((node) => {
|
|
1229
|
+
if (isElement(node) || node === null) {
|
|
1230
|
+
domReferenceRef.current = node;
|
|
1231
|
+
setDomReference(node);
|
|
1232
|
+
}
|
|
1233
|
+
if (isElement(position.refs.reference.current) || position.refs.reference.current === null || // Don't allow setting virtual elements using the old technique back to
|
|
1234
|
+
// `null` to support `positionReference` + an unstable `reference`
|
|
1235
|
+
// callback ref.
|
|
1236
|
+
node !== null && !isElement(node)) {
|
|
1237
|
+
position.refs.setReference(node);
|
|
1238
|
+
}
|
|
1239
|
+
}, [position.refs]);
|
|
1240
|
+
const refs = React.useMemo(() => ({
|
|
1241
|
+
...position.refs,
|
|
1242
|
+
setReference,
|
|
1243
|
+
setPositionReference,
|
|
1244
|
+
domReference: domReferenceRef
|
|
1245
|
+
}), [position.refs, setReference, setPositionReference]);
|
|
1246
|
+
const elements = React.useMemo(() => ({
|
|
1247
|
+
...position.elements,
|
|
1248
|
+
domReference
|
|
1249
|
+
}), [position.elements, domReference]);
|
|
1250
|
+
const context = React.useMemo(() => ({
|
|
1251
|
+
...position,
|
|
1252
|
+
...rootContext,
|
|
1253
|
+
refs,
|
|
1254
|
+
elements,
|
|
1255
|
+
nodeId
|
|
1256
|
+
}), [position, refs, elements, nodeId, rootContext]);
|
|
1257
|
+
index(() => {
|
|
1258
|
+
rootContext.dataRef.current.floatingContext = context;
|
|
1259
|
+
const node = tree == null ? void 0 : tree.nodesRef.current.find((node2) => node2.id === nodeId);
|
|
1260
|
+
if (node) {
|
|
1261
|
+
node.context = context;
|
|
1262
|
+
}
|
|
1263
|
+
});
|
|
1264
|
+
return React.useMemo(() => ({
|
|
1265
|
+
...position,
|
|
1266
|
+
context,
|
|
1267
|
+
refs,
|
|
1268
|
+
elements
|
|
1269
|
+
}), [position, refs, elements, context]);
|
|
1270
|
+
}
|
|
1271
|
+
const ACTIVE_KEY = "active";
|
|
1272
|
+
const SELECTED_KEY = "selected";
|
|
1273
|
+
function mergeProps(userProps, propsList, elementKey) {
|
|
1274
|
+
const map = /* @__PURE__ */ new Map();
|
|
1275
|
+
const isItem = elementKey === "item";
|
|
1276
|
+
let domUserProps = userProps;
|
|
1277
|
+
if (isItem && userProps) {
|
|
1278
|
+
const {
|
|
1279
|
+
[ACTIVE_KEY]: _,
|
|
1280
|
+
[SELECTED_KEY]: __,
|
|
1281
|
+
...validProps
|
|
1282
|
+
} = userProps;
|
|
1283
|
+
domUserProps = validProps;
|
|
1284
|
+
}
|
|
1285
|
+
return {
|
|
1286
|
+
...elementKey === "floating" && {
|
|
1287
|
+
tabIndex: -1,
|
|
1288
|
+
[FOCUSABLE_ATTRIBUTE]: ""
|
|
1289
|
+
},
|
|
1290
|
+
...domUserProps,
|
|
1291
|
+
...propsList.map((value) => {
|
|
1292
|
+
const propsOrGetProps = value ? value[elementKey] : null;
|
|
1293
|
+
if (typeof propsOrGetProps === "function") {
|
|
1294
|
+
return userProps ? propsOrGetProps(userProps) : null;
|
|
1295
|
+
}
|
|
1296
|
+
return propsOrGetProps;
|
|
1297
|
+
}).concat(userProps).reduce((acc, props) => {
|
|
1298
|
+
if (!props) {
|
|
1299
|
+
return acc;
|
|
1300
|
+
}
|
|
1301
|
+
Object.entries(props).forEach((_ref) => {
|
|
1302
|
+
let [key, value] = _ref;
|
|
1303
|
+
if (isItem && [ACTIVE_KEY, SELECTED_KEY].includes(key)) {
|
|
1304
|
+
return;
|
|
1305
|
+
}
|
|
1306
|
+
if (key.indexOf("on") === 0) {
|
|
1307
|
+
if (!map.has(key)) {
|
|
1308
|
+
map.set(key, []);
|
|
837
1309
|
}
|
|
838
|
-
if (
|
|
839
|
-
var
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
}
|
|
846
|
-
if (Object.freeze) {
|
|
847
|
-
Object.freeze(children);
|
|
848
|
-
}
|
|
849
|
-
} else {
|
|
850
|
-
error("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");
|
|
851
|
-
}
|
|
852
|
-
} else {
|
|
853
|
-
validateChildKeys(children, type);
|
|
1310
|
+
if (typeof value === "function") {
|
|
1311
|
+
var _map$get;
|
|
1312
|
+
(_map$get = map.get(key)) == null || _map$get.push(value);
|
|
1313
|
+
acc[key] = function() {
|
|
1314
|
+
var _map$get2;
|
|
1315
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
1316
|
+
args[_key] = arguments[_key];
|
|
854
1317
|
}
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
if (type === REACT_FRAGMENT_TYPE) {
|
|
858
|
-
validateFragmentProps(element);
|
|
859
|
-
} else {
|
|
860
|
-
validatePropTypes(element);
|
|
1318
|
+
return (_map$get2 = map.get(key)) == null ? void 0 : _map$get2.map((fn) => fn(...args)).find((val) => val !== void 0);
|
|
1319
|
+
};
|
|
861
1320
|
}
|
|
862
|
-
|
|
1321
|
+
} else {
|
|
1322
|
+
acc[key] = value;
|
|
863
1323
|
}
|
|
1324
|
+
});
|
|
1325
|
+
return acc;
|
|
1326
|
+
}, {})
|
|
1327
|
+
};
|
|
1328
|
+
}
|
|
1329
|
+
function useInteractions(propsList) {
|
|
1330
|
+
if (propsList === void 0) {
|
|
1331
|
+
propsList = [];
|
|
1332
|
+
}
|
|
1333
|
+
const referenceDeps = propsList.map((key) => key == null ? void 0 : key.reference);
|
|
1334
|
+
const floatingDeps = propsList.map((key) => key == null ? void 0 : key.floating);
|
|
1335
|
+
const itemDeps = propsList.map((key) => key == null ? void 0 : key.item);
|
|
1336
|
+
const getReferenceProps = React.useCallback(
|
|
1337
|
+
(userProps) => mergeProps(userProps, propsList, "reference"),
|
|
1338
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
1339
|
+
referenceDeps
|
|
1340
|
+
);
|
|
1341
|
+
const getFloatingProps = React.useCallback(
|
|
1342
|
+
(userProps) => mergeProps(userProps, propsList, "floating"),
|
|
1343
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
1344
|
+
floatingDeps
|
|
1345
|
+
);
|
|
1346
|
+
const getItemProps = React.useCallback(
|
|
1347
|
+
(userProps) => mergeProps(userProps, propsList, "item"),
|
|
1348
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
1349
|
+
itemDeps
|
|
1350
|
+
);
|
|
1351
|
+
return React.useMemo(() => ({
|
|
1352
|
+
getReferenceProps,
|
|
1353
|
+
getFloatingProps,
|
|
1354
|
+
getItemProps
|
|
1355
|
+
}), [getReferenceProps, getFloatingProps, getItemProps]);
|
|
1356
|
+
}
|
|
1357
|
+
const componentRoleToAriaRoleMap = /* @__PURE__ */ new Map([["select", "listbox"], ["combobox", "listbox"], ["label", false]]);
|
|
1358
|
+
function useRole(context, props) {
|
|
1359
|
+
var _componentRoleToAriaR;
|
|
1360
|
+
if (props === void 0) {
|
|
1361
|
+
props = {};
|
|
1362
|
+
}
|
|
1363
|
+
const {
|
|
1364
|
+
open,
|
|
1365
|
+
floatingId
|
|
1366
|
+
} = context;
|
|
1367
|
+
const {
|
|
1368
|
+
enabled = true,
|
|
1369
|
+
role = "dialog"
|
|
1370
|
+
} = props;
|
|
1371
|
+
const ariaRole = (_componentRoleToAriaR = componentRoleToAriaRoleMap.get(role)) != null ? _componentRoleToAriaR : role;
|
|
1372
|
+
const referenceId = useId();
|
|
1373
|
+
const parentId = useFloatingParentNodeId();
|
|
1374
|
+
const isNested = parentId != null;
|
|
1375
|
+
const reference = React.useMemo(() => {
|
|
1376
|
+
if (ariaRole === "tooltip" || role === "label") {
|
|
1377
|
+
return {
|
|
1378
|
+
["aria-" + (role === "label" ? "labelledby" : "describedby")]: open ? floatingId : void 0
|
|
1379
|
+
};
|
|
1380
|
+
}
|
|
1381
|
+
return {
|
|
1382
|
+
"aria-expanded": open ? "true" : "false",
|
|
1383
|
+
"aria-haspopup": ariaRole === "alertdialog" ? "dialog" : ariaRole,
|
|
1384
|
+
"aria-controls": open ? floatingId : void 0,
|
|
1385
|
+
...ariaRole === "listbox" && {
|
|
1386
|
+
role: "combobox"
|
|
1387
|
+
},
|
|
1388
|
+
...ariaRole === "menu" && {
|
|
1389
|
+
id: referenceId
|
|
1390
|
+
},
|
|
1391
|
+
...ariaRole === "menu" && isNested && {
|
|
1392
|
+
role: "menuitem"
|
|
1393
|
+
},
|
|
1394
|
+
...role === "select" && {
|
|
1395
|
+
"aria-autocomplete": "none"
|
|
1396
|
+
},
|
|
1397
|
+
...role === "combobox" && {
|
|
1398
|
+
"aria-autocomplete": "list"
|
|
864
1399
|
}
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
1400
|
+
};
|
|
1401
|
+
}, [ariaRole, floatingId, isNested, open, referenceId, role]);
|
|
1402
|
+
const floating = React.useMemo(() => {
|
|
1403
|
+
const floatingProps = {
|
|
1404
|
+
id: floatingId,
|
|
1405
|
+
...ariaRole && {
|
|
1406
|
+
role: ariaRole
|
|
869
1407
|
}
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
1408
|
+
};
|
|
1409
|
+
if (ariaRole === "tooltip" || role === "label") {
|
|
1410
|
+
return floatingProps;
|
|
1411
|
+
}
|
|
1412
|
+
return {
|
|
1413
|
+
...floatingProps,
|
|
1414
|
+
...ariaRole === "menu" && {
|
|
1415
|
+
"aria-labelledby": referenceId
|
|
874
1416
|
}
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
1417
|
+
};
|
|
1418
|
+
}, [ariaRole, floatingId, referenceId, role]);
|
|
1419
|
+
const item = React.useCallback((_ref) => {
|
|
1420
|
+
let {
|
|
1421
|
+
active,
|
|
1422
|
+
selected
|
|
1423
|
+
} = _ref;
|
|
1424
|
+
const commonProps = {
|
|
1425
|
+
role: "option",
|
|
1426
|
+
...active && {
|
|
1427
|
+
id: floatingId + "-option"
|
|
1428
|
+
}
|
|
1429
|
+
};
|
|
1430
|
+
switch (role) {
|
|
1431
|
+
case "select":
|
|
1432
|
+
return {
|
|
1433
|
+
...commonProps,
|
|
1434
|
+
"aria-selected": active && selected
|
|
1435
|
+
};
|
|
1436
|
+
case "combobox": {
|
|
1437
|
+
return {
|
|
1438
|
+
...commonProps,
|
|
1439
|
+
...active && {
|
|
1440
|
+
"aria-selected": true
|
|
1441
|
+
}
|
|
1442
|
+
};
|
|
1443
|
+
}
|
|
1444
|
+
}
|
|
1445
|
+
return {};
|
|
1446
|
+
}, [floatingId, role]);
|
|
1447
|
+
return React.useMemo(() => enabled ? {
|
|
1448
|
+
reference,
|
|
1449
|
+
floating,
|
|
1450
|
+
item
|
|
1451
|
+
} : {}, [enabled, reference, floating, item]);
|
|
883
1452
|
}
|
|
884
1453
|
export {
|
|
885
|
-
|
|
1454
|
+
FloatingFocusManager,
|
|
1455
|
+
FloatingPortal,
|
|
1456
|
+
flip,
|
|
1457
|
+
getOverflowAncestors,
|
|
1458
|
+
inline,
|
|
1459
|
+
offset,
|
|
1460
|
+
shift,
|
|
1461
|
+
useDismiss,
|
|
1462
|
+
useFloating,
|
|
1463
|
+
useFloatingParentNodeId,
|
|
1464
|
+
useFloatingPortalNode,
|
|
1465
|
+
useFloatingRootContext,
|
|
1466
|
+
useFloatingTree,
|
|
1467
|
+
useId,
|
|
1468
|
+
useInteractions,
|
|
1469
|
+
useRole
|
|
886
1470
|
};
|
|
887
1471
|
//# sourceMappingURL=react-text-annotator.es11.js.map
|