vue3-extended-multiselect 0.2.1 → 1.0.0

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