Files
Aislo/resources/tester/helper_469_3_list_draft.cjs
T
eomsangdonandClaude Sonnet 5.5 481f79f5ee fix(B05·B06): 관 · 구조물을 전부 지우고 떠나도 묻는 창이 뜨게 함 (PLAN 469-3 · 요구 432)
- 빈 목록 초안 "[]" 판정을 draftFilled 한 함수로 — 떠남 확인(design_leave)과 hasDrafts 가 같은 규칙
- 저장분이 있는 목록 칸의 "[]" = 고침 · 저장분도 빈 곳 · 저장분을 모를 때 = 전처럼 빈 칸
- 저장분 있음은 페이지 자료 줄(design_page_data)이 받을 때 적음 — 새 서버 요청 없음
- 지킴 시험 test_469_3 · 자료 줄 흉내 헬퍼 둘에 새 import 흉내

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-28 22:51:17 +09:00

70 lines
2.5 KiB
JavaScript

/* 469-3 빈 목록 초안("[]") 떠남 판정 헬퍼 — `design_leave` · `b_page_state` 를 한 번씩만 읽어(같은 모듈 한 벌)
* 저장분 있음/없음에 따라 designDirty · hasDrafts 가 같게 나오는지. 결과 JSON 을 stdout 으로.
*/
const path = require("path");
const { makeLoader } = require("./helper_ts_stub_loader.cjs");
const ROOT = path.join(__dirname, "..", "..");
const map = new Map();
const session = {
getItem: (key) => (map.has(key) ? map.get(key) : null),
setItem: (key, value) => map.set(key, String(value)),
removeItem: (key) => map.delete(key),
key: (index) => [...map.keys()][index] ?? null,
get length() {
return map.size;
},
};
globalThis.window = { sessionStorage: session, localStorage: session };
globalThis.sessionStorage = session;
const STUBS = {
"@config/config_frontend": {
ROUTES: { B05_PROFILE: "/b05-profile", B06_SECTION: "/b06-section" },
},
"@ui/ui_template_locale": { t: (key) => key },
"../b_project_switch": { guardProjectLeave: () => undefined },
};
const { loadTs } = makeLoader({
root: ROOT,
requireFor: (full, file) => (request) => {
if (request in STUBS) return STUBS[request];
if (request.startsWith(".")) return loadTs(path.join(path.dirname(file), `${request}.ts`));
return require(request);
},
});
const state = loadTs(path.join(ROOT, "A00_Common", "b_page_state.ts"));
const leave = loadTs(path.join(ROOT, "A00_Common", "design", "design_leave.ts"));
const P = "p1";
const set = (name, raw) => session.setItem(`aislo:draft:${name}:${P}`, raw);
const unset = (name) => session.removeItem(`aislo:draft:${name}:${P}`);
const both = () => [leave.designDirty(P), state.hasDrafts(P)];
const out = {};
set("pipes", "[]");
out.unknownSaved = both(); // 저장분을 모름 = 빈 칸(전과 같음)
state.noteSavedList(P, "pipes", false);
out.savedEmpty = both(); // 처음부터 관 0
state.noteSavedList(P, "pipes", true);
out.savedFilled = both(); // 관 있던 곳에서 모두 지움
unset("pipes");
set("structures", "[]");
out.structuresSavedEmpty = both();
state.noteSavedList(P, "structures", true);
out.structuresSavedFilled = both();
leave.discardDesignEdits(P);
out.afterDiscard = [both(), session.getItem(`aislo:draft:structures:${P}`)];
set("pipes", "[]");
state.forgetSavedLists(P);
out.afterForget = both();
for (const raw of ["{}", ""]) {
set("pipes", raw);
state.noteSavedList(P, "pipes", true);
out[`raw_${raw || "empty"}`] = both();
}
state.noteSavedList(P, "pipes", true);
set("pipes", '[{"id":1}]');
out.withItems = both();
process.stdout.write(JSON.stringify(out));