@tamagui/floating 2.7.7 → 3.0.0-beta.643.1

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 (151) hide show
  1. package/dist/cjs/Floating.cjs +10 -11
  2. package/dist/cjs/Floating.native.cjs +37 -0
  3. package/dist/cjs/Floating.native.js +20 -20
  4. package/dist/cjs/Floating.native.js.map +1 -1
  5. package/dist/cjs/index.cjs +45 -46
  6. package/dist/cjs/index.native.cjs +74 -0
  7. package/dist/cjs/index.native.js +45 -45
  8. package/dist/cjs/index.native.js.map +1 -1
  9. package/dist/cjs/interactions/PopupTriggerMap.cjs +36 -39
  10. package/dist/cjs/interactions/PopupTriggerMap.native.cjs +96 -0
  11. package/dist/cjs/interactions/PopupTriggerMap.native.js +76 -75
  12. package/dist/cjs/interactions/PopupTriggerMap.native.js.map +1 -1
  13. package/dist/cjs/interactions/createFloatingEvents.cjs +36 -39
  14. package/dist/cjs/interactions/createFloatingEvents.native.cjs +52 -0
  15. package/dist/cjs/interactions/createFloatingEvents.native.js +39 -41
  16. package/dist/cjs/interactions/createFloatingEvents.native.js.map +1 -1
  17. package/dist/cjs/interactions/safePolygon.cjs +263 -252
  18. package/dist/cjs/interactions/safePolygon.native.cjs +294 -0
  19. package/dist/cjs/interactions/safePolygon.native.js +271 -259
  20. package/dist/cjs/interactions/safePolygon.native.js.map +1 -1
  21. package/dist/cjs/interactions/types.cjs +10 -11
  22. package/dist/cjs/interactions/types.native.cjs +19 -0
  23. package/dist/cjs/interactions/types.native.js +10 -10
  24. package/dist/cjs/interactions/types.native.js.map +1 -1
  25. package/dist/cjs/interactions/useClick.cjs +96 -105
  26. package/dist/cjs/interactions/useClick.native.cjs +122 -0
  27. package/dist/cjs/interactions/useClick.native.js +101 -109
  28. package/dist/cjs/interactions/useClick.native.js.map +1 -1
  29. package/dist/cjs/interactions/useDelayGroup.cjs +86 -91
  30. package/dist/cjs/interactions/useDelayGroup.native.cjs +119 -0
  31. package/dist/cjs/interactions/useDelayGroup.native.js +92 -96
  32. package/dist/cjs/interactions/useDelayGroup.native.js.map +1 -1
  33. package/dist/cjs/interactions/useFocus.cjs +108 -115
  34. package/dist/cjs/interactions/useFocus.native.cjs +131 -0
  35. package/dist/cjs/interactions/useFocus.native.js +114 -120
  36. package/dist/cjs/interactions/useFocus.native.js.map +1 -1
  37. package/dist/cjs/interactions/useHover.cjs +321 -335
  38. package/dist/cjs/interactions/useHover.native.cjs +357 -0
  39. package/dist/cjs/interactions/useHover.native.js +333 -347
  40. package/dist/cjs/interactions/useHover.native.js.map +1 -1
  41. package/dist/cjs/interactions/useInnerOffset.cjs +103 -111
  42. package/dist/cjs/interactions/useInnerOffset.native.cjs +132 -0
  43. package/dist/cjs/interactions/useInnerOffset.native.js +113 -120
  44. package/dist/cjs/interactions/useInnerOffset.native.js.map +1 -1
  45. package/dist/cjs/interactions/useInteractions.cjs +85 -90
  46. package/dist/cjs/interactions/useInteractions.native.cjs +199 -0
  47. package/dist/cjs/interactions/useInteractions.native.js +180 -195
  48. package/dist/cjs/interactions/useInteractions.native.js.map +1 -1
  49. package/dist/cjs/interactions/useListNavigation.cjs +404 -390
  50. package/dist/cjs/interactions/useListNavigation.native.cjs +446 -0
  51. package/dist/cjs/interactions/useListNavigation.native.js +416 -401
  52. package/dist/cjs/interactions/useListNavigation.native.js.map +1 -1
  53. package/dist/cjs/interactions/useRole.cjs +92 -106
  54. package/dist/cjs/interactions/useRole.native.cjs +121 -0
  55. package/dist/cjs/interactions/useRole.native.js +103 -116
  56. package/dist/cjs/interactions/useRole.native.js.map +1 -1
  57. package/dist/cjs/interactions/useTypeahead.cjs +115 -129
  58. package/dist/cjs/interactions/useTypeahead.native.cjs +144 -0
  59. package/dist/cjs/interactions/useTypeahead.native.js +128 -141
  60. package/dist/cjs/interactions/useTypeahead.native.js.map +1 -1
  61. package/dist/cjs/interactions/utils.cjs +126 -143
  62. package/dist/cjs/interactions/utils.native.cjs +209 -0
  63. package/dist/cjs/interactions/utils.native.js +138 -154
  64. package/dist/cjs/interactions/utils.native.js.map +1 -1
  65. package/dist/cjs/middleware/inner.cjs +74 -101
  66. package/dist/cjs/middleware/inner.native.cjs +102 -0
  67. package/dist/cjs/middleware/inner.native.js +83 -109
  68. package/dist/cjs/middleware/inner.native.js.map +1 -1
  69. package/dist/cjs/useFloating.cjs +34 -46
  70. package/dist/cjs/useFloating.native.cjs +56 -0
  71. package/dist/cjs/useFloating.native.js +37 -48
  72. package/dist/cjs/useFloating.native.js.map +1 -1
  73. package/dist/esm/Floating.mjs +1 -2
  74. package/dist/esm/Floating.native.js +6 -4
  75. package/dist/esm/Floating.native.js.map +1 -1
  76. package/dist/esm/index.js +4 -5
  77. package/dist/esm/index.mjs +4 -5
  78. package/dist/esm/index.native.js +4 -5
  79. package/dist/esm/interactions/PopupTriggerMap.mjs +23 -22
  80. package/dist/esm/interactions/PopupTriggerMap.mjs.map +1 -1
  81. package/dist/esm/interactions/PopupTriggerMap.native.js +62 -58
  82. package/dist/esm/interactions/PopupTriggerMap.native.js.map +1 -1
  83. package/dist/esm/interactions/createFloatingEvents.mjs +22 -21
  84. package/dist/esm/interactions/createFloatingEvents.mjs.map +1 -1
  85. package/dist/esm/interactions/createFloatingEvents.native.js +25 -24
  86. package/dist/esm/interactions/createFloatingEvents.native.js.map +1 -1
  87. package/dist/esm/interactions/safePolygon.mjs +250 -234
  88. package/dist/esm/interactions/safePolygon.mjs.map +1 -1
  89. package/dist/esm/interactions/safePolygon.native.js +258 -242
  90. package/dist/esm/interactions/safePolygon.native.js.map +1 -1
  91. package/dist/esm/interactions/types.mjs +0 -2
  92. package/dist/esm/interactions/types.native.js +0 -2
  93. package/dist/esm/interactions/useClick.mjs +83 -87
  94. package/dist/esm/interactions/useClick.mjs.map +1 -1
  95. package/dist/esm/interactions/useClick.native.js +88 -92
  96. package/dist/esm/interactions/useClick.native.js.map +1 -1
  97. package/dist/esm/interactions/useDelayGroup.mjs +68 -65
  98. package/dist/esm/interactions/useDelayGroup.mjs.map +1 -1
  99. package/dist/esm/interactions/useDelayGroup.native.js +74 -71
  100. package/dist/esm/interactions/useDelayGroup.native.js.map +1 -1
  101. package/dist/esm/interactions/useFocus.mjs +95 -97
  102. package/dist/esm/interactions/useFocus.mjs.map +1 -1
  103. package/dist/esm/interactions/useFocus.native.js +101 -103
  104. package/dist/esm/interactions/useFocus.native.js.map +1 -1
  105. package/dist/esm/interactions/useHover.mjs +304 -310
  106. package/dist/esm/interactions/useHover.mjs.map +1 -1
  107. package/dist/esm/interactions/useHover.native.js +316 -323
  108. package/dist/esm/interactions/useHover.native.js.map +1 -1
  109. package/dist/esm/interactions/useInnerOffset.mjs +87 -85
  110. package/dist/esm/interactions/useInnerOffset.mjs.map +1 -1
  111. package/dist/esm/interactions/useInnerOffset.native.js +97 -95
  112. package/dist/esm/interactions/useInnerOffset.native.js.map +1 -1
  113. package/dist/esm/interactions/useInteractions.mjs +71 -72
  114. package/dist/esm/interactions/useInteractions.mjs.map +1 -1
  115. package/dist/esm/interactions/useInteractions.native.js +166 -178
  116. package/dist/esm/interactions/useInteractions.native.js.map +1 -1
  117. package/dist/esm/interactions/useListNavigation.mjs +392 -373
  118. package/dist/esm/interactions/useListNavigation.mjs.map +1 -1
  119. package/dist/esm/interactions/useListNavigation.native.js +404 -385
  120. package/dist/esm/interactions/useListNavigation.native.js.map +1 -1
  121. package/dist/esm/interactions/useRole.mjs +76 -80
  122. package/dist/esm/interactions/useRole.mjs.map +1 -1
  123. package/dist/esm/interactions/useRole.native.js +87 -91
  124. package/dist/esm/interactions/useRole.native.js.map +1 -1
  125. package/dist/esm/interactions/useTypeahead.mjs +102 -111
  126. package/dist/esm/interactions/useTypeahead.mjs.map +1 -1
  127. package/dist/esm/interactions/useTypeahead.native.js +115 -124
  128. package/dist/esm/interactions/useTypeahead.native.js.map +1 -1
  129. package/dist/esm/interactions/utils.mjs +91 -106
  130. package/dist/esm/interactions/utils.mjs.map +1 -1
  131. package/dist/esm/interactions/utils.native.js +103 -118
  132. package/dist/esm/interactions/utils.native.js.map +1 -1
  133. package/dist/esm/middleware/inner.mjs +58 -75
  134. package/dist/esm/middleware/inner.mjs.map +1 -1
  135. package/dist/esm/middleware/inner.native.js +67 -84
  136. package/dist/esm/middleware/inner.native.js.map +1 -1
  137. package/dist/esm/useFloating.mjs +17 -21
  138. package/dist/esm/useFloating.mjs.map +1 -1
  139. package/dist/esm/useFloating.native.js +19 -23
  140. package/dist/esm/useFloating.native.js.map +1 -1
  141. package/package.json +6 -5
  142. package/types/interactions/PopupTriggerMap.d.ts.map +1 -1
  143. package/types/interactions/useInteractions.d.ts.map +1 -1
  144. package/types/middleware/inner.d.ts.map +1 -1
  145. package/types/useFloating.d.ts.map +1 -1
  146. package/dist/esm/Floating.mjs.map +0 -1
  147. package/dist/esm/index.js.map +0 -1
  148. package/dist/esm/index.mjs.map +0 -1
  149. package/dist/esm/index.native.js.map +0 -1
  150. package/dist/esm/interactions/types.mjs.map +0 -1
  151. package/dist/esm/interactions/types.native.js.map +0 -1
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
 
