@cosmicdrift/kumiko-headless 0.214.0 → 0.215.1
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.
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cosmicdrift/kumiko-headless",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.215.1",
|
|
4
4
|
"description": "Headless UI logic for Kumiko — Dispatcher contract, Form-Controller, View-Model, Nav-Resolver. Plattform- und React-frei; jeder Renderer (renderer, renderer-web, renderer-native, …) komponiert darauf.",
|
|
5
5
|
"license": "BUSL-1.1",
|
|
6
6
|
"author": "Marc Frost <marc@cosmicdriftgamestudio.com>",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
}
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@cosmicdrift/kumiko-framework": "0.
|
|
39
|
+
"@cosmicdrift/kumiko-framework": "0.215.1",
|
|
40
40
|
"temporal-polyfill": "^0.3.2",
|
|
41
41
|
"zod": "^4.4.3"
|
|
42
42
|
},
|
|
@@ -154,3 +154,38 @@ describe("applyFormatSpec — unit (fw#2187)", () => {
|
|
|
154
154
|
expect(applyFormatSpec({ format: "unit", unit: "km" }, "")).toBe("");
|
|
155
155
|
});
|
|
156
156
|
});
|
|
157
|
+
|
|
158
|
+
describe("applyFormatSpec — enumOption (fw#2315)", () => {
|
|
159
|
+
const spec = { format: "enumOption", keyPrefix: "contact:entity:contact:field:status:option:" };
|
|
160
|
+
|
|
161
|
+
test("übersetzter Key gewinnt gegen den Rohwert", () => {
|
|
162
|
+
const translate = (key: string) =>
|
|
163
|
+
key === "contact:entity:contact:field:status:option:active" ? "Aktiv" : key;
|
|
164
|
+
expect(applyFormatSpec(spec, "active", translate)).toBe("Aktiv");
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
test("unbekannter Key fällt auf den Rohwert zurück (translate gibt den Key unverändert zurück)", () => {
|
|
168
|
+
const translate = (key: string) => key;
|
|
169
|
+
expect(applyFormatSpec(spec, "active", translate)).toBe("active");
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
test("ohne translate-Parameter fällt auf den Rohwert zurück", () => {
|
|
173
|
+
expect(applyFormatSpec(spec, "active")).toBe("active");
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
test("ohne keyPrefix fällt auf den Rohwert zurück, auch mit translate", () => {
|
|
177
|
+
const translate = (key: string) => `translated:${key}`;
|
|
178
|
+
expect(applyFormatSpec({ format: "enumOption" }, "active", translate)).toBe("active");
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
test("nicht-string-Wert wird vor der Key-Bildung stringifiziert", () => {
|
|
182
|
+
const translate = (key: string) =>
|
|
183
|
+
key === "contact:entity:contact:field:status:option:1" ? "Eins" : key;
|
|
184
|
+
expect(applyFormatSpec(spec, 1, translate)).toBe("Eins");
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
test("leerer Wert collapst zu '' wie jedes andere Nicht-priority-Format", () => {
|
|
188
|
+
expect(applyFormatSpec(spec, null, (k) => k)).toBe("");
|
|
189
|
+
expect(applyFormatSpec(spec, "", (k) => k)).toBe("");
|
|
190
|
+
});
|
|
191
|
+
});
|
package/src/format/index.ts
CHANGED
|
@@ -134,6 +134,7 @@ export { currencyDecimals } from "./money";
|
|
|
134
134
|
export function applyFormatSpec(
|
|
135
135
|
spec: { format: string } & Record<string, unknown>,
|
|
136
136
|
value: unknown,
|
|
137
|
+
translate?: (key: string) => string,
|
|
137
138
|
): string {
|
|
138
139
|
const isEmpty = value === null || value === undefined || value === "";
|
|
139
140
|
// priority renders its emptyLabel for empty values — every other format
|
|
@@ -176,6 +177,14 @@ export function applyFormatSpec(
|
|
|
176
177
|
if (isEmpty || value === 0) return emptyLabel;
|
|
177
178
|
return `${prefix}${value}`;
|
|
178
179
|
}
|
|
180
|
+
case "enumOption": {
|
|
181
|
+
const raw = typeof value === "string" ? value : String(value);
|
|
182
|
+
const keyPrefix = spec["keyPrefix"] as string | undefined;
|
|
183
|
+
if (keyPrefix === undefined || translate === undefined) return raw;
|
|
184
|
+
const key = `${keyPrefix}${raw}`;
|
|
185
|
+
const translated = translate(key);
|
|
186
|
+
return translated === key ? raw : translated;
|
|
187
|
+
}
|
|
179
188
|
default:
|
|
180
189
|
if (typeof process !== "undefined" && process.env.NODE_ENV !== "production") {
|
|
181
190
|
// biome-ignore lint/suspicious/noConsole: dev-only warning
|