refactor(856-4): 공용 줄 쌓기가 M02 · M01 을 거꾸로 부르는 것 끊음 — 층 · 부름 · 찾기 창 · 단위 고르기 · 합계 상자 · 기계 칸 고리
- 층 이름 · /api/m02 부름 = common_util_m02_call 새 조각(M02 Api_Fetch 는 그대로 내보냄 — M02 부르는 곳 안 바뀜) - 찾아 넣기 창 = 페이지가 넘김(StackFind · 줄 쌓기 화면 · 기계 시트 · 편집 · 제어 구역 훅) — M01 · M02 가 M02 openFindPicker 를 넘김 - 단위 고르기 = 부품 상자 ui_template_unit_pick(옛 M02 DataFlow/DF_UnitPick · 표준 표 읽기 같이 옮김) - 합계 상자 = A00 formula_doc_foot 로 합침(옛 M01 LogicLab_Foot · 쓰는 곳 하나) · 그 CSS = formula_doc_foot.css · 안 쓰는 세 칸 갈래 · 글 키 걷음 - 기계 제어 구역 ↔ 작업량 고리 = 칸 부품 line_stack_machine_cell 로(수 칸 · 바뀜 표시) - 수치: 공용(A00) → M01 · M02 import 9 파일 17 → 3 파일 7(남은 것 = 기계 · 불러온 재료 훅 — 858 · 857 몫) · ctl ↔ work 고리 0 - 동작 불변(화면 확인 · 시험) · 시험: 옮긴 파일 이름 · 경로만 고침 · 걸린 글 대조 줄 지움(721 · 737) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,41 +0,0 @@
|
||||
.m02-df-unitpick {
|
||||
position: relative;
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.m02-df-unitpick__panel {
|
||||
position: absolute;
|
||||
top: 100%;
|
||||
left: 0;
|
||||
z-index: 50;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: var(--spacing-4);
|
||||
min-width: 14em;
|
||||
max-height: 20em;
|
||||
padding: var(--spacing-8);
|
||||
border: 1px solid var(--color-border);
|
||||
border-radius: var(--radius-cards);
|
||||
background: var(--color-surface);
|
||||
box-shadow: var(--shadow-lg);
|
||||
}
|
||||
|
||||
.m02-df-unitpick__list {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
list-style: none;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
/* 단위 줄 = 목록 줄 부품 · 화살표 키로 고른 줄(is-on)만 마우스 꼴 */
|
||||
.m02-df-unitpick__item {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.m02-df-unitpick__item.is-on {
|
||||
background: var(--color-hover);
|
||||
}
|
||||
|
||||
.m02-df-unitpick__item.is-now {
|
||||
font-weight: var(--font-weight-bold);
|
||||
}
|
||||
@@ -1,204 +0,0 @@
|
||||
/* =============================================================================
|
||||
* M02_DF_UnitPick.ts
|
||||
* 단가산출 흐름도 공용 단위 고르기 — 치면 걸러진 목록 · 고르기만(손글 안 받음 · `free` = 목록에 없는 친 글도 씀) · 「-」 = 없음
|
||||
* 목록 = 단위 표준(산림품셈 1-2-2) 단위 + 표의 「더한 단위」(수식 문서 줄 단위) + 부른 쪽이 주는 마스터 결과단위 등 + 원 · 「같은 단위」(kg → ㎏) 는 하나만
|
||||
* 표준 표 읽는 길은 `setUnitSource` 로 바꿔 끼움(기본 = 서버 /standards) — 다른 판도 이것을 씀
|
||||
* 글 [한, 영] 짝은 아래 TEXT
|
||||
* ========================================================================== */
|
||||
|
||||
import { currentLanguageIndex } from "@ui/ui_template_locale";
|
||||
import { createButton, el } from "@ui/ui_template_elements";
|
||||
import type { UiSize } from "@ui/ui_template_button";
|
||||
import { cfStandards } from "./M02_DF_Api";
|
||||
import "./M02_DF_UnitPick.css";
|
||||
import { createEmpty } from "@ui/ui_template_empty";
|
||||
import "@ui/ui_template_list_row.css";
|
||||
|
||||
const TEXT = {
|
||||
None: ["없음", "none"],
|
||||
Filter: ["단위를 쳐서 찾음", "Type to filter units"],
|
||||
Empty: ["맞는 단위가 없음 — 목록에서만 고름", "No match — pick from the list only"],
|
||||
Free: ["「{u}」 그대로 씀", "Use “{u}”"],
|
||||
Pick: ["단위 고르기", "Pick a unit"],
|
||||
} as const;
|
||||
|
||||
const tu = (key: keyof typeof TEXT): string => TEXT[key][currentLanguageIndex === 1 ? 1 : 0];
|
||||
|
||||
/** 「없음」 을 뜻하는 단위 글 */
|
||||
export const NO_UNIT = "-";
|
||||
|
||||
/** 표준 표에서 읽은 것 — 단위 목록 · 단위마다 소수자리 제안(단위수량 쪽에서 가장 많이 쓴 자리) */
|
||||
export interface UnitStandard {
|
||||
units: string[];
|
||||
places: Record<string, number>;
|
||||
}
|
||||
|
||||
type UnitSource = () => Promise<UnitStandard>;
|
||||
|
||||
interface StandardRow {
|
||||
"규격 단위"?: string | null;
|
||||
"단위수량 단위"?: string | null;
|
||||
"단위수량 소수자리"?: number | null;
|
||||
}
|
||||
|
||||
/** 서버 표준 표(/standards) — 고친 표가 있으면 그것, 없으면 처음 값 */
|
||||
const fromServer: UnitSource = async () => {
|
||||
const table = (await cfStandards()).unit as {
|
||||
줄: StandardRow[];
|
||||
"더한 단위"?: string[];
|
||||
"같은 단위"?: Record<string, string>;
|
||||
};
|
||||
const same = (u: string | null | undefined): string | null | undefined =>
|
||||
(u && table["같은 단위"]?.[u]) || u; // kg → ㎏ 등 원문 꼴 하나만(요구 692)
|
||||
const units = [
|
||||
...table.줄.flatMap((r) => [r["규격 단위"], r["단위수량 단위"]]),
|
||||
...(table["더한 단위"] ?? []),
|
||||
]
|
||||
.map(same)
|
||||
.filter((u): u is string => !!u);
|
||||
const count: Record<string, Record<number, number>> = {};
|
||||
for (const r of table.줄) {
|
||||
const u = same(r["단위수량 단위"]);
|
||||
const p = r["단위수량 소수자리"];
|
||||
if (!u || u === "없음" || typeof p !== "number") continue;
|
||||
count[u] = { ...count[u], [p]: (count[u]?.[p] ?? 0) + 1 };
|
||||
}
|
||||
const places = Object.fromEntries(
|
||||
Object.entries(count).map(([u, c]) => [
|
||||
u,
|
||||
Number(Object.entries(c).sort((x, y) => y[1] - x[1])[0][0]),
|
||||
]),
|
||||
);
|
||||
return { units, places };
|
||||
};
|
||||
|
||||
let source: UnitSource = fromServer;
|
||||
let cache: Promise<UnitStandard> | null = null;
|
||||
|
||||
/** 표준 표 읽는 길 바꾸기(서버에서 고친 표를 읽을 때) — 목록을 다시 받음 */
|
||||
export function setUnitSource(next: UnitSource): void {
|
||||
source = next;
|
||||
cache = null;
|
||||
}
|
||||
|
||||
/** 표준 단위 + 원 — 같은 글은 한 번 · 「없음」 은 뺌 · 서버를 못 읽으면 원만(다음에 다시 읽음) */
|
||||
export async function loadStandard(): Promise<UnitStandard> {
|
||||
cache ??= source().then((std) => {
|
||||
const set = new Set([...std.units, "원"]);
|
||||
set.delete("없음");
|
||||
set.delete(NO_UNIT);
|
||||
return { units: [...set], places: std.places };
|
||||
});
|
||||
try {
|
||||
return await cache;
|
||||
} catch {
|
||||
cache = null;
|
||||
return { units: ["원"], places: {} };
|
||||
}
|
||||
}
|
||||
|
||||
export interface UnitPickOptions {
|
||||
/** 지금 단위 — 「-」 = 없음 */
|
||||
value: string;
|
||||
onPick(unit: string): void;
|
||||
/** 더 보일 단위(마스터 결과단위 등) */
|
||||
extra?: string[];
|
||||
readOnly?: boolean;
|
||||
ariaLabel?: string;
|
||||
/** 크기 단(줄 쌓기 24 등) — 없으면 옛 꼴 */
|
||||
size?: UiSize;
|
||||
/** 목록에 없는 친 글도 단위로 씀(줄 쌓기 · 804-7) */
|
||||
free?: boolean;
|
||||
}
|
||||
|
||||
/** 단위 고르기 — 단추를 누르면 걸러지는 목록 · 목록에서 고르기만 됨 */
|
||||
export function createUnitPick(opts: UnitPickOptions): HTMLElement {
|
||||
const label = (u: string): string => (u === NO_UNIT ? `${NO_UNIT} (${tu("None")})` : u);
|
||||
const root = el("span", { className: "m02-df-unitpick" });
|
||||
const open = createButton({
|
||||
label: opts.value || NO_UNIT,
|
||||
variant: "ghost",
|
||||
size: opts.size,
|
||||
disabled: opts.readOnly,
|
||||
onClick: () => toggle(),
|
||||
});
|
||||
open.setAttribute("aria-label", `${opts.ariaLabel ?? tu("Pick")}: ${opts.value || NO_UNIT}`);
|
||||
open.setAttribute("aria-haspopup", "listbox");
|
||||
root.append(open);
|
||||
if (opts.readOnly) return root;
|
||||
|
||||
const input = el("input", {
|
||||
className: "ui-input ui-input--sm m02-df-unitpick__filter",
|
||||
attrs: { type: "text", placeholder: tu("Filter"), "aria-label": tu("Filter") },
|
||||
});
|
||||
const list = el("ul", { className: "m02-df-unitpick__list", attrs: { role: "listbox" } });
|
||||
const panel = el("div", { className: "m02-df-unitpick__panel", children: [input, list] });
|
||||
panel.hidden = true;
|
||||
root.append(panel);
|
||||
|
||||
let all: string[] = [];
|
||||
let shown: string[] = [];
|
||||
let at = 0;
|
||||
const pick = (u: string): void => {
|
||||
close();
|
||||
if (u !== (opts.value || NO_UNIT)) opts.onPick(u);
|
||||
};
|
||||
const draw = (): void => {
|
||||
const q = input.value.trim().toLowerCase();
|
||||
shown = all.filter((u) => u === NO_UNIT || !q || u.toLowerCase().includes(q));
|
||||
if (q && !NO_UNIT.includes(q)) shown = shown.filter((u) => u !== NO_UNIT);
|
||||
const typed = input.value.trim();
|
||||
if (opts.free && typed && !all.includes(typed)) shown.push(typed); // 맨 끝 「그대로 씀」 줄
|
||||
at = Math.min(at, Math.max(0, shown.length - 1));
|
||||
list.replaceChildren(
|
||||
...(shown.length
|
||||
? shown.map((u, i) => {
|
||||
const b = el("button", {
|
||||
className: `ui-list-row ui-sidebar-row m02-df-unitpick__item${i === at ? " is-on" : ""}${u === (opts.value || NO_UNIT) ? " is-now" : ""}`,
|
||||
text:
|
||||
opts.free && u === input.value.trim() && !all.includes(u)
|
||||
? tu("Free").replace("{u}", u)
|
||||
: label(u),
|
||||
attrs: { type: "button", role: "option" },
|
||||
});
|
||||
b.addEventListener("click", () => pick(u));
|
||||
return el("li", { children: [b] });
|
||||
})
|
||||
: [el("li", { children: [createEmpty({ text: tu("Empty"), small: true })] })]),
|
||||
);
|
||||
};
|
||||
const close = (): void => {
|
||||
panel.hidden = true;
|
||||
document.removeEventListener("pointerdown", outside, true);
|
||||
};
|
||||
const outside = (e: Event): void => {
|
||||
if (!root.contains(e.target as Node)) close();
|
||||
};
|
||||
function toggle(): void {
|
||||
if (!panel.hidden) return close();
|
||||
panel.hidden = false;
|
||||
document.addEventListener("pointerdown", outside, true);
|
||||
input.value = "";
|
||||
void loadStandard().then(({ units }) => {
|
||||
const mine = [...(opts.extra ?? []), ...units];
|
||||
all = [NO_UNIT, ...new Set(mine.filter((u) => u && u !== NO_UNIT))];
|
||||
at = 0;
|
||||
draw();
|
||||
input.focus();
|
||||
});
|
||||
}
|
||||
input.addEventListener("input", () => ((at = 0), draw()));
|
||||
input.addEventListener("keydown", (e) => {
|
||||
if (e.key === "Escape") return (e.stopPropagation(), close(), open.focus());
|
||||
if (e.key === "ArrowDown" || e.key === "ArrowUp") {
|
||||
e.preventDefault();
|
||||
at = Math.max(0, Math.min(shown.length - 1, at + (e.key === "ArrowDown" ? 1 : -1)));
|
||||
return draw();
|
||||
}
|
||||
if (e.key === "Enter" && shown[at] !== undefined) {
|
||||
e.preventDefault();
|
||||
pick(shown[at]);
|
||||
}
|
||||
});
|
||||
return root;
|
||||
}
|
||||
Reference in New Issue
Block a user