vue3-extended-multiselect 1.4.1 → 1.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/.browserslistrc +3 -3
  2. package/.eslintrc.js +34 -34
  3. package/.github/workflows/publish.yml +41 -41
  4. package/.nvmrc +0 -0
  5. package/CHANGELOG.md +185 -181
  6. package/LICENSE +21 -21
  7. package/README.md +266 -266
  8. package/babel.config.js +5 -5
  9. package/index.js +2 -2
  10. package/jest.config.js +61 -61
  11. package/package.json +47 -47
  12. package/src/assets/base-arrow.svg +70 -70
  13. package/src/assets/cancel.svg +34 -34
  14. package/src/assets/circle-arrow.svg +7 -7
  15. package/src/assets/double-arrow.svg +39 -39
  16. package/src/assets/inner-arrow.svg +8 -8
  17. package/src/assets/loader.svg +5 -5
  18. package/src/assets/triangle-arrow.svg +72 -72
  19. package/src/assets/triangle-circle-arrow.svg +38 -38
  20. package/src/assets/wide-arrow.svg +72 -72
  21. package/src/components/ExtendedMultiselectCancel.vue +166 -166
  22. package/src/components/ExtendedMultiselectInput.vue +687 -687
  23. package/src/components/ExtendedMultiselectLoader.vue +182 -182
  24. package/src/components/ExtendedMultiselectMultiple.vue +320 -320
  25. package/src/components/ExtendedMultiselectOptions.vue +1144 -1144
  26. package/src/components/ExtendedMultiselectToggle.vue +273 -273
  27. package/src/components/Vue3ExtendedMultiselect.vue +1752 -1752
  28. package/src/composition/cancel.js +38 -38
  29. package/src/composition/image-path.js +16 -16
  30. package/src/composition/labels.js +41 -41
  31. package/src/composition/preselected-options.js +67 -67
  32. package/src/composition/search-value.js +33 -33
  33. package/src/composition/sizes.js +42 -42
  34. package/src/composition/toggle.js +33 -33
  35. package/src/events/LocalEmitter.js +31 -31
  36. package/src/events/emitter.js +2 -2
  37. package/src/sets/sets.js +99 -99
  38. package/src/styles/animations.css +18 -18
  39. package/src/styles/main.css +441 -441
  40. package/src/styles/variables.css +49 -49
  41. package/tests/unit/events.spec.js +138 -138
  42. package/tests/unit/props.spec.js +1099 -1099
  43. package/tests/utils/mount.js +37 -37
  44. package/tests/utils/utils.js +20 -20
  45. package/typings/vue3-extended-multiselect.d.ts +43 -43
