@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.
Files changed (51) hide show
  1. package/dist/cjs/BubbleSelect.cjs +45 -0
  2. package/dist/cjs/Select.cjs +398 -0
  3. package/dist/cjs/SelectContent.cjs +82 -0
  4. package/dist/cjs/SelectContent.native.cjs +28 -0
  5. package/dist/cjs/SelectContent.native.cjs.map +6 -0
  6. package/dist/cjs/SelectImpl.cjs +272 -0
  7. package/dist/cjs/SelectImpl.native.cjs +29 -0
  8. package/dist/cjs/SelectImpl.native.cjs.map +6 -0
  9. package/dist/cjs/SelectItem.cjs +158 -0
  10. package/dist/cjs/SelectItemText.cjs +89 -0
  11. package/dist/cjs/SelectScrollButton.cjs +136 -0
  12. package/dist/cjs/SelectScrollButton.native.cjs +28 -0
  13. package/dist/cjs/SelectScrollButton.native.cjs.map +6 -0
  14. package/dist/cjs/SelectTrigger.cjs +99 -0
  15. package/dist/cjs/SelectViewport.cjs +135 -0
  16. package/dist/cjs/SelectViewport.native.cjs +69 -0
  17. package/dist/cjs/SelectViewport.native.cjs.map +6 -0
  18. package/dist/cjs/constants.cjs +38 -0
  19. package/dist/cjs/context.cjs +55 -0
  20. package/dist/cjs/index.cjs +19 -0
  21. package/dist/cjs/types.cjs +16 -0
  22. package/dist/cjs/useSelectBreakpointActive.cjs +35 -0
  23. package/package.json +25 -24
  24. package/dist/cjs/BubbleSelect.js +0 -34
  25. package/dist/cjs/Select.js +0 -328
  26. package/dist/cjs/SelectContent.js +0 -45
  27. package/dist/cjs/SelectImpl.js +0 -224
  28. package/dist/cjs/SelectItem.js +0 -142
  29. package/dist/cjs/SelectItemText.js +0 -62
  30. package/dist/cjs/SelectScrollButton.js +0 -105
  31. package/dist/cjs/SelectTrigger.js +0 -84
  32. package/dist/cjs/SelectViewport.js +0 -111
  33. package/dist/cjs/constants.js +0 -27
  34. package/dist/cjs/context.js +0 -35
  35. package/dist/cjs/index.js +0 -16
  36. package/dist/cjs/types.js +0 -14
  37. package/dist/cjs/useSelectBreakpointActive.js +0 -29
  38. /package/dist/cjs/{BubbleSelect.js.map → BubbleSelect.cjs.map} +0 -0
  39. /package/dist/cjs/{Select.js.map → Select.cjs.map} +0 -0
  40. /package/dist/cjs/{SelectContent.js.map → SelectContent.cjs.map} +0 -0
  41. /package/dist/cjs/{SelectImpl.js.map → SelectImpl.cjs.map} +0 -0
  42. /package/dist/cjs/{SelectItem.js.map → SelectItem.cjs.map} +0 -0
  43. /package/dist/cjs/{SelectItemText.js.map → SelectItemText.cjs.map} +0 -0
  44. /package/dist/cjs/{SelectScrollButton.js.map → SelectScrollButton.cjs.map} +0 -0
  45. /package/dist/cjs/{SelectTrigger.js.map → SelectTrigger.cjs.map} +0 -0
  46. /package/dist/cjs/{SelectViewport.js.map → SelectViewport.cjs.map} +0 -0
  47. /package/dist/cjs/{constants.js.map → constants.cjs.map} +0 -0
  48. /package/dist/cjs/{context.js.map → context.cjs.map} +0 -0
  49. /package/dist/cjs/{index.js.map → index.cjs.map} +0 -0
  50. /package/dist/cjs/{types.js.map → types.cjs.map} +0 -0
  51. /package/dist/cjs/{useSelectBreakpointActive.js.map → useSelectBreakpointActive.cjs.map} +0 -0
