@appbaseio/reactivesearch-vue 1.35.5 → 1.36.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -53,7 +53,8 @@ var DataSearch = {
53
53
  selectedTags: [],
54
54
  isOpen: false,
55
55
  normalizedSuggestions: [],
56
- isPending: false
56
+ isPending: false,
57
+ isSuggestionSelected: false
57
58
  };
58
59
  this.internalComponent = props.componentId + "__internal";
59
60
  return this.__state;
@@ -293,12 +294,23 @@ var DataSearch = {
293
294
  this.updateQueryHandler(this.componentId, this.$data.currentValue, this.$props);
294
295
  }
295
296
  },
297
+ isLoading: function isLoading(newVal) {
298
+ if (newVal) {
299
+ this.suggestions = [];
300
+ }
301
+ },
296
302
  suggestions: function suggestions(newVal) {
303
+ if (this.isLoading) {
304
+ this.normalizedSuggestions = [];
305
+ return;
306
+ }
297
307
  if (Array.isArray(newVal) && this.$data.currentValue.trim().length) {
298
308
  // shallow check allows us to set suggestions even if the next set
299
309
  // of suggestions are same as the current one
300
310
  this.$emit('suggestions', newVal);
301
- this.normalizedSuggestions = this.onSuggestions(newVal);
311
+ if (!isEqual(this.normalizedSuggestions, newVal)) {
312
+ this.normalizedSuggestions = this.onSuggestions(newVal);
313
+ }
302
314
  }
303
315
  },
