@danielgindi/selectbox 2.0.57 → 2.0.58

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