@docsearch/react 3.5.0 → 3.5.2
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/dist/esm/DocSearch.js +2 -2
- package/dist/esm/DocSearchModal.js +18 -4
- package/dist/esm/types/DocSearchHit.d.ts +1 -0
- package/dist/esm/types/DocSearchState.d.ts +10 -0
- package/dist/esm/types/DocSearchState.js +1 -0
- package/dist/esm/types/index.d.ts +1 -0
- package/dist/esm/types/index.js +1 -0
- package/dist/esm/utils/removeHighlightTags.js +2 -2
- package/dist/esm/version.d.ts +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/umd/index.js +2 -2
- package/dist/umd/index.js.map +1 -1
- package/package.json +10 -6
package/dist/esm/DocSearch.js
CHANGED
|
@@ -51,12 +51,12 @@ export function DocSearch(props) {
|
|
|
51
51
|
});
|
|
52
52
|
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(DocSearchButton, {
|
|
53
53
|
ref: searchButtonRef,
|
|
54
|
-
translations: props === null || props === void 0
|
|
54
|
+
translations: props === null || props === void 0 || (_props$translations = props.translations) === null || _props$translations === void 0 ? void 0 : _props$translations.button,
|
|
55
55
|
onClick: onOpen
|
|
56
56
|
}), isOpen && createPortal( /*#__PURE__*/React.createElement(DocSearchModal, _extends({}, props, {
|
|
57
57
|
initialScrollY: window.scrollY,
|
|
58
58
|
initialQuery: initialQuery,
|
|
59
|
-
translations: props === null || props === void 0
|
|
59
|
+
translations: props === null || props === void 0 || (_props$translations2 = props.translations) === null || _props$translations2 === void 0 ? void 0 : _props$translations2.modal,
|
|
60
60
|
onClose: onClose
|
|
61
61
|
})), document.body));
|
|
62
62
|
}
|
|
@@ -119,6 +119,18 @@ export function DocSearchModal(_ref) {
|
|
|
119
119
|
recentSearches.add(search);
|
|
120
120
|
}
|
|
121
121
|
}, [favoriteSearches, recentSearches, disableUserPersonalization]);
|
|
122
|
+
var sendItemClickEvent = React.useCallback(function (item) {
|
|
123
|
+
if (!state.context.algoliaInsightsPlugin || !item.__autocomplete_id) return;
|
|
124
|
+
var insightsItem = item;
|
|
125
|
+
var insightsClickParams = {
|
|
126
|
+
eventName: 'Item Selected',
|
|
127
|
+
index: insightsItem.__autocomplete_indexName,
|
|
128
|
+
items: [insightsItem],
|
|
129
|
+
positions: [item.__autocomplete_id],
|
|
130
|
+
queryID: insightsItem.__autocomplete_queryID
|
|
131
|
+
};
|
|
132
|
+
state.context.algoliaInsightsPlugin.insights.clickedObjectIDsAfterSearch(insightsClickParams);
|
|
133
|
+
}, [state.context.algoliaInsightsPlugin]);
|
|
122
134
|
var autocomplete = React.useMemo(function () {
|
|
123
135
|
return createAutocomplete({
|
|
124
136
|
id: 'docsearch',
|
|
@@ -211,9 +223,9 @@ export function DocSearchModal(_ref) {
|
|
|
211
223
|
throw error;
|
|
212
224
|
}).then(function (_ref7) {
|
|
213
225
|
var results = _ref7.results;
|
|
214
|
-
var
|
|
215
|
-
|
|
216
|
-
nbHits =
|
|
226
|
+
var firstResult = results[0];
|
|
227
|
+
var hits = firstResult.hits,
|
|
228
|
+
nbHits = firstResult.nbHits;
|
|
217
229
|
var sources = groupBy(hits, function (hit) {
|
|
218
230
|
return removeHighlightTags(hit);
|
|
219
231
|
}, maxResultsPerGroup); // We store the `lvl0`s to display them as search suggestions
|
|
@@ -233,7 +245,7 @@ export function DocSearchModal(_ref) {
|
|
|
233
245
|
if (insightsActive) {
|
|
234
246
|
insightsParams = {
|
|
235
247
|
__autocomplete_indexName: indexName,
|
|
236
|
-
__autocomplete_queryID:
|
|
248
|
+
__autocomplete_queryID: firstResult.queryID,
|
|
237
249
|
__autocomplete_algoliaCredentials: {
|
|
238
250
|
appId: appId,
|
|
239
251
|
apiKey: apiKey
|
|
@@ -390,6 +402,8 @@ export function DocSearchModal(_ref) {
|
|
|
390
402
|
translations: screenStateTranslations,
|
|
391
403
|
getMissingResultsUrl: getMissingResultsUrl,
|
|
392
404
|
onItemClick: function onItemClick(item, event) {
|
|
405
|
+
// If insights is active, send insights click event
|
|
406
|
+
sendItemClickEvent(item);
|
|
393
407
|
saveRecentSearch(item);
|
|
394
408
|
|
|
395
409
|
if (!isModifierEvent(event)) {
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { AutocompleteContext, AutocompleteInsightsApi, AutocompleteState, BaseItem } from '@algolia/autocomplete-core';
|
|
2
|
+
interface DocSearchContext extends AutocompleteContext {
|
|
3
|
+
algoliaInsightsPlugin?: {
|
|
4
|
+
insights: AutocompleteInsightsApi;
|
|
5
|
+
};
|
|
6
|
+
}
|
|
7
|
+
export interface DocSearchState<TItem extends BaseItem> extends AutocompleteState<TItem> {
|
|
8
|
+
context: DocSearchContext;
|
|
9
|
+
}
|
|
10
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/esm/types/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
var regexHighlightTags = /(<mark>|<\/mark>)/g;
|
|
2
2
|
var regexHasHighlightTags = RegExp(regexHighlightTags.source);
|
|
3
3
|
export function removeHighlightTags(hit) {
|
|
4
|
-
var _internalDocSearchHit,
|
|
4
|
+
var _internalDocSearchHit, _hit$_highlightResult;
|
|
5
5
|
|
|
6
6
|
var internalDocSearchHit = hit;
|
|
7
7
|
|
|
@@ -9,7 +9,7 @@ export function removeHighlightTags(hit) {
|
|
|
9
9
|
return hit.hierarchy.lvl0;
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
var _ref = (internalDocSearchHit.__docsearch_parent ? (_internalDocSearchHit = internalDocSearchHit.__docsearch_parent) === null || _internalDocSearchHit === void 0
|
|
12
|
+
var _ref = (internalDocSearchHit.__docsearch_parent ? (_internalDocSearchHit = internalDocSearchHit.__docsearch_parent) === null || _internalDocSearchHit === void 0 || (_internalDocSearchHit = _internalDocSearchHit._highlightResult) === null || _internalDocSearchHit === void 0 || (_internalDocSearchHit = _internalDocSearchHit.hierarchy) === null || _internalDocSearchHit === void 0 ? void 0 : _internalDocSearchHit.lvl0 : (_hit$_highlightResult = hit._highlightResult) === null || _hit$_highlightResult === void 0 || (_hit$_highlightResult = _hit$_highlightResult.hierarchy) === null || _hit$_highlightResult === void 0 ? void 0 : _hit$_highlightResult.lvl0) || {},
|
|
13
13
|
value = _ref.value;
|
|
14
14
|
|
|
15
15
|
return value && regexHasHighlightTags.test(value) ? value.replace(regexHighlightTags, '') : value;
|
package/dist/esm/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "3.5.
|
|
1
|
+
export declare const version = "3.5.2";
|
package/dist/esm/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export var version = '3.5.
|
|
1
|
+
export var version = '3.5.2';
|