instantsearch.js 4.57.0 → 4.59.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.
Files changed (40) hide show
  1. package/README.md +1 -2
  2. package/cjs/components/Pagination/Pagination.js +4 -4
  3. package/cjs/components/RefinementList/RefinementList.js +2 -1
  4. package/cjs/components/SearchBox/SearchBox.js +5 -2
  5. package/cjs/components/Selector/Selector.js +4 -2
  6. package/cjs/components/Slider/Slider.js +3 -1
  7. package/cjs/lib/InstantSearch.js +44 -7
  8. package/cjs/lib/utils/createSendEventForFacet.js +12 -5
  9. package/cjs/lib/utils/createSendEventForHits.js +12 -6
  10. package/cjs/lib/version.js +1 -1
  11. package/cjs/middlewares/createInsightsMiddleware.js +16 -5
  12. package/cjs/widgets/index/index.js +16 -7
  13. package/cjs/widgets/sort-by/sort-by.js +2 -1
  14. package/dist/instantsearch.development.d.ts +17 -3
  15. package/dist/instantsearch.development.js +125 -56
  16. package/dist/instantsearch.development.js.map +1 -1
  17. package/dist/instantsearch.production.d.ts +17 -3
  18. package/dist/instantsearch.production.min.d.ts +17 -3
  19. package/dist/instantsearch.production.min.js +2 -2
  20. package/dist/instantsearch.production.min.js.map +1 -1
  21. package/es/components/InternalHighlight/InternalHighlight.d.ts +1 -1
  22. package/es/components/Pagination/Pagination.js +4 -4
  23. package/es/components/RefinementList/RefinementList.js +2 -1
  24. package/es/components/SearchBox/SearchBox.d.ts +3 -0
  25. package/es/components/SearchBox/SearchBox.js +5 -2
  26. package/es/components/Selector/Selector.d.ts +2 -1
  27. package/es/components/Selector/Selector.js +4 -2
  28. package/es/components/Slider/Slider.js +3 -1
  29. package/es/lib/InstantSearch.d.ts +15 -0
  30. package/es/lib/InstantSearch.js +42 -6
  31. package/es/lib/utils/createSendEventForFacet.d.ts +1 -1
  32. package/es/lib/utils/createSendEventForFacet.js +12 -5
  33. package/es/lib/utils/createSendEventForHits.d.ts +2 -2
  34. package/es/lib/utils/createSendEventForHits.js +12 -6
  35. package/es/lib/version.d.ts +1 -1
  36. package/es/lib/version.js +1 -1
  37. package/es/middlewares/createInsightsMiddleware.js +16 -5
  38. package/es/widgets/index/index.js +16 -7
  39. package/es/widgets/sort-by/sort-by.js +2 -1
  40. package/package.json +8 -8
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  <p align="center">
2
2
  <a href="https://www.algolia.com/doc/guides/building-search-ui/what-is-instantsearch/js/">
3
- <img alt="InstantSearch.js" src=".github/banner.png">
3
+ <img alt="InstantSearch.js" src="https://github.com/algolia/instantsearch/blob/master/.github/banner.png?raw=true">
4
4
  </a>
5
5
 
6
6
  <p align="center">
@@ -20,7 +20,6 @@ InstantSearch.js is a vanilla JavaScript library that lets you create an instant
20
20
  <!-- START doctoc generated TOC please keep comment here to allow auto update -->
21
21
  <!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
22
22
 
