@danielgindi/selectbox 2.0.58 → 2.0.60

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
@@ -8,282 +8,295 @@ import SelectBox, { DefaultOptions } from '../lib/SelectBox';
8
8
  import { createSlotBasedRenderFunc, createSlotBasedUnrenderFunc } from './utils/slots';
9
9
  import deepEqual from 'fast-deep-equal';
10
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
11
  export const PropTypes = {
37
12
  disabled: {
38
13
  type: Boolean,
39
- default: false,
14
+ default: false
40
15
  },
41
16
  readOnly: {
42
17
  type: Boolean,
43
18
  required: false,
44
- default: null,
19
+ default: null
45
20
  },
46
21
  clearable: {
47
22
  type: Boolean,
48
- default: true,
23
+ default: true
49
24
  },
50
25
  hasOpenIndicator: {
51
26
  type: Boolean,
52
- default: true,
27
+ default: true
53
28
  },
54
29
  placeholder: {
55
30
  type: String,
56
- default: '',
31
+ default: ''
57
32
  },
58
33
  sortSelectedItems: {
59
34
  type: Boolean,
60
- default: true,
35
+ default: true
61
36
  },
62
37
  sortListItems: {
63
38
  type: Boolean,
64
- default: false,
39
+ default: false
65
40
  },
66
41
  sortListCheckedFirst: {
67
42
  type: Boolean,
68
- default: true,
43
+ default: true
69
44
  },
70
45
  stickyValues: {
71
46
  type: Array,
72
- required: false,
47
+ required: false
73
48
  },
74
49
  sortItemComparator: {
75
50
  type: Function,
76
- required: false,
51
+ required: false
77
52
  },
78
53
  splitListCheckedGroups: {
79
54
  type: Boolean,
80
- default: true,
55
+ default: true
81
56
  },
82
57
  showSelection: {
83
58
  type: Boolean,
84
- default: true,
59
+ default: true
85
60
  },
86
61
  showPlaceholderInTooltip: {
87
62
  type: Boolean,
88
- default: true,
63
+ default: true
89
64
  },
90
65
  multiPlaceholderFormatter: {
91
66
  type: Function,
92
67
  required: false,
93
- default: undefined,
68
+ default: undefined
94
69
  },
95
70
  blurOnSingleSelection: {
96
- type: [Boolean, String],
71
+ type: [
72
+ Boolean,
73
+ String
74
+ ],
97
75
  default: 'touch',
98
- validator: (value) => {
99
- return [true, false, 'touch', null].includes(value);
100
- },
76
+ validator: (value)=>{
77
+ return [
78
+ true,
79
+ false,
80
+ 'touch',
81
+ null
82
+ ].includes(value);
83
+ }
101
84
  },
102
85
  multi: {
103
86
  type: Boolean,
104
- default: false,
87
+ default: false
105
88
  },
106
89
  searchable: {
107
90
  type: Boolean,
108
- default: true,
91
+ default: true
109
92
  },
110
93
  allowTypeToSelect: {
111
94
  type: Boolean,
112
- default: true,
95
+ default: true
113
96
  },
114
97
  noResultsText: {
115
98
  type: String,
116
- required: false,
99
+ required: false
117
100
  },
118
101
  filterThrottleWindow: {
119
102
  type: Number,
120
- required: false,
103
+ required: false
121
104
  },
122
105
  filterOnEmptyTerm: {
123
106
  type: Boolean,
124
- default: false,
107
+ default: false
125
108
  },
126
109
  filterFn: {
127
110
  type: Function,
128
- default: undefined,
111
+ default: undefined
129
112
  },
130
113
  onError: {
131
114
  type: Function,
132
- default: undefined,
115
+ default: undefined
133
116
  },
134
117
  filterDependencies: {
135
- type: [Array, String, Number, Boolean, Object],
136
- default: undefined,
118
+ type: [
119
+ Array,
120
+ String,
121
+ Number,
122
+ Boolean,
123
+ Object
124
+ ],
125
+ default: undefined
137
126
  },
138
127
  labelProp: {
139
128
  type: String,
140
- default: 'label',
129
+ default: 'label'
141
130
  },
142
131
  valueProp: {
143
132
  type: String,
144
- default: 'value',
133
+ default: 'value'
145
134
  },
146
135
  multiItemLabelProp: {
147
136
  type: String,
148
- default: 'short_label',
137
+ default: 'short_label'
149
138
  },
150
139
  multiItemRemovePosition: {
151
140
  type: String,
152
141
  default: 'after',
153
- validator: (value) => {
154
- return ['before', 'after', 'none'].includes(value);
155
- },
142
+ validator: (value)=>{
143
+ return [
144
+ 'before',
145
+ 'after',
146
+ 'none'
147
+ ].includes(value);
148
+ }
156
149
  },
157
150
  items: {
158
151
  type: Array,
159
- default: () => [],
152
+ default: ()=>[]
160
153
  },
161
154
  [isVue3 ? 'modelValue' : 'value']: {
162
- type: [String, Number, Boolean, Object, Array, Symbol],
163
- default: undefined,
155
+ type: [
156
+ String,
157
+ Number,
158
+ Boolean,
159
+ Object,
160
+ Array,
161
+ Symbol
162
+ ],
163
+ default: undefined
164
164
  },
165
165
  maxMultiItems: {
166
166
  type: Number,
167
- required: false,
167
+ required: false
168
168
  },
169
169
  multiItemsRestLabelProvider: {
170
170
  type: Function,
171
- required: false,
171
+ required: false
172
172
  },
173
173
  renderSingleItem: {
174
174
  type: Function,
175
- default: undefined,
175
+ default: undefined
176
176
  },
177
177
  unrenderSingleItem: {
178
178
  type: Function,
179
- default: undefined,
179
+ default: undefined
180
180
  },
181
181
  renderMultiItem: {
182
182
  type: Function,
183
- default: undefined,
183
+ default: undefined
184
184
  },
185
185
  unrenderMultiItem: {
186
186
  type: Function,
187
- default: undefined,
187
+ default: undefined
188
188
  },
189
189
  renderRestMultiItem: {
190
190
  type: Function,
191
- default: undefined,
191
+ default: undefined
192
192
  },
193
193
  unrenderRestMultiItem: {
194
194
  type: Function,
195
- default: undefined,
195
+ default: undefined
196
196
  },
197
197
  renderNoResultsItem: {
198
198
  type: Function,
199
- default: undefined,
199
+ default: undefined
200
200
  },
201
201
  unrenderNoResultsItem: {
202
202
  type: Function,
203
- default: undefined,
203
+ default: undefined
204
204
  },
205
205
  renderListItem: {
206
206
  type: Function,
207
- default: undefined,
207
+ default: undefined
208
208
  },
209
209
  unrenderListItem: {
210
210
  type: Function,
211
- default: undefined,
211
+ default: undefined
212
212
  },
213
213
  virtualMinItems: {
214
214
  type: Number,
215
- default: 10,
215
+ default: 10
216
216
  },
217
217
  baseClass: {
218
218
  type: String,
219
- default: undefined,
219
+ default: undefined
220
220
  },
221
221
  droplistBaseClass: {
222
222
  type: String,
223
- default: undefined,
223
+ default: undefined
224
224
  },
225
225
  additionalClasses: {
226
- type: [Object, Array, String],
227
- default: undefined,
226
+ type: [
227
+ Object,
228
+ Array,
229
+ String
230
+ ],
231
+ default: undefined
228
232
  },
229
233
  additionalDroplistClasses: {
230
- type: [Object, Array, String],
231
- default: undefined,
234
+ type: [
235
+ Object,
236
+ Array,
237
+ String
238
+ ],
239
+ default: undefined
232
240
  },
233
241
  direction: {
234
242
  type: String,
235
- default: undefined,
243
+ default: undefined
236
244
  },
237
245
  fixedDroplistWidth: {
238
246
  type: Boolean,
239
- default: false,
247
+ default: false
240
248
  },
241
249
  acceptNullAsValue: {
242
250
  type: Boolean,
243
- default: false,
251
+ default: false
244
252
  },
245
253
  emitNullForEmptyValue: {
246
254
  type: Boolean,
247
- default: false,
255
+ default: false
248
256
  },
249
257
  isLoadingMode: {
250
258
  type: Boolean,
251
- default: false,
259
+ default: false
252
260
  },
253
261
  closeListWhenLoading: {
254
262
  type: Boolean,
255
- required: false,
263
+ required: false
256
264
  },
257
265
  clearInputWhen: {
258
266
  type: Array,
259
267
  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;
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;
267
280
  }
268
281
  return true;
269
- },
282
+ }
270
283
  },
