instantsearch.js 4.40.4 → 4.41.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 +27 -0
- package/cjs/lib/InstantSearch.js +11 -3
- package/cjs/lib/routers/history.js +46 -31
- package/cjs/lib/utils/safelyRunOnBrowser.js +1 -1
- package/cjs/lib/version.js +1 -1
- package/dist/instantsearch.development.d.ts +12 -6
- package/dist/instantsearch.development.js +60 -37
- package/dist/instantsearch.development.js.map +1 -1
- package/dist/instantsearch.production.d.ts +12 -6
- package/dist/instantsearch.production.min.d.ts +12 -6
- package/dist/instantsearch.production.min.js +2 -2
- package/dist/instantsearch.production.min.js.map +1 -1
- package/es/lib/InstantSearch.js +11 -3
- package/es/lib/routers/history.d.ts +3 -3
- package/es/lib/routers/history.js +46 -31
- package/es/lib/utils/getAppIdAndApiKey.d.ts +1 -1
- package/es/lib/utils/safelyRunOnBrowser.d.ts +1 -1
- package/es/lib/utils/safelyRunOnBrowser.js +1 -1
- package/es/lib/version.d.ts +1 -1
- package/es/lib/version.js +1 -1
- package/es/types/widget.d.ts +1 -1
- package/es/widgets/index/index.d.ts +9 -3
- package/package.json +1 -1
package/es/lib/InstantSearch.js
CHANGED
|
@@ -460,9 +460,17 @@ var InstantSearch = /*#__PURE__*/function (_EventEmitter) {
|
|
|
460
460
|
defer(function () {
|
|
461
461
|
_this3.scheduleSearch = originalScheduleSearch;
|
|
462
462
|
})();
|
|
463
|
-
}
|
|
464
|
-
|
|
465
|
-
|
|
463
|
+
} // We only schedule a search when widgets have been added before `start()`
|
|
464
|
+
// because there are listeners that can use these results.
|
|
465
|
+
// This is especially useful in framework-based flavors that wait for
|
|
466
|
+
// dynamically-added widgets to trigger a network request. It avoids
|
|
467
|
+
// having to batch this initial network request with the one coming from
|
|
468
|
+
// `addWidgets()`.
|
|
469
|
+
// Later, we could also skip `index()` widgets and widgets that don't read
|
|
470
|
+
// the results, but this is an optimization that has a very low impact for now.
|
|
471
|
+
else if (this.mainIndex.getWidgets().length > 0) {
|
|
472
|
+
this.scheduleSearch();
|
|
473
|
+
} // Keep the previous reference for legacy purpose, some pattern use
|
|
466
474
|
// the direct Helper access `search.helper` (e.g multi-index).
|
|
467
475
|
|
|
468
476
|
|
|
@@ -47,10 +47,9 @@ declare class BrowserHistory<TRouteState> implements Router<TRouteState> {
|
|
|
47
47
|
private writeTimer?;
|
|
48
48
|
private _onPopState;
|
|
49
49
|
/**
|
|
50
|
-
* Indicates if
|
|
51
|
-
* It needs to avoid pushing state to history in case of back/forward in browser
|
|
50
|
+
* Indicates if last action was back/forward in the browser.
|
|
52
51
|
*/
|
|
53
|
-
private
|
|
52
|
+
private inPopState;
|
|
54
53
|
/**
|
|
55
54
|
* Indicates whether the history router is disposed or not.
|
|
56
55
|
*/
|
|
@@ -92,6 +91,7 @@ declare class BrowserHistory<TRouteState> implements Router<TRouteState> {
|
|
|
92
91
|
* Removes the event listener and cleans up the URL.
|
|
93
92
|
*/
|
|
94
93
|
dispose(): void;
|
|
94
|
+
private shouldWrite;
|
|
95
95
|
}
|
|
96
96
|
export default function historyRouter<TRouteState = UiState>({ createURL, parseURL, writeDelay, windowTitle, getLocation, }?: Partial<BrowserHistoryArgs<TRouteState>>): BrowserHistory<TRouteState>;
|
|
97
97
|
export {};
|
|
@@ -46,7 +46,7 @@ var BrowserHistory = /*#__PURE__*/function () {
|
|
|
46
46
|
|
|
47
47
|
_defineProperty(this, "writeTimer", void 0);
|
|
48
48
|
|
|
49
|
-
_defineProperty(this, "
|
|
49
|
+
_defineProperty(this, "inPopState", false);
|
|
50
50
|
|
|
51
51
|
_defineProperty(this, "isDisposed", false);
|
|
52
52
|
|
|
@@ -101,20 +101,14 @@ var BrowserHistory = /*#__PURE__*/function () {
|
|
|
101
101
|
}
|
|
102
102
|
|
|
103
103
|
_this2.writeTimer = setTimeout(function () {
|
|
104
|
-
setWindowTitle(title);
|
|
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)
|
|
104
|
+
setWindowTitle(title);
|
|
109
105
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
if (_this2.shouldPushState && lastPushWasByISAfterDispose) {
|
|
106
|
+
if (_this2.shouldWrite(url)) {
|
|
113
107
|
window.history.pushState(routeState, title || '', url);
|
|
114
108
|
_this2.latestAcknowledgedHistory = window.history.length;
|
|
115
109
|
}
|
|
116
110
|
|
|
117
|
-
_this2.
|
|
111
|
+
_this2.inPopState = false;
|
|
118
112
|
_this2.writeTimer = undefined;
|
|
119
113
|
}, _this2.writeDelay);
|
|
120
114
|
});
|
|
@@ -135,7 +129,7 @@ var BrowserHistory = /*#__PURE__*/function () {
|
|
|
135
129
|
_this3.writeTimer = undefined;
|
|
136
130
|
}
|
|
137
131
|
|
|
138
|
-
_this3.
|
|
132
|
+
_this3.inPopState = true;
|
|
139
133
|
var routeState = event.state; // At initial load, the state is read from the URL without update.
|
|
140
134
|
// Therefore the state object is not available.
|
|
141
135
|
// In this case, we fallback and read the URL.
|
|
@@ -193,18 +187,39 @@ var BrowserHistory = /*#__PURE__*/function () {
|
|
|
193
187
|
|
|
194
188
|
this.write({});
|
|
195
189
|
}
|
|
190
|
+
}, {
|
|
191
|
+
key: "shouldWrite",
|
|
192
|
+
value: function shouldWrite(url) {
|
|
193
|
+
var _this5 = this;
|
|
194
|
+
|
|
195
|
+
return safelyRunOnBrowser(function (_ref6) {
|
|
196
|
+
var window = _ref6.window;
|
|
197
|
+
// We do want to `pushState` if:
|
|
198
|
+
// - the router is not disposed, IS.js needs to update the URL
|
|
199
|
+
// OR
|
|
200
|
+
// - the last write was from InstantSearch.js
|
|
201
|
+
// (unlike a SPA, where it would have last written)
|
|
202
|
+
var lastPushWasByISAfterDispose = !(_this5.isDisposed && _this5.latestAcknowledgedHistory !== window.history.length);
|
|
203
|
+
return (// When the last state change was through popstate, the IS.js state changes,
|
|
204
|
+
// but that should not write the URL.
|
|
205
|
+
!_this5.inPopState && // When the previous pushState after dispose was by IS.js, we want to write the URL.
|
|
206
|
+
lastPushWasByISAfterDispose && // When the URL is the same as the current one, we do not want to write it.
|
|
207
|
+
url !== window.location.href
|
|
208
|
+
);
|
|
209
|
+
});
|
|
210
|
+
}
|
|
196
211
|
}]);
|
|
197
212
|
|
|
198
213
|
return BrowserHistory;
|
|
199
214
|
}();
|
|
200
215
|
|
|
201
216
|
export default function historyRouter() {
|
|
202
|
-
var
|
|
203
|
-
|
|
204
|
-
createURL =
|
|
205
|
-
var qsModule =
|
|
206
|
-
routeState =
|
|
207
|
-
location =
|
|
217
|
+
var _ref7 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
218
|
+
_ref7$createURL = _ref7.createURL,
|
|
219
|
+
createURL = _ref7$createURL === void 0 ? function (_ref8) {
|
|
220
|
+
var qsModule = _ref8.qsModule,
|
|
221
|
+
routeState = _ref8.routeState,
|
|
222
|
+
location = _ref8.location;
|
|
208
223
|
var protocol = location.protocol,
|
|
209
224
|
hostname = location.hostname,
|
|
210
225
|
_location$port = location.port,
|
|
@@ -220,11 +235,11 @@ export default function historyRouter() {
|
|
|
220
235
|
}
|
|
221
236
|
|
|
222
237
|
return "".concat(protocol, "//").concat(hostname).concat(portWithPrefix).concat(pathname, "?").concat(queryString).concat(hash);
|
|
223
|
-
} :
|
|
224
|
-
|
|
225
|
-
parseURL =
|
|
226
|
-
var qsModule =
|
|
227
|
-
location =
|
|
238
|
+
} : _ref7$createURL,
|
|
239
|
+
_ref7$parseURL = _ref7.parseURL,
|
|
240
|
+
parseURL = _ref7$parseURL === void 0 ? function (_ref9) {
|
|
241
|
+
var qsModule = _ref9.qsModule,
|
|
242
|
+
location = _ref9.location;
|
|
228
243
|
// `qs` by default converts arrays with more than 20 items to an object.
|
|
229
244
|
// We want to avoid this because the data structure manipulated can therefore vary.
|
|
230
245
|
// Setting the limit to `100` seems a good number because the engine's default is 100
|
|
@@ -238,21 +253,21 @@ export default function historyRouter() {
|
|
|
238
253
|
return qsModule.parse(location.search.slice(1), {
|
|
239
254
|
arrayLimit: 99
|
|
240
255
|
});
|
|
241
|
-
} :
|
|
242
|
-
|
|
243
|
-
writeDelay =
|
|
244
|
-
windowTitle =
|
|
245
|
-
|
|
246
|
-
getLocation =
|
|
247
|
-
return safelyRunOnBrowser(function (
|
|
248
|
-
var window =
|
|
256
|
+
} : _ref7$parseURL,
|
|
257
|
+
_ref7$writeDelay = _ref7.writeDelay,
|
|
258
|
+
writeDelay = _ref7$writeDelay === void 0 ? 400 : _ref7$writeDelay,
|
|
259
|
+
windowTitle = _ref7.windowTitle,
|
|
260
|
+
_ref7$getLocation = _ref7.getLocation,
|
|
261
|
+
getLocation = _ref7$getLocation === void 0 ? function () {
|
|
262
|
+
return safelyRunOnBrowser(function (_ref10) {
|
|
263
|
+
var window = _ref10.window;
|
|
249
264
|
return window.location;
|
|
250
265
|
}, {
|
|
251
266
|
fallback: function fallback() {
|
|
252
267
|
throw new Error('You need to provide `getLocation` to the `history` router in environments where `window` does not exist.');
|
|
253
268
|
}
|
|
254
269
|
});
|
|
255
|
-
} :
|
|
270
|
+
} : _ref7$getLocation;
|
|
256
271
|
|
|
257
272
|
return new BrowserHistory({
|
|
258
273
|
createURL: createURL,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function getAppIdAndApiKey(searchClient: any):
|
|
1
|
+
export declare function getAppIdAndApiKey(searchClient: any): [string, string];
|
|
@@ -8,7 +8,7 @@ declare type SafelyRunOnBrowserOptions<TReturn> = {
|
|
|
8
8
|
fallback: () => TReturn;
|
|
9
9
|
};
|
|
10
10
|
/**
|
|
11
|
-
* Runs code on browser
|
|
11
|
+
* Runs code on browser environments safely.
|
|
12
12
|
*/
|
|
13
13
|
export declare function safelyRunOnBrowser<TReturn>(callback: BrowserCallback<TReturn>, { fallback }?: SafelyRunOnBrowserOptions<TReturn>): TReturn;
|
|
14
14
|
export {};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// eslint-disable-next-line no-restricted-globals
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* Runs code on browser
|
|
4
|
+
* Runs code on browser environments safely.
|
|
5
5
|
*/
|
|
6
6
|
export function safelyRunOnBrowser(callback) {
|
|
7
7
|
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
|
package/es/lib/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default: "4.
|
|
1
|
+
declare const _default: "4.41.0";
|
|
2
2
|
export default _default;
|
package/es/lib/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export default '4.
|
|
1
|
+
export default '4.41.0';
|
package/es/types/widget.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ export declare type ScopedResult = {
|
|
|
11
11
|
};
|
|
12
12
|
declare type SharedRenderOptions = {
|
|
13
13
|
instantSearchInstance: InstantSearch;
|
|
14
|
-
parent: IndexWidget
|
|
14
|
+
parent: IndexWidget;
|
|
15
15
|
templatesConfig: Record<string, unknown>;
|
|
16
16
|
scopedResults: ScopedResult[];
|
|
17
17
|
state: SearchParameters;
|
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
import type { AlgoliaSearchHelper as Helper, SearchParameters, SearchResults } from 'algoliasearch-helper';
|
|
2
|
-
import type { UiState, IndexUiState, Widget,
|
|
2
|
+
import type { InstantSearch, UiState, IndexUiState, Widget, ScopedResult } from '../../types';
|
|
3
3
|
export declare type IndexWidgetParams = {
|
|
4
4
|
indexName: string;
|
|
5
5
|
indexId?: string;
|
|
6
6
|
};
|
|
7
|
-
declare type IndexInitOptions =
|
|
8
|
-
|
|
7
|
+
export declare type IndexInitOptions = {
|
|
8
|
+
instantSearchInstance: InstantSearch;
|
|
9
|
+
parent: IndexWidget | null;
|
|
10
|
+
uiState: UiState;
|
|
11
|
+
};
|
|
12
|
+
export declare type IndexRenderOptions = {
|
|
13
|
+
instantSearchInstance: InstantSearch;
|
|
14
|
+
};
|
|
9
15
|
export declare type IndexWidgetDescription = {
|
|
10
16
|
$$type: 'ais.index';
|
|
11
17
|
$$widgetType: 'ais.index';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "instantsearch.js",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.41.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",
|