@tamagui/floating 2.0.0-rc.3 → 2.0.0-rc.31

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 (190) hide show
  1. package/dist/cjs/Floating.native.js +4 -0
  2. package/dist/cjs/Floating.native.js.map +1 -1
  3. package/dist/cjs/index.cjs +33 -2
  4. package/dist/cjs/index.native.js +33 -2
  5. package/dist/cjs/index.native.js.map +1 -1
  6. package/dist/cjs/interactions/PopupTriggerMap.cjs +40 -0
  7. package/dist/cjs/interactions/PopupTriggerMap.native.js +73 -0
  8. package/dist/cjs/interactions/PopupTriggerMap.native.js.map +1 -0
  9. package/dist/cjs/interactions/createFloatingEvents.cjs +41 -0
  10. package/dist/cjs/interactions/createFloatingEvents.native.js +47 -0
  11. package/dist/cjs/interactions/createFloatingEvents.native.js.map +1 -0
  12. package/dist/cjs/interactions/safePolygon.cjs +191 -0
  13. package/dist/cjs/interactions/safePolygon.native.js +205 -0
  14. package/dist/cjs/interactions/safePolygon.native.js.map +1 -0
  15. package/dist/cjs/interactions/types.cjs +16 -0
  16. package/dist/cjs/interactions/types.native.js +19 -0
  17. package/dist/cjs/interactions/types.native.js.map +1 -0
  18. package/dist/cjs/interactions/useClick.cjs +82 -0
  19. package/dist/cjs/interactions/useClick.native.js +90 -0
  20. package/dist/cjs/interactions/useClick.native.js.map +1 -0
  21. package/dist/cjs/interactions/useDelayGroup.cjs +96 -0
  22. package/dist/cjs/interactions/useDelayGroup.native.js +109 -0
  23. package/dist/cjs/interactions/useDelayGroup.native.js.map +1 -0
  24. package/dist/cjs/interactions/useFocus.cjs +101 -0
  25. package/dist/cjs/interactions/useFocus.native.js +113 -0
  26. package/dist/cjs/interactions/useFocus.native.js.map +1 -0
  27. package/dist/cjs/interactions/useHover.cjs +224 -0
  28. package/dist/cjs/interactions/useHover.native.js +248 -0
  29. package/dist/cjs/interactions/useHover.native.js.map +1 -0
  30. package/dist/cjs/interactions/useInnerOffset.cjs +104 -0
  31. package/dist/cjs/interactions/useInnerOffset.native.js +118 -0
  32. package/dist/cjs/interactions/useInnerOffset.native.js.map +1 -0
  33. package/dist/cjs/interactions/useInteractions.cjs +76 -0
  34. package/dist/cjs/interactions/useInteractions.native.js +164 -0
  35. package/dist/cjs/interactions/useInteractions.native.js.map +1 -0
  36. package/dist/cjs/interactions/useListNavigation.cjs +253 -0
  37. package/dist/cjs/interactions/useListNavigation.native.js +297 -0
  38. package/dist/cjs/interactions/useListNavigation.native.js.map +1 -0
  39. package/dist/cjs/interactions/useRole.cjs +112 -0
  40. package/dist/cjs/interactions/useRole.native.js +128 -0
  41. package/dist/cjs/interactions/useRole.native.js.map +1 -0
  42. package/dist/cjs/interactions/useTypeahead.cjs +93 -0
  43. package/dist/cjs/interactions/useTypeahead.native.js +114 -0
  44. package/dist/cjs/interactions/useTypeahead.native.js.map +1 -0
  45. package/dist/cjs/interactions/utils.cjs +178 -0
  46. package/dist/cjs/interactions/utils.native.js +188 -0
  47. package/dist/cjs/interactions/utils.native.js.map +1 -0
  48. package/dist/cjs/middleware/inner.cjs +106 -0
  49. package/dist/cjs/middleware/inner.native.js +120 -0
  50. package/dist/cjs/middleware/inner.native.js.map +1 -0
  51. package/dist/cjs/useFloating.cjs +21 -17
  52. package/dist/cjs/useFloating.native.js +2 -0
  53. package/dist/cjs/useFloating.native.js.map +1 -1
  54. package/dist/esm/Floating.native.js +4 -1
  55. package/dist/esm/Floating.native.js.map +1 -1
  56. package/dist/esm/index.js +17 -34
  57. package/dist/esm/index.js.map +1 -6
  58. package/dist/esm/index.mjs +16 -2
  59. package/dist/esm/index.mjs.map +1 -1
  60. package/dist/esm/index.native.js +16 -2
  61. package/dist/esm/index.native.js.map +1 -1
  62. package/dist/esm/interactions/PopupTriggerMap.mjs +17 -0
  63. package/dist/esm/interactions/PopupTriggerMap.mjs.map +1 -0
  64. package/dist/esm/interactions/PopupTriggerMap.native.js +47 -0
  65. package/dist/esm/interactions/PopupTriggerMap.native.js.map +1 -0
  66. package/dist/esm/interactions/createFloatingEvents.mjs +18 -0
  67. package/dist/esm/interactions/createFloatingEvents.mjs.map +1 -0
  68. package/dist/esm/interactions/createFloatingEvents.native.js +21 -0
  69. package/dist/esm/interactions/createFloatingEvents.native.js.map +1 -0
  70. package/dist/esm/interactions/safePolygon.mjs +168 -0
  71. package/dist/esm/interactions/safePolygon.mjs.map +1 -0
  72. package/dist/esm/interactions/safePolygon.native.js +179 -0
  73. package/dist/esm/interactions/safePolygon.native.js.map +1 -0
  74. package/dist/esm/interactions/types.mjs +2 -0
  75. package/dist/esm/interactions/types.mjs.map +1 -0
  76. package/dist/esm/interactions/types.native.js +2 -0
  77. package/dist/esm/interactions/types.native.js.map +1 -0
  78. package/dist/esm/interactions/useClick.mjs +59 -0
  79. package/dist/esm/interactions/useClick.mjs.map +1 -0
  80. package/dist/esm/interactions/useClick.native.js +64 -0
  81. package/dist/esm/interactions/useClick.native.js.map +1 -0
  82. package/dist/esm/interactions/useDelayGroup.mjs +60 -0
  83. package/dist/esm/interactions/useDelayGroup.mjs.map +1 -0
  84. package/dist/esm/interactions/useDelayGroup.native.js +70 -0
  85. package/dist/esm/interactions/useDelayGroup.native.js.map +1 -0
  86. package/dist/esm/interactions/useFocus.mjs +78 -0
  87. package/dist/esm/interactions/useFocus.mjs.map +1 -0
  88. package/dist/esm/interactions/useFocus.native.js +87 -0
  89. package/dist/esm/interactions/useFocus.native.js.map +1 -0
  90. package/dist/esm/interactions/useHover.mjs +189 -0
  91. package/dist/esm/interactions/useHover.mjs.map +1 -0
  92. package/dist/esm/interactions/useHover.native.js +210 -0
  93. package/dist/esm/interactions/useHover.native.js.map +1 -0
  94. package/dist/esm/interactions/useInnerOffset.mjs +70 -0
  95. package/dist/esm/interactions/useInnerOffset.mjs.map +1 -0
  96. package/dist/esm/interactions/useInnerOffset.native.js +81 -0
  97. package/dist/esm/interactions/useInnerOffset.native.js.map +1 -0
  98. package/dist/esm/interactions/useInteractions.mjs +53 -0
  99. package/dist/esm/interactions/useInteractions.mjs.map +1 -0
  100. package/dist/esm/interactions/useInteractions.native.js +138 -0
  101. package/dist/esm/interactions/useInteractions.native.js.map +1 -0
  102. package/dist/esm/interactions/useListNavigation.mjs +230 -0
  103. package/dist/esm/interactions/useListNavigation.mjs.map +1 -0
  104. package/dist/esm/interactions/useListNavigation.native.js +271 -0
  105. package/dist/esm/interactions/useListNavigation.native.js.map +1 -0
  106. package/dist/esm/interactions/useRole.mjs +78 -0
  107. package/dist/esm/interactions/useRole.mjs.map +1 -0
  108. package/dist/esm/interactions/useRole.native.js +91 -0
  109. package/dist/esm/interactions/useRole.native.js.map +1 -0
  110. package/dist/esm/interactions/useTypeahead.mjs +70 -0
  111. package/dist/esm/interactions/useTypeahead.mjs.map +1 -0
  112. package/dist/esm/interactions/useTypeahead.native.js +88 -0
  113. package/dist/esm/interactions/useTypeahead.native.js.map +1 -0
  114. package/dist/esm/interactions/utils.mjs +134 -0
  115. package/dist/esm/interactions/utils.mjs.map +1 -0
  116. package/dist/esm/interactions/utils.native.js +141 -0
  117. package/dist/esm/interactions/utils.native.js.map +1 -0
  118. package/dist/esm/middleware/inner.mjs +72 -0
  119. package/dist/esm/middleware/inner.mjs.map +1 -0
  120. package/dist/esm/middleware/inner.native.js +83 -0
  121. package/dist/esm/middleware/inner.native.js.map +1 -0
  122. package/dist/esm/useFloating.mjs +21 -17
  123. package/dist/esm/useFloating.mjs.map +1 -1
  124. package/dist/esm/useFloating.native.js +2 -0
  125. package/dist/esm/useFloating.native.js.map +1 -1
  126. package/package.json +8 -10
  127. package/src/Floating.native.tsx +1 -0
  128. package/src/index.ts +49 -0
  129. package/src/interactions/PopupTriggerMap.ts +30 -0
  130. package/src/interactions/createFloatingEvents.ts +34 -0
  131. package/src/interactions/safePolygon.ts +500 -0
  132. package/src/interactions/types.ts +165 -0
  133. package/src/interactions/useClick.ts +148 -0
  134. package/src/interactions/useDelayGroup.ts +114 -0
  135. package/src/interactions/useFocus.ts +164 -0
  136. package/src/interactions/useHover.ts +453 -0
  137. package/src/interactions/useInnerOffset.ts +116 -0
  138. package/src/interactions/useInteractions.ts +101 -0
  139. package/src/interactions/useListNavigation.ts +578 -0
  140. package/src/interactions/useRole.ts +103 -0
  141. package/src/interactions/useTypeahead.ts +173 -0
  142. package/src/interactions/utils.ts +234 -0
  143. package/src/middleware/inner.ts +142 -0
  144. package/src/useFloating.tsx +13 -1
  145. package/types/Floating.native.d.ts +1 -0
  146. package/types/Floating.native.d.ts.map +1 -1
  147. package/types/index.d.ts +17 -2
  148. package/types/index.d.ts.map +1 -1
  149. package/types/interactions/PopupTriggerMap.d.ts +8 -0
  150. package/types/interactions/PopupTriggerMap.d.ts.map +1 -0
  151. package/types/interactions/createFloatingEvents.d.ts +7 -0
  152. package/types/interactions/createFloatingEvents.d.ts.map +1 -0
  153. package/types/interactions/safePolygon.d.ts +4 -0
  154. package/types/interactions/safePolygon.d.ts.map +1 -0
  155. package/types/interactions/types.d.ts +123 -0
  156. package/types/interactions/types.d.ts.map +1 -0
  157. package/types/interactions/useClick.d.ts +3 -0
  158. package/types/interactions/useClick.d.ts.map +1 -0
  159. package/types/interactions/useDelayGroup.d.ts +23 -0
  160. package/types/interactions/useDelayGroup.d.ts.map +1 -0
  161. package/types/interactions/useFocus.d.ts +3 -0
  162. package/types/interactions/useFocus.d.ts.map +1 -0
  163. package/types/interactions/useHover.d.ts +6 -0
  164. package/types/interactions/useHover.d.ts.map +1 -0
  165. package/types/interactions/useInnerOffset.d.ts +3 -0
  166. package/types/interactions/useInnerOffset.d.ts.map +1 -0
  167. package/types/interactions/useInteractions.d.ts +8 -0
  168. package/types/interactions/useInteractions.d.ts.map +1 -0
  169. package/types/interactions/useListNavigation.d.ts +3 -0
  170. package/types/interactions/useListNavigation.d.ts.map +1 -0
  171. package/types/interactions/useRole.d.ts +3 -0
  172. package/types/interactions/useRole.d.ts.map +1 -0
  173. package/types/interactions/useTypeahead.d.ts +3 -0
  174. package/types/interactions/useTypeahead.d.ts.map +1 -0
  175. package/types/interactions/utils.d.ts +46 -0
  176. package/types/interactions/utils.d.ts.map +1 -0
  177. package/types/middleware/inner.d.ts +14 -0
  178. package/types/middleware/inner.d.ts.map +1 -0
  179. package/types/useFloating.d.ts +7 -1
  180. package/types/useFloating.d.ts.map +1 -1
  181. package/dist/cjs/Floating.js +0 -15
  182. package/dist/cjs/Floating.js.map +0 -6
  183. package/dist/cjs/index.js +0 -34
  184. package/dist/cjs/index.js.map +0 -6
  185. package/dist/cjs/useFloating.js +0 -46
  186. package/dist/cjs/useFloating.js.map +0 -6
  187. package/dist/esm/Floating.js +0 -2
  188. package/dist/esm/Floating.js.map +0 -6
  189. package/dist/esm/useFloating.js +0 -23
  190. package/dist/esm/useFloating.js.map +0 -6
