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

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