instantsearch.js 4.65.0 → 4.66.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 (32) hide show
  1. package/cjs/connectors/answers/connectAnswers.js +3 -0
  2. package/cjs/connectors/hits/connectHits.js +2 -0
  3. package/cjs/connectors/infinite-hits/connectInfiniteHits.js +1 -0
  4. package/cjs/lib/version.js +1 -1
  5. package/cjs/widgets/answers/answers.js +4 -1
  6. package/cjs/widgets/hits/hits.js +66 -30
  7. package/cjs/widgets/places/places.js +3 -1
  8. package/dist/instantsearch.development.d.ts +7 -25
  9. package/dist/instantsearch.development.js +334 -253
  10. package/dist/instantsearch.development.js.map +1 -1
  11. package/dist/instantsearch.production.d.ts +7 -25
  12. package/dist/instantsearch.production.min.d.ts +7 -25
  13. package/dist/instantsearch.production.min.js +2 -2
  14. package/dist/instantsearch.production.min.js.map +1 -1
  15. package/es/connectors/answers/connectAnswers.d.ts +3 -0
  16. package/es/connectors/answers/connectAnswers.js +3 -0
  17. package/es/connectors/hits/connectHits.js +2 -0
  18. package/es/connectors/infinite-hits/connectInfiniteHits.js +1 -0
  19. package/es/connectors/refinement-list/connectRefinementList.d.ts +2 -0
  20. package/es/lib/version.d.ts +1 -1
  21. package/es/lib/version.js +1 -1
  22. package/es/widgets/answers/answers.d.ts +2 -2
  23. package/es/widgets/answers/answers.js +5 -2
  24. package/es/widgets/hits/defaultTemplates.d.ts +2 -2
  25. package/es/widgets/hits/hits.d.ts +2 -18
  26. package/es/widgets/hits/hits.js +67 -31
  27. package/es/widgets/places/places.d.ts +2 -6
  28. package/es/widgets/places/places.js +4 -1
  29. package/package.json +12 -10
  30. package/cjs/components/Hits/Hits.js +0 -72
  31. package/es/components/Hits/Hits.d.ts +0 -19
  32. package/es/components/Hits/Hits.js +0 -65
@@ -18,6 +18,9 @@ var withUsage = (0, _utils.createDocumentationMessageGenerator)({
18
18
  name: 'answers',
19
19
  connector: true
20
20
  });
21
+ /**
22
+ * @deprecated the answers service is no longer offered, and this widget will be removed in InstantSearch.js v5
23
+ */
21
24
  var connectAnswers = function connectAnswers(renderFn) {
22
25
  var unmountFn = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _utils.noop;
23
26
  (0, _utils.checkRendering)(renderFn, withUsage());
@@ -108,6 +108,8 @@ var connectHits = function connectHits(renderFn) {
108
108
  if (!escapeHTML) {
109
109
  return state;
110
110
  }
111
+
112
+ // @MAJOR: set this globally, not in the Hits widget to allow Hits to be conditionally used
111
113
  return state.setQueryParameters(_utils.TAG_PLACEHOLDER);
112
114
  }
113
115
  };
@@ -256,6 +256,7 @@ var connectInfiniteHits = function connectInfiniteHits(renderFn) {
256
256
  var uiState = _ref10.uiState;
257
257
  var widgetSearchParameters = searchParameters;
258
258
  if (escapeHTML) {
259
+ // @MAJOR: set this globally, not in the InfiniteHits widget to allow InfiniteHits to be conditionally used
259
260
  widgetSearchParameters = searchParameters.setQueryParameters(_utils.TAG_PLACEHOLDER);
260
261
  }
261
262
 
@@ -4,5 +4,5 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
- var _default = '4.65.0';
7
+ var _default = '4.66.1';
8
8
  exports.default = _default;
@@ -48,6 +48,9 @@ var renderer = function renderer(_ref) {
48
48
  }), containerNode);
49
49
  };
50
50
  };
