vue3-extended-multiselect 1.0.0 → 1.1.2

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.
Files changed (41) hide show
  1. package/.eslintrc.js +34 -34
  2. package/.github/workflows/publish.yml +41 -41
  3. package/CHANGELOG.md +109 -91
  4. package/LICENSE +21 -21
  5. package/README.md +261 -261
  6. package/index.js +2 -2
  7. package/jest.config.js +60 -57
  8. package/package.json +47 -47
  9. package/src/assets/base-arrow.svg +70 -70
  10. package/src/assets/cancel.svg +34 -34
  11. package/src/assets/circle-arrow.svg +7 -7
  12. package/src/assets/double-arrow.svg +39 -39
  13. package/src/assets/inner-arrow.svg +8 -8
  14. package/src/assets/loader.svg +5 -5
  15. package/src/assets/triangle-arrow.svg +72 -72
  16. package/src/assets/triangle-circle-arrow.svg +38 -38
  17. package/src/assets/wide-arrow.svg +72 -72
  18. package/src/components/ExtendedMultiselectCancel.vue +148 -148
  19. package/src/components/ExtendedMultiselectInput.vue +617 -617
  20. package/src/components/ExtendedMultiselectLoader.vue +182 -182
  21. package/src/components/ExtendedMultiselectMultiple.vue +295 -295
  22. package/src/components/ExtendedMultiselectOptions.vue +1092 -1091
  23. package/src/components/ExtendedMultiselectToggle.vue +261 -261
  24. package/src/components/Vue3ExtendedMultiselect.vue +1665 -1660
  25. package/src/composition/cancel.js +33 -33
  26. package/src/composition/image-path.js +16 -16
  27. package/src/composition/labels.js +39 -39
  28. package/src/composition/preselected-options.js +66 -66
  29. package/src/composition/search-value.js +33 -33
  30. package/src/composition/sizes.js +42 -42
  31. package/src/composition/toggle.js +33 -33
  32. package/src/events/emitter.js +2 -2
  33. package/src/sets/sets.js +99 -99
  34. package/src/styles/animations.css +18 -18
  35. package/src/styles/main.css +433 -432
  36. package/src/styles/variables.css +47 -47
  37. package/tests/unit/events.spec.js +135 -135
  38. package/tests/unit/props.spec.js +1040 -1040
  39. package/tests/utils/mount.js +37 -37
  40. package/tests/utils/utils.js +20 -20
  41. package/typings/vue3-extended-multiselect.d.ts +42 -42
