fix(project): 설명 체크리스트를 진짜 글머리 기호처럼 + 서식 도구 상단 고정
- 체크박스를 글자 속 <input> 대신 글머리 자리에 CSS 로 그린다(li::before) — 체크박스 왼쪽에 글자가 들어가던 버그 해결, Enter·빈 줄 Enter·Backspace 는 브라우저 글머리 목록 동작 그대로. 체크 여부는 li data-checked="true", 글자보다 왼쪽(체크박스)을 누르면 체크/해제. 새 줄은 체크 안 된 채로 시작 - 예전 방식(<input type=checkbox>) 체크리스트는 열 때 자동으로 새 방식으로 변환 - 서버 정리기: li 의 data-checked="true" 만 허용 - 서식 도구 줄 sticky — 설명을 아래로 스크롤해도 설명 구간 안에서는 위에 붙어 있음 - 정적 파일 버전 20260926r Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+46
-57
@@ -4977,9 +4977,12 @@
|
||||
// 크롬/엣지는 여전히 지원하고, 이미 같은 파일의 이미지 삽입에서도 쓰고
|
||||
// 있어(insertHTML) 일관된 패턴이다. 버튼 mousedown 에서 preventDefault
|
||||
// 안 하면 클릭 순간 에디터가 포커스를 잃어 선택 범위가 풀린다.
|
||||
// ── 체크리스트(서식 도구 ☑) — 글머리 목록처럼 줄마다 체크박스.
|
||||
// <ul class="pj-checklist"><li><input type="checkbox">할 일</li>…</ul>
|
||||
// (서버 정리기는 ul 의 class 로 pj-checklist 하나만, input 은 체크박스·checked 만 남긴다)
|
||||
// ── 체크리스트(서식 도구 ☑) — 글머리 기호처럼 줄마다 체크박스.
|
||||
// <ul class="pj-checklist"><li data-checked="true">한 일</li><li>할 일</li></ul>
|
||||
// 체크박스는 글자 속 요소가 아니라 글머리 기호 자리에 CSS 가 그린다(li::before) — 그래서
|
||||
// 체크박스 왼쪽에 글자가 들어갈 수 없고, Enter(새 줄)·빈 줄 Enter(목록 끝)·Backspace 는
|
||||
// 브라우저의 글머리 목록 동작 그대로다. 체크 여부는 li 의 data-checked 로 저장
|
||||
// (서버 정리기는 ul 의 class="pj-checklist", li 의 data-checked="true" 만 남긴다).
|
||||
function selNode() {
|
||||
const sel = window.getSelection();
|
||||
if (!sel || !sel.rangeCount) return null;
|
||||
@@ -4990,25 +4993,6 @@
|
||||
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;
|
||||
@@ -5018,59 +5002,64 @@
|
||||
if (!items.length) { const li = closestIn(selNode(), "li"); if (li) items.push(li); }
|
||||
return items;
|
||||
}
|
||||
// 체크박스가 하나도 없는 체크리스트는 평범한 목록으로, 줄마다 체크박스가 있는 ul 은 체크리스트로
|
||||
// 예전 방식(줄 맨 앞 <input type=checkbox>)으로 저장된 체크리스트를 새 방식으로 바꾸고,
|
||||
// 체크리스트 밖으로 나간 줄의 data-checked 는 지운다(빈 목록의 class 도).
|
||||
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");
|
||||
box.querySelectorAll("ul.pj-checklist > li").forEach(function (li) {
|
||||
const first = li.firstElementChild;
|
||||
if (first && first.tagName === "INPUT" && first.type === "checkbox" &&
|
||||
!(li.firstChild.nodeType === 3 && li.firstChild.nodeValue.replace(/[\s\u00a0\u200b]/g, ""))) {
|
||||
if (first.hasAttribute("checked")) li.setAttribute("data-checked", "true");
|
||||
first.remove();
|
||||
const t = li.firstChild;
|
||||
if (t && t.nodeType === 3) t.nodeValue = t.nodeValue.replace(/^[\s\u00a0]+/, "");
|
||||
}
|
||||
});
|
||||
box.querySelectorAll("[data-checked]").forEach(function (x) {
|
||||
if (!(x.tagName === "LI" && x.parentElement && x.parentElement.classList.contains("pj-checklist"))) {
|
||||
x.removeAttribute("data-checked");
|
||||
}
|
||||
});
|
||||
box.querySelectorAll("ul.pj-checklist").forEach(function (ul) {
|
||||
if (!ul.querySelector(":scope > li")) { ul.classList.remove("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(); });
|
||||
// 끄기 — 고른 줄을 목록에서 뺀다(글머리 버튼을 다시 누른 것과 같음)
|
||||
selectedItems(cur).forEach(function (li) { li.removeAttribute("data-checked"); });
|
||||
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));
|
||||
}
|
||||
if (ul) ul.classList.add("pj-checklist");
|
||||
}
|
||||
normalizeChecklists();
|
||||
}
|
||||
// 체크리스트 줄에서 Enter — 새 줄에도 체크박스(체크 안 된 채). 빈 줄에서 Enter 는 목록 끝.
|
||||
// 체크리스트 줄에서 Enter — 브라우저가 새 줄(li)을 만들 때 윗줄의 체크 표시까지
|
||||
// 복사하므로, 새 줄은 체크 안 된 채로 시작하게 지운다.
|
||||
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 }));
|
||||
if (nli && nli !== li) nli.removeAttribute("data-checked");
|
||||
normalizeChecklists();
|
||||
}, 0);
|
||||
});
|
||||
// 체크박스(글머리 자리) 누르기 — 줄의 글자보다 왼쪽을 누르면 체크/해제.
|
||||
box.addEventListener("mousedown", function (e) {
|
||||
const li = e.target && e.target.closest ? e.target.closest("ul.pj-checklist > li") : null;
|
||||
if (!li || !box.contains(li)) return;
|
||||
if (e.clientX >= li.getBoundingClientRect().left) return;
|
||||
e.preventDefault(); // 글자 커서가 옮겨가지 않게
|
||||
if (li.getAttribute("data-checked") === "true") li.removeAttribute("data-checked");
|
||||
else li.setAttribute("data-checked", "true");
|
||||
box.dispatchEvent(new Event("input", { bubbles: true }));
|
||||
});
|
||||
|
||||
const fmtbar = el("pj-desc-fmtbar");
|
||||
if (fmtbar) {
|
||||
@@ -5092,11 +5081,11 @@
|
||||
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(); });
|
||||
Array.prototype.forEach.call(cl.children, function (li) { if (li.tagName === "LI") li.removeAttribute("data-checked"); });
|
||||
cl.classList.remove("pj-checklist");
|
||||
if (!cl.className) cl.removeAttribute("class");
|
||||
if (cmd === "insertUnorderedList") { box.dispatchEvent(new Event("input", { bubbles: true })); updateFmtState(); return; }
|
||||
@@ -5359,10 +5348,10 @@
|
||||
return {
|
||||
setTaskId: setTaskId,
|
||||
setHtml: function (html) {
|
||||
// (체크박스는 checked 속성이 그대로 화면 상태가 된다 — 새 HTML 이라 따로 맞출 필요 없음)
|
||||
selectImg(null); lastRange = null;
|
||||
box.innerHTML = html || "";
|
||||
normalizeEditorLinks(box);
|
||||
normalizeChecklists(); // 예전 방식(<input type=checkbox>) 체크리스트 → 글머리식
|
||||
},
|
||||
getHtml: function () { return box.innerHTML; },
|
||||
isUploading: function () { return pendingUploads > 0; },
|
||||
|
||||
Reference in New Issue
Block a user