instantsearch.js 4.37.0 → 4.38.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 (65) hide show
  1. package/CHANGELOG.md +43 -0
  2. package/cjs/components/Hits/Hits.js +0 -6
  3. package/cjs/components/Pagination/Pagination.js +60 -41
  4. package/cjs/connectors/breadcrumb/connectBreadcrumb.js +10 -3
  5. package/cjs/connectors/clear-refinements/connectClearRefinements.js +11 -6
  6. package/cjs/connectors/current-refinements/connectCurrentRefinements.js +6 -2
  7. package/cjs/connectors/geo-search/connectGeoSearch.js +3 -1
  8. package/cjs/connectors/hierarchical-menu/connectHierarchicalMenu.js +3 -1
  9. package/cjs/connectors/hits/connectHits.js +3 -1
  10. package/cjs/connectors/hits-per-page/connectHitsPerPage.js +3 -1
  11. package/cjs/connectors/infinite-hits/connectInfiniteHits.js +3 -1
  12. package/cjs/connectors/menu/connectMenu.js +3 -1
  13. package/cjs/connectors/numeric-menu/connectNumericMenu.js +5 -3
  14. package/cjs/connectors/query-rules/connectQueryRules.js +3 -1
  15. package/cjs/connectors/refinement-list/connectRefinementList.js +8 -3
  16. package/cjs/connectors/search-box/connectSearchBox.js +15 -25
  17. package/cjs/connectors/sort-by/connectSortBy.js +3 -1
  18. package/cjs/helpers/highlight.js +4 -1
  19. package/cjs/helpers/reverseHighlight.js +4 -1
  20. package/cjs/helpers/reverseSnippet.js +4 -1
  21. package/cjs/helpers/snippet.js +4 -1
  22. package/cjs/lib/InstantSearch.js +9 -4
  23. package/cjs/lib/version.js +1 -1
  24. package/dist/instantsearch.development.d.ts +45 -14
  25. package/dist/instantsearch.development.js +160 -147
  26. package/dist/instantsearch.development.js.map +1 -1
  27. package/dist/instantsearch.production.d.ts +45 -14
  28. package/dist/instantsearch.production.min.d.ts +45 -14
  29. package/dist/instantsearch.production.min.js +2 -2
  30. package/dist/instantsearch.production.min.js.map +1 -1
  31. package/es/components/Hits/Hits.d.ts +1 -9
  32. package/es/components/Hits/Hits.js +0 -6
  33. package/es/components/Pagination/Pagination.d.ts +3 -10
  34. package/es/components/Pagination/Pagination.js +55 -34
  35. package/es/connectors/breadcrumb/connectBreadcrumb.js +10 -3
  36. package/es/connectors/clear-refinements/connectClearRefinements.js +11 -6
  37. package/es/connectors/current-refinements/connectCurrentRefinements.js +6 -2
  38. package/es/connectors/dynamic-widgets/connectDynamicWidgets.d.ts +4 -5
  39. package/es/connectors/geo-search/connectGeoSearch.js +3 -1
  40. package/es/connectors/hierarchical-menu/connectHierarchicalMenu.js +3 -1
  41. package/es/connectors/hits/connectHits.js +3 -1
  42. package/es/connectors/hits-per-page/connectHitsPerPage.js +3 -1
  43. package/es/connectors/infinite-hits/connectInfiniteHits.js +3 -1
  44. package/es/connectors/menu/connectMenu.js +3 -1
  45. package/es/connectors/numeric-menu/connectNumericMenu.js +5 -3
  46. package/es/connectors/query-rules/connectQueryRules.d.ts +1 -2
  47. package/es/connectors/query-rules/connectQueryRules.js +3 -1
  48. package/es/connectors/refinement-list/connectRefinementList.js +8 -3
  49. package/es/connectors/search-box/connectSearchBox.js +15 -25
  50. package/es/connectors/sort-by/connectSortBy.js +3 -1
  51. package/es/connectors/toggle-refinement/connectToggleRefinement.d.ts +36 -7
  52. package/es/helpers/highlight.js +5 -2
  53. package/es/helpers/reverseHighlight.js +5 -2
  54. package/es/helpers/reverseSnippet.js +5 -2
  55. package/es/helpers/snippet.js +5 -2
  56. package/es/lib/InstantSearch.js +9 -4
  57. package/es/lib/version.d.ts +1 -1
  58. package/es/lib/version.js +1 -1
  59. package/es/package.json +1 -1
  60. package/es/types/widget.d.ts +4 -1
  61. package/package.json +3 -3
  62. package/cjs/components/Pagination/PaginationLink.js +0 -60
  63. package/dist/instantsearch.development.min.d.ts +0 -5217
  64. package/es/components/Pagination/PaginationLink.d.ts +0 -16
  65. package/es/components/Pagination/PaginationLink.js +0 -49
