instantsearch.js 4.55.0 → 4.56.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.
Files changed (70) hide show
  1. package/cjs/components/Breadcrumb/Breadcrumb.js +2 -2
  2. package/cjs/components/Hits/Hits.js +4 -0
  3. package/cjs/components/InfiniteHits/InfiniteHits.js +4 -0
  4. package/cjs/components/RangeInput/RangeInput.js +22 -11
  5. package/cjs/components/RefinementList/RefinementList.js +34 -52
  6. package/cjs/components/Slider/Rheostat.js +163 -249
  7. package/cjs/connectors/infinite-hits/connectInfiniteHits.js +22 -7
  8. package/cjs/lib/InstantSearch.js +2 -4
  9. package/cjs/lib/routers/history.js +54 -1
  10. package/cjs/lib/utils/escape-highlight.js +2 -0
  11. package/cjs/lib/utils/getHighlightedParts.js +1 -0
  12. package/cjs/lib/utils/render-args.js +3 -2
  13. package/cjs/lib/version.js +1 -1
  14. package/cjs/widgets/hits-per-page/hits-per-page.js +3 -1
  15. package/cjs/widgets/index/index.js +8 -8
  16. package/dist/instantsearch.development.d.ts +76 -76
  17. package/dist/instantsearch.development.js +356 -341
  18. package/dist/instantsearch.development.js.map +1 -1
  19. package/dist/instantsearch.production.d.ts +76 -76
  20. package/dist/instantsearch.production.min.d.ts +76 -76
  21. package/dist/instantsearch.production.min.js +2 -2
  22. package/dist/instantsearch.production.min.js.map +1 -1
  23. package/es/components/Breadcrumb/Breadcrumb.d.ts +2 -2
  24. package/es/components/Breadcrumb/Breadcrumb.js +2 -2
  25. package/es/components/GeoSearchControls/GeoSearchButton.d.ts +1 -1
  26. package/es/components/GeoSearchControls/GeoSearchControls.d.ts +3 -3
  27. package/es/components/GeoSearchControls/GeoSearchToggle.d.ts +1 -1
  28. package/es/components/Hits/Hits.js +4 -0
  29. package/es/components/InfiniteHits/InfiniteHits.js +4 -0
  30. package/es/components/Pagination/Pagination.d.ts +2 -2
  31. package/es/components/RangeInput/RangeInput.d.ts +7 -4
  32. package/es/components/RangeInput/RangeInput.js +22 -11
  33. package/es/components/RefinementList/RefinementList.d.ts +0 -1
  34. package/es/components/RefinementList/RefinementList.js +34 -52
  35. package/es/components/RelevantSort/RelevantSort.d.ts +1 -1
  36. package/es/components/Selector/Selector.d.ts +2 -2
  37. package/es/components/Slider/Rheostat.d.ts +23 -17
  38. package/es/components/Slider/Rheostat.js +163 -249
  39. package/es/components/Slider/Slider.d.ts +1 -1
  40. package/es/connectors/current-refinements/connectCurrentRefinements.d.ts +2 -2
  41. package/es/connectors/dynamic-widgets/connectDynamicWidgets.d.ts +2 -2
  42. package/es/connectors/geo-search/connectGeoSearch.d.ts +7 -7
  43. package/es/connectors/infinite-hits/connectInfiniteHits.js +23 -8
  44. package/es/connectors/menu/connectMenu.d.ts +2 -2
  45. package/es/connectors/pagination/connectPagination.d.ts +1 -1
  46. package/es/connectors/range/connectRange.d.ts +3 -3
  47. package/es/connectors/refinement-list/connectRefinementList.d.ts +3 -3
  48. package/es/connectors/relevant-sort/connectRelevantSort.d.ts +1 -1
  49. package/es/lib/InstantSearch.d.ts +13 -13
  50. package/es/lib/InstantSearch.js +3 -5
  51. package/es/lib/routers/history.d.ts +2 -2
  52. package/es/lib/routers/history.js +55 -2
  53. package/es/lib/utils/defer.d.ts +2 -2
  54. package/es/lib/utils/escape-highlight.js +2 -0
  55. package/es/lib/utils/getHighlightedParts.js +1 -0
  56. package/es/lib/utils/render-args.js +3 -2
  57. package/es/lib/version.d.ts +1 -1
  58. package/es/lib/version.js +1 -1
  59. package/es/types/middleware.d.ts +6 -6
  60. package/es/types/router.d.ts +7 -7
  61. package/es/types/widget.d.ts +1 -1
  62. package/es/widgets/dynamic-widgets/dynamic-widgets.d.ts +2 -2
  63. package/es/widgets/geo-search/createHTMLMarker.d.ts +1 -1
  64. package/es/widgets/geo-search/geo-search.d.ts +1 -1
  65. package/es/widgets/hits-per-page/hits-per-page.js +3 -1
  66. package/es/widgets/index/index.d.ts +20 -20
  67. package/es/widgets/index/index.js +8 -8
  68. package/es/widgets/panel/panel.d.ts +2 -2
  69. package/es/widgets/range-slider/range-slider.d.ts +1 -1
  70. package/package.json +6 -6
