260805_01_ENH: 이메일 템플릿 저장 시 빈 칸 유지, 외부 설문에서 리스트 단건 조회, 리스트 헤더조회, 리스트 단건 수정 기능 사용할수 있도록 api 라우트 생성 및 cors 완화
This commit is contained in:
@@ -8,6 +8,7 @@ import { resolveUploadUrl } from './types'
|
||||
import { compressImage } from './utils/imageCompression'
|
||||
import { useDebouncedChange } from './hooks/useDebouncedChange'
|
||||
import { sanitizeHtmlForPreview } from './utils/sanitizeHtml'
|
||||
import { preserveEmptyParagraphs } from './utils/emptyParagraph'
|
||||
import { useTextareaInsert } from './hooks/useTextareaInsert'
|
||||
|
||||
type HtmlOnlyProps = Omit<KriEditorProps, 'mode'> & { mode: 'html' }
|
||||
@@ -121,7 +122,7 @@ export function KriEditorHtmlOnly({
|
||||
}
|
||||
}
|
||||
|
||||
const previewHtml = React.useMemo(() => sanitizeHtmlForPreview(html), [html])
|
||||
const previewHtml = React.useMemo(() => sanitizeHtmlForPreview(preserveEmptyParagraphs(html)), [html])
|
||||
|
||||
return (
|
||||
<div className={cn('rounded-md border bg-background', className)}>
|
||||
|
||||
@@ -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]);
|
||||
|
||||
9
src/components/kri-editor/utils/emptyParagraph.ts
Normal file
9
src/components/kri-editor/utils/emptyParagraph.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
const EMPTY_PARAGRAPH_PATTERN = /<p((?:\s+[^>]*)?)>\s*<\/p>/gi;
|
||||
|
||||
/**
|
||||
* 내용이 전혀 없는 <p></p>는 CSS margin이 collapse되어 이메일 클라이언트 등
|
||||
* 우리 앱 밖에서는 높이 0으로 붙어버린다. 를 채워 실제 콘텐츠로 줄 높이를 보장한다.
|
||||
*/
|
||||
export function preserveEmptyParagraphs(html: string): string {
|
||||
return html.replace(EMPTY_PARAGRAPH_PATTERN, (_match, attrs: string) => `<p${attrs}> </p>`);
|
||||
}
|
||||
Reference in New Issue
Block a user