@cardenelabs/cdl 0.63.0 → 0.64.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.
@@ -1086,7 +1086,10 @@ type CdlReadout = {
1086
1086
  id: string;
1087
1087
  kind: "badge";
1088
1088
  source: string;
1089
- /** color source (default source と同じ)、 別 signal で色を切替可能 */
1089
+ /**
1090
+ * 色を引く状態 (#861)。 書くと `map` をこの状態の値で引き、札の字は `source` の値のまま。
1091
+ * 書かなければ `source` の値で引く。 書いた状態が無い時は色を付けない (`source` に戻さない)
1092
+ */
1090
1093
  colorSource?: string;
1091
1094
  /** 値と色 mapping (例: [{value: 'ok', color: 'green'}])、 未指定なら brand 色 */
1092
1095
  map?: readonly {
@@ -1086,7 +1086,10 @@ type CdlReadout = {
1086
1086
  id: string;
1087
1087
  kind: "badge";
1088
1088
  source: string;
1089
- /** color source (default source と同じ)、 別 signal で色を切替可能 */
1089
+ /**
1090
+ * 色を引く状態 (#861)。 書くと `map` をこの状態の値で引き、札の字は `source` の値のまま。
1091
+ * 書かなければ `source` の値で引く。 書いた状態が無い時は色を付けない (`source` に戻さない)
1092
+ */
1090
1093
  colorSource?: string;
1091
1094
  /** 値と色 mapping (例: [{value: 'ok', color: 'green'}])、 未指定なら brand 色 */
1092
1095
  map?: readonly {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cardenelabs/cdl",
3
- "version": "0.63.0",
3
+ "version": "0.64.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",
@@ -57,6 +57,16 @@
57
57
  "node": ">=18"
58
58
  },
59
59
  "sideEffects": false,
60
+ "scripts": {
61
+ "build": "tsup",
62
+ "dev": "tsup --watch",
63
+ "typecheck": "tsc --noEmit",
64
+ "test": "cd ../.. && vitest run packages/cdl",
65
+ "lint": "tsc --noEmit",
66
+ "prepublishOnly": "pnpm run typecheck && pnpm run build",
67
+ "prepack": "node scripts/prepack-check.mjs",
68
+ "postpack": "node scripts/prepack-check.mjs"
69
+ },
60
70
  "peerDependencies": {
61
71
  "react": "^19.0.0",
62
72
  "react-dom": "^19.0.0"
@@ -68,12 +78,5 @@
68
78
  "typedoc": "^0.28.19",
69
79
  "typedoc-plugin-markdown": "^4.12.0",
70
80
  "typescript": "^5.8.0"
71
- },
72
- "scripts": {
73
- "build": "tsup",
74
- "dev": "tsup --watch",
75
- "typecheck": "tsc --noEmit",
76
- "test": "cd ../.. && vitest run packages/cdl",
77
- "lint": "tsc --noEmit"
78
81
  }
79
- }
82
+ }
@@ -1280,15 +1280,15 @@ function ReadoutWidget({
1280
1280
  colors={readout.colors ?? ["#e0e6ef", "#2d6a8f"]}
1281
1281
  />
1282
1282
  );
1283
- case "badge":
1284
- return (
1285
- <BadgeReadout
1286
- id={readout.id}
1287
- label={label}
1288
- value={typeof rawValue === "string" ? rawValue : String(rawValue ?? "")}
1289
- map={readout.map}
1290
- />
1291
- );
1283
+ case "badge": {
1284
+ const value = typeof rawValue === "string" ? rawValue : String(rawValue ?? "");
1285
+ // 色を引く鍵は `colorSource` を書けばその状態の値、書かなければ札の字と同じ値 (#861)。
1286
+ // 書いた状態が無い時は `source` の値に戻さない = 書き間違いが効いているように見えない
1287
+ const colorRaw = readout.colorSource === undefined ? undefined : stateOverrides[readout.colorSource];
1288
+ const colorKey =
1289
+ readout.colorSource === undefined ? value : colorRaw === undefined ? undefined : String(colorRaw);
1290
+ return <BadgeReadout id={readout.id} label={label} value={value} colorKey={colorKey} map={readout.map} />;
1291
+ }
1292
1292
  case "status-dot":
1293
1293
  return (
1294
1294
  <StatusDotReadout
@@ -3041,14 +3041,18 @@ function BadgeReadout({
3041
3041
  id,
3042
3042
  label,
3043
3043
  value,
3044
+ colorKey,
3044
3045
  map,
3045
3046
  }: {
3046
3047
  id: string;
3047
3048
  label: string;
3049
+ /** 札に出す字 */
3048
3050
  value: string;
3051
+ /** `map` を引く鍵。 無ければどの色にも当てない */
3052
+ colorKey: string | undefined;
3049
3053
  map?: readonly { value: string; color: string }[];
3050
3054
  }): JSX.Element {
3051
- const entry = map?.find((m) => m.value === value);
3055
+ const entry = colorKey === undefined ? undefined : map?.find((m) => m.value === colorKey);
3052
3056
  const color = entry?.color;
3053
3057
  return (
3054
3058
  <div className="cdl-ip-item cdl-ip-readout-badge" data-cdl-readout={id}>
package/src/types.ts CHANGED
@@ -1150,7 +1150,10 @@ export type CdlReadout =
1150
1150
  id: string;
1151
1151
  kind: "badge";
1152
1152
  source: string;
1153
- /** color source (default source と同じ)、 別 signal で色を切替可能 */
1153
+ /**
1154
+ * 色を引く状態 (#861)。 書くと `map` をこの状態の値で引き、札の字は `source` の値のまま。
1155
+ * 書かなければ `source` の値で引く。 書いた状態が無い時は色を付けない (`source` に戻さない)
1156
+ */
1154
1157
  colorSource?: string;
1155
1158
  /** 値と色 mapping (例: [{value: 'ok', color: 'green'}])、 未指定なら brand 色 */
1156
1159
  map?: readonly { value: string; color: string }[];