instantsearch.js 4.33.1 → 4.36.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 +42 -0
- package/README.md +24 -1
- package/cjs/connectors/autocomplete/connectAutocomplete.js +2 -1
- package/cjs/connectors/dynamic-widgets/connectDynamicWidgets.js +30 -5
- 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/dynamic-widgets/dynamic-widgets.js +8 -5
- package/cjs/widgets/index/index.js +20 -2
- package/dist/instantsearch.development.d.ts +23 -2
- package/dist/instantsearch.development.js +105 -37
- package/dist/instantsearch.development.js.map +1 -1
- package/dist/instantsearch.development.min.d.ts +23 -2
- package/dist/instantsearch.production.d.ts +23 -2
- package/dist/instantsearch.production.min.d.ts +23 -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/dynamic-widgets/connectDynamicWidgets.d.ts +14 -0
- package/es/connectors/dynamic-widgets/connectDynamicWidgets.js +31 -6
- 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/dynamic-widgets/dynamic-widgets.js +8 -5
- package/es/widgets/index/index.js +20 -2
- package/package.json +10 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,45 @@
|
|
|
1
|
+
# [4.36.0](https://github.com/algolia/instantsearch.js/compare/v4.35.0...v4.36.0) (2021-12-16)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* **dynamicWidgets:** send facets * and maxValuesPerFacet by default ([#4968](https://github.com/algolia/instantsearch.js/issues/4968)) ([969ae89](https://github.com/algolia/instantsearch.js/commit/969ae8980f7c8a055bb4c6c5967d04744644f555))
|
|
7
|
+
* **DynamicWidgets:** throw when transformItems returns anything that isn't an array ([#4975](https://github.com/algolia/instantsearch.js/issues/4975)) ([5c328c8](https://github.com/algolia/instantsearch.js/commit/5c328c85428eb9a5c1450fd01154751f4e0ea2fa))
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
# [4.35.0](https://github.com/algolia/instantsearch.js/compare/v4.34.0...v4.35.0) (2021-12-13)
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
### Features
|
|
15
|
+
|
|
16
|
+
* **events:** move to @algolia/events ([#4961](https://github.com/algolia/instantsearch.js/issues/4961)) ([1c56726](https://github.com/algolia/instantsearch.js/commit/1c5672640c65d7ed6f6e381a3162e508bdda44f3))
|
|
17
|
+
|
|
18
|
+
### Bug Fixes
|
|
19
|
+
|
|
20
|
+
* **deps:** Add missing peer dependency ([#4950](https://github.com/algolia/instantsearch.js/issues/4950)) ([468578da9](https://github.com/algolia/instantsearch.js/commit/468578da948a12224c892fd12cba4c880aa7b25f))
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
# [4.34.0](https://github.com/algolia/instantsearch.js/compare/v4.33.2...v4.34.0) (2021-12-07)
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
### Features
|
|
28
|
+
|
|
29
|
+
* rely on `state` in `getWidgetRenderState` ([#4960](https://github.com/algolia/instantsearch.js/issues/4960)) ([5006841](https://github.com/algolia/instantsearch.js/commit/50068417e5e7211802bc717b582946f6e630d7ac))
|
|
30
|
+
* support initial results (experimental) ([#4967](https://github.com/algolia/instantsearch.js/issues/4967)) ([db11c13](https://github.com/algolia/instantsearch.js/commit/db11c13ea55433491f5e924633bff12a303c1bc6))
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
## [4.33.2](https://github.com/algolia/instantsearch.js/compare/v4.33.1...v4.33.2) (2021-11-16)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
### Bug Fixes
|
|
38
|
+
|
|
39
|
+
* **connectNumericMenu:** allow option for same start/end values ([#4951](https://github.com/algolia/instantsearch.js/issues/4951)) ([18da714](https://github.com/algolia/instantsearch.js/commit/18da714574fa98957d29014add3123e9c377551f))
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
1
43
|
## [4.33.1](https://github.com/algolia/instantsearch.js/compare/v4.33.0...v4.33.1) (2021-11-02)
|
|
2
44
|
|
|
3
45
|
|
package/README.md
CHANGED
|
@@ -29,6 +29,7 @@ InstantSearch.js is a vanilla JavaScript library that lets you create an instant
|
|
|
29
29
|
- [Why](#why)
|
|
30
30
|
- [Getting started](#getting-started)
|
|
31
31
|
- [Installation](#installation)
|
|
32
|
+
- [TypeScript users](#typescript-users)
|
|
32
33
|
- [Documentation](#documentation)
|
|
33
34
|
- [Demos](#demos)
|
|
34
35
|
- [Playground](#playground)
|
|
@@ -102,6 +103,28 @@ npm install instantsearch.js algoliasearch
|
|
|
102
103
|
yarn add instantsearch.js algoliasearch
|
|
103
104
|
```
|
|
104
105
|
|
|
106
|
+
### TypeScript users
|
|
107
|
+
|
|
108
|
+
To use InstantSearch.js in a TypeScript environment, depending on your [`algoliasearch`](https://github.com/algolia/algoliasearch-client-javascript) version, you need to import different types.
|
|
109
|
+
|
|
110
|
+
>You still need to import these types even if you don't use InstantSearch.js with [`algoliasearch`](https://github.com/algolia/algoliasearch-client-javascript).
|
|
111
|
+
|
|
112
|
+
#### `algoliasearch` v4.x
|
|
113
|
+
|
|
114
|
+
This version uses types provided by both `algoliasearch` and `@algolia/client-search`.
|
|
115
|
+
|
|
116
|
+
```bash
|
|
117
|
+
yarn add algoliasearch@4 @algolia/client-search
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
#### `algoliasearch` v3.x
|
|
121
|
+
|
|
122
|
+
```bash
|
|
123
|
+
yarn add @types/algoliasearch@3
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
>v3.x is deprecated and will soon no longer be supported.
|
|
127
|
+
|
|
105
128
|
## Documentation
|
|
106
129
|
|
|
107
130
|
The documentation is available on the [Algolia website](https://www.algolia.com/doc/guides/building-search-ui/what-is-instantsearch/js/).
|
|
@@ -110,7 +133,7 @@ The documentation is available on the [Algolia website](https://www.algolia.com/
|
|
|
110
133
|
|
|
111
134
|
| E-commerce | Media | Travel |
|
|
112
135
|
| ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
113
|
-
| <a href="https://instantsearchjs.netlify.com/examples/e-commerce/"><img src="https://www.algolia.com/doc/assets/images/build-search-ui/demos/e-commerce-2c7ed6b6.png" width="250" alt="E-commerce demo preview"></a> | <a href="https://instantsearchjs.netlify.com/examples/media/"><img src="
|
|
136
|
+
| <a href="https://instantsearchjs.netlify.com/examples/e-commerce/"><img src="https://www.algolia.com/doc/assets/images/build-search-ui/demos/e-commerce-2c7ed6b6.png" width="250" alt="E-commerce demo preview"></a> | <a href="https://instantsearchjs.netlify.com/examples/media/"><img src="./examples/media/capture.png" width="250" alt="Media demo preview"></a> | <a href="https://instantsearchjs.netlify.com/examples/tourism/"><img src="https://instantsearchjs.netlify.com/examples/tourism/capture.png" width="250" alt="Tourism demo preview"></a> |
|
|
114
137
|
|
|
115
138
|
See more demos [on the website](https://www.algolia.com/doc/guides/building-search-ui/resources/demos/js/).
|
|
116
139
|
|
|
@@ -60,6 +60,7 @@ var connectAutocomplete = function connectAutocomplete(renderFn) {
|
|
|
60
60
|
var _this = this;
|
|
61
61
|
|
|
62
62
|
var helper = _ref4.helper,
|
|
63
|
+
state = _ref4.state,
|
|
63
64
|
scopedResults = _ref4.scopedResults,
|
|
64
65
|
instantSearchInstance = _ref4.instantSearchInstance;
|
|
65
66
|
|
|
@@ -87,7 +88,7 @@ var connectAutocomplete = function connectAutocomplete(renderFn) {
|
|
|
87
88
|
};
|
|
88
89
|
});
|
|
89
90
|
return {
|
|
90
|
-
currentRefinement:
|
|
91
|
+
currentRefinement: state.query || '',
|
|
91
92
|
indices: indices,
|
|
92
93
|
refine: connectorState.refine,
|
|
93
94
|
widgetParams: widgetParams
|
|
@@ -19,12 +19,17 @@ var withUsage = (0, _utils.createDocumentationMessageGenerator)({
|
|
|
19
19
|
name: 'dynamic-widgets',
|
|
20
20
|
connector: true
|
|
21
21
|
});
|
|
22
|
+
var MAX_WILDCARD_FACETS = 20;
|
|
22
23
|
|
|
23
24
|
var connectDynamicWidgets = function connectDynamicWidgets(renderFn) {
|
|
24
25
|
var unmountFn = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _utils.noop;
|
|
25
26
|
(0, _utils.checkRendering)(renderFn, withUsage());
|
|
26
27
|
return function (widgetParams) {
|
|
27
28
|
var widgets = widgetParams.widgets,
|
|
29
|
+
_widgetParams$maxValu = widgetParams.maxValuesPerFacet,
|
|
30
|
+
maxValuesPerFacet = _widgetParams$maxValu === void 0 ? 20 : _widgetParams$maxValu,
|
|
31
|
+
_widgetParams$facets = widgetParams.facets,
|
|
32
|
+
facets = _widgetParams$facets === void 0 ? ['*'] : _widgetParams$facets,
|
|
28
33
|
_widgetParams$transfo = widgetParams.transformItems,
|
|
29
34
|
transformItems = _widgetParams$transfo === void 0 ? function (items) {
|
|
30
35
|
return items;
|
|
@@ -37,6 +42,10 @@ var connectDynamicWidgets = function connectDynamicWidgets(renderFn) {
|
|
|
37
42
|
throw new Error(withUsage('The `widgets` option expects an array of widgets.'));
|
|
38
43
|
}
|
|
39
44
|
|
|
45
|
+
if (!(Array.isArray(facets) && facets.length <= 1 && (facets[0] === '*' || facets[0] === undefined))) {
|
|
46
|
+
throw new Error(withUsage("The `facets` option only accepts [] or [\"*\"], you passed ".concat(JSON.stringify(facets))));
|
|
47
|
+
}
|
|
48
|
+
|
|
40
49
|
var localWidgets = new Map();
|
|
41
50
|
return {
|
|
42
51
|
$$type: 'ais.dynamicWidgets',
|
|
@@ -116,6 +125,14 @@ var connectDynamicWidgets = function connectDynamicWidgets(renderFn) {
|
|
|
116
125
|
parent.removeWidgets(toRemove);
|
|
117
126
|
unmountFn();
|
|
118
127
|
},
|
|
128
|
+
getWidgetSearchParameters: function getWidgetSearchParameters(state) {
|
|
129
|
+
// broadening the scope of facets to avoid conflict between never and *
|
|
130
|
+
return facets.reduce(function (acc, curr) {
|
|
131
|
+
return acc.addFacet(curr);
|
|
132
|
+
}, state.setQueryParameters({
|
|
133
|
+
maxValuesPerFacet: Math.max(maxValuesPerFacet || 0, state.maxValuesPerFacet || 0)
|
|
134
|
+
}));
|
|
135
|
+
},
|
|
119
136
|
getRenderState: function getRenderState(renderState, renderOptions) {
|
|
120
137
|
return _objectSpread(_objectSpread({}, renderState), {}, {
|
|
121
138
|
dynamicWidgets: this.getWidgetRenderState(renderOptions)
|
|
@@ -124,7 +141,8 @@ var connectDynamicWidgets = function connectDynamicWidgets(renderFn) {
|
|
|
124
141
|
getWidgetRenderState: function getWidgetRenderState(_ref4) {
|
|
125
142
|
var _results$renderingCon, _results$renderingCon2, _results$renderingCon3, _results$renderingCon4;
|
|
126
143
|
|
|
127
|
-
var results = _ref4.results
|
|
144
|
+
var results = _ref4.results,
|
|
145
|
+
state = _ref4.state;
|
|
128
146
|
|
|
129
147
|
if (!results) {
|
|
130
148
|
return {
|
|
@@ -133,11 +151,18 @@ var connectDynamicWidgets = function connectDynamicWidgets(renderFn) {
|
|
|
133
151
|
};
|
|
134
152
|
}
|
|
135
153
|
|
|
136
|
-
var attributesToRender = (_results$renderingCon = (_results$renderingCon2 = results.renderingContent) === null || _results$renderingCon2 === void 0 ? void 0 : (_results$renderingCon3 = _results$renderingCon2.facetOrdering) === null || _results$renderingCon3 === void 0 ? void 0 : (_results$renderingCon4 = _results$renderingCon3.facets) === null || _results$renderingCon4 === void 0 ? void 0 : _results$renderingCon4.order) !== null && _results$renderingCon !== void 0 ? _results$renderingCon : []
|
|
154
|
+
var attributesToRender = transformItems((_results$renderingCon = (_results$renderingCon2 = results.renderingContent) === null || _results$renderingCon2 === void 0 ? void 0 : (_results$renderingCon3 = _results$renderingCon2.facetOrdering) === null || _results$renderingCon3 === void 0 ? void 0 : (_results$renderingCon4 = _results$renderingCon3.facets) === null || _results$renderingCon4 === void 0 ? void 0 : _results$renderingCon4.order) !== null && _results$renderingCon !== void 0 ? _results$renderingCon : [], {
|
|
155
|
+
results: results
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
if (!Array.isArray(attributesToRender)) {
|
|
159
|
+
throw new Error(withUsage('The `transformItems` option expects a function that returns an Array.'));
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
process.env.NODE_ENV === 'development' ? (0, _utils.warning)(maxValuesPerFacet >= (state.maxValuesPerFacet || 0), "The maxValuesPerFacet set by dynamic widgets (".concat(maxValuesPerFacet, ") is smaller than one of the limits set by a widget (").concat(state.maxValuesPerFacet, "). This causes a mismatch in query parameters and thus an extra network request when that widget is mounted.")) : void 0;
|
|
163
|
+
process.env.NODE_ENV === 'development' ? (0, _utils.warning)(attributesToRender.length <= MAX_WILDCARD_FACETS || widgetParams.facets !== undefined, "More than ".concat(MAX_WILDCARD_FACETS, " facets are requested to be displayed without explicitly setting which facets to retrieve. This could have a performance impact. Set \"facets\" to [] to do two smaller network requests, or explicitly to ['*'] to avoid this warning.")) : void 0;
|
|
137
164
|
return {
|
|
138
|
-
attributesToRender:
|
|
139
|
-
results: results
|
|
140
|
-
}),
|
|
165
|
+
attributesToRender: attributesToRender,
|
|
141
166
|
widgetParams: widgetParams
|
|
142
167
|
};
|
|
143
168
|
}
|
|
@@ -173,7 +173,7 @@ var connectInfiniteHits = function connectInfiniteHits(renderFn) {
|
|
|
173
173
|
index: helper.getIndex(),
|
|
174
174
|
widgetType: this.$$type
|
|
175
175
|
});
|
|
176
|
-
isFirstPage =
|
|
176
|
+
isFirstPage = state.page === undefined || getFirstReceivedPage(state, cachedHits) === 0;
|
|
177
177
|
} else {
|
|
178
178
|
var _state$page3 = state.page,
|
|
179
179
|
_page = _state$page3 === void 0 ? 0 : _state$page3;
|
|
@@ -242,6 +242,8 @@ function isRefined(state, attribute, option) {
|
|
|
242
242
|
if (option.start !== undefined && option.end !== undefined) {
|
|
243
243
|
if (option.start === option.end) {
|
|
244
244
|
return hasNumericRefinement(currentRefinements, '=', option.start);
|
|
245
|
+
} else {
|
|
246
|
+
return hasNumericRefinement(currentRefinements, '>=', option.start) && hasNumericRefinement(currentRefinements, '<=', option.end);
|
|
245
247
|
}
|
|
246
248
|
}
|
|
247
249
|
|
|
@@ -295,17 +297,17 @@ function getRefinedState(state, attribute, facetValue) {
|
|
|
295
297
|
if (refinedOption.start !== undefined) {
|
|
296
298
|
if (hasNumericRefinement(currentRefinements, '>=', refinedOption.start)) {
|
|
297
299
|
resolvedState = resolvedState.removeNumericRefinement(attribute, '>=', refinedOption.start);
|
|
298
|
-
} else {
|
|
299
|
-
resolvedState = resolvedState.addNumericRefinement(attribute, '>=', refinedOption.start);
|
|
300
300
|
}
|
|
301
|
+
|
|
302
|
+
resolvedState = resolvedState.addNumericRefinement(attribute, '>=', refinedOption.start);
|
|
301
303
|
}
|
|
302
304
|
|
|
303
305
|
if (refinedOption.end !== undefined) {
|
|
304
306
|
if (hasNumericRefinement(currentRefinements, '<=', refinedOption.end)) {
|
|
305
307
|
resolvedState = resolvedState.removeNumericRefinement(attribute, '<=', refinedOption.end);
|
|
306
|
-
} else {
|
|
307
|
-
resolvedState = resolvedState.addNumericRefinement(attribute, '<=', refinedOption.end);
|
|
308
308
|
}
|
|
309
|
+
|
|
310
|
+
resolvedState = resolvedState.addNumericRefinement(attribute, '<=', refinedOption.end);
|
|
309
311
|
}
|
|
310
312
|
|
|
311
313
|
if (typeof resolvedState.page === 'number') {
|
|
@@ -89,6 +89,7 @@ var connectPagination = function connectPagination(renderFn) {
|
|
|
89
89
|
getWidgetRenderState: function getWidgetRenderState(_ref6) {
|
|
90
90
|
var results = _ref6.results,
|
|
91
91
|
helper = _ref6.helper,
|
|
92
|
+
state = _ref6.state,
|
|
92
93
|
createURL = _ref6.createURL;
|
|
93
94
|
|
|
94
95
|
if (!connectorState.refine) {
|
|
@@ -99,14 +100,13 @@ var connectPagination = function connectPagination(renderFn) {
|
|
|
99
100
|
}
|
|
100
101
|
|
|
101
102
|
if (!connectorState.createURL) {
|
|
102
|
-
connectorState.createURL = function (
|
|
103
|
+
connectorState.createURL = function (helperState) {
|
|
103
104
|
return function (page) {
|
|
104
|
-
return createURL(
|
|
105
|
+
return createURL(helperState.setPage(page));
|
|
105
106
|
};
|
|
106
107
|
};
|
|
107
108
|
}
|
|
108
109
|
|
|
109
|
-
var state = helper.state;
|
|
110
110
|
var page = state.page || 0;
|
|
111
111
|
var nbPages = getMaxPage(results || {
|
|
112
112
|
nbPages: 0
|
|
@@ -71,11 +71,12 @@ var connectSearchBox = function connectSearchBox(renderFn) {
|
|
|
71
71
|
},
|
|
72
72
|
getWidgetRenderState: function getWidgetRenderState(_ref3) {
|
|
73
73
|
var helper = _ref3.helper,
|
|
74
|
-
searchMetadata = _ref3.searchMetadata
|
|
74
|
+
searchMetadata = _ref3.searchMetadata,
|
|
75
|
+
state = _ref3.state;
|
|
75
76
|
|
|
76
77
|
if (!_refine) {
|
|
77
78
|
var setQueryAndSearch = function setQueryAndSearch(query) {
|
|
78
|
-
if (query !==
|
|
79
|
+
if (query !== state.query) {
|
|
79
80
|
helper.setQuery(query).search();
|
|
80
81
|
}
|
|
81
82
|
};
|
|
@@ -92,7 +93,7 @@ var connectSearchBox = function connectSearchBox(renderFn) {
|
|
|
92
93
|
|
|
93
94
|
_clear = clear(helper);
|
|
94
95
|
return {
|
|
95
|
-
query:
|
|
96
|
+
query: state.query || '',
|
|
96
97
|
refine: _refine,
|
|
97
98
|
clear: _cachedClear,
|
|
98
99
|
widgetParams: widgetParams,
|
|
@@ -72,6 +72,7 @@ var connectSortBy = function connectSortBy(renderFn) {
|
|
|
72
72
|
getWidgetRenderState: function getWidgetRenderState(_ref3) {
|
|
73
73
|
var results = _ref3.results,
|
|
74
74
|
helper = _ref3.helper,
|
|
75
|
+
state = _ref3.state,
|
|
75
76
|
parent = _ref3.parent;
|
|
76
77
|
|
|
77
78
|
if (!connectorState.initialIndex && parent) {
|
|
@@ -85,7 +86,7 @@ var connectSortBy = function connectSortBy(renderFn) {
|
|
|
85
86
|
}
|
|
86
87
|
|
|
87
88
|
return {
|
|
88
|
-
currentRefinement:
|
|
89
|
+
currentRefinement: state.index,
|
|
89
90
|
options: transformItems(items),
|
|
90
91
|
refine: connectorState.setIndex,
|
|
91
92
|
hasNoResults: results ? results.nbHits === 0 : true,
|
|
@@ -50,18 +50,18 @@ var connectStats = function connectStats(renderFn) {
|
|
|
50
50
|
},
|
|
51
51
|
getWidgetRenderState: function getWidgetRenderState(_ref) {
|
|
52
52
|
var results = _ref.results,
|
|
53
|
-
|
|
53
|
+
state = _ref.state;
|
|
54
54
|
|
|
55
55
|
if (!results) {
|
|
56
56
|
return {
|
|
57
|
-
hitsPerPage:
|
|
57
|
+
hitsPerPage: state.hitsPerPage,
|
|
58
58
|
nbHits: 0,
|
|
59
59
|
nbSortedHits: undefined,
|
|
60
60
|
areHitsSorted: false,
|
|
61
61
|
nbPages: 0,
|
|
62
|
-
page:
|
|
62
|
+
page: state.page || 0,
|
|
63
63
|
processingTimeMS: -1,
|
|
64
|
-
query:
|
|
64
|
+
query: state.query || '',
|
|
65
65
|
widgetParams: widgetParams
|
|
66
66
|
};
|
|
67
67
|
}
|
|
@@ -185,7 +185,7 @@ var connectToggleRefinement = function connectToggleRefinement(renderFn) {
|
|
|
185
185
|
createURL = _ref6.createURL,
|
|
186
186
|
instantSearchInstance = _ref6.instantSearchInstance;
|
|
187
187
|
var isRefined = results ? on.every(function (v) {
|
|
188
|
-
return
|
|
188
|
+
return state.isDisjunctiveFacetRefined(attribute, v);
|
|
189
189
|
}) : on.every(function (v) {
|
|
190
190
|
return state.isDisjunctiveFacetRefined(attribute, v);
|
|
191
191
|
});
|
package/cjs/lib/InstantSearch.js
CHANGED
|
@@ -9,7 +9,7 @@ exports.default = void 0;
|
|
|
9
9
|
|
|
10
10
|
var _algoliasearchHelper = _interopRequireDefault(require("algoliasearch-helper"));
|
|
11
11
|
|
|
12
|
-
var _events = _interopRequireDefault(require("events"));
|
|
12
|
+
var _events = _interopRequireDefault(require("@algolia/events"));
|
|
13
13
|
|
|
14
14
|
var _index = _interopRequireWildcard(require("../widgets/index/index"));
|
|
15
15
|
|
|
@@ -112,6 +112,8 @@ var InstantSearch = /*#__PURE__*/function (_EventEmitter) {
|
|
|
112
112
|
|
|
113
113
|
_defineProperty(_assertThisInitialized(_this), "_initialUiState", void 0);
|
|
114
114
|
|
|
115
|
+
_defineProperty(_assertThisInitialized(_this), "_initialResults", void 0);
|
|
116
|
+
|
|
115
117
|
_defineProperty(_assertThisInitialized(_this), "_createURL", void 0);
|
|
116
118
|
|
|
117
119
|
_defineProperty(_assertThisInitialized(_this), "_searchFunction", void 0);
|
|
@@ -216,6 +218,7 @@ var InstantSearch = /*#__PURE__*/function (_EventEmitter) {
|
|
|
216
218
|
_this._isSearchStalled = false;
|
|
217
219
|
_this._createURL = defaultCreateURL;
|
|
218
220
|
_this._initialUiState = initialUiState;
|
|
221
|
+
_this._initialResults = null;
|
|
219
222
|
|
|
220
223
|
if (searchFunction) {
|
|
221
224
|
_this._searchFunction = searchFunction;
|
|
@@ -458,9 +461,27 @@ var InstantSearch = /*#__PURE__*/function (_EventEmitter) {
|
|
|
458
461
|
parent: null,
|
|
459
462
|
uiState: this._initialUiState
|
|
460
463
|
});
|
|
461
|
-
|
|
464
|
+
|
|
465
|
+
if (this._initialResults) {
|
|
466
|
+
var originalScheduleSearch = this.scheduleSearch; // We don't schedule a first search when initial results are provided
|
|
467
|
+
// because we already have the results to render. This skips the initial
|
|
468
|
+
// network request on the browser on `start`.
|
|
469
|
+
|
|
470
|
+
this.scheduleSearch = (0, _utils.defer)(_utils.noop); // We also skip the initial network request when widgets are dynamically
|
|
471
|
+
// added in the first tick (that's the case in all the framework-based flavors).
|
|
472
|
+
// When we add a widget to `index`, it calls `scheduleSearch`. We can rely
|
|
473
|
+
// on our `defer` util to restore the original `scheduleSearch` value once
|
|
474
|
+
// widgets are added to hook back to the regular lifecycle.
|
|
475
|
+
|
|
476
|
+
(0, _utils.defer)(function () {
|
|
477
|
+
_this3.scheduleSearch = originalScheduleSearch;
|
|
478
|
+
})();
|
|
479
|
+
} else {
|
|
480
|
+
this.scheduleSearch();
|
|
481
|
+
} // Keep the previous reference for legacy purpose, some pattern use
|
|
462
482
|
// the direct Helper access `search.helper` (e.g multi-index).
|
|
463
483
|
|
|
484
|
+
|
|
464
485
|
this.helper = this.mainIndex.getHelper(); // track we started the search if we add more widgets,
|
|
465
486
|
// to init them directly after add
|
|
466
487
|
|
package/cjs/lib/version.js
CHANGED
|
@@ -19,6 +19,10 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
|
19
19
|
|
|
20
20
|
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; }
|
|
21
21
|
|
|
22
|
+
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
23
|
+
|
|
24
|
+
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
25
|
+
|
|
22
26
|
var withUsage = (0, _utils.createDocumentationMessageGenerator)({
|
|
23
27
|
name: 'dynamic-widgets'
|
|
24
28
|
});
|
|
@@ -36,9 +40,9 @@ function createContainer(rootContainer) {
|
|
|
36
40
|
var dynamicWidgets = function dynamicWidgets(widgetParams) {
|
|
37
41
|
var _ref = widgetParams || {},
|
|
38
42
|
containerSelector = _ref.container,
|
|
39
|
-
transformItems = _ref.transformItems,
|
|
40
43
|
widgets = _ref.widgets,
|
|
41
|
-
fallbackWidget = _ref.fallbackWidget
|
|
44
|
+
fallbackWidget = _ref.fallbackWidget,
|
|
45
|
+
otherWidgetParams = _objectWithoutProperties(_ref, ["container", "widgets", "fallbackWidget"]);
|
|
42
46
|
|
|
43
47
|
if (!containerSelector) {
|
|
44
48
|
throw new Error(withUsage('The `container` option is required.'));
|
|
@@ -73,8 +77,7 @@ var dynamicWidgets = function dynamicWidgets(widgetParams) {
|
|
|
73
77
|
}, function () {
|
|
74
78
|
userContainer.removeChild(rootContainer);
|
|
75
79
|
});
|
|
76
|
-
var widget = makeWidget({
|
|
77
|
-
transformItems: transformItems,
|
|
80
|
+
var widget = makeWidget(_objectSpread(_objectSpread({}, otherWidgetParams), {}, {
|
|
78
81
|
widgets: connectorWidgets,
|
|
79
82
|
fallbackWidget: typeof fallbackWidget === 'function' ? function (_ref3) {
|
|
80
83
|
var attribute = _ref3.attribute;
|
|
@@ -85,7 +88,7 @@ var dynamicWidgets = function dynamicWidgets(widgetParams) {
|
|
|
85
88
|
container: container
|
|
86
89
|
});
|
|
87
90
|
} : undefined
|
|
88
|
-
});
|
|
91
|
+
}));
|
|
89
92
|
return _objectSpread(_objectSpread({}, widget), {}, {
|
|
90
93
|
init: function init(initOptions) {
|
|
91
94
|
widgets.forEach(function (cb) {
|
|
@@ -289,7 +289,8 @@ var index = function index(widgetParams) {
|
|
|
289
289
|
return this;
|
|
290
290
|
},
|
|
291
291
|
init: function init(_ref2) {
|
|
292
|
-
var _this3 = this
|
|
292
|
+
var _this3 = this,
|
|
293
|
+
_instantSearchInstanc;
|
|
293
294
|
|
|
294
295
|
var instantSearchInstance = _ref2.instantSearchInstance,
|
|
295
296
|
parent = _ref2.parent,
|
|
@@ -347,11 +348,21 @@ var index = function index(widgetParams) {
|
|
|
347
348
|
|
|
348
349
|
derivedHelper = mainHelper.derive(function () {
|
|
349
350
|
return _utils.mergeSearchParameters.apply(void 0, _toConsumableArray((0, _utils.resolveSearchParameters)(_this3)));
|
|
350
|
-
});
|
|
351
|
+
});
|
|
352
|
+
var indexInitialResults = (_instantSearchInstanc = instantSearchInstance._initialResults) === null || _instantSearchInstanc === void 0 ? void 0 : _instantSearchInstanc[this.getIndexId()];
|
|
353
|
+
|
|
354
|
+
if (indexInitialResults) {
|
|
355
|
+
// We restore the shape of the results provided to the instance to respect
|
|
356
|
+
// the helper's structure.
|
|
357
|
+
var results = new _algoliasearchHelper.default.SearchResults(new _algoliasearchHelper.default.SearchParameters(indexInitialResults.state), indexInitialResults.results);
|
|
358
|
+
derivedHelper.lastResults = results;
|
|
359
|
+
helper.lastResults = results;
|
|
360
|
+
} // Subscribe to the Helper state changes for the page before widgets
|
|
351
361
|
// are initialized. This behavior mimics the original one of the Helper.
|
|
352
362
|
// It makes sense to replicate it at the `init` step. We have another
|
|
353
363
|
// listener on `change` below, once `init` is done.
|
|
354
364
|
|
|
365
|
+
|
|
355
366
|
helper.on('change', function (_ref3) {
|
|
356
367
|
var isPageReset = _ref3.isPageReset;
|
|
357
368
|
|
|
@@ -452,6 +463,13 @@ var index = function index(widgetParams) {
|
|
|
452
463
|
instantSearchInstance.onInternalStateChange();
|
|
453
464
|
}
|
|
454
465
|
});
|
|
466
|
+
|
|
467
|
+
if (indexInitialResults) {
|
|
468
|
+
// If there are initial results, we're not notified of the next results
|
|
469
|
+
// because we don't trigger an initial search. We therefore need to directly
|
|
470
|
+
// schedule a render that will render the results injected on the helper.
|
|
471
|
+
instantSearchInstance.scheduleRender();
|
|
472
|
+
}
|
|
455
473
|
},
|
|
456
474
|
render: function render(_ref5) {
|
|
457
475
|
var _this4 = this;
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
/// <reference types="google.maps" />
|
|
2
|
-
/// <reference types="node" />
|
|
3
2
|
|
|
4
3
|
import type algoliasearch from 'algoliasearch/lite';
|
|
5
4
|
import type { AlgoliaSearchHelper } from 'algoliasearch-helper';
|
|
6
5
|
import type * as ClientSearch from '@algolia/client-search';
|
|
7
|
-
import EventEmitter from 'events';
|
|
6
|
+
import EventEmitter from '@algolia/events';
|
|
8
7
|
import type { InsightsClient as InsightsClient_2 } from 'search-insights';
|
|
9
8
|
import type { InsightsMethodMap } from 'search-insights';
|
|
10
9
|
import type * as Places from 'places.js';
|
|
@@ -1102,6 +1101,20 @@ declare type DynamicWidgetsConnectorParams = {
|
|
|
1102
1101
|
transformItems?(items: string[], metadata: {
|
|
1103
1102
|
results: SearchResults;
|
|
1104
1103
|
}): string[];
|
|
1104
|
+
/**
|
|
1105
|
+
* To prevent unneeded extra network requests when widgets mount or unmount,
|
|
1106
|
+
* we request all facet values.
|
|
1107
|
+
*
|
|
1108
|
+
* @default ['*']
|
|
1109
|
+
*/
|
|
1110
|
+
facets?: ['*'] | never[];
|
|
1111
|
+
/**
|
|
1112
|
+
* If you have more than 20 facet values pinned, you need to increase the
|
|
1113
|
+
* maxValuesPerFacet to at least that value.
|
|
1114
|
+
*
|
|
1115
|
+
* @default 20
|
|
1116
|
+
*/
|
|
1117
|
+
maxValuesPerFacet?: number;
|
|
1105
1118
|
};
|
|
1106
1119
|
|
|
1107
1120
|
declare type DynamicWidgetsRenderState = {
|
|
@@ -2194,6 +2207,13 @@ declare type InfiniteHitsWidgetParams = {
|
|
|
2194
2207
|
cache?: InfiniteHitsCache;
|
|
2195
2208
|
};
|
|
2196
2209
|
|
|
2210
|
+
declare type InitialResult = {
|
|
2211
|
+
state: PlainSearchParameters;
|
|
2212
|
+
results: SearchResults['_rawResults'];
|
|
2213
|
+
};
|
|
2214
|
+
|
|
2215
|
+
declare type InitialResults = Record<string, InitialResult>;
|
|
2216
|
+
|
|
2197
2217
|
declare type InitOptions = SharedRenderOptions & {
|
|
2198
2218
|
uiState: UiState;
|
|
2199
2219
|
results?: undefined;
|
|
@@ -2258,6 +2278,7 @@ declare class InstantSearch<TUiState extends UiState = UiState, TRouteState = TU
|
|
|
2258
2278
|
_searchStalledTimer: any;
|
|
2259
2279
|
_isSearchStalled: boolean;
|
|
2260
2280
|
_initialUiState: UiState;
|
|
2281
|
+
_initialResults: InitialResults | null;
|
|
2261
2282
|
_createURL: CreateURL<UiState>;
|
|
2262
2283
|
_searchFunction?: InstantSearchOptions['searchFunction'];
|
|
2263
2284
|
_mainHelperSearch?: AlgoliaSearchHelper['search'];
|