- 공용 명세 폼: 필수 상자 고르기 칸 빈 보기 없음 · 빈 옛 값 = 정의 기본값(없으면 첫 보기)을 실제 값으로(저장도 그 값) · 선택 상자 빈 보기 = 빈 글 · 숫자 칸 자리표시 글 걷음 - 시설 폼: 배관 · BOX · 세월교 · 물넘이 포장에 정의 기본값 전달 · 독립 기슭막이 설치 측 · 형태 빈 보기 없음 · 높이 · 추가 흙막이(단) · 월류 높이 자리표시 글 걷음 - 일반 구조물 칸: 필수 · 기본값 있는 고르기 칸 빈 보기 없음 · 그 밖 빈 보기 = 빈 글 · 「필수 입력」 자리표시 걷음 · 규칙 선택지 좁힘이 빈 보기 없는 칸도 다룸 - 기준 측점 이름표 「(비우면 시작)」 걷음 - 시험: 기슭막이 높이 칸 = 자리표시 없음 · 화면 점검 ui_checks/54-43 화면 확인(sub5_검증 · B05 구조물 20개): 「선택 안 함」 · 「안 정함」 · 「비우면」 · 「기본」 0 · 필수 칸 빈 보기 0 · 필수 칸 빈 값 0 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BVPp2o6Mh2FZJr72yW3ofZ
90 lines
3.8 KiB
TypeScript
90 lines
3.8 KiB
TypeScript
/* =============================================================================
|
|
* B05_Profile_UI_Structures_Spec.ts
|
|
* 일반 구조물(structures.json) 명세 컨테이너 폼(PLAN 52-10) — 계곡 통과 시설 밖 종류가 명세
|
|
* (`STRUCTURE_SPECS`)를 가지면 옵션 칸 아래에 같은 공용 폼(`design_structure_form`)을 그림.
|
|
*
|
|
* · 폼은 옵션 칸(`optionRow`) 짝으로 하나 — 조립기가 세워 걸고, 옵션 그리기 · 저장이 꺼내 씀
|
|
* · 명세 키 · 명세가 뺀 옛 키(retired)는 정의 옵션 칸으로 그리지 않음(옛 값은 병합이 지킴)
|
|
* · 잠금은 옵션 칸을 따름(측점 확정 전 흐림 · 조작 막음)
|
|
* ========================================================================== */
|
|
|
|
import type { StructureType } from "./B05_Profile_Api_Structures";
|
|
import {
|
|
createSpecForm,
|
|
type SpecForm,
|
|
type SpecLinks,
|
|
} from "../A00_Common/design/design_structure_form";
|
|
import { STRUCTURE_SPECS } from "../A00_Common/design/design_structure_pipe";
|
|
import { specKeys, type StructureSpec } from "../A00_Common/design/design_structure_spec";
|
|
import { optionDefaults } from "./B05_Profile_UI_Structures_Fields";
|
|
|
|
const forms = new WeakMap<HTMLElement, SpecForm>();
|
|
|
|
/** 일반 구조물 명세 — 계곡 통과 시설(관 지점 정본)은 시설 폼 몫이라 뺌. */
|
|
export const structureSpecOf = (type: StructureType | null): StructureSpec | null =>
|
|
(type && !type.managed_by && STRUCTURE_SPECS[type.type_id]) || null;
|
|
|
|
/** 옵션 칸 짝 폼을 세움 — 값이 바뀌면 `onChange`(패널 즉시 반영). */
|
|
export function createStructureSpecForm(
|
|
optionRow: HTMLElement,
|
|
links: SpecLinks,
|
|
onChange: () => void,
|
|
): SpecForm {
|
|
const form = createSpecForm(links, { onChange });
|
|
form.root.hidden = true;
|
|
forms.set(optionRow, form);
|
|
const lock = (): void => {
|
|
const locked = optionRow.classList.contains("is-locked");
|
|
form.root.inert = locked;
|
|
form.root.classList.toggle("is-locked", locked);
|
|
};
|
|
if (typeof MutationObserver !== "undefined")
|
|
new MutationObserver(lock).observe(optionRow, {
|
|
attributes: true,
|
|
attributeFilter: ["class"],
|
|
});
|
|
return form;
|
|
}
|
|
|
|
/** 정의 옵션 칸으로 안 그리는 키 — 명세 키 · 명세가 뺀 옛 키. */
|
|
export function specOwnedKeys(type: StructureType | null): Set<string> {
|
|
const spec = structureSpecOf(type);
|
|
return new Set(spec ? [...specKeys(spec).keys, ...spec.retired] : []);
|
|
}
|
|
|
|
/** 종류 · 값으로 명세 폼을 다시 그림(명세 없는 종류면 가림). */
|
|
export function paintStructureSpec(
|
|
optionRow: HTMLElement,
|
|
type: StructureType | null,
|
|
values: Record<string, string | number>,
|
|
): void {
|
|
const form = forms.get(optionRow);
|
|
const spec = structureSpecOf(type);
|
|
if (!form) return;
|
|
form.root.hidden = !spec;
|
|
if (!spec) return;
|
|
const groups = Object.fromEntries((type?.groups ?? []).map((g) => [g.id, g.name]));
|
|
form.write(spec, values, type?.spec_names ?? {}, groups, optionDefaults(type?.options ?? []));
|
|
}
|
|
|
|
/** 명세 폼 값(저장 키 그대로) — 명세 없는 종류면 빈 묶음. */
|
|
export function readStructureSpec(
|
|
optionRow: HTMLElement,
|
|
type: StructureType | null,
|
|
): Record<string, string | number> {
|
|
const form = forms.get(optionRow);
|
|
return form && structureSpecOf(type) ? form.read() : {};
|
|
}
|
|
|
|
/** [수정] 병합에서 폼이 다시 쓰는 키 — 명세 키 + 옛 값 중 선택 컨테이너 머리 키(빼면 지워져야 함). */
|
|
export function specRenderedKeys(
|
|
type: StructureType | null,
|
|
previous: Record<string, string | number> | undefined,
|
|
): string[] {
|
|
const spec = structureSpecOf(type);
|
|
if (!spec) return [];
|
|
const { keys, prefixes } = specKeys(spec);
|
|
const own = Object.keys(previous ?? {}).filter((key) => prefixes.some((p) => key.startsWith(p)));
|
|
return [...keys, ...own];
|
|
}
|