@@ -1,688 +1,688 @@
1
- <template>
2
- <div v-if="showSearchField">
3
- <input
4
- aria-controls="extended-search-field"
5
- ref="extendedInput"
6
- type="text"
7
- :accesskey="attrs.accesskey"
8
- :autocomplete="attrs.autocomplete"
9
- :class="searchFieldClass"
10
- :disabled="disabled"
11
- :id="inputId"
12
- :name="attrs.name"
13
- :placeholder="appropriatePlaceholder"
14
- :spellcheck="attrs.spellcheck"
15
- :tabindex="attrs.tabindex"
16
- :translate="attrs.translate"
17
- v-model="searchValue"
18
- @blur.prevent="rollUp"
19
- @focus.prevent="expand"
20
- @input="search"
21
- />
22
- <div
23
- class="extended__multiselect-block"
24
- v-show="!searchFieldForwarding && !multiple"
25
- @click.stop="expand"
26
- >
27
- <slot
28
- name="labelBlock"
29
- :label-block-value="singleLabel"
30
- >
31
- <span>{{ singleLabel }}</span>
32
- </slot>
33
- </div>
34
- <extended-multiselect-multiple
35
- v-show="multiple && !!selectedOptions.length"
36
- :style="multipleBlocksMargin"
37
- :disabled="disabled"
38
- :loading="loading"
39
- :toggle-multiple-blocks-limit="toggleMultipleBlocksLimit"
40
- :emitter-unique-id="emitterUniqueId"
41
- :empty-objects-placeholder="emptyObjectsPlaceholder"
42
- :label="label"
43
- :multiple-blocks-limit-message="multipleBlocksLimitMessage"
44
- :theme-type="themeType"
45
- :increase-display-by="increaseDisplayBy"
46
- :multipleBlocksLimit="multipleBlocksLimit"
47
- :selected-options="selectedOptions"
48
- :create-custom-option-label="createCustomOptionLabel"
49
- >
50
- <template #optionBlock="{ label, deselectBlock, index }">
51
- <slot
52
- name="optionBlock"
53
- :label="label"
54
- :index="index"
55
- :deselect-block="deselectBlock"
56
- >
57
- </slot>
58
- </template>
59
- <template #maxElements>
60
- <slot name="maxElements"></slot>
61
- </template>
62
- <template
63
- v-if="toggleMultipleBlocksLimit"
64
- #showMore="{ showMoreOptions }"
65
- >
66
- <slot
67
- name="showMore"
68
- :show-more-options="showMoreOptions"
69
- >
70
- </slot>
71
- </template>
72
- </extended-multiselect-multiple>
73
- </div>
74
- <div v-else-if="!showSearchField && multiple">
75
- <extended-multiselect-multiple
76
- :disabled="disabled"
77
- :loading="loading"
78
- :toggle-multiple-blocks-limit="toggleMultipleBlocksLimit"
79
- :emitter-unique-id="emitterUniqueId"
80
- :empty-objects-placeholder="emptyObjectsPlaceholder"
81
- :label="label"
82
- :multiple-blocks-limit-message="multipleBlocksLimitMessage"
83
- :theme-type="themeType"
84
- :increase-display-by="increaseDisplayBy"
85
- :multipleBlocksLimit="multipleBlocksLimit"
86
- :selected-options="selectedOptions"
87
- :create-custom-option-label="createCustomOptionLabel"
88
- >
89
- <template #optionBlock="{ label, deselectBlock, index }">
90
- <slot
91
- name="optionBlock"
92
- :label="label"
93
- :index="index"
94
- :deselect-block="deselectBlock"
95
- >
96
- </slot>
97
- </template>
98
- <template
99
- v-if="toggleMultipleBlocksLimit"
100
- #showMore="{ showMoreOptions }"
101
- >
102
- <slot
103
- name="showMore"
104
- :show-more-options="showMoreOptions"
105
- ></slot>
106
- </template>
107
- </extended-multiselect-multiple>
108
- <input
109
- class="extended__multiselect-input--hidden"
110
- ref="extendedInput"
111
- type="text"
112
- @blur.prevent="rollUp"
113
- @focus.prevent="expand"
114
- />
115
- </div>
116
- <div
117
- class="extended__multiselect-block"
118
- v-else
119
- >
120
- <slot
121
- name="labelBlock"
122
- :label-block-value="singleLabel"
123
- >
124
- <span>{{ singleLabel }}</span>
125
- </slot>
126
- <input
127
- class="extended__multiselect-input--hidden"
128
- ref="extendedInput"
129
- type="text"
130
- @blur.prevent="rollUp"
131
- @focus.prevent="expand"
132
- />
133
- </div>
134
- </template>
135
-
136
- <script setup>
137
- import {
138
- computed,
139
- defineProps,
140
- inject,
141
- nextTick,
142
- onBeforeMount,
143
- onMounted,
144
- ref,
145
- toRef,
146
- toRefs,
147
- useAttrs,
148
- watch,
149
- } from "vue";
150
-
151
- import { debounce } from "lodash-es";
152
- import emitter from "../events/emitter";
153
-
154
- import ExtendedMultiselectMultiple from "./ExtendedMultiselectMultiple.vue";
155
-
156
- const props = defineProps({
157
- /**
158
- * Determines whether to take search value from current
159
- * selected option if "multiple" prop equals false
160
- * @property {boolean} autoSelectSearchValue
161
- */
162
- autoSelectSearchValue: {
163
- type: Boolean,
164
- required: true,
165
- },
166
-
167
- /**
168
- * Determines which placeholder to use
169
- * depending on the options creation mode
170
- * @property {boolean} createOnTheGo
171
- */
172
- createOnTheGo: {
173
- type: Boolean,
174
- required: true,
175
- },
176
-
177
- /**
178
- * Blocks search field
179
- * @property {boolean} disabled
180
- */
181
- disabled: {
182
- type: Boolean,
183
- required: true,
184
- },
185
-
186
- /**
187
- * Determines whether option list expanded or not
188
- * @property {boolean} dropdownActive
189
- */
190
- dropdownActive: {
191
- type: Boolean,
192
- required: true,
193
- },
194
-
195
- /**
196
- * Provides "loading" state of component
197
- * to ExtendedMultiselectMultiple child component
198
- * @property {boolean} loading
199
- */
200
- loading: {
201
- type: Boolean,
202
- required: true,
203
- },
204
-
205
- /**
206
- * Determines whether to use ExtendedMultiselectMultiple
207
- * child component and some other related functionality
208
- * @property {boolean} multiple
209
- */
210
- multiple: {
211
- type: Boolean,
212
- required: true,
213
- },
214
-
215
- /**
216
- * Renews the pattern of internal search for available options
217
- * @property {boolean} searchFilterActive
218
- */
219
- searchFilterActive: {
220
- type: Boolean,
221
- required: true,
222
- },
223
-
224
- /**
225
- * Determines whether to show search field
226
- * @property {boolean} showSearchField
227
- */
228
- showSearchField: {
229
- type: Boolean,
230
- required: true,
231
- },
232
-
233
- /**
234
- * Determines whether to allow user to increase limit of shown
235
- * elements with selected options by special icon
236
- * @property {boolean} toggleMultipleBlocksLimit
237
- */
238
- toggleMultipleBlocksLimit: {
239
- type: Boolean,
240
- required: true,
241
- },
242
-
243
- /**
244
- * Determines whether to roll up options list
245
- * by option selection
246
- * @property {boolean} toggleOptionsBySelect
247
- */
248
- toggleOptionsBySelect: {
249
- type: Boolean,
250
- required: true,
251
- },
252
-
253
- /**
254
- * Determines whether to clear value of search field
255
- * after next switch of search field display
256
- * @property {boolean} togglingSavesSearchValue
257
- */
258
- togglingSavesSearchValue: {
259
- type: Boolean,
260
- required: true,
261
- },
262
-
263
- /**
264
- * Placeholder which will be shown
265
- * if "createOnTheGo" prop equals true
266
- * @property {string} createOptionPlaceholder
267
- */
268
- createOptionPlaceholder: {
269
- type: String,
270
- required: true,
271
- },
272
-
273
- /**
274
- * Assigns unique identifier of extended multiselect
275
- * for each event
276
- * @property {string} emitterUniqueId
277
- */
278
- emitterUniqueId: {
279
- type: String,
280
- required: true,
281
- },
282
-
283
- /**
284
- * Placeholder used in internal options filters
285
- * and provided to ExtendedMultiselectMultiple child component
286
- * @property {string} emptyObjectsPlaceholder
287
- */
288
- emptyObjectsPlaceholder: {
289
- type: String,
290
- required: true,
291
- },
292
-
293
- /**
294
- * Determines field of option which will be displayed as label
295
- * @property {string} label
296
- */
297
- label: {
298
- type: String,
299
- required: true,
300
- },
301
-
302
- /**
303
- * "placeholder" attribute for search field
304
- * @property {string} placeholder
305
- */
306
- placeholder: {
307
- type: String,
308
- required: true,
309
- },
310
-
311
- /**
312
- * Provides current theme of extended multiselect
313
- * to ExtendedMultiselectMultiple child component
314
- * @property {string} themeType
315
- */
316
- themeType: {
317
- type: String,
318
- required: true,
319
- },
320
-
321
- /**
322
- * Provides limit of hidden options amount to be shown next
323
- * @property {number} increaseDisplayBy
324
- */
325
- increaseDisplayBy: {
326
- type: Number,
327
- required: true,
328
- },
329
-
330
- /**
331
- * Provides limit of option blocks amount
332
- * to ExtendedMultiselectMultiple child component
333
- * @default null
334
- * @property {number} multipleBlocksLimit
335
- */
336
- multipleBlocksLimit: {
337
- type: Number,
338
- default: null,
339
- },
340
-
341
- /**
342
- * Provides list of selected options
343
- * to ExtendedMultiselectMultiple child component
344
- * @property {Array} selectedOptions
345
- */
346
- selectedOptions: {
347
- type: Array,
348
- required: true,
349
- },
350
-
351
- /**
352
- * Provides function that creates custom label for
353
- * block with selected option to ExtendedMultiselectMultiple
354
- * child component
355
- * @property {Function} createCustomOptionLabel
356
- */
357
- createCustomOptionLabel: {
358
- type: Function,
359
- required: true,
360
- },
361
-
362
- /**
363
- * Loader function provided by user.
364
- * @property {Function} externalOptionsLoader
365
- * @default null
366
- * @param {string} value - value of search field
367
- */
368
- externalOptionsLoader: {
369
- type: Function,
370
- default: null,
371
- },
372
-
373
- /**
374
- * Provides function that creates limit message for maximal of selected
375
- * options to ExtendedMultiselectMultiple child component
376
- * @property {Function} multipleBlocksLimitMessage
377
- */
378
- multipleBlocksLimitMessage: {
379
- type: Function,
380
- required: true,
381
- },
382
-
383
- /**
384
- * "id" attribute of search field
385
- * @default null
386
- * @property {string|number} inputId
387
- */
388
- inputId: {
389
- type: [String, Number],
390
- default: null,
391
- },
392
- });
393
-
394
- const searchState = inject("searchState");
395
- const setSearchValue = inject("setSearchValue");
396
- const setSearchPattern = inject("setSearchPattern");
397
-
398
- const emitterUniqueId = toRef(props, "emitterUniqueId");
399
-
400
- const blurSkip = ref(false);
401
- const reversePrevented = ref(false);
402
- const searchFieldFocused = ref(false);
403
- const optionWillBeTriggered = ref(false);
404
- const searchValue = ref("");
405
- const singleLabel = ref("");
406
- const blurSkipByToggleIcon = ref(0);
407
- const blurSkipByBlock = ref(0);
408
- const labelBlocks = ref([]);
409
- const searchDebounce = ref(debounce(() => {
410
- const searchPattern = searchValue.value ? new RegExp(`${searchValue.value}`, "i") : null;
411
-
412
- if (externalOptionsLoader.value) {
413
- emitter.emit(`extended:loader-pattern-changed-${emitterUniqueId.value}`, searchValue.value);
414
- } else {
415
- emitter.emit(`extended:search-pattern-changed-${emitterUniqueId.value}`, searchValue.value);
416
- setSearchPattern(searchPattern);
417
- }
418
- }, 250));
419
-
420
- /**
421
- * Element references
422
- */
423
- const extendedInput = ref(null);
424
-
425
- const {
426
- autoSelectSearchValue,
427
- createOnTheGo,
428
- createOptionPlaceholder,
429
- disabled,
430
- externalOptionsLoader,
431
- increaseDisplayBy,
432
- multiple,
433
- placeholder,
434
- searchFilterActive,
435
- showSearchField,
436
- toggleOptionsBySelect,
437
- togglingSavesSearchValue,
438
- } = toRefs(props);
439
-
440
- const attrs = useAttrs();
441
-
442
- /**
443
- * Defines "placeholder" attribute of search field
444
- * @function
445
- * @returns {string} placeholder
446
- */
447
- const appropriatePlaceholder = computed(() => {
448
- return createOnTheGo.value ? createOptionPlaceholder.value : placeholder.value;
449
- });
450
-
451
- /**
452
- * Sets "margin-top" css property to multiple options block
453
- * if search field is shown
454
- * @function
455
- * @returns {Object|null} margin-top
456
- */
457
- const multipleBlocksMargin = computed(() => {
458
- return searchFieldForwarding.value ? { marginTop: "4px" } : null;
459
- });
460
-
461
- /**
462
- * Defines classes of search field
463
- * @function
464
- * @returns {Array} classes
465
- */
466
- const searchFieldClass = computed(() => {
467
- const mainClass = searchFieldForwarding.value
468
- ? "extended__multiselect-input"
469
- : "extended__multiselect-input--hidden";
470
- const searchFieldClasses = [];
471
-
472
- if (optionWillBeTriggered.value) {
473
- searchFieldClasses.push("extended__multiselect-input--trigger-option");
474
- }
475
-
476
- searchFieldClasses.push(mainClass);
477
-
478
- return searchFieldClasses;
479
- });
480
-
481
- /**
482
- * Determines whether to show search field
483
- * over element with selected option
484
- * @function
485
- * @returns {boolean} display
486
- */
487
- const searchFieldForwarding = computed(() => {
488
- return searchFieldFocused.value || optionWillBeTriggered.value;
489
- });
490
-
491
- /**
492
- * Determines whether option shall be triggered before selection
493
- * @function
494
- * @emits extended:renew-field-forwarding
495
- * @param {boolean} searchFieldForwarding - restrictor of triggered option
496
- */
497
- watch(searchFieldForwarding, (value) => {
498
- if (value && autoSelectSearchValue.value && !multiple.value && singleLabel.value) {
499
- searchValue.value = singleLabel.value;
500
- }
501
- emitter.emit(`extended:renew-field-forwarding-${emitterUniqueId.value}`, value);
502
- });
503
-
504
- /**
505
- * Sets pattern of internal search for available options from search field to store
506
- * @function
507
- * @param {string} pattern - pattern of internal search for available options
508
- */
509
- watch(searchState, (prevState, state) => {
510
- if (state.searchPattern === prevState.searchPattern) return;
511
-
512
- if (searchFilterActive.value) {
513
- setSearchPattern(state.pattern);
514
- }
515
- }, { deep: true });
516
-
517
- /**
518
- * Sets value of search field from search field to store
519
- * @function
520
- * @param {string} value - value of search field
521
- */
522
- watch(searchValue, (value) => {
523
- if (searchFilterActive.value) {
524
- setSearchValue(value);
525
- }
526
- });
527
-
528
- /**
529
- * Expands options list
530
- * @function
531
- * @emits extended:expand-options
532
- */
533
- const expand = () => {
534
- if (disabled.value) return;
535
-
536
- searchFieldFocused.value = true;
537
- emitter.emit(`extended:expand-options-${emitterUniqueId.value}`);
538
- };
539
-
540
- /**
541
- * Describes behavour of input blur event
542
- * when "multiple" prop equals true
543
- * @function
544
- */
545
- const multipleBlur = () => {
546
- if (!multiple.value) {
547
- searchFieldFocused.value = false;
548
- return;
549
- }
550
-
551
- if (!blurSkipByBlock.value) {
552
- searchFieldFocused.value = false;
553
- }
554
- };
555
-
556
- /**
557
- * Rolls up options list if it needed
558
- * @function
559
- * @emits extended:rollup-options
560
- */
561
- const rollUp = () => {
562
- if (disabled.value) return;
563
-
564
- multipleBlur();
565
-
566
- if (!togglingSavesSearchValue.value) {
567
- searchValue.value = "";
568
- setSearchValue(null);
569
- setSearchPattern(null);
570
- }
571
-
572
- if (blurSkipByToggleIcon.value > 0) {
573
- blurSkipByToggleIcon.value = 0;
574
- return;
575
- }
576
-
577
- if (blurSkipByBlock.value > 0) {
578
- blurSkipByBlock.value = 0;
579
- return;
580
- }
581
-
582
- blurSkip.value = true;
583
- blurSkipByBlock.value = 0;
584
- blurSkipByToggleIcon.value = 0;
585
-
586
- emitter.emit(`extended:rollup-options-${emitterUniqueId.value}`, true);
587
- };
588
-
589
- /**
590
- * Activates debounced version of options list filter
591
- * @function
592
- */
593
- const search = () => {
594
- searchDebounce.value();
595
- };
596
-
597
- /**
598
- * "onBeforeMount" hook of the ExtendedMultiselectInput component
599
- * @listens extended:field-focus
600
- * @listens extended:rollup-options
601
- * @listens extended:select-option
602
- * @listens extended:deselect-option
603
- * @listens extended:clean-options
604
- * @listens extended:clear-field
605
- * @listens extended:skip-blur
606
- * @listens extended:skip-block-blur
607
- * @listens extended:skip-block-blur-zeroing
608
- * @listens extended:trigger-selection
609
- */
610
- onBeforeMount(() => {
611
- emitter.on(`extended:rollup-options-${emitterUniqueId.value}`, (internalRollup) => {
612
- if (blurSkip.value === true) {
613
- blurSkip.value = false;
614
- return;
615
- }
616
-
617
- if (internalRollup) {
618
- return;
619
- }
620
-
621
- rollUp();
622
- });
623
-
624
- emitter.on(`extended:select-option-${emitterUniqueId.value}`, (option) => {
625
-
626
- if (toggleOptionsBySelect.value) {
627
- rollUp();
628
- }
629
-
630
- if (multiple.value) {
631
- return;
632
- } else {
633
- singleLabel.value = option.label;
634
- }
635
- });
636
-
637
- emitter.on(`extended:deselect-option-${emitterUniqueId.value}`, () => {
638
- if (multiple.value) {
639
- return;
640
- } else {
641
- singleLabel.value = "";
642
- }
643
- });
644
-
645
- emitter.on(`extended:clean-options-${emitterUniqueId.value}`, () => {
646
- searchValue.value = null;
647
- });
648
-
649
- emitter.on(`extended:clear-field-${emitterUniqueId.value}`, () => {
650
- searchValue.value = null;
651
- });
652
-
653
- emitter.on(`extended:skip-blur-${emitterUniqueId.value}`, () => {
654
- blurSkipByToggleIcon.value++;
655
- });
656
-
657
- emitter.on(`extended:skip-block-blur-${emitterUniqueId.value}`, () => {
658
- blurSkipByBlock.value++;
659
- });
660
-
661
- emitter.on(`extended:skip-block-blur-zeroing-${emitterUniqueId.value}`, () => {
662
- blurSkipByBlock.value = 0;
663
- });
664
-
665
- emitter.on(`extended:trigger-selection-${emitterUniqueId.value}`, (triggerState) => {
666
- if (!toggleOptionsBySelect.value) {
667
- searchFieldFocused.value = false;
668
- }
669
- optionWillBeTriggered.value = triggerState;
670
- });
671
- });
672
-
673
- /**
674
- * "onMounted" hook of the ExtendedMultiselectInput component
675
- * @listens extended:field-focus
676
- */
677
- onMounted(() => {
678
- emitter.on(`extended:field-focus-${emitterUniqueId.value}`, () => {
679
- if (showSearchField.value) {
680
- nextTick(() => {
681
- extendedInput.value.focus();
682
- });
683
- } else {
684
- extendedInput.value.focus();
685
- }
686
- });
687
- });
1
+ <template>
2
+ <div v-if="showSearchField">
3
+ <input
4
+ aria-controls="extended-search-field"
5
+ ref="extendedInput"
6
+ type="text"
7
+ :accesskey="attrs.accesskey"
8
+ :autocomplete="attrs.autocomplete"
9
+ :class="searchFieldClass"
10
+ :disabled="disabled"
11
+ :id="inputId"
12
+ :name="attrs.name"
13
+ :placeholder="appropriatePlaceholder"
14
+ :spellcheck="attrs.spellcheck"
15
+ :tabindex="attrs.tabindex"
16
+ :translate="attrs.translate"
17
+ v-model="searchValue"
18
+ @blur.prevent="rollUp"
19
+ @focus.prevent="expand"
20
+ @input="search"
21
+ />
22
+ <div
23
+ class="extended__multiselect-block"
24
+ v-show="!searchFieldForwarding && !multiple"
25
+ @click.stop="expand"
26
+ >
27
+ <slot
28
+ name="labelBlock"
29
+ :label-block-value="singleLabel"
30
+ >
31
+ <span>{{ singleLabel }}</span>
32
+ </slot>
33
+ </div>
34
+ <extended-multiselect-multiple
35
+ v-show="multiple && !!selectedOptions.length"
36
+ :style="multipleBlocksMargin"
37
+ :disabled="disabled"
38
+ :loading="loading"
39
+ :toggle-multiple-blocks-limit="toggleMultipleBlocksLimit"
40
+ :emitter-unique-id="emitterUniqueId"
41
+ :empty-objects-placeholder="emptyObjectsPlaceholder"
42
+ :label="label"
43
+ :multiple-blocks-limit-message="multipleBlocksLimitMessage"
44
+ :theme-type="themeType"
45
+ :increase-display-by="increaseDisplayBy"
46
+ :multipleBlocksLimit="multipleBlocksLimit"
47
+ :selected-options="selectedOptions"
48
+ :create-custom-option-label="createCustomOptionLabel"
49
+ >
50
+ <template #optionBlock="{ label, deselectBlock, index }">
51
+ <slot
52
+ name="optionBlock"
53
+ :label="label"
54
+ :index="index"
55
+ :deselect-block="deselectBlock"
56
+ >
57
+ </slot>
58
+ </template>
59
+ <template #maxElements>
60
+ <slot name="maxElements"></slot>
61
+ </template>
62
+ <template
63
+ v-if="toggleMultipleBlocksLimit"
64
+ #showMore="{ showMoreOptions }"
65
+ >
66
+ <slot
67
+ name="showMore"
68
+ :show-more-options="showMoreOptions"
69
+ >
70
+ </slot>
71
+ </template>
72
+ </extended-multiselect-multiple>
73
+ </div>
74
+ <div v-else-if="!showSearchField && multiple">
75
+ <extended-multiselect-multiple
76
+ :disabled="disabled"
77
+ :loading="loading"
78
+ :toggle-multiple-blocks-limit="toggleMultipleBlocksLimit"
79
+ :emitter-unique-id="emitterUniqueId"
80
+ :empty-objects-placeholder="emptyObjectsPlaceholder"
81
+ :label="label"
82
+ :multiple-blocks-limit-message="multipleBlocksLimitMessage"
83
+ :theme-type="themeType"
84
+ :increase-display-by="increaseDisplayBy"
85
+ :multipleBlocksLimit="multipleBlocksLimit"
86
+ :selected-options="selectedOptions"
87
+ :create-custom-option-label="createCustomOptionLabel"
88
+ >
89
+ <template #optionBlock="{ label, deselectBlock, index }">
90
+ <slot
91
+ name="optionBlock"
92
+ :label="label"
93
+ :index="index"
94
+ :deselect-block="deselectBlock"
95
+ >
96
+ </slot>
97
+ </template>
98
+ <template
99
+ v-if="toggleMultipleBlocksLimit"
100
+ #showMore="{ showMoreOptions }"
101
+ >
102
+ <slot
103
+ name="showMore"
104
+ :show-more-options="showMoreOptions"
105
+ ></slot>
106
+ </template>
107
+ </extended-multiselect-multiple>
108
+ <input
109
+ class="extended__multiselect-input--hidden"
110
+ ref="extendedInput"
111
+ type="text"
112
+ @blur.prevent="rollUp"
113
+ @focus.prevent="expand"
114
+ />
115
+ </div>
116
+ <div
117
+ class="extended__multiselect-block"
118
+ v-else
119
+ >
120
+ <slot
121
+ name="labelBlock"
122
+ :label-block-value="singleLabel"
123
+ >
124
+ <span>{{ singleLabel }}</span>
125
+ </slot>
126
+ <input
127
+ class="extended__multiselect-input--hidden"
128
+ ref="extendedInput"
129
+ type="text"
130
+ @blur.prevent="rollUp"
131
+ @focus.prevent="expand"
132
+ />
133
+ </div>
134
+ </template>
135
+
136
+ <script setup>
137
+ import {
138
+ computed,
139
+ defineProps,
140
+ inject,
141
+ nextTick,
142
+ onBeforeMount,
143
+ onMounted,
144
+ ref,
145
+ toRef,
146
+ toRefs,
147
+ useAttrs,
148
+ watch,
149
+ } from "vue";
150
+
151
+ import { debounce } from "lodash-es";
152
+ import emitter from "../events/emitter";
153
+
154
+ import ExtendedMultiselectMultiple from "./ExtendedMultiselectMultiple.vue";
155
+
156
+ const props = defineProps({
157
+ /**
158
+ * Determines whether to take search value from current
159
+ * selected option if "multiple" prop equals false
160
+ * @property {boolean} autoSelectSearchValue
161
+ */
162
+ autoSelectSearchValue: {
163
+ type: Boolean,
164
+ required: true,
165
+ },
166
+
167
+ /**
168
+ * Determines which placeholder to use
169
+ * depending on the options creation mode
170
+ * @property {boolean} createOnTheGo
171
+ */
172
+ createOnTheGo: {
173
+ type: Boolean,
174
+ required: true,
175
+ },
176
+
177
+ /**
178
+ * Blocks search field
179
+ * @property {boolean} disabled
180
+ */
181
+ disabled: {
182
+ type: Boolean,
183
+ required: true,
184
+ },
185
+
186
+ /**
187
+ * Determines whether option list expanded or not
188
+ * @property {boolean} dropdownActive
189
+ */
190
+ dropdownActive: {
191
+ type: Boolean,
192
+ required: true,
193
+ },
194
+
195
+ /**
196
+ * Provides "loading" state of component
197
+ * to ExtendedMultiselectMultiple child component
198
+ * @property {boolean} loading
199
+ */
200
+ loading: {
201
+ type: Boolean,
202
+ required: true,
203
+ },
204
+
205
+ /**
206
+ * Determines whether to use ExtendedMultiselectMultiple
207
+ * child component and some other related functionality
208
+ * @property {boolean} multiple
209
+ */
210
+ multiple: {
211
+ type: Boolean,
212
+ required: true,
213
+ },
214
+
215
+ /**
216
+ * Renews the pattern of internal search for available options
217
+ * @property {boolean} searchFilterActive
218
+ */
219
+ searchFilterActive: {
220
+ type: Boolean,
221
+ required: true,
222
+ },
223
+
224
+ /**
225
+ * Determines whether to show search field
226
+ * @property {boolean} showSearchField
227
+ */
228
+ showSearchField: {
229
+ type: Boolean,
230
+ required: true,
231
+ },
232
+
233
+ /**
234
+ * Determines whether to allow user to increase limit of shown
235
+ * elements with selected options by special icon
236
+ * @property {boolean} toggleMultipleBlocksLimit
237
+ */
238
+ toggleMultipleBlocksLimit: {
239
+ type: Boolean,
240
+ required: true,
241
+ },
242
+
243
+ /**
244
+ * Determines whether to roll up options list
245
+ * by option selection
246
+ * @property {boolean} toggleOptionsBySelect
247
+ */
248
+ toggleOptionsBySelect: {
249
+ type: Boolean,
250
+ required: true,
251
+ },
252
+
253
+ /**
254
+ * Determines whether to clear value of search field
255
+ * after next switch of search field display
256
+ * @property {boolean} togglingSavesSearchValue
257
+ */
258
+ togglingSavesSearchValue: {
259
+ type: Boolean,
260
+ required: true,
261
+ },
262
+
263
+ /**
264
+ * Placeholder which will be shown
265
+ * if "createOnTheGo" prop equals true
266
+ * @property {string} createOptionPlaceholder
267
+ */
268
+ createOptionPlaceholder: {
269
+ type: String,
270
+ required: true,
271
+ },
272
+
273
+ /**
274
+ * Assigns unique identifier of extended multiselect
275
+ * for each event
276
+ * @property {string} emitterUniqueId
277
+ */
278
+ emitterUniqueId: {
279
+ type: String,
280
+ required: true,
281
+ },
282
+
283
+ /**
284
+ * Placeholder used in internal options filters
285
+ * and provided to ExtendedMultiselectMultiple child component
286
+ * @property {string} emptyObjectsPlaceholder
287
+ */
288
+ emptyObjectsPlaceholder: {
289
+ type: String,
290
+ required: true,
291
+ },
292
+
293
+ /**
294
+ * Determines field of option which will be displayed as label
295
+ * @property {string} label
296
+ */
297
+ label: {
298
+ type: String,
299
+ required: true,
300
+ },
301
+
302
+ /**
303
+ * "placeholder" attribute for search field
304
+ * @property {string} placeholder
305
+ */
306
+ placeholder: {
307
+ type: String,
308
+ required: true,
309
+ },
310
+
311
+ /**
312
+ * Provides current theme of extended multiselect
313
+ * to ExtendedMultiselectMultiple child component
314
+ * @property {string} themeType
315
+ */
316
+ themeType: {
317
+ type: String,
318
+ required: true,
319
+ },
320
+
321
+ /**
322
+ * Provides limit of hidden options amount to be shown next
323
+ * @property {number} increaseDisplayBy
324
+ */
325
+ increaseDisplayBy: {
326
+ type: Number,
327
+ required: true,
328
+ },
329
+
330
+ /**
331
+ * Provides limit of option blocks amount
332
+ * to ExtendedMultiselectMultiple child component
333
+ * @default null
334
+ * @property {number} multipleBlocksLimit
335
+ */
336
+ multipleBlocksLimit: {
337
+ type: Number,
338
+ default: null,
339
+ },
340
+
341
+ /**
342
+ * Provides list of selected options
343
+ * to ExtendedMultiselectMultiple child component
344
+ * @property {Array} selectedOptions
345
+ */
346
+ selectedOptions: {
347
+ type: Array,
348
+ required: true,
349
+ },
350
+
351
+ /**
352
+ * Provides function that creates custom label for
353
+ * block with selected option to ExtendedMultiselectMultiple
354
+ * child component
355
+ * @property {Function} createCustomOptionLabel
356
+ */
357
+ createCustomOptionLabel: {
358
+ type: Function,
359
+ required: true,
360
+ },
361
+
362
+ /**
363
+ * Loader function provided by user.
364
+ * @property {Function} externalOptionsLoader
365
+ * @default null
366
+ * @param {string} value - value of search field
367
+ */
368
+ externalOptionsLoader: {
369
+ type: Function,
370
+ default: null,
371
+ },
372
+
373
+ /**
374
+ * Provides function that creates limit message for maximal of selected
375
+ * options to ExtendedMultiselectMultiple child component
376
+ * @property {Function} multipleBlocksLimitMessage
377
+ */
378
+ multipleBlocksLimitMessage: {
379
+ type: Function,
380
+ required: true,
381
+ },
382
+
383
+ /**
384
+ * "id" attribute of search field
385
+ * @default null
386
+ * @property {string|number} inputId
387
+ */
388
+ inputId: {
389
+ type: [String, Number],
390
+ default: null,
391
+ },
392
+ });
393
+
394
+ const searchState = inject("searchState");
395
+ const setSearchValue = inject("setSearchValue");
396
+ const setSearchPattern = inject("setSearchPattern");
397
+
398
+ const emitterUniqueId = toRef(props, "emitterUniqueId");
399
+
400
+ const blurSkip = ref(false);
401
+ const reversePrevented = ref(false);
402
+ const searchFieldFocused = ref(false);
403
+ const optionWillBeTriggered = ref(false);
404
+ const searchValue = ref("");
405
+ const singleLabel = ref("");
406
+ const blurSkipByToggleIcon = ref(0);
407
+ const blurSkipByBlock = ref(0);
408
+ const labelBlocks = ref([]);
409
+ const searchDebounce = ref(debounce(() => {
410
+ const searchPattern = searchValue.value ? new RegExp(`${searchValue.value}`, "i") : null;
411
+
412
+ if (externalOptionsLoader.value) {
413
+ emitter.emit(`extended:loader-pattern-changed-${emitterUniqueId.value}`, searchValue.value);
414
+ } else {
415
+ emitter.emit(`extended:search-pattern-changed-${emitterUniqueId.value}`, searchValue.value);
416
+ setSearchPattern(searchPattern);
417
+ }
418
+ }, 250));
419
+
420
+ /**
421
+ * Element references
422
+ */
423
+ const extendedInput = ref(null);
424
+
425
+ const {
426
+ autoSelectSearchValue,
427
+ createOnTheGo,
428
+ createOptionPlaceholder,
429
+ disabled,
430
+ externalOptionsLoader,
431
+ increaseDisplayBy,
432
+ multiple,
433
+ placeholder,
434
+ searchFilterActive,
435
+ showSearchField,
436
+ toggleOptionsBySelect,
437
+ togglingSavesSearchValue,
438
+ } = toRefs(props);
439
+
440
+ const attrs = useAttrs();
441
+
442
+ /**
443
+ * Defines "placeholder" attribute of search field
444
+ * @function
445
+ * @returns {string} placeholder
446
+ */
447
+ const appropriatePlaceholder = computed(() => {
448
+ return createOnTheGo.value ? createOptionPlaceholder.value : placeholder.value;
449
+ });
450
+
451
+ /**
452
+ * Sets "margin-top" css property to multiple options block
453
+ * if search field is shown
454
+ * @function
455
+ * @returns {Object|null} margin-top
456
+ */
457
+ const multipleBlocksMargin = computed(() => {
458
+ return searchFieldForwarding.value ? { marginTop: "4px" } : null;
459
+ });
460
+
461
+ /**
462
+ * Defines classes of search field
463
+ * @function
464
+ * @returns {Array} classes
465
+ */
466
+ const searchFieldClass = computed(() => {
467
+ const mainClass = searchFieldForwarding.value
468
+ ? "extended__multiselect-input"
469
+ : "extended__multiselect-input--hidden";
470
+ const searchFieldClasses = [];
471
+
472
+ if (optionWillBeTriggered.value) {
473
+ searchFieldClasses.push("extended__multiselect-input--trigger-option");
474
+ }
475
+
476
+ searchFieldClasses.push(mainClass);
477
+
478
+ return searchFieldClasses;
479
+ });
480
+
481
+ /**
482
+ * Determines whether to show search field
483
+ * over element with selected option
484
+ * @function
485
+ * @returns {boolean} display
486
+ */
487
+ const searchFieldForwarding = computed(() => {
488
+ return searchFieldFocused.value || optionWillBeTriggered.value;
489
+ });
490
+
491
+ /**
492
+ * Determines whether option shall be triggered before selection
493
+ * @function
494
+ * @emits extended:renew-field-forwarding
495
+ * @param {boolean} searchFieldForwarding - restrictor of triggered option
496
+ */
497
+ watch(searchFieldForwarding, (value) => {
498
+ if (value && autoSelectSearchValue.value && !multiple.value && singleLabel.value) {
499
+ searchValue.value = singleLabel.value;
500
+ }
501
+ emitter.emit(`extended:renew-field-forwarding-${emitterUniqueId.value}`, value);
502
+ });
503
+
504
+ /**
505
+ * Sets pattern of internal search for available options from search field to store
506
+ * @function
507
+ * @param {string} pattern - pattern of internal search for available options
508
+ */
509
+ watch(searchState, (prevState, state) => {
510
+ if (state.searchPattern === prevState.searchPattern) return;
511
+
512
+ if (searchFilterActive.value) {
513
+ setSearchPattern(state.pattern);
514
+ }
515
+ }, { deep: true });
516
+
517
+ /**
518
+ * Sets value of search field from search field to store
519
+ * @function
520
+ * @param {string} value - value of search field
521
+ */
522
+ watch(searchValue, (value) => {
523
+ if (searchFilterActive.value) {
524
+ setSearchValue(value);
525
+ }
526
+ });
527
+
528
+ /**
529
+ * Expands options list
530
+ * @function
531
+ * @emits extended:expand-options
532
+ */
533
+ const expand = () => {
534
+ if (disabled.value) return;
535
+
536
+ searchFieldFocused.value = true;
537
+ emitter.emit(`extended:expand-options-${emitterUniqueId.value}`);
538
+ };
539
+
540
+ /**
541
+ * Describes behavour of input blur event
542
+ * when "multiple" prop equals true
543
+ * @function
544
+ */
545
+ const multipleBlur = () => {
546
+ if (!multiple.value) {
547
+ searchFieldFocused.value = false;
548
+ return;
549
+ }
550
+
551
+ if (!blurSkipByBlock.value) {
552
+ searchFieldFocused.value = false;
553
+ }
554
+ };
555
+
556
+ /**
557
+ * Rolls up options list if it needed
558
+ * @function
559
+ * @emits extended:rollup-options
560
+ */
561
+ const rollUp = () => {
562
+ if (disabled.value) return;
563
+
564
+ multipleBlur();
565
+
566
+ if (!togglingSavesSearchValue.value) {
567
+ searchValue.value = "";
568
+ setSearchValue(null);
569
+ setSearchPattern(null);
570
+ }
571
+
572
+ if (blurSkipByToggleIcon.value > 0) {
573
+ blurSkipByToggleIcon.value = 0;
574
+ return;
575
+ }
576
+
577
+ if (blurSkipByBlock.value > 0) {
578
+ blurSkipByBlock.value = 0;
579
+ return;
580
+ }
581
+
582
+ blurSkip.value = true;
583
+ blurSkipByBlock.value = 0;
584
+ blurSkipByToggleIcon.value = 0;
585
+
586
+ emitter.emit(`extended:rollup-options-${emitterUniqueId.value}`, true);
587
+ };
588
+
589
+ /**
590
+ * Activates debounced version of options list filter
591
+ * @function
592
+ */
593
+ const search = () => {
594
+ searchDebounce.value();
595
+ };
596
+
597
+ /**
598
+ * "onBeforeMount" hook of the ExtendedMultiselectInput component
599
+ * @listens extended:field-focus
600
+ * @listens extended:rollup-options
601
+ * @listens extended:select-option
602
+ * @listens extended:deselect-option
603
+ * @listens extended:clean-options
604
+ * @listens extended:clear-field
605
+ * @listens extended:skip-blur
606
+ * @listens extended:skip-block-blur
607
+ * @listens extended:skip-block-blur-zeroing
608
+ * @listens extended:trigger-selection
609
+ */
610
+ onBeforeMount(() => {
611
+ emitter.on(`extended:rollup-options-${emitterUniqueId.value}`, (internalRollup) => {
612
+ if (blurSkip.value === true) {
613
+ blurSkip.value = false;
614
+ return;
615
+ }
616
+
617
+ if (internalRollup) {
618
+ return;
619
+ }
620
+
621
+ rollUp();
622
+ });
623
+
624
+ emitter.on(`extended:select-option-${emitterUniqueId.value}`, (option) => {
625
+
626
+ if (toggleOptionsBySelect.value) {
627
+ rollUp();
628
+ }
629
+
630
+ if (multiple.value) {
631
+ return;
632
+ } else {
633
+ singleLabel.value = option.label;
634
+ }
635
+ });
636
+
637
+ emitter.on(`extended:deselect-option-${emitterUniqueId.value}`, () => {
638
+ if (multiple.value) {
639
+ return;
640
+ } else {
641
+ singleLabel.value = "";
642
+ }
643
+ });
644
+
645
+ emitter.on(`extended:clean-options-${emitterUniqueId.value}`, () => {
646
+ searchValue.value = null;
647
+ });
648
+
649
+ emitter.on(`extended:clear-field-${emitterUniqueId.value}`, () => {
650
+ searchValue.value = null;
651
+ });
652
+
653
+ emitter.on(`extended:skip-blur-${emitterUniqueId.value}`, () => {
654
+ blurSkipByToggleIcon.value++;
655
+ });
656
+
657
+ emitter.on(`extended:skip-block-blur-${emitterUniqueId.value}`, () => {
658
+ blurSkipByBlock.value++;
659
+ });
660
+
661
+ emitter.on(`extended:skip-block-blur-zeroing-${emitterUniqueId.value}`, () => {
662
+ blurSkipByBlock.value = 0;
663
+ });
664
+
665
+ emitter.on(`extended:trigger-selection-${emitterUniqueId.value}`, (triggerState) => {
666
+ if (!toggleOptionsBySelect.value) {
667
+ searchFieldFocused.value = false;
668
+ }
669
+ optionWillBeTriggered.value = triggerState;
670
+ });
671
+ });
672
+
673
+ /**
674
+ * "onMounted" hook of the ExtendedMultiselectInput component
675
+ * @listens extended:field-focus
676
+ */
677
+ onMounted(() => {
678
+ emitter.on(`extended:field-focus-${emitterUniqueId.value}`, () => {
679
+ if (showSearchField.value) {
680
+ nextTick(() => {
681
+ extendedInput.value.focus();
682
+ });
683
+ } else {
684
+ extendedInput.value.focus();
685
+ }
686
+ });
687
+ });
688
688
  </script>