@uipath/apollo-react 3.27.0 → 3.28.0-pr203.c12fbbd

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.
Files changed (47) hide show
  1. package/dist/material/components/ap-chat/components/input/chat-input-editor.cjs +13 -6
  2. package/dist/material/components/ap-chat/components/input/chat-input-editor.d.ts +0 -1
  3. package/dist/material/components/ap-chat/components/input/chat-input-editor.d.ts.map +1 -1
  4. package/dist/material/components/ap-chat/components/input/chat-input-editor.js +14 -7
  5. package/dist/material/components/ap-chat/components/input/chat-input-resource-picker.cjs +236 -193
  6. package/dist/material/components/ap-chat/components/input/chat-input-resource-picker.d.ts.map +1 -1
  7. package/dist/material/components/ap-chat/components/input/chat-input-resource-picker.js +238 -195
  8. package/dist/material/components/ap-chat/components/input/chat-input.cjs +1 -2
  9. package/dist/material/components/ap-chat/components/input/chat-input.d.ts.map +1 -1
  10. package/dist/material/components/ap-chat/components/input/chat-input.js +1 -2
  11. package/dist/material/components/ap-chat/components/input/tiptap/resource-chip-node-view.cjs +12 -3
  12. package/dist/material/components/ap-chat/components/input/tiptap/resource-chip-node-view.d.ts.map +1 -1
  13. package/dist/material/components/ap-chat/components/input/tiptap/resource-chip-node-view.js +13 -4
  14. package/dist/material/components/ap-chat/components/input/tiptap/tiptap-editor.cjs +25 -3
  15. package/dist/material/components/ap-chat/components/input/tiptap/tiptap-editor.d.ts +1 -0
  16. package/dist/material/components/ap-chat/components/input/tiptap/tiptap-editor.d.ts.map +1 -1
  17. package/dist/material/components/ap-chat/components/input/tiptap/tiptap-editor.js +26 -4
  18. package/dist/material/components/ap-chat/components/input/tiptap/tiptap-editor.styles.cjs +2 -1
  19. package/dist/material/components/ap-chat/components/input/tiptap/tiptap-editor.styles.d.ts.map +1 -1
  20. package/dist/material/components/ap-chat/components/input/tiptap/tiptap-editor.styles.js +2 -1
  21. package/dist/material/components/ap-chat/components/input/tiptap/tiptap-resource-suggestion.cjs +24 -14
  22. package/dist/material/components/ap-chat/components/input/tiptap/tiptap-resource-suggestion.d.ts +5 -2
  23. package/dist/material/components/ap-chat/components/input/tiptap/tiptap-resource-suggestion.d.ts.map +1 -1
  24. package/dist/material/components/ap-chat/components/input/tiptap/tiptap-resource-suggestion.js +21 -14
  25. package/dist/material/components/ap-chat/components/input/tiptap/tiptap.utils.cjs +25 -0
  26. package/dist/material/components/ap-chat/components/input/tiptap/tiptap.utils.d.ts +5 -0
  27. package/dist/material/components/ap-chat/components/input/tiptap/tiptap.utils.d.ts.map +1 -1
  28. package/dist/material/components/ap-chat/components/input/tiptap/tiptap.utils.js +23 -1
  29. package/dist/material/components/ap-chat/components/message/chat-message.cjs +2 -0
  30. package/dist/material/components/ap-chat/components/message/chat-message.d.ts.map +1 -1
  31. package/dist/material/components/ap-chat/components/message/chat-message.js +2 -0
  32. package/dist/material/components/ap-chat/components/message/markdown/parsers/resource-token-parser.cjs +11 -2
  33. package/dist/material/components/ap-chat/components/message/markdown/parsers/resource-token-parser.d.ts +1 -0
  34. package/dist/material/components/ap-chat/components/message/markdown/parsers/resource-token-parser.d.ts.map +1 -1
  35. package/dist/material/components/ap-chat/components/message/markdown/parsers/resource-token-parser.js +7 -1
  36. package/dist/material/components/ap-chat/hooks/use-resource-picker-state.cjs +13 -4
  37. package/dist/material/components/ap-chat/hooks/use-resource-picker-state.d.ts.map +1 -1
  38. package/dist/material/components/ap-chat/hooks/use-resource-picker-state.js +13 -4
  39. package/dist/material/components/ap-chat/providers/resource-picker-provider.cjs +54 -19
  40. package/dist/material/components/ap-chat/providers/resource-picker-provider.d.ts +4 -1
  41. package/dist/material/components/ap-chat/providers/resource-picker-provider.d.ts.map +1 -1
  42. package/dist/material/components/ap-chat/providers/resource-picker-provider.js +55 -20
  43. package/dist/material/components/ap-chat/service/ChatConstants.cjs +16 -4
  44. package/dist/material/components/ap-chat/service/ChatConstants.d.ts +4 -1
  45. package/dist/material/components/ap-chat/service/ChatConstants.d.ts.map +1 -1
  46. package/dist/material/components/ap-chat/service/ChatConstants.js +5 -2
  47. package/package.json +2 -1
