260811_01_ENH: 폰트 추가 및 html보기, 프리티어 적용
This commit is contained in:
@@ -9,6 +9,7 @@ import { compressImage } from './utils/imageCompression'
|
||||
import { useDebouncedChange } from './hooks/useDebouncedChange'
|
||||
import { sanitizeHtmlForPreview } from './utils/sanitizeHtml'
|
||||
import { preserveEmptyParagraphs } from './utils/emptyParagraph'
|
||||
import { formatHtmlSource } from './utils/formatHtml'
|
||||
import { useTextareaInsert } from './hooks/useTextareaInsert'
|
||||
|
||||
type HtmlOnlyProps = Omit<KriEditorProps, 'mode'> & { mode: 'html' }
|
||||
@@ -47,12 +48,31 @@ export function KriEditorHtmlOnly({
|
||||
else scheduleChange(next)
|
||||
}, [flushChange, scheduleChange])
|
||||
|
||||
// 사용자가 타이핑한 값이 아니라 외부에서 새로 세팅된 데이터일 때만(최초 마운트 포함)
|
||||
// prettier로 포맷팅해서 반영한다 — 편집 중(commitHtml 경로)에는 절대 재포맷하지 않는다.
|
||||
const applyExternalValue = React.useCallback((next: string) => {
|
||||
setHtml(next)
|
||||
latestHtmlRef.current = next
|
||||
formatHtmlSource(next)
|
||||
.then((formatted) => {
|
||||
if (latestHtmlRef.current !== next) return // 그 사이 값이 또 바뀌었으면 건너뜀
|
||||
setHtml(formatted)
|
||||
latestHtmlRef.current = formatted
|
||||
})
|
||||
.catch(() => {})
|
||||
}, [])
|
||||
|
||||
React.useEffect(() => {
|
||||
applyExternalValue(value || '')
|
||||
// 최초 마운트 시 1회만 실행 — 이후 value 변경은 아래 effect가 처리한다.
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [])
|
||||
|
||||
React.useEffect(() => {
|
||||
if ((value || '') !== latestHtmlRef.current) {
|
||||
setHtml(value || '')
|
||||
latestHtmlRef.current = value || ''
|
||||
applyExternalValue(value || '')
|
||||
}
|
||||
}, [value])
|
||||
}, [value, applyExternalValue])
|
||||
|
||||
React.useEffect(() => {
|
||||
onEditorReady?.(textareaRef.current)
|
||||
@@ -122,6 +142,16 @@ export function KriEditorHtmlOnly({
|
||||
}
|
||||
}
|
||||
|
||||
const handleFormatHtml = React.useCallback(async () => {
|
||||
try {
|
||||
const formatted = await formatHtmlSource(latestHtmlRef.current)
|
||||
commitHtml(formatted)
|
||||
} catch (error) {
|
||||
toast.error('HTML 정렬에 실패했습니다.')
|
||||
console.error(error)
|
||||
}
|
||||
}, [commitHtml])
|
||||
|
||||
const previewHtml = React.useMemo(
|
||||
() => sanitizeHtmlForPreview(preserveEmptyParagraphs(html)),
|
||||
[html],
|
||||
@@ -133,11 +163,16 @@ export function KriEditorHtmlOnly({
|
||||
<div className="flex flex-col gap-2 px-3 py-2">
|
||||
<div className="text-muted-foreground flex items-center justify-between text-xs">
|
||||
<span>HTML 모드</span>
|
||||
{onImageUpload ? (
|
||||
<button type="button" onClick={() => fileRef.current?.click()} className="rounded border px-2 py-1 hover:bg-muted">
|
||||
이미지 업로드
|
||||
<div className="flex items-center gap-2">
|
||||
<button type="button" onClick={handleFormatHtml} className="rounded border px-2 py-1 hover:bg-muted">
|
||||
정렬
|
||||
</button>
|
||||
) : null}
|
||||
{onImageUpload ? (
|
||||
<button type="button" onClick={() => fileRef.current?.click()} className="rounded border px-2 py-1 hover:bg-muted">
|
||||
이미지 업로드
|
||||
</button>
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
<textarea
|
||||
ref={textareaRef}
|
||||
|
||||
@@ -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}
|
||||
@@ -661,7 +688,7 @@ export function KriEditorWysiwyg(props: KriEditorProps) {
|
||||
<div className={cn("border-t p-3", previewClassName)}>
|
||||
<div className="mb-2 text-sm font-semibold">미리보기</div>
|
||||
<div className="rounded-md border bg-muted/30 p-3">
|
||||
<div className="kri-editor-preview" dangerouslySetInnerHTML={{ __html: previewHtml }} />
|
||||
<div dangerouslySetInnerHTML={{ __html: previewHtml }} />
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
@@ -10,6 +10,7 @@ import {
|
||||
Code2,
|
||||
Highlighter,
|
||||
Image as ImageIcon,
|
||||
IndentIncrease,
|
||||
Italic,
|
||||
Link2,
|
||||
List,
|
||||
@@ -38,6 +39,7 @@ interface ToolbarProps {
|
||||
showHtmlToggle: boolean
|
||||
isHtmlView: boolean
|
||||
onToggleHtmlView: () => void
|
||||
onFormatHtml: () => void
|
||||
fontFamilyOptions: KriEditorFontFamilyOption[]
|
||||
onSetFontFamily: (value: string) => void
|
||||
onSetFontSize: (value: string) => void
|
||||
@@ -76,6 +78,7 @@ export function Toolbar({
|
||||
showHtmlToggle,
|
||||
isHtmlView,
|
||||
onToggleHtmlView,
|
||||
onFormatHtml,
|
||||
fontFamilyOptions,
|
||||
onSetFontFamily,
|
||||
onSetFontSize,
|
||||
@@ -115,7 +118,7 @@ export function Toolbar({
|
||||
<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"
|
||||
className="h-8 w-[150px] rounded-md border bg-background px-2 text-sm"
|
||||
value={state.fontFamily ?? ''}
|
||||
onChange={(event) => onSetFontFamily(event.target.value)}
|
||||
title="글꼴"
|
||||
@@ -296,6 +299,9 @@ export function Toolbar({
|
||||
<>
|
||||
<Separator orientation="vertical" className="mx-1 h-6" />
|
||||
<ToolbarButton active={isHtmlView} title={isHtmlView ? 'WYSIWYG로 전환' : 'HTML 편집'} onClick={onToggleHtmlView}><Code2 className="size-4" /></ToolbarButton>
|
||||
{isHtmlView ? (
|
||||
<ToolbarButton title="HTML 정렬" onClick={onFormatHtml}><IndentIncrease className="size-4" /></ToolbarButton>
|
||||
) : null}
|
||||
</>
|
||||
) : null}
|
||||
{customContent ? (
|
||||
|
||||
@@ -2,7 +2,7 @@ import type { KriEditorFontFamilyOption } from "../types";
|
||||
|
||||
/**
|
||||
* OS/이메일 클라이언트에 기본 설치돼 있어 별도 @font-face 로딩 없이 바로 렌더링되는 웹 세이프 폰트 목록.
|
||||
* "기본값"은 fontFamily 속성을 제거(unset)해 상위 스타일을 상속한다.
|
||||
* "자동"은 fontFamily 속성을 제거(unset)해 상위 스타일을 상속한다.
|
||||
*/
|
||||
export const DEFAULT_FONT_FAMILY_OPTIONS: KriEditorFontFamilyOption[] = [
|
||||
{ label: "없음", value: "" },
|
||||
|
||||
16
src/components/kri-editor/utils/formatHtml.ts
Normal file
16
src/components/kri-editor/utils/formatHtml.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
export async function formatHtmlSource(html: string): Promise<string> {
|
||||
if (!html.trim()) return html;
|
||||
|
||||
const [{ format }, htmlPlugin] = await Promise.all([
|
||||
import("prettier/standalone"),
|
||||
import("prettier/plugins/html"),
|
||||
]);
|
||||
|
||||
return format(html, {
|
||||
parser: "html",
|
||||
plugins: [htmlPlugin],
|
||||
printWidth: 100,
|
||||
// 인라인 요소(span/a/mark 등) 사이 공백은 실제 렌더링에 영향을 주므로 보존한다.
|
||||
htmlWhitespaceSensitivity: "css",
|
||||
});
|
||||
}
|
||||
@@ -535,7 +535,7 @@ const MessageTemplate = ({ pageTitle, defaultTemplate }: MessageTemplateProps) =
|
||||
{!isSms && (
|
||||
<KriEditor
|
||||
//mode="both"
|
||||
mode="wysiwyg"
|
||||
mode="both"
|
||||
showPreview={true}
|
||||
value={normalizeQrCodeForEditor(selectedTemplate.tmplatBody) || "<p></p>"}
|
||||
onChange={(html: string) => setTemplateBody(html)}
|
||||
@@ -549,6 +549,7 @@ const MessageTemplate = ({ pageTitle, defaultTemplate }: MessageTemplateProps) =
|
||||
toolbar={{ strike: false, table: false, bulletList: false, orderedList: false }}
|
||||
editorExtensions={MESSAGE_EDITOR_EXTENSIONS}
|
||||
allowedCustomHtml={QR_CODE_ALLOWED_HTML}
|
||||
previewClassName="kri-editor-preview"
|
||||
transformPreviewHtml={renderQrCodePreviewHtml}
|
||||
renderToolbarEnd={({editor}) => (
|
||||
<QrCodeToolbar editor={editor} surveys={surveys} />
|
||||
|
||||
@@ -5,62 +5,80 @@ import { formatKst } from "@kri/common";
|
||||
import {cn} from "@/lib/utils";
|
||||
import {PROJECT_STATUS_CLASS, PROJECT_STATUS_LABEL} from "@/const/projectConst";
|
||||
import {ItrntUserInfo} from "@/types/user";
|
||||
import type {MouseEvent} from "react";
|
||||
|
||||
export const getProjectColumns = (
|
||||
users:ItrntUserInfo[],
|
||||
groupCodeLabelMap: Map<string, string> = new Map(),
|
||||
): ColumnDef<ProjectInfo>[] => [
|
||||
{
|
||||
accessorKey: "prjctIdx",
|
||||
header: "No",
|
||||
enableSorting: true,
|
||||
},
|
||||
{
|
||||
accessorKey: "prjctCd",
|
||||
header: "프로젝트 코드",
|
||||
enableSorting: true,
|
||||
meta: {
|
||||
maxWidth: 180
|
||||
onNavigateToInfo?: (projectInfo: ProjectInfo) => void,
|
||||
): ColumnDef<ProjectInfo>[] => {
|
||||
// 진행 상태/담당 그룹/담당 실사/등록일 셀은 행 클릭(list/manage)과 분기해 project/info로 이동시킨다.
|
||||
const handleInfoCellClick = (e: MouseEvent, projectInfo: ProjectInfo) => {
|
||||
if (!onNavigateToInfo) return;
|
||||
e.stopPropagation();
|
||||
onNavigateToInfo(projectInfo);
|
||||
};
|
||||
const infoCellClass = "flex h-full w-full items-center cursor-pointer";
|
||||
|
||||
return [
|
||||
{
|
||||
accessorKey: "prjctIdx",
|
||||
header: "No",
|
||||
enableSorting: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
accessorKey: "prjctName",
|
||||
header: "프로젝트 명",
|
||||
enableSorting: true,
|
||||
meta: {
|
||||
maxWidth: 1000
|
||||
{
|
||||
accessorKey: "prjctCd",
|
||||
header: "프로젝트 코드",
|
||||
enableSorting: true,
|
||||
meta: {
|
||||
maxWidth: 180
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
accessorKey: "prjctStatus",
|
||||
header: "진행 상태",
|
||||
cell: ({row}) => (
|
||||
<Badge className={cn("w-15 h-7 my-1.5", PROJECT_STATUS_CLASS[row.original.prjctStatus])}>
|
||||
{PROJECT_STATUS_LABEL[row.original.prjctStatus]}
|
||||
</Badge>
|
||||
) ,
|
||||
enableSorting: true,
|
||||
},
|
||||
{
|
||||
accessorKey: "ownerDept",
|
||||
header: "담당 그룹",
|
||||
enableSorting: true,
|
||||
cell: ({row}) => (
|
||||
groupCodeLabelMap.get(row.original.ownerDept) ?? row.original.ownerDept
|
||||
),
|
||||
},
|
||||
{
|
||||
accessorKey: "ownerFw",
|
||||
header: "담당 실사",
|
||||
enableSorting: true,
|
||||
cell: ({row}) => (
|
||||
users.find(u => u.userId === row.original.ownerFw)?.userNm ?? ""
|
||||
) ,
|
||||
},
|
||||
{
|
||||
accessorKey: "regDt",
|
||||
header: "등록일",
|
||||
cell: ({row}) => (formatKst(row.original.regDt ?? "", "date")),
|
||||
enableSorting: true,
|
||||
}
|
||||
];
|
||||
{
|
||||
accessorKey: "prjctName",
|
||||
header: "프로젝트 명",
|
||||
enableSorting: true,
|
||||
meta: {
|
||||
maxWidth: 1000
|
||||
},
|
||||
},
|
||||
{
|
||||
accessorKey: "prjctStatus",
|
||||
header: "진행 상태",
|
||||
cell: ({row}) => (
|
||||
<div className={infoCellClass} onClick={(e) => handleInfoCellClick(e, row.original)}>
|
||||
<Badge className={cn("w-15 h-7 my-1.5", PROJECT_STATUS_CLASS[row.original.prjctStatus])}>
|
||||
{PROJECT_STATUS_LABEL[row.original.prjctStatus]}
|
||||
</Badge>
|
||||
</div>
|
||||
) ,
|
||||
enableSorting: true,
|
||||
},
|
||||
{
|
||||
accessorKey: "ownerDept",
|
||||
header: "담당 그룹",
|
||||
enableSorting: true,
|
||||
cell: ({row}) => (
|
||||
<div className={infoCellClass} onClick={(e) => handleInfoCellClick(e, row.original)}>
|
||||
{groupCodeLabelMap.get(row.original.ownerDept) ?? row.original.ownerDept}
|
||||
</div>
|
||||
),
|
||||
},
|
||||
{
|
||||
accessorKey: "ownerFw",
|
||||
header: "담당 실사",
|
||||
enableSorting: true,
|
||||
cell: ({row}) => (
|
||||
<div className={infoCellClass} onClick={(e) => handleInfoCellClick(e, row.original)}>
|
||||
{users.find(u => u.userId === row.original.ownerFw)?.userNm ?? ""}
|
||||
</div>
|
||||
) ,
|
||||
},
|
||||
{
|
||||
accessorKey: "regDt",
|
||||
header: "등록일",
|
||||
cell: ({row}) => (formatKst(row.original.regDt ?? "", "date")),
|
||||
enableSorting: true,
|
||||
}
|
||||
];
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user