vue3-extended-multiselect 1.10.2 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/.browserslistrc +2 -2
  2. package/.eslintrc.js +35 -34
  3. package/.github/workflows/publish.yml +41 -41
  4. package/CHANGELOG.md +411 -389
  5. package/LICENSE +21 -21
  6. package/README.md +270 -270
  7. package/babel.config.js +9 -9
  8. package/index.js +2 -2
  9. package/jest.config.js +62 -62
  10. package/package.json +56 -46
  11. package/rollup.config.mjs +74 -0
  12. package/src/assets/{base-arrow.svg → images/base-arrow.svg} +70 -70
  13. package/src/assets/{cancel.svg → images/cancel.svg} +34 -34
  14. package/src/assets/{circle-arrow.svg → images/circle-arrow.svg} +7 -7
  15. package/src/assets/{double-arrow.svg → images/double-arrow.svg} +39 -39
  16. package/src/assets/{inner-arrow.svg → images/inner-arrow.svg} +8 -8
  17. package/src/assets/{loader.svg → images/loader.svg} +5 -5
  18. package/src/assets/{triangle-arrow.svg → images/triangle-arrow.svg} +72 -72
  19. package/src/assets/{triangle-circle-arrow.svg → images/triangle-circle-arrow.svg} +38 -38
  20. package/src/assets/{wide-arrow.svg → images/wide-arrow.svg} +72 -72
  21. package/src/components/ExtendedMultiselectCancel.vue +165 -165
  22. package/src/components/ExtendedMultiselectInput.vue +741 -741
  23. package/src/components/ExtendedMultiselectLoader.vue +182 -182
  24. package/src/components/ExtendedMultiselectMultiple.vue +399 -399
  25. package/src/components/ExtendedMultiselectOptions.vue +1190 -1190
  26. package/src/components/ExtendedMultiselectToggle.vue +271 -271
  27. package/src/components/Vue3ExtendedMultiselect.vue +2475 -1949
  28. package/src/composition/cancel.js +39 -39
  29. package/src/composition/click-outside.js +8 -8
  30. package/src/composition/debounce.js +8 -8
  31. package/src/composition/emitter.js +8 -8
  32. package/src/composition/image-path.js +16 -16
  33. package/src/composition/labels.js +41 -41
  34. package/src/composition/preselected-options.js +67 -67
  35. package/src/composition/search-value.js +33 -33
  36. package/src/composition/sizes.js +44 -44
  37. package/src/composition/toggle.js +31 -31
  38. package/src/sets/sets.js +99 -99
  39. package/src/styles/animations.css +18 -18
  40. package/src/styles/main.css +460 -460
  41. package/src/styles/variables.css +51 -51
  42. package/src/tools/Debounce.js +25 -25
  43. package/src/tools/LocalEmitter.js +31 -31
  44. package/src/tools/instance.js +2 -2
  45. package/tests/unit/events.spec.js +149 -149
  46. package/tests/unit/props.spec.js +1154 -1155
  47. package/tests/unit/tools.spec.js +55 -53
  48. package/tests/utils/mount.js +37 -37
  49. package/tests/utils/utils.js +24 -24
  50. package/typings/vue3-extended-multiselect.d.ts +43 -43
