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