instantsearch.js 4.53.0 → 4.54.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.
Files changed (53) hide show
  1. package/cjs/components/Pagination/Pagination.js +35 -17
  2. package/cjs/components/Template/Template.js +6 -3
  3. package/cjs/connectors/hierarchical-menu/connectHierarchicalMenu.js +4 -0
  4. package/cjs/connectors/menu/connectMenu.js +4 -0
  5. package/cjs/connectors/refinement-list/connectRefinementList.js +8 -0
  6. package/cjs/connectors/toggle-refinement/connectToggleRefinement.js +4 -0
  7. package/cjs/helpers/highlight.js +5 -0
  8. package/cjs/helpers/reverseHighlight.js +5 -0
  9. package/cjs/helpers/reverseSnippet.js +5 -0
  10. package/cjs/helpers/snippet.js +5 -0
  11. package/cjs/lib/server.js +60 -0
  12. package/cjs/lib/utils/index.js +11 -0
  13. package/cjs/lib/utils/walkIndex.js +18 -0
  14. package/cjs/lib/version.js +1 -1
  15. package/cjs/widgets/pagination/pagination.js +51 -39
  16. package/cjs/widgets/panel/panel.js +0 -2
  17. package/cjs/widgets/places/places.js +1 -0
  18. package/dist/instantsearch.development.d.ts +27 -4
  19. package/dist/instantsearch.development.js +133 -63
  20. package/dist/instantsearch.development.js.map +1 -1
  21. package/dist/instantsearch.production.d.ts +27 -4
  22. package/dist/instantsearch.production.min.d.ts +27 -4
  23. package/dist/instantsearch.production.min.js +2 -2
  24. package/dist/instantsearch.production.min.js.map +1 -1
  25. package/es/components/Pagination/Pagination.js +34 -17
  26. package/es/components/Panel/Panel.d.ts +1 -1
  27. package/es/components/Template/Template.js +6 -3
  28. package/es/connectors/hierarchical-menu/connectHierarchicalMenu.js +4 -0
  29. package/es/connectors/menu/connectMenu.js +5 -1
  30. package/es/connectors/refinement-list/connectRefinementList.js +9 -1
  31. package/es/connectors/toggle-refinement/connectToggleRefinement.js +5 -1
  32. package/es/helpers/highlight.d.ts +3 -0
  33. package/es/helpers/highlight.js +5 -0
  34. package/es/helpers/reverseHighlight.d.ts +3 -0
  35. package/es/helpers/reverseHighlight.js +5 -0
  36. package/es/helpers/reverseSnippet.d.ts +3 -0
  37. package/es/helpers/reverseSnippet.js +5 -0
  38. package/es/helpers/snippet.d.ts +3 -0
  39. package/es/helpers/snippet.js +5 -0
  40. package/es/lib/server.d.ts +10 -0
  41. package/es/lib/server.js +53 -0
  42. package/es/lib/utils/index.d.ts +1 -0
  43. package/es/lib/utils/index.js +1 -0
  44. package/es/lib/utils/walkIndex.d.ts +5 -0
  45. package/es/lib/utils/walkIndex.js +12 -0
  46. package/es/lib/version.d.ts +1 -1
  47. package/es/lib/version.js +1 -1
  48. package/es/widgets/pagination/pagination.d.ts +12 -5
  49. package/es/widgets/pagination/pagination.js +51 -39
  50. package/es/widgets/panel/panel.js +0 -2
  51. package/es/widgets/places/places.d.ts +1 -1
  52. package/es/widgets/places/places.js +1 -0
  53. package/package.json +5 -5
@@ -1,6 +1,7 @@
1
1
  import { cx } from '@algolia/ui-components-shared';
2
2
  import { h } from 'preact';
3
3
  import { isSpecialClick } from "../../lib/utils/index.js";
