@epicbagel/saas-kit 1.11.0 → 1.11.1
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/README.md +15 -8
- package/dist/chunk-D47AMKT4.cjs +293 -0
- package/dist/chunk-EDEN7TAL.js +293 -0
- package/dist/{chunk-UOVA4YKW.js → chunk-KF4X37DP.js} +2 -15
- package/dist/{chunk-7QTFYEPE.cjs → chunk-YMI3X2YL.cjs} +2 -15
- package/dist/primitives/chat.cjs +8 -8
- package/dist/primitives/chat.js +2 -2
- package/dist/primitives/voice-dictation-button.cjs +2 -2
- package/dist/primitives/voice-dictation-button.d.cts +8 -6
- package/dist/primitives/voice-dictation-button.d.ts +8 -6
- package/dist/primitives/voice-dictation-button.js +1 -1
- package/dist/primitives/voice-session-controls.cjs +2 -2
- package/dist/primitives/voice-session-controls.d.cts +2 -2
- package/dist/primitives/voice-session-controls.d.ts +2 -2
- package/dist/primitives/voice-session-controls.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-KQBXAQAY.cjs +0 -221
- package/dist/chunk-T3XMHWYV.js +0 -221
package/dist/chunk-T3XMHWYV.js
DELETED
|
@@ -1,221 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import {
|
|
3
|
-
AgentAudioVisualizerBar
|
|
4
|
-
} from "./chunk-5OF6D3GH.js";
|
|
5
|
-
import {
|
|
6
|
-
Button
|
|
7
|
-
} from "./chunk-W326GKML.js";
|
|
8
|
-
import {
|
|
9
|
-
cn
|
|
10
|
-
} from "./chunk-G6SRSWXB.js";
|
|
11
|
-
import {
|
|
12
|
-
useDictation
|
|
13
|
-
} from "./chunk-HLAHOVEI.js";
|
|
14
|
-
|
|
15
|
-
// src/primitives/voice-dictation-button.tsx
|
|
16
|
-
import {
|
|
17
|
-
useCallback,
|
|
18
|
-
useEffect,
|
|
19
|
-
useRef,
|
|
20
|
-
useState,
|
|
21
|
-
useSyncExternalStore
|
|
22
|
-
} from "react";
|
|
23
|
-
import * as DialogPrimitive from "@radix-ui/react-dialog";
|
|
24
|
-
import { Mic, LoaderCircle } from "lucide-react";
|
|
25
|
-
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
26
|
-
function VoiceDictationButton({
|
|
27
|
-
onCommit,
|
|
28
|
-
onCancel,
|
|
29
|
-
title = "Dictate your message",
|
|
30
|
-
caption = "Recording",
|
|
31
|
-
lang = "en-US",
|
|
32
|
-
continuous = true,
|
|
33
|
-
className,
|
|
34
|
-
size = "sm",
|
|
35
|
-
showLabel = false,
|
|
36
|
-
children,
|
|
37
|
-
disabled = false,
|
|
38
|
-
visibility = "visible",
|
|
39
|
-
shrink = true
|
|
40
|
-
}) {
|
|
41
|
-
const [open, setOpen] = useState(false);
|
|
42
|
-
const capture = useDictation({ lang, continuous });
|
|
43
|
-
const { transcript, interimTranscript: interim, supported, error } = capture;
|
|
44
|
-
const generation = useRef(0);
|
|
45
|
-
const finishing = useRef(false);
|
|
46
|
-
const previousFocus = useRef(null);
|
|
47
|
-
const elapsed = useRecordingTime(capture.state);
|
|
48
|
-
const busy = capture.state === "requesting" || capture.state === "transcribing";
|
|
49
|
-
const openOverlay = useCallback(() => {
|
|
50
|
-
previousFocus.current = document.activeElement instanceof HTMLElement ? document.activeElement : null;
|
|
51
|
-
generation.current++;
|
|
52
|
-
finishing.current = false;
|
|
53
|
-
setOpen(true);
|
|
54
|
-
void capture.start();
|
|
55
|
-
}, [capture.start]);
|
|
56
|
-
const closeOverlay = useCallback(() => {
|
|
57
|
-
generation.current++;
|
|
58
|
-
finishing.current = false;
|
|
59
|
-
capture.cancel();
|
|
60
|
-
setOpen(false);
|
|
61
|
-
}, [capture.cancel]);
|
|
62
|
-
const handleDone = useCallback(async () => {
|
|
63
|
-
if (finishing.current || busy) return;
|
|
64
|
-
if (capture.state === "error" && !capture.canRetry) {
|
|
65
|
-
void capture.start();
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
68
|
-
finishing.current = true;
|
|
69
|
-
const started = generation.current;
|
|
70
|
-
const final = await (capture.canRetry ? capture.retry() : capture.stop());
|
|
71
|
-
if (started !== generation.current) return;
|
|
72
|
-
finishing.current = false;
|
|
73
|
-
if (final === null) return;
|
|
74
|
-
closeOverlay();
|
|
75
|
-
if (final) onCommit(final);
|
|
76
|
-
else onCancel?.();
|
|
77
|
-
}, [busy, capture.canRetry, capture.retry, capture.start, capture.state, capture.stop, onCommit, onCancel, closeOverlay]);
|
|
78
|
-
const handleCancel = useCallback(() => {
|
|
79
|
-
closeOverlay();
|
|
80
|
-
onCancel?.();
|
|
81
|
-
}, [closeOverlay, onCancel]);
|
|
82
|
-
useEffect(() => {
|
|
83
|
-
if (open && capture.state === "idle") handleCancel();
|
|
84
|
-
}, [capture.state, handleCancel, open]);
|
|
85
|
-
useEffect(() => {
|
|
86
|
-
return () => {
|
|
87
|
-
generation.current++;
|
|
88
|
-
};
|
|
89
|
-
}, []);
|
|
90
|
-
if (!supported) return null;
|
|
91
|
-
const displayTranscript = `${transcript}${interim ? (transcript ? " " : "") + interim : ""}`;
|
|
92
|
-
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
93
|
-
children ? /* @__PURE__ */ jsx(
|
|
94
|
-
"button",
|
|
95
|
-
{
|
|
96
|
-
type: "button",
|
|
97
|
-
onClick: openOverlay,
|
|
98
|
-
disabled,
|
|
99
|
-
"aria-label": "Start dictation",
|
|
100
|
-
className: cn(visibility === "hidden" && "hidden", className),
|
|
101
|
-
children
|
|
102
|
-
}
|
|
103
|
-
) : /* @__PURE__ */ jsx(
|
|
104
|
-
Button,
|
|
105
|
-
{
|
|
106
|
-
type: "button",
|
|
107
|
-
onClick: openOverlay,
|
|
108
|
-
disabled,
|
|
109
|
-
variant: "outline",
|
|
110
|
-
size,
|
|
111
|
-
"aria-label": "Start dictation",
|
|
112
|
-
className: cn("transition-colors", visibility === "hidden" && "hidden", !shrink && "shrink-0", className),
|
|
113
|
-
children: /* @__PURE__ */ jsxs("span", { className: "flex items-center justify-center gap-2", children: [
|
|
114
|
-
/* @__PURE__ */ jsx(Mic, { className: "h-4 w-4" }),
|
|
115
|
-
showLabel && /* @__PURE__ */ jsx("span", { children: "Speak" })
|
|
116
|
-
] })
|
|
117
|
-
}
|
|
118
|
-
),
|
|
119
|
-
/* @__PURE__ */ jsx(
|
|
120
|
-
DialogPrimitive.Root,
|
|
121
|
-
{
|
|
122
|
-
open,
|
|
123
|
-
onOpenChange: (next) => {
|
|
124
|
-
if (!next) handleCancel();
|
|
125
|
-
},
|
|
126
|
-
children: /* @__PURE__ */ jsx(DialogPrimitive.Portal, { children: /* @__PURE__ */ jsxs(
|
|
127
|
-
DialogPrimitive.Content,
|
|
128
|
-
{
|
|
129
|
-
"aria-label": "Voice dictation",
|
|
130
|
-
"aria-labelledby": void 0,
|
|
131
|
-
"data-slot": "voice-dictation-panel",
|
|
132
|
-
"data-state": capture.state,
|
|
133
|
-
onCloseAutoFocus: (event) => {
|
|
134
|
-
event.preventDefault();
|
|
135
|
-
if (previousFocus.current?.isConnected) previousFocus.current.focus();
|
|
136
|
-
},
|
|
137
|
-
onKeyDown: (event) => {
|
|
138
|
-
if (event.key === "Enter" && !event.shiftKey && !(event.target instanceof HTMLElement && event.target.closest("button, input, textarea, select"))) {
|
|
139
|
-
event.preventDefault();
|
|
140
|
-
void handleDone();
|
|
141
|
-
}
|
|
142
|
-
},
|
|
143
|
-
className: "fixed bottom-4 left-1/2 z-[200] flex max-h-[calc(100dvh-2rem)] w-[calc(100%-2rem)] max-w-sm -translate-x-1/2 flex-col gap-3 overflow-y-auto rounded-2xl border border-border bg-background p-4 text-foreground shadow-lg outline-hidden sm:bottom-6",
|
|
144
|
-
children: [
|
|
145
|
-
/* @__PURE__ */ jsxs("div", { className: "flex min-w-0 items-start justify-between gap-3", children: [
|
|
146
|
-
/* @__PURE__ */ jsxs("div", { className: "min-w-0 space-y-1", children: [
|
|
147
|
-
/* @__PURE__ */ jsx(DialogPrimitive.Title, { className: "text-sm font-medium", children: title || "Voice dictation" }),
|
|
148
|
-
/* @__PURE__ */ jsxs("span", { role: "status", className: "flex items-center gap-1.5 text-xs text-muted-foreground", children: [
|
|
149
|
-
busy ? /* @__PURE__ */ jsx(LoaderCircle, { "aria-hidden": "true", className: "size-3.5 animate-spin motion-reduce:animate-none" }) : /* @__PURE__ */ jsx(Mic, { "aria-hidden": "true", className: "size-3.5" }),
|
|
150
|
-
capture.state === "transcribing" ? "Transcribing\u2026" : capture.state === "requesting" ? "Waiting for microphone\u2026" : error ? "Recording not saved" : capture.state === "ready" ? "Ready" : caption
|
|
151
|
-
] })
|
|
152
|
-
] }),
|
|
153
|
-
/* @__PURE__ */ jsxs("time", { "aria-label": "Recording duration", dateTime: `PT${elapsed}S`, className: "pt-0.5 font-mono text-xs tabular-nums text-muted-foreground", children: [
|
|
154
|
-
Math.floor(elapsed / 60).toString().padStart(2, "0"),
|
|
155
|
-
":",
|
|
156
|
-
(elapsed % 60).toString().padStart(2, "0")
|
|
157
|
-
] })
|
|
158
|
-
] }),
|
|
159
|
-
capture.audioLevels && /* @__PURE__ */ jsx(DictationWaveform, { source: capture.audioLevels, state: capture.state }),
|
|
160
|
-
/* @__PURE__ */ jsx(DialogPrimitive.Description, { className: "text-xs text-muted-foreground", children: capture.state === "transcribing" ? "Converting your recording to text\u2026" : capture.state === "requesting" ? "Allow microphone access to start." : error ? capture.canRetry ? "Retry this take or record again." : "Check microphone access, then try again." : "Speak, then choose Done to add the text." }),
|
|
161
|
-
displayTranscript && /* @__PURE__ */ jsxs("p", { className: "max-h-24 overflow-y-auto text-sm leading-relaxed", children: [
|
|
162
|
-
transcript,
|
|
163
|
-
interim && /* @__PURE__ */ jsxs("span", { className: "text-muted-foreground", children: [
|
|
164
|
-
transcript ? " " : "",
|
|
165
|
-
interim
|
|
166
|
-
] })
|
|
167
|
-
] }),
|
|
168
|
-
error && /* @__PURE__ */ jsx("p", { role: "alert", className: "text-xs text-destructive", children: error }),
|
|
169
|
-
/* @__PURE__ */ jsxs("div", { className: "flex flex-wrap items-center justify-end gap-2", children: [
|
|
170
|
-
/* @__PURE__ */ jsx(Button, { type: "button", variant: "ghost", size: "sm", className: "min-h-[44px]", onClick: handleCancel, children: "Cancel" }),
|
|
171
|
-
capture.canRetry && /* @__PURE__ */ jsx(Button, { type: "button", variant: "outline", size: "sm", className: "min-h-[44px]", onClick: () => void capture.start(), children: "Record again" }),
|
|
172
|
-
/* @__PURE__ */ jsx(Button, { type: "button", size: "sm", className: "min-h-[44px]", onClick: () => void handleDone(), disabled: busy, children: capture.state === "transcribing" ? "Transcribing\u2026" : capture.canRetry ? "Retry transcription" : error ? "Try again" : "Done" })
|
|
173
|
-
] })
|
|
174
|
-
]
|
|
175
|
-
}
|
|
176
|
-
) })
|
|
177
|
-
}
|
|
178
|
-
)
|
|
179
|
-
] });
|
|
180
|
-
}
|
|
181
|
-
var SILENCE = [];
|
|
182
|
-
var silence = () => SILENCE;
|
|
183
|
-
function DictationWaveform({ source, state }) {
|
|
184
|
-
const bands = useSyncExternalStore(source.subscribe, source.getSnapshot, silence);
|
|
185
|
-
return /* @__PURE__ */ jsx(
|
|
186
|
-
AgentAudioVisualizerBar,
|
|
187
|
-
{
|
|
188
|
-
"aria-hidden": "true",
|
|
189
|
-
"data-slot": "dictation-waveform",
|
|
190
|
-
size: "icon",
|
|
191
|
-
barCount: 24,
|
|
192
|
-
state: state === "recording" ? "listening" : state === "transcribing" ? "thinking" : state === "requesting" ? "connecting" : "disconnected",
|
|
193
|
-
volumeBands: state === "recording" ? bands : void 0,
|
|
194
|
-
className: "h-9 w-full text-foreground"
|
|
195
|
-
}
|
|
196
|
-
);
|
|
197
|
-
}
|
|
198
|
-
function useRecordingTime(state) {
|
|
199
|
-
const [elapsed, setElapsed] = useState(0);
|
|
200
|
-
const startedAt = useRef(null);
|
|
201
|
-
useEffect(() => {
|
|
202
|
-
if (state !== "recording") {
|
|
203
|
-
if (state === "idle" || state === "requesting") setElapsed(0);
|
|
204
|
-
else if (startedAt.current !== null) setElapsed(Math.floor((performance.now() - startedAt.current) / 1e3));
|
|
205
|
-
startedAt.current = null;
|
|
206
|
-
return;
|
|
207
|
-
}
|
|
208
|
-
startedAt.current = performance.now();
|
|
209
|
-
const update = () => setElapsed(Math.floor((performance.now() - startedAt.current) / 1e3));
|
|
210
|
-
update();
|
|
211
|
-
const timer = setInterval(update, 1e3);
|
|
212
|
-
return () => {
|
|
213
|
-
clearInterval(timer);
|
|
214
|
-
};
|
|
215
|
-
}, [state]);
|
|
216
|
-
return elapsed;
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
export {
|
|
220
|
-
VoiceDictationButton
|
|
221
|
-
};
|