@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 +76 -20
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +76 -20
- package/dist/index.mjs.map +1 -1
- package/dist/types/components/drawing-toolbar.d.ts +1 -1
- package/dist/types/components/drawing-toolbar.d.ts.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 +1 -1
- package/dist/types/lib/map-editor-api.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1132,7 +1132,20 @@ function DrawingToolbar({
|
|
|
1132
1132
|
showShortcutHint: showShortcutHints
|
|
1133
1133
|
}
|
|
1134
1134
|
),
|
|
1135
|
-
!hiddenDrawingTools.includes("polygon") && /* @__PURE__ */ jsx(
|
|
1135
|
+
!hiddenDrawingTools.includes("polygon") && hiddenDrawingTools.includes("rectangle") && /* @__PURE__ */ jsx(
|
|
1136
|
+
ToolButton,
|
|
1137
|
+
{
|
|
1138
|
+
mode: "draw_polygon",
|
|
1139
|
+
activeMode,
|
|
1140
|
+
onModeChange,
|
|
1141
|
+
icon: /* @__PURE__ */ jsx(Pentagon, { className: "w-5 h-5" }),
|
|
1142
|
+
label: "Draw Polygon",
|
|
1143
|
+
shortcut: "G",
|
|
1144
|
+
disabled: drawingDisabled,
|
|
1145
|
+
showShortcutHint: showShortcutHints
|
|
1146
|
+
}
|
|
1147
|
+
),
|
|
1148
|
+
!hiddenDrawingTools.includes("polygon") && !hiddenDrawingTools.includes("rectangle") && /* @__PURE__ */ jsx(
|
|
1136
1149
|
Dropdown,
|
|
1137
1150
|
{
|
|
1138
1151
|
menu: {
|
|
@@ -2862,6 +2875,37 @@ function formatEntityTypeName(type) {
|
|
|
2862
2875
|
function formatPropertyKey(key) {
|
|
2863
2876
|
return key.replace(/_/g, " ").replace(/\b\w/g, (c) => c.toUpperCase());
|
|
2864
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
|
+
}
|
|
2865
2909
|
const RECORD_EXCLUDE_KEYS = /* @__PURE__ */ new Set([
|
|
2866
2910
|
"entity_id",
|
|
2867
2911
|
"entity_type",
|
|
@@ -2919,7 +2963,7 @@ function parseRecordFields(feature) {
|
|
|
2919
2963
|
for (const [k, v] of Object.entries(obj)) {
|
|
2920
2964
|
if (v == null || v === "") continue;
|
|
2921
2965
|
if (RECORD_FIELDS_HIDDEN_PREFIXES.some((p) => k.startsWith(p))) continue;
|
|
2922
|
-
const display = typeof v === "object" ? JSON.stringify(v) : String(v);
|
|
2966
|
+
const display = typeof v === "object" ? JSON.stringify(v) : formatFieldValue(String(v));
|
|
2923
2967
|
entries.push({ key: k, value: display });
|
|
2924
2968
|
}
|
|
2925
2969
|
entries.sort((a, b) => a.key.localeCompare(b.key));
|
|
@@ -3312,7 +3356,7 @@ function PropertiesPanel({ selectedFeatures, onUpdateProperties, onUpdateGeometr
|
|
|
3312
3356
|
};
|
|
3313
3357
|
const updated = await featureRefreshProvider(geoFeature);
|
|
3314
3358
|
if (updated) {
|
|
3315
|
-
onUpdateProperties(feature.id, updated);
|
|
3359
|
+
onUpdateProperties(feature.id, updated, { fromRefresh: true });
|
|
3316
3360
|
if (!silent) {
|
|
3317
3361
|
toast({ title: "Refreshed", description: "Properties updated from record" });
|
|
3318
3362
|
}
|
|
@@ -3338,7 +3382,7 @@ function PropertiesPanel({ selectedFeatures, onUpdateProperties, onUpdateGeometr
|
|
|
3338
3382
|
}, [feature == null ? void 0 : feature.id, isRecord, featureRefreshProvider, feature, handleRefresh]);
|
|
3339
3383
|
const recordProperties = feature ? Object.entries(feature.properties).filter(
|
|
3340
3384
|
([key, value]) => !isExcludedRecordKey(key) && value !== void 0 && value !== null && !key.startsWith("_") && !key.startsWith("os_") && !key.startsWith("isHidden")
|
|
3341
|
-
).map(([key, value]) => ({ key, value: String(value) })) : [];
|
|
3385
|
+
).map(([key, value]) => ({ key, value: formatFieldValue(String(value)) })) : [];
|
|
3342
3386
|
const entityCardsContent = /* @__PURE__ */ jsx("div", { className: "p-2 space-y-2", children: entityCardProvider ? selectedFeatures.map((f) => {
|
|
3343
3387
|
const geoFeature = {
|
|
3344
3388
|
type: "Feature",
|
|
@@ -7887,12 +7931,16 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
7887
7931
|
}
|
|
7888
7932
|
}
|
|
7889
7933
|
} else {
|
|
7890
|
-
originalGeometriesRef.current.
|
|
7891
|
-
|
|
7892
|
-
|
|
7934
|
+
const previousGeometry = originalGeometriesRef.current.get(fid);
|
|
7935
|
+
const geometryChanged = !previousGeometry || JSON.stringify(previousGeometry) !== JSON.stringify(feature.geometry);
|
|
7936
|
+
if (geometryChanged) {
|
|
7937
|
+
originalGeometriesRef.current.set(fid, JSON.parse(JSON.stringify(feature.geometry)));
|
|
7938
|
+
if (!externalPersistence) {
|
|
7939
|
+
drawInstance.setFeatureProperty(fid, "_unsaved", true);
|
|
7940
|
+
}
|
|
7941
|
+
onFeatureUpdate == null ? void 0 : onFeatureUpdate(feature);
|
|
7942
|
+
setFeatureUpdateCounter((c) => c + 1);
|
|
7893
7943
|
}
|
|
7894
|
-
onFeatureUpdate == null ? void 0 : onFeatureUpdate(feature);
|
|
7895
|
-
setFeatureUpdateCounter((c) => c + 1);
|
|
7896
7944
|
}
|
|
7897
7945
|
});
|
|
7898
7946
|
syncRef.current();
|
|
@@ -7941,7 +7989,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
7941
7989
|
});
|
|
7942
7990
|
setSelectedFeatureIds(ids);
|
|
7943
7991
|
selectedFeatureIdsRef.current = ids;
|
|
7944
|
-
setShowProperties(ids.length > 0);
|
|
7992
|
+
if (enableProperties) setShowProperties(ids.length > 0);
|
|
7945
7993
|
syncRef.current();
|
|
7946
7994
|
onFeatureSelect == null ? void 0 : onFeatureSelect(e.features);
|
|
7947
7995
|
});
|
|
@@ -9136,6 +9184,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
9136
9184
|
handleModeChange(activeMode === "draw_polygon" ? "simple_select" : "draw_polygon");
|
|
9137
9185
|
break;
|
|
9138
9186
|
case "b":
|
|
9187
|
+
if (hiddenDrawingTools.includes("rectangle")) break;
|
|
9139
9188
|
e.preventDefault();
|
|
9140
9189
|
handleModeChange(activeMode === "draw_rectangle" ? "simple_select" : "draw_rectangle");
|
|
9141
9190
|
break;
|
|
@@ -9158,7 +9207,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
9158
9207
|
};
|
|
9159
9208
|
container.addEventListener("keydown", handleKeyDown);
|
|
9160
9209
|
return () => container.removeEventListener("keydown", handleKeyDown);
|
|
9161
|
-
}, [isMapLoaded, enableKeyboardShortcuts, isEditMode, activeMode, handleToggleEditMode, handleUndo, handleRedo, handleModeChange, selectedFeatureIds, handleDeleteSelected, canDeleteSelected]);
|
|
9210
|
+
}, [isMapLoaded, enableKeyboardShortcuts, isEditMode, activeMode, handleToggleEditMode, handleUndo, handleRedo, handleModeChange, selectedFeatureIds, handleDeleteSelected, canDeleteSelected, hiddenDrawingTools]);
|
|
9162
9211
|
const createPointAtCoords = useCallback((lng, lat) => {
|
|
9163
9212
|
if (!draw.current || !isMapLoaded) return;
|
|
9164
9213
|
if (!isEditModeRef.current) {
|
|
@@ -9190,13 +9239,13 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
9190
9239
|
});
|
|
9191
9240
|
draw.current.changeMode("simple_select", { featureIds: [id] });
|
|
9192
9241
|
setSelectedFeatureIds([id]);
|
|
9193
|
-
setShowProperties(true);
|
|
9242
|
+
if (enableProperties) setShowProperties(true);
|
|
9194
9243
|
updateFeatureCount();
|
|
9195
9244
|
scheduleTimelineUpdate();
|
|
9196
9245
|
saveStateForUndo();
|
|
9197
9246
|
syncFeaturesToCustomLayers();
|
|
9198
9247
|
onFeatureCreate == null ? void 0 : onFeatureCreate(feature);
|
|
9199
|
-
}, [isMapLoaded, externalPersistence, saveStateForUndo, updateFeatureCount, scheduleTimelineUpdate, syncFeaturesToCustomLayers, onFeatureCreate]);
|
|
9248
|
+
}, [isMapLoaded, externalPersistence, enableProperties, saveStateForUndo, updateFeatureCount, scheduleTimelineUpdate, syncFeaturesToCustomLayers, onFeatureCreate]);
|
|
9200
9249
|
const handleFeatureContextMenu = useCallback((e) => {
|
|
9201
9250
|
var _a, _b;
|
|
9202
9251
|
contextMenuFiredRef.current = true;
|
|
@@ -9353,7 +9402,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
9353
9402
|
}
|
|
9354
9403
|
setSelectedFeatureIds([]);
|
|
9355
9404
|
}, [isEditMode]);
|
|
9356
|
-
const handleUpdateProperties = useCallback((featureId, properties) => {
|
|
9405
|
+
const handleUpdateProperties = useCallback((featureId, properties, options) => {
|
|
9357
9406
|
var _a, _b, _c;
|
|
9358
9407
|
if (!map.current) return;
|
|
9359
9408
|
saveStateForUndo();
|
|
@@ -9375,7 +9424,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
9375
9424
|
draw.current.setFeatureProperty(featureId, key, value);
|
|
9376
9425
|
});
|
|
9377
9426
|
const currentUnsaved = (_b = drawFeature.properties) == null ? void 0 : _b._unsaved;
|
|
9378
|
-
if (!externalPersistence && hasRealChange && currentUnsaved !== false) {
|
|
9427
|
+
if (!externalPersistence && hasRealChange && currentUnsaved !== false && !(options == null ? void 0 : options.fromRefresh)) {
|
|
9379
9428
|
draw.current.setFeatureProperty(featureId, "_unsaved", true);
|
|
9380
9429
|
}
|
|
9381
9430
|
if (properties.kind === "text" || ((_c = drawFeature.properties) == null ? void 0 : _c.kind) === "text") {
|
|
@@ -9400,7 +9449,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
9400
9449
|
});
|
|
9401
9450
|
const currentUnsaved = (_a2 = f.properties) == null ? void 0 : _a2._unsaved;
|
|
9402
9451
|
f.properties = { ...f.properties, ...normalizedProperties };
|
|
9403
|
-
if (!externalPersistence && hasRealChange && currentUnsaved !== false) {
|
|
9452
|
+
if (!externalPersistence && hasRealChange && currentUnsaved !== false && !(options == null ? void 0 : options.fromRefresh)) {
|
|
9404
9453
|
f.properties._unsaved = true;
|
|
9405
9454
|
}
|
|
9406
9455
|
if (properties.kind === "text" || ((_b2 = f.properties) == null ? void 0 : _b2.kind) === "text") {
|
|
@@ -9790,8 +9839,15 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
9790
9839
|
const v = (_a = l.layout) == null ? void 0 : _a.visibility;
|
|
9791
9840
|
return v === void 0 || v === "visible";
|
|
9792
9841
|
};
|
|
9842
|
+
const isBasemap = (l) => basemapPrefixes.some((p) => l.id.startsWith(p));
|
|
9843
|
+
let lastBasemapGeometryIdx = -1;
|
|
9844
|
+
allLayers.forEach((l, i) => {
|
|
9845
|
+
if (isBasemap(l) && l.type !== "symbol" && isVisible(l)) {
|
|
9846
|
+
lastBasemapGeometryIdx = i;
|
|
9847
|
+
}
|
|
9848
|
+
});
|
|
9793
9849
|
const firstVisibleBasemapSymbol = allLayers.find(
|
|
9794
|
-
(l) => l.type === "symbol" &&
|
|
9850
|
+
(l, i) => i > lastBasemapGeometryIdx && l.type === "symbol" && isBasemap(l) && isVisible(l)
|
|
9795
9851
|
);
|
|
9796
9852
|
try {
|
|
9797
9853
|
if (firstVisibleBasemapSymbol) {
|
|
@@ -10898,7 +10954,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
10898
10954
|
map.current.getCanvas().style.cursor = "";
|
|
10899
10955
|
}
|
|
10900
10956
|
};
|
|
10901
|
-
}, [activeMode, isMapLoaded, onFeatureCreate]);
|
|
10957
|
+
}, [activeMode, isMapLoaded, onFeatureCreate, enableProperties]);
|
|
10902
10958
|
useEffect(() => {
|
|
10903
10959
|
if (!map.current || !isMapLoaded || !draw.current) return;
|
|
10904
10960
|
if (activeMode !== "draw_rectangle") {
|
|
@@ -10993,7 +11049,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
10993
11049
|
drawInstance.changeMode("simple_select", { featureIds: [featureId] });
|
|
10994
11050
|
setActiveMode("simple_select");
|
|
10995
11051
|
setSelectedFeatureIds([featureId]);
|
|
10996
|
-
setShowProperties(true);
|
|
11052
|
+
if (enableProperties) setShowProperties(true);
|
|
10997
11053
|
if (onFeatureCreate) {
|
|
10998
11054
|
onFeatureCreate(rectFeature);
|
|
10999
11055
|
}
|
|
@@ -11026,7 +11082,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
|
|
|
11026
11082
|
map.current.getCanvas().style.cursor = "";
|
|
11027
11083
|
}
|
|
11028
11084
|
};
|
|
11029
|
-
}, [activeMode, isMapLoaded, onFeatureCreate]);
|
|
11085
|
+
}, [activeMode, isMapLoaded, onFeatureCreate, enableProperties]);
|
|
11030
11086
|
const measurePointsRef = useRef([]);
|
|
11031
11087
|
useEffect(() => {
|
|
11032
11088
|
measurePointsRef.current = measurePoints;
|