@octostar/map-component 0.1.35 → 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
@@ -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",
@@ -7921,12 +7952,16 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
7921
7952
  }
7922
7953
  }
7923
7954
  } else {
7924
- originalGeometriesRef.current.set(fid, JSON.parse(JSON.stringify(feature.geometry)));
7925
- if (!externalPersistence) {
7926
- 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);
7927
7964
  }
7928
- onFeatureUpdate == null ? void 0 : onFeatureUpdate(feature);
7929
- setFeatureUpdateCounter((c) => c + 1);
7930
7965
  }
7931
7966
  });
7932
7967
  syncRef.current();
@@ -9388,7 +9423,7 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
9388
9423
  }
9389
9424
  setSelectedFeatureIds([]);
9390
9425
  }, [isEditMode]);
9391
- const handleUpdateProperties = react.useCallback((featureId, properties) => {
9426
+ const handleUpdateProperties = react.useCallback((featureId, properties, options) => {
9392
9427
  var _a, _b, _c;
9393
9428
  if (!map.current) return;
9394
9429
  saveStateForUndo();
@@ -9410,7 +9445,7 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
9410
9445
  draw.current.setFeatureProperty(featureId, key, value);
9411
9446
  });
9412
9447
  const currentUnsaved = (_b = drawFeature.properties) == null ? void 0 : _b._unsaved;
9413
- if (!externalPersistence && hasRealChange && currentUnsaved !== false) {
9448
+ if (!externalPersistence && hasRealChange && currentUnsaved !== false && !(options == null ? void 0 : options.fromRefresh)) {
9414
9449
  draw.current.setFeatureProperty(featureId, "_unsaved", true);
9415
9450
  }
9416
9451
  if (properties.kind === "text" || ((_c = drawFeature.properties) == null ? void 0 : _c.kind) === "text") {
@@ -9435,7 +9470,7 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
9435
9470
  });
9436
9471
  const currentUnsaved = (_a2 = f.properties) == null ? void 0 : _a2._unsaved;
9437
9472
  f.properties = { ...f.properties, ...normalizedProperties };
9438
- if (!externalPersistence && hasRealChange && currentUnsaved !== false) {
9473
+ if (!externalPersistence && hasRealChange && currentUnsaved !== false && !(options == null ? void 0 : options.fromRefresh)) {
9439
9474
  f.properties._unsaved = true;
9440
9475
  }
9441
9476
  if (properties.kind === "text" || ((_b2 = f.properties) == null ? void 0 : _b2.kind) === "text") {
@@ -9825,8 +9860,15 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
9825
9860
  const v = (_a = l.layout) == null ? void 0 : _a.visibility;
9826
9861
  return v === void 0 || v === "visible";
9827
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
+ });
9828
9870
  const firstVisibleBasemapSymbol = allLayers.find(
9829
- (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)
9830
9872
  );
9831
9873
  try {
9832
9874
  if (firstVisibleBasemapSymbol) {