@cosmicdrift/kumiko-headless 0.240.0 → 0.242.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.
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cosmicdrift/kumiko-headless",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.242.0",
|
|
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.242.0",
|
|
40
40
|
"temporal-polyfill": "^0.3.2",
|
|
41
41
|
"zod": "^4.4.3"
|
|
42
42
|
},
|
|
@@ -209,6 +209,41 @@ describe("applyFormatSpec — enumOption (fw#2315)", () => {
|
|
|
209
209
|
});
|
|
210
210
|
});
|
|
211
211
|
|
|
212
|
+
describe("applyFormatSpec — boolean labels through translate (fw#2683)", () => {
|
|
213
|
+
const TRUE_KEY = "managed-pages:entity:page:field:published:option:true";
|
|
214
|
+
const FALSE_KEY = "managed-pages:entity:page:field:published:option:false";
|
|
215
|
+
const spec = { format: "boolean", trueLabel: TRUE_KEY, falseLabel: FALSE_KEY };
|
|
216
|
+
const translate = (key: string): string => {
|
|
217
|
+
if (key === TRUE_KEY) return "Published";
|
|
218
|
+
if (key === FALSE_KEY) return "Draft";
|
|
219
|
+
return key;
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
test("an i18n key as trueLabel renders translated", () => {
|
|
223
|
+
expect(applyFormatSpec(spec, true, translate)).toBe("Published");
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
test("an i18n key as falseLabel renders translated", () => {
|
|
227
|
+
expect(applyFormatSpec(spec, false, translate)).toBe("Draft");
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
test("without translate the declared labels stay verbatim", () => {
|
|
231
|
+
expect(applyFormatSpec(spec, true)).toBe(TRUE_KEY);
|
|
232
|
+
expect(applyFormatSpec(spec, false)).toBe(FALSE_KEY);
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
test("a plain-text label is not mangled by a pass-through translate", () => {
|
|
236
|
+
const plain = { format: "boolean", trueLabel: "Yes", falseLabel: "No" };
|
|
237
|
+
expect(applyFormatSpec(plain, true, (k) => k)).toBe("Yes");
|
|
238
|
+
expect(applyFormatSpec(plain, false, (k) => k)).toBe("No");
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
test("undeclared labels keep the ✓ / empty defaults even with translate", () => {
|
|
242
|
+
expect(applyFormatSpec({ format: "boolean" }, true, translate)).toBe("✓");
|
|
243
|
+
expect(applyFormatSpec({ format: "boolean" }, false, translate)).toBe("");
|
|
244
|
+
});
|
|
245
|
+
});
|
|
246
|
+
|
|
212
247
|
describe("unit format keys stay in lockstep with UnitKey", () => {
|
|
213
248
|
// Mirror of packages/types/src/screen.ts UnitKey — keep lists equal without
|
|
214
249
|
// adding a kumiko-types dependency to headless.
|
package/src/format/index.ts
CHANGED
|
@@ -162,8 +162,14 @@ export function applyFormatSpec(
|
|
|
162
162
|
: undefined,
|
|
163
163
|
});
|
|
164
164
|
case "boolean": {
|
|
165
|
-
if (value === true)
|
|
166
|
-
|
|
165
|
+
if (value === true) {
|
|
166
|
+
const trueLabel = spec["trueLabel"] as string | undefined;
|
|
167
|
+
return trueLabel === undefined ? "✓" : (translate?.(trueLabel) ?? trueLabel);
|
|
168
|
+
}
|
|
169
|
+
if (value === false) {
|
|
170
|
+
const falseLabel = spec["falseLabel"] as string | undefined;
|
|
171
|
+
return falseLabel === undefined ? "" : (translate?.(falseLabel) ?? falseLabel);
|
|
172
|
+
}
|
|
167
173
|
return "";
|
|
168
174
|
}
|
|
169
175
|
case "currency": {
|
|
@@ -195,6 +201,8 @@ export function applyFormatSpec(
|
|
|
195
201
|
const translated = translate(key);
|
|
196
202
|
return translated === key ? raw : translated;
|
|
197
203
|
}
|
|
204
|
+
case "json":
|
|
205
|
+
return JSON.stringify(value, null, (spec["indent"] as number | undefined) ?? 2);
|
|
198
206
|
default:
|
|
199
207
|
if (typeof process !== "undefined" && process.env.NODE_ENV !== "production") {
|
|
200
208
|
// biome-ignore lint/suspicious/noConsole: dev-only warning
|