tetrons 2.3.23 ā 2.3.26
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/dist/app/page.d.ts +2 -0
- package/dist/components/components/tetrons/EditorContent.tsx +60 -62
- package/dist/components/tetrons/EditorContent.d.ts +6 -0
- package/dist/components/tetrons/EditorContent.tsx +60 -62
- package/dist/components/tetrons/ResizableImage.d.ts +1 -0
- package/dist/components/tetrons/ResizableImage.js +36 -0
- package/dist/components/tetrons/ResizableImageComponent.d.ts +4 -0
- package/dist/components/tetrons/ResizableImageComponent.jsx +37 -0
- package/dist/components/tetrons/extensions/Spellcheck.ts +50 -0
- package/dist/components/tetrons/toolbar/AIGroup.tsx +209 -0
- package/dist/components/tetrons/toolbar/MiscGroup.tsx +33 -0
- package/dist/components/tetrons/toolbar/TetronsToolbar.tsx +7 -1
- package/dist/index.d.ts +6 -12
- package/dist/index.js +11169 -11454
- package/dist/index.mjs +11237 -11521
- package/dist/styles/styles/tetrons.css +193 -1
- package/dist/styles/tetrons.css +193 -1
- package/package.json +52 -44
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import React, { useState, useRef } from "react";
|
|
4
|
+
import { Editor } from "@tiptap/react";
|
|
5
|
+
import { FaMicrophone, FaStop } from "react-icons/fa";
|
|
6
|
+
import { Waveform } from "@uiball/loaders";
|
|
7
|
+
import { motion, AnimatePresence } from "framer-motion";
|
|
8
|
+
|
|
9
|
+
export default function AiGroup({ editor }: { editor: Editor }) {
|
|
10
|
+
const [isRecording, setIsRecording] = useState(false);
|
|
11
|
+
const [audioBlob, setAudioBlob] = useState<Blob | null>(null);
|
|
12
|
+
const [isTranscribing, setIsTranscribing] = useState(false);
|
|
13
|
+
const [transcriptionError, setTranscriptionError] = useState("");
|
|
14
|
+
|
|
15
|
+
const [showPromptInput, setShowPromptInput] = useState(false);
|
|
16
|
+
const [prompt, setPrompt] = useState("");
|
|
17
|
+
const [isLoadingAI, setIsLoadingAI] = useState(false);
|
|
18
|
+
const [aiError, setAiError] = useState("");
|
|
19
|
+
|
|
20
|
+
const mediaRecorderRef = useRef<MediaRecorder | null>(null);
|
|
21
|
+
const chunksRef = useRef<BlobPart[]>([]);
|
|
22
|
+
|
|
23
|
+
const startRecording = async () => {
|
|
24
|
+
setTranscriptionError("");
|
|
25
|
+
setAudioBlob(null);
|
|
26
|
+
|
|
27
|
+
const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
|
|
28
|
+
const mediaRecorder = new MediaRecorder(stream);
|
|
29
|
+
mediaRecorderRef.current = mediaRecorder;
|
|
30
|
+
chunksRef.current = [];
|
|
31
|
+
|
|
32
|
+
mediaRecorder.ondataavailable = (e) => {
|
|
33
|
+
if (e.data.size > 0) chunksRef.current.push(e.data);
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
mediaRecorder.onstop = () => {
|
|
37
|
+
const blob = new Blob(chunksRef.current, { type: "audio/webm" });
|
|
38
|
+
setAudioBlob(blob);
|
|
39
|
+
transcribeAudio(blob);
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
mediaRecorder.start();
|
|
43
|
+
setIsRecording(true);
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const stopRecording = () => {
|
|
47
|
+
mediaRecorderRef.current?.stop();
|
|
48
|
+
setIsRecording(false);
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
const transcribeAudio = async (blob: Blob) => {
|
|
52
|
+
setIsTranscribing(true);
|
|
53
|
+
setTranscriptionError("");
|
|
54
|
+
|
|
55
|
+
const formData = new FormData();
|
|
56
|
+
formData.append("file", blob, "voice.webm");
|
|
57
|
+
|
|
58
|
+
try {
|
|
59
|
+
const res = await fetch("/api/transcribe", {
|
|
60
|
+
method: "POST",
|
|
61
|
+
body: formData,
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
const data = await res.json();
|
|
65
|
+
if (!res.ok || !data.transcript) {
|
|
66
|
+
throw new Error(data.error || "Failed to transcribe");
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
editor.commands.insertContent(data.transcript);
|
|
70
|
+
} catch (e) {
|
|
71
|
+
console.error(e);
|
|
72
|
+
setTranscriptionError("Transcription failed. Please try again.");
|
|
73
|
+
} finally {
|
|
74
|
+
setIsTranscribing(false);
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
const handleAiClick = () => {
|
|
79
|
+
setShowPromptInput(true);
|
|
80
|
+
setPrompt("");
|
|
81
|
+
setAiError("");
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
const handlePromptSubmit = async () => {
|
|
85
|
+
if (!prompt.trim()) return;
|
|
86
|
+
setIsLoadingAI(true);
|
|
87
|
+
setAiError("");
|
|
88
|
+
|
|
89
|
+
try {
|
|
90
|
+
const res = await fetch("/api/ai-action", {
|
|
91
|
+
method: "POST",
|
|
92
|
+
headers: { "Content-Type": "application/json" },
|
|
93
|
+
body: JSON.stringify({ content: prompt }),
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
const data = await res.json();
|
|
97
|
+
|
|
98
|
+
if (!res.ok || !data.response) {
|
|
99
|
+
throw new Error(data.error || "AI failed to generate content");
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
editor.commands.insertContent(data.response);
|
|
103
|
+
setShowPromptInput(false);
|
|
104
|
+
} catch (e) {
|
|
105
|
+
console.error(e);
|
|
106
|
+
setAiError("Failed to generate content. Try again.");
|
|
107
|
+
} finally {
|
|
108
|
+
setIsLoadingAI(false);
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
return (
|
|
113
|
+
<div className="group relative space-y-3">
|
|
114
|
+
<div className="flex gap-2 items-center">
|
|
115
|
+
{!isRecording ? (
|
|
116
|
+
<button
|
|
117
|
+
type="button"
|
|
118
|
+
onClick={startRecording}
|
|
119
|
+
className="icon-btn"
|
|
120
|
+
title="Start Voice Input"
|
|
121
|
+
>
|
|
122
|
+
<FaMicrophone size={18} />
|
|
123
|
+
</button>
|
|
124
|
+
) : (
|
|
125
|
+
<button
|
|
126
|
+
type="button"
|
|
127
|
+
onClick={stopRecording}
|
|
128
|
+
className="icon-btn stop-btn"
|
|
129
|
+
title="Stop Recording"
|
|
130
|
+
>
|
|
131
|
+
<FaStop size={18} />
|
|
132
|
+
</button>
|
|
133
|
+
)}
|
|
134
|
+
|
|
135
|
+
<button
|
|
136
|
+
type="button"
|
|
137
|
+
onClick={handleAiClick}
|
|
138
|
+
className="ai-button"
|
|
139
|
+
title="AI Assist"
|
|
140
|
+
>
|
|
141
|
+
AI
|
|
142
|
+
</button>
|
|
143
|
+
</div>
|
|
144
|
+
|
|
145
|
+
{isRecording && (
|
|
146
|
+
<div className="flex flex-col items-center">
|
|
147
|
+
<Waveform size={30} lineWeight={3.5} speed={1} color="#4F46E5" />
|
|
148
|
+
<p className="text-sm mt-1 text-gray-600">Recording...</p>
|
|
149
|
+
</div>
|
|
150
|
+
)}
|
|
151
|
+
|
|
152
|
+
{isTranscribing && (
|
|
153
|
+
<p className="text-sm text-gray-500">Transcribing...</p>
|
|
154
|
+
)}
|
|
155
|
+
|
|
156
|
+
{transcriptionError && (
|
|
157
|
+
<p className="text-sm text-red-600">{transcriptionError}</p>
|
|
158
|
+
)}
|
|
159
|
+
|
|
160
|
+
{audioBlob && (
|
|
161
|
+
<div className="mt-2">
|
|
162
|
+
<audio controls src={URL.createObjectURL(audioBlob)} />
|
|
163
|
+
</div>
|
|
164
|
+
)}
|
|
165
|
+
|
|
166
|
+
<AnimatePresence>
|
|
167
|
+
{showPromptInput && (
|
|
168
|
+
<motion.div
|
|
169
|
+
className="ai-modal-backdrop"
|
|
170
|
+
initial={{ opacity: 0 }}
|
|
171
|
+
animate={{ opacity: 1 }}
|
|
172
|
+
exit={{ opacity: 0 }}
|
|
173
|
+
>
|
|
174
|
+
<motion.div
|
|
175
|
+
className="ai-modal-content"
|
|
176
|
+
initial={{ scale: 0.9, opacity: 0 }}
|
|
177
|
+
animate={{ scale: 1, opacity: 1 }}
|
|
178
|
+
exit={{ scale: 0.9, opacity: 0 }}
|
|
179
|
+
>
|
|
180
|
+
<h2 className="ai-modal-title">AI Prompt</h2>
|
|
181
|
+
<textarea
|
|
182
|
+
className="ai-modal-textarea"
|
|
183
|
+
value={prompt}
|
|
184
|
+
onChange={(e) => setPrompt(e.target.value)}
|
|
185
|
+
placeholder="Enter your prompt here..."
|
|
186
|
+
/>
|
|
187
|
+
{aiError && <p className="ai-modal-error">{aiError}</p>}
|
|
188
|
+
<div className="ai-modal-actions">
|
|
189
|
+
<button
|
|
190
|
+
onClick={() => setShowPromptInput(false)}
|
|
191
|
+
className="ai-cancel-btn"
|
|
192
|
+
>
|
|
193
|
+
Cancel
|
|
194
|
+
</button>
|
|
195
|
+
<button
|
|
196
|
+
onClick={handlePromptSubmit}
|
|
197
|
+
disabled={isLoadingAI}
|
|
198
|
+
className="ai-submit-btn"
|
|
199
|
+
>
|
|
200
|
+
{isLoadingAI ? "Generating..." : "Submit"}
|
|
201
|
+
</button>
|
|
202
|
+
</div>
|
|
203
|
+
</motion.div>
|
|
204
|
+
</motion.div>
|
|
205
|
+
)}
|
|
206
|
+
</AnimatePresence>
|
|
207
|
+
</div>
|
|
208
|
+
);
|
|
209
|
+
}
|
|
@@ -5,9 +5,11 @@ import {
|
|
|
5
5
|
MdRefresh,
|
|
6
6
|
MdVisibility,
|
|
7
7
|
MdCode,
|
|
8
|
+
MdSpellcheck,
|
|
8
9
|
} from "react-icons/md";
|
|
9
10
|
import { Editor } from "@tiptap/react";
|
|
10
11
|
import ToolbarButton from "./ToolbarButton";
|
|
12
|
+
import { checkGrammar, GrammarMatch } from "../../../utils/checkGrammar";
|
|
11
13
|
|
|
12
14
|
interface MiscGroupProps {
|
|
13
15
|
editor: Editor;
|
|
@@ -34,6 +36,32 @@ export default function MiscGroup({ editor }: MiscGroupProps) {
|
|
|
34
36
|
}
|
|
35
37
|
};
|
|
36
38
|
|
|
39
|
+
const handleGrammarCheck = async () => {
|
|
40
|
+
const text = editor.getText();
|
|
41
|
+
try {
|
|
42
|
+
const issues: GrammarMatch[] = await checkGrammar(text);
|
|
43
|
+
if (issues.length === 0) {
|
|
44
|
+
alert("ā
No grammar issues found.");
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
let message = "š Grammar Suggestions:\n\n";
|
|
49
|
+
issues.forEach((issue: GrammarMatch, idx: number) => {
|
|
50
|
+
const replacements = issue.replacements
|
|
51
|
+
.map((r: { value: string }) => r.value)
|
|
52
|
+
.join(", ");
|
|
53
|
+
message += `${idx + 1}. "${
|
|
54
|
+
issue.context.text
|
|
55
|
+
}"\nā ${replacements}\nReason: ${issue.message}\n\n`;
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
alert(message);
|
|
59
|
+
} catch (err) {
|
|
60
|
+
console.error(err);
|
|
61
|
+
alert("ā Failed to check grammar. Please try again later.");
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
|
|
37
65
|
return (
|
|
38
66
|
<div className="misc-group">
|
|
39
67
|
<ToolbarButton
|
|
@@ -66,6 +94,11 @@ export default function MiscGroup({ editor }: MiscGroupProps) {
|
|
|
66
94
|
label="Preview"
|
|
67
95
|
onClick={handlePreview}
|
|
68
96
|
/>
|
|
97
|
+
<ToolbarButton
|
|
98
|
+
icon={MdSpellcheck}
|
|
99
|
+
label="Check Grammar"
|
|
100
|
+
onClick={handleGrammarCheck}
|
|
101
|
+
/>
|
|
69
102
|
</div>
|
|
70
103
|
);
|
|
71
104
|
}
|
|
@@ -10,6 +10,7 @@ import InsertGroup from "./InsertGroup";
|
|
|
10
10
|
import ListAlignGroup from "./ListAlignGroup";
|
|
11
11
|
import MiscGroup from "./MiscGroup";
|
|
12
12
|
import FileGroup from "./FileGroup";
|
|
13
|
+
import AiGroup from "./AIGroup";
|
|
13
14
|
|
|
14
15
|
export default function TetronsToolbar({
|
|
15
16
|
editor,
|
|
@@ -65,7 +66,12 @@ export default function TetronsToolbar({
|
|
|
65
66
|
<ActionGroup editor={editor} />
|
|
66
67
|
</>
|
|
67
68
|
)}
|
|
68
|
-
{version === "platinum" &&
|
|
69
|
+
{version === "platinum" && (
|
|
70
|
+
<>
|
|
71
|
+
<MiscGroup editor={editor} />
|
|
72
|
+
<AiGroup editor={editor} />
|
|
73
|
+
</>
|
|
74
|
+
)}
|
|
69
75
|
</div>
|
|
70
76
|
);
|
|
71
77
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
};
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
declare function initializeTetrons(apiKey: string): Promise<void>;
|
|
9
|
-
declare function getTetronsVersion(): "" | "free" | "pro" | "premium" | "platinum";
|
|
10
|
-
declare function isApiKeyValid(): boolean;
|
|
11
|
-
|
|
12
|
-
export { EditorContent, EditorContent as default, getTetronsVersion, initializeTetrons, isApiKeyValid };
|
|
1
|
+
import EditorContent from "./components/tetrons/EditorContent";
|
|
2
|
+
export declare function initializeTetrons(apiKey: string): Promise<void>;
|
|
3
|
+
export declare function getTetronsVersion(): "" | "free" | "pro" | "premium" | "platinum";
|
|
4
|
+
export declare function isApiKeyValid(): boolean;
|
|
5
|
+
export { EditorContent };
|
|
6
|
+
export default EditorContent;
|