3
+
3
4
  var __create = Object.create;
4
5
  var __defProp = Object.defineProperty;
5
6
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -7,130 +8,116 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
7
8
  var __getProtoOf = Object.getPrototypeOf;
8
9
  var __hasOwnProp = Object.prototype.hasOwnProperty;
9
10
  var __export = (target, all) => {
10
- for (var name in all) __defProp(target, name, {
11
- get: all[name],
12
- enumerable: true
13
- });
11
+ for (var name in all) __defProp(target, name, {
12
+ get: all[name],
13
+ enumerable: true
14
+ });
14
15
  };
15
16
  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;
17
+ if (from && typeof from === "object" || typeof from === "function") {
18
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
19
+ get: () => from[key],
20
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
21
+ });
22
+ }
23
+ return to;
23
24
  };
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
25
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
26
+ value: mod,
27
+ enumerable: true
32
28
  }) : target, mod));
33
- var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
34
- value: true
35
- }), mod);
29
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
36
30
  var useRole_exports = {};
37
- __export(useRole_exports, {
38
- useRole: () => useRole
39
- });
31
+ __export(useRole_exports, { useRole: () => useRole });
40
32
  module.exports = __toCommonJS(useRole_exports);
41
33
  var React = __toESM(require("react"), 1);
42
- var componentRoleToAriaRoleMap = /* @__PURE__ */new Map([["select", "listbox"], ["combobox", "listbox"], ["label", false]]);
34
+ var componentRoleToAriaRoleMap = /* @__PURE__ */ new Map([
35
+ ["select", "listbox"],
36
+ ["combobox", "listbox"],
37
+ ["label", false]
38
+ ]);
43
39
  var idCounter = 0;
