diff --git a/M02_MasterTemplete/DataFlow/M02_DF_FuncExtra.ts b/M02_MasterTemplete/DataFlow/M02_DF_FuncExtra.ts index 6d302fea5..02a8c2cc0 100644 --- a/M02_MasterTemplete/DataFlow/M02_DF_FuncExtra.ts +++ b/M02_MasterTemplete/DataFlow/M02_DF_FuncExtra.ts @@ -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 })), diff --git a/M02_MasterTemplete/DataFlow/M02_DF_FuncPanel.ts b/M02_MasterTemplete/DataFlow/M02_DF_FuncPanel.ts index 17f9cb13a..437d1d532 100644 --- a/M02_MasterTemplete/DataFlow/M02_DF_FuncPanel.ts +++ b/M02_MasterTemplete/DataFlow/M02_DF_FuncPanel.ts @@ -583,7 +583,7 @@ async function mountSheet(st: State): Promise { 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.칸; diff --git a/M02_MasterTemplete/DataFlow/M02_DF_LinkPanel.ts b/M02_MasterTemplete/DataFlow/M02_DF_LinkPanel.ts index f8efa089d..ac81f785a 100644 --- a/M02_MasterTemplete/DataFlow/M02_DF_LinkPanel.ts +++ b/M02_MasterTemplete/DataFlow/M02_DF_LinkPanel.ts @@ -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): 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 ? [