@tamagui/select 1.116.1 → 1.116.2

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 (37) hide show
  1. package/dist/cjs/BubbleSelect.js +34 -0
  2. package/dist/cjs/Select.js +325 -0
  3. package/dist/cjs/SelectContent.js +45 -0
  4. package/dist/cjs/SelectImpl.js +224 -0
  5. package/dist/cjs/SelectItem.js +142 -0
  6. package/dist/cjs/SelectItemText.js +62 -0
  7. package/dist/cjs/SelectScrollButton.js +105 -0
  8. package/dist/cjs/SelectTrigger.js +84 -0
  9. package/dist/cjs/SelectViewport.js +111 -0
  10. package/dist/cjs/constants.js +27 -0
  11. package/dist/cjs/context.js +35 -0
  12. package/dist/cjs/index.js +16 -0
  13. package/dist/cjs/types.js +14 -0
  14. package/dist/cjs/useSelectBreakpointActive.js +25 -0
  15. package/package.json +23 -23
  16. package/dist/cjs/SelectContent.native.cjs +0 -28
  17. package/dist/cjs/SelectContent.native.cjs.map +0 -6
  18. package/dist/cjs/SelectImpl.native.cjs +0 -29
  19. package/dist/cjs/SelectImpl.native.cjs.map +0 -6
  20. package/dist/cjs/SelectScrollButton.native.cjs +0 -28
  21. package/dist/cjs/SelectScrollButton.native.cjs.map +0 -6
  22. package/dist/cjs/SelectViewport.native.cjs +0 -55
  23. package/dist/cjs/SelectViewport.native.cjs.map +0 -6
  24. /package/dist/cjs/{BubbleSelect.cjs.map → BubbleSelect.js.map} +0 -0
  25. /package/dist/cjs/{Select.cjs.map → Select.js.map} +0 -0
  26. /package/dist/cjs/{SelectContent.cjs.map → SelectContent.js.map} +0 -0
  27. /package/dist/cjs/{SelectImpl.cjs.map → SelectImpl.js.map} +0 -0
  28. /package/dist/cjs/{SelectItem.cjs.map → SelectItem.js.map} +0 -0
  29. /package/dist/cjs/{SelectItemText.cjs.map → SelectItemText.js.map} +0 -0
  30. /package/dist/cjs/{SelectScrollButton.cjs.map → SelectScrollButton.js.map} +0 -0
  31. /package/dist/cjs/{SelectTrigger.cjs.map → SelectTrigger.js.map} +0 -0
  32. /package/dist/cjs/{SelectViewport.cjs.map → SelectViewport.js.map} +0 -0
  33. /package/dist/cjs/{constants.cjs.map → constants.js.map} +0 -0
  34. /package/dist/cjs/{context.cjs.map → context.js.map} +0 -0
  35. /package/dist/cjs/{index.cjs.map → index.js.map} +0 -0
  36. /package/dist/cjs/{types.cjs.map → types.js.map} +0 -0
  37. /package/dist/cjs/{useSelectBreakpointActive.cjs.map → useSelectBreakpointActive.js.map} +0 -0
