instantsearch.js 4.46.3 → 4.48.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 (44) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/cjs/connectors/hierarchical-menu/connectHierarchicalMenu.js +4 -1
  3. package/cjs/lib/InstantSearch.js +45 -6
  4. package/cjs/lib/utils/createSendEventForFacet.js +2 -1
  5. package/cjs/lib/utils/createSendEventForHits.js +1 -1
  6. package/cjs/lib/utils/index.js +13 -0
  7. package/cjs/lib/utils/render-args.js +47 -0
  8. package/cjs/lib/version.js +1 -1
  9. package/cjs/middlewares/createInsightsMiddleware.js +3 -5
  10. package/cjs/middlewares/createMetadataMiddleware.js +1 -15
  11. package/cjs/widgets/hierarchical-menu/defaultTemplates.js +3 -2
  12. package/cjs/widgets/hierarchical-menu/hierarchical-menu.js +4 -0
  13. package/cjs/widgets/index/index.js +7 -85
  14. package/dist/instantsearch.development.d.ts +34 -11
  15. package/dist/instantsearch.development.js +110 -115
  16. package/dist/instantsearch.development.js.map +1 -1
  17. package/dist/instantsearch.production.d.ts +34 -11
  18. package/dist/instantsearch.production.min.d.ts +34 -11
  19. package/dist/instantsearch.production.min.js +2 -2
  20. package/dist/instantsearch.production.min.js.map +1 -1
  21. package/es/connectors/hierarchical-menu/connectHierarchicalMenu.js +4 -1
  22. package/es/connectors/search-box/connectSearchBox.d.ts +1 -0
  23. package/es/lib/InstantSearch.d.ts +17 -4
  24. package/es/lib/InstantSearch.js +45 -6
  25. package/es/lib/utils/createSendEventForFacet.d.ts +4 -3
  26. package/es/lib/utils/createSendEventForFacet.js +2 -1
  27. package/es/lib/utils/createSendEventForHits.js +1 -1
  28. package/es/lib/utils/defer.d.ts +2 -2
  29. package/es/lib/utils/index.d.ts +1 -0
  30. package/es/lib/utils/index.js +1 -0
  31. package/es/lib/utils/render-args.d.ts +34 -0
  32. package/es/lib/utils/render-args.js +38 -0
  33. package/es/lib/version.d.ts +1 -1
  34. package/es/lib/version.js +1 -1
  35. package/es/middlewares/createInsightsMiddleware.d.ts +5 -5
  36. package/es/middlewares/createInsightsMiddleware.js +2 -2
  37. package/es/middlewares/createMetadataMiddleware.js +2 -16
  38. package/es/types/widget.d.ts +4 -0
  39. package/es/widgets/hierarchical-menu/defaultTemplates.js +3 -2
  40. package/es/widgets/hierarchical-menu/hierarchical-menu.d.ts +4 -0
  41. package/es/widgets/hierarchical-menu/hierarchical-menu.js +4 -0
  42. package/es/widgets/index/index.d.ts +1 -1
  43. package/es/widgets/index/index.js +8 -86
  44. package/package.json +7 -8
@@ -167,7 +167,10 @@ var connectHierarchicalMenu = function connectHierarchicalMenu(renderFn) {
167
167
  sendEvent = createSendEventForFacet({
168
168
  instantSearchInstance: instantSearchInstance,
169
169
  helper: helper,
170
- attribute: hierarchicalFacetName,
170
+ attribute: function attribute(facetValue) {
171
+ var index = facetValue.split(separator).length - 1;
172
+ return attributes[index];
173
+ },
171
174
  widgetType: this.$$type
172
175
  });
173
176
  }
@@ -34,6 +34,7 @@ export declare type SearchBoxRenderState = {
34
34
  * `true` if the search results takes more than a certain time to come back
35
35
  * from Algolia servers. This can be configured on the InstantSearch constructor with the attribute
36
36
  * `stalledSearchDelay` which is 200ms, by default.
37
+ * @deprecated use `instantSearchInstance.status` instead
37
38
  */
38
39
  isSearchStalled: boolean;
39
40
  };
@@ -86,6 +86,7 @@ export declare type InstantSearchOptions<TUiState extends UiState = UiState, TRo
86
86
  */
87
87
  insightsClient?: AlgoliaInsightsClient;
