instantsearch.js 4.32.0 → 4.33.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 +15 -0
- package/cjs/connectors/powered-by/connectPoweredBy.js +13 -4
- package/cjs/lib/InstantSearch.js +4 -2
- package/cjs/lib/infiniteHitsCache/sessionStorage.js +16 -12
- package/cjs/lib/routers/history.js +89 -42
- package/cjs/lib/utils/detect-insights-client.js +10 -1
- package/cjs/lib/utils/index.js +10 -1
- package/cjs/lib/utils/safelyRunOnBrowser.js +30 -0
- package/cjs/lib/version.js +1 -1
- package/cjs/lib/voiceSearchHelper/index.js +5 -0
- package/cjs/middlewares/createMetadataMiddleware.js +12 -3
- package/dist/instantsearch.development.d.ts +13 -2
- package/dist/instantsearch.development.js +161 -66
- package/dist/instantsearch.development.js.map +1 -1
- package/dist/instantsearch.development.min.d.ts +13 -2
- package/dist/instantsearch.production.d.ts +13 -2
- package/dist/instantsearch.production.min.d.ts +13 -2
- package/dist/instantsearch.production.min.js +2 -2
- package/dist/instantsearch.production.min.js.map +1 -1
- package/es/connectors/powered-by/connectPoweredBy.js +14 -5
- package/es/lib/InstantSearch.js +4 -2
- package/es/lib/infiniteHitsCache/sessionStorage.js +17 -14
- package/es/lib/routers/history.d.ts +13 -2
- package/es/lib/routers/history.js +88 -42
- package/es/lib/utils/detect-insights-client.js +9 -1
- package/es/lib/utils/index.d.ts +1 -0
- package/es/lib/utils/index.js +2 -1
- package/es/lib/utils/safelyRunOnBrowser.d.ts +14 -0
- package/es/lib/utils/safelyRunOnBrowser.js +23 -0
- package/es/lib/version.d.ts +1 -1
- package/es/lib/version.js +1 -1
- package/es/lib/voiceSearchHelper/index.js +5 -0
- package/es/middlewares/createMetadataMiddleware.js +12 -3
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,18 @@
|
|
|
1
|
+
# [4.33.0](https://github.com/algolia/instantsearch.js/compare/v4.32.0...v4.33.0) (2021-10-26)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* **router:** skip history push on browser back and forward actions ([#4933](https://github.com/algolia/instantsearch.js/issues/4933)) ([7909da4](https://github.com/algolia/instantsearch.js/commit/7909da4903eb1aee885811e280b909a3bda488be))
|
|
7
|
+
* **setUiState:** reset UI state with empty object ([#4944](https://github.com/algolia/instantsearch.js/issues/4944)) ([5faae4a](https://github.com/algolia/instantsearch.js/commit/5faae4ac44ac5ad2f8086ad2a306bcfaa14bc754))
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
### Features
|
|
11
|
+
|
|
12
|
+
* **router:** support server environments ([#4940](https://github.com/algolia/instantsearch.js/issues/4940)) ([a002962](https://github.com/algolia/instantsearch.js/commit/a002962df0e7683b29bef8bfaaddb494fa551a14))
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
1
16
|
# [4.32.0](https://github.com/algolia/instantsearch.js/compare/v4.31.1...v4.32.0) (2021-10-20)
|
|
2
17
|
|
|
3
18
|
|
|
@@ -25,11 +25,20 @@ var withUsage = (0, _utils.createDocumentationMessageGenerator)({
|
|
|
25
25
|
var connectPoweredBy = function connectPoweredBy(renderFn) {
|
|
26
26
|
var unmountFn = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _utils.noop;
|
|
27
27
|
(0, _utils.checkRendering)(renderFn, withUsage());
|
|
28
|
-
var defaultUrl = 'https://www.algolia.com/?' + 'utm_source=instantsearch.js&' + 'utm_medium=website&' + "utm_content=".concat(
|
|
28
|
+
var defaultUrl = 'https://www.algolia.com/?' + 'utm_source=instantsearch.js&' + 'utm_medium=website&' + "utm_content=".concat((0, _utils.safelyRunOnBrowser)(function (_ref) {
|
|
29
|
+
var _window$location;
|
|
30
|
+
|
|
31
|
+
var window = _ref.window;
|
|
32
|
+
return ((_window$location = window.location) === null || _window$location === void 0 ? void 0 : _window$location.hostname) || '';
|
|
33
|
+
}, {
|
|
34
|
+
fallback: function fallback() {
|
|
35
|
+
return '';
|
|
36
|
+
}
|
|
37
|
+
}), "&") + 'utm_campaign=poweredby';
|
|
29
38
|
return function (widgetParams) {
|
|
30
|
-
var
|
|
31
|
-
|
|
32
|
-
url =
|
|
39
|
+
var _ref2 = widgetParams || {},
|
|
40
|
+
_ref2$url = _ref2.url,
|
|
41
|
+
url = _ref2$url === void 0 ? defaultUrl : _ref2$url;
|
|
33
42
|
|
|
34
43
|
return {
|
|
35
44
|
$$type: 'ais.poweredBy',
|
package/cjs/lib/InstantSearch.js
CHANGED
|
@@ -522,15 +522,17 @@ var InstantSearch = /*#__PURE__*/function (_EventEmitter) {
|
|
|
522
522
|
var nextUiState = typeof uiState === 'function' ? uiState(this.mainIndex.getWidgetUiState({})) : uiState;
|
|
523
523
|
|
|
524
524
|
var setIndexHelperState = function setIndexHelperState(indexWidget) {
|
|
525
|
+
var nextIndexUiState = nextUiState[indexWidget.getIndexId()] || {};
|
|
526
|
+
|
|
525
527
|
if (process.env.NODE_ENV === 'development') {
|
|
526
528
|
(0, _utils.checkIndexUiState)({
|
|
527
529
|
index: indexWidget,
|
|
528
|
-
indexUiState:
|
|
530
|
+
indexUiState: nextIndexUiState
|
|
529
531
|
});
|
|
530
532
|
}
|
|
531
533
|
|
|
532
534
|
indexWidget.getHelper().setState(indexWidget.getWidgetSearchParameters(indexWidget.getHelper().state, {
|
|
533
|
-
uiState:
|
|
535
|
+
uiState: nextIndexUiState
|
|
534
536
|
}));
|
|
535
537
|
indexWidget.getWidgets().filter(_index.isIndexWidget).forEach(setIndexHelperState);
|
|
536
538
|
};
|
|
@@ -21,27 +21,27 @@ function getStateWithoutPage(state) {
|
|
|
21
21
|
|
|
22
22
|
var KEY = 'ais.infiniteHits';
|
|
23
23
|
|
|
24
|
-
function hasSessionStorage() {
|
|
25
|
-
return typeof window !== 'undefined' && typeof window.sessionStorage !== 'undefined';
|
|
26
|
-
}
|
|
27
|
-
|
|
28
24
|
function createInfiniteHitsSessionStorageCache() {
|
|
29
25
|
return {
|
|
30
26
|
read: function read(_ref2) {
|
|
31
27
|
var state = _ref2.state;
|
|
28
|
+
var sessionStorage = (0, _utils.safelyRunOnBrowser)(function (_ref3) {
|
|
29
|
+
var window = _ref3.window;
|
|
30
|
+
return window.sessionStorage;
|
|
31
|
+
});
|
|
32
32
|
|
|
33
|
-
if (!
|
|
33
|
+
if (!sessionStorage) {
|
|
34
34
|
return null;
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
try {
|
|
38
38
|
var cache = JSON.parse( // @ts-expect-error JSON.parse() requires a string, but it actually accepts null, too.
|
|
39
|
-
|
|
39
|
+
sessionStorage.getItem(KEY));
|
|
40
40
|
return cache && (0, _utils.isEqual)(cache.state, getStateWithoutPage(state)) ? cache.hits : null;
|
|
41
41
|
} catch (error) {
|
|
42
42
|
if (error instanceof SyntaxError) {
|
|
43
43
|
try {
|
|
44
|
-
|
|
44
|
+
sessionStorage.removeItem(KEY);
|
|
45
45
|
} catch (err) {// do nothing
|
|
46
46
|
}
|
|
47
47
|
}
|
|
@@ -49,16 +49,20 @@ function createInfiniteHitsSessionStorageCache() {
|
|
|
49
49
|
return null;
|
|
50
50
|
}
|
|
51
51
|
},
|
|
52
|
-
write: function write(
|
|
53
|
-
var state =
|
|
54
|
-
hits =
|
|
52
|
+
write: function write(_ref4) {
|
|
53
|
+
var state = _ref4.state,
|
|
54
|
+
hits = _ref4.hits;
|
|
55
|
+
var sessionStorage = (0, _utils.safelyRunOnBrowser)(function (_ref5) {
|
|
56
|
+
var window = _ref5.window;
|
|
57
|
+
return window.sessionStorage;
|
|
58
|
+
});
|
|
55
59
|
|
|
56
|
-
if (!
|
|
60
|
+
if (!sessionStorage) {
|
|
57
61
|
return;
|
|
58
62
|
}
|
|
59
63
|
|
|
60
64
|
try {
|
|
61
|
-
|
|
65
|
+
sessionStorage.setItem(KEY, JSON.stringify({
|
|
62
66
|
state: getStateWithoutPage(state),
|
|
63
67
|
hits: hits
|
|
64
68
|
}));
|
|
@@ -7,6 +7,8 @@ exports.default = historyRouter;
|
|
|
7
7
|
|
|
8
8
|
var _qs = _interopRequireDefault(require("qs"));
|
|
9
9
|
|
|
10
|
+
var _utils = require("../utils");
|
|
11
|
+
|
|
10
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
13
|
|
|
12
14
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
@@ -19,6 +21,8 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
|
|
|
19
21
|
|
|
20
22
|
var setWindowTitle = function setWindowTitle(title) {
|
|
21
23
|
if (title) {
|
|
24
|
+
// This function is only executed on browsers so we can disable this check.
|
|
25
|
+
// eslint-disable-next-line no-restricted-globals
|
|
22
26
|
window.document.title = title;
|
|
23
27
|
}
|
|
24
28
|
};
|
|
@@ -29,11 +33,14 @@ var BrowserHistory = /*#__PURE__*/function () {
|
|
|
29
33
|
* using web APIs (`window.location.pushState` and `onpopstate` event).
|
|
30
34
|
*/
|
|
31
35
|
function BrowserHistory(_ref) {
|
|
36
|
+
var _this = this;
|
|
37
|
+
|
|
32
38
|
var windowTitle = _ref.windowTitle,
|
|
33
39
|
_ref$writeDelay = _ref.writeDelay,
|
|
34
40
|
writeDelay = _ref$writeDelay === void 0 ? 400 : _ref$writeDelay,
|
|
35
41
|
createURL = _ref.createURL,
|
|
36
|
-
parseURL = _ref.parseURL
|
|
42
|
+
parseURL = _ref.parseURL,
|
|
43
|
+
getLocation = _ref.getLocation;
|
|
37
44
|
|
|
38
45
|
_classCallCheck(this, BrowserHistory);
|
|
39
46
|
|
|
@@ -45,15 +52,23 @@ var BrowserHistory = /*#__PURE__*/function () {
|
|
|
45
52
|
|
|
46
53
|
_defineProperty(this, "parseURL", void 0);
|
|
47
54
|
|
|
55
|
+
_defineProperty(this, "getLocation", void 0);
|
|
56
|
+
|
|
48
57
|
_defineProperty(this, "writeTimer", void 0);
|
|
49
58
|
|
|
59
|
+
_defineProperty(this, "shouldPushState", true);
|
|
60
|
+
|
|
50
61
|
this.windowTitle = windowTitle;
|
|
51
62
|
this.writeTimer = undefined;
|
|
52
63
|
this.writeDelay = writeDelay;
|
|
53
64
|
this._createURL = createURL;
|
|
54
65
|
this.parseURL = parseURL;
|
|
55
|
-
|
|
56
|
-
|
|
66
|
+
this.getLocation = getLocation;
|
|
67
|
+
(0, _utils.safelyRunOnBrowser)(function () {
|
|
68
|
+
var title = _this.windowTitle && _this.windowTitle(_this.read());
|
|
69
|
+
|
|
70
|
+
setWindowTitle(title);
|
|
71
|
+
});
|
|
57
72
|
}
|
|
58
73
|
/**
|
|
59
74
|
* Reads the URL and returns a syncable UI search state.
|
|
@@ -65,7 +80,7 @@ var BrowserHistory = /*#__PURE__*/function () {
|
|
|
65
80
|
value: function read() {
|
|
66
81
|
return this.parseURL({
|
|
67
82
|
qsModule: _qs.default,
|
|
68
|
-
location:
|
|
83
|
+
location: this.getLocation()
|
|
69
84
|
});
|
|
70
85
|
}
|
|
71
86
|
/**
|
|
@@ -75,20 +90,30 @@ var BrowserHistory = /*#__PURE__*/function () {
|
|
|
75
90
|
}, {
|
|
76
91
|
key: "write",
|
|
77
92
|
value: function write(routeState) {
|
|
78
|
-
var
|
|
93
|
+
var _this2 = this;
|
|
79
94
|
|
|
80
|
-
|
|
81
|
-
|
|
95
|
+
(0, _utils.safelyRunOnBrowser)(function (_ref2) {
|
|
96
|
+
var window = _ref2.window;
|
|
82
97
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
98
|
+
var url = _this2.createURL(routeState);
|
|
99
|
+
|
|
100
|
+
var title = _this2.windowTitle && _this2.windowTitle(routeState);
|
|
101
|
+
|
|
102
|
+
if (_this2.writeTimer) {
|
|
103
|
+
clearTimeout(_this2.writeTimer);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
_this2.writeTimer = setTimeout(function () {
|
|
107
|
+
setWindowTitle(title);
|
|
86
108
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
109
|
+
if (_this2.shouldPushState) {
|
|
110
|
+
window.history.pushState(routeState, title || '', url);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
_this2.shouldPushState = true;
|
|
114
|
+
_this2.writeTimer = undefined;
|
|
115
|
+
}, _this2.writeDelay);
|
|
116
|
+
});
|
|
92
117
|
}
|
|
93
118
|
/**
|
|
94
119
|
* Sets a callback on the `onpopstate` event of the history API of the current page.
|
|
@@ -98,26 +123,30 @@ var BrowserHistory = /*#__PURE__*/function () {
|
|
|
98
123
|
}, {
|
|
99
124
|
key: "onUpdate",
|
|
100
125
|
value: function onUpdate(callback) {
|
|
101
|
-
var
|
|
126
|
+
var _this3 = this;
|
|
102
127
|
|
|
103
128
|
this._onPopState = function (event) {
|
|
104
|
-
if (
|
|
105
|
-
|
|
106
|
-
|
|
129
|
+
if (_this3.writeTimer) {
|
|
130
|
+
clearTimeout(_this3.writeTimer);
|
|
131
|
+
_this3.writeTimer = undefined;
|
|
107
132
|
}
|
|
108
133
|
|
|
134
|
+
_this3.shouldPushState = false;
|
|
109
135
|
var routeState = event.state; // At initial load, the state is read from the URL without update.
|
|
110
136
|
// Therefore the state object is not available.
|
|
111
137
|
// In this case, we fallback and read the URL.
|
|
112
138
|
|
|
113
139
|
if (!routeState) {
|
|
114
|
-
callback(
|
|
140
|
+
callback(_this3.read());
|
|
115
141
|
} else {
|
|
116
142
|
callback(routeState);
|
|
117
143
|
}
|
|
118
144
|
};
|
|
119
145
|
|
|
120
|
-
|
|
146
|
+
(0, _utils.safelyRunOnBrowser)(function (_ref3) {
|
|
147
|
+
var window = _ref3.window;
|
|
148
|
+
window.addEventListener('popstate', _this3._onPopState);
|
|
149
|
+
});
|
|
121
150
|
}
|
|
122
151
|
/**
|
|
123
152
|
* Creates a complete URL from a given syncable UI state.
|
|
@@ -133,7 +162,7 @@ var BrowserHistory = /*#__PURE__*/function () {
|
|
|
133
162
|
return this._createURL({
|
|
134
163
|
qsModule: _qs.default,
|
|
135
164
|
routeState: routeState,
|
|
136
|
-
location:
|
|
165
|
+
location: this.getLocation()
|
|
137
166
|
});
|
|
138
167
|
}
|
|
139
168
|
/**
|
|
@@ -143,12 +172,18 @@ var BrowserHistory = /*#__PURE__*/function () {
|
|
|
143
172
|
}, {
|
|
144
173
|
key: "dispose",
|
|
145
174
|
value: function dispose() {
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
175
|
+
var _this4 = this;
|
|
176
|
+
|
|
177
|
+
(0, _utils.safelyRunOnBrowser)(function (_ref4) {
|
|
178
|
+
var window = _ref4.window;
|
|
179
|
+
|
|
180
|
+
if (_this4._onPopState) {
|
|
181
|
+
window.removeEventListener('popstate', _this4._onPopState);
|
|
182
|
+
}
|
|
183
|
+
});
|
|
149
184
|
|
|
150
185
|
if (this.writeTimer) {
|
|
151
|
-
|
|
186
|
+
clearTimeout(this.writeTimer);
|
|
152
187
|
}
|
|
153
188
|
|
|
154
189
|
this.write({});
|
|
@@ -159,12 +194,12 @@ var BrowserHistory = /*#__PURE__*/function () {
|
|
|
159
194
|
}();
|
|
160
195
|
|
|
161
196
|
function historyRouter() {
|
|
162
|
-
var
|
|
163
|
-
|
|
164
|
-
createURL =
|
|
165
|
-
var qsModule =
|
|
166
|
-
routeState =
|
|
167
|
-
location =
|
|
197
|
+
var _ref5 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
198
|
+
_ref5$createURL = _ref5.createURL,
|
|
199
|
+
createURL = _ref5$createURL === void 0 ? function (_ref6) {
|
|
200
|
+
var qsModule = _ref6.qsModule,
|
|
201
|
+
routeState = _ref6.routeState,
|
|
202
|
+
location = _ref6.location;
|
|
168
203
|
var protocol = location.protocol,
|
|
169
204
|
hostname = location.hostname,
|
|
170
205
|
_location$port = location.port,
|
|
@@ -180,11 +215,11 @@ function historyRouter() {
|
|
|
180
215
|
}
|
|
181
216
|
|
|
182
217
|
return "".concat(protocol, "//").concat(hostname).concat(portWithPrefix).concat(pathname, "?").concat(queryString).concat(hash);
|
|
183
|
-
} :
|
|
184
|
-
|
|
185
|
-
parseURL =
|
|
186
|
-
var qsModule =
|
|
187
|
-
location =
|
|
218
|
+
} : _ref5$createURL,
|
|
219
|
+
_ref5$parseURL = _ref5.parseURL,
|
|
220
|
+
parseURL = _ref5$parseURL === void 0 ? function (_ref7) {
|
|
221
|
+
var qsModule = _ref7.qsModule,
|
|
222
|
+
location = _ref7.location;
|
|
188
223
|
// `qs` by default converts arrays with more than 20 items to an object.
|
|
189
224
|
// We want to avoid this because the data structure manipulated can therefore vary.
|
|
190
225
|
// Setting the limit to `100` seems a good number because the engine's default is 100
|
|
@@ -198,15 +233,27 @@ function historyRouter() {
|
|
|
198
233
|
return qsModule.parse(location.search.slice(1), {
|
|
199
234
|
arrayLimit: 99
|
|
200
235
|
});
|
|
201
|
-
} :
|
|
202
|
-
|
|
203
|
-
writeDelay =
|
|
204
|
-
windowTitle =
|
|
236
|
+
} : _ref5$parseURL,
|
|
237
|
+
_ref5$writeDelay = _ref5.writeDelay,
|
|
238
|
+
writeDelay = _ref5$writeDelay === void 0 ? 400 : _ref5$writeDelay,
|
|
239
|
+
windowTitle = _ref5.windowTitle,
|
|
240
|
+
_ref5$getLocation = _ref5.getLocation,
|
|
241
|
+
getLocation = _ref5$getLocation === void 0 ? function () {
|
|
242
|
+
return (0, _utils.safelyRunOnBrowser)(function (_ref8) {
|
|
243
|
+
var window = _ref8.window;
|
|
244
|
+
return window.location;
|
|
245
|
+
}, {
|
|
246
|
+
fallback: function fallback() {
|
|
247
|
+
throw new Error('You need to provide `getLocation` to the `history` router in environments where `window` does not exist.');
|
|
248
|
+
}
|
|
249
|
+
});
|
|
250
|
+
} : _ref5$getLocation;
|
|
205
251
|
|
|
206
252
|
return new BrowserHistory({
|
|
207
253
|
createURL: createURL,
|
|
208
254
|
parseURL: parseURL,
|
|
209
255
|
writeDelay: writeDelay,
|
|
210
|
-
windowTitle: windowTitle
|
|
256
|
+
windowTitle: windowTitle,
|
|
257
|
+
getLocation: getLocation
|
|
211
258
|
});
|
|
212
259
|
}
|
|
@@ -5,6 +5,15 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = hasDetectedInsightsClient;
|
|
7
7
|
|
|
8
|
+
var _safelyRunOnBrowser = require("./safelyRunOnBrowser");
|
|
9
|
+
|
|
8
10
|
function hasDetectedInsightsClient() {
|
|
9
|
-
return
|
|
11
|
+
return (0, _safelyRunOnBrowser.safelyRunOnBrowser)(function (_ref) {
|
|
12
|
+
var window = _ref.window;
|
|
13
|
+
return Boolean(window.AlgoliaAnalyticsObject);
|
|
14
|
+
}, {
|
|
15
|
+
fallback: function fallback() {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
10
19
|
}
|
package/cjs/lib/utils/index.js
CHANGED
|
@@ -55,7 +55,8 @@ var _exportNames = {
|
|
|
55
55
|
debounce: true,
|
|
56
56
|
serializePayload: true,
|
|
57
57
|
deserializePayload: true,
|
|
58
|
-
getWidgetAttribute: true
|
|
58
|
+
getWidgetAttribute: true,
|
|
59
|
+
safelyRunOnBrowser: true
|
|
59
60
|
};
|
|
60
61
|
Object.defineProperty(exports, "capitalize", {
|
|
61
62
|
enumerable: true,
|
|
@@ -369,6 +370,12 @@ Object.defineProperty(exports, "getWidgetAttribute", {
|
|
|
369
370
|
return _getWidgetAttribute.getWidgetAttribute;
|
|
370
371
|
}
|
|
371
372
|
});
|
|
373
|
+
Object.defineProperty(exports, "safelyRunOnBrowser", {
|
|
374
|
+
enumerable: true,
|
|
375
|
+
get: function get() {
|
|
376
|
+
return _safelyRunOnBrowser.safelyRunOnBrowser;
|
|
377
|
+
}
|
|
378
|
+
});
|
|
372
379
|
|
|
373
380
|
var _capitalize = _interopRequireDefault(require("./capitalize"));
|
|
374
381
|
|
|
@@ -488,4 +495,6 @@ var _serializer = require("./serializer");
|
|
|
488
495
|
|
|
489
496
|
var _getWidgetAttribute = require("./getWidgetAttribute");
|
|
490
497
|
|
|
498
|
+
var _safelyRunOnBrowser = require("./safelyRunOnBrowser");
|
|
499
|
+
|
|
491
500
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.safelyRunOnBrowser = safelyRunOnBrowser;
|
|
7
|
+
|
|
8
|
+
// eslint-disable-next-line no-restricted-globals
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Runs code on browser enviromnents safely.
|
|
12
|
+
*/
|
|
13
|
+
function safelyRunOnBrowser(callback) {
|
|
14
|
+
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
|
|
15
|
+
fallback: function fallback() {
|
|
16
|
+
return undefined;
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
fallback = _ref.fallback;
|
|
20
|
+
|
|
21
|
+
// eslint-disable-next-line no-restricted-globals
|
|
22
|
+
if (typeof window === 'undefined') {
|
|
23
|
+
return fallback();
|
|
24
|
+
} // eslint-disable-next-line no-restricted-globals
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
return callback({
|
|
28
|
+
window: window
|
|
29
|
+
});
|
|
30
|
+
}
|
package/cjs/lib/version.js
CHANGED
|
@@ -11,6 +11,11 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
|
11
11
|
|
|
12
12
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
13
13
|
|
|
14
|
+
// `SpeechRecognition` is an API used on the browser so we can safely disable
|
|
15
|
+
// the `window` check.
|
|
16
|
+
|
|
17
|
+
/* eslint-disable no-restricted-globals */
|
|
18
|
+
|
|
14
19
|
/* global SpeechRecognition SpeechRecognitionEvent */
|
|
15
20
|
var createVoiceSearchHelper = function createVoiceSearchHelper(_ref) {
|
|
16
21
|
var searchAsYouSpeak = _ref.searchAsYouSpeak,
|
|
@@ -6,6 +6,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.isMetadataEnabled = isMetadataEnabled;
|
|
7
7
|
exports.createMetadataMiddleware = createMetadataMiddleware;
|
|
8
8
|
|
|
9
|
+
var _utils = require("../lib/utils");
|
|
10
|
+
|
|
9
11
|
function extractPayload(widgets, instantSearchInstance, payload) {
|
|
10
12
|
var parent = instantSearchInstance.mainIndex;
|
|
11
13
|
var initOptions = {
|
|
@@ -51,7 +53,14 @@ function extractPayload(widgets, instantSearchInstance, payload) {
|
|
|
51
53
|
}
|
|
52
54
|
|
|
53
55
|
function isMetadataEnabled() {
|
|
54
|
-
return
|
|
56
|
+
return (0, _utils.safelyRunOnBrowser)(function (_ref) {
|
|
57
|
+
var window = _ref.window;
|
|
58
|
+
return window.navigator.userAgent.indexOf('Algolia Crawler') > -1;
|
|
59
|
+
}, {
|
|
60
|
+
fallback: function fallback() {
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
});
|
|
55
64
|
}
|
|
56
65
|
/**
|
|
57
66
|
* Exposes the metadata of mounted widgets in a custom
|
|
@@ -63,8 +72,8 @@ function isMetadataEnabled() {
|
|
|
63
72
|
|
|
64
73
|
|
|
65
74
|
function createMetadataMiddleware() {
|
|
66
|
-
return function (
|
|
67
|
-
var instantSearchInstance =
|
|
75
|
+
return function (_ref2) {
|
|
76
|
+
var instantSearchInstance = _ref2.instantSearchInstance;
|
|
68
77
|
var payload = {
|
|
69
78
|
widgets: []
|
|
70
79
|
};
|
|
@@ -455,13 +455,23 @@ declare class BrowserHistory<TRouteState> implements Router<TRouteState> {
|
|
|
455
455
|
* It should be symmetrical to `createURL`.
|
|
456
456
|
*/
|
|
457
457
|
private readonly parseURL;
|
|
458
|
+
/**
|
|
459
|
+
* Returns the location to store in the history.
|
|
460
|
+
* @default () => window.location
|
|
461
|
+
*/
|
|
462
|
+
private readonly getLocation;
|
|
458
463
|
private writeTimer?;
|
|
459
464
|
private _onPopState;
|
|
465
|
+
/**
|
|
466
|
+
* Indicates if history.pushState should be executed.
|
|
467
|
+
* It needs to avoid pushing state to history in case of back/forward in browser
|
|
468
|
+
*/
|
|
469
|
+
private shouldPushState;
|
|
460
470
|
/**
|
|
461
471
|
* Initializes a new storage provider that syncs the search state to the URL
|
|
462
472
|
* using web APIs (`window.location.pushState` and `onpopstate` event).
|
|
463
473
|
*/
|
|
464
|
-
constructor({ windowTitle, writeDelay, createURL, parseURL, }: BrowserHistoryArgs<TRouteState>);
|
|
474
|
+
constructor({ windowTitle, writeDelay, createURL, parseURL, getLocation, }: BrowserHistoryArgs<TRouteState>);
|
|
465
475
|
/**
|
|
466
476
|
* Reads the URL and returns a syncable UI search state.
|
|
467
477
|
*/
|
|
@@ -494,6 +504,7 @@ declare type BrowserHistoryArgs<TRouteState> = {
|
|
|
494
504
|
writeDelay: number;
|
|
495
505
|
createURL: CreateURL_2<TRouteState>;
|
|
496
506
|
parseURL: ParseURL<TRouteState>;
|
|
507
|
+
getLocation(): Location;
|
|
497
508
|
};
|
|
498
509
|
|
|
499
510
|
declare type BuiltInBindEventForHits = (eventType: string, hits: Hit | Hits, eventName?: string) => string;
|
|
@@ -1723,7 +1734,7 @@ declare type HighlightOptions = {
|
|
|
1723
1734
|
}>;
|
|
1724
1735
|
};
|
|
1725
1736
|
|
|
1726
|
-
declare function historyRouter<TRouteState = UiState>({ createURL, parseURL, writeDelay, windowTitle, }?: Partial<BrowserHistoryArgs<TRouteState>>): BrowserHistory<TRouteState>;
|
|
1737
|
+
declare function historyRouter<TRouteState = UiState>({ createURL, parseURL, writeDelay, windowTitle, getLocation, }?: Partial<BrowserHistoryArgs<TRouteState>>): BrowserHistory<TRouteState>;
|
|
1727
1738
|
|
|
1728
1739
|
declare type Hit = {
|
|
1729
1740
|
__position: number;
|