@florasync/leaflet-geokit 0.8.1 → 0.8.3

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/CHANGELOG.md CHANGED
@@ -2,6 +2,19 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 0.8.3 - 2026-08-28
6
+
7
+ - Upgraded `uuid` to a patched release so consumer audits no longer inherit GHSA-w5hq-g745-h8pq through GeoKit.
8
+ - Hardened managed toolbar styling so branded `<button>` controls receive the same polished FloraSync treatment as Leaflet's default anchor controls.
9
+ - Added CSS-level hiding for duplicate default Leaflet.draw/ruler toolbars whenever managed toolbar groups are active.
10
+
11
+ ## 0.8.2 - 2026-08-24
12
+
13
+ - Added `save` as a first-class custom toolbar tool; activating it emits `leaflet-draw:export` with the current editable GeoJSON so host apps can persist map geometry from branded controls.
14
+ - Custom `toolbarGroups` now hide duplicate built-in Leaflet.draw/ruler toolbars by default, with per-group `hideDefaultToolbar: false` escape hatch.
15
+ - Replaced text fallback glyphs in custom toolbar groups with built-in SVG icons for every supported tool so incomplete host configs still render usable controls.
16
+ - Updated the irrigation draw harness and E2E coverage to prove custom draw/select/save controls work without duplicate default toolbars.
17
+
5
18
  ## 0.8.1 - 2026-07-15
6
19
 
7
20
  - Added `toolbarGroups` / `toolbar-groups` for multiple independent map toolbar groups with Leaflet-like corner placement.
package/README.md CHANGED
@@ -369,7 +369,7 @@ Customize the visual appearance:
369
369
  - **`theme-url`** (string, optional): External CSS stylesheet URL to inject into Shadow DOM
370
370
  - **`themeCss`** (property only): Inline CSS strings for custom styling
371
371
  - **`tool-button-config`** (JSON string, optional): Per-tool toolbar button config for custom icons, labels, and theme classes
372
- - **`toolbar-groups`** (JSON array, optional): Additional map toolbar groups with independent tool sets and corner placement
372
+ - **`toolbar-groups`** (JSON array, optional): Additional map toolbar groups with independent tool sets and corner placement. Custom groups hide the built-in Leaflet.draw/ruler toolbars by default so duplicate controls do not sit underneath branded buttons; set `hideDefaultToolbar: false` on a group only when the native toolbar should remain visible.
373
373
 
374
374
  ```html
375
375
  <leaflet-geokit theme-url="/css/custom-map-theme.css"></leaflet-geokit>
@@ -405,7 +405,7 @@ Customize the visual appearance:
405
405
  {
406
406
  "id": "irrigation-draw",
407
407
  "position": "bottomright",
408
- "tools": ["polygon", "select"]
408
+ "tools": ["polygon", "select", "save"]
409
409
  },
410
410
  {
411
411
  "id": "irrigation-style",
@@ -424,7 +424,7 @@ buttons without depending on Leaflet's sprite class names.
424
424
  #### Debugging & Development
425
425
 
426
426
  - **`log-level`** (string): Control console logging verbosity. Options: `trace`, `debug`, `info`, `warn`, `error`, `silent`. Default: `"debug"`
427
- - **`dev-overlay`** (boolean): Reserved for future development overlay features
427
+ - **`dev-overlay`** (boolean): Reserved compatibility flag. No overlay UI ships in `0.8.x`.
428
428
 
429
429
  ```html
430
430
  <leaflet-geokit log-level="info"></leaflet-geokit>
