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