wimui 0.69.0 → 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/InteractiveGraph/interactive-graph.module.cjs +1 -1
- package/dist/components/ai/InteractiveGraph/interactive-graph.module.js +1 -1
- package/dist/components/ai/ModelSelector/ModelSelector.cjs +1 -1
- package/dist/components/ai/ModelSelector/ModelSelector.js +119 -119
- package/dist/components/data-display/FAQSection/FAQSection.cjs +1 -1
- package/dist/components/data-display/FAQSection/FAQSection.js +28 -25
- package/dist/components/data-display/FAQSection/faq-section.module.cjs +1 -1
- package/dist/components/data-display/FAQSection/faq-section.module.js +8 -7
- 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/media/Video/video.module.cjs +1 -1
- package/dist/components/media/Video/video.module.js +2 -2
- 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/i18n/generated/common.cjs +1 -1
- package/dist/i18n/generated/common.js +3 -3
- package/dist/i18n/generated/components.cjs +1 -1
- package/dist/i18n/generated/components.d.ts +1 -1
- package/dist/i18n/generated/components.js +2 -2
- package/dist/i18n/generated/form.cjs +1 -1
- package/dist/i18n/generated/form.d.ts +1 -1
- package/dist/i18n/generated/form.js +4 -4
- package/dist/llms-full.txt +1 -1
- package/dist/llms.txt +1 -1
- package/dist/locales/en/common.json +1 -1
- package/dist/locales/en/components.json +2 -3
- package/dist/locales/en/form.json +3 -4
- package/dist/locales/ja/components.json +0 -1
- package/dist/locales/ja/form.json +1 -2
- package/dist/locales/pt/common.json +2 -2
- package/dist/locales/pt/components.json +2 -3
- package/dist/locales/pt/form.json +3 -4
- package/dist/styles.css +1 -1
- package/dist/wimui.umd.css +1 -1
- package/dist/wimui.umd.js +5 -5
- package/package.json +2 -2
|
@@ -2,150 +2,170 @@
|
|
|
2
2
|
import { useMergedRef as e } from "../../../hooks/useMergedRef.js";
|
|
3
3
|
import t from "../../../icon/check.js";
|
|
4
4
|
import { Icon as n } from "../../media/Icon/Icon.js";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import c from "
|
|
11
|
-
import {
|
|
5
|
+
import { getRovingIndex as r, isRovingKey as i } from "../../_internal/rovingIndex.js";
|
|
6
|
+
import { useInlineFloating as a } from "../../_internal/useInlineFloating.js";
|
|
7
|
+
import { BaseListItem as ee } from "../../_internal/BaseListItem/BaseListItem.js";
|
|
8
|
+
import { InputBase as te } from "../InputBase/InputBase.js";
|
|
9
|
+
import { FieldTemplate as ne } from "../FieldTemplate/FieldTemplate.js";
|
|
10
|
+
import { findTypeaheadIndex as o, isTypeaheadKey as s, useTypeahead as c } from "../../_internal/typeahead.js";
|
|
11
|
+
import { Chip as re } from "../../data-display/Chip/Chip.js";
|
|
12
|
+
import l from "./multiselect.module.js";
|
|
13
|
+
import { useEffect as u, useId as ie, useRef as d, useState as f } from "react";
|
|
12
14
|
import p from "classnames";
|
|
13
|
-
import { jsx as m, jsxs as
|
|
15
|
+
import { jsx as m, jsxs as ae } from "react/jsx-runtime";
|
|
14
16
|
//#region src/components/form/MultiSelect/MultiSelect.tsx
|
|
15
|
-
var
|
|
16
|
-
let [A, j] = f(!1), [
|
|
17
|
-
|
|
17
|
+
var h = ({ options: h = [], value: g, onChange: _, placeholder: v, label: y, error: b, required: x, layout: S, className: C, disabled: w = !1, defaultValue: T = [], allowClear: E = !1, id: D, width: O, fullWidth: k = !1, ...oe }) => {
|
|
18
|
+
let [A, j] = f(!1), [se, M] = f(T), [N, P] = f(-1), [ce, F] = f(!1), I = d(null), L = d(null), R = d(null), z = ie(), B = D || `wim-multiselect-${z}`, V = `${B}-list`, H = y ? `${B}-label` : void 0, U = b ? `${B}-error` : void 0, W = `${B}-trigger`, G = g !== void 0, K = G ? g : se;
|
|
19
|
+
u(() => {
|
|
18
20
|
let e = (e) => {
|
|
19
|
-
|
|
21
|
+
I.current && !I.current.contains(e.target) && j(!1);
|
|
20
22
|
};
|
|
21
23
|
return document.addEventListener("mousedown", e), () => document.removeEventListener("mousedown", e);
|
|
22
24
|
}, []);
|
|
23
|
-
let
|
|
24
|
-
if (
|
|
25
|
+
let le = (e) => {
|
|
26
|
+
if (w || e && e.target.closest("[data-chip-delete]")) return;
|
|
25
27
|
let t = !A;
|
|
26
|
-
j(t),
|
|
27
|
-
},
|
|
28
|
-
if (
|
|
28
|
+
j(t), P(t ? X() : -1);
|
|
29
|
+
}, q = (e) => {
|
|
30
|
+
if (w) return;
|
|
29
31
|
let t;
|
|
30
|
-
t =
|
|
31
|
-
},
|
|
32
|
-
if (e.stopPropagation(),
|
|
33
|
-
let n = (
|
|
34
|
-
|
|
35
|
-
},
|
|
36
|
-
e?.stopPropagation(), !
|
|
37
|
-
},
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
32
|
+
t = K?.includes(e) ? K.filter((t) => t !== e) : [...K || [], e], G || M(t), _ && _(t);
|
|
33
|
+
}, ue = (e, t) => {
|
|
34
|
+
if (e.stopPropagation(), w) return;
|
|
35
|
+
let n = (K || []).filter((e) => e !== t);
|
|
36
|
+
G || M(n), _ && _(n);
|
|
37
|
+
}, de = (e) => {
|
|
38
|
+
e?.stopPropagation(), !w && (G || M([]), _ && _([]));
|
|
39
|
+
}, J = h.filter((e) => K?.includes(e.value)), Y = (e) => !!h[e]?.disabled, X = () => r({
|
|
40
|
+
key: "Home",
|
|
41
|
+
current: -1,
|
|
42
|
+
count: h.length,
|
|
43
|
+
isDisabled: Y
|
|
44
|
+
}) ?? -1, Z = c(), fe = (e) => {
|
|
45
|
+
if (F(!0), !w) {
|
|
46
|
+
if (s(e, Z.typing())) {
|
|
47
|
+
e.preventDefault();
|
|
48
|
+
let t = o({
|
|
49
|
+
query: Z.push(e.key),
|
|
50
|
+
current: A ? N : -1,
|
|
51
|
+
count: h.length,
|
|
52
|
+
getText: (e) => h[e].label,
|
|
53
|
+
isDisabled: Y
|
|
54
|
+
});
|
|
55
|
+
t >= 0 && (j(!0), P(t));
|
|
56
|
+
} else if (A && i(e.key, "vertical")) {
|
|
57
|
+
e.preventDefault();
|
|
58
|
+
let t = r({
|
|
59
|
+
key: e.key,
|
|
60
|
+
current: N,
|
|
61
|
+
count: h.length,
|
|
62
|
+
orientation: "vertical",
|
|
63
|
+
isDisabled: Y
|
|
64
|
+
});
|
|
65
|
+
t !== null && P(t);
|
|
66
|
+
} else switch (e.key) {
|
|
67
|
+
case "ArrowDown":
|
|
68
|
+
e.preventDefault(), j(!0), P(X());
|
|
69
|
+
break;
|
|
70
|
+
case "Enter":
|
|
71
|
+
case " ":
|
|
72
|
+
e.preventDefault(), A ? N >= 0 && !Y(N) && q(h[N].value) : (j(!0), P(X()));
|
|
73
|
+
break;
|
|
74
|
+
case "Escape":
|
|
75
|
+
A && (e.preventDefault(), j(!1), P(-1), R.current?.focus());
|
|
76
|
+
break;
|
|
77
|
+
case "Tab": A && (j(!1), P(-1));
|
|
78
|
+
}
|
|
59
79
|
}
|
|
60
80
|
};
|
|
61
|
-
|
|
62
|
-
A &&
|
|
63
|
-
}, [
|
|
64
|
-
let { "aria-label":
|
|
65
|
-
return /* @__PURE__ */ m(
|
|
66
|
-
label:
|
|
67
|
-
error:
|
|
68
|
-
required:
|
|
69
|
-
layout:
|
|
70
|
-
labelId:
|
|
71
|
-
htmlFor:
|
|
72
|
-
errorId:
|
|
73
|
-
className:
|
|
74
|
-
children: /* @__PURE__ */
|
|
75
|
-
className: p("wim-multi-select",
|
|
76
|
-
ref:
|
|
77
|
-
onMouseMove: () =>
|
|
78
|
-
"data-keyboard-nav":
|
|
79
|
-
|
|
80
|
-
children: [/* @__PURE__ */ m(
|
|
81
|
-
disabled:
|
|
82
|
-
allowClear:
|
|
83
|
-
hasValue:
|
|
84
|
-
onClear:
|
|
85
|
-
intent:
|
|
86
|
-
width:
|
|
87
|
-
fullWidth:
|
|
81
|
+
u(() => {
|
|
82
|
+
A && N >= 0 && L.current && L.current.children[N]?.scrollIntoView({ block: "nearest" });
|
|
83
|
+
}, [N, A]);
|
|
84
|
+
let { "aria-label": pe, "aria-labelledby": Q, "aria-describedby": me, ...he } = oe, { setReference: ge, setFloating: $, floatingProps: _e } = a({ open: A && !w }), ve = e(I, ge), ye = e(L, $);
|
|
85
|
+
return /* @__PURE__ */ m(ne, {
|
|
86
|
+
label: y,
|
|
87
|
+
error: b,
|
|
88
|
+
required: x,
|
|
89
|
+
layout: S,
|
|
90
|
+
labelId: H,
|
|
91
|
+
htmlFor: W,
|
|
92
|
+
errorId: U,
|
|
93
|
+
className: C,
|
|
94
|
+
children: /* @__PURE__ */ ae("div", {
|
|
95
|
+
className: p("wim-multi-select", l.root, k && l.fullWidth),
|
|
96
|
+
ref: ve,
|
|
97
|
+
onMouseMove: () => F(!1),
|
|
98
|
+
"data-keyboard-nav": ce,
|
|
99
|
+
...he,
|
|
100
|
+
children: [/* @__PURE__ */ m(te, {
|
|
101
|
+
disabled: w,
|
|
102
|
+
allowClear: E,
|
|
103
|
+
hasValue: K && K.length > 0,
|
|
104
|
+
onClear: de,
|
|
105
|
+
intent: b ? "danger" : "default",
|
|
106
|
+
width: O,
|
|
107
|
+
fullWidth: k,
|
|
88
108
|
rightIcons: [{
|
|
89
109
|
name: "ChevronDownIcon",
|
|
90
110
|
rotated: A
|
|
91
111
|
}],
|
|
92
|
-
className: p(A &&
|
|
112
|
+
className: p(A && l.open),
|
|
93
113
|
children: /* @__PURE__ */ m("div", {
|
|
94
|
-
id:
|
|
114
|
+
id: W,
|
|
95
115
|
"data-testid": "multiselect-trigger",
|
|
96
|
-
className: p(
|
|
97
|
-
onClick:
|
|
98
|
-
tabIndex:
|
|
116
|
+
className: p(l.trigger, w && l.disabled),
|
|
117
|
+
onClick: le,
|
|
118
|
+
tabIndex: w ? -1 : 0,
|
|
99
119
|
role: "combobox",
|
|
100
120
|
"aria-expanded": A,
|
|
101
121
|
"aria-haspopup": "listbox",
|
|
102
|
-
"aria-controls": A ?
|
|
103
|
-
"aria-disabled":
|
|
104
|
-
"aria-labelledby":
|
|
105
|
-
"aria-describedby":
|
|
106
|
-
"aria-required":
|
|
107
|
-
"aria-invalid": !!
|
|
108
|
-
"aria-label":
|
|
109
|
-
onKeyDown:
|
|
110
|
-
ref:
|
|
111
|
-
"aria-activedescendant": A &&
|
|
122
|
+
"aria-controls": A ? V : void 0,
|
|
123
|
+
"aria-disabled": w,
|
|
124
|
+
"aria-labelledby": H || Q,
|
|
125
|
+
"aria-describedby": U || me,
|
|
126
|
+
"aria-required": x,
|
|
127
|
+
"aria-invalid": !!b,
|
|
128
|
+
"aria-label": y ? void 0 : pe || v,
|
|
129
|
+
onKeyDown: fe,
|
|
130
|
+
ref: R,
|
|
131
|
+
"aria-activedescendant": A && N >= 0 ? `${B}-option-${N}` : void 0,
|
|
112
132
|
children: /* @__PURE__ */ m("div", {
|
|
113
|
-
className: p(
|
|
114
|
-
children:
|
|
133
|
+
className: p(l.value, J.length === 0 && l.placeholder),
|
|
134
|
+
children: J.length > 0 ? J.map((e) => /* @__PURE__ */ m(re, {
|
|
115
135
|
"data-testid": "multiselect-chip",
|
|
116
136
|
size: "sm",
|
|
117
137
|
intent: "neutral",
|
|
118
138
|
variant: "solid",
|
|
119
|
-
disabled:
|
|
120
|
-
onDelete:
|
|
139
|
+
disabled: w,
|
|
140
|
+
onDelete: w ? void 0 : (t) => ue(t, e.value),
|
|
121
141
|
children: e.label
|
|
122
|
-
}, e.value)) :
|
|
142
|
+
}, e.value)) : v
|
|
123
143
|
})
|
|
124
144
|
})
|
|
125
|
-
}), A && !
|
|
126
|
-
id:
|
|
127
|
-
ref:
|
|
128
|
-
className:
|
|
129
|
-
...
|
|
145
|
+
}), A && !w && /* @__PURE__ */ m("ul", {
|
|
146
|
+
id: V,
|
|
147
|
+
ref: ye,
|
|
148
|
+
className: l.list,
|
|
149
|
+
..._e,
|
|
130
150
|
role: "listbox",
|
|
131
151
|
"aria-multiselectable": "true",
|
|
132
|
-
"aria-labelledby":
|
|
133
|
-
children:
|
|
134
|
-
let
|
|
135
|
-
return /* @__PURE__ */ m(
|
|
152
|
+
"aria-labelledby": H || Q || void 0,
|
|
153
|
+
children: h.map((e, r) => {
|
|
154
|
+
let i = K?.includes(e.value), a = r === N;
|
|
155
|
+
return /* @__PURE__ */ m(ee, {
|
|
136
156
|
asChild: !0,
|
|
137
|
-
id: `${
|
|
138
|
-
className: p(
|
|
139
|
-
active:
|
|
157
|
+
id: `${B}-option-${r}`,
|
|
158
|
+
className: p(l.option, i && l.selected),
|
|
159
|
+
active: a,
|
|
140
160
|
disabled: e.disabled,
|
|
141
|
-
onClick: () => !e.disabled &&
|
|
142
|
-
onMouseEnter: () =>
|
|
143
|
-
rightSection:
|
|
161
|
+
onClick: () => !e.disabled && q(e.value),
|
|
162
|
+
onMouseEnter: () => P(r),
|
|
163
|
+
rightSection: i ? /* @__PURE__ */ m(n, {
|
|
144
164
|
component: t,
|
|
145
165
|
size: "sm"
|
|
146
166
|
}) : void 0,
|
|
147
167
|
role: "option",
|
|
148
|
-
"aria-selected":
|
|
168
|
+
"aria-selected": i,
|
|
149
169
|
tabIndex: -1,
|
|
150
170
|
children: /* @__PURE__ */ m("li", { children: e.label })
|
|
151
171
|
}, e.value);
|
|
@@ -154,6 +174,6 @@ var g = ({ options: g = [], value: _, onChange: v, placeholder: y, label: b, err
|
|
|
154
174
|
})
|
|
155
175
|
});
|
|
156
176
|
};
|
|
157
|
-
|
|
177
|
+
h.displayName = "MultiSelect";
|
|
158
178
|
//#endregion
|
|
159
|
-
export {
|
|
179
|
+
export { h as MultiSelect };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
|
|
2
|
+
const e=require("../../_internal/rovingIndex.cjs"),t=require("../../_internal/typeahead.cjs");let n=require("react");function r({options:r,value:i,onChange:a,defaultValue:o,searchable:s,grouped:c,disabled:l,filterOption:u}){let[d,f]=(0,n.useState)(!1),[p,m]=(0,n.useState)(o||``),[h,g]=(0,n.useState)(``),[_,v]=(0,n.useState)(-1),[y,b]=(0,n.useState)(!1),x=(0,n.useRef)(null),S=(0,n.useRef)(null),C=(0,n.useRef)(null),w=(0,n.useRef)([]),T=i!==void 0,E=T?i:p,D=(0,n.useMemo)(()=>c&&r.length>0&&`options`in r[0]?r.flatMap(e=>e.options):r,[r,c]),O=(0,n.useMemo)(()=>{if(!h)return D;let e=u||((e,t)=>{if(e.type===`separator`)return!1;let n=typeof e.label==`string`?e.label:``,r=typeof e.value==`string`?e.value:``,i=t.toLowerCase();return n.toLowerCase().includes(i)||r.toLowerCase().includes(i)});return D.filter(t=>e(t,h))},[D,h,u]),k=D.find(e=>e.value===E);(0,n.useEffect)(()=>{let e=e=>{x.current&&!x.current.contains(e.target)&&(f(!1),g(``),v(-1))};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[]),(0,n.useEffect)(()=>{d&&s&&C.current&&C.current.focus()},[d,s]),(0,n.useEffect)(()=>{_>=0&&w.current[_]&&w.current[_]?.scrollIntoView({block:`nearest`,behavior:`smooth`})},[_]);let A=()=>{l||(f(!d),d||(g(``),v(-1)))},j=e=>{e.type===`separator`||e.disabled||(!T&&e.value!==void 0&&m(e.value),a&&e.value!==void 0&&a(e.value),f(!1),g(``),v(-1),S.current?.focus())},M=()=>{l||(T||m(``),a?.(``))},N=e=>!!O[e]?.disabled||O[e]?.type===`separator`,P=t.useTypeahead();return{isOpen:d,searchValue:h,setSearchValue:g,focusedIndex:_,setFocusedIndex:v,isKeyboardNavigating:y,setIsKeyboardNavigating:b,containerRef:x,triggerRef:S,searchInputRef:C,listItemsRef:w,currentValue:E,flatOptions:D,filteredOptions:O,selectedOption:k,focusedOption:_>=0?O[_]:null,handleToggle:A,handleSelect:j,handleClear:M,handleKeyDown:n=>{if(b(!0),!l){if(!s&&t.isTypeaheadKey(n,P.typing())){n.preventDefault();let e=t.findTypeaheadIndex({query:P.push(n.key),current:d?_:-1,count:O.length,getText:e=>{let t=O[e];return typeof t?.label==`string`?t.label:String(t?.value??``)},isDisabled:N});e>=0&&(f(!0),v(e))}else if(d&&e.isRovingKey(n.key,`vertical`)){n.preventDefault();let t=e.getRovingIndex({key:n.key,current:_,count:O.length,orientation:`vertical`,isDisabled:N});t!==null&&v(t)}else switch(n.key){case`Enter`:case` `:d?_>=0&&O[_]&&j(O[_]):f(!0),n.preventDefault();break;case`Escape`:f(!1),g(``),v(-1),S.current?.focus(),n.preventDefault();break;case`Tab`:d&&(f(!1),g(``),v(-1));break;case`ArrowDown`:n.preventDefault(),f(!0)}}}}}exports.useSelect=r;
|
|
@@ -1,95 +1,103 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import {
|
|
2
|
+
import { getRovingIndex as e, isRovingKey as t } from "../../_internal/rovingIndex.js";
|
|
3
|
+
import { findTypeaheadIndex as n, isTypeaheadKey as r, useTypeahead as i } from "../../_internal/typeahead.js";
|
|
4
|
+
import { useEffect as a, useMemo as o, useRef as s, useState as c } from "react";
|
|
3
5
|
//#region src/components/form/Select/useSelect.ts
|
|
4
|
-
function
|
|
5
|
-
let [
|
|
6
|
-
if (!
|
|
7
|
-
let e =
|
|
6
|
+
function l({ options: l, value: u, onChange: d, defaultValue: f, searchable: p, grouped: m, disabled: h, filterOption: g }) {
|
|
7
|
+
let [_, v] = c(!1), [y, b] = c(f || ""), [x, S] = c(""), [C, w] = c(-1), [T, E] = c(!1), D = s(null), O = s(null), k = s(null), A = s([]), j = u !== void 0, M = j ? u : y, N = o(() => m && l.length > 0 && "options" in l[0] ? l.flatMap((e) => e.options) : l, [l, m]), P = o(() => {
|
|
8
|
+
if (!x) return N;
|
|
9
|
+
let e = g || ((e, t) => {
|
|
8
10
|
if (e.type === "separator") return !1;
|
|
9
11
|
let n = typeof e.label == "string" ? e.label : "", r = typeof e.value == "string" ? e.value : "", i = t.toLowerCase();
|
|
10
12
|
return n.toLowerCase().includes(i) || r.toLowerCase().includes(i);
|
|
11
13
|
});
|
|
12
|
-
return
|
|
14
|
+
return N.filter((t) => e(t, x));
|
|
13
15
|
}, [
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
]),
|
|
18
|
-
|
|
16
|
+
N,
|
|
17
|
+
x,
|
|
18
|
+
g
|
|
19
|
+
]), F = N.find((e) => e.value === M);
|
|
20
|
+
a(() => {
|
|
19
21
|
let e = (e) => {
|
|
20
|
-
|
|
22
|
+
D.current && !D.current.contains(e.target) && (v(!1), S(""), w(-1));
|
|
21
23
|
};
|
|
22
24
|
return document.addEventListener("mousedown", e), () => document.removeEventListener("mousedown", e);
|
|
23
|
-
}, []),
|
|
24
|
-
|
|
25
|
-
}, [
|
|
26
|
-
|
|
25
|
+
}, []), a(() => {
|
|
26
|
+
_ && p && k.current && k.current.focus();
|
|
27
|
+
}, [_, p]), a(() => {
|
|
28
|
+
C >= 0 && A.current[C] && A.current[C]?.scrollIntoView({
|
|
27
29
|
block: "nearest",
|
|
28
30
|
behavior: "smooth"
|
|
29
31
|
});
|
|
30
|
-
}, [
|
|
31
|
-
let
|
|
32
|
-
|
|
33
|
-
},
|
|
34
|
-
e.type === "separator" || e.disabled || (!
|
|
35
|
-
}
|
|
32
|
+
}, [C]);
|
|
33
|
+
let I = () => {
|
|
34
|
+
h || (v(!_), _ || (S(""), w(-1)));
|
|
35
|
+
}, L = (e) => {
|
|
36
|
+
e.type === "separator" || e.disabled || (!j && e.value !== void 0 && b(e.value), d && e.value !== void 0 && d(e.value), v(!1), S(""), w(-1), O.current?.focus());
|
|
37
|
+
}, R = () => {
|
|
38
|
+
h || (j || b(""), d?.(""));
|
|
39
|
+
}, z = (e) => !!P[e]?.disabled || P[e]?.type === "separator", B = i();
|
|
36
40
|
return {
|
|
37
|
-
isOpen:
|
|
38
|
-
searchValue:
|
|
39
|
-
setSearchValue:
|
|
40
|
-
focusedIndex:
|
|
41
|
-
setFocusedIndex:
|
|
42
|
-
isKeyboardNavigating:
|
|
43
|
-
setIsKeyboardNavigating:
|
|
44
|
-
containerRef:
|
|
45
|
-
triggerRef:
|
|
46
|
-
searchInputRef:
|
|
47
|
-
listItemsRef:
|
|
48
|
-
currentValue:
|
|
49
|
-
flatOptions:
|
|
50
|
-
filteredOptions:
|
|
51
|
-
selectedOption:
|
|
52
|
-
focusedOption:
|
|
53
|
-
handleToggle:
|
|
54
|
-
handleSelect:
|
|
55
|
-
handleClear:
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
e.preventDefault(), f && y((e) => {
|
|
80
|
-
let t = e - 1;
|
|
81
|
-
for (t < 0 && (t = k.length - 1); t >= 0 && (k[t]?.disabled || k[t]?.type === "separator");) t--;
|
|
82
|
-
if (t < 0) for (t = k.length - 1; t > e && (k[t]?.disabled || k[t]?.type === "separator");) t--;
|
|
83
|
-
return t >= 0 ? t : e;
|
|
41
|
+
isOpen: _,
|
|
42
|
+
searchValue: x,
|
|
43
|
+
setSearchValue: S,
|
|
44
|
+
focusedIndex: C,
|
|
45
|
+
setFocusedIndex: w,
|
|
46
|
+
isKeyboardNavigating: T,
|
|
47
|
+
setIsKeyboardNavigating: E,
|
|
48
|
+
containerRef: D,
|
|
49
|
+
triggerRef: O,
|
|
50
|
+
searchInputRef: k,
|
|
51
|
+
listItemsRef: A,
|
|
52
|
+
currentValue: M,
|
|
53
|
+
flatOptions: N,
|
|
54
|
+
filteredOptions: P,
|
|
55
|
+
selectedOption: F,
|
|
56
|
+
focusedOption: C >= 0 ? P[C] : null,
|
|
57
|
+
handleToggle: I,
|
|
58
|
+
handleSelect: L,
|
|
59
|
+
handleClear: R,
|
|
60
|
+
handleKeyDown: (i) => {
|
|
61
|
+
if (E(!0), !h) {
|
|
62
|
+
if (!p && r(i, B.typing())) {
|
|
63
|
+
i.preventDefault();
|
|
64
|
+
let e = n({
|
|
65
|
+
query: B.push(i.key),
|
|
66
|
+
current: _ ? C : -1,
|
|
67
|
+
count: P.length,
|
|
68
|
+
getText: (e) => {
|
|
69
|
+
let t = P[e];
|
|
70
|
+
return typeof t?.label == "string" ? t.label : String(t?.value ?? "");
|
|
71
|
+
},
|
|
72
|
+
isDisabled: z
|
|
73
|
+
});
|
|
74
|
+
e >= 0 && (v(!0), w(e));
|
|
75
|
+
} else if (_ && t(i.key, "vertical")) {
|
|
76
|
+
i.preventDefault();
|
|
77
|
+
let t = e({
|
|
78
|
+
key: i.key,
|
|
79
|
+
current: C,
|
|
80
|
+
count: P.length,
|
|
81
|
+
orientation: "vertical",
|
|
82
|
+
isDisabled: z
|
|
84
83
|
});
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
84
|
+
t !== null && w(t);
|
|
85
|
+
} else switch (i.key) {
|
|
86
|
+
case "Enter":
|
|
87
|
+
case " ":
|
|
88
|
+
_ ? C >= 0 && P[C] && L(P[C]) : v(!0), i.preventDefault();
|
|
89
|
+
break;
|
|
90
|
+
case "Escape":
|
|
91
|
+
v(!1), S(""), w(-1), O.current?.focus(), i.preventDefault();
|
|
92
|
+
break;
|
|
93
|
+
case "Tab":
|
|
94
|
+
_ && (v(!1), S(""), w(-1));
|
|
95
|
+
break;
|
|
96
|
+
case "ArrowDown": i.preventDefault(), v(!0);
|
|
97
|
+
}
|
|
90
98
|
}
|
|
91
99
|
}
|
|
92
100
|
};
|
|
93
101
|
}
|
|
94
102
|
//#endregion
|
|
95
|
-
export {
|
|
103
|
+
export { l as useSelect };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
const e=require("../../../_virtual/_rolldown/runtime.cjs"),t=require("../../../i18n/useWimTranslation.cjs"),n=require("../Button/Button.cjs"),r=require("../../_internal/BaseListItem/BaseListItem.cjs"),
|
|
2
|
+
const e=require("../../../_virtual/_rolldown/runtime.cjs"),t=require("../../../i18n/useWimTranslation.cjs"),n=require("../Button/Button.cjs"),r=require("../../_internal/rovingIndex.cjs"),i=require("../../_internal/BaseListItem/BaseListItem.cjs"),a=require("../../../i18n/generated/form.cjs"),o=require("../FieldTemplate/FieldTemplate.cjs"),s=require("../../_internal/typeahead.cjs"),c=require("../Checkbox/Checkbox.cjs"),l=require("../../_internal/useAnnounce.cjs"),u=require("../../data-display/VirtualList/VirtualList.cjs"),d=require("./transfer.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=36,g=50,_=({data:e,title:n,listType:r,id:o,disabled:s,selectedKeys:l,focusedKey:_,setFocusedKey:v,onSelect:y,onSelectAll:b,onKeyDown:x,labels:S={},className:C})=>{let{t:w}=t.useWimTranslation(a.formNs),{noData:T=w(`transfer.no_data`)}=S,E=(0,f.useRef)(null),D=(0,f.useRef)(null),[O,k]=(0,f.useState)(0);(0,f.useEffect)(()=>{let e=E.current;if(!e)return;let t=new ResizeObserver(([e])=>{k(Math.floor(e.contentRect.height))});return t.observe(e),()=>t.disconnect()},[]),(0,f.useEffect)(()=>{if(!_||!D.current||O===0)return;let t=e.findIndex(e=>e.key===_);if(t===-1)return;let n=D.current,r=t*h,i=r+h;r<n.scrollTop?n.scrollTop=r:i>n.scrollTop+O&&(n.scrollTop=i-O)},[_,e,O]);let A=e.filter(e=>!e.disabled).map(e=>e.key),j=l.filter(e=>A.includes(e)),M=A.length>0&&j.length===A.length,N=j.length>0&&j.length<A.length,P=_&&e.some(e=>e.key===_)?`${o}-${r}-option-${_}`:void 0,F=e.length>=g&&O>0,I=(t,n)=>(0,m.jsx)(i.BaseListItem,{id:`${o}-${r}-option-${t.key}`,className:(0,p.default)(d.default.item,_===t.key&&d.default.active),disabled:s||t.disabled,active:_===t.key,onClick:()=>{t.disabled||(v(t.key),y(t.key))},role:`option`,"aria-selected":l.includes(t.key),"aria-disabled":s||t.disabled,"aria-setsize":F?e.length:void 0,"aria-posinset":F?n+1:void 0,icon:(0,m.jsx)(`div`,{className:(0,p.default)(d.default.checkboxVisual,l.includes(t.key)&&d.default.checked,(s||t.disabled)&&d.default.disabled),"aria-hidden":`true`}),children:t.title},t.key),L=typeof n==`string`?n:``;return(0,m.jsxs)(`div`,{className:(0,p.default)(d.default.list,C),children:[(0,m.jsxs)(`div`,{className:d.default.header,children:[(0,m.jsx)(c.Checkbox,{checked:M,indeterminate:N,onChange:()=>b(A,r),disabled:s||A.length===0,children:(0,m.jsx)(`span`,{className:d.default.headerTitle,title:L,children:n})}),(0,m.jsxs)(`span`,{className:d.default.headerCount,children:[j.length,`/`,e.length]})]}),(0,m.jsx)(`div`,{ref:E,className:d.default.body,role:e.length>0?`listbox`:`group`,"aria-multiselectable":e.length>0?`true`:void 0,"aria-label":L,"aria-activedescendant":e.length>0?P:void 0,"aria-disabled":s||void 0,tabIndex:e.length===0?-1:0,onKeyDown:t=>x(t,r,e),onFocus:()=>{if(!_){let t=e.find(e=>!e.disabled);t&&v(t.key)}},style:F?{overflow:`hidden`,padding:0}:void 0,children:e.length===0?(0,m.jsx)(`div`,{className:d.default.empty,"aria-live":`polite`,children:T}):F?(0,m.jsx)(u.VirtualList,{items:e,itemHeight:h,height:O,renderItem:I,itemRole:`none`,ref:D,role:`presentation`}):e.map((e,t)=>I(e,t))})]})},v=({dataSource:e=[],targetKeys:i,onChange:c,titles:u,className:h,style:g,disabled:v=!1,label:y,error:b,required:x,layout:S=`vertical`,labels:C={},"aria-label":w,"aria-labelledby":T,"aria-describedby":E})=>{let{t:D}=t.useWimTranslation(a.formNs),O=u??[D(`transfer.source`),D(`transfer.target`)],{moveToTarget:k=D(`transfer.move_to_target`),moveToSource:A=D(`transfer.move_to_source`),statusMovedToTarget:j=e=>D(`transfer.status_moved_to_target`,{count:e}),statusMovedToSource:M=e=>D(`transfer.status_moved_to_source`,{count:e})}=C,[N,P]=(0,f.useState)([]),[F,I]=(0,f.useState)(i||[]),L=`wim-transfer-${(0,f.useId)()}`,R=y?`${L}-label`:void 0,z=b?`${L}-error`:void 0,B=i!==void 0&&!!c,V=B?i:F,H=(0,f.useMemo)(()=>e.filter(e=>!V.includes(e.key)),[e,V]),U=(0,f.useMemo)(()=>e.filter(e=>V.includes(e.key)),[e,V]),[W,G]=(0,f.useState)(null),[K,q]=(0,f.useState)(null),{announce:J,region:ee}=l.useAnnounce();W&&!H.some(e=>e.key===W)&&G(null),K&&!U.some(e=>e.key===K)&&q(null);let Y=e=>{v||P(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e])},X=(e,t)=>{if(v)return;let n=e;n.every(e=>N.includes(e))?P(e=>e.filter(e=>!n.includes(e))):P(e=>[...new Set([...e,...n])])},Z=e=>{if(v)return;let t=e===`toRight`?H.map(e=>e.key):U.map(e=>e.key),n=N.filter(e=>t.includes(e));if(n.length===0)return;let r=e===`toRight`?[...V,...n]:V.filter(e=>!n.includes(e));B||I(r),c&&c(r,e,n),P(e=>e.filter(e=>!n.includes(e)));let i=e===`toRight`?j(n.length):M(n.length);J(i,{delay:50})},Q=s.useTypeahead(),te=e=>typeof e.title==`string`?e.title:e.key,$=(e,t,n)=>{if(v)return;let i=t===`source`?W:K,a=t===`source`?G:q,o=n.findIndex(e=>e.key===i),c=e=>!!n[e]?.disabled;if(s.isTypeaheadKey(e,Q.typing())){e.preventDefault();let t=s.findTypeaheadIndex({query:Q.push(e.key),current:o,count:n.length,getText:e=>te(n[e]),isDisabled:c});t>=0&&a(n[t].key)}else if(r.isRovingKey(e.key,`vertical`)){e.preventDefault();let t=r.getRovingIndex({key:e.key,current:o,count:n.length,orientation:`vertical`,isDisabled:c});t!==null&&a(n[t].key)}else if(e.key===` `){e.preventDefault();let t=n.find(e=>e.key===i);t&&!t.disabled&&Y(t.key)}else e.key===`Enter`&&(e.preventDefault(),Z(t===`source`?`toRight`:`toLeft`))},ne=N.filter(e=>H.some(t=>t.key===e)).length===0,re=N.filter(e=>U.some(t=>t.key===e)).length===0;return(0,m.jsx)(o.FieldTemplate,{label:y,error:b,required:x,layout:S,labelId:R,errorId:z,className:h,children:(0,m.jsxs)(`div`,{className:(0,p.default)(d.default.container,`wim-transfer`),children:[ee,(0,m.jsxs)(`div`,{className:(0,p.default)(d.default.root,v&&d.default.disabled),style:g,role:`group`,"aria-labelledby":y?R:T,"aria-label":y||T?void 0:w,"aria-describedby":[E,z].filter(Boolean).join(` `)||void 0,children:[(0,m.jsx)(_,{className:`wim-transfer__list`,data:H,title:O[0],listType:`source`,id:L,disabled:v,selectedKeys:N,focusedKey:W,setFocusedKey:G,onSelect:Y,onSelectAll:X,onKeyDown:$,labels:C}),(0,m.jsxs)(`div`,{className:(0,p.default)(d.default.operation,`wim-transfer__operation`),children:[(0,m.jsx)(n.Button,{variant:`outline`,size:`sm`,className:d.default.button,onClick:()=>Z(`toRight`),disabled:v||ne,icon:`ChevronRightIcon`,"aria-label":k}),(0,m.jsx)(n.Button,{variant:`outline`,size:`sm`,className:d.default.button,onClick:()=>Z(`toLeft`),disabled:v||re,icon:`ChevronLeftIcon`,"aria-label":A})]}),(0,m.jsx)(_,{className:`wim-transfer__list`,data:U,title:O[1],listType:`target`,id:L,disabled:v,selectedKeys:N,focusedKey:K,setFocusedKey:q,onSelect:Y,onSelectAll:X,onKeyDown:$,labels:C})]})]})})};exports.Transfer=v;
|