@tamagui/select 2.7.7 → 3.0.0-0.canary.1791056644527

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 (248) hide show
  1. package/dist/cjs/Select.cjs +406 -467
  2. package/dist/cjs/Select.native.cjs +495 -0
  3. package/dist/cjs/Select.native.js +445 -492
  4. package/dist/cjs/Select.native.js.map +1 -1
  5. package/dist/cjs/SelectContent.cjs +79 -79
  6. package/dist/cjs/SelectContent.native.cjs +29 -0
  7. package/dist/cjs/SelectContent.native.js +17 -22
  8. package/dist/cjs/SelectContent.native.js.map +1 -1
  9. package/dist/cjs/SelectImpl.cjs +305 -320
  10. package/dist/cjs/SelectImpl.native.cjs +29 -0
  11. package/dist/cjs/SelectImpl.native.js +16 -24
  12. package/dist/cjs/SelectImpl.native.js.map +1 -1
  13. package/dist/cjs/SelectItem.cjs +256 -205
  14. package/dist/cjs/SelectItem.native.cjs +288 -0
  15. package/dist/cjs/SelectItem.native.js +264 -213
  16. package/dist/cjs/SelectItem.native.js.map +1 -1
  17. package/dist/cjs/SelectItemText.cjs +48 -79
  18. package/dist/cjs/SelectItemText.native.cjs +73 -0
  19. package/dist/cjs/SelectItemText.native.js +49 -79
  20. package/dist/cjs/SelectItemText.native.js.map +1 -1
  21. package/dist/cjs/SelectScrollButton.cjs +110 -130
  22. package/dist/cjs/SelectScrollButton.native.cjs +37 -0
  23. package/dist/cjs/SelectScrollButton.native.js +24 -22
  24. package/dist/cjs/SelectScrollButton.native.js.map +1 -1
  25. package/dist/cjs/SelectTrigger.cjs +81 -80
  26. package/dist/cjs/SelectTrigger.native.cjs +100 -0
  27. package/dist/cjs/SelectTrigger.native.js +79 -65
  28. package/dist/cjs/SelectTrigger.native.js.map +1 -1
  29. package/dist/cjs/SelectViewport.cjs +111 -143
  30. package/dist/cjs/SelectViewport.native.cjs +72 -0
  31. package/dist/cjs/SelectViewport.native.js +53 -50
  32. package/dist/cjs/SelectViewport.native.js.map +1 -1
  33. package/dist/cjs/constants.cjs +20 -22
  34. package/dist/cjs/constants.native.cjs +40 -0
  35. package/dist/cjs/constants.native.js +20 -21
  36. package/dist/cjs/constants.native.js.map +1 -1
  37. package/dist/cjs/context.cjs +37 -48
  38. package/dist/cjs/context.native.cjs +57 -0
  39. package/dist/cjs/context.native.js +39 -49
  40. package/dist/cjs/context.native.js.map +1 -1
  41. package/dist/cjs/index.cjs +14 -11
  42. package/dist/cjs/index.native.cjs +26 -0
  43. package/dist/cjs/index.native.js +14 -10
  44. package/dist/cjs/index.native.js.map +1 -1
  45. package/dist/cjs/selectionController.cjs +343 -0
  46. package/dist/cjs/selectionController.native.cjs +407 -0
  47. package/dist/cjs/selectionController.native.js +409 -0
  48. package/dist/cjs/selectionController.native.js.map +1 -0
  49. package/dist/cjs/types.cjs +9 -11
  50. package/dist/cjs/types.native.cjs +18 -0
  51. package/dist/cjs/types.native.js +9 -10
  52. package/dist/cjs/types.native.js.map +1 -1
  53. package/dist/esm/Select.mjs +381 -443
  54. package/dist/esm/Select.mjs.map +1 -1
  55. package/dist/esm/Select.native.js +420 -469
  56. package/dist/esm/Select.native.js.map +1 -1
  57. package/dist/esm/SelectContent.mjs +67 -61
  58. package/dist/esm/SelectContent.mjs.map +1 -1
  59. package/dist/esm/SelectContent.native.js +4 -5
  60. package/dist/esm/SelectContent.native.js.map +1 -1
  61. package/dist/esm/SelectImpl.mjs +291 -295
  62. package/dist/esm/SelectImpl.mjs.map +1 -1
  63. package/dist/esm/SelectImpl.native.js +5 -8
  64. package/dist/esm/SelectImpl.native.js.map +1 -1
  65. package/dist/esm/SelectItem.mjs +240 -181
  66. package/dist/esm/SelectItem.mjs.map +1 -1
  67. package/dist/esm/SelectItem.native.js +249 -191
  68. package/dist/esm/SelectItem.native.js.map +1 -1
  69. package/dist/esm/SelectItemText.mjs +33 -55
  70. package/dist/esm/SelectItemText.mjs.map +1 -1
  71. package/dist/esm/SelectItemText.native.js +34 -56
  72. package/dist/esm/SelectItemText.native.js.map +1 -1
  73. package/dist/esm/SelectScrollButton.mjs +95 -107
  74. package/dist/esm/SelectScrollButton.mjs.map +1 -1
  75. package/dist/esm/SelectScrollButton.native.js +11 -7
  76. package/dist/esm/SelectScrollButton.native.js.map +1 -1
  77. package/dist/esm/SelectTrigger.mjs +66 -57
  78. package/dist/esm/SelectTrigger.mjs.map +1 -1
  79. package/dist/esm/SelectTrigger.native.js +64 -43
  80. package/dist/esm/SelectTrigger.native.js.map +1 -1
  81. package/dist/esm/SelectViewport.mjs +97 -120
  82. package/dist/esm/SelectViewport.mjs.map +1 -1
  83. package/dist/esm/SelectViewport.native.js +44 -39
  84. package/dist/esm/SelectViewport.native.js.map +1 -1
  85. package/dist/esm/constants.mjs +1 -0
  86. package/dist/esm/constants.mjs.map +1 -1
  87. package/dist/esm/constants.native.js +1 -0
  88. package/dist/esm/constants.native.js.map +1 -1
  89. package/dist/esm/context.mjs +20 -28
  90. package/dist/esm/context.mjs.map +1 -1
  91. package/dist/esm/context.native.js +23 -31
  92. package/dist/esm/context.native.js.map +1 -1
  93. package/dist/esm/index.js +13 -3
  94. package/dist/esm/index.mjs +13 -3
  95. package/dist/esm/index.native.js +13 -3
  96. package/dist/esm/selectionController.mjs +315 -0
  97. package/dist/esm/selectionController.mjs.map +1 -0
  98. package/dist/esm/selectionController.native.js +377 -0
  99. package/dist/esm/selectionController.native.js.map +1 -0
  100. package/dist/esm/types.mjs +0 -2
  101. package/dist/esm/types.native.js +0 -2
  102. package/dist/jsx/Select.mjs +381 -443
  103. package/dist/jsx/Select.mjs.map +1 -1
  104. package/dist/jsx/Select.native.cjs +495 -0
  105. package/dist/jsx/Select.native.js +445 -492
  106. package/dist/jsx/Select.native.js.map +1 -1
  107. package/dist/jsx/SelectContent.mjs +67 -61
  108. package/dist/jsx/SelectContent.mjs.map +1 -1
  109. package/dist/jsx/SelectContent.native.cjs +29 -0
  110. package/dist/jsx/SelectContent.native.js +17 -22
  111. package/dist/jsx/SelectContent.native.js.map +1 -1
  112. package/dist/jsx/SelectImpl.mjs +291 -295
  113. package/dist/jsx/SelectImpl.mjs.map +1 -1
  114. package/dist/jsx/SelectImpl.native.cjs +29 -0
  115. package/dist/jsx/SelectImpl.native.js +16 -24
  116. package/dist/jsx/SelectImpl.native.js.map +1 -1
  117. package/dist/jsx/SelectItem.mjs +240 -181
  118. package/dist/jsx/SelectItem.mjs.map +1 -1
  119. package/dist/jsx/SelectItem.native.cjs +288 -0
  120. package/dist/jsx/SelectItem.native.js +264 -213
  121. package/dist/jsx/SelectItem.native.js.map +1 -1
  122. package/dist/jsx/SelectItemText.mjs +33 -55
  123. package/dist/jsx/SelectItemText.mjs.map +1 -1
  124. package/dist/jsx/SelectItemText.native.cjs +73 -0
  125. package/dist/jsx/SelectItemText.native.js +49 -79
  126. package/dist/jsx/SelectItemText.native.js.map +1 -1
  127. package/dist/jsx/SelectScrollButton.mjs +95 -107
  128. package/dist/jsx/SelectScrollButton.mjs.map +1 -1
  129. package/dist/jsx/SelectScrollButton.native.cjs +37 -0
  130. package/dist/jsx/SelectScrollButton.native.js +24 -22
  131. package/dist/jsx/SelectScrollButton.native.js.map +1 -1
  132. package/dist/jsx/SelectTrigger.mjs +66 -57
  133. package/dist/jsx/SelectTrigger.mjs.map +1 -1
  134. package/dist/jsx/SelectTrigger.native.cjs +100 -0
  135. package/dist/jsx/SelectTrigger.native.js +79 -65
  136. package/dist/jsx/SelectTrigger.native.js.map +1 -1
  137. package/dist/jsx/SelectViewport.mjs +97 -120
  138. package/dist/jsx/SelectViewport.mjs.map +1 -1
  139. package/dist/jsx/SelectViewport.native.cjs +72 -0
  140. package/dist/jsx/SelectViewport.native.js +53 -50
  141. package/dist/jsx/SelectViewport.native.js.map +1 -1
  142. package/dist/jsx/constants.mjs +1 -0
  143. package/dist/jsx/constants.mjs.map +1 -1
  144. package/dist/jsx/constants.native.cjs +40 -0
  145. package/dist/jsx/constants.native.js +20 -21
  146. package/dist/jsx/constants.native.js.map +1 -1
  147. package/dist/jsx/context.mjs +20 -28
  148. package/dist/jsx/context.mjs.map +1 -1
  149. package/dist/jsx/context.native.cjs +57 -0
  150. package/dist/jsx/context.native.js +39 -49
  151. package/dist/jsx/context.native.js.map +1 -1
  152. package/dist/jsx/index.js +13 -3
  153. package/dist/jsx/index.mjs +13 -3
  154. package/dist/jsx/index.native.cjs +26 -0
  155. package/dist/jsx/index.native.js +14 -10
  156. package/dist/jsx/index.native.js.map +1 -1
  157. package/dist/jsx/selectionController.mjs +315 -0
  158. package/dist/jsx/selectionController.mjs.map +1 -0
  159. package/dist/jsx/selectionController.native.cjs +407 -0
  160. package/dist/jsx/selectionController.native.js +409 -0
  161. package/dist/jsx/selectionController.native.js.map +1 -0
  162. package/dist/jsx/types.mjs +0 -2
  163. package/dist/jsx/types.native.cjs +18 -0
  164. package/dist/jsx/types.native.js +9 -10
  165. package/dist/jsx/types.native.js.map +1 -1
  166. package/package.json +32 -31
  167. package/src/Select.tsx +478 -378
  168. package/src/SelectContent.tsx +46 -16
  169. package/src/SelectImpl.native.tsx +0 -8
  170. package/src/SelectImpl.tsx +149 -160
  171. package/src/SelectItem.tsx +280 -159
  172. package/src/SelectItemText.tsx +16 -33
  173. package/src/SelectScrollButton.native.tsx +13 -4
  174. package/src/SelectScrollButton.tsx +57 -42
  175. package/src/SelectTrigger.tsx +94 -53
  176. package/src/SelectViewport.native.tsx +42 -25
  177. package/src/SelectViewport.tsx +67 -72
  178. package/src/context.tsx +6 -2
  179. package/src/index.tsx +5 -2
  180. package/src/selectionController.ts +404 -0
  181. package/src/types.tsx +107 -59
  182. package/types/Select.d.ts +139 -201
  183. package/types/Select.d.ts.map +1 -1
  184. package/types/SelectContent.d.ts +1 -1
  185. package/types/SelectContent.d.ts.map +1 -1
  186. package/types/SelectContent.native.d.ts.map +1 -1
  187. package/types/SelectImpl.d.ts +2 -1
  188. package/types/SelectImpl.d.ts.map +1 -1
  189. package/types/SelectImpl.native.d.ts +1 -5
  190. package/types/SelectImpl.native.d.ts.map +1 -1
  191. package/types/SelectItem.d.ts +13 -16
  192. package/types/SelectItem.d.ts.map +1 -1
  193. package/types/SelectItemText.d.ts +9 -13
  194. package/types/SelectItemText.d.ts.map +1 -1
  195. package/types/SelectScrollButton.d.ts +15 -2
  196. package/types/SelectScrollButton.d.ts.map +1 -1
  197. package/types/SelectScrollButton.native.d.ts +16 -3
  198. package/types/SelectScrollButton.native.d.ts.map +1 -1
  199. package/types/SelectTrigger.d.ts +11 -23
  200. package/types/SelectTrigger.d.ts.map +1 -1
  201. package/types/SelectViewport.d.ts +11 -38
  202. package/types/SelectViewport.d.ts.map +1 -1
  203. package/types/SelectViewport.native.d.ts +15 -4
  204. package/types/SelectViewport.native.d.ts.map +1 -1
  205. package/types/context.d.ts +2 -0
  206. package/types/context.d.ts.map +1 -1
  207. package/types/index.d.ts +5 -2
  208. package/types/index.d.ts.map +1 -1
  209. package/types/selectionController.d.ts +90 -0
  210. package/types/selectionController.d.ts.map +1 -0
  211. package/types/types.d.ts +69 -50
  212. package/types/types.d.ts.map +1 -1
  213. package/dist/cjs/BubbleSelect.cjs +0 -50
  214. package/dist/cjs/BubbleSelect.native.js +0 -30
  215. package/dist/cjs/BubbleSelect.native.js.map +0 -1
  216. package/dist/cjs/useSelectBreakpointActive.cjs +0 -32
  217. package/dist/cjs/useSelectBreakpointActive.native.js +0 -35
  218. package/dist/cjs/useSelectBreakpointActive.native.js.map +0 -1
  219. package/dist/esm/BubbleSelect.mjs +0 -27
  220. package/dist/esm/BubbleSelect.mjs.map +0 -1
  221. package/dist/esm/BubbleSelect.native.js +0 -4
  222. package/dist/esm/BubbleSelect.native.js.map +0 -1
  223. package/dist/esm/index.js.map +0 -1
  224. package/dist/esm/index.mjs.map +0 -1
  225. package/dist/esm/index.native.js.map +0 -1
  226. package/dist/esm/types.mjs.map +0 -1
  227. package/dist/esm/types.native.js.map +0 -1
  228. package/dist/esm/useSelectBreakpointActive.mjs +0 -7
  229. package/dist/esm/useSelectBreakpointActive.mjs.map +0 -1
  230. package/dist/esm/useSelectBreakpointActive.native.js +0 -7
  231. package/dist/esm/useSelectBreakpointActive.native.js.map +0 -1
  232. package/dist/jsx/BubbleSelect.mjs +0 -27
  233. package/dist/jsx/BubbleSelect.mjs.map +0 -1
  234. package/dist/jsx/BubbleSelect.native.js +0 -30
  235. package/dist/jsx/BubbleSelect.native.js.map +0 -1
  236. package/dist/jsx/index.js.map +0 -1
  237. package/dist/jsx/index.mjs.map +0 -1
  238. package/dist/jsx/types.mjs.map +0 -1
  239. package/dist/jsx/useSelectBreakpointActive.mjs +0 -7
  240. package/dist/jsx/useSelectBreakpointActive.mjs.map +0 -1
  241. package/dist/jsx/useSelectBreakpointActive.native.js +0 -35
  242. package/dist/jsx/useSelectBreakpointActive.native.js.map +0 -1
  243. package/src/BubbleSelect.tsx +0 -50
  244. package/src/useSelectBreakpointActive.tsx +0 -7
  245. package/types/BubbleSelect.d.ts +0 -2
  246. package/types/BubbleSelect.d.ts.map +0 -1
  247. package/types/useSelectBreakpointActive.d.ts +0 -3
  248. package/types/useSelectBreakpointActive.d.ts.map +0 -1