51
+ /**
52
+ * @deprecated the answers service is no longer offered, and this widget will be removed in InstantSearch.js v5
53
+ */
51
54
  var answersWidget = function answersWidget(widgetParams) {
52
55
  var _ref3 = widgetParams || {},
53
56
  container = _ref3.container,
@@ -105,5 +108,5 @@ var answersWidget = function answersWidget(widgetParams) {
105
108
  $$widgetType: 'ais.answers'
106
109
  });
107
110
  };
108
- var _default = answersWidget;
111
+ var _default = (0, _utils.deprecate)(answersWidget, 'The answers widget is deprecated and will be removed in InstantSearch.js 5.0');
109
112
  exports.default = _default;
@@ -1,29 +1,37 @@
1
1
  "use strict";
2
2
 
3
+ 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); }
3
4
  Object.defineProperty(exports, "__esModule", {
4
5
  value: true
5
6
  });
6
7
  exports.default = void 0;
7
8
  var _instantsearchUiComponents = require("instantsearch-ui-components");
8
9
  var _preact = require("preact");
9
- var _Hits = _interopRequireDefault(require("../../components/Hits/Hits"));
10
+ var _Template = _interopRequireDefault(require("../../components/Template/Template"));
10
11
  var _connectHits = _interopRequireDefault(require("../../connectors/hits/connectHits"));
11
12
  var _insights = require("../../lib/insights");
12
- var _suit = require("../../lib/suit");
13
+ var _listener = require("../../lib/insights/listener");
13
14
  var _templating = require("../../lib/templating");
14
15
  var _utils = require("../../lib/utils");
15
16
  var _defaultTemplates = _interopRequireDefault(require("./defaultTemplates"));
17
+ var _excluded = ["hit", "index"];
16
18
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
- 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); }
18
19
  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; }
19
20
  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; }
20
21
  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; }
21
22
  function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
22
23
  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); }
24
+ 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; }
25
+ 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; }
26
+ function _objectDestructuringEmpty(obj) { if (obj == null) throw new TypeError("Cannot destructure " + obj); }
27
+ function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
23
28
  var withUsage = (0, _utils.createDocumentationMessageGenerator)({
24
29
  name: 'hits'
25
30
  });
26
- var suit = (0, _suit.component)('Hits');
31
+ var Hits = (0, _instantsearchUiComponents.createHitsComponent)({
32
+ createElement: _preact.h,
33
+ Fragment: _preact.Fragment
34
+ });
27
35
  var renderer = function renderer(_ref) {
28
36
  var renderState = _ref.renderState,
29
37
  cssClasses = _ref.cssClasses,
@@ -44,42 +52,70 @@ var renderer = function renderer(_ref) {
44
52
  });
45
53
  return;
46
54
  }
