instantsearch.js 4.62.0 → 4.63.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.
@@ -118,18 +118,18 @@ var RefinementList = /*#__PURE__*/function (_Component) {
118
118
  // if one special key is down
119
119
  return;
120
120
  }
121
- if (!(originalEvent.target instanceof HTMLElement) || !(originalEvent.target.parentNode instanceof HTMLElement)) {
121
+ var parent = originalEvent.target;
122
+ if (parent === null || parent.parentNode === null) {
122
123
  return;
123
124
  }
124
- if (isRefined && originalEvent.target.parentNode.querySelector('input[type="radio"]:checked')) {
125
+ if (isRefined && parent.parentNode.querySelector('input[type="radio"]:checked')) {
125
126
  // Prevent refinement for being reset if the user clicks on an already checked radio button
126
127
  return;
127
128
  }
128
- if (originalEvent.target.tagName === 'INPUT') {
129
+ if (parent.tagName === 'INPUT') {
129
130
  _this.refine(facetValueToRefine);
130
131
  return;
131
132
  }
132
- var parent = originalEvent.target;
133
133
  while (parent !== originalEvent.currentTarget) {
134
134
  if (parent.tagName === 'LABEL' && (parent.querySelector('input[type="checkbox"]') || parent.querySelector('input[type="radio"]'))) {
135
135
  return;
@@ -58,13 +58,15 @@ var SearchBox = /*#__PURE__*/function (_Component) {
58
58
  refine = _this$props.refine,
59
59
  onChange = _this$props.onChange;
60
60
  var query = event.target.value;
61
- if (searchAsYouType) {
62
- refine(query);
61
+ if (event.type === 'compositionend' || !event.isComposing) {
62
+ if (searchAsYouType) {
63
+ refine(query);
64
+ }
65
+ _this.setState({
66
+ query: query
67
+ });
68
+ onChange(event);
63
69
  }
64
- _this.setState({
65
- query: query
66
- });
67
- onChange(event);
68
70
  });
69
71
  _defineProperty(_assertThisInitialized(_this), "onSubmit", function (event) {
70
72
  var _this$props2 = _this.props,
@@ -174,7 +176,11 @@ var SearchBox = /*#__PURE__*/function (_Component) {
174
176
  ,
175
177
  spellCheck: "false",
176
178
  maxLength: 512,
177
- onInput: this.onInput,
179
+ onInput: this.onInput
180
+ // see: https://github.com/preactjs/preact/issues/1978
181
+ // eslint-disable-next-line react/no-unknown-property
182
+ ,
183
+ oncompositionend: this.onInput,
178
184
  onBlur: this.onBlur,
179
185
  onFocus: this.onFocus,
180
186
  "aria-label": ariaLabel
@@ -70,7 +70,7 @@ var connectSearchBox = function connectSearchBox(renderFn) {
70
70
  },
71
71
  getWidgetRenderState: function getWidgetRenderState(_ref3) {
72
72
  var helper = _ref3.helper,
73
- searchMetadata = _ref3.searchMetadata,
73
+ instantSearchInstance = _ref3.instantSearchInstance,
74
74
  state = _ref3.state;
75
75
  if (!_refine) {
76
76
  _refine = function _refine(query) {
@@ -87,7 +87,7 @@ var connectSearchBox = function connectSearchBox(renderFn) {
87
87
  refine: _refine,
88
88
  clear: _clear,
89
89
  widgetParams: widgetParams,
90
- isSearchStalled: searchMetadata.isSearchStalled
90
+ isSearchStalled: instantSearchInstance.status === 'stalled'
91
91
  };
92
92
  },
93
93
  getWidgetUiState: function getWidgetUiState(uiState, _ref4) {
@@ -36,7 +36,8 @@ var BrowserHistory = /*#__PURE__*/function () {
36
36
  getLocation = _ref.getLocation,
37
37
  start = _ref.start,
38
38
  dispose = _ref.dispose,
39
- push = _ref.push;
39
+ push = _ref.push,
40
+ cleanUrlOnDispose = _ref.cleanUrlOnDispose;
40
41
  _classCallCheck(this, BrowserHistory);
41
42
  _defineProperty(this, "$$type", 'ais.browser');
42
43
  /**
@@ -86,6 +87,7 @@ var BrowserHistory = /*#__PURE__*/function () {
86
87
  _defineProperty(this, "_start", void 0);
87
88
  _defineProperty(this, "_dispose", void 0);
88
89
  _defineProperty(this, "_push", void 0);
90
+ _defineProperty(this, "_cleanUrlOnDispose", void 0);
89
91
  this.windowTitle = windowTitle;
90
92
  this.writeTimer = undefined;
91
93
  this.writeDelay = writeDelay;
@@ -95,6 +97,13 @@ var BrowserHistory = /*#__PURE__*/function () {
95
97
  this._start = start;
96
98
  this._dispose = dispose;
97
99
  this._push = push;
100
+ this._cleanUrlOnDispose = typeof cleanUrlOnDispose === 'undefined' ? true : cleanUrlOnDispose;
101
+ if (process.env.NODE_ENV === 'development' && typeof cleanUrlOnDispose === 'undefined') {
102
+ // eslint-disable-next-line no-console
103
+ console.info("Starting from the next major version, InstantSearch will not clean up the URL from active refinements when it is disposed.\n\nWe recommend setting `cleanUrlOnDispose` to false to adopt this change today.\nTo stay with the current behaviour and remove this warning, set the option to true.\n\nSee documentation: ".concat((0, _utils.createDocumentationLink)({
104
+ name: 'history-router'
105
+ }), "#widget-param-cleanurlondispose"));
106
+ }
98
107
  (0, _utils.safelyRunOnBrowser)(function (_ref2) {
99
108
  var window = _ref2.window;
100
109
  var title = _this.windowTitle && _this.windowTitle(_this.read());
@@ -222,7 +231,9 @@ var BrowserHistory = /*#__PURE__*/function () {
222
231
  if (this.writeTimer) {
223
232
  clearTimeout(this.writeTimer);
224
233
  }
225
- this.write({});
234
+ if (this._cleanUrlOnDispose) {
235
+ this.write({});
236
+ }
226
237
  }
227
238
  }, {
228
239
  key: "start",
@@ -311,7 +322,8 @@ function historyRouter() {
311
322
  } : _ref7$getLocation,
312
323
  start = _ref7.start,
313
324
  dispose = _ref7.dispose,
314
- push = _ref7.push;
325
+ push = _ref7.push,
326
+ cleanUrlOnDispose = _ref7.cleanUrlOnDispose;
315
327
  return new BrowserHistory({
316
328
  createURL: createURL,
317
329
  parseURL: parseURL,
@@ -320,6 +332,7 @@ function historyRouter() {
320
332
  getLocation: getLocation,
321
333
  start: start,
322
334
  dispose: dispose,
323
- push: push
335
+ push: push,
336
+ cleanUrlOnDispose: cleanUrlOnDispose
324
337
  });
325
338
  }
@@ -4,5 +4,5 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
- var _default = '4.62.0';
7
+ var _default = '4.63.1';
8
8
  exports.default = _default;
@@ -22,7 +22,7 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
22
22
  function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
23
23
  function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
24
24
  function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
25
- var ALGOLIA_INSIGHTS_VERSION = '2.6.0';
25
+ var ALGOLIA_INSIGHTS_VERSION = '2.13.0';
26
26
  var ALGOLIA_INSIGHTS_SRC = "https://cdn.jsdelivr.net/npm/search-insights@".concat(ALGOLIA_INSIGHTS_VERSION, "/dist/search-insights.min.js");
27
27
  function createInsightsMiddleware() {
28
28
  var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
@@ -106,7 +106,7 @@ function createInsightsMiddleware() {
106
106
  // set it later on.
107
107
  //
108
108
  // Otherwise, the `init` call might override it with anonymous user token.
109
- userTokenBeforeInit = userToken;
109
+ userTokenBeforeInit = normalizeUserToken(userToken);
110
110
  });
111
111
 
112
112
  // Only `init` if the `insightsInitParams` option is passed or
@@ -162,13 +162,14 @@ function createInsightsMiddleware() {
162
162
  }
163
163
  var setUserTokenToSearch = function setUserTokenToSearch(userToken) {
164
164
  var immediate = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
165
- if (!userToken) {
165
+ var normalizedUserToken = normalizeUserToken(userToken);
166
+ if (!normalizedUserToken) {
166
167
  return;
167
168
  }
168
169
  var existingToken = helper.state.userToken;
169
170
  function applyToken() {
170
171
  helper.overrideStateWithoutTriggeringChangeEvent(_objectSpread(_objectSpread({}, helper.state), {}, {
171
- userToken: userToken
172
+ userToken: normalizedUserToken
172
173
  }));
173
174
  if (existingToken && existingToken !== userToken) {
174
175
  instantSearchInstance.scheduleSearch();
@@ -265,4 +266,15 @@ function isModernInsightsClient(client) {
265
266
  /* eslint-enable @typescript-eslint/naming-convention */
266
267
 
267
268
  return v3 || v2_6 || v1_10;
269
+ }
270
+
271
+ /**
272
+ * While `search-insights` supports both string and number user tokens,
273
+ * the Search API only accepts strings. This function normalizes the user token.
274
+ */
275
+ function normalizeUserToken(userToken) {
276
+ if (!userToken) {
277
+ return undefined;
278
+ }
279
+ return typeof userToken === 'number' ? userToken.toString() : userToken;
268
280
  }
@@ -486,11 +486,12 @@ declare class BrowserHistory<TRouteState> implements Router<TRouteState> {
486
486
  private _start?;
487
487
  private _dispose?;
488
488
  private _push?;
489
+ private _cleanUrlOnDispose;
489
490
  /**
490
491
  * Initializes a new storage provider that syncs the search state to the URL
491
492
  * using web APIs (`window.location.pushState` and `onpopstate` event).
492
493
  */
493
- constructor({ windowTitle, writeDelay, createURL, parseURL, getLocation, start, dispose, push, }: BrowserHistoryArgs<TRouteState>);
494
+ constructor({ windowTitle, writeDelay, createURL, parseURL, getLocation, start, dispose, push, cleanUrlOnDispose, }: BrowserHistoryArgs<TRouteState>);
494
495
  /**
495
496
  * Reads the URL and returns a syncable UI search state.
496
497
  */
@@ -529,6 +530,13 @@ declare type BrowserHistoryArgs<TRouteState> = {
529
530
  start?: (onUpdate: () => void) => void;
530
531
  dispose?: () => void;
531
532
  push?: (url: string) => void;
533
+ /**
534
+ * Whether the URL should be cleaned up when the router is disposed.
535
+ * This can be useful when closing a modal containing InstantSearch, to
536
+ * remove active refinements from the URL.
537
+ * @default true
538
+ */
539
+ cleanUrlOnDispose?: boolean;
532
540
  };
533
541
 
534
542
  declare type BuiltInBindEventForHits = (eventType: string, hits: Hit | Hit[], eventName?: string, additionalData?: Record<string, any>) => string;
@@ -1813,7 +1821,7 @@ declare type HighlightProps_2 = Omit<HighlightProps_3, 'classNames'> & {
1813
1821
  classNames?: Partial<HighlightClassNames>;
1814
1822
  };
1815
1823
 
1816
- declare function historyRouter<TRouteState = UiState>({ createURL, parseURL, writeDelay, windowTitle, getLocation, start, dispose, push, }?: Partial<BrowserHistoryArgs<TRouteState>>): BrowserHistory<TRouteState>;
1824
+ declare function historyRouter<TRouteState = UiState>({ createURL, parseURL, writeDelay, windowTitle, getLocation, start, dispose, push, cleanUrlOnDispose, }?: Partial<BrowserHistoryArgs<TRouteState>>): BrowserHistory<TRouteState>;
1817
1825
 
1818
1826
  declare type Hit<THit extends BaseHit = Record<string, any>> = {
1819
1827
  __position: number;
@@ -5328,9 +5336,7 @@ declare type ToggleRefinementTemplates = Partial<{
5328
5336
  /**
5329
5337
  * the text that describes the toggle action
5330
5338
  */
5331
- labelText: Template<ToggleRefinementValue & {
5332
- name: string;
5333
- }>;
5339
+ labelText: Template<ToggleRefinementRenderState['value']>;
5334
5340
  }>;
5335
5341
 
5336
5342
  declare type ToggleRefinementValue = {
@@ -1,4 +1,4 @@
1
- /*! InstantSearch.js 4.62.0 | © Algolia, Inc. and contributors; MIT License | https://github.com/algolia/instantsearch */
1
+ /*! InstantSearch.js 4.63.1 | © Algolia, Inc. and contributors; MIT License | https://github.com/algolia/instantsearch */
2
2
  (function (global, factory) {
3
3
  typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
4
4
  typeof define === 'function' && define.amd ? define(factory) :
@@ -4566,7 +4566,7 @@
4566
4566
  },
4567
4567
  getWidgetRenderState: function getWidgetRenderState(_ref3) {
4568
4568
  var helper = _ref3.helper,
4569
- searchMetadata = _ref3.searchMetadata,
4569
+ instantSearchInstance = _ref3.instantSearchInstance,
4570
4570
  state = _ref3.state;
4571
4571
  if (!_refine) {
4572
4572
  _refine = function _refine(query) {
@@ -4583,7 +4583,7 @@
4583
4583
  refine: _refine,
4584
4584
  clear: _clear,
4585
4585
  widgetParams: widgetParams,
4586
- isSearchStalled: searchMetadata.isSearchStalled
4586
+ isSearchStalled: instantSearchInstance.status === 'stalled'
4587
4587
  };
4588
4588
  },
4589
4589
  getWidgetUiState: function getWidgetUiState(uiState, _ref4) {
@@ -10086,7 +10086,7 @@
10086
10086
 
10087
10087
  var SearchResults_1 = SearchResults;
10088
10088
 
10089
- var version = '3.16.0';
10089
+ var version = '3.16.1';
10090
10090
 
10091
10091
  var escapeFacetValue$4 = escapeFacetValue_1.escapeFacetValue;
10092
10092
 
@@ -12731,7 +12731,7 @@
12731
12731
  };
12732
12732
  }
12733
12733
 
12734
- var ALGOLIA_INSIGHTS_VERSION = '2.6.0';
12734
+ var ALGOLIA_INSIGHTS_VERSION = '2.13.0';
12735
12735
  var ALGOLIA_INSIGHTS_SRC = "https://cdn.jsdelivr.net/npm/search-insights@".concat(ALGOLIA_INSIGHTS_VERSION, "/dist/search-insights.min.js");
12736
12736
  function createInsightsMiddleware() {
12737
12737
  var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
@@ -12815,7 +12815,7 @@
12815
12815
  // set it later on.
12816
12816
  //
12817
12817
  // Otherwise, the `init` call might override it with anonymous user token.
12818
- userTokenBeforeInit = userToken;
12818
+ userTokenBeforeInit = normalizeUserToken(userToken);
12819
12819
  });
12820
12820
 
12821
12821
  // Only `init` if the `insightsInitParams` option is passed or
@@ -12871,13 +12871,14 @@
12871
12871
  }
12872
12872
  var setUserTokenToSearch = function setUserTokenToSearch(userToken) {
12873
12873
  var immediate = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
12874
- if (!userToken) {
12874
+ var normalizedUserToken = normalizeUserToken(userToken);
12875
+ if (!normalizedUserToken) {
12875
12876
  return;
12876
12877
  }
12877
12878
  var existingToken = helper.state.userToken;
12878
12879
  function applyToken() {
12879
12880
  helper.overrideStateWithoutTriggeringChangeEvent(_objectSpread2(_objectSpread2({}, helper.state), {}, {
12880
- userToken: userToken
12881
+ userToken: normalizedUserToken
12881
12882
  }));
12882
12883
  if (existingToken && existingToken !== userToken) {
12883
12884
  instantSearchInstance.scheduleSearch();
@@ -12976,6 +12977,17 @@
12976
12977
  return v3 || v2_6 || v1_10;
12977
12978
  }
12978
12979
 
12980
+ /**
12981
+ * While `search-insights` supports both string and number user tokens,
12982
+ * the Search API only accepts strings. This function normalizes the user token.
12983
+ */
12984
+ function normalizeUserToken(userToken) {
12985
+ if (!userToken) {
12986
+ return undefined;
12987
+ }
12988
+ return typeof userToken === 'number' ? userToken.toString() : userToken;
12989
+ }
12990
+
12979
12991
  function extractWidgetPayload(widgets, instantSearchInstance, payload) {
12980
12992
  var initOptions = createInitArgs(instantSearchInstance, instantSearchInstance.mainIndex, instantSearchInstance._initialUiState);
12981
12993
  widgets.forEach(function (widget) {
@@ -13899,7 +13911,8 @@
13899
13911
  getLocation = _ref.getLocation,
13900
13912
  start = _ref.start,
13901
13913
  dispose = _ref.dispose,
13902
- push = _ref.push;
13914
+ push = _ref.push,
13915
+ cleanUrlOnDispose = _ref.cleanUrlOnDispose;
13903
13916
  _classCallCheck(this, BrowserHistory);
13904
13917
  _defineProperty(this, "$$type", 'ais.browser');
13905
13918
  /**
@@ -13949,6 +13962,7 @@
13949
13962
  _defineProperty(this, "_start", void 0);
13950
13963
  _defineProperty(this, "_dispose", void 0);
13951
13964
  _defineProperty(this, "_push", void 0);
13965
+ _defineProperty(this, "_cleanUrlOnDispose", void 0);
13952
13966
  this.windowTitle = windowTitle;
13953
13967
  this.writeTimer = undefined;
13954
13968
  this.writeDelay = writeDelay;
@@ -13958,6 +13972,13 @@
13958
13972
  this._start = start;
13959
13973
  this._dispose = dispose;
13960
13974
  this._push = push;
13975
+ this._cleanUrlOnDispose = typeof cleanUrlOnDispose === 'undefined' ? true : cleanUrlOnDispose;
13976
+ if ( typeof cleanUrlOnDispose === 'undefined') {
13977
+ // eslint-disable-next-line no-console
13978
+ console.info("Starting from the next major version, InstantSearch will not clean up the URL from active refinements when it is disposed.\n\nWe recommend setting `cleanUrlOnDispose` to false to adopt this change today.\nTo stay with the current behaviour and remove this warning, set the option to true.\n\nSee documentation: ".concat(createDocumentationLink({
13979
+ name: 'history-router'
13980
+ }), "#widget-param-cleanurlondispose"));
13981
+ }
13961
13982
  safelyRunOnBrowser(function (_ref2) {
13962
13983
  var window = _ref2.window;
13963
13984
  var title = _this.windowTitle && _this.windowTitle(_this.read());
@@ -14085,7 +14106,9 @@
14085
14106
  if (this.writeTimer) {
14086
14107
  clearTimeout(this.writeTimer);
14087
14108
  }
14088
- this.write({});
14109
+ if (this._cleanUrlOnDispose) {
14110
+ this.write({});
14111
+ }
14089
14112
  }
14090
14113
  }, {
14091
14114
  key: "start",
@@ -14174,7 +14197,8 @@
14174
14197
  } : _ref7$getLocation,
14175
14198
  start = _ref7.start,
14176
14199
  dispose = _ref7.dispose,
14177
- push = _ref7.push;
14200
+ push = _ref7.push,
14201
+ cleanUrlOnDispose = _ref7.cleanUrlOnDispose;
14178
14202
  return new BrowserHistory({
14179
14203
  createURL: createURL,
14180
14204
  parseURL: parseURL,
@@ -14183,7 +14207,8 @@
14183
14207
  getLocation: getLocation,
14184
14208
  start: start,
14185
14209
  dispose: dispose,
14186
- push: push
14210
+ push: push,
14211
+ cleanUrlOnDispose: cleanUrlOnDispose
14187
14212
  });
14188
14213
  }
14189
14214
 
@@ -14822,7 +14847,7 @@
14822
14847
  };
14823
14848
  }
14824
14849
 
14825
- var version$1 = '4.62.0';
14850
+ var version$1 = '4.63.1';
14826
14851
 
14827
14852
  var withUsage$r = createDocumentationMessageGenerator({
14828
14853
  name: 'instantsearch'
@@ -18004,13 +18029,15 @@
18004
18029
  refine = _this$props.refine,
18005
18030
  onChange = _this$props.onChange;
18006
18031
  var query = event.target.value;
18007
- if (searchAsYouType) {
18008
- refine(query);
18032
+ if (event.type === 'compositionend' || !event.isComposing) {
18033
+ if (searchAsYouType) {
18034
+ refine(query);
18035
+ }
18036
+ _this.setState({
18037
+ query: query
18038
+ });
18039
+ onChange(event);
18009
18040
  }
18010
- _this.setState({
18011
- query: query
18012
- });
18013
- onChange(event);
18014
18041
  });
18015
18042
  _defineProperty(_assertThisInitialized(_this), "onSubmit", function (event) {
18016
18043
  var _this$props2 = _this.props,
@@ -18120,7 +18147,11 @@
18120
18147
  ,
18121
18148
  spellCheck: "false",
18122
18149
  maxLength: 512,
18123
- onInput: this.onInput,
18150
+ onInput: this.onInput
18151
+ // see: https://github.com/preactjs/preact/issues/1978
18152
+ // eslint-disable-next-line react/no-unknown-property
18153
+ ,
18154
+ oncompositionend: this.onInput,
18124
18155
  onBlur: this.onBlur,
18125
18156
  onFocus: this.onFocus,
18126
18157
  "aria-label": ariaLabel
@@ -18281,18 +18312,18 @@
18281
18312
  // if one special key is down
18282
18313
  return;
18283
18314
  }
18284
- if (!(originalEvent.target instanceof HTMLElement) || !(originalEvent.target.parentNode instanceof HTMLElement)) {
18315
+ var parent = originalEvent.target;
18316
+ if (parent === null || parent.parentNode === null) {
18285
18317
  return;
18286
18318
  }
18287
- if (isRefined && originalEvent.target.parentNode.querySelector('input[type="radio"]:checked')) {
18319
+ if (isRefined && parent.parentNode.querySelector('input[type="radio"]:checked')) {
18288
18320
  // Prevent refinement for being reset if the user clicks on an already checked radio button
18289
18321
  return;
18290
18322
  }
18291
- if (originalEvent.target.tagName === 'INPUT') {
18323
+ if (parent.tagName === 'INPUT') {
18292
18324
  _this.refine(facetValueToRefine);
18293
18325
  return;
18294
18326
  }
18295
- var parent = originalEvent.target;
18296
18327
  while (parent !== originalEvent.currentTarget) {
18297
18328
  if (parent.tagName === 'LABEL' && (parent.querySelector('input[type="checkbox"]') || parent.querySelector('input[type="radio"]'))) {
18298
18329
  return;