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

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 +1691 -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-0ef14926.js +2154 -0
  7. package/dist/cjs/DataSearch.js +18 -2101
  8. package/dist/cjs/{DropDown-cf9bfffc.js → DropDown-e4381fcc.js} +16 -11
  9. package/dist/cjs/DynamicRangeSlider.js +40 -7
  10. package/dist/cjs/{Input-3cc3fa59.js → Input-0d7b25ad.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-311df9cc.js +1200 -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-be45e960.js +2141 -0
  32. package/dist/es/DataSearch.js +17 -2100
  33. package/dist/es/{DropDown-c8da0a2c.js → DropDown-ff6ad982.js} +16 -11
  34. package/dist/es/DynamicRangeSlider.js +40 -7
  35. package/dist/es/{Input-08bb1bcf.js → Input-e339e63a.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-af797de0.js +1193 -0
  53. package/dist/es/install.js +23 -32
  54. package/dist/es/version.js +1 -1
  55. package/package.json +4 -4
@@ -0,0 +1,1193 @@
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-be45e960.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-e339e63a.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, {
709
+ "class": "addon-before"
710
+ }, [addonBefore()]);
711
+ }
712
+
713
+ return null;
714
+ },
715
+ renderInputAddonAfter: function renderInputAddonAfter() {
716
+ var h = this.$createElement;
717
+ var addonAfter = this.$scopedSlots.addonAfter;
718
+
719
+ if (addonAfter) {
720
+ return h(InputAddon, {
721
+ "class": "addon-after"
722
+ }, [addonAfter()]);
723
+ }
724
+
725
+ return null;
726
+ },
727
+ renderIcons: function renderIcons() {
728
+ var h = this.$createElement;
729
+ var _this$$props4 = this.$props,
730
+ iconPosition = _this$$props4.iconPosition,
731
+ showClear = _this$$props4.showClear,
732
+ innerClass = _this$$props4.innerClass,
733
+ getMicInstance = _this$$props4.getMicInstance,
734
+ showVoiceSearch = _this$$props4.showVoiceSearch,
735
+ showIcon = _this$$props4.showIcon;
736
+ var renderMic = this.$scopedSlots.renderMic || this.$props.renderMic;
737
+ var currentValue = this.$data.currentValue;
738
+ return h("div", [h(IconGroup, {
739
+ "attrs": {
740
+ "groupPosition": "right",
741
+ "positionType": "absolute"
742
+ }
743
+ }, [currentValue && showClear && h(IconWrapper, {
744
+ "on": {
745
+ "click": this.clearValue
746
+ },
747
+ "attrs": {
748
+ "showIcon": showIcon,
749
+ "isClearIcon": true
750
+ }
751
+ }, [this.renderCancelIcon()]), showVoiceSearch && h(Mic, {
752
+ "attrs": {
753
+ "getInstance": getMicInstance,
754
+ "render": renderMic,
755
+ "handleResult": this.handleVoiceResults,
756
+ "className": getClassName(innerClass, 'mic') || null
757
+ }
758
+ }), iconPosition === 'right' && showIcon && h(IconWrapper, {
759
+ "on": {
760
+ "click": this.handleSearchIconClick
761
+ }
762
+ }, [this.renderIcon()])]), h(IconGroup, {
763
+ "attrs": {
764
+ "groupPosition": "left",
765
+ "positionType": "absolute"
766
+ }
767
+ }, [iconPosition === 'left' && showIcon && h(IconWrapper, {
768
+ "on": {
769
+ "click": this.handleSearchIconClick
770
+ }
771
+ }, [this.renderIcon()])])]);
772
+ },
773
+ focusSearchBox: function focusSearchBox(event) {
774
+ var _this$$refs, _this$$refs$this$$pro;
775
+
776
+ var elt = event.target || event.srcElement;
777
+ var tagName = elt.tagName;
778
+
779
+ if (elt.isContentEditable || tagName === 'INPUT' || tagName === 'SELECT' || tagName === 'TEXTAREA') {
780
+ // already in an input
781
+ return;
782
+ }
783
+
784
+ (_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
785
+ },
786
+ listenForFocusShortcuts: function listenForFocusShortcuts() {
787
+ var _this4 = this;
788
+
789
+ var _this$$props$focusSho = this.$props.focusShortcuts,
790
+ focusShortcuts = _this$$props$focusSho === void 0 ? ['/'] : _this$$props$focusSho;
791
+
792
+ if (isEmpty(focusShortcuts)) {
793
+ return;
794
+ }
795
+
796
+ var shortcutsString = parseFocusShortcuts(focusShortcuts).join(','); // handler for alphabets and other key combinations
797
+
798
+ hotkeys(shortcutsString, // eslint-disable-next-line no-unused-vars
799
+
800
+ /* eslint-disable no-shadow */
801
+ function (event, handler) {
802
+ // Prevent the default refresh event under WINDOWS system
803
+ event.preventDefault();
804
+
805
+ _this4.focusSearchBox(event);
806
+ }); // if one of modifier keys are used, they are handled below
807
+
808
+ hotkeys('*', function (event) {
809
+ var modifierKeys = extractModifierKeysFromFocusShortcuts(focusShortcuts);
810
+ if (modifierKeys.length === 0) return;
811
+
812
+ for (var index = 0; index < modifierKeys.length; index += 1) {
813
+ var element = modifierKeys[index];
814
+
815
+ if (hotkeys[element]) {
816
+ _this4.focusSearchBox(event);
817
+
818
+ break;
819
+ }
820
+ }
821
+ });
822
+ },
823
+ onAutofillClick: function onAutofillClick(suggestion) {
824
+ var value = suggestion.value;
825
+ this.isOpen = true;
826
+ this.currentValue = value;
827
+ this.triggerDefaultQuery(value);
828
+ },
829
+ renderAutoFill: function renderAutoFill(suggestion) {
830
+ var _this5 = this;
831
+
832
+ var h = this.$createElement;
833
+
834
+ var handleAutoFillClick = function handleAutoFillClick(e) {
835
+ e.stopPropagation();
836
+
837
+ _this5.onAutofillClick(suggestion);
838
+ };
839
+ /* 👇 avoid showing autofill for category suggestions👇 */
840
+
841
+
842
+ return suggestion._category ? null : h(AutoFillSvg, {
843
+ "on": {
844
+ "click": handleAutoFillClick
845
+ }
846
+ });
847
+ }
848
+ },
849
+ render: function render() {
850
+ var _this6 = this;
851
+
852
+ var h = arguments[0];
853
+ var _this$$props5 = this.$props,
854
+ theme = _this$$props5.theme,
855
+ expandSuggestionsContainer = _this$$props5.expandSuggestionsContainer;
856
+ var _this$$scopedSlots = this.$scopedSlots,
857
+ recentSearchesIcon = _this$$scopedSlots.recentSearchesIcon,
858
+ popularSearchesIcon = _this$$scopedSlots.popularSearchesIcon;
859
+ var hasSuggestions = Array.isArray(this.normalizedSuggestions) && this.normalizedSuggestions.length;
860
+ var renderItem = this.$scopedSlots.renderItem || this.$props.renderItem;
861
+ return h(Container, {
862
+ "class": this.$props.className
863
+ }, [this.$props.title && h(Title, {
864
+ "class": getClassName(this.$props.innerClass, 'title') || ''
865
+ }, [this.$props.title]), this.$props.autosuggest ? h(Downshift, {
866
+ "attrs": {
867
+ "id": this.$props.componentId + "-downshift",
868
+ "handleChange": this.onSuggestionSelected,
869
+ "handleMouseup": this.handleStateChange,
870
+ "isOpen": this.$data.isOpen
871
+ },
872
+ "scopedSlots": {
873
+ "default": function _default(_ref5) {
874
+ var getInputEvents = _ref5.getInputEvents,
875
+ getInputProps = _ref5.getInputProps,
876
+ getItemProps = _ref5.getItemProps,
877
+ getItemEvents = _ref5.getItemEvents,
878
+ isOpen = _ref5.isOpen,
879
+ highlightedIndex = _ref5.highlightedIndex,
880
+ setHighlightedIndex = _ref5.setHighlightedIndex;
881
+
882
+ var renderSuggestionsDropdown = function renderSuggestionsDropdown() {
883
+ var getIcon = function getIcon(iconType) {
884
+ switch (iconType) {
885
+ case suggestionTypes.Recent:
886
+ return recentSearchesIcon;
887
+
888
+ case suggestionTypes.Popular:
889
+ return popularSearchesIcon;
890
+
891
+ default:
892
+ return null;
893
+ }
894
+ };
895
+
896
+ return h("div", [_this6.hasCustomRenderer && _this6.getComponent({
897
+ isOpen: isOpen,
898
+ getItemProps: getItemProps,
899
+ getItemEvents: getItemEvents,
900
+ highlightedIndex: highlightedIndex
901
+ }), _this6.renderErrorComponent(), !_this6.hasCustomRenderer && isOpen && hasSuggestions ? h("ul", {
902
+ "class": suggestions(_this6.themePreset, theme) + " " + getClassName(_this6.$props.innerClass, 'list')
903
+ }, [_this6.normalizedSuggestions.map(function (item, index) {
904
+ return renderItem ? h("li", {
905
+ "domProps": _extends({}, getItemProps({
906
+ item: item
907
+ })),
908
+ "on": _extends({}, getItemEvents({
909
+ item: item
910
+ })),
911
+ "key": index + 1 + "-" + item.value,
912
+ "style": {
913
+ backgroundColor: _this6.getBackgroundColor(highlightedIndex, index),
914
+ justifyContent: 'flex-start',
915
+ alignItems: 'center'
916
+ }
917
+ }, [renderItem(item)]) : h("li", {
918
+ "domProps": _extends({}, getItemProps({
919
+ item: item
920
+ })),
921
+ "on": _extends({}, getItemEvents({
922
+ item: item
923
+ })),
924
+ "key": index + 1 + "-" + item.value,
925
+ "style": {
926
+ backgroundColor: _this6.getBackgroundColor(highlightedIndex, index),
927
+ justifyContent: 'flex-start',
928
+ alignItems: 'center'
929
+ }
930
+ }, [h("div", {
931
+ "style": {
932
+ padding: '0 10px 0 0',
933
+ display: 'flex'
934
+ }
935
+ }, [h(CustomSvg, {
936
+ "attrs": {
937
+ "className": getClassName(_this6.$props.innerClass, item._suggestion_type + "-search-icon") || null,
938
+ "icon": getIcon(item._suggestion_type),
939
+ "type": item._suggestion_type + "-search-icon"
940
+ }
941
+ })]), h(SuggestionItem, {
942
+ "attrs": {
943
+ "currentValue": _this6.currentValue,
944
+ "suggestion": item
945
+ }
946
+ }), _this6.renderAutoFill(item)]);
947
+ })]) : _this6.renderNoSuggestions(_this6.normalizedSuggestions)]);
948
+ };
949
+
950
+ return h("div", {
951
+ "class": suggestionsContainer
952
+ }, [h(InputGroup, [_this6.renderInputAddonBefore(), h(InputWrapper, [h(Input, {
953
+ "attrs": {
954
+ "id": _this6.$props.componentId + "-input",
955
+ "showIcon": _this6.$props.showIcon,
956
+ "showClear": _this6.$props.showClear,
957
+ "iconPosition": _this6.$props.iconPosition,
958
+ "placeholder": _this6.$props.placeholder,
959
+ "autoFocus": _this6.$props.autoFocus,
960
+ "themePreset": _this6.themePreset,
961
+ "autocomplete": "off"
962
+ },
963
+ "ref": _this6.$props.innerRef,
964
+ "class": getClassName(_this6.$props.innerClass, 'input'),
965
+ "on": _extends({}, getInputEvents({
966
+ onInput: _this6.onInputChange,
967
+ onBlur: function onBlur(e) {
968
+ _this6.$emit('blur', e, _this6.triggerQuery);
969
+ },
970
+ onFocus: _this6.handleFocus,
971
+ onKeyPress: function onKeyPress(e) {
972
+ _this6.$emit('keyPress', e, _this6.triggerQuery);
973
+
974
+ _this6.$emit('key-press', e, _this6.triggerQuery);
975
+ },
976
+ onKeyDown: function onKeyDown(e) {
977
+ return _this6.handleKeyDown(e, highlightedIndex);
978
+ },
979
+ onKeyUp: function onKeyUp(e) {
980
+ _this6.$emit('keyUp', e, _this6.triggerQuery);
981
+
982
+ _this6.$emit('key-up', e, _this6.triggerQuery);
983
+ },
984
+ onClick: function onClick() {
985
+ setHighlightedIndex(null);
986
+ }
987
+ })),
988
+ "domProps": _extends({}, getInputProps({
989
+ value: _this6.$data.currentValue === null ? '' : _this6.$data.currentValue
990
+ }))
991
+ }), _this6.renderIcons(), !expandSuggestionsContainer && renderSuggestionsDropdown()]), _this6.renderInputAddonAfter()]), expandSuggestionsContainer && renderSuggestionsDropdown()]);
992
+ }
993
+ }
994
+ }) : h("div", {
995
+ "class": suggestionsContainer
996
+ }, [h(InputGroup, [this.renderInputAddonBefore(), h(InputWrapper, [h(Input, {
997
+ "class": getClassName(this.$props.innerClass, 'input') || '',
998
+ "attrs": {
999
+ "placeholder": this.$props.placeholder,
1000
+ "iconPosition": this.$props.iconPosition,
1001
+ "showIcon": this.$props.showIcon,
1002
+ "showClear": this.$props.showClear,
1003
+ "themePreset": this.themePreset
1004
+ },
1005
+ "on": _extends({}, {
1006
+ blur: function blur(e) {
1007
+ _this6.$emit('blur', e, _this6.triggerQuery);
1008
+ },
1009
+ keypress: function keypress(e) {
1010
+ _this6.$emit('keyPress', e, _this6.triggerQuery);
1011
+
1012
+ _this6.$emit('key-press', e, _this6.triggerQuery);
1013
+ },
1014
+ input: this.onInputChange,
1015
+ focus: function focus(e) {
1016
+ _this6.$emit('focus', e, _this6.triggerQuery);
1017
+ },
1018
+ keydown: function keydown(e) {
1019
+ _this6.$emit('keyDown', e, _this6.triggerQuery);
1020
+
1021
+ _this6.$emit('key-down', e, _this6.triggerQuery);
1022
+ },
1023
+ keyup: function keyup(e) {
1024
+ _this6.$emit('keyUp', e, _this6.triggerQuery);
1025
+
1026
+ _this6.$emit('key-up', e, _this6.triggerQuery);
1027
+ }
1028
+ }),
1029
+ "domProps": _extends({}, {
1030
+ autofocus: this.$props.autoFocus,
1031
+ value: this.$data.currentValue ? this.$data.currentValue : ''
1032
+ }),
1033
+ "ref": this.$props.innerRef
1034
+ }), this.renderIcons()]), this.renderInputAddonAfter()])])]);
1035
+ },
1036
+ destroyed: function destroyed() {
1037
+ document.removeEventListener('keydown', this.onKeyDown);
1038
+ }
1039
+ };
1040
+
1041
+ SearchBox.defaultQuery = function (value, props) {
1042
+ var finalQuery = null;
1043
+ var fields = normalizeDataField(props.dataField, props.fieldWeights);
1044
+ finalQuery = {
1045
+ bool: {
1046
+ should: SearchBox.shouldQuery(value, fields, props),
1047
+ minimum_should_match: '1'
1048
+ }
1049
+ };
1050
+
1051
+ if (finalQuery && props.nestedField) {
1052
+ return {
1053
+ query: {
1054
+ nested: {
1055
+ path: props.nestedField,
1056
+ query: finalQuery
1057
+ }
1058
+ }
1059
+ };
1060
+ }
1061
+
1062
+ return finalQuery;
1063
+ };
1064
+
1065
+ SearchBox.shouldQuery = function (value, dataFields, props) {
1066
+ var finalQuery = [];
1067
+ var phrasePrefixFields = [];
1068
+ var fields = dataFields.map(function (dataField) {
1069
+ var queryField = "" + dataField.field + (dataField.weight ? "^" + dataField.weight : '');
1070
+
1071
+ if (!(dataField.field.endsWith('.keyword') || dataField.field.endsWith('.autosuggest') || dataField.field.endsWith('.search'))) {
1072
+ phrasePrefixFields.push(queryField);
1073
+ }
1074
+
1075
+ return queryField;
1076
+ });
1077
+
1078
+ if (props.searchOperators || props.queryString) {
1079
+ return {
1080
+ query: value,
1081
+ fields: fields,
1082
+ default_operator: props.queryFormat
1083
+ };
1084
+ }
1085
+
1086
+ if (props.queryFormat === 'and') {
1087
+ finalQuery.push({
1088
+ multi_match: {
1089
+ query: value,
1090
+ fields: fields,
1091
+ type: 'cross_fields',
1092
+ operator: 'and'
1093
+ }
1094
+ });
1095
+ finalQuery.push({
1096
+ multi_match: {
1097
+ query: value,
1098
+ fields: fields,
1099
+ type: 'phrase',
1100
+ operator: 'and'
1101
+ }
1102
+ });
1103
+
1104
+ if (phrasePrefixFields.length > 0) {
1105
+ finalQuery.push({
1106
+ multi_match: {
1107
+ query: value,
1108
+ fields: phrasePrefixFields,
1109
+ type: 'phrase_prefix',
1110
+ operator: 'and'
1111
+ }
1112
+ });
1113
+ }
1114
+
1115
+ return finalQuery;
1116
+ }
1117
+
1118
+ finalQuery.push({
1119
+ multi_match: {
1120
+ query: value,
1121
+ fields: fields,
1122
+ type: 'best_fields',
1123
+ operator: 'or',
1124
+ fuzziness: props.fuzziness ? props.fuzziness : 0
1125
+ }
1126
+ });
1127
+ finalQuery.push({
1128
+ multi_match: {
1129
+ query: value,
1130
+ fields: fields,
1131
+ type: 'phrase',
1132
+ operator: 'or'
1133
+ }
1134
+ });
1135
+
1136
+ if (phrasePrefixFields.length > 0) {
1137
+ finalQuery.push({
1138
+ multi_match: {
1139
+ query: value,
1140
+ fields: phrasePrefixFields,
1141
+ type: 'phrase_prefix',
1142
+ operator: 'or'
1143
+ }
1144
+ });
1145
+ }
1146
+
1147
+ return finalQuery;
1148
+ };
1149
+
1150
+ var mapStateToProps = function mapStateToProps(state, props) {
1151
+ return {
1152
+ selectedValue: state.selectedValues[props.componentId] && state.selectedValues[props.componentId].value || null,
1153
+ selectedCategory: state.selectedValues[props.componentId] && state.selectedValues[props.componentId].category || null,
1154
+ suggestions: state.hits[props.componentId] && state.hits[props.componentId].hits,
1155
+ rawData: state.rawData[props.componentId],
1156
+ aggregationData: state.compositeAggregations[props.componentId] || [],
1157
+ themePreset: state.config.themePreset,
1158
+ isLoading: !!state.isLoading[props.componentId + "_active"],
1159
+ error: state.error[props.componentId],
1160
+ enableAppbase: state.config.enableAppbase,
1161
+ time: state.hits[props.componentId] && state.hits[props.componentId].time || 0,
1162
+ total: state.hits[props.componentId] && state.hits[props.componentId].total,
1163
+ hidden: state.hits[props.componentId] && state.hits[props.componentId].hidden
1164
+ };
1165
+ };
1166
+
1167
+ var mapDispatchToProps = {
1168
+ updateQuery: updateQuery,
1169
+ setCustomQuery: setCustomQuery,
1170
+ setDefaultQuery: setDefaultQuery,
1171
+ recordSuggestionClick: recordSuggestionClick
1172
+ };
1173
+ var DSConnected = ComponentWrapper(connect(mapStateToProps, mapDispatchToProps)(SearchBox), {
1174
+ componentType: componentTypes.searchBox,
1175
+ internalComponent: true
1176
+ });
1177
+
1178
+ SearchBox.install = function (Vue) {
1179
+ Vue.component(SearchBox.name, DSConnected);
1180
+ }; // Add componentType for SSR
1181
+
1182
+
1183
+ SearchBox.componentType = componentTypes.searchBox;
1184
+
1185
+ var components = [ReactiveList, ResultCard, ResultList, ReactiveBase, DataSearch, SearchBox, SingleList, MultiList, SingleRange, MultiRange, RangeSlider, DynamicRangeSlider, ReactiveComponent, SelectedFilters, ToggleButton, SingleDropdownList, MultiDropdownList, StateProvider, RangeInput];
1186
+ function install (Vue) {
1187
+ components.map(function (component) {
1188
+ Vue.use(component);
1189
+ return null;
1190
+ });
1191
+ }
1192
+
1193
+ export { SearchBox as S, install as i };