@v-c/select 0.0.1
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/LICENSE +21 -0
- package/dist/BaseSelect/Polite.cjs +37 -0
- package/dist/BaseSelect/Polite.d.ts +7 -0
- package/dist/BaseSelect/Polite.js +34 -0
- package/dist/BaseSelect/index.cjs +763 -0
- package/dist/BaseSelect/index.d.ts +133 -0
- package/dist/BaseSelect/index.js +759 -0
- package/dist/OptGroup.cjs +5 -0
- package/dist/OptGroup.d.ts +6 -0
- package/dist/OptGroup.js +4 -0
- package/dist/Option.cjs +5 -0
- package/dist/Option.d.ts +8 -0
- package/dist/Option.js +4 -0
- package/dist/OptionList.cjs +255 -0
- package/dist/OptionList.d.ts +17 -0
- package/dist/OptionList.js +249 -0
- package/dist/Select.cjs +833 -0
- package/dist/Select.d.ts +96 -0
- package/dist/Select.js +828 -0
- package/dist/SelectContext.cjs +11 -0
- package/dist/SelectContext.d.ts +32 -0
- package/dist/SelectContext.js +9 -0
- package/dist/SelectInput/Affix.cjs +16 -0
- package/dist/SelectInput/Affix.d.ts +2 -0
- package/dist/SelectInput/Affix.js +13 -0
- package/dist/SelectInput/Content/MultipleContent.cjs +142 -0
- package/dist/SelectInput/Content/MultipleContent.d.ts +3 -0
- package/dist/SelectInput/Content/MultipleContent.js +138 -0
- package/dist/SelectInput/Content/Placeholder.cjs +33 -0
- package/dist/SelectInput/Content/Placeholder.d.ts +5 -0
- package/dist/SelectInput/Content/Placeholder.js +30 -0
- package/dist/SelectInput/Content/SingleContent.cjs +80 -0
- package/dist/SelectInput/Content/SingleContent.d.ts +3 -0
- package/dist/SelectInput/Content/SingleContent.js +77 -0
- package/dist/SelectInput/Content/index.cjs +40 -0
- package/dist/SelectInput/Content/index.d.ts +6 -0
- package/dist/SelectInput/Content/index.js +36 -0
- package/dist/SelectInput/Input.cjs +176 -0
- package/dist/SelectInput/Input.d.ts +22 -0
- package/dist/SelectInput/Input.js +173 -0
- package/dist/SelectInput/context.cjs +11 -0
- package/dist/SelectInput/context.d.ts +5 -0
- package/dist/SelectInput/context.js +9 -0
- package/dist/SelectInput/index.cjs +330 -0
- package/dist/SelectInput/index.d.ts +44 -0
- package/dist/SelectInput/index.js +325 -0
- package/dist/SelectTrigger.cjs +189 -0
- package/dist/SelectTrigger.d.ts +26 -0
- package/dist/SelectTrigger.js +185 -0
- package/dist/TransBtn.cjs +69 -0
- package/dist/TransBtn.d.ts +22 -0
- package/dist/TransBtn.js +66 -0
- package/dist/_virtual/rolldown_runtime.cjs +21 -0
- package/dist/hooks/index.cjs +23 -0
- package/dist/hooks/index.d.ts +17 -0
- package/dist/hooks/index.js +12 -0
- package/dist/hooks/useAllowClear.cjs +17 -0
- package/dist/hooks/useAllowClear.d.ts +9 -0
- package/dist/hooks/useAllowClear.js +16 -0
- package/dist/hooks/useBaseProps.cjs +12 -0
- package/dist/hooks/useBaseProps.d.ts +10 -0
- package/dist/hooks/useBaseProps.js +9 -0
- package/dist/hooks/useCache.cjs +36 -0
- package/dist/hooks/useCache.d.ts +7 -0
- package/dist/hooks/useCache.js +34 -0
- package/dist/hooks/useComponents.cjs +15 -0
- package/dist/hooks/useComponents.d.ts +8 -0
- package/dist/hooks/useComponents.js +13 -0
- package/dist/hooks/useFilterOptions.cjs +39 -0
- package/dist/hooks/useFilterOptions.d.ts +3 -0
- package/dist/hooks/useFilterOptions.js +37 -0
- package/dist/hooks/useLock.cjs +26 -0
- package/dist/hooks/useLock.d.ts +1 -0
- package/dist/hooks/useLock.js +24 -0
- package/dist/hooks/useOpen.cjs +58 -0
- package/dist/hooks/useOpen.d.ts +19 -0
- package/dist/hooks/useOpen.js +56 -0
- package/dist/hooks/useOptions.cjs +38 -0
- package/dist/hooks/useOptions.d.ts +13 -0
- package/dist/hooks/useOptions.js +36 -0
- package/dist/hooks/useRefFunc.cjs +12 -0
- package/dist/hooks/useRefFunc.d.ts +6 -0
- package/dist/hooks/useRefFunc.js +10 -0
- package/dist/hooks/useSearchConfig.cjs +21 -0
- package/dist/hooks/useSearchConfig.d.ts +11 -0
- package/dist/hooks/useSearchConfig.js +19 -0
- package/dist/hooks/useSelectTriggerControl.cjs +18 -0
- package/dist/hooks/useSelectTriggerControl.d.ts +2 -0
- package/dist/hooks/useSelectTriggerControl.js +16 -0
- package/dist/index.cjs +16 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +8 -0
- package/dist/interface.cjs +0 -0
- package/dist/interface.d.ts +23 -0
- package/dist/interface.js +0 -0
- package/dist/utils/commonUtil.cjs +37 -0
- package/dist/utils/commonUtil.d.ts +12 -0
- package/dist/utils/commonUtil.js +30 -0
- package/dist/utils/keyUtil.cjs +36 -0
- package/dist/utils/keyUtil.d.ts +2 -0
- package/dist/utils/keyUtil.js +34 -0
- package/dist/utils/legacyUtil.cjs +32 -0
- package/dist/utils/legacyUtil.d.ts +3 -0
- package/dist/utils/legacyUtil.js +31 -0
- package/dist/utils/platformUtil.cjs +5 -0
- package/dist/utils/platformUtil.d.ts +1 -0
- package/dist/utils/platformUtil.js +5 -0
- package/dist/utils/valueUtil.cjs +79 -0
- package/dist/utils/valueUtil.d.ts +18 -0
- package/dist/utils/valueUtil.js +75 -0
- package/package.json +43 -0
package/dist/Select.js
ADDED
|
@@ -0,0 +1,828 @@
|
|
|
1
|
+
import { useSelectProvider } from "./SelectContext.js";
|
|
2
|
+
import { fillFieldNames, flattenOptions, injectPropsWithOption } from "./utils/valueUtil.js";
|
|
3
|
+
import OptionList_default from "./OptionList.js";
|
|
4
|
+
import { hasValue, isComboNoValue, toArray } from "./utils/commonUtil.js";
|
|
5
|
+
import { BaseSelect, isMultiple } from "./BaseSelect/index.js";
|
|
6
|
+
import useCache from "./hooks/useCache.js";
|
|
7
|
+
import useFilterOptions from "./hooks/useFilterOptions.js";
|
|
8
|
+
import useOptions from "./hooks/useOptions.js";
|
|
9
|
+
import useRefFunc from "./hooks/useRefFunc.js";
|
|
10
|
+
import useSearchConfig from "./hooks/useSearchConfig.js";
|
|
11
|
+
import { convertChildrenToData } from "./utils/legacyUtil.js";
|
|
12
|
+
import { computed, createVNode, defineComponent, mergeDefaults, mergeProps, shallowRef, toRef, watch } from "vue";
|
|
13
|
+
import useId from "@v-c/util/dist/hooks/useId";
|
|
14
|
+
import omit from "@v-c/util/dist/omit";
|
|
15
|
+
import { filterEmpty } from "@v-c/util/dist/props-util";
|
|
16
|
+
var OMIT_DOM_PROPS = ["inputValue"];
|
|
17
|
+
var omitKeyList = [
|
|
18
|
+
"id",
|
|
19
|
+
"mode",
|
|
20
|
+
"prefixCls",
|
|
21
|
+
"backfill",
|
|
22
|
+
"fieldNames",
|
|
23
|
+
"showSearch",
|
|
24
|
+
"searchValue",
|
|
25
|
+
"onSearch",
|
|
26
|
+
"autoClearSearchValue",
|
|
27
|
+
"filterOption",
|
|
28
|
+
"optionFilterProp",
|
|
29
|
+
"filterSort",
|
|
30
|
+
"onSelect",
|
|
31
|
+
"onDeselect",
|
|
32
|
+
"onActive",
|
|
33
|
+
"popupMatchSelectWidth",
|
|
34
|
+
"optionLabelProp",
|
|
35
|
+
"options",
|
|
36
|
+
"optionRender",
|
|
37
|
+
"children",
|
|
38
|
+
"defaultActiveFirstOption",
|
|
39
|
+
"menuItemSelectedIcon",
|
|
40
|
+
"virtual",
|
|
41
|
+
"direction",
|
|
42
|
+
"listHeight",
|
|
43
|
+
"listItemHeight",
|
|
44
|
+
"labelRender",
|
|
45
|
+
"value",
|
|
46
|
+
"defaultValue",
|
|
47
|
+
"labelInValue",
|
|
48
|
+
"onChange",
|
|
49
|
+
"maxCount",
|
|
50
|
+
"classNames",
|
|
51
|
+
"styles"
|
|
52
|
+
];
|
|
53
|
+
function isRawValue(value) {
|
|
54
|
+
return !value || typeof value !== "object";
|
|
55
|
+
}
|
|
56
|
+
var Select_default = /* @__PURE__ */ defineComponent({
|
|
57
|
+
props: /* @__PURE__ */ mergeDefaults({
|
|
58
|
+
prefixCls: {
|
|
59
|
+
type: String,
|
|
60
|
+
required: false,
|
|
61
|
+
default: void 0
|
|
62
|
+
},
|
|
63
|
+
id: {
|
|
64
|
+
type: String,
|
|
65
|
+
required: false,
|
|
66
|
+
default: void 0
|
|
67
|
+
},
|
|
68
|
+
backfill: {
|
|
69
|
+
type: Boolean,
|
|
70
|
+
required: false,
|
|
71
|
+
default: void 0
|
|
72
|
+
},
|
|
73
|
+
fieldNames: {
|
|
74
|
+
type: Object,
|
|
75
|
+
required: false,
|
|
76
|
+
default: void 0
|
|
77
|
+
},
|
|
78
|
+
onSearch: {
|
|
79
|
+
type: Function,
|
|
80
|
+
required: false,
|
|
81
|
+
default: void 0
|
|
82
|
+
},
|
|
83
|
+
showSearch: {
|
|
84
|
+
type: [Boolean, Object],
|
|
85
|
+
required: false,
|
|
86
|
+
default: void 0
|
|
87
|
+
},
|
|
88
|
+
searchValue: {
|
|
89
|
+
type: String,
|
|
90
|
+
required: false,
|
|
91
|
+
default: void 0
|
|
92
|
+
},
|
|
93
|
+
autoClearSearchValue: {
|
|
94
|
+
type: Boolean,
|
|
95
|
+
required: false,
|
|
96
|
+
default: void 0
|
|
97
|
+
},
|
|
98
|
+
onSelect: {
|
|
99
|
+
type: Function,
|
|
100
|
+
required: false,
|
|
101
|
+
default: void 0
|
|
102
|
+
},
|
|
103
|
+
onDeselect: {
|
|
104
|
+
type: Function,
|
|
105
|
+
required: false,
|
|
106
|
+
default: void 0
|
|
107
|
+
},
|
|
108
|
+
onActive: {
|
|
109
|
+
type: Function,
|
|
110
|
+
required: false,
|
|
111
|
+
default: void 0
|
|
112
|
+
},
|
|
113
|
+
filterOption: {
|
|
114
|
+
type: [Boolean, Function],
|
|
115
|
+
required: false,
|
|
116
|
+
default: void 0
|
|
117
|
+
},
|
|
118
|
+
filterSort: {
|
|
119
|
+
type: Function,
|
|
120
|
+
required: false,
|
|
121
|
+
default: void 0
|
|
122
|
+
},
|
|
123
|
+
optionFilterProp: {
|
|
124
|
+
type: String,
|
|
125
|
+
required: false,
|
|
126
|
+
default: void 0
|
|
127
|
+
},
|
|
128
|
+
optionLabelProp: {
|
|
129
|
+
type: String,
|
|
130
|
+
required: false,
|
|
131
|
+
default: void 0
|
|
132
|
+
},
|
|
133
|
+
options: {
|
|
134
|
+
type: Array,
|
|
135
|
+
required: false,
|
|
136
|
+
default: void 0
|
|
137
|
+
},
|
|
138
|
+
optionRender: {
|
|
139
|
+
type: Function,
|
|
140
|
+
required: false,
|
|
141
|
+
default: void 0
|
|
142
|
+
},
|
|
143
|
+
defaultActiveFirstOption: {
|
|
144
|
+
type: Boolean,
|
|
145
|
+
required: false,
|
|
146
|
+
default: void 0
|
|
147
|
+
},
|
|
148
|
+
virtual: {
|
|
149
|
+
type: Boolean,
|
|
150
|
+
required: false,
|
|
151
|
+
default: void 0
|
|
152
|
+
},
|
|
153
|
+
direction: {
|
|
154
|
+
type: String,
|
|
155
|
+
required: false,
|
|
156
|
+
default: void 0
|
|
157
|
+
},
|
|
158
|
+
listHeight: {
|
|
159
|
+
type: Number,
|
|
160
|
+
required: false,
|
|
161
|
+
default: void 0
|
|
162
|
+
},
|
|
163
|
+
listItemHeight: {
|
|
164
|
+
type: Number,
|
|
165
|
+
required: false,
|
|
166
|
+
default: void 0
|
|
167
|
+
},
|
|
168
|
+
labelRender: {
|
|
169
|
+
type: Function,
|
|
170
|
+
required: false,
|
|
171
|
+
default: void 0
|
|
172
|
+
},
|
|
173
|
+
menuItemSelectedIcon: {
|
|
174
|
+
type: [
|
|
175
|
+
Object,
|
|
176
|
+
Function,
|
|
177
|
+
String,
|
|
178
|
+
Number,
|
|
179
|
+
null,
|
|
180
|
+
Boolean,
|
|
181
|
+
Array
|
|
182
|
+
],
|
|
183
|
+
required: false,
|
|
184
|
+
default: void 0
|
|
185
|
+
},
|
|
186
|
+
mode: {
|
|
187
|
+
type: String,
|
|
188
|
+
required: false,
|
|
189
|
+
default: void 0
|
|
190
|
+
},
|
|
191
|
+
labelInValue: {
|
|
192
|
+
type: Boolean,
|
|
193
|
+
required: false,
|
|
194
|
+
default: void 0
|
|
195
|
+
},
|
|
196
|
+
value: {
|
|
197
|
+
required: false,
|
|
198
|
+
default: void 0
|
|
199
|
+
},
|
|
200
|
+
defaultValue: {
|
|
201
|
+
required: false,
|
|
202
|
+
default: void 0
|
|
203
|
+
},
|
|
204
|
+
maxCount: {
|
|
205
|
+
type: Number,
|
|
206
|
+
required: false,
|
|
207
|
+
default: void 0
|
|
208
|
+
},
|
|
209
|
+
onChange: {
|
|
210
|
+
type: Function,
|
|
211
|
+
required: false,
|
|
212
|
+
default: void 0
|
|
213
|
+
},
|
|
214
|
+
classNames: {
|
|
215
|
+
type: Object,
|
|
216
|
+
required: false,
|
|
217
|
+
default: void 0
|
|
218
|
+
},
|
|
219
|
+
styles: {
|
|
220
|
+
type: Object,
|
|
221
|
+
required: false,
|
|
222
|
+
default: void 0
|
|
223
|
+
},
|
|
224
|
+
className: {
|
|
225
|
+
type: String,
|
|
226
|
+
required: false,
|
|
227
|
+
default: void 0
|
|
228
|
+
},
|
|
229
|
+
style: {
|
|
230
|
+
type: Object,
|
|
231
|
+
required: false,
|
|
232
|
+
default: void 0
|
|
233
|
+
},
|
|
234
|
+
tagRender: {
|
|
235
|
+
type: Function,
|
|
236
|
+
required: false,
|
|
237
|
+
default: void 0
|
|
238
|
+
},
|
|
239
|
+
autoFocus: {
|
|
240
|
+
type: Boolean,
|
|
241
|
+
required: false,
|
|
242
|
+
default: void 0
|
|
243
|
+
},
|
|
244
|
+
placeholder: {
|
|
245
|
+
type: [
|
|
246
|
+
Object,
|
|
247
|
+
Function,
|
|
248
|
+
String,
|
|
249
|
+
Number,
|
|
250
|
+
null,
|
|
251
|
+
Boolean,
|
|
252
|
+
Array
|
|
253
|
+
],
|
|
254
|
+
required: false,
|
|
255
|
+
default: void 0
|
|
256
|
+
},
|
|
257
|
+
title: {
|
|
258
|
+
type: String,
|
|
259
|
+
required: false,
|
|
260
|
+
default: void 0
|
|
261
|
+
},
|
|
262
|
+
tabIndex: {
|
|
263
|
+
type: Number,
|
|
264
|
+
required: false,
|
|
265
|
+
default: void 0
|
|
266
|
+
},
|
|
267
|
+
notFoundContent: {
|
|
268
|
+
type: [
|
|
269
|
+
Object,
|
|
270
|
+
Function,
|
|
271
|
+
String,
|
|
272
|
+
Number,
|
|
273
|
+
null,
|
|
274
|
+
Boolean,
|
|
275
|
+
Array
|
|
276
|
+
],
|
|
277
|
+
required: false,
|
|
278
|
+
default: void 0
|
|
279
|
+
},
|
|
280
|
+
onClear: {
|
|
281
|
+
type: Function,
|
|
282
|
+
required: false,
|
|
283
|
+
default: void 0
|
|
284
|
+
},
|
|
285
|
+
maxLength: {
|
|
286
|
+
type: Number,
|
|
287
|
+
required: false,
|
|
288
|
+
default: void 0
|
|
289
|
+
},
|
|
290
|
+
showScrollBar: {
|
|
291
|
+
type: [Boolean, String],
|
|
292
|
+
required: false,
|
|
293
|
+
default: void 0
|
|
294
|
+
},
|
|
295
|
+
choiceTransitionName: {
|
|
296
|
+
type: String,
|
|
297
|
+
required: false,
|
|
298
|
+
default: void 0
|
|
299
|
+
},
|
|
300
|
+
disabled: {
|
|
301
|
+
type: Boolean,
|
|
302
|
+
required: false,
|
|
303
|
+
default: void 0
|
|
304
|
+
},
|
|
305
|
+
loading: {
|
|
306
|
+
type: Boolean,
|
|
307
|
+
required: false,
|
|
308
|
+
default: void 0
|
|
309
|
+
},
|
|
310
|
+
open: {
|
|
311
|
+
type: Boolean,
|
|
312
|
+
required: false,
|
|
313
|
+
default: void 0
|
|
314
|
+
},
|
|
315
|
+
defaultOpen: {
|
|
316
|
+
type: Boolean,
|
|
317
|
+
required: false,
|
|
318
|
+
default: void 0
|
|
319
|
+
},
|
|
320
|
+
onPopupVisibleChange: {
|
|
321
|
+
type: Function,
|
|
322
|
+
required: false,
|
|
323
|
+
default: void 0
|
|
324
|
+
},
|
|
325
|
+
getInputElement: {
|
|
326
|
+
type: Function,
|
|
327
|
+
required: false,
|
|
328
|
+
default: void 0
|
|
329
|
+
},
|
|
330
|
+
getRawInputElement: {
|
|
331
|
+
type: Function,
|
|
332
|
+
required: false,
|
|
333
|
+
default: void 0
|
|
334
|
+
},
|
|
335
|
+
maxTagTextLength: {
|
|
336
|
+
type: Number,
|
|
337
|
+
required: false,
|
|
338
|
+
default: void 0
|
|
339
|
+
},
|
|
340
|
+
maxTagCount: {
|
|
341
|
+
type: [Number, String],
|
|
342
|
+
required: false,
|
|
343
|
+
default: void 0
|
|
344
|
+
},
|
|
345
|
+
maxTagPlaceholder: {
|
|
346
|
+
type: [
|
|
347
|
+
Object,
|
|
348
|
+
Function,
|
|
349
|
+
String,
|
|
350
|
+
Number,
|
|
351
|
+
null,
|
|
352
|
+
Boolean,
|
|
353
|
+
Array
|
|
354
|
+
],
|
|
355
|
+
required: false,
|
|
356
|
+
default: void 0
|
|
357
|
+
},
|
|
358
|
+
tokenSeparators: {
|
|
359
|
+
type: Array,
|
|
360
|
+
required: false,
|
|
361
|
+
default: void 0
|
|
362
|
+
},
|
|
363
|
+
allowClear: {
|
|
364
|
+
type: [Boolean, Object],
|
|
365
|
+
required: false,
|
|
366
|
+
default: void 0
|
|
367
|
+
},
|
|
368
|
+
prefix: {
|
|
369
|
+
type: [
|
|
370
|
+
Object,
|
|
371
|
+
Function,
|
|
372
|
+
String,
|
|
373
|
+
Number,
|
|
374
|
+
null,
|
|
375
|
+
Boolean,
|
|
376
|
+
Array
|
|
377
|
+
],
|
|
378
|
+
required: false,
|
|
379
|
+
default: void 0
|
|
380
|
+
},
|
|
381
|
+
suffixIcon: {
|
|
382
|
+
type: [
|
|
383
|
+
Object,
|
|
384
|
+
Function,
|
|
385
|
+
String,
|
|
386
|
+
Number,
|
|
387
|
+
null,
|
|
388
|
+
Boolean,
|
|
389
|
+
Array
|
|
390
|
+
],
|
|
391
|
+
required: false,
|
|
392
|
+
default: void 0
|
|
393
|
+
},
|
|
394
|
+
suffix: {
|
|
395
|
+
type: [
|
|
396
|
+
Object,
|
|
397
|
+
Function,
|
|
398
|
+
String,
|
|
399
|
+
Number,
|
|
400
|
+
null,
|
|
401
|
+
Boolean,
|
|
402
|
+
Array
|
|
403
|
+
],
|
|
404
|
+
required: false,
|
|
405
|
+
default: void 0
|
|
406
|
+
},
|
|
407
|
+
clearIcon: {
|
|
408
|
+
type: [
|
|
409
|
+
Object,
|
|
410
|
+
Function,
|
|
411
|
+
String,
|
|
412
|
+
Number,
|
|
413
|
+
null,
|
|
414
|
+
Boolean,
|
|
415
|
+
Array
|
|
416
|
+
],
|
|
417
|
+
required: false,
|
|
418
|
+
default: void 0
|
|
419
|
+
},
|
|
420
|
+
removeIcon: {
|
|
421
|
+
type: [
|
|
422
|
+
Object,
|
|
423
|
+
Function,
|
|
424
|
+
String,
|
|
425
|
+
Number,
|
|
426
|
+
null,
|
|
427
|
+
Boolean,
|
|
428
|
+
Array
|
|
429
|
+
],
|
|
430
|
+
required: false,
|
|
431
|
+
default: void 0
|
|
432
|
+
},
|
|
433
|
+
animation: {
|
|
434
|
+
type: String,
|
|
435
|
+
required: false,
|
|
436
|
+
default: void 0
|
|
437
|
+
},
|
|
438
|
+
transitionName: {
|
|
439
|
+
type: String,
|
|
440
|
+
required: false,
|
|
441
|
+
default: void 0
|
|
442
|
+
},
|
|
443
|
+
popupStyle: {
|
|
444
|
+
type: Object,
|
|
445
|
+
required: false,
|
|
446
|
+
default: void 0
|
|
447
|
+
},
|
|
448
|
+
popupClassName: {
|
|
449
|
+
type: String,
|
|
450
|
+
required: false,
|
|
451
|
+
default: void 0
|
|
452
|
+
},
|
|
453
|
+
popupMatchSelectWidth: {
|
|
454
|
+
type: [Boolean, Number],
|
|
455
|
+
required: false,
|
|
456
|
+
default: void 0
|
|
457
|
+
},
|
|
458
|
+
popupRender: {
|
|
459
|
+
type: Function,
|
|
460
|
+
required: false,
|
|
461
|
+
default: void 0
|
|
462
|
+
},
|
|
463
|
+
popupAlign: {
|
|
464
|
+
type: Object,
|
|
465
|
+
required: false,
|
|
466
|
+
default: void 0
|
|
467
|
+
},
|
|
468
|
+
placement: {
|
|
469
|
+
type: String,
|
|
470
|
+
required: false,
|
|
471
|
+
default: void 0
|
|
472
|
+
},
|
|
473
|
+
builtinPlacements: {
|
|
474
|
+
type: Object,
|
|
475
|
+
required: false,
|
|
476
|
+
default: void 0
|
|
477
|
+
},
|
|
478
|
+
getPopupContainer: {
|
|
479
|
+
type: Function,
|
|
480
|
+
required: false,
|
|
481
|
+
default: void 0
|
|
482
|
+
},
|
|
483
|
+
showAction: {
|
|
484
|
+
type: Array,
|
|
485
|
+
required: false,
|
|
486
|
+
default: void 0
|
|
487
|
+
},
|
|
488
|
+
onBlur: {
|
|
489
|
+
type: Function,
|
|
490
|
+
required: false,
|
|
491
|
+
default: void 0
|
|
492
|
+
},
|
|
493
|
+
onFocus: {
|
|
494
|
+
type: Function,
|
|
495
|
+
required: false,
|
|
496
|
+
default: void 0
|
|
497
|
+
},
|
|
498
|
+
onKeyUp: {
|
|
499
|
+
type: Function,
|
|
500
|
+
required: false,
|
|
501
|
+
default: void 0
|
|
502
|
+
},
|
|
503
|
+
onKeyDown: {
|
|
504
|
+
type: Function,
|
|
505
|
+
required: false,
|
|
506
|
+
default: void 0
|
|
507
|
+
},
|
|
508
|
+
onMouseDown: {
|
|
509
|
+
type: Function,
|
|
510
|
+
required: false,
|
|
511
|
+
default: void 0
|
|
512
|
+
},
|
|
513
|
+
onPopupScroll: {
|
|
514
|
+
type: Function,
|
|
515
|
+
required: false,
|
|
516
|
+
default: void 0
|
|
517
|
+
},
|
|
518
|
+
onInputKeyDown: {
|
|
519
|
+
type: Function,
|
|
520
|
+
required: false,
|
|
521
|
+
default: void 0
|
|
522
|
+
},
|
|
523
|
+
onMouseEnter: {
|
|
524
|
+
type: Function,
|
|
525
|
+
required: false,
|
|
526
|
+
default: void 0
|
|
527
|
+
},
|
|
528
|
+
onMouseLeave: {
|
|
529
|
+
type: Function,
|
|
530
|
+
required: false,
|
|
531
|
+
default: void 0
|
|
532
|
+
},
|
|
533
|
+
onClick: {
|
|
534
|
+
type: Function,
|
|
535
|
+
required: false,
|
|
536
|
+
default: void 0
|
|
537
|
+
},
|
|
538
|
+
components: {
|
|
539
|
+
type: Object,
|
|
540
|
+
required: false,
|
|
541
|
+
default: void 0
|
|
542
|
+
}
|
|
543
|
+
}, {
|
|
544
|
+
prefixCls: "vc-select",
|
|
545
|
+
popupMatchSelectWidth: true,
|
|
546
|
+
listHeight: 200,
|
|
547
|
+
listItemHeight: 20
|
|
548
|
+
}),
|
|
549
|
+
name: "VcSelect",
|
|
550
|
+
inheritAttrs: false,
|
|
551
|
+
setup(props, { attrs, expose, slots }) {
|
|
552
|
+
const baseSelectRef = shallowRef(null);
|
|
553
|
+
expose({
|
|
554
|
+
focus: () => baseSelectRef.value?.focus(),
|
|
555
|
+
blur: () => baseSelectRef.value?.blur(),
|
|
556
|
+
scrollTo: (arg) => baseSelectRef.value?.scrollTo?.(arg)
|
|
557
|
+
});
|
|
558
|
+
const mergedId = useId(props.id);
|
|
559
|
+
const multiple = computed(() => isMultiple(props.mode));
|
|
560
|
+
const [mergedShowSearch, searchConfig] = useSearchConfig(toRef(props, "showSearch"), {
|
|
561
|
+
filterOption: toRef(props, "filterOption"),
|
|
562
|
+
searchValue: toRef(props, "searchValue"),
|
|
563
|
+
optionFilterProp: toRef(props, "optionFilterProp"),
|
|
564
|
+
filterSort: toRef(props, "filterSort"),
|
|
565
|
+
onSearch: toRef(props, "onSearch"),
|
|
566
|
+
autoClearSearchValue: toRef(props, "autoClearSearchValue")
|
|
567
|
+
}, toRef(props, "mode"));
|
|
568
|
+
const mergedFilterOption = computed(() => {
|
|
569
|
+
if (searchConfig.value.filterOption === void 0 && props.mode === "combobox") return false;
|
|
570
|
+
return searchConfig.value.filterOption;
|
|
571
|
+
});
|
|
572
|
+
const mergedFieldNames = computed(() => fillFieldNames(props.fieldNames, false));
|
|
573
|
+
const internalSearchValue = shallowRef(props.searchValue || "");
|
|
574
|
+
watch(() => props.searchValue, (val) => {
|
|
575
|
+
if (val !== void 0) internalSearchValue.value = val;
|
|
576
|
+
});
|
|
577
|
+
const setSearchValue = (val) => {
|
|
578
|
+
internalSearchValue.value = val;
|
|
579
|
+
};
|
|
580
|
+
const mergedSearchValue = computed(() => internalSearchValue.value || "");
|
|
581
|
+
const childrenOptionsRef = shallowRef([]);
|
|
582
|
+
const parsedOptions = useOptions(toRef(props, "options"), childrenOptionsRef, mergedFieldNames, toRef(props, "optionFilterProp"), toRef(props, "optionLabelProp"));
|
|
583
|
+
const valueOptions = computed(() => parsedOptions.value.valueOptions);
|
|
584
|
+
const labelOptions = computed(() => parsedOptions.value.labelOptions);
|
|
585
|
+
const mergedOptions = computed(() => parsedOptions.value.options);
|
|
586
|
+
const convert2LabelValues = (draftValues) => {
|
|
587
|
+
return toArray(draftValues).map((val) => {
|
|
588
|
+
let rawValue;
|
|
589
|
+
let rawLabel;
|
|
590
|
+
let rawDisabled;
|
|
591
|
+
let rawTitle;
|
|
592
|
+
if (isRawValue(val)) rawValue = val;
|
|
593
|
+
else {
|
|
594
|
+
rawLabel = val.label;
|
|
595
|
+
rawValue = val.value;
|
|
596
|
+
}
|
|
597
|
+
const option = valueOptions.value.get(rawValue);
|
|
598
|
+
if (option) {
|
|
599
|
+
if (rawLabel === void 0) rawLabel = option?.[props.optionLabelProp || mergedFieldNames.value.label];
|
|
600
|
+
rawDisabled = option?.disabled;
|
|
601
|
+
rawTitle = option?.title;
|
|
602
|
+
}
|
|
603
|
+
return {
|
|
604
|
+
label: rawLabel,
|
|
605
|
+
value: rawValue,
|
|
606
|
+
key: rawValue,
|
|
607
|
+
disabled: rawDisabled,
|
|
608
|
+
title: rawTitle
|
|
609
|
+
};
|
|
610
|
+
});
|
|
611
|
+
};
|
|
612
|
+
const internalValue = shallowRef(props.defaultValue);
|
|
613
|
+
watch(() => props.value, (val) => {
|
|
614
|
+
if (val !== void 0) internalValue.value = val;
|
|
615
|
+
}, { immediate: true });
|
|
616
|
+
const setInternalValue = (val) => {
|
|
617
|
+
if (props.value === void 0) internalValue.value = val;
|
|
618
|
+
};
|
|
619
|
+
const [mergedValues, getMixedOption] = useCache(computed(() => {
|
|
620
|
+
const values = convert2LabelValues(multiple.value && internalValue.value === null ? [] : internalValue.value);
|
|
621
|
+
if (props.mode === "combobox" && isComboNoValue(values[0]?.value)) return [];
|
|
622
|
+
return values;
|
|
623
|
+
}), valueOptions);
|
|
624
|
+
const displayValues = computed(() => {
|
|
625
|
+
if (!props.mode && mergedValues.value.length === 1) {
|
|
626
|
+
const firstValue = mergedValues.value[0];
|
|
627
|
+
if (firstValue.value === null && (firstValue.label === null || firstValue.label === void 0)) return [];
|
|
628
|
+
}
|
|
629
|
+
return mergedValues.value.map((item) => ({
|
|
630
|
+
...item,
|
|
631
|
+
label: (typeof props.labelRender === "function" ? props.labelRender(item) : item.label) ?? item.value
|
|
632
|
+
}));
|
|
633
|
+
});
|
|
634
|
+
const rawValues = computed(() => new Set(mergedValues.value.map((val) => val.value)));
|
|
635
|
+
watch(mergedValues, () => {
|
|
636
|
+
if (props.mode === "combobox") {
|
|
637
|
+
const strValue = mergedValues.value[0]?.value;
|
|
638
|
+
setSearchValue(hasValue(strValue) ? String(strValue) : "");
|
|
639
|
+
}
|
|
640
|
+
});
|
|
641
|
+
const createTagOption = useRefFunc((val, label) => {
|
|
642
|
+
const mergedLabel = label ?? val;
|
|
643
|
+
return {
|
|
644
|
+
[mergedFieldNames.value.value]: val,
|
|
645
|
+
[mergedFieldNames.value.label]: mergedLabel
|
|
646
|
+
};
|
|
647
|
+
});
|
|
648
|
+
const filteredOptions = useFilterOptions(computed(() => {
|
|
649
|
+
if (props.mode !== "tags") return mergedOptions.value;
|
|
650
|
+
const cloneOptions = [...mergedOptions.value];
|
|
651
|
+
const existOptions = (val) => valueOptions.value.has(val);
|
|
652
|
+
[...mergedValues.value].sort((a, b) => a.value < b.value ? -1 : 1).forEach((item) => {
|
|
653
|
+
const val = item.value;
|
|
654
|
+
if (!existOptions(val)) cloneOptions.push(createTagOption(val, item.label));
|
|
655
|
+
});
|
|
656
|
+
return cloneOptions;
|
|
657
|
+
}), mergedFieldNames, mergedSearchValue, mergedFilterOption, toRef(props, "optionFilterProp"));
|
|
658
|
+
const filledSearchOptions = computed(() => {
|
|
659
|
+
if (props.mode !== "tags" || !mergedSearchValue.value || filteredOptions.value.some((item) => item[props.optionFilterProp || "value"] === mergedSearchValue.value)) return filteredOptions.value;
|
|
660
|
+
if (filteredOptions.value.some((item) => item[mergedFieldNames.value.value] === mergedSearchValue.value)) return filteredOptions.value;
|
|
661
|
+
return [createTagOption(mergedSearchValue.value), ...filteredOptions.value];
|
|
662
|
+
});
|
|
663
|
+
const sorter = (inputOptions) => {
|
|
664
|
+
return [...inputOptions].sort((a, b) => searchConfig.value.filterSort(a, b, { searchValue: mergedSearchValue.value })).map((item) => {
|
|
665
|
+
if (Array.isArray(item.options)) return {
|
|
666
|
+
...item,
|
|
667
|
+
options: item.options.length > 0 ? sorter(item.options) : item.options
|
|
668
|
+
};
|
|
669
|
+
return item;
|
|
670
|
+
});
|
|
671
|
+
};
|
|
672
|
+
const orderedFilteredOptions = computed(() => {
|
|
673
|
+
if (!searchConfig.value.filterSort) return filledSearchOptions.value;
|
|
674
|
+
return sorter(filledSearchOptions.value);
|
|
675
|
+
});
|
|
676
|
+
const displayOptions = computed(() => flattenOptions(orderedFilteredOptions.value, {
|
|
677
|
+
fieldNames: mergedFieldNames.value,
|
|
678
|
+
childrenAsData: false
|
|
679
|
+
}));
|
|
680
|
+
const triggerChange = (values) => {
|
|
681
|
+
const labeledValues = convert2LabelValues(values);
|
|
682
|
+
setInternalValue(labeledValues);
|
|
683
|
+
if (props.onChange && (labeledValues.length !== mergedValues.value.length || labeledValues.some((newVal, index) => mergedValues.value[index]?.value !== newVal?.value))) {
|
|
684
|
+
const returnValues = props.labelInValue ? labeledValues.map(({ label: l, value: v }) => ({
|
|
685
|
+
label: l,
|
|
686
|
+
value: v
|
|
687
|
+
})) : labeledValues.map((v) => v.value);
|
|
688
|
+
const returnOptions = labeledValues.map((v) => injectPropsWithOption(getMixedOption(v.value)));
|
|
689
|
+
props.onChange(multiple.value ? returnValues : returnValues[0], multiple.value ? returnOptions : returnOptions[0]);
|
|
690
|
+
}
|
|
691
|
+
};
|
|
692
|
+
const activeValue = shallowRef(null);
|
|
693
|
+
const accessibilityIndex = shallowRef(0);
|
|
694
|
+
const mergedDefaultActiveFirstOption = computed(() => props.defaultActiveFirstOption !== void 0 ? props.defaultActiveFirstOption : props.mode !== "combobox");
|
|
695
|
+
const onActiveValue = (active, index, { source = "keyboard" } = {}) => {
|
|
696
|
+
accessibilityIndex.value = index;
|
|
697
|
+
if (props.backfill && props.mode === "combobox" && active !== null && source === "keyboard") activeValue.value = String(active);
|
|
698
|
+
props.onActive?.(active);
|
|
699
|
+
};
|
|
700
|
+
const triggerSelect = (val, selected, type) => {
|
|
701
|
+
const getSelectEnt = () => {
|
|
702
|
+
const option = getMixedOption(val);
|
|
703
|
+
return [props.labelInValue ? {
|
|
704
|
+
label: option?.[mergedFieldNames.value.label],
|
|
705
|
+
value: val
|
|
706
|
+
} : val, injectPropsWithOption(option)];
|
|
707
|
+
};
|
|
708
|
+
if (selected && props.onSelect) {
|
|
709
|
+
const [wrappedValue, option] = getSelectEnt();
|
|
710
|
+
props.onSelect(wrappedValue, option);
|
|
711
|
+
} else if (!selected && props.onDeselect && type !== "clear") {
|
|
712
|
+
const [wrappedValue, option] = getSelectEnt();
|
|
713
|
+
props.onDeselect(wrappedValue, option);
|
|
714
|
+
}
|
|
715
|
+
};
|
|
716
|
+
const onInternalSelect = useRefFunc((val, info) => {
|
|
717
|
+
let cloneValues;
|
|
718
|
+
const mergedSelect = multiple.value ? info.selected : true;
|
|
719
|
+
if (mergedSelect) cloneValues = multiple.value ? [...mergedValues.value, val] : [val];
|
|
720
|
+
else cloneValues = mergedValues.value.filter((v) => v.value !== val);
|
|
721
|
+
triggerChange(cloneValues);
|
|
722
|
+
triggerSelect(val, mergedSelect);
|
|
723
|
+
if (props.mode === "combobox") activeValue.value = "";
|
|
724
|
+
else if (!multiple.value || searchConfig.value.autoClearSearchValue) {
|
|
725
|
+
setSearchValue("");
|
|
726
|
+
activeValue.value = "";
|
|
727
|
+
}
|
|
728
|
+
});
|
|
729
|
+
const onDisplayValuesChange = (nextValues, info) => {
|
|
730
|
+
triggerChange(nextValues);
|
|
731
|
+
const { type, values } = info;
|
|
732
|
+
if (type === "remove" || type === "clear") values.forEach((item) => {
|
|
733
|
+
triggerSelect(item.value, false, type);
|
|
734
|
+
});
|
|
735
|
+
};
|
|
736
|
+
const onInternalSearch = (searchText, info) => {
|
|
737
|
+
setSearchValue(searchText);
|
|
738
|
+
activeValue.value = null;
|
|
739
|
+
if (info.source === "submit") {
|
|
740
|
+
const formatted = (searchText || "").trim();
|
|
741
|
+
if (formatted) {
|
|
742
|
+
triggerChange(Array.from(new Set([...rawValues.value, formatted])));
|
|
743
|
+
triggerSelect(formatted, true);
|
|
744
|
+
setSearchValue("");
|
|
745
|
+
}
|
|
746
|
+
return;
|
|
747
|
+
}
|
|
748
|
+
if (info.source !== "blur") {
|
|
749
|
+
if (props.mode === "combobox") triggerChange(searchText);
|
|
750
|
+
searchConfig.value.onSearch?.(searchText);
|
|
751
|
+
}
|
|
752
|
+
};
|
|
753
|
+
const onInternalSearchSplit = (words) => {
|
|
754
|
+
let patchValues = words;
|
|
755
|
+
if (props.mode !== "tags") patchValues = words.map((word) => {
|
|
756
|
+
return labelOptions.value.get(word)?.[mergedFieldNames.value.value];
|
|
757
|
+
}).filter((val) => val !== void 0);
|
|
758
|
+
const newRawValues = Array.from(new Set([...rawValues.value, ...patchValues]));
|
|
759
|
+
triggerChange(newRawValues);
|
|
760
|
+
newRawValues.forEach((newRawValue) => {
|
|
761
|
+
triggerSelect(newRawValue, true);
|
|
762
|
+
});
|
|
763
|
+
};
|
|
764
|
+
useSelectProvider(computed(() => {
|
|
765
|
+
const realVirtual = props.virtual !== false && props.popupMatchSelectWidth !== false;
|
|
766
|
+
return {
|
|
767
|
+
...parsedOptions.value,
|
|
768
|
+
flattenOptions: displayOptions.value,
|
|
769
|
+
onActiveValue,
|
|
770
|
+
defaultActiveFirstOption: mergedDefaultActiveFirstOption.value,
|
|
771
|
+
onSelect: onInternalSelect,
|
|
772
|
+
menuItemSelectedIcon: props.menuItemSelectedIcon,
|
|
773
|
+
rawValues: rawValues.value,
|
|
774
|
+
fieldNames: mergedFieldNames.value,
|
|
775
|
+
virtual: realVirtual,
|
|
776
|
+
direction: props.direction,
|
|
777
|
+
listHeight: props.listHeight,
|
|
778
|
+
listItemHeight: props.listItemHeight,
|
|
779
|
+
childrenAsData: false,
|
|
780
|
+
maxCount: props.maxCount,
|
|
781
|
+
optionRender: props.optionRender,
|
|
782
|
+
classNames: props.classNames,
|
|
783
|
+
styles: props.styles
|
|
784
|
+
};
|
|
785
|
+
}));
|
|
786
|
+
let lastChildrenKey = "";
|
|
787
|
+
return () => {
|
|
788
|
+
if (!props.options || props.options.length === 0) {
|
|
789
|
+
const newChildrenOptions = convertChildrenToData(filterEmpty(slots?.default?.() ?? []));
|
|
790
|
+
const newKey = newChildrenOptions.map((o) => `${o.value}`).join(",");
|
|
791
|
+
if (lastChildrenKey !== newKey) {
|
|
792
|
+
lastChildrenKey = newKey;
|
|
793
|
+
childrenOptionsRef.value = newChildrenOptions;
|
|
794
|
+
}
|
|
795
|
+
}
|
|
796
|
+
const restAttrs = { ...attrs };
|
|
797
|
+
const restProps = omit(props, omitKeyList);
|
|
798
|
+
const { prefixCls, mode, classNames, styles, maxCount, placeholder, direction, popupMatchSelectWidth } = props;
|
|
799
|
+
return createVNode(BaseSelect, mergeProps(restAttrs, restProps, {
|
|
800
|
+
"placeholder": placeholder,
|
|
801
|
+
"id": mergedId,
|
|
802
|
+
"prefixCls": prefixCls,
|
|
803
|
+
"ref": (el) => {
|
|
804
|
+
baseSelectRef.value = el;
|
|
805
|
+
},
|
|
806
|
+
"omitDomProps": OMIT_DOM_PROPS,
|
|
807
|
+
"mode": mode,
|
|
808
|
+
"classNames": classNames,
|
|
809
|
+
"styles": styles,
|
|
810
|
+
"displayValues": displayValues.value,
|
|
811
|
+
"onDisplayValuesChange": onDisplayValuesChange,
|
|
812
|
+
"maxCount": maxCount,
|
|
813
|
+
"direction": direction,
|
|
814
|
+
"showSearch": mergedShowSearch.value,
|
|
815
|
+
"searchValue": mergedSearchValue.value,
|
|
816
|
+
"onSearch": onInternalSearch,
|
|
817
|
+
"autoClearSearchValue": searchConfig.value.autoClearSearchValue,
|
|
818
|
+
"onSearchSplit": onInternalSearchSplit,
|
|
819
|
+
"popupMatchSelectWidth": popupMatchSelectWidth,
|
|
820
|
+
"OptionList": OptionList_default,
|
|
821
|
+
"emptyOptions": !displayOptions.value.length,
|
|
822
|
+
"activeValue": activeValue.value || void 0,
|
|
823
|
+
"activeDescendantId": `${mergedId}_list_${accessibilityIndex.value}`
|
|
824
|
+
}), null);
|
|
825
|
+
};
|
|
826
|
+
}
|
|
827
|
+
});
|
|
828
|
+
export { Select_default as default };
|