@rockshin/tao-ui 0.0.35 → 0.0.37
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/popover/popover.css +1 -1
- package/dist/components/select/select.js +32 -171
- package/dist/components/select/use-select-selection.d.ts +16 -0
- package/dist/components/select/use-select-selection.js +260 -0
- package/dist/components/table/table.js +438 -501
- package/dist/components/table/use-table-data.d.ts +21 -0
- package/dist/components/table/use-table-data.js +244 -0
- package/package.json +1 -1
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
user-select: text;
|
|
15
15
|
filter: var(--tao-drop-shadow-popover);
|
|
16
16
|
transform-origin: var(--radix-popover-content-transform-origin);
|
|
17
|
-
z-index:
|
|
17
|
+
z-index: var(--tao-z-index-popup);
|
|
18
18
|
animation-duration: var(--tao-motion-duration-mid);
|
|
19
19
|
animation-timing-function: var(--tao-motion-ease-out);
|
|
20
20
|
}
|
|
@@ -4,9 +4,10 @@ import { TaoPortalScope, useTaoConfig } from "../../provider/tao-provider.js";
|
|
|
4
4
|
import { cx } from "../../utils/semantic.js";
|
|
5
5
|
import { MobileSelectDrawer } from "./mobile-select.js";
|
|
6
6
|
import { CheckIcon, ChevronDownIcon, CloseIcon, LoadingIcon, SearchIcon } from "./select-icons.js";
|
|
7
|
-
import {
|
|
7
|
+
import { defaultFilter, filterTree, flattenLeafOptions } from "./select-model.js";
|
|
8
8
|
import { SearchableSelectList } from "./select-searchable-list.js";
|
|
9
9
|
import { SelectTags } from "./select-tags.js";
|
|
10
|
+
import { useSelectSelection } from "./use-select-selection.js";
|
|
10
11
|
import "./select.css";
|
|
11
12
|
import { useIsMobile } from "../../utils/breakpoint.js";
|
|
12
13
|
import * as __rspack_external__radix_ui_react_popover_c8444160 from "@radix-ui/react-popover";
|
|
@@ -30,7 +31,7 @@ const PLACEMENT_MAP = {
|
|
|
30
31
|
}
|
|
31
32
|
};
|
|
32
33
|
const select_Select = /*#__PURE__*/ forwardRef(function(props, ref) {
|
|
33
|
-
const { options,
|
|
34
|
+
const { options, mode, placeholder, size, variant, disabled, status, showSearch, filterOption, searchValue: searchValueProp, onSearch, allowClear, loading, loadingIcon, notFoundContent = 'No results', prefix, suffixIcon, removeIcon, autoFocus, id, name, open: openProp, defaultOpen, onOpenChange, placement = 'bottomLeft', popupMatchSelectWidth = true, listHeight = 256, getPopupContainer, optionRender, labelRender, popupRender, tagRender, maxTagCount, maxTagPlaceholder, maxTagTextLength, maxCount, autoClearSearchValue = true, tokenSeparators, hideSelected, mobile, className, style, classNames, styles } = props;
|
|
34
35
|
const ctx = useTaoConfig();
|
|
35
36
|
const resolvedSize = size ?? ctx.size;
|
|
36
37
|
const resolvedVariant = variant ?? ctx.variant;
|
|
@@ -51,18 +52,7 @@ const select_Select = /*#__PURE__*/ forwardRef(function(props, ref) {
|
|
|
51
52
|
}), [
|
|
52
53
|
hasInlineSearch
|
|
53
54
|
]);
|
|
54
|
-
const
|
|
55
|
-
const [valueInternal, setValueInternal] = useState(isMultiple ? defaultValue ?? [] : defaultValue);
|
|
56
|
-
const value = isValueControlled ? valueProp : valueInternal;
|
|
57
|
-
const valueArray = useMemo(()=>{
|
|
58
|
-
if (isMultiple) return value ?? [];
|
|
59
|
-
return value ? [
|
|
60
|
-
value
|
|
61
|
-
] : [];
|
|
62
|
-
}, [
|
|
63
|
-
isMultiple,
|
|
64
|
-
value
|
|
65
|
-
]);
|
|
55
|
+
const { value, valueArray, selectedValueSet, selectedOption, selectedOptions, select: selectValue, addTokens, remove: removeValue, commit: handleMultiChange, clear: clearValue } = useSelectSelection(props, resolvedDisabled);
|
|
66
56
|
const isOpenControlled = void 0 !== openProp;
|
|
67
57
|
const [openInternal, setOpenInternal] = useState(defaultOpen ?? false);
|
|
68
58
|
const requestedOpen = isOpenControlled ? openProp : openInternal;
|
|
@@ -79,85 +69,21 @@ const select_Select = /*#__PURE__*/ forwardRef(function(props, ref) {
|
|
|
79
69
|
]);
|
|
80
70
|
const [hovering, setHovering] = useState(false);
|
|
81
71
|
const suppressCloseRef = useRef(false);
|
|
82
|
-
const { optionByToken, optionByValue } = useMemo(()=>buildSelectIndex(options), [
|
|
83
|
-
options
|
|
84
|
-
]);
|
|
85
|
-
const selectedValueSet = useMemo(()=>new Set(valueArray), [
|
|
86
|
-
valueArray
|
|
87
|
-
]);
|
|
88
72
|
const handleValueChange = useCallback((next)=>{
|
|
89
73
|
if (resolvedDisabled) return;
|
|
90
74
|
if (isMultiple) {
|
|
91
|
-
if (tokenSeparators &&
|
|
92
|
-
const hasSeparator = tokenSeparators.some((separator)=>separator && next.includes(separator));
|
|
93
|
-
if (hasSeparator) {
|
|
94
|
-
const tokens = tokenSeparators.reduce((parts, separator_0)=>separator_0 ? parts.flatMap((part)=>part.split(separator_0)) : parts, [
|
|
95
|
-
next
|
|
96
|
-
]).map((token)=>token.trim()).filter(Boolean);
|
|
97
|
-
const seen = new Set(selectedValueSet);
|
|
98
|
-
const toAdd = [];
|
|
99
|
-
for (const token_0 of tokens){
|
|
100
|
-
const option = optionByToken.get(token_0);
|
|
101
|
-
if (option?.disabled || !option && 'tags' !== mode) continue;
|
|
102
|
-
const value_0 = option?.value ?? token_0;
|
|
103
|
-
if (!seen.has(value_0)) {
|
|
104
|
-
seen.add(value_0);
|
|
105
|
-
toAdd.push(value_0);
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
if (toAdd.length > 0) {
|
|
109
|
-
const nextArray = [
|
|
110
|
-
...valueArray,
|
|
111
|
-
...toAdd
|
|
112
|
-
];
|
|
113
|
-
if (null != maxCount && nextArray.length > maxCount) return;
|
|
114
|
-
if (!isValueControlled) setValueInternal(nextArray);
|
|
115
|
-
const selectedOpts = nextArray.map((v)=>optionByValue.get(v)).filter(Boolean);
|
|
116
|
-
onChange?.(nextArray, selectedOpts);
|
|
117
|
-
for (const v_0 of toAdd){
|
|
118
|
-
const opt = optionByValue.get(v_0);
|
|
119
|
-
if (opt) onSelect?.(v_0, opt);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
return;
|
|
123
|
-
}
|
|
124
|
-
}
|
|
75
|
+
if (tokenSeparators?.some((separator)=>separator && next.includes(separator))) return void addTokens(next);
|
|
125
76
|
if (!hasInlineSearch) suppressCloseRef.current = true;
|
|
126
|
-
const current = valueArray;
|
|
127
|
-
const existed = selectedValueSet.has(next);
|
|
128
|
-
const nextArray_0 = existed ? current.filter((v_1)=>v_1 !== next) : [
|
|
129
|
-
...current,
|
|
130
|
-
next
|
|
131
|
-
];
|
|
132
|
-
if (!existed && null != maxCount && nextArray_0.length > maxCount) return;
|
|
133
|
-
if (!isValueControlled) setValueInternal(nextArray_0);
|
|
134
|
-
const selectedOpts_0 = nextArray_0.map((v_2)=>optionByValue.get(v_2)).filter(Boolean);
|
|
135
|
-
onChange?.(nextArray_0, selectedOpts_0);
|
|
136
|
-
const opt_0 = optionByValue.get(next);
|
|
137
|
-
if (opt_0) if (existed) onDeselect?.(next, opt_0);
|
|
138
|
-
else onSelect?.(next, opt_0);
|
|
139
|
-
if (autoClearSearchValue && !isSearchControlled) setSearchInternal('');
|
|
140
|
-
return;
|
|
141
77
|
}
|
|
142
|
-
|
|
143
|
-
if (!
|
|
144
|
-
onChange?.(next, opt_1);
|
|
145
|
-
if (opt_1) onSelect?.(next, opt_1);
|
|
78
|
+
if (!selectValue(next)) return;
|
|
79
|
+
if (isMultiple && autoClearSearchValue && !isSearchControlled) setSearchInternal('');
|
|
146
80
|
}, [
|
|
147
81
|
isMultiple,
|
|
148
82
|
hasInlineSearch,
|
|
149
|
-
valueArray,
|
|
150
|
-
maxCount,
|
|
151
83
|
tokenSeparators,
|
|
152
84
|
resolvedDisabled,
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
optionByToken,
|
|
156
|
-
optionByValue,
|
|
157
|
-
selectedValueSet,
|
|
158
|
-
onChange,
|
|
159
|
-
onSelect,
|
|
160
|
-
onDeselect,
|
|
85
|
+
selectValue,
|
|
86
|
+
addTokens,
|
|
161
87
|
autoClearSearchValue,
|
|
162
88
|
isSearchControlled
|
|
163
89
|
]);
|
|
@@ -182,9 +108,9 @@ const select_Select = /*#__PURE__*/ forwardRef(function(props, ref) {
|
|
|
182
108
|
showSearch,
|
|
183
109
|
isMobile
|
|
184
110
|
]);
|
|
185
|
-
const handleSearchChange = useCallback((
|
|
186
|
-
if (!isSearchControlled) setSearchInternal(
|
|
187
|
-
onSearch?.(
|
|
111
|
+
const handleSearchChange = useCallback((v)=>{
|
|
112
|
+
if (!isSearchControlled) setSearchInternal(v);
|
|
113
|
+
onSearch?.(v);
|
|
188
114
|
}, [
|
|
189
115
|
isSearchControlled,
|
|
190
116
|
onSearch
|
|
@@ -192,11 +118,11 @@ const select_Select = /*#__PURE__*/ forwardRef(function(props, ref) {
|
|
|
192
118
|
const handleSearchKeyDown = useCallback((e)=>{
|
|
193
119
|
if (isComposingKey(e.nativeEvent)) return;
|
|
194
120
|
if (!isMultiple || !tokenSeparators || 0 === tokenSeparators.length) return;
|
|
195
|
-
const
|
|
196
|
-
const sep = tokenSeparators.find((s)=>s &&
|
|
121
|
+
const value_0 = e.target.value;
|
|
122
|
+
const sep = tokenSeparators.find((s)=>s && value_0.includes(s));
|
|
197
123
|
if (!sep) return;
|
|
198
124
|
e.preventDefault();
|
|
199
|
-
handleValueChange(
|
|
125
|
+
handleValueChange(value_0);
|
|
200
126
|
if (!isSearchControlled) setSearchInternal('');
|
|
201
127
|
}, [
|
|
202
128
|
isMultiple,
|
|
@@ -205,21 +131,6 @@ const select_Select = /*#__PURE__*/ forwardRef(function(props, ref) {
|
|
|
205
131
|
isSearchControlled,
|
|
206
132
|
isComposingKey
|
|
207
133
|
]);
|
|
208
|
-
const clearValue = useCallback(()=>{
|
|
209
|
-
if (isMultiple) {
|
|
210
|
-
if (!isValueControlled) setValueInternal([]);
|
|
211
|
-
onChange?.([], void 0);
|
|
212
|
-
} else {
|
|
213
|
-
if (!isValueControlled) setValueInternal(void 0);
|
|
214
|
-
onChange?.('', void 0);
|
|
215
|
-
}
|
|
216
|
-
onClear?.();
|
|
217
|
-
}, [
|
|
218
|
-
isMultiple,
|
|
219
|
-
isValueControlled,
|
|
220
|
-
onChange,
|
|
221
|
-
onClear
|
|
222
|
-
]);
|
|
223
134
|
const handleClear = useCallback((e_0)=>{
|
|
224
135
|
e_0.stopPropagation();
|
|
225
136
|
clearValue();
|
|
@@ -229,45 +140,9 @@ const select_Select = /*#__PURE__*/ forwardRef(function(props, ref) {
|
|
|
229
140
|
const handleRemoveTag = useCallback((removedValue, e_1)=>{
|
|
230
141
|
e_1.stopPropagation();
|
|
231
142
|
e_1.preventDefault();
|
|
232
|
-
|
|
233
|
-
const nextArray_1 = valueArray.filter((v_4)=>v_4 !== removedValue);
|
|
234
|
-
if (!isValueControlled) setValueInternal(nextArray_1);
|
|
235
|
-
const selectedOpts_1 = nextArray_1.map((v_5)=>optionByValue.get(v_5)).filter(Boolean);
|
|
236
|
-
onChange?.(nextArray_1, selectedOpts_1);
|
|
237
|
-
const opt_2 = optionByValue.get(removedValue);
|
|
238
|
-
if (opt_2) onDeselect?.(removedValue, opt_2);
|
|
239
|
-
}, [
|
|
240
|
-
isMultiple,
|
|
241
|
-
valueArray,
|
|
242
|
-
isValueControlled,
|
|
243
|
-
optionByValue,
|
|
244
|
-
onChange,
|
|
245
|
-
onDeselect
|
|
246
|
-
]);
|
|
247
|
-
const handleMultiChange = useCallback((nextArray_2)=>{
|
|
248
|
-
if (resolvedDisabled) return;
|
|
249
|
-
if (!isValueControlled) setValueInternal(nextArray_2);
|
|
250
|
-
const selectedOpts_2 = nextArray_2.map((v_6)=>optionByValue.get(v_6)).filter(Boolean);
|
|
251
|
-
onChange?.(nextArray_2, selectedOpts_2);
|
|
252
|
-
const prev = valueArray;
|
|
253
|
-
const nextSet = new Set(nextArray_2);
|
|
254
|
-
for (const v_7 of nextArray_2)if (!selectedValueSet.has(v_7)) {
|
|
255
|
-
const opt_3 = optionByValue.get(v_7);
|
|
256
|
-
if (opt_3) onSelect?.(v_7, opt_3);
|
|
257
|
-
}
|
|
258
|
-
for (const v_8 of prev)if (!nextSet.has(v_8)) {
|
|
259
|
-
const opt_4 = optionByValue.get(v_8);
|
|
260
|
-
if (opt_4) onDeselect?.(v_8, opt_4);
|
|
261
|
-
}
|
|
143
|
+
removeValue(removedValue);
|
|
262
144
|
}, [
|
|
263
|
-
|
|
264
|
-
selectedValueSet,
|
|
265
|
-
resolvedDisabled,
|
|
266
|
-
isValueControlled,
|
|
267
|
-
optionByValue,
|
|
268
|
-
onChange,
|
|
269
|
-
onSelect,
|
|
270
|
-
onDeselect
|
|
145
|
+
removeValue
|
|
271
146
|
]);
|
|
272
147
|
const filteredOptions = useMemo(()=>{
|
|
273
148
|
let opts = options;
|
|
@@ -306,20 +181,6 @@ const select_Select = /*#__PURE__*/ forwardRef(function(props, ref) {
|
|
|
306
181
|
const allowClearEnabled = !!allowClear;
|
|
307
182
|
const clearIcon = 'object' == typeof allowClear && allowClear.clearIcon || /*#__PURE__*/ jsx(CloseIcon, {});
|
|
308
183
|
const showClearBtn = allowClearEnabled && (isMultiple ? valueArray.length > 0 : !!value) && !resolvedDisabled;
|
|
309
|
-
const selectedOption = useMemo(()=>!isMultiple && value ? optionByValue.get(value) : void 0, [
|
|
310
|
-
isMultiple,
|
|
311
|
-
value,
|
|
312
|
-
optionByValue
|
|
313
|
-
]);
|
|
314
|
-
const selectedOptions = useMemo(()=>isMultiple ? valueArray.map((v_9)=>optionByValue.get(v_9) ?? ('tags' === mode ? {
|
|
315
|
-
label: v_9,
|
|
316
|
-
value: v_9
|
|
317
|
-
} : void 0)).filter(Boolean) : [], [
|
|
318
|
-
isMultiple,
|
|
319
|
-
valueArray,
|
|
320
|
-
optionByValue,
|
|
321
|
-
mode
|
|
322
|
-
]);
|
|
323
184
|
const statusProps = {
|
|
324
185
|
'data-tao-error': 'error' === status || void 0,
|
|
325
186
|
'data-tao-warning': 'warning' === status || void 0
|
|
@@ -501,23 +362,23 @@ const select_Select = /*#__PURE__*/ forwardRef(function(props, ref) {
|
|
|
501
362
|
const resultCount = filteredFlatOptions.length;
|
|
502
363
|
const overMaxCount = isMultiple && null != maxCount && valueArray.length >= maxCount;
|
|
503
364
|
let optIndex = 0;
|
|
504
|
-
const renderItem = (
|
|
365
|
+
const renderItem = (opt)=>{
|
|
505
366
|
const index = optIndex++;
|
|
506
|
-
const textLabel = 'string' == typeof
|
|
507
|
-
const isSelected = selectedValueSet.has(
|
|
508
|
-
const itemDisabled =
|
|
367
|
+
const textLabel = 'string' == typeof opt.label ? opt.label : String(opt.label);
|
|
368
|
+
const isSelected = selectedValueSet.has(opt.value);
|
|
369
|
+
const itemDisabled = opt.disabled || !isSelected && overMaxCount;
|
|
509
370
|
return /*#__PURE__*/ jsxs(__rspack_external__radix_ui_react_select_4606f4d3.Item, {
|
|
510
|
-
value:
|
|
371
|
+
value: opt.value,
|
|
511
372
|
disabled: itemDisabled,
|
|
512
373
|
"data-tao-select-item": "",
|
|
513
|
-
"data-tao-has-desc": null !=
|
|
374
|
+
"data-tao-has-desc": null != opt.description || void 0,
|
|
514
375
|
"data-tao-selected": isMultiple && isSelected ? '' : void 0,
|
|
515
376
|
className: cx(classNames?.item),
|
|
516
377
|
style: styles?.item,
|
|
517
378
|
children: [
|
|
518
379
|
optionRender ? /*#__PURE__*/ jsxs(Fragment, {
|
|
519
380
|
children: [
|
|
520
|
-
optionRender(
|
|
381
|
+
optionRender(opt, {
|
|
521
382
|
index
|
|
522
383
|
}),
|
|
523
384
|
/*#__PURE__*/ jsx(__rspack_external__radix_ui_react_select_4606f4d3.ItemText, {
|
|
@@ -529,11 +390,11 @@ const select_Select = /*#__PURE__*/ forwardRef(function(props, ref) {
|
|
|
529
390
|
]
|
|
530
391
|
}) : /*#__PURE__*/ jsxs(Fragment, {
|
|
531
392
|
children: [
|
|
532
|
-
null !=
|
|
393
|
+
null != opt.icon && /*#__PURE__*/ jsx("span", {
|
|
533
394
|
"data-tao-select-item-icon": "",
|
|
534
395
|
className: cx(classNames?.itemIcon),
|
|
535
396
|
style: styles?.itemIcon,
|
|
536
|
-
children:
|
|
397
|
+
children: opt.icon
|
|
537
398
|
}),
|
|
538
399
|
/*#__PURE__*/ jsxs("span", {
|
|
539
400
|
"data-tao-select-item-main": "",
|
|
@@ -541,13 +402,13 @@ const select_Select = /*#__PURE__*/ forwardRef(function(props, ref) {
|
|
|
541
402
|
style: styles?.itemLabel,
|
|
542
403
|
children: [
|
|
543
404
|
/*#__PURE__*/ jsx(__rspack_external__radix_ui_react_select_4606f4d3.ItemText, {
|
|
544
|
-
children:
|
|
405
|
+
children: opt.label
|
|
545
406
|
}),
|
|
546
|
-
null !=
|
|
407
|
+
null != opt.description && /*#__PURE__*/ jsx("span", {
|
|
547
408
|
"data-tao-select-item-desc": "",
|
|
548
409
|
className: cx(classNames?.itemDesc),
|
|
549
410
|
style: styles?.itemDesc,
|
|
550
|
-
children:
|
|
411
|
+
children: opt.description
|
|
551
412
|
})
|
|
552
413
|
]
|
|
553
414
|
})
|
|
@@ -561,7 +422,7 @@ const select_Select = /*#__PURE__*/ forwardRef(function(props, ref) {
|
|
|
561
422
|
children: /*#__PURE__*/ jsx(CheckIcon, {})
|
|
562
423
|
})
|
|
563
424
|
]
|
|
564
|
-
},
|
|
425
|
+
}, opt.value);
|
|
565
426
|
};
|
|
566
427
|
const renderTree = (opts_0)=>opts_0.map((o_0)=>o_0.options ? /*#__PURE__*/ jsxs(__rspack_external__radix_ui_react_select_4606f4d3.Group, {
|
|
567
428
|
"data-tao-select-group": "",
|
|
@@ -589,8 +450,8 @@ const select_Select = /*#__PURE__*/ forwardRef(function(props, ref) {
|
|
|
589
450
|
children: notFoundContent
|
|
590
451
|
})
|
|
591
452
|
});
|
|
592
|
-
const isSearchableOptionDisabled = (
|
|
593
|
-
const searchableOptions = filteredFlatOptions.filter((
|
|
453
|
+
const isSearchableOptionDisabled = (option)=>!!option.disabled || overMaxCount && !selectedValueSet.has(option.value);
|
|
454
|
+
const searchableOptions = filteredFlatOptions.filter((option_0)=>!isSearchableOptionDisabled(option_0));
|
|
594
455
|
const lastSearchIndex = Math.max(searchableOptions.length - 1, 0);
|
|
595
456
|
const boundedSearchIndex = Math.min(Math.max(activeSearchIndex, 0), lastSearchIndex);
|
|
596
457
|
if (activeSearchIndex !== boundedSearchIndex) setActiveSearchIndex(boundedSearchIndex);
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { SelectProps } from './select-types';
|
|
2
|
+
type SelectionProps = Pick<SelectProps, 'options' | 'value' | 'defaultValue' | 'mode' | 'maxCount' | 'tokenSeparators' | 'onChange' | 'onSelect' | 'onDeselect' | 'onClear'>;
|
|
3
|
+
/** Owns selection values and their notifications across the Select displays. */
|
|
4
|
+
export declare function useSelectSelection(props: SelectionProps, disabled: boolean): {
|
|
5
|
+
value: string | string[] | undefined;
|
|
6
|
+
valueArray: string[];
|
|
7
|
+
selectedValueSet: Set<string>;
|
|
8
|
+
selectedOption: import("./select-types").SelectOption | undefined;
|
|
9
|
+
selectedOptions: import("./select-types").SelectOption[];
|
|
10
|
+
select: (next: string) => boolean;
|
|
11
|
+
addTokens: (input: string) => void;
|
|
12
|
+
remove: (removed: string) => void;
|
|
13
|
+
commit: (nextArray: string[]) => void;
|
|
14
|
+
clear: () => void;
|
|
15
|
+
};
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
import { c } from "react-compiler-runtime";
|
|
2
|
+
import { useState } from "react";
|
|
3
|
+
import { buildSelectIndex } from "./select-model.js";
|
|
4
|
+
function useSelectSelection(props, disabled) {
|
|
5
|
+
const $ = c(74);
|
|
6
|
+
const { options, value: valueProp, defaultValue, mode, maxCount, tokenSeparators, onChange, onSelect, onDeselect, onClear } = props;
|
|
7
|
+
const multiple = "multiple" === mode || "tags" === mode;
|
|
8
|
+
const controlled = "value" in props;
|
|
9
|
+
let t0;
|
|
10
|
+
if ($[0] !== defaultValue || $[1] !== multiple) {
|
|
11
|
+
t0 = multiple ? defaultValue ?? [] : defaultValue;
|
|
12
|
+
$[0] = defaultValue;
|
|
13
|
+
$[1] = multiple;
|
|
14
|
+
$[2] = t0;
|
|
15
|
+
} else t0 = $[2];
|
|
16
|
+
const [internalValue, setInternalValue] = useState(t0);
|
|
17
|
+
const value = controlled ? valueProp : internalValue;
|
|
18
|
+
let t1;
|
|
19
|
+
bb0: {
|
|
20
|
+
if (multiple) {
|
|
21
|
+
let t2;
|
|
22
|
+
if ($[3] !== value) {
|
|
23
|
+
t2 = value ?? [];
|
|
24
|
+
$[3] = value;
|
|
25
|
+
$[4] = t2;
|
|
26
|
+
} else t2 = $[4];
|
|
27
|
+
t1 = t2;
|
|
28
|
+
break bb0;
|
|
29
|
+
}
|
|
30
|
+
let t2;
|
|
31
|
+
if ($[5] !== value) {
|
|
32
|
+
t2 = value ? [
|
|
33
|
+
value
|
|
34
|
+
] : [];
|
|
35
|
+
$[5] = value;
|
|
36
|
+
$[6] = t2;
|
|
37
|
+
} else t2 = $[6];
|
|
38
|
+
t1 = t2;
|
|
39
|
+
}
|
|
40
|
+
const valueArray = t1;
|
|
41
|
+
let t2;
|
|
42
|
+
if ($[7] !== valueArray) {
|
|
43
|
+
t2 = new Set(valueArray);
|
|
44
|
+
$[7] = valueArray;
|
|
45
|
+
$[8] = t2;
|
|
46
|
+
} else t2 = $[8];
|
|
47
|
+
const selectedValueSet = t2;
|
|
48
|
+
let t3;
|
|
49
|
+
if ($[9] !== options) {
|
|
50
|
+
t3 = buildSelectIndex(options);
|
|
51
|
+
$[9] = options;
|
|
52
|
+
$[10] = t3;
|
|
53
|
+
} else t3 = $[10];
|
|
54
|
+
const { optionByValue, optionByToken } = t3;
|
|
55
|
+
let t4;
|
|
56
|
+
if ($[11] !== controlled || $[12] !== onChange || $[13] !== optionByValue) {
|
|
57
|
+
t4 = (next, t5)=>{
|
|
58
|
+
const clear = void 0 === t5 ? false : t5;
|
|
59
|
+
if (!controlled) setInternalValue(next);
|
|
60
|
+
const nextOptions = clear ? void 0 : Array.isArray(next) ? next.map((item)=>optionByValue.get(item)).filter(_temp) : optionByValue.get(next ?? "");
|
|
61
|
+
onChange?.(next ?? "", nextOptions);
|
|
62
|
+
};
|
|
63
|
+
$[11] = controlled;
|
|
64
|
+
$[12] = onChange;
|
|
65
|
+
$[13] = optionByValue;
|
|
66
|
+
$[14] = t4;
|
|
67
|
+
} else t4 = $[14];
|
|
68
|
+
const publish = t4;
|
|
69
|
+
let t5;
|
|
70
|
+
if ($[15] !== disabled || $[16] !== maxCount || $[17] !== multiple || $[18] !== onDeselect || $[19] !== onSelect || $[20] !== optionByValue || $[21] !== publish || $[22] !== selectedValueSet || $[23] !== valueArray) {
|
|
71
|
+
t5 = (next_0)=>{
|
|
72
|
+
if (disabled) return false;
|
|
73
|
+
const option_0 = optionByValue.get(next_0);
|
|
74
|
+
if (!multiple) {
|
|
75
|
+
publish(next_0);
|
|
76
|
+
if (option_0) onSelect?.(next_0, option_0);
|
|
77
|
+
return true;
|
|
78
|
+
}
|
|
79
|
+
const existed = selectedValueSet.has(next_0);
|
|
80
|
+
const nextArray = existed ? valueArray.filter((item_0)=>item_0 !== next_0) : [
|
|
81
|
+
...valueArray,
|
|
82
|
+
next_0
|
|
83
|
+
];
|
|
84
|
+
if (!existed && null != maxCount && nextArray.length > maxCount) return false;
|
|
85
|
+
publish(nextArray);
|
|
86
|
+
if (option_0) if (existed) onDeselect?.(next_0, option_0);
|
|
87
|
+
else onSelect?.(next_0, option_0);
|
|
88
|
+
return true;
|
|
89
|
+
};
|
|
90
|
+
$[15] = disabled;
|
|
91
|
+
$[16] = maxCount;
|
|
92
|
+
$[17] = multiple;
|
|
93
|
+
$[18] = onDeselect;
|
|
94
|
+
$[19] = onSelect;
|
|
95
|
+
$[20] = optionByValue;
|
|
96
|
+
$[21] = publish;
|
|
97
|
+
$[22] = selectedValueSet;
|
|
98
|
+
$[23] = valueArray;
|
|
99
|
+
$[24] = t5;
|
|
100
|
+
} else t5 = $[24];
|
|
101
|
+
const select = t5;
|
|
102
|
+
let t6;
|
|
103
|
+
if ($[25] !== disabled || $[26] !== maxCount || $[27] !== mode || $[28] !== onSelect || $[29] !== optionByToken || $[30] !== optionByValue || $[31] !== publish || $[32] !== selectedValueSet || $[33] !== tokenSeparators || $[34] !== valueArray) {
|
|
104
|
+
t6 = (input)=>{
|
|
105
|
+
if (disabled) return;
|
|
106
|
+
const tokens = (tokenSeparators ?? []).reduce(_temp2, [
|
|
107
|
+
input
|
|
108
|
+
]).map(_temp3).filter(Boolean);
|
|
109
|
+
const seen = new Set(selectedValueSet);
|
|
110
|
+
const added = [];
|
|
111
|
+
for (const token_0 of tokens){
|
|
112
|
+
const option_1 = optionByToken.get(token_0);
|
|
113
|
+
if (option_1?.disabled || !option_1 && "tags" !== mode) continue;
|
|
114
|
+
const next_1 = option_1?.value ?? token_0;
|
|
115
|
+
if (!seen.has(next_1)) {
|
|
116
|
+
seen.add(next_1);
|
|
117
|
+
added.push(next_1);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
if (0 === added.length) return;
|
|
121
|
+
const nextArray_0 = [
|
|
122
|
+
...valueArray,
|
|
123
|
+
...added
|
|
124
|
+
];
|
|
125
|
+
if (null != maxCount && nextArray_0.length > maxCount) return;
|
|
126
|
+
publish(nextArray_0);
|
|
127
|
+
for (const next_2 of added){
|
|
128
|
+
const option_2 = optionByValue.get(next_2);
|
|
129
|
+
if (option_2) onSelect?.(next_2, option_2);
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
$[25] = disabled;
|
|
133
|
+
$[26] = maxCount;
|
|
134
|
+
$[27] = mode;
|
|
135
|
+
$[28] = onSelect;
|
|
136
|
+
$[29] = optionByToken;
|
|
137
|
+
$[30] = optionByValue;
|
|
138
|
+
$[31] = publish;
|
|
139
|
+
$[32] = selectedValueSet;
|
|
140
|
+
$[33] = tokenSeparators;
|
|
141
|
+
$[34] = valueArray;
|
|
142
|
+
$[35] = t6;
|
|
143
|
+
} else t6 = $[35];
|
|
144
|
+
const addTokens = t6;
|
|
145
|
+
let t7;
|
|
146
|
+
if ($[36] !== multiple || $[37] !== onDeselect || $[38] !== optionByValue || $[39] !== publish || $[40] !== valueArray) {
|
|
147
|
+
t7 = (removed)=>{
|
|
148
|
+
if (!multiple) return;
|
|
149
|
+
publish(valueArray.filter((item_1)=>item_1 !== removed));
|
|
150
|
+
const option_3 = optionByValue.get(removed);
|
|
151
|
+
if (option_3) onDeselect?.(removed, option_3);
|
|
152
|
+
};
|
|
153
|
+
$[36] = multiple;
|
|
154
|
+
$[37] = onDeselect;
|
|
155
|
+
$[38] = optionByValue;
|
|
156
|
+
$[39] = publish;
|
|
157
|
+
$[40] = valueArray;
|
|
158
|
+
$[41] = t7;
|
|
159
|
+
} else t7 = $[41];
|
|
160
|
+
const remove = t7;
|
|
161
|
+
let t8;
|
|
162
|
+
if ($[42] !== disabled || $[43] !== onDeselect || $[44] !== onSelect || $[45] !== optionByValue || $[46] !== publish || $[47] !== selectedValueSet || $[48] !== valueArray) {
|
|
163
|
+
t8 = (nextArray_1)=>{
|
|
164
|
+
if (disabled) return;
|
|
165
|
+
publish(nextArray_1);
|
|
166
|
+
const nextSet = new Set(nextArray_1);
|
|
167
|
+
for (const next_3 of nextArray_1)if (!selectedValueSet.has(next_3)) {
|
|
168
|
+
const option_4 = optionByValue.get(next_3);
|
|
169
|
+
if (option_4) onSelect?.(next_3, option_4);
|
|
170
|
+
}
|
|
171
|
+
for (const previous of valueArray)if (!nextSet.has(previous)) {
|
|
172
|
+
const option_5 = optionByValue.get(previous);
|
|
173
|
+
if (option_5) onDeselect?.(previous, option_5);
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
$[42] = disabled;
|
|
177
|
+
$[43] = onDeselect;
|
|
178
|
+
$[44] = onSelect;
|
|
179
|
+
$[45] = optionByValue;
|
|
180
|
+
$[46] = publish;
|
|
181
|
+
$[47] = selectedValueSet;
|
|
182
|
+
$[48] = valueArray;
|
|
183
|
+
$[49] = t8;
|
|
184
|
+
} else t8 = $[49];
|
|
185
|
+
const commit = t8;
|
|
186
|
+
let t9;
|
|
187
|
+
if ($[50] !== multiple || $[51] !== onClear || $[52] !== publish) {
|
|
188
|
+
t9 = ()=>{
|
|
189
|
+
publish(multiple ? [] : void 0, true);
|
|
190
|
+
onClear?.();
|
|
191
|
+
};
|
|
192
|
+
$[50] = multiple;
|
|
193
|
+
$[51] = onClear;
|
|
194
|
+
$[52] = publish;
|
|
195
|
+
$[53] = t9;
|
|
196
|
+
} else t9 = $[53];
|
|
197
|
+
const clear_0 = t9;
|
|
198
|
+
let t10;
|
|
199
|
+
if ($[54] !== multiple || $[55] !== optionByValue || $[56] !== value) {
|
|
200
|
+
t10 = !multiple && value ? optionByValue.get(value) : void 0;
|
|
201
|
+
$[54] = multiple;
|
|
202
|
+
$[55] = optionByValue;
|
|
203
|
+
$[56] = value;
|
|
204
|
+
$[57] = t10;
|
|
205
|
+
} else t10 = $[57];
|
|
206
|
+
const selectedOption = t10;
|
|
207
|
+
let t11;
|
|
208
|
+
if ($[58] !== mode || $[59] !== multiple || $[60] !== optionByValue || $[61] !== valueArray) {
|
|
209
|
+
t11 = multiple ? valueArray.map((item_2)=>optionByValue.get(item_2) ?? ("tags" === mode ? {
|
|
210
|
+
label: item_2,
|
|
211
|
+
value: item_2
|
|
212
|
+
} : void 0)).filter(_temp4) : [];
|
|
213
|
+
$[58] = mode;
|
|
214
|
+
$[59] = multiple;
|
|
215
|
+
$[60] = optionByValue;
|
|
216
|
+
$[61] = valueArray;
|
|
217
|
+
$[62] = t11;
|
|
218
|
+
} else t11 = $[62];
|
|
219
|
+
const selectedOptions = t11;
|
|
220
|
+
let t12;
|
|
221
|
+
if ($[63] !== addTokens || $[64] !== clear_0 || $[65] !== commit || $[66] !== remove || $[67] !== select || $[68] !== selectedOption || $[69] !== selectedOptions || $[70] !== selectedValueSet || $[71] !== value || $[72] !== valueArray) {
|
|
222
|
+
t12 = {
|
|
223
|
+
value,
|
|
224
|
+
valueArray,
|
|
225
|
+
selectedValueSet,
|
|
226
|
+
selectedOption,
|
|
227
|
+
selectedOptions,
|
|
228
|
+
select,
|
|
229
|
+
addTokens,
|
|
230
|
+
remove,
|
|
231
|
+
commit,
|
|
232
|
+
clear: clear_0
|
|
233
|
+
};
|
|
234
|
+
$[63] = addTokens;
|
|
235
|
+
$[64] = clear_0;
|
|
236
|
+
$[65] = commit;
|
|
237
|
+
$[66] = remove;
|
|
238
|
+
$[67] = select;
|
|
239
|
+
$[68] = selectedOption;
|
|
240
|
+
$[69] = selectedOptions;
|
|
241
|
+
$[70] = selectedValueSet;
|
|
242
|
+
$[71] = value;
|
|
243
|
+
$[72] = valueArray;
|
|
244
|
+
$[73] = t12;
|
|
245
|
+
} else t12 = $[73];
|
|
246
|
+
return t12;
|
|
247
|
+
}
|
|
248
|
+
function _temp4(option_6) {
|
|
249
|
+
return void 0 !== option_6;
|
|
250
|
+
}
|
|
251
|
+
function _temp3(token) {
|
|
252
|
+
return token.trim();
|
|
253
|
+
}
|
|
254
|
+
function _temp2(parts, separator) {
|
|
255
|
+
return separator ? parts.flatMap((part)=>part.split(separator)) : parts;
|
|
256
|
+
}
|
|
257
|
+
function _temp(option) {
|
|
258
|
+
return void 0 !== option;
|
|
259
|
+
}
|
|
260
|
+
export { useSelectSelection };
|