@appbaseio/reactivesearch-vue 1.16.0-alpha.6 → 1.16.0-alpha.62

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