4
+ import Template from "../Template/Template.js";
4
5
  function Pagination(props) {
5
6
  function createClickHandler(pageNumber) {
6
7
  return function (event) {
@@ -21,7 +22,8 @@ function Pagination(props) {
21
22
  ariaLabel: "First",
22
23
  className: props.cssClasses.firstPageItem,
23
24
  isDisabled: props.isFirstPage,
24
- label: props.templates.first,
25
+ templates: props.templates,
26
+ templateKey: "first",
25
27
  pageNumber: 0,
26
28
  createURL: props.createURL,
27
29
  cssClasses: props.cssClasses,
@@ -30,7 +32,8 @@ function Pagination(props) {
30
32
  ariaLabel: "Previous",
31
33
  className: props.cssClasses.previousPageItem,
32
34
  isDisabled: props.isFirstPage,
33
- label: props.templates.previous,
35
+ templates: props.templates,
36
+ templateKey: "previous",
34
37
  pageNumber: props.currentPage - 1,
35
38
  createURL: props.createURL,
36
39
  cssClasses: props.cssClasses,
@@ -41,7 +44,8 @@ function Pagination(props) {
41
44
  ariaLabel: "Page ".concat(pageNumber + 1),
42
45
  className: props.cssClasses.pageItem,
43
46
  isSelected: pageNumber === props.currentPage,
44
- label: "".concat(pageNumber + 1),
47
+ templates: props.templates,
48
+ templateKey: "page",
45
49
  pageNumber: pageNumber,
46
50
  createURL: props.createURL,
47
51
  cssClasses: props.cssClasses,
@@ -51,7 +55,8 @@ function Pagination(props) {
51
55
  ariaLabel: "Next",
52
56
  className: props.cssClasses.nextPageItem,
53
57
  isDisabled: props.isLastPage,
54
- label: props.templates.next,
58
+ templates: props.templates,
59
+ templateKey: "next",
55
60
  pageNumber: props.currentPage + 1,
56
61
  createURL: props.createURL,
57
62
  cssClasses: props.cssClasses,
@@ -60,7 +65,8 @@ function Pagination(props) {
60
65
  ariaLabel: "Last",
61
66
  className: props.cssClasses.lastPageItem,
62
67
  isDisabled: props.isLastPage,
63
- label: props.templates.last,
68
+ templates: props.templates,
69
+ templateKey: "last",
64
70
  pageNumber: props.nbPages - 1,
65
71
  createURL: props.createURL,
66
72
  cssClasses: props.cssClasses,
@@ -68,7 +74,8 @@ function Pagination(props) {
68
74
  })));
69
75
  }
70
76
  function PaginationLink(_ref) {
71
- var label = _ref.label,
77
+ var templates = _ref.templates,
78
+ templateKey = _ref.templateKey,
72
79
  ariaLabel = _ref.ariaLabel,
73
80
  pageNumber = _ref.pageNumber,
74
81
  className = _ref.className,
@@ -81,18 +88,28 @@ function PaginationLink(_ref) {
81
88
  createClickHandler = _ref.createClickHandler;
82
89
  return h("li", {
83
90
  className: cx(cssClasses.item, className, isDisabled && cssClasses.disabledItem, isSelected && cssClasses.selectedItem)
84
- }, isDisabled ? h("span", {
85
- className: cssClasses.link,
86
- dangerouslySetInnerHTML: {
87
- __html: label
91
+ }, isDisabled ? h(Template, {
92
+ rootTagName: "span",
93
+ rootProps: {
94
+ className: cssClasses.link
95
+ },
96
+ templateKey: templateKey,
97
+ templates: templates,
98
+ data: {
99
+ page: pageNumber + 1
88
100
  }
89
- }) : h("a", {
90
- className: cssClasses.link,
91
- "aria-label": ariaLabel,
92
- href: createURL(pageNumber),
93
- onClick: createClickHandler(pageNumber),
94
- dangerouslySetInnerHTML: {
95
- __html: label
101
+ }) : h(Template, {
102
+ rootTagName: "a",
103
+ rootProps: {
104
+ className: cssClasses.link,
105
+ 'aria-label': ariaLabel,
106
+ href: createURL(pageNumber),
107
+ onClick: createClickHandler(pageNumber)
108
+ },
109
+ templateKey: templateKey,
110
+ templates: templates,
111
+ data: {
112
+ page: pageNumber + 1
96
113
  }
97
114
  }));
98
115
  }
@@ -3,7 +3,7 @@ import { h } from 'preact';
3
3
  import type { ComponentCSSClasses, UnknownWidgetFactory } from '../../types';
4
4
  import type { PanelCSSClasses, PanelSharedOptions, PanelTemplates } from '../../widgets/panel/panel';
5
5
  export type PanelComponentCSSClasses = ComponentCSSClasses<Omit<PanelCSSClasses, 'collapseIcon'>>;
6
- export type PanelComponentTemplates<TWidget extends UnknownWidgetFactory> = Required<PanelTemplates<TWidget>>;
6
+ export type PanelComponentTemplates<TWidget extends UnknownWidgetFactory> = PanelTemplates<TWidget>;
7
7
  export type PanelProps<TWidget extends UnknownWidgetFactory> = {
8
8
  hidden: boolean;
9
9
  collapsible: boolean;
@@ -40,9 +40,12 @@ var Template = /*#__PURE__*/function (_Component) {
40
40
  key: "render",
41
41
  value: function render() {
42
42
  var _this = this;
43
- process.env.NODE_ENV === 'development' ? warning(Object.keys(this.props.templates).every(function (key) {
44
- return typeof _this.props.templates[key] === 'function';
45
- }), "Hogan.js and string-based templates are deprecated and will not be supported in InstantSearch.js 5.x.\n\nYou can replace them with function-form templates and use either the provided `html` function or JSX templates.\n\nSee: https://www.algolia.com/doc/guides/building-search-ui/upgrade-guides/js/#upgrade-templates") : void 0;
43
+ if (process.env.NODE_ENV === 'development') {
44
+ var nonFunctionTemplates = Object.keys(this.props.templates).filter(function (key) {
45
+ return typeof _this.props.templates[key] !== 'function';
46
+ });
47
+ process.env.NODE_ENV === 'development' ? warning(nonFunctionTemplates.length === 0, "Hogan.js and string-based templates are deprecated and will not be supported in InstantSearch.js 5.x.\n\nYou can replace them with function-form templates and use either the provided `html` function or JSX templates.\n\nString-based templates: ".concat(nonFunctionTemplates.join(', '), ".\n\nSee: https://www.algolia.com/doc/guides/building-search-ui/upgrade-guides/js/#upgrade-templates")) : void 0;
48
+ }
46
49
  var RootTagName = this.props.rootTagName;
47
50
  var useCustomCompileOptions = this.props.useCustomCompileOptions[this.props.templateKey];
48
51
  var compileOptions = useCustomCompileOptions ? this.props.templatesConfig.compileOptions : {};
@@ -203,6 +203,10 @@ var connectHierarchicalMenu = function connectHierarchicalMenu(renderFn) {
203
203
  getWidgetSearchParameters: function getWidgetSearchParameters(searchParameters, _ref6) {
204
204
  var uiState = _ref6.uiState;
205
205
  var values = uiState.hierarchicalMenu && uiState.hierarchicalMenu[hierarchicalFacetName];
206
+ if (searchParameters.isConjunctiveFacet(hierarchicalFacetName) || searchParameters.isDisjunctiveFacet(hierarchicalFacetName)) {
207
+ process.env.NODE_ENV === 'development' ? warning(false, "HierarchicalMenu: Attribute \"".concat(hierarchicalFacetName, "\" is already used by another widget applying conjunctive or disjunctive faceting.\nAs this is not supported, please make sure to remove this other widget or this HierarchicalMenu widget will not work at all.")) : void 0;
208
+ return searchParameters;
209
+ }
206
210
  if (searchParameters.isHierarchicalFacet(hierarchicalFacetName)) {
207
211
  var facet = searchParameters.getHierarchicalFacetByName(hierarchicalFacetName);
208
212
  process.env.NODE_ENV === 'development' ? warning(isEqual(facet.attributes, attributes) && facet.separator === separator && facet.rootPath === rootPath, 'Using Breadcrumb and HierarchicalMenu on the same facet with different options overrides the configuration of the HierarchicalMenu.') : void 0;
@@ -13,7 +13,7 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
13
13
  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; }
14
14
  function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
15
15
  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); }
16
- import { checkRendering, createDocumentationMessageGenerator, createSendEventForFacet, noop } from "../../lib/utils/index.js";
16
+ import { checkRendering, createDocumentationMessageGenerator, createSendEventForFacet, noop, warning } from "../../lib/utils/index.js";
17
17
  var withUsage = createDocumentationMessageGenerator({
18
18
  name: 'menu',
19
19
  connector: true
@@ -175,6 +175,10 @@ var connectMenu = function connectMenu(renderFn) {
175
175
  getWidgetSearchParameters: function getWidgetSearchParameters(searchParameters, _ref5) {
176
176
  var uiState = _ref5.uiState;
177
177
  var value = uiState.menu && uiState.menu[attribute];
178
+ if (searchParameters.isConjunctiveFacet(attribute) || searchParameters.isDisjunctiveFacet(attribute)) {
179
+ process.env.NODE_ENV === 'development' ? warning(false, "Menu: Attribute \"".concat(attribute, "\" is already used by another widget applying conjunctive or disjunctive faceting.\nAs this is not supported, please make sure to remove this other widget or this Menu widget will not work at all.")) : void 0;
180
+ return searchParameters;
181
+ }
178
182
  var withFacetConfiguration = searchParameters.removeHierarchicalFacet(attribute).addHierarchicalFacet({
179
183
  name: attribute,
180
184
  attributes: [attribute]
@@ -8,7 +8,7 @@ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _ty
8
8
  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); }
9
9
  function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
10
10
  function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
11
- import { escapeFacets, TAG_PLACEHOLDER, TAG_REPLACEMENT, checkRendering, createDocumentationMessageGenerator, createSendEventForFacet, noop } from "../../lib/utils/index.js";
11
+ import { escapeFacets, TAG_PLACEHOLDER, TAG_REPLACEMENT, checkRendering, createDocumentationMessageGenerator, createSendEventForFacet, noop, warning } from "../../lib/utils/index.js";
12
12
  var withUsage = createDocumentationMessageGenerator({
13
13
  name: 'refinement-list',
14
14
  connector: true
@@ -247,6 +247,14 @@ var connectRefinementList = function connectRefinementList(renderFn) {
247
247
  getWidgetSearchParameters: function getWidgetSearchParameters(searchParameters, _ref6) {
248
248
  var uiState = _ref6.uiState;
249
249
  var isDisjunctive = operator === 'or';
250
+ if (searchParameters.isHierarchicalFacet(attribute)) {
251
+ process.env.NODE_ENV === 'development' ? warning(false, "RefinementList: Attribute \"".concat(attribute, "\" is already used by another widget applying hierarchical faceting.\nAs this is not supported, please make sure to remove this other widget or this RefinementList widget will not work at all.")) : void 0;
252
+ return searchParameters;
253
+ }
254
+ if (isDisjunctive && searchParameters.isConjunctiveFacet(attribute) || !isDisjunctive && searchParameters.isDisjunctiveFacet(attribute)) {
255
+ process.env.NODE_ENV === 'development' ? warning(false, "RefinementList: Attribute \"".concat(attribute, "\" is used by another refinement list with a different operator.\nAs this is not supported, please make sure to only use this attribute with one of the two operators.")) : void 0;
256
+ return searchParameters;
257
+ }
250
258
  var values = uiState.refinementList && uiState.refinementList[attribute];
251
259
  var withoutRefinements = searchParameters.clearRefinements(attribute);
252
260
  var withFacetConfiguration = isDisjunctive ? withoutRefinements.addDisjunctiveFacet(attribute) : withoutRefinements.addFacet(attribute);
@@ -4,7 +4,7 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
4
4
  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; }
5
5
  function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
6
6
  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); }
7
- import { checkRendering, escapeFacetValue, createDocumentationMessageGenerator, find, noop, toArray } from "../../lib/utils/index.js";
7
+ import { checkRendering, escapeFacetValue, createDocumentationMessageGenerator, find, noop, toArray, warning } from "../../lib/utils/index.js";
8
8
  var withUsage = createDocumentationMessageGenerator({
9
9
  name: 'toggle-refinement',
10
10
  connector: true
@@ -251,6 +251,10 @@ var connectToggleRefinement = function connectToggleRefinement(renderFn) {
251
251
  },
252
252
  getWidgetSearchParameters: function getWidgetSearchParameters(searchParameters, _ref11) {
253
253
  var uiState = _ref11.uiState;
254
+ if (searchParameters.isHierarchicalFacet(attribute) || searchParameters.isConjunctiveFacet(attribute)) {
255
+ process.env.NODE_ENV === 'development' ? warning(false, "ToggleRefinement: Attribute \"".concat(attribute, "\" is already used by another widget of a different type.\nAs this is not supported, please make sure to remove this other widget or this ToggleRefinement widget will not work at all.")) : void 0;
256
+ return searchParameters;
257
+ }
254
258
  var withFacetConfiguration = searchParameters.clearRefinements(attribute).addDisjunctiveFacet(attribute);
255
259
  var isRefined = Boolean(uiState.toggle && uiState.toggle[attribute]);
256
260
  if (isRefined) {
@@ -7,4 +7,7 @@ export type HighlightOptions = {
7
7
  highlighted: string;
8
8
  }>;
9
9
  };
10
+ /**
11
+ * @deprecated use html tagged templates and the Highlight component instead
12
+ */
10
13
  export default function highlight({ attribute, highlightedTagName, hit, cssClasses, }: HighlightOptions): string;
@@ -1,6 +1,10 @@
1
1
  import { component } from "../lib/suit.js";
2
2
  import { getPropertyByPath, TAG_REPLACEMENT, warning } from "../lib/utils/index.js";
3
3
  var suit = component('Highlight');
4
+
5
+ /**
6
+ * @deprecated use html tagged templates and the Highlight component instead
7
+ */
4
8
  export default function highlight(_ref) {
5
9
  var attribute = _ref.attribute,
6
10
  _ref$highlightedTagNa = _ref.highlightedTagName,
@@ -8,6 +12,7 @@ export default function highlight(_ref) {
8
12
  hit = _ref.hit,
9
13
  _ref$cssClasses = _ref.cssClasses,
10
14
  cssClasses = _ref$cssClasses === void 0 ? {} : _ref$cssClasses;
15
+ process.env.NODE_ENV === 'development' ? warning(false, "`instantsearch.highlight` function has been deprecated. It is still supported in 4.x releases, but not further. It is replaced by the `Highlight` 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;
11
16
  var highlightAttributeResult = getPropertyByPath(hit._highlightResult, attribute);
12
17
 
13
18
  // @MAJOR fallback to attribute value if highlight is not found
@@ -7,4 +7,7 @@ export type ReverseHighlightOptions = {
7
7
  highlighted: string;
8
8
  }>;
9
9
  };
10
+ /**
11
+ * @deprecated use html tagged templates and the ReverseHighlight component instead
12
+ */
10
13
  export default function reverseHighlight({ attribute, highlightedTagName, hit, cssClasses, }: ReverseHighlightOptions): string;
@@ -1,6 +1,10 @@
1
1
  import { component } from "../lib/suit.js";
2
2
  import { TAG_REPLACEMENT, getPropertyByPath, getHighlightedParts, reverseHighlightedParts, concatHighlightedParts, warning } from "../lib/utils/index.js";
3
3
  var suit = component('ReverseHighlight');
4
+
5
+ /**
6
+ * @deprecated use html tagged templates and the ReverseHighlight component instead
7
+ */
4
8
  export default function reverseHighlight(_ref) {
5
9
  var attribute = _ref.attribute,
6
10
  _ref$highlightedTagNa = _ref.highlightedTagName,
@@ -8,6 +12,7 @@ export default function reverseHighlight(_ref) {
8
12
  hit = _ref.hit,
9
13
  _ref$cssClasses = _ref.cssClasses,
10
14
  cssClasses = _ref$cssClasses === void 0 ? {} : _ref$cssClasses;
15
+ process.env.NODE_ENV === 'development' ? warning(false, "`instantsearch.reverseHighlight` function has been deprecated. It is still supported in 4.x releases, but not further. It is replaced by the `ReverseHighlight` 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;
11
16
  var highlightAttributeResult = getPropertyByPath(hit._highlightResult, attribute);
12
17
 
13
18
  // @MAJOR fallback to attribute value if highlight is not found
@@ -7,4 +7,7 @@ export type ReverseSnippetOptions = {
7
7
  highlighted: string;
8
8
  }>;
9
9
  };
10
+ /**
11
+ * @deprecated use html tagged templates and the ReverseSnippet component instead
12
+ */
10
13
  export default function reverseSnippet({ attribute, highlightedTagName, hit, cssClasses, }: ReverseSnippetOptions): string;
@@ -1,6 +1,10 @@
1
1
  import { component } from "../lib/suit.js";
2
2
  import { TAG_REPLACEMENT, getPropertyByPath, getHighlightedParts, reverseHighlightedParts, concatHighlightedParts, warning } from "../lib/utils/index.js";
3
3
  var suit = component('ReverseSnippet');
4
+
5
+ /**
6
+ * @deprecated use html tagged templates and the ReverseSnippet component instead
7
+ */
4
8
  export default function reverseSnippet(_ref) {
5
9
  var attribute = _ref.attribute,
6
10
  _ref$highlightedTagNa = _ref.highlightedTagName,
@@ -8,6 +12,7 @@ export default function reverseSnippet(_ref) {
8
12
  hit = _ref.hit,
9
13
  _ref$cssClasses = _ref.cssClasses,
10
14
  cssClasses = _ref$cssClasses === void 0 ? {} : _ref$cssClasses;
15
+ process.env.NODE_ENV === 'development' ? warning(false, "`instantsearch.reverseSnippet` function has been deprecated. It is still supported in 4.x releases, but not further. It is replaced by the `ReverseSnippet` 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;
11
16
  var snippetAttributeResult = getPropertyByPath(hit._snippetResult, attribute);
12
17
 
13
18
  // @MAJOR fallback to attribute value if snippet is not found
@@ -7,4 +7,7 @@ export type SnippetOptions = {
7
7
  highlighted?: string;
8
8
  };
9
9
  };
10
+ /**
11
+ * @deprecated use html tagged templates and the Snippet component instead
12
+ */
10
13
  export default function snippet({ attribute, highlightedTagName, hit, cssClasses, }: SnippetOptions): string;
@@ -1,6 +1,10 @@
1
1
  import { component } from "../lib/suit.js";
2
2
  import { TAG_REPLACEMENT, getPropertyByPath, warning } from "../lib/utils/index.js";
3
3
  var suit = component('Snippet');
4
+
5
+ /**
6
+ * @deprecated use html tagged templates and the Snippet component instead
7
+ */
4
8
  export default function snippet(_ref) {
5
9
  var attribute = _ref.attribute,
6
10
  _ref$highlightedTagNa = _ref.highlightedTagName,
@@ -8,6 +12,7 @@ export default function snippet(_ref) {
8
12
  hit = _ref.hit,
9
13
  _ref$cssClasses = _ref.cssClasses,
10
14
  cssClasses = _ref$cssClasses === void 0 ? {} : _ref$cssClasses;
15
+ process.env.NODE_ENV === 'development' ? 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;
11
16
  var snippetAttributeResult = getPropertyByPath(hit._snippetResult, attribute);
12
17
 
13
18
  // @MAJOR fallback to attribute value if snippet is not found
@@ -0,0 +1,10 @@
1
+ import type { IndexWidget, InitialResults, InstantSearch } from '../types';
2
+ /**
3
+ * Waits for the results from the search instance to coordinate the next steps
4
+ * in `getServerState()`.
5
+ */
6
+ export declare function waitForResults(search: InstantSearch): Promise<void>;
7
+ /**
8
+ * Walks the InstantSearch root index to construct the initial results.
9
+ */
10
+ export declare function getInitialResults(rootIndex: IndexWidget): InitialResults;
@@ -0,0 +1,53 @@
1
+ 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); }
2
+ 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; }
3
+ 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; }
4
+ 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; }
5
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
6
+ 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); }
7
+ import { walkIndex } from "./utils/index.js";
8
+ /**
9
+ * Waits for the results from the search instance to coordinate the next steps
10
+ * in `getServerState()`.
11
+ */
12
+ export function waitForResults(search) {
13
+ var helper = search.mainHelper;
14
+ helper.searchOnlyWithDerivedHelpers();
15
+ return new Promise(function (resolve, reject) {
16
+ // All derived helpers resolve in the same tick so we're safe only relying
17
+ // on the first one.
18
+ helper.derivedHelpers[0].on('result', function () {
19
+ resolve();
20
+ });
21
+
22
+ // However, we listen to errors that can happen on any derived helper because
23
+ // any error is critical.
24
+ helper.on('error', function (error) {
25
+ reject(error);
26
+ });
27
+ search.on('error', function (error) {
28
+ reject(error);
29
+ });
30
+ helper.derivedHelpers.forEach(function (derivedHelper) {
31
+ return derivedHelper.on('error', function (error) {
32
+ reject(error);
33
+ });
34
+ });
35
+ });
36
+ }
37
+
38
+ /**
39
+ * Walks the InstantSearch root index to construct the initial results.
40
+ */
41
+ export function getInitialResults(rootIndex) {
42
+ var initialResults = {};
43
+ walkIndex(rootIndex, function (widget) {
44
+ var searchResults = widget.getResults();
45
+ initialResults[widget.getIndexId()] = {
46
+ // We convert the Helper state to a plain object to pass parsable data
47
+ // structures from server to client.
48
+ state: _objectSpread({}, searchResults._state),
49
+ results: searchResults._rawResults
50
+ };
51
+ });
52
+ return initialResults;
53
+ }
@@ -33,6 +33,7 @@ export * from './isFacetRefined';
33
33
  export * from './isFiniteNumber';
34
34
  export * from './isPlainObject';
35
35
  export * from './isSpecialClick';
36
+ export * from './walkIndex';
36
37
  export * from './logger';
37
38
  export * from './mergeSearchParameters';
38
39
  export * from './omit';
@@ -33,6 +33,7 @@ export * from "./isFacetRefined.js";
33
33
  export * from "./isFiniteNumber.js";
34
34
  export * from "./isPlainObject.js";
35
35
  export * from "./isSpecialClick.js";
36
+ export * from "./walkIndex.js";
36
37
  export * from "./logger.js";
37
38
  export * from "./mergeSearchParameters.js";
38
39
  export * from "./omit.js";
@@ -0,0 +1,5 @@
1
+ import type { IndexWidget } from '../../types';
2
+ /**
3
+ * Recurse over all child indices
4
+ */
5
+ export declare function walkIndex(indexWidget: IndexWidget, callback: (widget: IndexWidget) => void): void;
@@ -0,0 +1,12 @@
1
+ import { isIndexWidget } from "./isIndexWidget.js";
2
+ /**
3
+ * Recurse over all child indices
4
+ */
5
+ export function walkIndex(indexWidget, callback) {
6
+ callback(indexWidget);
7
+ indexWidget.getWidgets().forEach(function (widget) {
8
+ if (isIndexWidget(widget)) {
9
+ walkIndex(widget, callback);
10
+ }
11
+ });
12
+ }
@@ -1,2 +1,2 @@
1
- declare const _default: "4.53.0";
1
+ declare const _default: "4.54.1";
2
2
  export default _default;
package/es/lib/version.js CHANGED
@@ -1 +1 @@
1
- export default '4.53.0';
1
+ export default '4.54.1';
@@ -1,6 +1,6 @@
1
1
 
2
2
  import type { PaginationConnectorParams, PaginationWidgetDescription } from '../../connectors/pagination/connectPagination';
3
- import type { WidgetFactory } from '../../types';
3
+ import type { Template, WidgetFactory } from '../../types';
4
4
  export type PaginationCSSClasses = Partial<{
5
5
  /**
6
6
  * CSS classes added to the root element of the widget.
@@ -55,19 +55,26 @@ export type PaginationTemplates = Partial<{
55
55
  /**
56
56
  * Label for the Previous link.
57
57
  */
58
- previous: string;
58
+ previous: Template;
59
59
  /**
60
60
  * Label for the Next link.
61
61
  */
62
- next: string;
62
+ next: Template;
63
+ /**
64
+ * Label for the link of a certain page
65
+ * Page is one-based, so `page` will be `1` for the first page.
66
+ */
67
+ page: Template<{
68
+ page: number;
69
+ }>;
63
70
  /**
64
71
  * Label for the First link.
65
72
  */
66
- first: string;
73
+ first: Template;
67
74
  /**
68
75
  * Label for the Last link.
69
76
  */
70
- last: string;
77
+ last: Template;
71
78
  }>;
72
79
  export type PaginationWidgetParams = {
73
80
  /**
@@ -15,28 +15,40 @@ var withUsage = createDocumentationMessageGenerator({
15
15
  name: 'pagination'
16
16
  });
17
17
  var defaultTemplates = {
18
- previous: '‹',
19
- next: '',
20
- first: '«',
21
- last: '»'
18
+ previous: function previous() {
19
+ return '';
20
+ },
21
+ next: function next() {
22
+ return '›';
23
+ },
24
+ page: function page(_ref) {
25
+ var _page = _ref.page;
26
+ return "".concat(_page);
27
+ },
28
+ first: function first() {
29
+ return '«';
30
+ },
31
+ last: function last() {
32
+ return '»';
33
+ }
22
34
  };
23
- var renderer = function renderer(_ref) {
24
- var containerNode = _ref.containerNode,
25
- cssClasses = _ref.cssClasses,
26
- templates = _ref.templates,
27
- showFirst = _ref.showFirst,
28
- showLast = _ref.showLast,
29
- showPrevious = _ref.showPrevious,
30
- showNext = _ref.showNext,
31
- scrollToNode = _ref.scrollToNode;
32
- return function (_ref2, isFirstRendering) {
33
- var createURL = _ref2.createURL,
34
- currentRefinement = _ref2.currentRefinement,
35
- nbPages = _ref2.nbPages,
36
- pages = _ref2.pages,
37
- isFirstPage = _ref2.isFirstPage,
38
- isLastPage = _ref2.isLastPage,
39
- refine = _ref2.refine;
35
+ var renderer = function renderer(_ref2) {
36
+ var containerNode = _ref2.containerNode,
37
+ cssClasses = _ref2.cssClasses,
38
+ templates = _ref2.templates,
39
+ showFirst = _ref2.showFirst,
40
+ showLast = _ref2.showLast,
41
+ showPrevious = _ref2.showPrevious,
42
+ showNext = _ref2.showNext,
43
+ scrollToNode = _ref2.scrollToNode;
44
+ return function (_ref3, isFirstRendering) {
45
+ var createURL = _ref3.createURL,
46
+ currentRefinement = _ref3.currentRefinement,
47
+ nbPages = _ref3.nbPages,
48
+ pages = _ref3.pages,
49
+ isFirstPage = _ref3.isFirstPage,
50
+ isLastPage = _ref3.isLastPage,
51
+ refine = _ref3.refine;
40
52
  if (isFirstRendering) return;
41
53
  var setCurrentPage = function setCurrentPage(pageNumber) {
42
54
  refine(pageNumber);
@@ -62,24 +74,24 @@ var renderer = function renderer(_ref) {
62
74
  };
63
75
  };
64
76
  var pagination = function pagination(widgetParams) {
65
- var _ref3 = widgetParams || {},
66
- container = _ref3.container,
67
- _ref3$templates = _ref3.templates,
68
- userTemplates = _ref3$templates === void 0 ? {} : _ref3$templates,
69
- _ref3$cssClasses = _ref3.cssClasses,
70
- userCssClasses = _ref3$cssClasses === void 0 ? {} : _ref3$cssClasses,
71
- totalPages = _ref3.totalPages,
72
- padding = _ref3.padding,
73
- _ref3$showFirst = _ref3.showFirst,
74
- showFirst = _ref3$showFirst === void 0 ? true : _ref3$showFirst,
75
- _ref3$showLast = _ref3.showLast,
76
- showLast = _ref3$showLast === void 0 ? true : _ref3$showLast,
77
- _ref3$showPrevious = _ref3.showPrevious,
78
- showPrevious = _ref3$showPrevious === void 0 ? true : _ref3$showPrevious,
79
- _ref3$showNext = _ref3.showNext,
80
- showNext = _ref3$showNext === void 0 ? true : _ref3$showNext,
81
- _ref3$scrollTo = _ref3.scrollTo,
82
- userScrollTo = _ref3$scrollTo === void 0 ? 'body' : _ref3$scrollTo;
77
+ var _ref4 = widgetParams || {},
78
+ container = _ref4.container,
79
+ _ref4$templates = _ref4.templates,
80
+ userTemplates = _ref4$templates === void 0 ? {} : _ref4$templates,
81
+ _ref4$cssClasses = _ref4.cssClasses,
82
+ userCssClasses = _ref4$cssClasses === void 0 ? {} : _ref4$cssClasses,
83
+ totalPages = _ref4.totalPages,
84
+ padding = _ref4.padding,
85
+ _ref4$showFirst = _ref4.showFirst,
86
+ showFirst = _ref4$showFirst === void 0 ? true : _ref4$showFirst,
87
+ _ref4$showLast = _ref4.showLast,
88
+ showLast = _ref4$showLast === void 0 ? true : _ref4$showLast,
89
+ _ref4$showPrevious = _ref4.showPrevious,
90
+ showPrevious = _ref4$showPrevious === void 0 ? true : _ref4$showPrevious,
91
+ _ref4$showNext = _ref4.showNext,
92
+ showNext = _ref4$showNext === void 0 ? true : _ref4$showNext,
93
+ _ref4$scrollTo = _ref4.scrollTo,
94
+ userScrollTo = _ref4$scrollTo === void 0 ? 'body' : _ref4$scrollTo;
83
95
  if (!container) {
84
96
  throw new Error(withUsage('The `container` option is required.'));
85
97
  }
@@ -90,8 +90,6 @@ var panel = function panel(panelWidgetParams) {
90
90
  }
91
91
  var containerNode = getContainerNode(widgetParams.container);
92
92
  var defaultTemplates = {
93
- header: '',
94
- footer: '',
95
93
  collapseButtonText: function collapseButtonText(_ref4) {
96
94
  var isCollapsed = _ref4.collapsed;
97
95
  return "<svg\n class=\"".concat(cssClasses.collapseIcon, "\"\n style=\"width: 1em; height: 1em;\"\n viewBox=\"0 0 500 500\"\n >\n <path d=\"").concat(isCollapsed ? 'M100 250l300-150v300z' : 'M250 400l150-300H100z', "\" fill=\"currentColor\" />\n </svg>");
@@ -1,5 +1,5 @@
1
- // @ts-ignore
2
1
  import type { WidgetFactory, WidgetRenderState } from '../../types';
2
+ // @ts-ignore
3
3
  import type * as Places from 'places.js';
4
4
  type StaticOptions = Places.StaticOptions;
5
5
  type PlacesInstance = Places.PlacesInstance;
@@ -8,6 +8,7 @@ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _ty
8
8
  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); }
9
9
  function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
10
10
  function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
11
+ /* Places.js is an optional dependency, no error should be reported if the package is missing */
11
12
  /** @ts-ignore */
12
13
 
13
14
  // using the type like this requires only one ts-ignore