feat(inout): 발주 메일 본문 서식 막대(크기·굵게·색·정렬·목록·링크 등)
미리보기 위 서식 막대로 고른 글자의 서식을 바꾼다(execCommand, 표·인라인 서식 유지). 서버는 밑줄·취소선 text-decoration-line 을 메일용 text-decoration 으로 바꿔 보낸다. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+152
-5
@@ -750,6 +750,38 @@
|
||||
const msgEl = dlg.querySelector(".io-dlg-msg"), sendBtn = dlg.querySelector("[data-mail-send]");
|
||||
const titleEl = dlg.querySelector("[data-mail-title]");
|
||||
let base = "", data = null, sent = false, edited = false;
|
||||
// 발주 메일 본문 서식 막대(2026-10-27) — 안내문 발송 편집기와 같은 구성. 함수 안에 둔다(initMail 을 위에서 먼저 부른다 — TDZ)
|
||||
const RTE_TEXT_COLORS = [["#1d1d1f", "기본(검정)"], ["#6b7280", "회색"], ["#d93025", "빨강"], ["#e8710a", "주황"], ["#b58100", "노랑"],
|
||||
["#188038", "초록"], ["#1a73e8", "파랑"], ["#7b2fd0", "보라"]];
|
||||
const RTE_BG_COLORS = [["transparent", "배경 없음"], ["#fff3bf", "노랑"], ["#ffd8a8", "주황"], ["#ffc9c9", "빨강"], ["#d3f9d8", "초록"],
|
||||
["#d0ebff", "파랑"], ["#e5dbff", "보라"], ["#f1f3f5", "회색"]];
|
||||
const ic = function (d) { return '<svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">' + d + "</svg>"; };
|
||||
const tb = function (attr, title, inner) { return '<button type="button" class="io-rte-btn" ' + attr + ' title="' + title + '" aria-label="' + title + '">' + inner + "</button>"; };
|
||||
const RTE_BAR = '<div class="io-rte" role="toolbar" aria-label="본문 서식">' +
|
||||
'<select class="io-rte-size" data-rte-size title="글자 크기" aria-label="글자 크기"><option value="">크기</option>' +
|
||||
["12px", "14px", "16px", "18px", "20px", "24px", "30px"].map(function (s) { return '<option value="' + s + '">' + s.replace("px", "") + (s === "14px" ? " (기본)" : "") + "</option>"; }).join("") +
|
||||
"</select><span class=\"io-rte-sep\"></span>" +
|
||||
tb('data-cmd="bold"', "굵게 (Ctrl+B)", "<b>B</b>") + tb('data-cmd="italic"', "기울임 (Ctrl+I)", "<i>I</i>") +
|
||||
tb('data-cmd="underline"', "밑줄 (Ctrl+U)", "<u>U</u>") + tb('data-cmd="strikeThrough"', "취소선", "<s>S</s>") +
|
||||
'<span class="io-rte-sep"></span>' +
|
||||
tb('data-pop="foreColor"', "글자 색", '<span class="io-rte-a">A</span>') +
|
||||
tb('data-pop="hiliteColor"', "배경 색", ic('<path d="M9 11l-4 4v3h3l4-4"/><path d="M14 6l4 4-6 6-4-4z"/><path d="M4 21h16" stroke="#f9ab00" stroke-width="3"/>')) +
|
||||
'<span class="io-rte-sep"></span>' +
|
||||
tb('data-cmd="justifyLeft"', "왼쪽 정렬", ic('<path d="M4 6h16M4 10h10M4 14h16M4 18h10"/>')) +
|
||||
tb('data-cmd="justifyCenter"', "가운데 정렬", ic('<path d="M4 6h16M7 10h10M4 14h16M7 18h10"/>')) +
|
||||
tb('data-cmd="justifyRight"', "오른쪽 정렬", ic('<path d="M4 6h16M10 10h10M4 14h16M10 18h10"/>')) +
|
||||
'<span class="io-rte-sep"></span>' +
|
||||
tb('data-cmd="insertOrderedList"', "번호 목록", ic('<path d="M10 6h10M10 12h10M10 18h10"/><path d="M4 5h1v4M4 15h2l-2 3h2" stroke-width="1.6"/>')) +
|
||||
tb('data-cmd="insertUnorderedList"', "글머리 목록", ic('<path d="M10 6h10M10 12h10M10 18h10"/><circle cx="5" cy="6" r="1"/><circle cx="5" cy="12" r="1"/><circle cx="5" cy="18" r="1"/>')) +
|
||||
'<span class="io-rte-sep"></span>' +
|
||||
tb('data-pop="link"', "링크", ic('<path d="M10 14a4 4 0 0 0 5.7 0l3-3a4 4 0 0 0-5.7-5.7l-1 1"/><path d="M14 10a4 4 0 0 0-5.7 0l-3 3a4 4 0 0 0 5.7 5.7l1-1"/>')) +
|
||||
tb('data-cmd="removeFormat"', "서식 지우기", ic('<path d="M6 5h12M12 5l-3 14M4 20l16-16" />')) +
|
||||
'<span class="io-rte-sep"></span>' +
|
||||
tb('data-cmd="undo"', "되돌리기 (Ctrl+Z)", ic('<path d="M9 14L4 9l5-5"/><path d="M4 9h11a5 5 0 0 1 0 10h-3"/>')) +
|
||||
tb('data-cmd="redo"', "다시 하기 (Ctrl+Y)", ic('<path d="M15 14l5-5-5-5"/><path d="M20 9H9a5 5 0 0 0 0 10h3"/>')) +
|
||||
'<button type="button" class="io-link-btn io-rte-reset" data-mail-reset hidden>원래 본문으로</button>' +
|
||||
'<div class="io-rte-pop" hidden></div></div>' +
|
||||
'<p class="io-rte-hint">본문을 눌러 바로 고칠 수 있습니다 — 글자를 고른 뒤 위 막대로 서식을 바꾸세요. 고친 내용 그대로 보냅니다.</p>';
|
||||
function say(text, bad) { msgEl.textContent = text || ""; msgEl.hidden = !text; msgEl.classList.toggle("is-bad", !!bad); }
|
||||
function esc(s) { const d = document.createElement("div"); d.textContent = s == null ? "" : String(s); return d.innerHTML; }
|
||||
function field(name) { return body.querySelector('[data-mail-field="' + name + '"]'); }
|
||||
@@ -794,8 +826,7 @@
|
||||
(notice ? '<p class="io-mail-notice">' + esc(notice) + "</p>" : "") +
|
||||
(receipt && data.photos_skipped ? '<p class="io-hint">HEIC 등 본문에 넣지 못하는 입고증 사진 ' + esc(data.photos_skipped) + "장은 빠집니다(입고 기록에는 그대로).</p>" : "") +
|
||||
(sentList ? '<div class="io-mail-sentlist"><b>보낸 기록</b><ul>' + sentList + "</ul></div>" : "") +
|
||||
(cfg.editable ? '<div class="io-mail-edit-bar"><span>본문을 눌러 바로 고칠 수 있습니다 — 고친 내용 그대로 보냅니다.</span>' +
|
||||
'<button type="button" class="io-link-btn" data-mail-reset hidden>원래 본문으로</button></div>' : "") +
|
||||
(cfg.editable ? RTE_BAR : "") +
|
||||
'<iframe class="io-mail-preview" title="메일 본문 미리보기"></iframe>';
|
||||
edited = false;
|
||||
setupPreview(body.querySelector(".io-mail-preview"), data.html);
|
||||
@@ -803,21 +834,137 @@
|
||||
}
|
||||
// 발주 메일 본문 고치기(2026-10-27) — 미리보기 iframe 을 designMode 로. 스크립트는 막고(allow-scripts 없음) 부모만 문서에 손댈 수 있게
|
||||
// allow-same-origin. 보낼 때 고쳤으면 body HTML 을 같이 보낸다(서버가 허용 태그·서식만 남김).
|
||||
// 서식 막대(RTE_BAR) = execCommand — 표·인라인 서식을 그대로 두려고 Quill 대신(Quill 은 표를 못 담는다). 글자 서식은 span style 로.
|
||||
function setupPreview(ifr, html) {
|
||||
ifr.setAttribute("sandbox", cfg.editable ? "allow-same-origin" : "");
|
||||
if (!cfg.editable) { ifr.srcdoc = html; return; }
|
||||
const reset = body.querySelector("[data-mail-reset]");
|
||||
const bar = body.querySelector(".io-rte"), reset = bar.querySelector("[data-mail-reset]");
|
||||
const sizeSel = bar.querySelector("[data-rte-size]"), pop = bar.querySelector(".io-rte-pop");
|
||||
let doc = null, saved = null;
|
||||
function markEdited() { edited = true; reset.hidden = false; }
|
||||
function saveRange() {
|
||||
const sel = doc && doc.getSelection();
|
||||
if (sel && sel.rangeCount) saved = sel.getRangeAt(0).cloneRange();
|
||||
}
|
||||
// 본문 문서는 포커스가 막대로 가도 자기 선택을 지닌다 — 그게 있으면 그대로, 없을 때만 기억한 선택
|
||||
function restoreRange() {
|
||||
const sel = doc.getSelection();
|
||||
const keep = sel && sel.rangeCount ? sel.getRangeAt(0).cloneRange() : saved;
|
||||
ifr.contentWindow.focus();
|
||||
if (!keep) return;
|
||||
sel.removeAllRanges();
|
||||
sel.addRange(keep);
|
||||
}
|
||||
function exec(cmd, value) {
|
||||
if (!doc) return;
|
||||
restoreRange();
|
||||
doc.execCommand("styleWithCSS", false, true);
|
||||
doc.execCommand(cmd, false, value == null ? null : value);
|
||||
saveRange();
|
||||
markEdited();
|
||||
refresh();
|
||||
}
|
||||
// 글자 크기 — execCommand 는 1~7 단계뿐이라 7 로 칠한 뒤 그 font 를 px 크기 span 으로 바꾼다
|
||||
function setSize(px) {
|
||||
if (!doc) return;
|
||||
restoreRange();
|
||||
doc.execCommand("styleWithCSS", false, false);
|
||||
doc.execCommand("fontSize", false, "7");
|
||||
const spans = [];
|
||||
doc.querySelectorAll('font[size="7"]').forEach(function (f) {
|
||||
const span = doc.createElement("span");
|
||||
span.style.fontSize = px;
|
||||
while (f.firstChild) span.appendChild(f.firstChild);
|
||||
f.replaceWith(span);
|
||||
span.querySelectorAll("span").forEach(function (s) { s.style.fontSize = ""; }); // 안쪽 예전 크기는 지운다
|
||||
spans.push(span);
|
||||
});
|
||||
if (spans.length) { // font 를 바꿔 끼우면 선택이 풀린다 — 바꾼 글자를 다시 고른 채로
|
||||
const r = doc.createRange();
|
||||
r.setStartBefore(spans[0]);
|
||||
r.setEndAfter(spans[spans.length - 1]);
|
||||
doc.getSelection().removeAllRanges();
|
||||
doc.getSelection().addRange(r);
|
||||
}
|
||||
saveRange();
|
||||
markEdited();
|
||||
refresh();
|
||||
}
|
||||
// 버튼 켜짐(굵게 등)·지금 글자 크기 표시
|
||||
function refresh() {
|
||||
if (!doc) return;
|
||||
bar.querySelectorAll("[data-cmd]").forEach(function (b) {
|
||||
let on = false;
|
||||
try { on = doc.queryCommandState(b.dataset.cmd); } catch (_) { /* 상태 없는 명령 */ }
|
||||
b.classList.toggle("is-active", !!on);
|
||||
});
|
||||
const sel = doc.getSelection();
|
||||
let el = sel && sel.anchorNode;
|
||||
if (el && el.nodeType === 1 && el.childNodes[sel.anchorOffset]) el = el.childNodes[sel.anchorOffset]; // 선택이 요소 경계에서 시작
|
||||
if (el && el.nodeType === 3) el = el.parentNode;
|
||||
const px = el && el.nodeType === 1 ? Math.round(parseFloat(doc.defaultView.getComputedStyle(el).fontSize)) + "px" : "";
|
||||
sizeSel.value = [].some.call(sizeSel.options, function (o) { return o.value === px; }) ? px : "";
|
||||
}
|
||||
function closePop() { pop.hidden = true; pop.innerHTML = ""; }
|
||||
function openPop(kind, anchor) {
|
||||
if (!pop.hidden && pop.dataset.kind === kind) { closePop(); return; }
|
||||
pop.dataset.kind = kind;
|
||||
if (kind === "link") {
|
||||
pop.innerHTML = '<input class="io-in" type="url" placeholder="https://… 또는 mailto:…" data-rte-url />' +
|
||||
'<button type="button" class="erp-btn erp-btn-primary erp-btn-sm" data-rte-link-ok>넣기</button>' +
|
||||
'<button type="button" class="erp-btn erp-btn-outline erp-btn-sm" data-rte-unlink>링크 빼기</button>';
|
||||
} else {
|
||||
const colors = kind === "foreColor" ? RTE_TEXT_COLORS : RTE_BG_COLORS;
|
||||
pop.innerHTML = colors.map(function (c) {
|
||||
return '<button type="button" class="io-rte-sw' + (c[0] === "transparent" ? " is-none" : "") + '" data-rte-color="' + c[0] +
|
||||
'" style="background:' + c[0] + '" title="' + c[1] + '" aria-label="' + c[1] + '"></button>';
|
||||
}).join("");
|
||||
}
|
||||
pop.style.left = anchor.offsetLeft + "px";
|
||||
pop.style.top = anchor.offsetTop + anchor.offsetHeight + 4 + "px";
|
||||
pop.hidden = false;
|
||||
const url = pop.querySelector("[data-rte-url]");
|
||||
if (url) url.focus();
|
||||
}
|
||||
ifr.addEventListener("load", function () {
|
||||
const doc = ifr.contentDocument;
|
||||
doc = ifr.contentDocument;
|
||||
saved = null;
|
||||
if (!doc) return;
|
||||
doc.designMode = "on";
|
||||
doc.body.style.outline = "none";
|
||||
doc.addEventListener("input", function () { edited = true; reset.hidden = false; });
|
||||
doc.addEventListener("input", markEdited);
|
||||
doc.addEventListener("selectionchange", function () { saveRange(); refresh(); });
|
||||
doc.addEventListener("mousedown", closePop);
|
||||
});
|
||||
// 막대를 누르는 순간의 본문 선택을 기억(크기 고르기·링크 칸으로 포커스가 옮겨 가도 그 글자에) — 색·링크 팝업 안은 이미 기억한 선택 그대로.
|
||||
// 버튼은 기본 동작을 막아 본문 선택이 풀리지 않게
|
||||
bar.addEventListener("mousedown", function (e) {
|
||||
if (!e.target.closest(".io-rte-pop")) saveRange();
|
||||
if (e.target.closest("button")) e.preventDefault();
|
||||
});
|
||||
bar.addEventListener("click", function (e) {
|
||||
const b = e.target.closest("button");
|
||||
if (!b) return;
|
||||
if (b.dataset.cmd) { closePop(); exec(b.dataset.cmd); }
|
||||
else if (b.dataset.pop) openPop(b.dataset.pop, b);
|
||||
else if (b.dataset.rteColor) { exec(pop.dataset.kind, b.dataset.rteColor); closePop(); }
|
||||
else if (b.hasAttribute("data-rte-link-ok")) {
|
||||
const v = pop.querySelector("[data-rte-url]").value.trim();
|
||||
if (!/^(https?:\/\/|mailto:)/i.test(v)) { pop.querySelector("[data-rte-url]").focus(); return; }
|
||||
exec("createLink", v);
|
||||
closePop();
|
||||
} else if (b.hasAttribute("data-rte-unlink")) { exec("unlink"); closePop(); }
|
||||
});
|
||||
bar.addEventListener("keydown", function (e) {
|
||||
if (e.key === "Enter" && e.target.matches("[data-rte-url]")) { e.preventDefault(); pop.querySelector("[data-rte-link-ok]").click(); }
|
||||
if (e.key === "Escape" && !pop.hidden) { e.preventDefault(); e.stopPropagation(); closePop(); }
|
||||
});
|
||||
sizeSel.addEventListener("change", function () { if (sizeSel.value) setSize(sizeSel.value); else setSize("14px"); });
|
||||
reset.onclick = async function () {
|
||||
if (!(await confirmMsg("고친 내용을 버리고 원래 본문으로 되돌릴까요?"))) return;
|
||||
edited = false;
|
||||
reset.hidden = true;
|
||||
closePop();
|
||||
ifr.srcdoc = data.html;
|
||||
};
|
||||
ifr.srcdoc = html;
|
||||
|
||||
Reference in New Issue
Block a user