This commit is contained in:
commit
c4e3fcda20
@ -1,4 +1,4 @@
|
|||||||
import React, { useRef } from 'react';
|
import React, { useRef, useEffect } from 'react';
|
||||||
import {
|
import {
|
||||||
Bold,
|
Bold,
|
||||||
Italic,
|
Italic,
|
||||||
@ -41,6 +41,25 @@ export default function RichTextEditor({
|
|||||||
className = '',
|
className = '',
|
||||||
}: RichTextEditorProps) {
|
}: RichTextEditorProps) {
|
||||||
const editorRef = useRef<HTMLDivElement>(null);
|
const editorRef = useRef<HTMLDivElement>(null);
|
||||||
|
const isTypingRef = useRef(false);
|
||||||
|
const isMountedRef = useRef(false);
|
||||||
|
|
||||||
|
// Sync value from props on initial mount or when external change occurs (not while active)
|
||||||
|
useEffect(() => {
|
||||||
|
if (!editorRef.current) return;
|
||||||
|
if (!isMountedRef.current) {
|
||||||
|
editorRef.current.innerHTML = value || '';
|
||||||
|
isMountedRef.current = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Only update innerHTML if it's different and not currently focused/typing
|
||||||
|
if (editorRef.current.innerHTML !== (value || '')) {
|
||||||
|
if (!isTypingRef.current && document.activeElement !== editorRef.current) {
|
||||||
|
editorRef.current.innerHTML = value || '';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, [value]);
|
||||||
|
|
||||||
const isMountedRef = useRef(false);
|
const isMountedRef = useRef(false);
|
||||||
|
|
||||||
@ -71,7 +90,11 @@ export default function RichTextEditor({
|
|||||||
|
|
||||||
const handleInput = () => {
|
const handleInput = () => {
|
||||||
if (editorRef.current) {
|
if (editorRef.current) {
|
||||||
|
isTypingRef.current = true;
|
||||||
onChange(editorRef.current.innerHTML);
|
onChange(editorRef.current.innerHTML);
|
||||||
|
setTimeout(() => {
|
||||||
|
isTypingRef.current = false;
|
||||||
|
}, 50);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -241,6 +264,7 @@ export default function RichTextEditor({
|
|||||||
<div
|
<div
|
||||||
ref={editorRef}
|
ref={editorRef}
|
||||||
contentEditable
|
contentEditable
|
||||||
|
suppressContentEditableWarning
|
||||||
onInput={handleInput}
|
onInput={handleInput}
|
||||||
data-placeholder={placeholder}
|
data-placeholder={placeholder}
|
||||||
className="p-4 min-h-[140px] max-h-[350px] overflow-y-auto outline-none text-xs leading-relaxed text-gray-800 font-vazir empty:before:content-[attr(data-placeholder)] empty:before:text-gray-400"
|
className="p-4 min-h-[140px] max-h-[350px] overflow-y-auto outline-none text-xs leading-relaxed text-gray-800 font-vazir empty:before:content-[attr(data-placeholder)] empty:before:text-gray-400"
|
||||||
|
|||||||
2
graphify-out/cache/stat-index.json
vendored
2
graphify-out/cache/stat-index.json
vendored
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user