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.
- package/dist/components/_internal/typeahead.cjs +2 -0
- package/dist/components/_internal/typeahead.d.ts +45 -0
- package/dist/components/_internal/typeahead.js +24 -0
- package/dist/components/ai/ModelSelector/ModelSelector.cjs +1 -1
- package/dist/components/ai/ModelSelector/ModelSelector.js +119 -119
- package/dist/components/form/Cascader/Cascader.cjs +1 -1
- package/dist/components/form/Cascader/Cascader.js +168 -151
- package/dist/components/form/MultiSelect/MultiSelect.cjs +1 -1
- package/dist/components/form/MultiSelect/MultiSelect.js +131 -111
- package/dist/components/form/Select/useSelect.cjs +1 -1
- package/dist/components/form/Select/useSelect.js +83 -75
- package/dist/components/form/Transfer/Transfer.cjs +1 -1
- package/dist/components/form/Transfer/Transfer.js +147 -141
- package/dist/components/navigation/Menubar/Menubar.cjs +1 -1
- package/dist/components/navigation/Menubar/Menubar.js +133 -122
- package/dist/components/overlay/Dropdown/Dropdown.cjs +1 -1
- package/dist/components/overlay/Dropdown/Dropdown.js +131 -122
- package/dist/components/overlay/Menu/Menu.cjs +1 -1
- package/dist/components/overlay/Menu/Menu.js +100 -89
- package/dist/llms-full.txt +1 -1
- package/dist/llms.txt +1 -1
- package/dist/wimui.umd.js +5 -5
- package/package.json +2 -2
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
let e=require("react");var t=({query:e,current:t,count:n,getText:r,isDisabled:i=()=>!1})=>{let a=e.toLowerCase();if(a===``||n<=0)return-1;let o=a.length>1&&a.split(``).every(e=>e===a[0]),s=o?a[0]:a,c=o||a.length===1?t+1:Math.max(t,0);for(let e=0;e<n;e++){let t=((c+e)%n+n)%n;if(!i(t)&&r(t).trim().toLowerCase().startsWith(s))return t}return-1},n=(e,t)=>e.key.length===1&&!e.ctrlKey&&!e.metaKey&&!e.altKey&&(e.key!==` `||t),r=500;function i(){let t=(0,e.useRef)(``),n=(0,e.useRef)(void 0);return(0,e.useEffect)(()=>()=>clearTimeout(n.current),[]),{push:(0,e.useCallback)(e=>(clearTimeout(n.current),t.current+=e,n.current=setTimeout(()=>{t.current=``},r),t.current),[]),typing:(0,e.useCallback)(()=>t.current!==``,[])}}exports.findTypeaheadIndex=t,exports.isTypeaheadKey=n,exports.useTypeahead=i;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 文字を打って、先頭が一致する項目へ移る(T370)。WAI-ARIA のパターン集が、リスト(listbox)と
|
|
3
|
+
* メニューで勧めている操作。以前は PhoneInput だけが自前で持っていた。
|
|
4
|
+
*
|
|
5
|
+
* ここでは計算と、打った文字をためる仕組みだけを持つ。どの項目をどう動かすか(フォーカスか、
|
|
6
|
+
* aria-activedescendant か、開いていないときに開くか)は各部品に残す(rovingIndex と同じ分け方)。
|
|
7
|
+
*
|
|
8
|
+
* Composition Contract:
|
|
9
|
+
* - Managed by: 呼び出す部品(キーの処理・preventDefault・動かした先の扱い)
|
|
10
|
+
* - Scroll lock: No
|
|
11
|
+
*/
|
|
12
|
+
export interface TypeaheadOptions {
|
|
13
|
+
/** ためた文字(大文字小文字は区別しない) */
|
|
14
|
+
query: string;
|
|
15
|
+
/** 今の位置。並びの外なら -1 */
|
|
16
|
+
current: number;
|
|
17
|
+
/** 項目の数 */
|
|
18
|
+
count: number;
|
|
19
|
+
/** 項目の文字(照合に使う) */
|
|
20
|
+
getText: (index: number) => string;
|
|
21
|
+
/** 無効の項目には止まらない */
|
|
22
|
+
isDisabled?: (index: number) => boolean;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* 先頭が `query` に一致する項目の位置。無ければ -1。
|
|
26
|
+
*
|
|
27
|
+
* - 打ち始め(1 文字)と、同じ文字の繰り返し("ss")は、今の次から探す ── 同じ文字を続けて打つと、
|
|
28
|
+
* その文字で始まる項目を順に巡る
|
|
29
|
+
* - 続きの文字("sw")は、今の項目から探す ── 今の項目が当たっていれば、そこに留まる
|
|
30
|
+
* - 末尾まで探したら、先頭へ折り返して探す
|
|
31
|
+
*/
|
|
32
|
+
export declare const findTypeaheadIndex: ({ query, current, count, getText, isDisabled, }: TypeaheadOptions) => number;
|
|
33
|
+
/**
|
|
34
|
+
* このキーを先頭一致の文字として扱うか。修飾キーとの組み合わせは扱わない。空白は、もう文字を
|
|
35
|
+
* ためているときだけ文字として扱う(ためていないときの空白は、項目を選ぶキー)。
|
|
36
|
+
*/
|
|
37
|
+
export declare const isTypeaheadKey: (event: Pick<KeyboardEvent, "key" | "ctrlKey" | "metaKey" | "altKey">, typing: boolean) => boolean;
|
|
38
|
+
/**
|
|
39
|
+
* 打った文字をためる。`push` は 1 文字足して、ためた文字を返す。間が空いたら捨てる。
|
|
40
|
+
* `typing()` は、いま文字をためているか(空白を文字として扱うかの判定に使う)。
|
|
41
|
+
*/
|
|
42
|
+
export declare function useTypeahead(): {
|
|
43
|
+
push: (char: string) => string;
|
|
44
|
+
typing: () => boolean;
|
|
45
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useCallback as e, useEffect as t, useRef as n } from "react";
|
|
3
|
+
//#region src/components/_internal/typeahead.ts
|
|
4
|
+
var r = ({ query: e, current: t, count: n, getText: r, isDisabled: i = () => !1 }) => {
|
|
5
|
+
let a = e.toLowerCase();
|
|
6
|
+
if (a === "" || n <= 0) return -1;
|
|
7
|
+
let o = a.length > 1 && a.split("").every((e) => e === a[0]), s = o ? a[0] : a, c = o || a.length === 1 ? t + 1 : Math.max(t, 0);
|
|
8
|
+
for (let e = 0; e < n; e++) {
|
|
9
|
+
let t = ((c + e) % n + n) % n;
|
|
10
|
+
if (!i(t) && r(t).trim().toLowerCase().startsWith(s)) return t;
|
|
11
|
+
}
|
|
12
|
+
return -1;
|
|
13
|
+
}, i = (e, t) => e.key.length === 1 && !e.ctrlKey && !e.metaKey && !e.altKey && (e.key !== " " || t), a = 500;
|
|
14
|
+
function o() {
|
|
15
|
+
let r = n(""), i = n(void 0);
|
|
16
|
+
return t(() => () => clearTimeout(i.current), []), {
|
|
17
|
+
push: e((e) => (clearTimeout(i.current), r.current += e, i.current = setTimeout(() => {
|
|
18
|
+
r.current = "";
|
|
19
|
+
}, a), r.current), []),
|
|
20
|
+
typing: e(() => r.current !== "", [])
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
//#endregion
|
|
24
|
+
export { r as findTypeaheadIndex, i as isTypeaheadKey, o as useTypeahead };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
const e=require("../../../_virtual/_rolldown/runtime.cjs"),t=require("../../../i18n/useWimTranslation.cjs"),n=require("../../../i18n/generated/common.cjs"),r=require("../../../hooks/useMergedRef.cjs"),i=require("../../layout/Transition/Transition.cjs"),a=require("../../../icon/check.cjs"),o=require("../../../icon/chevron-down.cjs"),s=require("../../media/Icon/Icon.cjs"),c=require("../../_internal/
|
|
2
|
+
const e=require("../../../_virtual/_rolldown/runtime.cjs"),t=require("../../../i18n/useWimTranslation.cjs"),n=require("../../../i18n/generated/common.cjs"),r=require("../../../hooks/useMergedRef.cjs"),i=require("../../layout/Transition/Transition.cjs"),a=require("../../../icon/check.cjs"),o=require("../../../icon/chevron-down.cjs"),s=require("../../media/Icon/Icon.cjs"),c=require("../../_internal/rovingIndex.cjs"),l=require("../../_internal/useInlineFloating.cjs"),u=require("../../_internal/typeahead.cjs"),d=require("./model-selector.module.cjs");let f=require("react");f=e.__toESM(f,1);let p=require("classnames");p=e.__toESM(p,1);let m=require("react/jsx-runtime");var h=e=>e>=1e6?`${(e/1e6).toFixed(e%1e6==0?0:1)}M`:e>=1e3?`${(e/1e3).toFixed(e%1e3==0?0:1)}K`:String(e),g=(e,t=`$`)=>`${t}${e}`,_=f.default.forwardRef(({models:e,value:_,defaultValue:v,onChange:y,size:b=`md`,disabled:x=!1,fullWidth:S=!1,showPricing:C=!0,showContext:ee=!0,labels:te,className:w,"aria-label":T,"aria-labelledby":E,"aria-describedby":D,...O},k)=>{let{t:A}=t.useWimTranslation(n.commonNs),{placeholder:j=A(`modelSelector.placeholder`),contextLabel:M=A(`modelSelector.context`),inputLabel:ne=A(`modelSelector.input`),outputLabel:re=A(`modelSelector.output`),perTokensLabel:N=`/1M`,triggerAriaLabel:P=A(`modelSelector.placeholder`)}=te??{},F=_!==void 0,[I,L]=(0,f.useState)(v),R=F?_:I,z=e.find(e=>e.id===R),[B,V]=(0,f.useState)(!1),[H,U]=(0,f.useState)(-1),W=(0,f.useRef)(null),G=(0,f.useRef)(null),K=(0,f.useId)(),q=`${K}-listbox`,J=(0,f.useCallback)(e=>{W.current=e,typeof k==`function`?k(e):k&&(k.current=e)},[k]);(0,f.useEffect)(()=>{if(!B)return;let e=e=>{W.current&&!W.current.contains(e.target)&&V(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[B]);let Y=e=>{e.disabled||(F||L(e.id),y?.(e.id,e),V(!1))},X=t=>!!e[t]?.disabled,Z=(t,n)=>c.getRovingIndex({key:t,current:n,count:e.length,orientation:`vertical`,isDisabled:X})??-1,ie=()=>Z(`Home`,-1),Q=u.useTypeahead(),$=t=>{let n=e.findIndex(e=>e.id===R);U(t??(n>=0?n:ie())),V(!0)},ae=t=>{if(!x){if(u.isTypeaheadKey(t,Q.typing())){t.preventDefault();let n=u.findTypeaheadIndex({query:Q.push(t.key),current:B?H:-1,count:e.length,getText:t=>e[t].name,isDisabled:X});n>=0&&(B?U(n):$(n))}else if(c.isRovingKey(t.key,`vertical`))t.preventDefault(),!B&&(t.key===`ArrowDown`||t.key===`ArrowUp`)?$():B?U(Z(t.key,H)):$(Z(t.key,-1));else switch(t.key){case`Enter`:case` `:if(t.preventDefault(),!B)$();else{let t=e[H];t&&Y(t)}break;case`Escape`:B&&(t.preventDefault(),V(!1));break;case`Tab`:V(!1)}}};(0,f.useEffect)(()=>{B&&H>=0&&(G.current?.querySelectorAll(`[role="option"]`)?.[H])?.scrollIntoView({block:`nearest`})},[H,B]);let oe=e=>{let t=[];if(ee&&e.contextLength&&t.push((0,m.jsxs)(`span`,{className:d.default.meta,children:[M,` `,h(e.contextLength)]},`ctx`)),C&&e.pricing){let{input:n,output:r,currency:i}=e.pricing;n!==void 0&&t.push((0,m.jsxs)(`span`,{className:d.default.meta,children:[ne,` `,g(n,i),N]},`in`)),r!==void 0&&t.push((0,m.jsxs)(`span`,{className:d.default.meta,children:[re,` `,g(r,i),N]},`out`))}if(t.length===0)return null;let n=t.flatMap((e,t)=>t===0?[e]:[` `,e]);return(0,m.jsx)(`span`,{className:d.default.metaRow,children:n})},{setReference:se,setFloating:ce,floatingProps:le}=l.useInlineFloating({open:B}),ue=r.useMergedRef(J,se);return(0,m.jsxs)(`div`,{ref:ue,className:(0,p.default)(`wim-model-selector`,d.default.root,d.default[b],S&&d.default.fullWidth,x&&d.default.disabled,w),...O,children:[(0,m.jsxs)(`button`,{type:`button`,role:`combobox`,className:d.default.trigger,"aria-haspopup":`listbox`,"aria-expanded":B,"aria-controls":B?q:void 0,"aria-activedescendant":B&&H>=0?`${K}-opt-${H}`:void 0,"aria-label":E?void 0:T??P,"aria-labelledby":E,"aria-describedby":D,disabled:x,onClick:()=>{x||(B?V(!1):$())},onKeyDown:ae,onKeyUp:e=>{e.key===` `&&e.preventDefault()},children:[(0,m.jsx)(`span`,{className:d.default.triggerLabel,children:z?(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(`span`,{className:d.default.triggerName,children:z.name}),` `,z.badge&&(0,m.jsx)(`span`,{className:d.default.badge,children:z.badge})]}):(0,m.jsx)(`span`,{className:d.default.placeholder,children:j})}),(0,m.jsx)(s.Icon,{component:o.default,size:`sm`,className:(0,p.default)(d.default.chevron,B&&d.default.chevronOpen)})]}),(0,m.jsx)(i.Transition,{show:B,preset:`scale`,unmount:!0,className:d.default.dropdownWrapper,ref:ce,...le,children:(0,m.jsx)(`ul`,{ref:G,id:q,role:`listbox`,"aria-label":E?void 0:T??P,"aria-labelledby":E,tabIndex:-1,className:d.default.dropdown,onMouseDown:e=>e.preventDefault(),children:e.map((e,t)=>{let n=e.id===R;return(0,m.jsxs)(`li`,{id:`${K}-opt-${t}`,role:`option`,"aria-selected":n,"aria-disabled":e.disabled||void 0,className:(0,p.default)(d.default.option,t===H&&d.default.active,e.disabled&&d.default.optionDisabled),onMouseEnter:()=>U(t),onClick:()=>Y(e),children:[(0,m.jsx)(`span`,{className:d.default.check,"aria-hidden":`true`,children:n&&(0,m.jsx)(s.Icon,{component:a.default,size:`sm`})}),(0,m.jsxs)(`span`,{className:d.default.optionBody,children:[(0,m.jsxs)(`span`,{className:d.default.optionHeader,children:[(0,m.jsx)(`span`,{className:d.default.optionName,children:e.name}),` `,e.badge&&(0,m.jsx)(`span`,{className:d.default.badge,children:e.badge})]}),` `,e.description&&(0,m.jsx)(`span`,{className:d.default.description,children:e.description}),` `,oe(e)]})]},e.id)})})})]})});_.displayName=`ModelSelector`,exports.ModelSelector=_;
|
|
@@ -4,207 +4,207 @@ import { commonNs as t } from "../../../i18n/generated/common.js";
|
|
|
4
4
|
import { useMergedRef as n } from "../../../hooks/useMergedRef.js";
|
|
5
5
|
import { Transition as r } from "../../layout/Transition/Transition.js";
|
|
6
6
|
import i from "../../../icon/check.js";
|
|
7
|
-
import
|
|
8
|
-
import { Icon as
|
|
9
|
-
import {
|
|
10
|
-
import
|
|
11
|
-
import
|
|
12
|
-
import
|
|
13
|
-
import {
|
|
7
|
+
import ee from "../../../icon/chevron-down.js";
|
|
8
|
+
import { Icon as a } from "../../media/Icon/Icon.js";
|
|
9
|
+
import { getRovingIndex as o, isRovingKey as s } from "../../_internal/rovingIndex.js";
|
|
10
|
+
import { useInlineFloating as te } from "../../_internal/useInlineFloating.js";
|
|
11
|
+
import { findTypeaheadIndex as ne, isTypeaheadKey as re, useTypeahead as ie } from "../../_internal/typeahead.js";
|
|
12
|
+
import c from "./model-selector.module.js";
|
|
13
|
+
import l, { useCallback as u, useEffect as d, useId as f, useRef as p, useState as m } from "react";
|
|
14
|
+
import h from "classnames";
|
|
15
|
+
import { Fragment as ae, jsx as g, jsxs as _ } from "react/jsx-runtime";
|
|
14
16
|
//#region src/components/ai/ModelSelector/ModelSelector.tsx
|
|
15
|
-
var
|
|
16
|
-
let { t:
|
|
17
|
-
|
|
18
|
-
}, [
|
|
19
|
-
|
|
20
|
-
if (!
|
|
17
|
+
var oe = (e) => e >= 1e6 ? `${(e / 1e6).toFixed(e % 1e6 == 0 ? 0 : 1)}M` : e >= 1e3 ? `${(e / 1e3).toFixed(e % 1e3 == 0 ? 0 : 1)}K` : String(e), v = (e, t = "$") => `${t}${e}`, y = l.forwardRef(({ models: l, value: y, defaultValue: b, onChange: se, size: ce = "md", disabled: x = !1, fullWidth: S = !1, showPricing: C = !0, showContext: w = !0, labels: T, className: le, "aria-label": E, "aria-labelledby": D, "aria-describedby": ue, ...de }, O) => {
|
|
18
|
+
let { t: k } = e(t), { placeholder: A = k("modelSelector.placeholder"), contextLabel: j = k("modelSelector.context"), inputLabel: M = k("modelSelector.input"), outputLabel: N = k("modelSelector.output"), perTokensLabel: P = "/1M", triggerAriaLabel: F = k("modelSelector.placeholder") } = T ?? {}, I = y !== void 0, [L, R] = m(b), z = I ? y : L, B = l.find((e) => e.id === z), [V, H] = m(!1), [U, W] = m(-1), G = p(null), K = p(null), q = f(), J = `${q}-listbox`, fe = u((e) => {
|
|
19
|
+
G.current = e, typeof O == "function" ? O(e) : O && (O.current = e);
|
|
20
|
+
}, [O]);
|
|
21
|
+
d(() => {
|
|
22
|
+
if (!V) return;
|
|
21
23
|
let e = (e) => {
|
|
22
|
-
|
|
24
|
+
G.current && !G.current.contains(e.target) && H(!1);
|
|
23
25
|
};
|
|
24
26
|
return document.addEventListener("mousedown", e), () => document.removeEventListener("mousedown", e);
|
|
25
|
-
}, [
|
|
26
|
-
let
|
|
27
|
-
e.disabled || (
|
|
28
|
-
}, Z = (e, t) => {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
break;
|
|
65
|
-
case "Tab": U(!1);
|
|
27
|
+
}, [V]);
|
|
28
|
+
let Y = (e) => {
|
|
29
|
+
e.disabled || (I || R(e.id), se?.(e.id, e), H(!1));
|
|
30
|
+
}, X = (e) => !!l[e]?.disabled, Z = (e, t) => o({
|
|
31
|
+
key: e,
|
|
32
|
+
current: t,
|
|
33
|
+
count: l.length,
|
|
34
|
+
orientation: "vertical",
|
|
35
|
+
isDisabled: X
|
|
36
|
+
}) ?? -1, pe = () => Z("Home", -1), Q = ie(), $ = (e) => {
|
|
37
|
+
let t = l.findIndex((e) => e.id === z);
|
|
38
|
+
W(e ?? (t >= 0 ? t : pe())), H(!0);
|
|
39
|
+
}, me = (e) => {
|
|
40
|
+
if (!x) {
|
|
41
|
+
if (re(e, Q.typing())) {
|
|
42
|
+
e.preventDefault();
|
|
43
|
+
let t = ne({
|
|
44
|
+
query: Q.push(e.key),
|
|
45
|
+
current: V ? U : -1,
|
|
46
|
+
count: l.length,
|
|
47
|
+
getText: (e) => l[e].name,
|
|
48
|
+
isDisabled: X
|
|
49
|
+
});
|
|
50
|
+
t >= 0 && (V ? W(t) : $(t));
|
|
51
|
+
} else if (s(e.key, "vertical")) e.preventDefault(), !V && (e.key === "ArrowDown" || e.key === "ArrowUp") ? $() : V ? W(Z(e.key, U)) : $(Z(e.key, -1));
|
|
52
|
+
else switch (e.key) {
|
|
53
|
+
case "Enter":
|
|
54
|
+
case " ":
|
|
55
|
+
if (e.preventDefault(), !V) $();
|
|
56
|
+
else {
|
|
57
|
+
let e = l[U];
|
|
58
|
+
e && Y(e);
|
|
59
|
+
}
|
|
60
|
+
break;
|
|
61
|
+
case "Escape":
|
|
62
|
+
V && (e.preventDefault(), H(!1));
|
|
63
|
+
break;
|
|
64
|
+
case "Tab": H(!1);
|
|
65
|
+
}
|
|
66
66
|
}
|
|
67
67
|
};
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
}, [
|
|
71
|
-
let
|
|
68
|
+
d(() => {
|
|
69
|
+
V && U >= 0 && (K.current?.querySelectorAll("[role=\"option\"]")?.[U])?.scrollIntoView({ block: "nearest" });
|
|
70
|
+
}, [U, V]);
|
|
71
|
+
let he = (e) => {
|
|
72
72
|
let t = [];
|
|
73
73
|
if (w && e.contextLength && t.push(/* @__PURE__ */ _("span", {
|
|
74
|
-
className:
|
|
74
|
+
className: c.meta,
|
|
75
75
|
children: [
|
|
76
|
-
|
|
76
|
+
j,
|
|
77
77
|
" ",
|
|
78
|
-
|
|
78
|
+
oe(e.contextLength)
|
|
79
79
|
]
|
|
80
|
-
}, "ctx")),
|
|
80
|
+
}, "ctx")), C && e.pricing) {
|
|
81
81
|
let { input: n, output: r, currency: i } = e.pricing;
|
|
82
82
|
n !== void 0 && t.push(/* @__PURE__ */ _("span", {
|
|
83
|
-
className:
|
|
83
|
+
className: c.meta,
|
|
84
84
|
children: [
|
|
85
|
-
|
|
85
|
+
M,
|
|
86
86
|
" ",
|
|
87
87
|
v(n, i),
|
|
88
|
-
|
|
88
|
+
P
|
|
89
89
|
]
|
|
90
90
|
}, "in")), r !== void 0 && t.push(/* @__PURE__ */ _("span", {
|
|
91
|
-
className:
|
|
91
|
+
className: c.meta,
|
|
92
92
|
children: [
|
|
93
|
-
|
|
93
|
+
N,
|
|
94
94
|
" ",
|
|
95
95
|
v(r, i),
|
|
96
|
-
|
|
96
|
+
P
|
|
97
97
|
]
|
|
98
98
|
}, "out"));
|
|
99
99
|
}
|
|
100
100
|
if (t.length === 0) return null;
|
|
101
101
|
let n = t.flatMap((e, t) => t === 0 ? [e] : [" ", e]);
|
|
102
102
|
return /* @__PURE__ */ g("span", {
|
|
103
|
-
className:
|
|
103
|
+
className: c.metaRow,
|
|
104
104
|
children: n
|
|
105
105
|
});
|
|
106
|
-
}, { setReference:
|
|
106
|
+
}, { setReference: ge, setFloating: _e, floatingProps: ve } = te({ open: V }), ye = n(fe, ge);
|
|
107
107
|
return /* @__PURE__ */ _("div", {
|
|
108
|
-
ref:
|
|
109
|
-
className:
|
|
110
|
-
...
|
|
108
|
+
ref: ye,
|
|
109
|
+
className: h("wim-model-selector", c.root, c[ce], S && c.fullWidth, x && c.disabled, le),
|
|
110
|
+
...de,
|
|
111
111
|
children: [/* @__PURE__ */ _("button", {
|
|
112
112
|
type: "button",
|
|
113
113
|
role: "combobox",
|
|
114
|
-
className:
|
|
114
|
+
className: c.trigger,
|
|
115
115
|
"aria-haspopup": "listbox",
|
|
116
|
-
"aria-expanded":
|
|
117
|
-
"aria-controls":
|
|
118
|
-
"aria-activedescendant":
|
|
119
|
-
"aria-label":
|
|
120
|
-
"aria-labelledby":
|
|
121
|
-
"aria-describedby":
|
|
122
|
-
disabled:
|
|
116
|
+
"aria-expanded": V,
|
|
117
|
+
"aria-controls": V ? J : void 0,
|
|
118
|
+
"aria-activedescendant": V && U >= 0 ? `${q}-opt-${U}` : void 0,
|
|
119
|
+
"aria-label": D ? void 0 : E ?? F,
|
|
120
|
+
"aria-labelledby": D,
|
|
121
|
+
"aria-describedby": ue,
|
|
122
|
+
disabled: x,
|
|
123
123
|
onClick: () => {
|
|
124
|
-
|
|
124
|
+
x || (V ? H(!1) : $());
|
|
125
125
|
},
|
|
126
|
-
onKeyDown:
|
|
126
|
+
onKeyDown: me,
|
|
127
127
|
onKeyUp: (e) => {
|
|
128
128
|
e.key === " " && e.preventDefault();
|
|
129
129
|
},
|
|
130
130
|
children: [/* @__PURE__ */ g("span", {
|
|
131
|
-
className:
|
|
132
|
-
children:
|
|
131
|
+
className: c.triggerLabel,
|
|
132
|
+
children: B ? /* @__PURE__ */ _(ae, { children: [
|
|
133
133
|
/* @__PURE__ */ g("span", {
|
|
134
|
-
className:
|
|
135
|
-
children:
|
|
134
|
+
className: c.triggerName,
|
|
135
|
+
children: B.name
|
|
136
136
|
}),
|
|
137
137
|
" ",
|
|
138
|
-
|
|
139
|
-
className:
|
|
140
|
-
children:
|
|
138
|
+
B.badge && /* @__PURE__ */ g("span", {
|
|
139
|
+
className: c.badge,
|
|
140
|
+
children: B.badge
|
|
141
141
|
})
|
|
142
142
|
] }) : /* @__PURE__ */ g("span", {
|
|
143
|
-
className:
|
|
144
|
-
children:
|
|
143
|
+
className: c.placeholder,
|
|
144
|
+
children: A
|
|
145
145
|
})
|
|
146
|
-
}), /* @__PURE__ */ g(
|
|
147
|
-
component:
|
|
146
|
+
}), /* @__PURE__ */ g(a, {
|
|
147
|
+
component: ee,
|
|
148
148
|
size: "sm",
|
|
149
|
-
className:
|
|
149
|
+
className: h(c.chevron, V && c.chevronOpen)
|
|
150
150
|
})]
|
|
151
151
|
}), /* @__PURE__ */ g(r, {
|
|
152
|
-
show:
|
|
152
|
+
show: V,
|
|
153
153
|
preset: "scale",
|
|
154
154
|
unmount: !0,
|
|
155
|
-
className:
|
|
156
|
-
ref:
|
|
157
|
-
...
|
|
155
|
+
className: c.dropdownWrapper,
|
|
156
|
+
ref: _e,
|
|
157
|
+
...ve,
|
|
158
158
|
children: /* @__PURE__ */ g("ul", {
|
|
159
|
-
ref:
|
|
160
|
-
id:
|
|
159
|
+
ref: K,
|
|
160
|
+
id: J,
|
|
161
161
|
role: "listbox",
|
|
162
|
-
"aria-label":
|
|
163
|
-
"aria-labelledby":
|
|
162
|
+
"aria-label": D ? void 0 : E ?? F,
|
|
163
|
+
"aria-labelledby": D,
|
|
164
164
|
tabIndex: -1,
|
|
165
|
-
className:
|
|
165
|
+
className: c.dropdown,
|
|
166
166
|
onMouseDown: (e) => e.preventDefault(),
|
|
167
|
-
children:
|
|
168
|
-
let n = e.id ===
|
|
167
|
+
children: l.map((e, t) => {
|
|
168
|
+
let n = e.id === z;
|
|
169
169
|
return /* @__PURE__ */ _("li", {
|
|
170
|
-
id: `${
|
|
170
|
+
id: `${q}-opt-${t}`,
|
|
171
171
|
role: "option",
|
|
172
172
|
"aria-selected": n,
|
|
173
173
|
"aria-disabled": e.disabled || void 0,
|
|
174
|
-
className:
|
|
175
|
-
onMouseEnter: () =>
|
|
176
|
-
onClick: () =>
|
|
174
|
+
className: h(c.option, t === U && c.active, e.disabled && c.optionDisabled),
|
|
175
|
+
onMouseEnter: () => W(t),
|
|
176
|
+
onClick: () => Y(e),
|
|
177
177
|
children: [/* @__PURE__ */ g("span", {
|
|
178
|
-
className:
|
|
178
|
+
className: c.check,
|
|
179
179
|
"aria-hidden": "true",
|
|
180
|
-
children: n && /* @__PURE__ */ g(
|
|
180
|
+
children: n && /* @__PURE__ */ g(a, {
|
|
181
181
|
component: i,
|
|
182
182
|
size: "sm"
|
|
183
183
|
})
|
|
184
184
|
}), /* @__PURE__ */ _("span", {
|
|
185
|
-
className:
|
|
185
|
+
className: c.optionBody,
|
|
186
186
|
children: [
|
|
187
187
|
/* @__PURE__ */ _("span", {
|
|
188
|
-
className:
|
|
188
|
+
className: c.optionHeader,
|
|
189
189
|
children: [
|
|
190
190
|
/* @__PURE__ */ g("span", {
|
|
191
|
-
className:
|
|
191
|
+
className: c.optionName,
|
|
192
192
|
children: e.name
|
|
193
193
|
}),
|
|
194
194
|
" ",
|
|
195
195
|
e.badge && /* @__PURE__ */ g("span", {
|
|
196
|
-
className:
|
|
196
|
+
className: c.badge,
|
|
197
197
|
children: e.badge
|
|
198
198
|
})
|
|
199
199
|
]
|
|
200
200
|
}),
|
|
201
201
|
" ",
|
|
202
202
|
e.description && /* @__PURE__ */ g("span", {
|
|
203
|
-
className:
|
|
203
|
+
className: c.description,
|
|
204
204
|
children: e.description
|
|
205
205
|
}),
|
|
206
206
|
" ",
|
|
207
|
-
|
|
207
|
+
he(e)
|
|
208
208
|
]
|
|
209
209
|
})]
|
|
210
210
|
}, e.id);
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
const e=require("../../../_virtual/_rolldown/runtime.cjs"),t=require("../../../hooks/useMergedRef.cjs"),n=require("../../_internal/composeEventHandlers.cjs"),r=require("../../layout/Transition/Transition.cjs"),i=require("../../../icon/chevron-right.cjs"),a=require("../../media/Icon/Icon.cjs"),o=require("../../_internal/
|
|
2
|
+
const e=require("../../../_virtual/_rolldown/runtime.cjs"),t=require("../../../hooks/useMergedRef.cjs"),n=require("../../_internal/composeEventHandlers.cjs"),r=require("../../layout/Transition/Transition.cjs"),i=require("../../../icon/chevron-right.cjs"),a=require("../../media/Icon/Icon.cjs"),o=require("../../_internal/rovingIndex.cjs"),s=require("../../_internal/useInlineFloating.cjs"),c=require("../../_internal/BaseListItem/BaseListItem.cjs"),l=require("../InputBase/InputBase.cjs"),u=require("./cascader.module.cjs"),ee=require("../FieldTemplate/FieldTemplate.cjs"),d=require("../../_internal/typeahead.cjs");let f=require("react");f=e.__toESM(f,1);let p=require("classnames");p=e.__toESM(p,1);let m=require("react/jsx-runtime");function h(e){return typeof e==`string`?e:typeof e==`number`?String(e):``}var g=({options:e=[],value:g,onChange:_,placeholder:v,label:y,error:b,required:x,layout:te,className:ne,disabled:S=!1,defaultValue:re,id:ie,expandTrigger:ae=`click`,separator:C=` / `,allowClear:oe=!1,"aria-label":w,"aria-labelledby":se,"aria-describedby":ce,width:le,fullWidth:ue=!1,...T})=>{let E=(0,f.useId)(),D=ie||`wim-cascader-${E}`,O=y?`${D}-label`:void 0,k=b?`${D}-error`:void 0,A=O??se,de=`${D}-trigger`,j=`${D}-popup`,[M,N]=(0,f.useState)(!1),[fe,P]=(0,f.useState)(re||[]),[F,I]=(0,f.useState)([]),[L,R]=(0,f.useState)(-1),[z,B]=(0,f.useState)([]),[pe,V]=(0,f.useState)(!1),H=(0,f.useRef)(null),U=(0,f.useRef)(null),W=g!==void 0,G=W?g:fe;(0,f.useEffect)(()=>{let e=e=>{H.current&&!H.current.contains(e.target)&&N(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[]),(0,f.useEffect)(()=>{if(M&&L>=0){let e=z[L],t=`${D}-menu-${L}-option-${e}`,n=H.current?.querySelector(`#${t}`);n&&n.scrollIntoView({block:`nearest`,behavior:`smooth`})}},[L,z,M,D]);let K=()=>{if(!S){let t=!M;N(t),t?(I(G||[]),R(0),B([o.getRovingIndex({key:`Home`,current:-1,count:e.length,isDisabled:t=>!!e[t]?.disabled})??0])):R(-1)}},me=()=>{if(!G||G.length===0)return null;let t=[],n=e;for(let e of G){let r=n.find(t=>t.value===e);if(r)t.push(r.label),n=r.children||[];else break}return t.length===0?null:t.map((e,n)=>(0,m.jsxs)(f.default.Fragment,{children:[e,n<t.length-1&&(0,m.jsx)(`span`,{children:C})]},n))},q=(t,n)=>{if(t.disabled)return;let r=[...F.slice(0,n),t.value];if(I(r),!t.children||t.children.length===0){if(W||P(r),_){let t=[],n=e;for(let e of r){let r=n.find(t=>t.value===e);r&&(t.push(r),n=r.children||[])}_(r,t)}N(!1),U.current?.focus()}},he=e=>{e?.stopPropagation(),!S&&(W||P([]),_&&_([],[]))},J=(e,t)=>{ae===`hover`&&!e.disabled&&I([...F.slice(0,t),e.value])},Y=d.useTypeahead(),ge=t=>{if(V(!0),S)return;if(!M){(t.key===`Enter`||t.key===` `||t.key===`ArrowDown`||t.key===`ArrowDown`&&t.altKey)&&(t.preventDefault(),K());return}let n=[e],r=e;for(let e=0;e<F.length;e++){let t=F[e],i=r.find(e=>e.value===t);if(i&&i.children&&i.children.length>0)n.push(i.children),r=i.children;else break}let i=n[L]||[],a=z[L]||0,s=e=>t=>!!e[t]?.disabled,c=e=>B(t=>{let n=[...t];return n[L]=e,n});if(d.isTypeaheadKey(t,Y.typing())){t.preventDefault();let e=d.findTypeaheadIndex({query:Y.push(t.key),current:a,count:i.length,getText:e=>{let t=i[e]?.label;return typeof t==`string`?t:String(i[e]?.value??``)},isDisabled:s(i)});e>=0&&c(e)}else if(o.isRovingKey(t.key,`vertical`)){t.preventDefault();let e=o.getRovingIndex({key:t.key,current:a,count:i.length,orientation:`vertical`,isDisabled:s(i)});e!==null&&c(e)}else switch(t.key){case`ArrowRight`:{t.preventDefault();let e=i[a];if(e&&!e.disabled&&e.children&&e.children.length>0){let t=e.children,n=o.getRovingIndex({key:`Home`,current:-1,count:t.length,isDisabled:s(t)})??0;I([...F.slice(0,L),e.value]),R(L+1),B(e=>[...e.slice(0,L+1),n])}break}case`ArrowLeft`:t.preventDefault(),L>0&&(R(L-1),B(e=>e.slice(0,L)));break;case`Enter`:case` `:{t.preventDefault();let e=i[a];e&&!e.disabled&&q(e,L);break}case`Escape`:t.preventDefault(),N(!1),R(-1),U.current?.focus();break;case`Tab`:M&&(N(!1),R(-1))}},X=[e],Z=e;for(let e=0;e<F.length;e++){let t=F[e],n=Z.find(e=>e.value===t);if(n&&n.children&&n.children.length>0)X.push(n.children),Z=n.children;else break}let Q=me(),$=()=>{if(!G||G.length===0)return``;let t=[],n=e;for(let e of G){let r=n.find(t=>t.value===e);if(r)t.push(h(r.label)),n=r.children||[];else break}return t.join(C)},{setReference:_e,setFloating:ve,floatingProps:ye}=s.useInlineFloating({open:M&&!S}),be=t.useMergedRef(H,_e);return(0,m.jsx)(ee.FieldTemplate,{label:y,error:b,required:x,layout:te,labelId:O,errorId:k,className:(0,p.default)(`wim-cascader`,ne),children:(0,m.jsxs)(`div`,{className:u.default.root,ref:be,"data-keyboard-nav":pe,...T,onMouseMove:n.composeEventHandlers(T.onMouseMove,()=>V(!1)),children:[(0,m.jsx)(l.InputBase,{disabled:S,allowClear:oe,hasValue:!!Q,onClear:he,intent:b?`danger`:`default`,width:le,fullWidth:ue,rightIcons:[{name:`ChevronDownIcon`,rotated:M}],className:(0,p.default)(M&&u.default.open),children:(0,m.jsx)(`div`,{id:de,ref:U,className:(0,p.default)(u.default.trigger,S&&u.default.disabled),onClick:K,onKeyDown:ge,tabIndex:S?-1:0,role:`combobox`,"aria-expanded":M,"aria-controls":M?j:void 0,"aria-haspopup":`listbox`,"aria-disabled":S,"aria-labelledby":A,"aria-label":A?void 0:w||$()||h(v),"aria-describedby":[ce,k].filter(Boolean).join(` `)||void 0,"aria-required":x,"aria-invalid":!!b,"aria-activedescendant":M&&L>=0?`${D}-menu-${L}-option-${z[L]}`:void 0,children:(0,m.jsx)(`div`,{className:(0,p.default)(u.default.value,!Q&&u.default.placeholder),children:Q||v})})}),(0,m.jsx)(r.Transition,{show:M&&!S,preset:`fade`,id:j,className:u.default.dropdown,ref:ve,...ye,children:X.map((e,t)=>(0,m.jsx)(`div`,{className:u.default.menu,role:`listbox`,"aria-labelledby":A,"aria-label":A?void 0:w||$()||h(v),children:e.map((e,n)=>{let r=F[t]===e.value,o=L===t&&z[t]===n,s=G[t]===e.value,l=e.children&&e.children.length>0;return(0,m.jsx)(c.BaseListItem,{className:(0,p.default)(u.default.menuItem,s&&u.default.selected),active:o||r,disabled:e.disabled,onClick:n=>{n.stopPropagation(),q(e,t)},onMouseEnter:()=>{J(e,t),R(t),B(e=>[...e.slice(0,t),n])},rightSection:l?(0,m.jsx)(a.Icon,{component:i.default,size:`sm`}):void 0,role:`option`,id:`${D}-menu-${t}-option-${n}`,"aria-selected":s,tabIndex:-1,children:e.label},e.value)})},t))})]})})};g.displayName=`Cascader`,exports.Cascader=g;
|