@algolia/satellite 2.3.0-rc.1 → 2.3.0-rc.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (28) hide show
  1. package/dist/cjs/Helpers/ShimmerText/ShimmerText.tailwind.js +1 -1
  2. package/dist/cjs/Layout/Chat/ChatContextAccordion/ChatContextAccordion.styles.d.ts +3 -3
  3. package/dist/cjs/Layout/Chat/ChatMessage/ChatMessage.styles.js +7 -1
  4. package/dist/cjs/Layout/Chat/ChatMessageLoader/ChatMessageLoader.styles.js +1 -1
  5. package/dist/cjs/Layout/Chat/ChatMessages/ChatMessages.d.ts +6 -4
  6. package/dist/cjs/Layout/Chat/ChatMessages/ChatMessages.js +44 -16
  7. package/dist/cjs/Layout/Chat/ChatMessages/useLastMessageHeight.d.ts +2 -4
  8. package/dist/cjs/Layout/Chat/ChatMessages/useLastMessageHeight.js +15 -14
  9. package/dist/cjs/Layout/Chat/ChatPrompt/ChatPrompt.d.ts +19 -11
  10. package/dist/cjs/Layout/Chat/ChatPrompt/ChatPrompt.js +7 -1
  11. package/dist/cjs/Layout/Chat/ChatPrompt/ChatPrompt.styles.js +1 -1
  12. package/dist/cjs/Layout/Chat/ChatPrompt/useFocusTyping.d.ts +12 -0
  13. package/dist/cjs/Layout/Chat/ChatPrompt/useFocusTyping.js +60 -0
  14. package/dist/esm/Helpers/ShimmerText/ShimmerText.tailwind.js +1 -1
  15. package/dist/esm/Layout/Chat/ChatContextAccordion/ChatContextAccordion.styles.d.ts +3 -3
  16. package/dist/esm/Layout/Chat/ChatMessage/ChatMessage.styles.js +7 -1
  17. package/dist/esm/Layout/Chat/ChatMessageLoader/ChatMessageLoader.styles.js +1 -1
  18. package/dist/esm/Layout/Chat/ChatMessages/ChatMessages.d.ts +6 -4
  19. package/dist/esm/Layout/Chat/ChatMessages/ChatMessages.js +45 -19
  20. package/dist/esm/Layout/Chat/ChatMessages/useLastMessageHeight.d.ts +2 -4
  21. package/dist/esm/Layout/Chat/ChatMessages/useLastMessageHeight.js +16 -15
  22. package/dist/esm/Layout/Chat/ChatPrompt/ChatPrompt.d.ts +19 -11
  23. package/dist/esm/Layout/Chat/ChatPrompt/ChatPrompt.js +7 -1
  24. package/dist/esm/Layout/Chat/ChatPrompt/ChatPrompt.styles.js +1 -1
  25. package/dist/esm/Layout/Chat/ChatPrompt/useFocusTyping.d.ts +12 -0
  26. package/dist/esm/Layout/Chat/ChatPrompt/useFocusTyping.js +54 -0
  27. package/dist/satellite.min.css +1 -1
  28. package/package.json +1 -1
@@ -14,7 +14,7 @@ var shimmerTextPlugin = plugin(function (_ref) {
14
14
  "animation-duration": "3s",
15
15
  "animation-iteration-count": "infinite",
16
16
  "animation-name": "shimmer-text",
17
- background: "".concat(theme("colors.grey.900"), " linear-gradient(to right, ").concat(theme("colors.grey.900"), " 0%, #ffffffbf 40%, #ffffffbf 60%, ").concat(theme("colors.grey.900"), " 100%)"),
17
+ background: "".concat(theme("colors.grey.600"), " linear-gradient(to right, ").concat(theme("colors.grey.600"), " 0%, #ffffffbf 40%, #ffffffbf 60%, ").concat(theme("colors.grey.600"), " 100%)"),
18
18
  "-webkit-background-clip": "text",
19
19
  "background-clip": "text",
20
20
  "background-repeat": "no-repeat",
@@ -6,8 +6,8 @@ export declare const chatContextAccordionStyles: import("tailwind-variants").TVR
6
6
  title?: import("tailwind-merge").ClassNameValue;
7
7
  content?: import("tailwind-merge").ClassNameValue;
8
8
  item?: import("tailwind-merge").ClassNameValue;
9
- trigger?: import("tailwind-merge").ClassNameValue;
10
9
  iconBg?: import("tailwind-merge").ClassNameValue;
10
+ trigger?: import("tailwind-merge").ClassNameValue;
11
11
  titleWrapper?: import("tailwind-merge").ClassNameValue;
12
12
  };
13
13
  };
@@ -19,8 +19,8 @@ export declare const chatContextAccordionStyles: import("tailwind-variants").TVR
19
19
  title?: import("tailwind-merge").ClassNameValue;
20
20
  content?: import("tailwind-merge").ClassNameValue;
21
21
  item?: import("tailwind-merge").ClassNameValue;
22
- trigger?: import("tailwind-merge").ClassNameValue;
23
22
  iconBg?: import("tailwind-merge").ClassNameValue;
