@cosmicdrift/kumiko-renderer-web 0.35.0 → 0.36.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-renderer-web",
3
- "version": "0.35.0",
3
+ "version": "0.36.0",
4
4
  "description": "Web-platform bindings for @cosmicdrift/kumiko-renderer. HTML default-primitives, browser history-based navigation, EventSource-backed live events, and a one-call createKumikoApp that mounts the whole stack via react-dom.",
5
5
  "license": "BUSL-1.1",
6
6
  "author": "Marc Frost <marc@cosmicdriftgamestudio.com>",
@@ -16,9 +16,9 @@
16
16
  "./styles.css": "./src/styles.css"
17
17
  },
18
18
  "dependencies": {
19
- "@cosmicdrift/kumiko-dispatcher-live": "0.21.0",
20
- "@cosmicdrift/kumiko-headless": "0.21.0",
21
- "@cosmicdrift/kumiko-renderer": "0.21.0",
19
+ "@cosmicdrift/kumiko-dispatcher-live": "0.35.0",
20
+ "@cosmicdrift/kumiko-headless": "0.35.0",
21
+ "@cosmicdrift/kumiko-renderer": "0.35.0",
22
22
  "@radix-ui/react-dialog": "^1.1.15",
23
23
  "@radix-ui/react-dropdown-menu": "^2.1.16",
24
24
  "@radix-ui/react-label": "^2.1.8",
@@ -3,7 +3,7 @@
3
3
  // Reine Funktionen aus primitives/index.tsx (exportiert für Test, wie
4
4
  // money-input seine Pure-Logik exportiert). Kein DOM.
5
5
 
6
- import { describe, expect, test } from "bun:test";
6
+ import { describe, expect, spyOn, test } from "bun:test";
7
7
  import {
8
8
  applyFormatSpec,
9
9
  computeVisiblePages,
@@ -100,9 +100,13 @@ describe("applyFormatSpec", () => {
100
100
  expect(applyFormatSpec({ format: "priority" }, 5)).toBe("5");
101
101
  });
102
102
 
103
- test("unbekanntes format → String(value) fallback", () => {
103
+ test("unbekanntes format → String(value) fallback + dev-warning", () => {
104
+ const warn = spyOn(console, "warn").mockImplementation(() => {});
104
105
  expect(applyFormatSpec({ format: "custom-app-format" }, 42)).toBe("42");
105
106
  expect(applyFormatSpec({ format: "custom-app-format" }, "hello")).toBe("hello");
107
+ expect(warn).toHaveBeenCalledTimes(2);
108
+ expect(warn.mock.calls[0]?.[0]).toContain("custom-app-format");
109
+ warn.mockRestore();
106
110
  });
107
111
  });
108
112
 
@@ -9,6 +9,7 @@
9
9
  // Dropdown etc. kommen später).
10
10
 
11
11
  import type { ListRowViewModel } from "@cosmicdrift/kumiko-headless";
12
+ import { applyFormatSpec } from "@cosmicdrift/kumiko-headless";
12
13
  import type {
13
14
  DataTableRowAction,
14
15
  DataTableSort,
@@ -1056,37 +1057,8 @@ export function isComponentRendererRef(renderer: unknown): { readonly name: stri
1056
1057
  return { name: component };
1057
1058
  }
1058
1059
 
1059
- // Applies a FormatSpec ({ format: "timestamp" } etc.) to a value.
1060
- // Handles all built-in FieldFormatRegistry keys; unknown app-specific keys
1061
- // fall back to String(value). Exported for unit tests.
1062
- export function applyFormatSpec(
1063
- spec: { format: string } & Record<string, unknown>,
1064
- value: unknown,
1065
- ): string {
1066
- if (value === null || value === undefined || value === "") return "";
1067
- switch (spec.format) {
1068
- case "timestamp":
1069
- case "date":
1070
- return formatDateCell(value, spec.format);
1071
- case "boolean": {
1072
- if (value === true) return (spec["trueLabel"] as string | undefined) ?? "✓";
1073
- if (value === false) return (spec["falseLabel"] as string | undefined) ?? "";
1074
- return "";
1075
- }
1076
- case "currency": {
1077
- const sym = (spec["symbol"] as string | undefined) ?? "";
1078
- return sym.length > 0 ? `${value} ${sym}` : String(value);
1079
- }
1080
- case "priority": {
1081
- const emptyLabel = (spec["emptyLabel"] as string | undefined) ?? "—";
1082
- const prefix = (spec["prefix"] as string | undefined) ?? "";
1083
- if (value === 0 || value === undefined || value === null) return emptyLabel;
1084
- return `${prefix}${value}`;
1085
- }
1086
- default:
1087
- return typeof value === "string" ? value : String(value);
1088
- }
1089
- }
1060
+ // applyFormatSpec re-exported from headless (platform-agnostic).
1061
+ export { applyFormatSpec };
1090
1062
 
1091
1063
  // Type-spezifische Default-Cell-Renderer. Author kann pro Spalte einen
1092
1064
  // expliziten renderer setzen (FormatSpec oder PlatformComponent); ohne
@@ -1103,7 +1075,7 @@ export function defaultCellRender(
1103
1075
  ): string {
1104
1076
  if (value === null || value === undefined || value === "") return "";
1105
1077
  if (type === "boolean") return value === true ? "✓" : "";
1106
- if (type === "timestamp" || type === "date") return formatDateCell(value, type);
1078
+ if (type === "timestamp" || type === "date") return applyFormatSpec({ format: type }, value);
1107
1079
  if (type === "select") {
1108
1080
  const raw = String(value);
1109
1081
  // Translated Label aus dem ViewModel-Builder (Convention-Key
@@ -1117,29 +1089,6 @@ export function defaultCellRender(
1117
1089
  return typeof value === "string" ? value : String(value);
1118
1090
  }
1119
1091
 
1120
- function formatDateCell(value: unknown, type: string): string {
1121
- // Server liefert ISO-String oder Temporal.Instant.toJSON() (gleicher
1122
- // ISO-shape). Für `type:"date"` zeigen wir nur das Datum, für
1123
- // `type:"timestamp"` Datum + Uhrzeit. Locale-Default = Browser.
1124
- try {
1125
- const raw = typeof value === "string" ? value : String(value);
1126
- const date = new Date(raw);
1127
- if (Number.isNaN(date.getTime())) return raw;
1128
- if (type === "date") {
1129
- return date.toLocaleDateString();
1130
- }
1131
- return date.toLocaleString(undefined, {
1132
- year: "numeric",
1133
- month: "short",
1134
- day: "numeric",
1135
- hour: "2-digit",
1136
- minute: "2-digit",
1137
- });
1138
- } catch {
1139
- return String(value);
1140
- }
1141
- }
1142
-
1143
1092
  function humanizeSlug(slug: string): string {
1144
1093
  // "degraded-performance" → "Degraded performance"
1145
1094
  if (slug.length === 0) return slug;