@appbaseio/reactivesearch-vue 1.28.0 → 1.29.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 (39) hide show
  1. package/dist/@appbaseio/reactivesearch-vue.umd.js +1780 -413
  2. package/dist/@appbaseio/reactivesearch-vue.umd.js.map +1 -1
  3. package/dist/@appbaseio/reactivesearch-vue.umd.min.js +5 -5
  4. package/dist/@appbaseio/reactivesearch-vue.umd.min.js.map +1 -1
  5. package/dist/cjs/{Button-11307285.js → Button-e0b7c1f6.js} +1 -1
  6. package/dist/cjs/DataSearch-eec21890.js +2171 -0
  7. package/dist/cjs/DataSearch.js +18 -2107
  8. package/dist/cjs/{DropDown-7aa3d0d2.js → DropDown-e4381fcc.js} +1 -1
  9. package/dist/cjs/{Input-3cc3fa59.js → Input-0d7b25ad.js} +1 -1
  10. package/dist/cjs/MultiDropdownList.js +3 -3
  11. package/dist/cjs/MultiList.js +1 -1
  12. package/dist/cjs/RangeInput.js +1 -1
  13. package/dist/cjs/ReactiveList.js +1 -1
  14. package/dist/cjs/SelectedFilters.js +1 -1
  15. package/dist/cjs/SingleDropdownList.js +3 -3
  16. package/dist/cjs/SingleList.js +1 -1
  17. package/dist/cjs/ToggleButton.js +1 -1
  18. package/dist/cjs/index.js +10 -9
  19. package/dist/cjs/install-4886582d.js +1244 -0
  20. package/dist/cjs/install.js +24 -29
  21. package/dist/cjs/version.js +1 -1
  22. package/dist/es/{Button-91561391.js → Button-33de88e6.js} +1 -1
  23. package/dist/es/DataSearch-42f547cd.js +2158 -0
  24. package/dist/es/DataSearch.js +17 -2106
  25. package/dist/es/{DropDown-60a426a2.js → DropDown-ff6ad982.js} +1 -1
  26. package/dist/es/{Input-08bb1bcf.js → Input-e339e63a.js} +1 -1
  27. package/dist/es/MultiDropdownList.js +3 -3
  28. package/dist/es/MultiList.js +1 -1
  29. package/dist/es/RangeInput.js +1 -1
  30. package/dist/es/ReactiveList.js +1 -1
  31. package/dist/es/SelectedFilters.js +1 -1
  32. package/dist/es/SingleDropdownList.js +3 -3
  33. package/dist/es/SingleList.js +1 -1
  34. package/dist/es/ToggleButton.js +1 -1
  35. package/dist/es/index.js +6 -6
  36. package/dist/es/install-54ebd72e.js +1237 -0
  37. package/dist/es/install.js +22 -31
  38. package/dist/es/version.js +1 -1
  39. package/package.json +2 -2
