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