kui-vue 3.4.8 → 3.4.9

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.
@@ -1,21 +1,21 @@
1
- import Option from './option'
1
+ import Option from "./option";
2
2
  import Icon from "../icon";
3
- import Empty from '../empty';
4
- import { hasProp, getChild, isNotEmpty } from '../_tool/utils'
3
+ import Empty from "../empty";
4
+ import { hasProp, getChild, isNotEmpty } from "../_tool/utils";
5
5
 
6
- import Drop from '../base/drop'
7
- import { t } from '../locale';
8
- import { Sync, Close, CloseCircle, ChevronDown } from 'kui-icons'
6
+ import Drop from "../base/drop";
7
+ import { t } from "../locale";
8
+ import { Sync, Close, CloseCircle, ChevronDown } from "kui-icons";
9
9
 
10
10
  export default {
11
11
  name: "Select",
12
12
  props: {
13
13
  placeholder: String,
14
14
  size: {
15
- default: 'default',
15
+ default: "default",
16
16
  validator(value) {
17
17
  return ["small", "large", "default"].indexOf(value) >= 0;
18
- }
18
+ },
19
19
  },
20
20
  transfer: { type: Boolean, default: true },
21
21
  width: Number,
@@ -36,106 +36,76 @@ export default {
36
36
  },
37
37
  provide() {
38
38
  return {
39
- Select: this
40
- }
39
+ Select: this,
40
+ };
41
41
  },
42
42
  data() {
43
43
  return {
44
44
  label: "",
45
45
  opened: false,
46
- currentValue: this.value || '',
46
+ currentValue: this.value || "",
47
47
  showSearch: false,
48
- queryKey: '',
48
+ queryKey: "",
49
49
  selectWidth: this.width,
50
- isFocus: false
50
+ isFocus: false,
51
51
  };
52
52
  },
53
53
  watch: {
54
54
  value(value) {
55
55
  if (isNotEmpty(value)) {
56
- this.currentValue = value
56
+ this.currentValue = value;
57
57
  } else {
58
- this.currentValue = this.multiple ? [] : ''
58
+ this.currentValue = this.multiple ? [] : "";
59
59
  }
60
60
  },
61
- currentValue(n, o) {
62
- this.setLabel()
63
- }
64
61
  },
