instantsearch.js 4.37.1 → 4.38.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.
- package/CHANGELOG.md +41 -0
- package/cjs/components/Hits/Hits.js +0 -6
- package/cjs/components/Pagination/Pagination.js +60 -41
- package/cjs/connectors/breadcrumb/connectBreadcrumb.js +6 -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 +3 -1
- 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/search-box/connectSearchBox.js +15 -25
- package/cjs/connectors/sort-by/connectSortBy.js +3 -1
- package/cjs/helpers/highlight.js +4 -1
- package/cjs/helpers/reverseHighlight.js +4 -1
- package/cjs/helpers/reverseSnippet.js +4 -1
- package/cjs/helpers/snippet.js +4 -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 +56 -14
- package/dist/instantsearch.development.js +194 -171
- package/dist/instantsearch.development.js.map +1 -1
- package/dist/instantsearch.production.d.ts +56 -14
- package/dist/instantsearch.production.min.d.ts +56 -14
- package/dist/instantsearch.production.min.js +2 -2
- package/dist/instantsearch.production.min.js.map +1 -1
- package/es/components/Hits/Hits.d.ts +1 -9
- package/es/components/Hits/Hits.js +0 -6
- package/es/components/Pagination/Pagination.d.ts +3 -10
- package/es/components/Pagination/Pagination.js +55 -34
- package/es/connectors/breadcrumb/connectBreadcrumb.js +6 -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.js +3 -1
- package/es/connectors/hits-per-page/connectHitsPerPage.js +3 -1
- package/es/connectors/infinite-hits/connectInfiniteHits.js +3 -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/search-box/connectSearchBox.js +15 -25
- package/es/connectors/sort-by/connectSortBy.js +3 -1
- package/es/connectors/toggle-refinement/connectToggleRefinement.d.ts +36 -7
- package/es/helpers/highlight.js +5 -2
- package/es/helpers/reverseHighlight.js +5 -2
- package/es/helpers/reverseSnippet.js +5 -2
- package/es/helpers/snippet.js +5 -2
- package/es/lib/routers/history.d.ts +11 -0
- package/es/lib/routers/history.js +44 -29
- 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/widget.d.ts +4 -1
- package/package.json +3 -3
- package/cjs/components/Pagination/PaginationLink.js +0 -60
- package/dist/instantsearch.development.min.d.ts +0 -5217
- package/es/components/Pagination/PaginationLink.d.ts +0 -16
- package/es/components/Pagination/PaginationLink.js +0 -49
|
@@ -58,16 +58,23 @@ var BrowserHistory = /*#__PURE__*/function () {
|
|
|
58
58
|
|
|
59
59
|
_defineProperty(this, "shouldPushState", true);
|
|
60
60
|
|
|
61
|
+
_defineProperty(this, "isDisposed", false);
|
|
62
|
+
|
|
63
|
+
_defineProperty(this, "latestAcknowledgedHistory", 0);
|
|
64
|
+
|
|
61
65
|
this.windowTitle = windowTitle;
|
|
62
66
|
this.writeTimer = undefined;
|
|
63
67
|
this.writeDelay = writeDelay;
|
|
64
68
|
this._createURL = createURL;
|
|
65
69
|
this.parseURL = parseURL;
|
|
66
70
|
this.getLocation = getLocation;
|
|
67
|
-
(0, _index.safelyRunOnBrowser)(function () {
|
|
71
|
+
(0, _index.safelyRunOnBrowser)(function (_ref2) {
|
|
72
|
+
var window = _ref2.window;
|
|
73
|
+
|
|
68
74
|
var title = _this.windowTitle && _this.windowTitle(_this.read());
|
|
69
75
|
|
|
70
76
|
setWindowTitle(title);
|
|
77
|
+
_this.latestAcknowledgedHistory = window.history.length;
|
|
71
78
|
});
|
|
72
79
|
}
|
|
73
80
|
/**
|
|
@@ -92,8 +99,8 @@ var BrowserHistory = /*#__PURE__*/function () {
|
|
|
92
99
|
value: function write(routeState) {
|
|
93
100
|
var _this2 = this;
|
|
94
101
|
|
|
95
|
-
(0, _index.safelyRunOnBrowser)(function (
|
|
96
|
-
var window =
|
|
102
|
+
(0, _index.safelyRunOnBrowser)(function (_ref3) {
|
|
103
|
+
var window = _ref3.window;
|
|
97
104
|
|
|
98
105
|
var url = _this2.createURL(routeState);
|
|
99
106
|
|
|
@@ -104,10 +111,17 @@ var BrowserHistory = /*#__PURE__*/function () {
|
|
|
104
111
|
}
|
|
105
112
|
|
|
106
113
|
_this2.writeTimer = setTimeout(function () {
|
|
107
|
-
setWindowTitle(title);
|
|
114
|
+
setWindowTitle(title); // We do want to `pushState` if:
|
|
115
|
+
// - the router is not disposed, IS.js needs to update the URL
|
|
116
|
+
// OR
|
|
117
|
+
// - the last write was from InstantSearch.js
|
|
118
|
+
// (unlike a SPA, where it would have last written)
|
|
119
|
+
|
|
120
|
+
var lastPushWasByISAfterDispose = !_this2.isDisposed || _this2.latestAcknowledgedHistory === window.history.length;
|
|
108
121
|
|
|
109
|
-
if (_this2.shouldPushState) {
|
|
122
|
+
if (_this2.shouldPushState && lastPushWasByISAfterDispose) {
|
|
110
123
|
window.history.pushState(routeState, title || '', url);
|
|
124
|
+
_this2.latestAcknowledgedHistory = window.history.length;
|
|
111
125
|
}
|
|
112
126
|
|
|
113
127
|
_this2.shouldPushState = true;
|
|
@@ -143,8 +157,8 @@ var BrowserHistory = /*#__PURE__*/function () {
|
|
|
143
157
|
}
|
|
144
158
|
};
|
|
145
159
|
|
|
146
|
-
(0, _index.safelyRunOnBrowser)(function (
|
|
147
|
-
var window =
|
|
160
|
+
(0, _index.safelyRunOnBrowser)(function (_ref4) {
|
|
161
|
+
var window = _ref4.window;
|
|
148
162
|
window.addEventListener('popstate', _this3._onPopState);
|
|
149
163
|
});
|
|
150
164
|
}
|
|
@@ -174,8 +188,9 @@ var BrowserHistory = /*#__PURE__*/function () {
|
|
|
174
188
|
value: function dispose() {
|
|
175
189
|
var _this4 = this;
|
|
176
190
|
|
|
177
|
-
|
|
178
|
-
|
|
191
|
+
this.isDisposed = true;
|
|
192
|
+
(0, _index.safelyRunOnBrowser)(function (_ref5) {
|
|
193
|
+
var window = _ref5.window;
|
|
179
194
|
|
|
180
195
|
if (_this4._onPopState) {
|
|
181
196
|
window.removeEventListener('popstate', _this4._onPopState);
|
|
@@ -194,12 +209,12 @@ var BrowserHistory = /*#__PURE__*/function () {
|
|
|
194
209
|
}();
|
|
195
210
|
|
|
196
211
|
function historyRouter() {
|
|
197
|
-
var
|
|
198
|
-
|
|
199
|
-
createURL =
|
|
200
|
-
var qsModule =
|
|
201
|
-
routeState =
|
|
202
|
-
location =
|
|
212
|
+
var _ref6 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
213
|
+
_ref6$createURL = _ref6.createURL,
|
|
214
|
+
createURL = _ref6$createURL === void 0 ? function (_ref7) {
|
|
215
|
+
var qsModule = _ref7.qsModule,
|
|
216
|
+
routeState = _ref7.routeState,
|
|
217
|
+
location = _ref7.location;
|
|
203
218
|
var protocol = location.protocol,
|
|
204
219
|
hostname = location.hostname,
|
|
205
220
|
_location$port = location.port,
|
|
@@ -215,11 +230,11 @@ function historyRouter() {
|
|
|
215
230
|
}
|
|
216
231
|
|
|
217
232
|
return "".concat(protocol, "//").concat(hostname).concat(portWithPrefix).concat(pathname, "?").concat(queryString).concat(hash);
|
|
218
|
-
} :
|
|
219
|
-
|
|
220
|
-
parseURL =
|
|
221
|
-
var qsModule =
|
|
222
|
-
location =
|
|
233
|
+
} : _ref6$createURL,
|
|
234
|
+
_ref6$parseURL = _ref6.parseURL,
|
|
235
|
+
parseURL = _ref6$parseURL === void 0 ? function (_ref8) {
|
|
236
|
+
var qsModule = _ref8.qsModule,
|
|
237
|
+
location = _ref8.location;
|
|
223
238
|
// `qs` by default converts arrays with more than 20 items to an object.
|
|
224
239
|
// We want to avoid this because the data structure manipulated can therefore vary.
|
|
225
240
|
// Setting the limit to `100` seems a good number because the engine's default is 100
|
|
@@ -233,21 +248,21 @@ function historyRouter() {
|
|
|
233
248
|
return qsModule.parse(location.search.slice(1), {
|
|
234
249
|
arrayLimit: 99
|
|
235
250
|
});
|
|
236
|
-
} :
|
|
237
|
-
|
|
238
|
-
writeDelay =
|
|
239
|
-
windowTitle =
|
|
240
|
-
|
|
241
|
-
getLocation =
|
|
242
|
-
return (0, _index.safelyRunOnBrowser)(function (
|
|
243
|
-
var window =
|
|
251
|
+
} : _ref6$parseURL,
|
|
252
|
+
_ref6$writeDelay = _ref6.writeDelay,
|
|
253
|
+
writeDelay = _ref6$writeDelay === void 0 ? 400 : _ref6$writeDelay,
|
|
254
|
+
windowTitle = _ref6.windowTitle,
|
|
255
|
+
_ref6$getLocation = _ref6.getLocation,
|
|
256
|
+
getLocation = _ref6$getLocation === void 0 ? function () {
|
|
257
|
+
return (0, _index.safelyRunOnBrowser)(function (_ref9) {
|
|
258
|
+
var window = _ref9.window;
|
|
244
259
|
return window.location;
|
|
245
260
|
}, {
|
|
246
261
|
fallback: function fallback() {
|
|
247
262
|
throw new Error('You need to provide `getLocation` to the `history` router in environments where `window` does not exist.');
|
|
248
263
|
}
|
|
249
264
|
});
|
|
250
|
-
} :
|
|
265
|
+
} : _ref6$getLocation;
|
|
251
266
|
|
|
252
267
|
return new BrowserHistory({
|
|
253
268
|
createURL: createURL,
|
package/cjs/lib/version.js
CHANGED
|
@@ -54,8 +54,10 @@ function extractPayload(widgets, instantSearchInstance, payload) {
|
|
|
54
54
|
|
|
55
55
|
function isMetadataEnabled() {
|
|
56
56
|
return (0, _index.safelyRunOnBrowser)(function (_ref) {
|
|
57
|
+
var _window$navigator, _window$navigator$use;
|
|
58
|
+
|
|
57
59
|
var window = _ref.window;
|
|
58
|
-
return window.navigator.userAgent.indexOf('Algolia Crawler') > -1;
|
|
60
|
+
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;
|
|
59
61
|
}, {
|
|
60
62
|
fallback: function fallback() {
|
|
61
63
|
return false;
|
|
@@ -466,6 +466,17 @@ declare class BrowserHistory<TRouteState> implements Router<TRouteState> {
|
|
|
466
466
|
* It needs to avoid pushing state to history in case of back/forward in browser
|
|
467
467
|
*/
|
|
468
468
|
private shouldPushState;
|
|
469
|
+
/**
|
|
470
|
+
* Indicates whether the history router is disposed or not.
|
|
471
|
+
*/
|
|
472
|
+
private isDisposed;
|
|
473
|
+
/**
|
|
474
|
+
* Indicates the window.history.length before the last call to
|
|
475
|
+
* window.history.pushState (called in `write`).
|
|
476
|
+
* It allows to determine if a `pushState` has been triggered elsewhere,
|
|
477
|
+
* and thus to prevent the `write` method from calling `pushState`.
|
|
478
|
+
*/
|
|
479
|
+
private latestAcknowledgedHistory;
|
|
469
480
|
/**
|
|
470
481
|
* Initializes a new storage provider that syncs the search state to the URL
|
|
471
482
|
* using web APIs (`window.location.pushState` and `onpopstate` event).
|
|
@@ -1098,9 +1109,9 @@ declare type DynamicWidgetsConnectorParams = {
|
|
|
1098
1109
|
* Function to transform the items to render.
|
|
1099
1110
|
* The function also exposes the full search response.
|
|
1100
1111
|
*/
|
|
1101
|
-
transformItems
|
|
1102
|
-
results:
|
|
1103
|
-
}
|
|
1112
|
+
transformItems?: TransformItems<string, Omit<TransformItemsMetadata, 'results'> & {
|
|
1113
|
+
results: NonNullable<TransformItemsMetadata['results']>;
|
|
1114
|
+
}>;
|
|
1104
1115
|
/**
|
|
1105
1116
|
* To prevent unneeded extra network requests when widgets mount or unmount,
|
|
1106
1117
|
* we request all facet values.
|
|
@@ -3203,8 +3214,6 @@ declare type ParamTrackedFilters = {
|
|
|
3203
3214
|
[facetName: string]: (facetValues: TrackedFilterRefinement[]) => TrackedFilterRefinement[];
|
|
3204
3215
|
};
|
|
3205
3216
|
|
|
3206
|
-
declare type ParamTransformItems = TransformItems<any>;
|
|
3207
|
-
|
|
3208
3217
|
declare type ParamTransformRuleContexts = (ruleContexts: string[]) => string[];
|
|
3209
3218
|
|
|
3210
3219
|
declare type ParseURL<TRouteState> = (args: {
|
|
@@ -3345,7 +3354,7 @@ declare type QueryRulesConnector = Connector<QueryRulesWidgetDescription, QueryR
|
|
|
3345
3354
|
declare type QueryRulesConnectorParams = {
|
|
3346
3355
|
trackedFilters?: ParamTrackedFilters;
|
|
3347
3356
|
transformRuleContexts?: ParamTransformRuleContexts;
|
|
3348
|
-
transformItems?:
|
|
3357
|
+
transformItems?: TransformItems<any>;
|
|
3349
3358
|
};
|
|
3350
3359
|
|
|
3351
3360
|
declare type QueryRulesRenderState = {
|
|
@@ -4915,7 +4924,9 @@ declare const toggleRefinement: ToggleRefinementWidget;
|
|
|
4915
4924
|
declare type ToggleRefinementConnector = Connector<ToggleRefinementWidgetDescription, ToggleRefinementConnectorParams>;
|
|
4916
4925
|
|
|
4917
4926
|
declare type ToggleRefinementConnectorParams = {
|
|
4918
|
-
/**
|
|
4927
|
+
/**
|
|
4928
|
+
* Name of the attribute for faceting (e.g., "free_shipping").
|
|
4929
|
+
*/
|
|
4919
4930
|
attribute: string;
|
|
4920
4931
|
/**
|
|
4921
4932
|
* Value to filter on when toggled.
|
|
@@ -4950,19 +4961,42 @@ declare type ToggleRefinementCSSClasses = Partial<{
|
|
|
4950
4961
|
declare type ToggleRefinementRenderState = {
|
|
4951
4962
|
/** The current toggle value */
|
|
4952
4963
|
value: {
|
|
4964
|
+
/**
|
|
4965
|
+
* The attribute name of this toggle.
|
|
4966
|
+
*/
|
|
4953
4967
|
name: string;
|
|
4968
|
+
/**
|
|
4969
|
+
* Whether the current option is "on" (true) or "off" (false)
|
|
4970
|
+
*/
|
|
4954
4971
|
isRefined: boolean;
|
|
4972
|
+
/**
|
|
4973
|
+
* Number of results if this option is toggled.
|
|
4974
|
+
*/
|
|
4955
4975
|
count: number | null;
|
|
4976
|
+
/**
|
|
4977
|
+
* Information about the "on" toggle.
|
|
4978
|
+
*/
|
|
4956
4979
|
onFacetValue: ToggleRefinementValue;
|
|
4980
|
+
/**
|
|
4981
|
+
* Information about the "off" toggle.
|
|
4982
|
+
*/
|
|
4957
4983
|
offFacetValue: ToggleRefinementValue;
|
|
4958
4984
|
};
|
|
4959
|
-
/**
|
|
4985
|
+
/**
|
|
4986
|
+
* Creates an URL for the next state.
|
|
4987
|
+
*/
|
|
4960
4988
|
createURL: CreateURL<string>;
|
|
4961
|
-
/**
|
|
4989
|
+
/**
|
|
4990
|
+
* Send a "Facet Clicked" Insights event.
|
|
4991
|
+
*/
|
|
4962
4992
|
sendEvent: SendEventForToggle;
|
|
4963
|
-
/**
|
|
4993
|
+
/**
|
|
4994
|
+
* Indicates if search state can be refined.
|
|
4995
|
+
*/
|
|
4964
4996
|
canRefine: boolean;
|
|
4965
|
-
/**
|
|
4997
|
+
/**
|
|
4998
|
+
* Updates to the next state by applying the toggle refinement.
|
|
4999
|
+
*/
|
|
4966
5000
|
refine: (value?: {
|
|
4967
5001
|
isRefined: boolean;
|
|
4968
5002
|
}) => void;
|
|
@@ -4976,9 +5010,13 @@ declare type ToggleRefinementTemplates = Partial<{
|
|
|
4976
5010
|
}>;
|
|
4977
5011
|
|
|
4978
5012
|
declare type ToggleRefinementValue = {
|
|
4979
|
-
/**
|
|
5013
|
+
/**
|
|
5014
|
+
* Whether this option is enabled.
|
|
5015
|
+
*/
|
|
4980
5016
|
isRefined: boolean;
|
|
4981
|
-
/**
|
|
5017
|
+
/**
|
|
5018
|
+
* Number of result if this option is toggled.
|
|
5019
|
+
*/
|
|
4982
5020
|
count: number | null;
|
|
4983
5021
|
};
|
|
4984
5022
|
|
|
@@ -5021,7 +5059,11 @@ declare type TrackedFilterRefinement = string | number | boolean;
|
|
|
5021
5059
|
/**
|
|
5022
5060
|
* Transforms the given items.
|
|
5023
5061
|
*/
|
|
5024
|
-
declare type TransformItems<TItem> = (items: TItem[]) => TItem[];
|
|
5062
|
+
declare type TransformItems<TItem, TMetadata = TransformItemsMetadata> = (items: TItem[], metadata: TMetadata) => TItem[];
|
|
5063
|
+
|
|
5064
|
+
declare type TransformItemsMetadata = {
|
|
5065
|
+
results?: SearchResults;
|
|
5066
|
+
};
|
|
5025
5067
|
|
|
5026
5068
|
declare type TransformSearchParameters = (searchParameters: SearchParameters) => PlainSearchParameters;
|
|
5027
5069
|
|