instantsearch.js 4.43.0 → 4.44.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 +29 -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/numeric-menu/connectNumericMenu.js +4 -41
- package/cjs/connectors/range/connectRange.js +7 -46
- package/cjs/connectors/rating-menu/connectRatingMenu.js +1 -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/InstantSearch.js +11 -1
- package/cjs/lib/version.js +1 -1
- package/dist/instantsearch.development.d.ts +10 -10
- package/dist/instantsearch.development.js +25 -116
- package/dist/instantsearch.development.js.map +1 -1
- package/dist/instantsearch.production.d.ts +10 -10
- package/dist/instantsearch.production.min.d.ts +10 -10
- 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/numeric-menu/connectNumericMenu.js +5 -42
- package/es/connectors/range/connectRange.js +8 -47
- package/es/connectors/rating-menu/connectRatingMenu.js +1 -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/InstantSearch.js +11 -1
- package/es/lib/version.d.ts +1 -1
- package/es/lib/version.js +1 -1
- package/es/types/results.d.ts +1 -1
- package/es/types/utils.d.ts +4 -0
- package/package.json +5 -2
|
@@ -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, '
|
|
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
|
*
|
|
@@ -16,7 +16,7 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
|
16
16
|
|
|
17
17
|
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
18
|
|
|
19
|
-
import { checkRendering, createDocumentationMessageGenerator, isFiniteNumber,
|
|
19
|
+
import { checkRendering, createDocumentationMessageGenerator, isFiniteNumber, noop } from "../../lib/utils/index.js";
|
|
20
20
|
var withUsage = createDocumentationMessageGenerator({
|
|
21
21
|
name: 'numeric-menu',
|
|
22
22
|
connector: true
|
|
@@ -24,47 +24,12 @@ var withUsage = createDocumentationMessageGenerator({
|
|
|
24
24
|
var $$type = 'ais.numericMenu';
|
|
25
25
|
|
|
26
26
|
var createSendEvent = function createSendEvent(_ref) {
|
|
27
|
-
var instantSearchInstance = _ref.instantSearchInstance
|
|
28
|
-
helper = _ref.helper,
|
|
29
|
-
attribute = _ref.attribute;
|
|
27
|
+
var instantSearchInstance = _ref.instantSearchInstance;
|
|
30
28
|
return function () {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
if (args.length === 1) {
|
|
36
|
-
instantSearchInstance.sendEventToInsights(args[0]);
|
|
29
|
+
if (arguments.length === 1) {
|
|
30
|
+
instantSearchInstance.sendEventToInsights(arguments.length <= 0 ? undefined : arguments[0]);
|
|
37
31
|
return;
|
|
38
32
|
}
|
|
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') {
|
|
46
|
-
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
|
-
}
|
|
68
33
|
};
|
|
69
34
|
};
|
|
70
35
|
|
|
@@ -208,9 +173,7 @@ var connectNumericMenu = function connectNumericMenu(renderFn) {
|
|
|
208
173
|
|
|
209
174
|
if (!connectorState.sendEvent) {
|
|
210
175
|
connectorState.sendEvent = createSendEvent({
|
|
211
|
-
instantSearchInstance: instantSearchInstance
|
|
212
|
-
helper: helper,
|
|
213
|
-
attribute: attribute
|
|
176
|
+
instantSearchInstance: instantSearchInstance
|
|
214
177
|
});
|
|
215
178
|
}
|
|
216
179
|
|
|
@@ -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
|
}),
|
|
@@ -215,7 +215,7 @@ var connectRatingMenu = function connectRatingMenu(renderFn) {
|
|
|
215
215
|
var maxValuesPerFacet = facetResults.length;
|
|
216
216
|
var maxDecimalPlaces = getFacetsMaxDecimalPlaces(facetResults);
|
|
217
217
|
var maxFacets = Math.pow(10, maxDecimalPlaces) * max;
|
|
218
|
-
process.env.NODE_ENV === 'development' ? warning(maxFacets <= maxValuesPerFacet, getFacetValuesWarningMessage({
|
|
218
|
+
process.env.NODE_ENV === 'development' ? warning(maxFacets <= maxValuesPerFacet || Boolean(results.__isArtificial), getFacetValuesWarningMessage({
|
|
219
219
|
maxDecimalPlaces: maxDecimalPlaces,
|
|
220
220
|
maxFacets: maxFacets,
|
|
221
221
|
maxValuesPerFacet: maxValuesPerFacet
|
|
@@ -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;
|
|
@@ -0,0 +1,44 @@
|
|
|
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 ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
|
|
4
|
+
|
|
5
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
6
|
+
|
|
7
|
+
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; }
|
|
8
|
+
|
|
9
|
+
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; }
|
|
10
|
+
|
|
11
|
+
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; }
|
|
12
|
+
|
|
13
|
+
/** @jsx h */
|
|
14
|
+
import { h } from 'preact';
|
|
15
|
+
import { ReverseHighlight as ReverseHighlightUiComponent } from "../../components/ReverseHighlight/ReverseHighlight.js";
|
|
16
|
+
import getHighlightedParts from "../../lib/utils/getHighlightedParts.js";
|
|
17
|
+
import getPropertyByPath from "../../lib/utils/getPropertyByPath.js";
|
|
18
|
+
import unescape from "../../lib/utils/unescape.js";
|
|
19
|
+
import { warning } from "../../lib/utils/logger.js";
|
|
20
|
+
export function ReverseHighlight(_ref) {
|
|
21
|
+
var hit = _ref.hit,
|
|
22
|
+
attribute = _ref.attribute,
|
|
23
|
+
cssClasses = _ref.cssClasses,
|
|
24
|
+
props = _objectWithoutProperties(_ref, ["hit", "attribute", "cssClasses"]);
|
|
25
|
+
|
|
26
|
+
var property = getPropertyByPath(hit._highlightResult, attribute) || [];
|
|
27
|
+
var properties = Array.isArray(property) ? property : [property];
|
|
28
|
+
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;
|
|
29
|
+
var parts = properties.map(function (_ref2) {
|
|
30
|
+
var value = _ref2.value;
|
|
31
|
+
return getHighlightedParts(unescape(value || '')).map(function (_ref3) {
|
|
32
|
+
var isHighlighted = _ref3.isHighlighted,
|
|
33
|
+
rest = _objectWithoutProperties(_ref3, ["isHighlighted"]);
|
|
34
|
+
|
|
35
|
+
return _objectSpread(_objectSpread({}, rest), {}, {
|
|
36
|
+
isHighlighted: !isHighlighted
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
return h(ReverseHighlightUiComponent, _extends({}, props, {
|
|
41
|
+
parts: parts,
|
|
42
|
+
classNames: cssClasses
|
|
43
|
+
}));
|
|
44
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** @jsx h */
|
|
2
|
+
import { h } from 'preact';
|
|
3
|
+
import type { BaseHit, Hit, PartialKeys } from '../../types';
|
|
4
|
+
import type { ReverseSnippetProps as ReverseSnippetUiComponentProps } from '../../components/ReverseSnippet/ReverseSnippet';
|
|
5
|
+
export declare type ReverseSnippetProps<THit extends Hit<BaseHit>> = {
|
|
6
|
+
hit: THit;
|
|
7
|
+
attribute: keyof THit | string[];
|
|
8
|
+
cssClasses?: ReverseSnippetUiComponentProps['classNames'];
|
|
9
|
+
} & PartialKeys<Omit<ReverseSnippetUiComponentProps, 'parts' | 'classNames'>, 'highlightedTagName' | 'nonHighlightedTagName' | 'separator'>;
|
|
10
|
+
export declare function ReverseSnippet<THit extends Hit<BaseHit>>({ hit, attribute, cssClasses, ...props }: ReverseSnippetProps<THit>): h.JSX.Element;
|
|
@@ -0,0 +1,44 @@
|
|
|
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 ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
|
|
4
|
+
|
|
5
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
6
|
+
|
|
7
|
+
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; }
|
|
8
|
+
|
|
9
|
+
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; }
|
|
10
|
+
|
|
11
|
+
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; }
|
|
12
|
+
|
|
13
|
+
/** @jsx h */
|
|
14
|
+
import { h } from 'preact';
|
|
15
|
+
import { ReverseSnippet as ReverseSnippetUiComponent } from "../../components/ReverseSnippet/ReverseSnippet.js";
|
|
16
|
+
import getHighlightedParts from "../../lib/utils/getHighlightedParts.js";
|
|
17
|
+
import getPropertyByPath from "../../lib/utils/getPropertyByPath.js";
|
|
18
|
+
import unescape from "../../lib/utils/unescape.js";
|
|
19
|
+
import { warning } from "../../lib/utils/logger.js";
|
|
20
|
+
export function ReverseSnippet(_ref) {
|
|
21
|
+
var hit = _ref.hit,
|
|
22
|
+
attribute = _ref.attribute,
|
|
23
|
+
cssClasses = _ref.cssClasses,
|
|
24
|
+
props = _objectWithoutProperties(_ref, ["hit", "attribute", "cssClasses"]);
|
|
25
|
+
|
|
26
|
+
var property = getPropertyByPath(hit._snippetResult, attribute) || [];
|
|
27
|
+
var properties = Array.isArray(property) ? property : [property];
|
|
28
|
+
process.env.NODE_ENV === 'development' ? warning(Boolean(properties.length), "Could not enable snippet for \"".concat(attribute.toString(), "\", will display an empty string.\nPlease check whether this attribute exists and is specified in `attributesToSnippet`.\n\nSee: https://alg.li/highlighting\n")) : void 0;
|
|
29
|
+
var parts = properties.map(function (_ref2) {
|
|
30
|
+
var value = _ref2.value;
|
|
31
|
+
return getHighlightedParts(unescape(value || '')).map(function (_ref3) {
|
|
32
|
+
var isHighlighted = _ref3.isHighlighted,
|
|
33
|
+
rest = _objectWithoutProperties(_ref3, ["isHighlighted"]);
|
|
34
|
+
|
|
35
|
+
return _objectSpread(_objectSpread({}, rest), {}, {
|
|
36
|
+
isHighlighted: !isHighlighted
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
return h(ReverseSnippetUiComponent, _extends({}, props, {
|
|
41
|
+
parts: parts,
|
|
42
|
+
classNames: cssClasses
|
|
43
|
+
}));
|
|
44
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** @jsx h */
|
|
2
|
+
import { h } from 'preact';
|
|
3
|
+
import type { BaseHit, Hit, PartialKeys } from '../../types';
|
|
4
|
+
import type { SnippetProps as SnippetUiComponentProps } from '../../components/Snippet/Snippet';
|
|
5
|
+
export declare type SnippetProps<THit extends Hit<BaseHit>> = {
|
|
6
|
+
hit: THit;
|
|
7
|
+
attribute: keyof THit | string[];
|
|
8
|
+
cssClasses?: SnippetUiComponentProps['classNames'];
|
|
9
|
+
} & PartialKeys<Omit<SnippetUiComponentProps, 'parts' | 'classNames'>, 'highlightedTagName' | 'nonHighlightedTagName' | 'separator'>;
|
|
10
|
+
export declare function Snippet<THit extends Hit<BaseHit>>({ hit, attribute, cssClasses, ...props }: SnippetProps<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 { Snippet as SnippetUiComponent } from "../../components/Snippet/Snippet.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 Snippet(_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._snippetResult, attribute) || [];
|
|
21
|
+
var properties = Array.isArray(property) ? property : [property];
|
|
22
|
+
process.env.NODE_ENV === 'development' ? warning(Boolean(properties.length), "Could not enable snippet for \"".concat(attribute.toString(), "\", will display an empty string.\nPlease check whether this attribute exists and is specified in `attributesToSnippet`.\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(SnippetUiComponent, _extends({}, props, {
|
|
28
|
+
parts: parts,
|
|
29
|
+
classNames: cssClasses
|
|
30
|
+
}));
|
|
31
|
+
}
|