instantsearch.js 4.37.1 → 4.38.1
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/cjs/components/Hits/Hits.js +0 -6
- package/cjs/components/Pagination/Pagination.js +60 -41
- package/cjs/connectors/breadcrumb/connectBreadcrumb.js +6 -1
- package/cjs/connectors/clear-refinements/connectClearRefinements.js +11 -6
- package/cjs/connectors/current-refinements/connectCurrentRefinements.js +6 -2
- package/cjs/connectors/geo-search/connectGeoSearch.js +3 -1
- package/cjs/connectors/hierarchical-menu/connectHierarchicalMenu.js +3 -1
- package/cjs/connectors/hits/connectHits.js +3 -1
- package/cjs/connectors/hits-per-page/connectHitsPerPage.js +3 -1
- package/cjs/connectors/infinite-hits/connectInfiniteHits.js +3 -1
- package/cjs/connectors/menu/connectMenu.js +3 -1
- package/cjs/connectors/numeric-menu/connectNumericMenu.js +5 -3
- package/cjs/connectors/query-rules/connectQueryRules.js +3 -1
- package/cjs/connectors/refinement-list/connectRefinementList.js +8 -3
- package/cjs/connectors/search-box/connectSearchBox.js +15 -25
- package/cjs/connectors/sort-by/connectSortBy.js +3 -1
- package/cjs/helpers/highlight.js +4 -1
- package/cjs/helpers/reverseHighlight.js +4 -1
- package/cjs/helpers/reverseSnippet.js +4 -1
- package/cjs/helpers/snippet.js +4 -1
- package/cjs/lib/routers/history.js +44 -29
- package/cjs/lib/version.js +1 -1
- package/cjs/middlewares/createMetadataMiddleware.js +3 -1
- package/dist/instantsearch.development.d.ts +56 -14
- package/dist/instantsearch.development.js +194 -171
- package/dist/instantsearch.development.js.map +1 -1
- package/dist/instantsearch.production.d.ts +56 -14
- package/dist/instantsearch.production.min.d.ts +56 -14
- package/dist/instantsearch.production.min.js +2 -2
- package/dist/instantsearch.production.min.js.map +1 -1
- package/es/components/Hits/Hits.d.ts +1 -9
- package/es/components/Hits/Hits.js +0 -6
- package/es/components/Pagination/Pagination.d.ts +3 -10
- package/es/components/Pagination/Pagination.js +55 -34
- package/es/connectors/breadcrumb/connectBreadcrumb.js +6 -1
- package/es/connectors/clear-refinements/connectClearRefinements.js +11 -6
- package/es/connectors/current-refinements/connectCurrentRefinements.js +6 -2
- package/es/connectors/dynamic-widgets/connectDynamicWidgets.d.ts +4 -5
- package/es/connectors/geo-search/connectGeoSearch.js +3 -1
- package/es/connectors/hierarchical-menu/connectHierarchicalMenu.js +3 -1
- package/es/connectors/hits/connectHits.js +3 -1
- package/es/connectors/hits-per-page/connectHitsPerPage.js +3 -1
- package/es/connectors/infinite-hits/connectInfiniteHits.js +3 -1
- package/es/connectors/menu/connectMenu.js +3 -1
- package/es/connectors/numeric-menu/connectNumericMenu.js +5 -3
- package/es/connectors/query-rules/connectQueryRules.d.ts +1 -2
- package/es/connectors/query-rules/connectQueryRules.js +3 -1
- package/es/connectors/refinement-list/connectRefinementList.js +8 -3
- package/es/connectors/search-box/connectSearchBox.js +15 -25
- package/es/connectors/sort-by/connectSortBy.js +3 -1
- package/es/connectors/toggle-refinement/connectToggleRefinement.d.ts +36 -7
- package/es/helpers/highlight.js +5 -2
- package/es/helpers/reverseHighlight.js +5 -2
- package/es/helpers/reverseSnippet.js +5 -2
- package/es/helpers/snippet.js +5 -2
- package/es/lib/routers/history.d.ts +11 -0
- package/es/lib/routers/history.js +44 -29
- package/es/lib/version.d.ts +1 -1
- package/es/lib/version.js +1 -1
- package/es/middlewares/createMetadataMiddleware.js +3 -1
- package/es/types/widget.d.ts +4 -1
- package/package.json +3 -3
- package/cjs/components/Pagination/PaginationLink.js +0 -60
- package/dist/instantsearch.development.min.d.ts +0 -5217
- package/es/components/Pagination/PaginationLink.d.ts +0 -16
- package/es/components/Pagination/PaginationLink.js +0 -49
|
@@ -15,13 +15,5 @@ export declare type HitsProps = {
|
|
|
15
15
|
cssClasses: HitsComponentCSSClasses;
|
|
16
16
|
templateProps: PreparedTemplateProps<HitsComponentTemplates>;
|
|
17
17
|
};
|
|
18
|
-
declare const Hits: {
|
|
19
|
-
({ results, hits, bindEvent, cssClasses, templateProps, }: HitsProps): h.JSX.Element;
|
|
20
|
-
defaultProps: {
|
|
21
|
-
results: {
|
|
22
|
-
hits: never[];
|
|
23
|
-
};
|
|
24
|
-
hits: never[];
|
|
25
|
-
};
|
|
26
|
-
};
|
|
18
|
+
declare const Hits: ({ results, hits, bindEvent, cssClasses, templateProps, }: HitsProps) => h.JSX.Element;
|
|
27
19
|
export default Hits;
|
|
@@ -7,10 +7,10 @@ export declare type PaginationComponentTemplates = Required<PaginationTemplates>
|
|
|
7
7
|
export declare type PaginationProps = {
|
|
8
8
|
createURL(value: number): string;
|
|
9
9
|
cssClasses: PaginationComponentCSSClasses;
|
|
10
|
-
currentPage: number;
|
|
11
10
|
templates: PaginationComponentTemplates;
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
currentPage: number;
|
|
12
|
+
nbPages: number;
|
|
13
|
+
pages: number[];
|
|
14
14
|
isFirstPage: boolean;
|
|
15
15
|
isLastPage: boolean;
|
|
16
16
|
setCurrentPage(value: number): void;
|
|
@@ -20,11 +20,4 @@ export declare type PaginationProps = {
|
|
|
20
20
|
showNext?: boolean;
|
|
21
21
|
};
|
|
22
22
|
declare function Pagination(props: PaginationProps): h.JSX.Element;
|
|
23
|
-
declare namespace Pagination {
|
|
24
|
-
var defaultProps: {
|
|
25
|
-
currentPage: number;
|
|
26
|
-
nbPages: number;
|
|
27
|
-
pages: never[];
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
23
|
export default Pagination;
|
|
@@ -3,84 +3,105 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
|
|
|
3
3
|
/** @jsx h */
|
|
4
4
|
import { h } from 'preact';
|
|
5
5
|
import cx from 'classnames';
|
|
6
|
-
import PaginationLink from "./PaginationLink.js";
|
|
7
6
|
import { isSpecialClick } from "../../lib/utils/index.js";
|
|
8
|
-
var defaultProps = {
|
|
9
|
-
currentPage: 0,
|
|
10
|
-
nbPages: 0,
|
|
11
|
-
pages: []
|
|
12
|
-
};
|
|
13
7
|
|
|
14
8
|
function Pagination(props) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
9
|
+
function createClickHandler(pageNumber) {
|
|
10
|
+
return function (event) {
|
|
11
|
+
if (isSpecialClick(event)) {
|
|
12
|
+
// do not alter the default browser behavior
|
|
13
|
+
// if one special key is down
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
21
16
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
17
|
+
event.preventDefault();
|
|
18
|
+
props.setCurrentPage(pageNumber);
|
|
19
|
+
};
|
|
20
|
+
}
|
|
25
21
|
|
|
26
22
|
return h("div", {
|
|
27
23
|
className: cx(props.cssClasses.root, _defineProperty({}, props.cssClasses.noRefinementRoot, props.nbPages <= 1))
|
|
28
24
|
}, h("ul", {
|
|
29
25
|
className: props.cssClasses.list
|
|
30
26
|
}, props.showFirst && h(PaginationLink, {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
additionalClassName: props.cssClasses.firstPageItem,
|
|
27
|
+
ariaLabel: "First",
|
|
28
|
+
className: props.cssClasses.firstPageItem,
|
|
34
29
|
isDisabled: props.isFirstPage,
|
|
35
30
|
label: props.templates.first,
|
|
36
31
|
pageNumber: 0,
|
|
37
32
|
createURL: props.createURL,
|
|
38
33
|
cssClasses: props.cssClasses,
|
|
39
|
-
|
|
34
|
+
createClickHandler: createClickHandler
|
|
40
35
|
}), props.showPrevious && h(PaginationLink, {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
additionalClassName: props.cssClasses.previousPageItem,
|
|
36
|
+
ariaLabel: "Previous",
|
|
37
|
+
className: props.cssClasses.previousPageItem,
|
|
44
38
|
isDisabled: props.isFirstPage,
|
|
45
39
|
label: props.templates.previous,
|
|
46
40
|
pageNumber: props.currentPage - 1,
|
|
47
41
|
createURL: props.createURL,
|
|
48
42
|
cssClasses: props.cssClasses,
|
|
49
|
-
|
|
43
|
+
createClickHandler: createClickHandler
|
|
50
44
|
}), props.pages.map(function (pageNumber) {
|
|
51
45
|
return h(PaginationLink, {
|
|
52
46
|
key: pageNumber,
|
|
53
47
|
ariaLabel: "".concat(pageNumber + 1),
|
|
54
|
-
|
|
48
|
+
className: props.cssClasses.pageItem,
|
|
55
49
|
isSelected: pageNumber === props.currentPage,
|
|
56
50
|
label: "".concat(pageNumber + 1),
|
|
57
51
|
pageNumber: pageNumber,
|
|
58
52
|
createURL: props.createURL,
|
|
59
53
|
cssClasses: props.cssClasses,
|
|
60
|
-
|
|
54
|
+
createClickHandler: createClickHandler
|
|
61
55
|
});
|
|
62
56
|
}), props.showNext && h(PaginationLink, {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
additionalClassName: props.cssClasses.nextPageItem,
|
|
57
|
+
ariaLabel: "Next",
|
|
58
|
+
className: props.cssClasses.nextPageItem,
|
|
66
59
|
isDisabled: props.isLastPage,
|
|
67
60
|
label: props.templates.next,
|
|
68
61
|
pageNumber: props.currentPage + 1,
|
|
69
62
|
createURL: props.createURL,
|
|
70
63
|
cssClasses: props.cssClasses,
|
|
71
|
-
|
|
64
|
+
createClickHandler: createClickHandler
|
|
72
65
|
}), props.showLast && h(PaginationLink, {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
additionalClassName: props.cssClasses.lastPageItem,
|
|
66
|
+
ariaLabel: "Last",
|
|
67
|
+
className: props.cssClasses.lastPageItem,
|
|
76
68
|
isDisabled: props.isLastPage,
|
|
77
69
|
label: props.templates.last,
|
|
78
70
|
pageNumber: props.nbPages - 1,
|
|
79
71
|
createURL: props.createURL,
|
|
80
72
|
cssClasses: props.cssClasses,
|
|
81
|
-
|
|
73
|
+
createClickHandler: createClickHandler
|
|
82
74
|
})));
|
|
83
75
|
}
|
|
84
76
|
|
|
85
|
-
|
|
77
|
+
function PaginationLink(_ref) {
|
|
78
|
+
var label = _ref.label,
|
|
79
|
+
ariaLabel = _ref.ariaLabel,
|
|
80
|
+
pageNumber = _ref.pageNumber,
|
|
81
|
+
className = _ref.className,
|
|
82
|
+
_ref$isDisabled = _ref.isDisabled,
|
|
83
|
+
isDisabled = _ref$isDisabled === void 0 ? false : _ref$isDisabled,
|
|
84
|
+
_ref$isSelected = _ref.isSelected,
|
|
85
|
+
isSelected = _ref$isSelected === void 0 ? false : _ref$isSelected,
|
|
86
|
+
cssClasses = _ref.cssClasses,
|
|
87
|
+
createURL = _ref.createURL,
|
|
88
|
+
createClickHandler = _ref.createClickHandler;
|
|
89
|
+
return h("li", {
|
|
90
|
+
className: cx(cssClasses.item, className, isDisabled && cssClasses.disabledItem, isSelected && cssClasses.selectedItem)
|
|
91
|
+
}, isDisabled ? h("span", {
|
|
92
|
+
className: cssClasses.link,
|
|
93
|
+
dangerouslySetInnerHTML: {
|
|
94
|
+
__html: label
|
|
95
|
+
}
|
|
96
|
+
}) : h("a", {
|
|
97
|
+
className: cssClasses.link,
|
|
98
|
+
"aria-label": ariaLabel,
|
|
99
|
+
href: createURL(pageNumber),
|
|
100
|
+
onClick: createClickHandler(pageNumber),
|
|
101
|
+
dangerouslySetInnerHTML: {
|
|
102
|
+
__html: label
|
|
103
|
+
}
|
|
104
|
+
}));
|
|
105
|
+
}
|
|
106
|
+
|
|
86
107
|
export default Pagination;
|
|
@@ -86,6 +86,9 @@ var connectBreadcrumb = function connectBreadcrumb(renderFn) {
|
|
|
86
86
|
state = _ref2.state;
|
|
87
87
|
|
|
88
88
|
function getItems() {
|
|
89
|
+
// The hierarchicalFacets condition is required for flavors
|
|
90
|
+
// that render immediately with empty results, without relying
|
|
91
|
+
// on init() (like React InstantSearch Hooks).
|
|
89
92
|
if (!results || state.hierarchicalFacets.length === 0) {
|
|
90
93
|
return [];
|
|
91
94
|
}
|
|
@@ -95,7 +98,9 @@ var connectBreadcrumb = function connectBreadcrumb(renderFn) {
|
|
|
95
98
|
|
|
96
99
|
var facetValues = results.getFacetValues(facetName, {});
|
|
97
100
|
var data = Array.isArray(facetValues.data) ? facetValues.data : [];
|
|
98
|
-
var items = transformItems(shiftItemsValues(prepareItems(data))
|
|
101
|
+
var items = transformItems(shiftItemsValues(prepareItems(data)), {
|
|
102
|
+
results: results
|
|
103
|
+
});
|
|
99
104
|
return items;
|
|
100
105
|
}
|
|
101
106
|
|
|
@@ -80,13 +80,15 @@ var connectClearRefinements = function connectClearRefinements(renderFn) {
|
|
|
80
80
|
},
|
|
81
81
|
getWidgetRenderState: function getWidgetRenderState(_ref2) {
|
|
82
82
|
var createURL = _ref2.createURL,
|
|
83
|
-
scopedResults = _ref2.scopedResults
|
|
84
|
-
|
|
85
|
-
|
|
83
|
+
scopedResults = _ref2.scopedResults,
|
|
84
|
+
results = _ref2.results;
|
|
85
|
+
connectorState.attributesToClear = scopedResults.reduce(function (attributesToClear, scopedResult) {
|
|
86
|
+
return attributesToClear.concat(getAttributesToClear({
|
|
86
87
|
scopedResult: scopedResult,
|
|
87
88
|
includedAttributes: includedAttributes,
|
|
88
89
|
excludedAttributes: excludedAttributes,
|
|
89
|
-
transformItems: transformItems
|
|
90
|
+
transformItems: transformItems,
|
|
91
|
+
results: results
|
|
90
92
|
}));
|
|
91
93
|
}, []);
|
|
92
94
|
|
|
@@ -131,7 +133,8 @@ function getAttributesToClear(_ref5) {
|
|
|
131
133
|
var scopedResult = _ref5.scopedResult,
|
|
132
134
|
includedAttributes = _ref5.includedAttributes,
|
|
133
135
|
excludedAttributes = _ref5.excludedAttributes,
|
|
134
|
-
transformItems = _ref5.transformItems
|
|
136
|
+
transformItems = _ref5.transformItems,
|
|
137
|
+
results = _ref5.results;
|
|
135
138
|
var includesQuery = includedAttributes.indexOf('query') !== -1 || excludedAttributes.indexOf('query') === -1;
|
|
136
139
|
return {
|
|
137
140
|
helper: scopedResult.helper,
|
|
@@ -147,7 +150,9 @@ function getAttributesToClear(_ref5) {
|
|
|
147
150
|
attribute === 'query' && includesQuery || // Otherwise, ignore the excluded attributes
|
|
148
151
|
excludedAttributes.indexOf(attribute) === -1
|
|
149
152
|
);
|
|
150
|
-
}))
|
|
153
|
+
})), {
|
|
154
|
+
results: results
|
|
155
|
+
})
|
|
151
156
|
};
|
|
152
157
|
}
|
|
153
158
|
|
|
@@ -74,7 +74,9 @@ var connectCurrentRefinements = function connectCurrentRefinements(renderFn) {
|
|
|
74
74
|
helper: helper,
|
|
75
75
|
includedAttributes: includedAttributes,
|
|
76
76
|
excludedAttributes: excludedAttributes
|
|
77
|
-
})
|
|
77
|
+
}), {
|
|
78
|
+
results: results
|
|
79
|
+
});
|
|
78
80
|
}
|
|
79
81
|
|
|
80
82
|
return scopedResults.reduce(function (accResults, scopedResult) {
|
|
@@ -83,7 +85,9 @@ var connectCurrentRefinements = function connectCurrentRefinements(renderFn) {
|
|
|
83
85
|
helper: scopedResult.helper,
|
|
84
86
|
includedAttributes: includedAttributes,
|
|
85
87
|
excludedAttributes: excludedAttributes
|
|
86
|
-
})
|
|
88
|
+
}), {
|
|
89
|
+
results: results
|
|
90
|
+
}));
|
|
87
91
|
}, []);
|
|
88
92
|
}
|
|
89
93
|
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { Connector, Widget } from '../../types';
|
|
1
|
+
import type { Connector, TransformItems, TransformItemsMetadata, Widget } from '../../types';
|
|
3
2
|
export declare type DynamicWidgetsRenderState = {
|
|
4
3
|
attributesToRender: string[];
|
|
5
4
|
};
|
|
@@ -20,9 +19,9 @@ export declare type DynamicWidgetsConnectorParams = {
|
|
|
20
19
|
* Function to transform the items to render.
|
|
21
20
|
* The function also exposes the full search response.
|
|
22
21
|
*/
|
|
23
|
-
transformItems
|
|
24
|
-
results:
|
|
25
|
-
}
|
|
22
|
+
transformItems?: TransformItems<string, Omit<TransformItemsMetadata, 'results'> & {
|
|
23
|
+
results: NonNullable<TransformItemsMetadata['results']>;
|
|
24
|
+
}>;
|
|
26
25
|
/**
|
|
27
26
|
* To prevent unneeded extra network requests when widgets mount or unmount,
|
|
28
27
|
* we request all facet values.
|
|
@@ -161,7 +161,9 @@ var connectGeoSearch = function connectGeoSearch(renderFn) {
|
|
|
161
161
|
var state = helper.state;
|
|
162
162
|
var items = results ? transformItems(results.hits.filter(function (hit) {
|
|
163
163
|
return hit._geoloc;
|
|
164
|
-
})
|
|
164
|
+
}), {
|
|
165
|
+
results: results
|
|
166
|
+
}) : [];
|
|
165
167
|
|
|
166
168
|
if (!sendEvent) {
|
|
167
169
|
sendEvent = createSendEventForHits({
|
|
@@ -192,7 +192,9 @@ var connectHierarchicalMenu = function connectHierarchicalMenu(renderFn) {
|
|
|
192
192
|
|
|
193
193
|
var hasExhaustiveItems = (state.maxValuesPerFacet || 0) > getLimit() ? facetItems.length <= getLimit() : facetItems.length < getLimit();
|
|
194
194
|
canToggleShowMore = showMore && (isShowingMore || !hasExhaustiveItems);
|
|
195
|
-
items = transformItems(_prepareFacetValues(facetItems)
|
|
195
|
+
items = transformItems(_prepareFacetValues(facetItems), {
|
|
196
|
+
results: results
|
|
197
|
+
});
|
|
196
198
|
}
|
|
197
199
|
|
|
198
200
|
return {
|
|
@@ -79,7 +79,9 @@ var connectHits = function connectHits(renderFn) {
|
|
|
79
79
|
|
|
80
80
|
var hitsWithAbsolutePosition = addAbsolutePosition(results.hits, results.page, results.hitsPerPage);
|
|
81
81
|
var hitsWithAbsolutePositionAndQueryID = addQueryID(hitsWithAbsolutePosition, results.queryID);
|
|
82
|
-
var transformedHits = transformItems(hitsWithAbsolutePositionAndQueryID
|
|
82
|
+
var transformedHits = transformItems(hitsWithAbsolutePositionAndQueryID, {
|
|
83
|
+
results: results
|
|
84
|
+
});
|
|
83
85
|
return {
|
|
84
86
|
hits: transformedHits,
|
|
85
87
|
results: results,
|
|
@@ -120,7 +120,9 @@ var connectHitsPerPage = function connectHitsPerPage(renderFn) {
|
|
|
120
120
|
createURL = _ref5.createURL,
|
|
121
121
|
helper = _ref5.helper;
|
|
122
122
|
return {
|
|
123
|
-
items: transformItems(normalizeItems(state)
|
|
123
|
+
items: transformItems(normalizeItems(state), {
|
|
124
|
+
results: results
|
|
125
|
+
}),
|
|
124
126
|
refine: connectorState.getRefine(helper),
|
|
125
127
|
createURL: connectorState.createURLFactory({
|
|
126
128
|
state: state,
|
|
@@ -176,7 +176,9 @@ var connectInfiniteHits = function connectInfiniteHits(renderFn) {
|
|
|
176
176
|
|
|
177
177
|
var hitsWithAbsolutePosition = addAbsolutePosition(results.hits, results.page, results.hitsPerPage);
|
|
178
178
|
var hitsWithAbsolutePositionAndQueryID = addQueryID(hitsWithAbsolutePosition, results.queryID);
|
|
179
|
-
var transformedHits = transformItems(hitsWithAbsolutePositionAndQueryID
|
|
179
|
+
var transformedHits = transformItems(hitsWithAbsolutePositionAndQueryID, {
|
|
180
|
+
results: results
|
|
181
|
+
});
|
|
180
182
|
|
|
181
183
|
if (cachedHits[_page] === undefined) {
|
|
182
184
|
cachedHits[_page] = transformedHits;
|
|
@@ -78,8 +78,8 @@ var connectNumericMenu = function connectNumericMenu(renderFn) {
|
|
|
78
78
|
_ref2$items = _ref2.items,
|
|
79
79
|
items = _ref2$items === void 0 ? [] : _ref2$items,
|
|
80
80
|
_ref2$transformItems = _ref2.transformItems,
|
|
81
|
-
transformItems = _ref2$transformItems === void 0 ? function (
|
|
82
|
-
return
|
|
81
|
+
transformItems = _ref2$transformItems === void 0 ? function (item) {
|
|
82
|
+
return item;
|
|
83
83
|
} : _ref2$transformItems;
|
|
84
84
|
|
|
85
85
|
if (attribute === '') {
|
|
@@ -216,7 +216,9 @@ var connectNumericMenu = function connectNumericMenu(renderFn) {
|
|
|
216
216
|
|
|
217
217
|
return {
|
|
218
218
|
createURL: connectorState.createURL(state),
|
|
219
|
-
items: transformItems(prepareItems(state)
|
|
219
|
+
items: transformItems(prepareItems(state), {
|
|
220
|
+
results: results
|
|
221
|
+
}),
|
|
220
222
|
hasNoResults: results ? results.nbHits === 0 : true,
|
|
221
223
|
refine: connectorState.refine,
|
|
222
224
|
sendEvent: connectorState.sendEvent,
|
|
@@ -4,11 +4,10 @@ export declare type ParamTrackedFilters = {
|
|
|
4
4
|
[facetName: string]: (facetValues: TrackedFilterRefinement[]) => TrackedFilterRefinement[];
|
|
5
5
|
};
|
|
6
6
|
export declare type ParamTransformRuleContexts = (ruleContexts: string[]) => string[];
|
|
7
|
-
declare type ParamTransformItems = TransformItems<any>;
|
|
8
7
|
export declare type QueryRulesConnectorParams = {
|
|
9
8
|
trackedFilters?: ParamTrackedFilters;
|
|
10
9
|
transformRuleContexts?: ParamTransformRuleContexts;
|
|
11
|
-
transformItems?:
|
|
10
|
+
transformItems?: TransformItems<any>;
|
|
12
11
|
};
|
|
13
12
|
export declare type QueryRulesRenderState = {
|
|
14
13
|
items: any[];
|
|
@@ -152,7 +152,9 @@ var connectQueryRules = function connectQueryRules(_render) {
|
|
|
152
152
|
_ref4$userData = _ref4.userData,
|
|
153
153
|
userData = _ref4$userData === void 0 ? [] : _ref4$userData;
|
|
154
154
|
|
|
155
|
-
var items = transformItems(userData
|
|
155
|
+
var items = transformItems(userData, {
|
|
156
|
+
results: results
|
|
157
|
+
});
|
|
156
158
|
return {
|
|
157
159
|
items: items,
|
|
158
160
|
widgetParams: widgetParams
|
|
@@ -105,7 +105,8 @@ var connectRefinementList = function connectRefinementList(renderFn) {
|
|
|
105
105
|
var createSearchForFacetValues = function createSearchForFacetValues(helper, widget) {
|
|
106
106
|
return function (renderOptions) {
|
|
107
107
|
return function (query) {
|
|
108
|
-
var instantSearchInstance = renderOptions.instantSearchInstance
|
|
108
|
+
var instantSearchInstance = renderOptions.instantSearchInstance,
|
|
109
|
+
searchResults = renderOptions.results;
|
|
109
110
|
|
|
110
111
|
if (query === '' && lastItemsFromMainSearch) {
|
|
111
112
|
// render with previous data from the helper.
|
|
@@ -132,7 +133,9 @@ var connectRefinementList = function connectRefinementList(renderFn) {
|
|
|
132
133
|
value: value,
|
|
133
134
|
label: value
|
|
134
135
|
});
|
|
135
|
-
})
|
|
136
|
+
}), {
|
|
137
|
+
results: searchResults
|
|
138
|
+
});
|
|
136
139
|
renderFn(_objectSpread(_objectSpread({}, widget.getWidgetRenderState(_objectSpread(_objectSpread({}, renderOptions), {}, {
|
|
137
140
|
results: lastResultsFromMainSearch
|
|
138
141
|
}))), {}, {
|
|
@@ -196,7 +199,9 @@ var connectRefinementList = function connectRefinementList(renderFn) {
|
|
|
196
199
|
facetOrdering: sortBy === DEFAULT_SORT
|
|
197
200
|
});
|
|
198
201
|
facetValues = values && Array.isArray(values) ? values : [];
|
|
199
|
-
items = transformItems(facetValues.slice(0, getLimit()).map(formatItems)
|
|
202
|
+
items = transformItems(facetValues.slice(0, getLimit()).map(formatItems), {
|
|
203
|
+
results: results
|
|
204
|
+
});
|
|
200
205
|
var maxValuesPerFacetConfig = state.maxValuesPerFacet;
|
|
201
206
|
var currentLimit = getLimit(); // If the limit is the max number of facet retrieved it is impossible to know
|
|
202
207
|
// if the facets are exhaustive. The only moment we are sure it is exhaustive
|
|
@@ -10,32 +10,28 @@ var withUsage = createDocumentationMessageGenerator({
|
|
|
10
10
|
connector: true
|
|
11
11
|
});
|
|
12
12
|
|
|
13
|
+
var defaultQueryHook = function defaultQueryHook(query, hook) {
|
|
14
|
+
return hook(query);
|
|
15
|
+
};
|
|
13
16
|
/**
|
|
14
17
|
* **SearchBox** connector provides the logic to build a widget that will let the user search for a query.
|
|
15
18
|
*
|
|
16
19
|
* The connector provides to the rendering: `refine()` to set the query. The behaviour of this function
|
|
17
20
|
* may be impacted by the `queryHook` widget parameter.
|
|
18
21
|
*/
|
|
22
|
+
|
|
23
|
+
|
|
19
24
|
var connectSearchBox = function connectSearchBox(renderFn) {
|
|
20
25
|
var unmountFn = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : noop;
|
|
21
26
|
checkRendering(renderFn, withUsage());
|
|
22
27
|
return function (widgetParams) {
|
|
23
28
|
var _ref = widgetParams || {},
|
|
24
|
-
queryHook = _ref.queryHook
|
|
25
|
-
|
|
26
|
-
function clear(helper) {
|
|
27
|
-
return function () {
|
|
28
|
-
helper.setQuery('').search();
|
|
29
|
-
};
|
|
30
|
-
}
|
|
29
|
+
_ref$queryHook = _ref.queryHook,
|
|
30
|
+
queryHook = _ref$queryHook === void 0 ? defaultQueryHook : _ref$queryHook;
|
|
31
31
|
|
|
32
32
|
var _refine;
|
|
33
33
|
|
|
34
|
-
var _clear
|
|
35
|
-
|
|
36
|
-
function _cachedClear() {
|
|
37
|
-
_clear();
|
|
38
|
-
}
|
|
34
|
+
var _clear;
|
|
39
35
|
|
|
40
36
|
return {
|
|
41
37
|
$$type: 'ais.searchBox',
|
|
@@ -67,27 +63,21 @@ var connectSearchBox = function connectSearchBox(renderFn) {
|
|
|
67
63
|
state = _ref3.state;
|
|
68
64
|
|
|
69
65
|
if (!_refine) {
|
|
70
|
-
var setQueryAndSearch = function setQueryAndSearch(query) {
|
|
71
|
-
if (query !== state.query) {
|
|
72
|
-
helper.setQuery(query).search();
|
|
73
|
-
}
|
|
74
|
-
};
|
|
75
|
-
|
|
76
66
|
_refine = function _refine(query) {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
67
|
+
queryHook(query, function (q) {
|
|
68
|
+
return helper.setQuery(q).search();
|
|
69
|
+
});
|
|
70
|
+
};
|
|
81
71
|
|
|
82
|
-
|
|
72
|
+
_clear = function _clear() {
|
|
73
|
+
helper.setQuery('').search();
|
|
83
74
|
};
|
|
84
75
|
}
|
|
85
76
|
|
|
86
|
-
_clear = clear(helper);
|
|
87
77
|
return {
|
|
88
78
|
query: state.query || '',
|
|
89
79
|
refine: _refine,
|
|
90
|
-
clear:
|
|
80
|
+
clear: _clear,
|
|
91
81
|
widgetParams: widgetParams,
|
|
92
82
|
isSearchStalled: searchMetadata.isSearchStalled
|
|
93
83
|
};
|
|
@@ -79,7 +79,9 @@ var connectSortBy = function connectSortBy(renderFn) {
|
|
|
79
79
|
|
|
80
80
|
return {
|
|
81
81
|
currentRefinement: state.index,
|
|
82
|
-
options: transformItems(items
|
|
82
|
+
options: transformItems(items, {
|
|
83
|
+
results: results
|
|
84
|
+
}),
|
|
83
85
|
refine: connectorState.setIndex,
|
|
84
86
|
hasNoResults: results ? results.nbHits === 0 : true,
|
|
85
87
|
widgetParams: widgetParams
|
|
@@ -3,13 +3,19 @@ declare type BuiltInSendEventForToggle = (eventType: string, isRefined: boolean,
|
|
|
3
3
|
declare type CustomSendEventForToggle = (customPayload: any) => void;
|
|
4
4
|
export declare type SendEventForToggle = BuiltInSendEventForToggle & CustomSendEventForToggle;
|
|
5
5
|
export declare type ToggleRefinementValue = {
|
|
6
|
-
/**
|
|
6
|
+
/**
|
|
7
|
+
* Whether this option is enabled.
|
|
8
|
+
*/
|
|
7
9
|
isRefined: boolean;
|
|
8
|
-
/**
|
|
10
|
+
/**
|
|
11
|
+
* Number of result if this option is toggled.
|
|
12
|
+
*/
|
|
9
13
|
count: number | null;
|
|
10
14
|
};
|
|
11
15
|
export declare type ToggleRefinementConnectorParams = {
|
|
12
|
-
/**
|
|
16
|
+
/**
|
|
17
|
+
* Name of the attribute for faceting (e.g., "free_shipping").
|
|
18
|
+
*/
|
|
13
19
|
attribute: string;
|
|
14
20
|
/**
|
|
15
21
|
* Value to filter on when toggled.
|
|
@@ -24,19 +30,42 @@ export declare type ToggleRefinementConnectorParams = {
|
|
|
24
30
|
export declare type ToggleRefinementRenderState = {
|
|
25
31
|
/** The current toggle value */
|
|
26
32
|
value: {
|
|
33
|
+
/**
|
|
34
|
+
* The attribute name of this toggle.
|
|
35
|
+
*/
|
|
27
36
|
name: string;
|
|
37
|
+
/**
|
|
38
|
+
* Whether the current option is "on" (true) or "off" (false)
|
|
39
|
+
*/
|
|
28
40
|
isRefined: boolean;
|
|
41
|
+
/**
|
|
42
|
+
* Number of results if this option is toggled.
|
|
43
|
+
*/
|
|
29
44
|
count: number | null;
|
|
45
|
+
/**
|
|
46
|
+
* Information about the "on" toggle.
|
|
47
|
+
*/
|
|
30
48
|
onFacetValue: ToggleRefinementValue;
|
|
49
|
+
/**
|
|
50
|
+
* Information about the "off" toggle.
|
|
51
|
+
*/
|
|
31
52
|
offFacetValue: ToggleRefinementValue;
|
|
32
53
|
};
|
|
33
|
-
/**
|
|
54
|
+
/**
|
|
55
|
+
* Creates an URL for the next state.
|
|
56
|
+
*/
|
|
34
57
|
createURL: CreateURL<string>;
|
|
35
|
-
/**
|
|
58
|
+
/**
|
|
59
|
+
* Send a "Facet Clicked" Insights event.
|
|
60
|
+
*/
|
|
36
61
|
sendEvent: SendEventForToggle;
|
|
37
|
-
/**
|
|
62
|
+
/**
|
|
63
|
+
* Indicates if search state can be refined.
|
|
64
|
+
*/
|
|
38
65
|
canRefine: boolean;
|
|
39
|
-
/**
|
|
66
|
+
/**
|
|
67
|
+
* Updates to the next state by applying the toggle refinement.
|
|
68
|
+
*/
|
|
40
69
|
refine: (value?: {
|
|
41
70
|
isRefined: boolean;
|
|
42
71
|
}) => void;
|
package/es/helpers/highlight.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { component } from "../lib/suit.js";
|
|
2
|
-
import { getPropertyByPath, TAG_REPLACEMENT } from "../lib/utils/index.js";
|
|
2
|
+
import { getPropertyByPath, TAG_REPLACEMENT, warning } from "../lib/utils/index.js";
|
|
3
3
|
var suit = component('Highlight');
|
|
4
4
|
export default function highlight(_ref) {
|
|
5
5
|
var attribute = _ref.attribute,
|
|
@@ -8,8 +8,11 @@ export default function highlight(_ref) {
|
|
|
8
8
|
hit = _ref.hit,
|
|
9
9
|
_ref$cssClasses = _ref.cssClasses,
|
|
10
10
|
cssClasses = _ref$cssClasses === void 0 ? {} : _ref$cssClasses;
|
|
11
|
+
var highlightAttributeResult = getPropertyByPath(hit._highlightResult, attribute); // @MAJOR fallback to attribute value if highlight is not found
|
|
11
12
|
|
|
12
|
-
|
|
13
|
+
process.env.NODE_ENV === 'development' ? warning(highlightAttributeResult, "Could not enable highlight for \"".concat(attribute, "\", will display an empty string.\nPlease check whether this attribute exists and is either searchable or specified in `attributesToHighlight`.\n\nSee: https://alg.li/highlighting\n")) : void 0;
|
|
14
|
+
|
|
15
|
+
var _ref2 = highlightAttributeResult || {},
|
|
13
16
|
_ref2$value = _ref2.value,
|
|
14
17
|
attributeValue = _ref2$value === void 0 ? '' : _ref2$value; // cx is not used, since it would be bundled as a dependency for Vue & Angular
|
|
15
18
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { TAG_REPLACEMENT, getPropertyByPath, getHighlightedParts, reverseHighlightedParts, concatHighlightedParts } from "../lib/utils/index.js";
|
|
1
|
+
import { TAG_REPLACEMENT, getPropertyByPath, getHighlightedParts, reverseHighlightedParts, concatHighlightedParts, warning } from "../lib/utils/index.js";
|
|
2
2
|
import { component } from "../lib/suit.js";
|
|
3
3
|
var suit = component('ReverseHighlight');
|
|
4
4
|
export default function reverseHighlight(_ref) {
|
|
@@ -8,8 +8,11 @@ export default function reverseHighlight(_ref) {
|
|
|
8
8
|
hit = _ref.hit,
|
|
9
9
|
_ref$cssClasses = _ref.cssClasses,
|
|
10
10
|
cssClasses = _ref$cssClasses === void 0 ? {} : _ref$cssClasses;
|
|
11
|
+
var highlightAttributeResult = getPropertyByPath(hit._highlightResult, attribute); // @MAJOR fallback to attribute value if highlight is not found
|
|
11
12
|
|
|
12
|
-
|
|
13
|
+
process.env.NODE_ENV === 'development' ? warning(highlightAttributeResult, "Could not enable reverse highlight for \"".concat(attribute, "\", will display an empty string.\nPlease check whether this attribute exists and is either searchable or specified in `attributesToHighlight`.\n\nSee: https://alg.li/highlighting\n")) : void 0;
|
|
14
|
+
|
|
15
|
+
var _ref2 = highlightAttributeResult || {},
|
|
13
16
|
_ref2$value = _ref2.value,
|
|
14
17
|
attributeValue = _ref2$value === void 0 ? '' : _ref2$value; // cx is not used, since it would be bundled as a dependency for Vue & Angular
|
|
15
18
|
|