@tamagui/floating 2.0.0-rc.4 → 2.0.0-rc.40

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 (191) hide show
  1. package/dist/cjs/Floating.cjs +7 -5
  2. package/dist/cjs/Floating.native.js +19 -13
  3. package/dist/cjs/Floating.native.js.map +1 -1
  4. package/dist/cjs/index.cjs +46 -13
  5. package/dist/cjs/index.native.js +46 -13
  6. package/dist/cjs/index.native.js.map +1 -1
  7. package/dist/cjs/interactions/PopupTriggerMap.cjs +49 -0
  8. package/dist/cjs/interactions/PopupTriggerMap.native.js +97 -0
  9. package/dist/cjs/interactions/PopupTriggerMap.native.js.map +1 -0
  10. package/dist/cjs/interactions/createFloatingEvents.cjs +50 -0
  11. package/dist/cjs/interactions/createFloatingEvents.native.js +56 -0
  12. package/dist/cjs/interactions/createFloatingEvents.native.js.map +1 -0
  13. package/dist/cjs/interactions/safePolygon.cjs +273 -0
  14. package/dist/cjs/interactions/safePolygon.native.js +284 -0
  15. package/dist/cjs/interactions/safePolygon.native.js.map +1 -0
  16. package/dist/cjs/interactions/types.cjs +18 -0
  17. package/dist/cjs/interactions/types.native.js +21 -0
  18. package/dist/cjs/interactions/types.native.js.map +1 -0
  19. package/dist/cjs/interactions/useClick.cjs +124 -0
  20. package/dist/cjs/interactions/useClick.native.js +132 -0
  21. package/dist/cjs/interactions/useClick.native.js.map +1 -0
  22. package/dist/cjs/interactions/useDelayGroup.cjs +115 -0
  23. package/dist/cjs/interactions/useDelayGroup.native.js +125 -0
  24. package/dist/cjs/interactions/useDelayGroup.native.js.map +1 -0
  25. package/dist/cjs/interactions/useFocus.cjs +130 -0
  26. package/dist/cjs/interactions/useFocus.native.js +139 -0
  27. package/dist/cjs/interactions/useFocus.native.js.map +1 -0
  28. package/dist/cjs/interactions/useHover.cjs +357 -0
  29. package/dist/cjs/interactions/useHover.native.js +373 -0
  30. package/dist/cjs/interactions/useHover.native.js.map +1 -0
  31. package/dist/cjs/interactions/useInnerOffset.cjs +128 -0
  32. package/dist/cjs/interactions/useInnerOffset.native.js +141 -0
  33. package/dist/cjs/interactions/useInnerOffset.native.js.map +1 -0
  34. package/dist/cjs/interactions/useInteractions.cjs +105 -0
  35. package/dist/cjs/interactions/useInteractions.native.js +216 -0
  36. package/dist/cjs/interactions/useInteractions.native.js.map +1 -0
  37. package/dist/cjs/interactions/useListNavigation.cjs +418 -0
  38. package/dist/cjs/interactions/useListNavigation.native.js +433 -0
  39. package/dist/cjs/interactions/useListNavigation.native.js.map +1 -0
  40. package/dist/cjs/interactions/useRole.cjs +122 -0
  41. package/dist/cjs/interactions/useRole.native.js +136 -0
  42. package/dist/cjs/interactions/useRole.native.js.map +1 -0
  43. package/dist/cjs/interactions/useTypeahead.cjs +143 -0
  44. package/dist/cjs/interactions/useTypeahead.native.js +159 -0
  45. package/dist/cjs/interactions/useTypeahead.native.js.map +1 -0
  46. package/dist/cjs/interactions/utils.cjs +208 -0
  47. package/dist/cjs/interactions/utils.native.js +227 -0
  48. package/dist/cjs/interactions/utils.native.js.map +1 -0
  49. package/dist/cjs/middleware/inner.cjs +118 -0
  50. package/dist/cjs/middleware/inner.native.js +130 -0
  51. package/dist/cjs/middleware/inner.native.js.map +1 -0
  52. package/dist/cjs/useFloating.cjs +35 -28
  53. package/dist/cjs/useFloating.native.js +51 -47
  54. package/dist/cjs/useFloating.native.js.map +1 -1
  55. package/dist/esm/Floating.native.js +6 -3
  56. package/dist/esm/Floating.native.js.map +1 -1
  57. package/dist/esm/index.js +17 -34
  58. package/dist/esm/index.js.map +1 -6
  59. package/dist/esm/index.mjs +16 -2
  60. package/dist/esm/index.mjs.map +1 -1
  61. package/dist/esm/index.native.js +16 -2
  62. package/dist/esm/index.native.js.map +1 -1
  63. package/dist/esm/interactions/PopupTriggerMap.mjs +24 -0
  64. package/dist/esm/interactions/PopupTriggerMap.mjs.map +1 -0
  65. package/dist/esm/interactions/PopupTriggerMap.native.js +69 -0
  66. package/dist/esm/interactions/PopupTriggerMap.native.js.map +1 -0
  67. package/dist/esm/interactions/createFloatingEvents.mjs +25 -0
  68. package/dist/esm/interactions/createFloatingEvents.mjs.map +1 -0
  69. package/dist/esm/interactions/createFloatingEvents.native.js +28 -0
  70. package/dist/esm/interactions/createFloatingEvents.native.js.map +1 -0
  71. package/dist/esm/interactions/safePolygon.mjs +248 -0
  72. package/dist/esm/interactions/safePolygon.mjs.map +1 -0
  73. package/dist/esm/interactions/safePolygon.native.js +256 -0
  74. package/dist/esm/interactions/safePolygon.native.js.map +1 -0
  75. package/dist/esm/interactions/types.mjs +2 -0
  76. package/dist/esm/interactions/types.mjs.map +1 -0
  77. package/dist/esm/interactions/types.native.js +2 -0
  78. package/dist/esm/interactions/types.native.js.map +1 -0
  79. package/dist/esm/interactions/useClick.mjs +99 -0
  80. package/dist/esm/interactions/useClick.mjs.map +1 -0
  81. package/dist/esm/interactions/useClick.native.js +104 -0
  82. package/dist/esm/interactions/useClick.native.js.map +1 -0
  83. package/dist/esm/interactions/useDelayGroup.mjs +77 -0
  84. package/dist/esm/interactions/useDelayGroup.mjs.map +1 -0
  85. package/dist/esm/interactions/useDelayGroup.native.js +84 -0
  86. package/dist/esm/interactions/useDelayGroup.native.js.map +1 -0
  87. package/dist/esm/interactions/useFocus.mjs +105 -0
  88. package/dist/esm/interactions/useFocus.mjs.map +1 -0
  89. package/dist/esm/interactions/useFocus.native.js +111 -0
  90. package/dist/esm/interactions/useFocus.native.js.map +1 -0
  91. package/dist/esm/interactions/useHover.mjs +320 -0
  92. package/dist/esm/interactions/useHover.mjs.map +1 -0
  93. package/dist/esm/interactions/useHover.native.js +333 -0
  94. package/dist/esm/interactions/useHover.native.js.map +1 -0
  95. package/dist/esm/interactions/useInnerOffset.mjs +92 -0
  96. package/dist/esm/interactions/useInnerOffset.mjs.map +1 -0
  97. package/dist/esm/interactions/useInnerOffset.native.js +102 -0
  98. package/dist/esm/interactions/useInnerOffset.native.js.map +1 -0
  99. package/dist/esm/interactions/useInteractions.mjs +80 -0
  100. package/dist/esm/interactions/useInteractions.mjs.map +1 -0
  101. package/dist/esm/interactions/useInteractions.native.js +188 -0
  102. package/dist/esm/interactions/useInteractions.native.js.map +1 -0
  103. package/dist/esm/interactions/useListNavigation.mjs +393 -0
  104. package/dist/esm/interactions/useListNavigation.mjs.map +1 -0
  105. package/dist/esm/interactions/useListNavigation.native.js +405 -0
  106. package/dist/esm/interactions/useListNavigation.native.js.map +1 -0
  107. package/dist/esm/interactions/useRole.mjs +86 -0
  108. package/dist/esm/interactions/useRole.mjs.map +1 -0
  109. package/dist/esm/interactions/useRole.native.js +97 -0
  110. package/dist/esm/interactions/useRole.native.js.map +1 -0
  111. package/dist/esm/interactions/useTypeahead.mjs +118 -0
  112. package/dist/esm/interactions/useTypeahead.mjs.map +1 -0
  113. package/dist/esm/interactions/useTypeahead.native.js +131 -0
  114. package/dist/esm/interactions/useTypeahead.native.js.map +1 -0
  115. package/dist/esm/interactions/utils.mjs +162 -0
  116. package/dist/esm/interactions/utils.mjs.map +1 -0
  117. package/dist/esm/interactions/utils.native.js +178 -0
  118. package/dist/esm/interactions/utils.native.js.map +1 -0
  119. package/dist/esm/middleware/inner.mjs +82 -0
  120. package/dist/esm/middleware/inner.mjs.map +1 -0
  121. package/dist/esm/middleware/inner.native.js +91 -0
  122. package/dist/esm/middleware/inner.native.js.map +1 -0
  123. package/dist/esm/useFloating.mjs +8 -3
  124. package/dist/esm/useFloating.mjs.map +1 -1
  125. package/dist/esm/useFloating.native.js +25 -23
  126. package/dist/esm/useFloating.native.js.map +1 -1
  127. package/package.json +8 -10
  128. package/src/Floating.native.tsx +1 -0
  129. package/src/index.ts +49 -0
  130. package/src/interactions/PopupTriggerMap.ts +30 -0
  131. package/src/interactions/createFloatingEvents.ts +34 -0
  132. package/src/interactions/safePolygon.ts +500 -0
  133. package/src/interactions/types.ts +165 -0
  134. package/src/interactions/useClick.ts +148 -0
  135. package/src/interactions/useDelayGroup.ts +114 -0
  136. package/src/interactions/useFocus.ts +164 -0
  137. package/src/interactions/useHover.ts +453 -0
  138. package/src/interactions/useInnerOffset.ts +116 -0
  139. package/src/interactions/useInteractions.ts +101 -0
  140. package/src/interactions/useListNavigation.ts +578 -0
  141. package/src/interactions/useRole.ts +103 -0
  142. package/src/interactions/useTypeahead.ts +173 -0
  143. package/src/interactions/utils.ts +234 -0
  144. package/src/middleware/inner.ts +141 -0
  145. package/src/useFloating.tsx +13 -1
  146. package/types/Floating.native.d.ts +1 -0
  147. package/types/Floating.native.d.ts.map +1 -1
  148. package/types/index.d.ts +17 -2
  149. package/types/index.d.ts.map +1 -1
  150. package/types/interactions/PopupTriggerMap.d.ts +8 -0
  151. package/types/interactions/PopupTriggerMap.d.ts.map +1 -0
  152. package/types/interactions/createFloatingEvents.d.ts +7 -0
  153. package/types/interactions/createFloatingEvents.d.ts.map +1 -0
  154. package/types/interactions/safePolygon.d.ts +4 -0
  155. package/types/interactions/safePolygon.d.ts.map +1 -0
  156. package/types/interactions/types.d.ts +123 -0
  157. package/types/interactions/types.d.ts.map +1 -0
  158. package/types/interactions/useClick.d.ts +3 -0
  159. package/types/interactions/useClick.d.ts.map +1 -0
  160. package/types/interactions/useDelayGroup.d.ts +23 -0
  161. package/types/interactions/useDelayGroup.d.ts.map +1 -0
  162. package/types/interactions/useFocus.d.ts +3 -0
  163. package/types/interactions/useFocus.d.ts.map +1 -0
  164. package/types/interactions/useHover.d.ts +6 -0
  165. package/types/interactions/useHover.d.ts.map +1 -0
  166. package/types/interactions/useInnerOffset.d.ts +3 -0
  167. package/types/interactions/useInnerOffset.d.ts.map +1 -0
  168. package/types/interactions/useInteractions.d.ts +8 -0
  169. package/types/interactions/useInteractions.d.ts.map +1 -0
  170. package/types/interactions/useListNavigation.d.ts +3 -0
  171. package/types/interactions/useListNavigation.d.ts.map +1 -0
  172. package/types/interactions/useRole.d.ts +3 -0
  173. package/types/interactions/useRole.d.ts.map +1 -0
  174. package/types/interactions/useTypeahead.d.ts +3 -0
  175. package/types/interactions/useTypeahead.d.ts.map +1 -0
  176. package/types/interactions/utils.d.ts +46 -0
  177. package/types/interactions/utils.d.ts.map +1 -0
  178. package/types/middleware/inner.d.ts +14 -0
  179. package/types/middleware/inner.d.ts.map +1 -0
  180. package/types/useFloating.d.ts +7 -1
  181. package/types/useFloating.d.ts.map +1 -1
  182. package/dist/cjs/Floating.js +0 -15
  183. package/dist/cjs/Floating.js.map +0 -6
  184. package/dist/cjs/index.js +0 -34
  185. package/dist/cjs/index.js.map +0 -6
  186. package/dist/cjs/useFloating.js +0 -46
  187. package/dist/cjs/useFloating.js.map +0 -6
  188. package/dist/esm/Floating.js +0 -2
  189. package/dist/esm/Floating.js.map +0 -6
  190. package/dist/esm/useFloating.js +0 -23
  191. package/dist/esm/useFloating.js.map +0 -6