@@ -5,38 +5,41 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
5
5
  var __getProtoOf = Object.getPrototypeOf;
6
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
7
  var __export = (target, all) => {
8
- for (var name in all) __defProp(target, name, {
9
- get: all[name],
10
- enumerable: true
11
- });
8
+ for (var name in all) __defProp(target, name, {
9
+ get: all[name],
10
+ enumerable: true
11
+ });
12
12
  };
13
13
  var __copyProps = (to, from, except, desc) => {
14
- if (from && typeof from === "object" || typeof from === "function") {
15
- for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
16
- get: () => from[key],
17
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
18
- });
19
- }
20
- return to;
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
16
+ get: () => from[key],
17
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
18
+ });
19
+ }
20
+ return to;
21
21
  };
22
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
23
- // If the importer is in node compatibility mode or this is not an ESM
24
- // file that has been converted to a CommonJS file using a Babel-
25
- // compatible transform (i.e. "__esModule" has not been set), then set
26
- // "default" to the CommonJS "module.exports" for node compatibility.
27
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
28
- value: mod,
29
- enumerable: true
22
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
23
+ value: mod,
24
+ enumerable: true
30
25
  }) : target, mod));
31
- var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
32
- value: true
33
- }), mod);
26
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
34
27
  var Select_exports = {};