65
62
  methods: {
66
63
  hideDrop() {
67
64
  if (this.showSearch) {
68
- this.queryKey = ''
69
- this.$refs.search.value = ''
70
- this.$refs.search.style.width = ''
65
+ this.queryKey = "";
66
+ this.$refs.search.value = "";
67
+ this.$refs.search.style.width = "";
71
68
  }
72
- this.showSearch = false
69
+ this.showSearch = false;
73
70
  },
74
71
  getLabel(childs, labelValue) {
75
- let Label = '';
76
- childs.forEach(c => {
77
- let { value, label } = c.componentOptions.propsData
72
+ let Label = null;
73
+ childs.forEach((c) => {
74
+ let { value, label } = c.componentOptions.propsData;
78
75
  if (labelValue === value) {
79
- Label = label || (c.componentOptions.children[0].text || '').trim()
76
+ Label = label || (c.componentOptions.children[0].text || "").trim();
80
77
  return;
81
78
  }
82
- })
83
- return Label || labelValue;
84
- },
85
- setLabel() {
86
- let { currentValue, multiple, label } = this
87
-
88
- currentValue = isNotEmpty(currentValue) ? currentValue : (multiple ? [] : '')
89
- let currentLabel = isNotEmpty(label) ? label : (multiple ? [] : '')
90
-
91
- let childs = this.getOptions()
92
- if (multiple) {
93
- if (currentValue.length) {
94
- let labels = []
95
- currentValue.forEach((value) => {
96
- let label = this.getLabel(childs, value)
97
- labels.push({ label, key: `label_${value}`, value })
98
- })
99
- currentLabel = labels
100
- } else {
101
- currentLabel = []
102
- }
103
-
104
- } else {
105
- currentLabel = this.getLabel(childs, currentValue)
106
- }
107
- this.label = currentLabel
108
-
109
- setTimeout(e => { this.setPosition() }, 230);
110
-
79
+ });
80
+ return Label;
111
81
  },
112
82
  clear(e) {
113
- let label = this.multiple ? [] : ""
114
- let value = this.multiple ? [] : ""
115
- this.label = label
116
- this.currentValue = value
83
+ let label = this.multiple ? [] : "";
84
+ let value = this.multiple ? [] : "";
85
+ this.label = label;
86
+ this.currentValue = value;
117
87
  this.$emit("input", value);
118
88
  this.$emit("change", value);
119
- e.stopPropagation()
89
+ e.stopPropagation();
120
90
  },
121
91
  showDrops() {
122
- let isSearch = ('search' in this.$listeners)
92
+ let isSearch = "search" in this.$listeners;
123
93
 
124
94
  this.opened = !this.opened;
125
95
  if (this.filterable || isSearch) {
126
- this.showSearch = this.opened
96
+ this.showSearch = this.opened;
127
97
  if (this.opened) {
128
- this.$nextTick(e => {
129
- this.isFocus = true
130
- this.$refs.search.focus()
131
- })
98
+ this.$nextTick((e) => {
99
+ this.isFocus = true;
100
+ this.$refs.search.focus();
101
+ });
132
102
  } else {
133
- this.$refs.search.blur()
134
- this.isFocus = false
103
+ this.$refs.search.blur();
104
+ this.isFocus = false;
135
105
 
136
106
  setTimeout(() => {
137
- this.queryKey = ''
138
- this.$refs.search.value = ''
107
+ this.queryKey = "";
108
+ this.$refs.search.value = "";
139
109
  }, 200);
140
110
  }
141
111
  }
@@ -145,273 +115,286 @@ export default {
145
115
  if (this.disabled) {
146
116
  return false;
147
117
  }
148
- let isSearch = ('search' in this.$listeners)
118
+ let isSearch = "search" in this.$listeners;
149
119
  if (isSearch) {
150
- // this.$nextTick(e => {
151
- this.showSearch = true
152
- this.$nextTick(e => {
153
- this.$refs.search.focus()
154
- this.isFocus = true
155
- })
156
- // })
120
+ this.showSearch = true;
121
+ this.$nextTick((e) => {
122
+ this.$refs.search.focus();
123
+ this.isFocus = true;
124
+ });
157
125
  return;
158
126
  }
159
- this.showDrops()
127
+ this.showDrops();
160
128
  },
161
129
  setPosition() {
162
- // if (!hasProp(this, 'width')) {
163
- // this.selectWidth = this.$el.offsetWidth
164
- // }
165
130
  if (this.opened) {
166
- this.$refs.overlay.setPosition()
131
+ this.$refs.overlay.setPosition();
167
132
  }
168
133
  },
169
134
  change(item) {
170
- let { multiple, value, currentValue } = this
135
+ let { multiple, value, currentValue } = this;
171
136
  // console.log(value, currentValue)
172
137
 
173
138
  if (this.showSearch) {
174
- this.queryKey = ''
175
- this.$refs.search.value = ''
176
- this.$refs.search.style.width = ''
139
+ this.queryKey = "";
140
+ this.$refs.search.value = "";
141
+ this.$refs.search.style.width = "";
177
142
  }
178
143
  if (!multiple) {
179
- this.opened = false
180
- this.showSearch = false
181
- } else if ('search' in this.$listeners || this.filterable) {
182
- this.$nextTick(e => {
183
- this.$refs.search.focus()
184
- this.isFocus = true
185
-
186
- })
144
+ this.opened = false;
145
+ this.showSearch = false;
146
+ } else if ("search" in this.$listeners || this.filterable) {
147
+ this.$nextTick((e) => {
148
+ this.$refs.search.focus();
149
+ this.isFocus = true;
150
+ });
187
151
  }
188
- let hasValue = hasProp(this, 'value')
152
+ let hasValue = hasProp(this, "value");
189
153
  //set value
190
154
  if (multiple) {
191
155
  if (!hasValue) {
192
- value = currentValue || []
156
+ value = currentValue || [];
193
157
  }
194
- let index = value.indexOf(item.value)
158
+ let index = value.indexOf(item.value);
195
159
  if (index === -1) {
196
- value.push(item.value)
160
+ value.push(item.value);
197
161
  } else {
198
- value.splice(index, 1)
162
+ value.splice(index, 1);
199
163
  }
200
164
  } else {
201
- value = item.value
165
+ value = item.value;
202
166
  }
203
- this.currentValue = value
167
+ this.currentValue = value;
204
168
 
205
169
  //set label
206
- if (!hasValue) {
207
- if (multiple) {
208
- let currentLabel = this.label || []
209
- let index = currentLabel.findIndex(x => x.value === item.value)// .map(x => x.label).indexOf(item.label)
210
- if (index === -1) {
211
- currentLabel.push({ label: item.label, key: item.label + item.value, value: item.value })
212
- } else {
213
- currentLabel.splice(index, 1)
214
- }
215
- this.label = currentLabel
216
- } else {
217
- this.label = item.label
218
- }
219
- setTimeout(e => { this.setPosition() }, 230);
220
- } else {
221
- this.$nextTick(e => this.setPosition())
222
- }
170
+
171
+ this.$nextTick((e) => this.setPosition());
223
172
  this.$emit("input", value);
224
173
  this.$emit("change", item);
225
174
  },
226
- removeTag(e, i) {
227
- if (this.disabled) return
228
- let values = this.currentValue || []
229
- let labels = this.label || []
230
- this.change({ value: values[i], label: labels[i].label })
231
- e.stopPropagation()
175
+ removeTag(e, c) {
176
+ if (this.disabled) return;
177
+ this.change({ value: c.value, label: c.label });
178
+ e.stopPropagation();
232
179
  },
233
180
  searchInput(e) {
234
- this.queryKey = e.target.value
181
+ this.queryKey = e.target.value;
235
182
  //todo:
236
- this.$nextTick(k => {
183
+ this.$nextTick((k) => {
237
184
  // let max = this.selectWidth - 15 - (this.showArrow ? 25 : 0)
238
- e.target.style.width = this.$refs.mirror.offsetWidth + 'px'
239
- this.setPosition()
240
- })
241
- if ('search' in this.$listeners) {
242
- clearTimeout(this.timer)
185
+ e.target.style.width = this.$refs.mirror.offsetWidth + "px";
186
+ this.setPosition();
187
+ });
188
+ if ("search" in this.$listeners) {
189
+ clearTimeout(this.timer);
243
190
  this.timer = setTimeout(() => {
244
191
  this.opened = true;
245
- this.$emit('search', e)
192
+ this.$emit("search", e);
246
193
  }, 500);
247
194
  }
248
195
  },
249
196
  emptyClick(e) {
250
197
  if (this.showSearch) {
251
- this.$nextTick(e => {
252
- this.$refs.search.focus()
253
- this.isFocus = true
254
-
255
- })
198
+ this.$nextTick((e) => {
199
+ this.$refs.search.focus();
200
+ this.isFocus = true;
201
+ });
256
202
  }
257
203
  },
258
- getOptions() {
259
- let { queryKey, options, $slots } = this
260
- let childs = null
204
+ getOptions(filterable) {
205
+ let { queryKey, options, $slots } = this;
206
+ let childs = null;
261
207
  if (Array.isArray(options)) {
262
208
  childs = options.map((k, i) => {
263
209
  let prop = {
264
210
  props: { ...k },
265
- key: k.key || (k.label + k.value)
266
- }
267
- return <Option {...prop} />
268
- })
211
+ key: k.key || k.label + k.value,
212
+ };
213
+ return <Option {...prop} />;
214
+ });
269
215
  } else {
270
- childs = getChild($slots.default)
216
+ childs = getChild($slots.default);
271
217
  }
218
+ if (!filterable) return childs;
219
+
272
220
  if (this.filterable && queryKey && !this.$listeners.search) {
273
221
  let parsedQuery = String(queryKey).replace(/(\^|\(|\)|\[|\]|\$|\*|\+|\.|\?|\\|\{|\}|\|)/g, "\\$1");
274
- let Reg = new RegExp(parsedQuery, 'i')
222
+ let Reg = new RegExp(parsedQuery, "i");
275
223
 
276
- childs = childs.filter(c => {
277
- let label = c.componentOptions.propsData.label || c.componentOptions.children[0].text
278
- return Reg.test(label)
279
- })
224
+ childs = childs.filter((c) => {
225
+ let label = c.componentOptions.propsData.label || c.componentOptions.children[0].text;
226
+ return Reg.test(label);
227
+ });
280
228
  }
281
- return childs
282
- }
283
- },
284
- mounted() {
285
- if (hasProp(this, 'value'))
286
- this.setLabel()
229
+ return childs;
230
+ },
287
231
  },