@@ -1,4 +1,4 @@
1
- import { TAG_REPLACEMENT, getPropertyByPath, getHighlightedParts, reverseHighlightedParts, concatHighlightedParts } from "../lib/utils/index.js";
1
+ import { TAG_REPLACEMENT, getPropertyByPath, getHighlightedParts, reverseHighlightedParts, concatHighlightedParts, warning } from "../lib/utils/index.js";
2
2
  import { component } from "../lib/suit.js";
3
3
  var suit = component('ReverseHighlight');
4
4
  export default function reverseHighlight(_ref) {
@@ -8,8 +8,11 @@ export default function reverseHighlight(_ref) {
8
8
  hit = _ref.hit,
9
9
  _ref$cssClasses = _ref.cssClasses,
10
10
  cssClasses = _ref$cssClasses === void 0 ? {} : _ref$cssClasses;
11
+ var highlightAttributeResult = getPropertyByPath(hit._highlightResult, attribute); // @MAJOR fallback to attribute value if highlight is not found
11
12
 
12
- var _ref2 = getPropertyByPath(hit._highlightResult, attribute) || {},
13
+ process.env.NODE_ENV === 'development' ? warning(highlightAttributeResult, "Could not enable reverse highlight for \"".concat(attribute, "\", will display an empty string.\nPlease check whether this attribute exists and is either searchable or specified in `attributesToHighlight`.\n\nSee: https://alg.li/highlighting\n")) : void 0;
14
+
15
+ var _ref2 = highlightAttributeResult || {},
13
16
  _ref2$value = _ref2.value,
14
17
  attributeValue = _ref2$value === void 0 ? '' : _ref2$value; // cx is not used, since it would be bundled as a dependency for Vue & Angular
15
18
 
@@ -1,4 +1,4 @@
1
- import { TAG_REPLACEMENT, getPropertyByPath, getHighlightedParts, reverseHighlightedParts, concatHighlightedParts } from "../lib/utils/index.js";
1
+ import { TAG_REPLACEMENT, getPropertyByPath, getHighlightedParts, reverseHighlightedParts, concatHighlightedParts, warning } from "../lib/utils/index.js";
2
2
  import { component } from "../lib/suit.js";
3
3
  var suit = component('ReverseSnippet');
4
4
  export default function reverseSnippet(_ref) {
@@ -8,8 +8,11 @@ export default function reverseSnippet(_ref) {
8
8
  hit = _ref.hit,
9
9
  _ref$cssClasses = _ref.cssClasses,
10
10
  cssClasses = _ref$cssClasses === void 0 ? {} : _ref$cssClasses;
11
+ var snippetAttributeResult = getPropertyByPath(hit._snippetResult, attribute); // @MAJOR fallback to attribute value if snippet is not found
11
12
 
12
- var _ref2 = getPropertyByPath(hit._snippetResult, attribute) || {},
13
+ process.env.NODE_ENV === 'development' ? warning(snippetAttributeResult, "Could not enable reverse snippet for \"".concat(attribute, "\", will display an empty string.\nPlease check whether this attribute exists and is specified in `attributesToSnippet`.\n\nSee: https://alg.li/highlighting\n")) : void 0;
14
+
15
+ var _ref2 = snippetAttributeResult || {},
13
16
  _ref2$value = _ref2.value,
14
17
  attributeValue = _ref2$value === void 0 ? '' : _ref2$value; // cx is not used, since it would be bundled as a dependency for Vue & Angular
15
18
 
@@ -1,5 +1,5 @@
1
1
  import { component } from "../lib/suit.js";
2
- import { TAG_REPLACEMENT, getPropertyByPath } from "../lib/utils/index.js";
2
+ import { TAG_REPLACEMENT, getPropertyByPath, warning } from "../lib/utils/index.js";
3
3
  var suit = component('Snippet');
4
4
  export default function snippet(_ref) {
5
5
  var attribute = _ref.attribute,
@@ -8,8 +8,11 @@ export default function snippet(_ref) {
8
8
  hit = _ref.hit,
9
9
  _ref$cssClasses = _ref.cssClasses,
10
10
  cssClasses = _ref$cssClasses === void 0 ? {} : _ref$cssClasses;
11
+ var snippetAttributeResult = getPropertyByPath(hit._snippetResult, attribute); // @MAJOR fallback to attribute value if snippet is not found
11
12
 
12
- var _ref2 = getPropertyByPath(hit._snippetResult, attribute) || {},
13
+ process.env.NODE_ENV === 'development' ? warning(snippetAttributeResult, "Could not enable snippet for \"".concat(attribute, "\", will display an empty string.\nPlease check whether this attribute exists and is specified in `attributesToSnippet`.\n\nSee: https://alg.li/highlighting\n")) : void 0;
14
+
15
+ var _ref2 = snippetAttributeResult || {},
13
16
  _ref2$value = _ref2.value,
14
17
  attributeValue = _ref2$value === void 0 ? '' : _ref2$value; // cx is not used, since it would be bundled as a dependency for Vue & Angular
15
18
 
@@ -425,10 +425,15 @@ var InstantSearch = /*#__PURE__*/function (_EventEmitter) {
425
425
 
426
426
  mainHelper.on('error', function (_ref4) {
427
427
  var error = _ref4.error;
428
-
429
- _this3.emit('error', {
430
- error: error
431
- });
428
+ // If an error is emitted, it is re-thrown by events. In previous versions
429
+ // we emitted {error}, which is thrown as:
430
+ // "Uncaught, unspecified \"error\" event. ([object Object])"
431
+ // To avoid breaking changes, we make the error available in both
432
+ // `error` and `error.error`
433
+ // @MAJOR emit only error
434
+ error.error = error;
435
+
436
+ _this3.emit('error', error);
432
437
  });
433
438
  this.mainHelper = mainHelper;
434
439
  this.middleware.forEach(function (_ref5) {
@@ -1,2 +1,2 @@
1
- declare const _default: "4.37.0";
1
+ declare const _default: "4.38.0";
2
2
  export default _default;
package/es/lib/version.js CHANGED
@@ -1 +1 @@
1
- export default '4.37.0';
1
+ export default '4.38.0';
package/es/package.json CHANGED
@@ -1 +1 @@
1
- {"type":"module"}
1
+ {"type":"module","sideEffects":false}
@@ -129,10 +129,13 @@ declare type RenderStateLifeCycle<TWidgetDescription extends WidgetDescription &
129
129
  export declare type Widget<TWidgetDescription extends WidgetDescription & WidgetParams = {
130
130
  $$type: string;
131
131
  }> = Expand<RequiredWidgetLifeCycle<TWidgetDescription> & WidgetType<TWidgetDescription> & UiStateLifeCycle<TWidgetDescription> & RenderStateLifeCycle<TWidgetDescription>>;
132
+ export declare type TransformItemsMetadata = {
133
+ results?: SearchResults;
134
+ };
132
135
  /**
133
136
  * Transforms the given items.
134
137
  */
135
- export declare type TransformItems<TItem> = (items: TItem[]) => TItem[];
138
+ export declare type TransformItems<TItem, TMetadata = TransformItemsMetadata> = (items: TItem[], metadata: TMetadata) => TItem[];
136
139
  /**
137
140
  * Transforms the given items.
138
141
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "instantsearch.js",
3
- "version": "4.37.0",
3
+ "version": "4.38.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",
@@ -25,7 +25,7 @@
25
25
  "build": "yarn run build:cjs && yarn run build:es && yarn run build:umd && yarn run build:types",
26
26
  "build:umd": "rm -rf dist && BABEL_ENV=umd rollup --config scripts/rollup/config.js",
27
27
  "build:cjs": "rm -rf cjs && BABEL_ENV=cjs babel src --extensions '.js,.ts,.tsx' --out-dir cjs/ --ignore 'src/index.es.ts','**/__tests__','**/__mocks__' --quiet",
28
- "build:es": "rm -rf es && BABEL_ENV=es babel src --extensions '.js,.ts,.tsx' --out-dir es/ --ignore 'src/index.es.ts','**/__tests__','**/__mocks__' --quiet && BABEL_ENV=es babel src/index.es.ts --out-file es/index.js --quiet && echo '{\"type\":\"module\"}' > es/package.json",
28
+ "build:es": "rm -rf es && BABEL_ENV=es babel src --extensions '.js,.ts,.tsx' --out-dir es/ --ignore 'src/index.es.ts','**/__tests__','**/__mocks__' --quiet && BABEL_ENV=es babel src/index.es.ts --out-file es/index.js --quiet && echo '{\"type\":\"module\",\"sideEffects\":false}' > es/package.json",
29
29
  "build:types": "./scripts/typescript/extract.js",
30
30
  "doctoc": "doctoc --no-title --maxlevel 3 README.md CONTRIBUTING.md",
31
31
  "storybook": "start-storybook --quiet --port 6006 --ci --static-dir .storybook/static",
@@ -140,7 +140,7 @@
140
140
  "rollup-plugin-uglify": "6.0.4",
141
141
  "scriptjs": "2.5.9",
142
142
  "semver": "6.3.0",
143
- "shelljs": "0.8.3",
143
+ "shelljs": "0.8.4",
144
144
  "shipjs": "0.21.0",
145
145
  "typescript": "4.3.5",
146
146
  "webpack": "4.41.5"
@@ -1,60 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _preact = require("preact");
9
-
10
- var _classnames = _interopRequireDefault(require("classnames"));
11
-
12
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
-
14
- /** @jsx h */
15
- function PaginationLink(_ref) {
16
- var label = _ref.label,
17
- ariaLabel = _ref.ariaLabel,
18
- pageNumber = _ref.pageNumber,
19
- _ref$additionalClassN = _ref.additionalClassName,
20
- additionalClassName = _ref$additionalClassN === void 0 ? null : _ref$additionalClassN,
21
- _ref$isDisabled = _ref.isDisabled,
22
- isDisabled = _ref$isDisabled === void 0 ? false : _ref$isDisabled,
23
- _ref$isSelected = _ref.isSelected,
24
- isSelected = _ref$isSelected === void 0 ? false : _ref$isSelected,
25
- cssClasses = _ref.cssClasses,
26
- createURL = _ref.createURL,
27
- handleClick = _ref.handleClick;
28
- var classes = {
29
- item: (0, _classnames.default)(cssClasses.item, additionalClassName, isDisabled && cssClasses.disabledItem, isSelected && cssClasses.selectedItem),
30
- link: cssClasses.link
31
- };
32
-
33
- if (isDisabled) {
34
- return (0, _preact.h)("li", {
35
- className: classes.item
36
- }, (0, _preact.h)("span", {
37
- className: classes.link,
38
- dangerouslySetInnerHTML: {
39
- __html: label
40
- }
41
- }));
42
- }
43
-
44
- return (0, _preact.h)("li", {
45
- className: classes.item
46
- }, (0, _preact.h)("a", {
47
- className: classes.link,
48
- "aria-label": ariaLabel,
49
- href: createURL(pageNumber),
50
- onClick: function onClick(event) {
51
- return handleClick(pageNumber, event);
52
- },
53
- dangerouslySetInnerHTML: {
54
- __html: label
55
- }
56
- }));
57
- }
58
-
59
- var _default = PaginationLink;
60
- exports.default = _default;