260803_02_ENH: kri editor에서 preview에서도 줄바꿈 보여지게 수정
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "kri-ui-registry",
|
"name": "kri-ui-registry",
|
||||||
"version": "0.9.8",
|
"version": "0.9.9",
|
||||||
"private": true,
|
"private": true,
|
||||||
"description": "KRI internal shadcn UI registry",
|
"description": "KRI internal shadcn UI registry",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ import { FontSize } from "./extensions/font-size";
|
|||||||
import { Div } from "./extensions/div";
|
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 { 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";
|
||||||
@@ -192,7 +193,7 @@ export function KriEditorWysiwyg(props: KriEditorProps) {
|
|||||||
if (viewRef.current === "html") return;
|
if (viewRef.current === "html") return;
|
||||||
const nextHtml = editor.getHTML();
|
const nextHtml = editor.getHTML();
|
||||||
setPreviewSource(nextHtml);
|
setPreviewSource(nextHtml);
|
||||||
scheduleChange(nextHtml);
|
scheduleChange(preserveEmptyParagraphs(nextHtml));
|
||||||
},
|
},
|
||||||
|
|
||||||
editorProps: {
|
editorProps: {
|
||||||
@@ -444,7 +445,7 @@ export function KriEditorWysiwyg(props: KriEditorProps) {
|
|||||||
const safe = sanitizeHtmlOpt ? sanitizeHtml(raw, allowedCustomHtml) : raw;
|
const safe = sanitizeHtmlOpt ? sanitizeHtml(raw, allowedCustomHtml) : raw;
|
||||||
|
|
||||||
editor.commands.setContent(safe, { emitUpdate: false, parseOptions: { preserveWhitespace: "full" } });
|
editor.commands.setContent(safe, { emitUpdate: false, parseOptions: { preserveWhitespace: "full" } });
|
||||||
flushChange(editor.getHTML());
|
flushChange(preserveEmptyParagraphs(editor.getHTML()));
|
||||||
setView("wysiwyg");
|
setView("wysiwyg");
|
||||||
}, [allowedCustomHtml, editor, flushChange, sanitizeHtmlOpt]);
|
}, [allowedCustomHtml, editor, flushChange, sanitizeHtmlOpt]);
|
||||||
|
|
||||||
@@ -506,8 +507,8 @@ export function KriEditorWysiwyg(props: KriEditorProps) {
|
|||||||
if (!editor) return;
|
if (!editor) return;
|
||||||
|
|
||||||
const onBlur = () => {
|
const onBlur = () => {
|
||||||
if (viewRef.current === "html") flushChange(htmlDraftRef.current);
|
if (viewRef.current === "html") flushChange(preserveEmptyParagraphs(htmlDraftRef.current));
|
||||||
else flushChange(editor.getHTML());
|
else flushChange(preserveEmptyParagraphs(editor.getHTML()));
|
||||||
};
|
};
|
||||||
|
|
||||||
editor.on("blur", onBlur);
|
editor.on("blur", onBlur);
|
||||||
@@ -542,7 +543,7 @@ export function KriEditorWysiwyg(props: KriEditorProps) {
|
|||||||
if (!editor) return;
|
if (!editor) return;
|
||||||
restoreSelection();
|
restoreSelection();
|
||||||
editor.chain().focus().insertContent(text).run();
|
editor.chain().focus().insertContent(text).run();
|
||||||
flushChange(editor.getHTML());
|
flushChange(preserveEmptyParagraphs(editor.getHTML()));
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
[editor, restoreSelection, flushChange, insertTextareaText]
|
[editor, restoreSelection, flushChange, insertTextareaText]
|
||||||
@@ -563,7 +564,8 @@ export function KriEditorWysiwyg(props: KriEditorProps) {
|
|||||||
}, [command, editor, props.onCommandReady]);
|
}, [command, editor, props.onCommandReady]);
|
||||||
|
|
||||||
const previewHtml = useMemo(() => {
|
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);
|
const withLinkStyle = applyLinkPreviewClass(sanitized);
|
||||||
return transformPreviewHtml ? transformPreviewHtml(withLinkStyle) : withLinkStyle;
|
return transformPreviewHtml ? transformPreviewHtml(withLinkStyle) : withLinkStyle;
|
||||||
}, [allowedCustomHtml, previewSource, sanitizeHtmlOpt, transformPreviewHtml]);
|
}, [allowedCustomHtml, previewSource, sanitizeHtmlOpt, transformPreviewHtml]);
|
||||||
|
|||||||
9
registry/components/kri-editor/utils/emptyParagraph.ts
Normal file
9
registry/components/kri-editor/utils/emptyParagraph.ts
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
const EMPTY_PARAGRAPH_PATTERN = /<p((?:\s+[^>]*)?)>\s*<\/p>/gi;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TipTap이 빈 줄을 <p></p>로 직렬화하면 이메일 클라이언트에서 margin collapse로 사라진다.
|
||||||
|
* 눈에 보이지 않는 콘텐츠( )를 채워 실제 발송 HTML에서도 빈 줄이 유지되게 한다.
|
||||||
|
*/
|
||||||
|
export function preserveEmptyParagraphs(html: string): string {
|
||||||
|
return html.replace(EMPTY_PARAGRAPH_PATTERN, (_match, attrs: string) => `<p${attrs}> </p>`);
|
||||||
|
}
|
||||||
@@ -412,11 +412,21 @@
|
|||||||
"type": "registry:component",
|
"type": "registry:component",
|
||||||
"target": "@components/kri-editor/utils/editorTypeGuards.ts"
|
"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",
|
"path": "kri-editor/utils/imageCompression.ts",
|
||||||
"type": "registry:component",
|
"type": "registry:component",
|
||||||
"target": "@components/kri-editor/utils/imageCompression.ts"
|
"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",
|
"path": "kri-editor/utils/sanitizeHtml.ts",
|
||||||
"type": "registry:component",
|
"type": "registry:component",
|
||||||
|
|||||||
Reference in New Issue
Block a user