271
284
  treatGroupSelectionAsItems: {
272
285
  type: Boolean,
273
- default: false,
286
+ default: false
274
287
  },
275
288
  autoCheckGroupChildren: {
276
289
  type: Boolean,
277
- default: true,
290
+ default: true
278
291
  },
279
292
  constrainListToWindow: {
280
293
  type: Boolean,
281
- default: true,
294
+ default: true
282
295
  },
283
296
  autoFlipListDirection: {
284
297
  type: Boolean,
285
- default: true,
286
- },
298
+ default: true
299
+ }
287
300
  };
288
301
  export default defineComponent({
289
302
  inheritAttrs: false,
@@ -305,17 +318,17 @@ export default defineComponent({
305
318
  'select',
306
319
  'input:resize',
307
320
  'itemschanged',
308
- 'search',
321
+ 'search'
309
322
  ],
310
- data() {
323
+ data () {
311
324
  return {
312
325
  el: undefined,
313
326
  isMounted: false,
314
- instance: undefined,
327
+ instance: undefined
315
328
  };
316
329
  },
317
330
  computed: {
318
- computedListOptions() {
331
+ computedListOptions () {
319
332
  let opts = {};
320
333
  if (this.droplistBaseClass) {
321
334
  opts.baseClassName = this.droplistBaseClass;
@@ -342,339 +355,281 @@ export default defineComponent({
342
355
  if (!opts.unrenderItem) {
343
356
  let fn = createSlotBasedUnrenderFunc(this, 'list-item');
344
357
  if (fn) {
345
- opts.unrenderItem = (item, el) => fn(el);
358
+ opts.unrenderItem = (item, el)=>fn(el);
346
359
  }
347
360
  }
348
361
  opts.renderNoResultsItem = this.computedRenderNoResultsItem;
349
362
  opts.unrenderNoResultsItem = this.computedUnrenderNoResultsItem;
350
363
  return opts;
351
364
  },
352
- computedRenderSingleItem() {
365
+ computedRenderSingleItem () {
353
366
  let render = this.renderSingleItem;
354
367
  if (!render) {
355
368
  render = createSlotBasedRenderFunc(this, 'single-item');
356
369
  }
357
370
  return render;
358
371
  },
359
- computedUnrenderSingleItem() {
372
+ computedUnrenderSingleItem () {
360
373
  let unrender = this.unrenderSingleItem;
361
374
  if (!unrender) {
362
375
  let fn = createSlotBasedUnrenderFunc(this, 'single-item');
363
376
  if (fn) {
364
- unrender = (item, el) => fn(el);
377
+ unrender = (item, el)=>fn(el);
365
378
  }
366
379
  }
367
380
  return unrender;
368
381
  },
369
- computedRenderMultiItem() {
382
+ computedRenderMultiItem () {
370
383
  let render = this.renderMultiItem;
371
384
  if (!render) {
372
385
  render = createSlotBasedRenderFunc(this, 'multi-item');
373
386
  }
374
387
  return render;
375
388
  },
376
- computedUnrenderMultiItem() {
389
+ computedUnrenderMultiItem () {
377
390
  let unrender = this.unrenderMultiItem;
378
391
  if (!unrender) {
379
392
  let fn = createSlotBasedUnrenderFunc(this, 'multi-item');
380
393
  if (fn) {
381
- unrender = (item, el) => fn(el);
394
+ unrender = (item, el)=>fn(el);
382
395
  }
383
396
  }
384
397
  return unrender;
385
398
  },
386
- computedRenderRestMultiItem() {
399
+ computedRenderRestMultiItem () {
387
400
  let render = this.renderRestMultiItem;
388
401
  if (!render) {
389
402
  render = createSlotBasedRenderFunc(this, 'rest-multi-item');
390
403
  }
391
404
  return render;
392
405
  },
393
- computedUnrenderRestMultiItem() {
406
+ computedUnrenderRestMultiItem () {
394
407
  let unrender = this.unrenderRestMultiItem;
395
408
  if (!unrender) {
396
409
  let fn = createSlotBasedUnrenderFunc(this, 'rest-multi-item');
397
410
  if (fn) {
398
- unrender = (item, el) => fn(el);
411
+ unrender = (item, el)=>fn(el);
399
412
  }
400
413
  }
401
414
  return unrender;
402
415
  },
403
- computedRenderNoResultsItem() {
416
+ computedRenderNoResultsItem () {
404
417
  let render = this.renderNoResultsItem;
405
418
  if (!render) {
406
419
  render = createSlotBasedRenderFunc(this, 'no-results-item');
407
420
  }
408
421
  return render;
409
422
  },
410
- computedUnrenderNoResultsItem() {
423
+ computedUnrenderNoResultsItem () {
411
424
  let unrender = this.unrenderNoResultsItem;
412
425
  if (!unrender) {
413
426
  let fn = createSlotBasedUnrenderFunc(this, 'no-results-item');
414
427
  if (fn) {
415
- unrender = (item, el) => fn(el);
428
+ unrender = (item, el)=>fn(el);
416
429
  }
417
430
  }
418
431
  return unrender;
419
432
  },
420
- additionalClassesList() {
433
+ additionalClassesList () {
421
434
  return this._concatClassesObject(this.additionalClasses);
422
435
  },
423
- additionalDroplistClassesList() {
436
+ additionalDroplistClassesList () {
424
437
  return this._concatClassesObject(this.additionalDroplistClasses);
425
- },
438
+ }
426
439
  },
427
440
  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;
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;
472
471
  this.instance.setStickyValues(value);
473
472
  },
474
- sortItemComparator(value) {
475
- if (this.instance)
476
- this.instance.setSortItemComparator(value);
473
+ sortItemComparator (value) {
474
+ if (this.instance) this.instance.setSortItemComparator(value);
477
475
  },
478
- splitListCheckedGroups(value) {
479
- if (this.instance)
480
- this.instance.setSplitListCheckedGroups(value);
476
+ splitListCheckedGroups (value) {
477
+ if (this.instance) this.instance.setSplitListCheckedGroups(value);
481
478
  },
482
- showSelection(value) {
483
- if (this.instance)
484
- this.instance.setShowSelection(value);
479
+ showSelection (value) {
480
+ if (this.instance) this.instance.setShowSelection(value);
485
481
  },
486
- showPlaceholderInTooltip(value) {
487
- if (this.instance)
488
- this.instance.setShowPlaceholderInTooltip(value);
482
+ showPlaceholderInTooltip (value) {
483
+ if (this.instance) this.instance.setShowPlaceholderInTooltip(value);
489
484
  },
490
- multiPlaceholderFormatter(formatter) {
491
- if (this.instance)
492
- this.instance.setMultiPlaceholderFormatter(formatter);
485
+ multiPlaceholderFormatter (formatter) {
486
+ if (this.instance) this.instance.setMultiPlaceholderFormatter(formatter);
493
487
  },
494
- showBlurOnSingleSelection(value) {
495
- if (this.instance)
496
- this.instance.setBlurOnSingleSelection(value);
488
+ showBlurOnSingleSelection (value) {
489
+ if (this.instance) this.instance.setBlurOnSingleSelection(value);
497
490
  },
498
- multi(value) {
499
- if (this.instance)
500
- this.instance.setMulti(value);
491
+ multi (value) {
492
+ if (this.instance) this.instance.setMulti(value);
501
493
  },
502
- searchable(value) {
503
- if (this.instance)
504
- this.instance.setSearchable(value);
494
+ searchable (value) {
495
+ if (this.instance) this.instance.setSearchable(value);
505
496
  },
506
- allowTypeToSelect(value) {
507
- if (this.instance)
508
- this.instance.setAllowTypeToSelect(value);
497
+ allowTypeToSelect (value) {
498
+ if (this.instance) this.instance.setAllowTypeToSelect(value);
509
499
  },
510
- noResultsText(value) {
511
- if (this.instance)
512
- this.instance.setNoResultsText(value ?? DefaultOptions.noResultsText);
500
+ noResultsText (value) {
501
+ if (this.instance) this.instance.setNoResultsText(value ?? DefaultOptions.noResultsText);
513
502
  },
514
- filterThrottleWindow(value) {
515
- if (this.instance)
516
- this.instance.setFilterThrottleWindow(value ?? DefaultOptions.filterThrottleWindow ?? 0);
503
+ filterThrottleWindow (value) {
504
+ if (this.instance) this.instance.setFilterThrottleWindow(value ?? DefaultOptions.filterThrottleWindow ?? 0);
517
505
  },
518
- filterOnEmptyTerm(value) {
519
- if (this.instance)
520
- this.instance.setFilterOnEmptyTerm(value || false);
506
+ filterOnEmptyTerm (value) {
507
+ if (this.instance) this.instance.setFilterOnEmptyTerm(value || false);
521
508
  },
522
- filterFn() {
523
- if (this.instance)
524
- this.instance.setFilterFn(this.filterFn);
509
+ filterFn () {
510
+ if (this.instance) this.instance.setFilterFn(this.filterFn);
525
511
  },
526
- onError() {
527
- if (this.instance)
528
- this.instance.setOnError(this.onError);
512
+ onError () {
513
+ if (this.instance) this.instance.setOnError(this.onError);
529
514
  },
530
- labelProp(value) {
531
- if (this.instance)
532
- this.instance.setLabelProp(value);
515
+ labelProp (value) {
516
+ if (this.instance) this.instance.setLabelProp(value);
533
517
  },
534
- valueProp(value) {
535
- if (this.instance)
536
- this.instance.setValueProp(value);
518
+ valueProp (value) {
519
+ if (this.instance) this.instance.setValueProp(value);
537
520
  },
538
- multiItemLabelProp(value) {
539
- if (this.instance)
540
- this.instance.setMultiItemLabelProp(value);
521
+ multiItemLabelProp (value) {
522
+ if (this.instance) this.instance.setMultiItemLabelProp(value);
541
523
  },
542
- multiItemRemovePosition(value) {
543
- if (this.instance)
544
- this.instance.setMultiItemRemovePosition(value);
524
+ multiItemRemovePosition (value) {
525
+ if (this.instance) this.instance.setMultiItemRemovePosition(value);
545
526
  },
546
- maxMultiItems(value) {
547
- if (this.instance)
548
- this.instance.setMaxMultiItems(value);
527
+ maxMultiItems (value) {
528
+ if (this.instance) this.instance.setMaxMultiItems(value);
549
529
  },
550
- multiItemsRestLabelProvider(value) {
551
- if (this.instance)
552
- this.instance.setMultiItemsRestLabelProvider(value);
530
+ multiItemsRestLabelProvider (value) {
531
+ if (this.instance) this.instance.setMultiItemsRestLabelProvider(value);
553
532
  },
554
- items(value) {
533
+ items (value) {
555
534
  if (this.instance) {
556
535
  this.instance.setItems(value, false);
557
536
  const modelValue = isVue3 ? this.modelValue : this.value;
558
537
  this.instance.setValue(modelValue === null && (!this.acceptNullAsValue || this.multi) ? undefined : modelValue);
559
538
  }
560
539
  },
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);
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);
637
596
  },
638
597
  filterDependencies: {
639
598
  deep: true,
640
- handler() {
641
- if (this.instance)
642
- this.instance.invokeRefilter();
643
- },
599
+ handler () {
600
+ if (this.instance) this.instance.invokeRefilter();
601
+ }
644
602
  },
645
- el(v) {
603
+ el (v) {
646
604
  if (v) {
647
605
  if (this.isMounted) {
648
606
  this._createBox();
649
607
  if (window.ResizeObserver === undefined) {
650
608
  const wasAttached = this._isAttached;
651
609
  this._isAttached = !!this.el && document.body.contains(this.el);
652
- if (!wasAttached && this.instance && this._isAttached)
653
- this.instance.refreshSize();
610
+ if (!wasAttached && this.instance && this._isAttached) this.instance.refreshSize();
654
611
  }
655
612
  }
656
- }
657
- else {
613
+ } else {
658
614
  this._destroyBox();
659
615
  }
660
- },
616
+ }
661
617
  },
662
- mounted() {
618
+ mounted () {
663
619
  this.isMounted = true;
664
620
  this._createBox();
665
621
  if (window.ResizeObserver === undefined && this.instance) {
666
622
  const wasAttached = this._isAttached;
667
623
  this._isAttached = !!this.$refs.el && document.body.contains(this.$refs.el);
668
- if (!wasAttached && this.instance && this._isAttached)
669
- this.instance.refreshSize();
624
+ if (!wasAttached && this.instance && this._isAttached) this.instance.refreshSize();
670
625
  }
671
626
  },
672
- unmounted() {
627
+ unmounted () {
673
628
  this.isMounted = false;
674
629
  },
675
630
  methods: {
676
- _handleBoxEvents(event, data) {
677
- switch (event) {
631
+ _handleBoxEvents (event, data) {
632
+ switch(event){
678
633
  case 'clear:before':
679
634
  case 'clear':
680
635
  case 'open':
@@ -690,27 +645,23 @@ export default defineComponent({
690
645
  case 'select':
691
646
  case 'input:resize':
692
647
  case 'itemschanged':
693
- this.$emit(event, ...(data === undefined ? [] : [data]));
648
+ this.$emit(event, ...data === undefined ? [] : [
649
+ data
650
+ ]);
694
651
  break;
695
652
  case 'search':
696
653
  this.$emit(event, data.value);
697
654
  break;
698
655
  }
699
- if (event === 'select' ||
700
- event === 'clear' ||
701
- event === 'groupcheck' ||
702
- (event === 'addsel' && !event.isCheckingGroup) ||
703
- (event === 'removesel' && !event.isCheckingGroup)) {
656
+ if (event === 'select' || event === 'clear' || event === 'groupcheck' || event === 'addsel' && !event.isCheckingGroup || event === 'removesel' && !event.isCheckingGroup) {
704
657
  let value = event === 'select' ? data.value : this.instance.getValue();
705
- if (value === undefined && event !== 'select' && this.emitNullForEmptyValue)
706
- value = null;
658
+ if (value === undefined && event !== 'select' && this.emitNullForEmptyValue) value = null;
707
659
  this.$emit(isVue3 ? 'update:modelValue' : 'input', value);
708
660
  }
709
661
  },
710
- _createBox() {
662
+ _createBox () {
711
663
  this._destroyBox();
712
- if (!this.el)
713
- return;
664
+ if (!this.el) return;
714
665
  let box = new SelectBox({
715
666
  el: this.el,
716
667
  baseClass: this.baseClass,
@@ -757,104 +708,78 @@ export default defineComponent({
757
708
  isLoadingMode: this.isLoadingMode,
758
709
  closeListWhenLoading: this.closeListWhenLoading ?? DefaultOptions.closeListWhenLoading,
759
710
  clearInputWhen: this.clearInputWhen,
760
- treatGroupSelectionAsItems: this.treatGroupSelectionAsItems,
711
+ treatGroupSelectionAsItems: this.treatGroupSelectionAsItems
761
712
  });
762
713
  const modelValue = isVue3 ? this.modelValue : this.value;
763
714
  box.setValue(modelValue === null && (!this.acceptNullAsValue || this.multi) ? undefined : modelValue);
764
715
  this.instance = markRaw(box);
765
716
  this.el = box.el;
766
717
  },
767
- _destroyBox() {
718
+ _destroyBox () {
768
719
  if (this.instance) {
769
720
  this.instance.destroy();
770
721
  this.instance = undefined;
771
722
  }
772
723
  },
773
- _concatClassesObject(classes) {
724
+ _concatClassesObject (classes) {
774
725
  if (Array.isArray(classes)) {
775
726
  return classes.join(' ');
776
- }
777
- else if (classes && typeof classes === 'object') {
727
+ } else if (classes && typeof classes === 'object') {
778
728
  let arr = [];
779
- for (let [key, value] of Object.entries(classes)) {
780
- if (value)
781
- arr.push(key);
729
+ for (let [key, value] of Object.entries(classes)){
730
+ if (value) arr.push(key);
782
731
  }
783
732
  return arr.join(' ');
784
733
  }
785
734
  return classes || '';
786
735
  },
787
- toggleLoading(on) {
788
- if (this.instance)
789
- this.instance.toggleLoading(on);
736
+ toggleLoading (on) {
737
+ if (this.instance) this.instance.toggleLoading(on);
790
738
  },
791
- toggleList(open) {
792
- if (this.instance)
793
- this.instance.toggleList(open);
739
+ toggleList (open) {
740
+ if (this.instance) this.instance.toggleList(open);
794
741
  },
795
- openList() {
796
- if (this.instance)
797
- this.instance.openList();
742
+ openList () {
743
+ if (this.instance) this.instance.openList();
798
744
  },
799
- closeList() {
800
- if (this.instance)
801
- this.instance.closeList();
745
+ closeList () {
746
+ if (this.instance) this.instance.closeList();
802
747
  },
803
- isListOpen() {
804
- if (this.instance)
805
- return this.instance.isListOpen();
748
+ isListOpen () {
749
+ if (this.instance) return this.instance.isListOpen();
806
750
  return false;
807
751
  },
808
- updateItemByValue(value, newItem) {
809
- if (this.instance)
810
- return this.instance.updateItemByValue(value, newItem);
752
+ updateItemByValue (value, newItem) {
753
+ if (this.instance) return this.instance.updateItemByValue(value, newItem);
811
754
  },
812
- getSelectedItems() {
813
- if (this.instance)
814
- return this.instance.getSelectedItems();
755
+ getSelectedItems () {
756
+ if (this.instance) return this.instance.getSelectedItems();
815
757
  return [];
816
758
  },
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();
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();
831
764
  return '';
832
765
  },
833
- /**
834
- * @returns {number}
835
- */
836
- getFilteredItemCount() {
837
- if (this.instance)
838
- return this.instance.getFilteredItemCount();
766
+ getFilteredItemCount () {
767
+ if (this.instance) return this.instance.getFilteredItemCount();
839
768
  return 0;
840
769
  },
841
- /**
842
- * @returns {boolean}
843
- */
844
- isFilterPending() {
845
- if (this.instance)
846
- return this.instance.isFilterPending();
770
+ isFilterPending () {
771
+ if (this.instance) return this.instance.isFilterPending();
847
772
  return false;
848
773
  },
849
- focus() {
774
+ focus () {
850
775
  this.instance?.focusInput();
851
776
  },
852
- blur() {
777
+ blur () {
853
778
  this.instance?.blurInput();
854
779
  },
855
- droplistElContains(other, considerSublists = true) {
780
+ droplistElContains (other, considerSublists = true) {
856
781
  return this.instance?.droplistElContains(other, considerSublists);
857
- },
858
- },
782
+ }
783
+ }
859
784
  });
860
785
  </script>