react-animated-select 0.6.6 → 0.7.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.
package/dist/index.es.js CHANGED
@@ -1,1712 +1,1096 @@
1
- import ft, { createContext as gt, forwardRef as pt, useRef as re, useImperativeHandle as ht, useEffect as pe, useCallback as R, memo as Xe, useLayoutEffect as We, Fragment as mt, useState as oe, useMemo as ve, useId as yt, isValidElement as jt, cloneElement as St, useContext as Qe } from "react";
2
- import { CSSTransition as Ke, TransitionGroup as st } from "react-transition-group";
3
- import { createPortal as $t } from "react-dom";
4
- import './index.css';var Be = { exports: {} }, Ye = {};
5
- var it;
6
- function Nt() {
7
- if (it) return Ye;
8
- it = 1;
9
- var e = /* @__PURE__ */ Symbol.for("react.transitional.element"), r = /* @__PURE__ */ Symbol.for("react.fragment");
10
- function n(l, a, x) {
11
- var y = null;
12
- if (x !== void 0 && (y = "" + x), a.key !== void 0 && (y = "" + a.key), "key" in a) {
13
- x = {};
14
- for (var f in a)
15
- f !== "key" && (x[f] = a[f]);
16
- } else x = a;
17
- return a = x.ref, {
18
- $$typeof: e,
19
- type: l,
20
- key: y,
21
- ref: a !== void 0 ? a : null,
22
- props: x
23
- };
24
- }
25
- return Ye.Fragment = r, Ye.jsx = n, Ye.jsxs = n, Ye;
26
- }
27
- var De = {};
28
- var ot;
29
- function Rt() {
30
- return ot || (ot = 1, process.env.NODE_ENV !== "production" && (function() {
31
- function e(t) {
32
- if (t == null) return null;
33
- if (typeof t == "function")
34
- return t.$$typeof === ue ? null : t.displayName || t.name || null;
35
- if (typeof t == "string") return t;
36
- switch (t) {
37
- case T:
38
- return "Fragment";
39
- case P:
40
- return "Profiler";
41
- case C:
42
- return "StrictMode";
43
- case Q:
44
- return "Suspense";
45
- case D:
46
- return "SuspenseList";
47
- case G:
48
- return "Activity";
49
- }
50
- if (typeof t == "object")
51
- switch (typeof t.tag == "number" && console.error(
52
- "Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."
53
- ), t.$$typeof) {
54
- case A:
55
- return "Portal";
56
- case F:
57
- return t.displayName || "Context";
58
- case I:
59
- return (t._context.displayName || "Context") + ".Consumer";
60
- case Z:
61
- var i = t.render;
62
- return t = t.displayName, t || (t = i.displayName || i.name || "", t = t !== "" ? "ForwardRef(" + t + ")" : "ForwardRef"), t;
63
- case U:
64
- return i = t.displayName || null, i !== null ? i : e(t.type) || "Memo";
65
- case c:
66
- i = t._payload, t = t._init;
67
- try {
68
- return e(t(i));
69
- } catch {
70
- }
71
- }
72
- return null;
73
- }
74
- function r(t) {
75
- return "" + t;
76
- }
77
- function n(t) {
78
- try {
79
- r(t);
80
- var i = !1;
81
- } catch {
82
- i = !0;
83
- }
84
- if (i) {
85
- i = console;
86
- var h = i.error, v = typeof Symbol == "function" && Symbol.toStringTag && t[Symbol.toStringTag] || t.constructor.name || "Object";
87
- return h.call(
88
- i,
89
- "The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",
90
- v
91
- ), r(t);
92
- }
1
+ "use client";
2
+ import { jsx as O, jsxs as q } from "react/jsx-runtime";
3
+ import { createContext as we, useState as U, useRef as F, useInsertionEffect as yt, isValidElement as xe, cloneElement as bt, useMemo as _, useLayoutEffect as ne, useEffect as oe, useCallback as K, useContext as B, useEffectEvent as ot, Children as it, useSyncExternalStore as re, memo as se, Fragment as at, Component as vt, useId as wt, useImperativeHandle as xt, useReducer as Ot } from "react";
4
+ import { flushSync as St, createPortal as Et } from "react-dom";
5
+ import './index.css';const Y = we(null), ce = we(null), de = we(null), kt = (e, t) => {
6
+ const n = typeof t == "function" ? t(e) : t;
7
+ return n === e ? e : Object.keys(n).some((s) => !Object.is(n[s], e[s])) ? { ...e, ...n } : e;
8
+ }, Me = (e) => {
9
+ let t = e;
10
+ const n = /* @__PURE__ */ new Set();
11
+ return {
12
+ get: () => t,
13
+ set: (r) => {
14
+ Object.keys(r).every((s) => Object.is(r[s], t[s])) || (t = { ...t, ...r }, n.forEach((s) => s()));
15
+ },
16
+ subscribe: (r) => (n.add(r), () => n.delete(r))
17
+ };
18
+ }, Re = (e) => {
19
+ const t = F(e);
20
+ yt(() => {
21
+ t.current = e;
22
+ });
23
+ const [n] = U(() => Object.fromEntries(
24
+ Object.keys(e).map((r) => [r, (...s) => t.current[r](...s)])
25
+ ));
26
+ return n;
27
+ }, lt = (e, t) => {
28
+ const [n, r] = U(e);
29
+ return n === e || t(n, e) ? n : (r(e), e);
30
+ }, Ct = (e, t) => e === t || !!e && !!t && Object.keys(e).length === Object.keys(t).length && Object.keys(e).every((n) => Object.is(e[n], t[n])), Ie = (e, t, n = 0) => {
31
+ if (Object.is(e, t)) return !0;
32
+ if (n > 12 || typeof e != "object" || typeof t != "object" || e === null || t === null || Array.isArray(e) !== Array.isArray(t)) return !1;
33
+ if (e.$$typeof || t.$$typeof) return e.$$typeof === t.$$typeof && e.type === t.type && e.key === t.key && Ie(e.props, t.props, n + 1);
34
+ const r = Object.keys(e);
35
+ return r.length === Object.keys(t).length && r.every((s) => Object.hasOwn(t, s) && Ie(e[s], t[s], n + 1));
36
+ }, Tt = /* @__PURE__ */ new Set(["style", "texts", "icons", "attrs"]), Mt = (e, t) => {
37
+ const n = Object.keys(t);
38
+ return n.length === Object.keys(e).length && n.every(
39
+ (r) => Tt.has(r) ? Ct(e[r], t[r]) : Object.is(e[r], t[r])
40
+ );
41
+ }, It = (e) => lt(e, Mt), Ne = (e) => lt(e, Ie), he = {
42
+ XMark: ({ className: e = "", ...t }) => /* @__PURE__ */ O(
43
+ "svg",
44
+ {
45
+ className: e,
46
+ viewBox: "0 0 320 512",
47
+ fill: "currentColor",
48
+ "aria-hidden": "true",
49
+ height: "1em",
50
+ width: "1em",
51
+ ...t,
52
+ children: /* @__PURE__ */ O("path", { d: "M310.6 361.4c12.5 12.5 12.5 32.8 0 45.3s-32.8 12.5-45.3 0L160 301.3 54.6 406.6c-12.5 12.5-32.8 12.5-45.3 0s-12.5-32.8 0-45.3L114.7 256 9.4 150.6c-12.5-12.5-12.5-32.8 0-45.3s32.8-12.5 45.3 0L160 210.7 265.4 105.4c12.5-12.5 32.8-12.5 45.3 0s12.5 32.8 0 45.3L205.3 256l105.3 105.4z" })
93
53
  }
94
- function l(t) {
95
- if (t === T) return "<>";
96
- if (typeof t == "object" && t !== null && t.$$typeof === c)
97
- return "<...>";
98
- try {
99
- var i = e(t);
100
- return i ? "<" + i + ">" : "<...>";
101
- } catch {
102
- return "<...>";
103
- }
54
+ ),
55
+ ArrowUp: ({ className: e = "", ...t }) => /* @__PURE__ */ O(
56
+ "svg",
57
+ {
58
+ className: e,
59
+ viewBox: "0 0 448 512",
60
+ fill: "currentColor",
61
+ "aria-hidden": "true",
62
+ height: "1em",
63
+ width: "1em",
64
+ ...t,
65
+ children: /* @__PURE__ */ O("path", { d: "M34.9 289.5l175.9-175.8c9.4-9.4 24.6-9.4 33.9 0L420.1 289.5c15.1 15.1 4.4 41-17 41H51.9c-21.4 0-32.1-25.9-17-41z" })
104
66
  }
105
- function a() {
106
- var t = M.A;
107
- return t === null ? null : t.getOwner();
67
+ ),
68
+ Checkmark: ({ className: e = "", ...t }) => /* @__PURE__ */ O(
69
+ "svg",
70
+ {
71
+ className: e,
72
+ viewBox: "0 0 24 24",
73
+ fill: "currentColor",
74
+ "aria-hidden": "true",
75
+ height: "1em",
76
+ width: "1em",
77
+ ...t,
78
+ children: /* @__PURE__ */ O("path", { d: "M20.285 6.708a1 1 0 0 0-1.414-1.416l-9.192 9.192-4.243-4.244a1 1 0 1 0-1.414 1.416l5 5a1 1 0 0 0 1.414 0l9.849-9.948z" })
108
79
  }
109
- function x() {
110
- return Error("react-stack-top-frame");
80
+ )
81
+ }, ae = (e, t) => {
82
+ if (!e) return null;
83
+ const n = (r = {}) => ({
84
+ ...t,
85
+ ...r,
86
+ style: {
87
+ ...t?.style,
88
+ ...r?.style
111
89
  }
112
- function y(t) {
113
- if (V.call(t, "key")) {
114
- var i = Object.getOwnPropertyDescriptor(t, "key").get;
115
- if (i && i.isReactWarning) return !1;
90
+ });
91
+ return typeof e == "string" ? /* @__PURE__ */ O("img", { src: e, ...n(), className: ue("rac-icon", t?.className), alt: "" }) : xe(e) ? bt(e, n(e.props)) : typeof e == "function" || typeof e == "object" && e.$$typeof ? /* @__PURE__ */ O(e, { ...n() }) : null;
92
+ }, Oe = (e, t) => `${e}-${String(t).replace(/[^A-Za-z0-9-]/gu, (n) => `_${n.codePointAt(0).toString(36)}_`)}`, X = (e) => e ? "" : void 0, ue = (e, t) => t ? `${e} ${t}` : e, Ve = (e, t, n) => e.jsx || (t && "original" in e ? t(e.original, { selected: n, disabled: !!e.disabled }) : null), Be = /* @__PURE__ */ q("span", { className: "rac-dots", "aria-hidden": "true", children: [
93
+ /* @__PURE__ */ O("i", {}),
94
+ /* @__PURE__ */ O("i", {}),
95
+ /* @__PURE__ */ O("i", {})
96
+ ] }), Nt = (() => {
97
+ try {
98
+ return process.env.NODE_ENV !== "production";
99
+ } catch {
100
+ return !1;
101
+ }
102
+ })(), ze = /* @__PURE__ */ new Set(), le = (e, t) => {
103
+ !Nt || ze.has(e) || (ze.add(e), console.warn(`[react-animated-select] ${t}`));
104
+ }, Q = (e) => {
105
+ e?.stopPropagation(), e?.preventDefault();
106
+ }, At = { index: -1, fallback: -1, ready: !1 }, ye = ({ index: e, fallback: t }) => e === -1 ? t : e, $t = 10, Lt = 500, Dt = /* @__PURE__ */ new Set(["ArrowDown", "ArrowUp", "PageDown", "PageUp", "Home", "End"]), jt = (e, t) => _(() => {
107
+ const n = new Set(e.map((s) => s.group).filter(Boolean)), r = (s) => !!s && !s.disabled && !s.loading && (s.groupHeader ? n.has(s.name) : !s.group || t.has(s.group));
108
+ return { reach: r, list: e.flatMap((s, c) => r(s) ? [c] : []) };
109
+ }, [e, t]), Pt = (e, t, n, r) => {
110
+ const s = e.length - 1;
111
+ if (s < 0) return -1;
112
+ if (n === "Home") return e[0];
113
+ if (n === "End") return e[s];
114
+ const c = n === "ArrowUp" || n === "PageUp" ? -1 : 1, i = e.indexOf(t);
115
+ if (i === -1) return e[c > 0 ? 0 : s];
116
+ const a = i + c * (n.startsWith("Page") ? $t : 1);
117
+ return a >= 0 && a <= s ? e[a] : n.startsWith("Page") || r ? e[a < 0 ? 0 : s] : e[(a + e.length) % e.length];
118
+ }, Rt = (e, t, n, r) => {
119
+ const s = [...r].every((o) => o === r[0]), c = s ? r[0] : r, i = t.filter((o) => "original" in e[o]), a = Math.max(i.indexOf(n) + (s ? 1 : 0), 0);
120
+ for (let o = 0; o < i.length; o++) {
121
+ const p = i[(a + o) % i.length];
122
+ if (String(e[p].name).toLowerCase().startsWith(c)) return p;
123
+ }
124
+ return -1;
125
+ };
126
+ function Vt({ props: e, state: t, setState: n, normalizedOptions: r, expandedGroups: s, selected: c, selectedIDs: i, visibility: a, setVisibility: o, modelActions: p, loadMoreOnce: l, highlightStore: g }) {
127
+ const { disabled: y, multiple: h, hasMore: S, loadButton: w, loadOffset: f, loadAhead: m, icons: D, onFocus: L, onBlur: C } = e, { selectOption: j, clear: M, removeOption: u } = p, { deleting: x } = t, { reach: E, list: $ } = jt(r, s), k = F({ lastWindowFocusTime: 0, justFocused: !1, focusTimeout: null, query: "", queryTimeout: null }), V = _(() => {
128
+ const d = new Set(h ? i.map((T) => T.id) : c ? [c.id] : []), v = d.size ? r.findIndex((T) => d.has(T.id) && E(T)) : -1;
129
+ return v !== -1 ? v : $.find((T) => !r[T].groupHeader) ?? $[0] ?? -1;
130
+ }, [r, c, i, h, E, $]), I = (d) => {
131
+ !w && a && S && d >= r.length - m && l();
132
+ };
133
+ ne(() => {
134
+ const { index: d } = g.get();
135
+ g.set({ fallback: V, index: d !== -1 && E(r[d]) ? d : -1 }), I(ye(g.get()));
136
+ }), oe(() => {
137
+ const d = k.current, v = () => d.lastWindowFocusTime = Date.now();
138
+ return window.addEventListener("focus", v), () => {
139
+ window.removeEventListener("focus", v), clearTimeout(d.focusTimeout), clearTimeout(d.queryTimeout);
140
+ };
141
+ }, []);
142
+ const A = (d) => {
143
+ g.set({ index: d }), I(d);
144
+ }, b = (d, v) => {
145
+ const T = k.current;
146
+ clearTimeout(T.queryTimeout), T.queryTimeout = setTimeout(() => T.query = "", Lt), T.query += d.toLowerCase();
147
+ const H = Rt(r, $, v, T.query);
148
+ H !== -1 && A(H), a || o(!0);
149
+ };
150
+ return Re({
151
+ highlight: A,
152
+ handleListScroll: (d) => {
153
+ if (w) return;
154
+ const { scrollTop: v, scrollHeight: T, clientHeight: H } = d.currentTarget;
155
+ T - v <= H + f && l();
156
+ },
157
+ handleBlur: (d) => {
158
+ const v = d.relatedTarget?.closest(".rac-options");
159
+ d.currentTarget.contains(d.relatedTarget) || v || (C?.(d), x && n({ deleting: !1 }), a && o(!1));
160
+ },
161
+ // [DOC: select-behavior]
162
+ handleFocus: (d) => {
163
+ d.currentTarget.contains(d.relatedTarget) || L?.(d), !(y || x || document.hidden || Date.now() - k.current.lastWindowFocusTime < 100) && (a || (clearTimeout(k.current.focusTimeout), k.current.focusTimeout = setTimeout(() => k.current.justFocused = !1, 200), k.current.justFocused = !0, o(!0)));
164
+ },
165
+ toggleVisibility: (d) => {
166
+ if (x) {
167
+ Q(d), n({ deleting: !1 });
168
+ return;
116
169
  }
117
- return t.key !== void 0;
118
- }
119
- function f(t, i) {
120
- function h() {
121
- ne || (ne = !0, console.error(
122
- "%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",
123
- i
124
- ));
170
+ y || k.current.justFocused || o(!a);
171
+ },
172
+ handleKeyDown: (d) => {
173
+ if (y || d.nativeEvent?.isComposing) return;
174
+ const { key: v } = d, T = ye(g.get());
175
+ if (v.length === 1 && !d.ctrlKey && !d.metaKey && !d.altKey && (v !== " " || k.current.query)) {
176
+ d.preventDefault(), b(v, T);
177
+ return;
125
178
  }
126
- h.isReactWarning = !0, Object.defineProperty(t, "key", {
127
- get: h,
128
- configurable: !0
129
- });
130
- }
131
- function j() {
132
- var t = e(this.type);
133
- return L[t] || (L[t] = !0, console.error(
134
- "Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release."
135
- )), t = this.props.ref, t !== void 0 ? t : null;
136
- }
137
- function s(t, i, h, v, de, o) {
138
- var m = h.ref;
139
- return t = {
140
- $$typeof: _,
141
- type: t,
142
- key: i,
143
- props: h,
144
- _owner: v
145
- }, (m !== void 0 ? m : null) !== null ? Object.defineProperty(t, "ref", {
146
- enumerable: !1,
147
- get: j
148
- }) : Object.defineProperty(t, "ref", { enumerable: !1, value: null }), t._store = {}, Object.defineProperty(t._store, "validated", {
149
- configurable: !1,
150
- enumerable: !1,
151
- writable: !0,
152
- value: 0
153
- }), Object.defineProperty(t, "_debugInfo", {
154
- configurable: !1,
155
- enumerable: !1,
156
- writable: !0,
157
- value: null
158
- }), Object.defineProperty(t, "_debugStack", {
159
- configurable: !1,
160
- enumerable: !1,
161
- writable: !0,
162
- value: de
163
- }), Object.defineProperty(t, "_debugTask", {
164
- configurable: !1,
165
- enumerable: !1,
166
- writable: !0,
167
- value: o
168
- }), Object.freeze && (Object.freeze(t.props), Object.freeze(t)), t;
169
- }
170
- function E(t, i, h, v, de, o) {
171
- var m = i.children;
172
- if (m !== void 0)
173
- if (v)
174
- if (he(m)) {
175
- for (v = 0; v < m.length; v++)
176
- S(m[v]);
177
- Object.freeze && Object.freeze(m);
178
- } else
179
- console.error(
180
- "React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead."
181
- );
182
- else S(m);
183
- if (V.call(i, "key")) {
184
- m = e(t);
185
- var g = Object.keys(i).filter(function(k) {
186
- return k !== "key";
187
- });
188
- v = 0 < g.length ? "{key: someKey, " + g.join(": ..., ") + ": ...}" : "{key: someKey}", W[m + v] || (g = 0 < g.length ? "{" + g.join(": ..., ") + ": ...}" : "{}", console.error(
189
- `A props object containing a "key" prop is being spread into JSX:
190
- let props = %s;
191
- <%s {...props} />
192
- React keys must be passed directly to JSX without using spread:
193
- let props = %s;
194
- <%s key={someKey} {...props} />`,
195
- v,
196
- m,
197
- g,
198
- m
199
- ), W[m + v] = !0);
179
+ if (Dt.has(v)) {
180
+ d.preventDefault(), (a || v === "Home" || v === "End") && A(Pt($, T, v, !w && S)), a || o(!0);
181
+ return;
182
+ }
183
+ switch (v) {
184
+ case "Enter":
185
+ case " ":
186
+ d.preventDefault(), a ? T !== -1 && r[T] && (A(T), j(r[T], d)) : o(!0);
187
+ break;
188
+ // [DOC: select-behavior]
189
+ case "Escape":
190
+ if (x) n({ deleting: !1 });
191
+ else if (a) o(!1);
192
+ else break;
193
+ Q(d);
194
+ break;
195
+ case "Tab":
196
+ a && o(!1);
197
+ break;
198
+ // [DOC: select-behavior]
199
+ case "Backspace":
200
+ case "Delete": {
201
+ const H = i.at(-1);
202
+ if (h && v === "Backspace" && D.remove && H) u(H.id);
203
+ else if (D.clear && (c || H)) M();
204
+ else break;
205
+ d.preventDefault();
206
+ break;
207
+ }
200
208
  }
201
- if (m = null, h !== void 0 && (n(h), m = "" + h), y(i) && (n(i.key), m = "" + i.key), "key" in i) {
202
- h = {};
203
- for (var N in i)
204
- N !== "key" && (h[N] = i[N]);
205
- } else h = i;
206
- return m && f(
207
- h,
208
- typeof t == "function" ? t.displayName || t.name || "Unknown" : t
209
- ), s(
210
- t,
211
- m,
212
- h,
213
- a(),
214
- de,
215
- o
216
- );
217
209
  }
218
- function S(t) {
219
- u(t) ? t._store && (t._store.validated = 1) : typeof t == "object" && t !== null && t.$$typeof === c && (t._payload.status === "fulfilled" ? u(t._payload.value) && t._payload.value._store && (t._payload.value._store.validated = 1) : t._store && (t._store.validated = 1));
210
+ });
211
+ }
212
+ const Bt = ["group", "disabled", "options", "items", "children"], He = ["name", "label", "id", "value"], ge = (e) => e != null && e !== "", ct = (e) => e !== null && typeof e == "object" && !Array.isArray(e), Se = (e) => ct(e) && [Object.prototype, null].includes(Object.getPrototypeOf(e)), Ht = (e) => {
213
+ try {
214
+ const t = String(e);
215
+ return t.startsWith("[object ") ? null : t;
216
+ } catch {
217
+ return null;
218
+ }
219
+ }, Fe = (e, t = !1) => {
220
+ if (t && typeof e.group == "string") return e.group;
221
+ const n = He.find((c) => ge(e[c]));
222
+ if (n) return String(e[n]);
223
+ const r = !Se(e) && Ht(e);
224
+ if (r) return r;
225
+ const s = Object.entries(e).find(([c, i]) => !Bt.includes(c) && ge(i));
226
+ return s ? String(s[1]) : null;
227
+ }, Ft = (e) => Se(e) && ("options" in e || "group" in e && !He.some((t) => t in e)), Ke = (e, t, n, r, s, { emptyOption: c, invalidOption: i, disabledOption: a }) => {
228
+ const o = `${n}-${t}`;
229
+ if (e == null || e === "")
230
+ return { id: o, userId: null, name: c, raw: e, disabled: !0, type: "normal", group: r, groupDisabled: s };
231
+ if (typeof e == "function")
232
+ return { id: o, userId: null, name: i, raw: e, disabled: !0, invalid: !0, type: "normal", group: r };
233
+ if (ct(e)) {
234
+ const p = s || e.disabled === !0, l = e.value !== void 0 ? e.value : e.id !== void 0 ? e.id : e, g = Fe(e) || (p ? a : c);
235
+ return {
236
+ id: o,
237
+ userId: e.id ?? e.value ?? e.name ?? e.label,
238
+ name: g,
239
+ raw: l,
240
+ original: e,
241
+ disabled: p || g === c,
242
+ type: typeof l == "boolean" ? "boolean" : "normal",
243
+ group: r || e.group || null,
244
+ groupDisabled: s
245
+ };
246
+ }
247
+ return { id: o, userId: e, name: String(e), raw: e, original: e, disabled: s, type: typeof e == "boolean" ? "boolean" : "normal", group: r };
248
+ }, Gt = ({
249
+ options: e,
250
+ jsxOptions: t,
251
+ childrenFirst: n,
252
+ hasMore: r,
253
+ loadButton: s,
254
+ loadPending: c,
255
+ loadingTitle: i,
256
+ emptyOption: a,
257
+ invalidOption: o,
258
+ disabledOption: p,
259
+ emptyGroup: l
260
+ }) => {
261
+ const g = { emptyOption: a, invalidOption: o, disabledOption: p }, y = /* @__PURE__ */ new Map(), h = [], S = /* @__PURE__ */ new Set(), w = (u) => {
262
+ let x = u;
263
+ for (let E = 1; S.has(x); E++) x = `${u}~${E}`;
264
+ return S.add(x), x;
265
+ }, f = t.map((u, x) => {
266
+ if (u.isGroupMarker) return { ...u, type: "group-marker" };
267
+ const E = !u.label && !ge(u.userId) && !ge(u.value) && !u.hasJsx;
268
+ return {
269
+ ...u,
270
+ id: w(`jsx-${u.id}`),
271
+ index: x,
272
+ userId: u.userId,
273
+ raw: u.value,
274
+ original: u.value,
275
+ name: u.label || (ge(u.value) ? String(u.value) : a),
276
+ disabled: !!u.disabled || E,
277
+ type: typeof u.value == "boolean" ? "boolean" : "normal",
278
+ group: u.group || null
279
+ };
280
+ });
281
+ let m = 0;
282
+ const D = (u, x = null, E = !1, $ = "0") => {
283
+ Array.isArray(u) || (u = [u]), u.forEach((k, V) => {
284
+ const I = `${$}-${V}`;
285
+ if (Ft(k)) {
286
+ const A = Fe(k, !0) || l;
287
+ y.has(A) || y.set(A, { disabled: !!k.disabled, items: [] }), k.options ? D(k.options, A, E || !!k.disabled, I) : h.push({ id: `empty-${A}-${I}`, name: A, group: A, isPlaceholder: !0, type: "group-marker", index: m++ });
288
+ } else Se(k) && !He.some((A) => A in k) && !k.group ? Object.values(k).forEach((A, b) => h.push({ ...Ke(A, `${I}-${b}`, "default", x, E, g), index: m++ })) : h.push({ ...Ke(k, I, "default", x, E, g), index: m++ });
289
+ });
290
+ };
291
+ D(e);
292
+ const L = n ? [...f, ...h] : [...h, ...f], C = [], j = /* @__PURE__ */ new Set();
293
+ L.forEach((u) => {
294
+ if (!u.group) {
295
+ C.push({ type: "item", data: u });
296
+ return;
220
297
  }
221
- function u(t) {
222
- return typeof t == "object" && t !== null && t.$$typeof === _;
298
+ j.has(u.group) || (j.add(u.group), C.push({ type: "group", name: u.group })), y.has(u.group) || y.set(u.group, { items: [] });
299
+ const x = y.get(u.group);
300
+ u.isGroupMarker ? (x.className = u.className, x.style = u.style, u.disabled && (x.disabled = !0)) : u.isPlaceholder || x.items.push(u);
301
+ });
302
+ const M = [];
303
+ return C.forEach((u) => {
304
+ if (u.type === "item") {
305
+ M.push(u.data);
306
+ return;
223
307
  }
224
- var $ = ft, _ = /* @__PURE__ */ Symbol.for("react.transitional.element"), A = /* @__PURE__ */ Symbol.for("react.portal"), T = /* @__PURE__ */ Symbol.for("react.fragment"), C = /* @__PURE__ */ Symbol.for("react.strict_mode"), P = /* @__PURE__ */ Symbol.for("react.profiler"), I = /* @__PURE__ */ Symbol.for("react.consumer"), F = /* @__PURE__ */ Symbol.for("react.context"), Z = /* @__PURE__ */ Symbol.for("react.forward_ref"), Q = /* @__PURE__ */ Symbol.for("react.suspense"), D = /* @__PURE__ */ Symbol.for("react.suspense_list"), U = /* @__PURE__ */ Symbol.for("react.memo"), c = /* @__PURE__ */ Symbol.for("react.lazy"), G = /* @__PURE__ */ Symbol.for("react.activity"), ue = /* @__PURE__ */ Symbol.for("react.client.reference"), M = $.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, V = Object.prototype.hasOwnProperty, he = Array.isArray, q = console.createTask ? console.createTask : function() {
225
- return null;
308
+ const x = y.get(u.name);
309
+ M.push({
310
+ className: x?.className || "",
311
+ id: `group-header-${u.name}`,
312
+ disabled: !!x?.disabled,
313
+ style: x?.style || {},
314
+ groupHeader: !0,
315
+ name: u.name,
316
+ type: "group"
317
+ }), x?.items.forEach((E) => M.push(E));
318
+ }), r && s && M.push({ id: "special-load-more-id", name: i, loadMore: !0, loading: c, type: "special" }), M;
319
+ }, Rn = (e) => {
320
+ const t = () => null;
321
+ return t.racKind = "define", t.racRender = e, t.displayName = `defineOption(${e.name || "anonymous"})`, t;
322
+ }, qe = { selected: null, selectedIDs: [] }, fe = (e) => {
323
+ try {
324
+ return JSON.stringify(e);
325
+ } catch {
326
+ return;
327
+ }
328
+ }, dt = (e, t) => e === t || e !== e && t !== t, be = (e) => typeof e == "object" && e !== null, Wt = (e, t) => dt(e, t) || be(e) && be(t) && fe(e) !== void 0 && fe(e) === fe(t), zt = (e, t, n, r) => {
329
+ if (e == null || Array.isArray(e) && e.length === 0) return qe;
330
+ const s = r.length ? new Map(t.map((l) => [l.id, l])) : null, c = s ? [...r.map((l) => s.get(l)).filter(Boolean), ...t] : t, i = /* @__PURE__ */ new Set(), a = /* @__PURE__ */ new Map(), o = (l) => "original" in l && !i.has(l.id), p = (l) => {
331
+ const g = be(l);
332
+ let y = c.find((m) => o(m) && dt(m.original, l));
333
+ const h = g ? fe(l) : void 0;
334
+ if (!y && h !== void 0 && (y = c.find((m) => o(m) && be(m.original) && fe(m.original) === h)), y)
335
+ return i.add(y.id), y;
336
+ const S = String(g ? l.id || l.value || h || "object" : l), w = (a.get(S) ?? -1) + 1;
337
+ a.set(S, w);
338
+ const f = `virtual-${S}-${w}`;
339
+ return g ? { id: f, name: Fe(l) || String(l.id || "Selected Object"), raw: l.value ?? l.id ?? l, original: l, userId: l.id ?? l.value ?? null, virtual: !0 } : { id: f, name: String(l), raw: l, original: l, userId: l, virtual: !0 };
340
+ };
341
+ return n ? { selected: null, selectedIDs: (Array.isArray(e) ? e : [e]).map(p) } : { selected: p(Array.isArray(e) ? e[0] : e), selectedIDs: qe.selectedIDs };
342
+ }, _e = {
343
+ x: ["width", "marginLeft", "marginRight", "paddingLeft", "paddingRight", "borderLeftWidth", "borderRightWidth"],
344
+ y: ["height", "marginTop", "marginBottom", "paddingTop", "paddingBottom", "borderTopWidth", "borderBottomWidth"]
345
+ }, Kt = { x: { minWidth: "0px", maxWidth: "none" }, y: { minHeight: "0px", maxHeight: "none" } }, ut = we(null);
346
+ let Ae = null;
347
+ const qt = () => Ae ??= (queueMicrotask(() => {
348
+ Ae = null;
349
+ }), {});
350
+ function ie({
351
+ as: e = "div",
352
+ axis: t = "y",
353
+ fade: n = !1,
354
+ in: r,
355
+ unmountOnExit: s = !0,
356
+ easing: c,
357
+ duration: i,
358
+ group: a,
359
+ nodeRef: o,
360
+ onEntered: p,
361
+ onExited: l,
362
+ ...g
363
+ }) {
364
+ const y = B(Y), h = B(ut), S = r === void 0 && !!h, w = S ? h.present : !!r, f = i ?? y?.duration ?? 300, m = c ?? y?.easing ?? "ease", D = F(null), L = o ?? D, C = F(null), j = F(!1), M = F({ restart: () => {
365
+ } }), [u] = U(() => S && h.appear ? !w : w), x = F(u), [E, $] = U(!w);
366
+ w && E && $(!1);
367
+ const k = ot(() => {
368
+ if (a?.delete(M.current), w) {
369
+ C.current = null, p?.();
370
+ return;
371
+ }
372
+ l?.(), S && h.onExited(), s && (C.current = null, $(!0));
373
+ });
374
+ return ne(() => {
375
+ const I = L.current;
376
+ if (!I) return;
377
+ const A = n ? [..._e[t], "opacity"] : _e[t], b = { overflow: "hidden", textOverflow: "clip", ...Kt[t] }, d = { ...Object.fromEntries(A.map((P) => [P, P === "opacity" ? 0 : "0px"])), ...b }, v = () => {
378
+ const P = getComputedStyle(I);
379
+ return { ...Object.fromEntries(A.map((G) => [G, P[G]])), ...b };
380
+ }, T = (P, G) => {
381
+ const ee = window.matchMedia?.("(prefers-reduced-motion: reduce)").matches, z = C.current = I.animate([P, G], { duration: ee ? 0 : f, easing: m, fill: x.current ? "backwards" : "both" });
382
+ if (z.onfinish = () => {
383
+ C.current === z && j.current && k();
384
+ }, M.current.frames = [P, G], !a) return;
385
+ const R = z.timeline?.currentTime;
386
+ R != null && (z.startTime = R, z.currentTime = 0), M.current.batch = qt(), a.add(M.current);
387
+ }, H = () => {
388
+ const [P, G] = M.current.frames, ee = C.current.effect.getComputedTiming().progress ?? 0, z = (R) => parseFloat(P[R]) + (parseFloat(G[R]) - parseFloat(P[R])) * ee;
389
+ return { ...Object.fromEntries(A.map((R) => [R, R === "opacity" ? z(R) : `${z(R)}px`])), ...b };
226
390
  };
227
- $ = {
228
- react_stack_bottom_frame: function(t) {
229
- return t();
391
+ if (M.current.restart = (P) => {
392
+ const G = C.current;
393
+ if (G?.playState !== "running" || !P && M.current.batch === Ae) return;
394
+ const ee = H();
395
+ G.cancel(), T(ee, x.current ? v() : d);
396
+ }, x.current === w) {
397
+ !w && !C.current && I.animate && (C.current = I.animate([d, d], { fill: "forwards" }));
398
+ return;
399
+ }
400
+ x.current = w;
401
+ const J = C.current;
402
+ if (J?.playState === "running") {
403
+ if (!a) {
404
+ J.reverse();
405
+ return;
230
406
  }
407
+ M.current.restart(!0);
408
+ } else {
409
+ if (J?.cancel(), !I.animate) {
410
+ k();
411
+ return;
412
+ }
413
+ w ? T(d, v()) : T(v(), d);
414
+ }
415
+ a?.forEach((P) => P !== M.current && P.restart());
416
+ }, [w, t, n, f, m, L, a]), ne(() => {
417
+ const I = M.current;
418
+ return j.current = !0, C.current?.playState === "running" && a?.add(I), () => {
419
+ j.current = !1, a?.delete(I);
231
420
  };
232
- var ne, L = {}, ae = $.react_stack_bottom_frame.bind(
233
- $,
234
- x
235
- )(), b = q(l(x)), W = {};
236
- De.Fragment = T, De.jsx = function(t, i, h) {
237
- var v = 1e4 > M.recentlyCreatedOwnerStacks++;
238
- return E(
239
- t,
240
- i,
241
- h,
242
- !1,
243
- v ? Error("react-stack-top-frame") : ae,
244
- v ? q(l(t)) : b
245
- );
246
- }, De.jsxs = function(t, i, h) {
247
- var v = 1e4 > M.recentlyCreatedOwnerStacks++;
248
- return E(
249
- t,
250
- i,
251
- h,
252
- !0,
253
- v ? Error("react-stack-top-frame") : ae,
254
- v ? q(l(t)) : b
255
- );
256
- };
257
- })()), De;
421
+ }, [a]), E && s ? null : /* @__PURE__ */ O(e, { ref: L, ...g });
258
422
  }
259
- var at;
260
- function Tt() {
261
- return at || (at = 1, process.env.NODE_ENV === "production" ? Be.exports = Nt() : Be.exports = Rt()), Be.exports;
423
+ const _t = ({ id: e, present: t, appear: n, onExited: r, children: s }) => {
424
+ const c = _(() => ({ present: t, appear: n, onExited: () => r(e) }), [e, t, n, r]);
425
+ return /* @__PURE__ */ O(ut.Provider, { value: c, children: s });
426
+ }, Ue = (e, t, n = !0) => {
427
+ const r = it.toArray(t).filter(xe), s = new Set(r.map((o) => o.key)), c = new Map(e.map((o) => [o.key, o])), i = r.map((o) => ({ key: o.key, el: o, present: !0, appear: c.get(o.key)?.appear ?? n }));
428
+ let a = 0;
429
+ return e.forEach((o) => {
430
+ s.has(o.key) ? o.present && (a = i.findIndex((p) => p.key === o.key) + 1) : i.splice(a++, 0, o.present ? { ...o, present: !1 } : o);
431
+ }), { children: t, list: i };
432
+ };
433
+ function $e({ children: e, hold: t = !1 }) {
434
+ const [n, r] = U(() => ({ ...Ue([], e, !1), hold: t }));
435
+ let s = n;
436
+ s.children !== e && (s = { ...s, ...Ue(s.list, e) }), s.hold !== t && (s = { ...s, hold: t, list: t ? s.list : s.list.filter((i) => i.present) }), s !== n && r(s);
437
+ const c = K((i) => r(
438
+ (a) => !a.hold && a.list.some((o) => o.key === i && !o.present) ? { ...a, list: a.list.filter((o) => o.key !== i) } : a
439
+ ), []);
440
+ return n.list.map(
441
+ ({ key: i, el: a, present: o, appear: p }) => /* @__PURE__ */ O(_t, { id: i, present: o, appear: p, onExited: c, children: a }, i)
442
+ );
262
443
  }
263
- var p = Tt();
264
- const lt = ({ className: e = "", ...r }) => /* @__PURE__ */ p.jsx(
265
- "svg",
266
- {
267
- className: e,
268
- role: "button",
269
- "aria-label": "Clear selection",
270
- xmlns: "http://www.w3.org/2000/svg",
271
- viewBox: "0 0 320 512",
272
- width: "1em",
273
- height: "1em",
274
- fill: "currentColor",
275
- ...r,
276
- children: /* @__PURE__ */ p.jsx("path", { d: "M310.6 361.4c12.5 12.5 12.5 32.8 0 45.3s-32.8 12.5-45.3 0L160 301.3 54.6 406.6c-12.5 12.5-32.8 12.5-45.3 0s-12.5-32.8 0-45.3L114.7 256 9.4 150.6c-12.5-12.5-12.5-32.8 0-45.3s32.8-12.5 45.3 0L160 210.7 265.4 105.4c12.5-12.5 32.8-12.5 45.3 0s12.5 32.8 0 45.3L205.3 256l105.3 105.4z" })
277
- }
278
- ), kt = ({ className: e = "", ...r }) => /* @__PURE__ */ p.jsx(
279
- "svg",
280
- {
281
- className: e,
282
- xmlns: "http://www.w3.org/2000/svg",
283
- viewBox: "0 0 448 512",
284
- width: "1em",
285
- height: "1em",
286
- fill: "currentColor",
287
- ...r,
288
- children: /* @__PURE__ */ p.jsx("path", { d: "M34.9 289.5l175.9-175.8c9.4-9.4 24.6-9.4 33.9 0L420.1 289.5c15.1 15.1 4.4 41-17 41H51.9c-21.4 0-32.1-25.9-17-41z" })
289
- }
290
- ), _t = ({ className: e = "", ...r }) => /* @__PURE__ */ p.jsx(
291
- "svg",
292
- {
293
- className: e,
294
- xmlns: "http://www.w3.org/2000/svg",
295
- viewBox: "0 0 24 24",
296
- width: "1em",
297
- height: "1em",
298
- fill: "currentColor",
299
- ...r,
300
- children: /* @__PURE__ */ p.jsx("path", { d: "M20.285 6.708a1 1 0 0 0-1.414-1.416l-9.192 9.192-4.243-4.244a1 1 0 1 0-1.414 1.416l5 5a1 1 0 0 0 1.414 0l9.849-9.948z" })
444
+ const ft = "rac-chip-slot", Le = "rac-flip", Ge = [], Ut = 0.25, Yt = { hoverId: null, swipedId: null, held: !1, breaks: Ge }, De = () => window.matchMedia?.("(prefers-reduced-motion: reduce)").matches, ve = (e) => Array.from(e.children).filter((t) => t.classList.contains(ft)), Ye = (e) => Array.from(e.children).some((t) => t.getAnimations?.().some((n) => n.constructor === Animation && n.id !== Le && n.playState === "running")), Jt = (e, t) => e.length === t.length && e.every((n, r) => n === t[r]), Xt = (e) => {
445
+ const t = [];
446
+ let n = -1 / 0;
447
+ for (const r of e) {
448
+ const s = r.getBoundingClientRect();
449
+ s.top >= n - 1 && (t.push([]), n = s.bottom), t.at(-1).push(r), n = Math.max(n, s.bottom);
301
450
  }
302
- ), rt = gt(null), He = pt(({ className: e = "", visibility: r = void 0, setLeaving: n, setEntering: l, setSpacer: a, children: x, duration: y = 300, unmount: f, style: j, exit: s = !0, ...E }, S) => {
303
- const u = re(null), $ = r !== void 0 ? r : E.in;
304
- ht(S, () => u.current), pe(() => {
305
- !$ && u.current && (u.current.style.width = "0px");
451
+ return t;
452
+ }, gt = (e, t, n, r) => {
453
+ const s = e.cloneNode(!0), { height: c, paddingInlineEnd: i } = getComputedStyle(e);
454
+ s.style.cssText = `visibility: hidden; pointer-events: none; height: ${c}; min-height: 0; padding-inline-end: calc(${i} + ${n}px)`, s.querySelectorAll(`:scope > :not(.${ft})`).forEach((l) => l.remove()), r && ve(s).forEach((l) => r.has(l.dataset.id) || l.remove()), n && s.querySelectorAll(".rac-chip-del").forEach((l) => l.remove());
455
+ const a = ve(s), o = new Map(a.map((l, g) => [l.dataset.id, g]));
456
+ t?.slice(1).forEach((l, g) => {
457
+ const y = Math.min(...l.map((S) => o.get(S) ?? 1 / 0)), h = Math.max(...t[g].map((S) => o.get(S) ?? -1).filter((S) => S < y));
458
+ h >= 0 && a[h].after(Object.assign(document.createElement("div"), { className: "rac-spacer" }));
459
+ }), e.style.position = "absolute", e.after(s), s.getAnimations?.({ subtree: !0 }).forEach((l) => l.effect?.getComputedTiming().endTime < 1 / 0 && l.finish());
460
+ const p = Xt(a).map((l) => l.map((g) => g.dataset.id));
461
+ return s.remove(), e.style.position = "", p;
462
+ }, pt = (e, t) => {
463
+ const n = t ? t.slice(0, -1).map((s) => s.at(-1)) : Ge, { breaks: r } = e.get();
464
+ return Jt(r, n) ? r : n;
465
+ }, Je = (e, t, n, r) => pt(e, r && n.length ? gt(t, null, r, new Set(n.map((s) => s.id))) : null), Xe = (e, t, n) => {
466
+ n.rows = gt(t, n.rows, n.reserve), e.set({ held: !0, breaks: pt(e, n.rows) });
467
+ }, Ze = (e, t, n, r) => {
468
+ if (!e.animate) return;
469
+ e.getAnimations().forEach((a) => a.id === Le && a.cancel());
470
+ const s = e.getBoundingClientRect(), c = t.left - s.left, i = t.top - s.top;
471
+ (Math.abs(c) > 0.5 || Math.abs(i) > 0.5) && e.animate([{ transform: `translate(${c}px, ${i}px)` }, { transform: "none" }], { id: Le, duration: n, easing: r });
472
+ }, Zt = (e, t, n, r, s) => {
473
+ if (!e || n === t.value) return;
474
+ const c = getComputedStyle(e), i = t.anim ? c.height : t.root;
475
+ t.anim?.cancel(), t.root = c.height;
476
+ const a = !t.value || i === t.root || !e.animate || De();
477
+ if (t.value = n, t.anim = null, a) return;
478
+ const o = { overflow: "hidden", alignItems: "flex-start" }, p = t.anim = e.animate([{ ...o, height: i }, { ...o, height: t.root }], { duration: r, easing: s });
479
+ p.onfinish = () => {
480
+ t.anim === p && (t.anim = null);
481
+ };
482
+ };
483
+ function Qt(e) {
484
+ const { selectRef: t, duration: n, easing: r, multiple: s, deleteInline: c, deleteAlways: i, icons: a } = B(Y), { selectedIDs: o, deleting: p, visibility: l, active: g } = B(de), { setDeleting: y, setVisibility: h } = B(ce), [S, w] = U(0), [f] = U(() => Me(Yt)), [m] = U(() => /* @__PURE__ */ new Set()), D = re(f.subscribe, () => f.get().held, () => !1), L = re(f.subscribe, () => f.get().breaks, () => Ge), C = F({ rows: null, reserve: 0, chips: e }), j = F(null), M = F({ value: 0, root: "", anim: null }), u = F(null), x = F(null), E = c && !i && !p && !!a.remove, $ = E ? S + Ut : 0, k = s && E && !S, V = ot((b) => {
485
+ const d = u.current, v = C.current;
486
+ d && (b && f.get().held && Xe(f, d, v), Zt(t.current, M.current, d.offsetHeight, n, r), f.get().held || f.set({ breaks: Je(f, d, v.chips, v.reserve) }));
487
+ });
488
+ ne(() => {
489
+ const b = C.current, d = u.current, v = b.chips !== e;
490
+ Object.assign(b, { chips: e, reserve: $ }), v && d && Ye(d) && Xe(f, d, b), V(!v);
491
+ }, [e, $, f]), ne(() => {
492
+ const b = () => V(!0), d = typeof ResizeObserver > "u" ? null : new ResizeObserver(b);
493
+ return d?.observe(u.current), document.fonts?.addEventListener("loadingdone", b), () => {
494
+ d?.disconnect(), document.fonts?.removeEventListener("loadingdone", b);
495
+ };
306
496
  }, []);
307
- const _ = R(() => {
308
- if (!u.current) return { left: "0px", right: "0px" };
309
- const A = window.getComputedStyle(u.current);
310
- return { left: A.marginLeft, right: A.marginRight };
497
+ const I = K(() => {
498
+ const b = u.current;
499
+ if (!b || !f.get().held || Ye(b)) return;
500
+ const d = ve(b), v = d.map((H) => H.getBoundingClientRect()), T = Je(f, b, C.current.chips, C.current.reserve);
501
+ C.current.rows = null, St(() => f.set({ held: !1, breaks: T })), De() || d.forEach((H, J) => H.isConnected && Ze(H, v[J], n, r));
502
+ }, [f, n, r]), A = K(() => {
503
+ u.current && (j.current = new Map(ve(u.current).map((b) => [b, b.getBoundingClientRect()])));
311
504
  }, []);
312
- return /* @__PURE__ */ p.jsx(
313
- Ke,
505
+ return ne(() => {
506
+ const b = j.current;
507
+ !b || L !== f.get().breaks || (j.current = null, De() || b.forEach((d, v) => v.isConnected && Ze(v, d, n, r)));
508
+ }, [L, e, f, n, r]), oe(() => () => M.current.anim?.cancel(), []), oe(() => {
509
+ p && l && h(!1), p && (!o.length || !g) && y(!1), f.set({ hoverId: null, ...!g && { swipedId: null } });
510
+ }, [o.length, p, l, g, y, h, f]), ne(() => {
511
+ const b = x.current;
512
+ if (!k || !b) return;
513
+ const d = getComputedStyle(b);
514
+ w(b.getBoundingClientRect().width + parseFloat(d.marginLeft) + parseFloat(d.marginRight));
515
+ }, [k]), { chipStore: f, delGroup: m, valueRef: u, delIconRef: x, probe: k, settle: I, held: D, snapshot: A };
516
+ }
517
+ const Qe = 1, et = 2, en = 600, tn = 10, tt = 30, nn = se(function({ element: t, deleting: n, locked: r, chipStore: s, delGroup: c }) {
518
+ const { selectRef: i, deleteInline: a, deleteAlways: o, icons: p, texts: l, valueAsOption: g, renderOption: y } = B(Y), h = !!p.remove, { setVisibility: S, setDeleting: w, removeOption: f } = B(ce), m = F({ longPressTimer: null, longPress: !1, x: 0, y: 0 }), D = re(s.subscribe, () => {
519
+ const { hoverId: b, swipedId: d } = s.get();
520
+ return (b === t.id ? Qe : 0) | (d === t.id ? et : 0);
521
+ }, () => 0), L = !!(D & Qe), C = !!(D & et), j = K((b) => {
522
+ const { clientX: d, clientY: v } = b.touches[0];
523
+ Object.assign(m.current, { x: d, y: v, longPress: !1 }), clearTimeout(m.current.longPressTimer), h && (m.current.longPressTimer = setTimeout(() => {
524
+ w(!0), m.current.longPress = !0, i.current?.focus(), S(!1), window.navigator.vibrate?.(50);
525
+ }, en));
526
+ }, [h, w, S, i]), M = K((b) => {
527
+ const { clientX: d, clientY: v } = b.touches[0], T = m.current.x - d;
528
+ Math.hypot(T, m.current.y - v) > tn && clearTimeout(m.current.longPressTimer), T > tt && !C ? s.set({ hoverId: null, swipedId: t.id }) : T < -tt && C && s.set({ swipedId: null });
529
+ }, [t.id, C, s]), u = K(() => clearTimeout(m.current.longPressTimer), []), x = K(() => s.set({ hoverId: t.id, swipedId: null }), [t.id, s]), E = K(() => {
530
+ s.get().hoverId === t.id && s.set({ hoverId: null });
531
+ }, [t.id, s]);
532
+ oe(() => () => clearTimeout(m.current.longPressTimer), []);
533
+ const $ = g ? Ve(t, y, !0) : null, k = $ ? /* @__PURE__ */ O("div", { className: "rac-option-jsx", children: $ }) : /* @__PURE__ */ O("span", { className: "rac-chip-text", children: t.name || l.emptyOption }), V = K((b) => {
534
+ s.set({ swipedId: null }), f(t.id), Q(b);
535
+ }, [t.id, f, s]), I = K((b) => {
536
+ Q(b), m.current.longPress ? m.current.longPress = !1 : n && V(b);
537
+ }, [n, V]), A = h && (o || !r && (L || C || n));
538
+ return /* @__PURE__ */ q(
539
+ "div",
314
540
  {
315
- onEnter: () => {
316
- u.current.style.transition = "none", u.current.style.marginRight = "0px", u.current.style.marginLeft = "0px", u.current.style.width = "0px", l?.(!0);
317
- },
318
- onEntering: () => {
319
- const { left: A, right: T } = _();
320
- requestAnimationFrame(() => {
321
- requestAnimationFrame(() => {
322
- u.current && (u.current.style.transition = `width ${y}ms, color ${y}ms, background-color ${y}ms, margin ${y}ms ease`, u.current.style.width = u.current.scrollWidth + "px", u.current.style.marginRight = T, u.current.style.marginLeft = A);
323
- });
324
- });
325
- },
326
- onEntered: () => {
327
- u.current.style.width = "auto", a?.(!1), l?.(!1);
328
- },
329
- onExit: () => {
330
- const { left: A, right: T } = _();
331
- u.current.style.width = u.current.scrollWidth + "px", u.current.style.marginRight = T, u.current.style.marginLeft = A, u.current.offsetHeight, n?.(!0);
332
- },
333
- onExiting: () => {
334
- u.current.style.marginRight = "0px", u.current.style.marginLeft = "0px", u.current.style.width = "0px";
335
- },
336
- onExited: () => {
337
- f?.(), n?.(!1), a?.(!1);
338
- },
339
- classNames: "rac-slide-left",
340
- unmountOnExit: s,
341
- timeout: y,
342
- nodeRef: u,
343
- in: $,
344
- ...E,
345
- children: /* @__PURE__ */ p.jsx(
346
- "div",
347
- {
348
- className: e,
349
- ref: u,
350
- style: {
351
- transition: `width ${y}ms, color ${y}ms, background-color ${y}ms, margin ${y}ms ease`,
352
- willChange: "width",
353
- overflow: "hidden",
354
- ...j
355
- },
356
- children: x
357
- }
358
- )
541
+ className: ue("rac-chip", $ && t.className),
542
+ style: $ ? t.style : void 0,
543
+ ...!r && { onTouchStart: j, onTouchMove: M, onTouchEnd: u, onTouchCancel: u, onMouseEnter: x, onMouseLeave: E, onClick: I },
544
+ children: [
545
+ k,
546
+ /* @__PURE__ */ O(
547
+ ie,
548
+ {
549
+ "aria-label": `${l.remove} ${t.name ?? ""}`.trim(),
550
+ group: a && !o && !n ? c : void 0,
551
+ onMouseDown: Q,
552
+ onClick: V,
553
+ className: "rac-chip-del",
554
+ disabled: r,
555
+ tabIndex: -1,
556
+ type: "button",
557
+ in: A,
558
+ as: "button",
559
+ axis: "x",
560
+ children: ae(p.remove)
561
+ }
562
+ )
563
+ ]
359
564
  }
360
565
  );
361
- }), At = Xe(({ element: e, index: r, setEntering: n, leaving: l, setLeaving: a, setSpacer: x, selectRef: y, spacer: f, delSpacer: j, setVisibility: s, setActiveHoverId: E, activeHoverId: S, swipedId: u, deleteInline: $, remove: _, renderIcon: A, DelIcon: T, normalizedOptions: C, swiped: P, onSwipe: I, deleting: F, setDeleting: Z, onRender: Q, duration: D, showDelete: U }) => {
362
- const c = re(null), G = re(!1), ue = re(!1), M = re(0), V = re(null), he = R((i) => {
363
- M.current = i.touches[0].clientX, G.current = !1, c.current && clearTimeout(c.current), c.current = setTimeout(() => {
364
- Z(!0), G.current = !0, y.current?.focus(), s(!1), window.navigator.vibrate && window.navigator.vibrate(50);
365
- }, 600), i.preventDefault();
366
- }, []), q = R((i) => {
367
- c.current && clearTimeout(c.current);
368
- const h = i.touches[0].clientX, v = M.current - h;
369
- Math.abs(v) > 10 && (ue.current = !0, v > 30 && !P ? (E(null), I(e.id)) : v < -30 && P && I(null));
370
- }, [e.id, P, I]), ne = R((i) => {
371
- c.current && clearTimeout(c.current), G.current && i.preventDefault();
372
- }, []);
373
- let L = null;
374
- if (e?.jsx)
375
- L = e.jsx;
376
- else if (e?.name)
377
- L = e.name;
378
- else if (e?.raw !== void 0) {
379
- const i = C.find(
380
- (h) => h.raw === e.raw || h.original === e.raw || h.userId === e.raw
381
- );
382
- i && (L = i.jsx ?? i.name);
566
+ }), rn = se(function({ element: t, chipStore: n, settle: r, ...s }) {
567
+ const c = re(n.subscribe, () => n.get().breaks.includes(t.id), () => !1);
568
+ return /* @__PURE__ */ q(at, { children: [
569
+ /* @__PURE__ */ O(ie, { className: "rac-chip-slot", onEntered: r, onExited: r, unmountOnExit: !1, "data-id": t.id, axis: "x", fade: !0, children: /* @__PURE__ */ O(nn, { element: t, chipStore: n, ...s }) }),
570
+ c && /* @__PURE__ */ O("div", { className: "rac-spacer" })
571
+ ] });
572
+ }), sn = { position: "absolute", visibility: "hidden", pointerEvents: "none" }, je = [], on = () => {
573
+ }, an = (e) => e == null ? "" : typeof e == "object" ? fe(e) ?? "" : String(e), ln = se(function() {
574
+ const { selectRef: t, multiple: n, name: r, required: s } = B(Y), { selected: c, selectedIDs: i, disabled: a } = B(de);
575
+ if (!r && !s) return null;
576
+ const o = (n ? i : c ? [c] : je).map((g) => an(g.original)), p = o.length ? o : n && !s ? je : [""], l = () => t.current?.focus();
577
+ return p.map(
578
+ (g, y) => /* @__PURE__ */ O("input", { className: "rac-input", name: r, value: g, required: s && !y, disabled: a, tabIndex: -1, "aria-hidden": "true", onChange: on, onFocus: l }, y)
579
+ );
580
+ });
581
+ class cn extends vt {
582
+ getSnapshotBeforeUpdate(t) {
583
+ return t.chips !== this.props.chips && this.props.take(), null;
383
584
  }
384
- L == null && (L = typeof e == "object" ? e.label ?? e.name ?? e.value ?? "Selected item" : String(e));
385
- const ae = R((i) => {
386
- i.stopPropagation(), i.preventDefault();
387
- }, []), b = R((i) => {
388
- ae(i), _(e.id), I(null);
389
- }, [e.id, _, I]), W = R((i) => {
390
- if (ae(i), G.current) {
391
- G.current = !1;
392
- return;
393
- }
394
- if (F) {
395
- b(i);
396
- return;
397
- }
398
- }, [F, b]);
399
- We(() => {
400
- if (V.current && Q) {
401
- const i = V.current.offsetWidth;
402
- Q(i);
403
- }
404
- }, [Q, L]);
405
- const t = U ? !0 : S === e.id || u === e.id || F;
406
- return /* @__PURE__ */ p.jsxs(mt, { children: [
407
- /* @__PURE__ */ p.jsxs(
408
- "div",
409
- {
410
- className: `rac-multiple-selected-option ${F ? "--deleting-shake" : ""}`,
411
- onMouseEnter: () => {
412
- E(e.id), I(null);
585
+ componentDidUpdate() {
586
+ }
587
+ render() {
588
+ return null;
589
+ }
590
+ }
591
+ const nt = (e, t) => {
592
+ const n = new Set(e.map((i) => i.id)), r = new Map(t.map(([i, a]) => [a.id, i])), s = t.filter(([, i]) => !n.has(i.id)), c = new Set(t.map(([i]) => i));
593
+ return e.map((i) => {
594
+ if (r.has(i.id)) return [r.get(i.id), i];
595
+ const a = s.findIndex(([, p]) => Wt(p.original, i.original));
596
+ if (a >= 0) return [s.splice(a, 1)[0][0], i];
597
+ let o = i.id;
598
+ for (; c.has(o); ) o += "~";
599
+ return c.add(o), [o, i];
600
+ });
601
+ }, dn = (e) => {
602
+ const [t, n] = U(() => ({ chips: e, keyed: nt(e, []) }));
603
+ if (t.chips === e) return t.keyed;
604
+ const r = nt(e, t.keyed);
605
+ return n({ chips: e, keyed: r }), r;
606
+ }, un = se(function() {
607
+ const { selectedText: t, icons: n, valueAsOption: r, renderOption: s } = B(Y), { selectedIDs: c, title: i, valueOption: a, hasActualValue: o, loading: p, error: l, deleting: g, active: y } = B(de), h = c.length > 0 && !t, S = h ? c : je, { chipStore: w, delGroup: f, valueRef: m, delIconRef: D, probe: L, settle: C, held: j, snapshot: M } = Qt(S), u = dn(S), [x] = U(() => /* @__PURE__ */ new Set()), E = r && a ? Ve(a, s, !0) : null, $ = p && !l && !o, k = `${E ? a.id : i}${$ ? "-loading" : ""}`, V = a?.type === "boolean" ? String(a.raw) : void 0;
608
+ return /* @__PURE__ */ q("div", { className: "rac-value", ref: m, children: [
609
+ /* @__PURE__ */ O(cn, { chips: S, take: M }),
610
+ /* @__PURE__ */ O($e, { children: !h && /* @__PURE__ */ q(ie, { axis: "x", fade: !0, group: x, className: ue("rac-title", E && a.className), style: E ? a.style : void 0, "data-bool": V, onEntered: C, onExited: C, children: [
611
+ E ? /* @__PURE__ */ O("div", { className: "rac-option-jsx", children: E }) : i,
612
+ $ && Be
613
+ ] }, k) }),
614
+ /* @__PURE__ */ O($e, { hold: j, children: u.map(
615
+ ([I, A]) => /* @__PURE__ */ O(
616
+ rn,
617
+ {
618
+ element: A,
619
+ deleting: g,
620
+ locked: !y,
621
+ chipStore: w,
622
+ delGroup: f,
623
+ settle: C
413
624
  },
414
- onMouseLeave: () => E(null),
415
- onTouchStart: he,
416
- onTouchMove: q,
417
- onTouchEnd: ne,
418
- onClick: W,
419
- ref: V,
420
- children: [
421
- L,
422
- /* @__PURE__ */ p.jsx(
423
- He,
424
- {
425
- style: {
426
- backgroundColor: F || $ ? "transparent" : "--rac-multiple-del-bg",
427
- position: F || $ ? "relative" : "absolute"
428
- },
429
- className: "rac-multiple-del",
430
- visibility: t,
431
- setEntering: n,
432
- setLeaving: a,
433
- setSpacer: x,
434
- duration: D,
435
- children: A(T, { onClick: b, onMouseDown: ae })
436
- }
437
- )
438
- ]
439
- }
440
- ),
441
- /* @__PURE__ */ p.jsx(
442
- He,
443
- {
444
- visibility: !l && !f?.state && !S && !u && !F && $ && j,
445
- className: "rac-multiple-option",
446
- style: { visibility: "hidden" },
447
- children: /* @__PURE__ */ p.jsx(
448
- "div",
449
- {
450
- style: { padding: 0, marginRight: 0, marginLeft: 0 },
451
- className: "rac-multiple-selected-option",
452
- children: A(T)
453
- }
454
- )
455
- }
456
- )
625
+ I
626
+ )
627
+ ) }),
628
+ L && /* @__PURE__ */ O("button", { type: "button", className: "rac-chip-del", tabIndex: -1, "aria-hidden": "true", ref: D, style: sn, children: ae(n.remove) })
457
629
  ] });
458
- }), xt = ({ children: e, setLeaving: r, duration: n, setSpacer: l, id: a = null, widthMode: x = !1, ...y }) => {
459
- const f = re(null), j = R(() => {
460
- if (!f.current) return { t: 0, b: 0, l: 0, r: 0 };
461
- const s = window.getComputedStyle(f.current);
462
- return {
463
- t: s.marginTop,
464
- b: s.marginBottom,
465
- l: s.marginLeft,
466
- r: s.marginRight
467
- };
468
- }, []);
469
- return /* @__PURE__ */ p.jsx(
470
- Ke,
630
+ }), fn = se(function() {
631
+ const { selectRef: t, selectId: n, highlightStore: r, positionStore: s, className: c, style: i, duration: a, easing: o, deleteInline: p, icons: l, texts: g, placeholder: y, id: h, required: S, attrs: w } = B(Y), { visibility: f, active: m, hasActualValue: D, deleting: L, loading: C, loadPending: j, error: M, normalizedOptions: u } = B(de), { handleBlur: x, handleFocus: E, handleKeyDown: $, toggleVisibility: k, clear: V } = B(ce), I = re(s.subscribe, () => s.get().upward, () => !1), A = re(r.subscribe, () => {
632
+ const v = f ? u[ye(r.get())] : null;
633
+ return v ? Oe(n, v.id) : void 0;
634
+ }, () => {
635
+ }), b = !!l.clear && D && m && !L, d = !!l.arrow && m && !L;
636
+ return /* @__PURE__ */ q(
637
+ "div",
471
638
  {
472
- classNames: "rac-slide-left",
473
- timeout: n,
474
- nodeRef: f,
475
- unmountOnExit: !0,
476
- ...y,
477
- onEnter: () => {
478
- const s = f.current;
479
- s && (x ? (s.style.width = "0px", s.style.marginLeft = "0px", s.style.marginRight = "0px") : (s.style.height = "0px", s.style.marginTop = "0px", s.style.marginBottom = "0px", s.style.transform = "translateY(-10px)"), s.style.opacity = "0");
480
- },
481
- onEntering: () => {
482
- const s = f.current, E = j();
483
- s.offsetHeight, x ? (s.style.width = s.scrollWidth + "px", s.style.marginRight = E.r, s.style.marginLeft = E.l) : (s.style.height = s.scrollHeight + "px", s.style.transform = "translateY(0)", s.style.marginBottom = E.b, s.style.marginTop = E.t), s.style.opacity = "1";
484
- },
485
- onEntered: () => {
486
- const s = f.current;
487
- s.style.width = x ? "auto" : "", s.style.height = x ? "" : "100%", s.style.opacity = "1", s.style.transform = "", l?.(!1);
488
- },
489
- onExit: () => {
490
- const s = f.current, E = j();
491
- x ? (s.style.width = s.offsetWidth + "px", s.style.marginRight = E.r, s.style.marginLeft = E.l) : (s.style.height = s.offsetHeight + "px", s.style.position = "absolute", s.style.marginBottom = E.b, s.style.marginTop = E.t), s.style.opacity = "1", r?.(!0);
492
- },
493
- onExiting: () => {
494
- const s = f.current;
495
- x ? (s.style.marginRight = "0px", s.style.marginLeft = "0px", s.style.width = "0px") : (s.style.transform = "translateY(10px)", s.style.marginBottom = "0px", s.style.marginTop = "0px", s.style.height = "0px"), s.style.opacity = "0";
639
+ ...w,
640
+ id: h,
641
+ ref: t,
642
+ style: { "--rac-duration": `${a}ms`, "--rac-ease": o, ...i },
643
+ className: ue("rac-select", c),
644
+ ...m && {
645
+ onKeyDown: $,
646
+ onFocus: E,
647
+ onClick: k,
648
+ onBlur: x
496
649
  },
497
- onExited: () => {
498
- l?.(!1), r?.(!1);
499
- },
500
- children: /* @__PURE__ */ p.jsx(
501
- "div",
502
- {
503
- ref: f,
504
- id: a,
505
- style: {
506
- transition: `all ${n}ms ease`,
507
- alignItems: "center",
508
- whiteSpace: "nowrap",
509
- overflow: "hidden",
510
- display: "flex",
511
- left: 0,
512
- top: 0
513
- },
514
- children: e
515
- }
516
- )
650
+ "aria-disabled": !m,
651
+ "aria-activedescendant": A,
652
+ "aria-controls": `${n}-listbox`,
653
+ tabIndex: m ? 0 : -1,
654
+ "aria-expanded": f,
655
+ "aria-busy": C || j || void 0,
656
+ "aria-label": w["aria-label"] ?? (w["aria-labelledby"] ? void 0 : y),
657
+ "aria-required": S || void 0,
658
+ "aria-haspopup": "listbox",
659
+ role: "combobox",
660
+ "data-placement": I ? "top" : "bottom",
661
+ "data-inline-delete": X(p),
662
+ "data-empty": X(!D),
663
+ "data-deleting": X(L),
664
+ "data-error": X(M),
665
+ children: [
666
+ /* @__PURE__ */ O(un, {}),
667
+ /* @__PURE__ */ q($e, { children: [
668
+ b && /* @__PURE__ */ O(ie, { as: "button", type: "button", axis: "x", className: "rac-clear", tabIndex: -1, "aria-label": g.clear, onMouseDown: Q, onClick: V, children: ae(l.clear) }, "clear"),
669
+ d && /* @__PURE__ */ O(ie, { axis: "x", className: "rac-arrow", "aria-hidden": "true", children: ae(l.arrow) }, "arrow")
670
+ ] }),
671
+ /* @__PURE__ */ O(ln, {})
672
+ ]
517
673
  }
518
674
  );
519
- }, Ot = Xe(({ element: e, index: r, setEntering: n, leaving: l, setLeaving: a, selectRef: x, setVisibility: y, setActiveHoverId: f, delSpacer: j, swiped: s, swipedId: E, onSwipe: S, activeHoverId: u, deleteInline: $, spacer: _, duration: A, normalizedOptions: T, setDeleting: C, renderIcon: P, deleting: I, DelIcon: F, remove: Z, registerItemWidth: Q, setSpacer: D, showDelete: U, ...c }) => /* @__PURE__ */ p.jsxs(mt, { children: [
520
- /* @__PURE__ */ p.jsx(
521
- xt,
675
+ }), ke = 0, gn = 1, rt = 2, ht = (e) => {
676
+ const { highlightStore: t } = B(Y), n = F(null), r = re(t.subscribe, () => {
677
+ const s = t.get();
678
+ return ye(s) !== e ? ke : s.ready ? rt : gn;
679
+ }, () => ke);
680
+ return ne(() => {
681
+ r === rt && n.current?.scrollIntoView?.({ block: "nearest" });
682
+ }, [r]), [n, r !== ke];
683
+ }, pn = se(function({ option: t, index: n, open: r, hasChildren: s }) {
684
+ const { selectId: c, icons: i } = B(Y), { selectOption: a, highlight: o } = B(ce), [p, l] = ht(n), g = s && !t.disabled;
685
+ return /* @__PURE__ */ q(
686
+ "div",
522
687
  {
523
- className: "rac-multiple-option",
524
- onEnter: c.onEnter,
525
- setLeaving: a,
526
- setSpacer: D,
527
- onExit: c.onExit,
528
- duration: A,
529
- id: e.id,
530
- in: c.in,
531
- widthMode: !0,
532
- children: /* @__PURE__ */ p.jsx(
533
- At,
534
- {
535
- onRender: (G) => Q(e.id, G),
536
- normalizedOptions: T,
537
- setActiveHoverId: f,
538
- activeHoverId: u,
539
- setVisibility: y,
540
- deleteInline: $,
541
- setDeleting: C,
542
- setEntering: n,
543
- setLeaving: a,
544
- renderIcon: P,
545
- showDelete: U,
546
- setSpacer: D,
547
- selectRef: x,
548
- delSpacer: j,
549
- duration: A,
550
- deleting: I,
551
- swipedId: E,
552
- onSwipe: S,
553
- element: e,
554
- DelIcon: F,
555
- leaving: l,
556
- swiped: s,
557
- remove: Z,
558
- spacer: _,
559
- index: r
560
- },
561
- e.id ?? r
562
- )
688
+ className: ue("rac-group", t.className),
689
+ onMouseEnter: () => g && o(n),
690
+ onClick: (y) => a(t, y),
691
+ "data-highlighted": X(l),
692
+ "data-disabled": X(t.disabled),
693
+ id: Oe(c, t.id),
694
+ "data-open": X(r),
695
+ style: t.style,
696
+ ref: p,
697
+ children: [
698
+ /* @__PURE__ */ O("span", { className: "rac-group-text", children: t.name }),
699
+ /* @__PURE__ */ O(ie, { axis: "x", in: s && !t.disabled, className: "rac-group-arrow", "aria-hidden": "true", children: ae(i.arrow) })
700
+ ]
563
701
  }
564
- ),
565
- _.state && _.id === e.id && /* @__PURE__ */ p.jsx(
702
+ );
703
+ }), hn = se(function({ option: t, index: n, isSelected: r, showCheckbox: s }) {
704
+ const { selectId: c, icons: i, renderOption: a } = B(Y), { selectOption: o, highlight: p } = B(ce), [l, g] = ht(n), y = !t.disabled && !t.loading, h = Ve(t, a, r);
705
+ return /* @__PURE__ */ q(
566
706
  "div",
567
707
  {
568
- style: { width: _.width - 2 },
569
- className: "rac-spacer"
708
+ className: ue("rac-option", t.className),
709
+ onMouseEnter: () => y && p(n),
710
+ onClick: (S) => !t.loading && o(t, S),
711
+ "aria-disabled": t.disabled || t.loading,
712
+ "data-invalid": X(t.invalid),
713
+ "data-bool": typeof t.raw == "boolean" ? String(t.raw) : void 0,
714
+ "data-highlighted": X(g),
715
+ "data-loading": X(t.loading),
716
+ id: Oe(c, t.id),
717
+ "aria-selected": r,
718
+ style: t.style,
719
+ role: "option",
720
+ ref: l,
721
+ children: [
722
+ h ? /* @__PURE__ */ O("div", { className: "rac-option-jsx", children: h }) : /* @__PURE__ */ O("span", { className: "rac-option-text", children: t.name }),
723
+ t.loading && Be,
724
+ s && /* @__PURE__ */ q("div", { className: "rac-check", "data-default": X(!i.checkbox), children: [
725
+ ae(i.check, { className: "rac-checkmark" }),
726
+ ae(i.checkbox, { className: "rac-check-icon" })
727
+ ] })
728
+ ]
570
729
  }
571
- )
572
- ] }));
573
- function Ct({ visibility: e, children: r, selectRef: n, onAnimationDone: l, unmount: a = !0, duration: x, easing: y, offset: f, animateOpacity: j, style: s, className: E, setBottomDirection: S = () => {
574
- } }) {
575
- const u = re(null), [$, _] = oe({ top: 0, left: 0, width: 0 }), A = re($);
576
- We(() => {
577
- A.current = $;
578
- }, [$]);
579
- const T = R(() => {
580
- if (n?.current) {
581
- const c = n.current.getBoundingClientRect(), G = window.innerHeight, ue = u.current?.scrollHeight || 250, M = G - c.bottom, V = M < ue && c.top > M;
582
- S(V), _({
583
- top: c.top,
584
- bottom: c.bottom,
585
- left: c.left,
586
- width: c.width,
587
- isUpward: V
588
- });
730
+ );
731
+ }), mn = se(function() {
732
+ const { selectId: t, multiple: n } = B(Y), { normalizedOptions: r, selected: s, selectedIDs: c, expandedGroups: i } = B(de), a = s?.id;
733
+ return _(() => {
734
+ const o = new Set(c.map((f) => f.id)), p = r.reduce((f, m) => (m.group && (f[m.group] = (f[m.group] || 0) + 1), f), {}), l = [];
735
+ let g = [], y = null, h = null;
736
+ const S = () => {
737
+ y !== null && g.length && l.push(
738
+ /* @__PURE__ */ O(ie, { axis: "y", in: i.has(y), className: "rac-group-items", role: "group", "aria-labelledby": h, children: g }, `slide-${y}`)
739
+ ), g = [];
740
+ }, w = (f, m) => /* @__PURE__ */ O(
741
+ hn,
742
+ {
743
+ isSelected: o.has(f.id) || a === f.id,
744
+ showCheckbox: n && !f.disabled,
745
+ option: f,
746
+ index: m
747
+ },
748
+ f.id
749
+ );
750
+ return r.forEach((f, m) => {
751
+ f.groupHeader ? (S(), y = f.name, h = Oe(t, f.id), l.push(
752
+ /* @__PURE__ */ O(
753
+ pn,
754
+ {
755
+ hasChildren: p[f.name] > 0,
756
+ open: i.has(f.name),
757
+ option: f,
758
+ index: m
759
+ },
760
+ f.id
761
+ )
762
+ )) : f.group ? g.push(w(f, m)) : (S(), y = null, l.push(w(f, m)));
763
+ }), S(), l;
764
+ }, [r, a, c, i, n, t]);
765
+ }), yn = (e = {}) => Object.fromEntries(Object.entries(e).filter(([t]) => t.startsWith("--"))), bn = (e, t, n, r) => {
766
+ const s = e.getBoundingClientRect(), c = getComputedStyle(e), i = s.left - parseFloat(c.marginLeft) - t.left, a = n ? s.bottom + parseFloat(c.marginBottom) - t.top + r : s.top - parseFloat(c.marginTop) - t.bottom - r;
767
+ Math.abs(i) > 0.5 && (e.style.left = `${t.left - i}px`), Math.abs(a) > 0.5 && (e.style[n ? "bottom" : "top"] = `${parseFloat(e.style[n ? "bottom" : "top"]) + (n ? a : -a)}px`);
768
+ }, vn = ({ selectRef: e, panelRef: t, open: n, offset: r, store: s }) => {
769
+ const c = F(0), i = K((o) => {
770
+ const p = e.current;
771
+ if (!p) return;
772
+ const l = n && o ? o.scrollHeight : 0;
773
+ l && (c.current = l), c.current || (c.current = parseFloat(getComputedStyle(p).getPropertyValue("--rac-list-max-height")) || 250);
774
+ const g = p.getBoundingClientRect(), y = window.innerHeight - g.bottom, h = y < c.current && g.top > y;
775
+ s.set({ upward: h }), !(!n || !o) && (o.style.width = `${g.width}px`, o.style.left = `${g.left}px`, o.style.top = h ? "auto" : `${g.bottom + r}px`, o.style.bottom = h ? `${window.innerHeight - g.top + r}px` : "auto", bn(o, g, h, r));
776
+ }, [e, n, r, s]), a = K((o) => {
777
+ o && i(o.parentElement);
778
+ }, [i]);
779
+ return ne(() => {
780
+ const o = () => i(t.current);
781
+ o(), window.addEventListener("resize", o);
782
+ const p = [() => window.removeEventListener("resize", o)];
783
+ if (n) {
784
+ if (window.addEventListener("scroll", o, { capture: !0, passive: !0 }), p.push(() => window.removeEventListener("scroll", o, { capture: !0 })), typeof ResizeObserver < "u") {
785
+ const l = new ResizeObserver(o);
786
+ e.current && l.observe(e.current), t.current && l.observe(t.current), p.push(() => l.disconnect());
787
+ }
788
+ } else if (typeof IntersectionObserver < "u") {
789
+ const l = new IntersectionObserver(o, { threshold: [0, 0.25, 0.5, 0.75, 1] });
790
+ e.current && l.observe(e.current), p.push(() => l.disconnect());
589
791
  }
590
- }, [n]);
591
- We(() => {
592
- if (e)
593
- return T(), window.addEventListener("scroll", T, !0), window.addEventListener("resize", T), () => {
594
- window.removeEventListener("scroll", T, !0), window.removeEventListener("resize", T);
595
- };
596
- }, [e, T]);
597
- const C = `height var(--rac-duration) ${y}${j ? `, opacity var(--rac-duration) ${y}` : ""}`;
598
- We(() => {
599
- if (!n?.current) return;
600
- const c = new ResizeObserver((G) => {
601
- for (let ue of G)
602
- if (e && u.current && n.current) {
603
- const M = n.current.getBoundingClientRect(), { isUpward: V } = A.current;
604
- u.current.style.width = `${M.width}px`, u.current.style.left = `${M.left}px`, V ? u.current.style.bottom = `${window.innerHeight - M.top + f}px` : u.current.style.top = `${M.bottom + f}px`;
605
- }
606
- });
607
- return c.observe(n.current), () => c.disconnect();
608
- }, [n, e, f]);
609
- const P = {
610
- position: "fixed",
611
- "--rac-duration": `${x}ms`,
612
- "--rac-easing": y,
613
- left: `${$.left}px`,
614
- width: `${$.width}px`,
615
- overflow: "hidden",
616
- zIndex: "2147483647",
617
- height: e ? "auto" : "0px",
618
- opacity: j ? e ? 1 : 0 : 1,
619
- pointerEvents: e ? "all" : "none",
620
- // visibility: visibility ? 'visible' : 'hidden',
621
- boxSizing: "border-box",
622
- transformOrigin: $.isUpward ? "bottom" : "top",
623
- ...$.isUpward ? {
624
- bottom: `${window.innerHeight - $.top + f}px`,
625
- top: "auto"
626
- } : {
627
- top: `${$.bottom + f}px`,
628
- bottom: "auto"
629
- },
630
- ...Object.fromEntries(
631
- Object.entries(s || {}).map(([c, G]) => [
632
- c.startsWith("--") ? c : `--rac-${c.replace(/([A-Z])/g, "-$1").toLowerCase()}`,
633
- G
634
- ])
635
- )
636
- }, I = R(() => {
637
- const c = u.current;
638
- c && (c.style.height = "0px", j && (c.style.opacity = "0"), c.style.transition = "");
639
- }, [j]), F = R(() => {
640
- const c = u.current;
641
- c && (c.style.transition = C, c.style.height = `${c.scrollHeight}px`, j && (c.style.opacity = "1"));
642
- }, [C, j]), Z = R(() => {
643
- const c = u.current;
644
- c && (c.style.height = "auto", c.style.transition = "", l && l());
645
- }, [l]), Q = R(() => {
646
- const c = u.current;
647
- c && (c.style.height = `${c.scrollHeight}px`, j && (c.style.opacity = "1"), c.offsetHeight, c.style.transition = C);
648
- }, [C, j]), D = R(() => {
649
- const c = u.current;
650
- c && (c.style.height = "0px", j && (c.style.opacity = "0"));
651
- }, [j]), U = R(() => {
652
- const c = u.current;
653
- c && (c.style.transition = "");
654
- }, []);
655
- return $t(
656
- /* @__PURE__ */ p.jsx(
657
- Ke,
792
+ return () => p.forEach((l) => l());
793
+ }, [n, i, e, t]), [re(s.subscribe, () => s.get().upward, () => !1), a];
794
+ }, wn = (e) => (typeof e == "function" ? e() : e) || document.body, xn = () => () => {
795
+ }, On = se(function() {
796
+ const { selectRef: t, selectId: n, positionStore: r, multiple: s, offset: c, duration: i, easing: a, animateOpacity: o, keepMounted: p, optionsClassName: l, style: g, container: y, hasMore: h, loadButton: S, texts: w } = B(Y), { visibility: f, normalizedOptions: m, loading: D, error: L } = B(de), { handleListScroll: C, setListReady: j } = B(ce), M = f && m.length > 0, u = re(xn, () => !0, () => !1), x = F(null), [E, $] = vn({ selectRef: t, panelRef: x, open: f && u, offset: c, store: r }), k = K(() => j(!0), [j]);
797
+ return u ? Et(
798
+ /* @__PURE__ */ O(
799
+ ie,
658
800
  {
659
- in: e,
660
- timeout: x,
661
- classNames: "rac-options",
662
- unmountOnExit: a,
663
- nodeRef: u,
664
- onEnter: I,
665
- onEntering: F,
666
- onEntered: Z,
667
- onExit: Q,
668
- onExiting: D,
669
- onExited: U,
670
- children: /* @__PURE__ */ p.jsx(
801
+ axis: "y",
802
+ fade: o,
803
+ in: M,
804
+ nodeRef: x,
805
+ unmountOnExit: !p,
806
+ onEntered: k,
807
+ onMouseDown: (V) => V.preventDefault(),
808
+ className: ue("rac-options", l),
809
+ "data-placement": E ? "top" : "bottom",
810
+ style: { ...yn(g), "--rac-duration": `${i}ms`, "--rac-ease": a, pointerEvents: M ? "auto" : "none", position: "fixed" },
811
+ children: /* @__PURE__ */ q(
671
812
  "div",
672
813
  {
673
- ref: u,
674
- className: `rac-options ${E || ""}`,
675
- style: {
676
- ...P,
677
- "--rac-duration": `${x}ms`,
678
- "--rac-duration-fast": "calc(var(--rac-duration) * 0.5)",
679
- "--rac-duration-base": "var(--rac-duration)",
680
- "--rac-duration-slow": "calc(var(--rac-duration) * 1.3)"
681
- },
682
- onMouseDown: (c) => c.preventDefault(),
683
- children: r
814
+ onScroll: C,
815
+ className: "rac-list",
816
+ "aria-multiselectable": s,
817
+ id: `${n}-listbox`,
818
+ "aria-label": w.list,
819
+ role: "listbox",
820
+ tabIndex: "-1",
821
+ ref: $,
822
+ children: [
823
+ /* @__PURE__ */ O(mn, {}),
824
+ L ? /* @__PURE__ */ O("div", { className: "rac-option", "data-error": "", children: /* @__PURE__ */ O("span", { className: "rac-option-text", children: w.error }) }) : (D || !S && h) && /* @__PURE__ */ q("div", { className: "rac-option", "data-loading": "", children: [
825
+ /* @__PURE__ */ O("span", { className: "rac-option-text", children: D ? w.loading : w.loadingMore }),
826
+ Be
827
+ ] })
828
+ ]
684
829
  }
685
830
  )
686
831
  }
687
832
  ),
688
- document.body
689
- );
690
- }
691
- const Pt = Xe(Ct, (e, r) => e.visibility === r.visibility && e.duration === r.duration && e.easing === r.easing && e.offset === r.offset && e.animateOpacity === r.animateOpacity && e.selectRef === r.selectRef && e.children === r.children && JSON.stringify(e.style) === JSON.stringify(r.style)), ct = (e) => {
692
- const r = window.getComputedStyle(e);
693
- return parseFloat(r.marginLeft) + parseFloat(r.marginRight);
694
- }, ut = (e) => e.reduce((r, n) => {
695
- const l = n.offsetTop, a = n.getBoundingClientRect().width;
696
- return r[l] = (r[l] || 0) + a, r;
697
- }, {}), Lt = Xe(({ deleteInline: e, selectRef: r, setVisibility: n, selectId: l, removeOption: a, renderOptions: x, selected: y, selectedIDs: f, setSelectedIds: j, normalizedOptions: s, title: E, visibility: S, active: u, hasOptions: $, hasActualValue: _, optionsClassName: A, selectedText: T, disabled: C, loading: P, error: I, registerOption: F, unregisterOption: Z, handleBlur: Q, handleFocus: D, toggleVisibility: U, handleKeyDown: c, handleListScroll: G, setAnimationFinished: ue, clear: M, children: V, placeholder: he, className: q, style: ne, duration: L, easing: ae, offset: b, animateOpacity: W, unmount: t, OpenIcon: i, ClearIcon: h, DelIcon: v, renderIcon: de, hasMore: o, loadButton: m, deleting: g, setDeleting: N, showDelete: k }) => {
698
- const [Y, fe] = oe(!1), [le, je] = oe(null), [ee, d] = oe(!1), [O, se] = oe({}), [xe, z] = oe(null), [ke, X] = oe(null), [Ee, Ne] = oe(!1), [te, _e] = oe(!1), Ae = re(!0), Re = re(null), ze = R((J) => {
699
- a ? a(J) : j((B) => B.filter((ce) => ce.id !== J));
700
- }, [a, j]), Je = R((J) => {
701
- if (g) {
702
- J.stopPropagation(), J.preventDefault(), N(!1);
703
- return;
704
- }
705
- U(J);
706
- }, [g, U]), Ue = R((J, B) => {
707
- se((ce) => ce[J] === B ? ce : { ...ce, [J]: B });
708
- }, []);
709
- We(() => {
710
- const J = Re.current;
711
- if (!J) return;
712
- const B = new ResizeObserver((ce) => {
713
- window.requestAnimationFrame(() => {
714
- if (!Array.isArray(ce) || !ce.length) return;
715
- const Ie = ce[0].contentRect.height;
716
- je(Ie);
717
- });
718
- });
719
- return B.observe(J), () => B.disconnect();
720
- }, []), pe(() => {
721
- Ae.current = !1, r && (typeof r == "function" ? r(r.current) : r.current = r.current);
722
- }, [r]), pe(() => {
723
- g && S && U() && U?.()(g && f?.length === 0) && N(!1), X(null);
724
- }, [f?.length, g]), We(() => {
725
- const J = Re.current;
726
- if (!J || !f?.length || g) {
727
- f?.length || d({ state: !1, id: null, width: 0 });
728
- return;
729
- }
730
- const B = Array.from(J.children).filter((we) => we.classList.contains("rac-multiple-option")), ce = J.clientWidth;
731
- if (B.length > f.length) {
732
- const we = new Set(f.map((be) => be.id)), Se = B.findIndex((be) => !we.has(be.id));
733
- if (Se === -1) return;
734
- const ge = B[Se], me = B[Se - 1];
735
- if (!(me && ge.offsetTop !== me.offsetTop)) {
736
- d({ state: !1, id: null, width: 0 });
833
+ wn(y)
834
+ ) : null;
835
+ }), mt = [];
836
+ function Sn({ props: e, jsxOptions: t, state: n, setState: r, setVisibility: s, loadMoreOnce: c }) {
837
+ const { onChange: i, disabled: a, loading: o, error: p, multiple: l, childrenFirst: g, groupsClosed: y, hasMore: h, loadButton: S, placeholder: w, selectedText: f, texts: m } = e, { disabledOption: D, emptyOption: L, invalidOption: C, emptyGroup: j } = m, { loadPending: M, internalValue: u, toggledGroups: x, picked: E } = n, $ = Ne(e.options), k = Ne(e.value), V = k !== void 0, I = V ? k : u, A = M ? m.loadingMore : m.loadMore, b = _(() => Gt({
838
+ options: $,
839
+ jsxOptions: t,
840
+ childrenFirst: g,
841
+ hasMore: h,
842
+ loadButton: S,
843
+ loadPending: M,
844
+ loadingTitle: A,
845
+ emptyOption: L,
846
+ invalidOption: C,
847
+ disabledOption: D,
848
+ emptyGroup: j
849
+ }), [$, t, g, h, S, M, A, L, C, D, j]), d = _(() => new Set(
850
+ b.filter((N) => N.groupHeader && !N.disabled && y === x.has(N.name)).map((N) => N.name)
851
+ ), [b, x, y]), { selected: v, selectedIDs: T } = _(() => zt(I, b, l, E), [I, b, l, E]), H = b.length > 0, J = !a && H, P = I != null && !(Array.isArray(I) && !I.length) && !(Se(I) && !Object.keys(I).length), G = P && f ? null : v, ee = _(() => P && f ? f : v ? v.name : p ? m.error : o ? m.loading : a ? m.disabled : H ? w : m.empty, [p, o, a, P, f, v, H, w, m]), z = (N) => r((W) => {
852
+ const te = new Set(W.toggledGroups);
853
+ return te.has(N) ? te.delete(N) : te.add(N), { toggledGroups: te };
854
+ }), R = (N, W, te) => {
855
+ r(V ? { picked: te } : { internalValue: N, picked: te }), i?.(N, W);
856
+ }, pe = (N) => R(N.map((W) => W.original), N.map((W) => W.userId), N.map((W) => W.id)), We = Re({
857
+ toggleGroup: z,
858
+ selectOption: (N, W) => {
859
+ if (N.groupHeader) {
860
+ Q(W), N.disabled || z(N.name);
737
861
  return;
738
862
  }
739
- const Fe = ut(B), Me = Object.keys(Fe).map(Number).sort((be, Te) => be - Te), H = Me.indexOf(ge.offsetTop);
740
- if (H <= 0) {
741
- d({ state: !1, id: null, width: 0 });
863
+ if (N.disabled || N.loadMore) {
864
+ Q(W), N.loadMore && !N.loading && c();
742
865
  return;
743
866
  }
744
- const K = Me[H - 1], ie = Fe[K], ye = ce - ie;
745
- Ie(me?.id || null, !0, ye);
746
- } else if (B.length === f.length) {
747
- const we = B[B.length - 1], Se = f[f.length - 1]?.id, ge = O[Se];
748
- if (!ge) return;
749
- const me = we?.firstElementChild || we, Pe = ct(me), Fe = ct(we), Me = B.slice(0, -1), H = ut(Me), K = Object.keys(H).map(Number).sort((Te, w) => Te - w);
750
- let ie = ce;
751
- if (K.length > 0) {
752
- const Te = Math.max(...K);
753
- ie = ce - (H[Te] || 0);
754
- }
755
- const ye = ge + Pe + Fe > ie, be = f[f.length - 2]?.id;
756
- Ie(be, ye, ie);
757
- }
758
- function Ie(we, Se, ge) {
759
- d((me) => me.id === we && me.state === Se && me.width === ge ? me : { state: Se, id: we, width: ge });
760
- }
761
- }, [f, O, g]);
762
- const Oe = h && _ && $ && !C && !P && !I && !g, Ce = i && u && !g, Ze = f?.map((J, B) => {
763
- const ce = B === f.length - 1;
764
- return /* @__PURE__ */ p.jsx(
765
- Ot,
766
- {
767
- normalizedOptions: s,
768
- registerItemWidth: Ue,
769
- setActiveHoverId: X,
770
- swiped: xe === J.id,
771
- activeHoverId: ke,
772
- setVisibility: n,
773
- deleteInline: e,
774
- setDeleting: N,
775
- setEntering: _e,
776
- setLeaving: Ne,
777
- renderIcon: de,
778
- showDelete: k,
779
- selectRef: r,
780
- setSpacer: d,
781
- onSwipe: z,
782
- delSpacer: ce,
783
- duration: L,
784
- deleting: g,
785
- swipedId: xe,
786
- leaving: Ee,
787
- element: J,
788
- DelIcon: v,
789
- spacer: ee,
790
- remove: ze,
791
- index: B
792
- },
793
- J.id ?? B
794
- );
795
- });
796
- return /* @__PURE__ */ p.jsxs(rt.Provider, { value: { registerOption: F, unregisterOption: Z }, children: [
797
- V,
798
- /* @__PURE__ */ p.jsxs(
799
- "div",
800
- {
801
- ref: r,
802
- style: {
803
- "--rac-duration-fast": "calc(var(--rac-duration) * 0.5)",
804
- "--rac-duration-slow": "calc(var(--rac-duration) * 1.3)",
805
- "--rac-duration-base": "var(--rac-duration)",
806
- "--rac-duration": `${L}ms`,
807
- ...ne
808
- },
809
- className: `
810
- ${!$ || C ? "rac-disabled-style" : ""}
811
- ${P ? "rac-loading-style" : ""}
812
- ${I ? "rac-error-style" : ""}
813
- ${q}
814
- rac-select
815
- `,
816
- ...u && {
817
- onKeyDown: c,
818
- onFocus: D,
819
- onClick: Je,
820
- onBlur: Q
821
- },
822
- "aria-disabled": C || !$,
823
- "aria-controls": `${l}-listbox`,
824
- tabIndex: u ? 0 : -1,
825
- "aria-expanded": S,
826
- "aria-label": he,
827
- "aria-haspopup": "listbox",
828
- role: "combobox",
829
- children: [
830
- /* @__PURE__ */ p.jsx(
831
- "div",
832
- {
833
- className: `rac-select-title-wrapper
834
- ${!I && !P && y?.type === "boolean" ? y.raw ? "rac-true-option" : "rac-false-option" : ""}
835
- `,
836
- style: {
837
- alignItems: f?.length && !T ? "flex-start" : "center",
838
- height: le ? `${le}px` : "auto"
839
- },
840
- children: /* @__PURE__ */ p.jsx(
841
- "div",
842
- {
843
- style: {
844
- alignItems: f?.length && !T ? "flex-start" : "center",
845
- height: P ? "100%" : "auto"
846
- },
847
- className: "rac-select-title",
848
- ref: Re,
849
- children: /* @__PURE__ */ p.jsx(
850
- st,
851
- {
852
- enter: !Ae.current,
853
- component: null,
854
- appear: !1,
855
- children: f?.length && !T && !P ? Ze : /* @__PURE__ */ p.jsxs(
856
- xt,
857
- {
858
- className: "rac-title-container",
859
- duration: L,
860
- widthMode: !0,
861
- children: [
862
- /* @__PURE__ */ p.jsx("span", { className: "rac-title-text", children: E }),
863
- /* @__PURE__ */ p.jsx(
864
- He,
865
- {
866
- className: "rac-loading-container",
867
- visibility: P && !I,
868
- duration: L,
869
- children: /* @__PURE__ */ p.jsxs("span", { className: "rac-loading-dots", children: [
870
- /* @__PURE__ */ p.jsx("i", {}),
871
- /* @__PURE__ */ p.jsx("i", {}),
872
- /* @__PURE__ */ p.jsx("i", {})
873
- ] })
874
- }
875
- )
876
- ]
877
- },
878
- E
879
- )
880
- }
881
- )
882
- }
883
- )
884
- }
885
- ),
886
- /* @__PURE__ */ p.jsx(
887
- He,
888
- {
889
- visibility: Oe || Ce,
890
- className: "rac-select-buttons",
891
- children: /* @__PURE__ */ p.jsxs(st, { component: null, children: [
892
- Oe && /* @__PURE__ */ p.jsx(
893
- He,
894
- {
895
- style: { display: "grid" },
896
- duration: L,
897
- children: de(h, {
898
- className: "rac-select-cancel",
899
- onMouseDown: (J) => {
900
- J.preventDefault(), J.stopPropagation();
901
- },
902
- onClick: M
903
- })
904
- },
905
- "clear-icon"
906
- ),
907
- " ",
908
- Ce && /* @__PURE__ */ p.jsx(
909
- He,
910
- {
911
- style: { display: "grid" },
912
- duration: L,
913
- children: de(i, { className: `rac-select-arrow ${S ? "--open" : ""} ${Y ? "" : "--up"}` })
914
- },
915
- "open-button"
916
- )
917
- ] })
918
- }
919
- ),
920
- /* @__PURE__ */ p.jsx(
921
- Pt,
922
- {
923
- style: { "--rac-duration": `${L}ms`, ...ne },
924
- visibility: S && s.length,
925
- onAnimationDone: () => ue(!0),
926
- setBottomDirection: fe,
927
- animateOpacity: W,
928
- className: A,
929
- selectRef: r,
930
- duration: L,
931
- unmount: t,
932
- easing: ae,
933
- offset: b,
934
- children: /* @__PURE__ */ p.jsxs(
935
- "div",
936
- {
937
- onScroll: G,
938
- className: "rac-select-list",
939
- "aria-label": "Options",
940
- role: "listbox",
941
- tabIndex: "-1",
942
- children: [
943
- x,
944
- !m && o && /* @__PURE__ */ p.jsxs(
945
- "div",
946
- {
947
- className: "rac-select-option rac-disabled-option rac-loading-option",
948
- style: { justifyContent: "initial", alignItems: "end", gap: 0 },
949
- onClick: (J) => J.stopPropagation(),
950
- children: [
951
- /* @__PURE__ */ p.jsx("span", { className: "rac-loading-option-title", children: "Loading" }),
952
- /* @__PURE__ */ p.jsx("div", { className: "rac-loading-container", children: /* @__PURE__ */ p.jsxs(
953
- "span",
954
- {
955
- style: { paddingBottom: "0.1em" },
956
- className: "rac-loading-dots",
957
- children: [
958
- /* @__PURE__ */ p.jsx("i", {}),
959
- /* @__PURE__ */ p.jsx("i", {}),
960
- /* @__PURE__ */ p.jsx("i", {})
961
- ]
962
- }
963
- ) })
964
- ]
965
- }
966
- )
967
- ]
968
- }
969
- )
970
- }
971
- )
972
- ]
973
- }
974
- )
975
- ] });
976
- }), Ht = ["group", "disabled", "options", "items", "children"], qe = ["name", "label", "id", "value"], dt = [], Ge = (e, r = !1) => {
977
- if (r && typeof e.group == "string") return e.group;
978
- const n = qe.find((a) => e[a] != null && e[a] !== "");
979
- if (n) return String(e[n]);
980
- const l = Object.entries(e).find(([a, x]) => !Ht.includes(a) && x != null && x !== "");
981
- return l ? String(l[1]) : null;
982
- };
983
- function It({
984
- options: e = dt,
985
- jsxOptions: r = dt,
986
- value: n,
987
- onChange: l,
988
- disabled: a = !1,
989
- loading: x = !1,
990
- error: y = !1,
991
- multiple: f = !1,
992
- placeholder: j = "Choose option",
993
- emptyText: s = "No options",
994
- disabledText: E = "Disabled",
995
- loadingText: S = "Loading",
996
- errorText: u = "Failed to load",
997
- disabledOption: $ = "Disabled option",
998
- emptyOption: _ = "Empty option",
999
- invalidOption: A = "Invalid option",
1000
- setVisibility: T,
1001
- hasMore: C,
1002
- loadButton: P,
1003
- setLoadingTitle: I,
1004
- loadingTitle: F,
1005
- loadMoreText: Z,
1006
- loadMore: Q,
1007
- childrenFirst: D = !1,
1008
- groupsClosed: U = !1
1009
- }) {
1010
- const c = n !== void 0, [G, ue] = oe(() => {
1011
- const o = /* @__PURE__ */ new Set();
1012
- if (U) return o;
1013
- const m = (g) => {
1014
- Array.isArray(g) && g.forEach((N) => {
1015
- if (N && typeof N == "object") {
1016
- if (("options" in N || "group" in N && !qe.some((Y) => Y in N)) && !N.disabled) {
1017
- const Y = Ge(N, !0) || "Empty group";
1018
- o.add(Y);
1019
- }
1020
- N.options && m(N.options);
1021
- }
1022
- });
1023
- };
1024
- return m(e), o;
1025
- }), M = re(null), V = R((o) => {
1026
- ue((m) => {
1027
- const g = new Set(m);
1028
- return g.has(o) ? g.delete(o) : g.add(o), g;
1029
- });
1030
- }, []), he = R((o, m, g = "n", N = null, k = !1) => {
1031
- const Y = `${g}-${m}`;
1032
- if (o == null || o === "" || o === void 0)
1033
- return {
1034
- name: _,
1035
- disabled: !0,
1036
- type: "normal",
1037
- groupDisabled: k,
1038
- userId: null,
1039
- raw: o,
1040
- group: N,
1041
- id: Y
1042
- };
1043
- if (typeof o == "function")
1044
- return { id: Y, userId: null, name: A, raw: o, disabled: !0, invalid: !0, type: "normal", group: N };
1045
- if (typeof o == "object" && !Array.isArray(o)) {
1046
- const fe = N || o.group || null, le = k || o.disabled === !0, je = o.id ?? o.value ?? o.name ?? o.label, ee = o.value !== void 0 ? o.value : o.id !== void 0 ? o.id : o;
1047
- let d = Ge(o) || (le ? $ : _);
1048
- return {
1049
- id: Y,
1050
- userId: je,
1051
- name: d,
1052
- raw: ee,
1053
- original: o,
1054
- disabled: le || d === _ && !le,
1055
- type: typeof ee == "boolean" ? "boolean" : "normal",
1056
- group: fe,
1057
- groupDisabled: k
1058
- };
1059
- }
1060
- return {
1061
- id: Y,
1062
- userId: o,
1063
- name: String(o),
1064
- raw: o,
1065
- original: o,
1066
- disabled: k,
1067
- type: typeof o == "boolean" ? "boolean" : "normal",
1068
- group: N
1069
- };
1070
- }, [_, A, $]), q = ve(() => {
1071
- const o = /* @__PURE__ */ new Map(), m = [], g = r.map((d, O) => {
1072
- if (d.isGroupMarker) return { ...d, type: "group-marker" };
1073
- const se = !d.label && !d.userId && !d.value && (d.value === void 0 || d.value === null || d.value === "") && !d.hasJsx;
1074
- return {
1075
- ...d,
1076
- id: `jsx-${d.id}`,
1077
- index: O,
1078
- userId: d.userId,
1079
- raw: d.value,
1080
- original: d.value,
1081
- name: se ? _ : d.label || d.userId || String(d.value || ""),
1082
- disabled: !!d.disabled || se,
1083
- type: typeof d.value == "boolean" ? "boolean" : "normal",
1084
- group: d.group || null
1085
- };
1086
- });
1087
- let N = 0;
1088
- const k = (d, O = null, se = !1, xe = "0") => {
1089
- Array.isArray(d) || (d = [d]), d.forEach((z, ke) => {
1090
- const X = `${xe}-${ke}`, Ee = z != null && typeof z == "object" && !Array.isArray(z);
1091
- if (Ee && ("options" in z || "group" in z && !qe.some((te) => te in z))) {
1092
- const te = Ge(z, !0) || "Empty group";
1093
- o.has(te) || o.set(te, { disabled: !!z.disabled, closedByDefault: !!z.disabled || U, items: [] }), z.options ? k(z.options, te, se || !!z.disabled, X) : m.push({ id: `empty-${te}-${X}`, name: te, group: te, isPlaceholder: !0, type: "group-marker", index: N++ });
1094
- } else if (Ee && !qe.some((te) => te in z) && !z.group)
1095
- Object.entries(z).forEach(([te, _e], Ae) => {
1096
- const Re = he(_e, `${X}-${Ae}`, "default", O, se);
1097
- m.push({ ...Re, index: N++ });
1098
- });
1099
- else {
1100
- const te = he(z, X, "default", O, se);
1101
- m.push({ ...te, index: N++ });
1102
- }
1103
- });
1104
- };
1105
- k(e);
1106
- const Y = D ? [...g, ...m] : [...m, ...g];
1107
- if (!M.current)
1108
- M.current = new Map(Y.map((d, O) => [d.id, O]));
1109
- else {
1110
- let d = !1;
1111
- if (Y.forEach((O) => {
1112
- M.current.has(O.id) || (d = !0);
1113
- }), d) {
1114
- const O = /* @__PURE__ */ new Map();
1115
- Y.forEach((se, xe) => {
1116
- O.set(se.id, xe);
1117
- }), M.current = O;
1118
- }
1119
- }
1120
- const fe = [...Y].sort((d, O) => {
1121
- const se = M.current.get(d.id) ?? 999999, xe = M.current.get(O.id) ?? 999999;
1122
- return se - xe;
1123
- }), le = [], je = /* @__PURE__ */ new Set();
1124
- fe.forEach((d) => {
1125
- if (!d.group)
1126
- le.push({ type: "item", data: d });
1127
- else {
1128
- je.has(d.group) || (je.add(d.group), le.push({ type: "group", name: d.group }));
1129
- const O = o.get(d.group) || { items: [] };
1130
- o.has(d.group) || o.set(d.group, O), d.isGroupMarker ? (O.className = d.className, O.style = d.style, d.disabled && (O.disabled = !0)) : d.isPlaceholder || O.items.push(d);
1131
- }
1132
- });
1133
- const ee = [];
1134
- return le.forEach((d) => {
1135
- if (d.type === "item")
1136
- ee.push(d.data);
1137
- else {
1138
- const O = d.name, se = o.get(O), xe = G.has(O);
1139
- ee.push({
1140
- className: se?.className || "",
1141
- id: `group-header-${O}`,
1142
- disabled: !!se?.disabled,
1143
- style: se?.style || {},
1144
- groupHeader: !0,
1145
- name: O,
1146
- type: "group",
1147
- hidden: !1,
1148
- expanded: xe
1149
- }), se?.items.forEach((z) => {
1150
- const ke = G.size > 0 ? !xe : !!U;
1151
- ee.push({ ...z, hidden: ke });
1152
- });
1153
- }
1154
- }), C && P && ee.push({
1155
- id: "special-load-more-id",
1156
- name: F,
1157
- loadMore: !0,
1158
- loading: F === Z,
1159
- type: "special"
1160
- }), ee;
1161
- }, [e, r, he, D, C, P, F, Z, U, G, _]), ne = R(() => {
1162
- if (n == null || Array.isArray(n) && n.length === 0)
1163
- return { initialId: null, initialIDs: [] };
1164
- const o = /* @__PURE__ */ new Set(), m = (g, N) => {
1165
- let k = q.find((fe) => fe.original === g && !o.has(fe.id));
1166
- if (!k && typeof g == "object")
1167
- try {
1168
- const fe = JSON.stringify(g);
1169
- k = q.find(
1170
- (le) => le.original && typeof le.original == "object" && JSON.stringify(le.original) === fe && !o.has(le.id)
1171
- );
1172
- } catch {
1173
- }
1174
- if (k)
1175
- return o.add(k.id), k;
1176
- const Y = typeof g == "object" ? g.id || g.value || JSON.stringify(g) : String(g);
1177
- return typeof g == "object" && g !== null ? {
1178
- id: `virtual-${Y}-${N}`,
1179
- name: Ge(g) || String(g.id || "Selected Object"),
1180
- raw: g.value ?? g.id ?? g,
1181
- original: g,
1182
- userId: g.id ?? g.value ?? null,
1183
- virtual: !0
1184
- } : {
1185
- id: `virtual-${Y}-${N}`,
1186
- name: String(g),
1187
- raw: g,
1188
- original: g,
1189
- userId: g,
1190
- virtual: !0
1191
- };
1192
- };
1193
- if (f)
1194
- return { initialId: null, initialIDs: (Array.isArray(n) ? n : [n]).map((k, Y) => m(k, Y)) };
1195
- {
1196
- const g = Array.isArray(n) ? n[0] : n;
1197
- return { initialId: m(g, 0).id, initialIDs: [] };
1198
- }
1199
- }, [c, n, q, f]), [L, ae] = oe(() => ne().initialId), [b, W] = oe(() => ne().initialIDs), t = ve(() => {
1200
- const o = q.find((m) => m.id === L);
1201
- if (o) return o;
1202
- if (!f && L?.startsWith("virtual-")) {
1203
- const m = Array.isArray(n) ? n[0] : n;
1204
- if (m)
1205
- return {
1206
- id: L,
1207
- name: typeof m == "object" ? Ge(m) : String(m),
1208
- original: m
1209
- };
1210
- }
1211
- return null;
1212
- }, [L, q, f, c, n]), i = R((o, m) => {
1213
- if (o.groupHeader) {
1214
- h(m), o.disabled || V(o.name);
1215
- return;
1216
- }
1217
- if (o.disabled || o.loadMore) {
1218
- h(m), o.loadMore && !o.loading && (I(Z), Q());
1219
- return;
1220
- }
1221
- if (f) {
1222
- if (o.disabled || o.groupHeader || o.loadMore) {
1223
- h(m);
867
+ if (l) {
868
+ Q(W);
869
+ const te = T.some((Ee) => Ee.id === N.id);
870
+ pe(te ? T.filter((Ee) => Ee.id !== N.id) : [...T, N]);
1224
871
  return;
1225
872
  }
1226
- h(m);
1227
- const N = b?.some((k) => k.id === o.id) ? b.filter((k) => k.id !== o.id) : [...b, o];
1228
- W(N), l?.(N.map((k) => k.original), N.map((k) => k.userId));
1229
- return;
1230
- }
1231
- ae(o.id), l?.(o.original, o.userId), T(!1);
1232
- }, [l, T, Q, Z, I, V, f, b]), h = R((o) => {
1233
- o?.stopPropagation(), o?.preventDefault();
1234
- }, []), v = R(() => {
1235
- l?.(null, null), ae(null), W([]);
1236
- }, [l]), de = R((o) => {
1237
- const m = b.filter((g) => g.id !== o);
1238
- W(m), l?.(m.map((g) => g.original), m.map((g) => g.userId));
1239
- }, [b, l]);
1240
- return {
1241
- normalizedOptions: q,
1242
- selected: t,
1243
- selectOption: i,
1244
- clear: v,
1245
- removeOption: de,
1246
- hasOptions: q.length > 0,
1247
- active: !y && !x && !a && q.length > 0,
1248
- selectedValue: n,
1249
- placeholder: j,
1250
- emptyText: s,
1251
- disabledText: E,
1252
- loadingText: S,
1253
- errorText: u,
1254
- disabledOption: $,
1255
- emptyOption: _,
1256
- invalidOption: A,
1257
- disabled: a,
1258
- loading: x,
1259
- error: y,
1260
- expandedGroups: G,
1261
- toggleGroup: V,
1262
- selectedIDs: b,
1263
- multiple: f,
1264
- setSelectedIds: W
1265
- };
873
+ v?.id !== N.id && R(N.original, N.userId, [N.id]), s(!1);
874
+ },
875
+ clear: (N) => {
876
+ Q(N), R(l ? [] : null, l ? [] : null, mt);
877
+ },
878
+ removeOption: (N) => pe(T.filter((W) => W.id !== N))
879
+ });
880
+ return { normalizedOptions: b, expandedGroups: d, selected: v, selectedIDs: T, hasOptions: H, active: J, hasActualValue: P, title: ee, valueOption: G, actions: We };
1266
881
  }
1267
- function Ft({ disabled: e, open: r, setOpen: n, options: l = [], selectOption: a, setDeleting: x, selected: y, selectedIDs: f, multiple: j, hasMore: s, loadMore: E, loadButton: S, loadButtonText: u, setLoadingTitle: $, loadOffset: _, loadAhead: A, expandedGroups: T, onOpen: C, onClose: P, deleting: I }) {
1268
- const F = re(!1), Z = re(0), Q = re(!1), [D, U] = oe(-1);
1269
- pe(() => {
1270
- Q.current = !1, S && $(u);
1271
- }, [l.length, s, S, u, $]);
1272
- const c = R(() => {
1273
- !s || Q.current || (Q.current = !0, E());
1274
- }, [s, E]), G = R((b) => {
1275
- if (S || !s || Q.current) return;
1276
- const { scrollTop: W, scrollHeight: t, clientHeight: i } = b.currentTarget(t - W <= i + _) && c();
1277
- }, [S, s, _, c]);
1278
- pe(() => {
1279
- !S && r && s && D >= l.length - A && c();
1280
- }, [D, r, s, l.length, A, S, c]), pe(() => {
1281
- const b = () => {
1282
- Z.current = Date.now();
1283
- };
1284
- return window.addEventListener("focus", b), () => window.removeEventListener("focus", b);
1285
- }, []), pe(() => {
1286
- if (!r) {
1287
- U(-1);
1288
- return;
1289
- }
1290
- const b = l[D], W = b && !b.hidden && !b.groupHeader;
1291
- if (D >= 0 && D < l.length && W) return;
1292
- let t = -1;
1293
- if (y && !j) {
1294
- const i = j ? y[0] : y;
1295
- i && (t = l.findIndex((h) => h.id === i.id && !h.disabled && !h.hidden && !h.groupHeader));
1296
- }
1297
- if (j && f.length) {
1298
- const i = new Set(f.map((h) => h.id));
1299
- t = l.findIndex(
1300
- (h) => i.has(h.id) && !h.disabled && !h.hidden && !h.groupHeader
1301
- );
1302
- }
1303
- t === -1 && (t = l.findIndex((i) => !i.disabled && !i.hidden && !i.groupHeader)), U(t);
1304
- }, [r, l, y]);
1305
- const ue = R((b, W) => {
1306
- const t = (v) => v && !v?.groupHeader && (!v?.group || T?.has(v?.group)) && !v?.disabled && !v?.loading, i = l.length;
1307
- if (i === 0) return -1;
1308
- let h = b;
1309
- for (let v = 0; v < i; v++) {
1310
- if (h = (h + W + i) % i, !S && s && (W > 0 && h === 0 || W < 0 && h === i - 1))
1311
- return b;
1312
- if (t(l[h])) return h;
1313
- }
1314
- return b;
1315
- }, [l, s, S, T]), M = R((b) => {
1316
- const W = b.relatedTarget?.closest(".rac-options");
1317
- !b.currentTarget.contains(b.relatedTarget) && !W && (n(!1), x(!1));
1318
- }, [n]), V = R(() => {
1319
- e || I || document.hidden || Date.now() - Z.current < 100 || r || (n(!0), F.current = !0, setTimeout(() => F.current = !1, 200));
1320
- }, [e, r, n, I]), he = re(r), q = re(C), ne = re(P);
1321
- pe(() => {
1322
- q.current = C, ne.current = P;
1323
- }, [C, P]), pe(() => {
1324
- he.current !== r && (r ? q.current?.() : ne.current?.(), he.current = r);
1325
- }, [r]);
1326
- const L = R((b) => {
1327
- e || I || b?.target?.closest(".rac-select-cancel") || F.current || n(!r);
1328
- }, [e, r, n, C, P, I]), ae = R((b) => {
1329
- if (!e)
1330
- switch (b.key) {
1331
- case "Enter":
1332
- case " ":
1333
- b.preventDefault(), r ? D !== -1 && l[D] && a(l[D], b) : n(!0);
1334
- break;
1335
- case "Escape":
1336
- b.preventDefault(), n(!1);
1337
- break;
1338
- case "ArrowDown":
1339
- b.preventDefault(), r ? U((W) => ue(W, 1)) : n(!0);
1340
- break;
1341
- case "ArrowUp":
1342
- b.preventDefault(), r ? U((W) => ue(W, -1)) : n(!0);
1343
- break;
1344
- case "Tab":
1345
- r && n(!1);
1346
- break;
882
+ const En = (e) => ({
883
+ internalVisibility: !1,
884
+ deleting: !1,
885
+ loadPending: !1,
886
+ toggledGroups: /* @__PURE__ */ new Set(),
887
+ internalValue: e.defaultValue,
888
+ picked: mt
889
+ });
890
+ function kn(e, t) {
891
+ const { ref: n, open: r, onOpenChange: s, hasMore: c, loadMore: i, loadButton: a, error: o, disabled: p, loading: l } = e, g = wt(), y = _(() => g.replace(/:/g, ""), [g]), h = F(null);
892
+ xt(n, () => h.current);
893
+ const [S, w] = Ot(kt, e, En), { internalVisibility: f, deleting: m, loadPending: D } = S, [L] = U(() => Me(At)), [C] = U(() => Me({ upward: !1 })), j = r !== void 0, M = j ? !!r : f, u = F(!1), x = F(!1), E = Re({
894
+ // [DOC: select-store]
895
+ setVisibility: (R) => {
896
+ R !== M && (j || w({ internalVisibility: R }), s?.(R));
897
+ },
898
+ // [DOC: select-store]
899
+ loadMoreOnce: () => {
900
+ if (!c || u.current) return;
901
+ if (!i) return le("no loadMore", "`hasMore` is set, but there is no `loadMore` to call.");
902
+ u.current = !0, w({ loadPending: !0 });
903
+ const R = () => w({ loadPending: !1 });
904
+ try {
905
+ i()?.then?.(R, R);
906
+ } catch (pe) {
907
+ u.current = !1, R(), (globalThis.reportError ?? console.error)(pe);
1347
908
  }
1348
- }, [e, r, n, D, l, a, ue]);
1349
- return ve(() => ({ handleBlur: M, handleFocus: V, toggleVisibility: L, handleKeyDown: ae, highlightedIndex: D, setHighlightedIndex: U, handleListScroll: G }), [M, V, L, ae, D, G]);
1350
- }
1351
- function Mt({ visibility: e, children: r, duration: n = 300, className: l }) {
1352
- const a = re(null), x = R(() => {
1353
- if (!a.current) return { top: "0px", bottom: "0px" };
1354
- const y = window.getComputedStyle(a.current);
1355
- return { top: y.marginTop, bottom: y.marginBottom };
1356
- }, []);
1357
- return /* @__PURE__ */ p.jsx(
1358
- Ke,
1359
- {
1360
- onEnter: () => {
1361
- a.current.style.height = "0px", a.current.style.marginTop = "0px", a.current.style.marginBottom = "0px";
1362
- },
1363
- onEntering: () => {
1364
- const { top: y, bottom: f } = x();
1365
- a.current.style.height = a.current.scrollHeight + "px", a.current.style.marginBottom = f, a.current.style.marginTop = y;
1366
- },
1367
- onEntered: () => a.current.style.height = "auto",
1368
- onExit: () => {
1369
- const { top: y, bottom: f } = x();
1370
- a.current.style.height = a.current.scrollHeight + "px", a.current.style.marginBottom = f, a.current.style.marginTop = y, a.current.offsetHeight;
1371
- },
1372
- onExiting: () => {
1373
- a.current.style.height = "0px", a.current.style.marginTop = "0px", a.current.style.marginBottom = "0px";
1374
- },
1375
- classNames: "rac-slide-down",
1376
- timeout: n,
1377
- nodeRef: a,
1378
- in: e,
1379
- unmountOnExit: !0,
1380
- children: /* @__PURE__ */ p.jsx(
1381
- "div",
1382
- {
1383
- style: {
1384
- transition: `height ${n}ms ease, margin ${n}ms ease`,
1385
- overflow: "hidden"
1386
- },
1387
- className: `${l} rac-slide-down-enter-done`,
1388
- ref: a,
1389
- tabIndex: -1,
1390
- children: r
1391
- }
1392
- )
1393
- }
1394
- );
1395
- }
1396
- const et = (e, r = "invalid-option", n = "") => {
1397
- const l = n ? n.replace(/:/g, "") : "";
1398
- if (typeof e != "string" || !e.trim())
1399
- return l ? `${r}-${l}` : `${r}-${Math.random().toString(36).slice(2, 8)}`;
1400
- const a = e.normalize("NFKD").replace(/[\u0300-\u036f]/g, "").replace(/\s+/g, "-").replace(/[^\p{L}\p{N}-]+/gu, "").toLowerCase();
1401
- return a ? a || `${r}-${Math.random().toString(36).slice(2, 8)}` : l ? `${r}-${l}` : `${r}-${Math.random().toString(36).slice(2, 8)}`;
1402
- }, Ve = (e, r) => {
1403
- if (!e) return null;
1404
- const n = (l = {}) => ({
1405
- ...r,
1406
- ...l,
1407
- style: {
1408
- ...r?.style,
1409
- ...l?.style
1410
- }
909
+ },
910
+ setListReady: (R) => L.set({ ready: R }),
911
+ setDeleting: (R) => w({ deleting: R })
912
+ }), $ = Sn({ props: e, jsxOptions: t, state: S, setState: w, setVisibility: E.setVisibility, loadMoreOnce: E.loadMoreOnce }), { normalizedOptions: k, expandedGroups: V, selected: I, selectedIDs: A, hasOptions: b, active: d, hasActualValue: v, title: T, valueOption: H, actions: J } = $, P = d && M, G = Vt({
913
+ props: e,
914
+ state: S,
915
+ setState: w,
916
+ normalizedOptions: k,
917
+ expandedGroups: V,
918
+ selected: I,
919
+ selectedIDs: A,
920
+ visibility: P,
921
+ highlightStore: L,
922
+ setVisibility: E.setVisibility,
923
+ loadMoreOnce: E.loadMoreOnce,
924
+ modelActions: J
1411
925
  });
1412
- if (typeof e == "string") return /* @__PURE__ */ p.jsx("img", { src: e, ...n(), alt: "" });
1413
- if (jt(e)) return St(e, n(e.props));
1414
- if (typeof e == "function" || typeof e == "object" && e.$$typeof) {
1415
- const l = e;
1416
- return /* @__PURE__ */ p.jsx(l, { ...n() });
926
+ oe(() => {
927
+ w({ loadPending: !1 });
928
+ }, [k.length, c, a]), oe(() => {
929
+ D || (u.current = !1);
930
+ }, [D]), oe(() => {
931
+ P && h.current && document.activeElement !== h.current && h.current.focus(), P || L.set({ index: -1, ready: !1 });
932
+ }, [P, L]), oe(() => {
933
+ x.current && !d && E.setVisibility(!1), x.current = d;
934
+ }, [d, E]);
935
+ const ee = _(() => ({ ...E, ...J, ...G }), [E, J, G]), z = _(() => ({
936
+ visibility: P,
937
+ deleting: m,
938
+ loadPending: D,
939
+ expandedGroups: V,
940
+ selectedIDs: A,
941
+ normalizedOptions: k,
942
+ selected: I,
943
+ hasOptions: b,
944
+ active: d,
945
+ hasActualValue: v,
946
+ title: T,
947
+ valueOption: H,
948
+ disabled: p,
949
+ loading: l,
950
+ error: o
951
+ }), [P, m, D, V, A, k, I, b, d, v, T, H, p, l, o]);
952
+ return { selectId: y, selectRef: h, highlightStore: L, positionStore: C, state: z, actions: ee };
953
+ }
954
+ const Cn = {}, Z = (e) => e != null && e !== "", Pe = (e) => e ? typeof e == "string" || typeof e == "number" ? String(e) : Array.isArray(e) ? e.map(Pe).join(" ").replace(/\s+/g, " ").trim() : xe(e) ? Pe(e.props.children) : "" : "", Tn = ({ name: e, label: t, id: n, value: r, className: s, style: c, children: i, disabled: a, group: o }, p, l) => {
955
+ const g = Pe(i), y = r !== void 0 ? r : g;
956
+ return i != null && !g && !Z(t) && !Z(e) && !Z(n) && !Z(r) && le("no text", "<Option> has content but no text to show in the title or chips. Add a `label` (or `value`), or enable `valueAsOption`."), {
957
+ id: Z(n) ? String(n) : p,
958
+ userId: Z(n) ? n : y,
959
+ value: y,
960
+ label: Z(t) ? String(t) : Z(e) ? String(e) : g || (Z(n) ? String(n) : ""),
961
+ jsx: i,
962
+ hasJsx: i != null,
963
+ className: s,
964
+ style: c,
965
+ disabled: !!a,
966
+ group: o || l || null
967
+ };
968
+ }, Mn = ({ name: e, label: t, value: n, id: r, disabled: s, className: c = "", style: i = Cn }, a) => {
969
+ const o = e ?? t ?? r ?? n;
970
+ return { disabled: !!s, isGroupMarker: !0, group: Z(o) ? String(o) : a, className: c, style: i };
971
+ }, In = (e) => `<${typeof e == "string" ? e : e?.displayName || e?.name || "Component"}>`, me = (e, t, n = null, r = "o", s = []) => (it.toArray(e).forEach((c) => {
972
+ if (!xe(c)) {
973
+ le("text", `Text inside <Select> or <OptGroup> is ignored ("${String(c).slice(0, 30)}"). Wrap it in <Option>.`);
974
+ return;
1417
975
  }
1418
- return null;
1419
- }, Wt = (e, r, n, l, a, x, y, f) => {
1420
- const j = f?.some((s) => s.id === e.id);
1421
- return e.groupHeader ? "rac-select-option rac-group-option" : [
1422
- "rac-select-option",
1423
- e.className,
1424
- (j || l === e.id) && "rac-selected",
1425
- r === n && "rac-highlighted",
1426
- (e.disabled || e.loading) && "rac-disabled-option",
1427
- (e.invalid || e.name === y) && "rac-invalid-option",
1428
- e.loadMore && a === x && "rac-loading-option",
1429
- typeof e.raw == "boolean" && (e.raw ? "rac-true-option" : "rac-false-option")
1430
- ].filter(Boolean).join(" ");
1431
- }, zt = pt(({
1432
- unmount: e,
1433
- children: r,
1434
- visibility: n,
1435
- setVisibility: l = () => {
1436
- },
1437
- ownBehavior: a = !1,
1438
- duration: x = 300,
1439
- easing: y = "ease-in",
1440
- offset: f = 1,
1441
- animateOpacity: j = !0,
1442
- style: s = {},
1443
- className: E = "",
1444
- OpenIcon: S = kt,
1445
- ClearIcon: u = lt,
1446
- DelIcon: $ = lt,
1447
- Checkmark: _ = _t,
1448
- Checkbox: A = void 0,
1449
- hasMore: T = !1,
1450
- loadMore: C = () => console.warn("loadMore not implemented"),
1451
- loadButton: P = !1,
1452
- loadButtonText: I = "Load more",
1453
- loadMoreText: F = "Loading",
1454
- selectedText: Z = void 0,
1455
- loadOffset: Q = 100,
1456
- loadAhead: D = 3,
1457
- optionsClassName: U = "",
1458
- onOpen: c = () => {
1459
- },
1460
- onClose: G = () => {
976
+ const i = `${r}-${String(c.key).slice(1).replace(/[:$]/g, (o) => o === ":" ? "-" : "k").replace(/[^\p{L}\p{N}-]/gu, "")}`, a = c.type?.racKind;
977
+ if (c.type === at) me(c.props.children, t, n, i, s);
978
+ else if (a === "option") s.push(Tn(c.props, i, n));
979
+ else if (a === "define") me(c.type.racRender(c.props), t, n, i, s);
980
+ else if (a === "group") {
981
+ const o = Mn(c.props, t);
982
+ s.push(o), me(c.props.children, t, o.group, i, s);
983
+ } else {
984
+ const o = In(c.type);
985
+ le(`child ${o}`, `${o} inside <Select> is ignored: only <Option/>, <OptGroup/> and defineOption() components are read. Put custom content inside <Option>, or wrap the component with defineOption().`);
986
+ }
987
+ }), s), Nn = /* @__PURE__ */ new Set(["ref", "options", "value", "defaultValue", "onChange", "children", "loadMore", "open", "onOpenChange", "onFocus", "onBlur", "childrenFirst", "groupsClosed", "disabled", "loading", "error"]), An = /^(aria|data)-/, Ce = {
988
+ options: [],
989
+ value: void 0,
990
+ defaultValue: void 0,
991
+ onChange: void 0,
992
+ multiple: !1,
993
+ childrenFirst: !1,
994
+ groupsClosed: !1,
995
+ disabled: !1,
996
+ loading: !1,
997
+ error: !1,
998
+ open: void 0,
999
+ onOpenChange: void 0,
1000
+ onFocus: void 0,
1001
+ onBlur: void 0,
1002
+ id: void 0,
1003
+ name: void 0,
1004
+ required: !1,
1005
+ hasMore: !1,
1006
+ loadMore: void 0,
1007
+ loadButton: !1,
1008
+ loadOffset: 100,
1009
+ loadAhead: 3,
1010
+ placeholder: "Choose option",
1011
+ selectedText: void 0,
1012
+ texts: {
1013
+ empty: "No options",
1014
+ disabled: "Disabled",
1015
+ loading: "Loading",
1016
+ error: "Failed to load",
1017
+ clear: "Clear selection",
1018
+ remove: "Remove",
1019
+ loadMore: "Load more",
1020
+ loadingMore: "Loading",
1021
+ emptyOption: "Empty option",
1022
+ invalidOption: "Invalid option",
1023
+ disabledOption: "Disabled option",
1024
+ emptyGroup: "Empty group",
1025
+ list: "Options"
1461
1026
  },
1462
- deleteInline: ue = !1,
1463
- showDelete: M = !1,
1464
- ...V
1465
- }, he) => {
1466
- const q = yt(), ne = ve(() => q.replace(/:/g, ""), [q]), [L, ae] = oe([]), [b, W] = oe(!1), [t, i] = oe(P ? I : F), [h, v] = oe(!1), de = re(null), [o, m] = oe(!1), g = R((H) => {
1467
- ae((K) => {
1468
- const ie = K.findIndex((ye) => ye.id === H.id);
1469
- if (ie !== -1) {
1470
- const ye = K[ie];
1471
- if (ye.label === H.label && ye.value === H.value && ye.disabled === H.disabled && ye.group === H.group)
1472
- return K;
1473
- const be = [...K];
1474
- return be[ie] = H, be;
1475
- }
1476
- return [...K, H];
1477
- });
1478
- }, []), N = R((H) => {
1479
- ae((K) => {
1480
- const ie = K.filter((ye) => ye.id !== H);
1481
- return ie.length === K.length ? K : ie;
1482
- });
1483
- }, []), k = n !== void 0, Y = ve(() => a || k ? !!n : b, [a, k, n, b]), fe = R((H) => {
1484
- a || (!k && W(H), l?.(H));
1485
- }, [a, k, l]), le = It({
1486
- ...V,
1487
- setVisibility: fe,
1488
- jsxOptions: L,
1489
- hasMore: T,
1490
- loadButton: P,
1491
- loadingTitle: t,
1492
- loadMore: C,
1493
- loadMoreText: F,
1494
- setLoadingTitle: i
1495
- }), { multiple: je, normalizedOptions: ee, selected: d, selectOption: O, clear: se, removeOption: xe, hasOptions: z, active: ke, selectedValue: X, disabled: Ee, loading: Ne, error: te, placeholder: _e, invalidOption: Ae, emptyText: Re, disabledText: ze, loadingText: Je, errorText: Ue, expandedGroups: Oe, selectedIDs: Ce, setSelectedIds: Ze } = le, J = Ft({ setDeleting: m, setLoadingTitle: i, loadButton: P, loadButtonText: I, hasMore: T, loadMore: C, disabled: Ee, multiple: je, open: Y, setOpen: fe, options: ee, selectOption: O, selected: d, loadOffset: Q, loadAhead: D, expandedGroups: Oe, selectedIDs: Ce, onOpen: c, onClose: G, deleting: o }), { handleListScroll: B, handleBlur: ce, handleFocus: Ie, toggleVisibility: we, handleKeyDown: Se, highlightedIndex: ge, setHighlightedIndex: me } = J;
1496
- ht(he, () => de.current), pe(() => {
1497
- if (!Y) {
1498
- v(!1);
1499
- return;
1500
- }
1501
- Y && de.current && document.activeElement !== de.current && de.current.focus();
1502
- }, [Y]), pe(() => {
1503
- (te || Ee || Ne || !z) && fe(!1);
1504
- }, [te, Ee, Ne, z, fe]), pe(() => {
1505
- k && W(!!n);
1506
- }, [n, k]), pe(() => {
1507
- if (Y && h && ge !== -1) {
1508
- const H = ee[ge];
1509
- H && document.getElementById(`${ne}-${et(H.id)}`)?.scrollIntoView({ block: "nearest" });
1510
- }
1511
- }, [ge, Y, h, ee, ne]);
1512
- const Pe = ve(() => X != null && !(Array.isArray(X) && X.length === 0) && !(typeof X == "object" && Object.keys(X).length === 0), [X]), Fe = ve(() => {
1513
- if (te) return Ue;
1514
- if (Ne) return Je;
1515
- if (Ee) return ze;
1516
- if (Pe && Z) return Z;
1517
- if (d) return d.jsx ?? d.name;
1518
- if (Pe) {
1519
- const H = ee.find((K) => K.raw === X);
1520
- return H ? H.name : typeof X == "object" && X !== null ? X.name ?? X.label ?? "Selected Object" : String(X);
1521
- }
1522
- return z ? _e : Re;
1523
- }, [Ee, Ne, te, z, d, X, _e, Ue, Je, ze, Re, Pe, ee]), Me = ve(() => {
1524
- const H = [];
1525
- let K = [], ie = null;
1526
- const ye = ee.reduce((w, $e) => ($e.group && (w[$e.group] = (w[$e.group] || 0) + 1), w), {}), be = (w) => {
1527
- w === null || K.length === 0 || (H.push(
1528
- /* @__PURE__ */ p.jsx(
1529
- Mt,
1530
- {
1531
- visibility: Oe.has(w),
1532
- className: "rac-group-container",
1533
- children: K
1534
- },
1535
- `slide-${w}`
1536
- )
1537
- ), K = []);
1538
- }, Te = (w, $e) => /* @__PURE__ */ p.jsxs(
1539
- "div",
1540
- {
1541
- className: Wt(w, $e, ge, d?.id, t, F, Ae, Ce),
1542
- style: { ...w.style, ...w.loading ? { justifyContent: "initial", alignItems: "end", gap: 0 } : {} },
1543
- onMouseEnter: () => !w.disabled && !w.loading && me($e),
1544
- onClick: (Le) => !w.loading && O(w, Le),
1545
- "aria-disabled": w.disabled || w.loading,
1546
- "aria-selected": d?.id === w.id,
1547
- id: `${ne}-${et(w.id)}`,
1548
- role: "option",
1549
- children: [
1550
- w.jsx ? /* @__PURE__ */ p.jsx("div", { className: "rac-jsx-option", children: w.jsx }) : /* @__PURE__ */ p.jsx("span", { className: "rac-option-title", children: w.name }),
1551
- w.loading && /* @__PURE__ */ p.jsxs(
1552
- "span",
1553
- {
1554
- style: { paddingBottom: "0.1em" },
1555
- className: "rac-loading-dots",
1556
- children: [
1557
- /* @__PURE__ */ p.jsx("i", {}),
1558
- /* @__PURE__ */ p.jsx("i", {}),
1559
- /* @__PURE__ */ p.jsx("i", {})
1560
- ]
1561
- }
1562
- ),
1563
- je && !w.disabled && /* @__PURE__ */ p.jsxs("div", { className: `rac-checkbox${A ? "" : "-default"}`, children: [
1564
- Ve(_, {
1565
- style: { position: A ? "" : "relative" },
1566
- className: `
1567
- rac-checkmark
1568
- ${Ce?.some((Le) => Le.id === w.id) ? "--checked" : ""}`
1569
- }),
1570
- Ve(A, { className: "rac-check-box" })
1571
- ] })
1572
- ]
1573
- },
1574
- w.id
1575
- );
1576
- return ee.forEach((w, $e) => {
1577
- const Le = w.groupHeader, nt = !!w.group;
1578
- if ((Le || !nt && ie !== null) && (be(ie), Le || (ie = null)), Le) {
1579
- ie = w.name;
1580
- const wt = Oe.has(w.name), Et = ye[w.name] > 0;
1581
- H.push(
1582
- /* @__PURE__ */ p.jsxs(
1583
- "div",
1584
- {
1585
- className: [
1586
- "rac-group-header",
1587
- w.disabled && "rac-disabled-group",
1588
- w.className
1589
- ].filter(Boolean).join(" "),
1590
- onClick: (vt) => O(w, vt),
1591
- style: w.style,
1592
- id: w.id,
1593
- children: [
1594
- /* @__PURE__ */ p.jsx("span", { className: "rac-group-title-text", children: w.name }),
1595
- /* @__PURE__ */ p.jsx(
1596
- He,
1597
- {
1598
- visibility: Et && !w.disabled,
1599
- style: { display: "grid" },
1600
- duration: x,
1601
- children: Ve(S, { className: `rac-group-arrow ${wt ? "--open" : ""}` })
1602
- }
1603
- )
1604
- ]
1605
- },
1606
- w.id
1607
- )
1608
- );
1609
- } else nt ? K.push(Te(w, $e)) : H.push(Te(w, $e));
1610
- }), be(ie), H;
1611
- }, [ee, O, ne, d, ge, t, F, Ae, me, Oe, S]);
1612
- return /* @__PURE__ */ p.jsx(
1613
- Lt,
1614
- {
1615
- setDeleting: m,
1616
- deleting: o,
1617
- selectedText: Z,
1618
- selectRef: de,
1619
- selectId: ne,
1620
- selectedIDs: Ce,
1621
- setSelectedIds: Ze,
1622
- multiple: je,
1623
- removeOption: xe,
1624
- optionsClassName: U,
1625
- renderIcon: Ve,
1626
- normalizedOptions: ee,
1627
- renderOptions: Me,
1628
- selected: d,
1629
- title: Fe,
1630
- visibility: Y,
1631
- active: ke,
1632
- hasOptions: z,
1633
- hasActualValue: Pe,
1634
- highlightedIndex: ge,
1635
- animationFinished: h,
1636
- disabled: Ee,
1637
- loading: Ne,
1638
- error: te,
1639
- setVisibility: fe,
1640
- setHighlightedIndex: me,
1641
- setAnimationFinished: v,
1642
- handleBlur: ce,
1643
- handleFocus: Ie,
1644
- toggleVisibility: we,
1645
- handleKeyDown: Se,
1646
- handleListScroll: B,
1647
- selectOption: O,
1648
- clear: se,
1649
- registerOption: g,
1650
- unregisterOption: N,
1651
- children: r,
1652
- placeholder: _e,
1653
- className: E,
1654
- style: s,
1655
- duration: x,
1656
- easing: y,
1657
- offset: f,
1658
- animateOpacity: j,
1659
- unmount: e,
1660
- OpenIcon: S,
1661
- ClearIcon: u,
1662
- DelIcon: $,
1663
- hasMore: T,
1664
- loadButton: P,
1665
- deleteInline: ue,
1666
- showDelete: M
1667
- }
1668
- );
1669
- }), bt = gt(null);
1670
- function Jt({ children: e, name: r, label: n, value: l, id: a, disabled: x, emptyGroupText: y = "Empty group", className: f = "", style: j = {} }) {
1671
- const s = Qe(rt), E = ve(() => {
1672
- const u = r ?? n ?? a ?? l;
1673
- return u != null && u !== "" ? String(u) : y;
1674
- }, [r, n, l, a, y]), S = ve(() => `group-marker-${et(E)}`, [E]);
1675
- return pe(() => {
1676
- if (!s) return;
1677
- const u = {
1678
- disabled: !!x,
1679
- isGroupMarker: !0,
1680
- group: E,
1681
- id: S,
1682
- className: f,
1683
- style: j
1684
- };
1685
- return s.registerOption(u), () => s.unregisterOption(S);
1686
- }, [s.registerOption, s.unregisterOption, S, E]), /* @__PURE__ */ p.jsx(bt.Provider, { value: E, children: e });
1027
+ renderOption: void 0,
1028
+ valueAsOption: !1,
1029
+ icons: { arrow: he.ArrowUp, clear: he.XMark, remove: he.XMark, check: he.Checkmark, checkbox: void 0 },
1030
+ deleteInline: !1,
1031
+ deleteAlways: !1,
1032
+ className: "",
1033
+ optionsClassName: "",
1034
+ style: {},
1035
+ container: void 0,
1036
+ duration: 300,
1037
+ easing: "ease",
1038
+ offset: 1,
1039
+ animateOpacity: !0,
1040
+ keepMounted: !1
1041
+ }, st = {
1042
+ visibility: "open",
1043
+ setVisibility: "onOpenChange",
1044
+ ownBehavior: "open without onOpenChange",
1045
+ onOpen: "onOpenChange",
1046
+ onClose: "onOpenChange",
1047
+ unmount: "keepMounted (inverted)",
1048
+ showDelete: "deleteAlways",
1049
+ OpenIcon: "icons.arrow",
1050
+ ClearIcon: "icons.clear",
1051
+ DelIcon: "icons.remove",
1052
+ Checkmark: "icons.check",
1053
+ Checkbox: "icons.checkbox",
1054
+ emptyText: "texts.empty",
1055
+ disabledText: "texts.disabled",
1056
+ loadingText: "texts.loading",
1057
+ errorText: "texts.error",
1058
+ clearText: "texts.clear",
1059
+ removeText: "texts.remove",
1060
+ loadButtonText: "texts.loadMore",
1061
+ loadMoreText: "texts.loadingMore",
1062
+ emptyOption: "texts.emptyOption",
1063
+ invalidOption: "texts.invalidOption",
1064
+ disabledOption: "texts.disabledOption"
1065
+ }, Te = (e, t) => {
1066
+ const n = { ...e };
1067
+ for (const r in t) t[r] !== void 0 && (n[r] = t[r]);
1068
+ return n;
1069
+ };
1070
+ function Vn(e) {
1071
+ for (const h in e) h in st && le(`renamed ${h}`, `The \`${h}\` prop was removed. Use \`${st[h]}\`.`);
1072
+ e.value !== void 0 && !e.onChange && le("read-only value", "`value` is set without `onChange`, so the Select is read-only. Pass `onChange`, or `defaultValue` instead of `value`.");
1073
+ const t = Te(Ce, e);
1074
+ t.texts = Te(Ce.texts, e.texts), t.icons = Te(Ce.icons, e.icons);
1075
+ const n = t.texts.emptyGroup, r = Ne(_(() => me(t.children, n), [t.children, n])), { selectId: s, selectRef: c, highlightStore: i, positionStore: a, state: o, actions: p } = kn(t, r), l = {}, g = {};
1076
+ for (const h in t) Nn.has(h) || ((An.test(h) ? g : l)[h] = t[h]);
1077
+ const y = It({ ...l, attrs: g, selectId: s, selectRef: c, highlightStore: i, positionStore: a });
1078
+ return /* @__PURE__ */ O(Y.Provider, { value: y, children: /* @__PURE__ */ O(ce.Provider, { value: p, children: /* @__PURE__ */ q(de.Provider, { value: o, children: [
1079
+ /* @__PURE__ */ O(fn, {}),
1080
+ /* @__PURE__ */ O(On, {})
1081
+ ] }) }) });
1687
1082
  }
1688
- const tt = (e) => e ? typeof e == "string" || typeof e == "number" ? String(e) : Array.isArray(e) ? e.map(tt).join(" ").replace(/\s+/g, " ").trim() : ft.isValidElement(e) ? tt(e.props.children) : "" : "";
1689
- function Ut({ name: e, label: r, id: n, value: l, className: a, style: x, children: y, disabled: f, group: j }) {
1690
- const s = Qe(rt), E = Qe(bt), S = s?.registerOption, u = s?.unregisterOption, $ = yt(), _ = ve(() => n ? String(n) : $.replace(/:/g, ""), [n, $]);
1691
- return pe(() => {
1692
- if (!S) return;
1693
- const A = tt(y), T = y != null;
1694
- let C = "";
1695
- return r != null && r !== "" ? C = String(r) : e != null && e !== "" ? C = String(e) : A ? C = A : n != null && n !== "" && (C = String(n)), S({
1696
- id: _,
1697
- value: l !== void 0 ? l : A,
1698
- label: C,
1699
- jsx: y,
1700
- hasJsx: T,
1701
- className: a,
1702
- style: x,
1703
- disabled: !!f,
1704
- group: j || E || null
1705
- }), () => u(_);
1706
- }, [_, e, r, l, y, a, x, f, j, E, S, u]), null;
1083
+ function $n() {
1084
+ return le("option outside", "<Option/> was rendered outside <Select>, or inside a component that <Select> cannot read. Use it as a direct child, or wrap the component with defineOption()."), null;
1085
+ }
1086
+ $n.racKind = "option";
1087
+ function Ln() {
1088
+ return null;
1707
1089
  }
1090
+ Ln.racKind = "group";
1708
1091
  export {
1709
- Jt as OptGroup,
1710
- Ut as Option,
1711
- zt as Select
1092
+ Ln as OptGroup,
1093
+ $n as Option,
1094
+ Vn as Select,
1095
+ Rn as defineOption
1712
1096
  };