@soomo/react-text-annotator 3.1.0-staging.10 → 3.1.0-staging.11
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/TextAnnotatorPopup/TextAnnotatorPopup.d.ts.map +1 -1
- package/dist/react-text-annotator.es10.js +9 -487
- package/dist/react-text-annotator.es10.js.map +1 -1
- package/dist/react-text-annotator.es11.js +1444 -78
- package/dist/react-text-annotator.es11.js.map +1 -1
- package/dist/react-text-annotator.es13.js +244 -7
- package/dist/react-text-annotator.es13.js.map +1 -1
- package/dist/react-text-annotator.es14.js +505 -1368
- package/dist/react-text-annotator.es14.js.map +1 -1
- package/dist/react-text-annotator.es15.js +85 -0
- package/dist/react-text-annotator.es15.js.map +1 -0
- package/dist/react-text-annotator.es16.js +36 -237
- package/dist/react-text-annotator.es16.js.map +1 -1
- package/dist/react-text-annotator.es17.js +445 -543
- package/dist/react-text-annotator.es17.js.map +1 -1
- package/dist/react-text-annotator.es2.js +1 -1
- package/dist/react-text-annotator.es4.js +2 -2
- package/dist/react-text-annotator.es6.js +8 -8
- package/dist/react-text-annotator.es6.js.map +1 -1
- package/package.json +2 -2
- package/dist/react-text-annotator.es12.js +0 -48
- package/dist/react-text-annotator.es12.js.map +0 -1
|
@@ -1,1451 +1,588 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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 = {};
|
|
1
|
+
import { offset as offset$1, shift as shift$1, flip as flip$1, inline as inline$1, computePosition as computePosition$1 } from "./react-text-annotator.es31.js";
|
|
2
|
+
import { createCoords, rectToClientRect, round, floor, max, min } from "./react-text-annotator.es30.js";
|
|
3
|
+
import { getOverflowAncestors, isElement, getWindow, getFrameElement, getComputedStyle, getDocumentElement, isHTMLElement, isWebKit, isTopLayer, getNodeName, isOverflowElement, getNodeScroll, getParentNode, isLastTraversableNode, isTableElement, isContainingBlock, getContainingBlock } from "./react-text-annotator.es28.js";
|
|
4
|
+
function getCssDimensions(element) {
|
|
5
|
+
const css = getComputedStyle(element);
|
|
6
|
+
let width = parseFloat(css.width) || 0;
|
|
7
|
+
let height = parseFloat(css.height) || 0;
|
|
8
|
+
const hasOffset = isHTMLElement(element);
|
|
9
|
+
const offsetWidth = hasOffset ? element.offsetWidth : width;
|
|
10
|
+
const offsetHeight = hasOffset ? element.offsetHeight : height;
|
|
11
|
+
const shouldFallback = round(width) !== offsetWidth || round(height) !== offsetHeight;
|
|
12
|
+
if (shouldFallback) {
|
|
13
|
+
width = offsetWidth;
|
|
14
|
+
height = offsetHeight;
|
|
34
15
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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];
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
return target;
|
|
16
|
+
return {
|
|
17
|
+
width,
|
|
18
|
+
height,
|
|
19
|
+
$: shouldFallback
|
|
62
20
|
};
|
|
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
21
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
let devMessageSet;
|
|
87
|
-
if (process.env.NODE_ENV !== "production") {
|
|
88
|
-
devMessageSet = /* @__PURE__ */ new Set();
|
|
22
|
+
function unwrapElement(element) {
|
|
23
|
+
return !isElement(element) ? element.contextElement : element;
|
|
89
24
|
}
|
|
90
|
-
function
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
25
|
+
function getScale(element) {
|
|
26
|
+
const domElement = unwrapElement(element);
|
|
27
|
+
if (!isHTMLElement(domElement)) {
|
|
28
|
+
return createCoords(1);
|
|
94
29
|
}
|
|
95
|
-
const
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
30
|
+
const rect = domElement.getBoundingClientRect();
|
|
31
|
+
const {
|
|
32
|
+
width,
|
|
33
|
+
height,
|
|
34
|
+
$
|
|
35
|
+
} = getCssDimensions(domElement);
|
|
36
|
+
let x = ($ ? round(rect.width) : rect.width) / width;
|
|
37
|
+
let y = ($ ? round(rect.height) : rect.height) / height;
|
|
38
|
+
if (!x || !Number.isFinite(x)) {
|
|
39
|
+
x = 1;
|
|
40
|
+
}
|
|
41
|
+
if (!y || !Number.isFinite(y)) {
|
|
42
|
+
y = 1;
|
|
100
43
|
}
|
|
101
|
-
}
|
|
102
|
-
function createPubSub() {
|
|
103
|
-
const map = /* @__PURE__ */ new Map();
|
|
104
44
|
return {
|
|
105
|
-
|
|
106
|
-
|
|
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
|
-
}
|
|
45
|
+
x,
|
|
46
|
+
y
|
|
116
47
|
};
|
|
117
48
|
}
|
|
118
|
-
const
|
|
119
|
-
|
|
120
|
-
const
|
|
121
|
-
|
|
122
|
-
|
|
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
|
-
}
|
|
49
|
+
const noOffsets = /* @__PURE__ */ createCoords(0);
|
|
50
|
+
function getVisualOffsets(element) {
|
|
51
|
+
const win = getWindow(element);
|
|
52
|
+
if (!isWebKit() || !win.visualViewport) {
|
|
53
|
+
return noOffsets;
|
|
145
54
|
}
|
|
146
|
-
return
|
|
55
|
+
return {
|
|
56
|
+
x: win.visualViewport.offsetLeft,
|
|
57
|
+
y: win.visualViewport.offsetTop
|
|
58
|
+
};
|
|
147
59
|
}
|
|
148
|
-
function
|
|
149
|
-
|
|
150
|
-
|
|
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);
|
|
60
|
+
function shouldAddVisualOffsets(element, isFixed, floatingOffsetParent) {
|
|
61
|
+
if (isFixed === void 0) {
|
|
62
|
+
isFixed = false;
|
|
163
63
|
}
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
let counterMap = /* @__PURE__ */ new WeakMap();
|
|
167
|
-
let uncontrolledElementsSet = /* @__PURE__ */ new WeakSet();
|
|
168
|
-
let markerMap = {};
|
|
169
|
-
let lockCount$1 = 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;
|
|
64
|
+
if (!floatingOffsetParent || isFixed && floatingOffsetParent !== getWindow(element)) {
|
|
65
|
+
return false;
|
|
175
66
|
}
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
67
|
+
return isFixed;
|
|
68
|
+
}
|
|
69
|
+
function getBoundingClientRect(element, includeScale, isFixedStrategy, offsetParent) {
|
|
70
|
+
if (includeScale === void 0) {
|
|
71
|
+
includeScale = false;
|
|
179
72
|
}
|
|
180
|
-
|
|
181
|
-
|
|
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();
|
|
73
|
+
if (isFixedStrategy === void 0) {
|
|
74
|
+
isFixedStrategy = false;
|
|
191
75
|
}
|
|
192
|
-
const
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
76
|
+
const clientRect = element.getBoundingClientRect();
|
|
77
|
+
const domElement = unwrapElement(element);
|
|
78
|
+
let scale = createCoords(1);
|
|
79
|
+
if (includeScale) {
|
|
80
|
+
if (offsetParent) {
|
|
81
|
+
if (isElement(offsetParent)) {
|
|
82
|
+
scale = getScale(offsetParent);
|
|
83
|
+
}
|
|
84
|
+
} else {
|
|
85
|
+
scale = getScale(element);
|
|
199
86
|
}
|
|
200
|
-
elementsToKeep.add(el);
|
|
201
|
-
el.parentNode && keep(el.parentNode);
|
|
202
87
|
}
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
88
|
+
const visualOffsets = shouldAddVisualOffsets(domElement, isFixedStrategy, offsetParent) ? getVisualOffsets(domElement) : createCoords(0);
|
|
89
|
+
let x = (clientRect.left + visualOffsets.x) / scale.x;
|
|
90
|
+
let y = (clientRect.top + visualOffsets.y) / scale.y;
|
|
91
|
+
let width = clientRect.width / scale.x;
|
|
92
|
+
let height = clientRect.height / scale.y;
|
|
93
|
+
if (domElement) {
|
|
94
|
+
const win = getWindow(domElement);
|
|
95
|
+
const offsetWin = offsetParent && isElement(offsetParent) ? getWindow(offsetParent) : offsetParent;
|
|
96
|
+
let currentWin = win;
|
|
97
|
+
let currentIFrame = getFrameElement(currentWin);
|
|
98
|
+
while (currentIFrame && offsetParent && offsetWin !== currentWin) {
|
|
99
|
+
const iframeScale = getScale(currentIFrame);
|
|
100
|
+
const iframeRect = currentIFrame.getBoundingClientRect();
|
|
101
|
+
const css = getComputedStyle(currentIFrame);
|
|
102
|
+
const left = iframeRect.left + (currentIFrame.clientLeft + parseFloat(css.paddingLeft)) * iframeScale.x;
|
|
103
|
+
const top = iframeRect.top + (currentIFrame.clientTop + parseFloat(css.paddingTop)) * iframeScale.y;
|
|
104
|
+
x *= iframeScale.x;
|
|
105
|
+
y *= iframeScale.y;
|
|
106
|
+
width *= iframeScale.x;
|
|
107
|
+
height *= iframeScale.y;
|
|
108
|
+
x += left;
|
|
109
|
+
y += top;
|
|
110
|
+
currentWin = getWindow(currentIFrame);
|
|
111
|
+
currentIFrame = getFrameElement(currentWin);
|
|
206
112
|
}
|
|
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);
|
|
221
|
-
}
|
|
222
|
-
if (markerValue === 1) {
|
|
223
|
-
node.setAttribute(markerName, "");
|
|
224
|
-
}
|
|
225
|
-
if (!alreadyHidden && controlAttribute) {
|
|
226
|
-
node.setAttribute(controlAttribute, "true");
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
});
|
|
230
113
|
}
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
114
|
+
return rectToClientRect({
|
|
115
|
+
width,
|
|
116
|
+
height,
|
|
117
|
+
x,
|
|
118
|
+
y
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
function convertOffsetParentRelativeRectToViewportRelativeRect(_ref) {
|
|
122
|
+
let {
|
|
123
|
+
elements,
|
|
124
|
+
rect,
|
|
125
|
+
offsetParent,
|
|
126
|
+
strategy
|
|
127
|
+
} = _ref;
|
|
128
|
+
const isFixed = strategy === "fixed";
|
|
129
|
+
const documentElement = getDocumentElement(offsetParent);
|
|
130
|
+
const topLayer = elements ? isTopLayer(elements.floating) : false;
|
|
131
|
+
if (offsetParent === documentElement || topLayer && isFixed) {
|
|
132
|
+
return rect;
|
|
133
|
+
}
|
|
134
|
+
let scroll = {
|
|
135
|
+
scrollLeft: 0,
|
|
136
|
+
scrollTop: 0
|
|
137
|
+
};
|
|
138
|
+
let scale = createCoords(1);
|
|
139
|
+
const offsets = createCoords(0);
|
|
140
|
+
const isOffsetParentAnElement = isHTMLElement(offsetParent);
|
|
141
|
+
if (isOffsetParentAnElement || !isOffsetParentAnElement && !isFixed) {
|
|
142
|
+
if (getNodeName(offsetParent) !== "body" || isOverflowElement(documentElement)) {
|
|
143
|
+
scroll = getNodeScroll(offsetParent);
|
|
144
|
+
}
|
|
145
|
+
if (isHTMLElement(offsetParent)) {
|
|
146
|
+
const offsetRect = getBoundingClientRect(offsetParent);
|
|
147
|
+
scale = getScale(offsetParent);
|
|
148
|
+
offsets.x = offsetRect.x + offsetParent.clientLeft;
|
|
149
|
+
offsets.y = offsetRect.y + offsetParent.clientTop;
|
|
254
150
|
}
|
|
151
|
+
}
|
|
152
|
+
return {
|
|
153
|
+
width: rect.width * scale.x,
|
|
154
|
+
height: rect.height * scale.y,
|
|
155
|
+
x: rect.x * scale.x - scroll.scrollLeft * scale.x + offsets.x,
|
|
156
|
+
y: rect.y * scale.y - scroll.scrollTop * scale.y + offsets.y
|
|
255
157
|
};
|
|
256
158
|
}
|
|
257
|
-
function
|
|
258
|
-
|
|
259
|
-
|
|
159
|
+
function getClientRects(element) {
|
|
160
|
+
return Array.from(element.getClientRects());
|
|
161
|
+
}
|
|
162
|
+
function getWindowScrollBarX(element, rect) {
|
|
163
|
+
const leftScroll = getNodeScroll(element).scrollLeft;
|
|
164
|
+
if (!rect) {
|
|
165
|
+
return getBoundingClientRect(getDocumentElement(element)).left + leftScroll;
|
|
260
166
|
}
|
|
261
|
-
|
|
262
|
-
|
|
167
|
+
return rect.left + leftScroll;
|
|
168
|
+
}
|
|
169
|
+
function getDocumentRect(element) {
|
|
170
|
+
const html = getDocumentElement(element);
|
|
171
|
+
const scroll = getNodeScroll(element);
|
|
172
|
+
const body = element.ownerDocument.body;
|
|
173
|
+
const width = max(html.scrollWidth, html.clientWidth, body.scrollWidth, body.clientWidth);
|
|
174
|
+
const height = max(html.scrollHeight, html.clientHeight, body.scrollHeight, body.clientHeight);
|
|
175
|
+
let x = -scroll.scrollLeft + getWindowScrollBarX(element);
|
|
176
|
+
const y = -scroll.scrollTop;
|
|
177
|
+
if (getComputedStyle(body).direction === "rtl") {
|
|
178
|
+
x += max(html.clientWidth, body.clientWidth) - width;
|
|
263
179
|
}
|
|
264
|
-
|
|
265
|
-
|
|
180
|
+
return {
|
|
181
|
+
width,
|
|
182
|
+
height,
|
|
183
|
+
x,
|
|
184
|
+
y
|
|
185
|
+
};
|
|
266
186
|
}
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
187
|
+
function getViewportRect(element, strategy) {
|
|
188
|
+
const win = getWindow(element);
|
|
189
|
+
const html = getDocumentElement(element);
|
|
190
|
+
const visualViewport = win.visualViewport;
|
|
191
|
+
let width = html.clientWidth;
|
|
192
|
+
let height = html.clientHeight;
|
|
193
|
+
let x = 0;
|
|
194
|
+
let y = 0;
|
|
195
|
+
if (visualViewport) {
|
|
196
|
+
width = visualViewport.width;
|
|
197
|
+
height = visualViewport.height;
|
|
198
|
+
const visualViewportBased = isWebKit();
|
|
199
|
+
if (!visualViewportBased || visualViewportBased && strategy === "fixed") {
|
|
200
|
+
x = visualViewport.offsetLeft;
|
|
201
|
+
y = visualViewport.offsetTop;
|
|
202
|
+
}
|
|
280
203
|
}
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
204
|
+
return {
|
|
205
|
+
width,
|
|
206
|
+
height,
|
|
207
|
+
x,
|
|
208
|
+
y
|
|
209
|
+
};
|
|
287
210
|
}
|
|
288
|
-
function
|
|
289
|
-
|
|
211
|
+
function getInnerBoundingClientRect(element, strategy) {
|
|
212
|
+
const clientRect = getBoundingClientRect(element, true, strategy === "fixed");
|
|
213
|
+
const top = clientRect.top + element.clientTop;
|
|
214
|
+
const left = clientRect.left + element.clientLeft;
|
|
215
|
+
const scale = isHTMLElement(element) ? getScale(element) : createCoords(1);
|
|
216
|
+
const width = element.clientWidth * scale.x;
|
|
217
|
+
const height = element.clientHeight * scale.y;
|
|
218
|
+
const x = left * scale.x;
|
|
219
|
+
const y = top * scale.y;
|
|
220
|
+
return {
|
|
221
|
+
width,
|
|
222
|
+
height,
|
|
223
|
+
x,
|
|
224
|
+
y
|
|
225
|
+
};
|
|
290
226
|
}
|
|
291
|
-
function
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
227
|
+
function getClientRectFromClippingAncestor(element, clippingAncestor, strategy) {
|
|
228
|
+
let rect;
|
|
229
|
+
if (clippingAncestor === "viewport") {
|
|
230
|
+
rect = getViewportRect(element, strategy);
|
|
231
|
+
} else if (clippingAncestor === "document") {
|
|
232
|
+
rect = getDocumentRect(getDocumentElement(element));
|
|
233
|
+
} else if (isElement(clippingAncestor)) {
|
|
234
|
+
rect = getInnerBoundingClientRect(clippingAncestor, strategy);
|
|
235
|
+
} else {
|
|
236
|
+
const visualOffsets = getVisualOffsets(element);
|
|
237
|
+
rect = {
|
|
238
|
+
...clippingAncestor,
|
|
239
|
+
x: clippingAncestor.x - visualOffsets.x,
|
|
240
|
+
y: clippingAncestor.y - visualOffsets.y
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
return rectToClientRect(rect);
|
|
295
244
|
}
|
|
296
|
-
function
|
|
297
|
-
const
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
245
|
+
function hasFixedPositionAncestor(element, stopNode) {
|
|
246
|
+
const parentNode = getParentNode(element);
|
|
247
|
+
if (parentNode === stopNode || !isElement(parentNode) || isLastTraversableNode(parentNode)) {
|
|
248
|
+
return false;
|
|
249
|
+
}
|
|
250
|
+
return getComputedStyle(parentNode).position === "fixed" || hasFixedPositionAncestor(parentNode, stopNode);
|
|
302
251
|
}
|
|
303
|
-
function
|
|
304
|
-
const
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
252
|
+
function getClippingElementAncestors(element, cache) {
|
|
253
|
+
const cachedResult = cache.get(element);
|
|
254
|
+
if (cachedResult) {
|
|
255
|
+
return cachedResult;
|
|
256
|
+
}
|
|
257
|
+
let result = getOverflowAncestors(element, [], false).filter((el) => isElement(el) && getNodeName(el) !== "body");
|
|
258
|
+
let currentContainingBlockComputedStyle = null;
|
|
259
|
+
const elementIsFixed = getComputedStyle(element).position === "fixed";
|
|
260
|
+
let currentNode = elementIsFixed ? getParentNode(element) : element;
|
|
261
|
+
while (isElement(currentNode) && !isLastTraversableNode(currentNode)) {
|
|
262
|
+
const computedStyle = getComputedStyle(currentNode);
|
|
263
|
+
const currentNodeIsContaining = isContainingBlock(currentNode);
|
|
264
|
+
if (!currentNodeIsContaining && computedStyle.position === "fixed") {
|
|
265
|
+
currentContainingBlockComputedStyle = null;
|
|
266
|
+
}
|
|
267
|
+
const shouldDropCurrentNode = elementIsFixed ? !currentNodeIsContaining && !currentContainingBlockComputedStyle : !currentNodeIsContaining && computedStyle.position === "static" && !!currentContainingBlockComputedStyle && ["absolute", "fixed"].includes(currentContainingBlockComputedStyle.position) || isOverflowElement(currentNode) && !currentNodeIsContaining && hasFixedPositionAncestor(element, currentNode);
|
|
268
|
+
if (shouldDropCurrentNode) {
|
|
269
|
+
result = result.filter((ancestor) => ancestor !== currentNode);
|
|
310
270
|
} else {
|
|
311
|
-
|
|
271
|
+
currentContainingBlockComputedStyle = computedStyle;
|
|
312
272
|
}
|
|
313
|
-
|
|
314
|
-
}
|
|
315
|
-
const HIDDEN_STYLES = {
|
|
316
|
-
border: 0,
|
|
317
|
-
clip: "rect(0 0 0 0)",
|
|
318
|
-
height: "1px",
|
|
319
|
-
margin: "-1px",
|
|
320
|
-
overflow: "hidden",
|
|
321
|
-
padding: 0,
|
|
322
|
-
position: "fixed",
|
|
323
|
-
whiteSpace: "nowrap",
|
|
324
|
-
width: "1px",
|
|
325
|
-
top: 0,
|
|
326
|
-
left: 0
|
|
327
|
-
};
|
|
328
|
-
let timeoutId;
|
|
329
|
-
function setActiveElementOnTab(event) {
|
|
330
|
-
if (event.key === "Tab") {
|
|
331
|
-
event.target;
|
|
332
|
-
clearTimeout(timeoutId);
|
|
273
|
+
currentNode = getParentNode(currentNode);
|
|
333
274
|
}
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
const
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
275
|
+
cache.set(element, result);
|
|
276
|
+
return result;
|
|
277
|
+
}
|
|
278
|
+
function getClippingRect(_ref) {
|
|
279
|
+
let {
|
|
280
|
+
element,
|
|
281
|
+
boundary,
|
|
282
|
+
rootBoundary,
|
|
283
|
+
strategy
|
|
284
|
+
} = _ref;
|
|
285
|
+
const elementClippingAncestors = boundary === "clippingAncestors" ? isTopLayer(element) ? [] : getClippingElementAncestors(element, this._c) : [].concat(boundary);
|
|
286
|
+
const clippingAncestors = [...elementClippingAncestors, rootBoundary];
|
|
287
|
+
const firstClippingAncestor = clippingAncestors[0];
|
|
288
|
+
const clippingRect = clippingAncestors.reduce((accRect, clippingAncestor) => {
|
|
289
|
+
const rect = getClientRectFromClippingAncestor(element, clippingAncestor, strategy);
|
|
290
|
+
accRect.top = max(rect.top, accRect.top);
|
|
291
|
+
accRect.right = min(rect.right, accRect.right);
|
|
292
|
+
accRect.bottom = min(rect.bottom, accRect.bottom);
|
|
293
|
+
accRect.left = max(rect.left, accRect.left);
|
|
294
|
+
return accRect;
|
|
295
|
+
}, getClientRectFromClippingAncestor(element, firstClippingAncestor, strategy));
|
|
296
|
+
return {
|
|
297
|
+
width: clippingRect.right - clippingRect.left,
|
|
298
|
+
height: clippingRect.bottom - clippingRect.top,
|
|
299
|
+
x: clippingRect.left,
|
|
300
|
+
y: clippingRect.top
|
|
354
301
|
};
|
|
355
|
-
return /* @__PURE__ */ React.createElement("span", _extends({}, props, restProps));
|
|
356
|
-
});
|
|
357
|
-
const PortalContext = /* @__PURE__ */ React.createContext(null);
|
|
358
|
-
const attr = /* @__PURE__ */ createAttribute("portal");
|
|
359
|
-
function useFloatingPortalNode(props) {
|
|
360
|
-
if (props === void 0) {
|
|
361
|
-
props = {};
|
|
362
|
-
}
|
|
363
|
-
const {
|
|
364
|
-
id,
|
|
365
|
-
root
|
|
366
|
-
} = props;
|
|
367
|
-
const uniqueId = useId();
|
|
368
|
-
const portalContext = usePortalContext();
|
|
369
|
-
const [portalNode, setPortalNode] = React.useState(null);
|
|
370
|
-
const portalNodeRef = React.useRef(null);
|
|
371
|
-
index(() => {
|
|
372
|
-
return () => {
|
|
373
|
-
portalNode == null || portalNode.remove();
|
|
374
|
-
queueMicrotask(() => {
|
|
375
|
-
portalNodeRef.current = null;
|
|
376
|
-
});
|
|
377
|
-
};
|
|
378
|
-
}, [portalNode]);
|
|
379
|
-
index(() => {
|
|
380
|
-
if (!uniqueId) return;
|
|
381
|
-
if (portalNodeRef.current) return;
|
|
382
|
-
const existingIdRoot = id ? document.getElementById(id) : null;
|
|
383
|
-
if (!existingIdRoot) return;
|
|
384
|
-
const subRoot = document.createElement("div");
|
|
385
|
-
subRoot.id = uniqueId;
|
|
386
|
-
subRoot.setAttribute(attr, "");
|
|
387
|
-
existingIdRoot.appendChild(subRoot);
|
|
388
|
-
portalNodeRef.current = subRoot;
|
|
389
|
-
setPortalNode(subRoot);
|
|
390
|
-
}, [id, uniqueId]);
|
|
391
|
-
index(() => {
|
|
392
|
-
if (!uniqueId) return;
|
|
393
|
-
if (portalNodeRef.current) return;
|
|
394
|
-
let container = root || (portalContext == null ? void 0 : portalContext.portalNode);
|
|
395
|
-
if (container && !isElement(container)) container = container.current;
|
|
396
|
-
container = container || document.body;
|
|
397
|
-
let idWrapper = null;
|
|
398
|
-
if (id) {
|
|
399
|
-
idWrapper = document.createElement("div");
|
|
400
|
-
idWrapper.id = id;
|
|
401
|
-
container.appendChild(idWrapper);
|
|
402
|
-
}
|
|
403
|
-
const subRoot = document.createElement("div");
|
|
404
|
-
subRoot.id = uniqueId;
|
|
405
|
-
subRoot.setAttribute(attr, "");
|
|
406
|
-
container = idWrapper || container;
|
|
407
|
-
container.appendChild(subRoot);
|
|
408
|
-
portalNodeRef.current = subRoot;
|
|
409
|
-
setPortalNode(subRoot);
|
|
410
|
-
}, [id, root, uniqueId, portalContext]);
|
|
411
|
-
return portalNode;
|
|
412
302
|
}
|
|
413
|
-
function
|
|
303
|
+
function getDimensions(element) {
|
|
414
304
|
const {
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
const
|
|
425
|
-
const
|
|
426
|
-
const
|
|
427
|
-
const
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
}
|
|
442
|
-
|
|
443
|
-
if (portalNode && isOutsideEvent(event)) {
|
|
444
|
-
const focusing = event.type === "focusin";
|
|
445
|
-
const manageFocus = focusing ? enableFocusInside : disableFocusInside;
|
|
446
|
-
manageFocus(portalNode);
|
|
447
|
-
}
|
|
448
|
-
}
|
|
449
|
-
portalNode.addEventListener("focusin", onFocus, true);
|
|
450
|
-
portalNode.addEventListener("focusout", onFocus, true);
|
|
451
|
-
return () => {
|
|
452
|
-
portalNode.removeEventListener("focusin", onFocus, true);
|
|
453
|
-
portalNode.removeEventListener("focusout", onFocus, true);
|
|
454
|
-
};
|
|
455
|
-
}, [portalNode, preserveTabOrder, modal]);
|
|
456
|
-
React.useEffect(() => {
|
|
457
|
-
if (!portalNode) return;
|
|
458
|
-
if (open) return;
|
|
459
|
-
enableFocusInside(portalNode);
|
|
460
|
-
}, [open, portalNode]);
|
|
461
|
-
return /* @__PURE__ */ React.createElement(PortalContext.Provider, {
|
|
462
|
-
value: React.useMemo(() => ({
|
|
463
|
-
preserveTabOrder,
|
|
464
|
-
beforeOutsideRef,
|
|
465
|
-
afterOutsideRef,
|
|
466
|
-
beforeInsideRef,
|
|
467
|
-
afterInsideRef,
|
|
468
|
-
portalNode,
|
|
469
|
-
setFocusManagerState
|
|
470
|
-
}), [preserveTabOrder, portalNode])
|
|
471
|
-
}, shouldRenderGuards && portalNode && /* @__PURE__ */ React.createElement(FocusGuard, {
|
|
472
|
-
"data-type": "outside",
|
|
473
|
-
ref: beforeOutsideRef,
|
|
474
|
-
onFocus: (event) => {
|
|
475
|
-
if (isOutsideEvent(event, portalNode)) {
|
|
476
|
-
var _beforeInsideRef$curr;
|
|
477
|
-
(_beforeInsideRef$curr = beforeInsideRef.current) == null || _beforeInsideRef$curr.focus();
|
|
478
|
-
} else {
|
|
479
|
-
const prevTabbable = getPreviousTabbable() || (focusManagerState == null ? void 0 : focusManagerState.refs.domReference.current);
|
|
480
|
-
prevTabbable == null || prevTabbable.focus();
|
|
481
|
-
}
|
|
482
|
-
}
|
|
483
|
-
}), shouldRenderGuards && portalNode && /* @__PURE__ */ React.createElement("span", {
|
|
484
|
-
"aria-owns": portalNode.id,
|
|
485
|
-
style: HIDDEN_STYLES
|
|
486
|
-
}), portalNode && /* @__PURE__ */ ReactDOM.createPortal(children, portalNode), shouldRenderGuards && portalNode && /* @__PURE__ */ React.createElement(FocusGuard, {
|
|
487
|
-
"data-type": "outside",
|
|
488
|
-
ref: afterOutsideRef,
|
|
489
|
-
onFocus: (event) => {
|
|
490
|
-
if (isOutsideEvent(event, portalNode)) {
|
|
491
|
-
var _afterInsideRef$curre;
|
|
492
|
-
(_afterInsideRef$curre = afterInsideRef.current) == null || _afterInsideRef$curre.focus();
|
|
493
|
-
} else {
|
|
494
|
-
const nextTabbable = getNextTabbable() || (focusManagerState == null ? void 0 : focusManagerState.refs.domReference.current);
|
|
495
|
-
nextTabbable == null || nextTabbable.focus();
|
|
496
|
-
(focusManagerState == null ? void 0 : focusManagerState.closeOnFocusOut) && (focusManagerState == null ? void 0 : focusManagerState.onOpenChange(false, event.nativeEvent, "focus-out"));
|
|
497
|
-
}
|
|
305
|
+
width,
|
|
306
|
+
height
|
|
307
|
+
} = getCssDimensions(element);
|
|
308
|
+
return {
|
|
309
|
+
width,
|
|
310
|
+
height
|
|
311
|
+
};
|
|
312
|
+
}
|
|
313
|
+
function getRectRelativeToOffsetParent(element, offsetParent, strategy) {
|
|
314
|
+
const isOffsetParentAnElement = isHTMLElement(offsetParent);
|
|
315
|
+
const documentElement = getDocumentElement(offsetParent);
|
|
316
|
+
const isFixed = strategy === "fixed";
|
|
317
|
+
const rect = getBoundingClientRect(element, true, isFixed, offsetParent);
|
|
318
|
+
let scroll = {
|
|
319
|
+
scrollLeft: 0,
|
|
320
|
+
scrollTop: 0
|
|
321
|
+
};
|
|
322
|
+
const offsets = createCoords(0);
|
|
323
|
+
if (isOffsetParentAnElement || !isOffsetParentAnElement && !isFixed) {
|
|
324
|
+
if (getNodeName(offsetParent) !== "body" || isOverflowElement(documentElement)) {
|
|
325
|
+
scroll = getNodeScroll(offsetParent);
|
|
326
|
+
}
|
|
327
|
+
if (isOffsetParentAnElement) {
|
|
328
|
+
const offsetRect = getBoundingClientRect(offsetParent, true, isFixed, offsetParent);
|
|
329
|
+
offsets.x = offsetRect.x + offsetParent.clientLeft;
|
|
330
|
+
offsets.y = offsetRect.y + offsetParent.clientTop;
|
|
331
|
+
} else if (documentElement) {
|
|
332
|
+
offsets.x = getWindowScrollBarX(documentElement);
|
|
498
333
|
}
|
|
499
|
-
}
|
|
334
|
+
}
|
|
335
|
+
let htmlX = 0;
|
|
336
|
+
let htmlY = 0;
|
|
337
|
+
if (documentElement && !isOffsetParentAnElement && !isFixed) {
|
|
338
|
+
const htmlRect = documentElement.getBoundingClientRect();
|
|
339
|
+
htmlY = htmlRect.top + scroll.scrollTop;
|
|
340
|
+
htmlX = htmlRect.left + scroll.scrollLeft - // RTL <body> scrollbar.
|
|
341
|
+
getWindowScrollBarX(documentElement, htmlRect);
|
|
342
|
+
}
|
|
343
|
+
const x = rect.left + scroll.scrollLeft - offsets.x - htmlX;
|
|
344
|
+
const y = rect.top + scroll.scrollTop - offsets.y - htmlY;
|
|
345
|
+
return {
|
|
346
|
+
x,
|
|
347
|
+
y,
|
|
348
|
+
width: rect.width,
|
|
349
|
+
height: rect.height
|
|
350
|
+
};
|
|
351
|
+
}
|
|
352
|
+
function isStaticPositioned(element) {
|
|
353
|
+
return getComputedStyle(element).position === "static";
|
|
500
354
|
}
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
function getFloatingFocusElement(floatingElement) {
|
|
504
|
-
if (!floatingElement) {
|
|
355
|
+
function getTrueOffsetParent(element, polyfill) {
|
|
356
|
+
if (!isHTMLElement(element) || getComputedStyle(element).position === "fixed") {
|
|
505
357
|
return null;
|
|
506
358
|
}
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
const LIST_LIMIT = 20;
|
|
510
|
-
let previouslyFocusedElements = [];
|
|
511
|
-
function addPreviouslyFocusedElement(element) {
|
|
512
|
-
previouslyFocusedElements = previouslyFocusedElements.filter((el) => el.isConnected);
|
|
513
|
-
let tabbableEl = element;
|
|
514
|
-
if (!tabbableEl || getNodeName(tabbableEl) === "body") return;
|
|
515
|
-
if (!isTabbable(tabbableEl, getTabbableOptions())) {
|
|
516
|
-
const tabbableChild = tabbable(tabbableEl, getTabbableOptions())[0];
|
|
517
|
-
if (tabbableChild) {
|
|
518
|
-
tabbableEl = tabbableChild;
|
|
519
|
-
}
|
|
359
|
+
if (polyfill) {
|
|
360
|
+
return polyfill(element);
|
|
520
361
|
}
|
|
521
|
-
|
|
522
|
-
if (
|
|
523
|
-
|
|
362
|
+
let rawOffsetParent = element.offsetParent;
|
|
363
|
+
if (getDocumentElement(element) === rawOffsetParent) {
|
|
364
|
+
rawOffsetParent = rawOffsetParent.ownerDocument.body;
|
|
524
365
|
}
|
|
366
|
+
return rawOffsetParent;
|
|
525
367
|
}
|
|
526
|
-
function
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
return /* @__PURE__ */ React.createElement("button", _extends({}, props, {
|
|
531
|
-
type: "button",
|
|
532
|
-
ref,
|
|
533
|
-
tabIndex: -1,
|
|
534
|
-
style: HIDDEN_STYLES
|
|
535
|
-
}));
|
|
536
|
-
});
|
|
537
|
-
function FloatingFocusManager(props) {
|
|
538
|
-
const {
|
|
539
|
-
context,
|
|
540
|
-
children,
|
|
541
|
-
disabled = false,
|
|
542
|
-
order = ["content"],
|
|
543
|
-
guards: _guards = true,
|
|
544
|
-
initialFocus = 0,
|
|
545
|
-
returnFocus = true,
|
|
546
|
-
restoreFocus = false,
|
|
547
|
-
modal = true,
|
|
548
|
-
visuallyHiddenDismiss = false,
|
|
549
|
-
closeOnFocusOut = true
|
|
550
|
-
} = props;
|
|
551
|
-
const {
|
|
552
|
-
open,
|
|
553
|
-
refs,
|
|
554
|
-
nodeId,
|
|
555
|
-
onOpenChange,
|
|
556
|
-
events,
|
|
557
|
-
dataRef,
|
|
558
|
-
floatingId,
|
|
559
|
-
elements: {
|
|
560
|
-
domReference,
|
|
561
|
-
floating
|
|
562
|
-
}
|
|
563
|
-
} = context;
|
|
564
|
-
const ignoreInitialFocus = typeof initialFocus === "number" && initialFocus < 0;
|
|
565
|
-
const isUntrappedTypeableCombobox = isTypeableCombobox(domReference) && ignoreInitialFocus;
|
|
566
|
-
const guards = supportsInert() ? _guards : true;
|
|
567
|
-
const orderRef = useLatestRef(order);
|
|
568
|
-
const initialFocusRef = useLatestRef(initialFocus);
|
|
569
|
-
const returnFocusRef = useLatestRef(returnFocus);
|
|
570
|
-
const tree = useFloatingTree();
|
|
571
|
-
const portalContext = usePortalContext();
|
|
572
|
-
const startDismissButtonRef = React.useRef(null);
|
|
573
|
-
const endDismissButtonRef = React.useRef(null);
|
|
574
|
-
const preventReturnFocusRef = React.useRef(false);
|
|
575
|
-
const isPointerDownRef = React.useRef(false);
|
|
576
|
-
const tabbableIndexRef = React.useRef(-1);
|
|
577
|
-
const isInsidePortal = portalContext != null;
|
|
578
|
-
const floatingFocusElement = getFloatingFocusElement(floating);
|
|
579
|
-
const getTabbableContent = useEffectEvent(function(container) {
|
|
580
|
-
if (container === void 0) {
|
|
581
|
-
container = floatingFocusElement;
|
|
582
|
-
}
|
|
583
|
-
return container ? tabbable(container, getTabbableOptions()) : [];
|
|
584
|
-
});
|
|
585
|
-
const getTabbableElements = useEffectEvent((container) => {
|
|
586
|
-
const content = getTabbableContent(container);
|
|
587
|
-
return orderRef.current.map((type) => {
|
|
588
|
-
if (domReference && type === "reference") {
|
|
589
|
-
return domReference;
|
|
590
|
-
}
|
|
591
|
-
if (floatingFocusElement && type === "floating") {
|
|
592
|
-
return floatingFocusElement;
|
|
593
|
-
}
|
|
594
|
-
return content;
|
|
595
|
-
}).filter(Boolean).flat();
|
|
596
|
-
});
|
|
597
|
-
React.useEffect(() => {
|
|
598
|
-
preventReturnFocusRef.current = false;
|
|
599
|
-
}, [disabled]);
|
|
600
|
-
React.useEffect(() => {
|
|
601
|
-
if (disabled) return;
|
|
602
|
-
if (!modal) return;
|
|
603
|
-
function onKeyDown(event) {
|
|
604
|
-
if (event.key === "Tab") {
|
|
605
|
-
if (contains(floatingFocusElement, activeElement(getDocument(floatingFocusElement))) && getTabbableContent().length === 0 && !isUntrappedTypeableCombobox) {
|
|
606
|
-
stopEvent(event);
|
|
607
|
-
}
|
|
608
|
-
const els = getTabbableElements();
|
|
609
|
-
const target = getTarget(event);
|
|
610
|
-
if (orderRef.current[0] === "reference" && target === domReference) {
|
|
611
|
-
stopEvent(event);
|
|
612
|
-
if (event.shiftKey) {
|
|
613
|
-
enqueueFocus(els[els.length - 1]);
|
|
614
|
-
} else {
|
|
615
|
-
enqueueFocus(els[1]);
|
|
616
|
-
}
|
|
617
|
-
}
|
|
618
|
-
if (orderRef.current[1] === "floating" && target === floatingFocusElement && event.shiftKey) {
|
|
619
|
-
stopEvent(event);
|
|
620
|
-
enqueueFocus(els[0]);
|
|
621
|
-
}
|
|
622
|
-
}
|
|
623
|
-
}
|
|
624
|
-
const doc = getDocument(floatingFocusElement);
|
|
625
|
-
doc.addEventListener("keydown", onKeyDown);
|
|
626
|
-
return () => {
|
|
627
|
-
doc.removeEventListener("keydown", onKeyDown);
|
|
628
|
-
};
|
|
629
|
-
}, [disabled, domReference, floatingFocusElement, modal, orderRef, isUntrappedTypeableCombobox, getTabbableContent, getTabbableElements]);
|
|
630
|
-
React.useEffect(() => {
|
|
631
|
-
if (disabled) return;
|
|
632
|
-
if (!floating) return;
|
|
633
|
-
function handleFocusIn(event) {
|
|
634
|
-
const target = getTarget(event);
|
|
635
|
-
const tabbableContent = getTabbableContent();
|
|
636
|
-
const tabbableIndex = tabbableContent.indexOf(target);
|
|
637
|
-
if (tabbableIndex !== -1) {
|
|
638
|
-
tabbableIndexRef.current = tabbableIndex;
|
|
639
|
-
}
|
|
640
|
-
}
|
|
641
|
-
floating.addEventListener("focusin", handleFocusIn);
|
|
642
|
-
return () => {
|
|
643
|
-
floating.removeEventListener("focusin", handleFocusIn);
|
|
644
|
-
};
|
|
645
|
-
}, [disabled, floating, getTabbableContent]);
|
|
646
|
-
React.useEffect(() => {
|
|
647
|
-
if (disabled) return;
|
|
648
|
-
if (!closeOnFocusOut) return;
|
|
649
|
-
function handlePointerDown() {
|
|
650
|
-
isPointerDownRef.current = true;
|
|
651
|
-
setTimeout(() => {
|
|
652
|
-
isPointerDownRef.current = false;
|
|
653
|
-
});
|
|
654
|
-
}
|
|
655
|
-
function handleFocusOutside(event) {
|
|
656
|
-
const relatedTarget = event.relatedTarget;
|
|
657
|
-
queueMicrotask(() => {
|
|
658
|
-
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) => {
|
|
659
|
-
var _node$context, _node$context2;
|
|
660
|
-
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);
|
|
661
|
-
}) || getAncestors(tree.nodesRef.current, nodeId).find((node) => {
|
|
662
|
-
var _node$context3, _node$context4;
|
|
663
|
-
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;
|
|
664
|
-
})));
|
|
665
|
-
if (restoreFocus && movedToUnrelatedNode && activeElement(getDocument(floatingFocusElement)) === getDocument(floatingFocusElement).body) {
|
|
666
|
-
if (isHTMLElement(floatingFocusElement)) {
|
|
667
|
-
floatingFocusElement.focus();
|
|
668
|
-
}
|
|
669
|
-
const prevTabbableIndex = tabbableIndexRef.current;
|
|
670
|
-
const tabbableContent = getTabbableContent();
|
|
671
|
-
const nodeToFocus = tabbableContent[prevTabbableIndex] || tabbableContent[tabbableContent.length - 1] || floatingFocusElement;
|
|
672
|
-
if (isHTMLElement(nodeToFocus)) {
|
|
673
|
-
nodeToFocus.focus();
|
|
674
|
-
}
|
|
675
|
-
}
|
|
676
|
-
if ((isUntrappedTypeableCombobox ? true : !modal) && relatedTarget && movedToUnrelatedNode && !isPointerDownRef.current && // Fix React 18 Strict Mode returnFocus due to double rendering.
|
|
677
|
-
relatedTarget !== getPreviouslyFocusedElement()) {
|
|
678
|
-
preventReturnFocusRef.current = true;
|
|
679
|
-
onOpenChange(false, event, "focus-out");
|
|
680
|
-
}
|
|
681
|
-
});
|
|
682
|
-
}
|
|
683
|
-
if (floating && isHTMLElement(domReference)) {
|
|
684
|
-
domReference.addEventListener("focusout", handleFocusOutside);
|
|
685
|
-
domReference.addEventListener("pointerdown", handlePointerDown);
|
|
686
|
-
floating.addEventListener("focusout", handleFocusOutside);
|
|
687
|
-
return () => {
|
|
688
|
-
domReference.removeEventListener("focusout", handleFocusOutside);
|
|
689
|
-
domReference.removeEventListener("pointerdown", handlePointerDown);
|
|
690
|
-
floating.removeEventListener("focusout", handleFocusOutside);
|
|
691
|
-
};
|
|
692
|
-
}
|
|
693
|
-
}, [disabled, domReference, floating, floatingFocusElement, modal, nodeId, tree, portalContext, onOpenChange, closeOnFocusOut, restoreFocus, getTabbableContent, isUntrappedTypeableCombobox]);
|
|
694
|
-
React.useEffect(() => {
|
|
695
|
-
var _portalContext$portal;
|
|
696
|
-
if (disabled) return;
|
|
697
|
-
const portalNodes = Array.from((portalContext == null || (_portalContext$portal = portalContext.portalNode) == null ? void 0 : _portalContext$portal.querySelectorAll("[" + createAttribute("portal") + "]")) || []);
|
|
698
|
-
if (floating) {
|
|
699
|
-
const insideElements = [floating, ...portalNodes, startDismissButtonRef.current, endDismissButtonRef.current, orderRef.current.includes("reference") || isUntrappedTypeableCombobox ? domReference : null].filter((x) => x != null);
|
|
700
|
-
const cleanup = modal || isUntrappedTypeableCombobox ? markOthers(insideElements, guards, !guards) : markOthers(insideElements);
|
|
701
|
-
return () => {
|
|
702
|
-
cleanup();
|
|
703
|
-
};
|
|
704
|
-
}
|
|
705
|
-
}, [disabled, domReference, floating, modal, orderRef, portalContext, isUntrappedTypeableCombobox, guards]);
|
|
706
|
-
index(() => {
|
|
707
|
-
if (disabled || !isHTMLElement(floatingFocusElement)) return;
|
|
708
|
-
const doc = getDocument(floatingFocusElement);
|
|
709
|
-
const previouslyFocusedElement = activeElement(doc);
|
|
710
|
-
queueMicrotask(() => {
|
|
711
|
-
const focusableElements = getTabbableElements(floatingFocusElement);
|
|
712
|
-
const initialFocusValue = initialFocusRef.current;
|
|
713
|
-
const elToFocus = (typeof initialFocusValue === "number" ? focusableElements[initialFocusValue] : initialFocusValue.current) || floatingFocusElement;
|
|
714
|
-
const focusAlreadyInsideFloatingEl = contains(floatingFocusElement, previouslyFocusedElement);
|
|
715
|
-
if (!ignoreInitialFocus && !focusAlreadyInsideFloatingEl && open) {
|
|
716
|
-
enqueueFocus(elToFocus, {
|
|
717
|
-
preventScroll: elToFocus === floatingFocusElement
|
|
718
|
-
});
|
|
719
|
-
}
|
|
720
|
-
});
|
|
721
|
-
}, [disabled, open, floatingFocusElement, ignoreInitialFocus, getTabbableElements, initialFocusRef]);
|
|
722
|
-
index(() => {
|
|
723
|
-
if (disabled || !floatingFocusElement) return;
|
|
724
|
-
let preventReturnFocusScroll = false;
|
|
725
|
-
const doc = getDocument(floatingFocusElement);
|
|
726
|
-
const previouslyFocusedElement = activeElement(doc);
|
|
727
|
-
const contextData = dataRef.current;
|
|
728
|
-
let openEvent = contextData.openEvent;
|
|
729
|
-
addPreviouslyFocusedElement(previouslyFocusedElement);
|
|
730
|
-
function onOpenChange2(_ref) {
|
|
731
|
-
let {
|
|
732
|
-
open: open2,
|
|
733
|
-
reason,
|
|
734
|
-
event,
|
|
735
|
-
nested
|
|
736
|
-
} = _ref;
|
|
737
|
-
if (open2) {
|
|
738
|
-
openEvent = event;
|
|
739
|
-
}
|
|
740
|
-
if (reason === "escape-key" && refs.domReference.current) {
|
|
741
|
-
addPreviouslyFocusedElement(refs.domReference.current);
|
|
742
|
-
}
|
|
743
|
-
if (reason === "hover" && event.type === "mouseleave") {
|
|
744
|
-
preventReturnFocusRef.current = true;
|
|
745
|
-
}
|
|
746
|
-
if (reason !== "outside-press") return;
|
|
747
|
-
if (nested) {
|
|
748
|
-
preventReturnFocusRef.current = false;
|
|
749
|
-
preventReturnFocusScroll = true;
|
|
750
|
-
} else {
|
|
751
|
-
preventReturnFocusRef.current = !(isVirtualClick(event) || isVirtualPointerEvent(event));
|
|
752
|
-
}
|
|
753
|
-
}
|
|
754
|
-
events.on("openchange", onOpenChange2);
|
|
755
|
-
const fallbackEl = doc.createElement("span");
|
|
756
|
-
fallbackEl.setAttribute("tabindex", "-1");
|
|
757
|
-
fallbackEl.setAttribute("aria-hidden", "true");
|
|
758
|
-
Object.assign(fallbackEl.style, HIDDEN_STYLES);
|
|
759
|
-
if (isInsidePortal && domReference) {
|
|
760
|
-
domReference.insertAdjacentElement("afterend", fallbackEl);
|
|
761
|
-
}
|
|
762
|
-
return () => {
|
|
763
|
-
events.off("openchange", onOpenChange2);
|
|
764
|
-
const activeEl = activeElement(doc);
|
|
765
|
-
const isFocusInsideFloatingTree = contains(floating, activeEl) || tree && getChildren(tree.nodesRef.current, nodeId).some((node) => {
|
|
766
|
-
var _node$context5;
|
|
767
|
-
return contains((_node$context5 = node.context) == null ? void 0 : _node$context5.elements.floating, activeEl);
|
|
768
|
-
});
|
|
769
|
-
const shouldFocusReference = isFocusInsideFloatingTree || openEvent && ["click", "mousedown"].includes(openEvent.type);
|
|
770
|
-
if (shouldFocusReference && refs.domReference.current) {
|
|
771
|
-
addPreviouslyFocusedElement(refs.domReference.current);
|
|
772
|
-
}
|
|
773
|
-
const returnElement = getPreviouslyFocusedElement() || fallbackEl;
|
|
774
|
-
queueMicrotask(() => {
|
|
775
|
-
if (
|
|
776
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
777
|
-
returnFocusRef.current && !preventReturnFocusRef.current && isHTMLElement(returnElement) && // If the focus moved somewhere else after mount, avoid returning focus
|
|
778
|
-
// since it likely entered a different element which should be
|
|
779
|
-
// respected: https://github.com/floating-ui/floating-ui/issues/2607
|
|
780
|
-
(returnElement !== activeEl && activeEl !== doc.body ? isFocusInsideFloatingTree : true)
|
|
781
|
-
) {
|
|
782
|
-
returnElement.focus({
|
|
783
|
-
preventScroll: preventReturnFocusScroll
|
|
784
|
-
});
|
|
785
|
-
}
|
|
786
|
-
fallbackEl.remove();
|
|
787
|
-
});
|
|
788
|
-
};
|
|
789
|
-
}, [disabled, floating, floatingFocusElement, returnFocusRef, dataRef, refs, events, tree, nodeId, isInsidePortal, domReference]);
|
|
790
|
-
index(() => {
|
|
791
|
-
if (disabled) return;
|
|
792
|
-
if (!portalContext) return;
|
|
793
|
-
portalContext.setFocusManagerState({
|
|
794
|
-
modal,
|
|
795
|
-
closeOnFocusOut,
|
|
796
|
-
open,
|
|
797
|
-
onOpenChange,
|
|
798
|
-
refs
|
|
799
|
-
});
|
|
800
|
-
return () => {
|
|
801
|
-
portalContext.setFocusManagerState(null);
|
|
802
|
-
};
|
|
803
|
-
}, [disabled, portalContext, modal, open, onOpenChange, refs, closeOnFocusOut]);
|
|
804
|
-
index(() => {
|
|
805
|
-
if (disabled) return;
|
|
806
|
-
if (!floatingFocusElement) return;
|
|
807
|
-
if (typeof MutationObserver !== "function") return;
|
|
808
|
-
if (ignoreInitialFocus) return;
|
|
809
|
-
const handleMutation = () => {
|
|
810
|
-
const tabIndex = floatingFocusElement.getAttribute("tabindex");
|
|
811
|
-
const tabbableContent = getTabbableContent();
|
|
812
|
-
const activeEl = activeElement(getDocument(floating));
|
|
813
|
-
const tabbableIndex = tabbableContent.indexOf(activeEl);
|
|
814
|
-
if (tabbableIndex !== -1) {
|
|
815
|
-
tabbableIndexRef.current = tabbableIndex;
|
|
816
|
-
}
|
|
817
|
-
if (orderRef.current.includes("floating") || activeEl !== refs.domReference.current && tabbableContent.length === 0) {
|
|
818
|
-
if (tabIndex !== "0") {
|
|
819
|
-
floatingFocusElement.setAttribute("tabindex", "0");
|
|
820
|
-
}
|
|
821
|
-
} else if (tabIndex !== "-1") {
|
|
822
|
-
floatingFocusElement.setAttribute("tabindex", "-1");
|
|
823
|
-
}
|
|
824
|
-
};
|
|
825
|
-
handleMutation();
|
|
826
|
-
const observer = new MutationObserver(handleMutation);
|
|
827
|
-
observer.observe(floatingFocusElement, {
|
|
828
|
-
childList: true,
|
|
829
|
-
subtree: true,
|
|
830
|
-
attributes: true
|
|
831
|
-
});
|
|
832
|
-
return () => {
|
|
833
|
-
observer.disconnect();
|
|
834
|
-
};
|
|
835
|
-
}, [disabled, floating, floatingFocusElement, refs, orderRef, getTabbableContent, ignoreInitialFocus]);
|
|
836
|
-
function renderDismissButton(location) {
|
|
837
|
-
if (disabled || !visuallyHiddenDismiss || !modal) {
|
|
838
|
-
return null;
|
|
839
|
-
}
|
|
840
|
-
return /* @__PURE__ */ React.createElement(VisuallyHiddenDismiss, {
|
|
841
|
-
ref: location === "start" ? startDismissButtonRef : endDismissButtonRef,
|
|
842
|
-
onClick: (event) => onOpenChange(false, event.nativeEvent)
|
|
843
|
-
}, typeof visuallyHiddenDismiss === "string" ? visuallyHiddenDismiss : "Dismiss");
|
|
368
|
+
function getOffsetParent(element, polyfill) {
|
|
369
|
+
const win = getWindow(element);
|
|
370
|
+
if (isTopLayer(element)) {
|
|
371
|
+
return win;
|
|
844
372
|
}
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
if (modal) {
|
|
851
|
-
const els = getTabbableElements();
|
|
852
|
-
enqueueFocus(order[0] === "reference" ? els[0] : els[els.length - 1]);
|
|
853
|
-
} else if (portalContext != null && portalContext.preserveTabOrder && portalContext.portalNode) {
|
|
854
|
-
preventReturnFocusRef.current = false;
|
|
855
|
-
if (isOutsideEvent(event, portalContext.portalNode)) {
|
|
856
|
-
const nextTabbable = getNextTabbable() || domReference;
|
|
857
|
-
nextTabbable == null || nextTabbable.focus();
|
|
858
|
-
} else {
|
|
859
|
-
var _portalContext$before;
|
|
860
|
-
(_portalContext$before = portalContext.beforeOutsideRef.current) == null || _portalContext$before.focus();
|
|
861
|
-
}
|
|
373
|
+
if (!isHTMLElement(element)) {
|
|
374
|
+
let svgOffsetParent = getParentNode(element);
|
|
375
|
+
while (svgOffsetParent && !isLastTraversableNode(svgOffsetParent)) {
|
|
376
|
+
if (isElement(svgOffsetParent) && !isStaticPositioned(svgOffsetParent)) {
|
|
377
|
+
return svgOffsetParent;
|
|
862
378
|
}
|
|
379
|
+
svgOffsetParent = getParentNode(svgOffsetParent);
|
|
863
380
|
}
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
if (isOutsideEvent(event, portalContext.portalNode)) {
|
|
875
|
-
const prevTabbable = getPreviousTabbable() || domReference;
|
|
876
|
-
prevTabbable == null || prevTabbable.focus();
|
|
877
|
-
} else {
|
|
878
|
-
var _portalContext$afterO;
|
|
879
|
-
(_portalContext$afterO = portalContext.afterOutsideRef.current) == null || _portalContext$afterO.focus();
|
|
880
|
-
}
|
|
881
|
-
}
|
|
882
|
-
}
|
|
883
|
-
}));
|
|
381
|
+
return win;
|
|
382
|
+
}
|
|
383
|
+
let offsetParent = getTrueOffsetParent(element, polyfill);
|
|
384
|
+
while (offsetParent && isTableElement(offsetParent) && isStaticPositioned(offsetParent)) {
|
|
385
|
+
offsetParent = getTrueOffsetParent(offsetParent, polyfill);
|
|
386
|
+
}
|
|
387
|
+
if (offsetParent && isLastTraversableNode(offsetParent) && isStaticPositioned(offsetParent) && !isContainingBlock(offsetParent)) {
|
|
388
|
+
return win;
|
|
389
|
+
}
|
|
390
|
+
return offsetParent || getContainingBlock(element) || win;
|
|
884
391
|
}
|
|
885
|
-
const
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
};
|
|
890
|
-
const captureHandlerKeys = {
|
|
891
|
-
pointerdown: "onPointerDownCapture",
|
|
892
|
-
mousedown: "onMouseDownCapture",
|
|
893
|
-
click: "onClickCapture"
|
|
894
|
-
};
|
|
895
|
-
const normalizeProp = (normalizable) => {
|
|
896
|
-
var _normalizable$escapeK, _normalizable$outside;
|
|
392
|
+
const getElementRects = async function(data) {
|
|
393
|
+
const getOffsetParentFn = this.getOffsetParent || getOffsetParent;
|
|
394
|
+
const getDimensionsFn = this.getDimensions;
|
|
395
|
+
const floatingDimensions = await getDimensionsFn(data.floating);
|
|
897
396
|
return {
|
|
898
|
-
|
|
899
|
-
|
|
397
|
+
reference: getRectRelativeToOffsetParent(data.reference, await getOffsetParentFn(data.floating), data.strategy),
|
|
398
|
+
floating: {
|
|
399
|
+
x: 0,
|
|
400
|
+
y: 0,
|
|
401
|
+
width: floatingDimensions.width,
|
|
402
|
+
height: floatingDimensions.height
|
|
403
|
+
}
|
|
900
404
|
};
|
|
901
405
|
};
|
|
902
|
-
function
|
|
903
|
-
|
|
904
|
-
|
|
406
|
+
function isRTL(element) {
|
|
407
|
+
return getComputedStyle(element).direction === "rtl";
|
|
408
|
+
}
|
|
409
|
+
const platform = {
|
|
410
|
+
convertOffsetParentRelativeRectToViewportRelativeRect,
|
|
411
|
+
getDocumentElement,
|
|
412
|
+
getClippingRect,
|
|
413
|
+
getOffsetParent,
|
|
414
|
+
getElementRects,
|
|
415
|
+
getClientRects,
|
|
416
|
+
getDimensions,
|
|
417
|
+
getScale,
|
|
418
|
+
isElement,
|
|
419
|
+
isRTL
|
|
420
|
+
};
|
|
421
|
+
function observeMove(element, onMove) {
|
|
422
|
+
let io = null;
|
|
423
|
+
let timeoutId;
|
|
424
|
+
const root = getDocumentElement(element);
|
|
425
|
+
function cleanup() {
|
|
426
|
+
var _io;
|
|
427
|
+
clearTimeout(timeoutId);
|
|
428
|
+
(_io = io) == null || _io.disconnect();
|
|
429
|
+
io = null;
|
|
905
430
|
}
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
elements,
|
|
910
|
-
dataRef
|
|
911
|
-
} = context;
|
|
912
|
-
const {
|
|
913
|
-
enabled = true,
|
|
914
|
-
escapeKey = true,
|
|
915
|
-
outsidePress: unstable_outsidePress = true,
|
|
916
|
-
outsidePressEvent = "pointerdown",
|
|
917
|
-
referencePress = false,
|
|
918
|
-
referencePressEvent = "pointerdown",
|
|
919
|
-
ancestorScroll = false,
|
|
920
|
-
bubbles,
|
|
921
|
-
capture
|
|
922
|
-
} = props;
|
|
923
|
-
const tree = useFloatingTree();
|
|
924
|
-
const outsidePressFn = useEffectEvent(typeof unstable_outsidePress === "function" ? unstable_outsidePress : () => false);
|
|
925
|
-
const outsidePress = typeof unstable_outsidePress === "function" ? outsidePressFn : unstable_outsidePress;
|
|
926
|
-
const insideReactTreeRef = React.useRef(false);
|
|
927
|
-
const endedOrStartedInsideRef = React.useRef(false);
|
|
928
|
-
const {
|
|
929
|
-
escapeKey: escapeKeyBubbles,
|
|
930
|
-
outsidePress: outsidePressBubbles
|
|
931
|
-
} = normalizeProp(bubbles);
|
|
932
|
-
const {
|
|
933
|
-
escapeKey: escapeKeyCapture,
|
|
934
|
-
outsidePress: outsidePressCapture
|
|
935
|
-
} = normalizeProp(capture);
|
|
936
|
-
const closeOnEscapeKeyDown = useEffectEvent((event) => {
|
|
937
|
-
var _dataRef$current$floa;
|
|
938
|
-
if (!open || !enabled || !escapeKey || event.key !== "Escape") {
|
|
939
|
-
return;
|
|
431
|
+
function refresh(skip, threshold) {
|
|
432
|
+
if (skip === void 0) {
|
|
433
|
+
skip = false;
|
|
940
434
|
}
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
if (!escapeKeyBubbles) {
|
|
944
|
-
event.stopPropagation();
|
|
945
|
-
if (children.length > 0) {
|
|
946
|
-
let shouldDismiss = true;
|
|
947
|
-
children.forEach((child) => {
|
|
948
|
-
var _child$context;
|
|
949
|
-
if ((_child$context = child.context) != null && _child$context.open && !child.context.dataRef.current.__escapeKeyBubbles) {
|
|
950
|
-
shouldDismiss = false;
|
|
951
|
-
return;
|
|
952
|
-
}
|
|
953
|
-
});
|
|
954
|
-
if (!shouldDismiss) {
|
|
955
|
-
return;
|
|
956
|
-
}
|
|
957
|
-
}
|
|
958
|
-
}
|
|
959
|
-
onOpenChange(false, isReactEvent(event) ? event.nativeEvent : event, "escape-key");
|
|
960
|
-
});
|
|
961
|
-
const closeOnEscapeKeyDownCapture = useEffectEvent((event) => {
|
|
962
|
-
var _getTarget2;
|
|
963
|
-
const callback = () => {
|
|
964
|
-
var _getTarget;
|
|
965
|
-
closeOnEscapeKeyDown(event);
|
|
966
|
-
(_getTarget = getTarget(event)) == null || _getTarget.removeEventListener("keydown", callback);
|
|
967
|
-
};
|
|
968
|
-
(_getTarget2 = getTarget(event)) == null || _getTarget2.addEventListener("keydown", callback);
|
|
969
|
-
});
|
|
970
|
-
const closeOnPressOutside = useEffectEvent((event) => {
|
|
971
|
-
var _dataRef$current$floa2;
|
|
972
|
-
const insideReactTree = insideReactTreeRef.current;
|
|
973
|
-
insideReactTreeRef.current = false;
|
|
974
|
-
const endedOrStartedInside = endedOrStartedInsideRef.current;
|
|
975
|
-
endedOrStartedInsideRef.current = false;
|
|
976
|
-
if (outsidePressEvent === "click" && endedOrStartedInside) {
|
|
977
|
-
return;
|
|
978
|
-
}
|
|
979
|
-
if (insideReactTree) {
|
|
980
|
-
return;
|
|
435
|
+
if (threshold === void 0) {
|
|
436
|
+
threshold = 1;
|
|
981
437
|
}
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
}
|
|
994
|
-
targetRootAncestor = nextParent;
|
|
995
|
-
}
|
|
996
|
-
if (markers.length && isElement(target) && !isRootElement(target) && // Clicked on a direct ancestor (e.g. FloatingOverlay).
|
|
997
|
-
!contains(target, elements.floating) && // If the target root element contains none of the markers, then the
|
|
998
|
-
// element was injected after the floating element rendered.
|
|
999
|
-
Array.from(markers).every((marker) => !contains(targetRootAncestor, marker))) {
|
|
438
|
+
cleanup();
|
|
439
|
+
const {
|
|
440
|
+
left,
|
|
441
|
+
top,
|
|
442
|
+
width,
|
|
443
|
+
height
|
|
444
|
+
} = element.getBoundingClientRect();
|
|
445
|
+
if (!skip) {
|
|
446
|
+
onMove();
|
|
447
|
+
}
|
|
448
|
+
if (!width || !height) {
|
|
1000
449
|
return;
|
|
1001
450
|
}
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
451
|
+
const insetTop = floor(top);
|
|
452
|
+
const insetRight = floor(root.clientWidth - (left + width));
|
|
453
|
+
const insetBottom = floor(root.clientHeight - (top + height));
|
|
454
|
+
const insetLeft = floor(left);
|
|
455
|
+
const rootMargin = -insetTop + "px " + -insetRight + "px " + -insetBottom + "px " + -insetLeft + "px";
|
|
456
|
+
const options = {
|
|
457
|
+
rootMargin,
|
|
458
|
+
threshold: max(0, min(1, threshold)) || 1
|
|
459
|
+
};
|
|
460
|
+
let isFirstUpdate = true;
|
|
461
|
+
function handleObserve(entries) {
|
|
462
|
+
const ratio = entries[0].intersectionRatio;
|
|
463
|
+
if (ratio !== threshold) {
|
|
464
|
+
if (!isFirstUpdate) {
|
|
465
|
+
return refresh();
|
|
1010
466
|
}
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
const targetIsInsideChildren = tree && getChildren(tree.nodesRef.current, nodeId).some((node) => {
|
|
1018
|
-
var _node$context;
|
|
1019
|
-
return isEventTargetWithin(event, (_node$context = node.context) == null ? void 0 : _node$context.elements.floating);
|
|
1020
|
-
});
|
|
1021
|
-
if (isEventTargetWithin(event, elements.floating) || isEventTargetWithin(event, elements.domReference) || targetIsInsideChildren) {
|
|
1022
|
-
return;
|
|
1023
|
-
}
|
|
1024
|
-
const children = tree ? getChildren(tree.nodesRef.current, nodeId) : [];
|
|
1025
|
-
if (children.length > 0) {
|
|
1026
|
-
let shouldDismiss = true;
|
|
1027
|
-
children.forEach((child) => {
|
|
1028
|
-
var _child$context2;
|
|
1029
|
-
if ((_child$context2 = child.context) != null && _child$context2.open && !child.context.dataRef.current.__outsidePressBubbles) {
|
|
1030
|
-
shouldDismiss = false;
|
|
1031
|
-
return;
|
|
467
|
+
if (!ratio) {
|
|
468
|
+
timeoutId = setTimeout(() => {
|
|
469
|
+
refresh(false, 1e-7);
|
|
470
|
+
}, 1e3);
|
|
471
|
+
} else {
|
|
472
|
+
refresh(false, ratio);
|
|
1032
473
|
}
|
|
1033
|
-
});
|
|
1034
|
-
if (!shouldDismiss) {
|
|
1035
|
-
return;
|
|
1036
|
-
}
|
|
1037
|
-
}
|
|
1038
|
-
onOpenChange(false, event, "outside-press");
|
|
1039
|
-
});
|
|
1040
|
-
const closeOnPressOutsideCapture = useEffectEvent((event) => {
|
|
1041
|
-
var _getTarget4;
|
|
1042
|
-
const callback = () => {
|
|
1043
|
-
var _getTarget3;
|
|
1044
|
-
closeOnPressOutside(event);
|
|
1045
|
-
(_getTarget3 = getTarget(event)) == null || _getTarget3.removeEventListener(outsidePressEvent, callback);
|
|
1046
|
-
};
|
|
1047
|
-
(_getTarget4 = getTarget(event)) == null || _getTarget4.addEventListener(outsidePressEvent, callback);
|
|
1048
|
-
});
|
|
1049
|
-
React.useEffect(() => {
|
|
1050
|
-
if (!open || !enabled) {
|
|
1051
|
-
return;
|
|
1052
|
-
}
|
|
1053
|
-
dataRef.current.__escapeKeyBubbles = escapeKeyBubbles;
|
|
1054
|
-
dataRef.current.__outsidePressBubbles = outsidePressBubbles;
|
|
1055
|
-
function onScroll(event) {
|
|
1056
|
-
onOpenChange(false, event, "ancestor-scroll");
|
|
1057
|
-
}
|
|
1058
|
-
const doc = getDocument(elements.floating);
|
|
1059
|
-
escapeKey && doc.addEventListener("keydown", escapeKeyCapture ? closeOnEscapeKeyDownCapture : closeOnEscapeKeyDown, escapeKeyCapture);
|
|
1060
|
-
outsidePress && doc.addEventListener(outsidePressEvent, outsidePressCapture ? closeOnPressOutsideCapture : closeOnPressOutside, outsidePressCapture);
|
|
1061
|
-
let ancestors = [];
|
|
1062
|
-
if (ancestorScroll) {
|
|
1063
|
-
if (isElement(elements.domReference)) {
|
|
1064
|
-
ancestors = getOverflowAncestors(elements.domReference);
|
|
1065
|
-
}
|
|
1066
|
-
if (isElement(elements.floating)) {
|
|
1067
|
-
ancestors = ancestors.concat(getOverflowAncestors(elements.floating));
|
|
1068
|
-
}
|
|
1069
|
-
if (!isElement(elements.reference) && elements.reference && elements.reference.contextElement) {
|
|
1070
|
-
ancestors = ancestors.concat(getOverflowAncestors(elements.reference.contextElement));
|
|
1071
474
|
}
|
|
475
|
+
isFirstUpdate = false;
|
|
1072
476
|
}
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
ancestor.addEventListener("scroll", onScroll, {
|
|
1079
|
-
passive: true
|
|
1080
|
-
});
|
|
1081
|
-
});
|
|
1082
|
-
return () => {
|
|
1083
|
-
escapeKey && doc.removeEventListener("keydown", escapeKeyCapture ? closeOnEscapeKeyDownCapture : closeOnEscapeKeyDown, escapeKeyCapture);
|
|
1084
|
-
outsidePress && doc.removeEventListener(outsidePressEvent, outsidePressCapture ? closeOnPressOutsideCapture : closeOnPressOutside, outsidePressCapture);
|
|
1085
|
-
ancestors.forEach((ancestor) => {
|
|
1086
|
-
ancestor.removeEventListener("scroll", onScroll);
|
|
477
|
+
try {
|
|
478
|
+
io = new IntersectionObserver(handleObserve, {
|
|
479
|
+
...options,
|
|
480
|
+
// Handle <iframe>s
|
|
481
|
+
root: root.ownerDocument
|
|
1087
482
|
});
|
|
1088
|
-
}
|
|
1089
|
-
|
|
1090
|
-
React.useEffect(() => {
|
|
1091
|
-
insideReactTreeRef.current = false;
|
|
1092
|
-
}, [outsidePress, outsidePressEvent]);
|
|
1093
|
-
const reference = React.useMemo(() => ({
|
|
1094
|
-
onKeyDown: closeOnEscapeKeyDown,
|
|
1095
|
-
[bubbleHandlerKeys[referencePressEvent]]: (event) => {
|
|
1096
|
-
if (referencePress) {
|
|
1097
|
-
onOpenChange(false, event.nativeEvent, "reference-press");
|
|
1098
|
-
}
|
|
1099
|
-
}
|
|
1100
|
-
}), [closeOnEscapeKeyDown, onOpenChange, referencePress, referencePressEvent]);
|
|
1101
|
-
const floating = React.useMemo(() => ({
|
|
1102
|
-
onKeyDown: closeOnEscapeKeyDown,
|
|
1103
|
-
onMouseDown() {
|
|
1104
|
-
endedOrStartedInsideRef.current = true;
|
|
1105
|
-
},
|
|
1106
|
-
onMouseUp() {
|
|
1107
|
-
endedOrStartedInsideRef.current = true;
|
|
1108
|
-
},
|
|
1109
|
-
[captureHandlerKeys[outsidePressEvent]]: () => {
|
|
1110
|
-
insideReactTreeRef.current = true;
|
|
1111
|
-
}
|
|
1112
|
-
}), [closeOnEscapeKeyDown, outsidePressEvent]);
|
|
1113
|
-
return React.useMemo(() => enabled ? {
|
|
1114
|
-
reference,
|
|
1115
|
-
floating
|
|
1116
|
-
} : {}, [enabled, reference, floating]);
|
|
1117
|
-
}
|
|
1118
|
-
function useFloatingRootContext(options) {
|
|
1119
|
-
const {
|
|
1120
|
-
open = false,
|
|
1121
|
-
onOpenChange: onOpenChangeProp,
|
|
1122
|
-
elements: elementsProp
|
|
1123
|
-
} = options;
|
|
1124
|
-
const floatingId = useId();
|
|
1125
|
-
const dataRef = React.useRef({});
|
|
1126
|
-
const [events] = React.useState(() => createPubSub());
|
|
1127
|
-
const nested = useFloatingParentNodeId() != null;
|
|
1128
|
-
if (process.env.NODE_ENV !== "production") {
|
|
1129
|
-
const optionDomReference = elementsProp.reference;
|
|
1130
|
-
if (optionDomReference && !isElement(optionDomReference)) {
|
|
1131
|
-
error("Cannot pass a virtual element to the `elements.reference` option,", "as it must be a real DOM element. Use `refs.setPositionReference()`", "instead.");
|
|
483
|
+
} catch (e) {
|
|
484
|
+
io = new IntersectionObserver(handleObserve, options);
|
|
1132
485
|
}
|
|
486
|
+
io.observe(element);
|
|
1133
487
|
}
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
dataRef.current.openEvent = open2 ? event : void 0;
|
|
1137
|
-
events.emit("openchange", {
|
|
1138
|
-
open: open2,
|
|
1139
|
-
event,
|
|
1140
|
-
reason,
|
|
1141
|
-
nested
|
|
1142
|
-
});
|
|
1143
|
-
onOpenChangeProp == null || onOpenChangeProp(open2, event, reason);
|
|
1144
|
-
});
|
|
1145
|
-
const refs = React.useMemo(() => ({
|
|
1146
|
-
setPositionReference
|
|
1147
|
-
}), []);
|
|
1148
|
-
const elements = React.useMemo(() => ({
|
|
1149
|
-
reference: positionReference || elementsProp.reference || null,
|
|
1150
|
-
floating: elementsProp.floating || null,
|
|
1151
|
-
domReference: elementsProp.reference
|
|
1152
|
-
}), [positionReference, elementsProp.reference, elementsProp.floating]);
|
|
1153
|
-
return React.useMemo(() => ({
|
|
1154
|
-
dataRef,
|
|
1155
|
-
open,
|
|
1156
|
-
onOpenChange,
|
|
1157
|
-
elements,
|
|
1158
|
-
events,
|
|
1159
|
-
floatingId,
|
|
1160
|
-
refs
|
|
1161
|
-
}), [open, onOpenChange, elements, events, floatingId, refs]);
|
|
488
|
+
refresh(true);
|
|
489
|
+
return cleanup;
|
|
1162
490
|
}
|
|
1163
|
-
function
|
|
491
|
+
function autoUpdate(reference, floating, update, options) {
|
|
1164
492
|
if (options === void 0) {
|
|
1165
493
|
options = {};
|
|
1166
494
|
}
|
|
1167
495
|
const {
|
|
1168
|
-
|
|
496
|
+
ancestorScroll = true,
|
|
497
|
+
ancestorResize = true,
|
|
498
|
+
elementResize = typeof ResizeObserver === "function",
|
|
499
|
+
layoutShift = typeof IntersectionObserver === "function",
|
|
500
|
+
animationFrame = false
|
|
1169
501
|
} = options;
|
|
1170
|
-
const
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
502
|
+
const referenceEl = unwrapElement(reference);
|
|
503
|
+
const ancestors = ancestorScroll || ancestorResize ? [...referenceEl ? getOverflowAncestors(referenceEl) : [], ...getOverflowAncestors(floating)] : [];
|
|
504
|
+
ancestors.forEach((ancestor) => {
|
|
505
|
+
ancestorScroll && ancestor.addEventListener("scroll", update, {
|
|
506
|
+
passive: true
|
|
507
|
+
});
|
|
508
|
+
ancestorResize && ancestor.addEventListener("resize", update);
|
|
1177
509
|
});
|
|
1178
|
-
const
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
const position = useFloating$1({
|
|
1192
|
-
...options,
|
|
1193
|
-
elements: {
|
|
1194
|
-
...computedElements,
|
|
1195
|
-
...positionReference && {
|
|
1196
|
-
reference: positionReference
|
|
510
|
+
const cleanupIo = referenceEl && layoutShift ? observeMove(referenceEl, update) : null;
|
|
511
|
+
let reobserveFrame = -1;
|
|
512
|
+
let resizeObserver = null;
|
|
513
|
+
if (elementResize) {
|
|
514
|
+
resizeObserver = new ResizeObserver((_ref) => {
|
|
515
|
+
let [firstEntry] = _ref;
|
|
516
|
+
if (firstEntry && firstEntry.target === referenceEl && resizeObserver) {
|
|
517
|
+
resizeObserver.unobserve(floating);
|
|
518
|
+
cancelAnimationFrame(reobserveFrame);
|
|
519
|
+
reobserveFrame = requestAnimationFrame(() => {
|
|
520
|
+
var _resizeObserver;
|
|
521
|
+
(_resizeObserver = resizeObserver) == null || _resizeObserver.observe(floating);
|
|
522
|
+
});
|
|
1197
523
|
}
|
|
524
|
+
update();
|
|
525
|
+
});
|
|
526
|
+
if (referenceEl && !animationFrame) {
|
|
527
|
+
resizeObserver.observe(referenceEl);
|
|
1198
528
|
}
|
|
1199
|
-
|
|
1200
|
-
const setPositionReference = React.useCallback((node) => {
|
|
1201
|
-
const computedPositionReference = isElement(node) ? {
|
|
1202
|
-
getBoundingClientRect: () => node.getBoundingClientRect(),
|
|
1203
|
-
contextElement: node
|
|
1204
|
-
} : node;
|
|
1205
|
-
_setPositionReference(computedPositionReference);
|
|
1206
|
-
position.refs.setReference(computedPositionReference);
|
|
1207
|
-
}, [position.refs]);
|
|
1208
|
-
const setReference = React.useCallback((node) => {
|
|
1209
|
-
if (isElement(node) || node === null) {
|
|
1210
|
-
domReferenceRef.current = node;
|
|
1211
|
-
setDomReference(node);
|
|
1212
|
-
}
|
|
1213
|
-
if (isElement(position.refs.reference.current) || position.refs.reference.current === null || // Don't allow setting virtual elements using the old technique back to
|
|
1214
|
-
// `null` to support `positionReference` + an unstable `reference`
|
|
1215
|
-
// callback ref.
|
|
1216
|
-
node !== null && !isElement(node)) {
|
|
1217
|
-
position.refs.setReference(node);
|
|
1218
|
-
}
|
|
1219
|
-
}, [position.refs]);
|
|
1220
|
-
const refs = React.useMemo(() => ({
|
|
1221
|
-
...position.refs,
|
|
1222
|
-
setReference,
|
|
1223
|
-
setPositionReference,
|
|
1224
|
-
domReference: domReferenceRef
|
|
1225
|
-
}), [position.refs, setReference, setPositionReference]);
|
|
1226
|
-
const elements = React.useMemo(() => ({
|
|
1227
|
-
...position.elements,
|
|
1228
|
-
domReference
|
|
1229
|
-
}), [position.elements, domReference]);
|
|
1230
|
-
const context = React.useMemo(() => ({
|
|
1231
|
-
...position,
|
|
1232
|
-
...rootContext,
|
|
1233
|
-
refs,
|
|
1234
|
-
elements,
|
|
1235
|
-
nodeId
|
|
1236
|
-
}), [position, refs, elements, nodeId, rootContext]);
|
|
1237
|
-
index(() => {
|
|
1238
|
-
rootContext.dataRef.current.floatingContext = context;
|
|
1239
|
-
const node = tree == null ? void 0 : tree.nodesRef.current.find((node2) => node2.id === nodeId);
|
|
1240
|
-
if (node) {
|
|
1241
|
-
node.context = context;
|
|
1242
|
-
}
|
|
1243
|
-
});
|
|
1244
|
-
return React.useMemo(() => ({
|
|
1245
|
-
...position,
|
|
1246
|
-
context,
|
|
1247
|
-
refs,
|
|
1248
|
-
elements
|
|
1249
|
-
}), [position, refs, elements, context]);
|
|
1250
|
-
}
|
|
1251
|
-
const ACTIVE_KEY = "active";
|
|
1252
|
-
const SELECTED_KEY = "selected";
|
|
1253
|
-
function mergeProps(userProps, propsList, elementKey) {
|
|
1254
|
-
const map = /* @__PURE__ */ new Map();
|
|
1255
|
-
const isItem = elementKey === "item";
|
|
1256
|
-
let domUserProps = userProps;
|
|
1257
|
-
if (isItem && userProps) {
|
|
1258
|
-
const {
|
|
1259
|
-
[ACTIVE_KEY]: _,
|
|
1260
|
-
[SELECTED_KEY]: __,
|
|
1261
|
-
...validProps
|
|
1262
|
-
} = userProps;
|
|
1263
|
-
domUserProps = validProps;
|
|
529
|
+
resizeObserver.observe(floating);
|
|
1264
530
|
}
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
},
|
|
1270
|
-
...domUserProps,
|
|
1271
|
-
...propsList.map((value) => {
|
|
1272
|
-
const propsOrGetProps = value ? value[elementKey] : null;
|
|
1273
|
-
if (typeof propsOrGetProps === "function") {
|
|
1274
|
-
return userProps ? propsOrGetProps(userProps) : null;
|
|
1275
|
-
}
|
|
1276
|
-
return propsOrGetProps;
|
|
1277
|
-
}).concat(userProps).reduce((acc, props) => {
|
|
1278
|
-
if (!props) {
|
|
1279
|
-
return acc;
|
|
1280
|
-
}
|
|
1281
|
-
Object.entries(props).forEach((_ref) => {
|
|
1282
|
-
let [key, value] = _ref;
|
|
1283
|
-
if (isItem && [ACTIVE_KEY, SELECTED_KEY].includes(key)) {
|
|
1284
|
-
return;
|
|
1285
|
-
}
|
|
1286
|
-
if (key.indexOf("on") === 0) {
|
|
1287
|
-
if (!map.has(key)) {
|
|
1288
|
-
map.set(key, []);
|
|
1289
|
-
}
|
|
1290
|
-
if (typeof value === "function") {
|
|
1291
|
-
var _map$get;
|
|
1292
|
-
(_map$get = map.get(key)) == null || _map$get.push(value);
|
|
1293
|
-
acc[key] = function() {
|
|
1294
|
-
var _map$get2;
|
|
1295
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
1296
|
-
args[_key] = arguments[_key];
|
|
1297
|
-
}
|
|
1298
|
-
return (_map$get2 = map.get(key)) == null ? void 0 : _map$get2.map((fn) => fn(...args)).find((val) => val !== void 0);
|
|
1299
|
-
};
|
|
1300
|
-
}
|
|
1301
|
-
} else {
|
|
1302
|
-
acc[key] = value;
|
|
1303
|
-
}
|
|
1304
|
-
});
|
|
1305
|
-
return acc;
|
|
1306
|
-
}, {})
|
|
1307
|
-
};
|
|
1308
|
-
}
|
|
1309
|
-
function useInteractions(propsList) {
|
|
1310
|
-
if (propsList === void 0) {
|
|
1311
|
-
propsList = [];
|
|
1312
|
-
}
|
|
1313
|
-
const referenceDeps = propsList.map((key) => key == null ? void 0 : key.reference);
|
|
1314
|
-
const floatingDeps = propsList.map((key) => key == null ? void 0 : key.floating);
|
|
1315
|
-
const itemDeps = propsList.map((key) => key == null ? void 0 : key.item);
|
|
1316
|
-
const getReferenceProps = React.useCallback(
|
|
1317
|
-
(userProps) => mergeProps(userProps, propsList, "reference"),
|
|
1318
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
1319
|
-
referenceDeps
|
|
1320
|
-
);
|
|
1321
|
-
const getFloatingProps = React.useCallback(
|
|
1322
|
-
(userProps) => mergeProps(userProps, propsList, "floating"),
|
|
1323
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
1324
|
-
floatingDeps
|
|
1325
|
-
);
|
|
1326
|
-
const getItemProps = React.useCallback(
|
|
1327
|
-
(userProps) => mergeProps(userProps, propsList, "item"),
|
|
1328
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
1329
|
-
itemDeps
|
|
1330
|
-
);
|
|
1331
|
-
return React.useMemo(() => ({
|
|
1332
|
-
getReferenceProps,
|
|
1333
|
-
getFloatingProps,
|
|
1334
|
-
getItemProps
|
|
1335
|
-
}), [getReferenceProps, getFloatingProps, getItemProps]);
|
|
1336
|
-
}
|
|
1337
|
-
const componentRoleToAriaRoleMap = /* @__PURE__ */ new Map([["select", "listbox"], ["combobox", "listbox"], ["label", false]]);
|
|
1338
|
-
function useRole(context, props) {
|
|
1339
|
-
var _componentRoleToAriaR;
|
|
1340
|
-
if (props === void 0) {
|
|
1341
|
-
props = {};
|
|
531
|
+
let frameId;
|
|
532
|
+
let prevRefRect = animationFrame ? getBoundingClientRect(reference) : null;
|
|
533
|
+
if (animationFrame) {
|
|
534
|
+
frameLoop();
|
|
1342
535
|
}
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
const {
|
|
1348
|
-
enabled = true,
|
|
1349
|
-
role = "dialog"
|
|
1350
|
-
} = props;
|
|
1351
|
-
const ariaRole = (_componentRoleToAriaR = componentRoleToAriaRoleMap.get(role)) != null ? _componentRoleToAriaR : role;
|
|
1352
|
-
const referenceId = useId();
|
|
1353
|
-
const parentId = useFloatingParentNodeId();
|
|
1354
|
-
const isNested = parentId != null;
|
|
1355
|
-
const reference = React.useMemo(() => {
|
|
1356
|
-
if (ariaRole === "tooltip" || role === "label") {
|
|
1357
|
-
return {
|
|
1358
|
-
["aria-" + (role === "label" ? "labelledby" : "describedby")]: open ? floatingId : void 0
|
|
1359
|
-
};
|
|
536
|
+
function frameLoop() {
|
|
537
|
+
const nextRefRect = getBoundingClientRect(reference);
|
|
538
|
+
if (prevRefRect && (nextRefRect.x !== prevRefRect.x || nextRefRect.y !== prevRefRect.y || nextRefRect.width !== prevRefRect.width || nextRefRect.height !== prevRefRect.height)) {
|
|
539
|
+
update();
|
|
1360
540
|
}
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
},
|
|
1377
|
-
...role === "combobox" && {
|
|
1378
|
-
"aria-autocomplete": "list"
|
|
1379
|
-
}
|
|
1380
|
-
};
|
|
1381
|
-
}, [ariaRole, floatingId, isNested, open, referenceId, role]);
|
|
1382
|
-
const floating = React.useMemo(() => {
|
|
1383
|
-
const floatingProps = {
|
|
1384
|
-
id: floatingId,
|
|
1385
|
-
...ariaRole && {
|
|
1386
|
-
role: ariaRole
|
|
1387
|
-
}
|
|
1388
|
-
};
|
|
1389
|
-
if (ariaRole === "tooltip" || role === "label") {
|
|
1390
|
-
return floatingProps;
|
|
1391
|
-
}
|
|
1392
|
-
return {
|
|
1393
|
-
...floatingProps,
|
|
1394
|
-
...ariaRole === "menu" && {
|
|
1395
|
-
"aria-labelledby": referenceId
|
|
1396
|
-
}
|
|
1397
|
-
};
|
|
1398
|
-
}, [ariaRole, floatingId, referenceId, role]);
|
|
1399
|
-
const item = React.useCallback((_ref) => {
|
|
1400
|
-
let {
|
|
1401
|
-
active,
|
|
1402
|
-
selected
|
|
1403
|
-
} = _ref;
|
|
1404
|
-
const commonProps = {
|
|
1405
|
-
role: "option",
|
|
1406
|
-
...active && {
|
|
1407
|
-
id: floatingId + "-option"
|
|
1408
|
-
}
|
|
1409
|
-
};
|
|
1410
|
-
switch (role) {
|
|
1411
|
-
case "select":
|
|
1412
|
-
return {
|
|
1413
|
-
...commonProps,
|
|
1414
|
-
"aria-selected": active && selected
|
|
1415
|
-
};
|
|
1416
|
-
case "combobox": {
|
|
1417
|
-
return {
|
|
1418
|
-
...commonProps,
|
|
1419
|
-
...active && {
|
|
1420
|
-
"aria-selected": true
|
|
1421
|
-
}
|
|
1422
|
-
};
|
|
1423
|
-
}
|
|
541
|
+
prevRefRect = nextRefRect;
|
|
542
|
+
frameId = requestAnimationFrame(frameLoop);
|
|
543
|
+
}
|
|
544
|
+
update();
|
|
545
|
+
return () => {
|
|
546
|
+
var _resizeObserver2;
|
|
547
|
+
ancestors.forEach((ancestor) => {
|
|
548
|
+
ancestorScroll && ancestor.removeEventListener("scroll", update);
|
|
549
|
+
ancestorResize && ancestor.removeEventListener("resize", update);
|
|
550
|
+
});
|
|
551
|
+
cleanupIo == null || cleanupIo();
|
|
552
|
+
(_resizeObserver2 = resizeObserver) == null || _resizeObserver2.disconnect();
|
|
553
|
+
resizeObserver = null;
|
|
554
|
+
if (animationFrame) {
|
|
555
|
+
cancelAnimationFrame(frameId);
|
|
1424
556
|
}
|
|
1425
|
-
|
|
1426
|
-
}, [floatingId, role]);
|
|
1427
|
-
return React.useMemo(() => enabled ? {
|
|
1428
|
-
reference,
|
|
1429
|
-
floating,
|
|
1430
|
-
item
|
|
1431
|
-
} : {}, [enabled, reference, floating, item]);
|
|
557
|
+
};
|
|
1432
558
|
}
|
|
559
|
+
const offset = offset$1;
|
|
560
|
+
const shift = shift$1;
|
|
561
|
+
const flip = flip$1;
|
|
562
|
+
const inline = inline$1;
|
|
563
|
+
const computePosition = (reference, floating, options) => {
|
|
564
|
+
const cache = /* @__PURE__ */ new Map();
|
|
565
|
+
const mergedOptions = {
|
|
566
|
+
platform,
|
|
567
|
+
...options
|
|
568
|
+
};
|
|
569
|
+
const platformWithCache = {
|
|
570
|
+
...mergedOptions.platform,
|
|
571
|
+
_c: cache
|
|
572
|
+
};
|
|
573
|
+
return computePosition$1(reference, floating, {
|
|
574
|
+
...mergedOptions,
|
|
575
|
+
platform: platformWithCache
|
|
576
|
+
});
|
|
577
|
+
};
|
|
1433
578
|
export {
|
|
1434
|
-
|
|
1435
|
-
|
|
579
|
+
autoUpdate,
|
|
580
|
+
computePosition,
|
|
1436
581
|
flip,
|
|
1437
582
|
getOverflowAncestors,
|
|
1438
583
|
inline,
|
|
1439
584
|
offset,
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
useFloating,
|
|
1443
|
-
useFloatingParentNodeId,
|
|
1444
|
-
useFloatingPortalNode,
|
|
1445
|
-
useFloatingRootContext,
|
|
1446
|
-
useFloatingTree,
|
|
1447
|
-
useId,
|
|
1448
|
-
useInteractions,
|
|
1449
|
-
useRole
|
|
585
|
+
platform,
|
|
586
|
+
shift
|
|
1450
587
|
};
|
|
1451
588
|
//# sourceMappingURL=react-text-annotator.es14.js.map
|