304
316
  selectedValue: function selectedValue(newVal, oldVal) {
@@ -432,12 +444,11 @@ var DataSearch = {
432
444
  return;
433
445
  }
434
446
  // Refresh recent searches when value becomes empty
435
- if (!value && props.enableDefaultSuggestions === false) {
436
- _this.resetStoreForComponent(props.componentId);
437
- } else if (!value && _this.currentValue && _this.enableRecentSearches) {
447
+ if (props.enableDefaultSuggestions && !value && _this.currentValue && _this.enableRecentSearches) {
438
448
  _this.getRecentSearches();
439
449
  }
440
450
  if (isTagsMode) {
451
+ var isTagAdded = false;
441
452
  if (Array.isArray(_this.selectedTags) && _this.selectedTags.length) {
442
453
  // check if value already present in selectedTags
443
454
  if (typeof value === 'string' && _this.selectedTags.includes(value)) {
@@ -446,14 +457,36 @@ var DataSearch = {
446
457
  }
447
458
  _this.selectedTags = [].concat(_this.selectedTags);
448
459
  if (typeof value === 'string' && !!value) {
449
- _this.selectedTags.push(value);
460
+ if (props.strictSelection && cause === causes.SUGGESTION_SELECT) {
461
+ _this.selectedTags.push(value);
462
+ isTagAdded = true;
463
+ } else if (!props.strictSelection) {
464
+ _this.selectedTags.push(value);
465
+ isTagAdded = true;
466
+ }
450
467
  } else if (Array.isArray(value) && !isEqual(_this.selectedTags, value)) {
451
- _this.selectedTags = value;
468
+ if (props.strictSelection && cause === causes.SUGGESTION_SELECT) {
469
+ _this.selectedTags = value;
470
+ isTagAdded = true;
471
+ } else if (!props.strictSelection) {
472
+ _this.selectedTags.push(value);
473
+ isTagAdded = true;
474
+ }
452
475
  }
453
476
  } else if (value) {
454
- _this.selectedTags = typeof value !== 'string' ? value : [].concat(value);
477
+ if (props.strictSelection && cause === causes.SUGGESTION_SELECT) {
478
+ _this.selectedTags = typeof value !== 'string' ? value : [].concat(value);
479
+ isTagAdded = true;
480
+ } else if (!props.strictSelection) {
481
+ _this.selectedTags = typeof value !== 'string' ? value : [].concat(value);
482
+ isTagAdded = true;
483
+ }
484
+ }
485
+ if (props.strictSelection && !isTagAdded) {
486
+ _this.currentValue = value;
487
+ } else {
488
+ _this.currentValue = '';
455
489
  }
456
- _this.currentValue = '';
457
490
  } else {
458
491
  _this.currentValue = value;
459
492
  }
@@ -473,7 +506,7 @@ var DataSearch = {
473
506
  if (props.strictSelection && props.autosuggest) {
474
507
  if (cause === causes.SUGGESTION_SELECT || props.value !== undefined) {
475
508
  _this.updateQueryHandler(props.componentId, queryHandlerValue, props);
476
- } else if (_this.currentValue !== '') {
509
+ } else if (_this.currentValue !== '' && !props.strictSelection) {
477
510
  _this.setValue('', true);
478
511
  }
479
512
  } else {
@@ -487,12 +520,12 @@ var DataSearch = {
487
520
  _this.$emit('value-change', value);
488
521
  // Set the already fetched suggestions if query is same as used last to fetch the hits
489
522
  if (value === _this.lastUsedQuery) {
490
- _this.suggestions = _this.onSuggestions(_this.suggestions);
523
+ _this.normalizedSuggestions = _this.onSuggestions(_this.suggestions);
491
524
  // invoke on suggestions
492
525
  _this.$emit('suggestions', _this.suggestions);
493
526
  } else if (!value) {
494
527
  // reset suggestions
495
- _this.suggestions = [];
528
+ _this.normalizedSuggestions = [];
496
529
  // invoke on suggestions
497
530
  _this.$emit('suggestions', _this.suggestions);
498
531
  }
@@ -503,11 +536,6 @@ var DataSearch = {
503
536
  if (props === void 0) {
504
537
  props = this.$props;
505
538
  }
506
- if (!value && props.enableDefaultSuggestions === false) {
507
- // clear Component data from store
508
- this.resetStoreForComponent(props.componentId);
509
- return;
510
- }
511
539
  var defaultQueryOptions;
512
540
  var query = DataSearch.defaultQuery(value, props);
513
541
  if (this.defaultQuery) {
@@ -602,17 +630,17 @@ var DataSearch = {
602
630
  var targetValue = event.target.value;
603
631
  var _this$$props2 = this.$props,
604
632
  value = _this$$props2.value,
605
- strictSelection = _this$$props2.strictSelection,
606
- size = _this$$props2.size,
607
- autosuggest = _this$$props2.autosuggest;
633
+ size = _this$$props2.size;
608
634
  if (value !== undefined) {
609
635
  this.isPending = true;
610
636
  }
611
637
  // if a suggestion was selected, delegate the handling to suggestion handler
612
638
  if (event.key === 'Enter' && (highlightedIndex === null || highlightedIndex < 0 || highlightedIndex === [].concat([].concat(this.suggestionsList).slice(0, size || 10), this.defaultSearchSuggestions, this.topSuggestions).length)) {
613
639
  this.isPending = false;
614
- this.setValue(this.$options.isTagsMode && autosuggest && strictSelection ? '' : targetValue, true, this.$props, undefined, false);
615
- this.onValueSelectedHandler(targetValue, causes.ENTER_PRESS);
640
+ if (!this.isSuggestionSelected) {
641
+ this.setValue(targetValue, true, this.$props, undefined, false);
642
+ this.onValueSelectedHandler(targetValue, causes.ENTER_PRESS);
643
+ }
616
644
  }
617
645
  // Need to review
618
646
  this.$emit('keyDown', event, this.triggerQuery);
@@ -648,11 +676,16 @@ var DataSearch = {
648
676
  }
649
677
  },
650
678
  onSuggestionSelected: function onSuggestionSelected(suggestion) {
679
+ var _this3 = this;
651
680
  var value = this.$props.value;
652
681
  // Record analytics for selected suggestions
653
682
  this.triggerClickAnalytics(suggestion._click_id);
654
683
  if (value === undefined) {
655
684
  this.setValue(suggestion.value, true, this.$props, causes.SUGGESTION_SELECT);
685
+ this.isSuggestionSelected = true;
686
+ setTimeout(function () {
687
+ _this3.isSuggestionSelected = false;
688
+ }, 50);
656
689
  } else if (this.$options.isTagsMode) {
657
690
  var emitValue = Array.isArray(this.selectedTags) ? [].concat(this.selectedTags) : [];
658
691
  if (this.selectedTags.includes(suggestion.value)) {
@@ -758,7 +791,7 @@ var DataSearch = {
758
791
  return null;
759
792
  },
760
793
  renderTag: function renderTag(item) {
761
- var _this3 = this;
794
+ var _this4 = this;
762
795
  var h = this.$createElement;
763
796
  var innerClass = this.$props.innerClass;
764
797
  return h(TagItem, {
@@ -771,7 +804,7 @@ var DataSearch = {
771
804
  "class": "close-icon",
772
805
  "on": {
773
806
  "click": function click() {
774
- return _this3.clearTag(item);
807
+ return _this4.clearTag(item);
775
808
  }
776
809
  }
777
810
  }, [h(CancelSvg)])]);
@@ -793,7 +826,7 @@ var DataSearch = {
793
826
  }
794
827
  },
795
828
  renderTags: function renderTags() {
796
- var _this4 = this;
829
+ var _this5 = this;
797
830
  var h = this.$createElement;
798
831
  if (!Array.isArray(this.selectedTags)) {
799
832
  return null;
@@ -806,7 +839,7 @@ var DataSearch = {
806
839
  handleClear: this.clearTag,
807
840
  handleClearAll: this.clearAllTags
808
841
  }) : h(TagsContainer, [tagsList.map(function (item) {
809
- return _this4.renderTag(item);
842
+ return _this5.renderTag(item);
810
843
  }), shouldRenderClearAllTag && h(TagItem, {
811
844
  "class": getClassName(this.$props.innerClass, 'selected-tag') || ''
812
845
  }, [h("span", ["Clear All"]), h("span", {
@@ -885,7 +918,7 @@ var DataSearch = {
885
918
  (_this$$refs = this.$refs) == null || (_this$$refs = _this$$refs[this.$props.innerRef]) == null ? void 0 : _this$$refs.focus(); // eslint-disable-line
886
919
  },
887
920
  listenForFocusShortcuts: function listenForFocusShortcuts() {
888
- var _this5 = this;
921
+ var _this6 = this;
889
922
  var _this$$props$focusSho = this.$props.focusShortcuts,
890
923
  focusShortcuts = _this$$props$focusSho === void 0 ? ['/'] : _this$$props$focusSho;
891
924
  if (isEmpty(focusShortcuts)) {
@@ -900,7 +933,7 @@ var DataSearch = {
900
933
  function (event, handler) {
901
934
  // Prevent the default refresh event under WINDOWS system
902
935
  event.preventDefault();
903
- _this5.focusSearchBox(event);
936
+ _this6.focusSearchBox(event);
904
937
  });
905
938
 
906
939
  // if one of modifier keys are used, they are handled below
@@ -910,7 +943,7 @@ var DataSearch = {
910
943
  for (var index = 0; index < modifierKeys.length; index += 1) {
911
944
  var element = modifierKeys[index];
912
945
  if (hotkeys[element]) {
913
- _this5.focusSearchBox(event);
946
+ _this6.focusSearchBox(event);
914
947
  break;
915
948
  }
916
949
  }
@@ -918,7 +951,7 @@ var DataSearch = {
918
951
  }
919
952
  },
920
953
  render: function render() {
921
- var _this6 = this;
954
+ var _this7 = this;
922
955
  var h = arguments[0];
923
956
  var _this$$props6 = this.$props,
924
957
  theme = _this$$props6.theme,
@@ -953,14 +986,14 @@ var DataSearch = {
953
986
  highlightedIndex = _ref4.highlightedIndex,
954
987
  setHighlightedIndex = _ref4.setHighlightedIndex;
955
988
  var renderSuggestionsContainer = function renderSuggestionsContainer() {
956
- return h("div", [_this6.hasCustomRenderer && _this6.getComponent({
989
+ return h("div", [_this7.hasCustomRenderer && _this7.getComponent({
957
990
  isOpen: isOpen,
958
991
  getItemProps: getItemProps,
959
992
  getItemEvents: getItemEvents,
960
993
  highlightedIndex: highlightedIndex
961
- }), _this6.renderErrorComponent(), !_this6.hasCustomRenderer && isOpen && hasSuggestions ? h("ul", {
962
- "class": suggestions(_this6.themePreset, theme) + " " + getClassName(_this6.$props.innerClass, 'list')
963
- }, [_this6.suggestionsList.slice(0, size || 10).map(function (item, index) {
994
+ }), _this7.renderErrorComponent(), !_this7.hasCustomRenderer && isOpen && hasSuggestions ? h("ul", {
995
+ "class": suggestions(_this7.themePreset, theme) + " " + getClassName(_this7.$props.innerClass, 'list')
996
+ }, [_this7.suggestionsList.slice(0, size || 10).map(function (item, index) {
964
997
  return h("li", {
965
998
  "domProps": _extends({}, getItemProps({
966
999
  item: item
@@ -970,15 +1003,15 @@ var DataSearch = {
970
1003
  })),
971
1004
  "key": index + 1 + "-" + item.value,
972
1005
  "style": {
973
- backgroundColor: _this6.getBackgroundColor(highlightedIndex, index)
1006
+ backgroundColor: _this7.getBackgroundColor(highlightedIndex, index)
974
1007
  }
975
1008
  }, [h(SuggestionItem, {
976
1009
  "attrs": {
977
- "currentValue": _this6.currentValue,
1010
+ "currentValue": _this7.currentValue,
978
1011
  "suggestion": item
979
1012
  }
980
1013
  })]);
981
- }), _this6.defaultSearchSuggestions.map(function (sugg, index) {
1014
+ }), _this7.defaultSearchSuggestions.map(function (sugg, index) {
982
1015
  return h("li", {
983
1016
  "domProps": _extends({}, getItemProps({
984
1017
  item: sugg
@@ -986,9 +1019,9 @@ var DataSearch = {
986
1019
  "on": _extends({}, getItemEvents({
987
1020
  item: sugg
988
1021
  })),
989
- "key": _this6.suggestionsList.length + index + 1 + "-" + sugg.value,
1022
+ "key": _this7.suggestionsList.length + index + 1 + "-" + sugg.value,
990
1023
  "style": {
991
- backgroundColor: _this6.getBackgroundColor(highlightedIndex, _this6.suggestionsList.length + index),
1024
+ backgroundColor: _this7.getBackgroundColor(highlightedIndex, _this7.suggestionsList.length + index),
992
1025
  justifyContent: 'flex-start'
993
1026
  }
994
1027
  }, [h("div", {
@@ -997,28 +1030,28 @@ var DataSearch = {
997
1030
  }
998
1031
  }, [sugg.source && sugg.source._recent_search && h(CustomSvg, {
999
1032
  "attrs": {
1000
- "className": getClassName(_this6.$props.innerClass, 'recent-search-icon') || null,
1033
+ "className": getClassName(_this7.$props.innerClass, 'recent-search-icon') || null,
1001
1034
  "icon": recentSearchesIcon,
1002
1035
  "type": "recent-search-icon"
1003
1036
  }
1004
1037
  }), sugg.source && sugg.source._popular_suggestion && h(CustomSvg, {
1005
1038
  "attrs": {
1006
- "className": getClassName(_this6.$props.innerClass, 'popular-search-icon') || null,
1039
+ "className": getClassName(_this7.$props.innerClass, 'popular-search-icon') || null,
1007
1040
  "icon": popularSearchesIcon,
1008
1041
  "type": "popular-search-icon"
1009
1042
  }
1010
1043
  })]), h(SuggestionItem, {
1011
1044
  "attrs": {
1012
- "currentValue": _this6.currentValue,
1045
+ "currentValue": _this7.currentValue,
1013
1046
  "suggestion": sugg
1014
1047
  }
1015
1048
  })]);
1016
- }), hasQuerySuggestionsRenderer(_this6) ? _this6.getComponent({
1049
+ }), hasQuerySuggestionsRenderer(_this7) ? _this7.getComponent({
1017
1050
  isOpen: isOpen,
1018
1051
  getItemProps: getItemProps,
1019
1052
  getItemEvents: getItemEvents,
1020
1053
  highlightedIndex: highlightedIndex
1021
- }, true) : _this6.topSuggestions.map(function (sugg, index) {
1054
+ }, true) : _this7.topSuggestions.map(function (sugg, index) {
1022
1055
  return h("li", {
1023
1056
  "domProps": _extends({}, getItemProps({
1024
1057
  item: sugg
@@ -1026,9 +1059,9 @@ var DataSearch = {
1026
1059
  "on": _extends({}, getItemEvents({
1027
1060
  item: sugg
1028
1061
  })),
1029
- "key": _this6.suggestionsList.length + index + 1 + "-" + sugg.value,
1062
+ "key": _this7.suggestionsList.length + index + 1 + "-" + sugg.value,
1030
1063
  "style": {
1031
- backgroundColor: _this6.getBackgroundColor(highlightedIndex, _this6.suggestionsList.length + index),
1064
+ backgroundColor: _this7.getBackgroundColor(highlightedIndex, _this7.suggestionsList.length + index),
1032
1065
  justifyContent: 'flex-start'
1033
1066
  }
1034
1067
  }, [h("div", {
@@ -1037,58 +1070,58 @@ var DataSearch = {
1037
1070
  }
1038
1071
  }, [h(CustomSvg, {
1039
1072
  "attrs": {
1040
- "className": getClassName(_this6.$props.innerClass, 'popular-search-icon') || null,
1073
+ "className": getClassName(_this7.$props.innerClass, 'popular-search-icon') || null,
1041
1074
  "icon": popularSearchesIcon,
1042
1075
  "type": "popular-search-icon"
1043
1076
  }
1044
1077
  })]), h(SuggestionItem, {
1045
1078
  "attrs": {
1046
- "currentValue": _this6.currentValue,
1079
+ "currentValue": _this7.currentValue,
1047
1080
  "suggestion": sugg
1048
1081
  }
1049
1082
  })]);
1050
- })]) : _this6.renderNoSuggestions(_this6.suggestionsList)]);
1083
+ })]) : _this7.renderNoSuggestions(_this7.suggestionsList)]);
1051
1084
  };
1052
1085
  return h("div", {
1053
1086
  "class": suggestionsContainer
1054
- }, [h(InputGroup, [_this6.renderInputAddonBefore(), h(InputWrapper, [h(Input, {
1087
+ }, [h(InputGroup, [_this7.renderInputAddonBefore(), h(InputWrapper, [h(Input, {
1055
1088
  "attrs": {
1056
- "id": _this6.$props.componentId + "-input",
1057
- "showIcon": _this6.$props.showIcon,
1058
- "showClear": _this6.$props.showClear,
1059
- "iconPosition": _this6.$props.iconPosition,
1060
- "placeholder": _this6.$props.placeholder,
1061
- "autoFocus": _this6.$props.autoFocus,
1062
- "themePreset": _this6.themePreset,
1089
+ "id": _this7.$props.componentId + "-input",
1090
+ "showIcon": _this7.$props.showIcon,
1091
+ "showClear": _this7.$props.showClear,
1092
+ "iconPosition": _this7.$props.iconPosition,
1093
+ "placeholder": _this7.$props.placeholder,
1094
+ "autoFocus": _this7.$props.autoFocus,
1095
+ "themePreset": _this7.themePreset,
1063
1096
  "autocomplete": "off"
1064
1097
  },
1065
- "ref": _this6.$props.innerRef,
1066
- "class": getClassName(_this6.$props.innerClass, 'input'),
1098
+ "ref": _this7.$props.innerRef,
1099
+ "class": getClassName(_this7.$props.innerClass, 'input'),
1067
1100
  "on": _extends({}, getInputEvents({
1068
- onInput: _this6.onInputChange,
1101
+ onInput: _this7.onInputChange,
1069
1102
  onBlur: function onBlur(e) {
1070
- _this6.$emit('blur', e, _this6.triggerQuery);
1103
+ _this7.$emit('blur', e, _this7.triggerQuery);
1071
1104
  },
1072
- onFocus: _this6.handleFocus,
1105
+ onFocus: _this7.handleFocus,
1073
1106
  onKeyPress: function onKeyPress(e) {
1074
- _this6.$emit('keyPress', e, _this6.triggerQuery);
1075
- _this6.$emit('key-press', e, _this6.triggerQuery);
1107
+ _this7.$emit('keyPress', e, _this7.triggerQuery);
1108
+ _this7.$emit('key-press', e, _this7.triggerQuery);
1076
1109
  },
1077
1110
  onKeyDown: function onKeyDown(e) {
1078
- return _this6.handleKeyDown(e, highlightedIndex);
1111
+ return _this7.handleKeyDown(e, highlightedIndex);
1079
1112
  },
1080
1113
  onKeyUp: function onKeyUp(e) {
1081
- _this6.$emit('keyUp', e, _this6.triggerQuery);
1082
- _this6.$emit('key-up', e, _this6.triggerQuery);
1114
+ _this7.$emit('keyUp', e, _this7.triggerQuery);
1115
+ _this7.$emit('key-up', e, _this7.triggerQuery);
1083
1116
  },
1084
1117
  onClick: function onClick() {
1085
1118
  setHighlightedIndex(null);
1086
1119
  }
1087
1120
  })),
1088
1121
  "domProps": _extends({}, getInputProps({
1089
- value: _this6.$data.currentValue === null || typeof _this6.$data.currentValue !== 'string' ? '' : _this6.$data.currentValue
1122
+ value: _this7.$data.currentValue === null || typeof _this7.$data.currentValue !== 'string' ? '' : _this7.$data.currentValue
1090
1123
  }))
1091
- }), _this6.renderIcons(), !expandSuggestionsContainer && renderSuggestionsContainer()]), ' ', _this6.renderInputAddonAfter()]), expandSuggestionsContainer && renderSuggestionsContainer(), _this6.renderTags()]);
1124
+ }), _this7.renderIcons(), !expandSuggestionsContainer && renderSuggestionsContainer()]), ' ', _this7.renderInputAddonAfter()]), expandSuggestionsContainer && renderSuggestionsContainer(), _this7.renderTags()]);
1092
1125
  }
1093
1126
  }
1094
1127
  }) : h("div", {
@@ -1104,22 +1137,22 @@ var DataSearch = {
1104
1137
  },
1105
1138
  "on": _extends({}, {
1106
1139
  blur: function blur(e) {
1107
- _this6.$emit('blur', e, _this6.triggerQuery);
1140
+ _this7.$emit('blur', e, _this7.triggerQuery);
1108
1141
  },
1109
1142
  keypress: function keypress(e) {
1110
- _this6.$emit('keyPress', e, _this6.triggerQuery);
1111
- _this6.$emit('key-press', e, _this6.triggerQuery);
1143
+ _this7.$emit('keyPress', e, _this7.triggerQuery);
1144
+ _this7.$emit('key-press', e, _this7.triggerQuery);
1112
1145
  },
1113
1146
  input: this.onInputChange,
1114
1147
  focus: function focus(e) {
1115
- _this6.$emit('focus', e, _this6.triggerQuery);
1148
+ _this7.$emit('focus', e, _this7.triggerQuery);
1116
1149
  },
1117
1150
  keydown: function keydown(e) {
1118
- _this6.handleKeyDown(e, null);
1151
+ _this7.handleKeyDown(e, null);
1119
1152
  },
1120
1153
  keyup: function keyup(e) {
1121
- _this6.$emit('keyUp', e, _this6.triggerQuery);
1122
- _this6.$emit('key-up', e, _this6.triggerQuery);
1154
+ _this7.$emit('keyUp', e, _this7.triggerQuery);
1155
+ _this7.$emit('key-up', e, _this7.triggerQuery);
1123
1156
  }
1124
1157
  }),
1125
1158
  "domProps": _extends({}, {