@algolia/satellite 2.2.3 → 2.3.0-rc.10
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/Actions/Accordion/Accordion.d.ts +8 -0
- package/dist/cjs/Actions/Accordion/Accordion.js +5 -3
- package/dist/cjs/Actions/Button/PolymorphicButton.js +5 -5
- package/dist/cjs/Actions/Button/PolymorphicIconButton.js +2 -2
- package/dist/cjs/Actions/Button/styles.d.ts +1 -0
- package/dist/cjs/Actions/Button/styles.js +15 -10
- package/dist/cjs/Actions/ButtonLink/ButtonLink.d.ts +2 -0
- package/dist/cjs/Actions/ButtonLink/ButtonLink.js +4 -2
- package/dist/cjs/Actions/SegmentedControl/SegmentedControl.js +3 -2
- package/dist/cjs/Actions/SegmentedControl/SegmentedControlOption.js +6 -3
- package/dist/cjs/Actions/ToggleButton/ToggleButtonBase.js +3 -3
- package/dist/cjs/Actions/ToggleGroup/ToggleGroup.d.ts +13 -14
- package/dist/cjs/Chat/ChatContextAccordion/ChatContextAccordion.d.ts +23 -0
- package/dist/cjs/Chat/ChatContextAccordion/ChatContextAccordion.js +51 -0
- package/dist/cjs/Chat/ChatContextAccordion/ChatContextAccordion.styles.d.ts +86 -0
- package/dist/cjs/Chat/ChatContextAccordion/ChatContextAccordion.styles.js +23 -0
- package/dist/cjs/Chat/ChatContextAccordion/index.d.ts +1 -0
- package/dist/cjs/Chat/ChatContextAccordion/index.js +16 -0
- package/dist/cjs/Chat/ChatMessage/ChatMessage.d.ts +117 -0
- package/dist/cjs/Chat/ChatMessage/ChatMessage.js +92 -0
- package/dist/cjs/Chat/ChatMessage/ChatMessage.styles.d.ts +167 -0
- package/dist/cjs/Chat/ChatMessage/ChatMessage.styles.js +77 -0
- package/dist/cjs/Chat/ChatMessage/index.d.ts +1 -0
- package/dist/cjs/Chat/ChatMessage/index.js +16 -0
- package/dist/cjs/Chat/ChatMessageError/ChatMessageError.d.ts +62 -0
- package/dist/cjs/Chat/ChatMessageError/ChatMessageError.js +73 -0
- package/dist/cjs/Chat/ChatMessageError/ChatMessageError.styles.d.ts +253 -0
- package/dist/cjs/Chat/ChatMessageError/ChatMessageError.styles.js +18 -0
- package/dist/cjs/Chat/ChatMessageError/index.d.ts +1 -0
- package/dist/cjs/Chat/ChatMessageError/index.js +16 -0
- package/dist/cjs/Chat/ChatMessageLoader/ChatMessageLoader.d.ts +21 -0
- package/dist/cjs/Chat/ChatMessageLoader/ChatMessageLoader.js +68 -0
- package/dist/cjs/Chat/ChatMessageLoader/ChatMessageLoader.styles.d.ts +280 -0
- package/dist/cjs/Chat/ChatMessageLoader/ChatMessageLoader.styles.js +21 -0
- package/dist/cjs/Chat/ChatMessageLoader/index.d.ts +1 -0
- package/dist/cjs/Chat/ChatMessageLoader/index.js +16 -0
- package/dist/cjs/Chat/ChatMessages/ChatMessages.d.ts +141 -0
- package/dist/cjs/Chat/ChatMessages/ChatMessages.js +165 -0
- package/dist/cjs/Chat/ChatMessages/ChatMessages.styles.d.ts +69 -0
- package/dist/cjs/Chat/ChatMessages/ChatMessages.styles.js +29 -0
- package/dist/cjs/Chat/ChatMessages/index.d.ts +1 -0
- package/dist/cjs/Chat/ChatMessages/index.js +16 -0
- package/dist/cjs/Chat/ChatMessages/useLastMessageHeight.d.ts +14 -0
- package/dist/cjs/Chat/ChatMessages/useLastMessageHeight.js +54 -0
- package/dist/cjs/Chat/ChatPrompt/ChatPrompt.d.ts +105 -0
- package/dist/cjs/Chat/ChatPrompt/ChatPrompt.js +163 -0
- package/dist/cjs/Chat/ChatPrompt/ChatPrompt.styles.d.ts +63 -0
- package/dist/cjs/Chat/ChatPrompt/ChatPrompt.styles.js +29 -0
- package/dist/cjs/Chat/ChatPrompt/index.d.ts +1 -0
- package/dist/cjs/Chat/ChatPrompt/index.js +16 -0
- package/dist/cjs/Chat/ChatPrompt/useFocusTyping.d.ts +30 -0
- package/dist/cjs/Chat/ChatPrompt/useFocusTyping.js +65 -0
- package/dist/cjs/Chat/ChatPrompt/useTypewriter.d.ts +27 -0
- package/dist/cjs/Chat/ChatPrompt/useTypewriter.js +87 -0
- package/dist/cjs/Chat/index.d.ts +15 -0
- package/dist/cjs/Chat/index.js +47 -0
- package/dist/cjs/Chat/types.d.ts +7 -0
- package/dist/cjs/Chat/types.js +5 -0
- package/dist/cjs/Fields/Checkbox/Checkbox.d.ts +2 -2
- package/dist/cjs/Fields/Checkbox/Checkbox.js +2 -2
- package/dist/cjs/Fields/Dropzone/Dropzone.js +1 -1
- package/dist/cjs/Fields/Form/stories/Complex.js +123 -50
- package/dist/cjs/Fields/Input/Input.js +10 -13
- package/dist/cjs/Fields/RadioGroup/RadioButton.js +9 -2
- package/dist/cjs/Fields/RadioGroup/RadioButton.tailwind.js +1 -1
- package/dist/cjs/Fields/RadioGroup/RadioGroupContext.d.ts +2 -0
- package/dist/cjs/Fields/RadioGroup/RadioGroupItem.js +1 -1
- package/dist/cjs/Fields/Select/Select.tailwind.js +4 -3
- package/dist/cjs/Fields/SelectableCard/SelectableCard.d.ts +35 -0
- package/dist/cjs/Fields/SelectableCard/SelectableCard.js +105 -0
- package/dist/cjs/Fields/SelectableCard/SelectableCardContext.d.ts +13 -0
- package/dist/cjs/Fields/SelectableCard/SelectableCardContext.js +15 -0
- package/dist/cjs/Fields/SelectableCard/SelectableCardGroup.d.ts +13 -0
- package/dist/cjs/Fields/SelectableCard/SelectableCardGroup.js +55 -0
- package/dist/cjs/Fields/SelectableCard/index.d.ts +2 -0
- package/dist/cjs/Fields/SelectableCard/index.js +27 -0
- package/dist/cjs/Fields/Switch/Switch.js +1 -1
- package/dist/cjs/Fields/TextArea/TextArea.d.ts +5 -1
- package/dist/cjs/Fields/TextArea/TextArea.js +3 -2
- package/dist/cjs/Fields/TextArea/TextArea.tailwind.js +1 -1
- package/dist/cjs/Fields/TextAreaAutoSize/TextAreaAutoSize.d.ts +26 -0
- package/dist/cjs/Fields/TextAreaAutoSize/TextAreaAutoSize.js +82 -0
- package/dist/cjs/Fields/TextAreaAutoSize/TextAreaAutoSize.styles.d.ts +37 -0
- package/dist/cjs/Fields/TextAreaAutoSize/TextAreaAutoSize.styles.js +16 -0
- package/dist/cjs/Fields/TextAreaAutoSize/index.d.ts +2 -0
- package/dist/cjs/Fields/TextAreaAutoSize/index.js +12 -0
- package/dist/cjs/Fields/index.d.ts +3 -1
- package/dist/cjs/Fields/index.js +26 -4
- package/dist/cjs/Helpers/ShimmerText/ShimmerText.d.ts +3 -0
- package/dist/cjs/Helpers/ShimmerText/ShimmerText.js +28 -0
- package/dist/cjs/Helpers/ShimmerText/ShimmerText.tailwind.d.ts +5 -0
- package/dist/cjs/Helpers/ShimmerText/ShimmerText.tailwind.js +37 -0
- package/dist/cjs/Helpers/ShimmerText/index.d.ts +2 -0
- package/dist/cjs/Helpers/ShimmerText/index.js +12 -0
- package/dist/cjs/Helpers/index.d.ts +1 -0
- package/dist/cjs/Helpers/index.js +11 -0
- package/dist/cjs/Helpers/utilities/focusable.tailwind.js +1 -1
- package/dist/cjs/Helpers/utilities/utilities.tailwind.js +6 -1
- package/dist/cjs/Indicators/Skeleton/Skeleton.d.ts +2 -2
- package/dist/cjs/Navigation/Link/Link.d.ts +10 -0
- package/dist/cjs/Navigation/Link/Link.js +4 -2
- package/dist/cjs/Satellite/locale.d.ts +7 -1
- package/dist/cjs/index.d.ts +1 -0
- package/dist/cjs/index.js +12 -0
- package/dist/cjs/styles/helpers/tv.d.ts +5 -0
- package/dist/cjs/styles/helpers/tv.js +13 -0
- package/dist/cjs/styles/tailwind.config.js +1 -1
- package/dist/cjs/utils/getTextFromReactNode.d.ts +2 -1
- package/dist/cjs/utils/getTextFromReactNode.js +12 -7
- package/dist/esm/Actions/Accordion/Accordion.d.ts +8 -0
- package/dist/esm/Actions/Accordion/Accordion.js +5 -3
- package/dist/esm/Actions/Button/PolymorphicButton.js +6 -6
- package/dist/esm/Actions/Button/PolymorphicIconButton.js +2 -2
- package/dist/esm/Actions/Button/styles.d.ts +1 -0
- package/dist/esm/Actions/Button/styles.js +14 -9
- package/dist/esm/Actions/ButtonLink/ButtonLink.d.ts +2 -0
- package/dist/esm/Actions/ButtonLink/ButtonLink.js +4 -2
- package/dist/esm/Actions/SegmentedControl/SegmentedControl.js +3 -2
- package/dist/esm/Actions/SegmentedControl/SegmentedControlOption.js +6 -3
- package/dist/esm/Actions/ToggleButton/ToggleButtonBase.js +4 -4
- package/dist/esm/Actions/ToggleGroup/ToggleGroup.d.ts +13 -14
- package/dist/esm/Chat/ChatContextAccordion/ChatContextAccordion.d.ts +23 -0
- package/dist/esm/Chat/ChatContextAccordion/ChatContextAccordion.js +44 -0
- package/dist/esm/Chat/ChatContextAccordion/ChatContextAccordion.styles.d.ts +86 -0
- package/dist/esm/Chat/ChatContextAccordion/ChatContextAccordion.styles.js +16 -0
- package/dist/esm/Chat/ChatContextAccordion/index.d.ts +1 -0
- package/dist/esm/Chat/ChatContextAccordion/index.js +1 -0
- package/dist/esm/Chat/ChatMessage/ChatMessage.d.ts +117 -0
- package/dist/esm/Chat/ChatMessage/ChatMessage.js +86 -0
- package/dist/esm/Chat/ChatMessage/ChatMessage.styles.d.ts +167 -0
- package/dist/esm/Chat/ChatMessage/ChatMessage.styles.js +70 -0
- package/dist/esm/Chat/ChatMessage/index.d.ts +1 -0
- package/dist/esm/Chat/ChatMessage/index.js +1 -0
- package/dist/esm/Chat/ChatMessageError/ChatMessageError.d.ts +62 -0
- package/dist/esm/Chat/ChatMessageError/ChatMessageError.js +66 -0
- package/dist/esm/Chat/ChatMessageError/ChatMessageError.styles.d.ts +253 -0
- package/dist/esm/Chat/ChatMessageError/ChatMessageError.styles.js +11 -0
- package/dist/esm/Chat/ChatMessageError/index.d.ts +1 -0
- package/dist/esm/Chat/ChatMessageError/index.js +1 -0
- package/dist/esm/Chat/ChatMessageLoader/ChatMessageLoader.d.ts +21 -0
- package/dist/esm/Chat/ChatMessageLoader/ChatMessageLoader.js +61 -0
- package/dist/esm/Chat/ChatMessageLoader/ChatMessageLoader.styles.d.ts +280 -0
- package/dist/esm/Chat/ChatMessageLoader/ChatMessageLoader.styles.js +14 -0
- package/dist/esm/Chat/ChatMessageLoader/index.d.ts +1 -0
- package/dist/esm/Chat/ChatMessageLoader/index.js +1 -0
- package/dist/esm/Chat/ChatMessages/ChatMessages.d.ts +141 -0
- package/dist/esm/Chat/ChatMessages/ChatMessages.js +158 -0
- package/dist/esm/Chat/ChatMessages/ChatMessages.styles.d.ts +69 -0
- package/dist/esm/Chat/ChatMessages/ChatMessages.styles.js +22 -0
- package/dist/esm/Chat/ChatMessages/index.d.ts +1 -0
- package/dist/esm/Chat/ChatMessages/index.js +1 -0
- package/dist/esm/Chat/ChatMessages/useLastMessageHeight.d.ts +14 -0
- package/dist/esm/Chat/ChatMessages/useLastMessageHeight.js +48 -0
- package/dist/esm/Chat/ChatPrompt/ChatPrompt.d.ts +105 -0
- package/dist/esm/Chat/ChatPrompt/ChatPrompt.js +159 -0
- package/dist/esm/Chat/ChatPrompt/ChatPrompt.styles.d.ts +63 -0
- package/dist/esm/Chat/ChatPrompt/ChatPrompt.styles.js +22 -0
- package/dist/esm/Chat/ChatPrompt/index.d.ts +1 -0
- package/dist/esm/Chat/ChatPrompt/index.js +1 -0
- package/dist/esm/Chat/ChatPrompt/useFocusTyping.d.ts +30 -0
- package/dist/esm/Chat/ChatPrompt/useFocusTyping.js +59 -0
- package/dist/esm/Chat/ChatPrompt/useTypewriter.d.ts +27 -0
- package/dist/esm/Chat/ChatPrompt/useTypewriter.js +80 -0
- package/dist/esm/Chat/index.d.ts +15 -0
- package/dist/esm/Chat/index.js +6 -0
- package/dist/esm/Chat/types.d.ts +7 -0
- package/dist/esm/Chat/types.js +1 -0
- package/dist/esm/Fields/Checkbox/Checkbox.d.ts +2 -2
- package/dist/esm/Fields/Checkbox/Checkbox.js +2 -2
- package/dist/esm/Fields/Dropzone/Dropzone.js +1 -1
- package/dist/esm/Fields/Form/stories/Complex.js +123 -50
- package/dist/esm/Fields/Input/Input.js +10 -13
- package/dist/esm/Fields/RadioGroup/RadioButton.js +10 -3
- package/dist/esm/Fields/RadioGroup/RadioButton.tailwind.js +1 -1
- package/dist/esm/Fields/RadioGroup/RadioGroupContext.d.ts +2 -0
- package/dist/esm/Fields/RadioGroup/RadioGroupItem.js +1 -1
- package/dist/esm/Fields/Select/Select.tailwind.js +4 -3
- package/dist/esm/Fields/SelectableCard/SelectableCard.d.ts +35 -0
- package/dist/esm/Fields/SelectableCard/SelectableCard.js +100 -0
- package/dist/esm/Fields/SelectableCard/SelectableCardContext.d.ts +13 -0
- package/dist/esm/Fields/SelectableCard/SelectableCardContext.js +9 -0
- package/dist/esm/Fields/SelectableCard/SelectableCardGroup.d.ts +13 -0
- package/dist/esm/Fields/SelectableCard/SelectableCardGroup.js +48 -0
- package/dist/esm/Fields/SelectableCard/index.d.ts +2 -0
- package/dist/esm/Fields/SelectableCard/index.js +2 -0
- package/dist/esm/Fields/Switch/Switch.js +1 -1
- package/dist/esm/Fields/TextArea/TextArea.d.ts +5 -1
- package/dist/esm/Fields/TextArea/TextArea.js +3 -2
- package/dist/esm/Fields/TextArea/TextArea.tailwind.js +1 -1
- package/dist/esm/Fields/TextAreaAutoSize/TextAreaAutoSize.d.ts +26 -0
- package/dist/esm/Fields/TextAreaAutoSize/TextAreaAutoSize.js +75 -0
- package/dist/esm/Fields/TextAreaAutoSize/TextAreaAutoSize.styles.d.ts +37 -0
- package/dist/esm/Fields/TextAreaAutoSize/TextAreaAutoSize.styles.js +9 -0
- package/dist/esm/Fields/TextAreaAutoSize/index.d.ts +2 -0
- package/dist/esm/Fields/TextAreaAutoSize/index.js +1 -0
- package/dist/esm/Fields/index.d.ts +3 -1
- package/dist/esm/Fields/index.js +3 -1
- package/dist/esm/Helpers/ShimmerText/ShimmerText.d.ts +3 -0
- package/dist/esm/Helpers/ShimmerText/ShimmerText.js +21 -0
- package/dist/esm/Helpers/ShimmerText/ShimmerText.tailwind.d.ts +5 -0
- package/dist/esm/Helpers/ShimmerText/ShimmerText.tailwind.js +36 -0
- package/dist/esm/Helpers/ShimmerText/index.d.ts +2 -0
- package/dist/esm/Helpers/ShimmerText/index.js +1 -0
- package/dist/esm/Helpers/index.d.ts +1 -0
- package/dist/esm/Helpers/index.js +2 -1
- package/dist/esm/Helpers/utilities/focusable.tailwind.js +1 -1
- package/dist/esm/Helpers/utilities/utilities.tailwind.js +6 -1
- package/dist/esm/Indicators/Skeleton/Skeleton.d.ts +2 -2
- package/dist/esm/Navigation/Link/Link.d.ts +10 -0
- package/dist/esm/Navigation/Link/Link.js +4 -2
- package/dist/esm/Satellite/locale.d.ts +7 -1
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/styles/helpers/tv.d.ts +5 -0
- package/dist/esm/styles/helpers/tv.js +7 -0
- package/dist/esm/styles/tailwind.config.js +1 -1
- package/dist/esm/utils/getTextFromReactNode.d.ts +2 -1
- package/dist/esm/utils/getTextFromReactNode.js +13 -8
- package/dist/satellite.min.css +1 -1
- package/package.json +12 -3
@@ -0,0 +1 @@
|
|
1
|
+
export * from "./ChatMessages";
|
@@ -0,0 +1,14 @@
|
|
1
|
+
import type { RefObject } from "react";
|
2
|
+
import type { ChatMessageBase } from "../../Chat/types";
|
3
|
+
/**
|
4
|
+
* React hook to compute the “fill” height below the last user message,
|
5
|
+
* based on the scroll container’s height, the last user‐message element’s height,
|
6
|
+
* and any CSS gap/padding offsets.
|
7
|
+
*
|
8
|
+
* @param scrollRef - The ref to the scroll container.
|
9
|
+
* @param lastUserMessageRef - The ref to the last user message.
|
10
|
+
* @param messages - The messages to display in the chat.
|
11
|
+
* @param lastMessageSubmitted - Whether the last message has been submitted.
|
12
|
+
* @param spacingOffset - The spacing offset.
|
13
|
+
*/
|
14
|
+
export declare function useLastMessageHeight(scrollRef: RefObject<HTMLElement>, lastUserMessageRef: RefObject<HTMLDivElement | null>, messages: ChatMessageBase[], lastMessageSubmitted: boolean, spacingOffset?: number): number;
|
@@ -0,0 +1,48 @@
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
2
|
+
import { useRef } from "react";
|
3
|
+
import { useLayoutEffect, useState } from "react";
|
4
|
+
/**
|
5
|
+
* React hook to compute the “fill” height below the last user message,
|
6
|
+
* based on the scroll container’s height, the last user‐message element’s height,
|
7
|
+
* and any CSS gap/padding offsets.
|
8
|
+
*
|
9
|
+
* @param scrollRef - The ref to the scroll container.
|
10
|
+
* @param lastUserMessageRef - The ref to the last user message.
|
11
|
+
* @param messages - The messages to display in the chat.
|
12
|
+
* @param lastMessageSubmitted - Whether the last message has been submitted.
|
13
|
+
* @param spacingOffset - The spacing offset.
|
14
|
+
*/
|
15
|
+
export function useLastMessageHeight(scrollRef, lastUserMessageRef, messages, lastMessageSubmitted) {
|
16
|
+
var spacingOffset = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 0;
|
17
|
+
var _useState = useState(0),
|
18
|
+
_useState2 = _slicedToArray(_useState, 2),
|
19
|
+
lastMessageHeight = _useState2[0],
|
20
|
+
setLastMessageHeight = _useState2[1];
|
21
|
+
var offsetsRef = useRef(0);
|
22
|
+
function getStaticOffsets() {
|
23
|
+
if (offsetsRef.current || !scrollRef.current) return offsetsRef.current;
|
24
|
+
|
25
|
+
// Compute any CSS gap/rowGap/padding offsets by reading computed style
|
26
|
+
var computed = window.getComputedStyle(scrollRef.current);
|
27
|
+
var rowGapValue = parseFloat(computed.rowGap) || parseFloat(computed.gap) || 0;
|
28
|
+
var paddingTop = parseFloat(computed.paddingTop) || 0;
|
29
|
+
var paddingBottom = parseFloat(computed.paddingBottom) || 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);
|
39
|
+
};
|
40
|
+
|
41
|
+
// Recompute whenever messages change and a new user message has just been submitted
|
42
|
+
useLayoutEffect(function () {
|
43
|
+
if (!lastMessageSubmitted) return;
|
44
|
+
updateLastMessageHeight();
|
45
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
46
|
+
}, [messages.length, lastMessageSubmitted]);
|
47
|
+
return lastMessageHeight;
|
48
|
+
}
|
@@ -0,0 +1,105 @@
|
|
1
|
+
import type { FormEvent, KeyboardEvent, ReactNode } from "react";
|
2
|
+
import type { ChatStatus } from "../../Chat/types";
|
3
|
+
import type { TextAreaAutoSizeProps } from "../../Fields/TextAreaAutoSize/TextAreaAutoSize";
|
4
|
+
export declare type ChatPromptLocale = {
|
5
|
+
textareaLabel?: string;
|
6
|
+
emptyMessageTooltip?: string;
|
7
|
+
stopResponseTooltip?: string;
|
8
|
+
sendMessageTooltip?: string;
|
9
|
+
disabledTooltip?: string;
|
10
|
+
};
|
11
|
+
export declare type ChatPromptProps = Omit<TextAreaAutoSizeProps, "onSubmit"> & {
|
12
|
+
/**
|
13
|
+
* Content to render above the textarea (e.g., a title or instructions).
|
14
|
+
*/
|
15
|
+
renderHeader?: ReactNode;
|
16
|
+
/**
|
17
|
+
* Content to render below the textarea (e.g., additional controls or hints).
|
18
|
+
*/
|
19
|
+
renderFooter?: ReactNode;
|
20
|
+
/**
|
21
|
+
* An optional array of placeholder strings to cycle through with a typewriter effect.
|
22
|
+
* If provided and non-empty, the component will use the dynamic, animated placeholder
|
23
|
+
* text instead of any static `placeholder` prop passed in.
|
24
|
+
*/
|
25
|
+
placeholders?: string[];
|
26
|
+
/**
|
27
|
+
* The current status of the chat prompt submit button:
|
28
|
+
* - "submitted": The message has been sent to the API and we're awaiting the start of the response stream.
|
29
|
+
* - "streaming": The response is actively streaming in from the API, receiving chunks of data.
|
30
|
+
* - "ready": The full response has been received and processed; a new user message can be submitted.
|
31
|
+
* - "error": An error occurred during the API request, preventing successful completion.
|
32
|
+
*/
|
33
|
+
status?: ChatStatus;
|
34
|
+
/**
|
35
|
+
* Whether to automatically focus the textarea when the user starts typing.
|
36
|
+
*/
|
37
|
+
autoFocusOnTyping?: boolean;
|
38
|
+
/**
|
39
|
+
* Whether to enable right-to-left (RTL) layout support.
|
40
|
+
*/
|
41
|
+
rtl?: boolean;
|
42
|
+
/**
|
43
|
+
* Optional locale.
|
44
|
+
*/
|
45
|
+
locale?: ChatPromptLocale;
|
46
|
+
/**
|
47
|
+
* Callback invoked when the user submits the form, either by clicking
|
48
|
+
* the submit button or pressing Enter (without Shift) inside the textarea.
|
49
|
+
*/
|
50
|
+
onSubmit?: (e: KeyboardEvent<HTMLTextAreaElement> | FormEvent<HTMLFormElement>) => void;
|
51
|
+
/**
|
52
|
+
* Callback invoked when the user requests to stop the current chat response stream.
|
53
|
+
*/
|
54
|
+
onStop?: () => void;
|
55
|
+
};
|
56
|
+
/**
|
57
|
+
* The `ChatPrompt` component provides a textarea for users to type messages and a button to submit them.
|
58
|
+
*
|
59
|
+
* See the [ChatPrompt documentation page](https://satellite.algolia.com/8261d6576/p/06f740-chat-prompt) for more information.
|
60
|
+
*/
|
61
|
+
export declare const ChatPrompt: import("react").ForwardRefExoticComponent<Omit<TextAreaAutoSizeProps, "onSubmit"> & {
|
62
|
+
/**
|
63
|
+
* Content to render above the textarea (e.g., a title or instructions).
|
64
|
+
*/
|
65
|
+
renderHeader?: ReactNode;
|
66
|
+
/**
|
67
|
+
* Content to render below the textarea (e.g., additional controls or hints).
|
68
|
+
*/
|
69
|
+
renderFooter?: ReactNode;
|
70
|
+
/**
|
71
|
+
* An optional array of placeholder strings to cycle through with a typewriter effect.
|
72
|
+
* If provided and non-empty, the component will use the dynamic, animated placeholder
|
73
|
+
* text instead of any static `placeholder` prop passed in.
|
74
|
+
*/
|
75
|
+
placeholders?: string[] | undefined;
|
76
|
+
/**
|
77
|
+
* The current status of the chat prompt submit button:
|
78
|
+
* - "submitted": The message has been sent to the API and we're awaiting the start of the response stream.
|
79
|
+
* - "streaming": The response is actively streaming in from the API, receiving chunks of data.
|
80
|
+
* - "ready": The full response has been received and processed; a new user message can be submitted.
|
81
|
+
* - "error": An error occurred during the API request, preventing successful completion.
|
82
|
+
*/
|
83
|
+
status?: ChatStatus | undefined;
|
84
|
+
/**
|
85
|
+
* Whether to automatically focus the textarea when the user starts typing.
|
86
|
+
*/
|
87
|
+
autoFocusOnTyping?: boolean | undefined;
|
88
|
+
/**
|
89
|
+
* Whether to enable right-to-left (RTL) layout support.
|
90
|
+
*/
|
91
|
+
rtl?: boolean | undefined;
|
92
|
+
/**
|
93
|
+
* Optional locale.
|
94
|
+
*/
|
95
|
+
locale?: ChatPromptLocale | undefined;
|
96
|
+
/**
|
97
|
+
* Callback invoked when the user submits the form, either by clicking
|
98
|
+
* the submit button or pressing Enter (without Shift) inside the textarea.
|
99
|
+
*/
|
100
|
+
onSubmit?: ((e: KeyboardEvent<HTMLTextAreaElement> | FormEvent<HTMLFormElement>) => void) | undefined;
|
101
|
+
/**
|
102
|
+
* Callback invoked when the user requests to stop the current chat response stream.
|
103
|
+
*/
|
104
|
+
onStop?: (() => void) | undefined;
|
105
|
+
} & import("react").RefAttributes<HTMLTextAreaElement>>;
|
@@ -0,0 +1,159 @@
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
2
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
3
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
4
|
+
var _excluded = ["className", "renderHeader", "children", "renderFooter", "onSubmit", "onStop", "placeholder", "placeholders", "status", "autoFocusOnTyping", "rtl", "defaultValue", "value", "locale", "id"];
|
5
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
6
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
7
|
+
import { useMemo } from "react";
|
8
|
+
import { useState } from "react";
|
9
|
+
import { useRef } from "react";
|
10
|
+
import { forwardRef } from "react";
|
11
|
+
import { chatPromptStyles } from "./ChatPrompt.styles";
|
12
|
+
import { useFocusOnTyping } from "./useFocusTyping";
|
13
|
+
import { useTypewriter } from "./useTypewriter";
|
14
|
+
import { IconButton } from "./../../Actions";
|
15
|
+
import { TextAreaAutoSize } from "./../../Fields/TextAreaAutoSize/TextAreaAutoSize";
|
16
|
+
import { ArrowUpIcon, StopCircleIcon } from "./../../Icons";
|
17
|
+
import { useLocale } from "./../../Satellite";
|
18
|
+
import { uniqueId } from "./../../utils";
|
19
|
+
import { mergeRefs } from "./../../utils/mergeRefs";
|
20
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
21
|
+
var DEFAULT_CHAT_PROMPT_LOCALE = {
|
22
|
+
textareaLabel: "Type your message...",
|
23
|
+
emptyMessageTooltip: "Message is empty",
|
24
|
+
stopResponseTooltip: "Stop response",
|
25
|
+
sendMessageTooltip: "Send message",
|
26
|
+
disabledTooltip: "Chat prompt is disabled"
|
27
|
+
};
|
28
|
+
/**
|
29
|
+
* The `ChatPrompt` component provides a textarea for users to type messages and a button to submit them.
|
30
|
+
*
|
31
|
+
* See the [ChatPrompt documentation page](https://satellite.algolia.com/8261d6576/p/06f740-chat-prompt) for more information.
|
32
|
+
*/
|
33
|
+
export var ChatPrompt = /*#__PURE__*/forwardRef(function (_ref, forwardedRef) {
|
34
|
+
var _ref2;
|
35
|
+
var className = _ref.className,
|
36
|
+
renderHeader = _ref.renderHeader,
|
37
|
+
children = _ref.children,
|
38
|
+
renderFooter = _ref.renderFooter,
|
39
|
+
onSubmit = _ref.onSubmit,
|
40
|
+
onStop = _ref.onStop,
|
41
|
+
staticPlaceholder = _ref.placeholder,
|
42
|
+
_ref$placeholders = _ref.placeholders,
|
43
|
+
placeholders = _ref$placeholders === void 0 ? [] : _ref$placeholders,
|
44
|
+
_ref$status = _ref.status,
|
45
|
+
status = _ref$status === void 0 ? "ready" : _ref$status,
|
46
|
+
_ref$autoFocusOnTypin = _ref.autoFocusOnTyping,
|
47
|
+
autoFocusOnTyping = _ref$autoFocusOnTypin === void 0 ? false : _ref$autoFocusOnTypin,
|
48
|
+
_ref$rtl = _ref.rtl,
|
49
|
+
rtl = _ref$rtl === void 0 ? false : _ref$rtl,
|
50
|
+
defaultValue = _ref.defaultValue,
|
51
|
+
valueProp = _ref.value,
|
52
|
+
propsLocale = _ref.locale,
|
53
|
+
propId = _ref.id,
|
54
|
+
props = _objectWithoutProperties(_ref, _excluded);
|
55
|
+
var contextLocale = useLocale("chatPrompt");
|
56
|
+
var locale = _objectSpread(_objectSpread(_objectSpread({}, DEFAULT_CHAT_PROMPT_LOCALE), contextLocale), propsLocale);
|
57
|
+
|
58
|
+
// eslint-disable-next-line @algolia/stl/prefer-stl-helper
|
59
|
+
var generatedId = useMemo(function () {
|
60
|
+
return uniqueId("stl-chat-prompt-");
|
61
|
+
}, []);
|
62
|
+
var textareaId = propId !== null && propId !== void 0 ? propId : generatedId;
|
63
|
+
var internalRef = useRef(null);
|
64
|
+
var styles = chatPromptStyles({
|
65
|
+
disabled: props.disabled
|
66
|
+
});
|
67
|
+
var _useState = useState(defaultValue !== null && defaultValue !== void 0 ? defaultValue : ""),
|
68
|
+
_useState2 = _slicedToArray(_useState, 2),
|
69
|
+
internalValue = _useState2[0],
|
70
|
+
setInternalValue = _useState2[1];
|
71
|
+
var isControlled = typeof valueProp !== "undefined";
|
72
|
+
var value = isControlled ? valueProp : internalValue;
|
73
|
+
var hasValue = typeof value === "string" ? value.trim() !== "" : !!value;
|
74
|
+
var canStop = status === "submitted" || status === "streaming";
|
75
|
+
var buttonDisabled = !hasValue && !canStop;
|
76
|
+
var dynamicPlaceholder = useTypewriter(placeholders, !hasValue);
|
77
|
+
var computedPlaceholder = placeholders.length > 0 ? dynamicPlaceholder : staticPlaceholder;
|
78
|
+
useFocusOnTyping(internalRef, {
|
79
|
+
enabled: autoFocusOnTyping,
|
80
|
+
strictChars: true
|
81
|
+
});
|
82
|
+
var submit = function submit(e) {
|
83
|
+
e.preventDefault();
|
84
|
+
if (canStop) {
|
85
|
+
onStop === null || onStop === void 0 || onStop();
|
86
|
+
return;
|
87
|
+
}
|
88
|
+
if (!hasValue) {
|
89
|
+
return;
|
90
|
+
}
|
91
|
+
onSubmit === null || onSubmit === void 0 || onSubmit(e);
|
92
|
+
};
|
93
|
+
return /*#__PURE__*/_jsxs("form", {
|
94
|
+
className: styles.base(),
|
95
|
+
onSubmit: submit,
|
96
|
+
dir: rtl ? "rtl" : "ltr",
|
97
|
+
children: [!!renderHeader && /*#__PURE__*/_jsx("div", {
|
98
|
+
className: styles.header(),
|
99
|
+
children: renderHeader
|
100
|
+
}), /*#__PURE__*/_jsx("div", {
|
101
|
+
className: styles.body(),
|
102
|
+
onClick: function onClick(e) {
|
103
|
+
var _internalRef$current;
|
104
|
+
if (e.target === internalRef.current) return;
|
105
|
+
(_internalRef$current = internalRef.current) === null || _internalRef$current === void 0 || _internalRef$current.focus();
|
106
|
+
},
|
107
|
+
children: /*#__PURE__*/_jsx(TextAreaAutoSize, _objectSpread(_objectSpread({
|
108
|
+
id: textareaId,
|
109
|
+
ref: mergeRefs([forwardedRef, internalRef]),
|
110
|
+
rows: 2,
|
111
|
+
maxRows: 8,
|
112
|
+
placeholder: computedPlaceholder,
|
113
|
+
value: value,
|
114
|
+
"aria-label": (_ref2 = placeholders[0] ? placeholders[0] : staticPlaceholder) !== null && _ref2 !== void 0 ? _ref2 : locale.textareaLabel,
|
115
|
+
translate: "no",
|
116
|
+
autoComplete: "off",
|
117
|
+
onInput: function onInput(e) {
|
118
|
+
var _props$onInput;
|
119
|
+
if (!isControlled) {
|
120
|
+
setInternalValue(e.currentTarget.value);
|
121
|
+
}
|
122
|
+
(_props$onInput = props.onInput) === null || _props$onInput === void 0 || _props$onInput.call(props, e);
|
123
|
+
}
|
124
|
+
}, props), {}, {
|
125
|
+
className: styles.textarea({
|
126
|
+
className: className
|
127
|
+
}),
|
128
|
+
onKeyDown: function onKeyDown(e) {
|
129
|
+
var _props$onKeyDown;
|
130
|
+
(_props$onKeyDown = props.onKeyDown) === null || _props$onKeyDown === void 0 || _props$onKeyDown.call(props, e);
|
131
|
+
if (e.key === "Enter" && !e.shiftKey) {
|
132
|
+
submit(e);
|
133
|
+
}
|
134
|
+
if (e.key === "Escape") {
|
135
|
+
e.currentTarget.blur();
|
136
|
+
}
|
137
|
+
},
|
138
|
+
children: /*#__PURE__*/_jsx("div", {
|
139
|
+
className: styles.actions(),
|
140
|
+
children: /*#__PURE__*/_jsx(IconButton, {
|
141
|
+
type: "submit",
|
142
|
+
icon: canStop ? StopCircleIcon : ArrowUpIcon,
|
143
|
+
variant: canStop ? "neutral" : "primary",
|
144
|
+
size: "small",
|
145
|
+
title: props.disabled ? locale.disabledTooltip : buttonDisabled ? locale.emptyMessageTooltip : canStop ? locale.stopResponseTooltip : locale.sendMessageTooltip,
|
146
|
+
tooltipSide: "top",
|
147
|
+
disabled: buttonDisabled,
|
148
|
+
className: styles.submit(),
|
149
|
+
"data-status": status
|
150
|
+
})
|
151
|
+
})
|
152
|
+
}))
|
153
|
+
}), !!renderFooter && /*#__PURE__*/_jsx("div", {
|
154
|
+
className: styles.footer(),
|
155
|
+
children: renderFooter
|
156
|
+
})]
|
157
|
+
});
|
158
|
+
});
|
159
|
+
ChatPrompt.displayName = "ChatPrompt";
|
@@ -0,0 +1,63 @@
|
|
1
|
+
export declare const chatPromptStyles: import("tailwind-variants").TVReturnType<{
|
2
|
+
disabled: {
|
3
|
+
true: {
|
4
|
+
actions: string;
|
5
|
+
};
|
6
|
+
};
|
7
|
+
}, {
|
8
|
+
base: string;
|
9
|
+
header: string;
|
10
|
+
body: string;
|
11
|
+
textarea: string;
|
12
|
+
actions: string;
|
13
|
+
submit: string;
|
14
|
+
footer: string;
|
15
|
+
}, undefined, {
|
16
|
+
responsiveVariants?: boolean | ("sm" | "md" | "lg" | "xl" | "2xl")[] | {
|
17
|
+
disabled?: boolean | ("sm" | "md" | "lg" | "xl" | "2xl")[] | undefined;
|
18
|
+
} | undefined;
|
19
|
+
} & import("tailwind-variants/dist/config").TWMConfig & {
|
20
|
+
twMergeConfig: {
|
21
|
+
prefix: string;
|
22
|
+
};
|
23
|
+
}, {
|
24
|
+
disabled: {
|
25
|
+
true: {
|
26
|
+
actions: string;
|
27
|
+
};
|
28
|
+
};
|
29
|
+
}, {
|
30
|
+
base: string;
|
31
|
+
header: string;
|
32
|
+
body: string;
|
33
|
+
textarea: string;
|
34
|
+
actions: string;
|
35
|
+
submit: string;
|
36
|
+
footer: string;
|
37
|
+
}, import("tailwind-variants").TVReturnType<{
|
38
|
+
disabled: {
|
39
|
+
true: {
|
40
|
+
actions: string;
|
41
|
+
};
|
42
|
+
};
|
43
|
+
}, {
|
44
|
+
base: string;
|
45
|
+
header: string;
|
46
|
+
body: string;
|
47
|
+
textarea: string;
|
48
|
+
actions: string;
|
49
|
+
submit: string;
|
50
|
+
footer: string;
|
51
|
+
}, undefined, import("tailwind-variants/dist/config").TVConfig<{
|
52
|
+
disabled: {
|
53
|
+
true: {
|
54
|
+
actions: string;
|
55
|
+
};
|
56
|
+
};
|
57
|
+
}, {
|
58
|
+
disabled: {
|
59
|
+
true: {
|
60
|
+
actions: string;
|
61
|
+
};
|
62
|
+
};
|
63
|
+
}>, unknown, unknown, undefined>>;
|
@@ -0,0 +1,22 @@
|
|
1
|
+
import _taggedTemplateLiteral from "@babel/runtime/helpers/taggedTemplateLiteral";
|
2
|
+
var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6, _templateObject7, _templateObject8;
|
3
|
+
import stl from "./../../styles/helpers/satellitePrefixer";
|
4
|
+
import { tv } from "./../../styles/helpers/tv";
|
5
|
+
export var chatPromptStyles = tv({
|
6
|
+
slots: {
|
7
|
+
base: stl(_templateObject || (_templateObject = _taggedTemplateLiteral(["relative flex flex-col items-stretch gap-2 w-full"]))),
|
8
|
+
header: stl(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["flex items-center gap-1.5"]))),
|
9
|
+
body: stl(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral([""]))),
|
10
|
+
textarea: stl(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["[&>textarea]:p-3 [&>textarea]:pb-0 [&>textarea]:thin-scrollbar"]))),
|
11
|
+
actions: stl(_templateObject5 || (_templateObject5 = _taggedTemplateLiteral(["flex flex-row p-3 pt-2 justify-end cursor-text"]))),
|
12
|
+
submit: stl(_templateObject6 || (_templateObject6 = _taggedTemplateLiteral([""]))),
|
13
|
+
footer: stl(_templateObject7 || (_templateObject7 = _taggedTemplateLiteral(["flex items-center justify-between gap-1.5"])))
|
14
|
+
},
|
15
|
+
variants: {
|
16
|
+
disabled: {
|
17
|
+
"true": {
|
18
|
+
actions: stl(_templateObject8 || (_templateObject8 = _taggedTemplateLiteral(["bg-grey-100 cursor-not-allowed"])))
|
19
|
+
}
|
20
|
+
}
|
21
|
+
}
|
22
|
+
});
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from "./ChatPrompt";
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from "./ChatPrompt";
|
@@ -0,0 +1,30 @@
|
|
1
|
+
/// <reference types="react" />
|
2
|
+
/**
|
3
|
+
* Check if the element is a textual element.
|
4
|
+
* @param el - The element to check.
|
5
|
+
* @returns True if the element is a textual element, false otherwise.
|
6
|
+
*/
|
7
|
+
export declare const isTextualElement: (el: HTMLElement) => boolean;
|
8
|
+
declare type Editable = HTMLTextAreaElement | HTMLInputElement | HTMLElement;
|
9
|
+
export interface UseFocusOnTypingOptions {
|
10
|
+
/**
|
11
|
+
* Whether the hook is enabled.
|
12
|
+
* @default true
|
13
|
+
*/
|
14
|
+
enabled?: boolean;
|
15
|
+
/**
|
16
|
+
* Whether to allow punctuation, diacritics, etc.
|
17
|
+
* @default false
|
18
|
+
*/
|
19
|
+
strictChars?: boolean;
|
20
|
+
}
|
21
|
+
/**
|
22
|
+
* Focus `editableRef` the moment the user types anywhere on the page,
|
23
|
+
* *unless* their cursor is already inside an editable control.
|
24
|
+
* @param editableRef - The ref to the editable element.
|
25
|
+
* @param options - The options for the hook.
|
26
|
+
* @param options.enabled - Whether the hook is enabled.
|
27
|
+
* @param options.strictChars - Whether to allow punctuation, diacritics, etc.
|
28
|
+
*/
|
29
|
+
export declare function useFocusOnTyping<E extends Editable = Editable>(editableRef: React.RefObject<E>, options?: UseFocusOnTypingOptions): void;
|
30
|
+
export {};
|
@@ -0,0 +1,59 @@
|
|
1
|
+
import { useCallback, useEffect } from "react";
|
2
|
+
|
3
|
+
/**
|
4
|
+
* Check if the element is a textual element.
|
5
|
+
* @param el - The element to check.
|
6
|
+
* @returns True if the element is a textual element, false otherwise.
|
7
|
+
*/
|
8
|
+
export 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
|
+
var t = el.type.toLowerCase();
|
14
|
+
return ["text", "search", "url", "email", "tel", "password", "number", "date", "datetime-local", "month", "week", "time"].includes(t);
|
15
|
+
}
|
16
|
+
return false;
|
17
|
+
};
|
18
|
+
|
19
|
+
// e.g. <div contentEditable>
|
20
|
+
|
21
|
+
/**
|
22
|
+
* Focus `editableRef` the moment the user types anywhere on the page,
|
23
|
+
* *unless* their cursor is already inside an editable control.
|
24
|
+
* @param editableRef - The ref to the editable element.
|
25
|
+
* @param options - The options for the hook.
|
26
|
+
* @param options.enabled - Whether the hook is enabled.
|
27
|
+
* @param options.strictChars - Whether to allow punctuation, diacritics, etc.
|
28
|
+
*/
|
29
|
+
export function useFocusOnTyping(editableRef) {
|
30
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
31
|
+
var _options$enabled = options.enabled,
|
32
|
+
enabled = _options$enabled === void 0 ? true : _options$enabled,
|
33
|
+
_options$strictChars = options.strictChars,
|
34
|
+
strictChars = _options$strictChars === void 0 ? false : _options$strictChars;
|
35
|
+
var handleKeyDown = useCallback(function (e) {
|
36
|
+
if (!enabled || e.ctrlKey || e.altKey || e.metaKey || e.isComposing || e.repeat || (
|
37
|
+
// Printable-character test
|
38
|
+
strictChars ? !/^[A-Za-z0-9]$/.test(e.key) : e.key.length !== 1)) {
|
39
|
+
return;
|
40
|
+
}
|
41
|
+
var node = editableRef.current;
|
42
|
+
if (!node) return;
|
43
|
+
if (node.contains(document.activeElement)) return;
|
44
|
+
var el = e.target;
|
45
|
+
if (!el || !isTextualElement(el)) {
|
46
|
+
node.focus();
|
47
|
+
}
|
48
|
+
}, [enabled, strictChars, editableRef]);
|
49
|
+
useEffect(function () {
|
50
|
+
if (typeof window === "undefined") return; // SSR/test guard
|
51
|
+
|
52
|
+
window.addEventListener("keydown", handleKeyDown, {
|
53
|
+
passive: true
|
54
|
+
});
|
55
|
+
return function () {
|
56
|
+
return window.removeEventListener("keydown", handleKeyDown);
|
57
|
+
};
|
58
|
+
}, [handleKeyDown]);
|
59
|
+
}
|
@@ -0,0 +1,27 @@
|
|
1
|
+
export interface UseTypewriterOptions {
|
2
|
+
/**
|
3
|
+
* Milliseconds per character when typing.
|
4
|
+
* @default 150
|
5
|
+
*/
|
6
|
+
typingSpeed?: number;
|
7
|
+
/**
|
8
|
+
* Milliseconds per character when deleting.
|
9
|
+
* @default 20
|
10
|
+
*/
|
11
|
+
deletingSpeed?: number;
|
12
|
+
/**
|
13
|
+
* Milliseconds to pause after typing a full word before deleting.
|
14
|
+
* @default 1000
|
15
|
+
*/
|
16
|
+
pauseDuration?: number;
|
17
|
+
}
|
18
|
+
/**
|
19
|
+
* A hook that types out a list of texts character by character.
|
20
|
+
* @param texts - The list of texts to type out.
|
21
|
+
* @param enabled - Whether the hook is enabled.
|
22
|
+
* @param options - The options for the hook.
|
23
|
+
* @param options.typingSpeed - The speed at which to type out the text.
|
24
|
+
* @param options.deletingSpeed - The speed at which to delete the text.
|
25
|
+
* @param options.pauseDuration - The duration to pause after typing a full word before deleting.
|
26
|
+
*/
|
27
|
+
export declare function useTypewriter(texts: string[], enabled?: boolean, options?: UseTypewriterOptions): string;
|
@@ -0,0 +1,80 @@
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
2
|
+
import { useEffect, useState } from "react";
|
3
|
+
/**
|
4
|
+
* A hook that types out a list of texts character by character.
|
5
|
+
* @param texts - The list of texts to type out.
|
6
|
+
* @param enabled - Whether the hook is enabled.
|
7
|
+
* @param options - The options for the hook.
|
8
|
+
* @param options.typingSpeed - The speed at which to type out the text.
|
9
|
+
* @param options.deletingSpeed - The speed at which to delete the text.
|
10
|
+
* @param options.pauseDuration - The duration to pause after typing a full word before deleting.
|
11
|
+
*/
|
12
|
+
export function useTypewriter(texts) {
|
13
|
+
var enabled = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
14
|
+
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
15
|
+
var _options$typingSpeed = options.typingSpeed,
|
16
|
+
typingSpeed = _options$typingSpeed === void 0 ? 150 : _options$typingSpeed,
|
17
|
+
_options$deletingSpee = options.deletingSpeed,
|
18
|
+
deletingSpeed = _options$deletingSpee === void 0 ? 20 : _options$deletingSpee,
|
19
|
+
_options$pauseDuratio = options.pauseDuration,
|
20
|
+
pauseDuration = _options$pauseDuratio === void 0 ? 1000 : _options$pauseDuratio;
|
21
|
+
var _useState = useState(""),
|
22
|
+
_useState2 = _slicedToArray(_useState, 2),
|
23
|
+
currentText = _useState2[0],
|
24
|
+
setCurrentText = _useState2[1];
|
25
|
+
var _useState3 = useState(false),
|
26
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
27
|
+
isDeleting = _useState4[0],
|
28
|
+
setIsDeleting = _useState4[1];
|
29
|
+
var _useState5 = useState(0),
|
30
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
31
|
+
loopIndex = _useState6[0],
|
32
|
+
setLoopIndex = _useState6[1];
|
33
|
+
useEffect(function () {
|
34
|
+
if (texts.length === 0 || !enabled) {
|
35
|
+
return;
|
36
|
+
}
|
37
|
+
var currentIndex = loopIndex % texts.length;
|
38
|
+
var fullText = texts[currentIndex];
|
39
|
+
var isFullWord = !isDeleting && currentText === fullText;
|
40
|
+
var isEmptyWord = isDeleting && currentText === "";
|
41
|
+
var nextText;
|
42
|
+
var delay;
|
43
|
+
if (isFullWord) {
|
44
|
+
// Just finished typing the full word: pause, then start deleting
|
45
|
+
nextText = fullText.substring(0, fullText.length - 1);
|
46
|
+
delay = pauseDuration;
|
47
|
+
} else if (isEmptyWord) {
|
48
|
+
// Just finished deleting the word: move to next word
|
49
|
+
nextText = "";
|
50
|
+
delay = typingSpeed;
|
51
|
+
} else {
|
52
|
+
// Normal typing or deleting behavior
|
53
|
+
if (isDeleting) {
|
54
|
+
nextText = fullText.substring(0, currentText.length - 1);
|
55
|
+
delay = deletingSpeed;
|
56
|
+
} else {
|
57
|
+
nextText = fullText.substring(0, currentText.length + 1);
|
58
|
+
delay = typingSpeed;
|
59
|
+
}
|
60
|
+
}
|
61
|
+
var timer = setTimeout(function () {
|
62
|
+
setCurrentText(nextText);
|
63
|
+
if (isFullWord) {
|
64
|
+
// Switch to deleting
|
65
|
+
setIsDeleting(true);
|
66
|
+
} else if (isEmptyWord) {
|
67
|
+
// Reset to typing next word
|
68
|
+
setIsDeleting(false);
|
69
|
+
setLoopIndex(function (prev) {
|
70
|
+
return prev + 1;
|
71
|
+
});
|
72
|
+
}
|
73
|
+
// Otherwise, keep the current isDeleting value
|
74
|
+
}, delay);
|
75
|
+
return function () {
|
76
|
+
return clearTimeout(timer);
|
77
|
+
};
|
78
|
+
}, [enabled, currentText, isDeleting, loopIndex, texts, typingSpeed, deletingSpeed, pauseDuration]);
|
79
|
+
return currentText;
|
80
|
+
}
|
@@ -0,0 +1,15 @@
|
|
1
|
+
export type { ChatMessageProps as ExperimentalChatMessageProps } from "./ChatMessage";
|
2
|
+
export { ChatMessage as ExperimentalChatMessage } from "./ChatMessage";
|
3
|
+
export type { ChatMessagesProps as ExperimentalChatMessagesProps, ChatMessageLocale as ExperimentalChatMessageLocale, } from "./ChatMessages";
|
4
|
+
export { ChatMessages as ExperimentalChatMessages } from "./ChatMessages";
|
5
|
+
export type { ChatPromptProps as ExperimentalChatPromptProps } from "./ChatPrompt";
|
6
|
+
export type { ChatPromptLocale as ExperimentalChatPromptLocale } from "./ChatPrompt";
|
7
|
+
export { ChatPrompt as ExperimentalChatPrompt } from "./ChatPrompt";
|
8
|
+
export type { ChatContextAccordionProps as ExperimentalChatContextAccordionProps } from "./ChatContextAccordion";
|
9
|
+
export { ChatContextAccordion as ExperimentalChatContextAccordion } from "./ChatContextAccordion";
|
10
|
+
export type { ChatMessageErrorLocale as ExperimentalChatMessageErrorLocale } from "./ChatMessageError";
|
11
|
+
export type { ChatMessageErrorProps as ExperimentalChatMessageErrorProps } from "./ChatMessageError";
|
12
|
+
export { ChatMessageError as ExperimentalChatMessageError } from "./ChatMessageError";
|
13
|
+
export type { ChatMessageLoaderProps as ExperimentalChatMessageLoaderProps } from "./ChatMessageLoader";
|
14
|
+
export { ChatMessageLoader as ExperimentalChatMessageLoader } from "./ChatMessageLoader";
|
15
|
+
export type { ChatMessageBase as ExperimentalChatMessageBase, ChatMessageRole as ExperimentalChatMessageRole, ChatStatus as ExperimentalChatStatus, } from "./types";
|
@@ -0,0 +1,6 @@
|
|
1
|
+
export { ChatMessage as ExperimentalChatMessage } from "./ChatMessage";
|
2
|
+
export { ChatMessages as ExperimentalChatMessages } from "./ChatMessages";
|
3
|
+
export { ChatPrompt as ExperimentalChatPrompt } from "./ChatPrompt";
|
4
|
+
export { ChatContextAccordion as ExperimentalChatContextAccordion } from "./ChatContextAccordion";
|
5
|
+
export { ChatMessageError as ExperimentalChatMessageError } from "./ChatMessageError";
|
6
|
+
export { ChatMessageLoader as ExperimentalChatMessageLoader } from "./ChatMessageLoader";
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|