@tamagui/select 3.0.0-beta.922.1 → 3.0.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 (106) hide show
  1. package/dist/cjs/Select.cjs +23 -25
  2. package/dist/cjs/Select.native.cjs +27 -26
  3. package/dist/cjs/Select.native.js +27 -26
  4. package/dist/cjs/Select.native.js.map +1 -1
  5. package/dist/cjs/SelectImpl.cjs +56 -50
  6. package/dist/cjs/SelectItem.cjs +49 -60
  7. package/dist/cjs/SelectItem.native.cjs +51 -79
  8. package/dist/cjs/SelectItem.native.js +51 -79
  9. package/dist/cjs/SelectItem.native.js.map +1 -1
  10. package/dist/cjs/SelectScrollButton.cjs +2 -2
  11. package/dist/cjs/SelectTrigger.cjs +22 -5
  12. package/dist/cjs/SelectTrigger.native.cjs +15 -5
  13. package/dist/cjs/SelectTrigger.native.js +15 -5
  14. package/dist/cjs/SelectTrigger.native.js.map +1 -1
  15. package/dist/cjs/SelectViewport.cjs +22 -30
  16. package/dist/cjs/SelectViewport.native.cjs +2 -2
  17. package/dist/cjs/SelectViewport.native.js +2 -2
  18. package/dist/cjs/SelectViewport.native.js.map +1 -1
  19. package/dist/cjs/selectionController.cjs +15 -5
  20. package/dist/cjs/selectionController.native.cjs +20 -15
  21. package/dist/cjs/selectionController.native.js +20 -15
  22. package/dist/cjs/selectionController.native.js.map +1 -1
  23. package/dist/esm/Select.mjs +27 -28
  24. package/dist/esm/Select.mjs.map +1 -1
  25. package/dist/esm/Select.native.js +31 -29
  26. package/dist/esm/Select.native.js.map +1 -1
  27. package/dist/esm/SelectImpl.mjs +56 -50
  28. package/dist/esm/SelectImpl.mjs.map +1 -1
  29. package/dist/esm/SelectItem.mjs +50 -61
  30. package/dist/esm/SelectItem.mjs.map +1 -1
  31. package/dist/esm/SelectItem.native.js +52 -80
  32. package/dist/esm/SelectItem.native.js.map +1 -1
  33. package/dist/esm/SelectScrollButton.mjs +2 -2
  34. package/dist/esm/SelectScrollButton.mjs.map +1 -1
  35. package/dist/esm/SelectTrigger.mjs +16 -5
  36. package/dist/esm/SelectTrigger.mjs.map +1 -1
  37. package/dist/esm/SelectTrigger.native.js +15 -4
  38. package/dist/esm/SelectTrigger.native.js.map +1 -1
  39. package/dist/esm/SelectViewport.mjs +22 -30
  40. package/dist/esm/SelectViewport.mjs.map +1 -1
  41. package/dist/esm/SelectViewport.native.js +3 -3
  42. package/dist/esm/SelectViewport.native.js.map +1 -1
  43. package/dist/esm/selectionController.mjs +15 -5
  44. package/dist/esm/selectionController.mjs.map +1 -1
  45. package/dist/esm/selectionController.native.js +20 -15
  46. package/dist/esm/selectionController.native.js.map +1 -1
  47. package/dist/jsx/Select.mjs +27 -28
  48. package/dist/jsx/Select.mjs.map +1 -1
  49. package/dist/jsx/Select.native.cjs +27 -26
  50. package/dist/jsx/Select.native.js +27 -26
  51. package/dist/jsx/Select.native.js.map +1 -1
  52. package/dist/jsx/SelectImpl.mjs +56 -50
  53. package/dist/jsx/SelectImpl.mjs.map +1 -1
  54. package/dist/jsx/SelectItem.mjs +50 -61
  55. package/dist/jsx/SelectItem.mjs.map +1 -1
  56. package/dist/jsx/SelectItem.native.cjs +51 -79
  57. package/dist/jsx/SelectItem.native.js +51 -79
  58. package/dist/jsx/SelectItem.native.js.map +1 -1
  59. package/dist/jsx/SelectScrollButton.mjs +2 -2
  60. package/dist/jsx/SelectScrollButton.mjs.map +1 -1
  61. package/dist/jsx/SelectTrigger.mjs +16 -5
  62. package/dist/jsx/SelectTrigger.mjs.map +1 -1
  63. package/dist/jsx/SelectTrigger.native.cjs +15 -5
  64. package/dist/jsx/SelectTrigger.native.js +15 -5
  65. package/dist/jsx/SelectTrigger.native.js.map +1 -1
  66. package/dist/jsx/SelectViewport.mjs +22 -30
  67. package/dist/jsx/SelectViewport.mjs.map +1 -1
  68. package/dist/jsx/SelectViewport.native.cjs +2 -2
  69. package/dist/jsx/SelectViewport.native.js +2 -2
  70. package/dist/jsx/SelectViewport.native.js.map +1 -1
  71. package/dist/jsx/selectionController.mjs +15 -5
  72. package/dist/jsx/selectionController.mjs.map +1 -1
  73. package/dist/jsx/selectionController.native.cjs +20 -15
  74. package/dist/jsx/selectionController.native.js +20 -15
  75. package/dist/jsx/selectionController.native.js.map +1 -1
  76. package/package.json +30 -29
  77. package/src/Select.tsx +41 -41
  78. package/src/SelectImpl.tsx +83 -81
  79. package/src/SelectItem.tsx +66 -91
  80. package/src/SelectScrollButton.tsx +2 -2
  81. package/src/SelectTrigger.tsx +19 -2
  82. package/src/SelectViewport.native.tsx +4 -4
  83. package/src/SelectViewport.tsx +21 -27
  84. package/src/selectionController.ts +20 -5
  85. package/src/types.tsx +26 -21
  86. package/types/Select.d.ts +42 -81
  87. package/types/Select.d.ts.map +1 -1
  88. package/types/SelectImpl.d.ts.map +1 -1
  89. package/types/SelectItem.d.ts +3 -5
  90. package/types/SelectItem.d.ts.map +1 -1
  91. package/types/SelectItemText.d.ts +3 -5
  92. package/types/SelectItemText.d.ts.map +1 -1
  93. package/types/SelectScrollButton.d.ts +5 -9
  94. package/types/SelectScrollButton.d.ts.map +1 -1
  95. package/types/SelectScrollButton.native.d.ts +5 -9
  96. package/types/SelectScrollButton.native.d.ts.map +1 -1
  97. package/types/SelectTrigger.d.ts +3 -5
  98. package/types/SelectTrigger.d.ts.map +1 -1
  99. package/types/SelectViewport.d.ts +4 -9
  100. package/types/SelectViewport.d.ts.map +1 -1
  101. package/types/SelectViewport.native.d.ts +4 -9
  102. package/types/SelectViewport.native.d.ts.map +1 -1
  103. package/types/selectionController.d.ts +2 -0
  104. package/types/selectionController.d.ts.map +1 -1
  105. package/types/types.d.ts +30 -21
  106. package/types/types.d.ts.map +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"SelectImpl.js","names":[],"sources":["esm/SelectImpl.js"],"sourcesContent":["import { autoUpdate, inner, offset, size, useClick, useFloatingRaw, useInnerOffset, useInteractions, useListNavigation, useRole, useTypeahead } from \"@tamagui/floating\";\nimport { useIsomorphicLayoutEffect } from \"@tamagui/constants\";\nimport { createChangeEventDetails, useEvent, useIsTouchDevice } from \"@tamagui/core\";\nimport { composeEventHandlers } from \"@tamagui/helpers\";\nimport * as React from \"react\";\nimport { flushSync } from \"react-dom\";\nimport { SCROLL_ARROW_THRESHOLD } from \"./constants\";\nimport { SelectItemParentProvider, SelectProvider, useSelectContext, useSelectItemParentContext } from \"./context\";\nimport { jsx } from \"react/jsx-runtime\";\n\nconst SelectInlineImpl = (props) => {\n\tconst { scope, children, open = false, listContentRef } = props;\n\tconst selectContext = useSelectContext(scope);\n\tconst selectItemParentContext = useSelectItemParentContext(scope);\n\tconst { setActiveIndex, selectedIndex, activeIndexRef } = selectContext;\n\tconst { requestOpenChange, registry } = selectItemParentContext;\n\tconst [scrollTop, setScrollTop] = React.useState(0);\n\tconst touch = useIsTouchDevice();\n\tconst listItemsRef = selectItemParentContext.listRef;\n\tconst overflowRef = React.useRef(null);\n\tconst upArrowRef = React.useRef(null);\n\tconst downArrowRef = React.useRef(null);\n\tconst allowSelectRef = React.useRef(false);\n\tconst allowMouseUpRef = React.useRef(true);\n\tconst selectTimeoutRef = React.useRef(null);\n\tconst latestKeyboardEventRef = React.useRef(void 0);\n\tconst state = React.useRef({\n\t\tisMouseOutside: false,\n\t\tisTyping: false\n\t});\n\tconst [controlledScrolling, setControlledScrolling] = React.useState(false);\n\tconst [fallback, setFallback] = React.useState(false);\n\tconst [innerOffset, setInnerOffset] = React.useState(0);\n\tconst [blockSelection, setBlockSelection] = React.useState(false);\n\tconst floatingStyle = React.useRef({});\n\tReact.useEffect(() => {\n\t\tif (!open) {\n\t\t\tsetScrollTop(0);\n\t\t\tsetFallback(false);\n\t\t\tsetControlledScrolling(false);\n\t\t}\n\t}, [open]);\n\tuseIsomorphicLayoutEffect(() => {\n\t\tif (!open) return;\n\t\tconst mouseUp = (e) => {\n\t\t\tif (state.current.isMouseOutside) requestOpenChange(false, createChangeEventDetails(\"outside-press\", e));\n\t\t};\n\t\tdocument.addEventListener(\"mouseup\", mouseUp);\n\t\treturn () => {\n\t\t\tdocument.removeEventListener(\"mouseup\", mouseUp);\n\t\t};\n\t}, [open]);\n\tconst { x, y, strategy, refs, update, placement: computedPlacement } = useFloatingRaw({\n\t\topen,\n\t\tplacement: \"bottom-start\",\n\t\twhileElementsMounted: autoUpdate,\n\t\tmiddleware: [\n\t\t\tsize({ apply({ rects: { reference: { width } } }) {\n\t\t\t\tObject.assign(floatingStyle.current, { minWidth: width + 8 });\n\t\t\t\tif (refs.floating.current) Object.assign(refs.floating.current.style, floatingStyle.current);\n\t\t\t} }),\n\t\t\tinner({\n\t\t\t\tlistRef: listItemsRef,\n\t\t\t\toverflowRef,\n\t\t\t\tindex: selectedIndex,\n\t\t\t\toffset: innerOffset,\n\t\t\t\tonFallbackChange: setFallback,\n\t\t\t\tpadding: 10,\n\t\t\t\tminItemsVisible: touch ? 10 : 4,\n\t\t\t\treferenceOverflowThreshold: 20\n\t\t\t}),\n\t\t\toffset({ crossAxis: -5 })\n\t\t]\n\t});\n\tconst floatingRef = refs.floating;\n\tconst showUpArrow = open && scrollTop > SCROLL_ARROW_THRESHOLD;\n\tconst showDownArrow = open && floatingRef.current && scrollTop < floatingRef.current.scrollHeight - floatingRef.current.clientHeight - SCROLL_ARROW_THRESHOLD;\n\tconst isScrollable = showDownArrow || showUpArrow;\n\tuseIsomorphicLayoutEffect(() => {\n\t\tif (typeof window === \"undefined\") return;\n\t\twindow.addEventListener(\"resize\", update);\n\t\tif (open) update();\n\t\treturn () => window.removeEventListener(\"resize\", update);\n\t}, [update, open]);\n\tconst onMatch = useEvent((index) => {\n\t\tif (!open) return;\n\t\tsetActiveIndex(index, {\n\t\t\treason: \"keyboard\",\n\t\t\tevent: latestKeyboardEventRef.current,\n\t\t\ttrigger: void 0,\n\t\t\tindex\n\t\t});\n\t});\n\tconst dataRef = React.useRef({});\n\tdataRef.current.placement = computedPlacement;\n\tconst interactionContext = {\n\t\topen,\n\t\tonOpenChange: (nextOpen, event, reason) => {\n\t\t\trequestOpenChange(nextOpen, createChangeEventDetails(reason === \"list-navigation\" ? \"keyboard\" : \"trigger-press\", event, refs.reference.current));\n\t\t},\n\t\trefs: {\n\t\t\treference: refs.reference,\n\t\t\tfloating: refs.floating,\n\t\t\tdomReference: refs.reference\n\t\t},\n\t\telements: {\n\t\t\treference: refs.reference?.current || null,\n\t\t\tfloating: refs.floating?.current || null,\n\t\t\tdomReference: refs.reference?.current || null\n\t\t},\n\t\tdataRef\n\t};\n\tconst interactionsProps = [\n\t\tuseClick(interactionContext, {\n\t\t\tevent: \"mousedown\",\n\t\t\tkeyboardHandlers: false\n\t\t}),\n\t\tuseRole(interactionContext, { role: \"listbox\" }),\n\t\tuseInnerOffset(interactionContext, {\n\t\t\tenabled: !fallback && isScrollable,\n\t\t\tonChange: setInnerOffset,\n\t\t\toverflowRef,\n\t\t\tscrollRef: refs.floating\n\t\t}),\n\t\tuseListNavigation(interactionContext, {\n\t\t\tlistRef: listItemsRef,\n\t\t\tactiveIndex: selectContext.activeIndex ?? 0,\n\t\t\tselectedIndex,\n\t\t\tonNavigate: (index) => {\n\t\t\t\tif (index !== null) setActiveIndex(index, {\n\t\t\t\t\treason: \"list-navigation\",\n\t\t\t\t\tevent: latestKeyboardEventRef.current,\n\t\t\t\t\ttrigger: void 0,\n\t\t\t\t\tindex\n\t\t\t\t});\n\t\t\t},\n\t\t\tdisabledIndices: registry.getDisabledIndices(),\n\t\t\tscrollItemIntoView: false\n\t\t}),\n\t\tuseTypeahead(interactionContext, {\n\t\t\tlistRef: listContentRef,\n\t\t\tonMatch,\n\t\t\tselectedIndex,\n\t\t\tactiveIndex: selectContext.activeIndex,\n\t\t\tonTypingChange: (e) => {\n\t\t\t\tstate.current.isTyping = e;\n\t\t\t}\n\t\t})\n\t];\n\tconst interactions = useInteractions(React.useMemo(() => {\n\t\treturn interactionsProps;\n\t}, interactionsProps));\n\tconst interactionsContext = React.useMemo(() => {\n\t\treturn {\n\t\t\t...interactions,\n\t\t\tgetReferenceProps(props2 = {}) {\n\t\t\t\treturn interactions.getReferenceProps({\n\t\t\t\t\t...props2,\n\t\t\t\t\tonKeyDown: composeEventHandlers(props2.onKeyDown, (event) => {\n\t\t\t\t\t\tlatestKeyboardEventRef.current = event.nativeEvent || event;\n\t\t\t\t\t\tif (event.key === \"Enter\" || event.code === \"Space\" || event.key === \" \" && !state.current.isTyping) {\n\t\t\t\t\t\t\tevent.preventDefault();\n\t\t\t\t\t\t\trequestOpenChange(true, createChangeEventDetails(\"keyboard\", event.nativeEvent || event, refs.reference.current));\n\t\t\t\t\t\t}\n\t\t\t\t\t})\n\t\t\t\t});\n\t\t\t},\n\t\t\tgetFloatingProps(props2) {\n\t\t\t\treturn interactions.getFloatingProps({\n\t\t\t\t\tref: refs.floating,\n\t\t\t\t\tclassName: \"Select\",\n\t\t\t\t\t...props2,\n\t\t\t\t\tstyle: {\n\t\t\t\t\t\tposition: strategy,\n\t\t\t\t\t\ttop: y ?? \"\",\n\t\t\t\t\t\tleft: x ?? \"\",\n\t\t\t\t\t\toutline: 0,\n\t\t\t\t\t\tscrollbarWidth: \"none\",\n\t\t\t\t\t\t...floatingStyle.current,\n\t\t\t\t\t\t...props2?.style\n\t\t\t\t\t},\n\t\t\t\t\tonPointerEnter() {\n\t\t\t\t\t\tsetControlledScrolling(false);\n\t\t\t\t\t\tstate.current.isMouseOutside = false;\n\t\t\t\t\t},\n\t\t\t\t\tonPointerLeave() {\n\t\t\t\t\t\tstate.current.isMouseOutside = true;\n\t\t\t\t\t},\n\t\t\t\t\tonPointerMove() {\n\t\t\t\t\t\tstate.current.isMouseOutside = false;\n\t\t\t\t\t\tsetControlledScrolling(false);\n\t\t\t\t\t},\n\t\t\t\t\tonKeyDown(event) {\n\t\t\t\t\t\tlatestKeyboardEventRef.current = event.nativeEvent || event;\n\t\t\t\t\t\tsetControlledScrolling(true);\n\t\t\t\t\t},\n\t\t\t\t\tonContextMenu(e) {\n\t\t\t\t\t\te.preventDefault();\n\t\t\t\t\t},\n\t\t\t\t\tonScroll(event) {\n\t\t\t\t\t\tflushSync(() => {\n\t\t\t\t\t\t\tsetScrollTop(event.currentTarget.scrollTop);\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t}\n\t\t};\n\t}, [\n\t\trefs.reference.current,\n\t\tx,\n\t\ty,\n\t\trefs.floating.current,\n\t\tinteractions\n\t]);\n\tuseIsomorphicLayoutEffect(() => {\n\t\tif (open) {\n\t\t\tallowMouseUpRef.current = false;\n\t\t\tselectTimeoutRef.current = setTimeout(() => {\n\t\t\t\tallowSelectRef.current = true;\n\t\t\t\tallowMouseUpRef.current = true;\n\t\t\t}, 300);\n\t\t\treturn () => {\n\t\t\t\tclearTimeout(selectTimeoutRef.current);\n\t\t\t};\n\t\t}\n\t\tallowSelectRef.current = false;\n\t\tallowMouseUpRef.current = true;\n\t\tsetInnerOffset(0);\n\t\tsetFallback(false);\n\t\tsetBlockSelection(false);\n\t}, [open]);\n\tuseIsomorphicLayoutEffect(() => {\n\t\tif (!open && state.current.isMouseOutside) state.current.isMouseOutside = false;\n\t}, [open]);\n\tReact.useEffect(() => {\n\t\tif (!open) return;\n\t\tconst scrollActiveIntoView = (index) => {\n\t\t\tif (controlledScrolling && index != null) listItemsRef.current[index]?.scrollIntoView({ block: \"nearest\" });\n\t\t\tsetScrollTop(refs.floating.current?.scrollTop ?? 0);\n\t\t};\n\t\tscrollActiveIntoView(activeIndexRef.current);\n\t\treturn selectItemParentContext.activeIndexSubscribe(scrollActiveIntoView);\n\t}, [\n\t\topen,\n\t\trefs,\n\t\tcontrolledScrolling,\n\t\tselectItemParentContext.activeIndexSubscribe\n\t]);\n\tReact.useEffect(() => {\n\t\tif (open && fallback) {\n\t\t\tif (selectedIndex != null) listItemsRef.current[selectedIndex]?.scrollIntoView({ block: \"nearest\" });\n\t\t}\n\t}, [\n\t\topen,\n\t\tfallback,\n\t\tselectedIndex\n\t]);\n\tuseIsomorphicLayoutEffect(() => {\n\t\tif (refs.floating.current && fallback) refs.floating.current.style.maxHeight = \"\";\n\t}, [refs, fallback]);\n\tconst floatingContext = React.useMemo(() => ({\n\t\trefs,\n\t\tdataRef\n\t}), [refs]);\n\treturn /* @__PURE__ */ jsx(SelectProvider, {\n\t\tscope,\n\t\t...selectContext,\n\t\tsetScrollTop,\n\t\tsetInnerOffset,\n\t\tfallback,\n\t\tfloatingContext,\n\t\tcanScrollDown: !!showDownArrow,\n\t\tcanScrollUp: !!showUpArrow,\n\t\tcontrolledScrolling,\n\t\tblockSelection,\n\t\tupArrowRef,\n\t\tdownArrowRef,\n\t\tupdate,\n\t\tchildren: /* @__PURE__ */ jsx(SelectItemParentProvider, {\n\t\t\tscope,\n\t\t\t...selectItemParentContext,\n\t\t\tallowMouseUpRef,\n\t\t\tallowSelectRef,\n\t\t\tdataRef,\n\t\t\tinteractions: interactionsContext,\n\t\t\tlistRef: listItemsRef,\n\t\t\tselectTimeoutRef,\n\t\t\tchildren\n\t\t})\n\t});\n};\n\nexport { SelectInlineImpl };"],"mappings":";;;;;;;;;;;AAUA,MAAM,oBAAoB,UAAU;CACnC,MAAM,EAAE,OAAO,UAAU,OAAO,OAAO,mBAAmB;CAC1D,MAAM,gBAAgB,iBAAiB,KAAK;CAC5C,MAAM,0BAA0B,2BAA2B,KAAK;CAChE,MAAM,EAAE,gBAAgB,eAAe,mBAAmB;CAC1D,MAAM,EAAE,mBAAmB,aAAa;CACxC,MAAM,CAAC,WAAW,gBAAgB,MAAM,SAAS,CAAC;CAClD,MAAM,QAAQ,iBAAiB;CAC/B,MAAM,eAAe,wBAAwB;CAC7C,MAAM,cAAc,MAAM,OAAO,IAAI;CACrC,MAAM,aAAa,MAAM,OAAO,IAAI;CACpC,MAAM,eAAe,MAAM,OAAO,IAAI;CACtC,MAAM,iBAAiB,MAAM,OAAO,KAAK;CACzC,MAAM,kBAAkB,MAAM,OAAO,IAAI;CACzC,MAAM,mBAAmB,MAAM,OAAO,IAAI;CAC1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CAChF,GAAG,CAAC,MAAM,QAAQ,CAAC;CACnB,MAAM,kBAAkB,MAAM,eAAe;EAC5C;EACA;CACD,IAAI,CAAC,IAAI,CAAC;CACV,OAAuB,oBAAI,gBAAgB;EAC1C;EACA,GAAG;EACH;EACA;EACA;EACA;EACA,eAAe,CAAC,CAAC;EACjB,aAAa,CAAC,CAAC;EACf;EACA;EACA;EACA;EACA;EACA,UAA0B,oBAAI,0BAA0B;GACvD;GACA,GAAG;GACH;GACA;GACA;GACA,cAAc;GACd,SAAS;GACT;GACA;EACD,CAAC;CACF,CAAC;AACF"}
