instantsearch.js 4.46.3 → 4.47.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/CHANGELOG.md +14 -0
  2. package/cjs/connectors/hierarchical-menu/connectHierarchicalMenu.js +4 -1
  3. package/cjs/lib/InstantSearch.js +45 -6
  4. package/cjs/lib/utils/createSendEventForFacet.js +2 -1
  5. package/cjs/lib/utils/createSendEventForHits.js +1 -1
  6. package/cjs/lib/utils/index.js +13 -0
  7. package/cjs/lib/utils/render-args.js +47 -0
  8. package/cjs/lib/version.js +1 -1
  9. package/cjs/middlewares/createMetadataMiddleware.js +1 -15
  10. package/cjs/widgets/hierarchical-menu/defaultTemplates.js +3 -2
  11. package/cjs/widgets/hierarchical-menu/hierarchical-menu.js +4 -0
  12. package/cjs/widgets/index/index.js +6 -84
  13. package/dist/instantsearch.development.d.ts +27 -4
  14. package/dist/instantsearch.development.js +107 -112
  15. package/dist/instantsearch.development.js.map +1 -1
  16. package/dist/instantsearch.production.d.ts +27 -4
  17. package/dist/instantsearch.production.min.d.ts +27 -4
  18. package/dist/instantsearch.production.min.js +2 -2
  19. package/dist/instantsearch.production.min.js.map +1 -1
  20. package/es/connectors/hierarchical-menu/connectHierarchicalMenu.js +4 -1
  21. package/es/connectors/search-box/connectSearchBox.d.ts +1 -0
  22. package/es/lib/InstantSearch.d.ts +17 -4
  23. package/es/lib/InstantSearch.js +45 -6
  24. package/es/lib/utils/createSendEventForFacet.d.ts +4 -3
  25. package/es/lib/utils/createSendEventForFacet.js +2 -1
  26. package/es/lib/utils/createSendEventForHits.js +1 -1
  27. package/es/lib/utils/defer.d.ts +2 -2
  28. package/es/lib/utils/index.d.ts +1 -0
  29. package/es/lib/utils/index.js +1 -0
  30. package/es/lib/utils/render-args.d.ts +34 -0
  31. package/es/lib/utils/render-args.js +38 -0
  32. package/es/lib/version.d.ts +1 -1
  33. package/es/lib/version.js +1 -1
  34. package/es/middlewares/createMetadataMiddleware.js +2 -16
  35. package/es/types/widget.d.ts +4 -0
  36. package/es/widgets/hierarchical-menu/defaultTemplates.js +3 -2
  37. package/es/widgets/hierarchical-menu/hierarchical-menu.d.ts +4 -0
  38. package/es/widgets/hierarchical-menu/hierarchical-menu.js +4 -0
  39. package/es/widgets/index/index.js +7 -85
  40. package/package.json +7 -7
