@danielgindi/selectbox 2.0.58 → 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/DropList.vue CHANGED
@@ -9,159 +9,181 @@ import { createSlotBasedRenderFunc, createSlotBasedUnrenderFunc } from './utils/
9
9
  import { defineComponent, version } from 'vue';
10
10
  const isVue3 = version > '3.';
11
11
  const AllListEvents = [
12
- 'itemfocus', 'itemblur', 'select',
13
- 'show:before', 'show',
14
- 'hide:before', 'hide', 'hide:after',
15
- 'check', 'groupcheck', 'blur',
16
- 'show_subitems', 'hide_subitems',
17
- 'subitems:select', 'subitems:blur',
12
+ 'itemfocus',
13
+ 'itemblur',
14
+ 'select',
15
+ 'show:before',
16
+ 'show',
17
+ 'hide:before',
18
+ 'hide',
19
+ 'hide:after',
20
+ 'check',
21
+ 'groupcheck',
22
+ 'blur',
23
+ 'show_subitems',
24
+ 'hide_subitems',
25
+ 'subitems:select',
26
+ 'subitems:blur'
18
27
  ];
19
28
  export const PropTypes = {
20
29
  baseClassName: {
21
- type: String,
30
+ type: String
22
31
  },
23
32
  additionalClasses: {
24
- type: [Object, Array, String],
33
+ type: [
34
+ Object,
35
+ Array,
36
+ String
37
+ ]
25
38
  },
26
39
  direction: {
27
40
  type: String,
28
- default: undefined,
41
+ default: undefined
29
42
  },
30
43
  autoFocus: {
31
44
  type: Boolean,
32
- default: true,
45
+ default: true
33
46
  },
34
47
  autoItemBlur: {
35
48
  type: Boolean,
36
- default: true,
49
+ default: true
37
50
  },
38
51
  autoItemBlurDelay: {
39
52
  type: Number,
40
- default: 300,
53
+ default: 300
41
54
  },
42
55
  capturesFocus: {
43
56
  type: Boolean,
44
- default: true,
57
+ default: true
45
58
  },
46
59
  multi: {
47
60
  type: Boolean,
48
- default: false,
61
+ default: false
49
62
  },
50
63
  isHeaderVisible: {
51
64
  type: Boolean,
52
- default: false,
65
+ default: false
53
66
  },
54
67
  isFooterVisible: {
55
68
  type: Boolean,
56
- default: false,
69
+ default: false
57
70
  },
58
71
  searchable: {
59
72
  type: Boolean,
60
- default: false,
73
+ default: false
61
74
  },
62
75
  searchPlaceholder: {
63
76
  type: String,
64
- required: false,
77
+ required: false
65
78
  },
66
79
  noResultsText: {
67
80
  type: String,
68
- required: false,
81
+ required: false
69
82
  },
70
83
  filterThrottleWindow: {
71
84
  type: Number,
72
- required: false,
85
+ required: false
73
86
  },
74
87
  filterOnEmptyTerm: {
75
88
  type: Boolean,
76
- default: false,
89
+ default: false
77
90
  },
78
91
  filterGroups: {
79
92
  type: Boolean,
80
- default: false,
93
+ default: false
81
94
  },
82
95
  filterEmptyGroups: {
83
96
  type: Boolean,
84
- default: false,
97
+ default: false
85
98
  },
86
99
  filterFn: {
87
100
  type: Function,
88
- default: undefined,
101
+ default: undefined
89
102
  },
90
103
  filterDependencies: {
91
- type: [Array, String, Number, Boolean, Object],
92
- default: undefined,
104
+ type: [
105
+ Array,
106
+ String,
107
+ Number,
108
+ Boolean,
109
+ Object
110
+ ],
111
+ default: undefined
93
112
  },
94
113
  keyDownHandler: {
95
- type: Function,
114
+ type: Function
96
115
  },
97
116
  onError: {
98
117
  type: Function,
99
- default: undefined,
118
+ default: undefined
100
119
  },
101
120
  autoCheckGroupChildren: {
102
121
  type: Boolean,
103
- default: true,
122
+ default: true
104
123
  },
105
124
  useExactTargetWidth: {
106
125
  type: Boolean,
107
- default: false,
126
+ default: false
108
127
  },
109
128
  constrainToWindow: {
110
129
  type: Boolean,
111
- default: true,
130
+ default: true
112
131
  },
113
132
  autoFlipDirection: {
114
133
  type: Boolean,
115
- default: true,
134
+ default: true
116
135
  },
117
136
  estimatedItemHeight: {
118
137
  type: Number,
119
- default: 20,
138
+ default: 20
120
139
  },
121
140
  estimateWidth: {
122
141
  type: Boolean,
123
- default: false,
142
+ default: false
124
143
  },
125
144
  virtualMinItems: {
126
145
  type: Number,
127
- default: 10,
146
+ default: 10
128
147
  },
129
148
  labelProp: {
130
149
  type: String,
131
- default: 'label',
150
+ default: 'label'
132
151
  },
133
152
  valueProp: {
134
153
  type: String,
135
- default: 'value',
154
+ default: 'value'
136
155
  },
137
156
  items: {
138
157
  type: Array,
139
- default: () => [],
158
+ default: ()=>[]
140
159
  },
141
160
  [isVue3 ? 'modelValue' : 'value']: {
142
- type: [Number, String, Object, Array],
161
+ type: [
162
+ Number,
163
+ String,
164
+ Object,
165
+ Array
166
+ ]
143
167
  },
144
168
  renderItem: {
145
- type: Function,
169
+ type: Function
146
170
  },
147
171
  unrenderItem: {
148
- type: Function,
172
+ type: Function
149
173
  },
150
174
  positionOptions: {
151
- type: Object,
175
+ type: Object
152
176
  },
153
177
  autoRelayoutOnItemsChange: {
154
178
  type: Boolean,
155
- default: true,
156
- },
179
+ default: true
180
+ }
157
181
  };