@@ -0,0 +1,164 @@
1
+ "use strict";
2
+
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all) __defProp(target, name, {
9
+ get: all[name],
10
+ enumerable: !0
11
+ });
12
+ },
13
+ __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
15
+ get: () => from[key],
16
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
17
+ });
18
+ return to;
19
+ };
20
+ var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
21
+ value: !0
22
+ }), mod);
23
+ var useInteractions_exports = {};
24
+ __export(useInteractions_exports, {
25
+ useInteractions: () => useInteractions
26
+ });
27
+ module.exports = __toCommonJS(useInteractions_exports);
28
+ function _type_of(obj) {
29
+ "@swc/helpers - typeof";
30
+
31
+ return obj && typeof Symbol < "u" && obj.constructor === Symbol ? "symbol" : typeof obj;
32
+ }
33
+ function useInteractions(propsList) {
34
+ var filtered = propsList.filter(Boolean),
35
+ referenceFns = /* @__PURE__ */new Map(),
36
+ floatingFns = /* @__PURE__ */new Map(),
37
+ itemFns = /* @__PURE__ */new Map(),
38
+ referenceStatic = {},
39
+ floatingStatic = {},
40
+ _iteratorNormalCompletion = !0,
41
+ _didIteratorError = !1,
42
+ _iteratorError = void 0;
43
+ try {
44
+ for (var _iterator = filtered[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = !0) {
45
+ var props = _step.value;
46
+ props.reference && collectProps(props.reference, referenceFns, referenceStatic), props.floating && collectProps(props.floating, floatingFns, floatingStatic), props.item && _type_of(props.item) === "object" && collectProps(props.item, itemFns, {});
47
+ }
48
+ } catch (err) {
49
+ _didIteratorError = !0, _iteratorError = err;
50
+ } finally {
51
+ try {
52
+ !_iteratorNormalCompletion && _iterator.return != null && _iterator.return();
53
+ } finally {
54
+ if (_didIteratorError) throw _iteratorError;
55
+ }
56
+ }
57
+ return {
58
+ getReferenceProps(userProps) {
59
+ return buildProps(referenceFns, referenceStatic, userProps);
60
+ },
61
+ getFloatingProps(userProps) {
62
+ return buildProps(floatingFns, floatingStatic, userProps);
63
+ },
64
+ getItemProps(userProps) {
65
+ return buildProps(itemFns, {}, userProps);
66
+ }
67
+ };
68
+ }
69
+ function collectProps(props, fnMap, staticMap) {
70
+ var _iteratorNormalCompletion = !0,
71
+ _didIteratorError = !1,
72
+ _iteratorError = void 0;
73
+ try {
74
+ for (var _iterator = Object.keys(props)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = !0) {
75
+ var key = _step.value;
76
+ if (typeof props[key] == "function") {
77
+ var arr = fnMap.get(key);
78
+ arr || (arr = [], fnMap.set(key, arr)), arr.push(props[key]);
79
+ } else staticMap[key] = props[key];
80
+ }
81
+ } catch (err) {
82
+ _didIteratorError = !0, _iteratorError = err;
83
+ } finally {
84
+ try {
85
+ !_iteratorNormalCompletion && _iterator.return != null && _iterator.return();
86
+ } finally {
87
+ if (_didIteratorError) throw _iteratorError;
88
+ }
89
+ }
90
+ }
91
+ function buildProps(fnMap, staticProps, userProps) {
92
+ var result = {
93
+ ...staticProps
94
+ },
95
+ _iteratorNormalCompletion = !0,
96
+ _didIteratorError = !1,
97
+ _iteratorError = void 0;
98
+ try {
99
+ for (var _loop = function () {
100
+ var [key, fns] = _step.value,
101
+ hookHandler = function () {
102
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) args[_key] = arguments[_key];
103
+ var _iteratorNormalCompletion2 = !0,
104
+ _didIteratorError2 = !1,
105
+ _iteratorError2 = void 0;
106
+ try {
107
+ for (var _iterator2 = fns[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = !0) {
108
+ var fn = _step2.value,
109
+ result2 = fn(...args);
110
+ if (result2 !== void 0) return result2;
111
+ }
112
+ } catch (err) {
113
+ _didIteratorError2 = !0, _iteratorError2 = err;
114
+ } finally {
115
+ try {
116
+ !_iteratorNormalCompletion2 && _iterator2.return != null && _iterator2.return();
117
+ } finally {
118
+ if (_didIteratorError2) throw _iteratorError2;
119
+ }
120
+ }
121
+ };
122
+ result[key] = hookHandler;
123
+ }, _iterator = fnMap[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = !0) _loop();
124
+ } catch (err) {
125
+ _didIteratorError = !0, _iteratorError = err;
126
+ } finally {
127
+ try {
128
+ !_iteratorNormalCompletion && _iterator.return != null && _iterator.return();
129
+ } finally {
130
+ if (_didIteratorError) throw _iteratorError;
131
+ }
132
+ }
133
+ if (userProps) {
134
+ var _iteratorNormalCompletion1 = !0,
135
+ _didIteratorError1 = !1,
136
+ _iteratorError1 = void 0;
137
+ try {
138
+ for (var _loop1 = function () {
139
+ var key = _step1.value;
140
+ if (key === "style") result.style = {
141
+ ...result.style,
142
+ ...userProps.style
143
+ };else if (typeof userProps[key] == "function" && result[key]) {
144
+ var hookFn = result[key],
145
+ userFn = userProps[key];
146
+ result[key] = function () {
147
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) args[_key] = arguments[_key];
148
+ userFn(...args), hookFn(...args);
149
+ };
150
+ } else result[key] = userProps[key];
151
+ }, _iterator1 = Object.keys(userProps)[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = !0) _loop1();
152
+ } catch (err) {
153
+ _didIteratorError1 = !0, _iteratorError1 = err;
154
+ } finally {
155
+ try {
156
+ !_iteratorNormalCompletion1 && _iterator1.return != null && _iterator1.return();
157
+ } finally {
158
+ if (_didIteratorError1) throw _iteratorError1;
159
+ }
160
+ }
161
+ }
162
+ return result;
163
+ }
164
+ //# sourceMappingURL=useInteractions.native.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","useInteractions_exports","__export","useInteractions","module","exports","_type_of","obj","Symbol","constructor","propsList","filtered","filter","Boolean","referenceFns","Map","floatingFns","itemFns","referenceStatic","floatingStatic","_iteratorNormalCompletion","_didIteratorError","_iteratorError","_iterator","iterator","_step","next","done","props","reference","collectProps","floating","item","err","return","getReferenceProps","userProps","buildProps","getFloatingProps","getItemProps","fnMap","staticMap","Object","keys","key","arr","get","set","push"],"sources":["../../../src/interactions/useInteractions.ts"],"sourcesContent":[null],"mappings":"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","ignoreList":[]}
@@ -0,0 +1,253 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all) __defProp(target, name, {
7
+ get: all[name],
8
+ enumerable: !0
9
+ });
10
+ },
11
+ __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
13
+ get: () => from[key],
14
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
15
+ });
16
+ return to;
17
+ };
18
+ var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
19
+ value: !0
20
+ }), mod);
21
+ var useListNavigation_exports = {};
22
+ __export(useListNavigation_exports, {
23
+ useListNavigation: () => useListNavigation
24
+ });
25
+ module.exports = __toCommonJS(useListNavigation_exports);
26
+ var import_react = require("react"),
27
+ import_use_event = require("@tamagui/use-event"),
28
+ import_utils = require("./utils.cjs");
29
+ const ARROW_UP = "ArrowUp",
30
+ ARROW_DOWN = "ArrowDown",
31
+ ARROW_LEFT = "ArrowLeft",
32
+ ARROW_RIGHT = "ArrowRight";
33
+ function doSwitch(orientation, vertical, horizontal) {
34
+ switch (orientation) {
35
+ case "vertical":
36
+ return vertical;
37
+ case "horizontal":
38
+ return horizontal;
39
+ default:
40
+ return vertical || horizontal;
41
+ }
42
+ }
43
+ function isMainOrientationKey(key, orientation) {
44
+ return doSwitch(orientation, key === ARROW_UP || key === ARROW_DOWN, key === ARROW_LEFT || key === ARROW_RIGHT);
45
+ }
46
+ function isMainOrientationToEndKey(key, orientation, rtl) {
47
+ return doSwitch(orientation, key === ARROW_DOWN, rtl ? key === ARROW_LEFT : key === ARROW_RIGHT) || key === "Enter" || key === " " || key === "";
48
+ }
49
+ function isCrossOrientationOpenKey(key, orientation, rtl) {
50
+ return doSwitch(orientation, rtl ? key === ARROW_LEFT : key === ARROW_RIGHT, key === ARROW_DOWN);
51
+ }
52
+ function isCrossOrientationCloseKey(key, orientation, rtl) {
53
+ return doSwitch(orientation, rtl ? key === ARROW_RIGHT : key === ARROW_LEFT, key === ARROW_UP);
54
+ }
55
+ function useListNavigation(context, props) {
56
+ const {
57
+ open,
58
+ onOpenChange,
59
+ elements
60
+ } = context,
61
+ {
62
+ listRef,
63
+ activeIndex,
64
+ onNavigate: unstable_onNavigate = () => {},
65
+ enabled = !0,
66
+ selectedIndex = null,
67
+ allowEscape = !1,
68
+ loop = !1,
69
+ nested = !1,
70
+ rtl = !1,
71
+ virtual = !1,
72
+ focusItemOnOpen = "auto",
73
+ focusItemOnHover = !0,
74
+ openOnArrowKeyDown = !0,
75
+ disabledIndices = void 0,
76
+ orientation = "vertical",
77
+ scrollItemIntoView = !0
78
+ } = props,
79
+ typeableComboboxReference = (0, import_utils.isTypeableCombobox)(elements.domReference),
80
+ focusItemOnOpenRef = (0, import_react.useRef)(focusItemOnOpen),
81
+ indexRef = (0, import_react.useRef)(selectedIndex ?? -1),
82
+ keyRef = (0, import_react.useRef)(null),
83
+ isPointerModalityRef = (0, import_react.useRef)(!0),
84
+ previousMountedRef = (0, import_react.useRef)(!!elements.floating),
85
+ previousOpenRef = (0, import_react.useRef)(open),
86
+ forceSyncFocusRef = (0, import_react.useRef)(!1),
87
+ forceScrollIntoViewRef = (0, import_react.useRef)(!1),
88
+ disabledIndicesRef = (0, import_react.useRef)(disabledIndices);
89
+ disabledIndicesRef.current = disabledIndices;
90
+ const latestOpenRef = (0, import_react.useRef)(open);
91
+ latestOpenRef.current = open;
92
+ const scrollItemIntoViewRef = (0, import_react.useRef)(scrollItemIntoView);
93
+ scrollItemIntoViewRef.current = scrollItemIntoView;
94
+ const selectedIndexRef = (0, import_react.useRef)(selectedIndex);
95
+ selectedIndexRef.current = selectedIndex;
96
+ const stableOnNavigate = (0, import_use_event.useEvent)(unstable_onNavigate),
97
+ [activeId, setActiveId] = (0, import_react.useState)(),
98
+ onNavigate = (0, import_use_event.useEvent)(() => {
99
+ stableOnNavigate(indexRef.current === -1 ? null : indexRef.current);
100
+ }),
101
+ previousOnNavigateRef = (0, import_react.useRef)(onNavigate),
102
+ focusItem = (0, import_use_event.useEvent)(() => {
103
+ function runFocus(item2) {
104
+ virtual ? setActiveId(item2.id) : (0, import_utils.enqueueFocus)(item2, {
105
+ sync: forceSyncFocusRef.current,
106
+ preventScroll: !0
107
+ });
108
+ }
109
+ const initialItem = listRef.current[indexRef.current],
110
+ forceScrollIntoView = forceScrollIntoViewRef.current;
111
+ initialItem && runFocus(initialItem), (forceSyncFocusRef.current ? v => v() : requestAnimationFrame)(() => {
112
+ const waitedItem = listRef.current[indexRef.current] || initialItem;
113
+ if (!waitedItem) return;
114
+ initialItem || runFocus(waitedItem);
115
+ const scrollIntoViewOptions = scrollItemIntoViewRef.current;
116
+ scrollIntoViewOptions && waitedItem && (forceScrollIntoView || !isPointerModalityRef.current) && waitedItem.scrollIntoView?.(typeof scrollIntoViewOptions == "boolean" ? {
117
+ block: "nearest",
118
+ inline: "nearest"
119
+ } : scrollIntoViewOptions);
120
+ });
121
+ });
122
+ (0, import_react.useLayoutEffect)(() => {
123
+ enabled && (open && elements.floating ? focusItemOnOpenRef.current && selectedIndex != null && (forceScrollIntoViewRef.current = !0, indexRef.current = selectedIndex, onNavigate()) : previousMountedRef.current && (indexRef.current = -1, previousOnNavigateRef.current()));
124
+ }, [enabled, open, elements.floating, selectedIndex, onNavigate]), (0, import_react.useLayoutEffect)(() => {
125
+ if (enabled && open && elements.floating) if (activeIndex == null) {
126
+ if (forceSyncFocusRef.current = !1, selectedIndexRef.current != null) return;
127
+ if (previousMountedRef.current && (indexRef.current = -1, focusItem()), (!previousOpenRef.current || !previousMountedRef.current) && focusItemOnOpenRef.current && (keyRef.current != null || focusItemOnOpenRef.current === !0 && keyRef.current == null)) {
128
+ let runs = 0;
129
+ const waitForListPopulated = () => {
130
+ listRef.current[0] == null ? (runs < 2 && (runs ? requestAnimationFrame : queueMicrotask)(waitForListPopulated), runs++) : (indexRef.current = keyRef.current == null || isMainOrientationToEndKey(keyRef.current, orientation, rtl) || nested ? (0, import_utils.getMinListIndex)(listRef, disabledIndicesRef.current) : (0, import_utils.getMaxListIndex)(listRef, disabledIndicesRef.current), keyRef.current = null, onNavigate());
131
+ };
132
+ waitForListPopulated();
133
+ }
134
+ } else (0, import_utils.isIndexOutOfListBounds)(listRef, activeIndex) || (indexRef.current = activeIndex, focusItem(), forceScrollIntoViewRef.current = !1);
135
+ }, [enabled, open, elements.floating, activeIndex, selectedIndexRef, nested, listRef, orientation, rtl, onNavigate, focusItem, disabledIndicesRef]), (0, import_react.useLayoutEffect)(() => {
136
+ previousOnNavigateRef.current = onNavigate, previousOpenRef.current = open, previousMountedRef.current = !!elements.floating;
137
+ }), (0, import_react.useLayoutEffect)(() => {
138
+ open || (keyRef.current = null, focusItemOnOpenRef.current = focusItemOnOpen);
139
+ }, [open, focusItemOnOpen]);
140
+ const hasActiveIndex = activeIndex != null,
141
+ commonOnKeyDown = (0, import_use_event.useEvent)(event => {
142
+ if (isPointerModalityRef.current = !1, forceSyncFocusRef.current = !0, event.which === 229 || !latestOpenRef.current && event.currentTarget === elements.floating) return;
143
+ if (nested && isCrossOrientationCloseKey(event.key, orientation, rtl)) {
144
+ (0, import_utils.stopEvent)(event), onOpenChange(!1, event.nativeEvent, "list-navigation"), (0, import_utils.isHTMLElement)(elements.domReference) && elements.domReference.focus();
145
+ return;
146
+ }
147
+ const currentIndex = indexRef.current,
148
+ minIndex = (0, import_utils.getMinListIndex)(listRef, disabledIndices),
149
+ maxIndex = (0, import_utils.getMaxListIndex)(listRef, disabledIndices);
150
+ if (typeableComboboxReference || (event.key === "Home" && ((0, import_utils.stopEvent)(event), indexRef.current = minIndex, onNavigate()), event.key === "End" && ((0, import_utils.stopEvent)(event), indexRef.current = maxIndex, onNavigate())), isMainOrientationKey(event.key, orientation)) {
151
+ if ((0, import_utils.stopEvent)(event), open && !virtual && (0, import_utils.activeElement)(event.currentTarget.ownerDocument) === event.currentTarget) {
152
+ indexRef.current = isMainOrientationToEndKey(event.key, orientation, rtl) ? minIndex : maxIndex, onNavigate();
153
+ return;
154
+ }
155
+ isMainOrientationToEndKey(event.key, orientation, rtl) ? loop ? indexRef.current = currentIndex >= maxIndex ? allowEscape && currentIndex !== listRef.current.length ? -1 : minIndex : (0, import_utils.findNonDisabledListIndex)(listRef, {
156
+ startingIndex: currentIndex,
157
+ disabledIndices
158
+ }) : indexRef.current = Math.min(maxIndex, (0, import_utils.findNonDisabledListIndex)(listRef, {
159
+ startingIndex: currentIndex,
160
+ disabledIndices
161
+ })) : loop ? indexRef.current = currentIndex <= minIndex ? allowEscape && currentIndex !== -1 ? listRef.current.length : maxIndex : (0, import_utils.findNonDisabledListIndex)(listRef, {
162
+ startingIndex: currentIndex,
163
+ decrement: !0,
164
+ disabledIndices
165
+ }) : indexRef.current = Math.max(minIndex, (0, import_utils.findNonDisabledListIndex)(listRef, {
166
+ startingIndex: currentIndex,
167
+ decrement: !0,
168
+ disabledIndices
169
+ })), (0, import_utils.isIndexOutOfListBounds)(listRef, indexRef.current) && (indexRef.current = -1), onNavigate();
170
+ }
171
+ }),
172
+ ariaActiveDescendantProp = (0, import_react.useMemo)(() => virtual && open && hasActiveIndex && {
173
+ "aria-activedescendant": activeId
174
+ }, [virtual, open, hasActiveIndex, activeId]),
175
+ floating = (0, import_react.useMemo)(() => ({
176
+ "aria-orientation": orientation === "both" ? void 0 : orientation,
177
+ ...(typeableComboboxReference ? {} : ariaActiveDescendantProp),
178
+ onKeyDown: commonOnKeyDown,
179
+ onPointerMove() {
180
+ isPointerModalityRef.current = !0;
181
+ }
182
+ }), [ariaActiveDescendantProp, commonOnKeyDown, orientation, typeableComboboxReference]),
183
+ reference = (0, import_react.useMemo)(() => {
184
+ function checkVirtualMouse(event) {
185
+ focusItemOnOpen === "auto" && (0, import_utils.isVirtualClick)(event.nativeEvent) && (focusItemOnOpenRef.current = !0);
186
+ }
187
+ function checkVirtualPointer(event) {
188
+ focusItemOnOpenRef.current = focusItemOnOpen, focusItemOnOpen === "auto" && (0, import_utils.isVirtualPointerEvent)(event.nativeEvent) && (focusItemOnOpenRef.current = !0);
189
+ }
190
+ return {
191
+ ...ariaActiveDescendantProp,
192
+ onKeyDown(event) {
193
+ isPointerModalityRef.current = !1;
194
+ const isArrowKey = event.key.startsWith("Arrow"),
195
+ isCrossOpenKey = isCrossOrientationOpenKey(event.key, orientation, rtl),
196
+ isMainKey = isMainOrientationKey(event.key, orientation),
197
+ isNavigationKey = (nested ? isCrossOpenKey : isMainKey) || event.key === "Enter" || event.key.trim() === "";
198
+ if (virtual && open) return commonOnKeyDown(event);
199
+ if (!(!open && !openOnArrowKeyDown && isArrowKey)) {
200
+ if (isNavigationKey && (keyRef.current = event.key), nested) {
201
+ isCrossOpenKey && ((0, import_utils.stopEvent)(event), open ? (indexRef.current = (0, import_utils.getMinListIndex)(listRef, disabledIndicesRef.current), onNavigate()) : onOpenChange(!0, event.nativeEvent, "list-navigation"));
202
+ return;
203
+ }
204
+ isMainKey && (selectedIndex != null && (indexRef.current = selectedIndex), (0, import_utils.stopEvent)(event), !open && openOnArrowKeyDown ? onOpenChange(!0, event.nativeEvent, "list-navigation") : commonOnKeyDown(event), open && onNavigate());
205
+ }
206
+ },
207
+ onFocus() {
208
+ open && !virtual && (indexRef.current = -1, onNavigate());
209
+ },
210
+ onPointerDown: checkVirtualPointer,
211
+ onPointerEnter: checkVirtualPointer,
212
+ onMouseDown: checkVirtualMouse,
213
+ onClick: checkVirtualMouse
214
+ };
215
+ }, [ariaActiveDescendantProp, commonOnKeyDown, disabledIndicesRef, focusItemOnOpen, listRef, nested, onNavigate, onOpenChange, open, openOnArrowKeyDown, orientation, rtl, selectedIndex, virtual]),
216
+ item = (0, import_react.useMemo)(() => {
217
+ function syncCurrentTarget(currentTarget) {
218
+ if (!latestOpenRef.current) return;
219
+ const index = listRef.current.indexOf(currentTarget);
220
+ index !== -1 && indexRef.current !== index && (indexRef.current = index, onNavigate());
221
+ }
222
+ return {
223
+ onFocus({
224
+ currentTarget
225
+ }) {
226
+ forceSyncFocusRef.current = !0, syncCurrentTarget(currentTarget);
227
+ },
228
+ onClick: ({
229
+ currentTarget
230
+ }) => currentTarget.focus({
231
+ preventScroll: !0
232
+ }),
233
+ // safari
234
+ onMouseMove({
235
+ currentTarget
236
+ }) {
237
+ forceSyncFocusRef.current = !0, forceScrollIntoViewRef.current = !1, focusItemOnHover && syncCurrentTarget(currentTarget);
238
+ },
239
+ onPointerLeave({
240
+ pointerType
241
+ }) {
242
+ !isPointerModalityRef.current || pointerType === "touch" || (forceSyncFocusRef.current = !0, focusItemOnHover && (indexRef.current = -1, onNavigate(), virtual || elements.floating?.focus({
243
+ preventScroll: !0
244
+ })));
245
+ }
246
+ };
247
+ }, [latestOpenRef, focusItemOnHover, listRef, onNavigate, virtual, elements.floating]);
248
+ return (0, import_react.useMemo)(() => enabled ? {
249
+ reference,
250
+ floating,
251
+ item
252
+ } : {}, [enabled, reference, floating, item]);
253
+ }