260810_06_ENH: 에디터 html에 프리티어 적용

This commit is contained in:
2026-08-10 16:54:45 +09:00
parent fd5b7d1998
commit a398003dcd
7 changed files with 122 additions and 9 deletions

View File

@@ -29,6 +29,7 @@ import { compressImage } from "./utils/imageCompression";
import { sanitizeHtml } from "./utils/sanitizeHtml";
import { preserveEmptyParagraphs } from "./utils/emptyParagraph";
import { DEFAULT_FONT_FAMILY_OPTIONS } from "./utils/fontFamilyOptions";
import { formatHtmlSource } from "./utils/formatHtml";
import { applyLinkPreviewClass, KRI_EDITOR_LINK_CLASS } from "./utils/linkPreview";
import { Toolbar } from "./toolbar/Toolbar";
import { useDebouncedChange } from "./hooks/useDebouncedChange";
@@ -456,8 +457,20 @@ export function KriEditorWysiwyg(props: KriEditorProps) {
if (!editor) return;
if (viewRef.current === "wysiwyg") {
htmlDraftRef.current = editor.getHTML();
const raw = editor.getHTML();
htmlDraftRef.current = raw;
setView("html");
// WYSIWYG에서 막 넘어온, 사용자가 직접 타이핑하지 않은 HTML이므로
// 화면 표시용으로만 정렬한다(onChange는 호출하지 않음 — 저장값은 그대로 유지).
formatHtmlSource(raw)
.then((formatted) => {
if (viewRef.current !== "html" || htmlDraftRef.current !== raw) return;
htmlDraftRef.current = formatted;
if (htmlTextareaRef.current) htmlTextareaRef.current.value = formatted;
setPreviewSource(formatted);
})
.catch(() => {});
return;
}
@@ -469,6 +482,19 @@ export function KriEditorWysiwyg(props: KriEditorProps) {
setView("wysiwyg");
}, [allowedCustomHtml, editor, flushChange, sanitizeHtmlOpt]);
const formatHtmlView = useCallback(async () => {
try {
const formatted = await formatHtmlSource(htmlDraftRef.current);
htmlDraftRef.current = formatted;
if (htmlTextareaRef.current) htmlTextareaRef.current.value = formatted;
setPreviewSource(formatted);
scheduleChange(preserveEmptyParagraphs(formatted));
} catch (err) {
toast.error("HTML 정렬에 실패했습니다.");
console.error(err);
}
}, [scheduleChange]);
useEffect(() => {
if (!editor) return;
@@ -615,6 +641,7 @@ export function KriEditorWysiwyg(props: KriEditorProps) {
showHtmlToggle={showHtmlToggle}
isHtmlView={view === "html"}
onToggleHtmlView={onToggleHtmlView}
onFormatHtml={formatHtmlView}
fontFamilyOptions={fontFamilyOptions}
onSetFontFamily={setFontFamily}
onSetFontSize={setFontSize}