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
+86 -1
View File
@@ -115,6 +115,36 @@ function unload(env) {
return e;
}
// jsdom에는 글꼴·레이아웃 엔진이 없다. 숨은 복사본의 실제 DOM/서식을 확인하면서
// 결정적인 글 너비를 제공한다. 실제 CSS·폰트 측정은 별도 브라우저 검증으로 확인한다.
function mockAutoFitLayout(env) {
const realRect = env.w.HTMLElement.prototype.getBoundingClientRect;
const measured = [];
env.w.HTMLElement.prototype.getBoundingClientRect = function () {
if (!this.classList.contains("pj-goal-autofit-measure")) return realRect.call(this);
measured.push(this);
const content = this.querySelector(".pj-goal-text, .pj-goal-text-ro, .pj-goal-num, .pj-goal-area-text, .pj-goal-row-text") || this;
let line = 0, longest = 0;
function walk(node, size, bold) {
if (node.nodeType === 3) {
node.nodeValue.split("\n").forEach(function (text, i) {
if (i) { longest = Math.max(longest, line); line = 0; }
line += text.length * size * (bold ? 1.2 : 1);
});
} else if (node.nodeType === 1) {
if (node.tagName === "BR") { longest = Math.max(longest, line); line = 0; return; }
const nextSize = parseFloat(node.style.fontSize) || size;
const nextBold = node.style.fontWeight ? Number(node.style.fontWeight) >= 600 : bold;
Array.from(node.childNodes).forEach(function (child) { walk(child, nextSize, nextBold); });
}
}
walk(content, 10, false);
const zoom = env.d.documentElement.classList.contains("pj-ui-scale") ? 0.75 : 1;
return { width: (Math.max(longest, line) + 13) * zoom };
};
return measured;
}
// ── 가짜 서버 — 목표 표(글 칸 상태를 기억해 화면 GET 에 반영) ───────────────
function goalsServer(env, st) {
st = Object.assign({ cells: {}, areaAdded: false, cellHook: null, metricHook: null, getHook: null }, st || {});
@@ -580,8 +610,63 @@ function meetServer(env, st) {
env.d.getElementById("pj-goal-area-add").click(); await settle(); await wait(20); await settle();
const fresh = env.d.querySelector('tbody.pj-goal-area .pj-goal-colresize[data-col="m1"]');
check("[너비] 표 새로 그린 뒤에도 손잡이", !!fresh && fresh !== lower);
mockAutoFitLayout(env);
fresh.dispatchEvent(new env.w.MouseEvent("dblclick", { bubbles: true }));
check("[너비] 새 행의 더블클릭 기본값 복원", table.querySelector('thead th[data-col="m1"]').style.getPropertyValue("--cw") === "85px");
check("[너비] 표를 다시 그린 뒤에도 더블클릭 내용 맞춤", table.querySelector('thead th[data-col="m1"]').style.getPropertyValue("--cw") === "95px");
});
await section(async function () {
const env = makeEnv(PAGE.goals_admin, GOALS_URL);
goalsServer(env); await boot(env);
const table = env.d.getElementById("pj-goal-table"), measured = mockAutoFitLayout(env);
const first = table.querySelector('.pj-goal-text[data-row="10"][data-month="1"]');
const second = table.querySelector('.pj-goal-text[data-row="11"][data-month="1"]');
first.value = "짧은 문단\n다담: 100 백만(김지통)\n주부콩: 20백만(김지통)";
second.value = "pj-rich:v1:" + JSON.stringify([{ text: "가장 긴 문단", size: 32, bold: true }, { text: " 끝" }]);
const draft = second.value, calls = env.calls.length;
function fit(key, body) {
const handle = table.querySelector((body ? "tbody " : "thead ") + '.pj-goal-colresize[data-col="' + key + '"]');
handle.dispatchEvent(new env.w.MouseEvent("dblclick", { bubbles: true, cancelable: true }));
}
function width(key) { return parseFloat(table.querySelector('thead th[data-col="' + key + '"]').style.getPropertyValue("--cw")); }
fit("m1", true);
const wanted = Math.ceil(7 * 32 * 1.2 + 2 * 10 + 13) + 2;
check("[자동 너비] 모든 행 중 가장 긴 문단·큰 글씨·굵기 반영", width("m1") === wanted, [width("m1"), wanted]);
check("[자동 너비] 원본 초안·부분 서식 보존·저장 요청 없음", second.value === draft && env.calls.length === calls);
check("[자동 너비] 복사본만 줄바꿈 해제·메뉴/손잡이 제외·측정 뒤 제거", measured.every(function (cell) {
const editor = cell.querySelector(".pj-goal-text");
return !cell.querySelector(".pj-goal-colresize, .pj-goal-menu-btn") && (!editor || editor.style.whiteSpace === "pre");
}) && !table.querySelector(".pj-goal-autofit-measure"));
second.value = "짧음";
fit("m1");
const paragraphWidth = Math.max.apply(null, first.textContent.split("\n").map(function (line) { return line.length; })) * 10 + 15;
check("[자동 너비] 명시적 줄바꿈 유지·문단 너비로 축소도 가능", width("m1") === paragraphWidth, [width("m1"), paragraphWidth]);
env.d.documentElement.classList.add("pj-ui-scale"); fit("m1");
check("[자동 너비] 75% 화면 배율에서도 같은 논리 너비", width("m1") === paragraphWidth);
env.d.documentElement.classList.remove("pj-ui-scale");
first.value = "긴".repeat(100); fit("m1");
const saved = env.w.localStorage.getItem("pj_goal_col_w");
check("[자동 너비] 600px를 넘는 문단도 잘리지 않고 기억", width("m1") === 1015 && JSON.parse(saved).m1 === 1015);
const restored = makeEnv(PAGE.goals_ro, GOALS_URL, { storage: { pj_goal_col_w: saved } });
goalsServer(restored); await boot(restored);
check("[자동 너비] 다시 열면 큰 자동 너비도 복원", restored.d.querySelector('thead th[data-col="m1"]').style.getPropertyValue("--cw") === "1015px");
const numeric = table.querySelector('input.pj-goal-num[data-month="2"]');
numeric.value = "12345678901234567890"; fit("m2");
check("[자동 너비] 숫자 입력칸의 현재 초안도 측정", width("m2") === 215);
table.querySelector(".pj-goal-area-text").textContent = "아주 긴 영역 이름"; fit("c1", true);
check("[자동 너비] rowspan 이름 열·메뉴 아이콘 제외", table.style.getPropertyValue("--goal-c1-w") === "115px");
const row = first.closest("tr"), merged = first.closest("td");
merged.colSpan = 2; merged.dataset.goalCols = "m1,m2";
merged.querySelector(".pj-goal-colresize").dataset.col = "m2";
row.querySelector('td[data-month="2"]').remove();
first.value = "병합".repeat(80);
const beforeM1 = width("m1"); fit("m2", true);
check("[자동 너비] 병합 셀은 나머지 열 유지·오른쪽 끝 열만 맞춤", width("m1") === beforeM1 && width("m2") === 1615 - beforeM1, [width("m1"), width("m2")]);
const qth = table.querySelector('thead th[data-col="q1"]'), folded = qth.classList.contains("is-folded");
fit("q1");
check("[자동 너비] 분기 열 더블클릭은 접기 상태를 바꾸지 않음", qth.classList.contains("is-folded") === folded);
mockAutoFitLayout(restored);
restored.d.querySelector('tbody .pj-goal-colresize[data-col="m1"]').dispatchEvent(new restored.w.MouseEvent("dblclick", { bubbles: true }));
check("[자동 너비] 보기 전용도 내용 맞춤 가능·쓰기 요청 없음", restored.d.querySelector('thead th[data-col="m1"]').style.getPropertyValue("--cw") === "95px" && !restored.calls.some(function (c) { return c.method !== "GET"; }));
});
// ════════════════════ [9] 매출 자동 갱신 — 정상 조용히 · 실패/일부 실패 안내 + 재시도 · 권한 없음 ════════════════════