@octostar/map-component 0.2.4 → 0.2.6

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
@@ -2784,6 +2784,32 @@ function formatDateForState(value) {
2784
2784
  }
2785
2785
  return "";
2786
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
+ }
2787
2813
  function getFeatureTypeIcon(geometryType, kind, size = "sm") {
2788
2814
  const cls = size === "lg" ? "w-5 h-5" : "w-4 h-4";
2789
2815
  if (kind === "text") {
@@ -3385,16 +3411,7 @@ function PropertiesPanel({ selectedFeatures, onUpdateProperties, onUpdateGeometr
3385
3411
  const recordProperties = feature ? Object.entries(feature.properties).filter(
3386
3412
  ([key, value]) => !isExcludedRecordKey(key) && value !== void 0 && value !== null && !key.startsWith("_") && !key.startsWith("os_") && !key.startsWith("isHidden")
3387
3413
  ).map(([key, value]) => ({ key, value: formatFieldValue(String(value)) })) : [];
3388
- const entityCardsContent = /* @__PURE__ */ jsx("div", { className: "p-2 space-y-2", children: entityCardProvider ? selectedFeatures.map((f) => {
3389
- const geoFeature = {
3390
- type: "Feature",
3391
- id: f.id,
3392
- geometry: f.geometry,
3393
- properties: f.properties
3394
- };
3395
- const card = entityCardProvider(geoFeature);
3396
- return card ? /* @__PURE__ */ jsx("div", { className: "border border-border rounded-md p-2 bg-card", children: card }, f.id) : null;
3397
- }) : /* @__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" }) });
3398
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" }) });
3399
3416
  if (hasMultipleSelection && !entityCardProvider) {
3400
3417
  return /* @__PURE__ */ jsxs(
@@ -3457,7 +3474,7 @@ function PropertiesPanel({ selectedFeatures, onUpdateProperties, onUpdateGeometr
3457
3474
  /* @__PURE__ */ jsx(Divider, { className: "!my-1.5" }),
3458
3475
  /* @__PURE__ */ jsxs("div", { className: "space-y-0.5", children: [
3459
3476
  /* @__PURE__ */ jsx("label", { htmlFor: "feature-name", className: "text-xs text-muted-foreground", children: feature.properties.kind === "text" ? "Label" : "Name" }),
3460
- /* @__PURE__ */ jsx(
3477
+ isEditMode ? /* @__PURE__ */ jsx(
3461
3478
  Input,
3462
3479
  {
3463
3480
  ref: nameInputRef,
@@ -3470,11 +3487,14 @@ function PropertiesPanel({ selectedFeatures, onUpdateProperties, onUpdateGeometr
3470
3487
  }
3471
3488
  },
3472
3489
  onBlur: () => handleSave(),
3473
- placeholder: isEditMode ? feature.properties.kind === "text" ? "Enter label..." : "Feature name" : "No name",
3474
- readOnly: !isEditMode,
3490
+ placeholder: feature.properties.kind === "text" ? "Enter label..." : "Feature name",
3475
3491
  className: "!h-6 text-[13px]",
3476
3492
  "data-testid": "input-feature-name"
3477
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" }) })
3478
3498
  )
3479
3499
  ] }),
3480
3500
  (typePickerProvider || feature.geometry.type === "Point" && feature.properties.kind !== "text" && pointIcon) && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
@@ -3945,7 +3965,7 @@ function PropertiesPanel({ selectedFeatures, onUpdateProperties, onUpdateGeometr
3945
3965
  /* @__PURE__ */ jsxs("div", { className: "space-y-1", children: [
3946
3966
  /* @__PURE__ */ jsxs("div", { className: "flex items-start gap-1", children: [
3947
3967
  /* @__PURE__ */ jsx("div", { className: "text-[13px] font-mono text-muted-foreground shrink-0 w-24 px-1 leading-6 select-none", children: "description" }),
3948
- /* @__PURE__ */ jsx(
3968
+ isEditMode ? /* @__PURE__ */ jsx(
3949
3969
  TextArea,
3950
3970
  {
3951
3971
  id: "feature-description",
@@ -3953,14 +3973,13 @@ function PropertiesPanel({ selectedFeatures, onUpdateProperties, onUpdateGeometr
3953
3973
  onChange: (e) => setDescription(e.target.value),
3954
3974
  onBlur: () => handleSave(),
3955
3975
  autoSize: { minRows: 1, maxRows: 5 },
3956
- placeholder: isEditMode ? "—" : "",
3957
- readOnly: !isEditMode,
3976
+ placeholder: "—",
3958
3977
  className: "flex-1 !text-[13px] !px-1.5 !py-0.5 resize-none",
3959
3978
  "data-testid": "input-feature-description"
3960
3979
  }
3961
- )
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: "—" }) })
3962
3981
  ] }),
3963
- 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: [
3964
3983
  /* @__PURE__ */ jsx(
3965
3984
  Input,
3966
3985
  {
@@ -3968,8 +3987,8 @@ function PropertiesPanel({ selectedFeatures, onUpdateProperties, onUpdateGeometr
3968
3987
  onChange: (e) => handlePropertyKeyChange(index, e.target.value),
3969
3988
  onBlur: () => handleSave(),
3970
3989
  placeholder: "Key",
3990
+ style: { width: "6rem", flex: "0 0 6rem" },
3971
3991
  className: "shrink-0 w-24 text-[13px] font-mono !h-6 !px-1",
3972
- readOnly: !isEditMode,
3973
3992
  "data-testid": `input-property-key-${index}`
3974
3993
  }
3975
3994
  ),
@@ -3981,11 +4000,10 @@ function PropertiesPanel({ selectedFeatures, onUpdateProperties, onUpdateGeometr
3981
4000
  onBlur: () => handleSave(),
3982
4001
  placeholder: "Value",
3983
4002
  className: "flex-1 text-[13px] !h-6 !px-1.5",
3984
- readOnly: !isEditMode,
3985
4003
  "data-testid": `input-property-value-${index}`
3986
4004
  }
3987
4005
  ),
3988
- isEditMode && /* @__PURE__ */ jsx(
4006
+ /* @__PURE__ */ jsx(
3989
4007
  "button",
3990
4008
  {
3991
4009
  type: "button",
@@ -3998,7 +4016,10 @@ function PropertiesPanel({ selectedFeatures, onUpdateProperties, onUpdateGeometr
3998
4016
  children: /* @__PURE__ */ jsx(Trash2, { className: "w-3 h-3" })
3999
4017
  }
4000
4018
  )
4001
- ] }, 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))
4002
4023
  ] }),
4003
4024
  isEditMode && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1 pt-0.5", children: [
4004
4025
  /* @__PURE__ */ jsx(
@@ -5272,6 +5293,86 @@ function useMapHistory(options) {
5272
5293
  }, [history, rerender]);
5273
5294
  return { push, undo, redo, clear, canUndo: history.canUndo, canRedo: history.canRedo };
5274
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
+ }
5275
5376
  const OTHER_BUCKET_KEY = "__other__";
5276
5377
  const OTHER_BUCKET_LABEL = "Other";
5277
5378
  const OTHER_BUCKET_COLOR = "#9ca3af";
@@ -6061,6 +6162,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
6061
6162
  const filterPolygonRef = useRef(null);
6062
6163
  const pendingFeatureKindRef = useRef(null);
6063
6164
  const arrowFeatureIdsRef = useRef(/* @__PURE__ */ new Set());
6165
+ const hasArrowFeaturesRef = useRef(false);
6064
6166
  const [circleDrawCenter, setCircleDrawCenter] = useState(null);
6065
6167
  const [circleDrawPreview, setCircleDrawPreview] = useState(null);
6066
6168
  const isDrawingCircle = useRef(false);
@@ -6178,19 +6280,28 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
6178
6280
  return true;
6179
6281
  });
6180
6282
  }, [selectedFeatureIds]);
6181
- 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
+ }, []);
6182
6298
  const getFeatureById = useCallback((id) => {
6183
6299
  if (draw.current) {
6184
6300
  const feature = draw.current.get(id);
6185
6301
  if (feature) return feature;
6186
6302
  }
6187
- const entries = Array.from(readOnlyFeatures.current.entries());
6188
- for (const [, features] of entries) {
6189
- const found = features.find((f) => String(f.id) === id);
6190
- if (found) return found;
6191
- }
6192
- return null;
6193
- }, []);
6303
+ return getReadOnlyFeatureById(id);
6304
+ }, [getReadOnlyFeatureById]);
6194
6305
  const canDeleteSelected = useMemo(() => {
6195
6306
  if (selectedFeatureIds.length === 0) return false;
6196
6307
  return selectedFeatureIds.some((id) => {
@@ -6216,7 +6327,9 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
6216
6327
  if (!isMapLoaded || !draw.current) {
6217
6328
  setSelectedFeatureIds(nextIds);
6218
6329
  if (options == null ? void 0 : options.focusProperties) setShowProperties(nextIds.length > 0);
6219
- 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
+ }
6220
6333
  return;
6221
6334
  }
6222
6335
  const editableIdSet = /* @__PURE__ */ new Set();
@@ -6243,8 +6356,9 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
6243
6356
  setSelectedFeatureIds(nextIds);
6244
6357
  selectedFeatureIdsRef.current = nextIds;
6245
6358
  if (options == null ? void 0 : options.focusProperties) setShowProperties(nextIds.length > 0);
6246
- const selectedFeaturesForCallback = nextIds.map((id) => getFeatureById(id)).filter(Boolean);
6247
- onFeatureSelect == null ? void 0 : onFeatureSelect(selectedFeaturesForCallback);
6359
+ if (onFeatureSelect) {
6360
+ onFeatureSelect(nextIds.map((id) => getFeatureById(id)).filter(Boolean));
6361
+ }
6248
6362
  syncRef.current();
6249
6363
  if (readOnlyIds.length > 0) {
6250
6364
  queueMicrotask(() => {
@@ -6268,6 +6382,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
6268
6382
  setFeatureCount(drawFeatureCount + hiddenCount + readOnlyCount);
6269
6383
  }, []);
6270
6384
  const timelineVisibleIdsRef = useRef(null);
6385
+ const timelineSyncRafRef = useRef(null);
6271
6386
  const syncRef = useRef(() => {
6272
6387
  });
6273
6388
  const hashStringToColor$1 = useCallback((str) => hashStringToColor(str), []);
@@ -6338,6 +6453,22 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
6338
6453
  });
6339
6454
  return colorMap;
6340
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
+ }, []);
6341
6472
  const isSyncingRef = useRef(false);
6342
6473
  const syncFeaturesToCustomLayers = useCallback(() => {
6343
6474
  if (!map.current) return;
@@ -6690,11 +6821,13 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
6690
6821
  if (arrowHeadSource && map.current) {
6691
6822
  const arrowHeadTriangles = [];
6692
6823
  const mapInstance = map.current;
6824
+ let sawArrowFeature = false;
6693
6825
  const headLength = 16;
6694
6826
  const headWidth = 10;
6695
6827
  sourceData.features.forEach((f) => {
6696
6828
  var _a;
6697
6829
  const isArrow = ((_a = f.properties) == null ? void 0 : _a.kind) === "arrow" || arrowFeatureIdsRef.current.has(String(f.id));
6830
+ if (isArrow) sawArrowFeature = true;
6698
6831
  if (f.geometry.type !== "LineString" || !isArrow) return;
6699
6832
  const coords = f.geometry.coordinates;
6700
6833
  if (coords.length < 2) return;
@@ -6740,6 +6873,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
6740
6873
  });
6741
6874
  });
6742
6875
  arrowHeadSource.setData({ type: "FeatureCollection", features: arrowHeadTriangles });
6876
+ hasArrowFeaturesRef.current = sawArrowFeature;
6743
6877
  }
6744
6878
  const arrowLabelSource = map.current.getSource("arrow-labels");
6745
6879
  if (arrowLabelSource) {
@@ -6785,37 +6919,15 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
6785
6919
  if (update3DFlightPathsRef == null ? void 0 : update3DFlightPathsRef.current) {
6786
6920
  update3DFlightPathsRef.current();
6787
6921
  }
6788
- const m = map.current;
6789
- if (m) {
6790
- m.once("idle", () => {
6791
- var _a;
6792
- const countLayers = ["custom-point", "custom-line", "custom-polygon-fill"];
6793
- const existing = countLayers.filter((id) => m.getLayer(id));
6794
- if (existing.length === 0) {
6795
- setVisibleFeatureCount(0);
6796
- setLabelsSuppressed(false);
6797
- return;
6798
- }
6799
- const threshold = autoLabelConfig.enabled ? autoLabelConfig.threshold : 220;
6800
- const rendered = m.queryRenderedFeatures(void 0, { layers: existing });
6801
- const uniqueIds = /* @__PURE__ */ new Set();
6802
- let count = 0;
6803
- for (const f of rendered) {
6804
- const fid = ((_a = f.properties) == null ? void 0 : _a.id) || f.id;
6805
- if (fid && !uniqueIds.has(String(fid))) {
6806
- uniqueIds.add(String(fid));
6807
- count++;
6808
- if (count > threshold) break;
6809
- }
6810
- }
6811
- setVisibleFeatureCount(count);
6812
- setLabelsSuppressed(false);
6813
- });
6922
+ {
6923
+ const threshold = autoLabelConfig.enabled ? autoLabelConfig.threshold : 220;
6924
+ setVisibleFeatureCount(countVisibleFeatures(threshold));
6925
+ setLabelsSuppressed(false);
6814
6926
  }
6815
6927
  } finally {
6816
6928
  isSyncingRef.current = false;
6817
6929
  }
6818
- }, [layers, hashStringToColor$1, autoLabelConfig]);
6930
+ }, [layers, hashStringToColor$1, autoLabelConfig, countVisibleFeatures]);
6819
6931
  const update3DFlightPaths = useCallback(() => {
6820
6932
  if (!map.current || !is3DTerrainEnabled) {
6821
6933
  if (map.current && flightPath3DLayerId.current) {
@@ -7136,6 +7248,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
7136
7248
  updateFeatureCount();
7137
7249
  scheduleTimelineUpdate();
7138
7250
  syncFeaturesToCustomLayers();
7251
+ setFeatureUpdateCounter((c) => c + 1);
7139
7252
  queueMicrotask(() => {
7140
7253
  isSelectingReadOnlyRef.current = false;
7141
7254
  });
@@ -7144,25 +7257,8 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
7144
7257
  );
7145
7258
  const buildDiffCommand = useCallback(
7146
7259
  (label, coalesceKey, before, after, beforeLayers, afterLayers, beforeSelectedIds, afterSelectedIds) => {
7147
- const featureIds = /* @__PURE__ */ new Set();
7148
- before.forEach((_v, k) => featureIds.add(k));
7149
- after.forEach((_v, k) => featureIds.add(k));
7150
- const layerIds = /* @__PURE__ */ new Set();
7151
- beforeLayers.forEach((_v, k) => layerIds.add(k));
7152
- afterLayers.forEach((_v, k) => layerIds.add(k));
7153
- const featuresChanged = Array.from(featureIds).some((id) => {
7154
- const b = before.get(id);
7155
- const a = after.get(id);
7156
- if (!b || !a || b.layerId !== a.layerId) return true;
7157
- if (JSON.stringify(b.feature.geometry) !== JSON.stringify(a.feature.geometry)) return true;
7158
- return JSON.stringify(b.feature.properties ?? {}) !== JSON.stringify(a.feature.properties ?? {});
7159
- });
7160
- const layersChanged = featuresChanged || Array.from(layerIds).some((id) => {
7161
- const b = beforeLayers.get(id);
7162
- const a = afterLayers.get(id);
7163
- return !b || !a || JSON.stringify(b) !== JSON.stringify(a);
7164
- });
7165
- if (!featuresChanged && !layersChanged) return null;
7260
+ const { featureIds, layerIds } = diffHistorySnapshots(before, after, beforeLayers, afterLayers);
7261
+ if (featureIds.size === 0 && layerIds.size === 0) return null;
7166
7262
  const pick = (src, keys) => {
7167
7263
  const out = /* @__PURE__ */ new Map();
7168
7264
  keys.forEach((k) => {
@@ -8354,12 +8450,14 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
8354
8450
  justCreatedRectangleRef.current = false;
8355
8451
  return;
8356
8452
  }
8357
- e.features.forEach((feature) => {
8358
- const fid = feature.id;
8359
- if (!originalGeometriesRef.current.has(fid)) {
8360
- originalGeometriesRef.current.set(fid, JSON.parse(JSON.stringify(feature.geometry)));
8361
- }
8362
- });
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
+ }
8363
8461
  const currentIds = new Set(ids);
8364
8462
  originalGeometriesRef.current.forEach((_, key) => {
8365
8463
  if (!currentIds.has(key)) {
@@ -9399,19 +9497,18 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
9399
9497
  const handleDeleteSelected = useCallback(() => {
9400
9498
  if (selectedFeatureIds.length === 0) return;
9401
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
+ }
9402
9505
  const editableIds = [];
9403
9506
  const readOnlyIds = [];
9404
- const currentLayers = layersRef.current;
9405
9507
  for (const id of selectedFeatureIds) {
9406
- const layer = currentLayers.find((l) => l.featureIds.includes(id));
9407
- if (layer == null ? void 0 : layer.readOnly) {
9408
- readOnlyIds.push(id);
9409
- } else {
9410
- editableIds.push(id);
9411
- }
9508
+ (readOnlyIdSet.has(id) ? readOnlyIds : editableIds).push(id);
9412
9509
  }
9510
+ saveStateForUndo("delete features");
9413
9511
  if (editableIds.length > 0 && draw.current) {
9414
- saveStateForUndo();
9415
9512
  editableIds.forEach((id) => {
9416
9513
  arrowFeatureIdsRef.current.delete(id);
9417
9514
  try {
@@ -9746,7 +9843,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
9746
9843
  const handleUpdateProperties = useCallback((featureId, properties, options) => {
9747
9844
  var _a, _b, _c;
9748
9845
  if (!map.current) return;
9749
- saveStateForUndo();
9846
+ if (!(options == null ? void 0 : options.fromRefresh)) saveStateForUndo();
9750
9847
  const { startDate, endDate } = normalizeTemporalProperties(properties);
9751
9848
  const normalizedProperties = {
9752
9849
  ...properties,
@@ -9773,12 +9870,13 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
9773
9870
  }
9774
9871
  syncFeaturesToCustomLayers();
9775
9872
  scheduleTimelineUpdate();
9873
+ setFeatureUpdateCounter((c) => c + 1);
9776
9874
  const updated = draw.current.get(featureId);
9777
9875
  if (updated) onFeatureUpdate == null ? void 0 : onFeatureUpdate(updated);
9778
9876
  } else {
9779
9877
  let updatedFeature;
9780
9878
  readOnlyFeatures.current.forEach((features, layerId) => {
9781
- var _a2, _b2;
9879
+ var _a2;
9782
9880
  const idx = features.findIndex((f) => String(f.id) === featureId);
9783
9881
  if (idx !== -1) {
9784
9882
  const f = features[idx];
@@ -9789,20 +9887,25 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
9789
9887
  if (JSON.stringify(oldVal) !== JSON.stringify(value)) hasRealChange = true;
9790
9888
  });
9791
9889
  const currentUnsaved = (_a2 = f.properties) == null ? void 0 : _a2._unsaved;
9792
- f.properties = { ...f.properties, ...normalizedProperties };
9890
+ const nextProperties = { ...f.properties, ...normalizedProperties };
9793
9891
  if (!externalPersistence && hasRealChange && currentUnsaved !== false && !(options == null ? void 0 : options.fromRefresh)) {
9794
- f.properties._unsaved = true;
9892
+ nextProperties._unsaved = true;
9795
9893
  }
9796
- if (properties.kind === "text" || ((_b2 = f.properties) == null ? void 0 : _b2.kind) === "text") {
9797
- delete f.properties.text;
9894
+ if (properties.kind === "text" || nextProperties.kind === "text") {
9895
+ delete nextProperties.text;
9798
9896
  }
9897
+ const replacement = { ...f, properties: nextProperties };
9898
+ const nextFeatures = features.slice();
9899
+ nextFeatures[idx] = replacement;
9900
+ readOnlyFeatures.current.set(layerId, nextFeatures);
9799
9901
  layerTemporalCacheRef.current.delete(layerId);
9800
- updatedFeature = f;
9902
+ updatedFeature = replacement;
9801
9903
  }
9802
9904
  });
9803
9905
  if (updatedFeature) {
9804
9906
  syncFeaturesToCustomLayers();
9805
9907
  scheduleTimelineUpdate();
9908
+ setFeatureUpdateCounter((c) => c + 1);
9806
9909
  onFeatureUpdate == null ? void 0 : onFeatureUpdate(updatedFeature);
9807
9910
  }
9808
9911
  }
@@ -9829,6 +9932,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
9829
9932
  }
9830
9933
  draw.current.changeMode("simple_select", { featureIds: [featureId] });
9831
9934
  syncFeaturesToCustomLayers();
9935
+ setFeatureUpdateCounter((c) => c + 1);
9832
9936
  const updated = draw.current.get(featureId);
9833
9937
  if (updated) {
9834
9938
  onFeatureUpdate == null ? void 0 : onFeatureUpdate(updated);
@@ -9996,16 +10100,8 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
9996
10100
  }, [saveStateForUndo]);
9997
10101
  const findFeatureById = useCallback((id) => {
9998
10102
  var _a;
9999
- let feature = (_a = draw.current) == null ? void 0 : _a.get(id);
10000
- if (feature) return feature;
10001
- readOnlyFeatures.current.forEach((features) => {
10002
- if (!feature) {
10003
- const found = features.find((f) => String(f.id) === id);
10004
- if (found) feature = found;
10005
- }
10006
- });
10007
- return feature;
10008
- }, []);
10103
+ return ((_a = draw.current) == null ? void 0 : _a.get(id)) ?? getReadOnlyFeatureById(id) ?? void 0;
10104
+ }, [getReadOnlyFeatureById]);
10009
10105
  const handleMoveFeaturesToLayer = useCallback((featureIds, targetLayerId) => {
10010
10106
  if (!draw.current) return;
10011
10107
  saveStateForUndo();
@@ -10365,22 +10461,10 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
10365
10461
  setAutoLabelConfig(config);
10366
10462
  }, []);
10367
10463
  const countVisibleFeaturesInViewport = useCallback(() => {
10368
- var _a;
10369
10464
  if (!map.current || !isMapLoaded) return;
10370
- const customLayers = ["custom-point", "custom-line", "custom-polygon-fill"];
10371
- const existingLayers = customLayers.filter((id) => map.current.getLayer(id));
10372
- if (existingLayers.length === 0) {
10373
- setVisibleFeatureCount(0);
10374
- return;
10375
- }
10376
- const rendered = map.current.queryRenderedFeatures(void 0, { layers: existingLayers });
10377
- const uniqueIds = /* @__PURE__ */ new Set();
10378
- for (const f of rendered) {
10379
- const fid = ((_a = f.properties) == null ? void 0 : _a.id) || f.id;
10380
- if (fid) uniqueIds.add(String(fid));
10381
- }
10382
- setVisibleFeatureCount(uniqueIds.size);
10383
- }, [isMapLoaded]);
10465
+ const threshold = autoLabelConfig.enabled ? autoLabelConfig.threshold : 220;
10466
+ setVisibleFeatureCount(countVisibleFeatures(threshold));
10467
+ }, [isMapLoaded, countVisibleFeatures, autoLabelConfig.enabled, autoLabelConfig.threshold]);
10384
10468
  useEffect(() => {
10385
10469
  if (!map.current || !isMapLoaded) return;
10386
10470
  const mapInstance = map.current;
@@ -10410,6 +10494,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
10410
10494
  if (!map.current || !isMapLoaded) return;
10411
10495
  const mapInstance = map.current;
10412
10496
  const handleMove = () => {
10497
+ if (!hasArrowFeaturesRef.current) return;
10413
10498
  if (syncRef.current) {
10414
10499
  syncRef.current();
10415
10500
  }
@@ -10466,31 +10551,8 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
10466
10551
  let lastCenter = mapInstance.getCenter();
10467
10552
  let lastZoom = mapInstance.getZoom();
10468
10553
  const updateViewportCount = () => {
10469
- var _a;
10470
- const layers2 = ["custom-point", "custom-line", "custom-polygon-fill"];
10471
- const existing = layers2.filter((id) => mapInstance.getLayer(id));
10472
- if (existing.length === 0) {
10473
- setVisibleFeatureCount(0);
10474
- setLabelsSuppressed(false);
10475
- return;
10476
- }
10477
10554
  const threshold = autoLabelConfig.enabled ? autoLabelConfig.threshold : 220;
10478
- const rendered = mapInstance.queryRenderedFeatures(void 0, { layers: existing });
10479
- const uniqueIds = /* @__PURE__ */ new Set();
10480
- let count = 0;
10481
- for (const f of rendered) {
10482
- const fid = ((_a = f.properties) == null ? void 0 : _a.id) || f.id;
10483
- if (fid && !uniqueIds.has(String(fid))) {
10484
- uniqueIds.add(String(fid));
10485
- count++;
10486
- if (count > threshold) {
10487
- setVisibleFeatureCount(count);
10488
- setLabelsSuppressed(false);
10489
- return;
10490
- }
10491
- }
10492
- }
10493
- setVisibleFeatureCount(count);
10555
+ setVisibleFeatureCount(countVisibleFeatures(threshold));
10494
10556
  setLabelsSuppressed(false);
10495
10557
  };
10496
10558
  const onMapMovement = () => {
@@ -10516,7 +10578,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
10516
10578
  } catch {
10517
10579
  }
10518
10580
  };
10519
- }, [isMapLoaded, autoLabelConfig.threshold, autoLabelConfig.enabled]);
10581
+ }, [isMapLoaded, autoLabelConfig.threshold, autoLabelConfig.enabled, countVisibleFeatures]);
10520
10582
  const DEFAULT_LABEL_THRESHOLD = 220;
10521
10583
  useEffect(() => {
10522
10584
  if (!map.current || !isMapLoaded) return;
@@ -12221,7 +12283,12 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
12221
12283
  const handleTimelineFilterChange = useCallback((visibleIds, hiddenIds, untimedIds) => {
12222
12284
  if (!draw.current || !map.current) return;
12223
12285
  timelineVisibleIdsRef.current = /* @__PURE__ */ new Set([...visibleIds, ...untimedIds]);
12224
- syncFeaturesToCustomLayers();
12286
+ if (timelineSyncRafRef.current == null) {
12287
+ timelineSyncRafRef.current = requestAnimationFrame(() => {
12288
+ timelineSyncRafRef.current = null;
12289
+ syncFeaturesToCustomLayers();
12290
+ });
12291
+ }
12225
12292
  }, [syncFeaturesToCustomLayers]);
12226
12293
  const prevTimelineEnabledRef = useRef(timelineStore.isEnabled);
12227
12294
  useEffect(() => {