feat(project): auto-fit goal column widths

This commit is contained in:
2026-10-03 06:55:00 +09:00
parent e726f986db
commit b32f2ac3a3
12 changed files with 307 additions and 17 deletions
+52 -8
View File
@@ -8599,10 +8599,10 @@
const year = table.dataset.year;
const isAdmin = table.dataset.admin === "true";
// ── 열 너비 — 머리 칸 오른쪽 끝을 끌어 조절, 브라우저에 기억(localStorage pj_goal_col_w) ──
// ── 열 너비 — 셀 오른쪽 경계에서 끌기·더블클릭 맞춤, 브라우저에 기억(localStorage pj_goal_col_w) ──
// · c1·c2 = 왼쪽 이름 두 칸(구분·항목) → 표의 CSS 변수 --goal-c1-w·--goal-c2-w(c2 의 left 도 c1 너비로 정해진다)
// · y = 연간, m1~m12 = 월, q1~q4 = 분기 → 그 머리 칸의 --cw(표는 table-layout: fixed 라 머리 칸 너비가 열 너비)
// 화면 배율(uiZoom) 안이라 마우스 이동 거리는 배율로 나눈다. 더블클릭 = 기본 너비.
// 화면 배율(uiZoom) 안이라 마우스 이동 거리는 배율로 나눈다. 더블클릭 = 가장 긴 문단에 맞춤.
const COL_KEY = "pj_goal_col_w";
const colDefault = { c1: 72, c2: 72, y: 90, q1: 80, q2: 80, q3: 80, q4: 80 };
for (let m = 1; m <= 12; m++) colDefault["m" + m] = 85;
@@ -8613,7 +8613,8 @@
const saved = JSON.parse(localStorage.getItem(COL_KEY) || "null");
if (saved) Object.keys(colDefault).forEach(function (k) {
const v = parseInt(saved[k], 10);
if (v) colW[k] = clampCol(k, v);
// 자동 맞춤은 긴 문단을 자르지 않도록 드래그 최대 너비를 넘을 수 있다.
if (v > 0) colW[k] = Math.max(colLimit(k)[0], v);
});
} catch (_) {}
function saveColW() {
@@ -8653,15 +8654,59 @@
occupied[rr] = occupied[rr] || [];
for (let cc = c; cc <= end; cc++) occupied[rr][cc] = true;
}
td.dataset.goalCols = keys.slice(c, end + 1).join(",");
if (!td.querySelector(".pj-goal-colresize") && keys[end]) {
const h = document.createElement("span"); h.className = "pj-goal-colresize";
h.dataset.col = keys[end]; h.title = "끌어서 너비 조절"; td.appendChild(h);
h.dataset.col = keys[end]; td.appendChild(h);
}
const handle = td.querySelector(".pj-goal-colresize");
if (handle) handle.title = "끌어서 너비 조절 · 더블클릭하면 내용에 맞춤";
c = end + 1;
});
});
}
addColHandles();
function naturalCellWidth(td) {
// 원본은 건드리지 않는다. 같은 셀 안의 숨은 복사본으로 폰트·부분 서식·여백을
// 그대로 재되, 화면 폭에 따른 줄바꿈만 해제한다(직접 넣은 줄바꿈은 유지).
const probe = document.createElement("div"), copy = td.cloneNode(true);
probe.style.cssText = "position:fixed;left:0;top:0;visibility:hidden;pointer-events:none;width:max-content;";
probe.setAttribute("aria-hidden", "true");
copy.classList.add("pj-goal-autofit-measure");
copy.querySelectorAll(".pj-goal-colresize, .pj-goal-menu-btn").forEach(function (n) { n.remove(); });
// input의 현재 초안은 HTML 속성과 다를 수 있고, 기본 입력칸의 내재 너비도 제외한다.
copy.querySelectorAll("input, textarea").forEach(function (n) {
const text = document.createElement("span");
text.className = n.className; text.style.cssText = n.style.cssText;
text.textContent = n.value; n.replaceWith(text);
});
[copy].concat(Array.from(copy.querySelectorAll("*"))).forEach(function (n) {
n.removeAttribute("id"); n.removeAttribute("contenteditable"); n.removeAttribute("data-placeholder");
n.classList.remove("is-shrunk", "is-gone");
const overrides = { position: "static", width: "max-content", "min-width": "0", "max-width": "none",
height: "auto", overflow: "visible", transition: "none", "overflow-wrap": "normal", "word-break": "normal" };
Object.keys(overrides).forEach(function (p) { n.style.setProperty(p, overrides[p], "important"); });
if (n.matches(".pj-goal-text, .pj-goal-text-ro, .pj-goal-area-text, .pj-goal-row-text")) {
n.style.setProperty("white-space", "pre", "important");
}
});
copy.style.setProperty("display", "block", "important");
probe.appendChild(copy); td.appendChild(probe);
try { return Math.ceil(copy.getBoundingClientRect().width / uiZoom()) + 2; }
finally { probe.remove(); }
}
function autoFitCol(key) {
let width = colLimit(key)[0];
table.querySelectorAll("[data-goal-cols]").forEach(function (td) {
const keys = td.dataset.goalCols.split(",");
if (!keys.includes(key)) return;
// 병합 칸의 다른 열은 유지하고 선택한 열에 필요한 나머지 너비만 더한다.
const otherWidth = keys.reduce(function (sum, k) { return sum + (k === key ? 0 : colW[k]); }, 0);
width = Math.max(width, naturalCellWidth(td) - otherWidth);
});
colW[key] = width;
applyColW(); saveColW(); fitAll(); stickKpi();
}
table.addEventListener("mousedown", function (e) {
const h = e.target.closest(".pj-goal-colresize");
if (!h) return;
@@ -8692,11 +8737,10 @@
table.addEventListener("dblclick", function (e) {
const h = e.target.closest(".pj-goal-colresize");
if (!h) return;
e.preventDefault();
e.stopPropagation();
colW[h.dataset.col] = colDefault[h.dataset.col];
applyColW();
saveColW();
fitAll();
lastColResize = Date.now();
autoFitCol(h.dataset.col);
});
// ── 틀 고정 — 머리 줄 아래 숫자 지표(매출·로아스) 줄까지 세로 스크롤에도 위에 붙어 있다.