@@ -1,328 +0,0 @@
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, __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: !0 });
9
- }, __copyProps = (to, from, except, desc) => {
10
- if (from && typeof from == "object" || typeof from == "function")
11
- for (let key of __getOwnPropNames(from))
12
- !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
13
- return to;
14
- };
15
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
16
- // If the importer is in node compatibility mode or this is not an ESM
17
- // file that has been converted to a CommonJS file using a Babel-
18
- // compatible transform (i.e. "__esModule" has not been set), then set
19
- // "default" to the CommonJS "module.exports" for node compatibility.
20
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: !0 }) : target,
21
- mod
22
- )), __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
23
- var Select_exports = {};
24
- __export(Select_exports, {
25
- Select: () => Select,
26
- SelectGroupFrame: () => SelectGroupFrame,
27
- SelectIcon: () => SelectIcon,
28
- SelectSeparator: () => SelectSeparator
29
- });
30
- module.exports = __toCommonJS(Select_exports);
31
- var import_adapt = require("@tamagui/adapt"), import_compose_refs = require("@tamagui/compose-refs"), import_constants = require("@tamagui/constants"), import_core = require("@tamagui/core"), import_get_token = require("@tamagui/get-token"), import_helpers = require("@tamagui/helpers"), import_list_item = require("@tamagui/list-item"), import_portal = require("@tamagui/portal"), import_separator = require("@tamagui/separator"), import_focusable = require("@tamagui/focusable"), import_sheet = require("@tamagui/sheet"), import_stacks = require("@tamagui/stacks"), import_text = require("@tamagui/text"), import_use_controllable_state = require("@tamagui/use-controllable-state"), React = __toESM(require("react")), import_use_debounce = require("@tamagui/use-debounce"), import_constants2 = require("./constants"), import_context = require("./context"), import_SelectContent = require("./SelectContent"), import_SelectImpl = require("./SelectImpl"), import_SelectItem = require("./SelectItem"), import_SelectItemText = require("./SelectItemText"), import_SelectScrollButton = require("./SelectScrollButton"), import_SelectTrigger = require("./SelectTrigger"), import_SelectViewport = require("./SelectViewport"), import_useSelectBreakpointActive = require("./useSelectBreakpointActive"), import_jsx_runtime = require("react/jsx-runtime");
32
- const VALUE_NAME = "SelectValue", SelectValueFrame = (0, import_core.styled)(import_text.SizableText, {
33
- name: VALUE_NAME,
34
- userSelect: "none"
35
- }), SelectValue = SelectValueFrame.styleable(
36
- function({
37
- __scopeSelect,
38
- children: childrenProp,
39
- placeholder,
40
- ...props
41
- }, forwardedRef) {
42
- const context = (0, import_context.useSelectContext)(VALUE_NAME, __scopeSelect), itemParentContext = (0, import_context.useSelectItemParentContext)(VALUE_NAME, __scopeSelect), composedRefs = (0, import_compose_refs.useComposedRefs)(forwardedRef, context.onValueNodeChange), children = childrenProp ?? context.selectedItem, selectValueChildren = context.value == null || context.value === "" ? placeholder ?? children : children;
43
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
44
- SelectValueFrame,
45
- {
46
- ...!props.unstyled && {
47
- size: itemParentContext.size,
48
- ellipse: !0,
49
- // we don't want events from the portalled `SelectValue` children to bubble
50
- // through the item they came from
51
- pointerEvents: "none"
52
- },
53
- ref: composedRefs,
54
- ...props,
55
- children: unwrapSelectItem(selectValueChildren)
56
- }
57
- );
58
- }
59
- );
60
- function unwrapSelectItem(selectValueChildren) {
61
- return React.Children.map(selectValueChildren, (child) => {
62
- if (child) {
63
- if (child.type?.staticConfig?.componentName === import_SelectItemText.ITEM_TEXT_NAME)
64
- return child.props.children;
65
- if (child.props?.children)
66
- return unwrapSelectItem(child.props.children);
67
- }
68
- return child;
69
- });
70
- }
71
- const SelectIcon = (0, import_core.styled)(import_stacks.XStack, {
72
- name: "SelectIcon",
73
- // @ts-ignore
74
- "aria-hidden": !0,
75
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_text.Paragraph, { children: "\u25BC" })
76
- }), ITEM_INDICATOR_NAME = "SelectItemIndicator", SelectItemIndicatorFrame = (0, import_core.styled)(import_stacks.XStack, {
77
- name: import_SelectItemText.ITEM_TEXT_NAME
78
- }), SelectItemIndicator = React.forwardRef(
79
- (props, forwardedRef) => {
80
- const { __scopeSelect, ...itemIndicatorProps } = props, context = (0, import_context.useSelectItemParentContext)(ITEM_INDICATOR_NAME, __scopeSelect), itemContext = (0, import_SelectItem.useSelectItemContext)(ITEM_INDICATOR_NAME, __scopeSelect);
81
- return context.shouldRenderWebNative ? null : itemContext.isSelected ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SelectItemIndicatorFrame, { "aria-hidden": !0, ...itemIndicatorProps, ref: forwardedRef }) : null;
82
- }
83
- );
84
- SelectItemIndicator.displayName = ITEM_INDICATOR_NAME;
85
- const GROUP_NAME = "SelectGroup", [SelectGroupContextProvider, useSelectGroupContext] = (0, import_context.createSelectContext)(GROUP_NAME), SelectGroupFrame = (0, import_core.styled)(import_stacks.YStack, {
86
- name: GROUP_NAME,
87
- width: "100%"
88
- }), NativeSelectTextFrame = (0, import_core.styled)(import_text.SizableText, {
89
- tag: "select",
90
- backgroundColor: "$background",
91
- borderColor: "$borderColor",
92
- hoverStyle: {
93
- backgroundColor: "$backgroundHover"
94
- }
95
- }), NativeSelectFrame = (0, import_core.styled)(import_stacks.ThemeableStack, {
96
- name: "NativeSelect",
97
- bordered: !0,
98
- userSelect: "none",
99
- outlineWidth: 0,
100
- paddingRight: 10,
101
- variants: {
102
- size: {
103
- "...size": (val, extras) => {
104
- const { tokens } = extras, paddingHorizontal = (0, import_core.getVariableValue)(tokens.space[val]);
105
- return {
106
- borderRadius: tokens.radius[val] ?? val,
107
- minHeight: tokens.size[val],
108
- paddingRight: paddingHorizontal + 20,
109
- paddingLeft: paddingHorizontal,
110
- paddingVertical: (0, import_get_token.getSpace)(val, {
111
- shift: -3
112
- })
113
- };
114
- }
115
- }
116
- },
117
- defaultVariants: {
118
- size: "$2"
119
- }
120
- }), SelectGroup = React.forwardRef(
121
- (props, forwardedRef) => {
122
- const { __scopeSelect, ...groupProps } = props, groupId = React.useId(), context = (0, import_context.useSelectContext)(GROUP_NAME, __scopeSelect), itemParentContext = (0, import_context.useSelectItemParentContext)(GROUP_NAME, __scopeSelect), size = itemParentContext.size ?? "$true", nativeSelectRef = React.useRef(null), content = itemParentContext.shouldRenderWebNative ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
123
- NativeSelectFrame,
124
- {
125
- asChild: !0,
126
- size,
127
- value: context.value,
128
- id: itemParentContext.id,
129
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
130
- NativeSelectTextFrame,
131
- {
132
- onChange: (event) => {
133
- itemParentContext.onChange(event.currentTarget.value);
134
- },
135
- size,
136
- ref: nativeSelectRef,
137
- style: {
138
- color: "var(--color)",
139
- // @ts-ignore
140
- appearance: "none"
141
- },
142
- children: props.children
143
- }
144
- )
145
- }
146
- ) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
147
- SelectGroupFrame,
148
- {
149
- role: "group",
150
- "aria-labelledby": groupId,
151
- ...groupProps,
152
- ref: forwardedRef
153
- }
154
- );
155
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SelectGroupContextProvider, { scope: __scopeSelect, id: groupId || "", children: content });
156
- }
157
- );
158
- SelectGroup.displayName = GROUP_NAME;
159
- const LABEL_NAME = "SelectLabel", SelectLabel = React.forwardRef(
160
- (props, forwardedRef) => {
161
- const { __scopeSelect, ...labelProps } = props, context = (0, import_context.useSelectItemParentContext)(LABEL_NAME, __scopeSelect), groupContext = useSelectGroupContext(LABEL_NAME, __scopeSelect);
162
- return context.shouldRenderWebNative ? null : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
163
- import_list_item.ListItem,
164
- {
165
- tag: "div",
166
- componentName: LABEL_NAME,
167
- fontWeight: "800",
168
- id: groupContext.id,
169
- size: context.size,
170
- ...labelProps,
171
- ref: forwardedRef
172
- }
173
- );
174
- }
175
- );
176
- SelectLabel.displayName = LABEL_NAME;
177
- const SelectSeparator = (0, import_core.styled)(import_separator.Separator, {
178
- name: "SelectSeparator"
179
- }), SelectSheetController = (props) => {
180
- const context = (0, import_context.useSelectContext)("SelectSheetController", props.__scopeSelect), showSheet = (0, import_useSelectBreakpointActive.useShowSelectSheet)(context), breakpointActive = (0, import_useSelectBreakpointActive.useSelectBreakpointActive)(context.sheetBreakpoint), getShowSheet = (0, import_core.useGet)(showSheet);
181
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
182
- import_sheet.SheetController,
183
- {
184
- onOpenChange: (val) => {
185
- getShowSheet() && props.onOpenChange(val);
186
- },
187
- open: context.open,
188
- hidden: breakpointActive === !1,
189
- children: props.children
190
- }
191
- );
192
- }, SelectSheetImpl = (props) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: props.children }), Select = (0, import_helpers.withStaticProperties)(
193
- (props) => {
194
- const {
195
- __scopeSelect,
196
- native,
197
- children,
198
- open: openProp,
199
- defaultOpen,
200
- onOpenChange,
201
- value: valueProp,
202
- defaultValue,
203
- onValueChange,
204
- disablePreventBodyScroll,
205
- size: sizeProp = "$true",
206
- onActiveChange,
207
- dir,
208
- id
209
- } = props, internalId = React.useId(), scopeKey = __scopeSelect ? Object.keys(__scopeSelect)[0] ?? internalId : internalId, { when, AdaptProvider } = (0, import_adapt.useAdaptParent)({
210
- Contents: React.useCallback(
211
- () => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_portal.PortalHost, { name: `${scopeKey}SheetContents` }),
212
- [scopeKey]
213
- )
214
- }), sheetBreakpoint = when, SelectImpl = (0, import_useSelectBreakpointActive.useSelectBreakpointActive)(sheetBreakpoint) || !import_constants.isWeb ? SelectSheetImpl : import_SelectImpl.SelectInlineImpl, forceUpdate = React.useReducer(() => ({}), {})[1], [selectedItem, setSelectedItem] = React.useState(null), [open, setOpen] = (0, import_use_controllable_state.useControllableState)({
215
- prop: openProp,
216
- defaultProp: defaultOpen || !1,
217
- onChange: onOpenChange
218
- }), [value, setValue] = (0, import_use_controllable_state.useControllableState)({
219
- prop: valueProp,
220
- defaultProp: defaultValue || "",
221
- onChange: onValueChange,
222
- transition: !0
223
- });
224
- React.useEffect(() => {
225
- open && emitValue(value);
226
- }, [open]), React.useEffect(() => {
227
- emitValue(value);
228
- }, [value]);
229
- const [activeIndex, setActiveIndex] = React.useState(0), [emitValue, valueSubscribe] = useEmitter(), [emitActiveIndex, activeIndexSubscribe] = useEmitter(), selectedIndexRef = React.useRef(null), activeIndexRef = React.useRef(null), listContentRef = React.useRef([]), [selectedIndex, setSelectedIndex] = React.useState(0), [valueNode, setValueNode] = React.useState(null);
230
- (0, import_constants.useIsomorphicLayoutEffect)(() => {
231
- selectedIndexRef.current = selectedIndex, activeIndexRef.current = activeIndex;
232
- });
233
- const shouldRenderWebNative = import_constants.isWeb && (native === !0 || native === "web" || Array.isArray(native) && native.includes("web")), setActiveIndexDebounced = (0, import_use_debounce.useDebounce)(
234
- (index) => {
235
- setActiveIndex((prev) => prev !== index ? (typeof index == "number" && emitActiveIndex(index), index) : prev);
236
- },
237
- 1,
238
- {},
239
- []
240
- );
241
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(AdaptProvider, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
242
- import_context.SelectItemParentProvider,
243
- {
244
- scope: __scopeSelect,
245
- initialValue: React.useMemo(() => value, [open]),
246
- size: sizeProp,
247
- activeIndexSubscribe,
248
- valueSubscribe,
249
- setOpen,
250
- id,
251
- onChange: React.useCallback((val) => {
252
- setValue(val), emitValue(val);
253
- }, []),
254
- onActiveChange: (0, import_core.useEvent)((...args) => {
255
- onActiveChange?.(...args);
256
- }),
257
- setSelectedIndex,
258
- setValueAtIndex: React.useCallback((index, value2) => {
259
- listContentRef.current[index] = value2;
260
- }, []),
261
- shouldRenderWebNative,
262
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
263
- import_context.SelectProvider,
264
- {
265
- scope: __scopeSelect,
266
- disablePreventBodyScroll,
267
- dir,
268
- blockSelection: !1,
269
- fallback: !1,
270
- selectedItem,
271
- setSelectedItem,
272
- forceUpdate,
273
- valueNode,
274
- onValueNodeChange: setValueNode,
275
- scopeKey,
276
- sheetBreakpoint,
277
- activeIndex,
278
- selectedIndex,
279
- setActiveIndex: setActiveIndexDebounced,
280
- value,
281
- open,
282
- native,
283
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SelectSheetController, { onOpenChange: setOpen, __scopeSelect, children: shouldRenderWebNative ? children : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
284
- SelectImpl,
285
- {
286
- activeIndexRef,
287
- listContentRef,
288
- selectedIndexRef,
289
- ...props,
290
- open,
291
- value,
292
- children
293
- }
294
- ) })
295
- }
296
- )
297
- }
298
- ) });
299
- },
300
- {
301
- Adapt: import_adapt.Adapt,
302
- Content: import_SelectContent.SelectContent,
303
- Group: SelectGroup,
304
- Icon: SelectIcon,
305
- Item: import_SelectItem.SelectItem,
306
- ItemIndicator: SelectItemIndicator,
307
- ItemText: import_SelectItemText.SelectItemText,
308
- Label: SelectLabel,
309
- ScrollDownButton: import_SelectScrollButton.SelectScrollDownButton,
310
- ScrollUpButton: import_SelectScrollButton.SelectScrollUpButton,
311
- Trigger: import_SelectTrigger.SelectTrigger,
312
- Value: SelectValue,
313
- Viewport: import_SelectViewport.SelectViewport,
314
- Sheet: import_sheet.Sheet.Controlled
315
- }
316
- );
317
- function useEmitter() {
318
- const listeners = React.useRef();
319
- listeners.current || (listeners.current = /* @__PURE__ */ new Set());
320
- const emit = (value) => {
321
- listeners.current.forEach((l) => l(value));
322
- }, subscribe = React.useCallback((listener) => (listeners.current.add(listener), () => {
323
- listeners.current.delete(listener);
324
- }), []);
325
- return [emit, subscribe];
326
- }
327
- Select.displayName = import_constants2.SELECT_NAME;
328
- //# sourceMappingURL=Select.js.map
@@ -1,45 +0,0 @@
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, __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: !0 });
9
- }, __copyProps = (to, from, except, desc) => {
10
- if (from && typeof from == "object" || typeof from == "function")
11
- for (let key of __getOwnPropNames(from))
12
- !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
13
- return to;
14
- };
15
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
16
- // If the importer is in node compatibility mode or this is not an ESM
17
- // file that has been converted to a CommonJS file using a Babel-
18
- // compatible transform (i.e. "__esModule" has not been set), then set
19
- // "default" to the CommonJS "module.exports" for node compatibility.
20
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: !0 }) : target,
21
- mod
22
- )), __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
23
- var SelectContent_exports = {};
24
- __export(SelectContent_exports, {
25
- SelectContent: () => SelectContent
26
- });
27
- module.exports = __toCommonJS(SelectContent_exports);
28
- var import_react = __toESM(require("react")), import_react2 = require("@floating-ui/react"), import_core = require("@tamagui/core"), import_focus_scope = require("@tamagui/focus-scope"), import_context = require("./context"), import_useSelectBreakpointActive = require("./useSelectBreakpointActive"), import_jsx_runtime = require("react/jsx-runtime");
29
- const CONTENT_NAME = "SelectContent", SelectContent = ({
30
- children,
31
- __scopeSelect,
32
- zIndex = 1e3,
33
- ...focusScopeProps
34
- }) => {
35
- const context = (0, import_context.useSelectContext)(CONTENT_NAME, __scopeSelect), itemParentContext = (0, import_context.useSelectItemParentContext)(CONTENT_NAME, __scopeSelect), themeName = (0, import_core.useThemeName)(), showSheet = (0, import_useSelectBreakpointActive.useShowSelectSheet)(context), contents = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_core.Theme, { forceClassName: !0, name: themeName, children }), touch = (0, import_core.useIsTouchDevice)(), overlayStyle = import_react.default.useMemo(() => ({ zIndex, pointerEvents: context.open ? "auto" : "none" }), [context.open]);
36
- return itemParentContext.shouldRenderWebNative ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children }) : showSheet ? context.open ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: contents }) : null : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react2.FloatingPortal, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
37
- import_react2.FloatingOverlay,
38
- {
39
- style: overlayStyle,
40
- lockScroll: !context.disablePreventBodyScroll && !!context.open && !touch,
41
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_focus_scope.FocusScope, { loop: !0, enabled: !!context.open, trapped: !0, ...focusScopeProps, children: contents })
42
- }
43
- ) });
44
- };
45
- //# sourceMappingURL=SelectContent.js.map
@@ -1,224 +0,0 @@
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, __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: !0 });
9
- }, __copyProps = (to, from, except, desc) => {
10
- if (from && typeof from == "object" || typeof from == "function")
11
- for (let key of __getOwnPropNames(from))
12
- !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
13
- return to;
14
- };
15
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
16
- // If the importer is in node compatibility mode or this is not an ESM
17
- // file that has been converted to a CommonJS file using a Babel-
18
- // compatible transform (i.e. "__esModule" has not been set), then set
19
- // "default" to the CommonJS "module.exports" for node compatibility.
20
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: !0 }) : target,
21
- mod
22
- )), __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
23
- var SelectImpl_exports = {};
24
- __export(SelectImpl_exports, {
25
- SelectInlineImpl: () => SelectInlineImpl
26
- });
27
- module.exports = __toCommonJS(SelectImpl_exports);
28
- var import_react = require("@floating-ui/react"), import_constants = require("@tamagui/constants"), import_core = require("@tamagui/core"), React = __toESM(require("react")), import_react_dom = require("react-dom"), import_constants2 = require("./constants"), import_context = require("./context"), import_jsx_runtime = require("react/jsx-runtime");
29
- const SelectInlineImpl = (props) => {
30
- const {
31
- __scopeSelect,
32
- children,
33
- open = !1,
34
- selectedIndexRef,
35
- listContentRef
36
- } = props, selectContext = (0, import_context.useSelectContext)("SelectSheetImpl", __scopeSelect), selectItemParentContext = (0, import_context.useSelectItemParentContext)(
37
- "SelectSheetImpl",
38
- __scopeSelect
39
- ), { setActiveIndex, selectedIndex, activeIndex, forceUpdate } = selectContext, { setOpen, setSelectedIndex } = selectItemParentContext, [scrollTop, setScrollTop] = React.useState(0), touch = (0, import_core.useIsTouchDevice)(), listItemsRef = React.useRef([]), overflowRef = React.useRef(null), upArrowRef = React.useRef(null), downArrowRef = React.useRef(null), allowSelectRef = React.useRef(!1), allowMouseUpRef = React.useRef(!0), selectTimeoutRef = React.useRef(), state = React.useRef({
40
- isMouseOutside: !1,
41
- isTyping: !1
42
- }), [controlledScrolling, setControlledScrolling] = React.useState(!1), [fallback, setFallback] = React.useState(!1), [innerOffset, setInnerOffset] = React.useState(0), [blockSelection, setBlockSelection] = React.useState(!1), floatingStyle = React.useRef({});
43
- (0, import_constants.useIsomorphicLayoutEffect)(() => {
44
- queueMicrotask(() => {
45
- open || (setScrollTop(0), setFallback(!1), setActiveIndex(null), setControlledScrolling(!1));
46
- });
47
- }, [open, setActiveIndex]), import_constants.isWeb && import_constants.isClient && (0, import_constants.useIsomorphicLayoutEffect)(() => {
48
- if (!open) return;
49
- const mouseUp = (e) => {
50
- state.current.isMouseOutside && setOpen(!1);
51
- };
52
- return document.addEventListener("mouseup", mouseUp), () => {
53
- document.removeEventListener("mouseup", mouseUp);
54
- };
55
- }, [open]);
56
- const { x, y, strategy, context, refs, update } = (0, import_react.useFloating)({
57
- open,
58
- onOpenChange: setOpen,
59
- placement: "bottom-start",
60
- whileElementsMounted: import_react.autoUpdate,
61
- // biome-ignore lint/correctness/noConstantCondition: <explanation>
62
- middleware: [
63
- (0, import_react.size)({
64
- apply({
65
- rects: {
66
- reference: { width }
67
- }
68
- }) {
69
- Object.assign(floatingStyle.current, {
70
- minWidth: width + 8
71
- }), refs.floating.current && Object.assign(refs.floating.current.style, floatingStyle.current);
72
- }
73
- }),
74
- (0, import_react.inner)({
75
- listRef: listItemsRef,
76
- overflowRef,
77
- index: selectedIndex,
78
- offset: innerOffset,
79
- onFallbackChange: setFallback,
80
- padding: 10,
81
- minItemsVisible: touch ? 10 : 4,
82
- referenceOverflowThreshold: 20
83
- }),
84
- (0, import_react.offset)({ crossAxis: -5 })
85
- ]
86
- }), floatingRef = refs.floating, showUpArrow = open && scrollTop > import_constants2.SCROLL_ARROW_THRESHOLD, showDownArrow = open && floatingRef.current && scrollTop < floatingRef.current.scrollHeight - floatingRef.current.clientHeight - import_constants2.SCROLL_ARROW_THRESHOLD, isScrollable = showDownArrow || showUpArrow;
87
- (0, import_constants.useIsomorphicLayoutEffect)(() => (window.addEventListener("resize", update), open && update(), () => window.removeEventListener("resize", update)), [update, open]);
88
- const onMatch = (0, import_core.useEvent)((index) => (open ? setActiveIndex : setSelectedIndex)(index)), interactionsProps = [
89
- (0, import_react.useClick)(context, { event: "mousedown", keyboardHandlers: !1 }),
90
- (0, import_react.useDismiss)(context, { outsidePress: !1 }),
91
- (0, import_react.useRole)(context, { role: "listbox" }),
92
- (0, import_react.useInnerOffset)(context, {
93
- enabled: !fallback && isScrollable,
94
- onChange: setInnerOffset,
95
- overflowRef,
96
- scrollRef: refs.floating
97
- }),
98
- (0, import_react.useListNavigation)(context, {
99
- listRef: listItemsRef,
100
- activeIndex: activeIndex || 0,
101
- selectedIndex,
102
- onNavigate: setActiveIndex,
103
- scrollItemIntoView: !1
104
- }),
105
- (0, import_react.useTypeahead)(context, {
106
- listRef: listContentRef,
107
- onMatch,
108
- selectedIndex,
109
- activeIndex,
110
- onTypingChange: (e) => {
111
- state.current.isTyping = e;
112
- }
113
- })
114
- ], interactions = (0, import_react.useInteractions)(
115
- // unfortunately these memos will just always break due to floating-ui context always changing :/
116
- React.useMemo(() => interactionsProps, interactionsProps)
117
- ), interactionsContext = React.useMemo(() => ({
118
- ...interactions,
119
- getReferenceProps() {
120
- return interactions.getReferenceProps({
121
- ref: refs.reference,
122
- className: "SelectTrigger",
123
- onKeyDown(event) {
124
- (event.key === "Enter" || event.code === "Space" || event.key === " " && !state.current.isTyping) && (event.preventDefault(), setOpen(!0));
125
- }
126
- });
127
- },
128
- getFloatingProps(props2) {
129
- return interactions.getFloatingProps({
130
- ref: refs.floating,
131
- className: "Select",
132
- ...props2,
133
- style: {
134
- position: strategy,
135
- top: y ?? "",
136
- left: x ?? "",
137
- outline: 0,
138
- scrollbarWidth: "none",
139
- ...floatingStyle.current,
140
- ...props2?.style
141
- },
142
- onPointerEnter() {
143
- setControlledScrolling(!1), state.current.isMouseOutside = !1;
144
- },
145
- onPointerLeave() {
146
- state.current.isMouseOutside = !0;
147
- },
148
- onPointerMove() {
149
- state.current.isMouseOutside = !1, setControlledScrolling(!1);
150
- },
151
- onKeyDown() {
152
- setControlledScrolling(!0);
153
- },
154
- onContextMenu(e) {
155
- e.preventDefault();
156
- },
157
- onScroll(event) {
158
- (0, import_react_dom.flushSync)(() => {
159
- setScrollTop(event.currentTarget.scrollTop);
160
- });
161
- }
162
- });
163
- }
164
- }), [refs.reference.current, x, y, refs.floating.current, interactions]);
165
- return (0, import_constants.useIsomorphicLayoutEffect)(() => {
166
- if (open)
167
- return selectTimeoutRef.current = setTimeout(() => {
168
- allowSelectRef.current = !0;
169
- }, 300), () => {
170
- clearTimeout(selectTimeoutRef.current);
171
- };
172
- allowSelectRef.current = !1, allowMouseUpRef.current = !0, setInnerOffset(0), setFallback(!1), setBlockSelection(!1);
173
- }, [open]), (0, import_constants.useIsomorphicLayoutEffect)(() => {
174
- !open && state.current.isMouseOutside && (state.current.isMouseOutside = !1);
175
- }, [open]), (0, import_constants.useIsomorphicLayoutEffect)(() => {
176
- function onPointerDown(e) {
177
- const target = e.target;
178
- refs.floating.current?.contains(target) || upArrowRef.current?.contains(target) || downArrowRef.current?.contains(target) || (setOpen(!1), setControlledScrolling(!1));
179
- }
180
- if (open)
181
- return document.addEventListener("pointerdown", onPointerDown), () => {
182
- document.removeEventListener("pointerdown", onPointerDown);
183
- };
184
- }, [open, refs, setOpen]), React.useEffect(() => {
185
- open && controlledScrolling && activeIndex != null && listItemsRef.current[activeIndex]?.scrollIntoView({ block: "nearest" }), setScrollTop(refs.floating.current?.scrollTop ?? 0);
186
- }, [open, refs, controlledScrolling, activeIndex]), React.useEffect(() => {
187
- open && fallback && selectedIndex != null && listItemsRef.current[selectedIndex]?.scrollIntoView({ block: "nearest" });
188
- }, [open, fallback, selectedIndex]), (0, import_constants.useIsomorphicLayoutEffect)(() => {
189
- refs.floating.current && fallback && (refs.floating.current.style.maxHeight = "");
190
- }, [refs, fallback]), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
191
- import_context.SelectProvider,
192
- {
193
- scope: __scopeSelect,
194
- ...selectContext,
195
- setScrollTop,
196
- setInnerOffset,
197
- fallback,
198
- floatingContext: context,
199
- activeIndex,
200
- canScrollDown: !!showDownArrow,
201
- canScrollUp: !!showUpArrow,
202
- controlledScrolling,
203
- blockSelection,
204
- upArrowRef,
205
- downArrowRef,
206
- update,
207
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
208
- import_context.SelectItemParentProvider,
209
- {
210
- scope: __scopeSelect,
211
- ...selectItemParentContext,
212
- allowMouseUpRef,
213
- allowSelectRef,
214
- dataRef: context.dataRef,
215
- interactions: interactionsContext,
216
- listRef: listItemsRef,
217
- selectTimeoutRef,
218
- children
219
- }
220
- )
221
- }
222
- );
223
- };
224
- //# sourceMappingURL=SelectImpl.js.map