EverydayTech Platform - Developer Reference
Complete Source Code Documentation - All Applications
Loading...
Searching...
No Matches
QuillAIToolbar.js
Go to the documentation of this file.
1// QuillAIToolbar.js - AI Toolbar for Quill Editor
2import React from 'react';
3
4export default function QuillAIToolbar({ quillRef }) {
5 const handleAIStream = async (type) => {
6 const editor = quillRef.current.getEditor();
7 const range = editor.getSelection();
8 if (!range) return;
9 const selectedText = editor.getText(range.index, range.length);
10 const res = await apiFetch(`/ai/stream`, {
11 method: 'POST',
12 headers: { 'Content-Type': 'application/json' },
13 body: JSON.stringify({ text: selectedText, type })
14 });
15 const reader = res.body.getReader();
16 let output = '';
17 while (true) {
18 const { value, done } = await reader.read();
19 if (done) break;
20 output += new TextDecoder().decode(value);
21 // Optionally, update editor live here
22 }
23 editor.deleteText(range.index, range.length);
24 editor.insertText(range.index, output);
25 };
26 return (
27 <div className="quill-ai-toolbar">
28 <button onClick={() => handleAIStream('rewrite')}>Rewrite (Live)</button>
29 <button onClick={() => handleAIStream('summary')}>Summarize (Live)</button>
30 <button onClick={() => handleAIStream('expand')}>Expand (Live)</button>
31 <button onClick={() => handleAIStream('continue')}>Continue (Live)</button>
32 </div>
33 );
34}