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