SheetLogic · SlNode · SlPill · SlEdge · SlOutside · SlKind · SlEnd · SlUserTable · SlValue · SlOutsideValue · SlEvalResult newLogic · addNode · removeNode · connect · disconnect · setPill · removePill · outsideCells · applyOutside · evalLogic · checkLogic (속은 준비 중) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VBToTCGk5dqDKeXCEP3vhk
134 lines
3.5 KiB
TypeScript
134 lines
3.5 KiB
TypeScript
/* =============================================================================
|
|
* M01_SL_Model.ts
|
|
* 시트 로직 Model — 로직 한 벌 = 통합문서 하나 · 상자 하나 = 시트 하나 · 알약 = 이름 붙은 칸
|
|
* 선 = 받는 입력 알약 칸에 「'시트 이름'!칸」 참조 수식 · DOM 없음
|
|
* 모양은 `docs/raw/M01_쉬운단가/시트로직_정함.md` 정함 1~5 그대로
|
|
* ========================================================================== */
|
|
|
|
import type { Workbook } from "../../A00_Common/spreadsheet/spreadsheet_types";
|
|
|
|
/** 상자 종류 — 입력값 · 고정값 · 표 · 계산 · 항목 · 다른 로직 · 결과 */
|
|
export type SlKind = "input" | "const" | "table" | "calc" | "item" | "logic" | "result";
|
|
|
|
/** 알약 = 이름 붙은 칸 */
|
|
export interface SlPill {
|
|
name: string;
|
|
/** 「B3」 */
|
|
cell: string;
|
|
unit?: string;
|
|
/** 바깥 값 칸 — 열 때 · 저장 때 마스터에서 넣음 */
|
|
outside?: boolean;
|
|
}
|
|
|
|
/** 상자 = 시트 하나 */
|
|
export interface SlNode {
|
|
id: string;
|
|
kind: SlKind;
|
|
name: string;
|
|
sheetId: string;
|
|
pillsIn: SlPill[];
|
|
pillsOut: SlPill[];
|
|
/** 표 키 · 요소 · 기존 로직 키 · 내 표 id */
|
|
ref?: string;
|
|
/** 띠 단계 — 0 입력값 · 1 표 · 2 계산 · 3 항목 · 4 결과 */
|
|
stage: number;
|
|
}
|
|
|
|
/** 선 — 출력 알약 → 입력 알약 */
|
|
export interface SlEdge {
|
|
id: string;
|
|
from: { node: string; pill: string };
|
|
to: { node: string; pill: string };
|
|
}
|
|
|
|
/** 바깥 값 칸 */
|
|
export interface SlOutside {
|
|
node: string;
|
|
cell: string;
|
|
kind: "table" | "price" | "logic";
|
|
ref: string;
|
|
}
|
|
|
|
/** 내 표 — 품셈에 없는 표(사용자가 만듦) */
|
|
export interface SlUserTable {
|
|
id: string;
|
|
name: string;
|
|
cols: string[];
|
|
rows: (number | string | null)[][];
|
|
}
|
|
|
|
export interface SheetLogic {
|
|
key: string | null;
|
|
name: string;
|
|
resultUnit: string;
|
|
workbook: Workbook;
|
|
nodes: SlNode[];
|
|
edges: SlEdge[];
|
|
userTables?: SlUserTable[];
|
|
}
|
|
|
|
/** 알약 한쪽 끝 */
|
|
export interface SlEnd {
|
|
node: string;
|
|
pill: string;
|
|
}
|
|
|
|
const notReady = (): never => {
|
|
throw new Error("준비 중");
|
|
};
|
|
|
|
/** 빈 시트 로직 */
|
|
export function newLogic(_name?: string, _resultUnit?: string): SheetLogic {
|
|
return notReady();
|
|
}
|
|
|
|
/** 상자 더하기 — 그 종류 틀(칸 A 이름 · B 값 · C 설명)로 시트를 만듦 */
|
|
export function addNode(
|
|
_sl: SheetLogic,
|
|
_kind: SlKind,
|
|
_name: string,
|
|
): { sl: SheetLogic; node: SlNode } {
|
|
return notReady();
|
|
}
|
|
|
|
/** 상자 지우기 — 시트 · 이어진 선 · 받던 참조 수식을 함께 지움 */
|
|
export function removeNode(_sl: SheetLogic, _node: string): SheetLogic {
|
|
return notReady();
|
|
}
|
|
|
|
/** 선 잇기 — 받는 알약 칸에 참조 수식 · 순환 · 없는 알약이면 막고 까닭(쉬운 말) */
|
|
export function connect(
|
|
_sl: SheetLogic,
|
|
_from: SlEnd,
|
|
_to: SlEnd,
|
|
): { sl: SheetLogic; why: string | null } {
|
|
return notReady();
|
|
}
|
|
|
|
/** 선 끊기 — 그 참조를 받는 칸 수식에서 뺌 */
|
|
export function disconnect(_sl: SheetLogic, _edge: string): SheetLogic {
|
|
return notReady();
|
|
}
|
|
|
|
/** 알약 정하기 — 같은 칸이나 같은 이름이 있으면 바꿈 */
|
|
export function setPill(
|
|
_sl: SheetLogic,
|
|
_node: string,
|
|
_cell: string,
|
|
_dir: "in" | "out",
|
|
_name: string,
|
|
_extra?: Pick<SlPill, "unit" | "outside">,
|
|
): SheetLogic {
|
|
return notReady();
|
|
}
|
|
|
|
/** 알약 빼기 — 이어진 선도 끊음 */
|
|
export function removePill(
|
|
_sl: SheetLogic,
|
|
_node: string,
|
|
_dir: "in" | "out",
|
|
_name: string,
|
|
): SheetLogic {
|
|
return notReady();
|
|
}
|