@danielgindi/selectbox 2.0.56 → 2.0.58

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.
package/vue/SelectBox.vue CHANGED
@@ -2,985 +2,859 @@
2
2
  <span :ref="v => el = v" />
3
3
  </template>
4
4
 
5
- <script>
6
- import { markRaw, version } from 'vue';
7
- import SelectBox, { DefaultOptions } from '../lib/SelectBox';
8
- import { createSlotBasedRenderFunc, createSlotBasedUnrenderFunc } from './utils/slots';
9
- import deepEqual from 'fast-deep-equal';
10
-
11
- const isVue3 = version > '3.';
12
-
13
- /**
14
- * Events:
15
- * 'clear:before': `{cancel: false}` - will clear the whole selection. return false to abort.
16
- * 'clear': clearead the whole selection.
17
- * 'open': `{ list: DropList `}: the drop list is opening
18
- * 'open:before': `{ list: DropList `}: the drop list will open
19
- * 'close': the drop list is closing
20
- * 'addsel:before': `{value, item, cancel: false}` - an item selection is about to be added (in multi mode). return false to abort.
21
- * 'removesel:before: `{value, item, cancel: false}` - an item selection is about to be removed (in multi mode). return false to abort.
22
- * 'select:before': `{value, item, cancel: false}` - an item is about to be selected (in single mode). return false to abort.
23
- * 'addsel': `{value, item}` - an item selection has been added (in multi mode)
24
- * 'removesel': `{value, item}` - an item selection has been removed (in multi mode)
25
- * 'select': `{value, item}` - an item has been selected (in single mode)
26
- * 'search': `string` - input box value has changed
27
- * 'search:focus': input box has gained focus
28
- * 'search:blur': input box has lost focus
29
- * 'search:term': search term has been updated, before results were re-filtered
30
- * 'input:resize': input box resized
31
- * 'input' (Vue v2): (on select, clear, addsel, removesel) - fired after any of the above events.
32
- * 'update:modelValue' (Vue v3): (on select, clear, addsel, removesel) - fired after any of the above events.
33
- * 'itemschanged': `{term, mutated, count}` = the current set of items has changed
34
- *
35
- * Slots:
36
- * list-item, single-item, multi-item, rest-multi-item, no-results-item
37
- */
38
-
39
- export const PropTypes = {
40
- disabled: {
41
- type: Boolean,
42
- default: false,
43
- },
44
- readOnly: {
45
- type: Boolean,
46
- required: false,
47
- default: null,
48
- },
49
- clearable: {
50
- type: Boolean,
51
- default: true,
52
- },
53
- hasOpenIndicator: {
54
- type: Boolean,
55
- default: true,
56
- },
57
- placeholder: {
58
- type: String,
59
- default: '',
60
- },
61
- sortSelectedItems: {
62
- type: Boolean,
63
- default: true,
64
- },
65
- sortListItems: {
66
- type: Boolean,
67
- default: false,
68
- },
69
- sortListCheckedFirst: {
70
- type: Boolean,
71
- default: true,
72
- },
73
- stickyValues: {
74
- type: Array,
75
- required: false,
76
- },
77
- sortItemComparator: {
78
- type: Function,
79
- required: false,
80
- },
81
- splitListCheckedGroups: {
82
- type: Boolean,
83
- default: true,
84
- },
85
- showSelection: {
86
- type: Boolean,
87
- default: true,
88
- },
89
- showPlaceholderInTooltip: {
90
- type: Boolean,
91
- default: true,
92
- },
93
- multiPlaceholderFormatter: {
94
- type: Function,
95
- required: false,
96
- default: undefined,
97
- },
98
- blurOnSingleSelection: {
99
- type: [Boolean, String],
100
- default: 'touch',
101
- validator: value => {
102
- return [true, false, 'touch', null].includes(value);
103
- },
104
- },
105
- multi: {
106
- type: Boolean,
107
- default: false,
108
- },
109
- searchable: {
110
- type: Boolean,
111
- default: true,
112
- },
113
- allowTypeToSelect: {
114
- type: Boolean,
115
- default: true,
116
- },
117
- noResultsText: {
118
- type: String,
119
- required: false,
120
- },
121
- filterThrottleWindow: {
122
- type: Number,
123
- required: false,
124
- },
125
- filterOnEmptyTerm: {
126
- type: Boolean,
127
- default: false,
128
- },
129
- filterFn: {
130
- type: Function,
131
- default: undefined,
132
- },
133
- filterDependencies: {
134
- type: [Array, String, Number, Boolean, Object],
135
- default: undefined,
136
- },
137
- labelProp: {
138
- type: String,
139
- default: 'label',
140
- },
141
- valueProp: {
142
- type: String,
143
- default: 'value',
144
- },
145
- multiItemLabelProp: {
146
- type: String,
147
- default: 'short_label',
148
- },
149
- multiItemRemovePosition: {
150
- type: String,
151
- default: 'after',
152
- validator: value => {
153
- return ['before', 'after', 'none'].includes(value);
154
- },
155
- },
156
- items: {
157
- type: Array,
158
- default: () => [],
159
- },
160
- [isVue3 ? 'modelValue' : 'value']: {
161
- type: [String, Number, Boolean, Object, Array, Symbol],
162
- default: undefined,
163
- },
164
- maxMultiItems: {
165
- type: Number,
166
- required: false,
167
- },
168
- multiItemsRestLabelProvider: {
169
- type: Function,
170
- required: false,
171
- },
172
- renderSingleItem: {
173
- type: Function,
174
- default: undefined,
175
- },
176
- unrenderSingleItem: {
177
- type: Function,
178
- default: undefined,
179
- },
180
- renderMultiItem: {
181
- type: Function,
182
- default: undefined,
183
- },
184
- unrenderMultiItem: {
185
- type: Function,
186
- default: undefined,
187
- },
188
- renderRestMultiItem: {
189
- type: Function,
190
- default: undefined,
191
- },
192
- unrenderRestMultiItem: {
193
- type: Function,
194
- default: undefined,
195
- },
196
- renderNoResultsItem: {
197
- type: Function,
198
- default: undefined,
199
- },
200
- unrenderNoResultsItem: {
201
- type: Function,
202
- default: undefined,
203
- },
204
- renderListItem: {
205
- type: Function,
206
- default: undefined,
207
- },
208
- unrenderListItem: {
209
- type: Function,
210
- default: undefined,
211
- },
212
- virtualMinItems: {
213
- type: Number,
214
- default: 10,
215
- },
216
- baseClass: {
217
- type: String,
218
- default: undefined,
219
- },
220
- droplistBaseClass: {
221
- type: String,
222
- default: undefined,
223
- },
224
- additionalClasses: {
225
- type: [Object, Array, String],
226
- default: undefined,
227
- },
228
- additionalDroplistClasses: {
229
- type: [Object, Array, String],
230
- default: undefined,
231
- },
232
- direction: {
233
- type: String,
234
- default: undefined,
235
- },
236
- fixedDroplistWidth: {
237
- type: Boolean,
238
- default: false,
239
- },
240
- acceptNullAsValue: {
241
- type: Boolean,
242
- default: false,
243
- },
244
- emitNullForEmptyValue: {
245
- type: Boolean,
246
- default: false,
247
- },
248
- isLoadingMode: {
249
- type: Boolean,
250
- default: false,
251
- },
252
- closeListWhenLoading: {
253
- type: Boolean,
254
- required: false,
255
- },
256
- clearInputWhen: {
257
- type: Array,
258
- required: false,
259
- default: () => ['single_close', 'multi_select_single'],
260
- validator: value => {
261
- if (value && !Array.isArray(value))
262
- return false;
263
- for (let v of value) {
264
- if (!['single_close', 'multi_close', 'multi_select_single'].includes(v))
265
- return false;
266
- }
267
- return true;
268
- },
269
- },
270
- treatGroupSelectionAsItems: {
271
- type: Boolean,
272
- default: false,
273
- },
274
- autoCheckGroupChildren: {
275
- type: Boolean,
276
- default: true,
277
- },
278
- constrainListToWindow: {
279
- type: Boolean,
280
- default: true,
281
- },
282
- autoFlipListDirection: {
283
- type: Boolean,
284
- default: true,
285
- },
286
- };
287
-
288
- export default {
289
- inheritAttrs: false,
290
-
291
- props: PropTypes,
292
-
293
- emits: [
294
- 'update:modelValue',
295
- 'clear:before',
296
- 'clear',
297
- 'open',
298
- 'close',
299
- 'search:focus',
300
- 'search:blur',
301
- 'search:term',
302
- 'addsel:before',
303
- 'addsel',
304
- 'removesel:before',
305
- 'removesel',
306
- 'select:before',
307
- 'select',
308
- 'input:resize',
309
- 'itemschanged',
310
- 'search',
311
- ],
312
-
313
- data() {
314
- return {
315
- el: undefined,
316
- isMounted: false,
317
- instance: undefined,
318
- };
319
- },
320
-
321
- computed: {
322
- computedListOptions() {
323
- let opts = {};
324
-
325
- if (this.droplistBaseClass) {
326
- opts.baseClassName = this.droplistBaseClass;
327
- }
328
-
329
- if (this.additionalDroplistClassesList) {
330
- opts.additionalClasses = this.additionalDroplistClassesList;
331
- }
332
-
333
- if (typeof this.autoCheckGroupChildren === 'boolean' && this.multi) {
334
- opts.autoCheckGroupChildren = this.autoCheckGroupChildren;
335
- }
336
-
337
- if (typeof this.constrainListToWindow === 'boolean') {
338
- opts.constrainToWindow = this.constrainListToWindow;
339
- }
340
-
341
- if (typeof this.autoFlipListDirection === 'boolean') {
342
- opts.autoFlipDirection = this.autoFlipListDirection;
343
- }
344
-
345
- opts.virtualMinItems = this.virtualMinItems;
346
- opts.useExactTargetWidth = this.fixedDroplistWidth;
347
-
348
- opts.renderItem = this.renderListItem;
349
- if (!opts.renderItem) {
350
- opts.renderItem = createSlotBasedRenderFunc(this, 'list-item');
351
- }
352
-
353
- opts.unrenderItem = this.unrenderListItem;
354
- if (!opts.unrenderItem) {
355
- let fn = createSlotBasedUnrenderFunc(this, 'list-item');
356
- if (fn) {
357
- opts.unrenderItem = (item, el) => fn(el);
358
- }
359
- }
360
-
361
- opts.renderNoResultsItem = this.renderNoResultsItem;
362
- if (!opts.renderNoResultsItem) {
363
- opts.renderNoResultsItem = createSlotBasedRenderFunc(this, 'rest-multi-item');
364
- }
365
-
366
- opts.unrenderNoResultsItem = this.unrenderNoResultsItem;
367
- if (!opts.unrenderNoResultsItem) {
368
- let fn = createSlotBasedUnrenderFunc(this, 'rest-multi-item');
369
- if (fn) {
370
- opts.unrenderNoResultsItem = (item, el) => fn(el);
371
- }
372
- }
373
-
374
- return opts;
375
- },
376
-
377
- computedRenderSingleItem() {
378
- let render = this.renderSingleItem;
379
-
380
- if (!render) {
381
- render = createSlotBasedRenderFunc(this, 'single-item');
382
- }
383
-
384
- return render;
385
- },
386
-
387
- computedUnrenderSingleItem() {
388
- let unrender = this.unrenderSingleItem;
389
-
390
- if (!unrender) {
391
- let fn = createSlotBasedUnrenderFunc(this, 'single-item');
392
- if (fn) {
393
- unrender = (item, el) => fn(el);
394
- }
395
- }
396
-
397
- return unrender;
398
- },
399
-
400
- computedRenderMultiItem() {
401
- let render = this.renderMultiItem;
402
-
403
- if (!render) {
404
- render = createSlotBasedRenderFunc(this, 'multi-item');
405
- }
406
-
407
- return render;
408
- },
409
-
410
- computedUnrenderMultiItem() {
411
- let unrender = this.unrenderMultiItem;
412
-
413
- if (!unrender) {
414
- let fn = createSlotBasedUnrenderFunc(this, 'multi-item');
415
- if (fn) {
416
- unrender = (item, el) => fn(el);
417
- }
418
- }
419
-
420
- return unrender;
421
- },
422
-
423
- computedRenderRestMultiItem() {
424
- let render = this.renderRestMultiItem;
425
-
426
- if (!render) {
427
- render = createSlotBasedRenderFunc(this, 'rest-multi-item');
428
- }
429
-
430
- return render;
431
- },
432
-
433
- computedUnrenderRestMultiItem() {
434
- let unrender = this.unrenderRestMultiItem;
435
-
436
- if (!unrender) {
437
- let fn = createSlotBasedUnrenderFunc(this, 'rest-multi-item');
438
- if (fn) {
439
- unrender = (item, el) => fn(el);
440
- }
441
- }
442
-
443
- return unrender;
444
- },
445
-
446
- computedRenderNoResultsItem() {
447
- let render = this.renderNoResultsItem;
448
-
449
- if (!render) {
450
- render = createSlotBasedRenderFunc(this, 'no-results-item');
451
- }
452
-
453
- return render;
454
- },
455
-
456
- computedUnrenderNoResultsItem() {
457
- let unrender = this.unrenderNoResultsItem;
458
-
459
- if (!unrender) {
460
- let fn = createSlotBasedUnrenderFunc(this, 'no-results-item');
461
- if (fn) {
462
- unrender = (item, el) => fn(el);
463
- }
464
- }
465
-
466
- return unrender;
467
- },
468
-
469
- additionalClassesList() {
470
- return this._concatClassesObject(this.additionalClasses);
471
- },
472
-
473
- additionalDroplistClassesList() {
474
- return this._concatClassesObject(this.additionalDroplistClasses);
475
- },
476
- },
477
-
478
- watch: {
479
- disabled(value) {
480
- if (this.instance)
481
- this.instance.disable(value);
482
- },
483
-
484
- readOnly() {
485
- if (this.instance)
486
- this.instance.setReadOnly(this.readOnly ?? false);
487
- },
488
-
489
- clearable(value) {
490
- if (this.instance)
491
- this.instance.setClearable(value);
492
- },
493
-
494
- direction(value) {
495
- if (this.instance)
496
- this.instance.setDirection(value);
497
- },
498
-
499
- hasOpenIndicator(value) {
500
- if (this.instance)
501
- this.instance.setHasOpenIndicator(value);
502
- },
503
-
504
- placeholder(value) {
505
- if (this.instance)
506
- this.instance.setPlaceholder(value);
507
- },
508
-
509
- sortSelectedItems(value) {
510
- if (this.instance)
511
- this.instance.setSortSelectedItems(value);
512
- },
513
-
514
- sortListItems(value) {
515
- if (this.instance)
516
- this.instance.setSortListItems(value);
517
- },
518
-
519
- sortListCheckedFirst(value) {
520
- if (this.instance)
521
- this.instance.setSortListCheckedFirst(value);
522
- },
523
-
524
- stickyValues(value) {
525
- if (!this.instance) return;
526
-
527
- // `stickyValues` tend to be a literal array,
528
- // and Vue will get a different reference for each update, triggering this watcher.
529
- // so use deepEqual here to avoid redoing the list items on each selection change.
530
- if (deepEqual(this.stickyValues, value)) return;
531
-
532
- this.instance.setStickyValues(value);
533
- },
534
-
535
- sortItemComparator(value) {
536
- if (this.instance)
537
- this.instance.setSortItemComparator(value);
538
- },
539
-
540
- splitListCheckedGroups(value) {
541
- if (this.instance)
542
- this.instance.setSplitListCheckedGroups(value);
543
- },
544
-
545
- showSelection(value) {
546
- if (this.instance)
547
- this.instance.setShowSelection(value);
548
- },
549
-
550
- showPlaceholderInTooltip(value) {
551
- if (this.instance)
552
- this.instance.setShowPlaceholderInTooltip(value);
553
- },
554
-
555
- multiPlaceholderFormatter(formatter) {
556
- if (this.instance)
557
- this.instance.setMultiPlaceholderFormatter(formatter);
558
- },
559
-
560
- showBlurOnSingleSelection(value) {
561
- if (this.instance)
562
- this.instance.setBlurOnSingleSelection(value);
563
- },
564
-
565
- multi(value) {
566
- if (this.instance)
567
- this.instance.setMulti(value);
568
- },
569
-
570
- searchable(value) {
571
- if (this.instance)
572
- this.instance.setSearchable(value);
573
- },
574
-
575
- allowTypeToSelect(value) {
576
- if (this.instance)
577
- this.instance.setAllowTypeToSelect(value);
578
- },
579
-
580
- noResultsText(value) {
581
- if (this.instance)
582
- this.instance.setNoResultsText(value ?? DefaultOptions.noResultsText);
583
- },
584
-
585
- filterThrottleWindow(value) {
586
- if (this.instance)
587
- this.instance.setFilterThrottleWindow(value ?? DefaultOptions.filterThrottleWindow ?? 0);
588
- },
589
-
590
- filterOnEmptyTerm(value) {
591
- if (this.instance)
592
- this.instance.setFilterOnEmptyTerm(value || false);
593
- },
594
-
595
- filterFn() {
596
- if (this.instance)
597
- this.instance.setFilterFn(this.filterFn);
598
- },
599
-
600
- labelProp(value) {
601
- if (this.instance)
602
- this.instance.setLabelProp(value);
603
- },
604
-
605
- valueProp(value) {
606
- if (this.instance)
607
- this.instance.setValueProp(value);
608
- },
609
-
610
- multiItemLabelProp(value) {
611
- if (this.instance)
612
- this.instance.setMultiItemLabelProp(value);
613
- },
614
-
615
- multiItemRemovePosition(value) {
616
- if (this.instance)
617
- this.instance.setMultiItemRemovePosition(value);
618
- },
619
-
620
- maxMultiItems(value) {
621
- if (this.instance)
622
- this.instance.setMaxMultiItems(value);
623
- },
624
-
625
- multiItemsRestLabelProvider(value) {
626
- if (this.instance)
627
- this.instance.setMultiItemsRestLabelProvider(value);
628
- },
629
-
630
- items(value) {
631
- if (this.instance) {
632
- this.instance.setItems(value, false);
633
-
634
- const modelValue = isVue3 ? this.modelValue : this.value;
635
- this.instance.setValue(modelValue === null && (!this.acceptNullAsValue || this.multi) ? undefined : modelValue);
636
- }
637
- },
638
-
639
- [isVue3 ? 'modelValue' : 'value'](value, old) {
640
- if (Array.isArray(value) && Array.isArray(old) &&
641
- value.length === old && value.every((v, i) => old[i] === v))
642
- return;
643
-
644
- if (this.instance)
645
- this.instance.setValue(value === null && (!this.acceptNullAsValue || this.multi) ? undefined : value);
646
- },
647
-
648
- renderSingleItem() {
649
- if (this.instance)
650
- this.instance.setRenderSingleItem(this.computedRenderSingleItem, this.computedUnrenderSingleItem);
651
- },
652
-
653
- unrenderSingleItem() {
654
- if (this.instance)
655
- this.instance.setRenderSingleItem(this.computedRenderSingleItem, this.computedUnrenderSingleItem);
656
- },
657
-
658
- renderMultiItem() {
659
- if (this.instance)
660
- this.instance.setRenderMultiItem(this.computedRenderMultiItem, this.computedUnrenderMultiItem);
661
- },
662
-
663
- unrenderMultiItem() {
664
- if (this.instance)
665
- this.instance.setRenderMultiItem(this.computedRenderMultiItem, this.computedUnrenderMultiItem);
666
- },
667
-
668
- renderRestMultiItem() {
669
- if (this.instance)
670
- this.instance.setRenderRestMultiItem(this.computedRenderRestMultiItem, this.computedUnrenderRestMultiItem);
671
- },
672
-
673
- unrenderRestMultiItem() {
674
- if (this.instance)
675
- this.instance.setRenderRestMultiItem(this.computedRenderRestMultiItem, this.computedUnrenderRestMultiItem);
676
- },
677
-
678
- renderNoResultsItem() {
679
- if (this.instance)
680
- this.instance.setRenderNoResultsItem(this.computedRenderNoResultsItem, this.computedUnrenderNoResultsItem);
681
- },
682
-
683
- unrenderNoResultsItem() {
684
- if (this.instance)
685
- this.instance.setRenderNoResultsItem(this.computedRenderNoResultsItem, this.computedUnrenderNoResultsItem);
686
- },
687
-
688
- renderListItem() {
689
- if (this.instance)
690
- this.instance.setListOptions(this.computedListOptions);
691
- },
692
-
693
- unrenderListItem() {
694
- if (this.instance)
695
- this.instance.setListOptions(this.computedListOptions);
696
- },
697
-
698
- ...(isVue3 ? {} : {
699
- $scopedSlots() { // Vue 2
700
- if (this.instance)
701
- this.instance.setListOptions(this.computedListOptions);
702
- },
703
- }),
704
-
705
- $slots() {
706
- if (this.instance)
707
- this.instance.setListOptions(this.computedListOptions);
708
- },
709
-
710
- additionalClasses() {
711
- if (this.instance)
712
- this.instance.setAdditionalClasses(this.additionalClassesList);
713
- },
714
-
715
- isLoadingMode() {
716
- if (this.instance)
717
- this.instance.setIsLoadingMode(!!this.isLoadingMode);
718
- },
719
-
720
- closeListWhenLoading() {
721
- if (this.instance)
722
- this.instance.setCloseListWhenLoading(this.closeListWhenLoading ?? DefaultOptions.closeListWhenLoading);
723
- },
724
-
725
- clearInputWhen() {
726
- if (this.instance)
727
- this.instance.setClearInputWhen(this.clearInputWhen);
728
- },
729
-
730
- treatGroupSelectionAsItems() {
731
- if (this.instance)
732
- this.instance.setTreatGroupSelectionAsItems(!!this.treatGroupSelectionAsItems);
733
- },
734
-
735
- filterDependencies: {
736
- deep: true,
737
- handler() {
738
- if (this.instance)
739
- this.instance.invokeRefilter();
740
- },
741
- },
742
-
743
- el(v) {
744
- if (v) {
745
- if (this.isMounted) {
746
- this._createBox();
747
-
748
- if (window.ResizeObserver === undefined) {
749
- const wasAttached = this._isAttached;
750
- this._isAttached = !!this.el && document.body.contains(this.el);
751
- if (!wasAttached && this.instance && this._isAttached)
752
- this.instance.refreshSize();
753
- }
754
- }
755
- } else {
756
- this._destroyBox();
757
- }
758
- },
759
- },
760
-
761
- mounted() {
762
- this.isMounted = true;
763
-
764
- this._createBox();
765
-
766
- if (window.ResizeObserver === undefined && this.instance) {
767
- const wasAttached = this._isAttached;
768
- this._isAttached = !!this.$refs.el && document.body.contains(this.$refs.el);
769
- if (!wasAttached && this.instance && this._isAttached)
770
- this.instance.refreshSize();
771
- }
772
- },
773
-
774
- unmounted() {
775
- this.isMounted = false;
776
- },
777
-
778
- methods: {
779
- _handleBoxEvents(event, data) {
780
- switch (event) {
781
- case 'clear:before':
782
- case 'clear':
783
- case 'open':
784
- case 'close':
785
- case 'search:focus':
786
- case 'search:blur':
787
- case 'search:term':
788
- case 'addsel:before':
789
- case 'addsel':
790
- case 'removesel:before':
791
- case 'removesel':
792
- case 'select:before':
793
- case 'select':
794
- case 'input:resize':
795
- case 'itemschanged':
796
- this.$emit(event, ...(data === undefined ? [] : [data]));
797
- break;
798
-
799
- case 'search':
800
- this.$emit(event, data.value);
801
- break;
802
- }
803
-
804
- if (event === 'select' ||
805
- event === 'clear' ||
806
- event === 'groupcheck' ||
807
- (event === 'addsel' && !event.isCheckingGroup) ||
808
- (event === 'removesel' && !event.isCheckingGroup)) {
809
- let value = event === 'select' ? data.value : this.instance.getValue();
810
- if (value === undefined && event !== 'select' && this.emitNullForEmptyValue)
811
- value = null;
812
- this.$emit(isVue3 ? 'update:modelValue' : 'input', value);
813
- }
814
- },
815
-
816
- _createBox() {
817
- this._destroyBox();
818
-
819
- if (!this.el)
820
- return;
821
-
822
- let box = new SelectBox({
823
- el: this.el,
824
- baseClass: this.baseClass,
825
- direction: this.direction,
826
- disabled: this.disabled,
827
- readOnly: this.readOnly ?? false,
828
- clearable: this.clearable,
829
- hasOpenIndicator: this.hasOpenIndicator,
830
- placeholder: this.placeholder,
831
- sortSelectedItems: this.sortSelectedItems,
832
- sortListItems: this.sortListItems,
833
- sortListCheckedFirst: this.sortListCheckedFirst,
834
- stickyValues: this.stickyValues,
835
- sortItemComparator: this.sortItemComparator,
836
- splitListCheckedGroups: this.splitListCheckedGroups,
837
- showSelection: this.showSelection,
838
- showPlaceholderInTooltip: this.showPlaceholderInTooltip,
839
- multiPlaceholderFormatter: this.multiPlaceholderFormatter,
840
- blurOnSingleSelection: this.blurOnSingleSelection,
841
- multi: this.multi,
842
- searchable: this.searchable,
843
- allowTypeToSelect: this.allowTypeToSelect,
844
- noResultsText: this.noResultsText ?? DefaultOptions.noResultsText,
845
- filterThrottleWindow: this.filterThrottleWindow ?? DefaultOptions.filterThrottleWindow ?? 0,
846
- filterOnEmptyTerm: this.filterOnEmptyTerm,
847
- labelProp: this.labelProp,
848
- valueProp: this.valueProp,
849
- multiItemLabelProp: this.multiItemLabelProp,
850
- multiItemRemovePosition: this.multiItemRemovePosition,
851
- maxMultiItems: this.maxMultiItems,
852
- multiItemsRestLabelProvider: this.multiItemsRestLabelProvider,
853
- items: this.items,
854
- listOptions: this.computedListOptions,
855
- renderSingleItem: this.computedRenderSingleItem,
856
- unrenderSingleItem: this.computedUnrenderSingleItem,
857
- renderMultiItem: this.computedRenderMultiItem,
858
- unrenderMultiItem: this.computedUnrenderMultiItem,
859
- renderRestMultiItem: this.computedRenderRestMultiItem,
860
- unrenderRestMultiItem: this.computedUnrenderRestMultiItem,
861
- filterFn: this.filterFn,
862
- on: this._handleBoxEvents.bind(this),
863
- additionalClasses: this.additionalClassesList,
864
- isLoadingMode: this.isLoadingMode,
865
- closeListWhenLoading: this.closeListWhenLoading ?? DefaultOptions.closeListWhenLoading,
866
- clearInputWhen: this.clearInputWhen,
867
- treatGroupSelectionAsItems: this.treatGroupSelectionAsItems,
868
- });
869
-
870
- const modelValue = isVue3 ? this.modelValue : this.value;
871
- box.setValue(modelValue === null && (!this.acceptNullAsValue || this.multi) ? undefined : modelValue);
872
-
873
- this.instance = markRaw(box);
874
- this.el = box.el;
875
- },
876
-
877
- _destroyBox() {
878
- if (this.instance) {
879
- this.instance.destroy();
880
- this.instance = undefined;
881
- }
882
- },
883
-
884
- _concatClassesObject(classes) {
885
- if (Array.isArray(classes)) {
886
- return classes.join(' ');
887
- }
888
- else if (classes && typeof classes === 'object') {
889
- let arr = [];
890
- for (let [key, value] of Object.entries(classes)) {
891
- if (value)
892
- arr.push(key);
893
- }
894
- return arr.join(' ');
895
- }
896
-
897
- return classes || '';
898
- },
899
-
900
- toggleLoading(on) {
901
- if (this.instance)
902
- this.instance.toggleLoading(on);
903
- },
904
-
905
- toggleList(open) {
906
- if (this.instance)
907
- this.instance.toggleList(open);
908
- },
909
-
910
- openList() {
911
- if (this.instance)
912
- this.instance.openList();
913
- },
914
-
915
- closeList() {
916
- if (this.instance)
917
- this.instance.closeList();
918
- },
919
-
920
- isListOpen() {
921
- if (this.instance)
922
- return this.instance.isListOpen();
923
- return false;
924
- },
925
-
926
- updateItemByValue(value, newItem) {
927
- if (this.instance)
928
- return this.instance.updateItemByValue(value, newItem);
929
- },
930
-
931
- getSelectedItems() {
932
- if (this.instance)
933
- return this.instance.getSelectedItems();
934
- return [];
935
- },
936
-
937
- /**
938
- * @param {string} term
939
- * @param {boolean} [performSearch=false] should actually perform the search, or just set the input's text?
940
- */
941
- setSearchTerm(term, performSearch) {
942
- if (term != null && this.instance)
943
- this.instance.setSearchTerm(term, performSearch);
944
- },
945
-
946
- /**
947
- * @returns {string}
948
- */
949
- getSearchTerm() {
950
- if (this.instance)
951
- return this.instance.getSearchTerm();
952
- return '';
953
- },
954
-
955
- /**
956
- * @returns {number}
957
- */
958
- getFilteredItemCount() {
959
- if (this.instance)
960
- return this.instance.getFilteredItemCount();
961
- return 0;
962
- },
963
-
964
- /**
965
- * @returns {boolean}
966
- */
967
- isFilterPending() {
968
- if (this.instance)
969
- return this.instance.isFilterPending();
970
- return false;
971
- },
972
-
973
- focus() {
974
- this.instance?.focusInput();
975
- },
976
-
977
- blur() {
978
- this.instance?.blurInput();
979
- },
980
-
981
- droplistElContains(other, considerSublists = true) {
982
- return this.instance?.droplistElContains(other, considerSublists);
983
- },
984
- },
985
- };
5
+ <script>
6
+ import { defineComponent, markRaw, version } from 'vue';
7
+ import SelectBox, { DefaultOptions } from '../lib/SelectBox';
8
+ import { createSlotBasedRenderFunc, createSlotBasedUnrenderFunc } from './utils/slots';
9
+ import deepEqual from 'fast-deep-equal';
10
+ const isVue3 = version > '3.';
11
+ /**
12
+ * Events:
13
+ * 'clear:before': `{cancel: false}` - will clear the whole selection. return false to abort.
14
+ * 'clear': clearead the whole selection.
15
+ * 'open': `{ list: DropList `}: the drop list is opening
16
+ * 'open:before': `{ list: DropList `}: the drop list will open
17
+ * 'close': the drop list is closing
18
+ * 'addsel:before': `{value, item, cancel: false}` - an item selection is about to be added (in multi mode). return false to abort.
19
+ * 'removesel:before: `{value, item, cancel: false}` - an item selection is about to be removed (in multi mode). return false to abort.
20
+ * 'select:before': `{value, item, cancel: false}` - an item is about to be selected (in single mode). return false to abort.
21
+ * 'addsel': `{value, item}` - an item selection has been added (in multi mode)
22
+ * 'removesel': `{value, item}` - an item selection has been removed (in multi mode)
23
+ * 'select': `{value, item}` - an item has been selected (in single mode)
24
+ * 'search': `string` - input box value has changed
25
+ * 'search:focus': input box has gained focus
26
+ * 'search:blur': input box has lost focus
27
+ * 'search:term': search term has been updated, before results were re-filtered
28
+ * 'input:resize': input box resized
29
+ * 'input' (Vue v2): (on select, clear, addsel, removesel) - fired after any of the above events.
30
+ * 'update:modelValue' (Vue v3): (on select, clear, addsel, removesel) - fired after any of the above events.
31
+ * 'itemschanged': `{term, mutated, count}` = the current set of items has changed
32
+ *
33
+ * Slots:
34
+ * list-item, single-item, multi-item, rest-multi-item, no-results-item
35
+ */
36
+ export const PropTypes = {
37
+ disabled: {
38
+ type: Boolean,
39
+ default: false,
40
+ },
41
+ readOnly: {
42
+ type: Boolean,
43
+ required: false,
44
+ default: null,
45
+ },
46
+ clearable: {
47
+ type: Boolean,
48
+ default: true,
49
+ },
50
+ hasOpenIndicator: {
51
+ type: Boolean,
52
+ default: true,
53
+ },
54
+ placeholder: {
55
+ type: String,
56
+ default: '',
57
+ },
58
+ sortSelectedItems: {
59
+ type: Boolean,
60
+ default: true,
61
+ },
62
+ sortListItems: {
63
+ type: Boolean,
64
+ default: false,
65
+ },
66
+ sortListCheckedFirst: {
67
+ type: Boolean,
68
+ default: true,
69
+ },
70
+ stickyValues: {
71
+ type: Array,
72
+ required: false,
73
+ },
74
+ sortItemComparator: {
75
+ type: Function,
76
+ required: false,
77
+ },
78
+ splitListCheckedGroups: {
79
+ type: Boolean,
80
+ default: true,
81
+ },
82
+ showSelection: {
83
+ type: Boolean,
84
+ default: true,
85
+ },
86
+ showPlaceholderInTooltip: {
87
+ type: Boolean,
88
+ default: true,
89
+ },
90
+ multiPlaceholderFormatter: {
91
+ type: Function,
92
+ required: false,
93
+ default: undefined,
94
+ },
95
+ blurOnSingleSelection: {
96
+ type: [Boolean, String],
97
+ default: 'touch',
98
+ validator: (value) => {
99
+ return [true, false, 'touch', null].includes(value);
100
+ },
101
+ },
102
+ multi: {
103
+ type: Boolean,
104
+ default: false,
105
+ },
106
+ searchable: {
107
+ type: Boolean,
108
+ default: true,
109
+ },
110
+ allowTypeToSelect: {
111
+ type: Boolean,
112
+ default: true,
113
+ },
114
+ noResultsText: {
115
+ type: String,
116
+ required: false,
117
+ },
118
+ filterThrottleWindow: {
119
+ type: Number,
120
+ required: false,
121
+ },
122
+ filterOnEmptyTerm: {
123
+ type: Boolean,
124
+ default: false,
125
+ },
126
+ filterFn: {
127
+ type: Function,
128
+ default: undefined,
129
+ },
130
+ onError: {
131
+ type: Function,
132
+ default: undefined,
133
+ },
134
+ filterDependencies: {
135
+ type: [Array, String, Number, Boolean, Object],
136
+ default: undefined,
137
+ },
138
+ labelProp: {
139
+ type: String,
140
+ default: 'label',
141
+ },
142
+ valueProp: {
143
+ type: String,
144
+ default: 'value',
145
+ },
146
+ multiItemLabelProp: {
147
+ type: String,
148
+ default: 'short_label',
149
+ },
150
+ multiItemRemovePosition: {
151
+ type: String,
152
+ default: 'after',
153
+ validator: (value) => {
154
+ return ['before', 'after', 'none'].includes(value);
155
+ },
156
+ },
157
+ items: {
158
+ type: Array,
159
+ default: () => [],
160
+ },
161
+ [isVue3 ? 'modelValue' : 'value']: {
162
+ type: [String, Number, Boolean, Object, Array, Symbol],
163
+ default: undefined,
164
+ },
165
+ maxMultiItems: {
166
+ type: Number,
167
+ required: false,
168
+ },
169
+ multiItemsRestLabelProvider: {
170
+ type: Function,
171
+ required: false,
172
+ },
173
+ renderSingleItem: {
174
+ type: Function,
175
+ default: undefined,
176
+ },
177
+ unrenderSingleItem: {
178
+ type: Function,
179
+ default: undefined,
180
+ },
181
+ renderMultiItem: {
182
+ type: Function,
183
+ default: undefined,
184
+ },
185
+ unrenderMultiItem: {
186
+ type: Function,
187
+ default: undefined,
188
+ },
189
+ renderRestMultiItem: {
190
+ type: Function,
191
+ default: undefined,
192
+ },
193
+ unrenderRestMultiItem: {
194
+ type: Function,
195
+ default: undefined,
196
+ },
197
+ renderNoResultsItem: {
198
+ type: Function,
199
+ default: undefined,
200
+ },
201
+ unrenderNoResultsItem: {
202
+ type: Function,
203
+ default: undefined,
204
+ },
205
+ renderListItem: {
206
+ type: Function,
207
+ default: undefined,
208
+ },
209
+ unrenderListItem: {
210
+ type: Function,
211
+ default: undefined,
212
+ },
213
+ virtualMinItems: {
214
+ type: Number,
215
+ default: 10,
216
+ },
217
+ baseClass: {
218
+ type: String,
219
+ default: undefined,
220
+ },
221
+ droplistBaseClass: {
222
+ type: String,
223
+ default: undefined,
224
+ },
225
+ additionalClasses: {
226
+ type: [Object, Array, String],
227
+ default: undefined,
228
+ },
229
+ additionalDroplistClasses: {
230
+ type: [Object, Array, String],
231
+ default: undefined,
232
+ },
233
+ direction: {
234
+ type: String,
235
+ default: undefined,
236
+ },
237
+ fixedDroplistWidth: {
238
+ type: Boolean,
239
+ default: false,
240
+ },
241
+ acceptNullAsValue: {
242
+ type: Boolean,
243
+ default: false,
244
+ },
245
+ emitNullForEmptyValue: {
246
+ type: Boolean,
247
+ default: false,
248
+ },
249
+ isLoadingMode: {
250
+ type: Boolean,
251
+ default: false,
252
+ },
253
+ closeListWhenLoading: {
254
+ type: Boolean,
255
+ required: false,
256
+ },
257
+ clearInputWhen: {
258
+ type: Array,
259
+ required: false,
260
+ default: () => ['single_close', 'multi_select_single'],
261
+ validator: (value) => {
262
+ if (value && !Array.isArray(value))
263
+ return false;
264
+ for (let v of value) {
265
+ if (!['single_close', 'multi_close', 'multi_select_single'].includes(v))
266
+ return false;
267
+ }
268
+ return true;
269
+ },
270
+ },
271
+ treatGroupSelectionAsItems: {
272
+ type: Boolean,
273
+ default: false,
274
+ },
275
+ autoCheckGroupChildren: {
276
+ type: Boolean,
277
+ default: true,
278
+ },
279
+ constrainListToWindow: {
280
+ type: Boolean,
281
+ default: true,
282
+ },
283
+ autoFlipListDirection: {
284
+ type: Boolean,
285
+ default: true,
286
+ },
287
+ };
288
+ export default defineComponent({
289
+ inheritAttrs: false,
290
+ props: PropTypes,
291
+ emits: [
292
+ 'update:modelValue',
293
+ 'clear:before',
294
+ 'clear',
295
+ 'open',
296
+ 'close',
297
+ 'search:focus',
298
+ 'search:blur',
299
+ 'search:term',
300
+ 'addsel:before',
301
+ 'addsel',
302
+ 'removesel:before',
303
+ 'removesel',
304
+ 'select:before',
305
+ 'select',
306
+ 'input:resize',
307
+ 'itemschanged',
308
+ 'search',
309
+ ],
310
+ data() {
311
+ return {
312
+ el: undefined,
313
+ isMounted: false,
314
+ instance: undefined,
315
+ };
316
+ },
317
+ computed: {
318
+ computedListOptions() {
319
+ let opts = {};
320
+ if (this.droplistBaseClass) {
321
+ opts.baseClassName = this.droplistBaseClass;
322
+ }
323
+ if (this.additionalDroplistClassesList) {
324
+ opts.additionalClasses = this.additionalDroplistClassesList;
325
+ }
326
+ if (typeof this.autoCheckGroupChildren === 'boolean' && this.multi) {
327
+ opts.autoCheckGroupChildren = this.autoCheckGroupChildren;
328
+ }
329
+ if (typeof this.constrainListToWindow === 'boolean') {
330
+ opts.constrainToWindow = this.constrainListToWindow;
331
+ }
332
+ if (typeof this.autoFlipListDirection === 'boolean') {
333
+ opts.autoFlipDirection = this.autoFlipListDirection;
334
+ }
335
+ opts.virtualMinItems = this.virtualMinItems;
336
+ opts.useExactTargetWidth = this.fixedDroplistWidth;
337
+ opts.renderItem = this.renderListItem;
338
+ if (!opts.renderItem) {
339
+ opts.renderItem = createSlotBasedRenderFunc(this, 'list-item');
340
+ }
341
+ opts.unrenderItem = this.unrenderListItem;
342
+ if (!opts.unrenderItem) {
343
+ let fn = createSlotBasedUnrenderFunc(this, 'list-item');
344
+ if (fn) {
345
+ opts.unrenderItem = (item, el) => fn(el);
346
+ }
347
+ }
348
+ opts.renderNoResultsItem = this.computedRenderNoResultsItem;
349
+ opts.unrenderNoResultsItem = this.computedUnrenderNoResultsItem;
350
+ return opts;
351
+ },
352
+ computedRenderSingleItem() {
353
+ let render = this.renderSingleItem;
354
+ if (!render) {
355
+ render = createSlotBasedRenderFunc(this, 'single-item');
356
+ }
357
+ return render;
358
+ },
359
+ computedUnrenderSingleItem() {
360
+ let unrender = this.unrenderSingleItem;
361
+ if (!unrender) {
362
+ let fn = createSlotBasedUnrenderFunc(this, 'single-item');
363
+ if (fn) {
364
+ unrender = (item, el) => fn(el);
365
+ }
366
+ }
367
+ return unrender;
368
+ },
369
+ computedRenderMultiItem() {
370
+ let render = this.renderMultiItem;
371
+ if (!render) {
372
+ render = createSlotBasedRenderFunc(this, 'multi-item');
373
+ }
374
+ return render;
375
+ },
376
+ computedUnrenderMultiItem() {
377
+ let unrender = this.unrenderMultiItem;
378
+ if (!unrender) {
379
+ let fn = createSlotBasedUnrenderFunc(this, 'multi-item');
380
+ if (fn) {
381
+ unrender = (item, el) => fn(el);
382
+ }
383
+ }
384
+ return unrender;
385
+ },
386
+ computedRenderRestMultiItem() {
387
+ let render = this.renderRestMultiItem;
388
+ if (!render) {
389
+ render = createSlotBasedRenderFunc(this, 'rest-multi-item');
390
+ }
391
+ return render;
392
+ },
393
+ computedUnrenderRestMultiItem() {
394
+ let unrender = this.unrenderRestMultiItem;
395
+ if (!unrender) {
396
+ let fn = createSlotBasedUnrenderFunc(this, 'rest-multi-item');
397
+ if (fn) {
398
+ unrender = (item, el) => fn(el);
399
+ }
400
+ }
401
+ return unrender;
402
+ },
403
+ computedRenderNoResultsItem() {
404
+ let render = this.renderNoResultsItem;
405
+ if (!render) {
406
+ render = createSlotBasedRenderFunc(this, 'no-results-item');
407
+ }
408
+ return render;
409
+ },
410
+ computedUnrenderNoResultsItem() {
411
+ let unrender = this.unrenderNoResultsItem;
412
+ if (!unrender) {
413
+ let fn = createSlotBasedUnrenderFunc(this, 'no-results-item');
414
+ if (fn) {
415
+ unrender = (item, el) => fn(el);
416
+ }
417
+ }
418
+ return unrender;
419
+ },
420
+ additionalClassesList() {
421
+ return this._concatClassesObject(this.additionalClasses);
422
+ },
423
+ additionalDroplistClassesList() {
424
+ return this._concatClassesObject(this.additionalDroplistClasses);
425
+ },
426
+ },
427
+ watch: {
428
+ disabled(value) {
429
+ if (this.instance)
430
+ this.instance.disable(value);
431
+ },
432
+ readOnly() {
433
+ if (this.instance)
434
+ this.instance.setReadOnly(this.readOnly ?? false);
435
+ },
436
+ clearable(value) {
437
+ if (this.instance)
438
+ this.instance.setClearable(value);
439
+ },
440
+ direction(value) {
441
+ if (this.instance)
442
+ this.instance.setDirection(value);
443
+ },
444
+ hasOpenIndicator(value) {
445
+ if (this.instance)
446
+ this.instance.setHasOpenIndicator(value);
447
+ },
448
+ placeholder(value) {
449
+ if (this.instance)
450
+ this.instance.setPlaceholder(value);
451
+ },
452
+ sortSelectedItems(value) {
453
+ if (this.instance)
454
+ this.instance.setSortSelectedItems(value);
455
+ },
456
+ sortListItems(value) {
457
+ if (this.instance)
458
+ this.instance.setSortListItems(value);
459
+ },
460
+ sortListCheckedFirst(value) {
461
+ if (this.instance)
462
+ this.instance.setSortListCheckedFirst(value);
463
+ },
464
+ stickyValues(value) {
465
+ if (!this.instance)
466
+ return;
467
+ // `stickyValues` tend to be a literal array,
468
+ // and Vue will get a different reference for each update, triggering this watcher.
469
+ // so use deepEqual here to avoid redoing the list items on each selection change.
470
+ if (deepEqual(this.stickyValues, value))
471
+ return;
472
+ this.instance.setStickyValues(value);
473
+ },
474
+ sortItemComparator(value) {
475
+ if (this.instance)
476
+ this.instance.setSortItemComparator(value);
477
+ },
478
+ splitListCheckedGroups(value) {
479
+ if (this.instance)
480
+ this.instance.setSplitListCheckedGroups(value);
481
+ },
482
+ showSelection(value) {
483
+ if (this.instance)
484
+ this.instance.setShowSelection(value);
485
+ },
486
+ showPlaceholderInTooltip(value) {
487
+ if (this.instance)
488
+ this.instance.setShowPlaceholderInTooltip(value);
489
+ },
490
+ multiPlaceholderFormatter(formatter) {
491
+ if (this.instance)
492
+ this.instance.setMultiPlaceholderFormatter(formatter);
493
+ },
494
+ showBlurOnSingleSelection(value) {
495
+ if (this.instance)
496
+ this.instance.setBlurOnSingleSelection(value);
497
+ },
498
+ multi(value) {
499
+ if (this.instance)
500
+ this.instance.setMulti(value);
501
+ },
502
+ searchable(value) {
503
+ if (this.instance)
504
+ this.instance.setSearchable(value);
505
+ },
506
+ allowTypeToSelect(value) {
507
+ if (this.instance)
508
+ this.instance.setAllowTypeToSelect(value);
509
+ },
510
+ noResultsText(value) {
511
+ if (this.instance)
512
+ this.instance.setNoResultsText(value ?? DefaultOptions.noResultsText);
513
+ },
514
+ filterThrottleWindow(value) {
515
+ if (this.instance)
516
+ this.instance.setFilterThrottleWindow(value ?? DefaultOptions.filterThrottleWindow ?? 0);
517
+ },
518
+ filterOnEmptyTerm(value) {
519
+ if (this.instance)
520
+ this.instance.setFilterOnEmptyTerm(value || false);
521
+ },
522
+ filterFn() {
523
+ if (this.instance)
524
+ this.instance.setFilterFn(this.filterFn);
525
+ },
526
+ onError() {
527
+ if (this.instance)
528
+ this.instance.setOnError(this.onError);
529
+ },
530
+ labelProp(value) {
531
+ if (this.instance)
532
+ this.instance.setLabelProp(value);
533
+ },
534
+ valueProp(value) {
535
+ if (this.instance)
536
+ this.instance.setValueProp(value);
537
+ },
538
+ multiItemLabelProp(value) {
539
+ if (this.instance)
540
+ this.instance.setMultiItemLabelProp(value);
541
+ },
542
+ multiItemRemovePosition(value) {
543
+ if (this.instance)
544
+ this.instance.setMultiItemRemovePosition(value);
545
+ },
546
+ maxMultiItems(value) {
547
+ if (this.instance)
548
+ this.instance.setMaxMultiItems(value);
549
+ },
550
+ multiItemsRestLabelProvider(value) {
551
+ if (this.instance)
552
+ this.instance.setMultiItemsRestLabelProvider(value);
553
+ },
554
+ items(value) {
555
+ if (this.instance) {
556
+ this.instance.setItems(value, false);
557
+ const modelValue = isVue3 ? this.modelValue : this.value;
558
+ this.instance.setValue(modelValue === null && (!this.acceptNullAsValue || this.multi) ? undefined : modelValue);
559
+ }
560
+ },
561
+ [isVue3 ? 'modelValue' : 'value'](value, old) {
562
+ if (Array.isArray(value) && Array.isArray(old) &&
563
+ value.length === old && value.every((v, i) => old[i] === v))
564
+ return;
565
+ if (this.instance)
566
+ this.instance.setValue(value === null && (!this.acceptNullAsValue || this.multi) ? undefined : value);
567
+ },
568
+ renderSingleItem() {
569
+ if (this.instance)
570
+ this.instance.setRenderSingleItem(this.computedRenderSingleItem, this.computedUnrenderSingleItem);
571
+ },
572
+ unrenderSingleItem() {
573
+ if (this.instance)
574
+ this.instance.setRenderSingleItem(this.computedRenderSingleItem, this.computedUnrenderSingleItem);
575
+ },
576
+ renderMultiItem() {
577
+ if (this.instance)
578
+ this.instance.setRenderMultiItem(this.computedRenderMultiItem, this.computedUnrenderMultiItem);
579
+ },
580
+ unrenderMultiItem() {
581
+ if (this.instance)
582
+ this.instance.setRenderMultiItem(this.computedRenderMultiItem, this.computedUnrenderMultiItem);
583
+ },
584
+ renderRestMultiItem() {
585
+ if (this.instance)
586
+ this.instance.setRenderRestMultiItem(this.computedRenderRestMultiItem, this.computedUnrenderRestMultiItem);
587
+ },
588
+ unrenderRestMultiItem() {
589
+ if (this.instance)
590
+ this.instance.setRenderRestMultiItem(this.computedRenderRestMultiItem, this.computedUnrenderRestMultiItem);
591
+ },
592
+ renderNoResultsItem() {
593
+ if (this.instance)
594
+ this.instance.setRenderNoResultsItem(this.computedRenderNoResultsItem, this.computedUnrenderNoResultsItem);
595
+ },
596
+ unrenderNoResultsItem() {
597
+ if (this.instance)
598
+ this.instance.setRenderNoResultsItem(this.computedRenderNoResultsItem, this.computedUnrenderNoResultsItem);
599
+ },
600
+ renderListItem() {
601
+ if (this.instance)
602
+ this.instance.setListOptions(this.computedListOptions);
603
+ },
604
+ unrenderListItem() {
605
+ if (this.instance)
606
+ this.instance.setListOptions(this.computedListOptions);
607
+ },
608
+ ...(isVue3 ? {} : {
609
+ $scopedSlots() {
610
+ if (this.instance)
611
+ this.instance.setListOptions(this.computedListOptions);
612
+ },
613
+ }),
614
+ $slots() {
615
+ if (this.instance)
616
+ this.instance.setListOptions(this.computedListOptions);
617
+ },
618
+ additionalClasses() {
619
+ if (this.instance)
620
+ this.instance.setAdditionalClasses(this.additionalClassesList);
621
+ },
622
+ isLoadingMode() {
623
+ if (this.instance)
624
+ this.instance.setIsLoadingMode(!!this.isLoadingMode);
625
+ },
626
+ closeListWhenLoading() {
627
+ if (this.instance)
628
+ this.instance.setCloseListWhenLoading(this.closeListWhenLoading ?? DefaultOptions.closeListWhenLoading);
629
+ },
630
+ clearInputWhen() {
631
+ if (this.instance)
632
+ this.instance.setClearInputWhen(this.clearInputWhen);
633
+ },
634
+ treatGroupSelectionAsItems() {
635
+ if (this.instance)
636
+ this.instance.setTreatGroupSelectionAsItems(!!this.treatGroupSelectionAsItems);
637
+ },
638
+ filterDependencies: {
639
+ deep: true,
640
+ handler() {
641
+ if (this.instance)
642
+ this.instance.invokeRefilter();
643
+ },
644
+ },
645
+ el(v) {
646
+ if (v) {
647
+ if (this.isMounted) {
648
+ this._createBox();
649
+ if (window.ResizeObserver === undefined) {
650
+ const wasAttached = this._isAttached;
651
+ this._isAttached = !!this.el && document.body.contains(this.el);
652
+ if (!wasAttached && this.instance && this._isAttached)
653
+ this.instance.refreshSize();
654
+ }
655
+ }
656
+ }
657
+ else {
658
+ this._destroyBox();
659
+ }
660
+ },
661
+ },
662
+ mounted() {
663
+ this.isMounted = true;
664
+ this._createBox();
665
+ if (window.ResizeObserver === undefined && this.instance) {
666
+ const wasAttached = this._isAttached;
667
+ this._isAttached = !!this.$refs.el && document.body.contains(this.$refs.el);
668
+ if (!wasAttached && this.instance && this._isAttached)
669
+ this.instance.refreshSize();
670
+ }
671
+ },
672
+ unmounted() {
673
+ this.isMounted = false;
674
+ },
675
+ methods: {
676
+ _handleBoxEvents(event, data) {
677
+ switch (event) {
678
+ case 'clear:before':
679
+ case 'clear':
680
+ case 'open':
681
+ case 'close':
682
+ case 'search:focus':
683
+ case 'search:blur':
684
+ case 'search:term':
685
+ case 'addsel:before':
686
+ case 'addsel':
687
+ case 'removesel:before':
688
+ case 'removesel':
689
+ case 'select:before':
690
+ case 'select':
691
+ case 'input:resize':
692
+ case 'itemschanged':
693
+ this.$emit(event, ...(data === undefined ? [] : [data]));
694
+ break;
695
+ case 'search':
696
+ this.$emit(event, data.value);
697
+ break;
698
+ }
699
+ if (event === 'select' ||
700
+ event === 'clear' ||
701
+ event === 'groupcheck' ||
702
+ (event === 'addsel' && !event.isCheckingGroup) ||
703
+ (event === 'removesel' && !event.isCheckingGroup)) {
704
+ let value = event === 'select' ? data.value : this.instance.getValue();
705
+ if (value === undefined && event !== 'select' && this.emitNullForEmptyValue)
706
+ value = null;
707
+ this.$emit(isVue3 ? 'update:modelValue' : 'input', value);
708
+ }
709
+ },
710
+ _createBox() {
711
+ this._destroyBox();
712
+ if (!this.el)
713
+ return;
714
+ let box = new SelectBox({
715
+ el: this.el,
716
+ baseClass: this.baseClass,
717
+ direction: this.direction,
718
+ disabled: this.disabled,
719
+ readOnly: this.readOnly ?? false,
720
+ clearable: this.clearable,
721
+ hasOpenIndicator: this.hasOpenIndicator,
722
+ placeholder: this.placeholder,
723
+ sortSelectedItems: this.sortSelectedItems,
724
+ sortListItems: this.sortListItems,
725
+ sortListCheckedFirst: this.sortListCheckedFirst,
726
+ stickyValues: this.stickyValues,
727
+ sortItemComparator: this.sortItemComparator,
728
+ splitListCheckedGroups: this.splitListCheckedGroups,
729
+ showSelection: this.showSelection,
730
+ showPlaceholderInTooltip: this.showPlaceholderInTooltip,
731
+ multiPlaceholderFormatter: this.multiPlaceholderFormatter,
732
+ blurOnSingleSelection: this.blurOnSingleSelection,
733
+ multi: this.multi,
734
+ searchable: this.searchable,
735
+ allowTypeToSelect: this.allowTypeToSelect,
736
+ noResultsText: this.noResultsText ?? DefaultOptions.noResultsText,
737
+ filterThrottleWindow: this.filterThrottleWindow ?? DefaultOptions.filterThrottleWindow ?? 0,
738
+ filterOnEmptyTerm: this.filterOnEmptyTerm,
739
+ labelProp: this.labelProp,
740
+ valueProp: this.valueProp,
741
+ multiItemLabelProp: this.multiItemLabelProp,
742
+ multiItemRemovePosition: this.multiItemRemovePosition,
743
+ maxMultiItems: this.maxMultiItems,
744
+ multiItemsRestLabelProvider: this.multiItemsRestLabelProvider,
745
+ items: this.items,
746
+ listOptions: this.computedListOptions,
747
+ renderSingleItem: this.computedRenderSingleItem,
748
+ unrenderSingleItem: this.computedUnrenderSingleItem,
749
+ renderMultiItem: this.computedRenderMultiItem,
750
+ unrenderMultiItem: this.computedUnrenderMultiItem,
751
+ renderRestMultiItem: this.computedRenderRestMultiItem,
752
+ unrenderRestMultiItem: this.computedUnrenderRestMultiItem,
753
+ filterFn: this.filterFn,
754
+ onError: this.onError,
755
+ on: this._handleBoxEvents.bind(this),
756
+ additionalClasses: this.additionalClassesList,
757
+ isLoadingMode: this.isLoadingMode,
758
+ closeListWhenLoading: this.closeListWhenLoading ?? DefaultOptions.closeListWhenLoading,
759
+ clearInputWhen: this.clearInputWhen,
760
+ treatGroupSelectionAsItems: this.treatGroupSelectionAsItems,
761
+ });
762
+ const modelValue = isVue3 ? this.modelValue : this.value;
763
+ box.setValue(modelValue === null && (!this.acceptNullAsValue || this.multi) ? undefined : modelValue);
764
+ this.instance = markRaw(box);
765
+ this.el = box.el;
766
+ },
767
+ _destroyBox() {
768
+ if (this.instance) {
769
+ this.instance.destroy();
770
+ this.instance = undefined;
771
+ }
772
+ },
773
+ _concatClassesObject(classes) {
774
+ if (Array.isArray(classes)) {
775
+ return classes.join(' ');
776
+ }
777
+ else if (classes && typeof classes === 'object') {
778
+ let arr = [];
779
+ for (let [key, value] of Object.entries(classes)) {
780
+ if (value)
781
+ arr.push(key);
782
+ }
783
+ return arr.join(' ');
784
+ }
785
+ return classes || '';
786
+ },
787
+ toggleLoading(on) {
788
+ if (this.instance)
789
+ this.instance.toggleLoading(on);
790
+ },
791
+ toggleList(open) {
792
+ if (this.instance)
793
+ this.instance.toggleList(open);
794
+ },
795
+ openList() {
796
+ if (this.instance)
797
+ this.instance.openList();
798
+ },
799
+ closeList() {
800
+ if (this.instance)
801
+ this.instance.closeList();
802
+ },
803
+ isListOpen() {
804
+ if (this.instance)
805
+ return this.instance.isListOpen();
806
+ return false;
807
+ },
808
+ updateItemByValue(value, newItem) {
809
+ if (this.instance)
810
+ return this.instance.updateItemByValue(value, newItem);
811
+ },
812
+ getSelectedItems() {
813
+ if (this.instance)
814
+ return this.instance.getSelectedItems();
815
+ return [];
816
+ },
817
+ /**
818
+ * @param {string} term
819
+ * @param {boolean} [performSearch=false] should actually perform the search, or just set the input's text?
820
+ */
821
+ setSearchTerm(term, performSearch) {
822
+ if (term != null && this.instance)
823
+ this.instance.setSearchTerm(term, performSearch);
824
+ },
825
+ /**
826
+ * @returns {string}
827
+ */
828
+ getSearchTerm() {
829
+ if (this.instance)
830
+ return this.instance.getSearchTerm();
831
+ return '';
832
+ },
833
+ /**
834
+ * @returns {number}
835
+ */
836
+ getFilteredItemCount() {
837
+ if (this.instance)
838
+ return this.instance.getFilteredItemCount();
839
+ return 0;
840
+ },
841
+ /**
842
+ * @returns {boolean}
843
+ */
844
+ isFilterPending() {
845
+ if (this.instance)
846
+ return this.instance.isFilterPending();
847
+ return false;
848
+ },
849
+ focus() {
850
+ this.instance?.focusInput();
851
+ },
852
+ blur() {
853
+ this.instance?.blurInput();
854
+ },
855
+ droplistElContains(other, considerSublists = true) {
856
+ return this.instance?.droplistElContains(other, considerSublists);
857
+ },
858
+ },
859
+ });
986
860
  </script>