vue3-extended-multiselect 1.2.4 → 1.4.1

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