23
-
24
23
  - [Why](#why)
25
24
  - [Getting started](#getting-started)
26
25
  - [Installation](#installation)
@@ -26,7 +26,7 @@ function Pagination(props) {
26
26
  }, (0, _preact.h)("ul", {
27
27
  className: props.cssClasses.list
28
28
  }, props.showFirst && (0, _preact.h)(PaginationLink, {
29
- ariaLabel: "First",
29
+ ariaLabel: "First Page",
30
30
  className: props.cssClasses.firstPageItem,
31
31
  isDisabled: props.isFirstPage,
32
32
  templates: props.templates,
@@ -36,7 +36,7 @@ function Pagination(props) {
36
36
  cssClasses: props.cssClasses,
37
37
  createClickHandler: createClickHandler
38
38
  }), props.showPrevious && (0, _preact.h)(PaginationLink, {
39
- ariaLabel: "Previous",
39
+ ariaLabel: "Previous Page",
40
40
  className: props.cssClasses.previousPageItem,
41
41
  isDisabled: props.isFirstPage,
42
42
  templates: props.templates,
@@ -59,7 +59,7 @@ function Pagination(props) {
59
59
  createClickHandler: createClickHandler
60
60
  });
61
61
  }), props.showNext && (0, _preact.h)(PaginationLink, {
62
- ariaLabel: "Next",
62
+ ariaLabel: "Next Page",
63
63
  className: props.cssClasses.nextPageItem,
64
64
  isDisabled: props.isLastPage,
65
65
  templates: props.templates,
@@ -69,7 +69,7 @@ function Pagination(props) {
69
69
  cssClasses: props.cssClasses,
70
70
  createClickHandler: createClickHandler
71
71
  }), props.showLast && (0, _preact.h)(PaginationLink, {
72
- ariaLabel: "Last",
72
+ ariaLabel: "Last Page, Page ".concat(props.nbPages),
73
73
  className: props.cssClasses.lastPageItem,
74
74
  isDisabled: props.isLastPage,
75
75
  templates: props.templates,
@@ -209,7 +209,8 @@ var RefinementList = /*#__PURE__*/function (_Component) {
209
209
  // This sets the search box to a controlled state because
210
210
  // we don't rely on the `refine` prop but on `onChange`.
211
211
  ,
212
- searchAsYouType: false
212
+ searchAsYouType: false,
213
+ ariaLabel: "Search for filters"
213
214
  }));
214
215
  var facetValues = this.props.facetValues && this.props.facetValues.length > 0 && (0, _preact.h)("ul", {
215
216
  className: this.props.cssClasses.list
@@ -31,6 +31,7 @@ var defaultProps = {
31
31
  searchAsYouType: true,
32
32
  isSearchStalled: false,
33
33
  disabled: false,
34
+ ariaLabel: 'Search',
34
35
  onChange: _utils.noop,
35
36
  onSubmit: _utils.noop,
36
37
  onReset: _utils.noop,
@@ -147,7 +148,8 @@ var SearchBox = /*#__PURE__*/function (_Component) {
147
148
  showReset = _this$props4.showReset,
148
149
  showLoadingIndicator = _this$props4.showLoadingIndicator,
149
150
  templates = _this$props4.templates,
150
- isSearchStalled = _this$props4.isSearchStalled;
151
+ isSearchStalled = _this$props4.isSearchStalled,
152
+ ariaLabel = _this$props4.ariaLabel;
151
153
  return (0, _preact.h)("div", {
152
154
  className: cssClasses.root
153
155
  }, (0, _preact.h)("form", {
@@ -174,7 +176,8 @@ var SearchBox = /*#__PURE__*/function (_Component) {
174
176
  maxLength: 512,
175
177
  onInput: this.onInput,
176
178
  onBlur: this.onBlur,
177
- onFocus: this.onFocus
179
+ onFocus: this.onFocus,
180
+ "aria-label": ariaLabel
178
181
  }), (0, _preact.h)(_Template.default, {
179
182
  templateKey: "submit",
180
183
  rootTagName: "button",
@@ -10,13 +10,15 @@ function Selector(_ref) {
10
10
  var currentValue = _ref.currentValue,
11
11
  options = _ref.options,
12
12
  cssClasses = _ref.cssClasses,
13
- setValue = _ref.setValue;
13
+ setValue = _ref.setValue,
14
+ ariaLabel = _ref.ariaLabel;
14
15
  return (0, _preact.h)("select", {
15
16
  className: (0, _uiComponentsShared.cx)(cssClasses.select),
16
17
  onChange: function onChange(event) {
17
18
  return setValue(event.target.value);
18
19
  },
19
- value: "".concat(currentValue)
20
+ value: "".concat(currentValue),
21
+ "aria-label": ariaLabel
20
22
  }, options.map(function (option) {
21
23
  return (0, _preact.h)("option", {
22
24
  className: (0, _uiComponentsShared.cx)(cssClasses.option),
@@ -56,8 +56,10 @@ var Slider = /*#__PURE__*/function (_Component) {
56
56
  parseFloat(props['aria-valuenow']) * 100) / 100;
57
57
  var value = _typeof(tooltips) === 'object' && tooltips.format ? tooltips.format(roundedValue) : roundedValue;
58
58
  var className = (0, _uiComponentsShared.cx)(props.className, props['data-handle-key'] === 0 && 'rheostat-handle-lower', props['data-handle-key'] === 1 && 'rheostat-handle-upper');
59
+ var ariaLabel = props['data-handle-key'] === 0 ? 'Minimum Filter Handle' : 'Maximum Filter Handle';
59
60
  return (0, _preact.h)("div", _extends({}, props, {
60
- className: className
61
+ className: className,
62
+ "aria-label": ariaLabel
61
63
  }), tooltips && (0, _preact.h)("div", {
62
64
  className: "rheostat-tooltip"
63
65
  }, value));
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.default = void 0;
6
+ exports.default = exports.INSTANTSEARCH_FUTURE_DEFAULTS = void 0;
7
7
  var _events = _interopRequireDefault(require("@algolia/events"));
8
8
  var _algoliasearchHelper = _interopRequireDefault(require("algoliasearch-helper"));
9
9
  var _createInsightsMiddleware = require("../middlewares/createInsightsMiddleware");
@@ -43,15 +43,21 @@ function defaultCreateURL() {
43
43
  /**
44
44
  * Global options for an InstantSearch instance.
45
45
  */
46
+ var INSTANTSEARCH_FUTURE_DEFAULTS = {
47
+ preserveSharedStateOnUnmount: false
48
+ };
49
+
46
50
  /**
47
51
  * The actual implementation of the InstantSearch. This is
48
52
  * created using the `instantsearch` factory function.
49
53
  * It emits the 'render' event every time a search is done
50
54
  */
55
+ exports.INSTANTSEARCH_FUTURE_DEFAULTS = INSTANTSEARCH_FUTURE_DEFAULTS;
51
56
  var InstantSearch = /*#__PURE__*/function (_EventEmitter) {
52
57
  _inherits(InstantSearch, _EventEmitter);
53
58
  var _super = _createSuper(InstantSearch);
54
59
  function InstantSearch(options) {
60
+ var _options$future2;
55
61
  var _this;
56
62
  _classCallCheck(this, InstantSearch);
57
63
  _this = _super.call(this);
@@ -61,6 +67,7 @@ var InstantSearch = /*#__PURE__*/function (_EventEmitter) {
61
67
  _defineProperty(_assertThisInitialized(_this), "indexName", void 0);
62
68
  _defineProperty(_assertThisInitialized(_this), "insightsClient", void 0);
63
69
  _defineProperty(_assertThisInitialized(_this), "onStateChange", null);
70
+ _defineProperty(_assertThisInitialized(_this), "future", void 0);
64
71
  _defineProperty(_assertThisInitialized(_this), "helper", void 0);
65
72
  _defineProperty(_assertThisInitialized(_this), "mainHelper", void 0);
66
73
  _defineProperty(_assertThisInitialized(_this), "mainIndex", void 0);
@@ -74,6 +81,7 @@ var InstantSearch = /*#__PURE__*/function (_EventEmitter) {
74
81
  _defineProperty(_assertThisInitialized(_this), "_createURL", void 0);
75
82
  _defineProperty(_assertThisInitialized(_this), "_searchFunction", void 0);
76
83
  _defineProperty(_assertThisInitialized(_this), "_mainHelperSearch", void 0);
84
+ _defineProperty(_assertThisInitialized(_this), "_insights", void 0);
77
85
  _defineProperty(_assertThisInitialized(_this), "middleware", []);
78
86
  _defineProperty(_assertThisInitialized(_this), "sendEventToInsights", void 0);
79
87
  /**
@@ -124,7 +132,7 @@ var InstantSearch = /*#__PURE__*/function (_EventEmitter) {
124
132
  _options$routing = options.routing,
125
133
  routing = _options$routing === void 0 ? null : _options$routing,
126
134
  _options$insights = options.insights,
127
- insights = _options$insights === void 0 ? false : _options$insights,
135
+ insights = _options$insights === void 0 ? undefined : _options$insights,
128
136
  searchFunction = options.searchFunction,
129
137
  _options$stalledSearc = options.stalledSearchDelay,
130
138
  stalledSearchDelay = _options$stalledSearc === void 0 ? 200 : _options$stalledSearc,
@@ -133,7 +141,9 @@ var InstantSearch = /*#__PURE__*/function (_EventEmitter) {
133
141
  _options$insightsClie = options.insightsClient,
134
142
  insightsClient = _options$insightsClie === void 0 ? null : _options$insightsClie,
135
143
  _options$onStateChang = options.onStateChange,
136
- onStateChange = _options$onStateChang === void 0 ? null : _options$onStateChang;
144
+ onStateChange = _options$onStateChang === void 0 ? null : _options$onStateChang,
145
+ _options$future = options.future,
146
+ future = _options$future === void 0 ? _objectSpread(_objectSpread({}, INSTANTSEARCH_FUTURE_DEFAULTS), options.future || {}) : _options$future;
137
147
  if (searchClient === null) {
138
148
  throw new Error(withUsage('The `searchClient` option is required.'));
139
149
  }
@@ -150,7 +160,14 @@ var InstantSearch = /*#__PURE__*/function (_EventEmitter) {
150
160
  process.env.NODE_ENV === 'development' ? (0, _utils.warning)(!options.searchParameters, "The `searchParameters` option is deprecated and will not be supported in InstantSearch.js 4.x.\n\nYou can replace it with the `configure` widget:\n\n```\nsearch.addWidgets([\n configure(".concat(JSON.stringify(options.searchParameters, null, 2), ")\n]);\n```\n\nSee ").concat((0, _utils.createDocumentationLink)({
151
161
  name: 'configure'
152
162
  }))) : void 0;
163
+ if (process.env.NODE_ENV === 'development' && ((_options$future2 = options.future) === null || _options$future2 === void 0 ? void 0 : _options$future2.preserveSharedStateOnUnmount) === undefined) {
164
+ // eslint-disable-next-line no-console
165
+ console.info("Starting from the next major version, InstantSearch will change how widgets state is preserved when they are removed. InstantSearch will keep the state of unmounted widgets to be usable by other widgets with the same attribute.\n\nWe recommend setting `future.preserveSharedStateOnUnmount` to true to adopt this change today.\nTo stay with the current behaviour and remove this warning, set the option to false.\n\nSee documentation: ".concat((0, _utils.createDocumentationLink)({
166
+ name: 'instantsearch'
167
+ }), "#widget-param-future\n "));
168
+ }
153
169
  _this.client = searchClient;
170
+ _this.future = future;
154
171
  _this.insightsClient = insightsClient;
155
172
  _this.indexName = indexName;
156
173
  _this.helper = null;
@@ -171,6 +188,7 @@ var InstantSearch = /*#__PURE__*/function (_EventEmitter) {
171
188
  _this._createURL = defaultCreateURL;
172
189
  _this._initialUiState = initialUiState;
173
190
  _this._initialResults = null;
191
+ _this._insights = insights;
174
192
  if (searchFunction) {
175
193
  process.env.NODE_ENV === 'development' ? (0, _utils.warning)(false, "The `searchFunction` option is deprecated. Use `onStateChange` instead.") : void 0;
176
194
  _this._searchFunction = searchFunction;
@@ -182,8 +200,9 @@ var InstantSearch = /*#__PURE__*/function (_EventEmitter) {
182
200
  _this.use((0, _createRouterMiddleware.createRouterMiddleware)(routerOptions));
183
201
  }
184
202
 
185
- // This is the default middleware,
186
- // any user-provided middleware will be added later and override this one.
203
+ // This is the default Insights middleware,
204
+ // added when `insights` is set to true by the user.
205
+ // Any user-provided middleware will be added later and override this one.
187
206
  if (insights) {
188
207
  var insightsOptions = typeof insights === 'boolean' ? {} : insights;
189
208
  insightsOptions.$$internal = true;
@@ -475,6 +494,24 @@ var InstantSearch = /*#__PURE__*/function (_EventEmitter) {
475
494
  var instance = _ref6.instance;
476
495
  instance.started();
477
496
  });
497
+
498
+ // This is the automatic Insights middleware,
499
+ // added when `insights` is unset and the initial results possess `queryID`.
500
+ // Any user-provided middleware will be added later and override this one.
501
+ if (typeof this._insights === 'undefined') {
502
+ mainHelper.derivedHelpers[0].once('result', function () {
503
+ var hasAutomaticInsights = _this3.mainIndex.getScopedResults().some(function (_ref7) {
504
+ var results = _ref7.results;
505
+ return results === null || results === void 0 ? void 0 : results._automaticInsights;
506
+ });
507
+ if (hasAutomaticInsights) {
508
+ _this3.use((0, _createInsightsMiddleware.createInsightsMiddleware)({
509
+ $$internal: true,
510
+ $$automatic: true
511
+ }));
512
+ }
513
+ });
514
+ }
478
515
  }
479
516
 
480
517
  /**
@@ -504,8 +541,8 @@ var InstantSearch = /*#__PURE__*/function (_EventEmitter) {
504
541
  (_this$mainHelper2 = this.mainHelper) === null || _this$mainHelper2 === void 0 ? void 0 : _this$mainHelper2.removeAllListeners();
505
542
  this.mainHelper = null;
506
543
  this.helper = null;
507
- this.middleware.forEach(function (_ref7) {
508
- var instance = _ref7.instance;
544
+ this.middleware.forEach(function (_ref8) {
545
+ var instance = _ref8.instance;
509
546
  instance.unsubscribe();
510
547
  });
511
548
  }
@@ -5,6 +5,11 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.createSendEventForFacet = createSendEventForFacet;
7
7
  var _isFacetRefined = require("./isFacetRefined");
8
+ 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; }
9
+ 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; }
10
+ 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; }
11
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
12
+ 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); }
8
13
  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); }
9
14
  function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
10
15
  function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
@@ -23,7 +28,9 @@ function createSendEventForFacet(_ref) {
23
28
  }
24
29
  var facetValue = args[1],
25
30
  _args$ = args[2],
26
- eventName = _args$ === void 0 ? 'Filter Applied' : _args$;
31
+ eventName = _args$ === void 0 ? 'Filter Applied' : _args$,
32
+ _args$2 = args[3],
33
+ additionalData = _args$2 === void 0 ? {} : _args$2;
27
34
  var _args$0$split = args[0].split(':'),
28
35
  _args$0$split2 = _slicedToArray(_args$0$split, 2),
29
36
  eventType = _args$0$split2[0],
@@ -31,7 +38,7 @@ function createSendEventForFacet(_ref) {
31
38
  var attribute = typeof attr === 'string' ? attr : attr(facetValue);
32
39
  if (args.length === 1 && _typeof(args[0]) === 'object') {
33
40
  instantSearchInstance.sendEventToInsights(args[0]);
34
- } else if (eventType === 'click' && (args.length === 2 || args.length === 3)) {
41
+ } else if (eventType === 'click' && args.length >= 2 && args.length <= 4) {
35
42
  if (!(0, _isFacetRefined.isFacetRefined)(helper, attribute, facetValue)) {
36
43
  // send event only when the facet is being checked "ON"
37
44
  instantSearchInstance.sendEventToInsights({
@@ -39,16 +46,16 @@ function createSendEventForFacet(_ref) {
39
46
  widgetType: widgetType,
40
47
  eventType: eventType,
41
48
  eventModifier: eventModifier,
42
- payload: {
49
+ payload: _objectSpread({
43
50
  eventName: eventName,
44
51
  index: helper.getIndex(),
45
52
  filters: ["".concat(attribute, ":").concat(facetValue)]
46
- },
53
+ }, additionalData),
47
54
  attribute: attribute
48
55
  });
49
56
  }
50
57
  } else if (process.env.NODE_ENV === 'development') {
51
- throw new Error("You need to pass two arguments like:\n sendEvent('click', facetValue);\n\nIf you want to send a custom payload, you can pass one object: sendEvent(customPayload);\n");
58
+ throw new Error("You need to pass between two and four arguments like:\n sendEvent('click', facetValue, eventName?, additionalData?);\n\nIf you want to send a custom payload, you can pass one object: sendEvent(customPayload);\n");
52
59
  }
53
60
  };
54
61
  return sendEventForFacet;
@@ -7,6 +7,11 @@ exports._buildEventPayloadsForHits = _buildEventPayloadsForHits;
7
7
  exports.createBindEventForHits = createBindEventForHits;
8
8
  exports.createSendEventForHits = createSendEventForHits;
9
9
  var _serializer = require("./serializer");
10
+ 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; }
11
+ 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; }
12
+ 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; }
13
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
14
+ 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); }
10
15
  function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
11
16
  function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
12
17
  function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
@@ -38,6 +43,7 @@ function _buildEventPayloadsForHits(_ref) {
38
43
  eventModifier = _args$0$split2[1];
39
44
  var hits = args[1];
40
45
  var eventName = args[2];
46
+ var additionalData = args[3] || {};
41
47
  if (!hits) {
42
48
  if (process.env.NODE_ENV === 'development') {
43
49
  throw new Error("You need to pass hit or hits as the second argument like:\n ".concat(methodName, "(eventType, hit);\n "));
@@ -77,11 +83,11 @@ function _buildEventPayloadsForHits(_ref) {
77
83
  insightsMethod: 'viewedObjectIDs',
78
84
  widgetType: widgetType,
79
85
  eventType: eventType,
80
- payload: {
86
+ payload: _objectSpread({
81
87
  eventName: eventName || 'Hits Viewed',
82
88
  index: index,
83
89
  objectIDs: objectIDsByChunk[i]
84
- },
90
+ }, additionalData),
85
91
  hits: batch,
86
92
  eventModifier: eventModifier
87
93
  };
@@ -92,13 +98,13 @@ function _buildEventPayloadsForHits(_ref) {
92
98
  insightsMethod: 'clickedObjectIDsAfterSearch',
93
99
  widgetType: widgetType,
94
100
  eventType: eventType,
95
- payload: {
101
+ payload: _objectSpread({
96
102
  eventName: eventName || 'Hit Clicked',
97
103
  index: index,
98
104
  queryID: queryID,
99
105
  objectIDs: objectIDsByChunk[i],
100
106
  positions: positionsByChunk[i]
101
- },
107
+ }, additionalData),
102
108
  hits: batch,
103
109
  eventModifier: eventModifier
104
110
  };
@@ -109,12 +115,12 @@ function _buildEventPayloadsForHits(_ref) {
109
115
  insightsMethod: 'convertedObjectIDsAfterSearch',
110
116
  widgetType: widgetType,
111
117
  eventType: eventType,
112
- payload: {
118
+ payload: _objectSpread({
113
119
  eventName: eventName || 'Hit Converted',
114
120
  index: index,
115
121
  queryID: queryID,
116
122
  objectIDs: objectIDsByChunk[i]
117
- },
123
+ }, additionalData),
118
124
  hits: batch,
119
125
  eventModifier: eventModifier
120
126
  };
@@ -4,5 +4,5 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
- var _default = '4.57.0';
7
+ var _default = '4.59.0';
8
8
  exports.default = _default;
@@ -30,7 +30,9 @@ function createInsightsMiddleware() {
30
30
  insightsInitParams = props.insightsInitParams,
31
31
  onEvent = props.onEvent,
32
32
  _props$$$internal = props.$$internal,
33
- $$internal = _props$$$internal === void 0 ? false : _props$$$internal;
33
+ $$internal = _props$$$internal === void 0 ? false : _props$$$internal,
34
+ _props$$$automatic = props.$$automatic,
35
+ $$automatic = _props$$$automatic === void 0 ? false : _props$$$automatic;
34
36
  var potentialInsightsClient = _insightsClient;
35
37
  if (!_insightsClient && _insightsClient !== null) {
36
38
  (0, _utils.safelyRunOnBrowser)(function (_ref) {
@@ -121,6 +123,7 @@ function createInsightsMiddleware() {
121
123
  return {
122
124
  $$type: 'ais.insights',
123
125
  $$internal: $$internal,
126
+ $$automatic: $$automatic,
124
127
  onStateChange: function onStateChange() {},
125
128
  subscribe: function subscribe() {
126
129
  if (!insightsClient.shouldAddScript) return;
@@ -141,14 +144,19 @@ function createInsightsMiddleware() {
141
144
  },
142
145
  started: function started() {
143
146
  insightsClient('addAlgoliaAgent', 'insights-middleware');
144
- helper = instantSearchInstance.helper;
147
+ helper = instantSearchInstance.mainHelper;
145
148
  initialParameters = {
146
149
  userToken: helper.state.userToken,
147
150
  clickAnalytics: helper.state.clickAnalytics
148
151
  };
149
- helper.overrideStateWithoutTriggeringChangeEvent(_objectSpread(_objectSpread({}, helper.state), {}, {
150
- clickAnalytics: true
151
- }));
152
+
153
+ // We don't want to force clickAnalytics when the insights is enabled from the search response.
154
+ // This means we don't enable insights for indices that don't opt in
155
+ if (!$$automatic) {
156
+ helper.overrideStateWithoutTriggeringChangeEvent(_objectSpread(_objectSpread({}, helper.state), {}, {
157
+ clickAnalytics: true
158
+ }));
159
+ }
152
160
  if (!$$internal) {
153
161
  instantSearchInstance.scheduleSearch();
154
162
  }
@@ -215,6 +223,9 @@ function createInsightsMiddleware() {
215
223
  } else if (event.insightsMethod) {
216
224
  // Source is used to differentiate events sent by instantsearch from those sent manually.
217
225
  event.payload.algoliaSource = ['instantsearch'];
226
+ if ($$automatic) {
227
+ event.payload.algoliaSource.push('instantsearch-automatic');
228
+ }
218
229
  if (event.eventModifier === 'internal') {
219
230
  event.payload.algoliaSource.push('instantsearch-internal');
220
231
  }
@@ -214,7 +214,7 @@ var index = function index(widgetParams) {
214
214
  return widgets.indexOf(widget) === -1;
215
215
  });
216
216
  if (localInstantSearchInstance && Boolean(widgets.length)) {
217
- var _nextState = widgets.reduce(function (state, widget) {
217
+ var cleanedState = widgets.reduce(function (state, widget) {
218
218
  // the `dispose` method exists at this point we already assert it
219
219
  var next = widget.dispose({
220
220
  helper: helper,
@@ -223,14 +223,23 @@ var index = function index(widgetParams) {
223
223
  });
224
224
  return next || state;
225
225
  }, helper.state);
226
+ var newState = localInstantSearchInstance.future.preserveSharedStateOnUnmount ? getLocalWidgetsSearchParameters(localWidgets, {
227
+ uiState: localUiState,
228
+ initialSearchParameters: new _algoliasearchHelper.default.SearchParameters({
229
+ index: this.getIndexName()
230
+ })
231
+ }) : getLocalWidgetsSearchParameters(localWidgets, {
232
+ uiState: getLocalWidgetsUiState(localWidgets, {
233
+ searchParameters: cleanedState,
234
+ helper: helper
235
+ }),
236
+ initialSearchParameters: cleanedState
237
+ });
226
238
  localUiState = getLocalWidgetsUiState(localWidgets, {
227
- searchParameters: _nextState,
239
+ searchParameters: newState,
228
240
  helper: helper
229
241
  });
230
- helper.setState(getLocalWidgetsSearchParameters(localWidgets, {
231
- uiState: localUiState,
232
- initialSearchParameters: _nextState
233
- }));
242
+ helper.setState(newState);
234
243
  if (localWidgets.length) {
235
244
  localInstantSearchInstance.scheduleSearch();
236
245
  }
@@ -296,7 +305,7 @@ var index = function index(widgetParams) {
296
305
  return mainHelper.searchForFacetValues(facetName, facetValue, maxFacetHits, state);
297
306
  };
298
307
  derivedHelper = mainHelper.derive(function () {
299
- return _utils.mergeSearchParameters.apply(void 0, _toConsumableArray((0, _utils.resolveSearchParameters)(_this3)));
308
+ return _utils.mergeSearchParameters.apply(void 0, [mainHelper.state].concat(_toConsumableArray((0, _utils.resolveSearchParameters)(_this3))));
300
309
  });
301
310
  var indexInitialResults = (_instantSearchInstanc = instantSearchInstance._initialResults) === null || _instantSearchInstanc === void 0 ? void 0 : _instantSearchInstanc[this.getIndexId()];
302
311
  if (indexInitialResults) {
@@ -37,7 +37,8 @@ var renderer = function renderer(_ref) {
37
37
  cssClasses: cssClasses,
38
38
  currentValue: currentRefinement,
39
39
  options: options,
40
- setValue: refine
40
+ setValue: refine,
41
+ ariaLabel: "Sort results by"
41
42
  })), containerNode);
42
43
  };
43
44
  };
@@ -531,11 +531,11 @@ declare type BrowserHistoryArgs<TRouteState> = {
531
531
  push?: (url: string) => void;
532
532
  };
533
533
 
534
- declare type BuiltInBindEventForHits = (eventType: string, hits: Hit | Hit[], eventName?: string) => string;
534
+ declare type BuiltInBindEventForHits = (eventType: string, hits: Hit | Hit[], eventName?: string, additionalData?: Record<string, any>) => string;
535
535
 
536
- declare type BuiltInSendEventForFacet = (eventType: string, facetValue: string, eventName?: string) => void;
536
+ declare type BuiltInSendEventForFacet = (eventType: string, facetValue: string, eventName?: string, additionalData?: Record<string, any>) => void;
537
537
 
538
- declare type BuiltInSendEventForHits = (eventType: string, hits: Hit | Hit[], eventName?: string) => void;
538
+ declare type BuiltInSendEventForHits = (eventType: string, hits: Hit | Hit[], eventName?: string, additionalData?: Record<string, any>) => void;
539
539
 
540
540
  declare type BuiltInSendEventForToggle = (eventType: string, isRefined: boolean, eventName?: string) => void;
541
541
 
@@ -2363,6 +2363,7 @@ declare class InstantSearch<TUiState extends UiState = UiState, TRouteState = TU
2363
2363
  indexName: string;
2364
2364
  insightsClient: InsightsClient | null;
2365
2365
  onStateChange: InstantSearchOptions<TUiState>['onStateChange'] | null;
2366
+ future: NonNullable<InstantSearchOptions<TUiState>['future']>;
2366
2367
  helper: AlgoliaSearchHelper | null;
2367
2368
  mainHelper: AlgoliaSearchHelper | null;
2368
2369
  mainIndex: IndexWidget;
@@ -2376,6 +2377,7 @@ declare class InstantSearch<TUiState extends UiState = UiState, TRouteState = TU
2376
2377
  _createURL: CreateURL<TUiState>;
2377
2378
  _searchFunction?: InstantSearchOptions['searchFunction'];
2378
2379
  _mainHelperSearch?: AlgoliaSearchHelper['search'];
2380
+ _insights: InstantSearchOptions['insights'];
2379
2381
  middleware: Array<{
2380
2382
  creator: Middleware<TUiState>;
2381
2383
  instance: MiddlewareDefinition<TUiState>;
@@ -2604,6 +2606,18 @@ declare type InstantSearchOptions<TUiState extends UiState = UiState, TRouteStat
2604
2606
  * @deprecated This property will be still supported in 4.x releases, but not further. It is replaced by the `insights` middleware. For more information, visit https://www.algolia.com/doc/guides/getting-insights-and-analytics/search-analytics/click-through-and-conversions/how-to/send-click-and-conversion-events-with-instantsearch/js/
2605
2607
  */
2606
2608
  insightsClient?: InsightsClient;
2609
+ future?: {
2610
+ /**
2611
+ * Changes the way `dispose` is used in InstantSearch lifecycle.
2612
+ *
2613
+ * If `false` (by default), each widget unmounting will remove its state as well, even if there are multiple widgets reading that UI State.
2614
+ *
2615
+ * If `true`, each widget unmounting will only remove its own state if it's the last of its type. This allows for dynamically adding and removing widgets without losing their state.
2616
+ *
2617
+ * @default false
2618
+ */
2619
+ preserveSharedStateOnUnmount?: boolean;
2620
+ };
2607
2621
  };
2608
2622
 
2609
2623
  declare type InstantSearchStatus = 'idle' | 'loading' | 'stalled' | 'error';