@danielgindi/selectbox 2.0.57 → 2.0.59

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,784 @@
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
+ export const PropTypes = {
12
+ disabled: {
13
+ type: Boolean,
14
+ default: false
15
+ },
16
+ readOnly: {
17
+ type: Boolean,
18
+ required: false,
19
+ default: null
20
+ },
21
+ clearable: {
22
+ type: Boolean,
23
+ default: true
24
+ },
25
+ hasOpenIndicator: {
26
+ type: Boolean,
27
+ default: true
28
+ },
29
+ placeholder: {
30
+ type: String,
31
+ default: ''
32
+ },
33
+ sortSelectedItems: {
34
+ type: Boolean,
35
+ default: true
36
+ },
37
+ sortListItems: {
38
+ type: Boolean,
39
+ default: false
40
+ },
41
+ sortListCheckedFirst: {
42
+ type: Boolean,
43
+ default: true
44
+ },
45
+ stickyValues: {
46
+ type: Array,
47
+ required: false
48
+ },
49
+ sortItemComparator: {
50
+ type: Function,
51
+ required: false
52
+ },
53
+ splitListCheckedGroups: {
54
+ type: Boolean,
55
+ default: true
56
+ },
57
+ showSelection: {
58
+ type: Boolean,
59
+ default: true
60
+ },
61
+ showPlaceholderInTooltip: {
62
+ type: Boolean,
63
+ default: true
64
+ },
65
+ multiPlaceholderFormatter: {
66
+ type: Function,
67
+ required: false,
68
+ default: undefined
69
+ },
70
+ blurOnSingleSelection: {
71
+ type: [
72
+ Boolean,
73
+ String
74
+ ],
75
+ default: 'touch',
76
+ validator: (value)=>{
77
+ return [
78
+ true,
79
+ false,
80
+ 'touch',
81
+ null
82
+ ].includes(value);
83
+ }
84
+ },
85
+ multi: {
86
+ type: Boolean,
87
+ default: false
88
+ },
89
+ searchable: {
90
+ type: Boolean,
91
+ default: true
92
+ },
93
+ allowTypeToSelect: {
94
+ type: Boolean,
95
+ default: true
96
+ },
97
+ noResultsText: {
98
+ type: String,
99
+ required: false
100
+ },
101
+ filterThrottleWindow: {
102
+ type: Number,
103
+ required: false
104
+ },
105
+ filterOnEmptyTerm: {
106
+ type: Boolean,
107
+ default: false
108
+ },
109
+ filterFn: {
110
+ type: Function,
111
+ default: undefined
112
+ },
113
+ onError: {
114
+ type: Function,
115
+ default: undefined
116
+ },
117
+ filterDependencies: {
118
+ type: [
119
+ Array,
120
+ String,
121
+ Number,
122
+ Boolean,
123
+ Object
124
+ ],
125
+ default: undefined
126
+ },
127
+ labelProp: {
128
+ type: String,
129
+ default: 'label'
130
+ },
131
+ valueProp: {
132
+ type: String,
133
+ default: 'value'
134
+ },
135
+ multiItemLabelProp: {
136
+ type: String,
137
+ default: 'short_label'
138
+ },
139
+ multiItemRemovePosition: {
140
+ type: String,
141
+ default: 'after',
142
+ validator: (value)=>{
143
+ return [
144
+ 'before',
145
+ 'after',
146
+ 'none'
147
+ ].includes(value);
148
+ }
149
+ },
150
+ items: {
151
+ type: Array,
152
+ default: ()=>[]
153
+ },
154
+ [isVue3 ? 'modelValue' : 'value']: {
155
+ type: [
156
+ String,
157
+ Number,
158
+ Boolean,
159
+ Object,
160
+ Array,
161
+ Symbol
162
+ ],
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: [
227
+ Object,
228
+ Array,
229
+ String
230
+ ],
231
+ default: undefined
232
+ },
233
+ additionalDroplistClasses: {
234
+ type: [
235
+ Object,
236
+ Array,
237
+ String
238
+ ],
239
+ default: undefined
240
+ },
241
+ direction: {
242
+ type: String,
243
+ default: undefined
244
+ },
245
+ fixedDroplistWidth: {
246
+ type: Boolean,
247
+ default: false
248
+ },
249
+ acceptNullAsValue: {
250
+ type: Boolean,
251
+ default: false
252
+ },
253
+ emitNullForEmptyValue: {
254
+ type: Boolean,
255
+ default: false
256
+ },
257
+ isLoadingMode: {
258
+ type: Boolean,
259
+ default: false
260
+ },
261
+ closeListWhenLoading: {
262
+ type: Boolean,
263
+ required: false
264
+ },
265
+ clearInputWhen: {
266
+ type: Array,
267
+ required: false,
268
+ default: ()=>[
269
+ 'single_close',
270
+ 'multi_select_single'
271
+ ],
272
+ validator: (value)=>{
273
+ if (value && !Array.isArray(value)) return false;
274
+ for (let v of value){
275
+ if (![
276
+ 'single_close',
277
+ 'multi_close',
278
+ 'multi_select_single'
279
+ ].includes(v)) return false;
280
+ }
281
+ return true;
282
+ }
283
+ },
284
+ treatGroupSelectionAsItems: {
285
+ type: Boolean,
286
+ default: false
287
+ },
288
+ autoCheckGroupChildren: {
289
+ type: Boolean,
290
+ default: true
291
+ },
292
+ constrainListToWindow: {
293
+ type: Boolean,
294
+ default: true
295
+ },
296
+ autoFlipListDirection: {
297
+ type: Boolean,
298
+ default: true
299
+ }
300
+ };
301
+ export default defineComponent({
302
+ inheritAttrs: false,
303
+ props: PropTypes,
304
+ emits: [
305
+ 'update:modelValue',
306
+ 'clear:before',
307
+ 'clear',
308
+ 'open',
309
+ 'close',
310
+ 'search:focus',
311
+ 'search:blur',
312
+ 'search:term',
313
+ 'addsel:before',
314
+ 'addsel',
315
+ 'removesel:before',
316
+ 'removesel',
317
+ 'select:before',
318
+ 'select',
319
+ 'input:resize',
320
+ 'itemschanged',
321
+ 'search'
322
+ ],
323
+ data () {
324
+ return {
325
+ el: undefined,
326
+ isMounted: false,
327
+ instance: undefined
328
+ };
329
+ },
330
+ computed: {
331
+ computedListOptions () {
332
+ let opts = {};
333
+ if (this.droplistBaseClass) {
334
+ opts.baseClassName = this.droplistBaseClass;
335
+ }
336
+ if (this.additionalDroplistClassesList) {
337
+ opts.additionalClasses = this.additionalDroplistClassesList;
338
+ }
339
+ if (typeof this.autoCheckGroupChildren === 'boolean' && this.multi) {
340
+ opts.autoCheckGroupChildren = this.autoCheckGroupChildren;
341
+ }
342
+ if (typeof this.constrainListToWindow === 'boolean') {
343
+ opts.constrainToWindow = this.constrainListToWindow;
344
+ }
345
+ if (typeof this.autoFlipListDirection === 'boolean') {
346
+ opts.autoFlipDirection = this.autoFlipListDirection;
347
+ }
348
+ opts.virtualMinItems = this.virtualMinItems;
349
+ opts.useExactTargetWidth = this.fixedDroplistWidth;
350
+ opts.renderItem = this.renderListItem;
351
+ if (!opts.renderItem) {
352
+ opts.renderItem = createSlotBasedRenderFunc(this, 'list-item');
353
+ }
354
+ opts.unrenderItem = this.unrenderListItem;
355
+ if (!opts.unrenderItem) {
356
+ let fn = createSlotBasedUnrenderFunc(this, 'list-item');
357
+ if (fn) {
358
+ opts.unrenderItem = (item, el)=>fn(el);
359
+ }
360
+ }
361
+ opts.renderNoResultsItem = this.computedRenderNoResultsItem;
362
+ opts.unrenderNoResultsItem = this.computedUnrenderNoResultsItem;
363
+ return opts;
364
+ },
365
+ computedRenderSingleItem () {
366
+ let render = this.renderSingleItem;
367
+ if (!render) {
368
+ render = createSlotBasedRenderFunc(this, 'single-item');
369
+ }
370
+ return render;
371
+ },
372
+ computedUnrenderSingleItem () {
373
+ let unrender = this.unrenderSingleItem;
374
+ if (!unrender) {
375
+ let fn = createSlotBasedUnrenderFunc(this, 'single-item');
376
+ if (fn) {
377
+ unrender = (item, el)=>fn(el);
378
+ }
379
+ }
380
+ return unrender;
381
+ },
382
+ computedRenderMultiItem () {
383
+ let render = this.renderMultiItem;
384
+ if (!render) {
385
+ render = createSlotBasedRenderFunc(this, 'multi-item');
386
+ }
387
+ return render;
388
+ },
389
+ computedUnrenderMultiItem () {
390
+ let unrender = this.unrenderMultiItem;
391
+ if (!unrender) {
392
+ let fn = createSlotBasedUnrenderFunc(this, 'multi-item');
393
+ if (fn) {
394
+ unrender = (item, el)=>fn(el);
395
+ }
396
+ }
397
+ return unrender;
398
+ },
399
+ computedRenderRestMultiItem () {
400
+ let render = this.renderRestMultiItem;
401
+ if (!render) {
402
+ render = createSlotBasedRenderFunc(this, 'rest-multi-item');
403
+ }
404
+ return render;
405
+ },
406
+ computedUnrenderRestMultiItem () {
407
+ let unrender = this.unrenderRestMultiItem;
408
+ if (!unrender) {
409
+ let fn = createSlotBasedUnrenderFunc(this, 'rest-multi-item');
410
+ if (fn) {
411
+ unrender = (item, el)=>fn(el);
412
+ }
413
+ }
414
+ return unrender;
415
+ },
416
+ computedRenderNoResultsItem () {
417
+ let render = this.renderNoResultsItem;
418
+ if (!render) {
419
+ render = createSlotBasedRenderFunc(this, 'no-results-item');
420
+ }
421
+ return render;
422
+ },
423
+ computedUnrenderNoResultsItem () {
424
+ let unrender = this.unrenderNoResultsItem;
425
+ if (!unrender) {
426
+ let fn = createSlotBasedUnrenderFunc(this, 'no-results-item');
427
+ if (fn) {
428
+ unrender = (item, el)=>fn(el);
429
+ }
430
+ }
431
+ return unrender;
432
+ },
433
+ additionalClassesList () {
434
+ return this._concatClassesObject(this.additionalClasses);
435
+ },
436
+ additionalDroplistClassesList () {
437
+ return this._concatClassesObject(this.additionalDroplistClasses);
438
+ }
439
+ },
440
+ watch: {
441
+ disabled (value) {
442
+ if (this.instance) this.instance.disable(value);
443
+ },
444
+ readOnly () {
445
+ if (this.instance) this.instance.setReadOnly(this.readOnly ?? false);
446
+ },
447
+ clearable (value) {
448
+ if (this.instance) this.instance.setClearable(value);
449
+ },
450
+ direction (value) {
451
+ if (this.instance) this.instance.setDirection(value);
452
+ },
453
+ hasOpenIndicator (value) {
454
+ if (this.instance) this.instance.setHasOpenIndicator(value);
455
+ },
456
+ placeholder (value) {
457
+ if (this.instance) this.instance.setPlaceholder(value);
458
+ },
459
+ sortSelectedItems (value) {
460
+ if (this.instance) this.instance.setSortSelectedItems(value);
461
+ },
462
+ sortListItems (value) {
463
+ if (this.instance) this.instance.setSortListItems(value);
464
+ },
465
+ sortListCheckedFirst (value) {
466
+ if (this.instance) this.instance.setSortListCheckedFirst(value);
467
+ },
468
+ stickyValues (value) {
469
+ if (!this.instance) return;
470
+ if (deepEqual(this.stickyValues, value)) return;
471
+ this.instance.setStickyValues(value);
472
+ },
473
+ sortItemComparator (value) {
474
+ if (this.instance) this.instance.setSortItemComparator(value);
475
+ },
476
+ splitListCheckedGroups (value) {
477
+ if (this.instance) this.instance.setSplitListCheckedGroups(value);
478
+ },
479
+ showSelection (value) {
480
+ if (this.instance) this.instance.setShowSelection(value);
481
+ },
482
+ showPlaceholderInTooltip (value) {
483
+ if (this.instance) this.instance.setShowPlaceholderInTooltip(value);
484
+ },
485
+ multiPlaceholderFormatter (formatter) {
486
+ if (this.instance) this.instance.setMultiPlaceholderFormatter(formatter);
487
+ },
488
+ showBlurOnSingleSelection (value) {
489
+ if (this.instance) this.instance.setBlurOnSingleSelection(value);
490
+ },
491
+ multi (value) {
492
+ if (this.instance) this.instance.setMulti(value);
493
+ },
494
+ searchable (value) {
495
+ if (this.instance) this.instance.setSearchable(value);
496
+ },
497
+ allowTypeToSelect (value) {
498
+ if (this.instance) this.instance.setAllowTypeToSelect(value);
499
+ },
500
+ noResultsText (value) {
501
+ if (this.instance) this.instance.setNoResultsText(value ?? DefaultOptions.noResultsText);
502
+ },
503
+ filterThrottleWindow (value) {
504
+ if (this.instance) this.instance.setFilterThrottleWindow(value ?? DefaultOptions.filterThrottleWindow ?? 0);
505
+ },
506
+ filterOnEmptyTerm (value) {
507
+ if (this.instance) this.instance.setFilterOnEmptyTerm(value || false);
508
+ },
509
+ filterFn () {
510
+ if (this.instance) this.instance.setFilterFn(this.filterFn);
511
+ },
512
+ onError () {
513
+ if (this.instance) this.instance.setOnError(this.onError);
514
+ },
515
+ labelProp (value) {
516
+ if (this.instance) this.instance.setLabelProp(value);
517
+ },
518
+ valueProp (value) {
519
+ if (this.instance) this.instance.setValueProp(value);
520
+ },
521
+ multiItemLabelProp (value) {
522
+ if (this.instance) this.instance.setMultiItemLabelProp(value);
523
+ },
524
+ multiItemRemovePosition (value) {
525
+ if (this.instance) this.instance.setMultiItemRemovePosition(value);
526
+ },
527
+ maxMultiItems (value) {
528
+ if (this.instance) this.instance.setMaxMultiItems(value);
529
+ },
530
+ multiItemsRestLabelProvider (value) {
531
+ if (this.instance) this.instance.setMultiItemsRestLabelProvider(value);
532
+ },
533
+ items (value) {
534
+ if (this.instance) {
535
+ this.instance.setItems(value, false);
536
+ const modelValue = isVue3 ? this.modelValue : this.value;
537
+ this.instance.setValue(modelValue === null && (!this.acceptNullAsValue || this.multi) ? undefined : modelValue);
538
+ }
539
+ },
540
+ [isVue3 ? 'modelValue' : 'value'] (value, old) {
541
+ if (Array.isArray(value) && Array.isArray(old) && value.length === old && value.every((v, i)=>old[i] === v)) return;
542
+ if (this.instance) this.instance.setValue(value === null && (!this.acceptNullAsValue || this.multi) ? undefined : value);
543
+ },
544
+ renderSingleItem () {
545
+ if (this.instance) this.instance.setRenderSingleItem(this.computedRenderSingleItem, this.computedUnrenderSingleItem);
546
+ },
547
+ unrenderSingleItem () {
548
+ if (this.instance) this.instance.setRenderSingleItem(this.computedRenderSingleItem, this.computedUnrenderSingleItem);
549
+ },
550
+ renderMultiItem () {
551
+ if (this.instance) this.instance.setRenderMultiItem(this.computedRenderMultiItem, this.computedUnrenderMultiItem);
552
+ },
553
+ unrenderMultiItem () {
554
+ if (this.instance) this.instance.setRenderMultiItem(this.computedRenderMultiItem, this.computedUnrenderMultiItem);
555
+ },
556
+ renderRestMultiItem () {
557
+ if (this.instance) this.instance.setRenderRestMultiItem(this.computedRenderRestMultiItem, this.computedUnrenderRestMultiItem);
558
+ },
559
+ unrenderRestMultiItem () {
560
+ if (this.instance) this.instance.setRenderRestMultiItem(this.computedRenderRestMultiItem, this.computedUnrenderRestMultiItem);
561
+ },
562
+ renderNoResultsItem () {
563
+ if (this.instance) this.instance.setRenderNoResultsItem(this.computedRenderNoResultsItem, this.computedUnrenderNoResultsItem);
564
+ },
565
+ unrenderNoResultsItem () {
566
+ if (this.instance) this.instance.setRenderNoResultsItem(this.computedRenderNoResultsItem, this.computedUnrenderNoResultsItem);
567
+ },
568
+ renderListItem () {
569
+ if (this.instance) this.instance.setListOptions(this.computedListOptions);
570
+ },
571
+ unrenderListItem () {
572
+ if (this.instance) this.instance.setListOptions(this.computedListOptions);
573
+ },
574
+ ...isVue3 ? {} : {
575
+ $scopedSlots () {
576
+ if (this.instance) this.instance.setListOptions(this.computedListOptions);
577
+ }
578
+ },
579
+ $slots () {
580
+ if (this.instance) this.instance.setListOptions(this.computedListOptions);
581
+ },
582
+ additionalClasses () {
583
+ if (this.instance) this.instance.setAdditionalClasses(this.additionalClassesList);
584
+ },
585
+ isLoadingMode () {
586
+ if (this.instance) this.instance.setIsLoadingMode(!!this.isLoadingMode);
587
+ },
588
+ closeListWhenLoading () {
589
+ if (this.instance) this.instance.setCloseListWhenLoading(this.closeListWhenLoading ?? DefaultOptions.closeListWhenLoading);
590
+ },
591
+ clearInputWhen () {
592
+ if (this.instance) this.instance.setClearInputWhen(this.clearInputWhen);
593
+ },
594
+ treatGroupSelectionAsItems () {
595
+ if (this.instance) this.instance.setTreatGroupSelectionAsItems(!!this.treatGroupSelectionAsItems);
596
+ },
597
+ filterDependencies: {
598
+ deep: true,
599
+ handler () {
600
+ if (this.instance) this.instance.invokeRefilter();
601
+ }
602
+ },
603
+ el (v) {
604
+ if (v) {
605
+ if (this.isMounted) {
606
+ this._createBox();
607
+ if (window.ResizeObserver === undefined) {
608
+ const wasAttached = this._isAttached;
609
+ this._isAttached = !!this.el && document.body.contains(this.el);
610
+ if (!wasAttached && this.instance && this._isAttached) this.instance.refreshSize();
611
+ }
612
+ }
613
+ } else {
614
+ this._destroyBox();
615
+ }
616
+ }
617
+ },
618
+ mounted () {
619
+ this.isMounted = true;
620
+ this._createBox();
621
+ if (window.ResizeObserver === undefined && this.instance) {
622
+ const wasAttached = this._isAttached;
623
+ this._isAttached = !!this.$refs.el && document.body.contains(this.$refs.el);
624
+ if (!wasAttached && this.instance && this._isAttached) this.instance.refreshSize();
625
+ }
626
+ },
627
+ unmounted () {
628
+ this.isMounted = false;
629
+ },
630
+ methods: {
631
+ _handleBoxEvents (event, data) {
632
+ switch(event){
633
+ case 'clear:before':
634
+ case 'clear':
635
+ case 'open':
636
+ case 'close':
637
+ case 'search:focus':
638
+ case 'search:blur':
639
+ case 'search:term':
640
+ case 'addsel:before':
641
+ case 'addsel':
642
+ case 'removesel:before':
643
+ case 'removesel':
644
+ case 'select:before':
645
+ case 'select':
646
+ case 'input:resize':
647
+ case 'itemschanged':
648
+ this.$emit(event, ...data === undefined ? [] : [
649
+ data
650
+ ]);
651
+ break;
652
+ case 'search':
653
+ this.$emit(event, data.value);
654
+ break;
655
+ }
656
+ if (event === 'select' || event === 'clear' || event === 'groupcheck' || event === 'addsel' && !event.isCheckingGroup || event === 'removesel' && !event.isCheckingGroup) {
657
+ let value = event === 'select' ? data.value : this.instance.getValue();
658
+ if (value === undefined && event !== 'select' && this.emitNullForEmptyValue) value = null;
659
+ this.$emit(isVue3 ? 'update:modelValue' : 'input', value);
660
+ }
661
+ },
662
+ _createBox () {
663
+ this._destroyBox();
664
+ if (!this.el) return;
665
+ let box = new SelectBox({
666
+ el: this.el,
667
+ baseClass: this.baseClass,
668
+ direction: this.direction,
669
+ disabled: this.disabled,
670
+ readOnly: this.readOnly ?? false,
671
+ clearable: this.clearable,
672
+ hasOpenIndicator: this.hasOpenIndicator,
673
+ placeholder: this.placeholder,
674
+ sortSelectedItems: this.sortSelectedItems,
675
+ sortListItems: this.sortListItems,
676
+ sortListCheckedFirst: this.sortListCheckedFirst,
677
+ stickyValues: this.stickyValues,
678
+ sortItemComparator: this.sortItemComparator,
679
+ splitListCheckedGroups: this.splitListCheckedGroups,
680
+ showSelection: this.showSelection,
681
+ showPlaceholderInTooltip: this.showPlaceholderInTooltip,
682
+ multiPlaceholderFormatter: this.multiPlaceholderFormatter,
683
+ blurOnSingleSelection: this.blurOnSingleSelection,
684
+ multi: this.multi,
685
+ searchable: this.searchable,
686
+ allowTypeToSelect: this.allowTypeToSelect,
687
+ noResultsText: this.noResultsText ?? DefaultOptions.noResultsText,
688
+ filterThrottleWindow: this.filterThrottleWindow ?? DefaultOptions.filterThrottleWindow ?? 0,
689
+ filterOnEmptyTerm: this.filterOnEmptyTerm,
690
+ labelProp: this.labelProp,
691
+ valueProp: this.valueProp,
692
+ multiItemLabelProp: this.multiItemLabelProp,
693
+ multiItemRemovePosition: this.multiItemRemovePosition,
694
+ maxMultiItems: this.maxMultiItems,
695
+ multiItemsRestLabelProvider: this.multiItemsRestLabelProvider,
696
+ items: this.items,
697
+ listOptions: this.computedListOptions,
698
+ renderSingleItem: this.computedRenderSingleItem,
699
+ unrenderSingleItem: this.computedUnrenderSingleItem,
700
+ renderMultiItem: this.computedRenderMultiItem,
701
+ unrenderMultiItem: this.computedUnrenderMultiItem,
702
+ renderRestMultiItem: this.computedRenderRestMultiItem,
703
+ unrenderRestMultiItem: this.computedUnrenderRestMultiItem,
704
+ filterFn: this.filterFn,
705
+ onError: this.onError,
706
+ on: this._handleBoxEvents.bind(this),
707
+ additionalClasses: this.additionalClassesList,
708
+ isLoadingMode: this.isLoadingMode,
709
+ closeListWhenLoading: this.closeListWhenLoading ?? DefaultOptions.closeListWhenLoading,
710
+ clearInputWhen: this.clearInputWhen,
711
+ treatGroupSelectionAsItems: this.treatGroupSelectionAsItems
712
+ });
713
+ const modelValue = isVue3 ? this.modelValue : this.value;
714
+ box.setValue(modelValue === null && (!this.acceptNullAsValue || this.multi) ? undefined : modelValue);
715
+ this.instance = markRaw(box);
716
+ this.el = box.el;
717
+ },
718
+ _destroyBox () {
719
+ if (this.instance) {
720
+ this.instance.destroy();
721
+ this.instance = undefined;
722
+ }
723
+ },
724
+ _concatClassesObject (classes) {
725
+ if (Array.isArray(classes)) {
726
+ return classes.join(' ');
727
+ } else if (classes && typeof classes === 'object') {
728
+ let arr = [];
729
+ for (let [key, value] of Object.entries(classes)){
730
+ if (value) arr.push(key);
731
+ }
732
+ return arr.join(' ');
733
+ }
734
+ return classes || '';
735
+ },
736
+ toggleLoading (on) {
737
+ if (this.instance) this.instance.toggleLoading(on);
738
+ },
739
+ toggleList (open) {
740
+ if (this.instance) this.instance.toggleList(open);
741
+ },
742
+ openList () {
743
+ if (this.instance) this.instance.openList();
744
+ },
745
+ closeList () {
746
+ if (this.instance) this.instance.closeList();
747
+ },
748
+ isListOpen () {
749
+ if (this.instance) return this.instance.isListOpen();
750
+ return false;
751
+ },
752
+ updateItemByValue (value, newItem) {
753
+ if (this.instance) return this.instance.updateItemByValue(value, newItem);
754
+ },
755
+ getSelectedItems () {
756
+ if (this.instance) return this.instance.getSelectedItems();
757
+ return [];
758
+ },
759
+ setSearchTerm (term, performSearch) {
760
+ if (term != null && this.instance) this.instance.setSearchTerm(term, performSearch);
761
+ },
762
+ getSearchTerm () {
763
+ if (this.instance) return this.instance.getSearchTerm();
764
+ return '';
765
+ },
766
+ getFilteredItemCount () {
767
+ if (this.instance) return this.instance.getFilteredItemCount();
768
+ return 0;
769
+ },
770
+ isFilterPending () {
771
+ if (this.instance) return this.instance.isFilterPending();
772
+ return false;
773
+ },
774
+ focus () {
775
+ this.instance?.focusInput();
776
+ },
777
+ blur () {
778
+ this.instance?.blurInput();
779
+ },
780
+ droplistElContains (other, considerSublists = true) {
781
+ return this.instance?.droplistElContains(other, considerSublists);
782
+ }
783
+ }
784
+ });
986
785
  </script>