88
88
  };
89
+ export declare type InstantSearchStatus = 'idle' | 'loading' | 'stalled' | 'error';
89
90
  /**
90
91
  * The actual implementation of the InstantSearch. This is
91
92
  * created using the `instantsearch` factory function.
@@ -104,7 +105,6 @@ declare class InstantSearch<TUiState extends UiState = UiState, TRouteState = TU
104
105
  renderState: RenderState;
105
106
  _stalledSearchDelay: number;
106
107
  _searchStalledTimer: any;
107
- _isSearchStalled: boolean;
108
108
  _initialUiState: TUiState;
109
109
  _initialResults: InitialResults | null;
110
110
  _createURL: CreateURL<TUiState>;
@@ -115,6 +115,19 @@ declare class InstantSearch<TUiState extends UiState = UiState, TRouteState = TU
115
115
  instance: MiddlewareDefinition;
116
116
  }>;
117
117
  sendEventToInsights: (event: InsightsEvent) => void;
118
+ /**
119
+ * The status of the search. Can be "idle", "loading", "stalled", or "error".
120
+ */
121
+ status: InstantSearchStatus;
122
+ /**
123
+ * The last returned error from the Search API.
124
+ * The error gets cleared when the next valid search response is rendered.
125
+ */
126
+ error: Error | undefined;
127
+ /**
128
+ * @deprecated use `status === 'stalled'` instead
129
+ */
130
+ get _isSearchStalled(): boolean;
118
131
  constructor(options: InstantSearchOptions<TUiState, TRouteState>);
119
132
  /**
120
133
  * Hooks a middleware into the InstantSearch lifecycle.
@@ -168,11 +181,11 @@ declare class InstantSearch<TUiState extends UiState = UiState, TRouteState = TU
168
181
  * @return {undefined} This method does not return anything
169
182
  */
170
183
  dispose(): void;