44
40
  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]);
41
+ var props = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
42
+ var _elements_domReference;
43
+ var { open, elements } = context;
44
+ var { enabled = true, role = "dialog" } = props;
45
+ var defaultReferenceId = React.useId();
46
+ var referenceId = ((_elements_domReference = elements.domReference) === null || _elements_domReference === void 0 ? void 0 : _elements_domReference.id) || defaultReferenceId;
47
+ var defaultFloatingId = React.useMemo(function() {
48
+ return `floating-${idCounter++}`;
49
+ }, []);
50
+ var floatingId = React.useMemo(function() {
51
+ var _elements_floating;
52
+ return ((_elements_floating = elements.floating) === null || _elements_floating === void 0 ? void 0 : _elements_floating.id) || defaultFloatingId;
53
+ }, [elements.floating, defaultFloatingId]);
54
+ var _componentRoleToAriaRoleMap_get;
55
+ var ariaRole = (_componentRoleToAriaRoleMap_get = componentRoleToAriaRoleMap.get(role)) !== null && _componentRoleToAriaRoleMap_get !== void 0 ? _componentRoleToAriaRoleMap_get : role;
56
+ var reference = React.useMemo(function() {
57
+ if (ariaRole === "tooltip" || role === "label") {
58
+ return { [`aria-${role === "label" ? "labelledby" : "describedby"}`]: open ? floatingId : void 0 };
59
+ }
60
+ return {
61
+ "aria-expanded": open ? "true" : "false",
62
+ "aria-haspopup": ariaRole === "alertdialog" ? "dialog" : ariaRole,
63
+ "aria-controls": open ? floatingId : void 0,
64
+ ...ariaRole === "listbox" && { role: "combobox" },
65
+ ...ariaRole === "menu" && { id: referenceId },
66
+ ...role === "select" && { "aria-autocomplete": "none" },
67
+ ...role === "combobox" && { "aria-autocomplete": "list" }
68
+ };
69
+ }, [
70
+ ariaRole,
71
+ floatingId,
72
+ open,
73
+ referenceId,
74
+ role
75
+ ]);
76
+ var floating = React.useMemo(function() {
77
+ var floatingProps = {
78
+ id: floatingId,
79
+ ...ariaRole && { role: ariaRole }
80
+ };
81
+ if (ariaRole === "tooltip" || role === "label") {
82
+ return floatingProps;
83
+ }
84
+ return {
85
+ ...floatingProps,
86
+ ...ariaRole === "menu" && { "aria-labelledby": referenceId }
87
+ };
88
+ }, [
89
+ ariaRole,
90
+ floatingId,
91
+ referenceId,
92
+ role
93
+ ]);
94
+ var item = React.useCallback(function(param) {
95
+ var { active, selected } = param;
96
+ var commonProps = {
97
+ role: "option",
98
+ ...active && { id: `${floatingId}-fui-option` }
99
+ };
100
+ switch (role) {
101
+ case "select":
102
+ case "combobox": return {
103
+ ...commonProps,
104
+ "aria-selected": selected
105
+ };
106
+ }
107
+ return {};
108
+ }, [floatingId, role]);
109
+ return React.useMemo(function() {
110
+ return enabled ? {
111
+ reference,
112
+ floating,
113
+ item
114
+ } : {};
115
+ }, [
116
+ enabled,
117
+ reference,
118
+ floating,
119
+ item
120
+ ]);
135
121
  }
