Files
Aislo/M02_MasterTemplete/StructOptions/M02_SO_Def_Table.ts
T
eomsangdonandClaude Opus 5.5 0da2fa0767 fix(구조물표): 322-2 다듬기(브레인 화면 확인) — 화면에 영어 키 안 보임 · 검사 글 한국어(화면 · 서버 짝) · 부품 탭 읽는 칸 = 정의 이름 · 줄바꿈 · 한눈 표 폭 줄임 · 바꿨다 되돌리면 [저장] 꺼짐
- 자리꼴 점 · 구간 · 터 · 정본 관 지점 · 구조물(키는 툴팁) · 고르기 글 = 부품 짧은 이름(괄호 설명 · 키는 툴팁) · 횡단도 없음 = 「안 만듦」 · 「벽 스윕」 → 「벽」 · 종류 키는 툴팁
- 검사 글: 「형상이 「없음」이면 횡단도도 「안 만듦」」 · 부품 짧은 이름 · 칸 이름 · 종류 이름(M02_SO_Def_Check.ts = M02_SO_Check.py)
- 부품 탭: 읽는 칸 = 그 부품을 쓰는 종류의 칸 이름(단위) · 표 줄바꿈(table-layout fixed)
- 한눈 표 형상칸 「기본 형태」 = 그림 형태 고르기(REVET_FORMS)
- [저장] 켬 = 저장할 꼴(tidy · 목록 짝 enabled)끼리 지금 판과 다를 때만(M02_SO_Def_Reflect.differs)
- 시험: 322-2 검사 글 · 되돌림 견본

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Ji4nuyLVHcxrXWHTdb5nRD
2026-10-14 16:29:30 +09:00

334 lines
11 KiB
TypeScript

