@octostar/map-component 0.1.35 → 0.1.37

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
@@ -2896,6 +2896,37 @@ function formatEntityTypeName(type) {
2896
2896
  function formatPropertyKey(key) {
2897
2897
  return key.replace(/_/g, " ").replace(/\b\w/g, (c) => c.toUpperCase());
2898
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
+ }
2899
2930
  const RECORD_EXCLUDE_KEYS = /* @__PURE__ */ new Set([
2900
2931
  "entity_id",
2901
2932
  "entity_type",
@@ -2953,7 +2984,7 @@ function parseRecordFields(feature) {
2953
2984
  for (const [k, v] of Object.entries(obj)) {
2954
2985
  if (v == null || v === "") continue;
2955
2986
  if (RECORD_FIELDS_HIDDEN_PREFIXES.some((p) => k.startsWith(p))) continue;
2956
- const display = typeof v === "object" ? JSON.stringify(v) : String(v);
2987
+ const display = typeof v === "object" ? JSON.stringify(v) : formatFieldValue(String(v));
2957
2988
  entries.push({ key: k, value: display });
2958
2989
  }
2959
2990
  entries.sort((a, b) => a.key.localeCompare(b.key));
@@ -3346,7 +3377,7 @@ function PropertiesPanel({ selectedFeatures, onUpdateProperties, onUpdateGeometr
3346
3377
  };
3347
3378
  const updated = await featureRefreshProvider(geoFeature);
3348
3379
  if (updated) {
3349
- onUpdateProperties(feature.id, updated);
3380
+ onUpdateProperties(feature.id, updated, { fromRefresh: true });
3350
3381
  if (!silent) {
3351
3382
  toast({ title: "Refreshed", description: "Properties updated from record" });
3352
3383
  }
@@ -3372,7 +3403,7 @@ function PropertiesPanel({ selectedFeatures, onUpdateProperties, onUpdateGeometr
3372
3403
  }, [feature == null ? void 0 : feature.id, isRecord, featureRefreshProvider, feature, handleRefresh]);
3373
3404
  const recordProperties = feature ? Object.entries(feature.properties).filter(
3374
3405
  ([key, value]) => !isExcludedRecordKey(key) && value !== void 0 && value !== null && !key.startsWith("_") && !key.startsWith("os_") && !key.startsWith("isHidden")
3375
- ).map(([key, value]) => ({ key, value: String(value) })) : [];
3406
+ ).map(([key, value]) => ({ key, value: formatFieldValue(String(value)) })) : [];
3376
3407
  const entityCardsContent = /* @__PURE__ */ jsxRuntime.jsx("div", { className: "p-2 space-y-2", children: entityCardProvider ? selectedFeatures.map((f) => {
3377
3408
  const geoFeature = {
3378
3409
  type: "Feature",
@@ -5886,6 +5917,7 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
5886
5917
  externalPersistence = false,
5887
5918
  enableKeyboardShortcuts = true,
5888
5919
  enableProperties = true,
5920
+ autoOpenProperties = true,
5889
5921
  toastProvider,
5890
5922
  customGlobalMenuItems,
5891
5923
  extraLayerToolbarButtons,
@@ -5967,6 +5999,7 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
5967
5999
  const isDrawingRectangle = react.useRef(false);
5968
6000
  const rectangleCornerPointRef = react.useRef(null);
5969
6001
  const justCreatedRectangleRef = react.useRef(false);
6002
+ const justCreatedFeatureRef = react.useRef(false);
5970
6003
  const [autoLabelConfig, setAutoLabelConfig] = react.useState({ enabled: true, threshold: 220 });
5971
6004
  const [visibleFeatureCount, setVisibleFeatureCount] = react.useState(Infinity);
5972
6005
  const lastLabelVisibility = react.useRef(false);
@@ -7795,6 +7828,10 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
7795
7828
  });
7796
7829
  const processedFeatureIds = /* @__PURE__ */ new Set();
7797
7830
  mapInstance.on("draw.create", (e) => {
7831
+ justCreatedFeatureRef.current = true;
7832
+ setTimeout(() => {
7833
+ justCreatedFeatureRef.current = false;
7834
+ }, 0);
7798
7835
  const newFeatures = e.features.filter((f) => {
7799
7836
  const id = f.id;
7800
7837
  if (processedFeatureIds.has(id)) return false;
@@ -7921,12 +7958,16 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
7921
7958
  }
7922
7959
  }
7923
7960
  } else {
7924
- originalGeometriesRef.current.set(fid, JSON.parse(JSON.stringify(feature.geometry)));
7925
- if (!externalPersistence) {
7926
- drawInstance.setFeatureProperty(fid, "_unsaved", true);
7961
+ const previousGeometry = originalGeometriesRef.current.get(fid);
7962
+ const geometryChanged = !previousGeometry || JSON.stringify(previousGeometry) !== JSON.stringify(feature.geometry);
7963
+ if (geometryChanged) {
7964
+ originalGeometriesRef.current.set(fid, JSON.parse(JSON.stringify(feature.geometry)));
7965
+ if (!externalPersistence) {
7966
+ drawInstance.setFeatureProperty(fid, "_unsaved", true);
7967
+ }
7968
+ onFeatureUpdate == null ? void 0 : onFeatureUpdate(feature);
7969
+ setFeatureUpdateCounter((c) => c + 1);
7927
7970
  }
7928
- onFeatureUpdate == null ? void 0 : onFeatureUpdate(feature);
7929
- setFeatureUpdateCounter((c) => c + 1);
7930
7971
  }
7931
7972
  });
7932
7973
  syncRef.current();
@@ -7975,7 +8016,11 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
7975
8016
  });
7976
8017
  setSelectedFeatureIds(ids);
7977
8018
  selectedFeatureIdsRef.current = ids;
7978
- if (enableProperties) setShowProperties(ids.length > 0);
8019
+ const wasJustCreated = justCreatedFeatureRef.current;
8020
+ justCreatedFeatureRef.current = false;
8021
+ if (enableProperties && (autoOpenProperties || !wasJustCreated)) {
8022
+ setShowProperties(ids.length > 0);
8023
+ }
7979
8024
  syncRef.current();
7980
8025
  onFeatureSelect == null ? void 0 : onFeatureSelect(e.features);
7981
8026
  });
@@ -9225,13 +9270,13 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
9225
9270
  });
9226
9271
  draw.current.changeMode("simple_select", { featureIds: [id] });
9227
9272
  setSelectedFeatureIds([id]);
9228
- if (enableProperties) setShowProperties(true);
9273
+ if (enableProperties && autoOpenProperties) setShowProperties(true);
9229
9274
  updateFeatureCount();
9230
9275
  scheduleTimelineUpdate();
9231
9276
  saveStateForUndo();
9232
9277
  syncFeaturesToCustomLayers();
9233
9278
  onFeatureCreate == null ? void 0 : onFeatureCreate(feature);
9234
- }, [isMapLoaded, externalPersistence, enableProperties, saveStateForUndo, updateFeatureCount, scheduleTimelineUpdate, syncFeaturesToCustomLayers, onFeatureCreate]);
9279
+ }, [isMapLoaded, externalPersistence, enableProperties, autoOpenProperties, saveStateForUndo, updateFeatureCount, scheduleTimelineUpdate, syncFeaturesToCustomLayers, onFeatureCreate]);
9235
9280
  const handleFeatureContextMenu = react.useCallback((e) => {
9236
9281
  var _a, _b;
9237
9282
  contextMenuFiredRef.current = true;
@@ -9388,7 +9433,7 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
9388
9433
  }
9389
9434
  setSelectedFeatureIds([]);
9390
9435
  }, [isEditMode]);
