@cardenelabs/cdl 0.60.0 → 0.61.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -769,6 +769,17 @@ type CdlState = {
769
769
  id: string;
770
770
  initial: number | string;
771
771
  };
772
+ /**
773
+ * 選択肢を持つ入力欄 (`dropdown` / `radio` / `tabs` / `multi-select`) の 1 つの選択肢 (#855)。
774
+ *
775
+ * 文字列は値と見せる字を兼ねる。 組は `value` を入力欄の値にし、`label` を操作部の選択肢と
776
+ * 箱の字の差し込み (`{id}`) に描く。 値は綴りのまま残るので、綴りで読む読み出し (信号の灯り等) と
777
+ * 表示の出し分け (`visibleIf`) は名前に影響されない。
778
+ */
779
+ type CdlInputOption = string | {
780
+ value: string;
781
+ label: string;
782
+ };
772
783
  /**
773
784
  * interactive input widget spec (v0.5+、 CAR #243)。
774
785
  *
@@ -801,8 +812,8 @@ type CdlInput = {
801
812
  } | {
802
813
  id: string;
803
814
  kind: "dropdown";
804
- /** 選択肢一覧 (非空必須、 defaultValue はこの中の 1 つ) */
805
- options: readonly string[];
815
+ /** 選択肢一覧 (非空必須、 defaultValue はこの中の 1 つの値) */
816
+ options: readonly CdlInputOption[];
806
817
  defaultValue: string;
807
818
  label?: string;
