feat(M01-쉬운단가): Cards 잠금 카드에 조건 보고 고치기 단추 - openEasyCond 답으로 식 바꿈 · 표와 조건 둘 다 있으면 두 단추

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01D2nUMUMTsqm93PbQtipo6c
This commit is contained in:
2026-10-01 09:54:42 +09:00
co-authored by Claude Sonnet 5.5
parent 18e8b93304
commit ea07beb5c4
+24 -12
View File
@@ -23,6 +23,7 @@ import {
type PickResult,
} from "./M01_EasyCalc_Model";
import { openEasyPick } from "./M01_EasyCalc_Pick";
import { openEasyCond, readCond } from "./M01_EasyCalc_Cond";
import { openEasyTable, readFinds } from "./M01_EasyCalc_Table";
import "./M01_EasyCalc_Cards.css";
@@ -62,6 +63,7 @@ const TEXT = {
Locked: ["잠김", "Locked"],
ToNumber: ["숫자로 바꾸기", "Make it a number"],
ByTable: ["표 보고 고르기", "Choose from table"],
ByCond: ["조건 보고 고치기", "Edit conditions"],
ToNumber_Wait: ["계산이 끝난 뒤 가능", "Available after calculation"],
ToNumber_Ask: [
"자동 값을 그대로 숫자로 바꿈 · 이후 자동으로 달라지지 않음",
@@ -207,11 +209,16 @@ async function lockToNumber(ctx: Ctx, card: EasyCard, value: number): Promise<vo
}
}
async function pickFromTable(ctx: Ctx, card: EasyCard): Promise<void> {
/** 표 · 조건 창 — 답(새 식)이 있으면 그 카드 식만 바꿈 */
async function editFormula(
ctx: Ctx,
card: EasyCard,
open: typeof openEasyTable | typeof openEasyCond,
): Promise<void> {
if (picking) return;
picking = true;
try {
const formula = await openEasyTable(card, ctx.doc, ctx.on.trial?.());
const formula = await open(card, ctx.doc, ctx.on.trial?.());
if (formula !== null) patchCard(ctx, card, { qtyFormula: formula });
} finally {
picking = false;
@@ -427,16 +434,21 @@ function lockedNote(ctx: Ctx, card: EasyCard): HTMLElement {
});
if (!line) button.title = tc("ToNumber_Wait");
note.push(button);
// 표 찾기가 있는 식만 — 조건 꼴 [조건 보고 고치기] 자리는 비워 둠(sub7)
if (card.qtyFormula !== null && readFinds(card.qtyFormula)?.length) {
note.push(
createButton({
label: tc("ByTable"),
variant: "ghost",
size: "sm",
onClick: () => void pickFromTable(ctx, card),
}),
);
const formula = card.qtyFormula;
const tools: [boolean, keyof typeof TEXT, typeof openEasyTable | typeof openEasyCond][] = [
[formula !== null && !!readFinds(formula)?.length, "ByTable", openEasyTable],
[formula !== null && !!readCond(formula, ctx.doc.row), "ByCond", openEasyCond],
];
for (const [has, label, open] of tools) {
if (has)
note.push(
createButton({
label: tc(label),
variant: "ghost",
size: "sm",
onClick: () => void editFormula(ctx, card, open),
}),
);
}
}
return el("div", { className: "m01-easycards-locknote", children: note });