Files
Aislo/M01_MasterData/StructOptions/M01_SO_Def_Layout.ts
T
eomsangdonandClaude Opus 5.5 e4b9b3e5a3 refactor(859-5 ②): 구조물 정의 코드 M02 StructOptions → M01_MasterData/StructOptions
- 파일 23 개 git mv · 이름 M02_SO_* → M01_SO_* · 내용 · 동작 · 화면 글 그대로
- 서버 주소 /api/m02 → /api/m01(이름만 · 10 길 · 수 469 그대로) · main.py 등록 이름 m01_so_*
- 화면 부름 = common_util_m02_call 의 call 에 base 인자(기본 /m02 · 구조물 정의만 /m01)
- import 고침 = B05 · B07 · B08 · M01 · M02 · main · 시험 · 도우미
- 소스 글자만 보던 시험 셋 지움(구조물 정의 옮김에 걸림 · 결과를 안 봄):
  test_m02_structure_options 좌측 줄 · test_m02_structure_option_groups 좌측 정의 줄 · test_136_3 M02 미리보기 단추 CSS
- test_553_5 부품 훑기 폴더 = 옮긴 자리

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-18 21:42:33 +09:00

121 lines
3.6 KiB
TypeScript

/* =============================================================================
* M01_SO_Def_Layout.ts
* 구조물 정의 편집 화면(PLAN 48-2) — 고른 종류의 **배치 격자**(B05 · B06 좌측 구조물 칸 = 두 칸)
* 옵션마다 줄 · 칸 · 너비 + 미리보기(기준 측점은 맨 위 한 줄 · 겹치면 빨강).
* 자리를 안 정한 옵션은 차례대로 빈 칸을 채움 · 숫자를 고치면 그 옵션 자리만 정의 `배치` 에 남음.
* ========================================================================== */
import { el } from "@ui/ui_template_elements";
import {
baseShown,
GRID_COLS,
live,
overlaps,
placeAll,
type Spot,
type StructDef,
type TypeDef,
} from "./M01_SO_Def_Model";
import { head, numberBox } from "./M01_SO_Def_Ui";
import { to } from "./M01_SO_Text";
export interface LayoutBlockOptions {
def: StructDef;
type: TypeDef;
edit: boolean;
changed: () => void;
}
const ROW_MAX = 60;
/** 미리보기 — 두 칸 격자 · 옵션마다 상자 */
function preview(def: StructDef, type: TypeDef, cells: Map<string, Spot>): HTMLElement {
const bad = new Set(overlaps(cells));
const base = baseShown(def, type.type_id);
const offset = base ? 1 : 0;
const boxes: HTMLElement[] = [];
if (base)
boxes.push(
el("div", {
className: "m02-sod__cell is-base",
text: to("BaseStation"),
attrs: { style: `grid-row: 1; grid-column: 1 / span ${GRID_COLS}` },
}),
);
for (const o of live(type.options)) {
const c = cells.get(o.key)!;
boxes.push(
el("div", {
className: `m02-sod__cell${bad.has(o.key) ? " is-bad" : ""}`,
text: o.label,
attrs: {
"data-sod-cell": o.key,
title: o.label,
style: `grid-row: ${c.줄 + offset}; grid-column: ${c.칸} / span ${c.너비}`,
},
}),
);
}
return el("div", {
className: "m02-sod__grid",
attrs: {
"data-sod-preview": "",
style: `grid-template-columns: repeat(${GRID_COLS}, minmax(0, 1fr))`,
},
children: boxes,
});
}
export function buildLayoutBlock(opt: LayoutBlockOptions): HTMLElement {
const { def, type, edit, changed } = opt;
const cells = placeAll(type.options, def.배치[type.type_id]);
const rows = live(type.options).map((o) => {
const c = cells.get(o.key)!;
const fix = (patch: Partial<Spot>): void => {
(def.배치[type.type_id] ??= {})[o.key] = { ...c, ...patch };
changed();
};
return el("div", {
className: "m02-sod__place",
attrs: { "data-sod-place-row": o.key },
children: [
el("span", { className: "m02-sod__placename", text: o.label }),
el("small", { text: to("GridRow") }),
numberBox(c.줄, (n) => fix({ 줄: n }), {
edit,
min: 1,
max: ROW_MAX,
attr: "data-sod-row",
}),
el("small", { text: to("GridCol") }),
numberBox(c.칸, (n) => fix({ 칸: n }), {
edit,
min: 1,
max: GRID_COLS,
attr: "data-sod-col",
}),
el("small", { text: to("GridWidth") }),
numberBox(c.너비, (n) => fix({ 너비: n }), {
edit,
min: 1,
max: GRID_COLS,
attr: "data-sod-width",
}),
],
});
});
return el("div", {
className: "m02-sod__block",
children: [
...head(to("LayoutHead"), to("LayoutNote")),
el("div", {
className: "m02-sod__layout",
children: [
el("div", { className: "m02-sod__places", children: rows }),
preview(def, type, cells),
],
}),
],
});
}