vue3-extended-multiselect 1.4.1 → 1.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/.browserslistrc +3 -3
  2. package/.eslintrc.js +34 -34
  3. package/.github/workflows/publish.yml +41 -41
  4. package/.nvmrc +0 -0
  5. package/CHANGELOG.md +185 -181
  6. package/LICENSE +21 -21
  7. package/README.md +266 -266
  8. package/babel.config.js +5 -5
  9. package/index.js +2 -2
  10. package/jest.config.js +61 -61
  11. package/package.json +47 -47
  12. package/src/assets/base-arrow.svg +70 -70
  13. package/src/assets/cancel.svg +34 -34
  14. package/src/assets/circle-arrow.svg +7 -7
  15. package/src/assets/double-arrow.svg +39 -39
  16. package/src/assets/inner-arrow.svg +8 -8
  17. package/src/assets/loader.svg +5 -5
  18. package/src/assets/triangle-arrow.svg +72 -72
  19. package/src/assets/triangle-circle-arrow.svg +38 -38
  20. package/src/assets/wide-arrow.svg +72 -72
  21. package/src/components/ExtendedMultiselectCancel.vue +166 -166
  22. package/src/components/ExtendedMultiselectInput.vue +687 -687
  23. package/src/components/ExtendedMultiselectLoader.vue +182 -182
  24. package/src/components/ExtendedMultiselectMultiple.vue +320 -320
  25. package/src/components/ExtendedMultiselectOptions.vue +1144 -1144
  26. package/src/components/ExtendedMultiselectToggle.vue +273 -273
  27. package/src/components/Vue3ExtendedMultiselect.vue +1752 -1752
  28. package/src/composition/cancel.js +38 -38
  29. package/src/composition/image-path.js +16 -16
  30. package/src/composition/labels.js +41 -41
  31. package/src/composition/preselected-options.js +67 -67
  32. package/src/composition/search-value.js +33 -33
  33. package/src/composition/sizes.js +42 -42
  34. package/src/composition/toggle.js +33 -33
  35. package/src/events/LocalEmitter.js +31 -31
  36. package/src/events/emitter.js +2 -2
  37. package/src/sets/sets.js +99 -99
  38. package/src/styles/animations.css +18 -18
  39. package/src/styles/main.css +441 -441
  40. package/src/styles/variables.css +49 -49
  41. package/tests/unit/events.spec.js +138 -138
  42. package/tests/unit/props.spec.js +1099 -1099
  43. package/tests/utils/mount.js +37 -37
  44. package/tests/utils/utils.js +20 -20
  45. package/typings/vue3-extended-multiselect.d.ts +43 -43
@@ -1,1753 +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
- :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
-
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.2
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
+
1753
1753
  </style>