@page-speed/maps 0.2.1 → 0.2.3
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/components/geo-map.cjs +58 -25
- package/dist/components/geo-map.cjs.map +1 -1
- package/dist/components/geo-map.js +58 -25
- package/dist/components/geo-map.js.map +1 -1
- package/dist/components/index.cjs +58 -25
- package/dist/components/index.cjs.map +1 -1
- package/dist/components/index.js +58 -25
- package/dist/components/index.js.map +1 -1
- package/dist/index.cjs +58 -25
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +58 -25
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1052,9 +1052,16 @@ function GeoMap({
|
|
|
1052
1052
|
const updateDimensions = () => {
|
|
1053
1053
|
if (containerRef.current) {
|
|
1054
1054
|
const rect = containerRef.current.getBoundingClientRect();
|
|
1055
|
-
setContainerDimensions({
|
|
1056
|
-
|
|
1057
|
-
|
|
1055
|
+
setContainerDimensions((prev) => {
|
|
1056
|
+
const newWidth = rect.width || 800;
|
|
1057
|
+
const newHeight = rect.height || calculatedHeight;
|
|
1058
|
+
if (prev.width === newWidth && prev.height === newHeight) {
|
|
1059
|
+
return prev;
|
|
1060
|
+
}
|
|
1061
|
+
return {
|
|
1062
|
+
width: newWidth,
|
|
1063
|
+
height: newHeight
|
|
1064
|
+
};
|
|
1058
1065
|
});
|
|
1059
1066
|
}
|
|
1060
1067
|
};
|
|
@@ -1191,17 +1198,41 @@ function GeoMap({
|
|
|
1191
1198
|
const [dynamicPanelPosition, setDynamicPanelPosition] = React3__namespace.useState(
|
|
1192
1199
|
panelPosition
|
|
1193
1200
|
);
|
|
1201
|
+
const viewStateRef = React3__namespace.useRef(uncontrolledViewState);
|
|
1194
1202
|
React3__namespace.useEffect(() => {
|
|
1195
1203
|
if (!viewState && !defaultViewState) {
|
|
1196
|
-
setUncontrolledViewState({
|
|
1197
|
-
latitude
|
|
1198
|
-
|
|
1199
|
-
|
|
1204
|
+
setUncontrolledViewState((prev) => {
|
|
1205
|
+
if (prev.latitude === firstCoordinate.latitude && prev.longitude === firstCoordinate.longitude && prev.zoom === calculatedZoom) {
|
|
1206
|
+
return prev;
|
|
1207
|
+
}
|
|
1208
|
+
return {
|
|
1209
|
+
latitude: firstCoordinate.latitude,
|
|
1210
|
+
longitude: firstCoordinate.longitude,
|
|
1211
|
+
zoom: calculatedZoom
|
|
1212
|
+
};
|
|
1200
1213
|
});
|
|
1201
1214
|
}
|
|
1202
|
-
}, [
|
|
1215
|
+
}, [
|
|
1216
|
+
// Use primitive values instead of objects to avoid reference changes
|
|
1217
|
+
firstCoordinate.latitude,
|
|
1218
|
+
firstCoordinate.longitude,
|
|
1219
|
+
calculatedZoom,
|
|
1220
|
+
viewState,
|
|
1221
|
+
defaultViewState
|
|
1222
|
+
]);
|
|
1203
1223
|
const isControlledViewState = viewState !== void 0;
|
|
1204
1224
|
const resolvedViewState = isControlledViewState ? viewState : uncontrolledViewState;
|
|
1225
|
+
React3__namespace.useEffect(() => {
|
|
1226
|
+
viewStateRef.current = resolvedViewState || uncontrolledViewState;
|
|
1227
|
+
}, [
|
|
1228
|
+
// Use primitive values to avoid reference changes
|
|
1229
|
+
resolvedViewState?.latitude,
|
|
1230
|
+
resolvedViewState?.longitude,
|
|
1231
|
+
resolvedViewState?.zoom,
|
|
1232
|
+
uncontrolledViewState.latitude,
|
|
1233
|
+
uncontrolledViewState.longitude,
|
|
1234
|
+
uncontrolledViewState.zoom
|
|
1235
|
+
]);
|
|
1205
1236
|
const applyViewState = React3__namespace.useCallback(
|
|
1206
1237
|
(nextState) => {
|
|
1207
1238
|
if (!isControlledViewState) {
|
|
@@ -1240,7 +1271,13 @@ function GeoMap({
|
|
|
1240
1271
|
setSelection({ type: "none" });
|
|
1241
1272
|
onSelectionChange?.({ type: "none" });
|
|
1242
1273
|
}
|
|
1243
|
-
}, [
|
|
1274
|
+
}, [
|
|
1275
|
+
// Use primitive values to avoid object reference issues
|
|
1276
|
+
selection.type,
|
|
1277
|
+
selection.markerId,
|
|
1278
|
+
selectedMarker?.id,
|
|
1279
|
+
onSelectionChange
|
|
1280
|
+
]);
|
|
1244
1281
|
const emitSelectionChange = React3__namespace.useCallback(
|
|
1245
1282
|
(nextSelection) => {
|
|
1246
1283
|
if (nextSelection.type === "none") {
|
|
@@ -1270,17 +1307,15 @@ function GeoMap({
|
|
|
1270
1307
|
markerId: marker.id,
|
|
1271
1308
|
clusterId: marker.clusterId
|
|
1272
1309
|
});
|
|
1273
|
-
const
|
|
1274
|
-
|
|
1275
|
-
|
|
1310
|
+
const currentState = viewStateRef.current;
|
|
1311
|
+
const center = {
|
|
1312
|
+
latitude: currentState.latitude ?? 0,
|
|
1313
|
+
longitude: currentState.longitude ?? 0
|
|
1276
1314
|
};
|
|
1277
1315
|
const optimalPosition = getOptimalPanelPosition(
|
|
1278
1316
|
marker.latitude,
|
|
1279
1317
|
marker.longitude,
|
|
1280
|
-
|
|
1281
|
-
latitude: currentCenter.latitude ?? firstCoordinate.latitude,
|
|
1282
|
-
longitude: currentCenter.longitude ?? firstCoordinate.longitude
|
|
1283
|
-
}
|
|
1318
|
+
center
|
|
1284
1319
|
);
|
|
1285
1320
|
setDynamicPanelPosition(optimalPosition);
|
|
1286
1321
|
applyViewState({
|
|
@@ -1290,7 +1325,7 @@ function GeoMap({
|
|
|
1290
1325
|
});
|
|
1291
1326
|
emitSelectionChange({ type: "marker", marker });
|
|
1292
1327
|
},
|
|
1293
|
-
[applyViewState, emitSelectionChange, markerFocusZoom
|
|
1328
|
+
[applyViewState, emitSelectionChange, markerFocusZoom]
|
|
1294
1329
|
);
|
|
1295
1330
|
const selectCluster = React3__namespace.useCallback(
|
|
1296
1331
|
(cluster) => {
|
|
@@ -1298,17 +1333,15 @@ function GeoMap({
|
|
|
1298
1333
|
type: "cluster",
|
|
1299
1334
|
clusterId: cluster.id
|
|
1300
1335
|
});
|
|
1301
|
-
const
|
|
1302
|
-
|
|
1303
|
-
|
|
1336
|
+
const currentState = viewStateRef.current;
|
|
1337
|
+
const center = {
|
|
1338
|
+
latitude: currentState.latitude ?? 0,
|
|
1339
|
+
longitude: currentState.longitude ?? 0
|
|
1304
1340
|
};
|
|
1305
1341
|
const optimalPosition = getOptimalPanelPosition(
|
|
1306
1342
|
cluster.latitude,
|
|
1307
1343
|
cluster.longitude,
|
|
1308
|
-
|
|
1309
|
-
latitude: currentCenter.latitude ?? firstCoordinate.latitude,
|
|
1310
|
-
longitude: currentCenter.longitude ?? firstCoordinate.longitude
|
|
1311
|
-
}
|
|
1344
|
+
center
|
|
1312
1345
|
);
|
|
1313
1346
|
setDynamicPanelPosition(optimalPosition);
|
|
1314
1347
|
applyViewState({
|
|
@@ -1318,7 +1351,7 @@ function GeoMap({
|
|
|
1318
1351
|
});
|
|
1319
1352
|
emitSelectionChange({ type: "cluster", cluster });
|
|
1320
1353
|
},
|
|
1321
|
-
[applyViewState, clusterFocusZoom, emitSelectionChange
|
|
1354
|
+
[applyViewState, clusterFocusZoom, emitSelectionChange]
|
|
1322
1355
|
);
|
|
1323
1356
|
const clearSelection = React3__namespace.useCallback(() => {
|
|
1324
1357
|
setSelection({ type: "none" });
|