260810_02_ENH: wysiwyg 에디터 툴바에 폰트 패밀리 추가

This commit is contained in:
2026-08-10 09:32:15 +09:00
parent 13d905c15b
commit 0feda2a324
9 changed files with 97 additions and 8 deletions

19
package-lock.json generated
View File

@@ -1,15 +1,16 @@
{ {
"name": "kri-ui-registry", "name": "kri-ui-registry",
"version": "0.5.0", "version": "0.10.0",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "kri-ui-registry", "name": "kri-ui-registry",
"version": "0.5.0", "version": "0.10.0",
"devDependencies": { "devDependencies": {
"@tanstack/react-table": "^8.21.3", "@tanstack/react-table": "^8.21.3",
"@tiptap/extension-color": "^3.27.1", "@tiptap/extension-color": "^3.27.1",
"@tiptap/extension-font-family": "^3.27.1",
"@tiptap/extension-highlight": "^3.27.1", "@tiptap/extension-highlight": "^3.27.1",
"@tiptap/extension-image": "^3.27.1", "@tiptap/extension-image": "^3.27.1",
"@tiptap/extension-link": "^3.27.1", "@tiptap/extension-link": "^3.27.1",
@@ -1024,6 +1025,20 @@
"@tiptap/pm": "3.27.1" "@tiptap/pm": "3.27.1"
} }
}, },
"node_modules/@tiptap/extension-font-family": {
"version": "3.27.1",
"resolved": "https://registry.npmjs.org/@tiptap/extension-font-family/-/extension-font-family-3.27.1.tgz",
"integrity": "sha512-sxPae35pbJSaF3IZRGDglB5z/7nzS9dmxLLjiQNWYmgUIs8+/EYcrsN/woYUS0nsgHswgBmg7DwBabunKLSGhQ==",
"dev": true,
"license": "MIT",
"funding": {
"type": "github",
"url": "https://github.com/sponsors/ueberdosis"
},
"peerDependencies": {
"@tiptap/extension-text-style": "3.27.1"
}
},
"node_modules/@tiptap/extension-gapcursor": { "node_modules/@tiptap/extension-gapcursor": {
"version": "3.27.1", "version": "3.27.1",
"resolved": "https://registry.npmjs.org/@tiptap/extension-gapcursor/-/extension-gapcursor-3.27.1.tgz", "resolved": "https://registry.npmjs.org/@tiptap/extension-gapcursor/-/extension-gapcursor-3.27.1.tgz",

View File

@@ -1,6 +1,6 @@
{ {
"name": "kri-ui-registry", "name": "kri-ui-registry",
"version": "0.10.0", "version": "0.11.0",
"private": true, "private": true,
"description": "KRI internal shadcn UI registry", "description": "KRI internal shadcn UI registry",
"scripts": { "scripts": {
@@ -12,6 +12,7 @@
"devDependencies": { "devDependencies": {
"@tanstack/react-table": "^8.21.3", "@tanstack/react-table": "^8.21.3",
"@tiptap/extension-color": "^3.27.1", "@tiptap/extension-color": "^3.27.1",
"@tiptap/extension-font-family": "^3.27.1",
"@tiptap/extension-highlight": "^3.27.1", "@tiptap/extension-highlight": "^3.27.1",
"@tiptap/extension-image": "^3.27.1", "@tiptap/extension-image": "^3.27.1",
"@tiptap/extension-link": "^3.27.1", "@tiptap/extension-link": "^3.27.1",

View File

@@ -79,7 +79,7 @@ export function KriTimePicker({
return ( return (
<div className={cn('flex flex-col divide-y sm:h-[300px] sm:flex-row sm:divide-x sm:divide-y-0', className)}> <div className={cn('flex flex-col divide-y sm:h-[300px] sm:flex-row sm:divide-x sm:divide-y-0', className)}>
<div className="flex flex-col"> <div className="flex flex-col">
<div className="px-2 pt-2 text-xs font-medium text-muted-foreground">{hourLabel}</div> <div className="mt-1 p-1 align-middle text-center text-base border-b">{hourLabel}</div>
<ScrollArea className="w-64 sm:w-auto sm:min-h-0 sm:flex-1"> <ScrollArea className="w-64 sm:w-auto sm:min-h-0 sm:flex-1">
<div className="flex p-2 sm:flex-col"> <div className="flex p-2 sm:flex-col">
{hours.map((hour) => ( {hours.map((hour) => (
@@ -101,7 +101,7 @@ export function KriTimePicker({
</div> </div>
<div className="flex flex-col"> <div className="flex flex-col">
<div className="px-2 pt-2 text-xs font-medium text-muted-foreground">{minuteLabel}</div> <div className="mt-1 p-1 align-middle text-center text-base border-b">{minuteLabel}</div>
<ScrollArea className="w-64 sm:w-auto sm:min-h-0 sm:flex-1"> <ScrollArea className="w-64 sm:w-auto sm:min-h-0 sm:flex-1">
<div className="flex p-2 sm:flex-col"> <div className="flex p-2 sm:flex-col">
{minutes.map((minute) => ( {minutes.map((minute) => (

View File

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

View File

@@ -3,9 +3,11 @@ export { KriEditorHtmlOnly } from './KriEditorHtmlOnly'
export { KriEditorSms } from './KriEditorSms' export { KriEditorSms } from './KriEditorSms'
export { KriEditorWysiwyg } from './KriEditorWysiwyg' export { KriEditorWysiwyg } from './KriEditorWysiwyg'
export { ToolbarButton as KriEditorToolbarButton } from './toolbar/ToolbarButton' export { ToolbarButton as KriEditorToolbarButton } from './toolbar/ToolbarButton'
export { DEFAULT_FONT_FAMILY_OPTIONS } from './utils/fontFamilyOptions'
export type { export type {
KriEditorAllowedHtml, KriEditorAllowedHtml,
KriEditorCommand, KriEditorCommand,
KriEditorFontFamilyOption,
KriEditorMode, KriEditorMode,
KriEditorProps, KriEditorProps,
KriEditorToolbarConfig, KriEditorToolbarConfig,

View File

@@ -25,7 +25,7 @@ import { Input } from '@/components/ui/input'
import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover' import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover'
import { Separator } from '@/components/ui/separator' import { Separator } from '@/components/ui/separator'
import { cn } from '@/lib/utils' import { cn } from '@/lib/utils'
import type { KriEditorToolbarConfig, KriEditorToolbarFeature, ToolbarState } from '../types' import type { KriEditorFontFamilyOption, KriEditorToolbarConfig, KriEditorToolbarFeature, ToolbarState } from '../types'
import { ToolbarButton } from './ToolbarButton' import { ToolbarButton } from './ToolbarButton'
interface ToolbarProps { interface ToolbarProps {
@@ -38,6 +38,8 @@ interface ToolbarProps {
showHtmlToggle: boolean showHtmlToggle: boolean
isHtmlView: boolean isHtmlView: boolean
onToggleHtmlView: () => void onToggleHtmlView: () => void
fontFamilyOptions: KriEditorFontFamilyOption[]
onSetFontFamily: (value: string) => void
onSetFontSize: (value: string) => void onSetFontSize: (value: string) => void
onSetTextColor: (value: string) => void onSetTextColor: (value: string) => void
onUnsetTextColor: () => void onUnsetTextColor: () => void
@@ -74,6 +76,8 @@ export function Toolbar({
showHtmlToggle, showHtmlToggle,
isHtmlView, isHtmlView,
onToggleHtmlView, onToggleHtmlView,
fontFamilyOptions,
onSetFontFamily,
onSetFontSize, onSetFontSize,
onSetTextColor, onSetTextColor,
onUnsetTextColor, onUnsetTextColor,
@@ -89,6 +93,7 @@ export function Toolbar({
customContent, customContent,
}: ToolbarProps) { }: ToolbarProps) {
const enabled = (feature: KriEditorToolbarFeature) => config?.[feature] !== false const enabled = (feature: KriEditorToolbarFeature) => config?.[feature] !== false
const showFontControls = enabled('fontFamily') || enabled('fontSize')
const showTextStyle = enabled('bold') || enabled('italic') || enabled('underline') || enabled('strike') const showTextStyle = enabled('bold') || enabled('italic') || enabled('underline') || enabled('strike')
const showColors = enabled('textColor') || enabled('highlight') const showColors = enabled('textColor') || enabled('highlight')
const showLists = enabled('bulletList') || enabled('orderedList') const showLists = enabled('bulletList') || enabled('orderedList')
@@ -108,6 +113,19 @@ export function Toolbar({
return ( return (
<div className={cn('flex items-center gap-1 overflow-x-auto whitespace-nowrap px-2 py-1', className)}> <div className={cn('flex items-center gap-1 overflow-x-auto whitespace-nowrap px-2 py-1', className)}>
{enabled('fontFamily') ? (
<select
className="h-8 w-[132px] rounded-md border bg-background px-2 text-sm"
value={state.fontFamily ?? ''}
onChange={(event) => onSetFontFamily(event.target.value)}
title="글꼴"
>
{fontFamilyOptions.map((option) => (
<option key={option.value} value={option.value}>{option.label}</option>
))}
</select>
) : null}
{enabled('fontSize') ? ( {enabled('fontSize') ? (
<select <select
className="h-8 w-[72px] rounded-md border bg-background px-2 text-sm" className="h-8 w-[72px] rounded-md border bg-background px-2 text-sm"
@@ -121,7 +139,7 @@ export function Toolbar({
</select> </select>
) : null} ) : null}
{enabled('fontSize') && showTextStyle ? <Separator orientation="vertical" className="mx-1 h-6" /> : null} {showFontControls && showTextStyle ? <Separator orientation="vertical" className="mx-1 h-6" /> : null}
{enabled('bold') ? ( {enabled('bold') ? (
<ToolbarButton active={state.isBold} disabled={!editor.can().chain().focus().toggleBold().run()} onClick={() => editor.chain().focus().toggleBold().run()} title="굵게"> <ToolbarButton active={state.isBold} disabled={!editor.can().chain().focus().toggleBold().run()} onClick={() => editor.chain().focus().toggleBold().run()} title="굵게">

View File

@@ -6,6 +6,7 @@ export type KriEditorMode = 'wysiwyg' | 'both' | 'html' | 'sms'
export type KriEditorUploadResult = string | { url: string } export type KriEditorUploadResult = string | { url: string }
export type KriEditorToolbarFeature = export type KriEditorToolbarFeature =
| 'fontFamily'
| 'fontSize' | 'fontSize'
| 'bold' | 'bold'
| 'italic' | 'italic'
@@ -39,6 +40,11 @@ export type KriEditorAllowedHtml = {
attributes?: string[] attributes?: string[]
} }
export type KriEditorFontFamilyOption = {
label: string
value: string
}
export type KriEditorProps = { export type KriEditorProps = {
onEditorReady?: (editor: Editor | HTMLTextAreaElement | null) => void onEditorReady?: (editor: Editor | HTMLTextAreaElement | null) => void
onCommandReady?: (command: KriEditorCommand | null) => void onCommandReady?: (command: KriEditorCommand | null) => void
@@ -69,6 +75,7 @@ export type KriEditorProps = {
smsMaxBytes?: number smsMaxBytes?: number
lmsMaxBytes?: number lmsMaxBytes?: number
toolbar?: KriEditorToolbarConfig | false toolbar?: KriEditorToolbarConfig | false
fontFamilyOptions?: KriEditorFontFamilyOption[]
renderToolbarEnd?: (context: KriEditorToolbarContext) => ReactNode renderToolbarEnd?: (context: KriEditorToolbarContext) => ReactNode
editorExtensions?: Extensions editorExtensions?: Extensions
allowedCustomHtml?: KriEditorAllowedHtml allowedCustomHtml?: KriEditorAllowedHtml
@@ -76,6 +83,7 @@ export type KriEditorProps = {
} }
export type ToolbarState = { export type ToolbarState = {
fontFamily: string | null
fontSize: string fontSize: string
textColor: string | null textColor: string | null
highlightColor: string | null highlightColor: string | null

View File

@@ -0,0 +1,17 @@
import type { KriEditorFontFamilyOption } from "../types";
/**
* OS/이메일 클라이언트에 기본 설치돼 있어 별도 @font-face 로딩 없이 바로 렌더링되는 웹 세이프 폰트 목록.
* "기본값"은 fontFamily 속성을 제거(unset)해 상위 스타일을 상속한다.
*/
export const DEFAULT_FONT_FAMILY_OPTIONS: KriEditorFontFamilyOption[] = [
{ label: "기본값", value: "" },
{ label: "맑은 고딕", value: "'Malgun Gothic', sans-serif" },
{ label: "Apple SD 고딕", value: "'Apple SD Gothic Neo', sans-serif" },
{ label: "Arial", value: "Arial, Helvetica, sans-serif" },
{ label: "Georgia", value: "Georgia, 'Times New Roman', serif" },
{ label: "Times New Roman", value: "'Times New Roman', Times, serif" },
{ label: "Courier New", value: "'Courier New', Courier, monospace" },
{ label: "Verdana", value: "Verdana, Geneva, sans-serif" },
{ label: "Tahoma", value: "Tahoma, Geneva, sans-serif" },
];

View File

@@ -329,6 +329,7 @@
], ],
"dependencies": [ "dependencies": [
"@tiptap/extension-color", "@tiptap/extension-color",
"@tiptap/extension-font-family",
"@tiptap/extension-highlight", "@tiptap/extension-highlight",
"@tiptap/extension-image", "@tiptap/extension-image",
"@tiptap/extension-link", "@tiptap/extension-link",
@@ -417,6 +418,11 @@
"type": "registry:component", "type": "registry:component",
"target": "@components/kri-editor/utils/emptyParagraph.ts" "target": "@components/kri-editor/utils/emptyParagraph.ts"
}, },
{
"path": "kri-editor/utils/fontFamilyOptions.ts",
"type": "registry:component",
"target": "@components/kri-editor/utils/fontFamilyOptions.ts"
},
{ {
"path": "kri-editor/utils/imageCompression.ts", "path": "kri-editor/utils/imageCompression.ts",
"type": "registry:component", "type": "registry:component",