@open-commune/web 0.2.12 → 0.2.13

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.
Files changed (2) hide show
  1. package/package.json +5 -4
  2. package/utils/location.js +36 -0
package/package.json CHANGED
@@ -17,8 +17,8 @@
17
17
  "@iconify/vue": "^5.0.3",
18
18
  "@nuxt/kit": "^4.6.1",
19
19
  "@nuxt/ui": "^4.12.0",
20
- "@open-commune/core": "^0.2.12",
21
- "@open-commune/editor": "^0.2.12",
20
+ "@open-commune/core": "^0.2.13",
21
+ "@open-commune/editor": "^0.2.13",
22
22
  "@pinia-orm/nuxt": "^2.0.0",
23
23
  "@pinia/nuxt": "^1.0.3",
24
24
  "@tanstack/vue-query": "^5.104.3",
@@ -40,7 +40,7 @@
40
40
  },
41
41
  "description": "The Open Commune application: the admin interface and the server, on a single origin.",
42
42
  "license": "AGPL-3.0-or-later",
43
- "version": "0.2.12",
43
+ "version": "0.2.13",
44
44
  "type": "module",
45
45
  "main": "./nuxt.config.ts",
46
46
  "files": [
@@ -59,7 +59,8 @@
59
59
  "plugins",
60
60
  "public",
61
61
  "server",
62
- "store"
62
+ "store",
63
+ "utils"
63
64
  ],
64
65
  "publishConfig": {
65
66
  "access": "public"
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Location values of the `input-location` widget: `{ address, coordinates }`,
3
+ * where `coordinates` is a Mapbox `[longitude, latitude]` pair.
4
+ *
5
+ * Legacy records carry an address with `coordinates: []` (typed by hand, never
6
+ * geocoded). A map centred on such a value falls back to `[0, 0]` — the open
7
+ * ocean in the Gulf of Guinea — so every reader checks the pair first.
8
+ */
9
+
10
+ // Metropolitan France, the view shown while a location has no coordinates.
11
+ export const FALLBACK_CENTER = [2.35, 46.6];
12
+ export const FALLBACK_ZOOM = 5;
13
+ export const LOCATION_ZOOM = 15;
14
+
15
+ /** The `[lng, lat]` pair as numbers, or `null` when it is not a usable position. */
16
+ export const toLngLat = (coordinates) => {
17
+ if (!Array.isArray(coordinates) || coordinates.length !== 2) {
18
+ return null;
19
+ }
20
+ const [lng, lat] = coordinates.map((value) =>
21
+ value === '' || value === null ? Number.NaN : Number(value),
22
+ );
23
+ if (!Number.isFinite(lng) || !Number.isFinite(lat)) {
24
+ return null;
25
+ }
26
+ if (lng < -180 || lng > 180 || lat < -90 || lat > 90) {
27
+ return null;
28
+ }
29
+ // [0, 0] is what a failed geocoding leaves behind, never a commune.
30
+ if (lng === 0 && lat === 0) {
31
+ return null;
32
+ }
33
+ return [lng, lat];
34
+ };
35
+
36
+ export const hasCoordinates = (location) => toLngLat(location?.coordinates) !== null;