@octostar/map-component 0.1.34 → 0.1.36

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.cjs CHANGED
@@ -1153,7 +1153,20 @@ function DrawingToolbar({
1153
1153
  showShortcutHint: showShortcutHints
1154
1154
  }
1155
1155
  ),
1156
- !hiddenDrawingTools.includes("polygon") && /* @__PURE__ */ jsxRuntime.jsx(
1156
+ !hiddenDrawingTools.includes("polygon") && hiddenDrawingTools.includes("rectangle") && /* @__PURE__ */ jsxRuntime.jsx(
1157
+ ToolButton,
1158
+ {
1159
+ mode: "draw_polygon",
1160
+ activeMode,
1161
+ onModeChange,
1162
+ icon: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Pentagon, { className: "w-5 h-5" }),
1163
+ label: "Draw Polygon",
1164
+ shortcut: "G",
1165
+ disabled: drawingDisabled,
1166
+ showShortcutHint: showShortcutHints
1167
+ }
1168
+ ),
1169
+ !hiddenDrawingTools.includes("polygon") && !hiddenDrawingTools.includes("rectangle") && /* @__PURE__ */ jsxRuntime.jsx(
1157
1170
  antd.Dropdown,
1158
1171
  {
1159
1172
  menu: {
@@ -2883,6 +2896,37 @@ function formatEntityTypeName(type) {
2883
2896
  function formatPropertyKey(key) {
2884
2897
  return key.replace(/_/g, " ").replace(/\b\w/g, (c) => c.toUpperCase());
2885
2898
  }
2899
+ const ISO_DATE_RE = /^\d{4}-\d{2}-\d{2}$/;
2900
+ const ISO_DATETIME_ZONED_RE = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(:\d{2})?(\.\d+)?(Z|[+-]\d{2}:?\d{2})$/;
2901
+ const ISO_DATETIME_NAIVE_RE = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(:\d{2})?(\.\d+)?$/;
2902
+ function formatFieldValue(value) {
2903
+ if (ISO_DATE_RE.test(value)) {
2904
+ const d = /* @__PURE__ */ new Date(`${value}T00:00:00Z`);
2905
+ if (Number.isNaN(d.getTime())) return value;
2906
+ return new Intl.DateTimeFormat(void 0, {
2907
+ year: "numeric",
2908
+ month: "short",
2909
+ day: "numeric",
2910
+ timeZone: "UTC"
2911
+ }).format(d);
2912
+ }
2913
+ const zoned = ISO_DATETIME_ZONED_RE.test(value);
2914
+ if (zoned || ISO_DATETIME_NAIVE_RE.test(value)) {
2915
+ const d = new Date(zoned ? value : `${value}Z`);
2916
+ if (Number.isNaN(d.getTime())) return value;
2917
+ const formatted = new Intl.DateTimeFormat(void 0, {
2918
+ year: "numeric",
2919
+ month: "short",
2920
+ day: "numeric",
2921
+ hour: "2-digit",
2922
+ minute: "2-digit",
2923
+ hour12: false,
2924
+ timeZone: "UTC"
2925
+ }).format(d);
2926
+ return zoned ? `${formatted} UTC` : formatted;
2927
+ }
2928
+ return value;
2929
+ }
2886
2930
  const RECORD_EXCLUDE_KEYS = /* @__PURE__ */ new Set([
2887
2931
  "entity_id",
2888
2932
  "entity_type",
@@ -2940,7 +2984,7 @@ function parseRecordFields(feature) {
2940
2984
  for (const [k, v] of Object.entries(obj)) {
2941
2985
  if (v == null || v === "") continue;
2942
2986
  if (RECORD_FIELDS_HIDDEN_PREFIXES.some((p) => k.startsWith(p))) continue;
2943
- const display = typeof v === "object" ? JSON.stringify(v) : String(v);
2987
+ const display = typeof v === "object" ? JSON.stringify(v) : formatFieldValue(String(v));
2944
2988
  entries.push({ key: k, value: display });
2945
2989
  }
2946
2990
  entries.sort((a, b) => a.key.localeCompare(b.key));
@@ -3333,7 +3377,7 @@ function PropertiesPanel({ selectedFeatures, onUpdateProperties, onUpdateGeometr
3333
3377
  };
3334
3378
  const updated = await featureRefreshProvider(geoFeature);
3335
3379
  if (updated) {
3336
- onUpdateProperties(feature.id, updated);
3380
+ onUpdateProperties(feature.id, updated, { fromRefresh: true });
3337
3381
  if (!silent) {
3338
3382
  toast({ title: "Refreshed", description: "Properties updated from record" });
3339
3383
  }
@@ -3359,7 +3403,7 @@ function PropertiesPanel({ selectedFeatures, onUpdateProperties, onUpdateGeometr
3359
3403
  }, [feature == null ? void 0 : feature.id, isRecord, featureRefreshProvider, feature, handleRefresh]);
3360
3404
  const recordProperties = feature ? Object.entries(feature.properties).filter(
3361
3405
  ([key, value]) => !isExcludedRecordKey(key) && value !== void 0 && value !== null && !key.startsWith("_") && !key.startsWith("os_") && !key.startsWith("isHidden")
3362
- ).map(([key, value]) => ({ key, value: String(value) })) : [];
3406
+ ).map(([key, value]) => ({ key, value: formatFieldValue(String(value)) })) : [];
3363
3407
  const entityCardsContent = /* @__PURE__ */ jsxRuntime.jsx("div", { className: "p-2 space-y-2", children: entityCardProvider ? selectedFeatures.map((f) => {
3364
3408
  const geoFeature = {
3365
3409
  type: "Feature",
@@ -7908,12 +7952,16 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
7908
7952
  }
7909
7953
  }
7910
7954
  } else {
7911
- originalGeometriesRef.current.set(fid, JSON.parse(JSON.stringify(feature.geometry)));
7912
- if (!externalPersistence) {
7913
- drawInstance.setFeatureProperty(fid, "_unsaved", true);
7955
+ const previousGeometry = originalGeometriesRef.current.get(fid);
7956
+ const geometryChanged = !previousGeometry || JSON.stringify(previousGeometry) !== JSON.stringify(feature.geometry);
7957
+ if (geometryChanged) {
7958
+ originalGeometriesRef.current.set(fid, JSON.parse(JSON.stringify(feature.geometry)));
7959
+ if (!externalPersistence) {
7960
+ drawInstance.setFeatureProperty(fid, "_unsaved", true);
7961
+ }
7962
+ onFeatureUpdate == null ? void 0 : onFeatureUpdate(feature);
7963
+ setFeatureUpdateCounter((c) => c + 1);
7914
7964
  }
7915
- onFeatureUpdate == null ? void 0 : onFeatureUpdate(feature);
7916
- setFeatureUpdateCounter((c) => c + 1);
7917
7965
  }
7918
7966
  });
7919
7967
  syncRef.current();
@@ -7962,7 +8010,7 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
7962
8010
  });
7963
8011
  setSelectedFeatureIds(ids);
7964
8012
  selectedFeatureIdsRef.current = ids;
7965
- setShowProperties(ids.length > 0);
8013
+ if (enableProperties) setShowProperties(ids.length > 0);
7966
8014
  syncRef.current();
7967
8015
  onFeatureSelect == null ? void 0 : onFeatureSelect(e.features);
7968
8016
  });
@@ -9157,6 +9205,7 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
9157
9205
  handleModeChange(activeMode === "draw_polygon" ? "simple_select" : "draw_polygon");
9158
9206
  break;
9159
9207
  case "b":
9208
+ if (hiddenDrawingTools.includes("rectangle")) break;
9160
9209
  e.preventDefault();
9161
9210
  handleModeChange(activeMode === "draw_rectangle" ? "simple_select" : "draw_rectangle");
9162
9211
  break;
@@ -9179,7 +9228,7 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
9179
9228
  };
9180
9229
  container.addEventListener("keydown", handleKeyDown);
9181
9230
  return () => container.removeEventListener("keydown", handleKeyDown);
9182
- }, [isMapLoaded, enableKeyboardShortcuts, isEditMode, activeMode, handleToggleEditMode, handleUndo, handleRedo, handleModeChange, selectedFeatureIds, handleDeleteSelected, canDeleteSelected]);
9231
+ }, [isMapLoaded, enableKeyboardShortcuts, isEditMode, activeMode, handleToggleEditMode, handleUndo, handleRedo, handleModeChange, selectedFeatureIds, handleDeleteSelected, canDeleteSelected, hiddenDrawingTools]);
9183
9232
  const createPointAtCoords = react.useCallback((lng, lat) => {
9184
9233
  if (!draw.current || !isMapLoaded) return;
9185
9234
  if (!isEditModeRef.current) {
@@ -9211,13 +9260,13 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
9211
9260
  });
9212
9261
  draw.current.changeMode("simple_select", { featureIds: [id] });
9213
9262
  setSelectedFeatureIds([id]);
9214
- setShowProperties(true);
9263
+ if (enableProperties) setShowProperties(true);
9215
9264
  updateFeatureCount();
9216
9265
  scheduleTimelineUpdate();
9217
9266
  saveStateForUndo();
9218
9267
  syncFeaturesToCustomLayers();
9219
9268
  onFeatureCreate == null ? void 0 : onFeatureCreate(feature);
9220
- }, [isMapLoaded, externalPersistence, saveStateForUndo, updateFeatureCount, scheduleTimelineUpdate, syncFeaturesToCustomLayers, onFeatureCreate]);
9269
+ }, [isMapLoaded, externalPersistence, enableProperties, saveStateForUndo, updateFeatureCount, scheduleTimelineUpdate, syncFeaturesToCustomLayers, onFeatureCreate]);
9221
9270
  const handleFeatureContextMenu = react.useCallback((e) => {
9222
9271
  var _a, _b;
9223
9272
  contextMenuFiredRef.current = true;
@@ -9374,7 +9423,7 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
9374
9423
  }
9375
9424
  setSelectedFeatureIds([]);
9376
9425
  }, [isEditMode]);
