instantsearch.js 4.44.1 → 4.45.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 +9 -0
- package/cjs/connectors/hits-per-page/connectHitsPerPage.js +3 -1
- package/cjs/connectors/numeric-menu/connectNumericMenu.js +27 -2
- package/cjs/connectors/rating-menu/connectRatingMenu.js +8 -2
- package/cjs/connectors/sort-by/connectSortBy.js +3 -1
- package/cjs/lib/version.js +1 -1
- package/dist/instantsearch.development.d.ts +20 -0
- package/dist/instantsearch.development.js +98 -8
- package/dist/instantsearch.development.js.map +1 -1
- package/dist/instantsearch.production.d.ts +20 -0
- package/dist/instantsearch.production.min.d.ts +20 -0
- package/dist/instantsearch.production.min.js +2 -2
- package/dist/instantsearch.production.min.js.map +1 -1
- package/es/connectors/hits-per-page/connectHitsPerPage.d.ts +5 -0
- package/es/connectors/hits-per-page/connectHitsPerPage.js +3 -1
- package/es/connectors/numeric-menu/connectNumericMenu.d.ts +8 -0
- package/es/connectors/numeric-menu/connectNumericMenu.js +27 -2
- package/es/connectors/rating-menu/connectRatingMenu.d.ts +2 -0
- package/es/connectors/rating-menu/connectRatingMenu.js +8 -2
- package/es/connectors/sort-by/connectSortBy.d.ts +5 -0
- package/es/connectors/sort-by/connectSortBy.js +3 -1
- package/es/lib/version.d.ts +1 -1
- package/es/lib/version.js +1 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
# [4.45.0](https://github.com/algolia/instantsearch.js/compare/v4.44.1...v4.45.0) (2022-08-29)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* **connectors:** deprecate `hasNoResults` in favor of `canRefine` ([#5091](https://github.com/algolia/instantsearch.js/issues/5091)) ([1749a4e](https://github.com/algolia/instantsearch.js/commit/1749a4eb9a2f28fa4a8d442163e3b10acbde7c22))
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
1
10
|
## [4.44.1](https://github.com/algolia/instantsearch.js/compare/v4.44.0...v4.44.1) (2022-08-25)
|
|
2
11
|
|
|
3
12
|
|
|
@@ -127,6 +127,7 @@ var connectHitsPerPage = function connectHitsPerPage(renderFn) {
|
|
|
127
127
|
results = _ref5.results,
|
|
128
128
|
createURL = _ref5.createURL,
|
|
129
129
|
helper = _ref5.helper;
|
|
130
|
+
var canRefine = results ? results.nbHits > 0 : false;
|
|
130
131
|
return {
|
|
131
132
|
items: transformItems(normalizeItems(state), {
|
|
132
133
|
results: results
|
|
@@ -136,7 +137,8 @@ var connectHitsPerPage = function connectHitsPerPage(renderFn) {
|
|
|
136
137
|
state: state,
|
|
137
138
|
createURL: createURL
|
|
138
139
|
}),
|
|
139
|
-
hasNoResults:
|
|
140
|
+
hasNoResults: !canRefine,
|
|
141
|
+
canRefine: canRefine,
|
|
140
142
|
widgetParams: widgetParams
|
|
141
143
|
};
|
|
142
144
|
},
|
|
@@ -7,6 +7,8 @@ exports.default = void 0;
|
|
|
7
7
|
|
|
8
8
|
var _index = require("../../lib/utils/index.js");
|
|
9
9
|
|
|
10
|
+
function _createForOfIteratorHelper(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e2) { throw _e2; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = o[Symbol.iterator](); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e3) { didErr = true; err = _e3; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
11
|
+
|
|
10
12
|
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
11
13
|
|
|
12
14
|
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
@@ -185,12 +187,35 @@ var connectNumericMenu = function connectNumericMenu(renderFn) {
|
|
|
185
187
|
});
|
|
186
188
|
}
|
|
187
189
|
|
|
190
|
+
var hasNoResults = results ? results.nbHits === 0 : true;
|
|
191
|
+
var preparedItems = prepareItems(state);
|
|
192
|
+
var allIsSelected = true;
|
|
193
|
+
|
|
194
|
+
var _iterator = _createForOfIteratorHelper(preparedItems),
|
|
195
|
+
_step;
|
|
196
|
+
|
|
197
|
+
try {
|
|
198
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
199
|
+
var item = _step.value;
|
|
200
|
+
|
|
201
|
+
if (item.isRefined && decodeURI(item.value) !== '{}') {
|
|
202
|
+
allIsSelected = false;
|
|
203
|
+
break;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
} catch (err) {
|
|
207
|
+
_iterator.e(err);
|
|
208
|
+
} finally {
|
|
209
|
+
_iterator.f();
|
|
210
|
+
}
|
|
211
|
+
|
|
188
212
|
return {
|
|
189
213
|
createURL: connectorState.createURL(state),
|
|
190
|
-
items: transformItems(
|
|
214
|
+
items: transformItems(preparedItems, {
|
|
191
215
|
results: results
|
|
192
216
|
}),
|
|
193
|
-
hasNoResults:
|
|
217
|
+
hasNoResults: hasNoResults,
|
|
218
|
+
canRefine: !(hasNoResults && allIsSelected),
|
|
194
219
|
refine: connectorState.refine,
|
|
195
220
|
sendEvent: connectorState.sendEvent,
|
|
196
221
|
widgetParams: widgetParams
|
|
@@ -218,6 +218,9 @@ var connectRatingMenu = function connectRatingMenu(renderFn) {
|
|
|
218
218
|
});
|
|
219
219
|
}
|
|
220
220
|
|
|
221
|
+
var refinementIsApplied = false;
|
|
222
|
+
var totalCount = 0;
|
|
223
|
+
|
|
221
224
|
if (results) {
|
|
222
225
|
var facetResults = results.getFacetValues(attribute, {});
|
|
223
226
|
var maxValuesPerFacet = facetResults.length;
|
|
@@ -233,6 +236,7 @@ var connectRatingMenu = function connectRatingMenu(renderFn) {
|
|
|
233
236
|
|
|
234
237
|
var _loop = function _loop(star) {
|
|
235
238
|
var isRefined = refinedStar === star;
|
|
239
|
+
refinementIsApplied = refinementIsApplied || isRefined;
|
|
236
240
|
var count = facetResults.filter(function (f) {
|
|
237
241
|
return Number(f.name) >= star && Number(f.name) <= max;
|
|
238
242
|
}).map(function (f) {
|
|
@@ -240,6 +244,7 @@ var connectRatingMenu = function connectRatingMenu(renderFn) {
|
|
|
240
244
|
}).reduce(function (sum, current) {
|
|
241
245
|
return sum + current;
|
|
242
246
|
}, 0);
|
|
247
|
+
totalCount += count;
|
|
243
248
|
|
|
244
249
|
if (refinedStar && !isRefined && count === 0) {
|
|
245
250
|
// skip count==0 when at least 1 refinement is enabled
|
|
@@ -269,10 +274,11 @@ var connectRatingMenu = function connectRatingMenu(renderFn) {
|
|
|
269
274
|
}
|
|
270
275
|
|
|
271
276
|
facetValues = facetValues.reverse();
|
|
277
|
+
var hasNoResults = results ? results.nbHits === 0 : true;
|
|
272
278
|
return {
|
|
273
279
|
items: facetValues,
|
|
274
|
-
hasNoResults:
|
|
275
|
-
canRefine:
|
|
280
|
+
hasNoResults: hasNoResults,
|
|
281
|
+
canRefine: (!hasNoResults || refinementIsApplied) && totalCount > 0,
|
|
276
282
|
refine: connectorState.toggleRefinementFactory(helper),
|
|
277
283
|
sendEvent: sendEvent,
|
|
278
284
|
createURL: connectorState.createURLFactory({
|
|
@@ -85,13 +85,15 @@ var connectSortBy = function connectSortBy(renderFn) {
|
|
|
85
85
|
};
|
|
86
86
|
}
|
|
87
87
|
|
|
88
|
+
var hasNoResults = results ? results.nbHits === 0 : true;
|
|
88
89
|
return {
|
|
89
90
|
currentRefinement: state.index,
|
|
90
91
|
options: transformItems(items, {
|
|
91
92
|
results: results
|
|
92
93
|
}),
|
|
93
94
|
refine: connectorState.setIndex,
|
|
94
|
-
hasNoResults:
|
|
95
|
+
hasNoResults: hasNoResults,
|
|
96
|
+
canRefine: !hasNoResults && items.length > 0,
|
|
95
97
|
widgetParams: widgetParams
|
|
96
98
|
};
|
|
97
99
|
},
|
package/cjs/lib/version.js
CHANGED
|
@@ -1872,8 +1872,13 @@ declare type HitsPerPageRenderState = {
|
|
|
1872
1872
|
refine: (value: number) => void;
|
|
1873
1873
|
/**
|
|
1874
1874
|
* Indicates whether or not the search has results.
|
|
1875
|
+
* @deprecated Use `canRefine` instead.
|
|
1875
1876
|
*/
|
|
1876
1877
|
hasNoResults: boolean;
|
|
1878
|
+
/**
|
|
1879
|
+
* Indicates if search state can be refined.
|
|
1880
|
+
*/
|
|
1881
|
+
canRefine: boolean;
|
|
1877
1882
|
};
|
|
1878
1883
|
|
|
1879
1884
|
declare type HitsPerPageRenderStateItem = {
|
|
@@ -2855,8 +2860,16 @@ declare type NumericMenuRenderState = {
|
|
|
2855
2860
|
createURL: CreateURL<NumericMenuRenderStateItem['value']>;
|
|
2856
2861
|
/**
|
|
2857
2862
|
* `true` if the last search contains no result
|
|
2863
|
+
* @deprecated Use `canRefine` instead.
|
|
2858
2864
|
*/
|
|
2859
2865
|
hasNoResults: boolean;
|
|
2866
|
+
/**
|
|
2867
|
+
* Indicates if search state can be refined.
|
|
2868
|
+
*
|
|
2869
|
+
* This is `true` if the last search contains no result and
|
|
2870
|
+
* "All" range is selected
|
|
2871
|
+
*/
|
|
2872
|
+
canRefine: boolean;
|
|
2860
2873
|
/**
|
|
2861
2874
|
* Sets the selected value and trigger a new search
|
|
2862
2875
|
*/
|
|
@@ -3721,6 +3734,8 @@ declare type RatingMenuRenderState = {
|
|
|
3721
3734
|
refine: (value: string) => void;
|
|
3722
3735
|
/**
|
|
3723
3736
|
* `true` if the last search contains no result.
|
|
3737
|
+
*
|
|
3738
|
+
* @deprecated Use `canRefine` instead.
|
|
3724
3739
|
*/
|
|
3725
3740
|
hasNoResults: boolean;
|
|
3726
3741
|
/**
|
|
@@ -4683,8 +4698,13 @@ declare type SortByRenderState = {
|
|
|
4683
4698
|
refine: (value: string) => void;
|
|
4684
4699
|
/**
|
|
4685
4700
|
* `true` if the last search contains no result.
|
|
4701
|
+
* @deprecated Use `canRefine` instead.
|
|
4686
4702
|
*/
|
|
4687
4703
|
hasNoResults: boolean;
|
|
4704
|
+
/**
|
|
4705
|
+
* `true` if we can refine.
|
|
4706
|
+
*/
|
|
4707
|
+
canRefine: boolean;
|
|
4688
4708
|
};
|
|
4689
4709
|
|
|
4690
4710
|
declare type SortByWidget = WidgetFactory<SortByWidgetDescription & {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! InstantSearch.js 4.
|
|
1
|
+
/*! InstantSearch.js 4.45.0 | © Algolia, Inc. and contributors; MIT License | https://github.com/algolia/instantsearch.js */
|
|
2
2
|
(function (global, factory) {
|
|
3
3
|
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
|
|
4
4
|
typeof define === 'function' && define.amd ? define(factory) :
|
|
@@ -297,6 +297,63 @@
|
|
|
297
297
|
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
298
298
|
}
|
|
299
299
|
|
|
300
|
+
function _createForOfIteratorHelper(o, allowArrayLike) {
|
|
301
|
+
var it;
|
|
302
|
+
|
|
303
|
+
if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) {
|
|
304
|
+
if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
|
|
305
|
+
if (it) o = it;
|
|
306
|
+
var i = 0;
|
|
307
|
+
|
|
308
|
+
var F = function () {};
|
|
309
|
+
|
|
310
|
+
return {
|
|
311
|
+
s: F,
|
|
312
|
+
n: function () {
|
|
313
|
+
if (i >= o.length) return {
|
|
314
|
+
done: true
|
|
315
|
+
};
|
|
316
|
+
return {
|
|
317
|
+
done: false,
|
|
318
|
+
value: o[i++]
|
|
319
|
+
};
|
|
320
|
+
},
|
|
321
|
+
e: function (e) {
|
|
322
|
+
throw e;
|
|
323
|
+
},
|
|
324
|
+
f: F
|
|
325
|
+
};
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
var normalCompletion = true,
|
|
332
|
+
didErr = false,
|
|
333
|
+
err;
|
|
334
|
+
return {
|
|
335
|
+
s: function () {
|
|
336
|
+
it = o[Symbol.iterator]();
|
|
337
|
+
},
|
|
338
|
+
n: function () {
|
|
339
|
+
var step = it.next();
|
|
340
|
+
normalCompletion = step.done;
|
|
341
|
+
return step;
|
|
342
|
+
},
|
|
343
|
+
e: function (e) {
|
|
344
|
+
didErr = true;
|
|
345
|
+
err = e;
|
|
346
|
+
},
|
|
347
|
+
f: function () {
|
|
348
|
+
try {
|
|
349
|
+
if (!normalCompletion && it.return != null) it.return();
|
|
350
|
+
} finally {
|
|
351
|
+
if (didErr) throw err;
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
};
|
|
355
|
+
}
|
|
356
|
+
|
|
300
357
|
function clone(value) {
|
|
301
358
|
if (typeof value === 'object' && value !== null) {
|
|
302
359
|
return _merge(Array.isArray(value) ? [] : {}, value);
|
|
@@ -8578,7 +8635,7 @@
|
|
|
8578
8635
|
instantSearchInstance.renderState = _objectSpread2(_objectSpread2({}, instantSearchInstance.renderState), {}, _defineProperty({}, parentIndexName, _objectSpread2(_objectSpread2({}, instantSearchInstance.renderState[parentIndexName]), renderState)));
|
|
8579
8636
|
}
|
|
8580
8637
|
|
|
8581
|
-
var version$1 = '4.
|
|
8638
|
+
var version$1 = '4.45.0';
|
|
8582
8639
|
|
|
8583
8640
|
var NAMESPACE = 'ais';
|
|
8584
8641
|
var component = function component(componentName) {
|
|
@@ -11612,6 +11669,7 @@
|
|
|
11612
11669
|
results = _ref5.results,
|
|
11613
11670
|
createURL = _ref5.createURL,
|
|
11614
11671
|
helper = _ref5.helper;
|
|
11672
|
+
var canRefine = results ? results.nbHits > 0 : false;
|
|
11615
11673
|
return {
|
|
11616
11674
|
items: transformItems(normalizeItems(state), {
|
|
11617
11675
|
results: results
|
|
@@ -11621,7 +11679,8 @@
|
|
|
11621
11679
|
state: state,
|
|
11622
11680
|
createURL: createURL
|
|
11623
11681
|
}),
|
|
11624
|
-
hasNoResults:
|
|
11682
|
+
hasNoResults: !canRefine,
|
|
11683
|
+
canRefine: canRefine,
|
|
11625
11684
|
widgetParams: widgetParams
|
|
11626
11685
|
};
|
|
11627
11686
|
},
|
|
@@ -12245,12 +12304,35 @@
|
|
|
12245
12304
|
});
|
|
12246
12305
|
}
|
|
12247
12306
|
|
|
12307
|
+
var hasNoResults = results ? results.nbHits === 0 : true;
|
|
12308
|
+
var preparedItems = prepareItems(state);
|
|
12309
|
+
var allIsSelected = true;
|
|
12310
|
+
|
|
12311
|
+
var _iterator = _createForOfIteratorHelper(preparedItems),
|
|
12312
|
+
_step;
|
|
12313
|
+
|
|
12314
|
+
try {
|
|
12315
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
12316
|
+
var item = _step.value;
|
|
12317
|
+
|
|
12318
|
+
if (item.isRefined && decodeURI(item.value) !== '{}') {
|
|
12319
|
+
allIsSelected = false;
|
|
12320
|
+
break;
|
|
12321
|
+
}
|
|
12322
|
+
}
|
|
12323
|
+
} catch (err) {
|
|
12324
|
+
_iterator.e(err);
|
|
12325
|
+
} finally {
|
|
12326
|
+
_iterator.f();
|
|
12327
|
+
}
|
|
12328
|
+
|
|
12248
12329
|
return {
|
|
12249
12330
|
createURL: connectorState.createURL(state),
|
|
12250
|
-
items: transformItems(
|
|
12331
|
+
items: transformItems(preparedItems, {
|
|
12251
12332
|
results: results
|
|
12252
12333
|
}),
|
|
12253
|
-
hasNoResults:
|
|
12334
|
+
hasNoResults: hasNoResults,
|
|
12335
|
+
canRefine: !(hasNoResults && allIsSelected),
|
|
12254
12336
|
refine: connectorState.refine,
|
|
12255
12337
|
sendEvent: connectorState.sendEvent,
|
|
12256
12338
|
widgetParams: widgetParams
|
|
@@ -13306,13 +13388,15 @@
|
|
|
13306
13388
|
};
|
|
13307
13389
|
}
|
|
13308
13390
|
|
|
13391
|
+
var hasNoResults = results ? results.nbHits === 0 : true;
|
|
13309
13392
|
return {
|
|
13310
13393
|
currentRefinement: state.index,
|
|
13311
13394
|
options: transformItems(items, {
|
|
13312
13395
|
results: results
|
|
13313
13396
|
}),
|
|
13314
13397
|
refine: connectorState.setIndex,
|
|
13315
|
-
hasNoResults:
|
|
13398
|
+
hasNoResults: hasNoResults,
|
|
13399
|
+
canRefine: !hasNoResults && items.length > 0,
|
|
13316
13400
|
widgetParams: widgetParams
|
|
13317
13401
|
};
|
|
13318
13402
|
},
|
|
@@ -13516,6 +13600,9 @@
|
|
|
13516
13600
|
});
|
|
13517
13601
|
}
|
|
13518
13602
|
|
|
13603
|
+
var refinementIsApplied = false;
|
|
13604
|
+
var totalCount = 0;
|
|
13605
|
+
|
|
13519
13606
|
if (results) {
|
|
13520
13607
|
var facetResults = results.getFacetValues(attribute, {});
|
|
13521
13608
|
var maxValuesPerFacet = facetResults.length;
|
|
@@ -13531,6 +13618,7 @@
|
|
|
13531
13618
|
|
|
13532
13619
|
var _loop = function _loop(star) {
|
|
13533
13620
|
var isRefined = refinedStar === star;
|
|
13621
|
+
refinementIsApplied = refinementIsApplied || isRefined;
|
|
13534
13622
|
var count = facetResults.filter(function (f) {
|
|
13535
13623
|
return Number(f.name) >= star && Number(f.name) <= max;
|
|
13536
13624
|
}).map(function (f) {
|
|
@@ -13538,6 +13626,7 @@
|
|
|
13538
13626
|
}).reduce(function (sum, current) {
|
|
13539
13627
|
return sum + current;
|
|
13540
13628
|
}, 0);
|
|
13629
|
+
totalCount += count;
|
|
13541
13630
|
|
|
13542
13631
|
if (refinedStar && !isRefined && count === 0) {
|
|
13543
13632
|
// skip count==0 when at least 1 refinement is enabled
|
|
@@ -13567,10 +13656,11 @@
|
|
|
13567
13656
|
}
|
|
13568
13657
|
|
|
13569
13658
|
facetValues = facetValues.reverse();
|
|
13659
|
+
var hasNoResults = results ? results.nbHits === 0 : true;
|
|
13570
13660
|
return {
|
|
13571
13661
|
items: facetValues,
|
|
13572
|
-
hasNoResults:
|
|
13573
|
-
canRefine:
|
|
13662
|
+
hasNoResults: hasNoResults,
|
|
13663
|
+
canRefine: (!hasNoResults || refinementIsApplied) && totalCount > 0,
|
|
13574
13664
|
refine: connectorState.toggleRefinementFactory(helper),
|
|
13575
13665
|
sendEvent: sendEvent,
|
|
13576
13666
|
createURL: connectorState.createURLFactory({
|