react-instantsearch 7.5.2 → 7.5.4

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.
@@ -8,7 +8,7 @@ exports.SearchBox = SearchBox;
8
8
  var _react = _interopRequireWildcard(require("react"));
9
9
  var _reactInstantsearchCore = require("react-instantsearch-core");
10
10
  var _SearchBox = require("../ui/SearchBox");
11
- var _excluded = ["queryHook", "searchAsYouType", "translations"];
11
+ var _excluded = ["queryHook", "searchAsYouType", "ignoreCompositionEvents", "translations"];
12
12
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
13
13
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
14
14
  function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
@@ -29,6 +29,8 @@ function SearchBox(_ref) {
29
29
  var queryHook = _ref.queryHook,
30
30
  _ref$searchAsYouType = _ref.searchAsYouType,
31
31
  searchAsYouType = _ref$searchAsYouType === void 0 ? true : _ref$searchAsYouType,
32
+ _ref$ignoreCompositio = _ref.ignoreCompositionEvents,
33
+ ignoreCompositionEvents = _ref$ignoreCompositio === void 0 ? false : _ref$ignoreCompositio,
32
34
  translations = _ref.translations,
33
35
  props = _objectWithoutProperties(_ref, _excluded);
34
36
  var _useSearchBox = (0, _reactInstantsearchCore.useSearchBox)({
@@ -45,9 +47,9 @@ function SearchBox(_ref) {
45
47
  setInputValue = _useState2[1];
46
48
  var inputRef = (0, _react.useRef)(null);
47
49
  function setQuery(newQuery) {
48
- var compositionComplete = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
50
+ var isComposing = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
49
51
  setInputValue(newQuery);
50
- if (searchAsYouType && compositionComplete) {
52
+ if (searchAsYouType && !(ignoreCompositionEvents && isComposing)) {
51
53
  refine(newQuery);
52
54
  }
53
55
  }
@@ -58,8 +60,7 @@ function SearchBox(_ref) {
58
60
  }
59
61
  }
60
62
  function onChange(event) {
61
- var compositionComplete = event.type === 'compositionend' || !event.nativeEvent.isComposing;
62
- setQuery(event.currentTarget.value, compositionComplete);
63
+ setQuery(event.currentTarget.value, event.nativeEvent.isComposing);
63
64
  }
64
65
  function onSubmit(event) {
65
66
  if (!searchAsYouType) {
@@ -7,7 +7,13 @@ export type SearchBoxProps = Omit<SearchBoxUiComponentProps, Exclude<keyof UiPro
7
7
  * @default true
8
8
  */
9
9
  searchAsYouType?: boolean;
10
+ /**
11
+ * Whether to update the search state in the middle of a
12
+ * composition session.
13
+ * @default false
14
+ */
15
+ ignoreCompositionEvents?: boolean;
10
16
  translations?: Partial<UiProps['translations']>;
11
17
  };
12
- export declare function SearchBox({ queryHook, searchAsYouType, translations, ...props }: SearchBoxProps): JSX.Element;
18
+ export declare function SearchBox({ queryHook, searchAsYouType, ignoreCompositionEvents, translations, ...props }: SearchBoxProps): JSX.Element;
13
19
  export {};
@@ -1,5 +1,5 @@
1
1
  function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
2
- var _excluded = ["queryHook", "searchAsYouType", "translations"];
2
+ var _excluded = ["queryHook", "searchAsYouType", "ignoreCompositionEvents", "translations"];
3
3
  function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
4
4
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
5
5
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
@@ -21,6 +21,8 @@ export function SearchBox(_ref) {
21
21
  var queryHook = _ref.queryHook,
22
22
  _ref$searchAsYouType = _ref.searchAsYouType,
23
23
  searchAsYouType = _ref$searchAsYouType === void 0 ? true : _ref$searchAsYouType,
24
+ _ref$ignoreCompositio = _ref.ignoreCompositionEvents,
25
+ ignoreCompositionEvents = _ref$ignoreCompositio === void 0 ? false : _ref$ignoreCompositio,
24
26
  translations = _ref.translations,
25
27
  props = _objectWithoutProperties(_ref, _excluded);
26
28
  var _useSearchBox = useSearchBox({
@@ -37,9 +39,9 @@ export function SearchBox(_ref) {
37
39
  setInputValue = _useState2[1];
38
40
  var inputRef = useRef(null);
39
41
  function setQuery(newQuery) {
40
- var compositionComplete = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
42
+ var isComposing = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
41
43
  setInputValue(newQuery);
42
- if (searchAsYouType && compositionComplete) {
44
+ if (searchAsYouType && !(ignoreCompositionEvents && isComposing)) {
43
45
  refine(newQuery);
44
46
  }
45
47
  }
@@ -50,8 +52,7 @@ export function SearchBox(_ref) {
50
52
  }
51
53
  }
52
54
  function onChange(event) {
53
- var compositionComplete = event.type === 'compositionend' || !event.nativeEvent.isComposing;
54
- setQuery(event.currentTarget.value, compositionComplete);
55
+ setQuery(event.currentTarget.value, event.nativeEvent.isComposing);
55
56
  }
56
57
  function onSubmit(event) {
57
58
  if (!searchAsYouType) {
@@ -7,7 +7,7 @@
7
7
 
8
8
  var React__default = 'default' in React ? React['default'] : React;
9
9
 
10
- var version = '7.5.2';
10
+ var version = '7.5.4';
11
11
 
12
12
  // Copyright Joyent, Inc. and other Node contributors.
13
13
  //
@@ -772,9 +772,12 @@
772
772
  .sort()
773
773
  .forEach(function (facetName) {
774
774
  var facetValues = facetsRefinements[facetName] || [];
775
- facetValues.sort().forEach(function (facetValue) {
776
- facetFilters.push(facetName + ':' + facetValue);
777
- });
775
+ facetValues
776
+ .slice()
777
+ .sort()
778
+ .forEach(function (facetValue) {
779
+ facetFilters.push(facetName + ':' + facetValue);
780
+ });
778
781
  });
779
782
 
780
783
  var facetsExcludes = state.facetsExcludes || {};
@@ -797,9 +800,12 @@
797
800
  }
798
801
  var orFilters = [];
799
802
 
800
- facetValues.sort().forEach(function (facetValue) {
801
- orFilters.push(facetName + ':' + facetValue);
802
- });
803
+ facetValues
804
+ .slice()
805
+ .sort()
806
+ .forEach(function (facetValue) {
807
+ orFilters.push(facetName + ':' + facetValue);
808
+ });
803
809
 
804
810
  facetFilters.push(orFilters);
805
811
  });
@@ -1465,7 +1471,7 @@
1465
1471
  numbers.numericRefinements = numericRefinements;
1466
1472
  }
1467
1473
 
1468
- return merge_1({}, partialState, numbers);
1474
+ return merge_1(partialState, numbers);
1469
1475
  };
1470
1476
 
1471
1477
  /**
@@ -4337,7 +4343,7 @@
4337
4343
 
4338
4344
  var SearchResults_1 = SearchResults;
4339
4345
 
4340
- var version$1 = '3.16.1';
4346
+ var version$1 = '3.16.2';
4341
4347
 
4342
4348
  var escapeFacetValue$3 = escapeFacetValue_1.escapeFacetValue;
4343
4349
 
@@ -7637,13 +7643,16 @@
7637
7643
  return;
7638
7644
  }
7639
7645
  var cachedRequest = Object.keys(results).map(function (key) {
7640
- return results[key].results.map(function (result) {
7641
- return {
7642
- indexName: result.index,
7643
- // We normalize the params received from the server as they can
7644
- // be serialized differently depending on the engine.
7645
- params: serializeQueryParameters(deserializeQueryParameters(result.params))
7646
- };
7646
+ var _results$key = results[key],
7647
+ state = _results$key.state,
7648
+ requestParams = _results$key.requestParams,
7649
+ serverResults = _results$key.results;
7650
+ return serverResults.map(function (result) {
7651
+ return _objectSpread$5({
7652
+ indexName: state.index || result.index
7653
+ }, requestParams || result.params ? {
7654
+ params: serializeQueryParameters(requestParams || deserializeQueryParameters(result.params))
7655
+ } : {});
7647
7656
  });
7648
7657
  });
7649
7658
  var cachedResults = Object.keys(results).reduce(function (acc, key) {
@@ -12195,7 +12204,7 @@
12195
12204
  };
12196
12205
  }
12197
12206
 
12198
- var version$3 = '4.64.0';
12207
+ var version$3 = '4.64.2';
12199
12208
 
12200
12209
  function _typeof$o(obj) {
12201
12210
  "@babel/helpers - typeof";
@@ -12663,9 +12672,7 @@
12663
12672
 
12664
12673
  /**
12665
12674
  * Ends the initialization of InstantSearch.js and triggers the
12666
- * first search. This method should be called after all widgets have been added
12667
- * to the instance of InstantSearch.js. InstantSearch.js also supports adding and removing
12668
- * widgets after the start as an **EXPERIMENTAL** feature.
12675
+ * first search.
12669
12676
  */
12670
12677
  }, {
12671
12678
  key: "start",
@@ -12816,9 +12823,7 @@
12816
12823
  }
12817
12824
 
12818
12825
  /**
12819
- * Removes all widgets without triggering a search afterwards. This is an **EXPERIMENTAL** feature,
12820
- * if you find an issue with it, please
12821
- * [open an issue](https://github.com/algolia/instantsearch/issues/new?title=Problem%20with%20dispose).
12826
+ * Removes all widgets without triggering a search afterwards.
12822
12827
  * @return {undefined} This method does not return anything
12823
12828
  */
12824
12829
  }, {
@@ -16032,7 +16037,7 @@
16032
16037
  dispose: function dispose(_ref4) {
16033
16038
  var state = _ref4.state;
16034
16039
  unmountFn();
16035
- return state.clearRefinements(attribute);
16040
+ return state.removeNumericRefinement(attribute);
16036
16041
  },
16037
16042
  getWidgetUiState: function getWidgetUiState(uiState, _ref5) {
16038
16043
  var searchParameters = _ref5.searchParameters;
@@ -16052,11 +16057,11 @@
16052
16057
  getWidgetSearchParameters: function getWidgetSearchParameters(searchParameters, _ref6) {
16053
16058
  var uiState = _ref6.uiState;
16054
16059
  var value = uiState.numericMenu && uiState.numericMenu[attribute];
16055
- var withoutRefinements = searchParameters.clearRefinements(attribute);
16060
+ var withoutRefinements = searchParameters.setQueryParameters({
16061
+ numericRefinements: _objectSpread$u(_objectSpread$u({}, searchParameters.numericRefinements), {}, _defineProperty$v({}, attribute, {}))
16062
+ });
16056
16063
  if (!value) {
16057
- return withoutRefinements.setQueryParameters({
16058
- numericRefinements: _objectSpread$u(_objectSpread$u({}, withoutRefinements.numericRefinements), {}, _defineProperty$v({}, attribute, {}))
16059
- });
16064
+ return withoutRefinements;
16060
16065
  }
16061
16066
  var isExact = value.indexOf(':') === -1;
16062
16067
  if (isExact) {
@@ -17494,8 +17499,7 @@
17494
17499
  return searchParameters;
17495
17500
  }
17496
17501
  var values = uiState.refinementList && uiState.refinementList[attribute];
17497
- var withoutRefinements = searchParameters.clearRefinements(attribute);
17498
- var withFacetConfiguration = isDisjunctive ? withoutRefinements.addDisjunctiveFacet(attribute) : withoutRefinements.addFacet(attribute);
17502
+ var withFacetConfiguration = isDisjunctive ? searchParameters.addDisjunctiveFacet(attribute).removeDisjunctiveFacetRefinement(attribute) : searchParameters.addFacet(attribute).removeFacetRefinement(attribute);
17499
17503
  var currentMaxValuesPerFacet = withFacetConfiguration.maxValuesPerFacet || 0;
17500
17504
  var nextMaxValuesPerFacet = Math.max(currentMaxValuesPerFacet, showMore ? showMoreLimit : limit);
17501
17505
  var withMaxValuesPerFacet = withFacetConfiguration.setQueryParameter('maxValuesPerFacet', nextMaxValuesPerFacet);
@@ -18344,7 +18348,7 @@
18344
18348
  if (searchParameters.isHierarchicalFacet(attribute) || searchParameters.isConjunctiveFacet(attribute)) {
18345
18349
  return searchParameters;
18346
18350
  }
18347
- var withFacetConfiguration = searchParameters.clearRefinements(attribute).addDisjunctiveFacet(attribute);
18351
+ var withFacetConfiguration = searchParameters.addDisjunctiveFacet(attribute).removeDisjunctiveFacetRefinement(attribute);
18348
18352
  var isRefined = Boolean(uiState.toggle && uiState.toggle[attribute]);
18349
18353
  if (isRefined) {
18350
18354
  if (on) {
@@ -18694,12 +18698,26 @@
18694
18698
  */
18695
18699
  function waitForResults(search) {
18696
18700
  var helper = search.mainHelper;
18701
+
18702
+ // Extract search parameters from the search client to use them
18703
+ // later during hydration.
18704
+ var requestParamsList;
18705
+ var client = helper.getClient();
18706
+ helper.setClient({
18707
+ search: function search(queries) {
18708
+ requestParamsList = queries.map(function (_ref) {
18709
+ var params = _ref.params;
18710
+ return params;
18711
+ });
18712
+ return client.search(queries);
18713
+ }
18714
+ });
18697
18715
  helper.searchOnlyWithDerivedHelpers();
18698
18716
  return new Promise(function (resolve, reject) {
18699
18717
  // All derived helpers resolve in the same tick so we're safe only relying
18700
18718
  // on the first one.
18701
18719
  helper.derivedHelpers[0].on('result', function () {
18702
- resolve();
18720
+ resolve(requestParamsList);
18703
18721
  });
18704
18722
 
18705
18723
  // However, we listen to errors that can happen on any derived helper because
@@ -18721,17 +18739,26 @@
18721
18739
  /**
18722
18740
  * Walks the InstantSearch root index to construct the initial results.
18723
18741
  */
18724
- function getInitialResults(rootIndex) {
18742
+ function getInitialResults(rootIndex,
18743
+ /**
18744
+ * Search parameters sent to the search client,
18745
+ * returned by `waitForResults()`.
18746
+ */
18747
+ requestParamsList) {
18725
18748
  var initialResults = {};
18749
+ var requestParamsIndex = 0;
18726
18750
  walkIndex(rootIndex, function (widget) {
18727
18751
  var searchResults = widget.getResults();
18728
18752
  if (searchResults) {
18729
- initialResults[widget.getIndexId()] = {
18753
+ var requestParams = requestParamsList === null || requestParamsList === void 0 ? void 0 : requestParamsList[requestParamsIndex++];
18754
+ initialResults[widget.getIndexId()] = _objectSpread$D({
18730
18755
  // We convert the Helper state to a plain object to pass parsable data
18731
18756
  // structures from server to client.
18732
18757
  state: _objectSpread$D({}, searchResults._state),
18733
18758
  results: searchResults._rawResults
18734
- };
18759
+ }, requestParams && {
18760
+ requestParams: requestParams
18761
+ });
18735
18762
  }
18736
18763
  });
18737
18764
  if (Object.keys(initialResults).length === 0) {
@@ -18816,9 +18843,9 @@
18816
18843
  throw new Error("Unable to retrieve InstantSearch's server state in `getServerState()`. Did you mount the <InstantSearch> component?");
18817
18844
  }
18818
18845
  return waitForResults(searchRef.current);
18819
- }).then(function () {
18846
+ }).then(function (requestParamsList) {
18820
18847
  return {
18821
- initialResults: getInitialResults(searchRef.current.mainIndex)
18848
+ initialResults: getInitialResults(searchRef.current.mainIndex, requestParamsList)
18822
18849
  };
18823
18850
  });
18824
18851
  }
@@ -20317,11 +20344,13 @@
20317
20344
  }));
20318
20345
  }
20319
20346
 
20320
- var _excluded$E = ["queryHook", "searchAsYouType", "translations"];
20347
+ var _excluded$E = ["queryHook", "searchAsYouType", "ignoreCompositionEvents", "translations"];
20321
20348
  function SearchBox$1(_ref) {
20322
20349
  var queryHook = _ref.queryHook,
20323
20350
  _ref$searchAsYouType = _ref.searchAsYouType,
20324
20351
  searchAsYouType = _ref$searchAsYouType === void 0 ? true : _ref$searchAsYouType,
20352
+ _ref$ignoreCompositio = _ref.ignoreCompositionEvents,
20353
+ ignoreCompositionEvents = _ref$ignoreCompositio === void 0 ? false : _ref$ignoreCompositio,
20325
20354
  translations = _ref.translations,
20326
20355
  props = _objectWithoutProperties$c(_ref, _excluded$E);
20327
20356
  var _useSearchBox = useSearchBox({
@@ -20338,9 +20367,9 @@
20338
20367
  setInputValue = _useState2[1];
20339
20368
  var inputRef = React.useRef(null);
20340
20369
  function setQuery(newQuery) {
20341
- var compositionComplete = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
20370
+ var isComposing = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
20342
20371
  setInputValue(newQuery);
20343
- if (searchAsYouType && compositionComplete) {
20372
+ if (searchAsYouType && !(ignoreCompositionEvents && isComposing)) {
20344
20373
  refine(newQuery);
20345
20374
  }
20346
20375
  }
@@ -20351,8 +20380,7 @@
20351
20380
  }
20352
20381
  }
20353
20382
  function onChange(event) {
20354
- var compositionComplete = event.type === 'compositionend' || !event.nativeEvent.isComposing;
20355
- setQuery(event.currentTarget.value, compositionComplete);
20383
+ setQuery(event.currentTarget.value, event.nativeEvent.isComposing);
20356
20384
  }
20357
20385
  function onSubmit(event) {
20358
20386
  if (!searchAsYouType) {