instantsearch.js 4.54.0 → 4.55.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 (104) hide show
  1. package/cjs/components/Hits/Hits.js +16 -7
  2. package/cjs/components/InfiniteHits/InfiniteHits.js +13 -2
  3. package/cjs/components/Pagination/Pagination.js +35 -17
  4. package/cjs/components/Template/Template.js +6 -3
  5. package/cjs/connectors/autocomplete/connectAutocomplete.js +1 -1
  6. package/cjs/connectors/geo-search/connectGeoSearch.js +1 -1
  7. package/cjs/connectors/hierarchical-menu/connectHierarchicalMenu.js +1 -1
  8. package/cjs/connectors/hits/connectHits.js +1 -1
  9. package/cjs/connectors/infinite-hits/connectInfiniteHits.js +39 -31
  10. package/cjs/connectors/menu/connectMenu.js +1 -1
  11. package/cjs/connectors/numeric-menu/connectNumericMenu.js +1 -1
  12. package/cjs/connectors/rating-menu/connectRatingMenu.js +7 -3
  13. package/cjs/connectors/refinement-list/connectRefinementList.js +1 -1
  14. package/cjs/connectors/toggle-refinement/connectToggleRefinement.js +14 -4
  15. package/cjs/helpers/highlight.js +5 -0
  16. package/cjs/helpers/insights.js +3 -4
  17. package/cjs/helpers/reverseHighlight.js +5 -0
  18. package/cjs/helpers/reverseSnippet.js +5 -0
  19. package/cjs/helpers/snippet.js +5 -0
  20. package/cjs/lib/InstantSearch.js +18 -2
  21. package/cjs/lib/insights/listener.js +43 -36
  22. package/cjs/lib/routers/history.js +1 -0
  23. package/cjs/lib/server.js +60 -0
  24. package/cjs/lib/stateMappings/simple.js +1 -0
  25. package/cjs/lib/stateMappings/singleIndex.js +1 -0
  26. package/cjs/lib/utils/createSendEventForFacet.js +12 -2
  27. package/cjs/lib/utils/createSendEventForHits.js +34 -11
  28. package/cjs/lib/utils/index.js +11 -0
  29. package/cjs/lib/utils/walkIndex.js +18 -0
  30. package/cjs/lib/version.js +1 -1
  31. package/cjs/middlewares/createInsightsMiddleware.js +135 -33
  32. package/cjs/middlewares/createMetadataMiddleware.js +17 -5
  33. package/cjs/middlewares/createRouterMiddleware.js +5 -1
  34. package/cjs/widgets/hits/hits.js +1 -2
  35. package/cjs/widgets/infinite-hits/infinite-hits.js +1 -2
  36. package/cjs/widgets/pagination/pagination.js +51 -39
  37. package/cjs/widgets/panel/panel.js +0 -2
  38. package/dist/instantsearch.development.d.ts +94 -12
  39. package/dist/instantsearch.development.js +543 -312
  40. package/dist/instantsearch.development.js.map +1 -1
  41. package/dist/instantsearch.production.d.ts +94 -12
  42. package/dist/instantsearch.production.min.d.ts +94 -12
  43. package/dist/instantsearch.production.min.js +2 -2
  44. package/dist/instantsearch.production.min.js.map +1 -1
  45. package/es/components/Hits/Hits.d.ts +5 -5
  46. package/es/components/Hits/Hits.js +15 -5
  47. package/es/components/InfiniteHits/InfiniteHits.d.ts +3 -2
  48. package/es/components/InfiniteHits/InfiniteHits.js +13 -2
  49. package/es/components/Pagination/Pagination.js +34 -17
  50. package/es/components/Panel/Panel.d.ts +1 -1
  51. package/es/components/Template/Template.js +6 -3
  52. package/es/connectors/autocomplete/connectAutocomplete.js +1 -1
  53. package/es/connectors/geo-search/connectGeoSearch.js +1 -1
  54. package/es/connectors/hierarchical-menu/connectHierarchicalMenu.js +1 -1
  55. package/es/connectors/hits/connectHits.js +1 -1
  56. package/es/connectors/infinite-hits/connectInfiniteHits.js +39 -31
  57. package/es/connectors/menu/connectMenu.js +1 -1
  58. package/es/connectors/numeric-menu/connectNumericMenu.js +1 -1
  59. package/es/connectors/rating-menu/connectRatingMenu.js +7 -3
  60. package/es/connectors/refinement-list/connectRefinementList.js +1 -1
  61. package/es/connectors/toggle-refinement/connectToggleRefinement.js +13 -3
  62. package/es/helpers/highlight.d.ts +3 -0
  63. package/es/helpers/highlight.js +5 -0
  64. package/es/helpers/insights.d.ts +2 -1
  65. package/es/helpers/insights.js +3 -3
  66. package/es/helpers/reverseHighlight.d.ts +3 -0
  67. package/es/helpers/reverseHighlight.js +5 -0
  68. package/es/helpers/reverseSnippet.d.ts +3 -0
  69. package/es/helpers/reverseSnippet.js +5 -0
  70. package/es/helpers/snippet.d.ts +3 -0
  71. package/es/helpers/snippet.js +5 -0
  72. package/es/lib/InstantSearch.d.ts +11 -1
  73. package/es/lib/InstantSearch.js +18 -2
  74. package/es/lib/insights/listener.d.ts +10 -6
  75. package/es/lib/insights/listener.js +42 -36
  76. package/es/lib/routers/history.d.ts +1 -0
  77. package/es/lib/routers/history.js +1 -0
  78. package/es/lib/server.d.ts +10 -0
  79. package/es/lib/server.js +53 -0
  80. package/es/lib/stateMappings/simple.js +1 -0
  81. package/es/lib/stateMappings/singleIndex.js +1 -0
  82. package/es/lib/utils/createSendEventForFacet.js +12 -2
  83. package/es/lib/utils/createSendEventForHits.d.ts +8 -0
  84. package/es/lib/utils/createSendEventForHits.js +33 -11
  85. package/es/lib/utils/index.d.ts +1 -0
  86. package/es/lib/utils/index.js +1 -0
  87. package/es/lib/utils/walkIndex.d.ts +5 -0
  88. package/es/lib/utils/walkIndex.js +12 -0
  89. package/es/lib/version.d.ts +1 -1
  90. package/es/lib/version.js +1 -1
  91. package/es/middlewares/createInsightsMiddleware.d.ts +12 -12
  92. package/es/middlewares/createInsightsMiddleware.js +136 -34
  93. package/es/middlewares/createMetadataMiddleware.d.ts +3 -1
  94. package/es/middlewares/createMetadataMiddleware.js +17 -5
  95. package/es/middlewares/createRouterMiddleware.js +5 -1
  96. package/es/types/insights.d.ts +19 -1
  97. package/es/types/middleware.d.ts +16 -0
  98. package/es/types/router.d.ts +8 -0
  99. package/es/widgets/hits/hits.js +2 -3
  100. package/es/widgets/infinite-hits/infinite-hits.js +2 -3
  101. package/es/widgets/pagination/pagination.d.ts +12 -5
  102. package/es/widgets/pagination/pagination.js +51 -39
  103. package/es/widgets/panel/panel.js +0 -2
  104. package/package.json +6 -6