23
+ trigger?: import("tailwind-merge").ClassNameValue;
24
24
  titleWrapper?: import("tailwind-merge").ClassNameValue;
25
25
  };
26
26
  };
@@ -41,8 +41,8 @@ export declare const chatContextAccordionStyles: import("tailwind-variants").TVR
41
41
  title?: import("tailwind-merge").ClassNameValue;
42
42
  content?: import("tailwind-merge").ClassNameValue;
43
43
  item?: import("tailwind-merge").ClassNameValue;
44
- trigger?: import("tailwind-merge").ClassNameValue;
45
44
  iconBg?: import("tailwind-merge").ClassNameValue;
45
+ trigger?: import("tailwind-merge").ClassNameValue;
46
46
  titleWrapper?: import("tailwind-merge").ClassNameValue;
47
47
  };
48
48
  };
@@ -8,7 +8,7 @@ exports.chatMessageStyles = void 0;
8
8
  var _taggedTemplateLiteral2 = _interopRequireDefault(require("@babel/runtime/helpers/taggedTemplateLiteral"));
9
9
  var _satellitePrefixer = _interopRequireDefault(require("./../../../styles/helpers/satellitePrefixer"));
10
10
  var _tv = require("./../../../styles/helpers/tv");
11
- var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6, _templateObject7, _templateObject8, _templateObject9, _templateObject10, _templateObject11, _templateObject12, _templateObject13, _templateObject14, _templateObject15, _templateObject16, _templateObject17;
11
+ var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6, _templateObject7, _templateObject8, _templateObject9, _templateObject10, _templateObject11, _templateObject12, _templateObject13, _templateObject14, _templateObject15, _templateObject16, _templateObject17, _templateObject18;
12
12
  var chatMessageStyles = exports.chatMessageStyles = (0, _tv.tv)({
13
13
  slots: {
14
14
  base: (0, _satellitePrefixer["default"])(_templateObject || (_templateObject = (0, _taggedTemplateLiteral2["default"])(["relative w-full scroll-mt-4 group/message"]))),
@@ -63,6 +63,12 @@ var chatMessageStyles = exports.chatMessageStyles = (0, _tv.tv)({
63
63
  className: {
64
64
  actions: (0, _satellitePrefixer["default"])(_templateObject17 || (_templateObject17 = (0, _taggedTemplateLiteral2["default"])(["opacity-0 group-hover/message:opacity-100 transition-opacity"])))
65
65
  }
66
+ }, {
67
+ actions: true,
68
+ side: "right",
69
+ className: {
70
+ actions: (0, _satellitePrefixer["default"])(_templateObject18 || (_templateObject18 = (0, _taggedTemplateLiteral2["default"])(["justify-end"])))
71
+ }
66
72
  }],
67
73
  defaultVariants: {
68
74
  variant: "subtle",
@@ -14,7 +14,7 @@ var chatMessageLoaderStyles = exports.chatMessageLoaderStyles = (0, _tv.tv)({
14
14
  extend: _ChatMessage.chatMessageStyles,
15
15
  slots: {
16
16
  content: (0, _satellitePrefixer["default"])(_templateObject || (_templateObject = (0, _taggedTemplateLiteral2["default"])(["w-full"]))),
17
- message: (0, _satellitePrefixer["default"])(_templateObject2 || (_templateObject2 = (0, _taggedTemplateLiteral2["default"])(["flex flex-col gap-2 typo-subdued"]))),
17
+ message: (0, _satellitePrefixer["default"])(_templateObject2 || (_templateObject2 = (0, _taggedTemplateLiteral2["default"])(["flex flex-col gap-2"]))),
18
18
  skeletonWrapper: (0, _satellitePrefixer["default"])(_templateObject3 || (_templateObject3 = (0, _taggedTemplateLiteral2["default"])(["flex flex-col gap-1"]))),
19
19
  skeleton: (0, _satellitePrefixer["default"])(_templateObject4 || (_templateObject4 = (0, _taggedTemplateLiteral2["default"])(["h-4"])))
20
20
  }
@@ -6,10 +6,11 @@ import type { ChatMessageBase, ChatStatus } from "../../../Layout/Chat/types";
6
6
  export declare type ChatMessageLocale = {
7
7
  scrollToBottomText?: string;
8
8
  };
9
+ declare type ChatMessageWithoutContent<Message extends ChatMessageBase> = Omit<ChatMessageProps<Message>, "content">;
9
10
  export declare type ChatMessagesProps<Message extends ChatMessageBase = ChatMessageBase> = Omit<HTMLAttributes<HTMLDivElement>, "children"> & {
10
11
  messages: Message[];
11
- userMessageProps?: Omit<ChatMessageProps<Message>, "content">;
12
- assistantMessageProps?: Omit<ChatMessageProps<Message>, "content">;
12
+ userMessageProps?: ChatMessageWithoutContent<Message> | ((message: Message) => ChatMessageWithoutContent<Message>);
13
+ assistantMessageProps?: ChatMessageWithoutContent<Message> | ((message: Message) => ChatMessageWithoutContent<Message>);
13
14
  loaderProps?: ChatMessageLoaderProps;
14
15
  errorProps?: Omit<ChatMessageErrorProps, "onReload">;
15
16
  renderMessage?: (message: Message) => ReactNode;
@@ -24,8 +25,8 @@ export declare type ChatMessagesProps<Message extends ChatMessageBase = ChatMess
24
25
  };
25
26
  export declare const ChatMessages: <Message extends ChatMessageBase = ChatMessageBase>(props: Omit<HTMLAttributes<HTMLDivElement>, "children"> & {
26
27
  messages: Message[];
27
- userMessageProps?: Omit<ChatMessageProps<Message>, "content"> | undefined;
28
- assistantMessageProps?: Omit<ChatMessageProps<Message>, "content"> | undefined;
28
+ userMessageProps?: ChatMessageWithoutContent<Message> | ((message: Message) => ChatMessageWithoutContent<Message>) | undefined;
29
+ assistantMessageProps?: ChatMessageWithoutContent<Message> | ((message: Message) => ChatMessageWithoutContent<Message>) | undefined;
29
30
  loaderProps?: ChatMessageLoaderProps | undefined;
30
31
  errorProps?: Omit<ChatMessageErrorProps, "onReload"> | undefined;
31
32
  renderMessage?: ((message: Message) => ReactNode) | undefined;
@@ -40,3 +41,4 @@ export declare const ChatMessages: <Message extends ChatMessageBase = ChatMessag
40
41
  } & {
41
42
  ref?: Ref<HTMLDivElement> | undefined;
42
43
  }) => ReactElement | null;
44
+ export {};
@@ -26,6 +26,12 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
26
26
  var DEFAULT_CHAT_MESSAGE_LOCALE = {
27
27
  scrollToBottomText: "Scroll to bottom"
28
28
  };
29
+ function resolveProps(propsOrFn, message) {
30
+ if (typeof propsOrFn === "function") {
31
+ return propsOrFn(message);
32
+ }
33
+ return propsOrFn;
34
+ }
29
35
  var ChatMessagesBase = function ChatMessagesBase(_ref, forwardedRef) {
30
36
  var messages = _ref.messages,
31
37
  userMessageProps = _ref.userMessageProps,
@@ -47,15 +53,16 @@ var ChatMessagesBase = function ChatMessagesBase(_ref, forwardedRef) {
47
53
  var contextLocale = (0, _Satellite.useLocale)("chatMessage");
48
54
  var locale = _objectSpread(_objectSpread(_objectSpread({}, DEFAULT_CHAT_MESSAGE_LOCALE), contextLocale), propsLocale);
49
55
  var _useStickToBottom = (0, _useStickToBottom2.useStickToBottom)({
50
- resize: "smooth",
51
- initial: "smooth"
56
+ // @ts-expect-error - Types are wrong in use-stick-to-bottom
57
+ initial: "instant",
58
+ resize: "smooth"
52
59
  }),
53
60
  scrollRef = _useStickToBottom.scrollRef,
54
61
  contentRef = _useStickToBottom.contentRef,
55
62
  isAtBottom = _useStickToBottom.isAtBottom,
56
63
  scrollToBottom = _useStickToBottom.scrollToBottom;
57
64
  var styles = (0, _ChatMessages.chatMessagesStyles)();
58
- var messageRefs = (0, _react.useRef)(new Map());
65
+ var lastUserMessageRef = (0, _react.useRef)(null);
59
66
  var _useState = (0, _react.useState)(false),
60
67
  _useState2 = (0, _slicedToArray2["default"])(_useState, 2),
61
68
  lastMessageSubmitted = _useState2[0],
@@ -63,19 +70,41 @@ var ChatMessagesBase = function ChatMessagesBase(_ref, forwardedRef) {
63
70
  var lastUserMessage = (0, _toConsumableArray2["default"])(messages).reverse().find(function (m) {
64
71
  return m.role === "user";
65
72
  });
66
- var lastUserMessageEl = lastUserMessage ? messageRefs.current.get(lastUserMessage.id) : undefined;
67
- var lastMessageHeight = (0, _useLastMessageHeight.useLastMessageHeight)(scrollRef, messages, lastUserMessageEl, lastMessageSubmitted, 24);
73
+ var lastMessageHeight = (0, _useLastMessageHeight.useLastMessageHeight)(scrollRef, lastUserMessageRef, messages, lastMessageSubmitted, 24);
74
+ var lastMessageId = (0, _react.useMemo)(function () {
75
+ var _messages;
76
+ return (_messages = messages[messages.length - 1]) === null || _messages === void 0 ? void 0 : _messages.id;
77
+ }, [messages]);
78
+ var getMessageProps = (0, _react.useCallback)(function (message) {
79
+ var propsResult;
80
+ if (message.role === "assistant") {
81
+ propsResult = resolveProps(assistantMessageProps, message);
82
+
83
+ // If the last assistant message is streaming, we don't want to render actions or footer
84
+ if (status === "streaming" && lastMessageId === message.id) {
85
+ propsResult = _objectSpread(_objectSpread({}, propsResult), {}, {
86
+ renderFooter: undefined,
87
+ renderActions: undefined,
88
+ actions: undefined
89
+ });
90
+ }
91
+ } else {
92
+ propsResult = resolveProps(userMessageProps, message);
93
+ }
94
+ return propsResult;
95
+ }, [assistantMessageProps, userMessageProps, status, lastMessageId]);
68
96
  (0, _react.useEffect)(function () {
69
- if (status !== "submitted" || !lastUserMessage) {
70
- return;
97
+ if (status === "submitted" && lastUserMessage) {
98
+ setLastMessageSubmitted(true);
71
99
  }
72
- setLastMessageSubmitted(true);
73
- }, [status, messages, lastUserMessage]);
100
+ }, [status, lastUserMessage]);
74
101
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", _objectSpread(_objectSpread({}, props), {}, {
75
102
  ref: forwardedRef,
76
103
  className: styles.base({
77
104
  className: className
78
105
  }),
106
+ role: "log",
107
+ "aria-live": "polite",
79
108
  children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
80
109
  ref: scrollRef,
81
110
  className: styles.scroll({
@@ -91,16 +120,15 @@ var ChatMessagesBase = function ChatMessagesBase(_ref, forwardedRef) {
91
120
  },
92
121
  children: [messages.map(function (message) {
93
122
  var isAssistant = message.role === "assistant";
123
+ var isLastUserMessage = (lastUserMessage === null || lastUserMessage === void 0 ? void 0 : lastUserMessage.id) === message.id;
94
124
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_ChatMessage.ChatMessage, _objectSpread(_objectSpread({
95
- ref: function ref(el) {
96
- if (el) messageRefs.current.set(message.id, el);else messageRefs.current["delete"](message.id);
97
- },
125
+ ref: isLastUserMessage ? lastUserMessageRef : undefined,
98
126
  side: isAssistant ? "left" : "right",
99
- variant: isAssistant ? "subtle" : "neutral",
100
- content: renderMessage ? renderMessage(message) : message.content
101
- }, isAssistant ? assistantMessageProps : userMessageProps), {}, {
102
- "data-role": message.role,
127
+ variant: isAssistant ? "subtle" : "neutral"
128
+ }, getMessageProps(message)), {}, {
129
+ content: renderMessage ? renderMessage(message) : message.content,
103
130
  actionsExtraData: message,
131
+ "data-role": message.role,
104
132
  "data-key": message.id
105
133
  }), message.id);
106
134
  }), status === "submitted" && (renderLoader !== null && renderLoader !== void 0 ? renderLoader : /*#__PURE__*/(0, _jsxRuntime.jsx)(_ChatMessageLoader.ChatMessageLoader, _objectSpread({}, loaderProps))), status === "error" && (renderError !== null && renderError !== void 0 ? renderError : /*#__PURE__*/(0, _jsxRuntime.jsx)(_ChatMessageError.ChatMessageError, _objectSpread(_objectSpread({}, errorProps), {}, {
@@ -1,10 +1,8 @@
1
1
  import type { RefObject } from "react";
2
+ import type { ChatMessageBase } from "../../../Layout/Chat/types";
2
3
  /**
3
4
  * React hook to compute the “fill” height below the last user message,
4
5
  * based on the scroll container’s height, the last user‐message element’s height,
5
6
  * and any CSS gap/padding offsets.
6
7
  */
7
- export declare function useLastMessageHeight(scrollRef: RefObject<HTMLElement>, messages: Array<{
8
- id: string;
9
- role: string;
10
- }>, lastUserMessageEl: HTMLElement | undefined, lastMessageSubmitted: boolean, spacingOffset?: number): number;
8
+ export declare function useLastMessageHeight(scrollRef: RefObject<HTMLElement>, lastUserMessageRef: RefObject<HTMLDivElement | null>, messages: ChatMessageBase[], lastMessageSubmitted: boolean, spacingOffset?: number): number;
@@ -12,29 +12,30 @@ var _react = require("react");
12
12
  * based on the scroll container’s height, the last user‐message element’s height,
13
13
  * and any CSS gap/padding offsets.
14
14
  */
15
- function useLastMessageHeight(scrollRef, messages, lastUserMessageEl, lastMessageSubmitted) {
15
+ function useLastMessageHeight(scrollRef, lastUserMessageRef, messages, lastMessageSubmitted) {
16
16
  var spacingOffset = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 0;
17
17
  var _useState = (0, _react.useState)(0),
18
18
  _useState2 = (0, _slicedToArray2["default"])(_useState, 2),
19
19
  lastMessageHeight = _useState2[0],
20
20
  setLastMessageHeight = _useState2[1];
21
- var updateLastMessageHeight = function updateLastMessageHeight() {
22
- var scrollEl = scrollRef.current;
23
- if (!scrollEl || messages.length === 0 || !lastMessageSubmitted || !lastUserMessageEl) return;
24
-
25
- // Measure parent/container height
26
- var parentHeight = scrollEl.clientHeight;
21
+ var offsetsRef = (0, _react.useRef)(0);
22
+ function getStaticOffsets() {
23
+ if (offsetsRef.current || !scrollRef.current) return offsetsRef.current;
27
24
 
28
25
  // Compute any CSS gap/rowGap/padding offsets by reading computed style
29
- var computed = window.getComputedStyle(scrollEl);
26
+ var computed = window.getComputedStyle(scrollRef.current);
30
27
  var rowGapValue = parseFloat(computed.rowGap) || parseFloat(computed.gap) || 0;
31
28
  var paddingTop = parseFloat(computed.paddingTop) || 0;
32
29
  var paddingBottom = parseFloat(computed.paddingBottom) || 0;
33
- var totalOffset = spacingOffset + rowGapValue + paddingTop + paddingBottom;
34
-
35
- // The “remaining” height is parentHeight − lastMsgElem.offsetHeight − totalOffset
36
- var remaining = parentHeight - lastUserMessageEl.offsetHeight - totalOffset;
37
- setLastMessageHeight(Math.max(remaining, 0));
30
+ offsetsRef.current = spacingOffset + rowGapValue + paddingTop + paddingBottom;
31
+ return offsetsRef.current;
32
+ }
33
+ var updateLastMessageHeight = function updateLastMessageHeight() {
34
+ var scrollEl = scrollRef.current;
35
+ var lastUserMessageEl = lastUserMessageRef.current;
36
+ if (!scrollEl || messages.length === 0 || !lastMessageSubmitted || !lastUserMessageEl) return;
37
+ var height = Math.max(scrollEl.clientHeight - lastUserMessageEl.offsetHeight - getStaticOffsets(), 0);
38
+ setLastMessageHeight(height);
38
39
  };
39
40
 
40
41
  // Recompute whenever messages change and a new user message has just been submitted
@@ -42,6 +43,6 @@ function useLastMessageHeight(scrollRef, messages, lastUserMessageEl, lastMessag
42
43
  if (!lastMessageSubmitted) return;
43
44
  updateLastMessageHeight();
44
45
  // eslint-disable-next-line react-hooks/exhaustive-deps
45
- }, [messages, lastMessageSubmitted]);
46
+ }, [messages.length, lastMessageSubmitted]);
46
47
  return lastMessageHeight;
47
48
  }
@@ -1,5 +1,5 @@
1
1
  import type { FormEvent, KeyboardEvent, ReactNode } from "react";
2
- import type { TextAreaProps } from "../../../Fields";
2
+ import type { TextAreaAutoSizeProps } from "../../../Fields/TextAreaAutoSize/TextAreaAutoSize";
3
3
  import type { ChatStatus } from "../../../Layout/Chat/types";
4
4
  export declare type ChatPromptLocale = {
5
5
  textareaLabel?: string;
@@ -7,7 +7,7 @@ export declare type ChatPromptLocale = {
7
7
  stopResponseTooltip?: string;
8
8
  sendMessageTooltip?: string;
9
9
  };
10
- export declare type ChatPromptProps = Omit<TextAreaProps, "onSubmit"> & {
10
+ export declare type ChatPromptProps = Omit<TextAreaAutoSizeProps, "onSubmit"> & {
11
11
  /**
12
12
  * Content to render above the textarea (e.g., a title or instructions).
13
13
  */
@@ -30,6 +30,14 @@ export declare type ChatPromptProps = Omit<TextAreaProps, "onSubmit"> & {
30
30
  * - "error": An error occurred during the API request, preventing successful completion.
31
31
  */
32
32
  status?: ChatStatus;
33
+ /**
34
+ * Whether to automatically focus the textarea when the user starts typing.
35
+ */
36
+ autoFocusOnTyping?: boolean;
37
+ /**
38
+ * Optional locale.
39
+ */
40
+ locale?: ChatPromptLocale;
33
41
  /**
34
42
  * Callback invoked when the user submits the form, either by clicking
35
43
  * the submit button or pressing Enter (without Shift) inside the textarea.
@@ -39,12 +47,8 @@ export declare type ChatPromptProps = Omit<TextAreaProps, "onSubmit"> & {
39
47
  * Callback invoked when the user requests to stop the current chat response stream.
40
48
  */
41
49
  onStop?: () => void;
42
- /**
43
- * Optional locale.
44
- */
45
- locale?: ChatPromptLocale;
46
50
  };
47
- export declare const ChatPrompt: import("react").ForwardRefExoticComponent<Omit<TextAreaProps, "onSubmit"> & {
51
+ export declare const ChatPrompt: import("react").ForwardRefExoticComponent<Omit<TextAreaAutoSizeProps, "onSubmit"> & {
48
52
  /**
49
53
  * Content to render above the textarea (e.g., a title or instructions).
50
54
  */
@@ -67,6 +71,14 @@ export declare const ChatPrompt: import("react").ForwardRefExoticComponent<Omit<
67
71
  * - "error": An error occurred during the API request, preventing successful completion.
68
72
  */
69
73
  status?: ChatStatus | undefined;
74
+ /**
75
+ * Whether to automatically focus the textarea when the user starts typing.
76
+ */
77
+ autoFocusOnTyping?: boolean | undefined;
78
+ /**
79
+ * Optional locale.
80
+ */
81
+ locale?: ChatPromptLocale | undefined;
70
82
  /**
71
83
  * Callback invoked when the user submits the form, either by clicking
72
84
  * the submit button or pressing Enter (without Shift) inside the textarea.
@@ -76,8 +88,4 @@ export declare const ChatPrompt: import("react").ForwardRefExoticComponent<Omit<
76
88
  * Callback invoked when the user requests to stop the current chat response stream.
77
89
  */
78
90
  onStop?: (() => void) | undefined;
79
- /**
80
- * Optional locale.
81
- */
82
- locale?: ChatPromptLocale | undefined;
83
91
  } & import("react").RefAttributes<HTMLTextAreaElement>>;
@@ -11,13 +11,14 @@ var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/h
11
11
  var _lucideReact = require("lucide-react");
12
12
  var _react = require("react");
13
13
  var _ChatPrompt = require("./ChatPrompt.styles");
14
+ var _useFocusTyping = require("./useFocusTyping");
14
15
  var _useTypewriter = require("./useTypewriter");
15
16
  var _Actions = require("./../../../Actions");
16
17
  var _TextAreaAutoSize = require("./../../../Fields/TextAreaAutoSize/TextAreaAutoSize");
17
18
  var _Satellite = require("./../../../Satellite");
18
19
  var _mergeRefs = require("./../../../utils/mergeRefs");
19
20
  var _jsxRuntime = require("react/jsx-runtime");
20
- var _excluded = ["className", "renderHeader", "children", "renderFooter", "onSubmit", "onStop", "placeholder", "placeholders", "status", "defaultValue", "value", "locale"];
21
+ var _excluded = ["className", "renderHeader", "children", "renderFooter", "onSubmit", "onStop", "placeholder", "placeholders", "status", "autoFocusOnTyping", "defaultValue", "value", "locale"];
21
22
  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; }
22
23
  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; }
23
24
  var DEFAULT_CHAT_PROMPT_LOCALE = {
@@ -39,6 +40,7 @@ var ChatPrompt = exports.ChatPrompt = /*#__PURE__*/(0, _react.forwardRef)(functi
39
40
  placeholders = _ref$placeholders === void 0 ? [] : _ref$placeholders,
40
41
  _ref$status = _ref.status,
41
42
  status = _ref$status === void 0 ? "ready" : _ref$status,
43
+ autoFocusOnTyping = _ref.autoFocusOnTyping,
42
44
  defaultValue = _ref.defaultValue,
43
45
  valueProp = _ref.value,
44
46
  propsLocale = _ref.locale,
@@ -58,6 +60,10 @@ var ChatPrompt = exports.ChatPrompt = /*#__PURE__*/(0, _react.forwardRef)(functi
58
60
  var buttonDisabled = !hasValue && !canStop;
59
61
  var dynamicPlaceholder = (0, _useTypewriter.useTypewriter)(placeholders, !hasValue);
60
62
  var computedPlaceholder = placeholders.length > 0 ? dynamicPlaceholder : staticPlaceholder;
63
+ (0, _useFocusTyping.useFocusOnTyping)(internalRef, {
64
+ enabled: autoFocusOnTyping,
65
+ strictChars: true
66
+ });
61
67
  var submit = function submit(e) {
62
68
  e.preventDefault();
63
69
  if (!hasValue || canStop) {
@@ -15,7 +15,7 @@ var chatPromptStyles = exports.chatPromptStyles = (0, _tv.tv)({
15
15
  header: (0, _satellitePrefixer["default"])(_templateObject2 || (_templateObject2 = (0, _taggedTemplateLiteral2["default"])(["flex items-center gap-1.5"]))),
16
16
  body: (0, _satellitePrefixer["default"])(_templateObject3 || (_templateObject3 = (0, _taggedTemplateLiteral2["default"])([""]))),
17
17
  textarea: (0, _satellitePrefixer["default"])(_templateObject4 || (_templateObject4 = (0, _taggedTemplateLiteral2["default"])(["[&>textarea]:p-3 [&>textarea]:pb-0 [&>textarea]:thin-scrollbar"]))),
18
- actions: (0, _satellitePrefixer["default"])(_templateObject5 || (_templateObject5 = (0, _taggedTemplateLiteral2["default"])(["flex flex-row p-3 pt-2 justify-end"]))),
18
+ actions: (0, _satellitePrefixer["default"])(_templateObject5 || (_templateObject5 = (0, _taggedTemplateLiteral2["default"])(["flex flex-row p-3 pt-2 justify-end cursor-text"]))),
19
19
  submit: (0, _satellitePrefixer["default"])(_templateObject6 || (_templateObject6 = (0, _taggedTemplateLiteral2["default"])([""]))),
20
20
  footer: (0, _satellitePrefixer["default"])(_templateObject7 || (_templateObject7 = (0, _taggedTemplateLiteral2["default"])(["flex items-center justify-between gap-1.5"])))
21
21
  }
@@ -0,0 +1,12 @@
1
+ /// <reference types="react" />
2
+ declare type Editable = HTMLTextAreaElement | HTMLInputElement | HTMLElement;
3
+ interface Options {
4
+ enabled?: boolean;
5
+ strictChars?: boolean;
6
+ }
7
+ /**
8
+ * Focus `editableRef` the moment the user types anywhere on the page,
9
+ * *unless* their cursor is already inside an editable control.
10
+ */
11
+ export declare function useFocusOnTyping<E extends Editable = Editable>(editableRef: React.RefObject<E>, { enabled, strictChars }?: Options): void;
12
+ export {};
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useFocusOnTyping = useFocusOnTyping;
7
+ var _react = require("react");
8
+ var isTextualElement = function isTextualElement(el) {
9
+ if (el.isContentEditable) return true;
10
+ var tag = el.tagName.toUpperCase();
11
+ if (tag === "TEXTAREA") return true;
12
+ if (tag === "INPUT") {
13
+ // Empty `type` defaults to "text"
14
+ var t = (el.type || "text").toLowerCase();
15
+ return ["text", "search", "url", "email", "tel", "password", "number", "date", "datetime-local", "month", "week", "time"].includes(t);
16
+ }
17
+ return false;
18
+ };
19
+ var shouldFocusEditable = function shouldFocusEditable(target) {
20
+ var el = target;
21
+ if (!el) return true;
22
+ return !isTextualElement(el);
23
+ };
24
+
25
+ // e.g. <div contentEditable>
26
+
27
+ /**
28
+ * Focus `editableRef` the moment the user types anywhere on the page,
29
+ * *unless* their cursor is already inside an editable control.
30
+ */
31
+ function useFocusOnTyping(editableRef) {
32
+ var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
33
+ _ref$enabled = _ref.enabled,
34
+ enabled = _ref$enabled === void 0 ? true : _ref$enabled,
35
+ _ref$strictChars = _ref.strictChars,
36
+ strictChars = _ref$strictChars === void 0 ? false : _ref$strictChars;
37
+ var handleKeyDown = (0, _react.useCallback)(function (e) {
38
+ if (!enabled || e.ctrlKey || e.altKey || e.metaKey || e.isComposing || e.repeat || (
39
+ // Printable-character test
40
+ strictChars ? !/^[A-Za-z0-9]$/.test(e.key) : e.key.length !== 1)) {
41
+ return;
42
+ }
43
+ var node = editableRef.current;
44
+ if (!node) return;
45
+ if (node.contains(document.activeElement)) return;
46
+ if (shouldFocusEditable(e.target)) {
47
+ node.focus();
48
+ }
49
+ }, [enabled, strictChars, editableRef]);
50
+ (0, _react.useEffect)(function () {
51
+ if (typeof window === "undefined") return; // SSR/test guard
52
+
53
+ window.addEventListener("keydown", handleKeyDown, {
54
+ passive: true
55
+ });
56
+ return function () {
57
+ return window.removeEventListener("keydown", handleKeyDown);
58
+ };
59
+ }, [handleKeyDown]);
60
+ }
@@ -13,7 +13,7 @@ var shimmerTextPlugin = plugin(function (_ref) {
13
13
  "animation-duration": "3s",
14
14
  "animation-iteration-count": "infinite",
15
15
  "animation-name": "shimmer-text",
16
- background: "".concat(theme("colors.grey.900"), " linear-gradient(to right, ").concat(theme("colors.grey.900"), " 0%, #ffffffbf 40%, #ffffffbf 60%, ").concat(theme("colors.grey.900"), " 100%)"),
16
+ background: "".concat(theme("colors.grey.600"), " linear-gradient(to right, ").concat(theme("colors.grey.600"), " 0%, #ffffffbf 40%, #ffffffbf 60%, ").concat(theme("colors.grey.600"), " 100%)"),
17
17
  "-webkit-background-clip": "text",
18
18
  "background-clip": "text",
19
19
  "background-repeat": "no-repeat",
@@ -6,8 +6,8 @@ export declare const chatContextAccordionStyles: import("tailwind-variants").TVR
6
6
  title?: import("tailwind-merge").ClassNameValue;
7
7
  content?: import("tailwind-merge").ClassNameValue;
8
8
  item?: import("tailwind-merge").ClassNameValue;
9
- trigger?: import("tailwind-merge").ClassNameValue;
10
9
  iconBg?: import("tailwind-merge").ClassNameValue;
10
+ trigger?: import("tailwind-merge").ClassNameValue;
11
11
  titleWrapper?: import("tailwind-merge").ClassNameValue;
12
12
  };
13
13
  };
@@ -19,8 +19,8 @@ export declare const chatContextAccordionStyles: import("tailwind-variants").TVR
19
19
  title?: import("tailwind-merge").ClassNameValue;
20
20
  content?: import("tailwind-merge").ClassNameValue;
21
21
  item?: import("tailwind-merge").ClassNameValue;
22
- trigger?: import("tailwind-merge").ClassNameValue;
23
22
  iconBg?: import("tailwind-merge").ClassNameValue;
23
+ trigger?: import("tailwind-merge").ClassNameValue;
24
24
  titleWrapper?: import("tailwind-merge").ClassNameValue;
25
25
  };
26
26
  };
@@ -41,8 +41,8 @@ export declare const chatContextAccordionStyles: import("tailwind-variants").TVR
41
41
  title?: import("tailwind-merge").ClassNameValue;
42
42
  content?: import("tailwind-merge").ClassNameValue;
43
43
  item?: import("tailwind-merge").ClassNameValue;
44
- trigger?: import("tailwind-merge").ClassNameValue;
45
44
  iconBg?: import("tailwind-merge").ClassNameValue;
45
+ trigger?: import("tailwind-merge").ClassNameValue;
46
46
  titleWrapper?: import("tailwind-merge").ClassNameValue;
47
47
  };
48
48
  };
@@ -1,5 +1,5 @@
1
1
  import _taggedTemplateLiteral from "@babel/runtime/helpers/taggedTemplateLiteral";
2
- var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6, _templateObject7, _templateObject8, _templateObject9, _templateObject10, _templateObject11, _templateObject12, _templateObject13, _templateObject14, _templateObject15, _templateObject16, _templateObject17;
2
+ var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6, _templateObject7, _templateObject8, _templateObject9, _templateObject10, _templateObject11, _templateObject12, _templateObject13, _templateObject14, _templateObject15, _templateObject16, _templateObject17, _templateObject18;
3
3
  import stl from "./../../../styles/helpers/satellitePrefixer";
4
4
  import { tv } from "./../../../styles/helpers/tv";
5
5
  export var chatMessageStyles = tv({
@@ -56,6 +56,12 @@ export var chatMessageStyles = tv({
56
56
  className: {
57
57
  actions: stl(_templateObject17 || (_templateObject17 = _taggedTemplateLiteral(["opacity-0 group-hover/message:opacity-100 transition-opacity"])))
58
58
  }
59
+ }, {
60
+ actions: true,
61
+ side: "right",
62
+ className: {
63
+ actions: stl(_templateObject18 || (_templateObject18 = _taggedTemplateLiteral(["justify-end"])))
64
+ }
59
65
  }],
60
66
  defaultVariants: {
61
67
  variant: "subtle",
@@ -7,7 +7,7 @@ export var chatMessageLoaderStyles = tv({
7
7
  extend: chatMessageStyles,
8
8
  slots: {
9
9
  content: stl(_templateObject || (_templateObject = _taggedTemplateLiteral(["w-full"]))),
10
- message: stl(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["flex flex-col gap-2 typo-subdued"]))),
10
+ message: stl(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["flex flex-col gap-2"]))),
11
11
  skeletonWrapper: stl(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["flex flex-col gap-1"]))),
12
12
  skeleton: stl(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["h-4"])))
13
13
  }
@@ -6,10 +6,11 @@ import type { ChatMessageBase, ChatStatus } from "../../../Layout/Chat/types";
6
6
  export declare type ChatMessageLocale = {
7
7
  scrollToBottomText?: string;
8
8
  };
9
+ declare type ChatMessageWithoutContent<Message extends ChatMessageBase> = Omit<ChatMessageProps<Message>, "content">;
9
10
  export declare type ChatMessagesProps<Message extends ChatMessageBase = ChatMessageBase> = Omit<HTMLAttributes<HTMLDivElement>, "children"> & {
10
11
  messages: Message[];
11
- userMessageProps?: Omit<ChatMessageProps<Message>, "content">;
12
- assistantMessageProps?: Omit<ChatMessageProps<Message>, "content">;
12
+ userMessageProps?: ChatMessageWithoutContent<Message> | ((message: Message) => ChatMessageWithoutContent<Message>);
13
+ assistantMessageProps?: ChatMessageWithoutContent<Message> | ((message: Message) => ChatMessageWithoutContent<Message>);
13
14
  loaderProps?: ChatMessageLoaderProps;
14
15
  errorProps?: Omit<ChatMessageErrorProps, "onReload">;
15
16
  renderMessage?: (message: Message) => ReactNode;
@@ -24,8 +25,8 @@ export declare type ChatMessagesProps<Message extends ChatMessageBase = ChatMess
24
25
  };
25
26
  export declare const ChatMessages: <Message extends ChatMessageBase = ChatMessageBase>(props: Omit<HTMLAttributes<HTMLDivElement>, "children"> & {
26
27
  messages: Message[];
27
- userMessageProps?: Omit<ChatMessageProps<Message>, "content"> | undefined;
28
- assistantMessageProps?: Omit<ChatMessageProps<Message>, "content"> | undefined;
28
+ userMessageProps?: ChatMessageWithoutContent<Message> | ((message: Message) => ChatMessageWithoutContent<Message>) | undefined;
29
+ assistantMessageProps?: ChatMessageWithoutContent<Message> | ((message: Message) => ChatMessageWithoutContent<Message>) | undefined;
29
30
  loaderProps?: ChatMessageLoaderProps | undefined;
30
31
  errorProps?: Omit<ChatMessageErrorProps, "onReload"> | undefined;
31
32
  renderMessage?: ((message: Message) => ReactNode) | undefined;
@@ -40,3 +41,4 @@ export declare const ChatMessages: <Message extends ChatMessageBase = ChatMessag
40
41
  } & {
41
42
  ref?: Ref<HTMLDivElement> | undefined;
42
43
  }) => ReactElement | null;
44
+ export {};