@algorisys/zen-ui-solid 13.8.0 → 13.8.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 (198) hide show
  1. package/dist/components/form/checkbox/checkbox.d.ts.map +1 -1
  2. package/dist/components/form/radio/radio-group.d.ts.map +1 -1
  3. package/dist/components/form/slider/slider.d.ts.map +1 -1
  4. package/dist/components/form/switch/switch.d.ts.map +1 -1
  5. package/dist/index208.js +13 -13
  6. package/dist/index209.js +2 -2
  7. package/dist/index210.js +5 -5
  8. package/dist/index211.js +12 -12
  9. package/dist/index212.js +13 -13
  10. package/dist/index213.js +10 -10
  11. package/dist/index214.js +10 -10
  12. package/dist/index215.js +9 -9
  13. package/dist/index216.js +9 -9
  14. package/dist/index218.js +14 -14
  15. package/dist/index219.js +14 -14
  16. package/dist/index220.js +13 -13
  17. package/dist/index221.js +1 -1
  18. package/dist/index222.js +5 -5
  19. package/dist/index223.js +9 -9
  20. package/dist/index224.js +24 -24
  21. package/dist/index225.js +5 -5
  22. package/dist/index226.js +3 -3
  23. package/dist/index249.js +10 -10
  24. package/dist/index250.js +3 -3
  25. package/dist/index252.js +2 -2
  26. package/dist/index257.js +1 -1
  27. package/dist/index258.js +1 -1
  28. package/dist/index271.js +5 -5
  29. package/dist/index271.js.map +1 -1
  30. package/dist/index272.js +5 -3
  31. package/dist/index272.js.map +1 -1
  32. package/dist/index273.js +3 -17
  33. package/dist/index273.js.map +1 -1
  34. package/dist/index274.js +17 -16
  35. package/dist/index274.js.map +1 -1
  36. package/dist/index275.js +16 -3
  37. package/dist/index275.js.map +1 -1
  38. package/dist/index276.js +3 -3
  39. package/dist/index276.js.map +1 -1
  40. package/dist/index277.js +3 -26
  41. package/dist/index277.js.map +1 -1
  42. package/dist/index278.js +26 -11
  43. package/dist/index278.js.map +1 -1
  44. package/dist/index279.js +10 -7
  45. package/dist/index279.js.map +1 -1
  46. package/dist/index280.js +8 -49
  47. package/dist/index280.js.map +1 -1
  48. package/dist/index281.js +49 -13
  49. package/dist/index281.js.map +1 -1
  50. package/dist/index282.js +12 -6
  51. package/dist/index282.js.map +1 -1
  52. package/dist/index283.js +7 -4
  53. package/dist/index283.js.map +1 -1
  54. package/dist/index284.js +4 -5
  55. package/dist/index284.js.map +1 -1
  56. package/dist/index286.js +6 -260
  57. package/dist/index286.js.map +1 -1
  58. package/dist/index287.js +105 -64
  59. package/dist/index287.js.map +1 -1
  60. package/dist/index288.js +67 -19
  61. package/dist/index288.js.map +1 -1
  62. package/dist/index289.js +72 -3
  63. package/dist/index289.js.map +1 -1
  64. package/dist/index290.js +22 -15
  65. package/dist/index290.js.map +1 -1
  66. package/dist/index291.js +58 -7
  67. package/dist/index291.js.map +1 -1
  68. package/dist/index292.js +3 -384
  69. package/dist/index292.js.map +1 -1
  70. package/dist/index293.js +16 -35
  71. package/dist/index293.js.map +1 -1
  72. package/dist/index294.js +384 -6
  73. package/dist/index294.js.map +1 -1
  74. package/dist/index295.js +92 -19
  75. package/dist/index295.js.map +1 -1
  76. package/dist/index296.js +34 -391
  77. package/dist/index296.js.map +1 -1
  78. package/dist/index297.js +6 -118
  79. package/dist/index297.js.map +1 -1
  80. package/dist/index298.js +17 -48
  81. package/dist/index298.js.map +1 -1
  82. package/dist/index299.js +62 -16
  83. package/dist/index299.js.map +1 -1
  84. package/dist/index300.js +48 -58
  85. package/dist/index300.js.map +1 -1
  86. package/dist/index301.js +31 -62
  87. package/dist/index301.js.map +1 -1
  88. package/dist/index302.js +16 -20
  89. package/dist/index302.js.map +1 -1
  90. package/dist/index303.js +58 -56
  91. package/dist/index303.js.map +1 -1
  92. package/dist/index304.js +20 -10
  93. package/dist/index304.js.map +1 -1
  94. package/dist/index305.js +10 -117
  95. package/dist/index305.js.map +1 -1
  96. package/dist/index306.js +920 -20
  97. package/dist/index306.js.map +1 -1
  98. package/dist/index307.js +37 -19
  99. package/dist/index307.js.map +1 -1
  100. package/dist/index308.js +256 -18
  101. package/dist/index308.js.map +1 -1
  102. package/dist/index309.js +114 -71
  103. package/dist/index309.js.map +1 -1
  104. package/dist/index310.js +556 -891
  105. package/dist/index310.js.map +1 -1
  106. package/dist/index311.js +121 -36
  107. package/dist/index311.js.map +1 -1
  108. package/dist/index312.js +17 -114
  109. package/dist/index312.js.map +1 -1
  110. package/dist/index313.js +363 -560
  111. package/dist/index313.js.map +1 -1
  112. package/dist/index314.js +85 -118
  113. package/dist/index314.js.map +1 -1
  114. package/dist/index315.js +16 -112
  115. package/dist/index315.js.map +1 -1
  116. package/dist/index316.js +115 -67
  117. package/dist/index316.js.map +1 -1
  118. package/dist/index317.js +21 -16
  119. package/dist/index317.js.map +1 -1
  120. package/dist/index318.js +19 -91
  121. package/dist/index318.js.map +1 -1
  122. package/dist/index319.js +20 -87
  123. package/dist/index319.js.map +1 -1
  124. package/dist/index320.js +71 -16
  125. package/dist/index320.js.map +1 -1
  126. package/dist/index321.js +118 -32
  127. package/dist/index321.js.map +1 -1
  128. package/dist/index323.js +1 -1
  129. package/dist/index324.js +93 -63
  130. package/dist/index324.js.map +1 -1
  131. package/dist/index325.js +5 -116
  132. package/dist/index325.js.map +1 -1
  133. package/dist/index326.js +38 -7
  134. package/dist/index326.js.map +1 -1
  135. package/dist/index327.js +44 -7
  136. package/dist/index327.js.map +1 -1
  137. package/dist/index328.js +2 -13
  138. package/dist/index328.js.map +1 -1
  139. package/dist/index329.js +65 -7
  140. package/dist/index329.js.map +1 -1
  141. package/dist/index330.js +115 -3
  142. package/dist/index330.js.map +1 -1
  143. package/dist/index331.js +608 -3
  144. package/dist/index331.js.map +1 -1
  145. package/dist/index332.js +295 -4
  146. package/dist/index332.js.map +1 -1
  147. package/dist/index333.js +88 -5
  148. package/dist/index333.js.map +1 -1
  149. package/dist/index334.js +11 -95
  150. package/dist/index334.js.map +1 -1
  151. package/dist/index335.js +20 -5
  152. package/dist/index335.js.map +1 -1
  153. package/dist/index336.js +62 -38
  154. package/dist/index336.js.map +1 -1
  155. package/dist/index337.js +33 -43
  156. package/dist/index337.js.map +1 -1
  157. package/dist/index338.js +7 -2
  158. package/dist/index338.js.map +1 -1
  159. package/dist/index339.js +6 -608
  160. package/dist/index339.js.map +1 -1
  161. package/dist/index340.js +11 -294
  162. package/dist/index340.js.map +1 -1
  163. package/dist/index341.js +6 -88
  164. package/dist/index341.js.map +1 -1
  165. package/dist/index342.js +3 -10
  166. package/dist/index342.js.map +1 -1
  167. package/dist/index343.js +3 -19
  168. package/dist/index343.js.map +1 -1
  169. package/dist/index344.js +4 -61
  170. package/dist/index344.js.map +1 -1
  171. package/dist/index345.js +5 -33
  172. package/dist/index345.js.map +1 -1
  173. package/dist/index346.js +3 -466
  174. package/dist/index346.js.map +1 -1
  175. package/dist/index347.js +9 -125
  176. package/dist/index347.js.map +1 -1
  177. package/dist/index348.js +33 -134
  178. package/dist/index348.js.map +1 -1
  179. package/dist/index349.js +21 -3
  180. package/dist/index349.js.map +1 -1
  181. package/dist/index350.js +5 -5
  182. package/dist/index351.js +2 -2
  183. package/dist/index357.js +464 -8
  184. package/dist/index357.js.map +1 -1
  185. package/dist/index358.js +126 -33
  186. package/dist/index358.js.map +1 -1
  187. package/dist/index359.js +133 -20
  188. package/dist/index359.js.map +1 -1
  189. package/dist/index53.js +21 -15
  190. package/dist/index53.js.map +1 -1
  191. package/dist/index54.js +15 -9
  192. package/dist/index54.js.map +1 -1
  193. package/dist/index55.js +20 -14
  194. package/dist/index55.js.map +1 -1
  195. package/dist/index62.js +42 -22
  196. package/dist/index62.js.map +1 -1
  197. package/dist/server/index.js +50 -12
  198. package/package.json +1 -1
