@yselimcan/ui 0.0.4 → 0.0.5

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 (184) hide show
  1. package/dist/index101.js +7 -133
  2. package/dist/index102.js +86 -26
  3. package/dist/index103.js +12 -8
  4. package/dist/index104.js +63 -5
  5. package/dist/index105.js +38 -13
  6. package/dist/index106.js +14 -23
  7. package/dist/index107.js +32 -7
  8. package/dist/index108.js +19 -88
  9. package/dist/index109.js +4 -11
  10. package/dist/index110.js +4 -63
  11. package/dist/index111.js +4 -37
  12. package/dist/index112.js +12 -14
  13. package/dist/index113.js +18 -32
  14. package/dist/index114.js +13 -19
  15. package/dist/index115.js +295 -4
  16. package/dist/index116.js +5 -4
  17. package/dist/index117.js +39 -5
  18. package/dist/index118.js +124 -10
  19. package/dist/index119.js +21 -19
  20. package/dist/index120.js +77 -13
  21. package/dist/index121.js +59 -291
  22. package/dist/index122.js +45 -4
  23. package/dist/index123.js +14 -39
  24. package/dist/index124.js +4 -124
  25. package/dist/index125.js +29 -20
  26. package/dist/index126.js +5 -77
  27. package/dist/index127.js +25 -62
  28. package/dist/index128.js +16 -44
  29. package/dist/index129.js +22 -14
  30. package/dist/index130.js +58 -5
  31. package/dist/index131.js +16 -28
  32. package/dist/index132.js +25 -15
  33. package/dist/index133.js +40 -21
  34. package/dist/index134.js +43 -59
  35. package/dist/index135.js +19 -15
  36. package/dist/index136.js +47 -26
  37. package/dist/index137.js +49 -38
  38. package/dist/index138.js +18 -43
  39. package/dist/index139.js +11 -21
  40. package/dist/index140.js +22 -48
  41. package/dist/index141.js +34 -50
  42. package/dist/index142.js +229 -16
  43. package/dist/index143.js +283 -11
  44. package/dist/index144.js +52 -21
  45. package/dist/index145.js +15 -35
  46. package/dist/index146.js +74 -225
  47. package/dist/index147.js +3 -283
  48. package/dist/index148.js +30 -53
  49. package/dist/index149.js +24 -16
  50. package/dist/index150.js +15 -79
  51. package/dist/index151.js +69 -3
  52. package/dist/index152.js +4 -31
  53. package/dist/index153.js +103 -22
  54. package/dist/index154.js +79 -15
  55. package/dist/index155.js +259 -65
  56. package/dist/index156.js +12 -4
  57. package/dist/index157.js +11 -105
  58. package/dist/index158.js +37 -76
  59. package/dist/index159.js +4 -263
  60. package/dist/index160.js +66 -11
  61. package/dist/index161.js +9 -10
  62. package/dist/index162.js +8 -40
  63. package/dist/index163.js +5 -4
  64. package/dist/index164.js +129 -62
  65. package/dist/index165.js +54 -10
  66. package/dist/index166.js +11 -8
  67. package/dist/index167.js +118 -6
  68. package/dist/index168.js +11 -53
  69. package/dist/index169.js +8 -11
  70. package/dist/index17.js +4 -4
  71. package/dist/index170.js +12 -117
  72. package/dist/index171.js +22 -11
  73. package/dist/index173.js +2 -2
  74. package/dist/index175.js +2 -2
  75. package/dist/index178.js +6 -6
  76. package/dist/index18.js +5 -5
  77. package/dist/index181.js +2 -2
  78. package/dist/index184.js +1 -1
  79. package/dist/index187.js +5 -5
  80. package/dist/index189.js +3 -3
  81. package/dist/index19.js +10 -10
  82. package/dist/index190.js +1 -1
  83. package/dist/index191.js +1 -1
  84. package/dist/index192.js +2 -2
  85. package/dist/index193.js +1 -1
  86. package/dist/index194.js +1 -1
  87. package/dist/index195.js +3 -3
  88. package/dist/index196.js +6 -6
  89. package/dist/index197.js +3 -3
  90. package/dist/index198.js +6 -6
  91. package/dist/index199.js +1 -1
  92. package/dist/index20.js +3 -3
  93. package/dist/index200.js +5 -47
  94. package/dist/index201.js +41 -193
  95. package/dist/index202.js +182 -30
  96. package/dist/index203.js +48 -20
  97. package/dist/index204.js +20 -6
  98. package/dist/index205.js +2 -2
  99. package/dist/index207.js +6 -9
  100. package/dist/index208.js +4 -17
  101. package/dist/index209.js +9 -6
  102. package/dist/index21.js +4 -4
  103. package/dist/index210.js +17 -4
  104. package/dist/index217.js +3 -3
  105. package/dist/index218.js +1 -1
  106. package/dist/index22.js +5 -5
  107. package/dist/index220.js +2 -2
  108. package/dist/index221.js +1 -1
  109. package/dist/index229.js +1 -1
  110. package/dist/index23.js +3 -3
  111. package/dist/index230.js +4 -597
  112. package/dist/index231.js +4 -11
  113. package/dist/index232.js +593 -29
  114. package/dist/index233.js +12 -4
  115. package/dist/index234.js +15 -5
  116. package/dist/index235.js +30 -12
  117. package/dist/index239.js +2 -2
  118. package/dist/index24.js +9 -9
  119. package/dist/index242.js +3 -3
  120. package/dist/index243.js +1 -1
  121. package/dist/index247.js +14 -321
  122. package/dist/index248.js +322 -3
  123. package/dist/index249.js +3 -3
  124. package/dist/index250.js +3 -15
  125. package/dist/index251.js +1 -1
  126. package/dist/index26.js +1 -1
  127. package/dist/index27.js +1 -1
  128. package/dist/index28.js +2 -2
  129. package/dist/index32.js +1 -1
  130. package/dist/index33.js +11 -11
  131. package/dist/index34.js +2 -2
  132. package/dist/index35.js +10 -10
  133. package/dist/index36.js +8 -8
  134. package/dist/index37.js +4 -4
  135. package/dist/index38.js +6 -6
  136. package/dist/index39.js +4 -4
  137. package/dist/index40.js +1 -1
  138. package/dist/index41.js +3 -3
  139. package/dist/index43.js +1 -1
  140. package/dist/index44.js +1 -1
  141. package/dist/index45.js +3 -3
  142. package/dist/index46.js +6 -6
  143. package/dist/index47.js +7 -7
  144. package/dist/index48.js +16 -16
  145. package/dist/index49.js +2 -2
  146. package/dist/index50.js +10 -10
  147. package/dist/index52.js +14 -14
  148. package/dist/index53.js +1 -1
  149. package/dist/index54.js +17 -17
  150. package/dist/index55.js +9 -9
  151. package/dist/index56.js +10 -10
  152. package/dist/index57.js +1 -1
  153. package/dist/index58.js +3 -3
  154. package/dist/index59.js +3 -3
  155. package/dist/index60.js +7 -7
  156. package/dist/index61.js +3 -3
  157. package/dist/index62.js +3 -3
  158. package/dist/index63.js +6 -6
  159. package/dist/index64.js +3 -3
  160. package/dist/index66.js +7 -7
  161. package/dist/index67.js +1 -1
  162. package/dist/index69.js +30 -30
  163. package/dist/index70.js +5 -5
  164. package/dist/index71.js +18 -18
  165. package/dist/index72.js +24 -24
  166. package/dist/index73.js +8 -8
  167. package/dist/index74.js +2 -2
  168. package/dist/index75.js +14 -14
  169. package/dist/index76.js +3 -3
  170. package/dist/index77.js +5 -5
  171. package/dist/index78.js +4 -4
  172. package/dist/index79.js +1 -1
  173. package/dist/index80.js +1 -1
  174. package/dist/index81.js +17 -17
  175. package/dist/index82.js +5 -5
  176. package/dist/index83.js +5 -5
  177. package/dist/index86.js +11 -54
  178. package/dist/index87.js +54 -11
  179. package/dist/index88.js +87 -81
  180. package/dist/index89.js +81 -87
  181. package/dist/index95.js +1 -1
  182. package/dist/index96.js +1 -1
  183. package/dist/styles.css +1 -1
  184. package/package.json +1 -1
