fix(ui): 글 입력 칸 우클릭 브라우저 메뉴도 막음 · B09 설계내역서 글 칸 줄 메뉴(184-1)
- 공용 ui_template_native_menu: 글 입력 칸 예외(isTextEditable) 삭제 - B09 attachRowMenu: 글 칸 위 return 삭제 - 시험: test_common_native_menu 기대값 · test_182 글 칸 줄 메뉴 시험 Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018jonfdxn1Xit9bdkNJpE4G
This commit is contained in:
@@ -3,32 +3,18 @@
|
||||
* 브라우저 기본 오른쪽 클릭 메뉴 막기 — 공용 진입(`A00_Common/main.ts`) · CAD iframe(`cad_host.ts`)이 부름.
|
||||
*
|
||||
* 창 캡처 단계에서 `preventDefault` 만 함 — 이벤트는 멈추지 않으므로 우리 메뉴 듣기는 그대로 돎.
|
||||
* 글 입력 칸(input · textarea · contenteditable · 읽기 전용 포함)은 브라우저 메뉴를 살림(붙여넣기 · 맞춤법).
|
||||
* ⚠ `instanceof` 안 씀 — iframe 문서의 요소는 다른 realm 이라 `instanceof HTMLElement` 가 거짓.
|
||||
* 글 입력 칸도 막음 — 붙여넣기 · 복사는 Ctrl+V · Ctrl+C · 그 칸에 우리 메뉴가 붙어 있으면 그 메뉴가 뜸.
|
||||
* ========================================================================== */
|
||||
|
||||
/** 막을 주소 — B · M 영역(`b01-…` · `m02-…`) · A 영역은 그대로 */
|
||||
export const NATIVE_MENU_ROUTE = /^[bm]\d/;
|
||||
|
||||
/** 글을 쓰는 input 종류 — checkbox · range · button 등은 빠짐 */
|
||||
const TEXT_INPUT_TYPES = new Set(["text", "search", "number", "email", "url", "tel", "password"]);
|
||||
|
||||
/** 오른쪽 클릭 자리가 글 입력 칸인지 */
|
||||
export function isTextEditable(target: EventTarget | null): boolean {
|
||||
const node = target as { tagName?: unknown; isContentEditable?: boolean; type?: string } | null;
|
||||
if (!node || typeof node.tagName !== "string") return false;
|
||||
if (node.isContentEditable) return true;
|
||||
const tag = node.tagName.toUpperCase();
|
||||
if (tag === "TEXTAREA") return true;
|
||||
return tag === "INPUT" && TEXT_INPUT_TYPES.has((node.type || "text").toLowerCase());
|
||||
}
|
||||
|
||||
/** `win` 의 기본 메뉴를 막음 — `isOn()` 이 거짓이면(예: A 영역 주소) 그대로 둠 */
|
||||
export function blockNativeMenu(win: Window, isOn: () => boolean): void {
|
||||
win.addEventListener(
|
||||
"contextmenu",
|
||||
(event) => {
|
||||
if (isOn() && !isTextEditable(event.target)) event.preventDefault();
|
||||
if (isOn()) event.preventDefault();
|
||||
},
|
||||
true,
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user