/* ============================================================================= * M02_MasterTemplete_Labor_Tree.ts * 일위대가 라이브러리 나무 자료(화면 없음) — 조합 목록 → 나무 부품(`TreePanel`) 모양 · 나무 고침 뒤 알림. * 조합 폴더 = [구분] · [구분, 상세구분](깊이 2 · PLAN 27-2a) · 항목 = 조합(열 = 키). * ========================================================================== */ import type { TreeEdit, TreeNote, TreeView } from "./M02_MasterTemplete_Api_Fetch"; import type { ComboList, ComboSummary } from "./M02_MasterTemplete_Labor_Api"; /** 조합의 폴더 — [구분] · [구분, 상세구분] · 구분 없으면 맨 위 */ export const pathOf = (c: ComboSummary): string[] => c.구분 ? (c.상세구분 ? [c.구분, c.상세구분] : [c.구분]) : []; /** 조합 목록 → 나무 부품 모양(항목 = 조합 · 열 = 키) */ export const toView = (list: ComboList, note?: TreeNote): TreeView => ({ 판: list.판, 폴더: list.폴더, items: list.줄.map((c) => ({ key: c.키, 열: c.키, 경로: [...pathOf(c), c.이름], 이름: c.이름, 단위: c.단위, })), ...(note ? { 알림: note } : {}), }); /** 나무 고침 뒤 알림 — 새 · 바뀐 폴더를 펼치고 고친 조합은 고른 채 */ export function noteOf(edit: TreeEdit, gone: string[]): TreeNote { const at = edit.경로 ?? []; const last = at[at.length - 1] ?? ""; if (edit.키 && edit.op !== "delete") { const where = edit.op === "move" ? (edit.새경로 ?? []) : at; return { op: edit.op, 열: edit.키, 경로: [...where, edit.이름 ?? ""], 지운항목: gone }; } const path = edit.op === "add-folder" ? [...at, edit.이름 ?? ""] : edit.op === "rename" ? [...at.slice(0, -1), edit.이름 ?? ""] : edit.op === "move" ? [...(edit.새경로 ?? []), last] : undefined; return { op: edit.op, ...(path ? { 경로: path } : {}), 지운항목: gone }; }