package/dist/index310.js CHANGED
@@ -1,927 +1,592 @@
1
- import { createComponent as d, mergeProps as M, memo as re, Portal as Ee, isServer as Le } from "solid-js/web";
2
- import { Popper as fe } from "./index286.js";
3
- import { createSelectableList as Ge } from "./index312.js";
4
- import { createSelectableItem as me, createListState as Ue } from "./index313.js";
5
- import { useOptionalDomCollectionContext as Ve, createDomCollection as Ne, createDomCollectionItem as _e } from "./index314.js";
6
- import { useLocale as H } from "./index252.js";
7
- import { createFocusScope as ze } from "./index315.js";
8
- import { createHideOutside as $e } from "./index316.js";
9
- import { DismissableLayer as Be } from "./index287.js";
10
- import { createDisclosureState as he } from "./index288.js";
11
- import { ButtonRoot as Xe } from "./index303.js";
12
- import { createToggleState as Ye } from "./index317.js";
13
- import { createRegisterId as B } from "./index289.js";
14
- import { createControllableSignal as He } from "./index302.js";
15
- import { createTagName as We } from "./index304.js";
16
- import { Polymorphic as A } from "./index290.js";
17
- import { createUniqueId as V, splitProps as I, createEffect as y, onCleanup as T, on as ve, Show as X, createSignal as F, createMemo as j, useContext as G, createContext as U } from "solid-js";
18
- import { mergeDefaultProps as D, composeEventHandlers as w, callHandler as P, focusWithoutScrolling as Q, contains as J, createGenerateId as ie, scrollIntoViewport as qe, removeItemFromArray as je, isPointInPolygon as Je } from "./index292.js";
19
- import Qe from "./index318.js";
20
- import Ze from "./index293.js";
21
- import { mergeRefs as N } from "./index294.js";
22
- import { combineStyle as et } from "./index295.js";
23
- var tt = U();
24
- function Z() {
25
- return G(tt);
26
- }
27
- var nt = U();
28
- function Me() {
29
- return G(nt);
1
+ import { createCollection as U } from "./index314.js";
2
+ import { useLocale as N } from "./index252.js";
3
+ import { createControllableSignal as W } from "./index304.js";
4
+ import { focusWithoutScrolling as E, scrollIntoView as O, mergeDefaultProps as H, isAppleDevice as _, callHandler as q, getFocusableTreeWalker as $, isMac as j } from "./index294.js";
5
+ import { createMemo as A, createEffect as L, on as C, createComputed as G, createSignal as k, mergeProps as Z, onMount as J } from "solid-js";
6
+ import { access as o } from "./index300.js";
7
+ import { createEventListener as Q } from "./index315.js";
8
+ var b = class R extends Set {
9
+ anchorKey;
10
+ currentKey;
11
+ constructor(t, s, n) {
12
+ super(t), t instanceof R ? (this.anchorKey = s || t.anchorKey, this.currentKey = n || t.currentKey) : (this.anchorKey = s, this.currentKey = n);
13
+ }
14
+ };
15
+ function X(e) {
16
+ const [t, s] = W(e);
17
+ return [() => t() ?? new b(), s];
30
18
  }
31
- var be = U();
32
- function Ce() {
33
- return G(be);
19
+ function V(e) {
20
+ return _() ? e.altKey : e.ctrlKey;
34
21
  }
35
- function L() {
36
- const r = Ce();
37
- if (r === void 0)
38
- throw new Error("[kobalte]: `useMenuContext` must be used within a `Menu` component");
39
- return r;
22
+ function I(e) {
23
+ return j() ? e.metaKey : e.ctrlKey;
40
24
  }
41
- var we = U();
42
- function se() {
43
- const r = G(we);
44
- if (r === void 0)
45
- throw new Error("[kobalte]: `useMenuItemContext` must be used within a `Menu.Item` component");
46
- return r;
25
+ function B(e) {
26
+ return new b(e);
47
27
  }
48
- var Pe = U();
49
- function E() {
50
- const r = G(Pe);
51
- if (r === void 0)
52
- throw new Error("[kobalte]: `useMenuRootContext` must be used within a `MenuRoot` component");
53
- return r;
28
+ function Y(e, t) {
29
+ if (e.size !== t.size)
30
+ return !1;
31
+ for (const s of e)
32
+ if (!t.has(s))
33
+ return !1;
34
+ return !0;
54
35
  }
55
- function ae(r) {
56
- let o;
57
- const s = E(), e = L(), t = D({
58
- id: s.generateId(`item-${V()}`)
59
- }, r), [n, u] = I(t, ["ref", "textValue", "disabled", "closeOnSelect", "checked", "indeterminate", "onSelect", "onPointerMove", "onPointerLeave", "onPointerDown", "onPointerUp", "onClick", "onKeyDown", "onMouseDown", "onFocus"]), [p, c] = F(), [b, g] = F(), [h, x] = F(), S = () => e.listState().selectionManager(), v = () => u.id, K = () => S().focusedKey() === v(), k = () => {
60
- n.onSelect?.(), n.closeOnSelect && setTimeout(
61
- () => {
62
- e.close(!0);
63
- },
64
- // Fix #446
65
- // Requires a delay for NavigationMenu to work on mobile.
66
- 1
67
- );
68
- };
69
- _e({
70
- getItem: () => ({
71
- ref: () => o,
72
- type: "item",
73
- key: v(),
74
- textValue: n.textValue ?? h()?.textContent ?? o?.textContent ?? "",
75
- disabled: n.disabled ?? !1
76
- })
77
- });
78
- const a = me({
79
- key: v,
80
- selectionManager: S,
81
- shouldSelectOnPressUp: !0,
82
- allowsDifferentPressOrigin: !0,
83
- disabled: () => n.disabled
84
- }, () => o), C = (m) => {
85
- P(m, n.onPointerMove), m.pointerType === "mouse" && (n.disabled ? e.onItemLeave(m) : (e.onItemEnter(m), m.defaultPrevented || (Q(m.currentTarget), e.listState().selectionManager().setFocused(!0), e.listState().selectionManager().setFocusedKey(v()))));
86
- }, i = (m) => {
87
- P(m, n.onPointerLeave), m.pointerType === "mouse" && e.onItemLeave(m);
88
- }, f = (m) => {
89
- P(m, n.onPointerUp), !n.disabled && m.button === 0 && k();
90
- }, O = (m) => {
91
- if (P(m, n.onKeyDown), !m.repeat && !n.disabled)
92
- switch (m.key) {
93
- case "Enter":
94
- case " ":
95
- k();
96
- break;
97
- }
98
- }, _ = j(() => {
99
- if (n.indeterminate)
100
- return "mixed";
101
- if (n.checked != null)
102
- return n.checked;
103
- }), W = j(() => ({
104
- "data-indeterminate": n.indeterminate ? "" : void 0,
105
- "data-checked": n.checked && !n.indeterminate ? "" : void 0,
106
- "data-disabled": n.disabled ? "" : void 0,
107
- "data-highlighted": K() ? "" : void 0
108
- })), z = {
109
- isChecked: () => n.checked,
110
- dataset: W,
111
- setLabelRef: x,
112
- generateId: ie(() => u.id),
113
- registerLabel: B(c),
114
- registerDescription: B(g)
36
+ function ee(e) {
37
+ const t = H({
38
+ selectionMode: "none",
39
+ selectionBehavior: "toggle"
40
+ }, e), [s, n] = k(!1), [c, f] = k(), w = A(() => {
41
+ const K = o(t.selectedKeys);
42
+ return K != null ? B(K) : K;
43
+ }), g = A(() => {
44
+ const K = o(t.defaultSelectedKeys);
45
+ return K != null ? B(K) : new b();
46
+ }), [S, p] = X({
47
+ value: w,
48
+ defaultValue: g,
49
+ onChange: (K) => t.onSelectionChange?.(K)
50
+ }), [m, v] = k(o(t.selectionBehavior)), D = () => o(t.selectionMode), T = () => o(t.disallowEmptySelection) ?? !1, x = (K) => {
51
+ (o(t.allowDuplicateSelectionEvents) || !Y(K, S())) && p(K);
115
52
  };
116
- return d(we.Provider, {
117
- value: z,
118
- get children() {
119
- return d(A, M({
120
- as: "div",
121
- ref(m) {
122
- var $ = N((ee) => o = ee, n.ref);
123
- typeof $ == "function" && $(m);
124
- },
125
- get tabIndex() {
126
- return a.tabIndex();
127
- },
128
- get "aria-checked"() {
129
- return _();
130
- },
131
- get "aria-disabled"() {
132
- return n.disabled;
133
- },
134
- get "aria-labelledby"() {
135
- return p();
136
- },
137
- get "aria-describedby"() {
138
- return b();
139
- },
140
- get "data-key"() {
141
- return a.dataKey();
142
- },
143
- get onPointerDown() {
144
- return w([n.onPointerDown, a.onPointerDown]);
145
- },
146
- get onPointerUp() {
147
- return w([f, a.onPointerUp]);
148
- },
149
- get onClick() {
150
- return w([n.onClick, a.onClick]);
151
- },
152
- get onKeyDown() {
153
- return w([O, a.onKeyDown]);
154
- },
155
- get onMouseDown() {
156
- return w([n.onMouseDown, a.onMouseDown]);
157
- },
158
- get onFocus() {
159
- return w([n.onFocus, a.onFocus]);
160
- },
161
- onPointerMove: C,
162
- onPointerLeave: i
163
- }, W, u));
164
- }
165
- });
166
- }
167
- function Rt(r) {
168
- const o = D({
169
- closeOnSelect: !1
170
- }, r), [s, e] = I(o, ["checked", "defaultChecked", "onChange", "onSelect"]), t = Ye({
171
- isSelected: () => s.checked,
172
- defaultIsSelected: () => s.defaultChecked,
173
- onSelectedChange: (u) => s.onChange?.(u),
174
- isDisabled: () => e.disabled
175
- });
176
- return d(ae, M({
177
- role: "menuitemcheckbox",
178
- get checked() {
179
- return t.isSelected();
180
- },
181
- onSelect: () => {
182
- s.onSelect?.(), t.toggle();
183
- }
184
- }, e));
185
- }
186
- var Y = {
187
- next: (r, o) => r === "ltr" ? o === "horizontal" ? "ArrowRight" : "ArrowDown" : o === "horizontal" ? "ArrowLeft" : "ArrowUp",
188
- previous: (r, o) => Y.next(r === "ltr" ? "rtl" : "ltr", o)
189
- }, pe = {
190
- first: (r) => r === "horizontal" ? "ArrowDown" : "ArrowRight",
191
- last: (r) => r === "horizontal" ? "ArrowUp" : "ArrowLeft"
192
- };
193
- function At(r) {
194
- const o = E(), s = L(), e = Z(), {
195
- direction: t
196
- } = H(), n = D({
197
- id: o.generateId("trigger")
198
- }, r), [u, p] = I(n, ["ref", "id", "disabled", "onPointerDown", "onClick", "onKeyDown", "onMouseOver", "onFocus"]);
199
- let c = () => o.value();
200
- e !== void 0 && (c = () => o.value() ?? u.id, e.lastValue() === void 0 && e.setLastValue(c));
201
- const b = We(() => s.triggerRef(), () => "button"), g = j(() => b() === "a" && s.triggerRef()?.getAttribute("href") != null);
202
- y(ve(() => e?.value(), (a) => {
203
- g() && a === c() && s.triggerRef()?.focus();
204
- }));
205
- const h = () => {
206
- e !== void 0 ? s.isOpen() ? e.value() === c() && e.closeMenu() : (e.autoFocusMenu() || e.setAutoFocusMenu(!0), s.open(!1)) : s.toggle(!0);
207
- }, x = (a) => {
208
- P(a, u.onPointerDown), a.currentTarget.dataset.pointerType = a.pointerType, !u.disabled && a.pointerType !== "touch" && a.button === 0 && h();
209
- }, S = (a) => {
210
- P(a, u.onClick), u.disabled || a.currentTarget.dataset.pointerType === "touch" && h();
211
- }, v = (a) => {
212
- if (P(a, u.onKeyDown), !u.disabled) {
213
- if (g())
214
- switch (a.key) {
215
- case "Enter":
216
- case " ":
217
- return;
218
- }
219
- switch (a.key) {
220
- case "Enter":
221
- case " ":
222
- case pe.first(o.orientation()):
223
- a.stopPropagation(), a.preventDefault(), qe(a.currentTarget), s.open("first"), e?.setAutoFocusMenu(!0), e?.setValue(c);
224
- break;
225
- case pe.last(o.orientation()):
226
- a.stopPropagation(), a.preventDefault(), s.open("last");
227
- break;
228
- case Y.next(t(), o.orientation()):
229
- if (e === void 0) break;
230
- a.stopPropagation(), a.preventDefault(), e.nextMenu();
231
- break;
232
- case Y.previous(t(), o.orientation()):
233
- if (e === void 0) break;
234
- a.stopPropagation(), a.preventDefault(), e.previousMenu();
235
- break;
236
- }
237
- }
238
- }, K = (a) => {
239
- P(a, u.onMouseOver), s.triggerRef()?.dataset.pointerType !== "touch" && !u.disabled && e !== void 0 && e.value() !== void 0 && e.setValue(c);
240
- }, k = (a) => {
241
- P(a, u.onFocus), e !== void 0 && a.currentTarget.dataset.pointerType !== "touch" && e.setValue(c);
53
+ return L(() => {
54
+ const K = S();
55
+ o(t.selectionBehavior) === "replace" && m() === "toggle" && typeof K == "object" && K.size === 0 && v("replace");
56
+ }), L(() => {
57
+ v(o(t.selectionBehavior) ?? "toggle");
58
+ }), {
59
+ selectionMode: D,
60
+ disallowEmptySelection: T,
61
+ selectionBehavior: m,
62
+ setSelectionBehavior: v,
63
+ isFocused: s,
64
+ setFocused: n,
65
+ focusedKey: c,
66
+ setFocusedKey: f,
67
+ selectedKeys: S,
68
+ setSelectedKeys: x
242
69
  };
243
- return y(() => T(s.registerTriggerId(u.id))), d(Xe, M({
244
- ref(a) {
245
- var C = N(s.setTriggerRef, u.ref);
246
- typeof C == "function" && C(a);
247
- },
248
- get "data-kb-menu-value-trigger"() {
249
- return o.value();
250
- },
251
- get id() {
252
- return u.id;
253
- },
254
- get disabled() {
255
- return u.disabled;
256
- },
257
- "aria-haspopup": "true",
258
- get "aria-expanded"() {
259
- return s.isOpen();
260
- },
261
- get "aria-controls"() {
262
- return re(() => !!s.isOpen())() ? s.contentId() : void 0;
263
- },
264
- get "data-highlighted"() {
265
- return c() !== void 0 && e?.value() === c() ? !0 : void 0;
266
- },
267
- get tabIndex() {
268
- return e !== void 0 ? e.value() === c() || e.lastValue() === c() ? 0 : -1 : void 0;
269
- },
270
- onPointerDown: x,
271
- onMouseOver: K,
272
- onClick: S,
273
- onKeyDown: v,
274
- onFocus: k,
275
- role: e !== void 0 ? "menuitem" : void 0
276
- }, () => s.dataset(), p));
277
70
  }
278
- function xe(r) {
279
- let o;
280
- const s = E(), e = L(), t = Z(), n = Me(), {
281
- direction: u
282
- } = H(), p = D({
283
- id: s.generateId(`content-${V()}`)
284
- }, r), [c, b] = I(p, ["ref", "id", "style", "onOpenAutoFocus", "onCloseAutoFocus", "onEscapeKeyDown", "onFocusOutside", "onPointerEnter", "onPointerMove", "onKeyDown", "onMouseDown", "onFocusIn", "onFocusOut"]);
285
- let g = 0;
286
- const h = () => e.parentMenuContext() == null && t === void 0 && s.isModal(), x = Ge({
287
- selectionManager: e.listState().selectionManager,
288
- collection: e.listState().collection,
289
- autoFocus: e.autoFocus,
290
- deferAutoFocus: !0,
291
- // ensure all menu items are mounted and collection is not empty before trying to autofocus.
292
- shouldFocusWrap: !0,
293
- disallowTypeAhead: () => !e.listState().selectionManager().isFocused(),
294
- orientation: () => s.orientation() === "horizontal" ? "vertical" : "horizontal"
295
- }, () => o);
296
- ze({
297
- trapFocus: () => h() && e.isOpen(),
298
- onMountAutoFocus: (i) => {
299
- t === void 0 && c.onOpenAutoFocus?.(i);
300
- },
301
- onUnmountAutoFocus: c.onCloseAutoFocus
302
- }, () => o);
303
- const S = (i) => {
304
- if (J(i.currentTarget, i.target) && (i.key === "Tab" && e.isOpen() && i.preventDefault(), t !== void 0 && i.currentTarget.getAttribute("aria-haspopup") !== "true"))
305
- switch (i.key) {
306
- case Y.next(u(), s.orientation()):
307
- i.stopPropagation(), i.preventDefault(), e.close(!0), t.setAutoFocusMenu(!0), t.nextMenu();
308
- break;
309
- case Y.previous(u(), s.orientation()):
310
- if (i.currentTarget.hasAttribute("data-closed")) break;
311
- i.stopPropagation(), i.preventDefault(), e.close(!0), t.setAutoFocusMenu(!0), t.previousMenu();
312
- break;
71
+ function te(e) {
72
+ const [t, s] = k(""), [n, c] = k(-1);
73
+ return {
74
+ typeSelectHandlers: {
75
+ onKeyDown: (w) => {
76
+ if (o(e.isDisabled))
77
+ return;
78
+ const g = o(e.keyboardDelegate), S = o(e.selectionManager);
79
+ if (!g.getKeyForSearch)
80
+ return;
81
+ const p = se(w.key);
82
+ if (!p || w.ctrlKey || w.metaKey)
83
+ return;
84
+ p === " " && t().trim().length > 0 && (w.preventDefault(), w.stopPropagation());
85
+ let m = s((D) => D + p), v = g.getKeyForSearch(m, S.focusedKey()) ?? g.getKeyForSearch(m);
86
+ v == null && ne(m) && (m = m[0], v = g.getKeyForSearch(m, S.focusedKey()) ?? g.getKeyForSearch(m)), v != null && (S.setFocusedKey(v), e.onTypeSelect?.(v)), clearTimeout(n()), c(window.setTimeout(() => s(""), 500));
313
87
  }
314
- }, v = (i) => {
315
- c.onEscapeKeyDown?.(i), t?.setAutoFocusMenu(!1), e.close(!0);
316
- }, K = (i) => {
317
- c.onFocusOutside?.(i), s.isModal() && i.preventDefault();
318
- }, k = (i) => {
319
- P(i, c.onPointerEnter), e.isOpen() && (e.parentMenuContext()?.listState().selectionManager().setFocused(!1), e.parentMenuContext()?.listState().selectionManager().setFocusedKey(void 0));
320
- }, a = (i) => {
321
- if (P(i, c.onPointerMove), i.pointerType !== "mouse")
322
- return;
323
- const f = i.target, O = g !== i.clientX;
324
- J(i.currentTarget, f) && O && (e.setPointerDir(i.clientX > g ? "right" : "left"), g = i.clientX);
325
- };
326
- y(() => T(e.registerContentId(c.id))), T(() => e.setContentRef(void 0));
327
- const C = {
328
- ref: N((i) => {
329
- e.setContentRef(i), o = i;
330
- }, c.ref),
331
- role: "menu",
332
- get id() {
333
- return c.id;
334
- },
335
- get tabIndex() {
336
- return x.tabIndex();
337
- },
338
- get "aria-labelledby"() {
339
- return e.triggerId();
340
- },
341
- onKeyDown: w([c.onKeyDown, x.onKeyDown, S]),
342
- onMouseDown: w([c.onMouseDown, x.onMouseDown]),
343
- onFocusIn: w([c.onFocusIn, x.onFocusIn]),
344
- onFocusOut: w([c.onFocusOut, x.onFocusOut]),
345
- onPointerEnter: k,
346
- onPointerMove: a,
347
- get "data-orientation"() {
348
- return s.orientation();
349
88
  }
350
89
  };
351
- return d(X, {
352
- get when() {
353
- return e.contentPresent();
354
- },
355
- get children() {
356
- return d(X, {
357
- get when() {
358
- return n === void 0 || e.parentMenuContext() != null;
359
- },
360
- get fallback() {
361
- return d(A, M({
362
- as: "div"
363
- }, () => e.dataset(), C, b));
364
- },
365
- get children() {
366
- return d(fe.Positioner, {
367
- get children() {
368
- return d(Be, M({
369
- get disableOutsidePointerEvents() {
370
- return re(() => !!h())() && e.isOpen();
371
- },
372
- get excludedElements() {
373
- return [e.triggerRef];
374
- },
375
- bypassTopMostLayerCheck: !0,
376
- get style() {
377
- return et({
378
- "--kb-menu-content-transform-origin": "var(--kb-popper-content-transform-origin)",
379
- position: "relative"
380
- }, c.style);
381
- },
382
- onEscapeKeyDown: v,
383
- onFocusOutside: K,
384
- get onDismiss() {
385
- return e.close;
386
- }
387
- }, () => e.dataset(), C, b));
388
- }
389
- });
390
- }
391
- });
392
- }
393
- });
394
90
  }
395
- function Et(r) {
396
- let o;
397
- const s = E(), e = L(), [t, n] = I(r, ["ref"]);
398
- return Qe({
399
- element: () => o ?? null,
400
- enabled: () => e.contentPresent() && s.preventScroll()
401
- }), d(xe, M({
402
- ref(u) {
403
- var p = N((c) => {
404
- o = c;
405
- }, t.ref);
406
- typeof p == "function" && p(u);
407
- }
408
- }, n));
91
+ function se(e) {
92
+ return e.length === 1 || !/^[A-Z]/i.test(e) ? e : "";
409
93
  }
410
- var Ie = U();
411
- function ot() {
412
- const r = G(Ie);
413
- if (r === void 0)
414
- throw new Error("[kobalte]: `useMenuGroupContext` must be used within a `Menu.Group` component");
415
- return r;
94
+ function ne(e) {
95
+ return e.split("").every((t) => t === e[0]);
416
96
  }
417
- function rt(r) {
418
- const o = E(), s = D({
419
- id: o.generateId(`group-${V()}`)
420
- }, r), [e, t] = F(), n = {
421
- generateId: ie(() => s.id),
422
- registerLabelId: B(t)
97
+ function de(e, t, s) {
98
+ const c = Z({
99
+ selectOnFocus: () => o(e.selectionManager).selectionBehavior() === "replace"
100
+ }, e), f = () => s?.() ?? t(), {
101
+ direction: w
102
+ } = N();
103
+ let g = {
104
+ top: 0,
105
+ left: 0
423
106
  };
424
- return d(Ie.Provider, {
425
- value: n,
426
- get children() {
427
- return d(A, M({
428
- as: "div",
429
- role: "group",
430
- get "aria-labelledby"() {
431
- return e();
432
- }
433
- }, s));
434
- }
107
+ Q(() => o(c.isVirtualized) ? void 0 : f(), "scroll", () => {
108
+ const i = f();
109
+ i && (g = {
110
+ top: i.scrollTop,
111
+ left: i.scrollLeft
112
+ });
435
113
  });
436
- }
437
- function Lt(r) {
438
- const o = ot(), s = D({
439
- id: o.generateId("label")
440
- }, r), [e, t] = I(s, ["id"]);
441
- return y(() => T(o.registerLabelId(e.id))), d(A, M({
442
- as: "span",
443
- get id() {
444
- return e.id;
445
- },
446
- "aria-hidden": "true"
447
- }, t));
448
- }
449
- function Gt(r) {
450
- const o = L(), s = D({
451
- children: "▼"
452
- }, r);
453
- return d(A, M({
454
- as: "span",
455
- "aria-hidden": "true"
456
- }, () => o.dataset(), s));
457
- }
458
- function Ut(r) {
459
- return d(ae, M({
460
- role: "menuitem",
461
- closeOnSelect: !0
462
- }, r));
463
- }
464
- function Vt(r) {
465
- const o = se(), s = D({
466
- id: o.generateId("description")
467
- }, r), [e, t] = I(s, ["id"]);
468
- return y(() => T(o.registerDescription(e.id))), d(A, M({
469
- as: "div",
470
- get id() {
471
- return e.id;
114
+ const {
115
+ typeSelectHandlers: S
116
+ } = te({
117
+ isDisabled: () => o(c.disallowTypeAhead),
118
+ keyboardDelegate: () => o(c.keyboardDelegate),
119
+ selectionManager: () => o(c.selectionManager)
120
+ }), p = () => o(c.orientation) ?? "vertical", m = (i) => {
121
+ q(i, S.onKeyDown), i.altKey && i.key === "Tab" && i.preventDefault();
122
+ const u = t();
123
+ if (!u?.contains(i.target))
124
+ return;
125
+ const l = o(c.selectionManager), y = o(c.selectOnFocus), d = (a) => {
126
+ a != null && (l.setFocusedKey(a), i.shiftKey && l.selectionMode() === "multiple" ? l.extendSelection(a) : y && !V(i) && l.replaceSelection(a));
127
+ }, r = o(c.keyboardDelegate), M = o(c.shouldFocusWrap), h = l.focusedKey();
128
+ switch (i.key) {
129
+ case (p() === "vertical" ? "ArrowDown" : "ArrowRight"): {
130
+ if (r.getKeyBelow) {
131
+ i.preventDefault();
132
+ let a;
133
+ h != null ? a = r.getKeyBelow(h) : a = r.getFirstKey?.(), a == null && M && (a = r.getFirstKey?.(h)), d(a);
134
+ }
135
+ break;
136
+ }
137
+ case (p() === "vertical" ? "ArrowUp" : "ArrowLeft"): {
138
+ if (r.getKeyAbove) {
139
+ i.preventDefault();
140
+ let a;
141
+ h != null ? a = r.getKeyAbove(h) : a = r.getLastKey?.(), a == null && M && (a = r.getLastKey?.(h)), d(a);
142
+ }
143
+ break;
144
+ }
145
+ case (p() === "vertical" ? "ArrowLeft" : "ArrowUp"): {
146
+ if (r.getKeyLeftOf) {
147
+ i.preventDefault();
148
+ const a = w() === "rtl";
149
+ let F;
150
+ h != null ? F = r.getKeyLeftOf(h) : F = a ? r.getFirstKey?.() : r.getLastKey?.(), d(F);
151
+ }
152
+ break;
153
+ }
154
+ case (p() === "vertical" ? "ArrowRight" : "ArrowDown"): {
155
+ if (r.getKeyRightOf) {
156
+ i.preventDefault();
157
+ const a = w() === "rtl";
158
+ let F;
159
+ h != null ? F = r.getKeyRightOf(h) : F = a ? r.getLastKey?.() : r.getFirstKey?.(), d(F);
160
+ }
161
+ break;
162
+ }
163
+ case "Home":
164
+ if (r.getFirstKey) {
165
+ i.preventDefault();
166
+ const a = r.getFirstKey(h, I(i));
167
+ a != null && (l.setFocusedKey(a), I(i) && i.shiftKey && l.selectionMode() === "multiple" ? l.extendSelection(a) : y && l.replaceSelection(a));
168
+ }
169
+ break;
170
+ case "End":
171
+ if (r.getLastKey) {
172
+ i.preventDefault();
173
+ const a = r.getLastKey(h, I(i));
174
+ a != null && (l.setFocusedKey(a), I(i) && i.shiftKey && l.selectionMode() === "multiple" ? l.extendSelection(a) : y && l.replaceSelection(a));
175
+ }
176
+ break;
177
+ case "PageDown":
178
+ if (r.getKeyPageBelow && h != null) {
179
+ i.preventDefault();
180
+ const a = r.getKeyPageBelow(h);
181
+ d(a);
182
+ }
183
+ break;
184
+ case "PageUp":
185
+ if (r.getKeyPageAbove && h != null) {
186
+ i.preventDefault();
187
+ const a = r.getKeyPageAbove(h);
188
+ d(a);
189
+ }
190
+ break;
191
+ case "a":
192
+ I(i) && l.selectionMode() === "multiple" && o(c.disallowSelectAll) !== !0 && (i.preventDefault(), l.selectAll());
193
+ break;
194
+ case "Escape":
195
+ i.defaultPrevented || (i.preventDefault(), o(c.disallowEmptySelection) || l.clearSelection());
196
+ break;
197
+ case "Tab":
198
+ if (!o(c.allowsTabNavigation)) {
199
+ if (i.shiftKey)
200
+ u.focus();
201
+ else {
202
+ const a = $(u, {
203
+ tabbable: !0
204
+ });
205
+ let F, P;
206
+ do
207
+ P = a.lastChild(), P && (F = P);
208
+ while (P);
209
+ F && !F.contains(document.activeElement) && E(F);
210
+ }
211
+ break;
212
+ }
472
213
  }
473
- }, () => o.dataset(), t));
474
- }
475
- function Nt(r) {
476
- const o = se(), s = D({
477
- id: o.generateId("indicator")
478
- }, r), [e, t] = I(s, ["forceMount"]);
479
- return d(X, {
480
- get when() {
481
- return e.forceMount || o.isChecked();
482
- },
483
- get children() {
484
- return d(A, M({
485
- as: "div"
486
- }, () => o.dataset(), t));
214
+ }, v = (i) => {
215
+ const u = o(c.selectionManager), l = o(c.keyboardDelegate), y = o(c.selectOnFocus);
216
+ if (u.isFocused()) {
217
+ i.currentTarget.contains(i.target) || u.setFocused(!1);
218
+ return;
487
219
  }
488
- });
489
- }
490
- function _t(r) {
491
- const o = se(), s = D({
492
- id: o.generateId("label")
493
- }, r), [e, t] = I(s, ["ref", "id"]);
494
- return y(() => T(o.registerLabel(e.id))), d(A, M({
495
- as: "div",
496
- ref(n) {
497
- var u = N(o.setLabelRef, e.ref);
498
- typeof u == "function" && u(n);
499
- },
500
- get id() {
501
- return e.id;
220
+ if (i.currentTarget.contains(i.target)) {
221
+ if (u.setFocused(!0), u.focusedKey() == null) {
222
+ const d = (M) => {
223
+ M != null && (u.setFocusedKey(M), y && u.replaceSelection(M));
224
+ }, r = i.relatedTarget;
225
+ r && i.currentTarget.compareDocumentPosition(r) & Node.DOCUMENT_POSITION_FOLLOWING ? d(u.lastSelectedKey() ?? l.getLastKey?.()) : d(u.firstSelectedKey() ?? l.getFirstKey?.());
226
+ } else if (!o(c.isVirtualized)) {
227
+ const d = f();
228
+ if (d) {
229
+ d.scrollTop = g.top, d.scrollLeft = g.left;
230
+ const r = d.querySelector(`[data-key="${u.focusedKey()}"]`);
231
+ r && (E(r), O(d, r));
232
+ }
233
+ }
502
234
  }
503
- }, () => o.dataset(), t));
504
- }
505
- function zt(r) {
506
- const o = L();
507
- return d(X, {
508
- get when() {
509
- return o.contentPresent();
510
- },
511
- get children() {
512
- return d(Ee, r);
235
+ }, D = (i) => {
236
+ const u = o(c.selectionManager);
237
+ i.currentTarget.contains(i.relatedTarget) || u.setFocused(!1);
238
+ }, T = (i) => {
239
+ f() === i.target && i.preventDefault();
240
+ }, x = () => {
241
+ const i = o(c.autoFocus);
242
+ if (!i)
243
+ return;
244
+ const u = o(c.selectionManager), l = o(c.keyboardDelegate);
245
+ let y;
246
+ i === "first" && (y = l.getFirstKey?.()), i === "last" && (y = l.getLastKey?.());
247
+ const d = u.selectedKeys();
248
+ d.size && (y = d.values().next().value), u.setFocused(!0), u.setFocusedKey(y);
249
+ const r = t();
250
+ r && y == null && !o(c.shouldUseVirtualFocus) && E(r);
251
+ };
252
+ return J(() => {
253
+ c.deferAutoFocus ? setTimeout(x, 0) : x();
254
+ }), L(C([f, () => o(c.isVirtualized), () => o(c.selectionManager).focusedKey()], (i) => {
255
+ const [u, l, y] = i;
256
+ if (l)
257
+ y && c.scrollToKey?.(y);
258
+ else if (y && u) {
259
+ const d = u.querySelector(`[data-key="${y}"]`);
260
+ d && O(u, d);
513
261
  }
514
- });
515
- }
516
- var De = U();
517
- function it() {
518
- const r = G(De);
519
- if (r === void 0)
520
- throw new Error("[kobalte]: `useMenuRadioGroupContext` must be used within a `Menu.RadioGroup` component");
521
- return r;
262
+ })), {
263
+ tabIndex: A(() => {
264
+ if (!o(c.shouldUseVirtualFocus))
265
+ return o(c.selectionManager).focusedKey() == null ? 0 : -1;
266
+ }),
267
+ onKeyDown: m,
268
+ onMouseDown: T,
269
+ onFocusIn: v,
270
+ onFocusOut: D
271
+ };
522
272
  }
523
- function $t(r) {
524
- const s = E().generateId(`radiogroup-${V()}`), e = D({
525
- id: s
526
- }, r), [t, n] = I(e, ["value", "defaultValue", "onChange", "disabled"]), [u, p] = He({
527
- value: () => t.value,
528
- defaultValue: () => t.defaultValue,
529
- onChange: (b) => t.onChange?.(b)
530
- }), c = {
531
- isDisabled: () => t.disabled,
532
- isSelectedValue: (b) => b === u(),
533
- setSelectedValue: (b) => p(b)
273
+ function ye(e, t) {
274
+ const s = () => o(e.selectionManager), n = () => o(e.key), c = () => o(e.shouldUseVirtualFocus), f = (l) => {
275
+ s().selectionMode() !== "none" && (s().selectionMode() === "single" ? s().isSelected(n()) && !s().disallowEmptySelection() ? s().toggleSelection(n()) : s().replaceSelection(n()) : l?.shiftKey ? s().extendSelection(n()) : s().selectionBehavior() === "toggle" || I(l) || "pointerType" in l && l.pointerType === "touch" ? s().toggleSelection(n()) : s().replaceSelection(n()));
276
+ }, w = () => s().isSelected(n()), g = () => o(e.disabled) || s().isDisabled(n()), S = () => !g() && s().canSelectItem(n());
277
+ let p = null;
278
+ const m = (l) => {
279
+ S() && (p = l.pointerType, l.pointerType === "mouse" && l.button === 0 && !o(e.shouldSelectOnPressUp) && f(l));
280
+ }, v = (l) => {
281
+ S() && l.pointerType === "mouse" && l.button === 0 && o(e.shouldSelectOnPressUp) && o(e.allowsDifferentPressOrigin) && f(l);
282
+ }, D = (l) => {
283
+ S() && (o(e.shouldSelectOnPressUp) && !o(e.allowsDifferentPressOrigin) || p !== "mouse") && f(l);
284
+ }, T = (l) => {
285
+ !S() || !["Enter", " "].includes(l.key) || (V(l) ? s().toggleSelection(n()) : f(l));
286
+ }, x = (l) => {
287
+ g() && l.preventDefault();
288
+ }, K = (l) => {
289
+ const y = t();
290
+ c() || g() || !y || l.target === y && s().setFocusedKey(n());
291
+ }, i = A(() => {
292
+ if (!(c() || g()))
293
+ return n() === s().focusedKey() ? 0 : -1;
294
+ }), u = A(() => o(e.virtualized) ? void 0 : n());
295
+ return L(C([t, n, c, () => s().focusedKey(), () => s().isFocused()], ([l, y, d, r, M]) => {
296
+ l && y === r && M && !d && document.activeElement !== l && (e.focus ? e.focus() : E(l));
297
+ })), {
298
+ isSelected: w,
299
+ isDisabled: g,
300
+ allowsSelection: S,
301
+ tabIndex: i,
302
+ dataKey: u,
303
+ onPointerDown: m,
304
+ onPointerUp: v,
305
+ onClick: D,
306
+ onKeyDown: T,
307
+ onMouseDown: x,
308
+ onFocus: K
534
309
  };
535
- return d(De.Provider, {
536
- value: c,
537
- get children() {
538
- return d(rt, n);
539
- }
540
- });
541
310
  }
542
- function Bt(r) {
543
- const o = it(), s = D({
544
- closeOnSelect: !1
545
- }, r), [e, t] = I(s, ["value", "onSelect"]);
546
- return d(ae, M({
547
- role: "menuitemradio",
548
- get checked() {
549
- return o.isSelectedValue(e.value);
550
- },
551
- onSelect: () => {
552
- e.onSelect?.(), o.setSelectedValue(e.value);
311
+ var ie = class {
312
+ collection;
313
+ state;
314
+ constructor(e, t) {
315
+ this.collection = e, this.state = t;
316
+ }
317
+ /** The type of selection that is allowed in the collection. */
318
+ selectionMode() {
319
+ return this.state.selectionMode();
320
+ }
321
+ /** Whether the collection allows empty selection. */
322
+ disallowEmptySelection() {
323
+ return this.state.disallowEmptySelection();
324
+ }
325
+ /** The selection behavior for the collection. */
326
+ selectionBehavior() {
327
+ return this.state.selectionBehavior();
328
+ }
329
+ /** Sets the selection behavior for the collection. */
330
+ setSelectionBehavior(e) {
331
+ this.state.setSelectionBehavior(e);
332
+ }
333
+ /** Whether the collection is currently focused. */
334
+ isFocused() {
335
+ return this.state.isFocused();
336
+ }
337
+ /** Sets whether the collection is focused. */
338
+ setFocused(e) {
339
+ this.state.setFocused(e);
340
+ }
341
+ /** The current focused key in the collection. */
342
+ focusedKey() {
343
+ return this.state.focusedKey();
344
+ }
345
+ /** Sets the focused key. */
346
+ setFocusedKey(e) {
347
+ (e == null || this.collection().getItem(e)) && this.state.setFocusedKey(e);
348
+ }
349
+ /** The currently selected keys in the collection. */
350
+ selectedKeys() {
351
+ return this.state.selectedKeys();
352
+ }
353
+ /** Returns whether a key is selected. */
354
+ isSelected(e) {
355
+ if (this.state.selectionMode() === "none")
356
+ return !1;
357
+ const t = this.getKey(e);
358
+ return t == null ? !1 : this.state.selectedKeys().has(t);
359
+ }
360
+ /** Whether the selection is empty. */
361
+ isEmpty() {
362
+ return this.state.selectedKeys().size === 0;
363
+ }
364
+ /** Whether all items in the collection are selected. */
365
+ isSelectAll() {
366
+ if (this.isEmpty())
367
+ return !1;
368
+ const e = this.state.selectedKeys();
369
+ return this.getAllSelectableKeys().every((t) => e.has(t));
370
+ }
371
+ firstSelectedKey() {
372
+ let e;
373
+ for (const t of this.state.selectedKeys()) {
374
+ const s = this.collection().getItem(t), n = s?.index != null && e?.index != null && s.index < e.index;
375
+ (!e || n) && (e = s);
553
376
  }
554
- }, t));
555
- }
556
- function st(r, o, s) {
557
- const e = r.split("-")[0], t = s.getBoundingClientRect(), n = [], u = o.clientX, p = o.clientY;
558
- switch (e) {
559
- case "top":
560
- n.push([u, p + 5]), n.push([t.left, t.bottom]), n.push([t.left, t.top]), n.push([t.right, t.top]), n.push([t.right, t.bottom]);
561
- break;
562
- case "right":
563
- n.push([u - 5, p]), n.push([t.left, t.top]), n.push([t.right, t.top]), n.push([t.right, t.bottom]), n.push([t.left, t.bottom]);
564
- break;
565
- case "bottom":
566
- n.push([u, p - 5]), n.push([t.right, t.top]), n.push([t.right, t.bottom]), n.push([t.left, t.bottom]), n.push([t.left, t.top]);
567
- break;
568
- case "left":
569
- n.push([u + 5, p]), n.push([t.right, t.bottom]), n.push([t.left, t.bottom]), n.push([t.left, t.top]), n.push([t.right, t.top]);
570
- break;
571
- }
572
- return n;
573
- }
574
- function at(r, o) {
575
- return o ? Je([r.clientX, r.clientY], o) : !1;
576
- }
577
- function ye(r) {
578
- const o = E(), s = Ve(), e = Ce(), t = Z(), n = Me(), u = D({
579
- placement: o.orientation() === "horizontal" ? "bottom-start" : "right-start"
580
- }, r), [p, c] = I(u, ["open", "defaultOpen", "onOpenChange"]);
581
- let b = 0, g = null, h = "right";
582
- const [x, S] = F(), [v, K] = F(), [k, a] = F(), [C, i] = F(), [f, O] = F(!0), [_, W] = F(c.placement), [z, m] = F([]), [$, ee] = F([]), {
583
- DomCollectionProvider: Se
584
- } = Ne({
585
- items: $,
586
- onItemsChange: ee
587
- }), R = he({
588
- open: () => p.open,
589
- defaultOpen: () => p.defaultOpen,
590
- onOpenChange: (l) => p.onOpenChange?.(l)
591
- }), {
592
- present: ke
593
- } = Ze({
594
- show: () => o.forceMount() || R.isOpen(),
595
- element: () => C() ?? null
596
- }), te = Ue({
597
- selectionMode: "none",
598
- dataSource: $
599
- }), ue = (l) => {
600
- O(l), R.open();
601
- }, ce = (l = !1) => {
602
- R.close(), l && e && e.close(!0);
603
- }, Oe = (l) => {
604
- O(l), R.toggle();
605
- }, le = () => {
606
- const l = C();
607
- l && (Q(l), te.selectionManager().setFocused(!0), te.selectionManager().setFocusedKey(void 0));
608
- }, de = () => {
609
- n != null ? setTimeout(() => le()) : le();
610
- }, Fe = (l) => {
611
- m((oe) => [...oe, l]);
612
- const q = e?.registerNestedMenu(l);
613
- return () => {
614
- m((oe) => je(oe, l)), q?.();
615
- };
616
- }, ne = (l) => h === g?.side && at(l, g?.area), Te = (l) => {
617
- ne(l) && l.preventDefault();
618
- }, Ke = (l) => {
619
- ne(l) || de();
620
- }, Re = (l) => {
621
- ne(l) && l.preventDefault();
622
- };
623
- $e({
624
- isDisabled: () => !(e == null && R.isOpen() && o.isModal()),
625
- targets: () => [C(), ...z()].filter(Boolean)
626
- }), y(() => {
627
- const l = C();
628
- if (!l || !e)
377
+ return e?.key;
378
+ }
379
+ lastSelectedKey() {
380
+ let e;
381
+ for (const t of this.state.selectedKeys()) {
382
+ const s = this.collection().getItem(t), n = s?.index != null && e?.index != null && s.index > e.index;
383
+ (!e || n) && (e = s);
384
+ }
385
+ return e?.key;
386
+ }
387
+ /** Extends the selection to the given key. */
388
+ extendSelection(e) {
389
+ if (this.selectionMode() === "none")
390
+ return;
391
+ if (this.selectionMode() === "single") {
392
+ this.replaceSelection(e);
629
393
  return;
630
- const q = e.registerNestedMenu(l);
631
- T(() => {
632
- q();
633
- });
634
- }), y(() => {
635
- e === void 0 && t?.registerMenu(o.value(), [C(), ...z()]);
636
- }), y(() => {
637
- e !== void 0 || t === void 0 || (t.value() === o.value() ? (k()?.focus(), t.autoFocusMenu() && ue(!0)) : ce());
638
- }), y(() => {
639
- e !== void 0 || t === void 0 || R.isOpen() && t.setValue(o.value());
640
- }), T(() => {
641
- e === void 0 && t?.unregisterMenu(o.value());
642
- });
643
- const Ae = {
644
- dataset: j(() => ({
645
- "data-expanded": R.isOpen() ? "" : void 0,
646
- "data-closed": R.isOpen() ? void 0 : ""
647
- })),
648
- isOpen: R.isOpen,
649
- contentPresent: ke,
650
- nestedMenus: z,
651
- currentPlacement: _,
652
- pointerGraceTimeoutId: () => b,
653
- autoFocus: f,
654
- listState: () => te,
655
- parentMenuContext: () => e,
656
- triggerRef: k,
657
- contentRef: C,
658
- triggerId: x,
659
- contentId: v,
660
- setTriggerRef: a,
661
- setContentRef: i,
662
- open: ue,
663
- close: ce,
664
- toggle: Oe,
665
- focusContent: de,
666
- onItemEnter: Te,
667
- onItemLeave: Ke,
668
- onTriggerLeave: Re,
669
- setPointerDir: (l) => h = l,
670
- setPointerGraceTimeoutId: (l) => b = l,
671
- setPointerGraceIntent: (l) => g = l,
672
- registerNestedMenu: Fe,
673
- registerItemToParentDomCollection: s?.registerItem,
674
- registerTriggerId: B(S),
675
- registerContentId: B(K)
676
- };
677
- return d(Se, {
678
- get children() {
679
- return d(be.Provider, {
680
- value: Ae,
681
- get children() {
682
- return d(X, {
683
- when: n === void 0,
684
- get fallback() {
685
- return c.children;
686
- },
687
- get children() {
688
- return d(fe, M({
689
- anchorRef: k,
690
- contentRef: C,
691
- onCurrentPlacementChange: W
692
- }, c));
693
- }
694
- });
695
- }
696
- });
697
394
  }
698
- });
699
- }
700
- function Xt(r) {
701
- const {
702
- direction: o
703
- } = H();
704
- return d(ye, M({
705
- get placement() {
706
- return o() === "rtl" ? "left-start" : "right-start";
707
- },
708
- flip: !0
709
- }, r));
710
- }
711
- var ut = {
712
- close: (r, o) => r === "ltr" ? [o === "horizontal" ? "ArrowLeft" : "ArrowUp"] : [o === "horizontal" ? "ArrowRight" : "ArrowDown"]
713
- };
714
- function Yt(r) {
715
- const o = L(), s = E(), [e, t] = I(r, ["onFocusOutside", "onKeyDown"]), {
716
- direction: n
717
- } = H();
718
- return d(xe, M({
719
- onOpenAutoFocus: (g) => {
720
- g.preventDefault();
721
- },
722
- onCloseAutoFocus: (g) => {
723
- g.preventDefault();
724
- },
725
- onFocusOutside: (g) => {
726
- e.onFocusOutside?.(g);
727
- const h = g.target;
728
- J(o.triggerRef(), h) || o.close();
729
- },
730
- onKeyDown: (g) => {
731
- P(g, e.onKeyDown);
732
- const h = J(g.currentTarget, g.target), x = ut.close(n(), s.orientation()).includes(g.key), S = o.parentMenuContext() != null;
733
- h && x && S && (o.close(), Q(o.triggerRef()));
395
+ const t = this.getKey(e);
396
+ if (t == null)
397
+ return;
398
+ const s = this.state.selectedKeys(), n = s.anchorKey || t, c = new b(s, n, t);
399
+ for (const f of this.getKeyRange(n, s.currentKey || t))
400
+ c.delete(f);
401
+ for (const f of this.getKeyRange(t, n))
402
+ this.canSelectItem(f) && c.add(f);
403
+ this.state.setSelectedKeys(c);
404
+ }
405
+ getKeyRange(e, t) {
406
+ const s = this.collection().getItem(e), n = this.collection().getItem(t);
407
+ return s && n ? s.index != null && n.index != null && s.index <= n.index ? this.getKeyRangeInternal(e, t) : this.getKeyRangeInternal(t, e) : [];
408
+ }
409
+ getKeyRangeInternal(e, t) {
410
+ const s = [];
411
+ let n = e;
412
+ for (; n != null; ) {
413
+ const c = this.collection().getItem(n);
414
+ if (c && c.type === "item" && s.push(n), n === t)
415
+ return s;
416
+ n = this.collection().getKeyAfter(n);
734
417
  }
735
- }, t));
736
- }
737
- var ge = ["Enter", " "], ct = {
738
- open: (r, o) => r === "ltr" ? [...ge, o === "horizontal" ? "ArrowRight" : "ArrowDown"] : [...ge, o === "horizontal" ? "ArrowLeft" : "ArrowUp"]
739
- };
740
- function Ht(r) {
741
- let o;
742
- const s = E(), e = L(), t = D({
743
- id: s.generateId(`sub-trigger-${V()}`)
744
- }, r), [n, u] = I(t, ["ref", "id", "textValue", "disabled", "onPointerMove", "onPointerLeave", "onPointerDown", "onPointerUp", "onClick", "onKeyDown", "onMouseDown", "onFocus"]);
745
- let p = null;
746
- const c = () => {
747
- Le || (p && window.clearTimeout(p), p = null);
748
- }, {
749
- direction: b
750
- } = H(), g = () => n.id, h = () => {
751
- const i = e.parentMenuContext();
752
- if (i == null)
753
- throw new Error("[kobalte]: `Menu.SubTrigger` must be used within a `Menu.Sub` component");
754
- return i.listState().selectionManager();
755
- }, x = () => e.listState().collection(), S = () => h().focusedKey() === g(), v = me({
756
- key: g,
757
- selectionManager: h,
758
- shouldSelectOnPressUp: !0,
759
- allowsDifferentPressOrigin: !0,
760
- disabled: () => n.disabled
761
- }, () => o), K = (i) => {
762
- P(i, n.onClick), !e.isOpen() && !n.disabled && e.open(!0);
763
- }, k = (i) => {
764
- if (P(i, n.onPointerMove), i.pointerType !== "mouse")
418
+ return [];
419
+ }
420
+ getKey(e) {
421
+ const t = this.collection().getItem(e);
422
+ return t ? !t || t.type !== "item" ? null : t.key : e;
423
+ }
424
+ /** Toggles whether the given key is selected. */
425
+ toggleSelection(e) {
426
+ if (this.selectionMode() === "none")
427
+ return;
428
+ if (this.selectionMode() === "single" && !this.isSelected(e)) {
429
+ this.replaceSelection(e);
765
430
  return;
766
- const f = e.parentMenuContext();
767
- if (f?.onItemEnter(i), !i.defaultPrevented) {
768
- if (n.disabled) {
769
- f?.onItemLeave(i);
770
- return;
771
- }
772
- !e.isOpen() && !p && (e.parentMenuContext()?.setPointerGraceIntent(null), p = window.setTimeout(() => {
773
- e.open(!1), c();
774
- }, 100)), f?.onItemEnter(i), i.defaultPrevented || (e.listState().selectionManager().isFocused() && (e.listState().selectionManager().setFocused(!1), e.listState().selectionManager().setFocusedKey(void 0)), Q(i.currentTarget), f?.listState().selectionManager().setFocused(!0), f?.listState().selectionManager().setFocusedKey(g()));
775
431
  }
776
- }, a = (i) => {
777
- if (P(i, n.onPointerLeave), i.pointerType !== "mouse")
432
+ const t = this.getKey(e);
433
+ if (t == null)
434
+ return;
435
+ const s = new b(this.state.selectedKeys());
436
+ s.has(t) ? s.delete(t) : this.canSelectItem(t) && (s.add(t), s.anchorKey = t, s.currentKey = t), !(this.disallowEmptySelection() && s.size === 0) && this.state.setSelectedKeys(s);
437
+ }
438
+ /** Replaces the selection with only the given key. */
439
+ replaceSelection(e) {
440
+ if (this.selectionMode() === "none")
441
+ return;
442
+ const t = this.getKey(e);
443
+ if (t == null)
444
+ return;
445
+ const s = this.canSelectItem(t) ? new b([t], t, t) : new b();
446
+ this.state.setSelectedKeys(s);
447
+ }
448
+ /** Replaces the selection with the given keys. */
449
+ setSelectedKeys(e) {
450
+ if (this.selectionMode() === "none")
778
451
  return;
779
- c();
780
- const f = e.parentMenuContext(), O = e.contentRef();
781
- if (O) {
782
- f?.setPointerGraceIntent({
783
- area: st(e.currentPlacement(), i, O),
784
- // Safe because sub menu always open "left" or "right".
785
- side: e.currentPlacement().split("-")[0]
786
- }), window.clearTimeout(f?.pointerGraceTimeoutId());
787
- const _ = window.setTimeout(() => {
788
- f?.setPointerGraceIntent(null);
789
- }, 300);
790
- f?.setPointerGraceTimeoutId(_);
791
- } else {
792
- if (f?.onTriggerLeave(i), i.defaultPrevented)
793
- return;
794
- f?.setPointerGraceIntent(null);
452
+ const t = new b();
453
+ for (const s of e) {
454
+ const n = this.getKey(s);
455
+ if (n != null && (t.add(n), this.selectionMode() === "single"))
456
+ break;
795
457
  }
796
- f?.onItemLeave(i);
797
- }, C = (i) => {
798
- P(i, n.onKeyDown), !i.repeat && (n.disabled || ct.open(b(), s.orientation()).includes(i.key) && (i.stopPropagation(), i.preventDefault(), h().setFocused(!1), h().setFocusedKey(void 0), e.isOpen() || e.open("first"), e.focusContent(), e.listState().selectionManager().setFocused(!0), e.listState().selectionManager().setFocusedKey(x().getFirstKey())));
799
- };
800
- return y(() => {
801
- if (e.registerItemToParentDomCollection == null)
802
- throw new Error("[kobalte]: `Menu.SubTrigger` must be used within a `Menu.Sub` component");
803
- const i = e.registerItemToParentDomCollection({
804
- ref: () => o,
805
- type: "item",
806
- key: g(),
807
- textValue: n.textValue ?? o?.textContent ?? "",
808
- disabled: n.disabled ?? !1
809
- });
810
- T(i);
811
- }), y(ve(() => e.parentMenuContext()?.pointerGraceTimeoutId(), (i) => {
812
- T(() => {
813
- window.clearTimeout(i), e.parentMenuContext()?.setPointerGraceIntent(null);
814
- });
815
- })), y(() => T(e.registerTriggerId(n.id))), T(() => {
816
- c();
817
- }), d(A, M({
818
- as: "div",
819
- ref(i) {
820
- var f = N((O) => {
821
- e.setTriggerRef(O), o = O;
822
- }, n.ref);
823
- typeof f == "function" && f(i);
824
- },
825
- get id() {
826
- return n.id;
827
- },
828
- role: "menuitem",
829
- get tabIndex() {
830
- return v.tabIndex();
831
- },
832
- "aria-haspopup": "true",
833
- get "aria-expanded"() {
834
- return e.isOpen();
835
- },
836
- get "aria-controls"() {
837
- return re(() => !!e.isOpen())() ? e.contentId() : void 0;
838
- },
839
- get "aria-disabled"() {
840
- return n.disabled;
841
- },
842
- get "data-key"() {
843
- return v.dataKey();
844
- },
845
- get "data-highlighted"() {
846
- return S() ? "" : void 0;
847
- },
848
- get "data-disabled"() {
849
- return n.disabled ? "" : void 0;
850
- },
851
- get onPointerDown() {
852
- return w([n.onPointerDown, v.onPointerDown]);
853
- },
854
- get onPointerUp() {
855
- return w([n.onPointerUp, v.onPointerUp]);
856
- },
857
- get onClick() {
858
- return w([K, v.onClick]);
859
- },
860
- get onKeyDown() {
861
- return w([C, v.onKeyDown]);
862
- },
863
- get onMouseDown() {
864
- return w([n.onMouseDown, v.onMouseDown]);
865
- },
866
- get onFocus() {
867
- return w([n.onFocus, v.onFocus]);
868
- },
869
- onPointerMove: k,
870
- onPointerLeave: a
871
- }, () => e.dataset(), u));
872
- }
873
- function Wt(r) {
874
- const o = Z(), s = `menu-${V()}`, e = D({
875
- id: s,
876
- modal: !0
877
- }, r), [t, n] = I(e, ["id", "modal", "preventScroll", "forceMount", "open", "defaultOpen", "onOpenChange", "value", "orientation"]), u = he({
878
- open: () => t.open,
879
- defaultOpen: () => t.defaultOpen,
880
- onOpenChange: (c) => t.onOpenChange?.(c)
881
- }), p = {
882
- isModal: () => t.modal ?? !0,
883
- preventScroll: () => t.preventScroll ?? p.isModal(),
884
- forceMount: () => t.forceMount ?? !1,
885
- generateId: ie(() => t.id),
886
- value: () => t.value,
887
- orientation: () => t.orientation ?? o?.orientation() ?? "horizontal"
888
- };
889
- return d(Pe.Provider, {
890
- value: p,
891
- get children() {
892
- return d(ye, M({
893
- get open() {
894
- return u.isOpen();
895
- },
896
- get onOpenChange() {
897
- return u.setIsOpen;
458
+ this.state.setSelectedKeys(t);
459
+ }
460
+ /** Selects all items in the collection. */
461
+ selectAll() {
462
+ this.selectionMode() === "multiple" && this.state.setSelectedKeys(new Set(this.getAllSelectableKeys()));
463
+ }
464
+ /**
465
+ * Removes all keys from the selection.
466
+ */
467
+ clearSelection() {
468
+ const e = this.state.selectedKeys();
469
+ !this.disallowEmptySelection() && e.size > 0 && this.state.setSelectedKeys(new b());
470
+ }
471
+ /**
472
+ * Toggles between select all and an empty selection.
473
+ */
474
+ toggleSelectAll() {
475
+ this.isSelectAll() ? this.clearSelection() : this.selectAll();
476
+ }
477
+ select(e, t) {
478
+ this.selectionMode() !== "none" && (this.selectionMode() === "single" ? this.isSelected(e) && !this.disallowEmptySelection() ? this.toggleSelection(e) : this.replaceSelection(e) : this.selectionBehavior() === "toggle" || t && t.pointerType === "touch" ? this.toggleSelection(e) : this.replaceSelection(e));
479
+ }
480
+ /** Returns whether the current selection is equal to the given selection. */
481
+ isSelectionEqual(e) {
482
+ if (e === this.state.selectedKeys())
483
+ return !0;
484
+ const t = this.selectedKeys();
485
+ if (e.size !== t.size)
486
+ return !1;
487
+ for (const s of e)
488
+ if (!t.has(s))
489
+ return !1;
490
+ for (const s of t)
491
+ if (!e.has(s))
492
+ return !1;
493
+ return !0;
494
+ }
495
+ canSelectItem(e) {
496
+ if (this.state.selectionMode() === "none")
497
+ return !1;
498
+ const t = this.collection().getItem(e);
499
+ return t != null && !t.disabled;
500
+ }
501
+ isDisabled(e) {
502
+ const t = this.collection().getItem(e);
503
+ return !t || t.disabled;
504
+ }
505
+ getAllSelectableKeys() {
506
+ const e = [];
507
+ return ((s) => {
508
+ for (; s != null; ) {
509
+ if (this.canSelectItem(s)) {
510
+ const n = this.collection().getItem(s);
511
+ if (!n)
512
+ continue;
513
+ n.type === "item" && e.push(s);
898
514
  }
899
- }, n));
900
- }
901
- });
515
+ s = this.collection().getKeyAfter(s);
516
+ }
517
+ })(this.collection().getFirstKey()), e;
518
+ }
519
+ }, z = class {
520
+ keyMap = /* @__PURE__ */ new Map();
521
+ iterable;
522
+ firstKey;
523
+ lastKey;
524
+ constructor(e) {
525
+ this.iterable = e;
526
+ for (const n of e)
527
+ this.keyMap.set(n.key, n);
528
+ if (this.keyMap.size === 0)
529
+ return;
530
+ let t, s = 0;
531
+ for (const [n, c] of this.keyMap)
532
+ t ? (t.nextKey = n, c.prevKey = t.key) : (this.firstKey = n, c.prevKey = void 0), c.type === "item" && (c.index = s++), t = c, t.nextKey = void 0;
533
+ this.lastKey = t.key;
534
+ }
535
+ *[Symbol.iterator]() {
536
+ yield* this.iterable;
537
+ }
538
+ getSize() {
539
+ return this.keyMap.size;
540
+ }
541
+ getKeys() {
542
+ return this.keyMap.keys();
543
+ }
544
+ getKeyBefore(e) {
545
+ return this.keyMap.get(e)?.prevKey;
546
+ }
547
+ getKeyAfter(e) {
548
+ return this.keyMap.get(e)?.nextKey;
549
+ }
550
+ getFirstKey() {
551
+ return this.firstKey;
552
+ }
553
+ getLastKey() {
554
+ return this.lastKey;
555
+ }
556
+ getItem(e) {
557
+ return this.keyMap.get(e);
558
+ }
559
+ at(e) {
560
+ const t = [...this.getKeys()];
561
+ return this.getItem(t[e]);
562
+ }
563
+ };
564
+ function ge(e) {
565
+ const t = ee(e), n = U({
566
+ dataSource: () => o(e.dataSource),
567
+ getKey: () => o(e.getKey),
568
+ getTextValue: () => o(e.getTextValue),
569
+ getDisabled: () => o(e.getDisabled),
570
+ getSectionChildren: () => o(e.getSectionChildren),
571
+ factory: (f) => e.filter ? new z(e.filter(f)) : new z(f)
572
+ }, [() => e.filter]), c = new ie(n, t);
573
+ return G(() => {
574
+ const f = t.focusedKey();
575
+ f != null && !n().getItem(f) && t.setFocusedKey(void 0);
576
+ }), {
577
+ collection: n,
578
+ selectionManager: () => c
579
+ };
902
580
  }
903
581
  export {
904
- Rt as MenuCheckboxItem,
905
- Et as MenuContent,
906
- rt as MenuGroup,
907
- Lt as MenuGroupLabel,
908
- Gt as MenuIcon,
909
- Ut as MenuItem,
910
- Vt as MenuItemDescription,
911
- Nt as MenuItemIndicator,
912
- _t as MenuItemLabel,
913
- zt as MenuPortal,
914
- $t as MenuRadioGroup,
915
- Bt as MenuRadioItem,
916
- Wt as MenuRoot,
917
- Xt as MenuSub,
918
- Yt as MenuSubContent,
919
- Ht as MenuSubTrigger,
920
- At as MenuTrigger,
921
- tt as MenubarContext,
922
- nt as NavigationMenuContext,
923
- L as useMenuContext,
924
- E as useMenuRootContext,
925
- Ce as useOptionalMenuContext
582
+ z as ListCollection,
583
+ b as Selection,
584
+ ie as SelectionManager,
585
+ ge as createListState,
586
+ ee as createMultipleSelectionState,
587
+ de as createSelectableCollection,
588
+ ye as createSelectableItem,
589
+ te as createTypeSelect,
590
+ Y as isSameSelection
926
591
  };
927
592
  //# sourceMappingURL=index310.js.map