diff --git a/package.json b/package.json index 8f3e934..4049657 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "kri-ui-registry", - "version": "0.9.8", + "version": "0.9.9", "private": true, "description": "KRI internal shadcn UI registry", "scripts": { diff --git a/registry/components/kri-editor/KriEditorWysiwyg.tsx b/registry/components/kri-editor/KriEditorWysiwyg.tsx index 5b35b88..edfa856 100644 --- a/registry/components/kri-editor/KriEditorWysiwyg.tsx +++ b/registry/components/kri-editor/KriEditorWysiwyg.tsx @@ -26,6 +26,7 @@ import { FontSize } from "./extensions/font-size"; import { Div } from "./extensions/div"; import { compressImage } from "./utils/imageCompression"; import { sanitizeHtml } from "./utils/sanitizeHtml"; +import { preserveEmptyParagraphs } from "./utils/emptyParagraph"; import { applyLinkPreviewClass, KRI_EDITOR_LINK_CLASS } from "./utils/linkPreview"; import { Toolbar } from "./toolbar/Toolbar"; import { useDebouncedChange } from "./hooks/useDebouncedChange"; @@ -192,7 +193,7 @@ export function KriEditorWysiwyg(props: KriEditorProps) { if (viewRef.current === "html") return; const nextHtml = editor.getHTML(); setPreviewSource(nextHtml); - scheduleChange(nextHtml); + scheduleChange(preserveEmptyParagraphs(nextHtml)); }, editorProps: { @@ -444,7 +445,7 @@ export function KriEditorWysiwyg(props: KriEditorProps) { const safe = sanitizeHtmlOpt ? sanitizeHtml(raw, allowedCustomHtml) : raw; editor.commands.setContent(safe, { emitUpdate: false, parseOptions: { preserveWhitespace: "full" } }); - flushChange(editor.getHTML()); + flushChange(preserveEmptyParagraphs(editor.getHTML())); setView("wysiwyg"); }, [allowedCustomHtml, editor, flushChange, sanitizeHtmlOpt]); @@ -506,8 +507,8 @@ export function KriEditorWysiwyg(props: KriEditorProps) { if (!editor) return; const onBlur = () => { - if (viewRef.current === "html") flushChange(htmlDraftRef.current); - else flushChange(editor.getHTML()); + if (viewRef.current === "html") flushChange(preserveEmptyParagraphs(htmlDraftRef.current)); + else flushChange(preserveEmptyParagraphs(editor.getHTML())); }; editor.on("blur", onBlur); @@ -542,7 +543,7 @@ export function KriEditorWysiwyg(props: KriEditorProps) { if (!editor) return; restoreSelection(); editor.chain().focus().insertContent(text).run(); - flushChange(editor.getHTML()); + flushChange(preserveEmptyParagraphs(editor.getHTML())); }, }), [editor, restoreSelection, flushChange, insertTextareaText] @@ -563,7 +564,8 @@ export function KriEditorWysiwyg(props: KriEditorProps) { }, [command, editor, props.onCommandReady]); const previewHtml = useMemo(() => { - const sanitized = sanitizeHtmlOpt ? sanitizeHtml(previewSource, allowedCustomHtml) : previewSource; + const preserved = preserveEmptyParagraphs(previewSource); + const sanitized = sanitizeHtmlOpt ? sanitizeHtml(preserved, allowedCustomHtml) : preserved; const withLinkStyle = applyLinkPreviewClass(sanitized); return transformPreviewHtml ? transformPreviewHtml(withLinkStyle) : withLinkStyle; }, [allowedCustomHtml, previewSource, sanitizeHtmlOpt, transformPreviewHtml]); diff --git a/registry/components/kri-editor/utils/emptyParagraph.ts b/registry/components/kri-editor/utils/emptyParagraph.ts new file mode 100644 index 0000000..e44b3e7 --- /dev/null +++ b/registry/components/kri-editor/utils/emptyParagraph.ts @@ -0,0 +1,9 @@ +const EMPTY_PARAGRAPH_PATTERN = /
]*)?)>\s*<\/p>/gi; + +/** + * TipTap이 빈 줄을
로 직렬화하면 이메일 클라이언트에서 margin collapse로 사라진다. + * 눈에 보이지 않는 콘텐츠( )를 채워 실제 발송 HTML에서도 빈 줄이 유지되게 한다. + */ +export function preserveEmptyParagraphs(html: string): string { + return html.replace(EMPTY_PARAGRAPH_PATTERN, (_match, attrs: string) => ``); +} diff --git a/registry/components/registry.json b/registry/components/registry.json index 9ff38cb..cd5ea2e 100644 --- a/registry/components/registry.json +++ b/registry/components/registry.json @@ -412,11 +412,21 @@ "type": "registry:component", "target": "@components/kri-editor/utils/editorTypeGuards.ts" }, + { + "path": "kri-editor/utils/emptyParagraph.ts", + "type": "registry:component", + "target": "@components/kri-editor/utils/emptyParagraph.ts" + }, { "path": "kri-editor/utils/imageCompression.ts", "type": "registry:component", "target": "@components/kri-editor/utils/imageCompression.ts" }, + { + "path": "kri-editor/utils/linkPreview.ts", + "type": "registry:component", + "target": "@components/kri-editor/utils/linkPreview.ts" + }, { "path": "kri-editor/utils/sanitizeHtml.ts", "type": "registry:component",