From a398003dcdec2604d93e2c77d052ff62d1194545 Mon Sep 17 00:00:00 2001 From: kric_jspark Date: Mon, 10 Aug 2026 16:54:45 +0900 Subject: [PATCH] =?UTF-8?q?260810=5F06=5FENH:=20=EC=97=90=EB=94=94?= =?UTF-8?q?=ED=84=B0=20html=EC=97=90=20=ED=94=84=EB=A6=AC=ED=8B=B0?= =?UTF-8?q?=EC=96=B4=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package-lock.json | 17 +++++++ package.json | 3 +- .../kri-editor/KriEditorHtmlOnly.tsx | 49 ++++++++++++++++--- .../kri-editor/KriEditorWysiwyg.tsx | 29 ++++++++++- .../components/kri-editor/toolbar/Toolbar.tsx | 6 +++ .../components/kri-editor/utils/formatHtml.ts | 21 ++++++++ registry/components/registry.json | 6 +++ 7 files changed, 122 insertions(+), 9 deletions(-) create mode 100644 registry/components/kri-editor/utils/formatHtml.ts diff --git a/package-lock.json b/package-lock.json index 59128e4..6f305fd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -31,6 +31,7 @@ "echarts": "^6.1.0", "echarts-for-react": "^3.0.6", "lucide-react": "^1.23.0", + "prettier": "^3.9.6", "rimraf": "^6.0.0", "serve": "^14.2.4", "shadcn": "^4.8.3", @@ -4581,6 +4582,22 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/prettier": { + "version": "3.9.6", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.9.6.tgz", + "integrity": "sha512-OpN0zzVdiaiAhxpuuj5efpIS4sY9j7bY6uR5mnj5yPzGkdkjNKSJeUThPb60Jw29QuAZgA4o+/iB49kFiaBX6g==", + "dev": true, + "license": "MIT", + "bin": { + "prettier": "bin/prettier.cjs" + }, + "engines": { + "node": ">=14" + }, + "funding": { + "url": "https://github.com/prettier/prettier?sponsor=1" + } + }, "node_modules/pretty-ms": { "version": "9.3.0", "resolved": "https://registry.npmjs.org/pretty-ms/-/pretty-ms-9.3.0.tgz", diff --git a/package.json b/package.json index 15392fd..1bb34d2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "kri-ui-registry", - "version": "0.11.5", + "version": "0.11.6", "private": true, "description": "KRI internal shadcn UI registry", "scripts": { @@ -33,6 +33,7 @@ "echarts": "^6.1.0", "echarts-for-react": "^3.0.6", "lucide-react": "^1.23.0", + "prettier": "^3.9.6", "rimraf": "^6.0.0", "serve": "^14.2.4", "shadcn": "^4.8.3", diff --git a/registry/components/kri-editor/KriEditorHtmlOnly.tsx b/registry/components/kri-editor/KriEditorHtmlOnly.tsx index ff59ea6..0e4c845 100644 --- a/registry/components/kri-editor/KriEditorHtmlOnly.tsx +++ b/registry/components/kri-editor/KriEditorHtmlOnly.tsx @@ -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 & { 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({
HTML 모드 - {onImageUpload ? ( - - ) : null} + {onImageUpload ? ( + + ) : null} +