instantsearch.js 4.66.1 → 4.68.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.
- package/cjs/components/Template/Template.js +11 -2
- package/cjs/connectors/hits/connectHits.js +4 -0
- package/cjs/lib/InstantSearch.js +1 -1
- package/cjs/lib/version.js +1 -1
- package/cjs/widgets/hits/hits.js +14 -3
- package/cjs/widgets/index/index.js +80 -16
- package/dist/instantsearch.development.d.ts +38 -2
- package/dist/instantsearch.development.js +568 -46
- package/dist/instantsearch.development.js.map +1 -1
- package/dist/instantsearch.production.d.ts +38 -2
- package/dist/instantsearch.production.min.d.ts +38 -2
- package/dist/instantsearch.production.min.js +2 -2
- package/dist/instantsearch.production.min.js.map +1 -1
- package/es/components/Template/Template.js +11 -2
- package/es/connectors/hits/connectHits.d.ts +5 -0
- package/es/connectors/hits/connectHits.js +4 -0
- package/es/lib/InstantSearch.js +1 -1
- package/es/lib/version.d.ts +1 -1
- package/es/lib/version.js +1 -1
- package/es/types/widget.d.ts +21 -2
- package/es/widgets/hits/defaultTemplates.d.ts +1 -1
- package/es/widgets/hits/hits.d.ts +8 -1
- package/es/widgets/hits/hits.js +14 -3
- package/es/widgets/index/index.js +80 -16
- package/es/widgets/panel/panel.d.ts +1 -1
- package/package.json +8 -8
|
@@ -42,7 +42,7 @@ var RawHtml = /*#__PURE__*/function (_Component) {
|
|
|
42
42
|
var fragment = new DocumentFragment();
|
|
43
43
|
var root = document.createElement('div');
|
|
44
44
|
root.innerHTML = this.props.content;
|
|
45
|
-
this.nodes = _toConsumableArray(root.
|
|
45
|
+
this.nodes = _toConsumableArray(root.childNodes);
|
|
46
46
|
this.nodes.forEach(function (node) {
|
|
47
47
|
return fragment.appendChild(node);
|
|
48
48
|
});
|
|
@@ -52,8 +52,17 @@ var RawHtml = /*#__PURE__*/function (_Component) {
|
|
|
52
52
|
key: "componentWillUnmount",
|
|
53
53
|
value: function componentWillUnmount() {
|
|
54
54
|
this.nodes.forEach(function (node) {
|
|
55
|
-
|
|
55
|
+
if (node instanceof Element) {
|
|
56
|
+
node.outerHTML = '';
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
node.nodeValue = '';
|
|
56
60
|
});
|
|
61
|
+
// if there is one TextNode first and one TextNode last, the
|
|
62
|
+
// last one's nodeValue will be assigned to the first.
|
|
63
|
+
if (this.nodes[0].nodeValue) {
|
|
64
|
+
this.nodes[0].nodeValue = '';
|
|
65
|
+
}
|
|
57
66
|
}
|
|
58
67
|
}, {
|
|
59
68
|
key: "render",
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { SendEventForHits, BindEventForHits } from '../../lib/utils';
|
|
2
2
|
import type { TransformItems, Connector, Hit, WidgetRenderState, BaseHit } from '../../types';
|
|
3
3
|
import type { SearchResults } from 'algoliasearch-helper';
|
|
4
|
+
type Banner = NonNullable<NonNullable<Required<SearchResults<Hit>['renderingContent']>>['widgets']['banners']>[number];
|
|
4
5
|
export type HitsRenderState<THit extends BaseHit = BaseHit> = {
|
|
5
6
|
/**
|
|
6
7
|
* The matched hits from Algolia API.
|
|
@@ -10,6 +11,10 @@ export type HitsRenderState<THit extends BaseHit = BaseHit> = {
|
|
|
10
11
|
* The response from the Algolia API.
|
|
11
12
|
*/
|
|
12
13
|
results?: SearchResults<Hit<THit>>;
|
|
14
|
+
/**
|
|
15
|
+
* The banner to display above the hits.
|
|
16
|
+
*/
|
|
17
|
+
banner?: Banner;
|
|
13
18
|
/**
|
|
14
19
|
* Sends an event to the Insights middleware.
|
|
15
20
|
*/
|
|
@@ -42,6 +42,7 @@ var connectHits = function connectHits(renderFn) {
|
|
|
42
42
|
});
|
|
43
43
|
},
|
|
44
44
|
getWidgetRenderState: function getWidgetRenderState(_ref2) {
|
|
45
|
+
var _results$renderingCon, _results$renderingCon2, _results$renderingCon3;
|
|
45
46
|
var results = _ref2.results,
|
|
46
47
|
helper = _ref2.helper,
|
|
47
48
|
instantSearchInstance = _ref2.instantSearchInstance;
|
|
@@ -67,6 +68,7 @@ var connectHits = function connectHits(renderFn) {
|
|
|
67
68
|
return {
|
|
68
69
|
hits: [],
|
|
69
70
|
results: undefined,
|
|
71
|
+
banner: undefined,
|
|
70
72
|
sendEvent: sendEvent,
|
|
71
73
|
bindEvent: bindEvent,
|
|
72
74
|
widgetParams: widgetParams
|
|
@@ -80,9 +82,11 @@ var connectHits = function connectHits(renderFn) {
|
|
|
80
82
|
var transformedHits = transformItems(hitsWithAbsolutePositionAndQueryID, {
|
|
81
83
|
results: results
|
|
82
84
|
});
|
|
85
|
+
var banner = (_results$renderingCon = results.renderingContent) === null || _results$renderingCon === void 0 ? void 0 : (_results$renderingCon2 = _results$renderingCon.widgets) === null || _results$renderingCon2 === void 0 ? void 0 : (_results$renderingCon3 = _results$renderingCon2.banners) === null || _results$renderingCon3 === void 0 ? void 0 : _results$renderingCon3[0];
|
|
83
86
|
return {
|
|
84
87
|
hits: transformedHits,
|
|
85
88
|
results: results,
|
|
89
|
+
banner: banner,
|
|
86
90
|
sendEvent: sendEvent,
|
|
87
91
|
bindEvent: bindEvent,
|
|
88
92
|
widgetParams: widgetParams
|
package/es/lib/InstantSearch.js
CHANGED
|
@@ -384,7 +384,7 @@ var InstantSearch = /*#__PURE__*/function (_EventEmitter) {
|
|
|
384
384
|
// under the hood, we have a different implementation. It should be
|
|
385
385
|
// completely transparent for the rest of the codebase. Only this module
|
|
386
386
|
// is impacted.
|
|
387
|
-
return mainHelper.searchOnlyWithDerivedHelpers();
|
|
387
|
+
return mainHelper.searchOnlyWithDerivedHelpers() && mainHelper.recommend();
|
|
388
388
|
};
|
|
389
389
|
if (this._searchFunction) {
|
|
390
390
|
// this client isn't used to actually search, but required for the helper
|
package/es/lib/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default: "4.
|
|
1
|
+
declare const _default: "4.68.0";
|
|
2
2
|
export default _default;
|
package/es/lib/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export default '4.
|
|
1
|
+
export default '4.68.0';
|
package/es/types/widget.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import type { InstantSearch } from './instantsearch';
|
|
|
3
3
|
import type { IndexRenderState, WidgetRenderState } from './render-state';
|
|
4
4
|
import type { IndexUiState, UiState } from './ui-state';
|
|
5
5
|
import type { Expand, RequiredKeys } from './utils';
|
|
6
|
-
import type { AlgoliaSearchHelper as Helper, SearchParameters, SearchResults } from 'algoliasearch-helper';
|
|
6
|
+
import type { AlgoliaSearchHelper as Helper, SearchParameters, SearchResults, RecommendParameters } from 'algoliasearch-helper';
|
|
7
7
|
export type ScopedResult = {
|
|
8
8
|
indexId: string;
|
|
9
9
|
results: SearchResults;
|
|
@@ -30,6 +30,9 @@ export type InitOptions = SharedRenderOptions & {
|
|
|
30
30
|
uiState: UiState;
|
|
31
31
|
results?: undefined;
|
|
32
32
|
};
|
|
33
|
+
export type ShouldRenderOptions = {
|
|
34
|
+
instantSearchInstance: InstantSearch;
|
|
35
|
+
};
|
|
33
36
|
export type RenderOptions = SharedRenderOptions & {
|
|
34
37
|
results: SearchResults;
|
|
35
38
|
};
|
|
@@ -51,6 +54,18 @@ export type WidgetDescription = {
|
|
|
51
54
|
indexRenderState?: Record<string, unknown>;
|
|
52
55
|
indexUiState?: Record<string, unknown>;
|
|
53
56
|
};
|
|
57
|
+
type SearchWidgetLifeCycle<TWidgetDescription extends WidgetDescription> = {
|
|
58
|
+
dependsOn?: 'search';
|
|
59
|
+
getWidgetParameters?: (state: SearchParameters, widgetParametersOptions: {
|
|
60
|
+
uiState: Expand<Partial<TWidgetDescription['indexUiState'] & IndexUiState>>;
|
|
61
|
+
}) => SearchParameters;
|
|
62
|
+
};
|
|
63
|
+
type RecommendWidgetLifeCycle<TWidgetDescription extends WidgetDescription> = {
|
|
64
|
+
dependsOn?: 'recommend';
|
|
65
|
+
getWidgetParameters: (state: RecommendParameters, widgetParametersOptions: {
|
|
66
|
+
uiState: Expand<Partial<TWidgetDescription['indexUiState'] & IndexUiState>>;
|
|
67
|
+
}) => RecommendParameters;
|
|
68
|
+
};
|
|
54
69
|
type RequiredWidgetLifeCycle<TWidgetDescription extends WidgetDescription> = {
|
|
55
70
|
/**
|
|
56
71
|
* Identifier for connectors and widgets.
|
|
@@ -60,6 +75,10 @@ type RequiredWidgetLifeCycle<TWidgetDescription extends WidgetDescription> = {
|
|
|
60
75
|
* Called once before the first search.
|
|
61
76
|
*/
|
|
62
77
|
init?: (options: InitOptions) => void;
|
|
78
|
+
/**
|
|
79
|
+
* Whether `render` should be called
|
|
80
|
+
*/
|
|
81
|
+
shouldRender?: (options: ShouldRenderOptions) => boolean;
|
|
63
82
|
/**
|
|
64
83
|
* Called after each search response has been received.
|
|
65
84
|
*/
|
|
@@ -116,7 +135,7 @@ type RequiredUiStateLifeCycle<TWidgetDescription extends WidgetDescription> = {
|
|
|
116
135
|
getWidgetSearchParameters: (state: SearchParameters, widgetSearchParametersOptions: {
|
|
117
136
|
uiState: Expand<Partial<TWidgetDescription['indexUiState'] & IndexUiState>>;
|
|
118
137
|
}) => SearchParameters;
|
|
119
|
-
};
|
|
138
|
+
} & (SearchWidgetLifeCycle<TWidgetDescription> | RecommendWidgetLifeCycle<TWidgetDescription>);
|
|
120
139
|
type UiStateLifeCycle<TWidgetDescription extends WidgetDescription> = TWidgetDescription extends RequiredKeys<WidgetDescription, 'indexUiState'> ? RequiredUiStateLifeCycle<TWidgetDescription> : Partial<RequiredUiStateLifeCycle<TWidgetDescription>>;
|
|
121
140
|
type RequiredRenderStateLifeCycle<TWidgetDescription extends WidgetDescription & WidgetParams> = {
|
|
122
141
|
/**
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
import type { HitsConnectorParams, HitsWidgetDescription } from '../../connectors/hits/connectHits';
|
|
2
|
+
import type { HitsConnectorParams, HitsRenderState, HitsWidgetDescription } from '../../connectors/hits/connectHits';
|
|
3
3
|
import type { Template, TemplateWithBindEvent, Hit, WidgetFactory } from '../../types';
|
|
4
4
|
import type { SearchResults } from 'algoliasearch-helper';
|
|
5
5
|
import type { HitsClassNames as HitsUiComponentClassNames } from 'instantsearch-ui-components';
|
|
@@ -20,6 +20,13 @@ export type HitsTemplates = Partial<{
|
|
|
20
20
|
/** @deprecated the index in the hits array, use __position instead, which is the absolute position */
|
|
21
21
|
__hitIndex: number;
|
|
22
22
|
}>;
|
|
23
|
+
/**
|
|
24
|
+
* Template to use for the banner.
|
|
25
|
+
*/
|
|
26
|
+
banner: Template<{
|
|
27
|
+
banner: Required<HitsRenderState['banner']>;
|
|
28
|
+
className: string;
|
|
29
|
+
}>;
|
|
23
30
|
}>;
|
|
24
31
|
export type HitsWidgetParams = {
|
|
25
32
|
/**
|
package/es/widgets/hits/hits.js
CHANGED
|
@@ -36,7 +36,8 @@ var renderer = function renderer(_ref) {
|
|
|
36
36
|
instantSearchInstance = _ref2.instantSearchInstance,
|
|
37
37
|
insights = _ref2.insights,
|
|
38
38
|
bindEvent = _ref2.bindEvent,
|
|
39
|
-
sendEvent = _ref2.sendEvent
|
|
39
|
+
sendEvent = _ref2.sendEvent,
|
|
40
|
+
banner = _ref2.banner;
|
|
40
41
|
if (isFirstRendering) {
|
|
41
42
|
renderState.templateProps = prepareTemplateProps({
|
|
42
43
|
defaultTemplates: defaultTemplates,
|
|
@@ -54,7 +55,8 @@ var renderer = function renderer(_ref) {
|
|
|
54
55
|
return h(TemplateComponent, _extends({}, renderState.templateProps, {
|
|
55
56
|
rootProps: rootProps,
|
|
56
57
|
templateKey: "empty",
|
|
57
|
-
data: results
|
|
58
|
+
data: results,
|
|
59
|
+
rootTagName: "fragment"
|
|
58
60
|
}));
|
|
59
61
|
};
|
|
60
62
|
|
|
@@ -87,12 +89,21 @@ var renderer = function renderer(_ref) {
|
|
|
87
89
|
sendEvent: sendEvent
|
|
88
90
|
}));
|
|
89
91
|
};
|
|
92
|
+
var bannerComponent = function bannerComponent(props) {
|
|
93
|
+
return h(TemplateComponent, _extends({}, renderState.templateProps, {
|
|
94
|
+
templateKey: "banner",
|
|
95
|
+
data: props,
|
|
96
|
+
rootTagName: "fragment"
|
|
97
|
+
}));
|
|
98
|
+
};
|
|
90
99
|
render(h(Hits, {
|
|
91
100
|
hits: receivedHits,
|
|
92
101
|
itemComponent: itemComponent,
|
|
93
102
|
sendEvent: sendEvent,
|
|
94
103
|
classNames: cssClasses,
|
|
95
|
-
emptyComponent: emptyComponent
|
|
104
|
+
emptyComponent: emptyComponent,
|
|
105
|
+
banner: banner,
|
|
106
|
+
bannerComponent: templates.banner ? bannerComponent : undefined
|
|
96
107
|
}), containerNode);
|
|
97
108
|
};
|
|
98
109
|
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
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
|
-
var _excluded = ["initialSearchParameters"]
|
|
2
|
+
var _excluded = ["initialSearchParameters"],
|
|
3
|
+
_excluded2 = ["initialRecommendParameters"];
|
|
3
4
|
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; }
|
|
4
5
|
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; }
|
|
5
6
|
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; }
|
|
@@ -25,6 +26,7 @@ var withUsage = createDocumentationMessageGenerator({
|
|
|
25
26
|
*/
|
|
26
27
|
function privateHelperSetState(helper, _ref) {
|
|
27
28
|
var state = _ref.state,
|
|
29
|
+
recommendState = _ref.recommendState,
|
|
28
30
|
isPageReset = _ref.isPageReset,
|
|
29
31
|
_uiState = _ref._uiState;
|
|
30
32
|
if (state !== helper.state) {
|
|
@@ -36,7 +38,14 @@ function privateHelperSetState(helper, _ref) {
|
|
|
36
38
|
_uiState: _uiState
|
|
37
39
|
});
|
|
38
40
|
}
|
|
41
|
+
if (recommendState !== helper.recommendState) {
|
|
42
|
+
helper.recommendState = recommendState;
|
|
43
|
+
|
|
44
|
+
// eslint-disable-next-line no-warning-comments
|
|
45
|
+
// TODO: emit "change" event when events for Recommend are implemented
|
|
46
|
+
}
|
|
39
47
|
}
|
|
48
|
+
|
|
40
49
|
function getLocalWidgetsUiState(widgets, widgetStateOptions) {
|
|
41
50
|
var initialUiState = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
42
51
|
return widgets.reduce(function (uiState, widget) {
|
|
@@ -55,15 +64,26 @@ function getLocalWidgetsUiState(widgets, widgetStateOptions) {
|
|
|
55
64
|
function getLocalWidgetsSearchParameters(widgets, widgetSearchParametersOptions) {
|
|
56
65
|
var initialSearchParameters = widgetSearchParametersOptions.initialSearchParameters,
|
|
57
66
|
rest = _objectWithoutProperties(widgetSearchParametersOptions, _excluded);
|
|
58
|
-
return widgets.
|
|
59
|
-
|
|
60
|
-
}).reduce(function (state, widget) {
|
|
61
|
-
if (!widget.getWidgetSearchParameters) {
|
|
67
|
+
return widgets.reduce(function (state, widget) {
|
|
68
|
+
if (!widget.getWidgetSearchParameters || isIndexWidget(widget)) {
|
|
62
69
|
return state;
|
|
63
70
|
}
|
|
71
|
+
if (widget.dependsOn === 'search' && widget.getWidgetParameters) {
|
|
72
|
+
return widget.getWidgetParameters(state, rest);
|
|
73
|
+
}
|
|
64
74
|
return widget.getWidgetSearchParameters(state, rest);
|
|
65
75
|
}, initialSearchParameters);
|
|
66
76
|
}
|
|
77
|
+
function getLocalWidgetsRecommendParameters(widgets, widgetRecommendParametersOptions) {
|
|
78
|
+
var initialRecommendParameters = widgetRecommendParametersOptions.initialRecommendParameters,
|
|
79
|
+
rest = _objectWithoutProperties(widgetRecommendParametersOptions, _excluded2);
|
|
80
|
+
return widgets.reduce(function (state, widget) {
|
|
81
|
+
if (!isIndexWidget(widget) && widget.dependsOn === 'recommend' && widget.getWidgetParameters) {
|
|
82
|
+
return widget.getWidgetParameters(state, rest);
|
|
83
|
+
}
|
|
84
|
+
return state;
|
|
85
|
+
}, initialRecommendParameters);
|
|
86
|
+
}
|
|
67
87
|
function resetPageFromWidgets(widgets) {
|
|
68
88
|
var indexWidgets = widgets.filter(isIndexWidget);
|
|
69
89
|
if (indexWidgets.length === 0) {
|
|
@@ -73,6 +93,7 @@ function resetPageFromWidgets(widgets) {
|
|
|
73
93
|
var widgetHelper = widget.getHelper();
|
|
74
94
|
privateHelperSetState(widgetHelper, {
|
|
75
95
|
state: widgetHelper.state.resetPage(),
|
|
96
|
+
recommendState: widgetHelper.recommendState,
|
|
76
97
|
isPageReset: true
|
|
77
98
|
});
|
|
78
99
|
resetPageFromWidgets(widget.getWidgets());
|
|
@@ -131,9 +152,18 @@ var index = function index(widgetParams) {
|
|
|
131
152
|
},
|
|
132
153
|
getScopedResults: function getScopedResults() {
|
|
133
154
|
var widgetParent = this.getParent();
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
155
|
+
var widgetSiblings;
|
|
156
|
+
if (widgetParent) {
|
|
157
|
+
widgetSiblings = widgetParent.getWidgets();
|
|
158
|
+
} else if (indexName.length === 0) {
|
|
159
|
+
// The widget is the root but has no index name:
|
|
160
|
+
// we resolve results from its children index widgets
|
|
161
|
+
widgetSiblings = this.getWidgets();
|
|
162
|
+
} else {
|
|
163
|
+
// The widget is the root and has an index name:
|
|
164
|
+
// we consider itself as the only sibling
|
|
165
|
+
widgetSiblings = [this];
|
|
166
|
+
}
|
|
137
167
|
return resolveScopedResultsFromWidgets(widgetSiblings);
|
|
138
168
|
},
|
|
139
169
|
getParent: function getParent() {
|
|
@@ -168,6 +198,10 @@ var index = function index(widgetParams) {
|
|
|
168
198
|
uiState: localUiState,
|
|
169
199
|
initialSearchParameters: helper.state
|
|
170
200
|
}),
|
|
201
|
+
recommendState: getLocalWidgetsRecommendParameters(localWidgets, {
|
|
202
|
+
uiState: localUiState,
|
|
203
|
+
initialRecommendParameters: helper.recommendState
|
|
204
|
+
}),
|
|
171
205
|
_uiState: localUiState
|
|
172
206
|
});
|
|
173
207
|
|
|
@@ -264,11 +298,16 @@ var index = function index(widgetParams) {
|
|
|
264
298
|
index: indexName
|
|
265
299
|
})
|
|
266
300
|
});
|
|
301
|
+
var recommendParameters = getLocalWidgetsRecommendParameters(localWidgets, {
|
|
302
|
+
uiState: localUiState,
|
|
303
|
+
initialRecommendParameters: new algoliasearchHelper.RecommendParameters()
|
|
304
|
+
});
|
|
267
305
|
|
|
268
306
|
// This Helper is only used for state management we do not care about the
|
|
269
307
|
// `searchClient`. Only the "main" Helper created at the `InstantSearch`
|
|
270
308
|
// level is aware of the client.
|
|
271
309
|
helper = algoliasearchHelper({}, parameters.index, parameters);
|
|
310
|
+
helper.recommendState = recommendParameters;
|
|
272
311
|
|
|
273
312
|
// We forward the call to `search` to the "main" instance of the Helper
|
|
274
313
|
// which is responsible for managing the queries (it's the only one that is
|
|
@@ -299,6 +338,8 @@ var index = function index(widgetParams) {
|
|
|
299
338
|
};
|
|
300
339
|
derivedHelper = mainHelper.derive(function () {
|
|
301
340
|
return mergeSearchParameters.apply(void 0, [mainHelper.state].concat(_toConsumableArray(resolveSearchParameters(_this3))));
|
|
341
|
+
}, function () {
|
|
342
|
+
return _this3.getHelper().recommendState;
|
|
302
343
|
});
|
|
303
344
|
var indexInitialResults = (_instantSearchInstanc = instantSearchInstance._initialResults) === null || _instantSearchInstanc === void 0 ? void 0 : _instantSearchInstanc[this.getIndexId()];
|
|
304
345
|
if (indexInitialResults) {
|
|
@@ -347,6 +388,21 @@ var index = function index(widgetParams) {
|
|
|
347
388
|
lastValidSearchParameters = results === null || results === void 0 ? void 0 : results._state;
|
|
348
389
|
});
|
|
349
390
|
|
|
391
|
+
// eslint-disable-next-line no-warning-comments
|
|
392
|
+
// TODO: listen to "result" event when events for Recommend are implemented
|
|
393
|
+
derivedHelper.on('recommend:result', function (_ref5) {
|
|
394
|
+
var recommend = _ref5.recommend;
|
|
395
|
+
// The index does not render the results it schedules a new render
|
|
396
|
+
// to let all the other indices emit their own results. It allows us to
|
|
397
|
+
// run the render process in one pass.
|
|
398
|
+
instantSearchInstance.scheduleRender();
|
|
399
|
+
|
|
400
|
+
// the derived helper is the one which actually searches, but the helper
|
|
401
|
+
// which is exposed e.g. via instance.helper, doesn't search, and thus
|
|
402
|
+
// does not have access to lastRecommendResults.
|
|
403
|
+
helper.lastRecommendResults = recommend.results;
|
|
404
|
+
});
|
|
405
|
+
|
|
350
406
|
// We compute the render state before calling `init` in a separate loop
|
|
351
407
|
// to construct the whole render state object that is then passed to
|
|
352
408
|
// `init`.
|
|
@@ -397,9 +453,9 @@ var index = function index(widgetParams) {
|
|
|
397
453
|
instantSearchInstance.scheduleRender();
|
|
398
454
|
}
|
|
399
455
|
},
|
|
400
|
-
render: function render(
|
|
456
|
+
render: function render(_ref6) {
|
|
401
457
|
var _this4 = this;
|
|
402
|
-
var instantSearchInstance =
|
|
458
|
+
var instantSearchInstance = _ref6.instantSearchInstance;
|
|
403
459
|
// we can't attach a listener to the error event of search, as the error
|
|
404
460
|
// then would no longer be thrown for global handlers.
|
|
405
461
|
if (instantSearchInstance.status === 'error' && !instantSearchInstance.mainHelper.hasPendingRequests() && lastValidSearchParameters) {
|
|
@@ -409,6 +465,14 @@ var index = function index(widgetParams) {
|
|
|
409
465
|
// We only render index widgets if there are no results.
|
|
410
466
|
// This makes sure `render` is never called with `results` being `null`.
|
|
411
467
|
var widgetsToRender = this.getResults() ? localWidgets : localWidgets.filter(isIndexWidget);
|
|
468
|
+
widgetsToRender = widgetsToRender.filter(function (widget) {
|
|
469
|
+
if (!widget.shouldRender) {
|
|
470
|
+
return true;
|
|
471
|
+
}
|
|
472
|
+
return widget.shouldRender({
|
|
473
|
+
instantSearchInstance: instantSearchInstance
|
|
474
|
+
});
|
|
475
|
+
});
|
|
412
476
|
widgetsToRender.forEach(function (widget) {
|
|
413
477
|
if (widget.getRenderState) {
|
|
414
478
|
var renderState = widget.getRenderState(instantSearchInstance.renderState[_this4.getIndexId()] || {}, createRenderArgs(instantSearchInstance, _this4));
|
|
@@ -467,8 +531,8 @@ var index = function index(widgetParams) {
|
|
|
467
531
|
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;
|
|
468
532
|
return this.getWidgetUiState(uiState);
|
|
469
533
|
},
|
|
470
|
-
getWidgetSearchParameters: function getWidgetSearchParameters(searchParameters,
|
|
471
|
-
var uiState =
|
|
534
|
+
getWidgetSearchParameters: function getWidgetSearchParameters(searchParameters, _ref7) {
|
|
535
|
+
var uiState = _ref7.uiState;
|
|
472
536
|
return getLocalWidgetsSearchParameters(localWidgets, {
|
|
473
537
|
uiState: uiState,
|
|
474
538
|
initialSearchParameters: searchParameters
|
|
@@ -489,10 +553,10 @@ var index = function index(widgetParams) {
|
|
|
489
553
|
};
|
|
490
554
|
};
|
|
491
555
|
export default index;
|
|
492
|
-
function storeRenderState(
|
|
493
|
-
var renderState =
|
|
494
|
-
instantSearchInstance =
|
|
495
|
-
parent =
|
|
556
|
+
function storeRenderState(_ref8) {
|
|
557
|
+
var renderState = _ref8.renderState,
|
|
558
|
+
instantSearchInstance = _ref8.instantSearchInstance,
|
|
559
|
+
parent = _ref8.parent;
|
|
496
560
|
var parentIndexName = parent ? parent.getIndexId() : instantSearchInstance.mainIndex.getIndexId();
|
|
497
561
|
instantSearchInstance.renderState = _objectSpread(_objectSpread({}, instantSearchInstance.renderState), {}, _defineProperty({}, parentIndexName, _objectSpread(_objectSpread({}, instantSearchInstance.renderState[parentIndexName]), renderState)));
|
|
498
562
|
}
|
|
@@ -80,7 +80,7 @@ export type PanelWidgetParams<TWidgetFactory extends AnyWidgetFactory> = {
|
|
|
80
80
|
*/
|
|
81
81
|
cssClasses?: PanelCSSClasses;
|
|
82
82
|
};
|
|
83
|
-
type AugmentedWidget<TWidgetFactory extends AnyWidgetFactory, TOverriddenKeys extends keyof Widget = 'init' | 'render' | 'dispose'> = Omit<ReturnType<TWidgetFactory>, TOverriddenKeys> & Pick<Required<Widget>, TOverriddenKeys>;
|
|
83
|
+
type AugmentedWidget<TWidgetFactory extends AnyWidgetFactory, TOverriddenKeys extends keyof Widget = 'init' | 'render' | 'dispose'> = Omit<ReturnType<TWidgetFactory>, TOverriddenKeys | 'dependsOn' | 'getWidgetParameters'> & Pick<Required<Widget>, TOverriddenKeys>;
|
|
84
84
|
export type PanelWidget = <TWidgetFactory extends AnyWidgetFactory>(panelWidgetParams?: PanelWidgetParams<TWidgetFactory>) => (widgetFactory: TWidgetFactory) => (widgetParams: Parameters<TWidgetFactory>[0]) => AugmentedWidget<TWidgetFactory>;
|
|
85
85
|
/**
|
|
86
86
|
* The panel widget wraps other widgets in a consistent panel design.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "instantsearch.js",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.68.0",
|
|
4
4
|
"description": "InstantSearch.js is a JavaScript library for building performant and instant search experiences with Algolia.",
|
|
5
5
|
"homepage": "https://www.algolia.com/doc/guides/building-search-ui/what-is-instantsearch/js/",
|
|
6
6
|
"types": "es/index.d.ts",
|
|
@@ -31,10 +31,10 @@
|
|
|
31
31
|
"@types/google.maps": "^3.45.3",
|
|
32
32
|
"@types/hogan.js": "^3.0.0",
|
|
33
33
|
"@types/qs": "^6.5.3",
|
|
34
|
-
"algoliasearch-helper": "3.
|
|
34
|
+
"algoliasearch-helper": "3.19.0",
|
|
35
35
|
"hogan.js": "^3.0.2",
|
|
36
36
|
"htm": "^3.0.0",
|
|
37
|
-
"instantsearch-ui-components": "0.
|
|
37
|
+
"instantsearch-ui-components": "0.5.0",
|
|
38
38
|
"preact": "^10.10.0",
|
|
39
39
|
"qs": "^6.5.1 < 6.10",
|
|
40
40
|
"search-insights": "^2.13.0"
|
|
@@ -56,15 +56,15 @@
|
|
|
56
56
|
"watch:es": "yarn --silent build:es:base --watch"
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|
|
59
|
-
"@instantsearch/mocks": "1.
|
|
60
|
-
"@instantsearch/tests": "1.
|
|
61
|
-
"@instantsearch/testutils": "1.
|
|
59
|
+
"@instantsearch/mocks": "1.42.0",
|
|
60
|
+
"@instantsearch/tests": "1.42.0",
|
|
61
|
+
"@instantsearch/testutils": "1.31.0",
|
|
62
62
|
"@storybook/html": "5.3.9",
|
|
63
63
|
"@types/scriptjs": "0.0.2",
|
|
64
|
-
"algoliasearch": "4.
|
|
64
|
+
"algoliasearch": "4.23.2",
|
|
65
65
|
"places.js": "1.17.1",
|
|
66
66
|
"scriptjs": "2.5.9",
|
|
67
67
|
"webpack": "4.47.0"
|
|
68
68
|
},
|
|
69
|
-
"gitHead": "
|
|
69
|
+
"gitHead": "68fe2ee8544096eff8c2fbafe01a50a8acbca2b9"
|
|
70
70
|
}
|