wimui 0.69.1 → 0.70.0

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.
@@ -4,227 +4,244 @@ import { composeEventHandlers as t } from "../../_internal/composeEventHandlers.
4
4
  import { Transition as n } from "../../layout/Transition/Transition.js";
5
5
  import r from "../../../icon/chevron-right.js";
6
6
  import { Icon as i } from "../../media/Icon/Icon.js";
7
- import { useInlineFloating as a } from "../../_internal/useInlineFloating.js";
8
- import { BaseListItem as ee } from "../../_internal/BaseListItem/BaseListItem.js";
9
- import { InputBase as o } from "../InputBase/InputBase.js";
10
- import s from "./cascader.module.js";
11
- import { FieldTemplate as c } from "../FieldTemplate/FieldTemplate.js";
12
- import l, { useEffect as u, useId as te, useRef as d, useState as f } from "react";
13
- import p from "classnames";
14
- import { jsx as m, jsxs as h } from "react/jsx-runtime";
7
+ import { getRovingIndex as a, isRovingKey as o } from "../../_internal/rovingIndex.js";
8
+ import { useInlineFloating as s } from "../../_internal/useInlineFloating.js";
9
+ import { BaseListItem as c } from "../../_internal/BaseListItem/BaseListItem.js";
10
+ import { InputBase as l } from "../InputBase/InputBase.js";
11
+ import u from "./cascader.module.js";
12
+ import { FieldTemplate as ee } from "../FieldTemplate/FieldTemplate.js";
13
+ import { findTypeaheadIndex as te, isTypeaheadKey as ne, useTypeahead as re } from "../../_internal/typeahead.js";
14
+ import ie, { useEffect as d, useId as ae, useRef as f, useState as p } from "react";
15
+ import m from "classnames";
16
+ import { jsx as h, jsxs as g } from "react/jsx-runtime";
15
17
  //#region src/components/form/Cascader/Cascader.tsx