288
232
  render() {
289
- let { disabled, size, multiple,
290
- opened, placeholder, showArrow, bordered,
291
- clear, removeTag, queryKey, theme, arrowIcon, icon, shape, filterable,
292
- clearable, label, toggleDrop, isFocus } = this
293
- let childNode = []
233
+ let { disabled, size, multiple, opened, placeholder, currentValue, showArrow, bordered, clear, removeTag, queryKey, theme, arrowIcon, icon, shape, filterable, clearable, toggleDrop, isFocus } = this;
234
+ let childNode = [];
294
235
  if (arrowIcon == undefined) {
295
- arrowIcon = ChevronDown
236
+ arrowIcon = ChevronDown;
237
+ }
238
+
239
+ let childs = this.getOptions();
240
+
241
+ let label = null;
242
+ let values = isNotEmpty(currentValue) ? currentValue : multiple ? [] : "";
243
+ if (multiple) {
244
+ if (currentValue.length) {
245
+ let labels = [];
246
+ values.forEach((value) => {
247
+ let label = this.getLabel(childs, value);
248
+ if (!label) return;
249
+ labels.push({ label, key: `label_${value}`, value });
250
+ });
251
+ label = labels;
252
+ } else {
253
+ label = [];
254
+ }
255
+ } else {
256
+ label = this.getLabel(childs, values);
296
257
  }
258
+
297
259
  const classes = [
298
260
  "k-select",
299
261
  {
300
262
  "k-select-disabled": disabled,
301
263
  "k-select-open": opened,
302
- 'k-select-borderless': bordered === false,
303
- "k-select-lg": size == 'large',
304
- "k-select-sm": size == 'small',
305
- "k-select-light": theme == 'light',
264
+ "k-select-borderless": bordered === false,
265
+ "k-select-lg": size == "large",
266
+ "k-select-sm": size == "small",
267
+ "k-select-light": theme == "light",
306
268
  "k-select-has-icon": !!icon,
307
- "k-select-circle": shape == 'circle' && !multiple,
269
+ "k-select-circle": shape == "circle" && !multiple,
308
270
  "k-select-multiple": multiple,
309
271
  "k-select-show-search": isFocus,
310
- "k-select-show-tags": multiple && (label || []).length
311
- }
312
- ]
272
+ "k-select-show-tags": multiple && (label || []).length,
273
+ },
274
+ ];
313
275
 
