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