instantsearch.js 4.67.0 → 4.68.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.
@@ -42,7 +42,7 @@ var RawHtml = /*#__PURE__*/function (_Component) {
42
42
  var fragment = new DocumentFragment();
43
43
  var root = document.createElement('div');
44
44
  root.innerHTML = this.props.content;
45
- this.nodes = _toConsumableArray(root.children);
45
+ this.nodes = _toConsumableArray(root.childNodes);
46
46
  this.nodes.forEach(function (node) {
47
47
  return fragment.appendChild(node);
48
48
  });
@@ -52,8 +52,17 @@ var RawHtml = /*#__PURE__*/function (_Component) {
52
52
  key: "componentWillUnmount",
53
53
  value: function componentWillUnmount() {
54
54
  this.nodes.forEach(function (node) {
55
- return node.outerHTML = '';
55
+ if (node instanceof Element) {
56
+ node.outerHTML = '';
57
+ return;
58
+ }
59
+ node.nodeValue = '';
56
60
  });
61
+ // if there is one TextNode first and one TextNode last, the
62
+ // last one's nodeValue will be assigned to the first.
63
+ if (this.nodes[0].nodeValue) {
64
+ this.nodes[0].nodeValue = '';
65
+ }
57
66
  }
58
67
  }, {
59
68
  key: "render",
@@ -1,6 +1,7 @@
1
1
  import type { SendEventForHits, BindEventForHits } from '../../lib/utils';
2
2
  import type { TransformItems, Connector, Hit, WidgetRenderState, BaseHit } from '../../types';
3
3
  import type { SearchResults } from 'algoliasearch-helper';
4
+ type Banner = NonNullable<NonNullable<Required<SearchResults<Hit>['renderingContent']>>['widgets']['banners']>[number];
4
5
  export type HitsRenderState<THit extends BaseHit = BaseHit> = {
5
6
  /**
6
7
  * The matched hits from Algolia API.
@@ -10,6 +11,10 @@ export type HitsRenderState<THit extends BaseHit = BaseHit> = {
10
11
  * The response from the Algolia API.
11
12
  */
12
13
  results?: SearchResults<Hit<THit>>;
14
+ /**
15
+ * The banner to display above the hits.
16
+ */
17
+ banner?: Banner;
13
18
  /**
14
19
  * Sends an event to the Insights middleware.
15
20
  */
@@ -42,6 +42,7 @@ var connectHits = function connectHits(renderFn) {
42
42
  });
43
43
  },
44
44
  getWidgetRenderState: function getWidgetRenderState(_ref2) {
45
+ var _results$renderingCon, _results$renderingCon2, _results$renderingCon3;
45
46
  var results = _ref2.results,
46
47
  helper = _ref2.helper,
47
48
  instantSearchInstance = _ref2.instantSearchInstance;
@@ -67,6 +68,7 @@ var connectHits = function connectHits(renderFn) {
67
68
  return {
68
69
  hits: [],
69
70
  results: undefined,
71
+ banner: undefined,
70
72
  sendEvent: sendEvent,
71
73
  bindEvent: bindEvent,
72
74
  widgetParams: widgetParams
@@ -80,9 +82,11 @@ var connectHits = function connectHits(renderFn) {
80
82
  var transformedHits = transformItems(hitsWithAbsolutePositionAndQueryID, {
81
83
  results: results
82
84
  });
85
+ var banner = (_results$renderingCon = results.renderingContent) === null || _results$renderingCon === void 0 ? void 0 : (_results$renderingCon2 = _results$renderingCon.widgets) === null || _results$renderingCon2 === void 0 ? void 0 : (_results$renderingCon3 = _results$renderingCon2.banners) === null || _results$renderingCon3 === void 0 ? void 0 : _results$renderingCon3[0];
83
86
  return {
84
87
  hits: transformedHits,
85
88
  results: results,
89
+ banner: banner,
86
90
  sendEvent: sendEvent,
87
91
  bindEvent: bindEvent,
88
92
  widgetParams: widgetParams
@@ -1,2 +1,2 @@
1
- declare const _default: "4.67.0";
1
+ declare const _default: "4.68.1";
2
2
  export default _default;
package/es/lib/version.js CHANGED
@@ -1 +1 @@
1
- export default '4.67.0';
1
+ export default '4.68.1';
@@ -1,3 +1,3 @@
1
1
  import type { HitsTemplates } from './hits';
2
- declare const defaultTemplates: Required<HitsTemplates>;
2
+ declare const defaultTemplates: HitsTemplates;
3
3
  export default defaultTemplates;
@@ -1,5 +1,5 @@
1
1
 
2
- import type { HitsConnectorParams, HitsWidgetDescription } from '../../connectors/hits/connectHits';
2
+ import type { HitsConnectorParams, HitsRenderState, HitsWidgetDescription } from '../../connectors/hits/connectHits';
3
3
  import type { Template, TemplateWithBindEvent, Hit, WidgetFactory } from '../../types';
4
4
  import type { SearchResults } from 'algoliasearch-helper';
5
5
  import type { HitsClassNames as HitsUiComponentClassNames } from 'instantsearch-ui-components';
@@ -20,6 +20,13 @@ export type HitsTemplates = Partial<{
20
20
  /** @deprecated the index in the hits array, use __position instead, which is the absolute position */
21
21
  __hitIndex: number;
22
22
  }>;
23
+ /**
24
+ * Template to use for the banner.
25
+ */
26
+ banner: Template<{
27
+ banner: Required<HitsRenderState['banner']>;
28
+ className: string;
29
+ }>;
23
30
  }>;
24
31
  export type HitsWidgetParams = {
25
32
  /**
@@ -36,7 +36,8 @@ var renderer = function renderer(_ref) {
36
36
  instantSearchInstance = _ref2.instantSearchInstance,
37
37
  insights = _ref2.insights,
38
38
  bindEvent = _ref2.bindEvent,
39
- sendEvent = _ref2.sendEvent;
39
+ sendEvent = _ref2.sendEvent,
40
+ banner = _ref2.banner;
40
41
  if (isFirstRendering) {
41
42
  renderState.templateProps = prepareTemplateProps({
42
43
  defaultTemplates: defaultTemplates,
@@ -54,7 +55,8 @@ var renderer = function renderer(_ref) {
54
55
  return h(TemplateComponent, _extends({}, renderState.templateProps, {
55
56
  rootProps: rootProps,
56
57
  templateKey: "empty",
57
- data: results
58
+ data: results,
59
+ rootTagName: "fragment"
58
60
  }));
59
61
  };
60
62
 
@@ -87,12 +89,21 @@ var renderer = function renderer(_ref) {
87
89
  sendEvent: sendEvent
88
90
  }));
89
91
  };
92
+ var bannerComponent = function bannerComponent(props) {
93
+ return h(TemplateComponent, _extends({}, renderState.templateProps, {
94
+ templateKey: "banner",
95
+ data: props,
96
+ rootTagName: "fragment"
97
+ }));
98
+ };
90
99
  render(h(Hits, {
91
100
  hits: receivedHits,
92
101
  itemComponent: itemComponent,
93
102
  sendEvent: sendEvent,
94
103
  classNames: cssClasses,
95
- emptyComponent: emptyComponent
104
+ emptyComponent: emptyComponent,
105
+ banner: banner,
106
+ bannerComponent: templates.banner ? bannerComponent : undefined
96
107
  }), containerNode);
97
108
  };
98
109
  };
@@ -152,9 +152,18 @@ var index = function index(widgetParams) {
152
152
  },
153
153
  getScopedResults: function getScopedResults() {
154
154
  var widgetParent = this.getParent();
155
-
156
- // If the widget is the root, we consider itself as the only sibling.
157
- var widgetSiblings = widgetParent ? widgetParent.getWidgets() : [this];
155
+ var widgetSiblings;
156
+ if (widgetParent) {
157
+ widgetSiblings = widgetParent.getWidgets();
158
+ } else if (indexName.length === 0) {
159
+ // The widget is the root but has no index name:
160
+ // we resolve results from its children index widgets
161
+ widgetSiblings = this.getWidgets();
162
+ } else {
163
+ // The widget is the root and has an index name:
164
+ // we consider itself as the only sibling
165
+ widgetSiblings = [this];
166
+ }
158
167
  return resolveScopedResultsFromWidgets(widgetSiblings);
159
168
  },
160
169
  getParent: function getParent() {
@@ -492,7 +501,7 @@ var index = function index(widgetParams) {
492
501
  _helper,
493
502
  _derivedHelper2;
494
503
  localWidgets.forEach(function (widget) {
495
- if (widget.dispose) {
504
+ if (widget.dispose && helper) {
496
505
  // The dispose function is always called once the instance is started
497
506
  // (it's an effect of `removeWidgets`). The index is initialized and
498
507
  // the Helper is available. We don't care about the return value of
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "instantsearch.js",
3
- "version": "4.67.0",
3
+ "version": "4.68.1",
4
4
  "description": "InstantSearch.js is a JavaScript library for building performant and instant search experiences with Algolia.",
5
5
  "homepage": "https://www.algolia.com/doc/guides/building-search-ui/what-is-instantsearch/js/",
6
6
  "types": "es/index.d.ts",
@@ -31,10 +31,10 @@
31
31
  "@types/google.maps": "^3.45.3",
32
32
  "@types/hogan.js": "^3.0.0",
33
33
  "@types/qs": "^6.5.3",
34
- "algoliasearch-helper": "3.18.0",
34
+ "algoliasearch-helper": "3.19.0",
35
35
  "hogan.js": "^3.0.2",
36
36
  "htm": "^3.0.0",
37
- "instantsearch-ui-components": "0.4.0",
37
+ "instantsearch-ui-components": "0.5.0",
38
38
  "preact": "^10.10.0",
39
39
  "qs": "^6.5.1 < 6.10",
40
40
  "search-insights": "^2.13.0"
@@ -56,9 +56,9 @@
56
56
  "watch:es": "yarn --silent build:es:base --watch"
57
57
  },
58
58
  "devDependencies": {
59
- "@instantsearch/mocks": "1.41.0",
60
- "@instantsearch/tests": "1.41.0",
61
- "@instantsearch/testutils": "1.30.0",
59
+ "@instantsearch/mocks": "1.43.0",
60
+ "@instantsearch/tests": "1.43.0",
61
+ "@instantsearch/testutils": "1.32.0",
62
62
  "@storybook/html": "5.3.9",
63
63
  "@types/scriptjs": "0.0.2",
64
64
  "algoliasearch": "4.23.2",
@@ -66,5 +66,5 @@
66
66
  "scriptjs": "2.5.9",
67
67
  "webpack": "4.47.0"
68
68
  },
69
- "gitHead": "17da3c2268354325cc22103260d944d3e4feff90"
69
+ "gitHead": "500174c459e94ca09bd9368b38489c97886f603f"
70
70
  }