@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 +71 -19
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +71 -19
- package/dist/index.mjs.map +1 -1
- package/dist/types/components/map-editor-canvas.d.ts.map +1 -1
- package/dist/types/components/properties-panel.d.ts +3 -1
- package/dist/types/components/properties-panel.d.ts.map +1 -1
- package/dist/types/lib/map-editor-api.d.ts +6 -0
- package/dist/types/lib/map-editor-api.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -2875,6 +2875,37 @@ function formatEntityTypeName(type) {
|
|
|
2875
2875
|
function formatPropertyKey(key) {
|
|
2876
2876
|
return key.replace(/_/g, " ").replace(/\b\w/g, (c) => c.toUpperCase());
|
|
2877
2877
|
}
|
|
2878
|
+
const ISO_DATE_RE = /^\d{4}-\d{2}-\d{2}$/;
|
|
2879
|
+
const ISO_DATETIME_ZONED_RE = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(:\d{2})?(\.\d+)?(Z|[+-]\d{2}:?\d{2})$/;
|
|
2880
|
+
const ISO_DATETIME_NAIVE_RE = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(:\d{2})?(\.\d+)?$/;
|
|
2881
|
+
function formatFieldValue(value) {
|
|
2882
|
+
if (ISO_DATE_RE.test(value)) {
|
|
2883
|
+
const d = /* @__PURE__ */ new Date(`${value}T00:00:00Z`);
|
|
2884
|
+
if (Number.isNaN(d.getTime())) return value;
|
|
2885
|
+
return new Intl.DateTimeFormat(void 0, {
|
|
2886
|
+
year: "numeric",
|
|
2887
|
+
month: "short",
|
|
2888
|
+
day: "numeric",
|
|
2889
|
+
timeZone: "UTC"
|
|
2890
|
+
}).format(d);
|
|
2891
|
+
}
|
|
2892
|
+
const zoned = ISO_DATETIME_ZONED_RE.test(value);
|
|
2893
|
+
if (zoned || ISO_DATETIME_NAIVE_RE.test(value)) {
|
|
2894
|
+
const d = new Date(zoned ? value : `${value}Z`);
|
|
2895
|
+
if (Number.isNaN(d.getTime())) return value;
|
|
2896
|
+
const formatted = new Intl.DateTimeFormat(void 0, {
|
|
2897
|
+
year: "numeric",
|
|
2898
|
+
month: "short",
|
|
2899
|
+
day: "numeric",
|
|
2900
|
+
hour: "2-digit",
|
|
2901
|
+
minute: "2-digit",
|
|
2902
|
+
hour12: false,
|
|
2903
|
+
timeZone: "UTC"
|
|
2904
|
+
}).format(d);
|
|
2905
|
+
return zoned ? `${formatted} UTC` : formatted;
|
|
2906
|
+
}
|
|
2907
|
+
return value;
|
|
2908
|
+
}
|
|
2878
2909
|
const RECORD_EXCLUDE_KEYS = /* @__PURE__ */ new Set([
|
|
2879
2910
|
"entity_id",
|
|
2880
2911
|
"entity_type",
|
|
@@ -2932,7 +2963,7 @@ function parseRecordFields(feature) {
|
|
|
2932
2963
|
for (const [k, v] of Object.entries(obj)) {
|
|
2933
2964
|
if (v == null || v === "") continue;
|
|
2934
2965
|
if (RECORD_FIELDS_HIDDEN_PREFIXES.some((p) => k.startsWith(p))) continue;
|
|
2935
|
-
const display = typeof v === "object" ? JSON.stringify(v) : String(v);
|
|
2966
|
+
const display = typeof v === "object" ? JSON.stringify(v) : formatFieldValue(String(v));
|
|
2936
2967
|
entries.push({ key: k, value: display });
|
|
2937
2968
|
}
|
|
2938
2969
|
entries.sort((a, b) => a.key.localeCompare(b.key));
|
|
@@ -3325,7 +3356,7 @@ function PropertiesPanel({ selectedFeatures, onUpdateProperties, onUpdateGeometr
|
|
|
3325
3356
|
};
|
|
3326
3357
|
const updated = await featureRefreshProvider(geoFeature);
|
|
3327
3358
|
if (updated) {
|
|
3328
|
-
onUpdateProperties(feature.id, updated);
|
|
3359
|
+
onUpdateProperties(feature.id, updated, { fromRefresh: true });
|
|
3329
3360
|
if (!silent) {
|
|
3330
3361
|
toast({ title: "Refreshed", description: "Properties updated from record" });
|
|
3331
3362
|
}
|
|
@@ -3351,7 +3382,7 @@ function PropertiesPanel({ selectedFeatures, onUpdateProperties, onUpdateGeometr
|
|
|
3351
3382
|
}, [feature == null ? void 0 : feature.id, isRecord, featureRefreshProvider, feature, handleRefresh]);
|
|
3352
3383
|
const recordProperties = feature ? Object.entries(feature.properties).filter(
|
|
3353
3384
|
([key, value]) => !isExcludedRecordKey(key) && value !== void 0 && value !== null && !key.startsWith("_") && !key.startsWith("os_") && !key.startsWith("isHidden")
|
|
3354
|
-
).map(([key, value]) => ({ key, value: String(value) })) : [];
|
|
3385
|
+
).map(([key, value]) => ({ key, value: formatFieldValue(String(value)) })) : [];
|
|
3355
3386
|
const entityCardsContent = /* @__PURE__ */ jsx("div", { className: "p-2 space-y-2", children: entityCardProvider ? selectedFeatures.map((f) => {
|
|
3356
3387
|
const geoFeature = {
|
|
3357
3388
|
type: "Feature",
|
|
@@ -5865,6 +5896,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
5865
5896
|
externalPersistence = false,
|
|
5866
5897
|
enableKeyboardShortcuts = true,
|
|
5867
5898
|
enableProperties = true,
|
|
5899
|
+
autoOpenProperties = true,
|
|
5868
5900
|
toastProvider,
|
|
5869
5901
|
customGlobalMenuItems,
|
|
5870
5902
|
extraLayerToolbarButtons,
|
|
@@ -5946,6 +5978,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
5946
5978
|
const isDrawingRectangle = useRef(false);
|
|
5947
5979
|
const rectangleCornerPointRef = useRef(null);
|
|
5948
5980
|
const justCreatedRectangleRef = useRef(false);
|
|
5981
|
+
const justCreatedFeatureRef = useRef(false);
|
|
5949
5982
|
const [autoLabelConfig, setAutoLabelConfig] = useState({ enabled: true, threshold: 220 });
|
|
5950
5983
|
const [visibleFeatureCount, setVisibleFeatureCount] = useState(Infinity);
|
|
5951
5984
|
const lastLabelVisibility = useRef(false);
|
|
@@ -7774,6 +7807,10 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
7774
7807
|
});
|
|
7775
7808
|
const processedFeatureIds = /* @__PURE__ */ new Set();
|
|
7776
7809
|
mapInstance.on("draw.create", (e) => {
|
|
7810
|
+
justCreatedFeatureRef.current = true;
|
|
7811
|
+
setTimeout(() => {
|
|
7812
|
+
justCreatedFeatureRef.current = false;
|
|
7813
|
+
}, 0);
|
|
7777
7814
|
const newFeatures = e.features.filter((f) => {
|
|
7778
7815
|
const id = f.id;
|
|
7779
7816
|
if (processedFeatureIds.has(id)) return false;
|
|
@@ -7900,12 +7937,16 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
7900
7937
|
}
|
|
7901
7938
|
}
|
|
7902
7939
|
} else {
|
|
7903
|
-
originalGeometriesRef.current.
|
|
7904
|
-
|
|
7905
|
-
|
|
7940
|
+
const previousGeometry = originalGeometriesRef.current.get(fid);
|
|
7941
|
+
const geometryChanged = !previousGeometry || JSON.stringify(previousGeometry) !== JSON.stringify(feature.geometry);
|
|
7942
|
+
if (geometryChanged) {
|
|
7943
|
+
originalGeometriesRef.current.set(fid, JSON.parse(JSON.stringify(feature.geometry)));
|
|
7944
|
+
if (!externalPersistence) {
|
|
7945
|
+
drawInstance.setFeatureProperty(fid, "_unsaved", true);
|
|
7946
|
+
}
|
|
7947
|
+
onFeatureUpdate == null ? void 0 : onFeatureUpdate(feature);
|
|
7948
|
+
setFeatureUpdateCounter((c) => c + 1);
|
|
7906
7949
|
}
|
|
7907
|
-
onFeatureUpdate == null ? void 0 : onFeatureUpdate(feature);
|
|
7908
|
-
setFeatureUpdateCounter((c) => c + 1);
|
|
7909
7950
|
}
|
|
7910
7951
|
});
|
|
7911
7952
|
syncRef.current();
|
|
@@ -7954,7 +7995,11 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
7954
7995
|
});
|
|
7955
7996
|
setSelectedFeatureIds(ids);
|
|
7956
7997
|
selectedFeatureIdsRef.current = ids;
|
|
7957
|
-
|
|
7998
|
+
const wasJustCreated = justCreatedFeatureRef.current;
|
|
7999
|
+
justCreatedFeatureRef.current = false;
|
|
8000
|
+
if (enableProperties && (autoOpenProperties || !wasJustCreated)) {
|
|
8001
|
+
setShowProperties(ids.length > 0);
|
|
8002
|
+
}
|
|
7958
8003
|
syncRef.current();
|
|
7959
8004
|
onFeatureSelect == null ? void 0 : onFeatureSelect(e.features);
|
|
7960
8005
|
});
|
|
@@ -9204,13 +9249,13 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
9204
9249
|
});
|
|
9205
9250
|
draw.current.changeMode("simple_select", { featureIds: [id] });
|
|
9206
9251
|
setSelectedFeatureIds([id]);
|
|
9207
|
-
if (enableProperties) setShowProperties(true);
|
|
9252
|
+
if (enableProperties && autoOpenProperties) setShowProperties(true);
|
|
9208
9253
|
updateFeatureCount();
|
|
9209
9254
|
scheduleTimelineUpdate();
|
|
9210
9255
|
saveStateForUndo();
|
|
9211
9256
|
syncFeaturesToCustomLayers();
|
|
9212
9257
|
onFeatureCreate == null ? void 0 : onFeatureCreate(feature);
|
|
9213
|
-
}, [isMapLoaded, externalPersistence, enableProperties, saveStateForUndo, updateFeatureCount, scheduleTimelineUpdate, syncFeaturesToCustomLayers, onFeatureCreate]);
|
|
9258
|
+
}, [isMapLoaded, externalPersistence, enableProperties, autoOpenProperties, saveStateForUndo, updateFeatureCount, scheduleTimelineUpdate, syncFeaturesToCustomLayers, onFeatureCreate]);
|
|
9214
9259
|
const handleFeatureContextMenu = useCallback((e) => {
|
|
9215
9260
|
var _a, _b;
|
|
9216
9261
|
contextMenuFiredRef.current = true;
|
|
@@ -9367,7 +9412,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
9367
9412
|
}
|
|
9368
9413
|
setSelectedFeatureIds([]);
|
|
9369
9414
|
}, [isEditMode]);
|
|
9370
|
-
const handleUpdateProperties = useCallback((featureId, properties) => {
|
|
9415
|
+
const handleUpdateProperties = useCallback((featureId, properties, options) => {
|
|
9371
9416
|
var _a, _b, _c;
|
|
9372
9417
|
if (!map.current) return;
|
|
9373
9418
|
saveStateForUndo();
|
|
@@ -9389,7 +9434,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
9389
9434
|
draw.current.setFeatureProperty(featureId, key, value);
|
|
9390
9435
|
});
|
|
9391
9436
|
const currentUnsaved = (_b = drawFeature.properties) == null ? void 0 : _b._unsaved;
|
|
9392
|
-
if (!externalPersistence && hasRealChange && currentUnsaved !== false) {
|
|
9437
|
+
if (!externalPersistence && hasRealChange && currentUnsaved !== false && !(options == null ? void 0 : options.fromRefresh)) {
|
|
9393
9438
|
draw.current.setFeatureProperty(featureId, "_unsaved", true);
|
|
9394
9439
|
}
|
|
9395
9440
|
if (properties.kind === "text" || ((_c = drawFeature.properties) == null ? void 0 : _c.kind) === "text") {
|
|
@@ -9414,7 +9459,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
9414
9459
|
});
|
|
9415
9460
|
const currentUnsaved = (_a2 = f.properties) == null ? void 0 : _a2._unsaved;
|
|
9416
9461
|
f.properties = { ...f.properties, ...normalizedProperties };
|
|
9417
|
-
if (!externalPersistence && hasRealChange && currentUnsaved !== false) {
|
|
9462
|
+
if (!externalPersistence && hasRealChange && currentUnsaved !== false && !(options == null ? void 0 : options.fromRefresh)) {
|
|
9418
9463
|
f.properties._unsaved = true;
|
|
9419
9464
|
}
|
|
9420
9465
|
if (properties.kind === "text" || ((_b2 = f.properties) == null ? void 0 : _b2.kind) === "text") {
|
|
@@ -9804,8 +9849,15 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
9804
9849
|
const v = (_a = l.layout) == null ? void 0 : _a.visibility;
|
|
9805
9850
|
return v === void 0 || v === "visible";
|
|
9806
9851
|
};
|
|
9852
|
+
const isBasemap = (l) => basemapPrefixes.some((p) => l.id.startsWith(p));
|
|
9853
|
+
let lastBasemapGeometryIdx = -1;
|
|
9854
|
+
allLayers.forEach((l, i) => {
|
|
9855
|
+
if (isBasemap(l) && l.type !== "symbol" && isVisible(l)) {
|
|
9856
|
+
lastBasemapGeometryIdx = i;
|
|
9857
|
+
}
|
|
9858
|
+
});
|
|
9807
9859
|
const firstVisibleBasemapSymbol = allLayers.find(
|
|
9808
|
-
(l) => l.type === "symbol" &&
|
|
9860
|
+
(l, i) => i > lastBasemapGeometryIdx && l.type === "symbol" && isBasemap(l) && isVisible(l)
|
|
9809
9861
|
);
|
|
9810
9862
|
try {
|
|
9811
9863
|
if (firstVisibleBasemapSymbol) {
|
|
@@ -10879,7 +10931,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
10879
10931
|
drawInstance.changeMode("simple_select", { featureIds: [featureId] });
|
|
10880
10932
|
setActiveMode("simple_select");
|
|
10881
10933
|
setSelectedFeatureIds([featureId]);
|
|
10882
|
-
if (enableProperties) setShowProperties(true);
|
|
10934
|
+
if (enableProperties && autoOpenProperties) setShowProperties(true);
|
|
10883
10935
|
if (onFeatureCreate) {
|
|
10884
10936
|
onFeatureCreate(circleFeature);
|
|
10885
10937
|
}
|
|
@@ -10912,7 +10964,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
10912
10964
|
map.current.getCanvas().style.cursor = "";
|
|
10913
10965
|
}
|
|
10914
10966
|
};
|
|
10915
|
-
}, [activeMode, isMapLoaded, onFeatureCreate, enableProperties]);
|
|
10967
|
+
}, [activeMode, isMapLoaded, onFeatureCreate, enableProperties, autoOpenProperties]);
|
|
10916
10968
|
useEffect(() => {
|
|
10917
10969
|
if (!map.current || !isMapLoaded || !draw.current) return;
|
|
10918
10970
|
if (activeMode !== "draw_rectangle") {
|
|
@@ -11007,7 +11059,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
11007
11059
|
drawInstance.changeMode("simple_select", { featureIds: [featureId] });
|
|
11008
11060
|
setActiveMode("simple_select");
|
|
11009
11061
|
setSelectedFeatureIds([featureId]);
|
|
11010
|
-
if (enableProperties) setShowProperties(true);
|
|
11062
|
+
if (enableProperties && autoOpenProperties) setShowProperties(true);
|
|
11011
11063
|
if (onFeatureCreate) {
|
|
11012
11064
|
onFeatureCreate(rectFeature);
|
|
11013
11065
|
}
|
|
@@ -11040,7 +11092,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
11040
11092
|
map.current.getCanvas().style.cursor = "";
|
|
11041
11093
|
}
|
|
11042
11094
|
};
|
|
11043
|
-
}, [activeMode, isMapLoaded, onFeatureCreate, enableProperties]);
|
|
11095
|
+
}, [activeMode, isMapLoaded, onFeatureCreate, enableProperties, autoOpenProperties]);
|
|
11044
11096
|
const measurePointsRef = useRef([]);
|
|
11045
11097
|
useEffect(() => {
|
|
11046
11098
|
measurePointsRef.current = measurePoints;
|