@aiaiai-pt/design-system 0.62.0 → 0.63.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/components/ActionFormRenderer.svelte +36 -9
- package/components/ActionFormRenderer.svelte.d.ts +8 -0
- package/components/GeoSearch.svelte +7 -5
- package/components/MapPicker.svelte +27 -3
- package/components/action-form-renderer-widgets.d.ts +11 -0
- package/components/action-form-renderer-widgets.ts +30 -9
- package/package.json +1 -1
|
@@ -55,6 +55,7 @@
|
|
|
55
55
|
dateToDateOnly,
|
|
56
56
|
geometryFieldPlan,
|
|
57
57
|
lonLatToGeoJsonPoint,
|
|
58
|
+
mapGeocoderUrl,
|
|
58
59
|
mapInitialCenter,
|
|
59
60
|
storedFileDescriptor,
|
|
60
61
|
widgetKind,
|
|
@@ -160,6 +161,14 @@
|
|
|
160
161
|
/** Inline error rendered by the geo MapPicker(s) (e.g. the consumer's
|
|
161
162
|
* out-of-bounds copy) — forwarded as MapPicker's `error`. */
|
|
162
163
|
geoError?: string;
|
|
164
|
+
/** The host's geocoder: a Nominatim-compatible `/search` URL forwarded as
|
|
165
|
+
* `searchProviderUrl` to EVERY MapPicker the renderer mounts (`geo`
|
|
166
|
+
* params and `geometry` params in every mode); reverse geocoding uses
|
|
167
|
+
* the same base with `/reverse`. It WINS over a parameter's
|
|
168
|
+
* `ui_schema.map.geocoder_url` — which geocoder the browser may call is
|
|
169
|
+
* the host's policy. Unset (and no declaration) → the picker's own
|
|
170
|
+
* default (public Nominatim), unchanged. */
|
|
171
|
+
geocoderUrl?: string;
|
|
163
172
|
/** Service-flow wizard (#105 P6): render ONLY the section whose
|
|
164
173
|
* name (its label, falling back to its key) matches — one screen per
|
|
165
174
|
* step. The value bag still spans ALL parameters (so answers persist
|
|
@@ -238,6 +247,7 @@
|
|
|
238
247
|
layers = [],
|
|
239
248
|
onoutofbounds = undefined,
|
|
240
249
|
geoError = undefined,
|
|
250
|
+
geocoderUrl = undefined,
|
|
241
251
|
activeSectionKey = null,
|
|
242
252
|
hideSubmit = false,
|
|
243
253
|
onchange = undefined,
|
|
@@ -527,6 +537,25 @@
|
|
|
527
537
|
return "";
|
|
528
538
|
}
|
|
529
539
|
|
|
540
|
+
/** The geocoder a parameter's MapPicker calls: the host's `geocoderUrl`,
|
|
541
|
+
* else the parameter's `ui_schema.map.geocoder_url`, else undefined (the
|
|
542
|
+
* picker's default). */
|
|
543
|
+
function geocoderFor(parameter: Entity): string | undefined {
|
|
544
|
+
return geocoderUrl || mapGeocoderUrl(parameter);
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
/** SIBLING-ADDRESS CONVENTION, shared by every POINT map field (`geo` and
|
|
548
|
+
* `geometry` in point mode): when the form also declares a parameter keyed
|
|
549
|
+
* `address`, the picker's resolved address (search pick or reverse
|
|
550
|
+
* geocode) fills it — tracking the pin; the person can still edit the
|
|
551
|
+
* field afterwards (a later pin overwrites). Shape-mode pickers never
|
|
552
|
+
* call it: a search there only pans the map. */
|
|
553
|
+
function fillSiblingAddress(displayName: string) {
|
|
554
|
+
if (renderedParameters.some((p) => parameterKey(p) === "address")) {
|
|
555
|
+
setValue("address", displayName);
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
|
|
530
559
|
function setValue(key: string, value: unknown) {
|
|
531
560
|
values = { ...values, [key]: value };
|
|
532
561
|
}
|
|
@@ -1099,8 +1128,10 @@
|
|
|
1099
1128
|
error={fieldError ?? plan.error ?? geoError}
|
|
1100
1129
|
label={String(parameter.label ?? key)}
|
|
1101
1130
|
center={mapInitialCenter(parameter)}
|
|
1131
|
+
searchProviderUrl={geocoderFor(parameter)}
|
|
1102
1132
|
value={plan.coords ?? undefined}
|
|
1103
1133
|
onchange={(coords: [number, number]) => setValue(key, lonLatToGeoJsonPoint(coords))}
|
|
1134
|
+
onaddress={fillSiblingAddress}
|
|
1104
1135
|
/>
|
|
1105
1136
|
{:else}
|
|
1106
1137
|
<MapPicker
|
|
@@ -1111,6 +1142,7 @@
|
|
|
1111
1142
|
error={fieldError ?? plan.error ?? geoError}
|
|
1112
1143
|
label={String(parameter.label ?? key)}
|
|
1113
1144
|
center={mapInitialCenter(parameter)}
|
|
1145
|
+
searchProviderUrl={geocoderFor(parameter)}
|
|
1114
1146
|
geometry={plan.geometry}
|
|
1115
1147
|
ongeometry={(geometry: unknown) => setValue(key, geometry ?? null)}
|
|
1116
1148
|
{...geometryLabels}
|
|
@@ -1121,10 +1153,8 @@
|
|
|
1121
1153
|
[lon, lat] the BFF's GEO_PARSE binding transform turns into a Point.
|
|
1122
1154
|
The renderer stays generic — geo is just another param type, the
|
|
1123
1155
|
occurrence/location coupling lives entirely in the ontology binding.
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
reverse geocode) auto-fills it — tracking the pin; the citizen can
|
|
1127
|
-
still edit the field afterwards (a later pin overwrites). -->
|
|
1156
|
+
The sibling `address` auto-fill is `fillSiblingAddress` (shared with
|
|
1157
|
+
the geometry point picker above). -->
|
|
1128
1158
|
<MapPicker
|
|
1129
1159
|
mode="point"
|
|
1130
1160
|
height="20rem"
|
|
@@ -1140,12 +1170,9 @@
|
|
|
1140
1170
|
value={Array.isArray(values[key])
|
|
1141
1171
|
? (values[key] as [number, number])
|
|
1142
1172
|
: undefined}
|
|
1173
|
+
searchProviderUrl={geocoderFor(parameter)}
|
|
1143
1174
|
onchange={(coords: [number, number]) => setValue(key, coords)}
|
|
1144
|
-
onaddress={
|
|
1145
|
-
if (renderedParameters.some((p) => parameterKey(p) === "address")) {
|
|
1146
|
-
setValue("address", displayName);
|
|
1147
|
-
}
|
|
1148
|
-
}}
|
|
1175
|
+
onaddress={fillSiblingAddress}
|
|
1149
1176
|
/>
|
|
1150
1177
|
{:else}
|
|
1151
1178
|
<Input
|
|
@@ -102,6 +102,14 @@ interface Props {
|
|
|
102
102
|
/** Inline error rendered by the geo MapPicker(s) (e.g. the consumer's
|
|
103
103
|
* out-of-bounds copy) — forwarded as MapPicker's `error`. */
|
|
104
104
|
geoError?: string;
|
|
105
|
+
/** The host's geocoder: a Nominatim-compatible `/search` URL forwarded as
|
|
106
|
+
* `searchProviderUrl` to EVERY MapPicker the renderer mounts (`geo`
|
|
107
|
+
* params and `geometry` params in every mode); reverse geocoding uses
|
|
108
|
+
* the same base with `/reverse`. It WINS over a parameter's
|
|
109
|
+
* `ui_schema.map.geocoder_url` — which geocoder the browser may call is
|
|
110
|
+
* the host's policy. Unset (and no declaration) → the picker's own
|
|
111
|
+
* default (public Nominatim), unchanged. */
|
|
112
|
+
geocoderUrl?: string;
|
|
105
113
|
/** Service-flow wizard (#105 P6): render ONLY the section whose
|
|
106
114
|
* name (its label, falling back to its key) matches — one screen per
|
|
107
115
|
* step. The value bag still spans ALL parameters (so answers persist
|
|
@@ -43,9 +43,11 @@
|
|
|
43
43
|
viewbox = undefined,
|
|
44
44
|
/** @type {((lon: number, lat: number, item: { label: string, value: string }) => void) | undefined} */
|
|
45
45
|
onlocation = undefined,
|
|
46
|
-
/** @type {((displayName: string) => void) | undefined}
|
|
47
|
-
* resolved address label on BOTH paths: reverse geocode
|
|
48
|
-
* coords set
|
|
46
|
+
/** @type {((displayName: string, info: { source: 'reverse', coords: [number, number] } | { source: 'pick' }) => void) | undefined}
|
|
47
|
+
* — fires with the resolved address label on BOTH paths: reverse geocode
|
|
48
|
+
* (map click / coords set; `info.coords` are the reversed [lon, lat]) and
|
|
49
|
+
* forward selection (`info.source === 'pick'`). Consumers feed address
|
|
50
|
+
* fields; `info` lets them tell a person's pick from a reverse geocode. */
|
|
49
51
|
onresolved = undefined,
|
|
50
52
|
/** @type {[number, number] | undefined} — set externally to reverse-geocode and show address */
|
|
51
53
|
coords = $bindable(undefined),
|
|
@@ -82,7 +84,7 @@
|
|
|
82
84
|
if (result.display_name) {
|
|
83
85
|
value = `${lon},${lat}`;
|
|
84
86
|
items = [{ value: `${lon},${lat}`, label: result.display_name, description: result.type?.replace(/_/g, ' ') ?? '' }];
|
|
85
|
-
onresolved?.(result.display_name);
|
|
87
|
+
onresolved?.(result.display_name, { source: 'reverse', coords: [lon, lat] });
|
|
86
88
|
}
|
|
87
89
|
} catch {
|
|
88
90
|
// Reverse geocoding failed — leave search bar as-is
|
|
@@ -142,7 +144,7 @@
|
|
|
142
144
|
const lat = parseFloat(latStr);
|
|
143
145
|
if (!Number.isNaN(lon) && !Number.isNaN(lat)) {
|
|
144
146
|
const selectedItem = items.find((i) => i.value === val);
|
|
145
|
-
if (selectedItem?.label) onresolved?.(selectedItem.label);
|
|
147
|
+
if (selectedItem?.label) onresolved?.(selectedItem.label, { source: 'pick' });
|
|
146
148
|
onlocation?.(lon, lat, selectedItem ?? { label: '', value: val });
|
|
147
149
|
}
|
|
148
150
|
}
|
|
@@ -126,8 +126,11 @@
|
|
|
126
126
|
* Defaults to English copy for the mode. */
|
|
127
127
|
instructionsLabel = undefined,
|
|
128
128
|
/** @type {((displayName: string) => void) | undefined} — the resolved
|
|
129
|
-
* address whenever the
|
|
130
|
-
* map click). Feed it to an address field; coords stay
|
|
129
|
+
* address whenever the PERSON settles the pin (search pick or reverse
|
|
130
|
+
* geocode of a map click). Feed it to an address field; coords stay
|
|
131
|
+
* `onchange`. The reverse geocode of the initial `value` only fills the
|
|
132
|
+
* search box: it never fires here, so opening an edit form cannot
|
|
133
|
+
* overwrite the address stored with the pin. */
|
|
131
134
|
onaddress = undefined,
|
|
132
135
|
/** @type {string} */
|
|
133
136
|
height = '100%',
|
|
@@ -287,14 +290,35 @@
|
|
|
287
290
|
let searchCoords = $state(/** @type {[number, number] | undefined} */ (undefined));
|
|
288
291
|
let initialReverseDone = false;
|
|
289
292
|
|
|
293
|
+
// The initial value's reverse geocode, while still unanswered: it shows the
|
|
294
|
+
// address in the search box but is not the person settling the pin, so it
|
|
295
|
+
// must not reach `onaddress` (an edit form would overwrite its stored
|
|
296
|
+
// address on open).
|
|
297
|
+
/** @type {string | null} */
|
|
298
|
+
let initialReverseKey = null;
|
|
299
|
+
|
|
290
300
|
// Set searchCoords from initial value (triggers reverse geocode in GeoSearch)
|
|
291
301
|
$effect(() => {
|
|
292
302
|
if (!initialReverseDone && value) {
|
|
293
303
|
searchCoords = /** @type {[number, number]} */ ([...value]);
|
|
304
|
+
initialReverseKey = `${value[0]},${value[1]}`;
|
|
294
305
|
initialReverseDone = true;
|
|
295
306
|
}
|
|
296
307
|
});
|
|
297
308
|
|
|
309
|
+
/** GeoSearch resolved an address: forward it as `onaddress` unless it is
|
|
310
|
+
* the reverse geocode of the initial value. */
|
|
311
|
+
function handleResolved(displayName, info) {
|
|
312
|
+
if (info?.source === 'reverse' && initialReverseKey !== null) {
|
|
313
|
+
const key = `${info.coords[0]},${info.coords[1]}`;
|
|
314
|
+
if (key === initialReverseKey) {
|
|
315
|
+
initialReverseKey = null;
|
|
316
|
+
return;
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
onaddress?.(displayName);
|
|
320
|
+
}
|
|
321
|
+
|
|
298
322
|
function handleGeoLocation(lon, lat) {
|
|
299
323
|
if (!_map) return;
|
|
300
324
|
const view = _map.getView();
|
|
@@ -603,7 +627,7 @@
|
|
|
603
627
|
providerUrl={searchProviderUrl}
|
|
604
628
|
viewbox={searchViewbox}
|
|
605
629
|
onlocation={handleGeoLocation}
|
|
606
|
-
onresolved={
|
|
630
|
+
onresolved={handleResolved}
|
|
607
631
|
bind:coords={searchCoords}
|
|
608
632
|
size="sm"
|
|
609
633
|
/>
|
|
@@ -68,6 +68,17 @@ export declare function mapInitialCenter(parameter: {
|
|
|
68
68
|
ui_schema?: unknown;
|
|
69
69
|
[key: string]: unknown;
|
|
70
70
|
}): [number, number] | undefined;
|
|
71
|
+
/** The map picker's GEOCODER, declared per parameter:
|
|
72
|
+
* `ui_schema.map.geocoder_url`, a Nominatim-compatible `/search` URL (the
|
|
73
|
+
* picker derives reverse geocoding by swapping `/search` for `/reverse`).
|
|
74
|
+
* Absent, blank or not a string → undefined. The renderer's `geocoderUrl`
|
|
75
|
+
* prop WINS over this: which geocoder a browser may call is the host's
|
|
76
|
+
* policy (e.g. no request to a third-party geocoder), so a declaration only
|
|
77
|
+
* fills in where the host sets none. */
|
|
78
|
+
export declare function mapGeocoderUrl(parameter: {
|
|
79
|
+
ui_schema?: unknown;
|
|
80
|
+
[key: string]: unknown;
|
|
81
|
+
}): string | undefined;
|
|
71
82
|
export type StoredFile = {
|
|
72
83
|
name: string;
|
|
73
84
|
url?: string;
|
|
@@ -189,15 +189,7 @@ export function mapInitialCenter(parameter: {
|
|
|
189
189
|
ui_schema?: unknown;
|
|
190
190
|
[key: string]: unknown;
|
|
191
191
|
}): [number, number] | undefined {
|
|
192
|
-
const
|
|
193
|
-
parameter.ui_schema && typeof parameter.ui_schema === "object"
|
|
194
|
-
? (parameter.ui_schema as Record<string, unknown>)
|
|
195
|
-
: null;
|
|
196
|
-
const map =
|
|
197
|
-
ui?.map && typeof ui.map === "object"
|
|
198
|
-
? (ui.map as Record<string, unknown>)
|
|
199
|
-
: null;
|
|
200
|
-
const c = map?.initial_center;
|
|
192
|
+
const c = uiSchemaMap(parameter)?.initial_center;
|
|
201
193
|
if (
|
|
202
194
|
Array.isArray(c) &&
|
|
203
195
|
c.length >= 2 &&
|
|
@@ -209,6 +201,35 @@ export function mapInitialCenter(parameter: {
|
|
|
209
201
|
return undefined;
|
|
210
202
|
}
|
|
211
203
|
|
|
204
|
+
/** The parameter's map presentation hints: `ui_schema.map`, or null. */
|
|
205
|
+
function uiSchemaMap(parameter: {
|
|
206
|
+
ui_schema?: unknown;
|
|
207
|
+
[key: string]: unknown;
|
|
208
|
+
}): Record<string, unknown> | null {
|
|
209
|
+
const ui =
|
|
210
|
+
parameter.ui_schema && typeof parameter.ui_schema === "object"
|
|
211
|
+
? (parameter.ui_schema as Record<string, unknown>)
|
|
212
|
+
: null;
|
|
213
|
+
return ui?.map && typeof ui.map === "object"
|
|
214
|
+
? (ui.map as Record<string, unknown>)
|
|
215
|
+
: null;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/** The map picker's GEOCODER, declared per parameter:
|
|
219
|
+
* `ui_schema.map.geocoder_url`, a Nominatim-compatible `/search` URL (the
|
|
220
|
+
* picker derives reverse geocoding by swapping `/search` for `/reverse`).
|
|
221
|
+
* Absent, blank or not a string → undefined. The renderer's `geocoderUrl`
|
|
222
|
+
* prop WINS over this: which geocoder a browser may call is the host's
|
|
223
|
+
* policy (e.g. no request to a third-party geocoder), so a declaration only
|
|
224
|
+
* fills in where the host sets none. */
|
|
225
|
+
export function mapGeocoderUrl(parameter: {
|
|
226
|
+
ui_schema?: unknown;
|
|
227
|
+
[key: string]: unknown;
|
|
228
|
+
}): string | undefined {
|
|
229
|
+
const url = uiSchemaMap(parameter)?.geocoder_url;
|
|
230
|
+
return typeof url === "string" && url.trim() !== "" ? url.trim() : undefined;
|
|
231
|
+
}
|
|
232
|
+
|
|
212
233
|
export type StoredFile = { name: string; url?: string };
|
|
213
234
|
|
|
214
235
|
/** #40 — normalize a file param's stored-current value (the edit form's
|