instantsearch.js 4.37.3 → 4.39.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/CHANGELOG.md +32 -0
- package/cjs/connectors/breadcrumb/connectBreadcrumb.js +3 -1
- package/cjs/connectors/clear-refinements/connectClearRefinements.js +11 -6
- package/cjs/connectors/current-refinements/connectCurrentRefinements.js +6 -2
- package/cjs/connectors/geo-search/connectGeoSearch.js +3 -1
- package/cjs/connectors/hierarchical-menu/connectHierarchicalMenu.js +3 -1
- package/cjs/connectors/hits/connectHits.js +3 -1
- package/cjs/connectors/hits-per-page/connectHitsPerPage.js +3 -1
- package/cjs/connectors/infinite-hits/connectInfiniteHits.js +5 -2
- package/cjs/connectors/menu/connectMenu.js +3 -1
- package/cjs/connectors/numeric-menu/connectNumericMenu.js +5 -3
- package/cjs/connectors/query-rules/connectQueryRules.js +3 -1
- package/cjs/connectors/refinement-list/connectRefinementList.js +8 -3
- package/cjs/connectors/sort-by/connectSortBy.js +3 -1
- package/cjs/lib/routers/history.js +44 -29
- package/cjs/lib/version.js +1 -1
- package/cjs/middlewares/createMetadataMiddleware.js +3 -1
- package/dist/instantsearch.development.d.ts +60 -43
- package/dist/instantsearch.development.js +108 -56
- package/dist/instantsearch.development.js.map +1 -1
- package/dist/instantsearch.production.d.ts +60 -43
- package/dist/instantsearch.production.min.d.ts +60 -43
- package/dist/instantsearch.production.min.js +2 -2
- package/dist/instantsearch.production.min.js.map +1 -1
- package/es/components/ToggleRefinement/ToggleRefinement.d.ts +3 -0
- package/es/components/ToggleRefinement/ToggleRefinement.js +4 -0
- package/es/connectors/breadcrumb/connectBreadcrumb.js +3 -1
- package/es/connectors/clear-refinements/connectClearRefinements.js +11 -6
- package/es/connectors/current-refinements/connectCurrentRefinements.js +6 -2
- package/es/connectors/dynamic-widgets/connectDynamicWidgets.d.ts +4 -5
- package/es/connectors/geo-search/connectGeoSearch.js +3 -1
- package/es/connectors/hierarchical-menu/connectHierarchicalMenu.js +3 -1
- package/es/connectors/hits/connectHits.d.ts +10 -10
- package/es/connectors/hits/connectHits.js +3 -1
- package/es/connectors/hits/connectHitsWithInsights.d.ts +1 -1
- package/es/connectors/hits-per-page/connectHitsPerPage.js +3 -1
- package/es/connectors/infinite-hits/connectInfiniteHits.d.ts +21 -21
- package/es/connectors/infinite-hits/connectInfiniteHits.js +5 -2
- package/es/connectors/infinite-hits/connectInfiniteHitsWithInsights.d.ts +1 -1
- package/es/connectors/menu/connectMenu.js +3 -1
- package/es/connectors/numeric-menu/connectNumericMenu.js +5 -3
- package/es/connectors/query-rules/connectQueryRules.d.ts +1 -2
- package/es/connectors/query-rules/connectQueryRules.js +3 -1
- package/es/connectors/refinement-list/connectRefinementList.js +8 -3
- package/es/connectors/sort-by/connectSortBy.js +3 -1
- package/es/lib/routers/history.d.ts +11 -0
- package/es/lib/routers/history.js +44 -29
- package/es/lib/utils/createSendEventForHits.d.ts +3 -0
- package/es/lib/utils/createSendEventForHits.js +3 -0
- package/es/lib/version.d.ts +1 -1
- package/es/lib/version.js +1 -1
- package/es/middlewares/createMetadataMiddleware.js +3 -1
- package/es/types/results.d.ts +8 -5
- package/es/types/widget.d.ts +4 -1
- package/package.json +4 -4
- package/dist/instantsearch.development.min.d.ts +0 -5246
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
function _extends() { _extends = Object.assign || 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); }
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* @jest-environment jsdom
|
|
5
|
+
*/
|
|
6
|
+
|
|
3
7
|
/** @jsx h */
|
|
4
8
|
import { h } from 'preact';
|
|
5
9
|
import Template from "../Template/Template.js";
|
|
@@ -98,7 +98,9 @@ var connectBreadcrumb = function connectBreadcrumb(renderFn) {
|
|
|
98
98
|
|
|
99
99
|
var facetValues = results.getFacetValues(facetName, {});
|
|
100
100
|
var data = Array.isArray(facetValues.data) ? facetValues.data : [];
|
|
101
|
-
var items = transformItems(shiftItemsValues(prepareItems(data))
|
|
101
|
+
var items = transformItems(shiftItemsValues(prepareItems(data)), {
|
|
102
|
+
results: results
|
|
103
|
+
});
|
|
102
104
|
return items;
|
|
103
105
|
}
|
|
104
106
|
|
|
@@ -80,13 +80,15 @@ var connectClearRefinements = function connectClearRefinements(renderFn) {
|
|
|
80
80
|
},
|
|
81
81
|
getWidgetRenderState: function getWidgetRenderState(_ref2) {
|
|
82
82
|
var createURL = _ref2.createURL,
|
|
83
|
-
scopedResults = _ref2.scopedResults
|
|
84
|
-
|
|
85
|
-
|
|
83
|
+
scopedResults = _ref2.scopedResults,
|
|
84
|
+
results = _ref2.results;
|
|
85
|
+
connectorState.attributesToClear = scopedResults.reduce(function (attributesToClear, scopedResult) {
|
|
86
|
+
return attributesToClear.concat(getAttributesToClear({
|
|
86
87
|
scopedResult: scopedResult,
|
|
87
88
|
includedAttributes: includedAttributes,
|
|
88
89
|
excludedAttributes: excludedAttributes,
|
|
89
|
-
transformItems: transformItems
|
|
90
|
+
transformItems: transformItems,
|
|
91
|
+
results: results
|
|
90
92
|
}));
|
|
91
93
|
}, []);
|
|
92
94
|
|
|
@@ -131,7 +133,8 @@ function getAttributesToClear(_ref5) {
|
|
|
131
133
|
var scopedResult = _ref5.scopedResult,
|
|
132
134
|
includedAttributes = _ref5.includedAttributes,
|
|
133
135
|
excludedAttributes = _ref5.excludedAttributes,
|
|
134
|
-
transformItems = _ref5.transformItems
|
|
136
|
+
transformItems = _ref5.transformItems,
|
|
137
|
+
results = _ref5.results;
|
|
135
138
|
var includesQuery = includedAttributes.indexOf('query') !== -1 || excludedAttributes.indexOf('query') === -1;
|
|
136
139
|
return {
|
|
137
140
|
helper: scopedResult.helper,
|
|
@@ -147,7 +150,9 @@ function getAttributesToClear(_ref5) {
|
|
|
147
150
|
attribute === 'query' && includesQuery || // Otherwise, ignore the excluded attributes
|
|
148
151
|
excludedAttributes.indexOf(attribute) === -1
|
|
149
152
|
);
|
|
150
|
-
}))
|
|
153
|
+
})), {
|
|
154
|
+
results: results
|
|
155
|
+
})
|
|
151
156
|
};
|
|
152
157
|
}
|
|
153
158
|
|
|
@@ -74,7 +74,9 @@ var connectCurrentRefinements = function connectCurrentRefinements(renderFn) {
|
|
|
74
74
|
helper: helper,
|
|
75
75
|
includedAttributes: includedAttributes,
|
|
76
76
|
excludedAttributes: excludedAttributes
|
|
77
|
-
})
|
|
77
|
+
}), {
|
|
78
|
+
results: results
|
|
79
|
+
});
|
|
78
80
|
}
|
|
79
81
|
|
|
80
82
|
return scopedResults.reduce(function (accResults, scopedResult) {
|
|
@@ -83,7 +85,9 @@ var connectCurrentRefinements = function connectCurrentRefinements(renderFn) {
|
|
|
83
85
|
helper: scopedResult.helper,
|
|
84
86
|
includedAttributes: includedAttributes,
|
|
85
87
|
excludedAttributes: excludedAttributes
|
|
86
|
-
})
|
|
88
|
+
}), {
|
|
89
|
+
results: results
|
|
90
|
+
}));
|
|
87
91
|
}, []);
|
|
88
92
|
}
|
|
89
93
|
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { Connector, Widget } from '../../types';
|
|
1
|
+
import type { Connector, TransformItems, TransformItemsMetadata, Widget } from '../../types';
|
|
3
2
|
export declare type DynamicWidgetsRenderState = {
|
|
4
3
|
attributesToRender: string[];
|
|
5
4
|
};
|
|
@@ -20,9 +19,9 @@ export declare type DynamicWidgetsConnectorParams = {
|
|
|
20
19
|
* Function to transform the items to render.
|
|
21
20
|
* The function also exposes the full search response.
|
|
22
21
|
*/
|
|
23
|
-
transformItems
|
|
24
|
-
results:
|
|
25
|
-
}
|
|
22
|
+
transformItems?: TransformItems<string, Omit<TransformItemsMetadata, 'results'> & {
|
|
23
|
+
results: NonNullable<TransformItemsMetadata['results']>;
|
|
24
|
+
}>;
|
|
26
25
|
/**
|
|
27
26
|
* To prevent unneeded extra network requests when widgets mount or unmount,
|
|
28
27
|
* we request all facet values.
|
|
@@ -161,7 +161,9 @@ var connectGeoSearch = function connectGeoSearch(renderFn) {
|
|
|
161
161
|
var state = helper.state;
|
|
162
162
|
var items = results ? transformItems(results.hits.filter(function (hit) {
|
|
163
163
|
return hit._geoloc;
|
|
164
|
-
})
|
|
164
|
+
}), {
|
|
165
|
+
results: results
|
|
166
|
+
}) : [];
|
|
165
167
|
|
|
166
168
|
if (!sendEvent) {
|
|
167
169
|
sendEvent = createSendEventForHits({
|
|
@@ -192,7 +192,9 @@ var connectHierarchicalMenu = function connectHierarchicalMenu(renderFn) {
|
|
|
192
192
|
|
|
193
193
|
var hasExhaustiveItems = (state.maxValuesPerFacet || 0) > getLimit() ? facetItems.length <= getLimit() : facetItems.length < getLimit();
|
|
194
194
|
canToggleShowMore = showMore && (isShowingMore || !hasExhaustiveItems);
|
|
195
|
-
items = transformItems(_prepareFacetValues(facetItems)
|
|
195
|
+
items = transformItems(_prepareFacetValues(facetItems), {
|
|
196
|
+
results: results
|
|
197
|
+
});
|
|
196
198
|
}
|
|
197
199
|
|
|
198
200
|
return {
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import type { SendEventForHits, BindEventForHits } from '../../lib/utils';
|
|
2
|
-
import type { TransformItems, Connector,
|
|
2
|
+
import type { TransformItems, Connector, Hit, WidgetRenderState, BaseHit } from '../../types';
|
|
3
3
|
import type { SearchResults } from 'algoliasearch-helper';
|
|
4
|
-
export declare type HitsRenderState = {
|
|
4
|
+
export declare type HitsRenderState<THit extends BaseHit = BaseHit> = {
|
|
5
5
|
/**
|
|
6
6
|
* The matched hits from Algolia API.
|
|
7
7
|
*/
|
|
8
|
-
hits:
|
|
8
|
+
hits: Array<Hit<THit>>;
|
|
9
9
|
/**
|
|
10
10
|
* The response from the Algolia API.
|
|
11
11
|
*/
|
|
12
|
-
results?: SearchResults<Hit
|
|
12
|
+
results?: SearchResults<Hit<THit>>;
|
|
13
13
|
/**
|
|
14
14
|
* Sends an event to the Insights middleware.
|
|
15
15
|
*/
|
|
@@ -19,7 +19,7 @@ export declare type HitsRenderState = {
|
|
|
19
19
|
*/
|
|
20
20
|
bindEvent: BindEventForHits;
|
|
21
21
|
};
|
|
22
|
-
export declare type HitsConnectorParams = {
|
|
22
|
+
export declare type HitsConnectorParams<THit extends BaseHit = BaseHit> = {
|
|
23
23
|
/**
|
|
24
24
|
* Whether to escape HTML tags from hits string values.
|
|
25
25
|
*
|
|
@@ -29,15 +29,15 @@ export declare type HitsConnectorParams = {
|
|
|
29
29
|
/**
|
|
30
30
|
* Function to transform the items passed to the templates.
|
|
31
31
|
*/
|
|
32
|
-
transformItems?: TransformItems<Hit
|
|
32
|
+
transformItems?: TransformItems<Hit<THit>>;
|
|
33
33
|
};
|
|
34
|
-
export declare type HitsWidgetDescription = {
|
|
34
|
+
export declare type HitsWidgetDescription<THit extends BaseHit = BaseHit> = {
|
|
35
35
|
$$type: 'ais.hits';
|
|
36
|
-
renderState: HitsRenderState
|
|
36
|
+
renderState: HitsRenderState<THit>;
|
|
37
37
|
indexRenderState: {
|
|
38
|
-
hits: WidgetRenderState<HitsRenderState
|
|
38
|
+
hits: WidgetRenderState<HitsRenderState<THit>, HitsConnectorParams<THit>>;
|
|
39
39
|
};
|
|
40
40
|
};
|
|
41
|
-
export declare type HitsConnector = Connector<HitsWidgetDescription
|
|
41
|
+
export declare type HitsConnector<THit extends BaseHit = BaseHit> = Connector<HitsWidgetDescription<THit>, HitsConnectorParams<THit>>;
|
|
42
42
|
declare const connectHits: HitsConnector;
|
|
43
43
|
export default connectHits;
|
|
@@ -79,7 +79,9 @@ var connectHits = function connectHits(renderFn) {
|
|
|
79
79
|
|
|
80
80
|
var hitsWithAbsolutePosition = addAbsolutePosition(results.hits, results.page, results.hitsPerPage);
|
|
81
81
|
var hitsWithAbsolutePositionAndQueryID = addQueryID(hitsWithAbsolutePosition, results.queryID);
|
|
82
|
-
var transformedHits = transformItems(hitsWithAbsolutePositionAndQueryID
|
|
82
|
+
var transformedHits = transformItems(hitsWithAbsolutePositionAndQueryID, {
|
|
83
|
+
results: results
|
|
84
|
+
});
|
|
83
85
|
return {
|
|
84
86
|
hits: transformedHits,
|
|
85
87
|
results: results,
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const connectHitsWithInsights: import("./connectHits").HitsConnector
|
|
1
|
+
declare const connectHitsWithInsights: import("./connectHits").HitsConnector<import("../../types").BaseHit>;
|
|
2
2
|
export default connectHitsWithInsights;
|
|
@@ -120,7 +120,9 @@ var connectHitsPerPage = function connectHitsPerPage(renderFn) {
|
|
|
120
120
|
createURL = _ref5.createURL,
|
|
121
121
|
helper = _ref5.helper;
|
|
122
122
|
return {
|
|
123
|
-
items: transformItems(normalizeItems(state)
|
|
123
|
+
items: transformItems(normalizeItems(state), {
|
|
124
|
+
results: results
|
|
125
|
+
}),
|
|
124
126
|
refine: connectorState.getRefine(helper),
|
|
125
127
|
createURL: connectorState.createURLFactory({
|
|
126
128
|
state: state,
|
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
import type { PlainSearchParameters, SearchResults } from 'algoliasearch-helper';
|
|
2
|
-
import type {
|
|
2
|
+
import type { Connector, TransformItems, Hit, WidgetRenderState, BaseHit } from '../../types';
|
|
3
3
|
import type { SendEventForHits, BindEventForHits } from '../../lib/utils';
|
|
4
|
-
export declare type InfiniteHitsCachedHits = {
|
|
5
|
-
[page: number]:
|
|
4
|
+
export declare type InfiniteHitsCachedHits<THit extends BaseHit> = {
|
|
5
|
+
[page: number]: Array<Hit<THit>>;
|
|
6
6
|
};
|
|
7
|
-
declare type Read = ({ state, }: {
|
|
7
|
+
declare type Read<THit extends BaseHit> = ({ state, }: {
|
|
8
8
|
state: PlainSearchParameters;
|
|
9
|
-
}) => InfiniteHitsCachedHits | null;
|
|
10
|
-
declare type Write = ({ state, hits, }: {
|
|
9
|
+
}) => InfiniteHitsCachedHits<THit> | null;
|
|
10
|
+
declare type Write<THit extends BaseHit> = ({ state, hits, }: {
|
|
11
11
|
state: PlainSearchParameters;
|
|
12
|
-
hits: InfiniteHitsCachedHits
|
|
12
|
+
hits: InfiniteHitsCachedHits<THit>;
|
|
13
13
|
}) => void;
|
|
14
|
-
export declare type InfiniteHitsCache = {
|
|
15
|
-
read: Read
|
|
16
|
-
write: Write
|
|
14
|
+
export declare type InfiniteHitsCache<THit extends BaseHit = BaseHit> = {
|
|
15
|
+
read: Read<THit>;
|
|
16
|
+
write: Write<THit>;
|
|
17
17
|
};
|
|
18
|
-
export declare type InfiniteHitsConnectorParams = {
|
|
18
|
+
export declare type InfiniteHitsConnectorParams<THit extends BaseHit = BaseHit> = {
|
|
19
19
|
/**
|
|
20
20
|
* Escapes HTML entities from hits string values.
|
|
21
21
|
*
|
|
@@ -32,15 +32,15 @@ export declare type InfiniteHitsConnectorParams = {
|
|
|
32
32
|
* Receives the items, and is called before displaying them.
|
|
33
33
|
* Useful for mapping over the items to transform, and remove or reorder them.
|
|
34
34
|
*/
|
|
35
|
-
transformItems?: TransformItems<Hit
|
|
35
|
+
transformItems?: TransformItems<Hit<THit>>;
|
|
36
36
|
/**
|
|
37
37
|
* Reads and writes hits from/to cache.
|
|
38
38
|
* When user comes back to the search page after leaving for product page,
|
|
39
39
|
* this helps restore InfiniteHits and its scroll position.
|
|
40
40
|
*/
|
|
41
|
-
cache?: InfiniteHitsCache
|
|
41
|
+
cache?: InfiniteHitsCache<THit>;
|
|
42
42
|
};
|
|
43
|
-
export declare type InfiniteHitsRenderState = {
|
|
43
|
+
export declare type InfiniteHitsRenderState<THit extends BaseHit = BaseHit> = {
|
|
44
44
|
/**
|
|
45
45
|
* Loads the previous results.
|
|
46
46
|
*/
|
|
@@ -68,26 +68,26 @@ export declare type InfiniteHitsRenderState = {
|
|
|
68
68
|
/**
|
|
69
69
|
* Hits for the current page
|
|
70
70
|
*/
|
|
71
|
-
currentPageHits:
|
|
71
|
+
currentPageHits: Array<Hit<THit>>;
|
|
72
72
|
/**
|
|
73
73
|
* Hits for current and cached pages
|
|
74
74
|
*/
|
|
75
|
-
hits:
|
|
75
|
+
hits: Array<Hit<THit>>;
|
|
76
76
|
/**
|
|
77
77
|
* The response from the Algolia API.
|
|
78
78
|
*/
|
|
79
|
-
results?: SearchResults<Hit
|
|
79
|
+
results?: SearchResults<Hit<THit>>;
|
|
80
80
|
};
|
|
81
|
-
export declare type InfiniteHitsWidgetDescription = {
|
|
81
|
+
export declare type InfiniteHitsWidgetDescription<THit extends BaseHit = BaseHit> = {
|
|
82
82
|
$$type: 'ais.infiniteHits';
|
|
83
|
-
renderState: InfiniteHitsRenderState
|
|
83
|
+
renderState: InfiniteHitsRenderState<THit>;
|
|
84
84
|
indexRenderState: {
|
|
85
|
-
infiniteHits: WidgetRenderState<InfiniteHitsRenderState
|
|
85
|
+
infiniteHits: WidgetRenderState<InfiniteHitsRenderState<THit>, InfiniteHitsConnectorParams<THit>>;
|
|
86
86
|
};
|
|
87
87
|
indexUiState: {
|
|
88
88
|
page: number;
|
|
89
89
|
};
|
|
90
90
|
};
|
|
91
|
-
export declare type InfiniteHitsConnector = Connector<InfiniteHitsWidgetDescription
|
|
91
|
+
export declare type InfiniteHitsConnector<THit extends BaseHit = BaseHit> = Connector<InfiniteHitsWidgetDescription<THit>, InfiniteHitsConnectorParams<THit>>;
|
|
92
92
|
declare const connectInfiniteHits: InfiniteHitsConnector;
|
|
93
93
|
export default connectInfiniteHits;
|
|
@@ -61,7 +61,8 @@ function extractHitsFromCachedHits(cachedHits) {
|
|
|
61
61
|
|
|
62
62
|
var connectInfiniteHits = function connectInfiniteHits(renderFn) {
|
|
63
63
|
var unmountFn = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : noop;
|
|
64
|
-
checkRendering(renderFn, withUsage());
|
|
64
|
+
checkRendering(renderFn, withUsage()); // @TODO: this should be a generic, but a Connector can not yet be generic itself
|
|
65
|
+
|
|
65
66
|
return function (widgetParams) {
|
|
66
67
|
var _ref4 = widgetParams || {},
|
|
67
68
|
_ref4$escapeHTML = _ref4.escapeHTML,
|
|
@@ -176,7 +177,9 @@ var connectInfiniteHits = function connectInfiniteHits(renderFn) {
|
|
|
176
177
|
|
|
177
178
|
var hitsWithAbsolutePosition = addAbsolutePosition(results.hits, results.page, results.hitsPerPage);
|
|
178
179
|
var hitsWithAbsolutePositionAndQueryID = addQueryID(hitsWithAbsolutePosition, results.queryID);
|
|
179
|
-
var transformedHits = transformItems(hitsWithAbsolutePositionAndQueryID
|
|
180
|
+
var transformedHits = transformItems(hitsWithAbsolutePositionAndQueryID, {
|
|
181
|
+
results: results
|
|
182
|
+
});
|
|
180
183
|
|
|
181
184
|
if (cachedHits[_page] === undefined) {
|
|
182
185
|
cachedHits[_page] = transformedHits;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const connectInfiniteHitsWithInsights: import("./connectInfiniteHits").InfiniteHitsConnector
|
|
1
|
+
declare const connectInfiniteHitsWithInsights: import("./connectInfiniteHits").InfiniteHitsConnector<import("../../types").BaseHit>;
|
|
2
2
|
export default connectInfiniteHitsWithInsights;
|
|
@@ -78,8 +78,8 @@ var connectNumericMenu = function connectNumericMenu(renderFn) {
|
|
|
78
78
|
_ref2$items = _ref2.items,
|
|
79
79
|
items = _ref2$items === void 0 ? [] : _ref2$items,
|
|
80
80
|
_ref2$transformItems = _ref2.transformItems,
|
|
81
|
-
transformItems = _ref2$transformItems === void 0 ? function (
|
|
82
|
-
return
|
|
81
|
+
transformItems = _ref2$transformItems === void 0 ? function (item) {
|
|
82
|
+
return item;
|
|
83
83
|
} : _ref2$transformItems;
|
|
84
84
|
|
|
85
85
|
if (attribute === '') {
|
|
@@ -216,7 +216,9 @@ var connectNumericMenu = function connectNumericMenu(renderFn) {
|
|
|
216
216
|
|
|
217
217
|
return {
|
|
218
218
|
createURL: connectorState.createURL(state),
|
|
219
|
-
items: transformItems(prepareItems(state)
|
|
219
|
+
items: transformItems(prepareItems(state), {
|
|
220
|
+
results: results
|
|
221
|
+
}),
|
|
220
222
|
hasNoResults: results ? results.nbHits === 0 : true,
|
|
221
223
|
refine: connectorState.refine,
|
|
222
224
|
sendEvent: connectorState.sendEvent,
|
|
@@ -4,11 +4,10 @@ export declare type ParamTrackedFilters = {
|
|
|
4
4
|
[facetName: string]: (facetValues: TrackedFilterRefinement[]) => TrackedFilterRefinement[];
|
|
5
5
|
};
|
|
6
6
|
export declare type ParamTransformRuleContexts = (ruleContexts: string[]) => string[];
|
|
7
|
-
declare type ParamTransformItems = TransformItems<any>;
|
|
8
7
|
export declare type QueryRulesConnectorParams = {
|
|
9
8
|
trackedFilters?: ParamTrackedFilters;
|
|
10
9
|
transformRuleContexts?: ParamTransformRuleContexts;
|
|
11
|
-
transformItems?:
|
|
10
|
+
transformItems?: TransformItems<any>;
|
|
12
11
|
};
|
|
13
12
|
export declare type QueryRulesRenderState = {
|
|
14
13
|
items: any[];
|
|
@@ -152,7 +152,9 @@ var connectQueryRules = function connectQueryRules(_render) {
|
|
|
152
152
|
_ref4$userData = _ref4.userData,
|
|
153
153
|
userData = _ref4$userData === void 0 ? [] : _ref4$userData;
|
|
154
154
|
|
|
155
|
-
var items = transformItems(userData
|
|
155
|
+
var items = transformItems(userData, {
|
|
156
|
+
results: results
|
|
157
|
+
});
|
|
156
158
|
return {
|
|
157
159
|
items: items,
|
|
158
160
|
widgetParams: widgetParams
|
|
@@ -105,7 +105,8 @@ var connectRefinementList = function connectRefinementList(renderFn) {
|
|
|
105
105
|
var createSearchForFacetValues = function createSearchForFacetValues(helper, widget) {
|
|
106
106
|
return function (renderOptions) {
|
|
107
107
|
return function (query) {
|
|
108
|
-
var instantSearchInstance = renderOptions.instantSearchInstance
|
|
108
|
+
var instantSearchInstance = renderOptions.instantSearchInstance,
|
|
109
|
+
searchResults = renderOptions.results;
|
|
109
110
|
|
|
110
111
|
if (query === '' && lastItemsFromMainSearch) {
|
|
111
112
|
// render with previous data from the helper.
|
|
@@ -132,7 +133,9 @@ var connectRefinementList = function connectRefinementList(renderFn) {
|
|
|
132
133
|
value: value,
|
|
133
134
|
label: value
|
|
134
135
|
});
|
|
135
|
-
})
|
|
136
|
+
}), {
|
|
137
|
+
results: searchResults
|
|
138
|
+
});
|
|
136
139
|
renderFn(_objectSpread(_objectSpread({}, widget.getWidgetRenderState(_objectSpread(_objectSpread({}, renderOptions), {}, {
|
|
137
140
|
results: lastResultsFromMainSearch
|
|
138
141
|
}))), {}, {
|
|
@@ -196,7 +199,9 @@ var connectRefinementList = function connectRefinementList(renderFn) {
|
|
|
196
199
|
facetOrdering: sortBy === DEFAULT_SORT
|
|
197
200
|
});
|
|
198
201
|
facetValues = values && Array.isArray(values) ? values : [];
|
|
199
|
-
items = transformItems(facetValues.slice(0, getLimit()).map(formatItems)
|
|
202
|
+
items = transformItems(facetValues.slice(0, getLimit()).map(formatItems), {
|
|
203
|
+
results: results
|
|
204
|
+
});
|
|
200
205
|
var maxValuesPerFacetConfig = state.maxValuesPerFacet;
|
|
201
206
|
var currentLimit = getLimit(); // If the limit is the max number of facet retrieved it is impossible to know
|
|
202
207
|
// if the facets are exhaustive. The only moment we are sure it is exhaustive
|
|
@@ -79,7 +79,9 @@ var connectSortBy = function connectSortBy(renderFn) {
|
|
|
79
79
|
|
|
80
80
|
return {
|
|
81
81
|
currentRefinement: state.index,
|
|
82
|
-
options: transformItems(items
|
|
82
|
+
options: transformItems(items, {
|
|
83
|
+
results: results
|
|
84
|
+
}),
|
|
83
85
|
refine: connectorState.setIndex,
|
|
84
86
|
hasNoResults: results ? results.nbHits === 0 : true,
|
|
85
87
|
widgetParams: widgetParams
|
|
@@ -51,6 +51,17 @@ declare class BrowserHistory<TRouteState> implements Router<TRouteState> {
|
|
|
51
51
|
* It needs to avoid pushing state to history in case of back/forward in browser
|
|
52
52
|
*/
|
|
53
53
|
private shouldPushState;
|
|
54
|
+
/**
|
|
55
|
+
* Indicates whether the history router is disposed or not.
|
|
56
|
+
*/
|
|
57
|
+
private isDisposed;
|
|
58
|
+
/**
|
|
59
|
+
* Indicates the window.history.length before the last call to
|
|
60
|
+
* window.history.pushState (called in `write`).
|
|
61
|
+
* It allows to determine if a `pushState` has been triggered elsewhere,
|
|
62
|
+
* and thus to prevent the `write` method from calling `pushState`.
|
|
63
|
+
*/
|
|
64
|
+
private latestAcknowledgedHistory;
|
|
54
65
|
/**
|
|
55
66
|
* Initializes a new storage provider that syncs the search state to the URL
|
|
56
67
|
* using web APIs (`window.location.pushState` and `onpopstate` event).
|
|
@@ -48,16 +48,23 @@ var BrowserHistory = /*#__PURE__*/function () {
|
|
|
48
48
|
|
|
49
49
|
_defineProperty(this, "shouldPushState", true);
|
|
50
50
|
|
|
51
|
+
_defineProperty(this, "isDisposed", false);
|
|
52
|
+
|
|
53
|
+
_defineProperty(this, "latestAcknowledgedHistory", 0);
|
|
54
|
+
|
|
51
55
|
this.windowTitle = windowTitle;
|
|
52
56
|
this.writeTimer = undefined;
|
|
53
57
|
this.writeDelay = writeDelay;
|
|
54
58
|
this._createURL = createURL;
|
|
55
59
|
this.parseURL = parseURL;
|
|
56
60
|
this.getLocation = getLocation;
|
|
57
|
-
safelyRunOnBrowser(function () {
|
|
61
|
+
safelyRunOnBrowser(function (_ref2) {
|
|
62
|
+
var window = _ref2.window;
|
|
63
|
+
|
|
58
64
|
var title = _this.windowTitle && _this.windowTitle(_this.read());
|
|
59
65
|
|
|
60
66
|
setWindowTitle(title);
|
|
67
|
+
_this.latestAcknowledgedHistory = window.history.length;
|
|
61
68
|
});
|
|
62
69
|
}
|
|
63
70
|
/**
|
|
@@ -82,8 +89,8 @@ var BrowserHistory = /*#__PURE__*/function () {
|
|
|
82
89
|
value: function write(routeState) {
|
|
83
90
|
var _this2 = this;
|
|
84
91
|
|
|
85
|
-
safelyRunOnBrowser(function (
|
|
86
|
-
var window =
|
|
92
|
+
safelyRunOnBrowser(function (_ref3) {
|
|
93
|
+
var window = _ref3.window;
|
|
87
94
|
|
|
88
95
|
var url = _this2.createURL(routeState);
|
|
89
96
|
|
|
@@ -94,10 +101,17 @@ var BrowserHistory = /*#__PURE__*/function () {
|
|
|
94
101
|
}
|
|
95
102
|
|
|
96
103
|
_this2.writeTimer = setTimeout(function () {
|
|
97
|
-
setWindowTitle(title);
|
|
104
|
+
setWindowTitle(title); // We do want to `pushState` if:
|
|
105
|
+
// - the router is not disposed, IS.js needs to update the URL
|
|
106
|
+
// OR
|
|
107
|
+
// - the last write was from InstantSearch.js
|
|
108
|
+
// (unlike a SPA, where it would have last written)
|
|
109
|
+
|
|
110
|
+
var lastPushWasByISAfterDispose = !_this2.isDisposed || _this2.latestAcknowledgedHistory === window.history.length;
|
|
98
111
|
|
|
99
|
-
if (_this2.shouldPushState) {
|
|
112
|
+
if (_this2.shouldPushState && lastPushWasByISAfterDispose) {
|
|
100
113
|
window.history.pushState(routeState, title || '', url);
|
|
114
|
+
_this2.latestAcknowledgedHistory = window.history.length;
|
|
101
115
|
}
|
|
102
116
|
|
|
103
117
|
_this2.shouldPushState = true;
|
|
@@ -133,8 +147,8 @@ var BrowserHistory = /*#__PURE__*/function () {
|
|
|
133
147
|
}
|
|
134
148
|
};
|
|
135
149
|
|
|
136
|
-
safelyRunOnBrowser(function (
|
|
137
|
-
var window =
|
|
150
|
+
safelyRunOnBrowser(function (_ref4) {
|
|
151
|
+
var window = _ref4.window;
|
|
138
152
|
window.addEventListener('popstate', _this3._onPopState);
|
|
139
153
|
});
|
|
140
154
|
}
|
|
@@ -164,8 +178,9 @@ var BrowserHistory = /*#__PURE__*/function () {
|
|
|
164
178
|
value: function dispose() {
|
|
165
179
|
var _this4 = this;
|
|
166
180
|
|
|
167
|
-
|
|
168
|
-
|
|
181
|
+
this.isDisposed = true;
|
|
182
|
+
safelyRunOnBrowser(function (_ref5) {
|
|
183
|
+
var window = _ref5.window;
|
|
169
184
|
|
|
170
185
|
if (_this4._onPopState) {
|
|
171
186
|
window.removeEventListener('popstate', _this4._onPopState);
|
|
@@ -184,12 +199,12 @@ var BrowserHistory = /*#__PURE__*/function () {
|
|
|
184
199
|
}();
|
|
185
200
|
|
|
186
201
|
export default function historyRouter() {
|
|
187
|
-
var
|
|
188
|
-
|
|
189
|
-
createURL =
|
|
190
|
-
var qsModule =
|
|
191
|
-
routeState =
|
|
192
|
-
location =
|
|
202
|
+
var _ref6 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
203
|
+
_ref6$createURL = _ref6.createURL,
|
|
204
|
+
createURL = _ref6$createURL === void 0 ? function (_ref7) {
|
|
205
|
+
var qsModule = _ref7.qsModule,
|
|
206
|
+
routeState = _ref7.routeState,
|
|
207
|
+
location = _ref7.location;
|
|
193
208
|
var protocol = location.protocol,
|
|
194
209
|
hostname = location.hostname,
|
|
195
210
|
_location$port = location.port,
|
|
@@ -205,11 +220,11 @@ export default function historyRouter() {
|
|
|
205
220
|
}
|
|
206
221
|
|
|
207
222
|
return "".concat(protocol, "//").concat(hostname).concat(portWithPrefix).concat(pathname, "?").concat(queryString).concat(hash);
|
|
208
|
-
} :
|
|
209
|
-
|
|
210
|
-
parseURL =
|
|
211
|
-
var qsModule =
|
|
212
|
-
location =
|
|
223
|
+
} : _ref6$createURL,
|
|
224
|
+
_ref6$parseURL = _ref6.parseURL,
|
|
225
|
+
parseURL = _ref6$parseURL === void 0 ? function (_ref8) {
|
|
226
|
+
var qsModule = _ref8.qsModule,
|
|
227
|
+
location = _ref8.location;
|
|
213
228
|
// `qs` by default converts arrays with more than 20 items to an object.
|
|
214
229
|
// We want to avoid this because the data structure manipulated can therefore vary.
|
|
215
230
|
// Setting the limit to `100` seems a good number because the engine's default is 100
|
|
@@ -223,21 +238,21 @@ export default function historyRouter() {
|
|
|
223
238
|
return qsModule.parse(location.search.slice(1), {
|
|
224
239
|
arrayLimit: 99
|
|
225
240
|
});
|
|
226
|
-
} :
|
|
227
|
-
|
|
228
|
-
writeDelay =
|
|
229
|
-
windowTitle =
|
|
230
|
-
|
|
231
|
-
getLocation =
|
|
232
|
-
return safelyRunOnBrowser(function (
|
|
233
|
-
var window =
|
|
241
|
+
} : _ref6$parseURL,
|
|
242
|
+
_ref6$writeDelay = _ref6.writeDelay,
|
|
243
|
+
writeDelay = _ref6$writeDelay === void 0 ? 400 : _ref6$writeDelay,
|
|
244
|
+
windowTitle = _ref6.windowTitle,
|
|
245
|
+
_ref6$getLocation = _ref6.getLocation,
|
|
246
|
+
getLocation = _ref6$getLocation === void 0 ? function () {
|
|
247
|
+
return safelyRunOnBrowser(function (_ref9) {
|
|
248
|
+
var window = _ref9.window;
|
|
234
249
|
return window.location;
|
|
235
250
|
}, {
|
|
236
251
|
fallback: function fallback() {
|
|
237
252
|
throw new Error('You need to provide `getLocation` to the `history` router in environments where `window` does not exist.');
|
|
238
253
|
}
|
|
239
254
|
});
|
|
240
|
-
} :
|
|
255
|
+
} : _ref6$getLocation;
|
|
241
256
|
|
|
242
257
|
return new BrowserHistory({
|
|
243
258
|
createURL: createURL,
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @jest-environment jsdom
|
|
3
|
+
*/
|
|
1
4
|
import type { InstantSearch, Hit, Hits } from '../../types';
|
|
2
5
|
declare type BuiltInSendEventForHits = (eventType: string, hits: Hit | Hits, eventName?: string) => void;
|
|
3
6
|
declare type CustomSendEventForHits = (customPayload: any) => void;
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* @jest-environment jsdom
|
|
5
|
+
*/
|
|
3
6
|
import { serializePayload } from "./serializer.js";
|
|
4
7
|
|
|
5
8
|
function chunk(arr) {
|
package/es/lib/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default: "4.
|
|
1
|
+
declare const _default: "4.39.0";
|
|
2
2
|
export default _default;
|
package/es/lib/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export default '4.
|
|
1
|
+
export default '4.39.0';
|
|
@@ -46,8 +46,10 @@ function extractPayload(widgets, instantSearchInstance, payload) {
|
|
|
46
46
|
|
|
47
47
|
export function isMetadataEnabled() {
|
|
48
48
|
return safelyRunOnBrowser(function (_ref) {
|
|
49
|
+
var _window$navigator, _window$navigator$use;
|
|
50
|
+
|
|
49
51
|
var window = _ref.window;
|
|
50
|
-
return window.navigator.userAgent.indexOf('Algolia Crawler') > -1;
|
|
52
|
+
return ((_window$navigator = window.navigator) === null || _window$navigator === void 0 ? void 0 : (_window$navigator$use = _window$navigator.userAgent) === null || _window$navigator$use === void 0 ? void 0 : _window$navigator$use.indexOf('Algolia Crawler')) > -1;
|
|
51
53
|
}, {
|
|
52
54
|
fallback: function fallback() {
|
|
53
55
|
return false;
|