122
+
136
123
  //# sourceMappingURL=useRole.native.js.map
@@ -1 +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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,GAAA,IAAAC,WAAA,CAAAC,SAAA;EAAAC,KAAA;AAAA,IAAAH,GAAA;AAAA,IAAAI,eAAA;AAAAC,QAAA,CAAAD,eAAA;EAAAE,OAAA,EAAAA,CAAA,KAAAA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Z,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":[]}
1
+ {"version":3,"file":"useRole.native.js","names":[],"sources":["cjs/interactions/useRole.native.js"],"sourcesContent":["\"use strict\";\nvar __create = Object.create;\nvar __defProp = Object.defineProperty;\nvar __getOwnPropDesc = Object.getOwnPropertyDescriptor;\nvar __getOwnPropNames = Object.getOwnPropertyNames;\nvar __getProtoOf = Object.getPrototypeOf;\nvar __hasOwnProp = Object.prototype.hasOwnProperty;\nvar __export = (target, all) => {\n for (var name in all)\n __defProp(target, name, { get: all[name], enumerable: true });\n};\nvar __copyProps = (to, from, except, desc) => {\n if (from && typeof from === \"object\" || typeof from === \"function\") {\n for (let key of __getOwnPropNames(from))\n if (!__hasOwnProp.call(to, key) && key !== except)\n __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });\n }\n return to;\n};\nvar __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(\n // If the importer is in node compatibility mode or this is not an ESM\n // file that has been converted to a CommonJS file using a Babel-\n // compatible transform (i.e. \"__esModule\" has not been set), then set\n // \"default\" to the CommonJS \"module.exports\" for node compatibility.\n isNodeMode || !mod || !mod.__esModule ? __defProp(target, \"default\", { value: mod, enumerable: true }) : target,\n mod\n));\nvar __toCommonJS = (mod) => __copyProps(__defProp({}, \"__esModule\", { value: true }), mod);\nvar useRole_exports = {};\n__export(useRole_exports, {\n useRole: () => useRole\n});\nmodule.exports = __toCommonJS(useRole_exports);\nvar React = __toESM(require(\"react\"), 1);\nvar componentRoleToAriaRoleMap = /* @__PURE__ */ new Map([\n [\n \"select\",\n \"listbox\"\n ],\n [\n \"combobox\",\n \"listbox\"\n ],\n [\n \"label\",\n false\n ]\n]);\nvar idCounter = 0;\nfunction useRole(context) {\n var props = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};\n var _elements_domReference;\n var { open, elements } = context;\n var { enabled = true, role = \"dialog\" } = props;\n var defaultReferenceId = React.useId();\n var referenceId = ((_elements_domReference = elements.domReference) === null || _elements_domReference === void 0 ? void 0 : _elements_domReference.id) || defaultReferenceId;\n var defaultFloatingId = React.useMemo(function() {\n return `floating-${idCounter++}`;\n }, []);\n var floatingId = React.useMemo(function() {\n var _elements_floating;\n return ((_elements_floating = elements.floating) === null || _elements_floating === void 0 ? void 0 : _elements_floating.id) || defaultFloatingId;\n }, [\n elements.floating,\n defaultFloatingId\n ]);\n var _componentRoleToAriaRoleMap_get;\n var ariaRole = (_componentRoleToAriaRoleMap_get = componentRoleToAriaRoleMap.get(role)) !== null && _componentRoleToAriaRoleMap_get !== void 0 ? _componentRoleToAriaRoleMap_get : role;\n var reference = React.useMemo(function() {\n if (ariaRole === \"tooltip\" || role === \"label\") {\n return {\n [`aria-${role === \"label\" ? \"labelledby\" : \"describedby\"}`]: open ? floatingId : void 0\n };\n }\n return {\n \"aria-expanded\": open ? \"true\" : \"false\",\n \"aria-haspopup\": ariaRole === \"alertdialog\" ? \"dialog\" : ariaRole,\n \"aria-controls\": open ? floatingId : void 0,\n ...ariaRole === \"listbox\" && {\n role: \"combobox\"\n },\n ...ariaRole === \"menu\" && {\n id: referenceId\n },\n ...role === \"select\" && {\n \"aria-autocomplete\": \"none\"\n },\n ...role === \"combobox\" && {\n \"aria-autocomplete\": \"list\"\n }\n };\n }, [\n ariaRole,\n floatingId,\n open,\n referenceId,\n role\n ]);\n var floating = React.useMemo(function() {\n var floatingProps = {\n id: floatingId,\n ...ariaRole && {\n role: ariaRole\n }\n };\n if (ariaRole === \"tooltip\" || role === \"label\") {\n return floatingProps;\n }\n return {\n ...floatingProps,\n ...ariaRole === \"menu\" && {\n \"aria-labelledby\": referenceId\n }\n };\n }, [\n ariaRole,\n floatingId,\n referenceId,\n role\n ]);\n var item = React.useCallback(function(param) {\n var { active, selected } = param;\n var commonProps = {\n role: \"option\",\n ...active && {\n id: `${floatingId}-fui-option`\n }\n };\n switch (role) {\n case \"select\":\n case \"combobox\":\n return {\n ...commonProps,\n \"aria-selected\": selected\n };\n }\n return {};\n }, [\n floatingId,\n role\n ]);\n return React.useMemo(function() {\n return enabled ? {\n reference,\n floating,\n item\n } : {};\n }, [\n enabled,\n reference,\n floating,\n item\n ]);\n}\n//# sourceMappingURL=useRole.js.map\n"],"mappings":";;;;AACA,IAAI,WAAW,OAAO;AACtB,IAAI,YAAY,OAAO;AACvB,IAAI,mBAAmB,OAAO;AAC9B,IAAI,oBAAoB,OAAO;AAC/B,IAAI,eAAe,OAAO;AAC1B,IAAI,eAAe,OAAO,UAAU;AACpC,IAAI,YAAY,QAAQ,QAAQ;CAC9B,KAAK,IAAI,QAAQ,KACf,UAAU,QAAQ,MAAM;EAAE,KAAK,IAAI;EAAO,YAAY;CAAK,CAAC;AAChE;AACA,IAAI,eAAe,IAAI,MAAM,QAAQ,SAAS;CAC5C,IAAI,QAAQ,OAAO,SAAS,YAAY,OAAO,SAAS,YAAY;EAClE,KAAK,IAAI,OAAO,kBAAkB,IAAI,GACpC,IAAI,CAAC,aAAa,KAAK,IAAI,GAAG,KAAK,QAAQ,QAC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AO,UAAU;GACf;GACA;GACA;EACF,IAAI,CAAC;CACP,GAAG;EACD;EACA;EACA;EACA;CACF,CAAC;AACH"}
@@ -1,143 +1,129 @@
1
+
1
2
  var __defProp = Object.defineProperty;
