@appbaseio/reactivesearch-vue 1.35.2 → 1.35.3

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;
@@ -438,6 +439,7 @@ var DataSearch = {
438
439
  _this.getRecentSearches();
439
440
  }
440
441
  if (isTagsMode) {
442
+ var isTagAdded = false;
441
443
  if (Array.isArray(_this.selectedTags) && _this.selectedTags.length) {
442
444
  // check if value already present in selectedTags
443
445
  if (typeof value === 'string' && _this.selectedTags.includes(value)) {
@@ -446,14 +448,36 @@ var DataSearch = {
446
448
  }
447
449
  _this.selectedTags = [].concat(_this.selectedTags);
448
450
  if (typeof value === 'string' && !!value) {
449
- _this.selectedTags.push(value);
451
+ if (props.strictSelection && cause === causes.SUGGESTION_SELECT) {
452
+ _this.selectedTags.push(value);
453
+ isTagAdded = true;
454
+ } else if (!props.strictSelection) {
455
+ _this.selectedTags.push(value);
456
+ isTagAdded = true;
457
+ }
450
458
  } else if (Array.isArray(value) && !isEqual(_this.selectedTags, value)) {
451
- _this.selectedTags = value;
459
+ if (props.strictSelection && cause === causes.SUGGESTION_SELECT) {
460
+ _this.selectedTags = value;
461
+ isTagAdded = true;
462
+ } else if (!props.strictSelection) {
463
+ _this.selectedTags.push(value);
464
+ isTagAdded = true;
465
+ }
452
466
  }
453
467
  } else if (value) {
454
- _this.selectedTags = typeof value !== 'string' ? value : [].concat(value);
468
+ if (props.strictSelection && cause === causes.SUGGESTION_SELECT) {
469
+ _this.selectedTags = typeof value !== 'string' ? value : [].concat(value);
470
+ isTagAdded = true;
471
+ } else if (!props.strictSelection) {
472
+ _this.selectedTags = typeof value !== 'string' ? value : [].concat(value);
473
+ isTagAdded = true;
474
+ }
475
+ }
476
+ if (props.strictSelection && !isTagAdded) {
477
+ _this.currentValue = value;
478
+ } else {
479
+ _this.currentValue = '';
455
480
  }
456
- _this.currentValue = '';
457
481
  } else {
458
482
  _this.currentValue = value;
459
483
  }
@@ -473,7 +497,7 @@ var DataSearch = {
473
497
  if (props.strictSelection && props.autosuggest) {
474
498
  if (cause === causes.SUGGESTION_SELECT || props.value !== undefined) {
475
499
  _this.updateQueryHandler(props.componentId, queryHandlerValue, props);
476
- } else if (_this.currentValue !== '') {
500
+ } else if (_this.currentValue !== '' && !props.strictSelection) {
477
501
  _this.setValue('', true);
478
502
  }
479
503
  } else {
@@ -602,17 +626,17 @@ var DataSearch = {
602
626
  var targetValue = event.target.value;
603
627
  var _this$$props2 = this.$props,
604
628
  value = _this$$props2.value,
605
- strictSelection = _this$$props2.strictSelection,
606
- size = _this$$props2.size,
607
- autosuggest = _this$$props2.autosuggest;
629
+ size = _this$$props2.size;
608
630
  if (value !== undefined) {
609
631
  this.isPending = true;
610
632
  }
611
633
  // if a suggestion was selected, delegate the handling to suggestion handler
612
634
  if (event.key === 'Enter' && (highlightedIndex === null || highlightedIndex < 0 || highlightedIndex === [].concat([].concat(this.suggestionsList).slice(0, size || 10), this.defaultSearchSuggestions, this.topSuggestions).length)) {
613
635
  this.isPending = false;
614
- this.setValue(this.$options.isTagsMode && autosuggest && strictSelection ? '' : targetValue, true, this.$props, undefined, false);
615
- this.onValueSelectedHandler(targetValue, causes.ENTER_PRESS);
636
+ if (!this.isSuggestionSelected) {
637
+ this.setValue(targetValue, true, this.$props, undefined, false);
638
+ this.onValueSelectedHandler(targetValue, causes.ENTER_PRESS);
639
+ }
616
640
  }
617
641
  // Need to review
618
642
  this.$emit('keyDown', event, this.triggerQuery);
@@ -648,11 +672,16 @@ var DataSearch = {
648
672
  }
649
673
  },
650
674
  onSuggestionSelected: function onSuggestionSelected(suggestion) {
675
+ var _this3 = this;
651
676
  var value = this.$props.value;
652
677
  // Record analytics for selected suggestions
653
678
  this.triggerClickAnalytics(suggestion._click_id);
654
679
  if (value === undefined) {
655
680
  this.setValue(suggestion.value, true, this.$props, causes.SUGGESTION_SELECT);
681
+ this.isSuggestionSelected = true;
682
+ setTimeout(function () {
683
+ _this3.isSuggestionSelected = false;
684
+ }, 50);
656
685
  } else if (this.$options.isTagsMode) {
657
686
  var emitValue = Array.isArray(this.selectedTags) ? [].concat(this.selectedTags) : [];
658
687
  if (this.selectedTags.includes(suggestion.value)) {
@@ -758,7 +787,7 @@ var DataSearch = {
758
787
  return null;
759
788
  },
760
789
  renderTag: function renderTag(item) {
761
- var _this3 = this;
790
+ var _this4 = this;
762
791
  var h = this.$createElement;
763
792
  var innerClass = this.$props.innerClass;
764
793
  return h(TagItem, {
@@ -771,7 +800,7 @@ var DataSearch = {
771
800
  "class": "close-icon",
772
801
  "on": {
773
802
  "click": function click() {
774
- return _this3.clearTag(item);
803
+ return _this4.clearTag(item);
775
804
  }
776
805
  }
777
806
  }, [h(CancelSvg)])]);
@@ -793,7 +822,7 @@ var DataSearch = {
793
822
  }
794
823
  },
795
824
  renderTags: function renderTags() {
796
- var _this4 = this;
825
+ var _this5 = this;
797
826
  var h = this.$createElement;
798
827
  if (!Array.isArray(this.selectedTags)) {
799
828
  return null;
@@ -806,7 +835,7 @@ var DataSearch = {
806
835
  handleClear: this.clearTag,
807
836
  handleClearAll: this.clearAllTags
808
837
  }) : h(TagsContainer, [tagsList.map(function (item) {
809
- return _this4.renderTag(item);
838
+ return _this5.renderTag(item);
810
839
  }), shouldRenderClearAllTag && h(TagItem, {
811
840
  "class": getClassName(this.$props.innerClass, 'selected-tag') || ''
812
841
  }, [h("span", ["Clear All"]), h("span", {
@@ -885,7 +914,7 @@ var DataSearch = {
885
914
  (_this$$refs = this.$refs) == null || (_this$$refs = _this$$refs[this.$props.innerRef]) == null ? void 0 : _this$$refs.focus(); // eslint-disable-line
886
915
  },
887
916
  listenForFocusShortcuts: function listenForFocusShortcuts() {
888
- var _this5 = this;
917
+ var _this6 = this;
889
918
  var _this$$props$focusSho = this.$props.focusShortcuts,
890
919
  focusShortcuts = _this$$props$focusSho === void 0 ? ['/'] : _this$$props$focusSho;
891
920
  if (isEmpty(focusShortcuts)) {
@@ -900,7 +929,7 @@ var DataSearch = {
900
929
  function (event, handler) {
901
930
  // Prevent the default refresh event under WINDOWS system
902
931
  event.preventDefault();
903
- _this5.focusSearchBox(event);
932
+ _this6.focusSearchBox(event);
904
933
  });
905
934
 
906
935
  // if one of modifier keys are used, they are handled below
@@ -910,7 +939,7 @@ var DataSearch = {
910
939
  for (var index = 0; index < modifierKeys.length; index += 1) {
911
940
  var element = modifierKeys[index];
912
941
  if (hotkeys[element]) {
913
- _this5.focusSearchBox(event);
942
+ _this6.focusSearchBox(event);
914
943
  break;
915
944
  }
916
945
  }
@@ -918,7 +947,7 @@ var DataSearch = {
918
947
  }
919
948
  },
920
949
  render: function render() {
921
- var _this6 = this;
950
+ var _this7 = this;
922
951
  var h = arguments[0];
923
952
  var _this$$props6 = this.$props,
924
953
  theme = _this$$props6.theme,
@@ -953,14 +982,14 @@ var DataSearch = {
953
982
  highlightedIndex = _ref4.highlightedIndex,
954
983
  setHighlightedIndex = _ref4.setHighlightedIndex;
955
984
  var renderSuggestionsContainer = function renderSuggestionsContainer() {
956
- return h("div", [_this6.hasCustomRenderer && _this6.getComponent({
985
+ return h("div", [_this7.hasCustomRenderer && _this7.getComponent({
957
986
  isOpen: isOpen,
958
987
  getItemProps: getItemProps,
959
988
  getItemEvents: getItemEvents,
960
989
  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) {
990
+ }), _this7.renderErrorComponent(), !_this7.hasCustomRenderer && isOpen && hasSuggestions ? h("ul", {
991
+ "class": suggestions(_this7.themePreset, theme) + " " + getClassName(_this7.$props.innerClass, 'list')
992
+ }, [_this7.suggestionsList.slice(0, size || 10).map(function (item, index) {
964
993
  return h("li", {
965
994
  "domProps": _extends({}, getItemProps({
966
995
  item: item
@@ -970,15 +999,15 @@ var DataSearch = {
970
999
  })),
971
1000
  "key": index + 1 + "-" + item.value,
972
1001
  "style": {
973
- backgroundColor: _this6.getBackgroundColor(highlightedIndex, index)
1002
+ backgroundColor: _this7.getBackgroundColor(highlightedIndex, index)
974
1003
  }
975
1004
  }, [h(SuggestionItem, {
976
1005
  "attrs": {
977
- "currentValue": _this6.currentValue,
1006
+ "currentValue": _this7.currentValue,
978
1007
  "suggestion": item
979
1008
  }
980
1009
  })]);
981
- }), _this6.defaultSearchSuggestions.map(function (sugg, index) {
1010
+ }), _this7.defaultSearchSuggestions.map(function (sugg, index) {
982
1011
  return h("li", {
983
1012
  "domProps": _extends({}, getItemProps({
984
1013
  item: sugg
@@ -986,9 +1015,9 @@ var DataSearch = {
986
1015
  "on": _extends({}, getItemEvents({
987
1016
  item: sugg
988
1017
  })),
989
- "key": _this6.suggestionsList.length + index + 1 + "-" + sugg.value,
1018
+ "key": _this7.suggestionsList.length + index + 1 + "-" + sugg.value,
990
1019
  "style": {
991
- backgroundColor: _this6.getBackgroundColor(highlightedIndex, _this6.suggestionsList.length + index),
1020
+ backgroundColor: _this7.getBackgroundColor(highlightedIndex, _this7.suggestionsList.length + index),
992
1021
  justifyContent: 'flex-start'
993
1022
  }
994
1023
  }, [h("div", {
@@ -997,28 +1026,28 @@ var DataSearch = {
997
1026
  }
998
1027
  }, [sugg.source && sugg.source._recent_search && h(CustomSvg, {
999
1028
  "attrs": {
1000
- "className": getClassName(_this6.$props.innerClass, 'recent-search-icon') || null,
1029
+ "className": getClassName(_this7.$props.innerClass, 'recent-search-icon') || null,
1001
1030
  "icon": recentSearchesIcon,
1002
1031
  "type": "recent-search-icon"
1003
1032
  }
1004
1033
  }), sugg.source && sugg.source._popular_suggestion && h(CustomSvg, {
1005
1034
  "attrs": {
1006
- "className": getClassName(_this6.$props.innerClass, 'popular-search-icon') || null,
1035
+ "className": getClassName(_this7.$props.innerClass, 'popular-search-icon') || null,
1007
1036
  "icon": popularSearchesIcon,
1008
1037
  "type": "popular-search-icon"
1009
1038
  }
1010
1039
  })]), h(SuggestionItem, {
1011
1040
  "attrs": {
1012
- "currentValue": _this6.currentValue,
1041
+ "currentValue": _this7.currentValue,
1013
1042
  "suggestion": sugg
1014
1043
  }
1015
1044
  })]);
1016
- }), hasQuerySuggestionsRenderer(_this6) ? _this6.getComponent({
1045
+ }), hasQuerySuggestionsRenderer(_this7) ? _this7.getComponent({
1017
1046
  isOpen: isOpen,
1018
1047
  getItemProps: getItemProps,
1019
1048
  getItemEvents: getItemEvents,
1020
1049
  highlightedIndex: highlightedIndex
1021
- }, true) : _this6.topSuggestions.map(function (sugg, index) {
1050
+ }, true) : _this7.topSuggestions.map(function (sugg, index) {
1022
1051
  return h("li", {
1023
1052
  "domProps": _extends({}, getItemProps({
1024
1053
  item: sugg
@@ -1026,9 +1055,9 @@ var DataSearch = {
1026
1055
  "on": _extends({}, getItemEvents({
1027
1056
  item: sugg
1028
1057
  })),
1029
- "key": _this6.suggestionsList.length + index + 1 + "-" + sugg.value,
1058
+ "key": _this7.suggestionsList.length + index + 1 + "-" + sugg.value,
1030
1059
  "style": {
1031
- backgroundColor: _this6.getBackgroundColor(highlightedIndex, _this6.suggestionsList.length + index),
1060
+ backgroundColor: _this7.getBackgroundColor(highlightedIndex, _this7.suggestionsList.length + index),
1032
1061
  justifyContent: 'flex-start'
1033
1062
  }
1034
1063
  }, [h("div", {
@@ -1037,58 +1066,58 @@ var DataSearch = {
1037
1066
  }
1038
1067
  }, [h(CustomSvg, {
1039
1068
  "attrs": {
1040
- "className": getClassName(_this6.$props.innerClass, 'popular-search-icon') || null,
1069
+ "className": getClassName(_this7.$props.innerClass, 'popular-search-icon') || null,
1041
1070
  "icon": popularSearchesIcon,
1042
1071
  "type": "popular-search-icon"
1043
1072
  }
1044
1073
  })]), h(SuggestionItem, {
1045
1074
  "attrs": {
1046
- "currentValue": _this6.currentValue,
1075
+ "currentValue": _this7.currentValue,
1047
1076
  "suggestion": sugg
1048
1077
  }
1049
1078
  })]);
1050
- })]) : _this6.renderNoSuggestions(_this6.suggestionsList)]);
1079
+ })]) : _this7.renderNoSuggestions(_this7.suggestionsList)]);
1051
1080
  };
1052
1081
  return h("div", {
1053
1082
  "class": suggestionsContainer
1054
- }, [h(InputGroup, [_this6.renderInputAddonBefore(), h(InputWrapper, [h(Input, {
1083
+ }, [h(InputGroup, [_this7.renderInputAddonBefore(), h(InputWrapper, [h(Input, {
1055
1084
  "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,
1085
+ "id": _this7.$props.componentId + "-input",
1086
+ "showIcon": _this7.$props.showIcon,
1087
+ "showClear": _this7.$props.showClear,
1088
+ "iconPosition": _this7.$props.iconPosition,
1089
+ "placeholder": _this7.$props.placeholder,
1090
+ "autoFocus": _this7.$props.autoFocus,
1091
+ "themePreset": _this7.themePreset,
1063
1092
  "autocomplete": "off"
1064
1093
  },
1065
- "ref": _this6.$props.innerRef,
1066
- "class": getClassName(_this6.$props.innerClass, 'input'),
1094
+ "ref": _this7.$props.innerRef,
1095
+ "class": getClassName(_this7.$props.innerClass, 'input'),
1067
1096
  "on": _extends({}, getInputEvents({
1068
- onInput: _this6.onInputChange,
1097
+ onInput: _this7.onInputChange,
1069
1098
  onBlur: function onBlur(e) {
1070
- _this6.$emit('blur', e, _this6.triggerQuery);
1099
+ _this7.$emit('blur', e, _this7.triggerQuery);
1071
1100
  },
1072
- onFocus: _this6.handleFocus,
1101
+ onFocus: _this7.handleFocus,
1073
1102
  onKeyPress: function onKeyPress(e) {
1074
- _this6.$emit('keyPress', e, _this6.triggerQuery);
1075
- _this6.$emit('key-press', e, _this6.triggerQuery);
1103
+ _this7.$emit('keyPress', e, _this7.triggerQuery);
1104
+ _this7.$emit('key-press', e, _this7.triggerQuery);
1076
1105
  },
1077
1106
  onKeyDown: function onKeyDown(e) {
1078
- return _this6.handleKeyDown(e, highlightedIndex);
1107
+ return _this7.handleKeyDown(e, highlightedIndex);
1079
1108
  },
1080
1109
  onKeyUp: function onKeyUp(e) {
1081
- _this6.$emit('keyUp', e, _this6.triggerQuery);
1082
- _this6.$emit('key-up', e, _this6.triggerQuery);
1110
+ _this7.$emit('keyUp', e, _this7.triggerQuery);
1111
+ _this7.$emit('key-up', e, _this7.triggerQuery);
1083
1112
  },
1084
1113
  onClick: function onClick() {
1085
1114
  setHighlightedIndex(null);
1086
1115
  }
1087
1116
  })),
1088
1117
  "domProps": _extends({}, getInputProps({
1089
- value: _this6.$data.currentValue === null || typeof _this6.$data.currentValue !== 'string' ? '' : _this6.$data.currentValue
1118
+ value: _this7.$data.currentValue === null || typeof _this7.$data.currentValue !== 'string' ? '' : _this7.$data.currentValue
1090
1119
  }))
1091
- }), _this6.renderIcons(), !expandSuggestionsContainer && renderSuggestionsContainer()]), ' ', _this6.renderInputAddonAfter()]), expandSuggestionsContainer && renderSuggestionsContainer(), _this6.renderTags()]);
1120
+ }), _this7.renderIcons(), !expandSuggestionsContainer && renderSuggestionsContainer()]), ' ', _this7.renderInputAddonAfter()]), expandSuggestionsContainer && renderSuggestionsContainer(), _this7.renderTags()]);
1092
1121
  }
1093
1122
  }
1094
1123
  }) : h("div", {
@@ -1104,22 +1133,22 @@ var DataSearch = {
1104
1133
  },
1105
1134
  "on": _extends({}, {
1106
1135
  blur: function blur(e) {
1107
- _this6.$emit('blur', e, _this6.triggerQuery);
1136
+ _this7.$emit('blur', e, _this7.triggerQuery);
1108
1137
  },
1109
1138
  keypress: function keypress(e) {
1110
- _this6.$emit('keyPress', e, _this6.triggerQuery);
1111
- _this6.$emit('key-press', e, _this6.triggerQuery);
1139
+ _this7.$emit('keyPress', e, _this7.triggerQuery);
1140
+ _this7.$emit('key-press', e, _this7.triggerQuery);
1112
1141
  },
1113
1142
  input: this.onInputChange,
1114
1143
  focus: function focus(e) {
1115
- _this6.$emit('focus', e, _this6.triggerQuery);
1144
+ _this7.$emit('focus', e, _this7.triggerQuery);
1116
1145
  },
1117
1146
  keydown: function keydown(e) {
1118
- _this6.handleKeyDown(e, null);
1147
+ _this7.handleKeyDown(e, null);
1119
1148
  },
1120
1149
  keyup: function keyup(e) {
1121
- _this6.$emit('keyUp', e, _this6.triggerQuery);
1122
- _this6.$emit('key-up', e, _this6.triggerQuery);
1150
+ _this7.$emit('keyUp', e, _this7.triggerQuery);
1151
+ _this7.$emit('key-up', e, _this7.triggerQuery);
1123
1152
  }
1124
1153
  }),
1125
1154
  "domProps": _extends({}, {