umy-ui-table 1.2.0

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