2
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
4
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
5
6
  var __export = (target, all) => {
6
- for (var name in all) __defProp(target, name, {
7
- get: all[name],
8
- enumerable: true
9
- });
7
+ for (var name in all) __defProp(target, name, {
8
+ get: all[name],
9
+ enumerable: true
10
+ });
10
11
  };
11
12
  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;
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
15
+ get: () => from[key],
16
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
17
+ });
18
+ }
19
+ return to;
19
20
  };
20
- var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
21
- value: true
22
- }), mod);
21
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
23
22
  var useTypeahead_exports = {};
24
- __export(useTypeahead_exports, {
25
- useTypeahead: () => useTypeahead
26
- });
23
+ __export(useTypeahead_exports, { useTypeahead: () => useTypeahead });
27
24
  module.exports = __toCommonJS(useTypeahead_exports);
28
25
  var import_react = require("react");
29
26
  var import_use_event = require("@tamagui/use-event");
30
27
  var import_utils = require("./utils.cjs");
31
28
  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
- }
29
+ const { open, dataRef } = context;
30
+ const { listRef, activeIndex, onMatch: unstable_onMatch, onTypingChange: unstable_onTypingChange, enabled = true, findMatch = null, resetMs = 750, ignoreKeys = [], selectedIndex = null } = props;
31
+ const timeoutIdRef = (0, import_react.useRef)(-1);
32
+ const stringRef = (0, import_react.useRef)("");
33
+ const prevIndexRef = (0, import_react.useRef)(selectedIndex ?? activeIndex ?? -1);
34
+ const matchIndexRef = (0, import_react.useRef)(null);
35
+ const onMatch = (0, import_use_event.useEvent)(unstable_onMatch || (() => {}));
36
+ const onTypingChange = (0, import_use_event.useEvent)(unstable_onTypingChange || (() => {}));
37
+ const findMatchRef = (0, import_react.useRef)(findMatch);
38
+ findMatchRef.current = findMatch;
39
+ const ignoreKeysRef = (0, import_react.useRef)(ignoreKeys);
40
+ ignoreKeysRef.current = ignoreKeys;
41
+ (0, import_react.useLayoutEffect)(() => {
42
+ if (open) {
43
+ (0, import_utils.clearTimeoutIfSet)(timeoutIdRef);
44
+ matchIndexRef.current = null;
45
+ stringRef.current = "";
46
+ }
47
+ }, [open]);
48
+ (0, import_react.useLayoutEffect)(() => {
49
+ if (open && stringRef.current === "") {
50
+ prevIndexRef.current = selectedIndex ?? activeIndex ?? -1;
51
+ }
52
+ }, [
53
+ open,
54
+ selectedIndex,
55
+ activeIndex
56
+ ]);
57
+ const setTypingChange = (value) => {
58
+ if (value) {
59
+ if (!dataRef.current.typing) {
60
+ dataRef.current.typing = value;
61
+ onTypingChange(value);
62
+ }
63
+ } else {
64
+ if (dataRef.current.typing) {
65
+ dataRef.current.typing = value;
66
+ onTypingChange(value);
67
+ }
68
+ }
69
+ };
70
+ const onKeyDown = (event) => {
71
+ function getMatchingIndex(list, orderedList, string) {
72
+ const str = findMatchRef.current ? findMatchRef.current(orderedList, string) : orderedList.find((text) => text?.toLocaleLowerCase().indexOf(string.toLocaleLowerCase()) === 0);
73
+ return str ? list.indexOf(str) : -1;
74
+ }
75
+ const listContent = listRef.current;
76
+ if (stringRef.current.length > 0 && stringRef.current[0] !== " ") {
77
+ if (getMatchingIndex(listContent, listContent, stringRef.current) === -1) {
78
+ setTypingChange(false);
79
+ } else if (event.key === " ") {
80
+ (0, import_utils.stopEvent)(event);
81
+ }
82
+ }
83
+ if (listContent == null || ignoreKeysRef.current.includes(event.key) || event.key.length !== 1 || event.ctrlKey || event.metaKey || event.altKey) {
84
+ return;
85
+ }
86
+ if (open && event.key !== " ") {
87
+ (0, import_utils.stopEvent)(event);
88
+ setTypingChange(true);
89
+ }
90
+ const allowRapidSuccessionOfFirstLetter = listContent.every((text) => text ? text[0]?.toLocaleLowerCase() !== text[1]?.toLocaleLowerCase() : true);
91
+ if (allowRapidSuccessionOfFirstLetter && stringRef.current === event.key) {
92
+ stringRef.current = "";
93
+ prevIndexRef.current = matchIndexRef.current;
94
+ }
95
+ stringRef.current += event.key;
96
+ (0, import_utils.clearTimeoutIfSet)(timeoutIdRef);
97
+ timeoutIdRef.current = window.setTimeout(() => {
98
+ stringRef.current = "";
99
+ prevIndexRef.current = matchIndexRef.current;
100
+ setTypingChange(false);
101
+ }, resetMs);
102
+ const prevIndex = prevIndexRef.current;
103
+ const index = getMatchingIndex(listContent, [...listContent.slice((prevIndex || 0) + 1), ...listContent.slice(0, (prevIndex || 0) + 1)], stringRef.current);
104
+ if (index !== -1) {
105
+ onMatch(index);
106
+ matchIndexRef.current = index;
107
+ } else if (event.key !== " ") {
108
+ stringRef.current = "";
109
+ setTypingChange(false);
110
+ }
111
+ };
112
+ const reference = (0, import_react.useMemo)(() => ({ onKeyDown }), [open, enabled]);
113
+ const floating = (0, import_react.useMemo)(() => ({
114
+ onKeyDown,
115
+ onKeyUp(event) {
116
+ if (event.key === " ") {
117
+ setTypingChange(false);
118
+ }
119
+ }
120
+ }), [open, enabled]);
121
+ return (0, import_react.useMemo)(() => enabled ? {
122
+ reference,
123
+ floating
124
+ } : {}, [
125
+ enabled,
126
+ reference,
127
+ floating
128
+ ]);
129
+ }