@florasync/leaflet-geokit 0.9.0 → 0.9.1
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/ARCHITECTURE.md +195 -0
- package/README.md +7 -1
- package/custom-toolbar.html +165 -0
- package/dist/django/index.js.map +1 -1
- package/dist/leaflet-geokit.es.js.map +1 -1
- package/dist/leaflet-geokit.external.es.js.map +1 -1
- package/dist/leaflet-geokit.umd.js.map +1 -1
- package/dist/preact/index-DCKj0r6a.js.map +1 -1
- package/dist/preact-bundled/index.js.map +1 -1
- package/dist/react/index-DCKj0r6a.js.map +1 -1
- package/dist/react-bundled/index.js.map +1 -1
- package/dist/types/components/LeafletDrawMapElement.d.ts +6 -6
- package/dist/types/django/index.d.ts +2 -2
- package/dist/types/external.d.ts +9 -9
- package/dist/types/index.d.ts +9 -9
- package/dist/types/lib/FeatureStore.d.ts +2 -2
- package/dist/types/lib/LayerRegistry.d.ts +1 -1
- package/dist/types/lib/MapController.d.ts +8 -8
- package/dist/types/lib/layer-cake/LayerCakeManager.d.ts +2 -2
- package/dist/types/lib/layer-style-panel.d.ts +1 -1
- package/dist/types/lib/marker-icons.d.ts +1 -1
- package/dist/types/lib/providers.d.ts +1 -1
- package/dist/types/lib/snapping.d.ts +1 -1
- package/dist/types/lib/tool-buttons.d.ts +1 -1
- package/dist/types/lib/tool-capabilities.d.ts +1 -1
- package/dist/types/lib/toolbar-layout.d.ts +1 -1
- package/dist/types/preact/core.d.ts +2 -2
- package/dist/types/preact/index.d.ts +2 -2
- package/dist/types/preact-bundled/index.d.ts +3 -3
- package/dist/types/react/core.d.ts +2 -2
- package/dist/types/react/index.d.ts +2 -2
- package/dist/types/react-bundled/index.d.ts +3 -3
- package/dist/types/types/events.d.ts +1 -1
- package/dist/types/types/public.d.ts +6 -6
- package/dist/types/utils/geojson-pipeline.d.ts +1 -1
- package/dist/types/utils/geojson.d.ts +1 -1
- package/docs/api-reference.md +249 -0
- package/docs/custom-toolbar.md +168 -0
- package/docs/diagnostics.md +216 -0
- package/docs/grower-measurement.md +23 -0
- package/docs/integration-recipes.md +301 -0
- package/docs/release-verification.md +75 -0
- package/docs/shims/django.md +102 -0
- package/docs/shims/preact.md +98 -0
- package/docs/shims/react.md +98 -0
- package/docs/toolbar-layout.md +158 -0
- package/docs/toolbar-styling.md +2 -2
- package/package.json +14 -3
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
# Integration recipes
|
|
2
|
+
|
|
3
|
+
Use the public element API to keep your application independent of private
|
|
4
|
+
Leaflet handlers and Shadow DOM structure. These recipes compose existing
|
|
5
|
+
contracts; follow the linked guides for complete options and limitations.
|
|
6
|
+
|
|
7
|
+
## Start with a ready browser map
|
|
8
|
+
|
|
9
|
+
This TypeScript module is for a browser bundle. The mount point is an app-owned
|
|
10
|
+
`<div id="map-root"></div>`. Register listeners and configure properties before
|
|
11
|
+
connecting a new element; `customElements.whenDefined` alone does not mean the
|
|
12
|
+
Leaflet map is ready.
|
|
13
|
+
|
|
14
|
+
```ts
|
|
15
|
+
import { LeafletDrawMapElement } from "@florasync/leaflet-geokit";
|
|
16
|
+
|
|
17
|
+
const mount = document.getElementById("map-root");
|
|
18
|
+
if (!mount) throw new Error("Missing #map-root");
|
|
19
|
+
const map = new LeafletDrawMapElement();
|
|
20
|
+
map.style.cssText = "display:block;width:100%;height:420px";
|
|
21
|
+
map.setAttribute("draw-polygon", "");
|
|
22
|
+
map.setAttribute("draw-layer-cake", "");
|
|
23
|
+
map.setAttribute("edit-features", "");
|
|
24
|
+
map.setAttribute("tile-provider", "osm");
|
|
25
|
+
map.addEventListener("leaflet-geokit:diagnostic", (event) => {
|
|
26
|
+
console.error((event as CustomEvent).detail);
|
|
27
|
+
});
|
|
28
|
+
const ready = new Promise<void>((resolve) => {
|
|
29
|
+
const onStatus = () => {
|
|
30
|
+
if (!map.status.ready) return;
|
|
31
|
+
map.removeEventListener("leaflet-geokit:status", onStatus);
|
|
32
|
+
resolve();
|
|
33
|
+
};
|
|
34
|
+
map.addEventListener("leaflet-geokit:status", onStatus);
|
|
35
|
+
});
|
|
36
|
+
mount.append(map);
|
|
37
|
+
await ready;
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
The following browser recipes assume this ready `map`. Production hosts should
|
|
41
|
+
surface initialization failure and provide cancellation/timeout rather than leave
|
|
42
|
+
a loading UI waiting forever. Remove the element on teardown (`map.remove()`),
|
|
43
|
+
and also remove listeners attached to host-owned buttons or sidebars.
|
|
44
|
+
|
|
45
|
+
## Branded toolbar without Shadow DOM queries
|
|
46
|
+
|
|
47
|
+
For the complete worked example, use [branded toolbars and external buttons](custom-toolbar.md)
|
|
48
|
+
and its existing HTML harness. The small configuration below shows how that
|
|
49
|
+
contract composes with the ready map above: configure a managed group, then style
|
|
50
|
+
the public tokens/parts.
|
|
51
|
+
|
|
52
|
+
```ts
|
|
53
|
+
map.toolbarGroups = [
|
|
54
|
+
{
|
|
55
|
+
id: "grower",
|
|
56
|
+
tools: ["polygon", "layerCake", "layerStyle"],
|
|
57
|
+
position: "topright",
|
|
58
|
+
orientation: "horizontal",
|
|
59
|
+
ariaLabel: "Growing area tools",
|
|
60
|
+
},
|
|
61
|
+
];
|
|
62
|
+
map.toolButtonConfig = {
|
|
63
|
+
polygon: { title: "Draw a bed", ariaLabel: "Draw a growing bed" },
|
|
64
|
+
layerCake: { title: "Water zones", ariaLabel: "Draw concentric water zones" },
|
|
65
|
+
};
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
```css
|
|
69
|
+
leaflet-geokit {
|
|
70
|
+
--geokit-tool-background: #173d2b;
|
|
71
|
+
--geokit-tool-color: #fff;
|
|
72
|
+
--geokit-tool-hover-background: #275d43;
|
|
73
|
+
--geokit-tool-focus-ring: 3px solid #f3c969;
|
|
74
|
+
--geokit-tool-radius: 8px;
|
|
75
|
+
}
|
|
76
|
+
leaflet-geokit::part(toolbar-group) {
|
|
77
|
+
border: 2px solid #173d2b;
|
|
78
|
+
}
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
The dedicated [toolbar styling contract](toolbar-styling.md) owns the full token,
|
|
82
|
+
part, slot, icon and state reference. For responsive zones use
|
|
83
|
+
[toolbar layout](toolbar-layout.md); keep the focus/disabled/active affordances in
|
|
84
|
+
[accessibility](accessibility.md). `themeCss`/`theme-url` support per-tool rules
|
|
85
|
+
inside the shadow root; a `::part` selector cannot filter by inner data attributes.
|
|
86
|
+
Only pass trusted/sanitized HTML to icon and popover renderers.
|
|
87
|
+
|
|
88
|
+
## External layerCake button
|
|
89
|
+
|
|
90
|
+
An external button uses the same tool bus as the managed toolbar. Enable
|
|
91
|
+
`draw-layer-cake` before connection (as above); do not call private draw handlers.
|
|
92
|
+
|
|
93
|
+
```ts
|
|
94
|
+
const cakeButton = document.createElement("button");
|
|
95
|
+
cakeButton.type = "button";
|
|
96
|
+
cakeButton.textContent = "Draw water zones";
|
|
97
|
+
mount.before(cakeButton);
|
|
98
|
+
|
|
99
|
+
const startCake = () => {
|
|
100
|
+
map.dispatchEvent(
|
|
101
|
+
new CustomEvent("leaflet-geokit:tool-command", {
|
|
102
|
+
detail: { tool: "layerCake", source: "host-sidebar" },
|
|
103
|
+
}),
|
|
104
|
+
);
|
|
105
|
+
};
|
|
106
|
+
cakeButton.addEventListener("click", startCake);
|
|
107
|
+
|
|
108
|
+
// On host teardown, also call:
|
|
109
|
+
// cakeButton.removeEventListener("click", startCake);
|
|
110
|
+
// cakeButton.remove();
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
Alternatively, `await map.activateTool("layerCake", { source: "host-sidebar" })`
|
|
114
|
+
returns whether activation was handled; it does not mean the user saved a cake.
|
|
115
|
+
The user draws the first circle to start a draft. Only then may a sidebar call
|
|
116
|
+
`updateLayerCakeSession`, `saveLayerCakeSession`, or `cancelLayerCakeSession`.
|
|
117
|
+
Read [external cake controls](layers.md#external-cake-controls) for session events,
|
|
118
|
+
radii in meters, style presets and correlation fields. Use
|
|
119
|
+
[getToolCapabilities](tool-capabilities.md) to reflect availability in host UI and
|
|
120
|
+
[tool lifecycle](tool-lifecycle.md) to observe completion, cancellation or failure.
|
|
121
|
+
|
|
122
|
+
## Validate an upload before importing
|
|
123
|
+
|
|
124
|
+
The app owns file selection, upload limits and error rendering. This function
|
|
125
|
+
accepts file text; it returns diagnostics when the structural validation fails
|
|
126
|
+
and rejects if the map import itself fails.
|
|
127
|
+
|
|
128
|
+
```ts
|
|
129
|
+
import { importGeoJSONText } from "@florasync/leaflet-geokit";
|
|
130
|
+
|
|
131
|
+
async function importUpload(text: string) {
|
|
132
|
+
const parsed = importGeoJSONText(text);
|
|
133
|
+
if (!parsed.valid || !parsed.data) return parsed;
|
|
134
|
+
|
|
135
|
+
await map.importGeoJSON(parsed.data, {
|
|
136
|
+
behavior: "replace",
|
|
137
|
+
validate: true,
|
|
138
|
+
fitToData: true,
|
|
139
|
+
layer: { name: "Uploaded growing areas", kind: "imported" },
|
|
140
|
+
});
|
|
141
|
+
return parsed;
|
|
142
|
+
}
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
For an already-parsed value use exported `validateGeoJSON(unknown)` to inspect
|
|
146
|
+
validity or `importGeoJSONData(unknown)` to validate and obtain a normalized
|
|
147
|
+
FeatureCollection. `validate: true` on the map also checks ingest-hook output
|
|
148
|
+
before replacement; add mode rejects existing IDs. This protects against data
|
|
149
|
+
validation failures, not arbitrary renderer failures. CRS warnings are nonfatal:
|
|
150
|
+
apply your own rejection policy if needed. No automatic reprojection occurs.
|
|
151
|
+
|
|
152
|
+
The [GeoJSON pipeline guide](geojson-pipelines.md) covers diagnostic shapes,
|
|
153
|
+
URL ingestion, Multi/GeometryCollection expansion, stable IDs, source export,
|
|
154
|
+
diff/patch and metadata conflicts. Use its diagnostic `exportGeoJSONData` recipe
|
|
155
|
+
when persisting source geometry; do not confuse it with legacy source export.
|
|
156
|
+
|
|
157
|
+
## Host layer manager
|
|
158
|
+
|
|
159
|
+
Subscribe once, render a detached snapshot, and send changes through public
|
|
160
|
+
methods. Here the list is a minimal read-only summary; app-owned checkbox/style/
|
|
161
|
+
reorder controls can call the methods described below.
|
|
162
|
+
|
|
163
|
+
```ts
|
|
164
|
+
const layerList = document.createElement("ul");
|
|
165
|
+
mount.after(layerList);
|
|
166
|
+
const renderLayers = () => {
|
|
167
|
+
layerList.replaceChildren(
|
|
168
|
+
...map.getLayers().map((layer) => {
|
|
169
|
+
const item = document.createElement("li");
|
|
170
|
+
item.textContent = `${layer.name}: ${layer.visible ? "visible" : "hidden"}`;
|
|
171
|
+
return item;
|
|
172
|
+
}),
|
|
173
|
+
);
|
|
174
|
+
};
|
|
175
|
+
map.addEventListener("leaflet-geokit:layers-changed", renderLayers);
|
|
176
|
+
renderLayers();
|
|
177
|
+
|
|
178
|
+
// On host teardown, also call:
|
|
179
|
+
// map.removeEventListener("leaflet-geokit:layers-changed", renderLayers);
|
|
180
|
+
// layerList.remove();
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
Use `setLayerVisibility`, `setLayerStyle`, `focusLayer`, `reorderLayers` and
|
|
184
|
+
`removeLayer` for interactions. Reordering requires every current ID exactly once;
|
|
185
|
+
the reserved basemap cannot be removed. Hidden features still export. For
|
|
186
|
+
persistence, use `exportGeoJSON({ preserveLayers: true })` and import with
|
|
187
|
+
`{ behavior: "replace", preserveLayers: true }` on restoration.
|
|
188
|
+
|
|
189
|
+
The [layer guide](layers.md) owns these invariants, draft editing and the
|
|
190
|
+
cancelable host-owned style-panel recipe. Run the existing
|
|
191
|
+
[layer-manager harness](../layer-manager.html) through `npm run dev` for the full
|
|
192
|
+
sidebar rather than introducing another controller implementation.
|
|
193
|
+
|
|
194
|
+
## Raster providers and optional basemap adapters
|
|
195
|
+
|
|
196
|
+
The default is Leaflet with OSM. Choose `tile-provider="osm"` or `"here"` for
|
|
197
|
+
built-ins; a custom URL uses `tile-url`, not `tile-provider="custom"`.
|
|
198
|
+
After readiness, the equivalent property-based custom configuration is:
|
|
199
|
+
|
|
200
|
+
```ts
|
|
201
|
+
map.tileProvider = undefined;
|
|
202
|
+
map.tileAttribution = "Your licensed dataset attribution";
|
|
203
|
+
map.tileUrl = "/tiles/{z}/{x}/{y}.png";
|
|
204
|
+
const diagnostics = map.getProviderDiagnostics();
|
|
205
|
+
console.log(diagnostics); // Configuration report, not tile-load health.
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
The URL above is a **host-provided endpoint**, not a GeoKit tile service. Keep
|
|
209
|
+
attribution accurate. Root and `/external` export `createRasterProvider`,
|
|
210
|
+
`createCustomRasterProvider`, `createMapLibreBasemapAdapter`, and
|
|
211
|
+
`getProviderDiagnostics`. To mount an optional bridge, call
|
|
212
|
+
`map.setBasemapAdapter(adapter)` after readiness; `null` restores raster settings.
|
|
213
|
+
|
|
214
|
+
Follow [providers](providers.md) for the full injected MapLibre/PMTiles experiment,
|
|
215
|
+
shared Leaflet instance, worker/CSP setup, cleanup and production gates. It is a
|
|
216
|
+
basemap seam, not a packaged MapLibre renderer or alternate drawing engine.
|
|
217
|
+
Never put server secrets in browser properties, HTML or URLs; HERE/browser key
|
|
218
|
+
restrictions and vendor licensing remain host responsibilities. No automatic paid
|
|
219
|
+
fallback or offline cache is supplied.
|
|
220
|
+
|
|
221
|
+
## React and Preact
|
|
222
|
+
|
|
223
|
+
Actual exported component names are `ReactLeafletGeoKit` and
|
|
224
|
+
`PreactLeafletGeoKit`, not `GeoKit` or `LeafletMap`.
|
|
225
|
+
|
|
226
|
+
| Host owns Leaflet/Draw assets | Package provisions assets (browser-only) |
|
|
227
|
+
| ---------------------------------------------------------- | ------------------------------------------------------------------ |
|
|
228
|
+
| `@florasync/leaflet-geokit/react` → `ReactLeafletGeoKit` | `@florasync/leaflet-geokit/react-bundled` → `ReactLeafletGeoKit` |
|
|
229
|
+
| `@florasync/leaflet-geokit/preact` → `PreactLeafletGeoKit` | `@florasync/leaflet-geokit/preact-bundled` → `PreactLeafletGeoKit` |
|
|
230
|
+
|
|
231
|
+
Use the existing [React](shims/react.md) and [Preact](shims/preact.md) quick starts.
|
|
232
|
+
Both wrappers accept `attributes`, `toolbarGroups`, `toolButtonConfig`,
|
|
233
|
+
`toolHooks`, `toolEventEmitter`, `initialGeoJSONText`, change/error callbacks and
|
|
234
|
+
`onReady(element)`. Use `onReady` to attach the public APIs above; keep callback
|
|
235
|
+
and configuration identities stable where possible. Supply a height.
|
|
236
|
+
|
|
237
|
+
Additive wrappers default to `use-external-leaflet` and `skip-leaflet-styles`;
|
|
238
|
+
supply compatible Leaflet/Draw assets and, when needed, `leafletInstance`. Global
|
|
239
|
+
page CSS does not penetrate Shadow DOM: use `themeCss`/`theme-url` for required
|
|
240
|
+
shadow styles or explicitly opt back into injected styles. Framework runtimes
|
|
241
|
+
are consumer peers, not bundled React/Preact copies.
|
|
242
|
+
|
|
243
|
+
## Django form bridge
|
|
244
|
+
|
|
245
|
+
The exported initializer is `initDjangoGeokit`. The server renders a textarea
|
|
246
|
+
with class `geokit-editor-widget`; an app browser entry imports and initializes
|
|
247
|
+
the shim **after the textarea exists**:
|
|
248
|
+
|
|
249
|
+
```ts
|
|
250
|
+
import { initDjangoGeokit } from "@florasync/leaflet-geokit/django";
|
|
251
|
+
|
|
252
|
+
const handles = initDjangoGeokit(".geokit-editor-widget", {
|
|
253
|
+
height: 420,
|
|
254
|
+
elementAttributes: { "draw-polygon": true, "edit-features": true },
|
|
255
|
+
onError: (error, context) => console.error(context.phase, error),
|
|
256
|
+
});
|
|
257
|
+
// Before app-controlled submission, await Promise.all(handles.map(h => h.sync())).
|
|
258
|
+
// When removing the widget, call handles.forEach(h => h.destroy()).
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
See [Django shim](shims/django.md) for `data-geokit-*` configuration and form data
|
|
262
|
+
flow. The bridge hides the textarea, loads initial JSON on readiness, and writes
|
|
263
|
+
changes back to its value. For custom programmatic edits, explicitly await
|
|
264
|
+
`handle.sync()` before submission. Django still validates and authorizes posted
|
|
265
|
+
GeoJSON server-side. Load the built browser entry with a module script; a bare
|
|
266
|
+
npm specifier needs your bundler/import map, and a classic Django Media script
|
|
267
|
+
is not automatically an ESM loader. The optional browser global is
|
|
268
|
+
`window.GeoKitDjango.init`, installed by loading the shim, not by Python.
|
|
269
|
+
|
|
270
|
+
## SSR-safe imports: separate wrapper modules from browser registration
|
|
271
|
+
|
|
272
|
+
Only the **additive** `/react` and `/preact` wrappers defer element registration to
|
|
273
|
+
client effects. They can be imported in SSR code with their respective framework
|
|
274
|
+
runtime installed. They do not render a working Leaflet map on the server.
|
|
275
|
+
|
|
276
|
+
The root, `/external`, `/django`, `/react-bundled` and `/preact-bundled` entries
|
|
277
|
+
are **not SSR-safe runtime imports**: they eagerly register custom elements or
|
|
278
|
+
import the root that does. A named utility import from the root is not an
|
|
279
|
+
exception. No `/ssr`, `/geojson`, `/utils` or `/providers` subpath is exported.
|
|
280
|
+
|
|
281
|
+
Type-only imports are erased and can be used in server-shared TypeScript. For
|
|
282
|
+
plain-element or bundled integrations, dynamically import in client-only code:
|
|
283
|
+
|
|
284
|
+
```ts
|
|
285
|
+
import type { LeafletDrawMapElement } from "@florasync/leaflet-geokit";
|
|
286
|
+
|
|
287
|
+
async function createClientMap(): Promise<LeafletDrawMapElement | null> {
|
|
288
|
+
if (typeof window === "undefined" || typeof customElements === "undefined") {
|
|
289
|
+
return null;
|
|
290
|
+
}
|
|
291
|
+
const { LeafletDrawMapElement } = await import("@florasync/leaflet-geokit");
|
|
292
|
+
return new LeafletDrawMapElement(); // Configure/listen before appending.
|
|
293
|
+
}
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
Call this from your framework's client lifecycle, not during server rendering.
|
|
297
|
+
Use its client-only/no-SSR component mechanism for bundled wrappers. Do not
|
|
298
|
+
statically import a browser-only entry elsewhere in that server module graph.
|
|
299
|
+
A successful server import of an additive wrapper proves only the import boundary,
|
|
300
|
+
not hydration, asset loading or browser editing: exercise those separately with
|
|
301
|
+
the existing framework harnesses.
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# Release verification and consumer smoke
|
|
2
|
+
|
|
3
|
+
Run from the package root with installed dependencies (Node >=20, npm >=9).
|
|
4
|
+
These commands validate local source; they do not publish or authorize a release.
|
|
5
|
+
|
|
6
|
+
```sh
|
|
7
|
+
npm run prettier:check
|
|
8
|
+
npm run lint
|
|
9
|
+
npm run typecheck
|
|
10
|
+
npm run test:unit:focused -- tests/element.spec.ts tests/toolbar-contract.spec.ts tests/tool-capabilities.spec.ts tests/tool-lifecycle.spec.ts tests/geojson-pipeline.spec.ts
|
|
11
|
+
npm run build
|
|
12
|
+
npm run pack:dry
|
|
13
|
+
npm run test:consumer
|
|
14
|
+
npx playwright test --config playwright.release.config.ts --workers=1 e2e/custom-toolbar.spec.ts e2e/irrigation-draw-mode.spec.ts e2e/public-tool-acceptance.spec.ts
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
`pack:dry` invokes prepack and rebuilds. `test:consumer` expects a completed build,
|
|
18
|
+
packs with `--ignore-scripts` and `HUSKY=0` into an isolated temporary directory, checks all
|
|
19
|
+
export targets and required adoption docs in the actual tarball, rejects leaked
|
|
20
|
+
test declarations, then compiles imports of every package subpath with strict
|
|
21
|
+
TypeScript. It reuses installed dependency packages, not source aliases for
|
|
22
|
+
GeoKit, and removes its temporary consumer afterward. A missing declaration,
|
|
23
|
+
unresolved declaration dependency or absent export target fails the command.
|
|
24
|
+
This is a type-resolution smoke, not a claim that browser-only entries run in Node.
|
|
25
|
+
The gate compiles in strict NodeNext mode with `skipLibCheck: false`, including
|
|
26
|
+
transitive relative declaration imports. Some npm versions still invoke prepare
|
|
27
|
+
while packing with `--ignore-scripts`; `HUSKY=0` prevents hook installation.
|
|
28
|
+
After alias rewriting, the build normalizes relative declaration specifiers to
|
|
29
|
+
explicit `.js` paths using the TypeScript AST. This avoids depending on whether
|
|
30
|
+
the installed tsc-alias version adds extensions. Missing relative declaration
|
|
31
|
+
targets fail the build rather than ship unresolved imports.
|
|
32
|
+
|
|
33
|
+
For a release candidate, retain the full `npm run release:dry` (typecheck, coverage
|
|
34
|
+
unit suite, build, pack dry-run) and complete Playwright release suite. Focused
|
|
35
|
+
checks do not replace those gates. `.github/workflows/release-candidate.yml`
|
|
36
|
+
validates an exact source SHA and creates an immutable tarball;
|
|
37
|
+
`.github/workflows/npm-publish.yml` verifies approved bytes before publication.
|
|
38
|
+
The packed-consumer smoke is also part of `release:dry`.
|
|
39
|
+
|
|
40
|
+
## Browser evidence
|
|
41
|
+
|
|
42
|
+
- `/custom-toolbar.html`: minimal branded toolbar, guidance popover, external
|
|
43
|
+
layer-cake activation/cancel, Save export and event-based activation. Its test
|
|
44
|
+
captures light/dark mobile/tablet/desktop screenshots.
|
|
45
|
+
- `/irrigation-draw-mode.html`: retain actual external-panel and secondary-toolbar
|
|
46
|
+
geometry creation/export assertions, not just idle button rendering.
|
|
47
|
+
- `e2e/public-tool-acceptance.spec.ts`: public tool interactions.
|
|
48
|
+
- Existing provider, GeoJSON, layer-manager, accessibility, responsive toolbar and
|
|
49
|
+
touch suites remain release gates; see their `e2e/*.spec.ts` sources.
|
|
50
|
+
|
|
51
|
+
Install Chromium with `npx playwright install chromium` if absent. The committed
|
|
52
|
+
release config uses port 5173 and may reuse a dev server outside CI. In a shared
|
|
53
|
+
workspace, use an owned Playwright config with a distinct strict port, no server
|
|
54
|
+
reuse, HMR disabled and a run-owned artifact/cache directory. Do not stop another
|
|
55
|
+
agent's server or rewrite shared screenshot baselines to get green results.
|
|
56
|
+
Use polling when host inotify watches are exhausted.
|
|
57
|
+
|
|
58
|
+
## Publication and real consumer checks
|
|
59
|
+
|
|
60
|
+
1. Obtain explicit release authorization for the exact reviewed source and archive.
|
|
61
|
+
2. Run all release gates on that candidate; capture commands, statuses and SHA.
|
|
62
|
+
3. Verify package export targets and strict packed-consumer compilation.
|
|
63
|
+
4. Publish only approved bytes through the release workflow; never publish merely
|
|
64
|
+
because `pack:dry` passed.
|
|
65
|
+
5. Download the registry tarball and compare SHA-256 and registry integrity with
|
|
66
|
+
the approved archive. Verify source/tag provenance separately.
|
|
67
|
+
6. Load the version-pinned Django module in a real browser; require element
|
|
68
|
+
registration and no page errors. A 200 response alone does not prove importability.
|
|
69
|
+
7. Verify the consuming app resolves the registry version, not a sibling source
|
|
70
|
+
alias; exercise its actual React/Preact and Django surfaces, including screenshots.
|
|
71
|
+
|
|
72
|
+
Release 0.9.0 consumer evidence is tracked on FLOA-526 and FLOA-452. New local docs
|
|
73
|
+
or harness edits are not retroactively present in that published archive. Keep
|
|
74
|
+
local verification, published artifact verification and deployed app verification
|
|
75
|
+
separate in handoffs.
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
# Django shim
|
|
2
|
+
|
|
3
|
+
This shim bridges a Django form widget (`<textarea>`) to the `<leaflet-geokit>` custom element. It keeps your form field synchronized with the map editor while letting Django submit the GeoJSON value as usual.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @florasync/leaflet-geokit
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick start (Django widget)
|
|
12
|
+
|
|
13
|
+
Create a widget that renders a textarea with the shim selector class:
|
|
14
|
+
|
|
15
|
+
```python
|
|
16
|
+
# widgets.py
|
|
17
|
+
from django import forms
|
|
18
|
+
|
|
19
|
+
class LeafletGeoKitWidget(forms.Textarea):
|
|
20
|
+
template_name = "widgets/geokit_map.html"
|
|
21
|
+
|
|
22
|
+
class Media:
|
|
23
|
+
# ESM shim bundle (module script)
|
|
24
|
+
js = (
|
|
25
|
+
"https://cdn.jsdelivr.net/npm/@florasync/leaflet-geokit/dist/django/index.js",
|
|
26
|
+
)
|
|
27
|
+
css = {
|
|
28
|
+
"all": ("https://unpkg.com/leaflet/dist/leaflet.css",)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
def __init__(self, attrs=None):
|
|
32
|
+
default_attrs = {"class": "geokit-editor-widget"}
|
|
33
|
+
if attrs:
|
|
34
|
+
default_attrs.update(attrs)
|
|
35
|
+
super().__init__(default_attrs)
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Template snippet (explicit init):
|
|
39
|
+
|
|
40
|
+
```html
|
|
41
|
+
{# widgets/geokit_map.html #} {% include "django/forms/widgets/textarea.html" %}
|
|
42
|
+
<script type="module">
|
|
43
|
+
window.GeoKitDjango?.init(".geokit-editor-widget");
|
|
44
|
+
</script>
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Configuration via data attributes
|
|
48
|
+
|
|
49
|
+
The shim copies `data-geokit-*` attributes from the textarea onto the custom element, so you can configure the map per field without writing extra JS.
|
|
50
|
+
|
|
51
|
+
```html
|
|
52
|
+
<textarea
|
|
53
|
+
class="geokit-editor-widget"
|
|
54
|
+
data-geokit-height="480"
|
|
55
|
+
data-geokit-latitude="39.7392"
|
|
56
|
+
data-geokit-longitude="-104.9903"
|
|
57
|
+
data-geokit-zoom="11"
|
|
58
|
+
data-geokit-draw-polygon
|
|
59
|
+
data-geokit-draw-rectangle
|
|
60
|
+
data-geokit-edit-features
|
|
61
|
+
data-geokit-delete-features
|
|
62
|
+
></textarea>
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
Notes:
|
|
66
|
+
|
|
67
|
+
- `data-geokit-height` accepts a number (pixels) or any valid CSS height string.
|
|
68
|
+
- Boolean attributes (e.g., `data-geokit-draw-polygon`) can be written as empty, `true`, or `1` to enable. Use `false` or `0` to skip.
|
|
69
|
+
|
|
70
|
+
## Using the shim programmatically
|
|
71
|
+
|
|
72
|
+
```js
|
|
73
|
+
import { initDjangoGeokit } from "@florasync/leaflet-geokit/django";
|
|
74
|
+
|
|
75
|
+
const handles = initDjangoGeokit(".geokit-editor-widget", {
|
|
76
|
+
height: 420,
|
|
77
|
+
elementAttributes: {
|
|
78
|
+
"draw-polygon": true,
|
|
79
|
+
"draw-rectangle": true,
|
|
80
|
+
"edit-features": true,
|
|
81
|
+
"delete-features": false,
|
|
82
|
+
zoom: 12,
|
|
83
|
+
},
|
|
84
|
+
onError: (error, context) => {
|
|
85
|
+
console.error("GeoKit Django shim error", error, context);
|
|
86
|
+
},
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
// Later if needed
|
|
90
|
+
handles.forEach((handle) => handle.destroy());
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## Data flow
|
|
94
|
+
|
|
95
|
+
- The shim mounts `<leaflet-geokit>` above the textarea and hides the textarea.
|
|
96
|
+
- GeoJSON edits emit custom events (`leaflet-draw:*`); the shim calls `getGeoJSON()` and writes the serialized value back into the textarea.
|
|
97
|
+
- Initial textarea JSON (if any) is loaded into the map on `leaflet-draw:ready`.
|
|
98
|
+
|
|
99
|
+
## Troubleshooting
|
|
100
|
+
|
|
101
|
+
- If the map is blank, make sure the field has a fixed height (use `data-geokit-height` or the shim `height` option).
|
|
102
|
+
- If you see a JSON parsing error, confirm the textarea contains a valid GeoJSON FeatureCollection.
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
# Preact shims
|
|
2
|
+
|
|
3
|
+
These shims provide lightweight Preact wrappers around the [`<leaflet-geokit>`](../../src/components/LeafletDrawMapElement.ts:17) custom element.
|
|
4
|
+
|
|
5
|
+
There are **two entrypoints**:
|
|
6
|
+
|
|
7
|
+
- External/additive wrapper (host already loads Leaflet/Draw): [`@florasync/leaflet-geokit/preact`](../../package.json:9)
|
|
8
|
+
- Bundled/self-provisioned wrapper (package provides Leaflet/Draw): [`@florasync/leaflet-geokit/preact-bundled`](../../package.json:9)
|
|
9
|
+
|
|
10
|
+
## Install
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
npm install @florasync/leaflet-geokit preact
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
`preact` is a consumer-provided peer dependency for these wrappers.
|
|
17
|
+
|
|
18
|
+
## Import
|
|
19
|
+
|
|
20
|
+
External/additive mode:
|
|
21
|
+
|
|
22
|
+
```ts
|
|
23
|
+
import { PreactLeafletGeoKit } from "@florasync/leaflet-geokit/preact";
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Bundled/self-provisioned mode:
|
|
27
|
+
|
|
28
|
+
```ts
|
|
29
|
+
import { PreactLeafletGeoKit } from "@florasync/leaflet-geokit/preact-bundled";
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Quick start
|
|
33
|
+
|
|
34
|
+
```tsx
|
|
35
|
+
import { PreactLeafletGeoKit } from "@florasync/leaflet-geokit/preact";
|
|
36
|
+
|
|
37
|
+
export function MapEditor() {
|
|
38
|
+
return (
|
|
39
|
+
<PreactLeafletGeoKit
|
|
40
|
+
style={{ width: "100%", height: "420px" }}
|
|
41
|
+
attributes={{
|
|
42
|
+
latitude: 39.7392,
|
|
43
|
+
longitude: -104.9903,
|
|
44
|
+
zoom: 11,
|
|
45
|
+
"draw-polygon": true,
|
|
46
|
+
"draw-rectangle": true,
|
|
47
|
+
"edit-features": true,
|
|
48
|
+
}}
|
|
49
|
+
onChangeText={(text) => {
|
|
50
|
+
console.log(text);
|
|
51
|
+
}}
|
|
52
|
+
onError={(error) => console.error(error)}
|
|
53
|
+
/>
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Choosing an entrypoint
|
|
59
|
+
|
|
60
|
+
- Use [`@florasync/leaflet-geokit/preact`](../../package.json:9) when your app already owns Leaflet + Leaflet.draw runtime and CSS.
|
|
61
|
+
- Use [`@florasync/leaflet-geokit/preact-bundled`](../../package.json:9) when you want this package to provide Leaflet + Leaflet.draw.
|
|
62
|
+
|
|
63
|
+
## External Leaflet behavior (`/preact`)
|
|
64
|
+
|
|
65
|
+
By default, the wrapper mounts in external/additive mode:
|
|
66
|
+
|
|
67
|
+
- Sets `use-external-leaflet`
|
|
68
|
+
- Sets `skip-leaflet-styles`
|
|
69
|
+
|
|
70
|
+
So your app should load Leaflet + Leaflet.draw assets beforehand.
|
|
71
|
+
|
|
72
|
+
If needed, provide an explicit namespace via `leafletInstance`.
|
|
73
|
+
|
|
74
|
+
## Bundled behavior (`/preact-bundled`)
|
|
75
|
+
|
|
76
|
+
By default, the bundled wrapper does **not** set external/additive flags.
|
|
77
|
+
|
|
78
|
+
- Does not set `use-external-leaflet`
|
|
79
|
+
- Does not set `skip-leaflet-styles`
|
|
80
|
+
|
|
81
|
+
This is the simplest path for apps that do not preload Leaflet.
|
|
82
|
+
|
|
83
|
+
## Props (both wrappers)
|
|
84
|
+
|
|
85
|
+
- `attributes`: map of attributes forwarded to `<leaflet-geokit>`
|
|
86
|
+
- `externalLeaflet`: optional override of default wrapper mode (`/preact` defaults `true`, `/preact-bundled` defaults `false`)
|
|
87
|
+
- `leafletInstance`: explicit Leaflet namespace (`window.L` equivalent)
|
|
88
|
+
- `initialGeoJSONText`: loaded once after `leaflet-draw:ready`
|
|
89
|
+
- `onChangeText`: receives serialized GeoJSON after create/edit/delete/merge
|
|
90
|
+
- `onChangeGeoJSON`: receives parsed FeatureCollection object
|
|
91
|
+
- `onReady`: receives the underlying custom element
|
|
92
|
+
- `onError`: receives normalized `Error` objects
|
|
93
|
+
|
|
94
|
+
## Notes
|
|
95
|
+
|
|
96
|
+
- Ensure the element has a fixed height.
|
|
97
|
+
- For strict ownership by host styles, keep `externalLeaflet` enabled and provide CSS from your app.
|
|
98
|
+
- Preact wrapper entrypoints do not bundle Preact runtime code; your app provides the Preact runtime.
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
# React shims
|
|
2
|
+
|
|
3
|
+
These shims provide React wrappers around the [`<leaflet-geokit>`](../../src/components/LeafletDrawMapElement.ts:17) custom element.
|
|
4
|
+
|
|
5
|
+
There are **two entrypoints**:
|
|
6
|
+
|
|
7
|
+
- External/additive wrapper (host already loads Leaflet/Draw): [`@florasync/leaflet-geokit/react`](../../package.json:9)
|
|
8
|
+
- Bundled/self-provisioned wrapper (package provides Leaflet/Draw): [`@florasync/leaflet-geokit/react-bundled`](../../package.json:9)
|
|
9
|
+
|
|
10
|
+
## Install
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
npm install @florasync/leaflet-geokit react react-dom
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
`react` and `react-dom` are consumer-provided peer dependencies for these wrappers.
|
|
17
|
+
|
|
18
|
+
## Import
|
|
19
|
+
|
|
20
|
+
External/additive mode:
|
|
21
|
+
|
|
22
|
+
```ts
|
|
23
|
+
import { ReactLeafletGeoKit } from "@florasync/leaflet-geokit/react";
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Bundled/self-provisioned mode:
|
|
27
|
+
|
|
28
|
+
```ts
|
|
29
|
+
import { ReactLeafletGeoKit } from "@florasync/leaflet-geokit/react-bundled";
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Quick start
|
|
33
|
+
|
|
34
|
+
```tsx
|
|
35
|
+
import { ReactLeafletGeoKit } from "@florasync/leaflet-geokit/react";
|
|
36
|
+
|
|
37
|
+
export function MapEditor() {
|
|
38
|
+
return (
|
|
39
|
+
<ReactLeafletGeoKit
|
|
40
|
+
style={{ width: "100%", height: "420px" }}
|
|
41
|
+
attributes={{
|
|
42
|
+
latitude: 39.7392,
|
|
43
|
+
longitude: -104.9903,
|
|
44
|
+
zoom: 11,
|
|
45
|
+
"draw-polygon": true,
|
|
46
|
+
"draw-rectangle": true,
|
|
47
|
+
"edit-features": true,
|
|
48
|
+
}}
|
|
49
|
+
onChangeText={(text) => {
|
|
50
|
+
console.log(text);
|
|
51
|
+
}}
|
|
52
|
+
onError={(error) => console.error(error)}
|
|
53
|
+
/>
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Choosing an entrypoint
|
|
59
|
+
|
|
60
|
+
- Use [`@florasync/leaflet-geokit/react`](../../package.json:9) when your app already owns Leaflet + Leaflet.draw runtime and CSS.
|
|
61
|
+
- Use [`@florasync/leaflet-geokit/react-bundled`](../../package.json:9) when you want this package to provide Leaflet + Leaflet.draw.
|
|
62
|
+
|
|
63
|
+
## External Leaflet behavior (`/react`)
|
|
64
|
+
|
|
65
|
+
By default, the wrapper mounts in external/additive mode:
|
|
66
|
+
|
|
67
|
+
- Sets `use-external-leaflet`
|
|
68
|
+
- Sets `skip-leaflet-styles`
|
|
69
|
+
|
|
70
|
+
So your app should load Leaflet + Leaflet.draw assets beforehand.
|
|
71
|
+
|
|
72
|
+
If needed, provide an explicit namespace via `leafletInstance`.
|
|
73
|
+
|
|
74
|
+
## Bundled behavior (`/react-bundled`)
|
|
75
|
+
|
|
76
|
+
By default, the bundled wrapper does **not** set external/additive flags.
|
|
77
|
+
|
|
78
|
+
- Does not set `use-external-leaflet`
|
|
79
|
+
- Does not set `skip-leaflet-styles`
|
|
80
|
+
|
|
81
|
+
This is the simplest path for apps that do not preload Leaflet.
|
|
82
|
+
|
|
83
|
+
## Props (both wrappers)
|
|
84
|
+
|
|
85
|
+
- `attributes`: map of attributes forwarded to `<leaflet-geokit>`
|
|
86
|
+
- `externalLeaflet`: optional override of default wrapper mode (`/react` defaults `true`, `/react-bundled` defaults `false`)
|
|
87
|
+
- `leafletInstance`: explicit Leaflet namespace (`window.L` equivalent)
|
|
88
|
+
- `initialGeoJSONText`: loaded once after `leaflet-draw:ready`
|
|
89
|
+
- `onChangeText`: receives serialized GeoJSON after create/edit/delete/merge
|
|
90
|
+
- `onChangeGeoJSON`: receives parsed FeatureCollection object
|
|
91
|
+
- `onReady`: receives the underlying custom element
|
|
92
|
+
- `onError`: receives normalized `Error` objects
|
|
93
|
+
|
|
94
|
+
## Notes
|
|
95
|
+
|
|
96
|
+
- Ensure the element has a fixed height.
|
|
97
|
+
- For strict ownership by host styles, keep `externalLeaflet` enabled and provide CSS from your app.
|
|
98
|
+
- React wrapper entrypoints do not bundle React runtime code; your app provides the React runtime.
|