1// QuillAIToolbar.js - AI Toolbar for Quill Editor
2import React from 'react';
4export default function QuillAIToolbar({ quillRef }) {
5 const handleAIStream = async (type) => {
6 const editor = quillRef.current.getEditor();
7 const range = editor.getSelection();
9 const selectedText = editor.getText(range.index, range.length);
10 const res = await apiFetch(`/ai/stream`, {
12 headers: { 'Content-Type': 'application/json' },
13 body: JSON.stringify({ text: selectedText, type })
15 const reader = res.body.getReader();
18 const { value, done } = await reader.read();
20 output += new TextDecoder().decode(value);
21 // Optionally, update editor live here
23 editor.deleteText(range.index, range.length);
24 editor.insertText(range.index, output);
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>