171
- scheduleSearch: ((...args: any[]) => void) & {
184
+ scheduleSearch: (() => void) & {
172
185
  wait(): Promise<void>;
173
186
  cancel(): void;
174
187
  };
175
- scheduleRender: ((...args: any[]) => void) & {
188
+ scheduleRender: ((shouldResetStatus?: boolean) => void) & {
176
189
  wait(): Promise<void>;
177
190
  cancel(): void;
178
191
  };
@@ -184,7 +197,7 @@ declare class InstantSearch<TUiState extends UiState = UiState, TRouteState = TU
184
197
  */
185
198
  setUiState(uiState: TUiState | ((previousUiState: TUiState) => TUiState), callOnStateChange?: boolean): void;
186
199
  getUiState(): TUiState;
187
- onInternalStateChange: ((...args: any[]) => void) & {
200
+ onInternalStateChange: (() => void) & {
188
201
  wait(): Promise<void>;
189
202
  cancel(): void;
190
203
  };
@@ -86,8 +86,6 @@ var InstantSearch = /*#__PURE__*/function (_EventEmitter) {
86
86
 
87
87
  _defineProperty(_assertThisInitialized(_this), "_searchStalledTimer", void 0);
88
88
 
89
- _defineProperty(_assertThisInitialized(_this), "_isSearchStalled", void 0);
90
-
91
89
  _defineProperty(_assertThisInitialized(_this), "_initialUiState", void 0);
92
90
 
93
91
  _defineProperty(_assertThisInitialized(_this), "_initialResults", void 0);
@@ -102,6 +100,10 @@ var InstantSearch = /*#__PURE__*/function (_EventEmitter) {
102
100
 
103
101
  _defineProperty(_assertThisInitialized(_this), "sendEventToInsights", void 0);
104
102
 
103
+ _defineProperty(_assertThisInitialized(_this), "status", 'idle');
104
+
105
+ _defineProperty(_assertThisInitialized(_this), "error", undefined);
106
+
105
107
  _defineProperty(_assertThisInitialized(_this), "scheduleSearch", defer(function () {
106
108
  if (_this.started) {
107
109
  _this.mainHelper.search();
@@ -109,10 +111,16 @@ var InstantSearch = /*#__PURE__*/function (_EventEmitter) {
109
111
  }));
110
112
 
111
113
  _defineProperty(_assertThisInitialized(_this), "scheduleRender", defer(function () {
114
+ var shouldResetStatus = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
115
+
112
116
  if (!_this.mainHelper.hasPendingRequests()) {
113
117
  clearTimeout(_this._searchStalledTimer);
114
118
  _this._searchStalledTimer = null;
115
- _this._isSearchStalled = false;
119
+
120
+ if (shouldResetStatus) {
121
+ _this.status = 'idle';
122
+ _this.error = undefined;
123
+ }
116
124
  }
117
125
 
118
126
  _this.mainIndex.render({
@@ -193,7 +201,6 @@ var InstantSearch = /*#__PURE__*/function (_EventEmitter) {
193
201
  };
194
202
  _this._stalledSearchDelay = stalledSearchDelay;
195
203
  _this._searchStalledTimer = null;
196
- _this._isSearchStalled = false;
197
204
  _this._createURL = defaultCreateURL;
198
205
  _this._initialUiState = initialUiState;
199
206
  _this._initialResults = null;
@@ -222,6 +229,25 @@ var InstantSearch = /*#__PURE__*/function (_EventEmitter) {
222
229
 
223
230
 
224
231
  _createClass(InstantSearch, [{
232
+ key: "_isSearchStalled",
233
+ get:
234
+ /**
235
+ * The status of the search. Can be "idle", "loading", "stalled", or "error".
236
+ */
237
+
238
+ /**
239
+ * The last returned error from the Search API.
240
+ * The error gets cleared when the next valid search response is rendered.
241
+ */
242
+
243
+ /**
244
+ * @deprecated use `status === 'stalled'` instead
245
+ */
246
+ function get() {
247
+ process.env.NODE_ENV === 'development' ? warning(false, "`InstantSearch._isSearchStalled` is deprecated and will be removed in InstantSearch.js 5.0.\n\nUse `InstantSearch.status === \"stalled\"` instead.") : void 0;
248
+ return this.status === 'stalled';
249
+ }
250
+ }, {
225
251
  key: "use",
226
252
  value: function use() {
227
253
  var _this2 = this;
@@ -383,10 +409,18 @@ var InstantSearch = /*#__PURE__*/function (_EventEmitter) {
383
409
  var mainHelper = this.mainHelper || algoliasearchHelper(this.client, this.indexName);
384
410
 
385
411
  mainHelper.search = function () {
386
- // This solution allows us to keep the exact same API for the users but
412
+ _this3.status = 'loading'; // @MAJOR: use scheduleRender here
413
+ // For now, widgets don't expect to be rendered at the start of `loading`,
414
+ // so it would be a breaking change to add an extra render. We don't have
415
+ // these guarantees about the render event, thus emitting it once more
416
+ // isn't a breaking change.
417
+
418
+ _this3.emit('render'); // This solution allows us to keep the exact same API for the users but
387
419
  // under the hood, we have a different implementation. It should be
388
420
  // completely transparent for the rest of the codebase. Only this module
389
421
  // is impacted.
422
+
423
+
390
424
  return mainHelper.searchOnlyWithDerivedHelpers();
391
425
  };
392
426
 
@@ -443,6 +477,11 @@ var InstantSearch = /*#__PURE__*/function (_EventEmitter) {
443
477
 
444
478
 
445
479
  error.error = error;
480
+ _this3.error = error;
481
+ _this3.status = 'error';
482
+
483
+ _this3.scheduleRender(false); // This needs to execute last because it throws the error.
484
+
446
485
 
447
486
  _this3.emit('error', error);
448
487
  });
@@ -531,7 +570,7 @@ var InstantSearch = /*#__PURE__*/function (_EventEmitter) {
531
570
 
532
571
  if (!this._searchStalledTimer) {
533
572
  this._searchStalledTimer = setTimeout(function () {
534
- _this4._isSearchStalled = true;
573
+ _this4.status = 'stalled';
535
574
 
536
575
  _this4.scheduleRender();
537
576
  }, this._stalledSearchDelay);
@@ -3,10 +3,11 @@ import type { InstantSearch } from '../../types';
3
3
  declare type BuiltInSendEventForFacet = (eventType: string, facetValue: string, eventName?: string) => void;
4
4
  declare type CustomSendEventForFacet = (customPayload: any) => void;
5
5
  export declare type SendEventForFacet = BuiltInSendEventForFacet & CustomSendEventForFacet;
6
- export declare function createSendEventForFacet({ instantSearchInstance, helper, attribute, widgetType, }: {
6
+ declare type CreateSendEventForFacetOptions = {
7
7
  instantSearchInstance: InstantSearch;
8
8
  helper: AlgoliaSearchHelper;
9
- attribute: string;
9
+ attribute: string | ((facetValue: string) => string);
10
10
  widgetType: string;
11
- }): SendEventForFacet;
11
+ };
12
+ export declare function createSendEventForFacet({ instantSearchInstance, helper, attribute: attr, widgetType, }: CreateSendEventForFacetOptions): SendEventForFacet;
12
13
  export {};
@@ -4,7 +4,7 @@ import { isFacetRefined } from "./isFacetRefined.js";
4
4
  export function createSendEventForFacet(_ref) {
5
5
  var instantSearchInstance = _ref.instantSearchInstance,
6
6
  helper = _ref.helper,
7
- attribute = _ref.attribute,
7
+ attr = _ref.attribute,
8
8
  widgetType = _ref.widgetType;
9
9
 
10
10
  var sendEventForFacet = function sendEventForFacet() {
@@ -16,6 +16,7 @@ export function createSendEventForFacet(_ref) {
16
16
  facetValue = args[1],
17
17
  _args$ = args[2],
18
18
  eventName = _args$ === void 0 ? 'Filter Applied' : _args$;
19
+ var attribute = typeof attr === 'string' ? attr : attr(facetValue);
19
20
 
20
21
  if (args.length === 1 && _typeof(args[0]) === 'object') {
21
22
  instantSearchInstance.sendEventToInsights(args[0]);
@@ -140,7 +140,7 @@ export function createSendEventForHits(_ref2) {
140
140
  index: index,
141
141
  methodName: 'sendEvent',
142
142
  args: args,
143
- isSearchStalled: instantSearchInstance._isSearchStalled
143
+ isSearchStalled: instantSearchInstance.status === 'stalled'
144
144
  });
145
145
  payloads.forEach(function (payload) {
146
146
  return instantSearchInstance.sendEventToInsights(payload);
@@ -1,7 +1,7 @@
1
1
  declare type Callback = (...args: any[]) => void;
2
- declare type Defer = Callback & {
2
+ declare type Defer = {
3
3
  wait(): Promise<void>;
4
4
  cancel(): void;
5
5
  };
6
- export declare function defer(callback: Callback): Defer;
6
+ export declare function defer<TCallback extends Callback>(callback: TCallback): TCallback & Defer;
7
7
  export {};
@@ -38,6 +38,7 @@ export * from './logger';
38
38
  export * from './mergeSearchParameters';
39
39
  export * from './noop';
40
40
  export * from './range';
41
+ export * from './render-args';
41
42
  export * from './resolveSearchParameters';
42
43
  export * from './reverseHighlightedParts';
43
44
  export * from './safelyRunOnBrowser';
@@ -38,6 +38,7 @@ export * from "./logger.js";
38
38
  export * from "./mergeSearchParameters.js";
39
39
  export * from "./noop.js";
40
40
  export * from "./range.js";
41
+ export * from "./render-args.js";
41
42
  export * from "./resolveSearchParameters.js";
42
43
  export * from "./reverseHighlightedParts.js";
43
44
  export * from "./safelyRunOnBrowser.js";
@@ -0,0 +1,34 @@
1
+ import type { InstantSearch, UiState } from '../../types';
2
+ import type { IndexWidget } from '../../widgets/index/index';
3
+ export declare function createInitArgs(instantSearchInstance: InstantSearch, parent: IndexWidget, uiState: UiState): {
4
+ uiState: UiState;
5
+ helper: import("algoliasearch-helper").AlgoliaSearchHelper;
6
+ parent: IndexWidget;
7
+ instantSearchInstance: InstantSearch<UiState, UiState>;
8
+ state: import("algoliasearch-helper").SearchParameters;
9
+ renderState: import("../../types").RenderState;
10
+ templatesConfig: Record<string, unknown>;
11
+ createURL: (state: import("algoliasearch-helper").SearchParameters) => string;
12
+ scopedResults: never[];
13
+ searchMetadata: {
14
+ isSearchStalled: boolean;
15
+ };
16
+ status: import("../InstantSearch").InstantSearchStatus;
17
+ error: Error | undefined;
18
+ };
19
+ export declare function createRenderArgs(instantSearchInstance: InstantSearch, parent: IndexWidget): {
20
+ helper: import("algoliasearch-helper").AlgoliaSearchHelper;
21
+ parent: IndexWidget;
22
+ instantSearchInstance: InstantSearch<UiState, UiState>;
23
+ results: import("algoliasearch-helper").SearchResults<any>;
24
+ scopedResults: import("../../types").ScopedResult[];
25
+ state: import("algoliasearch-helper").SearchParameters;
26
+ renderState: import("../../types").RenderState;
27
+ templatesConfig: Record<string, unknown>;
28
+ createURL: (state: import("algoliasearch-helper").SearchParameters) => string;
29
+ searchMetadata: {
30
+ isSearchStalled: boolean;
31
+ };
32
+ status: import("../InstantSearch").InstantSearchStatus;
33
+ error: Error | undefined;
34
+ };
@@ -0,0 +1,38 @@
1
+ export function createInitArgs(instantSearchInstance, parent, uiState) {
2
+ var helper = parent.getHelper();
3
+ return {
4
+ uiState: uiState,
5
+ helper: helper,
6
+ parent: parent,
7
+ instantSearchInstance: instantSearchInstance,
8
+ state: helper.state,
9
+ renderState: instantSearchInstance.renderState,
10
+ templatesConfig: instantSearchInstance.templatesConfig,
11
+ createURL: parent.createURL,
12
+ scopedResults: [],
13
+ searchMetadata: {
14
+ isSearchStalled: instantSearchInstance.status === 'stalled'
15
+ },
16
+ status: instantSearchInstance.status,
17
+ error: instantSearchInstance.error
18
+ };
19
+ }
20
+ export function createRenderArgs(instantSearchInstance, parent) {
21
+ var results = parent.getResults();
22
+ return {
23
+ helper: parent.getHelper(),
24
+ parent: parent,
25
+ instantSearchInstance: instantSearchInstance,
26
+ results: results,
27
+ scopedResults: parent.getScopedResults(),
28
+ state: results._state,
29
+ renderState: instantSearchInstance.renderState,
30
+ templatesConfig: instantSearchInstance.templatesConfig,
31
+ createURL: parent.createURL,
32
+ searchMetadata: {
33
+ isSearchStalled: instantSearchInstance.status === 'stalled'
34
+ },
35
+ status: instantSearchInstance.status,
36
+ error: instantSearchInstance.error
37
+ };
38
+ }
@@ -1,2 +1,2 @@
1
- declare const _default: "4.46.3";
1
+ declare const _default: "4.48.0";
2
2
  export default _default;
package/es/lib/version.js CHANGED
@@ -1 +1 @@
1
- export default '4.46.3';
1
+ export default '4.48.0';
@@ -7,15 +7,15 @@ export declare type InsightsEvent = {
7
7
  hits?: Hit[];
8
8
  attribute?: string;
9
9
  };
10
- export declare type InsightsProps = {
11
- insightsClient: null | InsightsClient;
10
+ export declare type InsightsProps<TInsightsClient extends null | InsightsClient = InsightsClient | null> = {
11
+ insightsClient: TInsightsClient;
12
12
  insightsInitParams?: {
13
13
  userHasOptedOut?: boolean;
14
14
  useCookie?: boolean;
15
15
  cookieDuration?: number;
16
16
  region?: 'de' | 'us';
17
17
  };
18
- onEvent?: (event: InsightsEvent, insightsClient: null | InsightsClient) => void;
18
+ onEvent?: (event: InsightsEvent, insightsClient: TInsightsClient) => void;
19
19
  };
20
- export declare type CreateInsightsMiddleware = (props: InsightsProps) => InternalMiddleware;
21
- export declare const createInsightsMiddleware: CreateInsightsMiddleware;
20
+ export declare type CreateInsightsMiddleware = typeof createInsightsMiddleware;
21
+ export declare function createInsightsMiddleware<TInsightsClient extends null | InsightsClient>(props: InsightsProps<TInsightsClient>): InternalMiddleware;
@@ -18,7 +18,7 @@ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
18
18
 
19
19
  import { getInsightsAnonymousUserTokenInternal } from "../helpers/index.js";
20
20
  import { warning, noop, getAppIdAndApiKey, find } from "../lib/utils/index.js";
21
- export var createInsightsMiddleware = function createInsightsMiddleware(props) {
21
+ export function createInsightsMiddleware(props) {
22
22
  var _ref = props || {},
23
23
  _insightsClient = _ref.insightsClient,
24
24
  insightsInitParams = _ref.insightsInitParams,
@@ -157,4 +157,4 @@ export var createInsightsMiddleware = function createInsightsMiddleware(props) {
157
157
  }
158
158
  };
159
159
  };
160
- };
160
+ }
@@ -1,21 +1,7 @@
1
- import { safelyRunOnBrowser } from "../lib/utils/index.js";
1
+ import { createInitArgs, safelyRunOnBrowser } from "../lib/utils/index.js";
2
2
 
3
3
  function extractPayload(widgets, instantSearchInstance, payload) {
4
- var parent = instantSearchInstance.mainIndex;
5
- var initOptions = {
6
- instantSearchInstance: instantSearchInstance,
7
- parent: parent,
8
- scopedResults: [],
9
- state: parent.getHelper().state,
10
- helper: parent.getHelper(),
11
- createURL: parent.createURL,
12
- uiState: instantSearchInstance._initialUiState,
13
- renderState: instantSearchInstance.renderState,
14
- templatesConfig: instantSearchInstance.templatesConfig,
15
- searchMetadata: {
16
- isSearchStalled: instantSearchInstance._isSearchStalled
17
- }
18
- };
4
+ var initOptions = createInitArgs(instantSearchInstance, instantSearchInstance.mainIndex, instantSearchInstance._initialUiState);
19
5
  widgets.forEach(function (widget) {
20
6
  var widgetParams = {};
21
7
 
@@ -17,9 +17,13 @@ declare type SharedRenderOptions = {
17
17
  state: SearchParameters;
18
18
  renderState: IndexRenderState;
19
19
  helper: Helper;
20
+ /** @deprecated use `status` instead */
20
21
  searchMetadata: {
22
+ /** @deprecated use `status === "stalled"` instead */
21
23
  isSearchStalled: boolean;
22
24
  };
25
+ status: InstantSearch['status'];
26
+ error: InstantSearch['error'];
23
27
  createURL(state: SearchParameters): string;
24
28
  };
25
29
  export declare type InitOptions = SharedRenderOptions & {
@@ -6,9 +6,10 @@ var defaultTemplates = {
6
6
  var url = _ref.url,
7
7
  label = _ref.label,
8
8
  count = _ref.count,
9
- cssClasses = _ref.cssClasses;
9
+ cssClasses = _ref.cssClasses,
10
+ isRefined = _ref.isRefined;
10
11
  return h("a", {
11
- className: cx(cssClasses.link),
12
+ className: cx([cx(cssClasses.link), cx(isRefined ? cssClasses.selectedItemLink : undefined)]),
12
13
  href: url
13
14
  }, h("span", {
14
15
  className: cx(cssClasses.label)
@@ -53,6 +53,10 @@ export declare type HierarchicalMenuCSSClasses = Partial<{
53
53
  * CSS class to add to each link (when using the default template).
54
54
  */
55
55
  link: string | string[];
56
+ /**
57
+ * CSS class to add to the link of each selected item element (when using the default template).
58
+ */
59
+ selectedItemLink: string | string[];
56
60
  /**
57
61
  * CSS class to add to each label (when using the default template).
58
62
  */
@@ -156,6 +156,10 @@ var hierarchicalMenu = function hierarchicalMenu(widgetParams) {
156
156
  link: cx(suit({
157
157
  descendantName: 'link'
158
158
  }), userCssClasses.link),
159
+ selectedItemLink: cx(suit({
160
+ descendantName: 'link',
161
+ modifierName: 'selected'
162
+ }), userCssClasses.selectedItemLink),
159
163
  label: cx(suit({
160
164
  descendantName: 'label'
161
165
  }), userCssClasses.label),
@@ -36,7 +36,7 @@ export declare type IndexWidget = Omit<Widget<IndexWidgetDescription & {
36
36
  * @deprecated
37
37
  */
38
38
  getWidgetState(uiState: UiState): UiState;
39
- getWidgetUiState<TUiState = UiState>(uiState: TUiState): TUiState;
39
+ getWidgetUiState<TUiState extends UiState = UiState>(uiState: TUiState): TUiState;
40
40
  getWidgetSearchParameters(searchParameters: SearchParameters, searchParametersOptions: {
41
41
  uiState: IndexUiState;
42
42
  }): SearchParameters;
@@ -21,7 +21,7 @@ function _objectWithoutProperties(source, excluded) { if (source == null) return
21
21
  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; }
22
22
 
23
23
  import algoliasearchHelper from 'algoliasearch-helper';
24
- import { checkIndexUiState, createDocumentationMessageGenerator, resolveSearchParameters, mergeSearchParameters, warning, isIndexWidget } from "../../lib/utils/index.js";
24
+ import { checkIndexUiState, createDocumentationMessageGenerator, resolveSearchParameters, mergeSearchParameters, warning, isIndexWidget, createInitArgs, createRenderArgs } from "../../lib/utils/index.js";
25
25
  var withUsage = createDocumentationMessageGenerator({
26
26
  name: 'index-widget'
27
27
  });
@@ -184,20 +184,7 @@ var index = function index(widgetParams) {
184
184
 
185
185
  widgets.forEach(function (widget) {
186
186
  if (widget.getRenderState) {
187
- var renderState = widget.getRenderState(localInstantSearchInstance.renderState[_this.getIndexId()] || {}, {
188
- uiState: localInstantSearchInstance._initialUiState,
189
- helper: _this.getHelper(),
190
- parent: _this,
191
- instantSearchInstance: localInstantSearchInstance,
192
- state: helper.state,
193
- renderState: localInstantSearchInstance.renderState,
194
- templatesConfig: localInstantSearchInstance.templatesConfig,
195
- createURL: _this.createURL,
196
- scopedResults: [],
197
- searchMetadata: {
198
- isSearchStalled: localInstantSearchInstance._isSearchStalled
199
- }
200
- });
187
+ var renderState = widget.getRenderState(localInstantSearchInstance.renderState[_this.getIndexId()] || {}, createInitArgs(localInstantSearchInstance, _this, localInstantSearchInstance._initialUiState));
201
188
  storeRenderState({
202
189
  renderState: renderState,
203
190
  instantSearchInstance: localInstantSearchInstance,
@@ -207,20 +194,7 @@ var index = function index(widgetParams) {
207
194
  });
208
195
  widgets.forEach(function (widget) {
209
196
  if (widget.init) {
210
- widget.init({
211
- helper: helper,
212
- parent: _this,
213
- uiState: localInstantSearchInstance._initialUiState,
214
- instantSearchInstance: localInstantSearchInstance,
215
- state: helper.state,
216
- renderState: localInstantSearchInstance.renderState,
217
- templatesConfig: localInstantSearchInstance.templatesConfig,
218
- createURL: _this.createURL,
219
- scopedResults: [],
220
- searchMetadata: {
221
- isSearchStalled: localInstantSearchInstance._isSearchStalled
222
- }
223
- });
197
+ widget.init(createInitArgs(localInstantSearchInstance, _this, localInstantSearchInstance._initialUiState));
224
198
  }
225
199
  });
226
200
  localInstantSearchInstance.scheduleSearch();
@@ -386,20 +360,7 @@ var index = function index(widgetParams) {
386
360
 
387
361
  localWidgets.forEach(function (widget) {
388
362
  if (widget.getRenderState) {
389
- var renderState = widget.getRenderState(instantSearchInstance.renderState[_this3.getIndexId()] || {}, {
390
- uiState: uiState,
391
- helper: helper,
392
- parent: _this3,
393
- instantSearchInstance: instantSearchInstance,
394
- state: helper.state,
395
- renderState: instantSearchInstance.renderState,
396
- templatesConfig: instantSearchInstance.templatesConfig,
397
- createURL: _this3.createURL,
398
- scopedResults: [],
399
- searchMetadata: {
400
- isSearchStalled: instantSearchInstance._isSearchStalled
401
- }
402
- });
363
+ var renderState = widget.getRenderState(instantSearchInstance.renderState[_this3.getIndexId()] || {}, createInitArgs(instantSearchInstance, _this3, uiState));
403
364
  storeRenderState({
404
365
  renderState: renderState,
405
366
  instantSearchInstance: instantSearchInstance,
@@ -413,20 +374,7 @@ var index = function index(widgetParams) {
413
374
  !widget.getWidgetState || Boolean(widget.getWidgetUiState), 'The `getWidgetState` method is renamed `getWidgetUiState` and will no longer exist under that name in InstantSearch.js 5.x. Please use `getWidgetUiState` instead.') : void 0;
414
375
 
415
376
  if (widget.init) {
416
- widget.init({
417
- uiState: uiState,
418
- helper: helper,
419
- parent: _this3,
420
- instantSearchInstance: instantSearchInstance,
421
- state: helper.state,
422
- renderState: instantSearchInstance.renderState,
423
- templatesConfig: instantSearchInstance.templatesConfig,
424
- createURL: _this3.createURL,
425
- scopedResults: [],
426
- searchMetadata: {
427
- isSearchStalled: instantSearchInstance._isSearchStalled
428
- }
429
- });
377
+ widget.init(createInitArgs(instantSearchInstance, _this3, uiState));
430
378
  }
431
379
  }); // Subscribe to the Helper state changes for the `uiState` once widgets
432
380
  // are initialized. Until the first render, state changes are part of the
@@ -467,20 +415,7 @@ var index = function index(widgetParams) {
467
415
 
468
416
  localWidgets.forEach(function (widget) {
469
417
  if (widget.getRenderState) {
470
- var renderState = widget.getRenderState(instantSearchInstance.renderState[_this4.getIndexId()] || {}, {
471
- helper: _this4.getHelper(),
472
- parent: _this4,
473
- instantSearchInstance: instantSearchInstance,
474
- results: _this4.getResults(),
475
- scopedResults: _this4.getScopedResults(),
476
- state: _this4.getResults()._state,
477
- renderState: instantSearchInstance.renderState,
478
- templatesConfig: instantSearchInstance.templatesConfig,
479
- createURL: _this4.createURL,
480
- searchMetadata: {
481
- isSearchStalled: instantSearchInstance._isSearchStalled
482
- }
483
- });
418
+ var renderState = widget.getRenderState(instantSearchInstance.renderState[_this4.getIndexId()] || {}, createRenderArgs(instantSearchInstance, _this4));
484
419
  storeRenderState({
485
420
  renderState: renderState,
486
421
  instantSearchInstance: instantSearchInstance,
@@ -496,20 +431,7 @@ var index = function index(widgetParams) {
496
431
  // be delayed. The render is triggered for the complete tree but some parts do
497
432
  // not have results yet.
498
433
  if (widget.render) {
499
- widget.render({
500
- helper: helper,
501
- parent: _this4,
502
- instantSearchInstance: instantSearchInstance,
503
- results: _this4.getResults(),
504
- scopedResults: _this4.getScopedResults(),
505
- state: _this4.getResults()._state,
506
- renderState: instantSearchInstance.renderState,
507
- templatesConfig: instantSearchInstance.templatesConfig,
508
- createURL: _this4.createURL,
509
- searchMetadata: {
510
- isSearchStalled: instantSearchInstance._isSearchStalled
511
- }
512
- });
434
+ widget.render(createRenderArgs(instantSearchInstance, _this4));
513
435
  }
514
436
  });
515
437
  },
@@ -541,7 +463,7 @@ var index = function index(widgetParams) {
541
463
  getWidgetUiState: function getWidgetUiState(uiState) {
542
464
  return localWidgets.filter(isIndexWidget).reduce(function (previousUiState, innerIndex) {
543
465
  return innerIndex.getWidgetUiState(previousUiState);
544
- }, _objectSpread(_objectSpread({}, uiState), {}, _defineProperty({}, this.getIndexId(), localUiState)));
466
+ }, _objectSpread(_objectSpread({}, uiState), {}, _defineProperty({}, indexId, _objectSpread(_objectSpread({}, uiState[indexId]), localUiState))));
545
467
  },
546
468
  getWidgetState: function getWidgetState(uiState) {
547
469
  process.env.NODE_ENV === 'development' ? warning(false, 'The `getWidgetState` method is renamed `getWidgetUiState` and will no longer exist under that name in InstantSearch.js 5.x. Please use `getWidgetUiState` instead.') : void 0;