16
- function g(e) {
18
+ function _(e) {
17
19
  return typeof e == "string" ? e : typeof e == "number" ? String(e) : "";
18
20
  }
19
- var _ = ({ options: _ = [], value: v, onChange: y, placeholder: b, label: x, error: S, required: C, layout: ne, className: re, disabled: w = !1, defaultValue: ie, id: ae, expandTrigger: oe = "click", separator: T = " / ", allowClear: se = !1, "aria-label": E, "aria-labelledby": ce, "aria-describedby": le, width: ue, fullWidth: de = !1, ...D }) => {
20
- let fe = te(), O = ae || `wim-cascader-${fe}`, k = x ? `${O}-label` : void 0, A = S ? `${O}-error` : void 0, j = k ?? ce, pe = `${O}-trigger`, M = `${O}-popup`, [N, P] = f(!1), [me, F] = f(ie || []), [I, L] = f([]), [R, z] = f(-1), [B, V] = f([]), [he, H] = f(!1), U = d(null), W = d(null), G = v !== void 0, K = G ? v : me;
21
- u(() => {
21
+ var v = ({ options: v = [], value: y, onChange: b, placeholder: x, label: S, error: C, required: w, layout: oe, className: se, disabled: T = !1, defaultValue: ce, id: le, expandTrigger: ue = "click", separator: E = " / ", allowClear: de = !1, "aria-label": D, "aria-labelledby": fe, "aria-describedby": pe, width: me, fullWidth: he = !1, ...O }) => {
22
+ let ge = ae(), k = le || `wim-cascader-${ge}`, A = S ? `${k}-label` : void 0, j = C ? `${k}-error` : void 0, M = A ?? fe, _e = `${k}-trigger`, N = `${k}-popup`, [P, F] = p(!1), [ve, I] = p(ce || []), [L, R] = p([]), [z, B] = p(-1), [V, H] = p([]), [ye, U] = p(!1), W = f(null), G = f(null), K = y !== void 0, q = K ? y : ve;
23
+ d(() => {
22
24
  let e = (e) => {
23
- U.current && !U.current.contains(e.target) && P(!1);
25
+ W.current && !W.current.contains(e.target) && F(!1);
24
26
  };
25
27
  return document.addEventListener("mousedown", e), () => document.removeEventListener("mousedown", e);
26
- }, []), u(() => {
27
- if (N && R >= 0) {
28
- let e = B[R], t = `${O}-menu-${R}-option-${e}`, n = U.current?.querySelector(`#${t}`);
28
+ }, []), d(() => {
29
+ if (P && z >= 0) {
30
+ let e = V[z], t = `${k}-menu-${z}-option-${e}`, n = W.current?.querySelector(`#${t}`);
29
31
  n && n.scrollIntoView({
30
32
  block: "nearest",
31
33
  behavior: "smooth"
32
34
  });
33
35
  }
34
36
  }, [
35
- R,
36
- B,
37
- N,
38
- O
37
+ z,
38
+ V,
39
+ P,
40
+ k
39
41
  ]);
40
- let q = () => {
41
- if (!w) {
42
- let e = !N;
43
- P(e), e ? (L(K || []), z(0), V([0])) : z(-1);
42
+ let J = () => {
43
+ if (!T) {
44
+ let e = !P;
45
+ F(e), e ? (R(q || []), B(0), H([a({
46
+ key: "Home",
47
+ current: -1,
48
+ count: v.length,
49
+ isDisabled: (e) => !!v[e]?.disabled
50
+ }) ?? 0])) : B(-1);
44
51
  }
45
- }, ge = () => {
46
- if (!K || K.length === 0) return null;
47
- let e = [], t = _;
48
- for (let n of K) {
52
+ }, be = () => {
53
+ if (!q || q.length === 0) return null;
54
+ let e = [], t = v;
55
+ for (let n of q) {
49
56
  let r = t.find((e) => e.value === n);
50
57
  if (r) e.push(r.label), t = r.children || [];
51
58
  else break;
52
59
  }
53
- return e.length === 0 ? null : e.map((t, n) => /* @__PURE__ */ h(l.Fragment, { children: [t, n < e.length - 1 && /* @__PURE__ */ m("span", { children: T })] }, n));
54
- }, J = (e, t) => {
60
+ return e.length === 0 ? null : e.map((t, n) => /* @__PURE__ */ g(ie.Fragment, { children: [t, n < e.length - 1 && /* @__PURE__ */ h("span", { children: E })] }, n));
61
+ }, Y = (e, t) => {
55
62
  if (e.disabled) return;
56
- let n = [...I.slice(0, t), e.value];
57
- if (L(n), !e.children || e.children.length === 0) {
58
- if (G || F(n), y) {
59
- let e = [], t = _;
63
+ let n = [...L.slice(0, t), e.value];
64
+ if (R(n), !e.children || e.children.length === 0) {
65
+ if (K || I(n), b) {
66
+ let e = [], t = v;
60
67
  for (let r of n) {
61
68
  let n = t.find((e) => e.value === r);
62
69
  n && (e.push(n), t = n.children || []);
63
70
  }
64
- y(n, e);
71
+ b(n, e);
65
72
  }
66
- P(!1), W.current?.focus();
73
+ F(!1), G.current?.focus();
67
74
  }
68
- }, _e = (e) => {
69
- e?.stopPropagation(), !w && (G || F([]), y && y([], []));
70
- }, Y = (e, t) => {
71
- oe === "hover" && !e.disabled && L([...I.slice(0, t), e.value]);
72
- }, ve = (e) => {
73
- if (H(!0), w) return;
74
- if (!N) {
75
- (e.key === "Enter" || e.key === " " || e.key === "ArrowDown" || e.key === "ArrowDown" && e.altKey) && (e.preventDefault(), q());
75
+ }, xe = (e) => {
76
+ e?.stopPropagation(), !T && (K || I([]), b && b([], []));
77
+ }, Se = (e, t) => {
78
+ ue === "hover" && !e.disabled && R([...L.slice(0, t), e.value]);
79
+ }, X = re(), Ce = (e) => {
80
+ if (U(!0), T) return;
81
+ if (!P) {
82
+ (e.key === "Enter" || e.key === " " || e.key === "ArrowDown" || e.key === "ArrowDown" && e.altKey) && (e.preventDefault(), J());
76
83
  return;
77
84
  }
78
- let t = [_], n = _;
79
- for (let e = 0; e < I.length; e++) {
80
- let r = I[e], i = n.find((e) => e.value === r);
85
+ let t = [v], n = v;
86
+ for (let e = 0; e < L.length; e++) {
87
+ let r = L[e], i = n.find((e) => e.value === r);
81
88
  if (i && i.children && i.children.length > 0) t.push(i.children), n = i.children;
82
89
  else break;
83
90
  }
84
- let r = t[R] || [], i = B[R] || 0;
85
- switch (e.key) {
86
- case "ArrowDown":
87
- e.preventDefault(), V((e) => {
88
- let t = [...e];
89
- return t[R] = Math.min(i + 1, r.length - 1), t;
90
- });
91
- break;
92
- case "ArrowUp":
93
- e.preventDefault(), V((e) => {
94
- let t = [...e];
95
- return t[R] = Math.max(i - 1, 0), t;
96
- });
97
- break;
91
+ let r = t[z] || [], i = V[z] || 0, s = (e) => (t) => !!e[t]?.disabled, c = (e) => H((t) => {
92
+ let n = [...t];
93
+ return n[z] = e, n;
94
+ });
95
+ if (ne(e, X.typing())) {
96
+ e.preventDefault();
97
+ let t = te({
98
+ query: X.push(e.key),
99
+ current: i,
100
+ count: r.length,
101
+ getText: (e) => {
102
+ let t = r[e]?.label;
103
+ return typeof t == "string" ? t : String(r[e]?.value ?? "");
104
+ },
105
+ isDisabled: s(r)
106
+ });
107
+ t >= 0 && c(t);
108
+ } else if (o(e.key, "vertical")) {
109
+ e.preventDefault();
110
+ let t = a({
111
+ key: e.key,
112
+ current: i,
113
+ count: r.length,
114
+ orientation: "vertical",
115
+ isDisabled: s(r)
116
+ });
117
+ t !== null && c(t);
118
+ } else switch (e.key) {
98
119
  case "ArrowRight": {
99
120
  e.preventDefault();
100
121
  let t = r[i];
101
- t && t.children && t.children.length > 0 && (L([...I.slice(0, R), t.value]), z(R + 1), V((e) => [...e.slice(0, R + 1), 0]));
122
+ if (t && !t.disabled && t.children && t.children.length > 0) {
123
+ let e = t.children, n = a({
124
+ key: "Home",
125
+ current: -1,
126
+ count: e.length,
127
+ isDisabled: s(e)
128
+ }) ?? 0;
129
+ R([...L.slice(0, z), t.value]), B(z + 1), H((e) => [...e.slice(0, z + 1), n]);
130
+ }
102
131
  break;
103
132
  }
104
133
  case "ArrowLeft":
105
- e.preventDefault(), R > 0 && (z(R - 1), V((e) => e.slice(0, R)));
134
+ e.preventDefault(), z > 0 && (B(z - 1), H((e) => e.slice(0, z)));
106
135
  break;
107
136
  case "Enter":
108
137
  case " ": {
109
138
  e.preventDefault();
110
139
  let t = r[i];
111
- t && J(t, R);
140
+ t && !t.disabled && Y(t, z);
112
141
  break;
113
142
  }
114
143
  case "Escape":
115
- e.preventDefault(), P(!1), z(-1), W.current?.focus();
116
- break;
117
- case "Home":
118
- e.preventDefault(), V((e) => {
119
- let t = [...e];
120
- return t[R] = 0, t;
121
- });
122
- break;
123
- case "End":
124
- e.preventDefault(), V((e) => {
125
- let t = [...e];
126
- return t[R] = r.length - 1, t;
127
- });
144
+ e.preventDefault(), F(!1), B(-1), G.current?.focus();
128
145
  break;
129
- case "Tab": N && (P(!1), z(-1));
146
+ case "Tab": P && (F(!1), B(-1));
130
147
  }
131
- }, X = [_], Z = _;
132
- for (let e = 0; e < I.length; e++) {
133
- let t = I[e], n = Z.find((e) => e.value === t);
134
- if (n && n.children && n.children.length > 0) X.push(n.children), Z = n.children;
148
+ }, Z = [v], we = v;
149
+ for (let e = 0; e < L.length; e++) {
150
+ let t = L[e], n = we.find((e) => e.value === t);
151
+ if (n && n.children && n.children.length > 0) Z.push(n.children), we = n.children;
135
152
  else break;
136
153
  }
137
- let Q = ge(), $ = () => {
138
- if (!K || K.length === 0) return "";
139
- let e = [], t = _;
140
- for (let n of K) {
154
+ let Q = be(), $ = () => {
155
+ if (!q || q.length === 0) return "";
156
+ let e = [], t = v;
157
+ for (let n of q) {
141
158
  let r = t.find((e) => e.value === n);
142
- if (r) e.push(g(r.label)), t = r.children || [];
159
+ if (r) e.push(_(r.label)), t = r.children || [];
143
160
  else break;
144
161
  }
145
- return e.join(T);
146
- }, { setReference: ye, setFloating: be, floatingProps: xe } = a({ open: N && !w }), Se = e(U, ye);
147
- return /* @__PURE__ */ m(c, {
148
- label: x,
149
- error: S,
150
- required: C,
151
- layout: ne,
152
- labelId: k,
153
- errorId: A,
154
- className: p("wim-cascader", re),
155
- children: /* @__PURE__ */ h("div", {
156
- className: s.root,
157
- ref: Se,
158
- "data-keyboard-nav": he,
159
- ...D,
160
- onMouseMove: t(D.onMouseMove, () => H(!1)),
161
- children: [/* @__PURE__ */ m(o, {
162
- disabled: w,
163
- allowClear: se,
162
+ return e.join(E);
163
+ }, { setReference: Te, setFloating: Ee, floatingProps: De } = s({ open: P && !T }), Oe = e(W, Te);
164
+ return /* @__PURE__ */ h(ee, {
165
+ label: S,
166
+ error: C,
167
+ required: w,
168
+ layout: oe,
169
+ labelId: A,
170
+ errorId: j,
171
+ className: m("wim-cascader", se),
172
+ children: /* @__PURE__ */ g("div", {
173
+ className: u.root,
174
+ ref: Oe,
175
+ "data-keyboard-nav": ye,
176
+ ...O,
177
+ onMouseMove: t(O.onMouseMove, () => U(!1)),
178
+ children: [/* @__PURE__ */ h(l, {
179
+ disabled: T,
180
+ allowClear: de,
164
181
  hasValue: !!Q,
165
- onClear: _e,
166
- intent: S ? "danger" : "default",
167
- width: ue,
168
- fullWidth: de,
182
+ onClear: xe,
183
+ intent: C ? "danger" : "default",
184
+ width: me,
185
+ fullWidth: he,
169
186
  rightIcons: [{
170
187
  name: "ChevronDownIcon",
171
- rotated: N
188
+ rotated: P
172
189
  }],
173
- className: p(N && s.open),
174
- children: /* @__PURE__ */ m("div", {
175
- id: pe,
176
- ref: W,
177
- className: p(s.trigger, w && s.disabled),
178
- onClick: q,
179
- onKeyDown: ve,
180
- tabIndex: w ? -1 : 0,
190
+ className: m(P && u.open),
191
+ children: /* @__PURE__ */ h("div", {
192
+ id: _e,
193
+ ref: G,
194
+ className: m(u.trigger, T && u.disabled),
195
+ onClick: J,
196
+ onKeyDown: Ce,
197
+ tabIndex: T ? -1 : 0,
181
198
  role: "combobox",
182
- "aria-expanded": N,
183
- "aria-controls": N ? M : void 0,
199
+ "aria-expanded": P,
200
+ "aria-controls": P ? N : void 0,
184
201
  "aria-haspopup": "listbox",
185
- "aria-disabled": w,
186
- "aria-labelledby": j,
187
- "aria-label": j ? void 0 : E || $() || g(b),
188
- "aria-describedby": [le, A].filter(Boolean).join(" ") || void 0,
189
- "aria-required": C,
190
- "aria-invalid": !!S,
191
- "aria-activedescendant": N && R >= 0 ? `${O}-menu-${R}-option-${B[R]}` : void 0,
192
- children: /* @__PURE__ */ m("div", {
193
- className: p(s.value, !Q && s.placeholder),
194
- children: Q || b
202
+ "aria-disabled": T,
203
+ "aria-labelledby": M,
204
+ "aria-label": M ? void 0 : D || $() || _(x),
205
+ "aria-describedby": [pe, j].filter(Boolean).join(" ") || void 0,
206
+ "aria-required": w,
207
+ "aria-invalid": !!C,
208
+ "aria-activedescendant": P && z >= 0 ? `${k}-menu-${z}-option-${V[z]}` : void 0,
209
+ children: /* @__PURE__ */ h("div", {
210
+ className: m(u.value, !Q && u.placeholder),
211
+ children: Q || x
195
212
  })
196
213
  })
197
- }), /* @__PURE__ */ m(n, {
198
- show: N && !w,
214
+ }), /* @__PURE__ */ h(n, {
215
+ show: P && !T,
199
216
  preset: "fade",
200
- id: M,
201
- className: s.dropdown,
202
- ref: be,
203
- ...xe,
204
- children: X.map((e, t) => /* @__PURE__ */ m("div", {
205
- className: s.menu,
217
+ id: N,
218
+ className: u.dropdown,
219
+ ref: Ee,
220
+ ...De,
221
+ children: Z.map((e, t) => /* @__PURE__ */ h("div", {
222
+ className: u.menu,
206
223
  role: "listbox",
207
- "aria-labelledby": j,
208
- "aria-label": j ? void 0 : E || $() || g(b),
224
+ "aria-labelledby": M,
225
+ "aria-label": M ? void 0 : D || $() || _(x),
209
226
  children: e.map((e, n) => {
210
- let a = I[t] === e.value, o = R === t && B[t] === n, c = K[t] === e.value, l = e.children && e.children.length > 0;
211
- return /* @__PURE__ */ m(ee, {
212
- className: p(s.menuItem, c && s.selected),
227
+ let a = L[t] === e.value, o = z === t && V[t] === n, s = q[t] === e.value, l = e.children && e.children.length > 0;
228
+ return /* @__PURE__ */ h(c, {
229
+ className: m(u.menuItem, s && u.selected),
213
230
  active: o || a,
214
231
  disabled: e.disabled,
215
232
  onClick: (n) => {
216
- n.stopPropagation(), J(e, t);
233
+ n.stopPropagation(), Y(e, t);
217
234
  },
218
235
  onMouseEnter: () => {
219
- Y(e, t), z(t), V((e) => [...e.slice(0, t), n]);
236
+ Se(e, t), B(t), H((e) => [...e.slice(0, t), n]);
220
237
  },
221
- rightSection: l ? /* @__PURE__ */ m(i, {
238
+ rightSection: l ? /* @__PURE__ */ h(i, {
222
239
  component: r,
223
240
  size: "sm"
224
241
  }) : void 0,
225
242
  role: "option",
226
- id: `${O}-menu-${t}-option-${n}`,
227
- "aria-selected": c,
243
+ id: `${k}-menu-${t}-option-${n}`,
244
+ "aria-selected": s,
228
245
  tabIndex: -1,
229
246
  children: e.label
230
247
  }, e.value);
@@ -234,6 +251,6 @@ var _ = ({ options: _ = [], value: v, onChange: y, placeholder: b, label: x, err
234
251
  })
235
252
  });
236
253
  };
237
- _.displayName = "Cascader";
254
+ v.displayName = "Cascader";
238
255
  //#endregion
239
- export { _ as Cascader };
256
+ export { v as Cascader };
@@ -1,2 +1,2 @@
1
1
  "use client";
2
- const e=require("../../../_virtual/_rolldown/runtime.cjs"),t=require("../../../hooks/useMergedRef.cjs"),n=require("../../../icon/check.cjs"),r=require("../../media/Icon/Icon.cjs"),i=require("../../_internal/useInlineFloating.cjs"),a=require("../../_internal/BaseListItem/BaseListItem.cjs"),o=require("../InputBase/InputBase.cjs"),s=require("../FieldTemplate/FieldTemplate.cjs"),c=require("../../data-display/Chip/Chip.cjs"),l=require("./multiselect.module.cjs");let u=require("react");u=e.__toESM(u,1);let d=require("classnames");d=e.__toESM(d,1);let f=require("react/jsx-runtime");var p=({options:e=[],value:p,onChange:m,placeholder:h,label:g,error:_,required:v,layout:y,className:b,disabled:x=!1,defaultValue:S=[],allowClear:C=!1,id:ee,width:w,fullWidth:T=!1,...E})=>{let[D,O]=(0,u.useState)(!1),[k,A]=(0,u.useState)(S),[j,M]=(0,u.useState)(-1),[N,P]=(0,u.useState)(!1),F=(0,u.useRef)(null),I=(0,u.useRef)(null),L=(0,u.useRef)(null),R=(0,u.useId)(),z=ee||`wim-multiselect-${R}`,B=`${z}-list`,V=g?`${z}-label`:void 0,H=_?`${z}-error`:void 0,U=`${z}-trigger`,W=p!==void 0,G=W?p:k;(0,u.useEffect)(()=>{let e=e=>{F.current&&!F.current.contains(e.target)&&O(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[]);let K=e=>{if(x||e&&e.target.closest(`[data-chip-delete]`))return;let t=!D;O(t),M(t?0:-1)},q=e=>{if(x)return;let t;t=G?.includes(e)?G.filter(t=>t!==e):[...G||[],e],W||A(t),m&&m(t)},J=(e,t)=>{if(e.stopPropagation(),x)return;let n=(G||[]).filter(e=>e!==t);W||A(n),m&&m(n)},Y=e=>{e?.stopPropagation(),!x&&(W||A([]),m&&m([]))},X=e.filter(e=>G?.includes(e.value)),Z=t=>{if(P(!0),!x)switch(t.key){case`ArrowDown`:t.preventDefault(),D?M(t=>t<e.length-1?t+1:0):(O(!0),M(0));break;case`ArrowUp`:t.preventDefault(),D&&M(t=>t>0?t-1:e.length-1);break;case`Enter`:case` `:t.preventDefault(),D?j>=0&&q(e[j].value):(O(!0),M(0));break;case`Escape`:D&&(t.preventDefault(),O(!1),M(-1),L.current?.focus());break;case`Home`:D&&(t.preventDefault(),M(0));break;case`End`:D&&(t.preventDefault(),M(e.length-1));break;case`Tab`:D&&(O(!1),M(-1))}};(0,u.useEffect)(()=>{D&&j>=0&&I.current&&I.current.children[j]?.scrollIntoView({block:`nearest`})},[j,D]);let{"aria-label":Q,"aria-labelledby":$,"aria-describedby":te,...ne}=E,{setReference:re,setFloating:ie,floatingProps:ae}=i.useInlineFloating({open:D&&!x}),oe=t.useMergedRef(F,re),se=t.useMergedRef(I,ie);return(0,f.jsx)(s.FieldTemplate,{label:g,error:_,required:v,layout:y,labelId:V,htmlFor:U,errorId:H,className:b,children:(0,f.jsxs)(`div`,{className:(0,d.default)(`wim-multi-select`,l.default.root,T&&l.default.fullWidth),ref:oe,onMouseMove:()=>P(!1),"data-keyboard-nav":N,...ne,children:[(0,f.jsx)(o.InputBase,{disabled:x,allowClear:C,hasValue:G&&G.length>0,onClear:Y,intent:_?`danger`:`default`,width:w,fullWidth:T,rightIcons:[{name:`ChevronDownIcon`,rotated:D}],className:(0,d.default)(D&&l.default.open),children:(0,f.jsx)(`div`,{id:U,"data-testid":`multiselect-trigger`,className:(0,d.default)(l.default.trigger,x&&l.default.disabled),onClick:K,tabIndex:x?-1:0,role:`combobox`,"aria-expanded":D,"aria-haspopup":`listbox`,"aria-controls":D?B:void 0,"aria-disabled":x,"aria-labelledby":V||$,"aria-describedby":H||te,"aria-required":v,"aria-invalid":!!_,"aria-label":g?void 0:Q||h,onKeyDown:Z,ref:L,"aria-activedescendant":D&&j>=0?`${z}-option-${j}`:void 0,children:(0,f.jsx)(`div`,{className:(0,d.default)(l.default.value,X.length===0&&l.default.placeholder),children:X.length>0?X.map(e=>(0,f.jsx)(c.Chip,{"data-testid":`multiselect-chip`,size:`sm`,intent:`neutral`,variant:`solid`,disabled:x,onDelete:x?void 0:t=>J(t,e.value),children:e.label},e.value)):h})})}),D&&!x&&(0,f.jsx)(`ul`,{id:B,ref:se,className:l.default.list,...ae,role:`listbox`,"aria-multiselectable":`true`,"aria-labelledby":V||$||void 0,children:e.map((e,t)=>{let i=G?.includes(e.value),o=t===j;return(0,f.jsx)(a.BaseListItem,{asChild:!0,id:`${z}-option-${t}`,className:(0,d.default)(l.default.option,i&&l.default.selected),active:o,disabled:e.disabled,onClick:()=>!e.disabled&&q(e.value),onMouseEnter:()=>M(t),rightSection:i?(0,f.jsx)(r.Icon,{component:n.default,size:`sm`}):void 0,role:`option`,"aria-selected":i,tabIndex:-1,children:(0,f.jsx)(`li`,{children:e.label})},e.value)})})]})})};p.displayName=`MultiSelect`,exports.MultiSelect=p;
2
+ const e=require("../../../_virtual/_rolldown/runtime.cjs"),t=require("../../../hooks/useMergedRef.cjs"),n=require("../../../icon/check.cjs"),r=require("../../media/Icon/Icon.cjs"),i=require("../../_internal/rovingIndex.cjs"),a=require("../../_internal/useInlineFloating.cjs"),ee=require("../../_internal/BaseListItem/BaseListItem.cjs"),o=require("../InputBase/InputBase.cjs"),s=require("../FieldTemplate/FieldTemplate.cjs"),c=require("../../_internal/typeahead.cjs"),l=require("../../data-display/Chip/Chip.cjs"),u=require("./multiselect.module.cjs");let d=require("react");d=e.__toESM(d,1);let f=require("classnames");f=e.__toESM(f,1);let p=require("react/jsx-runtime");var m=({options:e=[],value:m,onChange:h,placeholder:g,label:_,error:v,required:y,layout:b,className:x,disabled:S=!1,defaultValue:te=[],allowClear:ne=!1,id:re,width:C,fullWidth:w=!1,...T})=>{let[E,D]=(0,d.useState)(!1),[O,k]=(0,d.useState)(te),[A,j]=(0,d.useState)(-1),[ie,M]=(0,d.useState)(!1),N=(0,d.useRef)(null),P=(0,d.useRef)(null),F=(0,d.useRef)(null),I=(0,d.useId)(),L=re||`wim-multiselect-${I}`,R=`${L}-list`,z=_?`${L}-label`:void 0,B=v?`${L}-error`:void 0,V=`${L}-trigger`,H=m!==void 0,U=H?m:O;(0,d.useEffect)(()=>{let e=e=>{N.current&&!N.current.contains(e.target)&&D(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[]);let W=e=>{if(S||e&&e.target.closest(`[data-chip-delete]`))return;let t=!E;D(t),j(t?X():-1)},G=e=>{if(S)return;let t;t=U?.includes(e)?U.filter(t=>t!==e):[...U||[],e],H||k(t),h&&h(t)},K=(e,t)=>{if(e.stopPropagation(),S)return;let n=(U||[]).filter(e=>e!==t);H||k(n),h&&h(n)},q=e=>{e?.stopPropagation(),!S&&(H||k([]),h&&h([]))},J=e.filter(e=>U?.includes(e.value)),Y=t=>!!e[t]?.disabled,X=()=>i.getRovingIndex({key:`Home`,current:-1,count:e.length,isDisabled:Y})??-1,Z=c.useTypeahead(),ae=t=>{if(M(!0),!S){if(c.isTypeaheadKey(t,Z.typing())){t.preventDefault();let n=c.findTypeaheadIndex({query:Z.push(t.key),current:E?A:-1,count:e.length,getText:t=>e[t].label,isDisabled:Y});n>=0&&(D(!0),j(n))}else if(E&&i.isRovingKey(t.key,`vertical`)){t.preventDefault();let n=i.getRovingIndex({key:t.key,current:A,count:e.length,orientation:`vertical`,isDisabled:Y});n!==null&&j(n)}else switch(t.key){case`ArrowDown`:t.preventDefault(),D(!0),j(X());break;case`Enter`:case` `:t.preventDefault(),E?A>=0&&!Y(A)&&G(e[A].value):(D(!0),j(X()));break;case`Escape`:E&&(t.preventDefault(),D(!1),j(-1),F.current?.focus());break;case`Tab`:E&&(D(!1),j(-1))}}};(0,d.useEffect)(()=>{E&&A>=0&&P.current&&P.current.children[A]?.scrollIntoView({block:`nearest`})},[A,E]);let{"aria-label":oe,"aria-labelledby":Q,"aria-describedby":se,...ce}=T,{setReference:le,setFloating:$,floatingProps:ue}=a.useInlineFloating({open:E&&!S}),de=t.useMergedRef(N,le),fe=t.useMergedRef(P,$);return(0,p.jsx)(s.FieldTemplate,{label:_,error:v,required:y,layout:b,labelId:z,htmlFor:V,errorId:B,className:x,children:(0,p.jsxs)(`div`,{className:(0,f.default)(`wim-multi-select`,u.default.root,w&&u.default.fullWidth),ref:de,onMouseMove:()=>M(!1),"data-keyboard-nav":ie,...ce,children:[(0,p.jsx)(o.InputBase,{disabled:S,allowClear:ne,hasValue:U&&U.length>0,onClear:q,intent:v?`danger`:`default`,width:C,fullWidth:w,rightIcons:[{name:`ChevronDownIcon`,rotated:E}],className:(0,f.default)(E&&u.default.open),children:(0,p.jsx)(`div`,{id:V,"data-testid":`multiselect-trigger`,className:(0,f.default)(u.default.trigger,S&&u.default.disabled),onClick:W,tabIndex:S?-1:0,role:`combobox`,"aria-expanded":E,"aria-haspopup":`listbox`,"aria-controls":E?R:void 0,"aria-disabled":S,"aria-labelledby":z||Q,"aria-describedby":B||se,"aria-required":y,"aria-invalid":!!v,"aria-label":_?void 0:oe||g,onKeyDown:ae,ref:F,"aria-activedescendant":E&&A>=0?`${L}-option-${A}`:void 0,children:(0,p.jsx)(`div`,{className:(0,f.default)(u.default.value,J.length===0&&u.default.placeholder),children:J.length>0?J.map(e=>(0,p.jsx)(l.Chip,{"data-testid":`multiselect-chip`,size:`sm`,intent:`neutral`,variant:`solid`,disabled:S,onDelete:S?void 0:t=>K(t,e.value),children:e.label},e.value)):g})})}),E&&!S&&(0,p.jsx)(`ul`,{id:R,ref:fe,className:u.default.list,...ue,role:`listbox`,"aria-multiselectable":`true`,"aria-labelledby":z||Q||void 0,children:e.map((e,t)=>{let i=U?.includes(e.value),a=t===A;return(0,p.jsx)(ee.BaseListItem,{asChild:!0,id:`${L}-option-${t}`,className:(0,f.default)(u.default.option,i&&u.default.selected),active:a,disabled:e.disabled,onClick:()=>!e.disabled&&G(e.value),onMouseEnter:()=>j(t),rightSection:i?(0,p.jsx)(r.Icon,{component:n.default,size:`sm`}):void 0,role:`option`,"aria-selected":i,tabIndex:-1,children:(0,p.jsx)(`li`,{children:e.label})},e.value)})})]})})};m.displayName=`MultiSelect`,exports.MultiSelect=m;