@tamagui/select 1.114.4 → 1.115.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/BubbleSelect.cjs +45 -0
- package/dist/cjs/Select.cjs +398 -0
- package/dist/cjs/SelectContent.cjs +82 -0
- package/dist/cjs/SelectContent.native.cjs +28 -0
- package/dist/cjs/SelectContent.native.cjs.map +6 -0
- package/dist/cjs/SelectImpl.cjs +272 -0
- package/dist/cjs/SelectImpl.native.cjs +29 -0
- package/dist/cjs/SelectImpl.native.cjs.map +6 -0
- package/dist/cjs/SelectItem.cjs +158 -0
- package/dist/cjs/SelectItemText.cjs +89 -0
- package/dist/cjs/SelectScrollButton.cjs +136 -0
- package/dist/cjs/SelectScrollButton.native.cjs +28 -0
- package/dist/cjs/SelectScrollButton.native.cjs.map +6 -0
- package/dist/cjs/SelectTrigger.cjs +99 -0
- package/dist/cjs/SelectViewport.cjs +135 -0
- package/dist/cjs/SelectViewport.native.cjs +69 -0
- package/dist/cjs/SelectViewport.native.cjs.map +6 -0
- package/dist/cjs/constants.cjs +38 -0
- package/dist/cjs/context.cjs +55 -0
- package/dist/cjs/index.cjs +19 -0
- package/dist/cjs/types.cjs +16 -0
- package/dist/cjs/useSelectBreakpointActive.cjs +35 -0
- package/package.json +25 -24
- package/dist/cjs/BubbleSelect.js +0 -34
- package/dist/cjs/Select.js +0 -328
- package/dist/cjs/SelectContent.js +0 -45
- package/dist/cjs/SelectImpl.js +0 -224
- package/dist/cjs/SelectItem.js +0 -142
- package/dist/cjs/SelectItemText.js +0 -62
- package/dist/cjs/SelectScrollButton.js +0 -105
- package/dist/cjs/SelectTrigger.js +0 -84
- package/dist/cjs/SelectViewport.js +0 -111
- package/dist/cjs/constants.js +0 -27
- package/dist/cjs/context.js +0 -35
- package/dist/cjs/index.js +0 -16
- package/dist/cjs/types.js +0 -14
- package/dist/cjs/useSelectBreakpointActive.js +0 -29
- /package/dist/cjs/{BubbleSelect.js.map → BubbleSelect.cjs.map} +0 -0
- /package/dist/cjs/{Select.js.map → Select.cjs.map} +0 -0
- /package/dist/cjs/{SelectContent.js.map → SelectContent.cjs.map} +0 -0
- /package/dist/cjs/{SelectImpl.js.map → SelectImpl.cjs.map} +0 -0
- /package/dist/cjs/{SelectItem.js.map → SelectItem.cjs.map} +0 -0
- /package/dist/cjs/{SelectItemText.js.map → SelectItemText.cjs.map} +0 -0
- /package/dist/cjs/{SelectScrollButton.js.map → SelectScrollButton.cjs.map} +0 -0
- /package/dist/cjs/{SelectTrigger.js.map → SelectTrigger.cjs.map} +0 -0
- /package/dist/cjs/{SelectViewport.js.map → SelectViewport.cjs.map} +0 -0
- /package/dist/cjs/{constants.js.map → constants.cjs.map} +0 -0
- /package/dist/cjs/{context.js.map → context.cjs.map} +0 -0
- /package/dist/cjs/{index.js.map → index.cjs.map} +0 -0
- /package/dist/cjs/{types.js.map → types.cjs.map} +0 -0
- /package/dist/cjs/{useSelectBreakpointActive.js.map → useSelectBreakpointActive.cjs.map} +0 -0
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf,
|
|
6
|
+
__hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all) __defProp(target, name, {
|
|
9
|
+
get: all[name],
|
|
10
|
+
enumerable: !0
|
|
11
|
+
});
|
|
12
|
+
},
|
|
13
|
+
__copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
|
|
15
|
+
get: () => from[key],
|
|
16
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
17
|
+
});
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
26
|
+
value: mod,
|
|
27
|
+
enumerable: !0
|
|
28
|
+
}) : target, mod)),
|
|
29
|
+
__toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
30
|
+
value: !0
|
|
31
|
+
}), mod);
|
|
32
|
+
var SelectImpl_exports = {};
|
|
33
|
+
__export(SelectImpl_exports, {
|
|
34
|
+
SelectInlineImpl: () => SelectInlineImpl
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(SelectImpl_exports);
|
|
37
|
+
var import_react = require("@floating-ui/react"),
|
|
38
|
+
import_constants = require("@tamagui/constants"),
|
|
39
|
+
import_core = require("@tamagui/core"),
|
|
40
|
+
React = __toESM(require("react")),
|
|
41
|
+
import_react_dom = require("react-dom"),
|
|
42
|
+
import_constants2 = require("./constants.cjs"),
|
|
43
|
+
import_context = require("./context.cjs"),
|
|
44
|
+
import_jsx_runtime = require("react/jsx-runtime");
|
|
45
|
+
const SelectInlineImpl = props => {
|
|
46
|
+
const {
|
|
47
|
+
__scopeSelect,
|
|
48
|
+
children,
|
|
49
|
+
open = !1,
|
|
50
|
+
selectedIndexRef,
|
|
51
|
+
listContentRef
|
|
52
|
+
} = props,
|
|
53
|
+
selectContext = (0, import_context.useSelectContext)("SelectSheetImpl", __scopeSelect),
|
|
54
|
+
selectItemParentContext = (0, import_context.useSelectItemParentContext)("SelectSheetImpl", __scopeSelect),
|
|
55
|
+
{
|
|
56
|
+
setActiveIndex,
|
|
57
|
+
selectedIndex,
|
|
58
|
+
activeIndex,
|
|
59
|
+
forceUpdate
|
|
60
|
+
} = selectContext,
|
|
61
|
+
{
|
|
62
|
+
setOpen,
|
|
63
|
+
setSelectedIndex
|
|
64
|
+
} = selectItemParentContext,
|
|
65
|
+
[scrollTop, setScrollTop] = React.useState(0),
|
|
66
|
+
touch = (0, import_core.useIsTouchDevice)(),
|
|
67
|
+
listItemsRef = React.useRef([]),
|
|
68
|
+
overflowRef = React.useRef(null),
|
|
69
|
+
upArrowRef = React.useRef(null),
|
|
70
|
+
downArrowRef = React.useRef(null),
|
|
71
|
+
allowSelectRef = React.useRef(!1),
|
|
72
|
+
allowMouseUpRef = React.useRef(!0),
|
|
73
|
+
selectTimeoutRef = React.useRef(),
|
|
74
|
+
state = React.useRef({
|
|
75
|
+
isMouseOutside: !1,
|
|
76
|
+
isTyping: !1
|
|
77
|
+
}),
|
|
78
|
+
[controlledScrolling, setControlledScrolling] = React.useState(!1),
|
|
79
|
+
[fallback, setFallback] = React.useState(!1),
|
|
80
|
+
[innerOffset, setInnerOffset] = React.useState(0),
|
|
81
|
+
[blockSelection, setBlockSelection] = React.useState(!1),
|
|
82
|
+
floatingStyle = React.useRef({});
|
|
83
|
+
(0, import_constants.useIsomorphicLayoutEffect)(() => {
|
|
84
|
+
queueMicrotask(() => {
|
|
85
|
+
open || (setScrollTop(0), setFallback(!1), setActiveIndex(null), setControlledScrolling(!1));
|
|
86
|
+
});
|
|
87
|
+
}, [open, setActiveIndex]), import_constants.isWeb && import_constants.isClient && (0, import_constants.useIsomorphicLayoutEffect)(() => {
|
|
88
|
+
if (!open) return;
|
|
89
|
+
const mouseUp = e => {
|
|
90
|
+
state.current.isMouseOutside && setOpen(!1);
|
|
91
|
+
};
|
|
92
|
+
return document.addEventListener("mouseup", mouseUp), () => {
|
|
93
|
+
document.removeEventListener("mouseup", mouseUp);
|
|
94
|
+
};
|
|
95
|
+
}, [open]);
|
|
96
|
+
const {
|
|
97
|
+
x,
|
|
98
|
+
y,
|
|
99
|
+
strategy,
|
|
100
|
+
context,
|
|
101
|
+
refs,
|
|
102
|
+
update
|
|
103
|
+
} = (0, import_react.useFloating)({
|
|
104
|
+
open,
|
|
105
|
+
onOpenChange: setOpen,
|
|
106
|
+
placement: "bottom-start",
|
|
107
|
+
whileElementsMounted: import_react.autoUpdate,
|
|
108
|
+
// biome-ignore lint/correctness/noConstantCondition: <explanation>
|
|
109
|
+
middleware: [(0, import_react.size)({
|
|
110
|
+
apply({
|
|
111
|
+
rects: {
|
|
112
|
+
reference: {
|
|
113
|
+
width
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}) {
|
|
117
|
+
Object.assign(floatingStyle.current, {
|
|
118
|
+
minWidth: width + 8
|
|
119
|
+
}), refs.floating.current && Object.assign(refs.floating.current.style, floatingStyle.current);
|
|
120
|
+
}
|
|
121
|
+
}), (0, import_react.inner)({
|
|
122
|
+
listRef: listItemsRef,
|
|
123
|
+
overflowRef,
|
|
124
|
+
index: selectedIndex,
|
|
125
|
+
offset: innerOffset,
|
|
126
|
+
onFallbackChange: setFallback,
|
|
127
|
+
padding: 10,
|
|
128
|
+
minItemsVisible: touch ? 10 : 4,
|
|
129
|
+
referenceOverflowThreshold: 20
|
|
130
|
+
}), (0, import_react.offset)({
|
|
131
|
+
crossAxis: -5
|
|
132
|
+
})]
|
|
133
|
+
}),
|
|
134
|
+
floatingRef = refs.floating,
|
|
135
|
+
showUpArrow = open && scrollTop > import_constants2.SCROLL_ARROW_THRESHOLD,
|
|
136
|
+
showDownArrow = open && floatingRef.current && scrollTop < floatingRef.current.scrollHeight - floatingRef.current.clientHeight - import_constants2.SCROLL_ARROW_THRESHOLD,
|
|
137
|
+
isScrollable = showDownArrow || showUpArrow;
|
|
138
|
+
(0, import_constants.useIsomorphicLayoutEffect)(() => (window.addEventListener("resize", update), open && update(), () => window.removeEventListener("resize", update)), [update, open]);
|
|
139
|
+
const onMatch = (0, import_core.useEvent)(index => (open ? setActiveIndex : setSelectedIndex)(index)),
|
|
140
|
+
interactionsProps = [(0, import_react.useClick)(context, {
|
|
141
|
+
event: "mousedown",
|
|
142
|
+
keyboardHandlers: !1
|
|
143
|
+
}), (0, import_react.useDismiss)(context, {
|
|
144
|
+
outsidePress: !1
|
|
145
|
+
}), (0, import_react.useRole)(context, {
|
|
146
|
+
role: "listbox"
|
|
147
|
+
}), (0, import_react.useInnerOffset)(context, {
|
|
148
|
+
enabled: !fallback && isScrollable,
|
|
149
|
+
onChange: setInnerOffset,
|
|
150
|
+
overflowRef,
|
|
151
|
+
scrollRef: refs.floating
|
|
152
|
+
}), (0, import_react.useListNavigation)(context, {
|
|
153
|
+
listRef: listItemsRef,
|
|
154
|
+
activeIndex: activeIndex || 0,
|
|
155
|
+
selectedIndex,
|
|
156
|
+
onNavigate: setActiveIndex,
|
|
157
|
+
scrollItemIntoView: !1
|
|
158
|
+
}), (0, import_react.useTypeahead)(context, {
|
|
159
|
+
listRef: listContentRef,
|
|
160
|
+
onMatch,
|
|
161
|
+
selectedIndex,
|
|
162
|
+
activeIndex,
|
|
163
|
+
onTypingChange: e => {
|
|
164
|
+
state.current.isTyping = e;
|
|
165
|
+
}
|
|
166
|
+
})],
|
|
167
|
+
interactions = (0, import_react.useInteractions)(
|
|
168
|
+
// unfortunately these memos will just always break due to floating-ui context always changing :/
|
|
169
|
+
React.useMemo(() => interactionsProps, interactionsProps)),
|
|
170
|
+
interactionsContext = React.useMemo(() => ({
|
|
171
|
+
...interactions,
|
|
172
|
+
getReferenceProps() {
|
|
173
|
+
return interactions.getReferenceProps({
|
|
174
|
+
ref: refs.reference,
|
|
175
|
+
className: "SelectTrigger",
|
|
176
|
+
onKeyDown(event) {
|
|
177
|
+
(event.key === "Enter" || event.code === "Space" || event.key === " " && !state.current.isTyping) && (event.preventDefault(), setOpen(!0));
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
},
|
|
181
|
+
getFloatingProps(props2) {
|
|
182
|
+
return interactions.getFloatingProps({
|
|
183
|
+
ref: refs.floating,
|
|
184
|
+
className: "Select",
|
|
185
|
+
...props2,
|
|
186
|
+
style: {
|
|
187
|
+
position: strategy,
|
|
188
|
+
top: y ?? "",
|
|
189
|
+
left: x ?? "",
|
|
190
|
+
outline: 0,
|
|
191
|
+
scrollbarWidth: "none",
|
|
192
|
+
...floatingStyle.current,
|
|
193
|
+
...props2?.style
|
|
194
|
+
},
|
|
195
|
+
onPointerEnter() {
|
|
196
|
+
setControlledScrolling(!1), state.current.isMouseOutside = !1;
|
|
197
|
+
},
|
|
198
|
+
onPointerLeave() {
|
|
199
|
+
state.current.isMouseOutside = !0;
|
|
200
|
+
},
|
|
201
|
+
onPointerMove() {
|
|
202
|
+
state.current.isMouseOutside = !1, setControlledScrolling(!1);
|
|
203
|
+
},
|
|
204
|
+
onKeyDown() {
|
|
205
|
+
setControlledScrolling(!0);
|
|
206
|
+
},
|
|
207
|
+
onContextMenu(e) {
|
|
208
|
+
e.preventDefault();
|
|
209
|
+
},
|
|
210
|
+
onScroll(event) {
|
|
211
|
+
(0, import_react_dom.flushSync)(() => {
|
|
212
|
+
setScrollTop(event.currentTarget.scrollTop);
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
}), [refs.reference.current, x, y, refs.floating.current, interactions]);
|
|
218
|
+
return (0, import_constants.useIsomorphicLayoutEffect)(() => {
|
|
219
|
+
if (open) return selectTimeoutRef.current = setTimeout(() => {
|
|
220
|
+
allowSelectRef.current = !0;
|
|
221
|
+
}, 300), () => {
|
|
222
|
+
clearTimeout(selectTimeoutRef.current);
|
|
223
|
+
};
|
|
224
|
+
allowSelectRef.current = !1, allowMouseUpRef.current = !0, setInnerOffset(0), setFallback(!1), setBlockSelection(!1);
|
|
225
|
+
}, [open]), (0, import_constants.useIsomorphicLayoutEffect)(() => {
|
|
226
|
+
!open && state.current.isMouseOutside && (state.current.isMouseOutside = !1);
|
|
227
|
+
}, [open]), (0, import_constants.useIsomorphicLayoutEffect)(() => {
|
|
228
|
+
function onPointerDown(e) {
|
|
229
|
+
const target = e.target;
|
|
230
|
+
refs.floating.current?.contains(target) || upArrowRef.current?.contains(target) || downArrowRef.current?.contains(target) || (setOpen(!1), setControlledScrolling(!1));
|
|
231
|
+
}
|
|
232
|
+
if (open) return document.addEventListener("pointerdown", onPointerDown), () => {
|
|
233
|
+
document.removeEventListener("pointerdown", onPointerDown);
|
|
234
|
+
};
|
|
235
|
+
}, [open, refs, setOpen]), React.useEffect(() => {
|
|
236
|
+
open && controlledScrolling && activeIndex != null && listItemsRef.current[activeIndex]?.scrollIntoView({
|
|
237
|
+
block: "nearest"
|
|
238
|
+
}), setScrollTop(refs.floating.current?.scrollTop ?? 0);
|
|
239
|
+
}, [open, refs, controlledScrolling, activeIndex]), React.useEffect(() => {
|
|
240
|
+
open && fallback && selectedIndex != null && listItemsRef.current[selectedIndex]?.scrollIntoView({
|
|
241
|
+
block: "nearest"
|
|
242
|
+
});
|
|
243
|
+
}, [open, fallback, selectedIndex]), (0, import_constants.useIsomorphicLayoutEffect)(() => {
|
|
244
|
+
refs.floating.current && fallback && (refs.floating.current.style.maxHeight = "");
|
|
245
|
+
}, [refs, fallback]), /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_context.SelectProvider, {
|
|
246
|
+
scope: __scopeSelect,
|
|
247
|
+
...selectContext,
|
|
248
|
+
setScrollTop,
|
|
249
|
+
setInnerOffset,
|
|
250
|
+
fallback,
|
|
251
|
+
floatingContext: context,
|
|
252
|
+
activeIndex,
|
|
253
|
+
canScrollDown: !!showDownArrow,
|
|
254
|
+
canScrollUp: !!showUpArrow,
|
|
255
|
+
controlledScrolling,
|
|
256
|
+
blockSelection,
|
|
257
|
+
upArrowRef,
|
|
258
|
+
downArrowRef,
|
|
259
|
+
update,
|
|
260
|
+
children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_context.SelectItemParentProvider, {
|
|
261
|
+
scope: __scopeSelect,
|
|
262
|
+
...selectItemParentContext,
|
|
263
|
+
allowMouseUpRef,
|
|
264
|
+
allowSelectRef,
|
|
265
|
+
dataRef: context.dataRef,
|
|
266
|
+
interactions: interactionsContext,
|
|
267
|
+
listRef: listItemsRef,
|
|
268
|
+
selectTimeoutRef,
|
|
269
|
+
children
|
|
270
|
+
})
|
|
271
|
+
});
|
|
272
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all) __defProp(target, name, {
|
|
7
|
+
get: all[name],
|
|
8
|
+
enumerable: !0
|
|
9
|
+
});
|
|
10
|
+
},
|
|
11
|
+
__copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
|
|
13
|
+
get: () => from[key],
|
|
14
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
15
|
+
});
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
19
|
+
value: !0
|
|
20
|
+
}), mod);
|
|
21
|
+
var SelectImpl_native_exports = {};
|
|
22
|
+
__export(SelectImpl_native_exports, {
|
|
23
|
+
SelectInlineImpl: () => SelectInlineImpl
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(SelectImpl_native_exports);
|
|
26
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
27
|
+
const SelectInlineImpl = props => (process.env.NODE_ENV === "development" && console.warn("Sheet not implemented inline on native"), /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, {
|
|
28
|
+
children: props.children
|
|
29
|
+
}));
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf,
|
|
6
|
+
__hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all) __defProp(target, name, {
|
|
9
|
+
get: all[name],
|
|
10
|
+
enumerable: !0
|
|
11
|
+
});
|
|
12
|
+
},
|
|
13
|
+
__copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
|
|
15
|
+
get: () => from[key],
|
|
16
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
17
|
+
});
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
26
|
+
value: mod,
|
|
27
|
+
enumerable: !0
|
|
28
|
+
}) : target, mod)),
|
|
29
|
+
__toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
30
|
+
value: !0
|
|
31
|
+
}), mod);
|
|
32
|
+
var SelectItem_exports = {};
|
|
33
|
+
__export(SelectItem_exports, {
|
|
34
|
+
SelectItem: () => SelectItem,
|
|
35
|
+
SelectItemContextProvider: () => SelectItemContextProvider,
|
|
36
|
+
useSelectItemContext: () => useSelectItemContext
|
|
37
|
+
});
|
|
38
|
+
module.exports = __toCommonJS(SelectItem_exports);
|
|
39
|
+
var import_compose_refs = require("@tamagui/compose-refs"),
|
|
40
|
+
import_constants = require("@tamagui/constants"),
|
|
41
|
+
import_list_item = require("@tamagui/list-item"),
|
|
42
|
+
React = __toESM(require("react")),
|
|
43
|
+
import_context = require("./context.cjs"),
|
|
44
|
+
import_jsx_runtime = require("react/jsx-runtime");
|
|
45
|
+
const ITEM_NAME = "SelectItem",
|
|
46
|
+
[SelectItemContextProvider, useSelectItemContext] = (0, import_context.createSelectContext)(ITEM_NAME),
|
|
47
|
+
SelectItem = import_list_item.ListItemFrame.styleable(function (props, forwardedRef) {
|
|
48
|
+
const {
|
|
49
|
+
__scopeSelect,
|
|
50
|
+
value,
|
|
51
|
+
disabled = !1,
|
|
52
|
+
textValue: textValueProp,
|
|
53
|
+
index,
|
|
54
|
+
...restProps
|
|
55
|
+
} = props,
|
|
56
|
+
{
|
|
57
|
+
props: listItemProps
|
|
58
|
+
} = (0, import_list_item.useListItem)({
|
|
59
|
+
...(!props.unstyled && {
|
|
60
|
+
ellipse: !0
|
|
61
|
+
}),
|
|
62
|
+
...restProps
|
|
63
|
+
}),
|
|
64
|
+
context = (0, import_context.useSelectItemParentContext)(ITEM_NAME, __scopeSelect),
|
|
65
|
+
{
|
|
66
|
+
setSelectedIndex,
|
|
67
|
+
listRef,
|
|
68
|
+
setOpen,
|
|
69
|
+
onChange,
|
|
70
|
+
activeIndexSubscribe,
|
|
71
|
+
valueSubscribe,
|
|
72
|
+
allowMouseUpRef,
|
|
73
|
+
allowSelectRef,
|
|
74
|
+
setValueAtIndex,
|
|
75
|
+
selectTimeoutRef,
|
|
76
|
+
dataRef,
|
|
77
|
+
interactions,
|
|
78
|
+
shouldRenderWebNative,
|
|
79
|
+
size,
|
|
80
|
+
onActiveChange,
|
|
81
|
+
initialValue
|
|
82
|
+
} = context,
|
|
83
|
+
[isSelected, setSelected] = React.useState(initialValue === value);
|
|
84
|
+
React.useEffect(() => activeIndexSubscribe(i => {
|
|
85
|
+
index === i && (onActiveChange(value, index), listRef?.current[index]?.focus());
|
|
86
|
+
}), [index]), React.useEffect(() => valueSubscribe(val => {
|
|
87
|
+
setSelected(val === value);
|
|
88
|
+
}), [value]);
|
|
89
|
+
const textId = React.useId(),
|
|
90
|
+
composedRefs = (0, import_compose_refs.useComposedRefs)(forwardedRef, node => {
|
|
91
|
+
import_constants.isWeb && node instanceof HTMLElement && listRef && (listRef.current[index] = node);
|
|
92
|
+
});
|
|
93
|
+
(0, import_constants.useIsomorphicLayoutEffect)(() => {
|
|
94
|
+
setValueAtIndex(index, value);
|
|
95
|
+
}, [index, setValueAtIndex, value]);
|
|
96
|
+
function handleSelect() {
|
|
97
|
+
setSelectedIndex(index), onChange(value), setOpen(!1);
|
|
98
|
+
}
|
|
99
|
+
const selectItemProps = React.useMemo(() => interactions ? interactions.getItemProps({
|
|
100
|
+
onTouchMove() {
|
|
101
|
+
allowSelectRef.current = !0, allowMouseUpRef.current = !1;
|
|
102
|
+
},
|
|
103
|
+
onTouchEnd() {
|
|
104
|
+
allowSelectRef.current = !1, allowMouseUpRef.current = !0;
|
|
105
|
+
},
|
|
106
|
+
onKeyDown(event) {
|
|
107
|
+
event.key === "Enter" || event.key === " " && !dataRef?.current.typing ? (event.preventDefault(), handleSelect()) : allowSelectRef.current = !0;
|
|
108
|
+
},
|
|
109
|
+
onClick() {
|
|
110
|
+
allowSelectRef.current && handleSelect();
|
|
111
|
+
},
|
|
112
|
+
onMouseUp() {
|
|
113
|
+
allowMouseUpRef.current && (allowSelectRef.current && handleSelect(), clearTimeout(selectTimeoutRef.current), selectTimeoutRef.current = setTimeout(() => {
|
|
114
|
+
allowSelectRef.current = !0;
|
|
115
|
+
}));
|
|
116
|
+
}
|
|
117
|
+
}) : {
|
|
118
|
+
onPress: handleSelect
|
|
119
|
+
}, [handleSelect]);
|
|
120
|
+
return /* @__PURE__ */(0, import_jsx_runtime.jsx)(SelectItemContextProvider, {
|
|
121
|
+
scope: __scopeSelect,
|
|
122
|
+
value,
|
|
123
|
+
textId: textId || "",
|
|
124
|
+
isSelected,
|
|
125
|
+
children: shouldRenderWebNative ? /* @__PURE__ */(0, import_jsx_runtime.jsx)("option", {
|
|
126
|
+
value,
|
|
127
|
+
children: props.children
|
|
128
|
+
}) : /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_list_item.ListItemFrame, {
|
|
129
|
+
tag: "div",
|
|
130
|
+
componentName: ITEM_NAME,
|
|
131
|
+
ref: composedRefs,
|
|
132
|
+
"aria-labelledby": textId,
|
|
133
|
+
"aria-selected": isSelected,
|
|
134
|
+
"data-state": isSelected ? "active" : "inactive",
|
|
135
|
+
"aria-disabled": disabled || void 0,
|
|
136
|
+
"data-disabled": disabled ? "" : void 0,
|
|
137
|
+
tabIndex: disabled ? void 0 : -1,
|
|
138
|
+
...(!props.unstyled && {
|
|
139
|
+
backgrounded: !0,
|
|
140
|
+
pressTheme: !0,
|
|
141
|
+
hoverTheme: !0,
|
|
142
|
+
focusTheme: !0,
|
|
143
|
+
cursor: "default",
|
|
144
|
+
size,
|
|
145
|
+
outlineOffset: -0.5,
|
|
146
|
+
focusVisibleStyle: {
|
|
147
|
+
outlineColor: "$outlineColor",
|
|
148
|
+
outlineWidth: 1,
|
|
149
|
+
outlineStyle: "solid"
|
|
150
|
+
}
|
|
151
|
+
}),
|
|
152
|
+
...listItemProps,
|
|
153
|
+
...selectItemProps
|
|
154
|
+
})
|
|
155
|
+
});
|
|
156
|
+
}, {
|
|
157
|
+
disableTheme: !0
|
|
158
|
+
});
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf,
|
|
6
|
+
__hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all) __defProp(target, name, {
|
|
9
|
+
get: all[name],
|
|
10
|
+
enumerable: !0
|
|
11
|
+
});
|
|
12
|
+
},
|
|
13
|
+
__copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
|
|
15
|
+
get: () => from[key],
|
|
16
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
17
|
+
});
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
26
|
+
value: mod,
|
|
27
|
+
enumerable: !0
|
|
28
|
+
}) : target, mod)),
|
|
29
|
+
__toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
30
|
+
value: !0
|
|
31
|
+
}), mod);
|
|
32
|
+
var SelectItemText_exports = {};
|
|
33
|
+
__export(SelectItemText_exports, {
|
|
34
|
+
ITEM_TEXT_NAME: () => ITEM_TEXT_NAME,
|
|
35
|
+
SelectItemText: () => SelectItemText,
|
|
36
|
+
SelectItemTextFrame: () => SelectItemTextFrame
|
|
37
|
+
});
|
|
38
|
+
module.exports = __toCommonJS(SelectItemText_exports);
|
|
39
|
+
var import_compose_refs = require("@tamagui/compose-refs"),
|
|
40
|
+
import_core = require("@tamagui/core"),
|
|
41
|
+
import_text = require("@tamagui/text"),
|
|
42
|
+
React = __toESM(require("react")),
|
|
43
|
+
import_context = require("./context.cjs"),
|
|
44
|
+
import_SelectItem = require("./SelectItem.cjs"),
|
|
45
|
+
import_jsx_runtime = require("react/jsx-runtime");
|
|
46
|
+
const ITEM_TEXT_NAME = "SelectItemText",
|
|
47
|
+
SelectItemTextFrame = (0, import_core.styled)(import_text.SizableText, {
|
|
48
|
+
name: ITEM_TEXT_NAME,
|
|
49
|
+
variants: {
|
|
50
|
+
unstyled: {
|
|
51
|
+
false: {
|
|
52
|
+
userSelect: "none",
|
|
53
|
+
color: "$color",
|
|
54
|
+
ellipse: !0
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
defaultVariants: {
|
|
59
|
+
unstyled: process.env.TAMAGUI_HEADLESS === "1"
|
|
60
|
+
}
|
|
61
|
+
}),
|
|
62
|
+
SelectItemText = SelectItemTextFrame.styleable(function (props, forwardedRef) {
|
|
63
|
+
const {
|
|
64
|
+
__scopeSelect,
|
|
65
|
+
className,
|
|
66
|
+
...itemTextProps
|
|
67
|
+
} = props,
|
|
68
|
+
context = (0, import_context.useSelectContext)(ITEM_TEXT_NAME, __scopeSelect),
|
|
69
|
+
itemParentContext = (0, import_context.useSelectItemParentContext)(ITEM_TEXT_NAME, __scopeSelect),
|
|
70
|
+
ref = React.useRef(null),
|
|
71
|
+
composedRefs = (0, import_compose_refs.useComposedRefs)(forwardedRef, ref),
|
|
72
|
+
itemContext = (0, import_SelectItem.useSelectItemContext)(ITEM_TEXT_NAME, __scopeSelect),
|
|
73
|
+
contents = React.useRef();
|
|
74
|
+
return contents.current = /* @__PURE__ */(0, import_jsx_runtime.jsx)(SelectItemTextFrame, {
|
|
75
|
+
className,
|
|
76
|
+
size: itemParentContext.size,
|
|
77
|
+
id: itemContext.textId,
|
|
78
|
+
...itemTextProps,
|
|
79
|
+
ref: composedRefs
|
|
80
|
+
}), React.useEffect(() => {
|
|
81
|
+
itemParentContext.initialValue === itemContext.value && !context.selectedIndex && context.setSelectedItem(contents.current);
|
|
82
|
+
}, []), React.useEffect(() => itemParentContext.valueSubscribe(val => {
|
|
83
|
+
val === itemContext.value && context.setSelectedItem(contents.current);
|
|
84
|
+
}), [itemContext.value]), itemParentContext.shouldRenderWebNative ? /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, {
|
|
85
|
+
children: props.children
|
|
86
|
+
}) : /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, {
|
|
87
|
+
children: contents.current
|
|
88
|
+
});
|
|
89
|
+
});
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf,
|
|
6
|
+
__hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all) __defProp(target, name, {
|
|
9
|
+
get: all[name],
|
|
10
|
+
enumerable: !0
|
|
11
|
+
});
|
|
12
|
+
},
|
|
13
|
+
__copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
|
|
15
|
+
get: () => from[key],
|
|
16
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
17
|
+
});
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
26
|
+
value: mod,
|
|
27
|
+
enumerable: !0
|
|
28
|
+
}) : target, mod)),
|
|
29
|
+
__toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
30
|
+
value: !0
|
|
31
|
+
}), mod);
|
|
32
|
+
var SelectScrollButton_exports = {};
|
|
33
|
+
__export(SelectScrollButton_exports, {
|
|
34
|
+
SelectScrollDownButton: () => SelectScrollDownButton,
|
|
35
|
+
SelectScrollUpButton: () => SelectScrollUpButton
|
|
36
|
+
});
|
|
37
|
+
module.exports = __toCommonJS(SelectScrollButton_exports);
|
|
38
|
+
var import_react = require("@floating-ui/react"),
|
|
39
|
+
import_compose_refs = require("@tamagui/compose-refs"),
|
|
40
|
+
import_stacks = require("@tamagui/stacks"),
|
|
41
|
+
React = __toESM(require("react")),
|
|
42
|
+
import_react_dom = require("react-dom"),
|
|
43
|
+
import_context = require("./context.cjs"),
|
|
44
|
+
import_jsx_runtime = require("react/jsx-runtime");
|
|
45
|
+
const SCROLL_UP_BUTTON_NAME = "SelectScrollUpButton",
|
|
46
|
+
SelectScrollUpButton = React.forwardRef((props, forwardedRef) => /* @__PURE__ */(0, import_jsx_runtime.jsx)(SelectScrollButtonImpl, {
|
|
47
|
+
componentName: SCROLL_UP_BUTTON_NAME,
|
|
48
|
+
...props,
|
|
49
|
+
dir: "up",
|
|
50
|
+
ref: forwardedRef
|
|
51
|
+
}));
|
|
52
|
+
SelectScrollUpButton.displayName = SCROLL_UP_BUTTON_NAME;
|
|
53
|
+
const SCROLL_DOWN_BUTTON_NAME = "SelectScrollDownButton",
|
|
54
|
+
SelectScrollDownButton = React.forwardRef((props, forwardedRef) => /* @__PURE__ */(0, import_jsx_runtime.jsx)(SelectScrollButtonImpl, {
|
|
55
|
+
componentName: SCROLL_DOWN_BUTTON_NAME,
|
|
56
|
+
...props,
|
|
57
|
+
dir: "down",
|
|
58
|
+
ref: forwardedRef
|
|
59
|
+
}));
|
|
60
|
+
SelectScrollDownButton.displayName = SCROLL_DOWN_BUTTON_NAME;
|
|
61
|
+
const SelectScrollButtonImpl = React.memo(React.forwardRef((props, forwardedRef) => {
|
|
62
|
+
const {
|
|
63
|
+
__scopeSelect,
|
|
64
|
+
dir,
|
|
65
|
+
componentName,
|
|
66
|
+
...scrollIndicatorProps
|
|
67
|
+
} = props,
|
|
68
|
+
{
|
|
69
|
+
forceUpdate,
|
|
70
|
+
open,
|
|
71
|
+
fallback,
|
|
72
|
+
setScrollTop,
|
|
73
|
+
setInnerOffset,
|
|
74
|
+
...context
|
|
75
|
+
} = (0, import_context.useSelectContext)(componentName, __scopeSelect),
|
|
76
|
+
floatingRef = context.floatingContext?.refs.floating,
|
|
77
|
+
statusRef = React.useRef("idle"),
|
|
78
|
+
isVisible = context[dir === "down" ? "canScrollDown" : "canScrollUp"],
|
|
79
|
+
frameRef = React.useRef(),
|
|
80
|
+
{
|
|
81
|
+
x,
|
|
82
|
+
y,
|
|
83
|
+
refs,
|
|
84
|
+
strategy
|
|
85
|
+
} = (0, import_react.useFloating)({
|
|
86
|
+
open: open && isVisible,
|
|
87
|
+
strategy: "fixed",
|
|
88
|
+
elements: {
|
|
89
|
+
reference: floatingRef?.current
|
|
90
|
+
},
|
|
91
|
+
placement: dir === "up" ? "top" : "bottom",
|
|
92
|
+
middleware: [(0, import_react.offset)(({
|
|
93
|
+
rects
|
|
94
|
+
}) => -rects.floating.height)],
|
|
95
|
+
whileElementsMounted: (...args) => (0, import_react.autoUpdate)(...args, {
|
|
96
|
+
animationFrame: !0
|
|
97
|
+
})
|
|
98
|
+
}),
|
|
99
|
+
composedRef = (0, import_compose_refs.useComposedRefs)(forwardedRef, refs.setFloating);
|
|
100
|
+
if (!isVisible) return null;
|
|
101
|
+
const onScroll = amount => {
|
|
102
|
+
const floating = floatingRef;
|
|
103
|
+
floating && (fallback ? floating.current && (floating.current.scrollTop -= amount, (0, import_react_dom.flushSync)(() => setScrollTop(floating.current?.scrollTop ?? 0))) : (0, import_react_dom.flushSync)(() => setInnerOffset(value => value - amount)));
|
|
104
|
+
};
|
|
105
|
+
return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_stacks.YStack, {
|
|
106
|
+
ref: composedRef,
|
|
107
|
+
componentName,
|
|
108
|
+
"aria-hidden": !0,
|
|
109
|
+
...scrollIndicatorProps,
|
|
110
|
+
zIndex: 1e3,
|
|
111
|
+
position: strategy,
|
|
112
|
+
left: x || 0,
|
|
113
|
+
top: y || 0,
|
|
114
|
+
width: `calc(${(floatingRef?.current?.offsetWidth ?? 0) - 2}px)`,
|
|
115
|
+
onPointerEnter: () => {
|
|
116
|
+
statusRef.current = "active";
|
|
117
|
+
let prevNow = Date.now();
|
|
118
|
+
function frame() {
|
|
119
|
+
const element = floatingRef?.current;
|
|
120
|
+
if (element) {
|
|
121
|
+
const currentNow = Date.now(),
|
|
122
|
+
msElapsed = currentNow - prevNow;
|
|
123
|
+
prevNow = currentNow;
|
|
124
|
+
const pixelsToScroll = msElapsed / 2,
|
|
125
|
+
remainingPixels = dir === "up" ? element.scrollTop : element.scrollHeight - element.clientHeight - element.scrollTop,
|
|
126
|
+
scrollRemaining = dir === "up" ? element.scrollTop - pixelsToScroll > 0 : element.scrollTop + pixelsToScroll < element.scrollHeight - element.clientHeight;
|
|
127
|
+
onScroll(dir === "up" ? Math.min(pixelsToScroll, remainingPixels) : Math.max(-pixelsToScroll, -remainingPixels)), scrollRemaining && (frameRef.current = requestAnimationFrame(frame));
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
cancelAnimationFrame(frameRef.current), frameRef.current = requestAnimationFrame(frame);
|
|
131
|
+
},
|
|
132
|
+
onPointerLeave: () => {
|
|
133
|
+
statusRef.current = "idle", cancelAnimationFrame(frameRef.current);
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
}));
|