@@ -478,7 +478,7 @@ map.toolbarGroups = [
478
478
  {
479
479
  id: "irrigation-draw",
480
480
  position: "bottomright",
481
- tools: ["polygon", "select"],
481
+ tools: ["polygon", "select", "save"],
482
482
  ariaLabel: "Irrigation drawing tools",
483
483
  },
484
484
  {
@@ -534,7 +534,7 @@ const toolbarGroups: ToolToolbarGroupConfig[] = [
534
534
  {
535
535
  id: "irrigation-draw",
536
536
  position: "bottomright",
537
- tools: ["polygon", "select"],
537
+ tools: ["polygon", "select", "save"],
538
538
  ariaLabel: "Irrigation drawing tools",
539
539
  },
540
540
  {
@@ -551,8 +551,10 @@ map!.toolbarGroups = toolbarGroups;
551
551
 
552
552
  Supported tool keys are `polygon`, `polyline`, `rectangle`, `circle`, `marker`,
553
553
  `layerCake`, `move`, `select`, `edit`, `delete`, `ruler`,
554
- `measurementSettings`, and `layerStyle`. `select` disables active draw/edit
555
- handlers; `layerStyle` emits a public trigger event for host-owned style panels.
554
+ `measurementSettings`, `layerStyle`, and `save`. `select` disables active draw/edit
555
+ handlers; `layerStyle` emits a public trigger event for host-owned style panels;
556
+ `save` emits `leaflet-draw:export` with the current editable GeoJSON for host
557
+ persistence.
556
558
 
557
559
  `map.toolButtonConfig` takes precedence over the `tool-button-config` attribute;
558
560
  `map.toolbarGroups` takes precedence over the `toolbar-groups` attribute. Set a
@@ -602,8 +604,8 @@ GeoKit emits `leaflet-geokit:tool-trigger-requested`, then either
602
604
  `groupId`, `handled`, `timestamp`, and optional `error`.
603
605
 
604
606
  See `irrigation-draw-mode.html` for a working integration demo with custom
605
- icons, popovers, two toolbar groups, an external panel button, and real polygon
606
- draw activation.
607
+ icons, popovers, two toolbar groups, an external panel button, real polygon
608
+ draw activation, and a custom save button.
607
609
 
608
610
  #### Programmatic Marker Icon Override
609
611
 
@@ -766,8 +768,25 @@ const data = await map.getGeoJSON();
766
768
  console.log(`${data.features.length} features on map`);
767
769
  ```
768
770
 
771
+ **[`importGeoJSON(fc, options?)`](src/components/LeafletDrawMapElement.ts)**: Promise<string[]>
772
+
773
+ - Explicit import contract for host apps: `behavior: "replace" | "add"`
774
+ - `replace` clears existing data before ingest; `add` preserves existing map data
775
+ - `fitToData` is optional and defaults to `false` for direct programmatic imports
776
+ - Returns array of assigned stable feature IDs
777
+ - Triggers [`leaflet-draw:ingest`](src/types/events.ts:51) event before import (`mode: "load"` for replace, `mode: "add"` for additive imports)
778
+
779
+ ```javascript
780
+ const ids = await map.importGeoJSON(newFeatures, {
781
+ behavior: "add",
782
+ fitToData: true,
783
+ });
784
+ console.log("Imported features with IDs:", ids);
785
+ ```
786
+
769
787
  **[`loadGeoJSON(fc)`](src/components/LeafletDrawMapElement.ts:390)**: Promise<void>
770
788
 
789
+ - Back-compat alias for `importGeoJSON(fc, { behavior: "replace" })`
771
790
  - Clears existing data and loads new FeatureCollection
772
791
  - Does NOT auto-fit the view (use [`fitBoundsToData()`](src/components/LeafletDrawMapElement.ts:428) separately)
773
792
  - Triggers [`leaflet-draw:ingest`](src/types/events.ts:51) event before loading
@@ -775,14 +794,13 @@ console.log(`${data.features.length} features on map`);
775
794
  ```javascript
776
795
  await map.loadGeoJSON({
777
796
  type: "FeatureCollection",
778
- features: [
779
- /* ... */
780
- ],
797
+ features: [/* ... */],
781
798
  });
782
799
  ```
783
800
 
784
801
  **[`addFeatures(fc)`](src/components/LeafletDrawMapElement.ts:406)**: Promise<string[]>
785
802
 
803
+ - Back-compat alias for `importGeoJSON(fc, { behavior: "add" })`
786
804
  - Adds features to existing map data (does not clear)
787
805
  - Returns array of assigned stable feature IDs
788
806
  - Expands `Multi*` and `GeometryCollection` inputs into one single-geometry feature/id per child part
@@ -812,9 +830,7 @@ await map.clearLayers();
812
830
  await map.updateFeature(featureId, {
813
831
  type: "Feature",
814
832
  properties: { name: "Updated" },
815
- geometry: {
816
- /* ... */
817
- },
833
+ geometry: {/* ... */},
818
834
  });
819
835
  ```
820
836
 
@@ -864,36 +880,43 @@ await map.fitBounds(
864
880
 
865
881
  #### Data Import Helpers
866
882
 
867
- **[`loadGeoJSONFromUrl(url)`](src/components/LeafletDrawMapElement.ts:510)**: Promise<void>
883
+ **[`loadGeoJSONFromUrl(url, options?)`](src/components/LeafletDrawMapElement.ts:510)**: Promise<void>
868
884
 
869
- - Fetches GeoJSON from URL and loads it
885
+ - Fetches GeoJSON from URL and imports it with explicit `behavior: "replace" | "add"`
870
886
  - Expects `application/json` content type
871
- - Automatically fits view to loaded data
872
- - Emits error events on fetch/parse failures
887
+ - Defaults to `behavior: "replace"` and `fitToData: true` for file/URL style imports
888
+ - Emits error events on fetch/parse/import failures
873
889
 
874
890
  ```javascript
875
- await map.loadGeoJSONFromUrl("/api/geodata.json");
891
+ await map.loadGeoJSONFromUrl("/api/geodata.json", {
892
+ behavior: "add",
893
+ });
876
894
  ```
877
895
 
878
- **[`loadGeoJSONFromText(text)`](src/components/LeafletDrawMapElement.ts:533)**: Promise<void>
896
+ **[`loadGeoJSONFromText(text, options?)`](src/components/LeafletDrawMapElement.ts:533)**: Promise<void>
879
897
 
880
- - Parses GeoJSON from text string and loads it
881
- - Automatically fits view to loaded data
882
- - Emits error events on parse failures
898
+ - Parses GeoJSON from text string and imports it with explicit `behavior: "replace" | "add"`
899
+ - Defaults to `behavior: "replace"` and `fitToData: true`
900
+ - Emits error events on parse/import failures
883
901
 
884
902
  ```javascript
885
903
  const text = await file.text();
886
- await map.loadGeoJSONFromText(text);
904
+ await map.loadGeoJSONFromText(text, {
905
+ behavior: "replace",
906
+ });
887
907
  ```
888
908
 
889
- **[`exportGeoJSON()`](src/components/LeafletDrawMapElement.ts:459)**: Promise<FeatureCollection>
909
+ **[`exportGeoJSON(options?)`](src/components/LeafletDrawMapElement.ts:459)**: Promise<FeatureCollection>
890
910
 
891
911
  - Exports current data and emits [`leaflet-draw:export`](src/types/events.ts:57) event
892
- - Returns the FeatureCollection for convenience
893
- - Useful for triggering export workflows
912
+ - Defaults to `adapter: "editing"`, which preserves the current editable single-geometry feature state
913
+ - `adapter: "source"` opt-in re-merges stable derived sibling IDs like `bed-1::0` / `bed-1::1` back into source-like `Multi*` or `GeometryCollection` output
914
+ - Source export is intentionally opt-in because sibling property divergence is resolved by reusing the first child properties
894
915
 
895
916
  ```javascript
896
- const exported = await map.exportGeoJSON();
917
+ const exported = await map.exportGeoJSON({
918
+ adapter: "source",
919
+ });
897
920
  // Listen for the event to trigger download/save workflows
898
921
  ```
899
922
 
@@ -927,9 +950,41 @@ The component emits typed CustomEvents that can be listened to for real-time upd
927
950
 
928
951
  #### Core Lifecycle Events
929
952
 
930
- **[`leaflet-draw:ready`](src/types/events.ts:7)**
953
+ **[`leaflet-geokit:status`](src/types/events.ts)**
954
+
955
+ - Fired whenever the public readiness/loading/error snapshot changes
956
+ - Also mirrored on the element as `map.status`
957
+ - Detail: `{ state, ready, busy, featureCount, lastEvent?, lastError?, timestamp }`
958
+
959
+ ```javascript
960
+ map.addEventListener("leaflet-geokit:status", (e) => {
961
+ const { state, featureCount, lastError } = e.detail;
962
+ console.log("GeoKit status:", state, featureCount, lastError?.code);
963
+ });
964
+
965
+ console.log(map.status.state); // 'uninitialized' | 'initializing' | 'ready' | 'loading' | 'error'
966
+ ```
967
+
968
+ **[`leaflet-geokit:diagnostic`](src/types/events.ts)**
931
969
 
932
- - Fired when map is fully initialized and ready for interaction
970
+ - Fired for recoverable and fatal diagnostics
971
+ - Recoverable diagnostics keep `status.state` at `ready` when the map remains usable
972
+ - Detail: `{ code, message, recoverable, severity, state, cause?, timestamp }`
973
+
974
+ ```javascript
975
+ map.addEventListener("leaflet-geokit:diagnostic", (e) => {
976
+ if (e.detail.recoverable) {
977
+ console.warn("Recoverable GeoKit issue:", e.detail.code, e.detail.message);
978
+ return;
979
+ }
980
+
981
+ console.error("Fatal GeoKit issue:", e.detail.code, e.detail.message);
982
+ });
983
+ ```
984
+
985
+ **[`leaflet-draw:ready`](src/types/events.ts)**
986
+
987
+ - Compatibility event fired when the map is fully initialized and ready for interaction
933
988
  - Detail: `{ bounds?: [[number, number], [number, number]] }`
934
989
 
935
990
  ```javascript
@@ -938,21 +993,26 @@ map.addEventListener("leaflet-draw:ready", (e) => {
938
993
  });
939
994
  ```
940
995
 
941
- **[`leaflet-draw:error`](src/types/events.ts:42)**
996
+ **[`leaflet-draw:error`](src/types/events.ts)**
942
997
 
943
- - Fired when errors occur (fetch failures, parse errors, etc.)
944
- - Also used for non-fatal marker icon normalization warnings before GeoKit falls back to defaults
945
- - Detail: `{ message: string, cause?: unknown }`
998
+ - Fired when GeoKit hits a typed error condition (fetch failures, parse errors, init failures, config warnings)
999
+ - Recoverable warnings still emit here for backward compatibility
1000
+ - Detail: `{ code, message, recoverable, cause?, timestamp }`
946
1001
 
947
1002
  ```javascript
948
1003
  map.addEventListener("leaflet-draw:error", (e) => {
949
- console.error("Map error:", e.detail.message, e.detail.cause);
1004
+ console.error(
1005
+ "Map error:",
1006
+ e.detail.code,
1007
+ e.detail.message,
1008
+ e.detail.recoverable,
1009
+ );
950
1010
  });
951
1011
  ```
952
1012
 
953
1013
  #### Drawing & Editing Events
954
1014
 
955
- **[`leaflet-draw:created`](src/types/events.ts:15)**
1015
+ **[`leaflet-draw:created`](src/types/events.ts)**
956
1016
 
957
1017
  - Fired when user creates a new feature via drawing tools
958
1018
  - Detail: `{ id: string, layerType: string, geoJSON: Feature }`
@@ -968,7 +1028,7 @@ map.addEventListener('leaflet-draw:created', (e) => {
968
1028
  });
969
1029
  ```
970
1030
 
971
- **[`leaflet-draw:edited`](src/types/events.ts:25)**
1031
+ **[`leaflet-draw:edited`](src/types/events.ts)**
972
1032
 
973
1033
  - Fired when user modifies existing features via edit tools
974
1034
  - Detail: `{ ids: string[], geoJSON: FeatureCollection }`
@@ -987,7 +1047,7 @@ map.addEventListener('leaflet-draw:edited', (e) => {
987
1047
  });
988
1048
  ```
989
1049
 
990
- **[`leaflet-draw:deleted`](src/types/events.ts:34)**
1050
+ **[`leaflet-draw:deleted`](src/types/events.ts)**
991
1051
 
992
1052
  - Fired when user deletes features via delete tools
993
1053
  - Detail: `{ ids: string[], geoJSON: FeatureCollection }`
@@ -1007,7 +1067,7 @@ map.addEventListener('leaflet-draw:deleted', (e) => {
1007
1067
 
1008
1068
  #### Data Flow Events
1009
1069
 
1010
- **[`leaflet-draw:ingest`](src/types/events.ts:51)**
1070
+ **[`leaflet-draw:ingest`](src/types/events.ts)**
1011
1071
 
1012
1072
  - Fired BEFORE data is loaded/added to the map
1013
1073
  - Detail: `{ fc: FeatureCollection, mode: 'load' | 'add' }`
@@ -1034,7 +1094,7 @@ map.addEventListener("leaflet-draw:ingest", (e) => {
1034
1094
  });
1035
1095
  ```
1036
1096
 
1037
- **[`leaflet-draw:export`](src/types/events.ts:57)**
1097
+ **[`leaflet-draw:export`](src/types/events.ts)**
1038
1098
 
1039
1099
  - Fired when [`exportGeoJSON()`](src/components/LeafletDrawMapElement.ts:459) method is called
1040
1100
  - Detail: `{ geoJSON: FeatureCollection, featureCount: number }`
@@ -1056,32 +1116,16 @@ map.addEventListener("leaflet-draw:export", (e) => {
1056
1116
  });
1057
1117
  ```
1058
1118
 
1059
- #### Extended Tool Events
1060
-
1061
- **`leaflet-draw:drawstart`** / **`leaflet-draw:drawstop`**
1062
-
1063
- - Fired when drawing mode starts/stops
1064
- - Useful for UI state management
1065
-
1066
- **`leaflet-draw:editstart`** / **`leaflet-draw:editstop`**
1067
-
1068
- - Fired when edit mode starts/stops
1119
+ #### Merge and Tool Events
1069
1120
 
1070
1121
  **`leaflet-draw:merged`**
1071
1122
 
1072
1123
  - Fired after successful polygon merge operation
1073
1124
  - Detail includes merge statistics and result
1074
1125
 
1075
- ```javascript
1076
- // Show/hide UI elements based on draw state
1077
- map.addEventListener("leaflet-draw:drawstart", () => {
1078
- document.querySelector("#toolbar").classList.add("drawing-active");
1079
- });
1080
-
1081
- map.addEventListener("leaflet-draw:drawstop", () => {
1082
- document.querySelector("#toolbar").classList.remove("drawing-active");
1083
- });
1084
- ```
1126
+ GeoKit `0.8.x` does not emit public draw/edit start-stop lifecycle events.
1127
+ Use `leaflet-geokit:status` for readiness/loading coordination and the
1128
+ `leaflet-geokit:tool-*` events for host-triggered tool actions.
1085
1129
 
1086
1130
  ### Feature ID Management
1087
1131
 
@@ -1091,6 +1135,7 @@ The component guarantees stable, persistent feature IDs that survive editing ope
1091
1135
  2. **Property IDs**: If no `feature.id` but has `properties.id`, that's used
1092
1136
  3. **Generated IDs**: Otherwise, a UUID is generated and stored in `properties.id`
1093
1137
  4. **Multi-geometry normalization**: `MultiPoint`, `MultiLineString`, `MultiPolygon`, and `GeometryCollection` inputs are expanded into single-geometry features. If the source feature already had an ID, each child receives a stable derived ID such as `bed-1::0` and `bed-1::1`
1138
+ 5. **Opt-in source export**: `exportGeoJSON({ adapter: "source" })` best-effort re-merges those stable derived siblings into source-like `Multi*`/`GeometryCollection` output for hosts that want source-shaped files back
1094
1139
 
1095
1140
  ```javascript
1096
1141
  // Features maintain their IDs through edit cycles
@@ -1193,7 +1238,9 @@ C. Load from text (e.g., user paste or file input)
1193
1238
 
1194
1239
  ```js
1195
1240
  const text = await file.text();
1196
- await el.loadGeoJSONFromText(text);
1241
+ await el.loadGeoJSONFromText(text, {
1242
+ behavior: "add", // or "replace" to clear existing map data first
1243
+ });
1197
1244
  ```
1198
1245
 
1199
1246
  D. Programmatic CRUD with ids
@@ -1431,11 +1478,9 @@ SSR
1431
1478
 
1432
1479
  Planned enhancements
1433
1480
 
1434
- - Dev overlay (opt-in) to visualize state, counts, and last event payloads
1435
1481
  - Geometry-level layer sync for updateFeature without re-add
1436
1482
  - Playwright e2e and CI workflows
1437
1483
  - Advanced import providers (files, streams) and output format adapters
1438
- - Theming hooks for overlay UI
1439
1484
 
1440
1485
  Versioning and releases
1441
1486