@@ -26,10 +26,10 @@ var Breadcrumb = function Breadcrumb(_ref) {
26
26
  rootTagName: "a",
27
27
  rootProps: {
28
28
  className: cssClasses.link,
29
- href: createURL(undefined),
29
+ href: createURL(null),
30
30
  onClick: function onClick(event) {
31
31
  event.preventDefault();
32
- refine(undefined);
32
+ refine(null);
33
33
  }
34
34
  }
35
35
  }))), items.map(function (item, idx) {
@@ -52,6 +52,10 @@ function Hits(_ref) {
52
52
  onClick: function onClick(event) {
53
53
  handleInsightsClick(event);
54
54
  sendEvent('click:internal', hit, 'Hit Clicked');
55
+ },
56
+ onAuxClick: function onAuxClick(event) {
57
+ handleInsightsClick(event);
58
+ sendEvent('click:internal', hit, 'Hit Clicked');
55
59
  }
56
60
  },
57
61
  key: hit.objectID,
@@ -65,6 +65,10 @@ var InfiniteHits = function InfiniteHits(_ref) {
65
65
  onClick: function onClick(event) {
66
66
  handleInsightsClick(event);
67
67
  sendEvent('click:internal', hit, 'Hit Clicked');
68
+ },
69
+ onAuxClick: function onAuxClick(event) {
70
+ handleInsightsClick(event);
71
+ sendEvent('click:internal', hit, 'Hit Clicked');
68
72
  }
69
73
  },
70
74
  key: hit.objectID,
@@ -23,10 +23,17 @@ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.g
23
23
  function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
24
24
  function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
25
25
  function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
26
+ // Strips leading `0` from a positive number value
27
+ function stripLeadingZeroFromInput(value) {
28
+ return value.replace(/^(0+)\d/, function (part) {
29
+ return Number(part).toString();
30
+ });
31
+ }
26
32
  var RangeInput = /*#__PURE__*/function (_Component) {
27
33
  _inherits(RangeInput, _Component);
28
34
  var _super = _createSuper(RangeInput);
29
35
  function RangeInput() {
36
+ var _this$props$values$mi, _this$props$values$ma;
30
37
  var _this;
31
38
  _classCallCheck(this, RangeInput);
32
39
  for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
@@ -34,36 +41,40 @@ var RangeInput = /*#__PURE__*/function (_Component) {
34
41
  }
35
42
  _this = _super.call.apply(_super, [this].concat(args));
36
43
  _defineProperty(_assertThisInitialized(_this), "state", {
37
- min: _this.props.values.min,
38
- max: _this.props.values.max
44
+ min: (_this$props$values$mi = _this.props.values.min) === null || _this$props$values$mi === void 0 ? void 0 : _this$props$values$mi.toString(),
45
+ max: (_this$props$values$ma = _this.props.values.max) === null || _this$props$values$ma === void 0 ? void 0 : _this$props$values$ma.toString()
39
46
  });
40
47
  _defineProperty(_assertThisInitialized(_this), "onInput", function (key) {
41
48
  return function (event) {
42
49
  var _ref = event.currentTarget,
43
50
  value = _ref.value;
44
- _this.setState(_defineProperty({}, key, Number(value)));
51
+ _this.setState(_defineProperty({}, key, value));
45
52
  };
46
53
  });
47
54
  _defineProperty(_assertThisInitialized(_this), "onSubmit", function (event) {
48
55
  event.preventDefault();
49
- _this.props.refine([_this.state.min, _this.state.max]);
56
+ var _this$state = _this.state,
57
+ min = _this$state.min,
58
+ max = _this$state.max;
59
+ _this.props.refine([min ? Number(min) : undefined, max ? Number(max) : undefined]);
50
60
  });
51
61
  return _this;
52
62
  }
53
63
  _createClass(RangeInput, [{
54
64
  key: "componentWillReceiveProps",
55
65
  value: function componentWillReceiveProps(nextProps) {
66
+ var _nextProps$values$min, _nextProps$values$max;
56
67
  this.setState({
57
- min: nextProps.values.min,
58
- max: nextProps.values.max
68
+ min: (_nextProps$values$min = nextProps.values.min) === null || _nextProps$values$min === void 0 ? void 0 : _nextProps$values$min.toString(),
69
+ max: (_nextProps$values$max = nextProps.values.max) === null || _nextProps$values$max === void 0 ? void 0 : _nextProps$values$max.toString()
59
70
  });
60
71
  }
61
72
  }, {
62
73
  key: "render",
63
74
  value: function render() {
64
- var _this$state = this.state,
65
- minValue = _this$state.min,
66
- maxValue = _this$state.max;
75
+ var _this$state2 = this.state,
76
+ minValue = _this$state2.min,
77
+ maxValue = _this$state2.max;
67
78
  var _this$props = this.props,
68
79
  min = _this$props.min,
69
80
  max = _this$props.max,
@@ -86,7 +97,7 @@ var RangeInput = /*#__PURE__*/function (_Component) {
86
97
  min: min,
87
98
  max: max,
88
99
  step: step,
89
- value: minValue !== null && minValue !== void 0 ? minValue : '',
100
+ value: stripLeadingZeroFromInput(minValue !== null && minValue !== void 0 ? minValue : ''),
90
101
  onInput: this.onInput('min'),
91
102
  placeholder: min === null || min === void 0 ? void 0 : min.toString(),
92
103
  disabled: isDisabled
@@ -104,7 +115,7 @@ var RangeInput = /*#__PURE__*/function (_Component) {
104
115
  min: min,
105
116
  max: max,
106
117
  step: step,
107
- value: maxValue !== null && maxValue !== void 0 ? maxValue : '',
118
+ value: stripLeadingZeroFromInput(maxValue !== null && maxValue !== void 0 ? maxValue : ''),
108
119
  onInput: this.onInput('max'),
109
120
  placeholder: max === null || max === void 0 ? void 0 : max.toString(),
110
121
  disabled: isDisabled
@@ -41,49 +41,36 @@ function isHierarchicalMenuItem(facetValue) {
41
41
  var RefinementList = /*#__PURE__*/function (_Component) {
42
42
  _inherits(RefinementList, _Component);
43
43
  var _super = _createSuper(RefinementList);
44
- function RefinementList(props) {
44
+ function RefinementList() {
45
45
  var _this;
46
46
  _classCallCheck(this, RefinementList);
47
- _this = _super.call(this, props);
48
- _defineProperty(_assertThisInitialized(_this), "searchBox", (0, _preact.createRef)());
49
- _this.handleItemClick = _this.handleItemClick.bind(_assertThisInitialized(_this));
50
- return _this;
51
- }
52
- _createClass(RefinementList, [{
53
- key: "shouldComponentUpdate",
54
- value: function shouldComponentUpdate(nextProps) {
55
- var areFacetValuesDifferent = !(0, _utils.isEqual)(this.props.facetValues, nextProps.facetValues);
56
- return areFacetValuesDifferent;
47
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
48
+ args[_key] = arguments[_key];
57
49
  }
58
- }, {
59
- key: "refine",
60
- value: function refine(facetValueToRefine) {
61
- this.props.toggleRefinement(facetValueToRefine);
62
- }
63
- }, {
64
- key: "_generateFacetItem",
65
- value: function _generateFacetItem(facetValue) {
50
+ _this = _super.call.apply(_super, [this].concat(args));
51
+ _defineProperty(_assertThisInitialized(_this), "searchBox", (0, _preact.createRef)());
52
+ _defineProperty(_assertThisInitialized(_this), "_generateFacetItem", function (facetValue) {
66
53
  var subItems;
67
54
  if (isHierarchicalMenuItem(facetValue) && Array.isArray(facetValue.data) && facetValue.data.length > 0) {
68
- var _this$props$cssClasse = this.props.cssClasses,
55
+ var _this$props$cssClasse = _this.props.cssClasses,
69
56
  root = _this$props$cssClasse.root,
70
57
  cssClasses = _objectWithoutProperties(_this$props$cssClasse, _excluded);
71
- subItems = (0, _preact.h)(RefinementList, _extends({}, this.props, {
58
+ subItems = (0, _preact.h)(RefinementList, _extends({}, _this.props, {
72
59
  // We want to keep `root` required for external usage but not for the
73
60
  // sub items.
74
61
  cssClasses: cssClasses,
75
- depth: this.props.depth + 1,
62
+ depth: _this.props.depth + 1,
76
63
  facetValues: facetValue.data,
77
64
  showMore: false,
78
- className: this.props.cssClasses.childList
65
+ className: _this.props.cssClasses.childList
79
66
  }));
80
67
  }
81
- var url = this.props.createURL(facetValue.value);
68
+ var url = _this.props.createURL(facetValue.value);
82
69
  var templateData = _objectSpread(_objectSpread({}, facetValue), {}, {
83
70
  url: url,
84
- attribute: this.props.attribute,
85
- cssClasses: this.props.cssClasses,
86
- isFromSearch: this.props.isFromSearch
71
+ attribute: _this.props.attribute,
72
+ cssClasses: _this.props.cssClasses,
73
+ isFromSearch: _this.props.isFromSearch
87
74
  });
88
75
  var key = facetValue.value;
89
76
  if (facetValue.isRefined !== undefined) {
@@ -92,38 +79,20 @@ var RefinementList = /*#__PURE__*/function (_Component) {
92
79
  if (facetValue.count !== undefined) {
93
80
  key += "/".concat(facetValue.count);
94
81
  }
95
- var refinementListItemClassName = (0, _uiComponentsShared.cx)(this.props.cssClasses.item, facetValue.isRefined && this.props.cssClasses.selectedItem, !facetValue.count && this.props.cssClasses.disabledItem, Boolean(isHierarchicalMenuItem(facetValue) && Array.isArray(facetValue.data) && facetValue.data.length > 0) && this.props.cssClasses.parentItem);
82
+ var refinementListItemClassName = (0, _uiComponentsShared.cx)(_this.props.cssClasses.item, facetValue.isRefined && _this.props.cssClasses.selectedItem, !facetValue.count && _this.props.cssClasses.disabledItem, Boolean(isHierarchicalMenuItem(facetValue) && Array.isArray(facetValue.data) && facetValue.data.length > 0) && _this.props.cssClasses.parentItem);
96
83
  return (0, _preact.h)(_RefinementListItem.default, {
97
84
  templateKey: "item",
98
85
  key: key,
99
86
  facetValueToRefine: facetValue.value,
100
- handleClick: this.handleItemClick,
87
+ handleClick: _this.handleItemClick,
101
88
  isRefined: facetValue.isRefined,
102
89
  className: refinementListItemClassName,
103
90
  subItems: subItems,
104
91
  templateData: templateData,
105
- templateProps: this.props.templateProps
92
+ templateProps: _this.props.templateProps
106
93
  });
107
- }
108
-
109
- // Click events on DOM tree like LABEL > INPUT will result in two click events
110
- // instead of one.
111
- // No matter the framework, see https://www.google.com/search?q=click+label+twice
112
- //
113
- // Thus making it hard to distinguish activation from deactivation because both click events
114
- // are very close. Debounce is a solution but hacky.
115
- //
116
- // So the code here checks if the click was done on or in a LABEL. If this LABEL
117
- // has a checkbox inside, we ignore the first click event because we will get another one.
118
- //
119
- // We also check if the click was done inside a link and then e.preventDefault() because we already
120
- // handle the url
121
- //
122
- // Finally, we always stop propagation of the event to avoid multiple levels RefinementLists to fail: click
123
- // on child would click on parent also
124
- }, {
125
- key: "handleItemClick",
126
- value: function handleItemClick(_ref) {
94
+ });
95
+ _defineProperty(_assertThisInitialized(_this), "handleItemClick", function (_ref) {
127
96
  var facetValueToRefine = _ref.facetValueToRefine,
128
97
  isRefined = _ref.isRefined,
129
98
  originalEvent = _ref.originalEvent;
@@ -140,7 +109,7 @@ var RefinementList = /*#__PURE__*/function (_Component) {
140
109
  return;
141
110
  }
142
111
  if (originalEvent.target.tagName === 'INPUT') {
143
- this.refine(facetValueToRefine);
112
+ _this.refine(facetValueToRefine);
144
113
  return;
145
114
  }
146
115
  var parent = originalEvent.target;
@@ -154,7 +123,20 @@ var RefinementList = /*#__PURE__*/function (_Component) {
154
123
  parent = parent.parentNode;
155
124
  }
156
125
  originalEvent.stopPropagation();
157
- this.refine(facetValueToRefine);
126
+ _this.refine(facetValueToRefine);
127
+ });
128
+ return _this;
129
+ }
130
+ _createClass(RefinementList, [{
131
+ key: "shouldComponentUpdate",
132
+ value: function shouldComponentUpdate(nextProps) {
133
+ var areFacetValuesDifferent = !(0, _utils.isEqual)(this.props.facetValues, nextProps.facetValues);
134
+ return areFacetValuesDifferent;
135
+ }
136
+ }, {
137
+ key: "refine",
138
+ value: function refine(facetValueToRefine) {
139
+ this.props.toggleRefinement(facetValueToRefine);
158
140
  }
159
141
  }, {
160
142
  key: "componentWillReceiveProps",