react-instantsearch 7.29.0 → 7.31.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/dist/cjs/components/AutocompleteSearch.js +6 -3
- package/dist/cjs/components/ChatGreeting.js +16 -0
- package/dist/cjs/components/ChatMessageLoader.js +16 -0
- package/dist/cjs/components/ChatSidePanelLayout.js +17 -0
- package/dist/cjs/components/index.js +3 -0
- package/dist/cjs/ui/SearchBox.js +38 -2
- package/dist/cjs/widgets/Autocomplete.js +43 -19
- package/dist/cjs/widgets/Chat.js +23 -5
- package/dist/cjs/widgets/SearchBox.js +18 -2
- package/dist/cjs/widgets/TrendingFacets.js +55 -0
- package/dist/cjs/widgets/chat/tools/SearchIndexTool.js +7 -3
- package/dist/cjs/widgets/index.js +1 -0
- package/dist/es/components/AutocompleteSearch.d.ts +5 -2
- package/dist/es/components/AutocompleteSearch.js +6 -3
- package/dist/es/components/ChatGreeting.d.ts +1 -0
- package/dist/es/components/ChatGreeting.js +8 -0
- package/dist/es/components/ChatMessageLoader.d.ts +1 -0
- package/dist/es/components/ChatMessageLoader.js +8 -0
- package/dist/es/components/ChatOverlayLayout.d.ts +1 -3
- package/dist/es/components/ChatSidePanelLayout.d.ts +1 -0
- package/dist/es/components/ChatSidePanelLayout.js +9 -0
- package/dist/es/components/index.d.ts +3 -0
- package/dist/es/components/index.js +3 -0
- package/dist/es/index.js +4 -0
- package/dist/es/ui/SearchBox.d.ts +15 -1
- package/dist/es/ui/SearchBox.js +38 -2
- package/dist/es/widgets/Autocomplete.d.ts +6 -0
- package/dist/es/widgets/Autocomplete.js +43 -19
- package/dist/es/widgets/Chat.d.ts +13 -3
- package/dist/es/widgets/Chat.js +37 -19
- package/dist/es/widgets/RefinementList.d.ts +3 -2
- package/dist/es/widgets/SearchBox.d.ts +8 -2
- package/dist/es/widgets/SearchBox.js +19 -3
- package/dist/es/widgets/TrendingFacets.d.ts +11 -0
- package/dist/es/widgets/TrendingFacets.js +46 -0
- package/dist/es/widgets/chat/tools/SearchIndexTool.js +7 -3
- package/dist/es/widgets/index.d.ts +1 -0
- package/dist/es/widgets/index.js +1 -0
- package/dist/umd/ReactInstantSearch.js +988 -262
- package/dist/umd/ReactInstantSearch.min.js +3 -3
- package/package.json +5 -5
- package/dist/cjs/widgets/index.umd.js +0 -69
- package/dist/es/widgets/index.umd.d.ts +0 -32
- package/dist/es/widgets/index.umd.js +0 -37
|
@@ -39,6 +39,14 @@ export type SearchBoxClassNames = {
|
|
|
39
39
|
* Class names to apply to the loading icon
|
|
40
40
|
*/
|
|
41
41
|
loadingIcon: string;
|
|
42
|
+
/**
|
|
43
|
+
* Class names to apply to the AI mode button
|
|
44
|
+
*/
|
|
45
|
+
aiModeButton: string;
|
|
46
|
+
/**
|
|
47
|
+
* Class names to apply to the AI mode icon
|
|
48
|
+
*/
|
|
49
|
+
aiModeIcon: string;
|
|
42
50
|
};
|
|
43
51
|
export type SearchBoxTranslations = {
|
|
44
52
|
/**
|
|
@@ -49,6 +57,10 @@ export type SearchBoxTranslations = {
|
|
|
49
57
|
* The alternative text of the reset button.
|
|
50
58
|
*/
|
|
51
59
|
resetButtonTitle: string;
|
|
60
|
+
/**
|
|
61
|
+
* The alternative text of the AI mode button.
|
|
62
|
+
*/
|
|
63
|
+
aiModeButtonTitle?: string;
|
|
52
64
|
};
|
|
53
65
|
export type SearchBoxProps = Omit<React.ComponentProps<'div'>, 'onSubmit' | 'onReset' | 'onChange'> & Pick<React.ComponentProps<'form'>, 'onSubmit'> & Required<Pick<React.ComponentProps<'form'>, 'onReset'>> & Pick<React.ComponentProps<'input'>, 'placeholder' | 'autoFocus'> & {
|
|
54
66
|
onChange?: (event: React.ChangeEvent<HTMLInputElement> | React.CompositionEvent<HTMLInputElement>) => void;
|
|
@@ -60,7 +72,9 @@ export type SearchBoxProps = Omit<React.ComponentProps<'div'>, 'onSubmit' | 'onR
|
|
|
60
72
|
resetIconComponent?: React.JSXElementConstructor<IconProps>;
|
|
61
73
|
submitIconComponent?: React.JSXElementConstructor<IconProps>;
|
|
62
74
|
loadingIconComponent?: React.JSXElementConstructor<IconProps>;
|
|
75
|
+
aiModeIconComponent?: React.JSXElementConstructor<IconProps>;
|
|
76
|
+
onAiModeClick?: () => void;
|
|
63
77
|
classNames?: Partial<SearchBoxClassNames>;
|
|
64
78
|
translations: SearchBoxTranslations;
|
|
65
79
|
};
|
|
66
|
-
export declare function SearchBox({ formRef, inputRef, inputProps, isSearchStalled, onChange, onReset, onSubmit, placeholder, value, autoFocus, resetIconComponent: ResetIcon, submitIconComponent: SubmitIcon, loadingIconComponent: LoadingIcon, classNames, translations, ...props }: SearchBoxProps): React.JSX.Element;
|
|
80
|
+
export declare function SearchBox({ formRef, inputRef, inputProps, isSearchStalled, onChange, onReset, onSubmit, placeholder, value, autoFocus, resetIconComponent: ResetIcon, submitIconComponent: SubmitIcon, loadingIconComponent: LoadingIcon, aiModeIconComponent: AiModeIcon, onAiModeClick, classNames, translations, ...props }: SearchBoxProps): React.JSX.Element;
|
package/dist/es/ui/SearchBox.js
CHANGED
|
@@ -60,8 +60,30 @@ function DefaultLoadingIcon(param) {
|
|
|
60
60
|
repeatCount: "indefinite"
|
|
61
61
|
})))));
|
|
62
62
|
}
|
|
63
|
+
function DefaultAiModeIcon(param) {
|
|
64
|
+
var classNames = param.classNames;
|
|
65
|
+
return /*#__PURE__*/ React.createElement("svg", {
|
|
66
|
+
className: cx('ais-AiModeButton-icon', classNames.aiModeIcon),
|
|
67
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
68
|
+
fill: "none",
|
|
69
|
+
viewBox: "0 0 20 20",
|
|
70
|
+
width: "16",
|
|
71
|
+
height: "16",
|
|
72
|
+
"aria-hidden": "true"
|
|
73
|
+
}, /*#__PURE__*/ React.createElement("path", {
|
|
74
|
+
fill: "currentColor",
|
|
75
|
+
fillRule: "evenodd",
|
|
76
|
+
d: "M10 1.875c.27 0 .51.173.594.43l1.593 4.844a1.043 1.043 0 0 0 .664.664l4.844 1.593a.625.625 0 0 1 0 1.188l-4.844 1.593a1.043 1.043 0 0 0-.664.664l-1.593 4.844a.625.625 0 0 1-1.188 0l-1.593-4.844a1.042 1.042 0 0 0-.664-.664l-4.844-1.593a.625.625 0 0 1 0-1.188l4.844-1.593a1.042 1.042 0 0 0 .664-.664l1.593-4.844a.625.625 0 0 1 .594-.43ZM9 7.539A2.292 2.292 0 0 1 7.54 9L4.5 10l3.04 1A2.292 2.292 0 0 1 9 12.46l1 3.04 1-3.04A2.293 2.293 0 0 1 12.46 11l3.04-1-3.04-1A2.292 2.292 0 0 1 11 7.54L10 4.5 9 7.54ZM4.167 1.875c.345 0 .625.28.625.625v3.333a.625.625 0 0 1-1.25 0V2.5c0-.345.28-.625.625-.625ZM15.833 13.542c.345 0 .625.28.625.625V17.5a.625.625 0 1 1-1.25 0v-3.333c0-.345.28-.625.625-.625Z",
|
|
77
|
+
clipRule: "evenodd"
|
|
78
|
+
}), /*#__PURE__*/ React.createElement("path", {
|
|
79
|
+
fill: "currentColor",
|
|
80
|
+
fillRule: "evenodd",
|
|
81
|
+
d: "M1.875 4.167c0-.346.28-.625.625-.625h3.333a.625.625 0 1 1 0 1.25H2.5a.625.625 0 0 1-.625-.625ZM13.542 15.833c0-.345.28-.625.625-.625H17.5a.625.625 0 0 1 0 1.25h-3.333a.625.625 0 0 1-.625-.625Z",
|
|
82
|
+
clipRule: "evenodd"
|
|
83
|
+
}));
|
|
84
|
+
}
|
|
63
85
|
function SearchBox(_0) {
|
|
64
|
-
var formRef = _0.formRef, inputRef = _0.inputRef, inputProps = _0.inputProps, isSearchStalled = _0.isSearchStalled, onChange = _0.onChange, onReset = _0.onReset, onSubmit = _0.onSubmit, _0_placeholder = _0.placeholder, placeholder = _0_placeholder === void 0 ? '' : _0_placeholder, value = _0.value, autoFocus = _0.autoFocus, tmp = _0.resetIconComponent, ResetIcon = tmp === void 0 ? DefaultResetIcon : tmp, tmp1 = _0.submitIconComponent, SubmitIcon = tmp1 === void 0 ? DefaultSubmitIcon : tmp1, tmp2 = _0.loadingIconComponent, LoadingIcon = tmp2 === void 0 ? DefaultLoadingIcon : tmp2, _0_classNames = _0.classNames, classNames = _0_classNames === void 0 ? {} : _0_classNames, translations = _0.translations, props = _(_0, [
|
|
86
|
+
var formRef = _0.formRef, inputRef = _0.inputRef, inputProps = _0.inputProps, isSearchStalled = _0.isSearchStalled, onChange = _0.onChange, onReset = _0.onReset, onSubmit = _0.onSubmit, _0_placeholder = _0.placeholder, placeholder = _0_placeholder === void 0 ? '' : _0_placeholder, value = _0.value, autoFocus = _0.autoFocus, tmp = _0.resetIconComponent, ResetIcon = tmp === void 0 ? DefaultResetIcon : tmp, tmp1 = _0.submitIconComponent, SubmitIcon = tmp1 === void 0 ? DefaultSubmitIcon : tmp1, tmp2 = _0.loadingIconComponent, LoadingIcon = tmp2 === void 0 ? DefaultLoadingIcon : tmp2, tmp3 = _0.aiModeIconComponent, AiModeIcon = tmp3 === void 0 ? DefaultAiModeIcon : tmp3, onAiModeClick = _0.onAiModeClick, _0_classNames = _0.classNames, classNames = _0_classNames === void 0 ? {} : _0_classNames, translations = _0.translations, props = _(_0, [
|
|
65
87
|
"formRef",
|
|
66
88
|
"inputRef",
|
|
67
89
|
"inputProps",
|
|
@@ -75,6 +97,8 @@ function SearchBox(_0) {
|
|
|
75
97
|
"resetIconComponent",
|
|
76
98
|
"submitIconComponent",
|
|
77
99
|
"loadingIconComponent",
|
|
100
|
+
"aiModeIconComponent",
|
|
101
|
+
"onAiModeClick",
|
|
78
102
|
"classNames",
|
|
79
103
|
"translations"
|
|
80
104
|
]);
|
|
@@ -134,7 +158,19 @@ function SearchBox(_0) {
|
|
|
134
158
|
hidden: value.length === 0 || isSearchStalled
|
|
135
159
|
}, /*#__PURE__*/ React.createElement(ResetIcon, {
|
|
136
160
|
classNames: classNames
|
|
137
|
-
})), /*#__PURE__*/ React.createElement("
|
|
161
|
+
})), onAiModeClick && /*#__PURE__*/ React.createElement("button", {
|
|
162
|
+
className: cx('ais-AiModeButton', classNames.aiModeButton),
|
|
163
|
+
type: "button",
|
|
164
|
+
title: translations.aiModeButtonTitle || 'AI Mode',
|
|
165
|
+
onClick: function onClick(e) {
|
|
166
|
+
e.preventDefault();
|
|
167
|
+
onAiModeClick();
|
|
168
|
+
}
|
|
169
|
+
}, /*#__PURE__*/ React.createElement(AiModeIcon, {
|
|
170
|
+
classNames: classNames
|
|
171
|
+
}), /*#__PURE__*/ React.createElement("span", {
|
|
172
|
+
className: "ais-AiModeButton-label"
|
|
173
|
+
}, translations.aiModeButtonTitle || 'AI Mode')), /*#__PURE__*/ React.createElement("span", {
|
|
138
174
|
className: cx('ais-SearchBox-loadingIndicator', classNames.loadingIndicator),
|
|
139
175
|
hidden: !isSearchStalled
|
|
140
176
|
}, /*#__PURE__*/ React.createElement(LoadingIcon, {
|
|
@@ -77,6 +77,12 @@ export type AutocompleteProps<TItem extends BaseHit> = ComponentProps<'div'> & {
|
|
|
77
77
|
* Translations for the Autocomplete widget.
|
|
78
78
|
*/
|
|
79
79
|
translations?: Partial<AutocompleteTranslations>;
|
|
80
|
+
/**
|
|
81
|
+
* When true, renders an AI mode button inside the search input
|
|
82
|
+
* that opens the Chat widget and sends the current query.
|
|
83
|
+
* Requires a Chat widget on the same index.
|
|
84
|
+
*/
|
|
85
|
+
aiMode?: boolean;
|
|
80
86
|
};
|
|
81
87
|
export declare function EXPERIMENTAL_Autocomplete<TItem extends BaseHit = BaseHit>({ indices, showQuerySuggestions, showPromptSuggestions, showRecent, searchParameters: userSearchParameters, detachedMediaQuery, translations: userTranslations, ...props }: AutocompleteProps<TItem>): React.JSX.Element;
|
|
82
88
|
export {};
|
|
@@ -308,7 +308,7 @@ function EXPERIMENTAL_Autocomplete(_0) {
|
|
|
308
308
|
}))));
|
|
309
309
|
}
|
|
310
310
|
function InnerAutocomplete(_0) {
|
|
311
|
-
var indicesConfig = _0.indicesConfig, refineSearchBox = _0.refineSearchBox, isSearchStalled = _0.isSearchStalled, getSearchPageURL = _0.getSearchPageURL, userOnSelect = _0.onSelect, indexUiState = _0.indexUiState, isSearchPage = _0.isSearchPage, PanelComponent = _0.panelComponent, showRecent = _0.showRecent, recentSearchConfig = _0.recentSearchConfig, showQuerySuggestions = _0.showQuerySuggestions, showPromptSuggestions = _0.showPromptSuggestions, chatRenderState = _0.chatRenderState, transformItems = _0.transformItems, placeholder = _0.placeholder, autoFocus = _0.autoFocus, _0_detachedMediaQuery = _0.detachedMediaQuery, detachedMediaQuery = _0_detachedMediaQuery === void 0 ? DEFAULT_DETACHED_MEDIA_QUERY : _0_detachedMediaQuery, translations = _0.translations, classNames = _0.classNames, props = _(_0, [
|
|
311
|
+
var indicesConfig = _0.indicesConfig, refineSearchBox = _0.refineSearchBox, isSearchStalled = _0.isSearchStalled, getSearchPageURL = _0.getSearchPageURL, userOnSelect = _0.onSelect, indexUiState = _0.indexUiState, isSearchPage = _0.isSearchPage, PanelComponent = _0.panelComponent, showRecent = _0.showRecent, recentSearchConfig = _0.recentSearchConfig, showQuerySuggestions = _0.showQuerySuggestions, showPromptSuggestions = _0.showPromptSuggestions, chatRenderState = _0.chatRenderState, transformItems = _0.transformItems, placeholder = _0.placeholder, autoFocus = _0.autoFocus, _0_detachedMediaQuery = _0.detachedMediaQuery, detachedMediaQuery = _0_detachedMediaQuery === void 0 ? DEFAULT_DETACHED_MEDIA_QUERY : _0_detachedMediaQuery, translations = _0.translations, classNames = _0.classNames, aiMode = _0.aiMode, props = _(_0, [
|
|
312
312
|
"indicesConfig",
|
|
313
313
|
"refineSearchBox",
|
|
314
314
|
"isSearchStalled",
|
|
@@ -327,13 +327,18 @@ function InnerAutocomplete(_0) {
|
|
|
327
327
|
"autoFocus",
|
|
328
328
|
"detachedMediaQuery",
|
|
329
329
|
"translations",
|
|
330
|
-
"classNames"
|
|
330
|
+
"classNames",
|
|
331
|
+
"aiMode"
|
|
331
332
|
]);
|
|
332
|
-
var _ref;
|
|
333
|
+
var _indexUiState_query, _ref;
|
|
333
334
|
var _showPromptSuggestions_searchParameters;
|
|
334
335
|
var _useAutocomplete = useAutocomplete({
|
|
335
|
-
transformItems: transformItems
|
|
336
|
+
transformItems: transformItems,
|
|
337
|
+
future: {
|
|
338
|
+
undefinedEmptyQuery: true
|
|
339
|
+
}
|
|
336
340
|
}), indices = _useAutocomplete.indices, refineAutocomplete = _useAutocomplete.refine, currentRefinement = _useAutocomplete.currentRefinement;
|
|
341
|
+
var resolvedQuery = currentRefinement !== undefined ? currentRefinement : (_indexUiState_query = indexUiState.query) !== null && _indexUiState_query !== void 0 ? _indexUiState_query : '';
|
|
337
342
|
var _useDetachedMode = useDetachedMode(detachedMediaQuery), isDetached = _useDetachedMode.isDetached, isModalDetached = _useDetachedMode.isModalDetached, isModalOpen = _useDetachedMode.isModalOpen, setIsModalOpen = _useDetachedMode.setIsModalOpen;
|
|
338
343
|
var previousIsDetachedRef = useRef(isDetached);
|
|
339
344
|
var _useStorage = useStorage({
|
|
@@ -499,7 +504,7 @@ function InnerAutocomplete(_0) {
|
|
|
499
504
|
});
|
|
500
505
|
}
|
|
501
506
|
indicesForPanel.forEach(function(param) {
|
|
502
|
-
var indexId = param.indexId, indexName = param.indexName, hits = param.hits;
|
|
507
|
+
var indexId = param.indexId, indexName = param.indexName, hits = param.hits, sendEvent = param.sendEvent;
|
|
503
508
|
var elementId = indexName;
|
|
504
509
|
if (indexName === (showQuerySuggestions === null || showQuerySuggestions === void 0 ? void 0 : showQuerySuggestions.indexName)) {
|
|
505
510
|
elementId = 'suggestions';
|
|
@@ -525,9 +530,14 @@ function InnerAutocomplete(_0) {
|
|
|
525
530
|
});
|
|
526
531
|
}),
|
|
527
532
|
getItemProps: getItemProps,
|
|
533
|
+
sendEvent: sendEvent,
|
|
528
534
|
classNames: currentIndexConfig.classNames
|
|
529
535
|
});
|
|
530
536
|
});
|
|
537
|
+
var handleCancel = function handleCancel() {
|
|
538
|
+
setIsModalOpen(false);
|
|
539
|
+
setIsOpen(false);
|
|
540
|
+
};
|
|
531
541
|
var searchBoxContent = /*#__PURE__*/ React.createElement(AutocompleteSearch, {
|
|
532
542
|
inputProps: getInputProps(),
|
|
533
543
|
clearQuery: function clearQuery() {
|
|
@@ -537,9 +547,31 @@ function InnerAutocomplete(_0) {
|
|
|
537
547
|
onQueryChange: function onQueryChange(query) {
|
|
538
548
|
refineAutocomplete(query);
|
|
539
549
|
},
|
|
540
|
-
query:
|
|
541
|
-
|
|
542
|
-
|
|
550
|
+
query: resolvedQuery,
|
|
551
|
+
isSearchStalled: isSearchStalled,
|
|
552
|
+
onCancel: function onCancel() {
|
|
553
|
+
if (isDetached) {
|
|
554
|
+
handleCancel();
|
|
555
|
+
}
|
|
556
|
+
},
|
|
557
|
+
isDetached: isDetached,
|
|
558
|
+
submitTitle: isDetached ? translations.detachedCancelButtonText : undefined,
|
|
559
|
+
onAiModeClick: aiMode ? function() {
|
|
560
|
+
setIsOpen(false);
|
|
561
|
+
if (isDetached) {
|
|
562
|
+
setIsModalOpen(false);
|
|
563
|
+
}
|
|
564
|
+
if (chatRenderState) {
|
|
565
|
+
var _chatRenderState_setOpen;
|
|
566
|
+
(_chatRenderState_setOpen = chatRenderState.setOpen) === null || _chatRenderState_setOpen === void 0 ? void 0 : _chatRenderState_setOpen.call(chatRenderState, true);
|
|
567
|
+
if (resolvedQuery.trim()) {
|
|
568
|
+
var _chatRenderState_sendMessage;
|
|
569
|
+
(_chatRenderState_sendMessage = chatRenderState.sendMessage) === null || _chatRenderState_sendMessage === void 0 ? void 0 : _chatRenderState_sendMessage.call(chatRenderState, {
|
|
570
|
+
text: resolvedQuery
|
|
571
|
+
});
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
} : undefined
|
|
543
575
|
});
|
|
544
576
|
var panelContent = /*#__PURE__*/ React.createElement(AutocompletePanel, getPanelProps(), PanelComponent ? /*#__PURE__*/ React.createElement(PanelComponent, {
|
|
545
577
|
elements: elements,
|
|
@@ -558,7 +590,7 @@ function InnerAutocomplete(_0) {
|
|
|
558
590
|
rootRef: rootRef,
|
|
559
591
|
classNames: classNames
|
|
560
592
|
}), /*#__PURE__*/ React.createElement(AutocompleteDetachedSearchButton, {
|
|
561
|
-
query:
|
|
593
|
+
query: resolvedQuery,
|
|
562
594
|
placeholder: placeholder,
|
|
563
595
|
classNames: classNames,
|
|
564
596
|
onClick: function onClick() {
|
|
@@ -572,19 +604,11 @@ function InnerAutocomplete(_0) {
|
|
|
572
604
|
translations: translations
|
|
573
605
|
}), isModalOpen && /*#__PURE__*/ React.createElement(AutocompleteDetachedOverlay, {
|
|
574
606
|
classNames: classNames,
|
|
575
|
-
onClose:
|
|
576
|
-
setIsModalOpen(false);
|
|
577
|
-
setIsOpen(false);
|
|
578
|
-
}
|
|
607
|
+
onClose: handleCancel
|
|
579
608
|
}, /*#__PURE__*/ React.createElement(AutocompleteDetachedContainer, {
|
|
580
609
|
classNames: detachedContainerClassNames
|
|
581
610
|
}, /*#__PURE__*/ React.createElement(AutocompleteDetachedFormContainer, {
|
|
582
|
-
classNames: classNames
|
|
583
|
-
onCancel: function onCancel() {
|
|
584
|
-
setIsModalOpen(false);
|
|
585
|
-
setIsOpen(false);
|
|
586
|
-
},
|
|
587
|
-
translations: translations
|
|
611
|
+
classNames: classNames
|
|
588
612
|
}, searchBoxContent), panelContent)));
|
|
589
613
|
}
|
|
590
614
|
// Normal (non-detached) rendering
|
|
@@ -14,7 +14,7 @@ type UserMessagesProps = Omit<ChatUiProps['messagesProps'], 'messages' | 'tools'
|
|
|
14
14
|
type UserPromptProps = Omit<ChatUiProps['promptProps'], 'value' | 'onInput' | 'onSubmit' | 'headerComponent' | 'footerComponent'>;
|
|
15
15
|
export type Tool = UserClientSideTool;
|
|
16
16
|
export type Tools = UserClientSideTools;
|
|
17
|
-
export type ChatProps<TObject, TUiMessage extends UIMessage = UIMessage> = Omit<ChatUiProps, keyof UiProps> & UseChatProps<TUiMessage> & {
|
|
17
|
+
export type ChatProps<TObject, TUiMessage extends UIMessage = UIMessage> = Omit<ChatUiProps, keyof UiProps | 'ref'> & UseChatProps<TUiMessage> & {
|
|
18
18
|
itemComponent?: ItemComponent<TObject>;
|
|
19
19
|
tools?: UserClientSideTools;
|
|
20
20
|
getSearchPageURL?: (nextUiState: IndexUiState) => string;
|
|
@@ -30,11 +30,12 @@ export type ChatProps<TObject, TUiMessage extends UIMessage = UIMessage> = Omit<
|
|
|
30
30
|
headerCloseIconComponent?: ChatUiProps['headerProps']['closeIconComponent'];
|
|
31
31
|
headerMinimizeIconComponent?: ChatUiProps['headerProps']['minimizeIconComponent'];
|
|
32
32
|
headerMaximizeIconComponent?: ChatUiProps['headerProps']['maximizeIconComponent'];
|
|
33
|
-
messagesLoaderComponent?: ChatUiProps['messagesProps']['loaderComponent'];
|
|
34
33
|
messagesErrorComponent?: ChatUiProps['messagesProps']['errorComponent'];
|
|
35
34
|
promptComponent?: ChatUiProps['promptComponent'];
|
|
36
35
|
promptHeaderComponent?: ChatUiProps['promptProps']['headerComponent'];
|
|
37
36
|
promptFooterComponent?: ChatUiProps['promptProps']['footerComponent'];
|
|
37
|
+
loaderComponent?: ChatUiProps['messagesProps']['loaderComponent'];
|
|
38
|
+
emptyComponent?: ChatUiProps['messagesProps']['emptyComponent'];
|
|
38
39
|
actionsComponent?: ChatUiProps['messagesProps']['actionsComponent'];
|
|
39
40
|
assistantMessageLeadingComponent?: ChatMessageProps['leadingComponent'];
|
|
40
41
|
assistantMessageFooterComponent?: ChatMessageProps['footerComponent'];
|
|
@@ -48,4 +49,13 @@ export type ChatProps<TObject, TUiMessage extends UIMessage = UIMessage> = Omit<
|
|
|
48
49
|
messages: ChatUiProps['messagesProps']['translations'];
|
|
49
50
|
}>;
|
|
50
51
|
};
|
|
51
|
-
export
|
|
52
|
+
export type ChatHandle = {
|
|
53
|
+
setOpen: (open: boolean) => void;
|
|
54
|
+
sendMessage: (params: {
|
|
55
|
+
text: string;
|
|
56
|
+
}) => void;
|
|
57
|
+
setInput: (input: string) => void;
|
|
58
|
+
};
|
|
59
|
+
export declare const Chat: <TObject extends RecordWithObjectID = RecordWithObjectID, TUiMessage extends UIMessage = UIMessage>(props: ChatProps<TObject, TUiMessage> & {
|
|
60
|
+
ref?: React.Ref<ChatHandle>;
|
|
61
|
+
}) => React.ReactElement | null;
|
package/dist/es/widgets/Chat.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { _ } from '@swc/helpers/esm/_define_property.js';
|
|
2
|
-
import { _ as _$
|
|
3
|
-
import { _ as _$
|
|
4
|
-
import { _ as _$
|
|
5
|
-
import { _ as _$
|
|
2
|
+
import { _ as _$4 } from '@swc/helpers/esm/_object_spread.js';
|
|
3
|
+
import { _ as _$5 } from '@swc/helpers/esm/_object_spread_props.js';
|
|
4
|
+
import { _ as _$2 } from '@swc/helpers/esm/_object_without_properties.js';
|
|
5
|
+
import { _ as _$3 } from '@swc/helpers/esm/_sliced_to_array.js';
|
|
6
|
+
import { _ as _$1 } from '@swc/helpers/esm/_to_array.js';
|
|
6
7
|
import { createChatComponent } from 'instantsearch-ui-components';
|
|
7
8
|
import { SearchIndexToolType, RecommendToolType, MemorizeToolType, MemorySearchToolType, PonderToolType } from 'instantsearch.js/es/lib/chat/index.js';
|
|
8
9
|
export { MemorizeToolType, MemorySearchToolType, PonderToolType, RecommendToolType, SearchIndexToolType } from 'instantsearch.js/es/lib/chat/index.js';
|
|
9
|
-
import React, { createElement, Fragment, useState, useRef, useMemo, useEffect } from 'react';
|
|
10
|
+
import React, { createElement, Fragment, useState, useRef, useMemo, useImperativeHandle, useEffect } from 'react';
|
|
10
11
|
import { useInstantSearch, useChat } from 'react-instantsearch-core';
|
|
11
12
|
import { useStickToBottom } from '../lib/useStickToBottom.js';
|
|
12
13
|
import { createCarouselTool } from './chat/tools/SearchIndexTool.js';
|
|
@@ -19,8 +20,11 @@ function createDefaultTools(itemComponent, getSearchPageURL) {
|
|
|
19
20
|
var _obj;
|
|
20
21
|
return _obj = {}, _(_obj, SearchIndexToolType, createCarouselTool(true, itemComponent, getSearchPageURL)), _(_obj, RecommendToolType, createCarouselTool(false, itemComponent, getSearchPageURL)), _(_obj, MemorizeToolType, {}), _(_obj, MemorySearchToolType, {}), _(_obj, PonderToolType, {}), _obj;
|
|
21
22
|
}
|
|
22
|
-
function
|
|
23
|
-
var
|
|
23
|
+
function ChatInner(_0, _1) {
|
|
24
|
+
var _ref = [
|
|
25
|
+
_0,
|
|
26
|
+
_1
|
|
27
|
+
], _ref1 = _$1(_ref), _ref2 = _ref1[0], _rest = _ref1.slice(1), userTools = _ref2.tools, toggleButtonProps = _ref2.toggleButtonProps, headerProps = _ref2.headerProps, messagesProps = _ref2.messagesProps, promptProps = _ref2.promptProps, itemComponent = _ref2.itemComponent, layoutComponent = _ref2.layoutComponent, toggleButtonComponent = _ref2.toggleButtonComponent, toggleButtonIconComponent = _ref2.toggleButtonIconComponent, headerComponent = _ref2.headerComponent, headerTitleIconComponent = _ref2.headerTitleIconComponent, headerCloseIconComponent = _ref2.headerCloseIconComponent, headerMinimizeIconComponent = _ref2.headerMinimizeIconComponent, headerMaximizeIconComponent = _ref2.headerMaximizeIconComponent, loaderComponent = _ref2.loaderComponent, messagesErrorComponent = _ref2.messagesErrorComponent, promptComponent = _ref2.promptComponent, promptHeaderComponent = _ref2.promptHeaderComponent, promptFooterComponent = _ref2.promptFooterComponent, assistantMessageLeadingComponent = _ref2.assistantMessageLeadingComponent, assistantMessageFooterComponent = _ref2.assistantMessageFooterComponent, userMessageLeadingComponent = _ref2.userMessageLeadingComponent, userMessageFooterComponent = _ref2.userMessageFooterComponent, emptyComponent = _ref2.emptyComponent, actionsComponent = _ref2.actionsComponent, suggestionsComponent = _ref2.suggestionsComponent, classNames = _ref2.classNames, _ref_translations = _ref2.translations, translations = _ref_translations === void 0 ? {} : _ref_translations, title = _ref2.title, getSearchPageURL = _ref2.getSearchPageURL, props = _$2(_ref2, [
|
|
24
28
|
"tools",
|
|
25
29
|
"toggleButtonProps",
|
|
26
30
|
"headerProps",
|
|
@@ -35,7 +39,7 @@ function Chat(_0) {
|
|
|
35
39
|
"headerCloseIconComponent",
|
|
36
40
|
"headerMinimizeIconComponent",
|
|
37
41
|
"headerMaximizeIconComponent",
|
|
38
|
-
"
|
|
42
|
+
"loaderComponent",
|
|
39
43
|
"messagesErrorComponent",
|
|
40
44
|
"promptComponent",
|
|
41
45
|
"promptHeaderComponent",
|
|
@@ -44,16 +48,17 @@ function Chat(_0) {
|
|
|
44
48
|
"assistantMessageFooterComponent",
|
|
45
49
|
"userMessageLeadingComponent",
|
|
46
50
|
"userMessageFooterComponent",
|
|
51
|
+
"emptyComponent",
|
|
47
52
|
"actionsComponent",
|
|
48
53
|
"suggestionsComponent",
|
|
49
54
|
"classNames",
|
|
50
55
|
"translations",
|
|
51
56
|
"title",
|
|
52
57
|
"getSearchPageURL"
|
|
53
|
-
]);
|
|
58
|
+
]), _rest1 = _$3(_rest, 1), ref = _rest1[0];
|
|
54
59
|
var promptTranslations = translations.prompt, headerTranslations = translations.header, messageTranslations = translations.message, messagesTranslations = translations.messages;
|
|
55
60
|
var _useInstantSearch = useInstantSearch(), indexUiState = _useInstantSearch.indexUiState, setIndexUiState = _useInstantSearch.setIndexUiState;
|
|
56
|
-
var _useState = _$
|
|
61
|
+
var _useState = _$3(useState(false), 2), maximized = _useState[0], setMaximized = _useState[1];
|
|
57
62
|
var promptRef = useRef(null);
|
|
58
63
|
var _useStickToBottom = useStickToBottom({
|
|
59
64
|
initial: 'smooth',
|
|
@@ -61,16 +66,25 @@ function Chat(_0) {
|
|
|
61
66
|
}), scrollRef = _useStickToBottom.scrollRef, contentRef = _useStickToBottom.contentRef, scrollToBottom = _useStickToBottom.scrollToBottom, isAtBottom = _useStickToBottom.isAtBottom;
|
|
62
67
|
var tools = useMemo(function() {
|
|
63
68
|
var defaults = createDefaultTools(itemComponent, getSearchPageURL);
|
|
64
|
-
return _$
|
|
69
|
+
return _$4({}, defaults, userTools);
|
|
65
70
|
}, [
|
|
66
71
|
getSearchPageURL,
|
|
67
72
|
itemComponent,
|
|
68
73
|
userTools
|
|
69
74
|
]);
|
|
70
|
-
var chatState = useChat(_$
|
|
75
|
+
var chatState = useChat(_$5(_$4({}, props), {
|
|
71
76
|
tools: tools
|
|
72
77
|
}));
|
|
73
78
|
var messages = chatState.messages, sendMessage = chatState.sendMessage, status = chatState.status, regenerate = chatState.regenerate, stop = chatState.stop, error = chatState.error, input = chatState.input, setInput = chatState.setInput, open = chatState.open, setOpen = chatState.setOpen, isClearing = chatState.isClearing, clearMessages = chatState.clearMessages, onClearTransitionEnd = chatState.onClearTransitionEnd, toolsFromConnector = chatState.tools, suggestions = chatState.suggestions, onFeedback = chatState.sendChatMessageFeedback, feedbackState = chatState.feedbackState;
|
|
79
|
+
useImperativeHandle(ref, function() {
|
|
80
|
+
return {
|
|
81
|
+
setOpen: setOpen,
|
|
82
|
+
sendMessage: function sendMessage1(params) {
|
|
83
|
+
return sendMessage(params);
|
|
84
|
+
},
|
|
85
|
+
setInput: setInput
|
|
86
|
+
};
|
|
87
|
+
});
|
|
74
88
|
var wasOpenRef = useRef(false);
|
|
75
89
|
useEffect(function() {
|
|
76
90
|
var shouldFocusPrompt = !wasOpenRef.current && open;
|
|
@@ -97,14 +111,14 @@ function Chat(_0) {
|
|
|
97
111
|
promptComponent: promptComponent,
|
|
98
112
|
toggleButtonComponent: toggleButtonComponent,
|
|
99
113
|
suggestionsComponent: suggestionsComponent,
|
|
100
|
-
toggleButtonProps: _$
|
|
114
|
+
toggleButtonProps: _$4({
|
|
101
115
|
open: open,
|
|
102
116
|
onClick: function onClick() {
|
|
103
117
|
return setOpen(!open);
|
|
104
118
|
},
|
|
105
119
|
toggleIconComponent: toggleButtonIconComponent
|
|
106
120
|
}, toggleButtonProps),
|
|
107
|
-
headerProps: _$
|
|
121
|
+
headerProps: _$4({
|
|
108
122
|
onClose: function onClose() {
|
|
109
123
|
return setOpen(false);
|
|
110
124
|
},
|
|
@@ -120,7 +134,7 @@ function Chat(_0) {
|
|
|
120
134
|
maximizeIconComponent: headerMaximizeIconComponent,
|
|
121
135
|
translations: headerTranslations
|
|
122
136
|
}, headerProps),
|
|
123
|
-
messagesProps: _$
|
|
137
|
+
messagesProps: _$4({
|
|
124
138
|
status: status,
|
|
125
139
|
onReload: function onReload(messageId) {
|
|
126
140
|
return regenerate({
|
|
@@ -130,6 +144,8 @@ function Chat(_0) {
|
|
|
130
144
|
onClose: function onClose() {
|
|
131
145
|
return setOpen(false);
|
|
132
146
|
},
|
|
147
|
+
sendMessage: sendMessage,
|
|
148
|
+
setInput: setInput,
|
|
133
149
|
onFeedback: onFeedback,
|
|
134
150
|
feedbackState: feedbackState,
|
|
135
151
|
messages: messages,
|
|
@@ -142,21 +158,22 @@ function Chat(_0) {
|
|
|
142
158
|
scrollRef: scrollRef,
|
|
143
159
|
contentRef: contentRef,
|
|
144
160
|
onScrollToBottom: scrollToBottom,
|
|
145
|
-
loaderComponent:
|
|
161
|
+
loaderComponent: loaderComponent,
|
|
146
162
|
errorComponent: messagesErrorComponent,
|
|
163
|
+
emptyComponent: emptyComponent,
|
|
147
164
|
actionsComponent: actionsComponent,
|
|
148
|
-
assistantMessageProps: _$
|
|
165
|
+
assistantMessageProps: _$4({
|
|
149
166
|
leadingComponent: assistantMessageLeadingComponent,
|
|
150
167
|
footerComponent: assistantMessageFooterComponent
|
|
151
168
|
}, messagesProps === null || messagesProps === void 0 ? void 0 : messagesProps.assistantMessageProps),
|
|
152
|
-
userMessageProps: _$
|
|
169
|
+
userMessageProps: _$4({
|
|
153
170
|
leadingComponent: userMessageLeadingComponent,
|
|
154
171
|
footerComponent: userMessageFooterComponent
|
|
155
172
|
}, messagesProps === null || messagesProps === void 0 ? void 0 : messagesProps.userMessageProps),
|
|
156
173
|
translations: messagesTranslations,
|
|
157
174
|
messageTranslations: messageTranslations
|
|
158
175
|
}, messagesProps),
|
|
159
|
-
promptProps: _$
|
|
176
|
+
promptProps: _$4({
|
|
160
177
|
promptRef: promptRef,
|
|
161
178
|
status: status,
|
|
162
179
|
value: input,
|
|
@@ -187,5 +204,6 @@ function Chat(_0) {
|
|
|
187
204
|
classNames: classNames
|
|
188
205
|
});
|
|
189
206
|
}
|
|
207
|
+
var Chat = /*#__PURE__*/ React.forwardRef(ChatInner);
|
|
190
208
|
|
|
191
209
|
export { Chat, createDefaultTools };
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import type { RefinementListProps as RefinementListUiComponentProps } from '../ui/RefinementList';
|
|
3
|
-
import type { SearchBoxTranslations } from '../ui/SearchBox';
|
|
4
3
|
import type { RefinementListWidgetParams } from 'instantsearch.js/es/widgets/refinement-list/refinement-list';
|
|
5
4
|
import type { UseRefinementListProps } from 'react-instantsearch-core';
|
|
6
5
|
type UiProps = Pick<RefinementListUiComponentProps, 'canRefine' | 'items' | 'onRefine' | 'query' | 'searchBox' | 'noResults' | 'canToggleShowMore' | 'onToggleShowMore' | 'isShowingMore' | 'translations'>;
|
|
7
6
|
export type RefinementListProps = Omit<RefinementListUiComponentProps, keyof UiProps> & UseRefinementListProps & Pick<RefinementListWidgetParams, 'searchable' | 'searchablePlaceholder' | 'searchableSelectOnSubmit'> & {
|
|
8
|
-
translations?: Partial<UiProps['translations'] &
|
|
7
|
+
translations?: Partial<UiProps['translations'] & {
|
|
8
|
+
submitButtonTitle: string;
|
|
9
|
+
resetButtonTitle: string;
|
|
9
10
|
/**
|
|
10
11
|
* What to display when there are no results.
|
|
11
12
|
*/
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import type { SearchBoxProps as SearchBoxUiComponentProps } from '../ui/SearchBox';
|
|
3
3
|
import type { UseSearchBoxProps } from 'react-instantsearch-core';
|
|
4
|
-
type UiProps = Pick<SearchBoxUiComponentProps, 'inputRef' | 'isSearchStalled' | 'onChange' | 'onReset' | 'onSubmit' | 'value' | 'autoFocus' | 'translations'>;
|
|
4
|
+
type UiProps = Pick<SearchBoxUiComponentProps, 'inputRef' | 'isSearchStalled' | 'onChange' | 'onReset' | 'onSubmit' | 'onAiModeClick' | 'value' | 'autoFocus' | 'translations'>;
|
|
5
5
|
export type SearchBoxProps = Omit<SearchBoxUiComponentProps, Exclude<keyof UiProps, 'onSubmit' | 'autoFocus'>> & UseSearchBoxProps & {
|
|
6
6
|
/**
|
|
7
7
|
* Whether to trigger the search only on submit.
|
|
@@ -14,7 +14,13 @@ export type SearchBoxProps = Omit<SearchBoxUiComponentProps, Exclude<keyof UiPro
|
|
|
14
14
|
* @default false
|
|
15
15
|
*/
|
|
16
16
|
ignoreCompositionEvents?: boolean;
|
|
17
|
+
/**
|
|
18
|
+
* When true, renders an AI mode button inside the search box
|
|
19
|
+
* that opens the Chat widget and sends the current query.
|
|
20
|
+
* Requires a Chat widget on the same index.
|
|
21
|
+
*/
|
|
22
|
+
aiMode?: boolean;
|
|
17
23
|
translations?: Partial<UiProps['translations']>;
|
|
18
24
|
};
|
|
19
|
-
export declare function SearchBox({ queryHook, searchAsYouType, ignoreCompositionEvents, translations, ...props }: SearchBoxProps): React.JSX.Element;
|
|
25
|
+
export declare function SearchBox({ queryHook, searchAsYouType, ignoreCompositionEvents, aiMode, translations, ...props }: SearchBoxProps): React.JSX.Element;
|
|
20
26
|
export {};
|
|
@@ -2,14 +2,15 @@ import { _ as _$2 } from '@swc/helpers/esm/_object_spread.js';
|
|
|
2
2
|
import { _ } from '@swc/helpers/esm/_object_without_properties.js';
|
|
3
3
|
import { _ as _$1 } from '@swc/helpers/esm/_sliced_to_array.js';
|
|
4
4
|
import React, { useState, useRef } from 'react';
|
|
5
|
-
import { useSearchBox } from 'react-instantsearch-core';
|
|
5
|
+
import { useSearchBox, useInstantSearch } from 'react-instantsearch-core';
|
|
6
6
|
import { SearchBox as SearchBox$1 } from '../ui/SearchBox.js';
|
|
7
7
|
|
|
8
8
|
function SearchBox(_0) {
|
|
9
|
-
var queryHook = _0.queryHook, _0_searchAsYouType = _0.searchAsYouType, searchAsYouType = _0_searchAsYouType === void 0 ? true : _0_searchAsYouType, _0_ignoreCompositionEvents = _0.ignoreCompositionEvents, ignoreCompositionEvents = _0_ignoreCompositionEvents === void 0 ? false : _0_ignoreCompositionEvents, translations = _0.translations, props = _(_0, [
|
|
9
|
+
var queryHook = _0.queryHook, _0_searchAsYouType = _0.searchAsYouType, searchAsYouType = _0_searchAsYouType === void 0 ? true : _0_searchAsYouType, _0_ignoreCompositionEvents = _0.ignoreCompositionEvents, ignoreCompositionEvents = _0_ignoreCompositionEvents === void 0 ? false : _0_ignoreCompositionEvents, aiMode = _0.aiMode, translations = _0.translations, props = _(_0, [
|
|
10
10
|
"queryHook",
|
|
11
11
|
"searchAsYouType",
|
|
12
12
|
"ignoreCompositionEvents",
|
|
13
|
+
"aiMode",
|
|
13
14
|
"translations"
|
|
14
15
|
]);
|
|
15
16
|
var _useSearchBox = useSearchBox({
|
|
@@ -17,6 +18,7 @@ function SearchBox(_0) {
|
|
|
17
18
|
}, {
|
|
18
19
|
$$widgetType: 'ais.searchBox'
|
|
19
20
|
}), query = _useSearchBox.query, refine = _useSearchBox.refine, isSearchStalled = _useSearchBox.isSearchStalled;
|
|
21
|
+
var indexRenderState = useInstantSearch().indexRenderState;
|
|
20
22
|
var _useState = _$1(useState(query), 2), inputValue = _useState[0], setInputValue = _useState[1];
|
|
21
23
|
var inputRef = useRef(null);
|
|
22
24
|
function setQuery(newQuery) {
|
|
@@ -56,10 +58,24 @@ function SearchBox(_0) {
|
|
|
56
58
|
onChange: onChange,
|
|
57
59
|
onReset: onReset,
|
|
58
60
|
onSubmit: onSubmit,
|
|
61
|
+
onAiModeClick: aiMode ? function() {
|
|
62
|
+
var chatRenderState = indexRenderState.chat;
|
|
63
|
+
if (chatRenderState) {
|
|
64
|
+
var _chatRenderState_setOpen;
|
|
65
|
+
(_chatRenderState_setOpen = chatRenderState.setOpen) === null || _chatRenderState_setOpen === void 0 ? void 0 : _chatRenderState_setOpen.call(chatRenderState, true);
|
|
66
|
+
if (inputValue.trim()) {
|
|
67
|
+
var _chatRenderState_sendMessage;
|
|
68
|
+
(_chatRenderState_sendMessage = chatRenderState.sendMessage) === null || _chatRenderState_sendMessage === void 0 ? void 0 : _chatRenderState_sendMessage.call(chatRenderState, {
|
|
69
|
+
text: inputValue
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
} : undefined,
|
|
59
74
|
value: inputValue,
|
|
60
75
|
translations: _$2({
|
|
61
76
|
submitButtonTitle: 'Submit the search query',
|
|
62
|
-
resetButtonTitle: 'Clear the search query'
|
|
77
|
+
resetButtonTitle: 'Clear the search query',
|
|
78
|
+
aiModeButtonTitle: 'AI Mode'
|
|
63
79
|
}, translations)
|
|
64
80
|
};
|
|
65
81
|
return /*#__PURE__*/ React.createElement(SearchBox$1, _$2({}, props, uiProps));
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { TrendingFacetsProps as TrendingFacetsUiComponentProps } from 'instantsearch-ui-components';
|
|
3
|
+
import type { UseTrendingFacetsProps } from 'react-instantsearch-core';
|
|
4
|
+
type UiProps = Pick<TrendingFacetsUiComponentProps, 'items' | 'itemComponent' | 'headerComponent' | 'emptyComponent' | 'status'>;
|
|
5
|
+
export type TrendingFacetsProps = Omit<TrendingFacetsUiComponentProps, keyof UiProps> & UseTrendingFacetsProps & {
|
|
6
|
+
itemComponent?: TrendingFacetsUiComponentProps['itemComponent'];
|
|
7
|
+
headerComponent?: TrendingFacetsUiComponentProps['headerComponent'];
|
|
8
|
+
emptyComponent?: TrendingFacetsUiComponentProps['emptyComponent'];
|
|
9
|
+
};
|
|
10
|
+
export declare function TrendingFacets({ facetName, limit, threshold, fallbackParameters, queryParameters, escapeHTML, transformItems, itemComponent, headerComponent, emptyComponent, ...props }: TrendingFacetsProps): React.JSX.Element;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { _ as _$1 } from '@swc/helpers/esm/_object_spread.js';
|
|
2
|
+
import { _ } from '@swc/helpers/esm/_object_without_properties.js';
|
|
3
|
+
import { createTrendingFacetsComponent } from 'instantsearch-ui-components';
|
|
4
|
+
import React, { createElement, Fragment } from 'react';
|
|
5
|
+
import { useInstantSearch, useTrendingFacets } from 'react-instantsearch-core';
|
|
6
|
+
|
|
7
|
+
var TrendingFacetsUiComponent = createTrendingFacetsComponent({
|
|
8
|
+
createElement: createElement,
|
|
9
|
+
Fragment: Fragment
|
|
10
|
+
});
|
|
11
|
+
function TrendingFacets(_0) {
|
|
12
|
+
var facetName = _0.facetName, limit = _0.limit, threshold = _0.threshold, fallbackParameters = _0.fallbackParameters, queryParameters = _0.queryParameters, escapeHTML = _0.escapeHTML, transformItems = _0.transformItems, itemComponent = _0.itemComponent, headerComponent = _0.headerComponent, emptyComponent = _0.emptyComponent, props = _(_0, [
|
|
13
|
+
"facetName",
|
|
14
|
+
"limit",
|
|
15
|
+
"threshold",
|
|
16
|
+
"fallbackParameters",
|
|
17
|
+
"queryParameters",
|
|
18
|
+
"escapeHTML",
|
|
19
|
+
"transformItems",
|
|
20
|
+
"itemComponent",
|
|
21
|
+
"headerComponent",
|
|
22
|
+
"emptyComponent"
|
|
23
|
+
]);
|
|
24
|
+
var status = useInstantSearch().status;
|
|
25
|
+
var items = useTrendingFacets({
|
|
26
|
+
facetName: facetName,
|
|
27
|
+
limit: limit,
|
|
28
|
+
threshold: threshold,
|
|
29
|
+
fallbackParameters: fallbackParameters,
|
|
30
|
+
queryParameters: queryParameters,
|
|
31
|
+
escapeHTML: escapeHTML,
|
|
32
|
+
transformItems: transformItems
|
|
33
|
+
}, {
|
|
34
|
+
$$widgetType: 'ais.trendingFacets'
|
|
35
|
+
}).items;
|
|
36
|
+
var uiProps = {
|
|
37
|
+
items: items,
|
|
38
|
+
itemComponent: itemComponent,
|
|
39
|
+
headerComponent: headerComponent,
|
|
40
|
+
emptyComponent: emptyComponent,
|
|
41
|
+
status: status
|
|
42
|
+
};
|
|
43
|
+
return /*#__PURE__*/ React.createElement(TrendingFacetsUiComponent, _$1({}, props, uiProps));
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export { TrendingFacets };
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { _ } from '@swc/helpers/esm/_object_spread.js';
|
|
2
2
|
import { createButtonComponent, ArrowRightIcon, ChevronLeftIcon, ChevronRightIcon } from 'instantsearch-ui-components';
|
|
3
|
+
import { addAbsolutePosition, addQueryID } from 'instantsearch.js/es/lib/utils/index.js';
|
|
3
4
|
import React, { createElement } from 'react';
|
|
4
5
|
import { Carousel } from '../../../components/Carousel.js';
|
|
5
6
|
|
|
@@ -8,10 +9,13 @@ function createCarouselTool(showViewAll, itemComponent, getSearchPageURL) {
|
|
|
8
9
|
createElement: createElement
|
|
9
10
|
});
|
|
10
11
|
function SearchLayoutComponent(param) {
|
|
11
|
-
var message = param.message, applyFilters = param.applyFilters, onClose = param.onClose;
|
|
12
|
+
var message = param.message, applyFilters = param.applyFilters, onClose = param.onClose, sendEvent = param.sendEvent;
|
|
13
|
+
var _ref;
|
|
14
|
+
var _output_hits;
|
|
12
15
|
var input = message === null || message === void 0 ? void 0 : message.input;
|
|
13
16
|
var output = message === null || message === void 0 ? void 0 : message.output;
|
|
14
|
-
var
|
|
17
|
+
var hitsWithAbsolutePosition = addAbsolutePosition((output === null || output === void 0 ? void 0 : output.hits) || [], 0, ((_ref = input === null || input === void 0 ? void 0 : input.number_of_results) !== null && _ref !== void 0 ? _ref : output === null || output === void 0 ? void 0 : (_output_hits = output.hits) === null || _output_hits === void 0 ? void 0 : _output_hits.length) || 5);
|
|
18
|
+
var items = addQueryID(hitsWithAbsolutePosition, output === null || output === void 0 ? void 0 : output.queryID);
|
|
15
19
|
var MemoedHeaderComponent = React.useMemo(function() {
|
|
16
20
|
return function(props) {
|
|
17
21
|
return /*#__PURE__*/ React.createElement(HeaderComponent, _({
|
|
@@ -32,7 +36,7 @@ function createCarouselTool(showViewAll, itemComponent, getSearchPageURL) {
|
|
|
32
36
|
return /*#__PURE__*/ React.createElement(Carousel, {
|
|
33
37
|
items: items,
|
|
34
38
|
itemComponent: itemComponent,
|
|
35
|
-
sendEvent:
|
|
39
|
+
sendEvent: sendEvent,
|
|
36
40
|
showNavigation: false,
|
|
37
41
|
headerComponent: MemoedHeaderComponent
|
|
38
42
|
});
|
package/dist/es/widgets/index.js
CHANGED
|
@@ -23,5 +23,6 @@ export { SortBy } from './SortBy.js';
|
|
|
23
23
|
export { Stats } from './Stats.js';
|
|
24
24
|
export { ToggleRefinement } from './ToggleRefinement.js';
|
|
25
25
|
export { TrendingItems } from './TrendingItems.js';
|
|
26
|
+
export { TrendingFacets } from './TrendingFacets.js';
|
|
26
27
|
export { FilterSuggestions } from './FilterSuggestions.js';
|
|
27
28
|
export { MemorizeToolType, MemorySearchToolType, PonderToolType, RecommendToolType, SearchIndexToolType } from 'instantsearch.js/es/lib/chat/index.js';
|