@@ -0,0 +1,34 @@
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 __copyProps = (to, from, except, desc) => {
7
+ if (from && typeof from == "object" || typeof from == "function")
8
+ for (let key of __getOwnPropNames(from))
9
+ !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
10
+ return to;
11
+ };
12
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
13
+ // If the importer is in node compatibility mode or this is not an ESM
14
+ // file that has been converted to a CommonJS file using a Babel-
15
+ // compatible transform (i.e. "__esModule" has not been set), then set
16
+ // "default" to the CommonJS "module.exports" for node compatibility.
17
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: !0 }) : target,
18
+ mod
19
+ ));
20
+ var import_compose_refs = require("@tamagui/compose-refs"), import_use_previous = require("@tamagui/use-previous"), React = __toESM(require("react"));
21
+ const BubbleSelect = React.forwardRef((props, forwardedRef) => {
22
+ const { value, ...selectProps } = props, ref = React.useRef(null), composedRefs = (0, import_compose_refs.useComposedRefs)(forwardedRef, ref), prevValue = (0, import_use_previous.usePrevious)(value);
23
+ return React.useEffect(() => {
24
+ const select = ref.current, selectProto = window.HTMLSelectElement.prototype, setValue = Object.getOwnPropertyDescriptor(
25
+ selectProto,
26
+ "value"
27
+ ).set;
28
+ if (prevValue !== value && setValue) {
29
+ const event = new Event("change", { bubbles: !0 });
30
+ setValue.call(select, value), select.dispatchEvent(event);
31
+ }
32
+ }, [prevValue, value]), null;
33
+ });
34
+ //# sourceMappingURL=BubbleSelect.js.map
@@ -0,0 +1,325 @@
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_focusable = require("@tamagui/focusable"), import_get_token = require("@tamagui/get-token"), import_helpers = require("@tamagui/helpers"), import_list_item = require("@tamagui/list-item"), import_separator = require("@tamagui/separator"), import_sheet = require("@tamagui/sheet"), import_stacks = require("@tamagui/stacks"), import_text = require("@tamagui/text"), import_use_controllable_state = require("@tamagui/use-controllable-state"), import_use_debounce = require("@tamagui/use-debounce"), React = __toESM(require("react")), 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), isAdapted = (0, import_adapt.useAdaptIsActive)(), 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: isAdapted === !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
+ function(props) {
194
+ const internalId = React.useId(), scopeKey = props.__scopeSelect ? Object.keys(props.__scopeSelect)[0] ?? internalId : internalId;
195
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_adapt.AdaptParent, { scope: `${scopeKey}SheetContents`, portal: !0, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SelectInner, { scopeKey, ...props }) });
196
+ },
197
+ {
198
+ Adapt: import_adapt.Adapt,
199
+ Content: import_SelectContent.SelectContent,
200
+ Group: SelectGroup,
201
+ Icon: SelectIcon,
202
+ Item: import_SelectItem.SelectItem,
203
+ ItemIndicator: SelectItemIndicator,
204
+ ItemText: import_SelectItemText.SelectItemText,
205
+ Label: SelectLabel,
206
+ ScrollDownButton: import_SelectScrollButton.SelectScrollDownButton,
207
+ ScrollUpButton: import_SelectScrollButton.SelectScrollUpButton,
208
+ Trigger: import_SelectTrigger.SelectTrigger,
209
+ Value: SelectValue,
210
+ Viewport: import_SelectViewport.SelectViewport,
211
+ Sheet: import_sheet.Sheet.Controlled
212
+ }
213
+ );
214
+ function useEmitter() {
215
+ const listeners = React.useRef();
216
+ listeners.current || (listeners.current = /* @__PURE__ */ new Set());
217
+ const emit = (value) => {
218
+ listeners.current.forEach((l) => l(value));
219
+ }, subscribe = React.useCallback((listener) => (listeners.current.add(listener), () => {
220
+ listeners.current.delete(listener);
221
+ }), []);
222
+ return [emit, subscribe];
223
+ }
224
+ function SelectInner(props) {
225
+ const {
226
+ __scopeSelect,
227
+ native,
228
+ children,
229
+ open: openProp,
230
+ defaultOpen,
231
+ onOpenChange,
232
+ value: valueProp,
233
+ defaultValue,
234
+ onValueChange,
235
+ disablePreventBodyScroll,
236
+ size: sizeProp = "$true",
237
+ onActiveChange,
238
+ dir,
239
+ id
240
+ } = props, SelectImpl = (0, import_adapt.useAdaptIsActive)() || !import_constants.isWeb ? SelectSheetImpl : import_SelectImpl.SelectInlineImpl, forceUpdate = React.useReducer(() => ({}), {})[1], [selectedItem, setSelectedItem] = React.useState(null), [open, setOpen] = (0, import_use_controllable_state.useControllableState)({
241
+ prop: openProp,
242
+ defaultProp: defaultOpen || !1,
243
+ onChange: onOpenChange
244
+ }), [value, setValue] = (0, import_use_controllable_state.useControllableState)({
245
+ prop: valueProp,
246
+ defaultProp: defaultValue || "",
247
+ onChange: onValueChange,
248
+ transition: !0
249
+ });
250
+ React.useEffect(() => {
251
+ open && emitValue(value);
252
+ }, [open]), React.useEffect(() => {
253
+ emitValue(value);
254
+ }, [value]);
255
+ 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);
256
+ (0, import_constants.useIsomorphicLayoutEffect)(() => {
257
+ selectedIndexRef.current = selectedIndex, activeIndexRef.current = activeIndex;
258
+ });
259
+ const shouldRenderWebNative = import_constants.isWeb && (native === !0 || native === "web" || Array.isArray(native) && native.includes("web")), setActiveIndexDebounced = (0, import_use_debounce.useDebounce)(
260
+ (index) => {
261
+ setActiveIndex((prev) => prev !== index ? (typeof index == "number" && emitActiveIndex(index), index) : prev);
262
+ },
263
+ 1,
264
+ {},
265
+ []
266
+ );
267
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
268
+ import_context.SelectItemParentProvider,
269
+ {
270
+ scope: __scopeSelect,
271
+ initialValue: React.useMemo(() => value, [open]),
272
+ size: sizeProp,
273
+ activeIndexSubscribe,
274
+ valueSubscribe,
275
+ setOpen,
276
+ id,
277
+ onChange: React.useCallback((val) => {
278
+ setValue(val), emitValue(val);
279
+ }, []),
280
+ onActiveChange: (0, import_core.useEvent)((...args) => {
281
+ onActiveChange?.(...args);
282
+ }),
283
+ setSelectedIndex,
284
+ setValueAtIndex: React.useCallback((index, value2) => {
285
+ listContentRef.current[index] = value2;
286
+ }, []),
287
+ shouldRenderWebNative,
288
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
289
+ import_context.SelectProvider,
290
+ {
291
+ scope: __scopeSelect,
292
+ disablePreventBodyScroll,
293
+ dir,
294
+ blockSelection: !1,
295
+ fallback: !1,
296
+ selectedItem,
297
+ setSelectedItem,
298
+ forceUpdate,
299
+ valueNode,
300
+ onValueNodeChange: setValueNode,
301
+ scopeKey: props.scopeKey,
302
+ activeIndex,
303
+ selectedIndex,
304
+ setActiveIndex: setActiveIndexDebounced,
305
+ value,
306
+ open,
307
+ native,
308
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SelectSheetController, { onOpenChange: setOpen, __scopeSelect, children: shouldRenderWebNative ? children : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
309
+ SelectImpl,
310
+ {
311
+ activeIndexRef,
312
+ listContentRef,
313
+ selectedIndexRef,
314
+ ...props,
315
+ open,
316
+ value,
317
+ children
318
+ }
319
+ ) })
320
+ }
321
+ )
322
+ }
323
+ );
324
+ }
325
+ //# sourceMappingURL=Select.js.map
@@ -0,0 +1,45 @@
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
@@ -0,0 +1,224 @@
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