@94ai/nf-popup-lazy-select 3.2.80 → 3.2.82

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.
@@ -0,0 +1,880 @@
1
+ <template>
2
+ <div
3
+ class="el-select"
4
+ :class="[selectSize ? 'el-select--' + selectSize : '']">
5
+ <div
6
+ class="el-select__tags"
7
+ v-if="multiple"
8
+ ref="tags"
9
+ :style="{ 'max-width': inputWidth - 32 + 'px', width: '100%' }">
10
+ <span v-if="collapseTags && selected.length">
11
+ <el-tag
12
+ :closable="!selectDisabled"
13
+ :size="collapseTagSize"
14
+ :hit="selected[0].hitState"
15
+ type="info"
16
+ @close="deleteTag($event, selected[0])"
17
+ disable-transitions>
18
+ <span class="el-select__tags-text">{{ selected[0].currentLabel }}</span>
19
+ </el-tag>
20
+ <el-tag
21
+ v-if="selected.length > 1"
22
+ :closable="false"
23
+ :size="collapseTagSize"
24
+ type="info"
25
+ disable-transitions>
26
+ <span class="el-select__tags-text">+ {{ selected.length - 1 }}</span>
27
+ </el-tag>
28
+ </span>
29
+ <transition-group @after-leave="resetInputHeight" v-if="!collapseTags">
30
+ <el-tag
31
+ v-for="item in selected"
32
+ :key="getValueKey(item)"
33
+ :closable="!selectDisabled"
34
+ :size="collapseTagSize"
35
+ :hit="item.hitState"
36
+ type="info"
37
+ @close="deleteTag($event, item)"
38
+ disable-transitions>
39
+ <span class="el-select__tags-text">{{ item.currentLabel }}</span>
40
+ </el-tag>
41
+ </transition-group>
42
+
43
+ <input
44
+ type="text"
45
+ class="el-select__input"
46
+ :class="[selectSize ? `is-${ selectSize }` : '']"
47
+ :disabled="selectDisabled"
48
+ :autocomplete="autoComplete || autocomplete"
49
+ @focus="handleFocus"
50
+ @blur="softFocus = false"
51
+ @keyup="managePlaceholder"
52
+ @keydown="resetInputState"
53
+ @keydown.down.prevent="navigateOptions('next')"
54
+ @keydown.up.prevent="navigateOptions('prev')"
55
+ @keydown.enter.prevent="selectOption"
56
+ @keydown.delete="deletePrevTag"
57
+ @compositionstart="handleComposition"
58
+ @compositionupdate="handleComposition"
59
+ @compositionend="handleComposition"
60
+ v-model="query"
61
+ @input="debouncedQueryChange"
62
+ v-if="filterable"
63
+ :style="{ 'flex-grow': '1', width: inputLength / (inputWidth - 32) + '%', 'max-width': inputWidth - 42 + 'px' }"
64
+ ref="input">
65
+ </div>
66
+ <el-input
67
+ ref="reference"
68
+ v-model="selectedLabel"
69
+ type="text"
70
+ :placeholder="currentPlaceholder"
71
+ :name="name"
72
+ :id="id"
73
+ :autocomplete="autoComplete || autocomplete"
74
+ :size="selectSize"
75
+ :disabled="selectDisabled"
76
+ :readonly="readonly"
77
+ :validate-event="false"
78
+ :class="{ 'is-focus': visible }"
79
+ :tabindex="(multiple && filterable) ? '-1' : null"
80
+ @focus="handleFocus"
81
+ @blur="handleBlur"
82
+ @keyup.native="debouncedOnInputChange"
83
+ @keydown.native.down.stop.prevent="navigateOptions('next')"
84
+ @keydown.native.up.stop.prevent="navigateOptions('prev')"
85
+ @keydown.native.enter.prevent="selectOption"
86
+ @paste.native="debouncedOnInputChange"
87
+ @mouseenter.native="inputHovering = true"
88
+ @mouseleave.native="inputHovering = false">
89
+ <template slot="prefix" v-if="$slots.prefix">
90
+ <slot name="prefix"></slot>
91
+ </template>
92
+ <template slot="suffix">
93
+ <i v-if="showClose" class="el-select__caret el-input__icon el-icon-circle-close" @click="handleClearClick"></i>
94
+ <i v-if="showClear" class="el-select__caret el-input__icon el-icon-circle-close" @click="handleClearKeywordClick"></i>
95
+ </template>
96
+ </el-input>
97
+ <transition
98
+ name="el-zoom-in-top"
99
+ @before-enter="handleMenuEnter"
100
+ @after-leave="doDestroy">
101
+ <select-menu
102
+ ref="popper"
103
+ :append-to-body="popperAppendToBody"
104
+ v-show="emptyText !== false">
105
+ <el-scrollbar
106
+ tag="ul"
107
+ wrap-class="el-select-dropdown__wrap"
108
+ view-class="el-select-dropdown__list"
109
+ ref="scrollbar"
110
+ :class="{ 'is-empty': !allowCreate && query && filteredOptionsCount === 0 }"
111
+ v-show="options.length > 0 && !loading">
112
+ <el-option
113
+ :value="query"
114
+ created
115
+ v-if="showNewOption">
116
+ </el-option>
117
+ <slot></slot>
118
+ </el-scrollbar>
119
+ <template v-if="emptyText && (!allowCreate || loading || (allowCreate && options.length === 0 ))">
120
+ <slot name="empty" v-if="$slots.empty"></slot>
121
+ <p class="el-select-dropdown__empty" v-else>
122
+ {{ emptyText }}
123
+ </p>
124
+ </template>
125
+ </select-menu>
126
+ </transition>
127
+ </div>
128
+ </template>
129
+
130
+ <script type="text/babel">
131
+ import Emitter from 'element-ui/src/mixins/emitter';
132
+ import Focus from 'element-ui/src/mixins/focus';
133
+ import Locale from 'element-ui/src/mixins/locale';
134
+ import debounce from 'throttle-debounce/debounce';
135
+ import { addResizeListener, removeResizeListener } from 'element-ui/src/utils/resize-event';
136
+ import { t } from 'element-ui/src/locale';
137
+ import scrollIntoView from 'element-ui/src/utils/scroll-into-view';
138
+ import { getValueByPath, valueEquals, isIE, isEdge } from 'element-ui/src/utils/util';
139
+ import { isKorean } from 'element-ui/src/utils/shared';
140
+ import NavigationMixin from 'element-ui/packages/select/src/navigation-mixin';
141
+ import SelectMenu from 'element-ui/packages/select/src/select-dropdown.vue';
142
+ import { closest } from '@94ai/common-utils'
143
+
144
+ export default {
145
+ mixins: [Emitter, Locale, Focus('reference'), NavigationMixin],
146
+
147
+ name: 'ElSelect',
148
+
149
+ componentName: 'ElSelect',
150
+
151
+ inject: {
152
+ elForm: {
153
+ default: ''
154
+ },
155
+
156
+ elFormItem: {
157
+ default: ''
158
+ }
159
+ },
160
+
161
+ provide() {
162
+ return {
163
+ 'select': this
164
+ };
165
+ },
166
+
167
+ computed: {
168
+ _elFormItemSize() {
169
+ return (this.elFormItem || {}).elFormItemSize;
170
+ },
171
+
172
+ readonly() {
173
+ return !this.filterable || this.multiple || (!isIE() && !isEdge() && !this.visible);
174
+ },
175
+
176
+ showClose() {
177
+ let hasValue = this.multiple
178
+ ? Array.isArray(this.value) && this.value.length > 0
179
+ : this.value !== undefined && this.value !== null && this.value !== '';
180
+ let criteria = this.clearable &&
181
+ !this.selectDisabled &&
182
+ this.inputHovering &&
183
+ hasValue;
184
+ return criteria;
185
+ },
186
+
187
+ showClear() {
188
+ const nfPopupLazySelect = closest(this, 'nf-popup-lazy-select')
189
+ const keywords = this.selectedLabel || this.query
190
+ if (nfPopupLazySelect && !nfPopupLazySelect.assignmentOnSelect && keywords) {
191
+ return true
192
+ }
193
+ return false
194
+ },
195
+
196
+ debounce() {
197
+ return this.remote ? 300 : 0;
198
+ },
199
+
200
+ emptyText() {
201
+ if (this.loading) {
202
+ return this.loadingText || this.t('el.select.loading');
203
+ } else {
204
+ if (this.remote && this.query === '' && this.options.length === 0) return false;
205
+ if (this.filterable && this.query && this.options.length > 0 && this.filteredOptionsCount === 0) {
206
+ return this.noMatchText || this.t('el.select.noMatch');
207
+ }
208
+ if (this.options.length === 0) {
209
+ return this.noDataText || this.t('el.select.noData');
210
+ }
211
+ }
212
+ return null;
213
+ },
214
+
215
+ showNewOption() {
216
+ let hasExistingOption = this.options.filter(option => !option.created)
217
+ .some(option => option.currentLabel === this.query);
218
+ return this.filterable && this.allowCreate && this.query !== '' && !hasExistingOption;
219
+ },
220
+
221
+ selectSize() {
222
+ return this.size || this._elFormItemSize || (this.$ELEMENT || {}).size;
223
+ },
224
+
225
+ selectDisabled() {
226
+ return this.disabled || (this.elForm || {}).disabled;
227
+ },
228
+
229
+ collapseTagSize() {
230
+ return ['small', 'mini'].indexOf(this.selectSize) > -1
231
+ ? 'mini'
232
+ : 'small';
233
+ }
234
+ },
235
+
236
+ components: {
237
+ SelectMenu,
238
+ },
239
+
240
+ props: {
241
+ name: String,
242
+ id: String,
243
+ value: {
244
+ required: true
245
+ },
246
+ autocomplete: {
247
+ type: String,
248
+ default: 'off'
249
+ },
250
+ /** @Deprecated in next major version */
251
+ autoComplete: {
252
+ type: String,
253
+ validator(val) {
254
+ process.env.NODE_ENV !== 'production' &&
255
+ console.warn('[Element Warn][Select]\'auto-complete\' property will be deprecated in next major version. please use \'autocomplete\' instead.');
256
+ return true;
257
+ }
258
+ },
259
+ automaticDropdown: Boolean,
260
+ size: String,
261
+ disabled: Boolean,
262
+ clearable: Boolean,
263
+ filterable: Boolean,
264
+ allowCreate: Boolean,
265
+ loading: Boolean,
266
+ popperClass: String,
267
+ remote: Boolean,
268
+ loadingText: String,
269
+ noMatchText: String,
270
+ noDataText: String,
271
+ remoteMethod: Function,
272
+ filterMethod: Function,
273
+ multiple: Boolean,
274
+ multipleLimit: {
275
+ type: Number,
276
+ default: 0
277
+ },
278
+ placeholder: {
279
+ type: String,
280
+ default() {
281
+ return t('el.select.placeholder');
282
+ }
283
+ },
284
+ defaultFirstOption: Boolean,
285
+ reserveKeyword: Boolean,
286
+ valueKey: {
287
+ type: String,
288
+ default: 'value'
289
+ },
290
+ collapseTags: Boolean,
291
+ popperAppendToBody: {
292
+ type: Boolean,
293
+ default: true
294
+ }
295
+ },
296
+
297
+ data() {
298
+ return {
299
+ options: [],
300
+ cachedOptions: [],
301
+ createdLabel: null,
302
+ createdSelected: false,
303
+ selected: this.multiple ? [] : {},
304
+ inputLength: 20,
305
+ inputWidth: 0,
306
+ initialInputHeight: 0,
307
+ cachedPlaceHolder: '',
308
+ optionsCount: 0,
309
+ filteredOptionsCount: 0,
310
+ visible: false,
311
+ softFocus: false,
312
+ selectedLabel: '',
313
+ hoverIndex: -1,
314
+ query: '',
315
+ previousQuery: null,
316
+ inputHovering: false,
317
+ currentPlaceholder: '',
318
+ isOnComposition: false,
319
+ isSilentBlur: false
320
+ };
321
+ },
322
+
323
+ watch: {
324
+ selectDisabled() {
325
+ this.$nextTick(() => {
326
+ this.resetInputHeight();
327
+ });
328
+ },
329
+
330
+ placeholder(val) {
331
+ this.cachedPlaceHolder = this.currentPlaceholder = val;
332
+ },
333
+
334
+ value(val, oldVal) {
335
+ if (this.multiple) {
336
+ this.resetInputHeight();
337
+ if ((val && val.length > 0) || (this.$refs.input && this.query !== '')) {
338
+ this.currentPlaceholder = '';
339
+ } else {
340
+ this.currentPlaceholder = this.cachedPlaceHolder;
341
+ }
342
+ if (this.filterable && !this.reserveKeyword) {
343
+ this.query = '';
344
+ this.handleQueryChange(this.query);
345
+ }
346
+ }
347
+ this.setSelected();
348
+ if (this.filterable && !this.multiple) {
349
+ this.inputLength = 20;
350
+ }
351
+ if (!valueEquals(val, oldVal)) {
352
+ this.dispatch('ElFormItem', 'el.form.change', val);
353
+ }
354
+ },
355
+
356
+ visible(val) {
357
+ if (!val) {
358
+ this.broadcast('ElSelectDropdown', 'destroyPopper');
359
+ if (this.$refs.input) {
360
+ this.$refs.input.blur();
361
+ }
362
+ this.query = '';
363
+ this.previousQuery = null;
364
+ this.selectedLabel = '';
365
+ this.inputLength = 20;
366
+ this.resetHoverIndex();
367
+ this.$nextTick(() => {
368
+ if (this.$refs.input &&
369
+ this.$refs.input.value === '' &&
370
+ this.selected.length === 0) {
371
+ this.currentPlaceholder = this.cachedPlaceHolder;
372
+ }
373
+ });
374
+ if (!this.multiple) {
375
+ if (this.selected) {
376
+ if (this.filterable && this.allowCreate &&
377
+ this.createdSelected && this.createdLabel) {
378
+ this.selectedLabel = this.createdLabel;
379
+ } else {
380
+ this.selectedLabel = this.selected.currentLabel;
381
+ }
382
+ if (this.filterable) this.query = this.selectedLabel;
383
+ }
384
+
385
+ if (this.filterable) {
386
+ this.currentPlaceholder = this.cachedPlaceHolder;
387
+ }
388
+ }
389
+ } else {
390
+ this.broadcast('ElSelectDropdown', 'updatePopper');
391
+ if (this.filterable) {
392
+ this.query = this.remote ? '' : this.selectedLabel;
393
+ this.handleQueryChange(this.query);
394
+ if (this.multiple) {
395
+ this.$refs.input.focus();
396
+ } else {
397
+ if (!this.remote) {
398
+ this.broadcast('ElOption', 'queryChange', '');
399
+ this.broadcast('ElOptionGroup', 'queryChange');
400
+ }
401
+
402
+ if (this.selectedLabel) {
403
+ this.currentPlaceholder = this.selectedLabel;
404
+ this.selectedLabel = '';
405
+ }
406
+ }
407
+ }
408
+ }
409
+ this.$emit('visible-change', val);
410
+ },
411
+
412
+ options() {
413
+ if (this.$isServer) return;
414
+ this.$nextTick(() => {
415
+ this.broadcast('ElSelectDropdown', 'updatePopper');
416
+ });
417
+ if (this.multiple) {
418
+ this.resetInputHeight();
419
+ }
420
+ let inputs = this.$el.querySelectorAll('input');
421
+ if ([].indexOf.call(inputs, document.activeElement) === -1) {
422
+ if (!this.multiple) {
423
+ const nfPopupLazySelect = closest(this, 'nf-popup-lazy-select')
424
+ if (nfPopupLazySelect) {
425
+ return
426
+ }
427
+ }
428
+ this.setSelected();
429
+ }
430
+ if (this.defaultFirstOption && (this.filterable || this.remote) && this.filteredOptionsCount) {
431
+ this.checkDefaultFirstOption();
432
+ }
433
+ }
434
+ },
435
+
436
+ methods: {
437
+ handleComposition(event) {
438
+ const text = event.target.value;
439
+ if (event.type === 'compositionend') {
440
+ this.isOnComposition = false;
441
+ this.$nextTick(_ => this.handleQueryChange(text));
442
+ } else {
443
+ const lastCharacter = text[text.length - 1] || '';
444
+ this.isOnComposition = !isKorean(lastCharacter);
445
+ }
446
+ },
447
+ handleQueryChange(val) {
448
+ if (this.previousQuery === val || this.isOnComposition) return;
449
+ if (
450
+ this.previousQuery === null &&
451
+ (typeof this.filterMethod === 'function' || typeof this.remoteMethod === 'function')
452
+ ) {
453
+ this.previousQuery = val;
454
+ return;
455
+ }
456
+ this.previousQuery = val;
457
+ this.$nextTick(() => {
458
+ if (this.visible) this.broadcast('ElSelectDropdown', 'updatePopper');
459
+ });
460
+ this.hoverIndex = -1;
461
+ if (this.multiple && this.filterable) {
462
+ this.$nextTick(() => {
463
+ const length = this.$refs.input.value.length * 15 + 20;
464
+ this.inputLength = this.collapseTags ? Math.min(50, length) : length;
465
+ this.managePlaceholder();
466
+ this.resetInputHeight();
467
+ });
468
+ }
469
+ if (this.remote && typeof this.remoteMethod === 'function') {
470
+ this.hoverIndex = -1;
471
+ this.remoteMethod(val);
472
+ } else if (typeof this.filterMethod === 'function') {
473
+ this.filterMethod(val);
474
+ this.broadcast('ElOptionGroup', 'queryChange');
475
+ } else {
476
+ this.filteredOptionsCount = this.optionsCount;
477
+ this.broadcast('ElOption', 'queryChange', val);
478
+ this.broadcast('ElOptionGroup', 'queryChange');
479
+ }
480
+ if (this.defaultFirstOption && (this.filterable || this.remote) && this.filteredOptionsCount) {
481
+ this.checkDefaultFirstOption();
482
+ }
483
+ },
484
+
485
+ scrollToOption(option) {
486
+ const target = Array.isArray(option) && option[0] ? option[0].$el : option.$el;
487
+ if (this.$refs.popper && target) {
488
+ const menu = this.$refs.popper.$el.querySelector('.el-select-dropdown__wrap');
489
+ scrollIntoView(menu, target);
490
+ }
491
+ this.$refs.scrollbar && this.$refs.scrollbar.handleScroll();
492
+ },
493
+
494
+ handleMenuEnter() {
495
+ this.$nextTick(() => this.scrollToOption(this.selected));
496
+ },
497
+
498
+ emitChange(val) {
499
+ if (!valueEquals(this.value, val)) {
500
+ this.$emit('change', val);
501
+ }
502
+ },
503
+
504
+ getOption(value) {
505
+ let option;
506
+ const isObject = Object.prototype.toString.call(value).toLowerCase() === '[object object]';
507
+ const isNull = Object.prototype.toString.call(value).toLowerCase() === '[object null]';
508
+ const isUndefined = Object.prototype.toString.call(value).toLowerCase() === '[object undefined]';
509
+
510
+ for (let i = this.cachedOptions.length - 1; i >= 0; i--) {
511
+ const cachedOption = this.cachedOptions[i];
512
+ const isEqual = isObject
513
+ ? getValueByPath(cachedOption.value, this.valueKey) === getValueByPath(value, this.valueKey)
514
+ : cachedOption.value === value;
515
+ if (isEqual) {
516
+ option = cachedOption;
517
+ break;
518
+ }
519
+ }
520
+ if (option) return option;
521
+ const label = (!isObject && !isNull && !isUndefined)
522
+ ? value : '';
523
+ let newOption = {
524
+ value: value,
525
+ currentLabel: label
526
+ };
527
+ if (this.multiple) {
528
+ newOption.hitState = false;
529
+ }
530
+ return newOption;
531
+ },
532
+
533
+ setSelected() {
534
+ if (!this.multiple) {
535
+ let option = this.getOption(this.value);
536
+ if (option.created) {
537
+ this.createdLabel = option.currentLabel;
538
+ this.createdSelected = true;
539
+ } else {
540
+ this.createdSelected = false;
541
+ }
542
+ this.selectedLabel = option.currentLabel;
543
+ this.selected = option;
544
+ if (this.filterable) this.query = this.selectedLabel;
545
+ return;
546
+ }
547
+ let result = [];
548
+ if (Array.isArray(this.value)) {
549
+ this.value.forEach(value => {
550
+ result.push(this.getOption(value));
551
+ });
552
+ }
553
+ this.selected = result;
554
+ this.$nextTick(() => {
555
+ this.resetInputHeight();
556
+ });
557
+ },
558
+
559
+ handleFocus(event) {
560
+ if (!this.softFocus) {
561
+ this.$emit('focus', event);
562
+ } else {
563
+ this.softFocus = false;
564
+ }
565
+ },
566
+
567
+ blur() {
568
+ this.$refs.reference.blur();
569
+ },
570
+
571
+ handleBlur(event) {
572
+ setTimeout(() => {
573
+ if (this.isSilentBlur) {
574
+ this.isSilentBlur = false;
575
+ } else {
576
+ this.$emit('blur', event);
577
+ }
578
+ }, 50);
579
+ this.softFocus = false;
580
+ },
581
+
582
+ handleClearClick(event) {
583
+ this.deleteSelected(event);
584
+ this.currentPlaceholder = this.cachedPlaceHolder = this.placeholder
585
+ },
586
+
587
+ handleClearKeywordClick(event) {
588
+ event.stopPropagation();
589
+ this.selectedLabel = ''
590
+ this.query = ''
591
+ this.previousQuery = ''
592
+ if (typeof this.filterMethod === 'function') {
593
+ this.filterMethod('');
594
+ this.broadcast('ElOptionGroup', 'queryChange');
595
+ }
596
+ },
597
+
598
+ doDestroy() {
599
+ this.$refs.popper && this.$refs.popper.doDestroy();
600
+ },
601
+
602
+ toggleLastOptionHitState(hit) {
603
+ if (!Array.isArray(this.selected)) return;
604
+ const option = this.selected[this.selected.length - 1];
605
+ if (!option) return;
606
+
607
+ if (hit === true || hit === false) {
608
+ option.hitState = hit;
609
+ return hit;
610
+ }
611
+
612
+ option.hitState = !option.hitState;
613
+ return option.hitState;
614
+ },
615
+
616
+ deletePrevTag(e) {
617
+ if (e.target.value.length <= 0 && !this.toggleLastOptionHitState()) {
618
+ const value = this.value.slice();
619
+ value.pop();
620
+ this.$emit('input', value);
621
+ this.emitChange(value);
622
+ }
623
+ },
624
+
625
+ managePlaceholder() {
626
+ if (this.currentPlaceholder !== '') {
627
+ this.currentPlaceholder = this.$refs.input.value ? '' : this.cachedPlaceHolder;
628
+ }
629
+ },
630
+
631
+ resetInputState(e) {
632
+ if (e.keyCode !== 8) this.toggleLastOptionHitState(false);
633
+ this.inputLength = this.$refs.input.value.length * 15 + 20;
634
+ this.resetInputHeight();
635
+ },
636
+
637
+ resetInputHeight() {
638
+ if (this.collapseTags && !this.filterable) return;
639
+ this.$nextTick(() => {
640
+ if (!this.$refs.reference) return;
641
+ let inputChildNodes = this.$refs.reference.$el.childNodes;
642
+ let input = [].filter.call(inputChildNodes, item => item.tagName === 'INPUT')[0];
643
+ const tags = this.$refs.tags;
644
+ const sizeInMap = this.initialInputHeight || 40;
645
+ input.style.height = this.selected.length === 0
646
+ ? sizeInMap + 'px'
647
+ : Math.max(
648
+ tags ? (tags.clientHeight + (tags.clientHeight > sizeInMap ? 6 : 0)) : 0,
649
+ sizeInMap
650
+ ) + 'px';
651
+ if (this.visible && this.emptyText !== false) {
652
+ this.broadcast('ElSelectDropdown', 'updatePopper');
653
+ }
654
+ });
655
+ },
656
+
657
+ resetHoverIndex() {
658
+ setTimeout(() => {
659
+ if (!this.multiple) {
660
+ this.hoverIndex = this.options.indexOf(this.selected);
661
+ } else {
662
+ if (this.selected.length > 0) {
663
+ this.hoverIndex = Math.min.apply(null, this.selected.map(item => this.options.indexOf(item)));
664
+ } else {
665
+ this.hoverIndex = -1;
666
+ }
667
+ }
668
+ }, 300);
669
+ },
670
+
671
+ handleOptionSelect(option, byClick) {
672
+ const nfPopupLazySelect = closest(this, 'nf-popup-lazy-select')
673
+ if (this.multiple) {
674
+ const value = (this.value || []).slice();
675
+ const optionIndex = this.getValueIndex(value, option.value);
676
+ if (optionIndex > -1) {
677
+ value.splice(optionIndex, 1);
678
+ } else if (this.multipleLimit <= 0 || value.length < this.multipleLimit) {
679
+ value.push(option.value);
680
+ }
681
+ this.$emit('input', value);
682
+ this.emitChange(value);
683
+ if (option.created) {
684
+ this.query = '';
685
+ this.handleQueryChange('');
686
+ this.inputLength = 20;
687
+ }
688
+ if (this.filterable) this.$refs.input.focus();
689
+ } else {
690
+ if (nfPopupLazySelect?.assignmentOnSelect) {
691
+ this.$emit('input', option.value);
692
+ this.emitChange(option.value);
693
+ }
694
+ this.$emit('select-item', option.value);
695
+ }
696
+ this.isSilentBlur = byClick;
697
+ this.setSoftFocus();
698
+ if (this.visible) return;
699
+ this.$nextTick(() => {
700
+ this.scrollToOption(option);
701
+ });
702
+ },
703
+
704
+ setSoftFocus() {
705
+ this.softFocus = true;
706
+ const input = this.$refs.input || this.$refs.reference;
707
+ if (input) {
708
+ input.focus();
709
+ }
710
+ },
711
+
712
+ getValueIndex(arr = [], value) {
713
+ const isObject = Object.prototype.toString.call(value).toLowerCase() === '[object object]';
714
+ if (!isObject) {
715
+ return arr.indexOf(value);
716
+ } else {
717
+ const valueKey = this.valueKey;
718
+ let index = -1;
719
+ arr.some((item, i) => {
720
+ if (getValueByPath(item, valueKey) === getValueByPath(value, valueKey)) {
721
+ index = i;
722
+ return true;
723
+ }
724
+ return false;
725
+ });
726
+ return index;
727
+ }
728
+ },
729
+
730
+ toggleMenu() {
731
+ if (!this.selectDisabled) {
732
+ this.visible = !this.visible;
733
+ if (this.visible) {
734
+ (this.$refs.input || this.$refs.reference)?.focus();
735
+ }
736
+ }
737
+ },
738
+
739
+ selectOption() {
740
+ if (this.options[this.hoverIndex]) {
741
+ this.handleOptionSelect(this.options[this.hoverIndex]);
742
+ }
743
+ },
744
+
745
+ deleteSelected(event) {
746
+ event.stopPropagation();
747
+ const value = this.multiple ? [] : '';
748
+ this.$emit('input', value);
749
+ this.emitChange(value);
750
+ this.$emit('clear');
751
+ },
752
+
753
+ deleteTag(event, tag) {
754
+ let index = this.selected.indexOf(tag);
755
+ if (index > -1 && !this.selectDisabled) {
756
+ const value = this.value.slice();
757
+ value.splice(index, 1);
758
+ this.$emit('input', value);
759
+ this.emitChange(value);
760
+ this.$emit('remove-tag', tag.value);
761
+ }
762
+ event.stopPropagation();
763
+ },
764
+
765
+ onInputChange() {
766
+ if (this.filterable && this.query !== this.selectedLabel) {
767
+ this.query = this.selectedLabel;
768
+ this.handleQueryChange(this.query);
769
+ }
770
+ },
771
+
772
+ onOptionDestroy(index) {
773
+ if (index > -1) {
774
+ this.optionsCount--;
775
+ this.filteredOptionsCount--;
776
+ this.options.splice(index, 1);
777
+ }
778
+ },
779
+
780
+ resetInputWidth() {
781
+ this.inputWidth = this.$refs.reference.$el.getBoundingClientRect().width;
782
+ },
783
+
784
+ handleResize() {
785
+ this.resetInputWidth();
786
+ if (this.multiple) this.resetInputHeight();
787
+ },
788
+
789
+ checkDefaultFirstOption() {
790
+ this.hoverIndex = -1;
791
+ // highlight the created option
792
+ let hasCreated = false;
793
+ for (let i = this.options.length - 1; i >= 0; i--) {
794
+ if (this.options[i].created) {
795
+ hasCreated = true;
796
+ this.hoverIndex = i;
797
+ break;
798
+ }
799
+ }
800
+ if (hasCreated) return;
801
+ for (let i = 0; i !== this.options.length; ++i) {
802
+ const option = this.options[i];
803
+ if (this.query) {
804
+ // highlight first options that passes the filter
805
+ if (!option.disabled && !option.groupDisabled && option.visible) {
806
+ this.hoverIndex = i;
807
+ break;
808
+ }
809
+ } else {
810
+ // highlight currently selected option
811
+ if (option.itemSelected) {
812
+ this.hoverIndex = i;
813
+ break;
814
+ }
815
+ }
816
+ }
817
+ },
818
+
819
+ getValueKey(item) {
820
+ if (Object.prototype.toString.call(item.value).toLowerCase() !== '[object object]') {
821
+ return item.value;
822
+ } else {
823
+ return getValueByPath(item.value, this.valueKey);
824
+ }
825
+ }
826
+ },
827
+
828
+ created() {
829
+ this.cachedPlaceHolder = this.currentPlaceholder = this.placeholder;
830
+ if (this.multiple && !Array.isArray(this.value)) {
831
+ this.$emit('input', []);
832
+ }
833
+ if (!this.multiple && Array.isArray(this.value)) {
834
+ this.$emit('input', '');
835
+ }
836
+
837
+ this.debouncedOnInputChange = debounce(this.debounce, () => {
838
+ this.onInputChange();
839
+ });
840
+
841
+ this.debouncedQueryChange = debounce(this.debounce, (e) => {
842
+ this.handleQueryChange(e.target.value);
843
+ });
844
+
845
+ this.$on('handleOptionClick', this.handleOptionSelect);
846
+ this.$on('setSelected', this.setSelected);
847
+ },
848
+
849
+ mounted() {
850
+ if (this.multiple && Array.isArray(this.value) && this.value.length > 0) {
851
+ this.currentPlaceholder = '';
852
+ }
853
+ addResizeListener(this.$el, this.handleResize);
854
+
855
+ const reference = this.$refs.reference;
856
+ if (reference && reference.$el) {
857
+ const sizeMap = {
858
+ medium: 36,
859
+ small: 32,
860
+ mini: 28
861
+ };
862
+ const input = reference.$el.querySelector('input');
863
+ this.initialInputHeight = input.getBoundingClientRect().height || sizeMap[this.selectSize];
864
+ }
865
+ if (this.remote && this.multiple) {
866
+ this.resetInputHeight();
867
+ }
868
+ this.$nextTick(() => {
869
+ if (reference && reference.$el) {
870
+ this.inputWidth = reference.$el.getBoundingClientRect().width;
871
+ }
872
+ });
873
+ this.setSelected();
874
+ },
875
+
876
+ beforeDestroy() {
877
+ if (this.$el && this.handleResize) removeResizeListener(this.$el, this.handleResize);
878
+ }
879
+ };
880
+ </script>