vue3-extended-multiselect 0.1.2 → 0.1.4
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/.eslintrc.js +29 -29
- package/.github/workflows/publish.yml +41 -0
- package/.nvmrc +0 -0
- package/CHANGELOG.md +51 -43
- package/LICENSE +21 -21
- package/README.md +116 -116
- package/index.js +2 -2
- package/jest.config.js +57 -57
- package/package.json +46 -46
- package/src/assets/base-arrow.svg +70 -70
- package/src/assets/cancel.svg +34 -34
- package/src/assets/circle-arrow.svg +7 -7
- package/src/assets/double-arrow.svg +39 -39
- package/src/assets/inner-arrow.svg +8 -8
- package/src/assets/loader.svg +5 -5
- package/src/assets/triangle-arrow.svg +72 -72
- package/src/assets/triangle-circle-arrow.svg +38 -38
- package/src/assets/wide-arrow.svg +72 -72
- package/src/components/ExtendedMultiselectCancel.vue +142 -142
- package/src/components/ExtendedMultiselectInput.vue +618 -618
- package/src/components/ExtendedMultiselectLoader.vue +176 -176
- package/src/components/ExtendedMultiselectMultiple.vue +291 -291
- package/src/components/ExtendedMultiselectOptions.vue +1087 -1087
- package/src/components/ExtendedMultiselectToggle.vue +254 -254
- package/src/components/Vue3ExtendedMultiselect.vue +1651 -1651
- package/src/composition/cancel.js +30 -30
- package/src/composition/labels.js +39 -39
- package/src/composition/preselected-options.js +66 -66
- package/src/composition/search-value.js +33 -33
- package/src/composition/sizes.js +42 -42
- package/src/composition/toggle.js +33 -33
- package/src/sets/sets.js +99 -99
- package/src/styles/animations.css +19 -19
- package/src/styles/main.css +433 -433
- package/src/styles/variables.css +41 -41
- package/tests/unit/events.spec.js +135 -135
- package/tests/unit/props.spec.js +1040 -1040
- package/tests/utils/mount.js +37 -37
- package/tests/utils/utils.js +20 -20
- package/typings/vue3-extended-multiselect.d.ts +42 -33
|
@@ -1,1651 +1,1651 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<section
|
|
3
|
-
aria-owns="extended-search-field"
|
|
4
|
-
ref="extendedMultiselectWrapper"
|
|
5
|
-
role="combobox"
|
|
6
|
-
:aria-roledescription="roledescription"
|
|
7
|
-
:class="wrapperClasses"
|
|
8
|
-
:tabindex="tabindexIfSearch"
|
|
9
|
-
@click.stop.left="fieldFocus"
|
|
10
|
-
@click.stop.middle="fieldFocus"
|
|
11
|
-
@keyup.stop.esc="rollUp"
|
|
12
|
-
@keyup.stop.enter="selectByEnter"
|
|
13
|
-
@mousedown.stop.left="toggleRestrictor"
|
|
14
|
-
@mousedown.stop.middle="toggleRestrictor"
|
|
15
|
-
@mouseleave.stop="resetEnterIndex"
|
|
16
|
-
>
|
|
17
|
-
<div
|
|
18
|
-
id="extended__multiselect"
|
|
19
|
-
ref="extendedMultiselect"
|
|
20
|
-
:class="classes"
|
|
21
|
-
:style="[displayWrongValue, expanded]"
|
|
22
|
-
>
|
|
23
|
-
<div>
|
|
24
|
-
<extended-multiselect-input
|
|
25
|
-
:accesskey="attrs.accesskey"
|
|
26
|
-
:autocomplete="attrs.autocomplete"
|
|
27
|
-
:name="attrs.name"
|
|
28
|
-
:spellcheck="attrs.spellcheck"
|
|
29
|
-
:tabindex="attrs.tabindex"
|
|
30
|
-
:translate="attrs.translate"
|
|
31
|
-
:create-on-the-go="createOnTheGo"
|
|
32
|
-
:disabled="inputDisabled"
|
|
33
|
-
:dropdown-active="dropdownActive"
|
|
34
|
-
:loading="internalLoading"
|
|
35
|
-
:multiple="multiple"
|
|
36
|
-
:search-filter-active="searchFilterActive"
|
|
37
|
-
:toggling-saves-search-value="togglingSavesSearchValue"
|
|
38
|
-
:toggle-options-by-select="toggleOptionsBySelect"
|
|
39
|
-
:placeholder="placeholder"
|
|
40
|
-
:show-search-field="showSearchField"
|
|
41
|
-
:empty-objects-placeholder="emptyObjectsPlaceholder"
|
|
42
|
-
:multiple-blocks-limit-message="multipleBlocksLimitMessage"
|
|
43
|
-
:theme-type="themeType"
|
|
44
|
-
:increase-display-by="increaseDisplayBy"
|
|
45
|
-
:multipleBlocksLimit="multipleBlocksLimit"
|
|
46
|
-
:restricted-options-length="restrictedOptionsLength"
|
|
47
|
-
:toggle-multiple-blocks-limit="toggleMultipleBlocksLimit"
|
|
48
|
-
:selected-options="selectedOptions"
|
|
49
|
-
:create-custom-option-label="createCustomOptionLabel"
|
|
50
|
-
:create-option-placeholder="createOptionPlaceholder"
|
|
51
|
-
:input-id="inputId"
|
|
52
|
-
>
|
|
53
|
-
<template
|
|
54
|
-
v-if="!showSearchField"
|
|
55
|
-
#labelBlock="{ labelBlockValue }"
|
|
56
|
-
>
|
|
57
|
-
<slot
|
|
58
|
-
name="labelBlock"
|
|
59
|
-
:label="labelBlockValue"
|
|
60
|
-
>
|
|
61
|
-
</slot>
|
|
62
|
-
</template>
|
|
63
|
-
<template #optionBlock="{ label, deselectBlock, index }">
|
|
64
|
-
<slot
|
|
65
|
-
name="optionBlock"
|
|
66
|
-
:label="label"
|
|
67
|
-
:index="index"
|
|
68
|
-
:deselect-block="deselectBlock"
|
|
69
|
-
>
|
|
70
|
-
</slot>
|
|
71
|
-
</template>
|
|
72
|
-
<template
|
|
73
|
-
#maxElements
|
|
74
|
-
>
|
|
75
|
-
<slot name="maxElements"></slot>
|
|
76
|
-
</template>
|
|
77
|
-
<template
|
|
78
|
-
v-if="toggleMultipleBlocksLimit"
|
|
79
|
-
#showMore="{ showMoreOptions }"
|
|
80
|
-
>
|
|
81
|
-
<slot
|
|
82
|
-
name="showMore"
|
|
83
|
-
:increase="showMoreOptions"
|
|
84
|
-
>
|
|
85
|
-
</slot>
|
|
86
|
-
</template>
|
|
87
|
-
</extended-multiselect-input>
|
|
88
|
-
</div>
|
|
89
|
-
<slot
|
|
90
|
-
name="toggle"
|
|
91
|
-
:toggle-options-list="toggleOptionsList"
|
|
92
|
-
>
|
|
93
|
-
<extended-multiselect-toggle
|
|
94
|
-
ref="extendedMultiselectToggle"
|
|
95
|
-
:tabindex="attrs.tabindex"
|
|
96
|
-
:disabled="inputDisabled"
|
|
97
|
-
:dropdown-active="dropdownActive"
|
|
98
|
-
:loading="internalLoading"
|
|
99
|
-
:icon-filter="iconFilter"
|
|
100
|
-
:icon-size="iconSize"
|
|
101
|
-
:toggle-icon="toggleIcon"
|
|
102
|
-
/>
|
|
103
|
-
</slot>
|
|
104
|
-
<slot
|
|
105
|
-
name="cancel"
|
|
106
|
-
:cancel="cancel"
|
|
107
|
-
>
|
|
108
|
-
<extended-multiselect-cancel
|
|
109
|
-
v-if="showClearIcon"
|
|
110
|
-
:tabindex="attrs.tabindex"
|
|
111
|
-
:disabled="inputDisabled"
|
|
112
|
-
:show-search-field="showSearchField"
|
|
113
|
-
:loading="internalLoading"
|
|
114
|
-
:icon-filter="iconFilter"
|
|
115
|
-
:icon-size="iconSize"
|
|
116
|
-
:selected-options="selectedOptions"
|
|
117
|
-
/>
|
|
118
|
-
</slot>
|
|
119
|
-
</div>
|
|
120
|
-
<transition
|
|
121
|
-
name="extended-toggle"
|
|
122
|
-
type="transition"
|
|
123
|
-
>
|
|
124
|
-
<extended-multiselect-options
|
|
125
|
-
v-if="dropdownActive"
|
|
126
|
-
:auto-select-created-option="autoSelectCreatedOption"
|
|
127
|
-
:clear-by-select-when-multiple="clearBySelectWhenMultiple"
|
|
128
|
-
:create-on-the-go="createOnTheGo"
|
|
129
|
-
:disabled-primitive-options-converted="disabledPrimitiveOptionsConverted"
|
|
130
|
-
:highlight-options="highlightOptions"
|
|
131
|
-
:multiple="multiple"
|
|
132
|
-
:selected-options-shown="selectedOptionsShown"
|
|
133
|
-
:show-insert-warnings="showInsertWarnings"
|
|
134
|
-
:show-marker="showMarker"
|
|
135
|
-
:chosen-toggle-appearance-side="chosenToggleAppearanceSide"
|
|
136
|
-
:create-option-type="createOptionType"
|
|
137
|
-
:empty-objects-placeholder="emptyObjectsPlaceholder"
|
|
138
|
-
:label="label"
|
|
139
|
-
:theme-type="themeType"
|
|
140
|
-
:any-option-wrapper-block-height="anyOptionWrapperBlockHeight"
|
|
141
|
-
:max-options-count="maxOptionsCount"
|
|
142
|
-
:min-options-count="minOptionsCount"
|
|
143
|
-
:options-padding="optionsPadding"
|
|
144
|
-
:toggle-max-height="toggleMaxHeight"
|
|
145
|
-
:toggle-min-height="toggleMinHeight"
|
|
146
|
-
:create-option-fields="createOptionFields"
|
|
147
|
-
:options="restrictedOptions"
|
|
148
|
-
:restricted-options="restrictedOptions"
|
|
149
|
-
:selected-options="selectedOptions"
|
|
150
|
-
:special-keys-block="specialKeysBlock"
|
|
151
|
-
:preselected-option="preselectedOption"
|
|
152
|
-
:preselected-options="preselectedOptions"
|
|
153
|
-
:create-custom-option-label="createCustomOptionLabel"
|
|
154
|
-
>
|
|
155
|
-
<template
|
|
156
|
-
v-if="slots.listHeader"
|
|
157
|
-
#listHeader
|
|
158
|
-
>
|
|
159
|
-
<slot name="listHeader"></slot>
|
|
160
|
-
</template>
|
|
161
|
-
<template
|
|
162
|
-
v-if="maxOptionsCount"
|
|
163
|
-
#moreThanLimit
|
|
164
|
-
>
|
|
165
|
-
<slot name="moreThanLimit"></slot>
|
|
166
|
-
</template>
|
|
167
|
-
<template
|
|
168
|
-
v-if="minOptionsCount"
|
|
169
|
-
#lessThanLimit
|
|
170
|
-
>
|
|
171
|
-
<slot name="lessThanLimit"></slot>
|
|
172
|
-
</template>
|
|
173
|
-
<template #option="{ option, createCustomOptionLabel }">
|
|
174
|
-
<slot
|
|
175
|
-
name="option"
|
|
176
|
-
:option="option"
|
|
177
|
-
:create-custom-option-label="createCustomOptionLabel"
|
|
178
|
-
>
|
|
179
|
-
</slot>
|
|
180
|
-
</template>
|
|
181
|
-
<template #marker>
|
|
182
|
-
<slot name="marker"></slot>
|
|
183
|
-
</template>
|
|
184
|
-
<template
|
|
185
|
-
v-if="noResultsBlockShown"
|
|
186
|
-
#noResults
|
|
187
|
-
>
|
|
188
|
-
<slot name="noResults"></slot>
|
|
189
|
-
</template>
|
|
190
|
-
<template #noOptions>
|
|
191
|
-
<slot name="noOptions"></slot>
|
|
192
|
-
</template>
|
|
193
|
-
<template
|
|
194
|
-
v-if="slots.listFooter"
|
|
195
|
-
#listFooter
|
|
196
|
-
>
|
|
197
|
-
<slot name="listFooter"></slot>
|
|
198
|
-
</template>
|
|
199
|
-
</extended-multiselect-options>
|
|
200
|
-
</transition>
|
|
201
|
-
</section>
|
|
202
|
-
</template>
|
|
203
|
-
|
|
204
|
-
<script setup>
|
|
205
|
-
import {
|
|
206
|
-
computed,
|
|
207
|
-
defineEmits,
|
|
208
|
-
defineProps,
|
|
209
|
-
onBeforeMount,
|
|
210
|
-
onMounted,
|
|
211
|
-
provide,
|
|
212
|
-
ref,
|
|
213
|
-
toRefs,
|
|
214
|
-
useAttrs,
|
|
215
|
-
useSlots,
|
|
216
|
-
watch,
|
|
217
|
-
} from "vue";
|
|
218
|
-
|
|
219
|
-
import clickOutside from "click-outside";
|
|
220
|
-
import emitter from "tiny-emitter/instance";
|
|
221
|
-
|
|
222
|
-
import {
|
|
223
|
-
themeTypes,
|
|
224
|
-
loaderThemeTypes,
|
|
225
|
-
toggleIcons,
|
|
226
|
-
iconFilters,
|
|
227
|
-
iconSizes,
|
|
228
|
-
createOptionTypes,
|
|
229
|
-
specialKeysToBlock,
|
|
230
|
-
toggleAppearenceSides,
|
|
231
|
-
UnionPropType,
|
|
232
|
-
} from "../sets/sets";
|
|
233
|
-
|
|
234
|
-
import useToggle from "../composition/toggle";
|
|
235
|
-
import useCancel from "../composition/cancel";
|
|
236
|
-
import usePreselectedOptions from "../composition/preselected-options";
|
|
237
|
-
import useSearchValue from "../composition/search-value";
|
|
238
|
-
|
|
239
|
-
import ExtendedMultiselectCancel from "./ExtendedMultiselectCancel.vue";
|
|
240
|
-
import ExtendedMultiselectInput from "./ExtendedMultiselectInput.vue";
|
|
241
|
-
import ExtendedMultiselectOptions from "./ExtendedMultiselectOptions.vue";
|
|
242
|
-
import ExtendedMultiselectToggle from "./ExtendedMultiselectToggle.vue";
|
|
243
|
-
|
|
244
|
-
/**
|
|
245
|
-
* @author Ridiger Daniil Dmitrievich
|
|
246
|
-
* @version 1.0.0
|
|
247
|
-
*/
|
|
248
|
-
|
|
249
|
-
const props = defineProps({
|
|
250
|
-
/**
|
|
251
|
-
* Determines whether to select just now created option
|
|
252
|
-
* automatically
|
|
253
|
-
* @default false
|
|
254
|
-
* @property {boolean} autoSelectCreatedOption
|
|
255
|
-
*/
|
|
256
|
-
autoSelectCreatedOption: {
|
|
257
|
-
type: Boolean,
|
|
258
|
-
default: false,
|
|
259
|
-
},
|
|
260
|
-
|
|
261
|
-
/**
|
|
262
|
-
* Determines whether to clear search field by option selection
|
|
263
|
-
* @default false
|
|
264
|
-
* @property {boolean} clearBySelectWhenMultiple
|
|
265
|
-
*/
|
|
266
|
-
clearBySelectWhenMultiple: {
|
|
267
|
-
type: Boolean,
|
|
268
|
-
default: false,
|
|
269
|
-
},
|
|
270
|
-
|
|
271
|
-
/**
|
|
272
|
-
* Allows user to create new options from search field
|
|
273
|
-
* @default false
|
|
274
|
-
* @property {boolean} createOnTheGo
|
|
275
|
-
*/
|
|
276
|
-
createOnTheGo: {
|
|
277
|
-
type: Boolean,
|
|
278
|
-
default: false,
|
|
279
|
-
},
|
|
280
|
-
|
|
281
|
-
/**
|
|
282
|
-
* Determines whether options list should be expanded by default
|
|
283
|
-
* @default false
|
|
284
|
-
* @property {boolean} defaultExpanded
|
|
285
|
-
*/
|
|
286
|
-
defaultExpanded: {
|
|
287
|
-
type: Boolean,
|
|
288
|
-
default: false,
|
|
289
|
-
},
|
|
290
|
-
|
|
291
|
-
/**
|
|
292
|
-
* Disables extended multiselect
|
|
293
|
-
* @default false
|
|
294
|
-
* @property {boolean} disabled
|
|
295
|
-
*/
|
|
296
|
-
disabled: {
|
|
297
|
-
type: Boolean,
|
|
298
|
-
default: false,
|
|
299
|
-
},
|
|
300
|
-
|
|
301
|
-
/**
|
|
302
|
-
* Switches options highlighting while hovering
|
|
303
|
-
* @default true
|
|
304
|
-
* @property {boolean} highlightOptions
|
|
305
|
-
*/
|
|
306
|
-
highlightOptions: {
|
|
307
|
-
type: Boolean,
|
|
308
|
-
default: true,
|
|
309
|
-
},
|
|
310
|
-
|
|
311
|
-
/**
|
|
312
|
-
* Switches loading state of extended multiselect
|
|
313
|
-
* @default false
|
|
314
|
-
* @property {boolean} loading
|
|
315
|
-
*/
|
|
316
|
-
loading: {
|
|
317
|
-
type: Boolean,
|
|
318
|
-
default: false,
|
|
319
|
-
},
|
|
320
|
-
|
|
321
|
-
/**
|
|
322
|
-
* Allows user to select multiple options
|
|
323
|
-
* @default false
|
|
324
|
-
* @property {boolean} multiple
|
|
325
|
-
*/
|
|
326
|
-
multiple: {
|
|
327
|
-
type: Boolean,
|
|
328
|
-
default: false,
|
|
329
|
-
},
|
|
330
|
-
|
|
331
|
-
/**
|
|
332
|
-
* Determines whether to show special hint if no options were found
|
|
333
|
-
* @default true
|
|
334
|
-
* @property {boolean} noResultsBlockShown
|
|
335
|
-
*/
|
|
336
|
-
noResultsBlockShown: {
|
|
337
|
-
type: Boolean,
|
|
338
|
-
default: true,
|
|
339
|
-
},
|
|
340
|
-
|
|
341
|
-
/**
|
|
342
|
-
* Determines whether to clear search field by selection/deselection of options
|
|
343
|
-
* @default true
|
|
344
|
-
* @property {boolean} resetSearchByValue
|
|
345
|
-
*/
|
|
346
|
-
resetSearchByValue: {
|
|
347
|
-
type: Boolean,
|
|
348
|
-
default: true,
|
|
349
|
-
},
|
|
350
|
-
|
|
351
|
-
/**
|
|
352
|
-
* Allows user to use internal search for options
|
|
353
|
-
* @default true
|
|
354
|
-
* @property {boolean} searchFilterActive
|
|
355
|
-
*/
|
|
356
|
-
searchFilterActive: {
|
|
357
|
-
type: Boolean,
|
|
358
|
-
default: true,
|
|
359
|
-
},
|
|
360
|
-
|
|
361
|
-
/**
|
|
362
|
-
* Switches full payload of extended multiselect events
|
|
363
|
-
* @default true
|
|
364
|
-
* @property {boolean} simpleEvents
|
|
365
|
-
*/
|
|
366
|
-
simpleEvents: {
|
|
367
|
-
type: Boolean,
|
|
368
|
-
default: true,
|
|
369
|
-
},
|
|
370
|
-
|
|
371
|
-
/**
|
|
372
|
-
* Determines whether to show selected options in options list
|
|
373
|
-
* @default false
|
|
374
|
-
* @property {boolean} selectedOptionsShown
|
|
375
|
-
*/
|
|
376
|
-
selectedOptionsShown: {
|
|
377
|
-
type: Boolean,
|
|
378
|
-
default: false,
|
|
379
|
-
},
|
|
380
|
-
|
|
381
|
-
/**
|
|
382
|
-
* Allows user to deselect all options by special icon
|
|
383
|
-
* @default false
|
|
384
|
-
* @property {boolean} showClearIcon
|
|
385
|
-
*/
|
|
386
|
-
showClearIcon: {
|
|
387
|
-
type: Boolean,
|
|
388
|
-
default: false,
|
|
389
|
-
},
|
|
390
|
-
|
|
391
|
-
/**
|
|
392
|
-
* Determines whether to show useful internal warnings in console
|
|
393
|
-
* @default false
|
|
394
|
-
* @property {boolean} showInsertWarnings
|
|
395
|
-
*/
|
|
396
|
-
showInsertWarnings: {
|
|
397
|
-
type: Boolean,
|
|
398
|
-
default: false,
|
|
399
|
-
},
|
|
400
|
-
|
|
401
|
-
/**
|
|
402
|
-
* Determines whether to show slot with special marker beside option in options list
|
|
403
|
-
* @default false
|
|
404
|
-
* @property {boolean} showMarker
|
|
405
|
-
*/
|
|
406
|
-
showMarker: {
|
|
407
|
-
type: Boolean,
|
|
408
|
-
default: false,
|
|
409
|
-
},
|
|
410
|
-
|
|
411
|
-
/**
|
|
412
|
-
* Determines whether to show search field which allows user
|
|
413
|
-
* to search for options with internal search
|
|
414
|
-
* @default true
|
|
415
|
-
* @property {boolean} showSearchField
|
|
416
|
-
*/
|
|
417
|
-
showSearchField: {
|
|
418
|
-
type: Boolean,
|
|
419
|
-
default: true,
|
|
420
|
-
},
|
|
421
|
-
|
|
422
|
-
/**
|
|
423
|
-
* Allows user to increase limit of shown elements with selected options
|
|
424
|
-
* by special icon
|
|
425
|
-
* @default false
|
|
426
|
-
* @property {boolean} toggleMultipleBlocksLimit
|
|
427
|
-
*/
|
|
428
|
-
toggleMultipleBlocksLimit: {
|
|
429
|
-
type: Boolean,
|
|
430
|
-
default: false,
|
|
431
|
-
},
|
|
432
|
-
|
|
433
|
-
/**
|
|
434
|
-
* Determines whether to roll up options list by selection of option
|
|
435
|
-
* @default true
|
|
436
|
-
* @property {boolean} toggleOptionsBySelect
|
|
437
|
-
*/
|
|
438
|
-
toggleOptionsBySelect: {
|
|
439
|
-
type: Boolean,
|
|
440
|
-
default: true,
|
|
441
|
-
},
|
|
442
|
-
|
|
443
|
-
/**
|
|
444
|
-
* Determines whether to save current search value if
|
|
445
|
-
* display of options list was toggled
|
|
446
|
-
* @default true
|
|
447
|
-
* @property {boolean} togglingSavesSearchValue
|
|
448
|
-
*/
|
|
449
|
-
togglingSavesSearchValue: {
|
|
450
|
-
type: Boolean,
|
|
451
|
-
default: true,
|
|
452
|
-
},
|
|
453
|
-
|
|
454
|
-
/**
|
|
455
|
-
* Determines whether to define special class for extended multiselect
|
|
456
|
-
* if value is wrong
|
|
457
|
-
* Irregularity of value is defined by user
|
|
458
|
-
* @default false
|
|
459
|
-
* @property {boolean} wrongCurrentValue
|
|
460
|
-
*/
|
|
461
|
-
wrongCurrentValue: {
|
|
462
|
-
type: Boolean,
|
|
463
|
-
default: false,
|
|
464
|
-
},
|
|
465
|
-
|
|
466
|
-
/**
|
|
467
|
-
* Placeholder for the search field to be used if
|
|
468
|
-
* user is allowed to create new options
|
|
469
|
-
* @default "Select or create features"
|
|
470
|
-
* @property {string} createOptionPlaceholder
|
|
471
|
-
*/
|
|
472
|
-
createOptionPlaceholder: {
|
|
473
|
-
type: String,
|
|
474
|
-
default: "Select or create features",
|
|
475
|
-
},
|
|
476
|
-
|
|
477
|
-
/**
|
|
478
|
-
* Defines kind for all options which will be created by user
|
|
479
|
-
* @default "primitive"
|
|
480
|
-
* @property {string} createOptionType
|
|
481
|
-
*/
|
|
482
|
-
createOptionType: {
|
|
483
|
-
type: String,
|
|
484
|
-
default: "primitive",
|
|
485
|
-
validator(value) {
|
|
486
|
-
return createOptionTypes.includes(value);
|
|
487
|
-
},
|
|
488
|
-
},
|
|
489
|
-
|
|
490
|
-
/**
|
|
491
|
-
* Placeholder for options of type "object"
|
|
492
|
-
* or Array instances which length/keys length equals 0
|
|
493
|
-
* @default "Empty Object/Array"
|
|
494
|
-
* @property {string} emptyObjectsPlaceholder
|
|
495
|
-
*/
|
|
496
|
-
emptyObjectsPlaceholder: {
|
|
497
|
-
type: String,
|
|
498
|
-
default: "Empty Object/Array",
|
|
499
|
-
validator(value) {
|
|
500
|
-
return !!value;
|
|
501
|
-
},
|
|
502
|
-
},
|
|
503
|
-
|
|
504
|
-
/**
|
|
505
|
-
* Defines "border-color" css-property for extended multiselect with wrong value
|
|
506
|
-
* @default "#FF0000"
|
|
507
|
-
* @property {string} errorBorderColor
|
|
508
|
-
*/
|
|
509
|
-
errorBorderColor: {
|
|
510
|
-
type: String,
|
|
511
|
-
default: "#FF0000",
|
|
512
|
-
},
|
|
513
|
-
|
|
514
|
-
/**
|
|
515
|
-
* Defines svg-filter with color settings for all icons except loader
|
|
516
|
-
* @default "basic"
|
|
517
|
-
* @property {string} iconFilter
|
|
518
|
-
*/
|
|
519
|
-
iconFilter: {
|
|
520
|
-
type: String,
|
|
521
|
-
default: "basic",
|
|
522
|
-
validator(value) {
|
|
523
|
-
return iconFilters.includes(value);
|
|
524
|
-
},
|
|
525
|
-
},
|
|
526
|
-
|
|
527
|
-
/**
|
|
528
|
-
* Defines sizes for all icons in pixels except loader
|
|
529
|
-
* @default "large"
|
|
530
|
-
* @property {string} iconSize
|
|
531
|
-
*/
|
|
532
|
-
iconSize: {
|
|
533
|
-
type: String,
|
|
534
|
-
default: "large",
|
|
535
|
-
validator(value) {
|
|
536
|
-
return iconSizes.includes(value);
|
|
537
|
-
},
|
|
538
|
-
},
|
|
539
|
-
|
|
540
|
-
/**
|
|
541
|
-
* Defines field in options of type "object" that will be the label of option
|
|
542
|
-
* @default "label"
|
|
543
|
-
* @property {string} label
|
|
544
|
-
*/
|
|
545
|
-
label: {
|
|
546
|
-
type: String,
|
|
547
|
-
default: "label",
|
|
548
|
-
},
|
|
549
|
-
|
|
550
|
-
/**
|
|
551
|
-
* Defines svg-filter with color settings for loader icon
|
|
552
|
-
* @default "loader-default"
|
|
553
|
-
* @property {string} loaderIconFilter
|
|
554
|
-
*/
|
|
555
|
-
loaderIconFilter: {
|
|
556
|
-
type: String,
|
|
557
|
-
default: "loader-default",
|
|
558
|
-
validator(value) {
|
|
559
|
-
return loaderThemeTypes.includes(value);
|
|
560
|
-
},
|
|
561
|
-
},
|
|
562
|
-
|
|
563
|
-
/**
|
|
564
|
-
* Placeholder for search field to be used if
|
|
565
|
-
* user is not allowed to create new options
|
|
566
|
-
* @default "Select features"
|
|
567
|
-
* @property {string} placeholder
|
|
568
|
-
*/
|
|
569
|
-
placeholder: {
|
|
570
|
-
type: String,
|
|
571
|
-
default: "Select features",
|
|
572
|
-
},
|
|
573
|
-
|
|
574
|
-
/**
|
|
575
|
-
* Defines overall color theme for extended multiselect
|
|
576
|
-
* @default "basic"
|
|
577
|
-
* @property {string} themeType
|
|
578
|
-
*/
|
|
579
|
-
themeType: {
|
|
580
|
-
type: String,
|
|
581
|
-
default: "basic",
|
|
582
|
-
validator(value) {
|
|
583
|
-
return themeTypes.includes(value);
|
|
584
|
-
},
|
|
585
|
-
},
|
|
586
|
-
|
|
587
|
-
/**
|
|
588
|
-
* Defines which side options list will be displayed on
|
|
589
|
-
* @default "auto"
|
|
590
|
-
* @property {string} toggleAppearanceSide
|
|
591
|
-
*/
|
|
592
|
-
toggleAppearanceSide: {
|
|
593
|
-
type: String,
|
|
594
|
-
default: "auto",
|
|
595
|
-
validator(value) {
|
|
596
|
-
return toggleAppearenceSides.includes(value);
|
|
597
|
-
},
|
|
598
|
-
},
|
|
599
|
-
|
|
600
|
-
/**
|
|
601
|
-
* Defines kind of toggle icon from icons collection
|
|
602
|
-
* @default "double-arrow"
|
|
603
|
-
* @property {string} toggleIcon
|
|
604
|
-
*/
|
|
605
|
-
toggleIcon: {
|
|
606
|
-
type: String,
|
|
607
|
-
default: "double-arrow",
|
|
608
|
-
validator(value) {
|
|
609
|
-
return toggleIcons.includes(value);
|
|
610
|
-
},
|
|
611
|
-
},
|
|
612
|
-
|
|
613
|
-
/**
|
|
614
|
-
* Defines "height" css-property for each option in options list
|
|
615
|
-
* @default 30
|
|
616
|
-
* @property {number} anyOptionWrapperBlockHeight
|
|
617
|
-
*/
|
|
618
|
-
anyOptionWrapperBlockHeight: {
|
|
619
|
-
type: Number,
|
|
620
|
-
default: 30,
|
|
621
|
-
},
|
|
622
|
-
|
|
623
|
-
/**
|
|
624
|
-
* Defines gap which increases limit of displayed elements with selected options
|
|
625
|
-
* @default 5
|
|
626
|
-
* @property {number} increaseDisplayBy
|
|
627
|
-
*/
|
|
628
|
-
increaseDisplayBy: {
|
|
629
|
-
type: Number,
|
|
630
|
-
default: 5,
|
|
631
|
-
},
|
|
632
|
-
|
|
633
|
-
/**
|
|
634
|
-
* Maximal limit of selected options
|
|
635
|
-
* @default null
|
|
636
|
-
* @property {number|null} maxOptionsCount
|
|
637
|
-
*/
|
|
638
|
-
maxOptionsCount: {
|
|
639
|
-
type: Number,
|
|
640
|
-
default: null,
|
|
641
|
-
},
|
|
642
|
-
|
|
643
|
-
/**
|
|
644
|
-
* Minimal limit of selected options
|
|
645
|
-
* @default null
|
|
646
|
-
* @property {number|null} minOptionsCount
|
|
647
|
-
*/
|
|
648
|
-
minOptionsCount: {
|
|
649
|
-
type: Number,
|
|
650
|
-
default: null,
|
|
651
|
-
},
|
|
652
|
-
|
|
653
|
-
/**
|
|
654
|
-
* Defines limit of displayed elements with selected options
|
|
655
|
-
* @default null
|
|
656
|
-
* @property {number|null} multipleBlocksLimit
|
|
657
|
-
*/
|
|
658
|
-
multipleBlocksLimit: {
|
|
659
|
-
type: Number,
|
|
660
|
-
default: null,
|
|
661
|
-
},
|
|
662
|
-
|
|
663
|
-
/**
|
|
664
|
-
* Defines maximal limit of options list length
|
|
665
|
-
* @default null
|
|
666
|
-
* @property {number|null} optionsCountRestriction
|
|
667
|
-
*/
|
|
668
|
-
optionsCountRestriction: {
|
|
669
|
-
type: Number,
|
|
670
|
-
default: null,
|
|
671
|
-
},
|
|
672
|
-
|
|
673
|
-
/**
|
|
674
|
-
* Defines maximal value in pixels of "max-height" css-property for options list
|
|
675
|
-
* @default 400
|
|
676
|
-
* @property {number} toggleMaxHeight
|
|
677
|
-
*/
|
|
678
|
-
toggleMaxHeight: {
|
|
679
|
-
type: Number,
|
|
680
|
-
default: 400,
|
|
681
|
-
},
|
|
682
|
-
|
|
683
|
-
/**
|
|
684
|
-
* Defines minimal value in pixels of "max-height" css-property for options list
|
|
685
|
-
* @default null
|
|
686
|
-
* @property {number} toggleMaxHeight
|
|
687
|
-
*/
|
|
688
|
-
toggleMinHeight: {
|
|
689
|
-
type: Number,
|
|
690
|
-
default: null,
|
|
691
|
-
},
|
|
692
|
-
|
|
693
|
-
/**
|
|
694
|
-
* Defines a list of fields for options of type "object" created by user
|
|
695
|
-
* @default ["label"]
|
|
696
|
-
* @property {Array} createOptionFields
|
|
697
|
-
*/
|
|
698
|
-
createOptionFields: {
|
|
699
|
-
type: Array,
|
|
700
|
-
default: () => ["label"],
|
|
701
|
-
validator(value) {
|
|
702
|
-
return !value.some((field) => {
|
|
703
|
-
return typeof field !== "string";
|
|
704
|
-
});
|
|
705
|
-
},
|
|
706
|
-
},
|
|
707
|
-
|
|
708
|
-
/**
|
|
709
|
-
* Defines a list of primitive types for options.
|
|
710
|
-
* Options of given types will be disabled for selection.
|
|
711
|
-
* @default []
|
|
712
|
-
* @property {Array} disabledPrimitiveOptions
|
|
713
|
-
*/
|
|
714
|
-
disabledPrimitiveOptions: {
|
|
715
|
-
type: Array,
|
|
716
|
-
default: () => [],
|
|
717
|
-
validator(value) {
|
|
718
|
-
return value.every((option) => {
|
|
719
|
-
return typeof option === "string" || Array.isArray(option)
|
|
720
|
-
|| typeof option === "number" || typeof option === "boolean"
|
|
721
|
-
|| typeof option === "function";
|
|
722
|
-
});
|
|
723
|
-
},
|
|
724
|
-
},
|
|
725
|
-
|
|
726
|
-
/**
|
|
727
|
-
* Raw options list
|
|
728
|
-
* @default []
|
|
729
|
-
* @property {Array|Function} options
|
|
730
|
-
*/
|
|
731
|
-
options: {
|
|
732
|
-
type: [Array, Function],
|
|
733
|
-
default: () => [],
|
|
734
|
-
},
|
|
735
|
-
|
|
736
|
-
/**
|
|
737
|
-
* Defines a list with "padding-top", "padding-left", "padding-bottom"
|
|
738
|
-
* and "padding-right" css-properties for options in options list.
|
|
739
|
-
* Property "padding-top" matches index zero.
|
|
740
|
-
* Property "padding-right" matches index three.
|
|
741
|
-
* @default []
|
|
742
|
-
* @property {Array} optionsPadding
|
|
743
|
-
*/
|
|
744
|
-
optionsPadding: {
|
|
745
|
-
type: Array,
|
|
746
|
-
default: () => [],
|
|
747
|
-
validator(value) {
|
|
748
|
-
return value.length < 5
|
|
749
|
-
&& !value.some((padding) => {
|
|
750
|
-
return typeof padding !== "number";
|
|
751
|
-
});
|
|
752
|
-
},
|
|
753
|
-
},
|
|
754
|
-
|
|
755
|
-
/**
|
|
756
|
-
* Defines a list of options that will be select by default
|
|
757
|
-
* @default []
|
|
758
|
-
* @property {Array} preselectedOptions
|
|
759
|
-
*/
|
|
760
|
-
preselectedOptions: {
|
|
761
|
-
type: Array,
|
|
762
|
-
default: () => [],
|
|
763
|
-
},
|
|
764
|
-
|
|
765
|
-
/**
|
|
766
|
-
* Defines a list of keys which in combination with mouse buttons or "enter" key
|
|
767
|
-
* will prevent selection of option
|
|
768
|
-
* @default []
|
|
769
|
-
* @property {Array} specialKeysBlock
|
|
770
|
-
*/
|
|
771
|
-
specialKeysBlock: {
|
|
772
|
-
type: Array,
|
|
773
|
-
default: () => [],
|
|
774
|
-
validator(value) {
|
|
775
|
-
return value.every((keyBlock) => {
|
|
776
|
-
return specialKeysToBlock.includes(keyBlock);
|
|
777
|
-
});
|
|
778
|
-
},
|
|
779
|
-
},
|
|
780
|
-
|
|
781
|
-
/**
|
|
782
|
-
* Defines value of extended multiselect that can be used in "v-model" attribute
|
|
783
|
-
* @default []
|
|
784
|
-
* @property {Array|null} modelValue
|
|
785
|
-
*/
|
|
786
|
-
modelValue: {
|
|
787
|
-
type: UnionPropType,
|
|
788
|
-
default: null,
|
|
789
|
-
},
|
|
790
|
-
|
|
791
|
-
/**
|
|
792
|
-
* Defines function that creates custom label for each option
|
|
793
|
-
* @default ()=>null
|
|
794
|
-
* @property {Function} createCustomOptionLabel
|
|
795
|
-
*/
|
|
796
|
-
createCustomOptionLabel: {
|
|
797
|
-
type: Function,
|
|
798
|
-
default: (option) => null,
|
|
799
|
-
},
|
|
800
|
-
|
|
801
|
-
/**
|
|
802
|
-
* Defines function that creates notification when maximal limit
|
|
803
|
-
* of selected options has been reached
|
|
804
|
-
* @default ()=>string
|
|
805
|
-
* @property {Function} multipleBlocksLimitMessage
|
|
806
|
-
*/
|
|
807
|
-
multipleBlocksLimitMessage: {
|
|
808
|
-
type: Function,
|
|
809
|
-
default: (number) => `and ${number} more items`,
|
|
810
|
-
},
|
|
811
|
-
|
|
812
|
-
/**
|
|
813
|
-
* "id" attribute of search field
|
|
814
|
-
* @default null
|
|
815
|
-
* @property {string|number|null} inputId
|
|
816
|
-
*/
|
|
817
|
-
inputId: {
|
|
818
|
-
type: [String, Number],
|
|
819
|
-
default: null,
|
|
820
|
-
},
|
|
821
|
-
|
|
822
|
-
/**
|
|
823
|
-
* Defines options that will be select by default
|
|
824
|
-
* @default null
|
|
825
|
-
* @property {UnionPropType|null} preselectedOption
|
|
826
|
-
*/
|
|
827
|
-
preselectedOption: {
|
|
828
|
-
type: UnionPropType,
|
|
829
|
-
default: null,
|
|
830
|
-
},
|
|
831
|
-
});
|
|
832
|
-
|
|
833
|
-
const emit = defineEmits([
|
|
834
|
-
"active",
|
|
835
|
-
"clean",
|
|
836
|
-
"close",
|
|
837
|
-
"increase",
|
|
838
|
-
"option-created",
|
|
839
|
-
"pattern-changed",
|
|
840
|
-
"select",
|
|
841
|
-
"update:modelValue"
|
|
842
|
-
]);
|
|
843
|
-
|
|
844
|
-
const dropdownActive = ref(false);
|
|
845
|
-
const inputDisabled = ref(false);
|
|
846
|
-
const internalLoader = ref(false);
|
|
847
|
-
const chosenToggleAppearanceSide = ref(null);
|
|
848
|
-
const rawOptions = ref([]);
|
|
849
|
-
const selectedOptions = ref([]);
|
|
850
|
-
const togglePattern = /^extended__multiselect-toggle/i;
|
|
851
|
-
|
|
852
|
-
/**
|
|
853
|
-
* Element references
|
|
854
|
-
*/
|
|
855
|
-
const extendedMultiselectWrapper = ref(null);
|
|
856
|
-
const extendedMultiselect = ref(null);
|
|
857
|
-
const extendedMultiselectToggle = ref(null);
|
|
858
|
-
|
|
859
|
-
const {
|
|
860
|
-
defaultExpanded,
|
|
861
|
-
disabled,
|
|
862
|
-
disabledPrimitiveOptions,
|
|
863
|
-
emptyObjectsPlaceholder,
|
|
864
|
-
errorBorderColor,
|
|
865
|
-
inputId,
|
|
866
|
-
label,
|
|
867
|
-
loading,
|
|
868
|
-
loaderIconFilter,
|
|
869
|
-
multiple,
|
|
870
|
-
options,
|
|
871
|
-
optionsCountRestriction,
|
|
872
|
-
preselectedOption,
|
|
873
|
-
preselectedOptions,
|
|
874
|
-
resetSearchByValue,
|
|
875
|
-
simpleEvents,
|
|
876
|
-
showClearIcon,
|
|
877
|
-
showInsertWarnings,
|
|
878
|
-
showSearchField,
|
|
879
|
-
themeType,
|
|
880
|
-
toggleAppearanceSide,
|
|
881
|
-
toggleMaxHeight,
|
|
882
|
-
toggleOptionsBySelect,
|
|
883
|
-
wrongCurrentValue,
|
|
884
|
-
} = toRefs(props);
|
|
885
|
-
|
|
886
|
-
const {
|
|
887
|
-
searchState,
|
|
888
|
-
setSearchValue,
|
|
889
|
-
setSearchPattern,
|
|
890
|
-
} = useSearchValue();
|
|
891
|
-
|
|
892
|
-
provide("loaderIconFilter", loaderIconFilter.value);
|
|
893
|
-
provide("searchState", searchState);
|
|
894
|
-
provide("setSearchValue", setSearchValue);
|
|
895
|
-
provide("setSearchPattern", setSearchPattern);
|
|
896
|
-
|
|
897
|
-
const { toggleOptionsList } = useToggle(loading, disabled, internalLoader);
|
|
898
|
-
const { cancel } = useCancel(disabled, showSearchField, selectedOptions);
|
|
899
|
-
const { createLabel, optionTypeRestrictor } = usePreselectedOptions(
|
|
900
|
-
label,
|
|
901
|
-
emptyObjectsPlaceholder,
|
|
902
|
-
showInsertWarnings,
|
|
903
|
-
);
|
|
904
|
-
const attrs = useAttrs();
|
|
905
|
-
const slots = useSlots();
|
|
906
|
-
|
|
907
|
-
/**
|
|
908
|
-
* Defines a list of extended multiselect wrapper classes
|
|
909
|
-
* @function
|
|
910
|
-
* @returns {Array} classes
|
|
911
|
-
*/
|
|
912
|
-
const classes = computed(() => {
|
|
913
|
-
let theme;
|
|
914
|
-
const localClassList = [];
|
|
915
|
-
|
|
916
|
-
switch(themeType.value) {
|
|
917
|
-
case "basic":
|
|
918
|
-
theme = "extended__multiselect";
|
|
919
|
-
break;
|
|
920
|
-
case "slate-grey":
|
|
921
|
-
theme = "extended__multiselect-slate-grey";
|
|
922
|
-
break;
|
|
923
|
-
case "slate-blue":
|
|
924
|
-
theme = "extended__multiselect-slate-blue";
|
|
925
|
-
break;
|
|
926
|
-
case "teal":
|
|
927
|
-
theme = "extended__multiselect-teal";
|
|
928
|
-
break;
|
|
929
|
-
case "strict":
|
|
930
|
-
theme = "extended__multiselect-strict";
|
|
931
|
-
break;
|
|
932
|
-
default: return ["extended__multiselect"];
|
|
933
|
-
}
|
|
934
|
-
|
|
935
|
-
localClassList.push(theme);
|
|
936
|
-
|
|
937
|
-
const clear = showClearIcon.value
|
|
938
|
-
? "extended__multiselect-clear--active"
|
|
939
|
-
: "extended__multiselect-clear--locked";
|
|
940
|
-
|
|
941
|
-
localClassList.push(clear);
|
|
942
|
-
|
|
943
|
-
return localClassList;
|
|
944
|
-
});
|
|
945
|
-
|
|
946
|
-
/**
|
|
947
|
-
* Defines a list of disabled options by types given in "disabledPrimitiveOptions" prop
|
|
948
|
-
* @function
|
|
949
|
-
* @returns {Array} options
|
|
950
|
-
*/
|
|
951
|
-
const disabledPrimitiveOptionsConverted = computed(() => {
|
|
952
|
-
if (!disabledPrimitiveOptions.value) return null;
|
|
953
|
-
|
|
954
|
-
return disabledPrimitiveOptions.value.map((disabledOption) => {
|
|
955
|
-
if (Array.isArray(disabledOption)) {
|
|
956
|
-
if (!disabledOption.length) return emptyObjectsPlaceholder.value;
|
|
957
|
-
|
|
958
|
-
return disabledOption.join(", ");
|
|
959
|
-
}
|
|
960
|
-
|
|
961
|
-
return disabledOption;
|
|
962
|
-
});
|
|
963
|
-
});
|
|
964
|
-
|
|
965
|
-
/**
|
|
966
|
-
* Determines whether to display irregularity of value by "border-color" css-property
|
|
967
|
-
* @function
|
|
968
|
-
* @returns {Object|null} styles
|
|
969
|
-
*/
|
|
970
|
-
const displayWrongValue = computed(() => {
|
|
971
|
-
return wrongCurrentValue.value ? { borderColor: errorBorderColor.value } : null;
|
|
972
|
-
});
|
|
973
|
-
|
|
974
|
-
/**
|
|
975
|
-
* Defines styles depending on current options list dropdown state
|
|
976
|
-
* @function
|
|
977
|
-
* @returns {Object|null} styles
|
|
978
|
-
*/
|
|
979
|
-
const expanded = computed(() => {
|
|
980
|
-
let borderStyles;
|
|
981
|
-
|
|
982
|
-
if (chosenToggleAppearanceSide.value === "atop") {
|
|
983
|
-
borderStyles = {
|
|
984
|
-
borderTopLeftRadius: 0,
|
|
985
|
-
borderTopRightRadius: 0,
|
|
986
|
-
transition: "border-top-left-radius 250ms, border-top-right-radius 250ms",
|
|
987
|
-
};
|
|
988
|
-
} else {
|
|
989
|
-
borderStyles = {
|
|
990
|
-
borderBottomLeftRadius: 0,
|
|
991
|
-
borderBottomRightRadius: 0,
|
|
992
|
-
transition: "border-bottom-left-radius 250ms, border-bottom-right-radius 250ms",
|
|
993
|
-
};
|
|
994
|
-
}
|
|
995
|
-
|
|
996
|
-
return dropdownActive.value ? borderStyles : null;
|
|
997
|
-
});
|
|
998
|
-
|
|
999
|
-
/**
|
|
1000
|
-
* Determines whether to activate loading state by "loading" prop
|
|
1001
|
-
* or by internal loading sign
|
|
1002
|
-
* @function
|
|
1003
|
-
* @returns {boolean} loading
|
|
1004
|
-
*/
|
|
1005
|
-
const internalLoading = computed(() => {
|
|
1006
|
-
return loading.value || internalLoader.value;
|
|
1007
|
-
});
|
|
1008
|
-
|
|
1009
|
-
/**
|
|
1010
|
-
* Defines a list of options filtered by maximal admissible options amount
|
|
1011
|
-
* @function
|
|
1012
|
-
* @returns {Array} options
|
|
1013
|
-
*/
|
|
1014
|
-
const restrictedOptions = computed(() => {
|
|
1015
|
-
return optionsCountRestriction.value
|
|
1016
|
-
? rawOptions.value.filter((option, index) => index + 1 <= optionsCountRestriction.value)
|
|
1017
|
-
: rawOptions.value;
|
|
1018
|
-
});
|
|
1019
|
-
|
|
1020
|
-
/**
|
|
1021
|
-
* Determines length of options list after filtering by
|
|
1022
|
-
* maximal admissible options amount
|
|
1023
|
-
* @function
|
|
1024
|
-
* @returns {number} length
|
|
1025
|
-
*/
|
|
1026
|
-
const restrictedOptionsLength = computed(() => {
|
|
1027
|
-
return restrictedOptions.value.length;
|
|
1028
|
-
});
|
|
1029
|
-
|
|
1030
|
-
/**
|
|
1031
|
-
* Defines "aria-roledescription" attribute of extended multiselect wrapper
|
|
1032
|
-
* @function
|
|
1033
|
-
* @returns {string} aria-roledescription
|
|
1034
|
-
*/
|
|
1035
|
-
const roledescription = computed(() => {
|
|
1036
|
-
return multiple.value ? "Multiselect" : "Select";
|
|
1037
|
-
});
|
|
1038
|
-
|
|
1039
|
-
/**
|
|
1040
|
-
* Defines "tabindex" attribute of extended multiselect wrapper if needed
|
|
1041
|
-
* @function
|
|
1042
|
-
* @returns {number} tabindex
|
|
1043
|
-
*/
|
|
1044
|
-
const tabindexIfSearch = computed(() => {
|
|
1045
|
-
return showSearchField.value ? attrs.tabindex : -1;
|
|
1046
|
-
});
|
|
1047
|
-
|
|
1048
|
-
/**
|
|
1049
|
-
* Defines special class which indicates disabled or loading state
|
|
1050
|
-
* of extended multiselect wrapper
|
|
1051
|
-
* @function
|
|
1052
|
-
* @returns {string} class
|
|
1053
|
-
*/
|
|
1054
|
-
const wrapperClasses = computed(() => {
|
|
1055
|
-
return inputDisabled.value && !internalLoading.value
|
|
1056
|
-
? "extended__multiselect-wrapper--disabled"
|
|
1057
|
-
: "extended__multiselect-wrapper";
|
|
1058
|
-
});
|
|
1059
|
-
|
|
1060
|
-
/**
|
|
1061
|
-
* Disables search field if "disabled" prop equals true
|
|
1062
|
-
* @function
|
|
1063
|
-
* @param {boolean} value - "disabled" prop
|
|
1064
|
-
*/
|
|
1065
|
-
watch(disabled, (value) => {
|
|
1066
|
-
inputDisabled.value = value;
|
|
1067
|
-
}, { immediate: true });
|
|
1068
|
-
|
|
1069
|
-
/**
|
|
1070
|
-
* Forcibly rolls up dropdown options list by changing "dropdownActive" flag
|
|
1071
|
-
* @function
|
|
1072
|
-
* @emits extended:rollup-options
|
|
1073
|
-
* @param {boolean} value - "dropdownActive" flag
|
|
1074
|
-
*/
|
|
1075
|
-
watch(dropdownActive, (value) => {
|
|
1076
|
-
if (!value) {
|
|
1077
|
-
emitter.emit("extended:rollup-options");
|
|
1078
|
-
}
|
|
1079
|
-
});
|
|
1080
|
-
|
|
1081
|
-
/**
|
|
1082
|
-
* Disables search field if "loading" prop equals true
|
|
1083
|
-
* @function
|
|
1084
|
-
* @param {boolean} value - "loading" prop
|
|
1085
|
-
*/
|
|
1086
|
-
watch(internalLoading, (value) => {
|
|
1087
|
-
if (disabled.value) return;
|
|
1088
|
-
|
|
1089
|
-
inputDisabled.value = value;
|
|
1090
|
-
}, { immediate: true });
|
|
1091
|
-
|
|
1092
|
-
/**
|
|
1093
|
-
* Clears value of search field after changing selected option/options
|
|
1094
|
-
* if "resetSearchByValue" prop equals true
|
|
1095
|
-
* @function
|
|
1096
|
-
* @emits extended:clear-field
|
|
1097
|
-
*/
|
|
1098
|
-
watch(selectedOptions, (value) => {
|
|
1099
|
-
if (multiple.value) {
|
|
1100
|
-
emit("update:modelValue", value);
|
|
1101
|
-
} else {
|
|
1102
|
-
emit("update:modelValue", value[0]);
|
|
1103
|
-
}
|
|
1104
|
-
|
|
1105
|
-
if (resetSearchByValue.value) {
|
|
1106
|
-
emitter.emit("extended:clear-field");
|
|
1107
|
-
}
|
|
1108
|
-
}, { deep: true });
|
|
1109
|
-
|
|
1110
|
-
/**
|
|
1111
|
-
* Emits "active" when dropdown options list is active
|
|
1112
|
-
* @function
|
|
1113
|
-
* @emits active
|
|
1114
|
-
*/
|
|
1115
|
-
const activeEmitter = () => {
|
|
1116
|
-
const eventData = simpleEvents.value ? null : {
|
|
1117
|
-
inputId: inputId.value,
|
|
1118
|
-
};
|
|
1119
|
-
|
|
1120
|
-
/**
|
|
1121
|
-
* @event active
|
|
1122
|
-
* @type {object|null}
|
|
1123
|
-
* @property {string} inputId - id of search field set by "id" prop
|
|
1124
|
-
*/
|
|
1125
|
-
emit("active", eventData);
|
|
1126
|
-
};
|
|
1127
|
-
|
|
1128
|
-
/**
|
|
1129
|
-
* Emits "close" when dropdown options list is rolled up
|
|
1130
|
-
* @function
|
|
1131
|
-
* @emits close
|
|
1132
|
-
*/
|
|
1133
|
-
const closeEmitter = () => {
|
|
1134
|
-
const eventData = simpleEvents.value
|
|
1135
|
-
? selectedOptions.value
|
|
1136
|
-
: createEventFields(selectedOptions.value, "options");
|
|
1137
|
-
|
|
1138
|
-
/**
|
|
1139
|
-
* @event close
|
|
1140
|
-
* @type {object|Array}
|
|
1141
|
-
* @property {string} inputId - id of search field set by "id" prop
|
|
1142
|
-
* @property {Array} options - array of selected options
|
|
1143
|
-
*/
|
|
1144
|
-
emit("close", eventData);
|
|
1145
|
-
}
|
|
1146
|
-
|
|
1147
|
-
/**
|
|
1148
|
-
* Creates payload for events that can be listened by outer listeners
|
|
1149
|
-
* @function
|
|
1150
|
-
* @param {UnionPropType} field - main payload of event
|
|
1151
|
-
* @param {string} fieldName - name of field with main payload of event
|
|
1152
|
-
* @returns {object} payload
|
|
1153
|
-
*/
|
|
1154
|
-
const createEventFields = (field, fieldName) => {
|
|
1155
|
-
const eventFields = {
|
|
1156
|
-
inputId: inputId.value,
|
|
1157
|
-
};
|
|
1158
|
-
|
|
1159
|
-
Object.defineProperty(eventFields, fieldName, {
|
|
1160
|
-
value: field,
|
|
1161
|
-
enumerable: true,
|
|
1162
|
-
});
|
|
1163
|
-
|
|
1164
|
-
return eventFields;
|
|
1165
|
-
};
|
|
1166
|
-
|
|
1167
|
-
/**
|
|
1168
|
-
* Focuses search field if "click" native event was triggered on available element
|
|
1169
|
-
* @function
|
|
1170
|
-
* @emits extended:field-focus
|
|
1171
|
-
* @param {MouseEvent} mouseEvent - MouseEvent instance
|
|
1172
|
-
*/
|
|
1173
|
-
const fieldFocus = (mouseEvent) => {
|
|
1174
|
-
if (internalLoading.value || disabled.value) return;
|
|
1175
|
-
|
|
1176
|
-
if (!toggleOptionsBySelect.value) {
|
|
1177
|
-
const customFilteredOptions = toggleOptionsRestrictor(mouseEvent);
|
|
1178
|
-
|
|
1179
|
-
if (customFilteredOptions) return;
|
|
1180
|
-
}
|
|
1181
|
-
|
|
1182
|
-
const customFilteredCancel = toggleCustomRestrictor(mouseEvent, 2);
|
|
1183
|
-
const customFilteredSelf = toggleCustomRestrictor(mouseEvent, 1);
|
|
1184
|
-
const filteredHasCancel = toggleDetector(mouseEvent, /^extended__multiselect-cancel/i);
|
|
1185
|
-
const filteredHasToggle = toggleDetector(mouseEvent, togglePattern);
|
|
1186
|
-
|
|
1187
|
-
if (customFilteredCancel) return;
|
|
1188
|
-
if (customFilteredSelf && dropdownActive.value === false) return;
|
|
1189
|
-
if (filteredHasCancel.length) return;
|
|
1190
|
-
if (filteredHasToggle.length && dropdownActive.value === false) return;
|
|
1191
|
-
|
|
1192
|
-
emitter.emit("extended:field-focus");
|
|
1193
|
-
};
|
|
1194
|
-
|
|
1195
|
-
/**
|
|
1196
|
-
* Emits event whose listener resets index of "enter" key pressing
|
|
1197
|
-
* @function
|
|
1198
|
-
* @emits extended:reset-index
|
|
1199
|
-
*/
|
|
1200
|
-
const resetEnterIndex = () => {
|
|
1201
|
-
emitter.emit("extended:reset-index");
|
|
1202
|
-
};
|
|
1203
|
-
|
|
1204
|
-
/**
|
|
1205
|
-
* Rolls up dropdown options list
|
|
1206
|
-
* @function
|
|
1207
|
-
* @emits extended:rollup-options
|
|
1208
|
-
*/
|
|
1209
|
-
const rollUp = () => {
|
|
1210
|
-
dropdownActive.value = false;
|
|
1211
|
-
emitter.emit("extended:rollup-options");
|
|
1212
|
-
};
|
|
1213
|
-
|
|
1214
|
-
/**
|
|
1215
|
-
* Triggers selection of option by "enter" key pressing
|
|
1216
|
-
* @function
|
|
1217
|
-
* @emits extended:select-enter
|
|
1218
|
-
* @param {KeyboardEvent} keyboardEvent - KeyboardEvent instance
|
|
1219
|
-
*/
|
|
1220
|
-
const selectByEnter = (keyboardEvent) => {
|
|
1221
|
-
emitter.emit("extended:select-enter", keyboardEvent);
|
|
1222
|
-
};
|
|
1223
|
-
|
|
1224
|
-
/**
|
|
1225
|
-
* Sets preselected option provided by "preselectedOption" prop
|
|
1226
|
-
* @function
|
|
1227
|
-
* @emits extended:select-option
|
|
1228
|
-
*/
|
|
1229
|
-
const setPreselectedOption = () => {
|
|
1230
|
-
const availableOptionType = optionTypeRestrictor(preselectedOption.value);
|
|
1231
|
-
const mappedOptions = restrictedOptions.value.map((restrictedOption) => {
|
|
1232
|
-
return JSON.stringify(restrictedOption);
|
|
1233
|
-
});
|
|
1234
|
-
|
|
1235
|
-
if (!availableOptionType) return;
|
|
1236
|
-
if (!mappedOptions.includes(JSON.stringify(preselectedOption.value)) && showInsertWarnings.value) {
|
|
1237
|
-
console.warn("vue-extended-multiselect: option in «preselectedOption» property should be the same as analogue in «options» property");
|
|
1238
|
-
return;
|
|
1239
|
-
}
|
|
1240
|
-
|
|
1241
|
-
const isObjectOrArray = typeof preselectedOption.value === "object";
|
|
1242
|
-
const label = createLabel(isObjectOrArray, preselectedOption.value);
|
|
1243
|
-
|
|
1244
|
-
emitter.emit("extended:select-option", {
|
|
1245
|
-
label,
|
|
1246
|
-
option: preselectedOption.value,
|
|
1247
|
-
});
|
|
1248
|
-
};
|
|
1249
|
-
|
|
1250
|
-
/**
|
|
1251
|
-
* Sets preselected options provided by "preselectedOptions" prop
|
|
1252
|
-
* if "multiple" prop equals true
|
|
1253
|
-
* @function
|
|
1254
|
-
* @emits extended:select-option
|
|
1255
|
-
*/
|
|
1256
|
-
const setPreselectedOptions = async () => {
|
|
1257
|
-
let allOptionsWereSelected = 0;
|
|
1258
|
-
const mappedOptions = restrictedOptions.value.map((restrictedOption) => {
|
|
1259
|
-
return JSON.stringify(restrictedOption);
|
|
1260
|
-
});
|
|
1261
|
-
|
|
1262
|
-
preselectedOptions.value.forEach((preselectedOption) => {
|
|
1263
|
-
const availableOptionType = optionTypeRestrictor(preselectedOption);
|
|
1264
|
-
|
|
1265
|
-
if (!preselectedOption || !availableOptionType) return;
|
|
1266
|
-
if (selectedOptions.value.includes(preselectedOption)) return;
|
|
1267
|
-
|
|
1268
|
-
if (mappedOptions.includes(JSON.stringify(preselectedOption))) {
|
|
1269
|
-
const isObjectOrArray = typeof option === "object";
|
|
1270
|
-
const label = createLabel(isObjectOrArray, preselectedOption);
|
|
1271
|
-
|
|
1272
|
-
allOptionsWereSelected++;
|
|
1273
|
-
|
|
1274
|
-
emitter.emit("extended:select-option", {
|
|
1275
|
-
label,
|
|
1276
|
-
option: preselectedOption,
|
|
1277
|
-
});
|
|
1278
|
-
}
|
|
1279
|
-
});
|
|
1280
|
-
|
|
1281
|
-
if (allOptionsWereSelected !== preselectedOptions.value.length && showInsertWarnings.value) {
|
|
1282
|
-
console.warn("vue-extended-multiselect: options in «preselectedOptions» property should be the same as analogues in «options» property");
|
|
1283
|
-
}
|
|
1284
|
-
};
|
|
1285
|
-
|
|
1286
|
-
/**
|
|
1287
|
-
* Determines conditions that control preselected options installattion
|
|
1288
|
-
* @function
|
|
1289
|
-
*/
|
|
1290
|
-
const setPreselectedOptionsByConditions = () => {
|
|
1291
|
-
if (preselectedOption.value && !multiple.value) {
|
|
1292
|
-
setPreselectedOption();
|
|
1293
|
-
}
|
|
1294
|
-
|
|
1295
|
-
if (preselectedOptions.value && multiple.value) {
|
|
1296
|
-
setPreselectedOptions();
|
|
1297
|
-
}
|
|
1298
|
-
};
|
|
1299
|
-
|
|
1300
|
-
/**
|
|
1301
|
-
* Defines a position of dropdown appearance
|
|
1302
|
-
* @function
|
|
1303
|
-
* @returns {string} position
|
|
1304
|
-
*/
|
|
1305
|
-
const toggleAppearanceRestrictor = () => {
|
|
1306
|
-
if (!window) return "under";
|
|
1307
|
-
|
|
1308
|
-
const innerHeight = window.innerHeight;
|
|
1309
|
-
const offsetTop = extendedMultiselect.value.getBoundingClientRect().y;
|
|
1310
|
-
const difference = innerHeight - offsetTop;
|
|
1311
|
-
|
|
1312
|
-
if (difference > toggleMaxHeight.value) {
|
|
1313
|
-
return "under";
|
|
1314
|
-
} else {
|
|
1315
|
-
return "atop";
|
|
1316
|
-
}
|
|
1317
|
-
};
|
|
1318
|
-
|
|
1319
|
-
/**
|
|
1320
|
-
* Sets a position of dropdown appearance
|
|
1321
|
-
* @function
|
|
1322
|
-
*/
|
|
1323
|
-
const toggleAppearanceRestrictorActivate = () => {
|
|
1324
|
-
if (!dropdownActive.value) {
|
|
1325
|
-
chosenToggleAppearanceSide.value = toggleAppearanceSide.value !== "auto"
|
|
1326
|
-
? toggleAppearanceSide.value
|
|
1327
|
-
: toggleAppearanceRestrictor();
|
|
1328
|
-
}
|
|
1329
|
-
};
|
|
1330
|
-
|
|
1331
|
-
/**
|
|
1332
|
-
* Restricts toggling of dropdown options list
|
|
1333
|
-
* @function
|
|
1334
|
-
* @emits extended:skip-block-blur
|
|
1335
|
-
* @param {MouseEvent} mouseEvent - MouseEvent instance
|
|
1336
|
-
* @returns {boolean} toggling
|
|
1337
|
-
*/
|
|
1338
|
-
const toggleBlockRestrictor = (mouseEvent) => {
|
|
1339
|
-
let generalRestriction;
|
|
1340
|
-
let filteredCustomSelf;
|
|
1341
|
-
const filteredHasBlock = toggleDetector(mouseEvent, /^extended__multiselect-block/i, true);
|
|
1342
|
-
const filteredSelf = toggleDetector(mouseEvent, /^extended__multiselect-clear/i);
|
|
1343
|
-
|
|
1344
|
-
if (filteredSelf || filteredHasBlock) {
|
|
1345
|
-
filteredCustomSelf = true;
|
|
1346
|
-
} else {
|
|
1347
|
-
filteredCustomSelf = toggleCustomRestrictor(mouseEvent);
|
|
1348
|
-
}
|
|
1349
|
-
|
|
1350
|
-
if (extendedMultiselectToggle.value) {
|
|
1351
|
-
generalRestriction = (filteredHasBlock && dropdownActive.value && filteredCustomSelf)
|
|
1352
|
-
|| (filteredSelf && dropdownActive.value && filteredCustomSelf);
|
|
1353
|
-
} else {
|
|
1354
|
-
generalRestriction = (filteredHasBlock && dropdownActive.value)
|
|
1355
|
-
|| (filteredSelf && dropdownActive.value);
|
|
1356
|
-
}
|
|
1357
|
-
|
|
1358
|
-
if (generalRestriction) {
|
|
1359
|
-
emitter.emit("extended:skip-block-blur");
|
|
1360
|
-
return true;
|
|
1361
|
-
}
|
|
1362
|
-
|
|
1363
|
-
return false;
|
|
1364
|
-
}
|
|
1365
|
-
|
|
1366
|
-
/**
|
|
1367
|
-
* Restricts toggling of dropdown options list by clicking
|
|
1368
|
-
* on particular descendants of toggle wrapper element
|
|
1369
|
-
* @function
|
|
1370
|
-
* @param {MouseEvent} mouseEvent - MouseEvent instance
|
|
1371
|
-
* @param {number} blockType - type of block which needs restriction
|
|
1372
|
-
* @returns {boolean} restriction
|
|
1373
|
-
*/
|
|
1374
|
-
const toggleCustomRestrictor = (mouseEvent, blockType) => {
|
|
1375
|
-
let eventTarget = mouseEvent.target;
|
|
1376
|
-
const toggleWrapper = extendedMultiselect.value;
|
|
1377
|
-
const customToggle = toggleWrapper.children[blockType];
|
|
1378
|
-
|
|
1379
|
-
while(eventTarget) {
|
|
1380
|
-
if (eventTarget === customToggle) return true;
|
|
1381
|
-
|
|
1382
|
-
eventTarget = eventTarget.parentNode;
|
|
1383
|
-
}
|
|
1384
|
-
|
|
1385
|
-
return false;
|
|
1386
|
-
};
|
|
1387
|
-
|
|
1388
|
-
/**
|
|
1389
|
-
* Restricts toggling of dropdown options list by clicking
|
|
1390
|
-
* on particular elements defined by given pattern
|
|
1391
|
-
* @function
|
|
1392
|
-
* @param {MouseEvent} mouseEvent - MouseEvent instance
|
|
1393
|
-
* @param {string} pattern - pattern with block class partial name
|
|
1394
|
-
* @param {boolean} mode - marks whether restrict by parent element or by current target
|
|
1395
|
-
* @returns {Array} classes
|
|
1396
|
-
*/
|
|
1397
|
-
const toggleDetector = (mouseEvent, pattern, mode) => {
|
|
1398
|
-
const target = mouseEvent.target;
|
|
1399
|
-
|
|
1400
|
-
let filteredHasToggle = Array.prototype.filter.call(target.classList, (className) => {
|
|
1401
|
-
return pattern.test(className) === true;
|
|
1402
|
-
});
|
|
1403
|
-
|
|
1404
|
-
if (!filteredHasToggle.length && mode && target.parentNode) {
|
|
1405
|
-
filteredHasToggle = Array.prototype.filter.call(target.parentNode.classList, (className) => {
|
|
1406
|
-
return pattern.test(className) === true;
|
|
1407
|
-
});
|
|
1408
|
-
}
|
|
1409
|
-
|
|
1410
|
-
return filteredHasToggle;
|
|
1411
|
-
};
|
|
1412
|
-
|
|
1413
|
-
/**
|
|
1414
|
-
* Toggles dropdown options list and activates
|
|
1415
|
-
* necessary methods with relevant events
|
|
1416
|
-
* @function
|
|
1417
|
-
*/
|
|
1418
|
-
const toggleOptions = () => {
|
|
1419
|
-
if (internalLoading.value || disabled.value) return;
|
|
1420
|
-
|
|
1421
|
-
toggleAppearanceRestrictorActivate();
|
|
1422
|
-
|
|
1423
|
-
if (!dropdownActive.value) {
|
|
1424
|
-
activeEmitter();
|
|
1425
|
-
} else {
|
|
1426
|
-
closeEmitter();
|
|
1427
|
-
}
|
|
1428
|
-
|
|
1429
|
-
dropdownActive.value = !dropdownActive.value;
|
|
1430
|
-
};
|
|
1431
|
-
|
|
1432
|
-
/**
|
|
1433
|
-
* Prevents toggling dropdown options list
|
|
1434
|
-
* by selecting/deselecting option
|
|
1435
|
-
* @function
|
|
1436
|
-
* @param {MouseEvent} mouseEvent - MouseEvent instance
|
|
1437
|
-
* @returns {boolean} restriction
|
|
1438
|
-
*/
|
|
1439
|
-
const toggleOptionsRestrictor = (mouseEvent) => {
|
|
1440
|
-
let eventTarget = mouseEvent.target;
|
|
1441
|
-
const optionsWrapper = optionsWrapper.value;
|
|
1442
|
-
|
|
1443
|
-
while(eventTarget) {
|
|
1444
|
-
if (eventTarget === optionsWrapper) return true;
|
|
1445
|
-
|
|
1446
|
-
eventTarget = eventTarget.parentNode;
|
|
1447
|
-
}
|
|
1448
|
-
|
|
1449
|
-
return false;
|
|
1450
|
-
};
|
|
1451
|
-
|
|
1452
|
-
/**
|
|
1453
|
-
* Collects restrictions from other methods and defines
|
|
1454
|
-
* general restriction of toggling dropdown options list
|
|
1455
|
-
* @function
|
|
1456
|
-
* @emits extended:skip-blur
|
|
1457
|
-
* @param {MouseEvent} mouseEvent - MouseEvent instance
|
|
1458
|
-
*/
|
|
1459
|
-
const toggleRestrictor = (mouseEvent) => {
|
|
1460
|
-
const targetContentBlock = toggleBlockRestrictor(mouseEvent);
|
|
1461
|
-
|
|
1462
|
-
if (targetContentBlock) return;
|
|
1463
|
-
|
|
1464
|
-
const filteredHasToggle = toggleDetector(mouseEvent, togglePattern);
|
|
1465
|
-
|
|
1466
|
-
if (filteredHasToggle.length && dropdownActive.value) {
|
|
1467
|
-
emitter.emit("extended:skip-blur");
|
|
1468
|
-
}
|
|
1469
|
-
};
|
|
1470
|
-
|
|
1471
|
-
/**
|
|
1472
|
-
* "onBeforeMount" hook of the Vue3ExtendedMultiselect component
|
|
1473
|
-
* @emits select
|
|
1474
|
-
* @emits clean
|
|
1475
|
-
* @emits option-created
|
|
1476
|
-
* @emits increase
|
|
1477
|
-
* @emits pattern-changed
|
|
1478
|
-
* @emits extended:rollup-options
|
|
1479
|
-
* @listens extended:rollup-options
|
|
1480
|
-
* @listens extended:toggle-options
|
|
1481
|
-
* @listens extended:select-option
|
|
1482
|
-
* @listens extended:deselect-option
|
|
1483
|
-
* @listens extended:clean-options
|
|
1484
|
-
* @listens extended:create-option
|
|
1485
|
-
* @listens extended:increase-display
|
|
1486
|
-
* @listens extended:search-pattern-changed
|
|
1487
|
-
*/
|
|
1488
|
-
onBeforeMount(() => {
|
|
1489
|
-
chosenToggleAppearanceSide.value = toggleAppearanceSide.value;
|
|
1490
|
-
|
|
1491
|
-
emitter.on("extended:rollup-options", () => {
|
|
1492
|
-
if (!dropdownActive.value) return;
|
|
1493
|
-
|
|
1494
|
-
closeEmitter();
|
|
1495
|
-
dropdownActive.value = false;
|
|
1496
|
-
});
|
|
1497
|
-
|
|
1498
|
-
emitter.on("extended:toggle-options", () => {
|
|
1499
|
-
toggleOptions();
|
|
1500
|
-
});
|
|
1501
|
-
|
|
1502
|
-
emitter.on("extended:select-option", (option) => {
|
|
1503
|
-
const eventData = simpleEvents.value
|
|
1504
|
-
? option.option
|
|
1505
|
-
: createEventFields(option.option, "option");
|
|
1506
|
-
|
|
1507
|
-
if (multiple.value) {
|
|
1508
|
-
selectedOptions.value.push(option.option);
|
|
1509
|
-
/**
|
|
1510
|
-
* @event select
|
|
1511
|
-
* @type {Object}
|
|
1512
|
-
* @property {string} inputId - id of search field set by "id" prop
|
|
1513
|
-
* @property {UnionPropType} option - just now selected option
|
|
1514
|
-
*/
|
|
1515
|
-
emit("select", eventData);
|
|
1516
|
-
} else {
|
|
1517
|
-
selectedOptions.value = [option.option];
|
|
1518
|
-
/**
|
|
1519
|
-
* @see select
|
|
1520
|
-
*/
|
|
1521
|
-
emit("select", eventData);
|
|
1522
|
-
}
|
|
1523
|
-
});
|
|
1524
|
-
|
|
1525
|
-
emitter.on("extended:deselect-option", (index = null, clearAll) => {
|
|
1526
|
-
if (multiple.value && !clearAll) {
|
|
1527
|
-
const deselectedOption = selectedOptions.value[index];
|
|
1528
|
-
|
|
1529
|
-
const eventData = simpleEvents.value
|
|
1530
|
-
? deselectedOption
|
|
1531
|
-
: createEventFields(deselectedOption, "option");
|
|
1532
|
-
|
|
1533
|
-
/**
|
|
1534
|
-
* @event clean
|
|
1535
|
-
* @type {Object}
|
|
1536
|
-
* @property {string} inputId - id of search field set by "id" prop
|
|
1537
|
-
* @property {UnionPropType} option - just now deselected option
|
|
1538
|
-
*/
|
|
1539
|
-
emit("clean", eventData);
|
|
1540
|
-
|
|
1541
|
-
selectedOptions.value.splice(index, 1);
|
|
1542
|
-
return;
|
|
1543
|
-
} else {
|
|
1544
|
-
selectedOptions.value = [];
|
|
1545
|
-
}
|
|
1546
|
-
|
|
1547
|
-
emitter.emit("extended:rollup-options");
|
|
1548
|
-
});
|
|
1549
|
-
|
|
1550
|
-
emitter.on("extended:clean-options", (selectedOptions) => {
|
|
1551
|
-
const eventData = simpleEvents.value
|
|
1552
|
-
? selectedOptions.value
|
|
1553
|
-
: createEventFields(selectedOptions, "options");
|
|
1554
|
-
|
|
1555
|
-
/**
|
|
1556
|
-
* @see clean
|
|
1557
|
-
* @property {Array} options - just now deselected options
|
|
1558
|
-
*/
|
|
1559
|
-
emit("clean", eventData);
|
|
1560
|
-
});
|
|
1561
|
-
|
|
1562
|
-
emitter.on("extended:create-option", (createdOption) => {
|
|
1563
|
-
const eventData = simpleEvents.value
|
|
1564
|
-
? createdOption
|
|
1565
|
-
: createEventFields(createdOption, "option");
|
|
1566
|
-
|
|
1567
|
-
/**
|
|
1568
|
-
* @event option-created
|
|
1569
|
-
* @type {PluginObject}
|
|
1570
|
-
* @property {string} inputId - id of search field set by "id" prop
|
|
1571
|
-
* @property {UnionPropType} option - option created by user
|
|
1572
|
-
*/
|
|
1573
|
-
emit("option-created", eventData);
|
|
1574
|
-
});
|
|
1575
|
-
|
|
1576
|
-
emitter.on("extended:increase-display", (limit) => {
|
|
1577
|
-
const eventData = simpleEvents.value ? limit : createEventFields(limit, "limit");
|
|
1578
|
-
|
|
1579
|
-
/**
|
|
1580
|
-
* @event increase
|
|
1581
|
-
* @type {Object}
|
|
1582
|
-
* @property {string} inputId - id of search field set by "id" prop
|
|
1583
|
-
* @property {limit} - current limit of options to be shown next
|
|
1584
|
-
*/
|
|
1585
|
-
emit("increase", eventData);
|
|
1586
|
-
});
|
|
1587
|
-
|
|
1588
|
-
emitter.on("extended:search-pattern-changed", (pattern) => {
|
|
1589
|
-
const eventData = simpleEvents.value
|
|
1590
|
-
? pattern
|
|
1591
|
-
: createEventFields(pattern, "pattern");
|
|
1592
|
-
|
|
1593
|
-
/**
|
|
1594
|
-
* @event pattern-changed
|
|
1595
|
-
* @type {Object}
|
|
1596
|
-
* @property {string} inputId - id of search field set by "id" prop
|
|
1597
|
-
* @property {pattern} - pattern of internal search for available options
|
|
1598
|
-
*/
|
|
1599
|
-
emit("pattern-changed", eventData);
|
|
1600
|
-
});
|
|
1601
|
-
});
|
|
1602
|
-
|
|
1603
|
-
/**
|
|
1604
|
-
* "onMounted" hook of the Vue3ExtendedMultiselect component
|
|
1605
|
-
* @emits extended:rollup-options
|
|
1606
|
-
* @listens extended:expand-options
|
|
1607
|
-
*/
|
|
1608
|
-
onMounted(() => {
|
|
1609
|
-
if (typeof options.value === "function") {
|
|
1610
|
-
internalLoader.value = true;
|
|
1611
|
-
options.value().then(options => {
|
|
1612
|
-
rawOptions.value = options;
|
|
1613
|
-
internalLoader.value = false;
|
|
1614
|
-
setPreselectedOptionsByConditions();
|
|
1615
|
-
});
|
|
1616
|
-
} else {
|
|
1617
|
-
rawOptions.value = options.value;
|
|
1618
|
-
setPreselectedOptionsByConditions();
|
|
1619
|
-
}
|
|
1620
|
-
|
|
1621
|
-
const root = extendedMultiselectWrapper.value;
|
|
1622
|
-
|
|
1623
|
-
clickOutside(root, () => {
|
|
1624
|
-
emitter.emit("extended:rollup-options");
|
|
1625
|
-
});
|
|
1626
|
-
|
|
1627
|
-
if (
|
|
1628
|
-
defaultExpanded.value
|
|
1629
|
-
&& !inputDisabled.value
|
|
1630
|
-
&& !internalLoading.value
|
|
1631
|
-
&& typeof options.value !== "function"
|
|
1632
|
-
) {
|
|
1633
|
-
dropdownActive.value = true;
|
|
1634
|
-
}
|
|
1635
|
-
|
|
1636
|
-
emitter.on("extended:expand-options", () => {
|
|
1637
|
-
if (dropdownActive.value === true) return;
|
|
1638
|
-
|
|
1639
|
-
toggleAppearanceRestrictorActivate();
|
|
1640
|
-
activeEmitter();
|
|
1641
|
-
|
|
1642
|
-
dropdownActive.value = true;
|
|
1643
|
-
});
|
|
1644
|
-
});
|
|
1645
|
-
</script>
|
|
1646
|
-
|
|
1647
|
-
<style>
|
|
1648
|
-
|
|
1649
|
-
@import "../styles/main.css";
|
|
1650
|
-
|
|
1651
|
-
</style>
|
|
1
|
+
<template>
|
|
2
|
+
<section
|
|
3
|
+
aria-owns="extended-search-field"
|
|
4
|
+
ref="extendedMultiselectWrapper"
|
|
5
|
+
role="combobox"
|
|
6
|
+
:aria-roledescription="roledescription"
|
|
7
|
+
:class="wrapperClasses"
|
|
8
|
+
:tabindex="tabindexIfSearch"
|
|
9
|
+
@click.stop.left="fieldFocus"
|
|
10
|
+
@click.stop.middle="fieldFocus"
|
|
11
|
+
@keyup.stop.esc="rollUp"
|
|
12
|
+
@keyup.stop.enter="selectByEnter"
|
|
13
|
+
@mousedown.stop.left="toggleRestrictor"
|
|
14
|
+
@mousedown.stop.middle="toggleRestrictor"
|
|
15
|
+
@mouseleave.stop="resetEnterIndex"
|
|
16
|
+
>
|
|
17
|
+
<div
|
|
18
|
+
id="extended__multiselect"
|
|
19
|
+
ref="extendedMultiselect"
|
|
20
|
+
:class="classes"
|
|
21
|
+
:style="[displayWrongValue, expanded]"
|
|
22
|
+
>
|
|
23
|
+
<div>
|
|
24
|
+
<extended-multiselect-input
|
|
25
|
+
:accesskey="attrs.accesskey"
|
|
26
|
+
:autocomplete="attrs.autocomplete"
|
|
27
|
+
:name="attrs.name"
|
|
28
|
+
:spellcheck="attrs.spellcheck"
|
|
29
|
+
:tabindex="attrs.tabindex"
|
|
30
|
+
:translate="attrs.translate"
|
|
31
|
+
:create-on-the-go="createOnTheGo"
|
|
32
|
+
:disabled="inputDisabled"
|
|
33
|
+
:dropdown-active="dropdownActive"
|
|
34
|
+
:loading="internalLoading"
|
|
35
|
+
:multiple="multiple"
|
|
36
|
+
:search-filter-active="searchFilterActive"
|
|
37
|
+
:toggling-saves-search-value="togglingSavesSearchValue"
|
|
38
|
+
:toggle-options-by-select="toggleOptionsBySelect"
|
|
39
|
+
:placeholder="placeholder"
|
|
40
|
+
:show-search-field="showSearchField"
|
|
41
|
+
:empty-objects-placeholder="emptyObjectsPlaceholder"
|
|
42
|
+
:multiple-blocks-limit-message="multipleBlocksLimitMessage"
|
|
43
|
+
:theme-type="themeType"
|
|
44
|
+
:increase-display-by="increaseDisplayBy"
|
|
45
|
+
:multipleBlocksLimit="multipleBlocksLimit"
|
|
46
|
+
:restricted-options-length="restrictedOptionsLength"
|
|
47
|
+
:toggle-multiple-blocks-limit="toggleMultipleBlocksLimit"
|
|
48
|
+
:selected-options="selectedOptions"
|
|
49
|
+
:create-custom-option-label="createCustomOptionLabel"
|
|
50
|
+
:create-option-placeholder="createOptionPlaceholder"
|
|
51
|
+
:input-id="inputId"
|
|
52
|
+
>
|
|
53
|
+
<template
|
|
54
|
+
v-if="!showSearchField"
|
|
55
|
+
#labelBlock="{ labelBlockValue }"
|
|
56
|
+
>
|
|
57
|
+
<slot
|
|
58
|
+
name="labelBlock"
|
|
59
|
+
:label="labelBlockValue"
|
|
60
|
+
>
|
|
61
|
+
</slot>
|
|
62
|
+
</template>
|
|
63
|
+
<template #optionBlock="{ label, deselectBlock, index }">
|
|
64
|
+
<slot
|
|
65
|
+
name="optionBlock"
|
|
66
|
+
:label="label"
|
|
67
|
+
:index="index"
|
|
68
|
+
:deselect-block="deselectBlock"
|
|
69
|
+
>
|
|
70
|
+
</slot>
|
|
71
|
+
</template>
|
|
72
|
+
<template
|
|
73
|
+
#maxElements
|
|
74
|
+
>
|
|
75
|
+
<slot name="maxElements"></slot>
|
|
76
|
+
</template>
|
|
77
|
+
<template
|
|
78
|
+
v-if="toggleMultipleBlocksLimit"
|
|
79
|
+
#showMore="{ showMoreOptions }"
|
|
80
|
+
>
|
|
81
|
+
<slot
|
|
82
|
+
name="showMore"
|
|
83
|
+
:increase="showMoreOptions"
|
|
84
|
+
>
|
|
85
|
+
</slot>
|
|
86
|
+
</template>
|
|
87
|
+
</extended-multiselect-input>
|
|
88
|
+
</div>
|
|
89
|
+
<slot
|
|
90
|
+
name="toggle"
|
|
91
|
+
:toggle-options-list="toggleOptionsList"
|
|
92
|
+
>
|
|
93
|
+
<extended-multiselect-toggle
|
|
94
|
+
ref="extendedMultiselectToggle"
|
|
95
|
+
:tabindex="attrs.tabindex"
|
|
96
|
+
:disabled="inputDisabled"
|
|
97
|
+
:dropdown-active="dropdownActive"
|
|
98
|
+
:loading="internalLoading"
|
|
99
|
+
:icon-filter="iconFilter"
|
|
100
|
+
:icon-size="iconSize"
|
|
101
|
+
:toggle-icon="toggleIcon"
|
|
102
|
+
/>
|
|
103
|
+
</slot>
|
|
104
|
+
<slot
|
|
105
|
+
name="cancel"
|
|
106
|
+
:cancel="cancel"
|
|
107
|
+
>
|
|
108
|
+
<extended-multiselect-cancel
|
|
109
|
+
v-if="showClearIcon"
|
|
110
|
+
:tabindex="attrs.tabindex"
|
|
111
|
+
:disabled="inputDisabled"
|
|
112
|
+
:show-search-field="showSearchField"
|
|
113
|
+
:loading="internalLoading"
|
|
114
|
+
:icon-filter="iconFilter"
|
|
115
|
+
:icon-size="iconSize"
|
|
116
|
+
:selected-options="selectedOptions"
|
|
117
|
+
/>
|
|
118
|
+
</slot>
|
|
119
|
+
</div>
|
|
120
|
+
<transition
|
|
121
|
+
name="extended-toggle"
|
|
122
|
+
type="transition"
|
|
123
|
+
>
|
|
124
|
+
<extended-multiselect-options
|
|
125
|
+
v-if="dropdownActive"
|
|
126
|
+
:auto-select-created-option="autoSelectCreatedOption"
|
|
127
|
+
:clear-by-select-when-multiple="clearBySelectWhenMultiple"
|
|
128
|
+
:create-on-the-go="createOnTheGo"
|
|
129
|
+
:disabled-primitive-options-converted="disabledPrimitiveOptionsConverted"
|
|
130
|
+
:highlight-options="highlightOptions"
|
|
131
|
+
:multiple="multiple"
|
|
132
|
+
:selected-options-shown="selectedOptionsShown"
|
|
133
|
+
:show-insert-warnings="showInsertWarnings"
|
|
134
|
+
:show-marker="showMarker"
|
|
135
|
+
:chosen-toggle-appearance-side="chosenToggleAppearanceSide"
|
|
136
|
+
:create-option-type="createOptionType"
|
|
137
|
+
:empty-objects-placeholder="emptyObjectsPlaceholder"
|
|
138
|
+
:label="label"
|
|
139
|
+
:theme-type="themeType"
|
|
140
|
+
:any-option-wrapper-block-height="anyOptionWrapperBlockHeight"
|
|
141
|
+
:max-options-count="maxOptionsCount"
|
|
142
|
+
:min-options-count="minOptionsCount"
|
|
143
|
+
:options-padding="optionsPadding"
|
|
144
|
+
:toggle-max-height="toggleMaxHeight"
|
|
145
|
+
:toggle-min-height="toggleMinHeight"
|
|
146
|
+
:create-option-fields="createOptionFields"
|
|
147
|
+
:options="restrictedOptions"
|
|
148
|
+
:restricted-options="restrictedOptions"
|
|
149
|
+
:selected-options="selectedOptions"
|
|
150
|
+
:special-keys-block="specialKeysBlock"
|
|
151
|
+
:preselected-option="preselectedOption"
|
|
152
|
+
:preselected-options="preselectedOptions"
|
|
153
|
+
:create-custom-option-label="createCustomOptionLabel"
|
|
154
|
+
>
|
|
155
|
+
<template
|
|
156
|
+
v-if="slots.listHeader"
|
|
157
|
+
#listHeader
|
|
158
|
+
>
|
|
159
|
+
<slot name="listHeader"></slot>
|
|
160
|
+
</template>
|
|
161
|
+
<template
|
|
162
|
+
v-if="maxOptionsCount"
|
|
163
|
+
#moreThanLimit
|
|
164
|
+
>
|
|
165
|
+
<slot name="moreThanLimit"></slot>
|
|
166
|
+
</template>
|
|
167
|
+
<template
|
|
168
|
+
v-if="minOptionsCount"
|
|
169
|
+
#lessThanLimit
|
|
170
|
+
>
|
|
171
|
+
<slot name="lessThanLimit"></slot>
|
|
172
|
+
</template>
|
|
173
|
+
<template #option="{ option, createCustomOptionLabel }">
|
|
174
|
+
<slot
|
|
175
|
+
name="option"
|
|
176
|
+
:option="option"
|
|
177
|
+
:create-custom-option-label="createCustomOptionLabel"
|
|
178
|
+
>
|
|
179
|
+
</slot>
|
|
180
|
+
</template>
|
|
181
|
+
<template #marker>
|
|
182
|
+
<slot name="marker"></slot>
|
|
183
|
+
</template>
|
|
184
|
+
<template
|
|
185
|
+
v-if="noResultsBlockShown"
|
|
186
|
+
#noResults
|
|
187
|
+
>
|
|
188
|
+
<slot name="noResults"></slot>
|
|
189
|
+
</template>
|
|
190
|
+
<template #noOptions>
|
|
191
|
+
<slot name="noOptions"></slot>
|
|
192
|
+
</template>
|
|
193
|
+
<template
|
|
194
|
+
v-if="slots.listFooter"
|
|
195
|
+
#listFooter
|
|
196
|
+
>
|
|
197
|
+
<slot name="listFooter"></slot>
|
|
198
|
+
</template>
|
|
199
|
+
</extended-multiselect-options>
|
|
200
|
+
</transition>
|
|
201
|
+
</section>
|
|
202
|
+
</template>
|
|
203
|
+
|
|
204
|
+
<script setup>
|
|
205
|
+
import {
|
|
206
|
+
computed,
|
|
207
|
+
defineEmits,
|
|
208
|
+
defineProps,
|
|
209
|
+
onBeforeMount,
|
|
210
|
+
onMounted,
|
|
211
|
+
provide,
|
|
212
|
+
ref,
|
|
213
|
+
toRefs,
|
|
214
|
+
useAttrs,
|
|
215
|
+
useSlots,
|
|
216
|
+
watch,
|
|
217
|
+
} from "vue";
|
|
218
|
+
|
|
219
|
+
import clickOutside from "click-outside";
|
|
220
|
+
import emitter from "tiny-emitter/instance";
|
|
221
|
+
|
|
222
|
+
import {
|
|
223
|
+
themeTypes,
|
|
224
|
+
loaderThemeTypes,
|
|
225
|
+
toggleIcons,
|
|
226
|
+
iconFilters,
|
|
227
|
+
iconSizes,
|
|
228
|
+
createOptionTypes,
|
|
229
|
+
specialKeysToBlock,
|
|
230
|
+
toggleAppearenceSides,
|
|
231
|
+
UnionPropType,
|
|
232
|
+
} from "../sets/sets";
|
|
233
|
+
|
|
234
|
+
import useToggle from "../composition/toggle";
|
|
235
|
+
import useCancel from "../composition/cancel";
|
|
236
|
+
import usePreselectedOptions from "../composition/preselected-options";
|
|
237
|
+
import useSearchValue from "../composition/search-value";
|
|
238
|
+
|
|
239
|
+
import ExtendedMultiselectCancel from "./ExtendedMultiselectCancel.vue";
|
|
240
|
+
import ExtendedMultiselectInput from "./ExtendedMultiselectInput.vue";
|
|
241
|
+
import ExtendedMultiselectOptions from "./ExtendedMultiselectOptions.vue";
|
|
242
|
+
import ExtendedMultiselectToggle from "./ExtendedMultiselectToggle.vue";
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* @author Ridiger Daniil Dmitrievich
|
|
246
|
+
* @version 1.0.0
|
|
247
|
+
*/
|
|
248
|
+
|
|
249
|
+
const props = defineProps({
|
|
250
|
+
/**
|
|
251
|
+
* Determines whether to select just now created option
|
|
252
|
+
* automatically
|
|
253
|
+
* @default false
|
|
254
|
+
* @property {boolean} autoSelectCreatedOption
|
|
255
|
+
*/
|
|
256
|
+
autoSelectCreatedOption: {
|
|
257
|
+
type: Boolean,
|
|
258
|
+
default: false,
|
|
259
|
+
},
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* Determines whether to clear search field by option selection
|
|
263
|
+
* @default false
|
|
264
|
+
* @property {boolean} clearBySelectWhenMultiple
|
|
265
|
+
*/
|
|
266
|
+
clearBySelectWhenMultiple: {
|
|
267
|
+
type: Boolean,
|
|
268
|
+
default: false,
|
|
269
|
+
},
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* Allows user to create new options from search field
|
|
273
|
+
* @default false
|
|
274
|
+
* @property {boolean} createOnTheGo
|
|
275
|
+
*/
|
|
276
|
+
createOnTheGo: {
|
|
277
|
+
type: Boolean,
|
|
278
|
+
default: false,
|
|
279
|
+
},
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* Determines whether options list should be expanded by default
|
|
283
|
+
* @default false
|
|
284
|
+
* @property {boolean} defaultExpanded
|
|
285
|
+
*/
|
|
286
|
+
defaultExpanded: {
|
|
287
|
+
type: Boolean,
|
|
288
|
+
default: false,
|
|
289
|
+
},
|
|
290
|
+
|
|
291
|
+
/**
|
|
292
|
+
* Disables extended multiselect
|
|
293
|
+
* @default false
|
|
294
|
+
* @property {boolean} disabled
|
|
295
|
+
*/
|
|
296
|
+
disabled: {
|
|
297
|
+
type: Boolean,
|
|
298
|
+
default: false,
|
|
299
|
+
},
|
|
300
|
+
|
|
301
|
+
/**
|
|
302
|
+
* Switches options highlighting while hovering
|
|
303
|
+
* @default true
|
|
304
|
+
* @property {boolean} highlightOptions
|
|
305
|
+
*/
|
|
306
|
+
highlightOptions: {
|
|
307
|
+
type: Boolean,
|
|
308
|
+
default: true,
|
|
309
|
+
},
|
|
310
|
+
|
|
311
|
+
/**
|
|
312
|
+
* Switches loading state of extended multiselect
|
|
313
|
+
* @default false
|
|
314
|
+
* @property {boolean} loading
|
|
315
|
+
*/
|
|
316
|
+
loading: {
|
|
317
|
+
type: Boolean,
|
|
318
|
+
default: false,
|
|
319
|
+
},
|
|
320
|
+
|
|
321
|
+
/**
|
|
322
|
+
* Allows user to select multiple options
|
|
323
|
+
* @default false
|
|
324
|
+
* @property {boolean} multiple
|
|
325
|
+
*/
|
|
326
|
+
multiple: {
|
|
327
|
+
type: Boolean,
|
|
328
|
+
default: false,
|
|
329
|
+
},
|
|
330
|
+
|
|
331
|
+
/**
|
|
332
|
+
* Determines whether to show special hint if no options were found
|
|
333
|
+
* @default true
|
|
334
|
+
* @property {boolean} noResultsBlockShown
|
|
335
|
+
*/
|
|
336
|
+
noResultsBlockShown: {
|
|
337
|
+
type: Boolean,
|
|
338
|
+
default: true,
|
|
339
|
+
},
|
|
340
|
+
|
|
341
|
+
/**
|
|
342
|
+
* Determines whether to clear search field by selection/deselection of options
|
|
343
|
+
* @default true
|
|
344
|
+
* @property {boolean} resetSearchByValue
|
|
345
|
+
*/
|
|
346
|
+
resetSearchByValue: {
|
|
347
|
+
type: Boolean,
|
|
348
|
+
default: true,
|
|
349
|
+
},
|
|
350
|
+
|
|
351
|
+
/**
|
|
352
|
+
* Allows user to use internal search for options
|
|
353
|
+
* @default true
|
|
354
|
+
* @property {boolean} searchFilterActive
|
|
355
|
+
*/
|
|
356
|
+
searchFilterActive: {
|
|
357
|
+
type: Boolean,
|
|
358
|
+
default: true,
|
|
359
|
+
},
|
|
360
|
+
|
|
361
|
+
/**
|
|
362
|
+
* Switches full payload of extended multiselect events
|
|
363
|
+
* @default true
|
|
364
|
+
* @property {boolean} simpleEvents
|
|
365
|
+
*/
|
|
366
|
+
simpleEvents: {
|
|
367
|
+
type: Boolean,
|
|
368
|
+
default: true,
|
|
369
|
+
},
|
|
370
|
+
|
|
371
|
+
/**
|
|
372
|
+
* Determines whether to show selected options in options list
|
|
373
|
+
* @default false
|
|
374
|
+
* @property {boolean} selectedOptionsShown
|
|
375
|
+
*/
|
|
376
|
+
selectedOptionsShown: {
|
|
377
|
+
type: Boolean,
|
|
378
|
+
default: false,
|
|
379
|
+
},
|
|
380
|
+
|
|
381
|
+
/**
|
|
382
|
+
* Allows user to deselect all options by special icon
|
|
383
|
+
* @default false
|
|
384
|
+
* @property {boolean} showClearIcon
|
|
385
|
+
*/
|
|
386
|
+
showClearIcon: {
|
|
387
|
+
type: Boolean,
|
|
388
|
+
default: false,
|
|
389
|
+
},
|
|
390
|
+
|
|
391
|
+
/**
|
|
392
|
+
* Determines whether to show useful internal warnings in console
|
|
393
|
+
* @default false
|
|
394
|
+
* @property {boolean} showInsertWarnings
|
|
395
|
+
*/
|
|
396
|
+
showInsertWarnings: {
|
|
397
|
+
type: Boolean,
|
|
398
|
+
default: false,
|
|
399
|
+
},
|
|
400
|
+
|
|
401
|
+
/**
|
|
402
|
+
* Determines whether to show slot with special marker beside option in options list
|
|
403
|
+
* @default false
|
|
404
|
+
* @property {boolean} showMarker
|
|
405
|
+
*/
|
|
406
|
+
showMarker: {
|
|
407
|
+
type: Boolean,
|
|
408
|
+
default: false,
|
|
409
|
+
},
|
|
410
|
+
|
|
411
|
+
/**
|
|
412
|
+
* Determines whether to show search field which allows user
|
|
413
|
+
* to search for options with internal search
|
|
414
|
+
* @default true
|
|
415
|
+
* @property {boolean} showSearchField
|
|
416
|
+
*/
|
|
417
|
+
showSearchField: {
|
|
418
|
+
type: Boolean,
|
|
419
|
+
default: true,
|
|
420
|
+
},
|
|
421
|
+
|
|
422
|
+
/**
|
|
423
|
+
* Allows user to increase limit of shown elements with selected options
|
|
424
|
+
* by special icon
|
|
425
|
+
* @default false
|
|
426
|
+
* @property {boolean} toggleMultipleBlocksLimit
|
|
427
|
+
*/
|
|
428
|
+
toggleMultipleBlocksLimit: {
|
|
429
|
+
type: Boolean,
|
|
430
|
+
default: false,
|
|
431
|
+
},
|
|
432
|
+
|
|
433
|
+
/**
|
|
434
|
+
* Determines whether to roll up options list by selection of option
|
|
435
|
+
* @default true
|
|
436
|
+
* @property {boolean} toggleOptionsBySelect
|
|
437
|
+
*/
|
|
438
|
+
toggleOptionsBySelect: {
|
|
439
|
+
type: Boolean,
|
|
440
|
+
default: true,
|
|
441
|
+
},
|
|
442
|
+
|
|
443
|
+
/**
|
|
444
|
+
* Determines whether to save current search value if
|
|
445
|
+
* display of options list was toggled
|
|
446
|
+
* @default true
|
|
447
|
+
* @property {boolean} togglingSavesSearchValue
|
|
448
|
+
*/
|
|
449
|
+
togglingSavesSearchValue: {
|
|
450
|
+
type: Boolean,
|
|
451
|
+
default: true,
|
|
452
|
+
},
|
|
453
|
+
|
|
454
|
+
/**
|
|
455
|
+
* Determines whether to define special class for extended multiselect
|
|
456
|
+
* if value is wrong
|
|
457
|
+
* Irregularity of value is defined by user
|
|
458
|
+
* @default false
|
|
459
|
+
* @property {boolean} wrongCurrentValue
|
|
460
|
+
*/
|
|
461
|
+
wrongCurrentValue: {
|
|
462
|
+
type: Boolean,
|
|
463
|
+
default: false,
|
|
464
|
+
},
|
|
465
|
+
|
|
466
|
+
/**
|
|
467
|
+
* Placeholder for the search field to be used if
|
|
468
|
+
* user is allowed to create new options
|
|
469
|
+
* @default "Select or create features"
|
|
470
|
+
* @property {string} createOptionPlaceholder
|
|
471
|
+
*/
|
|
472
|
+
createOptionPlaceholder: {
|
|
473
|
+
type: String,
|
|
474
|
+
default: "Select or create features",
|
|
475
|
+
},
|
|
476
|
+
|
|
477
|
+
/**
|
|
478
|
+
* Defines kind for all options which will be created by user
|
|
479
|
+
* @default "primitive"
|
|
480
|
+
* @property {string} createOptionType
|
|
481
|
+
*/
|
|
482
|
+
createOptionType: {
|
|
483
|
+
type: String,
|
|
484
|
+
default: "primitive",
|
|
485
|
+
validator(value) {
|
|
486
|
+
return createOptionTypes.includes(value);
|
|
487
|
+
},
|
|
488
|
+
},
|
|
489
|
+
|
|
490
|
+
/**
|
|
491
|
+
* Placeholder for options of type "object"
|
|
492
|
+
* or Array instances which length/keys length equals 0
|
|
493
|
+
* @default "Empty Object/Array"
|
|
494
|
+
* @property {string} emptyObjectsPlaceholder
|
|
495
|
+
*/
|
|
496
|
+
emptyObjectsPlaceholder: {
|
|
497
|
+
type: String,
|
|
498
|
+
default: "Empty Object/Array",
|
|
499
|
+
validator(value) {
|
|
500
|
+
return !!value;
|
|
501
|
+
},
|
|
502
|
+
},
|
|
503
|
+
|
|
504
|
+
/**
|
|
505
|
+
* Defines "border-color" css-property for extended multiselect with wrong value
|
|
506
|
+
* @default "#FF0000"
|
|
507
|
+
* @property {string} errorBorderColor
|
|
508
|
+
*/
|
|
509
|
+
errorBorderColor: {
|
|
510
|
+
type: String,
|
|
511
|
+
default: "#FF0000",
|
|
512
|
+
},
|
|
513
|
+
|
|
514
|
+
/**
|
|
515
|
+
* Defines svg-filter with color settings for all icons except loader
|
|
516
|
+
* @default "basic"
|
|
517
|
+
* @property {string} iconFilter
|
|
518
|
+
*/
|
|
519
|
+
iconFilter: {
|
|
520
|
+
type: String,
|
|
521
|
+
default: "basic",
|
|
522
|
+
validator(value) {
|
|
523
|
+
return iconFilters.includes(value);
|
|
524
|
+
},
|
|
525
|
+
},
|
|
526
|
+
|
|
527
|
+
/**
|
|
528
|
+
* Defines sizes for all icons in pixels except loader
|
|
529
|
+
* @default "large"
|
|
530
|
+
* @property {string} iconSize
|
|
531
|
+
*/
|
|
532
|
+
iconSize: {
|
|
533
|
+
type: String,
|
|
534
|
+
default: "large",
|
|
535
|
+
validator(value) {
|
|
536
|
+
return iconSizes.includes(value);
|
|
537
|
+
},
|
|
538
|
+
},
|
|
539
|
+
|
|
540
|
+
/**
|
|
541
|
+
* Defines field in options of type "object" that will be the label of option
|
|
542
|
+
* @default "label"
|
|
543
|
+
* @property {string} label
|
|
544
|
+
*/
|
|
545
|
+
label: {
|
|
546
|
+
type: String,
|
|
547
|
+
default: "label",
|
|
548
|
+
},
|
|
549
|
+
|
|
550
|
+
/**
|
|
551
|
+
* Defines svg-filter with color settings for loader icon
|
|
552
|
+
* @default "loader-default"
|
|
553
|
+
* @property {string} loaderIconFilter
|
|
554
|
+
*/
|
|
555
|
+
loaderIconFilter: {
|
|
556
|
+
type: String,
|
|
557
|
+
default: "loader-default",
|
|
558
|
+
validator(value) {
|
|
559
|
+
return loaderThemeTypes.includes(value);
|
|
560
|
+
},
|
|
561
|
+
},
|
|
562
|
+
|
|
563
|
+
/**
|
|
564
|
+
* Placeholder for search field to be used if
|
|
565
|
+
* user is not allowed to create new options
|
|
566
|
+
* @default "Select features"
|
|
567
|
+
* @property {string} placeholder
|
|
568
|
+
*/
|
|
569
|
+
placeholder: {
|
|
570
|
+
type: String,
|
|
571
|
+
default: "Select features",
|
|
572
|
+
},
|
|
573
|
+
|
|
574
|
+
/**
|
|
575
|
+
* Defines overall color theme for extended multiselect
|
|
576
|
+
* @default "basic"
|
|
577
|
+
* @property {string} themeType
|
|
578
|
+
*/
|
|
579
|
+
themeType: {
|
|
580
|
+
type: String,
|
|
581
|
+
default: "basic",
|
|
582
|
+
validator(value) {
|
|
583
|
+
return themeTypes.includes(value);
|
|
584
|
+
},
|
|
585
|
+
},
|
|
586
|
+
|
|
587
|
+
/**
|
|
588
|
+
* Defines which side options list will be displayed on
|
|
589
|
+
* @default "auto"
|
|
590
|
+
* @property {string} toggleAppearanceSide
|
|
591
|
+
*/
|
|
592
|
+
toggleAppearanceSide: {
|
|
593
|
+
type: String,
|
|
594
|
+
default: "auto",
|
|
595
|
+
validator(value) {
|
|
596
|
+
return toggleAppearenceSides.includes(value);
|
|
597
|
+
},
|
|
598
|
+
},
|
|
599
|
+
|
|
600
|
+
/**
|
|
601
|
+
* Defines kind of toggle icon from icons collection
|
|
602
|
+
* @default "double-arrow"
|
|
603
|
+
* @property {string} toggleIcon
|
|
604
|
+
*/
|
|
605
|
+
toggleIcon: {
|
|
606
|
+
type: String,
|
|
607
|
+
default: "double-arrow",
|
|
608
|
+
validator(value) {
|
|
609
|
+
return toggleIcons.includes(value);
|
|
610
|
+
},
|
|
611
|
+
},
|
|
612
|
+
|
|
613
|
+
/**
|
|
614
|
+
* Defines "height" css-property for each option in options list
|
|
615
|
+
* @default 30
|
|
616
|
+
* @property {number} anyOptionWrapperBlockHeight
|
|
617
|
+
*/
|
|
618
|
+
anyOptionWrapperBlockHeight: {
|
|
619
|
+
type: Number,
|
|
620
|
+
default: 30,
|
|
621
|
+
},
|
|
622
|
+
|
|
623
|
+
/**
|
|
624
|
+
* Defines gap which increases limit of displayed elements with selected options
|
|
625
|
+
* @default 5
|
|
626
|
+
* @property {number} increaseDisplayBy
|
|
627
|
+
*/
|
|
628
|
+
increaseDisplayBy: {
|
|
629
|
+
type: Number,
|
|
630
|
+
default: 5,
|
|
631
|
+
},
|
|
632
|
+
|
|
633
|
+
/**
|
|
634
|
+
* Maximal limit of selected options
|
|
635
|
+
* @default null
|
|
636
|
+
* @property {number|null} maxOptionsCount
|
|
637
|
+
*/
|
|
638
|
+
maxOptionsCount: {
|
|
639
|
+
type: Number,
|
|
640
|
+
default: null,
|
|
641
|
+
},
|
|
642
|
+
|
|
643
|
+
/**
|
|
644
|
+
* Minimal limit of selected options
|
|
645
|
+
* @default null
|
|
646
|
+
* @property {number|null} minOptionsCount
|
|
647
|
+
*/
|
|
648
|
+
minOptionsCount: {
|
|
649
|
+
type: Number,
|
|
650
|
+
default: null,
|
|
651
|
+
},
|
|
652
|
+
|
|
653
|
+
/**
|
|
654
|
+
* Defines limit of displayed elements with selected options
|
|
655
|
+
* @default null
|
|
656
|
+
* @property {number|null} multipleBlocksLimit
|
|
657
|
+
*/
|
|
658
|
+
multipleBlocksLimit: {
|
|
659
|
+
type: Number,
|
|
660
|
+
default: null,
|
|
661
|
+
},
|
|
662
|
+
|
|
663
|
+
/**
|
|
664
|
+
* Defines maximal limit of options list length
|
|
665
|
+
* @default null
|
|
666
|
+
* @property {number|null} optionsCountRestriction
|
|
667
|
+
*/
|
|
668
|
+
optionsCountRestriction: {
|
|
669
|
+
type: Number,
|
|
670
|
+
default: null,
|
|
671
|
+
},
|
|
672
|
+
|
|
673
|
+
/**
|
|
674
|
+
* Defines maximal value in pixels of "max-height" css-property for options list
|
|
675
|
+
* @default 400
|
|
676
|
+
* @property {number} toggleMaxHeight
|
|
677
|
+
*/
|
|
678
|
+
toggleMaxHeight: {
|
|
679
|
+
type: Number,
|
|
680
|
+
default: 400,
|
|
681
|
+
},
|
|
682
|
+
|
|
683
|
+
/**
|
|
684
|
+
* Defines minimal value in pixels of "max-height" css-property for options list
|
|
685
|
+
* @default null
|
|
686
|
+
* @property {number} toggleMaxHeight
|
|
687
|
+
*/
|
|
688
|
+
toggleMinHeight: {
|
|
689
|
+
type: Number,
|
|
690
|
+
default: null,
|
|
691
|
+
},
|
|
692
|
+
|
|
693
|
+
/**
|
|
694
|
+
* Defines a list of fields for options of type "object" created by user
|
|
695
|
+
* @default ["label"]
|
|
696
|
+
* @property {Array} createOptionFields
|
|
697
|
+
*/
|
|
698
|
+
createOptionFields: {
|
|
699
|
+
type: Array,
|
|
700
|
+
default: () => ["label"],
|
|
701
|
+
validator(value) {
|
|
702
|
+
return !value.some((field) => {
|
|
703
|
+
return typeof field !== "string";
|
|
704
|
+
});
|
|
705
|
+
},
|
|
706
|
+
},
|
|
707
|
+
|
|
708
|
+
/**
|
|
709
|
+
* Defines a list of primitive types for options.
|
|
710
|
+
* Options of given types will be disabled for selection.
|
|
711
|
+
* @default []
|
|
712
|
+
* @property {Array} disabledPrimitiveOptions
|
|
713
|
+
*/
|
|
714
|
+
disabledPrimitiveOptions: {
|
|
715
|
+
type: Array,
|
|
716
|
+
default: () => [],
|
|
717
|
+
validator(value) {
|
|
718
|
+
return value.every((option) => {
|
|
719
|
+
return typeof option === "string" || Array.isArray(option)
|
|
720
|
+
|| typeof option === "number" || typeof option === "boolean"
|
|
721
|
+
|| typeof option === "function";
|
|
722
|
+
});
|
|
723
|
+
},
|
|
724
|
+
},
|
|
725
|
+
|
|
726
|
+
/**
|
|
727
|
+
* Raw options list
|
|
728
|
+
* @default []
|
|
729
|
+
* @property {Array|Function} options
|
|
730
|
+
*/
|
|
731
|
+
options: {
|
|
732
|
+
type: [Array, Function],
|
|
733
|
+
default: () => [],
|
|
734
|
+
},
|
|
735
|
+
|
|
736
|
+
/**
|
|
737
|
+
* Defines a list with "padding-top", "padding-left", "padding-bottom"
|
|
738
|
+
* and "padding-right" css-properties for options in options list.
|
|
739
|
+
* Property "padding-top" matches index zero.
|
|
740
|
+
* Property "padding-right" matches index three.
|
|
741
|
+
* @default []
|
|
742
|
+
* @property {Array} optionsPadding
|
|
743
|
+
*/
|
|
744
|
+
optionsPadding: {
|
|
745
|
+
type: Array,
|
|
746
|
+
default: () => [],
|
|
747
|
+
validator(value) {
|
|
748
|
+
return value.length < 5
|
|
749
|
+
&& !value.some((padding) => {
|
|
750
|
+
return typeof padding !== "number";
|
|
751
|
+
});
|
|
752
|
+
},
|
|
753
|
+
},
|
|
754
|
+
|
|
755
|
+
/**
|
|
756
|
+
* Defines a list of options that will be select by default
|
|
757
|
+
* @default []
|
|
758
|
+
* @property {Array} preselectedOptions
|
|
759
|
+
*/
|
|
760
|
+
preselectedOptions: {
|
|
761
|
+
type: Array,
|
|
762
|
+
default: () => [],
|
|
763
|
+
},
|
|
764
|
+
|
|
765
|
+
/**
|
|
766
|
+
* Defines a list of keys which in combination with mouse buttons or "enter" key
|
|
767
|
+
* will prevent selection of option
|
|
768
|
+
* @default []
|
|
769
|
+
* @property {Array} specialKeysBlock
|
|
770
|
+
*/
|
|
771
|
+
specialKeysBlock: {
|
|
772
|
+
type: Array,
|
|
773
|
+
default: () => [],
|
|
774
|
+
validator(value) {
|
|
775
|
+
return value.every((keyBlock) => {
|
|
776
|
+
return specialKeysToBlock.includes(keyBlock);
|
|
777
|
+
});
|
|
778
|
+
},
|
|
779
|
+
},
|
|
780
|
+
|
|
781
|
+
/**
|
|
782
|
+
* Defines value of extended multiselect that can be used in "v-model" attribute
|
|
783
|
+
* @default []
|
|
784
|
+
* @property {Array|null} modelValue
|
|
785
|
+
*/
|
|
786
|
+
modelValue: {
|
|
787
|
+
type: UnionPropType,
|
|
788
|
+
default: null,
|
|
789
|
+
},
|
|
790
|
+
|
|
791
|
+
/**
|
|
792
|
+
* Defines function that creates custom label for each option
|
|
793
|
+
* @default ()=>null
|
|
794
|
+
* @property {Function} createCustomOptionLabel
|
|
795
|
+
*/
|
|
796
|
+
createCustomOptionLabel: {
|
|
797
|
+
type: Function,
|
|
798
|
+
default: (option) => null,
|
|
799
|
+
},
|
|
800
|
+
|
|
801
|
+
/**
|
|
802
|
+
* Defines function that creates notification when maximal limit
|
|
803
|
+
* of selected options has been reached
|
|
804
|
+
* @default ()=>string
|
|
805
|
+
* @property {Function} multipleBlocksLimitMessage
|
|
806
|
+
*/
|
|
807
|
+
multipleBlocksLimitMessage: {
|
|
808
|
+
type: Function,
|
|
809
|
+
default: (number) => `and ${number} more items`,
|
|
810
|
+
},
|
|
811
|
+
|
|
812
|
+
/**
|
|
813
|
+
* "id" attribute of search field
|
|
814
|
+
* @default null
|
|
815
|
+
* @property {string|number|null} inputId
|
|
816
|
+
*/
|
|
817
|
+
inputId: {
|
|
818
|
+
type: [String, Number],
|
|
819
|
+
default: null,
|
|
820
|
+
},
|
|
821
|
+
|
|
822
|
+
/**
|
|
823
|
+
* Defines options that will be select by default
|
|
824
|
+
* @default null
|
|
825
|
+
* @property {UnionPropType|null} preselectedOption
|
|
826
|
+
*/
|
|
827
|
+
preselectedOption: {
|
|
828
|
+
type: UnionPropType,
|
|
829
|
+
default: null,
|
|
830
|
+
},
|
|
831
|
+
});
|
|
832
|
+
|
|
833
|
+
const emit = defineEmits([
|
|
834
|
+
"active",
|
|
835
|
+
"clean",
|
|
836
|
+
"close",
|
|
837
|
+
"increase",
|
|
838
|
+
"option-created",
|
|
839
|
+
"pattern-changed",
|
|
840
|
+
"select",
|
|
841
|
+
"update:modelValue"
|
|
842
|
+
]);
|
|
843
|
+
|
|
844
|
+
const dropdownActive = ref(false);
|
|
845
|
+
const inputDisabled = ref(false);
|
|
846
|
+
const internalLoader = ref(false);
|
|
847
|
+
const chosenToggleAppearanceSide = ref(null);
|
|
848
|
+
const rawOptions = ref([]);
|
|
849
|
+
const selectedOptions = ref([]);
|
|
850
|
+
const togglePattern = /^extended__multiselect-toggle/i;
|
|
851
|
+
|
|
852
|
+
/**
|
|
853
|
+
* Element references
|
|
854
|
+
*/
|
|
855
|
+
const extendedMultiselectWrapper = ref(null);
|
|
856
|
+
const extendedMultiselect = ref(null);
|
|
857
|
+
const extendedMultiselectToggle = ref(null);
|
|
858
|
+
|
|
859
|
+
const {
|
|
860
|
+
defaultExpanded,
|
|
861
|
+
disabled,
|
|
862
|
+
disabledPrimitiveOptions,
|
|
863
|
+
emptyObjectsPlaceholder,
|
|
864
|
+
errorBorderColor,
|
|
865
|
+
inputId,
|
|
866
|
+
label,
|
|
867
|
+
loading,
|
|
868
|
+
loaderIconFilter,
|
|
869
|
+
multiple,
|
|
870
|
+
options,
|
|
871
|
+
optionsCountRestriction,
|
|
872
|
+
preselectedOption,
|
|
873
|
+
preselectedOptions,
|
|
874
|
+
resetSearchByValue,
|
|
875
|
+
simpleEvents,
|
|
876
|
+
showClearIcon,
|
|
877
|
+
showInsertWarnings,
|
|
878
|
+
showSearchField,
|
|
879
|
+
themeType,
|
|
880
|
+
toggleAppearanceSide,
|
|
881
|
+
toggleMaxHeight,
|
|
882
|
+
toggleOptionsBySelect,
|
|
883
|
+
wrongCurrentValue,
|
|
884
|
+
} = toRefs(props);
|
|
885
|
+
|
|
886
|
+
const {
|
|
887
|
+
searchState,
|
|
888
|
+
setSearchValue,
|
|
889
|
+
setSearchPattern,
|
|
890
|
+
} = useSearchValue();
|
|
891
|
+
|
|
892
|
+
provide("loaderIconFilter", loaderIconFilter.value);
|
|
893
|
+
provide("searchState", searchState);
|
|
894
|
+
provide("setSearchValue", setSearchValue);
|
|
895
|
+
provide("setSearchPattern", setSearchPattern);
|
|
896
|
+
|
|
897
|
+
const { toggleOptionsList } = useToggle(loading, disabled, internalLoader);
|
|
898
|
+
const { cancel } = useCancel(disabled, showSearchField, selectedOptions);
|
|
899
|
+
const { createLabel, optionTypeRestrictor } = usePreselectedOptions(
|
|
900
|
+
label,
|
|
901
|
+
emptyObjectsPlaceholder,
|
|
902
|
+
showInsertWarnings,
|
|
903
|
+
);
|
|
904
|
+
const attrs = useAttrs();
|
|
905
|
+
const slots = useSlots();
|
|
906
|
+
|
|
907
|
+
/**
|
|
908
|
+
* Defines a list of extended multiselect wrapper classes
|
|
909
|
+
* @function
|
|
910
|
+
* @returns {Array} classes
|
|
911
|
+
*/
|
|
912
|
+
const classes = computed(() => {
|
|
913
|
+
let theme;
|
|
914
|
+
const localClassList = [];
|
|
915
|
+
|
|
916
|
+
switch(themeType.value) {
|
|
917
|
+
case "basic":
|
|
918
|
+
theme = "extended__multiselect";
|
|
919
|
+
break;
|
|
920
|
+
case "slate-grey":
|
|
921
|
+
theme = "extended__multiselect-slate-grey";
|
|
922
|
+
break;
|
|
923
|
+
case "slate-blue":
|
|
924
|
+
theme = "extended__multiselect-slate-blue";
|
|
925
|
+
break;
|
|
926
|
+
case "teal":
|
|
927
|
+
theme = "extended__multiselect-teal";
|
|
928
|
+
break;
|
|
929
|
+
case "strict":
|
|
930
|
+
theme = "extended__multiselect-strict";
|
|
931
|
+
break;
|
|
932
|
+
default: return ["extended__multiselect"];
|
|
933
|
+
}
|
|
934
|
+
|
|
935
|
+
localClassList.push(theme);
|
|
936
|
+
|
|
937
|
+
const clear = showClearIcon.value
|
|
938
|
+
? "extended__multiselect-clear--active"
|
|
939
|
+
: "extended__multiselect-clear--locked";
|
|
940
|
+
|
|
941
|
+
localClassList.push(clear);
|
|
942
|
+
|
|
943
|
+
return localClassList;
|
|
944
|
+
});
|
|
945
|
+
|
|
946
|
+
/**
|
|
947
|
+
* Defines a list of disabled options by types given in "disabledPrimitiveOptions" prop
|
|
948
|
+
* @function
|
|
949
|
+
* @returns {Array} options
|
|
950
|
+
*/
|
|
951
|
+
const disabledPrimitiveOptionsConverted = computed(() => {
|
|
952
|
+
if (!disabledPrimitiveOptions.value) return null;
|
|
953
|
+
|
|
954
|
+
return disabledPrimitiveOptions.value.map((disabledOption) => {
|
|
955
|
+
if (Array.isArray(disabledOption)) {
|
|
956
|
+
if (!disabledOption.length) return emptyObjectsPlaceholder.value;
|
|
957
|
+
|
|
958
|
+
return disabledOption.join(", ");
|
|
959
|
+
}
|
|
960
|
+
|
|
961
|
+
return disabledOption;
|
|
962
|
+
});
|
|
963
|
+
});
|
|
964
|
+
|
|
965
|
+
/**
|
|
966
|
+
* Determines whether to display irregularity of value by "border-color" css-property
|
|
967
|
+
* @function
|
|
968
|
+
* @returns {Object|null} styles
|
|
969
|
+
*/
|
|
970
|
+
const displayWrongValue = computed(() => {
|
|
971
|
+
return wrongCurrentValue.value ? { borderColor: errorBorderColor.value } : null;
|
|
972
|
+
});
|
|
973
|
+
|
|
974
|
+
/**
|
|
975
|
+
* Defines styles depending on current options list dropdown state
|
|
976
|
+
* @function
|
|
977
|
+
* @returns {Object|null} styles
|
|
978
|
+
*/
|
|
979
|
+
const expanded = computed(() => {
|
|
980
|
+
let borderStyles;
|
|
981
|
+
|
|
982
|
+
if (chosenToggleAppearanceSide.value === "atop") {
|
|
983
|
+
borderStyles = {
|
|
984
|
+
borderTopLeftRadius: 0,
|
|
985
|
+
borderTopRightRadius: 0,
|
|
986
|
+
transition: "border-top-left-radius 250ms, border-top-right-radius 250ms",
|
|
987
|
+
};
|
|
988
|
+
} else {
|
|
989
|
+
borderStyles = {
|
|
990
|
+
borderBottomLeftRadius: 0,
|
|
991
|
+
borderBottomRightRadius: 0,
|
|
992
|
+
transition: "border-bottom-left-radius 250ms, border-bottom-right-radius 250ms",
|
|
993
|
+
};
|
|
994
|
+
}
|
|
995
|
+
|
|
996
|
+
return dropdownActive.value ? borderStyles : null;
|
|
997
|
+
});
|
|
998
|
+
|
|
999
|
+
/**
|
|
1000
|
+
* Determines whether to activate loading state by "loading" prop
|
|
1001
|
+
* or by internal loading sign
|
|
1002
|
+
* @function
|
|
1003
|
+
* @returns {boolean} loading
|
|
1004
|
+
*/
|
|
1005
|
+
const internalLoading = computed(() => {
|
|
1006
|
+
return loading.value || internalLoader.value;
|
|
1007
|
+
});
|
|
1008
|
+
|
|
1009
|
+
/**
|
|
1010
|
+
* Defines a list of options filtered by maximal admissible options amount
|
|
1011
|
+
* @function
|
|
1012
|
+
* @returns {Array} options
|
|
1013
|
+
*/
|
|
1014
|
+
const restrictedOptions = computed(() => {
|
|
1015
|
+
return optionsCountRestriction.value
|
|
1016
|
+
? rawOptions.value.filter((option, index) => index + 1 <= optionsCountRestriction.value)
|
|
1017
|
+
: rawOptions.value;
|
|
1018
|
+
});
|
|
1019
|
+
|
|
1020
|
+
/**
|
|
1021
|
+
* Determines length of options list after filtering by
|
|
1022
|
+
* maximal admissible options amount
|
|
1023
|
+
* @function
|
|
1024
|
+
* @returns {number} length
|
|
1025
|
+
*/
|
|
1026
|
+
const restrictedOptionsLength = computed(() => {
|
|
1027
|
+
return restrictedOptions.value.length;
|
|
1028
|
+
});
|
|
1029
|
+
|
|
1030
|
+
/**
|
|
1031
|
+
* Defines "aria-roledescription" attribute of extended multiselect wrapper
|
|
1032
|
+
* @function
|
|
1033
|
+
* @returns {string} aria-roledescription
|
|
1034
|
+
*/
|
|
1035
|
+
const roledescription = computed(() => {
|
|
1036
|
+
return multiple.value ? "Multiselect" : "Select";
|
|
1037
|
+
});
|
|
1038
|
+
|
|
1039
|
+
/**
|
|
1040
|
+
* Defines "tabindex" attribute of extended multiselect wrapper if needed
|
|
1041
|
+
* @function
|
|
1042
|
+
* @returns {number} tabindex
|
|
1043
|
+
*/
|
|
1044
|
+
const tabindexIfSearch = computed(() => {
|
|
1045
|
+
return showSearchField.value ? attrs.tabindex : -1;
|
|
1046
|
+
});
|
|
1047
|
+
|
|
1048
|
+
/**
|
|
1049
|
+
* Defines special class which indicates disabled or loading state
|
|
1050
|
+
* of extended multiselect wrapper
|
|
1051
|
+
* @function
|
|
1052
|
+
* @returns {string} class
|
|
1053
|
+
*/
|
|
1054
|
+
const wrapperClasses = computed(() => {
|
|
1055
|
+
return inputDisabled.value && !internalLoading.value
|
|
1056
|
+
? "extended__multiselect-wrapper--disabled"
|
|
1057
|
+
: "extended__multiselect-wrapper";
|
|
1058
|
+
});
|
|
1059
|
+
|
|
1060
|
+
/**
|
|
1061
|
+
* Disables search field if "disabled" prop equals true
|
|
1062
|
+
* @function
|
|
1063
|
+
* @param {boolean} value - "disabled" prop
|
|
1064
|
+
*/
|
|
1065
|
+
watch(disabled, (value) => {
|
|
1066
|
+
inputDisabled.value = value;
|
|
1067
|
+
}, { immediate: true });
|
|
1068
|
+
|
|
1069
|
+
/**
|
|
1070
|
+
* Forcibly rolls up dropdown options list by changing "dropdownActive" flag
|
|
1071
|
+
* @function
|
|
1072
|
+
* @emits extended:rollup-options
|
|
1073
|
+
* @param {boolean} value - "dropdownActive" flag
|
|
1074
|
+
*/
|
|
1075
|
+
watch(dropdownActive, (value) => {
|
|
1076
|
+
if (!value) {
|
|
1077
|
+
emitter.emit("extended:rollup-options");
|
|
1078
|
+
}
|
|
1079
|
+
});
|
|
1080
|
+
|
|
1081
|
+
/**
|
|
1082
|
+
* Disables search field if "loading" prop equals true
|
|
1083
|
+
* @function
|
|
1084
|
+
* @param {boolean} value - "loading" prop
|
|
1085
|
+
*/
|
|
1086
|
+
watch(internalLoading, (value) => {
|
|
1087
|
+
if (disabled.value) return;
|
|
1088
|
+
|
|
1089
|
+
inputDisabled.value = value;
|
|
1090
|
+
}, { immediate: true });
|
|
1091
|
+
|
|
1092
|
+
/**
|
|
1093
|
+
* Clears value of search field after changing selected option/options
|
|
1094
|
+
* if "resetSearchByValue" prop equals true
|
|
1095
|
+
* @function
|
|
1096
|
+
* @emits extended:clear-field
|
|
1097
|
+
*/
|
|
1098
|
+
watch(selectedOptions, (value) => {
|
|
1099
|
+
if (multiple.value) {
|
|
1100
|
+
emit("update:modelValue", value);
|
|
1101
|
+
} else {
|
|
1102
|
+
emit("update:modelValue", value[0]);
|
|
1103
|
+
}
|
|
1104
|
+
|
|
1105
|
+
if (resetSearchByValue.value) {
|
|
1106
|
+
emitter.emit("extended:clear-field");
|
|
1107
|
+
}
|
|
1108
|
+
}, { deep: true });
|
|
1109
|
+
|
|
1110
|
+
/**
|
|
1111
|
+
* Emits "active" when dropdown options list is active
|
|
1112
|
+
* @function
|
|
1113
|
+
* @emits active
|
|
1114
|
+
*/
|
|
1115
|
+
const activeEmitter = () => {
|
|
1116
|
+
const eventData = simpleEvents.value ? null : {
|
|
1117
|
+
inputId: inputId.value,
|
|
1118
|
+
};
|
|
1119
|
+
|
|
1120
|
+
/**
|
|
1121
|
+
* @event active
|
|
1122
|
+
* @type {object|null}
|
|
1123
|
+
* @property {string} inputId - id of search field set by "id" prop
|
|
1124
|
+
*/
|
|
1125
|
+
emit("active", eventData);
|
|
1126
|
+
};
|
|
1127
|
+
|
|
1128
|
+
/**
|
|
1129
|
+
* Emits "close" when dropdown options list is rolled up
|
|
1130
|
+
* @function
|
|
1131
|
+
* @emits close
|
|
1132
|
+
*/
|
|
1133
|
+
const closeEmitter = () => {
|
|
1134
|
+
const eventData = simpleEvents.value
|
|
1135
|
+
? selectedOptions.value
|
|
1136
|
+
: createEventFields(selectedOptions.value, "options");
|
|
1137
|
+
|
|
1138
|
+
/**
|
|
1139
|
+
* @event close
|
|
1140
|
+
* @type {object|Array}
|
|
1141
|
+
* @property {string} inputId - id of search field set by "id" prop
|
|
1142
|
+
* @property {Array} options - array of selected options
|
|
1143
|
+
*/
|
|
1144
|
+
emit("close", eventData);
|
|
1145
|
+
}
|
|
1146
|
+
|
|
1147
|
+
/**
|
|
1148
|
+
* Creates payload for events that can be listened by outer listeners
|
|
1149
|
+
* @function
|
|
1150
|
+
* @param {UnionPropType} field - main payload of event
|
|
1151
|
+
* @param {string} fieldName - name of field with main payload of event
|
|
1152
|
+
* @returns {object} payload
|
|
1153
|
+
*/
|
|
1154
|
+
const createEventFields = (field, fieldName) => {
|
|
1155
|
+
const eventFields = {
|
|
1156
|
+
inputId: inputId.value,
|
|
1157
|
+
};
|
|
1158
|
+
|
|
1159
|
+
Object.defineProperty(eventFields, fieldName, {
|
|
1160
|
+
value: field,
|
|
1161
|
+
enumerable: true,
|
|
1162
|
+
});
|
|
1163
|
+
|
|
1164
|
+
return eventFields;
|
|
1165
|
+
};
|
|
1166
|
+
|
|
1167
|
+
/**
|
|
1168
|
+
* Focuses search field if "click" native event was triggered on available element
|
|
1169
|
+
* @function
|
|
1170
|
+
* @emits extended:field-focus
|
|
1171
|
+
* @param {MouseEvent} mouseEvent - MouseEvent instance
|
|
1172
|
+
*/
|
|
1173
|
+
const fieldFocus = (mouseEvent) => {
|
|
1174
|
+
if (internalLoading.value || disabled.value) return;
|
|
1175
|
+
|
|
1176
|
+
if (!toggleOptionsBySelect.value) {
|
|
1177
|
+
const customFilteredOptions = toggleOptionsRestrictor(mouseEvent);
|
|
1178
|
+
|
|
1179
|
+
if (customFilteredOptions) return;
|
|
1180
|
+
}
|
|
1181
|
+
|
|
1182
|
+
const customFilteredCancel = toggleCustomRestrictor(mouseEvent, 2);
|
|
1183
|
+
const customFilteredSelf = toggleCustomRestrictor(mouseEvent, 1);
|
|
1184
|
+
const filteredHasCancel = toggleDetector(mouseEvent, /^extended__multiselect-cancel/i);
|
|
1185
|
+
const filteredHasToggle = toggleDetector(mouseEvent, togglePattern);
|
|
1186
|
+
|
|
1187
|
+
if (customFilteredCancel) return;
|
|
1188
|
+
if (customFilteredSelf && dropdownActive.value === false) return;
|
|
1189
|
+
if (filteredHasCancel.length) return;
|
|
1190
|
+
if (filteredHasToggle.length && dropdownActive.value === false) return;
|
|
1191
|
+
|
|
1192
|
+
emitter.emit("extended:field-focus");
|
|
1193
|
+
};
|
|
1194
|
+
|
|
1195
|
+
/**
|
|
1196
|
+
* Emits event whose listener resets index of "enter" key pressing
|
|
1197
|
+
* @function
|
|
1198
|
+
* @emits extended:reset-index
|
|
1199
|
+
*/
|
|
1200
|
+
const resetEnterIndex = () => {
|
|
1201
|
+
emitter.emit("extended:reset-index");
|
|
1202
|
+
};
|
|
1203
|
+
|
|
1204
|
+
/**
|
|
1205
|
+
* Rolls up dropdown options list
|
|
1206
|
+
* @function
|
|
1207
|
+
* @emits extended:rollup-options
|
|
1208
|
+
*/
|
|
1209
|
+
const rollUp = () => {
|
|
1210
|
+
dropdownActive.value = false;
|
|
1211
|
+
emitter.emit("extended:rollup-options");
|
|
1212
|
+
};
|
|
1213
|
+
|
|
1214
|
+
/**
|
|
1215
|
+
* Triggers selection of option by "enter" key pressing
|
|
1216
|
+
* @function
|
|
1217
|
+
* @emits extended:select-enter
|
|
1218
|
+
* @param {KeyboardEvent} keyboardEvent - KeyboardEvent instance
|
|
1219
|
+
*/
|
|
1220
|
+
const selectByEnter = (keyboardEvent) => {
|
|
1221
|
+
emitter.emit("extended:select-enter", keyboardEvent);
|
|
1222
|
+
};
|
|
1223
|
+
|
|
1224
|
+
/**
|
|
1225
|
+
* Sets preselected option provided by "preselectedOption" prop
|
|
1226
|
+
* @function
|
|
1227
|
+
* @emits extended:select-option
|
|
1228
|
+
*/
|
|
1229
|
+
const setPreselectedOption = () => {
|
|
1230
|
+
const availableOptionType = optionTypeRestrictor(preselectedOption.value);
|
|
1231
|
+
const mappedOptions = restrictedOptions.value.map((restrictedOption) => {
|
|
1232
|
+
return JSON.stringify(restrictedOption);
|
|
1233
|
+
});
|
|
1234
|
+
|
|
1235
|
+
if (!availableOptionType) return;
|
|
1236
|
+
if (!mappedOptions.includes(JSON.stringify(preselectedOption.value)) && showInsertWarnings.value) {
|
|
1237
|
+
console.warn("vue-extended-multiselect: option in «preselectedOption» property should be the same as analogue in «options» property");
|
|
1238
|
+
return;
|
|
1239
|
+
}
|
|
1240
|
+
|
|
1241
|
+
const isObjectOrArray = typeof preselectedOption.value === "object";
|
|
1242
|
+
const label = createLabel(isObjectOrArray, preselectedOption.value);
|
|
1243
|
+
|
|
1244
|
+
emitter.emit("extended:select-option", {
|
|
1245
|
+
label,
|
|
1246
|
+
option: preselectedOption.value,
|
|
1247
|
+
});
|
|
1248
|
+
};
|
|
1249
|
+
|
|
1250
|
+
/**
|
|
1251
|
+
* Sets preselected options provided by "preselectedOptions" prop
|
|
1252
|
+
* if "multiple" prop equals true
|
|
1253
|
+
* @function
|
|
1254
|
+
* @emits extended:select-option
|
|
1255
|
+
*/
|
|
1256
|
+
const setPreselectedOptions = async () => {
|
|
1257
|
+
let allOptionsWereSelected = 0;
|
|
1258
|
+
const mappedOptions = restrictedOptions.value.map((restrictedOption) => {
|
|
1259
|
+
return JSON.stringify(restrictedOption);
|
|
1260
|
+
});
|
|
1261
|
+
|
|
1262
|
+
preselectedOptions.value.forEach((preselectedOption) => {
|
|
1263
|
+
const availableOptionType = optionTypeRestrictor(preselectedOption);
|
|
1264
|
+
|
|
1265
|
+
if (!preselectedOption || !availableOptionType) return;
|
|
1266
|
+
if (selectedOptions.value.includes(preselectedOption)) return;
|
|
1267
|
+
|
|
1268
|
+
if (mappedOptions.includes(JSON.stringify(preselectedOption))) {
|
|
1269
|
+
const isObjectOrArray = typeof option === "object";
|
|
1270
|
+
const label = createLabel(isObjectOrArray, preselectedOption);
|
|
1271
|
+
|
|
1272
|
+
allOptionsWereSelected++;
|
|
1273
|
+
|
|
1274
|
+
emitter.emit("extended:select-option", {
|
|
1275
|
+
label,
|
|
1276
|
+
option: preselectedOption,
|
|
1277
|
+
});
|
|
1278
|
+
}
|
|
1279
|
+
});
|
|
1280
|
+
|
|
1281
|
+
if (allOptionsWereSelected !== preselectedOptions.value.length && showInsertWarnings.value) {
|
|
1282
|
+
console.warn("vue-extended-multiselect: options in «preselectedOptions» property should be the same as analogues in «options» property");
|
|
1283
|
+
}
|
|
1284
|
+
};
|
|
1285
|
+
|
|
1286
|
+
/**
|
|
1287
|
+
* Determines conditions that control preselected options installattion
|
|
1288
|
+
* @function
|
|
1289
|
+
*/
|
|
1290
|
+
const setPreselectedOptionsByConditions = () => {
|
|
1291
|
+
if (preselectedOption.value && !multiple.value) {
|
|
1292
|
+
setPreselectedOption();
|
|
1293
|
+
}
|
|
1294
|
+
|
|
1295
|
+
if (preselectedOptions.value && multiple.value) {
|
|
1296
|
+
setPreselectedOptions();
|
|
1297
|
+
}
|
|
1298
|
+
};
|
|
1299
|
+
|
|
1300
|
+
/**
|
|
1301
|
+
* Defines a position of dropdown appearance
|
|
1302
|
+
* @function
|
|
1303
|
+
* @returns {string} position
|
|
1304
|
+
*/
|
|
1305
|
+
const toggleAppearanceRestrictor = () => {
|
|
1306
|
+
if (!window) return "under";
|
|
1307
|
+
|
|
1308
|
+
const innerHeight = window.innerHeight;
|
|
1309
|
+
const offsetTop = extendedMultiselect.value.getBoundingClientRect().y;
|
|
1310
|
+
const difference = innerHeight - offsetTop;
|
|
1311
|
+
|
|
1312
|
+
if (difference > toggleMaxHeight.value) {
|
|
1313
|
+
return "under";
|
|
1314
|
+
} else {
|
|
1315
|
+
return "atop";
|
|
1316
|
+
}
|
|
1317
|
+
};
|
|
1318
|
+
|
|
1319
|
+
/**
|
|
1320
|
+
* Sets a position of dropdown appearance
|
|
1321
|
+
* @function
|
|
1322
|
+
*/
|
|
1323
|
+
const toggleAppearanceRestrictorActivate = () => {
|
|
1324
|
+
if (!dropdownActive.value) {
|
|
1325
|
+
chosenToggleAppearanceSide.value = toggleAppearanceSide.value !== "auto"
|
|
1326
|
+
? toggleAppearanceSide.value
|
|
1327
|
+
: toggleAppearanceRestrictor();
|
|
1328
|
+
}
|
|
1329
|
+
};
|
|
1330
|
+
|
|
1331
|
+
/**
|
|
1332
|
+
* Restricts toggling of dropdown options list
|
|
1333
|
+
* @function
|
|
1334
|
+
* @emits extended:skip-block-blur
|
|
1335
|
+
* @param {MouseEvent} mouseEvent - MouseEvent instance
|
|
1336
|
+
* @returns {boolean} toggling
|
|
1337
|
+
*/
|
|
1338
|
+
const toggleBlockRestrictor = (mouseEvent) => {
|
|
1339
|
+
let generalRestriction;
|
|
1340
|
+
let filteredCustomSelf;
|
|
1341
|
+
const filteredHasBlock = toggleDetector(mouseEvent, /^extended__multiselect-block/i, true);
|
|
1342
|
+
const filteredSelf = toggleDetector(mouseEvent, /^extended__multiselect-clear/i);
|
|
1343
|
+
|
|
1344
|
+
if (filteredSelf || filteredHasBlock) {
|
|
1345
|
+
filteredCustomSelf = true;
|
|
1346
|
+
} else {
|
|
1347
|
+
filteredCustomSelf = toggleCustomRestrictor(mouseEvent);
|
|
1348
|
+
}
|
|
1349
|
+
|
|
1350
|
+
if (extendedMultiselectToggle.value) {
|
|
1351
|
+
generalRestriction = (filteredHasBlock && dropdownActive.value && filteredCustomSelf)
|
|
1352
|
+
|| (filteredSelf && dropdownActive.value && filteredCustomSelf);
|
|
1353
|
+
} else {
|
|
1354
|
+
generalRestriction = (filteredHasBlock && dropdownActive.value)
|
|
1355
|
+
|| (filteredSelf && dropdownActive.value);
|
|
1356
|
+
}
|
|
1357
|
+
|
|
1358
|
+
if (generalRestriction) {
|
|
1359
|
+
emitter.emit("extended:skip-block-blur");
|
|
1360
|
+
return true;
|
|
1361
|
+
}
|
|
1362
|
+
|
|
1363
|
+
return false;
|
|
1364
|
+
}
|
|
1365
|
+
|
|
1366
|
+
/**
|
|
1367
|
+
* Restricts toggling of dropdown options list by clicking
|
|
1368
|
+
* on particular descendants of toggle wrapper element
|
|
1369
|
+
* @function
|
|
1370
|
+
* @param {MouseEvent} mouseEvent - MouseEvent instance
|
|
1371
|
+
* @param {number} blockType - type of block which needs restriction
|
|
1372
|
+
* @returns {boolean} restriction
|
|
1373
|
+
*/
|
|
1374
|
+
const toggleCustomRestrictor = (mouseEvent, blockType) => {
|
|
1375
|
+
let eventTarget = mouseEvent.target;
|
|
1376
|
+
const toggleWrapper = extendedMultiselect.value;
|
|
1377
|
+
const customToggle = toggleWrapper.children[blockType];
|
|
1378
|
+
|
|
1379
|
+
while(eventTarget) {
|
|
1380
|
+
if (eventTarget === customToggle) return true;
|
|
1381
|
+
|
|
1382
|
+
eventTarget = eventTarget.parentNode;
|
|
1383
|
+
}
|
|
1384
|
+
|
|
1385
|
+
return false;
|
|
1386
|
+
};
|
|
1387
|
+
|
|
1388
|
+
/**
|
|
1389
|
+
* Restricts toggling of dropdown options list by clicking
|
|
1390
|
+
* on particular elements defined by given pattern
|
|
1391
|
+
* @function
|
|
1392
|
+
* @param {MouseEvent} mouseEvent - MouseEvent instance
|
|
1393
|
+
* @param {string} pattern - pattern with block class partial name
|
|
1394
|
+
* @param {boolean} mode - marks whether restrict by parent element or by current target
|
|
1395
|
+
* @returns {Array} classes
|
|
1396
|
+
*/
|
|
1397
|
+
const toggleDetector = (mouseEvent, pattern, mode) => {
|
|
1398
|
+
const target = mouseEvent.target;
|
|
1399
|
+
|
|
1400
|
+
let filteredHasToggle = Array.prototype.filter.call(target.classList, (className) => {
|
|
1401
|
+
return pattern.test(className) === true;
|
|
1402
|
+
});
|
|
1403
|
+
|
|
1404
|
+
if (!filteredHasToggle.length && mode && target.parentNode) {
|
|
1405
|
+
filteredHasToggle = Array.prototype.filter.call(target.parentNode.classList, (className) => {
|
|
1406
|
+
return pattern.test(className) === true;
|
|
1407
|
+
});
|
|
1408
|
+
}
|
|
1409
|
+
|
|
1410
|
+
return filteredHasToggle;
|
|
1411
|
+
};
|
|
1412
|
+
|
|
1413
|
+
/**
|
|
1414
|
+
* Toggles dropdown options list and activates
|
|
1415
|
+
* necessary methods with relevant events
|
|
1416
|
+
* @function
|
|
1417
|
+
*/
|
|
1418
|
+
const toggleOptions = () => {
|
|
1419
|
+
if (internalLoading.value || disabled.value) return;
|
|
1420
|
+
|
|
1421
|
+
toggleAppearanceRestrictorActivate();
|
|
1422
|
+
|
|
1423
|
+
if (!dropdownActive.value) {
|
|
1424
|
+
activeEmitter();
|
|
1425
|
+
} else {
|
|
1426
|
+
closeEmitter();
|
|
1427
|
+
}
|
|
1428
|
+
|
|
1429
|
+
dropdownActive.value = !dropdownActive.value;
|
|
1430
|
+
};
|
|
1431
|
+
|
|
1432
|
+
/**
|
|
1433
|
+
* Prevents toggling dropdown options list
|
|
1434
|
+
* by selecting/deselecting option
|
|
1435
|
+
* @function
|
|
1436
|
+
* @param {MouseEvent} mouseEvent - MouseEvent instance
|
|
1437
|
+
* @returns {boolean} restriction
|
|
1438
|
+
*/
|
|
1439
|
+
const toggleOptionsRestrictor = (mouseEvent) => {
|
|
1440
|
+
let eventTarget = mouseEvent.target;
|
|
1441
|
+
const optionsWrapper = optionsWrapper.value;
|
|
1442
|
+
|
|
1443
|
+
while(eventTarget) {
|
|
1444
|
+
if (eventTarget === optionsWrapper) return true;
|
|
1445
|
+
|
|
1446
|
+
eventTarget = eventTarget.parentNode;
|
|
1447
|
+
}
|
|
1448
|
+
|
|
1449
|
+
return false;
|
|
1450
|
+
};
|
|
1451
|
+
|
|
1452
|
+
/**
|
|
1453
|
+
* Collects restrictions from other methods and defines
|
|
1454
|
+
* general restriction of toggling dropdown options list
|
|
1455
|
+
* @function
|
|
1456
|
+
* @emits extended:skip-blur
|
|
1457
|
+
* @param {MouseEvent} mouseEvent - MouseEvent instance
|
|
1458
|
+
*/
|
|
1459
|
+
const toggleRestrictor = (mouseEvent) => {
|
|
1460
|
+
const targetContentBlock = toggleBlockRestrictor(mouseEvent);
|
|
1461
|
+
|
|
1462
|
+
if (targetContentBlock) return;
|
|
1463
|
+
|
|
1464
|
+
const filteredHasToggle = toggleDetector(mouseEvent, togglePattern);
|
|
1465
|
+
|
|
1466
|
+
if (filteredHasToggle.length && dropdownActive.value) {
|
|
1467
|
+
emitter.emit("extended:skip-blur");
|
|
1468
|
+
}
|
|
1469
|
+
};
|
|
1470
|
+
|
|
1471
|
+
/**
|
|
1472
|
+
* "onBeforeMount" hook of the Vue3ExtendedMultiselect component
|
|
1473
|
+
* @emits select
|
|
1474
|
+
* @emits clean
|
|
1475
|
+
* @emits option-created
|
|
1476
|
+
* @emits increase
|
|
1477
|
+
* @emits pattern-changed
|
|
1478
|
+
* @emits extended:rollup-options
|
|
1479
|
+
* @listens extended:rollup-options
|
|
1480
|
+
* @listens extended:toggle-options
|
|
1481
|
+
* @listens extended:select-option
|
|
1482
|
+
* @listens extended:deselect-option
|
|
1483
|
+
* @listens extended:clean-options
|
|
1484
|
+
* @listens extended:create-option
|
|
1485
|
+
* @listens extended:increase-display
|
|
1486
|
+
* @listens extended:search-pattern-changed
|
|
1487
|
+
*/
|
|
1488
|
+
onBeforeMount(() => {
|
|
1489
|
+
chosenToggleAppearanceSide.value = toggleAppearanceSide.value;
|
|
1490
|
+
|
|
1491
|
+
emitter.on("extended:rollup-options", () => {
|
|
1492
|
+
if (!dropdownActive.value) return;
|
|
1493
|
+
|
|
1494
|
+
closeEmitter();
|
|
1495
|
+
dropdownActive.value = false;
|
|
1496
|
+
});
|
|
1497
|
+
|
|
1498
|
+
emitter.on("extended:toggle-options", () => {
|
|
1499
|
+
toggleOptions();
|
|
1500
|
+
});
|
|
1501
|
+
|
|
1502
|
+
emitter.on("extended:select-option", (option) => {
|
|
1503
|
+
const eventData = simpleEvents.value
|
|
1504
|
+
? option.option
|
|
1505
|
+
: createEventFields(option.option, "option");
|
|
1506
|
+
|
|
1507
|
+
if (multiple.value) {
|
|
1508
|
+
selectedOptions.value.push(option.option);
|
|
1509
|
+
/**
|
|
1510
|
+
* @event select
|
|
1511
|
+
* @type {Object}
|
|
1512
|
+
* @property {string} inputId - id of search field set by "id" prop
|
|
1513
|
+
* @property {UnionPropType} option - just now selected option
|
|
1514
|
+
*/
|
|
1515
|
+
emit("select", eventData);
|
|
1516
|
+
} else {
|
|
1517
|
+
selectedOptions.value = [option.option];
|
|
1518
|
+
/**
|
|
1519
|
+
* @see select
|
|
1520
|
+
*/
|
|
1521
|
+
emit("select", eventData);
|
|
1522
|
+
}
|
|
1523
|
+
});
|
|
1524
|
+
|
|
1525
|
+
emitter.on("extended:deselect-option", (index = null, clearAll) => {
|
|
1526
|
+
if (multiple.value && !clearAll) {
|
|
1527
|
+
const deselectedOption = selectedOptions.value[index];
|
|
1528
|
+
|
|
1529
|
+
const eventData = simpleEvents.value
|
|
1530
|
+
? deselectedOption
|
|
1531
|
+
: createEventFields(deselectedOption, "option");
|
|
1532
|
+
|
|
1533
|
+
/**
|
|
1534
|
+
* @event clean
|
|
1535
|
+
* @type {Object}
|
|
1536
|
+
* @property {string} inputId - id of search field set by "id" prop
|
|
1537
|
+
* @property {UnionPropType} option - just now deselected option
|
|
1538
|
+
*/
|
|
1539
|
+
emit("clean", eventData);
|
|
1540
|
+
|
|
1541
|
+
selectedOptions.value.splice(index, 1);
|
|
1542
|
+
return;
|
|
1543
|
+
} else {
|
|
1544
|
+
selectedOptions.value = [];
|
|
1545
|
+
}
|
|
1546
|
+
|
|
1547
|
+
emitter.emit("extended:rollup-options");
|
|
1548
|
+
});
|
|
1549
|
+
|
|
1550
|
+
emitter.on("extended:clean-options", (selectedOptions) => {
|
|
1551
|
+
const eventData = simpleEvents.value
|
|
1552
|
+
? selectedOptions.value
|
|
1553
|
+
: createEventFields(selectedOptions, "options");
|
|
1554
|
+
|
|
1555
|
+
/**
|
|
1556
|
+
* @see clean
|
|
1557
|
+
* @property {Array} options - just now deselected options
|
|
1558
|
+
*/
|
|
1559
|
+
emit("clean", eventData);
|
|
1560
|
+
});
|
|
1561
|
+
|
|
1562
|
+
emitter.on("extended:create-option", (createdOption) => {
|
|
1563
|
+
const eventData = simpleEvents.value
|
|
1564
|
+
? createdOption
|
|
1565
|
+
: createEventFields(createdOption, "option");
|
|
1566
|
+
|
|
1567
|
+
/**
|
|
1568
|
+
* @event option-created
|
|
1569
|
+
* @type {PluginObject}
|
|
1570
|
+
* @property {string} inputId - id of search field set by "id" prop
|
|
1571
|
+
* @property {UnionPropType} option - option created by user
|
|
1572
|
+
*/
|
|
1573
|
+
emit("option-created", eventData);
|
|
1574
|
+
});
|
|
1575
|
+
|
|
1576
|
+
emitter.on("extended:increase-display", (limit) => {
|
|
1577
|
+
const eventData = simpleEvents.value ? limit : createEventFields(limit, "limit");
|
|
1578
|
+
|
|
1579
|
+
/**
|
|
1580
|
+
* @event increase
|
|
1581
|
+
* @type {Object}
|
|
1582
|
+
* @property {string} inputId - id of search field set by "id" prop
|
|
1583
|
+
* @property {limit} - current limit of options to be shown next
|
|
1584
|
+
*/
|
|
1585
|
+
emit("increase", eventData);
|
|
1586
|
+
});
|
|
1587
|
+
|
|
1588
|
+
emitter.on("extended:search-pattern-changed", (pattern) => {
|
|
1589
|
+
const eventData = simpleEvents.value
|
|
1590
|
+
? pattern
|
|
1591
|
+
: createEventFields(pattern, "pattern");
|
|
1592
|
+
|
|
1593
|
+
/**
|
|
1594
|
+
* @event pattern-changed
|
|
1595
|
+
* @type {Object}
|
|
1596
|
+
* @property {string} inputId - id of search field set by "id" prop
|
|
1597
|
+
* @property {pattern} - pattern of internal search for available options
|
|
1598
|
+
*/
|
|
1599
|
+
emit("pattern-changed", eventData);
|
|
1600
|
+
});
|
|
1601
|
+
});
|
|
1602
|
+
|
|
1603
|
+
/**
|
|
1604
|
+
* "onMounted" hook of the Vue3ExtendedMultiselect component
|
|
1605
|
+
* @emits extended:rollup-options
|
|
1606
|
+
* @listens extended:expand-options
|
|
1607
|
+
*/
|
|
1608
|
+
onMounted(() => {
|
|
1609
|
+
if (typeof options.value === "function") {
|
|
1610
|
+
internalLoader.value = true;
|
|
1611
|
+
options.value().then(options => {
|
|
1612
|
+
rawOptions.value = options;
|
|
1613
|
+
internalLoader.value = false;
|
|
1614
|
+
setPreselectedOptionsByConditions();
|
|
1615
|
+
});
|
|
1616
|
+
} else {
|
|
1617
|
+
rawOptions.value = options.value;
|
|
1618
|
+
setPreselectedOptionsByConditions();
|
|
1619
|
+
}
|
|
1620
|
+
|
|
1621
|
+
const root = extendedMultiselectWrapper.value;
|
|
1622
|
+
|
|
1623
|
+
clickOutside(root, () => {
|
|
1624
|
+
emitter.emit("extended:rollup-options");
|
|
1625
|
+
});
|
|
1626
|
+
|
|
1627
|
+
if (
|
|
1628
|
+
defaultExpanded.value
|
|
1629
|
+
&& !inputDisabled.value
|
|
1630
|
+
&& !internalLoading.value
|
|
1631
|
+
&& typeof options.value !== "function"
|
|
1632
|
+
) {
|
|
1633
|
+
dropdownActive.value = true;
|
|
1634
|
+
}
|
|
1635
|
+
|
|
1636
|
+
emitter.on("extended:expand-options", () => {
|
|
1637
|
+
if (dropdownActive.value === true) return;
|
|
1638
|
+
|
|
1639
|
+
toggleAppearanceRestrictorActivate();
|
|
1640
|
+
activeEmitter();
|
|
1641
|
+
|
|
1642
|
+
dropdownActive.value = true;
|
|
1643
|
+
});
|
|
1644
|
+
});
|
|
1645
|
+
</script>
|
|
1646
|
+
|
|
1647
|
+
<style>
|
|
1648
|
+
|
|
1649
|
+
@import "../styles/main.css";
|
|
1650
|
+
|
|
1651
|
+
</style>
|