9377
- const handleUpdateProperties = react.useCallback((featureId, properties) => {
9426
+ const handleUpdateProperties = react.useCallback((featureId, properties, options) => {
9378
9427
  var _a, _b, _c;
9379
9428
  if (!map.current) return;
9380
9429
  saveStateForUndo();
@@ -9396,7 +9445,7 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
9396
9445
  draw.current.setFeatureProperty(featureId, key, value);
9397
9446
  });
9398
9447
  const currentUnsaved = (_b = drawFeature.properties) == null ? void 0 : _b._unsaved;
9399
- if (!externalPersistence && hasRealChange && currentUnsaved !== false) {
9448
+ if (!externalPersistence && hasRealChange && currentUnsaved !== false && !(options == null ? void 0 : options.fromRefresh)) {
9400
9449
  draw.current.setFeatureProperty(featureId, "_unsaved", true);
9401
9450
  }
9402
9451
  if (properties.kind === "text" || ((_c = drawFeature.properties) == null ? void 0 : _c.kind) === "text") {
@@ -9421,7 +9470,7 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
9421
9470
  });
9422
9471
  const currentUnsaved = (_a2 = f.properties) == null ? void 0 : _a2._unsaved;
9423
9472
  f.properties = { ...f.properties, ...normalizedProperties };
9424
- if (!externalPersistence && hasRealChange && currentUnsaved !== false) {
9473
+ if (!externalPersistence && hasRealChange && currentUnsaved !== false && !(options == null ? void 0 : options.fromRefresh)) {
9425
9474
  f.properties._unsaved = true;
9426
9475
  }
9427
9476
  if (properties.kind === "text" || ((_b2 = f.properties) == null ? void 0 : _b2.kind) === "text") {
@@ -9811,8 +9860,15 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
9811
9860
  const v = (_a = l.layout) == null ? void 0 : _a.visibility;
9812
9861
  return v === void 0 || v === "visible";
9813
9862
  };
9863
+ const isBasemap = (l) => basemapPrefixes.some((p) => l.id.startsWith(p));
9864
+ let lastBasemapGeometryIdx = -1;
9865
+ allLayers.forEach((l, i) => {
9866
+ if (isBasemap(l) && l.type !== "symbol" && isVisible(l)) {
9867
+ lastBasemapGeometryIdx = i;
9868
+ }
9869
+ });
9814
9870
  const firstVisibleBasemapSymbol = allLayers.find(
9815
- (l) => l.type === "symbol" && basemapPrefixes.some((p) => l.id.startsWith(p)) && isVisible(l)
9871
+ (l, i) => i > lastBasemapGeometryIdx && l.type === "symbol" && isBasemap(l) && isVisible(l)
9816
9872
  );
9817
9873
  try {
9818
9874
  if (firstVisibleBasemapSymbol) {
@@ -10919,7 +10975,7 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
10919
10975
  map.current.getCanvas().style.cursor = "";
10920
10976
  }
10921
10977
  };
10922
- }, [activeMode, isMapLoaded, onFeatureCreate]);
10978
+ }, [activeMode, isMapLoaded, onFeatureCreate, enableProperties]);
10923
10979
  react.useEffect(() => {
10924
10980
  if (!map.current || !isMapLoaded || !draw.current) return;
10925
10981
  if (activeMode !== "draw_rectangle") {
@@ -11014,7 +11070,7 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
11014
11070
  drawInstance.changeMode("simple_select", { featureIds: [featureId] });
11015
11071
  setActiveMode("simple_select");
11016
11072
  setSelectedFeatureIds([featureId]);
11017
- setShowProperties(true);
11073
+ if (enableProperties) setShowProperties(true);
11018
11074
  if (onFeatureCreate) {
11019
11075
  onFeatureCreate(rectFeature);
11020
11076
  }
@@ -11047,7 +11103,7 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
11047
11103
  map.current.getCanvas().style.cursor = "";
11048
11104
  }
11049
11105
  };
11050
- }, [activeMode, isMapLoaded, onFeatureCreate]);
11106
+ }, [activeMode, isMapLoaded, onFeatureCreate, enableProperties]);
11051
11107
  const measurePointsRef = react.useRef([]);
11052
11108
  react.useEffect(() => {
11053
11109
  measurePointsRef.current = measurePoints;