mirror of
https://github.com/bitbaum/chatkit.git
synced 2026-12-04 05:47:38 +01:00
The owner's finding, 2026-11-06: every product installs the shared packages
and the text boxes people type in are still made by hand, with no microphone;
two comment systems were written in one week. This gives the two remaining
shapes of "a person types words" a component, so there is nothing to build
locally.
- DictationField: a labelled text area (or one line) with the composer's
microphone — Web Speech, the recording fallback, the take with its timer,
kept for a retry — appending to what is there; 16px, 44px targets.
Optional improve={{ run, suggestions }}: one tap or say/type what to change;
working, failure and Undo in words, the text untouched on failure. No model
call or prompt here; run is the app's.
- CommentThread: oldest first, the box is Composer, a transport the app
implements (post, optional remove), optimistic removal rolled back with a
message, a refused post keeps the draft, text not markup, a sign-in link
for a signed-out reader, times in a stated timeZone.
- VoiceBar/VoiceProblem are one implementation shared by Composer and the
field; Composer behaves as before.
- Styles after the ChatApp boundary: the embedded sheet keeps its budget.
- test/browser-field.mjs + fixture page; render tests; README; 0.23.0.
verify: format, lint, typecheck, build, 142 unit tests, and all five browser
suites (the four existing ones unchanged) pass.
Claude-Session: https://claude.ai/code/session_019MDtmvpWNTLxXNfwUHS7MD
Co-authored-by: Claude <noreply@anthropic.com>
69 lines
2.9 KiB
TypeScript
69 lines
2.9 KiB
TypeScript
import { type ComposerVoice } from "./Composer.js";
|
|
export type CommentItem = {
|
|
id: string;
|
|
/** The name readers see. */
|
|
author: string;
|
|
/** Plain text; line breaks are kept. */
|
|
body: string;
|
|
createdAt: string | number | Date;
|
|
};
|
|
/**
|
|
* Where comments go. The component owns the list, the optimistic removal and
|
|
* every failure message; the app owns the database and who may do what.
|
|
*/
|
|
export type CommentTransport = {
|
|
/** Store the comment and return it as stored (its id, its author, its time). Throw to refuse. */
|
|
post: (text: string) => Promise<CommentItem>;
|
|
/** Delete one. Omit and nobody gets a Remove button. */
|
|
remove?: (id: string) => Promise<void>;
|
|
};
|
|
export type CommentThreadLabels = {
|
|
/** The heading: "No comments yet", "1 comment", "7 comments". */
|
|
count: (n: number) => string;
|
|
placeholder: string;
|
|
ariaLabel: string;
|
|
send: string;
|
|
signIn: string;
|
|
remove: string;
|
|
postFailed: string;
|
|
removeFailed: string;
|
|
postedAs: (name: string) => string;
|
|
};
|
|
export declare const DEFAULT_COMMENT_THREAD_LABELS: CommentThreadLabels;
|
|
export type CommentThreadProps = {
|
|
/** The comments as loaded, oldest first. Re-mount (a `key`) to load a new set. */
|
|
comments: readonly CommentItem[];
|
|
transport: CommentTransport;
|
|
/** Who is looking. `null`: readers see the thread and a sign-in link, not the box. */
|
|
viewer: {
|
|
name: string;
|
|
} | null;
|
|
/** Where "Sign in to comment" goes. Required for a signed-out reader to have a way forward. */
|
|
signInHref?: string;
|
|
/** Who may remove which comment (its author; the page's owner). Default: nobody. */
|
|
canRemove?: (comment: CommentItem) => boolean;
|
|
/** The microphone of the box. Pass `{ transcribeUrl }` for the server leg. */
|
|
voice?: ComposerVoice | false;
|
|
/**
|
|
* How a time reads. Default: `locale` in `timeZone` (UTC when none is given,
|
|
* so the server's and the browser's markup agree). Pass your own to match
|
|
* the rest of the product.
|
|
*/
|
|
formatTime?: (at: Date) => string;
|
|
locale?: string;
|
|
timeZone?: string;
|
|
/** Heading level. Default 2. */
|
|
headingLevel?: 2 | 3 | 4;
|
|
labels?: Partial<CommentThreadLabels>;
|
|
className?: string;
|
|
};
|
|
/**
|
|
* The conversation under anything: an article, a page, a listing. Comments
|
|
* read oldest first, the box is chatkit's `Composer` (so it has the
|
|
* microphone, 16px text and Enter-to-send like every other box in the fleet),
|
|
* and a person can remove what they wrote. Reading needs nothing; writing
|
|
* needs `viewer`, and a signed-out reader is shown the way to sign in on the
|
|
* same screen, never a dead end.
|
|
*/
|
|
export declare function CommentThread({ comments, transport, viewer, signInHref, canRemove, voice, formatTime, locale, timeZone, headingLevel, labels: overrides, className, }: CommentThreadProps): import("react").JSX.Element;
|
|
//# sourceMappingURL=CommentThread.d.ts.map
|