@@ -1,1661 +1,1666 @@
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 "../events/emitter";
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(
898
- loading,
899
- disabled,
900
- internalLoader,
901
- );
902
- const { cancel } = useCancel(
903
- disabled,
904
- showSearchField,
905
- selectedOptions,
906
- );
907
- const { createLabel, optionTypeRestrictor } = usePreselectedOptions(
908
- label,
909
- emptyObjectsPlaceholder,
910
- showInsertWarnings,
911
- );
912
- const attrs = useAttrs();
913
- const slots = useSlots();
914
-
915
- /**
916
- * Defines a list of extended multiselect wrapper classes
917
- * @function
918
- * @returns {Array} classes
919
- */
920
- const classes = computed(() => {
921
- let theme;
922
- const localClassList = [];
923
-
924
- switch(themeType.value) {
925
- case "basic":
926
- theme = "extended__multiselect";
927
- break;
928
- case "slate-grey":
929
- theme = "extended__multiselect-slate-grey";
930
- break;
931
- case "slate-blue":
932
- theme = "extended__multiselect-slate-blue";
933
- break;
934
- case "teal":
935
- theme = "extended__multiselect-teal";
936
- break;
937
- case "strict":
938
- theme = "extended__multiselect-strict";
939
- break;
940
- default: return ["extended__multiselect"];
941
- }
942
-
943
- localClassList.push(theme);
944
-
945
- const clear = showClearIcon.value
946
- ? "extended__multiselect-clear--active"
947
- : "extended__multiselect-clear--locked";
948
-
949
- localClassList.push(clear);
950
-
951
- return localClassList;
952
- });
953
-
954
- /**
955
- * Defines a list of disabled options by types given in "disabledPrimitiveOptions" prop
956
- * @function
957
- * @returns {Array} options
958
- */
959
- const disabledPrimitiveOptionsConverted = computed(() => {
960
- if (!disabledPrimitiveOptions.value) return null;
961
-
962
- return disabledPrimitiveOptions.value.map((disabledOption) => {
963
- if (Array.isArray(disabledOption)) {
964
- if (!disabledOption.length) return emptyObjectsPlaceholder.value;
965
-
966
- return disabledOption.join(", ");
967
- }
968
-
969
- return disabledOption;
970
- });
971
- });
972
-
973
- /**
974
- * Determines whether to display irregularity of value by "border-color" css-property
975
- * @function
976
- * @returns {Object|null} styles
977
- */
978
- const displayWrongValue = computed(() => {
979
- return wrongCurrentValue.value ? { borderColor: errorBorderColor.value } : null;
980
- });
981
-
982
- /**
983
- * Defines styles depending on current options list dropdown state
984
- * @function
985
- * @returns {Object|null} styles
986
- */
987
- const expanded = computed(() => {
988
- let borderStyles;
989
-
990
- if (chosenToggleAppearanceSide.value === "atop") {
991
- borderStyles = {
992
- borderTopLeftRadius: 0,
993
- borderTopRightRadius: 0,
994
- transition: "border-top-left-radius 250ms, border-top-right-radius 250ms",
995
- };
996
- } else {
997
- borderStyles = {
998
- borderBottomLeftRadius: 0,
999
- borderBottomRightRadius: 0,
1000
- transition: "border-bottom-left-radius 250ms, border-bottom-right-radius 250ms",
1001
- };
1002
- }
1003
-
1004
- return dropdownActive.value ? borderStyles : null;
1005
- });
1006
-
1007
- /**
1008
- * Determines whether to activate loading state by "loading" prop
1009
- * or by internal loading sign
1010
- * @function
1011
- * @returns {boolean} loading
1012
- */
1013
- const internalLoading = computed(() => {
1014
- return loading.value || internalLoader.value;
1015
- });
1016
-
1017
- /**
1018
- * Defines a list of options filtered by maximal admissible options amount
1019
- * @function
1020
- * @returns {Array} options
1021
- */
1022
- const restrictedOptions = computed(() => {
1023
- return optionsCountRestriction.value
1024
- ? rawOptions.value.filter((option, index) => index + 1 <= optionsCountRestriction.value)
1025
- : rawOptions.value;
1026
- });
1027
-
1028
- /**
1029
- * Determines length of options list after filtering by
1030
- * maximal admissible options amount
1031
- * @function
1032
- * @returns {number} length
1033
- */
1034
- const restrictedOptionsLength = computed(() => {
1035
- return restrictedOptions.value.length;
1036
- });
1037
-
1038
- /**
1039
- * Defines "aria-roledescription" attribute of extended multiselect wrapper
1040
- * @function
1041
- * @returns {string} aria-roledescription
1042
- */
1043
- const roledescription = computed(() => {
1044
- return multiple.value ? "Multiselect" : "Select";
1045
- });
1046
-
1047
- /**
1048
- * Defines "tabindex" attribute of extended multiselect wrapper if needed
1049
- * @function
1050
- * @returns {number} tabindex
1051
- */
1052
- const tabindexIfSearch = computed(() => {
1053
- return showSearchField.value ? attrs.tabindex : -1;
1054
- });
1055
-
1056
- /**
1057
- * Defines special class which indicates disabled or loading state
1058
- * of extended multiselect wrapper
1059
- * @function
1060
- * @returns {string} class
1061
- */
1062
- const wrapperClasses = computed(() => {
1063
- return inputDisabled.value && !internalLoading.value
1064
- ? "extended__multiselect-wrapper--disabled"
1065
- : "extended__multiselect-wrapper";
1066
- });
1067
-
1068
- /**
1069
- * Disables search field if "disabled" prop equals true
1070
- * @function
1071
- * @param {boolean} value - "disabled" prop
1072
- */
1073
- watch(disabled, (value) => {
1074
- inputDisabled.value = value;
1075
- }, { immediate: true });
1076
-
1077
- /**
1078
- * Forcibly rolls up dropdown options list by changing "dropdownActive" flag
1079
- * @function
1080
- * @emits extended:rollup-options
1081
- * @param {boolean} value - "dropdownActive" flag
1082
- */
1083
- watch(dropdownActive, (value) => {
1084
- if (!value) {
1085
- emitter.emit("extended:rollup-options");
1086
- }
1087
- });
1088
-
1089
- /**
1090
- * Disables search field if "loading" prop equals true
1091
- * @function
1092
- * @param {boolean} value - "loading" prop
1093
- */
1094
- watch(internalLoading, (value) => {
1095
- if (disabled.value) return;
1096
-
1097
- inputDisabled.value = value;
1098
- }, { immediate: true });
1099
-
1100
- /**
1101
- * Clears value of search field after changing selected option/options
1102
- * if "resetSearchByValue" prop equals true
1103
- * @function
1104
- * @emits extended:clear-field
1105
- */
1106
- watch(selectedOptions, (value) => {
1107
- if (multiple.value) {
1108
- emit("update:modelValue", value);
1109
- } else {
1110
- emit("update:modelValue", value[0]);
1111
- }
1112
-
1113
- if (resetSearchByValue.value) {
1114
- emitter.emit("extended:clear-field");
1115
- }
1116
- }, { deep: true });
1117
-
1118
- /**
1119
- * Emits "active" when dropdown options list is active
1120
- * @function
1121
- * @emits active
1122
- */
1123
- const activeEmitter = () => {
1124
- const eventData = simpleEvents.value ? null : {
1125
- inputId: inputId.value,
1126
- };
1127
-
1128
- /**
1129
- * @event active
1130
- * @type {object|null}
1131
- * @property {string} inputId - id of search field set by "id" prop
1132
- */
1133
- emit("active", eventData);
1134
- };
1135
-
1136
- /**
1137
- * Emits "close" when dropdown options list is rolled up
1138
- * @function
1139
- * @emits close
1140
- */
1141
- const closeEmitter = () => {
1142
- const eventData = simpleEvents.value
1143
- ? selectedOptions.value
1144
- : createEventFields(selectedOptions.value, "options");
1145
-
1146
- /**
1147
- * @event close
1148
- * @type {object|Array}
1149
- * @property {string} inputId - id of search field set by "id" prop
1150
- * @property {Array} options - array of selected options
1151
- */
1152
- emit("close", eventData);
1153
- }
1154
-
1155
- /**
1156
- * Creates payload for events that can be listened by outer listeners
1157
- * @function
1158
- * @param {UnionPropType} field - main payload of event
1159
- * @param {string} fieldName - name of field with main payload of event
1160
- * @returns {object} payload
1161
- */
1162
- const createEventFields = (field, fieldName) => {
1163
- const eventFields = {
1164
- inputId: inputId.value,
1165
- };
1166
-
1167
- Object.defineProperty(eventFields, fieldName, {
1168
- value: field,
1169
- enumerable: true,
1170
- });
1171
-
1172
- return eventFields;
1173
- };
1174
-
1175
- /**
1176
- * Focuses search field if "click" native event was triggered on available element
1177
- * @function
1178
- * @emits extended:field-focus
1179
- * @param {MouseEvent} mouseEvent - MouseEvent instance
1180
- */
1181
- const fieldFocus = (mouseEvent) => {
1182
- if (internalLoading.value || disabled.value) return;
1183
-
1184
- if (!toggleOptionsBySelect.value && typeof options.value !== "function") {
1185
- const customFilteredOptions = toggleOptionsRestrictor(mouseEvent);
1186
-
1187
- if (customFilteredOptions) return;
1188
- }
1189
-
1190
- const customFilteredCancel = toggleCustomRestrictor(mouseEvent, 2);
1191
- const customFilteredSelf = toggleCustomRestrictor(mouseEvent, 1);
1192
- const filteredHasCancel = toggleDetector(mouseEvent, /^extended__multiselect-cancel/i);
1193
- const filteredHasToggle = toggleDetector(mouseEvent, togglePattern);
1194
-
1195
- if (customFilteredCancel) return;
1196
- if (customFilteredSelf && dropdownActive.value === false) return;
1197
- if (filteredHasCancel.length) return;
1198
- if (filteredHasToggle.length && dropdownActive.value === false) return;
1199
-
1200
- emitter.emit("extended:field-focus");
1201
- };
1202
-
1203
- /**
1204
- * Emits event whose listener resets index of "enter" key pressing
1205
- * @function
1206
- * @emits extended:reset-index
1207
- */
1208
- const resetEnterIndex = () => {
1209
- emitter.emit("extended:reset-index");
1210
- };
1211
-
1212
- /**
1213
- * Rolls up dropdown options list
1214
- * @function
1215
- * @emits extended:rollup-options
1216
- */
1217
- const rollUp = () => {
1218
- dropdownActive.value = false;
1219
- emitter.emit("extended:rollup-options");
1220
- };
1221
-
1222
- /**
1223
- * Triggers selection of option by "enter" key pressing
1224
- * @function
1225
- * @emits extended:select-enter
1226
- * @param {KeyboardEvent} keyboardEvent - KeyboardEvent instance
1227
- */
1228
- const selectByEnter = (keyboardEvent) => {
1229
- emitter.emit("extended:select-enter", keyboardEvent);
1230
- };
1231
-
1232
- /**
1233
- * Sets preselected option provided by "preselectedOption" prop
1234
- * @function
1235
- * @emits extended:select-option
1236
- */
1237
- const setPreselectedOption = () => {
1238
- const availableOptionType = optionTypeRestrictor(preselectedOption.value);
1239
- const mappedOptions = restrictedOptions.value.map((restrictedOption) => {
1240
- return JSON.stringify(restrictedOption);
1241
- });
1242
-
1243
- if (!availableOptionType) return;
1244
- if (!mappedOptions.includes(JSON.stringify(preselectedOption.value)) && showInsertWarnings.value) {
1245
- console.warn("vue-extended-multiselect: option in «preselectedOption» property should be the same as analogue in «options» property");
1246
- return;
1247
- }
1248
-
1249
- const isObjectOrArray = typeof preselectedOption.value === "object";
1250
- const label = createLabel(isObjectOrArray, preselectedOption.value);
1251
-
1252
- emitter.emit("extended:select-option", {
1253
- label,
1254
- option: preselectedOption.value,
1255
- });
1256
- };
1257
-
1258
- /**
1259
- * Sets preselected options provided by "preselectedOptions" prop
1260
- * if "multiple" prop equals true
1261
- * @function
1262
- * @emits extended:select-option
1263
- */
1264
- const setPreselectedOptions = async () => {
1265
- let allOptionsWereSelected = 0;
1266
- const mappedOptions = restrictedOptions.value.map((restrictedOption) => {
1267
- return JSON.stringify(restrictedOption);
1268
- });
1269
-
1270
- preselectedOptions.value.forEach((preselectedOption) => {
1271
- const availableOptionType = optionTypeRestrictor(preselectedOption);
1272
-
1273
- if (!preselectedOption || !availableOptionType) return;
1274
- if (selectedOptions.value.includes(preselectedOption)) return;
1275
-
1276
- if (mappedOptions.includes(JSON.stringify(preselectedOption))) {
1277
- const isObjectOrArray = typeof option === "object";
1278
- const label = createLabel(isObjectOrArray, preselectedOption);
1279
-
1280
- allOptionsWereSelected++;
1281
-
1282
- emitter.emit("extended:select-option", {
1283
- label,
1284
- option: preselectedOption,
1285
- });
1286
- }
1287
- });
1288
-
1289
- if (allOptionsWereSelected !== preselectedOptions.value.length && showInsertWarnings.value) {
1290
- console.warn("vue-extended-multiselect: options in «preselectedOptions» property should be the same as analogues in «options» property");
1291
- }
1292
- };
1293
-
1294
- /**
1295
- * Determines conditions that control preselected options installattion
1296
- * @function
1297
- */
1298
- const setPreselectedOptionsByConditions = () => {
1299
- if (preselectedOption.value && !multiple.value) {
1300
- setPreselectedOption();
1301
- }
1302
-
1303
- if (preselectedOptions.value && multiple.value) {
1304
- setPreselectedOptions();
1305
- }
1306
- };
1307
-
1308
- /**
1309
- * Defines a position of dropdown appearance
1310
- * @function
1311
- * @returns {string} position
1312
- */
1313
- const toggleAppearanceRestrictor = () => {
1314
- if (!window) return "under";
1315
-
1316
- const innerHeight = window.innerHeight;
1317
- const offsetTop = extendedMultiselect.value.getBoundingClientRect().y;
1318
- const difference = innerHeight - offsetTop;
1319
-
1320
- if (difference > toggleMaxHeight.value) {
1321
- return "under";
1322
- } else {
1323
- return "atop";
1324
- }
1325
- };
1326
-
1327
- /**
1328
- * Sets a position of dropdown appearance
1329
- * @function
1330
- */
1331
- const toggleAppearanceRestrictorActivate = () => {
1332
- if (!dropdownActive.value) {
1333
- chosenToggleAppearanceSide.value = toggleAppearanceSide.value !== "auto"
1334
- ? toggleAppearanceSide.value
1335
- : toggleAppearanceRestrictor();
1336
- }
1337
- };
1338
-
1339
- /**
1340
- * Restricts toggling of dropdown options list
1341
- * @function
1342
- * @emits extended:skip-block-blur
1343
- * @param {MouseEvent} mouseEvent - MouseEvent instance
1344
- * @returns {boolean} toggling
1345
- */
1346
- const toggleBlockRestrictor = (mouseEvent) => {
1347
- let generalRestriction;
1348
- let filteredCustomSelf;
1349
- const filteredHasBlock = toggleDetector(mouseEvent, /^extended__multiselect-block/i, true);
1350
- const filteredSelf = toggleDetector(mouseEvent, /^extended__multiselect-clear/i);
1351
-
1352
- if (filteredSelf || filteredHasBlock) {
1353
- filteredCustomSelf = true;
1354
- } else {
1355
- filteredCustomSelf = toggleCustomRestrictor(mouseEvent);
1356
- }
1357
-
1358
- if (extendedMultiselectToggle.value) {
1359
- generalRestriction = (filteredHasBlock && dropdownActive.value && filteredCustomSelf)
1360
- || (filteredSelf && dropdownActive.value && filteredCustomSelf);
1361
- } else {
1362
- generalRestriction = (filteredHasBlock && dropdownActive.value)
1363
- || (filteredSelf && dropdownActive.value);
1364
- }
1365
-
1366
- if (generalRestriction) {
1367
- emitter.emit("extended:skip-block-blur");
1368
- return true;
1369
- }
1370
-
1371
- return false;
1372
- }
1373
-
1374
- /**
1375
- * Restricts toggling of dropdown options list by clicking
1376
- * on particular descendants of toggle wrapper element
1377
- * @function
1378
- * @param {MouseEvent} mouseEvent - MouseEvent instance
1379
- * @param {number} blockType - type of block which needs restriction
1380
- * @returns {boolean} restriction
1381
- */
1382
- const toggleCustomRestrictor = (mouseEvent, blockType) => {
1383
- let eventTarget = mouseEvent.target;
1384
- const toggleWrapper = extendedMultiselect.value;
1385
- const customToggle = toggleWrapper.children[blockType];
1386
-
1387
- while(eventTarget) {
1388
- if (eventTarget === customToggle) return true;
1389
-
1390
- eventTarget = eventTarget.parentNode;
1391
- }
1392
-
1393
- return false;
1394
- };
1395
-
1396
- /**
1397
- * Restricts toggling of dropdown options list by clicking
1398
- * on particular elements defined by given pattern
1399
- * @function
1400
- * @param {MouseEvent} mouseEvent - MouseEvent instance
1401
- * @param {string} pattern - pattern with block class partial name
1402
- * @param {boolean} mode - marks whether restrict by parent element or by current target
1403
- * @returns {Array} classes
1404
- */
1405
- const toggleDetector = (mouseEvent, pattern, mode) => {
1406
- const target = mouseEvent.target;
1407
-
1408
- let filteredHasToggle = Array.prototype.filter.call(target.classList, (className) => {
1409
- return pattern.test(className) === true;
1410
- });
1411
-
1412
- if (!filteredHasToggle.length && mode && target.parentNode) {
1413
- filteredHasToggle = Array.prototype.filter.call(target.parentNode.classList, (className) => {
1414
- return pattern.test(className) === true;
1415
- });
1416
- }
1417
-
1418
- return filteredHasToggle;
1419
- };
1420
-
1421
- /**
1422
- * Toggles dropdown options list and activates
1423
- * necessary methods with relevant events
1424
- * @function
1425
- */
1426
- const toggleOptions = () => {
1427
- if (internalLoading.value || disabled.value) return;
1428
-
1429
- toggleAppearanceRestrictorActivate();
1430
-
1431
- if (!dropdownActive.value) {
1432
- activeEmitter();
1433
- } else {
1434
- closeEmitter();
1435
- }
1436
-
1437
- dropdownActive.value = !dropdownActive.value;
1438
- };
1439
-
1440
- /**
1441
- * Prevents toggling dropdown options list
1442
- * by selecting/deselecting option
1443
- * @function
1444
- * @param {MouseEvent} mouseEvent - MouseEvent instance
1445
- * @returns {boolean} restriction
1446
- */
1447
- const toggleOptionsRestrictor = (mouseEvent) => {
1448
- if (!optionsWrapper.value) return false;
1449
-
1450
- let eventTarget = mouseEvent.target;
1451
- const optionsWrapper = optionsWrapper.value;
1452
-
1453
- while(eventTarget) {
1454
- if (eventTarget === optionsWrapper) return true;
1455
-
1456
- eventTarget = eventTarget.parentNode;
1457
- }
1458
-
1459
- return false;
1460
- };
1461
-
1462
- /**
1463
- * Collects restrictions from other methods and defines
1464
- * general restriction of toggling dropdown options list
1465
- * @function
1466
- * @emits extended:skip-blur
1467
- * @param {MouseEvent} mouseEvent - MouseEvent instance
1468
- */
1469
- const toggleRestrictor = (mouseEvent) => {
1470
- const targetContentBlock = toggleBlockRestrictor(mouseEvent);
1471
-
1472
- if (targetContentBlock) return;
1473
-
1474
- const filteredHasToggle = toggleDetector(mouseEvent, togglePattern);
1475
-
1476
- if (filteredHasToggle.length && dropdownActive.value) {
1477
- emitter.emit("extended:skip-blur");
1478
- }
1479
- };
1480
-
1481
- /**
1482
- * "onBeforeMount" hook of the Vue3ExtendedMultiselect component
1483
- * @emits select
1484
- * @emits clean
1485
- * @emits option-created
1486
- * @emits increase
1487
- * @emits pattern-changed
1488
- * @emits extended:rollup-options
1489
- * @listens extended:rollup-options
1490
- * @listens extended:toggle-options
1491
- * @listens extended:select-option
1492
- * @listens extended:deselect-option
1493
- * @listens extended:clean-options
1494
- * @listens extended:create-option
1495
- * @listens extended:increase-display
1496
- * @listens extended:search-pattern-changed
1497
- */
1498
- onBeforeMount(() => {
1499
- chosenToggleAppearanceSide.value = toggleAppearanceSide.value;
1500
-
1501
- emitter.on("extended:rollup-options", () => {
1502
- if (!dropdownActive.value) return;
1503
-
1504
- closeEmitter();
1505
- dropdownActive.value = false;
1506
- });
1507
-
1508
- emitter.on("extended:toggle-options", () => {
1509
- toggleOptions();
1510
- });
1511
-
1512
- emitter.on("extended:select-option", (option) => {
1513
- const eventData = simpleEvents.value
1514
- ? option.option
1515
- : createEventFields(option.option, "option");
1516
-
1517
- if (multiple.value) {
1518
- selectedOptions.value.push(option.option);
1519
- /**
1520
- * @event select
1521
- * @type {Object}
1522
- * @property {string} inputId - id of search field set by "id" prop
1523
- * @property {UnionPropType} option - just now selected option
1524
- */
1525
- emit("select", eventData);
1526
- } else {
1527
- selectedOptions.value = [option.option];
1528
- /**
1529
- * @see select
1530
- */
1531
- emit("select", eventData);
1532
- }
1533
- });
1534
-
1535
- emitter.on("extended:deselect-option", (payload) => {
1536
- if (multiple.value && (payload && !payload.clearAll)) {
1537
- const deselectedOption = selectedOptions.value[payload.index];
1538
-
1539
- const eventData = simpleEvents.value
1540
- ? deselectedOption
1541
- : createEventFields(deselectedOption, "option");
1542
-
1543
- /**
1544
- * @event clean
1545
- * @type {Object}
1546
- * @property {string} inputId - id of search field set by "id" prop
1547
- * @property {UnionPropType} option - just now deselected option
1548
- */
1549
- emit("clean", eventData);
1550
-
1551
- selectedOptions.value.splice(payload.index, 1);
1552
- return;
1553
- } else {
1554
- selectedOptions.value = [];
1555
- }
1556
-
1557
- emitter.emit("extended:rollup-options");
1558
- });
1559
-
1560
- emitter.on("extended:clean-options", (selectedOptions) => {
1561
- const eventData = simpleEvents.value
1562
- ? selectedOptions.value
1563
- : createEventFields(selectedOptions, "options");
1564
-
1565
- /**
1566
- * @see clean
1567
- * @property {Array} options - just now deselected options
1568
- */
1569
- emit("clean", eventData);
1570
- });
1571
-
1572
- emitter.on("extended:create-option", (createdOption) => {
1573
- const eventData = simpleEvents.value
1574
- ? createdOption
1575
- : createEventFields(createdOption, "option");
1576
-
1577
- /**
1578
- * @event option-created
1579
- * @type {PluginObject}
1580
- * @property {string} inputId - id of search field set by "id" prop
1581
- * @property {UnionPropType} option - option created by user
1582
- */
1583
- emit("option-created", eventData);
1584
- });
1585
-
1586
- emitter.on("extended:increase-display", (limit) => {
1587
- const eventData = simpleEvents.value ? limit : createEventFields(limit, "limit");
1588
-
1589
- /**
1590
- * @event increase
1591
- * @type {Object}
1592
- * @property {string} inputId - id of search field set by "id" prop
1593
- * @property {limit} - current limit of options to be shown next
1594
- */
1595
- emit("increase", eventData);
1596
- });
1597
-
1598
- emitter.on("extended:search-pattern-changed", (pattern) => {
1599
- const eventData = simpleEvents.value
1600
- ? pattern
1601
- : createEventFields(pattern, "pattern");
1602
-
1603
- /**
1604
- * @event pattern-changed
1605
- * @type {Object}
1606
- * @property {string} inputId - id of search field set by "id" prop
1607
- * @property {pattern} - pattern of internal search for available options
1608
- */
1609
- emit("pattern-changed", eventData);
1610
- });
1611
- });
1612
-
1613
- /**
1614
- * "onMounted" hook of the Vue3ExtendedMultiselect component
1615
- * @emits extended:rollup-options
1616
- * @listens extended:expand-options
1617
- */
1618
- onMounted(() => {
1619
- if (typeof options.value === "function") {
1620
- internalLoader.value = true;
1621
- options.value().then(options => {
1622
- rawOptions.value = options;
1623
- internalLoader.value = false;
1624
- setPreselectedOptionsByConditions();
1625
- });
1626
- } else {
1627
- rawOptions.value = options.value;
1628
- setPreselectedOptionsByConditions();
1629
- }
1630
-
1631
- const root = extendedMultiselectWrapper.value;
1632
-
1633
- clickOutside(root, () => {
1634
- emitter.emit("extended:rollup-options");
1635
- });
1636
-
1637
- if (
1638
- defaultExpanded.value
1639
- && !inputDisabled.value
1640
- && !internalLoading.value
1641
- && typeof options.value !== "function"
1642
- ) {
1643
- dropdownActive.value = true;
1644
- }
1645
-
1646
- emitter.on("extended:expand-options", () => {
1647
- if (dropdownActive.value === true) return;
1648
-
1649
- toggleAppearanceRestrictorActivate();
1650
- activeEmitter();
1651
-
1652
- dropdownActive.value = true;
1653
- });
1654
- });
1655
- </script>
1656
-
1657
- <style>
1658
-
1659
- @import "../styles/main.css";
1660
-
1
+ <template>
2
+ <section
3
+ aria-owns="extended-search-field"
4
+ role="combobox"
5
+ :aria-roledescription="roledescription"
6
+ :class="wrapperClasses"
7
+ :tabindex="tabindexIfSearch"
8
+ v-click-outside="clickOutside"
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 { directive as vClickOutside } from "vue3-click-away";
220
+ import emitter from "../events/emitter";
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 extendedMultiselect = ref(null);
856
+ const extendedMultiselectToggle = ref(null);
857
+
858
+ const {
859
+ defaultExpanded,
860
+ disabled,
861
+ disabledPrimitiveOptions,
862
+ emptyObjectsPlaceholder,
863
+ errorBorderColor,
864
+ inputId,
865
+ label,
866
+ loading,
867
+ loaderIconFilter,
868
+ multiple,
869
+ options,
870
+ optionsCountRestriction,
871
+ preselectedOption,
872
+ preselectedOptions,
873
+ resetSearchByValue,
874
+ simpleEvents,
875
+ showClearIcon,
876
+ showInsertWarnings,
877
+ showSearchField,
878
+ themeType,
879
+ toggleAppearanceSide,
880
+ toggleMaxHeight,
881
+ toggleOptionsBySelect,
882
+ wrongCurrentValue,
883
+ } = toRefs(props);
884
+
885
+ const {
886
+ searchState,
887
+ setSearchValue,
888
+ setSearchPattern,
889
+ } = useSearchValue();
890
+
891
+ provide("loaderIconFilter", loaderIconFilter.value);
892
+ provide("searchState", searchState);
893
+ provide("setSearchValue", setSearchValue);
894
+ provide("setSearchPattern", setSearchPattern);
895
+
896
+ const { toggleOptionsList } = useToggle(
897
+ loading,
898
+ disabled,
899
+ internalLoader,
900
+ );
901
+ const { cancel } = useCancel(
902
+ disabled,
903
+ showSearchField,
904
+ selectedOptions,
905
+ );
906
+ const { createLabel, optionTypeRestrictor } = usePreselectedOptions(
907
+ label,
908
+ emptyObjectsPlaceholder,
909
+ showInsertWarnings,
910
+ );
911
+ const attrs = useAttrs();
912
+ const slots = useSlots();
913
+
914
+ /**
915
+ * Defines a list of extended multiselect wrapper classes
916
+ * @function
917
+ * @returns {Array} classes
918
+ */
919
+ const classes = computed(() => {
920
+ let theme;
921
+ const localClassList = [];
922
+
923
+ switch(themeType.value) {
924
+ case "basic":
925
+ theme = "extended__multiselect";
926
+ break;
927
+ case "slate-grey":
928
+ theme = "extended__multiselect-slate-grey";
929
+ break;
930
+ case "slate-blue":
931
+ theme = "extended__multiselect-slate-blue";
932
+ break;
933
+ case "teal":
934
+ theme = "extended__multiselect-teal";
935
+ break;
936
+ case "strict":
937
+ theme = "extended__multiselect-strict";
938
+ break;
939
+ default: return ["extended__multiselect"];
940
+ }
941
+
942
+ localClassList.push(theme);
943
+
944
+ const clear = showClearIcon.value
945
+ ? "extended__multiselect-clear--active"
946
+ : "extended__multiselect-clear--locked";
947
+
948
+ localClassList.push(clear);
949
+
950
+ return localClassList;
951
+ });
952
+
953
+ /**
954
+ * Defines a list of disabled options by types given in "disabledPrimitiveOptions" prop
955
+ * @function
956
+ * @returns {Array} options
957
+ */
958
+ const disabledPrimitiveOptionsConverted = computed(() => {
959
+ if (!disabledPrimitiveOptions.value) return null;
960
+
961
+ return disabledPrimitiveOptions.value.map((disabledOption) => {
962
+ if (Array.isArray(disabledOption)) {
963
+ if (!disabledOption.length) return emptyObjectsPlaceholder.value;
964
+
965
+ return disabledOption.join(", ");
966
+ }
967
+
968
+ return disabledOption;
969
+ });
970
+ });
971
+
972
+ /**
973
+ * Determines whether to display irregularity of value by "border-color" css-property
974
+ * @function
975
+ * @returns {Object|null} styles
976
+ */
977
+ const displayWrongValue = computed(() => {
978
+ return wrongCurrentValue.value ? { borderColor: errorBorderColor.value } : null;
979
+ });
980
+
981
+ /**
982
+ * Defines styles depending on current options list dropdown state
983
+ * @function
984
+ * @returns {Object|null} styles
985
+ */
986
+ const expanded = computed(() => {
987
+ let borderStyles;
988
+
989
+ if (chosenToggleAppearanceSide.value === "atop") {
990
+ borderStyles = {
991
+ borderTopLeftRadius: 0,
992
+ borderTopRightRadius: 0,
993
+ transition: "border-top-left-radius 250ms, border-top-right-radius 250ms",
994
+ };
995
+ } else {
996
+ borderStyles = {
997
+ borderBottomLeftRadius: 0,
998
+ borderBottomRightRadius: 0,
999
+ transition: "border-bottom-left-radius 250ms, border-bottom-right-radius 250ms",
1000
+ };
1001
+ }
1002
+
1003
+ return dropdownActive.value ? borderStyles : null;
1004
+ });
1005
+
1006
+ /**
1007
+ * Determines whether to activate loading state by "loading" prop
1008
+ * or by internal loading sign
1009
+ * @function
1010
+ * @returns {boolean} loading
1011
+ */
1012
+ const internalLoading = computed(() => {
1013
+ return loading.value || internalLoader.value;
1014
+ });
1015
+
1016
+ /**
1017
+ * Defines a list of options filtered by maximal admissible options amount
1018
+ * @function
1019
+ * @returns {Array} options
1020
+ */
1021
+ const restrictedOptions = computed(() => {
1022
+ return optionsCountRestriction.value
1023
+ ? rawOptions.value.filter((option, index) => index + 1 <= optionsCountRestriction.value)
1024
+ : rawOptions.value;
1025
+ });
1026
+
1027
+ /**
1028
+ * Determines length of options list after filtering by
1029
+ * maximal admissible options amount
1030
+ * @function
1031
+ * @returns {number} length
1032
+ */
1033
+ const restrictedOptionsLength = computed(() => {
1034
+ return restrictedOptions.value.length;
1035
+ });
1036
+
1037
+ /**
1038
+ * Defines "aria-roledescription" attribute of extended multiselect wrapper
1039
+ * @function
1040
+ * @returns {string} aria-roledescription
1041
+ */
1042
+ const roledescription = computed(() => {
1043
+ return multiple.value ? "Multiselect" : "Select";
1044
+ });
1045
+
1046
+ /**
1047
+ * Defines "tabindex" attribute of extended multiselect wrapper if needed
1048
+ * @function
1049
+ * @returns {number} tabindex
1050
+ */
1051
+ const tabindexIfSearch = computed(() => {
1052
+ return showSearchField.value ? attrs.tabindex : -1;
1053
+ });
1054
+
1055
+ /**
1056
+ * Defines special class which indicates disabled or loading state
1057
+ * of extended multiselect wrapper
1058
+ * @function
1059
+ * @returns {string} class
1060
+ */
1061
+ const wrapperClasses = computed(() => {
1062
+ return inputDisabled.value && !internalLoading.value
1063
+ ? "extended__multiselect-wrapper--disabled"
1064
+ : "extended__multiselect-wrapper";
1065
+ });
1066
+
1067
+ /**
1068
+ * Disables search field if "disabled" prop equals true
1069
+ * @function
1070
+ * @param {boolean} value - "disabled" prop
1071
+ */
1072
+ watch(disabled, (value) => {
1073
+ inputDisabled.value = value;
1074
+ }, { immediate: true });
1075
+
1076
+ /**
1077
+ * Forcibly rolls up dropdown options list by changing "dropdownActive" flag
1078
+ * @function
1079
+ * @emits extended:rollup-options
1080
+ * @param {boolean} value - "dropdownActive" flag
1081
+ */
1082
+ watch(dropdownActive, (value) => {
1083
+ if (!value) {
1084
+ emitter.emit("extended:rollup-options");
1085
+ }
1086
+ });
1087
+
1088
+ /**
1089
+ * Disables search field if "loading" prop equals true
1090
+ * @function
1091
+ * @param {boolean} value - "loading" prop
1092
+ */
1093
+ watch(internalLoading, (value) => {
1094
+ if (disabled.value) return;
1095
+
1096
+ inputDisabled.value = value;
1097
+ }, { immediate: true });
1098
+
1099
+ /**
1100
+ * Clears value of search field after changing selected option/options
1101
+ * if "resetSearchByValue" prop equals true
1102
+ * @function
1103
+ * @emits extended:clear-field
1104
+ */
1105
+ watch(selectedOptions, (value) => {
1106
+ if (multiple.value) {
1107
+ emit("update:modelValue", value);
1108
+ } else {
1109
+ emit("update:modelValue", value[0]);
1110
+ }
1111
+
1112
+ if (resetSearchByValue.value) {
1113
+ emitter.emit("extended:clear-field");
1114
+ }
1115
+ }, { deep: true });
1116
+
1117
+ /**
1118
+ * Emits "active" when dropdown options list is active
1119
+ * @function
1120
+ * @emits active
1121
+ */
1122
+ const activeEmitter = () => {
1123
+ const eventData = simpleEvents.value ? null : {
1124
+ inputId: inputId.value,
1125
+ };
1126
+
1127
+ /**
1128
+ * @event active
1129
+ * @type {object|null}
1130
+ * @property {string} inputId - id of search field set by "id" prop
1131
+ */
1132
+ emit("active", eventData);
1133
+ };
1134
+
1135
+ /**
1136
+ * Handler for "v-click-outside" directive
1137
+ * @function
1138
+ * @emits "extended:rollup-options"
1139
+ */
1140
+ const clickOutside = () => {
1141
+ emitter.emit("extended:rollup-options");
1142
+ };
1143
+
1144
+ /**
1145
+ * Emits "close" when dropdown options list is rolled up
1146
+ * @function
1147
+ * @emits close
1148
+ */
1149
+ const closeEmitter = () => {
1150
+ const eventData = simpleEvents.value
1151
+ ? selectedOptions.value
1152
+ : createEventFields(selectedOptions.value, "options");
1153
+
1154
+ /**
1155
+ * @event close
1156
+ * @type {object|Array}
1157
+ * @property {string} inputId - id of search field set by "id" prop
1158
+ * @property {Array} options - array of selected options
1159
+ */
1160
+ emit("close", eventData);
1161
+ }
1162
+
1163
+ /**
1164
+ * Creates payload for events that can be listened by outer listeners
1165
+ * @function
1166
+ * @param {UnionPropType} field - main payload of event
1167
+ * @param {string} fieldName - name of field with main payload of event
1168
+ * @returns {object} payload
1169
+ */
1170
+ const createEventFields = (field, fieldName) => {
1171
+ const eventFields = {
1172
+ inputId: inputId.value,
1173
+ };
1174
+
1175
+ Object.defineProperty(eventFields, fieldName, {
1176
+ value: field,
1177
+ enumerable: true,
1178
+ });
1179
+
1180
+ return eventFields;
1181
+ };
1182
+
1183
+ /**
1184
+ * Focuses search field if "click" native event was triggered on available element
1185
+ * @function
1186
+ * @emits extended:field-focus
1187
+ * @param {MouseEvent} mouseEvent - MouseEvent instance
1188
+ */
1189
+ const fieldFocus = (mouseEvent) => {
1190
+ if (internalLoading.value || disabled.value) return;
1191
+
1192
+ if (!toggleOptionsBySelect.value) {
1193
+ const customFilteredOptions = toggleOptionsRestrictor(mouseEvent);
1194
+
1195
+ if (customFilteredOptions) return;
1196
+ }
1197
+
1198
+ const customFilteredCancel = toggleCustomRestrictor(mouseEvent, 2);
1199
+ const customFilteredSelf = toggleCustomRestrictor(mouseEvent, 1);
1200
+ const filteredHasCancel = toggleDetector(mouseEvent, /^extended__multiselect-cancel/i);
1201
+ const filteredHasToggle = toggleDetector(mouseEvent, togglePattern);
1202
+
1203
+ if (customFilteredCancel) return;
1204
+ if (customFilteredSelf && dropdownActive.value === false) return;
1205
+ if (filteredHasCancel.length) return;
1206
+ if (filteredHasToggle.length && dropdownActive.value === false) return;
1207
+
1208
+ emitter.emit("extended:field-focus");
1209
+ };
1210
+
1211
+ /**
1212
+ * Emits event whose listener resets index of "enter" key pressing
1213
+ * @function
1214
+ * @emits extended:reset-index
1215
+ */
1216
+ const resetEnterIndex = () => {
1217
+ emitter.emit("extended:reset-index");
1218
+ };
1219
+
1220
+ /**
1221
+ * Rolls up dropdown options list
1222
+ * @function
1223
+ * @emits extended:rollup-options
1224
+ */
1225
+ const rollUp = () => {
1226
+ dropdownActive.value = false;
1227
+ emitter.emit("extended:rollup-options");
1228
+ };
1229
+
1230
+ /**
1231
+ * Triggers selection of option by "enter" key pressing
1232
+ * @function
1233
+ * @emits extended:select-enter
1234
+ * @param {KeyboardEvent} keyboardEvent - KeyboardEvent instance
1235
+ */
1236
+ const selectByEnter = (keyboardEvent) => {
1237
+ emitter.emit("extended:select-enter", keyboardEvent);
1238
+ };
1239
+
1240
+ /**
1241
+ * Sets preselected option provided by "preselectedOption" prop
1242
+ * @function
1243
+ * @emits extended:select-option
1244
+ */
1245
+ const setPreselectedOption = () => {
1246
+ const availableOptionType = optionTypeRestrictor(preselectedOption.value);
1247
+ const mappedOptions = restrictedOptions.value.map((restrictedOption) => {
1248
+ return JSON.stringify(restrictedOption);
1249
+ });
1250
+
1251
+ if (!availableOptionType) return;
1252
+ if (!mappedOptions.includes(JSON.stringify(preselectedOption.value)) && showInsertWarnings.value) {
1253
+ console.warn("vue-extended-multiselect: option in «preselectedOption» property should be the same as analogue in «options» property");
1254
+ return;
1255
+ }
1256
+
1257
+ const isObjectOrArray = typeof preselectedOption.value === "object";
1258
+ const label = createLabel(isObjectOrArray, preselectedOption.value);
1259
+
1260
+ emitter.emit("extended:select-option", {
1261
+ label,
1262
+ option: preselectedOption.value,
1263
+ });
1264
+ };
1265
+
1266
+ /**
1267
+ * Sets preselected options provided by "preselectedOptions" prop
1268
+ * if "multiple" prop equals true
1269
+ * @function
1270
+ * @emits extended:select-option
1271
+ */
1272
+ const setPreselectedOptions = async () => {
1273
+ let allOptionsWereSelected = 0;
1274
+ const mappedOptions = restrictedOptions.value.map((restrictedOption) => {
1275
+ return JSON.stringify(restrictedOption);
1276
+ });
1277
+
1278
+ preselectedOptions.value.forEach((preselectedOption) => {
1279
+ const availableOptionType = optionTypeRestrictor(preselectedOption);
1280
+
1281
+ if (!preselectedOption || !availableOptionType) return;
1282
+ if (selectedOptions.value.includes(preselectedOption)) return;
1283
+
1284
+ if (mappedOptions.includes(JSON.stringify(preselectedOption))) {
1285
+ const isObjectOrArray = typeof option === "object";
1286
+ const label = createLabel(isObjectOrArray, preselectedOption);
1287
+
1288
+ allOptionsWereSelected++;
1289
+
1290
+ emitter.emit("extended:select-option", {
1291
+ label,
1292
+ option: preselectedOption,
1293
+ });
1294
+ }
1295
+ });
1296
+
1297
+ if (allOptionsWereSelected !== preselectedOptions.value.length && showInsertWarnings.value) {
1298
+ console.warn("vue-extended-multiselect: options in «preselectedOptions» property should be the same as analogues in «options» property");
1299
+ }
1300
+ };
1301
+
1302
+ /**
1303
+ * Determines conditions that control preselected options installattion
1304
+ * @function
1305
+ */
1306
+ const setPreselectedOptionsByConditions = () => {
1307
+ if (preselectedOption.value && !multiple.value) {
1308
+ setPreselectedOption();
1309
+ }
1310
+
1311
+ if (preselectedOptions.value && multiple.value) {
1312
+ setPreselectedOptions();
1313
+ }
1314
+ };
1315
+
1316
+ /**
1317
+ * Defines a position of dropdown appearance
1318
+ * @function
1319
+ * @returns {string} position
1320
+ */
1321
+ const toggleAppearanceRestrictor = () => {
1322
+ if (!window) return "under";
1323
+
1324
+ const innerHeight = window.innerHeight;
1325
+ const offsetTop = extendedMultiselect.value.getBoundingClientRect().y;
1326
+ const difference = innerHeight - offsetTop;
1327
+
1328
+ if (difference > toggleMaxHeight.value) {
1329
+ return "under";
1330
+ } else {
1331
+ return "atop";
1332
+ }
1333
+ };
1334
+
1335
+ /**
1336
+ * Sets a position of dropdown appearance
1337
+ * @function
1338
+ */
1339
+ const toggleAppearanceRestrictorActivate = () => {
1340
+ if (!dropdownActive.value) {
1341
+ chosenToggleAppearanceSide.value = toggleAppearanceSide.value !== "auto"
1342
+ ? toggleAppearanceSide.value
1343
+ : toggleAppearanceRestrictor();
1344
+ }
1345
+ };
1346
+
1347
+ /**
1348
+ * Restricts toggling of dropdown options list
1349
+ * @function
1350
+ * @emits extended:skip-block-blur
1351
+ * @param {MouseEvent} mouseEvent - MouseEvent instance
1352
+ * @returns {boolean} toggling
1353
+ */
1354
+ const toggleBlockRestrictor = (mouseEvent) => {
1355
+ let generalRestriction;
1356
+ let filteredCustomSelf;
1357
+ const filteredHasBlock = toggleDetector(mouseEvent, /^extended__multiselect-block/i, true);
1358
+ const filteredSelf = toggleDetector(mouseEvent, /^extended__multiselect-clear/i);
1359
+
1360
+ if (filteredSelf || filteredHasBlock) {
1361
+ filteredCustomSelf = true;
1362
+ } else {
1363
+ filteredCustomSelf = toggleCustomRestrictor(mouseEvent);
1364
+ }
1365
+
1366
+ if (extendedMultiselectToggle.value) {
1367
+ generalRestriction = (filteredHasBlock && dropdownActive.value && filteredCustomSelf)
1368
+ || (filteredSelf && dropdownActive.value && filteredCustomSelf);
1369
+ } else {
1370
+ generalRestriction = (filteredHasBlock && dropdownActive.value)
1371
+ || (filteredSelf && dropdownActive.value);
1372
+ }
1373
+
1374
+ if (generalRestriction) {
1375
+ emitter.emit("extended:skip-block-blur");
1376
+ return true;
1377
+ }
1378
+
1379
+ return false;
1380
+ }
1381
+
1382
+ /**
1383
+ * Restricts toggling of dropdown options list by clicking
1384
+ * on particular descendants of toggle wrapper element
1385
+ * @function
1386
+ * @param {MouseEvent} mouseEvent - MouseEvent instance
1387
+ * @param {number} blockType - type of block which needs restriction
1388
+ * @returns {boolean} restriction
1389
+ */
1390
+ const toggleCustomRestrictor = (mouseEvent, blockType) => {
1391
+ let eventTarget = mouseEvent.target;
1392
+ const toggleWrapper = extendedMultiselect.value;
1393
+ const customToggle = toggleWrapper.children[blockType];
1394
+
1395
+ while(eventTarget) {
1396
+ if (eventTarget === customToggle) return true;
1397
+
1398
+ eventTarget = eventTarget.parentNode;
1399
+ }
1400
+
1401
+ return false;
1402
+ };
1403
+
1404
+ /**
1405
+ * Restricts toggling of dropdown options list by clicking
1406
+ * on particular elements defined by given pattern
1407
+ * @function
1408
+ * @param {MouseEvent} mouseEvent - MouseEvent instance
1409
+ * @param {string} pattern - pattern with block class partial name
1410
+ * @param {boolean} mode - marks whether restrict by parent element or by current target
1411
+ * @returns {Array} classes
1412
+ */
1413
+ const toggleDetector = (mouseEvent, pattern, mode) => {
1414
+ const target = mouseEvent.target;
1415
+
1416
+ let filteredHasToggle = Array.prototype.filter.call(target.classList, (className) => {
1417
+ return pattern.test(className) === true;
1418
+ });
1419
+
1420
+ if (!filteredHasToggle.length && mode && target.parentNode) {
1421
+ filteredHasToggle = Array.prototype.filter.call(target.parentNode.classList, (className) => {
1422
+ return pattern.test(className) === true;
1423
+ });
1424
+ }
1425
+
1426
+ return filteredHasToggle;
1427
+ };
1428
+
1429
+ /**
1430
+ * Toggles dropdown options list and activates
1431
+ * necessary methods with relevant events
1432
+ * @function
1433
+ */
1434
+ const toggleOptions = () => {
1435
+ if (internalLoading.value || disabled.value) return;
1436
+
1437
+ toggleAppearanceRestrictorActivate();
1438
+
1439
+ if (!dropdownActive.value) {
1440
+ activeEmitter();
1441
+ } else {
1442
+ closeEmitter();
1443
+ }
1444
+
1445
+ dropdownActive.value = !dropdownActive.value;
1446
+ };
1447
+
1448
+ /**
1449
+ * Prevents toggling dropdown options list
1450
+ * by selecting/deselecting option
1451
+ * @function
1452
+ * @param {MouseEvent} mouseEvent - MouseEvent instance
1453
+ * @returns {boolean} restriction
1454
+ */
1455
+ const toggleOptionsRestrictor = (mouseEvent) => {
1456
+ try {
1457
+ let eventTarget = mouseEvent.target;
1458
+ const optionsWrapper = optionsWrapper.value;
1459
+
1460
+ while(eventTarget) {
1461
+ if (eventTarget === optionsWrapper) return true;
1462
+
1463
+ eventTarget = eventTarget.parentNode;
1464
+ }
1465
+
1466
+ return false;
1467
+ } catch(e) {
1468
+ return false;
1469
+ }
1470
+ };
1471
+
1472
+ /**
1473
+ * Collects restrictions from other methods and defines
1474
+ * general restriction of toggling dropdown options list
1475
+ * @function
1476
+ * @emits extended:skip-blur
1477
+ * @param {MouseEvent} mouseEvent - MouseEvent instance
1478
+ */
1479
+ const toggleRestrictor = (mouseEvent) => {
1480
+ const targetContentBlock = toggleBlockRestrictor(mouseEvent);
1481
+
1482
+ if (targetContentBlock) return;
1483
+
1484
+ const filteredHasToggle = toggleDetector(mouseEvent, togglePattern);
1485
+
1486
+ if (filteredHasToggle.length && dropdownActive.value) {
1487
+ emitter.emit("extended:skip-blur");
1488
+ }
1489
+ };
1490
+
1491
+ /**
1492
+ * "onBeforeMount" hook of the Vue3ExtendedMultiselect component
1493
+ * @emits select
1494
+ * @emits clean
1495
+ * @emits option-created
1496
+ * @emits increase
1497
+ * @emits pattern-changed
1498
+ * @emits extended:rollup-options
1499
+ * @listens extended:rollup-options
1500
+ * @listens extended:toggle-options
1501
+ * @listens extended:select-option
1502
+ * @listens extended:deselect-option
1503
+ * @listens extended:clean-options
1504
+ * @listens extended:create-option
1505
+ * @listens extended:increase-display
1506
+ * @listens extended:search-pattern-changed
1507
+ */
1508
+ onBeforeMount(() => {
1509
+ chosenToggleAppearanceSide.value = toggleAppearanceSide.value;
1510
+
1511
+ emitter.on("extended:rollup-options", () => {
1512
+ if (!dropdownActive.value) return;
1513
+
1514
+ closeEmitter();
1515
+ dropdownActive.value = false;
1516
+ });
1517
+
1518
+ emitter.on("extended:toggle-options", () => {
1519
+ toggleOptions();
1520
+ });
1521
+
1522
+ emitter.on("extended:select-option", (option) => {
1523
+ const eventData = simpleEvents.value
1524
+ ? option.option
1525
+ : createEventFields(option.option, "option");
1526
+
1527
+ if (multiple.value) {
1528
+ selectedOptions.value.push(option.option);
1529
+ /**
1530
+ * @event select
1531
+ * @type {Object}
1532
+ * @property {string} inputId - id of search field set by "id" prop
1533
+ * @property {UnionPropType} option - just now selected option
1534
+ */
1535
+ emit("select", eventData);
1536
+ } else {
1537
+ selectedOptions.value = [option.option];
1538
+ /**
1539
+ * @see select
1540
+ */
1541
+ emit("select", eventData);
1542
+ }
1543
+ });
1544
+
1545
+ emitter.on("extended:deselect-option", (payload) => {
1546
+ if (multiple.value && (payload && !payload.clearAll)) {
1547
+ const deselectedOption = selectedOptions.value[payload.index];
1548
+
1549
+ const eventData = simpleEvents.value
1550
+ ? deselectedOption
1551
+ : createEventFields(deselectedOption, "option");
1552
+
1553
+ /**
1554
+ * @event clean
1555
+ * @type {Object}
1556
+ * @property {string} inputId - id of search field set by "id" prop
1557
+ * @property {UnionPropType} option - just now deselected option
1558
+ */
1559
+ emit("clean", eventData);
1560
+
1561
+ selectedOptions.value.splice(payload.index, 1);
1562
+ return;
1563
+ } else {
1564
+ selectedOptions.value = [];
1565
+ }
1566
+
1567
+ if (toggleOptionsBySelect.value) {
1568
+ emitter.emit("extended:rollup-options");
1569
+ }
1570
+ });
1571
+
1572
+ emitter.on("extended:clean-options", (selectedOptions) => {
1573
+ const eventData = simpleEvents.value
1574
+ ? selectedOptions.value
1575
+ : createEventFields(selectedOptions, "options");
1576
+
1577
+ /**
1578
+ * @see clean
1579
+ * @property {Array} options - just now deselected options
1580
+ */
1581
+ emit("clean", eventData);
1582
+ });
1583
+
1584
+ emitter.on("extended:create-option", (createdOption) => {
1585
+ const eventData = simpleEvents.value
1586
+ ? createdOption
1587
+ : createEventFields(createdOption, "option");
1588
+
1589
+ /**
1590
+ * @event option-created
1591
+ * @type {PluginObject}
1592
+ * @property {string} inputId - id of search field set by "id" prop
1593
+ * @property {UnionPropType} option - option created by user
1594
+ */
1595
+ emit("option-created", eventData);
1596
+ });
1597
+
1598
+ emitter.on("extended:increase-display", (limit) => {
1599
+ const eventData = simpleEvents.value ? limit : createEventFields(limit, "limit");
1600
+
1601
+ /**
1602
+ * @event increase
1603
+ * @type {Object}
1604
+ * @property {string} inputId - id of search field set by "id" prop
1605
+ * @property {limit} - current limit of options to be shown next
1606
+ */
1607
+ emit("increase", eventData);
1608
+ });
1609
+
1610
+ emitter.on("extended:search-pattern-changed", (pattern) => {
1611
+ const eventData = simpleEvents.value
1612
+ ? pattern
1613
+ : createEventFields(pattern, "pattern");
1614
+
1615
+ /**
1616
+ * @event pattern-changed
1617
+ * @type {Object}
1618
+ * @property {string} inputId - id of search field set by "id" prop
1619
+ * @property {pattern} - pattern of internal search for available options
1620
+ */
1621
+ emit("pattern-changed", eventData);
1622
+ });
1623
+ });
1624
+
1625
+ /**
1626
+ * "onMounted" hook of the Vue3ExtendedMultiselect component
1627
+ * @listens extended:expand-options
1628
+ */
1629
+ onMounted(() => {
1630
+ if (typeof options.value === "function") {
1631
+ internalLoader.value = true;
1632
+ options.value().then(options => {
1633
+ rawOptions.value = options;
1634
+ internalLoader.value = false;
1635
+ setPreselectedOptionsByConditions();
1636
+ });
1637
+ } else {
1638
+ rawOptions.value = options.value;
1639
+ setPreselectedOptionsByConditions();
1640
+ }
1641
+
1642
+ if (
1643
+ defaultExpanded.value
1644
+ && !inputDisabled.value
1645
+ && !internalLoading.value
1646
+ && typeof options.value !== "function"
1647
+ ) {
1648
+ dropdownActive.value = true;
1649
+ }
1650
+
1651
+ emitter.on("extended:expand-options", () => {
1652
+ if (dropdownActive.value === true) return;
1653
+
1654
+ toggleAppearanceRestrictorActivate();
1655
+ activeEmitter();
1656
+
1657
+ dropdownActive.value = true;
1658
+ });
1659
+ });
1660
+ </script>
1661
+
1662
+ <style>
1663
+
1664
+ @import "../styles/main.css";
1665
+
1661
1666
  </style>