@@ -0,0 +1,1244 @@
1
+ 'use strict';
2
+
3
+ function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
4
+
5
+ var configureStore = require('@appbaseio/reactivecore');
6
+ var configureStore__default = _interopDefault(configureStore);
7
+ var _rollupPluginBabelHelpers = require('./_rollupPluginBabelHelpers-f127c8b7.js');
8
+ var VueTypes = _interopDefault(require('vue-types'));
9
+ var constants = require('@appbaseio/reactivecore/lib/utils/constants');
10
+ var helper = require('@appbaseio/reactivecore/lib/utils/helper');
11
+ var styled = require('@appbaseio/vue-emotion');
12
+ var styled__default = _interopDefault(styled);
13
+ var Button = require('./Button-e0b7c1f6.js');
14
+ var vueTypes = require('./vueTypes-57d01f18.js');
15
+ var ReactiveList = require('./ReactiveList.js');
16
+ var index = require('./index-4509aa45.js');
17
+ var ComponentWrapper = require('./ComponentWrapper-10bad289.js');
18
+ var Title = require('./Title-584a8cc8.js');
19
+ var ReactiveBase = require('./ReactiveBase.js');
20
+ var hotkeys = _interopDefault(require('hotkeys-js'));
21
+ var DataSearch = require('./DataSearch-eec21890.js');
22
+ var CancelSvg = require('./CancelSvg-4aa35935.js');
23
+ var Input = require('./Input-0d7b25ad.js');
24
+ var Container = require('./Container-526efa6a.js');
25
+ var SingleList = require('./SingleList.js');
26
+ var MultiList = require('./MultiList.js');
27
+ var SingleDropdownList = require('./SingleDropdownList.js');
28
+ var MultiDropdownList = require('./MultiDropdownList.js');
29
+ var ToggleButton = require('./ToggleButton.js');
30
+ var ReactiveComponent = require('./ReactiveComponent.js');
31
+ var SelectedFilters = require('./SelectedFilters.js');
32
+ var SingleRange = require('./SingleRange.js');
33
+ var MultiRange = require('./MultiRange.js');
34
+ var ResultCard = require('./ResultCard.js');
35
+ var ResultList = require('./ResultList.js');
36
+ var RangeSlider = require('./RangeSlider.js');
37
+ var DynamicRangeSlider = require('./DynamicRangeSlider.js');
38
+ var StateProvider = require('./StateProvider.js');
39
+ var RangeInput = require('./RangeInput.js');
40
+
41
+ var _templateObject;
42
+ var AutofillSvgIcon = styled__default('button')(_templateObject || (_templateObject = _rollupPluginBabelHelpers._taggedTemplateLiteralLoose(["\n\tdisplay: flex;\n\tmargin-left: auto;\n\tposition: relative;\n\tright: -3px;\n\tborder: none;\n\toutline: none;\n\tbackground: transparent;\n\tpadding: 0;\n\tz-index: 111000;\n\n\tsvg {\n\t\tcursor: pointer;\n\t\tfill: #707070;\n\t\theight: 20px;\n\t}\n\n\t&:hover {\n\t\tsvg {\n\t\t\tfill: #1c1a1a;\n\t\t}\n\t}\n"])));
43
+ var AutoFillSvg = {
44
+ name: 'AutoFillSvg',
45
+ render: function render() {
46
+ var h = arguments[0];
47
+ return h(AutofillSvgIcon, {
48
+ "on": {
49
+ "click": this.$listeners.click
50
+ }
51
+ }, [h("svg", {
52
+ "attrs": {
53
+ "viewBox": "0 0 24 24"
54
+ }
55
+ }, [h("path", {
56
+ "attrs": {
57
+ "d": "M8 17v-7.586l8.293 8.293c0.391 0.391 1.024 0.391 1.414 0s0.391-1.024 0-1.414l-8.293-8.293h7.586c0.552 0 1-0.448 1-1s-0.448-1-1-1h-10c-0.552 0-1 0.448-1 1v10c0 0.552 0.448 1 1 1s1-0.448 1-1z"
58
+ }
59
+ })])]);
60
+ },
61
+ methods: {
62
+ clicked: function clicked(e) {
63
+ e.stopPropagation();
64
+ window.console.log('hey', e);
65
+ }
66
+ }
67
+ };
68
+
69
+ var updateQuery = configureStore.Actions.updateQuery,
70
+ setCustomQuery = configureStore.Actions.setCustomQuery,
71
+ setDefaultQuery = configureStore.Actions.setDefaultQuery,
72
+ recordSuggestionClick = configureStore.Actions.recordSuggestionClick;
73
+ var _debounce = configureStore.helper.debounce,
74
+ checkValueChange = configureStore.helper.checkValueChange,
75
+ getClassName = configureStore.helper.getClassName,
76
+ isEqual = configureStore.helper.isEqual,
77
+ getCompositeAggsQuery = configureStore.helper.getCompositeAggsQuery,
78
+ withClickIds = configureStore.helper.withClickIds,
79
+ getResultStats = configureStore.helper.getResultStats,
80
+ normalizeDataField = configureStore.helper.normalizeDataField;
81
+ var SearchBox = {
82
+ name: 'SearchBox',
83
+ data: function data() {
84
+ var props = this.$props;
85
+ this.__state = {
86
+ currentValue: '',
87
+ isOpen: false,
88
+ normalizedSuggestions: []
89
+ };
90
+ this.internalComponent = props.componentId + "__internal";
91
+ return this.__state;
92
+ },
93
+ inject: {
94
+ theme: {
95
+ from: 'theme_reactivesearch'
96
+ }
97
+ },
98
+ created: function created() {
99
+ var _this$$props = this.$props,
100
+ distinctField = _this$$props.distinctField,
101
+ distinctFieldConfig = _this$$props.distinctFieldConfig,
102
+ index = _this$$props.index;
103
+
104
+ if (this.enableAppbase && this.aggregationField && this.aggregationField !== '') {
105
+ console.warn('Warning(ReactiveSearch): The `aggregationField` prop has been marked as deprecated, please use the `distinctField` prop instead.');
106
+ }
107
+
108
+ if (!this.enableAppbase && (distinctField || distinctFieldConfig)) {
109
+ console.warn('Warning(ReactiveSearch): In order to use the `distinctField` and `distinctFieldConfig` props, the `enableAppbase` prop must be set to true in `ReactiveBase`.');
110
+ }
111
+
112
+ if (!this.enableAppbase && index) {
113
+ console.warn('Warning(ReactiveSearch): In order to use the `index` prop, the `enableAppbase` prop must be set to true in `ReactiveBase`.');
114
+ }
115
+
116
+ this.currentValue = this.selectedValue || this.value || this.defaultValue || '';
117
+ this.handleTextChange = _debounce(this.handleText, this.$props.debounce);
118
+ this.setValue(this.currentValue, true, this.$props, undefined, false, this.selectedCategory); // Set custom and default queries in store
119
+
120
+ this.triggerCustomQuery(this.currentValue, this.selectedCategory);
121
+ this.triggerDefaultQuery(this.currentValue);
122
+ },
123
+ computed: {
124
+ hasCustomRenderer: function hasCustomRenderer() {
125
+ return index.hasCustomRenderer(this);
126
+ },
127
+ stats: function stats() {
128
+ return getResultStats(this);
129
+ }
130
+ },
131
+ props: {
132
+ autoFocus: VueTypes.bool,
133
+ autosuggest: VueTypes.bool.def(true),
134
+ beforeValueChange: vueTypes.types.func,
135
+ className: VueTypes.string.def(''),
136
+ clearIcon: vueTypes.types.children,
137
+ componentId: vueTypes.types.stringRequired,
138
+ customHighlight: vueTypes.types.func,
139
+ customQuery: vueTypes.types.func,
140
+ defaultQuery: vueTypes.types.func,
141
+ dataField: VueTypes.oneOfType([VueTypes.string, VueTypes.shape({
142
+ field: VueTypes.string,
143
+ weight: VueTypes.number
144
+ }), VueTypes.arrayOf(VueTypes.string), VueTypes.arrayOf({
145
+ field: VueTypes.string,
146
+ weight: VueTypes.number
147
+ })]),
148
+ aggregationField: vueTypes.types.string,
149
+ aggregationSize: VueTypes.number,
150
+ size: VueTypes.number,
151
+ debounce: VueTypes.number.def(0),
152
+ defaultValue: vueTypes.types.string,
153
+ excludeFields: vueTypes.types.excludeFields,
154
+ value: vueTypes.types.value,
155
+ defaultSuggestions: vueTypes.types.suggestions,
156
+ enableSynonyms: VueTypes.bool.def(true),
157
+ enableQuerySuggestions: VueTypes.bool.def(false),
158
+ enablePopularSuggestions: VueTypes.bool.def(false),
159
+ enableRecentSuggestions: VueTypes.bool.def(false),
160
+ fieldWeights: vueTypes.types.fieldWeights,
161
+ filterLabel: vueTypes.types.string,
162
+ fuzziness: vueTypes.types.fuzziness,
163
+ highlight: VueTypes.bool,
164
+ highlightField: vueTypes.types.stringOrArray,
165
+ icon: vueTypes.types.children,
166
+ iconPosition: VueTypes.oneOf(['left', 'right']).def('left'),
167
+ includeFields: vueTypes.types.includeFields,
168
+ innerClass: vueTypes.types.style,
169
+ innerRef: VueTypes.string.def('searchInputField'),
170
+ render: vueTypes.types.func,
171
+ renderNoSuggestion: vueTypes.types.title,
172
+ renderError: vueTypes.types.title,
173
+ placeholder: VueTypes.string.def('Search'),
174
+ queryFormat: VueTypes.oneOf(['and', 'or']).def('or'),
175
+ react: vueTypes.types.react,
176
+ showClear: VueTypes.bool.def(true),
177
+ showDistinctSuggestions: VueTypes.bool.def(true),
178
+ showFilter: VueTypes.bool.def(true),
179
+ showIcon: VueTypes.bool.def(true),
180
+ title: vueTypes.types.title,
181
+ theme: vueTypes.types.style,
182
+ URLParams: VueTypes.bool.def(false),
183
+ strictSelection: VueTypes.bool.def(false),
184
+ nestedField: vueTypes.types.string,
185
+ enablePredictiveSuggestions: VueTypes.bool.def(false),
186
+ recentSearchesIcon: VueTypes.any,
187
+ popularSearchesIcon: VueTypes.any,
188
+ // mic props
189
+ showVoiceSearch: VueTypes.bool.def(false),
190
+ getMicInstance: vueTypes.types.func,
191
+ renderMic: vueTypes.types.func,
192
+ distinctField: vueTypes.types.string,
193
+ distinctFieldConfig: vueTypes.types.props,
194
+ //
195
+ focusShortcuts: VueTypes.arrayOf(VueTypes.oneOfType([VueTypes.string, VueTypes.number])).def(['/']),
196
+ addonBefore: VueTypes.any,
197
+ addonAfter: VueTypes.any,
198
+ expandSuggestionsContainer: VueTypes.bool.def(true),
199
+ index: VueTypes.string,
200
+ popularSuggestionsConfig: VueTypes.object,
201
+ recentSuggestionsConfig: VueTypes.object,
202
+ applyStopwords: VueTypes.bool,
203
+ customStopwords: vueTypes.types.stringArray,
204
+ onData: vueTypes.types.func,
205
+ renderItem: vueTypes.types.func,
206
+ enterButton: VueTypes.bool.def(false),
207
+ renderEnterButton: VueTypes.any
208
+ },
209
+ mounted: function mounted() {
210
+ this.listenForFocusShortcuts();
211
+ },
212
+ watch: {
213
+ dataField: function dataField(newVal, oldVal) {
214
+ if (!isEqual(newVal, oldVal)) {
215
+ this.triggerCustomQuery(this.$data.currentValue);
216
+ }
217
+ },
218
+ fieldWeights: function fieldWeights() {
219
+ this.triggerCustomQuery(this.$data.currentValue);
220
+ },
221
+ fuzziness: function fuzziness() {
222
+ this.triggerCustomQuery(this.$data.currentValue);
223
+ },
224
+ queryFormat: function queryFormat() {
225
+ this.triggerCustomQuery(this.$data.currentValue);
226
+ },
227
+ defaultValue: function defaultValue(newVal) {
228
+ this.setValue(newVal, true, this.$props);
229
+ },
230
+ value: function value(newVal, oldVal) {
231
+ if (!isEqual(newVal, oldVal)) {
232
+ this.setValue(newVal, true, this.$props, newVal === '' ? configureStore.causes.CLEAR_VALUE : undefined, false);
233
+ }
234
+ },
235
+ defaultQuery: function defaultQuery(newVal, oldVal) {
236
+ if (!index.isQueryIdentical(newVal, oldVal, this.$data.currentValue, this.$props)) {
237
+ this.triggerDefaultQuery(this.$data.currentValue);
238
+ }
239
+ },
240
+ customQuery: function customQuery(newVal, oldVal) {
241
+ if (!index.isQueryIdentical(newVal, oldVal, this.$data.currentValue, this.$props)) {
242
+ this.triggerCustomQuery(this.$data.currentValue);
243
+ }
244
+ },
245
+ suggestions: function suggestions(newVal) {
246
+ var suggestionsList = [];
247
+
248
+ if (Array.isArray(newVal) && newVal.length) {
249
+ suggestionsList = [].concat(withClickIds(newVal));
250
+ } else if (Array.isArray(this.$props.defaultSuggestions) && this.$props.defaultSuggestions.length) {
251
+ suggestionsList = [].concat(withClickIds(this.$props.defaultSuggestions));
252
+ }
253
+
254
+ this.normalizedSuggestions = suggestionsList;
255
+ },
256
+ selectedValue: function selectedValue(newVal, oldVal) {
257
+ if (oldVal !== newVal && this.$data.currentValue !== newVal) {
258
+ if (!newVal && this.$data.currentValue) {
259
+ // selected value is cleared, call onValueSelected
260
+ this.onValueSelectedHandler('', configureStore.causes.CLEAR_VALUE);
261
+ }
262
+
263
+ if (this.$props.value === undefined) {
264
+ this.setValue(newVal || '', true, this.$props);
265
+ }
266
+ }
267
+ },
268
+ focusShortcuts: function focusShortcuts() {
269
+ this.listenForFocusShortcuts();
270
+ },
271
+ rawData: function rawData(newVal) {
272
+ this.$emit('on-data', {
273
+ data: this.normalizedSuggestions,
274
+ rawData: newVal,
275
+ aggregationData: this.aggregationData,
276
+ loading: this.isLoading,
277
+ error: this.isError
278
+ });
279
+ },
280
+ aggregationData: function aggregationData(newVal) {
281
+ this.$emit('on-data', {
282
+ data: this.normalizedSuggestions,
283
+ rawData: this.rawData,
284
+ aggregationData: newVal,
285
+ loading: this.isLoading,
286
+ error: this.isError
287
+ });
288
+ },
289
+ loading: function loading(newVal) {
290
+ this.$emit('on-data', {
291
+ data: this.normalizedSuggestions,
292
+ rawData: this.rawData,
293
+ aggregationData: this.aggregationData,
294
+ loading: newVal,
295
+ error: this.isError
296
+ });
297
+ },
298
+ error: function error(newVal) {
299
+ this.$emit('on-data', {
300
+ data: this.normalizedSuggestions,
301
+ rawData: this.rawData,
302
+ aggregationData: this.aggregationData,
303
+ loading: this.isLoading,
304
+ error: newVal
305
+ });
306
+ },
307
+ debounce: function debounce(newVal, oldVal) {
308
+ if (!isEqual(newVal, oldVal)) {
309
+ this.handleTextChange = _debounce(this.handleText, newVal);
310
+ }
311
+ }
312
+ },
313
+ methods: {
314
+ handleText: function handleText(value, cause) {
315
+ if (cause === configureStore.causes.CLEAR_VALUE) {
316
+ this.triggerCustomQuery(value);
317
+ this.triggerDefaultQuery(value);
318
+ } else if (this.$props.autosuggest) {
319
+ this.triggerDefaultQuery(value);
320
+ } else if (!this.$props.enterButton) {
321
+ this.triggerCustomQuery(value);
322
+ }
323
+ },
324
+ validateDataField: function validateDataField() {
325
+ var propName = 'dataField';
326
+ var componentName = SearchBox.name;
327
+ var props = this.$props;
328
+ var requiredError = propName + " supplied to " + componentName + " is required. Validation failed.";
329
+ var propValue = props[propName];
330
+
331
+ if (!this.enableAppbase) {
332
+ if (!propValue) {
333
+ console.error(requiredError);
334
+ return;
335
+ }
336
+
337
+ if (typeof propValue !== 'string' && typeof propValue !== 'object' && !Array.isArray(propValue)) {
338
+ console.error("Invalid " + propName + " supplied to " + componentName + ". Validation failed.");
339
+ return;
340
+ }
341
+
342
+ if (Array.isArray(propValue) && propValue.length === 0) {
343
+ console.error(requiredError);
344
+ }
345
+ }
346
+ },
347
+ getComponent: function getComponent(downshiftProps) {
348
+ if (downshiftProps === void 0) {
349
+ downshiftProps = {};
350
+ }
351
+
352
+ var currentValue = this.$data.currentValue;
353
+ var data = {
354
+ error: this.error,
355
+ loading: this.isLoading,
356
+ downshiftProps: downshiftProps,
357
+ data: this.normalizedSuggestions,
358
+ rawData: this.rawData,
359
+ value: currentValue,
360
+ resultStats: this.stats
361
+ };
362
+ return index.getComponent(data, this);
363
+ },
364
+ // returns size and aggs property
365
+ getBasicQueryOptions: function getBasicQueryOptions() {
366
+ var aggregationField = this.$props.aggregationField;
367
+ var queryOptions = helper.getQueryOptions(this.$props);
368
+
369
+ if (aggregationField) {
370
+ queryOptions.aggs = getCompositeAggsQuery({
371
+ props: this.$props,
372
+ showTopHits: true
373
+ }).aggs;
374
+ }
375
+
376
+ return queryOptions;
377
+ },
378
+ handleSearchIconClick: function handleSearchIconClick() {
379
+ var currentValue = this.currentValue;
380
+
381
+ if (currentValue.trim()) {
382
+ this.setValue(currentValue, true);
383
+ this.onValueSelectedHandler(currentValue, configureStore.causes.SEARCH_ICON_CLICK);
384
+ }
385
+ },
386
+ setValue: function setValue(value, isDefaultValue, props, cause, toggleIsOpen, categoryValue) {
387
+ var _this = this;
388
+
389
+ if (isDefaultValue === void 0) {
390
+ isDefaultValue = false;
391
+ }
392
+
393
+ if (props === void 0) {
394
+ props = this.$props;
395
+ }
396
+
397
+ if (toggleIsOpen === void 0) {
398
+ toggleIsOpen = true;
399
+ }
400
+
401
+ if (categoryValue === void 0) {
402
+ categoryValue = undefined;
403
+ }
404
+
405
+ var performUpdate = function performUpdate() {
406
+ _this.currentValue = value;
407
+
408
+ if (isDefaultValue) {
409
+ if (_this.$props.autosuggest) {
410
+ if (toggleIsOpen) {
411
+ _this.isOpen = false;
412
+ }
413
+
414
+ _this.triggerDefaultQuery(value);
415
+ } // in case of strict selection only SUGGESTION_SELECT should be able
416
+ // to set the query otherwise the value should reset
417
+
418
+
419
+ if (props.strictSelection) {
420
+ if (cause === configureStore.causes.SUGGESTION_SELECT || value === '') {
421
+ _this.triggerCustomQuery(value, categoryValue);
422
+ } else {
423
+ _this.setValue('', true);
424
+ }
425
+ } else if (props.value === undefined) {
426
+ _this.triggerCustomQuery(value, categoryValue);
427
+ }
428
+ } else {
429
+ // debounce for handling text while typing
430
+ _this.handleTextChange(value, cause);
431
+ }
432
+
433
+ _this.$emit('valueChange', value);
434
+
435
+ _this.$emit('value-change', value);
436
+ };
437
+
438
+ checkValueChange(props.componentId, value, props.beforeValueChange, performUpdate);
439
+ },
440
+ triggerDefaultQuery: function triggerDefaultQuery(paramValue) {
441
+ if (!this.$props.autosuggest) {
442
+ return;
443
+ }
444
+
445
+ var value = typeof paramValue !== 'string' ? this.currentValue : paramValue;
446
+ var query = SearchBox.defaultQuery(value, this.$props);
447
+
448
+ if (this.defaultQuery) {
449
+ var defaultQueryToBeSet = this.defaultQuery(value, this.$props) || {};
450
+
451
+ if (defaultQueryToBeSet.query) {
452
+ query = defaultQueryToBeSet.query;
453
+ } // Update calculated default query in store
454
+
455
+
456
+ index.updateDefaultQuery(this.$props.componentId, this.setDefaultQuery, this.$props, value);
457
+ }
458
+
459
+ this.updateQuery({
460
+ componentId: this.internalComponent,
461
+ query: query,
462
+ value: value,
463
+ componentType: constants.componentTypes.searchBox
464
+ });
465
+ },
466
+ triggerCustomQuery: function triggerCustomQuery(paramValue, categoryValue) {
467
+ if (categoryValue === void 0) {
468
+ categoryValue = undefined;
469
+ }
470
+
471
+ var _this$$props2 = this.$props,
472
+ customQuery = _this$$props2.customQuery,
473
+ filterLabel = _this$$props2.filterLabel,
474
+ showFilter = _this$$props2.showFilter,
475
+ URLParams = _this$$props2.URLParams;
476
+ var value = typeof paramValue !== 'string' ? this.$data.currentValue : paramValue;
477
+ var defaultQueryTobeSet = SearchBox.defaultQuery("" + value + (categoryValue ? " in " + categoryValue : ''), this.$props);
478
+ var query = defaultQueryTobeSet;
479
+
480
+ if (customQuery) {
481
+ var customQueryTobeSet = customQuery(value, this.$props);
482
+ var queryTobeSet = customQueryTobeSet.query;
483
+
484
+ if (queryTobeSet) {
485
+ query = queryTobeSet;
486
+ }
487
+
488
+ index.updateCustomQuery(this.$props.componentId, this.setCustomQuery, this.$props, value);
489
+ }
490
+
491
+ this.updateQuery({
492
+ componentId: this.$props.componentId,
493
+ query: query,
494
+ value: value,
495
+ label: filterLabel,
496
+ showFilter: showFilter,
497
+ URLParams: URLParams,
498
+ componentType: constants.componentTypes.searchBox,
499
+ category: categoryValue
500
+ });
501
+ },
502
+ handleFocus: function handleFocus(event) {
503
+ if (this.$props.autosuggest) {
504
+ this.isOpen = true;
505
+ }
506
+
507
+ this.$emit('focus', event);
508
+ },
509
+ handleVoiceResults: function handleVoiceResults(_ref) {
510
+ var results = _ref.results;
511
+
512
+ if (results && results[0] && results[0].isFinal && results[0][0] && results[0][0].transcript && results[0][0].transcript.trim()) {
513
+ this.setValue(results[0][0].transcript.trim(), true);
514
+ }
515
+ },
516
+ triggerQuery: function triggerQuery(_ref2) {
517
+ var _ref2$isOpen = _ref2.isOpen,
518
+ isOpen = _ref2$isOpen === void 0 ? undefined : _ref2$isOpen,
519
+ _ref2$customQuery = _ref2.customQuery,
520
+ customQuery = _ref2$customQuery === void 0 ? true : _ref2$customQuery,
521
+ _ref2$defaultQuery = _ref2.defaultQuery,
522
+ defaultQuery = _ref2$defaultQuery === void 0 ? true : _ref2$defaultQuery,
523
+ _ref2$value = _ref2.value,
524
+ value = _ref2$value === void 0 ? undefined : _ref2$value,
525
+ _ref2$categoryValue = _ref2.categoryValue,
526
+ categoryValue = _ref2$categoryValue === void 0 ? undefined : _ref2$categoryValue;
527
+
528
+ if (typeof isOpen === 'boolean') {
529
+ this.isOpen = isOpen;
530
+ }
531
+
532
+ if (customQuery) {
533
+ this.triggerCustomQuery(value, categoryValue);
534
+ }
535
+
536
+ if (defaultQuery) {
537
+ this.triggerDefaultQuery(value);
538
+ }
539
+ },
540
+ triggerClickAnalytics: function triggerClickAnalytics(searchPosition, documentId) {
541
+ // click analytics would only work client side and after javascript loads
542
+ var docId = documentId;
543
+
544
+ if (!docId) {
545
+ var hitData = this.normalizedSuggestions.find(function (hit) {
546
+ return hit._click_id === searchPosition;
547
+ });
548
+
549
+ if (hitData && hitData.source && hitData.source._id) {
550
+ docId = hitData.source._id;
551
+ }
552
+ }
553
+
554
+ this.recordSuggestionClick(searchPosition, docId);
555
+ },
556
+ clearValue: function clearValue() {
557
+ this.setValue('', false, this.$props, configureStore.causes.CLEAR_VALUE, false);
558
+ this.onValueSelectedHandler('', configureStore.causes.CLEAR_VALUE);
559
+ },
560
+ handleKeyDown: function handleKeyDown(event, highlightedIndex) {
561
+ // if a suggestion was selected, delegate the handling to suggestion handler
562
+ if (event.key === 'Enter' && highlightedIndex === null) {
563
+ this.setValue(event.target.value, true);
564
+ this.onValueSelectedHandler(event.target.value, configureStore.causes.ENTER_PRESS);
565
+ } // Need to review
566
+
567
+
568
+ this.$emit('keyDown', event, this.triggerQuery);
569
+ this.$emit('key-down', event, this.triggerQuery);
570
+ },
571
+ onInputChange: function onInputChange(e) {
572
+ var _this2 = this;
573
+
574
+ var inputValue = e.target.value;
575
+
576
+ if (!this.$data.isOpen && this.$props.autosuggest) {
577
+ this.isOpen = true;
578
+ }
579
+
580
+ var value = this.$props.value;
581
+
582
+ if (value === undefined) {
583
+ this.setValue(inputValue, false, this.$props, inputValue === '' ? configureStore.causes.CLEAR_VALUE : undefined);
584
+ } else {
585
+ this.$emit('change', inputValue, function (_ref3) {
586
+ var isOpen = _ref3.isOpen;
587
+ return _this2.triggerQuery({
588
+ defaultQuery: true,
589
+ customQuery: true,
590
+ value: inputValue,
591
+ isOpen: isOpen
592
+ });
593
+ }, e);
594
+ }
595
+ },
596
+ onSuggestionSelected: function onSuggestionSelected(suggestion) {
597
+ var _this3 = this;
598
+
599
+ this.isOpen = false;
600
+ var value = this.$props.value; // Record analytics for selected suggestions
601
+
602
+ this.triggerClickAnalytics(suggestion._click_id);
603
+
604
+ if (value === undefined) {
605
+ this.setValue(suggestion.value, true, this.$props, configureStore.causes.SUGGESTION_SELECT, false, suggestion._category);
606
+ } else {
607
+ this.$emit('change', suggestion.value, function (_ref4) {
608
+ var isOpen = _ref4.isOpen;
609
+ return _this3.triggerQuery({
610
+ isOpen: isOpen,
611
+ value: suggestion.value,
612
+ categoryValue: suggestion._category
613
+ });
614
+ });
615
+ }
616
+
617
+ this.onValueSelectedHandler(suggestion.value, configureStore.causes.SUGGESTION_SELECT, suggestion.source);
618
+ },
619
+ onValueSelectedHandler: function onValueSelectedHandler(currentValue) {
620
+ if (currentValue === void 0) {
621
+ currentValue = this.$data.currentValue;
622
+ }
623
+
624
+ for (var _len = arguments.length, cause = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
625
+ cause[_key - 1] = arguments[_key];
626
+ }
627
+
628
+ this.$emit.apply(this, ['valueSelected', currentValue].concat(cause));
629
+ this.$emit.apply(this, ['value-selected', currentValue].concat(cause));
630
+ },
631
+ handleStateChange: function handleStateChange(changes) {
632
+ var isOpen = changes.isOpen;
633
+ this.isOpen = isOpen;
634
+ },
635
+ getBackgroundColor: function getBackgroundColor(highlightedIndex, index) {
636
+ var isDark = this.themePreset === 'dark';
637
+
638
+ if (isDark) {
639
+ return highlightedIndex === index ? '#555' : '#424242';
640
+ }
641
+
642
+ return highlightedIndex === index ? '#eee' : '#fff';
643
+ },
644
+ renderIcon: function renderIcon() {
645
+ var h = this.$createElement;
646
+
647
+ if (this.$props.showIcon) {
648
+ return this.$props.icon || h(DataSearch.SearchSvg);
649
+ }
650
+
651
+ return null;
652
+ },
653
+ renderErrorComponent: function renderErrorComponent() {
654
+ var h = this.$createElement;
655
+ var renderError = this.$scopedSlots.renderError || this.$props.renderError;
656
+
657
+ if (this.error && renderError && this.$data.currentValue && !this.isLoading) {
658
+ return h(DataSearch.SuggestionWrapper, {
659
+ "attrs": {
660
+ "innerClass": this.$props.innerClass,
661
+ "innerClassName": "error",
662
+ "theme": this.theme,
663
+ "themePreset": this.themePreset
664
+ }
665
+ }, [index.isFunction(renderError) ? renderError(this.error) : renderError]);
666
+ }
667
+
668
+ return null;
669
+ },
670
+ renderCancelIcon: function renderCancelIcon() {
671
+ var h = this.$createElement;
672
+
673
+ if (this.$props.showClear) {
674
+ return this.$props.clearIcon || h(CancelSvg.CancelSvg);
675
+ }
676
+
677
+ return null;
678
+ },
679
+ renderNoSuggestions: function renderNoSuggestions(finalSuggestionsList) {
680
+ if (finalSuggestionsList === void 0) {
681
+ finalSuggestionsList = [];
682
+ }
683
+
684
+ var h = this.$createElement;
685
+ var _this$$props3 = this.$props,
686
+ theme = _this$$props3.theme,
687
+ innerClass = _this$$props3.innerClass;
688
+ var renderNoSuggestion = this.$scopedSlots.renderNoSuggestion || this.$props.renderNoSuggestion;
689
+ var renderError = this.$scopedSlots.renderError || this.$props.renderError;
690
+ var _this$$data = this.$data,
691
+ isOpen = _this$$data.isOpen,
692
+ currentValue = _this$$data.currentValue;
693
+
694
+ if (renderNoSuggestion && isOpen && !finalSuggestionsList.length && !this.isLoading && currentValue && !(renderError && this.error)) {
695
+ return h(DataSearch.SuggestionWrapper, {
696
+ "attrs": {
697
+ "innerClass": innerClass,
698
+ "themePreset": this.themePreset,
699
+ "theme": theme,
700
+ "innerClassName": "noSuggestion"
701
+ },
702
+ "scopedSlots": {
703
+ "default": function _default() {
704
+ return typeof renderNoSuggestion === 'function' ? renderNoSuggestion(currentValue) : renderNoSuggestion;
705
+ }
706
+ }
707
+ });
708
+ }
709
+
710
+ return null;
711
+ },
712
+ renderInputAddonBefore: function renderInputAddonBefore() {
713
+ var h = this.$createElement;
714
+ var addonBefore = this.$scopedSlots.addonBefore;
715
+
716
+ if (addonBefore) {
717
+ return h(DataSearch.InputAddon, {
718
+ "class": "addon-before"
719
+ }, [addonBefore()]);
720
+ }
721
+
722
+ return null;
723
+ },
724
+ renderInputAddonAfter: function renderInputAddonAfter() {
725
+ var h = this.$createElement;
726
+ var addonAfter = this.$scopedSlots.addonAfter;
727
+
728
+ if (addonAfter) {
729
+ return h(DataSearch.InputAddon, {
730
+ "class": "addon-after"
731
+ }, [addonAfter()]);
732
+ }
733
+
734
+ return null;
735
+ },
736
+ renderEnterButtonElement: function renderEnterButtonElement() {
737
+ var _this4 = this;
738
+
739
+ var h = this.$createElement;
740
+ var _this$$props4 = this.$props,
741
+ enterButton = _this$$props4.enterButton,
742
+ innerClass = _this$$props4.innerClass;
743
+ var renderEnterButton = this.$scopedSlots.renderEnterButton;
744
+
745
+ var enterButtonOnClick = function enterButtonOnClick() {
746
+ return _this4.triggerQuery({
747
+ isOpen: false,
748
+ value: _this4.currentValue,
749
+ customQuery: true
750
+ });
751
+ };
752
+
753
+ if (enterButton) {
754
+ var getEnterButtonMarkup = function getEnterButtonMarkup() {
755
+ if (renderEnterButton) {
756
+ return renderEnterButton(enterButtonOnClick);
757
+ }
758
+
759
+ return h(Button.Button, {
760
+ "class": "enter-btn " + getClassName(innerClass, 'enterButton'),
761
+ "attrs": {
762
+ "primary": true
763
+ },
764
+ "on": {
765
+ "click": enterButtonOnClick
766
+ }
767
+ }, ["Search"]);
768
+ };
769
+
770
+ return h("div", {
771
+ "class": "enter-button-wrapper"
772
+ }, [getEnterButtonMarkup()]);
773
+ }
774
+
775
+ return null;
776
+ },
777
+ renderIcons: function renderIcons() {
778
+ var h = this.$createElement;
779
+ var _this$$props5 = this.$props,
780
+ iconPosition = _this$$props5.iconPosition,
781
+ showClear = _this$$props5.showClear,
782
+ innerClass = _this$$props5.innerClass,
783
+ getMicInstance = _this$$props5.getMicInstance,
784
+ showVoiceSearch = _this$$props5.showVoiceSearch,
785
+ showIcon = _this$$props5.showIcon;
786
+ var renderMic = this.$scopedSlots.renderMic || this.$props.renderMic;
787
+ var currentValue = this.$data.currentValue;
788
+ return h("div", [h(CancelSvg.IconGroup, {
789
+ "attrs": {
790
+ "groupPosition": "right",
791
+ "positionType": "absolute"
792
+ }
793
+ }, [currentValue && showClear && h(CancelSvg.IconWrapper, {
794
+ "on": {
795
+ "click": this.clearValue
796
+ },
797
+ "attrs": {
798
+ "showIcon": showIcon,
799
+ "isClearIcon": true
800
+ }
801
+ }, [this.renderCancelIcon()]), showVoiceSearch && h(DataSearch.Mic, {
802
+ "attrs": {
803
+ "getInstance": getMicInstance,
804
+ "render": renderMic,
805
+ "handleResult": this.handleVoiceResults,
806
+ "className": getClassName(innerClass, 'mic') || null
807
+ }
808
+ }), iconPosition === 'right' && showIcon && h(CancelSvg.IconWrapper, {
809
+ "on": {
810
+ "click": this.handleSearchIconClick
811
+ }
812
+ }, [this.renderIcon()])]), h(CancelSvg.IconGroup, {
813
+ "attrs": {
814
+ "groupPosition": "left",
815
+ "positionType": "absolute"
816
+ }
817
+ }, [iconPosition === 'left' && showIcon && h(CancelSvg.IconWrapper, {
818
+ "on": {
819
+ "click": this.handleSearchIconClick
820
+ }
821
+ }, [this.renderIcon()])])]);
822
+ },
823
+ focusSearchBox: function focusSearchBox(event) {
824
+ var _this$$refs, _this$$refs$this$$pro;
825
+
826
+ var elt = event.target || event.srcElement;
827
+ var tagName = elt.tagName;
828
+
829
+ if (elt.isContentEditable || tagName === 'INPUT' || tagName === 'SELECT' || tagName === 'TEXTAREA') {
830
+ // already in an input
831
+ return;
832
+ }
833
+
834
+ (_this$$refs = this.$refs) == null ? void 0 : (_this$$refs$this$$pro = _this$$refs[this.$props.innerRef]) == null ? void 0 : _this$$refs$this$$pro.focus(); // eslint-disable-line
835
+ },
836
+ listenForFocusShortcuts: function listenForFocusShortcuts() {
837
+ var _this5 = this;
838
+
839
+ var _this$$props$focusSho = this.$props.focusShortcuts,
840
+ focusShortcuts = _this$$props$focusSho === void 0 ? ['/'] : _this$$props$focusSho;
841
+
842
+ if (index.isEmpty(focusShortcuts)) {
843
+ return;
844
+ }
845
+
846
+ var shortcutsString = index.parseFocusShortcuts(focusShortcuts).join(','); // handler for alphabets and other key combinations
847
+
848
+ hotkeys(shortcutsString, // eslint-disable-next-line no-unused-vars
849
+
850
+ /* eslint-disable no-shadow */
851
+ function (event, handler) {
852
+ // Prevent the default refresh event under WINDOWS system
853
+ event.preventDefault();
854
+
855
+ _this5.focusSearchBox(event);
856
+ }); // if one of modifier keys are used, they are handled below
857
+
858
+ hotkeys('*', function (event) {
859
+ var modifierKeys = index.extractModifierKeysFromFocusShortcuts(focusShortcuts);
860
+ if (modifierKeys.length === 0) return;
861
+
862
+ for (var index$1 = 0; index$1 < modifierKeys.length; index$1 += 1) {
863
+ var element = modifierKeys[index$1];
864
+
865
+ if (hotkeys[element]) {
866
+ _this5.focusSearchBox(event);
867
+
868
+ break;
869
+ }
870
+ }
871
+ });
872
+ },
873
+ onAutofillClick: function onAutofillClick(suggestion) {
874
+ var value = suggestion.value;
875
+ this.isOpen = true;
876
+ this.currentValue = value;
877
+ this.triggerDefaultQuery(value);
878
+ },
879
+ renderAutoFill: function renderAutoFill(suggestion) {
880
+ var _this6 = this;
881
+
882
+ var h = this.$createElement;
883
+
884
+ var handleAutoFillClick = function handleAutoFillClick(e) {
885
+ e.stopPropagation();
886
+
887
+ _this6.onAutofillClick(suggestion);
888
+ };
889
+ /* 👇 avoid showing autofill for category suggestions👇 */
890
+
891
+
892
+ return suggestion._category ? null : h(AutoFillSvg, {
893
+ "on": {
894
+ "click": handleAutoFillClick
895
+ }
896
+ });
897
+ }
898
+ },
899
+ render: function render() {
900
+ var _this7 = this;
901
+
902
+ var h = arguments[0];
903
+ var _this$$props6 = this.$props,
904
+ theme = _this$$props6.theme,
905
+ expandSuggestionsContainer = _this$$props6.expandSuggestionsContainer;
906
+ var _this$$scopedSlots = this.$scopedSlots,
907
+ recentSearchesIcon = _this$$scopedSlots.recentSearchesIcon,
908
+ popularSearchesIcon = _this$$scopedSlots.popularSearchesIcon;
909
+ var hasSuggestions = Array.isArray(this.normalizedSuggestions) && this.normalizedSuggestions.length;
910
+ var renderItem = this.$scopedSlots.renderItem || this.$props.renderItem;
911
+ return h(Container.Container, {
912
+ "class": this.$props.className
913
+ }, [this.$props.title && h(Title.Title, {
914
+ "class": getClassName(this.$props.innerClass, 'title') || ''
915
+ }, [this.$props.title]), this.$props.autosuggest ? h(CancelSvg.Downshift, {
916
+ "attrs": {
917
+ "id": this.$props.componentId + "-downshift",
918
+ "handleChange": this.onSuggestionSelected,
919
+ "handleMouseup": this.handleStateChange,
920
+ "isOpen": this.$data.isOpen
921
+ },
922
+ "scopedSlots": {
923
+ "default": function _default(_ref5) {
924
+ var getInputEvents = _ref5.getInputEvents,
925
+ getInputProps = _ref5.getInputProps,
926
+ getItemProps = _ref5.getItemProps,
927
+ getItemEvents = _ref5.getItemEvents,
928
+ isOpen = _ref5.isOpen,
929
+ highlightedIndex = _ref5.highlightedIndex,
930
+ setHighlightedIndex = _ref5.setHighlightedIndex;
931
+
932
+ var renderSuggestionsDropdown = function renderSuggestionsDropdown() {
933
+ var getIcon = function getIcon(iconType) {
934
+ switch (iconType) {
935
+ case helper.suggestionTypes.Recent:
936
+ return recentSearchesIcon;
937
+
938
+ case helper.suggestionTypes.Popular:
939
+ return popularSearchesIcon;
940
+
941
+ default:
942
+ return null;
943
+ }
944
+ };
945
+
946
+ return h("div", [_this7.hasCustomRenderer && _this7.getComponent({
947
+ isOpen: isOpen,
948
+ getItemProps: getItemProps,
949
+ getItemEvents: getItemEvents,
950
+ highlightedIndex: highlightedIndex
951
+ }), _this7.renderErrorComponent(), !_this7.hasCustomRenderer && isOpen && hasSuggestions ? h("ul", {
952
+ "class": Input.suggestions(_this7.themePreset, theme) + " " + getClassName(_this7.$props.innerClass, 'list')
953
+ }, [_this7.normalizedSuggestions.map(function (item, index) {
954
+ return renderItem ? h("li", {
955
+ "domProps": _rollupPluginBabelHelpers._extends({}, getItemProps({
956
+ item: item
957
+ })),
958
+ "on": _rollupPluginBabelHelpers._extends({}, getItemEvents({
959
+ item: item
960
+ })),
961
+ "key": index + 1 + "-" + item.value,
962
+ "style": {
963
+ backgroundColor: _this7.getBackgroundColor(highlightedIndex, index),
964
+ justifyContent: 'flex-start',
965
+ alignItems: 'center'
966
+ }
967
+ }, [renderItem(item)]) : h("li", {
968
+ "domProps": _rollupPluginBabelHelpers._extends({}, getItemProps({
969
+ item: item
970
+ })),
971
+ "on": _rollupPluginBabelHelpers._extends({}, getItemEvents({
972
+ item: item
973
+ })),
974
+ "key": index + 1 + "-" + item.value,
975
+ "style": {
976
+ backgroundColor: _this7.getBackgroundColor(highlightedIndex, index),
977
+ justifyContent: 'flex-start',
978
+ alignItems: 'center'
979
+ }
980
+ }, [h("div", {
981
+ "style": {
982
+ padding: '0 10px 0 0',
983
+ display: 'flex'
984
+ }
985
+ }, [h(DataSearch.CustomSvg, {
986
+ "attrs": {
987
+ "className": getClassName(_this7.$props.innerClass, item._suggestion_type + "-search-icon") || null,
988
+ "icon": getIcon(item._suggestion_type),
989
+ "type": item._suggestion_type + "-search-icon"
990
+ }
991
+ })]), h(DataSearch.SuggestionItem, {
992
+ "attrs": {
993
+ "currentValue": _this7.currentValue,
994
+ "suggestion": item
995
+ }
996
+ }), _this7.renderAutoFill(item)]);
997
+ })]) : _this7.renderNoSuggestions(_this7.normalizedSuggestions)]);
998
+ };
999
+
1000
+ return h("div", {
1001
+ "class": Input.suggestionsContainer
1002
+ }, [h(DataSearch.InputGroup, [_this7.renderInputAddonBefore(), h(CancelSvg.InputWrapper, [h(Input.Input, {
1003
+ "attrs": {
1004
+ "id": _this7.$props.componentId + "-input",
1005
+ "showIcon": _this7.$props.showIcon,
1006
+ "showClear": _this7.$props.showClear,
1007
+ "iconPosition": _this7.$props.iconPosition,
1008
+ "placeholder": _this7.$props.placeholder,
1009
+ "autoFocus": _this7.$props.autoFocus,
1010
+ "themePreset": _this7.themePreset,
1011
+ "autocomplete": "off"
1012
+ },
1013
+ "ref": _this7.$props.innerRef,
1014
+ "class": getClassName(_this7.$props.innerClass, 'input'),
1015
+ "on": _rollupPluginBabelHelpers._extends({}, getInputEvents({
1016
+ onInput: _this7.onInputChange,
1017
+ onBlur: function onBlur(e) {
1018
+ _this7.$emit('blur', e, _this7.triggerQuery);
1019
+ },
1020
+ onFocus: _this7.handleFocus,
1021
+ onKeyPress: function onKeyPress(e) {
1022
+ _this7.$emit('keyPress', e, _this7.triggerQuery);
1023
+
1024
+ _this7.$emit('key-press', e, _this7.triggerQuery);
1025
+ },
1026
+ onKeyDown: function onKeyDown(e) {
1027
+ return _this7.handleKeyDown(e, highlightedIndex);
1028
+ },
1029
+ onKeyUp: function onKeyUp(e) {
1030
+ _this7.$emit('keyUp', e, _this7.triggerQuery);
1031
+
1032
+ _this7.$emit('key-up', e, _this7.triggerQuery);
1033
+ },
1034
+ onClick: function onClick() {
1035
+ setHighlightedIndex(null);
1036
+ }
1037
+ })),
1038
+ "domProps": _rollupPluginBabelHelpers._extends({}, getInputProps({
1039
+ value: _this7.$data.currentValue === null ? '' : _this7.$data.currentValue
1040
+ }))
1041
+ }), _this7.renderIcons(), !expandSuggestionsContainer && renderSuggestionsDropdown()]), _this7.renderInputAddonAfter(), _this7.renderEnterButtonElement()]), expandSuggestionsContainer && renderSuggestionsDropdown()]);
1042
+ }
1043
+ }
1044
+ }) : h("div", {
1045
+ "class": Input.suggestionsContainer
1046
+ }, [h(DataSearch.InputGroup, [this.renderInputAddonBefore(), h(CancelSvg.InputWrapper, [h(Input.Input, {
1047
+ "class": getClassName(this.$props.innerClass, 'input') || '',
1048
+ "attrs": {
1049
+ "placeholder": this.$props.placeholder,
1050
+ "iconPosition": this.$props.iconPosition,
1051
+ "showIcon": this.$props.showIcon,
1052
+ "showClear": this.$props.showClear,
1053
+ "themePreset": this.themePreset
1054
+ },
1055
+ "on": _rollupPluginBabelHelpers._extends({}, {
1056
+ blur: function blur(e) {
1057
+ _this7.$emit('blur', e, _this7.triggerQuery);
1058
+ },
1059
+ keypress: function keypress(e) {
1060
+ _this7.$emit('keyPress', e, _this7.triggerQuery);
1061
+
1062
+ _this7.$emit('key-press', e, _this7.triggerQuery);
1063
+ },
1064
+ input: this.onInputChange,
1065
+ focus: function focus(e) {
1066
+ _this7.$emit('focus', e, _this7.triggerQuery);
1067
+ },
1068
+ keydown: function keydown(e) {
1069
+ _this7.$emit('keyDown', e, _this7.triggerQuery);
1070
+
1071
+ _this7.$emit('key-down', e, _this7.triggerQuery);
1072
+ },
1073
+ keyup: function keyup(e) {
1074
+ _this7.$emit('keyUp', e, _this7.triggerQuery);
1075
+
1076
+ _this7.$emit('key-up', e, _this7.triggerQuery);
1077
+ }
1078
+ }),
1079
+ "domProps": _rollupPluginBabelHelpers._extends({}, {
1080
+ autofocus: this.$props.autoFocus,
1081
+ value: this.$data.currentValue ? this.$data.currentValue : ''
1082
+ }),
1083
+ "ref": this.$props.innerRef
1084
+ }), this.renderIcons()]), this.renderInputAddonAfter(), this.renderEnterButtonElement()])])]);
1085
+ },
1086
+ destroyed: function destroyed() {
1087
+ document.removeEventListener('keydown', this.onKeyDown);
1088
+ }
1089
+ };
1090
+
1091
+ SearchBox.defaultQuery = function (value, props) {
1092
+ var finalQuery = null;
1093
+ var fields = normalizeDataField(props.dataField, props.fieldWeights);
1094
+ finalQuery = {
1095
+ bool: {
1096
+ should: SearchBox.shouldQuery(value, fields, props),
1097
+ minimum_should_match: '1'
1098
+ }
1099
+ };
1100
+
1101
+ if (finalQuery && props.nestedField) {
1102
+ return {
1103
+ query: {
1104
+ nested: {
1105
+ path: props.nestedField,
1106
+ query: finalQuery
1107
+ }
1108
+ }
1109
+ };
1110
+ }
1111
+
1112
+ return finalQuery;
1113
+ };
1114
+
1115
+ SearchBox.shouldQuery = function (value, dataFields, props) {
1116
+ var finalQuery = [];
1117
+ var phrasePrefixFields = [];
1118
+ var fields = dataFields.map(function (dataField) {
1119
+ var queryField = "" + dataField.field + (dataField.weight ? "^" + dataField.weight : '');
1120
+
1121
+ if (!(dataField.field.endsWith('.keyword') || dataField.field.endsWith('.autosuggest') || dataField.field.endsWith('.search'))) {
1122
+ phrasePrefixFields.push(queryField);
1123
+ }
1124
+
1125
+ return queryField;
1126
+ });
1127
+
1128
+ if (props.searchOperators || props.queryString) {
1129
+ return {
1130
+ query: value,
1131
+ fields: fields,
1132
+ default_operator: props.queryFormat
1133
+ };
1134
+ }
1135
+
1136
+ if (props.queryFormat === 'and') {
1137
+ finalQuery.push({
1138
+ multi_match: {
1139
+ query: value,
1140
+ fields: fields,
1141
+ type: 'cross_fields',
1142
+ operator: 'and'
1143
+ }
1144
+ });
1145
+ finalQuery.push({
1146
+ multi_match: {
1147
+ query: value,
1148
+ fields: fields,
1149
+ type: 'phrase',
1150
+ operator: 'and'
1151
+ }
1152
+ });
1153
+
1154
+ if (phrasePrefixFields.length > 0) {
1155
+ finalQuery.push({
1156
+ multi_match: {
1157
+ query: value,
1158
+ fields: phrasePrefixFields,
1159
+ type: 'phrase_prefix',
1160
+ operator: 'and'
1161
+ }
1162
+ });
1163
+ }
1164
+
1165
+ return finalQuery;
1166
+ }
1167
+
1168
+ finalQuery.push({
1169
+ multi_match: {
1170
+ query: value,
1171
+ fields: fields,
1172
+ type: 'best_fields',
1173
+ operator: 'or',
1174
+ fuzziness: props.fuzziness ? props.fuzziness : 0
1175
+ }
1176
+ });
1177
+ finalQuery.push({
1178
+ multi_match: {
1179
+ query: value,
1180
+ fields: fields,
1181
+ type: 'phrase',
1182
+ operator: 'or'
1183
+ }
1184
+ });
1185
+
1186
+ if (phrasePrefixFields.length > 0) {
1187
+ finalQuery.push({
1188
+ multi_match: {
1189
+ query: value,
1190
+ fields: phrasePrefixFields,
1191
+ type: 'phrase_prefix',
1192
+ operator: 'or'
1193
+ }
1194
+ });
1195
+ }
1196
+
1197
+ return finalQuery;
1198
+ };
1199
+
1200
+ var mapStateToProps = function mapStateToProps(state, props) {
1201
+ return {
1202
+ selectedValue: state.selectedValues[props.componentId] && state.selectedValues[props.componentId].value || null,
1203
+ selectedCategory: state.selectedValues[props.componentId] && state.selectedValues[props.componentId].category || null,
1204
+ suggestions: state.hits[props.componentId] && state.hits[props.componentId].hits,
1205
+ rawData: state.rawData[props.componentId],
1206
+ aggregationData: state.compositeAggregations[props.componentId] || [],
1207
+ themePreset: state.config.themePreset,
1208
+ isLoading: !!state.isLoading[props.componentId + "_active"],
1209
+ error: state.error[props.componentId],
1210
+ enableAppbase: state.config.enableAppbase,
1211
+ time: state.hits[props.componentId] && state.hits[props.componentId].time || 0,
1212
+ total: state.hits[props.componentId] && state.hits[props.componentId].total,
1213
+ hidden: state.hits[props.componentId] && state.hits[props.componentId].hidden
1214
+ };
1215
+ };
1216
+
1217
+ var mapDispatchToProps = {
1218
+ updateQuery: updateQuery,
1219
+ setCustomQuery: setCustomQuery,
1220
+ setDefaultQuery: setDefaultQuery,
1221
+ recordSuggestionClick: recordSuggestionClick
1222
+ };
1223
+ var DSConnected = ComponentWrapper.ComponentWrapper(index.connect(mapStateToProps, mapDispatchToProps)(SearchBox), {
1224
+ componentType: constants.componentTypes.searchBox,
1225
+ internalComponent: true
1226
+ });
1227
+
1228
+ SearchBox.install = function (Vue) {
1229
+ Vue.component(SearchBox.name, DSConnected);
1230
+ }; // Add componentType for SSR
1231
+
1232
+
1233
+ SearchBox.componentType = constants.componentTypes.searchBox;
1234
+
1235
+ var components = [ReactiveList.default, ResultCard.default, ResultList.default, ReactiveBase.default, DataSearch.DataSearch, SearchBox, SingleList.default, MultiList.default, SingleRange.default, MultiRange.default, RangeSlider.default, DynamicRangeSlider.default, ReactiveComponent.default, SelectedFilters.default, ToggleButton.default, SingleDropdownList.default, MultiDropdownList.default, StateProvider.default, RangeInput.default];
1236
+ function install (Vue) {
1237
+ components.map(function (component) {
1238
+ Vue.use(component);
1239
+ return null;
1240
+ });
1241
+ }
1242
+
1243
+ exports.SearchBox = SearchBox;
1244
+ exports.install = install;