MCPcopy Create free account
hub / github.com/TryCatchLearn/Overflow / RichTextEditor

Function RichTextEditor

webapp/src/components/rte/RichTextEditor.tsx:16–71  ·  view source on GitHub ↗
({onChange, onBlur, value, errorMessage}: Props)

Source from the content-addressed store, hash-verified

14}
15
16export default function RichTextEditor({onChange, onBlur, value, errorMessage}: Props) {
17 const prevPublicIds = useRef<string[]>([]);
18
19 const editor = useEditor({
20 extensions: [StarterKit, Image],
21 content: '',
22 editorProps: {
23 attributes: {
24 class: clsx('w-full p-3 bg-default-100 rounded-xl min-h-60 prose ' +
25 'dark:prose-invert dark:prose-pre:bg-primary-100 max-w-none', {
26 'bg-red-50 dark:bg-red-900/30': errorMessage
27 })
28 }
29 },
30 onBlur() {
31 onBlur()
32 },
33 onUpdate({editor}) {
34 const html = editor.getHTML();
35 onChange(html);
36
37 const currentPublicIds = extractPublicIdsFromHtml(html);
38 const prev = prevPublicIds.current;
39
40 const deleted = prev.filter(id => !currentPublicIds.includes(id));
41
42 if (deleted.length > 0) {
43 deleted.forEach(publicId => {
44 fetch('/api/delete-image', {
45 method: 'POST',
46 headers: { 'Content-type': 'application/json' },
47 body: JSON.stringify(publicId),
48 }).then(() => console.log('deleted ' + publicId));
49 });
50 }
51
52 prevPublicIds.current = currentPublicIds;
53 },
54 immediatelyRender: false,
55 })
56
57 useEffect(() => {
58 if (editor && value !== editor.getHTML()) {
59 editor.commands.setContent(value)
60 }
61 }, [editor, value])
62
63 return (
64 <div>
65 <MenuBar editor={editor} />
66 <EditorContent editor={editor} />
67 </div>
68 )
69
70
71}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…