instantsearch.js 4.43.0 → 4.44.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 (53) hide show
  1. package/CHANGELOG.md +29 -0
  2. package/cjs/components/Highlight/Highlight.js +33 -0
  3. package/cjs/components/InternalHighlight/InternalHighlight.js +16 -0
  4. package/cjs/components/ReverseHighlight/ReverseHighlight.js +33 -0
  5. package/cjs/components/ReverseSnippet/ReverseSnippet.js +33 -0
  6. package/cjs/components/Snippet/Snippet.js +33 -0
  7. package/cjs/connectors/numeric-menu/connectNumericMenu.js +4 -41
  8. package/cjs/connectors/range/connectRange.js +7 -46
  9. package/cjs/connectors/rating-menu/connectRatingMenu.js +1 -1
  10. package/cjs/helpers/components/Highlight.js +45 -0
  11. package/cjs/helpers/components/ReverseHighlight.js +58 -0
  12. package/cjs/helpers/components/ReverseSnippet.js +58 -0
  13. package/cjs/helpers/components/Snippet.js +45 -0
  14. package/cjs/helpers/components/index.js +57 -0
  15. package/cjs/lib/InstantSearch.js +11 -1
  16. package/cjs/lib/version.js +1 -1
  17. package/dist/instantsearch.development.d.ts +10 -10
  18. package/dist/instantsearch.development.js +25 -116
  19. package/dist/instantsearch.development.js.map +1 -1
  20. package/dist/instantsearch.production.d.ts +10 -10
  21. package/dist/instantsearch.production.min.d.ts +10 -10
  22. package/dist/instantsearch.production.min.js +2 -2
  23. package/dist/instantsearch.production.min.js.map +1 -1
  24. package/es/components/Highlight/Highlight.d.ts +7 -0
  25. package/es/components/Highlight/Highlight.js +24 -0
  26. package/es/components/InternalHighlight/InternalHighlight.d.ts +2 -0
  27. package/es/components/InternalHighlight/InternalHighlight.js +6 -0
  28. package/es/components/ReverseHighlight/ReverseHighlight.d.ts +7 -0
  29. package/es/components/ReverseHighlight/ReverseHighlight.js +24 -0
  30. package/es/components/ReverseSnippet/ReverseSnippet.d.ts +7 -0
  31. package/es/components/ReverseSnippet/ReverseSnippet.js +24 -0
  32. package/es/components/Snippet/Snippet.d.ts +7 -0
  33. package/es/components/Snippet/Snippet.js +24 -0
  34. package/es/connectors/geo-search/connectGeoSearch.d.ts +10 -10
  35. package/es/connectors/numeric-menu/connectNumericMenu.js +5 -42
  36. package/es/connectors/range/connectRange.js +8 -47
  37. package/es/connectors/rating-menu/connectRatingMenu.js +1 -1
  38. package/es/helpers/components/Highlight.d.ts +10 -0
  39. package/es/helpers/components/Highlight.js +31 -0
  40. package/es/helpers/components/ReverseHighlight.d.ts +10 -0
  41. package/es/helpers/components/ReverseHighlight.js +44 -0
  42. package/es/helpers/components/ReverseSnippet.d.ts +10 -0
  43. package/es/helpers/components/ReverseSnippet.js +44 -0
  44. package/es/helpers/components/Snippet.d.ts +10 -0
  45. package/es/helpers/components/Snippet.js +31 -0
  46. package/es/helpers/components/index.d.ts +4 -0
  47. package/es/helpers/components/index.js +4 -0
  48. package/es/lib/InstantSearch.js +11 -1
  49. package/es/lib/version.d.ts +1 -1
  50. package/es/lib/version.js +1 -1
  51. package/es/types/results.d.ts +1 -1
  52. package/es/types/utils.d.ts +4 -0
  53. package/package.json +5 -2
@@ -4,5 +4,5 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
- var _default = '4.43.0';
7
+ var _default = '4.44.1';
8
8
  exports.default = _default;
@@ -34,7 +34,7 @@ declare type AlgoliaHit<THit extends BaseHit = Record<string, any>> = {
34
34
  };
35
35
  };
36
36
  _distinctSeqID?: number;
37
- _geoLoc?: GeoLoc;
37
+ _geoloc?: GeoLoc;
38
38
  } & THit;
39
39
 
40
40
  declare const analytics: AnalyticsWidget;
@@ -1169,7 +1169,7 @@ declare const EXPERIMENTAL_connectDynamicWidgets: DynamicWidgetsConnector;
1169
1169
  /** @deprecated use dynamicWidgets */
1170
1170
  declare const EXPERIMENTAL_dynamicWidgets: DynamicWidgetsWidget;
