@appbaseio/reactivesearch-vue 1.26.0 → 1.27.0-gamma.1

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