@@ -1,4 +1,4 @@
1
- /*! InstantSearch.js 4.46.3 | © Algolia, Inc. and contributors; MIT License | https://github.com/algolia/instantsearch.js */
1
+ /*! InstantSearch.js 4.47.0 | © 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) :
@@ -6304,7 +6304,7 @@
6304
6304
  function createSendEventForFacet(_ref) {
6305
6305
  var instantSearchInstance = _ref.instantSearchInstance,
6306
6306
  helper = _ref.helper,
6307
- attribute = _ref.attribute,
6307
+ attr = _ref.attribute,
6308
6308
  widgetType = _ref.widgetType;
6309
6309
 
6310
6310
  var sendEventForFacet = function sendEventForFacet() {
@@ -6316,6 +6316,7 @@
6316
6316
  facetValue = args[1],
6317
6317
  _args$ = args[2],
6318
6318
  eventName = _args$ === void 0 ? 'Filter Applied' : _args$;
6319
+ var attribute = typeof attr === 'string' ? attr : attr(facetValue);
6319
6320
 
6320
6321
  if (args.length === 1 && _typeof(args[0]) === 'object') {
6321
6322
  instantSearchInstance.sendEventToInsights(args[0]);
@@ -6481,7 +6482,7 @@
6481
6482
  index: index,
6482
6483
  methodName: 'sendEvent',
6483
6484
  args: args,
6484
- isSearchStalled: instantSearchInstance._isSearchStalled
6485
+ isSearchStalled: instantSearchInstance.status === 'stalled'
6485
6486
  });
6486
6487
  payloads.forEach(function (payload) {
6487
6488
  return instantSearchInstance.sendEventToInsights(payload);
@@ -7219,6 +7220,45 @@
7219
7220
  });
7220
7221
  }
7221
7222
 
7223
+ function createInitArgs(instantSearchInstance, parent, uiState) {
7224
+ var helper = parent.getHelper();
7225
+ return {
7226
+ uiState: uiState,
7227
+ helper: helper,
7228
+ parent: parent,
7229
+ instantSearchInstance: instantSearchInstance,
7230
+ state: helper.state,
7231
+ renderState: instantSearchInstance.renderState,
7232
+ templatesConfig: instantSearchInstance.templatesConfig,
7233
+ createURL: parent.createURL,
7234
+ scopedResults: [],
7235
+ searchMetadata: {
7236
+ isSearchStalled: instantSearchInstance.status === 'stalled'
7237
+ },
7238
+ status: instantSearchInstance.status,
7239
+ error: instantSearchInstance.error
7240
+ };
7241
+ }
7242
+ function createRenderArgs(instantSearchInstance, parent) {
7243
+ var results = parent.getResults();
7244
+ return {
7245
+ helper: parent.getHelper(),
7246
+ parent: parent,
7247
+ instantSearchInstance: instantSearchInstance,
7248
+ results: results,
7249
+ scopedResults: parent.getScopedResults(),
7250
+ state: results._state,
7251
+ renderState: instantSearchInstance.renderState,
7252
+ templatesConfig: instantSearchInstance.templatesConfig,
7253
+ createURL: parent.createURL,
7254
+ searchMetadata: {
7255
+ isSearchStalled: instantSearchInstance.status === 'stalled'
7256
+ },
7257
+ status: instantSearchInstance.status,
7258
+ error: instantSearchInstance.error
7259
+ };
7260
+ }
7261
+
7222
7262
  function resolveSearchParameters(current) {
7223
7263
  var parent = current.getParent();
7224
7264
  var states = [current.getHelper().state];
@@ -7439,20 +7479,7 @@
7439
7479
 
7440
7480
  widgets.forEach(function (widget) {
7441
7481
  if (widget.getRenderState) {
7442
- var renderState = widget.getRenderState(localInstantSearchInstance.renderState[_this.getIndexId()] || {}, {
7443
- uiState: localInstantSearchInstance._initialUiState,
7444
- helper: _this.getHelper(),
7445
- parent: _this,
7446
- instantSearchInstance: localInstantSearchInstance,
7447
- state: helper.state,
7448
- renderState: localInstantSearchInstance.renderState,
7449
- templatesConfig: localInstantSearchInstance.templatesConfig,
7450
- createURL: _this.createURL,
7451
- scopedResults: [],
7452
- searchMetadata: {
7453
- isSearchStalled: localInstantSearchInstance._isSearchStalled
7454
- }
7455
- });
7482
+ var renderState = widget.getRenderState(localInstantSearchInstance.renderState[_this.getIndexId()] || {}, createInitArgs(localInstantSearchInstance, _this, localInstantSearchInstance._initialUiState));
7456
7483
  storeRenderState({
7457
7484
  renderState: renderState,
7458
7485
  instantSearchInstance: localInstantSearchInstance,
@@ -7462,20 +7489,7 @@
7462
7489
  });
7463
7490
  widgets.forEach(function (widget) {
7464
7491
  if (widget.init) {
7465
- widget.init({
7466
- helper: helper,
7467
- parent: _this,
7468
- uiState: localInstantSearchInstance._initialUiState,
7469
- instantSearchInstance: localInstantSearchInstance,
7470
- state: helper.state,
7471
- renderState: localInstantSearchInstance.renderState,
7472
- templatesConfig: localInstantSearchInstance.templatesConfig,
7473
- createURL: _this.createURL,
7474
- scopedResults: [],
7475
- searchMetadata: {
7476
- isSearchStalled: localInstantSearchInstance._isSearchStalled
7477
- }
7478
- });
7492
+ widget.init(createInitArgs(localInstantSearchInstance, _this, localInstantSearchInstance._initialUiState));
7479
7493
  }
7480
7494
  });
7481
7495
  localInstantSearchInstance.scheduleSearch();
@@ -7641,20 +7655,7 @@
7641
7655
 
7642
7656
  localWidgets.forEach(function (widget) {
7643
7657
  if (widget.getRenderState) {
7644
- var renderState = widget.getRenderState(instantSearchInstance.renderState[_this3.getIndexId()] || {}, {
7645
- uiState: uiState,
7646
- helper: helper,
7647
- parent: _this3,
7648
- instantSearchInstance: instantSearchInstance,
7649
- state: helper.state,
7650
- renderState: instantSearchInstance.renderState,
7651
- templatesConfig: instantSearchInstance.templatesConfig,
7652
- createURL: _this3.createURL,
7653
- scopedResults: [],
7654
- searchMetadata: {
7655
- isSearchStalled: instantSearchInstance._isSearchStalled
7656
- }
7657
- });
7658
+ var renderState = widget.getRenderState(instantSearchInstance.renderState[_this3.getIndexId()] || {}, createInitArgs(instantSearchInstance, _this3, uiState));
7658
7659
  storeRenderState({
7659
7660
  renderState: renderState,
7660
7661
  instantSearchInstance: instantSearchInstance,
@@ -7668,20 +7669,7 @@
7668
7669
  !widget.getWidgetState || Boolean(widget.getWidgetUiState), 'The `getWidgetState` method is renamed `getWidgetUiState` and will no longer exist under that name in InstantSearch.js 5.x. Please use `getWidgetUiState` instead.') ;
7669
7670
 
7670
7671
  if (widget.init) {
7671
- widget.init({
7672
- uiState: uiState,
7673
- helper: helper,
7674
- parent: _this3,
7675
- instantSearchInstance: instantSearchInstance,
7676
- state: helper.state,
7677
- renderState: instantSearchInstance.renderState,
7678
- templatesConfig: instantSearchInstance.templatesConfig,
7679
- createURL: _this3.createURL,
7680
- scopedResults: [],
7681
- searchMetadata: {
7682
- isSearchStalled: instantSearchInstance._isSearchStalled
7683
- }
7684
- });
7672
+ widget.init(createInitArgs(instantSearchInstance, _this3, uiState));
7685
7673
  }
7686
7674
  }); // Subscribe to the Helper state changes for the `uiState` once widgets
7687
7675
  // are initialized. Until the first render, state changes are part of the
@@ -7722,20 +7710,7 @@
7722
7710
 
7723
7711
  localWidgets.forEach(function (widget) {
7724
7712
  if (widget.getRenderState) {
7725
- var renderState = widget.getRenderState(instantSearchInstance.renderState[_this4.getIndexId()] || {}, {
7726
- helper: _this4.getHelper(),
7727
- parent: _this4,
7728
- instantSearchInstance: instantSearchInstance,
7729
- results: _this4.getResults(),
7730
- scopedResults: _this4.getScopedResults(),
7731
- state: _this4.getResults()._state,
7732
- renderState: instantSearchInstance.renderState,
7733
- templatesConfig: instantSearchInstance.templatesConfig,
7734
- createURL: _this4.createURL,
7735
- searchMetadata: {
7736
- isSearchStalled: instantSearchInstance._isSearchStalled
7737
- }
7738
- });
7713
+ var renderState = widget.getRenderState(instantSearchInstance.renderState[_this4.getIndexId()] || {}, createRenderArgs(instantSearchInstance, _this4));
7739
7714
  storeRenderState({
7740
7715
  renderState: renderState,
7741
7716
  instantSearchInstance: instantSearchInstance,
@@ -7751,20 +7726,7 @@
7751
7726
  // be delayed. The render is triggered for the complete tree but some parts do
7752
7727
  // not have results yet.
7753
7728
  if (widget.render) {
7754
- widget.render({
7755
- helper: helper,
7756
- parent: _this4,
7757
- instantSearchInstance: instantSearchInstance,
7758
- results: _this4.getResults(),
7759
- scopedResults: _this4.getScopedResults(),
7760
- state: _this4.getResults()._state,
7761
- renderState: instantSearchInstance.renderState,
7762
- templatesConfig: instantSearchInstance.templatesConfig,
7763
- createURL: _this4.createURL,
7764
- searchMetadata: {
7765
- isSearchStalled: instantSearchInstance._isSearchStalled
7766
- }
7767
- });
7729
+ widget.render(createRenderArgs(instantSearchInstance, _this4));
7768
7730
  }
7769
7731
  });
7770
7732
  },
@@ -7826,7 +7788,7 @@
7826
7788
  instantSearchInstance.renderState = _objectSpread2(_objectSpread2({}, instantSearchInstance.renderState), {}, _defineProperty({}, parentIndexName, _objectSpread2(_objectSpread2({}, instantSearchInstance.renderState[parentIndexName]), renderState)));
7827
7789
  }
7828
7790
 
7829
- var version$1 = '4.46.3';
7791
+ var version$1 = '4.47.0';
7830
7792
 
7831
7793
  var NAMESPACE = 'ais';
7832
7794
  var component = function component(componentName) {
@@ -9224,21 +9186,7 @@
9224
9186
  };
9225
9187
 
9226
9188
  function extractPayload(widgets, instantSearchInstance, payload) {
9227
- var parent = instantSearchInstance.mainIndex;
9228
- var initOptions = {
9229
- instantSearchInstance: instantSearchInstance,
9230
- parent: parent,
9231
- scopedResults: [],
9232
- state: parent.getHelper().state,
9233
- helper: parent.getHelper(),
9234
- createURL: parent.createURL,
9235
- uiState: instantSearchInstance._initialUiState,
9236
- renderState: instantSearchInstance.renderState,
9237
- templatesConfig: instantSearchInstance.templatesConfig,
9238
- searchMetadata: {
9239
- isSearchStalled: instantSearchInstance._isSearchStalled
9240
- }
9241
- };
9189
+ var initOptions = createInitArgs(instantSearchInstance, instantSearchInstance.mainIndex, instantSearchInstance._initialUiState);
9242
9190
  widgets.forEach(function (widget) {
9243
9191
  var widgetParams = {};
9244
9192
 
@@ -9368,8 +9316,6 @@
9368
9316
 
9369
9317
  _defineProperty(_assertThisInitialized(_this), "_searchStalledTimer", void 0);
9370
9318
 
9371
- _defineProperty(_assertThisInitialized(_this), "_isSearchStalled", void 0);
9372
-
9373
9319
  _defineProperty(_assertThisInitialized(_this), "_initialUiState", void 0);
9374
9320
 
9375
9321
  _defineProperty(_assertThisInitialized(_this), "_initialResults", void 0);
@@ -9384,6 +9330,10 @@
9384
9330
 
9385
9331
  _defineProperty(_assertThisInitialized(_this), "sendEventToInsights", void 0);
9386
9332
 
9333
+ _defineProperty(_assertThisInitialized(_this), "status", 'idle');
9334
+
9335
+ _defineProperty(_assertThisInitialized(_this), "error", undefined);
9336
+
9387
9337
  _defineProperty(_assertThisInitialized(_this), "scheduleSearch", defer(function () {
9388
9338
  if (_this.started) {
9389
9339
  _this.mainHelper.search();
@@ -9391,10 +9341,16 @@
9391
9341
  }));
9392
9342
 
9393
9343
  _defineProperty(_assertThisInitialized(_this), "scheduleRender", defer(function () {
9344
+ var shouldResetStatus = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
9345
+
9394
9346
  if (!_this.mainHelper.hasPendingRequests()) {
9395
9347
  clearTimeout(_this._searchStalledTimer);
9396
9348
  _this._searchStalledTimer = null;
9397
- _this._isSearchStalled = false;
9349
+
9350
+ if (shouldResetStatus) {
9351
+ _this.status = 'idle';
9352
+ _this.error = undefined;
9353
+ }
9398
9354
  }
9399
9355
 
9400
9356
  _this.mainIndex.render({
@@ -9475,7 +9431,6 @@
9475
9431
  };
9476
9432
  _this._stalledSearchDelay = stalledSearchDelay;
9477
9433
  _this._searchStalledTimer = null;
9478
- _this._isSearchStalled = false;
9479
9434
  _this._createURL = defaultCreateURL;
9480
9435
  _this._initialUiState = initialUiState;
9481
9436
  _this._initialResults = null;
@@ -9504,6 +9459,25 @@
9504
9459
 
9505
9460
 
9506
9461
  _createClass(InstantSearch, [{
9462
+ key: "_isSearchStalled",
9463
+ get:
9464
+ /**
9465
+ * The status of the search. Can be "idle", "loading", "stalled", or "error".
9466
+ */
9467
+
9468
+ /**
9469
+ * The last returned error from the Search API.
9470
+ * The error gets cleared when the next valid search response is rendered.
9471
+ */
9472
+
9473
+ /**
9474
+ * @deprecated use `status === 'stalled'` instead
9475
+ */
9476
+ function get() {
9477
+ _warning(false, "`InstantSearch._isSearchStalled` is deprecated and will be removed in InstantSearch.js 5.0.\n\nUse `InstantSearch.status === \"stalled\"` instead.") ;
9478
+ return this.status === 'stalled';
9479
+ }
9480
+ }, {
9507
9481
  key: "use",
9508
9482
  value: function use() {
9509
9483
  var _this2 = this;
@@ -9665,10 +9639,18 @@
9665
9639
  var mainHelper = this.mainHelper || algoliasearchHelper_1(this.client, this.indexName);
9666
9640
 
9667
9641
  mainHelper.search = function () {
9668
- // This solution allows us to keep the exact same API for the users but
9642
+ _this3.status = 'loading'; // @MAJOR: use scheduleRender here
9643
+ // For now, widgets don't expect to be rendered at the start of `loading`,
9644
+ // so it would be a breaking change to add an extra render. We don't have
9645
+ // these guarantees about the render event, thus emitting it once more
9646
+ // isn't a breaking change.
9647
+
9648
+ _this3.emit('render'); // This solution allows us to keep the exact same API for the users but
9669
9649
  // under the hood, we have a different implementation. It should be
9670
9650
  // completely transparent for the rest of the codebase. Only this module
9671
9651
  // is impacted.
9652
+
9653
+
9672
9654
  return mainHelper.searchOnlyWithDerivedHelpers();
9673
9655
  };
9674
9656
 
@@ -9725,6 +9707,11 @@
9725
9707
 
9726
9708
 
9727
9709
  error.error = error;
9710
+ _this3.error = error;
9711
+ _this3.status = 'error';
9712
+
9713
+ _this3.scheduleRender(false); // This needs to execute last because it throws the error.
9714
+
9728
9715
 
9729
9716
  _this3.emit('error', error);
9730
9717
  });