@@ -44,13 +44,16 @@ const index_cjs_namespaceObject = require("./tiptap/index.cjs");
44
44
  const chat_input_editor_EditorWithPicker = /*#__PURE__*/ (0, external_react_namespaceObject.forwardRef)(function(props, ref) {
45
45
  const { value, placeholder, minRows, maxRows, lineHeight, onChange, onKeyDown, editorRef } = props;
46
46
  const dropdownRef = (0, external_react_namespaceObject.useRef)(null);
47
- const { isOpen, drillDown, open, close, setQuery } = (0, resource_picker_provider_cjs_namespaceObject.useAutopilotChatResourcePicker)();
48
- const isOpenRef = (0, external_react_namespaceObject.useRef)(isOpen);
47
+ const { isOpenRef, drillDown, open, close, handleMentionEnd, setQuery } = (0, resource_picker_provider_cjs_namespaceObject.useAutopilotChatResourcePicker)();
49
48
  const drillDownRef = (0, external_react_namespaceObject.useRef)(drillDown);
50
49
  const valueRef = (0, external_react_namespaceObject.useRef)(value);
51
- isOpenRef.current = isOpen;
52
- drillDownRef.current = drillDown;
53
- valueRef.current = value;
50
+ (0, external_react_namespaceObject.useLayoutEffect)(()=>{
51
+ drillDownRef.current = drillDown;
52
+ valueRef.current = value;
53
+ }, [
54
+ drillDown,
55
+ value
56
+ ]);
54
57
  const handleChange = (0, external_react_namespaceObject.useCallback)((newValue)=>{
55
58
  if (isOpenRef.current && drillDownRef.current && !newValue.includes('@')) close();
56
59
  onChange(newValue);
@@ -90,7 +93,7 @@ const chat_input_editor_EditorWithPicker = /*#__PURE__*/ (0, external_react_name
90
93
  onChange: handleChange,
91
94
  onKeyDown: handleKeyDown,
92
95
  onMentionStart: open,
93
- onMentionEnd: close,
96
+ onMentionEnd: handleMentionEnd,
94
97
  onMentionQueryChange: setQuery
95
98
  }),
96
99
  /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_chat_input_resource_picker_cjs_namespaceObject.ResourcePickerDropdown, {
@@ -108,9 +111,13 @@ const chat_input_editor_ChatInputEditor = /*#__PURE__*/ external_react_default()
108
111
  const handleDrillDown = (0, external_react_namespaceObject.useCallback)(()=>{
109
112
  editorRef.current?.clearMentionQuery();
110
113
  }, []);
114
+ const handleClose = (0, external_react_namespaceObject.useCallback)(()=>{
115
+ editorRef.current?.exitMention();
116
+ }, []);
111
117
  return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(resource_picker_provider_cjs_namespaceObject.AutopilotChatResourcePickerProvider, {
112
118
  onResourceSelect: handleResourceSelect,
113
119
  onDrillDown: handleDrillDown,
120
+ onClose: handleClose,
114
121
  children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(chat_input_editor_EditorWithPicker, {
115
122
  ...props,
116
123
  ref: ref,
@@ -11,7 +11,6 @@ export interface ChatInputEditorProps {
11
11
  minRows: number;
12
12
  maxRows: number;
13
13
  lineHeight?: string;
14
- anchorEl: HTMLElement | null;
15
14
  onChange: (value: string) => void;
16
15
  onKeyDown?: (event: KeyboardEvent) => boolean;
17
16
  }
@@ -1 +1 @@
1
- {"version":3,"file":"chat-input-editor.d.ts","sourceRoot":"","sources":["../../../../../../src/material/components/ap-chat/components/input/chat-input-editor.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA+D,MAAM,OAAO,CAAC;AAYpF,MAAM,WAAW,qBAAqB;IACpC,KAAK,EAAE,MAAM,IAAI,CAAC;IAClB,KAAK,EAAE,MAAM,IAAI,CAAC;IAClB,kBAAkB,EAAE,MAAM,IAAI,CAAC;IAC/B,oBAAoB,EAAE,MAAM,MAAM,CAAC;CACpC;AAED,MAAM,WAAW,oBAAoB;IACnC,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,WAAW,GAAG,IAAI,CAAC;IAC7B,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAClC,SAAS,CAAC,EAAE,CAAC,KAAK,EAAE,aAAa,KAAK,OAAO,CAAC;CAC/C;AAiFD,eAAO,MAAM,eAAe,+FAyB3B,CAAC"}
1
+ {"version":3,"file":"chat-input-editor.d.ts","sourceRoot":"","sources":["../../../../../../src/material/components/ap-chat/components/input/chat-input-editor.tsx"],"names":[],"mappings":"AAAA,OAAO,KAMN,MAAM,OAAO,CAAC;AAYf,MAAM,WAAW,qBAAqB;IACpC,KAAK,EAAE,MAAM,IAAI,CAAC;IAClB,KAAK,EAAE,MAAM,IAAI,CAAC;IAClB,kBAAkB,EAAE,MAAM,IAAI,CAAC;IAC/B,oBAAoB,EAAE,MAAM,MAAM,CAAC;CACpC;AAED,MAAM,WAAW,oBAAoB;IACnC,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAClC,SAAS,CAAC,EAAE,CAAC,KAAK,EAAE,aAAa,KAAK,OAAO,CAAC;CAC/C;AAqFD,eAAO,MAAM,eAAe,+FA8B3B,CAAC"}
@@ -1,18 +1,21 @@
1
1
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
2
- import react, { forwardRef, useCallback, useImperativeHandle, useRef } from "react";
2
+ import react, { forwardRef, useCallback, useImperativeHandle, useLayoutEffect, useRef } from "react";
3
3
  import { AutopilotChatResourcePickerProvider, useAutopilotChatResourcePicker } from "../../providers/resource-picker-provider.js";
4
4
  import { ResourcePickerDropdown } from "./chat-input-resource-picker.js";
5
5
  import { TipTapEditor } from "./tiptap/index.js";
6
6
  const chat_input_editor_EditorWithPicker = /*#__PURE__*/ forwardRef(function(props, ref) {
7
7
  const { value, placeholder, minRows, maxRows, lineHeight, onChange, onKeyDown, editorRef } = props;
8
8
  const dropdownRef = useRef(null);
9
- const { isOpen, drillDown, open, close, setQuery } = useAutopilotChatResourcePicker();
10
- const isOpenRef = useRef(isOpen);
9
+ const { isOpenRef, drillDown, open, close, handleMentionEnd, setQuery } = useAutopilotChatResourcePicker();
11
10
  const drillDownRef = useRef(drillDown);
12
11
  const valueRef = useRef(value);
13
- isOpenRef.current = isOpen;
14
- drillDownRef.current = drillDown;
15
- valueRef.current = value;
12
+ useLayoutEffect(()=>{
13
+ drillDownRef.current = drillDown;
14
+ valueRef.current = value;
15
+ }, [
16
+ drillDown,
17
+ value
18
+ ]);
16
19
  const handleChange = useCallback((newValue)=>{
17
20
  if (isOpenRef.current && drillDownRef.current && !newValue.includes('@')) close();
18
21
  onChange(newValue);
@@ -52,7 +55,7 @@ const chat_input_editor_EditorWithPicker = /*#__PURE__*/ forwardRef(function(pro
52
55
  onChange: handleChange,
53
56
  onKeyDown: handleKeyDown,
54
57
  onMentionStart: open,
55
- onMentionEnd: close,
58
+ onMentionEnd: handleMentionEnd,
56
59
  onMentionQueryChange: setQuery
57
60
  }),
58
61
  /*#__PURE__*/ jsx(ResourcePickerDropdown, {
@@ -70,9 +73,13 @@ const chat_input_editor_ChatInputEditor = /*#__PURE__*/ react.memo(/*#__PURE__*/
70
73
  const handleDrillDown = useCallback(()=>{
71
74
  editorRef.current?.clearMentionQuery();
72
75
  }, []);
76
+ const handleClose = useCallback(()=>{
77
+ editorRef.current?.exitMention();
78
+ }, []);
73
79
  return /*#__PURE__*/ jsx(AutopilotChatResourcePickerProvider, {
74
80
  onResourceSelect: handleResourceSelect,
75
81
  onDrillDown: handleDrillDown,
82
+ onClose: handleClose,
76
83
  children: /*#__PURE__*/ jsx(chat_input_editor_EditorWithPicker, {
77
84
  ...props,
78
85
  ref: ref,
@@ -49,6 +49,7 @@ var apollo_core_default = /*#__PURE__*/ __webpack_require__.n(apollo_core_namesp
49
49
  const external_index_cjs_namespaceObject = require("../../../../index.cjs");
50
50
  const external_react_namespaceObject = require("react");
51
51
  var external_react_default = /*#__PURE__*/ __webpack_require__.n(external_react_namespaceObject);
52
+ const external_react_window_namespaceObject = require("react-window");
52
53
  const index_cjs_namespaceObject = require("../../../ap-skeleton/index.cjs");
53
54
  const chat_state_provider_cjs_namespaceObject = require("../../providers/chat-state-provider.cjs");
54
55
  const resource_picker_provider_cjs_namespaceObject = require("../../providers/resource-picker-provider.cjs");
@@ -88,12 +89,6 @@ const EmptyContainer = (0, styles_namespaceObject.styled)('div')(({ theme })=>({
88
89
  padding: `${apollo_core_default().Padding.PadXxl} ${apollo_core_default().Padding.PadXxxl}`,
89
90
  color: theme.palette.semantic.colorForegroundDeEmp
90
91
  }));
91
- const LoadMoreContainer = (0, styles_namespaceObject.styled)('div')({
92
- display: 'flex',
93
- alignItems: 'center',
94
- justifyContent: 'center',
95
- padding: apollo_core_default().Padding.PadXxl
96
- });
97
92
  const DrillDownHeader = (0, styles_namespaceObject.styled)('div')(({ theme })=>({
98
93
  display: 'flex',
99
94
  alignItems: 'center',
@@ -104,17 +99,57 @@ const DrillDownHeader = (0, styles_namespaceObject.styled)('div')(({ theme })=>(
104
99
  const SkeletonItem = (0, styles_namespaceObject.styled)(StyledMenuItem)({
105
100
  pointerEvents: 'none'
106
101
  });
107
- const chat_input_resource_picker_ResourceMenuItem = /*#__PURE__*/ external_react_default().memo(function({ item, isSelected, onItemClick, tooltipPlacement, fontToken }) {
102
+ const StyledResourceList = (0, styles_namespaceObject.styled)(external_react_window_namespaceObject.List)({
103
+ '&::-webkit-scrollbar': {
104
+ width: '6px'
105
+ },
106
+ '&::-webkit-scrollbar-track': {
107
+ background: 'transparent'
108
+ },
109
+ '&::-webkit-scrollbar-thumb': {
110
+ background: 'var(--color-border-de-emp)',
111
+ borderRadius: '3px'
112
+ }
113
+ });
114
+ const loaderRowStyle = {
115
+ display: 'flex',
116
+ alignItems: 'center',
117
+ justifyContent: 'center'
118
+ };
119
+ const preventDefaultMouseDown = (e)=>e.preventDefault();
120
+ const MENU_SLOT_PROPS = {
121
+ paper: {
122
+ sx: {
123
+ width: external_service_index_cjs_namespaceObject.CHAT_RESOURCE_PICKER_MENU_WIDTH,
124
+ maxHeight: external_service_index_cjs_namespaceObject.CHAT_RESOURCE_PICKER_MENU_MAX_HEIGHT,
125
+ overflowY: 'hidden',
126
+ display: 'flex',
127
+ flexDirection: 'column'
128
+ }
129
+ }
130
+ };
131
+ const VirtualizedResourceRow = ({ index, style, ariaAttributes, items, selectedIndex, navigationMode, handleItemClick, onMouseEnterItem, tooltipPlacement, fontToken })=>{
132
+ if (index >= items.length) return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("div", {
133
+ style: {
134
+ ...style,
135
+ ...loaderRowStyle
136
+ },
137
+ children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(CircularProgress_default(), {
138
+ size: 20
139
+ })
140
+ });
141
+ const item = items[index];
142
+ const isSelected = index === selectedIndex;
108
143
  const isCategory = (0, resource_picker_provider_cjs_namespaceObject.isResourceSelector)(item);
109
144
  const tooltipContent = item.tooltip;
110
- const handleClick = (0, external_react_namespaceObject.useCallback)(()=>onItemClick(item), [
111
- onItemClick,
112
- item
113
- ]);
145
+ const isKeyboardSelected = isSelected && 'keyboard' === navigationMode;
114
146
  const menuItem = /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(StyledMenuItem, {
115
147
  id: `resource-item-${item.id}`,
116
148
  selected: isSelected,
117
- onClick: handleClick,
149
+ onClick: ()=>handleItemClick(item),
150
+ onMouseEnter: ()=>onMouseEnterItem(index),
151
+ style: style,
152
+ ...ariaAttributes,
118
153
  children: [
119
154
  /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(ResourceItemContent, {
120
155
  children: [
@@ -145,49 +180,167 @@ const chat_input_resource_picker_ResourceMenuItem = /*#__PURE__*/ external_react
145
180
  children: tooltipContent
146
181
  }),
147
182
  placement: tooltipPlacement,
148
- open: isSelected ? true : void 0,
149
- enterDelay: isSelected ? 0 : external_service_index_cjs_namespaceObject.CHAT_RESOURCE_PICKER_TOOLTIP_ENTER_DELAY,
150
- enterNextDelay: isSelected ? 0 : external_service_index_cjs_namespaceObject.CHAT_RESOURCE_PICKER_TOOLTIP_ENTER_DELAY,
183
+ open: isKeyboardSelected ? true : void 0,
184
+ enterDelay: isKeyboardSelected ? 0 : external_service_index_cjs_namespaceObject.CHAT_RESOURCE_PICKER_TOOLTIP_ENTER_DELAY,
185
+ enterNextDelay: isKeyboardSelected ? 0 : external_service_index_cjs_namespaceObject.CHAT_RESOURCE_PICKER_TOOLTIP_ENTER_DELAY,
151
186
  children: menuItem
152
187
  });
153
- });
154
- function ResourcePickerDropdownInner(_props, ref) {
155
- const { isOpen, anchorPosition, displayedItems, drillDown, query, loading, loadingMore, searchInProgress, hasMore, error, previousDisplayCount, handleItemClick, close, goBackOrClose, retryLoad, loadMore } = (0, resource_picker_provider_cjs_namespaceObject.useAutopilotChatResourcePicker)();
188
+ };
189
+ const chat_input_resource_picker_MenuContent = /*#__PURE__*/ external_react_default().memo(function({ virtualListRef, selectedIndex, navigationMode, onMouseEnterItem, onItemClick }) {
190
+ const { displayedItems: items, drillDown, query, loading, loadingMore, searchInProgress, hasMore, error, previousDisplayCount, goBackOrClose, retryLoad, loadMore } = (0, resource_picker_provider_cjs_namespaceObject.useAutopilotChatResourcePicker)();
156
191
  const { theming, spacing } = (0, chat_state_provider_cjs_namespaceObject.useChatState)();
157
- const listRef = (0, external_react_namespaceObject.useRef)(null);
158
- const isOpenRef = (0, external_react_namespaceObject.useRef)(isOpen);
159
- isOpenRef.current = isOpen;
160
192
  const { _ } = (0, react_namespaceObject.useLingui)();
161
- const [selectedIndex, setSelectedIndex] = (0, external_react_namespaceObject.useState)(0);
162
- const scrollStateRef = (0, external_react_namespaceObject.useRef)({
193
+ const drillDownHeaderRef = (0, external_react_namespaceObject.useRef)(null);
194
+ const [drillDownHeaderHeight, setDrillDownHeaderHeight] = (0, external_react_namespaceObject.useState)(0);
195
+ (0, external_react_namespaceObject.useLayoutEffect)(()=>{
196
+ if (!drillDown) return void setDrillDownHeaderHeight(0);
197
+ setDrillDownHeaderHeight(drillDownHeaderRef.current?.offsetHeight ?? 0);
198
+ }, [
199
+ drillDown
200
+ ]);
201
+ const handleRowsRendered = (0, external_react_namespaceObject.useCallback)((visibleRows, _allRows)=>{
202
+ if (!hasMore || loadingMore) return;
203
+ if (visibleRows.stopIndex >= items.length - external_service_index_cjs_namespaceObject.CHAT_RESOURCE_PICKER_LOAD_MORE_THRESHOLD) loadMore();
204
+ }, [
205
+ items.length,
163
206
  hasMore,
164
207
  loadingMore,
165
- loadMore,
166
- scrollTop: 0,
167
- container: null
208
+ loadMore
209
+ ]);
210
+ const tooltipPlacement = theming?.chatMenu?.groupItemTooltipPlacement ?? 'left';
211
+ const isLoadingState = loading || searchInProgress;
212
+ const skeletonElements = (0, external_react_namespaceObject.useMemo)(()=>{
213
+ const skeletonCount = Math.min(Math.max(previousDisplayCount, external_service_index_cjs_namespaceObject.CHAT_RESOURCE_PICKER_MIN_SKELETON_COUNT), external_service_index_cjs_namespaceObject.CHAT_RESOURCE_PICKER_MAX_SKELETON_COUNT);
214
+ return Array.from({
215
+ length: skeletonCount
216
+ }).map((_, index)=>/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(SkeletonItem, {
217
+ disabled: true,
218
+ children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(index_cjs_namespaceObject.ApSkeleton, {})
219
+ }, `skeleton-${index}`));
220
+ }, [
221
+ previousDisplayCount
222
+ ]);
223
+ const rowCount = items.length + (loadingMore ? 1 : 0);
224
+ const listHeight = Math.min(external_service_index_cjs_namespaceObject.CHAT_RESOURCE_PICKER_MENU_MAX_HEIGHT - drillDownHeaderHeight, rowCount * external_service_index_cjs_namespaceObject.CHAT_RESOURCE_PICKER_ITEM_HEIGHT);
225
+ const rowProps = (0, external_react_namespaceObject.useMemo)(()=>({
226
+ items,
227
+ selectedIndex,
228
+ navigationMode,
229
+ handleItemClick: onItemClick,
230
+ onMouseEnterItem,
231
+ tooltipPlacement,
232
+ fontToken: spacing.primaryFontToken
233
+ }), [
234
+ items,
235
+ selectedIndex,
236
+ navigationMode,
237
+ onItemClick,
238
+ onMouseEnterItem,
239
+ tooltipPlacement,
240
+ spacing.primaryFontToken
241
+ ]);
242
+ const drillDownHeader = drillDown ? /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(DrillDownHeader, {
243
+ ref: drillDownHeaderRef,
244
+ children: [
245
+ /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(icon_button_cjs_namespaceObject.AutopilotChatIconButton, {
246
+ size: "small",
247
+ onClick: goBackOrClose,
248
+ "aria-label": _({
249
+ id: 'autopilot-chat.resource-picker.back'
250
+ }),
251
+ children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_index_cjs_namespaceObject.ApIcon, {
252
+ variant: "outlined",
253
+ name: "arrow_back",
254
+ size: apollo_core_default().Icon.IconXs
255
+ })
256
+ }),
257
+ /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_index_cjs_namespaceObject.ApTypography, {
258
+ variant: spacing.primaryBoldFontToken,
259
+ style: ellipsisStyle,
260
+ children: drillDown.category.displayName
261
+ })
262
+ ]
263
+ }) : null;
264
+ if (isLoadingState) return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(jsx_runtime_namespaceObject.Fragment, {
265
+ children: [
266
+ drillDownHeader,
267
+ skeletonElements
268
+ ]
269
+ });
270
+ if (error) return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(jsx_runtime_namespaceObject.Fragment, {
271
+ children: [
272
+ drillDownHeader,
273
+ /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(ErrorContainer, {
274
+ children: [
275
+ /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_index_cjs_namespaceObject.ApTypography, {
276
+ variant: apollo_core_namespaceObject.FontVariantToken.fontSizeS,
277
+ children: error
278
+ }),
279
+ /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_index_cjs_namespaceObject.ApButton, {
280
+ variant: "text",
281
+ size: "small",
282
+ onClick: retryLoad,
283
+ label: _({
284
+ id: 'autopilot-chat.resource-picker.retry'
285
+ })
286
+ })
287
+ ]
288
+ })
289
+ ]
290
+ });
291
+ if (0 === items.length) {
292
+ const emptyMessage = query.trim() ? _({
293
+ id: 'autopilot-chat.resource-picker.no-results'
294
+ }) : _({
295
+ id: 'autopilot-chat.resource-picker.empty'
296
+ });
297
+ return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(jsx_runtime_namespaceObject.Fragment, {
298
+ children: [
299
+ drillDownHeader,
300
+ /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(EmptyContainer, {
301
+ children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_index_cjs_namespaceObject.ApTypography, {
302
+ variant: apollo_core_namespaceObject.FontVariantToken.fontSizeS,
303
+ children: emptyMessage
304
+ })
305
+ })
306
+ ]
307
+ });
308
+ }
309
+ return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(jsx_runtime_namespaceObject.Fragment, {
310
+ children: [
311
+ drillDownHeader,
312
+ /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(StyledResourceList, {
313
+ listRef: virtualListRef,
314
+ rowProps: rowProps,
315
+ rowComponent: VirtualizedResourceRow,
316
+ rowCount: rowCount,
317
+ rowHeight: external_service_index_cjs_namespaceObject.CHAT_RESOURCE_PICKER_ITEM_HEIGHT,
318
+ overscanCount: 5,
319
+ onRowsRendered: handleRowsRendered,
320
+ style: {
321
+ height: listHeight
322
+ }
323
+ })
324
+ ]
168
325
  });
169
- scrollStateRef.current.hasMore = hasMore;
170
- scrollStateRef.current.loadingMore = loadingMore;
171
- scrollStateRef.current.loadMore = loadMore;
326
+ });
327
+ function ResourcePickerDropdownInner(_props, ref) {
328
+ const { isOpen, isOpenRef, anchorPosition, displayedItems: items, drillDown, query, handleItemClick, close, goBackOrClose } = (0, resource_picker_provider_cjs_namespaceObject.useAutopilotChatResourcePicker)();
329
+ const virtualListRef = (0, external_react_window_namespaceObject.useListRef)(null);
330
+ const { _ } = (0, react_namespaceObject.useLingui)();
331
+ const [selectedIndex, setSelectedIndex] = (0, external_react_namespaceObject.useState)(0);
332
+ const [navigationMode, setNavigationMode] = (0, external_react_namespaceObject.useState)('none');
172
333
  const prevStateRef = (0, external_react_namespaceObject.useRef)({
173
334
  query,
174
- drillDownId: drillDown?.category?.id,
175
- selectedIndex,
176
- loadingMore
335
+ drillDownId: drillDown?.category?.id
177
336
  });
178
- const handleScroll = (0, external_react_namespaceObject.useCallback)((event)=>{
179
- const target = event.currentTarget;
180
- const state = scrollStateRef.current;
181
- state.scrollTop = target.scrollTop;
182
- state.container = target;
183
- if (!state.hasMore || state.loadingMore) return;
184
- const nearBottom = target.scrollHeight - target.scrollTop - target.clientHeight < external_service_index_cjs_namespaceObject.CHAT_RESOURCE_PICKER_SCROLL_THRESHOLD;
185
- if (nearBottom) state.loadMore();
186
- }, []);
187
337
  (0, external_react_namespaceObject.useEffect)(()=>{
188
338
  const prev = prevStateRef.current;
189
339
  const currentDrillDownId = drillDown?.category?.id;
190
- if (prev.query !== query || prev.drillDownId !== currentDrillDownId) setSelectedIndex(0);
340
+ if (prev.query !== query || prev.drillDownId !== currentDrillDownId) {
341
+ setSelectedIndex(0);
342
+ setNavigationMode('none');
343
+ }
191
344
  prev.query = query;
192
345
  prev.drillDownId = currentDrillDownId;
193
346
  }, [
@@ -195,44 +348,42 @@ function ResourcePickerDropdownInner(_props, ref) {
195
348
  drillDown
196
349
  ]);
197
350
  (0, external_react_namespaceObject.useEffect)(()=>{
198
- const prev = prevStateRef.current;
199
- if (prev.selectedIndex === selectedIndex) return;
200
- prev.selectedIndex = selectedIndex;
201
- const selectedItem = displayedItems[selectedIndex];
202
- if (listRef.current && selectedItem) {
203
- const selectedElement = listRef.current.querySelector(`#resource-item-${selectedItem.id}`);
204
- selectedElement?.scrollIntoView({
205
- block: 'nearest'
206
- });
351
+ if (isOpen) {
352
+ setSelectedIndex(0);
353
+ setNavigationMode('none');
207
354
  }
208
355
  }, [
209
- selectedIndex,
210
- displayedItems
356
+ isOpen
211
357
  ]);
212
- (0, external_react_namespaceObject.useLayoutEffect)(()=>{
213
- const prev = prevStateRef.current;
214
- const wasLoadingMore = prev.loadingMore;
215
- prev.loadingMore = loadingMore;
216
- if (wasLoadingMore && !loadingMore) {
217
- const { scrollTop, container } = scrollStateRef.current;
218
- if (container && scrollTop > 0) container.scrollTop = scrollTop;
219
- }
358
+ (0, external_react_namespaceObject.useEffect)(()=>{
359
+ if ('keyboard' === navigationMode) virtualListRef.current?.scrollToRow({
360
+ index: selectedIndex,
361
+ align: 'auto'
362
+ });
220
363
  }, [
221
- loadingMore
364
+ selectedIndex,
365
+ navigationMode,
366
+ virtualListRef
222
367
  ]);
223
368
  const navigateUp = (0, external_react_namespaceObject.useCallback)(()=>{
224
369
  setSelectedIndex((prev)=>Math.max(prev - 1, 0));
370
+ setNavigationMode('keyboard');
225
371
  }, []);
226
372
  const navigateDown = (0, external_react_namespaceObject.useCallback)(()=>{
227
- setSelectedIndex((prev)=>Math.min(prev + 1, displayedItems.length - 1));
373
+ setSelectedIndex((prev)=>Math.min(prev + 1, items.length - 1));
374
+ setNavigationMode('keyboard');
228
375
  }, [
229
- displayedItems.length
376
+ items.length
230
377
  ]);
378
+ const handleMouseEnterItem = (0, external_react_namespaceObject.useCallback)((index)=>{
379
+ setSelectedIndex(index);
380
+ setNavigationMode('pointer');
381
+ }, []);
231
382
  const selectItem = (0, external_react_namespaceObject.useCallback)(()=>{
232
- const selectedItem = displayedItems[selectedIndex];
383
+ const selectedItem = items[selectedIndex];
233
384
  if (selectedItem) handleItemClick(selectedItem);
234
385
  }, [
235
- displayedItems,
386
+ items,
236
387
  selectedIndex,
237
388
  handleItemClick
238
389
  ]);
@@ -255,7 +406,7 @@ function ResourcePickerDropdownInner(_props, ref) {
255
406
  return true;
256
407
  case 'Escape':
257
408
  event.preventDefault();
258
- goBackOrClose();
409
+ drillDown ? goBackOrClose() : close();
259
410
  return true;
260
411
  default:
261
412
  return false;
@@ -265,138 +416,23 @@ function ResourcePickerDropdownInner(_props, ref) {
265
416
  navigateDown,
266
417
  navigateUp,
267
418
  selectItem,
268
- goBackOrClose
419
+ goBackOrClose,
420
+ drillDown,
421
+ close
269
422
  ]);
270
- const tooltipPlacement = theming?.chatMenu?.groupItemTooltipPlacement ?? 'left';
271
- const skeletonElements = (0, external_react_namespaceObject.useMemo)(()=>{
272
- const skeletonCount = Math.min(Math.max(previousDisplayCount, external_service_index_cjs_namespaceObject.CHAT_RESOURCE_PICKER_MIN_SKELETON_COUNT), external_service_index_cjs_namespaceObject.CHAT_RESOURCE_PICKER_MAX_SKELETON_COUNT);
273
- return Array.from({
274
- length: skeletonCount
275
- }).map((_, index)=>/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(SkeletonItem, {
276
- disabled: true,
277
- children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(index_cjs_namespaceObject.ApSkeleton, {})
278
- }, `skeleton-${index}`));
279
- }, [
280
- previousDisplayCount
281
- ]);
282
- const menuSlotProps = (0, external_react_namespaceObject.useMemo)(()=>({
283
- paper: {
284
- sx: {
285
- width: external_service_index_cjs_namespaceObject.CHAT_RESOURCE_PICKER_MENU_WIDTH,
286
- maxHeight: external_service_index_cjs_namespaceObject.CHAT_RESOURCE_PICKER_MENU_MAX_HEIGHT,
287
- overflowY: 'auto'
288
- },
289
- onScroll: handleScroll
290
- }
291
- }), [
292
- handleScroll
293
- ]);
294
- const isLoadingState = loading || searchInProgress;
295
- const drillDownHeader = (0, external_react_namespaceObject.useMemo)(()=>{
296
- if (!drillDown) return null;
297
- return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(DrillDownHeader, {
298
- children: [
299
- /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(icon_button_cjs_namespaceObject.AutopilotChatIconButton, {
300
- size: "small",
301
- onClick: goBackOrClose,
302
- "aria-label": _({
303
- id: 'autopilot-chat.resource-picker.back'
304
- }),
305
- children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_index_cjs_namespaceObject.ApIcon, {
306
- variant: "outlined",
307
- name: "arrow_back",
308
- size: apollo_core_default().Icon.IconXs
309
- })
310
- }),
311
- /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_index_cjs_namespaceObject.ApTypography, {
312
- variant: spacing.primaryBoldFontToken,
313
- style: ellipsisStyle,
314
- children: drillDown.category.displayName
315
- })
316
- ]
317
- }, "drilldown-header");
423
+ const handleMenuClose = (0, external_react_namespaceObject.useCallback)((_event, reason)=>{
424
+ if ('escapeKeyDown' === reason && drillDown) return void goBackOrClose();
425
+ close();
318
426
  }, [
319
427
  drillDown,
320
428
  goBackOrClose,
321
- spacing.primaryBoldFontToken,
322
- _
323
- ]);
324
- const menuContent = (0, external_react_namespaceObject.useMemo)(()=>{
325
- if (isLoadingState) return [
326
- drillDownHeader,
327
- ...skeletonElements
328
- ];
329
- if (error) return [
330
- drillDownHeader,
331
- /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(ErrorContainer, {
332
- children: [
333
- /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_index_cjs_namespaceObject.ApTypography, {
334
- variant: apollo_core_namespaceObject.FontVariantToken.fontSizeS,
335
- children: error
336
- }),
337
- /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_index_cjs_namespaceObject.ApButton, {
338
- variant: "text",
339
- size: "small",
340
- onClick: retryLoad,
341
- label: "retry",
342
- children: _({
343
- id: 'autopilot-chat.resource-picker.retry'
344
- })
345
- })
346
- ]
347
- }, "error")
348
- ];
349
- if (0 === displayedItems.length) {
350
- const emptyMessage = query.trim() ? _({
351
- id: 'autopilot-chat.resource-picker.no-results'
352
- }) : _({
353
- id: 'autopilot-chat.resource-picker.empty'
354
- });
355
- return [
356
- drillDownHeader,
357
- /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(EmptyContainer, {
358
- children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_index_cjs_namespaceObject.ApTypography, {
359
- variant: apollo_core_namespaceObject.FontVariantToken.fontSizeS,
360
- children: emptyMessage
361
- })
362
- }, "empty")
363
- ];
364
- }
365
- return [
366
- drillDownHeader,
367
- ...displayedItems.map((item, index)=>/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(chat_input_resource_picker_ResourceMenuItem, {
368
- item: item,
369
- isSelected: index === selectedIndex,
370
- onItemClick: handleItemClick,
371
- tooltipPlacement: tooltipPlacement,
372
- fontToken: spacing.primaryFontToken
373
- }, item.id)),
374
- loadingMore && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(LoadMoreContainer, {
375
- children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(CircularProgress_default(), {
376
- size: 20
377
- })
378
- }, "loading-more")
379
- ];
380
- }, [
381
- isLoadingState,
382
- drillDownHeader,
383
- skeletonElements,
384
- error,
385
- retryLoad,
386
- _,
387
- displayedItems,
388
- query,
389
- selectedIndex,
390
- handleItemClick,
391
- tooltipPlacement,
392
- spacing.primaryFontToken,
393
- loadingMore
429
+ close
394
430
  ]);
395
431
  return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(Menu_default(), {
396
432
  open: isOpen,
397
433
  anchorReference: "anchorPosition",
398
434
  anchorPosition: anchorPosition ?? void 0,
399
- onClose: close,
435
+ onClose: handleMenuClose,
400
436
  anchorOrigin: {
401
437
  vertical: 'top',
402
438
  horizontal: 'left'
@@ -412,10 +448,17 @@ function ResourcePickerDropdownInner(_props, ref) {
412
448
  id: 'autopilot-chat.resource-picker.label'
413
449
  }),
414
450
  dense: true,
415
- ref: listRef
451
+ disableListWrap: true,
452
+ onMouseDown: preventDefaultMouseDown
416
453
  },
417
- slotProps: menuSlotProps,
418
- children: menuContent
454
+ slotProps: MENU_SLOT_PROPS,
455
+ children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(chat_input_resource_picker_MenuContent, {
456
+ virtualListRef: virtualListRef,
457
+ selectedIndex: selectedIndex,
458
+ navigationMode: navigationMode,
459
+ onMouseEnterItem: handleMouseEnterItem,
460
+ onItemClick: handleItemClick
461
+ })
419
462
  });
420
463
  }
421
464
  const ResourcePickerDropdown = /*#__PURE__*/ external_react_default().memo(/*#__PURE__*/ (0, external_react_namespaceObject.forwardRef)(ResourcePickerDropdownInner));
@@ -1 +1 @@
1
- {"version":3,"file":"chat-input-resource-picker.d.ts","sourceRoot":"","sources":["../../../../../../src/material/components/ap-chat/components/input/chat-input-resource-picker.tsx"],"names":[],"mappings":"AAQA,OAAO,KASN,MAAM,OAAO,CAAC;AAoIf,MAAM,WAAW,4BAA4B;IAC3C,aAAa,EAAE,CAAC,KAAK,EAAE,aAAa,KAAK,OAAO,CAAC;CAClD;AA0SD,eAAO,MAAM,sBAAsB,wFAAsD,CAAC"}
1
+ {"version":3,"file":"chat-input-resource-picker.d.ts","sourceRoot":"","sources":["../../../../../../src/material/components/ap-chat/components/input/chat-input-resource-picker.tsx"],"names":[],"mappings":"AAQA,OAAO,KASN,MAAM,OAAO,CAAC;AAiWf,MAAM,WAAW,4BAA4B;IAC3C,aAAa,EAAE,CAAC,KAAK,EAAE,aAAa,KAAK,OAAO,CAAC;CAClD;AAwJD,eAAO,MAAM,sBAAsB,wFAAsD,CAAC"}