Commit a76bbbf
authored
feat(embed): add a versioned postMessage API for host pages (#1468)
* feat(embed): add a versioned postMessage API for host pages
URL parameters configure an embed once, at load. A host page that frames
GeoLibre had no way to keep talking to the map: every interaction meant
reloading the iframe with a new `?url=`, throwing away the analyst's
session, and nothing the user did inside the map was visible outside it.
Add an opt-in runtime protocol on top of the existing embed plumbing.
Host to app: `loadProject`, `setView`, `highlightFeature`, `openTool`
(the runtime twin of `?tool=`). App to host: `ready`, `ack`,
`projectLoaded`, `selectionChanged`, `viewChanged` (throttled),
`toolCompleted`, `serverFileWritten`. Every message is versioned
`{v, type, payload}`, and app messages carry `source: "geolibre"` so a
host can filter its own postMessage traffic.
The API is off by default. It activates only when the deployment names
the origins it trusts (`GEOLIBRE_EMBED_ORIGINS` on the Docker image,
`VITE_GEOLIBRE_EMBED_ORIGINS` at build time), so a public deployment can
never be driven by whoever frames it. The allowlist is enforced in both
directions, and setting it also narrows the existing Jupyter/`?embed=1`
project and scripting bridges to those origins.
Fixes #1462
* fix(embed): resolve highlight ids against the layer instead of trusting them
Explicit `featureId`/`featureIds` were passed through unchecked, so a
`highlightFeature` naming an id no feature carries — a typo, or any layer
whose features live in its MapLibre source rather than `layer.geojson` —
selected a phantom id, drew no highlight, and still answered `ack {ok:
true}`. Resolve ids against the layer's features under the same
`String(feature.id ?? index)` convention the map controller uses, and
reject a request that names features but resolves to none, leaving the
user's existing selection untouched. A request naming nothing is still
the documented "clear the highlight" form.
Also fix the docs claim that outbound messages are never addressed to
`*` (they are, before the handshake, when the `*` wildcard is
configured), type the null-geometry test fixtures as `Feature<null>[]`
(`Feature` defaults its geometry parameter to `Geometry`), and match the
surrounding assertion style in one test.1 parent 33488ca commit a76bbbf
11 files changed
Lines changed: 1264 additions & 13 deletions
File tree
- apps/geolibre-desktop/src
- components/layout
- hooks
- lib
- docker
- docs
- user-guide
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
30 | 34 | | |
31 | 35 | | |
32 | 36 | | |
33 | 37 | | |
| 38 | + | |
34 | 39 | | |
35 | 40 | | |
36 | 41 | | |
| |||
Lines changed: 5 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
114 | 114 | | |
115 | 115 | | |
116 | 116 | | |
| 117 | + | |
117 | 118 | | |
118 | 119 | | |
119 | 120 | | |
| |||
748 | 749 | | |
749 | 750 | | |
750 | 751 | | |
| 752 | + | |
| 753 | + | |
| 754 | + | |
| 755 | + | |
751 | 756 | | |
752 | 757 | | |
753 | 758 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
| 8 | + | |
7 | 9 | | |
8 | 10 | | |
9 | 11 | | |
| |||
21 | 23 | | |
22 | 24 | | |
23 | 25 | | |
24 | | - | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
25 | 30 | | |
26 | 31 | | |
27 | 32 | | |
| |||
64 | 69 | | |
65 | 70 | | |
66 | 71 | | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
67 | 77 | | |
68 | 78 | | |
69 | 79 | | |
| |||
77 | 87 | | |
78 | 88 | | |
79 | 89 | | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
80 | 97 | | |
81 | 98 | | |
82 | 99 | | |
| 100 | + | |
83 | 101 | | |
84 | 102 | | |
85 | 103 | | |
| |||
88 | 106 | | |
89 | 107 | | |
90 | 108 | | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
91 | 116 | | |
92 | 117 | | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
93 | 121 | | |
94 | 122 | | |
95 | 123 | | |
| |||
0 commit comments