mirror of
https://github.com/bitbaum/chatkit.git
synced 2026-12-04 12:07:33 +01:00
The four steps 0.41 left in the README are done: - One frame: TypingBox (typing.tsx) draws the voice bar, box, strip, text, tools row and the take's problem for both. The field's tools row is the composer's ck-tools, so its paperclip and microphone are bare icons like the composer's (they were bordered circles). Frame and text share one set of rules in styles.css; each shape keeps only its differences. - One text hookup: useTypingText (dictation + appendTranscript + clipToMaxLength + the latest-text ref). - One submit-key rule: submitKeyAction in composer.ts, exported. - Same controls on both: Composer `attachments`; DictationField `handleRef` (DictationFieldHandle) and `attachExtras`. Public APIs are additive. All existing tests unchanged; new unit, render and browser checks (390px, 320px dark, desktop). Claude-Session: https://claude.ai/code/session_019MDtmv1SAs6YZn4FrewbXR Co-authored-by: Claude <noreply@anthropic.com>
86 lines
4.0 KiB
TypeScript
86 lines
4.0 KiB
TypeScript
/**
|
|
* The composer's decisions, kept out of the component so they can be tested
|
|
* without a DOM — and so every app that uses the one composer gets exactly the
|
|
* same answer to "may this send?" and "does the draft survive?".
|
|
*
|
|
* From loki `src/components/composer/composer-logic.ts`, where these were
|
|
* written after four composers in one app gave four different answers.
|
|
*/
|
|
/** A destination the same words can go to (e.g. Ask vs Inject). */
|
|
export type ComposerMode = {
|
|
id: string;
|
|
label: string;
|
|
hint?: string;
|
|
};
|
|
/** `false` keeps the draft (the send failed or was refused); anything else
|
|
* clears it. A failed send must be retryable from the same box, not retyped. */
|
|
export type ComposerSendResult = void | boolean;
|
|
export declare function composerCanSend({ text, attachmentCount, attachmentOnlyText, sending, disabled, blocked, queue, }: {
|
|
text: string;
|
|
attachmentCount: number;
|
|
attachmentOnlyText?: string;
|
|
sending: boolean;
|
|
disabled: boolean;
|
|
blocked: boolean;
|
|
/** The app takes a message while a turn runs and sends it after. With it,
|
|
* `sending` no longer refuses the send — it queues it. */
|
|
queue?: boolean;
|
|
}): boolean;
|
|
/** The words actually sent: the draft, or the app's stand-in for an
|
|
* attachments-only send. */
|
|
export declare function composerOutgoingText(text: string, attachmentCount: number, attachmentOnlyText?: string): string;
|
|
export declare function shouldClearDraft(result: ComposerSendResult): boolean;
|
|
/** Dictated words join the draft with one space, never glued to the last word. */
|
|
export declare function appendTranscript(draft: string, said: string): string;
|
|
/**
|
|
* Text a field sets itself (a dictated take, a rewrite) kept within the
|
|
* field's `maxLength`. The attribute stops typing and pasting at the limit
|
|
* and nothing else: a value set in code goes straight past it, and the form
|
|
* then refuses or cuts what the person said. Cut at the limit, on a word
|
|
* where one is near, so the field never holds more than it may send.
|
|
*/
|
|
export declare function clipToMaxLength(text: string, maxLength: number | undefined): string;
|
|
/**
|
|
* The three shapes a box takes, for its submit key: a `"composer"` sends a
|
|
* message in a conversation; a `"multiline"` field and a `"single"` (one-line)
|
|
* field are every other place a person types.
|
|
*/
|
|
export type TypingShape = "composer" | "multiline" | "single";
|
|
/** The parts of a key press the submit rule reads (a React or DOM event fits). */
|
|
export type SubmitKeyEvent = {
|
|
key: string;
|
|
shiftKey?: boolean;
|
|
altKey?: boolean;
|
|
metaKey?: boolean;
|
|
ctrlKey?: boolean;
|
|
/** An IME composition is running (`event.nativeEvent.isComposing`). */
|
|
isComposing?: boolean;
|
|
/** `229` is the IME's own key on browsers that do not set `isComposing`. */
|
|
keyCode?: number;
|
|
};
|
|
/**
|
|
* What a key does in a box. `"submit"`: prevent the browser's default and
|
|
* submit. `"block"`: prevent the default and do nothing (it would submit, but
|
|
* may not now). `"type"`: not the box's key; leave it to the browser.
|
|
*/
|
|
export type SubmitKeyAction = "submit" | "block" | "type";
|
|
/**
|
|
* THE submit-key rule, the same in every box of every app:
|
|
* - a composer: Enter sends, Shift+Enter breaks the line;
|
|
* - a multi-line field: Cmd+Enter or Ctrl+Enter submits, Enter breaks the line;
|
|
* - a one-line field: Enter submits; Shift+Enter and Alt+Enter do nothing
|
|
* (the browser would otherwise post the native form).
|
|
* Never during an IME composition (an Enter that chooses a word is left to
|
|
* the browser), and never while a take is recorded or transcribed (`busy`) or
|
|
* the box may not change (`locked`: disabled, read-only) — then the key that
|
|
* would submit is swallowed, so a form is not posted mid-take without the
|
|
* words.
|
|
*/
|
|
export declare function submitKeyAction(event: SubmitKeyEvent, { shape, busy, locked }: {
|
|
shape: TypingShape;
|
|
busy?: boolean;
|
|
locked?: boolean;
|
|
}): SubmitKeyAction;
|
|
/** `75` → `1:15`. The recording timer. */
|
|
export declare function formatElapsed(seconds: number): string;
|
|
//# sourceMappingURL=composer.d.ts.map
|