260810_03_ENH: 이메일 템플릿 수정에 폰트 추가

This commit is contained in:
2026-08-10 11:54:41 +09:00
parent aad991b16b
commit ef748142f8
10 changed files with 149 additions and 14 deletions

View File

@@ -5,6 +5,7 @@ import { EditorContent, useEditor, type Editor } from "@tiptap/react";
import StarterKit from "@tiptap/starter-kit";
import Underline from "@tiptap/extension-underline";
import { TextStyle } from "@tiptap/extension-text-style";
import FontFamily from "@tiptap/extension-font-family";
import Color from "@tiptap/extension-color";
import Highlight from "@tiptap/extension-highlight";
import TiptapImage from "@tiptap/extension-image";
@@ -27,6 +28,7 @@ import { Div } from "./extensions/div";
import { compressImage } from "./utils/imageCompression";
import { sanitizeHtml } from "./utils/sanitizeHtml";
import { preserveEmptyParagraphs } from "./utils/emptyParagraph";
import { DEFAULT_FONT_FAMILY_OPTIONS } from "./utils/fontFamilyOptions";
import { applyLinkPreviewClass, KRI_EDITOR_LINK_CLASS } from "./utils/linkPreview";
import { Toolbar } from "./toolbar/Toolbar";
import { useDebouncedChange } from "./hooks/useDebouncedChange";
@@ -35,9 +37,10 @@ import { useTextareaInsert } from "./hooks/useTextareaInsert";
type ViewMode = "wysiwyg" | "html";
function getToolbarState(editor: Editor): ToolbarState {
const ts = editor.getAttributes("textStyle") as { fontSize?: string | null; color?: string | null };
const ts = editor.getAttributes("textStyle") as { fontSize?: string | null; fontFamily?: string | null; color?: string | null };
const hl = editor.getAttributes("highlight") as { color?: string | null };
const fontFamily = (ts?.fontFamily ?? null) as string | null;
const fontSize = (ts?.fontSize ?? "16px") as string;
const textColor = (ts?.color ?? null) as string | null;
const highlightColor = (hl?.color ?? null) as string | null;
@@ -48,6 +51,7 @@ function getToolbarState(editor: Editor): ToolbarState {
"left";
return {
fontFamily,
fontSize,
textColor,
highlightColor,
@@ -89,6 +93,7 @@ export function KriEditorWysiwyg(props: KriEditorProps) {
allowBase64 = false,
sanitizeHtml: sanitizeHtmlOpt = true,
toolbar = {},
fontFamilyOptions = DEFAULT_FONT_FAMILY_OPTIONS,
editorExtensions = [],
allowedCustomHtml,
transformPreviewHtml,
@@ -122,6 +127,7 @@ export function KriEditorWysiwyg(props: KriEditorProps) {
const selectionRef = useRef<{ from: number; to: number } | null>(null);
const [tb, setTb] = useState<ToolbarState>({
fontFamily: null,
fontSize: "16px",
textColor: null,
highlightColor: null,
@@ -150,6 +156,7 @@ export function KriEditorWysiwyg(props: KriEditorProps) {
Underline,
TextStyle,
FontSize,
FontFamily,
Color,
Highlight.configure({ multicolor: true }),
Div,
@@ -276,6 +283,19 @@ export function KriEditorWysiwyg(props: KriEditorProps) {
[editor, restoreSelection]
);
const setFontFamily = useCallback(
(value: string) => {
if (!editor) return;
restoreSelection();
if (!value) {
editor.chain().focus().unsetFontFamily().run();
return;
}
editor.chain().focus().setFontFamily(value).run();
},
[editor, restoreSelection]
);
const setTextColor = useCallback(
(hex: string) => {
if (!editor) return;
@@ -595,6 +615,8 @@ export function KriEditorWysiwyg(props: KriEditorProps) {
showHtmlToggle={showHtmlToggle}
isHtmlView={view === "html"}
onToggleHtmlView={onToggleHtmlView}
fontFamilyOptions={fontFamilyOptions}
onSetFontFamily={setFontFamily}
onSetFontSize={setFontSize}
onSetTextColor={setTextColor}
onUnsetTextColor={unsetTextColor}