instantsearch.js 4.35.0 → 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 +10 -0
- package/cjs/connectors/dynamic-widgets/connectDynamicWidgets.js +30 -5
- package/cjs/lib/version.js +1 -1
- package/cjs/widgets/dynamic-widgets/dynamic-widgets.js +8 -5
- package/dist/instantsearch.development.d.ts +14 -0
- package/dist/instantsearch.development.js +36 -12
- package/dist/instantsearch.development.js.map +1 -1
- package/dist/instantsearch.development.min.d.ts +14 -0
- package/dist/instantsearch.production.d.ts +14 -0
- package/dist/instantsearch.production.min.d.ts +14 -0
- package/dist/instantsearch.production.min.js +2 -2
- package/dist/instantsearch.production.min.js.map +1 -1
- package/es/connectors/dynamic-widgets/connectDynamicWidgets.d.ts +14 -0
- package/es/connectors/dynamic-widgets/connectDynamicWidgets.js +31 -6
- package/es/lib/version.d.ts +1 -1
- package/es/lib/version.js +1 -1
- package/es/widgets/dynamic-widgets/dynamic-widgets.js +8 -5
- package/package.json +1 -1
|
@@ -23,6 +23,20 @@ export declare type DynamicWidgetsConnectorParams = {
|
|
|
23
23
|
transformItems?(items: string[], metadata: {
|
|
24
24
|
results: SearchResults;
|
|
25
25
|
}): string[];
|
|
26
|
+
/**
|
|
27
|
+
* To prevent unneeded extra network requests when widgets mount or unmount,
|
|
28
|
+
* we request all facet values.
|
|
29
|
+
*
|
|
30
|
+
* @default ['*']
|
|
31
|
+
*/
|
|
32
|
+
facets?: ['*'] | never[];
|
|
33
|
+
/**
|
|
34
|
+
* If you have more than 20 facet values pinned, you need to increase the
|
|
35
|
+
* maxValuesPerFacet to at least that value.
|
|
36
|
+
*
|
|
37
|
+
* @default 20
|
|
38
|
+
*/
|
|
39
|
+
maxValuesPerFacet?: number;
|
|
26
40
|
};
|
|
27
41
|
export declare type DynamicWidgetsWidgetDescription = {
|
|
28
42
|
$$type: 'ais.dynamicWidgets';
|
|
@@ -6,17 +6,22 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
|
|
|
6
6
|
|
|
7
7
|
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
|
8
8
|
|
|
9
|
-
import { checkRendering, createDocumentationMessageGenerator, getWidgetAttribute, noop } from '../../lib/utils';
|
|
9
|
+
import { checkRendering, createDocumentationMessageGenerator, getWidgetAttribute, noop, warning } from '../../lib/utils';
|
|
10
10
|
var withUsage = createDocumentationMessageGenerator({
|
|
11
11
|
name: 'dynamic-widgets',
|
|
12
12
|
connector: true
|
|
13
13
|
});
|
|
14
|
+
var MAX_WILDCARD_FACETS = 20;
|
|
14
15
|
|
|
15
16
|
var connectDynamicWidgets = function connectDynamicWidgets(renderFn) {
|
|
16
17
|
var unmountFn = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : noop;
|
|
17
18
|
checkRendering(renderFn, withUsage());
|
|
18
19
|
return function (widgetParams) {
|
|
19
20
|
var widgets = widgetParams.widgets,
|
|
21
|
+
_widgetParams$maxValu = widgetParams.maxValuesPerFacet,
|
|
22
|
+
maxValuesPerFacet = _widgetParams$maxValu === void 0 ? 20 : _widgetParams$maxValu,
|
|
23
|
+
_widgetParams$facets = widgetParams.facets,
|
|
24
|
+
facets = _widgetParams$facets === void 0 ? ['*'] : _widgetParams$facets,
|
|
20
25
|
_widgetParams$transfo = widgetParams.transformItems,
|
|
21
26
|
transformItems = _widgetParams$transfo === void 0 ? function (items) {
|
|
22
27
|
return items;
|
|
@@ -29,6 +34,10 @@ var connectDynamicWidgets = function connectDynamicWidgets(renderFn) {
|
|
|
29
34
|
throw new Error(withUsage('The `widgets` option expects an array of widgets.'));
|
|
30
35
|
}
|
|
31
36
|
|
|
37
|
+
if (!(Array.isArray(facets) && facets.length <= 1 && (facets[0] === '*' || facets[0] === undefined))) {
|
|
38
|
+
throw new Error(withUsage("The `facets` option only accepts [] or [\"*\"], you passed ".concat(JSON.stringify(facets))));
|
|
39
|
+
}
|
|
40
|
+
|
|
32
41
|
var localWidgets = new Map();
|
|
33
42
|
return {
|
|
34
43
|
$$type: 'ais.dynamicWidgets',
|
|
@@ -108,6 +117,14 @@ var connectDynamicWidgets = function connectDynamicWidgets(renderFn) {
|
|
|
108
117
|
parent.removeWidgets(toRemove);
|
|
109
118
|
unmountFn();
|
|
110
119
|
},
|
|
120
|
+
getWidgetSearchParameters: function getWidgetSearchParameters(state) {
|
|
121
|
+
// broadening the scope of facets to avoid conflict between never and *
|
|
122
|
+
return facets.reduce(function (acc, curr) {
|
|
123
|
+
return acc.addFacet(curr);
|
|
124
|
+
}, state.setQueryParameters({
|
|
125
|
+
maxValuesPerFacet: Math.max(maxValuesPerFacet || 0, state.maxValuesPerFacet || 0)
|
|
126
|
+
}));
|
|
127
|
+
},
|
|
111
128
|
getRenderState: function getRenderState(renderState, renderOptions) {
|
|
112
129
|
return _objectSpread(_objectSpread({}, renderState), {}, {
|
|
113
130
|
dynamicWidgets: this.getWidgetRenderState(renderOptions)
|
|
@@ -116,7 +133,8 @@ var connectDynamicWidgets = function connectDynamicWidgets(renderFn) {
|
|
|
116
133
|
getWidgetRenderState: function getWidgetRenderState(_ref4) {
|
|
117
134
|
var _results$renderingCon, _results$renderingCon2, _results$renderingCon3, _results$renderingCon4;
|
|
118
135
|
|
|
119
|
-
var results = _ref4.results
|
|
136
|
+
var results = _ref4.results,
|
|
137
|
+
state = _ref4.state;
|
|
120
138
|
|
|
121
139
|
if (!results) {
|
|
122
140
|
return {
|
|
@@ -125,11 +143,18 @@ var connectDynamicWidgets = function connectDynamicWidgets(renderFn) {
|
|
|
125
143
|
};
|
|
126
144
|
}
|
|
127
145
|
|
|
128
|
-
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 : []
|
|
146
|
+
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 : [], {
|
|
147
|
+
results: results
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
if (!Array.isArray(attributesToRender)) {
|
|
151
|
+
throw new Error(withUsage('The `transformItems` option expects a function that returns an Array.'));
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
process.env.NODE_ENV === 'development' ? 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;
|
|
155
|
+
process.env.NODE_ENV === 'development' ? 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;
|
|
129
156
|
return {
|
|
130
|
-
attributesToRender:
|
|
131
|
-
results: results
|
|
132
|
-
}),
|
|
157
|
+
attributesToRender: attributesToRender,
|
|
133
158
|
widgetParams: widgetParams
|
|
134
159
|
};
|
|
135
160
|
}
|
package/es/lib/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default: "4.
|
|
1
|
+
declare const _default: "4.36.0";
|
|
2
2
|
export default _default;
|
package/es/lib/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export default '4.
|
|
1
|
+
export default '4.36.0';
|
|
@@ -4,6 +4,10 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
|
4
4
|
|
|
5
5
|
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; }
|
|
6
6
|
|
|
7
|
+
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; }
|
|
8
|
+
|
|
9
|
+
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; }
|
|
10
|
+
|
|
7
11
|
import connectDynamicWidgets from '../../connectors/dynamic-widgets/connectDynamicWidgets';
|
|
8
12
|
import { component } from '../../lib/suit';
|
|
9
13
|
import { createDocumentationMessageGenerator, getContainerNode, getWidgetAttribute } from '../../lib/utils';
|
|
@@ -24,9 +28,9 @@ function createContainer(rootContainer) {
|
|
|
24
28
|
var dynamicWidgets = function dynamicWidgets(widgetParams) {
|
|
25
29
|
var _ref = widgetParams || {},
|
|
26
30
|
containerSelector = _ref.container,
|
|
27
|
-
transformItems = _ref.transformItems,
|
|
28
31
|
widgets = _ref.widgets,
|
|
29
|
-
fallbackWidget = _ref.fallbackWidget
|
|
32
|
+
fallbackWidget = _ref.fallbackWidget,
|
|
33
|
+
otherWidgetParams = _objectWithoutProperties(_ref, ["container", "widgets", "fallbackWidget"]);
|
|
30
34
|
|
|
31
35
|
if (!containerSelector) {
|
|
32
36
|
throw new Error(withUsage('The `container` option is required.'));
|
|
@@ -61,8 +65,7 @@ var dynamicWidgets = function dynamicWidgets(widgetParams) {
|
|
|
61
65
|
}, function () {
|
|
62
66
|
userContainer.removeChild(rootContainer);
|
|
63
67
|
});
|
|
64
|
-
var widget = makeWidget({
|
|
65
|
-
transformItems: transformItems,
|
|
68
|
+
var widget = makeWidget(_objectSpread(_objectSpread({}, otherWidgetParams), {}, {
|
|
66
69
|
widgets: connectorWidgets,
|
|
67
70
|
fallbackWidget: typeof fallbackWidget === 'function' ? function (_ref3) {
|
|
68
71
|
var attribute = _ref3.attribute;
|
|
@@ -73,7 +76,7 @@ var dynamicWidgets = function dynamicWidgets(widgetParams) {
|
|
|
73
76
|
container: container
|
|
74
77
|
});
|
|
75
78
|
} : undefined
|
|
76
|
-
});
|
|
79
|
+
}));
|
|
77
80
|
return _objectSpread(_objectSpread({}, widget), {}, {
|
|
78
81
|
init: function init(initOptions) {
|
|
79
82
|
widgets.forEach(function (cb) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "instantsearch.js",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.36.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",
|