1
+ {"version":3,"file":"SelectImpl.js","names":[],"sources":["esm/SelectImpl.js"],"sourcesContent":["import { autoUpdate, inner, offset, size, useClick, useFloatingRaw, useInnerOffset, useInteractions, useListNavigation, useRole, useTypeahead } from \"@tamagui/floating\";\nimport { useIsomorphicLayoutEffect } from \"@tamagui/constants\";\nimport { createChangeEventDetails, useEvent, useIsTouchDevice } from \"@tamagui/core\";\nimport { composeEventHandlers } from \"@tamagui/helpers\";\nimport * as React from \"react\";\nimport { SCROLL_ARROW_THRESHOLD } from \"./constants\";\nimport { SelectItemParentProvider, SelectProvider, useSelectContext, useSelectItemParentContext } from \"./context\";\nimport { jsx } from \"react/jsx-runtime\";\n\nconst SelectInlineImpl = (props) => {\n\tconst { scope, children, open = false, listContentRef } = props;\n\tconst selectContext = useSelectContext(scope);\n\tconst selectItemParentContext = useSelectItemParentContext(scope);\n\tconst { setActiveIndex, selectedIndex, activeIndexRef } = selectContext;\n\tconst { requestOpenChange, registry } = selectItemParentContext;\n\tconst touch = useIsTouchDevice();\n\tconst listItemsRef = selectItemParentContext.listRef;\n\tconst overflowRef = React.useRef(null);\n\tconst upArrowRef = React.useRef(null);\n\tconst downArrowRef = React.useRef(null);\n\tconst allowSelectRef = React.useRef(false);\n\tconst allowMouseUpRef = React.useRef(true);\n\tconst selectTimeoutRef = React.useRef(null);\n\tconst latestKeyboardEventRef = React.useRef(void 0);\n\tconst state = React.useRef({\n\t\tisMouseOutside: false,\n\t\tisTyping: false\n\t});\n\tconst [controlledScrolling, setControlledScrolling] = React.useState(false);\n\tconst [fallback, setFallback] = React.useState(false);\n\tconst [innerOffset, setInnerOffset] = React.useState(0);\n\tconst [blockSelection, setBlockSelection] = React.useState(false);\n\tReact.useEffect(() => {\n\t\tif (!open) {\n\t\t\tsetCanScrollUp(false);\n\t\t\tsetCanScrollDown(false);\n\t\t\tsetFallback(false);\n\t\t\tsetControlledScrolling(false);\n\t\t}\n\t}, [open]);\n\tuseIsomorphicLayoutEffect(() => {\n\t\tif (!open) return;\n\t\tconst mouseUp = (e) => {\n\t\t\tif (state.current.isMouseOutside) requestOpenChange(false, createChangeEventDetails(\"outside-press\", e));\n\t\t};\n\t\tdocument.addEventListener(\"mouseup\", mouseUp);\n\t\treturn () => {\n\t\t\tdocument.removeEventListener(\"mouseup\", mouseUp);\n\t\t};\n\t}, [open]);\n\tconst { x, y, strategy, refs, update, placement: computedPlacement } = useFloatingRaw({\n\t\topen,\n\t\tplacement: \"bottom-start\",\n\t\twhileElementsMounted: autoUpdate,\n\t\tmiddleware: [\n\t\t\tsize({ apply({ rects, elements }) {\n\t\t\t\telements.floating.style.minWidth = `${rects.reference.width + 8}px`;\n\t\t\t} }),\n\t\t\tinner({\n\t\t\t\tlistRef: listItemsRef,\n\t\t\t\toverflowRef,\n\t\t\t\tindex: selectedIndex,\n\t\t\t\toffset: innerOffset,\n\t\t\t\tonFallbackChange: setFallback,\n\t\t\t\tpadding: 10,\n\t\t\t\tminItemsVisible: touch ? 10 : 4,\n\t\t\t\treferenceOverflowThreshold: 20\n\t\t\t}),\n\t\t\toffset({ crossAxis: -4 })\n\t\t]\n\t});\n\tconst [canScrollUp, setCanScrollUp] = React.useState(false);\n\tconst [canScrollDown, setCanScrollDown] = React.useState(false);\n\tconst updateScrollArrows = React.useCallback(() => {\n\t\tconst el = refs.floating.current;\n\t\tif (!el) return;\n\t\tsetCanScrollUp(el.scrollTop > SCROLL_ARROW_THRESHOLD);\n\t\tsetCanScrollDown(el.scrollTop < el.scrollHeight - el.clientHeight - SCROLL_ARROW_THRESHOLD);\n\t}, [refs]);\n\tconst showUpArrow = open && canScrollUp;\n\tconst showDownArrow = open && canScrollDown;\n\tconst isScrollable = showDownArrow || showUpArrow;\n\tuseIsomorphicLayoutEffect(() => {\n\t\tif (open) update();\n\t}, [update, open]);\n\tconst onMatch = useEvent((index) => {\n\t\tif (!open) return;\n\t\tsetActiveIndex(index, {\n\t\t\treason: \"keyboard\",\n\t\t\tevent: latestKeyboardEventRef.current,\n\t\t\ttrigger: void 0,\n\t\t\tindex\n\t\t});\n\t});\n\tconst dataRef = React.useRef({});\n\tdataRef.current.placement = computedPlacement;\n\tconst onOpenChange = useEvent((nextOpen, event, reason) => {\n\t\trequestOpenChange(nextOpen, createChangeEventDetails(reason === \"list-navigation\" ? \"keyboard\" : \"trigger-press\", event, refs.reference.current));\n\t});\n\tconst referenceElement = refs.reference.current || null;\n\tconst floatingElement = refs.floating.current || null;\n\tconst interactionContext = React.useMemo(() => ({\n\t\topen,\n\t\tonOpenChange,\n\t\trefs: {\n\t\t\treference: refs.reference,\n\t\t\tfloating: refs.floating,\n\t\t\tdomReference: refs.reference\n\t\t},\n\t\telements: {\n\t\t\treference: referenceElement,\n\t\t\tfloating: floatingElement,\n\t\t\tdomReference: referenceElement\n\t\t},\n\t\tdataRef\n\t}), [\n\t\topen,\n\t\tonOpenChange,\n\t\trefs,\n\t\treferenceElement,\n\t\tfloatingElement\n\t]);\n\tconst interactionsProps = [\n\t\tuseClick(interactionContext, {\n\t\t\tevent: \"mousedown\",\n\t\t\tkeyboardHandlers: false\n\t\t}),\n\t\tuseRole(interactionContext, { role: \"listbox\" }),\n\t\tuseInnerOffset(interactionContext, {\n\t\t\tenabled: !fallback && isScrollable,\n\t\t\tonChange: setInnerOffset,\n\t\t\toverflowRef,\n\t\t\tscrollRef: refs.floating\n\t\t}),\n\t\tuseListNavigation(interactionContext, {\n\t\t\tlistRef: listItemsRef,\n\t\t\tactiveIndex: null,\n\t\t\tselectedIndex,\n\t\t\tonNavigate: (index) => {\n\t\t\t\tif (index !== null) setActiveIndex(index, {\n\t\t\t\t\treason: \"list-navigation\",\n\t\t\t\t\tevent: latestKeyboardEventRef.current,\n\t\t\t\t\ttrigger: void 0,\n\t\t\t\t\tindex\n\t\t\t\t});\n\t\t\t},\n\t\t\tdisabledIndices: registry.getDisabledIndices(),\n\t\t\tscrollItemIntoView: false,\n\t\t\tfocusItemOnHover: false\n\t\t}),\n\t\tuseTypeahead(interactionContext, {\n\t\t\tlistRef: listContentRef,\n\t\t\tonMatch,\n\t\t\tselectedIndex,\n\t\t\tactiveIndex: null,\n\t\t\tonTypingChange: (e) => {\n\t\t\t\tstate.current.isTyping = e;\n\t\t\t}\n\t\t})\n\t];\n\tconst interactions = useInteractions(React.useMemo(() => {\n\t\treturn interactionsProps;\n\t}, interactionsProps));\n\tconst interactionsContext = React.useMemo(() => {\n\t\treturn {\n\t\t\tgetReferenceProps(props2 = {}) {\n\t\t\t\treturn interactions.getReferenceProps({\n\t\t\t\t\t...props2,\n\t\t\t\t\tonKeyDown: composeEventHandlers(props2.onKeyDown, (event) => {\n\t\t\t\t\t\tlatestKeyboardEventRef.current = event.nativeEvent || event;\n\t\t\t\t\t\tif (event.key === \"Enter\" || event.code === \"Space\" || event.key === \" \" && !state.current.isTyping) {\n\t\t\t\t\t\t\tevent.preventDefault();\n\t\t\t\t\t\t\trequestOpenChange(true, createChangeEventDetails(\"keyboard\", event.nativeEvent || event, refs.reference.current));\n\t\t\t\t\t\t}\n\t\t\t\t\t})\n\t\t\t\t});\n\t\t\t},\n\t\t\tgetFloatingProps(props2) {\n\t\t\t\treturn interactions.getFloatingProps({\n\t\t\t\t\tref: refs.floating,\n\t\t\t\t\t...props2,\n\t\t\t\t\tonPointerEnter() {\n\t\t\t\t\t\tsetControlledScrolling(false);\n\t\t\t\t\t\tstate.current.isMouseOutside = false;\n\t\t\t\t\t},\n\t\t\t\t\tonPointerLeave() {\n\t\t\t\t\t\tstate.current.isMouseOutside = true;\n\t\t\t\t\t},\n\t\t\t\t\tonPointerMove() {\n\t\t\t\t\t\tstate.current.isMouseOutside = false;\n\t\t\t\t\t\tsetControlledScrolling(false);\n\t\t\t\t\t},\n\t\t\t\t\tonKeyDown(event) {\n\t\t\t\t\t\tlatestKeyboardEventRef.current = event.nativeEvent || event;\n\t\t\t\t\t\tsetControlledScrolling(true);\n\t\t\t\t\t},\n\t\t\t\t\tonContextMenu(e) {\n\t\t\t\t\t\te.preventDefault();\n\t\t\t\t\t},\n\t\t\t\t\tonScroll: updateScrollArrows\n\t\t\t\t});\n\t\t\t}\n\t\t};\n\t}, [\n\t\trefs,\n\t\tinteractions,\n\t\trequestOpenChange,\n\t\tupdateScrollArrows\n\t]);\n\tconst floatingPosition = React.useMemo(() => ({\n\t\tposition: strategy,\n\t\ttop: y ?? \"\",\n\t\tleft: x ?? \"\"\n\t}), [\n\t\tstrategy,\n\t\tx,\n\t\ty\n\t]);\n\tuseIsomorphicLayoutEffect(() => {\n\t\tif (open) {\n\t\t\tallowMouseUpRef.current = false;\n\t\t\tselectTimeoutRef.current = setTimeout(() => {\n\t\t\t\tallowSelectRef.current = true;\n\t\t\t\tallowMouseUpRef.current = true;\n\t\t\t}, 300);\n\t\t\treturn () => {\n\t\t\t\tclearTimeout(selectTimeoutRef.current);\n\t\t\t};\n\t\t}\n\t\tallowSelectRef.current = false;\n\t\tallowMouseUpRef.current = true;\n\t\tsetInnerOffset(0);\n\t\tsetFallback(false);\n\t\tsetBlockSelection(false);\n\t}, [open]);\n\tuseIsomorphicLayoutEffect(() => {\n\t\tif (!open && state.current.isMouseOutside) state.current.isMouseOutside = false;\n\t}, [open]);\n\tReact.useEffect(() => {\n\t\tif (!open) return;\n\t\tconst scrollActiveIntoView = (index) => {\n\t\t\tif (controlledScrolling && index != null) listItemsRef.current[index]?.scrollIntoView({ block: \"nearest\" });\n\t\t\tupdateScrollArrows();\n\t\t};\n\t\tscrollActiveIntoView(activeIndexRef.current);\n\t\treturn selectItemParentContext.activeIndexSubscribe(scrollActiveIntoView);\n\t}, [\n\t\topen,\n\t\tcontrolledScrolling,\n\t\tselectItemParentContext.activeIndexSubscribe,\n\t\tupdateScrollArrows\n\t]);\n\tReact.useEffect(() => {\n\t\tif (open && fallback) {\n\t\t\tif (selectedIndex != null) listItemsRef.current[selectedIndex]?.scrollIntoView({ block: \"nearest\" });\n\t\t}\n\t}, [\n\t\topen,\n\t\tfallback,\n\t\tselectedIndex\n\t]);\n\tuseIsomorphicLayoutEffect(() => {\n\t\tif (refs.floating.current && fallback) refs.floating.current.style.maxHeight = \"\";\n\t}, [refs, fallback]);\n\tconst floatingContext = React.useMemo(() => ({\n\t\trefs,\n\t\tdataRef\n\t}), [refs]);\n\treturn /* @__PURE__ */ jsx(SelectProvider, {\n\t\tscope,\n\t\t...selectContext,\n\t\tupdateScrollArrows,\n\t\tsetInnerOffset,\n\t\tfallback,\n\t\tfloatingContext,\n\t\tinteractions: interactionsContext,\n\t\tfloatingPosition,\n\t\tcanScrollDown: !!showDownArrow,\n\t\tcanScrollUp: !!showUpArrow,\n\t\tcontrolledScrolling,\n\t\tblockSelection,\n\t\tupArrowRef,\n\t\tdownArrowRef,\n\t\tupdate,\n\t\tchildren: /* @__PURE__ */ jsx(SelectItemParentProvider, {\n\t\t\tscope,\n\t\t\t...selectItemParentContext,\n\t\t\tallowMouseUpRef,\n\t\t\tallowSelectRef,\n\t\t\tdataRef,\n\t\t\tgetItemProps: interactions.getItemProps,\n\t\t\tlistRef: listItemsRef,\n\t\t\tselectTimeoutRef,\n\t\t\tchildren\n\t\t})\n\t});\n};\n\nexport { SelectInlineImpl };"],"mappings":";;;;;;;;;;AASA,MAAM,oBAAoB,UAAU;CACnC,MAAM,EAAE,OAAO,UAAU,OAAO,OAAO,mBAAmB;CAC1D,MAAM,gBAAgB,iBAAiB,KAAK;CAC5C,MAAM,0BAA0B,2BAA2B,KAAK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zE,GAAG;EACF;EACA;EACA,wBAAwB;EACxB;CACD,CAAC;CACD,MAAM,gBAAgB;EACrB,IAAI,QAAQ,UAAU;GACrB,IAAI,iBAAiB,MAAM,aAAa,QAAQ,cAAc,EAAE,eAAe,EAAE,OAAO,UAAU,CAAC;EACpG;CACD,GAAG;EACF;EACA;EACA;CACD,CAAC;CACD,gCAAgC;EAC/B,IAAI,KAAK,SAAS,WAAW,UAAU,KAAK,SAAS,QAAQ,MAAM,YAAY;CAChF,GAAG,CAAC,MAAM,QAAQ,CAAC;CACnB,MAAM,kBAAkB,MAAM,eAAe;EAC5C;EACA;CACD,IAAI,CAAC,IAAI,CAAC;CACV,OAAuB,oBAAI,gBAAgB;EAC1C;EACA,GAAG;EACH;EACA;EACA;EACA;EACA,cAAc;EACd;EACA,eAAe,CAAC,CAAC;EACjB,aAAa,CAAC,CAAC;EACf;EACA;EACA;EACA;EACA;EACA,UAA0B,oBAAI,0BAA0B;GACvD;GACA,GAAG;GACH;GACA;GACA;GACA,cAAc,aAAa;GAC3B,SAAS;GACT;GACA;EACD,CAAC;CACF,CAAC;AACF"}
@@ -4,7 +4,7 @@ import { isWeb, useIsomorphicLayoutEffect } from "@tamagui/constants";
4
4
  import { View, createChangeEventDetails, createStyledContext, createStyledHOC, styled } from "@tamagui/core";
