feat(project): 설명 체크박스를 글머리 목록처럼(체크리스트) + 작업 창 스크롤바 정리
- ☑ = 체크리스트 켜기/끄기: 지금 줄(고른 줄들)을 <ul class="pj-checklist"> 로, 줄마다 체크박스. Enter 로 새 줄에도 체크박스, 빈 줄 Enter 는 목록 끝. 체크리스트 안에서 글머리·번호 버튼은 체크박스를 빼고 그 목록으로. 체크한 줄은 흐리게 + 취소선 - 서버 정리기: ul 의 class 는 pj-checklist 하나만 허용(태그별 허용 class 표) - 작업 창 스크롤 영역: 가로 스크롤 제거(설명란 음수 여백 때문에 생기던 것), 오른쪽 여백까지 넓혀 세로 스크롤바를 창 오른쪽 끝으로 - 도움말 8장 체크리스트 설명 갱신, 정적 파일 버전 20260926q Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+115
-4
@@ -4977,6 +4977,101 @@
|
||||
// 크롬/엣지는 여전히 지원하고, 이미 같은 파일의 이미지 삽입에서도 쓰고
|
||||
// 있어(insertHTML) 일관된 패턴이다. 버튼 mousedown 에서 preventDefault
|
||||
// 안 하면 클릭 순간 에디터가 포커스를 잃어 선택 범위가 풀린다.
|
||||
// ── 체크리스트(서식 도구 ☑) — 글머리 목록처럼 줄마다 체크박스.
|
||||
// <ul class="pj-checklist"><li><input type="checkbox">할 일</li>…</ul>
|
||||
// (서버 정리기는 ul 의 class 로 pj-checklist 하나만, input 은 체크박스·checked 만 남긴다)
|
||||
function selNode() {
|
||||
const sel = window.getSelection();
|
||||
if (!sel || !sel.rangeCount) return null;
|
||||
const n = sel.getRangeAt(0).startContainer;
|
||||
return n.nodeType === 1 ? n : n.parentElement;
|
||||
}
|
||||
function closestIn(n, selector) {
|
||||
const x = n && n.closest ? n.closest(selector) : null;
|
||||
return x && box.contains(x) ? x : null;
|
||||
}
|
||||
// 줄(li) 맨 앞의 체크박스(앞의 빈 글자는 건너뜀)
|
||||
function leadingBox(li) {
|
||||
for (let c = li.firstChild; c; c = c.nextSibling) {
|
||||
if (c.nodeType === 3 && !c.nodeValue.replace(/[\s\u00a0\u200b]/g, "")) continue;
|
||||
return (c.nodeType === 1 && c.tagName === "INPUT" && c.type === "checkbox") ? c : null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
function caretAfter(node) {
|
||||
const r = document.createRange();
|
||||
r.setStartAfter(node); r.collapse(true);
|
||||
const sel = window.getSelection();
|
||||
sel.removeAllRanges(); sel.addRange(r);
|
||||
}
|
||||
function ensureBox(li) {
|
||||
let cb = leadingBox(li);
|
||||
if (!cb) { cb = document.createElement("input"); cb.type = "checkbox"; li.insertBefore(cb, li.firstChild); }
|
||||
return cb;
|
||||
}
|
||||
function selectedItems(listEl) {
|
||||
const sel = window.getSelection();
|
||||
const r = sel && sel.rangeCount ? sel.getRangeAt(0) : null;
|
||||
const items = Array.prototype.filter.call(listEl.children, function (li) {
|
||||
return li.tagName === "LI" && r && r.intersectsNode(li);
|
||||
});
|
||||
if (!items.length) { const li = closestIn(selNode(), "li"); if (li) items.push(li); }
|
||||
return items;
|
||||
}
|
||||
// 체크박스가 하나도 없는 체크리스트는 평범한 목록으로, 줄마다 체크박스가 있는 ul 은 체크리스트로
|
||||
function normalizeChecklists() {
|
||||
box.querySelectorAll("ul").forEach(function (ul) {
|
||||
const lis = Array.prototype.filter.call(ul.children, function (x) { return x.tagName === "LI"; });
|
||||
const withBox = lis.filter(function (li) { return leadingBox(li); }).length;
|
||||
if (ul.classList.contains("pj-checklist") && !withBox) ul.classList.remove("pj-checklist");
|
||||
else if (lis.length && withBox === lis.length) ul.classList.add("pj-checklist");
|
||||
if (!ul.className) ul.removeAttribute("class");
|
||||
});
|
||||
}
|
||||
function toggleChecklist() {
|
||||
const cur = closestIn(selNode(), "ul.pj-checklist");
|
||||
if (cur) {
|
||||
// 끄기 — 고른 줄의 체크박스를 빼고 목록에서 뺀다(글머리 버튼을 다시 누른 것과 같음)
|
||||
selectedItems(cur).forEach(function (li) { const cb = leadingBox(li); if (cb) cb.remove(); });
|
||||
try { document.execCommand("insertUnorderedList"); } catch (_) {}
|
||||
} else {
|
||||
// 켜기 — 목록이 아니면 먼저 글머리 목록으로 만든 뒤(번호 목록이면 글머리로 바뀜),
|
||||
// 그 목록의 줄마다 체크박스
|
||||
if (!closestIn(selNode(), "ul")) { try { document.execCommand("insertUnorderedList"); } catch (_) {} }
|
||||
const ul = closestIn(selNode(), "ul");
|
||||
if (ul) {
|
||||
ul.classList.add("pj-checklist");
|
||||
Array.prototype.forEach.call(ul.children, function (li) { if (li.tagName === "LI") ensureBox(li); });
|
||||
const li = closestIn(selNode(), "li");
|
||||
if (li && !li.textContent.replace(/[\s\u00a0\u200b]/g, "")) caretAfter(leadingBox(li));
|
||||
}
|
||||
}
|
||||
normalizeChecklists();
|
||||
}
|
||||
// 체크리스트 줄에서 Enter — 새 줄에도 체크박스(체크 안 된 채). 빈 줄에서 Enter 는 목록 끝.
|
||||
box.addEventListener("keydown", function (e) {
|
||||
if (e.key !== "Enter" || e.shiftKey || e.isComposing) return;
|
||||
const li = closestIn(selNode(), "ul.pj-checklist > li");
|
||||
if (!li) return;
|
||||
if (!li.textContent.replace(/[\s\u00a0\u200b]/g, "")) {
|
||||
e.preventDefault();
|
||||
const cb = leadingBox(li);
|
||||
if (cb) cb.remove();
|
||||
try { document.execCommand("insertUnorderedList"); } catch (_) {}
|
||||
normalizeChecklists();
|
||||
box.dispatchEvent(new Event("input", { bubbles: true }));
|
||||
return;
|
||||
}
|
||||
setTimeout(function () {
|
||||
const nli = closestIn(selNode(), "ul.pj-checklist > li");
|
||||
if (!nli || nli === li) return;
|
||||
let cb = leadingBox(nli);
|
||||
if (!cb) { cb = ensureBox(nli); caretAfter(cb); }
|
||||
else if (cb.hasAttribute("checked")) { cb.removeAttribute("checked"); cb.checked = false; }
|
||||
box.dispatchEvent(new Event("input", { bubbles: true }));
|
||||
}, 0);
|
||||
});
|
||||
|
||||
const fmtbar = el("pj-desc-fmtbar");
|
||||
if (fmtbar) {
|
||||
fmtbar.addEventListener("mousedown", function (e) { e.preventDefault(); });
|
||||
@@ -4990,12 +5085,23 @@
|
||||
arg = prompt("연결할 주소(URL)를 입력하세요", "https://");
|
||||
if (!arg) return;
|
||||
}
|
||||
// 체크박스 — 커서 자리에 체크박스 하나 + 공백. 누르면 체크/해제(아래 클릭 처리).
|
||||
// 체크리스트 — 글머리 목록처럼 켜고 끈다(줄마다 체크박스).
|
||||
if (cmd === "insertCheckbox") {
|
||||
try { document.execCommand("insertHTML", false, '<input type="checkbox"> '); } catch (_) {}
|
||||
toggleChecklist();
|
||||
box.dispatchEvent(new Event("input", { bubbles: true }));
|
||||
updateFmtState();
|
||||
return;
|
||||
}
|
||||
// 체크리스트 안에서 글머리/번호 버튼 — 체크박스를 빼고 그 목록으로 바꾼다.
|
||||
if (cmd === "insertUnorderedList" || cmd === "insertOrderedList") {
|
||||
const cl = closestIn(selNode(), "ul.pj-checklist");
|
||||
if (cl) {
|
||||
Array.prototype.forEach.call(cl.children, function (li) { const cb = li.tagName === "LI" && leadingBox(li); if (cb) cb.remove(); });
|
||||
cl.classList.remove("pj-checklist");
|
||||
if (!cl.className) cl.removeAttribute("class");
|
||||
if (cmd === "insertUnorderedList") { box.dispatchEvent(new Event("input", { bubbles: true })); updateFmtState(); return; }
|
||||
}
|
||||
}
|
||||
try { document.execCommand(cmd, false, arg); } catch (_) {}
|
||||
if (cmd === "createLink") normalizeEditorLinks(box);
|
||||
updateFmtState();
|
||||
@@ -5003,9 +5109,14 @@
|
||||
function updateFmtState() {
|
||||
fmtbar.querySelectorAll(".pj-desc-fmtbtn[data-cmd]").forEach(function (btn) {
|
||||
const cmd = btn.dataset.cmd;
|
||||
if (cmd === "createLink" || cmd === "removeFormat" || cmd === "insertCheckbox") return;
|
||||
if (cmd === "createLink" || cmd === "removeFormat") return;
|
||||
const inChecklist = !!closestIn(selNode(), "ul.pj-checklist");
|
||||
let active = false;
|
||||
try { active = document.queryCommandState(cmd); } catch (_) { active = false; }
|
||||
if (cmd === "insertCheckbox") active = inChecklist;
|
||||
else {
|
||||
try { active = document.queryCommandState(cmd); } catch (_) { active = false; }
|
||||
if (cmd === "insertUnorderedList" && inChecklist) active = false;
|
||||
}
|
||||
btn.classList.toggle("is-active", active);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user