@synerise/ds-search 0.6.0 → 0.6.4

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/Search.js CHANGED
@@ -1,30 +1,12 @@
1
- function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
2
-
3
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
1
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
4
2
 
5
3
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
6
4
 
7
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
8
-
9
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
10
-
11
- function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
12
-
13
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
14
-
15
- function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
16
-
17
- function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
18
-
19
- function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
20
-
21
- function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
22
-
23
5
  function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
24
6
 
25
- function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
7
+ function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; }
26
8
 
27
- function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
9
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
28
10
 
29
11
  import * as React from 'react';
30
12
  import onClickOutside from 'react-onclickoutside';
@@ -47,20 +29,16 @@ var getParametersScrollTop = function getParametersScrollTop(_ref) {
47
29
  };
48
30
 
49
31
  var Search = /*#__PURE__*/function (_React$PureComponent) {
50
- _inherits(Search, _React$PureComponent);
51
-
52
- var _super = _createSuper(Search);
32
+ _inheritsLoose(Search, _React$PureComponent);
53
33
 
54
34
  function Search(props) {
55
35
  var _this;
56
36
 
57
- _classCallCheck(this, Search);
37
+ _this = _React$PureComponent.call(this, props) || this; // eslint-disable-next-line react/state-in-constructor
58
38
 
59
- _this = _super.call(this, props); // eslint-disable-next-line react/state-in-constructor
39
+ _defineProperty(_assertThisInitialized(_this), "wrapperRef", React.createRef());
60
40
 
61
- _this.wrapperRef = /*#__PURE__*/React.createRef();
62
-
63
- _this.handleClickOutside = function () {
41
+ _defineProperty(_assertThisInitialized(_this), "handleClickOutside", function () {
64
42
  var _this$state = _this.state,
65
43
  isInputOpen = _this$state.isInputOpen,
66
44
  label = _this$state.label,
@@ -77,9 +55,9 @@ var Search = /*#__PURE__*/function (_React$PureComponent) {
77
55
  isListVisible: false,
78
56
  scrollbarScrollTop: 0
79
57
  });
80
- };
58
+ });
81
59
 
82
- _this.handleClearValue = function () {
60
+ _defineProperty(_assertThisInitialized(_this), "handleClearValue", function () {
83
61
  var _this$props = _this.props,
84
62
  parameters = _this$props.parameters,
85
63
  recent = _this$props.recent,
@@ -94,7 +72,7 @@ var Search = /*#__PURE__*/function (_React$PureComponent) {
94
72
  filteredSuggestions: suggestions,
95
73
  isResultChosen: false
96
74
  });
97
- };
75
+ });
98
76
 