35
28
  __export(Select_exports, {
36
- Select: () => Select,
37
- SelectGroupFrame: () => SelectGroupFrame,
38
- SelectIcon: () => SelectIcon,
39
- SelectSeparator: () => SelectSeparator
29
+ Select: () => Select,
30
+ SelectGroup: () => SelectGroup,
31
+ SelectGroupFrame: () => SelectGroupFrame,
32
+ SelectIcon: () => SelectIcon,
33
+ SelectIndicator: () => SelectIndicator,
34
+ SelectIndicatorFrame: () => SelectIndicatorFrame,
35
+ SelectItemIndicator: () => SelectItemIndicator,
36
+ SelectItemIndicatorFrame: () => SelectItemIndicatorFrame,
37
+ SelectLabel: () => SelectLabel,
38
+ SelectLabelFrame: () => SelectLabelFrame,
39
+ SelectRoot: () => SelectRoot,
40
+ SelectSeparator: () => SelectSeparator,
41
+ SelectValue: () => SelectValue,
42
+ SelectValueFrame: () => SelectValueFrame
40
43
  });
41
44
  module.exports = __toCommonJS(Select_exports);
42
45
  var import_adapt = require("@tamagui/adapt");
@@ -45,12 +48,7 @@ var import_constants = require("@tamagui/constants");
45
48
  var import_core = require("@tamagui/core");
46
49
  var import_focus_scope = require("@tamagui/focus-scope");
47
50
  require("@tamagui/focusable");
48
- var import_get_token = require("@tamagui/get-token");
49
51
  var import_helpers = require("@tamagui/helpers");
50
- var import_separator = require("@tamagui/separator");
51
- var import_controller = require("@tamagui/sheet/controller");
52
- var import_stacks = require("@tamagui/stacks");
53
- var import_text = require("@tamagui/text");
54
52
  var import_use_controllable_state = require("@tamagui/use-controllable-state");
55
53
  var React = __toESM(require("react"), 1);
56
54
  var import_context = require("./context.cjs");
@@ -61,455 +59,396 @@ var import_SelectItemText = require("./SelectItemText.cjs");
61
59
  var import_SelectScrollButton = require("./SelectScrollButton.cjs");
62
60
  var import_SelectTrigger = require("./SelectTrigger.cjs");
63
61
  var import_SelectViewport = require("./SelectViewport.cjs");
64
- var import_useSelectBreakpointActive = require("./useSelectBreakpointActive.cjs");
62
+ var import_selectionController = require("./selectionController.cjs");
65
63
  var import_jsx_runtime = require("react/jsx-runtime");