1171
1171
 
1172
- declare type GeoHit = Hit & Required<Pick<Hit, '_geoLoc'>>;
1172
+ declare type GeoHit<THit extends BaseHit = Record<string, any>> = Hit<THit> & Required<Pick<Hit, '_geoloc'>>;
1173
1173
 
1174
1174
  declare type GeoLoc = {
1175
1175
  lat: number;
@@ -1191,9 +1191,9 @@ declare type GeoLoc = {
1191
1191
  */
1192
1192
  declare const geoSearch: GeoSearchWidget;
1193
1193
 
1194
- declare type GeoSearchConnector = Connector<GeoSearchWidgetDescription, GeoSearchConnectorParams>;
1194
+ declare type GeoSearchConnector<THit extends BaseHit = Record<string, any>> = Connector<GeoSearchWidgetDescription<THit>, GeoSearchConnectorParams<THit>>;
1195
1195
 
1196
- declare type GeoSearchConnectorParams = {
1196
+ declare type GeoSearchConnectorParams<THit extends BaseHit = Record<string, any>> = {
1197
1197
  /**
1198
1198
  * If true, refine will be triggered as you move the map.
1199
1199
  * @default true
@@ -1203,7 +1203,7 @@ declare type GeoSearchConnectorParams = {
1203
1203
  * Function to transform the items passed to the templates.
1204
1204
  * @default items => items
1205
1205
  */
1206
- transformItems?: TransformItems<GeoHit>;
1206
+ transformItems?: TransformItems<GeoHit<THit>>;
1207
1207
  };
1208
1208
 
1209
1209
  declare type GeoSearchCSSClasses = Partial<{
@@ -1249,7 +1249,7 @@ declare type GeoSearchMarker<TOptions> = {
1249
1249
  };
1250
1250
  };
1251
1251
 
1252
- declare type GeoSearchRenderState = {
1252
+ declare type GeoSearchRenderState<THit extends BaseHit = Record<string, any>> = {
1253
1253
  /**
1254
1254
  * Reset the current bounding box refinement.
1255
1255
  */
@@ -1273,7 +1273,7 @@ declare type GeoSearchRenderState = {
1273
1273
  /**
1274
1274
  * The matched hits from Algolia API.
1275
1275
  */
1276
- items: GeoHit[];
1276
+ items: Array<GeoHit<THit>>;
1277
1277
  /**
1278
1278
  * The current position of the search.
1279
1279
  */
@@ -1313,11 +1313,11 @@ declare type GeoSearchWidget = WidgetFactory<GeoSearchWidgetDescription & {
1313
1313
  $$widgetType: 'ais.geoSearch';
1314
1314
  }, GeoSearchConnectorParams, GeoSearchWidgetParams>;
1315
1315
 
1316
- declare type GeoSearchWidgetDescription = {
1316
+ declare type GeoSearchWidgetDescription<THit extends BaseHit = Record<string, any>> = {
1317
1317
  $$type: 'ais.geoSearch';
1318
- renderState: GeoSearchRenderState;
1318
+ renderState: GeoSearchRenderState<THit>;
1319
1319
  indexRenderState: {
1320
- geoSearch: WidgetRenderState<GeoSearchRenderState, GeoSearchConnectorParams>;
1320
+ geoSearch: WidgetRenderState<GeoSearchRenderState<THit>, GeoSearchConnectorParams<THit>>;
1321
1321
  };
1322
1322
  indexUiState: {
1323
1323
  geoSearch: {
@@ -1,4 +1,4 @@
1
- /*! InstantSearch.js 4.43.0 | © Algolia, Inc. and contributors; MIT License | https://github.com/algolia/instantsearch.js */
1
+ /*! InstantSearch.js 4.44.1 | © Algolia, Inc. and contributors; MIT License | https://github.com/algolia/instantsearch.js */
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) :
@@ -7918,31 +7918,6 @@
7918
7918
  }
7919
7919
  }
7920
7920
 
7921
- function convertNumericRefinementsToFilters(state, attribute) {
7922
- if (!state) {
7923
- return null;
7924
- }
7925
-
7926
- var filtersObj = state.numericRefinements[attribute];
7927
- /*
7928
- filtersObj === {
7929
- "<=": [10],
7930
- "=": [],
7931
- ">=": [5]
7932
- }
7933
- */
7934
-
7935
- var filters = [];
7936
- Object.keys(filtersObj).filter(function (operator) {
7937
- return Array.isArray(filtersObj[operator]) && filtersObj[operator].length > 0;
7938
- }).forEach(function (operator) {
7939
- filtersObj[operator].forEach(function (value) {
7940
- filters.push("".concat(attribute).concat(operator).concat(value));
7941
- });
7942
- });
7943
- return filters;
7944
- }
7945
-
7946
7921
  // copied from
7947
7922
  // https://github.com/algolia/autocomplete.js/blob/307a7acc4283e10a19cb7d067f04f1bea79dc56f/packages/autocomplete-core/src/utils/createConcurrentSafePromise.ts#L1:L1
7948
7923
 
@@ -8603,7 +8578,7 @@
8603
8578
  instantSearchInstance.renderState = _objectSpread2(_objectSpread2({}, instantSearchInstance.renderState), {}, _defineProperty({}, parentIndexName, _objectSpread2(_objectSpread2({}, instantSearchInstance.renderState[parentIndexName]), renderState)));
8604
8579
  }
8605
8580
 
8606
- var version$1 = '4.43.0';
8581
+ var version$1 = '4.44.1';
8607
8582
 
8608
8583
  var NAMESPACE = 'ais';
8609
8584
  var component = function component(componentName) {
@@ -10477,12 +10452,22 @@
10477
10452
 
10478
10453
  mainHelper.on('error', function (_ref4) {
10479
10454
  var error = _ref4.error;
10480
- // If an error is emitted, it is re-thrown by events. In previous versions
10455
+
10456
+ if (!(error instanceof Error)) {
10457
+ // typescript lies here, error is in some cases { name: string, message: string }
10458
+ var err = error;
10459
+ error = Object.keys(err).reduce(function (acc, key) {
10460
+ acc[key] = err[key];
10461
+ return acc;
10462
+ }, new Error(err.message));
10463
+ } // If an error is emitted, it is re-thrown by events. In previous versions
10481
10464
  // we emitted {error}, which is thrown as:
10482
10465
  // "Uncaught, unspecified \"error\" event. ([object Object])"
10483
10466
  // To avoid breaking changes, we make the error available in both
10484
10467
  // `error` and `error.error`
10485
10468
  // @MAJOR emit only error
10469
+
10470
+
10486
10471
  error.error = error;
10487
10472
 
10488
10473
  _this3.emit('error', error);
@@ -12107,46 +12092,11 @@
12107
12092
  var $$type = 'ais.numericMenu';
12108
12093
 
12109
12094
  var createSendEvent = function createSendEvent(_ref) {
12110
- var instantSearchInstance = _ref.instantSearchInstance,
12111
- helper = _ref.helper,
12112
- attribute = _ref.attribute;
12095
+ var instantSearchInstance = _ref.instantSearchInstance;
12113
12096
  return function () {
12114
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
12115
- args[_key] = arguments[_key];
12116
- }
12117
-
12118
- if (args.length === 1) {
12119
- instantSearchInstance.sendEventToInsights(args[0]);
12120
- return;
12121
- }
12122
-
12123
- var eventType = args[0],
12124
- facetValue = args[1],
12125
- _args$ = args[2],
12126
- eventName = _args$ === void 0 ? 'Filter Applied' : _args$;
12127
-
12128
- if (eventType !== 'click') {
12097
+ if (arguments.length === 1) {
12098
+ instantSearchInstance.sendEventToInsights(arguments.length <= 0 ? undefined : arguments[0]);
12129
12099
  return;
12130
- } // facetValue === "%7B%22start%22:5,%22end%22:10%7D"
12131
-
12132
-
12133
- var filters = convertNumericRefinementsToFilters(getRefinedState(helper.state, attribute, facetValue), attribute);
12134
-
12135
- if (filters && filters.length > 0) {
12136
- /*
12137
- filters === ["price<=10", "price>=5"]
12138
- */
12139
- instantSearchInstance.sendEventToInsights({
12140
- insightsMethod: 'clickedFilters',
12141
- widgetType: $$type,
12142
- eventType: eventType,
12143
- payload: {
12144
- eventName: eventName,
12145
- index: helper.getIndex(),
12146
- filters: filters
12147
- },
12148
- attribute: attribute
12149
- });
12150
12100
  }
12151
12101
  };
12152
12102
  };
@@ -12291,9 +12241,7 @@
12291
12241
 
12292
12242
  if (!connectorState.sendEvent) {
12293
12243
  connectorState.sendEvent = createSendEvent({
12294
- instantSearchInstance: instantSearchInstance,
12295
- helper: helper,
12296
- attribute: attribute
12244
+ instantSearchInstance: instantSearchInstance
12297
12245
  });
12298
12246
  }
12299
12247
 
@@ -12719,50 +12667,12 @@
12719
12667
  return null;
12720
12668
  };
12721
12669
 
12722
- var sendEventWithRefinedState = function sendEventWithRefinedState(refinedState, instantSearchInstance, helper) {
12723
- var eventName = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'Filter Applied';
12724
- var filters = convertNumericRefinementsToFilters(refinedState, attribute);
12725
-
12726
- if (filters && filters.length > 0) {
12727
- instantSearchInstance.sendEventToInsights({
12728
- insightsMethod: 'clickedFilters',
12729
- widgetType: $$type$1,
12730
- eventType: 'click',
12731
- payload: {
12732
- eventName: eventName,
12733
- index: helper.getIndex(),
12734
- filters: filters
12735
- },
12736
- attribute: attribute
12737
- });
12738
- }
12739
- };
12740
-
12741
- var createSendEvent = function createSendEvent(instantSearchInstance, helper, currentRange) {
12670
+ var createSendEvent = function createSendEvent(instantSearchInstance) {
12742
12671
  return function () {
12743
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
12744
- args[_key] = arguments[_key];
12745
- }
12746
-
12747
- if (args.length === 1) {
12748
- instantSearchInstance.sendEventToInsights(args[0]);
12749
- return;
12750
- }
12751
-
12752
- var eventType = args[0],
12753
- facetValue = args[1],
12754
- eventName = args[2];
12755
-
12756
- if (eventType !== 'click') {
12672
+ if (arguments.length === 1) {
12673
+ instantSearchInstance.sendEventToInsights(arguments.length <= 0 ? undefined : arguments[0]);
12757
12674
  return;
12758
12675
  }
12759
-
12760
- var _facetValue = _slicedToArray(facetValue, 2),
12761
- nextMin = _facetValue[0],
12762
- nextMax = _facetValue[1];
12763
-
12764
- var refinedState = getRefinedState(helper, currentRange, nextMin, nextMax);
12765
- sendEventWithRefinedState(refinedState, instantSearchInstance, helper, eventName);
12766
12676
  };
12767
12677
  };
12768
12678
 
@@ -12808,7 +12718,7 @@
12808
12718
  return [min, max];
12809
12719
  }
12810
12720
 
12811
- function _refine(instantSearchInstance, helper, currentRange) {
12721
+ function _refine(helper, currentRange) {
12812
12722
  return function () {
12813
12723
  var _ref11 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [undefined, undefined],
12814
12724
  _ref12 = _slicedToArray(_ref11, 2),
@@ -12818,7 +12728,6 @@
12818
12728
  var refinedState = getRefinedState(helper, currentRange, nextMin, nextMax);
12819
12729
 
12820
12730
  if (refinedState) {
12821
- sendEventWithRefinedState(refinedState, instantSearchInstance, helper);
12822
12731
  helper.setState(refinedState).search();
12823
12732
  }
12824
12733
  };
@@ -12864,12 +12773,12 @@
12864
12773
  // On first render pass an empty range
12865
12774
  // to be able to bypass the validation
12866
12775
  // related to it
12867
- refine = _refine(instantSearchInstance, helper, {
12776
+ refine = _refine(helper, {
12868
12777
  min: undefined,
12869
12778
  max: undefined
12870
12779
  });
12871
12780
  } else {
12872
- refine = _refine(instantSearchInstance, helper, currentRange);
12781
+ refine = _refine(helper, currentRange);
12873
12782
  }
12874
12783
 
12875
12784
  return {
@@ -12877,7 +12786,7 @@
12877
12786
  canRefine: currentRange.min !== currentRange.max,
12878
12787
  format: rangeFormatter,
12879
12788
  range: currentRange,
12880
- sendEvent: createSendEvent(instantSearchInstance, helper, currentRange),
12789
+ sendEvent: createSendEvent(instantSearchInstance),
12881
12790
  widgetParams: _objectSpread2(_objectSpread2({}, widgetParams), {}, {
12882
12791
  precision: precision
12883
12792
  }),
@@ -13612,7 +13521,7 @@
13612
13521
  var maxValuesPerFacet = facetResults.length;
13613
13522
  var maxDecimalPlaces = getFacetsMaxDecimalPlaces(facetResults);
13614
13523
  var maxFacets = Math.pow(10, maxDecimalPlaces) * max;
13615
- _warning(maxFacets <= maxValuesPerFacet, getFacetValuesWarningMessage({
13524
+ _warning(maxFacets <= maxValuesPerFacet || Boolean(results.__isArtificial), getFacetValuesWarningMessage({
13616
13525
  maxDecimalPlaces: maxDecimalPlaces,
13617
13526
  maxFacets: maxFacets,
13618
13527
  maxValuesPerFacet: maxValuesPerFacet