Merge remote-tracking branch 'origin/dev' into sub_laptop_4
This commit is contained in:
@@ -52,10 +52,10 @@
|
||||
display: none;
|
||||
}
|
||||
|
||||
/* 띠 — 화면 위 3분의 1 안쪽 · 길면 가로로 밀기 */
|
||||
/* 띠 — 세로는 상자 높이만큼 다 보임(사용자 요청) · 길면 가로로 밀기 */
|
||||
.m01-sldg__band {
|
||||
max-height: 33vh;
|
||||
overflow: auto;
|
||||
overflow-x: auto;
|
||||
overflow-y: hidden;
|
||||
border: 1px solid var(--color-border);
|
||||
border-radius: var(--radius-lg);
|
||||
background: color-mix(in srgb, var(--color-accent) 5%, var(--color-canvas));
|
||||
|
||||
@@ -8,9 +8,9 @@
|
||||
font-size: var(--text-body);
|
||||
}
|
||||
|
||||
/* 세 칸은 내용 높이만큼 — 넘치면 창(모달) 전체만 세로로 밈 */
|
||||
.m01-sl .ui-modal__body {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
flex: 0 0 auto;
|
||||
gap: var(--spacing-12);
|
||||
}
|
||||
|
||||
@@ -111,11 +111,10 @@
|
||||
|
||||
/* 위 가로 다이어그램 · 아래 왼쪽 시트 판 · 아래 오른쪽 결과 */
|
||||
.m01-sl__layout {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
display: grid;
|
||||
grid-template-columns: minmax(0, 2fr) minmax(0, 1fr);
|
||||
grid-template-rows: minmax(160px, 2fr) minmax(0, 3fr);
|
||||
grid-template-rows: auto auto;
|
||||
align-items: start;
|
||||
grid-template-areas:
|
||||
"diagram diagram"
|
||||
"panel result";
|
||||
@@ -137,7 +136,6 @@
|
||||
.m01-sl__part {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
min-height: 0;
|
||||
border: 1px solid var(--color-border);
|
||||
border-radius: var(--radius-lg);
|
||||
}
|
||||
@@ -149,9 +147,7 @@
|
||||
}
|
||||
|
||||
.m01-sl__part-body {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
overflow: auto;
|
||||
min-width: 0;
|
||||
padding: var(--spacing-12);
|
||||
}
|
||||
|
||||
@@ -164,7 +160,6 @@
|
||||
"diagram"
|
||||
"panel"
|
||||
"result";
|
||||
overflow: auto;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -33,7 +33,8 @@ export const loadMods = () =>
|
||||
import("./M01_SL_Result"),
|
||||
import("./M01_SL_Import"),
|
||||
import("../../A00_Common/spreadsheet/spreadsheet_recalc"),
|
||||
]).then(([model, ev, api, diagram, panel, table, item, result, imp, recalc]) => ({
|
||||
import("./M01_SL_LogicTools"),
|
||||
]).then(([model, ev, api, diagram, panel, table, item, result, imp, recalc, logic]) => ({
|
||||
model,
|
||||
ev,
|
||||
api,
|
||||
@@ -44,6 +45,7 @@ export const loadMods = () =>
|
||||
result,
|
||||
imp,
|
||||
recalc,
|
||||
logic,
|
||||
}));
|
||||
export type Mods = Awaited<ReturnType<typeof loadMods>>;
|
||||
|
||||
@@ -109,13 +111,19 @@ export function outsidePlaces(M: Mods, sl: SheetLogic): SlOutsideAt[] {
|
||||
if (!at.has(k)) at.set(k, p);
|
||||
};
|
||||
M.item.itemOutsides(sl).forEach(put);
|
||||
for (const c of M.ev.outsideCells(sl)) {
|
||||
const node = sl.nodes.find((n) => n.id === c.node);
|
||||
if (node && c.source)
|
||||
put({ item: { id: c.id, ...c.source } as SlQuery, sheet: node.sheetId, cell: c.cell });
|
||||
}
|
||||
// 상자에 출처가 적힌 알약 → 넘길 값을 실은 물음(outsideOf) → 출처를 짐작한 나머지(넘길 값 없음) 차례
|
||||
const cells = M.ev.outsideCells(sl);
|
||||
const fromCell = (explicit: boolean): void => {
|
||||
for (const c of cells) {
|
||||
const node = sl.nodes.find((n) => n.id === c.node);
|
||||
if (node && c.source && !!node.source === explicit)
|
||||
put({ item: { id: c.id, ...c.source } as SlQuery, sheet: node.sheetId, cell: c.cell });
|
||||
}
|
||||
};
|
||||
fromCell(true);
|
||||
// 넘길 입력값이 수식 칸이면 계산값이 있어야 함(없으면 null 로 넘어가 단가가 0)
|
||||
M.imp.outsideOf(sl, M.recalc.recalcWorkbook(sl.workbook)).forEach(put);
|
||||
fromCell(false);
|
||||
return [...at.values()];
|
||||
}
|
||||
|
||||
@@ -139,6 +147,18 @@ export async function fillOutside(
|
||||
return { sl: M.ev.applyOutside(sl, values), errors };
|
||||
}
|
||||
|
||||
/* 시트 판 높이 — 그 시트가 쓰는 줄 수 + 두 줄(안쪽 세로 밀기 없게 · 사용자 요청)
|
||||
* ponytail: 편집기 줄 높이 · 띠 높이를 숫자로 둠 — 편집기 꾸밈이 바뀌면 같이 고침 */
|
||||
const ROW_PX = 20;
|
||||
const CHROME_PX = 26 + 24 + 24 + 20; // 위 띠 · 칸 머리 · 아래 상태줄 · 가로 밀기 막대
|
||||
function sheetHeight(sheet: { 칸: Record<string, unknown> } | null): number {
|
||||
const rows = Object.keys(sheet?.칸 ?? {}).reduce(
|
||||
(most, a1) => Math.max(most, Number(a1.replace(/^[A-Z]+/, "")) || 0),
|
||||
0,
|
||||
);
|
||||
return CHROME_PX + (Math.max(rows, 6) + 2) * ROW_PX;
|
||||
}
|
||||
|
||||
/** 서버가 다시 셈한 합계 — 결과 상자 「계」 알약 칸의 서버 계산값(수식이 아니면 칸 값) */
|
||||
function serverTotal(sl: SheetLogic): number | null {
|
||||
const box = sl.nodes.find((n) => n.kind === "result");
|
||||
@@ -293,6 +313,7 @@ export function showPaper(
|
||||
panelHost.hidden = false;
|
||||
pickHint.hidden = true;
|
||||
toolsHost.className = ""; // 표 손잡이가 제 꾸밈 이름을 붙임 — 다른 종류로 바뀌면 지움
|
||||
panelHost.style.setProperty("--sl-sheet-h", `${sheetHeight(M.model.nodeSheet(sl, node.id))}px`);
|
||||
M.panel.renderPanel(panelHost, sl, node.id, {
|
||||
change: (next) => edit(next),
|
||||
pill: (nodeId, cell, dir, pillName) => edit(M.model.setPill(sl, nodeId, cell, dir, pillName)),
|
||||
@@ -306,6 +327,13 @@ export function showPaper(
|
||||
loadPrices(node.id);
|
||||
},
|
||||
});
|
||||
else if (node.kind === "logic")
|
||||
M.logic.renderLogicTools(toolsHost, sl, node.id, {
|
||||
change: (next) => {
|
||||
edit(next, true);
|
||||
loadPrices(node.id);
|
||||
},
|
||||
});
|
||||
else toolsHost.replaceChildren();
|
||||
};
|
||||
|
||||
|
||||
@@ -19,15 +19,15 @@
|
||||
import { currentLanguageIndex } from "@ui/ui_template_locale";
|
||||
import { colName, quoteSheet } from "../../A00_Common/spreadsheet/spreadsheet_address";
|
||||
import type {
|
||||
CalcValues,
|
||||
Cell,
|
||||
DataValidationKind,
|
||||
Sheet,
|
||||
Workbook,
|
||||
} from "../../A00_Common/spreadsheet/spreadsheet_types";
|
||||
import type { HoLine, LogicInput, LogicRow } from "../M01_MasterData_UI_Logic_Api";
|
||||
import { readLogic } from "../LogicBuilder/M01_LB_Blocks";
|
||||
import type { SheetLogic, SlEdge, SlKind, SlNode, SlPill } from "./M01_SL_Model";
|
||||
import type { SlField, SlOutside, SlOutsideAt } from "./M01_SL_Api";
|
||||
import { applyItemLayout, refreshBases, type ItemRef } from "./M01_SL_Item";
|
||||
import {
|
||||
parseFormula,
|
||||
RULES,
|
||||
@@ -64,6 +64,7 @@ const TEXT = {
|
||||
Field: ["요소의 칸 값 「{v}」", "Element field “{v}”"],
|
||||
FindAll: ["표 줄을 통째로 씀", "Uses a whole table row"],
|
||||
Parse: ["읽을 수 없는 글", "Text that can't be read"],
|
||||
PassCalc: ["넘길 값에 계산이 들어 있음", "A passed value is calculated"],
|
||||
} as const;
|
||||
const t = (k: keyof typeof TEXT, v = ""): string =>
|
||||
TEXT[k][currentLanguageIndex === 1 ? 1 : 0].replace("{v}", v);
|
||||
@@ -75,6 +76,8 @@ export interface SlImportOptions {
|
||||
tables?: Record<string, SlImportTable>;
|
||||
/** 입력값 → 예시값 — 없으면 선택 목록 첫째 · 범위 낮은 끝 · 숫자 0 */
|
||||
examples?: Record<string, number | string>;
|
||||
/** 키 → 보일 이름(직종 · 자재 · 다른 로직) — 상자 이름에 번호 대신 */
|
||||
names?: Record<string, string>;
|
||||
}
|
||||
|
||||
export interface SlImportReport {
|
||||
@@ -120,20 +123,26 @@ class Build {
|
||||
readonly tables = new Map<string, TableBox>();
|
||||
readonly logics = new Map<string, SlNode>();
|
||||
readonly consts = new Map<string, SlNode>();
|
||||
readonly specs = new Map<string, LogicInput>();
|
||||
/** 키 → 보일 이름 — 호표 줄 이름 · 받은 이름 */
|
||||
readonly names = new Map<string, string>();
|
||||
|
||||
constructor(readonly opts: SlImportOptions) {}
|
||||
constructor(readonly opts: SlImportOptions) {
|
||||
for (const [k, v] of Object.entries(opts.names ?? {})) this.names.set(k, v);
|
||||
}
|
||||
|
||||
node(kind: SlKind, name: string, stage: number, ref?: string): SlNode {
|
||||
/** 상자 하나 + 시트 — `head` 면 1행 머리(이름 · 값 · 설명) · 항목 틀은 머리 없음 */
|
||||
node(kind: SlKind, name: string, stage: number, ref?: string, head = true): SlNode {
|
||||
const n = this.nodes.length + 1;
|
||||
const head = { input: "Input", const: "Const", table: "Table", calc: "Calc", item: "Item", logic: "Logic", result: "Result" }[kind] as keyof typeof TEXT; // prettier-ignore
|
||||
const base = kind === "result" ? t("Result") : `${t(head)} · ${name}`.slice(0, 31);
|
||||
const word = { input: "Input", const: "Const", table: "Table", calc: "Calc", item: "Item", logic: "Logic", result: "Result" }[kind] as keyof typeof TEXT; // prettier-ignore
|
||||
const base = kind === "result" ? t("Result") : `${t(word)} · ${name}`.slice(0, 31);
|
||||
let title = base;
|
||||
for (let k = 2; [...this.sheets.values()].some((s) => s.이름 === title); k++)
|
||||
title = `${base.slice(0, 28)} ${k}`;
|
||||
const sheet: Sheet = {
|
||||
id: `s${n}`,
|
||||
이름: title,
|
||||
칸: { A1: { 값: t("Name") }, B1: { 값: t("Value") }, C1: { 값: t("Note") } },
|
||||
칸: head ? { A1: { 값: t("Name") }, B1: { 값: t("Value") }, C1: { 값: t("Note") } } : {},
|
||||
};
|
||||
this.book.시트.push(sheet);
|
||||
this.sheets.set(sheet.id, sheet);
|
||||
@@ -306,7 +315,7 @@ function put(sc: Scope, label: string, text: string, pill: "out" | null, note =
|
||||
function constBox(b: Build, key: string): SlNode {
|
||||
const had = b.consts.get(key);
|
||||
if (had) return had;
|
||||
const node = b.node("const", key, 0, key);
|
||||
const node = b.node("const", b.names.get(key) ?? key, 0, key);
|
||||
const at = b.row(node, t("Price"), {}, t("Outside"));
|
||||
b.pill(node, "in", { name: t("Price"), cell: at, outside: true });
|
||||
b.pill(node, "out", { name: t("Price"), cell: at });
|
||||
@@ -340,16 +349,17 @@ function logicBox(b: Build, n: Extract<Ast, { t: "logic" }>, field?: string): Sl
|
||||
let node = b.logics.get(sig);
|
||||
if (!node) {
|
||||
if (/[{}]/.test(n.head)) throw new Fail(t("Hole", n.head));
|
||||
node = b.node("logic", n.head, 2, n.head);
|
||||
node = b.node("logic", b.names.get(n.head) ?? n.head, 1, n.head);
|
||||
args(b, node, n.args);
|
||||
b.logics.set(sig, node);
|
||||
}
|
||||
const name = field ?? t("Result");
|
||||
if (!node.pillsOut.some((p) => p.name === name)) {
|
||||
const at = b.row(node, name, {}, t("Outside"));
|
||||
b.pill(node, "in", { name, cell: at, outside: true });
|
||||
b.pill(node, "out", { name, cell: at });
|
||||
}
|
||||
const money = ["노무비", "재료비", "경비", "계"];
|
||||
for (const name of field && money.includes(field) ? money : [field ?? t("Result")])
|
||||
if (!node.pillsOut.some((p) => p.name === name)) {
|
||||
const at = b.row(node, name, {}, t("Outside"));
|
||||
b.pill(node, "in", { name, cell: at, outside: true });
|
||||
b.pill(node, "out", { name, cell: at });
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
@@ -374,7 +384,7 @@ function newTable(b: Build, n: Extract<Ast, { t: "find" }>, sig: string): TableB
|
||||
for (const [k] of n.args) if (!(k in table.조건)) throw new Fail(t("NoCol", k));
|
||||
if (n.args.some(([k]) => table.조건[k] === "범위") && !RULES.includes(rule))
|
||||
throw new Fail(t("Rule", String(table.범위규칙)));
|
||||
const node = b.node("table", table.이름 || n.head, 1, n.head);
|
||||
const node = b.node("table", table.이름 || b.names.get(n.head) || n.head, 1, n.head);
|
||||
const s = b.sheet(node);
|
||||
// 조건 알약 — 받는 값은 넘긴 식
|
||||
const cond = new Map<string, string>();
|
||||
@@ -383,7 +393,6 @@ function newTable(b: Build, n: Extract<Ast, { t: "find" }>, sig: string): TableB
|
||||
// 표 E1 부터
|
||||
const cols = tableCols(table);
|
||||
const rows = tableRows(table);
|
||||
b.row(node, t("Table"), { 값: n.head }, t("Outside"));
|
||||
// 바깥 값 「표」 알약 — Table 상자와 같은 꼴(출력 · 블록 왼위 · 머리 줄 포함) · Eval · 서버가 이 칸에서 블록을 채움
|
||||
b.pill(node, "out", { name: "표", cell: "E1", outside: true });
|
||||
rows.forEach((r, i) =>
|
||||
@@ -394,8 +403,13 @@ function newTable(b: Build, n: Extract<Ast, { t: "find" }>, sig: string): TableB
|
||||
);
|
||||
const letter = (key: string, part: "v" | "lo" | "hi"): string =>
|
||||
colName(4 + cols.findIndex((c) => c.key === key && c.part === part));
|
||||
const N = table.줄.length;
|
||||
// 마스터 표 줄이 늘어도 따라가게 — 줄 수 이상 · 최소 20 줄까지 셈 · 「표 줄 수」 칸 밖 줄은 안 맞음
|
||||
const N = Math.max(20, table.줄.length);
|
||||
const range = (L: string): string => `$${L}$2:$${L}$${N + 1}`;
|
||||
const count = b.row(node, "표 줄 수", {
|
||||
식: `MAX(${cols.map((_, j) => `COUNTA(${range(colName(4 + j))})`).join(",")})`,
|
||||
});
|
||||
const last = `$B$${count.slice(1)}`;
|
||||
let free = 4 + cols.length + 1;
|
||||
// 맞음 — 줄마다 조건 셈(빈 칸은 무엇이든 맞음 · 범위는 규칙대로)
|
||||
const M = colName(free++);
|
||||
@@ -424,7 +438,8 @@ function newTable(b: Build, n: Extract<Ast, { t: "find" }>, sig: string): TableB
|
||||
: `OR(${H}="",${x}<=${H})`;
|
||||
return `AND(OR(${L}="",${x}${low}${L}),${up})`;
|
||||
});
|
||||
s.칸[`${M}${r}`] = { 식: parts.length ? `IF(AND(${parts.join(",")}),1,0)` : "1" };
|
||||
const fit = parts.length ? `IF(AND(${parts.join(",")}),1,0)` : "1";
|
||||
s.칸[`${M}${r}`] = { 식: `IF(${r - 1}>${last},0,${fit})` };
|
||||
}
|
||||
// 여러 줄이 맞으면 위 끝이 가장 작은 줄(규칙 이하 · 이상·이하 — 엔진 `find`)
|
||||
let hit = M;
|
||||
@@ -484,27 +499,14 @@ function inputBox(b: Build, spec: LogicInput): void {
|
||||
const at = b.out(node, spec.이름, example(spec, b.opts.examples?.[spec.이름]), spec.단위 ?? "");
|
||||
const r = Number(at.slice(1)) - 1;
|
||||
const whole = { r0: r, c0: 1, r1: r, c1: 1 };
|
||||
if (spec.고르기?.length)
|
||||
b.sheet(node).유효성 = [
|
||||
{
|
||||
id: "v1",
|
||||
범위: [whole],
|
||||
규칙: { 종류: "목록", 값들: spec.고르기.map(String) },
|
||||
어기면: "막음",
|
||||
},
|
||||
];
|
||||
else if (spec.범위)
|
||||
b.sheet(node).유효성 = [
|
||||
{
|
||||
id: "v1",
|
||||
범위: [whole],
|
||||
규칙: { 종류: "수범위", 아래: spec.범위[0], 위: spec.범위[1] },
|
||||
어기면: "막음",
|
||||
},
|
||||
];
|
||||
const rule: DataValidationKind | null = spec.고르기?.length
|
||||
? { 종류: "목록", 값들: spec.고르기.map(String) }
|
||||
: spec.범위 ? { 종류: "수범위", 아래: spec.범위[0], 위: spec.범위[1] } : null; // prettier-ignore
|
||||
if (rule) b.sheet(node).유효성 = [{ id: "v1", 범위: [whole], 규칙: rule, 어기면: "막음" }];
|
||||
const pill = node.pillsOut[0];
|
||||
if (spec.단위) pill.unit = spec.단위;
|
||||
b.inputs.set(spec.이름, node);
|
||||
b.specs.set(spec.이름, spec);
|
||||
}
|
||||
|
||||
/** 수량 — 숫자 · 이름 하나면 바로 · 식이면 계산 상자 「이름 수량」 → [상자, 알약] */
|
||||
@@ -519,54 +521,90 @@ function qtyFrom(b: Build, item: HoLine, name: string): [SlNode, string] | numbe
|
||||
return [node, label];
|
||||
}
|
||||
|
||||
/** 항목 상자(호표 줄) → 비목 출력 알약들 */
|
||||
/** 항목 틀 — Item `applyItemLayout` 으로 그 상자 시트 · 알약을 채움(Item 이 알아보는 꼴 한 벌) */
|
||||
function layout(b: Build, node: SlNode, ref: ItemRef, qty?: number): void {
|
||||
const sheet = b.sheet(node);
|
||||
const mini = { key: null, name: "", resultUnit: "", workbook: { ...b.book, 시트: [sheet] }, nodes: [node], edges: [] }; // prettier-ignore
|
||||
const got = applyItemLayout(mini, node, ref, qty);
|
||||
sheet.칸 = got.workbook.시트[0].칸;
|
||||
const 유효성 = got.workbook.시트[0].유효성;
|
||||
if (유효성) sheet.유효성 = 유효성;
|
||||
Object.assign(node, got.nodes[0]);
|
||||
}
|
||||
|
||||
/** 항목 상자(호표 줄) — Item 틀 그대로(node.ref = ItemRef) → 비목 출력 알약들 */
|
||||
function itemBox(b: Build, item: HoLine, lines: Map<string, [SlNode, string]>): [SlNode, Cost][] {
|
||||
const name = item.이름 || String(item.요소);
|
||||
const element = typeof item.요소 === "string" ? item.요소 : JSON.stringify(item.요소);
|
||||
const call =
|
||||
typeof item.요소 === "string" && item.요소.startsWith("로직(") ? parseFormula(item.요소) : null;
|
||||
const node = b.node("item", name, 3, call?.t === "logic" ? (call.args.some(([k]) => k === "기계") ? element : call.head) : element); // prettier-ignore
|
||||
const q = qtyFrom(b, item, name);
|
||||
const qty =
|
||||
typeof q === "number"
|
||||
? b.row(node, t("Qty"), { 값: q }, item.단위 ?? "")
|
||||
: b.link(node, q[0], q[1]);
|
||||
if (typeof q === "number") b.pill(node, "in", { name: t("Qty"), cell: qty, unit: item.단위 });
|
||||
const out: [SlNode, Cost][] = [];
|
||||
if (call?.t === "logic") {
|
||||
args(b, node, call.args);
|
||||
const unit = COSTS.map((k) => {
|
||||
const at = b.row(node, `${t("Price")} · ${k}`, {}, t("Outside"));
|
||||
b.pill(node, "in", { name: k, cell: at, outside: true });
|
||||
return at;
|
||||
});
|
||||
const fixed = item.비목 as Cost | undefined;
|
||||
const total = `${qty}*(${unit.join("+")})`;
|
||||
if (fixed && (COSTS as readonly string[]).includes(fixed)) {
|
||||
b.out(node, fixed, { 식: total });
|
||||
out.push([node, fixed]);
|
||||
lines.set(name, [node, fixed]);
|
||||
} else {
|
||||
COSTS.forEach((k, i) => {
|
||||
b.out(node, k, { 식: `${qty}*${unit[i]}` });
|
||||
out.push([node, k]);
|
||||
});
|
||||
b.out(node, t("Amount"), { 식: total });
|
||||
lines.set(name, [node, t("Amount")]);
|
||||
const el: unknown = item.요소;
|
||||
const call = typeof el === "string" && el.startsWith("로직(") ? parseFormula(el) : null;
|
||||
const logic = call?.t === "logic" ? call : null;
|
||||
const what: ItemRef["what"] = logic
|
||||
? logic.args.some(([k]) => k === "기계") ? "장비" : "일위대가"
|
||||
: item.종류 === "인력" ? "노무" : "재료"; // prettier-ignore
|
||||
// 넘길 값 — 입력값 이름은 예시값으로(Item 이 ref.inputs 로 바깥 값을 받음) · 글 · 수는 요소 글 안에 그대로
|
||||
const need: LogicInput[] = [];
|
||||
const inputs: Record<string, unknown> = {};
|
||||
const bad: string[] = [];
|
||||
for (const [k, v] of logic?.args ?? []) {
|
||||
if (v.t !== "name") {
|
||||
if (v.t !== "num" && v.t !== "str") bad.push(k);
|
||||
continue;
|
||||
}
|
||||
const spec = b.specs.get(v.v);
|
||||
if (!spec) bad.push(k);
|
||||
else {
|
||||
need.push({ ...spec, 이름: k });
|
||||
inputs[k] = example(spec, b.opts.examples?.[spec.이름]).값;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
const price = b.row(node, t("Price"), {}, t("Outside"));
|
||||
b.pill(node, "in", { name: t("Price"), cell: price, outside: true });
|
||||
const holes = typeof item.요소 === "string" ? [item.요소] : Object.values(item.요소 ?? {});
|
||||
const element = what === "재료" && typeof el === "string" ? { 키: el } : el;
|
||||
const ref: ItemRef = {
|
||||
what,
|
||||
element,
|
||||
...(item.규격 ? { spec: item.규격 } : {}),
|
||||
...(item.단위 ? { unit: item.단위 } : {}),
|
||||
...(need.length ? { need, inputs } : {}),
|
||||
};
|
||||
const node = b.node("item", name, 3, JSON.stringify(ref), false);
|
||||
const outside: Cost[] = what === "노무" ? ["노무비"] : what === "재료" ? ["재료비"] : [...COSTS];
|
||||
const q = qtyFrom(b, item, name);
|
||||
layout(b, node, ref, typeof q === "number" ? q : undefined);
|
||||
if (typeof q !== "number") b.link(node, q[0], q[1], node.pillsIn[0]);
|
||||
const holes = typeof el === "string" ? [el] : Object.values(el ?? {});
|
||||
const priceAt = what === "재료" ? "B3" : "B2";
|
||||
if (holes.some((v) => typeof v === "string" && /\{[^}]*\}/.test(v)))
|
||||
b.cant(node, price, t("Hole", element), element);
|
||||
b.cant(node, priceAt, t("Hole", typeof el === "string" ? el : JSON.stringify(el)), String(el));
|
||||
if (bad.length) b.cant(node, priceAt, t("PassCalc"), bad.join(", "));
|
||||
lines.set(name, [node, "금액"]);
|
||||
return outside.map((c): [SlNode, Cost] => [node, c]);
|
||||
}
|
||||
|
||||
/** 덧줄 — 「노무비 * 3 / 100」 꼴이면 Item 비율 틀 · 아니면 식 그대로 계산하는 항목(금액 · 비목 · 단가 알약) */
|
||||
const RATE_RE = /^\(?(노무비|재료비|경비)\)?\*(\d+(?:\.\d+)?)\/100$/;
|
||||
|
||||
function extraBox(
|
||||
b: Build,
|
||||
extra: { 이름: string; 식: string; 비목?: string; 출처?: string },
|
||||
sc: Omit<Scope, "here">,
|
||||
): [SlNode, Cost] {
|
||||
const cost = (
|
||||
(COSTS as readonly string[]).includes(item.비목 ?? "") ? item.비목 : "재료비"
|
||||
(COSTS as readonly string[]).includes(extra.비목 ?? "") ? extra.비목 : "경비"
|
||||
) as Cost;
|
||||
b.out(node, cost, { 식: `${qty}*${price}` });
|
||||
lines.set(name, [node, cost]);
|
||||
return [[node, cost]];
|
||||
const m = RATE_RE.exec(extra.식.replace(/\s+/g, ""));
|
||||
if (m) {
|
||||
const base = m[1] as Cost;
|
||||
const ref: ItemRef = { what: "비율", base, into: cost };
|
||||
const node = b.node("item", extra.이름, 3, JSON.stringify(ref), false);
|
||||
b.sheet(node).칸.B1 = { 값: Number(m[2]) }; // 율 — Item 이 이 칸을 살림
|
||||
layout(b, node, ref);
|
||||
return [node, cost];
|
||||
}
|
||||
const node = b.node("item", extra.이름, 3);
|
||||
const at = put({ ...sc, here: node }, "금액", extra.식, "out", extra.출처 ?? "");
|
||||
b.out(node, "단가", { 식: at });
|
||||
b.out(node, cost, { 식: at });
|
||||
b.out(node, "사용 수량", { 값: 1 });
|
||||
return [node, cost];
|
||||
}
|
||||
|
||||
type Cut = { 대상?: string; 자리?: number; 방법?: string };
|
||||
@@ -598,8 +636,10 @@ export function importLogicReport(row: LogicRow, opts: SlImportOptions = {}): Sl
|
||||
b.pill(result, "out", { name: t("Result"), cell: at, unit: row.결과단위 });
|
||||
} else {
|
||||
const lines = new Map<string, [SlNode, string]>();
|
||||
for (const h of row.호표 ?? [])
|
||||
if (typeof h.요소 === "string" && h.이름 && !b.names.has(h.요소)) b.names.set(h.요소, h.이름);
|
||||
const outs = (row.호표 ?? []).flatMap((item) => itemBox(b, item, lines));
|
||||
// 항목 합 — 덧줄이 「노무비」 등으로 부르는 호표 줄 비목 합
|
||||
// 항목 합 — 식 덧줄이 「노무비」 등으로 부르는 앞 줄까지의 비목 합
|
||||
const sum = b.node("calc", t("Sum"), 3);
|
||||
const costs = {} as Record<Cost, [SlNode, string][]>;
|
||||
for (const k of COSTS) {
|
||||
@@ -608,27 +648,32 @@ export function importLogicReport(row: LogicRow, opts: SlImportOptions = {}): Sl
|
||||
costs[k] = [[sum, k]];
|
||||
}
|
||||
const extras = new Map<string, [SlNode, string]>();
|
||||
const into: [SlNode, Cost][] = [...outs];
|
||||
for (const extra of row.덧줄 ?? []) {
|
||||
const cost = (
|
||||
(COSTS as readonly string[]).includes(extra.비목 ?? "") ? extra.비목 : "경비"
|
||||
) as Cost;
|
||||
const node = b.node("item", extra.이름, 3, "비율");
|
||||
put({ b, here: node, costs, extras, lines }, cost, extra.식, "out", extra.출처 ?? "");
|
||||
const [node, cost] = extraBox(b, extra, { b, costs, extras, lines });
|
||||
extras.set(extra.이름, [node, cost]);
|
||||
costs[cost] = [...costs[cost], [node, cost]];
|
||||
into.push([node, cost]);
|
||||
}
|
||||
const total: string[] = [];
|
||||
// 결과 = Model 결과 틀 — B2~B4 노무비 · 재료비 · 경비 입력 알약(선이 여럿이면 +) · B5 계
|
||||
for (const k of COSTS) {
|
||||
const refs = costs[k].map(([n, c]) => b.link(result, n, c));
|
||||
const at = b.out(result, k, {
|
||||
식: cutText(row, "계", refs.length > 1 ? `SUM(${refs.join(",")})` : refs[0]),
|
||||
});
|
||||
total.push(at);
|
||||
const at = b.row(result, k, {});
|
||||
b.pill(result, "in", { name: k, cell: at });
|
||||
const refs = into
|
||||
.filter(([, c]) => c === k)
|
||||
.map(([n]) => {
|
||||
const src = n.pillsOut.find((p) => p.name === k)!;
|
||||
const to = { node: result.id, pill: k };
|
||||
b.edges.push({ id: `e${b.edges.length + 1}`, from: { node: n.id, pill: k }, to });
|
||||
return `${quoteSheet(b.sheet(n).이름)}!${src.cell}`;
|
||||
});
|
||||
if (refs.length) b.sheet(result).칸[at] = { 식: refs.join("+") };
|
||||
}
|
||||
b.out(result, "계", { 식: `SUM(${total.join(",")})` }, row.결과단위);
|
||||
const parts = COSTS.map((_, i) => cutText(row, "계", `B${2 + i}`));
|
||||
b.out(result, "계", { 식: parts.join("+") }, row.결과단위);
|
||||
}
|
||||
b.book.활성 = b.book.시트[0]?.id;
|
||||
const sl: SheetLogic = {
|
||||
const built: SheetLogic = {
|
||||
key: null,
|
||||
name: row.이름,
|
||||
resultUnit: row.결과단위,
|
||||
@@ -636,6 +681,8 @@ export function importLogicReport(row: LogicRow, opts: SlImportOptions = {}): Sl
|
||||
nodes: b.nodes,
|
||||
edges: b.edges,
|
||||
};
|
||||
// 비율 항목 바탕 = Item 과 같은 셈(다른 항목 상자의 그 비목 합 · 선 함께)
|
||||
const sl = refreshBases(built);
|
||||
return { sl, problems: b.problems };
|
||||
}
|
||||
|
||||
@@ -644,48 +691,4 @@ export function importLogic(row: LogicRow, opts: SlImportOptions = {}): SheetLog
|
||||
return importLogicReport(row, opts).sl;
|
||||
}
|
||||
|
||||
/** 칸 값 — 서버 · 화면 계산값이 있으면 그것 · 아니면 넣은 값 */
|
||||
function valueAt(sl: SheetLogic, sheetId: string, cell: string, calc?: CalcValues): unknown {
|
||||
const got = calc?.[sheetId]?.[cell];
|
||||
if (got && "수" in got) return Number(got.수);
|
||||
if (got && "글" in got) return got.글;
|
||||
if (got && "참" in got) return got.참;
|
||||
return sl.workbook.시트.find((s) => s.id === sheetId)?.칸[cell]?.값 ?? null;
|
||||
}
|
||||
|
||||
/** 바깥 값 자리(`M01_SL_Api` 모양) — 넘길 입력값은 지금 칸 값(`calc` 가 있으면 그 값)으로 */
|
||||
export function outsideOf(sl: SheetLogic, calc?: CalcValues): SlOutsideAt[] {
|
||||
const out: SlOutsideAt[] = [];
|
||||
for (const node of sl.nodes) {
|
||||
const passed: Record<string, unknown> = {};
|
||||
const outside = [...node.pillsIn, ...node.pillsOut].filter((p) => p.outside);
|
||||
const sheet = sl.workbook.시트.find((s) => s.id === node.sheetId);
|
||||
for (const p of node.pillsIn) {
|
||||
const note = sheet?.칸[`C${p.cell.slice(1)}`]?.값;
|
||||
if (node.kind !== "table" && TEXT.Pass.includes(note as never))
|
||||
passed[p.name] = valueAt(sl, node.sheetId, p.cell, calc);
|
||||
}
|
||||
const ref = node.ref ?? "";
|
||||
for (const p of outside) {
|
||||
const id = `${node.id}:${p.name}`;
|
||||
const field = (["노무비", "재료비", "경비", "계"] as string[]).includes(p.name)
|
||||
? (p.name as SlField)
|
||||
: undefined;
|
||||
let item: SlOutside;
|
||||
if (node.kind === "table") item = { id, kind: "표", table: ref };
|
||||
else if (
|
||||
node.kind === "logic" ||
|
||||
ref.startsWith("GF") ||
|
||||
ref.startsWith("GC") ||
|
||||
ref.startsWith("GX")
|
||||
)
|
||||
item = { id, kind: "로직", key: ref, inputs: passed, ...(field ? { field } : {}) };
|
||||
else if (ref.startsWith("로직("))
|
||||
item = { id, kind: "장비", element: ref, inputs: passed, ...(field ? { field } : {}) };
|
||||
else if (ref.startsWith("LB")) item = { id, kind: "노임", key: ref };
|
||||
else item = { id, kind: "자재", key: ref };
|
||||
out.push({ item, sheet: node.sheetId, cell: p.cell });
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
export { outsideOf } from "./M01_SL_Import_Parse";
|
||||
|
||||
@@ -3,10 +3,15 @@
|
||||
* 시트 로직 가져오기 — 엔진 문법(`master_formula._Parser`)으로 로직 식 글 읽기 · 나무 → `M01_SL_Import.ts` 가 엑셀 수식으로
|
||||
* 꼴 = 수 · '글' · 이름 · 찾기(표, 가=나).칸 · 로직(키, 가=나).칸 · 만약/최소/최대/올림/버림/반올림 · 키:… 요소 ·
|
||||
* - · * / · + - · 비교 · 그리고 · 또는 · 못 읽으면 null
|
||||
* 아래 끝 = 품셈 표 → 시트 칸 놓기(조건 칸 → 값 칸 · 범위는 아래 · 위 두 칸) — 바깥 값 「표」 모양과 같음
|
||||
* 아래 = 품셈 표 → 시트 칸 놓기(조건 칸 → 값 칸 · 범위는 아래 · 위 두 칸 — 바깥 값 「표」 모양과 같음) ·
|
||||
* 바깥 값 자리(`outsideOf`)
|
||||
* ========================================================================== */
|
||||
|
||||
import { currentLanguageIndex } from "@ui/ui_template_locale";
|
||||
import type { CalcValues } from "../../A00_Common/spreadsheet/spreadsheet_types";
|
||||
import type { SheetLogic, SlNode } from "./M01_SL_Model";
|
||||
import type { SlField, SlOutside, SlOutsideAt } from "./M01_SL_Api";
|
||||
import { itemRefOf, type ItemRef } from "./M01_SL_Item";
|
||||
|
||||
export type Ast =
|
||||
| { t: "num"; v: string }
|
||||
@@ -184,3 +189,85 @@ export function tableRows(table: SlImportTable): (string | number | null)[][] {
|
||||
};
|
||||
return [cols.map((c) => c.head), ...table.줄.map((r) => cols.map((c) => one(r[c.key], c.part)))];
|
||||
}
|
||||
|
||||
/* ── 바깥 값 자리 ─────────────────────────────────────────────────────────── */
|
||||
|
||||
/** 넘길 값 칸 표시(C 칸) — `M01_SL_Import` TEXT.Pass 한 · 영 */
|
||||
const PASS = ["넘길 값", "Passed value"];
|
||||
const COST3 = ["노무비", "재료비", "경비"] as const;
|
||||
|
||||
/** 칸 값 — 서버 · 화면 계산값이 있으면 그것 · 아니면 넣은 값 */
|
||||
function valueAt(sl: SheetLogic, sheetId: string, cell: string, calc?: CalcValues): unknown {
|
||||
const got = calc?.[sheetId]?.[cell];
|
||||
if (got && "수" in got) return Number(got.수);
|
||||
if (got && "글" in got) return got.글;
|
||||
if (got && "참" in got) return got.참;
|
||||
return sl.workbook.시트.find((s) => s.id === sheetId)?.칸[cell]?.값 ?? null;
|
||||
}
|
||||
|
||||
/** 바깥 값 자리(`M01_SL_Api` 모양) — 넘길 입력값은 지금 칸 값(`calc` 가 있으면 그 값)으로 */
|
||||
export function outsideOf(sl: SheetLogic, calc?: CalcValues): SlOutsideAt[] {
|
||||
const out: SlOutsideAt[] = [];
|
||||
for (const node of sl.nodes) {
|
||||
const passed: Record<string, unknown> = {};
|
||||
const outside = [...node.pillsIn, ...node.pillsOut].filter((p) => p.outside);
|
||||
const sheet = sl.workbook.시트.find((s) => s.id === node.sheetId);
|
||||
for (const p of node.pillsIn) {
|
||||
const note = sheet?.칸[`C${p.cell.slice(1)}`]?.값;
|
||||
if (node.kind !== "table" && PASS.includes(String(note)))
|
||||
passed[p.name] = valueAt(sl, node.sheetId, p.cell, calc);
|
||||
}
|
||||
const ref = node.ref ?? "";
|
||||
const item = itemRefOf(node);
|
||||
if (item) {
|
||||
out.push(...itemOutside(node, item));
|
||||
continue;
|
||||
}
|
||||
for (const p of outside) {
|
||||
const id = `${node.id}:${p.name}`;
|
||||
const field = (["노무비", "재료비", "경비", "계"] as string[]).includes(p.name)
|
||||
? (p.name as SlField)
|
||||
: undefined;
|
||||
let item: SlOutside;
|
||||
if (node.kind === "table") item = { id, kind: "표", table: ref };
|
||||
else if (
|
||||
node.kind === "logic" ||
|
||||
ref.startsWith("GF") ||
|
||||
ref.startsWith("GC") ||
|
||||
ref.startsWith("GX")
|
||||
)
|
||||
item = { id, kind: "로직", key: ref, inputs: passed, ...(field ? { field } : {}) };
|
||||
else if (ref.startsWith("로직("))
|
||||
item = { id, kind: "장비", element: ref, inputs: passed, ...(field ? { field } : {}) };
|
||||
else if (ref.startsWith("LB")) item = { id, kind: "노임", key: ref };
|
||||
else item = { id, kind: "자재", key: ref };
|
||||
out.push({ item, sheet: node.sheetId, cell: p.cell });
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/** 항목 상자 바깥 값 — Item `itemOutsides` 와 같은 칸 · 자재 검색어 묶음은 key = 묶음 JSON 글(서버가 「{」 로 풂) */
|
||||
function itemOutside(node: SlNode, ref: ItemRef): SlOutsideAt[] {
|
||||
const at = (cell: string, item: SlOutside): SlOutsideAt => ({ item, sheet: node.sheetId, cell });
|
||||
const id = (f: string): string => `${node.id}:${f}`;
|
||||
const el = ref.element;
|
||||
const inputs = ref.inputs ?? {};
|
||||
if (ref.what === "노무") return [at("B2", { id: id("노무비"), kind: "노임", key: String(el) })];
|
||||
if (ref.what === "재료") {
|
||||
const keyed = typeof el === "object" && el !== null && "키" in el;
|
||||
const key = keyed ? String((el as { 키: unknown }).키) : JSON.stringify(el);
|
||||
return [at("B3", { id: id("재료비"), kind: "자재", key })];
|
||||
}
|
||||
if (ref.what === "비율") return [];
|
||||
const text = String(el);
|
||||
const key = /로직\(\s*([A-Z]{2}\d{6})/.exec(text)?.[1] ?? "";
|
||||
return COST3.map((f, i) =>
|
||||
at(
|
||||
`B${2 + i}`,
|
||||
ref.what === "장비"
|
||||
? { id: id(f), kind: "장비", element: text, inputs, field: f }
|
||||
: { id: id(f), kind: "로직", key, inputs, field: f },
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
|
||||
import { currentLanguageIndex } from "@ui/ui_template_locale";
|
||||
import { createButton, createSelectField, el } from "@ui/ui_template_elements";
|
||||
import { quoteSheet } from "../../A00_Common/spreadsheet/spreadsheet_address";
|
||||
import type { Cell, Sheet } from "../../A00_Common/spreadsheet/spreadsheet_types";
|
||||
import type { LogicInput } from "../M01_MasterData_UI_Logic_Api";
|
||||
import { searchElements } from "../M01_MasterData_UI_Logic_Api";
|
||||
@@ -18,7 +17,7 @@ import { formatPrice } from "../M01_MasterData_UI_Logic_Money";
|
||||
import { openEasyPick } from "../EasyCalc/M01_EasyCalc_Pick";
|
||||
import type { PickResult } from "../EasyCalc/M01_EasyCalc_Model";
|
||||
import { slOutside, slPlain, type SlField, type SlOutside, type SlOutsideAt } from "./M01_SL_Api";
|
||||
import type { SheetLogic, SlNode, SlPill } from "./M01_SL_Model";
|
||||
import { connect, disconnect, type SheetLogic, type SlNode, type SlPill } from "./M01_SL_Model";
|
||||
import "./M01_SL_Item.css";
|
||||
|
||||
const TEXT = {
|
||||
@@ -265,6 +264,16 @@ const FIELD_CELL: Record<string, string> = {
|
||||
};
|
||||
|
||||
/** 상자 시트를 항목 틀로 채움 — 예전 수량 칸(값 · 이어진 참조)은 살림 */
|
||||
/** 상자 시트를 항목 틀로 채움 — 가져오기(Import)도 이 틀 · ref 로 맞춤 */
|
||||
export function applyItemLayout(
|
||||
sl: SheetLogic,
|
||||
node: SlNode,
|
||||
ref: ItemRef,
|
||||
qty?: number | null,
|
||||
): SheetLogic {
|
||||
return applyLayout(sl, node, ref, qty);
|
||||
}
|
||||
|
||||
function applyLayout(sl: SheetLogic, node: SlNode, ref: ItemRef, qty?: number | null): SheetLogic {
|
||||
const sheet = sheetOf(sl, node);
|
||||
const oldRef = itemRefOf(node);
|
||||
@@ -299,39 +308,35 @@ function applyLayout(sl: SheetLogic, node: SlNode, ref: ItemRef, qty?: number |
|
||||
};
|
||||
}
|
||||
|
||||
/** 비율 상자마다 「바탕」 = 다른 항목 상자의 그 비목 합 — 시트 사이 참조 · 선도 함께 */
|
||||
/** 비율 상자마다 「바탕」 = 다른 항목 상자의 그 비목 출력 — 선 잇기(Model `connect`)로 함
|
||||
* · 아는 항목 상자(ref 가 이 틀 것)만 바탕이 됨 — 모르는 상자(가져온 것 등)는 읽지도 쓰지도 않음
|
||||
* · 비목을 바꾸면 옛 비목 선만 끊음 — 손으로 이은 다른 선 · 그 칸 수식은 그대로 */
|
||||
export function refreshBases(sl: SheetLogic): SheetLogic {
|
||||
let out = sl;
|
||||
for (const node of sl.nodes) {
|
||||
const ref = itemRefOf(node);
|
||||
if (!ref || ref.what !== "비율") continue;
|
||||
if (!ref || ref.what !== "비율" || !node.pillsIn.some((p) => p.name === PILL_BASE)) continue;
|
||||
const base = ref.base ?? "노무비";
|
||||
const sources = out.nodes.filter((n) => {
|
||||
const known = (n: SlNode): boolean => {
|
||||
const r = itemRefOf(n);
|
||||
return n.kind === "item" && r && r.what !== "비율";
|
||||
});
|
||||
const refs = sources
|
||||
.map((n) => {
|
||||
const s = sheetOf(out, n);
|
||||
return s ? `${quoteSheet(s.이름)}!${costCell(itemRefOf(n)!, base)}` : "";
|
||||
})
|
||||
.filter(Boolean);
|
||||
const formula = refs.length ? refs.join("+") : "0";
|
||||
out = editSheet(out, node, (cells) => {
|
||||
cells[RATE.base] = refs.length ? calc(formula) : num(0);
|
||||
});
|
||||
const mine = (id: string): boolean => id.startsWith(`e-base-${node.id}-`);
|
||||
out = {
|
||||
...out,
|
||||
edges: [
|
||||
...out.edges.filter((e) => !mine(e.id)),
|
||||
...sources.map((n) => ({
|
||||
id: `e-base-${node.id}-${n.id}`,
|
||||
from: { node: n.id, pill: base },
|
||||
to: { node: node.id, pill: PILL_BASE },
|
||||
})),
|
||||
],
|
||||
return n.id !== node.id && n.kind === "item" && !!r && r.what !== "비율";
|
||||
};
|
||||
for (const e of out.edges.filter((x) => x.to.node === node.id && x.to.pill === PILL_BASE)) {
|
||||
const from = out.nodes.find((n) => n.id === e.from.node);
|
||||
if (from && known(from) && e.from.pill !== base && (COSTS as string[]).includes(e.from.pill))
|
||||
out = disconnect(out, e.id);
|
||||
}
|
||||
for (const src of out.nodes.filter(known)) {
|
||||
const there = out.edges.some(
|
||||
(e) =>
|
||||
e.from.node === src.id &&
|
||||
e.from.pill === base &&
|
||||
e.to.node === node.id &&
|
||||
e.to.pill === PILL_BASE,
|
||||
);
|
||||
if (!there)
|
||||
out = connect(out, { node: src.id, pill: base }, { node: node.id, pill: PILL_BASE }).sl;
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
.m01-sllogic__title {
|
||||
color: var(--color-text-body);
|
||||
font-size: var(--text-body);
|
||||
}
|
||||
|
||||
.m01-sllogic__chosen {
|
||||
margin: var(--spacing-4) 0;
|
||||
color: var(--color-text-body);
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.m01-sllogic__search {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
gap: var(--spacing-8);
|
||||
margin: var(--spacing-8) 0;
|
||||
}
|
||||
|
||||
.m01-sllogic__input {
|
||||
box-sizing: border-box;
|
||||
width: 200px;
|
||||
max-width: 100%;
|
||||
height: var(--control-height-sm);
|
||||
padding: 3px 6px;
|
||||
border: 1px solid var(--color-border);
|
||||
border-radius: var(--radius-sm);
|
||||
background: var(--color-canvas);
|
||||
color: var(--color-text-body);
|
||||
font: inherit;
|
||||
font-size: var(--text-body-sm);
|
||||
}
|
||||
|
||||
.m01-sllogic__input[readonly] {
|
||||
background: var(--color-surface);
|
||||
}
|
||||
|
||||
.m01-sllogic__list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: var(--spacing-4);
|
||||
max-height: 240px;
|
||||
margin: 0 0 var(--spacing-8);
|
||||
padding: 0;
|
||||
overflow: auto;
|
||||
list-style: none;
|
||||
}
|
||||
|
||||
.m01-sllogic__list .ui-btn {
|
||||
max-width: 100%;
|
||||
text-align: left;
|
||||
white-space: normal;
|
||||
}
|
||||
|
||||
.m01-sllogic__fields {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: flex-end;
|
||||
gap: var(--spacing-8) var(--spacing-16);
|
||||
margin: var(--spacing-8) 0;
|
||||
color: var(--color-text-body);
|
||||
}
|
||||
|
||||
.m01-sllogic__fields > strong,
|
||||
.m01-sllogic__fields > .m01-sllogic__muted {
|
||||
flex-basis: 100%;
|
||||
}
|
||||
|
||||
.m01-sllogic__field {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: var(--spacing-4);
|
||||
color: var(--color-text-secondary);
|
||||
font-size: var(--text-body-sm);
|
||||
}
|
||||
|
||||
.m01-sllogic__muted {
|
||||
margin: 0;
|
||||
color: var(--color-text-muted);
|
||||
font-size: var(--text-caption);
|
||||
}
|
||||
|
||||
.m01-sllogic__msg {
|
||||
margin: var(--spacing-4) 0 0;
|
||||
color: var(--color-danger);
|
||||
font-size: var(--text-caption);
|
||||
}
|
||||
@@ -0,0 +1,297 @@
|
||||
/* =============================================================================
|
||||
* M01_SL_LogicTools.ts
|
||||
* 시트 로직 — 「다른 로직」 상자 손잡이. 기존 로직을 찾아 고르면 상자 시트를 그 로직의 틀로 채움
|
||||
* 로직의 입력값마다 입력 알약(「넘길 값」 줄 · 예시값) · 결과는 바깥 값 출력 알약
|
||||
* 돈 로직 = 노무비 · 재료비 · 경비 · 계 / 돈 아닌 로직(작업량 등) = 결과
|
||||
* 틀 모양은 Import 의 다른 로직 상자와 한 벌(`outsideOf` 가 「넘길 값」 칸과 알약 이름으로 물음을 만듦)
|
||||
* — 상자 `source` 는 안 씀: 한 상자에 비목별 물음이 여럿이라 알약 이름이 비목을 정함. 상자 `ref` = 로직 번호.
|
||||
* 모양은 docs/raw/M01_쉬운단가/시트로직_정함.md 3 · 4. 이 폴더째 지워도 됨.
|
||||
* ========================================================================== */
|
||||
|
||||
import { currentLanguageIndex } from "@ui/ui_template_locale";
|
||||
import { createButton, createSelectField, el } from "@ui/ui_template_elements";
|
||||
import type { Cell } from "../../A00_Common/spreadsheet/spreadsheet_types";
|
||||
import type { LogicInput, LogicRow } from "../M01_MasterData_UI_Logic_Api";
|
||||
import { listEasy, openEasy, type EasyListItem } from "../EasyCalc/M01_EasyCalc_Api";
|
||||
import { slPlain } from "./M01_SL_Api";
|
||||
import { disconnect, renameNode, type SheetLogic, type SlNode, type SlPill } from "./M01_SL_Model";
|
||||
import "./M01_SL_LogicTools.css";
|
||||
|
||||
const TEXT = {
|
||||
Title: ["다른 로직", "Other logic"],
|
||||
Search: ["로직 이름 찾기", "Find a logic by name"],
|
||||
Find: ["찾기", "Find"],
|
||||
None: ["아직 고르지 않았어요", "Nothing chosen yet"],
|
||||
Chosen: ["고른 로직", "Chosen logic"],
|
||||
NoHit: ["찾은 로직이 없어요", "No logic found"],
|
||||
More: ["더 있어요 — 이름을 더 적어 보세요", "More exist — type more of the name"],
|
||||
Loading: ["가져오는 중", "Loading"],
|
||||
Inputs: ["넘길 값", "Passed values"],
|
||||
NoInputs: ["넘길 값이 없는 로직이에요", "This logic takes no values"],
|
||||
Linked: ["다른 상자에서 이어진 값", "Value from another box"],
|
||||
Pick: ["고르세요", "Choose"],
|
||||
Bad: ["숫자를 넣어 주세요", "Enter a number"],
|
||||
Hint: [
|
||||
"결과는 바깥 값 — 열 때 · 저장 때 넣어요",
|
||||
"Result is an outside value — filled on open and save",
|
||||
],
|
||||
Result: ["결과", "Result"],
|
||||
Labor: ["노무비", "Labor cost"],
|
||||
Material: ["재료비", "Material cost"],
|
||||
Expense: ["경비", "Expense"],
|
||||
Sum: ["계", "Total"],
|
||||
Name: ["이름", "Name"],
|
||||
Value: ["값", "Value"],
|
||||
Note: ["설명", "Note"],
|
||||
Pass: ["넘길 값", "Passed value"],
|
||||
Outside: ["바깥 값 — 열 때 · 저장 때 넣음", "Outside value — filled on open and save"],
|
||||
} as const;
|
||||
|
||||
type TextKey = keyof typeof TEXT;
|
||||
const tt = (key: TextKey): string => TEXT[key][currentLanguageIndex === 1 ? 1 : 0];
|
||||
|
||||
const LIMIT = 30;
|
||||
|
||||
/** 로직 결과가 돈인가 */
|
||||
const isMoney = (unit: string): boolean => unit.startsWith("원");
|
||||
|
||||
/** 상자 시트를 다른 로직 틀로 채움 · `trial` = 입력값 예시(열 때 받은 자동값) */
|
||||
export function applyLogic(
|
||||
sl: SheetLogic,
|
||||
nodeId: string,
|
||||
row: LogicRow,
|
||||
trial: Record<string, unknown> = {},
|
||||
): SheetLogic {
|
||||
const node = sl.nodes.find((n) => n.id === nodeId);
|
||||
if (!node) return sl;
|
||||
if (node.ref === row.키 && node.pillsIn.length) return sl; // 같은 로직을 또 고름 — 그대로
|
||||
// 다른 로직을 고르면 옛 선은 끊음(받는 칸 수식도 함께 정리)
|
||||
let work = sl;
|
||||
for (const e of sl.edges)
|
||||
if (e.from.node === nodeId || e.to.node === nodeId) work = disconnect(work, e.id);
|
||||
for (const name of [row.이름, `${row.이름} 2`, `${row.이름} 3`]) {
|
||||
const got = renameNode(work, nodeId, name);
|
||||
if (!got.why) {
|
||||
work = got.sl;
|
||||
break;
|
||||
}
|
||||
}
|
||||
const cells: Record<string, Cell> = {
|
||||
A1: { 값: tt("Name") },
|
||||
B1: { 값: tt("Value") },
|
||||
C1: { 값: tt("Note") },
|
||||
};
|
||||
const pillsIn: SlPill[] = [];
|
||||
const pillsOut: SlPill[] = [];
|
||||
let r = 2;
|
||||
for (const spec of row.입력 ?? []) {
|
||||
const at = `B${r}`;
|
||||
cells[`A${r}`] = { 값: spec.이름 };
|
||||
const v = trial[spec.이름];
|
||||
if (typeof v === "number" || typeof v === "string") cells[at] = { 값: v };
|
||||
cells[`C${r}`] = { 값: tt("Pass") };
|
||||
pillsIn.push({ name: spec.이름, cell: at, ...(spec.단위 ? { unit: spec.단위 } : {}) });
|
||||
r++;
|
||||
}
|
||||
const unit = row.결과단위 ?? "";
|
||||
const money = isMoney(unit);
|
||||
const outs = money ? [tt("Labor"), tt("Material"), tt("Expense"), tt("Sum")] : [tt("Result")];
|
||||
for (const name of outs) {
|
||||
const at = `B${r}`;
|
||||
cells[`A${r}`] = { 값: name };
|
||||
cells[`C${r}`] = { 값: tt("Outside") };
|
||||
pillsIn.push({ name, cell: at, outside: true });
|
||||
pillsOut.push({ name, cell: at, unit: money ? "원" : unit });
|
||||
r++;
|
||||
}
|
||||
const 시트 = work.workbook.시트.map((s) => (s.id === node.sheetId ? { ...s, 칸: cells } : s));
|
||||
return {
|
||||
...work,
|
||||
workbook: { ...work.workbook, 시트 },
|
||||
nodes: work.nodes.map((n) => {
|
||||
if (n.id !== nodeId) return n;
|
||||
const next: SlNode = { ...n, ref: row.키, pillsIn, pillsOut, stage: 1 };
|
||||
delete next.source;
|
||||
return next;
|
||||
}),
|
||||
};
|
||||
}
|
||||
|
||||
/** 그 로직의 입력 설명(고르기 · 범위) — 한 번 받은 것은 다시 안 받음 */
|
||||
const rows = new Map<string, LogicRow>();
|
||||
|
||||
/** 다른 로직 상자 손잡이 — 찾기 → 고르기 → 넘길 값 칸 */
|
||||
export function renderLogicTools(
|
||||
host: HTMLElement,
|
||||
sl: SheetLogic,
|
||||
nodeId: string,
|
||||
on: { change(sl: SheetLogic): void },
|
||||
): void {
|
||||
const node = sl.nodes.find((n) => n.id === nodeId);
|
||||
const msg = el("p", { className: "m01-sllogic__msg" });
|
||||
if (!node) {
|
||||
host.replaceChildren();
|
||||
return;
|
||||
}
|
||||
const sheet = sl.workbook.시트.find((s) => s.id === node.sheetId);
|
||||
const results = el("ul", { className: "m01-sllogic__list" });
|
||||
const fieldsHost = el("div", { className: "m01-sllogic__fields" });
|
||||
const box = el("input", {
|
||||
className: "m01-sllogic__input",
|
||||
attrs: { type: "text", placeholder: tt("Search"), "aria-label": tt("Search") },
|
||||
});
|
||||
|
||||
const emit = (make: () => SheetLogic): void => {
|
||||
msg.textContent = "";
|
||||
try {
|
||||
on.change(make());
|
||||
} catch (e) {
|
||||
msg.textContent = slPlain(e);
|
||||
}
|
||||
};
|
||||
|
||||
const choose = async (item: EasyListItem): Promise<void> => {
|
||||
msg.textContent = tt("Loading");
|
||||
try {
|
||||
const opened = await openEasy(item.key);
|
||||
rows.set(item.key, opened.row);
|
||||
msg.textContent = "";
|
||||
on.change(applyLogic(sl, node.id, opened.row, opened.trial));
|
||||
} catch (e) {
|
||||
msg.textContent = slPlain(e);
|
||||
}
|
||||
};
|
||||
|
||||
const search = async (): Promise<void> => {
|
||||
msg.textContent = tt("Loading");
|
||||
try {
|
||||
const found = await listEasy(box.value.trim());
|
||||
msg.textContent = "";
|
||||
results.replaceChildren(
|
||||
...(found.length
|
||||
? found.slice(0, LIMIT).map((it) => {
|
||||
const b = createButton({
|
||||
label: `${it.name} · ${it.resultUnit}${it.where ? ` · ${it.where}` : ""}`,
|
||||
variant: "ghost",
|
||||
size: "sm",
|
||||
onClick: () => void choose(it),
|
||||
});
|
||||
return el("li", { children: [b] });
|
||||
})
|
||||
: [el("li", { className: "m01-sllogic__muted", text: tt("NoHit") })]),
|
||||
...(found.length > LIMIT
|
||||
? [el("li", { className: "m01-sllogic__muted", text: tt("More") })]
|
||||
: []),
|
||||
);
|
||||
} catch (e) {
|
||||
msg.textContent = slPlain(e);
|
||||
}
|
||||
};
|
||||
box.addEventListener("keydown", (ev) => {
|
||||
if (ev.key === "Enter") void search();
|
||||
});
|
||||
|
||||
/** 넘길 값 칸 — 고르기가 있으면 고르기 · 아니면 숫자 · 다른 상자에서 이어진 칸은 읽기만 */
|
||||
const fieldFor = (pill: SlPill, spec: LogicInput | undefined): HTMLElement => {
|
||||
const cur = sheet?.칸[pill.cell];
|
||||
const linked = cur?.식 !== undefined;
|
||||
const put = (v: number | string): void =>
|
||||
emit(() => ({
|
||||
...sl,
|
||||
workbook: {
|
||||
...sl.workbook,
|
||||
시트: sl.workbook.시트.map((s) =>
|
||||
s.id === node.sheetId ? { ...s, 칸: { ...s.칸, [pill.cell]: { 값: v } } } : s,
|
||||
),
|
||||
},
|
||||
}));
|
||||
const label = el("span", { text: pill.unit ? `${pill.name} (${pill.unit})` : pill.name });
|
||||
let control: HTMLElement;
|
||||
if (spec?.고르기?.length && !linked) {
|
||||
control = createSelectField({
|
||||
options: [
|
||||
{ value: "", text: tt("Pick") },
|
||||
...spec.고르기.map((o) => ({ value: String(o), text: String(o) })),
|
||||
],
|
||||
value: cur?.값 === undefined ? "" : String(cur.값),
|
||||
compact: true,
|
||||
ariaLabel: pill.name,
|
||||
onChange: (v) => {
|
||||
const hit = spec.고르기?.find((o) => String(o) === v);
|
||||
if (hit !== undefined) put(hit);
|
||||
},
|
||||
}).root;
|
||||
} else {
|
||||
const input = el("input", {
|
||||
className: "m01-sllogic__input",
|
||||
attrs: { type: "text", inputmode: "decimal", "aria-label": pill.name },
|
||||
});
|
||||
if (spec?.범위) input.placeholder = `${spec.범위[0]} ∼ ${spec.범위[1]}`;
|
||||
input.value = linked || cur?.값 === undefined ? "" : String(cur.값);
|
||||
input.readOnly = linked;
|
||||
input.addEventListener("change", () => {
|
||||
const raw = input.value.trim();
|
||||
const n = Number(raw);
|
||||
if (raw === "") return;
|
||||
if (Number.isNaN(n)) msg.textContent = tt("Bad");
|
||||
else put(n);
|
||||
});
|
||||
control = input;
|
||||
}
|
||||
return el("label", {
|
||||
className: "m01-sllogic__field",
|
||||
children: [
|
||||
label,
|
||||
control,
|
||||
...(linked ? [el("small", { className: "m01-sllogic__muted", text: tt("Linked") })] : []),
|
||||
],
|
||||
});
|
||||
};
|
||||
|
||||
const drawFields = (row: LogicRow | undefined): void => {
|
||||
const passed = node.pillsIn.filter((p) => !p.outside);
|
||||
fieldsHost.replaceChildren(
|
||||
el("strong", { text: tt("Inputs") }),
|
||||
...(passed.length
|
||||
? passed.map((p) =>
|
||||
fieldFor(
|
||||
p,
|
||||
row?.입력?.find((i) => i.이름 === p.name),
|
||||
),
|
||||
)
|
||||
: [el("p", { className: "m01-sllogic__muted", text: tt("NoInputs") })]),
|
||||
el("p", { className: "m01-sllogic__muted", text: tt("Hint") }),
|
||||
);
|
||||
};
|
||||
|
||||
host.replaceChildren(
|
||||
el("strong", { className: "m01-sllogic__title", text: `${tt("Title")} · ${node.name}` }),
|
||||
el("p", {
|
||||
className: "m01-sllogic__chosen",
|
||||
text: node.ref ? `${tt("Chosen")}: ${node.name}` : tt("None"),
|
||||
}),
|
||||
el("div", {
|
||||
className: "m01-sllogic__search",
|
||||
children: [
|
||||
box,
|
||||
createButton({ label: tt("Find"), size: "sm", onClick: () => void search() }),
|
||||
],
|
||||
}),
|
||||
results,
|
||||
...(node.ref ? [fieldsHost] : []),
|
||||
msg,
|
||||
);
|
||||
if (node.ref) {
|
||||
const known = rows.get(node.ref);
|
||||
drawFields(known);
|
||||
if (!known) {
|
||||
void openEasy(node.ref).then(
|
||||
(o) => {
|
||||
rows.set(o.row.키, o.row);
|
||||
drawFields(o.row);
|
||||
},
|
||||
() => undefined,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -54,6 +54,8 @@
|
||||
.m01-slpanel-sheet {
|
||||
position: relative;
|
||||
min-height: 260px;
|
||||
/* 그 시트가 쓰는 줄 수만큼(Entry 가 --sl-sheet-h 를 정함) — 안쪽 세로 밀기 없음(사용자 요청) */
|
||||
height: var(--sl-sheet-h, 260px);
|
||||
border: 1px solid var(--color-border);
|
||||
border-radius: var(--radius-cards);
|
||||
overflow: hidden;
|
||||
|
||||
@@ -24,6 +24,7 @@ import "./M01_SL_Result.css";
|
||||
const TEXT = {
|
||||
Per: ["{per} 당", "per {per}"],
|
||||
Total: ["합계", "Total"],
|
||||
Value: ["결과값", "Result value"],
|
||||
Won: ["원", "KRW"],
|
||||
Labor: ["노무비", "Labor cost"],
|
||||
Material: ["재료비", "Material cost"],
|
||||
@@ -47,6 +48,7 @@ const tr = (key: TextKey, fill: Record<string, string> = {}): string =>
|
||||
TEXT[key][currentLanguageIndex].replace(/\{(\w+)\}/g, (m, k: string) => fill[k] ?? m);
|
||||
|
||||
const COSTS = ["노무비", "재료비", "경비"] as const;
|
||||
const num = (v: number): string => v.toLocaleString("ko-KR", { maximumFractionDigits: 6 });
|
||||
const n0 = (v: unknown): number => (typeof v === "number" && Number.isFinite(v) ? v : 0);
|
||||
|
||||
const sheetOf = (sl: SheetLogic, node: SlNode): Sheet | undefined =>
|
||||
@@ -157,13 +159,34 @@ export function renderResult(
|
||||
values: SlEvalResult,
|
||||
on: { change(sl: SheetLogic): void },
|
||||
): void {
|
||||
const money = !sl.resultUnit || sl.resultUnit.startsWith("원");
|
||||
const { 계 } = values.result;
|
||||
const per = sl.resultUnit.includes("/") ? sl.resultUnit.split("/").slice(1).join("/") : "";
|
||||
/** 돈이 아닌 결과(㎥/시간 …) — 결과 상자의 「계」 · 없으면 이어진 첫 숫자 */
|
||||
const plainValue = (): number | null => {
|
||||
const box = sl.nodes.find((n) => n.kind === "result");
|
||||
const ins = box ? Object.values(values.pillsIn[box.id] ?? {}) : [];
|
||||
const first = [계, ...COSTS.map((c) => values.result[c]), ...ins].find(
|
||||
(v) => typeof v === "number" && Number.isFinite(v),
|
||||
);
|
||||
return typeof first === "number" ? first : null;
|
||||
};
|
||||
const perUnit = sl.resultUnit.split("/").slice(1).join("/");
|
||||
const perText = !perUnit
|
||||
? tr("Total")
|
||||
: tr("Per", { per: /^\d/.test(perUnit) ? perUnit : `1${perUnit}` });
|
||||
const shown = money ? 계 : plainValue();
|
||||
const big = el("p", {
|
||||
className: "m01-slresult__big",
|
||||
children: [
|
||||
el("span", { text: per ? tr("Per", { per: `1${per}` }) : tr("Total") }),
|
||||
el("strong", { text: 계 === null ? "—" : `${formatMoney(계)} ${tr("Won")}` }),
|
||||
el("span", { text: money ? perText : tr("Value") }),
|
||||
el("strong", {
|
||||
text:
|
||||
shown === null
|
||||
? "—"
|
||||
: money
|
||||
? `${formatMoney(shown)} ${tr("Won")}`
|
||||
: `${num(shown)} ${sl.resultUnit}`.trim(),
|
||||
}),
|
||||
],
|
||||
});
|
||||
const costs = el("dl", {
|
||||
@@ -191,7 +214,7 @@ export function renderResult(
|
||||
middle: {},
|
||||
};
|
||||
const sheetHost = el("div", { className: "m01-slresult__sheet" });
|
||||
renderSheet(sheetHost, head, ans);
|
||||
if (money) renderSheet(sheetHost, head, ans);
|
||||
|
||||
const msg = el("p", { className: "m01-slresult__msg" });
|
||||
const put =
|
||||
@@ -225,7 +248,7 @@ export function renderResult(
|
||||
: [];
|
||||
host.replaceChildren(
|
||||
big,
|
||||
costs,
|
||||
...(money ? [costs] : []),
|
||||
...strip,
|
||||
...(problems.length
|
||||
? [
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/* =============================================================================
|
||||
* M01_SL_Table_Build.ts
|
||||
* 표 상자 짜기 — 표 한 벌 → 시트 칸(찾기용 열쇠 · 입력 칸 · 걸린 줄 · 상태 · 결과 칸 수식) · 알약 · 붙여넣기 읽기
|
||||
* 표 상자 짜기 — 표 한 벌 → 시트 칸(찾기용 합친 조건 · 입력 칸 · 걸린 줄 · 상태 · 결과 칸 수식) · 알약 · 붙여넣기 읽기
|
||||
* DOM 없음 · 서버 없음(시험이 Node 로 바로 돌림) · 화면 = `M01_SL_Table.ts`
|
||||
*
|
||||
* 시트 모양(표 상자 시트 하나):
|
||||
* A1 부터 = 표 블록(머리 줄 + 줄 · 범위 조건 「3~4」 는 「이름·아래」 「이름·위」 두 칸) — 품셈 표는 바깥 값이 채움
|
||||
* 빈 열 하나 건너 = 찾기용 열쇠 열(조건 칸을 「|」 로 이은 글 · 빈칸 = 무관 줄은 그 칸을 뺀 열쇠 열이 따로)
|
||||
* 다시 빈 열 하나 건너 = 찾기 판 — 입력(조건 칸마다) · 열쇠 · 일치 수 · 걸린 줄 · 상태 · 결과(결과 칸마다)
|
||||
* 빈 열 하나 건너 = 찾기용 합친 조건 열(조건 칸을 「|」 로 이은 글 · 빈칸 = 무관 줄은 그 칸을 뺀 합친 조건 열이 따로)
|
||||
* 다시 빈 열 하나 건너 = 찾기 판 — 입력(조건 칸마다) · 합친 조건 · 일치 수 · 걸린 줄 · 상태 · 결과(결과 칸마다)
|
||||
* 맞는 줄 없음 · 둘 이상이면 상태 칸이 글로 알리고 결과 칸은 #N/A
|
||||
* ========================================================================== */
|
||||
|
||||
@@ -58,7 +58,7 @@ export interface TblPlan {
|
||||
outCells: Record<string, string>;
|
||||
idxCell: string;
|
||||
statusCell: string;
|
||||
/** 찾기 판 왼쪽 첫 열(0 부터) — 이 열 앞 블록 · 열쇠 열은 다시 쓸 때 지움 */
|
||||
/** 찾기 판 왼쪽 첫 열(0 부터) — 이 열 앞 블록 · 합친 조건 열은 다시 쓸 때 지움 */
|
||||
helperFrom: number;
|
||||
warnings: string[];
|
||||
}
|
||||
@@ -74,7 +74,8 @@ const colIndex = (letters: string): number =>
|
||||
[...letters].reduce((n, ch) => n * 26 + ch.charCodeAt(0) - 64, 0) - 1;
|
||||
const at = (r: number, c: number): string => `${colName(c)}${r}`;
|
||||
|
||||
const MARGIN = 20;
|
||||
/** 표 줄이 늘어도 따라가도록 블록 아래로 여유 줄을 둠 — 줄 수 이상 · 최소 20 */
|
||||
const marginOf = (n: number): number => Math.max(20, n);
|
||||
const quote = (s: string): string => `"${s.replace(/"/g, '""')}"`;
|
||||
|
||||
/** 범위 칸인가 — 조건 칸이 「범위」 이거나 값 칸에 범위(배열) 줄이 하나라도 있으면(서버 표 블록과 같은 규칙) */
|
||||
@@ -148,16 +149,16 @@ export function planLookup(info: TblInfo, roles: TblRoles): TblPlan {
|
||||
warnings.push("범위 조건과 빈칸(무관)은 함께 못 씀 — 빈칸 줄은 맞지 않음");
|
||||
const rule = info.rule ?? "초과·이하";
|
||||
const lowBased = /이상·미만/.test(rule) || (/^이상/.test(rule) && !/초과/.test(rule));
|
||||
const R = (range ? n : n + MARGIN) + 1;
|
||||
const R = n + marginOf(n) + 1;
|
||||
const rng = (L: string): string => `${L}$2:${L}$${R}`;
|
||||
|
||||
// 열쇠 열 — 맨 앞은 모든 조건 칸 · 이어서 빈칸(무관) 변형들
|
||||
// 합친 조건 열 — 맨 앞은 모든 조건 칸 · 이어서 빈칸(무관) 변형들
|
||||
const variants: string[][] = [[]];
|
||||
if (!range) {
|
||||
const bl = blankable.slice(0, 2);
|
||||
const subsets =
|
||||
bl.length === 2 ? [[bl[0]], [bl[1]], [bl[0], bl[1]]] : bl.length === 1 ? [[bl[0]]] : [];
|
||||
variants.push(...subsets.filter((sub) => sub.length < exact.length)); // 모든 조건 칸이 빈칸인 변형은 열쇠가 없음
|
||||
variants.push(...subsets.filter((sub) => sub.length < exact.length)); // 모든 조건 칸이 빈칸인 변형은 합친 조건가 없음
|
||||
}
|
||||
const keyCols = exact.length ? variants : [];
|
||||
const kStart = W + 1;
|
||||
@@ -166,7 +167,9 @@ export function planLookup(info: TblInfo, roles: TblRoles): TblPlan {
|
||||
const V = L + 1;
|
||||
const cells: Record<string, Cell> = {};
|
||||
keyCols.forEach((skip, v) => {
|
||||
cells[at(1, kStart + v)] = { 값: skip.length ? `열쇠(${skip.join("·")} 무관)` : "열쇠" };
|
||||
cells[at(1, kStart + v)] = {
|
||||
값: skip.length ? `합친 조건(${skip.join("·")} 무관)` : "합친 조건",
|
||||
};
|
||||
const rest = exact.filter((c) => !skip.includes(c));
|
||||
for (let r = 2; r <= R; r++) {
|
||||
const key = rest.map((c) => `${letter(c)}${r}`).join('&"|"&');
|
||||
@@ -183,7 +186,9 @@ export function planLookup(info: TblInfo, roles: TblRoles): TblPlan {
|
||||
|
||||
// 찾기 판
|
||||
let row = 1;
|
||||
cells[at(row++, L)] = { 값: "표에서 찾기" };
|
||||
cells[at(row++, L)] = {
|
||||
값: ["표에서 찾기", info.name, info.no, info.base].filter(Boolean).join(" · "),
|
||||
};
|
||||
const inCells: Record<string, string> = {};
|
||||
const inputOf: Record<string, string> = {};
|
||||
for (const c of conds) {
|
||||
@@ -194,6 +199,14 @@ export function planLookup(info: TblInfo, roles: TblRoles): TblPlan {
|
||||
inputOf[c] = at(row, V);
|
||||
row++;
|
||||
}
|
||||
// 표 줄 수 — 블록 안 칸이 찬 줄 수(마스터 표 줄이 늘거나 줄어도 따라감)
|
||||
const rowsCell = ((): string => {
|
||||
cells[at(row, L)] = { 값: "표 줄 수" };
|
||||
cells[at(row, V)] = {
|
||||
식: `MAX(${cols.map((_, c) => `COUNTA(${rng(colName(c))})`).join(",")})`,
|
||||
};
|
||||
return at(row++, V);
|
||||
})();
|
||||
const keyOf = (skip: string[]): string =>
|
||||
exact
|
||||
.filter((c) => !skip.includes(c))
|
||||
@@ -210,10 +223,10 @@ export function planLookup(info: TblInfo, roles: TblRoles): TblPlan {
|
||||
let idx = "";
|
||||
let count = "";
|
||||
if (exact.length) {
|
||||
const keyCell = idxRow("열쇠", keyOf([]));
|
||||
const keyCell = idxRow("합친 조건", keyOf([]));
|
||||
const ks = keyCols.map((skip, v) => {
|
||||
if (v === 0) return keyCell;
|
||||
cells[at(row, L)] = { 값: `열쇠(${skip.join("·")} 무관)` };
|
||||
cells[at(row, L)] = { 값: `합친 조건(${skip.join("·")} 무관)` };
|
||||
cells[at(row, V)] = { 식: keyOf(skip) };
|
||||
return at(row++, V);
|
||||
});
|
||||
@@ -224,7 +237,7 @@ export function planLookup(info: TblInfo, roles: TblRoles): TblPlan {
|
||||
);
|
||||
count = idxRow(
|
||||
"일치 수",
|
||||
`IF(ISNUMBER(${idx}),IF(${idx}>${n},0,IF(AND(OR(ISBLANK(INDEX(${lo},${idx})),${x}>INDEX(${lo},${idx})),OR(ISBLANK(INDEX(${up},${idx})),${x}<=INDEX(${up},${idx}))),1,0)),0)`,
|
||||
`IF(ISNUMBER(${idx}),IF(${idx}>${rowsCell},0,IF(AND(OR(ISBLANK(INDEX(${lo},${idx})),${x}>INDEX(${lo},${idx})),OR(ISBLANK(INDEX(${up},${idx})),${x}<=INDEX(${up},${idx}))),1,0)),0)`,
|
||||
);
|
||||
} else {
|
||||
const found = ks.map((k, v) => `COUNTIF(${rng(kLetters[v])},${k})`);
|
||||
@@ -242,7 +255,7 @@ export function planLookup(info: TblInfo, roles: TblRoles): TblPlan {
|
||||
const inside = lowBased
|
||||
? `AND(OR(ISBLANK(INDEX(${lo},${idx})),${x}>=INDEX(${lo},${idx})),OR(ISBLANK(INDEX(${up},${idx})),${x}<INDEX(${up},${idx})))`
|
||||
: `AND(OR(ISBLANK(INDEX(${lo},${idx})),${x}>INDEX(${lo},${idx})),OR(ISBLANK(INDEX(${up},${idx})),${x}<=INDEX(${up},${idx})))`;
|
||||
count = idxRow("일치 수", `IF(AND(${idx}>=1,${idx}<=${n}),IF(${inside},1,0),0)`);
|
||||
count = idxRow("일치 수", `IF(AND(${idx}>=1,${idx}<=${rowsCell}),IF(${inside},1,0),0)`);
|
||||
} else {
|
||||
warnings.push("조건 칸이 없음 — 찾을 줄이 없음");
|
||||
count = idxRow("일치 수", "0");
|
||||
@@ -294,6 +307,21 @@ export function pillsOf(
|
||||
const sheetIndexOf = (sl: SheetLogic, node: SlNode): number =>
|
||||
sl.workbook.시트.findIndex((s) => s.id === node.sheetId);
|
||||
|
||||
/** 시트 이름을 바꿈 — 같은 이름이 있으면 번호를 붙이고 · 다른 시트가 이 시트를 가리키던 참조 수식도 따라 고침 */
|
||||
function renameSheet(sl: SheetLogic, sheet: Sheet, want: string): void {
|
||||
if (sheet.이름 === want) return;
|
||||
const taken = new Set(sl.workbook.시트.filter((s) => s !== sheet).map((s) => s.이름));
|
||||
let name = want;
|
||||
for (let i = 2; taken.has(name); i++) name = `${want} (${i})`;
|
||||
const quote = (n: string): string => `'${n.replace(/'/g, "''")}'`;
|
||||
const old = sheet.이름;
|
||||
const olds = [`${quote(old)}!`, ...(/^[\p{L}\p{N}_]+$/u.test(old) ? [`${old}!`] : [])];
|
||||
for (const s of sl.workbook.시트)
|
||||
for (const cell of Object.values(s.칸))
|
||||
if (cell.식) for (const o of olds) cell.식 = cell.식.split(o).join(`${quote(name)}!`);
|
||||
sheet.이름 = name;
|
||||
}
|
||||
|
||||
/** 표 상자에 표 · 찾기 판을 씀 — 새 시트 로직(받은 것은 안 바꿈) · `fillBlock` 이면 블록도 씀(내 표 · 시험) */
|
||||
export function applyTable(
|
||||
sl: SheetLogic,
|
||||
@@ -331,6 +359,7 @@ export function applyTable(
|
||||
!(e.to.node === nodeId && gone("in", e.to.pill)),
|
||||
);
|
||||
node.name = `표 · ${info.name}`;
|
||||
renameSheet(next, sheet, node.name);
|
||||
node.ref = opts.ref;
|
||||
node.pillsIn = pills.pillsIn;
|
||||
node.pillsOut = pills.pillsOut;
|
||||
|
||||
@@ -29,7 +29,7 @@ HOOKS = r"""
|
||||
import { readFileSync, existsSync } from "node:fs";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { stripTypeScriptTypes } from "node:module";
|
||||
const ALLOW = /(EasyCalc_(Model|Table|Cond)|M01_LB_Blocks|M01_SL_Import(_Parse)?|spreadsheet_(address|types))(\.ts)?$/;
|
||||
const ALLOW = /(EasyCalc_(Model|Table|Cond)|M01_LB_Blocks|M01_SL_Import(_Parse)?|M01_SL_(Item|Model)|spreadsheet_\w+)(\.ts)?$/;
|
||||
export async function resolve(spec, ctx, next) {
|
||||
if (spec.startsWith(".") && ctx.parentURL && !spec.endsWith(".ts")) {
|
||||
const u = new URL(spec + ".ts", ctx.parentURL);
|
||||
@@ -161,12 +161,25 @@ def _tables_of(row: dict, tables: dict) -> dict:
|
||||
return {k: tables[k] for k in keys if k in tables}
|
||||
|
||||
|
||||
def _names_of(row: dict, master) -> dict:
|
||||
"""다른 로직 · 노임 키 → 이름(화면이 마스터 목록에서 넘기는 것과 같음)"""
|
||||
cm, files, _ = master
|
||||
m = cm.mf.Master(files)
|
||||
keys = set(re.findall(r"(?:G[FCX]|LB|MT)\d{6}", json.dumps(row, ensure_ascii=False)))
|
||||
return {k: str(m.get(k).get("이름") or k) for k in keys}
|
||||
|
||||
|
||||
def _num(v) -> float:
|
||||
"""빈 칸(선이 없는 비목 알약)은 0 · 수가 아니면 nan"""
|
||||
if v is None:
|
||||
return 0.0
|
||||
return float(v["수"]) if isinstance(v, dict) and "수" in v else float("nan")
|
||||
|
||||
|
||||
def _fill(sl: dict, places: list, py_lines: list, master) -> None:
|
||||
"""바깥 값 넣기 — 표는 가져올 때 이미 · 노임 = 마스터 · 자재 = `/calc` 줄 단가 · 장비 · 로직 = 그 로직 `/calc`"""
|
||||
from M01_MasterData.LogicBuilder import M01_LB_Calc as lb
|
||||
|
||||
cm, files, _ = master
|
||||
m = cm.mf.Master(files)
|
||||
nodes = {n["id"]: n for n in sl["nodes"]}
|
||||
@@ -180,14 +193,21 @@ def _fill(sl: dict, places: list, py_lines: list, master) -> None:
|
||||
elif kind == "자재":
|
||||
name = nodes[item["id"].split(":")[0]]["name"]
|
||||
value = next(x["단가"] for x in py_lines if x["이름"] == name)
|
||||
elif kind == "장비": # 서버와 같음 — 요소 글 한 줄(수량 1)을 셈해 그 비목
|
||||
line = {
|
||||
"종류": "로직",
|
||||
"요소": item["element"],
|
||||
"이름": "장비",
|
||||
"단위": "시간",
|
||||
"수량": "1",
|
||||
}
|
||||
inputs = item["inputs"]
|
||||
one = {"키": "", "원문번호": "", "이름": "장비", "결과단위": "원/시간", "출처": "",
|
||||
"입력": [{"이름": k} for k in inputs], "중간": [], "호표": [line], "덧줄": []} # fmt: skip
|
||||
value = lb.calc(one, inputs, {})["lines"][0]["비목"].get(item["field"], 0)
|
||||
else:
|
||||
key = (
|
||||
item["key"]
|
||||
if kind == "로직"
|
||||
else re.match(r"로직\((\w+)", item["element"]).group(1)
|
||||
)
|
||||
got = cm.mf.run(m, key, {k: Decimal(str(v)) if isinstance(v, (int, float)) else v
|
||||
for k, v in item["inputs"].items()}) # fmt: skip
|
||||
got = cm.mf.run(m, item["key"], {k: Decimal(str(v)) if isinstance(v, (int, float)) else v
|
||||
for k, v in item["inputs"].items()}) # fmt: skip
|
||||
value = got["결과"] if "결과" in got else got[item.get("field") or "계"]
|
||||
if value is None: # 마스터에 값이 없음 — 바깥 값 칸을 비움(`/calc` 도 그 줄을 비우고 0)
|
||||
continue
|
||||
@@ -197,7 +217,8 @@ def _fill(sl: dict, places: list, py_lines: list, master) -> None:
|
||||
|
||||
def _result_cells(sl: dict) -> dict:
|
||||
node = next(n for n in sl["nodes"] if n["kind"] == "result")
|
||||
return {p["name"]: (node["sheetId"], p["cell"]) for p in node["pillsOut"]}
|
||||
# 결과 틀 — 노무비 · 재료비 · 경비 = 입력 알약 · 계(또는 결과) = 출력 알약
|
||||
return {p["name"]: (node["sheetId"], p["cell"]) for p in node["pillsIn"] + node["pillsOut"]}
|
||||
|
||||
|
||||
@pytest.mark.parametrize("row,given", SAMPLES, ids=[r["키"] for r, _ in SAMPLES])
|
||||
@@ -206,9 +227,14 @@ def test_가져온_시트로직_값이_calc_와_같음(row: dict, given: dict, m
|
||||
from M01_MasterData.LogicBuilder import M01_LB_Calc as lb
|
||||
|
||||
rep = _node(
|
||||
"const r = I.importLogicReport(A.row, { tables: A.tables, examples: A.given });"
|
||||
"const r = I.importLogicReport(A.row, { tables: A.tables, examples: A.given, names: A.names });"
|
||||
"out({ ...r, places: I.outsideOf(r.sl) });",
|
||||
{"row": row, "tables": _tables_of(row, master[2]), "given": given},
|
||||
{
|
||||
"row": row,
|
||||
"tables": _tables_of(row, master[2]),
|
||||
"given": given,
|
||||
"names": _names_of(row, master),
|
||||
},
|
||||
)
|
||||
assert rep["problems"] == []
|
||||
sl = rep["sl"]
|
||||
@@ -219,6 +245,14 @@ def test_가져온_시트로직_값이_calc_와_같음(row: dict, given: dict, m
|
||||
for n in sl["nodes"]: # 표 상자 = 「표」 바깥 값 출력 알약(E1 · Table 상자와 같은 꼴)
|
||||
if n["kind"] == "table":
|
||||
assert {"name": "표", "cell": "E1", "outside": True} in n["pillsOut"]
|
||||
# 상자 이름에 번호(키) 없음 · 항목 상자 = Item 틀(ItemRef · B1 수량 · B6 금액)
|
||||
assert not [n["name"] for n in sl["nodes"] if re.fullmatch(r"[A-Z]{2}\d{6}", n["name"])]
|
||||
for n in sl["nodes"]:
|
||||
if n["kind"] == "item" and n.get("ref", "").startswith("{"):
|
||||
ref = json.loads(n["ref"])
|
||||
assert ref["what"] in ("노무", "재료", "장비", "일위대가", "비율")
|
||||
pills = {p["name"]: p["cell"] for p in n["pillsOut"]}
|
||||
assert pills["금액"] == ("B4" if ref["what"] == "비율" else "B6")
|
||||
for e in sl["edges"]:
|
||||
assert any(p["name"] == e["from"]["pill"] for p in ids[e["from"]["node"]]["pillsOut"])
|
||||
assert any(p["name"] == e["to"]["pill"] for p in ids[e["to"]["node"]]["pillsIn"])
|
||||
|
||||
@@ -31,11 +31,21 @@ const jobs = JSON.parse(fs.readFileSync(0, "utf8"));
|
||||
const out = jobs.map((job) => {
|
||||
if (job.op === "plan") {
|
||||
const plan = m.planLookup(job.info, job.roles);
|
||||
const cells = { ...m.blockCells(job.info), ...plan.cells };
|
||||
const cells = { ...m.blockCells(job.blockInfo || job.info), ...plan.cells };
|
||||
for (const [c, v] of Object.entries(job.inputs || {})) cells[plan.inCells[c]] = { 값: v };
|
||||
return { cells, plan };
|
||||
}
|
||||
if (job.op === "paste") return m.parsePaste(job.text);
|
||||
if (job.op === "rename") {
|
||||
const sl = { key: null, name: "t", resultUnit: "", edges: [],
|
||||
workbook: { 종류: "통합문서", 판: 1, 열: "t", 서식: [{}], 시트: [
|
||||
{ id: "s1", 이름: "표", 칸: {} },
|
||||
{ id: "s2", 이름: "계산", 칸: { B2: { 식: "'표'!G7*2" }, B3: { 식: "표!G7+1" } } } ] },
|
||||
nodes: [{ id: "n1", kind: "table", name: "표", sheetId: "s1", pillsIn: [], pillsOut: [], stage: 1 }] };
|
||||
const done = m.applyTable(sl, "n1", job.info, job.roles, { ref: job.info.key, fillBlock: false, outside: true }).sl;
|
||||
const texts = Object.values(done.workbook.시트[0].칸).map((c) => String(c.값 ?? ""));
|
||||
return { sheets: done.workbook.시트.map((x) => x.이름), refs: done.workbook.시트[1].칸, ref: done.nodes[0].ref, node: done.nodes[0].name, texts };
|
||||
}
|
||||
if (job.op === "reapply") {
|
||||
const base = { key: null, name: "t", resultUnit: "원/㎡", edges: [],
|
||||
workbook: { 종류: "통합문서", 판: 1, 열: "t", 서식: [{}], 시트: [{ id: "s1", 이름: "표", 칸: {} }] },
|
||||
@@ -230,3 +240,37 @@ def test_블록_머리_차례():
|
||||
"폭·아래",
|
||||
"폭·위",
|
||||
]
|
||||
|
||||
|
||||
def test_표가_늘어도_찾기_범위가_따라감():
|
||||
"""마스터 표 줄이 시험 때보다 늘었을 때 — 찾기 판이 만든 줄 수 밖 새 줄도 찾음(범위 표 · 같음 표 둘 다)."""
|
||||
small = {**RATE, "rows": RATE["rows"][:2]}
|
||||
extra = [{"높이": [5.5 + i, 6.5 + i], "증가율": 70 + i} for i in range(5)]
|
||||
grown = {**small, "rows": [*small["rows"], *extra]}
|
||||
roles = {"cond": ["높이"], "out": ["증가율"]}
|
||||
plan = run(
|
||||
[{"op": "plan", "info": small, "roles": roles, "inputs": {"높이": 8.5}, "blockInfo": grown}]
|
||||
)[0]
|
||||
book = {
|
||||
"종류": "통합문서",
|
||||
"판": 1,
|
||||
"열": "t",
|
||||
"서식": [{}],
|
||||
"시트": [{"id": "s1", "이름": "표", "칸": plan["cells"]}],
|
||||
"활성": "s1",
|
||||
}
|
||||
values = recalc_workbooks([book])[0]["s1"]
|
||||
assert values[plan["plan"]["statusCell"]]["글"] == "찾음"
|
||||
assert float(values[plan["plan"]["outCells"]["증가율"]]["수"]) == 72
|
||||
|
||||
|
||||
def test_표_상자에_표_번호가_안_보임_이름으로_보임():
|
||||
info = {**EXACT, "key": "QF000421", "name": "메쌓기(인력)", "no": "13-4-1", "base": "1㎡"}
|
||||
roles = {"cond": list(info["conds"]), "out": ["석공"]}
|
||||
out = run([{"op": "rename", "info": info, "roles": roles}])[0]
|
||||
assert out["sheets"] == ["표 · 메쌓기(인력)", "계산"]
|
||||
assert out["ref"] == "QF000421" # 번호는 상자 ref 에만
|
||||
assert "QF000421" not in " ".join(out["texts"])
|
||||
assert any("13-4-1" in t and "1㎡" in t for t in out["texts"])
|
||||
assert out["refs"]["B2"]["식"] == "'표 · 메쌓기(인력)'!G7*2"
|
||||
assert out["refs"]["B3"]["식"] == "'표 · 메쌓기(인력)'!G7+1"
|
||||
|
||||
Reference in New Issue
Block a user