5
5
  import { composeEventHandlers } from "@tamagui/helpers";
6
6
  import * as React from "react";
7
- import { useSelectContext, useSelectItemParentContext } from "./context.mjs";
7
+ import { useSelectItemParentContext } from "./context.mjs";
8
8
  import { getSelectOptionProps } from "./selectionController.mjs";
9
9
  import { jsx } from "react/jsx-runtime";
10
10
 
@@ -19,34 +19,22 @@ const SelectItem = createStyledHOC(SelectItemFrame, function SelectItem2(props,
19
19
  const { scope, value, disabled: disabledProp, "aria-disabled": ariaDisabled, textValue: textValueProp, ...restProps } = props;
20
20
  const disabled = disabledProp ?? ariaDisabled === true;
21
21
  const context = useSelectItemParentContext(scope);
22
- const selectContext = useSelectContext(scope);
23
- const isAdapted = useAdaptIsActive(selectContext.adaptScope);
24
- const { listRef, registry, mode, selectedValues, selectValue, activeIndexSubscribe, activeIndexRef, allowMouseUpRef, allowSelectRef, selectTimeoutRef, interactions, shouldRenderWebNative, setActiveIndexFast, moveActive, search } = context;
22
+ const isAdapted = useAdaptIsActive(context.adaptScope);
23
+ const { registry, mode, selectedValues, selectValue, activeIndexSubscribe, activeIndexRef, allowMouseUpRef, allowSelectRef, selectTimeoutRef, getItemProps, shouldRenderWebNative, setActiveIndex, lastPointerRef, moveActive, search } = context;
25
24
  const isSelected = selectedValues.includes(value);
26
25
  const pendingMouseUpSelectionRef = React.useRef(false);
27
26
  const itemNodeRef = React.useRef(null);
28
- const [, rerenderRegistry] = React.useReducer((version) => version + 1, 0);
29
27
  const registrationRef = React.useRef(null);
30
28
  const initialRegistration = React.useRef({
31
29
  value,
32
30
  disabled,
33
31
  textValue: textValueProp
34
32
  });
35
- useIsomorphicLayoutEffect(() => registry.subscribe(() => rerenderRegistry()), [registry]);
36
33
  useIsomorphicLayoutEffect(() => {
37
34
  const registration = registry.registerItem(initialRegistration.current);
38
35
  registrationRef.current = registration;
39
- const registeredNode = itemNodeRef.current;
40
- registration.setNode(registeredNode);
41
- const registeredIndex = registry.getItems().findIndex((item) => item.id === registration.id);
42
- if (isWeb && listRef && registeredIndex >= 0 && registeredNode instanceof HTMLElement) {
43
- listRef.current[registeredIndex] = registeredNode;
44
- }
36
+ registration.setNode(itemNodeRef.current);
45
37
  return () => {
46
- const currentIndex = registry.getItems().findIndex((item) => item.id === registration.id);
47
- if (listRef && currentIndex >= 0 && listRef.current[currentIndex] === registeredNode) {
48
- listRef.current[currentIndex] = null;
49
- }
50
38
  registrationRef.current = null;
51
39
  registration.unregister();
52
40
  };
@@ -65,37 +53,34 @@ const SelectItem = createStyledHOC(SelectItemFrame, function SelectItem2(props,
65
53
  useIsomorphicLayoutEffect(() => {
66
54
  registrationRef.current?.setNode(itemNodeRef.current);
67
55
  });
68
- const index = registry.getIndex(value);
56
+ const [isActive, setIsActive] = React.useState(false);
57
+ const isActiveRef = React.useRef(false);
69
58
  React.useEffect(() => {
70
59
  const handleActiveIndex = (i) => {
71
- if (index === i) {
72
- if (isWeb) {
73
- requestAnimationFrame(() => {
74
- listRef?.current[index]?.focus();
75
- });
76
- }
60
+ const next = i != null && registry.getIndex(value) === i;
61
+ if (next !== isActiveRef.current) {
62
+ isActiveRef.current = next;
63
+ setIsActive(next);
64
+ }
65
+ if (next && isWeb) {
66
+ requestAnimationFrame(() => {
67
+ itemNodeRef.current?.focus?.();
68
+ });
77
69
  }
78
70
  };
79
- const currentActiveIndex = activeIndexRef?.current;
80
- if (currentActiveIndex !== null && currentActiveIndex !== void 0) {
81
- handleActiveIndex(currentActiveIndex);
82
- }
71
+ handleActiveIndex(activeIndexRef?.current ?? null);
83
72
  return activeIndexSubscribe(handleActiveIndex);
84
73
  }, [
85
74
  activeIndexRef,
86
75
  activeIndexSubscribe,
87
- index,
88
- listRef
76
+ registry,
77
+ value
89
78
  ]);
90
79
  const textId = React.useId();
91
80
  const refCallback = React.useCallback((node) => {
92
81
  itemNodeRef.current = node;
93
82
  registrationRef.current?.setNode(node);
94
- if (!isWeb) return;
95
- if (listRef && index >= 0) {
96
- listRef.current[index] = node instanceof HTMLElement ? node : null;
97
- }
98
- }, [index, listRef]);
83
+ }, []);
99
84
  const composedRefs = useComposedRefs(forwardedRef, refCallback);
100
85
  const handleSelect = React.useCallback((event, reason = "item-press") => {
101
86
  if (disabled) return;
@@ -106,6 +91,27 @@ const SelectItem = createStyledHOC(SelectItemFrame, function SelectItem2(props,
106
91
  selectValue,
107
92
  value
108
93
  ]);
94
+ const handleMouseMove = React.useCallback((event) => {
95
+ if (disabled) return;
96
+ const index = registry.getIndex(value);
97
+ if (index < 0) return;
98
+ const last = lastPointerRef.current;
99
+ if (event.clientX === last.x && event.clientY === last.y) return;
100
+ last.x = event.clientX;
101
+ last.y = event.clientY;
102
+ setActiveIndex(index, {
103
+ reason: "item-hover",
104
+ event: event.nativeEvent || event,
105
+ trigger: event.currentTarget,
106
+ index
107
+ });
108
+ }, [
109
+ disabled,
110
+ lastPointerRef,
111
+ registry,
112
+ setActiveIndex,
113
+ value
114
+ ]);
109
115
  const handleKeyDown = React.useCallback((event) => {
110
116
  if (disabled) return;
111
117
  if (event.key === "Enter" || event.key === " ") {
@@ -119,7 +125,7 @@ const SelectItem = createStyledHOC(SelectItemFrame, function SelectItem2(props,
119
125
  moveActive(event.key === "ArrowDown" ? 1 : -1, event.nativeEvent || event);
120
126
  return;
121
127
  }
122
- if (!interactions && event.key?.length === 1 && !event.metaKey && !event.ctrlKey) {
128
+ if (!getItemProps && event.key?.length === 1 && !event.metaKey && !event.ctrlKey) {
123
129
  search(event.key, event.nativeEvent || event);
124
130
  }
125
131
  if (allowSelectRef) {
@@ -129,14 +135,14 @@ const SelectItem = createStyledHOC(SelectItemFrame, function SelectItem2(props,
129
135
  allowSelectRef,
130
136
  disabled,
131
137
  handleSelect,
132
- interactions,
138
+ getItemProps,
133
139
  moveActive,
134
140
  search
135
141
  ]);
136
142
  const selectItemProps = React.useMemo(() => {
137
- if (interactions) {
143
+ if (getItemProps) {
138
144
  const { onTouchMove, onTouchEnd, onKeyDown, onClick, onMouseUp, onMouseMove, onPress, ...itemProps } = restProps;
139
- const interactionProps = interactions.getItemProps({
145
+ const interactionProps = getItemProps({
140
146
  ...itemProps,
141
147
  onTouchMove() {
142
148
  allowSelectRef.current = true;
@@ -146,15 +152,7 @@ const SelectItem = createStyledHOC(SelectItemFrame, function SelectItem2(props,
146
152
  allowSelectRef.current = false;
147
153
  allowMouseUpRef.current = true;
148
154
  },
149
- onMouseMove(event) {
150
- if (disabled || index < 0) return;
151
- setActiveIndexFast?.(index, {
152
- reason: "item-hover",
153
- event: event.nativeEvent || event,
154
- trigger: event.currentTarget,
155
- index
156
- });
157
- },
155
+ onMouseMove: handleMouseMove,
158
156
  onKeyDown: handleKeyDown,
159
157
  onClick(event) {
160
158
  if (disabled) return;
@@ -207,15 +205,7 @@ const SelectItem = createStyledHOC(SelectItemFrame, function SelectItem2(props,
207
205
  return {
208
206
  ...restProps,
209
207
  onKeyDown: composeEventHandlers(restProps.onKeyDown, handleKeyDown),
210
- onMouseMove: composeEventHandlers(restProps.onMouseMove, (event) => {
211
- if (disabled || index < 0) return;
212
- setActiveIndexFast?.(index, {
213
- reason: "item-hover",
214
- event: event.nativeEvent || event,
215
- trigger: event.currentTarget,
216
- index
217
- });
218
- }),
208
+ onMouseMove: composeEventHandlers(restProps.onMouseMove, handleMouseMove),
219
209
  onPress: composeEventHandlers(restProps.onPress, handleSelect)
220
210
  };
221
211
  }, [
@@ -223,12 +213,11 @@ const SelectItem = createStyledHOC(SelectItemFrame, function SelectItem2(props,
223
213
  allowSelectRef,
224
214
  disabled,
225
215
  handleKeyDown,
216
+ handleMouseMove,
226
217
  handleSelect,
227
- index,
228
- interactions,
218
+ getItemProps,
229
219
  restProps,
230
- selectTimeoutRef,
231
- setActiveIndexFast
220
+ selectTimeoutRef
232
221
  ]);
233
222
  const accessibilityProps = getSelectOptionProps(mode, isSelected, disabled, isWeb ? "web" : "native");
234
223
  return /* @__PURE__ */ jsx(SelectItemContextProvider, {
@@ -247,7 +236,7 @@ const SelectItem = createStyledHOC(SelectItemFrame, function SelectItem2(props,
247
236
  "aria-labelledby": textId,
248
237
  "data-state": isSelected ? "active" : "inactive",
249
238
  "data-disabled": disabled ? "" : void 0,
250
- tabIndex: disabled ? void 0 : isWeb && isAdapted ? index === (selectContext.activeIndex ?? selectContext.selectedIndex) ? 0 : -1 : -1,
239
+ tabIndex: disabled ? void 0 : isWeb && isAdapted && (isActive || activeIndexRef?.current == null && isSelected) ? 0 : -1,
251
240
  zIndex: 100,
252
241
  ...selectItemProps,
253
242
  ...accessibilityProps
@@ -1 +1 @@
1
- {"version":3,"file":"SelectItem.js","names":[],"sources":["esm/SelectItem.js"],"sourcesContent":["import { useComposedRefs } from \"@tamagui/compose-refs\";\nimport { useAdaptIsActive } from \"@tamagui/adapt\";\nimport { isWeb, useIsomorphicLayoutEffect } from \"@tamagui/constants\";\nimport {\n createChangeEventDetails,\n createStyledHOC,\n createStyledContext,\n styled,\n View\n} from \"@tamagui/core\";\nimport { composeEventHandlers } from \"@tamagui/helpers\";\nimport * as React from \"react\";\nimport { useSelectContext, useSelectItemParentContext } from \"./context\";\nimport { getSelectOptionProps } from \"./selectionController\";\nimport { jsx } from \"react/jsx-runtime\";\nconst ITEM_NAME = \"SelectItem\";\nconst {\n Provider: SelectItemContextProvider,\n useStyledContext: useSelectItemContext\n} = createStyledContext(null, ITEM_NAME);\nconst SelectItemFrame = styled(View, {\n displayName: ITEM_NAME,\n alignItems: \"center\",\n flexDirection: \"row\"\n});\nconst SelectItem = createStyledHOC(\n SelectItemFrame,\n function SelectItem2(props, forwardedRef) {\n const {\n scope,\n value,\n disabled: disabledProp,\n \"aria-disabled\": ariaDisabled,\n textValue: textValueProp,\n ...restProps\n } = props;\n const disabled = disabledProp ?? ariaDisabled === true;\n const context = useSelectItemParentContext(scope);\n const selectContext = useSelectContext(scope);\n const isAdapted = useAdaptIsActive(selectContext.adaptScope);\n const {\n listRef,\n registry,\n mode,\n selectedValues,\n selectValue,\n activeIndexSubscribe,\n activeIndexRef,\n allowMouseUpRef,\n allowSelectRef,\n selectTimeoutRef,\n interactions,\n shouldRenderWebNative,\n setActiveIndexFast,\n moveActive,\n search\n } = context;\n const isSelected = selectedValues.includes(value);\n const pendingMouseUpSelectionRef = React.useRef(false);\n const itemNodeRef = React.useRef(null);\n const [, rerenderRegistry] = React.useReducer((version) => version + 1, 0);\n const registrationRef = React.useRef(\n null\n );\n const initialRegistration = React.useRef({\n value,\n disabled,\n textValue: textValueProp\n });\n useIsomorphicLayoutEffect(\n () => registry.subscribe(() => rerenderRegistry()),\n [registry]\n );\n useIsomorphicLayoutEffect(() => {\n const registration = registry.registerItem(initialRegistration.current);\n registrationRef.current = registration;\n const registeredNode = itemNodeRef.current;\n registration.setNode(registeredNode);\n const registeredIndex = registry.getItems().findIndex((item) => item.id === registration.id);\n if (isWeb && listRef && registeredIndex >= 0 && registeredNode instanceof HTMLElement) {\n listRef.current[registeredIndex] = registeredNode;\n }\n return () => {\n const currentIndex = registry.getItems().findIndex((item) => item.id === registration.id);\n if (listRef && currentIndex >= 0 && listRef.current[currentIndex] === registeredNode) {\n listRef.current[currentIndex] = null;\n }\n registrationRef.current = null;\n registration.unregister();\n };\n }, [registry]);\n useIsomorphicLayoutEffect(() => {\n registrationRef.current?.update({ value, disabled, textValue: textValueProp });\n }, [disabled, textValueProp, value]);\n useIsomorphicLayoutEffect(() => {\n registrationRef.current?.setNode(itemNodeRef.current);\n });\n const index = registry.getIndex(value);\n React.useEffect(() => {\n const handleActiveIndex = (i) => {\n if (index === i) {\n if (isWeb) {\n requestAnimationFrame(() => {\n listRef?.current[index]?.focus();\n });\n }\n }\n };\n const currentActiveIndex = activeIndexRef?.current;\n if (currentActiveIndex !== null && currentActiveIndex !== void 0) {\n handleActiveIndex(currentActiveIndex);\n }\n return activeIndexSubscribe(handleActiveIndex);\n }, [activeIndexRef, activeIndexSubscribe, index, listRef]);\n const textId = React.useId();\n const refCallback = React.useCallback(\n (node) => {\n itemNodeRef.current = node;\n registrationRef.current?.setNode(node);\n if (!isWeb) return;\n if (listRef && index >= 0) {\n listRef.current[index] = node instanceof HTMLElement ? node : null;\n }\n },\n [index, listRef]\n );\n const composedRefs = useComposedRefs(forwardedRef, refCallback);\n const handleSelect = React.useCallback(\n (event, reason = \"item-press\") => {\n if (disabled) return;\n const nativeEvent = event?.nativeEvent || event;\n selectValue(\n value,\n createChangeEventDetails(\n reason,\n nativeEvent,\n event?.currentTarget\n )\n );\n },\n [disabled, selectValue, value]\n );\n const handleKeyDown = React.useCallback(\n (event) => {\n if (disabled) return;\n if (event.key === \"Enter\" || event.key === \" \") {\n event.preventDefault();\n handleSelect(event, \"keyboard\");\n return;\n }\n if (event.key === \"ArrowDown\" || event.key === \"ArrowUp\") {\n event.preventDefault();\n event.stopPropagation();\n moveActive(event.key === \"ArrowDown\" ? 1 : -1, event.nativeEvent || event);\n return;\n }\n if (!interactions && event.key?.length === 1 && !event.metaKey && !event.ctrlKey) {\n search(event.key, event.nativeEvent || event);\n }\n if (allowSelectRef) {\n allowSelectRef.current = true;\n }\n },\n [allowSelectRef, disabled, handleSelect, interactions, moveActive, search]\n );\n const selectItemProps = React.useMemo(() => {\n if (interactions) {\n const {\n onTouchMove,\n onTouchEnd,\n onKeyDown,\n onClick,\n onMouseUp,\n onMouseMove,\n onPress,\n ...itemProps\n } = restProps;\n const interactionProps = interactions.getItemProps({\n ...itemProps,\n onTouchMove() {\n allowSelectRef.current = true;\n allowMouseUpRef.current = false;\n },\n onTouchEnd() {\n allowSelectRef.current = false;\n allowMouseUpRef.current = true;\n },\n onMouseMove(event) {\n if (disabled || index < 0) return;\n setActiveIndexFast?.(index, {\n reason: \"item-hover\",\n event: event.nativeEvent || event,\n trigger: event.currentTarget,\n index\n });\n },\n onKeyDown: handleKeyDown,\n onClick(event) {\n if (disabled) return;\n const shouldSelect = pendingMouseUpSelectionRef.current || allowSelectRef.current;\n pendingMouseUpSelectionRef.current = false;\n clearTimeout(selectTimeoutRef.current);\n allowSelectRef.current = true;\n if (shouldSelect) {\n handleSelect(event);\n }\n },\n onMouseUp(event) {\n if (disabled) return;\n if (!allowMouseUpRef.current) {\n allowMouseUpRef.current = true;\n allowSelectRef.current = true;\n return;\n }\n pendingMouseUpSelectionRef.current = allowSelectRef.current;\n clearTimeout(selectTimeoutRef.current);\n selectTimeoutRef.current = setTimeout(() => {\n allowSelectRef.current = true;\n if (pendingMouseUpSelectionRef.current) {\n pendingMouseUpSelectionRef.current = false;\n handleSelect(event);\n }\n });\n }\n });\n return {\n ...interactionProps,\n onTouchMove: composeEventHandlers(\n onTouchMove,\n interactionProps.onTouchMove\n ),\n onTouchEnd: composeEventHandlers(\n onTouchEnd,\n interactionProps.onTouchEnd\n ),\n onKeyDown: composeEventHandlers(onKeyDown, interactionProps.onKeyDown),\n onClick(event) {\n onClick?.(event);\n if (event.defaultPrevented) {\n pendingMouseUpSelectionRef.current = false;\n clearTimeout(selectTimeoutRef.current);\n allowSelectRef.current = true;\n return;\n }\n interactionProps.onClick?.(event);\n },\n onMouseUp: composeEventHandlers(onMouseUp, interactionProps.onMouseUp),\n onMouseMove: composeEventHandlers(\n onMouseMove,\n interactionProps.onMouseMove\n ),\n onPress\n };\n }\n return {\n ...restProps,\n onKeyDown: composeEventHandlers(restProps.onKeyDown, handleKeyDown),\n onMouseMove: composeEventHandlers(restProps.onMouseMove, (event) => {\n if (disabled || index < 0) return;\n setActiveIndexFast?.(index, {\n reason: \"item-hover\",\n event: event.nativeEvent || event,\n trigger: event.currentTarget,\n index\n });\n }),\n onPress: composeEventHandlers(restProps.onPress, handleSelect)\n };\n }, [\n allowMouseUpRef,\n allowSelectRef,\n disabled,\n handleKeyDown,\n handleSelect,\n index,\n interactions,\n restProps,\n selectTimeoutRef,\n setActiveIndexFast\n ]);\n const accessibilityProps = getSelectOptionProps(\n mode,\n isSelected,\n disabled,\n isWeb ? \"web\" : \"native\"\n );\n return /* @__PURE__ */ jsx(\n SelectItemContextProvider,\n {\n scope,\n value,\n textId: textId || \"\",\n textValue: textValueProp,\n isSelected,\n children: shouldRenderWebNative ? /* @__PURE__ */ jsx(\"option\", { value, disabled, children: props.children }) : /* @__PURE__ */ jsx(\n SelectItemFrame,\n {\n render: \"div\",\n ref: composedRefs,\n \"aria-labelledby\": textId,\n \"data-state\": isSelected ? \"active\" : \"inactive\",\n \"data-disabled\": disabled ? \"\" : void 0,\n tabIndex: disabled ? void 0 : isWeb && isAdapted ? index === (selectContext.activeIndex ?? selectContext.selectedIndex) ? 0 : -1 : -1,\n zIndex: 100,\n ...selectItemProps,\n ...accessibilityProps\n }\n )\n }\n );\n },\n {\n disableTheme: true\n }\n);\nexport {\n SelectItem,\n SelectItemContextProvider,\n SelectItemFrame,\n useSelectItemContext\n};\n//# sourceMappingURL=SelectIt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AAE;GAAO;GAAU,UAAU,MAAM;EAAS,CAAC,IAAoB,oBAC/H,iBACA;GACE,QAAQ;GACR,KAAK;GACL,mBAAmB;GACnB,cAAc,aAAa,WAAW;GACtC,iBAAiB,WAAW,KAAK,KAAK;GACtC,UAAU,WAAW,KAAK,IAAI,SAAS,YAAY,WAAW,cAAc,eAAe,cAAc,iBAAiB,IAAI,CAAC,IAAI,CAAC;GACpI,QAAQ;GACR,GAAG;GACH,GAAG;EACL,CACF;CACF,CACF;AACF,GACA,EACE,cAAc,KAChB,CACF"}
1
+ {"version":3,"file":"SelectItem.js","names":[],"sources":["esm/SelectItem.js"],"sourcesContent":["import { useComposedRefs } from \"@tamagui/compose-refs\";\nimport { useAdaptIsActive } from \"@tamagui/adapt\";\nimport { isWeb, useIsomorphicLayoutEffect } from \"@tamagui/constants\";\nimport {\n createChangeEventDetails,\n createStyledHOC,\n createStyledContext,\n styled,\n View\n} from \"@tamagui/core\";\nimport { composeEventHandlers } from \"@tamagui/helpers\";\nimport * as React from \"react\";\nimport { useSelectItemParentContext } from \"./context\";\nimport { getSelectOptionProps } from \"./selectionController\";\nimport { jsx } from \"react/jsx-runtime\";\nconst ITEM_NAME = \"SelectItem\";\nconst {\n Provider: SelectItemContextProvider,\n useStyledContext: useSelectItemContext\n} = createStyledContext(null, ITEM_NAME);\nconst SelectItemFrame = styled(View, {\n displayName: ITEM_NAME,\n alignItems: \"center\",\n flexDirection: \"row\"\n});\nconst SelectItem = createStyledHOC(\n SelectItemFrame,\n function SelectItem2(props, forwardedRef) {\n const {\n scope,\n value,\n disabled: disabledProp,\n \"aria-disabled\": ariaDisabled,\n textValue: textValueProp,\n ...restProps\n } = props;\n const disabled = disabledProp ?? ariaDisabled === true;\n const context = useSelectItemParentContext(scope);\n const isAdapted = useAdaptIsActive(context.adaptScope);\n const {\n registry,\n mode,\n selectedValues,\n selectValue,\n activeIndexSubscribe,\n activeIndexRef,\n allowMouseUpRef,\n allowSelectRef,\n selectTimeoutRef,\n getItemProps,\n shouldRenderWebNative,\n setActiveIndex,\n lastPointerRef,\n moveActive,\n search\n } = context;\n const isSelected = selectedValues.includes(value);\n const pendingMouseUpSelectionRef = React.useRef(false);\n const itemNodeRef = React.useRef(null);\n const registrationRef = React.useRef(\n null\n );\n const initialRegistration = React.useRef({\n value,\n disabled,\n textValue: textValueProp\n });\n useIsomorphicLayoutEffect(() => {\n const registration = registry.registerItem(initialRegistration.current);\n registrationRef.current = registration;\n registration.setNode(itemNodeRef.current);\n return () => {\n registrationRef.current = null;\n registration.unregister();\n };\n }, [registry]);\n useIsomorphicLayoutEffect(() => {\n registrationRef.current?.update({ value, disabled, textValue: textValueProp });\n }, [disabled, textValueProp, value]);\n useIsomorphicLayoutEffect(() => {\n registrationRef.current?.setNode(itemNodeRef.current);\n });\n const [isActive, setIsActive] = React.useState(false);\n const isActiveRef = React.useRef(false);\n React.useEffect(() => {\n const handleActiveIndex = (i) => {\n const next = i != null && registry.getIndex(value) === i;\n if (next !== isActiveRef.current) {\n isActiveRef.current = next;\n setIsActive(next);\n }\n if (next && isWeb) {\n requestAnimationFrame(() => {\n itemNodeRef.current?.focus?.();\n });\n }\n };\n handleActiveIndex(activeIndexRef?.current ?? null);\n return activeIndexSubscribe(handleActiveIndex);\n }, [activeIndexRef, activeIndexSubscribe, registry, value]);\n const textId = React.useId();\n const refCallback = React.useCallback((node) => {\n itemNodeRef.current = node;\n registrationRef.current?.setNode(node);\n }, []);\n const composedRefs = useComposedRefs(forwardedRef, refCallback);\n const handleSelect = React.useCallback(\n (event, reason = \"item-press\") => {\n if (disabled) return;\n const nativeEvent = event?.nativeEvent || event;\n selectValue(\n value,\n createChangeEventDetails(\n reason,\n nativeEvent,\n event?.currentTarget\n )\n );\n },\n [disabled, selectValue, value]\n );\n const handleMouseMove = React.useCallback(\n (event) => {\n if (disabled) return;\n const index = registry.getIndex(value);\n if (index < 0) return;\n const last = lastPointerRef.current;\n if (event.clientX === last.x && event.clientY === last.y) return;\n last.x = event.clientX;\n last.y = event.clientY;\n setActiveIndex(index, {\n reason: \"item-hover\",\n event: event.nativeEvent || event,\n trigger: event.currentTarget,\n index\n });\n },\n [disabled, lastPointerRef, registry, setActiveIndex, value]\n );\n const handleKeyDown = React.useCallback(\n (event) => {\n if (disabled) return;\n if (event.key === \"Enter\" || event.key === \" \") {\n event.preventDefault();\n handleSelect(event, \"keyboard\");\n return;\n }\n if (event.key === \"ArrowDown\" || event.key === \"ArrowUp\") {\n event.preventDefault();\n event.stopPropagation();\n moveActive(event.key === \"ArrowDown\" ? 1 : -1, event.nativeEvent || event);\n return;\n }\n if (!getItemProps && event.key?.length === 1 && !event.metaKey && !event.ctrlKey) {\n search(event.key, event.nativeEvent || event);\n }\n if (allowSelectRef) {\n allowSelectRef.current = true;\n }\n },\n [allowSelectRef, disabled, handleSelect, getItemProps, moveActive, search]\n );\n const selectItemProps = React.useMemo(() => {\n if (getItemProps) {\n const {\n onTouchMove,\n onTouchEnd,\n onKeyDown,\n onClick,\n onMouseUp,\n onMouseMove,\n onPress,\n ...itemProps\n } = restProps;\n const interactionProps = getItemProps({\n ...itemProps,\n onTouchMove() {\n allowSelectRef.current = true;\n allowMouseUpRef.current = false;\n },\n onTouchEnd() {\n allowSelectRef.current = false;\n allowMouseUpRef.current = true;\n },\n onMouseMove: handleMouseMove,\n onKeyDown: handleKeyDown,\n onClick(event) {\n if (disabled) return;\n const shouldSelect = pendingMouseUpSelectionRef.current || allowSelectRef.current;\n pendingMouseUpSelectionRef.current = false;\n clearTimeout(selectTimeoutRef.current);\n allowSelectRef.current = true;\n if (shouldSelect) {\n handleSelect(event);\n }\n },\n onMouseUp(event) {\n if (disabled) return;\n if (!allowMouseUpRef.current) {\n allowMouseUpRef.current = true;\n allowSelectRef.current = true;\n return;\n }\n pendingMouseUpSelectionRef.current = allowSelectRef.current;\n clearTimeout(selectTimeoutRef.current);\n selectTimeoutRef.current = setTimeout(() => {\n allowSelectRef.current = true;\n if (pendingMouseUpSelectionRef.current) {\n pendingMouseUpSelectionRef.current = false;\n handleSelect(event);\n }\n });\n }\n });\n return {\n ...interactionProps,\n onTouchMove: composeEventHandlers(\n onTouchMove,\n interactionProps.onTouchMove\n ),\n onTouchEnd: composeEventHandlers(\n onTouchEnd,\n interactionProps.onTouchEnd\n ),\n onKeyDown: composeEventHandlers(onKeyDown, interactionProps.onKeyDown),\n onClick(event) {\n onClick?.(event);\n if (event.defaultPrevented) {\n pendingMouseUpSelectionRef.current = false;\n clearTimeout(selectTimeoutRef.current);\n allowSelectRef.current = true;\n return;\n }\n interactionProps.onClick?.(event);\n },\n onMouseUp: composeEventHandlers(onMouseUp, interactionProps.onMouseUp),\n onMouseMove: composeEventHandlers(\n onMouseMove,\n interactionProps.onMouseMove\n ),\n onPress\n };\n }\n return {\n ...restProps,\n onKeyDown: composeEventHandlers(restProps.onKeyDown, handleKeyDown),\n onMouseMove: composeEventHandlers(restProps.onMouseMove, handleMouseMove),\n onPress: composeEventHandlers(restProps.onPress, handleSelect)\n };\n }, [\n allowMouseUpRef,\n allowSelectRef,\n disabled,\n handleKeyDown,\n handleMouseMove,\n handleSelect,\n getItemProps,\n restProps,\n selectTimeoutRef\n ]);\n const accessibilityProps = getSelectOptionProps(\n mode,\n isSelected,\n disabled,\n isWeb ? \"web\" : \"native\"\n );\n return /* @__PURE__ */ jsx(\n SelectItemContextProvider,\n {\n scope,\n value,\n textId: textId || \"\",\n textValue: textValueProp,\n isSelected,\n children: shouldRenderWebNative ? /* @__PURE__ */ jsx(\"option\", { value, disabled, children: props.children }) : /* @__PURE__ */ jsx(\n SelectItemFrame,\n {\n render: \"div\",\n ref: composedRefs,\n \"aria-labelledby\": textId,\n \"data-state\": isSelected ? \"active\" : \"inactive\",\n \"data-disabled\": disabled ? \"\" : void 0,\n tabIndex: disabled ? void 0 : isWeb && isAdapted && (isActive || activeIndexRef?.current == null && isSelected) ? 0 : -1,\n zIndex: 100,\n ...selectItemProps,\n ...accessibilityProps\n }\n )\n }\n );\n },\n {\n disableTheme: true\n }\n);\nexport {\n SelectItem,\n SelectItemContextProvider,\n SelectItemFrame,\n useSelectItemContext\n};\n//# sourceMappingURL=SelectItem.js.map\n"],"mappings":";;;;;;;;;;;AAeA,MAAM,YAAY;AAClB,MAAM,EACJ,UAAU,2BACV,kBAAkB,yBAChB,oBAAoB,MAAM,SAAS;AACvC,MAAM,kBAAkB,OAAO,MAAM;CACnC,aAAa;CACb,YAAY;CACZ,eAAe;AACjB,CAAC;AACD,MAAM,aAAa,gBACjB,iBACA,SAAS,YAAY,OAAO,cAAc;CACxC,MAAM,EACJ,OACA,OACA,UAAU,cACV,iBAAiB,cACjB,WAAW,eACX,GAAG,cACD;CACJ,MAAM,WAAW,gBAAgB,iBAAiB;CAClD,MAAM,UAAU,2BAA2B,KAAK;CAChD,MAAM,YAAY,iBAAiB,QAAQ,UAAU;CACrD,MAAM,EACJ,UACA,MACA,gBACA,aACA,sBACA,gBACA,iBACA,gBACA,kBACA,cACA,uBACA,gBACA,gBACA,YACA,WACE;CACJ,MAAM,aAAa,eAAe,SAAS,KAAK;CAChD,MAAM,6BAA6B,MAAM,OAAO,KAAK;CACrD,MAAM,cAAc,MAAM,OAAO,IAAI;CACrC,MAAM,kBAAkB,MAAM,OAC5B,IACF;CACA,MAAM,sBAAsB,MAAM,OAAO;EACvC;EACA;EACA,WAAW;CACb,CAAC;CACD,gCAAgC;EAC9B,MAAM,eAAe,SAAS,aAAa,oBAAoB,OAAO;EACtE,gBAAgB,UAAU;EAC1B,aAAa,QAAQ,YAAY,OAAO;EACxC,aAAa;GACX,gBAAgB,UAAU;GAC1B,aAAa,WAAW;EAC1B;CACF,GAAG,CAAC,QAAQ,CAAC;CACb,gCAAgC;EAC9B,gBAAgB,SAAS,OAAO;GAAE;GAAO;GAAU,WAAW;EAAc,CAAC;CAC/E,GAAG;EAAC;EAAU;EAAe;CAAK,CAAC;CACnC,gCAAgC;EAC9B,gBAAgB,SAAS,QAAQ,YAAY,OAAO;CACtD,CAAC;CACD,MAAM,C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ayoutEffect } from "@tamagui/constants";
5
5
  import { View, createChangeEventDetails, createStyledContext, createStyledHOC, styled } from "@tamagui/core";
6
6
  import { composeEventHandlers } from "@tamagui/helpers";
7
7
  import * as React from "react";
8
- import { useSelectContext, useSelectItemParentContext } from "./context.native.js";
8
+ import { useSelectItemParentContext } from "./context.native.js";
9
9
  import { getSelectOptionProps } from "./selectionController.native.js";
10
10
 
11
- function _instanceof(left, right) {
12
- if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
13
- return !!right[Symbol.hasInstance](left);
14
- } else {
15
- return left instanceof right;
16
- }
17
- }
18
11
  var ITEM_NAME = "SelectItem";
19
12
  var { Provider: SelectItemContextProvider, useStyledContext: useSelectItemContext } = createStyledContext(null, ITEM_NAME);
20
13
  var SelectItemFrame = styled(View, {
@@ -26,44 +19,22 @@ var SelectItem = createStyledHOC(SelectItemFrame, function SelectItem2(props, fo
26
19
  var { scope, value, disabled: disabledProp, "aria-disabled": ariaDisabled, textValue: textValueProp, ...restProps } = props;
27
20
  var disabled = disabledProp !== null && disabledProp !== void 0 ? disabledProp : ariaDisabled === true;
28
21
  var context = useSelectItemParentContext(scope);
29
- var selectContext = useSelectContext(scope);
30
- var isAdapted = useAdaptIsActive(selectContext.adaptScope);
31
- var { listRef, registry, mode, selectedValues, selectValue, activeIndexSubscribe, activeIndexRef, allowMouseUpRef, allowSelectRef, selectTimeoutRef, interactions, shouldRenderWebNative, setActiveIndexFast, moveActive, search } = context;
22
+ var isAdapted = useAdaptIsActive(context.adaptScope);
23
+ var { registry, mode, selectedValues, selectValue, activeIndexSubscribe, activeIndexRef, allowMouseUpRef, allowSelectRef, selectTimeoutRef, getItemProps, shouldRenderWebNative, setActiveIndex, lastPointerRef, moveActive, search } = context;
32
24
  var isSelected = selectedValues.includes(value);
33
25
  var pendingMouseUpSelectionRef = React.useRef(false);
34
26
  var itemNodeRef = React.useRef(null);
35
- var [, rerenderRegistry] = React.useReducer(function(version) {
36
- return version + 1;
37
- }, 0);
38
27
  var registrationRef = React.useRef(null);
39
28
  var initialRegistration = React.useRef({
40
29
  value,
41
30
  disabled,
42
31
  textValue: textValueProp
43
32
  });
44
- useIsomorphicLayoutEffect(function() {
45
- return registry.subscribe(function() {
46
- return rerenderRegistry();
47
- });
48
- }, [registry]);
49
33
  useIsomorphicLayoutEffect(function() {
50
34
  var registration = registry.registerItem(initialRegistration.current);
51
35
  registrationRef.current = registration;
52
- var registeredNode = itemNodeRef.current;
53
- registration.setNode(registeredNode);
54
- var registeredIndex = registry.getItems().findIndex(function(item) {
55
- return item.id === registration.id;
56
- });
57
- if (isWeb && listRef && registeredIndex >= 0 && _instanceof(registeredNode, HTMLElement)) {
58
- listRef.current[registeredIndex] = registeredNode;
59
- }
36
+ registration.setNode(itemNodeRef.current);
60
37
  return function() {
61
- var currentIndex = registry.getItems().findIndex(function(item) {
62
- return item.id === registration.id;
63
- });
64
- if (listRef && currentIndex >= 0 && listRef.current[currentIndex] === registeredNode) {
65
- listRef.current[currentIndex] = null;
66
- }
67
38
  registrationRef.current = null;
68
39
  registration.unregister();
69
40
  };
@@ -84,39 +55,37 @@ var SelectItem = createStyledHOC(SelectItemFrame, function SelectItem2(props, fo
84
55
  var _registrationRef_current;
85
56
  (_registrationRef_current = registrationRef.current) === null || _registrationRef_current === void 0 ? void 0 : _registrationRef_current.setNode(itemNodeRef.current);
86
57
  });
87
- var index = registry.getIndex(value);
58
+ var [isActive, setIsActive] = React.useState(false);
59
+ var isActiveRef = React.useRef(false);
88
60
  React.useEffect(function() {
89
61
  var handleActiveIndex = function(i) {
90
- if (index === i) {
91
- if (isWeb) {
92
- requestAnimationFrame(function() {
93
- var _listRef_current_index;
94
- listRef === null || listRef === void 0 ? void 0 : (_listRef_current_index = listRef.current[index]) === null || _listRef_current_index === void 0 ? void 0 : _listRef_current_index.focus();
95
- });
96
- }
62
+ var next = i != null && registry.getIndex(value) === i;
63
+ if (next !== isActiveRef.current) {
64
+ isActiveRef.current = next;
65
+ setIsActive(next);
66
+ }
67
+ if (next && isWeb) {
68
+ requestAnimationFrame(function() {
69
+ var _itemNodeRef_current_focus, _itemNodeRef_current;
70
+ (_itemNodeRef_current = itemNodeRef.current) === null || _itemNodeRef_current === void 0 ? void 0 : (_itemNodeRef_current_focus = _itemNodeRef_current.focus) === null || _itemNodeRef_current_focus === void 0 ? void 0 : _itemNodeRef_current_focus.call(_itemNodeRef_current);
71
+ });
97
72
  }
98
73
  };
99
- var currentActiveIndex = activeIndexRef === null || activeIndexRef === void 0 ? void 0 : activeIndexRef.current;
100
- if (currentActiveIndex !== null && currentActiveIndex !== void 0) {
101
- handleActiveIndex(currentActiveIndex);
102
- }
74
+ var _activeIndexRef_current;
75
+ handleActiveIndex((_activeIndexRef_current = activeIndexRef === null || activeIndexRef === void 0 ? void 0 : activeIndexRef.current) !== null && _activeIndexRef_current !== void 0 ? _activeIndexRef_current : null);
103
76
  return activeIndexSubscribe(handleActiveIndex);
104
77
  }, [
105
78
  activeIndexRef,
106
79
  activeIndexSubscribe,
107
- index,
108
- listRef
80
+ registry,
81
+ value
109
82
  ]);
110
83
  var textId = React.useId();
111
84
  var refCallback = React.useCallback(function(node) {
112
85
  var _registrationRef_current;
113
86
  itemNodeRef.current = node;
114
87
  (_registrationRef_current = registrationRef.current) === null || _registrationRef_current === void 0 ? void 0 : _registrationRef_current.setNode(node);
115
- if (!isWeb) return;
116
- if (listRef && index >= 0) {
117
- listRef.current[index] = _instanceof(node, HTMLElement) ? node : null;
118
- }
119
- }, [index, listRef]);
88
+ }, []);
120
89
  var composedRefs = useComposedRefs(forwardedRef, refCallback);
121
90
  var handleSelect = React.useCallback(function(event) {
122
91
  var reason = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "item-press";
@@ -128,6 +97,27 @@ var SelectItem = createStyledHOC(SelectItemFrame, function SelectItem2(props, fo
128
97
  selectValue,
129
98
  value
130
99
  ]);
100
+ var handleMouseMove = React.useCallback(function(event) {
101
+ if (disabled) return;
102
+ var index = registry.getIndex(value);
103
+ if (index < 0) return;
104
+ var last = lastPointerRef.current;
105
+ if (event.clientX === last.x && event.clientY === last.y) return;
106
+ last.x = event.clientX;
107
+ last.y = event.clientY;
108
+ setActiveIndex(index, {
109
+ reason: "item-hover",
110
+ event: event.nativeEvent || event,
111
+ trigger: event.currentTarget,
112
+ index
113
+ });
114
+ }, [
115
+ disabled,
116
+ lastPointerRef,
117
+ registry,
118
+ setActiveIndex,
119
+ value
120
+ ]);
131
121
  var handleKeyDown = React.useCallback(function(event) {
132
122
  var _event_key;
133
123
  if (disabled) return;
@@ -142,7 +132,7 @@ var SelectItem = createStyledHOC(SelectItemFrame, function SelectItem2(props, fo
142
132
  moveActive(event.key === "ArrowDown" ? 1 : -1, event.nativeEvent || event);
143
133
  return;
144
134
  }
145
- if (!interactions && ((_event_key = event.key) === null || _event_key === void 0 ? void 0 : _event_key.length) === 1 && !event.metaKey && !event.ctrlKey) {
135
+ if (!getItemProps && ((_event_key = event.key) === null || _event_key === void 0 ? void 0 : _event_key.length) === 1 && !event.metaKey && !event.ctrlKey) {
146
136
  search(event.key, event.nativeEvent || event);
147
137
  }
148
138
  if (allowSelectRef) {
@@ -152,14 +142,14 @@ var SelectItem = createStyledHOC(SelectItemFrame, function SelectItem2(props, fo
152
142
  allowSelectRef,
153
143
  disabled,
154
144
  handleSelect,
155
- interactions,
145
+ getItemProps,
156
146
  moveActive,
157
147
  search
158
148
  ]);
159
149
  var selectItemProps = React.useMemo(function() {
160
- if (interactions) {
150
+ if (getItemProps) {
161
151
  var { onTouchMove, onTouchEnd, onKeyDown, onClick, onMouseUp, onMouseMove, onPress, ...itemProps } = restProps;
162
- var interactionProps = interactions.getItemProps({
152
+ var interactionProps = getItemProps({
163
153
  ...itemProps,
164
154
  onTouchMove() {
165
155
  allowSelectRef.current = true;
@@ -169,15 +159,7 @@ var SelectItem = createStyledHOC(SelectItemFrame, function SelectItem2(props, fo
169
159
  allowSelectRef.current = false;
170
160
  allowMouseUpRef.current = true;
171
161
  },
172
- onMouseMove(event) {
173
- if (disabled || index < 0) return;
174
- setActiveIndexFast === null || setActiveIndexFast === void 0 ? void 0 : setActiveIndexFast(index, {
175
- reason: "item-hover",
176
- event: event.nativeEvent || event,
177
- trigger: event.currentTarget,
178
- index
179
- });
180
- },
162
+ onMouseMove: handleMouseMove,
181
163
  onKeyDown: handleKeyDown,
182
164
  onClick(event) {
183
165
  if (disabled) return;
@@ -231,15 +213,7 @@ var SelectItem = createStyledHOC(SelectItemFrame, function SelectItem2(props, fo
231
213
  return {
232
214
  ...restProps,
233
215
  onKeyDown: composeEventHandlers(restProps.onKeyDown, handleKeyDown),
234
- onMouseMove: composeEventHandlers(restProps.onMouseMove, function(event) {
235
- if (disabled || index < 0) return;
236
- setActiveIndexFast === null || setActiveIndexFast === void 0 ? void 0 : setActiveIndexFast(index, {
237
- reason: "item-hover",
238
- event: event.nativeEvent || event,
239
- trigger: event.currentTarget,
240
- index
241
- });
242
- }),
216
+ onMouseMove: composeEventHandlers(restProps.onMouseMove, handleMouseMove),
243
217
  onPress: composeEventHandlers(restProps.onPress, handleSelect)
244
218
  };
245
219
  }, [
@@ -247,15 +221,13 @@ var SelectItem = createStyledHOC(SelectItemFrame, function SelectItem2(props, fo
247
221
  allowSelectRef,
248
222
  disabled,
249
223
  handleKeyDown,
224
+ handleMouseMove,
250
225
  handleSelect,
251
- index,
252
- interactions,
226
+ getItemProps,
253
227
  restProps,
254
- selectTimeoutRef,
255
- setActiveIndexFast
228
+ selectTimeoutRef
256
229
  ]);
257
230
  var accessibilityProps = getSelectOptionProps(mode, isSelected, disabled, isWeb ? "web" : "native");
258
- var _selectContext_activeIndex;
259
231
  return /* @__PURE__ */ jsx(SelectItemContextProvider, {
260
232
  scope,
261
233
  value,
@@ -272,7 +244,7 @@ var SelectItem = createStyledHOC(SelectItemFrame, function SelectItem2(props, fo
272
244
  "aria-labelledby": textId,
273
245
  "data-state": isSelected ? "active" : "inactive",
274
246
  "data-disabled": disabled ? "" : void 0,
275
- tabIndex: disabled ? void 0 : isWeb && isAdapted ? index === ((_selectContext_activeIndex = selectContext.activeIndex) !== null && _selectContext_activeIndex !== void 0 ? _selectContext_activeIndex : selectContext.selectedIndex) ? 0 : -1 : -1,
247
+ tabIndex: disabled ? void 0 : isWeb && isAdapted && (isActive || (activeIndexRef === null || activeIndexRef === void 0 ? void 0 : activeIndexRef.current) == null && isSelected) ? 0 : -1,
276
248
  zIndex: 100,
277
249
  ...selectItemProps,
278
250
  ...accessibilityProps