@epicbagel/saas-kit 1.0.0 → 1.1.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.
- package/README.md +38 -1
- package/THIRD_PARTY_NOTICES.md +13 -7
- package/dist/chunk-2AU7ZRGX.cjs +96 -0
- package/dist/chunk-2BTDBZYN.cjs +154 -0
- package/dist/chunk-2HV2KKOE.cjs +38 -0
- package/dist/chunk-2KFZQJH5.cjs +29 -0
- package/dist/chunk-32Q4XOTU.cjs +204 -0
- package/dist/chunk-42RTTHND.js +29 -0
- package/dist/chunk-6FC65AZQ.js +38 -0
- package/dist/chunk-6V4XMQ6D.js +118 -0
- package/dist/chunk-B765DSRG.cjs +66 -0
- package/dist/chunk-ELPV44S6.cjs +44 -0
- package/dist/chunk-EOUO3ORO.cjs +244 -0
- package/dist/chunk-EZCKWTH7.js +204 -0
- package/dist/chunk-F366BHWH.js +116 -0
- package/dist/chunk-GFG2R5BZ.js +132 -0
- package/dist/chunk-HAC32ALJ.js +244 -0
- package/dist/chunk-I5UQSBBZ.cjs +118 -0
- package/dist/chunk-INNGGLMZ.js +44 -0
- package/dist/chunk-IW4ZIXXG.js +66 -0
- package/dist/chunk-JZOBIPFC.js +96 -0
- package/dist/chunk-KENBU3NV.cjs +27 -0
- package/dist/chunk-MHYAVXOE.js +159 -0
- package/dist/chunk-RIWLAMME.cjs +159 -0
- package/dist/chunk-SUB4BAYE.cjs +73 -0
- package/dist/chunk-THWIJG5C.js +73 -0
- package/dist/chunk-V4YWTRLD.cjs +116 -0
- package/dist/chunk-VY5U4VGV.js +27 -0
- package/dist/chunk-XABXUP6L.cjs +132 -0
- package/dist/chunk-Z45YKVAM.js +154 -0
- package/dist/primitives/action-dock.cjs +8 -0
- package/dist/primitives/action-dock.d.cts +10 -0
- package/dist/primitives/action-dock.d.ts +10 -0
- package/dist/primitives/action-dock.js +8 -0
- package/dist/primitives/alert.d.cts +1 -1
- package/dist/primitives/alert.d.ts +1 -1
- package/dist/primitives/attachment.cjs +25 -203
- package/dist/primitives/attachment.d.cts +1 -1
- package/dist/primitives/attachment.d.ts +1 -1
- package/dist/primitives/attachment.js +12 -190
- package/dist/primitives/badge.d.cts +1 -1
- package/dist/primitives/badge.d.ts +1 -1
- package/dist/primitives/board-view.cjs +3 -3
- package/dist/primitives/board-view.js +2 -2
- package/dist/primitives/bubble.cjs +14 -0
- package/dist/primitives/bubble.d.cts +21 -0
- package/dist/primitives/bubble.d.ts +21 -0
- package/dist/primitives/bubble.js +14 -0
- package/dist/primitives/button.d.cts +2 -2
- package/dist/primitives/button.d.ts +2 -2
- package/dist/primitives/chat.cjs +864 -0
- package/dist/primitives/chat.d.cts +326 -0
- package/dist/primitives/chat.d.ts +326 -0
- package/dist/primitives/chat.js +864 -0
- package/dist/primitives/connection.cjs +6 -6
- package/dist/primitives/connection.js +7 -7
- package/dist/primitives/file-dropzone.cjs +7 -113
- package/dist/primitives/file-dropzone.js +6 -112
- package/dist/primitives/input-group.cjs +21 -0
- package/dist/primitives/input-group.d.cts +20 -0
- package/dist/primitives/input-group.d.ts +20 -0
- package/dist/primitives/input-group.js +21 -0
- package/dist/primitives/item.cjs +197 -0
- package/dist/primitives/item.d.cts +28 -0
- package/dist/primitives/item.d.ts +28 -0
- package/dist/primitives/item.js +197 -0
- package/dist/primitives/lazy-markdown.cjs +10 -0
- package/dist/primitives/lazy-markdown.d.cts +20 -0
- package/dist/primitives/lazy-markdown.d.ts +20 -0
- package/dist/primitives/lazy-markdown.js +10 -0
- package/dist/primitives/markdown.cjs +17 -0
- package/dist/primitives/markdown.d.cts +32 -0
- package/dist/primitives/markdown.d.ts +32 -0
- package/dist/primitives/markdown.js +17 -0
- package/dist/primitives/marker.cjs +14 -0
- package/dist/primitives/marker.d.cts +15 -0
- package/dist/primitives/marker.d.ts +15 -0
- package/dist/primitives/marker.js +14 -0
- package/dist/primitives/message-scroller.cjs +26 -0
- package/dist/primitives/message-scroller.d.cts +16 -0
- package/dist/primitives/message-scroller.d.ts +16 -0
- package/dist/primitives/message-scroller.js +26 -0
- package/dist/primitives/message.cjs +7 -84
- package/dist/primitives/message.js +8 -85
- package/dist/primitives/resource-list.cjs +3 -3
- package/dist/primitives/resource-list.js +2 -2
- package/dist/primitives/rich-text.cjs +3 -38
- package/dist/primitives/rich-text.js +3 -38
- package/dist/primitives/section-header.d.cts +1 -1
- package/dist/primitives/section-header.d.ts +1 -1
- package/dist/primitives/spinner.cjs +23 -0
- package/dist/primitives/spinner.d.cts +6 -0
- package/dist/primitives/spinner.d.ts +6 -0
- package/dist/primitives/spinner.js +23 -0
- package/dist/primitives/suggestion.cjs +11 -0
- package/dist/primitives/suggestion.d.cts +19 -0
- package/dist/primitives/suggestion.d.ts +19 -0
- package/dist/primitives/suggestion.js +11 -0
- package/dist/primitives/switch-field.cjs +2 -2
- package/dist/primitives/switch-field.js +3 -3
- package/dist/primitives/textarea.cjs +4 -33
- package/dist/primitives/textarea.js +3 -32
- package/dist/primitives/toggle-group.d.cts +2 -2
- package/dist/primitives/toggle-group.d.ts +2 -2
- package/dist/primitives/toggle.d.cts +2 -2
- package/dist/primitives/toggle.d.ts +2 -2
- package/dist/primitives/trace.cjs +23 -0
- package/dist/primitives/trace.d.cts +22 -0
- package/dist/primitives/trace.d.ts +22 -0
- package/dist/primitives/trace.js +23 -0
- package/dist/primitives/voice-dictation-button.cjs +5 -239
- package/dist/primitives/voice-dictation-button.js +4 -238
- package/package.json +125 -2
- package/src/styles/components/bubble.css +81 -0
- package/src/styles/components/marker.css +27 -0
- package/src/styles/components/message-scroller.css +11 -0
- package/src/styles/components.css +3 -0
- package/src/styles/utilities.css +3 -2
- package/dist/{chunk-UGF2K6NR.js → chunk-HRLP4BHJ.js} +6 -6
- package/dist/{chunk-RWWOFWLP.cjs → chunk-IH3COANJ.cjs} +3 -3
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import {
|
|
3
|
+
Trace,
|
|
4
|
+
TraceCollapsible,
|
|
5
|
+
TraceCollapsibleContent,
|
|
6
|
+
TraceCollapsibleTrigger,
|
|
7
|
+
TraceDescription,
|
|
8
|
+
TraceIcon,
|
|
9
|
+
TraceLine,
|
|
10
|
+
TraceTitle
|
|
11
|
+
} from "../chunk-Z45YKVAM.js";
|
|
12
|
+
import "../chunk-NBUWGRQO.js";
|
|
13
|
+
import "../chunk-G6SRSWXB.js";
|
|
14
|
+
export {
|
|
15
|
+
Trace,
|
|
16
|
+
TraceCollapsible,
|
|
17
|
+
TraceCollapsibleContent,
|
|
18
|
+
TraceCollapsibleTrigger,
|
|
19
|
+
TraceDescription,
|
|
20
|
+
TraceIcon,
|
|
21
|
+
TraceLine,
|
|
22
|
+
TraceTitle
|
|
23
|
+
};
|
|
@@ -1,244 +1,10 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});"use client";
|
|
2
2
|
"use client";
|
|
3
3
|
|
|
4
4
|
|
|
5
|
-
var
|
|
5
|
+
var _chunkEOUO3OROcjs = require('../chunk-EOUO3ORO.cjs');
|
|
6
|
+
require('../chunk-L4DH72UF.cjs');
|
|
7
|
+
require('../chunk-KWLSBTB2.cjs');
|
|
6
8
|
|
|
7
9
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
// src/primitives/voice-dictation-button.tsx
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
var _react = require('react');
|
|
17
|
-
var _reactdialog = require('@radix-ui/react-dialog'); var DialogPrimitive = _interopRequireWildcard(_reactdialog);
|
|
18
|
-
var _lucidereact = require('lucide-react');
|
|
19
|
-
var _jsxruntime = require('react/jsx-runtime');
|
|
20
|
-
function VoiceDictationButton({
|
|
21
|
-
onCommit,
|
|
22
|
-
onCancel,
|
|
23
|
-
title = "Dictate your message",
|
|
24
|
-
caption = "listening",
|
|
25
|
-
lang = "en-US",
|
|
26
|
-
continuous = true,
|
|
27
|
-
className,
|
|
28
|
-
size = "sm",
|
|
29
|
-
showLabel = false,
|
|
30
|
-
children,
|
|
31
|
-
disabled = false,
|
|
32
|
-
visibility = "visible",
|
|
33
|
-
shrink = true
|
|
34
|
-
}) {
|
|
35
|
-
const [supported, setSupported] = _react.useState.call(void 0, false);
|
|
36
|
-
const [open, setOpen] = _react.useState.call(void 0, false);
|
|
37
|
-
const [transcript, setTranscript] = _react.useState.call(void 0, "");
|
|
38
|
-
const [interim, setInterim] = _react.useState.call(void 0, "");
|
|
39
|
-
const [errored, setErrored] = _react.useState.call(void 0, false);
|
|
40
|
-
const recognitionRef = _react.useRef.call(void 0, null);
|
|
41
|
-
_react.useEffect.call(void 0, () => {
|
|
42
|
-
const w = window;
|
|
43
|
-
const Ctor = _nullishCoalesce(w.SpeechRecognition, () => ( w.webkitSpeechRecognition));
|
|
44
|
-
setSupported(typeof Ctor === "function");
|
|
45
|
-
}, []);
|
|
46
|
-
const stop = _react.useCallback.call(void 0, () => {
|
|
47
|
-
_optionalChain([recognitionRef, 'access', _ => _.current, 'optionalAccess', _2 => _2.stop, 'call', _3 => _3()]);
|
|
48
|
-
recognitionRef.current = null;
|
|
49
|
-
}, []);
|
|
50
|
-
const startRecognition = _react.useCallback.call(void 0, () => {
|
|
51
|
-
const w = window;
|
|
52
|
-
const Ctor = _nullishCoalesce(w.SpeechRecognition, () => ( w.webkitSpeechRecognition));
|
|
53
|
-
if (!Ctor) return;
|
|
54
|
-
const rec = new Ctor();
|
|
55
|
-
rec.continuous = continuous;
|
|
56
|
-
rec.interimResults = true;
|
|
57
|
-
rec.lang = lang;
|
|
58
|
-
rec.onresult = (event) => {
|
|
59
|
-
let finalChunk = "";
|
|
60
|
-
let interimChunk = "";
|
|
61
|
-
for (let i = event.resultIndex; i < event.results.length; i++) {
|
|
62
|
-
const r = event.results[i];
|
|
63
|
-
if (!r) continue;
|
|
64
|
-
if (r.isFinal) finalChunk += r[0].transcript;
|
|
65
|
-
else interimChunk += r[0].transcript;
|
|
66
|
-
}
|
|
67
|
-
if (finalChunk) {
|
|
68
|
-
setTranscript((prev) => prev ? prev + " " + finalChunk : finalChunk);
|
|
69
|
-
setInterim("");
|
|
70
|
-
} else if (interimChunk) {
|
|
71
|
-
setInterim(interimChunk);
|
|
72
|
-
}
|
|
73
|
-
};
|
|
74
|
-
rec.onerror = () => {
|
|
75
|
-
setErrored(true);
|
|
76
|
-
};
|
|
77
|
-
rec.onend = () => {
|
|
78
|
-
recognitionRef.current = null;
|
|
79
|
-
};
|
|
80
|
-
recognitionRef.current = rec;
|
|
81
|
-
setErrored(false);
|
|
82
|
-
rec.start();
|
|
83
|
-
}, [continuous, lang]);
|
|
84
|
-
const openOverlay = _react.useCallback.call(void 0, () => {
|
|
85
|
-
setTranscript("");
|
|
86
|
-
setInterim("");
|
|
87
|
-
setOpen(true);
|
|
88
|
-
startRecognition();
|
|
89
|
-
}, [startRecognition]);
|
|
90
|
-
const closeOverlay = _react.useCallback.call(void 0, () => {
|
|
91
|
-
stop();
|
|
92
|
-
setOpen(false);
|
|
93
|
-
setInterim("");
|
|
94
|
-
}, [stop]);
|
|
95
|
-
const handleDone = _react.useCallback.call(void 0, () => {
|
|
96
|
-
const final = `${transcript} ${interim}`.trim();
|
|
97
|
-
closeOverlay();
|
|
98
|
-
if (final) onCommit(final);
|
|
99
|
-
else _optionalChain([onCancel, 'optionalCall', _4 => _4()]);
|
|
100
|
-
}, [transcript, interim, onCommit, onCancel, closeOverlay]);
|
|
101
|
-
const handleCancel = _react.useCallback.call(void 0, () => {
|
|
102
|
-
closeOverlay();
|
|
103
|
-
_optionalChain([onCancel, 'optionalCall', _5 => _5()]);
|
|
104
|
-
}, [closeOverlay, onCancel]);
|
|
105
|
-
_react.useEffect.call(void 0, () => {
|
|
106
|
-
if (!open) return;
|
|
107
|
-
const onKey = (e) => {
|
|
108
|
-
if (e.key === "Enter" && !e.shiftKey) handleDone();
|
|
109
|
-
};
|
|
110
|
-
document.addEventListener("keydown", onKey);
|
|
111
|
-
return () => document.removeEventListener("keydown", onKey);
|
|
112
|
-
}, [open, handleDone]);
|
|
113
|
-
_react.useEffect.call(void 0, () => {
|
|
114
|
-
return () => {
|
|
115
|
-
_optionalChain([recognitionRef, 'access', _6 => _6.current, 'optionalAccess', _7 => _7.abort, 'call', _8 => _8()]);
|
|
116
|
-
};
|
|
117
|
-
}, []);
|
|
118
|
-
if (!supported) return null;
|
|
119
|
-
const displayTranscript = `${transcript}${interim ? (transcript ? " " : "") + interim : ""}`;
|
|
120
|
-
return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _jsxruntime.Fragment, { children: [
|
|
121
|
-
children ? /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
122
|
-
"button",
|
|
123
|
-
{
|
|
124
|
-
type: "button",
|
|
125
|
-
onClick: openOverlay,
|
|
126
|
-
disabled,
|
|
127
|
-
"aria-label": "Start dictation",
|
|
128
|
-
className: _chunkKWLSBTB2cjs.cn.call(void 0, visibility === "hidden" && "hidden", className),
|
|
129
|
-
children
|
|
130
|
-
}
|
|
131
|
-
) : /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
132
|
-
_chunkL4DH72UFcjs.Button,
|
|
133
|
-
{
|
|
134
|
-
type: "button",
|
|
135
|
-
onClick: openOverlay,
|
|
136
|
-
disabled,
|
|
137
|
-
variant: "outline",
|
|
138
|
-
size,
|
|
139
|
-
"aria-label": "Start dictation",
|
|
140
|
-
className: _chunkKWLSBTB2cjs.cn.call(void 0, "transition-colors", visibility === "hidden" && "hidden", !shrink && "shrink-0", className),
|
|
141
|
-
children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "span", { className: "flex items-center justify-center gap-2", children: [
|
|
142
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _lucidereact.Mic, { className: "h-4 w-4" }),
|
|
143
|
-
showLabel && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { children: "Speak" })
|
|
144
|
-
] })
|
|
145
|
-
}
|
|
146
|
-
),
|
|
147
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
148
|
-
DialogPrimitive.Root,
|
|
149
|
-
{
|
|
150
|
-
open,
|
|
151
|
-
onOpenChange: (next) => {
|
|
152
|
-
if (!next) closeOverlay();
|
|
153
|
-
},
|
|
154
|
-
children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, DialogPrimitive.Portal, { children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0,
|
|
155
|
-
DialogPrimitive.Content,
|
|
156
|
-
{
|
|
157
|
-
"aria-label": "Voice dictation",
|
|
158
|
-
onOpenAutoFocus: (e) => e.preventDefault(),
|
|
159
|
-
onMouseDown: (e) => {
|
|
160
|
-
if (e.target === e.currentTarget) handleCancel();
|
|
161
|
-
},
|
|
162
|
-
className: "fixed inset-0 z-[200] flex flex-col bg-background outline-hidden md:items-center md:justify-center md:bg-black/40 md:backdrop-blur-sm",
|
|
163
|
-
children: [
|
|
164
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, DialogPrimitive.Title, { className: "sr-only", children: "Voice dictation" }),
|
|
165
|
-
/* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "flex-1 md:flex-initial w-full md:max-w-lg md:rounded-xl bg-background flex flex-col md:max-h-[80vh] md:shadow-2xl md:border md:border-border", children: [
|
|
166
|
-
/* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "flex items-center justify-between px-4 py-3 border-b border-border md:rounded-t-xl", children: [
|
|
167
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { className: "font-mono text-xs uppercase tracking-wider text-muted-foreground", children: caption }),
|
|
168
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
169
|
-
"button",
|
|
170
|
-
{
|
|
171
|
-
type: "button",
|
|
172
|
-
onClick: handleCancel,
|
|
173
|
-
"aria-label": "Cancel",
|
|
174
|
-
className: "p-1 -m-1 rounded-sm hover:bg-muted/60 transition-colors",
|
|
175
|
-
children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _lucidereact.X, { className: "h-4 w-4" })
|
|
176
|
-
}
|
|
177
|
-
)
|
|
178
|
-
] }),
|
|
179
|
-
/* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "flex-1 flex flex-col items-center justify-center px-6 text-center", children: [
|
|
180
|
-
/* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "relative w-24 h-24 mb-10 flex items-center justify-center", children: [
|
|
181
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
182
|
-
"span",
|
|
183
|
-
{
|
|
184
|
-
"aria-hidden": true,
|
|
185
|
-
className: _chunkKWLSBTB2cjs.cn.call(void 0,
|
|
186
|
-
"absolute inset-0 rounded-full",
|
|
187
|
-
errored ? "bg-destructive/20" : "bg-destructive/20 animate-ping"
|
|
188
|
-
)
|
|
189
|
-
}
|
|
190
|
-
),
|
|
191
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
192
|
-
"span",
|
|
193
|
-
{
|
|
194
|
-
"aria-hidden": true,
|
|
195
|
-
className: _chunkKWLSBTB2cjs.cn.call(void 0,
|
|
196
|
-
"absolute inset-2 rounded-full",
|
|
197
|
-
errored ? "bg-destructive/40" : "bg-destructive/40"
|
|
198
|
-
)
|
|
199
|
-
}
|
|
200
|
-
),
|
|
201
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _lucidereact.Mic, { className: "relative h-9 w-9 text-destructive-foreground" })
|
|
202
|
-
] }),
|
|
203
|
-
title && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "text-base font-medium text-muted-foreground mb-3", children: title }),
|
|
204
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "p", { className: "text-xl md:text-2xl leading-relaxed min-h-[5rem] max-w-xl text-foreground", children: displayTranscript ? /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _jsxruntime.Fragment, { children: [
|
|
205
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { children: transcript }),
|
|
206
|
-
interim && /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "span", { className: "text-muted-foreground", children: [
|
|
207
|
-
transcript ? " " : "",
|
|
208
|
-
interim
|
|
209
|
-
] })
|
|
210
|
-
] }) : /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { className: "text-muted-foreground italic text-base", children: "Start speaking \u2014 I'm listening." }) }),
|
|
211
|
-
errored && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "p", { className: "text-sm text-destructive mt-4", children: "Couldn't access the microphone. Check permissions." })
|
|
212
|
-
] }),
|
|
213
|
-
/* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "border-t border-border px-4 py-4 pb-[calc(1rem+env(safe-area-inset-bottom))] md:pb-4 md:rounded-b-xl flex flex-col items-stretch gap-2", children: [
|
|
214
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
215
|
-
_chunkL4DH72UFcjs.Button,
|
|
216
|
-
{
|
|
217
|
-
size: "lg",
|
|
218
|
-
className: "h-12 w-full",
|
|
219
|
-
onClick: handleDone,
|
|
220
|
-
disabled: !displayTranscript.trim(),
|
|
221
|
-
children: "Done"
|
|
222
|
-
}
|
|
223
|
-
),
|
|
224
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
225
|
-
"button",
|
|
226
|
-
{
|
|
227
|
-
type: "button",
|
|
228
|
-
onClick: handleCancel,
|
|
229
|
-
className: "text-sm text-muted-foreground hover:text-foreground py-1",
|
|
230
|
-
children: "Cancel"
|
|
231
|
-
}
|
|
232
|
-
)
|
|
233
|
-
] })
|
|
234
|
-
] })
|
|
235
|
-
]
|
|
236
|
-
}
|
|
237
|
-
) })
|
|
238
|
-
}
|
|
239
|
-
)
|
|
240
|
-
] });
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
exports.VoiceDictationButton = VoiceDictationButton;
|
|
10
|
+
exports.VoiceDictationButton = _chunkEOUO3OROcjs.VoiceDictationButton;
|
|
@@ -1,244 +1,10 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
"use client";
|
|
3
3
|
import {
|
|
4
|
-
|
|
5
|
-
} from "../chunk-
|
|
6
|
-
import
|
|
7
|
-
|
|
8
|
-
} from "../chunk-G6SRSWXB.js";
|
|
9
|
-
|
|
10
|
-
// src/primitives/voice-dictation-button.tsx
|
|
11
|
-
import {
|
|
12
|
-
useCallback,
|
|
13
|
-
useEffect,
|
|
14
|
-
useRef,
|
|
15
|
-
useState
|
|
16
|
-
} from "react";
|
|
17
|
-
import * as DialogPrimitive from "@radix-ui/react-dialog";
|
|
18
|
-
import { Mic, X } from "lucide-react";
|
|
19
|
-
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
20
|
-
function VoiceDictationButton({
|
|
21
|
-
onCommit,
|
|
22
|
-
onCancel,
|
|
23
|
-
title = "Dictate your message",
|
|
24
|
-
caption = "listening",
|
|
25
|
-
lang = "en-US",
|
|
26
|
-
continuous = true,
|
|
27
|
-
className,
|
|
28
|
-
size = "sm",
|
|
29
|
-
showLabel = false,
|
|
30
|
-
children,
|
|
31
|
-
disabled = false,
|
|
32
|
-
visibility = "visible",
|
|
33
|
-
shrink = true
|
|
34
|
-
}) {
|
|
35
|
-
const [supported, setSupported] = useState(false);
|
|
36
|
-
const [open, setOpen] = useState(false);
|
|
37
|
-
const [transcript, setTranscript] = useState("");
|
|
38
|
-
const [interim, setInterim] = useState("");
|
|
39
|
-
const [errored, setErrored] = useState(false);
|
|
40
|
-
const recognitionRef = useRef(null);
|
|
41
|
-
useEffect(() => {
|
|
42
|
-
const w = window;
|
|
43
|
-
const Ctor = w.SpeechRecognition ?? w.webkitSpeechRecognition;
|
|
44
|
-
setSupported(typeof Ctor === "function");
|
|
45
|
-
}, []);
|
|
46
|
-
const stop = useCallback(() => {
|
|
47
|
-
recognitionRef.current?.stop();
|
|
48
|
-
recognitionRef.current = null;
|
|
49
|
-
}, []);
|
|
50
|
-
const startRecognition = useCallback(() => {
|
|
51
|
-
const w = window;
|
|
52
|
-
const Ctor = w.SpeechRecognition ?? w.webkitSpeechRecognition;
|
|
53
|
-
if (!Ctor) return;
|
|
54
|
-
const rec = new Ctor();
|
|
55
|
-
rec.continuous = continuous;
|
|
56
|
-
rec.interimResults = true;
|
|
57
|
-
rec.lang = lang;
|
|
58
|
-
rec.onresult = (event) => {
|
|
59
|
-
let finalChunk = "";
|
|
60
|
-
let interimChunk = "";
|
|
61
|
-
for (let i = event.resultIndex; i < event.results.length; i++) {
|
|
62
|
-
const r = event.results[i];
|
|
63
|
-
if (!r) continue;
|
|
64
|
-
if (r.isFinal) finalChunk += r[0].transcript;
|
|
65
|
-
else interimChunk += r[0].transcript;
|
|
66
|
-
}
|
|
67
|
-
if (finalChunk) {
|
|
68
|
-
setTranscript((prev) => prev ? prev + " " + finalChunk : finalChunk);
|
|
69
|
-
setInterim("");
|
|
70
|
-
} else if (interimChunk) {
|
|
71
|
-
setInterim(interimChunk);
|
|
72
|
-
}
|
|
73
|
-
};
|
|
74
|
-
rec.onerror = () => {
|
|
75
|
-
setErrored(true);
|
|
76
|
-
};
|
|
77
|
-
rec.onend = () => {
|
|
78
|
-
recognitionRef.current = null;
|
|
79
|
-
};
|
|
80
|
-
recognitionRef.current = rec;
|
|
81
|
-
setErrored(false);
|
|
82
|
-
rec.start();
|
|
83
|
-
}, [continuous, lang]);
|
|
84
|
-
const openOverlay = useCallback(() => {
|
|
85
|
-
setTranscript("");
|
|
86
|
-
setInterim("");
|
|
87
|
-
setOpen(true);
|
|
88
|
-
startRecognition();
|
|
89
|
-
}, [startRecognition]);
|
|
90
|
-
const closeOverlay = useCallback(() => {
|
|
91
|
-
stop();
|
|
92
|
-
setOpen(false);
|
|
93
|
-
setInterim("");
|
|
94
|
-
}, [stop]);
|
|
95
|
-
const handleDone = useCallback(() => {
|
|
96
|
-
const final = `${transcript} ${interim}`.trim();
|
|
97
|
-
closeOverlay();
|
|
98
|
-
if (final) onCommit(final);
|
|
99
|
-
else onCancel?.();
|
|
100
|
-
}, [transcript, interim, onCommit, onCancel, closeOverlay]);
|
|
101
|
-
const handleCancel = useCallback(() => {
|
|
102
|
-
closeOverlay();
|
|
103
|
-
onCancel?.();
|
|
104
|
-
}, [closeOverlay, onCancel]);
|
|
105
|
-
useEffect(() => {
|
|
106
|
-
if (!open) return;
|
|
107
|
-
const onKey = (e) => {
|
|
108
|
-
if (e.key === "Enter" && !e.shiftKey) handleDone();
|
|
109
|
-
};
|
|
110
|
-
document.addEventListener("keydown", onKey);
|
|
111
|
-
return () => document.removeEventListener("keydown", onKey);
|
|
112
|
-
}, [open, handleDone]);
|
|
113
|
-
useEffect(() => {
|
|
114
|
-
return () => {
|
|
115
|
-
recognitionRef.current?.abort();
|
|
116
|
-
};
|
|
117
|
-
}, []);
|
|
118
|
-
if (!supported) return null;
|
|
119
|
-
const displayTranscript = `${transcript}${interim ? (transcript ? " " : "") + interim : ""}`;
|
|
120
|
-
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
121
|
-
children ? /* @__PURE__ */ jsx(
|
|
122
|
-
"button",
|
|
123
|
-
{
|
|
124
|
-
type: "button",
|
|
125
|
-
onClick: openOverlay,
|
|
126
|
-
disabled,
|
|
127
|
-
"aria-label": "Start dictation",
|
|
128
|
-
className: cn(visibility === "hidden" && "hidden", className),
|
|
129
|
-
children
|
|
130
|
-
}
|
|
131
|
-
) : /* @__PURE__ */ jsx(
|
|
132
|
-
Button,
|
|
133
|
-
{
|
|
134
|
-
type: "button",
|
|
135
|
-
onClick: openOverlay,
|
|
136
|
-
disabled,
|
|
137
|
-
variant: "outline",
|
|
138
|
-
size,
|
|
139
|
-
"aria-label": "Start dictation",
|
|
140
|
-
className: cn("transition-colors", visibility === "hidden" && "hidden", !shrink && "shrink-0", className),
|
|
141
|
-
children: /* @__PURE__ */ jsxs("span", { className: "flex items-center justify-center gap-2", children: [
|
|
142
|
-
/* @__PURE__ */ jsx(Mic, { className: "h-4 w-4" }),
|
|
143
|
-
showLabel && /* @__PURE__ */ jsx("span", { children: "Speak" })
|
|
144
|
-
] })
|
|
145
|
-
}
|
|
146
|
-
),
|
|
147
|
-
/* @__PURE__ */ jsx(
|
|
148
|
-
DialogPrimitive.Root,
|
|
149
|
-
{
|
|
150
|
-
open,
|
|
151
|
-
onOpenChange: (next) => {
|
|
152
|
-
if (!next) closeOverlay();
|
|
153
|
-
},
|
|
154
|
-
children: /* @__PURE__ */ jsx(DialogPrimitive.Portal, { children: /* @__PURE__ */ jsxs(
|
|
155
|
-
DialogPrimitive.Content,
|
|
156
|
-
{
|
|
157
|
-
"aria-label": "Voice dictation",
|
|
158
|
-
onOpenAutoFocus: (e) => e.preventDefault(),
|
|
159
|
-
onMouseDown: (e) => {
|
|
160
|
-
if (e.target === e.currentTarget) handleCancel();
|
|
161
|
-
},
|
|
162
|
-
className: "fixed inset-0 z-[200] flex flex-col bg-background outline-hidden md:items-center md:justify-center md:bg-black/40 md:backdrop-blur-sm",
|
|
163
|
-
children: [
|
|
164
|
-
/* @__PURE__ */ jsx(DialogPrimitive.Title, { className: "sr-only", children: "Voice dictation" }),
|
|
165
|
-
/* @__PURE__ */ jsxs("div", { className: "flex-1 md:flex-initial w-full md:max-w-lg md:rounded-xl bg-background flex flex-col md:max-h-[80vh] md:shadow-2xl md:border md:border-border", children: [
|
|
166
|
-
/* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between px-4 py-3 border-b border-border md:rounded-t-xl", children: [
|
|
167
|
-
/* @__PURE__ */ jsx("span", { className: "font-mono text-xs uppercase tracking-wider text-muted-foreground", children: caption }),
|
|
168
|
-
/* @__PURE__ */ jsx(
|
|
169
|
-
"button",
|
|
170
|
-
{
|
|
171
|
-
type: "button",
|
|
172
|
-
onClick: handleCancel,
|
|
173
|
-
"aria-label": "Cancel",
|
|
174
|
-
className: "p-1 -m-1 rounded-sm hover:bg-muted/60 transition-colors",
|
|
175
|
-
children: /* @__PURE__ */ jsx(X, { className: "h-4 w-4" })
|
|
176
|
-
}
|
|
177
|
-
)
|
|
178
|
-
] }),
|
|
179
|
-
/* @__PURE__ */ jsxs("div", { className: "flex-1 flex flex-col items-center justify-center px-6 text-center", children: [
|
|
180
|
-
/* @__PURE__ */ jsxs("div", { className: "relative w-24 h-24 mb-10 flex items-center justify-center", children: [
|
|
181
|
-
/* @__PURE__ */ jsx(
|
|
182
|
-
"span",
|
|
183
|
-
{
|
|
184
|
-
"aria-hidden": true,
|
|
185
|
-
className: cn(
|
|
186
|
-
"absolute inset-0 rounded-full",
|
|
187
|
-
errored ? "bg-destructive/20" : "bg-destructive/20 animate-ping"
|
|
188
|
-
)
|
|
189
|
-
}
|
|
190
|
-
),
|
|
191
|
-
/* @__PURE__ */ jsx(
|
|
192
|
-
"span",
|
|
193
|
-
{
|
|
194
|
-
"aria-hidden": true,
|
|
195
|
-
className: cn(
|
|
196
|
-
"absolute inset-2 rounded-full",
|
|
197
|
-
errored ? "bg-destructive/40" : "bg-destructive/40"
|
|
198
|
-
)
|
|
199
|
-
}
|
|
200
|
-
),
|
|
201
|
-
/* @__PURE__ */ jsx(Mic, { className: "relative h-9 w-9 text-destructive-foreground" })
|
|
202
|
-
] }),
|
|
203
|
-
title && /* @__PURE__ */ jsx("div", { className: "text-base font-medium text-muted-foreground mb-3", children: title }),
|
|
204
|
-
/* @__PURE__ */ jsx("p", { className: "text-xl md:text-2xl leading-relaxed min-h-[5rem] max-w-xl text-foreground", children: displayTranscript ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
205
|
-
/* @__PURE__ */ jsx("span", { children: transcript }),
|
|
206
|
-
interim && /* @__PURE__ */ jsxs("span", { className: "text-muted-foreground", children: [
|
|
207
|
-
transcript ? " " : "",
|
|
208
|
-
interim
|
|
209
|
-
] })
|
|
210
|
-
] }) : /* @__PURE__ */ jsx("span", { className: "text-muted-foreground italic text-base", children: "Start speaking \u2014 I'm listening." }) }),
|
|
211
|
-
errored && /* @__PURE__ */ jsx("p", { className: "text-sm text-destructive mt-4", children: "Couldn't access the microphone. Check permissions." })
|
|
212
|
-
] }),
|
|
213
|
-
/* @__PURE__ */ jsxs("div", { className: "border-t border-border px-4 py-4 pb-[calc(1rem+env(safe-area-inset-bottom))] md:pb-4 md:rounded-b-xl flex flex-col items-stretch gap-2", children: [
|
|
214
|
-
/* @__PURE__ */ jsx(
|
|
215
|
-
Button,
|
|
216
|
-
{
|
|
217
|
-
size: "lg",
|
|
218
|
-
className: "h-12 w-full",
|
|
219
|
-
onClick: handleDone,
|
|
220
|
-
disabled: !displayTranscript.trim(),
|
|
221
|
-
children: "Done"
|
|
222
|
-
}
|
|
223
|
-
),
|
|
224
|
-
/* @__PURE__ */ jsx(
|
|
225
|
-
"button",
|
|
226
|
-
{
|
|
227
|
-
type: "button",
|
|
228
|
-
onClick: handleCancel,
|
|
229
|
-
className: "text-sm text-muted-foreground hover:text-foreground py-1",
|
|
230
|
-
children: "Cancel"
|
|
231
|
-
}
|
|
232
|
-
)
|
|
233
|
-
] })
|
|
234
|
-
] })
|
|
235
|
-
]
|
|
236
|
-
}
|
|
237
|
-
) })
|
|
238
|
-
}
|
|
239
|
-
)
|
|
240
|
-
] });
|
|
241
|
-
}
|
|
4
|
+
VoiceDictationButton
|
|
5
|
+
} from "../chunk-HAC32ALJ.js";
|
|
6
|
+
import "../chunk-HQRWRRZJ.js";
|
|
7
|
+
import "../chunk-G6SRSWXB.js";
|
|
242
8
|
export {
|
|
243
9
|
VoiceDictationButton
|
|
244
10
|
};
|