instantsearch.js 4.54.1 → 4.55.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/cjs/components/Hits/Hits.js +16 -7
- package/cjs/components/InfiniteHits/InfiniteHits.js +13 -2
- package/cjs/connectors/autocomplete/connectAutocomplete.js +1 -1
- package/cjs/connectors/geo-search/connectGeoSearch.js +1 -1
- package/cjs/connectors/hierarchical-menu/connectHierarchicalMenu.js +1 -1
- package/cjs/connectors/hits/connectHits.js +1 -1
- package/cjs/connectors/infinite-hits/connectInfiniteHits.js +39 -31
- package/cjs/connectors/menu/connectMenu.js +1 -1
- package/cjs/connectors/numeric-menu/connectNumericMenu.js +1 -1
- package/cjs/connectors/rating-menu/connectRatingMenu.js +7 -3
- package/cjs/connectors/refinement-list/connectRefinementList.js +1 -1
- package/cjs/connectors/toggle-refinement/connectToggleRefinement.js +14 -4
- package/cjs/helpers/insights.js +3 -4
- package/cjs/lib/InstantSearch.js +18 -2
- package/cjs/lib/insights/listener.js +43 -36
- package/cjs/lib/routers/history.js +1 -0
- package/cjs/lib/stateMappings/simple.js +1 -0
- package/cjs/lib/stateMappings/singleIndex.js +1 -0
- package/cjs/lib/utils/createSendEventForFacet.js +12 -2
- package/cjs/lib/utils/createSendEventForHits.js +34 -11
- package/cjs/lib/version.js +1 -1
- package/cjs/middlewares/createInsightsMiddleware.js +135 -33
- package/cjs/middlewares/createMetadataMiddleware.js +17 -5
- package/cjs/middlewares/createRouterMiddleware.js +5 -1
- package/cjs/widgets/hits/hits.js +1 -2
- package/cjs/widgets/infinite-hits/infinite-hits.js +1 -2
- package/dist/instantsearch.development.d.ts +67 -8
- package/dist/instantsearch.development.js +433 -251
- package/dist/instantsearch.development.js.map +1 -1
- package/dist/instantsearch.production.d.ts +67 -8
- package/dist/instantsearch.production.min.d.ts +67 -8
- package/dist/instantsearch.production.min.js +2 -2
- package/dist/instantsearch.production.min.js.map +1 -1
- package/es/components/Hits/Hits.d.ts +5 -5
- package/es/components/Hits/Hits.js +15 -5
- package/es/components/InfiniteHits/InfiniteHits.d.ts +3 -2
- package/es/components/InfiniteHits/InfiniteHits.js +13 -2
- package/es/connectors/autocomplete/connectAutocomplete.js +1 -1
- package/es/connectors/geo-search/connectGeoSearch.js +1 -1
- package/es/connectors/hierarchical-menu/connectHierarchicalMenu.js +1 -1
- package/es/connectors/hits/connectHits.js +1 -1
- package/es/connectors/infinite-hits/connectInfiniteHits.js +39 -31
- package/es/connectors/menu/connectMenu.js +1 -1
- package/es/connectors/numeric-menu/connectNumericMenu.js +1 -1
- package/es/connectors/rating-menu/connectRatingMenu.js +7 -3
- package/es/connectors/refinement-list/connectRefinementList.js +1 -1
- package/es/connectors/toggle-refinement/connectToggleRefinement.js +13 -3
- package/es/helpers/insights.d.ts +2 -1
- package/es/helpers/insights.js +3 -3
- package/es/lib/InstantSearch.d.ts +11 -1
- package/es/lib/InstantSearch.js +18 -2
- package/es/lib/insights/listener.d.ts +10 -6
- package/es/lib/insights/listener.js +42 -36
- package/es/lib/routers/history.d.ts +1 -0
- package/es/lib/routers/history.js +1 -0
- package/es/lib/stateMappings/simple.js +1 -0
- package/es/lib/stateMappings/singleIndex.js +1 -0
- package/es/lib/utils/createSendEventForFacet.js +12 -2
- package/es/lib/utils/createSendEventForHits.d.ts +8 -0
- package/es/lib/utils/createSendEventForHits.js +33 -11
- package/es/lib/version.d.ts +1 -1
- package/es/lib/version.js +1 -1
- package/es/middlewares/createInsightsMiddleware.d.ts +12 -12
- package/es/middlewares/createInsightsMiddleware.js +136 -34
- package/es/middlewares/createMetadataMiddleware.d.ts +3 -1
- package/es/middlewares/createMetadataMiddleware.js +17 -5
- package/es/middlewares/createRouterMiddleware.js +5 -1
- package/es/types/insights.d.ts +19 -1
- package/es/types/middleware.d.ts +16 -0
- package/es/types/router.d.ts +8 -0
- package/es/widgets/hits/hits.js +2 -3
- package/es/widgets/infinite-hits/infinite-hits.js +2 -3
- package/package.json +6 -6
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { h } from 'preact';
|
|
3
3
|
import type { PreparedTemplateProps } from '../../lib/templating';
|
|
4
4
|
import type { BindEventForHits, SendEventForHits } from '../../lib/utils';
|
|
5
|
-
import type { ComponentCSSClasses, Hit } from '../../types';
|
|
5
|
+
import type { ComponentCSSClasses, Hit, InsightsClient } from '../../types';
|
|
6
6
|
import type { HitsCSSClasses, HitsTemplates } from '../../widgets/hits/hits';
|
|
7
7
|
import type { SearchResults } from 'algoliasearch-helper';
|
|
8
8
|
export type HitsComponentCSSClasses = ComponentCSSClasses<HitsCSSClasses>;
|
|
@@ -10,10 +10,10 @@ export type HitsComponentTemplates = Required<HitsTemplates>;
|
|
|
10
10
|
export type HitsProps = {
|
|
11
11
|
results: SearchResults;
|
|
12
12
|
hits: Hit[];
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
insights?: InsightsClient;
|
|
14
|
+
sendEvent: SendEventForHits;
|
|
15
|
+
bindEvent: BindEventForHits;
|
|
15
16
|
cssClasses: HitsComponentCSSClasses;
|
|
16
17
|
templateProps: PreparedTemplateProps<HitsComponentTemplates>;
|
|
17
18
|
};
|
|
18
|
-
|
|
19
|
-
export default Hits;
|
|
19
|
+
export default function Hits({ results, hits, insights, bindEvent, sendEvent, cssClasses, templateProps, }: HitsProps): h.JSX.Element;
|
|
@@ -7,20 +7,27 @@ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input ==
|
|
|
7
7
|
function _extends() { _extends = Object.assign ? Object.assign.bind() : 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); }
|
|
8
8
|
import { cx } from '@algolia/ui-components-shared';
|
|
9
9
|
import { h } from 'preact';
|
|
10
|
+
import { createInsightsEventHandler } from "../../lib/insights/listener.js";
|
|
10
11
|
import { warning } from "../../lib/utils/index.js";
|
|
11
12
|
import Template from "../Template/Template.js";
|
|
12
|
-
|
|
13
|
+
export default function Hits(_ref) {
|
|
13
14
|
var results = _ref.results,
|
|
14
15
|
hits = _ref.hits,
|
|
16
|
+
insights = _ref.insights,
|
|
15
17
|
bindEvent = _ref.bindEvent,
|
|
16
18
|
sendEvent = _ref.sendEvent,
|
|
17
19
|
cssClasses = _ref.cssClasses,
|
|
18
20
|
templateProps = _ref.templateProps;
|
|
21
|
+
var handleInsightsClick = createInsightsEventHandler({
|
|
22
|
+
insights: insights,
|
|
23
|
+
sendEvent: sendEvent
|
|
24
|
+
});
|
|
19
25
|
if (results.hits.length === 0) {
|
|
20
26
|
return h(Template, _extends({}, templateProps, {
|
|
21
27
|
templateKey: "empty",
|
|
22
28
|
rootProps: {
|
|
23
|
-
className: cx(cssClasses.root, cssClasses.emptyRoot)
|
|
29
|
+
className: cx(cssClasses.root, cssClasses.emptyRoot),
|
|
30
|
+
onClick: handleInsightsClick
|
|
24
31
|
},
|
|
25
32
|
data: results
|
|
26
33
|
}));
|
|
@@ -34,7 +41,11 @@ var Hits = function Hits(_ref) {
|
|
|
34
41
|
templateKey: "item",
|
|
35
42
|
rootTagName: "li",
|
|
36
43
|
rootProps: {
|
|
37
|
-
className: cssClasses.item
|
|
44
|
+
className: cssClasses.item,
|
|
45
|
+
onClick: function onClick(event) {
|
|
46
|
+
handleInsightsClick(event);
|
|
47
|
+
sendEvent('click:internal', hit, 'Hit Clicked');
|
|
48
|
+
}
|
|
38
49
|
},
|
|
39
50
|
key: hit.objectID,
|
|
40
51
|
data: _objectSpread(_objectSpread({}, hit), {}, {
|
|
@@ -47,5 +58,4 @@ var Hits = function Hits(_ref) {
|
|
|
47
58
|
sendEvent: sendEvent
|
|
48
59
|
}));
|
|
49
60
|
})));
|
|
50
|
-
}
|
|
51
|
-
export default Hits;
|
|
61
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
|
|
2
2
|
import { h } from 'preact';
|
|
3
3
|
import type { SendEventForHits, BindEventForHits } from '../../lib/utils';
|
|
4
|
-
import type { ComponentCSSClasses, Hit } from '../../types';
|
|
4
|
+
import type { ComponentCSSClasses, Hit, InsightsClient } from '../../types';
|
|
5
5
|
import type { InfiniteHitsCSSClasses, InfiniteHitsTemplates } from '../../widgets/infinite-hits/infinite-hits';
|
|
6
6
|
import type { SearchResults } from 'algoliasearch-helper';
|
|
7
7
|
export type InfiniteHitsComponentCSSClasses = ComponentCSSClasses<InfiniteHitsCSSClasses>;
|
|
@@ -19,8 +19,9 @@ export type InfiniteHitsProps = {
|
|
|
19
19
|
};
|
|
20
20
|
isFirstPage: boolean;
|
|
21
21
|
isLastPage: boolean;
|
|
22
|
+
insights?: InsightsClient;
|
|
22
23
|
sendEvent: SendEventForHits;
|
|
23
24
|
bindEvent: BindEventForHits;
|
|
24
25
|
};
|
|
25
|
-
declare const InfiniteHits: ({ results, hits, bindEvent, sendEvent, hasShowPrevious, showPrevious, showMore, isFirstPage, isLastPage, cssClasses, templateProps, }: InfiniteHitsProps) => h.JSX.Element;
|
|
26
|
+
declare const InfiniteHits: ({ results, hits, insights, bindEvent, sendEvent, hasShowPrevious, showPrevious, showMore, isFirstPage, isLastPage, cssClasses, templateProps, }: InfiniteHitsProps) => h.JSX.Element;
|
|
26
27
|
export default InfiniteHits;
|
|
@@ -7,11 +7,13 @@ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input ==
|
|
|
7
7
|
function _extends() { _extends = Object.assign ? Object.assign.bind() : 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); }
|
|
8
8
|
import { cx } from '@algolia/ui-components-shared';
|
|
9
9
|
import { h } from 'preact';
|
|
10
|
+
import { createInsightsEventHandler } from "../../lib/insights/listener.js";
|
|
10
11
|
import { warning } from "../../lib/utils/index.js";
|
|
11
12
|
import Template from "../Template/Template.js";
|
|
12
13
|
var InfiniteHits = function InfiniteHits(_ref) {
|
|
13
14
|
var results = _ref.results,
|
|
14
15
|
hits = _ref.hits,
|
|
16
|
+
insights = _ref.insights,
|
|
15
17
|
bindEvent = _ref.bindEvent,
|
|
16
18
|
sendEvent = _ref.sendEvent,
|
|
17
19
|
hasShowPrevious = _ref.hasShowPrevious,
|
|
@@ -21,11 +23,16 @@ var InfiniteHits = function InfiniteHits(_ref) {
|
|
|
21
23
|
isLastPage = _ref.isLastPage,
|
|
22
24
|
cssClasses = _ref.cssClasses,
|
|
23
25
|
templateProps = _ref.templateProps;
|
|
26
|
+
var handleInsightsClick = createInsightsEventHandler({
|
|
27
|
+
insights: insights,
|
|
28
|
+
sendEvent: sendEvent
|
|
29
|
+
});
|
|
24
30
|
if (results.hits.length === 0) {
|
|
25
31
|
return h(Template, _extends({}, templateProps, {
|
|
26
32
|
templateKey: "empty",
|
|
27
33
|
rootProps: {
|
|
28
|
-
className: cx(cssClasses.root, cssClasses.emptyRoot)
|
|
34
|
+
className: cx(cssClasses.root, cssClasses.emptyRoot),
|
|
35
|
+
onClick: handleInsightsClick
|
|
29
36
|
},
|
|
30
37
|
data: results
|
|
31
38
|
}));
|
|
@@ -47,7 +54,11 @@ var InfiniteHits = function InfiniteHits(_ref) {
|
|
|
47
54
|
templateKey: "item",
|
|
48
55
|
rootTagName: "li",
|
|
49
56
|
rootProps: {
|
|
50
|
-
className: cssClasses.item
|
|
57
|
+
className: cssClasses.item,
|
|
58
|
+
onClick: function onClick(event) {
|
|
59
|
+
handleInsightsClick(event);
|
|
60
|
+
sendEvent('click:internal', hit, 'Hit Clicked');
|
|
61
|
+
}
|
|
51
62
|
},
|
|
52
63
|
key: hit.objectID,
|
|
53
64
|
data: _objectSpread(_objectSpread({}, hit), {}, {
|
|
@@ -35,7 +35,7 @@ var connectAutocomplete = function connectAutocomplete(renderFn) {
|
|
|
35
35
|
renderState.indices.forEach(function (_ref3) {
|
|
36
36
|
var sendEvent = _ref3.sendEvent,
|
|
37
37
|
hits = _ref3.hits;
|
|
38
|
-
sendEvent('view', hits);
|
|
38
|
+
sendEvent('view:internal', hits);
|
|
39
39
|
});
|
|
40
40
|
renderFn(_objectSpread(_objectSpread({}, renderState), {}, {
|
|
41
41
|
instantSearchInstance: instantSearchInstance
|
|
@@ -131,7 +131,7 @@ var connectGeoSearch = function connectGeoSearch(renderFn) {
|
|
|
131
131
|
widgetState.internalToggleRefineOnMapMove = createInternalToggleRefinementOnMapMove(renderArgs, this.render.bind(this));
|
|
132
132
|
widgetState.internalSetMapMoveSinceLastRefine = createInternalSetMapMoveSinceLastRefine(renderArgs, this.render.bind(this));
|
|
133
133
|
var widgetRenderState = this.getWidgetRenderState(renderArgs);
|
|
134
|
-
sendEvent('view', widgetRenderState.items);
|
|
134
|
+
sendEvent('view:internal', widgetRenderState.items);
|
|
135
135
|
renderFn(_objectSpread(_objectSpread({}, widgetRenderState), {}, {
|
|
136
136
|
instantSearchInstance: instantSearchInstance
|
|
137
137
|
}), isFirstRendering);
|
|
@@ -155,7 +155,7 @@ var connectHierarchicalMenu = function connectHierarchicalMenu(renderFn) {
|
|
|
155
155
|
}
|
|
156
156
|
if (!_refine) {
|
|
157
157
|
_refine = function _refine(facetValue) {
|
|
158
|
-
sendEvent('click', facetValue);
|
|
158
|
+
sendEvent('click:internal', facetValue);
|
|
159
159
|
helper.toggleFacetRefinement(hierarchicalFacetName, facetValue).search();
|
|
160
160
|
};
|
|
161
161
|
}
|
|
@@ -34,7 +34,7 @@ var connectHits = function connectHits(renderFn) {
|
|
|
34
34
|
renderFn(_objectSpread(_objectSpread({}, renderState), {}, {
|
|
35
35
|
instantSearchInstance: renderOptions.instantSearchInstance
|
|
36
36
|
}), false);
|
|
37
|
-
renderState.sendEvent('view', renderState.hits);
|
|
37
|
+
renderState.sendEvent('view:internal', renderState.hits);
|
|
38
38
|
},
|
|
39
39
|
getRenderState: function getRenderState(renderState, renderOptions) {
|
|
40
40
|
return _objectSpread(_objectSpread({}, renderState), {}, {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
2
|
-
var _excluded = ["page"]
|
|
2
|
+
var _excluded = ["page"],
|
|
3
|
+
_excluded2 = ["clickAnalytics", "userToken"];
|
|
3
4
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); 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 = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
5
6
|
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
@@ -24,17 +25,24 @@ function getStateWithoutPage(state) {
|
|
|
24
25
|
rest = _objectWithoutProperties(_ref, _excluded);
|
|
25
26
|
return rest;
|
|
26
27
|
}
|
|
28
|
+
function normalizeState(state) {
|
|
29
|
+
var _ref2 = state || {},
|
|
30
|
+
clickAnalytics = _ref2.clickAnalytics,
|
|
31
|
+
userToken = _ref2.userToken,
|
|
32
|
+
rest = _objectWithoutProperties(_ref2, _excluded2);
|
|
33
|
+
return rest;
|
|
34
|
+
}
|
|
27
35
|
function getInMemoryCache() {
|
|
28
36
|
var cachedHits = null;
|
|
29
37
|
var cachedState = null;
|
|
30
38
|
return {
|
|
31
|
-
read: function read(
|
|
32
|
-
var state =
|
|
39
|
+
read: function read(_ref3) {
|
|
40
|
+
var state = _ref3.state;
|
|
33
41
|
return isEqual(cachedState, getStateWithoutPage(state)) ? cachedHits : null;
|
|
34
42
|
},
|
|
35
|
-
write: function write(
|
|
36
|
-
var state =
|
|
37
|
-
hits =
|
|
43
|
+
write: function write(_ref4) {
|
|
44
|
+
var state = _ref4.state,
|
|
45
|
+
hits = _ref4.hits;
|
|
38
46
|
cachedState = getStateWithoutPage(state);
|
|
39
47
|
cachedHits = hits;
|
|
40
48
|
}
|
|
@@ -54,15 +62,15 @@ var connectInfiniteHits = function connectInfiniteHits(renderFn) {
|
|
|
54
62
|
// @TODO: this should be a generic, but a Connector can not yet be generic itself
|
|
55
63
|
|
|
56
64
|
return function (widgetParams) {
|
|
57
|
-
var
|
|
58
|
-
|
|
59
|
-
escapeHTML =
|
|
60
|
-
|
|
61
|
-
transformItems =
|
|
65
|
+
var _ref5 = widgetParams || {},
|
|
66
|
+
_ref5$escapeHTML = _ref5.escapeHTML,
|
|
67
|
+
escapeHTML = _ref5$escapeHTML === void 0 ? true : _ref5$escapeHTML,
|
|
68
|
+
_ref5$transformItems = _ref5.transformItems,
|
|
69
|
+
transformItems = _ref5$transformItems === void 0 ? function (items) {
|
|
62
70
|
return items;
|
|
63
|
-
} :
|
|
64
|
-
|
|
65
|
-
cache =
|
|
71
|
+
} : _ref5$transformItems,
|
|
72
|
+
_ref5$cache = _ref5.cache,
|
|
73
|
+
cache = _ref5$cache === void 0 ? getInMemoryCache() : _ref5$cache;
|
|
66
74
|
var showPrevious;
|
|
67
75
|
var showMore;
|
|
68
76
|
var sendEvent;
|
|
@@ -93,7 +101,7 @@ var connectInfiniteHits = function connectInfiniteHits(renderFn) {
|
|
|
93
101
|
// avoid updating the browser URL when the user displays the previous page.
|
|
94
102
|
helper.overrideStateWithoutTriggeringChangeEvent(_objectSpread(_objectSpread({}, helper.state), {}, {
|
|
95
103
|
page: getFirstReceivedPage(helper.state, cache.read({
|
|
96
|
-
state: helper.state
|
|
104
|
+
state: normalizeState(helper.state)
|
|
97
105
|
}) || {}) - 1
|
|
98
106
|
})).searchWithoutTriggeringOnStateChange();
|
|
99
107
|
};
|
|
@@ -101,7 +109,7 @@ var connectInfiniteHits = function connectInfiniteHits(renderFn) {
|
|
|
101
109
|
var getShowMore = function getShowMore(helper) {
|
|
102
110
|
return function () {
|
|
103
111
|
helper.setPage(getLastReceivedPage(helper.state, cache.read({
|
|
104
|
-
state: helper.state
|
|
112
|
+
state: normalizeState(helper.state)
|
|
105
113
|
}) || {}) + 1).search();
|
|
106
114
|
};
|
|
107
115
|
};
|
|
@@ -118,19 +126,19 @@ var connectInfiniteHits = function connectInfiniteHits(renderFn) {
|
|
|
118
126
|
renderFn(_objectSpread(_objectSpread({}, widgetRenderState), {}, {
|
|
119
127
|
instantSearchInstance: instantSearchInstance
|
|
120
128
|
}), false);
|
|
121
|
-
sendEvent('view', widgetRenderState.currentPageHits);
|
|
129
|
+
sendEvent('view:internal', widgetRenderState.currentPageHits);
|
|
122
130
|
},
|
|
123
131
|
getRenderState: function getRenderState(renderState, renderOptions) {
|
|
124
132
|
return _objectSpread(_objectSpread({}, renderState), {}, {
|
|
125
133
|
infiniteHits: this.getWidgetRenderState(renderOptions)
|
|
126
134
|
});
|
|
127
135
|
},
|
|
128
|
-
getWidgetRenderState: function getWidgetRenderState(
|
|
129
|
-
var results =
|
|
130
|
-
helper =
|
|
131
|
-
parent =
|
|
132
|
-
existingState =
|
|
133
|
-
instantSearchInstance =
|
|
136
|
+
getWidgetRenderState: function getWidgetRenderState(_ref6) {
|
|
137
|
+
var results = _ref6.results,
|
|
138
|
+
helper = _ref6.helper,
|
|
139
|
+
parent = _ref6.parent,
|
|
140
|
+
existingState = _ref6.state,
|
|
141
|
+
instantSearchInstance = _ref6.instantSearchInstance;
|
|
134
142
|
var isFirstPage;
|
|
135
143
|
var currentPageHits = [];
|
|
136
144
|
/**
|
|
@@ -140,7 +148,7 @@ var connectInfiniteHits = function connectInfiniteHits(renderFn) {
|
|
|
140
148
|
*/
|
|
141
149
|
var state = parent.getPreviousState() || existingState;
|
|
142
150
|
var cachedHits = cache.read({
|
|
143
|
-
state: state
|
|
151
|
+
state: normalizeState(state)
|
|
144
152
|
}) || {};
|
|
145
153
|
if (!results) {
|
|
146
154
|
showPrevious = getShowPrevious(helper);
|
|
@@ -170,7 +178,7 @@ var connectInfiniteHits = function connectInfiniteHits(renderFn) {
|
|
|
170
178
|
if (cachedHits[_page] === undefined && !results.__isArtificial && instantSearchInstance.status === 'idle') {
|
|
171
179
|
cachedHits[_page] = transformedHits;
|
|
172
180
|
cache.write({
|
|
173
|
-
state: state,
|
|
181
|
+
state: normalizeState(state),
|
|
174
182
|
hits: cachedHits
|
|
175
183
|
});
|
|
176
184
|
}
|
|
@@ -192,8 +200,8 @@ var connectInfiniteHits = function connectInfiniteHits(renderFn) {
|
|
|
192
200
|
widgetParams: widgetParams
|
|
193
201
|
};
|
|
194
202
|
},
|
|
195
|
-
dispose: function dispose(
|
|
196
|
-
var state =
|
|
203
|
+
dispose: function dispose(_ref7) {
|
|
204
|
+
var state = _ref7.state;
|
|
197
205
|
unmountFn();
|
|
198
206
|
var stateWithoutPage = state.setQueryParameter('page', undefined);
|
|
199
207
|
if (!escapeHTML) {
|
|
@@ -203,8 +211,8 @@ var connectInfiniteHits = function connectInfiniteHits(renderFn) {
|
|
|
203
211
|
return _objectSpread(_objectSpread({}, acc), {}, _defineProperty({}, key, undefined));
|
|
204
212
|
}, {}));
|
|
205
213
|
},
|
|
206
|
-
getWidgetUiState: function getWidgetUiState(uiState,
|
|
207
|
-
var searchParameters =
|
|
214
|
+
getWidgetUiState: function getWidgetUiState(uiState, _ref8) {
|
|
215
|
+
var searchParameters = _ref8.searchParameters;
|
|
208
216
|
var page = searchParameters.page || 0;
|
|
209
217
|
if (!page) {
|
|
210
218
|
// return without adding `page` to uiState
|
|
@@ -217,8 +225,8 @@ var connectInfiniteHits = function connectInfiniteHits(renderFn) {
|
|
|
217
225
|
page: page + 1
|
|
218
226
|
});
|
|
219
227
|
},
|
|
220
|
-
getWidgetSearchParameters: function getWidgetSearchParameters(searchParameters,
|
|
221
|
-
var uiState =
|
|
228
|
+
getWidgetSearchParameters: function getWidgetSearchParameters(searchParameters, _ref9) {
|
|
229
|
+
var uiState = _ref9.uiState;
|
|
222
230
|
var widgetSearchParameters = searchParameters;
|
|
223
231
|
if (escapeHTML) {
|
|
224
232
|
widgetSearchParameters = searchParameters.setQueryParameters(TAG_PLACEHOLDER);
|
|
@@ -121,7 +121,7 @@ var connectMenu = function connectMenu(renderFn) {
|
|
|
121
121
|
var _helper$getHierarchic = helper.getHierarchicalFacetBreadcrumb(attribute),
|
|
122
122
|
_helper$getHierarchic2 = _slicedToArray(_helper$getHierarchic, 1),
|
|
123
123
|
refinedItem = _helper$getHierarchic2[0];
|
|
124
|
-
sendEvent('click', facetValue ? facetValue : refinedItem);
|
|
124
|
+
sendEvent('click:internal', facetValue ? facetValue : refinedItem);
|
|
125
125
|
helper.toggleFacetRefinement(attribute, facetValue ? facetValue : refinedItem).search();
|
|
126
126
|
};
|
|
127
127
|
}
|
|
@@ -137,7 +137,7 @@ var connectNumericMenu = function connectNumericMenu(renderFn) {
|
|
|
137
137
|
if (!connectorState.refine) {
|
|
138
138
|
connectorState.refine = function (facetValue) {
|
|
139
139
|
var refinedState = getRefinedState(helper.state, attribute, facetValue);
|
|
140
|
-
connectorState.sendEvent('click', facetValue);
|
|
140
|
+
connectorState.sendEvent('click:internal', facetValue);
|
|
141
141
|
helper.setState(refinedState).search();
|
|
142
142
|
};
|
|
143
143
|
}
|
|
@@ -35,10 +35,13 @@ var createSendEvent = function createSendEvent(_ref) {
|
|
|
35
35
|
instantSearchInstance.sendEventToInsights(args[0]);
|
|
36
36
|
return;
|
|
37
37
|
}
|
|
38
|
-
var
|
|
39
|
-
facetValue = args[1],
|
|
38
|
+
var facetValue = args[1],
|
|
40
39
|
_args$ = args[2],
|
|
41
40
|
eventName = _args$ === void 0 ? 'Filter Applied' : _args$;
|
|
41
|
+
var _args$0$split = args[0].split(':'),
|
|
42
|
+
_args$0$split2 = _slicedToArray(_args$0$split, 2),
|
|
43
|
+
eventType = _args$0$split2[0],
|
|
44
|
+
eventModifier = _args$0$split2[1];
|
|
42
45
|
if (eventType !== 'click') {
|
|
43
46
|
return;
|
|
44
47
|
}
|
|
@@ -48,6 +51,7 @@ var createSendEvent = function createSendEvent(_ref) {
|
|
|
48
51
|
insightsMethod: 'clickedFilters',
|
|
49
52
|
widgetType: $$type,
|
|
50
53
|
eventType: eventType,
|
|
54
|
+
eventModifier: eventModifier,
|
|
51
55
|
payload: {
|
|
52
56
|
eventName: eventName,
|
|
53
57
|
index: helper.getIndex(),
|
|
@@ -123,7 +127,7 @@ var connectRatingMenu = function connectRatingMenu(renderFn) {
|
|
|
123
127
|
return emptyState;
|
|
124
128
|
}
|
|
125
129
|
var toggleRefinement = function toggleRefinement(helper, facetValue) {
|
|
126
|
-
sendEvent('click', facetValue);
|
|
130
|
+
sendEvent('click:internal', facetValue);
|
|
127
131
|
helper.setState(getRefinedState(helper.state, facetValue)).search();
|
|
128
132
|
};
|
|
129
133
|
var connectorState = {
|
|
@@ -172,7 +172,7 @@ var connectRefinementList = function connectRefinementList(renderFn) {
|
|
|
172
172
|
widgetType: this.$$type
|
|
173
173
|
});
|
|
174
174
|
triggerRefine = function triggerRefine(facetValue) {
|
|
175
|
-
sendEvent('click', facetValue);
|
|
175
|
+
sendEvent('click:internal', facetValue);
|
|
176
176
|
helper.toggleFacetRefinement(attribute, facetValue).search();
|
|
177
177
|
};
|
|
178
178
|
searchForFacetValues = createSearchForFacetValues(helper, this);
|
|
@@ -4,6 +4,12 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
|
4
4
|
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
5
5
|
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
6
6
|
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
7
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
8
|
+
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."); }
|
|
9
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
10
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
11
|
+
function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
|
|
12
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
7
13
|
import { checkRendering, escapeFacetValue, createDocumentationMessageGenerator, find, noop, toArray, warning } from "../../lib/utils/index.js";
|
|
8
14
|
var withUsage = createDocumentationMessageGenerator({
|
|
9
15
|
name: 'toggle-refinement',
|
|
@@ -23,10 +29,13 @@ var createSendEvent = function createSendEvent(_ref) {
|
|
|
23
29
|
instantSearchInstance.sendEventToInsights(args[0]);
|
|
24
30
|
return;
|
|
25
31
|
}
|
|
26
|
-
var
|
|
27
|
-
isRefined = args[1],
|
|
32
|
+
var isRefined = args[1],
|
|
28
33
|
_args$ = args[2],
|
|
29
34
|
eventName = _args$ === void 0 ? 'Filter Applied' : _args$;
|
|
35
|
+
var _args$0$split = args[0].split(':'),
|
|
36
|
+
_args$0$split2 = _slicedToArray(_args$0$split, 2),
|
|
37
|
+
eventType = _args$0$split2[0],
|
|
38
|
+
eventModifier = _args$0$split2[1];
|
|
30
39
|
if (eventType !== 'click' || on === undefined) {
|
|
31
40
|
return;
|
|
32
41
|
}
|
|
@@ -38,6 +47,7 @@ var createSendEvent = function createSendEvent(_ref) {
|
|
|
38
47
|
insightsMethod: 'clickedFilters',
|
|
39
48
|
widgetType: $$type,
|
|
40
49
|
eventType: eventType,
|
|
50
|
+
eventModifier: eventModifier,
|
|
41
51
|
payload: {
|
|
42
52
|
eventName: eventName,
|
|
43
53
|
index: helper.getIndex(),
|
|
@@ -84,7 +94,7 @@ var connectToggleRefinement = function connectToggleRefinement(renderFn) {
|
|
|
84
94
|
},
|
|
85
95
|
isRefined = _ref3.isRefined;
|
|
86
96
|
if (!isRefined) {
|
|
87
|
-
sendEvent('click', isRefined);
|
|
97
|
+
sendEvent('click:internal', isRefined);
|
|
88
98
|
if (hasAnOffValue) {
|
|
89
99
|
off.forEach(function (v) {
|
|
90
100
|
return helper.removeDisjunctiveFacetRefinement(attribute, v);
|
package/es/helpers/insights.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import type { InsightsClientMethod, InsightsClientPayload } from '../types';
|
|
2
|
+
/** @deprecated use bindEvent instead */
|
|
2
3
|
export declare function readDataAttributes(domElement: HTMLElement): {
|
|
3
4
|
method: InsightsClientMethod;
|
|
4
5
|
payload: Partial<InsightsClientPayload>;
|
|
5
6
|
};
|
|
6
|
-
|
|
7
|
+
/** @deprecated use bindEvent instead */
|
|
7
8
|
export declare function writeDataAttributes({ method, payload, }: {
|
|
8
9
|
method: InsightsClientMethod;
|
|
9
10
|
payload: Partial<InsightsClientPayload>;
|
package/es/helpers/insights.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
2
2
|
import { warning, serializePayload, deserializePayload } from "../lib/utils/index.js";
|
|
3
|
+
/** @deprecated use bindEvent instead */
|
|
3
4
|
export function readDataAttributes(domElement) {
|
|
4
5
|
var method = domElement.getAttribute('data-insights-method');
|
|
5
6
|
var serializedPayload = domElement.getAttribute('data-insights-payload');
|
|
@@ -16,9 +17,8 @@ export function readDataAttributes(domElement) {
|
|
|
16
17
|
throw new Error('The insights helper was unable to parse `data-insights-payload`.');
|
|
17
18
|
}
|
|
18
19
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}
|
|
20
|
+
|
|
21
|
+
/** @deprecated use bindEvent instead */
|
|
22
22
|
export function writeDataAttributes(_ref) {
|
|
23
23
|
var method = _ref.method,
|
|
24
24
|
payload = _ref.payload;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import EventEmitter from '@algolia/events';
|
|
2
|
-
import type { InsightsEvent } from '../middlewares/createInsightsMiddleware';
|
|
2
|
+
import type { InsightsEvent, InsightsProps } from '../middlewares/createInsightsMiddleware';
|
|
3
3
|
import type { RouterProps } from '../middlewares/createRouterMiddleware';
|
|
4
4
|
import type { InsightsClient as AlgoliaInsightsClient, SearchClient, Widget, UiState, CreateURL, Middleware, MiddlewareDefinition, RenderState, InitialResults } from '../types';
|
|
5
5
|
import type { IndexWidget } from '../widgets/index/index';
|
|
@@ -79,6 +79,16 @@ export type InstantSearchOptions<TUiState extends UiState = UiState, TRouteState
|
|
|
79
79
|
* client side persistence. Passing `true` will use the default URL options.
|
|
80
80
|
*/
|
|
81
81
|
routing?: RouterProps<TUiState, TRouteState> | boolean;
|
|
82
|
+
/**
|
|
83
|
+
* Enables the Insights middleware and loads the Insights library
|
|
84
|
+
* if not already loaded.
|
|
85
|
+
*
|
|
86
|
+
* The Insights middleware sends view and click events automatically, and lets
|
|
87
|
+
* you set up your own events.
|
|
88
|
+
*
|
|
89
|
+
* @default false
|
|
90
|
+
*/
|
|
91
|
+
insights?: InsightsProps | boolean;
|
|
82
92
|
/**
|
|
83
93
|
* the instance of search-insights to use for sending insights events inside
|
|
84
94
|
* widgets like `hits`.
|
package/es/lib/InstantSearch.js
CHANGED
|
@@ -16,6 +16,7 @@ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _ty
|
|
|
16
16
|
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
17
17
|
import EventEmitter from '@algolia/events';
|
|
18
18
|
import algoliasearchHelper from 'algoliasearch-helper';
|
|
19
|
+
import { createInsightsMiddleware } from "../middlewares/createInsightsMiddleware.js";
|
|
19
20
|
import { createMetadataMiddleware, isMetadataEnabled } from "../middlewares/createMetadataMiddleware.js";
|
|
20
21
|
import { createRouterMiddleware } from "../middlewares/createRouterMiddleware.js";
|
|
21
22
|
import index from "../widgets/index/index.js";
|
|
@@ -105,6 +106,8 @@ var InstantSearch = /*#__PURE__*/function (_EventEmitter) {
|
|
|
105
106
|
initialUiState = _options$initialUiSta === void 0 ? {} : _options$initialUiSta,
|
|
106
107
|
_options$routing = options.routing,
|
|
107
108
|
routing = _options$routing === void 0 ? null : _options$routing,
|
|
109
|
+
_options$insights = options.insights,
|
|
110
|
+
insights = _options$insights === void 0 ? false : _options$insights,
|
|
108
111
|
searchFunction = options.searchFunction,
|
|
109
112
|
_options$stalledSearc = options.stalledSearchDelay,
|
|
110
113
|
stalledSearchDelay = _options$stalledSearc === void 0 ? 200 : _options$stalledSearc,
|
|
@@ -160,11 +163,22 @@ var InstantSearch = /*#__PURE__*/function (_EventEmitter) {
|
|
|
160
163
|
}
|
|
161
164
|
_this.sendEventToInsights = noop;
|
|
162
165
|
if (routing) {
|
|
163
|
-
var routerOptions = typeof routing === 'boolean' ?
|
|
166
|
+
var routerOptions = typeof routing === 'boolean' ? {} : routing;
|
|
167
|
+
routerOptions.$$internal = true;
|
|
164
168
|
_this.use(createRouterMiddleware(routerOptions));
|
|
165
169
|
}
|
|
170
|
+
|
|
171
|
+
// This is the default middleware,
|
|
172
|
+
// any user-provided middleware will be added later and override this one.
|
|
173
|
+
if (insights) {
|
|
174
|
+
var insightsOptions = typeof insights === 'boolean' ? {} : insights;
|
|
175
|
+
insightsOptions.$$internal = true;
|
|
176
|
+
_this.use(createInsightsMiddleware(insightsOptions));
|
|
177
|
+
}
|
|
166
178
|
if (isMetadataEnabled()) {
|
|
167
|
-
_this.use(createMetadataMiddleware(
|
|
179
|
+
_this.use(createMetadataMiddleware({
|
|
180
|
+
$$internal: true
|
|
181
|
+
}));
|
|
168
182
|
}
|
|
169
183
|
return _this;
|
|
170
184
|
}
|
|
@@ -200,6 +214,8 @@ var InstantSearch = /*#__PURE__*/function (_EventEmitter) {
|
|
|
200
214
|
}
|
|
201
215
|
var newMiddlewareList = middleware.map(function (fn) {
|
|
202
216
|
var newMiddleware = _objectSpread({
|
|
217
|
+
$$type: '__unknown__',
|
|
218
|
+
$$internal: false,
|
|
203
219
|
subscribe: noop,
|
|
204
220
|
started: noop,
|
|
205
221
|
unsubscribe: noop,
|
|
@@ -2,10 +2,14 @@
|
|
|
2
2
|
import { h } from 'preact';
|
|
3
3
|
import type { InsightsEvent } from '../../middlewares/createInsightsMiddleware';
|
|
4
4
|
import type { InsightsClient } from '../../types';
|
|
5
|
-
type
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
sendEvent?: (event: InsightsEvent) => void;
|
|
5
|
+
export type InsightsEventHandlerOptions = {
|
|
6
|
+
insights?: InsightsClient;
|
|
7
|
+
sendEvent: (event: InsightsEvent) => void;
|
|
9
8
|
};
|
|
10
|
-
declare const
|
|
11
|
-
|
|
9
|
+
export declare const createInsightsEventHandler: ({ insights, sendEvent }: InsightsEventHandlerOptions) => (event: MouseEvent) => void;
|
|
10
|
+
/**
|
|
11
|
+
* @deprecated use `sendEvent` directly instead
|
|
12
|
+
*/
|
|
13
|
+
export default function withInsightsListener(BaseComponent: any): (props: {
|
|
14
|
+
[key: string]: any;
|
|
15
|
+
} & InsightsEventHandlerOptions) => h.JSX.Element;
|