instantsearch.js 4.43.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 +27 -0
- package/cjs/components/Highlight/Highlight.js +33 -0
- package/cjs/components/InternalHighlight/InternalHighlight.js +16 -0
- package/cjs/components/ReverseHighlight/ReverseHighlight.js +33 -0
- package/cjs/components/ReverseSnippet/ReverseSnippet.js +33 -0
- package/cjs/components/Snippet/Snippet.js +33 -0
- package/cjs/connectors/hits-per-page/connectHitsPerPage.js +3 -1
- package/cjs/connectors/numeric-menu/connectNumericMenu.js +31 -43
- package/cjs/connectors/range/connectRange.js +7 -46
- package/cjs/connectors/rating-menu/connectRatingMenu.js +8 -2
- package/cjs/connectors/sort-by/connectSortBy.js +3 -1
- package/cjs/helpers/components/Highlight.js +45 -0
- package/cjs/helpers/components/ReverseHighlight.js +58 -0
- package/cjs/helpers/components/ReverseSnippet.js +58 -0
- package/cjs/helpers/components/Snippet.js +45 -0
- package/cjs/helpers/components/index.js +57 -0
- package/cjs/lib/version.js +1 -1
- package/dist/instantsearch.development.d.ts +29 -9
- package/dist/instantsearch.development.js +109 -120
- package/dist/instantsearch.development.js.map +1 -1
- package/dist/instantsearch.production.d.ts +29 -9
- package/dist/instantsearch.production.min.d.ts +29 -9
- package/dist/instantsearch.production.min.js +2 -2
- package/dist/instantsearch.production.min.js.map +1 -1
- package/es/components/Highlight/Highlight.d.ts +7 -0
- package/es/components/Highlight/Highlight.js +24 -0
- package/es/components/InternalHighlight/InternalHighlight.d.ts +2 -0
- package/es/components/InternalHighlight/InternalHighlight.js +6 -0
- package/es/components/ReverseHighlight/ReverseHighlight.d.ts +7 -0
- package/es/components/ReverseHighlight/ReverseHighlight.js +24 -0
- package/es/components/ReverseSnippet/ReverseSnippet.d.ts +7 -0
- package/es/components/ReverseSnippet/ReverseSnippet.js +24 -0
- package/es/components/Snippet/Snippet.d.ts +7 -0
- package/es/components/Snippet/Snippet.js +24 -0
- package/es/connectors/geo-search/connectGeoSearch.d.ts +10 -10
- 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 +32 -44
- package/es/connectors/range/connectRange.js +8 -47
- 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/helpers/components/Highlight.d.ts +10 -0
- package/es/helpers/components/Highlight.js +31 -0
- package/es/helpers/components/ReverseHighlight.d.ts +10 -0
- package/es/helpers/components/ReverseHighlight.js +44 -0
- package/es/helpers/components/ReverseSnippet.d.ts +10 -0
- package/es/helpers/components/ReverseSnippet.js +44 -0
- package/es/helpers/components/Snippet.d.ts +10 -0
- package/es/helpers/components/Snippet.js +31 -0
- package/es/helpers/components/index.d.ts +4 -0
- package/es/helpers/components/index.js +4 -0
- package/es/lib/version.d.ts +1 -1
- package/es/lib/version.js +1 -1
- package/es/types/utils.d.ts +4 -0
- package/package.json +6 -3
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { h } from 'preact';
|
|
2
|
+
import type { HighlightProps as InternalHighlightProps, HighlightClassNames as InternalHighlightClassNames } from '@algolia/ui-components-highlight-vdom';
|
|
3
|
+
export declare type HighlightClassNames = InternalHighlightClassNames;
|
|
4
|
+
export declare type HighlightProps = Omit<InternalHighlightProps, 'classNames'> & {
|
|
5
|
+
classNames?: Partial<HighlightClassNames>;
|
|
6
|
+
};
|
|
7
|
+
export declare function Highlight({ classNames, ...props }: HighlightProps): h.JSX.Element;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
2
|
+
|
|
3
|
+
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; }
|
|
4
|
+
|
|
5
|
+
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; }
|
|
6
|
+
|
|
7
|
+
/** @jsx h */
|
|
8
|
+
import { cx } from '@algolia/ui-components-shared';
|
|
9
|
+
import { h } from 'preact';
|
|
10
|
+
import { InternalHighlight } from "../InternalHighlight/InternalHighlight.js";
|
|
11
|
+
export function Highlight(_ref) {
|
|
12
|
+
var _ref$classNames = _ref.classNames,
|
|
13
|
+
classNames = _ref$classNames === void 0 ? {} : _ref$classNames,
|
|
14
|
+
props = _objectWithoutProperties(_ref, ["classNames"]);
|
|
15
|
+
|
|
16
|
+
return h(InternalHighlight, _extends({
|
|
17
|
+
classNames: {
|
|
18
|
+
root: cx('ais-Highlight', classNames.root),
|
|
19
|
+
highlighted: cx('ais-Highlight-highlighted', classNames.highlighted),
|
|
20
|
+
nonHighlighted: cx('ais-Highlight-nonHighlighted', classNames.nonHighlighted),
|
|
21
|
+
separator: cx('ais-Highlight-separator', classNames.separator)
|
|
22
|
+
}
|
|
23
|
+
}, props));
|
|
24
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { h } from 'preact';
|
|
2
|
+
import type { HighlightProps as InternalHighlightProps, HighlightClassNames as InternalHighlightClassNames } from '@algolia/ui-components-highlight-vdom';
|
|
3
|
+
export declare type ReverseHighlightClassNames = InternalHighlightClassNames;
|
|
4
|
+
export declare type ReverseHighlightProps = Omit<InternalHighlightProps, 'classNames'> & {
|
|
5
|
+
classNames?: Partial<ReverseHighlightClassNames>;
|
|
6
|
+
};
|
|
7
|
+
export declare function ReverseHighlight({ classNames, ...props }: ReverseHighlightProps): h.JSX.Element;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
2
|
+
|
|
3
|
+
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; }
|
|
4
|
+
|
|
5
|
+
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; }
|
|
6
|
+
|
|
7
|
+
/** @jsx h */
|
|
8
|
+
import { cx } from '@algolia/ui-components-shared';
|
|
9
|
+
import { h } from 'preact';
|
|
10
|
+
import { InternalHighlight } from "../InternalHighlight/InternalHighlight.js";
|
|
11
|
+
export function ReverseHighlight(_ref) {
|
|
12
|
+
var _ref$classNames = _ref.classNames,
|
|
13
|
+
classNames = _ref$classNames === void 0 ? {} : _ref$classNames,
|
|
14
|
+
props = _objectWithoutProperties(_ref, ["classNames"]);
|
|
15
|
+
|
|
16
|
+
return h(InternalHighlight, _extends({
|
|
17
|
+
classNames: {
|
|
18
|
+
root: cx('ais-ReverseHighlight', classNames.root),
|
|
19
|
+
highlighted: cx('ais-ReverseHighlight-highlighted', classNames.highlighted),
|
|
20
|
+
nonHighlighted: cx('ais-ReverseHighlight-nonHighlighted', classNames.nonHighlighted),
|
|
21
|
+
separator: cx('ais-ReverseHighlight-separator', classNames.separator)
|
|
22
|
+
}
|
|
23
|
+
}, props));
|
|
24
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { h } from 'preact';
|
|
2
|
+
import type { HighlightProps as InternalHighlightProps, HighlightClassNames as InternalHighlightClassNames } from '@algolia/ui-components-highlight-vdom';
|
|
3
|
+
export declare type ReverseSnippetClassNames = InternalHighlightClassNames;
|
|
4
|
+
export declare type ReverseSnippetProps = Omit<InternalHighlightProps, 'classNames'> & {
|
|
5
|
+
classNames?: Partial<ReverseSnippetClassNames>;
|
|
6
|
+
};
|
|
7
|
+
export declare function ReverseSnippet({ classNames, ...props }: ReverseSnippetProps): h.JSX.Element;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
2
|
+
|
|
3
|
+
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; }
|
|
4
|
+
|
|
5
|
+
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; }
|
|
6
|
+
|
|
7
|
+
/** @jsx h */
|
|
8
|
+
import { cx } from '@algolia/ui-components-shared';
|
|
9
|
+
import { h } from 'preact';
|
|
10
|
+
import { InternalHighlight } from "../InternalHighlight/InternalHighlight.js";
|
|
11
|
+
export function ReverseSnippet(_ref) {
|
|
12
|
+
var _ref$classNames = _ref.classNames,
|
|
13
|
+
classNames = _ref$classNames === void 0 ? {} : _ref$classNames,
|
|
14
|
+
props = _objectWithoutProperties(_ref, ["classNames"]);
|
|
15
|
+
|
|
16
|
+
return h(InternalHighlight, _extends({
|
|
17
|
+
classNames: {
|
|
18
|
+
root: cx('ais-ReverseSnippet', classNames.root),
|
|
19
|
+
highlighted: cx('ais-ReverseSnippet-highlighted', classNames.highlighted),
|
|
20
|
+
nonHighlighted: cx('ais-ReverseSnippet-nonHighlighted', classNames.nonHighlighted),
|
|
21
|
+
separator: cx('ais-ReverseSnippet-separator', classNames.separator)
|
|
22
|
+
}
|
|
23
|
+
}, props));
|
|
24
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { h } from 'preact';
|
|
2
|
+
import type { HighlightProps as InternalHighlightProps, HighlightClassNames as InternalHighlightClassNames } from '@algolia/ui-components-highlight-vdom';
|
|
3
|
+
export declare type SnippetClassNames = InternalHighlightClassNames;
|
|
4
|
+
export declare type SnippetProps = Omit<InternalHighlightProps, 'classNames'> & {
|
|
5
|
+
classNames?: Partial<SnippetClassNames>;
|
|
6
|
+
};
|
|
7
|
+
export declare function Snippet({ classNames, ...props }: SnippetProps): h.JSX.Element;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
2
|
+
|
|
3
|
+
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; }
|
|
4
|
+
|
|
5
|
+
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; }
|
|
6
|
+
|
|
7
|
+
/** @jsx h */
|
|
8
|
+
import { cx } from '@algolia/ui-components-shared';
|
|
9
|
+
import { h } from 'preact';
|
|
10
|
+
import { InternalHighlight } from "../InternalHighlight/InternalHighlight.js";
|
|
11
|
+
export function Snippet(_ref) {
|
|
12
|
+
var _ref$classNames = _ref.classNames,
|
|
13
|
+
classNames = _ref$classNames === void 0 ? {} : _ref$classNames,
|
|
14
|
+
props = _objectWithoutProperties(_ref, ["classNames"]);
|
|
15
|
+
|
|
16
|
+
return h(InternalHighlight, _extends({
|
|
17
|
+
classNames: {
|
|
18
|
+
root: cx('ais-Snippet', classNames.root),
|
|
19
|
+
highlighted: cx('ais-Snippet-highlighted', classNames.highlighted),
|
|
20
|
+
nonHighlighted: cx('ais-Snippet-nonHighlighted', classNames.nonHighlighted),
|
|
21
|
+
separator: cx('ais-Snippet-separator', classNames.separator)
|
|
22
|
+
}
|
|
23
|
+
}, props));
|
|
24
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { SendEventForHits } from '../../lib/utils';
|
|
2
|
-
import type { Connector, GeoLoc, Hit, TransformItems, WidgetRenderState } from '../../types';
|
|
3
|
-
export declare type GeoHit = Hit & Required<Pick<Hit, '_geoloc'>>;
|
|
2
|
+
import type { BaseHit, Connector, GeoLoc, Hit, TransformItems, WidgetRenderState } from '../../types';
|
|
3
|
+
export declare type GeoHit<THit extends BaseHit = Record<string, any>> = Hit<THit> & Required<Pick<Hit, '_geoloc'>>;
|
|
4
4
|
declare type Bounds = {
|
|
5
5
|
/**
|
|
6
6
|
* The top right corner of the map view.
|
|
@@ -11,7 +11,7 @@ declare type Bounds = {
|
|
|
11
11
|
*/
|
|
12
12
|
southWest: GeoLoc;
|
|
13
13
|
};
|
|
14
|
-
export declare type GeoSearchRenderState = {
|
|
14
|
+
export declare type GeoSearchRenderState<THit extends BaseHit = Record<string, any>> = {
|
|
15
15
|
/**
|
|
16
16
|
* Reset the current bounding box refinement.
|
|
17
17
|
*/
|
|
@@ -35,7 +35,7 @@ export declare type GeoSearchRenderState = {
|
|
|
35
35
|
/**
|
|
36
36
|
* The matched hits from Algolia API.
|
|
37
37
|
*/
|
|
38
|
-
items: GeoHit
|
|
38
|
+
items: Array<GeoHit<THit>>;
|
|
39
39
|
/**
|
|
40
40
|
* The current position of the search.
|
|
41
41
|
*/
|
|
@@ -59,7 +59,7 @@ export declare type GeoSearchRenderState = {
|
|
|
59
59
|
*/
|
|
60
60
|
toggleRefineOnMapMove(): void;
|
|
61
61
|
};
|
|
62
|
-
export declare type GeoSearchConnectorParams = {
|
|
62
|
+
export declare type GeoSearchConnectorParams<THit extends BaseHit = Record<string, any>> = {
|
|
63
63
|
/**
|
|
64
64
|
* If true, refine will be triggered as you move the map.
|
|
65
65
|
* @default true
|
|
@@ -69,13 +69,13 @@ export declare type GeoSearchConnectorParams = {
|
|
|
69
69
|
* Function to transform the items passed to the templates.
|
|
70
70
|
* @default items => items
|
|
71
71
|
*/
|
|
72
|
-
transformItems?: TransformItems<GeoHit
|
|
72
|
+
transformItems?: TransformItems<GeoHit<THit>>;
|
|
73
73
|
};
|
|
74
|
-
export declare type GeoSearchWidgetDescription = {
|
|
74
|
+
export declare type GeoSearchWidgetDescription<THit extends BaseHit = Record<string, any>> = {
|
|
75
75
|
$$type: 'ais.geoSearch';
|
|
76
|
-
renderState: GeoSearchRenderState
|
|
76
|
+
renderState: GeoSearchRenderState<THit>;
|
|
77
77
|
indexRenderState: {
|
|
78
|
-
geoSearch: WidgetRenderState<GeoSearchRenderState
|
|
78
|
+
geoSearch: WidgetRenderState<GeoSearchRenderState<THit>, GeoSearchConnectorParams<THit>>;
|
|
79
79
|
};
|
|
80
80
|
indexUiState: {
|
|
81
81
|
geoSearch: {
|
|
@@ -90,7 +90,7 @@ export declare type GeoSearchWidgetDescription = {
|
|
|
90
90
|
};
|
|
91
91
|
};
|
|
92
92
|
};
|
|
93
|
-
export declare type GeoSearchConnector = Connector<GeoSearchWidgetDescription
|
|
93
|
+
export declare type GeoSearchConnector<THit extends BaseHit = Record<string, any>> = Connector<GeoSearchWidgetDescription<THit>, GeoSearchConnectorParams<THit>>;
|
|
94
94
|
/**
|
|
95
95
|
* The **GeoSearch** connector provides the logic to build a widget that will display the results on a map. It also provides a way to search for results based on their position. The connector provides functions to manage the search experience (search on map interaction or control the interaction for example).
|
|
96
96
|
*
|
|
@@ -50,8 +50,13 @@ export declare type HitsPerPageRenderState = {
|
|
|
50
50
|
refine: (value: number) => void;
|
|
51
51
|
/**
|
|
52
52
|
* Indicates whether or not the search has results.
|
|
53
|
+
* @deprecated Use `canRefine` instead.
|
|
53
54
|
*/
|
|
54
55
|
hasNoResults: boolean;
|
|
56
|
+
/**
|
|
57
|
+
* Indicates if search state can be refined.
|
|
58
|
+
*/
|
|
59
|
+
canRefine: boolean;
|
|
55
60
|
};
|
|
56
61
|
export declare type HitsPerPageWidgetDescription = {
|
|
57
62
|
$$type: 'ais.hitsPerPage';
|
|
@@ -119,6 +119,7 @@ var connectHitsPerPage = function connectHitsPerPage(renderFn) {
|
|
|
119
119
|
results = _ref5.results,
|
|
120
120
|
createURL = _ref5.createURL,
|
|
121
121
|
helper = _ref5.helper;
|
|
122
|
+
var canRefine = results ? results.nbHits > 0 : false;
|
|
122
123
|
return {
|
|
123
124
|
items: transformItems(normalizeItems(state), {
|
|
124
125
|
results: results
|
|
@@ -128,7 +129,8 @@ var connectHitsPerPage = function connectHitsPerPage(renderFn) {
|
|
|
128
129
|
state: state,
|
|
129
130
|
createURL: createURL
|
|
130
131
|
}),
|
|
131
|
-
hasNoResults:
|
|
132
|
+
hasNoResults: !canRefine,
|
|
133
|
+
canRefine: canRefine,
|
|
132
134
|
widgetParams: widgetParams
|
|
133
135
|
};
|
|
134
136
|
},
|
|
@@ -56,8 +56,16 @@ export declare type NumericMenuRenderState = {
|
|
|
56
56
|
createURL: CreateURL<NumericMenuRenderStateItem['value']>;
|
|
57
57
|
/**
|
|
58
58
|
* `true` if the last search contains no result
|
|
59
|
+
* @deprecated Use `canRefine` instead.
|
|
59
60
|
*/
|
|
60
61
|
hasNoResults: boolean;
|
|
62
|
+
/**
|
|
63
|
+
* Indicates if search state can be refined.
|
|
64
|
+
*
|
|
65
|
+
* This is `true` if the last search contains no result and
|
|
66
|
+
* "All" range is selected
|
|
67
|
+
*/
|
|
68
|
+
canRefine: boolean;
|
|
61
69
|
/**
|
|
62
70
|
* Sets the selected value and trigger a new search
|
|
63
71
|
*/
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
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; } } }; }
|
|
2
|
+
|
|
1
3
|
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
2
4
|
|
|
3
5
|
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."); }
|
|
@@ -16,7 +18,7 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
|
16
18
|
|
|
17
19
|
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; }
|
|
18
20
|
|
|
19
|
-
import { checkRendering, createDocumentationMessageGenerator, isFiniteNumber,
|
|
21
|
+
import { checkRendering, createDocumentationMessageGenerator, isFiniteNumber, noop } from "../../lib/utils/index.js";
|
|
20
22
|
var withUsage = createDocumentationMessageGenerator({
|
|
21
23
|
name: 'numeric-menu',
|
|
22
24
|
connector: true
|
|
@@ -24,46 +26,11 @@ var withUsage = createDocumentationMessageGenerator({
|
|
|
24
26
|
var $$type = 'ais.numericMenu';
|
|
25
27
|
|
|
26
28
|
var createSendEvent = function createSendEvent(_ref) {
|
|
27
|
-
var instantSearchInstance = _ref.instantSearchInstance
|
|
28
|
-
helper = _ref.helper,
|
|
29
|
-
attribute = _ref.attribute;
|
|
29
|
+
var instantSearchInstance = _ref.instantSearchInstance;
|
|
30
30
|
return function () {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
if (args.length === 1) {
|
|
36
|
-
instantSearchInstance.sendEventToInsights(args[0]);
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
var eventType = args[0],
|
|
41
|
-
facetValue = args[1],
|
|
42
|
-
_args$ = args[2],
|
|
43
|
-
eventName = _args$ === void 0 ? 'Filter Applied' : _args$;
|
|
44
|
-
|
|
45
|
-
if (eventType !== 'click') {
|
|
31
|
+
if (arguments.length === 1) {
|
|
32
|
+
instantSearchInstance.sendEventToInsights(arguments.length <= 0 ? undefined : arguments[0]);
|
|
46
33
|
return;
|
|
47
|
-
} // facetValue === "%7B%22start%22:5,%22end%22:10%7D"
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
var filters = convertNumericRefinementsToFilters(getRefinedState(helper.state, attribute, facetValue), attribute);
|
|
51
|
-
|
|
52
|
-
if (filters && filters.length > 0) {
|
|
53
|
-
/*
|
|
54
|
-
filters === ["price<=10", "price>=5"]
|
|
55
|
-
*/
|
|
56
|
-
instantSearchInstance.sendEventToInsights({
|
|
57
|
-
insightsMethod: 'clickedFilters',
|
|
58
|
-
widgetType: $$type,
|
|
59
|
-
eventType: eventType,
|
|
60
|
-
payload: {
|
|
61
|
-
eventName: eventName,
|
|
62
|
-
index: helper.getIndex(),
|
|
63
|
-
filters: filters
|
|
64
|
-
},
|
|
65
|
-
attribute: attribute
|
|
66
|
-
});
|
|
67
34
|
}
|
|
68
35
|
};
|
|
69
36
|
};
|
|
@@ -208,18 +175,39 @@ var connectNumericMenu = function connectNumericMenu(renderFn) {
|
|
|
208
175
|
|
|
209
176
|
if (!connectorState.sendEvent) {
|
|
210
177
|
connectorState.sendEvent = createSendEvent({
|
|
211
|
-
instantSearchInstance: instantSearchInstance
|
|
212
|
-
helper: helper,
|
|
213
|
-
attribute: attribute
|
|
178
|
+
instantSearchInstance: instantSearchInstance
|
|
214
179
|
});
|
|
215
180
|
}
|
|
216
181
|
|
|
182
|
+
var hasNoResults = results ? results.nbHits === 0 : true;
|
|
183
|
+
var preparedItems = prepareItems(state);
|
|
184
|
+
var allIsSelected = true;
|
|
185
|
+
|
|
186
|
+
var _iterator = _createForOfIteratorHelper(preparedItems),
|
|
187
|
+
_step;
|
|
188
|
+
|
|
189
|
+
try {
|
|
190
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
191
|
+
var item = _step.value;
|
|
192
|
+
|
|
193
|
+
if (item.isRefined && decodeURI(item.value) !== '{}') {
|
|
194
|
+
allIsSelected = false;
|
|
195
|
+
break;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
} catch (err) {
|
|
199
|
+
_iterator.e(err);
|
|
200
|
+
} finally {
|
|
201
|
+
_iterator.f();
|
|
202
|
+
}
|
|
203
|
+
|
|
217
204
|
return {
|
|
218
205
|
createURL: connectorState.createURL(state),
|
|
219
|
-
items: transformItems(
|
|
206
|
+
items: transformItems(preparedItems, {
|
|
220
207
|
results: results
|
|
221
208
|
}),
|
|
222
|
-
hasNoResults:
|
|
209
|
+
hasNoResults: hasNoResults,
|
|
210
|
+
canRefine: !(hasNoResults && allIsSelected),
|
|
223
211
|
refine: connectorState.refine,
|
|
224
212
|
sendEvent: connectorState.sendEvent,
|
|
225
213
|
widgetParams: widgetParams
|
|
@@ -16,7 +16,7 @@ function _iterableToArrayLimit(arr, i) { if (typeof Symbol === "undefined" || !(
|
|
|
16
16
|
|
|
17
17
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
18
18
|
|
|
19
|
-
import { checkRendering, createDocumentationMessageGenerator,
|
|
19
|
+
import { checkRendering, createDocumentationMessageGenerator, isFiniteNumber, find, noop } from "../../lib/utils/index.js";
|
|
20
20
|
var withUsage = createDocumentationMessageGenerator({
|
|
21
21
|
name: 'range-input',
|
|
22
22
|
connector: true
|
|
@@ -148,50 +148,12 @@ var connectRange = function connectRange(renderFn) {
|
|
|
148
148
|
return null;
|
|
149
149
|
};
|
|
150
150
|
|
|
151
|
-
var
|
|
152
|
-
var eventName = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'Filter Applied';
|
|
153
|
-
var filters = convertNumericRefinementsToFilters(refinedState, attribute);
|
|
154
|
-
|
|
155
|
-
if (filters && filters.length > 0) {
|
|
156
|
-
instantSearchInstance.sendEventToInsights({
|
|
157
|
-
insightsMethod: 'clickedFilters',
|
|
158
|
-
widgetType: $$type,
|
|
159
|
-
eventType: 'click',
|
|
160
|
-
payload: {
|
|
161
|
-
eventName: eventName,
|
|
162
|
-
index: helper.getIndex(),
|
|
163
|
-
filters: filters
|
|
164
|
-
},
|
|
165
|
-
attribute: attribute
|
|
166
|
-
});
|
|
167
|
-
}
|
|
168
|
-
};
|
|
169
|
-
|
|
170
|
-
var createSendEvent = function createSendEvent(instantSearchInstance, helper, currentRange) {
|
|
151
|
+
var createSendEvent = function createSendEvent(instantSearchInstance) {
|
|
171
152
|
return function () {
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
if (args.length === 1) {
|
|
177
|
-
instantSearchInstance.sendEventToInsights(args[0]);
|
|
153
|
+
if (arguments.length === 1) {
|
|
154
|
+
instantSearchInstance.sendEventToInsights(arguments.length <= 0 ? undefined : arguments[0]);
|
|
178
155
|
return;
|
|
179
156
|
}
|
|
180
|
-
|
|
181
|
-
var eventType = args[0],
|
|
182
|
-
facetValue = args[1],
|
|
183
|
-
eventName = args[2];
|
|
184
|
-
|
|
185
|
-
if (eventType !== 'click') {
|
|
186
|
-
return;
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
var _facetValue = _slicedToArray(facetValue, 2),
|
|
190
|
-
nextMin = _facetValue[0],
|
|
191
|
-
nextMax = _facetValue[1];
|
|
192
|
-
|
|
193
|
-
var refinedState = getRefinedState(helper, currentRange, nextMin, nextMax);
|
|
194
|
-
sendEventWithRefinedState(refinedState, instantSearchInstance, helper, eventName);
|
|
195
157
|
};
|
|
196
158
|
};
|
|
197
159
|
|
|
@@ -237,7 +199,7 @@ var connectRange = function connectRange(renderFn) {
|
|
|
237
199
|
return [min, max];
|
|
238
200
|
}
|
|
239
201
|
|
|
240
|
-
function _refine(
|
|
202
|
+
function _refine(helper, currentRange) {
|
|
241
203
|
return function () {
|
|
242
204
|
var _ref11 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [undefined, undefined],
|
|
243
205
|
_ref12 = _slicedToArray(_ref11, 2),
|
|
@@ -247,7 +209,6 @@ var connectRange = function connectRange(renderFn) {
|
|
|
247
209
|
var refinedState = getRefinedState(helper, currentRange, nextMin, nextMax);
|
|
248
210
|
|
|
249
211
|
if (refinedState) {
|
|
250
|
-
sendEventWithRefinedState(refinedState, instantSearchInstance, helper);
|
|
251
212
|
helper.setState(refinedState).search();
|
|
252
213
|
}
|
|
253
214
|
};
|
|
@@ -293,12 +254,12 @@ var connectRange = function connectRange(renderFn) {
|
|
|
293
254
|
// On first render pass an empty range
|
|
294
255
|
// to be able to bypass the validation
|
|
295
256
|
// related to it
|
|
296
|
-
refine = _refine(
|
|
257
|
+
refine = _refine(helper, {
|
|
297
258
|
min: undefined,
|
|
298
259
|
max: undefined
|
|
299
260
|
});
|
|
300
261
|
} else {
|
|
301
|
-
refine = _refine(
|
|
262
|
+
refine = _refine(helper, currentRange);
|
|
302
263
|
}
|
|
303
264
|
|
|
304
265
|
return {
|
|
@@ -306,7 +267,7 @@ var connectRange = function connectRange(renderFn) {
|
|
|
306
267
|
canRefine: currentRange.min !== currentRange.max,
|
|
307
268
|
format: rangeFormatter,
|
|
308
269
|
range: currentRange,
|
|
309
|
-
sendEvent: createSendEvent(instantSearchInstance
|
|
270
|
+
sendEvent: createSendEvent(instantSearchInstance),
|
|
310
271
|
widgetParams: _objectSpread(_objectSpread({}, widgetParams), {}, {
|
|
311
272
|
precision: precision
|
|
312
273
|
}),
|
|
@@ -210,6 +210,9 @@ var connectRatingMenu = function connectRatingMenu(renderFn) {
|
|
|
210
210
|
});
|
|
211
211
|
}
|
|
212
212
|
|
|
213
|
+
var refinementIsApplied = false;
|
|
214
|
+
var totalCount = 0;
|
|
215
|
+
|
|
213
216
|
if (results) {
|
|
214
217
|
var facetResults = results.getFacetValues(attribute, {});
|
|
215
218
|
var maxValuesPerFacet = facetResults.length;
|
|
@@ -225,6 +228,7 @@ var connectRatingMenu = function connectRatingMenu(renderFn) {
|
|
|
225
228
|
|
|
226
229
|
var _loop = function _loop(star) {
|
|
227
230
|
var isRefined = refinedStar === star;
|
|
231
|
+
refinementIsApplied = refinementIsApplied || isRefined;
|
|
228
232
|
var count = facetResults.filter(function (f) {
|
|
229
233
|
return Number(f.name) >= star && Number(f.name) <= max;
|
|
230
234
|
}).map(function (f) {
|
|
@@ -232,6 +236,7 @@ var connectRatingMenu = function connectRatingMenu(renderFn) {
|
|
|
232
236
|
}).reduce(function (sum, current) {
|
|
233
237
|
return sum + current;
|
|
234
238
|
}, 0);
|
|
239
|
+
totalCount += count;
|
|
235
240
|
|
|
236
241
|
if (refinedStar && !isRefined && count === 0) {
|
|
237
242
|
// skip count==0 when at least 1 refinement is enabled
|
|
@@ -261,10 +266,11 @@ var connectRatingMenu = function connectRatingMenu(renderFn) {
|
|
|
261
266
|
}
|
|
262
267
|
|
|
263
268
|
facetValues = facetValues.reverse();
|
|
269
|
+
var hasNoResults = results ? results.nbHits === 0 : true;
|
|
264
270
|
return {
|
|
265
271
|
items: facetValues,
|
|
266
|
-
hasNoResults:
|
|
267
|
-
canRefine:
|
|
272
|
+
hasNoResults: hasNoResults,
|
|
273
|
+
canRefine: (!hasNoResults || refinementIsApplied) && totalCount > 0,
|
|
268
274
|
refine: connectorState.toggleRefinementFactory(helper),
|
|
269
275
|
sendEvent: sendEvent,
|
|
270
276
|
createURL: connectorState.createURLFactory({
|
|
@@ -43,8 +43,13 @@ export declare type SortByRenderState = {
|
|
|
43
43
|
refine: (value: string) => void;
|
|
44
44
|
/**
|
|
45
45
|
* `true` if the last search contains no result.
|
|
46
|
+
* @deprecated Use `canRefine` instead.
|
|
46
47
|
*/
|
|
47
48
|
hasNoResults: boolean;
|
|
49
|
+
/**
|
|
50
|
+
* `true` if we can refine.
|
|
51
|
+
*/
|
|
52
|
+
canRefine: boolean;
|
|
48
53
|
};
|
|
49
54
|
export declare type SortByWidgetDescription = {
|
|
50
55
|
$$type: 'ais.sortBy';
|
|
@@ -77,13 +77,15 @@ var connectSortBy = function connectSortBy(renderFn) {
|
|
|
77
77
|
};
|
|
78
78
|
}
|
|
79
79
|
|
|
80
|
+
var hasNoResults = results ? results.nbHits === 0 : true;
|
|
80
81
|
return {
|
|
81
82
|
currentRefinement: state.index,
|
|
82
83
|
options: transformItems(items, {
|
|
83
84
|
results: results
|
|
84
85
|
}),
|
|
85
86
|
refine: connectorState.setIndex,
|
|
86
|
-
hasNoResults:
|
|
87
|
+
hasNoResults: hasNoResults,
|
|
88
|
+
canRefine: !hasNoResults && items.length > 0,
|
|
87
89
|
widgetParams: widgetParams
|
|
88
90
|
};
|
|
89
91
|
},
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** @jsx h */
|
|
2
|
+
import { h } from 'preact';
|
|
3
|
+
import type { BaseHit, Hit, PartialKeys } from '../../types';
|
|
4
|
+
import type { HighlightProps as HighlightUiComponentProps } from '../../components/Highlight/Highlight';
|
|
5
|
+
export declare type HighlightProps<THit extends Hit<BaseHit>> = {
|
|
6
|
+
hit: THit;
|
|
7
|
+
attribute: keyof THit | string[];
|
|
8
|
+
cssClasses?: HighlightUiComponentProps['classNames'];
|
|
9
|
+
} & PartialKeys<Omit<HighlightUiComponentProps, 'parts' | 'classNames'>, 'highlightedTagName' | 'nonHighlightedTagName' | 'separator'>;
|
|
10
|
+
export declare function Highlight<THit extends Hit<BaseHit>>({ hit, attribute, cssClasses, ...props }: HighlightProps<THit>): h.JSX.Element;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
2
|
+
|
|
3
|
+
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; }
|
|
4
|
+
|
|
5
|
+
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; }
|
|
6
|
+
|
|
7
|
+
/** @jsx h */
|
|
8
|
+
import { h } from 'preact';
|
|
9
|
+
import { Highlight as HighlightUiComponent } from "../../components/Highlight/Highlight.js";
|
|
10
|
+
import getHighlightedParts from "../../lib/utils/getHighlightedParts.js";
|
|
11
|
+
import getPropertyByPath from "../../lib/utils/getPropertyByPath.js";
|
|
12
|
+
import unescape from "../../lib/utils/unescape.js";
|
|
13
|
+
import { warning } from "../../lib/utils/logger.js";
|
|
14
|
+
export function Highlight(_ref) {
|
|
15
|
+
var hit = _ref.hit,
|
|
16
|
+
attribute = _ref.attribute,
|
|
17
|
+
cssClasses = _ref.cssClasses,
|
|
18
|
+
props = _objectWithoutProperties(_ref, ["hit", "attribute", "cssClasses"]);
|
|
19
|
+
|
|
20
|
+
var property = getPropertyByPath(hit._highlightResult, attribute) || [];
|
|
21
|
+
var properties = Array.isArray(property) ? property : [property];
|
|
22
|
+
process.env.NODE_ENV === 'development' ? warning(Boolean(properties.length), "Could not enable highlight for \"".concat(attribute.toString(), "\", 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;
|
|
23
|
+
var parts = properties.map(function (_ref2) {
|
|
24
|
+
var value = _ref2.value;
|
|
25
|
+
return getHighlightedParts(unescape(value || ''));
|
|
26
|
+
});
|
|
27
|
+
return h(HighlightUiComponent, _extends({}, props, {
|
|
28
|
+
parts: parts,
|
|
29
|
+
classNames: cssClasses
|
|
30
|
+
}));
|
|
31
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** @jsx h */
|
|
2
|
+
import { h } from 'preact';
|
|
3
|
+
import type { BaseHit, Hit, PartialKeys } from '../../types';
|
|
4
|
+
import type { ReverseHighlightProps as ReverseHighlightUiComponentProps } from '../../components/ReverseHighlight/ReverseHighlight';
|
|
5
|
+
export declare type ReverseHighlightProps<THit extends Hit<BaseHit>> = {
|
|
6
|
+
hit: THit;
|
|
7
|
+
attribute: keyof THit | string[];
|
|
8
|
+
cssClasses?: ReverseHighlightUiComponentProps['classNames'];
|
|
9
|
+
} & PartialKeys<Omit<ReverseHighlightUiComponentProps, 'parts' | 'classNames'>, 'highlightedTagName' | 'nonHighlightedTagName' | 'separator'>;
|
|
10
|
+
export declare function ReverseHighlight<THit extends Hit<BaseHit>>({ hit, attribute, cssClasses, ...props }: ReverseHighlightProps<THit>): h.JSX.Element;
|