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