251216_01_ENH : 프로젝트에 FW User 배정 구현 및 테스트 완료

This commit is contained in:
2025-12-16 16:57:03 +09:00
parent d9775c8a1d
commit bfbf4635b3
19 changed files with 813 additions and 107 deletions

View File

@@ -79,6 +79,7 @@ export function KriEditorWysiwyg(props: KriEditorProps) {
debounceMs = 350,
onImageUpload,
onImageUploadError,
maxImageBytes = 5 * 1024 * 1024,
imageMaxWidth = 1600,
imageMaxHeight = 1600,
@@ -93,6 +94,11 @@ export function KriEditorWysiwyg(props: KriEditorProps) {
const isLmsMode = mode === "lms";
const showHtmlToggle = mode === "both";
const LINK_HTML_ATTRS = {
rel: "noopener noreferrer",
target: "_blank",
} as const;
const { scheduleChange, flushChange, optimisticHtmlRef } = useDebouncedChange(onChange, debounceMs);
const fileRef = useRef<HTMLInputElement | null>(null);
@@ -156,13 +162,12 @@ export function KriEditorWysiwyg(props: KriEditorProps) {
Div,
Link.configure({
openOnClick: false,
autolink: true,
openOnClick: false,
linkOnPaste: true,
HTMLAttributes: {
class: "text-blue-600 underline underline-offset-2",
rel: "noopener noreferrer nofollow",
target: "_blank",
class: "cursor-pointer text-blue-600 underline underline-offset-2",
...LINK_HTML_ATTRS,
},
}),
@@ -174,6 +179,7 @@ export function KriEditorWysiwyg(props: KriEditorProps) {
TableCell,
TiptapImage.configure({
inline: true,
allowBase64,
HTMLAttributes: {
class: "max-w-full h-auto",
@@ -206,6 +212,52 @@ export function KriEditorWysiwyg(props: KriEditorProps) {
"[&_td]:border [&_td]:p-2 [&_td]:align-top [&_td]:min-w-[90px]"
),
},
handleDOMEvents: {
click: (view, event) => {
const e = event as MouseEvent;
// Alt + 좌클릭만
if (!e.altKey || e.button !== 0) return false;
// 이미지(또는 리사이즈 컨테이너) 클릭일 때만
const target = e.target as HTMLElement | null;
const isImageClick = !!target?.closest?.("img, [data-resize-container]");
if (!isImageClick) return false;
// 1) 문서 상태에서 link mark의 href 찾기 (NodeView/리사이즈 DOM에서도 안전)
const pos = view.posAtCoords({ left: e.clientX, top: e.clientY });
const linkType = view.state.schema.marks.link;
let href: string | undefined;
if (pos && linkType) {
const $pos = view.state.doc.resolve(pos.pos);
const pickHref = (marks: readonly any[] | null | undefined) =>
marks?.find(m => m.type === linkType)?.attrs?.href as string | undefined;
href =
pickHref($pos.marks()) ||
pickHref($pos.nodeAfter?.marks) ||
pickHref($pos.nodeBefore?.marks);
}
// 2) DOM fallback (실제 <a>가 있는 경우)
if (!href) {
const a = target?.closest?.("a") as HTMLAnchorElement | null;
if (a?.href) href = a.href;
}
if (!href) return false;
// 링크 열기 + 에디터 클릭 처리(커서 이동 등) 막기
e.preventDefault();
e.stopPropagation();
console.log(LINK_HTML_ATTRS.rel.replaceAll(" ",","))
window.open(href, LINK_HTML_ATTRS.target, LINK_HTML_ATTRS.rel.replaceAll(" ",","));
return true;
},
},
},
});
@@ -318,12 +370,14 @@ const normalizeLinkUrl = (raw: string): string => {
if (!editor) return;
restoreSelection();
const prev = (editor.getAttributes("link").href as string | undefined) ?? "";
if (editor.isActive("link")) {
editor.chain().focus().unsetLink().run();
return;
if(confirm(`링크를 해제 하시겠습니까?\r\nLink: ${prev}`)){
editor.chain().focus().unsetLink().run();
return;
}
}
const prev = (editor.getAttributes("link").href as string | undefined) ?? "";
const url = window.prompt("링크 URL을 입력하세요", prev);
if (url === null) return;
@@ -412,8 +466,12 @@ const normalizeLinkUrl = (raw: string): string => {
restoreSelection();
editor.chain().focus().setImage({ src: url }).run();
} catch (err) {
toast.error("이미지 업로드에 실패했습니다.");
console.error(err);
if(onImageUploadError){
onImageUploadError(err);
}else{
toast.error("이미지 업로드에 실패했습니다.");
console.error(err);
}
}
},
[