47
- (0, _preact.render)((0, _preact.h)(_Hits.default, {
48
- cssClasses: cssClasses,
49
- hits: receivedHits,
50
- results: results,
51
- templateProps: renderState.templateProps,
55
+ var handleInsightsClick = (0, _listener.createInsightsEventHandler)({
52
56
  insights: insights,
57
+ sendEvent: sendEvent
58
+ });
59
+ var emptyComponent = function emptyComponent(_ref3) {
60
+ var rootProps = _extends({}, (_objectDestructuringEmpty(_ref3), _ref3));
61
+ return (0, _preact.h)(_Template.default, _extends({}, renderState.templateProps, {
62
+ rootProps: rootProps,
63
+ templateKey: "empty",
64
+ data: results
65
+ }));
66
+ };
67
+
68
+ // @MAJOR: Move default hit component back to the UI library
69
+ // once flavour specificities are erased
70
+ var itemComponent = function itemComponent(_ref4) {
71
+ var hit = _ref4.hit,
72
+ index = _ref4.index,
73
+ rootProps = _objectWithoutProperties(_ref4, _excluded);
74
+ return (0, _preact.h)(_Template.default, _extends({}, renderState.templateProps, {
75
+ templateKey: "item",
76
+ rootTagName: "li",
77
+ rootProps: _objectSpread(_objectSpread({}, rootProps), {}, {
78
+ onClick: function onClick(event) {
79
+ handleInsightsClick(event);
80
+ rootProps.onClick();
81
+ },
82
+ onAuxClick: function onAuxClick(event) {
83
+ handleInsightsClick(event);
84
+ rootProps.onAuxClick();
85
+ }
86
+ }),
87
+ data: _objectSpread(_objectSpread({}, hit), {}, {
88
+ get __hitIndex() {
89
+ process.env.NODE_ENV === 'development' ? (0, _utils.warning)(false, 'The `__hitIndex` property is deprecated. Use the absolute `__position` instead.') : void 0;
90
+ return index;
91
+ }
92
+ }),
93
+ bindEvent: bindEvent,
94
+ sendEvent: sendEvent
95
+ }));
96
+ };
97
+ (0, _preact.render)((0, _preact.h)(Hits, {
98
+ hits: receivedHits,
99
+ itemComponent: itemComponent,
53
100
  sendEvent: sendEvent,
54
- bindEvent: bindEvent
101
+ classNames: cssClasses,
102
+ emptyComponent: emptyComponent
55
103
  }), containerNode);
56
104
  };
57
105
  };
58
106
  var hits = function hits(widgetParams) {
59
- var _ref3 = widgetParams || {},
60
- container = _ref3.container,
61
- escapeHTML = _ref3.escapeHTML,
62
- transformItems = _ref3.transformItems,
63
- _ref3$templates = _ref3.templates,
64
- templates = _ref3$templates === void 0 ? {} : _ref3$templates,
65
- _ref3$cssClasses = _ref3.cssClasses,
66
- userCssClasses = _ref3$cssClasses === void 0 ? {} : _ref3$cssClasses;
107
+ var _ref5 = widgetParams || {},
108
+ container = _ref5.container,
109
+ escapeHTML = _ref5.escapeHTML,
110
+ transformItems = _ref5.transformItems,
111
+ _ref5$templates = _ref5.templates,
112
+ templates = _ref5$templates === void 0 ? {} : _ref5$templates,
113
+ _ref5$cssClasses = _ref5.cssClasses,
114
+ cssClasses = _ref5$cssClasses === void 0 ? {} : _ref5$cssClasses;
67
115
  if (!container) {
68
116
  throw new Error(withUsage('The `container` option is required.'));
69
117
  }
70
118
  var containerNode = (0, _utils.getContainerNode)(container);
71
- var cssClasses = {
72
- root: (0, _instantsearchUiComponents.cx)(suit(), userCssClasses.root),
73
- emptyRoot: (0, _instantsearchUiComponents.cx)(suit({
74
- modifierName: 'empty'
75
- }), userCssClasses.emptyRoot),
76
- list: (0, _instantsearchUiComponents.cx)(suit({
77
- descendantName: 'list'
78
- }), userCssClasses.list),
79
- item: (0, _instantsearchUiComponents.cx)(suit({
80
- descendantName: 'item'
81
- }), userCssClasses.item)
82
- };
83
119
  var specializedRenderer = renderer({
84
120
  containerNode: containerNode,
85
121
  cssClasses: cssClasses,
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports.default = void 0;
8
+ var _utils = require("../../lib/utils");
8
9
  var _excluded = ["placesReference", "defaultPosition"],
9
10
  _excluded2 = ["places"];
10
11
  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; }
@@ -20,6 +21,7 @@ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) r
20
21
  /**
21
22
  * This widget sets the geolocation value for the search based on the selected
22
23
  * result in the Algolia Places autocomplete.
24
+ * @deprecated the places service is no longer offered, and this widget will be removed in InstantSearch.js v5
23
25
  */
24
26
  var placesWidget = function placesWidget(widgetParams) {
25
27
  var _ref = widgetParams || {},
@@ -105,5 +107,5 @@ var placesWidget = function placesWidget(widgetParams) {
105
107
  }
106
108
  };
107
109
  };
108
- var _default = placesWidget;
110
+ var _default = (0, _utils.deprecate)(placesWidget, 'The places widget is deprecated and will be removed in InstantSearch.js 5.0.');
109
111
  exports.default = _default;
@@ -7,6 +7,7 @@ import { FindAnswersOptions } from 'algoliasearch-helper/types/algoliasearch.js'
7
7
  import { h } from 'preact';
8
8
  import type { HighlightClassNames as HighlightClassNames_2 } from 'instantsearch-ui-components';
9
9
  import type { HighlightProps as HighlightProps_3 } from 'instantsearch-ui-components';
10
+ import type { HitsClassNames } from 'instantsearch-ui-components';
10
11
  import type { HoganOptions } from 'hogan.js';
11
12
  import type { html } from 'htm/preact';
12
13
  import type { InsightsClient as InsightsClient_2 } from 'search-insights';
@@ -1111,6 +1112,8 @@ declare type CustomSendEventForHits = (customPayload: any) => void;
1111
1112
 
1112
1113
  declare type CustomSendEventForToggle = (customPayload: any) => void;
1113
1114
 
1115
+ declare const _default: PlacesWidget;
1116
+
1114
1117
  declare type DisposeOptions = {
1115
1118
  helper: AlgoliaSearchHelper;
1116
1119
  state: SearchParameters;
@@ -1863,24 +1866,7 @@ declare type HitsConnectorParams<THit extends BaseHit = BaseHit> = {
1863
1866
  transformItems?: TransformItems<Hit<THit>>;
1864
1867
  };
1865
1868
 
1866
- declare type HitsCSSClasses = Partial<{
1867
- /**
1868
- * CSS class to add to the wrapping element.
1869
- */
1870
- root: string | string[];
1871
- /**
1872
- * CSS class to add to the wrapping element when no results.
1873
- */
1874
- emptyRoot: string | string[];
1875
- /**
1876
- * CSS class to add to the list of results.
1877
- */
1878
- list: string | string[];
1879
- /**
1880
- * CSS class to add to each result.
1881
- */
1882
- item: string | string[];
1883
- }>;
1869
+ declare type HitsCSSClasses = Partial<HitsClassNames>;
1884
1870
 
1885
1871
  declare type HitSnippetResult = {
1886
1872
  [attribute: string]: HitAttributeSnippetResult[] | HitSnippetResult[] | HitAttributeSnippetResult | HitSnippetResult;
@@ -3431,12 +3417,6 @@ declare type PlacesInstance = Places.PlacesInstance;
3431
3417
 
3432
3418
  declare type PlacesWidget = WidgetFactory<PlacesWidgetDescription, PlacesWidgetParams, PlacesWidgetParams>;
3433
3419
 
3434
- /**
3435
- * This widget sets the geolocation value for the search based on the selected
3436
- * result in the Algolia Places autocomplete.
3437
- */
3438
- declare const placesWidget: PlacesWidget;
3439
-
3440
3420
  declare type PlacesWidgetDescription = {
3441
3421
  $$type: 'ais.places';
3442
3422
  $$widgetType: 'ais.places';
@@ -4263,6 +4243,8 @@ declare type RefinementListRenderState = {
4263
4243
  isFromSearch: boolean;
4264
4244
  /**
4265
4245
  * `true` if a refinement can be applied.
4246
+ * @MAJOR: reconsider how `canRefine` is computed so it both accounts for the
4247
+ * items returned in the main search and in SFFV.
4266
4248
  */
4267
4249
  canRefine: boolean;
4268
4250
  /**
@@ -5563,7 +5545,7 @@ declare namespace widgets {
5563
5545
  numericMenu,
5564
5546
  pagination,
5565
5547
  panel,
5566
- placesWidget as places,
5548
+ _default as places,
5567
5549
  poweredBy,
5568
5550
  queryRuleContext,
5569
5551
  queryRuleCustomData,