@octostar/map-component 0.2.3 → 0.2.5

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/dist/index.mjs CHANGED
@@ -1745,6 +1745,7 @@ function LayersPanel({
1745
1745
  externalPersistence = false,
1746
1746
  customGlobalMenuItems,
1747
1747
  extraLayerToolbarButtons,
1748
+ extraNewLayerButtons,
1748
1749
  layerBadgeProvider,
1749
1750
  featureCountProvider
1750
1751
  }) {
@@ -2690,7 +2691,8 @@ function LayersPanel({
2690
2691
  className: "!w-7 !h-7 !min-w-0 !p-0 shrink-0",
2691
2692
  "data-testid": "button-search-new-layer"
2692
2693
  }
2693
- ) })
2694
+ ) }),
2695
+ extraNewLayerButtons
2694
2696
  ] })
2695
2697
  ] }),
2696
2698
  /* @__PURE__ */ jsx("div", { className: "flex-1 min-h-0 overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "p-1.5 space-y-0.5 pr-2", children: [
@@ -2782,6 +2784,32 @@ function formatDateForState(value) {
2782
2784
  }
2783
2785
  return "";
2784
2786
  }
2787
+ const ENTITY_CARDS_RENDER_CAP = 50;
2788
+ function EntityCardsList({
2789
+ selectedFeatures,
2790
+ entityCardProvider
2791
+ }) {
2792
+ const shown = selectedFeatures.slice(0, ENTITY_CARDS_RENDER_CAP);
2793
+ return /* @__PURE__ */ jsxs("div", { className: "p-2 space-y-2", children: [
2794
+ shown.map((f) => {
2795
+ const geoFeature = {
2796
+ type: "Feature",
2797
+ id: f.id,
2798
+ geometry: f.geometry,
2799
+ properties: f.properties
2800
+ };
2801
+ const card = entityCardProvider(geoFeature);
2802
+ return card ? /* @__PURE__ */ jsx("div", { className: "border border-border rounded-md p-2 bg-card", children: card }, f.id) : null;
2803
+ }),
2804
+ selectedFeatures.length > shown.length && /* @__PURE__ */ jsxs("div", { className: "text-center py-2 text-muted-foreground text-sm", "data-testid": "entity-cards-cap-note", children: [
2805
+ "Showing the first ",
2806
+ shown.length,
2807
+ " of ",
2808
+ selectedFeatures.length.toLocaleString(),
2809
+ " selected features"
2810
+ ] })
2811
+ ] });
2812
+ }
2785
2813
  function getFeatureTypeIcon(geometryType, kind, size = "sm") {
2786
2814
  const cls = size === "lg" ? "w-5 h-5" : "w-4 h-4";
2787
2815
  if (kind === "text") {
@@ -3383,16 +3411,7 @@ function PropertiesPanel({ selectedFeatures, onUpdateProperties, onUpdateGeometr
3383
3411
  const recordProperties = feature ? Object.entries(feature.properties).filter(
3384
3412
  ([key, value]) => !isExcludedRecordKey(key) && value !== void 0 && value !== null && !key.startsWith("_") && !key.startsWith("os_") && !key.startsWith("isHidden")
3385
3413
  ).map(([key, value]) => ({ key, value: formatFieldValue(String(value)) })) : [];
3386
- const entityCardsContent = /* @__PURE__ */ jsx("div", { className: "p-2 space-y-2", children: entityCardProvider ? selectedFeatures.map((f) => {
3387
- const geoFeature = {
3388
- type: "Feature",
3389
- id: f.id,
3390
- geometry: f.geometry,
3391
- properties: f.properties
3392
- };
3393
- const card = entityCardProvider(geoFeature);
3394
- return card ? /* @__PURE__ */ jsx("div", { className: "border border-border rounded-md p-2 bg-card", children: card }, f.id) : null;
3395
- }) : /* @__PURE__ */ jsx("div", { className: "text-center py-4 text-muted-foreground text-sm", children: "No entity card provider registered" }) });
3414
+ const entityCardsContent = entityCardProvider ? /* @__PURE__ */ jsx(EntityCardsList, { selectedFeatures, entityCardProvider }) : /* @__PURE__ */ jsx("div", { className: "p-2 space-y-2", children: /* @__PURE__ */ jsx("div", { className: "text-center py-4 text-muted-foreground text-sm", children: "No entity card provider registered" }) });
3396
3415
  const propertiesDisabledOverlay = /* @__PURE__ */ jsx("div", { className: "absolute inset-0 bg-background/80 flex items-center justify-center z-10 rounded-md", children: /* @__PURE__ */ jsx("p", { className: "text-sm text-muted-foreground text-center px-4", children: "Select a single feature to see/set properties" }) });
3397
3416
  if (hasMultipleSelection && !entityCardProvider) {
3398
3417
  return /* @__PURE__ */ jsxs(
@@ -3455,7 +3474,7 @@ function PropertiesPanel({ selectedFeatures, onUpdateProperties, onUpdateGeometr
3455
3474
  /* @__PURE__ */ jsx(Divider, { className: "!my-1.5" }),
3456
3475
  /* @__PURE__ */ jsxs("div", { className: "space-y-0.5", children: [
3457
3476
  /* @__PURE__ */ jsx("label", { htmlFor: "feature-name", className: "text-xs text-muted-foreground", children: feature.properties.kind === "text" ? "Label" : "Name" }),
3458
- /* @__PURE__ */ jsx(
3477
+ isEditMode ? /* @__PURE__ */ jsx(
3459
3478
  Input,
3460
3479
  {
3461
3480
  ref: nameInputRef,
@@ -3468,11 +3487,14 @@ function PropertiesPanel({ selectedFeatures, onUpdateProperties, onUpdateGeometr
3468
3487
  }
3469
3488
  },
3470
3489
  onBlur: () => handleSave(),
3471
- placeholder: isEditMode ? feature.properties.kind === "text" ? "Enter label..." : "Feature name" : "No name",
3472
- readOnly: !isEditMode,
3490
+ placeholder: feature.properties.kind === "text" ? "Enter label..." : "Feature name",
3473
3491
  className: "!h-6 text-[13px]",
3474
3492
  "data-testid": "input-feature-name"
3475
3493
  }
3494
+ ) : (
3495
+ // Static in view mode — a readOnly Input keeps the editable look
3496
+ // but swallows every keystroke (see LatLngFields).
3497
+ /* @__PURE__ */ jsx("div", { className: "text-[13px] px-1 py-0.5 break-words", "data-testid": "text-feature-name", children: name || /* @__PURE__ */ jsx("span", { className: "text-muted-foreground", children: "No name" }) })
3476
3498
  )
3477
3499
  ] }),
3478
3500
  (typePickerProvider || feature.geometry.type === "Point" && feature.properties.kind !== "text" && pointIcon) && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
@@ -3943,7 +3965,7 @@ function PropertiesPanel({ selectedFeatures, onUpdateProperties, onUpdateGeometr
3943
3965
  /* @__PURE__ */ jsxs("div", { className: "space-y-1", children: [
3944
3966
  /* @__PURE__ */ jsxs("div", { className: "flex items-start gap-1", children: [
3945
3967
  /* @__PURE__ */ jsx("div", { className: "text-[13px] font-mono text-muted-foreground shrink-0 w-24 px-1 leading-6 select-none", children: "description" }),
3946
- /* @__PURE__ */ jsx(
3968
+ isEditMode ? /* @__PURE__ */ jsx(
3947
3969
  TextArea,
3948
3970
  {
3949
3971
  id: "feature-description",
@@ -3951,14 +3973,13 @@ function PropertiesPanel({ selectedFeatures, onUpdateProperties, onUpdateGeometr
3951
3973
  onChange: (e) => setDescription(e.target.value),
3952
3974
  onBlur: () => handleSave(),
3953
3975
  autoSize: { minRows: 1, maxRows: 5 },
3954
- placeholder: isEditMode ? "—" : "",
3955
- readOnly: !isEditMode,
3976
+ placeholder: "—",
3956
3977
  className: "flex-1 !text-[13px] !px-1.5 !py-0.5 resize-none",
3957
3978
  "data-testid": "input-feature-description"
3958
3979
  }
3959
- )
3980
+ ) : /* @__PURE__ */ jsx("div", { className: "flex-1 text-[13px] px-1.5 leading-6 break-words", "data-testid": "text-feature-description", children: description || /* @__PURE__ */ jsx("span", { className: "text-muted-foreground", children: "—" }) })
3960
3981
  ] }),
3961
- customProperties.map((prop, index) => /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1", children: [
3982
+ customProperties.map((prop, index) => /* @__PURE__ */ jsx("div", { className: isEditMode ? "flex items-center gap-1" : "flex items-start gap-1", children: isEditMode ? /* @__PURE__ */ jsxs(Fragment, { children: [
3962
3983
  /* @__PURE__ */ jsx(
3963
3984
  Input,
3964
3985
  {
@@ -3966,8 +3987,8 @@ function PropertiesPanel({ selectedFeatures, onUpdateProperties, onUpdateGeometr
3966
3987
  onChange: (e) => handlePropertyKeyChange(index, e.target.value),
3967
3988
  onBlur: () => handleSave(),
3968
3989
  placeholder: "Key",
3990
+ style: { width: "6rem", flex: "0 0 6rem" },
3969
3991
  className: "shrink-0 w-24 text-[13px] font-mono !h-6 !px-1",
3970
- readOnly: !isEditMode,
3971
3992
  "data-testid": `input-property-key-${index}`
3972
3993
  }
3973
3994
  ),
@@ -3979,11 +4000,10 @@ function PropertiesPanel({ selectedFeatures, onUpdateProperties, onUpdateGeometr
3979
4000
  onBlur: () => handleSave(),
3980
4001
  placeholder: "Value",
3981
4002
  className: "flex-1 text-[13px] !h-6 !px-1.5",
3982
- readOnly: !isEditMode,
3983
4003
  "data-testid": `input-property-value-${index}`
3984
4004
  }
3985
4005
  ),
3986
- isEditMode && /* @__PURE__ */ jsx(
4006
+ /* @__PURE__ */ jsx(
3987
4007
  "button",
3988
4008
  {
3989
4009
  type: "button",
@@ -3996,7 +4016,10 @@ function PropertiesPanel({ selectedFeatures, onUpdateProperties, onUpdateGeometr
3996
4016
  children: /* @__PURE__ */ jsx(Trash2, { className: "w-3 h-3" })
3997
4017
  }
3998
4018
  )
3999
- ] }, index))
4019
+ ] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
4020
+ /* @__PURE__ */ jsx("div", { className: "text-[13px] font-mono text-muted-foreground shrink-0 w-24 px-1 leading-6 select-none break-all", children: prop.key }),
4021
+ /* @__PURE__ */ jsx("div", { className: "flex-1 text-[13px] px-1.5 leading-6 break-words", "data-testid": `text-property-value-${index}`, children: prop.value || /* @__PURE__ */ jsx("span", { className: "text-muted-foreground", children: "—" }) })
4022
+ ] }) }, index))
4000
4023
  ] }),
4001
4024
  isEditMode && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1 pt-0.5", children: [
4002
4025
  /* @__PURE__ */ jsx(
@@ -5270,6 +5293,86 @@ function useMapHistory(options) {
5270
5293
  }, [history, rerender]);
5271
5294
  return { push, undo, redo, clear, canUndo: history.canUndo, canRedo: history.canRedo };
5272
5295
  }
5296
+ function historyLayersEqual(a, b) {
5297
+ if (a.featureIds.length !== b.featureIds.length) return false;
5298
+ for (let i = 0; i < a.featureIds.length; i += 1) {
5299
+ if (a.featureIds[i] !== b.featureIds[i]) return false;
5300
+ }
5301
+ const { featureIds: _aIds, ...aRest } = a;
5302
+ const { featureIds: _bIds, ...bRest } = b;
5303
+ return JSON.stringify(aRest) === JSON.stringify(bRest);
5304
+ }
5305
+ function diffHistorySnapshots(before, after, beforeLayers, afterLayers) {
5306
+ const allFeatureIds = /* @__PURE__ */ new Set();
5307
+ before.forEach((_v, k) => allFeatureIds.add(k));
5308
+ after.forEach((_v, k) => allFeatureIds.add(k));
5309
+ const featureIds = /* @__PURE__ */ new Set();
5310
+ allFeatureIds.forEach((id) => {
5311
+ const b = before.get(id);
5312
+ const a = after.get(id);
5313
+ if (!b || !a || b.layerId !== a.layerId || b.store !== a.store) {
5314
+ featureIds.add(id);
5315
+ return;
5316
+ }
5317
+ if (b.feature === a.feature) return;
5318
+ if (JSON.stringify(b.feature.geometry) !== JSON.stringify(a.feature.geometry) || JSON.stringify(b.feature.properties ?? {}) !== JSON.stringify(a.feature.properties ?? {})) {
5319
+ featureIds.add(id);
5320
+ }
5321
+ });
5322
+ const allLayerIds = /* @__PURE__ */ new Set();
5323
+ beforeLayers.forEach((_v, k) => allLayerIds.add(k));
5324
+ afterLayers.forEach((_v, k) => allLayerIds.add(k));
5325
+ const layerIds = /* @__PURE__ */ new Set();
5326
+ allLayerIds.forEach((id) => {
5327
+ const b = beforeLayers.get(id);
5328
+ const a = afterLayers.get(id);
5329
+ if (!b || !a || !historyLayersEqual(b, a)) layerIds.add(id);
5330
+ });
5331
+ return { featureIds, layerIds };
5332
+ }
5333
+ function isReadOnlyIndexCurrent(cached, store) {
5334
+ if (!cached || cached.sources.size !== store.size) return false;
5335
+ let stale = false;
5336
+ store.forEach((features, layerId) => {
5337
+ if (!stale && cached.sources.get(layerId) !== features) stale = true;
5338
+ });
5339
+ return !stale;
5340
+ }
5341
+ function buildReadOnlyFeatureIndex(store) {
5342
+ const byId = /* @__PURE__ */ new Map();
5343
+ store.forEach((features) => {
5344
+ for (const f of features) {
5345
+ if (f.id == null) continue;
5346
+ const fid = String(f.id);
5347
+ if (!byId.has(fid)) byId.set(fid, f);
5348
+ }
5349
+ });
5350
+ return { sources: new Map(store), byId };
5351
+ }
5352
+ function countFeaturesInBounds(featureGroups, bounds, options) {
5353
+ var _a;
5354
+ const { west, east, south, north } = bounds;
5355
+ const { threshold, visibleSet } = options;
5356
+ const fullWidth = east - west >= 360;
5357
+ const inView = (lng, lat) => {
5358
+ if (lat < south || lat > north) return false;
5359
+ if (fullWidth) return true;
5360
+ return lng >= west && lng <= east || lng + 360 >= west && lng + 360 <= east || lng - 360 >= west && lng - 360 <= east;
5361
+ };
5362
+ let count = 0;
5363
+ for (const features of featureGroups) {
5364
+ for (const f of features) {
5365
+ if (visibleSet && f.id != null && !visibleSet.has(String(f.id))) continue;
5366
+ if (((_a = f.geometry) == null ? void 0 : _a.type) === "Point") {
5367
+ const [lng, lat] = f.geometry.coordinates;
5368
+ if (!inView(lng, lat)) continue;
5369
+ }
5370
+ count += 1;
5371
+ if (count > threshold) return count;
5372
+ }
5373
+ }
5374
+ return count;
5375
+ }
5273
5376
  const OTHER_BUCKET_KEY = "__other__";
5274
5377
  const OTHER_BUCKET_LABEL = "Other";
5275
5378
  const OTHER_BUCKET_COLOR = "#9ca3af";
@@ -5987,6 +6090,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
5987
6090
  toastProvider,
5988
6091
  customGlobalMenuItems,
5989
6092
  extraLayerToolbarButtons,
6093
+ extraNewLayerButtons,
5990
6094
  layerBadgeProvider,
5991
6095
  featureCountProvider,
5992
6096
  fitBoundsProvider,
@@ -6058,6 +6162,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
6058
6162
  const filterPolygonRef = useRef(null);
6059
6163
  const pendingFeatureKindRef = useRef(null);
6060
6164
  const arrowFeatureIdsRef = useRef(/* @__PURE__ */ new Set());
6165
+ const hasArrowFeaturesRef = useRef(false);
6061
6166
  const [circleDrawCenter, setCircleDrawCenter] = useState(null);
6062
6167
  const [circleDrawPreview, setCircleDrawPreview] = useState(null);
6063
6168
  const isDrawingCircle = useRef(false);
@@ -6175,19 +6280,28 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
6175
6280
  return true;
6176
6281
  });
6177
6282
  }, [selectedFeatureIds]);
6178
- const selectedFeatures = getSelectedFeatures();
6283
+ const selectedFeatures = useMemo(
6284
+ () => getSelectedFeatures(),
6285
+ // eslint-disable-next-line react-hooks/exhaustive-deps -- featureUpdateCounter invalidates stale clones
6286
+ [getSelectedFeatures, featureUpdateCounter]
6287
+ );
6288
+ const readOnlyFeatureIndexRef = useRef(null);
6289
+ const getReadOnlyFeatureById = useCallback((id) => {
6290
+ const store = readOnlyFeatures.current;
6291
+ let cached = readOnlyFeatureIndexRef.current;
6292
+ if (!isReadOnlyIndexCurrent(cached, store)) {
6293
+ cached = buildReadOnlyFeatureIndex(store);
6294
+ readOnlyFeatureIndexRef.current = cached;
6295
+ }
6296
+ return cached.byId.get(id) ?? null;
6297
+ }, []);
6179
6298
  const getFeatureById = useCallback((id) => {
6180
6299
  if (draw.current) {
6181
6300
  const feature = draw.current.get(id);
6182
6301
  if (feature) return feature;
6183
6302
  }
6184
- const entries = Array.from(readOnlyFeatures.current.entries());
6185
- for (const [, features] of entries) {
6186
- const found = features.find((f) => String(f.id) === id);
6187
- if (found) return found;
6188
- }
6189
- return null;
6190
- }, []);
6303
+ return getReadOnlyFeatureById(id);
6304
+ }, [getReadOnlyFeatureById]);
6191
6305
  const canDeleteSelected = useMemo(() => {
6192
6306
  if (selectedFeatureIds.length === 0) return false;
6193
6307
  return selectedFeatureIds.some((id) => {
@@ -6213,7 +6327,9 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
6213
6327
  if (!isMapLoaded || !draw.current) {
6214
6328
  setSelectedFeatureIds(nextIds);
6215
6329
  if (options == null ? void 0 : options.focusProperties) setShowProperties(nextIds.length > 0);
6216
- onFeatureSelect == null ? void 0 : onFeatureSelect(nextIds.length > 0 ? nextIds.map((id) => getFeatureById(id)).filter(Boolean) : []);
6330
+ if (onFeatureSelect) {
6331
+ onFeatureSelect(nextIds.length > 0 ? nextIds.map((id) => getFeatureById(id)).filter(Boolean) : []);
6332
+ }
6217
6333
  return;
6218
6334
  }
6219
6335
  const editableIdSet = /* @__PURE__ */ new Set();
@@ -6240,8 +6356,9 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
6240
6356
  setSelectedFeatureIds(nextIds);
6241
6357
  selectedFeatureIdsRef.current = nextIds;
6242
6358
  if (options == null ? void 0 : options.focusProperties) setShowProperties(nextIds.length > 0);
6243
- const selectedFeaturesForCallback = nextIds.map((id) => getFeatureById(id)).filter(Boolean);
6244
- onFeatureSelect == null ? void 0 : onFeatureSelect(selectedFeaturesForCallback);
6359
+ if (onFeatureSelect) {
6360
+ onFeatureSelect(nextIds.map((id) => getFeatureById(id)).filter(Boolean));
6361
+ }
6245
6362
  syncRef.current();
6246
6363
  if (readOnlyIds.length > 0) {
6247
6364
  queueMicrotask(() => {
@@ -6265,6 +6382,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
6265
6382
  setFeatureCount(drawFeatureCount + hiddenCount + readOnlyCount);
6266
6383
  }, []);
6267
6384
  const timelineVisibleIdsRef = useRef(null);
6385
+ const timelineSyncRafRef = useRef(null);
6268
6386
  const syncRef = useRef(() => {
6269
6387
  });
6270
6388
  const hashStringToColor$1 = useCallback((str) => hashStringToColor(str), []);
@@ -6335,6 +6453,22 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
6335
6453
  });
6336
6454
  return colorMap;
6337
6455
  }, [selectedFeatureIds, layers, getAllFeatures, hashStringToColor$1]);
6456
+ const countVisibleFeatures = useCallback((threshold) => {
6457
+ const m = map.current;
6458
+ if (!m) return 0;
6459
+ const bounds = m.getBounds();
6460
+ const groups = [];
6461
+ if (draw.current) groups.push(draw.current.getAll().features);
6462
+ readOnlyFeatures.current.forEach((features, layerId) => {
6463
+ const layer = layersRef.current.find((l) => l.id === layerId);
6464
+ if (layer == null ? void 0 : layer.visible) groups.push(features);
6465
+ });
6466
+ return countFeaturesInBounds(
6467
+ groups,
6468
+ { west: bounds.getWest(), east: bounds.getEast(), south: bounds.getSouth(), north: bounds.getNorth() },
6469
+ { threshold, visibleSet: timelineVisibleIdsRef.current }
6470
+ );
6471
+ }, []);
6338
6472
  const isSyncingRef = useRef(false);
6339
6473
  const syncFeaturesToCustomLayers = useCallback(() => {
6340
6474
  if (!map.current) return;
@@ -6687,11 +6821,13 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
6687
6821
  if (arrowHeadSource && map.current) {
6688
6822
  const arrowHeadTriangles = [];
6689
6823
  const mapInstance = map.current;
6824
+ let sawArrowFeature = false;
6690
6825
  const headLength = 16;
6691
6826
  const headWidth = 10;
6692
6827
  sourceData.features.forEach((f) => {
6693
6828
  var _a;
6694
6829
  const isArrow = ((_a = f.properties) == null ? void 0 : _a.kind) === "arrow" || arrowFeatureIdsRef.current.has(String(f.id));
6830
+ if (isArrow) sawArrowFeature = true;
6695
6831
  if (f.geometry.type !== "LineString" || !isArrow) return;
6696
6832
  const coords = f.geometry.coordinates;
6697
6833
  if (coords.length < 2) return;
@@ -6737,6 +6873,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
6737
6873
  });
6738
6874
  });
6739
6875
  arrowHeadSource.setData({ type: "FeatureCollection", features: arrowHeadTriangles });
6876
+ hasArrowFeaturesRef.current = sawArrowFeature;
6740
6877
  }
6741
6878
  const arrowLabelSource = map.current.getSource("arrow-labels");
6742
6879
  if (arrowLabelSource) {
@@ -6782,37 +6919,15 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
6782
6919
  if (update3DFlightPathsRef == null ? void 0 : update3DFlightPathsRef.current) {
6783
6920
  update3DFlightPathsRef.current();
6784
6921
  }
6785
- const m = map.current;
6786
- if (m) {
6787
- m.once("idle", () => {
6788
- var _a;
6789
- const countLayers = ["custom-point", "custom-line", "custom-polygon-fill"];
6790
- const existing = countLayers.filter((id) => m.getLayer(id));
6791
- if (existing.length === 0) {
6792
- setVisibleFeatureCount(0);
6793
- setLabelsSuppressed(false);
6794
- return;
6795
- }
6796
- const threshold = autoLabelConfig.enabled ? autoLabelConfig.threshold : 220;
6797
- const rendered = m.queryRenderedFeatures(void 0, { layers: existing });
6798
- const uniqueIds = /* @__PURE__ */ new Set();
6799
- let count = 0;
6800
- for (const f of rendered) {
6801
- const fid = ((_a = f.properties) == null ? void 0 : _a.id) || f.id;
6802
- if (fid && !uniqueIds.has(String(fid))) {
6803
- uniqueIds.add(String(fid));
6804
- count++;
6805
- if (count > threshold) break;
6806
- }
6807
- }
6808
- setVisibleFeatureCount(count);
6809
- setLabelsSuppressed(false);
6810
- });
6922
+ {
6923
+ const threshold = autoLabelConfig.enabled ? autoLabelConfig.threshold : 220;
6924
+ setVisibleFeatureCount(countVisibleFeatures(threshold));
6925
+ setLabelsSuppressed(false);
6811
6926
  }
6812
6927
  } finally {
6813
6928
  isSyncingRef.current = false;
6814
6929
  }
6815
- }, [layers, hashStringToColor$1, autoLabelConfig]);
6930
+ }, [layers, hashStringToColor$1, autoLabelConfig, countVisibleFeatures]);
6816
6931
  const update3DFlightPaths = useCallback(() => {
6817
6932
  if (!map.current || !is3DTerrainEnabled) {
6818
6933
  if (map.current && flightPath3DLayerId.current) {
@@ -7133,6 +7248,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
7133
7248
  updateFeatureCount();
7134
7249
  scheduleTimelineUpdate();
7135
7250
  syncFeaturesToCustomLayers();
7251
+ setFeatureUpdateCounter((c) => c + 1);
7136
7252
  queueMicrotask(() => {
7137
7253
  isSelectingReadOnlyRef.current = false;
7138
7254
  });
@@ -7141,25 +7257,8 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
7141
7257
  );
7142
7258
  const buildDiffCommand = useCallback(
7143
7259
  (label, coalesceKey, before, after, beforeLayers, afterLayers, beforeSelectedIds, afterSelectedIds) => {
7144
- const featureIds = /* @__PURE__ */ new Set();
7145
- before.forEach((_v, k) => featureIds.add(k));
7146
- after.forEach((_v, k) => featureIds.add(k));
7147
- const layerIds = /* @__PURE__ */ new Set();
7148
- beforeLayers.forEach((_v, k) => layerIds.add(k));
7149
- afterLayers.forEach((_v, k) => layerIds.add(k));
7150
- const featuresChanged = Array.from(featureIds).some((id) => {
7151
- const b = before.get(id);
7152
- const a = after.get(id);
7153
- if (!b || !a || b.layerId !== a.layerId) return true;
7154
- if (JSON.stringify(b.feature.geometry) !== JSON.stringify(a.feature.geometry)) return true;
7155
- return JSON.stringify(b.feature.properties ?? {}) !== JSON.stringify(a.feature.properties ?? {});
7156
- });
7157
- const layersChanged = featuresChanged || Array.from(layerIds).some((id) => {
7158
- const b = beforeLayers.get(id);
7159
- const a = afterLayers.get(id);
7160
- return !b || !a || JSON.stringify(b) !== JSON.stringify(a);
7161
- });
7162
- if (!featuresChanged && !layersChanged) return null;
7260
+ const { featureIds, layerIds } = diffHistorySnapshots(before, after, beforeLayers, afterLayers);
7261
+ if (featureIds.size === 0 && layerIds.size === 0) return null;
7163
7262
  const pick = (src, keys) => {
7164
7263
  const out = /* @__PURE__ */ new Map();
7165
7264
  keys.forEach((k) => {
@@ -8351,12 +8450,14 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
8351
8450
  justCreatedRectangleRef.current = false;
8352
8451
  return;
8353
8452
  }
8354
- e.features.forEach((feature) => {
8355
- const fid = feature.id;
8356
- if (!originalGeometriesRef.current.has(fid)) {
8357
- originalGeometriesRef.current.set(fid, JSON.parse(JSON.stringify(feature.geometry)));
8358
- }
8359
- });
8453
+ if (isEditModeRef.current) {
8454
+ e.features.forEach((feature) => {
8455
+ const fid = feature.id;
8456
+ if (!originalGeometriesRef.current.has(fid)) {
8457
+ originalGeometriesRef.current.set(fid, JSON.parse(JSON.stringify(feature.geometry)));
8458
+ }
8459
+ });
8460
+ }
8360
8461
  const currentIds = new Set(ids);
8361
8462
  originalGeometriesRef.current.forEach((_, key) => {
8362
8463
  if (!currentIds.has(key)) {
@@ -9396,19 +9497,18 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
9396
9497
  const handleDeleteSelected = useCallback(() => {
9397
9498
  if (selectedFeatureIds.length === 0) return;
9398
9499
  const idSet = new Set(selectedFeatureIds);
9500
+ const readOnlyIdSet = /* @__PURE__ */ new Set();
9501
+ for (const layer of layersRef.current) {
9502
+ if (!layer.readOnly) continue;
9503
+ for (const fid of layer.featureIds) readOnlyIdSet.add(fid);
9504
+ }
9399
9505
  const editableIds = [];
9400
9506
  const readOnlyIds = [];
9401
- const currentLayers = layersRef.current;
9402
9507
  for (const id of selectedFeatureIds) {
9403
- const layer = currentLayers.find((l) => l.featureIds.includes(id));
9404
- if (layer == null ? void 0 : layer.readOnly) {
9405
- readOnlyIds.push(id);
9406
- } else {
9407
- editableIds.push(id);
9408
- }
9508
+ (readOnlyIdSet.has(id) ? readOnlyIds : editableIds).push(id);
9409
9509
  }
9510
+ saveStateForUndo("delete features");
9410
9511
  if (editableIds.length > 0 && draw.current) {
9411
- saveStateForUndo();
9412
9512
  editableIds.forEach((id) => {
9413
9513
  arrowFeatureIdsRef.current.delete(id);
9414
9514
  try {
@@ -9743,7 +9843,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
9743
9843
  const handleUpdateProperties = useCallback((featureId, properties, options) => {
9744
9844
  var _a, _b, _c;
9745
9845
  if (!map.current) return;
9746
- saveStateForUndo();
9846
+ if (!(options == null ? void 0 : options.fromRefresh)) saveStateForUndo();
9747
9847
  const { startDate, endDate } = normalizeTemporalProperties(properties);
9748
9848
  const normalizedProperties = {
9749
9849
  ...properties,
@@ -9770,12 +9870,13 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
9770
9870
  }
9771
9871
  syncFeaturesToCustomLayers();
9772
9872
  scheduleTimelineUpdate();
9873
+ setFeatureUpdateCounter((c) => c + 1);
9773
9874
  const updated = draw.current.get(featureId);
9774
9875
  if (updated) onFeatureUpdate == null ? void 0 : onFeatureUpdate(updated);
9775
9876
  } else {
9776
9877
  let updatedFeature;
9777
9878
  readOnlyFeatures.current.forEach((features, layerId) => {
9778
- var _a2, _b2;
9879
+ var _a2;
9779
9880
  const idx = features.findIndex((f) => String(f.id) === featureId);
9780
9881
  if (idx !== -1) {
9781
9882
  const f = features[idx];
@@ -9786,20 +9887,25 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
9786
9887
  if (JSON.stringify(oldVal) !== JSON.stringify(value)) hasRealChange = true;
9787
9888
  });
9788
9889
  const currentUnsaved = (_a2 = f.properties) == null ? void 0 : _a2._unsaved;
9789
- f.properties = { ...f.properties, ...normalizedProperties };
9890
+ const nextProperties = { ...f.properties, ...normalizedProperties };
9790
9891
  if (!externalPersistence && hasRealChange && currentUnsaved !== false && !(options == null ? void 0 : options.fromRefresh)) {
9791
- f.properties._unsaved = true;
9892
+ nextProperties._unsaved = true;
9792
9893
  }
9793
- if (properties.kind === "text" || ((_b2 = f.properties) == null ? void 0 : _b2.kind) === "text") {
9794
- delete f.properties.text;
9894
+ if (properties.kind === "text" || nextProperties.kind === "text") {
9895
+ delete nextProperties.text;
9795
9896
  }
9897
+ const replacement = { ...f, properties: nextProperties };
9898
+ const nextFeatures = features.slice();
9899
+ nextFeatures[idx] = replacement;
9900
+ readOnlyFeatures.current.set(layerId, nextFeatures);
9796
9901
  layerTemporalCacheRef.current.delete(layerId);
9797
- updatedFeature = f;
9902
+ updatedFeature = replacement;
9798
9903
  }
9799
9904
  });
9800
9905
  if (updatedFeature) {
9801
9906
  syncFeaturesToCustomLayers();
9802
9907
  scheduleTimelineUpdate();
9908
+ setFeatureUpdateCounter((c) => c + 1);
9803
9909
  onFeatureUpdate == null ? void 0 : onFeatureUpdate(updatedFeature);
9804
9910
  }
9805
9911
  }
@@ -9826,6 +9932,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
9826
9932
  }
9827
9933
  draw.current.changeMode("simple_select", { featureIds: [featureId] });
9828
9934
  syncFeaturesToCustomLayers();
9935
+ setFeatureUpdateCounter((c) => c + 1);
9829
9936
  const updated = draw.current.get(featureId);
9830
9937
  if (updated) {
9831
9938
  onFeatureUpdate == null ? void 0 : onFeatureUpdate(updated);
@@ -9993,16 +10100,8 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
9993
10100
  }, [saveStateForUndo]);
9994
10101
  const findFeatureById = useCallback((id) => {
9995
10102
  var _a;
9996
- let feature = (_a = draw.current) == null ? void 0 : _a.get(id);
9997
- if (feature) return feature;
9998
- readOnlyFeatures.current.forEach((features) => {
9999
- if (!feature) {
10000
- const found = features.find((f) => String(f.id) === id);
10001
- if (found) feature = found;
10002
- }
10003
- });
10004
- return feature;
10005
- }, []);
10103
+ return ((_a = draw.current) == null ? void 0 : _a.get(id)) ?? getReadOnlyFeatureById(id) ?? void 0;
10104
+ }, [getReadOnlyFeatureById]);
10006
10105
  const handleMoveFeaturesToLayer = useCallback((featureIds, targetLayerId) => {
10007
10106
  if (!draw.current) return;
10008
10107
  saveStateForUndo();
@@ -10362,22 +10461,10 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
10362
10461
  setAutoLabelConfig(config);
10363
10462
  }, []);
10364
10463
  const countVisibleFeaturesInViewport = useCallback(() => {
10365
- var _a;
10366
10464
  if (!map.current || !isMapLoaded) return;
10367
- const customLayers = ["custom-point", "custom-line", "custom-polygon-fill"];
10368
- const existingLayers = customLayers.filter((id) => map.current.getLayer(id));
10369
- if (existingLayers.length === 0) {
10370
- setVisibleFeatureCount(0);
10371
- return;
10372
- }
10373
- const rendered = map.current.queryRenderedFeatures(void 0, { layers: existingLayers });
10374
- const uniqueIds = /* @__PURE__ */ new Set();
10375
- for (const f of rendered) {
10376
- const fid = ((_a = f.properties) == null ? void 0 : _a.id) || f.id;
10377
- if (fid) uniqueIds.add(String(fid));
10378
- }
10379
- setVisibleFeatureCount(uniqueIds.size);
10380
- }, [isMapLoaded]);
10465
+ const threshold = autoLabelConfig.enabled ? autoLabelConfig.threshold : 220;
10466
+ setVisibleFeatureCount(countVisibleFeatures(threshold));
10467
+ }, [isMapLoaded, countVisibleFeatures, autoLabelConfig.enabled, autoLabelConfig.threshold]);
10381
10468
  useEffect(() => {
10382
10469
  if (!map.current || !isMapLoaded) return;
10383
10470
  const mapInstance = map.current;
@@ -10407,6 +10494,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
10407
10494
  if (!map.current || !isMapLoaded) return;
10408
10495
  const mapInstance = map.current;
10409
10496
  const handleMove = () => {
10497
+ if (!hasArrowFeaturesRef.current) return;
10410
10498
  if (syncRef.current) {
10411
10499
  syncRef.current();
10412
10500
  }
@@ -10463,31 +10551,8 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
10463
10551
  let lastCenter = mapInstance.getCenter();
10464
10552
  let lastZoom = mapInstance.getZoom();
10465
10553
  const updateViewportCount = () => {
10466
- var _a;
10467
- const layers2 = ["custom-point", "custom-line", "custom-polygon-fill"];
10468
- const existing = layers2.filter((id) => mapInstance.getLayer(id));
10469
- if (existing.length === 0) {
10470
- setVisibleFeatureCount(0);
10471
- setLabelsSuppressed(false);
10472
- return;
10473
- }
10474
10554
  const threshold = autoLabelConfig.enabled ? autoLabelConfig.threshold : 220;
10475
- const rendered = mapInstance.queryRenderedFeatures(void 0, { layers: existing });
10476
- const uniqueIds = /* @__PURE__ */ new Set();
10477
- let count = 0;
10478
- for (const f of rendered) {
10479
- const fid = ((_a = f.properties) == null ? void 0 : _a.id) || f.id;
10480
- if (fid && !uniqueIds.has(String(fid))) {
10481
- uniqueIds.add(String(fid));
10482
- count++;
10483
- if (count > threshold) {
10484
- setVisibleFeatureCount(count);
10485
- setLabelsSuppressed(false);
10486
- return;
10487
- }
10488
- }
10489
- }
10490
- setVisibleFeatureCount(count);
10555
+ setVisibleFeatureCount(countVisibleFeatures(threshold));
10491
10556
  setLabelsSuppressed(false);
10492
10557
  };
10493
10558
  const onMapMovement = () => {
@@ -10513,7 +10578,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
10513
10578
  } catch {
10514
10579
  }
10515
10580
  };
10516
- }, [isMapLoaded, autoLabelConfig.threshold, autoLabelConfig.enabled]);
10581
+ }, [isMapLoaded, autoLabelConfig.threshold, autoLabelConfig.enabled, countVisibleFeatures]);
10517
10582
  const DEFAULT_LABEL_THRESHOLD = 220;
10518
10583
  useEffect(() => {
10519
10584
  if (!map.current || !isMapLoaded) return;
@@ -12218,7 +12283,12 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
12218
12283
  const handleTimelineFilterChange = useCallback((visibleIds, hiddenIds, untimedIds) => {
12219
12284
  if (!draw.current || !map.current) return;
12220
12285
  timelineVisibleIdsRef.current = /* @__PURE__ */ new Set([...visibleIds, ...untimedIds]);
12221
- syncFeaturesToCustomLayers();
12286
+ if (timelineSyncRafRef.current == null) {
12287
+ timelineSyncRafRef.current = requestAnimationFrame(() => {
12288
+ timelineSyncRafRef.current = null;
12289
+ syncFeaturesToCustomLayers();
12290
+ });
12291
+ }
12222
12292
  }, [syncFeaturesToCustomLayers]);
12223
12293
  const prevTimelineEnabledRef = useRef(timelineStore.isEnabled);
12224
12294
  useEffect(() => {
@@ -12990,6 +13060,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
12990
13060
  externalPersistence,
12991
13061
  customGlobalMenuItems,
12992
13062
  extraLayerToolbarButtons,
13063
+ extraNewLayerButtons,
12993
13064
  layerBadgeProvider,
12994
13065
  featureCountProvider
12995
13066
  }