@appbaseio/reactivesearch-vue 1.36.0 → 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;
@@ -447,6 +448,7 @@ var DataSearch = {
447
448
  _this.getRecentSearches();
448
449
  }
449
450
  if (isTagsMode) {
451
+ var isTagAdded = false;
450
452
  if (Array.isArray(_this.selectedTags) && _this.selectedTags.length) {
451
453
  // check if value already present in selectedTags
452
454
  if (typeof value === 'string' && _this.selectedTags.includes(value)) {
@@ -455,14 +457,36 @@ var DataSearch = {
455
457
  }
456
458
  _this.selectedTags = [].concat(_this.selectedTags);
457
459
  if (typeof value === 'string' && !!value) {
458
- _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
+ }
459
467
  } else if (Array.isArray(value) && !isEqual(_this.selectedTags, value)) {
460
- _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
+ }
461
475
  }
462
476
  } else if (value) {
463
- _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 = '';
464
489
  }
465
- _this.currentValue = '';
466
490
  } else {
467
491
  _this.currentValue = value;
468
492
  }
@@ -482,7 +506,7 @@ var DataSearch = {
482
506
  if (props.strictSelection && props.autosuggest) {
483
507
  if (cause === causes.SUGGESTION_SELECT || props.value !== undefined) {
484
508
  _this.updateQueryHandler(props.componentId, queryHandlerValue, props);
485
- } else if (_this.currentValue !== '') {
509
+ } else if (_this.currentValue !== '' && !props.strictSelection) {
486
510
  _this.setValue('', true);
487
511
  }
488
512
  } else {
@@ -496,7 +520,7 @@ var DataSearch = {
496
520
  _this.$emit('value-change', value);
497
521
  // Set the already fetched suggestions if query is same as used last to fetch the hits
498
522
  if (value === _this.lastUsedQuery) {
499
- _this.suggestions = _this.onSuggestions(_this.suggestions);
523
+ _this.normalizedSuggestions = _this.onSuggestions(_this.suggestions);
500
524
  // invoke on suggestions
501
525
  _this.$emit('suggestions', _this.suggestions);
502
526
  } else if (!value) {
@@ -606,17 +630,17 @@ var DataSearch = {
606
630
  var targetValue = event.target.value;
607
631
  var _this$$props2 = this.$props,
608
632
  value = _this$$props2.value,
609
- strictSelection = _this$$props2.strictSelection,
610
- size = _this$$props2.size,
611
- autosuggest = _this$$props2.autosuggest;
633
+ size = _this$$props2.size;
612
634
  if (value !== undefined) {
613
635
  this.isPending = true;
614
636
  }
615
637
  // if a suggestion was selected, delegate the handling to suggestion handler
616
638
  if (event.key === 'Enter' && (highlightedIndex === null || highlightedIndex < 0 || highlightedIndex === [].concat([].concat(this.suggestionsList).slice(0, size || 10), this.defaultSearchSuggestions, this.topSuggestions).length)) {
617
639
  this.isPending = false;
618
- this.setValue(this.$options.isTagsMode && autosuggest && strictSelection ? '' : targetValue, true, this.$props, undefined, false);
619
- 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
+ }
620
644
  }
621
645
  // Need to review
622
646
  this.$emit('keyDown', event, this.triggerQuery);
@@ -652,11 +676,16 @@ var DataSearch = {
652
676
  }
653
677
  },
654
678
  onSuggestionSelected: function onSuggestionSelected(suggestion) {
679
+ var _this3 = this;
655
680
  var value = this.$props.value;
656
681
  // Record analytics for selected suggestions
657
682
  this.triggerClickAnalytics(suggestion._click_id);
658
683
  if (value === undefined) {
659
684
  this.setValue(suggestion.value, true, this.$props, causes.SUGGESTION_SELECT);
685
+ this.isSuggestionSelected = true;
686
+ setTimeout(function () {
687
+ _this3.isSuggestionSelected = false;
688
+ }, 50);
660
689
  } else if (this.$options.isTagsMode) {
661
690
  var emitValue = Array.isArray(this.selectedTags) ? [].concat(this.selectedTags) : [];
662
691
  if (this.selectedTags.includes(suggestion.value)) {
@@ -762,7 +791,7 @@ var DataSearch = {
762
791
  return null;
763
792
  },
764
793
  renderTag: function renderTag(item) {
765
- var _this3 = this;
794
+ var _this4 = this;
766
795
  var h = this.$createElement;
767
796
  var innerClass = this.$props.innerClass;
768
797
  return h(TagItem, {
@@ -775,7 +804,7 @@ var DataSearch = {
775
804
  "class": "close-icon",
776
805
  "on": {
777
806
  "click": function click() {
778
- return _this3.clearTag(item);
807
+ return _this4.clearTag(item);
779
808
  }
780
809
  }
781
810
  }, [h(CancelSvg)])]);
@@ -797,7 +826,7 @@ var DataSearch = {
797
826
  }
798
827
  },
799
828
  renderTags: function renderTags() {
800
- var _this4 = this;
829
+ var _this5 = this;
801
830
  var h = this.$createElement;
802
831
  if (!Array.isArray(this.selectedTags)) {
803
832
  return null;
@@ -810,7 +839,7 @@ var DataSearch = {
810
839
  handleClear: this.clearTag,
811
840
  handleClearAll: this.clearAllTags
812
841
  }) : h(TagsContainer, [tagsList.map(function (item) {
813
- return _this4.renderTag(item);
842
+ return _this5.renderTag(item);
814
843
  }), shouldRenderClearAllTag && h(TagItem, {
815
844
  "class": getClassName(this.$props.innerClass, 'selected-tag') || ''
816
845
  }, [h("span", ["Clear All"]), h("span", {
@@ -889,7 +918,7 @@ var DataSearch = {
889
918
  (_this$$refs = this.$refs) == null || (_this$$refs = _this$$refs[this.$props.innerRef]) == null ? void 0 : _this$$refs.focus(); // eslint-disable-line
890
919
  },
891
920
  listenForFocusShortcuts: function listenForFocusShortcuts() {
892
- var _this5 = this;
921
+ var _this6 = this;
893
922
  var _this$$props$focusSho = this.$props.focusShortcuts,
894
923
  focusShortcuts = _this$$props$focusSho === void 0 ? ['/'] : _this$$props$focusSho;
895
924
  if (isEmpty(focusShortcuts)) {
@@ -904,7 +933,7 @@ var DataSearch = {
904
933
  function (event, handler) {
905
934
  // Prevent the default refresh event under WINDOWS system
906
935
  event.preventDefault();
907
- _this5.focusSearchBox(event);
936
+ _this6.focusSearchBox(event);
908
937
  });
909
938
 
910
939
  // if one of modifier keys are used, they are handled below
@@ -914,7 +943,7 @@ var DataSearch = {
914
943
  for (var index = 0; index < modifierKeys.length; index += 1) {
915
944
  var element = modifierKeys[index];
916
945
  if (hotkeys[element]) {
917
- _this5.focusSearchBox(event);
946
+ _this6.focusSearchBox(event);
918
947
  break;
919
948
  }
920
949
  }
@@ -922,7 +951,7 @@ var DataSearch = {
922
951
  }
923
952
  },
924
953
  render: function render() {
925
- var _this6 = this;
954
+ var _this7 = this;
926
955
  var h = arguments[0];
927
956
  var _this$$props6 = this.$props,
928
957
  theme = _this$$props6.theme,
@@ -957,14 +986,14 @@ var DataSearch = {
957
986
  highlightedIndex = _ref4.highlightedIndex,
958
987
  setHighlightedIndex = _ref4.setHighlightedIndex;
959
988
  var renderSuggestionsContainer = function renderSuggestionsContainer() {
960
- return h("div", [_this6.hasCustomRenderer && _this6.getComponent({
989
+ return h("div", [_this7.hasCustomRenderer && _this7.getComponent({
961
990
  isOpen: isOpen,
962
991
  getItemProps: getItemProps,
963
992
  getItemEvents: getItemEvents,
964
993
  highlightedIndex: highlightedIndex
965
- }), _this6.renderErrorComponent(), !_this6.hasCustomRenderer && isOpen && hasSuggestions ? h("ul", {
966
- "class": suggestions(_this6.themePreset, theme) + " " + getClassName(_this6.$props.innerClass, 'list')
967
- }, [_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) {
968
997
  return h("li", {
969
998
  "domProps": _extends({}, getItemProps({
970
999
  item: item
@@ -974,15 +1003,15 @@ var DataSearch = {
974
1003
  })),
975
1004
  "key": index + 1 + "-" + item.value,
976
1005
  "style": {
977
- backgroundColor: _this6.getBackgroundColor(highlightedIndex, index)
1006
+ backgroundColor: _this7.getBackgroundColor(highlightedIndex, index)
978
1007
  }
979
1008
  }, [h(SuggestionItem, {
980
1009
  "attrs": {
981
- "currentValue": _this6.currentValue,
1010
+ "currentValue": _this7.currentValue,
982
1011
  "suggestion": item
983
1012
  }
984
1013
  })]);
985
- }), _this6.defaultSearchSuggestions.map(function (sugg, index) {
1014
+ }), _this7.defaultSearchSuggestions.map(function (sugg, index) {
986
1015
  return h("li", {
987
1016
  "domProps": _extends({}, getItemProps({
988
1017
  item: sugg
@@ -990,9 +1019,9 @@ var DataSearch = {
990
1019
  "on": _extends({}, getItemEvents({
991
1020
  item: sugg
992
1021
  })),
993
- "key": _this6.suggestionsList.length + index + 1 + "-" + sugg.value,
1022
+ "key": _this7.suggestionsList.length + index + 1 + "-" + sugg.value,
994
1023
  "style": {
995
- backgroundColor: _this6.getBackgroundColor(highlightedIndex, _this6.suggestionsList.length + index),
1024
+ backgroundColor: _this7.getBackgroundColor(highlightedIndex, _this7.suggestionsList.length + index),
996
1025
  justifyContent: 'flex-start'
997
1026
  }
998
1027
  }, [h("div", {
@@ -1001,28 +1030,28 @@ var DataSearch = {
1001
1030
  }
1002
1031
  }, [sugg.source && sugg.source._recent_search && h(CustomSvg, {
1003
1032
  "attrs": {
1004
- "className": getClassName(_this6.$props.innerClass, 'recent-search-icon') || null,
1033
+ "className": getClassName(_this7.$props.innerClass, 'recent-search-icon') || null,
1005
1034
  "icon": recentSearchesIcon,
1006
1035
  "type": "recent-search-icon"
1007
1036
  }
1008
1037
  }), sugg.source && sugg.source._popular_suggestion && h(CustomSvg, {
1009
1038
  "attrs": {
1010
- "className": getClassName(_this6.$props.innerClass, 'popular-search-icon') || null,
1039
+ "className": getClassName(_this7.$props.innerClass, 'popular-search-icon') || null,
1011
1040
  "icon": popularSearchesIcon,
1012
1041
  "type": "popular-search-icon"
1013
1042
  }
1014
1043
  })]), h(SuggestionItem, {
1015
1044
  "attrs": {
1016
- "currentValue": _this6.currentValue,
1045
+ "currentValue": _this7.currentValue,
1017
1046
  "suggestion": sugg
1018
1047
  }
1019
1048
  })]);
1020
- }), hasQuerySuggestionsRenderer(_this6) ? _this6.getComponent({
1049
+ }), hasQuerySuggestionsRenderer(_this7) ? _this7.getComponent({
1021
1050
  isOpen: isOpen,
1022
1051
  getItemProps: getItemProps,
1023
1052
  getItemEvents: getItemEvents,
1024
1053
  highlightedIndex: highlightedIndex
1025
- }, true) : _this6.topSuggestions.map(function (sugg, index) {
1054
+ }, true) : _this7.topSuggestions.map(function (sugg, index) {
1026
1055
  return h("li", {
1027
1056
  "domProps": _extends({}, getItemProps({
1028
1057
  item: sugg
@@ -1030,9 +1059,9 @@ var DataSearch = {
1030
1059
  "on": _extends({}, getItemEvents({
1031
1060
  item: sugg
1032
1061
  })),
1033
- "key": _this6.suggestionsList.length + index + 1 + "-" + sugg.value,
1062
+ "key": _this7.suggestionsList.length + index + 1 + "-" + sugg.value,
1034
1063
  "style": {
1035
- backgroundColor: _this6.getBackgroundColor(highlightedIndex, _this6.suggestionsList.length + index),
1064
+ backgroundColor: _this7.getBackgroundColor(highlightedIndex, _this7.suggestionsList.length + index),
1036
1065
  justifyContent: 'flex-start'
1037
1066
  }
1038
1067
  }, [h("div", {
@@ -1041,58 +1070,58 @@ var DataSearch = {
1041
1070
  }
1042
1071
  }, [h(CustomSvg, {
1043
1072
  "attrs": {
1044
- "className": getClassName(_this6.$props.innerClass, 'popular-search-icon') || null,
1073
+ "className": getClassName(_this7.$props.innerClass, 'popular-search-icon') || null,
1045
1074
  "icon": popularSearchesIcon,
1046
1075
  "type": "popular-search-icon"
1047
1076
  }
1048
1077
  })]), h(SuggestionItem, {
1049
1078
  "attrs": {
1050
- "currentValue": _this6.currentValue,
1079
+ "currentValue": _this7.currentValue,
1051
1080
  "suggestion": sugg
1052
1081
  }
1053
1082
  })]);
1054
- })]) : _this6.renderNoSuggestions(_this6.suggestionsList)]);
1083
+ })]) : _this7.renderNoSuggestions(_this7.suggestionsList)]);
1055
1084
  };
1056
1085
  return h("div", {
1057
1086
  "class": suggestionsContainer
1058
- }, [h(InputGroup, [_this6.renderInputAddonBefore(), h(InputWrapper, [h(Input, {
1087
+ }, [h(InputGroup, [_this7.renderInputAddonBefore(), h(InputWrapper, [h(Input, {
1059
1088
  "attrs": {
1060
- "id": _this6.$props.componentId + "-input",
1061
- "showIcon": _this6.$props.showIcon,
1062
- "showClear": _this6.$props.showClear,
1063
- "iconPosition": _this6.$props.iconPosition,
1064
- "placeholder": _this6.$props.placeholder,
1065
- "autoFocus": _this6.$props.autoFocus,
1066
- "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,
1067
1096
  "autocomplete": "off"
1068
1097
  },
1069
- "ref": _this6.$props.innerRef,
1070
- "class": getClassName(_this6.$props.innerClass, 'input'),
1098
+ "ref": _this7.$props.innerRef,
1099
+ "class": getClassName(_this7.$props.innerClass, 'input'),
1071
1100
  "on": _extends({}, getInputEvents({
1072
- onInput: _this6.onInputChange,
1101
+ onInput: _this7.onInputChange,
1073
1102
  onBlur: function onBlur(e) {
1074
- _this6.$emit('blur', e, _this6.triggerQuery);
1103
+ _this7.$emit('blur', e, _this7.triggerQuery);
1075
1104
  },
1076
- onFocus: _this6.handleFocus,
1105
+ onFocus: _this7.handleFocus,
1077
1106
  onKeyPress: function onKeyPress(e) {
1078
- _this6.$emit('keyPress', e, _this6.triggerQuery);
1079
- _this6.$emit('key-press', e, _this6.triggerQuery);
1107
+ _this7.$emit('keyPress', e, _this7.triggerQuery);
1108
+ _this7.$emit('key-press', e, _this7.triggerQuery);
1080
1109
  },
1081
1110
  onKeyDown: function onKeyDown(e) {
1082
- return _this6.handleKeyDown(e, highlightedIndex);
1111
+ return _this7.handleKeyDown(e, highlightedIndex);
1083
1112
  },
1084
1113
  onKeyUp: function onKeyUp(e) {
1085
- _this6.$emit('keyUp', e, _this6.triggerQuery);
1086
- _this6.$emit('key-up', e, _this6.triggerQuery);
1114
+ _this7.$emit('keyUp', e, _this7.triggerQuery);
1115
+ _this7.$emit('key-up', e, _this7.triggerQuery);
1087
1116
  },
1088
1117
  onClick: function onClick() {
1089
1118
  setHighlightedIndex(null);
1090
1119
  }
1091
1120
  })),
1092
1121
  "domProps": _extends({}, getInputProps({
1093
- 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
1094
1123
  }))
1095
- }), _this6.renderIcons(), !expandSuggestionsContainer && renderSuggestionsContainer()]), ' ', _this6.renderInputAddonAfter()]), expandSuggestionsContainer && renderSuggestionsContainer(), _this6.renderTags()]);
1124
+ }), _this7.renderIcons(), !expandSuggestionsContainer && renderSuggestionsContainer()]), ' ', _this7.renderInputAddonAfter()]), expandSuggestionsContainer && renderSuggestionsContainer(), _this7.renderTags()]);
1096
1125
  }
1097
1126
  }
1098
1127
  }) : h("div", {
@@ -1108,22 +1137,22 @@ var DataSearch = {
1108
1137
  },
1109
1138
  "on": _extends({}, {
1110
1139
  blur: function blur(e) {
1111
- _this6.$emit('blur', e, _this6.triggerQuery);
1140
+ _this7.$emit('blur', e, _this7.triggerQuery);
1112
1141
  },
1113
1142
  keypress: function keypress(e) {
1114
- _this6.$emit('keyPress', e, _this6.triggerQuery);
1115
- _this6.$emit('key-press', e, _this6.triggerQuery);
1143
+ _this7.$emit('keyPress', e, _this7.triggerQuery);
1144
+ _this7.$emit('key-press', e, _this7.triggerQuery);
1116
1145
  },
1117
1146
  input: this.onInputChange,
1118
1147
  focus: function focus(e) {
1119
- _this6.$emit('focus', e, _this6.triggerQuery);
1148
+ _this7.$emit('focus', e, _this7.triggerQuery);
1120
1149
  },
1121
1150
  keydown: function keydown(e) {
1122
- _this6.handleKeyDown(e, null);
1151
+ _this7.handleKeyDown(e, null);
1123
1152
  },
1124
1153
  keyup: function keyup(e) {
1125
- _this6.$emit('keyUp', e, _this6.triggerQuery);
1126
- _this6.$emit('key-up', e, _this6.triggerQuery);
1154
+ _this7.$emit('keyUp', e, _this7.triggerQuery);
1155
+ _this7.$emit('key-up', e, _this7.triggerQuery);
1127
1156
  }
1128
1157
  }),
1129
1158
  "domProps": _extends({}, {