314
276
  const queryProps = {
315
277
  on: {
316
278
  input: this.searchInput,
317
279
  blur: () => {
318
- if (!this.opened) this.showSearch = false
319
- this.isFocus = false
320
-
321
- }
280
+ if (!this.opened) this.showSearch = false;
281
+ this.isFocus = false;
282
+ },
322
283
  },
323
- ref: 'search',
324
- class: 'k-select-search',
284
+ ref: "search",
285
+ class: "k-select-search",
325
286
  attrs: {
326
- autoComplete: 'off',
327
- }
328
- }
329
- const queryNode = <div v-show={this.showSearch} key="search" class="k-select-search-wrap">
330
- <input {...queryProps} />
331
- <span class="k-select-search-mirror" ref="mirror">{queryKey}</span>
332
- </div>
333
-
334
- let childs = this.getOptions()
287
+ autoComplete: "off",
288
+ },
289
+ };
290
+ const queryNode = (
291
+ <div v-show={this.showSearch} key="search" class="k-select-search-wrap">
292
+ <input {...queryProps} />
293
+ <span class="k-select-search-mirror" ref="mirror">
294
+ {queryKey}
295
+ </span>
296
+ </div>
297
+ );
335
298
 
336
- const loadingNode = <div class="k-select-loading"><Icon type={Sync} spin /><span>{t('k.select.loading')}</span></div>
299
+ const loadingNode = (
300
+ <div class="k-select-loading">
301
+ <Icon type={Sync} spin />
302
+ <span>{t("k.select.loading")}</span>
303
+ </div>
304
+ );
337
305
  const props = {
338
- ref: 'overlay',
306
+ ref: "overlay",
339
307
  props: {
340
308
  width: this.selectWidth,
341
309
  value: opened,
342
310
  selection: this.$el,
343
311
  transfer: true,
344
312
  extendWidth: true,
345
- transitionName: 'k-select',
346
- className: ['k-select-dropdown', { 'k-select-dropdown-multiple': this.multiple, 'k-select-dropdown-sm': size == 'small' }]
313
+ transitionName: "k-select",
314
+ className: [
315
+ "k-select-dropdown",
316
+ {
317
+ "k-select-dropdown-multiple": this.multiple,
318
+ "k-select-dropdown-sm": size == "small",
319
+ },
320
+ ],
347
321
  },
348
322
  on: {
349
- input: e => {
350
- this.opened = e
323
+ input: (e) => {
324
+ this.opened = e;
351
325
  },
352
326
  hide: () => {
353
- this.opened = false
327
+ this.opened = false;
354
328
  setTimeout(() => {
355
- this.hideDrop()
356
- }, 300)
357
- }
358
- }
359
- }
360
- let overlay = <Drop {...props}>{this.loading ? loadingNode : (!childs.length ? <Empty onClick={this.emptyClick} description={this.emptyText} /> : <ul>{childs}</ul>)}</Drop>
329
+ this.hideDrop();
330
+ }, 300);
331
+ },
332
+ },
333
+ };
334
+ childs = this.getOptions(true);
335
+
336
+ let overlay = <Drop {...props}>{this.loading ? loadingNode : !childs.length ? <Empty onClick={this.emptyClick} description={this.emptyText} /> : <ul>{childs}</ul>}</Drop>;
361
337
 
