@tamagui/select 1.0.1-beta.118 → 1.0.1-beta.121
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/cjs/Select.js +36 -32
- package/dist/cjs/Select.js.map +2 -2
- package/dist/cjs/SelectContent.js +2 -1
- package/dist/cjs/SelectContent.js.map +2 -2
- package/dist/cjs/SelectImpl.js +154 -284
- package/dist/cjs/SelectImpl.js.map +2 -2
- package/dist/cjs/SelectScrollButton.js +54 -40
- package/dist/cjs/SelectScrollButton.js.map +2 -2
- package/dist/cjs/SelectViewport.js +10 -6
- package/dist/cjs/SelectViewport.js.map +2 -2
- package/dist/cjs/types.js.map +1 -1
- package/dist/esm/Select.js +36 -32
- package/dist/esm/Select.js.map +2 -2
- package/dist/esm/SelectContent.js +3 -2
- package/dist/esm/SelectContent.js.map +2 -2
- package/dist/esm/SelectImpl.js +158 -286
- package/dist/esm/SelectImpl.js.map +2 -2
- package/dist/esm/SelectScrollButton.js +54 -40
- package/dist/esm/SelectScrollButton.js.map +2 -2
- package/dist/esm/SelectViewport.js +10 -6
- package/dist/esm/SelectViewport.js.map +2 -2
- package/dist/jsx/Select.js +34 -34
- package/dist/jsx/Select.js.map +2 -2
- package/dist/jsx/SelectContent.js +3 -2
- package/dist/jsx/SelectContent.js.map +2 -2
- package/dist/jsx/SelectImpl.js +128 -266
- package/dist/jsx/SelectImpl.js.map +2 -2
- package/dist/jsx/SelectScrollButton.js +53 -39
- package/dist/jsx/SelectScrollButton.js.map +2 -2
- package/dist/jsx/SelectViewport.js +10 -6
- package/dist/jsx/SelectViewport.js.map +2 -2
- package/package.json +15 -15
- package/src/Select.tsx +47 -49
- package/src/SelectContent.tsx +4 -2
- package/src/SelectImpl.tsx +179 -369
- package/src/SelectScrollButton.tsx +72 -54
- package/src/SelectViewport.tsx +12 -6
- package/src/types.tsx +9 -1
- package/types/Select.d.ts +15 -15
- package/types/Select.d.ts.map +1 -1
- package/types/SelectContent.d.ts +0 -1
- package/types/SelectContent.d.ts.map +1 -1
- package/types/SelectImpl.d.ts.map +1 -1
- package/types/SelectViewport.d.ts +3 -3
- package/types/SelectViewport.d.ts.map +1 -1
- package/types/types.d.ts +9 -1
- package/types/types.d.ts.map +1 -1
- package/types/constants.d.ts +0 -8
- package/types/constants.d.ts.map +0 -1
package/dist/esm/SelectImpl.js
CHANGED
|
@@ -1,43 +1,46 @@
|
|
|
1
1
|
import {
|
|
2
|
-
detectOverflow,
|
|
3
2
|
flip,
|
|
3
|
+
inner,
|
|
4
4
|
offset,
|
|
5
|
+
shift,
|
|
5
6
|
size,
|
|
6
7
|
useClick,
|
|
7
8
|
useDismiss,
|
|
8
9
|
useFloating,
|
|
10
|
+
useInnerOffset,
|
|
9
11
|
useInteractions,
|
|
10
12
|
useListNavigation,
|
|
11
13
|
useRole,
|
|
12
14
|
useTypeahead
|
|
13
15
|
} from "@floating-ui/react-dom-interactions";
|
|
14
|
-
import {
|
|
16
|
+
import { useIsTouchDevice } from "@tamagui/core";
|
|
15
17
|
import * as React from "react";
|
|
16
|
-
import {
|
|
18
|
+
import { flushSync } from "react-dom";
|
|
19
|
+
import { SCROLL_ARROW_THRESHOLD, WINDOW_PADDING } from "./constants";
|
|
17
20
|
import { SelectProvider, useSelectContext } from "./context";
|
|
18
21
|
const SelectInlineImpl = (props) => {
|
|
19
|
-
const {
|
|
20
|
-
__scopeSelect,
|
|
21
|
-
children,
|
|
22
|
-
open = false,
|
|
23
|
-
activeIndexRef,
|
|
24
|
-
selectedIndexRef,
|
|
25
|
-
listContentRef
|
|
26
|
-
} = props;
|
|
22
|
+
const { __scopeSelect, children, open = false, selectedIndexRef, listContentRef } = props;
|
|
27
23
|
const selectContext = useSelectContext("SelectSheetImpl", __scopeSelect);
|
|
28
24
|
const { setActiveIndex, setOpen, setSelectedIndex, selectedIndex, activeIndex, forceUpdate } = selectContext;
|
|
29
|
-
const [showArrows, setShowArrows] = React.useState(false);
|
|
30
25
|
const [scrollTop, setScrollTop] = React.useState(0);
|
|
31
|
-
const
|
|
26
|
+
const touch = useIsTouchDevice();
|
|
32
27
|
const listItemsRef = React.useRef([]);
|
|
28
|
+
const overflowRef = React.useRef(null);
|
|
29
|
+
const upArrowRef = React.useRef(null);
|
|
30
|
+
const downArrowRef = React.useRef(null);
|
|
31
|
+
const allowSelectRef = React.useRef(false);
|
|
32
|
+
const allowMouseUpRef = React.useRef(true);
|
|
33
|
+
const selectTimeoutRef = React.useRef();
|
|
33
34
|
const [controlledScrolling, setControlledScrolling] = React.useState(false);
|
|
34
|
-
const [
|
|
35
|
+
const [fallback, setFallback] = React.useState(false);
|
|
36
|
+
const [innerOffset, setInnerOffset] = React.useState(0);
|
|
37
|
+
const [blockSelection, setBlockSelection] = React.useState(false);
|
|
38
|
+
const floatingStyle = React.useRef({});
|
|
35
39
|
React.useEffect(() => {
|
|
36
40
|
const frame = requestAnimationFrame(() => {
|
|
37
|
-
setShowArrows(open);
|
|
38
41
|
if (!open) {
|
|
39
42
|
setScrollTop(0);
|
|
40
|
-
|
|
43
|
+
setFallback(false);
|
|
41
44
|
setActiveIndex(null);
|
|
42
45
|
setControlledScrolling(false);
|
|
43
46
|
}
|
|
@@ -46,92 +49,56 @@ const SelectInlineImpl = (props) => {
|
|
|
46
49
|
cancelAnimationFrame(frame);
|
|
47
50
|
};
|
|
48
51
|
}, [open, setActiveIndex]);
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
52
|
+
const updateFloatingSize = size({
|
|
53
|
+
apply({
|
|
54
|
+
availableHeight,
|
|
55
|
+
rects: {
|
|
56
|
+
reference: { width }
|
|
57
|
+
}
|
|
58
|
+
}) {
|
|
59
|
+
floatingStyle.current = {
|
|
60
|
+
width,
|
|
61
|
+
maxHeight: availableHeight
|
|
62
|
+
};
|
|
63
|
+
},
|
|
64
|
+
padding: WINDOW_PADDING
|
|
65
|
+
});
|
|
66
|
+
const { x, y, reference, floating, strategy, context, refs } = useFloating({
|
|
57
67
|
open,
|
|
58
68
|
onOpenChange: setOpen,
|
|
59
|
-
placement: "bottom",
|
|
60
|
-
middleware:
|
|
61
|
-
offset(({ rects }) => {
|
|
62
|
-
const index = activeIndexRef.current ?? selectedIndexRef.current;
|
|
63
|
-
if (index == null) {
|
|
64
|
-
return 0;
|
|
65
|
-
}
|
|
66
|
-
const item = listItemsRef.current[index];
|
|
67
|
-
if (item == null) {
|
|
68
|
-
return 0;
|
|
69
|
-
}
|
|
70
|
-
const offsetTop = item.offsetTop;
|
|
71
|
-
const itemHeight = item.offsetHeight;
|
|
72
|
-
const height = rects.reference.height;
|
|
73
|
-
return -offsetTop - height - (itemHeight - height) / 2;
|
|
74
|
-
}),
|
|
75
|
-
{
|
|
76
|
-
name: "size",
|
|
77
|
-
async fn(args) {
|
|
78
|
-
var _a;
|
|
79
|
-
const {
|
|
80
|
-
elements: { floating: floating2 },
|
|
81
|
-
rects: { reference: reference2 },
|
|
82
|
-
middlewareData: middlewareData2
|
|
83
|
-
} = args;
|
|
84
|
-
const overflow = await detectOverflow(args, {
|
|
85
|
-
padding: WINDOW_PADDING
|
|
86
|
-
});
|
|
87
|
-
const top = Math.max(0, overflow.top);
|
|
88
|
-
const bottom = Math.max(0, overflow.bottom);
|
|
89
|
-
const nextY = args.y + top;
|
|
90
|
-
if ((_a = middlewareData2.size) == null ? void 0 : _a.skip) {
|
|
91
|
-
return {
|
|
92
|
-
y: nextY,
|
|
93
|
-
data: {
|
|
94
|
-
y: middlewareData2.size.y
|
|
95
|
-
}
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
Object.assign(floating2.style, {
|
|
99
|
-
maxHeight: `${floating2.scrollHeight - Math.abs(top + bottom)}px`,
|
|
100
|
-
minWidth: `${reference2.width + getFloatingPadding(floating2) * 2}px`
|
|
101
|
-
});
|
|
102
|
-
return {
|
|
103
|
-
y: nextY,
|
|
104
|
-
data: {
|
|
105
|
-
y: top,
|
|
106
|
-
skip: true
|
|
107
|
-
},
|
|
108
|
-
reset: {
|
|
109
|
-
rects: true
|
|
110
|
-
}
|
|
111
|
-
};
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
] : [
|
|
69
|
+
placement: "bottom-start",
|
|
70
|
+
middleware: fallback ? [
|
|
115
71
|
offset(5),
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
72
|
+
...[
|
|
73
|
+
touch ? shift({ crossAxis: true, padding: WINDOW_PADDING }) : flip({ padding: WINDOW_PADDING })
|
|
74
|
+
],
|
|
75
|
+
updateFloatingSize
|
|
76
|
+
] : [
|
|
77
|
+
inner({
|
|
78
|
+
listRef: listItemsRef,
|
|
79
|
+
overflowRef,
|
|
80
|
+
index: selectedIndex,
|
|
81
|
+
offset: innerOffset,
|
|
82
|
+
onFallbackChange: setFallback,
|
|
83
|
+
padding: 10,
|
|
84
|
+
minItemsVisible: touch ? 10 : 4,
|
|
85
|
+
referenceOverflowThreshold: 20
|
|
86
|
+
}),
|
|
87
|
+
updateFloatingSize
|
|
126
88
|
]
|
|
127
89
|
});
|
|
128
90
|
const floatingRef = refs.floating;
|
|
129
|
-
const showUpArrow =
|
|
130
|
-
const showDownArrow =
|
|
91
|
+
const showUpArrow = open && scrollTop > SCROLL_ARROW_THRESHOLD;
|
|
92
|
+
const showDownArrow = open && floatingRef.current && scrollTop < floatingRef.current.scrollHeight - floatingRef.current.clientHeight - SCROLL_ARROW_THRESHOLD;
|
|
131
93
|
const interactions = useInteractions([
|
|
132
94
|
useClick(context, { pointerDown: true }),
|
|
95
|
+
useDismiss(context, { outsidePointerDown: false }),
|
|
133
96
|
useRole(context, { role: "listbox" }),
|
|
134
|
-
|
|
97
|
+
useInnerOffset(context, {
|
|
98
|
+
enabled: !fallback,
|
|
99
|
+
onChange: setInnerOffset,
|
|
100
|
+
overflowRef
|
|
101
|
+
}),
|
|
135
102
|
useListNavigation(context, {
|
|
136
103
|
listRef: listItemsRef,
|
|
137
104
|
activeIndex,
|
|
@@ -145,230 +112,135 @@ const SelectInlineImpl = (props) => {
|
|
|
145
112
|
activeIndex
|
|
146
113
|
})
|
|
147
114
|
]);
|
|
148
|
-
const
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
const visualMaxHeight = viewportHeight - WINDOW_PADDING * 2;
|
|
159
|
-
if (amount < 0 && selectedIndexRef.current != null && Math.round(rectBottom) < Math.round(viewportHeight + getVisualOffsetTop() - WINDOW_PADDING)) {
|
|
160
|
-
floating2.style.maxHeight = `${Math.min(visualMaxHeight, currentMaxHeight - amount)}px`;
|
|
161
|
-
}
|
|
162
|
-
if (amount > 0 && Math.round(rectTop) > Math.round(WINDOW_PADDING - getVisualOffsetTop()) && floating2.scrollHeight > floating2.offsetHeight) {
|
|
163
|
-
const nextTop = Math.max(WINDOW_PADDING + getVisualOffsetTop(), currentTop - amount);
|
|
164
|
-
const nextMaxHeight = Math.min(visualMaxHeight, currentMaxHeight + amount);
|
|
165
|
-
Object.assign(floating2.style, {
|
|
166
|
-
maxHeight: `${nextMaxHeight}px`,
|
|
167
|
-
top: `${nextTop}px`
|
|
168
|
-
});
|
|
169
|
-
if (nextTop - WINDOW_PADDING > getVisualOffsetTop()) {
|
|
170
|
-
floating2.scrollTop -= nextMaxHeight - currentMaxHeight + getFloatingPadding(floating2);
|
|
171
|
-
}
|
|
172
|
-
return currentTop - nextTop;
|
|
173
|
-
}
|
|
174
|
-
}, [middlewareType, selectedIndexRef]);
|
|
175
|
-
const touchPageYRef = React.useRef(null);
|
|
176
|
-
const handleWheel = React.useCallback((event) => {
|
|
177
|
-
var _a;
|
|
178
|
-
const pinching = event.ctrlKey;
|
|
179
|
-
const currentTarget = event.currentTarget;
|
|
180
|
-
function isWheelEvent(event2) {
|
|
181
|
-
return typeof event2.deltaY === "number";
|
|
182
|
-
}
|
|
183
|
-
function isTouchEvent(event2) {
|
|
184
|
-
return event2.touches != null;
|
|
185
|
-
}
|
|
186
|
-
if (Math.abs(((currentTarget == null ? void 0 : currentTarget.offsetHeight) ?? 0) - (((visualViewport == null ? void 0 : visualViewport.height) ?? 0) - WINDOW_PADDING * 2)) > 1 && !pinching) {
|
|
187
|
-
event.preventDefault();
|
|
188
|
-
} else if (isWheelEvent(event) && isFirefox) {
|
|
189
|
-
currentTarget.scrollTop += event.deltaY;
|
|
190
|
-
}
|
|
191
|
-
if (!pinching) {
|
|
192
|
-
let delta = 5;
|
|
193
|
-
if (isTouchEvent(event)) {
|
|
194
|
-
const currentPageY = touchPageYRef.current;
|
|
195
|
-
const pageY = (_a = event.touches[0]) == null ? void 0 : _a.pageY;
|
|
196
|
-
if (pageY != null) {
|
|
197
|
-
touchPageYRef.current = pageY;
|
|
198
|
-
if (currentPageY != null) {
|
|
199
|
-
delta = currentPageY - pageY;
|
|
115
|
+
const interactionsContext = {
|
|
116
|
+
...interactions,
|
|
117
|
+
getReferenceProps() {
|
|
118
|
+
return interactions.getReferenceProps({
|
|
119
|
+
ref: reference,
|
|
120
|
+
className: "SelectTrigger",
|
|
121
|
+
onKeyDown(event) {
|
|
122
|
+
if (event.key === "Enter" || event.key === " " && !context.dataRef.current.typing) {
|
|
123
|
+
event.preventDefault();
|
|
124
|
+
setOpen(true);
|
|
200
125
|
}
|
|
201
126
|
}
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
127
|
+
});
|
|
128
|
+
},
|
|
129
|
+
getFloatingProps(props2) {
|
|
130
|
+
return interactions.getFloatingProps({
|
|
131
|
+
ref: floating,
|
|
132
|
+
className: "Select",
|
|
133
|
+
...props2,
|
|
134
|
+
style: {
|
|
135
|
+
position: strategy,
|
|
136
|
+
top: y ?? "",
|
|
137
|
+
left: x ?? "",
|
|
138
|
+
outline: 0,
|
|
139
|
+
listStyleType: "none",
|
|
140
|
+
scrollbarWidth: "none",
|
|
141
|
+
...floatingStyle.current,
|
|
142
|
+
...props2 == null ? void 0 : props2.style
|
|
143
|
+
},
|
|
144
|
+
onPointerEnter() {
|
|
145
|
+
setControlledScrolling(false);
|
|
146
|
+
},
|
|
147
|
+
onPointerMove() {
|
|
148
|
+
setControlledScrolling(false);
|
|
149
|
+
},
|
|
150
|
+
onKeyDown() {
|
|
151
|
+
setControlledScrolling(true);
|
|
152
|
+
},
|
|
153
|
+
onContextMenu(e) {
|
|
154
|
+
e.preventDefault();
|
|
155
|
+
},
|
|
156
|
+
onScroll(event) {
|
|
157
|
+
flushSync(() => setScrollTop(event.currentTarget.scrollTop));
|
|
158
|
+
}
|
|
159
|
+
});
|
|
211
160
|
}
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
161
|
+
};
|
|
162
|
+
React.useLayoutEffect(() => {
|
|
163
|
+
if (open) {
|
|
164
|
+
selectTimeoutRef.current = setTimeout(() => {
|
|
165
|
+
allowSelectRef.current = true;
|
|
166
|
+
}, 300);
|
|
217
167
|
return () => {
|
|
218
|
-
|
|
219
|
-
floating2.removeEventListener("touchmove", handleWheel);
|
|
220
|
-
floating2.removeEventListener("touchend", onTouchEnd);
|
|
168
|
+
clearTimeout(selectTimeoutRef.current);
|
|
221
169
|
};
|
|
170
|
+
} else {
|
|
171
|
+
allowSelectRef.current = false;
|
|
172
|
+
allowMouseUpRef.current = true;
|
|
173
|
+
setInnerOffset(0);
|
|
174
|
+
setFallback(false);
|
|
175
|
+
setBlockSelection(false);
|
|
222
176
|
}
|
|
223
|
-
}, [open
|
|
224
|
-
React.useEffect(() => {
|
|
225
|
-
window.addEventListener("resize", update);
|
|
226
|
-
return () => {
|
|
227
|
-
window.removeEventListener("resize", update);
|
|
228
|
-
};
|
|
229
|
-
}, [update]);
|
|
177
|
+
}, [open]);
|
|
230
178
|
React.useLayoutEffect(() => {
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
const itemHeight = ((_a = listItemsRef.current[prevActiveIndex]) == null ? void 0 : _a.offsetHeight) ?? 0;
|
|
237
|
-
const floatingHeight = floating2.offsetHeight;
|
|
238
|
-
const top = item.offsetTop;
|
|
239
|
-
const bottom = top + itemHeight;
|
|
240
|
-
if (top < floating2.scrollTop + 20) {
|
|
241
|
-
const diff = floating2.scrollTop - top + 20;
|
|
242
|
-
floating2.scrollTop -= diff;
|
|
243
|
-
if (activeIndex != selectedIndex && activeIndex != null) {
|
|
244
|
-
increaseHeight(floating2, -diff);
|
|
245
|
-
}
|
|
246
|
-
} else if (bottom > floatingHeight + floating2.scrollTop - 20) {
|
|
247
|
-
const diff = bottom - floatingHeight - floating2.scrollTop + 20;
|
|
248
|
-
floating2.scrollTop += diff;
|
|
249
|
-
if (activeIndex != selectedIndex && activeIndex != null) {
|
|
250
|
-
floating2.scrollTop -= increaseHeight(floating2, diff) ?? 0;
|
|
251
|
-
}
|
|
252
|
-
}
|
|
179
|
+
function onPointerDown(e) {
|
|
180
|
+
var _a, _b, _c;
|
|
181
|
+
const target = e.target;
|
|
182
|
+
if (!((_a = refs.floating.current) == null ? void 0 : _a.contains(target)) && !((_b = upArrowRef.current) == null ? void 0 : _b.contains(target)) && !((_c = downArrowRef.current) == null ? void 0 : _c.contains(target))) {
|
|
183
|
+
setOpen(false);
|
|
253
184
|
}
|
|
254
185
|
}
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
increaseHeight
|
|
263
|
-
]);
|
|
186
|
+
if (open) {
|
|
187
|
+
document.addEventListener("pointerdown", onPointerDown);
|
|
188
|
+
return () => {
|
|
189
|
+
document.removeEventListener("pointerdown", onPointerDown);
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
}, [open, refs, setOpen]);
|
|
264
193
|
React.useLayoutEffect(() => {
|
|
265
194
|
var _a;
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
const item = listItemsRef.current[selectedIndex];
|
|
272
|
-
if (item) {
|
|
273
|
-
floating2.scrollTop = item.offsetTop - floating2.clientHeight + referenceRect.height;
|
|
195
|
+
if (open && controlledScrolling) {
|
|
196
|
+
requestAnimationFrame(() => {
|
|
197
|
+
var _a2;
|
|
198
|
+
if (activeIndex != null) {
|
|
199
|
+
(_a2 = listItemsRef.current[activeIndex]) == null ? void 0 : _a2.scrollIntoView({ block: "nearest" });
|
|
274
200
|
}
|
|
275
|
-
|
|
276
|
-
}
|
|
277
|
-
floating2.scrollTop = (_a = middlewareData.size) == null ? void 0 : _a.y;
|
|
278
|
-
const closeToBottom = ((visualViewport == null ? void 0 : visualViewport.height) ?? 0) + getVisualOffsetTop() - referenceRect.bottom < FALLBACK_THRESHOLD;
|
|
279
|
-
const closeToTop = referenceRect.top < FALLBACK_THRESHOLD;
|
|
280
|
-
if (floating2.offsetHeight < MIN_HEIGHT || closeToTop || closeToBottom) {
|
|
281
|
-
setMiddlewareType("fallback");
|
|
282
|
-
}
|
|
201
|
+
});
|
|
283
202
|
}
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
increaseHeight,
|
|
287
|
-
selectedIndex,
|
|
288
|
-
middlewareType,
|
|
289
|
-
refs.floating,
|
|
290
|
-
refs.reference,
|
|
291
|
-
middlewareData
|
|
292
|
-
]);
|
|
203
|
+
setScrollTop(((_a = refs.floating.current) == null ? void 0 : _a.scrollTop) ?? 0);
|
|
204
|
+
}, [open, refs, controlledScrolling, activeIndex]);
|
|
293
205
|
React.useLayoutEffect(() => {
|
|
294
|
-
if (open &&
|
|
206
|
+
if (open && fallback) {
|
|
295
207
|
requestAnimationFrame(() => {
|
|
296
208
|
var _a;
|
|
297
|
-
(
|
|
209
|
+
if (selectedIndex != null) {
|
|
210
|
+
(_a = listItemsRef.current[selectedIndex]) == null ? void 0 : _a.scrollIntoView({ block: "nearest" });
|
|
211
|
+
}
|
|
298
212
|
});
|
|
299
213
|
}
|
|
300
|
-
}, [
|
|
301
|
-
React.
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
setMiddlewareType("align");
|
|
307
|
-
setActiveIndex(null);
|
|
308
|
-
setControlledScrolling(false);
|
|
309
|
-
}
|
|
310
|
-
});
|
|
311
|
-
return () => cancelAnimationFrame(frame);
|
|
312
|
-
}, [open, setActiveIndex]);
|
|
214
|
+
}, [open, fallback, selectedIndex]);
|
|
215
|
+
React.useLayoutEffect(() => {
|
|
216
|
+
if (refs.floating.current && fallback) {
|
|
217
|
+
refs.floating.current.style.maxHeight = "";
|
|
218
|
+
}
|
|
219
|
+
}, [refs, fallback]);
|
|
313
220
|
return /* @__PURE__ */ React.createElement(SelectProvider, {
|
|
314
221
|
scope: __scopeSelect,
|
|
315
222
|
...selectContext,
|
|
316
|
-
|
|
223
|
+
setScrollTop,
|
|
224
|
+
setInnerOffset,
|
|
317
225
|
floatingRef,
|
|
318
226
|
setValueAtIndex: (index, value) => {
|
|
319
227
|
listContentRef.current[index] = value;
|
|
320
228
|
},
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
getReferenceProps() {
|
|
324
|
-
return interactions.getReferenceProps({
|
|
325
|
-
ref: reference,
|
|
326
|
-
className: "SelectTrigger",
|
|
327
|
-
onKeyDown(event) {
|
|
328
|
-
if (event.key === "Enter" || event.key === " " && !context.dataRef.current.typing) {
|
|
329
|
-
event.preventDefault();
|
|
330
|
-
setOpen(true);
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
});
|
|
334
|
-
},
|
|
335
|
-
getFloatingProps(props2) {
|
|
336
|
-
return interactions.getFloatingProps({
|
|
337
|
-
ref: floating,
|
|
338
|
-
className: "Select",
|
|
339
|
-
...props2,
|
|
340
|
-
style: {
|
|
341
|
-
position: strategy,
|
|
342
|
-
top: y ?? "",
|
|
343
|
-
left: x ?? "",
|
|
344
|
-
outline: 0,
|
|
345
|
-
listStyleType: "none",
|
|
346
|
-
scrollbarWidth: "none",
|
|
347
|
-
userSelect: "none",
|
|
348
|
-
...props2 == null ? void 0 : props2.style
|
|
349
|
-
},
|
|
350
|
-
onPointerEnter() {
|
|
351
|
-
setControlledScrolling(false);
|
|
352
|
-
},
|
|
353
|
-
onPointerMove() {
|
|
354
|
-
setControlledScrolling(false);
|
|
355
|
-
},
|
|
356
|
-
onKeyDown() {
|
|
357
|
-
setControlledScrolling(true);
|
|
358
|
-
},
|
|
359
|
-
onScroll(event) {
|
|
360
|
-
setScrollTop(event.currentTarget.scrollTop);
|
|
361
|
-
}
|
|
362
|
-
});
|
|
363
|
-
}
|
|
364
|
-
},
|
|
229
|
+
fallback,
|
|
230
|
+
interactions: interactionsContext,
|
|
365
231
|
floatingContext: context,
|
|
366
232
|
activeIndex,
|
|
367
233
|
canScrollDown: !!showDownArrow,
|
|
368
234
|
canScrollUp: !!showUpArrow,
|
|
369
235
|
controlledScrolling: true,
|
|
370
236
|
dataRef: context.dataRef,
|
|
371
|
-
listRef: listItemsRef
|
|
237
|
+
listRef: listItemsRef,
|
|
238
|
+
blockSelection,
|
|
239
|
+
allowMouseUpRef,
|
|
240
|
+
upArrowRef,
|
|
241
|
+
downArrowRef,
|
|
242
|
+
selectTimeoutRef,
|
|
243
|
+
allowSelectRef
|
|
372
244
|
}, children);
|
|
373
245
|
};
|
|
374
246
|
const userAgent = typeof navigator !== "undefined" && navigator.userAgent || "";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/SelectImpl.tsx"],
|
|
4
|
-
"sourcesContent": ["import {\n detectOverflow,\n flip,\n offset,\n size,\n useClick,\n useDismiss,\n useFloating,\n useInteractions,\n useListNavigation,\n useRole,\n useTypeahead,\n} from '@floating-ui/react-dom-interactions'\nimport { usePrevious } from '@radix-ui/react-use-previous'\nimport * as React from 'react'\n\nimport { FALLBACK_THRESHOLD, MIN_HEIGHT, SCROLL_ARROW_THRESHOLD, WINDOW_PADDING } from './constants'\nimport { SelectProvider, useSelectContext } from './context'\nimport { ScopedProps, SelectProps } from './types'\n\nexport type SelectImplProps = ScopedProps<SelectProps> & {\n activeIndexRef: any\n selectedIndexRef: any\n listContentRef: any\n}\n\n// TODO use id for focusing from label\nexport const SelectInlineImpl = (props: SelectImplProps) => {\n const {\n __scopeSelect,\n children,\n open = false,\n activeIndexRef,\n selectedIndexRef,\n listContentRef,\n } = props\n\n const selectContext = useSelectContext('SelectSheetImpl', __scopeSelect)\n const { setActiveIndex, setOpen, setSelectedIndex, selectedIndex, activeIndex, forceUpdate } =\n selectContext\n const [showArrows, setShowArrows] = React.useState(false)\n const [scrollTop, setScrollTop] = React.useState(0)\n const prevActiveIndex = usePrevious<number | null>(activeIndex)\n\n const listItemsRef = React.useRef<Array<HTMLElement | null>>([])\n\n const [controlledScrolling, setControlledScrolling] = React.useState(false)\n const [middlewareType, setMiddlewareType] = React.useState<'align' | 'fallback'>('align')\n\n // Wait for scroll position to settle before showing arrows to prevent\n // interference with pointer events.\n React.useEffect(() => {\n const frame = requestAnimationFrame(() => {\n setShowArrows(open)\n\n if (!open) {\n setScrollTop(0)\n setMiddlewareType('align')\n setActiveIndex(null)\n setControlledScrolling(false)\n }\n })\n return () => {\n cancelAnimationFrame(frame)\n }\n }, [open, setActiveIndex])\n\n function getFloatingPadding(floating: HTMLElement | null) {\n if (!floating) {\n return 0\n }\n return Number(getComputedStyle(floating).paddingLeft?.replace('px', ''))\n }\n\n const { x, y, reference, floating, strategy, context, refs, middlewareData, update } =\n useFloating({\n open,\n onOpenChange: setOpen,\n placement: 'bottom',\n middleware:\n middlewareType === 'align'\n ? [\n offset(({ rects }) => {\n const index = activeIndexRef.current ?? selectedIndexRef.current\n\n if (index == null) {\n return 0\n }\n\n const item = listItemsRef.current[index]\n\n if (item == null) {\n return 0\n }\n\n const offsetTop = item.offsetTop\n const itemHeight = item.offsetHeight\n const height = rects.reference.height\n\n return -offsetTop - height - (itemHeight - height) / 2\n }),\n // Custom `size` that can handle the opposite direction of the placement\n {\n name: 'size',\n async fn(args) {\n const {\n elements: { floating },\n rects: { reference },\n middlewareData,\n } = args\n\n const overflow = await detectOverflow(args, {\n padding: WINDOW_PADDING,\n })\n\n const top = Math.max(0, overflow.top)\n const bottom = Math.max(0, overflow.bottom)\n const nextY = args.y + top\n\n if (middlewareData.size?.skip) {\n return {\n y: nextY,\n data: {\n y: middlewareData.size.y,\n },\n }\n }\n\n Object.assign(floating.style, {\n maxHeight: `${floating.scrollHeight - Math.abs(top + bottom)}px`,\n minWidth: `${reference.width + getFloatingPadding(floating) * 2}px`,\n })\n\n return {\n y: nextY,\n data: {\n y: top,\n skip: true,\n },\n reset: {\n rects: true,\n },\n }\n },\n },\n ]\n : [\n offset(5),\n flip(),\n size({\n apply({ rects, availableHeight, elements }) {\n Object.assign(elements.floating.style, {\n width: `${rects.reference.width}px`,\n maxHeight: `${availableHeight}px`,\n })\n },\n padding: WINDOW_PADDING,\n }),\n ],\n })\n\n const floatingRef = refs.floating\n\n const showUpArrow = showArrows && scrollTop > SCROLL_ARROW_THRESHOLD\n const showDownArrow =\n showArrows &&\n floatingRef.current &&\n scrollTop <\n floatingRef.current.scrollHeight - floatingRef.current.clientHeight - SCROLL_ARROW_THRESHOLD\n\n const interactions = useInteractions([\n useClick(context, { pointerDown: true }),\n useRole(context, { role: 'listbox' }),\n useDismiss(context),\n useListNavigation(context, {\n listRef: listItemsRef,\n activeIndex,\n selectedIndex,\n onNavigate: setActiveIndex,\n }),\n useTypeahead(context, {\n listRef: listContentRef,\n onMatch: open ? setActiveIndex : setSelectedIndex,\n selectedIndex,\n activeIndex,\n }),\n ])\n\n const increaseHeight = React.useCallback(\n (floating: HTMLElement, amount = 0) => {\n if (middlewareType === 'fallback') {\n return\n }\n\n const currentMaxHeight = Number(floating.style.maxHeight.replace('px', ''))\n const currentTop = Number(floating.style.top.replace('px', ''))\n const rect = floating.getBoundingClientRect()\n const rectTop = rect.top\n const rectBottom = rect.bottom\n const viewportHeight = visualViewport?.height ?? 0\n const visualMaxHeight = viewportHeight - WINDOW_PADDING * 2\n\n if (\n amount < 0 &&\n selectedIndexRef.current != null &&\n Math.round(rectBottom) < Math.round(viewportHeight + getVisualOffsetTop() - WINDOW_PADDING)\n ) {\n floating.style.maxHeight = `${Math.min(visualMaxHeight, currentMaxHeight - amount)}px`\n }\n\n if (\n amount > 0 &&\n Math.round(rectTop) > Math.round(WINDOW_PADDING - getVisualOffsetTop()) &&\n floating.scrollHeight > floating.offsetHeight\n ) {\n const nextTop = Math.max(WINDOW_PADDING + getVisualOffsetTop(), currentTop - amount)\n\n const nextMaxHeight = Math.min(visualMaxHeight, currentMaxHeight + amount)\n\n Object.assign(floating.style, {\n maxHeight: `${nextMaxHeight}px`,\n top: `${nextTop}px`,\n })\n\n if (nextTop - WINDOW_PADDING > getVisualOffsetTop()) {\n floating.scrollTop -= nextMaxHeight - currentMaxHeight + getFloatingPadding(floating)\n }\n\n return currentTop - nextTop\n }\n },\n [middlewareType, selectedIndexRef]\n )\n\n const touchPageYRef = React.useRef<number | null>(null)\n\n const handleWheel = React.useCallback(\n (event: WheelEvent | TouchEvent) => {\n const pinching = event.ctrlKey\n\n const currentTarget = event.currentTarget as HTMLElement\n\n function isWheelEvent(event: any): event is WheelEvent {\n return typeof event.deltaY === 'number'\n }\n\n function isTouchEvent(event: any): event is TouchEvent {\n return event.touches != null\n }\n\n if (\n Math.abs(\n (currentTarget?.offsetHeight ?? 0) - ((visualViewport?.height ?? 0) - WINDOW_PADDING * 2)\n ) > 1 &&\n !pinching\n ) {\n event.preventDefault()\n } else if (isWheelEvent(event) && isFirefox) {\n // Firefox needs this to propagate scrolling\n // during momentum scrolling phase if the\n // height reached its maximum (at boundaries)\n currentTarget.scrollTop += event.deltaY\n }\n\n if (!pinching) {\n let delta = 5\n\n if (isTouchEvent(event)) {\n const currentPageY = touchPageYRef.current\n const pageY = event.touches[0]?.pageY\n\n if (pageY != null) {\n touchPageYRef.current = pageY\n\n if (currentPageY != null) {\n delta = currentPageY - pageY\n }\n }\n }\n\n increaseHeight(currentTarget, isWheelEvent(event) ? event.deltaY : delta)\n setScrollTop(currentTarget.scrollTop)\n // Ensure derived data (scroll arrows) is fresh\n forceUpdate()\n }\n },\n [forceUpdate, increaseHeight]\n )\n\n // Handle `onWheel` event in an effect to remove the `passive` option so we\n // can .preventDefault() it\n React.useEffect(() => {\n function onTouchEnd() {\n touchPageYRef.current = null\n }\n\n const floating = floatingRef.current\n if (open && floating && middlewareType === 'align') {\n floating.addEventListener('wheel', handleWheel)\n floating.addEventListener('touchmove', handleWheel)\n floating.addEventListener('touchend', onTouchEnd, { passive: true })\n return () => {\n floating.removeEventListener('wheel', handleWheel)\n floating.removeEventListener('touchmove', handleWheel)\n floating.removeEventListener('touchend', onTouchEnd)\n }\n }\n }, [open, floatingRef, handleWheel, middlewareType])\n\n // Ensure the menu remains attached to the reference element when resizing.\n React.useEffect(() => {\n window.addEventListener('resize', update)\n return () => {\n window.removeEventListener('resize', update)\n }\n }, [update])\n\n // Scroll the active or selected item into view when in `controlledScrolling`\n // mode (i.e. arrow key nav).\n React.useLayoutEffect(() => {\n const floating = floatingRef.current\n\n if (open && controlledScrolling && floating) {\n const item =\n activeIndex != null\n ? listItemsRef.current[activeIndex]\n : selectedIndex != null\n ? listItemsRef.current[selectedIndex]\n : null\n\n if (item && prevActiveIndex != null) {\n const itemHeight = listItemsRef.current[prevActiveIndex]?.offsetHeight ?? 0\n\n const floatingHeight = floating.offsetHeight\n const top = item.offsetTop\n const bottom = top + itemHeight\n\n if (top < floating.scrollTop + 20) {\n const diff = floating.scrollTop - top + 20\n floating.scrollTop -= diff\n\n if (activeIndex != selectedIndex && activeIndex != null) {\n increaseHeight(floating, -diff)\n }\n } else if (bottom > floatingHeight + floating.scrollTop - 20) {\n const diff = bottom - floatingHeight - floating.scrollTop + 20\n\n floating.scrollTop += diff\n\n if (activeIndex != selectedIndex && activeIndex != null) {\n floating.scrollTop -= increaseHeight(floating, diff) ?? 0\n }\n }\n }\n }\n }, [\n open,\n controlledScrolling,\n prevActiveIndex,\n activeIndex,\n selectedIndex,\n floatingRef,\n increaseHeight,\n ])\n\n // Sync the height and the scrollTop values and device whether to use fallback\n // positioning.\n React.useLayoutEffect(() => {\n const floating = refs.floating.current\n const reference = refs.reference.current\n\n if (open && floating && reference && floating.offsetHeight < floating.scrollHeight) {\n const referenceRect = reference.getBoundingClientRect()\n\n if (middlewareType === 'fallback') {\n const item = listItemsRef.current[selectedIndex]\n if (item) {\n floating.scrollTop = item.offsetTop - floating.clientHeight + referenceRect.height\n }\n return\n }\n\n floating.scrollTop = middlewareData.size?.y\n\n const closeToBottom =\n (visualViewport?.height ?? 0) + getVisualOffsetTop() - referenceRect.bottom <\n FALLBACK_THRESHOLD\n const closeToTop = referenceRect.top < FALLBACK_THRESHOLD\n\n if (floating.offsetHeight < MIN_HEIGHT || closeToTop || closeToBottom) {\n setMiddlewareType('fallback')\n }\n }\n }, [\n open,\n increaseHeight,\n selectedIndex,\n middlewareType,\n refs.floating,\n refs.reference,\n // Always re-run this effect when the position has been computed so the\n // .scrollTop change works with fresh sizing.\n middlewareData,\n ])\n\n React.useLayoutEffect(() => {\n if (open && selectedIndex != null) {\n requestAnimationFrame(() => {\n listItemsRef.current[selectedIndex]?.focus({ preventScroll: true })\n })\n }\n }, [listItemsRef, selectedIndex, open])\n\n // Wait for scroll position to settle before showing arrows to prevent\n // interference with pointer events.\n React.useEffect(() => {\n const frame = requestAnimationFrame(() => {\n setShowArrows(open)\n\n if (!open) {\n setScrollTop(0)\n setMiddlewareType('align')\n setActiveIndex(null)\n setControlledScrolling(false)\n }\n })\n return () => cancelAnimationFrame(frame)\n }, [open, setActiveIndex])\n\n // We set this to true by default so that events bubble to forms without JS (SSR)\n // const isFormControl = trigger ? Boolean(trigger.closest('form')) : true\n // const [bubbleSelect, setBubbleSelect] = React.useState<HTMLSelectElement | null>(null)\n // const triggerPointerDownPosRef = React.useRef<{ x: number; y: number } | null>(null)\n return (\n <SelectProvider\n scope={__scopeSelect}\n {...(selectContext as Required<typeof selectContext>)}\n increaseHeight={increaseHeight}\n floatingRef={floatingRef}\n setValueAtIndex={(index, value) => {\n listContentRef.current[index] = value\n }}\n interactions={{\n ...interactions,\n getReferenceProps() {\n return interactions.getReferenceProps({\n ref: reference,\n className: 'SelectTrigger',\n onKeyDown(event) {\n if (event.key === 'Enter' || (event.key === ' ' && !context.dataRef.current.typing)) {\n event.preventDefault()\n setOpen(true)\n }\n },\n })\n },\n getFloatingProps(props) {\n return interactions.getFloatingProps({\n ref: floating,\n className: 'Select',\n ...props,\n style: {\n position: strategy,\n top: y ?? '',\n left: x ?? '',\n outline: 0,\n listStyleType: 'none',\n scrollbarWidth: 'none',\n userSelect: 'none',\n ...props?.style,\n },\n onPointerEnter() {\n setControlledScrolling(false)\n },\n onPointerMove() {\n setControlledScrolling(false)\n },\n onKeyDown() {\n setControlledScrolling(true)\n },\n onScroll(event) {\n setScrollTop(event.currentTarget.scrollTop)\n },\n })\n },\n }}\n floatingContext={context}\n activeIndex={activeIndex}\n canScrollDown={!!showDownArrow}\n canScrollUp={!!showUpArrow}\n controlledScrolling\n dataRef={context.dataRef}\n listRef={listItemsRef}\n >\n {children}\n {/* {isFormControl ? (\n <BubbleSelect\n ref={setBubbleSelect}\n aria-hidden\n tabIndex={-1}\n name={name}\n autoComplete={autoComplete}\n value={value}\n // enable form autofill\n onChange={(event) => setValue(event.target.value)}\n />\n ) : null} */}\n </SelectProvider>\n )\n}\n\n// Cross browser fixes for pinch-zooming/backdrop-filter \uD83D\uDE44\nconst userAgent = (typeof navigator !== 'undefined' && navigator.userAgent) || ''\nconst isFirefox = userAgent.toLowerCase().includes('firefox')\n\nfunction getVisualOffsetTop() {\n return !/^((?!chrome|android).)*safari/i.test(userAgent) ? visualViewport?.offsetTop ?? 0 : 0\n}\n"],
|
|
5
|
-
"mappings": "AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;
|
|
4
|
+
"sourcesContent": ["import {\n SideObject,\n detectOverflow,\n flip,\n inner,\n offset,\n shift,\n size,\n useClick,\n useDismiss,\n useFloating,\n useInnerOffset,\n useInteractions,\n useListNavigation,\n useRole,\n useTypeahead,\n} from '@floating-ui/react-dom-interactions'\nimport { usePrevious } from '@radix-ui/react-use-previous'\nimport { useForceUpdate, useIsTouchDevice } from '@tamagui/core'\nimport * as React from 'react'\nimport { flushSync } from 'react-dom'\n\nimport { FALLBACK_THRESHOLD, MIN_HEIGHT, SCROLL_ARROW_THRESHOLD, WINDOW_PADDING } from './constants'\nimport { SelectProvider, useSelectContext } from './context'\nimport { ScopedProps, SelectProps } from './types'\n\nexport type SelectImplProps = ScopedProps<SelectProps> & {\n activeIndexRef: any\n selectedIndexRef: any\n listContentRef: any\n}\n\n// TODO use id for focusing from label\nexport const SelectInlineImpl = (props: SelectImplProps) => {\n const { __scopeSelect, children, open = false, selectedIndexRef, listContentRef } = props\n\n const selectContext = useSelectContext('SelectSheetImpl', __scopeSelect)\n const { setActiveIndex, setOpen, setSelectedIndex, selectedIndex, activeIndex, forceUpdate } =\n selectContext\n const [scrollTop, setScrollTop] = React.useState(0)\n const touch = useIsTouchDevice()\n\n const listItemsRef = React.useRef<Array<HTMLElement | null>>([])\n const overflowRef = React.useRef<null | SideObject>(null)\n const upArrowRef = React.useRef<HTMLDivElement | null>(null)\n const downArrowRef = React.useRef<HTMLDivElement | null>(null)\n const allowSelectRef = React.useRef(false)\n const allowMouseUpRef = React.useRef(true)\n const selectTimeoutRef = React.useRef<any>()\n\n const [controlledScrolling, setControlledScrolling] = React.useState(false)\n const [fallback, setFallback] = React.useState(false)\n const [innerOffset, setInnerOffset] = React.useState(0)\n const [blockSelection, setBlockSelection] = React.useState(false)\n const floatingStyle = React.useRef({})\n\n // Wait for scroll position to settle before showing arrows to prevent\n // interference with pointer events.\n React.useEffect(() => {\n const frame = requestAnimationFrame(() => {\n if (!open) {\n setScrollTop(0)\n setFallback(false)\n setActiveIndex(null)\n setControlledScrolling(false)\n }\n })\n return () => {\n cancelAnimationFrame(frame)\n }\n }, [open, setActiveIndex])\n\n const updateFloatingSize = size({\n apply({\n availableHeight,\n rects: {\n reference: { width },\n },\n }) {\n floatingStyle.current = {\n width: width,\n maxHeight: availableHeight,\n }\n },\n padding: WINDOW_PADDING,\n })\n\n const { x, y, reference, floating, strategy, context, refs } = useFloating({\n open,\n onOpenChange: setOpen,\n placement: 'bottom-start',\n middleware: fallback\n ? [\n offset(5),\n ...[\n touch\n ? shift({ crossAxis: true, padding: WINDOW_PADDING })\n : flip({ padding: WINDOW_PADDING }),\n ],\n updateFloatingSize,\n ]\n : [\n inner({\n listRef: listItemsRef,\n overflowRef,\n index: selectedIndex,\n offset: innerOffset,\n onFallbackChange: setFallback,\n padding: 10,\n minItemsVisible: touch ? 10 : 4,\n referenceOverflowThreshold: 20,\n }),\n updateFloatingSize,\n ],\n })\n\n const floatingRef = refs.floating\n\n const showUpArrow = open && scrollTop > SCROLL_ARROW_THRESHOLD\n const showDownArrow =\n open &&\n floatingRef.current &&\n scrollTop <\n floatingRef.current.scrollHeight - floatingRef.current.clientHeight - SCROLL_ARROW_THRESHOLD\n\n const interactions = useInteractions([\n useClick(context, { pointerDown: true }),\n useDismiss(context, { outsidePointerDown: false }),\n useRole(context, { role: 'listbox' }),\n useInnerOffset(context, {\n enabled: !fallback,\n onChange: setInnerOffset,\n overflowRef,\n }),\n useListNavigation(context, {\n listRef: listItemsRef,\n activeIndex,\n selectedIndex,\n onNavigate: setActiveIndex,\n }),\n useTypeahead(context, {\n listRef: listContentRef,\n onMatch: open ? setActiveIndex : setSelectedIndex,\n selectedIndex,\n activeIndex,\n }),\n ])\n\n const interactionsContext = {\n ...interactions,\n getReferenceProps() {\n return interactions.getReferenceProps({\n ref: reference,\n className: 'SelectTrigger',\n onKeyDown(event) {\n if (event.key === 'Enter' || (event.key === ' ' && !context.dataRef.current.typing)) {\n event.preventDefault()\n setOpen(true)\n }\n },\n })\n },\n getFloatingProps(props) {\n return interactions.getFloatingProps({\n ref: floating,\n className: 'Select',\n ...props,\n style: {\n position: strategy,\n top: y ?? '',\n left: x ?? '',\n outline: 0,\n listStyleType: 'none',\n scrollbarWidth: 'none',\n ...floatingStyle.current,\n ...props?.style,\n },\n onPointerEnter() {\n setControlledScrolling(false)\n },\n onPointerMove() {\n setControlledScrolling(false)\n },\n onKeyDown() {\n setControlledScrolling(true)\n },\n onContextMenu(e) {\n e.preventDefault()\n },\n onScroll(event) {\n // In React 18, the ScrollArrows need to synchronously know this value to prevent\n // painting at the wrong time.\n flushSync(() => setScrollTop(event.currentTarget.scrollTop))\n },\n })\n },\n }\n\n // effects\n\n React.useLayoutEffect(() => {\n if (open) {\n selectTimeoutRef.current = setTimeout(() => {\n allowSelectRef.current = true\n }, 300)\n\n return () => {\n clearTimeout(selectTimeoutRef.current)\n }\n } else {\n allowSelectRef.current = false\n allowMouseUpRef.current = true\n setInnerOffset(0)\n setFallback(false)\n setBlockSelection(false)\n }\n }, [open])\n\n // Replacement for `useDismiss` as the arrows are outside of the floating\n // element DOM tree.\n React.useLayoutEffect(() => {\n function onPointerDown(e: PointerEvent) {\n const target = e.target as Node\n if (\n !refs.floating.current?.contains(target) &&\n !upArrowRef.current?.contains(target) &&\n !downArrowRef.current?.contains(target)\n ) {\n setOpen(false)\n }\n }\n\n if (open) {\n document.addEventListener('pointerdown', onPointerDown)\n return () => {\n document.removeEventListener('pointerdown', onPointerDown)\n }\n }\n }, [open, refs, setOpen])\n\n // Scroll the `activeIndex` item into view only in \"controlledScrolling\"\n // (keyboard nav) mode.\n React.useLayoutEffect(() => {\n if (open && controlledScrolling) {\n requestAnimationFrame(() => {\n if (activeIndex != null) {\n listItemsRef.current[activeIndex]?.scrollIntoView({ block: 'nearest' })\n }\n })\n }\n\n setScrollTop(refs.floating.current?.scrollTop ?? 0)\n }, [open, refs, controlledScrolling, activeIndex])\n\n // Scroll the `selectedIndex` into view upon opening the floating element.\n React.useLayoutEffect(() => {\n if (open && fallback) {\n requestAnimationFrame(() => {\n if (selectedIndex != null) {\n listItemsRef.current[selectedIndex]?.scrollIntoView({ block: 'nearest' })\n }\n })\n }\n }, [open, fallback, selectedIndex])\n\n // Unset the height limiting for fallback mode. This gets executed prior to\n // the positioning call.\n React.useLayoutEffect(() => {\n if (refs.floating.current && fallback) {\n refs.floating.current.style.maxHeight = ''\n }\n }, [refs, fallback])\n\n // We set this to true by default so that events bubble to forms without JS (SSR)\n // const isFormControl = trigger ? Boolean(trigger.closest('form')) : true\n // const [bubbleSelect, setBubbleSelect] = React.useState<HTMLSelectElement | null>(null)\n // const triggerPointerDownPosRef = React.useRef<{ x: number; y: number } | null>(null)\n\n return (\n <SelectProvider\n scope={__scopeSelect}\n {...(selectContext as Required<typeof selectContext>)}\n setScrollTop={setScrollTop}\n setInnerOffset={setInnerOffset}\n floatingRef={floatingRef}\n setValueAtIndex={(index, value) => {\n listContentRef.current[index] = value\n }}\n fallback={fallback}\n interactions={interactionsContext}\n floatingContext={context}\n activeIndex={activeIndex}\n canScrollDown={!!showDownArrow}\n canScrollUp={!!showUpArrow}\n controlledScrolling\n dataRef={context.dataRef}\n listRef={listItemsRef}\n blockSelection={blockSelection}\n allowMouseUpRef={allowMouseUpRef}\n upArrowRef={upArrowRef}\n downArrowRef={downArrowRef}\n selectTimeoutRef={selectTimeoutRef}\n allowSelectRef={allowSelectRef}\n >\n {children}\n {/* {isFormControl ? (\n <BubbleSelect\n ref={setBubbleSelect}\n aria-hidden\n tabIndex={-1}\n name={name}\n autoComplete={autoComplete}\n value={value}\n // enable form autofill\n onChange={(event) => setValue(event.target.value)}\n />\n ) : null} */}\n </SelectProvider>\n )\n}\n\n// Cross browser fixes for pinch-zooming/backdrop-filter \uD83D\uDE44\nconst userAgent = (typeof navigator !== 'undefined' && navigator.userAgent) || ''\nconst isFirefox = userAgent.toLowerCase().includes('firefox')\n\nfunction getVisualOffsetTop() {\n return !/^((?!chrome|android).)*safari/i.test(userAgent) ? visualViewport?.offsetTop ?? 0 : 0\n}\n"],
|
|
5
|
+
"mappings": "AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAkBA;AACA;AACA;AAEA;AACA;AAUO,MAAM,mBAAmB,CAAC,UAA2B;AAC1D,QAAM,EAAE,eAAe,UAAU,OAAO,OAAO,kBAAkB,mBAAmB;AAEpF,QAAM,gBAAgB,iBAAiB,mBAAmB,aAAa;AACvE,QAAM,EAAE,gBAAgB,SAAS,kBAAkB,eAAe,aAAa,gBAC7E;AACF,QAAM,CAAC,WAAW,gBAAgB,MAAM,SAAS,CAAC;AAClD,QAAM,QAAQ,iBAAiB;AAE/B,QAAM,eAAe,MAAM,OAAkC,CAAC,CAAC;AAC/D,QAAM,cAAc,MAAM,OAA0B,IAAI;AACxD,QAAM,aAAa,MAAM,OAA8B,IAAI;AAC3D,QAAM,eAAe,MAAM,OAA8B,IAAI;AAC7D,QAAM,iBAAiB,MAAM,OAAO,KAAK;AACzC,QAAM,kBAAkB,MAAM,OAAO,IAAI;AACzC,QAAM,mBAAmB,MAAM,OAAY;AAE3C,QAAM,CAAC,qBAAqB,0BAA0B,MAAM,SAAS,KAAK;AAC1E,QAAM,CAAC,UAAU,eAAe,MAAM,SAAS,KAAK;AACpD,QAAM,CAAC,aAAa,kBAAkB,MAAM,SAAS,CAAC;AACtD,QAAM,CAAC,gBAAgB,qBAAqB,MAAM,SAAS,KAAK;AAChE,QAAM,gBAAgB,MAAM,OAAO,CAAC,CAAC;AAIrC,QAAM,UAAU,MAAM;AACpB,UAAM,QAAQ,sBAAsB,MAAM;AACxC,UAAI,CAAC,MAAM;A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