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