package/dist/index143.js CHANGED
@@ -1,14 +1,286 @@
1
- import * as c from "react";
2
- import { useIsoLayoutEffect as o } from "./index104.js";
3
- import { useStableCallback as f } from "./index102.js";
4
- function u(r, n) {
5
- const t = c.useRef(r), e = f(n);
6
- o(() => {
7
- t.current !== r && e(t.current);
8
- }, [r, e]), o(() => {
9
- t.current = r;
10
- }, [r]);
1
+ import * as m from "react";
2
+ import { isHTMLElement as be } from "./index164.js";
3
+ import { useValueAsRef as A } from "./index128.js";
4
+ import { useStableCallback as ae } from "./index127.js";
5
+ import { useIsoLayoutEffect as L } from "./index126.js";
6
+ import { useFloatingParentNodeId as ze, useFloatingTree as Ge } from "./index181.js";
7
+ import { createChangeEventDetails as X } from "./index107.js";
8
+ import { enqueueFocus as We } from "./index238.js";
9
+ import { ARROW_DOWN as ee, ARROW_LEFT as W, ARROW_RIGHT as _, ARROW_UP as Te } from "./index245.js";
10
+ import { isIndexOutOfListBounds as Me, getMinListIndex as fe, getMaxListIndex as Pe, createGridCellMap as _e, isListIndexDisabled as de, getGridNavigatedIndex as qe, getGridCellIndexOfCorner as He, getGridCellIndices as $e, findNonDisabledListIndex as Y } from "./index246.js";
11
+ import { getFloatingFocusElement as Be, isTypeableCombobox as Ue, activeElement as ve, getDocument as je, contains as Ce, getTarget as Je } from "./index151.js";
12
+ import { stopEvent as T, isVirtualClick as Qe, isVirtualPointerEvent as Xe } from "./index221.js";
13
+ import { listNavigation as me, focusOut as Ye } from "./index108.js";
14
+ const Ze = "Escape";
15
+ function re(o, p, c) {
16
+ switch (o) {
17
+ case "vertical":
18
+ return p;
19
+ case "horizontal":
20
+ return c;
21
+ default:
22
+ return p || c;
23
+ }
24
+ }
25
+ function Z(o, p) {
26
+ return re(p, o === Te || o === ee, o === W || o === _);
27
+ }
28
+ function pe(o, p, c) {
29
+ return re(p, o === ee, c ? o === W : o === _) || o === "Enter" || o === " " || o === "";
30
+ }
31
+ function er(o, p, c) {
32
+ return re(p, c ? o === W : o === _, o === ee);
33
+ }
34
+ function rr(o, p, c, s) {
35
+ const g = c ? o === _ : o === W, O = o === Te;
36
+ return p === "both" || p === "horizontal" && s && s > 1 ? o === Ze : re(p, g, O);
37
+ }
38
+ function pr(o, p) {
39
+ const c = "rootStore" in o ? o.rootStore : o, s = c.useState("open"), g = c.useState("floatingElement"), O = c.useState("domReferenceElement"), ge = c.context.dataRef, {
40
+ listRef: n,
41
+ activeIndex: y,
42
+ onNavigate: Se = () => {
43
+ },
44
+ enabled: E = !0,
45
+ selectedIndex: N = null,
46
+ allowEscape: te = !1,
47
+ loopFocus: q = !1,
48
+ nested: b = !1,
49
+ rtl: x = !1,
50
+ virtual: f = !1,
51
+ focusItemOnOpen: M = "auto",
52
+ focusItemOnHover: ne = !0,
53
+ openOnArrowKeyDown: oe = !0,
54
+ disabledIndices: R = void 0,
55
+ orientation: d = "vertical",
56
+ parentOrientation: Ie,
57
+ cols: S = 1,
58
+ scrollItemIntoView: Fe = !0,
59
+ itemSizes: Ae,
60
+ dense: Le = !1,
61
+ id: Re,
62
+ resetOnPointerLeave: Ne = !0,
63
+ externalTree: ke
64
+ } = p;
65
+ process.env.NODE_ENV !== "production" && (te && (q || console.warn("`useListNavigation` looping must be enabled to allow escaping."), f || console.warn("`useListNavigation` must be virtual to allow escaping.")), d === "vertical" && S > 1 && console.warn("In grid list navigation mode (`cols` > 1), the `orientation` should", 'be either "horizontal" or "both".'));
66
+ const De = Be(g), k = A(De), H = ze(), P = Ge(ke);
67
+ L(() => {
68
+ ge.current.orientation = d;
69
+ }, [ge, d]);
70
+ const ie = Ue(O), v = m.useRef(M), t = m.useRef(N ?? -1), C = m.useRef(null), F = m.useRef(!0), l = ae((e) => {
71
+ Se(t.current === -1 ? null : t.current, e);
72
+ }), he = m.useRef(l), D = m.useRef(!!g), Oe = m.useRef(s), h = m.useRef(!1), $ = m.useRef(!1), ce = A(R), B = A(s), Ke = A(Fe), K = A(N), xe = A(Ne), ue = ae(() => {
73
+ function e(a) {
74
+ f ? P?.events.emit("virtualfocus", a) : We(a, {
75
+ sync: h.current,
76
+ preventScroll: !0
77
+ });
78
+ }
79
+ const i = n.current[t.current], r = $.current;
80
+ i && e(i), (h.current ? (a) => a() : requestAnimationFrame)(() => {
81
+ const a = n.current[t.current] || i;
82
+ if (!a)
83
+ return;
84
+ i || e(a);
85
+ const I = Ke.current;
86
+ I && // eslint-disable-next-line @typescript-eslint/no-use-before-define
87
+ se && (r || !F.current) && a.scrollIntoView?.(typeof I == "boolean" ? {
88
+ block: "nearest",
89
+ inline: "nearest"
90
+ } : I);
91
+ });
92
+ });
93
+ L(() => {
94
+ E && (s && g ? (t.current = N ?? -1, v.current && N != null && ($.current = !0, l())) : D.current && (t.current = -1, he.current()));
95
+ }, [E, s, g, N, l]), L(() => {
96
+ if (E) {
97
+ if (!s) {
98
+ h.current = !1;
99
+ return;
100
+ }
101
+ if (g)
102
+ if (y == null) {
103
+ if (h.current = !1, K.current != null)
104
+ return;
105
+ if (D.current && (t.current = -1, ue()), (!Oe.current || !D.current) && v.current && (C.current != null || v.current === !0 && C.current == null)) {
106
+ let e = 0;
107
+ const i = () => {
108
+ n.current[0] == null ? (e < 2 && (e ? requestAnimationFrame : queueMicrotask)(i), e += 1) : (t.current = C.current == null || pe(C.current, d, x) || b ? fe(n) : Pe(n), C.current = null, l());
109
+ };
110
+ i();
111
+ }
112
+ } else Me(n, y) || (t.current = y, ue(), $.current = !1);
113
+ }
114
+ }, [E, s, g, y, K, b, n, d, x, l, ue, ce]), L(() => {
115
+ if (!E || g || !P || f || !D.current)
116
+ return;
117
+ const e = P.nodesRef.current, i = e.find((a) => a.id === H)?.context?.elements.floating, r = ve(je(g)), u = e.some((a) => a.context && Ce(a.context.elements.floating, r));
118
+ i && !u && F.current && i.focus({
119
+ preventScroll: !0
120
+ });
121
+ }, [E, g, P, H, f]), L(() => {
122
+ he.current = l, Oe.current = s, D.current = !!g;
123
+ }), L(() => {
124
+ s || (C.current = null, v.current = M);
125
+ }, [s, M]);
126
+ const Ee = y != null, se = m.useMemo(() => {
127
+ function e(r) {
128
+ if (!B.current)
129
+ return;
130
+ const u = n.current.indexOf(r.currentTarget);
131
+ u !== -1 && t.current !== u && (t.current = u, l(r));
132
+ }
133
+ return {
134
+ onFocus(r) {
135
+ h.current = !0, e(r);
136
+ },
137
+ onClick: ({
138
+ currentTarget: r
139
+ }) => r.focus({
140
+ preventScroll: !0
141
+ }),
142
+ // Safari
143
+ onMouseMove(r) {
144
+ h.current = !0, $.current = !1, ne && e(r);
145
+ },
146
+ onPointerLeave(r) {
147
+ if (!B.current || !F.current || r.pointerType === "touch")
148
+ return;
149
+ h.current = !0;
150
+ const u = r.relatedTarget;
151
+ !ne || n.current.includes(u) || xe.current && (t.current = -1, l(r), f || k.current?.focus({
152
+ preventScroll: !0
153
+ }));
154
+ }
155
+ };
156
+ }, [B, k, ne, n, l, xe, f]), U = m.useCallback(() => Ie ?? P?.nodesRef.current.find((e) => e.id === H)?.context?.dataRef?.current.orientation, [H, P, Ie]), V = ae((e) => {
157
+ if (F.current = !1, h.current = !0, e.which === 229 || !B.current && e.currentTarget === k.current)
158
+ return;
159
+ if (b && rr(e.key, d, x, S)) {
160
+ Z(e.key, U()) || T(e), c.setOpen(!1, X(me, e.nativeEvent)), be(O) && (f ? P?.events.emit("virtualfocus", O) : O.focus());
161
+ return;
162
+ }
163
+ const i = t.current, r = fe(n, R), u = Pe(n, R);
164
+ if (ie || (e.key === "Home" && (T(e), t.current = r, l(e)), e.key === "End" && (T(e), t.current = u, l(e))), S > 1) {
165
+ const a = Ae || Array.from({
166
+ length: n.current.length
167
+ }, () => ({
168
+ width: 1,
169
+ height: 1
170
+ })), I = _e(a, S, Le), z = I.findIndex((w) => w != null && !de(n, w, R)), le = I.reduce((w, G, Ve) => G != null && !de(n, G, R) ? Ve : w, -1), Q = I[qe({
171
+ current: I.map((w) => w != null ? n.current[w] : null)
172
+ }, {
173
+ event: e,
174
+ orientation: d,
175
+ loopFocus: q,
176
+ rtl: x,
177
+ cols: S,
178
+ // treat undefined (empty grid spaces) as disabled indices so we
179
+ // don't end up in them
180
+ disabledIndices: $e([...(typeof R != "function" ? R : null) || n.current.map((w, G) => de(n, G, R) ? G : void 0), void 0], I),
181
+ minIndex: z,
182
+ maxIndex: le,
183
+ prevIndex: He(
184
+ t.current > u ? r : t.current,
185
+ a,
186
+ I,
187
+ S,
188
+ // use a corner matching the edge closest to the direction
189
+ // we're moving in so we don't end up in the same item. Prefer
190
+ // top/left over bottom/right.
191
+ // eslint-disable-next-line no-nested-ternary
192
+ e.key === ee ? "bl" : e.key === (x ? W : _) ? "tr" : "tl"
193
+ ),
194
+ stopEvent: !0
195
+ })];
196
+ if (Q != null && (t.current = Q, l(e)), d === "both")
197
+ return;
198
+ }
199
+ if (Z(e.key, d)) {
200
+ if (T(e), s && !f && ve(e.currentTarget.ownerDocument) === e.currentTarget) {
201
+ t.current = pe(e.key, d, x) ? r : u, l(e);
202
+ return;
203
+ }
204
+ pe(e.key, d, x) ? q ? i >= u ? te && i !== n.current.length ? t.current = -1 : (h.current = !1, t.current = r) : t.current = Y(n, {
205
+ startingIndex: i,
206
+ disabledIndices: R
207
+ }) : t.current = Math.min(u, Y(n, {
208
+ startingIndex: i,
209
+ disabledIndices: R
210
+ })) : q ? i <= r ? te && i !== -1 ? t.current = n.current.length : (h.current = !1, t.current = u) : t.current = Y(n, {
211
+ startingIndex: i,
212
+ decrement: !0,
213
+ disabledIndices: R
214
+ }) : t.current = Math.max(r, Y(n, {
215
+ startingIndex: i,
216
+ decrement: !0,
217
+ disabledIndices: R
218
+ })), Me(n, t.current) && (t.current = -1), l(e);
219
+ }
220
+ }), j = m.useMemo(() => f && s && Ee && {
221
+ "aria-activedescendant": `${Re}-${y}`
222
+ }, [f, s, Ee, Re, y]), we = m.useMemo(() => ({
223
+ "aria-orientation": d === "both" ? void 0 : d,
224
+ ...ie ? {} : j,
225
+ onKeyDown(e) {
226
+ if (e.key === "Tab" && e.shiftKey && s && !f) {
227
+ const i = Je(e.nativeEvent);
228
+ if (i && !Ce(k.current, i))
229
+ return;
230
+ T(e), c.setOpen(!1, X(Ye, e.nativeEvent)), be(O) && O.focus();
231
+ return;
232
+ }
233
+ V(e);
234
+ },
235
+ onPointerMove() {
236
+ F.current = !0;
237
+ }
238
+ }), [j, V, k, d, ie, c, s, f, O]), J = m.useMemo(() => {
239
+ function e(r) {
240
+ M === "auto" && Qe(r.nativeEvent) && (v.current = !f);
241
+ }
242
+ function i(r) {
243
+ v.current = M, M === "auto" && Xe(r.nativeEvent) && (v.current = !0);
244
+ }
245
+ return {
246
+ onKeyDown(r) {
247
+ const u = c.select("open");
248
+ F.current = !1;
249
+ const a = r.key.startsWith("Arrow"), I = er(r.key, U(), x), z = Z(r.key, d), le = (b ? I : z) || r.key === "Enter" || r.key.trim() === "";
250
+ if (f && u)
251
+ return V(r);
252
+ if (!(!u && !oe && a)) {
253
+ if (le) {
254
+ const Q = Z(r.key, U());
255
+ C.current = b && Q ? null : r.key;
256
+ }
257
+ if (b) {
258
+ I && (T(r), u ? (t.current = fe(n, ce.current), l(r)) : c.setOpen(!0, X(me, r.nativeEvent, r.currentTarget)));
259
+ return;
260
+ }
261
+ z && (K.current != null && (t.current = K.current), T(r), !u && oe ? c.setOpen(!0, X(me, r.nativeEvent, r.currentTarget)) : V(r), u && l(r));
262
+ }
263
+ },
264
+ onFocus(r) {
265
+ c.select("open") && !f && (t.current = -1, l(r));
266
+ },
267
+ onPointerDown: i,
268
+ onPointerEnter: i,
269
+ onMouseDown: e,
270
+ onClick: e
271
+ };
272
+ }, [V, ce, M, n, b, l, c, oe, d, U, x, K, f]), ye = m.useMemo(() => ({
273
+ ...j,
274
+ ...J
275
+ }), [j, J]);
276
+ return m.useMemo(() => E ? {
277
+ reference: ye,
278
+ floating: we,
279
+ item: se,
280
+ trigger: J
281
+ } : {}, [E, ye, we, J, se]);
11
282
  }
12
283
  export {
13
- u as useValueChanged
284
+ Ze as ESCAPE,
285
+ pr as useListNavigation
14
286
  };
package/dist/index144.js CHANGED
@@ -1,25 +1,56 @@
1
- "use client";
2
- import * as e from "react";
3
- import { useStableCallback as a } from "./index102.js";
4
- import { useEnhancedClickHandler as u } from "./index208.js";
5
- function f(s) {
6
- const [n, t] = e.useState(null), c = a((p, i) => {
7
- s || t(i);
8
- }), o = e.useCallback(() => {
9
- t(null);
10
- }, []), {
11
- onClick: r,
12
- onPointerDown: l
13
- } = u(c);
14
- return e.useMemo(() => ({
15
- openMethod: n,
16
- reset: o,
17
- triggerProps: {
18
- onClick: r,
19
- onPointerDown: l
1
+ import * as o from "react";
2
+ import { useStableCallback as S } from "./index127.js";
3
+ import { useIsoLayoutEffect as T } from "./index126.js";
4
+ import { useTimeout as D } from "./index148.js";
5
+ import { EMPTY_ARRAY as U } from "./index100.js";
6
+ import { stopEvent as O } from "./index221.js";
7
+ function H(l, b) {
8
+ const g = "rootStore" in l ? l.rootStore : l, c = g.useState("open"), u = g.context.dataRef, {
9
+ listRef: E,
10
+ activeIndex: p,
11
+ onMatch: A,
12
+ onTypingChange: R,
13
+ enabled: h = !0,
14
+ findMatch: L = null,
15
+ resetMs: F = 750,
16
+ ignoreKeys: P = U,
17
+ selectedIndex: y = null
18
+ } = b, m = D(), r = o.useRef(""), i = o.useRef(y ?? p ?? -1), f = o.useRef(null);
19
+ T(() => {
20
+ c && (m.clear(), f.current = null, r.current = "");
21
+ }, [c, m]), T(() => {
22
+ c && r.current === "" && (i.current = y ?? p ?? -1);
23
+ }, [c, y, p]);
24
+ const n = S((e) => {
25
+ e ? u.current.typing || (u.current.typing = e, R?.(e)) : u.current.typing && (u.current.typing = e, R?.(e));
26
+ }), a = S((e) => {
27
+ function C(s, x, I) {
28
+ const K = L ? L(x, I) : x.find((Y) => Y?.toLocaleLowerCase().indexOf(I.toLocaleLowerCase()) === 0);
29
+ return K ? s.indexOf(K) : -1;
20
30
  }
21
- }), [n, o, r, l]);
31
+ const t = E.current;
32
+ if (r.current.length > 0 && r.current[0] !== " " && (C(t, t, r.current) === -1 ? n(!1) : e.key === " " && O(e)), t == null || P.includes(e.key) || // Character key.
33
+ e.key.length !== 1 || // Modifier key.
34
+ e.ctrlKey || e.metaKey || e.altKey)
35
+ return;
36
+ c && e.key !== " " && (O(e), n(!0)), t.every((s) => s ? s[0]?.toLocaleLowerCase() !== s[1]?.toLocaleLowerCase() : !0) && r.current === e.key && (r.current = "", i.current = f.current), r.current += e.key, m.start(F, () => {
37
+ r.current = "", i.current = f.current, n(!1);
38
+ });
39
+ const w = i.current, d = C(t, [...t.slice((w || 0) + 1), ...t.slice(0, (w || 0) + 1)], r.current);
40
+ d !== -1 ? (A?.(d), f.current = d) : e.key !== " " && (r.current = "", n(!1));
41
+ }), k = o.useMemo(() => ({
42
+ onKeyDown: a
43
+ }), [a]), M = o.useMemo(() => ({
44
+ onKeyDown: a,
45
+ onKeyUp(e) {
46
+ e.key === " " && n(!1);
47
+ }
48
+ }), [a, n]);
49
+ return o.useMemo(() => h ? {
50
+ reference: k,
51
+ floating: M
52
+ } : {}, [h, k, M]);
22
53
  }
23
54
  export {
24
- f as useOpenInteractionType
55
+ H as useTypeahead
25
56
  };
package/dist/index145.js CHANGED
@@ -1,38 +1,18 @@
1
- import { isElement as s } from "./index101.js";
2
- import { useId as m } from "./index184.js";
3
- import { useRefWithInit as c } from "./index107.js";
4
- import { useIsoLayoutEffect as a } from "./index104.js";
5
- import { useFloatingParentNodeId as u } from "./index181.js";
6
- import { FloatingRootStore as g } from "./index242.js";
7
- import { PopupTriggerMap as p } from "./index202.js";
8
- function O(o) {
9
- const {
10
- open: r = !1,
11
- onOpenChange: i,
12
- elements: e = {}
13
- } = o, f = m(), l = u() != null;
14
- if (process.env.NODE_ENV !== "production") {
15
- const n = e.reference;
16
- n && !s(n) && console.error("Cannot pass a virtual element to the `elements.reference` option,", "as it must be a real DOM element. Use `context.setPositionReference()`", "instead.");
17
- }
18
- const t = c(() => new g({
19
- open: r,
20
- onOpenChange: i,
21
- referenceElement: e.reference ?? null,
22
- floatingElement: e.floating ?? null,
23
- triggerElements: e.triggers ?? new p(),
24
- floatingId: f,
25
- nested: l,
26
- noEmit: o.noEmit || !1
27
- })).current;
28
- return a(() => {
29
- const n = {
30
- open: r,
31
- floatingId: f
32
- };
33
- e.reference !== void 0 && (n.referenceElement = e.reference, n.domReferenceElement = s(e.reference) ? e.reference : null), e.floating !== void 0 && (n.floatingElement = e.floating), t.update(n);
34
- }, [r, f, e.reference, e.floating, t]), t.context.onOpenChange = i, t.context.nested = l, t.context.noEmit = o.noEmit || !1, t;
1
+ import * as c from "react";
2
+ import { s as i } from "./index249.js";
3
+ import { w as S } from "./index250.js";
4
+ import { isReactVersionAtLeast as a } from "./index200.js";
5
+ const u = a(19), m = u ? p : l;
6
+ function b(t, e, o, r, n) {
7
+ return m(t, e, o, r, n);
8
+ }
9
+ function p(t, e, o, r, n) {
10
+ const s = c.useCallback(() => e(t.getSnapshot(), o, r, n), [t, e, o, r, n]);
11
+ return i.useSyncExternalStore(t.subscribe, s, s);
12
+ }
13
+ function l(t, e, o, r, n) {
14
+ return S.useSyncExternalStoreWithSelector(t.subscribe, t.getSnapshot, t.getSnapshot, (s) => e(s, o, r, n));
35
15
  }
36
16
  export {
37
- O as useFloatingRootContext
17
+ b as useStore
38
18
  };