instantsearch.js 4.72.2 → 4.73.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.
@@ -3,9 +3,9 @@ import { h } from 'preact';
3
3
  import type { SendEventForHits, BindEventForHits } from '../../lib/utils';
4
4
  import type { ComponentCSSClasses, Hit, InsightsClient } from '../../types';
5
5
  import type { InfiniteHitsCSSClasses, InfiniteHitsTemplates } from '../../widgets/infinite-hits/infinite-hits';
6
- import type { SearchResults } from 'algoliasearch-helper';
6
+ import type { Banner, SearchResults } from 'algoliasearch-helper';
7
7
  export type InfiniteHitsComponentCSSClasses = ComponentCSSClasses<InfiniteHitsCSSClasses>;
8
- export type InfiniteHitsComponentTemplates = Required<InfiniteHitsTemplates>;
8
+ export type InfiniteHitsComponentTemplates = InfiniteHitsTemplates;
9
9
  export type InfiniteHitsProps = {
10
10
  cssClasses: InfiniteHitsComponentCSSClasses;
11
11
  hits: Hit[];
@@ -22,6 +22,7 @@ export type InfiniteHitsProps = {
22
22
  insights?: InsightsClient;
23
23
  sendEvent: SendEventForHits;
24
24
  bindEvent: BindEventForHits;
25
+ banner?: Banner;
25
26
  };
26
- declare const InfiniteHits: ({ results, hits, insights, bindEvent, sendEvent, hasShowPrevious, showPrevious, showMore, isFirstPage, isLastPage, cssClasses, templateProps, }: InfiniteHitsProps) => h.JSX.Element;
27
+ declare const InfiniteHits: ({ results, hits, insights, bindEvent, sendEvent, hasShowPrevious, showPrevious, showMore, isFirstPage, isLastPage, cssClasses, templateProps, banner, }: InfiniteHitsProps) => h.JSX.Element;
27
28
  export default InfiniteHits;
@@ -10,32 +10,65 @@ import { h } from 'preact';
10
10
  import { createInsightsEventHandler } from "../../lib/insights/listener.js";
11
11
  import { warning } from "../../lib/utils/index.js";
12
12
  import Template from "../Template/Template.js";
13
- var InfiniteHits = function InfiniteHits(_ref) {
14
- var results = _ref.results,
15
- hits = _ref.hits,
16
- insights = _ref.insights,
17
- bindEvent = _ref.bindEvent,
18
- sendEvent = _ref.sendEvent,
19
- hasShowPrevious = _ref.hasShowPrevious,
20
- showPrevious = _ref.showPrevious,
21
- showMore = _ref.showMore,
22
- isFirstPage = _ref.isFirstPage,
23
- isLastPage = _ref.isLastPage,
24
- cssClasses = _ref.cssClasses,
25
- templateProps = _ref.templateProps;
13
+ var DefaultBanner = function DefaultBanner(_ref) {
14
+ var banner = _ref.banner,
15
+ classNames = _ref.classNames;
16
+ if (!banner.image.urls[0].url) {
17
+ return null;
18
+ }
19
+ return h("aside", {
20
+ className: cx(classNames.bannerRoot)
21
+ }, banner.link ? h("a", {
22
+ className: cx(classNames.bannerLink),
23
+ href: banner.link.url,
24
+ target: banner.link.target
25
+ }, h("img", {
26
+ className: cx(classNames.bannerImage),
27
+ src: banner.image.urls[0].url,
28
+ alt: banner.image.title
29
+ })) : h("img", {
30
+ className: cx(classNames.bannerImage),
31
+ src: banner.image.urls[0].url,
32
+ alt: banner.image.title
33
+ }));
34
+ };
35
+ var InfiniteHits = function InfiniteHits(_ref2) {
36
+ var results = _ref2.results,
37
+ hits = _ref2.hits,
38
+ insights = _ref2.insights,
39
+ bindEvent = _ref2.bindEvent,
40
+ sendEvent = _ref2.sendEvent,
41
+ hasShowPrevious = _ref2.hasShowPrevious,
42
+ showPrevious = _ref2.showPrevious,
43
+ showMore = _ref2.showMore,
44
+ isFirstPage = _ref2.isFirstPage,
45
+ isLastPage = _ref2.isLastPage,
46
+ cssClasses = _ref2.cssClasses,
47
+ templateProps = _ref2.templateProps,
48
+ banner = _ref2.banner;
26
49
  var handleInsightsClick = createInsightsEventHandler({
27
50
  insights: insights,
28
51
  sendEvent: sendEvent
29
52
  });
30
53
  if (results.hits.length === 0) {
31
- return h(Template, _extends({}, templateProps, {
54
+ return h("div", {
55
+ className: cx(cssClasses.root, cssClasses.emptyRoot),
56
+ onClick: handleInsightsClick
57
+ }, banner && (templateProps.templates.banner ? h(Template, _extends({}, templateProps, {
58
+ templateKey: "banner",
59
+ rootTagName: "fragment",
60
+ data: {
61
+ banner: banner,
62
+ className: cssClasses.bannerRoot
63
+ }
64
+ })) : h(DefaultBanner, {
65
+ banner: banner,
66
+ classNames: cssClasses
67
+ })), h(Template, _extends({}, templateProps, {
32
68
  templateKey: "empty",
33
- rootProps: {
34
- className: cx(cssClasses.root, cssClasses.emptyRoot),
35
- onClick: handleInsightsClick
36
- },
69
+ rootTagName: "fragment",
37
70
  data: results
38
- }));
71
+ })));
39
72
  }
40
73
  return h("div", {
41
74
  className: cssClasses.root
@@ -47,6 +80,16 @@ var InfiniteHits = function InfiniteHits(_ref) {
47
80
  disabled: isFirstPage,
48
81
  onClick: showPrevious
49
82
  }
83
+ })), banner && (templateProps.templates.banner ? h(Template, _extends({}, templateProps, {
84
+ templateKey: "banner",
85
+ rootTagName: "fragment",
86
+ data: {
87
+ banner: banner,
88
+ className: cssClasses.bannerRoot
89
+ }
90
+ })) : h(DefaultBanner, {
91
+ banner: banner,
92
+ classNames: cssClasses
50
93
  })), h("ol", {
51
94
  className: cssClasses.list
52
95
  }, hits.map(function (hit, index) {
@@ -129,7 +129,7 @@ var Template = /*#__PURE__*/function (_Component2) {
129
129
  if (RootTagName === Fragment) {
130
130
  return h(RawHtml, {
131
131
  content: content,
132
- key: content
132
+ key: Math.random()
133
133
  });
134
134
  }
135
135
  return h(RootTagName, _extends({}, this.props.rootProps, {
@@ -57,12 +57,12 @@ var Paginator = /*#__PURE__*/function () {
57
57
  }, {
58
58
  key: "isLastPage",
59
59
  value: function isLastPage() {
60
- return this.currentPage === this.total - 1 || this.total === 0;
60
+ return this.currentPage >= this.total - 1;
61
61
  }
62
62
  }, {
63
63
  key: "isFirstPage",
64
64
  value: function isFirstPage() {
65
- return this.currentPage === 0;
65
+ return this.currentPage <= 0;
66
66
  }
67
67
  }]);
68
68
  return Paginator;
@@ -1,2 +1,2 @@
1
- declare const _default: "4.72.2";
1
+ declare const _default: "4.73.0";
2
2
  export default _default;
package/es/lib/version.js CHANGED
@@ -1 +1 @@
1
- export default '4.72.2';
1
+ export default '4.73.0';
@@ -35,6 +35,18 @@ export type InfiniteHitsCSSClasses = Partial<{
35
35
  * The disabled “Show more” button.
36
36
  */
37
37
  disabledLoadMore: string | string[];
38
+ /**
39
+ * Class names to apply to the banner element
40
+ */
41
+ bannerRoot: string | string[];
42
+ /**
43
+ * Class names to apply to the banner image element
44
+ */
45
+ bannerImage: string | string[];
46
+ /**
47
+ * Class names to apply to the banner link element
48
+ */
49
+ bannerLink: string | string[];
38
50
  }>;
39
51
  export type InfiniteHitsTemplates<THit extends NonNullable<object> = BaseHit> = Partial<{
40
52
  /**
@@ -56,6 +68,13 @@ export type InfiniteHitsTemplates<THit extends NonNullable<object> = BaseHit> =
56
68
  /** @deprecated the index in the hits array, use __position instead, which is the absolute position */
57
69
  __hitIndex: number;
58
70
  }>;
71
+ /**
72
+ * Template to use for the banner.
73
+ */
74
+ banner: Template<{
75
+ banner: Required<InfiniteHitsRenderState['banner']>;
76
+ className: string;
77
+ }>;
59
78
  }>;
60
79
  export type InfiniteHitsWidgetParams<THit extends NonNullable<object> = BaseHit> = {
61
80
  /**
@@ -33,7 +33,8 @@ var renderer = function renderer(_ref) {
33
33
  instantSearchInstance = _ref2.instantSearchInstance,
34
34
  insights = _ref2.insights,
35
35
  bindEvent = _ref2.bindEvent,
36
- sendEvent = _ref2.sendEvent;
36
+ sendEvent = _ref2.sendEvent,
37
+ banner = _ref2.banner;
37
38
  if (isFirstRendering) {
38
39
  renderState.templateProps = prepareTemplateProps({
39
40
  defaultTemplates: defaultTemplates,
@@ -54,7 +55,8 @@ var renderer = function renderer(_ref) {
54
55
  isLastPage: isLastPage,
55
56
  insights: insights,
56
57
  sendEvent: sendEvent,
57
- bindEvent: bindEvent
58
+ bindEvent: bindEvent,
59
+ banner: banner
58
60
  }), containerNode);
59
61
  };
60
62
  };
@@ -97,7 +99,16 @@ export default (function infiniteHits(widgetParams) {
97
99
  disabledLoadMore: cx(suit({
98
100
  descendantName: 'loadMore',
99
101
  modifierName: 'disabled'
100
- }), userCssClasses.disabledLoadMore)
102
+ }), userCssClasses.disabledLoadMore),
103
+ bannerRoot: cx(suit({
104
+ descendantName: 'banner'
105
+ }), userCssClasses.bannerRoot),
106
+ bannerImage: cx(suit({
107
+ descendantName: 'banner-image'
108
+ }), userCssClasses.bannerImage),
109
+ bannerLink: cx(suit({
110
+ descendantName: 'banner-link'
111
+ }), userCssClasses.bannerLink)
101
112
  };
102
113
  var specializedRenderer = renderer({
103
114
  containerNode: containerNode,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "instantsearch.js",
3
- "version": "4.72.2",
3
+ "version": "4.73.0",
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,7 +31,7 @@
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.22.1",
34
+ "algoliasearch-helper": "3.22.2",
35
35
  "hogan.js": "^3.0.2",
36
36
  "htm": "^3.0.0",
37
37
  "instantsearch-ui-components": "0.7.0",
@@ -56,9 +56,9 @@
56
56
  "watch:es": "yarn --silent build:es:base --watch"
57
57
  },
58
58
  "devDependencies": {
59
- "@instantsearch/mocks": "1.49.0",
60
- "@instantsearch/tests": "1.49.0",
61
- "@instantsearch/testutils": "1.38.0",
59
+ "@instantsearch/mocks": "1.50.0",
60
+ "@instantsearch/tests": "1.50.0",
61
+ "@instantsearch/testutils": "1.39.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": "4b7875af7a48a1f193b81793e473b7463cb7330c"
69
+ "gitHead": "e7cf000edf9869be9d2e3df9b3e1c8fdb25a0040"
70
70
  }