@@ -0,0 +1,136 @@
1
+ "use strict";
2
+
3
+ var __create = Object.create;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __export = (target, all) => {
10
+ for (var name in all) __defProp(target, name, {
11
+ get: all[name],
12
+ enumerable: true
13
+ });
14
+ };
15
+ var __copyProps = (to, from, except, desc) => {
16
+ if (from && typeof from === "object" || typeof from === "function") {
17
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
18
+ get: () => from[key],
19
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
20
+ });
21
+ }
22
+ return to;
23
+ };
24
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
25
+ // If the importer is in node compatibility mode or this is not an ESM
26
+ // file that has been converted to a CommonJS file using a Babel-
27
+ // compatible transform (i.e. "__esModule" has not been set), then set
28
+ // "default" to the CommonJS "module.exports" for node compatibility.
29
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
30
+ value: mod,
31
+ enumerable: true
32
+ }) : target, mod));
33
+ var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
34
+ value: true
35
+ }), mod);
36
+ var useRole_exports = {};
37
+ __export(useRole_exports, {
38
+ useRole: () => useRole
39
+ });
40
+ module.exports = __toCommonJS(useRole_exports);
41
+ var React = __toESM(require("react"), 1);
42
+ var componentRoleToAriaRoleMap = /* @__PURE__ */new Map([["select", "listbox"], ["combobox", "listbox"], ["label", false]]);
43
+ var idCounter = 0;
44
+ function useRole(context) {
45
+ var props = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
46
+ var _elements_domReference;
47
+ var {
48
+ open,
49
+ elements
50
+ } = context;
51
+ var {
52
+ enabled = true,
53
+ role = "dialog"
54
+ } = props;
55
+ var defaultReferenceId = React.useId();
56
+ var referenceId = ((_elements_domReference = elements.domReference) === null || _elements_domReference === void 0 ? void 0 : _elements_domReference.id) || defaultReferenceId;
57
+ var defaultFloatingId = React.useMemo(function () {
58
+ return `floating-${idCounter++}`;
59
+ }, []);
60
+ var floatingId = React.useMemo(function () {
61
+ var _elements_floating;
62
+ return ((_elements_floating = elements.floating) === null || _elements_floating === void 0 ? void 0 : _elements_floating.id) || defaultFloatingId;
63
+ }, [elements.floating, defaultFloatingId]);
64
+ var _componentRoleToAriaRoleMap_get;
65
+ var ariaRole = (_componentRoleToAriaRoleMap_get = componentRoleToAriaRoleMap.get(role)) !== null && _componentRoleToAriaRoleMap_get !== void 0 ? _componentRoleToAriaRoleMap_get : role;
66
+ var reference = React.useMemo(function () {
67
+ if (ariaRole === "tooltip" || role === "label") {
68
+ return {
69
+ [`aria-${role === "label" ? "labelledby" : "describedby"}`]: open ? floatingId : void 0
70
+ };
71
+ }
72
+ return {
73
+ "aria-expanded": open ? "true" : "false",
74
+ "aria-haspopup": ariaRole === "alertdialog" ? "dialog" : ariaRole,
75
+ "aria-controls": open ? floatingId : void 0,
76
+ ...(ariaRole === "listbox" && {
77
+ role: "combobox"
78
+ }),
79
+ ...(ariaRole === "menu" && {
80
+ id: referenceId
81
+ }),
82
+ ...(role === "select" && {
83
+ "aria-autocomplete": "none"
84
+ }),
85
+ ...(role === "combobox" && {
86
+ "aria-autocomplete": "list"
87
+ })
88
+ };
89
+ }, [ariaRole, floatingId, open, referenceId, role]);
90
+ var floating = React.useMemo(function () {
91
+ var floatingProps = {
92
+ id: floatingId,
93
+ ...(ariaRole && {
94
+ role: ariaRole
95
+ })
96
+ };
97
+ if (ariaRole === "tooltip" || role === "label") {
98
+ return floatingProps;
99
+ }
100
+ return {
101
+ ...floatingProps,
102
+ ...(ariaRole === "menu" && {
103
+ "aria-labelledby": referenceId
104
+ })
105
+ };
106
+ }, [ariaRole, floatingId, referenceId, role]);
107
+ var item = React.useCallback(function (param) {
108
+ var {
109
+ active,
110
+ selected
111
+ } = param;
112
+ var commonProps = {
113
+ role: "option",
114
+ ...(active && {
115
+ id: `${floatingId}-fui-option`
116
+ })
117
+ };
118
+ switch (role) {
119
+ case "select":
120
+ case "combobox":
121
+ return {
122
+ ...commonProps,
123
+ "aria-selected": selected
124
+ };
125
+ }
126
+ return {};
127
+ }, [floatingId, role]);
128
+ return React.useMemo(function () {
129
+ return enabled ? {
130
+ reference,
131
+ floating,
132
+ item
133
+ } : {};
134
+ }, [enabled, reference, floating, item]);
135
+ }
136
+ //# sourceMappingURL=useRole.native.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","useRole_exports","__export","useRole","module","exports","React","__toESM","require","componentRoleToAriaRoleMap","Map","idCounter","context","props","arguments","length","_elements_domReference","open","elements","enabled","role","defaultReferenceId","useId","referenceId","domReference","id","defaultFloatingId","useMemo","floatingId","_elements_floating","floating","_componentRoleToAriaRoleMap_get","ariaRole","get","reference","floatingProps"],"sources":["../../../src/interactions/useRole.ts"],"sourcesContent":[null],"mappings":";;;;;;;;;;;;;;;;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AM,IAAAD,+BAAgB,GAAAtB,0BAAA,CAAAwB,GAAA,CAAAb,IAAA,eAAAW,+BAAA,cAAAA,+BAAA,GAAAX,IAAA;EAAA,IACpBc,SAAI,GAAA5B,KAAA,CAAAqB,OAAA;IAAA,IACJK,QAAI,KAAY,SAAQ,IAAAZ,IAAS;MACnC;QAEI,SAAAA,IAAa,eAAa,YAAS,gBAAS,KAAAH,IAAA,GAAAW,UAAA;MAC9C;IACF;IAEA,OAAO;MACL,eAAG,EAAAX,IAAA;MACH,eAAI,EAAae,QAAA,KAAY,wBAAmB,GAAAA,QAAY;MAC9D,iBAAAf,IAAA,GAAAW,UAAA;MACE,IAAAI,QAAU,cAAY;QAEpBZ,IAAA;MACH,CAAE;MACD,IAAAY,QAAM,WAAc;QAClBP,EAAA,EAAAF;MAAM;MAER,IAAAH,IAAA;QAEA,mBAAc;MAAA;MACP,IACLA,IAAK;QACH,mBAAO;MAAA;IACF;EACc,IACnBY,QACJ,EAEAJ,UAAQ,EACVX,IAAA,EACAM,WAAC,EACHH,IAAA,CAEA;EAAa,IACXU,QAAO,GAAAxB,KAAY,CAAAqB,OAAA,aAAW;IAC9B,IAACQ,aAAS;MACZV,EAAA,EAAAG,UAAA;MACF,IAAAI,QAAA","ignoreList":[]}
@@ -0,0 +1,143 @@
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: true
9
+ });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
14
+ get: () => from[key],
15
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
16
+ });
17
+ }
18
+ return to;
19
+ };
20
+ var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
21
+ value: true
22
+ }), mod);
23
+ var useTypeahead_exports = {};
24
+ __export(useTypeahead_exports, {
25
+ useTypeahead: () => useTypeahead
26
+ });
27
+ module.exports = __toCommonJS(useTypeahead_exports);
28
+ var import_react = require("react");
29
+ var import_use_event = require("@tamagui/use-event");
30
+ var import_utils = require("./utils.cjs");
31
+ function useTypeahead(context, props) {
32
+ const {
33
+ open,
34
+ dataRef
35
+ } = context;
36
+ const {
37
+ listRef,
38
+ activeIndex,
39
+ onMatch: unstable_onMatch,
40
+ onTypingChange: unstable_onTypingChange,
41
+ enabled = true,
42
+ findMatch = null,
43
+ resetMs = 750,
44
+ ignoreKeys = [],
45
+ selectedIndex = null
46
+ } = props;
47
+ const timeoutIdRef = (0, import_react.useRef)(-1);
48
+ const stringRef = (0, import_react.useRef)("");
49
+ const prevIndexRef = (0, import_react.useRef)(selectedIndex ?? activeIndex ?? -1);
50
+ const matchIndexRef = (0, import_react.useRef)(null);
51
+ const onMatch = (0, import_use_event.useEvent)(unstable_onMatch || (() => {}));
52
+ const onTypingChange = (0, import_use_event.useEvent)(unstable_onTypingChange || (() => {}));
53
+ const findMatchRef = (0, import_react.useRef)(findMatch);
54
+ findMatchRef.current = findMatch;
55
+ const ignoreKeysRef = (0, import_react.useRef)(ignoreKeys);
56
+ ignoreKeysRef.current = ignoreKeys;
57
+ (0, import_react.useLayoutEffect)(() => {
58
+ if (open) {
59
+ (0, import_utils.clearTimeoutIfSet)(timeoutIdRef);
60
+ matchIndexRef.current = null;
61
+ stringRef.current = "";
62
+ }
63
+ }, [open]);
64
+ (0, import_react.useLayoutEffect)(() => {
65
+ if (open && stringRef.current === "") {
66
+ prevIndexRef.current = selectedIndex ?? activeIndex ?? -1;
67
+ }
68
+ }, [open, selectedIndex, activeIndex]);
69
+ const setTypingChange = value => {
70
+ if (value) {
71
+ if (!dataRef.current.typing) {
72
+ dataRef.current.typing = value;
73
+ onTypingChange(value);
74
+ }
75
+ } else {
76
+ if (dataRef.current.typing) {
77
+ dataRef.current.typing = value;
78
+ onTypingChange(value);
79
+ }
80
+ }
81
+ };
82
+ const onKeyDown = event => {
83
+ function getMatchingIndex(list, orderedList, string) {
84
+ const str = findMatchRef.current ? findMatchRef.current(orderedList, string) : orderedList.find(text => text?.toLocaleLowerCase().indexOf(string.toLocaleLowerCase()) === 0);
85
+ return str ? list.indexOf(str) : -1;
86
+ }
87
+ const listContent = listRef.current;
88
+ if (stringRef.current.length > 0 && stringRef.current[0] !== " ") {
89
+ if (getMatchingIndex(listContent, listContent, stringRef.current) === -1) {
90
+ setTypingChange(false);
91
+ } else if (event.key === " ") {
92
+ (0, import_utils.stopEvent)(event);
93
+ }
94
+ }
95
+ if (listContent == null || ignoreKeysRef.current.includes(event.key) ||
96
+ // character key
97
+ event.key.length !== 1 ||
98
+ // modifier key
99
+ event.ctrlKey || event.metaKey || event.altKey) {
100
+ return;
101
+ }
102
+ if (open && event.key !== " ") {
103
+ (0, import_utils.stopEvent)(event);
104
+ setTypingChange(true);
105
+ }
106
+ const allowRapidSuccessionOfFirstLetter = listContent.every(text => text ? text[0]?.toLocaleLowerCase() !== text[1]?.toLocaleLowerCase() : true);
107
+ if (allowRapidSuccessionOfFirstLetter && stringRef.current === event.key) {
108
+ stringRef.current = "";
109
+ prevIndexRef.current = matchIndexRef.current;
110
+ }
111
+ stringRef.current += event.key;
112
+ (0, import_utils.clearTimeoutIfSet)(timeoutIdRef);
113
+ timeoutIdRef.current = window.setTimeout(() => {
114
+ stringRef.current = "";
115
+ prevIndexRef.current = matchIndexRef.current;
116
+ setTypingChange(false);
117
+ }, resetMs);
118
+ const prevIndex = prevIndexRef.current;
119
+ const index = getMatchingIndex(listContent, [...listContent.slice((prevIndex || 0) + 1), ...listContent.slice(0, (prevIndex || 0) + 1)], stringRef.current);
120
+ if (index !== -1) {
121
+ onMatch(index);
122
+ matchIndexRef.current = index;
123
+ } else if (event.key !== " ") {
124
+ stringRef.current = "";
125
+ setTypingChange(false);
126
+ }
127
+ };
128
+ const reference = (0, import_react.useMemo)(() => ({
129
+ onKeyDown
130
+ }), [open, enabled]);
131
+ const floating = (0, import_react.useMemo)(() => ({
132
+ onKeyDown,
133
+ onKeyUp(event) {
134
+ if (event.key === " ") {
135
+ setTypingChange(false);
136
+ }
137
+ }
138
+ }), [open, enabled]);
139
+ return (0, import_react.useMemo)(() => enabled ? {
140
+ reference,
141
+ floating
142
+ } : {}, [enabled, reference, floating]);
143
+ }
@@ -0,0 +1,159 @@
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: true
11
+ });
12
+ };
13
+ var __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
16
+ get: () => from[key],
17
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
18
+ });
19
+ }
20
+ return to;
21
+ };
22
+ var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
23
+ value: true
24
+ }), mod);
25
+ var useTypeahead_exports = {};
26
+ __export(useTypeahead_exports, {
27
+ useTypeahead: () => useTypeahead
28
+ });
29
+ module.exports = __toCommonJS(useTypeahead_exports);
30
+ var import_react = require("react");
31
+ var import_use_event = require("@tamagui/use-event");
32
+ var import_utils = require("./utils.native.js");
33
+ function useTypeahead(context, props) {
34
+ var {
35
+ open,
36
+ dataRef
37
+ } = context;
38
+ var {
39
+ listRef,
40
+ activeIndex,
41
+ onMatch: unstable_onMatch,
42
+ onTypingChange: unstable_onTypingChange,
43
+ enabled = true,
44
+ findMatch = null,
45
+ resetMs = 750,
46
+ ignoreKeys = [],
47
+ selectedIndex = null
48
+ } = props;
49
+ var timeoutIdRef = (0, import_react.useRef)(-1);
50
+ var stringRef = (0, import_react.useRef)("");
51
+ var _ref;
52
+ var prevIndexRef = (0, import_react.useRef)((_ref = selectedIndex !== null && selectedIndex !== void 0 ? selectedIndex : activeIndex) !== null && _ref !== void 0 ? _ref : -1);
53
+ var matchIndexRef = (0, import_react.useRef)(null);
54
+ var onMatch = (0, import_use_event.useEvent)(unstable_onMatch || function () {});
55
+ var onTypingChange = (0, import_use_event.useEvent)(unstable_onTypingChange || function () {});
56
+ var findMatchRef = (0, import_react.useRef)(findMatch);
57
+ findMatchRef.current = findMatch;
58
+ var ignoreKeysRef = (0, import_react.useRef)(ignoreKeys);
59
+ ignoreKeysRef.current = ignoreKeys;
60
+ (0, import_react.useLayoutEffect)(function () {
61
+ if (open) {
62
+ (0, import_utils.clearTimeoutIfSet)(timeoutIdRef);
63
+ matchIndexRef.current = null;
64
+ stringRef.current = "";
65
+ }
66
+ }, [open]);
67
+ (0, import_react.useLayoutEffect)(function () {
68
+ if (open && stringRef.current === "") {
69
+ var _ref2;
70
+ prevIndexRef.current = (_ref2 = selectedIndex !== null && selectedIndex !== void 0 ? selectedIndex : activeIndex) !== null && _ref2 !== void 0 ? _ref2 : -1;
71
+ }
72
+ }, [open, selectedIndex, activeIndex]);
73
+ var setTypingChange = function (value) {
74
+ if (value) {
75
+ if (!dataRef.current.typing) {
76
+ dataRef.current.typing = value;
77
+ onTypingChange(value);
78
+ }
79
+ } else {
80
+ if (dataRef.current.typing) {
81
+ dataRef.current.typing = value;
82
+ onTypingChange(value);
83
+ }
84
+ }
85
+ };
86
+ var onKeyDown = function (event) {
87
+ function getMatchingIndex(list, orderedList, string) {
88
+ var str = findMatchRef.current ? findMatchRef.current(orderedList, string) : orderedList.find(function (text) {
89
+ return (text === null || text === void 0 ? void 0 : text.toLocaleLowerCase().indexOf(string.toLocaleLowerCase())) === 0;
90
+ });
91
+ return str ? list.indexOf(str) : -1;
92
+ }
93
+ var listContent = listRef.current;
94
+ if (stringRef.current.length > 0 && stringRef.current[0] !== " ") {
95
+ if (getMatchingIndex(listContent, listContent, stringRef.current) === -1) {
96
+ setTypingChange(false);
97
+ } else if (event.key === " ") {
98
+ (0, import_utils.stopEvent)(event);
99
+ }
100
+ }
101
+ if (listContent == null || ignoreKeysRef.current.includes(event.key) ||
102
+ // character key
103
+ event.key.length !== 1 ||
104
+ // modifier key
105
+ event.ctrlKey || event.metaKey || event.altKey) {
106
+ return;
107
+ }
108
+ if (open && event.key !== " ") {
109
+ (0, import_utils.stopEvent)(event);
110
+ setTypingChange(true);
111
+ }
112
+ var allowRapidSuccessionOfFirstLetter = listContent.every(function (text) {
113
+ var _text_, _text_1;
114
+ return text ? ((_text_ = text[0]) === null || _text_ === void 0 ? void 0 : _text_.toLocaleLowerCase()) !== ((_text_1 = text[1]) === null || _text_1 === void 0 ? void 0 : _text_1.toLocaleLowerCase()) : true;
115
+ });
116
+ if (allowRapidSuccessionOfFirstLetter && stringRef.current === event.key) {
117
+ stringRef.current = "";
118
+ prevIndexRef.current = matchIndexRef.current;
119
+ }
120
+ stringRef.current += event.key;
121
+ (0, import_utils.clearTimeoutIfSet)(timeoutIdRef);
122
+ timeoutIdRef.current = window.setTimeout(function () {
123
+ stringRef.current = "";
124
+ prevIndexRef.current = matchIndexRef.current;
125
+ setTypingChange(false);
126
+ }, resetMs);
127
+ var prevIndex = prevIndexRef.current;
128
+ var index = getMatchingIndex(listContent, [...listContent.slice((prevIndex || 0) + 1), ...listContent.slice(0, (prevIndex || 0) + 1)], stringRef.current);
129
+ if (index !== -1) {
130
+ onMatch(index);
131
+ matchIndexRef.current = index;
132
+ } else if (event.key !== " ") {
133
+ stringRef.current = "";
134
+ setTypingChange(false);
135
+ }
136
+ };
137
+ var reference = (0, import_react.useMemo)(function () {
138
+ return {
139
+ onKeyDown
140
+ };
141
+ }, [open, enabled]);
142
+ var floating = (0, import_react.useMemo)(function () {
143
+ return {
144
+ onKeyDown,
145
+ onKeyUp(event) {
146
+ if (event.key === " ") {
147
+ setTypingChange(false);
148
+ }
149
+ }
150
+ };
151
+ }, [open, enabled]);
152
+ return (0, import_react.useMemo)(function () {
153
+ return enabled ? {
154
+ reference,
155
+ floating
156
+ } : {};
157
+ }, [enabled, reference, floating]);
158
+ }
159
+ //# sourceMappingURL=useTypeahead.native.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","useTypeahead_exports","__export","useTypeahead","module","exports","import_react","require","import_use_event","import_utils","context","props","open","dataRef","listRef","activeIndex","onMatch","unstable_onMatch","onTypingChange","unstable_onTypingChange","enabled","findMatch","resetMs","ignoreKeys","selectedIndex","timeoutIdRef","useRef","stringRef","_ref","prevIndexRef","matchIndexRef","useEvent","findMatchRef","current","ignoreKeysRef","useLayoutEffect","clearTimeoutIfSet","_ref2","setTypingChange","typing","onKeyDown","event","getMatchingIndex","list","orderedList","string","str","find","text","toLocaleLowerCase","indexOf","listContent","length","key","stopEvent","includes","ctrlKey","metaKey","altKey","allowRapidSuccessionOfFirstLetter","every","_text_","_text_1","window","setTimeout","prevIndex","index","slice","reference","useMemo","floating","onKeyUp"],"sources":["../../../src/interactions/useTypeahead.ts"],"sourcesContent":[null],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,GAAA,IAAAC,WAAA,CAAAC,SAAA;EAAAC,KAAA;AAAA,IAAAH,GAAA;AAAA,IAAAI,oBAAA;AAAAC,QAAA,CAAAD,oBAAA;EAAAE,YAAA,EAAAA,CAAA,KAAAA;AAAA;AAAAC,MAAA,CAAAC,OAAA,GAAAT,YAAiD,CAAAK,oBAAA;AACjD,IAAAK,YAAA,GAAAC,OAAyB;AAEzB,IAAAC,gBAA6C,GAAAD,OAAA;AAItC,IAAAE,YAAS,GAAAF,OACd,oBACA;AAEA,SAAMJ,YAAQA,CAAAO,OAAY,EAAA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Aa;IAE/B,IAAAiC,KAAM,GAAAxB,gBAAQ,CAAAS,WAAA,GACZ,GAAAA,WAAA,CAAAgB,KAAA,EAAAF,SAAA,aACA,GAAAd,WAAA,CAAAgB,KAAA,KAAAF,SAAA,cAAAtC,SACK,CAAAM,OAAY;IAA0B,IACzCiC,KAAG;MACLlD,OAAA,CAAAkD,KAAA;MACApC,aAAU,CAAAG,OAAA,GAAAiC,KAAA;IACZ,WAAAzB,KAAA,CAAAY,GAAA;MAEA1B,SAAI,CAAAM,OAAc;MAChBK,eAAa;IACb;EAAwB;EAExB,IAAA8B,SAAA,GAAU,IAAA9D,YAAU,CAAA+D,OAAA;IACpB;MACF7B;IACF;EAEA,IACE5B,IAAA,EACAQ,OAAO,CACT;EAEA,IAAAkD,QAAM,OAAAhE,YAAqC,CAAA+D,OAAA;IACzC,OAAO;MACL7B,SAAA;MACA+B,QAAQ9B,KAAA,EAA4B;QAClC,IAAIA,KAAA,CAAMY,GAAA,KAAQ,KAAK;UACrBf,eAAA,CAAgB,KAAK;QACvB;MACF;IACF;EAAA,GACC,CACH1B,IAAA,EAEAQ,OAAA,CAAO,CACL;EAA4C,OAC3C,IAAAd,YAAoB,CAAA+D,OAAQ;IAC/B,OAAAjD,OAAA;MACFgD,SAAA","ignoreList":[]}
@@ -0,0 +1,208 @@
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: true
9
+ });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
14
+ get: () => from[key],
15
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
16
+ });
17
+ }
18
+ return to;
19
+ };
20
+ var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
21
+ value: true
22
+ }), mod);
23
+ var utils_exports = {};
24
+ __export(utils_exports, {
25
+ activeElement: () => activeElement,
26
+ clearTimeoutIfSet: () => clearTimeoutIfSet,
27
+ contains: () => contains,
28
+ enqueueFocus: () => enqueueFocus,
29
+ findNonDisabledListIndex: () => findNonDisabledListIndex,
30
+ getDocument: () => getDocument,
31
+ getMaxListIndex: () => getMaxListIndex,
32
+ getMinListIndex: () => getMinListIndex,
33
+ getTarget: () => getTarget,
34
+ isElement: () => isElement,
35
+ isHTMLElement: () => isHTMLElement,
36
+ isIndexOutOfListBounds: () => isIndexOutOfListBounds,
37
+ isListIndexDisabled: () => isListIndexDisabled,
38
+ isMac: () => isMac,
39
+ isMouseLikePointerType: () => isMouseLikePointerType,
40
+ isSafari: () => isSafari,
41
+ isTypeableCombobox: () => isTypeableCombobox,
42
+ isTypeableElement: () => isTypeableElement,
43
+ isVirtualClick: () => isVirtualClick,
44
+ isVirtualPointerEvent: () => isVirtualPointerEvent,
45
+ matchesFocusVisible: () => matchesFocusVisible,
46
+ stopEvent: () => stopEvent
47
+ });
48
+ module.exports = __toCommonJS(utils_exports);
49
+ function getDocument(node) {
50
+ return node?.ownerDocument || document;
51
+ }
52
+ function contains(parent, child) {
53
+ if (!parent || !child) return false;
54
+ const rootNode = child.getRootNode?.();
55
+ if (parent.contains(child)) return true;
56
+ if (rootNode && isShadowRoot(rootNode)) {
57
+ let next = child;
58
+ while (next) {
59
+ if (parent === next) return true;
60
+ next = next.parentNode || next.host;
61
+ }
62
+ }
63
+ return false;
64
+ }
65
+ function isShadowRoot(node) {
66
+ return node instanceof ShadowRoot;
67
+ }
68
+ function getTarget(event) {
69
+ if ("composedPath" in event) {
70
+ return event.composedPath()[0];
71
+ }
72
+ return event.target;
73
+ }
74
+ function activeElement(doc) {
75
+ let el = doc.activeElement;
76
+ while (el?.shadowRoot?.activeElement != null) {
77
+ el = el.shadowRoot.activeElement;
78
+ }
79
+ return el;
80
+ }
81
+ function isHTMLElement(value) {
82
+ return value instanceof HTMLElement;
83
+ }
84
+ function isElement(value) {
85
+ return value instanceof Element;
86
+ }
87
+ const TYPEABLE_SELECTOR = "input:not([type='hidden']):not([disabled]),[contenteditable]:not([contenteditable='false']),textarea:not([disabled])";
88
+ function isTypeableElement(element) {
89
+ return isHTMLElement(element) && element.matches(TYPEABLE_SELECTOR);
90
+ }
91
+ function isTypeableCombobox(element) {
92
+ if (!element) return false;
93
+ return element.getAttribute("role") === "combobox" && isTypeableElement(element);
94
+ }
95
+ function getPlatform() {
96
+ const uaData = navigator.userAgentData;
97
+ if (uaData?.platform) return uaData.platform;
98
+ return navigator.platform;
99
+ }
100
+ function getUserAgent() {
101
+ const uaData = navigator.userAgentData;
102
+ if (uaData && Array.isArray(uaData.brands)) {
103
+ return uaData.brands.map(({
104
+ brand,
105
+ version
106
+ }) => `${brand}/${version}`).join(" ");
107
+ }
108
+ return navigator.userAgent;
109
+ }
110
+ function isSafari() {
111
+ return /apple/i.test(navigator.vendor);
112
+ }
113
+ function isMac() {
114
+ return getPlatform().toLowerCase().startsWith("mac") && !navigator.maxTouchPoints;
115
+ }
116
+ function isJSDOM() {
117
+ return getUserAgent().includes("jsdom/");
118
+ }
119
+ function matchesFocusVisible(element) {
120
+ if (!element || isJSDOM()) return true;
121
+ try {
122
+ return element.matches(":focus-visible");
123
+ } catch {
124
+ return true;
125
+ }
126
+ }
127
+ function isMouseLikePointerType(pointerType, strict) {
128
+ const values = ["mouse", "pen"];
129
+ if (!strict) {
130
+ values.push("", void 0);
131
+ }
132
+ return values.includes(pointerType);
133
+ }
134
+ function clearTimeoutIfSet(timeoutRef) {
135
+ if (timeoutRef.current !== -1) {
136
+ clearTimeout(timeoutRef.current);
137
+ timeoutRef.current = -1;
138
+ }
139
+ }
140
+ function stopEvent(event) {
141
+ event.preventDefault();
142
+ event.stopPropagation();
143
+ }
144
+ function isVirtualClick(event) {
145
+ if (event.mozInputSource === 0 && event.isTrusted) return true;
146
+ if (isAndroid() && event.pointerType) {
147
+ return event.type === "click" && event.buttons === 1;
148
+ }
149
+ return event.detail === 0 && !event.pointerType;
150
+ }
151
+ function isVirtualPointerEvent(event) {
152
+ if (isJSDOM()) return false;
153
+ return !isAndroid() && event.width === 0 && event.height === 0 || isAndroid() && event.width === 1 && event.height === 1 && event.pressure === 0 && event.detail === 0 && event.pointerType === "mouse" || event.width < 1 && event.height < 1 && event.pressure === 0 && event.detail === 0 && event.pointerType === "touch";
154
+ }
155
+ function isAndroid() {
156
+ const re = /android/i;
157
+ return re.test(getPlatform()) || re.test(getUserAgent());
158
+ }
159
+ let rafId = 0;
160
+ function enqueueFocus(el, options = {}) {
161
+ const {
162
+ preventScroll = false,
163
+ cancelPrevious = true,
164
+ sync = false
165
+ } = options;
166
+ cancelPrevious && cancelAnimationFrame(rafId);
167
+ const exec = () => el?.focus({
168
+ preventScroll
169
+ });
170
+ if (sync) {
171
+ exec();
172
+ } else {
173
+ rafId = requestAnimationFrame(exec);
174
+ }
175
+ }
176
+ function isListIndexDisabled(listRef, index, disabledIndices) {
177
+ if (typeof disabledIndices === "function") return disabledIndices(index);
178
+ if (disabledIndices) return disabledIndices.includes(index);
179
+ const element = listRef.current[index];
180
+ return element == null || element.hasAttribute("disabled") || element.getAttribute("aria-disabled") === "true";
181
+ }
182
+ function findNonDisabledListIndex(listRef, {
183
+ startingIndex = -1,
184
+ decrement = false,
185
+ disabledIndices,
186
+ amount = 1
187
+ } = {}) {
188
+ let index = startingIndex;
189
+ do {
190
+ index += decrement ? -amount : amount;
191
+ } while (index >= 0 && index <= listRef.current.length - 1 && isListIndexDisabled(listRef, index, disabledIndices));
192
+ return index;
193
+ }
194
+ function getMinListIndex(listRef, disabledIndices) {
195
+ return findNonDisabledListIndex(listRef, {
196
+ disabledIndices
197
+ });
198
+ }
199
+ function getMaxListIndex(listRef, disabledIndices) {
200
+ return findNonDisabledListIndex(listRef, {
201
+ decrement: true,
202
+ startingIndex: listRef.current.length,
203
+ disabledIndices
204
+ });
205
+ }
206
+ function isIndexOutOfListBounds(listRef, index) {
207
+ return index < 0 || index >= listRef.current.length;
208
+ }