@aiaiai-pt/design-system 0.58.0 → 0.60.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 +67 -21
- package/components/ActionFormRenderer.svelte.d.ts +10 -0
- package/components/MapDisplay.svelte +59 -4
- package/components/MapDisplay.svelte.d.ts +11 -1
- package/components/MapPicker.svelte +334 -34
- package/components/MapPicker.svelte.d.ts +33 -3
- package/components/SidebarItem.svelte +39 -0
- package/components/SidebarItem.svelte.d.ts +9 -0
- package/components/action-form-renderer-widgets.d.ts +30 -0
- package/components/action-form-renderer-widgets.ts +83 -0
- package/components/map-geometry.d.ts +46 -0
- package/components/map-geometry.ts +253 -0
- package/components/map-utils.d.ts +15 -4
- package/components/map-utils.js +60 -1
- package/components/renderer/display.d.ts +12 -1
- package/components/renderer/display.ts +16 -1
- package/package.json +5 -1
- package/tokens/components.css +4 -0
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
import {
|
|
54
54
|
dateOnlyToDate,
|
|
55
55
|
dateToDateOnly,
|
|
56
|
-
|
|
56
|
+
geometryFieldPlan,
|
|
57
57
|
lonLatToGeoJsonPoint,
|
|
58
58
|
mapInitialCenter,
|
|
59
59
|
storedFileDescriptor,
|
|
@@ -207,6 +207,16 @@
|
|
|
207
207
|
* fields are empty. Rendered as a polite `role="status"` so screen
|
|
208
208
|
* readers announce why the form cannot be submitted. */
|
|
209
209
|
requiredFieldsMessage?: string;
|
|
210
|
+
/** atelier#2838 — the loud field state for a `geometry` param whose
|
|
211
|
+
* declared `geometry_type` no picker can draw (e.g. GeometryCollection).
|
|
212
|
+
* Receives the declared type name. */
|
|
213
|
+
unsupportedGeometryLabel?: (geometryType: string) => string;
|
|
214
|
+
/** atelier#2838 — forwarded verbatim to the MapPicker of every shape-mode
|
|
215
|
+
* `geometry` param (Polygon, MultiPolygon, …) so consumers can translate
|
|
216
|
+
* its toolbar and keyboard instructions (see MapPicker's
|
|
217
|
+
* `deleteSelectedLabel`, `clearLabel`, `countLabel`,
|
|
218
|
+
* `instructionsLabel`). */
|
|
219
|
+
geometryLabels?: Record<string, unknown>;
|
|
210
220
|
}
|
|
211
221
|
|
|
212
222
|
let {
|
|
@@ -244,6 +254,9 @@
|
|
|
244
254
|
dropLabel = "Drop files here or click to browse",
|
|
245
255
|
defaultSectionLabel = "Details",
|
|
246
256
|
requiredFieldsMessage = "Fill in all required fields to submit.",
|
|
257
|
+
unsupportedGeometryLabel = (geometryType: string) =>
|
|
258
|
+
`Unsupported geometry type: ${geometryType}. This field cannot be edited here.`,
|
|
259
|
+
geometryLabels = {},
|
|
247
260
|
}: Props = $props();
|
|
248
261
|
|
|
249
262
|
let values = $state<Record<string, unknown>>({});
|
|
@@ -523,7 +536,12 @@
|
|
|
523
536
|
// reach the wire (readonly defaults OUT on the form-surface.v1 lane;
|
|
524
537
|
// `payload: "include"` declares prefill-and-send).
|
|
525
538
|
if (!isPayloadIncluded(parameter)) continue;
|
|
526
|
-
bag
|
|
539
|
+
// An explicit null in the bag is a CLEAR (a removed geometry, a cleared
|
|
540
|
+
// relationship/json) and rides the wire as null — falling back to
|
|
541
|
+
// `initialValue` here re-sent the prefilled default on edit forms
|
|
542
|
+
// (atelier#2838). Only a key never seeded falls back.
|
|
543
|
+
bag[key] =
|
|
544
|
+
key in values && values[key] !== undefined ? values[key] : initialValue(parameter);
|
|
527
545
|
}
|
|
528
546
|
return bag;
|
|
529
547
|
}
|
|
@@ -1047,25 +1065,53 @@
|
|
|
1047
1065
|
{/if}
|
|
1048
1066
|
</div>
|
|
1049
1067
|
{:else if kind === "geometry"}
|
|
1050
|
-
<!-- #39 — the form-surface.v1 geometry widget
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
{
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1068
|
+
<!-- #39 / atelier#2838 — the form-surface.v1 geometry widget. The picker
|
|
1069
|
+
follows the parameter's DECLARED `geometry_type` (a GeoJSON type
|
|
1070
|
+
name): absent or Point → the point picker over a GeoJSON Point (the
|
|
1071
|
+
MapPicker speaks [lon, lat] at its prop edge; the pure adapters
|
|
1072
|
+
translate); a drawable type → that MapPicker shape mode, storing a
|
|
1073
|
+
GeoJSON value of EXACTLY that type (null when every shape is
|
|
1074
|
+
removed). A value of another type fails LOUD on the field; a type
|
|
1075
|
+
no picker can draw (GeometryCollection, unknown names) renders a
|
|
1076
|
+
loud unsupported state and NO picker — never a silent point. The
|
|
1077
|
+
legacy `geo` param (bare tuple) is the branch below, untouched. -->
|
|
1078
|
+
{@const plan = geometryFieldPlan(parameter, values[key])}
|
|
1079
|
+
{#if plan.mode === null}
|
|
1080
|
+
<div class="afr-file-param" role="group" aria-labelledby={`${key}-geometry-label`}>
|
|
1081
|
+
<span id={`${key}-geometry-label`} class="afr-file-label"
|
|
1082
|
+
>{String(parameter.label ?? key)}</span
|
|
1083
|
+
>
|
|
1084
|
+
<Alert variant="error">
|
|
1085
|
+
{unsupportedGeometryLabel(plan.unsupportedType)}
|
|
1086
|
+
</Alert>
|
|
1087
|
+
</div>
|
|
1088
|
+
{:else if plan.mode === "point"}
|
|
1089
|
+
<MapPicker
|
|
1090
|
+
mode="point"
|
|
1091
|
+
height="20rem"
|
|
1092
|
+
{boundary}
|
|
1093
|
+
{layers}
|
|
1094
|
+
{onoutofbounds}
|
|
1095
|
+
error={fieldError ?? plan.error ?? geoError}
|
|
1096
|
+
label={String(parameter.label ?? key)}
|
|
1097
|
+
center={mapInitialCenter(parameter)}
|
|
1098
|
+
value={plan.coords ?? undefined}
|
|
1099
|
+
onchange={(coords: [number, number]) => setValue(key, lonLatToGeoJsonPoint(coords))}
|
|
1100
|
+
/>
|
|
1101
|
+
{:else}
|
|
1102
|
+
<MapPicker
|
|
1103
|
+
mode={plan.mode}
|
|
1104
|
+
height="20rem"
|
|
1105
|
+
{boundary}
|
|
1106
|
+
{layers}
|
|
1107
|
+
error={fieldError ?? plan.error ?? geoError}
|
|
1108
|
+
label={String(parameter.label ?? key)}
|
|
1109
|
+
center={mapInitialCenter(parameter)}
|
|
1110
|
+
geometry={plan.geometry}
|
|
1111
|
+
ongeometry={(geometry: unknown) => setValue(key, geometry ?? null)}
|
|
1112
|
+
{...geometryLabels}
|
|
1113
|
+
/>
|
|
1114
|
+
{/if}
|
|
1069
1115
|
{:else if type === "geo"}
|
|
1070
1116
|
<!-- A `geo` parameter renders the DS map-picker; its value is the
|
|
1071
1117
|
[lon, lat] the BFF's GEO_PARSE binding transform turns into a Point.
|
|
@@ -146,6 +146,16 @@ interface Props {
|
|
|
146
146
|
* fields are empty. Rendered as a polite `role="status"` so screen
|
|
147
147
|
* readers announce why the form cannot be submitted. */
|
|
148
148
|
requiredFieldsMessage?: string;
|
|
149
|
+
/** atelier#2838 — the loud field state for a `geometry` param whose
|
|
150
|
+
* declared `geometry_type` no picker can draw (e.g. GeometryCollection).
|
|
151
|
+
* Receives the declared type name. */
|
|
152
|
+
unsupportedGeometryLabel?: (geometryType: string) => string;
|
|
153
|
+
/** atelier#2838 — forwarded verbatim to the MapPicker of every shape-mode
|
|
154
|
+
* `geometry` param (Polygon, MultiPolygon, …) so consumers can translate
|
|
155
|
+
* its toolbar and keyboard instructions (see MapPicker's
|
|
156
|
+
* `deleteSelectedLabel`, `clearLabel`, `countLabel`,
|
|
157
|
+
* `instructionsLabel`). */
|
|
158
|
+
geometryLabels?: Record<string, unknown>;
|
|
149
159
|
}
|
|
150
160
|
declare const ActionFormRenderer: import("svelte").Component<Props, {}, "">;
|
|
151
161
|
type ActionFormRenderer = ReturnType<typeof ActionFormRenderer>;
|
|
@@ -1,18 +1,34 @@
|
|
|
1
1
|
<!--
|
|
2
2
|
@component MapDisplay
|
|
3
3
|
|
|
4
|
-
Read-only map showing a point or polygon
|
|
4
|
+
Read-only map showing a point or polygon, or ANY GeoJSON geometry through
|
|
5
|
+
`geometry` (Point, MultiPoint, LineString, MultiLineString, Polygon,
|
|
6
|
+
MultiPolygon, or a recursive GeometryCollection — atelier#2838): every
|
|
7
|
+
leaf is drawn and the view fits its extent; a lone point is centred at
|
|
8
|
+
`zoom`. Validate a stored value with `geoGeometry` (renderer/display) —
|
|
9
|
+
an invalid `geometry` draws nothing. OpenLayers with configurable tiles.
|
|
5
10
|
Consumes --map-* tokens from components.css.
|
|
6
11
|
|
|
7
12
|
@example Point
|
|
8
13
|
<MapDisplay center={[-9.14, 38.74]} zoom={14} marker={[-9.14, 38.74]} />
|
|
9
14
|
|
|
15
|
+
@example Any GeoJSON geometry (e.g. a stored location)
|
|
16
|
+
<MapDisplay zoom={16} geometry={geoGeometry(row.location)} />
|
|
17
|
+
|
|
10
18
|
@example Styled tiles
|
|
11
19
|
<MapDisplay center={[-9.14, 38.74]} tileSource={{ type: 'stadia', layer: 'stamen_toner_lite' }} />
|
|
12
20
|
-->
|
|
13
21
|
<script>
|
|
14
22
|
import { fromLonLat } from 'ol/proj.js';
|
|
15
|
-
import {
|
|
23
|
+
import {
|
|
24
|
+
buildGeometryFeatures,
|
|
25
|
+
createTileLayer,
|
|
26
|
+
createMapStyles,
|
|
27
|
+
createOverlayLayers,
|
|
28
|
+
cssPx,
|
|
29
|
+
watchTheme,
|
|
30
|
+
renderMapError,
|
|
31
|
+
} from './map-utils.js';
|
|
16
32
|
|
|
17
33
|
let {
|
|
18
34
|
/** @type {[number, number]} — [longitude, latitude] WGS84 */
|
|
@@ -23,6 +39,11 @@
|
|
|
23
39
|
marker = undefined,
|
|
24
40
|
/** @type {number[][] | undefined} — polygon coords [[lon,lat], ...] */
|
|
25
41
|
polygon = undefined,
|
|
42
|
+
/** @type {unknown} — any GeoJSON geometry (incl. GeometryCollection),
|
|
43
|
+
* drawn in full; the view fits its extent (a lone point keeps `zoom`).
|
|
44
|
+
* Reactive: a value arriving after mount is drawn then. Invalid or
|
|
45
|
+
* null → nothing drawn. Coexists with `marker` / `polygon`. */
|
|
46
|
+
geometry = undefined,
|
|
26
47
|
/** @type {import('./map-utils.js').TileSourceConfig} */
|
|
27
48
|
tileSource = { type: 'osm' },
|
|
28
49
|
/** @type {import('./map-utils.js').OverlayLayerDef[]} — ordered GeoJSON
|
|
@@ -46,6 +67,37 @@
|
|
|
46
67
|
let _map = $state();
|
|
47
68
|
/** @type {any} — shared style factory (set at mount) */
|
|
48
69
|
let _styles = $state();
|
|
70
|
+
/** @type {any} — the marker/polygon/geometry vector source (set at mount) */
|
|
71
|
+
let _vectorSource = $state.raw();
|
|
72
|
+
|
|
73
|
+
// The `geometry` features have ONE owner: this effect — a detail page
|
|
74
|
+
// typically loads its record after the map mounts. Replaces only its own
|
|
75
|
+
// features (never the `marker` / `polygon` ones) and re-fits the view.
|
|
76
|
+
/** @type {any[]} */
|
|
77
|
+
let _geometryFeatures = [];
|
|
78
|
+
let _geometrySeq = 0;
|
|
79
|
+
$effect(() => {
|
|
80
|
+
const g = geometry;
|
|
81
|
+
const map = _map;
|
|
82
|
+
const source = _vectorSource;
|
|
83
|
+
if (!map || !source) return;
|
|
84
|
+
const seq = ++_geometrySeq;
|
|
85
|
+
void (async () => {
|
|
86
|
+
const built = await buildGeometryFeatures(g);
|
|
87
|
+
if (seq !== _geometrySeq || _map !== map) return;
|
|
88
|
+
for (const f of _geometryFeatures) source.removeFeature(f);
|
|
89
|
+
_geometryFeatures = built?.features ?? [];
|
|
90
|
+
if (!built) return;
|
|
91
|
+
source.addFeatures(_geometryFeatures);
|
|
92
|
+
const view = map.getView();
|
|
93
|
+
if (built.center) {
|
|
94
|
+
view.setCenter(built.center);
|
|
95
|
+
} else {
|
|
96
|
+
const pad = container ? cssPx(container, '--space-lg', 24) : 24;
|
|
97
|
+
view.fit(built.extent, { padding: [pad, pad, pad, pad], maxZoom: 18 });
|
|
98
|
+
}
|
|
99
|
+
})();
|
|
100
|
+
});
|
|
49
101
|
|
|
50
102
|
// The `layers` overlays have ONE owner: this effect (same contract as
|
|
51
103
|
// MapPicker's boundary). Consumers typically RESOLVE overlay defs
|
|
@@ -124,11 +176,13 @@
|
|
|
124
176
|
}));
|
|
125
177
|
}
|
|
126
178
|
|
|
179
|
+
const vectorSource = new VectorSource({ features });
|
|
127
180
|
const vectorLayer = new VectorLayer({
|
|
128
|
-
source:
|
|
181
|
+
source: vectorSource,
|
|
129
182
|
style: (feature) => {
|
|
130
183
|
const type = feature.getGeometry()?.getType();
|
|
131
|
-
|
|
184
|
+
// Lines take the polygon style's stroke (fill is ignored).
|
|
185
|
+
return type === 'Point' || type === 'MultiPoint' ? styles.marker : styles.polygon;
|
|
132
186
|
},
|
|
133
187
|
});
|
|
134
188
|
|
|
@@ -143,6 +197,7 @@
|
|
|
143
197
|
}),
|
|
144
198
|
controls: [],
|
|
145
199
|
});
|
|
200
|
+
_vectorSource = vectorSource;
|
|
146
201
|
_map = map;
|
|
147
202
|
|
|
148
203
|
disposeTheme = watchTheme(() => {
|
|
@@ -6,12 +6,20 @@ type MapDisplay = {
|
|
|
6
6
|
/**
|
|
7
7
|
* MapDisplay
|
|
8
8
|
*
|
|
9
|
-
* Read-only map showing a point or polygon
|
|
9
|
+
* Read-only map showing a point or polygon, or ANY GeoJSON geometry through
|
|
10
|
+
* `geometry` (Point, MultiPoint, LineString, MultiLineString, Polygon,
|
|
11
|
+
* MultiPolygon, or a recursive GeometryCollection — atelier#2838): every
|
|
12
|
+
* leaf is drawn and the view fits its extent; a lone point is centred at
|
|
13
|
+
* `zoom`. Validate a stored value with `geoGeometry` (renderer/display) —
|
|
14
|
+
* an invalid `geometry` draws nothing. OpenLayers with configurable tiles.
|
|
10
15
|
* Consumes --map-* tokens from components.css.
|
|
11
16
|
*
|
|
12
17
|
* @example Point
|
|
13
18
|
* <MapDisplay center={[-9.14, 38.74]} zoom={14} marker={[-9.14, 38.74]} />
|
|
14
19
|
*
|
|
20
|
+
* @example Any GeoJSON geometry (e.g. a stored location)
|
|
21
|
+
* <MapDisplay zoom={16} geometry={geoGeometry(row.location)} />
|
|
22
|
+
*
|
|
15
23
|
* @example Styled tiles
|
|
16
24
|
* <MapDisplay center={[-9.14, 38.74]} tileSource={{ type: 'stadia', layer: 'stamen_toner_lite' }} />
|
|
17
25
|
*/
|
|
@@ -20,6 +28,7 @@ declare const MapDisplay: import("svelte").Component<{
|
|
|
20
28
|
zoom?: number;
|
|
21
29
|
marker?: any;
|
|
22
30
|
polygon?: any;
|
|
31
|
+
geometry?: any;
|
|
23
32
|
tileSource?: Record<string, any>;
|
|
24
33
|
layers?: any[];
|
|
25
34
|
height?: string;
|
|
@@ -30,6 +39,7 @@ type $$ComponentProps = {
|
|
|
30
39
|
zoom?: number;
|
|
31
40
|
marker?: any;
|
|
32
41
|
polygon?: any;
|
|
42
|
+
geometry?: any;
|
|
33
43
|
tileSource?: Record<string, any>;
|
|
34
44
|
layers?: any[];
|
|
35
45
|
height?: string;
|