@@ -7,6 +7,10 @@ exports.default = snippet;
7
7
  var _suit = require("../lib/suit");
8
8
  var _utils = require("../lib/utils");
9
9
  var suit = (0, _suit.component)('Snippet');
10
+
11
+ /**
12
+ * @deprecated use html tagged templates and the Snippet component instead
13
+ */
10
14
  function snippet(_ref) {
11
15
  var attribute = _ref.attribute,
12
16
  _ref$highlightedTagNa = _ref.highlightedTagName,
@@ -14,6 +18,7 @@ function snippet(_ref) {
14
18
  hit = _ref.hit,
15
19
  _ref$cssClasses = _ref.cssClasses,
16
20
  cssClasses = _ref$cssClasses === void 0 ? {} : _ref$cssClasses;
21
+ process.env.NODE_ENV === 'development' ? (0, _utils.warning)(false, "`instantsearch.snippet` function has been deprecated. It is still supported in 4.x releases, but not further. It is replaced by the `Snippet` component.\n\nFor more information, visit https://www.algolia.com/doc/guides/building-search-ui/upgrade-guides/js/?client=html+tagged+templates#upgrade-templates") : void 0;
17
22
  var snippetAttributeResult = (0, _utils.getPropertyByPath)(hit._snippetResult, attribute);
18
23
 
19
24
  // @MAJOR fallback to attribute value if snippet is not found
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.default = void 0;
7
7
  var _events = _interopRequireDefault(require("@algolia/events"));
8
8
  var _algoliasearchHelper = _interopRequireDefault(require("algoliasearch-helper"));
9
+ var _createInsightsMiddleware = require("../middlewares/createInsightsMiddleware");
9
10
  var _createMetadataMiddleware = require("../middlewares/createMetadataMiddleware");
10
11
  var _createRouterMiddleware = require("../middlewares/createRouterMiddleware");
11
12
  var _index = _interopRequireDefault(require("../widgets/index/index"));
@@ -112,6 +113,8 @@ var InstantSearch = /*#__PURE__*/function (_EventEmitter) {
112
113
  initialUiState = _options$initialUiSta === void 0 ? {} : _options$initialUiSta,
113
114
  _options$routing = options.routing,
114
115
  routing = _options$routing === void 0 ? null : _options$routing,
116
+ _options$insights = options.insights,
117
+ insights = _options$insights === void 0 ? false : _options$insights,
115
118
  searchFunction = options.searchFunction,
116
119
  _options$stalledSearc = options.stalledSearchDelay,
117
120
  stalledSearchDelay = _options$stalledSearc === void 0 ? 200 : _options$stalledSearc,
@@ -167,11 +170,22 @@ var InstantSearch = /*#__PURE__*/function (_EventEmitter) {
167
170
  }
168
171
  _this.sendEventToInsights = _utils.noop;
169
172
  if (routing) {
170
- var routerOptions = typeof routing === 'boolean' ? undefined : routing;
173
+ var routerOptions = typeof routing === 'boolean' ? {} : routing;
174
+ routerOptions.$$internal = true;
171
175
  _this.use((0, _createRouterMiddleware.createRouterMiddleware)(routerOptions));
172
176
  }
177
+
178
+ // This is the default middleware,
179
+ // any user-provided middleware will be added later and override this one.
180
+ if (insights) {
181
+ var insightsOptions = typeof insights === 'boolean' ? {} : insights;
182
+ insightsOptions.$$internal = true;
183
+ _this.use((0, _createInsightsMiddleware.createInsightsMiddleware)(insightsOptions));
184
+ }
173
185
  if ((0, _createMetadataMiddleware.isMetadataEnabled)()) {
174
- _this.use((0, _createMetadataMiddleware.createMetadataMiddleware)());
186
+ _this.use((0, _createMetadataMiddleware.createMetadataMiddleware)({
187
+ $$internal: true
188
+ }));
175
189
  }
176
190
  return _this;
177
191
  }
@@ -207,6 +221,8 @@ var InstantSearch = /*#__PURE__*/function (_EventEmitter) {
207
221
  }
208
222
  var newMiddlewareList = middleware.map(function (fn) {
209
223
  var newMiddleware = _objectSpread({
224
+ $$type: '__unknown__',
225
+ $$internal: false,
210
226
  subscribe: _utils.noop,
211
227
  started: _utils.noop,
212
228
  unsubscribe: _utils.noop,
@@ -3,11 +3,40 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.default = void 0;
6
+ exports.createInsightsEventHandler = void 0;
7
+ exports.default = withInsightsListener;
7
8
  var _preact = require("preact");
8
9
  var _insights = require("../../helpers/insights");
9
10
  var _utils = require("../utils");
10
- var findInsightsTarget = function findInsightsTarget(startElement, endElement, validator) {
11
+ var createInsightsEventHandler = function createInsightsEventHandler(_ref) {
12
+ var insights = _ref.insights,
13
+ sendEvent = _ref.sendEvent;
14
+ return function (event) {
15
+ // new way, e.g. bindEvent("click", hit, "Hit clicked")
16
+ var insightsThroughSendEvent = findInsightsTarget(event.target, event.currentTarget, function (element) {
17
+ return element.hasAttribute('data-insights-event');
18
+ });
19
+ if (insightsThroughSendEvent) {
20
+ var payload = parseInsightsEvent(insightsThroughSendEvent);
21
+ payload.forEach(function (single) {
22
+ return sendEvent(single);
23
+ });
24
+ }
25
+
26
+ // old way, e.g. instantsearch.insights("clickedObjectIDsAfterSearch", { .. })
27
+ var insightsThroughFunction = findInsightsTarget(event.target, event.currentTarget, function (element) {
28
+ return element.hasAttribute('data-insights-method') && element.hasAttribute('data-insights-payload');
29
+ });
30
+ if (insightsThroughFunction) {
31
+ var _readDataAttributes = (0, _insights.readDataAttributes)(insightsThroughFunction),
32
+ method = _readDataAttributes.method,
33
+ _payload = _readDataAttributes.payload;
34
+ insights(method, _payload);
35
+ }
36
+ };
37
+ };
38
+ exports.createInsightsEventHandler = createInsightsEventHandler;
39
+ function findInsightsTarget(startElement, endElement, validator) {
11
40
  var element = startElement;
12
41
  while (element && !validator(element)) {
13
42
  if (element === endElement) {
@@ -16,8 +45,8 @@ var findInsightsTarget = function findInsightsTarget(startElement, endElement, v
16
45
  element = element.parentElement;
17
46
  }
18
47
  return element;
19
- };
20
- var parseInsightsEvent = function parseInsightsEvent(element) {
48
+ }
49
+ function parseInsightsEvent(element) {
21
50
  var serializedPayload = element.getAttribute('data-insights-event');
22
51
  if (typeof serializedPayload !== 'string') {
23
52
  throw new Error('The insights middleware expects `data-insights-event` to be a base64-encoded JSON string.');
@@ -27,39 +56,17 @@ var parseInsightsEvent = function parseInsightsEvent(element) {
27
56
  } catch (error) {
28
57
  throw new Error('The insights middleware was unable to parse `data-insights-event`.');
29
58
  }
30
- };
31
- var insightsListener = function insightsListener(BaseComponent) {
32
- function WithInsightsListener(props) {
33
- var handleClick = function handleClick(event) {
34
- if (props.sendEvent) {
35
- // new way with insights middleware
36
- var targetWithEvent = findInsightsTarget(event.target, event.currentTarget, function (element) {
37
- return element.hasAttribute('data-insights-event');
38
- });
39
- if (targetWithEvent) {
40
- var payload = parseInsightsEvent(targetWithEvent);
41
- payload.forEach(function (single) {
42
- return props.sendEvent(single);
43
- });
44
- }
45
- }
59
+ }
46
60
 
47
- // old way, e.g. instantsearch.insights("clickedObjectIDsAfterSearch", { .. })
48
- var insightsTarget = findInsightsTarget(event.target, event.currentTarget, function (element) {
49
- return (0, _insights.hasDataAttributes)(element);
50
- });
51
- if (insightsTarget) {
52
- var _readDataAttributes = (0, _insights.readDataAttributes)(insightsTarget),
53
- method = _readDataAttributes.method,
54
- _payload = _readDataAttributes.payload;
55
- props.insights(method, _payload);
56
- }
57
- };
61
+ /**
62
+ * @deprecated use `sendEvent` directly instead
63
+ */
64
+ function withInsightsListener(BaseComponent) {
65
+ process.env.NODE_ENV === 'development' ? (0, _utils.warning)(false, 'The `withInsightsListener` function is deprecated and will be removed in the next major version. Please use `sendEvent` directly instead.') : void 0;
66
+ return function WithInsightsListener(props) {
67
+ var handleClick = createInsightsEventHandler(props);
58
68
  return (0, _preact.h)("div", {
59
69
  onClick: handleClick
60
70
  }, (0, _preact.h)(BaseComponent, props));
61
- }
62
- return WithInsightsListener;
63
- };
64
- var _default = insightsListener;
65
- exports.default = _default;
71
+ };
72
+ }
@@ -38,6 +38,7 @@ var BrowserHistory = /*#__PURE__*/function () {
38
38
  dispose = _ref.dispose,
39
39
  push = _ref.push;
40
40
  _classCallCheck(this, BrowserHistory);
41
+ _defineProperty(this, "$$type", 'ais.browser');
41
42
  _defineProperty(this, "windowTitle", void 0);
42
43
  _defineProperty(this, "writeDelay", void 0);
43
44
  _defineProperty(this, "_createURL", void 0);
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getInitialResults = getInitialResults;
7
+ exports.waitForResults = waitForResults;
8
+ var _utils = require("./utils");
9
+ 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); }
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); }
15
+ /**
16
+ * Waits for the results from the search instance to coordinate the next steps
17
+ * in `getServerState()`.
18
+ */
19
+ function waitForResults(search) {
20
+ var helper = search.mainHelper;
21
+ helper.searchOnlyWithDerivedHelpers();
22
+ return new Promise(function (resolve, reject) {
23
+ // All derived helpers resolve in the same tick so we're safe only relying
24
+ // on the first one.
25
+ helper.derivedHelpers[0].on('result', function () {
26
+ resolve();
27
+ });
28
+
29
+ // However, we listen to errors that can happen on any derived helper because
30
+ // any error is critical.
31
+ helper.on('error', function (error) {
32
+ reject(error);
33
+ });
34
+ search.on('error', function (error) {
35
+ reject(error);
36
+ });
37
+ helper.derivedHelpers.forEach(function (derivedHelper) {
38
+ return derivedHelper.on('error', function (error) {
39
+ reject(error);
40
+ });
41
+ });
42
+ });
43
+ }
44
+
45
+ /**
46
+ * Walks the InstantSearch root index to construct the initial results.
47
+ */
48
+ function getInitialResults(rootIndex) {
49
+ var initialResults = {};
50
+ (0, _utils.walkIndex)(rootIndex, function (widget) {
51
+ var searchResults = widget.getResults();
52
+ initialResults[widget.getIndexId()] = {
53
+ // We convert the Helper state to a plain object to pass parsable data
54
+ // structures from server to client.
55
+ state: _objectSpread({}, searchResults._state),
56
+ results: searchResults._rawResults
57
+ };
58
+ });
59
+ return initialResults;
60
+ }
@@ -24,6 +24,7 @@ function getIndexStateWithoutConfigure(uiState) {
24
24
  // which excludes "configure" as this function does.
25
25
  function simpleStateMapping() {
26
26
  return {
27
+ $$type: 'ais.simple',
27
28
  stateToRoute: function stateToRoute(uiState) {
28
29
  return Object.keys(uiState).reduce(function (state, indexId) {
29
30
  return _objectSpread(_objectSpread({}, state), {}, _defineProperty({}, indexId, getIndexStateWithoutConfigure(uiState[indexId])));
@@ -18,6 +18,7 @@ function getIndexStateWithoutConfigure(uiState) {
18
18
  }
19
19
  function singleIndexStateMapping(indexName) {
20
20
  return {
21
+ $$type: 'ais.singleIndex',
21
22
  stateToRoute: function stateToRoute(uiState) {
22
23
  return getIndexStateWithoutConfigure(uiState[indexName] || {});
23
24
  },
@@ -6,6 +6,12 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.createSendEventForFacet = createSendEventForFacet;
7
7
  var _isFacetRefined = require("./isFacetRefined");
8
8
  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
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
10
+ 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."); }
11
+ 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); }
12
+ 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; }
13
+ function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
14
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
9
15
  function createSendEventForFacet(_ref) {
10
16
  var instantSearchInstance = _ref.instantSearchInstance,
11
17
  helper = _ref.helper,
@@ -15,10 +21,13 @@ function createSendEventForFacet(_ref) {
15
21
  for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
16
22
  args[_key] = arguments[_key];
17
23
  }
18
- var eventType = args[0],
19
- facetValue = args[1],
24
+ var facetValue = args[1],
20
25
  _args$ = args[2],
21
26
  eventName = _args$ === void 0 ? 'Filter Applied' : _args$;
27
+ var _args$0$split = args[0].split(':'),
28
+ _args$0$split2 = _slicedToArray(_args$0$split, 2),
29
+ eventType = _args$0$split2[0],
30
+ eventModifier = _args$0$split2[1];
22
31
  var attribute = typeof attr === 'string' ? attr : attr(facetValue);
23
32
  if (args.length === 1 && _typeof(args[0]) === 'object') {
24
33
  instantSearchInstance.sendEventToInsights(args[0]);
@@ -29,6 +38,7 @@ function createSendEventForFacet(_ref) {
29
38
  insightsMethod: 'clickedFilters',
30
39
  widgetType: widgetType,
31
40
  eventType: eventType,
41
+ eventModifier: eventModifier,
32
42
  payload: {
33
43
  eventName: eventName,
34
44
  index: helper.getIndex(),
@@ -3,9 +3,16 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ exports._buildEventPayloadsForHits = _buildEventPayloadsForHits;
6
7
  exports.createBindEventForHits = createBindEventForHits;
7
8
  exports.createSendEventForHits = createSendEventForHits;
8
9
  var _serializer = require("./serializer");
10
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
11
+ 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
+ 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); }
13
+ 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; }
14
+ function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
15
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
9
16
  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); }
10
17
  function chunk(arr) {
11
18
  var chunkSize = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 20;
@@ -15,7 +22,7 @@ function chunk(arr) {
15
22
  }
16
23
  return chunks;
17
24
  }
18
- var buildPayloads = function buildPayloads(_ref) {
25
+ function _buildEventPayloadsForHits(_ref) {
19
26
  var index = _ref.index,
20
27
  widgetType = _ref.widgetType,
21
28
  methodName = _ref.methodName,
@@ -25,7 +32,10 @@ var buildPayloads = function buildPayloads(_ref) {
25
32
  if (args.length === 1 && _typeof(args[0]) === 'object') {
26
33
  return [args[0]];
27
34
  }
28
- var eventType = args[0];
35
+ var _args$0$split = args[0].split(':'),
36
+ _args$0$split2 = _slicedToArray(_args$0$split, 2),
37
+ eventType = _args$0$split2[0],
38
+ eventModifier = _args$0$split2[1];
29
39
  var hits = args[1];
30
40
  var eventName = args[2];
31
41
  if (!hits) {
@@ -72,7 +82,8 @@ var buildPayloads = function buildPayloads(_ref) {
72
82
  index: index,
73
83
  objectIDs: objectIDsByChunk[i]
74
84
  },
75
- hits: batch
85
+ hits: batch,
86
+ eventModifier: eventModifier
76
87
  };
77
88
  });
78
89
  } else if (eventType === 'click') {
@@ -82,13 +93,14 @@ var buildPayloads = function buildPayloads(_ref) {
82
93
  widgetType: widgetType,
83
94
  eventType: eventType,
84
95
  payload: {
85
- eventName: eventName,
96
+ eventName: eventName || 'Hit Clicked',
86
97
  index: index,
87
98
  queryID: queryID,
88
99
  objectIDs: objectIDsByChunk[i],
89
100
  positions: positionsByChunk[i]
90
101
  },
91
- hits: batch
102
+ hits: batch,
103
+ eventModifier: eventModifier
92
104
  };
93
105
  });
94
106
  } else if (eventType === 'conversion') {
@@ -98,12 +110,13 @@ var buildPayloads = function buildPayloads(_ref) {
98
110
  widgetType: widgetType,
99
111
  eventType: eventType,
100
112
  payload: {
101
- eventName: eventName,
113
+ eventName: eventName || 'Hit Converted',
102
114
  index: index,
103
115
  queryID: queryID,
104
116
  objectIDs: objectIDsByChunk[i]
105
117
  },
106
- hits: batch
118
+ hits: batch,
119
+ eventModifier: eventModifier
107
120
  };
108
121
  });
109
122
  } else if (process.env.NODE_ENV === 'development') {
@@ -111,16 +124,18 @@ var buildPayloads = function buildPayloads(_ref) {
111
124
  } else {
112
125
  return [];
113
126
  }
114
- };
127
+ }
115
128
  function createSendEventForHits(_ref2) {
116
129
  var instantSearchInstance = _ref2.instantSearchInstance,
117
130
  index = _ref2.index,
118
131
  widgetType = _ref2.widgetType;
132
+ var sentEvents = {};
133
+ var timer = undefined;
119
134
  var sendEventForHits = function sendEventForHits() {
120
135
  for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
121
136
  args[_key] = arguments[_key];
122
137
  }
123
- var payloads = buildPayloads({
138
+ var payloads = _buildEventPayloadsForHits({
124
139
  widgetType: widgetType,
125
140
  index: index,
126
141
  methodName: 'sendEvent',
@@ -128,8 +143,16 @@ function createSendEventForHits(_ref2) {
128
143
  instantSearchInstance: instantSearchInstance
129
144
  });
130
145
  payloads.forEach(function (payload) {
131
- return instantSearchInstance.sendEventToInsights(payload);
146
+ if (payload.eventType === 'click' && payload.eventModifier === 'internal' && sentEvents[payload.eventType]) {
147
+ return;
148
+ }
149
+ sentEvents[payload.eventType] = true;
150
+ instantSearchInstance.sendEventToInsights(payload);
132
151
  });
152
+ clearTimeout(timer);
153
+ timer = setTimeout(function () {
154
+ sentEvents = {};
155
+ }, 0);
133
156
  };
134
157
  return sendEventForHits;
135
158
  }
@@ -141,7 +164,7 @@ function createBindEventForHits(_ref3) {
141
164
  for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
142
165
  args[_key2] = arguments[_key2];
143
166
  }
144
- var payloads = buildPayloads({
167
+ var payloads = _buildEventPayloadsForHits({
145
168
  widgetType: widgetType,
146
169
  index: index,
147
170
  methodName: 'bindEvent',
@@ -388,6 +388,17 @@ Object.keys(_isSpecialClick).forEach(function (key) {
388
388
  }
389
389
  });
390
390
  });
391
+ var _walkIndex = require("./walkIndex");
392
+ Object.keys(_walkIndex).forEach(function (key) {
393
+ if (key === "default" || key === "__esModule") return;
394
+ if (key in exports && exports[key] === _walkIndex[key]) return;
395
+ Object.defineProperty(exports, key, {
396
+ enumerable: true,
397
+ get: function get() {
398
+ return _walkIndex[key];
399
+ }
400
+ });
401
+ });
391
402
  var _logger = require("./logger");
392
403
  Object.keys(_logger).forEach(function (key) {
393
404
  if (key === "default" || key === "__esModule") return;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.walkIndex = walkIndex;
7
+ var _isIndexWidget = require("./isIndexWidget");
8
+ /**
9
+ * Recurse over all child indices
10
+ */
11
+ function walkIndex(indexWidget, callback) {
12
+ callback(indexWidget);
13
+ indexWidget.getWidgets().forEach(function (widget) {
14
+ if ((0, _isIndexWidget.isIndexWidget)(widget)) {
15
+ walkIndex(widget, callback);
16
+ }
17
+ });
18
+ }
@@ -4,5 +4,5 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
- var _default = '4.54.0';
7
+ var _default = '4.55.0';
8
8
  exports.default = _default;