@aiaiai-pt/design-system 0.46.1 → 0.46.3
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.
|
@@ -54,6 +54,7 @@
|
|
|
54
54
|
dateToDateOnly,
|
|
55
55
|
geoJsonPointToLonLat,
|
|
56
56
|
lonLatToGeoJsonPoint,
|
|
57
|
+
mapInitialCenter,
|
|
57
58
|
storedFileDescriptor,
|
|
58
59
|
widgetKind,
|
|
59
60
|
} from "./action-form-renderer-widgets";
|
|
@@ -1007,6 +1008,7 @@
|
|
|
1007
1008
|
{onoutofbounds}
|
|
1008
1009
|
error={fieldError ?? hydrated.error ?? geoError}
|
|
1009
1010
|
label={String(parameter.label ?? key)}
|
|
1011
|
+
center={mapInitialCenter(parameter)}
|
|
1010
1012
|
value={hydrated.coords ?? undefined}
|
|
1011
1013
|
onchange={(coords: [number, number]) => setValue(key, lonLatToGeoJsonPoint(coords))}
|
|
1012
1014
|
/>
|
|
@@ -1027,9 +1029,10 @@
|
|
|
1027
1029
|
{onoutofbounds}
|
|
1028
1030
|
error={fieldError ?? geoError}
|
|
1029
1031
|
label={String(parameter.label ?? key)}
|
|
1030
|
-
center={
|
|
1031
|
-
|
|
1032
|
-
|
|
1032
|
+
center={mapInitialCenter(parameter) ??
|
|
1033
|
+
(Array.isArray(parameter.default_value)
|
|
1034
|
+
? (parameter.default_value as [number, number])
|
|
1035
|
+
: undefined)}
|
|
1033
1036
|
value={Array.isArray(values[key])
|
|
1034
1037
|
? (values[key] as [number, number])
|
|
1035
1038
|
: undefined}
|
|
@@ -27,6 +27,17 @@ export declare function geoJsonPointToLonLat(value: unknown): {
|
|
|
27
27
|
};
|
|
28
28
|
/** #39 — serialize a placed pin back onto the GeoJSON wire shape. */
|
|
29
29
|
export declare function lonLatToGeoJsonPoint(coords: [number, number]): GeoJsonPoint;
|
|
30
|
+
/** #46 — the map picker's INITIAL CENTRE, from its declared home:
|
|
31
|
+
* `ui_schema.map.initial_center` ([lon, lat]). A viewport hint is
|
|
32
|
+
* presentation, not a value — it lives in ui_schema so `default_value`
|
|
33
|
+
* keeps its one meaning (the initial VALUE). Malformed/absent → undefined
|
|
34
|
+
* (the picker keeps its own default). Consumers still passing a bare
|
|
35
|
+
* [lon, lat] `default_value` on a legacy geo param keep working via the
|
|
36
|
+
* renderer's fallback (deprecated; removed next minor). */
|
|
37
|
+
export declare function mapInitialCenter(parameter: {
|
|
38
|
+
ui_schema?: unknown;
|
|
39
|
+
[key: string]: unknown;
|
|
40
|
+
}): [number, number] | undefined;
|
|
30
41
|
export type StoredFile = {
|
|
31
42
|
name: string;
|
|
32
43
|
url?: string;
|
|
@@ -95,6 +95,37 @@ export function lonLatToGeoJsonPoint(coords: [number, number]): GeoJsonPoint {
|
|
|
95
95
|
return { type: "Point", coordinates: [coords[0], coords[1]] };
|
|
96
96
|
}
|
|
97
97
|
|
|
98
|
+
/** #46 — the map picker's INITIAL CENTRE, from its declared home:
|
|
99
|
+
* `ui_schema.map.initial_center` ([lon, lat]). A viewport hint is
|
|
100
|
+
* presentation, not a value — it lives in ui_schema so `default_value`
|
|
101
|
+
* keeps its one meaning (the initial VALUE). Malformed/absent → undefined
|
|
102
|
+
* (the picker keeps its own default). Consumers still passing a bare
|
|
103
|
+
* [lon, lat] `default_value` on a legacy geo param keep working via the
|
|
104
|
+
* renderer's fallback (deprecated; removed next minor). */
|
|
105
|
+
export function mapInitialCenter(parameter: {
|
|
106
|
+
ui_schema?: unknown;
|
|
107
|
+
[key: string]: unknown;
|
|
108
|
+
}): [number, number] | undefined {
|
|
109
|
+
const ui =
|
|
110
|
+
parameter.ui_schema && typeof parameter.ui_schema === "object"
|
|
111
|
+
? (parameter.ui_schema as Record<string, unknown>)
|
|
112
|
+
: null;
|
|
113
|
+
const map =
|
|
114
|
+
ui?.map && typeof ui.map === "object"
|
|
115
|
+
? (ui.map as Record<string, unknown>)
|
|
116
|
+
: null;
|
|
117
|
+
const c = map?.initial_center;
|
|
118
|
+
if (
|
|
119
|
+
Array.isArray(c) &&
|
|
120
|
+
c.length >= 2 &&
|
|
121
|
+
typeof c[0] === "number" &&
|
|
122
|
+
typeof c[1] === "number"
|
|
123
|
+
) {
|
|
124
|
+
return [c[0], c[1]];
|
|
125
|
+
}
|
|
126
|
+
return undefined;
|
|
127
|
+
}
|
|
128
|
+
|
|
98
129
|
export type StoredFile = { name: string; url?: string };
|
|
99
130
|
|
|
100
131
|
/** #40 — normalize a file param's stored-current value (the edit form's
|
|
@@ -22,15 +22,24 @@
|
|
|
22
22
|
* Everything here is PURE and dependency-free.
|
|
23
23
|
*/
|
|
24
24
|
export type ObjectFallback = "redact" | "json";
|
|
25
|
+
/** How a boolean renders: "raw" (default) → "true"/"false" (both hosts'
|
|
26
|
+
* historical output); "yes-no" → "Yes"/"No" (the staff admin's cell copy —
|
|
27
|
+
* #748 lifts it here so the admin's private renderCell fork can retire). */
|
|
28
|
+
export type BooleanDisplay = "raw" | "yes-no";
|
|
25
29
|
/**
|
|
26
|
-
* Pure value → display string. Scalars stringify
|
|
27
|
-
* formatted members; a
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
30
|
+
* Pure value → display string. Scalars stringify (booleans per
|
|
31
|
+
* `booleanDisplay`); arrays join their non-empty formatted members; a
|
|
32
|
+
* disclosed relationship object renders its human handle
|
|
33
|
+
* (label→name→display_name→title→code) then its id — `display_name`/`code`
|
|
34
|
+
* joined the order in #748 so an expanded rel carrying only those (ontology
|
|
35
|
+
* rows commonly do) renders its handle, not its UUID. An UNKNOWN object
|
|
36
|
+
* renders per `objectFallback`: "redact" (default) → "" (never dumps
|
|
37
|
+
* internals — the public security boundary); "json" → pretty JSON (the admin
|
|
38
|
+
* operator view).
|
|
31
39
|
*/
|
|
32
40
|
export declare function formatScalar(value: unknown, opts?: {
|
|
33
41
|
objectFallback?: ObjectFallback;
|
|
42
|
+
booleanDisplay?: BooleanDisplay;
|
|
34
43
|
}): string;
|
|
35
44
|
/** True for an ISO-8601 timestamp STRING (not a bare date). Value-shape
|
|
36
45
|
* detection — used where the schema can't tell us the field is a datetime. */
|
|
@@ -60,6 +69,7 @@ export declare function displayCell(value: unknown, locale: string, opts?: {
|
|
|
60
69
|
treatAsDate?: boolean;
|
|
61
70
|
treatAsDateTime?: boolean;
|
|
62
71
|
objectFallback?: ObjectFallback;
|
|
72
|
+
booleanDisplay?: BooleanDisplay;
|
|
63
73
|
}): string;
|
|
64
74
|
/** Operator copy for a status value (falls back to the raw value). `labels` is
|
|
65
75
|
* untrusted DATA — a non-object/array is ignored. */
|
|
@@ -24,21 +24,37 @@
|
|
|
24
24
|
|
|
25
25
|
export type ObjectFallback = "redact" | "json";
|
|
26
26
|
|
|
27
|
+
/** How a boolean renders: "raw" (default) → "true"/"false" (both hosts'
|
|
28
|
+
* historical output); "yes-no" → "Yes"/"No" (the staff admin's cell copy —
|
|
29
|
+
* #748 lifts it here so the admin's private renderCell fork can retire). */
|
|
30
|
+
export type BooleanDisplay = "raw" | "yes-no";
|
|
31
|
+
|
|
27
32
|
/**
|
|
28
|
-
* Pure value → display string. Scalars stringify
|
|
29
|
-
* formatted members; a
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
+
* Pure value → display string. Scalars stringify (booleans per
|
|
34
|
+
* `booleanDisplay`); arrays join their non-empty formatted members; a
|
|
35
|
+
* disclosed relationship object renders its human handle
|
|
36
|
+
* (label→name→display_name→title→code) then its id — `display_name`/`code`
|
|
37
|
+
* joined the order in #748 so an expanded rel carrying only those (ontology
|
|
38
|
+
* rows commonly do) renders its handle, not its UUID. An UNKNOWN object
|
|
39
|
+
* renders per `objectFallback`: "redact" (default) → "" (never dumps
|
|
40
|
+
* internals — the public security boundary); "json" → pretty JSON (the admin
|
|
41
|
+
* operator view).
|
|
33
42
|
*/
|
|
34
43
|
export function formatScalar(
|
|
35
44
|
value: unknown,
|
|
36
|
-
opts: {
|
|
45
|
+
opts: {
|
|
46
|
+
objectFallback?: ObjectFallback;
|
|
47
|
+
booleanDisplay?: BooleanDisplay;
|
|
48
|
+
} = {},
|
|
37
49
|
): string {
|
|
38
50
|
// `== null` catches both null and undefined.
|
|
39
51
|
if (value == null) return "";
|
|
40
52
|
if (typeof value === "string") return value;
|
|
41
|
-
if (typeof value === "
|
|
53
|
+
if (typeof value === "boolean") {
|
|
54
|
+
if (opts.booleanDisplay === "yes-no") return value ? "Yes" : "No";
|
|
55
|
+
return String(value);
|
|
56
|
+
}
|
|
57
|
+
if (typeof value === "number") {
|
|
42
58
|
return String(value);
|
|
43
59
|
}
|
|
44
60
|
if (Array.isArray(value)) {
|
|
@@ -49,7 +65,7 @@ export function formatScalar(
|
|
|
49
65
|
}
|
|
50
66
|
if (typeof value === "object") {
|
|
51
67
|
const o = value as Record<string, unknown>;
|
|
52
|
-
for (const k of ["label", "name", "title"]) {
|
|
68
|
+
for (const k of ["label", "name", "display_name", "title", "code"]) {
|
|
53
69
|
const v = o[k];
|
|
54
70
|
if (typeof v === "string" && v) return v;
|
|
55
71
|
}
|
|
@@ -130,6 +146,7 @@ export function displayCell(
|
|
|
130
146
|
treatAsDate?: boolean;
|
|
131
147
|
treatAsDateTime?: boolean;
|
|
132
148
|
objectFallback?: ObjectFallback;
|
|
149
|
+
booleanDisplay?: BooleanDisplay;
|
|
133
150
|
} = {},
|
|
134
151
|
): string {
|
|
135
152
|
if (typeof value === "string" && value) {
|
|
@@ -137,7 +154,10 @@ export function displayCell(
|
|
|
137
154
|
if (opts.treatAsDateTime) return formatDateTime(value, locale);
|
|
138
155
|
}
|
|
139
156
|
if (isIsoTimestamp(value)) return formatTimestamp(value, locale);
|
|
140
|
-
return formatScalar(value, {
|
|
157
|
+
return formatScalar(value, {
|
|
158
|
+
objectFallback: opts.objectFallback,
|
|
159
|
+
booleanDisplay: opts.booleanDisplay,
|
|
160
|
+
});
|
|
141
161
|
}
|
|
142
162
|
|
|
143
163
|
/** Operator copy for a status value (falls back to the raw value). `labels` is
|