99
77
  _this.state = {
100
78
  isInputOpen: !!props.value || !!props.parameterValue,
@@ -115,422 +93,410 @@ var Search = /*#__PURE__*/function (_React$PureComponent) {
115
93
  return _this;
116
94
  }
117
95
 
118
- _createClass(Search, [{
119
- key: "componentDidUpdate",
120
- value: function componentDidUpdate(prevProps) {
121
- var _prevProps$suggestion;
122
-
123
- var _this$props2 = this.props,
124
- recent = _this$props2.recent,
125
- suggestions = _this$props2.suggestions,
126
- parameters = _this$props2.parameters,
127
- value = _this$props2.value,
128
- textLookupConfig = _this$props2.textLookupConfig,
129
- hideLabel = _this$props2.hideLabel,
130
- parameterValue = _this$props2.parameterValue;
131
-
132
- if (prevProps.value !== value && !value || prevProps.parameterValue && !parameterValue) {
133
- this.handleChange(value); // eslint-disable-next-line react/no-did-update-set-state
134
-
135
- this.setState({
136
- isResultChosen: false
137
- });
138
- }
96
+ var _proto = Search.prototype;
139
97
 
140
- if (prevProps.recent.length !== recent.length) {
141
- // eslint-disable-next-line react/no-did-update-set-state
142
- this.setState({
143
- filteredRecent: getAllElementsFiltered(recent, value, textLookupConfig.recent)
144
- });
145
- }
98
+ _proto.componentDidUpdate = function componentDidUpdate(prevProps) {
99
+ var _prevProps$suggestion;
146
100
 
147
- if (prevProps.parameters.length !== parameters.length) {
148
- // eslint-disable-next-line react/no-did-update-set-state
149
- this.setState({
150
- filteredParameters: parameterValue ? parameters : getAllElementsFiltered(parameters, value, textLookupConfig.parameters)
151
- });
152
- }
101
+ var _this$props2 = this.props,
102
+ recent = _this$props2.recent,
103
+ suggestions = _this$props2.suggestions,
104
+ parameters = _this$props2.parameters,
105
+ value = _this$props2.value,
106
+ textLookupConfig = _this$props2.textLookupConfig,
107
+ hideLabel = _this$props2.hideLabel,
108
+ parameterValue = _this$props2.parameterValue;
153
109
 
154
- if (suggestions && ((_prevProps$suggestion = prevProps.suggestions) === null || _prevProps$suggestion === void 0 ? void 0 : _prevProps$suggestion.length) !== suggestions.length) {
155
- // eslint-disable-next-line react/no-did-update-set-state
156
- this.setState({
157
- filteredSuggestions: getAllElementsFiltered(suggestions, value, textLookupConfig.suggestions)
158
- });
159
- }
110
+ if (prevProps.value !== value && !value || prevProps.parameterValue && !parameterValue) {
111
+ this.handleChange(value); // eslint-disable-next-line react/no-did-update-set-state
160
112
 
161
- if (hideLabel && prevProps.hideLabel !== hideLabel) {
162
- // eslint-disable-next-line react/no-did-update-set-state
163
- this.setState({
164
- label: null,
165
- isResultChosen: false
166
- });
167
- }
113
+ this.setState({
114
+ isResultChosen: false
115
+ });
168
116
  }
169
- }, {
170
- key: "onKeyDown",
171
- value: function onKeyDown(e) {
172
- var _this$props3 = this.props,
173
- value = _this$props3.value,
174
- onParameterValueChange = _this$props3.onParameterValueChange,
175
- recent = _this$props3.recent;
176
- var isInputOpen = this.state.isInputOpen;
177
-
178
- if (e.key === 'Backspace' && value === '' && isInputOpen) {
179
- this.setState({
180
- label: null,
181
- filteredRecent: recent
182
- });
183
- onParameterValueChange('', null);
184
- return;
185
- }
186
-
187
- if (e.key === 'Enter' && isInputOpen) {
188
- this.setState({
189
- isResultChosen: !!value
190
- });
191
- }
192
117
 
118
+ if (prevProps.recent.length !== recent.length) {
119
+ // eslint-disable-next-line react/no-did-update-set-state
193
120
  this.setState({
194
- moveCursorToEnd: false
121
+ filteredRecent: getAllElementsFiltered(recent, value, textLookupConfig.recent)
195
122
  });
196
123
  }
197
- }, {
198
- key: "getSearchWrapperWidth",
199
- value: function getSearchWrapperWidth() {
200
- var width = this.props.width;
201
-
202
- if (width) {
203
- return width - MENU_WIDTH_OFFSET;
204
- }
205
124
 
206
- if (this.wrapperRef !== null && this.wrapperRef.current && this.wrapperRef.current.clientWidth > MENU_WIDTH_OFFSET) {
207
- return this.wrapperRef.current.clientWidth - MENU_WIDTH_OFFSET;
208
- }
209
-
210
- return 0;
211
- } // This handler is used for onClickOutside HOC
212
-
213
- }, {
214
- key: "handleChange",
215
- value: function handleChange(currentValue) {
216
- var _this$props4 = this.props,
217
- parameterValue = _this$props4.parameterValue,
218
- recent = _this$props4.recent,
219
- suggestions = _this$props4.suggestions,
220
- parameters = _this$props4.parameters,
221
- onValueChange = _this$props4.onValueChange,
222
- textLookupConfig = _this$props4.textLookupConfig;
223
- var isAnythingToShow;
224
- onValueChange(currentValue);
225
-
226
- if (parameterValue) {
227
- var matchingSuggestions = getAllElementsFiltered(suggestions, currentValue, textLookupConfig.suggestions);
228
- this.setState({
229
- filteredSuggestions: matchingSuggestions
230
- });
231
- isAnythingToShow = matchingSuggestions.length > 0;
232
- } else {
233
- var matchingRecent = getAllElementsFiltered(recent, currentValue, textLookupConfig.recent);
234
- var matchingParameters = getAllElementsFiltered(parameters, currentValue, textLookupConfig.parameters);
235
- this.setState({
236
- filteredParameters: matchingParameters,
237
- filteredRecent: matchingRecent
238
- });
239
- isAnythingToShow = matchingRecent.length > 0 || matchingParameters.length > 0;
240
- }
125
+ if (prevProps.parameters.length !== parameters.length) {
126
+ // eslint-disable-next-line react/no-did-update-set-state
127
+ this.setState({
128
+ filteredParameters: parameterValue ? parameters : getAllElementsFiltered(parameters, value, textLookupConfig.parameters)
129
+ });
130
+ }
241
131
 
132
+ if (suggestions && ((_prevProps$suggestion = prevProps.suggestions) == null ? void 0 : _prevProps$suggestion.length) !== suggestions.length) {
133
+ // eslint-disable-next-line react/no-did-update-set-state
242
134
  this.setState({
243
- isResultChosen: false,
244
- isListVisible: isAnythingToShow
135
+ filteredSuggestions: getAllElementsFiltered(suggestions, value, textLookupConfig.suggestions)
245
136
  });
246
137
  }
247
- }, {
248
- key: "isListItemRendered",
249
- value: function isListItemRendered() {
250
- var _this$props5 = this.props,
251
- suggestions = _this$props5.suggestions,
252
- recent = _this$props5.recent,
253
- parameters = _this$props5.parameters,
254
- value = _this$props5.value,
255
- parameterValue = _this$props5.parameterValue,
256
- textLookupConfig = _this$props5.textLookupConfig;
257
- var isAnythingToShow;
258
-
259
- if (parameterValue) {
260
- isAnythingToShow = hasSomeElementFiltered(suggestions, value, textLookupConfig.suggestions);
261
- } else {
262
- var anyRecentItem = hasSomeElementFiltered(recent, value, textLookupConfig.recent);
263
- var anyFilter = hasSomeElementFiltered(parameters, value, textLookupConfig.parameters);
264
- isAnythingToShow = anyFilter || anyRecentItem;
265
- }
266
138
 
267
- return isAnythingToShow;
139
+ if (hideLabel && prevProps.hideLabel !== hideLabel) {
140
+ // eslint-disable-next-line react/no-did-update-set-state
141
+ this.setState({
142
+ label: null,
143
+ isResultChosen: false
144
+ });
268
145
  }
269
- }, {
270
- key: "selectResult",
271
- value: function selectResult(item, dataKey) {
272
- var _this$props6 = this.props,
273
- onValueChange = _this$props6.onValueChange,
274
- textLookupConfig = _this$props6.textLookupConfig;
146
+ };
147
+
148
+ _proto.onKeyDown = function onKeyDown(e) {
149
+ var _this$props3 = this.props,
150
+ value = _this$props3.value,
151
+ onParameterValueChange = _this$props3.onParameterValueChange,
152
+ recent = _this$props3.recent;
153
+ var isInputOpen = this.state.isInputOpen;
154
+
155
+ if (e.key === 'Backspace' && value === '' && isInputOpen) {
275
156
  this.setState({
276
- isResultChosen: true,
277
- moveCursorToEnd: true
157
+ label: null,
158
+ filteredRecent: recent
278
159
  });
279
- onValueChange(item[textLookupConfig[dataKey]]);
160
+ onParameterValueChange('', null);
161
+ return;
280
162
  }
281
- }, {
282
- key: "selectFilter",
283
- value: function selectFilter(item) {
284
- var _this$props7 = this.props,
285
- onValueChange = _this$props7.onValueChange,
286
- onParameterValueChange = _this$props7.onParameterValueChange,
287
- filterLookupKey = _this$props7.filterLookupKey,
288
- textLookupConfig = _this$props7.textLookupConfig;
289
- onValueChange('');
163
+
164
+ if (e.key === 'Enter' && isInputOpen) {
290
165
  this.setState({
291
- label: item,
292
- moveCursorToEnd: true
166
+ isResultChosen: !!value
293
167
  });
168
+ }
294
169
 
295
- if (filterLookupKey && item[filterLookupKey]) {
296
- onValueChange(item[textLookupConfig.parameters]); // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
297
- // @ts-ignore
170
+ this.setState({
171
+ moveCursorToEnd: false
172
+ });
173
+ };
298
174
 
299
- onParameterValueChange(item[filterLookupKey], item);
300
- this.setState({
301
- isResultChosen: true
302
- });
303
- } else {
304
- // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
305
- // @ts-ignore
306
- onParameterValueChange(item[textLookupConfig.parameters], item);
307
- }
175
+ _proto.getSearchWrapperWidth = function getSearchWrapperWidth() {
176
+ var width = this.props.width;
177
+
178
+ if (width) {
179
+ return width - MENU_WIDTH_OFFSET;
308
180
  }
309
- }, {
310
- key: "renderRecentItems",
311
- value: function renderRecentItems() {
312
- var _this2 = this;
313
-
314
- var _this$props8 = this.props,
315
- recent = _this$props8.recent,
316
- recentDisplayProps = _this$props8.recentDisplayProps,
317
- value = _this$props8.value;
318
- var _this$state2 = this.state,
319
- label = _this$state2.label,
320
- filteredRecent = _this$state2.filteredRecent,
321
- itemsListWidth = _this$state2.itemsListWidth;
322
- var title = recentDisplayProps.title,
323
- tooltip = recentDisplayProps.tooltip,
324
- rowHeight = recentDisplayProps.rowHeight,
325
- itemRender = recentDisplayProps.itemRender;
326
- return recent && !label && hasSomeElement(filteredRecent) && /*#__PURE__*/React.createElement(React.Fragment, null, !!title && /*#__PURE__*/React.createElement(SearchHeader, {
327
- headerText: title,
328
- tooltip: tooltip
329
- }), /*#__PURE__*/React.createElement(SearchItems, {
330
- data: filteredRecent,
331
- highlight: value,
332
- itemRender: itemRender,
333
- onItemClick: function onItemClick(item) {
334
- return _this2.selectResult(item, SelectResultDataKeys.RECENT);
335
- },
336
- rowHeight: rowHeight,
337
- width: itemsListWidth
338
- }));
181
+
182
+ if (this.wrapperRef !== null && this.wrapperRef.current && this.wrapperRef.current.clientWidth > MENU_WIDTH_OFFSET) {
183
+ return this.wrapperRef.current.clientWidth - MENU_WIDTH_OFFSET;
339
184
  }
340
- }, {
341
- key: "renderParameters",
342
- value: function renderParameters() {
343
- var _this3 = this;
344
-
345
- var _this$props9 = this.props,
346
- parameters = _this$props9.parameters,
347
- parametersDisplayProps = _this$props9.parametersDisplayProps,
348
- value = _this$props9.value,
349
- dropdownMaxHeight = _this$props9.dropdownMaxHeight,
350
- recentDisplayProps = _this$props9.recentDisplayProps;
351
- var _this$state3 = this.state,
352
- label = _this$state3.label,
353
- filteredParameters = _this$state3.filteredParameters,
354
- itemsListWidth = _this$state3.itemsListWidth,
355
- scrollbarScrollTop = _this$state3.scrollbarScrollTop,
356
- filteredRecent = _this$state3.filteredRecent;
357
- var title = parametersDisplayProps.title,
358
- tooltip = parametersDisplayProps.tooltip,
359
- rowHeight = parametersDisplayProps.rowHeight,
360
- itemRender = parametersDisplayProps.itemRender,
361
- listProps = parametersDisplayProps.listProps;
362
- return parameters && !label && hasSomeElement(filteredParameters) && /*#__PURE__*/React.createElement(React.Fragment, null, !!title && /*#__PURE__*/React.createElement(SearchHeader, {
363
- headerText: title,
364
- tooltip: tooltip
365
- }), /*#__PURE__*/React.createElement(SearchItems, {
366
- data: filteredParameters,
367
- height: dropdownMaxHeight,
368
- highlight: value,
369
- itemRender: itemRender,
370
- onItemClick: function onItemClick(item) {
371
- return _this3.selectFilter(item);
372
- },
373
- rowHeight: rowHeight,
374
- width: itemsListWidth,
375
- listProps: _objectSpread({
376
- scrollTop: getParametersScrollTop({
377
- scrollTop: scrollbarScrollTop,
378
- recent: filteredRecent,
379
- rowHeight: recentDisplayProps.rowHeight
380
- })
381
- }, listProps || {})
382
- }));
185
+
186
+ return 0;
187
+ } // This handler is used for onClickOutside HOC
188
+ ;
189
+
190
+ _proto.handleChange = function handleChange(currentValue) {
191
+ var _this$props4 = this.props,
192
+ parameterValue = _this$props4.parameterValue,
193
+ recent = _this$props4.recent,
194
+ suggestions = _this$props4.suggestions,
195
+ parameters = _this$props4.parameters,
196
+ onValueChange = _this$props4.onValueChange,
197
+ textLookupConfig = _this$props4.textLookupConfig;
198
+ var isAnythingToShow;
199
+ onValueChange(currentValue);
200
+
201
+ if (parameterValue) {
202
+ var matchingSuggestions = getAllElementsFiltered(suggestions, currentValue, textLookupConfig.suggestions);
203
+ this.setState({
204
+ filteredSuggestions: matchingSuggestions
205
+ });
206
+ isAnythingToShow = matchingSuggestions.length > 0;
207
+ } else {
208
+ var matchingRecent = getAllElementsFiltered(recent, currentValue, textLookupConfig.recent);
209
+ var matchingParameters = getAllElementsFiltered(parameters, currentValue, textLookupConfig.parameters);
210
+ this.setState({
211
+ filteredParameters: matchingParameters,
212
+ filteredRecent: matchingRecent
213
+ });
214
+ isAnythingToShow = matchingRecent.length > 0 || matchingParameters.length > 0;
383
215
  }
384
- }, {
385
- key: "renderSuggestions",
386
- value: function renderSuggestions() {
387
- var _this4 = this;
388
-
389
- var _this$props10 = this.props,
390
- suggestions = _this$props10.suggestions,
391
- parameterValue = _this$props10.parameterValue,
392
- suggestionsDisplayProps = _this$props10.suggestionsDisplayProps,
393
- value = _this$props10.value,
394
- dropdownMaxHeight = _this$props10.dropdownMaxHeight;
395
- var _this$state4 = this.state,
396
- isResultChosen = _this$state4.isResultChosen,
397
- itemsListWidth = _this$state4.itemsListWidth,
398
- filteredSuggestions = _this$state4.filteredSuggestions,
399
- scrollbarScrollTop = _this$state4.scrollbarScrollTop;
400
- return suggestions && suggestionsDisplayProps && parameterValue && !isResultChosen && filteredSuggestions && hasSomeElement(filteredSuggestions) && /*#__PURE__*/React.createElement(React.Fragment, null, !!suggestionsDisplayProps.title && /*#__PURE__*/React.createElement(SearchHeader, {
401
- headerText: suggestionsDisplayProps.title,
402
- tooltip: suggestionsDisplayProps.tooltip
403
- }), /*#__PURE__*/React.createElement(SearchItems, {
404
- data: filteredSuggestions,
405
- height: dropdownMaxHeight,
406
- highlight: value,
407
- itemRender: suggestionsDisplayProps.itemRender,
408
- onItemClick: function onItemClick(item) {
409
- return _this4.selectResult(item, SelectResultDataKeys.SUGGESTIONS);
410
- },
411
- rowHeight: suggestionsDisplayProps.rowHeight,
412
- width: itemsListWidth,
413
- listProps: _objectSpread({
414
- scrollTop: scrollbarScrollTop
415
- }, suggestionsDisplayProps.listProps || {})
416
- }));
216
+
217
+ this.setState({
218
+ isResultChosen: false,
219
+ isListVisible: isAnythingToShow
220
+ });
221
+ };
222
+
223
+ _proto.isListItemRendered = function isListItemRendered() {
224
+ var _this$props5 = this.props,
225
+ suggestions = _this$props5.suggestions,
226
+ recent = _this$props5.recent,
227
+ parameters = _this$props5.parameters,
228
+ value = _this$props5.value,
229
+ parameterValue = _this$props5.parameterValue,
230
+ textLookupConfig = _this$props5.textLookupConfig;
231
+ var isAnythingToShow;
232
+
233
+ if (parameterValue) {
234
+ isAnythingToShow = hasSomeElementFiltered(suggestions, value, textLookupConfig.suggestions);
235
+ } else {
236
+ var anyRecentItem = hasSomeElementFiltered(recent, value, textLookupConfig.recent);
237
+ var anyFilter = hasSomeElementFiltered(parameters, value, textLookupConfig.parameters);
238
+ isAnythingToShow = anyFilter || anyRecentItem;
417
239
  }
418
- }, {
419
- key: "renderInputWrapper",
420
- value: function renderInputWrapper() {
421
- var _this5 = this;
422
-
423
- var _this$props11 = this.props,
424
- placeholder = _this$props11.placeholder,
425
- clearTooltip = _this$props11.clearTooltip,
426
- value = _this$props11.value,
427
- textLookupConfig = _this$props11.textLookupConfig,
428
- filterLookupKey = _this$props11.filterLookupKey,
429
- disableInput = _this$props11.disableInput,
430
- inputProps = _this$props11.inputProps;
431
- var _this$state5 = this.state,
432
- label = _this$state5.label,
433
- focusInputTrigger = _this$state5.focusInputTrigger,
434
- toggleInputTrigger = _this$state5.toggleInputTrigger,
435
- moveCursorToEnd = _this$state5.moveCursorToEnd;
436
- return /*#__PURE__*/React.createElement(SearchInput, {
437
- alwaysHighlight: true,
438
- clearTooltip: clearTooltip,
439
- filterLookupKey: filterLookupKey,
440
- textLookupKey: textLookupConfig.parameters,
441
- filterLabel: label,
442
- focusTrigger: focusInputTrigger,
443
- onButtonClick: function onButtonClick() {
444
- return _this5.setState({
445
- focusInputTrigger: !focusInputTrigger
446
- });
447
- },
448
- onChange: function onChange(newValue) {
449
- return _this5.handleChange(newValue);
450
- },
451
- onClear: this.handleClearValue,
452
- onClick: function onClick() {
453
- return _this5.setState({
454
- isListVisible: true,
455
- itemsListWidth: _this5.getSearchWrapperWidth()
456
- });
457
- },
458
- onKeyDown: function onKeyDown(e) {
459
- return _this5.onKeyDown(e);
460
- },
461
- onToggle: function onToggle(toggle) {
462
- _this5.setState({
463
- isListVisible: toggle,
464
- isInputOpen: toggle
465
- });
466
240
 
467
- setTimeout(function () {
468
- _this5.setState({
469
- itemsListWidth: _this5.getSearchWrapperWidth()
470
- });
471
- }, INPUT_EXPAND_ANIMATION_DURATION);
472
- },
473
- placeholder: placeholder,
474
- toggleTrigger: toggleInputTrigger,
475
- value: value,
476
- moveCursorToEnd: moveCursorToEnd,
477
- disableInput: disableInput,
478
- inputProps: inputProps
241
+ return isAnythingToShow;
242
+ };
243
+
244
+ _proto.selectResult = function selectResult(item, dataKey) {
245
+ var _this$props6 = this.props,
246
+ onValueChange = _this$props6.onValueChange,
247
+ textLookupConfig = _this$props6.textLookupConfig;
248
+ this.setState({
249
+ isResultChosen: true,
250
+ moveCursorToEnd: true
251
+ });
252
+ onValueChange(item[textLookupConfig[dataKey]]);
253
+ };
254
+
255
+ _proto.selectFilter = function selectFilter(item) {
256
+ var _this$props7 = this.props,
257
+ onValueChange = _this$props7.onValueChange,
258
+ onParameterValueChange = _this$props7.onParameterValueChange,
259
+ filterLookupKey = _this$props7.filterLookupKey,
260
+ textLookupConfig = _this$props7.textLookupConfig;
261
+ onValueChange('');
262
+ this.setState({
263
+ label: item,
264
+ moveCursorToEnd: true
265
+ });
266
+
267
+ if (filterLookupKey && item[filterLookupKey]) {
268
+ onValueChange(item[textLookupConfig.parameters]); // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
269
+ // @ts-ignore
270
+
271
+ onParameterValueChange(item[filterLookupKey], item);
272
+ this.setState({
273
+ isResultChosen: true
479
274
  });
275
+ } else {
276
+ // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
277
+ // @ts-ignore
278
+ onParameterValueChange(item[textLookupConfig.parameters], item);
480
279
  }
481
- }, {
482
- key: "render",
483
- value: function render() {
484
- var _this6 = this;
485
-
486
- var _this$props12 = this.props,
487
- divider = _this$props12.divider,
488
- dropdownMaxHeight = _this$props12.dropdownMaxHeight,
489
- width = _this$props12.width,
490
- style = _this$props12.style;
491
- var _this$state6 = this.state,
492
- isInputOpen = _this$state6.isInputOpen,
493
- label = _this$state6.label,
494
- isListVisible = _this$state6.isListVisible,
495
- focusInputTrigger = _this$state6.focusInputTrigger,
496
- isResultChosen = _this$state6.isResultChosen,
497
- filteredParameters = _this$state6.filteredParameters,
498
- filteredRecent = _this$state6.filteredRecent;
499
- return /*#__PURE__*/React.createElement(S.SearchWrapper, {
500
- ref: this.wrapperRef,
501
- className: "SearchWrapper",
502
- inputOpen: isInputOpen,
503
- width: width,
504
- onKeyDown: function onKeyDown(e) {
505
- focusWithArrowKeys(e, 'ds-search-item', function () {
506
- _this6.setState({
507
- focusInputTrigger: !focusInputTrigger
508
- });
280
+ };
281
+
282
+ _proto.renderRecentItems = function renderRecentItems() {
283
+ var _this2 = this;
284
+
285
+ var _this$props8 = this.props,
286
+ recent = _this$props8.recent,
287
+ recentDisplayProps = _this$props8.recentDisplayProps,
288
+ value = _this$props8.value;
289
+ var _this$state2 = this.state,
290
+ label = _this$state2.label,
291
+ filteredRecent = _this$state2.filteredRecent,
292
+ itemsListWidth = _this$state2.itemsListWidth;
293
+ var title = recentDisplayProps.title,
294
+ tooltip = recentDisplayProps.tooltip,
295
+ rowHeight = recentDisplayProps.rowHeight,
296
+ itemRender = recentDisplayProps.itemRender;
297
+ return recent && !label && hasSomeElement(filteredRecent) && /*#__PURE__*/React.createElement(React.Fragment, null, !!title && /*#__PURE__*/React.createElement(SearchHeader, {
298
+ headerText: title,
299
+ tooltip: tooltip
300
+ }), /*#__PURE__*/React.createElement(SearchItems, {
301
+ data: filteredRecent,
302
+ highlight: value,
303
+ itemRender: itemRender,
304
+ onItemClick: function onItemClick(item) {
305
+ return _this2.selectResult(item, SelectResultDataKeys.RECENT);
306
+ },
307
+ rowHeight: rowHeight,
308
+ width: itemsListWidth
309
+ }));
310
+ };
311
+
312
+ _proto.renderParameters = function renderParameters() {
313
+ var _this3 = this;
314
+
315
+ var _this$props9 = this.props,
316
+ parameters = _this$props9.parameters,
317
+ parametersDisplayProps = _this$props9.parametersDisplayProps,
318
+ value = _this$props9.value,
319
+ dropdownMaxHeight = _this$props9.dropdownMaxHeight,
320
+ recentDisplayProps = _this$props9.recentDisplayProps;
321
+ var _this$state3 = this.state,
322
+ label = _this$state3.label,
323
+ filteredParameters = _this$state3.filteredParameters,
324
+ itemsListWidth = _this$state3.itemsListWidth,
325
+ scrollbarScrollTop = _this$state3.scrollbarScrollTop,
326
+ filteredRecent = _this$state3.filteredRecent;
327
+ var title = parametersDisplayProps.title,
328
+ tooltip = parametersDisplayProps.tooltip,
329
+ rowHeight = parametersDisplayProps.rowHeight,
330
+ itemRender = parametersDisplayProps.itemRender,
331
+ listProps = parametersDisplayProps.listProps;
332
+ return parameters && !label && hasSomeElement(filteredParameters) && /*#__PURE__*/React.createElement(React.Fragment, null, !!title && /*#__PURE__*/React.createElement(SearchHeader, {
333
+ headerText: title,
334
+ tooltip: tooltip
335
+ }), /*#__PURE__*/React.createElement(SearchItems, {
336
+ data: filteredParameters,
337
+ height: dropdownMaxHeight,
338
+ highlight: value,
339
+ itemRender: itemRender,
340
+ onItemClick: function onItemClick(item) {
341
+ return _this3.selectFilter(item);
342
+ },
343
+ rowHeight: rowHeight,
344
+ width: itemsListWidth,
345
+ listProps: _objectSpread({
346
+ scrollTop: getParametersScrollTop({
347
+ scrollTop: scrollbarScrollTop,
348
+ recent: filteredRecent,
349
+ rowHeight: recentDisplayProps.rowHeight
350
+ })
351
+ }, listProps || {})
352
+ }));
353
+ };
354
+
355
+ _proto.renderSuggestions = function renderSuggestions() {
356
+ var _this4 = this;
357
+
358
+ var _this$props10 = this.props,
359
+ suggestions = _this$props10.suggestions,
360
+ parameterValue = _this$props10.parameterValue,
361
+ suggestionsDisplayProps = _this$props10.suggestionsDisplayProps,
362
+ value = _this$props10.value,
363
+ dropdownMaxHeight = _this$props10.dropdownMaxHeight;
364
+ var _this$state4 = this.state,
365
+ isResultChosen = _this$state4.isResultChosen,
366
+ itemsListWidth = _this$state4.itemsListWidth,
367
+ filteredSuggestions = _this$state4.filteredSuggestions,
368
+ scrollbarScrollTop = _this$state4.scrollbarScrollTop;
369
+ return suggestions && suggestionsDisplayProps && parameterValue && !isResultChosen && filteredSuggestions && hasSomeElement(filteredSuggestions) && /*#__PURE__*/React.createElement(React.Fragment, null, !!suggestionsDisplayProps.title && /*#__PURE__*/React.createElement(SearchHeader, {
370
+ headerText: suggestionsDisplayProps.title,
371
+ tooltip: suggestionsDisplayProps.tooltip
372
+ }), /*#__PURE__*/React.createElement(SearchItems, {
373
+ data: filteredSuggestions,
374
+ height: dropdownMaxHeight,
375
+ highlight: value,
376
+ itemRender: suggestionsDisplayProps.itemRender,
377
+ onItemClick: function onItemClick(item) {
378
+ return _this4.selectResult(item, SelectResultDataKeys.SUGGESTIONS);
379
+ },
380
+ rowHeight: suggestionsDisplayProps.rowHeight,
381
+ width: itemsListWidth,
382
+ listProps: _objectSpread({
383
+ scrollTop: scrollbarScrollTop
384
+ }, suggestionsDisplayProps.listProps || {})
385
+ }));
386
+ };
387
+
388
+ _proto.renderInputWrapper = function renderInputWrapper() {
389
+ var _this5 = this;
390
+
391
+ var _this$props11 = this.props,
392
+ placeholder = _this$props11.placeholder,
393
+ clearTooltip = _this$props11.clearTooltip,
394
+ value = _this$props11.value,
395
+ textLookupConfig = _this$props11.textLookupConfig,
396
+ filterLookupKey = _this$props11.filterLookupKey,
397
+ disableInput = _this$props11.disableInput,
398
+ inputProps = _this$props11.inputProps;
399
+ var _this$state5 = this.state,
400
+ label = _this$state5.label,
401
+ focusInputTrigger = _this$state5.focusInputTrigger,
402
+ toggleInputTrigger = _this$state5.toggleInputTrigger,
403
+ moveCursorToEnd = _this$state5.moveCursorToEnd;
404
+ return /*#__PURE__*/React.createElement(SearchInput, {
405
+ alwaysHighlight: true,
406
+ clearTooltip: clearTooltip,
407
+ filterLookupKey: filterLookupKey,
408
+ textLookupKey: textLookupConfig.parameters,
409
+ filterLabel: label,
410
+ focusTrigger: focusInputTrigger,
411
+ onButtonClick: function onButtonClick() {
412
+ return _this5.setState({
413
+ focusInputTrigger: !focusInputTrigger
414
+ });
415
+ },
416
+ onChange: function onChange(newValue) {
417
+ return _this5.handleChange(newValue);
418
+ },
419
+ onClear: this.handleClearValue,
420
+ onClick: function onClick() {
421
+ return _this5.setState({
422
+ isListVisible: true,
423
+ itemsListWidth: _this5.getSearchWrapperWidth()
424
+ });
425
+ },
426
+ onKeyDown: function onKeyDown(e) {
427
+ return _this5.onKeyDown(e);
428
+ },
429
+ onToggle: function onToggle(toggle) {
430
+ _this5.setState({
431
+ isListVisible: toggle,
432
+ isInputOpen: toggle
433
+ });
434
+
435
+ setTimeout(function () {
436
+ _this5.setState({
437
+ itemsListWidth: _this5.getSearchWrapperWidth()
509
438
  });
510
- },
511
- style: style
512
- }, this.renderInputWrapper(), isListVisible && /*#__PURE__*/React.createElement(S.SearchDropdownWrapper, {
513
- onClick: function onClick() {
439
+ }, INPUT_EXPAND_ANIMATION_DURATION);
440
+ },
441
+ placeholder: placeholder,
442
+ toggleTrigger: toggleInputTrigger,
443
+ value: value,
444
+ moveCursorToEnd: moveCursorToEnd,
445
+ disableInput: disableInput,
446
+ inputProps: inputProps
447
+ });
448
+ };
449
+
450
+ _proto.render = function render() {
451
+ var _this6 = this;
452
+
453
+ var _this$props12 = this.props,
454
+ divider = _this$props12.divider,
455
+ dropdownMaxHeight = _this$props12.dropdownMaxHeight,
456
+ width = _this$props12.width,
457
+ style = _this$props12.style;
458
+ var _this$state6 = this.state,
459
+ isInputOpen = _this$state6.isInputOpen,
460
+ label = _this$state6.label,
461
+ isListVisible = _this$state6.isListVisible,
462
+ focusInputTrigger = _this$state6.focusInputTrigger,
463
+ isResultChosen = _this$state6.isResultChosen,
464
+ filteredParameters = _this$state6.filteredParameters,
465
+ filteredRecent = _this$state6.filteredRecent;
466
+ return /*#__PURE__*/React.createElement(S.SearchWrapper, {
467
+ ref: this.wrapperRef,
468
+ className: "SearchWrapper",
469
+ inputOpen: isInputOpen,
470
+ width: width,
471
+ onKeyDown: function onKeyDown(e) {
472
+ focusWithArrowKeys(e, 'ds-search-item', function () {
514
473
  _this6.setState({
515
474
  focusInputTrigger: !focusInputTrigger
516
475
  });
517
- }
518
- }, /*#__PURE__*/React.createElement(S.SearchDropdownContent, {
519
- maxHeight: dropdownMaxHeight,
520
- className: isInputOpen && !isResultChosen && this.isListItemRendered() ? 'search-list-open' : ''
521
- }, /*#__PURE__*/React.createElement(Scrollbar, {
522
- absolute: true,
523
- maxHeight: dropdownMaxHeight - SCROLLBAR_HEIGHT_OFFSET,
524
- onScroll: function onScroll(_ref2) {
525
- var currentTarget = _ref2.currentTarget;
526
-
527
- _this6.setState({
528
- scrollbarScrollTop: currentTarget.scrollTop
529
- });
530
- }
531
- }, this.renderRecentItems(), !!(filteredParameters !== null && filteredParameters !== void 0 && filteredParameters.length) && !!(filteredRecent !== null && filteredRecent !== void 0 && filteredRecent.length) && !label && divider, this.renderParameters(), this.renderSuggestions()))));
532
- }
533
- }]);
476
+ });
477
+ },
478
+ style: style
479
+ }, this.renderInputWrapper(), isListVisible && /*#__PURE__*/React.createElement(S.SearchDropdownWrapper, {
480
+ onClick: function onClick() {
481
+ _this6.setState({
482
+ focusInputTrigger: !focusInputTrigger
483
+ });
484
+ }
485
+ }, /*#__PURE__*/React.createElement(S.SearchDropdownContent, {
486
+ maxHeight: dropdownMaxHeight,
487
+ className: isInputOpen && !isResultChosen && this.isListItemRendered() ? 'search-list-open' : ''
488
+ }, /*#__PURE__*/React.createElement(Scrollbar, {
489
+ absolute: true,
490
+ maxHeight: dropdownMaxHeight - SCROLLBAR_HEIGHT_OFFSET,
491
+ onScroll: function onScroll(_ref2) {
492
+ var currentTarget = _ref2.currentTarget;
493
+
494
+ _this6.setState({
495
+ scrollbarScrollTop: currentTarget.scrollTop
496
+ });
497
+ }
498
+ }, this.renderRecentItems(), !!(filteredParameters != null && filteredParameters.length) && !!(filteredRecent != null && filteredRecent.length) && !label && divider, this.renderParameters(), this.renderSuggestions()))));
499
+ };
534
500
 
535
501
  return Search;
536
502
  }(React.PureComponent);