refactor(853-1): M01 화면 죽은 것 걷음 — 묶음 ①
- 지움: UI_Logic_Pick.ts(부르는 곳 0) · UI_Logic_Edit.ts(buildEditor · qtyKind 죽음 · 남은 formatNumber 는 공용 다시 내보내기뿐) · UI_Tree.ts(공용 트리 다시 내보내기 껍데기) - Logic_Note: buildNote 와 그것만 쓰던 relatedFinds · matchRow · tableView 등 걷음(살아 있는 loadTable · explain 남김) - LogicLab_Foot.FOOT_OF · Draft.fileCount 걷음(부르는 곳 0) - 글 키: Logic_Text 62 · LogicLab_Text 11 걷음(정적 · 동적 부름 0 · typecheck 가 지킴) - import 를 본래 자리로: formatNumber · formatMoney 등 → common_util_money · renderTree → @ui/ui_template_tree - UI_Logic_Money.ts 는 남김 — M02 네 파일이 import(sub2 몫) - 시험: test_782_1 소유 선택지 시험 지움(죽은 buildEditor 글만 봄) · test_208_1 · test_modal_top 경로 목록에서 Logic_Pick 줄 뺌 · helper_717_1 의 Logic_Edit 가짜 모듈 뺌 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,17 +1,12 @@
|
||||
/* =============================================================================
|
||||
* M01_MasterData_UI_Logic_Note.ts
|
||||
* 설명 카드 — 식 하나를 쉬운 말로 풀고, 그 식이 기대는 원문 표를 미리 보임(걸린 줄 강조).
|
||||
* 원문 표 읽기(`loadTable`) · 식 쉬운 말 풀이(`explain`).
|
||||
*
|
||||
* 순수 읽기 — `/elements` 로 표 파일을 찾고 `/table` 로 통째 읽어 그 자리에서 줄을 맞힘.
|
||||
* 엔진을 다시 돌리지 않음(수량·금액은 `/calc` 답이 줌) — 여기서는 「어느 줄이 걸렸나」만 보임.
|
||||
* 흐름 그림 상자(`…_Logic_Flow.ts`)와 테스트 방식 B 가 같이 씀.
|
||||
* 순수 읽기 — `/elements` 로 표 파일을 찾고 `/table` 로 통째 읽음.
|
||||
* ========================================================================== */
|
||||
|
||||
import { API_BASE_URL } from "@config/config_frontend";
|
||||
import { el } from "@ui/ui_template_elements";
|
||||
import { logicApiPaths, type ElementBrief, type NamedFormula } from "./M01_MasterData_UI_Logic_Api";
|
||||
import { formatNumber } from "./M01_MasterData_UI_Logic_Edit";
|
||||
import { tx } from "./M01_MasterData_UI_Logic_Text";
|
||||
import { logicApiPaths, type ElementBrief } from "./M01_MasterData_UI_Logic_Api";
|
||||
|
||||
/* ── 원문 표(소요량·계수) 읽기 ─────────────────────────────────────────── */
|
||||
|
||||
@@ -60,13 +55,7 @@ export function loadTable(key: string): Promise<TableRow | null> {
|
||||
return job;
|
||||
}
|
||||
|
||||
/* ── 식 속 찾기(표, 조건...).칸 뽑기 ────────────────────────────────────── */
|
||||
|
||||
export interface FindCall {
|
||||
table: string;
|
||||
conds: [string, string][];
|
||||
col: string;
|
||||
}
|
||||
/* ── 식 속 찾기(표, 조건...).칸 ──────────────────────────────────────── */
|
||||
|
||||
const FIND_RE = /찾기\(\s*([A-Za-z0-9_]+)\s*,([^)]*)\)\s*\.\s*([A-Za-z0-9_가-힣]+)/g;
|
||||
|
||||
@@ -81,78 +70,6 @@ function splitConds(raw: string): [string, string][] {
|
||||
});
|
||||
}
|
||||
|
||||
function findCalls(expr: string): FindCall[] {
|
||||
const out: FindCall[] = [];
|
||||
for (const m of expr.matchAll(FIND_RE)) {
|
||||
out.push({ table: m[1], conds: splitConds(m[2]), col: m[3] });
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/** 식 안에 이름이 낱말로 나오는지 — 한글엔 \b 가 안 먹어 앞뒤 글자를 직접 봄 */
|
||||
function mentions(expr: string, name: string): boolean {
|
||||
if (!name) return false;
|
||||
const idx = expr.indexOf(name);
|
||||
if (idx < 0) return false;
|
||||
const isWord = (c: string | undefined) => !!c && /[A-Za-z0-9_가-힣]/.test(c);
|
||||
return !isWord(expr[idx - 1]) && !isWord(expr[idx + name.length]);
|
||||
}
|
||||
|
||||
export interface RelatedFind {
|
||||
/** 「이 줄」 또는 물려 쓰는 중간 값 이름 */
|
||||
source: string;
|
||||
find: FindCall;
|
||||
}
|
||||
|
||||
/** 이 줄 식이 기대는 찾기(...) — 자기 식 + (한 단계) 물려 쓰는 중간 식 */
|
||||
export function relatedFinds(expr: string, middles: NamedFormula[]): RelatedFind[] {
|
||||
const out: RelatedFind[] = findCalls(expr).map((find) => ({
|
||||
source: tx("Note_ThisLine"),
|
||||
find,
|
||||
}));
|
||||
for (const m of middles) {
|
||||
if (!mentions(expr, m.이름)) continue;
|
||||
for (const find of findCalls(m.식)) out.push({ source: m.이름, find });
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/* ── 조건 값 풀기 · 표 줄 맞히기 ───────────────────────────────────────── */
|
||||
|
||||
export interface EvalCtx {
|
||||
values: Record<string, string>;
|
||||
middle: Record<string, unknown>;
|
||||
}
|
||||
|
||||
function resolveIdent(name: string, ctx: EvalCtx): string | number | undefined {
|
||||
const quoted = name.match(/^["'](.*)["']$/);
|
||||
if (quoted) return quoted[1];
|
||||
if (/^-?\d+(\.\d+)?$/.test(name)) return Number(name);
|
||||
if (ctx.values[name] !== undefined && ctx.values[name] !== "") return ctx.values[name];
|
||||
if (ctx.middle[name] !== undefined) return ctx.middle[name] as number;
|
||||
return undefined;
|
||||
}
|
||||
|
||||
function sameValue(a: unknown, b: unknown): boolean {
|
||||
if (a === undefined || a === null || b === undefined) return false;
|
||||
const na = Number(a);
|
||||
const nb = Number(b);
|
||||
if (!Number.isNaN(na) && !Number.isNaN(nb)) return na === nb;
|
||||
return String(a) === String(b);
|
||||
}
|
||||
|
||||
/** 지금 조건 값으로 찾기() 가 고를 줄 — 못 맞히면 null(값을 아직 안 골랐거나 후보 여럿) */
|
||||
export function matchRow(
|
||||
table: TableRow,
|
||||
conds: [string, string][],
|
||||
ctx: EvalCtx,
|
||||
): Record<string, unknown> | null {
|
||||
for (const row of table.줄 ?? []) {
|
||||
if (conds.every(([col, rhs]) => sameValue(row[col], resolveIdent(rhs, ctx)))) return row;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/* ── 쉬운 말 풀이 — 찾기()/만약() 을 문장으로, 안 되면 식 그대로 ─────────── */
|
||||
|
||||
function splitTop(s: string): string[] {
|
||||
@@ -200,92 +117,3 @@ export function explain(expr: string): string {
|
||||
});
|
||||
return expandIf(withFind).trim() || expr;
|
||||
}
|
||||
|
||||
/* ── 카드 그리기 ──────────────────────────────────────────────────────── */
|
||||
|
||||
export interface NoteOptions {
|
||||
/** 풀어 볼 식 — 호표 줄의 수량 · 중간 값·덧줄의 식 */
|
||||
expr: string;
|
||||
/** 물려 쓰는 중간 값(한 단계) */
|
||||
middles: NamedFormula[];
|
||||
ctx: EvalCtx;
|
||||
}
|
||||
|
||||
/** 표 하나를 그림 — 지금 값으로 걸린 줄은 강조 */
|
||||
function tableView(find: RelatedFind, table: TableRow, ctx: EvalCtx): HTMLElement[] {
|
||||
const hit = matchRow(table, find.find.conds, ctx);
|
||||
const cols = [...Object.keys(table.조건 ?? {}), ...Object.keys(table.값칸 ?? {})];
|
||||
const body = (table.줄 ?? []).map((line) =>
|
||||
el("tr", {
|
||||
className: hit === line ? "m01c__hit" : "",
|
||||
children: cols.map((c) => el("td", { text: formatNumber(line[c]) })),
|
||||
}),
|
||||
);
|
||||
const use = table.용도
|
||||
? [table.용도.공종, (table.용도.대상 ?? []).join("·")].filter(Boolean).join(" · ")
|
||||
: "";
|
||||
return [
|
||||
el("p", {
|
||||
className: "ui-text ui-text--muted",
|
||||
text: `${find.source} · ${table.원문번호 ?? table.키} ${table.이름 ?? ""} (${table.출처 ?? ""})`,
|
||||
}),
|
||||
...(use
|
||||
? [el("p", { className: "ui-text ui-text--muted", text: `${tx("Use_Of")} — ${use}` })]
|
||||
: []),
|
||||
el("table", {
|
||||
className: "m01c__table",
|
||||
children: [
|
||||
el("thead", { children: [el("tr", { children: cols.map((c) => el("th", { text: c })) })] }),
|
||||
el("tbody", { children: body }),
|
||||
],
|
||||
}),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 설명 카드를 `host` 에 채움 — 쉬운 말 풀이 · 원문 표 미리보기 · 고급(식 그대로).
|
||||
* 표는 서버에서 읽어 오므로 먼저 「찾는 중」을 보이고 온 뒤 갈아 끼움.
|
||||
*/
|
||||
export function buildNote(host: HTMLElement, opts: NoteOptions): void {
|
||||
const related = relatedFinds(opts.expr, opts.middles);
|
||||
const advanced = el("details", {
|
||||
className: "m01c__raw",
|
||||
children: [el("summary", { text: tx("Note_Formula") }), el("pre", { text: opts.expr })],
|
||||
});
|
||||
const plain = explain(opts.expr);
|
||||
const head: HTMLElement[] = [
|
||||
el("p", { className: "ui-text ui-text--muted", text: tx("Note_Plain") }),
|
||||
el("p", { className: "m01c__plain", text: plain }),
|
||||
];
|
||||
if (!related.length) {
|
||||
host.replaceChildren(...head, advanced);
|
||||
return;
|
||||
}
|
||||
const tables = el("div", {
|
||||
className: "ui-text ui-text--muted",
|
||||
text: `${tx("Note_Searching")}…`,
|
||||
});
|
||||
host.replaceChildren(
|
||||
...head,
|
||||
el("p", { className: "ui-text ui-text--muted", text: tx("Note_Table") }),
|
||||
tables,
|
||||
advanced,
|
||||
);
|
||||
void Promise.all(related.map(async (r) => ({ r, table: await loadTable(r.find.table) }))).then(
|
||||
(got) => {
|
||||
tables.className = "m01c__tables";
|
||||
tables.replaceChildren(
|
||||
...got.flatMap(({ r, table }) =>
|
||||
table
|
||||
? tableView(r, table, opts.ctx)
|
||||
: [
|
||||
el("p", {
|
||||
className: "ui-text ui-text--muted",
|
||||
text: tx("Note_TableMissing", { v: r.find.table }),
|
||||
}),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user