- 한눈 표(M02_SO_Def_Table): 군 · 종류 ▲▼ · 이름 · 목록 · 자리꼴 · 정본(고정) · 횡단도 · 카드 이름 · 형상(+ 벽 기본 형태 · 물빼기) · 알약 색 · 3D · 검사 · 처음 값 = 흐림 「기본」 · 바꿈 = 진함 · [처음 값으로] - 종류별: 반영 칸 + 명세 이름 나무 줄마다 보임(컨테이너 = 그 안 칸) · 못 숨김 · 미리보기 숨김 따름 · 「안 씀」 = 목록 B06 만 - 부품 탭(M02_SO_Def_Parts): 부품 · 읽는 칸 · 자리꼴 · 정본 · 쓰는 종류 · 켬/끔(정의 부품 = 끈 것만) - 편집 손질(M02_SO_Def_Reflect): 처음 값이면 반영에서 지움 · [저장] 때 enabled = 목록 both 일 때만 참 - 검사 짝 M02_SO_Def_Check.ts ↔ M02_SO_Check.py(글까지 같음): 반영 · 부품 꼴 · 형상 none → 횡단도 none · 부품 자리꼴 · 정본 · 기본값 없는 읽는 칸 새로 숨김 금지(앞 판 숨김 그대로) · 종류 지우기 · 자리꼴 · 정본 · 군 글자 · 선택지 값 고정 · 서버 check(doc, 지금 판) · 앞 판 없으면 꼴만 - 명세 폼: 쓰는 옵션 키가 모두 숨긴 칸 · 상자는 안 그림(값 그대로) · B05 · B06 시설 · 구조물 명세 폼이 정의 「표시」를 따름 - 판 알림: GET 구조물 목록에 definition_version · structures.json 판 ≠ 지금 판이면 「구조물 정의가 판 N 으로 바뀜 — 저장하면 반영」 한 번 - 시험: test_322_2_check_mirror(거울 · 규칙 · 반영 손질 · 서버 저장 · 422) · 판 알림 · 옛 정의 화면 시험 = 선택지 값 대신 이름 표 · 못 숨김 아닌 칸 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Ji4nuyLVHcxrXWHTdb5nRD
122 lines
4.8 KiB
TypeScript
122 lines
4.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 SpecFormHooks,
|
|
type SpecLinks,
|
|
} from "../A00_Common/design/design_structure_form";
|
|
import { STRUCTURE_SPECS } from "../A00_Common/design/design_structure_pipe";
|
|
import { ADDON_SPECS } from "../A00_Common/design/design_structure_slope_tier";
|
|
import { specKeys, type StructureSpec } from "../A00_Common/design/design_structure_spec";
|
|
import { hiddenOptionKeys, optionDefaults } from "./B05_Profile_UI_Structures_Fields";
|
|
import type { WideningBox } from "./B05_Profile_UI_Structures_Widening";
|
|
|
|
const forms = new WeakMap<HTMLElement, SpecForm>();
|
|
/** 범위형 명세(노면공 · 87-3)의 「확폭 구간」 상자 — 옵션 칸 짝. */
|
|
const widenings = new WeakMap<HTMLElement, WideningBox>();
|
|
|
|
/** 일반 구조물 명세 — 계곡 통과 시설(관 지점 정본)은 시설 폼 몫이라 뺌 · 정의 그룹 종류 덧붙임(178-3 추가 단)도. */
|
|
export const structureSpecOf = (type: StructureType | null): StructureSpec | null =>
|
|
(type && !type.managed_by && (STRUCTURE_SPECS[type.type_id] ?? ADDON_SPECS[type.type_id])) ||
|
|
null;
|
|
|
|
/** 옵션 칸 짝 폼을 세움 — 값이 바뀌면 `onChange`(패널 즉시 반영). */
|
|
export function createStructureSpecForm(
|
|
optionRow: HTMLElement,
|
|
links: SpecLinks,
|
|
onChange: () => void,
|
|
auto?: SpecFormHooks["auto"],
|
|
widening?: WideningBox,
|
|
): SpecForm {
|
|
const form = createSpecForm(links, { onChange, auto });
|
|
form.root.hidden = true;
|
|
forms.set(optionRow, form);
|
|
if (widening) widenings.set(optionRow, widening);
|
|
const lock = (): void => {
|
|
const locked = optionRow.classList.contains("is-locked");
|
|
for (const root of [form.root, widening?.root]) {
|
|
if (!root) continue;
|
|
root.inert = locked;
|
|
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,
|
|
...(spec.dropped ?? []),
|
|
...(spec.byRange ? ["widening_off"] : []),
|
|
]
|
|
: [],
|
|
);
|
|
}
|
|
|
|
/** 종류 · 값으로 명세 폼을 다시 그림(명세 없는 종류면 가림). */
|
|
export function paintStructureSpec(
|
|
optionRow: HTMLElement,
|
|
type: StructureType | null,
|
|
values: Record<string, string | number>,
|
|
): void {
|
|
const form = forms.get(optionRow);
|
|
const spec = structureSpecOf(type);
|
|
widenings.get(optionRow)?.paint(!!spec?.byRange, values.widening_off);
|
|
if (!form) return;
|
|
form.root.hidden = !spec;
|
|
if (!spec) return;
|
|
const groups = Object.fromEntries((type?.groups ?? []).map((g) => [g.id, g.name]));
|
|
const options = type?.options ?? [];
|
|
form.write(
|
|
spec,
|
|
values,
|
|
type?.spec_names ?? {},
|
|
groups,
|
|
optionDefaults(options),
|
|
hiddenOptionKeys(options),
|
|
);
|
|
}
|
|
|
|
/** 명세 폼 값(저장 키 그대로) — 명세 없는 종류면 빈 묶음. */
|
|
export function readStructureSpec(
|
|
optionRow: HTMLElement,
|
|
type: StructureType | null,
|
|
): Record<string, string | number> {
|
|
const form = forms.get(optionRow);
|
|
const spec = structureSpecOf(type);
|
|
if (!form || !spec) return {};
|
|
return { ...form.read(), ...(spec.byRange ? widenings.get(optionRow)?.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, ...(spec.dropped ?? []), ...(spec.byRange ? ["widening_off"] : [])];
|
|
}
|