808
819
  } | {
@@ -810,6 +821,10 @@ type CdlInput = {
810
821
  kind: "toggle";
811
822
  defaultValue: boolean;
812
823
  label?: string;
824
+ /** 入の時に箱の字の差し込み (`{id}`) へ描く名前。 省略時は `true` (#855) */
825
+ onLabel?: string;
826
+ /** 切の時に箱の字の差し込み (`{id}`) へ描く名前。 省略時は `false` (#855) */
827
+ offLabel?: string;
813
828
  }
814
829
  /**
815
830
  * XY pad = 2 軸 slider、 `.input.xypad(id)` は 実は 2 個の signal (id_x / id_y) を生成する
@@ -841,7 +856,7 @@ type CdlInput = {
841
856
  | {
842
857
  id: string;
843
858
  kind: "radio";
844
- options: readonly string[];
859
+ options: readonly CdlInputOption[];
845
860
  defaultValue: string;
846
861
  label?: string;
847
862
  }
@@ -867,7 +882,7 @@ type CdlInput = {
867
882
  | {
868
883
  id: string;
869
884
  kind: "multi-select";
870
- options: readonly string[];
885
+ options: readonly CdlInputOption[];
871
886
  defaultValues: readonly string[];
872
887
  label?: string;
873
888
  }
@@ -875,7 +890,7 @@ type CdlInput = {
875
890
  | {
876
891
  id: string;
877
892
  kind: "tabs";
878
- options: readonly string[];
893
+ options: readonly CdlInputOption[];
879
894
  defaultValue: string;
880
895
  label?: string;
881
896
  }
@@ -2999,4 +3014,4 @@ type CdlDiagramViewProps = {
2999
3014
  };
3000
3015
  declare function CdlDiagramView({ diagram, laid: laidProp, hideHeader, hideMiniPhaseIndicator, focusPhaseId, debug, emitGeometryWarn, headingLevel, interactiveHandlers }: CdlDiagramViewProps): JSX.Element;
3001
3016
 
3002
- export { computeInputSignalKey as $, EDGE_HEAD_FILLS as A, type BBox as B, type CdlDiagram as C, EDGE_HEAD_FILL_DEFAULT as D, type EdgeStyle as E, EDGE_REVEALS as F, EDGE_REVEAL_DEFAULT as G, EDGE_STYLES as H, type EdgeReveal as I, type JourneyEmotion as J, type InteractiveHandlerMap as K, type LaidDiagram as L, type InteractiveSignalsAccessor as M, type NodeKind as N, type LaidLane as O, NODE_KINDS as P, type QuadrantKey as Q, type RowMark as R, type Signal as S, type Tone as T, RELATION_FOCUSES as U, RELATION_FOCUS_DEFAULT as V, type RelationFocus as W, type ScrollProgressHandle as X, TONES as Y, computeEventBindingKey as Z, computeFormulaKey as _, type CdlInput as a, computeScrollTriggerKey as a0, computed as a1, createInteractiveSignalsAccessor as a2, createScrollProgressHandle as a3, createScrollProgressSignals as a4, hasInteractivePrimitives as a5, resolveLang as a6, sequenceBoardMetrics as a7, sequenceStepId as a8, signal as a9, type CdlLane as b, type CdlNode as c, type Side as d, type EdgeRole as e, type EdgeHead as f, type EdgeHeadFill as g, type CdlState as h, type CdlEventTarget as i, type CdlLang as j, type Computed as k, type CdlDerivedValue as l, type CdlScrollTrigger as m, type CdlDiagramViewProps as n, type LaidEdge as o, type LaidNode as p, type CdlEdge as q, CdlDiagramView as r, type CdlEventBinding as s, type CdlEventKind as t, type CdlFormula as u, type CdlPhase as v, type ChartPieForm as w, type ChartSlopeForm as x, EDGE_HEADS as y, EDGE_HEAD_DEFAULT as z };
3017
+ export { computeFormulaKey as $, EDGE_HEAD_DEFAULT as A, type BBox as B, type CdlDiagram as C, EDGE_HEAD_FILLS as D, type EdgeStyle as E, EDGE_HEAD_FILL_DEFAULT as F, EDGE_REVEALS as G, EDGE_REVEAL_DEFAULT as H, EDGE_STYLES as I, type JourneyEmotion as J, type EdgeReveal as K, type LaidDiagram as L, type InteractiveHandlerMap as M, type NodeKind as N, type InteractiveSignalsAccessor as O, type LaidLane as P, type QuadrantKey as Q, type RowMark as R, type Signal as S, type Tone as T, NODE_KINDS as U, RELATION_FOCUSES as V, RELATION_FOCUS_DEFAULT as W, type RelationFocus as X, type ScrollProgressHandle as Y, TONES as Z, computeEventBindingKey as _, type CdlInput as a, computeInputSignalKey as a0, computeScrollTriggerKey as a1, computed as a2, createInteractiveSignalsAccessor as a3, createScrollProgressHandle as a4, createScrollProgressSignals as a5, hasInteractivePrimitives as a6, resolveLang as a7, sequenceBoardMetrics as a8, sequenceStepId as a9, signal as aa, type CdlLane as b, type CdlNode as c, type Side as d, type EdgeRole as e, type EdgeHead as f, type EdgeHeadFill as g, type CdlState as h, type CdlInputOption as i, type CdlEventTarget as j, type CdlLang as k, type Computed as l, type CdlDerivedValue as m, type CdlScrollTrigger as n, type CdlDiagramViewProps as o, type LaidEdge as p, type LaidNode as q, type CdlEdge as r, CdlDiagramView as s, type CdlEventBinding as t, type CdlEventKind as u, type CdlFormula as v, type CdlPhase as w, type ChartPieForm as x, type ChartSlopeForm as y, EDGE_HEADS as z };
@@ -769,6 +769,17 @@ type CdlState = {
769
769
  id: string;
770
770
  initial: number | string;
771
771
  };
772
+ /**
773
+ * 選択肢を持つ入力欄 (`dropdown` / `radio` / `tabs` / `multi-select`) の 1 つの選択肢 (#855)。
774
+ *
775
+ * 文字列は値と見せる字を兼ねる。 組は `value` を入力欄の値にし、`label` を操作部の選択肢と
776
+ * 箱の字の差し込み (`{id}`) に描く。 値は綴りのまま残るので、綴りで読む読み出し (信号の灯り等) と
777
+ * 表示の出し分け (`visibleIf`) は名前に影響されない。
778
+ */
779
+ type CdlInputOption = string | {
780
+ value: string;
781
+ label: string;
782
+ };
772
783
  /**
773
784
  * interactive input widget spec (v0.5+、 CAR #243)。
774
785
  *
@@ -801,8 +812,8 @@ type CdlInput = {
801
812
  } | {
802
813
  id: string;
803
814
  kind: "dropdown";
804
- /** 選択肢一覧 (非空必須、 defaultValue はこの中の 1 つ) */
805
- options: readonly string[];
815
+ /** 選択肢一覧 (非空必須、 defaultValue はこの中の 1 つの値) */
816
+ options: readonly CdlInputOption[];
806
817
  defaultValue: string;
807
818
  label?: string;
808
819
  } | {
@@ -810,6 +821,10 @@ type CdlInput = {
810
821
  kind: "toggle";
811
822
  defaultValue: boolean;
812
823
  label?: string;
824
+ /** 入の時に箱の字の差し込み (`{id}`) へ描く名前。 省略時は `true` (#855) */
825
+ onLabel?: string;
826
+ /** 切の時に箱の字の差し込み (`{id}`) へ描く名前。 省略時は `false` (#855) */
827
+ offLabel?: string;
813
828
  }
814
829
  /**
815
830
  * XY pad = 2 軸 slider、 `.input.xypad(id)` は 実は 2 個の signal (id_x / id_y) を生成する
@@ -841,7 +856,7 @@ type CdlInput = {
841
856
  | {
842
857
  id: string;
843
858
  kind: "radio";
844
- options: readonly string[];
859
+ options: readonly CdlInputOption[];
845
860
  defaultValue: string;
846
861
  label?: string;
847
862
  }
@@ -867,7 +882,7 @@ type CdlInput = {
867
882
  | {
868
883
  id: string;
869
884
  kind: "multi-select";
870
- options: readonly string[];
885
+ options: readonly CdlInputOption[];
871
886
  defaultValues: readonly string[];
872
887
  label?: string;
873
888
  }
@@ -875,7 +890,7 @@ type CdlInput = {
875
890
  | {
876
891
  id: string;
877
892
  kind: "tabs";
878
- options: readonly string[];
893
+ options: readonly CdlInputOption[];
879
894
  defaultValue: string;
880
895
  label?: string;
881
896
  }
@@ -2999,4 +3014,4 @@ type CdlDiagramViewProps = {
2999
3014
  };
3000
3015
  declare function CdlDiagramView({ diagram, laid: laidProp, hideHeader, hideMiniPhaseIndicator, focusPhaseId, debug, emitGeometryWarn, headingLevel, interactiveHandlers }: CdlDiagramViewProps): JSX.Element;
3001
3016
 
3002
- export { computeInputSignalKey as $, EDGE_HEAD_FILLS as A, type BBox as B, type CdlDiagram as C, EDGE_HEAD_FILL_DEFAULT as D, type EdgeStyle as E, EDGE_REVEALS as F, EDGE_REVEAL_DEFAULT as G, EDGE_STYLES as H, type EdgeReveal as I, type JourneyEmotion as J, type InteractiveHandlerMap as K, type LaidDiagram as L, type InteractiveSignalsAccessor as M, type NodeKind as N, type LaidLane as O, NODE_KINDS as P, type QuadrantKey as Q, type RowMark as R, type Signal as S, type Tone as T, RELATION_FOCUSES as U, RELATION_FOCUS_DEFAULT as V, type RelationFocus as W, type ScrollProgressHandle as X, TONES as Y, computeEventBindingKey as Z, computeFormulaKey as _, type CdlInput as a, computeScrollTriggerKey as a0, computed as a1, createInteractiveSignalsAccessor as a2, createScrollProgressHandle as a3, createScrollProgressSignals as a4, hasInteractivePrimitives as a5, resolveLang as a6, sequenceBoardMetrics as a7, sequenceStepId as a8, signal as a9, type CdlLane as b, type CdlNode as c, type Side as d, type EdgeRole as e, type EdgeHead as f, type EdgeHeadFill as g, type CdlState as h, type CdlEventTarget as i, type CdlLang as j, type Computed as k, type CdlDerivedValue as l, type CdlScrollTrigger as m, type CdlDiagramViewProps as n, type LaidEdge as o, type LaidNode as p, type CdlEdge as q, CdlDiagramView as r, type CdlEventBinding as s, type CdlEventKind as t, type CdlFormula as u, type CdlPhase as v, type ChartPieForm as w, type ChartSlopeForm as x, EDGE_HEADS as y, EDGE_HEAD_DEFAULT as z };
3017
+ export { computeFormulaKey as $, EDGE_HEAD_DEFAULT as A, type BBox as B, type CdlDiagram as C, EDGE_HEAD_FILLS as D, type EdgeStyle as E, EDGE_HEAD_FILL_DEFAULT as F, EDGE_REVEALS as G, EDGE_REVEAL_DEFAULT as H, EDGE_STYLES as I, type JourneyEmotion as J, type EdgeReveal as K, type LaidDiagram as L, type InteractiveHandlerMap as M, type NodeKind as N, type InteractiveSignalsAccessor as O, type LaidLane as P, type QuadrantKey as Q, type RowMark as R, type Signal as S, type Tone as T, NODE_KINDS as U, RELATION_FOCUSES as V, RELATION_FOCUS_DEFAULT as W, type RelationFocus as X, type ScrollProgressHandle as Y, TONES as Z, computeEventBindingKey as _, type CdlInput as a, computeInputSignalKey as a0, computeScrollTriggerKey as a1, computed as a2, createInteractiveSignalsAccessor as a3, createScrollProgressHandle as a4, createScrollProgressSignals as a5, hasInteractivePrimitives as a6, resolveLang as a7, sequenceBoardMetrics as a8, sequenceStepId as a9, signal as aa, type CdlLane as b, type CdlNode as c, type Side as d, type EdgeRole as e, type EdgeHead as f, type EdgeHeadFill as g, type CdlState as h, type CdlInputOption as i, type CdlEventTarget as j, type CdlLang as k, type Computed as l, type CdlDerivedValue as m, type CdlScrollTrigger as n, type CdlDiagramViewProps as o, type LaidEdge as p, type LaidNode as q, type CdlEdge as r, CdlDiagramView as s, type CdlEventBinding as t, type CdlEventKind as u, type CdlFormula as v, type CdlPhase as w, type ChartPieForm as x, type ChartSlopeForm as y, EDGE_HEADS as z };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cardenelabs/cdl",
3
- "version": "0.60.0",
3
+ "version": "0.61.0",
4
4
  "description": "CDL (Chainome Diagram Language). Mermaid-like declarative DSL that compiles to animated SVG diagrams. Built for blockchain / Solidity flows, generic enough for sequence / flow / state / ER / topology diagrams.",
5
5
  "license": "MIT",
6
6
  "author": "cardene777",
package/src/builder.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { parseFormula } from "./formula";
2
+ import { 選択肢の値 } from "./input-option";
2
3
  import type { CdlLang } from "./lang";
3
4
  import type {
4
5
  CdlDiagram,
@@ -7,6 +8,7 @@ import type {
7
8
  CdlEventTarget,
8
9
  CdlFormula,
9
10
  CdlInput,
11
+ CdlInputOption,
10
12
  CdlLane,
11
13
  CdlNode,
12
14
  CdlPhase,
@@ -1284,11 +1286,11 @@ export type InputChain = {
1284
1286
  ) => DiagramBuilder;
1285
1287
  dropdown: (
1286
1288
  id: string,
1287
- opts: { options: readonly string[]; defaultValue: string; label?: string },
1289
+ opts: { options: readonly CdlInputOption[]; defaultValue: string; label?: string },
1288
1290
  ) => DiagramBuilder;
1289
1291
  toggle: (
1290
1292
  id: string,
1291
- opts: { defaultValue: boolean; label?: string },
1293
+ opts: { defaultValue: boolean; label?: string; onLabel?: string; offLabel?: string },
1292
1294
  ) => DiagramBuilder;
1293
1295
  /** 2 軸 slider = XY pad、 単一 id で pointer position を保持 (x/y は同 signal に格納) */
1294
1296
  xypad: (
@@ -1311,7 +1313,7 @@ export type InputChain = {
1311
1313
  /** 排他選択、 dropdown と同じ semantics だが視覚は横並び button */
1312
1314
  radio: (
1313
1315
  id: string,
1314
- opts: { options: readonly string[]; defaultValue: string; label?: string },
1316
+ opts: { options: readonly CdlInputOption[]; defaultValue: string; label?: string },
1315
1317
  ) => DiagramBuilder;
1316
1318
  /** hex color (#RRGGBB) picker、 SVG stroke / fill に signal 経由で bind */
1317
1319
  color: (
@@ -1339,11 +1341,11 @@ export type InputChain = {
1339
1341
  ) => DiagramBuilder;
1340
1342
  multiSelect: (
1341
1343
  id: string,
1342
- opts: { options: readonly string[]; defaultValues: readonly string[]; label?: string },
1344
+ opts: { options: readonly CdlInputOption[]; defaultValues: readonly string[]; label?: string },
1343
1345
  ) => DiagramBuilder;
1344
1346
  tabs: (
1345
1347
  id: string,
1346
- opts: { options: readonly string[]; defaultValue: string; label?: string },
1348
+ opts: { options: readonly CdlInputOption[]; defaultValue: string; label?: string },
1347
1349
  ) => DiagramBuilder;
1348
1350
  datetime: (
1349
1351
  id: string,
@@ -2008,9 +2010,10 @@ export function diagram(
2008
2010
  if (opts.options.length === 0) {
2009
2011
  throw new Error(`input.dropdown '${inputId}' の options が空です (最低 1 件必要)`);
2010
2012
  }
2011
- if (!opts.options.includes(opts.defaultValue)) {
2013
+ // 既定値は選択肢の値 (綴り) で比べる。 名前を渡すと入力欄に名前が入り、綴りで読む読み出しが読めない (#855)
2014
+ if (!opts.options.some((o) => 選択肢の値(o) === opts.defaultValue)) {
2012
2015
  throw new Error(
2013
- `input.dropdown '${inputId}' の defaultValue '${opts.defaultValue}' が options に含まれません (options: ${opts.options.join(", ")})`,
2016
+ `input.dropdown '${inputId}' の defaultValue '${opts.defaultValue}' が options の値に含まれません (options: ${opts.options.map(選択肢の値).join(", ")})`,
2014
2017
  );
2015
2018
  }
2016
2019
  inputs.push({
@@ -2028,6 +2031,9 @@ export function diagram(
2028
2031
  id: inputId,
2029
2032
  kind: "toggle",
2030
2033
  defaultValue: opts.defaultValue,
2034
+ // 名前を渡さない切り替えは変更前と同じ形に保つ (空の名前も渡さないのと同じ)
2035
+ ...(opts.onLabel ? { onLabel: opts.onLabel } : {}),
2036
+ ...(opts.offLabel ? { offLabel: opts.offLabel } : {}),
2031
2037
  label: opts.label,
2032
2038
  });
2033
2039
  return api;
@@ -2095,9 +2101,9 @@ export function diagram(
2095
2101
  if (opts.options.length === 0) {
2096
2102
  throw new Error(`input.radio '${inputId}' の options が空です`);
2097
2103
  }
2098
- if (!opts.options.includes(opts.defaultValue)) {
2104
+ if (!opts.options.some((o) => 選択肢の値(o) === opts.defaultValue)) {
2099
2105
  throw new Error(
2100
- `input.radio '${inputId}' の defaultValue '${opts.defaultValue}' が options に含まれません`,
2106
+ `input.radio '${inputId}' の defaultValue '${opts.defaultValue}' が options の値に含まれません`,
2101
2107
  );
2102
2108
  }
2103
2109
  inputs.push({
@@ -2183,8 +2189,8 @@ export function diagram(
2183
2189
  if (opts.options.length === 0) {
2184
2190
  throw new Error(`input.tabs '${inputId}' の options が空です`);
2185
2191
  }
2186
- if (!opts.options.includes(opts.defaultValue)) {
2187
- throw new Error(`input.tabs '${inputId}' の defaultValue が options に含まれません`);
2192
+ if (!opts.options.some((o) => 選択肢の値(o) === opts.defaultValue)) {
2193
+ throw new Error(`input.tabs '${inputId}' の defaultValue が options の値に含まれません`);
2188
2194
  }
2189
2195
  inputs.push({
2190
2196
  id: inputId,
package/src/index.ts CHANGED
@@ -8,7 +8,7 @@ export type { Signal, Computed } from "./reactive";
8
8
  // 追加、 consumer app 側 HTML widget と signal 経由で bind する。 cdl 自身は widget を描画せず metadata のみ。
9
9
  export { createInputSignals, inputDefaultValue } from "./input-signals";
10
10
  export type { InputChain } from "./builder";
11
- export type { CdlInput } from "./types";
11
+ export type { CdlInput, CdlInputOption } from "./types";
12
12
 
13
13
  // 描画側が書く固定の字の言語 (#847)。 図の `lang` に渡す値と、記法の文字列を言語に直す関数。
14
14
  // 辞書そのものは公開しない = 字の一覧は描画の実装に属し、利用側が辞書の中身に依存すると
@@ -0,0 +1,62 @@
1
+ import type { CdlInput, CdlInputOption } from "./types";
2
+
3
+ /**
4
+ * 入力欄の値と、画面に描く名前を分けて読む (#855)。
5
+ *
6
+ * 選択肢は文字列 (値と名前を兼ねる) か `{ value, label }` の組で書ける。 値は入力欄に入り、
7
+ * 綴りで読む読み出しと表示の出し分けが読む。 名前は操作部の選択肢と箱の字の差し込みにだけ描く。
8
+ */
9
+
10
+ /** 選択肢の値 (入力欄に入る綴り) */
11
+ export function 選択肢の値(option: CdlInputOption): string {
12
+ return typeof option === "string" ? option : option.value;
13
+ }
14
+
15
+ /** 選択肢の名前 (画面に描く字)。 名前が空なら値を描く */
16
+ export function 選択肢の名前(option: CdlInputOption): string {
17
+ return typeof option === "string" || option.label === "" ? 選択肢の値(option) : option.label;
18
+ }
19
+
20
+ /** 1 つの入力欄の値ごとの名前。 `複数` は値を `,` でつないで持つ入力欄 (`multi-select`) */
21
+ export type 入力欄の名前 = { readonly 名前: ReadonlyMap<string, string>; readonly 複数: boolean };
22
+
23
+ /** 入力欄の id → 値ごとの名前の表。 名前を持つ入力欄だけを載せる */
24
+ export type 値の名前の表 = ReadonlyMap<string, 入力欄の名前>;
25
+
26
+ /**
27
+ * 図の入力欄から、値ごとの名前の表を作る。
28
+ *
29
+ * 載せるのは名前を書いた値だけ。 名前を 1 つも持たない入力欄は表に載らないので、
30
+ * 名前を書かない図の差し込みは変更前と同じ字になる。
31
+ */
32
+ export function 値の名前の表を作る(inputs: readonly CdlInput[] | undefined): 値の名前の表 {
33
+ const 表 = new Map<string, 入力欄の名前>();
34
+ for (const input of inputs ?? []) {
35
+ const 名前 = new Map<string, string>();
36
+ if (input.kind === "dropdown" || input.kind === "radio" || input.kind === "tabs" || input.kind === "multi-select") {
37
+ for (const option of input.options) {
38
+ if (typeof option !== "string" && option.label !== "") 名前.set(option.value, option.label);
39
+ }
40
+ } else if (input.kind === "toggle") {
41
+ if (input.onLabel) 名前.set("true", input.onLabel);
42
+ if (input.offLabel) 名前.set("false", input.offLabel);
43
+ }
44
+ if (名前.size > 0) 表.set(input.id, { 名前, 複数: input.kind === "multi-select" });
45
+ }
46
+ return 表;
47
+ }
48
+
49
+ /**
50
+ * 差し込む値を名前で読む。 名前を持たない値は綴りのまま返す。
51
+ *
52
+ * `multi-select` の値は選んだ値を `,` でつないだ文字列 (`"a,b"`) なので、値ごとに名前へ置き換えて
53
+ * つなぎ直す。 つなぎの字は `,` のまま (図の言語を持たない差し込みで、特定の言語の読点を選ばない)。
54
+ * それ以外の入力欄は値全体を 1 つとして引く (値に `,` を含む選択肢を割らない)。
55
+ */
56
+ export function 値を名前で読む(入力欄: 入力欄の名前, 値: string): string {
57
+ if (!入力欄.複数) return 入力欄.名前.get(値) ?? 値;
58
+ return 値
59
+ .split(",")
60
+ .map((v) => 入力欄.名前.get(v) ?? v)
61
+ .join(",");
62
+ }
@@ -3,6 +3,7 @@ import type { JSX } from "react";
3
3
  import type { LaidNode, NodeKind } from "../types";
4
4
  import { toneColor } from "./node-tone";
5
5
  import { interpolate } from "../render/utils";
6
+ import type { 値の名前の表 } from "../input-option";
6
7
  import {
7
8
  genericTextCentered,
8
9
  genericTextShift,
@@ -235,11 +236,14 @@ export function GenericNode({
235
236
  active,
236
237
  value,
237
238
  stateValues,
239
+ 値の名前,
238
240
  }: {
239
241
  node: LaidNode;
240
242
  active: boolean;
241
243
  value: string | undefined;
242
244
  stateValues: Record<string, string>;
245
+ /** 入力欄の値ごとの名前 (#855)。 値と行の差し込みに使う */
246
+ 値の名前?: 値の名前の表;
243
247
  }): JSX.Element {
244
248
  const base = STYLES[node.kind] ?? FALLBACK;
245
249
  // `tone` 指定があれば kind の既定色を置き換える。 色を決める式は `node-tone.ts` に集約。
@@ -357,7 +361,7 @@ export function GenericNode({
357
361
  // 独自に書いていた間、 解決できない参照を空文字に潰していた = 書き間違いが
358
362
  // 「値が無い」 と区別できなかった。
359
363
  // 共通経路は解決できない参照を `{名前}` のまま残すので、 読み手が気付ける。
360
- const resolvedValue = value !== undefined ? interpolate(value, stateValues) : undefined;
364
+ const resolvedValue = value !== undefined ? interpolate(value, stateValues, 値の名前) : undefined;
361
365
 
362
366
  /*
363
367
  * shape 別の text 配置 (diamond / cloud は中心揃え、 rect 等は左上揃え)。
@@ -449,7 +453,7 @@ export function GenericNode({
449
453
  // rightColX (= 左列 max 幅 + gap) で右列開始 x を揃える (DB table / UML class 風)。
450
454
  // 旧実装は split(":") 単一 delimiter + 右 anchor (node 右端寄せ) で行毎にズレていた。
451
455
  // value と同じく engine 共通の経路で解決する (独自に書くと字種と既定値がずれる)
452
- const resolved = node.rows.map((row) => interpolate(row, stateValues));
456
+ const resolved = node.rows.map((row) => interpolate(row, stateValues, 値の名前));
453
457
  const splits = resolved.map(splitRow);
454
458
  // 左列は比例の書体で描く (`font-family` を指定していないので継承する)。 字数に一定を
455
459
  // 掛ける形では実物に届かず、 右列が左列の字に重なる (`#425`)。 字ごとの幅で見積もる。
@@ -4,6 +4,7 @@ import { CDL_TEXT, resolveLang, 字を差し込む, type CdlLang, type CdlTextKe
4
4
  import { assertNever } from "../assert-never";
5
5
  import type { CdlDiagram, CdlInput, CdlReadout } from "../types";
6
6
  import { createInputSignals, inputDefaultValue } from "../input-signals";
7
+ import { 選択肢の値, 選択肢の名前 } from "../input-option";
7
8
  import { createFormulaComputeds } from "../formula";
8
9
  import { 式を名札で読む } from "../formula/parser";
9
10
  import {
@@ -781,9 +782,10 @@ function InputWidget({
781
782
  data-cdl-input={input.id}
782
783
  className="cdl-ip-dropdown-select"
783
784
  >
785
+ {/* 値は綴りのまま入力欄に入れ、字だけを選択肢の名前で描く (#855) */}
784
786
  {input.options.map((opt) => (
785
- <option key={opt} value={opt}>
786
- {opt}
787
+ <option key={選択肢の値(opt)} value={選択肢の値(opt)}>
788
+ {選択肢の名前(opt)}
787
789
  </option>
788
790
  ))}
789
791
  </select>
@@ -799,19 +801,19 @@ function InputWidget({
799
801
  <legend className="cdl-ip-label">{label}</legend>
800
802
  <div className="cdl-ip-radio-options">
801
803
  {input.options.map((opt) => (
802
- <label key={opt} className="cdl-ip-radio-option">
804
+ <label key={選択肢の値(opt)} className="cdl-ip-radio-option">
803
805
  <input
804
806
  type="radio"
805
807
  name={input.id}
806
- value={opt}
807
- checked={value === opt}
808
+ value={選択肢の値(opt)}
809
+ checked={value === 選択肢の値(opt)}
808
810
  onChange={() => {
809
- signal.value = opt;
811
+ signal.value = 選択肢の値(opt);
810
812
  }}
811
813
  data-cdl-input={input.id}
812
814
  className="cdl-ip-radio-input"
813
815
  />
814
- <span className="cdl-ip-radio-label">{opt}</span>
816
+ <span className="cdl-ip-radio-label">{選択肢の名前(opt)}</span>
815
817
  </label>
816
818
  ))}
817
819
  </div>
@@ -864,16 +866,16 @@ function InputWidget({
864
866
  <div className="cdl-ip-tabs-bar" role="tablist">
865
867
  {input.options.map((opt) => (
866
868
  <button
867
- key={opt}
869
+ key={選択肢の値(opt)}
868
870
  type="button"
869
871
  role="tab"
870
- className={`cdl-ip-tabs-btn ${value === opt ? "cdl-ip-tabs-active" : ""}`}
872
+ className={`cdl-ip-tabs-btn ${value === 選択肢の値(opt) ? "cdl-ip-tabs-active" : ""}`}
871
873
  onClick={() => {
872
- signal.value = opt;
874
+ signal.value = 選択肢の値(opt);
873
875
  }}
874
876
  data-cdl-input={input.id}
875
877
  >
876
- {opt}
878
+ {選択肢の名前(opt)}
877
879
  </button>
878
880
  ))}
879
881
  </div>
@@ -2983,14 +2985,14 @@ function MultiSelectWidget({
2983
2985
  <div className="cdl-ip-multi-select-chips">
2984
2986
  {input.options.map((opt) => (
2985
2987
  <button
2986
- key={opt}
2988
+ key={選択肢の値(opt)}
2987
2989
  type="button"
2988
- className={`cdl-ip-multi-select-chip ${selected.has(opt) ? "cdl-ip-multi-select-active" : ""}`}
2989
- onClick={() => toggle(opt)}
2990
+ className={`cdl-ip-multi-select-chip ${selected.has(選択肢の値(opt)) ? "cdl-ip-multi-select-active" : ""}`}
2991
+ onClick={() => toggle(選択肢の値(opt))}
2990
2992
  data-cdl-input={input.id}
2991
- data-cdl-multi-value={opt}
2993
+ data-cdl-multi-value={選択肢の値(opt)}
2992
2994
  >
2993
- {opt}
2995
+ {選択肢の名前(opt)}
2994
2996
  </button>
2995
2997
  ))}
2996
2998
  </div>
@@ -89,6 +89,7 @@ import {
89
89
  import type { LaidNode } from "../types";
90
90
  import type { CdlLang } from "../lang";
91
91
  import { hasUnresolvedRef, interpolate, resolveNumericAttr } from "./utils";
92
+ import type { 値の名前の表 } from "../input-option";
92
93
 
93
94
  /**
94
95
  * 触れた箱の関係を光らせる時に、箱へ付ける受け口 (#806)。
@@ -117,9 +118,15 @@ export function CdlNodeView({
117
118
  chartLineScale,
118
119
  関係の受け口,
119
120
  lang,
121
+ 値の名前,
120
122
  }: {
121
123
  node: LaidNode;
122
124
  active: boolean;
125
+ /**
126
+ * 入力欄の値ごとの名前 (#855)。 箱の字の差し込みにだけ使い、表示の出し分けと数の差し込みには使わない。
127
+ * 渡さない呼び方は値を綴りのまま差し込む
128
+ */
129
+ 値の名前?: 値の名前の表;
123
130
  /** 描画側の固定の字の言語 (#847)。 字を持つ形の部品へ渡す。 渡さない呼び方は英語で描く */
124
131
  lang?: CdlLang;
125
132
  /**
@@ -134,8 +141,8 @@ export function CdlNodeView({
134
141
  /** 触れた箱の関係を光らせる時の受け口 (#806)。 書かない図では `undefined` */
135
142
  関係の受け口?: 関係の受け口;
136
143
  }): JSX.Element {
137
- const value = node.value ? interpolate(node.value, stateValues) : undefined;
138
- const rows = (node.rows ?? []).map((r) => interpolate(r, stateValues));
144
+ const value = node.value ? interpolate(node.value, stateValues, 値の名前) : undefined;
145
+ const rows = (node.rows ?? []).map((r) => interpolate(r, stateValues, 値の名前));
139
146
  // visual binding = wBind / hBind の template を stateValues で resolve、 layout の
140
147
  // static w/h を fallback として保持。 signal 値変化で node の描画寸法がリアルタイム変化する
141
148
  // (arc-intro 相当の 「slider で bar が伸びる」 UX の foundation)。
@@ -159,9 +166,9 @@ export function CdlNodeView({
159
166
  }
160
167
  const resolvedNode: LaidNode = {
161
168
  ...node,
162
- title: interpolate(node.title, stateValues),
163
- subtitle: node.subtitle ? interpolate(node.subtitle, stateValues) : node.subtitle,
164
- eyebrow: node.eyebrow ? interpolate(node.eyebrow, stateValues) : node.eyebrow,
169
+ title: interpolate(node.title, stateValues, 値の名前),
170
+ subtitle: node.subtitle ? interpolate(node.subtitle, stateValues, 値の名前) : node.subtitle,
171
+ eyebrow: node.eyebrow ? interpolate(node.eyebrow, stateValues, 値の名前) : node.eyebrow,
165
172
  w: boundW,
166
173
  h: boundH,
167
174
  };
@@ -442,7 +449,7 @@ export function CdlNodeView({
442
449
  return <MarkEndNode node={resolvedNode} active={active} />;
443
450
  default:
444
451
  // 新 NodeKind 25 種は GenericNode で汎用描画 (kind 別 icon / color / shape)
445
- return <GenericNode node={resolvedNode} active={active} value={node.value} stateValues={stateValues} />;
452
+ return <GenericNode node={resolvedNode} active={active} value={node.value} stateValues={stateValues} 値の名前={値の名前} />;
446
453
  }
447
454
  })();
448
455
  // node bounding box を node.w/h に固定するための invisible rect。
@@ -26,6 +26,7 @@ import { resolveChartData } from "./payload-binding";
26
26
  import { relatedFocusSet } from "./relation-focus";
27
27
  import { TONE, TONE_HEX } from "./tone";
28
28
  import { computeStateValues } from "./utils";
29
+ import type { 値の名前の表 } from "../input-option";
29
30
 
30
31
  export function CdlStage({
31
32
  laid,
@@ -36,8 +37,11 @@ export function CdlStage({
36
37
  debug,
37
38
  compact = false,
38
39
  svgRef,
40
+ 値の名前,
39
41
  }: {
40
42
  laid: LaidDiagram;
43
+ /** 入力欄の値ごとの名前 (#855)。 箱の字の差し込みへ渡す。 渡さない呼び方は値を綴りのまま差し込む */
44
+ 値の名前?: 値の名前の表;
41
45
  currentPhase: CdlPhase | undefined;
42
46
  progress: number;
43
47
  /**
@@ -432,6 +436,7 @@ export function CdlStage({
432
436
  drawing={描く}
433
437
  progress={描く ? 描く進み : progress}
434
438
  stateValues={stateValues}
439
+ 値の名前={値の名前}
435
440
  currentPhaseId={currentPhase?.id}
436
441
  chartLineScale={chartLineScales.get(node.id)}
437
442
  />
@@ -2,6 +2,7 @@ import { lerp } from "../anim";
2
2
  import type { LaidDiagram } from "../types";
3
3
  import { withDerivedValues } from "./derived-values";
4
4
  import { TEMPLATE_LEFTOVER_SRC, TEMPLATE_REF_SRC } from "../template-name";
5
+ import { 値を名前で読む, type 値の名前の表 } from "../input-option";
5
6
 
6
7
  const TEMPLATE_REF_RE = new RegExp(TEMPLATE_REF_SRC, "g");
7
8
  // 残っている参照の判定用。 `g` を付けないので `lastIndex` を持たず、 使い回しても結果が
@@ -113,14 +114,25 @@ export function mergeStateValues(
113
114
  *
114
115
  * 名前に使える文字は `template-name.ts` が決める (engine 全体で 1 つ)。 ここだけで
115
116
  * 定義すると、 式を書ける側との間で「読めるが書けない」 「書けるが読めない」 名前ができる。
117
+ *
118
+ * `名前の表` を渡すと、 付け足しの無い `{id}` の値を入力欄の値ごとの名前で差し込む (#855)。
119
+ * 渡すのは画面に字を描く所 (箱の題・副題・見出し・値・行) だけ。 表示の出し分けと数の差し込みは
120
+ * 値を綴りのまま読む必要があるので渡さない。
116
121
  */
117
- export function interpolate(template: string, values: Record<string, string>): string {
122
+ export function interpolate(
123
+ template: string,
124
+ values: Record<string, string>,
125
+ 名前の表?: 値の名前の表,
126
+ ): string {
118
127
  return template.replace(TEMPLATE_REF_RE, (_, id: string, accessor?: string) => {
119
128
  // 自分が持つ名前だけを見る。 継承を辿ると `{constructor}` が「値がある」 と読まれ、
120
129
  // prototype の中身が図に出る (実測)
121
130
  const raw = Object.hasOwn(values, id) ? values[id] : undefined;
122
131
  if (raw === undefined) return `{${id}${accessor ?? ""}}`;
123
- if (!accessor) return raw;
132
+ if (!accessor) {
133
+ const 入力欄 = 名前の表?.get(id);
134
+ return 入力欄 ? 値を名前で読む(入力欄, raw) : raw;
135
+ }
124
136
  const arr = parseArraySignal(raw);
125
137
  if (!arr) return `{${id}${accessor}}`;
126
138
  if (accessor === ".length") return String(arr.length);
package/src/render.tsx CHANGED
@@ -10,6 +10,7 @@ import {
10
10
  type InteractiveHandlerMap,
11
11
  } from "./render/interactive-panel";
12
12
  import { computeStateValues, mergeStateValues } from "./render/utils";
13
+ import { 値の名前の表を作る } from "./input-option";
13
14
  import { visualValidateLaid } from "./visual-validate";
14
15
  import type { CdlDiagram, LaidDiagram } from "./types";
15
16
 
@@ -165,6 +166,10 @@ export function CdlDiagramView({ diagram, laid: laidProp, hideHeader = false, hi
165
166
  return mergeStateValues(baseStateValues, interactive.stateOverrides);
166
167
  }, [isInteractive, baseStateValues, interactive.stateOverrides]);
167
168
 
169
+ // 入力欄の値ごとの名前 (#855)。 状態の値には混ぜず、箱の字の差し込みにだけ渡す
170
+ // (出し分けと綴りで読む読み出しは値を綴りのまま読む)
171
+ const 値の名前 = useMemo(() => 値の名前の表を作る(diagram.inputs), [diagram.inputs]);
172
+
168
173
  return (
169
174
  <div
170
175
  ref={isInteractive ? interactive.containerRef : undefined}
@@ -193,7 +198,7 @@ export function CdlDiagramView({ diagram, laid: laidProp, hideHeader = false, hi
193
198
  {/* interactive panel = input widget / formula readout / scroll readout (SVG の上に配置)、
194
199
  diagram に interactive primitive がなければ null (SSR / render 影響なし) */}
195
200
  {isInteractive && interactive.panel}
196
- <CdlStage laid={laid} currentPhase={currentPhase} progress={progress} drawProgress={drawProgress} stateValues={stateValues} debug={debug} compact={hideHeader} svgRef={isInteractive ? interactive.svgRef : undefined} />
201
+ <CdlStage laid={laid} currentPhase={currentPhase} progress={progress} drawProgress={drawProgress} stateValues={stateValues} 値の名前={値の名前} debug={debug} compact={hideHeader} svgRef={isInteractive ? interactive.svgRef : undefined} />
197
202
  {/* hideHeader + multi-phase 時、 phase indicator が消えると動きが読めないため
198
203
  mini indicator (dot 列 + 現在 phase title + badge) を bottom に追加 */}
199
204
  {hideHeader && !hideMiniPhaseIndicator && currentPhase && laid.phases.length > 1 && (