instantsearch-ui-components 0.13.0 → 0.15.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/autocomplete/AutocompleteRecentSearch.js +42 -0
- package/dist/cjs/components/autocomplete/AutocompleteSearch.js +5 -0
- package/dist/cjs/components/autocomplete/AutocompleteSuggestion.js +12 -3
- package/dist/cjs/components/autocomplete/createAutocompletePropGetters.js +38 -15
- package/dist/cjs/components/autocomplete/createAutocompleteStorage.js +174 -0
- package/dist/cjs/components/autocomplete/icons.js +20 -0
- package/dist/cjs/components/autocomplete/index.js +22 -0
- package/dist/cjs/components/chat/Chat.js +2 -1
- package/dist/cjs/components/chat/ChatMessage.js +3 -0
- package/dist/cjs/components/chat/ChatMessages.js +14 -5
- package/dist/cjs/version.js +1 -1
- package/dist/es/components/autocomplete/AutocompleteRecentSearch.d.ts +38 -0
- package/dist/es/components/autocomplete/AutocompleteRecentSearch.js +36 -0
- package/dist/es/components/autocomplete/AutocompleteSearch.js +5 -0
- package/dist/es/components/autocomplete/AutocompleteSuggestion.d.ts +11 -2
- package/dist/es/components/autocomplete/AutocompleteSuggestion.js +12 -3
- package/dist/es/components/autocomplete/createAutocompletePropGetters.d.ts +1 -1
- package/dist/es/components/autocomplete/createAutocompletePropGetters.js +38 -15
- package/dist/es/components/autocomplete/createAutocompleteStorage.d.ts +74 -0
- package/dist/es/components/autocomplete/createAutocompleteStorage.js +166 -0
- package/dist/es/components/autocomplete/icons.d.ts +2 -0
- package/dist/es/components/autocomplete/icons.js +18 -0
- package/dist/es/components/autocomplete/index.d.ts +2 -0
- package/dist/es/components/autocomplete/index.js +3 -1
- package/dist/es/components/chat/Chat.d.ts +1 -0
- package/dist/es/components/chat/Chat.js +2 -1
- package/dist/es/components/chat/ChatMessage.js +3 -0
- package/dist/es/components/chat/ChatMessages.d.ts +9 -1
- package/dist/es/components/chat/ChatMessages.js +14 -5
- package/dist/es/components/chat/types.d.ts +1 -1
- package/dist/es/version.d.ts +1 -1
- package/dist/es/version.js +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createAutocompleteRecentSearchComponent = createAutocompleteRecentSearchComponent;
|
|
7
|
+
var _lib = require("../../lib");
|
|
8
|
+
var _icons = require("./icons");
|
|
9
|
+
function createAutocompleteRecentSearchComponent(_ref) {
|
|
10
|
+
var createElement = _ref.createElement;
|
|
11
|
+
return function AutocompleteRecentSearch(_ref2) {
|
|
12
|
+
var item = _ref2.item,
|
|
13
|
+
children = _ref2.children,
|
|
14
|
+
onSelect = _ref2.onSelect,
|
|
15
|
+
onRemoveRecentSearch = _ref2.onRemoveRecentSearch,
|
|
16
|
+
_ref2$classNames = _ref2.classNames,
|
|
17
|
+
classNames = _ref2$classNames === void 0 ? {} : _ref2$classNames;
|
|
18
|
+
return createElement("div", {
|
|
19
|
+
onClick: onSelect,
|
|
20
|
+
className: (0, _lib.cx)('ais-AutocompleteItemWrapper ais-AutocompleteRecentSearchWrapper', classNames.root)
|
|
21
|
+
}, createElement("div", {
|
|
22
|
+
className: (0, _lib.cx)('ais-AutocompleteItemContent', 'ais-AutocompleteRecentSearchItemContent', classNames.content)
|
|
23
|
+
}, createElement("div", {
|
|
24
|
+
className: (0, _lib.cx)('ais-AutocompleteItemIcon', 'ais-AutocompleteRecentSearchItemIcon', classNames.content)
|
|
25
|
+
}, createElement(_icons.AutocompleteClockIcon, {
|
|
26
|
+
createElement: createElement
|
|
27
|
+
})), createElement("div", {
|
|
28
|
+
className: (0, _lib.cx)('ais-AutocompleteItemContentBody', 'ais-AutocompleteRecentSearchItemContentBody', classNames.content)
|
|
29
|
+
}, children)), createElement("div", {
|
|
30
|
+
className: (0, _lib.cx)('ais-AutocompleteItemActions', 'ais-AutocompleteRecentSearchItemActions', classNames.actions)
|
|
31
|
+
}, createElement("button", {
|
|
32
|
+
className: (0, _lib.cx)('ais-AutocompleteItemActionButton', 'ais-AutocompleteRecentSearchItemDeleteButton', classNames.deleteButton),
|
|
33
|
+
title: "Remove ".concat(item.query, " from recent searches"),
|
|
34
|
+
onClick: function onClick(evt) {
|
|
35
|
+
evt.stopPropagation();
|
|
36
|
+
onRemoveRecentSearch();
|
|
37
|
+
}
|
|
38
|
+
}, createElement(_icons.AutocompleteTrashIcon, {
|
|
39
|
+
createElement: createElement
|
|
40
|
+
}))));
|
|
41
|
+
};
|
|
42
|
+
}
|
|
@@ -14,6 +14,7 @@ function createAutocompleteSearchComponent(_ref) {
|
|
|
14
14
|
onClear = _ref2.onClear,
|
|
15
15
|
query = _ref2.query,
|
|
16
16
|
isSearchStalled = _ref2.isSearchStalled;
|
|
17
|
+
var inputRef = inputProps.ref;
|
|
17
18
|
return createElement("form", {
|
|
18
19
|
className: "ais-AutocompleteForm",
|
|
19
20
|
action: "",
|
|
@@ -21,6 +22,10 @@ function createAutocompleteSearchComponent(_ref) {
|
|
|
21
22
|
role: "search",
|
|
22
23
|
onSubmit: function onSubmit(e) {
|
|
23
24
|
return e.preventDefault();
|
|
25
|
+
},
|
|
26
|
+
onReset: function onReset() {
|
|
27
|
+
var _inputRef$current;
|
|
28
|
+
return (_inputRef$current = inputRef.current) === null || _inputRef$current === void 0 ? void 0 : _inputRef$current.focus();
|
|
24
29
|
}
|
|
25
30
|
}, createElement("div", {
|
|
26
31
|
className: "ais-AutocompleteInputWrapperPrefix"
|
|
@@ -5,16 +5,25 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.createAutocompleteSuggestionComponent = createAutocompleteSuggestionComponent;
|
|
7
7
|
var _lib = require("../../lib");
|
|
8
|
+
var _icons = require("./icons");
|
|
8
9
|
function createAutocompleteSuggestionComponent(_ref) {
|
|
9
10
|
var createElement = _ref.createElement;
|
|
10
11
|
return function AutocompleteSuggestion(_ref2) {
|
|
11
|
-
var
|
|
12
|
+
var children = _ref2.children,
|
|
12
13
|
onSelect = _ref2.onSelect,
|
|
13
14
|
_ref2$classNames = _ref2.classNames,
|
|
14
15
|
classNames = _ref2$classNames === void 0 ? {} : _ref2$classNames;
|
|
15
16
|
return createElement("div", {
|
|
16
17
|
onClick: onSelect,
|
|
17
|
-
className: (0, _lib.cx)('ais-
|
|
18
|
-
},
|
|
18
|
+
className: (0, _lib.cx)('ais-AutocompleteItemWrapper', 'ais-AutocompleteSuggestionWrapper', classNames.root)
|
|
19
|
+
}, createElement("div", {
|
|
20
|
+
className: (0, _lib.cx)('ais-AutocompleteItemContent', 'ais-AutocompleteSuggestionItemContent', classNames.content)
|
|
21
|
+
}, createElement("div", {
|
|
22
|
+
className: (0, _lib.cx)('ais-AutocompleteItemIcon', 'ais-AutocompleteSuggestionItemIcon', classNames.content)
|
|
23
|
+
}, createElement(_icons.AutocompleteSubmitIcon, {
|
|
24
|
+
createElement: createElement
|
|
25
|
+
})), createElement("div", {
|
|
26
|
+
className: (0, _lib.cx)('ais-AutocompleteItemContentBody', 'ais-AutocompleteSuggestionItemContentBody', classNames.content)
|
|
27
|
+
}, children)));
|
|
19
28
|
};
|
|
20
29
|
}
|
|
@@ -19,6 +19,7 @@ function createAutocompletePropGetters(_ref) {
|
|
|
19
19
|
onRefine = _ref2.onRefine,
|
|
20
20
|
globalOnSelect = _ref2.onSelect;
|
|
21
21
|
var getElementId = createGetElementId(useId());
|
|
22
|
+
var inputRef = useRef(null);
|
|
22
23
|
var rootRef = useRef(null);
|
|
23
24
|
var _useState = useState(false),
|
|
24
25
|
_useState2 = (0, _slicedToArray2.default)(_useState, 2),
|
|
@@ -50,7 +51,7 @@ function createAutocompletePropGetters(_ref) {
|
|
|
50
51
|
document.body.removeEventListener('click', onBodyClick);
|
|
51
52
|
};
|
|
52
53
|
}, [rootRef]);
|
|
53
|
-
var
|
|
54
|
+
var getNextActiveDescendant = function getNextActiveDescendant(key) {
|
|
54
55
|
switch (key) {
|
|
55
56
|
case 'ArrowLeft':
|
|
56
57
|
case 'ArrowUp':
|
|
@@ -69,11 +70,21 @@ function createAutocompletePropGetters(_ref) {
|
|
|
69
70
|
}
|
|
70
71
|
};
|
|
71
72
|
var submit = function submit() {
|
|
72
|
-
var
|
|
73
|
-
|
|
74
|
-
if (
|
|
73
|
+
var _override$activeDesce;
|
|
74
|
+
var override = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
75
|
+
if (isOpen) {
|
|
76
|
+
setIsOpen(false);
|
|
77
|
+
} else {
|
|
78
|
+
var _inputRef$current;
|
|
79
|
+
(_inputRef$current = inputRef.current) === null || _inputRef$current === void 0 ? void 0 : _inputRef$current.blur();
|
|
80
|
+
}
|
|
81
|
+
var actualDescendant = (_override$activeDesce = override.activeDescendant) !== null && _override$activeDesce !== void 0 ? _override$activeDesce : activeDescendant;
|
|
82
|
+
if (!actualDescendant && override.query) {
|
|
83
|
+
onRefine(override.query);
|
|
84
|
+
}
|
|
85
|
+
if (actualDescendant && items.has(actualDescendant)) {
|
|
75
86
|
var _getQuery;
|
|
76
|
-
var _ref3 = items.get(
|
|
87
|
+
var _ref3 = items.get(actualDescendant),
|
|
77
88
|
_item = _ref3.item,
|
|
78
89
|
_ref3$config = _ref3.config,
|
|
79
90
|
indexOnSelect = _ref3$config.onSelect,
|
|
@@ -95,6 +106,7 @@ function createAutocompletePropGetters(_ref) {
|
|
|
95
106
|
getInputProps: function getInputProps() {
|
|
96
107
|
return {
|
|
97
108
|
id: getElementId('input'),
|
|
109
|
+
ref: inputRef,
|
|
98
110
|
role: 'combobox',
|
|
99
111
|
'aria-autocomplete': 'list',
|
|
100
112
|
'aria-expanded': isOpen,
|
|
@@ -105,33 +117,42 @@ function createAutocompletePropGetters(_ref) {
|
|
|
105
117
|
return setIsOpen(true);
|
|
106
118
|
},
|
|
107
119
|
onKeyDown: function onKeyDown(event) {
|
|
108
|
-
if (event.key === 'Escape') {
|
|
109
|
-
setActiveDescendant(undefined);
|
|
110
|
-
setIsOpen(false);
|
|
111
|
-
return;
|
|
112
|
-
}
|
|
113
120
|
switch (event.key) {
|
|
121
|
+
case 'Escape':
|
|
122
|
+
{
|
|
123
|
+
if (isOpen) {
|
|
124
|
+
setIsOpen(false);
|
|
125
|
+
event.preventDefault();
|
|
126
|
+
} else {
|
|
127
|
+
setActiveDescendant(undefined);
|
|
128
|
+
}
|
|
129
|
+
break;
|
|
130
|
+
}
|
|
114
131
|
case 'ArrowLeft':
|
|
115
132
|
case 'ArrowUp':
|
|
116
133
|
case 'ArrowRight':
|
|
117
134
|
case 'ArrowDown':
|
|
118
135
|
{
|
|
119
136
|
var _document$getElementB;
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
(
|
|
137
|
+
setIsOpen(true);
|
|
138
|
+
var nextActiveDescendant = getNextActiveDescendant(event.key);
|
|
139
|
+
setActiveDescendant(nextActiveDescendant);
|
|
140
|
+
(_document$getElementB = document.getElementById(nextActiveDescendant)) === null || _document$getElementB === void 0 ? void 0 : _document$getElementB.scrollIntoView(false);
|
|
123
141
|
event.preventDefault();
|
|
124
142
|
break;
|
|
125
143
|
}
|
|
126
144
|
case 'Enter':
|
|
127
145
|
{
|
|
128
|
-
submit(
|
|
146
|
+
submit({
|
|
147
|
+
query: event.target.value
|
|
148
|
+
});
|
|
129
149
|
break;
|
|
130
150
|
}
|
|
131
151
|
case 'Tab':
|
|
132
152
|
setIsOpen(false);
|
|
133
153
|
break;
|
|
134
154
|
default:
|
|
155
|
+
setIsOpen(true);
|
|
135
156
|
return;
|
|
136
157
|
}
|
|
137
158
|
},
|
|
@@ -159,7 +180,9 @@ function createAutocompletePropGetters(_ref) {
|
|
|
159
180
|
role: 'row',
|
|
160
181
|
'aria-selected': id === activeDescendant,
|
|
161
182
|
onSelect: function onSelect() {
|
|
162
|
-
return submit(
|
|
183
|
+
return submit({
|
|
184
|
+
activeDescendant: id
|
|
185
|
+
});
|
|
163
186
|
}
|
|
164
187
|
};
|
|
165
188
|
},
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.createAutocompleteStorage = createAutocompleteStorage;
|
|
8
|
+
exports.createStorage = createStorage;
|
|
9
|
+
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
10
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
11
|
+
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
|
12
|
+
function createAutocompleteStorage(_ref) {
|
|
13
|
+
var useEffect = _ref.useEffect,
|
|
14
|
+
useMemo = _ref.useMemo,
|
|
15
|
+
useState = _ref.useState;
|
|
16
|
+
return function useStorage(_ref2) {
|
|
17
|
+
var showRecent = _ref2.showRecent,
|
|
18
|
+
query = _ref2.query,
|
|
19
|
+
indices = _ref2.indices,
|
|
20
|
+
indicesConfig = _ref2.indicesConfig;
|
|
21
|
+
var storageKey = showRecent && (0, _typeof2.default)(showRecent) === 'object' ? showRecent.storageKey : undefined;
|
|
22
|
+
var storage = useMemo(function () {
|
|
23
|
+
return createStorage({
|
|
24
|
+
limit: 5,
|
|
25
|
+
storageKey: storageKey
|
|
26
|
+
});
|
|
27
|
+
}, [storageKey]);
|
|
28
|
+
var _useState = useState(storage.getSnapshot()),
|
|
29
|
+
_useState2 = (0, _slicedToArray2.default)(_useState, 2),
|
|
30
|
+
snapshot = _useState2[0],
|
|
31
|
+
setSnapshot = _useState2[1];
|
|
32
|
+
useEffect(function () {
|
|
33
|
+
storage.registerUpdateListener(function () {
|
|
34
|
+
setSnapshot(storage.getSnapshot());
|
|
35
|
+
});
|
|
36
|
+
return function () {
|
|
37
|
+
storage.unregisterUpdateListener();
|
|
38
|
+
};
|
|
39
|
+
}, [storage]);
|
|
40
|
+
if (!showRecent) {
|
|
41
|
+
return {
|
|
42
|
+
storage: {
|
|
43
|
+
onAdd: function onAdd() {},
|
|
44
|
+
onRemove: function onRemove() {}
|
|
45
|
+
},
|
|
46
|
+
storageHits: [],
|
|
47
|
+
indicesForPropGetters: indices,
|
|
48
|
+
indicesConfigForPropGetters: indicesConfig
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
var storageHits = snapshot.getAll(query).map(function (value) {
|
|
52
|
+
return {
|
|
53
|
+
objectID: value,
|
|
54
|
+
query: value,
|
|
55
|
+
__indexName: 'recent-searches',
|
|
56
|
+
_highlightResult: getHighlightedAttribute({
|
|
57
|
+
item: {
|
|
58
|
+
query: value
|
|
59
|
+
},
|
|
60
|
+
query: query || ''
|
|
61
|
+
})
|
|
62
|
+
};
|
|
63
|
+
});
|
|
64
|
+
var indicesForPropGetters = (0, _toConsumableArray2.default)(indices);
|
|
65
|
+
var indicesConfigForPropGetters = (0, _toConsumableArray2.default)(indicesConfig);
|
|
66
|
+
indicesForPropGetters.unshift({
|
|
67
|
+
indexName: 'recent-searches',
|
|
68
|
+
indexId: 'recent-searches',
|
|
69
|
+
hits: storageHits
|
|
70
|
+
});
|
|
71
|
+
indicesConfigForPropGetters.unshift({
|
|
72
|
+
indexName: 'recent-searches',
|
|
73
|
+
// @ts-expect-error - we know it has query as it's generated from storageHits
|
|
74
|
+
getQuery: function getQuery(item) {
|
|
75
|
+
return item.query;
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
return {
|
|
79
|
+
storage: storage,
|
|
80
|
+
storageHits: storageHits,
|
|
81
|
+
indicesForPropGetters: indicesForPropGetters,
|
|
82
|
+
indicesConfigForPropGetters: indicesConfigForPropGetters
|
|
83
|
+
};
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
var LOCAL_STORAGE_KEY_TEST = 'test-localstorage-support';
|
|
87
|
+
var LOCAL_STORAGE_KEY = 'autocomplete-recent-searches';
|
|
88
|
+
function isLocalStorageSupported() {
|
|
89
|
+
try {
|
|
90
|
+
localStorage.setItem(LOCAL_STORAGE_KEY_TEST, '');
|
|
91
|
+
localStorage.removeItem(LOCAL_STORAGE_KEY_TEST);
|
|
92
|
+
return true;
|
|
93
|
+
} catch (error) {
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
function getHighlightedAttribute(_ref3) {
|
|
98
|
+
var item = _ref3.item,
|
|
99
|
+
query = _ref3.query;
|
|
100
|
+
if (!query.trim().length) {
|
|
101
|
+
return {
|
|
102
|
+
query: {
|
|
103
|
+
matchLevel: 'none'
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
return {
|
|
108
|
+
query: {
|
|
109
|
+
value: item.query.replace(new RegExp(query.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&'), 'gi'), function (match) {
|
|
110
|
+
return "<mark>".concat(match, "</mark>");
|
|
111
|
+
})
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
function getLocalStorage() {
|
|
116
|
+
var key = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : LOCAL_STORAGE_KEY;
|
|
117
|
+
if (!isLocalStorageSupported()) {
|
|
118
|
+
return {
|
|
119
|
+
setItems: function setItems() {},
|
|
120
|
+
getItems: function getItems() {
|
|
121
|
+
return [];
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
return {
|
|
126
|
+
setItems: function setItems(items) {
|
|
127
|
+
try {
|
|
128
|
+
window.localStorage.setItem(key, JSON.stringify(items));
|
|
129
|
+
} catch (_unused) {
|
|
130
|
+
// do nothing, this likely means the storage is full
|
|
131
|
+
}
|
|
132
|
+
},
|
|
133
|
+
getItems: function getItems() {
|
|
134
|
+
var items = window.localStorage.getItem(key);
|
|
135
|
+
return items ? JSON.parse(items) : [];
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
function createStorage(_ref4) {
|
|
140
|
+
var _ref4$limit = _ref4.limit,
|
|
141
|
+
limit = _ref4$limit === void 0 ? 5 : _ref4$limit,
|
|
142
|
+
storageKey = _ref4.storageKey;
|
|
143
|
+
var storage = getLocalStorage(storageKey);
|
|
144
|
+
var updateListener = null;
|
|
145
|
+
return {
|
|
146
|
+
onAdd: function onAdd(query) {
|
|
147
|
+
this.onRemove(query);
|
|
148
|
+
storage.setItems([query].concat((0, _toConsumableArray2.default)(storage.getItems())));
|
|
149
|
+
},
|
|
150
|
+
onRemove: function onRemove(query) {
|
|
151
|
+
var _updateListener;
|
|
152
|
+
storage.setItems(storage.getItems().filter(function (q) {
|
|
153
|
+
return q !== query;
|
|
154
|
+
}));
|
|
155
|
+
(_updateListener = updateListener) === null || _updateListener === void 0 ? void 0 : _updateListener();
|
|
156
|
+
},
|
|
157
|
+
registerUpdateListener: function registerUpdateListener(callback) {
|
|
158
|
+
updateListener = callback;
|
|
159
|
+
},
|
|
160
|
+
unregisterUpdateListener: function unregisterUpdateListener() {
|
|
161
|
+
updateListener = null;
|
|
162
|
+
},
|
|
163
|
+
getSnapshot: function getSnapshot() {
|
|
164
|
+
return {
|
|
165
|
+
getAll: function getAll() {
|
|
166
|
+
var query = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
|
|
167
|
+
return storage.getItems().filter(function (q) {
|
|
168
|
+
return q.includes(query);
|
|
169
|
+
}).slice(0, limit);
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
}
|
|
@@ -4,8 +4,10 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.AutocompleteClearIcon = AutocompleteClearIcon;
|
|
7
|
+
exports.AutocompleteClockIcon = AutocompleteClockIcon;
|
|
7
8
|
exports.AutocompleteLoadingIcon = AutocompleteLoadingIcon;
|
|
8
9
|
exports.AutocompleteSubmitIcon = AutocompleteSubmitIcon;
|
|
10
|
+
exports.AutocompleteTrashIcon = AutocompleteTrashIcon;
|
|
9
11
|
function AutocompleteSubmitIcon(_ref) {
|
|
10
12
|
var createElement = _ref.createElement;
|
|
11
13
|
return createElement("svg", {
|
|
@@ -53,4 +55,22 @@ function AutocompleteClearIcon(_ref3) {
|
|
|
53
55
|
}, createElement("path", {
|
|
54
56
|
d: "M5.293 6.707l5.293 5.293-5.293 5.293c-0.391 0.391-0.391 1.024 0 1.414s1.024 0.391 1.414 0l5.293-5.293 5.293 5.293c0.391 0.391 1.024 0.391 1.414 0s0.391-1.024 0-1.414l-5.293-5.293 5.293-5.293c0.391-0.391 0.391-1.024 0-1.414s-1.024-0.391-1.414 0l-5.293 5.293-5.293-5.293c-0.391-0.391-1.024-0.391-1.414 0s-0.391 1.024 0 1.414z"
|
|
55
57
|
}));
|
|
58
|
+
}
|
|
59
|
+
function AutocompleteClockIcon(_ref4) {
|
|
60
|
+
var createElement = _ref4.createElement;
|
|
61
|
+
return createElement("svg", {
|
|
62
|
+
viewBox: "0 0 24 24",
|
|
63
|
+
fill: "currentColor"
|
|
64
|
+
}, createElement("path", {
|
|
65
|
+
d: "M12.516 6.984v5.25l4.5 2.672-0.75 1.266-5.25-3.188v-6h1.5zM12 20.016q3.281 0 5.648-2.367t2.367-5.648-2.367-5.648-5.648-2.367-5.648 2.367-2.367 5.648 2.367 5.648 5.648 2.367zM12 2.016q4.125 0 7.055 2.93t2.93 7.055-2.93 7.055-7.055 2.93-7.055-2.93-2.93-7.055 2.93-7.055 7.055-2.93z"
|
|
66
|
+
}));
|
|
67
|
+
}
|
|
68
|
+
function AutocompleteTrashIcon(_ref5) {
|
|
69
|
+
var createElement = _ref5.createElement;
|
|
70
|
+
return createElement("svg", {
|
|
71
|
+
viewBox: "0 0 24 24",
|
|
72
|
+
fill: "currentColor"
|
|
73
|
+
}, createElement("path", {
|
|
74
|
+
d: "M18 7v13c0 0.276-0.111 0.525-0.293 0.707s-0.431 0.293-0.707 0.293h-10c-0.276 0-0.525-0.111-0.707-0.293s-0.293-0.431-0.293-0.707v-13zM17 5v-1c0-0.828-0.337-1.58-0.879-2.121s-1.293-0.879-2.121-0.879h-4c-0.828 0-1.58 0.337-2.121 0.879s-0.879 1.293-0.879 2.121v1h-4c-0.552 0-1 0.448-1 1s0.448 1 1 1h1v13c0 0.828 0.337 1.58 0.879 2.121s1.293 0.879 2.121 0.879h10c0.828 0 1.58-0.337 2.121-0.879s0.879-1.293 0.879-2.121v-13h1c0.552 0 1-0.448 1-1s-0.448-1-1-1zM9 5v-1c0-0.276 0.111-0.525 0.293-0.707s0.431-0.293 0.707-0.293h4c0.276 0 0.525 0.111 0.707 0.293s0.293 0.431 0.293 0.707v1zM9 11v6c0 0.552 0.448 1 1 1s1-0.448 1-1v-6c0-0.552-0.448-1-1-1s-1 0.448-1 1zM13 11v6c0 0.552 0.448 1 1 1s1-0.448 1-1v-6c0-0.552-0.448-1-1-1s-1 0.448-1 1z"
|
|
75
|
+
}));
|
|
56
76
|
}
|
|
@@ -36,6 +36,17 @@ Object.keys(_AutocompletePanel).forEach(function (key) {
|
|
|
36
36
|
}
|
|
37
37
|
});
|
|
38
38
|
});
|
|
39
|
+
var _AutocompleteRecentSearch = require("./AutocompleteRecentSearch");
|
|
40
|
+
Object.keys(_AutocompleteRecentSearch).forEach(function (key) {
|
|
41
|
+
if (key === "default" || key === "__esModule") return;
|
|
42
|
+
if (key in exports && exports[key] === _AutocompleteRecentSearch[key]) return;
|
|
43
|
+
Object.defineProperty(exports, key, {
|
|
44
|
+
enumerable: true,
|
|
45
|
+
get: function get() {
|
|
46
|
+
return _AutocompleteRecentSearch[key];
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
});
|
|
39
50
|
var _AutocompleteSearch = require("./AutocompleteSearch");
|
|
40
51
|
Object.keys(_AutocompleteSearch).forEach(function (key) {
|
|
41
52
|
if (key === "default" || key === "__esModule") return;
|
|
@@ -68,4 +79,15 @@ Object.keys(_createAutocompletePropGetters).forEach(function (key) {
|
|
|
68
79
|
return _createAutocompletePropGetters[key];
|
|
69
80
|
}
|
|
70
81
|
});
|
|
82
|
+
});
|
|
83
|
+
var _createAutocompleteStorage = require("./createAutocompleteStorage");
|
|
84
|
+
Object.keys(_createAutocompleteStorage).forEach(function (key) {
|
|
85
|
+
if (key === "default" || key === "__esModule") return;
|
|
86
|
+
if (key in exports && exports[key] === _createAutocompleteStorage[key]) return;
|
|
87
|
+
Object.defineProperty(exports, key, {
|
|
88
|
+
enumerable: true,
|
|
89
|
+
get: function get() {
|
|
90
|
+
return _createAutocompleteStorage[key];
|
|
91
|
+
}
|
|
92
|
+
});
|
|
71
93
|
});
|
|
@@ -59,7 +59,8 @@ function createChatComponent(_ref) {
|
|
|
59
59
|
classNames: classNames.header,
|
|
60
60
|
maximized: maximized
|
|
61
61
|
})), createElement(ChatMessages, (0, _extends2.default)({}, messagesProps, {
|
|
62
|
-
classNames: classNames.messages
|
|
62
|
+
classNames: classNames.messages,
|
|
63
|
+
messageClassNames: classNames.message
|
|
63
64
|
})), createElement(PromptComponent || ChatPrompt, _objectSpread(_objectSpread({}, promptProps), {}, {
|
|
64
65
|
classNames: classNames.prompt
|
|
65
66
|
}))), createElement("div", {
|
|
@@ -84,6 +84,9 @@ function createChatMessageComponent(_ref) {
|
|
|
84
84
|
toolCallId: toolMessage.toolCallId
|
|
85
85
|
});
|
|
86
86
|
};
|
|
87
|
+
if (!ToolLayoutComponent) {
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
87
90
|
return createElement("div", {
|
|
88
91
|
key: "".concat(message.id, "-").concat(index),
|
|
89
92
|
className: "ais-ChatMessage-tool"
|
|
@@ -15,7 +15,7 @@ var _ChatMessage = require("./ChatMessage");
|
|
|
15
15
|
var _ChatMessageError = require("./ChatMessageError");
|
|
16
16
|
var _ChatMessageLoader = require("./ChatMessageLoader");
|
|
17
17
|
var _icons = require("./icons");
|
|
18
|
-
var _excluded = ["classNames", "messages", "messageComponent", "loaderComponent", "errorComponent", "actionsComponent", "tools", "indexUiState", "setIndexUiState", "status", "hideScrollToBottom", "onReload", "onClose", "translations", "userMessageProps", "assistantMessageProps", "isClearing", "onClearTransitionEnd", "isScrollAtBottom", "scrollRef", "contentRef", "onScrollToBottom"];
|
|
18
|
+
var _excluded = ["classNames", "messageClassNames", "messageTranslations", "messages", "messageComponent", "loaderComponent", "errorComponent", "actionsComponent", "tools", "indexUiState", "setIndexUiState", "status", "hideScrollToBottom", "onReload", "onClose", "translations", "userMessageProps", "assistantMessageProps", "isClearing", "onClearTransitionEnd", "isScrollAtBottom", "scrollRef", "contentRef", "onScrollToBottom"];
|
|
19
19
|
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; }
|
|
20
20
|
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) { (0, _defineProperty2.default)(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; }
|
|
21
21
|
var getTextContent = function getTextContent(message) {
|
|
@@ -45,8 +45,10 @@ function createDefaultMessageComponent(_ref) {
|
|
|
45
45
|
setIndexUiState = _ref2.setIndexUiState,
|
|
46
46
|
onReload = _ref2.onReload,
|
|
47
47
|
onClose = _ref2.onClose,
|
|
48
|
-
|
|
49
|
-
|
|
48
|
+
actionsComponent = _ref2.actionsComponent,
|
|
49
|
+
classNames = _ref2.classNames,
|
|
50
|
+
messageTranslations = _ref2.messageTranslations,
|
|
51
|
+
translations = _ref2.translations;
|
|
50
52
|
var defaultAssistantActions = [].concat((0, _toConsumableArray2.default)(hasTextContent(message) ? [{
|
|
51
53
|
title: translations.copyToClipboardLabel,
|
|
52
54
|
icon: function icon() {
|
|
@@ -78,7 +80,9 @@ function createDefaultMessageComponent(_ref) {
|
|
|
78
80
|
onClose: onClose,
|
|
79
81
|
actions: defaultActions,
|
|
80
82
|
actionsComponent: actionsComponent,
|
|
81
|
-
"data-role": message.role
|
|
83
|
+
"data-role": message.role,
|
|
84
|
+
classNames: classNames,
|
|
85
|
+
translations: messageTranslations
|
|
82
86
|
}, messageProps));
|
|
83
87
|
};
|
|
84
88
|
}
|
|
@@ -101,6 +105,9 @@ function createChatMessagesComponent(_ref3) {
|
|
|
101
105
|
return function ChatMessages(userProps) {
|
|
102
106
|
var _userProps$classNames = userProps.classNames,
|
|
103
107
|
classNames = _userProps$classNames === void 0 ? {} : _userProps$classNames,
|
|
108
|
+
_userProps$messageCla = userProps.messageClassNames,
|
|
109
|
+
messageClassNames = _userProps$messageCla === void 0 ? {} : _userProps$messageCla,
|
|
110
|
+
messageTranslations = userProps.messageTranslations,
|
|
104
111
|
_userProps$messages = userProps.messages,
|
|
105
112
|
messages = _userProps$messages === void 0 ? [] : _userProps$messages,
|
|
106
113
|
MessageComponent = userProps.messageComponent,
|
|
@@ -169,7 +176,9 @@ function createChatMessagesComponent(_ref3) {
|
|
|
169
176
|
onReload: onReload,
|
|
170
177
|
actionsComponent: ActionsComponent,
|
|
171
178
|
onClose: onClose,
|
|
172
|
-
translations: translations
|
|
179
|
+
translations: translations,
|
|
180
|
+
classNames: messageClassNames,
|
|
181
|
+
messageTranslations: messageTranslations
|
|
173
182
|
});
|
|
174
183
|
}), status === 'submitted' && createElement(DefaultLoader, {
|
|
175
184
|
translations: {
|
package/dist/cjs/version.js
CHANGED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/** @jsx createElement */
|
|
2
|
+
import type { ComponentChildren, Renderer } from '../../types';
|
|
3
|
+
export type AutocompleteRecentSearchProps<T = {
|
|
4
|
+
query: string;
|
|
5
|
+
} & Record<string, unknown>> = {
|
|
6
|
+
item: T;
|
|
7
|
+
children?: ComponentChildren;
|
|
8
|
+
onSelect: () => void;
|
|
9
|
+
onRemoveRecentSearch: () => void;
|
|
10
|
+
classNames?: Partial<AutocompleteRecentSearchClassNames>;
|
|
11
|
+
};
|
|
12
|
+
export type AutocompleteRecentSearchClassNames = {
|
|
13
|
+
/**
|
|
14
|
+
* Class names to apply to the root element
|
|
15
|
+
**/
|
|
16
|
+
root: string | string[];
|
|
17
|
+
/**
|
|
18
|
+
* Class names to apply to the content element
|
|
19
|
+
**/
|
|
20
|
+
content: string | string[];
|
|
21
|
+
/**
|
|
22
|
+
* Class names to apply to the actions element
|
|
23
|
+
**/
|
|
24
|
+
actions: string | string[];
|
|
25
|
+
/**
|
|
26
|
+
* Class names to apply to the icon element
|
|
27
|
+
**/
|
|
28
|
+
icon: string | string[];
|
|
29
|
+
/**
|
|
30
|
+
* Class names to apply to the body element
|
|
31
|
+
**/
|
|
32
|
+
body: string | string[];
|
|
33
|
+
/**
|
|
34
|
+
* Class names to apply to the delete button element
|
|
35
|
+
**/
|
|
36
|
+
deleteButton: string | string[];
|
|
37
|
+
};
|
|
38
|
+
export declare function createAutocompleteRecentSearchComponent({ createElement, }: Renderer): ({ item, children, onSelect, onRemoveRecentSearch, classNames, }: AutocompleteRecentSearchProps) => JSX.Element;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { cx } from "../../lib/index.js";
|
|
2
|
+
import { AutocompleteClockIcon, AutocompleteTrashIcon } from "./icons.js";
|
|
3
|
+
export function createAutocompleteRecentSearchComponent(_ref) {
|
|
4
|
+
var createElement = _ref.createElement;
|
|
5
|
+
return function AutocompleteRecentSearch(_ref2) {
|
|
6
|
+
var item = _ref2.item,
|
|
7
|
+
children = _ref2.children,
|
|
8
|
+
onSelect = _ref2.onSelect,
|
|
9
|
+
onRemoveRecentSearch = _ref2.onRemoveRecentSearch,
|
|
10
|
+
_ref2$classNames = _ref2.classNames,
|
|
11
|
+
classNames = _ref2$classNames === void 0 ? {} : _ref2$classNames;
|
|
12
|
+
return createElement("div", {
|
|
13
|
+
onClick: onSelect,
|
|
14
|
+
className: cx('ais-AutocompleteItemWrapper ais-AutocompleteRecentSearchWrapper', classNames.root)
|
|
15
|
+
}, createElement("div", {
|
|
16
|
+
className: cx('ais-AutocompleteItemContent', 'ais-AutocompleteRecentSearchItemContent', classNames.content)
|
|
17
|
+
}, createElement("div", {
|
|
18
|
+
className: cx('ais-AutocompleteItemIcon', 'ais-AutocompleteRecentSearchItemIcon', classNames.content)
|
|
19
|
+
}, createElement(AutocompleteClockIcon, {
|
|
20
|
+
createElement: createElement
|
|
21
|
+
})), createElement("div", {
|
|
22
|
+
className: cx('ais-AutocompleteItemContentBody', 'ais-AutocompleteRecentSearchItemContentBody', classNames.content)
|
|
23
|
+
}, children)), createElement("div", {
|
|
24
|
+
className: cx('ais-AutocompleteItemActions', 'ais-AutocompleteRecentSearchItemActions', classNames.actions)
|
|
25
|
+
}, createElement("button", {
|
|
26
|
+
className: cx('ais-AutocompleteItemActionButton', 'ais-AutocompleteRecentSearchItemDeleteButton', classNames.deleteButton),
|
|
27
|
+
title: "Remove ".concat(item.query, " from recent searches"),
|
|
28
|
+
onClick: function onClick(evt) {
|
|
29
|
+
evt.stopPropagation();
|
|
30
|
+
onRemoveRecentSearch();
|
|
31
|
+
}
|
|
32
|
+
}, createElement(AutocompleteTrashIcon, {
|
|
33
|
+
createElement: createElement
|
|
34
|
+
}))));
|
|
35
|
+
};
|
|
36
|
+
}
|
|
@@ -7,6 +7,7 @@ export function createAutocompleteSearchComponent(_ref) {
|
|
|
7
7
|
onClear = _ref2.onClear,
|
|
8
8
|
query = _ref2.query,
|
|
9
9
|
isSearchStalled = _ref2.isSearchStalled;
|
|
10
|
+
var inputRef = inputProps.ref;
|
|
10
11
|
return createElement("form", {
|
|
11
12
|
className: "ais-AutocompleteForm",
|
|
12
13
|
action: "",
|
|
@@ -14,6 +15,10 @@ export function createAutocompleteSearchComponent(_ref) {
|
|
|
14
15
|
role: "search",
|
|
15
16
|
onSubmit: function onSubmit(e) {
|
|
16
17
|
return e.preventDefault();
|
|
18
|
+
},
|
|
19
|
+
onReset: function onReset() {
|
|
20
|
+
var _inputRef$current;
|
|
21
|
+
return (_inputRef$current = inputRef.current) === null || _inputRef$current === void 0 ? void 0 : _inputRef$current.focus();
|
|
17
22
|
}
|
|
18
23
|
}, createElement("div", {
|
|
19
24
|
className: "ais-AutocompleteInputWrapperPrefix"
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
/** @jsx createElement */
|
|
2
|
-
import type { Renderer } from '../../types';
|
|
2
|
+
import type { ComponentChildren, Renderer } from '../../types';
|
|
3
3
|
export type AutocompleteSuggestionProps<T = {
|
|
4
4
|
query: string;
|
|
5
5
|
} & Record<string, unknown>> = {
|
|
6
6
|
item: T;
|
|
7
7
|
onSelect: () => void;
|
|
8
|
+
children: ComponentChildren;
|
|
8
9
|
classNames?: Partial<AutocompleteSuggestionClassNames>;
|
|
9
10
|
};
|
|
10
11
|
export type AutocompleteSuggestionClassNames = {
|
|
@@ -12,5 +13,13 @@ export type AutocompleteSuggestionClassNames = {
|
|
|
12
13
|
* Class names to apply to the root element
|
|
13
14
|
**/
|
|
14
15
|
root: string | string[];
|
|
16
|
+
/** Class names to apply to the content element **/
|
|
17
|
+
content: string | string[];
|
|
18
|
+
/** Class names to apply to the actions element **/
|
|
19
|
+
actions: string | string[];
|
|
20
|
+
/** Class names to apply to the icon element **/
|
|
21
|
+
icon: string | string[];
|
|
22
|
+
/** Class names to apply to the body element **/
|
|
23
|
+
body: string | string[];
|
|
15
24
|
};
|
|
16
|
-
export declare function createAutocompleteSuggestionComponent({ createElement, }: Renderer): ({
|
|
25
|
+
export declare function createAutocompleteSuggestionComponent({ createElement, }: Renderer): ({ children, onSelect, classNames, }: AutocompleteSuggestionProps) => JSX.Element;
|
|
@@ -1,14 +1,23 @@
|
|
|
1
1
|
import { cx } from "../../lib/index.js";
|
|
2
|
+
import { AutocompleteSubmitIcon } from "./icons.js";
|
|
2
3
|
export function createAutocompleteSuggestionComponent(_ref) {
|
|
3
4
|
var createElement = _ref.createElement;
|
|
4
5
|
return function AutocompleteSuggestion(_ref2) {
|
|
5
|
-
var
|
|
6
|
+
var children = _ref2.children,
|
|
6
7
|
onSelect = _ref2.onSelect,
|
|
7
8
|
_ref2$classNames = _ref2.classNames,
|
|
8
9
|
classNames = _ref2$classNames === void 0 ? {} : _ref2$classNames;
|
|
9
10
|
return createElement("div", {
|
|
10
11
|
onClick: onSelect,
|
|
11
|
-
className: cx('ais-
|
|
12
|
-
},
|
|
12
|
+
className: cx('ais-AutocompleteItemWrapper', 'ais-AutocompleteSuggestionWrapper', classNames.root)
|
|
13
|
+
}, createElement("div", {
|
|
14
|
+
className: cx('ais-AutocompleteItemContent', 'ais-AutocompleteSuggestionItemContent', classNames.content)
|
|
15
|
+
}, createElement("div", {
|
|
16
|
+
className: cx('ais-AutocompleteItemIcon', 'ais-AutocompleteSuggestionItemIcon', classNames.content)
|
|
17
|
+
}, createElement(AutocompleteSubmitIcon, {
|
|
18
|
+
createElement: createElement
|
|
19
|
+
})), createElement("div", {
|
|
20
|
+
className: cx('ais-AutocompleteItemContentBody', 'ais-AutocompleteSuggestionItemContentBody', classNames.content)
|
|
21
|
+
}, children)));
|
|
13
22
|
};
|
|
14
23
|
}
|
|
@@ -28,7 +28,7 @@ type CreateAutocompletePropGettersParams = {
|
|
|
28
28
|
};
|
|
29
29
|
useState: <TType>(initialState: TType) => [TType, (newState: TType) => unknown];
|
|
30
30
|
};
|
|
31
|
-
type UsePropGetters<TItem extends BaseHit> = (params: {
|
|
31
|
+
export type UsePropGetters<TItem extends BaseHit> = (params: {
|
|
32
32
|
indices: Array<{
|
|
33
33
|
indexName: string;
|
|
34
34
|
indexId: string;
|
|
@@ -12,6 +12,7 @@ export function createAutocompletePropGetters(_ref) {
|
|
|
12
12
|
onRefine = _ref2.onRefine,
|
|
13
13
|
globalOnSelect = _ref2.onSelect;
|
|
14
14
|
var getElementId = createGetElementId(useId());
|
|
15
|
+
var inputRef = useRef(null);
|
|
15
16
|
var rootRef = useRef(null);
|
|
16
17
|
var _useState = useState(false),
|
|
17
18
|
_useState2 = _slicedToArray(_useState, 2),
|
|
@@ -43,7 +44,7 @@ export function createAutocompletePropGetters(_ref) {
|
|
|
43
44
|
document.body.removeEventListener('click', onBodyClick);
|
|
44
45
|
};
|
|
45
46
|
}, [rootRef]);
|
|
46
|
-
var
|
|
47
|
+
var getNextActiveDescendant = function getNextActiveDescendant(key) {
|
|
47
48
|
switch (key) {
|
|
48
49
|
case 'ArrowLeft':
|
|
49
50
|
case 'ArrowUp':
|
|
@@ -62,11 +63,21 @@ export function createAutocompletePropGetters(_ref) {
|
|
|
62
63
|
}
|
|
63
64
|
};
|
|
64
65
|
var submit = function submit() {
|
|
65
|
-
var
|
|
66
|
-
|
|
67
|
-
if (
|
|
66
|
+
var _override$activeDesce;
|
|
67
|
+
var override = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
68
|
+
if (isOpen) {
|
|
69
|
+
setIsOpen(false);
|
|
70
|
+
} else {
|
|
71
|
+
var _inputRef$current;
|
|
72
|
+
(_inputRef$current = inputRef.current) === null || _inputRef$current === void 0 ? void 0 : _inputRef$current.blur();
|
|
73
|
+
}
|
|
74
|
+
var actualDescendant = (_override$activeDesce = override.activeDescendant) !== null && _override$activeDesce !== void 0 ? _override$activeDesce : activeDescendant;
|
|
75
|
+
if (!actualDescendant && override.query) {
|
|
76
|
+
onRefine(override.query);
|
|
77
|
+
}
|
|
78
|
+
if (actualDescendant && items.has(actualDescendant)) {
|
|
68
79
|
var _getQuery;
|
|
69
|
-
var _ref3 = items.get(
|
|
80
|
+
var _ref3 = items.get(actualDescendant),
|
|
70
81
|
_item = _ref3.item,
|
|
71
82
|
_ref3$config = _ref3.config,
|
|
72
83
|
indexOnSelect = _ref3$config.onSelect,
|
|
@@ -88,6 +99,7 @@ export function createAutocompletePropGetters(_ref) {
|
|
|
88
99
|
getInputProps: function getInputProps() {
|
|
89
100
|
return {
|
|
90
101
|
id: getElementId('input'),
|
|
102
|
+
ref: inputRef,
|
|
91
103
|
role: 'combobox',
|
|
92
104
|
'aria-autocomplete': 'list',
|
|
93
105
|
'aria-expanded': isOpen,
|
|
@@ -98,33 +110,42 @@ export function createAutocompletePropGetters(_ref) {
|
|
|
98
110
|
return setIsOpen(true);
|
|
99
111
|
},
|
|
100
112
|
onKeyDown: function onKeyDown(event) {
|
|
101
|
-
if (event.key === 'Escape') {
|
|
102
|
-
setActiveDescendant(undefined);
|
|
103
|
-
setIsOpen(false);
|
|
104
|
-
return;
|
|
105
|
-
}
|
|
106
113
|
switch (event.key) {
|
|
114
|
+
case 'Escape':
|
|
115
|
+
{
|
|
116
|
+
if (isOpen) {
|
|
117
|
+
setIsOpen(false);
|
|
118
|
+
event.preventDefault();
|
|
119
|
+
} else {
|
|
120
|
+
setActiveDescendant(undefined);
|
|
121
|
+
}
|
|
122
|
+
break;
|
|
123
|
+
}
|
|
107
124
|
case 'ArrowLeft':
|
|
108
125
|
case 'ArrowUp':
|
|
109
126
|
case 'ArrowRight':
|
|
110
127
|
case 'ArrowDown':
|
|
111
128
|
{
|
|
112
129
|
var _document$getElementB;
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
(
|
|
130
|
+
setIsOpen(true);
|
|
131
|
+
var nextActiveDescendant = getNextActiveDescendant(event.key);
|
|
132
|
+
setActiveDescendant(nextActiveDescendant);
|
|
133
|
+
(_document$getElementB = document.getElementById(nextActiveDescendant)) === null || _document$getElementB === void 0 ? void 0 : _document$getElementB.scrollIntoView(false);
|
|
116
134
|
event.preventDefault();
|
|
117
135
|
break;
|
|
118
136
|
}
|
|
119
137
|
case 'Enter':
|
|
120
138
|
{
|
|
121
|
-
submit(
|
|
139
|
+
submit({
|
|
140
|
+
query: event.target.value
|
|
141
|
+
});
|
|
122
142
|
break;
|
|
123
143
|
}
|
|
124
144
|
case 'Tab':
|
|
125
145
|
setIsOpen(false);
|
|
126
146
|
break;
|
|
127
147
|
default:
|
|
148
|
+
setIsOpen(true);
|
|
128
149
|
return;
|
|
129
150
|
}
|
|
130
151
|
},
|
|
@@ -152,7 +173,9 @@ export function createAutocompletePropGetters(_ref) {
|
|
|
152
173
|
role: 'row',
|
|
153
174
|
'aria-selected': id === activeDescendant,
|
|
154
175
|
onSelect: function onSelect() {
|
|
155
|
-
return submit(
|
|
176
|
+
return submit({
|
|
177
|
+
activeDescendant: id
|
|
178
|
+
});
|
|
156
179
|
}
|
|
157
180
|
};
|
|
158
181
|
},
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type { UsePropGetters } from './createAutocompletePropGetters';
|
|
2
|
+
type CreateAutocompleteStorageParams = {
|
|
3
|
+
useEffect: (effect: () => void, inputs?: readonly unknown[]) => void;
|
|
4
|
+
useMemo: <TType>(factory: () => TType, inputs: readonly unknown[]) => TType;
|
|
5
|
+
useState: <TType>(initialState: TType) => [TType, (newState: TType) => unknown];
|
|
6
|
+
};
|
|
7
|
+
type UseStorageParams<TItem extends Record<string, unknown>> = {
|
|
8
|
+
showRecent?: boolean | {
|
|
9
|
+
storageKey?: string;
|
|
10
|
+
};
|
|
11
|
+
query?: string;
|
|
12
|
+
} & Pick<Parameters<UsePropGetters<TItem>>[0], 'indices' | 'indicesConfig'>;
|
|
13
|
+
export declare function createAutocompleteStorage({ useEffect, useMemo, useState, }: CreateAutocompleteStorageParams): <TItem extends Record<string, unknown>>({ showRecent, query, indices, indicesConfig, }: UseStorageParams<TItem>) => {
|
|
14
|
+
storage: {
|
|
15
|
+
onAdd: () => void;
|
|
16
|
+
onRemove: () => void;
|
|
17
|
+
};
|
|
18
|
+
storageHits: never[];
|
|
19
|
+
indicesForPropGetters: {
|
|
20
|
+
indexName: string;
|
|
21
|
+
indexId: string;
|
|
22
|
+
hits: Array<{
|
|
23
|
+
[key: string]: unknown;
|
|
24
|
+
}>;
|
|
25
|
+
}[];
|
|
26
|
+
indicesConfigForPropGetters: import("./createAutocompletePropGetters").AutocompleteIndexConfig<TItem>[];
|
|
27
|
+
} | {
|
|
28
|
+
storage: {
|
|
29
|
+
onAdd(query: string): void;
|
|
30
|
+
onRemove(query: string): void;
|
|
31
|
+
registerUpdateListener(callback: () => void): void;
|
|
32
|
+
unregisterUpdateListener(): void;
|
|
33
|
+
getSnapshot(): {
|
|
34
|
+
getAll(query?: string): string[];
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
storageHits: {
|
|
38
|
+
objectID: string;
|
|
39
|
+
query: string;
|
|
40
|
+
__indexName: string;
|
|
41
|
+
_highlightResult: {
|
|
42
|
+
query: {
|
|
43
|
+
matchLevel: string;
|
|
44
|
+
value?: undefined;
|
|
45
|
+
};
|
|
46
|
+
} | {
|
|
47
|
+
query: {
|
|
48
|
+
value: string;
|
|
49
|
+
matchLevel?: undefined;
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
}[];
|
|
53
|
+
indicesForPropGetters: {
|
|
54
|
+
indexName: string;
|
|
55
|
+
indexId: string;
|
|
56
|
+
hits: Array<{
|
|
57
|
+
[key: string]: unknown;
|
|
58
|
+
}>;
|
|
59
|
+
}[];
|
|
60
|
+
indicesConfigForPropGetters: import("./createAutocompletePropGetters").AutocompleteIndexConfig<TItem>[];
|
|
61
|
+
};
|
|
62
|
+
export declare function createStorage({ limit, storageKey, }: {
|
|
63
|
+
limit: number;
|
|
64
|
+
storageKey?: string;
|
|
65
|
+
}): {
|
|
66
|
+
onAdd(query: string): void;
|
|
67
|
+
onRemove(query: string): void;
|
|
68
|
+
registerUpdateListener(callback: () => void): void;
|
|
69
|
+
unregisterUpdateListener(): void;
|
|
70
|
+
getSnapshot(): {
|
|
71
|
+
getAll(query?: string): string[];
|
|
72
|
+
};
|
|
73
|
+
};
|
|
74
|
+
export {};
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
2
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
3
|
+
import _typeof from "@babel/runtime/helpers/typeof";
|
|
4
|
+
export function createAutocompleteStorage(_ref) {
|
|
5
|
+
var useEffect = _ref.useEffect,
|
|
6
|
+
useMemo = _ref.useMemo,
|
|
7
|
+
useState = _ref.useState;
|
|
8
|
+
return function useStorage(_ref2) {
|
|
9
|
+
var showRecent = _ref2.showRecent,
|
|
10
|
+
query = _ref2.query,
|
|
11
|
+
indices = _ref2.indices,
|
|
12
|
+
indicesConfig = _ref2.indicesConfig;
|
|
13
|
+
var storageKey = showRecent && _typeof(showRecent) === 'object' ? showRecent.storageKey : undefined;
|
|
14
|
+
var storage = useMemo(function () {
|
|
15
|
+
return createStorage({
|
|
16
|
+
limit: 5,
|
|
17
|
+
storageKey: storageKey
|
|
18
|
+
});
|
|
19
|
+
}, [storageKey]);
|
|
20
|
+
var _useState = useState(storage.getSnapshot()),
|
|
21
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
22
|
+
snapshot = _useState2[0],
|
|
23
|
+
setSnapshot = _useState2[1];
|
|
24
|
+
useEffect(function () {
|
|
25
|
+
storage.registerUpdateListener(function () {
|
|
26
|
+
setSnapshot(storage.getSnapshot());
|
|
27
|
+
});
|
|
28
|
+
return function () {
|
|
29
|
+
storage.unregisterUpdateListener();
|
|
30
|
+
};
|
|
31
|
+
}, [storage]);
|
|
32
|
+
if (!showRecent) {
|
|
33
|
+
return {
|
|
34
|
+
storage: {
|
|
35
|
+
onAdd: function onAdd() {},
|
|
36
|
+
onRemove: function onRemove() {}
|
|
37
|
+
},
|
|
38
|
+
storageHits: [],
|
|
39
|
+
indicesForPropGetters: indices,
|
|
40
|
+
indicesConfigForPropGetters: indicesConfig
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
var storageHits = snapshot.getAll(query).map(function (value) {
|
|
44
|
+
return {
|
|
45
|
+
objectID: value,
|
|
46
|
+
query: value,
|
|
47
|
+
__indexName: 'recent-searches',
|
|
48
|
+
_highlightResult: getHighlightedAttribute({
|
|
49
|
+
item: {
|
|
50
|
+
query: value
|
|
51
|
+
},
|
|
52
|
+
query: query || ''
|
|
53
|
+
})
|
|
54
|
+
};
|
|
55
|
+
});
|
|
56
|
+
var indicesForPropGetters = _toConsumableArray(indices);
|
|
57
|
+
var indicesConfigForPropGetters = _toConsumableArray(indicesConfig);
|
|
58
|
+
indicesForPropGetters.unshift({
|
|
59
|
+
indexName: 'recent-searches',
|
|
60
|
+
indexId: 'recent-searches',
|
|
61
|
+
hits: storageHits
|
|
62
|
+
});
|
|
63
|
+
indicesConfigForPropGetters.unshift({
|
|
64
|
+
indexName: 'recent-searches',
|
|
65
|
+
// @ts-expect-error - we know it has query as it's generated from storageHits
|
|
66
|
+
getQuery: function getQuery(item) {
|
|
67
|
+
return item.query;
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
return {
|
|
71
|
+
storage: storage,
|
|
72
|
+
storageHits: storageHits,
|
|
73
|
+
indicesForPropGetters: indicesForPropGetters,
|
|
74
|
+
indicesConfigForPropGetters: indicesConfigForPropGetters
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
var LOCAL_STORAGE_KEY_TEST = 'test-localstorage-support';
|
|
79
|
+
var LOCAL_STORAGE_KEY = 'autocomplete-recent-searches';
|
|
80
|
+
function isLocalStorageSupported() {
|
|
81
|
+
try {
|
|
82
|
+
localStorage.setItem(LOCAL_STORAGE_KEY_TEST, '');
|
|
83
|
+
localStorage.removeItem(LOCAL_STORAGE_KEY_TEST);
|
|
84
|
+
return true;
|
|
85
|
+
} catch (error) {
|
|
86
|
+
return false;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
function getHighlightedAttribute(_ref3) {
|
|
90
|
+
var item = _ref3.item,
|
|
91
|
+
query = _ref3.query;
|
|
92
|
+
if (!query.trim().length) {
|
|
93
|
+
return {
|
|
94
|
+
query: {
|
|
95
|
+
matchLevel: 'none'
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
return {
|
|
100
|
+
query: {
|
|
101
|
+
value: item.query.replace(new RegExp(query.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&'), 'gi'), function (match) {
|
|
102
|
+
return "<mark>".concat(match, "</mark>");
|
|
103
|
+
})
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
function getLocalStorage() {
|
|
108
|
+
var key = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : LOCAL_STORAGE_KEY;
|
|
109
|
+
if (!isLocalStorageSupported()) {
|
|
110
|
+
return {
|
|
111
|
+
setItems: function setItems() {},
|
|
112
|
+
getItems: function getItems() {
|
|
113
|
+
return [];
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
return {
|
|
118
|
+
setItems: function setItems(items) {
|
|
119
|
+
try {
|
|
120
|
+
window.localStorage.setItem(key, JSON.stringify(items));
|
|
121
|
+
} catch (_unused) {
|
|
122
|
+
// do nothing, this likely means the storage is full
|
|
123
|
+
}
|
|
124
|
+
},
|
|
125
|
+
getItems: function getItems() {
|
|
126
|
+
var items = window.localStorage.getItem(key);
|
|
127
|
+
return items ? JSON.parse(items) : [];
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
export function createStorage(_ref4) {
|
|
132
|
+
var _ref4$limit = _ref4.limit,
|
|
133
|
+
limit = _ref4$limit === void 0 ? 5 : _ref4$limit,
|
|
134
|
+
storageKey = _ref4.storageKey;
|
|
135
|
+
var storage = getLocalStorage(storageKey);
|
|
136
|
+
var updateListener = null;
|
|
137
|
+
return {
|
|
138
|
+
onAdd: function onAdd(query) {
|
|
139
|
+
this.onRemove(query);
|
|
140
|
+
storage.setItems([query].concat(_toConsumableArray(storage.getItems())));
|
|
141
|
+
},
|
|
142
|
+
onRemove: function onRemove(query) {
|
|
143
|
+
var _updateListener;
|
|
144
|
+
storage.setItems(storage.getItems().filter(function (q) {
|
|
145
|
+
return q !== query;
|
|
146
|
+
}));
|
|
147
|
+
(_updateListener = updateListener) === null || _updateListener === void 0 ? void 0 : _updateListener();
|
|
148
|
+
},
|
|
149
|
+
registerUpdateListener: function registerUpdateListener(callback) {
|
|
150
|
+
updateListener = callback;
|
|
151
|
+
},
|
|
152
|
+
unregisterUpdateListener: function unregisterUpdateListener() {
|
|
153
|
+
updateListener = null;
|
|
154
|
+
},
|
|
155
|
+
getSnapshot: function getSnapshot() {
|
|
156
|
+
return {
|
|
157
|
+
getAll: function getAll() {
|
|
158
|
+
var query = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
|
|
159
|
+
return storage.getItems().filter(function (q) {
|
|
160
|
+
return q.includes(query);
|
|
161
|
+
}).slice(0, limit);
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
}
|
|
@@ -4,4 +4,6 @@ type IconProps = Pick<Renderer, 'createElement'>;
|
|
|
4
4
|
export declare function AutocompleteSubmitIcon({ createElement }: IconProps): JSX.Element;
|
|
5
5
|
export declare function AutocompleteLoadingIcon({ createElement }: IconProps): JSX.Element;
|
|
6
6
|
export declare function AutocompleteClearIcon({ createElement }: IconProps): JSX.Element;
|
|
7
|
+
export declare function AutocompleteClockIcon({ createElement }: IconProps): JSX.Element;
|
|
8
|
+
export declare function AutocompleteTrashIcon({ createElement }: IconProps): JSX.Element;
|
|
7
9
|
export {};
|
|
@@ -45,4 +45,22 @@ export function AutocompleteClearIcon(_ref3) {
|
|
|
45
45
|
}, createElement("path", {
|
|
46
46
|
d: "M5.293 6.707l5.293 5.293-5.293 5.293c-0.391 0.391-0.391 1.024 0 1.414s1.024 0.391 1.414 0l5.293-5.293 5.293 5.293c0.391 0.391 1.024 0.391 1.414 0s0.391-1.024 0-1.414l-5.293-5.293 5.293-5.293c0.391-0.391 0.391-1.024 0-1.414s-1.024-0.391-1.414 0l-5.293 5.293-5.293-5.293c-0.391-0.391-1.024-0.391-1.414 0s-0.391 1.024 0 1.414z"
|
|
47
47
|
}));
|
|
48
|
+
}
|
|
49
|
+
export function AutocompleteClockIcon(_ref4) {
|
|
50
|
+
var createElement = _ref4.createElement;
|
|
51
|
+
return createElement("svg", {
|
|
52
|
+
viewBox: "0 0 24 24",
|
|
53
|
+
fill: "currentColor"
|
|
54
|
+
}, createElement("path", {
|
|
55
|
+
d: "M12.516 6.984v5.25l4.5 2.672-0.75 1.266-5.25-3.188v-6h1.5zM12 20.016q3.281 0 5.648-2.367t2.367-5.648-2.367-5.648-5.648-2.367-5.648 2.367-2.367 5.648 2.367 5.648 5.648 2.367zM12 2.016q4.125 0 7.055 2.93t2.93 7.055-2.93 7.055-7.055 2.93-7.055-2.93-2.93-7.055 2.93-7.055 7.055-2.93z"
|
|
56
|
+
}));
|
|
57
|
+
}
|
|
58
|
+
export function AutocompleteTrashIcon(_ref5) {
|
|
59
|
+
var createElement = _ref5.createElement;
|
|
60
|
+
return createElement("svg", {
|
|
61
|
+
viewBox: "0 0 24 24",
|
|
62
|
+
fill: "currentColor"
|
|
63
|
+
}, createElement("path", {
|
|
64
|
+
d: "M18 7v13c0 0.276-0.111 0.525-0.293 0.707s-0.431 0.293-0.707 0.293h-10c-0.276 0-0.525-0.111-0.707-0.293s-0.293-0.431-0.293-0.707v-13zM17 5v-1c0-0.828-0.337-1.58-0.879-2.121s-1.293-0.879-2.121-0.879h-4c-0.828 0-1.58 0.337-2.121 0.879s-0.879 1.293-0.879 2.121v1h-4c-0.552 0-1 0.448-1 1s0.448 1 1 1h1v13c0 0.828 0.337 1.58 0.879 2.121s1.293 0.879 2.121 0.879h10c0.828 0 1.58-0.337 2.121-0.879s0.879-1.293 0.879-2.121v-13h1c0.552 0 1-0.448 1-1s-0.448-1-1-1zM9 5v-1c0-0.276 0.111-0.525 0.293-0.707s0.431-0.293 0.707-0.293h4c0.276 0 0.525 0.111 0.707 0.293s0.293 0.431 0.293 0.707v1zM9 11v6c0 0.552 0.448 1 1 1s1-0.448 1-1v-6c0-0.552-0.448-1-1-1s-1 0.448-1 1zM13 11v6c0 0.552 0.448 1 1 1s1-0.448 1-1v-6c0-0.552-0.448-1-1-1s-1 0.448-1 1z"
|
|
65
|
+
}));
|
|
48
66
|
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export * from './Autocomplete';
|
|
2
2
|
export * from './AutocompleteIndex';
|
|
3
3
|
export * from './AutocompletePanel';
|
|
4
|
+
export * from './AutocompleteRecentSearch';
|
|
4
5
|
export * from './AutocompleteSearch';
|
|
5
6
|
export * from './AutocompleteSuggestion';
|
|
6
7
|
export * from './createAutocompletePropGetters';
|
|
8
|
+
export * from './createAutocompleteStorage';
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export * from "./Autocomplete.js";
|
|
2
2
|
export * from "./AutocompleteIndex.js";
|
|
3
3
|
export * from "./AutocompletePanel.js";
|
|
4
|
+
export * from "./AutocompleteRecentSearch.js";
|
|
4
5
|
export * from "./AutocompleteSearch.js";
|
|
5
6
|
export * from "./AutocompleteSuggestion.js";
|
|
6
|
-
export * from "./createAutocompletePropGetters.js";
|
|
7
|
+
export * from "./createAutocompletePropGetters.js";
|
|
8
|
+
export * from "./createAutocompleteStorage.js";
|
|
@@ -8,6 +8,7 @@ export type ChatClassNames = {
|
|
|
8
8
|
container?: string | string[];
|
|
9
9
|
header?: ChatHeaderProps['classNames'];
|
|
10
10
|
messages?: ChatMessagesProps['classNames'];
|
|
11
|
+
message?: ChatMessagesProps['messageClassNames'];
|
|
11
12
|
prompt?: ChatPromptProps['classNames'];
|
|
12
13
|
toggleButton?: ChatToggleButtonProps['classNames'];
|
|
13
14
|
};
|
|
@@ -52,7 +52,8 @@ export function createChatComponent(_ref) {
|
|
|
52
52
|
classNames: classNames.header,
|
|
53
53
|
maximized: maximized
|
|
54
54
|
})), createElement(ChatMessages, _extends({}, messagesProps, {
|
|
55
|
-
classNames: classNames.messages
|
|
55
|
+
classNames: classNames.messages,
|
|
56
|
+
messageClassNames: classNames.message
|
|
56
57
|
})), createElement(PromptComponent || ChatPrompt, _objectSpread(_objectSpread({}, promptProps), {}, {
|
|
57
58
|
classNames: classNames.prompt
|
|
58
59
|
}))), createElement("div", {
|
|
@@ -77,6 +77,9 @@ export function createChatMessageComponent(_ref) {
|
|
|
77
77
|
toolCallId: toolMessage.toolCallId
|
|
78
78
|
});
|
|
79
79
|
};
|
|
80
|
+
if (!ToolLayoutComponent) {
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
80
83
|
return createElement("div", {
|
|
81
84
|
key: "".concat(message.id, "-").concat(index),
|
|
82
85
|
className: "ais-ChatMessage-tool"
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/** @jsx createElement */
|
|
2
2
|
import type { ComponentProps, MutableRef, Renderer } from '../../types';
|
|
3
|
-
import type { ChatMessageProps } from './ChatMessage';
|
|
3
|
+
import type { ChatMessageProps, ChatMessageClassNames, ChatMessageTranslations } from './ChatMessage';
|
|
4
4
|
import type { ChatMessageErrorProps } from './ChatMessageError';
|
|
5
5
|
import type { ChatMessageLoaderProps } from './ChatMessageLoader';
|
|
6
6
|
import type { ChatMessageBase, ChatStatus, ClientSideTools } from './types';
|
|
@@ -99,10 +99,18 @@ export type ChatMessagesProps<TMessage extends ChatMessageBase = ChatMessageBase
|
|
|
99
99
|
* Optional class names
|
|
100
100
|
*/
|
|
101
101
|
classNames?: Partial<ChatMessagesClassNames>;
|
|
102
|
+
/**
|
|
103
|
+
* Optional message class names
|
|
104
|
+
*/
|
|
105
|
+
messageClassNames?: Partial<ChatMessageClassNames>;
|
|
102
106
|
/**
|
|
103
107
|
* Optional translations
|
|
104
108
|
*/
|
|
105
109
|
translations?: Partial<ChatMessagesTranslations>;
|
|
110
|
+
/**
|
|
111
|
+
* Optional message translations
|
|
112
|
+
*/
|
|
113
|
+
messageTranslations?: Partial<ChatMessageTranslations>;
|
|
106
114
|
/**
|
|
107
115
|
* Optional user message props
|
|
108
116
|
*/
|
|
@@ -2,7 +2,7 @@ import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
|
2
2
|
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
3
3
|
import _extends from "@babel/runtime/helpers/extends";
|
|
4
4
|
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
5
|
-
var _excluded = ["classNames", "messages", "messageComponent", "loaderComponent", "errorComponent", "actionsComponent", "tools", "indexUiState", "setIndexUiState", "status", "hideScrollToBottom", "onReload", "onClose", "translations", "userMessageProps", "assistantMessageProps", "isClearing", "onClearTransitionEnd", "isScrollAtBottom", "scrollRef", "contentRef", "onScrollToBottom"];
|
|
5
|
+
var _excluded = ["classNames", "messageClassNames", "messageTranslations", "messages", "messageComponent", "loaderComponent", "errorComponent", "actionsComponent", "tools", "indexUiState", "setIndexUiState", "status", "hideScrollToBottom", "onReload", "onClose", "translations", "userMessageProps", "assistantMessageProps", "isClearing", "onClearTransitionEnd", "isScrollAtBottom", "scrollRef", "contentRef", "onScrollToBottom"];
|
|
6
6
|
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; }
|
|
7
7
|
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; }
|
|
8
8
|
import { cx } from "../../lib/index.js";
|
|
@@ -38,8 +38,10 @@ function createDefaultMessageComponent(_ref) {
|
|
|
38
38
|
setIndexUiState = _ref2.setIndexUiState,
|
|
39
39
|
onReload = _ref2.onReload,
|
|
40
40
|
onClose = _ref2.onClose,
|
|
41
|
-
|
|
42
|
-
|
|
41
|
+
actionsComponent = _ref2.actionsComponent,
|
|
42
|
+
classNames = _ref2.classNames,
|
|
43
|
+
messageTranslations = _ref2.messageTranslations,
|
|
44
|
+
translations = _ref2.translations;
|
|
43
45
|
var defaultAssistantActions = [].concat(_toConsumableArray(hasTextContent(message) ? [{
|
|
44
46
|
title: translations.copyToClipboardLabel,
|
|
45
47
|
icon: function icon() {
|
|
@@ -71,7 +73,9 @@ function createDefaultMessageComponent(_ref) {
|
|
|
71
73
|
onClose: onClose,
|
|
72
74
|
actions: defaultActions,
|
|
73
75
|
actionsComponent: actionsComponent,
|
|
74
|
-
"data-role": message.role
|
|
76
|
+
"data-role": message.role,
|
|
77
|
+
classNames: classNames,
|
|
78
|
+
translations: messageTranslations
|
|
75
79
|
}, messageProps));
|
|
76
80
|
};
|
|
77
81
|
}
|
|
@@ -94,6 +98,9 @@ export function createChatMessagesComponent(_ref3) {
|
|
|
94
98
|
return function ChatMessages(userProps) {
|
|
95
99
|
var _userProps$classNames = userProps.classNames,
|
|
96
100
|
classNames = _userProps$classNames === void 0 ? {} : _userProps$classNames,
|
|
101
|
+
_userProps$messageCla = userProps.messageClassNames,
|
|
102
|
+
messageClassNames = _userProps$messageCla === void 0 ? {} : _userProps$messageCla,
|
|
103
|
+
messageTranslations = userProps.messageTranslations,
|
|
97
104
|
_userProps$messages = userProps.messages,
|
|
98
105
|
messages = _userProps$messages === void 0 ? [] : _userProps$messages,
|
|
99
106
|
MessageComponent = userProps.messageComponent,
|
|
@@ -162,7 +169,9 @@ export function createChatMessagesComponent(_ref3) {
|
|
|
162
169
|
onReload: onReload,
|
|
163
170
|
actionsComponent: ActionsComponent,
|
|
164
171
|
onClose: onClose,
|
|
165
|
-
translations: translations
|
|
172
|
+
translations: translations,
|
|
173
|
+
classNames: messageClassNames,
|
|
174
|
+
messageTranslations: messageTranslations
|
|
166
175
|
});
|
|
167
176
|
}), status === 'submitted' && createElement(DefaultLoader, {
|
|
168
177
|
translations: {
|
|
@@ -18,7 +18,7 @@ export type ClientSideToolComponentProps = {
|
|
|
18
18
|
};
|
|
19
19
|
export type ClientSideToolComponent = (props: ClientSideToolComponentProps) => JSX.Element;
|
|
20
20
|
export type ClientSideTool = {
|
|
21
|
-
layoutComponent
|
|
21
|
+
layoutComponent?: ClientSideToolComponent;
|
|
22
22
|
addToolResult: AddToolResult;
|
|
23
23
|
onToolCall?: (params: Parameters<NonNullable<ChatInit<UIMessage>['onToolCall']>>[0]['toolCall'] & {
|
|
24
24
|
addToolResult: AddToolResultWithOutput;
|
package/dist/es/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default: "0.
|
|
1
|
+
declare const _default: "0.15.0";
|
|
2
2
|
export default _default;
|
package/dist/es/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export default '0.
|
|
1
|
+
export default '0.15.0';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "instantsearch-ui-components",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.15.0",
|
|
4
4
|
"description": "Common UI components for InstantSearch.",
|
|
5
5
|
"types": "dist/es/index.d.ts",
|
|
6
6
|
"main": "dist/cjs/index.js",
|
|
@@ -53,5 +53,5 @@
|
|
|
53
53
|
"zod": "^3.25.76 || ^4",
|
|
54
54
|
"zod-to-json-schema": "3.24.6"
|
|
55
55
|
},
|
|
56
|
-
"gitHead": "
|
|
56
|
+
"gitHead": "b4cb69c8cfaa9dc22dfe8fe695568cf5200f3893"
|
|
57
57
|
}
|