/* 116-1 우클릭 → [추가]까지 헬퍼 — `_Structures_Panel_AddAt` 판정 · 끝맺음과 `_Commit.loadForm(null)` * (새로 놓기가 부르는 비움)을 Node 로 돌려 표준출력 JSON 한 벌로. TS 로더는 `helper_54_12_live_required.cjs` 와 같다. */ const fs = require("fs"); const path = require("path"); const ts = require(path.join(__dirname, "..", "..", "config", "node_modules", "typescript")); const CATALOG = require("./helper_322_catalog_module.cjs"); // 구조물 표(322-1) const ROOT = path.join(__dirname, "..", ".."); const cache = new Map(); const session = new Map(); const fakeStorage = { getItem: (k) => session.get(k) ?? null, setItem: (k, v) => session.set(k, String(v)), removeItem: (k) => session.delete(k), }; globalThis.window = { sessionStorage: fakeStorage, localStorage: fakeStorage }; globalThis.sessionStorage = fakeStorage; globalThis.localStorage = fakeStorage; const STUBS = { "@config/config_frontend": { API_BASE_URL: "/api", API_TIMEOUT_MS: 1000 }, "./ui_template_checkbox.css": {}, }; function loadTs(file) { const full = path.resolve(file); if (cache.has(full)) return cache.get(full); const js = ts.transpileModule(fs.readFileSync(full, "utf8"), { compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2020 }, }).outputText; const box = { exports: {} }; cache.set(full, box.exports); const localRequire = (request) => { if (CATALOG.isCatalogRequest(request)) return CATALOG; if (STUBS[request]) return STUBS[request]; if (request.startsWith(".")) return loadTs(path.join(path.dirname(full), `${request}.ts`)); if (request.startsWith("@")) return new Proxy({}, { get: () => () => {} }); return require(request); }; new Function("exports", "module", "require", js)(box.exports, box, localRequire); cache.set(full, box.exports); return box.exports; } const B05 = path.join(ROOT, "B05_Profile"); const { addsAtOnce, finishAdd } = loadTs( path.join(B05, "B05_Profile_UI_Structures_Panel_AddAt.ts"), ); const { loadForm } = loadTs(path.join(B05, "B05_Profile_UI_Structures_Panel_Commit.ts")); const entry = (required, value) => ({ required, isEmpty: () => value === "" }); // 동작 = 정의 종류 덧칸(앱의 `withDefinition` 과 같음 · 323-7 종류 키 대신 동작 이름) const DEFINED = JSON.parse( fs.readFileSync(path.join(ROOT, "resources", "master_template", "구조물정의.json"), "utf8"), ); const behaviors = (typeId) => DEFINED.종류?.[typeId]?.동작 ?? []; const type = (type_id, managed_by = null) => ({ type_id, group: "C", managed_by, behaviors: behaviors(type_id), }); /** 목록 알림 → 페이지가 임시 id 를 붙여 패널 배열 안을 갈아 채우는 것(`withLocalIds` · `setStructures`). */ function fakeCommit(structures, adds) { let n = 0; return async () => { if (!adds) return; // [추가]가 거절 — 아무것도 안 듦 structures.push({ structure_id: null, type_id: "retaining_wall", chainage_m: 120 }); structures.splice( 0, structures.length, ...structures.map((s) => (s.structure_id ? s : { ...s, structure_id: `local${++n}` })), ); }; } async function finish(t, adds) { const structures = [{ structure_id: "old1", type_id: "berm", chainage_m: 40 }]; const picked = []; let commits = 0; const commit = fakeCommit(structures, adds); const done = await finishAdd({ type: t, anchorM: 120, structures, commit: async () => (commits++, commit()), pick: { selectById: (id) => picked.push(["id", id]), selectPipeByChainage: (at) => picked.push(["pipe", at]), }, }); return { done, picked, commits, count: structures.length }; } /** 새로 놓기(startNew → resetForm → loadForm(null))가 옛 집계 항목 · 그룹 잇기를 비우는지. */ function clearedByNew() { let summary = { code: "OLD", name: "옛 집계" }; let groups = { inlet: { code: "OLD2" } }; const station = () => ({ write() {}, clearInvalid() {} }); const ctx = { cancelTempPipe() {}, setEditingId() {}, setSelectedPipeChainage() {}, setPositionConfirmed() {}, interval: () => 20, anchorFields: station(), startFields: station(), endFields: station(), memoField: { value: "옛 메모" }, renderOptionFields() {}, setSummary: (v) => (summary = v), groupBoxes: { set: (v) => (groups = v), setShapes() {} }, syncFacilityForm() {}, syncPlacementFields() {}, syncButtons() {}, renderList() {}, callbacks: { onSelect() {} }, }; loadForm(ctx, null); return { summary, groups, memo: ctx.memoField.value }; } (async () => { const out = { once: { noRequired: addsAtOnce(type("retaining_wall"), [entry(false, ""), entry(true, "L")]), requiredEmpty: addsAtOnce(type("masonry_wet"), [entry(true, ""), entry(false, "1")]), pavement: addsAtOnce(type("pavement_concrete"), []), fordBridge: addsAtOnce(type("ford_bridge", "pipe_points"), []), fordPavement: addsAtOnce(type("ford_pavement", "pipe_points"), []), pipe: addsAtOnce(type("pipe", "pipe_points"), []), box: addsAtOnce(type("box_culvert", "pipe_points"), []), }, structure: await finish(type("retaining_wall"), true), refused: await finish(type("retaining_wall"), false), pipe: await finish(type("pipe", "pipe_points"), true), cleared: clearedByNew(), }; process.stdout.write(JSON.stringify(out)); })();