66
- const SelectValueFrame = (0, import_core.styled)(import_text.SizableText, {
67
- name: "SelectValue",
68
- userSelect: "none"
64
+ const SelectValueFrame = (0, import_core.styled)(import_core.Text, { displayName: "SelectValue" });
65
+ const SelectValue = (0, import_core.createStyledHOC)(SelectValueFrame, function SelectValue2({ scope, children: childrenProp, placeholder, ...props }, forwardedRef) {
66
+ const context = (0, import_context.useSelectContext)(scope);
67
+ const itemParentContext = (0, import_context.useSelectItemParentContext)(scope);
68
+ const composedRefs = (0, import_compose_refs.useComposedRefs)(forwardedRef, context.onValueNodeChange);
69
+ const isEmptyValue = context.selectedValues.length === 0;
70
+ const [, rerender] = React.useReducer((version) => version + 1, 0);
71
+ (0, import_constants.useIsomorphicLayoutEffect)(() => itemParentContext.registry.subscribe(rerender), [itemParentContext.registry]);
72
+ const registeredValue = context.mode === "multiple" ? context.selectedValues.map((value, index) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(React.Fragment, { children: [index > 0 ? ", " : null, itemParentContext.registry.getItem(value)?.label ?? value] }, value)) : itemParentContext.registry.getItem(context.selectedValues[0])?.label ?? context.value;
73
+ const children = childrenProp !== void 0 ? childrenProp : context.renderValue ? context.renderValue(context.value) : registeredValue;
74
+ const selectValueChildren = isEmptyValue ? placeholder ?? children : children;
75
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SelectValueFrame, {
76
+ pointerEvents: "none",
77
+ ref: composedRefs,
78
+ ...props,
79
+ children: selectValueChildren
80
+ });
69
81
  });
70
- const SelectValue = SelectValueFrame.styleable(function SelectValue2({
71
- scope,
72
- children: childrenProp,
73
- placeholder,
74
- ...props
75
- }, forwardedRef) {
76
- const context = (0, import_context.useSelectContext)(scope);
77
- const itemParentContext = (0, import_context.useSelectItemParentContext)(scope);
78
- const composedRefs = (0, import_compose_refs.useComposedRefs)(
79
- // @ts-ignore TODO react 19 type needs fix
80
- forwardedRef, context.onValueNodeChange);
81
- const isEmptyValue = context.value == null || context.value === "";
82
- const renderedValue = context.renderValue?.(context.value);
83
- const children = childrenProp ?? renderedValue ?? itemParentContext.selectedItem ?? context.value;
84
- const selectValueChildren = isEmptyValue ? placeholder ?? children : children;
85
- return /* @__PURE__ */(0, import_jsx_runtime.jsx)(SelectValueFrame, {
86
- ...(!props.unstyled && {
87
- size: itemParentContext.size,
88
- ellipsis: true,
89
- pointerEvents: "none"
90
- }),
91
- ref: composedRefs,
92
- ...props,
93
- children: unwrapSelectItem(selectValueChildren)
94
- });
82
+ const SelectIcon = (0, import_core.styled)(import_core.View, {
83
+ displayName: "SelectIcon",
84
+ "aria-hidden": true
95
85
  });
96
- function unwrapSelectItem(selectValueChildren) {
97
- return React.Children.map(selectValueChildren, child => {
98
- if (child) {
99
- if (child.type?.staticConfig?.componentName === import_SelectItemText.ITEM_TEXT_NAME) return child.props.children;
100
- if (child.props?.children) return unwrapSelectItem(child.props.children);
101
- }
102
- return child;
103
- });
104
- }
105
- const SelectIcon = (0, import_core.styled)(import_stacks.XStack, {
106
- name: "SelectIcon",
107
- "aria-hidden": true,
108
- children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_text.Paragraph, {
109
- children: "▼"
110
- })
111
- });
112
- const SelectItemIndicatorFrame = (0, import_core.styled)(import_stacks.XStack, {
113
- name: "SelectItemIndicator"
114
- });
115
- const SelectItemIndicator = React.forwardRef(function SelectItemIndicator2(props, forwardedRef) {
116
- const {
117
- scope,
118
- ...itemIndicatorProps
119
- } = props;
120
- const context = (0, import_context.useSelectItemParentContext)(scope);
121
- const itemContext = (0, import_SelectItem.useSelectItemContext)(scope);
122
- if (context.shouldRenderWebNative) return null;
123
- return itemContext.isSelected ? /* @__PURE__ */(0, import_jsx_runtime.jsx)(SelectItemIndicatorFrame, {
124
- "aria-hidden": true,
125
- ...itemIndicatorProps,
126
- ref: forwardedRef
127
- }) : null;
86
+ const SelectItemIndicatorFrame = (0, import_core.styled)(import_core.View, { displayName: "SelectItemIndicator" });
87
+ const SelectItemIndicator = (0, import_core.createStyledHOC)(SelectItemIndicatorFrame, function SelectItemIndicator2(props, forwardedRef) {
88
+ const { scope, ...itemIndicatorProps } = props;
89
+ const context = (0, import_context.useSelectItemParentContext)(scope);
90
+ const itemContext = (0, import_SelectItem.useSelectItemContext)(scope);
91
+ if (context.shouldRenderWebNative) return null;
92
+ return itemContext.isSelected ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SelectItemIndicatorFrame, {
93
+ "aria-hidden": true,
94
+ ...itemIndicatorProps,
95
+ ref: forwardedRef
96
+ }) : null;
128
97
  });
129
- const SelectIndicatorFrame = (0, import_core.styled)(import_stacks.YStack, {
130
- name: "SelectIndicator",
131
- variants: {
132
- unstyled: {
133
- false: {
134
- position: "absolute",
135
- top: 0,
136
- left: 0,
137
- pointerEvents: "none",
138
- zIndex: 10,
139
- backgroundColor: "$background",
140
- borderRadius: 0
141
- }
142
- }
143
- },
144
- defaultVariants: {
145
- unstyled: process.env.TAMAGUI_HEADLESS === "1"
146
- }
98
+ const SelectIndicatorFrame = (0, import_core.styled)(import_core.View, {
99
+ displayName: "SelectIndicator",
100
+ position: "absolute",
101
+ top: 0,
102
+ left: 0,
103
+ pointerEvents: "none",
104
+ zIndex: 10
147
105
  });
148
- const SelectIndicator = SelectIndicatorFrame.styleable(function SelectIndicator2({
149
- scope,
150
- ...props
151
- }, forwardedRef) {
152
- const itemContext = (0, import_context.useSelectItemParentContext)(scope);
153
- const context = (0, import_context.useSelectContext)(scope);
154
- const [layout, setLayout] = React.useState(null);
155
- const rafRef = React.useRef(0);
156
- React.useLayoutEffect(() => {
157
- const update = index => {
158
- if (typeof index !== "number") return;
159
- cancelAnimationFrame(rafRef.current);
160
- rafRef.current = requestAnimationFrame(() => {
161
- const node = itemContext.listRef?.current?.[index];
162
- if (node) setLayout({
163
- width: Math.round(node.offsetWidth),
164
- height: Math.round(node.offsetHeight),
165
- x: Math.round(node.offsetLeft),
166
- y: Math.round(node.offsetTop)
167
- });
168
- });
169
- };
170
- if (context.open && context.activeIndexRef.current !== null) update(context.activeIndexRef.current);
171
- return itemContext.activeIndexSubscribe(update);
172
- }, [context.open, itemContext.listRef]);
173
- if (!layout) return null;
174
- return /* @__PURE__ */(0, import_jsx_runtime.jsx)(SelectIndicatorFrame, {
175
- ref: forwardedRef,
176
- ...props,
177
- width: layout.width,
178
- height: layout.height,
179
- x: layout.x,
180
- y: layout.y
181
- });
106
+ const SelectIndicator = (0, import_core.createStyledHOC)(SelectIndicatorFrame, function SelectIndicator2({ scope, ...props }, forwardedRef) {
107
+ const itemContext = (0, import_context.useSelectItemParentContext)(scope);
108
+ const context = (0, import_context.useSelectContext)(scope);
109
+ const [layout, setLayout] = React.useState(null);
110
+ const rafRef = React.useRef(0);
111
+ (0, import_constants.useIsomorphicLayoutEffect)(() => {
112
+ const update = (index) => {
113
+ if (typeof index !== "number") return;
114
+ cancelAnimationFrame(rafRef.current);
115
+ rafRef.current = requestAnimationFrame(() => {
116
+ const node = itemContext.listRef?.current?.[index];
117
+ if (node) setLayout({
118
+ width: Math.round(node.offsetWidth),
119
+ height: Math.round(node.offsetHeight),
120
+ x: Math.round(node.offsetLeft),
121
+ y: Math.round(node.offsetTop)
122
+ });
123
+ });
124
+ };
125
+ if (context.open && context.activeIndexRef.current !== null) update(context.activeIndexRef.current);
126
+ return itemContext.activeIndexSubscribe(update);
127
+ }, [context.open, itemContext.listRef]);
128
+ if (!layout) return null;
129
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SelectIndicatorFrame, {
130
+ ref: forwardedRef,
131
+ ...props,
132
+ width: layout.width,
133
+ height: layout.height,
134
+ x: layout.x,
135
+ y: layout.y
136
+ });
182
137
  });
183
138
  const GROUP_NAME = "SelectGroup";
184
- const {
185
- Provider: SelectGroupContextProvider,
186
- useStyledContext: useSelectGroupContext
187
- } = (0, import_core.createStyledContext)({
188
- id: ""
189
- }, "SelectGroup");
190
- const SelectGroupFrame = (0, import_core.styled)(import_stacks.YStack, {
191
- name: GROUP_NAME,
192
- width: "100%"
193
- });
194
- const NativeSelectTextFrame = (0, import_core.styled)(import_text.SizableText, {
195
- render: "select",
196
- backgroundColor: "$background",
197
- borderColor: "$borderColor",
198
- hoverStyle: {
199
- backgroundColor: "$backgroundHover"
200
- }
201
- });
202
- const NativeSelectFrame = (0, import_core.styled)(import_stacks.YStack, {
203
- name: "NativeSelect",
204
- variants: {
205
- size: {
206
- "...size": (val, extras) => {
207
- const {
208
- tokens
209
- } = extras;
210
- const paddingHorizontal = (0, import_core.getVariableValue)(tokens.space[val]);
211
- return {
212
- borderRadius: tokens.radius[val] ?? val,
213
- minHeight: tokens.size[val],
214
- paddingRight: paddingHorizontal + 20,
215
- paddingLeft: paddingHorizontal,
216
- paddingVertical: (0, import_get_token.getSpace)(val, {
217
- shift: -3
218
- })
219
- };
220
- }
221
- },
222
- unstyled: {
223
- false: {
224
- borderWidth: 1,
225
- borderColor: "$borderColor",
226
- userSelect: "none",
227
- outlineWidth: 0,
228
- paddingRight: 10
229
- }
230
- }
231
- },
232
- defaultVariants: {
233
- size: "$2",
234
- unstyled: process.env.TAMAGUI_HEADLESS === "1" ? true : false
235
- }
139
+ const { Provider: SelectGroupContextProvider, useStyledContext: useSelectGroupContext } = (0, import_core.createStyledContext)({ id: "" }, "SelectGroup");
140
+ const SelectGroupFrame = (0, import_core.styled)(import_core.View, { displayName: GROUP_NAME });
141
+ const NativeSelect = (0, import_core.styled)(import_core.Text, {
142
+ displayName: "NativeSelect",
143
+ render: "select"
236
144
  });
237
- const SelectGroup = React.forwardRef((props, forwardedRef) => {
238
- const {
239
- scope,
240
- ...groupProps
241
- } = props;
242
- const groupId = React.useId();
243
- const context = (0, import_context.useSelectContext)(scope);
244
- const itemParentContext = (0, import_context.useSelectItemParentContext)(scope);
245
- const size = itemParentContext.size ?? "$true";
246
- const nativeSelectRef = React.useRef(null);
247
- const content = (() => {
248
- if (itemParentContext.shouldRenderWebNative) return /* @__PURE__ */(0, import_jsx_runtime.jsx)(NativeSelectFrame, {
249
- asChild: true,
250
- size,
251
- value: context.value,
252
- id: itemParentContext.id,
253
- children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(NativeSelectTextFrame, {
254
- onChange: event => {
255
- itemParentContext.onChange(event.currentTarget.value);
256
- },
257
- size,
258
- ref: nativeSelectRef,
259
- style: {
260
- color: "var(--color)",
261
- appearance: "none"
262
- },
263
- children: props.children
264
- })
265
- });
266
- return /* @__PURE__ */(0, import_jsx_runtime.jsx)(SelectGroupFrame, {
267
- role: "group",
268
- "aria-labelledby": groupId,
269
- ...groupProps,
270
- ref: forwardedRef
271
- });
272
- })();
273
- return /* @__PURE__ */(0, import_jsx_runtime.jsx)(SelectGroupContextProvider, {
274
- scope,
275
- id: groupId || "",
276
- children: content
277
- });
145
+ const SelectGroup = (0, import_core.createStyledHOC)(SelectGroupFrame, (props, forwardedRef) => {
146
+ const { scope, ...groupProps } = props;
147
+ const groupId = React.useId();
148
+ const context = (0, import_context.useSelectContext)(scope);
149
+ const itemParentContext = (0, import_context.useSelectItemParentContext)(scope);
150
+ const StyledNativeSelect = React.useContext(import_context.SelectNativeComponentContext);
151
+ const nativeSelectRef = React.useRef(null);
152
+ const content = (() => {
153
+ if (itemParentContext.shouldRenderWebNative) return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(NativeSelect, {
154
+ ...StyledNativeSelect && {
155
+ render: StyledNativeSelect,
156
+ size: itemParentContext.size,
157
+ style: { appearance: "none" }
158
+ },
159
+ ...groupProps,
160
+ value: context.value,
161
+ multiple: context.mode === "multiple",
162
+ name: itemParentContext.name,
163
+ form: itemParentContext.form,
164
+ id: itemParentContext.id,
165
+ onChange: ((event) => {
166
+ const value = context.mode === "multiple" ? Array.from(event.currentTarget.selectedOptions, (option) => option.value) : event.currentTarget.value;
167
+ itemParentContext.changeNativeValue(value, event.nativeEvent);
168
+ }),
169
+ ref: nativeSelectRef,
170
+ children: props.children
171
+ });
172
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SelectGroupFrame, {
173
+ role: "group",
174
+ "aria-labelledby": groupId,
175
+ ...groupProps,
176
+ ref: forwardedRef
177
+ });
178
+ })();
179
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SelectGroupContextProvider, {
180
+ scope,
181
+ id: groupId || "",
182
+ children: content
183
+ });
278
184
  });
279
185
  SelectGroup.displayName = GROUP_NAME;
280
- const SelectLabelFrame = (0, import_core.styled)(import_text.SizableText, {
281
- name: "SelectLabel",
282
- variants: {
283
- unstyled: {
284
- false: {
285
- size: "$true",
286
- ellipsis: true,
287
- maxWidth: "100%",
288
- cursor: "default"
289
- }
290
- },
291
- size: {
292
- "...size": (val, {
293
- tokens
294
- }) => {
295
- return {
296
- paddingHorizontal: tokens.space[val],
297
- paddingVertical: (0, import_get_token.getSpace)(tokens.space[val], {
298
- shift: -4
299
- })
300
- };
301
- }
302
- }
303
- },
304
- defaultVariants: {
305
- unstyled: process.env.TAMAGUI_HEADLESS === "1"
306
- }
186
+ const SelectLabelFrame = (0, import_core.styled)(import_core.Text, { displayName: "SelectLabel" });
187
+ const SelectLabel = (0, import_core.createStyledHOC)(SelectLabelFrame, (props, forwardedRef) => {
188
+ const { scope, ...labelProps } = props;
189
+ const context = (0, import_context.useSelectItemParentContext)(scope);
190
+ const groupContext = useSelectGroupContext(scope);
191
+ if (context.shouldRenderWebNative) return null;
192
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SelectLabelFrame, {
193
+ render: "div",
194
+ id: groupContext.id,
195
+ ...labelProps,
196
+ ref: forwardedRef
197
+ });
307
198
  });
308
- const SelectLabel = SelectLabelFrame.styleable((props, forwardedRef) => {
309
- const {
310
- scope,
311
- ...labelProps
312
- } = props;
313
- const context = (0, import_context.useSelectItemParentContext)(scope);
314
- const groupContext = useSelectGroupContext(scope);
315
- if (context.shouldRenderWebNative) return null;
316
- return /* @__PURE__ */(0, import_jsx_runtime.jsx)(SelectLabelFrame, {
317
- render: "div",
318
- id: groupContext.id,
319
- size: context.size,
320
- ...labelProps,
321
- ref: forwardedRef
322
- });
323
- });
324
- const SelectSeparator = (0, import_core.styled)(import_separator.Separator, {
325
- name: "SelectSeparator"
326
- });
327
- const SelectSheetController = props => {
328
- const context = (0, import_context.useSelectContext)(props.scope);
329
- const showSheet = (0, import_useSelectBreakpointActive.useShowSelectSheet)(context);
330
- const isAdapted = (0, import_adapt.useAdaptIsActive)(context.adaptScope);
331
- const getShowSheet = (0, import_core.useGet)(showSheet);
332
- return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_controller.SheetController, {
333
- onOpenChange: val => {
334
- if (getShowSheet()) props.onOpenChange(val);
335
- },
336
- open: context.open,
337
- hidden: !isAdapted,
338
- children: props.children
339
- });
340
- };
341
- const SelectSheetImpl = props => {
342
- return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, {
343
- children: props.children
344
- });
199
+ const SelectSeparator = (0, import_core.styled)(import_core.View, { displayName: "SelectSeparator" });
200
+ const SelectSheetImpl = (props) => {
201
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: props.children });
345
202
  };
346
- const Select = (0, import_helpers.withStaticProperties)(function Select2(props) {
347
- const adaptScope = `AdaptSelect${props.scope || ""}`;
348
- return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_adapt.AdaptParent, {
349
- scope: adaptScope,
350
- portal: true,
351
- children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(SelectInner, {
352
- scope: props.scope,
353
- adaptScope,
354
- ...props
355
- })
356
- });
357
- }, {
358
- Adapt: import_adapt.Adapt,
359
- Content: import_SelectContent.SelectContent,
360
- Group: SelectGroup,
361
- Icon: SelectIcon,
362
- Item: import_SelectItem.SelectItem,
363
- ItemIndicator: SelectItemIndicator,
364
- ItemText: import_SelectItemText.SelectItemText,
365
- Label: SelectLabel,
366
- ScrollDownButton: import_SelectScrollButton.SelectScrollDownButton,
367
- ScrollUpButton: import_SelectScrollButton.SelectScrollUpButton,
368
- Trigger: import_SelectTrigger.SelectTrigger,
369
- Value: SelectValue,
370
- Viewport: import_SelectViewport.SelectViewport,
371
- Indicator: SelectIndicator,
372
- FocusScope: import_focus_scope.FocusScopeController
203
+ function SelectRoot(props) {
204
+ const adaptScope = `AdaptSelect${props.scope || ""}`;
205
+ const [open, requestOpenChange] = (0, import_use_controllable_state.useControllableState)({
206
+ prop: props.open,
207
+ defaultProp: props.defaultOpen || false,
208
+ onChange: props.onOpenChange
209
+ });
210
+ const handleAdaptOpenChange = React.useCallback((nextOpen) => {
211
+ requestOpenChange(nextOpen, (0, import_core.createChangeEventDetails)(nextOpen ? "trigger-press" : "outside-press"));
212
+ }, [requestOpenChange]);
213
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_adapt.AdaptParent, {
214
+ scope: adaptScope,
215
+ adaptChildren: props.children,
216
+ open,
217
+ onOpenChange: handleAdaptOpenChange,
218
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SelectInner, {
219
+ ...props,
220
+ scope: props.scope,
221
+ adaptScope,
222
+ open,
223
+ requestOpenChange
224
+ })
225
+ });
226
+ }
227
+ const Select = (0, import_helpers.withStaticProperties)(SelectRoot, {
228
+ Root: SelectRoot,
229
+ Adapt: import_adapt.Adapt,
230
+ Content: import_SelectContent.SelectContent,
231
+ Group: SelectGroup,
232
+ Icon: SelectIcon,
233
+ Item: import_SelectItem.SelectItem,
234
+ ItemIndicator: SelectItemIndicator,
235
+ ItemText: import_SelectItemText.SelectItemText,
236
+ Label: SelectLabel,
237
+ ScrollDownButton: import_SelectScrollButton.SelectScrollDownButton,
238
+ ScrollUpButton: import_SelectScrollButton.SelectScrollUpButton,
239
+ Separator: SelectSeparator,
240
+ Trigger: import_SelectTrigger.SelectTrigger,
241
+ Value: SelectValue,
242
+ Viewport: import_SelectViewport.SelectViewport,
243
+ Indicator: SelectIndicator,
244
+ FocusScope: import_focus_scope.FocusScopeController
373
245
  });
374
246
  function useEmitter() {
375
- const listenersRef = React.useRef(/* @__PURE__ */new Set());
376
- return [React.useCallback(value => {
377
- listenersRef.current.forEach(l => l(value));
378
- }, []), React.useCallback(listener => {
379
- listenersRef.current.add(listener);
380
- return () => {
381
- listenersRef.current.delete(listener);
382
- };
383
- }, [])];
247
+ const listenersRef = React.useRef(/* @__PURE__ */ new Set());
248
+ return [React.useCallback((value) => {
249
+ listenersRef.current.forEach((l) => l(value));
250
+ }, []), React.useCallback((listener) => {
251
+ listenersRef.current.add(listener);
252
+ return () => {
253
+ listenersRef.current.delete(listener);
254
+ };
255
+ }, [])];
384
256
  }
385
257
  function SelectInner(props) {
386
- const {
387
- scope = "",
388
- adaptScope,
389
- native,
390
- children,
391
- open: openProp,
392
- defaultOpen,
393
- onOpenChange,
394
- value: valueProp,
395
- defaultValue,
396
- onValueChange,
397
- disablePreventBodyScroll,
398
- size: sizeProp = "$true",
399
- onActiveChange,
400
- dir,
401
- id,
402
- renderValue,
403
- lazyMount,
404
- zIndex
405
- } = props;
406
- const SelectImpl = (0, import_adapt.useAdaptIsActive)(adaptScope) || !import_constants.isWeb ? SelectSheetImpl : import_SelectImpl.SelectInlineImpl;
407
- const forceUpdate = React.useReducer(() => ({}), {})[1];
408
- const [selectedItem, setSelectedItem] = React.useState(null);
409
- const [open, setOpen] = (0, import_use_controllable_state.useControllableState)({
410
- prop: openProp,
411
- defaultProp: defaultOpen || false,
412
- onChange: onOpenChange
413
- });
414
- const [value, setValue] = (0, import_use_controllable_state.useControllableState)({
415
- prop: valueProp,
416
- defaultProp: defaultValue || "",
417
- onChange: onValueChange,
418
- transition: true
419
- });
420
- React.useEffect(() => {
421
- if (open) emitValue(value);
422
- }, [open]);
423
- React.useEffect(() => {
424
- emitValue(value);
425
- }, [value]);
426
- const activeIndexRef = React.useRef(null);
427
- const [activeIndex, setActiveIndexState] = React.useState(null);
428
- const [emitValue, valueSubscribe] = useEmitter();
429
- const [emitActiveIndex, activeIndexSubscribe] = useEmitter();
430
- const selectedIndexRef = React.useRef(null);
431
- const listContentRef = React.useRef([]);
432
- const [selectedIndex, setSelectedIndex] = React.useState(0);
433
- const [valueNode, setValueNode] = React.useState(null);
434
- (0, import_constants.useIsomorphicLayoutEffect)(() => {
435
- selectedIndexRef.current = selectedIndex;
436
- });
437
- const shouldRenderWebNative = import_constants.isWeb && (native === true || native === "web" || Array.isArray(native) && native.includes("web"));
438
- const setActiveIndexFast = React.useCallback(index => {
439
- if (activeIndexRef.current !== index) {
440
- activeIndexRef.current = index;
441
- if (typeof index === "number") emitActiveIndex(index);
442
- }
443
- }, [emitActiveIndex]);
444
- const setActiveIndex = React.useCallback(index => {
445
- setActiveIndexFast(index);
446
- setActiveIndexState(index);
447
- }, [setActiveIndexFast]);
448
- const content = /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_context.SelectItemParentProvider, {
449
- scopeName: scope,
450
- scope,
451
- adaptScope,
452
- initialValue: React.useMemo(() => value, [open]),
453
- size: sizeProp,
454
- activeIndexSubscribe,
455
- activeIndexRef,
456
- valueSubscribe,
457
- setOpen,
458
- id,
459
- onChange: React.useCallback(val => {
460
- setValue(val);
461
- emitValue(val);
462
- }, []),
463
- onActiveChange: (0, import_core.useEvent)((value2, index) => {
464
- onActiveChange?.(value2, index);
465
- }),
466
- setSelectedIndex,
467
- setValueAtIndex: React.useCallback((index, value2) => {
468
- listContentRef.current[index] = value2;
469
- }, []),
470
- shouldRenderWebNative,
471
- setActiveIndexFast,
472
- selectedItem,
473
- setSelectedItem,
474
- children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_context.SelectProvider, {
475
- scope,
476
- scopeName: scope,
477
- adaptScope,
478
- disablePreventBodyScroll,
479
- dir,
480
- blockSelection: false,
481
- fallback: false,
482
- forceUpdate,
483
- valueNode,
484
- onValueNodeChange: setValueNode,
485
- activeIndex,
486
- activeIndexRef,
487
- selectedIndex,
488
- setActiveIndex,
489
- value,
490
- open,
491
- native,
492
- renderValue,
493
- lazyMount,
494
- children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(SelectSheetController, {
495
- onOpenChange: setOpen,
496
- scope,
497
- children: shouldRenderWebNative ? children : /* @__PURE__ */(0, import_jsx_runtime.jsx)(SelectImpl, {
498
- activeIndexRef,
499
- listContentRef,
500
- selectedIndexRef,
501
- setActiveIndexFast,
502
- ...props,
503
- open,
504
- value,
505
- children
506
- })
507
- })
508
- })
509
- });
510
- if (zIndex !== void 0) return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_context.SelectZIndexContext.Provider, {
511
- value: zIndex,
512
- children: content
513
- });
514
- return content;
515
- }
258
+ const { scope = "", adaptScope, native, children, open, requestOpenChange, defaultOpen: _defaultOpen, onOpenChange: _onOpenChange, value: valueProp, defaultValue, onValueChange, multiple = false, name, form, disablePreventBodyScroll, size: sizeProp = true, onActiveChange, dir, id, renderValue, lazyMount, zIndex } = props;
259
+ const SelectImpl = (0, import_adapt.useAdaptIsActive)(adaptScope) ? SelectSheetImpl : import_SelectImpl.SelectInlineImpl;
260
+ const mode = multiple ? "multiple" : "single";
261
+ const [valueState, requestValueChange] = (0, import_use_controllable_state.useControllableState)({
262
+ prop: valueProp,
263
+ defaultProp: defaultValue ?? (mode === "multiple" ? [] : ""),
264
+ onChange: onValueChange,
265
+ transition: true
266
+ });
267
+ const value = React.useMemo(() => mode === "multiple" ? (0, import_selectionController.selectedValuesFromSelection)(mode, valueState) : typeof valueState === "string" ? valueState : "", [mode, valueState]);
268
+ const selectedValues = React.useMemo(() => (0, import_selectionController.selectedValuesFromSelection)(mode, value), [mode, value]);
269
+ const [, rerenderRegistry] = React.useReducer((version) => version + 1, 0);
270
+ const registryRef = React.useRef(null);
271
+ if (!registryRef.current) registryRef.current = (0, import_selectionController.createSelectItemRegistry)(rerenderRegistry);
272
+ const registry = registryRef.current;
273
+ const controllerRef = React.useRef(null);
274
+ if (!controllerRef.current) controllerRef.current = (0, import_selectionController.createSelectSelectionController)({
275
+ mode,
276
+ value,
277
+ registry
278
+ });
279
+ const controller = controllerRef.current;
280
+ controller.setMode(mode);
281
+ controller.setValue(value);
282
+ React.useEffect(() => {}, [props.id, requestOpenChange]);
283
+ const activeIndexRef = React.useRef(null);
284
+ const [emitActiveIndex, activeIndexSubscribe] = useEmitter();
285
+ const selectedIndexRef = React.useRef(null);
286
+ const lastPointerRef = React.useRef({
287
+ x: -1,
288
+ y: -1
289
+ });
290
+ const listContentRef = React.useRef([]);
291
+ const listRef = React.useRef([]);
292
+ const [valueNode, setValueNode] = React.useState(null);
293
+ const selectedIndex = Math.max(0, controller.selectionAnchorIndex());
294
+ listContentRef.current = registry.getTypeaheadLabels();
295
+ const itemNodes = registry.getNodes();
296
+ listRef.current.length = itemNodes.length;
297
+ for (let i = 0; i < itemNodes.length; i++) listRef.current[i] = itemNodes[i];
298
+ (0, import_constants.useIsomorphicLayoutEffect)(() => {
299
+ selectedIndexRef.current = selectedIndex;
300
+ });
301
+ const shouldRenderWebNative = import_constants.isWeb && (native === true || native === "web" || Array.isArray(native) && native.includes("web"));
302
+ const setActiveIndex = React.useCallback((index, details) => {
303
+ if (activeIndexRef.current === index) return;
304
+ activeIndexRef.current = index;
305
+ controller.setActiveIndex(index);
306
+ emitActiveIndex(index);
307
+ if (typeof index === "number") {
308
+ const item = registry.getItems()[index];
309
+ if (item && details) onActiveChange?.(item.value, details);
310
+ }
311
+ }, [
312
+ controller,
313
+ emitActiveIndex,
314
+ onActiveChange,
315
+ registry
316
+ ]);
317
+ const activeDetails = React.useCallback((reason, index, event) => ({
318
+ reason,
319
+ event,
320
+ trigger: void 0,
321
+ index
322
+ }), []);
323
+ const moveActive = React.useCallback((direction, event) => {
324
+ const nextIndex = registry.nextEnabledIndex(activeIndexRef.current, direction);
325
+ if (nextIndex >= 0) setActiveIndex(nextIndex, activeDetails("keyboard", nextIndex, event));
326
+ }, [
327
+ activeDetails,
328
+ registry,
329
+ setActiveIndex
330
+ ]);
331
+ const typeaheadRef = React.useRef({
332
+ text: "",
333
+ timeout: null
334
+ });
335
+ const search = React.useCallback((text, event) => {
336
+ clearTimeout(typeaheadRef.current.timeout);
337
+ typeaheadRef.current.text += text;
338
+ let nextIndex = registry.findTypeaheadIndex(typeaheadRef.current.text, activeIndexRef.current);
339
+ if (nextIndex < 0 && typeaheadRef.current.text.length > 1) {
340
+ typeaheadRef.current.text = text;
341
+ nextIndex = registry.findTypeaheadIndex(text, activeIndexRef.current);
342
+ }
343
+ typeaheadRef.current.timeout = setTimeout(() => {
344
+ typeaheadRef.current.text = "";
345
+ }, 750);
346
+ if (nextIndex >= 0) setActiveIndex(nextIndex, activeDetails("keyboard", nextIndex, event));
347
+ }, [
348
+ activeDetails,
349
+ registry,
350
+ setActiveIndex
351
+ ]);
352
+ React.useEffect(() => {
353
+ return () => clearTimeout(typeaheadRef.current.timeout);
354
+ }, []);
355
+ React.useEffect(() => {
356
+ if (open) {
357
+ const nextIndex = controller.initialActiveIndex();
358
+ if (nextIndex >= 0) setActiveIndex(nextIndex, activeDetails("list-navigation", nextIndex));
359
+ } else setActiveIndex(null);
360
+ }, [
361
+ open,
362
+ selectedIndex,
363
+ registry.getItems().length
364
+ ]);
365
+ const selectValue = React.useCallback((nextItemValue, details) => {
366
+ const item = registry.getItem(nextItemValue);
367
+ if (!item || item.disabled) return;
368
+ controller.setMode(mode);
369
+ controller.setValue(value);
370
+ const previousValue = controller.value;
371
+ requestValueChange(controller.toggle(nextItemValue), details);
372
+ if (details.isCanceled) {
373
+ controller.setValue(previousValue);
374
+ return;
375
+ }
376
+ if (controller.shouldCloseOnSelect) requestOpenChange(false, (0, import_core.createChangeEventDetails)(details.reason === "keyboard" ? "keyboard" : "item-press", details.event, details.trigger));
377
+ }, [
378
+ controller,
379
+ mode,
380
+ registry,
381
+ requestOpenChange,
382
+ requestValueChange,
383
+ value
384
+ ]);
385
+ const changeNativeValue = React.useCallback((nextValue, event) => {
386
+ const details = (0, import_core.createChangeEventDetails)("native-change", event);
387
+ requestValueChange(nextValue, details);
388
+ if (!details.isCanceled) controller.setValue(nextValue);
389
+ }, [controller, requestValueChange]);
390
+ const content = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_context.SelectItemParentProvider, {
391
+ scopeName: scope,
392
+ scope,
393
+ adaptScope,
394
+ mode,
395
+ selectedValues,
396
+ registry,
397
+ size: sizeProp,
398
+ activeIndexSubscribe,
399
+ activeIndexRef,
400
+ requestOpenChange,
401
+ id,
402
+ name,
403
+ form,
404
+ selectValue,
405
+ changeNativeValue,
406
+ shouldRenderWebNative,
407
+ setActiveIndex,
408
+ selectedIndex,
409
+ lastPointerRef,
410
+ listRef,
411
+ moveActive,
412
+ search,
413
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_context.SelectProvider, {
414
+ scope,
415
+ scopeName: scope,
416
+ adaptScope,
417
+ disablePreventBodyScroll,
418
+ dir,
419
+ blockSelection: false,
420
+ fallback: false,
421
+ valueNode,
422
+ onValueNodeChange: setValueNode,
423
+ activeIndexRef,
424
+ selectedIndex,
425
+ setActiveIndex,
426
+ value,
427
+ mode,
428
+ selectedValues,
429
+ open,
430
+ native,
431
+ renderValue,
432
+ lazyMount,
433
+ children: shouldRenderWebNative ? children : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SelectImpl, {
434
+ activeIndexRef,
435
+ listContentRef,
436
+ selectedIndexRef,
437
+ ...props,
438
+ open,
439
+ value,
440
+ children
441
+ })
442
+ }), import_constants.isWeb && !shouldRenderWebNative && name ? (mode === "multiple" ? selectedValues : [value]).map((inputValue) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("input", {
443
+ type: "hidden",
444
+ name,
445
+ form,
446
+ value: inputValue
447
+ }, inputValue)) : null]
448
+ });
449
+ if (zIndex !== void 0) return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_context.SelectZIndexContext.Provider, {
450
+ value: zIndex,
451
+ children: content
452
+ });
453
+ return content;
454
+ }