@appbaseio/reactivesearch-vue 1.34.0-alpha.2 → 1.35.0

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