@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.
@@ -60,7 +60,8 @@ var DataSearch = {
60
60
  selectedTags: [],
61
61
  isOpen: false,
62
62
  normalizedSuggestions: [],
63
- isPending: false
63
+ isPending: false,
64
+ isSuggestionSelected: false
64
65
  };
65
66
  this.internalComponent = props.componentId + "__internal";
66
67
  return this.__state;
@@ -300,12 +301,23 @@ var DataSearch = {
300
301
  this.updateQueryHandler(this.componentId, this.$data.currentValue, this.$props);
301
302
  }
302
303
  },
304
+ isLoading: function isLoading(newVal) {
305
+ if (newVal) {
306
+ this.suggestions = [];
307
+ }
308
+ },
303
309
  suggestions: function suggestions(newVal) {
310
+ if (this.isLoading) {
311
+ this.normalizedSuggestions = [];
312
+ return;
313
+ }
304
314
  if (Array.isArray(newVal) && this.$data.currentValue.trim().length) {
305
315
  // shallow check allows us to set suggestions even if the next set
306
316
  // of suggestions are same as the current one
307
317
  this.$emit('suggestions', newVal);
308
- this.normalizedSuggestions = this.onSuggestions(newVal);
318
+ if (!isEqual(this.normalizedSuggestions, newVal)) {
319
+ this.normalizedSuggestions = this.onSuggestions(newVal);
320
+ }
309
321
  }
310
322
  },
