@duskmoon-dev/components 0.4.1 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,5 @@
1
- import type { ComponentProps, ForwardRefExoticComponent, RefAttributes } from "react";
1
+ import type { ComponentProps, ForwardRefExoticComponent, RefAttributes, ReactNode } from "react";
2
+ import type { TextAreaProps } from "../input";
2
3
  export type ChatPlacement = "start" | "end";
3
4
  export type ChatTimeline = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24;
4
5
  export type ChatBubbleColor = "primary" | "secondary" | "tertiary" | "accent" | "neutral" | "base" | "info" | "success" | "warning" | "error";
@@ -48,8 +49,81 @@ export type ChatToolStatusProps = ComponentProps<"span">;
48
49
  export type ChatToolCallProps = ComponentProps<"div">;
49
50
  export type ChatToolResultProps = ComponentProps<"div">;
50
51
  export type ChatTypingProps = Omit<ComponentProps<"span">, "children">;
52
+ /** A snapshot of the controlled draft at submission time. */
53
+ export interface ChatComposerSubmission {
54
+ value: string;
55
+ files: File[];
56
+ }
57
+ export interface ChatComposerCompletion {
58
+ id: string;
59
+ label: string;
60
+ description?: ReactNode;
61
+ disabled?: boolean;
62
+ }
63
+ export interface ChatComposerCompletionContext {
64
+ value: string;
65
+ selectionStart: number;
66
+ selectionEnd: number;
67
+ }
68
+ /** The application supplies candidates and owns inserting the selected result. */
69
+ export interface ChatComposerCompletionConfig {
70
+ items: readonly ChatComposerCompletion[];
71
+ onSelect: (item: ChatComposerCompletion, context: ChatComposerCompletionContext) => void;
72
+ label?: string;
73
+ }
74
+ export interface ChatComposerActionContext {
75
+ submit: () => void;
76
+ submitting: boolean;
77
+ canSubmit: boolean;
78
+ disabled: boolean;
79
+ generating: boolean;
80
+ openAttachments: () => void;
81
+ }
82
+ export interface ChatComposerAttachmentContext {
83
+ remove: () => void;
84
+ disabled: boolean;
85
+ }
86
+ export interface ChatComposerProps extends Omit<ComponentProps<"div">, "children" | "onSubmit" | "onChange"> {
87
+ value: string;
88
+ onValueChange: (value: string) => void;
89
+ /** Return false to reject admission and retain the draft. */
90
+ onSubmit: (snapshot: ChatComposerSubmission) => boolean | void | Promise<boolean | void>;
91
+ attachments?: File[];
92
+ /** Enables the native file picker and attachment removal controls. */
93
+ onAttachmentsChange?: (files: File[]) => void;
94
+ accept?: string;
95
+ /** @default true */
96
+ multiple?: boolean;
97
+ /** Permit a draft containing only files. @default false */
98
+ allowAttachmentOnly?: boolean;
99
+ disabled?: boolean;
100
+ /** Gates submission while keeping the draft editable. */
101
+ busy?: boolean;
102
+ /** Shows Stop when onStop is supplied; does not prevent submission. */
103
+ generating?: boolean;
104
+ /** Application-controlled admission, including follow-ups. @default true */
105
+ canSubmit?: boolean;
106
+ onStop?: () => void;
107
+ error?: ReactNode;
108
+ onSubmitError?: (error: unknown) => void;
109
+ /** Clear unchanged admitted text and only admitted file entries. @default true */
110
+ clearOnSubmit?: boolean;
111
+ completion?: ChatComposerCompletionConfig;
112
+ /** @default 1 */
113
+ minRows?: number;
114
+ /** @default 6 */
115
+ maxRows?: number;
116
+ textareaProps?: Omit<TextAreaProps, "value" | "defaultValue" | "onChange" | "disabled" | "rows" | "autoSize" | "ref">;
117
+ attachLabel?: string;
118
+ sendLabel?: string;
119
+ stopLabel?: string;
120
+ renderAttachment?: (file: File, context: ChatComposerAttachmentContext) => ReactNode;
121
+ /** Extra application actions rendered alongside Attach, Stop, and Send. */
122
+ children?: ReactNode | ((context: ChatComposerActionContext) => ReactNode);
123
+ }
51
124
  type ChatPartComponent<T extends HTMLElement, P> = ForwardRefExoticComponent<P & RefAttributes<T>>;
52
125
  export type ChatComponent = ChatPartComponent<HTMLDivElement, ChatProps> & {
126
+ Composer: ChatPartComponent<HTMLDivElement, ChatComposerProps>;
53
127
  Avatar: ChatPartComponent<HTMLDivElement, ChatAvatarProps>;
54
128
  Header: ChatPartComponent<HTMLDivElement, ChatHeaderProps>;
55
129
  Bubble: ChatPartComponent<HTMLDivElement, ChatBubbleProps>;
@@ -0,0 +1,4 @@
1
+ import React from "react";
2
+ import type { ChatComposerProps } from "./Chat.types";
3
+ /** Controlled prompts, attachments, and application-supplied completions. */
4
+ export declare const ChatComposer: React.ForwardRefExoticComponent<Omit<ChatComposerProps, "ref"> & React.RefAttributes<HTMLDivElement>>;
@@ -1,2 +1,3 @@
1
1
  export * from "./Chat";
2
+ export * from "./ChatComposer";
2
3
  export type * from "./Chat.types";