9391
- const handleUpdateProperties = react.useCallback((featureId, properties) => {
9436
+ const handleUpdateProperties = react.useCallback((featureId, properties, options) => {
9392
9437
  var _a, _b, _c;
9393
9438
  if (!map.current) return;
9394
9439
  saveStateForUndo();
@@ -9410,7 +9455,7 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
9410
9455
  draw.current.setFeatureProperty(featureId, key, value);
9411
9456
  });
9412
9457
  const currentUnsaved = (_b = drawFeature.properties) == null ? void 0 : _b._unsaved;
9413
- if (!externalPersistence && hasRealChange && currentUnsaved !== false) {
9458
+ if (!externalPersistence && hasRealChange && currentUnsaved !== false && !(options == null ? void 0 : options.fromRefresh)) {
9414
9459
  draw.current.setFeatureProperty(featureId, "_unsaved", true);
9415
9460
  }
9416
9461
  if (properties.kind === "text" || ((_c = drawFeature.properties) == null ? void 0 : _c.kind) === "text") {
@@ -9435,7 +9480,7 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
9435
9480
  });
9436
9481
  const currentUnsaved = (_a2 = f.properties) == null ? void 0 : _a2._unsaved;
9437
9482
  f.properties = { ...f.properties, ...normalizedProperties };
9438
- if (!externalPersistence && hasRealChange && currentUnsaved !== false) {
9483
+ if (!externalPersistence && hasRealChange && currentUnsaved !== false && !(options == null ? void 0 : options.fromRefresh)) {
9439
9484
  f.properties._unsaved = true;
9440
9485
  }
9441
9486
  if (properties.kind === "text" || ((_b2 = f.properties) == null ? void 0 : _b2.kind) === "text") {
@@ -9825,8 +9870,15 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
9825
9870
  const v = (_a = l.layout) == null ? void 0 : _a.visibility;
9826
9871
  return v === void 0 || v === "visible";
9827
9872
  };
9873
+ const isBasemap = (l) => basemapPrefixes.some((p) => l.id.startsWith(p));
9874
+ let lastBasemapGeometryIdx = -1;
9875
+ allLayers.forEach((l, i) => {
9876
+ if (isBasemap(l) && l.type !== "symbol" && isVisible(l)) {
9877
+ lastBasemapGeometryIdx = i;
9878
+ }
9879
+ });
9828
9880
  const firstVisibleBasemapSymbol = allLayers.find(
9829
- (l) => l.type === "symbol" && basemapPrefixes.some((p) => l.id.startsWith(p)) && isVisible(l)
9881
+ (l, i) => i > lastBasemapGeometryIdx && l.type === "symbol" && isBasemap(l) && isVisible(l)
9830
9882
  );
9831
9883
  try {
9832
9884
  if (firstVisibleBasemapSymbol) {
@@ -10900,7 +10952,7 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
10900
10952
  drawInstance.changeMode("simple_select", { featureIds: [featureId] });
10901
10953
  setActiveMode("simple_select");
10902
10954
  setSelectedFeatureIds([featureId]);
10903
- if (enableProperties) setShowProperties(true);
10955
+ if (enableProperties && autoOpenProperties) setShowProperties(true);
10904
10956
  if (onFeatureCreate) {
10905
10957
  onFeatureCreate(circleFeature);
10906
10958
  }
@@ -10933,7 +10985,7 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
10933
10985
  map.current.getCanvas().style.cursor = "";
10934
10986
  }
10935
10987
  };
10936
- }, [activeMode, isMapLoaded, onFeatureCreate, enableProperties]);
10988
+ }, [activeMode, isMapLoaded, onFeatureCreate, enableProperties, autoOpenProperties]);
10937
10989
  react.useEffect(() => {
10938
10990
  if (!map.current || !isMapLoaded || !draw.current) return;
10939
10991
  if (activeMode !== "draw_rectangle") {
@@ -11028,7 +11080,7 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
11028
11080
  drawInstance.changeMode("simple_select", { featureIds: [featureId] });
11029
11081
  setActiveMode("simple_select");
11030
11082
  setSelectedFeatureIds([featureId]);
11031
- if (enableProperties) setShowProperties(true);
11083
+ if (enableProperties && autoOpenProperties) setShowProperties(true);
11032
11084
  if (onFeatureCreate) {
11033
11085
  onFeatureCreate(rectFeature);
11034
11086
  }
@@ -11061,7 +11113,7 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
11061
11113
  map.current.getCanvas().style.cursor = "";
11062
11114
  }
11063
11115
  };
11064
- }, [activeMode, isMapLoaded, onFeatureCreate, enableProperties]);
11116
+ }, [activeMode, isMapLoaded, onFeatureCreate, enableProperties, autoOpenProperties]);
11065
11117
  const measurePointsRef = react.useRef([]);
11066
11118
  react.useEffect(() => {
11067
11119
  measurePointsRef.current = measurePoints;