/* =============================================================================
* M02_SO_Def_Table.ts
* 구조물 정의 「한눈 표」 탭(PLAN 322-2) — 종류마다 B05 · B06 반영 한 줄.
* 군 · 종류(▲▼) · 이름 · 목록 · 자리꼴 · 정본(읽기만 「고정」) · 횡단도 · 카드 이름 · 형상(+ 형상칸) ·
* 알약 색 · 3D · 검사. 흐린 칸 = 처음 값(「기본」) · 진한 칸 = 바꾼 값 · [처음 값으로] = 그 종류 반영 지움.
* 칸 손질 = `M02_SO_Def_Reflect` · 검사 글 = `M02_SO_Def_Check`(서버 짝) · 「종류별」 탭이 같은 칸(`reflectCells`)을 씀.
* ========================================================================== */
import { createButton, createTag, el } from "@ui/ui_template_elements";
import type { CatalogRow } from "../../common_util/common_util_structure_catalog";
import { stepFamily, stepType, type StructDef, type TypeDef } from "./M02_SO_Def_Model";
import { REVET_FORMS } from "../../B06_Section/B06_Section_UI_Cross_Culvert_Const";
import {
isSet,
OWNER_KO,
PART_BOX,
PLACE_KO,
shortName,
resetRow,
rowsOf,
setReflect,
setShapeOpt,
valueOf,
type ReflectField,
} from "./M02_SO_Def_Reflect";
import { checkBox, pickBox, textBox } from "./M02_SO_Def_Ui";
import { to } from "./M02_SO_Text";
type Pairs = ReadonlyArray<readonly [string, string]>;
const LIST_PAIRS = (): Pairs => [
["both", to("ListBoth")],
["b06", to("ListB06")],
["hidden", to("ListHidden")],
];
/** 갈래 고르기 — 없음(횡단도 = 안 만듦 · 카드 이름 = 종류 이름) + 부품 상자 차례 · 글 = 짧은 이름
* (영어 키 · 괄호 설명은 툴팁 · 322-2 다듬기). */
const OFF_TEXT: Record<Exclude<ReflectField, "목록">, () => string> = {
횡단도: () => to("StationNone"),
카드이름: () => to("TitleName"),
형상: () => to("OffNone"),
"3D": () => to("OffNone"),
};
const partPairs = (branch: Exclude<ReflectField, "목록">): Pairs => [
[branch === "카드이름" ? "name" : "none", OFF_TEXT[branch]()],
...Object.entries(PART_BOX[branch]).map(([id, part]) => [id, shortName(part.이름)] as const),
];
/** 고르기 항목 툴팁 = 키 · 부품 긴 이름. */
function tipOptions(box: HTMLSelectElement, branch: ReflectField): void {
if (branch === "목록") return;
for (const option of Array.from(box.options)) {
const part = PART_BOX[branch][option.value];
option.title = part ? `${option.value} · ${part.이름}` : option.value;
}
}
interface CellCtx {
def: StructDef;
type: TypeDef;
row: CatalogRow;
edit: boolean;
changed: () => void;
}
/** 반영 칸 하나 — 처음 값이면 흐리게 「기본」 · 바꿨으면 진하게. */
function reflectCell(ctx: CellCtx, field: ReflectField): HTMLElement {
const { def, type, row, edit, changed } = ctx;
const pairs = field === "목록" ? LIST_PAIRS() : partPairs(field);
const box = pickBox(
pairs,
valueOf(row, field),
(v) => {
setReflect(def, type.type_id, field, v);
changed();
},
{ edit, attr: `data-sod-reflect-${field}` },
);
tipOptions(box, field);
return mark(isSet(def, type.type_id, field), box);
}
/** 흐림(기본) · 진함(바꿈) 꼴. */
function mark(changed: boolean, ...children: HTMLElement[]): HTMLElement {
return el("div", {
className: `m02-sod__cell ${changed ? "is-changed" : "is-default"}`,
children: [...children, ...(changed ? [] : [createTag(to("Default"), "neutral")])],
});
}
/** 형상칸 — 벽(형상 wall)만: 기본 형태(그림 형태 고르기) · 물빼기. */
function shapeOptsCell(ctx: CellCtx): HTMLElement {
const { def, type, row, edit, changed } = ctx;
if (row.shape !== "wall") return el("span", { className: "m02-side__empty", text: "—" });
const form = String(row.shapeOpts.form ?? "");
const forms = !form || REVET_FORMS.includes(form) ? REVET_FORMS : [form, ...REVET_FORMS];
const box = pickBox(
forms.map((f) => [f, f] as const),
form,
(v) => (setShapeOpt(def, type.type_id, "form", v), changed()),
{ edit, attr: "data-sod-shape-form" },
);
box.title = to("WallForm");
return mark(
isSet(def, type.type_id, "형상칸"),
box,
checkBox(
to("Weep"),
row.shapeOpts.weep === true,
(v) => (setShapeOpt(def, type.type_id, "weep", v), changed()),
{ edit, attr: "data-sod-shape-weep" },
),
);
}
/** 알약 색(style.color). */
function colorCell(ctx: CellCtx): HTMLElement {
const box = el("input", {
className: "m02-sod__color",
attrs: { type: "color", "data-sod-color": "" },
}) as HTMLInputElement;
const style = (ctx.type.style ?? {}) as { color?: string };
box.value = style.color ?? "#888888";
box.disabled = !ctx.edit;
box.addEventListener("change", () => {
ctx.type.style = { ...style, color: box.value };
ctx.changed();
});
return box;
}
/** 자리꼴 · 정본 = 한국어 글 · 「고정」(키는 툴팁). */
const fixed = (text: string, key: string): HTMLElement =>
el("span", {
className: "m02-sod__fixed",
attrs: { title: key },
children: [el("span", { text }), createTag(to("Fixed"), "neutral")],
});
/** 「종류별」 탭이 쓰는 반영 칸들 — [글, 칸] 짝. */
export function reflectCells(
def: StructDef,
type: TypeDef,
edit: boolean,
changed: () => void,
): Array<[string, HTMLElement]> {
const row = rowsOf(def).get(type.type_id);
if (!row) return [];
const ctx = { def, type, row, edit, changed };
return [
[to("ColList"), reflectCell(ctx, "목록")],
[to("ColPlacement"), fixed(PLACE_KO[row.placement] ?? row.placement, row.placement)],
[to("ColOwner"), fixed(OWNER_KO[row.owner] ?? row.owner, row.owner)],
[to("ColStation"), reflectCell(ctx, "횡단도")],
[to("ColTitle"), reflectCell(ctx, "카드이름")],
[to("ColShape"), reflectCell(ctx, "형상")],
[to("ColShapeOpts"), shapeOptsCell(ctx)],
[to("ColColor"), colorCell(ctx)],
[to("Col3D"), reflectCell(ctx, "3D")],
];
}
function moveButton(label: string, run: () => boolean, off: boolean, changed: () => void) {
const b = createButton({ label, variant: "ghost", size: "sm" });
b.disabled = off;
b.addEventListener("click", () => run() && changed());
return b;
}
/** 그 종류 검사 글 — 이름 · 키가 든 줄. */
const issuesOf = (issues: readonly string[], type: TypeDef): string[] =>
issues.filter((t) => t.includes(`「${type.name}」`) || t.includes(`「${type.type_id}`));
export function buildTable(opt: {
def: StructDef;
edit: boolean;
changed: () => void;
issues: readonly string[];
}): HTMLElement {
const { def, edit, changed, issues } = opt;
const heads = [
"ColFamily",
"ColKind",
"ColName",
"ColList",
"ColPlacement",
"ColOwner",
"ColStation",
"ColTitle",
"ColShape",
"ColShapeOpts",
"ColColor",
"Col3D",
"ColCheck",
] as const;
const td = (child: HTMLElement | string): HTMLElement =>
el("td", typeof child === "string" ? { text: child } : { children: [child] });
const body: HTMLElement[] = [];
const families = Object.keys(def.구조물군);
families.forEach((g, gi) => {
const name = textBox(def.구조물군[g], (v) => (def.구조물군[g] = v), changed, {
edit,
attr: "data-sod-family-name",
});
const familyRow = el("tr", {
className: "m02-sod__familyrow",
attrs: { "data-sod-table-family": g },
children: [
el("td", {
attrs: { colspan: String(heads.length) },
children: [
el("strong", { text: g }),
name,
...(edit
? [
moveButton(to("GroupUp"), () => stepFamily(def, g, -1), gi === 0, changed),
moveButton(
to("GroupDown"),
() => stepFamily(def, g, 1),
gi === families.length - 1,
changed,
),
]
: []),
],
}),
],
});
body.push(familyRow);
const kinds = def.types.filter((t) => t.group === g);
kinds.forEach((type, ti) => {
const cells = new Map(reflectCells(def, type, edit, changed));
const bad = issuesOf(issues, type);
const reset = createButton({ label: to("Reset"), variant: "ghost", size: "sm" });
reset.disabled = !edit || !(def as { 반영?: Record<string, unknown> }).반영?.[type.type_id];
reset.addEventListener("click", () => (resetRow(def, type.type_id), changed()));
body.push(
el("tr", {
attrs: { "data-sod-table-kind": type.type_id },
children: [
td(""),
el("td", {
attrs: { title: type.type_id }, // 영어 키는 툴팁만(322-2 다듬기)
children: [
...(edit
? [
moveButton(
to("GroupUp"),
() => stepType(def, type.type_id, -1),
ti === 0,
changed,
),
moveButton(
to("GroupDown"),
() => stepType(def, type.type_id, 1),
ti === kinds.length - 1,
changed,
),
]
: []),
],
}),
td(
textBox(type.name, (v) => (type.name = v), changed, {
edit,
attr: "data-sod-kind-name",
}),
),
...[
"ColList",
"ColPlacement",
"ColOwner",
"ColStation",
"ColTitle",
"ColShape",
"ColShapeOpts",
"ColColor",
"Col3D",
].map((key) => td(cells.get(to(key as (typeof heads)[number])) ?? "")),
el("td", {
attrs: { "data-sod-table-check": "" },
children: [
bad.length
? el("span", { className: "m02-sod__bad", text: bad.join(" · ") })
: createTag(to("Ok"), "accent"),
reset,
],
}),
],
}),
);
});
});
return el("div", {
className: "m02-sod__tablewrap",
children: [
el("p", { className: "m02-side__empty", text: to("TableNote") }),
el("table", {
className: "m02-sod__table",
attrs: { "data-sod-table": "" },
children: [
el("thead", {
children: [el("tr", { children: heads.map((h) => el("th", { text: to(h) })) })],
}),
el("tbody", { children: body }),
],
}),
],
});
}
/** 「종류별」 탭 머리 아래 반영 칸 묶음(한눈 표 한 줄과 같은 칸). */
export function buildReflectBlock(
def: StructDef,
type: TypeDef,
edit: boolean,
changed: () => void,
): HTMLElement {
return el("div", {
className: "m02-sod__block",
attrs: { "data-sod-reflect-block": "" },
children: [
el("h4", { className: "m02-opts__group", text: to("ReflectHead") }),
el("div", {
className: "m02-sod__reflect",
children: reflectCells(def, type, edit, changed).map(([label, cell]) =>
el("label", {
className: "m02-sod__reflectrow",
children: [el("span", { text: label }), cell],
}),
),
}),
],
});
}