@aiaiai-pt/design-system 0.46.1 → 0.46.2

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={Array.isArray(parameter.default_value)
1031
- ? (parameter.default_value as [number, number])
1032
- : undefined}
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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aiaiai-pt/design-system",
3
- "version": "0.46.1",
3
+ "version": "0.46.2",
4
4
  "description": "Design system tokens and Svelte components for aiaiai products",
5
5
  "license": "MIT",
6
6
  "type": "module",