react-instantsearch 7.20.2 → 7.22.0

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.
package/dist/cjs/index.js CHANGED
@@ -35,4 +35,15 @@ Object.keys(_components).forEach(function (key) {
35
35
  return _components[key];
36
36
  }
37
37
  });
38
+ });
39
+ var _useStickToBottom = require("./lib/useStickToBottom");
40
+ Object.keys(_useStickToBottom).forEach(function (key) {
41
+ if (key === "default" || key === "__esModule") return;
42
+ if (key in exports && exports[key] === _useStickToBottom[key]) return;
43
+ Object.defineProperty(exports, key, {
44
+ enumerable: true,
45
+ get: function get() {
46
+ return _useStickToBottom[key];
47
+ }
48
+ });
38
49
  });
@@ -10,10 +10,10 @@ var _reactInstantsearchCore = require("react-instantsearch-core");
10
10
  var _AutocompleteSearch = require("../components/AutocompleteSearch");
11
11
  var _ReverseHighlight = require("./ReverseHighlight");
12
12
  var _excluded = ["indices", "showSuggestions", "showRecent", "searchParameters"],
13
- _excluded2 = ["indicesConfig", "refineSearchBox", "getSearchPageURL", "onSelect", "indexUiState", "isSearchPage", "panelComponent", "showRecent", "showSuggestions", "placeholder"];
13
+ _excluded2 = ["indicesConfig", "refineSearchBox", "getSearchPageURL", "onSelect", "indexUiState", "isSearchPage", "panelComponent", "showRecent", "recentSearchConfig", "showSuggestions", "placeholder"];
14
14
  function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
15
- function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
16
15
  function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
16
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
17
17
  function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
18
18
  function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
19
19
  function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
@@ -60,6 +60,7 @@ var useStorage = (0, _instantsearchUiComponents.createAutocompleteStorage)({
60
60
  useState: _react.useState
61
61
  });
62
62
  function EXPERIMENTAL_Autocomplete(_ref) {
63
+ var _showRecent$className, _showRecent$className2, _showRecent$className3, _showRecent$className4;
63
64
  var _ref$indices = _ref.indices,
64
65
  indices = _ref$indices === void 0 ? [] : _ref$indices,
65
66
  showSuggestions = _ref.showSuggestions,
@@ -85,10 +86,12 @@ function EXPERIMENTAL_Autocomplete(_ref) {
85
86
  headerComponent: showSuggestions.headerComponent,
86
87
  itemComponent: showSuggestions.itemComponent || function (_ref2) {
87
88
  var item = _ref2.item,
88
- onSelect = _ref2.onSelect;
89
+ onSelect = _ref2.onSelect,
90
+ onApply = _ref2.onApply;
89
91
  return /*#__PURE__*/_react.default.createElement(AutocompleteSuggestion, {
90
92
  item: item,
91
- onSelect: onSelect
93
+ onSelect: onSelect,
94
+ onApply: onApply
92
95
  }, /*#__PURE__*/_react.default.createElement(ConditionalReverseHighlight, {
93
96
  item: item
94
97
  }));
@@ -105,6 +108,16 @@ function EXPERIMENTAL_Autocomplete(_ref) {
105
108
  getURL: showSuggestions.getURL
106
109
  });
107
110
  }
111
+ var recentSearchConfig = showRecent ? {
112
+ headerComponent: _typeof(showRecent) === 'object' ? showRecent.headerComponent : undefined,
113
+ itemComponent: _typeof(showRecent) === 'object' && showRecent.itemComponent ? showRecent.itemComponent : AutocompleteRecentSearch,
114
+ classNames: {
115
+ root: (0, _instantsearchUiComponents.cx)('ais-AutocompleteRecentSearches', _typeof(showRecent) === 'object' ? (_showRecent$className = showRecent.classNames) === null || _showRecent$className === void 0 ? void 0 : _showRecent$className.root : undefined),
116
+ list: (0, _instantsearchUiComponents.cx)('ais-AutocompleteRecentSearchesList', _typeof(showRecent) === 'object' ? (_showRecent$className2 = showRecent.classNames) === null || _showRecent$className2 === void 0 ? void 0 : _showRecent$className2.list : undefined),
117
+ header: (0, _instantsearchUiComponents.cx)('ais-AutocompleteRecentSearchesHeader', _typeof(showRecent) === 'object' ? (_showRecent$className3 = showRecent.classNames) === null || _showRecent$className3 === void 0 ? void 0 : _showRecent$className3.header : undefined),
118
+ item: (0, _instantsearchUiComponents.cx)('ais-AutocompleteRecentSearchesItem', _typeof(showRecent) === 'object' ? (_showRecent$className4 = showRecent.classNames) === null || _showRecent$className4 === void 0 ? void 0 : _showRecent$className4.item : undefined)
119
+ }
120
+ } : undefined;
108
121
  var isSearchPage = (0, _react.useMemo)(function () {
109
122
  return typeof indexRenderState.hits !== 'undefined' || typeof indexRenderState.infiniteHits !== 'undefined';
110
123
  }, [indexRenderState]);
@@ -121,6 +134,7 @@ function EXPERIMENTAL_Autocomplete(_ref) {
121
134
  indexUiState: indexUiState,
122
135
  isSearchPage: isSearchPage,
123
136
  showRecent: showRecent,
137
+ recentSearchConfig: recentSearchConfig,
124
138
  showSuggestions: showSuggestions
125
139
  }))));