158
182
  export default defineComponent({
159
183
  inheritAttrs: false,
160
184
  props: PropTypes,
161
185
  emits: [
162
- // vue events
163
186
  'update:modelValue',
164
- // DropList.js events (passthrough)
165
187
  'itemfocus',
166
188
  'itemblur',
167
189
  'select',
@@ -176,24 +198,23 @@ export default defineComponent({
176
198
  'hide_subitems',
177
199
  'subitems:select',
178
200
  'subitems:blur',
179
- // Element events
180
201
  'keypress',
181
- 'keydown',
202
+ 'keydown'
182
203
  ],
183
- data() {
204
+ data () {
184
205
  return {
185
206
  el: undefined,
186
207
  nonReactive: Object.seal({
187
208
  instance: undefined,
188
- sink: new DomEventsSink(),
189
- }),
209
+ sink: new DomEventsSink()
210
+ })
190
211
  };
191
212
  },
192
213
  computed: {
193
- computedOptions() {
214
+ computedOptions () {
194
215
  let opts = {
195
216
  on: this._handleListEvents.bind(this),
196
- positionOptionsProvider: () => this.positionOptions,
217
+ positionOptionsProvider: ()=>this.positionOptions
197
218
  };
198
219
  if (this.baseClassName) {
199
220
  opts.baseClassName = this.baseClassName;
@@ -204,22 +225,39 @@ export default defineComponent({
204
225
  if (this.direction) {
205
226
  opts.direction = this.direction;
206
227
  }
207
- for (let key of ['autoItemBlur', 'capturesFocus', 'multi',
208
- 'autoCheckGroupChildren', 'useExactTargetWidth', 'constrainToWindow',
209
- 'autoFlipDirection', 'estimateWidth',
210
- 'isHeaderVisible', 'isFooterVisible',
211
- 'searchable', 'filterOnEmptyTerm',
212
- 'filterGroups', 'filterEmptyGroups']) {
228
+ for (let key of [
229
+ 'autoItemBlur',
230
+ 'capturesFocus',
231
+ 'multi',
232
+ 'autoCheckGroupChildren',
233
+ 'useExactTargetWidth',
234
+ 'constrainToWindow',
235
+ 'autoFlipDirection',
236
+ 'estimateWidth',
237
+ 'isHeaderVisible',
238
+ 'isFooterVisible',
239
+ 'searchable',
240
+ 'filterOnEmptyTerm',
241
+ 'filterGroups',
242
+ 'filterEmptyGroups'
243
+ ]){
213
244
  if (typeof this[key] === 'boolean') {
214
245
  opts[key] = this[key];
215
246
  }
216
247
  }
217
- for (let key of ['autoItemBlurDelay', 'estimatedItemHeight', 'virtualMinItems']) {
248
+ for (let key of [
249
+ 'autoItemBlurDelay',
250
+ 'estimatedItemHeight',
251
+ 'virtualMinItems'
252
+ ]){
218
253
  if (typeof this[key] === 'number') {
219
254
  opts[key] = this[key];
220
255
  }
221
256
  }
222
- for (let key of ['labelProp', 'valueProp']) {
257
+ for (let key of [
258
+ 'labelProp',
259
+ 'valueProp'
260
+ ]){
223
261
  if (typeof this[key] === 'string') {
224
262
  opts[key] = this[key];
225
263
  }
@@ -236,7 +274,7 @@ export default defineComponent({
236
274
  if (!opts.unrenderItem) {
237
275
  let fn = createSlotBasedUnrenderFunc(this, 'item');
238
276
  if (fn) {
239
- opts.unrenderItem = (item, el) => fn(el);
277
+ opts.unrenderItem = (item, el)=>fn(el);
240
278
  }
241
279
  }
242
280
  opts.renderNoResultsItem = this.computedRenderNoResultsItem ?? createSlotBasedRenderFunc(this, 'no-results-item');
@@ -244,136 +282,117 @@ export default defineComponent({
244
282
  if (!opts.unrenderNoResultsItem) {
245
283
  let fn = createSlotBasedUnrenderFunc(this, 'no-results-item');
246
284
  if (fn) {
247
- opts.unrenderNoResultsItem = (item, el) => fn(el);
285
+ opts.unrenderNoResultsItem = (item, el)=>fn(el);
248
286
  }
249
287
  }
250
288
  return opts;
251
289
  },
252
- additionalClassesList() {
290
+ additionalClassesList () {
253
291
  return this._concatClassesObject(this.additionalClasses);
254
292
  },
255
- listRef() {
293
+ listRef () {
256
294
  return this.nonReactive.instance;
257
- },
295
+ }
258
296
  },
259
297
  watch: {
260
- items(value) {
298
+ items (value) {
261
299
  if (this.nonReactive.instance) {
262
300
  const instance = this.nonReactive.instance;
263
301
  instance.setItems(Array.isArray(value) ? value : []);
264
- if (this.autoRelayoutOnItemsChange && instance.isVisible())
265
- instance.relayout();
302
+ if (this.autoRelayoutOnItemsChange && instance.isVisible()) instance.relayout();
266
303
  }
267
304
  },
268
- [isVue3 ? 'modelValue' : 'value'](value, old) {
269
- if (Array.isArray(value) && Array.isArray(old) &&
270
- value.length === old && value.every((v, i) => old[i] === v))
271
- return;
305
+ [isVue3 ? 'modelValue' : 'value'] (value, old) {
306
+ if (Array.isArray(value) && Array.isArray(old) && value.length === old && value.every((v, i)=>old[i] === v)) return;
272
307
  if (this.nonReactive.instance) {
273
308
  if (this.multi) {
274
- this.nonReactive.instance.setCheckedValues(Array.isArray(value) ? value : value == null ? [] : [value]);
275
- }
276
- else {
309
+ this.nonReactive.instance.setCheckedValues(Array.isArray(value) ? value : value == null ? [] : [
310
+ value
311
+ ]);
312
+ } else {
277
313
  this.nonReactive.instance.setSingleSelectedItemByValue(value === null ? undefined : value);
278
314
  }
279
315
  }
280
316
  },
281
- additionalClasses() {
282
- if (this.nonReactive.instance)
283
- this.nonReactive.instance.setAdditionalClasses(this.additionalClassesList);
317
+ additionalClasses () {
318
+ if (this.nonReactive.instance) this.nonReactive.instance.setAdditionalClasses(this.additionalClassesList);
284
319
  },
285
- direction(value) {
286
- if (this.nonReactive.instance)
287
- this.nonReactive.instance.setDirection(value);
320
+ direction (value) {
321
+ if (this.nonReactive.instance) this.nonReactive.instance.setDirection(value);
288
322
  },
289
- noResultsText(value) {
290
- if (this.nonReactive.instance)
291
- this.nonReactive.instance.setNoResultsText(value ?? DefaultOptions.noResultsText);
323
+ noResultsText (value) {
324
+ if (this.nonReactive.instance) this.nonReactive.instance.setNoResultsText(value ?? DefaultOptions.noResultsText);
292
325
  },
293
- filterThrottleWindow(value) {
294
- if (this.nonReactive.instance)
295
- this.nonReactive.instance.setFilterThrottleWindow(value ?? DefaultOptions.filterThrottleWindow ?? 0);
326
+ filterThrottleWindow (value) {
327
+ if (this.nonReactive.instance) this.nonReactive.instance.setFilterThrottleWindow(value ?? DefaultOptions.filterThrottleWindow ?? 0);
296
328
  },
297
- filterOnEmptyTerm(value) {
298
- if (this.nonReactive.instance)
299
- this.nonReactive.instance.setFilterOnEmptyTerm(value);
329
+ filterOnEmptyTerm (value) {
330
+ if (this.nonReactive.instance) this.nonReactive.instance.setFilterOnEmptyTerm(value);
300
331
  },
301
- filterGroups(value) {
302
- if (this.nonReactive.instance)
303
- this.nonReactive.instance.setFilterGroups(value);
332
+ filterGroups (value) {
333
+ if (this.nonReactive.instance) this.nonReactive.instance.setFilterGroups(value);
304
334
  },
305
- filterEmptyGroups(value) {
306
- if (this.nonReactive.instance)
307
- this.nonReactive.instance.setFilterEmptyGroups(value);
335
+ filterEmptyGroups (value) {
336
+ if (this.nonReactive.instance) this.nonReactive.instance.setFilterEmptyGroups(value);
308
337
  },
309
- filterFn() {
310
- if (this.nonReactive.instance)
311
- this.nonReactive.instance.setFilterFn(this.filterFn);
338
+ filterFn () {
339
+ if (this.nonReactive.instance) this.nonReactive.instance.setFilterFn(this.filterFn);
312
340
  },
313
- onError() {
314
- if (this.nonReactive.instance)
315
- this.nonReactive.instance.setOnError(this.onError);
341
+ onError () {
342
+ if (this.nonReactive.instance) this.nonReactive.instance.setOnError(this.onError);
316
343
  },
317
- renderItem() {
344
+ renderItem () {
318
345
  this._recreateList();
319
346
  },
320
- unrenderItem() {
347
+ unrenderItem () {
321
348
  this._recreateList();
322
349
  },
323
- renderNoResultsItem() {
350
+ renderNoResultsItem () {
324
351
  this._recreateList();
325
352
  },
326
- unrenderNoResultsItem() {
353
+ unrenderNoResultsItem () {
327
354
  this._recreateList();
328
355
  },
329
- searchable(v) {
330
- if (this.nonReactive.instance)
331
- this.nonReactive.instance.setSearchable(v);
356
+ searchable (v) {
357
+ if (this.nonReactive.instance) this.nonReactive.instance.setSearchable(v);
332
358
  this.relayout();
333
359
  },
334
- searchPlaceholder(value) {
335
- if (this.nonReactive.instance)
336
- this.nonReactive.instance.setSearchPlaceholder(value ?? DefaultOptions.searchPlaceholder);
360
+ searchPlaceholder (value) {
361
+ if (this.nonReactive.instance) this.nonReactive.instance.setSearchPlaceholder(value ?? DefaultOptions.searchPlaceholder);
337
362
  },
338
- isHeaderVisible(v) {
339
- if (this.nonReactive.instance)
340
- this.nonReactive.instance.setHeaderVisible(v);
363
+ isHeaderVisible (v) {
364
+ if (this.nonReactive.instance) this.nonReactive.instance.setHeaderVisible(v);
341
365
  this.relayout();
342
366
  },
343
- isFooterVisible(v) {
344
- if (this.nonReactive.instance)
345
- this.nonReactive.instance.setFooterVisible(v);
367
+ isFooterVisible (v) {
368
+ if (this.nonReactive.instance) this.nonReactive.instance.setFooterVisible(v);
346
369
  this.relayout();
347
370
  },
348
371
  positionOptions: {
349
372
  deep: true,
350
- handler() {
373
+ handler () {
351
374
  this.relayout();
352
- },
375
+ }
353
376
  },
354
- ...(isVue3 ? {} : {
355
- $scopedSlots() {
377
+ ...isVue3 ? {} : {
378
+ $scopedSlots () {
356
379
  this._recreateList();
357
- },
358
- }),
359
- $slots() {
360
- this._recreateList();
380
+ }
361
381
  },
382
+ $slots () {
383
+ this._recreateList();
384
+ }
362
385
  },
363
- mounted() {
386
+ mounted () {
364
387
  this._createList();
365
388
  },
366
- [isVue3 ? 'unmounted' : 'destroyed']() {
389
+ [isVue3 ? 'unmounted' : 'destroyed'] () {
367
390
  this._destroyList();
368
391
  },
369
392
  methods: {
370
- _handleListEvents(event, data) {
371
- if ((event === 'select' && !this.multi) ||
372
- event === 'check' && !event.isCheckingGroup ||
373
- event === 'groupcheck') {
374
- this.$emit(isVue3 ? 'update:modelValue' : 'input', event === 'select'
375
- ? data.value
376
- : this.nonReactive.instance.getCheckedValues(false));
393
+ _handleListEvents (event, data) {
394
+ if (event === 'select' && !this.multi || event === 'check' && !event.isCheckingGroup || event === 'groupcheck') {
395
+ this.$emit(isVue3 ? 'update:modelValue' : 'input', event === 'select' ? data.value : this.nonReactive.instance.getCheckedValues(false));
377
396
  }
378
397
  if (event === 'hide') {
379
398
  this._clearAutoRelayout();
@@ -384,7 +403,7 @@ export default defineComponent({
384
403
  this.nonReactive.instance.el.focus();
385
404
  }
386
405
  }
387
- switch (event) {
406
+ switch(event){
388
407
  case 'itemfocus':
389
408
  case 'itemblur':
390
409
  case 'select':
@@ -399,27 +418,28 @@ export default defineComponent({
399
418
  case 'hide_subitems':
400
419
  case 'subitems:select':
401
420
  case 'subitems:blur':
402
- this.$emit(event, ...(data === undefined ? [] : [data]));
421
+ this.$emit(event, ...data === undefined ? [] : [
422
+ data
423
+ ]);
403
424
  break;
404
425
  }
405
426
  },
406
- _createList() {
427
+ _createList () {
407
428
  this._destroyList();
408
- if (!this.$root)
409
- return;
429
+ if (!this.$root) return;
410
430
  let list = new DropList(this.computedOptions);
411
431
  this.el = list.el;
412
432
  this.nonReactive.instance = list;
413
- this.nonReactive.sink.add(this.nonReactive.instance.el, 'keydown.vue', (evt) => {
433
+ this.nonReactive.sink.add(this.nonReactive.instance.el, 'keydown.vue', (evt)=>{
414
434
  this.$emit('keydown', evt);
415
435
  }, true);
416
- if (Array.isArray(this.items))
417
- list.addItems(this.items);
436
+ if (Array.isArray(this.items)) list.addItems(this.items);
418
437
  const modelValue = isVue3 ? this.modelValue : this.value;
419
438
  if (this.multi) {
420
- list.setCheckedValues(Array.isArray(modelValue) ? modelValue : modelValue == null ? [] : [modelValue]);
421
- }
422
- else {
439
+ list.setCheckedValues(Array.isArray(modelValue) ? modelValue : modelValue == null ? [] : [
440
+ modelValue
441
+ ]);
442
+ } else {
423
443
  list.setSingleSelectedItemByValue(modelValue === null ? undefined : modelValue);
424
444
  }
425
445
  const headerRenderer = createSlotBasedRenderFunc(this, 'header');
@@ -433,7 +453,7 @@ export default defineComponent({
433
453
  list.show();
434
454
  this._setupAutoRelayout();
435
455
  },
436
- _destroyList() {
456
+ _destroyList () {
437
457
  this._clearAutoRelayout();
438
458
  if (this.nonReactive.instance) {
439
459
  this.nonReactive.instance.destroy();
@@ -442,59 +462,52 @@ export default defineComponent({
442
462
  this.el = undefined;
443
463
  this.nonReactive.sink.remove(null, '.vue');
444
464
  },
445
- _recreateList() {
465
+ _recreateList () {
446
466
  this._destroyList();
447
467
  this._createList();
448
468
  },
449
- _concatClassesObject(classes) {
469
+ _concatClassesObject (classes) {
450
470
  if (Array.isArray(classes)) {
451
471
  return classes.join(' ');
452
- }
453
- else if (classes && typeof classes === 'object') {
472
+ } else if (classes && typeof classes === 'object') {
454
473
  let arr = [];
455
- for (let [key, value] of Object.entries(classes)) {
456
- if (value)
457
- arr.push(key);
474
+ for (let [key, value] of Object.entries(classes)){
475
+ if (value) arr.push(key);
458
476
  }
459
477
  return arr.join(' ');
460
478
  }
461
479
  return classes || '';
462
480
  },
463
- _clearAutoRelayout() {
481
+ _clearAutoRelayout () {
464
482
  this.nonReactive.sink.remove(null, '.trackposition');
465
483
  },
466
- _setupAutoRelayout() {
484
+ _setupAutoRelayout () {
467
485
  this._clearAutoRelayout();
468
- if (!this.nonReactive.instance)
469
- return;
470
- this.nonReactive.sink.add(window, 'resize.trackposition', () => this.relayout());
486
+ if (!this.nonReactive.instance) return;
487
+ this.nonReactive.sink.add(window, 'resize.trackposition', ()=>this.relayout());
471
488
  let parent = this.nonReactive.instance.el.parentNode;
472
- while (parent) {
473
- if (parent.scrollHeight > parent.offsetHeight ||
474
- parent.scrollWidth > parent.offsetWidth) {
489
+ while(parent){
490
+ if (parent.scrollHeight > parent.offsetHeight || parent.scrollWidth > parent.offsetWidth) {
475
491
  if (parent === document.documentElement) {
476
492
  parent = window;
477
493
  }
478
- this.nonReactive.sink.add(parent, 'scroll.trackposition', () => this.relayout());
494
+ this.nonReactive.sink.add(parent, 'scroll.trackposition', ()=>this.relayout());
479
495
  }
480
496
  parent = parent.parentNode;
481
497
  }
482
498
  },
483
- relayout() {
484
- if (this.nonReactive.instance)
485
- this.nonReactive.instance.relayout();
499
+ relayout () {
500
+ if (this.nonReactive.instance) this.nonReactive.instance.relayout();
486
501
  },
487
- getHeaderElement() {
488
- if (this.nonReactive.instance)
489
- return this.nonReactive.instance.getHeaderElement();
502
+ getHeaderElement () {
503
+ if (this.nonReactive.instance) return this.nonReactive.instance.getHeaderElement();
490
504
  },
491
- getFooterElement() {
492
- if (this.nonReactive.instance)
493
- return this.nonReactive.instance.getFooterElement();
505
+ getFooterElement () {
506
+ if (this.nonReactive.instance) return this.nonReactive.instance.getFooterElement();
494
507
  },
495
- elContains(other, considerSublists = true) {
508
+ elContains (other, considerSublists = true) {
496
509
  return !!this.listRef?.elContains(other, considerSublists);
497
- },
498
- },
510
+ }
511
+ }
499
512
  });
500
513
  </script>