@appbaseio/reactivesearch-vue 1.33.10 → 1.33.12

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