- 시설 폼 칸에 옵션 키 표식(data-option-keys) · 끈 키의 칸은 가림 · 칸이 다 가려진 줄은 줄째 - 키가 여럿인 칸(본체 규격 · 유입구 구조)은 키가 다 꺼졌을 때만 가림 · 독립 기슭막이는 유입 · 유출 채널 키로 넓힘 - 숨긴 칸은 칸 값(제안값 채우기 포함)이 아니라 폼이 받은 옛 값을 저장에 그대로 실음 · 이 폼에는 필수 검사가 없음 - 가리기 코드는 새 파일(_Facility_Hidden)로 분리해 Facility.ts 700줄 아래 유지 - 시험 3개 추가 Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TULoa94ZFL26KU6ZqVpjkF
60 lines
2.7 KiB
TypeScript
60 lines
2.7 KiB
TypeScript
/* =============================================================================
|
|
* B05_Profile_UI_Drainage_Facility_Hidden.ts
|
|
* 계곡 통과 시설 폼의 **끈 옵션 가리기** — M02 「구조물 옵션 보이기」에서 끈 옵션
|
|
* (`GET /api/projects/structure-types` 의 `visible: false`)의 칸을 시설 폼에서도 안 그린다
|
|
* (PLAN 21-10 흠 8).
|
|
*
|
|
* · 칸은 `labeled(..., 옵션키)` 가 붙인 `data-option-keys` 표식으로 찾는다 — 키가 여럿인 칸(본체 규격 ·
|
|
* 유입구 구조)은 **키가 다 꺼졌을 때** 가린다(하나만 꺼지면 남은 키를 적는 칸이라 둠).
|
|
* · 숨긴 칸의 값은 칸이 아니라 **폼이 받은 옛 값**(`remember`)을 저장에 그대로 싣는다 —
|
|
* 칸에 제안값을 채워도 숨긴 값이 몰래 바뀌지 않는다.
|
|
* · 필수 검사는 이 폼에 없다(레지스트리 옵션 칸은 `renderOptionFields` 가 숨긴 칸을 뺌).
|
|
* ========================================================================== */
|
|
|
|
import { hiddenFormKeys } from "./B05_Profile_UI_Drainage_Facility_Merge";
|
|
|
|
export interface HiddenOptions {
|
|
/** 폼이 받은 옵션 — 숨긴 칸의 옛 값 보존용. `setFacility` 가 부른다. */
|
|
remember: (options: Record<string, string | number>) => void;
|
|
/** 끈 레지스트리 키를 받아 칸을 가린다. */
|
|
set: (facility: string | null, registryKeys: Iterable<string>) => void;
|
|
/** 읽은 옵션에서 숨긴 칸을 칸 값이 아닌 옛 값으로 바꾼다. */
|
|
restore: (options: Record<string, string | number>) => void;
|
|
}
|
|
|
|
export function createHiddenOptions(root: HTMLElement): HiddenOptions {
|
|
let hidden: ReadonlySet<string> = new Set();
|
|
let stored: Record<string, string | number> = {};
|
|
const apply = (): void => {
|
|
root.querySelectorAll<HTMLElement>("[data-option-keys]").forEach((node) => {
|
|
const keys = (node.dataset.optionKeys ?? "").split(" ");
|
|
node.classList.toggle(
|
|
"is-option-hidden",
|
|
keys.every((key) => hidden.has(key)),
|
|
);
|
|
});
|
|
// 칸이 다 가려진 줄은 줄째(빈 줄 간격이 안 남게)
|
|
root.querySelectorAll<HTMLElement>(".b05-structure__grid").forEach((row) => {
|
|
const kids = [...row.children];
|
|
const all =
|
|
kids.length > 0 && kids.every((kid) => kid.classList.contains("is-option-hidden"));
|
|
row.classList.toggle("is-option-hidden", all);
|
|
});
|
|
};
|
|
return {
|
|
remember(options) {
|
|
stored = { ...options };
|
|
},
|
|
set(facility, registryKeys) {
|
|
hidden = hiddenFormKeys(facility, registryKeys);
|
|
apply();
|
|
},
|
|
restore(options) {
|
|
for (const key of hidden) {
|
|
delete options[key];
|
|
if (stored[key] !== undefined) options[key] = stored[key];
|
|
}
|
|
},
|
|
};
|
|
}
|