@@ -9813,7 +9800,7 @@
9813
9800
 
9814
9801
  if (!this._searchStalledTimer) {
9815
9802
  this._searchStalledTimer = setTimeout(function () {
9816
- _this4._isSearchStalled = true;
9803
+ _this4.status = 'stalled';
9817
9804
 
9818
9805
  _this4.scheduleRender();
9819
9806
  }, this._stalledSearchDelay);
@@ -10384,7 +10371,10 @@
10384
10371
  sendEvent = createSendEventForFacet({
10385
10372
  instantSearchInstance: instantSearchInstance,
10386
10373
  helper: helper,
10387
- attribute: hierarchicalFacetName,
10374
+ attribute: function attribute(facetValue) {
10375
+ var index = facetValue.split(separator).length - 1;
10376
+ return attributes[index];
10377
+ },
10388
10378
  widgetType: this.$$type
10389
10379
  });
10390
10380
  }
@@ -17970,9 +17960,10 @@
17970
17960
  var url = _ref.url,
17971
17961
  label = _ref.label,
17972
17962
  count = _ref.count,
17973
- cssClasses = _ref.cssClasses;
17963
+ cssClasses = _ref.cssClasses,
17964
+ isRefined = _ref.isRefined;
17974
17965
  return h("a", {
17975
- className: cx(cssClasses.link),
17966
+ className: cx([cx(cssClasses.link), cx(isRefined ? cssClasses.selectedItemLink : undefined)]),
17976
17967
  href: url
17977
17968
  }, h("span", {
17978
17969
  className: cx(cssClasses.label)
@@ -18130,6 +18121,10 @@
18130
18121
  link: classnames(suit$a({
18131
18122
  descendantName: 'link'
18132
18123
  }), userCssClasses.link),
18124
+ selectedItemLink: classnames(suit$a({
18125
+ descendantName: 'link',
18126
+ modifierName: 'selected'
18127
+ }), userCssClasses.selectedItemLink),
18133
18128
  label: classnames(suit$a({
18134
18129
  descendantName: 'label'
18135
18130
  }), userCssClasses.label),