react-instantsearch 7.18.0 → 7.20.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/ui/ReverseHighlight.js +27 -0
- package/dist/cjs/widgets/Autocomplete.js +117 -30
- package/dist/cjs/widgets/Chat.js +34 -25
- package/dist/cjs/widgets/ReverseHighlight.js +46 -0
- package/dist/cjs/widgets/index.js +11 -0
- package/dist/cjs/widgets/index.umd.js +12 -0
- package/dist/es/ui/ReverseHighlight.d.ts +7 -0
- package/dist/es/ui/ReverseHighlight.js +20 -0
- package/dist/es/widgets/Autocomplete.d.ts +25 -1
- package/dist/es/widgets/Autocomplete.js +117 -30
- package/dist/es/widgets/Chat.d.ts +10 -6
- package/dist/es/widgets/Chat.js +34 -25
- package/dist/es/widgets/ReverseHighlight.d.ts +9 -0
- package/dist/es/widgets/ReverseHighlight.js +39 -0
- package/dist/es/widgets/index.d.ts +1 -0
- package/dist/es/widgets/index.js +1 -0
- package/dist/es/widgets/index.umd.d.ts +1 -0
- package/dist/es/widgets/index.umd.js +1 -0
- package/dist/umd/ReactInstantSearch.js +766 -320
- package/dist/umd/ReactInstantSearch.js.map +1 -1
- package/dist/umd/ReactInstantSearch.min.js +1 -1
- package/dist/umd/ReactInstantSearch.min.js.map +1 -1
- package/package.json +5 -5
|
@@ -1,11 +1,6 @@
|
|
|
1
|
+
var _excluded = ["indices", "showSuggestions", "showRecent", "searchParameters"],
|
|
2
|
+
_excluded2 = ["indicesConfig", "refineSearchBox", "getSearchPageURL", "onSelect", "indexUiState", "isSearchPage", "panelComponent", "showRecent", "showSuggestions"];
|
|
1
3
|
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
-
var _excluded = ["indices", "showSuggestions"],
|
|
3
|
-
_excluded2 = ["indicesConfig", "refineSearchBox", "getSearchPageURL", "onSelect", "indexUiState", "isSearchPage"];
|
|
4
|
-
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
5
|
-
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
6
|
-
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
7
|
-
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
8
|
-
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
9
4
|
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
|
|
10
5
|
function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
|
|
11
6
|
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
@@ -13,12 +8,18 @@ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r)
|
|
|
13
8
|
function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
|
|
14
9
|
function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
|
|
15
10
|
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
11
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
12
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
13
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
14
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
15
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
16
16
|
function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
|
|
17
17
|
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
|
|
18
|
-
import { createAutocompleteComponent, createAutocompleteIndexComponent, createAutocompletePanelComponent, createAutocompletePropGetters, createAutocompleteSuggestionComponent, cx } from 'instantsearch-ui-components';
|
|
18
|
+
import { createAutocompleteComponent, createAutocompleteIndexComponent, createAutocompletePanelComponent, createAutocompletePropGetters, createAutocompleteSuggestionComponent, createAutocompleteRecentSearchComponent, createAutocompleteStorage, cx } from 'instantsearch-ui-components';
|
|
19
19
|
import React, { createElement, Fragment, useEffect, useId, useMemo, useRef, useState } from 'react';
|
|
20
20
|
import { Configure, Index, useAutocomplete, useInstantSearch, useSearchBox } from 'react-instantsearch-core';
|
|
21
21
|
import { AutocompleteSearch } from "../components/AutocompleteSearch.js";
|
|
22
|
+
import { ReverseHighlight } from "./ReverseHighlight.js";
|
|
22
23
|
var Autocomplete = createAutocompleteComponent({
|
|
23
24
|
createElement: createElement,
|
|
24
25
|
Fragment: Fragment
|
|
@@ -35,6 +36,10 @@ var AutocompleteSuggestion = createAutocompleteSuggestionComponent({
|
|
|
35
36
|
createElement: createElement,
|
|
36
37
|
Fragment: Fragment
|
|
37
38
|
});
|
|
39
|
+
var AutocompleteRecentSearch = createAutocompleteRecentSearchComponent({
|
|
40
|
+
createElement: createElement,
|
|
41
|
+
Fragment: Fragment
|
|
42
|
+
});
|
|
38
43
|
var usePropGetters = createAutocompletePropGetters({
|
|
39
44
|
useEffect: useEffect,
|
|
40
45
|
useId: useId,
|
|
@@ -42,13 +47,17 @@ var usePropGetters = createAutocompletePropGetters({
|
|
|
42
47
|
useRef: useRef,
|
|
43
48
|
useState: useState
|
|
44
49
|
});
|
|
45
|
-
var
|
|
46
|
-
|
|
50
|
+
var useStorage = createAutocompleteStorage({
|
|
51
|
+
useEffect: useEffect,
|
|
52
|
+
useMemo: useMemo,
|
|
53
|
+
useState: useState
|
|
47
54
|
});
|
|
48
55
|
export function EXPERIMENTAL_Autocomplete(_ref) {
|
|
49
56
|
var _ref$indices = _ref.indices,
|
|
50
57
|
indices = _ref$indices === void 0 ? [] : _ref$indices,
|
|
51
58
|
showSuggestions = _ref.showSuggestions,
|
|
59
|
+
showRecent = _ref.showRecent,
|
|
60
|
+
userSearchParameters = _ref.searchParameters,
|
|
52
61
|
props = _objectWithoutProperties(_ref, _excluded);
|
|
53
62
|
var _useInstantSearch = useInstantSearch(),
|
|
54
63
|
indexUiState = _useInstantSearch.indexUiState,
|
|
@@ -58,13 +67,25 @@ export function EXPERIMENTAL_Autocomplete(_ref) {
|
|
|
58
67
|
$$widgetType: 'ais.autocomplete'
|
|
59
68
|
}),
|
|
60
69
|
refine = _useSearchBox.refine;
|
|
70
|
+
var searchParameters = _objectSpread({
|
|
71
|
+
hitsPerPage: 5
|
|
72
|
+
}, userSearchParameters);
|
|
61
73
|
var indicesConfig = _toConsumableArray(indices);
|
|
62
74
|
if (showSuggestions !== null && showSuggestions !== void 0 && showSuggestions.indexName) {
|
|
63
75
|
var _showSuggestions$clas, _showSuggestions$clas2, _showSuggestions$clas3, _showSuggestions$clas4;
|
|
64
76
|
indicesConfig.unshift({
|
|
65
77
|
indexName: showSuggestions.indexName,
|
|
66
78
|
headerComponent: showSuggestions.headerComponent,
|
|
67
|
-
itemComponent: showSuggestions.itemComponent ||
|
|
79
|
+
itemComponent: showSuggestions.itemComponent || function (_ref2) {
|
|
80
|
+
var item = _ref2.item,
|
|
81
|
+
onSelect = _ref2.onSelect;
|
|
82
|
+
return /*#__PURE__*/React.createElement(AutocompleteSuggestion, {
|
|
83
|
+
item: item,
|
|
84
|
+
onSelect: onSelect
|
|
85
|
+
}, /*#__PURE__*/React.createElement(ConditionalReverseHighlight, {
|
|
86
|
+
item: item
|
|
87
|
+
}));
|
|
88
|
+
},
|
|
68
89
|
classNames: {
|
|
69
90
|
root: cx('ais-AutocompleteSuggestions', showSuggestions === null || showSuggestions === void 0 ? void 0 : (_showSuggestions$clas = showSuggestions.classNames) === null || _showSuggestions$clas === void 0 ? void 0 : _showSuggestions$clas.root),
|
|
70
91
|
list: cx('ais-AutocompleteSuggestionsList', showSuggestions === null || showSuggestions === void 0 ? void 0 : (_showSuggestions$clas2 = showSuggestions.classNames) === null || _showSuggestions$clas2 === void 0 ? void 0 : _showSuggestions$clas2.list),
|
|
@@ -82,16 +103,18 @@ export function EXPERIMENTAL_Autocomplete(_ref) {
|
|
|
82
103
|
}, [indexRenderState]);
|
|
83
104
|
return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement(Index, {
|
|
84
105
|
EXPERIMENTAL_isolated: true
|
|
85
|
-
},
|
|
106
|
+
}, /*#__PURE__*/React.createElement(Configure, searchParameters), indicesConfig.map(function (index) {
|
|
86
107
|
return /*#__PURE__*/React.createElement(Index, {
|
|
87
108
|
key: index.indexName,
|
|
88
109
|
indexName: index.indexName
|
|
89
|
-
});
|
|
110
|
+
}, /*#__PURE__*/React.createElement(Configure, index.searchParameters));
|
|
90
111
|
}), /*#__PURE__*/React.createElement(InnerAutocomplete, _extends({}, props, {
|
|
91
112
|
indicesConfig: indicesConfig,
|
|
92
113
|
refineSearchBox: refine,
|
|
93
114
|
indexUiState: indexUiState,
|
|
94
|
-
isSearchPage: isSearchPage
|
|
115
|
+
isSearchPage: isSearchPage,
|
|
116
|
+
showRecent: showRecent,
|
|
117
|
+
showSuggestions: showSuggestions
|
|
95
118
|
}))));
|
|
96
119
|
}
|
|
97
120
|
function InnerAutocomplete(_ref3) {
|
|
@@ -101,16 +124,31 @@ function InnerAutocomplete(_ref3) {
|
|
|
101
124
|
userOnSelect = _ref3.onSelect,
|
|
102
125
|
indexUiState = _ref3.indexUiState,
|
|
103
126
|
isSearchPage = _ref3.isSearchPage,
|
|
127
|
+
PanelComponent = _ref3.panelComponent,
|
|
128
|
+
showRecent = _ref3.showRecent,
|
|
129
|
+
showSuggestions = _ref3.showSuggestions,
|
|
104
130
|
props = _objectWithoutProperties(_ref3, _excluded2);
|
|
105
131
|
var _useAutocomplete = useAutocomplete(),
|
|
106
132
|
indices = _useAutocomplete.indices,
|
|
107
|
-
refineAutocomplete = _useAutocomplete.refine
|
|
108
|
-
|
|
133
|
+
refineAutocomplete = _useAutocomplete.refine,
|
|
134
|
+
currentRefinement = _useAutocomplete.currentRefinement;
|
|
135
|
+
var _useStorage = useStorage({
|
|
136
|
+
showRecent: showRecent,
|
|
137
|
+
query: currentRefinement,
|
|
109
138
|
indices: indices,
|
|
110
|
-
indicesConfig: indicesConfig
|
|
139
|
+
indicesConfig: indicesConfig
|
|
140
|
+
}),
|
|
141
|
+
storage = _useStorage.storage,
|
|
142
|
+
storageHits = _useStorage.storageHits,
|
|
143
|
+
indicesForPropGetters = _useStorage.indicesForPropGetters,
|
|
144
|
+
indicesConfigForPropGetters = _useStorage.indicesConfigForPropGetters;
|
|
145
|
+
var _usePropGetters = usePropGetters({
|
|
146
|
+
indices: indicesForPropGetters,
|
|
147
|
+
indicesConfig: indicesConfigForPropGetters,
|
|
111
148
|
onRefine: function onRefine(query) {
|
|
112
149
|
refineAutocomplete(query);
|
|
113
150
|
refineSearchBox(query);
|
|
151
|
+
storage.onAdd(query);
|
|
114
152
|
},
|
|
115
153
|
onSelect: userOnSelect !== null && userOnSelect !== void 0 ? userOnSelect : function (_ref4) {
|
|
116
154
|
var query = _ref4.query,
|
|
@@ -133,30 +171,79 @@ function InnerAutocomplete(_ref3) {
|
|
|
133
171
|
getItemProps = _usePropGetters.getItemProps,
|
|
134
172
|
getPanelProps = _usePropGetters.getPanelProps,
|
|
135
173
|
getRootProps = _usePropGetters.getRootProps;
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
174
|
+
var AutocompleteRecentSearchComponent = _typeof(showRecent) === 'object' && showRecent.itemComponent || AutocompleteRecentSearch;
|
|
175
|
+
var elements = {};
|
|
176
|
+
if (showRecent) {
|
|
177
|
+
elements.recent = /*#__PURE__*/React.createElement(AutocompleteIndex
|
|
178
|
+
// @ts-ignore - there seems to be problems with React.ComponentType and this, but it's actually correct
|
|
179
|
+
, {
|
|
180
|
+
ItemComponent: function ItemComponent(_ref5) {
|
|
181
|
+
var item = _ref5.item,
|
|
182
|
+
onSelect = _ref5.onSelect;
|
|
183
|
+
return /*#__PURE__*/React.createElement(AutocompleteRecentSearchComponent, {
|
|
184
|
+
item: item,
|
|
185
|
+
onSelect: onSelect,
|
|
186
|
+
onRemoveRecentSearch: function onRemoveRecentSearch() {
|
|
187
|
+
return storage.onRemove(item.query);
|
|
188
|
+
}
|
|
189
|
+
}, /*#__PURE__*/React.createElement(ConditionalReverseHighlight, {
|
|
190
|
+
item: item
|
|
191
|
+
}));
|
|
192
|
+
},
|
|
193
|
+
classNames: {
|
|
194
|
+
root: 'ais-AutocompleteRecentSearches',
|
|
195
|
+
list: 'ais-AutocompleteRecentSearchesList',
|
|
196
|
+
item: 'ais-AutocompleteRecentSearchesItem'
|
|
197
|
+
},
|
|
198
|
+
items: storageHits,
|
|
199
|
+
getItemProps: getItemProps
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
indices.forEach(function (_ref6, i) {
|
|
203
|
+
var indexId = _ref6.indexId,
|
|
204
|
+
indexName = _ref6.indexName,
|
|
205
|
+
hits = _ref6.hits;
|
|
206
|
+
var elementId = indexName === (showSuggestions === null || showSuggestions === void 0 ? void 0 : showSuggestions.indexName) ? 'suggestions' : indexName;
|
|
207
|
+
elements[elementId] = /*#__PURE__*/React.createElement(AutocompleteIndex, {
|
|
146
208
|
key: indexId
|
|
147
209
|
// @ts-expect-error - there seems to be problems with React.ComponentType and this, but it's actually correct
|
|
148
210
|
,
|
|
149
|
-
HeaderComponent: indicesConfig[
|
|
211
|
+
HeaderComponent: indicesConfig[i].headerComponent
|
|
150
212
|
// @ts-expect-error - there seems to be problems with React.ComponentType and this, but it's actually correct
|
|
151
213
|
,
|
|
152
|
-
ItemComponent: indicesConfig[
|
|
214
|
+
ItemComponent: indicesConfig[i].itemComponent,
|
|
153
215
|
items: hits.map(function (item) {
|
|
154
216
|
return _objectSpread(_objectSpread({}, item), {}, {
|
|
155
217
|
__indexName: indexId
|
|
156
218
|
});
|
|
157
219
|
}),
|
|
158
220
|
getItemProps: getItemProps,
|
|
159
|
-
classNames: indicesConfig[
|
|
221
|
+
classNames: indicesConfig[i].classNames
|
|
160
222
|
});
|
|
223
|
+
});
|
|
224
|
+
return /*#__PURE__*/React.createElement(Autocomplete, _extends({}, props, getRootProps()), /*#__PURE__*/React.createElement(AutocompleteSearch, {
|
|
225
|
+
inputProps: getInputProps(),
|
|
226
|
+
clearQuery: function clearQuery() {
|
|
227
|
+
refineSearchBox('');
|
|
228
|
+
refineAutocomplete('');
|
|
229
|
+
}
|
|
230
|
+
}), /*#__PURE__*/React.createElement(AutocompletePanel, getPanelProps(), PanelComponent ? /*#__PURE__*/React.createElement(PanelComponent, {
|
|
231
|
+
elements: elements,
|
|
232
|
+
indices: indices
|
|
233
|
+
}) : Object.keys(elements).map(function (elementId) {
|
|
234
|
+
return elements[elementId];
|
|
161
235
|
})));
|
|
236
|
+
}
|
|
237
|
+
function ConditionalReverseHighlight(_ref7) {
|
|
238
|
+
var _item$_highlightResul;
|
|
239
|
+
var item = _ref7.item;
|
|
240
|
+
if (!((_item$_highlightResul = item._highlightResult) !== null && _item$_highlightResul !== void 0 && _item$_highlightResul.query) ||
|
|
241
|
+
// @ts-expect-error - we should not have matchLevel as arrays here
|
|
242
|
+
item._highlightResult.query.matchLevel === 'none') {
|
|
243
|
+
return item.query;
|
|
244
|
+
}
|
|
245
|
+
return /*#__PURE__*/React.createElement(ReverseHighlight, {
|
|
246
|
+
attribute: "query",
|
|
247
|
+
hit: item
|
|
248
|
+
});
|
|
162
249
|
}
|
|
@@ -1,23 +1,22 @@
|
|
|
1
1
|
import { SearchIndexToolType, RecommendToolType } from 'instantsearch.js/es/lib/chat';
|
|
2
2
|
import React from 'react';
|
|
3
3
|
export { SearchIndexToolType, RecommendToolType };
|
|
4
|
-
import type { ChatProps as ChatUiProps, RecommendComponentProps, RecordWithObjectID, UserClientSideTool, UserClientSideTools } from 'instantsearch-ui-components';
|
|
4
|
+
import type { ChatProps as ChatUiProps, RecommendComponentProps, RecordWithObjectID, UserClientSideTool, UserClientSideTools, ChatMessageProps } from 'instantsearch-ui-components';
|
|
5
5
|
import type { IndexUiState } from 'instantsearch.js';
|
|
6
6
|
import type { UIMessage } from 'instantsearch.js/es/lib/chat';
|
|
7
|
-
import type {
|
|
7
|
+
import type { UseChatProps } from 'react-instantsearch-core';
|
|
8
8
|
export declare function createDefaultTools<TObject extends RecordWithObjectID>(itemComponent?: ItemComponent<TObject>, getSearchPageURL?: (nextUiState: IndexUiState) => string): UserClientSideTools;
|
|
9
9
|
type ItemComponent<TObject> = RecommendComponentProps<TObject>['itemComponent'];
|
|
10
10
|
type UiProps = Pick<ChatUiProps, 'open' | 'headerProps' | 'toggleButtonProps' | 'messagesProps' | 'promptProps' | 'headerComponent' | 'promptComponent'>;
|
|
11
11
|
type UserToggleButtonProps = Omit<ChatUiProps['toggleButtonProps'], 'open' | 'onClick'>;
|
|
12
12
|
type UserHeaderProps = Omit<ChatUiProps['headerProps'], 'onClose'>;
|
|
13
|
-
type UserMessagesProps = Omit<ChatUiProps['messagesProps'], 'messages' | 'tools' | 'indexUiState' | 'setIndexUiState' | 'scrollRef' | 'contentRef'>;
|
|
13
|
+
type UserMessagesProps = Omit<ChatUiProps['messagesProps'], 'messages' | 'tools' | 'indexUiState' | 'setIndexUiState' | 'scrollRef' | 'contentRef' | 'messageComponent' | 'leadingComponent' | 'footerComponent' | 'translations' | 'classNames'>;
|
|
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> &
|
|
17
|
+
export type ChatProps<TObject, TUiMessage extends UIMessage = UIMessage> = Omit<ChatUiProps, keyof UiProps> & UseChatProps<TUiMessage> & {
|
|
18
18
|
itemComponent?: ItemComponent<TObject>;
|
|
19
19
|
tools?: UserClientSideTools;
|
|
20
|
-
defaultOpen?: boolean;
|
|
21
20
|
getSearchPageURL?: (nextUiState: IndexUiState) => string;
|
|
22
21
|
toggleButtonProps?: UserToggleButtonProps;
|
|
23
22
|
headerProps?: UserHeaderProps;
|
|
@@ -36,10 +35,15 @@ export type ChatProps<TObject, TUiMessage extends UIMessage = UIMessage> = Omit<
|
|
|
36
35
|
promptHeaderComponent?: ChatUiProps['promptProps']['headerComponent'];
|
|
37
36
|
promptFooterComponent?: ChatUiProps['promptProps']['footerComponent'];
|
|
38
37
|
actionsComponent?: ChatUiProps['messagesProps']['actionsComponent'];
|
|
38
|
+
assistantMessageLeadingComponent?: ChatMessageProps['leadingComponent'];
|
|
39
|
+
assistantMessageFooterComponent?: ChatMessageProps['footerComponent'];
|
|
40
|
+
userMessageLeadingComponent?: ChatMessageProps['leadingComponent'];
|
|
41
|
+
userMessageFooterComponent?: ChatMessageProps['footerComponent'];
|
|
39
42
|
translations?: Partial<{
|
|
40
43
|
prompt: ChatUiProps['promptProps']['translations'];
|
|
41
44
|
header: ChatUiProps['headerProps']['translations'];
|
|
45
|
+
message: ChatUiProps['messagesProps']['messageTranslations'];
|
|
42
46
|
messages: ChatUiProps['messagesProps']['translations'];
|
|
43
47
|
}>;
|
|
44
48
|
};
|
|
45
|
-
export declare function Chat<TObject extends RecordWithObjectID, TUiMessage extends UIMessage>({ tools: userTools,
|
|
49
|
+
export declare function Chat<TObject extends RecordWithObjectID, TUiMessage extends UIMessage>({ tools: userTools, toggleButtonProps, headerProps, messagesProps, promptProps, itemComponent, toggleButtonComponent, toggleButtonIconComponent, headerComponent, headerTitleIconComponent, headerCloseIconComponent, headerMinimizeIconComponent, headerMaximizeIconComponent, messagesLoaderComponent, messagesErrorComponent, promptComponent, promptHeaderComponent, promptFooterComponent, assistantMessageLeadingComponent, assistantMessageFooterComponent, userMessageLeadingComponent, userMessageFooterComponent, actionsComponent, classNames, translations, title, getSearchPageURL, ...props }: ChatProps<TObject, TUiMessage>): React.JSX.Element;
|
package/dist/es/widgets/Chat.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var _excluded = ["tools", "
|
|
1
|
+
var _excluded = ["tools", "toggleButtonProps", "headerProps", "messagesProps", "promptProps", "itemComponent", "toggleButtonComponent", "toggleButtonIconComponent", "headerComponent", "headerTitleIconComponent", "headerCloseIconComponent", "headerMinimizeIconComponent", "headerMaximizeIconComponent", "messagesLoaderComponent", "messagesErrorComponent", "promptComponent", "promptHeaderComponent", "promptFooterComponent", "assistantMessageLeadingComponent", "assistantMessageFooterComponent", "userMessageLeadingComponent", "userMessageFooterComponent", "actionsComponent", "classNames", "translations", "title", "getSearchPageURL"];
|
|
2
2
|
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
3
3
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
4
4
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
@@ -13,7 +13,6 @@ function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t =
|
|
|
13
13
|
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
14
14
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
15
15
|
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
16
|
-
import { lastAssistantMessageIsCompleteWithToolCalls } from 'ai';
|
|
17
16
|
import { createChatComponent } from 'instantsearch-ui-components';
|
|
18
17
|
import { SearchIndexToolType, RecommendToolType } from "instantsearch.js/es/lib/chat/index.js";
|
|
19
18
|
import React, { createElement, Fragment } from 'react';
|
|
@@ -31,8 +30,6 @@ export function createDefaultTools(itemComponent, getSearchPageURL) {
|
|
|
31
30
|
}
|
|
32
31
|
export function Chat(_ref2) {
|
|
33
32
|
var userTools = _ref2.tools,
|
|
34
|
-
_ref2$defaultOpen = _ref2.defaultOpen,
|
|
35
|
-
defaultOpen = _ref2$defaultOpen === void 0 ? false : _ref2$defaultOpen,
|
|
36
33
|
toggleButtonProps = _ref2.toggleButtonProps,
|
|
37
34
|
headerProps = _ref2.headerProps,
|
|
38
35
|
messagesProps = _ref2.messagesProps,
|
|
@@ -50,6 +47,10 @@ export function Chat(_ref2) {
|
|
|
50
47
|
promptComponent = _ref2.promptComponent,
|
|
51
48
|
promptHeaderComponent = _ref2.promptHeaderComponent,
|
|
52
49
|
promptFooterComponent = _ref2.promptFooterComponent,
|
|
50
|
+
assistantMessageLeadingComponent = _ref2.assistantMessageLeadingComponent,
|
|
51
|
+
assistantMessageFooterComponent = _ref2.assistantMessageFooterComponent,
|
|
52
|
+
userMessageLeadingComponent = _ref2.userMessageLeadingComponent,
|
|
53
|
+
userMessageFooterComponent = _ref2.userMessageFooterComponent,
|
|
53
54
|
actionsComponent = _ref2.actionsComponent,
|
|
54
55
|
classNames = _ref2.classNames,
|
|
55
56
|
_ref2$translations = _ref2.translations,
|
|
@@ -59,6 +60,7 @@ export function Chat(_ref2) {
|
|
|
59
60
|
props = _objectWithoutProperties(_ref2, _excluded);
|
|
60
61
|
var promptTranslations = translations.prompt,
|
|
61
62
|
headerTranslations = translations.header,
|
|
63
|
+
messageTranslations = translations.message,
|
|
62
64
|
messagesTranslations = translations.messages;
|
|
63
65
|
var _useInstantSearch = useInstantSearch(),
|
|
64
66
|
indexUiState = _useInstantSearch.indexUiState,
|
|
@@ -80,25 +82,23 @@ export function Chat(_ref2) {
|
|
|
80
82
|
var defaults = createDefaultTools(itemComponent, getSearchPageURL);
|
|
81
83
|
return _objectSpread(_objectSpread({}, defaults), userTools);
|
|
82
84
|
}, [getSearchPageURL, itemComponent, userTools]);
|
|
83
|
-
var
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
onClearTransitionEnd = _useChat.onClearTransitionEnd,
|
|
101
|
-
hookTools = _useChat.tools;
|
|
85
|
+
var chatState = useChat(_objectSpread(_objectSpread({}, props), {}, {
|
|
86
|
+
tools: tools
|
|
87
|
+
}));
|
|
88
|
+
var messages = chatState.messages,
|
|
89
|
+
sendMessage = chatState.sendMessage,
|
|
90
|
+
status = chatState.status,
|
|
91
|
+
regenerate = chatState.regenerate,
|
|
92
|
+
stop = chatState.stop,
|
|
93
|
+
error = chatState.error,
|
|
94
|
+
input = chatState.input,
|
|
95
|
+
setInput = chatState.setInput,
|
|
96
|
+
open = chatState.open,
|
|
97
|
+
setOpen = chatState.setOpen,
|
|
98
|
+
isClearing = chatState.isClearing,
|
|
99
|
+
clearMessages = chatState.clearMessages,
|
|
100
|
+
onClearTransitionEnd = chatState.onClearTransitionEnd,
|
|
101
|
+
toolsFromConnector = chatState.tools;
|
|
102
102
|
if (process.env.NODE_ENV === 'development' && error) {
|
|
103
103
|
throw error;
|
|
104
104
|
}
|
|
@@ -143,7 +143,7 @@ export function Chat(_ref2) {
|
|
|
143
143
|
return setOpen(false);
|
|
144
144
|
},
|
|
145
145
|
messages: messages,
|
|
146
|
-
tools:
|
|
146
|
+
tools: toolsFromConnector,
|
|
147
147
|
indexUiState: indexUiState,
|
|
148
148
|
setIndexUiState: setIndexUiState,
|
|
149
149
|
isClearing: isClearing,
|
|
@@ -155,7 +155,16 @@ export function Chat(_ref2) {
|
|
|
155
155
|
loaderComponent: messagesLoaderComponent,
|
|
156
156
|
errorComponent: messagesErrorComponent,
|
|
157
157
|
actionsComponent: actionsComponent,
|
|
158
|
-
|
|
158
|
+
assistantMessageProps: _objectSpread({
|
|
159
|
+
leadingComponent: assistantMessageLeadingComponent,
|
|
160
|
+
footerComponent: assistantMessageFooterComponent
|
|
161
|
+
}, messagesProps === null || messagesProps === void 0 ? void 0 : messagesProps.assistantMessageProps),
|
|
162
|
+
userMessageProps: _objectSpread({
|
|
163
|
+
leadingComponent: userMessageLeadingComponent,
|
|
164
|
+
footerComponent: userMessageFooterComponent
|
|
165
|
+
}, messagesProps === null || messagesProps === void 0 ? void 0 : messagesProps.userMessageProps),
|
|
166
|
+
translations: messagesTranslations,
|
|
167
|
+
messageTranslations: messageTranslations
|
|
159
168
|
}, messagesProps),
|
|
160
169
|
promptProps: _objectSpread({
|
|
161
170
|
promptRef: promptRef,
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { PartialKeys } from '../types';
|
|
3
|
+
import type { ReverseHighlightProps as ReverseHighlightUiComponentProps } from '../ui/ReverseHighlight';
|
|
4
|
+
import type { BaseHit, Hit } from 'instantsearch.js';
|
|
5
|
+
export type ReverseHighlightProps<THit extends Hit<BaseHit>> = {
|
|
6
|
+
hit: THit;
|
|
7
|
+
attribute: keyof THit | string[];
|
|
8
|
+
} & PartialKeys<Omit<ReverseHighlightUiComponentProps, 'parts'>, 'highlightedTagName' | 'nonHighlightedTagName' | 'separator'>;
|
|
9
|
+
export declare function ReverseHighlight<THit extends Hit<BaseHit>>({ hit, attribute, highlightedTagName, nonHighlightedTagName, separator, ...props }: ReverseHighlightProps<THit>): React.JSX.Element;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
+
var _excluded = ["hit", "attribute", "highlightedTagName", "nonHighlightedTagName", "separator"],
|
|
3
|
+
_excluded2 = ["isHighlighted"];
|
|
4
|
+
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
|
|
5
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
6
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
7
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
8
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
9
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
10
|
+
function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
|
|
11
|
+
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
|
|
12
|
+
import { getHighlightedParts, getPropertyByPath, unescape } from "instantsearch.js/es/lib/utils/index.js";
|
|
13
|
+
import React from 'react';
|
|
14
|
+
import { ReverseHighlight as ReverseHighlightUiComponent } from "../ui/ReverseHighlight.js";
|
|
15
|
+
export function ReverseHighlight(_ref) {
|
|
16
|
+
var hit = _ref.hit,
|
|
17
|
+
attribute = _ref.attribute,
|
|
18
|
+
highlightedTagName = _ref.highlightedTagName,
|
|
19
|
+
nonHighlightedTagName = _ref.nonHighlightedTagName,
|
|
20
|
+
separator = _ref.separator,
|
|
21
|
+
props = _objectWithoutProperties(_ref, _excluded);
|
|
22
|
+
var property = getPropertyByPath(hit._highlightResult, attribute) || [];
|
|
23
|
+
var properties = Array.isArray(property) ? property : [property];
|
|
24
|
+
var parts = properties.map(function (singleValue) {
|
|
25
|
+
return getHighlightedParts(unescape(singleValue.value || '')).map(function (_ref2) {
|
|
26
|
+
var isHighlighted = _ref2.isHighlighted,
|
|
27
|
+
rest = _objectWithoutProperties(_ref2, _excluded2);
|
|
28
|
+
return _objectSpread(_objectSpread({}, rest), {}, {
|
|
29
|
+
isHighlighted: !isHighlighted
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
return /*#__PURE__*/React.createElement(ReverseHighlightUiComponent, _extends({}, props, {
|
|
34
|
+
parts: parts,
|
|
35
|
+
highlightedTagName: highlightedTagName,
|
|
36
|
+
nonHighlightedTagName: nonHighlightedTagName,
|
|
37
|
+
separator: separator
|
|
38
|
+
}));
|
|
39
|
+
}
|
|
@@ -16,6 +16,7 @@ export * from './PoweredBy';
|
|
|
16
16
|
export * from './RangeInput';
|
|
17
17
|
export * from './RefinementList';
|
|
18
18
|
export * from './RelatedProducts';
|
|
19
|
+
export * from './ReverseHighlight';
|
|
19
20
|
export * from './SearchBox';
|
|
20
21
|
export * from './Snippet';
|
|
21
22
|
export * from './SortBy';
|
package/dist/es/widgets/index.js
CHANGED
|
@@ -16,6 +16,7 @@ export * from "./PoweredBy.js";
|
|
|
16
16
|
export * from "./RangeInput.js";
|
|
17
17
|
export * from "./RefinementList.js";
|
|
18
18
|
export * from "./RelatedProducts.js";
|
|
19
|
+
export * from "./ReverseHighlight.js";
|
|
19
20
|
export * from "./SearchBox.js";
|
|
20
21
|
export * from "./Snippet.js";
|
|
21
22
|
export * from "./SortBy.js";
|
|
@@ -19,6 +19,7 @@ export * from './PoweredBy';
|
|
|
19
19
|
export * from './RangeInput';
|
|
20
20
|
export * from './RefinementList';
|
|
21
21
|
export * from './RelatedProducts';
|
|
22
|
+
export * from './ReverseHighlight';
|
|
22
23
|
export * from './SearchBox';
|
|
23
24
|
export * from './Snippet';
|
|
24
25
|
export * from './SortBy';
|
|
@@ -21,6 +21,7 @@ export * from "./PoweredBy.js";
|
|
|
21
21
|
export * from "./RangeInput.js";
|
|
22
22
|
export * from "./RefinementList.js";
|
|
23
23
|
export * from "./RelatedProducts.js";
|
|
24
|
+
export * from "./ReverseHighlight.js";
|
|
24
25
|
export * from "./SearchBox.js";
|
|
25
26
|
export * from "./Snippet.js";
|
|
26
27
|
export * from "./SortBy.js";
|