362
- label = multiple ? (label || []) : label + ''
363
- placeholder = placeholder || t('k.select.placeholder')
364
- const placeNode = ((placeholder && (((label === null || label === undefined) || !label.length) && !queryKey))
365
- ? <div class="k-select-placeholder">{placeholder}</div>
366
- : null
367
- )
368
- const tags = multiple ?
369
- label.map((c, i) => {
370
- return <span class="k-select-tag" key={c.key}>{c.label}<Icon type={Close} onClick={e => removeTag(e, i)} /></span>
371
- })
372
- : null
338
+ label = multiple ? label || [] : label;
339
+ placeholder = placeholder || t("k.select.placeholder");
340
+ const placeNode = placeholder && !isNotEmpty(label) && !queryKey ? <div class="k-select-placeholder">{placeholder}</div> : null;
341
+ const tags = multiple
342
+ ? label.map((c, i) => {
343
+ return (
344
+ <span class="k-select-tag" key={c.key}>
345
+ {c.label}
346
+ <Icon type={Close} onClick={(e) => removeTag(e, c)} />
347
+ </span>
348
+ );
349
+ })
350
+ : null;
373
351
 
374
352
  const labelStyle = {
375
353
  // opacity: this.showSearch ? .4 : 1,
376
- display: queryKey.length ? 'none' : ''
377
- }
378
- const labelsNode = ((multiple)
379
- ? (
380
- [<div class="k-select-labels" name="k-select-tag">{tags}{queryNode}</div>]
381
- )
382
- : (label.length ? <div class="k-select-label" style={labelStyle}>{label}</div> : null)
383
- )
384
- let isSearch = ('search' in this.$listeners)
354
+ display: queryKey.length ? "none" : "",
355
+ };
356
+ const labelsNode = multiple ? (
357
+ [
358
+ <div class="k-select-labels" name="k-select-tag">
359
+ {tags}
360
+ {queryNode}
361
+ </div>,
362
+ ]
363
+ ) : label ? (
364
+ <div class="k-select-label" style={labelStyle}>
365
+ {label}
366
+ </div>
367
+ ) : null;
368
+ let isSearch = "search" in this.$listeners;
385
369
  childNode.push(labelsNode);
386
370
  placeNode && childNode.push(placeNode);
387
371
 
388
-
389
372
  if ((filterable || isSearch) && !multiple) {
390
- childNode.push(queryNode)
373
+ childNode.push(queryNode);
391
374
  }
392
375
  // label = "1"
393
- const styles = { width: `${this.width}px` }
394
- let showClear = !disabled && clearable && isNotEmpty(label) && label.length > 0
376
+ const styles = { width: `${this.width}px` };
377
+ let showClear = !disabled && clearable && isNotEmpty(label) && label.length > 0;
395
378
 
396
- classes[1]['k-select-has-clear'] = showClear
397
- const iconNodes = []
379
+ classes[1]["k-select-has-clear"] = showClear;
380
+ const iconNodes = [];
398
381
 
399
382
  if (!isSearch && showArrow) {
400
- iconNodes.push(<Icon class="k-select-arrow" type={arrowIcon} />)
383
+ iconNodes.push(<Icon class="k-select-arrow" type={arrowIcon} />);
401
384
  }
402
385
  if (showClear) {
403
- iconNodes.push(<Icon class="k-select-clearable" type={CloseCircle} onClick={clear} />)
386
+ iconNodes.push(<Icon class="k-select-clearable" type={CloseCircle} onClick={clear} />);
404
387
  }
405
388
  // console.log(iconNodes)
406
389
 
407
- iconNodes.push(" ")
390
+ iconNodes.push(" ");
408
391
  return (
409
392
  <div tabIndex="0" class={classes} style={styles} onClick={toggleDrop} ref="rel">
410
393
  {icon ? <Icon type={icon} class="k-select-icon" /> : null}
411
394
  <div class="k-select-selection">{childNode}</div>
412
395
  {iconNodes}
413
396
  {overlay}
414
- </div >
415
- )
416
- }
397
+ </div>
398
+ );
399
+ },
417
400
  };
package/dist/k-ui.css CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * kui-vue v3.4.8
2
+ * kui-vue v3.4.9
3
3
  * Copyright 2017-present, kui-vue.
4
4
  * All rights reserved.
5
5
  * Docs: https://k-ui.cn