126
140
  }
@@ -133,6 +147,7 @@ function InnerAutocomplete(_ref3) {
133
147
  isSearchPage = _ref3.isSearchPage,
134
148
  PanelComponent = _ref3.panelComponent,
135
149
  showRecent = _ref3.showRecent,
150
+ recentSearchConfig = _ref3.recentSearchConfig,
136
151
  showSuggestions = _ref3.showSuggestions,
137
152
  placeholder = _ref3.placeholder,
138
153
  props = _objectWithoutProperties(_ref3, _excluded2);
@@ -158,6 +173,9 @@ function InnerAutocomplete(_ref3) {
158
173
  refineSearchBox(query);
159
174
  storage.onAdd(query);
160
175
  },
176
+ onApply: function onApply(query) {
177
+ refineAutocomplete(query);
178
+ },
161
179
  onSelect: userOnSelect !== null && userOnSelect !== void 0 ? userOnSelect : function (_ref4) {
162
180
  var query = _ref4.query,
163
181
  setQuery = _ref4.setQuery,
@@ -180,30 +198,29 @@ function InnerAutocomplete(_ref3) {
180
198
  getItemProps = _usePropGetters.getItemProps,
181
199
  getPanelProps = _usePropGetters.getPanelProps,
182
200
  getRootProps = _usePropGetters.getRootProps;
183
- var AutocompleteRecentSearchComponent = _typeof(showRecent) === 'object' && showRecent.itemComponent || AutocompleteRecentSearch;
184
201
  var elements = {};
185
- if (showRecent) {
186
- elements.recent = /*#__PURE__*/_react.default.createElement(AutocompleteIndex
187
- // @ts-ignore - there seems to be problems with React.ComponentType and this, but it's actually correct
188
- , {
202
+ if (showRecent && recentSearchConfig) {
203
+ var RecentSearchItemComponent = recentSearchConfig.itemComponent;
204
+ elements.recent = /*#__PURE__*/_react.default.createElement(AutocompleteIndex, {
205
+ HeaderComponent: recentSearchConfig.headerComponent
206
+ // @ts-ignore - there seems to be problems with React.ComponentType and this, but it's actually correct
207
+ ,
189
208
  ItemComponent: function ItemComponent(_ref5) {
190
209
  var item = _ref5.item,
191
- onSelect = _ref5.onSelect;
192
- return /*#__PURE__*/_react.default.createElement(AutocompleteRecentSearchComponent, {
210
+ onSelect = _ref5.onSelect,
211
+ onApply = _ref5.onApply;
212
+ return /*#__PURE__*/_react.default.createElement(RecentSearchItemComponent, {
193
213
  item: item,
194
214
  onSelect: onSelect,
195
215
  onRemoveRecentSearch: function onRemoveRecentSearch() {
196
216
  return storage.onRemove(item.query);
197
- }
217
+ },
218
+ onApply: onApply
198
219
  }, /*#__PURE__*/_react.default.createElement(ConditionalReverseHighlight, {
199
220
  item: item
200
221
  }));
201
222
  },
202
- classNames: {
203
- root: 'ais-AutocompleteRecentSearches',
204
- list: 'ais-AutocompleteRecentSearchesList',
205
- item: 'ais-AutocompleteRecentSearchesItem'
206
- },
223
+ classNames: recentSearchConfig.classNames,
207
224
  items: storageHits,
208
225
  getItemProps: getItemProps,
209
226
  key: "recentSearches"
@@ -1,3 +1,4 @@
1
1
  export * from 'react-instantsearch-core';
2
2
  export * from './widgets';
3
3
  export * from './components';
4
+ export * from './lib/useStickToBottom';
package/dist/es/index.js CHANGED
@@ -1,3 +1,5 @@
1
1
  export * from 'react-instantsearch-core';
2
2
  export * from "./widgets/index.js";
3
- export * from "./components/index.js";
3
+ export * from "./components/index.js";
4
+ // @internal Internal exports (not part of the public API)
5
+ export * from "./lib/useStickToBottom.js";
@@ -22,14 +22,21 @@ export type AutocompleteProps<TItem extends BaseHit> = ComponentProps<'div'> & {
22
22
  * Storage key to use in the local storage.
23
23
  */
24
24
  storageKey?: string;
25
+ /**
26
+ * Component to use for the header, before the list of items.
27
+ */
28
+ headerComponent?: AutocompleteIndexProps<{
29
+ query: string;
30
+ }>['HeaderComponent'];
25
31
  /**
26
32
  * Component to use for each recent search item.
27
33
  */
28
- itemComponent: AutocompleteIndexProps<{
34
+ itemComponent?: AutocompleteIndexProps<{
29
35
  query: string;
30
36
  }>['ItemComponent'] & {
31
37
  onRemoveRecentSearch: () => void;
32
38
  };
39
+ classNames?: Partial<AutocompleteIndexClassNames>;
33
40
  };
34
41
  getSearchPageURL?: (nextUiState: IndexUiState) => string;
35
42
  onSelect?: AutocompleteIndexConfig<TItem>['onSelect'];
@@ -1,7 +1,7 @@
1
1
  var _excluded = ["indices", "showSuggestions", "showRecent", "searchParameters"],
2
- _excluded2 = ["indicesConfig", "refineSearchBox", "getSearchPageURL", "onSelect", "indexUiState", "isSearchPage", "panelComponent", "showRecent", "showSuggestions", "placeholder"];
3
- function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
+ _excluded2 = ["indicesConfig", "refineSearchBox", "getSearchPageURL", "onSelect", "indexUiState", "isSearchPage", "panelComponent", "showRecent", "recentSearchConfig", "showSuggestions", "placeholder"];
4
3
  function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
4
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
5
5
  function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
6
6
  function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
7
7
  function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
@@ -53,6 +53,7 @@ var useStorage = createAutocompleteStorage({
53
53
  useState: useState
54
54
  });
55
55
  export function EXPERIMENTAL_Autocomplete(_ref) {
56
+ var _showRecent$className, _showRecent$className2, _showRecent$className3, _showRecent$className4;
56
57
  var _ref$indices = _ref.indices,
57
58
  indices = _ref$indices === void 0 ? [] : _ref$indices,
58
59
  showSuggestions = _ref.showSuggestions,
@@ -78,10 +79,12 @@ export function EXPERIMENTAL_Autocomplete(_ref) {
78
79
  headerComponent: showSuggestions.headerComponent,
79
80
  itemComponent: showSuggestions.itemComponent || function (_ref2) {
80
81
  var item = _ref2.item,
81
- onSelect = _ref2.onSelect;
82
+ onSelect = _ref2.onSelect,
83
+ onApply = _ref2.onApply;
82
84
  return /*#__PURE__*/React.createElement(AutocompleteSuggestion, {
83
85
  item: item,
84
- onSelect: onSelect
86
+ onSelect: onSelect,
87
+ onApply: onApply
85
88
  }, /*#__PURE__*/React.createElement(ConditionalReverseHighlight, {
86
89
  item: item
87
90
  }));
@@ -98,6 +101,16 @@ export function EXPERIMENTAL_Autocomplete(_ref) {
98
101
  getURL: showSuggestions.getURL
99
102
  });
100
103
  }
104
+ var recentSearchConfig = showRecent ? {
105
+ headerComponent: _typeof(showRecent) === 'object' ? showRecent.headerComponent : undefined,
106
+ itemComponent: _typeof(showRecent) === 'object' && showRecent.itemComponent ? showRecent.itemComponent : AutocompleteRecentSearch,
107
+ classNames: {
108
+ root: cx('ais-AutocompleteRecentSearches', _typeof(showRecent) === 'object' ? (_showRecent$className = showRecent.classNames) === null || _showRecent$className === void 0 ? void 0 : _showRecent$className.root : undefined),
109
+ list: cx('ais-AutocompleteRecentSearchesList', _typeof(showRecent) === 'object' ? (_showRecent$className2 = showRecent.classNames) === null || _showRecent$className2 === void 0 ? void 0 : _showRecent$className2.list : undefined),
110
+ header: cx('ais-AutocompleteRecentSearchesHeader', _typeof(showRecent) === 'object' ? (_showRecent$className3 = showRecent.classNames) === null || _showRecent$className3 === void 0 ? void 0 : _showRecent$className3.header : undefined),
111
+ item: cx('ais-AutocompleteRecentSearchesItem', _typeof(showRecent) === 'object' ? (_showRecent$className4 = showRecent.classNames) === null || _showRecent$className4 === void 0 ? void 0 : _showRecent$className4.item : undefined)
112
+ }
113
+ } : undefined;
101
114
  var isSearchPage = useMemo(function () {
102
115
  return typeof indexRenderState.hits !== 'undefined' || typeof indexRenderState.infiniteHits !== 'undefined';
103
116
  }, [indexRenderState]);
@@ -114,6 +127,7 @@ export function EXPERIMENTAL_Autocomplete(_ref) {
114
127
  indexUiState: indexUiState,
115
128
  isSearchPage: isSearchPage,
116
129
  showRecent: showRecent,
130
+ recentSearchConfig: recentSearchConfig,
117
131
  showSuggestions: showSuggestions
118
132
  }))));
119
133
  }
@@ -126,6 +140,7 @@ function InnerAutocomplete(_ref3) {
126
140
  isSearchPage = _ref3.isSearchPage,
127
141
  PanelComponent = _ref3.panelComponent,
128
142
  showRecent = _ref3.showRecent,
143
+ recentSearchConfig = _ref3.recentSearchConfig,
129
144
  showSuggestions = _ref3.showSuggestions,
130
145
  placeholder = _ref3.placeholder,
131
146
  props = _objectWithoutProperties(_ref3, _excluded2);
@@ -151,6 +166,9 @@ function InnerAutocomplete(_ref3) {
151
166
  refineSearchBox(query);
152
167
  storage.onAdd(query);
153
168
  },
169
+ onApply: function onApply(query) {
170
+ refineAutocomplete(query);
171
+ },
154
172
  onSelect: userOnSelect !== null && userOnSelect !== void 0 ? userOnSelect : function (_ref4) {
155
173
  var query = _ref4.query,
156
174
  setQuery = _ref4.setQuery,
@@ -173,30 +191,29 @@ function InnerAutocomplete(_ref3) {
173
191
  getItemProps = _usePropGetters.getItemProps,
174
192
  getPanelProps = _usePropGetters.getPanelProps,
175
193
  getRootProps = _usePropGetters.getRootProps;
176
- var AutocompleteRecentSearchComponent = _typeof(showRecent) === 'object' && showRecent.itemComponent || AutocompleteRecentSearch;
177
194
  var elements = {};
178
- if (showRecent) {
179
- elements.recent = /*#__PURE__*/React.createElement(AutocompleteIndex
180
- // @ts-ignore - there seems to be problems with React.ComponentType and this, but it's actually correct
181
- , {
195
+ if (showRecent && recentSearchConfig) {
196
+ var RecentSearchItemComponent = recentSearchConfig.itemComponent;
197
+ elements.recent = /*#__PURE__*/React.createElement(AutocompleteIndex, {
198
+ HeaderComponent: recentSearchConfig.headerComponent
199
+ // @ts-ignore - there seems to be problems with React.ComponentType and this, but it's actually correct
200
+ ,
182
201
  ItemComponent: function ItemComponent(_ref5) {
183
202
  var item = _ref5.item,
184
- onSelect = _ref5.onSelect;
185
- return /*#__PURE__*/React.createElement(AutocompleteRecentSearchComponent, {
203
+ onSelect = _ref5.onSelect,
204
+ onApply = _ref5.onApply;
205
+ return /*#__PURE__*/React.createElement(RecentSearchItemComponent, {
186
206
  item: item,
187
207
  onSelect: onSelect,
188
208
  onRemoveRecentSearch: function onRemoveRecentSearch() {
189
209
  return storage.onRemove(item.query);
190
- }
210
+ },
211
+ onApply: onApply
191
212
  }, /*#__PURE__*/React.createElement(ConditionalReverseHighlight, {
192
213
  item: item
193
214
  }));
194
215
  },
195
- classNames: {
196
- root: 'ais-AutocompleteRecentSearches',
197
- list: 'ais-AutocompleteRecentSearchesList',
198
- item: 'ais-AutocompleteRecentSearchesItem'
199
- },
216
+ classNames: recentSearchConfig.classNames,
200
217
  items: storageHits,
201
218
  getItemProps: getItemProps,
202
219
  key: "recentSearches"