311
323
  selectedValue: function selectedValue(newVal, oldVal) {
@@ -439,12 +451,11 @@ var DataSearch = {
439
451
  return;
440
452
  }
441
453
  // Refresh recent searches when value becomes empty
442
- if (!value && props.enableDefaultSuggestions === false) {
443
- _this.resetStoreForComponent(props.componentId);
444
- } else if (!value && _this.currentValue && _this.enableRecentSearches) {
454
+ if (props.enableDefaultSuggestions && !value && _this.currentValue && _this.enableRecentSearches) {
445
455
  _this.getRecentSearches();
446
456
  }
447
457
  if (isTagsMode) {
458
+ var isTagAdded = false;
448
459
  if (Array.isArray(_this.selectedTags) && _this.selectedTags.length) {
449
460
  // check if value already present in selectedTags
450
461
  if (typeof value === 'string' && _this.selectedTags.includes(value)) {
@@ -453,14 +464,36 @@ var DataSearch = {
453
464
  }
454
465
  _this.selectedTags = [].concat(_this.selectedTags);
455
466
  if (typeof value === 'string' && !!value) {
456
- _this.selectedTags.push(value);
467
+ if (props.strictSelection && cause === configureStore.causes.SUGGESTION_SELECT) {
468
+ _this.selectedTags.push(value);
469
+ isTagAdded = true;
470
+ } else if (!props.strictSelection) {
471
+ _this.selectedTags.push(value);
472
+ isTagAdded = true;
473
+ }
457
474
  } else if (Array.isArray(value) && !isEqual(_this.selectedTags, value)) {
458
- _this.selectedTags = value;
475
+ if (props.strictSelection && cause === configureStore.causes.SUGGESTION_SELECT) {
476
+ _this.selectedTags = value;
477
+ isTagAdded = true;
478
+ } else if (!props.strictSelection) {
479
+ _this.selectedTags.push(value);
480
+ isTagAdded = true;
481
+ }
459
482
  }
460
483
  } else if (value) {
461
- _this.selectedTags = typeof value !== 'string' ? value : [].concat(value);
484
+ if (props.strictSelection && cause === configureStore.causes.SUGGESTION_SELECT) {
485
+ _this.selectedTags = typeof value !== 'string' ? value : [].concat(value);
486
+ isTagAdded = true;
487
+ } else if (!props.strictSelection) {
488
+ _this.selectedTags = typeof value !== 'string' ? value : [].concat(value);
489
+ isTagAdded = true;
490
+ }
491
+ }
492
+ if (props.strictSelection && !isTagAdded) {
493
+ _this.currentValue = value;
494
+ } else {
495
+ _this.currentValue = '';
462
496
  }
463
- _this.currentValue = '';
464
497
  } else {
465
498
  _this.currentValue = value;
466
499
  }
@@ -480,7 +513,7 @@ var DataSearch = {
480
513
  if (props.strictSelection && props.autosuggest) {
481
514
  if (cause === configureStore.causes.SUGGESTION_SELECT || props.value !== undefined) {
482
515
  _this.updateQueryHandler(props.componentId, queryHandlerValue, props);
483
- } else if (_this.currentValue !== '') {
516
+ } else if (_this.currentValue !== '' && !props.strictSelection) {
484
517
  _this.setValue('', true);
485
518
  }
486
519
  } else {
@@ -494,12 +527,12 @@ var DataSearch = {
494
527
  _this.$emit('value-change', value);
495
528
  // Set the already fetched suggestions if query is same as used last to fetch the hits
496
529
  if (value === _this.lastUsedQuery) {
497
- _this.suggestions = _this.onSuggestions(_this.suggestions);
530
+ _this.normalizedSuggestions = _this.onSuggestions(_this.suggestions);
498
531
  // invoke on suggestions
499
532
  _this.$emit('suggestions', _this.suggestions);
500
533
  } else if (!value) {
501
534
  // reset suggestions
502
- _this.suggestions = [];
535
+ _this.normalizedSuggestions = [];
503
536
  // invoke on suggestions
504
537
  _this.$emit('suggestions', _this.suggestions);
505
538
  }
@@ -510,11 +543,6 @@ var DataSearch = {
510
543
  if (props === void 0) {
511
544
  props = this.$props;
512
545
  }
513
- if (!value && props.enableDefaultSuggestions === false) {
514
- // clear Component data from store
515
- this.resetStoreForComponent(props.componentId);
516
- return;
517
- }
518
546
  var defaultQueryOptions;
519
547
  var query = DataSearch.defaultQuery(value, props);
520
548
  if (this.defaultQuery) {
@@ -609,17 +637,17 @@ var DataSearch = {
609
637
  var targetValue = event.target.value;
610
638
  var _this$$props2 = this.$props,
611
639
  value = _this$$props2.value,
612
- strictSelection = _this$$props2.strictSelection,
613
- size = _this$$props2.size,
614
- autosuggest = _this$$props2.autosuggest;
640
+ size = _this$$props2.size;
615
641
  if (value !== undefined) {
616
642
  this.isPending = true;
617
643
  }
618
644
  // if a suggestion was selected, delegate the handling to suggestion handler
619
645
  if (event.key === 'Enter' && (highlightedIndex === null || highlightedIndex < 0 || highlightedIndex === [].concat([].concat(this.suggestionsList).slice(0, size || 10), this.defaultSearchSuggestions, this.topSuggestions).length)) {
620
646
  this.isPending = false;
621
- this.setValue(this.$options.isTagsMode && autosuggest && strictSelection ? '' : targetValue, true, this.$props, undefined, false);
622
- this.onValueSelectedHandler(targetValue, configureStore.causes.ENTER_PRESS);
647
+ if (!this.isSuggestionSelected) {
648
+ this.setValue(targetValue, true, this.$props, undefined, false);
649
+ this.onValueSelectedHandler(targetValue, configureStore.causes.ENTER_PRESS);
650
+ }
623
651
  }
624
652
  // Need to review
625
653
  this.$emit('keyDown', event, this.triggerQuery);
@@ -655,11 +683,16 @@ var DataSearch = {
655
683
  }
656
684
  },
657
685
  onSuggestionSelected: function onSuggestionSelected(suggestion) {
686
+ var _this3 = this;
658
687
  var value = this.$props.value;
659
688
  // Record analytics for selected suggestions
660
689
  this.triggerClickAnalytics(suggestion._click_id);
661
690
  if (value === undefined) {
662
691
  this.setValue(suggestion.value, true, this.$props, configureStore.causes.SUGGESTION_SELECT);
692
+ this.isSuggestionSelected = true;
693
+ setTimeout(function () {
694
+ _this3.isSuggestionSelected = false;
695
+ }, 50);
663
696
  } else if (this.$options.isTagsMode) {
664
697
  var emitValue = Array.isArray(this.selectedTags) ? [].concat(this.selectedTags) : [];
665
698
  if (this.selectedTags.includes(suggestion.value)) {
@@ -765,7 +798,7 @@ var DataSearch = {
765
798
  return null;
766
799
  },
767
800
  renderTag: function renderTag(item) {
768
- var _this3 = this;
801
+ var _this4 = this;
769
802
  var h = this.$createElement;
770
803
  var innerClass = this.$props.innerClass;
771
804
  return h(Tags.TagItem, {
@@ -778,7 +811,7 @@ var DataSearch = {
778
811
  "class": "close-icon",
779
812
  "on": {
780
813
  "click": function click() {
781
- return _this3.clearTag(item);
814
+ return _this4.clearTag(item);
782
815
  }
783
816
  }
784
817
  }, [h(CancelSvg.CancelSvg)])]);
@@ -800,7 +833,7 @@ var DataSearch = {
800
833
  }
801
834
  },
802
835
  renderTags: function renderTags() {
803
- var _this4 = this;
836
+ var _this5 = this;
804
837
  var h = this.$createElement;
805
838
  if (!Array.isArray(this.selectedTags)) {
806
839
  return null;
@@ -813,7 +846,7 @@ var DataSearch = {
813
846
  handleClear: this.clearTag,
814
847
  handleClearAll: this.clearAllTags
815
848
  }) : h(Tags.TagsContainer, [tagsList.map(function (item) {
816
- return _this4.renderTag(item);
849
+ return _this5.renderTag(item);
817
850
  }), shouldRenderClearAllTag && h(Tags.TagItem, {
818
851
  "class": getClassName(this.$props.innerClass, 'selected-tag') || ''
819
852
  }, [h("span", ["Clear All"]), h("span", {
@@ -892,7 +925,7 @@ var DataSearch = {
892
925
  (_this$$refs = this.$refs) == null || (_this$$refs = _this$$refs[this.$props.innerRef]) == null ? void 0 : _this$$refs.focus(); // eslint-disable-line
893
926
  },
894
927
  listenForFocusShortcuts: function listenForFocusShortcuts() {
895
- var _this5 = this;
928
+ var _this6 = this;
896
929
  var _this$$props$focusSho = this.$props.focusShortcuts,
897
930
  focusShortcuts = _this$$props$focusSho === void 0 ? ['/'] : _this$$props$focusSho;
898
931
  if (index.isEmpty(focusShortcuts)) {
@@ -907,7 +940,7 @@ var DataSearch = {
907
940
  function (event, handler) {
908
941
  // Prevent the default refresh event under WINDOWS system
909
942
  event.preventDefault();
910
- _this5.focusSearchBox(event);
943
+ _this6.focusSearchBox(event);
911
944
  });
912
945
 
913
946
  // if one of modifier keys are used, they are handled below
@@ -917,7 +950,7 @@ var DataSearch = {
917
950
  for (var index$1 = 0; index$1 < modifierKeys.length; index$1 += 1) {
918
951
  var element = modifierKeys[index$1];
919
952
  if (hotkeys[element]) {
920
- _this5.focusSearchBox(event);
953
+ _this6.focusSearchBox(event);
921
954
  break;
922
955
  }
923
956
  }
@@ -925,7 +958,7 @@ var DataSearch = {
925
958
  }
926
959
  },
927
960
  render: function render() {
928
- var _this6 = this;
961
+ var _this7 = this;
929
962
  var h = arguments[0];
930
963
  var _this$$props6 = this.$props,
931
964
  theme = _this$$props6.theme,
@@ -960,14 +993,14 @@ var DataSearch = {
960
993
  highlightedIndex = _ref4.highlightedIndex,
961
994
  setHighlightedIndex = _ref4.setHighlightedIndex;
962
995
  var renderSuggestionsContainer = function renderSuggestionsContainer() {
963
- return h("div", [_this6.hasCustomRenderer && _this6.getComponent({
996
+ return h("div", [_this7.hasCustomRenderer && _this7.getComponent({
964
997
  isOpen: isOpen,
965
998
  getItemProps: getItemProps,
966
999
  getItemEvents: getItemEvents,
967
1000
  highlightedIndex: highlightedIndex
968
- }), _this6.renderErrorComponent(), !_this6.hasCustomRenderer && isOpen && hasSuggestions ? h("ul", {
969
- "class": Input.suggestions(_this6.themePreset, theme) + " " + getClassName(_this6.$props.innerClass, 'list')
970
- }, [_this6.suggestionsList.slice(0, size || 10).map(function (item, index) {
1001
+ }), _this7.renderErrorComponent(), !_this7.hasCustomRenderer && isOpen && hasSuggestions ? h("ul", {
1002
+ "class": Input.suggestions(_this7.themePreset, theme) + " " + getClassName(_this7.$props.innerClass, 'list')
1003
+ }, [_this7.suggestionsList.slice(0, size || 10).map(function (item, index) {
971
1004
  return h("li", {
972
1005
  "domProps": _rollupPluginBabelHelpers._extends({}, getItemProps({
973
1006
  item: item
@@ -977,15 +1010,15 @@ var DataSearch = {
977
1010
  })),
978
1011
  "key": index + 1 + "-" + item.value,
979
1012
  "style": {
980
- backgroundColor: _this6.getBackgroundColor(highlightedIndex, index)
1013
+ backgroundColor: _this7.getBackgroundColor(highlightedIndex, index)
981
1014
  }
982
1015
  }, [h(Tags.SuggestionItem, {
983
1016
  "attrs": {
984
- "currentValue": _this6.currentValue,
1017
+ "currentValue": _this7.currentValue,
985
1018
  "suggestion": item
986
1019
  }
987
1020
  })]);
988
- }), _this6.defaultSearchSuggestions.map(function (sugg, index) {
1021
+ }), _this7.defaultSearchSuggestions.map(function (sugg, index) {
989
1022
  return h("li", {
990
1023
  "domProps": _rollupPluginBabelHelpers._extends({}, getItemProps({
991
1024
  item: sugg
@@ -993,9 +1026,9 @@ var DataSearch = {
993
1026
  "on": _rollupPluginBabelHelpers._extends({}, getItemEvents({
994
1027
  item: sugg
995
1028
  })),
996
- "key": _this6.suggestionsList.length + index + 1 + "-" + sugg.value,
1029
+ "key": _this7.suggestionsList.length + index + 1 + "-" + sugg.value,
997
1030
  "style": {
998
- backgroundColor: _this6.getBackgroundColor(highlightedIndex, _this6.suggestionsList.length + index),
1031
+ backgroundColor: _this7.getBackgroundColor(highlightedIndex, _this7.suggestionsList.length + index),
999
1032
  justifyContent: 'flex-start'
1000
1033
  }
1001
1034
  }, [h("div", {
@@ -1004,28 +1037,28 @@ var DataSearch = {
1004
1037
  }
1005
1038
  }, [sugg.source && sugg.source._recent_search && h(Tags.CustomSvg, {
1006
1039
  "attrs": {
1007
- "className": getClassName(_this6.$props.innerClass, 'recent-search-icon') || null,
1040
+ "className": getClassName(_this7.$props.innerClass, 'recent-search-icon') || null,
1008
1041
  "icon": recentSearchesIcon,
1009
1042
  "type": "recent-search-icon"
1010
1043
  }
1011
1044
  }), sugg.source && sugg.source._popular_suggestion && h(Tags.CustomSvg, {
1012
1045
  "attrs": {
1013
- "className": getClassName(_this6.$props.innerClass, 'popular-search-icon') || null,
1046
+ "className": getClassName(_this7.$props.innerClass, 'popular-search-icon') || null,
1014
1047
  "icon": popularSearchesIcon,
1015
1048
  "type": "popular-search-icon"
1016
1049
  }
1017
1050
  })]), h(Tags.SuggestionItem, {
1018
1051
  "attrs": {
1019
- "currentValue": _this6.currentValue,
1052
+ "currentValue": _this7.currentValue,
1020
1053
  "suggestion": sugg
1021
1054
  }
1022
1055
  })]);
1023
- }), index.hasQuerySuggestionsRenderer(_this6) ? _this6.getComponent({
1056
+ }), index.hasQuerySuggestionsRenderer(_this7) ? _this7.getComponent({
1024
1057
  isOpen: isOpen,
1025
1058
  getItemProps: getItemProps,
1026
1059
  getItemEvents: getItemEvents,
1027
1060
  highlightedIndex: highlightedIndex
1028
- }, true) : _this6.topSuggestions.map(function (sugg, index) {
1061
+ }, true) : _this7.topSuggestions.map(function (sugg, index) {
1029
1062
  return h("li", {
1030
1063
  "domProps": _rollupPluginBabelHelpers._extends({}, getItemProps({
1031
1064
  item: sugg
@@ -1033,9 +1066,9 @@ var DataSearch = {
1033
1066
  "on": _rollupPluginBabelHelpers._extends({}, getItemEvents({
1034
1067
  item: sugg
1035
1068
  })),
1036
- "key": _this6.suggestionsList.length + index + 1 + "-" + sugg.value,
1069
+ "key": _this7.suggestionsList.length + index + 1 + "-" + sugg.value,
1037
1070
  "style": {
1038
- backgroundColor: _this6.getBackgroundColor(highlightedIndex, _this6.suggestionsList.length + index),
1071
+ backgroundColor: _this7.getBackgroundColor(highlightedIndex, _this7.suggestionsList.length + index),
1039
1072
  justifyContent: 'flex-start'
1040
1073
  }
1041
1074
  }, [h("div", {
@@ -1044,58 +1077,58 @@ var DataSearch = {
1044
1077
  }
1045
1078
  }, [h(Tags.CustomSvg, {
1046
1079
  "attrs": {
1047
- "className": getClassName(_this6.$props.innerClass, 'popular-search-icon') || null,
1080
+ "className": getClassName(_this7.$props.innerClass, 'popular-search-icon') || null,
1048
1081
  "icon": popularSearchesIcon,
1049
1082
  "type": "popular-search-icon"
1050
1083
  }
1051
1084
  })]), h(Tags.SuggestionItem, {
1052
1085
  "attrs": {
1053
- "currentValue": _this6.currentValue,
1086
+ "currentValue": _this7.currentValue,
1054
1087
  "suggestion": sugg
1055
1088
  }
1056
1089
  })]);
1057
- })]) : _this6.renderNoSuggestions(_this6.suggestionsList)]);
1090
+ })]) : _this7.renderNoSuggestions(_this7.suggestionsList)]);
1058
1091
  };
1059
1092
  return h("div", {
1060
1093
  "class": Input.suggestionsContainer
1061
- }, [h(Tags.InputGroup, [_this6.renderInputAddonBefore(), h(CancelSvg.InputWrapper, [h(Input.Input, {
1094
+ }, [h(Tags.InputGroup, [_this7.renderInputAddonBefore(), h(CancelSvg.InputWrapper, [h(Input.Input, {
1062
1095
  "attrs": {
1063
- "id": _this6.$props.componentId + "-input",
1064
- "showIcon": _this6.$props.showIcon,
1065
- "showClear": _this6.$props.showClear,
1066
- "iconPosition": _this6.$props.iconPosition,
1067
- "placeholder": _this6.$props.placeholder,
1068
- "autoFocus": _this6.$props.autoFocus,
1069
- "themePreset": _this6.themePreset,
1096
+ "id": _this7.$props.componentId + "-input",
1097
+ "showIcon": _this7.$props.showIcon,
1098
+ "showClear": _this7.$props.showClear,
1099
+ "iconPosition": _this7.$props.iconPosition,
1100
+ "placeholder": _this7.$props.placeholder,
1101
+ "autoFocus": _this7.$props.autoFocus,
1102
+ "themePreset": _this7.themePreset,
1070
1103
  "autocomplete": "off"
1071
1104
  },
1072
- "ref": _this6.$props.innerRef,
1073
- "class": getClassName(_this6.$props.innerClass, 'input'),
1105
+ "ref": _this7.$props.innerRef,
1106
+ "class": getClassName(_this7.$props.innerClass, 'input'),
1074
1107
  "on": _rollupPluginBabelHelpers._extends({}, getInputEvents({
1075
- onInput: _this6.onInputChange,
1108
+ onInput: _this7.onInputChange,
1076
1109
  onBlur: function onBlur(e) {
1077
- _this6.$emit('blur', e, _this6.triggerQuery);
1110
+ _this7.$emit('blur', e, _this7.triggerQuery);
1078
1111
  },
1079
- onFocus: _this6.handleFocus,
1112
+ onFocus: _this7.handleFocus,
1080
1113
  onKeyPress: function onKeyPress(e) {
1081
- _this6.$emit('keyPress', e, _this6.triggerQuery);
1082
- _this6.$emit('key-press', e, _this6.triggerQuery);
1114
+ _this7.$emit('keyPress', e, _this7.triggerQuery);
1115
+ _this7.$emit('key-press', e, _this7.triggerQuery);
1083
1116
  },
1084
1117
  onKeyDown: function onKeyDown(e) {
1085
- return _this6.handleKeyDown(e, highlightedIndex);
1118
+ return _this7.handleKeyDown(e, highlightedIndex);
1086
1119
  },
1087
1120
  onKeyUp: function onKeyUp(e) {
1088
- _this6.$emit('keyUp', e, _this6.triggerQuery);
1089
- _this6.$emit('key-up', e, _this6.triggerQuery);
1121
+ _this7.$emit('keyUp', e, _this7.triggerQuery);
1122
+ _this7.$emit('key-up', e, _this7.triggerQuery);
1090
1123
  },
1091
1124
  onClick: function onClick() {
1092
1125
  setHighlightedIndex(null);
1093
1126
  }
1094
1127
  })),
1095
1128
  "domProps": _rollupPluginBabelHelpers._extends({}, getInputProps({
1096
- value: _this6.$data.currentValue === null || typeof _this6.$data.currentValue !== 'string' ? '' : _this6.$data.currentValue
1129
+ value: _this7.$data.currentValue === null || typeof _this7.$data.currentValue !== 'string' ? '' : _this7.$data.currentValue
1097
1130
  }))
1098
- }), _this6.renderIcons(), !expandSuggestionsContainer && renderSuggestionsContainer()]), ' ', _this6.renderInputAddonAfter()]), expandSuggestionsContainer && renderSuggestionsContainer(), _this6.renderTags()]);
1131
+ }), _this7.renderIcons(), !expandSuggestionsContainer && renderSuggestionsContainer()]), ' ', _this7.renderInputAddonAfter()]), expandSuggestionsContainer && renderSuggestionsContainer(), _this7.renderTags()]);
1099
1132
  }
1100
1133
  }
1101
1134
  }) : h("div", {
@@ -1111,22 +1144,22 @@ var DataSearch = {
1111
1144
  },
1112
1145
  "on": _rollupPluginBabelHelpers._extends({}, {
1113
1146
  blur: function blur(e) {
1114
- _this6.$emit('blur', e, _this6.triggerQuery);
1147
+ _this7.$emit('blur', e, _this7.triggerQuery);
1115
1148
  },
1116
1149
  keypress: function keypress(e) {
1117
- _this6.$emit('keyPress', e, _this6.triggerQuery);
1118
- _this6.$emit('key-press', e, _this6.triggerQuery);
1150
+ _this7.$emit('keyPress', e, _this7.triggerQuery);
1151
+ _this7.$emit('key-press', e, _this7.triggerQuery);
1119
1152
  },
1120
1153
  input: this.onInputChange,
1121
1154
  focus: function focus(e) {
1122
- _this6.$emit('focus', e, _this6.triggerQuery);
1155
+ _this7.$emit('focus', e, _this7.triggerQuery);
1123
1156
  },
1124
1157
  keydown: function keydown(e) {
1125
- _this6.handleKeyDown(e, null);
1158
+ _this7.handleKeyDown(e, null);
1126
1159
  },
1127
1160
  keyup: function keyup(e) {
1128
- _this6.$emit('keyUp', e, _this6.triggerQuery);
1129
- _this6.$emit('key-up', e, _this6.triggerQuery);
1161
+ _this7.$emit('keyUp', e, _this7.triggerQuery);
1162
+ _this7.$emit('key-up', e, _this7.triggerQuery);
1130
1163
  }
1131
1164
  }),
1132
1165
  "domProps": _rollupPluginBabelHelpers._extends({}, {