@@ -1,1191 +1,1191 @@
1
- <template>
2
- <div
3
- ref="optionsWrapper"
4
- tabindex="-1"
5
- :class="classes"
6
- :style="styles"
7
- >
8
- <slot name="listHeader"></slot>
9
- <div
10
- v-if="showCreateNewOptionBlock"
11
- class="extended__multiselect-option-create"
12
- :class="optionHighlightClasses(null)"
13
- @mousedown="createNewOption"
14
- >
15
- {{ searchState.searchValue }}
16
- </div>
17
- <slot
18
- name="moreThanLimit"
19
- v-if="maxOptionsWereSelected"
20
- >
21
- <span>Maximum limit of selected options was achieved</span>
22
- </slot>
23
- <slot
24
- name="lessThanLimit"
25
- v-if="minOptionsWereNotSelected"
26
- >
27
- <span>Minimum amount of selected options was not achieved</span>
28
- </slot>
29
- <div class="extended__multiselect-options_container">
30
- <div
31
- role="listbox"
32
- v-for="(option, index) in availableOptions"
33
- :key="index"
34
- >
35
- <div
36
- v-if="option"
37
- :aria-setsize="availableOptions.length"
38
- :aria-posinset="index"
39
- :aria-labelledby="`option-label-${index}`"
40
- :aria-disabled="optionIsDisabled(option)"
41
- :class="optionHighlightClasses(option)"
42
- :style="optionHeightByProps"
43
- :enter-locator="index"
44
- :role="optionCreateRole(option)"
45
- @click.stop="selectOption(option, $event)"
46
- @keypress.stop="selectOption(option, $event)"
47
- @mousedown="triggerOptionBeforeSelection"
48
- @mouseenter.stop="setEnterIndex"
49
- >
50
- <slot
51
- name="option"
52
- :option="option"
53
- :create-custom-option-label="createCustomOptionLabel"
54
- >
55
- <div class="extended__multiselect-marker">
56
- <slot
57
- name="marker"
58
- :selected="showCurrentMarker(option)"
59
- >
60
- <div
61
- v-if="showMarker && showCurrentMarker(option)"
62
- :class="markerShapeClass(option)"
63
- :style="markerShapeMargin"
64
- >
65
- </div>
66
- <div
67
- v-else-if="showMarker"
68
- class="extended__multiselect-marker-shape-only"
69
- >
70
- </div>
71
- </slot>
72
- </div>
73
- <span :id="`option-label-${index}`">
74
- {{ optionCreateLabel(option) }}
75
- </span>
76
- </slot>
77
- </div>
78
- </div>
79
- </div>
80
- <slot
81
- name="noResults"
82
- v-if="emptySearchResult"
83
- >
84
- <span>No results were found by search</span>
85
- </slot>
86
- <slot
87
- name="noOptions"
88
- v-if="emptyOptionsList"
89
- >
90
- <span>Options list is empty</span>
91
- </slot>
92
- <slot name="listFooter"></slot>
93
- </div>
94
- </template>
95
-
96
- <script setup>
97
- import {
98
- computed,
99
- defineProps,
100
- inject,
101
- nextTick,
102
- onBeforeMount,
103
- onMounted,
104
- reactive,
105
- ref,
106
- toRefs,
107
- } from "vue";
108
-
109
- import usePreselectedOptions from "../composition/preselected-options";
110
- import useLabels from "../composition/labels";
111
-
112
- import { UnionPropType } from "../sets/sets";
113
-
114
- const props = defineProps({
115
- /**
116
- * Determines whether to immediately select just now created option
117
- * @property {boolean} autoSelectCreatedOption
118
- */
119
- autoSelectCreatedOption: {
120
- type: Boolean,
121
- required: true,
122
- },
123
-
124
- /**
125
- * Determines whether to show noResults slot
126
- * and block with new option's text
127
- * @property {boolean} createOnTheGo
128
- */
129
- createOnTheGo: {
130
- type: Boolean,
131
- required: true,
132
- },
133
-
134
- /**
135
- * Determines whether to emit clear event
136
- * by option selection
137
- * @property {boolean} clearBySelectWhenMultiple
138
- */
139
- clearBySelectWhenMultiple: {
140
- type: Boolean,
141
- required: true,
142
- },
143
-
144
- /**
145
- * Determines whether to define thematic class for
146
- * every option
147
- * @property {boolean} highlightOptions
148
- */
149
- highlightOptions: {
150
- type: Boolean,
151
- required: true,
152
- },
153
-
154
- /**
155
- * Determines "loading" state of component
156
- * that disables option selection
157
- * @property {boolean} loading
158
- */
159
- loading: {
160
- type: Boolean,
161
- required: true,
162
- },
163
-
164
- /**
165
- * Determines whether to use functionality of
166
- * multiple select
167
- * @property {boolean} multiple
168
- */
169
- multiple: {
170
- type: Boolean,
171
- required: true,
172
- },
173
-
174
- /**
175
- * Determines whether to show selected options
176
- * in options list
177
- * @property {boolean} selectedOptionsShown
178
- */
179
- selectedOptionsShown: {
180
- type: Boolean,
181
- required: true,
182
- },
183
-
184
- /**
185
- * Determines whether to log warnings about incorrect props
186
- * @property {boolean} showInsertWarnings
187
- */
188
- showInsertWarnings: {
189
- type: Boolean,
190
- required: true,
191
- },
192
-
193
- /**
194
- * Determines whether to show marker slot
195
- * @property {boolean} showMarker
196
- */
197
- showMarker: {
198
- type: Boolean,
199
- required: true,
200
- },
201
-
202
- /**
203
- * Defines class of options list placement after expanse
204
- * @property {string} chosenToggleAppearanceSide
205
- */
206
- chosenToggleAppearanceSide: {
207
- type: String,
208
- required: true,
209
- },
210
-
211
- /**
212
- * Determines type of option that will be created
213
- * @property {string} createOptionType
214
- */
215
- createOptionType: {
216
- type: String,
217
- required: true,
218
- },
219
-
220
- /**
221
- * Determines a field in options of type "object"
222
- * which value will be used to disable such options.
223
- * @property {string} disableByField
224
- */
225
- disableByField: {
226
- type: String,
227
- required: true,
228
- },
229
-
230
- /**
231
- * Sets labels for options of type "object"
232
- * or Array instances which length/keys length equals 0
233
- * @property {string} emptyObjectsPlaceholder
234
- */
235
- emptyObjectsPlaceholder: {
236
- type: String,
237
- required: true,
238
- },
239
-
240
- /**
241
- * Determines field of option which will be displayed as label
242
- * @property {string} label
243
- */
244
- label: {
245
- type: String,
246
- required: true,
247
- },
248
-
249
- /**
250
- * Determines field in options of type "object"
251
- * to use in internal search.
252
- * @property {string} searchByField
253
- */
254
- searchByField: {
255
- type: String,
256
- required: true,
257
- },
258
-
259
- /**
260
- * Current theme of extended-multiselect
261
- * used in class definition
262
- * @property {string} themeType
263
- */
264
- themeType: {
265
- type: String,
266
- required: true,
267
- },
268
-
269
- /**
270
- * Determines maximal limit of selected options
271
- * @property {number|null} maxOptionsCount
272
- */
273
- maxOptionsCount: {
274
- type: Number,
275
- default: null,
276
- },
277
-
278
- /**
279
- * Determines minimal limit of selected options
280
- * @property {number|null} minOptionsCount
281
- */
282
- minOptionsCount: {
283
- type: Number,
284
- default: null,
285
- },
286
-
287
- /**
288
- * Defines value of "max-height" css-property of options list
289
- * @property {number} toggleMaxHeight
290
- */
291
- toggleMaxHeight: {
292
- type: Number,
293
- required: true,
294
- },
295
-
296
- /**
297
- * Defines value of "min-height" css-property of options list
298
- * @property {number} toggleMinHeight
299
- */
300
- toggleMinHeight: {
301
- type: Number,
302
- default: null,
303
- },
304
-
305
- /**
306
- * List of fields for new options of type "object" created by user
307
- * if "createOnTheGo" prop equals true
308
- * Each field will have basic value of "searchValue" prop
309
- * @property {Array} createOptionFields
310
- */
311
- createOptionFields: {
312
- type: Array,
313
- required: true,
314
- },
315
-
316
- /**
317
- * Searches for options with listed primitive values
318
- * and disables it
319
- * @property {Array} disabledPrimitiveOptionsConverted
320
- */
321
- disabledPrimitiveOptionsConverted: {
322
- type: Array,
323
- required: true,
324
- },
325
-
326
- /**
327
- * Unfiltered options list
328
- * @property {Array} options
329
- */
330
- options: {
331
- type: Array,
332
- required: true,
333
- },
334
-
335
- /**
336
- * Defines value of "padding" css-property of every option
337
- * @property {Array} optionsPadding
338
- */
339
- optionsPadding: {
340
- type: Array,
341
- required: true,
342
- },
343
-
344
- /**
345
- * List of options which should be selected by default
346
- * if "multiple" prop equals true
347
- * @property {Array} preselectedOptions
348
- */
349
- preselectedOptions: {
350
- type: Array,
351
- required: true,
352
- },
353
-
354
- /**
355
- * List of options filtered by maximal available options amount
356
- * @property {Array} restrictedOptions
357
- */
358
- restrictedOptions: {
359
- type: Array,
360
- required: true,
361
- },
362
-
363
- /**
364
- * List of selected options or list with single selected option
365
- * if "multiple" prop equals false
366
- * @property {Array} selectedOptions
367
- */
368
- selectedOptions: {
369
- type: Array,
370
- required: true,
371
- },
372
-
373
- /**
374
- * List of key names that in combination with "enter" key
375
- * should cancel option selection
376
- * @property {Array} specialKeysBlock
377
- */
378
- specialKeysBlock: {
379
- type: Array,
380
- required: true,
381
- },
382
-
383
- /**
384
- * Reactive instance of LocalEmitter class
385
- * @property {object} emitter
386
- */
387
- emitter: {
388
- type: Object,
389
- required: true,
390
- },
391
-
392
- /**
393
- * Creates custom label for every option in options list
394
- * @property {Function} createCustomOptionLabel
395
- */
396
- createCustomOptionLabel: {
397
- type: Function,
398
- required: true,
399
- },
400
-
401
- /**
402
- * Loader function provided by user.
403
- * @property {Function} externalOptionsLoader
404
- * @default null
405
- * @param {string} value - value of search field
406
- */
407
- externalOptionsLoader: {
408
- type: Function,
409
- default: null,
410
- },
411
-
412
- /**
413
- * Defines "height" css-property of every option element
414
- * @property {number} anyOptionWrapperBlockHeight
415
- */
416
- anyOptionWrapperBlockHeight: {
417
- type: [Number, String],
418
- required: true,
419
- },
420
-
421
- /**
422
- * Option which should be selected by default
423
- * if "multiple" prop equals false
424
- * @property {UnionPropType|null} preselectedOption
425
- */
426
- preselectedOption: {
427
- type: UnionPropType,
428
- default: null,
429
- },
430
- });
431
-
432
- const searchState = inject("searchState");
433
- const setSearchValue = inject("setSearchValue");
434
- const setSearchPattern = inject("setSearchPattern");
435
-
436
- const fieldWasShown = ref(false);
437
- const atopWithScroll = ref(null);
438
- const enterIndex = ref(null);
439
- const heightFromMounted = reactive({});
440
- const underWithScroll = ref(null);
441
-
442
- /**
443
- * Element references
444
- */
445
- const optionsWrapper = ref(null);
446
-
447
- const {
448
- anyOptionWrapperBlockHeight,
449
- autoSelectCreatedOption,
450
- chosenToggleAppearanceSide,
451
- clearBySelectWhenMultiple,
452
- createOnTheGo,
453
- createCustomOptionLabel,
454
- createOptionFields,
455
- createOptionType,
456
- disableByField,
457
- disabledPrimitiveOptionsConverted,
458
- emitter,
459
- emptyObjectsPlaceholder,
460
- highlightOptions,
461
- loading,
462
- label,
463
- searchByField,
464
- maxOptionsCount,
465
- minOptionsCount,
466
- multiple,
467
- options,
468
- optionsPadding,
469
- restrictedOptions,
470
- selectedOptions,
471
- selectedOptionsShown,
472
- showInsertWarnings,
473
- showMarker,
474
- specialKeysBlock,
475
- themeType,
476
- toggleMaxHeight,
477
- toggleMinHeight,
478
- externalOptionsLoader,
479
- } = toRefs(props);
480
-
481
- const { createLabel, optionTypeRestrictor } = usePreselectedOptions(
482
- label,
483
- emptyObjectsPlaceholder,
484
- showInsertWarnings,
485
- );
486
- const { optionCreateLabel } = useLabels(
487
- label,
488
- createCustomOptionLabel,
489
- emptyObjectsPlaceholder,
490
- );
491
-
492
- /**
493
- * List of options filtered by "disabled" and "selected" signs
494
- * also by equality to null and undefined primitive values
495
- * or instance declarations
496
- * @function
497
- * @returns {Array} options
498
- */
499
- const availableOptions = computed(() => {
500
- let filteredOptions = restrictedOptions.value.filter((option) => {
501
- const availableOptionType = optionTypeRestrictor(option);
502
-
503
- if (!option || !availableOptionType) return false;
504
-
505
- if (!lookForSimpleOptions(option)) return false;
506
-
507
- if (selectedOptionsShown.value) return true;
508
-
509
- return lookForObjectOptions(option);
510
- });
511
-
512
- let finalOptionsList = filteredOptions;
513
-
514
- if (searchState.searchPattern) {
515
- finalOptionsList = filterBySearchPattern(filteredOptions);
516
- }
517
-
518
- return finalOptionsList;
519
- });
520
-
521
- /**
522
- * Defines a list of options list classes
523
- * @function
524
- * @returns {Array} classes
525
- */
526
- const classes = computed(() => {
527
- let theme = [];
528
-
529
- switch(themeType.value) {
530
- case "basic":
531
- theme.push("extended__multiselect-options");
532
- break;
533
- case "slate-grey":
534
- theme.push("extended__multiselect-options-slate-grey");
535
- break;
536
- case "slate-blue":
537
- theme.push("extended__multiselect-options-slate-blue");
538
- break;
539
- case "teal":
540
- theme.push("extended__multiselect-options-teal");
541
- break;
542
- case "strict":
543
- theme.push("extended__multiselect-options-strict");
544
- break;
545
- default:
546
- theme.push("extended__multiselect-options");
547
- }
548
-
549
- if (showMarker.value) {
550
- theme.push("extended__multiselect-options--marker");
551
- }
552
-
553
- if (chosenToggleAppearanceSide.value === "atop") {
554
- theme.push("extended__multiselect-options--atop");
555
- }
556
-
557
- return theme;
558
- });
559
-
560
- /**
561
- * Determines whether given options list is empty
562
- * @function
563
- * @returns {boolean} emptiness
564
- */
565
- const emptyOptionsList = computed(() => {
566
- return (!options.value.length || !options.value.filter((option) => !!option).length
567
- || !availableOptions.value.length) && !searchState.searchValue;
568
- });
569
-
570
- /**
571
- * Determines whether list of internal search results is empty
572
- * @function
573
- * @returns {boolean} emptiness
574
- */
575
- const emptySearchResult = computed(() => {
576
- return !availableOptions.value.length && !createOnTheGo.value && searchState.searchValue;
577
- });
578
-
579
- /**
580
- * Defines styles for "min-heigt", "max-height"
581
- * and "top" css-properties of options wrapper
582
- * @function
583
- * @returns {Object} styles
584
- */
585
- const heightFromProps = computed(() => {
586
- let heightRecord = {};
587
-
588
- if (chosenToggleAppearanceSide.value === "atop") {
589
- Object.defineProperty(heightRecord, "top", {
590
- enumerable: true,
591
- value: `-${toggleMaxHeight.value}px`,
592
- });
593
- }
594
-
595
- Object.defineProperty(heightRecord, "maxHeight", {
596
- enumerable: true,
597
- value: `${toggleMaxHeight.value}px`,
598
- });
599
-
600
- if (toggleMinHeight.value) {
601
- if (toggleMinHeight.value > toggleMaxHeight.value) {
602
- if (showInsertWarnings.value) {
603
- let errorMessage = "vue-extended-multiselect: «toggleMinHeight» property can not be greater than «toggleMaxHeight» property.";
604
- errorMessage += "«toggleMaxHeight» property was reset to default value of 400 pixels.";
605
- console.warn(errorMessage);
606
- }
607
-
608
- return Object.keys(heightRecord).length ? heightRecord : null;
609
- }
610
-
611
- Object.defineProperty(heightRecord, "minHeight", {
612
- enumerable: true,
613
- value: `${toggleMinHeight.value}px`,
614
- });
615
- }
616
-
617
- return Object.keys(heightRecord).length ? heightRecord : null;
618
- });
619
-
620
- /**
621
- * Determines whether maximal amount of options has been selected
622
- * @function
623
- * @returns {boolean} reaching
624
- */
625
- const maxOptionsWereSelected = computed(() => {
626
- return maxOptionsCount.value && multiple.value && selectedOptions.value.length === maxOptionsCount.value;
627
- });
628
-
629
- /**
630
- * Defines styles for "margin-top" css-property of marker element
631
- * @function
632
- * @returns {Object} styles
633
- */
634
- const markerShapeMargin = computed(() => {
635
- return { marginTop: "2px" };
636
- });
637
-
638
- /**
639
- * Determines whether minimal amount of options has not been selected
640
- * @function
641
- * @returns {boolean} reaching
642
- */
643
- const minOptionsWereNotSelected = computed(() => {
644
- return minOptionsCount.value && multiple.value && selectedOptions.value.length < minOptionsCount.value;
645
- });
646
-
647
- /**
648
- * Defines styles for "padding" and "height" css-property
649
- * of every option element
650
- * @function
651
- * @returns {Object} styles
652
- */
653
- const optionHeightByProps = computed(() => {
654
- const heightNumeric = typeof anyOptionWrapperBlockHeight.value === "number";
655
- let height = {
656
- height: heightNumeric ? `${anyOptionWrapperBlockHeight.value}px` : `${anyOptionWrapperBlockHeight.value}`,
657
- };
658
-
659
- if (optionsPadding.value.length) {
660
- const padding = {
661
- paddingTop: optionsPadding.value[0] ? `${optionsPadding.value[0]}px` : null,
662
- paddingLeft: optionsPadding.value[1] ? `${optionsPadding.value[1]}px` : null,
663
- paddingBottom: optionsPadding.value[2] ? `${optionsPadding.value[2]}px` : null,
664
- paddingRight: optionsPadding.value[3] ? `${optionsPadding.value[3]}px` : null,
665
- };
666
-
667
- return Object.assign(height, padding);
668
- }
669
-
670
- return height;
671
- });
672
-
673
- /**
674
- * Determines whether to show element with new custom option
675
- * @function
676
- * @returns {boolean} display
677
- */
678
- const showCreateNewOptionBlock = computed(() => {
679
- return createOnTheGo.value && !availableOptions.value.length && searchState.searchValue;
680
- });
681
-
682
- /**
683
- * Summarizes styles for options wrapper in combined collection
684
- * @function
685
- * @returns {Array} styles
686
- */
687
-
688
- const styles = computed(() => {
689
- return [
690
- heightFromProps.value,
691
- heightFromMounted,
692
- atopWithScroll.value,
693
- underWithScroll.value
694
- ];
695
- });
696
-
697
- /**
698
- * Toggles "border-bottom-right-radius", "border-bottom-right-radius"
699
- * and "top" css-properties of options wrapper
700
- * @function
701
- * @param {boolean} afterLoading - loading state flag
702
- */
703
- const calculateTopOffset = (afterLoading = false) => {
704
- nextTick(() => {
705
- if (!optionsWrapper.value) return;
706
-
707
- const offsetHeight = optionsWrapper.value.offsetHeight;
708
- const scrollHeight = optionsWrapper.value.scrollHeight;
709
-
710
- if (chosenToggleAppearanceSide.value === "atop") {
711
- if (scrollHeight > offsetHeight) {
712
- atopWithScroll.value = {
713
- borderTopRightRadius: 0,
714
- };
715
- }
716
-
717
- if (toggleMaxHeight.value >= offsetHeight || afterLoading) {
718
- heightFromMounted.top = `-${offsetHeight - 1}px`;
719
- }
720
- } else {
721
- if (scrollHeight > offsetHeight) {
722
- underWithScroll.value = {
723
- borderBottomRightRadius: 0,
724
- };
725
- }
726
- }
727
- });
728
- };
729
-
730
- /**
731
- * Restricts repeated selection of option
732
- * @function
733
- * @param {string} calculatedOptionLabel - displayed label of option
734
- */
735
- const compareWithSelected = (calculatedOptionLabel) => {
736
- return !selectedOptions.value.find((selectedOption) => {
737
- let calculatedSelectedOptionLabel;
738
-
739
- if (typeof selectedOption === "object") {
740
- if (Object.keys(selectedOption).length === 0) {
741
- calculatedSelectedOptionLabel = emptyObjectsPlaceholder.value;
742
- } else if (Array.isArray(selectedOption)) {
743
- calculatedSelectedOptionLabel = selectedOption.join(", ");
744
- } else {
745
- calculatedSelectedOptionLabel = typeof selectedOption[label.value] === "object"
746
- ? JSON.stringify(selectedOption[label.value])
747
- : selectedOption[label.value].toString();
748
- }
749
- } else {
750
- calculatedSelectedOptionLabel = selectedOption.toString();
751
- }
752
-
753
- return calculatedSelectedOptionLabel === calculatedOptionLabel;
754
- });
755
- };
756
-
757
- /**
758
- * Creates new option by users input
759
- * if "createOnTheGo" prop equals true
760
- * @function
761
- * @emits extended:create-option
762
- */
763
- const createNewOption = () => {
764
- if (loading.value) return;
765
-
766
- let newOption;
767
-
768
- switch(createOptionType.value) {
769
- case "primitive":
770
- newOption = searchState.searchValue;
771
- break;
772
- case "array":
773
- newOption = [searchState.searchValue];
774
- break;
775
- case "object":
776
- newOption = createObjectOption();
777
- break;
778
- }
779
-
780
- options.value.unshift(newOption);
781
- emitter.value.emit("extended:create-option", newOption);
782
-
783
- if (autoSelectCreatedOption.value) {
784
- selectOption(newOption, { target: { id: "extended__multiselect" } });
785
- setSearchValue(null);
786
- setSearchPattern(null);
787
- }
788
- };
789
-
790
- /**
791
- * Creates option of type object
792
- * if "createOptionType" equals "object"
793
- * @function
794
- * @returns {UnionPropType} option
795
- */
796
- const createObjectOption = () => {
797
- if (!createOptionFields.value) {
798
- if (showInsertWarnings.value) {
799
- console.warn("vue-extended-multiselect: if option should be object — option fields should not be empty");
800
- }
801
-
802
- return searchState.searchValue;
803
- }
804
-
805
- const newOption = {};
806
-
807
- createOptionFields.value.forEach((field) => {
808
- Object.defineProperty(newOption, field, {
809
- enumerable: true,
810
- writable: true,
811
- configurable: true,
812
- value: `${field}-${searchState.searchValue}`,
813
- });
814
- });
815
-
816
- return newOption;
817
- };
818
-
819
- /**
820
- * Recognises if option is disabled
821
- * @function
822
- * @param {UnionPropType} option - option to recognize
823
- * @returns {boolean} prohibition
824
- */
825
- const defineDisabledOption = (option) => {
826
- if (typeof option === "object" && !Array.isArray(option)) return false;
827
-
828
- let convertedOption;
829
- if (Array.isArray(option) && !option.length) {
830
- convertedOption = emptyObjectsPlaceholder.value;
831
- } else {
832
- convertedOption = option;
833
- }
834
-
835
- if (disabledPrimitiveOptionsConverted.value.includes(convertedOption)) return true;
836
-
837
- return false;
838
- };
839
-
840
- /**
841
- * Filters options list by pattern of internal search for available options
842
- * @function
843
- * @param {Array} optionsList - pre-filtered list of oprions
844
- * @returns {boolean} filter
845
- */
846
- const filterBySearchPattern = (optionsList) => {
847
- return optionsList.filter((option) => {
848
- if (typeof option === "object") {
849
- if (Array.isArray(option)) {
850
- return searchState.searchPattern.test(option.length ? option.join(", ") : emptyObjectsPlaceholder.value);
851
- }
852
-
853
- let internalSearchResult;
854
-
855
- if (searchByField.value.length) {
856
- if (!option[searchByField.value]) return false;
857
-
858
- internalSearchResult = option[searchByField.value].toString();
859
- } else {
860
- internalSearchResult = option[label.value].toString();
861
- }
862
-
863
- return searchState.searchPattern.test(internalSearchResult);
864
- } else {
865
- return searchState.searchPattern.test(option.toString());
866
- }
867
- });
868
- };
869
-
870
- /**
871
- * Blocks keys pressed in combination with "enter" key
872
- * for not to select options by them
873
- * @function
874
- * @param {KeyboardEvent} keyboardEvent - KeyboardEvent instance
875
- * @returns {boolean} block
876
- */
877
- const keyBlocker = (keyboardEvent) => {
878
- if (!keyboardEvent) return false;
879
-
880
- const altKeyBlock = specialKeysBlock.value.includes("alt");
881
- const ctrlKeyBlock = specialKeysBlock.value.includes("ctrl");
882
- const shiftKeyBlock = specialKeysBlock.value.includes("shift");
883
-
884
- if (altKeyBlock && keyboardEvent.altKey) return true;
885
- if (ctrlKeyBlock && keyboardEvent.ctrlKey) return true;
886
- if (shiftKeyBlock && keyboardEvent.shiftKey) return true;
887
-
888
- return false;
889
- }
890
-
891
- /**
892
- * Searchs for already selected options in particular
893
- * for options of type "object"
894
- * @function
895
- * @param {UnionPropType} option - option for search
896
- * @returns {boolean} selected
897
- */
898
- const lookForObjectOptions = (option) => {
899
- if (typeof option === "object") {
900
- let calculatedOptionLabel;
901
-
902
- if (Array.isArray(option) && !!option.length) {
903
- calculatedOptionLabel = option.join(", ");
904
- } else {
905
- const hasLabel = Object.getOwnPropertyNames(option).includes(label.value);
906
-
907
- if (hasLabel) {
908
- calculatedOptionLabel = typeof option[label.value] === "object"
909
- ? JSON.stringify(option[label.value])
910
- : option[label.value].toString();
911
- } else {
912
- calculatedOptionLabel = JSON.stringify(option);
913
- }
914
-
915
- if (Object.keys(option).length === 0) {
916
- calculatedOptionLabel = emptyObjectsPlaceholder.value;
917
- }
918
- }
919
-
920
- return compareWithSelected(calculatedOptionLabel);
921
- } else {
922
- return !selectedOptions.value.includes(option);
923
- }
924
- };
925
-
926
- /**
927
- * Searches for already selected options in particular
928
- * for options of primitive types or of type "function"
929
- * @function
930
- * @param {UnionPropType} option - option for search
931
- * @returns {boolean} selected
932
- */
933
- const lookForSimpleOptions = (option) => {
934
- if (typeof option === "object" && Object.keys(option).length === 0) {
935
- const emptyObject = selectedOptions.value.find((emptyObject) => {
936
- return typeof emptyObject === "object" && !Object.keys(emptyObject).length;
937
- });
938
-
939
- if (!emptyObject || selectedOptionsShown.value) return true;
940
-
941
- return false;
942
- }
943
-
944
- if (
945
- typeof option === "object"
946
- && !Array.isArray(option)
947
- && !Object.keys(option).includes(label.value)
948
- ) return false;
949
-
950
- return true;
951
- };
952
-
953
- /**
954
- * Defines a class for "marker" slot content
955
- * @function
956
- * @param {UnionPropType} option - option in options list
957
- * @returns {string} class
958
- */
959
- const markerShapeClass = (option) => {
960
- if (lookForSimpleOptions(option) && lookForObjectOptions(option)) {
961
- return "extended__multiselect-marker-shape--selected";
962
- }
963
-
964
- return "extended__multiselect-marker-shape";
965
- }
966
-
967
- /**
968
- * Creates role of every option element for accessible applications
969
- * if it needed
970
- * @function
971
- * @param {UnionPropType} option - each option from options list
972
- * @returns {string|null} role
973
- */
974
- const optionCreateRole = (option) => {
975
- if (optionIsDisabled(option)) return null;
976
- if (!option) return null;
977
-
978
- return "option";
979
- };
980
-
981
- /**
982
- * Determines whether option is disabled
983
- * @function
984
- * @param {UnionPropType} option - each option from options list
985
- * @returns {boolean} blocking
986
- */
987
- const optionIsDisabled = (option) => {
988
- if (option[disableByField.value] || defineDisabledOption(option)) return true;
989
-
990
- return false;
991
- }
992
-
993
- /**
994
- * Defines various classes for options dependent from props
995
- * @function
996
- * @param {UnionPropType} option - each option from options list
997
- * @returns {Array} classes
998
- */
999
- const optionHighlightClasses = (option) => {
1000
- let theme = [];
1001
-
1002
- if (highlightOptions.value) {
1003
- switch(themeType.value) {
1004
- case "basic":
1005
- theme.push("extended__multiselect-options_option");
1006
- break;
1007
- case "slate-grey":
1008
- theme.push("extended__multiselect-options_option-slate-grey");
1009
- break;
1010
- case "slate-blue":
1011
- theme.push("extended__multiselect-options_option-slate-blue");
1012
- break;
1013
- case "teal":
1014
- theme.push("extended__multiselect-options_option-teal");
1015
- break;
1016
- case "strict":
1017
- theme.push("extended__multiselect-options_option-strict");
1018
- break;
1019
- default:
1020
- theme.push("extended__multiselect-options_option");
1021
- }
1022
- }
1023
-
1024
- if (showMarker) {
1025
- theme.push("extended__multiselect-options_option--marker");
1026
- }
1027
-
1028
- if (option && option[disableByField.value]) {
1029
- theme.push("extended__multiselect-options_option--disabled");
1030
- }
1031
-
1032
- if (disabledPrimitiveOptionsConverted.value && option && defineDisabledOption(option)) {
1033
- theme.push("extended__multiselect-options_option--disabled");
1034
- }
1035
-
1036
- return theme;
1037
- };
1038
-
1039
- /**
1040
- * Selects option
1041
- * @function
1042
- * @emits extended:deselect-option
1043
- * @param {UnionPropType} option - option to select
1044
- * @param {MouseEvent|KeyboardEvent} clickEvent - MouseEvent or KeyboardEvent instance
1045
- */
1046
- const selectOption = (option, clickEvent) => {
1047
-
1048
- emitter.value.emit("extended:trigger-selection", false);
1049
-
1050
- if (!clickEvent) return;
1051
- if (keyBlocker(clickEvent)) return;
1052
- if (loading.value) return;
1053
- if (maxOptionsWereSelected.value) return;
1054
- if (option[disableByField.value] || defineDisabledOption(option)) return;
1055
- if (
1056
- clickEvent.target.id === "extended__multiselect-toggle"
1057
- || clickEvent.target.id === "extended__multiselect-cancel"
1058
- ) return;
1059
-
1060
- if (selectedOptionsShown.value || externalOptionsLoader.value) {
1061
- const optionDeselected = lookForObjectOptions(option);
1062
-
1063
- if (!optionDeselected) {
1064
- const index = selectedOptions.value.findIndex((selectedOption) => {
1065
- return JSON.stringify(selectedOption) === JSON.stringify(option);
1066
- });
1067
-
1068
- emitter.value.emit("extended:deselect-option", { skipNextRemoval: true, index });
1069
-
1070
- return;
1071
- }
1072
- }
1073
-
1074
- const isObject = typeof option === "object" && !Array.isArray(option);
1075
-
1076
- if (isObject && !Object.keys(option).includes(label.value)) {
1077
- if (showInsertWarnings.value) {
1078
- console.warn("vue-extended-multiselect: wrong label type inserted");
1079
- }
1080
- }
1081
-
1082
- selectOptionEmitter(option);
1083
- };
1084
-
1085
- /**
1086
- * Emits select events or clear event
1087
- * if prop "clearBySelectWhenMultiple" equals true
1088
- * @function
1089
- * @emits extended:clear-field
1090
- * @emits extended:select-option
1091
- * @param {UnionPropType} - option to select
1092
- */
1093
- const selectOptionEmitter = (option) => {
1094
- const isObjectOrArray = typeof option === "object";
1095
- const label = createLabel(isObjectOrArray, option);
1096
-
1097
- if (multiple.value) {
1098
- if (clearBySelectWhenMultiple.value) {
1099
- emitter.value.emit("extended:clear-field");
1100
- }
1101
-
1102
- emitter.value.emit("extended:select-option", {
1103
- label,
1104
- option,
1105
- });
1106
- } else {
1107
- emitter.value.emit("extended:select-option", {
1108
- label,
1109
- option,
1110
- });
1111
- }
1112
- };
1113
-
1114
- /**
1115
- * Determines an option which will be selected
1116
- * by pressing "enter" key on it
1117
- * @function
1118
- * @param {MouseEvent} event - MouseEvent instance
1119
- */
1120
- const setEnterIndex = (event) => {
1121
- enterIndex.value = event.target.getAttribute("enter-locator");
1122
- };
1123
-
1124
- /**
1125
- * Determines whether to show marker beside option by its selection
1126
- * @function
1127
- * @param {UnionPropType} option - each option from options list
1128
- * @returns {boolean} display
1129
- */
1130
- const showCurrentMarker = (option) => {
1131
- if (!lookForSimpleOptions(option) || !lookForObjectOptions(option)) {
1132
- return true;
1133
- }
1134
-
1135
- return false;
1136
- };
1137
-
1138
- /**
1139
- * Emits event which listener will add special class
1140
- * to search field before option selection
1141
- * @function
1142
- * @emits extended:trigger-selection
1143
- */
1144
- const triggerOptionBeforeSelection = () => {
1145
- if (fieldWasShown.value) {
1146
- emitter.value.emit("extended:trigger-selection", true);
1147
- }
1148
- };
1149
-
1150
- /**
1151
- * "onBeforeMount" hook of ExtendedMultiselectOptions component
1152
- * @listens extended:select-enter
1153
- * @listens extended:renew-field-forwarding
1154
- * @listens extended:reset-index
1155
- */
1156
- onBeforeMount(() => {
1157
- const objectFields = restrictedOptions.value.filter((option) => {
1158
- if (!option) return false;
1159
-
1160
- return typeof option === "object" && typeof option[label.value] === "object";
1161
- });
1162
-
1163
- if (objectFields.length && showInsertWarnings.value) {
1164
- console.warn("vue-extended-multiselect: «label» property can not be of type «object»");
1165
- }
1166
-
1167
- emitter.value.on("extended:select-enter", (keyboardEvent) => {
1168
- if (!enterIndex.value) return;
1169
-
1170
- const option = availableOptions.value[enterIndex.value];
1171
- selectOption(option, keyboardEvent);
1172
- });
1173
-
1174
- emitter.value.on("extended:renew-field-forwarding", (value) => {
1175
- fieldWasShown.value = value;
1176
- });
1177
-
1178
- emitter.value.on("extended:reset-index", () => {
1179
- enterIndex.value = null;
1180
- });
1181
- });
1182
-
1183
- /**
1184
- * "onMounted" hook of ExtendedMultiselectOptions component
1185
- */
1186
- onMounted(() => {
1187
- new ResizeObserver(() => {
1188
- calculateTopOffset();
1189
- }).observe(optionsWrapper.value);
1190
- });
1
+ <template>
2
+ <div
3
+ ref="optionsWrapper"
4
+ tabindex="-1"
5
+ :class="classes"
6
+ :style="styles"
7
+ >
8
+ <slot name="listHeader"></slot>
9
+ <div
10
+ v-if="showCreateNewOptionBlock"
11
+ class="extended__multiselect-option-create"
12
+ :class="optionHighlightClasses(null)"
13
+ @mousedown="createNewOption"
14
+ >
15
+ {{ searchState.searchValue }}
16
+ </div>
17
+ <slot
18
+ name="moreThanLimit"
19
+ v-if="maxOptionsWereSelected"
20
+ >
21
+ <span>Maximum limit of selected options was achieved</span>
22
+ </slot>
23
+ <slot
24
+ name="lessThanLimit"
25
+ v-if="minOptionsWereNotSelected"
26
+ >
27
+ <span>Minimum amount of selected options was not achieved</span>
28
+ </slot>
29
+ <div class="extended__multiselect-options_container">
30
+ <div
31
+ role="listbox"
32
+ v-for="(option, index) in availableOptions"
33
+ :key="index"
34
+ >
35
+ <div
36
+ v-if="option"
37
+ :aria-setsize="availableOptions.length"
38
+ :aria-posinset="index"
39
+ :aria-labelledby="`option-label-${index}`"
40
+ :aria-disabled="optionIsDisabled(option)"
41
+ :class="optionHighlightClasses(option)"
42
+ :style="optionHeightByProps"
43
+ :enter-locator="index"
44
+ :role="optionCreateRole(option)"
45
+ @click.stop="selectOption(option, $event)"
46
+ @keypress.stop="selectOption(option, $event)"
47
+ @mousedown="triggerOptionBeforeSelection"
48
+ @mouseenter.stop="setEnterIndex"
49
+ >
50
+ <slot
51
+ name="option"
52
+ :option="option"
53
+ :create-custom-option-label="createCustomOptionLabel"
54
+ >
55
+ <div class="extended__multiselect-marker">
56
+ <slot
57
+ name="marker"
58
+ :selected="showCurrentMarker(option)"
59
+ >
60
+ <div
61
+ v-if="showMarker && showCurrentMarker(option)"
62
+ :class="markerShapeClass(option)"
63
+ :style="markerShapeMargin"
64
+ >
65
+ </div>
66
+ <div
67
+ v-else-if="showMarker"
68
+ class="extended__multiselect-marker-shape-only"
69
+ >
70
+ </div>
71
+ </slot>
72
+ </div>
73
+ <span :id="`option-label-${index}`">
74
+ {{ optionCreateLabel(option) }}
75
+ </span>
76
+ </slot>
77
+ </div>
78
+ </div>
79
+ </div>
80
+ <slot
81
+ name="noResults"
82
+ v-if="emptySearchResult"
83
+ >
84
+ <span>No results were found by search</span>
85
+ </slot>
86
+ <slot
87
+ name="noOptions"
88
+ v-if="emptyOptionsList"
89
+ >
90
+ <span>Options list is empty</span>
91
+ </slot>
92
+ <slot name="listFooter"></slot>
93
+ </div>
94
+ </template>
95
+
96
+ <script setup>
97
+ import {
98
+ computed,
99
+ defineProps,
100
+ inject,
101
+ nextTick,
102
+ onBeforeMount,
103
+ onMounted,
104
+ reactive,
105
+ ref,
106
+ toRefs,
107
+ } from "vue";
108
+
109
+ import usePreselectedOptions from "../composition/preselected-options";
110
+ import useLabels from "../composition/labels";
111
+
112
+ import { UnionPropType } from "../sets/sets";
113
+
114
+ const props = defineProps({
115
+ /**
116
+ * Determines whether to immediately select just now created option
117
+ * @property {boolean} autoSelectCreatedOption
118
+ */
119
+ autoSelectCreatedOption: {
120
+ type: Boolean,
121
+ required: true,
122
+ },
123
+
124
+ /**
125
+ * Determines whether to show noResults slot
126
+ * and block with new option's text
127
+ * @property {boolean} createOnTheGo
128
+ */
129
+ createOnTheGo: {
130
+ type: Boolean,
131
+ required: true,
132
+ },
133
+
134
+ /**
135
+ * Determines whether to emit clear event
136
+ * by option selection
137
+ * @property {boolean} clearBySelectWhenMultiple
138
+ */
139
+ clearBySelectWhenMultiple: {
140
+ type: Boolean,
141
+ required: true,
142
+ },
143
+
144
+ /**
145
+ * Determines whether to define thematic class for
146
+ * every option
147
+ * @property {boolean} highlightOptions
148
+ */
149
+ highlightOptions: {
150
+ type: Boolean,
151
+ required: true,
152
+ },
153
+
154
+ /**
155
+ * Determines "loading" state of component
156
+ * that disables option selection
157
+ * @property {boolean} loading
158
+ */
159
+ loading: {
160
+ type: Boolean,
161
+ required: true,
162
+ },
163
+
164
+ /**
165
+ * Determines whether to use functionality of
166
+ * multiple select
167
+ * @property {boolean} multiple
168
+ */
169
+ multiple: {
170
+ type: Boolean,
171
+ required: true,
172
+ },
173
+
174
+ /**
175
+ * Determines whether to show selected options
176
+ * in options list
177
+ * @property {boolean} selectedOptionsShown
178
+ */
179
+ selectedOptionsShown: {
180
+ type: Boolean,
181
+ required: true,
182
+ },
183
+
184
+ /**
185
+ * Determines whether to log warnings about incorrect props
186
+ * @property {boolean} showInsertWarnings
187
+ */
188
+ showInsertWarnings: {
189
+ type: Boolean,
190
+ required: true,
191
+ },
192
+
193
+ /**
194
+ * Determines whether to show marker slot
195
+ * @property {boolean} showMarker
196
+ */
197
+ showMarker: {
198
+ type: Boolean,
199
+ required: true,
200
+ },
201
+
202
+ /**
203
+ * Defines class of options list placement after expanse
204
+ * @property {string} chosenToggleAppearanceSide
205
+ */
206
+ chosenToggleAppearanceSide: {
207
+ type: String,
208
+ required: true,
209
+ },
210
+
211
+ /**
212
+ * Determines type of option that will be created
213
+ * @property {string} createOptionType
214
+ */
215
+ createOptionType: {
216
+ type: String,
217
+ required: true,
218
+ },
219
+
220
+ /**
221
+ * Determines a field in options of type "object"
222
+ * which value will be used to disable such options.
223
+ * @property {string} disableByField
224
+ */
225
+ disableByField: {
226
+ type: String,
227
+ required: true,
228
+ },
229
+
230
+ /**
231
+ * Sets labels for options of type "object"
232
+ * or Array instances which length/keys length equals 0
233
+ * @property {string} emptyObjectsPlaceholder
234
+ */
235
+ emptyObjectsPlaceholder: {
236
+ type: String,
237
+ required: true,
238
+ },
239
+
240
+ /**
241
+ * Determines field of option which will be displayed as label
242
+ * @property {string} label
243
+ */
244
+ label: {
245
+ type: String,
246
+ required: true,
247
+ },
248
+
249
+ /**
250
+ * Determines field in options of type "object"
251
+ * to use in internal search.
252
+ * @property {string} searchByField
253
+ */
254
+ searchByField: {
255
+ type: String,
256
+ required: true,
257
+ },
258
+
259
+ /**
260
+ * Current theme of extended-multiselect
261
+ * used in class definition
262
+ * @property {string} themeType
263
+ */
264
+ themeType: {
265
+ type: String,
266
+ required: true,
267
+ },
268
+
269
+ /**
270
+ * Determines maximal limit of selected options
271
+ * @property {number|null} maxOptionsCount
272
+ */
273
+ maxOptionsCount: {
274
+ type: Number,
275
+ default: null,
276
+ },
277
+
278
+ /**
279
+ * Determines minimal limit of selected options
280
+ * @property {number|null} minOptionsCount
281
+ */
282
+ minOptionsCount: {
283
+ type: Number,
284
+ default: null,
285
+ },
286
+
287
+ /**
288
+ * Defines value of "max-height" css-property of options list
289
+ * @property {number} toggleMaxHeight
290
+ */
291
+ toggleMaxHeight: {
292
+ type: Number,
293
+ required: true,
294
+ },
295
+
296
+ /**
297
+ * Defines value of "min-height" css-property of options list
298
+ * @property {number} toggleMinHeight
299
+ */
300
+ toggleMinHeight: {
301
+ type: Number,
302
+ default: null,
303
+ },
304
+
305
+ /**
306
+ * List of fields for new options of type "object" created by user
307
+ * if "createOnTheGo" prop equals true
308
+ * Each field will have basic value of "searchValue" prop
309
+ * @property {Array} createOptionFields
310
+ */
311
+ createOptionFields: {
312
+ type: Array,
313
+ required: true,
314
+ },
315
+
316
+ /**
317
+ * Searches for options with listed primitive values
318
+ * and disables it
319
+ * @property {Array} disabledPrimitiveOptionsConverted
320
+ */
321
+ disabledPrimitiveOptionsConverted: {
322
+ type: Array,
323
+ required: true,
324
+ },
325
+
326
+ /**
327
+ * Unfiltered options list
328
+ * @property {Array} options
329
+ */
330
+ options: {
331
+ type: Array,
332
+ required: true,
333
+ },
334
+
335
+ /**
336
+ * Defines value of "padding" css-property of every option
337
+ * @property {Array} optionsPadding
338
+ */
339
+ optionsPadding: {
340
+ type: Array,
341
+ required: true,
342
+ },
343
+
344
+ /**
345
+ * List of options which should be selected by default
346
+ * if "multiple" prop equals true
347
+ * @property {Array} preselectedOptions
348
+ */
349
+ preselectedOptions: {
350
+ type: Array,
351
+ required: true,
352
+ },
353
+
354
+ /**
355
+ * List of options filtered by maximal available options amount
356
+ * @property {Array} restrictedOptions
357
+ */
358
+ restrictedOptions: {
359
+ type: Array,
360
+ required: true,
361
+ },
362
+
363
+ /**
364
+ * List of selected options or list with single selected option
365
+ * if "multiple" prop equals false
366
+ * @property {Array} selectedOptions
367
+ */
368
+ selectedOptions: {
369
+ type: Array,
370
+ required: true,
371
+ },
372
+
373
+ /**
374
+ * List of key names that in combination with "enter" key
375
+ * should cancel option selection
376
+ * @property {Array} specialKeysBlock
377
+ */
378
+ specialKeysBlock: {
379
+ type: Array,
380
+ required: true,
381
+ },
382
+
383
+ /**
384
+ * Reactive instance of LocalEmitter class
385
+ * @property {object} emitter
386
+ */
387
+ emitter: {
388
+ type: Object,
389
+ required: true,
390
+ },
391
+
392
+ /**
393
+ * Creates custom label for every option in options list
394
+ * @property {Function} createCustomOptionLabel
395
+ */
396
+ createCustomOptionLabel: {
397
+ type: Function,
398
+ required: true,
399
+ },
400
+
401
+ /**
402
+ * Loader function provided by user.
403
+ * @property {Function} externalOptionsLoader
404
+ * @default null
405
+ * @param {string} value - value of search field
406
+ */
407
+ externalOptionsLoader: {
408
+ type: Function,
409
+ default: null,
410
+ },
411
+
412
+ /**
413
+ * Defines "height" css-property of every option element
414
+ * @property {number} anyOptionWrapperBlockHeight
415
+ */
416
+ anyOptionWrapperBlockHeight: {
417
+ type: [Number, String],
418
+ required: true,
419
+ },
420
+
421
+ /**
422
+ * Option which should be selected by default
423
+ * if "multiple" prop equals false
424
+ * @property {UnionPropType|null} preselectedOption
425
+ */
426
+ preselectedOption: {
427
+ type: UnionPropType,
428
+ default: null,
429
+ },
430
+ });
431
+
432
+ const searchState = inject("searchState");
433
+ const setSearchValue = inject("setSearchValue");
434
+ const setSearchPattern = inject("setSearchPattern");
435
+
436
+ const fieldWasShown = ref(false);
437
+ const atopWithScroll = ref(null);
438
+ const enterIndex = ref(null);
439
+ const heightFromMounted = reactive({});
440
+ const underWithScroll = ref(null);
441
+
442
+ /**
443
+ * Element references
444
+ */
445
+ const optionsWrapper = ref(null);
446
+
447
+ const {
448
+ anyOptionWrapperBlockHeight,
449
+ autoSelectCreatedOption,
450
+ chosenToggleAppearanceSide,
451
+ clearBySelectWhenMultiple,
452
+ createOnTheGo,
453
+ createCustomOptionLabel,
454
+ createOptionFields,
455
+ createOptionType,
456
+ disableByField,
457
+ disabledPrimitiveOptionsConverted,
458
+ emitter,
459
+ emptyObjectsPlaceholder,
460
+ highlightOptions,
461
+ loading,
462
+ label,
463
+ searchByField,
464
+ maxOptionsCount,
465
+ minOptionsCount,
466
+ multiple,
467
+ options,
468
+ optionsPadding,
469
+ restrictedOptions,
470
+ selectedOptions,
471
+ selectedOptionsShown,
472
+ showInsertWarnings,
473
+ showMarker,
474
+ specialKeysBlock,
475
+ themeType,
476
+ toggleMaxHeight,
477
+ toggleMinHeight,
478
+ externalOptionsLoader,
479
+ } = toRefs(props);
480
+
481
+ const { createLabel, optionTypeRestrictor } = usePreselectedOptions(
482
+ label,
483
+ emptyObjectsPlaceholder,
484
+ showInsertWarnings,
485
+ );
486
+ const { optionCreateLabel } = useLabels(
487
+ label,
488
+ createCustomOptionLabel,
489
+ emptyObjectsPlaceholder,
490
+ );
491
+
492
+ /**
493
+ * List of options filtered by "disabled" and "selected" signs
494
+ * also by equality to null and undefined primitive values
495
+ * or instance declarations
496
+ * @function
497
+ * @returns {Array} options
498
+ */
499
+ const availableOptions = computed(() => {
500
+ let filteredOptions = restrictedOptions.value.filter((option) => {
501
+ const availableOptionType = optionTypeRestrictor(option);
502
+
503
+ if (!option || !availableOptionType) return false;
504
+
505
+ if (!lookForSimpleOptions(option)) return false;
506
+
507
+ if (selectedOptionsShown.value) return true;
508
+
509
+ return lookForObjectOptions(option);
510
+ });
511
+
512
+ let finalOptionsList = filteredOptions;
513
+
514
+ if (searchState.searchPattern) {
515
+ finalOptionsList = filterBySearchPattern(filteredOptions);
516
+ }
517
+
518
+ return finalOptionsList;
519
+ });
520
+
521
+ /**
522
+ * Defines a list of options list classes
523
+ * @function
524
+ * @returns {Array} classes
525
+ */
526
+ const classes = computed(() => {
527
+ let theme = [];
528
+
529
+ switch(themeType.value) {
530
+ case "basic":
531
+ theme.push("extended__multiselect-options");
532
+ break;
533
+ case "slate-grey":
534
+ theme.push("extended__multiselect-options-slate-grey");
535
+ break;
536
+ case "slate-blue":
537
+ theme.push("extended__multiselect-options-slate-blue");
538
+ break;
539
+ case "teal":
540
+ theme.push("extended__multiselect-options-teal");
541
+ break;
542
+ case "strict":
543
+ theme.push("extended__multiselect-options-strict");
544
+ break;
545
+ default:
546
+ theme.push("extended__multiselect-options");
547
+ }
548
+
549
+ if (showMarker.value) {
550
+ theme.push("extended__multiselect-options--marker");
551
+ }
552
+
553
+ if (chosenToggleAppearanceSide.value === "atop") {
554
+ theme.push("extended__multiselect-options--atop");
555
+ }
556
+
557
+ return theme;
558
+ });
559
+
560
+ /**
561
+ * Determines whether given options list is empty
562
+ * @function
563
+ * @returns {boolean} emptiness
564
+ */
565
+ const emptyOptionsList = computed(() => {
566
+ return (!options.value.length || !options.value.filter((option) => !!option).length
567
+ || !availableOptions.value.length) && !searchState.searchValue;
568
+ });
569
+
570
+ /**
571
+ * Determines whether list of internal search results is empty
572
+ * @function
573
+ * @returns {boolean} emptiness
574
+ */
575
+ const emptySearchResult = computed(() => {
576
+ return !availableOptions.value.length && !createOnTheGo.value && searchState.searchValue;
577
+ });
578
+
579
+ /**
580
+ * Defines styles for "min-heigt", "max-height"
581
+ * and "top" css-properties of options wrapper
582
+ * @function
583
+ * @returns {Object} styles
584
+ */
585
+ const heightFromProps = computed(() => {
586
+ let heightRecord = {};
587
+
588
+ if (chosenToggleAppearanceSide.value === "atop") {
589
+ Object.defineProperty(heightRecord, "top", {
590
+ enumerable: true,
591
+ value: `-${toggleMaxHeight.value}px`,
592
+ });
593
+ }
594
+
595
+ Object.defineProperty(heightRecord, "maxHeight", {
596
+ enumerable: true,
597
+ value: `${toggleMaxHeight.value}px`,
598
+ });
599
+
600
+ if (toggleMinHeight.value) {
601
+ if (toggleMinHeight.value > toggleMaxHeight.value) {
602
+ if (showInsertWarnings.value) {
603
+ let errorMessage = "vue-extended-multiselect: «toggleMinHeight» property can not be greater than «toggleMaxHeight» property.";
604
+ errorMessage += "«toggleMaxHeight» property was reset to default value of 400 pixels.";
605
+ console.warn(errorMessage);
606
+ }
607
+
608
+ return Object.keys(heightRecord).length ? heightRecord : null;
609
+ }
610
+
611
+ Object.defineProperty(heightRecord, "minHeight", {
612
+ enumerable: true,
613
+ value: `${toggleMinHeight.value}px`,
614
+ });
615
+ }
616
+
617
+ return Object.keys(heightRecord).length ? heightRecord : null;
618
+ });
619
+
620
+ /**
621
+ * Determines whether maximal amount of options has been selected
622
+ * @function
623
+ * @returns {boolean} reaching
624
+ */
625
+ const maxOptionsWereSelected = computed(() => {
626
+ return maxOptionsCount.value && multiple.value && selectedOptions.value.length === maxOptionsCount.value;
627
+ });
628
+
629
+ /**
630
+ * Defines styles for "margin-top" css-property of marker element
631
+ * @function
632
+ * @returns {Object} styles
633
+ */
634
+ const markerShapeMargin = computed(() => {
635
+ return { marginTop: "2px" };
636
+ });
637
+
638
+ /**
639
+ * Determines whether minimal amount of options has not been selected
640
+ * @function
641
+ * @returns {boolean} reaching
642
+ */
643
+ const minOptionsWereNotSelected = computed(() => {
644
+ return minOptionsCount.value && multiple.value && selectedOptions.value.length < minOptionsCount.value;
645
+ });
646
+
647
+ /**
648
+ * Defines styles for "padding" and "height" css-property
649
+ * of every option element
650
+ * @function
651
+ * @returns {Object} styles
652
+ */
653
+ const optionHeightByProps = computed(() => {
654
+ const heightNumeric = typeof anyOptionWrapperBlockHeight.value === "number";
655
+ let height = {
656
+ height: heightNumeric ? `${anyOptionWrapperBlockHeight.value}px` : `${anyOptionWrapperBlockHeight.value}`,
657
+ };
658
+
659
+ if (optionsPadding.value.length) {
660
+ const padding = {
661
+ paddingTop: optionsPadding.value[0] ? `${optionsPadding.value[0]}px` : null,
662
+ paddingLeft: optionsPadding.value[1] ? `${optionsPadding.value[1]}px` : null,
663
+ paddingBottom: optionsPadding.value[2] ? `${optionsPadding.value[2]}px` : null,
664
+ paddingRight: optionsPadding.value[3] ? `${optionsPadding.value[3]}px` : null,
665
+ };
666
+
667
+ return Object.assign(height, padding);
668
+ }
669
+
670
+ return height;
671
+ });
672
+
673
+ /**
674
+ * Determines whether to show element with new custom option
675
+ * @function
676
+ * @returns {boolean} display
677
+ */
678
+ const showCreateNewOptionBlock = computed(() => {
679
+ return createOnTheGo.value && !availableOptions.value.length && searchState.searchValue;
680
+ });
681
+
682
+ /**
683
+ * Summarizes styles for options wrapper in combined collection
684
+ * @function
685
+ * @returns {Array} styles
686
+ */
687
+
688
+ const styles = computed(() => {
689
+ return [
690
+ heightFromProps.value,
691
+ heightFromMounted,
692
+ atopWithScroll.value,
693
+ underWithScroll.value
694
+ ];
695
+ });
696
+
697
+ /**
698
+ * Toggles "border-bottom-right-radius", "border-bottom-right-radius"
699
+ * and "top" css-properties of options wrapper
700
+ * @function
701
+ * @param {boolean} afterLoading - loading state flag
702
+ */
703
+ const calculateTopOffset = (afterLoading = false) => {
704
+ nextTick(() => {
705
+ if (!optionsWrapper.value) return;
706
+
707
+ const offsetHeight = optionsWrapper.value.offsetHeight;
708
+ const scrollHeight = optionsWrapper.value.scrollHeight;
709
+
710
+ if (chosenToggleAppearanceSide.value === "atop") {
711
+ if (scrollHeight > offsetHeight) {
712
+ atopWithScroll.value = {
713
+ borderTopRightRadius: 0,
714
+ };
715
+ }
716
+
717
+ if (toggleMaxHeight.value >= offsetHeight || afterLoading) {
718
+ heightFromMounted.top = `-${offsetHeight - 1}px`;
719
+ }
720
+ } else {
721
+ if (scrollHeight > offsetHeight) {
722
+ underWithScroll.value = {
723
+ borderBottomRightRadius: 0,
724
+ };
725
+ }
726
+ }
727
+ });
728
+ };
729
+
730
+ /**
731
+ * Restricts repeated selection of option
732
+ * @function
733
+ * @param {string} calculatedOptionLabel - displayed label of option
734
+ */
735
+ const compareWithSelected = (calculatedOptionLabel) => {
736
+ return !selectedOptions.value.find((selectedOption) => {
737
+ let calculatedSelectedOptionLabel;
738
+
739
+ if (typeof selectedOption === "object") {
740
+ if (Object.keys(selectedOption).length === 0) {
741
+ calculatedSelectedOptionLabel = emptyObjectsPlaceholder.value;
742
+ } else if (Array.isArray(selectedOption)) {
743
+ calculatedSelectedOptionLabel = selectedOption.join(", ");
744
+ } else {
745
+ calculatedSelectedOptionLabel = typeof selectedOption[label.value] === "object"
746
+ ? JSON.stringify(selectedOption[label.value])
747
+ : selectedOption[label.value].toString();
748
+ }
749
+ } else {
750
+ calculatedSelectedOptionLabel = selectedOption.toString();
751
+ }
752
+
753
+ return calculatedSelectedOptionLabel === calculatedOptionLabel;
754
+ });
755
+ };
756
+
757
+ /**
758
+ * Creates new option by users input
759
+ * if "createOnTheGo" prop equals true
760
+ * @function
761
+ * @emits extended:create-option
762
+ */
763
+ const createNewOption = () => {
764
+ if (loading.value) return;
765
+
766
+ let newOption;
767
+
768
+ switch(createOptionType.value) {
769
+ case "primitive":
770
+ newOption = searchState.searchValue;
771
+ break;
772
+ case "array":
773
+ newOption = [searchState.searchValue];
774
+ break;
775
+ case "object":
776
+ newOption = createObjectOption();
777
+ break;
778
+ }
779
+
780
+ options.value.unshift(newOption);
781
+ emitter.value.emit("extended:create-option", newOption);
782
+
783
+ if (autoSelectCreatedOption.value) {
784
+ selectOption(newOption, { target: { id: "extended__multiselect" } });
785
+ setSearchValue(null);
786
+ setSearchPattern(null);
787
+ }
788
+ };
789
+
790
+ /**
791
+ * Creates option of type object
792
+ * if "createOptionType" equals "object"
793
+ * @function
794
+ * @returns {UnionPropType} option
795
+ */
796
+ const createObjectOption = () => {
797
+ if (!createOptionFields.value) {
798
+ if (showInsertWarnings.value) {
799
+ console.warn("vue-extended-multiselect: if option should be object — option fields should not be empty");
800
+ }
801
+
802
+ return searchState.searchValue;
803
+ }
804
+
805
+ const newOption = {};
806
+
807
+ createOptionFields.value.forEach((field) => {
808
+ Object.defineProperty(newOption, field, {
809
+ enumerable: true,
810
+ writable: true,
811
+ configurable: true,
812
+ value: `${field}-${searchState.searchValue}`,
813
+ });
814
+ });
815
+
816
+ return newOption;
817
+ };
818
+
819
+ /**
820
+ * Recognises if option is disabled
821
+ * @function
822
+ * @param {UnionPropType} option - option to recognize
823
+ * @returns {boolean} prohibition
824
+ */
825
+ const defineDisabledOption = (option) => {
826
+ if (typeof option === "object" && !Array.isArray(option)) return false;
827
+
828
+ let convertedOption;
829
+ if (Array.isArray(option) && !option.length) {
830
+ convertedOption = emptyObjectsPlaceholder.value;
831
+ } else {
832
+ convertedOption = option;
833
+ }
834
+
835
+ if (disabledPrimitiveOptionsConverted.value.includes(convertedOption)) return true;
836
+
837
+ return false;
838
+ };
839
+
840
+ /**
841
+ * Filters options list by pattern of internal search for available options
842
+ * @function
843
+ * @param {Array} optionsList - pre-filtered list of oprions
844
+ * @returns {boolean} filter
845
+ */
846
+ const filterBySearchPattern = (optionsList) => {
847
+ return optionsList.filter((option) => {
848
+ if (typeof option === "object") {
849
+ if (Array.isArray(option)) {
850
+ return searchState.searchPattern.test(option.length ? option.join(", ") : emptyObjectsPlaceholder.value);
851
+ }
852
+
853
+ let internalSearchResult;
854
+
855
+ if (searchByField.value.length) {
856
+ if (!option[searchByField.value]) return false;
857
+
858
+ internalSearchResult = option[searchByField.value].toString();
859
+ } else {
860
+ internalSearchResult = option[label.value].toString();
861
+ }
862
+
863
+ return searchState.searchPattern.test(internalSearchResult);
864
+ } else {
865
+ return searchState.searchPattern.test(option.toString());
866
+ }
867
+ });
868
+ };
869
+
870
+ /**
871
+ * Blocks keys pressed in combination with "enter" key
872
+ * for not to select options by them
873
+ * @function
874
+ * @param {KeyboardEvent} keyboardEvent - KeyboardEvent instance
875
+ * @returns {boolean} block
876
+ */
877
+ const keyBlocker = (keyboardEvent) => {
878
+ if (!keyboardEvent) return false;
879
+
880
+ const altKeyBlock = specialKeysBlock.value.includes("alt");
881
+ const ctrlKeyBlock = specialKeysBlock.value.includes("ctrl");
882
+ const shiftKeyBlock = specialKeysBlock.value.includes("shift");
883
+
884
+ if (altKeyBlock && keyboardEvent.altKey) return true;
885
+ if (ctrlKeyBlock && keyboardEvent.ctrlKey) return true;
886
+ if (shiftKeyBlock && keyboardEvent.shiftKey) return true;
887
+
888
+ return false;
889
+ }
890
+
891
+ /**
892
+ * Searchs for already selected options in particular
893
+ * for options of type "object"
894
+ * @function
895
+ * @param {UnionPropType} option - option for search
896
+ * @returns {boolean} selected
897
+ */
898
+ const lookForObjectOptions = (option) => {
899
+ if (typeof option === "object") {
900
+ let calculatedOptionLabel;
901
+
902
+ if (Array.isArray(option) && !!option.length) {
903
+ calculatedOptionLabel = option.join(", ");
904
+ } else {
905
+ const hasLabel = Object.getOwnPropertyNames(option).includes(label.value);
906
+
907
+ if (hasLabel) {
908
+ calculatedOptionLabel = typeof option[label.value] === "object"
909
+ ? JSON.stringify(option[label.value])
910
+ : option[label.value].toString();
911
+ } else {
912
+ calculatedOptionLabel = JSON.stringify(option);
913
+ }
914
+
915
+ if (Object.keys(option).length === 0) {
916
+ calculatedOptionLabel = emptyObjectsPlaceholder.value;
917
+ }
918
+ }
919
+
920
+ return compareWithSelected(calculatedOptionLabel);
921
+ } else {
922
+ return !selectedOptions.value.includes(option);
923
+ }
924
+ };
925
+
926
+ /**
927
+ * Searches for already selected options in particular
928
+ * for options of primitive types or of type "function"
929
+ * @function
930
+ * @param {UnionPropType} option - option for search
931
+ * @returns {boolean} selected
932
+ */
933
+ const lookForSimpleOptions = (option) => {
934
+ if (typeof option === "object" && Object.keys(option).length === 0) {
935
+ const emptyObject = selectedOptions.value.find((emptyObject) => {
936
+ return typeof emptyObject === "object" && !Object.keys(emptyObject).length;
937
+ });
938
+
939
+ if (!emptyObject || selectedOptionsShown.value) return true;
940
+
941
+ return false;
942
+ }
943
+
944
+ if (
945
+ typeof option === "object"
946
+ && !Array.isArray(option)
947
+ && !Object.keys(option).includes(label.value)
948
+ ) return false;
949
+
950
+ return true;
951
+ };
952
+
953
+ /**
954
+ * Defines a class for "marker" slot content
955
+ * @function
956
+ * @param {UnionPropType} option - option in options list
957
+ * @returns {string} class
958
+ */
959
+ const markerShapeClass = (option) => {
960
+ if (lookForSimpleOptions(option) && lookForObjectOptions(option)) {
961
+ return "extended__multiselect-marker-shape--selected";
962
+ }
963
+
964
+ return "extended__multiselect-marker-shape";
965
+ }
966
+
967
+ /**
968
+ * Creates role of every option element for accessible applications
969
+ * if it needed
970
+ * @function
971
+ * @param {UnionPropType} option - each option from options list
972
+ * @returns {string|null} role
973
+ */
974
+ const optionCreateRole = (option) => {
975
+ if (optionIsDisabled(option)) return null;
976
+ if (!option) return null;
977
+
978
+ return "option";
979
+ };
980
+
981
+ /**
982
+ * Determines whether option is disabled
983
+ * @function
984
+ * @param {UnionPropType} option - each option from options list
985
+ * @returns {boolean} blocking
986
+ */
987
+ const optionIsDisabled = (option) => {
988
+ if (option[disableByField.value] || defineDisabledOption(option)) return true;
989
+
990
+ return false;
991
+ }
992
+
993
+ /**
994
+ * Defines various classes for options dependent from props
995
+ * @function
996
+ * @param {UnionPropType} option - each option from options list
997
+ * @returns {Array} classes
998
+ */
999
+ const optionHighlightClasses = (option) => {
1000
+ let theme = [];
1001
+
1002
+ if (highlightOptions.value) {
1003
+ switch(themeType.value) {
1004
+ case "basic":
1005
+ theme.push("extended__multiselect-options_option");
1006
+ break;
1007
+ case "slate-grey":
1008
+ theme.push("extended__multiselect-options_option-slate-grey");
1009
+ break;
1010
+ case "slate-blue":
1011
+ theme.push("extended__multiselect-options_option-slate-blue");
1012
+ break;
1013
+ case "teal":
1014
+ theme.push("extended__multiselect-options_option-teal");
1015
+ break;
1016
+ case "strict":
1017
+ theme.push("extended__multiselect-options_option-strict");
1018
+ break;
1019
+ default:
1020
+ theme.push("extended__multiselect-options_option");
1021
+ }
1022
+ }
1023
+
1024
+ if (showMarker) {
1025
+ theme.push("extended__multiselect-options_option--marker");
1026
+ }
1027
+
1028
+ if (option && option[disableByField.value]) {
1029
+ theme.push("extended__multiselect-options_option--disabled");
1030
+ }
1031
+
1032
+ if (disabledPrimitiveOptionsConverted.value && option && defineDisabledOption(option)) {
1033
+ theme.push("extended__multiselect-options_option--disabled");
1034
+ }
1035
+
1036
+ return theme;
1037
+ };
1038
+
1039
+ /**
1040
+ * Selects option
1041
+ * @function
1042
+ * @emits extended:deselect-option
1043
+ * @param {UnionPropType} option - option to select
1044
+ * @param {MouseEvent|KeyboardEvent} clickEvent - MouseEvent or KeyboardEvent instance
1045
+ */
1046
+ const selectOption = (option, clickEvent) => {
1047
+
1048
+ emitter.value.emit("extended:trigger-selection", false);
1049
+
1050
+ if (!clickEvent) return;
1051
+ if (keyBlocker(clickEvent)) return;
1052
+ if (loading.value) return;
1053
+ if (maxOptionsWereSelected.value) return;
1054
+ if (option[disableByField.value] || defineDisabledOption(option)) return;
1055
+ if (
1056
+ clickEvent.target.id === "extended__multiselect-toggle"
1057
+ || clickEvent.target.id === "extended__multiselect-cancel"
1058
+ ) return;
1059
+
1060
+ if (selectedOptionsShown.value || externalOptionsLoader.value) {
1061
+ const optionDeselected = lookForObjectOptions(option);
1062
+
1063
+ if (!optionDeselected) {
1064
+ const index = selectedOptions.value.findIndex((selectedOption) => {
1065
+ return JSON.stringify(selectedOption) === JSON.stringify(option);
1066
+ });
1067
+
1068
+ emitter.value.emit("extended:deselect-option", { skipNextRemoval: true, index });
1069
+
1070
+ return;
1071
+ }
1072
+ }
1073
+
1074
+ const isObject = typeof option === "object" && !Array.isArray(option);
1075
+
1076
+ if (isObject && !Object.keys(option).includes(label.value)) {
1077
+ if (showInsertWarnings.value) {
1078
+ console.warn("vue-extended-multiselect: wrong label type inserted");
1079
+ }
1080
+ }
1081
+
1082
+ selectOptionEmitter(option);
1083
+ };
1084
+
1085
+ /**
1086
+ * Emits select events or clear event
1087
+ * if prop "clearBySelectWhenMultiple" equals true
1088
+ * @function
1089
+ * @emits extended:clear-field
1090
+ * @emits extended:select-option
1091
+ * @param {UnionPropType} - option to select
1092
+ */
1093
+ const selectOptionEmitter = (option) => {
1094
+ const isObjectOrArray = typeof option === "object";
1095
+ const label = createLabel(isObjectOrArray, option);
1096
+
1097
+ if (multiple.value) {
1098
+ if (clearBySelectWhenMultiple.value) {
1099
+ emitter.value.emit("extended:clear-field");
1100
+ }
1101
+
1102
+ emitter.value.emit("extended:select-option", {
1103
+ label,
1104
+ option,
1105
+ });
1106
+ } else {
1107
+ emitter.value.emit("extended:select-option", {
1108
+ label,
1109
+ option,
1110
+ });
1111
+ }
1112
+ };
1113
+
1114
+ /**
1115
+ * Determines an option which will be selected
1116
+ * by pressing "enter" key on it
1117
+ * @function
1118
+ * @param {MouseEvent} event - MouseEvent instance
1119
+ */
1120
+ const setEnterIndex = (event) => {
1121
+ enterIndex.value = event.target.getAttribute("enter-locator");
1122
+ };
1123
+
1124
+ /**
1125
+ * Determines whether to show marker beside option by its selection
1126
+ * @function
1127
+ * @param {UnionPropType} option - each option from options list
1128
+ * @returns {boolean} display
1129
+ */
1130
+ const showCurrentMarker = (option) => {
1131
+ if (!lookForSimpleOptions(option) || !lookForObjectOptions(option)) {
1132
+ return true;
1133
+ }
1134
+
1135
+ return false;
1136
+ };
1137
+
1138
+ /**
1139
+ * Emits event which listener will add special class
1140
+ * to search field before option selection
1141
+ * @function
1142
+ * @emits extended:trigger-selection
1143
+ */
1144
+ const triggerOptionBeforeSelection = () => {
1145
+ if (fieldWasShown.value) {
1146
+ emitter.value.emit("extended:trigger-selection", true);
1147
+ }
1148
+ };
1149
+
1150
+ /**
1151
+ * "onBeforeMount" hook of ExtendedMultiselectOptions component
1152
+ * @listens extended:select-enter
1153
+ * @listens extended:renew-field-forwarding
1154
+ * @listens extended:reset-index
1155
+ */
1156
+ onBeforeMount(() => {
1157
+ const objectFields = restrictedOptions.value.filter((option) => {
1158
+ if (!option) return false;
1159
+
1160
+ return typeof option === "object" && typeof option[label.value] === "object";
1161
+ });
1162
+
1163
+ if (objectFields.length && showInsertWarnings.value) {
1164
+ console.warn("vue-extended-multiselect: «label» property can not be of type «object»");
1165
+ }
1166
+
1167
+ emitter.value.on("extended:select-enter", (keyboardEvent) => {
1168
+ if (!enterIndex.value) return;
1169
+
1170
+ const option = availableOptions.value[enterIndex.value];
1171
+ selectOption(option, keyboardEvent);
1172
+ });
1173
+
1174
+ emitter.value.on("extended:renew-field-forwarding", (value) => {
1175
+ fieldWasShown.value = value;
1176
+ });
1177
+
1178
+ emitter.value.on("extended:reset-index", () => {
1179
+ enterIndex.value = null;
1180
+ });
1181
+ });
1182
+
1183
+ /**
1184
+ * "onMounted" hook of ExtendedMultiselectOptions component
1185
+ */
1186
+ onMounted(() => {
1187
+ new ResizeObserver(() => {
1188
+ calculateTopOffset();
1189
+ }).observe(optionsWrapper.value);
1190
+ });
1191
1191
  </script>