fix(M02-흐름도): 조건 줄 새 줄 기본 값은 목록 첫 값(속 글 안 보임) · 조건 만들기 목록에 나중에 놓은 알약 · 변수도 뜸
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01D2nUMUMTsqm93PbQtipo6c
This commit is contained in:
@@ -60,10 +60,12 @@ export function drawCells(host: HTMLElement, x: ExtraContext): void {
|
||||
});
|
||||
}
|
||||
|
||||
/** 우클릭 「조건 만들기」 에 주는 것 — 칸에 올 값 목록(알약이면 valueChoices · 변수면 고르기 목록) · 이름 붙은 칸 */
|
||||
export function conditionsOf(x: ExtraContext): ConditionOptions {
|
||||
/** 우클릭 「조건 만들기」 에 주는 것 — 칸에 올 값 목록(알약이면 valueChoices · 변수면 고르기 목록) · 이름 붙은 칸
|
||||
* get 으로 부를 때마다 지금 상태를 다시 읽음(나중에 놓은 알약 · 만든 변수도 목록에 뜸) */
|
||||
export function conditionsOf(get: () => ExtraContext): ConditionOptions {
|
||||
return {
|
||||
valuesFor: (a1) => {
|
||||
const x = get();
|
||||
const f = boxOf(x)?.func;
|
||||
const at = a1.toUpperCase();
|
||||
const v = f?.variables.find((y) => y.cell?.toUpperCase() === at);
|
||||
@@ -75,6 +77,7 @@ export function conditionsOf(x: ExtraContext): ConditionOptions {
|
||||
return link ? valueChoices(x.lg, link.from, { values: x.detail.values }) : null;
|
||||
},
|
||||
pills: () => {
|
||||
const x = get();
|
||||
const f = boxOf(x)?.func;
|
||||
return [
|
||||
...(f?.inputs ?? []).filter((i) => i.cell).map((i) => ({ name: i.port, cell: i.cell })),
|
||||
|
||||
@@ -583,7 +583,7 @@ async function mountSheet(st: State): Promise<void> {
|
||||
preview: true,
|
||||
tabs: false,
|
||||
readOnly: st.readOnly,
|
||||
conditions: conditionsOf(extra(st)),
|
||||
conditions: conditionsOf(() => extra(st)),
|
||||
onChange: (b) => onBook(st, b),
|
||||
onSelect: (s) => {
|
||||
st.cell = s.칸;
|
||||
|
||||
@@ -85,6 +85,7 @@ const TEXT = {
|
||||
Or: ["또는", "or"],
|
||||
If: ["조건", "If"],
|
||||
AddLine: ["+ 조건 줄", "+ Condition line"],
|
||||
PickOne: ["고르세요", "choose"],
|
||||
Join: ["잇는 말", "Join with"],
|
||||
OutRange: ["범위 {n} 밖", "Outside the range {n}"],
|
||||
Range: ["{n} (범위)", "{n} (range)"],
|
||||
@@ -264,12 +265,16 @@ function gateValue(ctx: Ctx, c: CfGateCond, onPick: (v: number | string) => void
|
||||
const list = valueChoices(ctx.lg, c.from, { values: ctx.detail.values });
|
||||
if (list?.length) {
|
||||
const key = (v: string | number): string => `${typeof v}:${v}`;
|
||||
const options = list.map((v) => ({ value: key(v), text: String(v) }));
|
||||
const known = list.some((v) => key(v) === key(c.value));
|
||||
const options = [
|
||||
...(known ? [] : [{ value: "", text: tk("PickOne") }]),
|
||||
...list.map((v) => ({ value: key(v), text: String(v) })),
|
||||
];
|
||||
return [
|
||||
select(
|
||||
ctx,
|
||||
options,
|
||||
key(c.value),
|
||||
known ? key(c.value) : "",
|
||||
(k) => {
|
||||
const hit = list.find((v) => key(v) === k);
|
||||
if (hit !== undefined) onPick(hit);
|
||||
@@ -345,8 +350,12 @@ function gateEditor(ctx: Ctx, rule: Extract<CfRule, { kind: "gate" }>): HTMLElem
|
||||
label: tk("AddLine"),
|
||||
variant: "ghost",
|
||||
size: "sm",
|
||||
onClick: () =>
|
||||
put([...g.conds, { from: first?.from ?? { box: "", name: "" }, op: "=", value: 0 }]),
|
||||
onClick: () => {
|
||||
const from = first?.from ?? { box: "", name: "" };
|
||||
// 새 줄 기본 값 — 목록이 있는 알약이면 그 첫 값 · 아니면 0
|
||||
const value = valueChoices(ctx.lg, from, { values: ctx.detail.values })?.[0] ?? 0;
|
||||
put([...g.conds, { from, op: "=", value }]);
|
||||
},
|
||||
}),
|
||||
...(g.conds.length > 1
|
||||
? [
|
||||
|
||||
Reference in New Issue
Block a user