Files
CatoandClaude 6451d3b9d0 feat(react): DictationField and CommentThread — any text box has the microphone (#73)
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>
2026-11-06 09:22:19 +01:00

43 lines
3.3 KiB
JavaScript

"use client";
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
import { useEffect, useRef, useState } from "react";
import { formatElapsed } from "../composer.js";
import { IconCheck, IconSpinner, IconX } from "./icons.js";
/**
* What has been heard so far, as one line that follows the end of the words:
* a long sentence scrolls with the speaker instead of freezing on its start.
*/
function LiveWords({ text, dim }) {
const ref = useRef(null);
useEffect(() => {
const el = ref.current;
if (el)
el.scrollLeft = el.scrollWidth;
}, [text]);
return (_jsx("span", { ref: ref, className: dim ? "ck-voice-live ck-voice-live-dim" : "ck-voice-live", children: text }));
}
function Elapsed({ since }) {
const [now, setNow] = useState(() => Date.now());
useEffect(() => {
if (since === null)
return;
const t = setInterval(() => setNow(Date.now()), 250);
return () => clearInterval(t);
}, [since]);
return (_jsx("span", { className: "ck-voice-timer", children: formatElapsed(since === null ? 0 : (now - since) / 1000) }));
}
/** Covers its positioned parent while a take is live or being written down. */
export function VoiceBar({ dictation, labels, }) {
const listening = dictation.status === "listening";
const transcribing = dictation.status === "transcribing";
if (!listening && !transcribing)
return null;
return (_jsx("div", { className: "ck-voice-bar", role: "status", "aria-live": "polite", children: listening ? (_jsxs(_Fragment, { children: [_jsx("span", { className: "ck-voice-dot", "aria-hidden": true }), dictation.liveText ? (_jsx(LiveWords, { text: dictation.liveText })) : (_jsx("span", { className: "ck-voice-wave", "aria-hidden": true, children: Array.from({ length: 9 }).map((_, i) => (_jsx("span", {}, i))) })), _jsx(Elapsed, { since: dictation.startedAt }), _jsx("button", { type: "button", className: "ck-icon-btn", onClick: dictation.cancel, "aria-label": labels.cancelRecording, title: labels.cancelRecording, children: _jsx(IconX, {}) }), _jsx("button", { type: "button", className: "ck-voice-confirm", onClick: dictation.stop, "aria-label": labels.confirmRecording, title: labels.confirmRecording, children: _jsx(IconCheck, {}) })] })) : (_jsxs(_Fragment, { children: [_jsx(IconSpinner, {}), dictation.liveText ? (_jsx(LiveWords, { text: dictation.liveText, dim: true })) : (_jsx("span", { className: "ck-voice-timer", children: labels.transcribing }))] })) }));
}
/** A mic failure, in words, with the way forward: try the kept take again, or dismiss. */
export function VoiceProblem({ dictation, labels, }) {
if (!dictation.problem)
return null;
return (_jsxs("p", { className: "ck-problem", role: "status", children: [_jsxs("span", { children: [labels.dictation[dictation.problem], dictation.problemDetail && (_jsxs("span", { className: "ck-problem-detail", children: [" ", dictation.problemDetail] }))] }), dictation.canRetry && (_jsx("button", { type: "button", className: "ck-problem-retry", onClick: () => void dictation.retry(), disabled: dictation.status !== "idle", children: labels.retryTake })), _jsx("button", { type: "button", className: "ck-problem-x", onClick: dictation.clearProblem, "aria-label": labels.dismiss, children: _jsx(IconX, {}) })] }));
}
//# sourceMappingURL=Voice.js.map