@enso-ui/typeahead 3.0.13 → 3.0.14

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@enso-ui/typeahead",
3
- "version": "3.0.13",
3
+ "version": "3.0.14",
4
4
  "description": "Vue Typeahead",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -3,7 +3,7 @@
3
3
  ref="typeahead">
4
4
  <template #default="{
5
5
  addTag, canAddTag, clearBindings, controlEvents, disabled,
6
- invalidQuery, highlight, i18n, inputBindings, inputEvents,
6
+ invalidRegExp, highlight, i18n, inputBindings, inputEvents,
7
7
  itemEvents, items, label, loading, minQueryLength,
8
8
  modeSelector, modeBindings, modeEvents,
9
9
  readonly, query, searchControl,
@@ -20,7 +20,7 @@
20
20
  <input class="input is-fullwidth"
21
21
  :class="[
22
22
  { 'is-rounded': isRounded },
23
- { 'is-danger': invalidQuery || hasError }
23
+ { 'is-danger': invalidRegExp || hasError }
24
24
  ]"
25
25
  v-bind="inputBindings"
26
26
  type="text"
@@ -6,15 +6,15 @@ export default {
6
6
  name: 'CoreTypeahead',
7
7
 
8
8
  props: {
9
- disabled: {
10
- type: Boolean,
11
- default: false,
12
- },
13
9
  debounce: {
14
10
  type: Number,
15
11
  default: 250,
16
12
  validator: v => v > 0,
17
13
  },
14
+ disabled: {
15
+ type: Boolean,
16
+ default: false,
17
+ },
18
18
  errorHandler: {
19
19
  type: Function,
20
20
  default: error => {
@@ -59,9 +59,7 @@ export default {
59
59
  },
60
60
  regExp: {
61
61
  type: RegExp,
62
- default() {
63
- return /(.*?)/;
64
- },
62
+ default:() => /(.*?)/,
65
63
  },
66
64
  searchControl: {
67
65
  type: Boolean,
@@ -95,21 +93,24 @@ export default {
95
93
  mode: v.searchMode,
96
94
  ongoingRequest: null,
97
95
  query: '',
98
- waitingResponse: false,
99
96
  }),
100
97
 
101
98
  computed: {
102
99
  canAddTag() {
103
- return this.taggable && !!this.query
104
- && this.queryDoesntMatch && !this.waitingResponse;
100
+ return this.taggable && this.query !== ''
101
+ && !this.loading && this.queryHasNoResults;
105
102
  },
106
103
  invalidQuery() {
107
- return this.query && !this.regExp.test(this.query);
104
+ return this.query.trim().length < this.minQueryLength
105
+ || this.invalidRegExp;
106
+ },
107
+ invalidRegExp() {
108
+ return !this.regExp.test(this.query);
108
109
  },
109
110
  modeSelector() {
110
111
  return this.searchModes.length > 1;
111
112
  },
112
- queryDoesntMatch() {
113
+ queryHasNoResults() {
113
114
  return !this.items
114
115
  .some(item => `${item[this.label]}`
115
116
  .toLowerCase() === this.query.toLowerCase());
@@ -124,12 +125,6 @@ export default {
124
125
  },
125
126
  },
126
127
 
127
- watch: {
128
- query(query) {
129
- this.waitingResponse = query !== '';
130
- },
131
- },
132
-
133
128
  created() {
134
129
  this.fetch = debounce(this.fetch, this.debounce);
135
130
  },
@@ -158,11 +153,6 @@ export default {
158
153
  return;
159
154
  }
160
155
 
161
- if (this.query.length < this.minQueryLength) {
162
- this.items = [];
163
- return;
164
- }
165
-
166
156
  if (this.ongoingRequest) {
167
157
  this.ongoingRequest.cancel();
168
158
  }
@@ -173,15 +163,9 @@ export default {
173
163
  this.http.get(this.source, {
174
164
  params: this.requestParams,
175
165
  cancelToken: this.ongoingRequest.token,
176
- }).then(({ data }) => {
177
- this.items = data;
178
- this.loading = false;
179
- this.waitingResponse = false;
180
- }).catch(error => {
181
- this.loading = false;
182
- this.waitingResponse = false;
183
- this.errorHandler(error);
184
- });
166
+ }).then(({ data }) => (this.items = data))
167
+ .catch(this.errorHandler)
168
+ .finally(() => (this.loading = false));
185
169
  },
186
170
  highlight(item) {
187
171
  this.query.split(' ')
@@ -191,7 +175,7 @@ export default {
191
175
  return item;
192
176
  },
193
177
  search(item = null) {
194
- if (this.query.length < this.minQueryLength) {
178
+ if (this.invalidQuery) {
195
179
  return;
196
180
  }
197
181
 
@@ -200,6 +184,7 @@ export default {
200
184
  }
201
185
 
202
186
  this.$emit('search', { item, query: this.query });
187
+
203
188
  this.query = '';
204
189
  },
205
190
  select(index) {
@@ -222,7 +207,7 @@ export default {
222
207
  click: this.search,
223
208
  },
224
209
  disabled: this.disabled,
225
- invalidQuery: this.invalidQuery,
210
+ invalidRegExp: this.invalidRegExp,
226
211
  highlight: this.highlight,
227
212
  i18n: this.i18n,
228
213
  inputBindings: { value: this.query },