instantsearch.js 4.33.0 → 4.35.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 +41 -0
- package/README.md +24 -1
- package/cjs/connectors/autocomplete/connectAutocomplete.js +2 -1
- package/cjs/connectors/infinite-hits/connectInfiniteHits.js +1 -1
- package/cjs/connectors/numeric-menu/connectNumericMenu.js +6 -4
- package/cjs/connectors/pagination/connectPagination.js +3 -3
- package/cjs/connectors/search-box/connectSearchBox.js +4 -3
- package/cjs/connectors/sort-by/connectSortBy.js +2 -1
- package/cjs/connectors/stats/connectStats.js +4 -4
- package/cjs/connectors/toggle-refinement/connectToggleRefinement.js +1 -1
- package/cjs/lib/InstantSearch.js +23 -2
- package/cjs/lib/version.js +1 -1
- package/cjs/widgets/index/index.js +21 -3
- package/dist/instantsearch.development.d.ts +9 -2
- package/dist/instantsearch.development.js +72 -28
- package/dist/instantsearch.development.js.map +1 -1
- package/dist/instantsearch.development.min.d.ts +9 -2
- package/dist/instantsearch.production.d.ts +9 -2
- package/dist/instantsearch.production.min.d.ts +9 -2
- package/dist/instantsearch.production.min.js +2 -2
- package/dist/instantsearch.production.min.js.map +1 -1
- package/es/connectors/autocomplete/connectAutocomplete.js +2 -1
- package/es/connectors/infinite-hits/connectInfiniteHits.js +1 -1
- package/es/connectors/numeric-menu/connectNumericMenu.js +6 -4
- package/es/connectors/pagination/connectPagination.js +3 -3
- package/es/connectors/search-box/connectSearchBox.js +4 -3
- package/es/connectors/sort-by/connectSortBy.js +2 -1
- package/es/connectors/stats/connectStats.js +4 -4
- package/es/connectors/toggle-refinement/connectToggleRefinement.js +1 -1
- package/es/lib/InstantSearch.d.ts +3 -3
- package/es/lib/InstantSearch.js +23 -2
- package/es/lib/version.d.ts +1 -1
- package/es/lib/version.js +1 -1
- package/es/types/results.d.ts +7 -0
- package/es/widgets/index/index.js +21 -3
- package/package.json +10 -7
|
@@ -52,6 +52,7 @@ var connectAutocomplete = function connectAutocomplete(renderFn) {
|
|
|
52
52
|
var _this = this;
|
|
53
53
|
|
|
54
54
|
var helper = _ref4.helper,
|
|
55
|
+
state = _ref4.state,
|
|
55
56
|
scopedResults = _ref4.scopedResults,
|
|
56
57
|
instantSearchInstance = _ref4.instantSearchInstance;
|
|
57
58
|
|
|
@@ -79,7 +80,7 @@ var connectAutocomplete = function connectAutocomplete(renderFn) {
|
|
|
79
80
|
};
|
|
80
81
|
});
|
|
81
82
|
return {
|
|
82
|
-
currentRefinement:
|
|
83
|
+
currentRefinement: state.query || '',
|
|
83
84
|
indices: indices,
|
|
84
85
|
refine: connectorState.refine,
|
|
85
86
|
widgetParams: widgetParams
|
|
@@ -165,7 +165,7 @@ var connectInfiniteHits = function connectInfiniteHits(renderFn) {
|
|
|
165
165
|
index: helper.getIndex(),
|
|
166
166
|
widgetType: this.$$type
|
|
167
167
|
});
|
|
168
|
-
isFirstPage =
|
|
168
|
+
isFirstPage = state.page === undefined || getFirstReceivedPage(state, cachedHits) === 0;
|
|
169
169
|
} else {
|
|
170
170
|
var _state$page3 = state.page,
|
|
171
171
|
_page = _state$page3 === void 0 ? 0 : _state$page3;
|
|
@@ -234,6 +234,8 @@ function isRefined(state, attribute, option) {
|
|
|
234
234
|
if (option.start !== undefined && option.end !== undefined) {
|
|
235
235
|
if (option.start === option.end) {
|
|
236
236
|
return hasNumericRefinement(currentRefinements, '=', option.start);
|
|
237
|
+
} else {
|
|
238
|
+
return hasNumericRefinement(currentRefinements, '>=', option.start) && hasNumericRefinement(currentRefinements, '<=', option.end);
|
|
237
239
|
}
|
|
238
240
|
}
|
|
239
241
|
|
|
@@ -287,17 +289,17 @@ function getRefinedState(state, attribute, facetValue) {
|
|
|
287
289
|
if (refinedOption.start !== undefined) {
|
|
288
290
|
if (hasNumericRefinement(currentRefinements, '>=', refinedOption.start)) {
|
|
289
291
|
resolvedState = resolvedState.removeNumericRefinement(attribute, '>=', refinedOption.start);
|
|
290
|
-
} else {
|
|
291
|
-
resolvedState = resolvedState.addNumericRefinement(attribute, '>=', refinedOption.start);
|
|
292
292
|
}
|
|
293
|
+
|
|
294
|
+
resolvedState = resolvedState.addNumericRefinement(attribute, '>=', refinedOption.start);
|
|
293
295
|
}
|
|
294
296
|
|
|
295
297
|
if (refinedOption.end !== undefined) {
|
|
296
298
|
if (hasNumericRefinement(currentRefinements, '<=', refinedOption.end)) {
|
|
297
299
|
resolvedState = resolvedState.removeNumericRefinement(attribute, '<=', refinedOption.end);
|
|
298
|
-
} else {
|
|
299
|
-
resolvedState = resolvedState.addNumericRefinement(attribute, '<=', refinedOption.end);
|
|
300
300
|
}
|
|
301
|
+
|
|
302
|
+
resolvedState = resolvedState.addNumericRefinement(attribute, '<=', refinedOption.end);
|
|
301
303
|
}
|
|
302
304
|
|
|
303
305
|
if (typeof resolvedState.page === 'number') {
|
|
@@ -78,6 +78,7 @@ var connectPagination = function connectPagination(renderFn) {
|
|
|
78
78
|
getWidgetRenderState: function getWidgetRenderState(_ref6) {
|
|
79
79
|
var results = _ref6.results,
|
|
80
80
|
helper = _ref6.helper,
|
|
81
|
+
state = _ref6.state,
|
|
81
82
|
createURL = _ref6.createURL;
|
|
82
83
|
|
|
83
84
|
if (!connectorState.refine) {
|
|
@@ -88,14 +89,13 @@ var connectPagination = function connectPagination(renderFn) {
|
|
|
88
89
|
}
|
|
89
90
|
|
|
90
91
|
if (!connectorState.createURL) {
|
|
91
|
-
connectorState.createURL = function (
|
|
92
|
+
connectorState.createURL = function (helperState) {
|
|
92
93
|
return function (page) {
|
|
93
|
-
return createURL(
|
|
94
|
+
return createURL(helperState.setPage(page));
|
|
94
95
|
};
|
|
95
96
|
};
|
|
96
97
|
}
|
|
97
98
|
|
|
98
|
-
var state = helper.state;
|
|
99
99
|
var page = state.page || 0;
|
|
100
100
|
var nbPages = getMaxPage(results || {
|
|
101
101
|
nbPages: 0
|
|
@@ -63,11 +63,12 @@ var connectSearchBox = function connectSearchBox(renderFn) {
|
|
|
63
63
|
},
|
|
64
64
|
getWidgetRenderState: function getWidgetRenderState(_ref3) {
|
|
65
65
|
var helper = _ref3.helper,
|
|
66
|
-
searchMetadata = _ref3.searchMetadata
|
|
66
|
+
searchMetadata = _ref3.searchMetadata,
|
|
67
|
+
state = _ref3.state;
|
|
67
68
|
|
|
68
69
|
if (!_refine) {
|
|
69
70
|
var setQueryAndSearch = function setQueryAndSearch(query) {
|
|
70
|
-
if (query !==
|
|
71
|
+
if (query !== state.query) {
|
|
71
72
|
helper.setQuery(query).search();
|
|
72
73
|
}
|
|
73
74
|
};
|
|
@@ -84,7 +85,7 @@ var connectSearchBox = function connectSearchBox(renderFn) {
|
|
|
84
85
|
|
|
85
86
|
_clear = clear(helper);
|
|
86
87
|
return {
|
|
87
|
-
query:
|
|
88
|
+
query: state.query || '',
|
|
88
89
|
refine: _refine,
|
|
89
90
|
clear: _cachedClear,
|
|
90
91
|
widgetParams: widgetParams,
|
|
@@ -64,6 +64,7 @@ var connectSortBy = function connectSortBy(renderFn) {
|
|
|
64
64
|
getWidgetRenderState: function getWidgetRenderState(_ref3) {
|
|
65
65
|
var results = _ref3.results,
|
|
66
66
|
helper = _ref3.helper,
|
|
67
|
+
state = _ref3.state,
|
|
67
68
|
parent = _ref3.parent;
|
|
68
69
|
|
|
69
70
|
if (!connectorState.initialIndex && parent) {
|
|
@@ -77,7 +78,7 @@ var connectSortBy = function connectSortBy(renderFn) {
|
|
|
77
78
|
}
|
|
78
79
|
|
|
79
80
|
return {
|
|
80
|
-
currentRefinement:
|
|
81
|
+
currentRefinement: state.index,
|
|
81
82
|
options: transformItems(items),
|
|
82
83
|
refine: connectorState.setIndex,
|
|
83
84
|
hasNoResults: results ? results.nbHits === 0 : true,
|
|
@@ -42,18 +42,18 @@ var connectStats = function connectStats(renderFn) {
|
|
|
42
42
|
},
|
|
43
43
|
getWidgetRenderState: function getWidgetRenderState(_ref) {
|
|
44
44
|
var results = _ref.results,
|
|
45
|
-
|
|
45
|
+
state = _ref.state;
|
|
46
46
|
|
|
47
47
|
if (!results) {
|
|
48
48
|
return {
|
|
49
|
-
hitsPerPage:
|
|
49
|
+
hitsPerPage: state.hitsPerPage,
|
|
50
50
|
nbHits: 0,
|
|
51
51
|
nbSortedHits: undefined,
|
|
52
52
|
areHitsSorted: false,
|
|
53
53
|
nbPages: 0,
|
|
54
|
-
page:
|
|
54
|
+
page: state.page || 0,
|
|
55
55
|
processingTimeMS: -1,
|
|
56
|
-
query:
|
|
56
|
+
query: state.query || '',
|
|
57
57
|
widgetParams: widgetParams
|
|
58
58
|
};
|
|
59
59
|
}
|
|
@@ -177,7 +177,7 @@ var connectToggleRefinement = function connectToggleRefinement(renderFn) {
|
|
|
177
177
|
createURL = _ref6.createURL,
|
|
178
178
|
instantSearchInstance = _ref6.instantSearchInstance;
|
|
179
179
|
var isRefined = results ? on.every(function (v) {
|
|
180
|
-
return
|
|
180
|
+
return state.isDisjunctiveFacetRefined(attribute, v);
|
|
181
181
|
}) : on.every(function (v) {
|
|
182
182
|
return state.isDisjunctiveFacetRefined(attribute, v);
|
|
183
183
|
});
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
1
|
import type { AlgoliaSearchHelper } from 'algoliasearch-helper';
|
|
3
|
-
import EventEmitter from 'events';
|
|
2
|
+
import EventEmitter from '@algolia/events';
|
|
4
3
|
import type { IndexWidget } from '../widgets/index/index';
|
|
5
|
-
import type { InsightsClient as AlgoliaInsightsClient, SearchClient, Widget, UiState, CreateURL, Middleware, MiddlewareDefinition, RenderState } from '../types';
|
|
4
|
+
import type { InsightsClient as AlgoliaInsightsClient, SearchClient, Widget, UiState, CreateURL, Middleware, MiddlewareDefinition, RenderState, InitialResults } from '../types';
|
|
6
5
|
import type { RouterProps } from '../middlewares/createRouterMiddleware';
|
|
7
6
|
import type { InsightsEvent } from '../middlewares/createInsightsMiddleware';
|
|
8
7
|
/**
|
|
@@ -106,6 +105,7 @@ declare class InstantSearch<TUiState extends UiState = UiState, TRouteState = TU
|
|
|
106
105
|
_searchStalledTimer: any;
|
|
107
106
|
_isSearchStalled: boolean;
|
|
108
107
|
_initialUiState: UiState;
|
|
108
|
+
_initialResults: InitialResults | null;
|
|
109
109
|
_createURL: CreateURL<UiState>;
|
|
110
110
|
_searchFunction?: InstantSearchOptions['searchFunction'];
|
|
111
111
|
_mainHelperSearch?: AlgoliaSearchHelper['search'];
|
package/es/lib/InstantSearch.js
CHANGED
|
@@ -27,7 +27,7 @@ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.g
|
|
|
27
27
|
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; }
|
|
28
28
|
|
|
29
29
|
import algoliasearchHelper from 'algoliasearch-helper';
|
|
30
|
-
import EventEmitter from 'events';
|
|
30
|
+
import EventEmitter from '@algolia/events';
|
|
31
31
|
import index, { isIndexWidget } from '../widgets/index/index';
|
|
32
32
|
import version from './version';
|
|
33
33
|
import createHelpers from './createHelpers';
|
|
@@ -91,6 +91,8 @@ var InstantSearch = /*#__PURE__*/function (_EventEmitter) {
|
|
|
91
91
|
|
|
92
92
|
_defineProperty(_assertThisInitialized(_this), "_initialUiState", void 0);
|
|
93
93
|
|
|
94
|
+
_defineProperty(_assertThisInitialized(_this), "_initialResults", void 0);
|
|
95
|
+
|
|
94
96
|
_defineProperty(_assertThisInitialized(_this), "_createURL", void 0);
|
|
95
97
|
|
|
96
98
|
_defineProperty(_assertThisInitialized(_this), "_searchFunction", void 0);
|
|
@@ -195,6 +197,7 @@ var InstantSearch = /*#__PURE__*/function (_EventEmitter) {
|
|
|
195
197
|
_this._isSearchStalled = false;
|
|
196
198
|
_this._createURL = defaultCreateURL;
|
|
197
199
|
_this._initialUiState = initialUiState;
|
|
200
|
+
_this._initialResults = null;
|
|
198
201
|
|
|
199
202
|
if (searchFunction) {
|
|
200
203
|
_this._searchFunction = searchFunction;
|
|
@@ -437,9 +440,27 @@ var InstantSearch = /*#__PURE__*/function (_EventEmitter) {
|
|
|
437
440
|
parent: null,
|
|
438
441
|
uiState: this._initialUiState
|
|
439
442
|
});
|
|
440
|
-
|
|
443
|
+
|
|
444
|
+
if (this._initialResults) {
|
|
445
|
+
var originalScheduleSearch = this.scheduleSearch; // We don't schedule a first search when initial results are provided
|
|
446
|
+
// because we already have the results to render. This skips the initial
|
|
447
|
+
// network request on the browser on `start`.
|
|
448
|
+
|
|
449
|
+
this.scheduleSearch = defer(noop); // We also skip the initial network request when widgets are dynamically
|
|
450
|
+
// added in the first tick (that's the case in all the framework-based flavors).
|
|
451
|
+
// When we add a widget to `index`, it calls `scheduleSearch`. We can rely
|
|
452
|
+
// on our `defer` util to restore the original `scheduleSearch` value once
|
|
453
|
+
// widgets are added to hook back to the regular lifecycle.
|
|
454
|
+
|
|
455
|
+
defer(function () {
|
|
456
|
+
_this3.scheduleSearch = originalScheduleSearch;
|
|
457
|
+
})();
|
|
458
|
+
} else {
|
|
459
|
+
this.scheduleSearch();
|
|
460
|
+
} // Keep the previous reference for legacy purpose, some pattern use
|
|
441
461
|
// the direct Helper access `search.helper` (e.g multi-index).
|
|
442
462
|
|
|
463
|
+
|
|
443
464
|
this.helper = this.mainIndex.getHelper(); // track we started the search if we add more widgets,
|
|
444
465
|
// to init them directly after add
|
|
445
466
|
|
package/es/lib/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default: "4.
|
|
1
|
+
declare const _default: "4.35.0";
|
|
2
2
|
export default _default;
|
package/es/lib/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export default '4.
|
|
1
|
+
export default '4.35.0';
|
package/es/types/results.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { PlainSearchParameters, SearchResults } from 'algoliasearch-helper';
|
|
1
2
|
export declare type HitAttributeHighlightResult = {
|
|
2
3
|
value: string;
|
|
3
4
|
matchLevel: 'none' | 'partial' | 'full';
|
|
@@ -64,3 +65,9 @@ export declare type NumericRefinement = {
|
|
|
64
65
|
operator: string;
|
|
65
66
|
};
|
|
66
67
|
export declare type Refinement = FacetRefinement | NumericRefinement;
|
|
68
|
+
declare type InitialResult = {
|
|
69
|
+
state: PlainSearchParameters;
|
|
70
|
+
results: SearchResults['_rawResults'];
|
|
71
|
+
};
|
|
72
|
+
export declare type InitialResults = Record<string, InitialResult>;
|
|
73
|
+
export {};
|
|
@@ -275,7 +275,8 @@ var index = function index(widgetParams) {
|
|
|
275
275
|
return this;
|
|
276
276
|
},
|
|
277
277
|
init: function init(_ref2) {
|
|
278
|
-
var _this3 = this
|
|
278
|
+
var _this3 = this,
|
|
279
|
+
_instantSearchInstanc;
|
|
279
280
|
|
|
280
281
|
var instantSearchInstance = _ref2.instantSearchInstance,
|
|
281
282
|
parent = _ref2.parent,
|
|
@@ -333,11 +334,21 @@ var index = function index(widgetParams) {
|
|
|
333
334
|
|
|
334
335
|
derivedHelper = mainHelper.derive(function () {
|
|
335
336
|
return mergeSearchParameters.apply(void 0, _toConsumableArray(resolveSearchParameters(_this3)));
|
|
336
|
-
});
|
|
337
|
+
});
|
|
338
|
+
var indexInitialResults = (_instantSearchInstanc = instantSearchInstance._initialResults) === null || _instantSearchInstanc === void 0 ? void 0 : _instantSearchInstanc[this.getIndexId()];
|
|
339
|
+
|
|
340
|
+
if (indexInitialResults) {
|
|
341
|
+
// We restore the shape of the results provided to the instance to respect
|
|
342
|
+
// the helper's structure.
|
|
343
|
+
var results = new algoliasearchHelper.SearchResults(new algoliasearchHelper.SearchParameters(indexInitialResults.state), indexInitialResults.results);
|
|
344
|
+
derivedHelper.lastResults = results;
|
|
345
|
+
helper.lastResults = results;
|
|
346
|
+
} // Subscribe to the Helper state changes for the page before widgets
|
|
337
347
|
// are initialized. This behavior mimics the original one of the Helper.
|
|
338
348
|
// It makes sense to replicate it at the `init` step. We have another
|
|
339
349
|
// listener on `change` below, once `init` is done.
|
|
340
350
|
|
|
351
|
+
|
|
341
352
|
helper.on('change', function (_ref3) {
|
|
342
353
|
var isPageReset = _ref3.isPageReset;
|
|
343
354
|
|
|
@@ -438,6 +449,13 @@ var index = function index(widgetParams) {
|
|
|
438
449
|
instantSearchInstance.onInternalStateChange();
|
|
439
450
|
}
|
|
440
451
|
});
|
|
452
|
+
|
|
453
|
+
if (indexInitialResults) {
|
|
454
|
+
// If there are initial results, we're not notified of the next results
|
|
455
|
+
// because we don't trigger an initial search. We therefore need to directly
|
|
456
|
+
// schedule a render that will render the results injected on the helper.
|
|
457
|
+
instantSearchInstance.scheduleRender();
|
|
458
|
+
}
|
|
441
459
|
},
|
|
442
460
|
render: function render(_ref5) {
|
|
443
461
|
var _this4 = this;
|
|
@@ -541,7 +559,7 @@ var index = function index(widgetParams) {
|
|
|
541
559
|
localUiState = getLocalWidgetsUiState(localWidgets, {
|
|
542
560
|
searchParameters: this.getHelper().state,
|
|
543
561
|
helper: this.getHelper()
|
|
544
|
-
});
|
|
562
|
+
}, localUiState);
|
|
545
563
|
}
|
|
546
564
|
};
|
|
547
565
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "instantsearch.js",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.35.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",
|
|
@@ -55,16 +55,16 @@
|
|
|
55
55
|
"@types/google.maps": "^3.45.3",
|
|
56
56
|
"@types/hogan.js": "^3.0.0",
|
|
57
57
|
"@types/qs": "^6.5.3",
|
|
58
|
-
"algoliasearch-helper": "^3.
|
|
58
|
+
"algoliasearch-helper": "^3.7.0",
|
|
59
59
|
"classnames": "^2.2.5",
|
|
60
|
-
"events": "^
|
|
60
|
+
"@algolia/events": "^4.0.1",
|
|
61
61
|
"hogan.js": "^3.0.2",
|
|
62
62
|
"preact": "^10.0.0",
|
|
63
63
|
"qs": "^6.5.1 < 6.10",
|
|
64
|
-
"search-insights": "^2.0
|
|
64
|
+
"search-insights": "^2.1.0"
|
|
65
65
|
},
|
|
66
66
|
"devDependencies": {
|
|
67
|
-
"@algolia/client-search": "4.
|
|
67
|
+
"@algolia/client-search": "4.11.0",
|
|
68
68
|
"@babel/cli": "7.8.4",
|
|
69
69
|
"@babel/core": "7.9.6",
|
|
70
70
|
"@babel/plugin-proposal-class-properties": "7.8.3",
|
|
@@ -95,7 +95,7 @@
|
|
|
95
95
|
"@wdio/selenium-standalone-service": "5.16.5",
|
|
96
96
|
"@wdio/spec-reporter": "5.16.5",
|
|
97
97
|
"@wdio/static-server-service": "5.16.5",
|
|
98
|
-
"algoliasearch": "4.
|
|
98
|
+
"algoliasearch": "4.11.0",
|
|
99
99
|
"algoliasearch-v3": "npm:algoliasearch@3.35.1",
|
|
100
100
|
"babel-eslint": "10.0.3",
|
|
101
101
|
"babel-jest": "27.1.0",
|
|
@@ -144,13 +144,16 @@
|
|
|
144
144
|
"typescript": "4.3.5",
|
|
145
145
|
"webpack": "4.41.5"
|
|
146
146
|
},
|
|
147
|
+
"peerDependencies": {
|
|
148
|
+
"algoliasearch": ">= 3.1 < 5"
|
|
149
|
+
},
|
|
147
150
|
"resolutions": {
|
|
148
151
|
"places.js/algoliasearch": "3.35.0"
|
|
149
152
|
},
|
|
150
153
|
"bundlesize": [
|
|
151
154
|
{
|
|
152
155
|
"path": "./dist/instantsearch.production.min.js",
|
|
153
|
-
"maxSize": "69.
|
|
156
|
+
"maxSize": "69.50 kB"
|
|
154
157
|
},
|
|
155
158
|
{
|
|
156
159
|
"path": "./dist/instantsearch.development.js",
|