260728_04_ENH: 에디터에 커스텀 태그 인식하도록 수정
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "kri-ui-registry",
|
||||
"version": "0.9.5",
|
||||
"version": "0.9.6",
|
||||
"private": true,
|
||||
"description": "KRI internal shadcn UI registry",
|
||||
"scripts": {
|
||||
|
||||
@@ -87,6 +87,8 @@ export function KriEditorWysiwyg(props: KriEditorProps) {
|
||||
allowBase64 = false,
|
||||
sanitizeHtml: sanitizeHtmlOpt = true,
|
||||
toolbar = {},
|
||||
editorExtensions = [],
|
||||
allowedCustomHtml,
|
||||
} = props;
|
||||
|
||||
const showHtmlToggle = mode === "both";
|
||||
@@ -179,6 +181,7 @@ export function KriEditorWysiwyg(props: KriEditorProps) {
|
||||
},
|
||||
}),
|
||||
Placeholder.configure({ placeholder }),
|
||||
...editorExtensions,
|
||||
],
|
||||
|
||||
content: value || "<p></p>",
|
||||
@@ -436,12 +439,12 @@ export function KriEditorWysiwyg(props: KriEditorProps) {
|
||||
}
|
||||
|
||||
const raw = htmlDraftRef.current;
|
||||
const safe = sanitizeHtmlOpt ? sanitizeHtml(raw) : raw;
|
||||
const safe = sanitizeHtmlOpt ? sanitizeHtml(raw, allowedCustomHtml) : raw;
|
||||
|
||||
editor.commands.setContent(safe, { emitUpdate: false, parseOptions: { preserveWhitespace: "full" } });
|
||||
flushChange(editor.getHTML());
|
||||
setView("wysiwyg");
|
||||
}, [editor, flushChange, sanitizeHtmlOpt]);
|
||||
}, [allowedCustomHtml, editor, flushChange, sanitizeHtmlOpt]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!editor) return;
|
||||
@@ -558,8 +561,8 @@ export function KriEditorWysiwyg(props: KriEditorProps) {
|
||||
}, [command, editor, props.onCommandReady]);
|
||||
|
||||
const previewHtml = useMemo(() => {
|
||||
return sanitizeHtmlOpt ? sanitizeHtml(previewSource) : previewSource;
|
||||
}, [previewSource, sanitizeHtmlOpt]);
|
||||
return sanitizeHtmlOpt ? sanitizeHtml(previewSource, allowedCustomHtml) : previewSource;
|
||||
}, [allowedCustomHtml, previewSource, sanitizeHtmlOpt]);
|
||||
|
||||
if (!editor) {
|
||||
return (
|
||||
|
||||
@@ -4,6 +4,7 @@ export { KriEditorSms } from './KriEditorSms'
|
||||
export { KriEditorWysiwyg } from './KriEditorWysiwyg'
|
||||
export { ToolbarButton as KriEditorToolbarButton } from './toolbar/ToolbarButton'
|
||||
export type {
|
||||
KriEditorAllowedHtml,
|
||||
KriEditorCommand,
|
||||
KriEditorMode,
|
||||
KriEditorProps,
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import type { Extensions } from '@tiptap/core'
|
||||
import type { Editor } from '@tiptap/react'
|
||||
import type { ReactNode } from 'react'
|
||||
|
||||
@@ -33,6 +34,11 @@ export type KriEditorToolbarContext = {
|
||||
view: 'wysiwyg' | 'html'
|
||||
}
|
||||
|
||||
export type KriEditorAllowedHtml = {
|
||||
tags?: string[]
|
||||
attributes?: string[]
|
||||
}
|
||||
|
||||
export type KriEditorProps = {
|
||||
onEditorReady?: (editor: Editor | HTMLTextAreaElement | null) => void
|
||||
onCommandReady?: (command: KriEditorCommand | null) => void
|
||||
@@ -64,6 +70,8 @@ export type KriEditorProps = {
|
||||
lmsMaxBytes?: number
|
||||
toolbar?: KriEditorToolbarConfig | false
|
||||
renderToolbarEnd?: (context: KriEditorToolbarContext) => ReactNode
|
||||
editorExtensions?: Extensions
|
||||
allowedCustomHtml?: KriEditorAllowedHtml
|
||||
}
|
||||
|
||||
export type ToolbarState = {
|
||||
|
||||
@@ -2,14 +2,14 @@
|
||||
|
||||
import DOMPurify from "dompurify";
|
||||
|
||||
const HTML_PROFILE = {
|
||||
USE_PROFILES: {
|
||||
html: true,
|
||||
},
|
||||
} as const;
|
||||
export type SanitizeHtmlOptions = {
|
||||
tags?: string[];
|
||||
attributes?: string[];
|
||||
};
|
||||
|
||||
export function sanitizeHtml(
|
||||
input: string,
|
||||
options?: SanitizeHtmlOptions,
|
||||
): string {
|
||||
if (!input) {
|
||||
return "";
|
||||
@@ -17,12 +17,19 @@ export function sanitizeHtml(
|
||||
|
||||
return DOMPurify.sanitize(
|
||||
input,
|
||||
HTML_PROFILE,
|
||||
{
|
||||
USE_PROFILES: {
|
||||
html: true,
|
||||
},
|
||||
ADD_TAGS: options?.tags ?? [],
|
||||
ADD_ATTR: options?.attributes ?? [],
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
export function sanitizeHtmlForPreview(
|
||||
input: string,
|
||||
options?: SanitizeHtmlOptions,
|
||||
): string {
|
||||
return sanitizeHtml(input);
|
||||
return sanitizeHtml(input, options);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user