@appbaseio/reactivesearch-vue 1.28.0 → 1.29.0-preview.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 (39) hide show
  1. package/dist/@appbaseio/reactivesearch-vue.umd.js +1759 -371
  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-b05fef06.js +1247 -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-bd448c02.js +1240 -0
  37. package/dist/es/install.js +22 -31
  38. package/dist/es/version.js +1 -1
  39. package/package.json +3 -3
@@ -0,0 +1,1240 @@
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 (highlightedIndex === void 0) {
556
+ highlightedIndex = null;
557
+ }
558
+
559
+ // if a suggestion was selected, delegate the handling to suggestion handler
560
+ if (event.key === 'Enter') {
561
+ if (this.$props.autosuggest === false) {
562
+ this.enterButtonOnClick();
563
+ } else if (highlightedIndex === null) {
564
+ this.setValue(event.target.value, true);
565
+ this.onValueSelectedHandler(event.target.value, causes.ENTER_PRESS);
566
+ }
567
+ } // Need to review
568
+
569
+
570
+ this.$emit('keyDown', event, this.triggerQuery);
571
+ this.$emit('key-down', event, this.triggerQuery);
572
+ },
573
+ onInputChange: function onInputChange(e) {
574
+ var _this2 = this;
575
+
576
+ var inputValue = e.target.value;
577
+
578
+ if (!this.$data.isOpen && this.$props.autosuggest) {
579
+ this.isOpen = true;
580
+ }
581
+
582
+ var value = this.$props.value;
583
+
584
+ if (value === undefined) {
585
+ this.setValue(inputValue, false, this.$props, inputValue === '' ? causes.CLEAR_VALUE : undefined);
586
+ } else {
587
+ this.$emit('change', inputValue, function (_ref3) {
588
+ var isOpen = _ref3.isOpen;
589
+ return _this2.triggerQuery({
590
+ defaultQuery: true,
591
+ customQuery: true,
592
+ value: inputValue,
593
+ isOpen: isOpen
594
+ });
595
+ }, e);
596
+ }
597
+ },
598
+ onSuggestionSelected: function onSuggestionSelected(suggestion) {
599
+ var _this3 = this;
600
+
601
+ this.isOpen = false;
602
+ var value = this.$props.value; // Record analytics for selected suggestions
603
+
604
+ this.triggerClickAnalytics(suggestion._click_id);
605
+
606
+ if (value === undefined) {
607
+ this.setValue(suggestion.value, true, this.$props, causes.SUGGESTION_SELECT, false, suggestion._category);
608
+ } else {
609
+ this.$emit('change', suggestion.value, function (_ref4) {
610
+ var isOpen = _ref4.isOpen;
611
+ return _this3.triggerQuery({
612
+ isOpen: isOpen,
613
+ value: suggestion.value,
614
+ categoryValue: suggestion._category
615
+ });
616
+ });
617
+ }
618
+
619
+ this.onValueSelectedHandler(suggestion.value, causes.SUGGESTION_SELECT, suggestion.source);
620
+ },
621
+ onValueSelectedHandler: function onValueSelectedHandler(currentValue) {
622
+ if (currentValue === void 0) {
623
+ currentValue = this.$data.currentValue;
624
+ }
625
+
626
+ for (var _len = arguments.length, cause = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
627
+ cause[_key - 1] = arguments[_key];
628
+ }
629
+
630
+ this.$emit.apply(this, ['valueSelected', currentValue].concat(cause));
631
+ this.$emit.apply(this, ['value-selected', currentValue].concat(cause));
632
+ },
633
+ handleStateChange: function handleStateChange(changes) {
634
+ var isOpen = changes.isOpen;
635
+ this.isOpen = isOpen;
636
+ },
637
+ getBackgroundColor: function getBackgroundColor(highlightedIndex, index) {
638
+ var isDark = this.themePreset === 'dark';
639
+
640
+ if (isDark) {
641
+ return highlightedIndex === index ? '#555' : '#424242';
642
+ }
643
+
644
+ return highlightedIndex === index ? '#eee' : '#fff';
645
+ },
646
+ renderIcon: function renderIcon() {
647
+ var h = this.$createElement;
648
+
649
+ if (this.$props.showIcon) {
650
+ return this.$props.icon || h(SearchSvg);
651
+ }
652
+
653
+ return null;
654
+ },
655
+ renderErrorComponent: function renderErrorComponent() {
656
+ var h = this.$createElement;
657
+ var renderError = this.$scopedSlots.renderError || this.$props.renderError;
658
+
659
+ if (this.error && renderError && this.$data.currentValue && !this.isLoading) {
660
+ return h(SuggestionWrapper, {
661
+ "attrs": {
662
+ "innerClass": this.$props.innerClass,
663
+ "innerClassName": "error",
664
+ "theme": this.theme,
665
+ "themePreset": this.themePreset
666
+ }
667
+ }, [isFunction(renderError) ? renderError(this.error) : renderError]);
668
+ }
669
+
670
+ return null;
671
+ },
672
+ renderCancelIcon: function renderCancelIcon() {
673
+ var h = this.$createElement;
674
+
675
+ if (this.$props.showClear) {
676
+ return this.$props.clearIcon || h(CancelSvg);
677
+ }
678
+
679
+ return null;
680
+ },
681
+ renderNoSuggestions: function renderNoSuggestions(finalSuggestionsList) {
682
+ if (finalSuggestionsList === void 0) {
683
+ finalSuggestionsList = [];
684
+ }
685
+
686
+ var h = this.$createElement;
687
+ var _this$$props3 = this.$props,
688
+ theme = _this$$props3.theme,
689
+ innerClass = _this$$props3.innerClass;
690
+ var renderNoSuggestion = this.$scopedSlots.renderNoSuggestion || this.$props.renderNoSuggestion;
691
+ var renderError = this.$scopedSlots.renderError || this.$props.renderError;
692
+ var _this$$data = this.$data,
693
+ isOpen = _this$$data.isOpen,
694
+ currentValue = _this$$data.currentValue;
695
+
696
+ if (renderNoSuggestion && isOpen && !finalSuggestionsList.length && !this.isLoading && currentValue && !(renderError && this.error)) {
697
+ return h(SuggestionWrapper, {
698
+ "attrs": {
699
+ "innerClass": innerClass,
700
+ "themePreset": this.themePreset,
701
+ "theme": theme,
702
+ "innerClassName": "noSuggestion"
703
+ },
704
+ "scopedSlots": {
705
+ "default": function _default() {
706
+ return typeof renderNoSuggestion === 'function' ? renderNoSuggestion(currentValue) : renderNoSuggestion;
707
+ }
708
+ }
709
+ });
710
+ }
711
+
712
+ return null;
713
+ },
714
+ renderInputAddonBefore: function renderInputAddonBefore() {
715
+ var h = this.$createElement;
716
+ var addonBefore = this.$scopedSlots.addonBefore;
717
+
718
+ if (addonBefore) {
719
+ return h(InputAddon, {
720
+ "class": "addon-before"
721
+ }, [addonBefore()]);
722
+ }
723
+
724
+ return null;
725
+ },
726
+ renderInputAddonAfter: function renderInputAddonAfter() {
727
+ var h = this.$createElement;
728
+ var addonAfter = this.$scopedSlots.addonAfter;
729
+
730
+ if (addonAfter) {
731
+ return h(InputAddon, {
732
+ "class": "addon-after"
733
+ }, [addonAfter()]);
734
+ }
735
+
736
+ return null;
737
+ },
738
+ enterButtonOnClick: function enterButtonOnClick() {
739
+ this.triggerQuery({
740
+ isOpen: false,
741
+ value: this.currentValue,
742
+ customQuery: true
743
+ });
744
+ },
745
+ renderEnterButtonElement: function renderEnterButtonElement() {
746
+ var _this4 = this;
747
+
748
+ var h = this.$createElement;
749
+ var _this$$props4 = this.$props,
750
+ enterButton = _this$$props4.enterButton,
751
+ innerClass = _this$$props4.innerClass;
752
+ var renderEnterButton = this.$scopedSlots.renderEnterButton;
753
+
754
+ if (enterButton) {
755
+ var getEnterButtonMarkup = function getEnterButtonMarkup() {
756
+ if (renderEnterButton) {
757
+ return renderEnterButton(_this4.enterButtonOnClick);
758
+ }
759
+
760
+ return h(Button, {
761
+ "class": "enter-btn " + getClassName(innerClass, 'enterButton'),
762
+ "attrs": {
763
+ "primary": true
764
+ },
765
+ "on": {
766
+ "click": _this4.enterButtonOnClick
767
+ }
768
+ }, ["Search"]);
769
+ };
770
+
771
+ return h("div", {
772
+ "class": "enter-button-wrapper"
773
+ }, [getEnterButtonMarkup()]);
774
+ }
775
+
776
+ return null;
777
+ },
778
+ renderIcons: function renderIcons() {
779
+ var h = this.$createElement;
780
+ var _this$$props5 = this.$props,
781
+ iconPosition = _this$$props5.iconPosition,
782
+ showClear = _this$$props5.showClear,
783
+ innerClass = _this$$props5.innerClass,
784
+ getMicInstance = _this$$props5.getMicInstance,
785
+ showVoiceSearch = _this$$props5.showVoiceSearch,
786
+ showIcon = _this$$props5.showIcon;
787
+ var renderMic = this.$scopedSlots.renderMic || this.$props.renderMic;
788
+ var currentValue = this.$data.currentValue;
789
+ return h("div", [h(IconGroup, {
790
+ "attrs": {
791
+ "groupPosition": "right",
792
+ "positionType": "absolute"
793
+ }
794
+ }, [currentValue && showClear && h(IconWrapper, {
795
+ "on": {
796
+ "click": this.clearValue
797
+ },
798
+ "attrs": {
799
+ "showIcon": showIcon,
800
+ "isClearIcon": true
801
+ }
802
+ }, [this.renderCancelIcon()]), showVoiceSearch && h(Mic, {
803
+ "attrs": {
804
+ "getInstance": getMicInstance,
805
+ "render": renderMic,
806
+ "handleResult": this.handleVoiceResults,
807
+ "className": getClassName(innerClass, 'mic') || null
808
+ }
809
+ }), iconPosition === 'right' && showIcon && h(IconWrapper, {
810
+ "on": {
811
+ "click": this.handleSearchIconClick
812
+ }
813
+ }, [this.renderIcon()])]), h(IconGroup, {
814
+ "attrs": {
815
+ "groupPosition": "left",
816
+ "positionType": "absolute"
817
+ }
818
+ }, [iconPosition === 'left' && showIcon && h(IconWrapper, {
819
+ "on": {
820
+ "click": this.handleSearchIconClick
821
+ }
822
+ }, [this.renderIcon()])])]);
823
+ },
824
+ focusSearchBox: function focusSearchBox(event) {
825
+ var _this$$refs, _this$$refs$this$$pro;
826
+
827
+ var elt = event.target || event.srcElement;
828
+ var tagName = elt.tagName;
829
+
830
+ if (elt.isContentEditable || tagName === 'INPUT' || tagName === 'SELECT' || tagName === 'TEXTAREA') {
831
+ // already in an input
832
+ return;
833
+ }
834
+
835
+ (_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
836
+ },
837
+ listenForFocusShortcuts: function listenForFocusShortcuts() {
838
+ var _this5 = this;
839
+
840
+ var _this$$props$focusSho = this.$props.focusShortcuts,
841
+ focusShortcuts = _this$$props$focusSho === void 0 ? ['/'] : _this$$props$focusSho;
842
+
843
+ if (isEmpty(focusShortcuts)) {
844
+ return;
845
+ }
846
+
847
+ var shortcutsString = parseFocusShortcuts(focusShortcuts).join(','); // handler for alphabets and other key combinations
848
+
849
+ hotkeys(shortcutsString, // eslint-disable-next-line no-unused-vars
850
+
851
+ /* eslint-disable no-shadow */
852
+ function (event, handler) {
853
+ // Prevent the default refresh event under WINDOWS system
854
+ event.preventDefault();
855
+
856
+ _this5.focusSearchBox(event);
857
+ }); // if one of modifier keys are used, they are handled below
858
+
859
+ hotkeys('*', function (event) {
860
+ var modifierKeys = extractModifierKeysFromFocusShortcuts(focusShortcuts);
861
+ if (modifierKeys.length === 0) return;
862
+
863
+ for (var index = 0; index < modifierKeys.length; index += 1) {
864
+ var element = modifierKeys[index];
865
+
866
+ if (hotkeys[element]) {
867
+ _this5.focusSearchBox(event);
868
+
869
+ break;
870
+ }
871
+ }
872
+ });
873
+ },
874
+ onAutofillClick: function onAutofillClick(suggestion) {
875
+ var value = suggestion.value;
876
+ this.isOpen = true;
877
+ this.currentValue = value;
878
+ this.triggerDefaultQuery(value);
879
+ },
880
+ renderAutoFill: function renderAutoFill(suggestion) {
881
+ var _this6 = this;
882
+
883
+ var h = this.$createElement;
884
+
885
+ var handleAutoFillClick = function handleAutoFillClick(e) {
886
+ e.stopPropagation();
887
+
888
+ _this6.onAutofillClick(suggestion);
889
+ };
890
+ /* 👇 avoid showing autofill for category suggestions👇 */
891
+
892
+
893
+ return suggestion._category ? null : h(AutoFillSvg, {
894
+ "on": {
895
+ "click": handleAutoFillClick
896
+ }
897
+ });
898
+ }
899
+ },
900
+ render: function render() {
901
+ var _this7 = this;
902
+
903
+ var h = arguments[0];
904
+ var _this$$props6 = this.$props,
905
+ theme = _this$$props6.theme,
906
+ expandSuggestionsContainer = _this$$props6.expandSuggestionsContainer;
907
+ var _this$$scopedSlots = this.$scopedSlots,
908
+ recentSearchesIcon = _this$$scopedSlots.recentSearchesIcon,
909
+ popularSearchesIcon = _this$$scopedSlots.popularSearchesIcon;
910
+ var hasSuggestions = Array.isArray(this.normalizedSuggestions) && this.normalizedSuggestions.length;
911
+ var renderItem = this.$scopedSlots.renderItem || this.$props.renderItem;
912
+ return h(Container, {
913
+ "class": this.$props.className
914
+ }, [this.$props.title && h(Title, {
915
+ "class": getClassName(this.$props.innerClass, 'title') || ''
916
+ }, [this.$props.title]), this.$props.autosuggest ? h(Downshift, {
917
+ "attrs": {
918
+ "id": this.$props.componentId + "-downshift",
919
+ "handleChange": this.onSuggestionSelected,
920
+ "handleMouseup": this.handleStateChange,
921
+ "isOpen": this.$data.isOpen
922
+ },
923
+ "scopedSlots": {
924
+ "default": function _default(_ref5) {
925
+ var getInputEvents = _ref5.getInputEvents,
926
+ getInputProps = _ref5.getInputProps,
927
+ getItemProps = _ref5.getItemProps,
928
+ getItemEvents = _ref5.getItemEvents,
929
+ isOpen = _ref5.isOpen,
930
+ highlightedIndex = _ref5.highlightedIndex,
931
+ setHighlightedIndex = _ref5.setHighlightedIndex;
932
+
933
+ var renderSuggestionsDropdown = function renderSuggestionsDropdown() {
934
+ var getIcon = function getIcon(iconType) {
935
+ switch (iconType) {
936
+ case suggestionTypes.Recent:
937
+ return recentSearchesIcon;
938
+
939
+ case suggestionTypes.Popular:
940
+ return popularSearchesIcon;
941
+
942
+ default:
943
+ return null;
944
+ }
945
+ };
946
+
947
+ return h("div", [_this7.hasCustomRenderer && _this7.getComponent({
948
+ isOpen: isOpen,
949
+ getItemProps: getItemProps,
950
+ getItemEvents: getItemEvents,
951
+ highlightedIndex: highlightedIndex
952
+ }), _this7.renderErrorComponent(), !_this7.hasCustomRenderer && isOpen && hasSuggestions ? h("ul", {
953
+ "class": suggestions(_this7.themePreset, theme) + " " + getClassName(_this7.$props.innerClass, 'list')
954
+ }, [_this7.normalizedSuggestions.map(function (item, index) {
955
+ return renderItem ? h("li", {
956
+ "domProps": _extends({}, getItemProps({
957
+ item: item
958
+ })),
959
+ "on": _extends({}, getItemEvents({
960
+ item: item
961
+ })),
962
+ "key": index + 1 + "-" + item.value,
963
+ "style": {
964
+ backgroundColor: _this7.getBackgroundColor(highlightedIndex, index),
965
+ justifyContent: 'flex-start',
966
+ alignItems: 'center'
967
+ }
968
+ }, [renderItem(item)]) : h("li", {
969
+ "domProps": _extends({}, getItemProps({
970
+ item: item
971
+ })),
972
+ "on": _extends({}, getItemEvents({
973
+ item: item
974
+ })),
975
+ "key": index + 1 + "-" + item.value,
976
+ "style": {
977
+ backgroundColor: _this7.getBackgroundColor(highlightedIndex, index),
978
+ justifyContent: 'flex-start',
979
+ alignItems: 'center'
980
+ }
981
+ }, [h("div", {
982
+ "style": {
983
+ padding: '0 10px 0 0',
984
+ display: 'flex'
985
+ }
986
+ }, [h(CustomSvg, {
987
+ "attrs": {
988
+ "className": getClassName(_this7.$props.innerClass, item._suggestion_type + "-search-icon") || null,
989
+ "icon": getIcon(item._suggestion_type),
990
+ "type": item._suggestion_type + "-search-icon"
991
+ }
992
+ })]), h(SuggestionItem, {
993
+ "attrs": {
994
+ "currentValue": _this7.currentValue,
995
+ "suggestion": item
996
+ }
997
+ }), _this7.renderAutoFill(item)]);
998
+ })]) : _this7.renderNoSuggestions(_this7.normalizedSuggestions)]);
999
+ };
1000
+
1001
+ return h("div", {
1002
+ "class": suggestionsContainer
1003
+ }, [h(InputGroup, [_this7.renderInputAddonBefore(), h(InputWrapper, [h(Input, {
1004
+ "attrs": {
1005
+ "id": _this7.$props.componentId + "-input",
1006
+ "showIcon": _this7.$props.showIcon,
1007
+ "showClear": _this7.$props.showClear,
1008
+ "iconPosition": _this7.$props.iconPosition,
1009
+ "placeholder": _this7.$props.placeholder,
1010
+ "autoFocus": _this7.$props.autoFocus,
1011
+ "themePreset": _this7.themePreset,
1012
+ "autocomplete": "off"
1013
+ },
1014
+ "ref": _this7.$props.innerRef,
1015
+ "class": getClassName(_this7.$props.innerClass, 'input'),
1016
+ "on": _extends({}, getInputEvents({
1017
+ onInput: _this7.onInputChange,
1018
+ onBlur: function onBlur(e) {
1019
+ _this7.$emit('blur', e, _this7.triggerQuery);
1020
+ },
1021
+ onFocus: _this7.handleFocus,
1022
+ onKeyPress: function onKeyPress(e) {
1023
+ _this7.$emit('keyPress', e, _this7.triggerQuery);
1024
+
1025
+ _this7.$emit('key-press', e, _this7.triggerQuery);
1026
+ },
1027
+ onKeyDown: function onKeyDown(e) {
1028
+ return _this7.handleKeyDown(e, highlightedIndex);
1029
+ },
1030
+ onKeyUp: function onKeyUp(e) {
1031
+ _this7.$emit('keyUp', e, _this7.triggerQuery);
1032
+
1033
+ _this7.$emit('key-up', e, _this7.triggerQuery);
1034
+ },
1035
+ onClick: function onClick() {
1036
+ setHighlightedIndex(null);
1037
+ }
1038
+ })),
1039
+ "domProps": _extends({}, getInputProps({
1040
+ value: _this7.$data.currentValue === null ? '' : _this7.$data.currentValue
1041
+ }))
1042
+ }), _this7.renderIcons(), !expandSuggestionsContainer && renderSuggestionsDropdown()]), _this7.renderInputAddonAfter(), _this7.renderEnterButtonElement()]), expandSuggestionsContainer && renderSuggestionsDropdown()]);
1043
+ }
1044
+ }
1045
+ }) : h("div", {
1046
+ "class": suggestionsContainer
1047
+ }, [h(InputGroup, [this.renderInputAddonBefore(), h(InputWrapper, [h(Input, {
1048
+ "class": getClassName(this.$props.innerClass, 'input') || '',
1049
+ "attrs": {
1050
+ "placeholder": this.$props.placeholder,
1051
+ "iconPosition": this.$props.iconPosition,
1052
+ "showIcon": this.$props.showIcon,
1053
+ "showClear": this.$props.showClear,
1054
+ "themePreset": this.themePreset
1055
+ },
1056
+ "on": _extends({}, {
1057
+ blur: function blur(e) {
1058
+ _this7.$emit('blur', e, _this7.triggerQuery);
1059
+ },
1060
+ keypress: function keypress(e) {
1061
+ _this7.$emit('keyPress', e, _this7.triggerQuery);
1062
+
1063
+ _this7.$emit('key-press', e, _this7.triggerQuery);
1064
+ },
1065
+ input: this.onInputChange,
1066
+ focus: function focus(e) {
1067
+ _this7.$emit('focus', e, _this7.triggerQuery);
1068
+ },
1069
+ keydown: this.handleKeyDown,
1070
+ keyup: function keyup(e) {
1071
+ _this7.$emit('keyUp', e, _this7.triggerQuery);
1072
+
1073
+ _this7.$emit('key-up', e, _this7.triggerQuery);
1074
+ }
1075
+ }),
1076
+ "domProps": _extends({}, {
1077
+ autofocus: this.$props.autoFocus,
1078
+ value: this.$data.currentValue ? this.$data.currentValue : ''
1079
+ }),
1080
+ "ref": this.$props.innerRef
1081
+ }), this.renderIcons()]), this.renderInputAddonAfter(), this.renderEnterButtonElement()])])]);
1082
+ },
1083
+ destroyed: function destroyed() {
1084
+ document.removeEventListener('keydown', this.onKeyDown);
1085
+ }
1086
+ };
1087
+
1088
+ SearchBox.defaultQuery = function (value, props) {
1089
+ var finalQuery = null;
1090
+ var fields = normalizeDataField(props.dataField, props.fieldWeights);
1091
+ finalQuery = {
1092
+ bool: {
1093
+ should: SearchBox.shouldQuery(value, fields, props),
1094
+ minimum_should_match: '1'
1095
+ }
1096
+ };
1097
+
1098
+ if (finalQuery && props.nestedField) {
1099
+ return {
1100
+ query: {
1101
+ nested: {
1102
+ path: props.nestedField,
1103
+ query: finalQuery
1104
+ }
1105
+ }
1106
+ };
1107
+ }
1108
+
1109
+ return finalQuery;
1110
+ };
1111
+
1112
+ SearchBox.shouldQuery = function (value, dataFields, props) {
1113
+ var finalQuery = [];
1114
+ var phrasePrefixFields = [];
1115
+ var fields = dataFields.map(function (dataField) {
1116
+ var queryField = "" + dataField.field + (dataField.weight ? "^" + dataField.weight : '');
1117
+
1118
+ if (!(dataField.field.endsWith('.keyword') || dataField.field.endsWith('.autosuggest') || dataField.field.endsWith('.search'))) {
1119
+ phrasePrefixFields.push(queryField);
1120
+ }
1121
+
1122
+ return queryField;
1123
+ });
1124
+
1125
+ if (props.searchOperators || props.queryString) {
1126
+ return {
1127
+ query: value,
1128
+ fields: fields,
1129
+ default_operator: props.queryFormat
1130
+ };
1131
+ }
1132
+
1133
+ if (props.queryFormat === 'and') {
1134
+ finalQuery.push({
1135
+ multi_match: {
1136
+ query: value,
1137
+ fields: fields,
1138
+ type: 'cross_fields',
1139
+ operator: 'and'
1140
+ }
1141
+ });
1142
+ finalQuery.push({
1143
+ multi_match: {
1144
+ query: value,
1145
+ fields: fields,
1146
+ type: 'phrase',
1147
+ operator: 'and'
1148
+ }
1149
+ });
1150
+
1151
+ if (phrasePrefixFields.length > 0) {
1152
+ finalQuery.push({
1153
+ multi_match: {
1154
+ query: value,
1155
+ fields: phrasePrefixFields,
1156
+ type: 'phrase_prefix',
1157
+ operator: 'and'
1158
+ }
1159
+ });
1160
+ }
1161
+
1162
+ return finalQuery;
1163
+ }
1164
+
1165
+ finalQuery.push({
1166
+ multi_match: {
1167
+ query: value,
1168
+ fields: fields,
1169
+ type: 'best_fields',
1170
+ operator: 'or',
1171
+ fuzziness: props.fuzziness ? props.fuzziness : 0
1172
+ }
1173
+ });
1174
+ finalQuery.push({
1175
+ multi_match: {
1176
+ query: value,
1177
+ fields: fields,
1178
+ type: 'phrase',
1179
+ operator: 'or'
1180
+ }
1181
+ });
1182
+
1183
+ if (phrasePrefixFields.length > 0) {
1184
+ finalQuery.push({
1185
+ multi_match: {
1186
+ query: value,
1187
+ fields: phrasePrefixFields,
1188
+ type: 'phrase_prefix',
1189
+ operator: 'or'
1190
+ }
1191
+ });
1192
+ }
1193
+
1194
+ return finalQuery;
1195
+ };
1196
+
1197
+ var mapStateToProps = function mapStateToProps(state, props) {
1198
+ return {
1199
+ selectedValue: state.selectedValues[props.componentId] && state.selectedValues[props.componentId].value || null,
1200
+ selectedCategory: state.selectedValues[props.componentId] && state.selectedValues[props.componentId].category || null,
1201
+ suggestions: state.hits[props.componentId] && state.hits[props.componentId].hits,
1202
+ rawData: state.rawData[props.componentId],
1203
+ aggregationData: state.compositeAggregations[props.componentId] || [],
1204
+ themePreset: state.config.themePreset,
1205
+ isLoading: !!state.isLoading[props.componentId + "_active"],
1206
+ error: state.error[props.componentId],
1207
+ enableAppbase: state.config.enableAppbase,
1208
+ time: state.hits[props.componentId] && state.hits[props.componentId].time || 0,
1209
+ total: state.hits[props.componentId] && state.hits[props.componentId].total,
1210
+ hidden: state.hits[props.componentId] && state.hits[props.componentId].hidden
1211
+ };
1212
+ };
1213
+
1214
+ var mapDispatchToProps = {
1215
+ updateQuery: updateQuery,
1216
+ setCustomQuery: setCustomQuery,
1217
+ setDefaultQuery: setDefaultQuery,
1218
+ recordSuggestionClick: recordSuggestionClick
1219
+ };
1220
+ var DSConnected = ComponentWrapper(connect(mapStateToProps, mapDispatchToProps)(SearchBox), {
1221
+ componentType: componentTypes.searchBox,
1222
+ internalComponent: true
1223
+ });
1224
+
1225
+ SearchBox.install = function (Vue) {
1226
+ Vue.component(SearchBox.name, DSConnected);
1227
+ }; // Add componentType for SSR
1228
+
1229
+
1230
+ SearchBox.componentType = componentTypes.searchBox;
1231
+
1232
+ var components = [ReactiveList, ResultCard, ResultList, ReactiveBase, DataSearch, SearchBox, SingleList, MultiList, SingleRange, MultiRange, RangeSlider, DynamicRangeSlider, ReactiveComponent, SelectedFilters, ToggleButton, SingleDropdownList, MultiDropdownList, StateProvider, RangeInput];
1233
+ function install (Vue) {
1234
+ components.map(function (component) {
1235
+ Vue.use(component);
1236
+ return null;
1237
+ });
1238
+ }
1239
+
1240
+ export { SearchBox as S, install as i };