@aiaiai-pt/design-system 0.61.2 → 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.
@@ -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
- SIBLING-ADDRESS CONVENTION: when the form also declares a parameter
1125
- keyed `address`, the picker's resolved address (search pick or
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={(displayName: string) => {
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} — fires with the
47
- * resolved address label on BOTH paths: reverse geocode (map click /
48
- * coords set) and forward selection. Consumers feed address fields. */
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 pin settles (search pick or reverse geocode of a
130
- * map click). Feed it to an address field; coords stay `onchange`. */
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={onaddress}
630
+ onresolved={handleResolved}
607
631
  bind:coords={searchCoords}
608
632
  size="sm"
609
633
  />
@@ -66,6 +66,21 @@
66
66
  /** @type {string} — label for the "next" nav button */
67
67
  nextLabel = 'NEXT',
68
68
 
69
+ /* Host-language text (atelier#2674): the summary and the navigation's
70
+ accessible names. Each count arrives already formatted. */
71
+ /** @type {(total: string) => string} — cursor-mode summary */
72
+ totalLabel = (total) => `${total} total`,
73
+ /** @type {(start: string, end: string, total: string) => string} — offset-mode range */
74
+ rangeLabel = (start, end, total) => `${start}–${end} of ${total}`,
75
+ /** @type {string} — accessible name of the page-size control */
76
+ rowsPerPageLabel = 'Rows per page',
77
+ /** @type {string} — accessible name of the previous-page button */
78
+ previousPageLabel = 'Previous page',
79
+ /** @type {string} — accessible name of the next-page button */
80
+ nextPageLabel = 'Next page',
81
+ /** @type {string | undefined} — BCP 47 locale the counts are formatted in */
82
+ locale = undefined,
83
+
69
84
  /** @type {string} */
70
85
  class: className = '',
71
86
  ...rest
@@ -87,13 +102,17 @@
87
102
  total_items === undefined
88
103
  ? ''
89
104
  : mode === 'cursor'
90
- ? `${total_items.toLocaleString()} total`
105
+ ? totalLabel(total_items.toLocaleString(locale))
91
106
  : (() => {
92
107
  const start = (current_page - 1) * page_size + 1;
93
108
  const end = Math.min(current_page * page_size, total_items);
94
109
  return start > total_items
95
- ? `${total_items.toLocaleString()} total`
96
- : `${start}–${end} of ${total_items.toLocaleString()}`;
110
+ ? totalLabel(total_items.toLocaleString(locale))
111
+ : rangeLabel(
112
+ start.toLocaleString(locale),
113
+ end.toLocaleString(locale),
114
+ total_items.toLocaleString(locale)
115
+ );
97
116
  })()
98
117
  );
99
118
 
@@ -138,7 +157,7 @@
138
157
  value={page_size_value}
139
158
  options={page_size_options}
140
159
  onchange={(val) => on_page_size_change?.(Number(val))}
141
- aria-label="Rows per page"
160
+ aria-label={rowsPerPageLabel}
142
161
  />
143
162
  </div>
144
163
  {/if}
@@ -150,15 +169,15 @@
150
169
  <span class="pagination-spacer" aria-hidden="true"></span>
151
170
 
152
171
  {#if mode === 'cursor'}
153
- <button class="pagination-nav" disabled={!has_prev} onclick={on_prev} aria-label="Previous page">
172
+ <button class="pagination-nav" disabled={!has_prev} onclick={on_prev} aria-label={previousPageLabel}>
154
173
  {@render chevronLeft()}<span>{prevLabel}</span>
155
174
  </button>
156
- <button class="pagination-nav" disabled={!has_next} onclick={on_next} aria-label="Next page">
175
+ <button class="pagination-nav" disabled={!has_next} onclick={on_next} aria-label={nextPageLabel}>
157
176
  <span>{nextLabel}</span>{@render chevronRight()}
158
177
  </button>
159
178
 
160
179
  {:else}
161
- <button class="pagination-nav" disabled={current_page <= 1} onclick={() => on_page_change?.(current_page - 1)} aria-label="Previous page">
180
+ <button class="pagination-nav" disabled={current_page <= 1} onclick={() => on_page_change?.(current_page - 1)} aria-label={previousPageLabel}>
162
181
  {@render chevronLeft()}<span>{prevLabel}</span>
163
182
  </button>
164
183
 
@@ -181,7 +200,7 @@
181
200
  {/each}
182
201
  </div>
183
202
 
184
- <button class="pagination-nav" disabled={current_page >= (total_pages ?? current_page)} onclick={() => on_page_change?.(current_page + 1)} aria-label="Next page">
203
+ <button class="pagination-nav" disabled={current_page >= (total_pages ?? current_page)} onclick={() => on_page_change?.(current_page + 1)} aria-label={nextPageLabel}>
185
204
  <span>{nextLabel}</span>{@render chevronRight()}
186
205
  </button>
187
206
  {/if}
@@ -46,6 +46,12 @@ declare const Pagination: import("svelte").Component<{
46
46
  on_page_size_change?: any;
47
47
  prevLabel?: string;
48
48
  nextLabel?: string;
49
+ totalLabel?: Function;
50
+ rangeLabel?: Function;
51
+ rowsPerPageLabel?: string;
52
+ previousPageLabel?: string;
53
+ nextPageLabel?: string;
54
+ locale?: any;
49
55
  class?: string;
50
56
  } & Record<string, any>, {}, "">;
51
57
  type $$ComponentProps = {
@@ -63,5 +69,11 @@ type $$ComponentProps = {
63
69
  on_page_size_change?: any;
64
70
  prevLabel?: string;
65
71
  nextLabel?: string;
72
+ totalLabel?: Function;
73
+ rangeLabel?: Function;
74
+ rowsPerPageLabel?: string;
75
+ previousPageLabel?: string;
76
+ nextPageLabel?: string;
77
+ locale?: any;
66
78
  class?: string;
67
79
  } & Record<string, any>;
@@ -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 ui =
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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aiaiai-pt/design-system",
3
- "version": "0.61.2",
3
+ "version": "0.63.0",
4
4
  "description": "Design system tokens and Svelte components for aiaiai products",
5
5
  "license": "MIT",
6
6
  "type": "module",