zenit-sdk 0.0.9 → 0.1.1
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/{chunk-PCTRVN4O.mjs → chunk-OOK4DBG5.mjs} +118 -80
- package/dist/chunk-OOK4DBG5.mjs.map +1 -0
- package/dist/index.js +194 -156
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/react/index.js +194 -156
- package/dist/react/index.js.map +1 -1
- package/dist/react/index.mjs +1 -1
- package/package.json +1 -1
- package/dist/chunk-PCTRVN4O.mjs.map +0 -1
package/dist/react/index.js
CHANGED
|
@@ -58,7 +58,7 @@ __export(react_exports, {
|
|
|
58
58
|
module.exports = __toCommonJS(react_exports);
|
|
59
59
|
|
|
60
60
|
// src/react/ZenitMap.tsx
|
|
61
|
-
var
|
|
61
|
+
var import_react5 = __toESM(require("react"));
|
|
62
62
|
var import_react_leaflet4 = require("react-leaflet");
|
|
63
63
|
var import_leaflet4 = __toESM(require("leaflet"));
|
|
64
64
|
|
|
@@ -293,6 +293,7 @@ function getEffectiveLayerOpacity(baseOpacity, zoom, layerType, geometryType, op
|
|
|
293
293
|
}
|
|
294
294
|
|
|
295
295
|
// src/react/map/layer-geojson.tsx
|
|
296
|
+
var import_react = require("react");
|
|
296
297
|
var import_react_leaflet = require("react-leaflet");
|
|
297
298
|
var import_leaflet = __toESM(require("leaflet"));
|
|
298
299
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
@@ -334,6 +335,44 @@ var LayerGeoJson = ({
|
|
|
334
335
|
const pointFeatures = features.filter(isPointGeometry);
|
|
335
336
|
const fillData = fillFeatures.length > 0 ? buildFeatureCollection(fillFeatures) : null;
|
|
336
337
|
const pointsData = pointFeatures.length > 0 ? buildFeatureCollection(pointFeatures) : null;
|
|
338
|
+
const clusterLayerRef = (0, import_react.useRef)(null);
|
|
339
|
+
const canCluster = typeof import_leaflet.default.markerClusterGroup === "function";
|
|
340
|
+
(0, import_react.useEffect)(() => {
|
|
341
|
+
if (!mapInstance || !panesReady || !pointsData || !canCluster) return;
|
|
342
|
+
const markerClusterGroup = import_leaflet.default.markerClusterGroup;
|
|
343
|
+
const clusterLayer = clusterLayerRef.current ?? markerClusterGroup();
|
|
344
|
+
clusterLayerRef.current = clusterLayer;
|
|
345
|
+
if (!mapInstance.hasLayer(clusterLayer)) {
|
|
346
|
+
mapInstance.addLayer(clusterLayer);
|
|
347
|
+
}
|
|
348
|
+
clusterLayer.clearLayers();
|
|
349
|
+
const geoJsonLayer = import_leaflet.default.geoJSON(pointsData, {
|
|
350
|
+
pointToLayer: (feature, latlng) => import_leaflet.default.circleMarker(latlng, {
|
|
351
|
+
radius: isMobile ? 8 : 6,
|
|
352
|
+
pane: mapInstance.getPane(pointsPaneName) ? pointsPaneName : void 0,
|
|
353
|
+
...styleFn(feature, layerType, baseOpacity)
|
|
354
|
+
}),
|
|
355
|
+
onEachFeature
|
|
356
|
+
});
|
|
357
|
+
clusterLayer.addLayer(geoJsonLayer);
|
|
358
|
+
return () => {
|
|
359
|
+
clusterLayer.clearLayers();
|
|
360
|
+
if (mapInstance.hasLayer(clusterLayer)) {
|
|
361
|
+
mapInstance.removeLayer(clusterLayer);
|
|
362
|
+
}
|
|
363
|
+
};
|
|
364
|
+
}, [
|
|
365
|
+
baseOpacity,
|
|
366
|
+
canCluster,
|
|
367
|
+
isMobile,
|
|
368
|
+
layerType,
|
|
369
|
+
mapInstance,
|
|
370
|
+
onEachFeature,
|
|
371
|
+
panesReady,
|
|
372
|
+
pointsData,
|
|
373
|
+
pointsPaneName,
|
|
374
|
+
styleFn
|
|
375
|
+
]);
|
|
337
376
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
|
338
377
|
fillData && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
339
378
|
import_react_leaflet.GeoJSON,
|
|
@@ -348,7 +387,7 @@ var LayerGeoJson = ({
|
|
|
348
387
|
},
|
|
349
388
|
`fill-${layerId}`
|
|
350
389
|
),
|
|
351
|
-
pointsData && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
390
|
+
pointsData && !canCluster && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
352
391
|
import_react_leaflet.GeoJSON,
|
|
353
392
|
{
|
|
354
393
|
data: pointsData,
|
|
@@ -365,26 +404,26 @@ var LayerGeoJson = ({
|
|
|
365
404
|
};
|
|
366
405
|
|
|
367
406
|
// src/react/map/location-control.tsx
|
|
368
|
-
var
|
|
407
|
+
var import_react3 = require("react");
|
|
369
408
|
var import_react_dom = require("react-dom");
|
|
370
409
|
var import_react_leaflet2 = require("react-leaflet");
|
|
371
410
|
var import_leaflet3 = __toESM(require("leaflet"));
|
|
372
411
|
|
|
373
412
|
// src/react/hooks/use-geolocation.ts
|
|
374
|
-
var
|
|
413
|
+
var import_react2 = require("react");
|
|
375
414
|
function useGeolocation(options) {
|
|
376
|
-
const [isTracking, setIsTracking] = (0,
|
|
377
|
-
const [location, setLocation] = (0,
|
|
378
|
-
const [error, setError] = (0,
|
|
379
|
-
const watchIdRef = (0,
|
|
380
|
-
const stopTracking = (0,
|
|
415
|
+
const [isTracking, setIsTracking] = (0, import_react2.useState)(false);
|
|
416
|
+
const [location, setLocation] = (0, import_react2.useState)(null);
|
|
417
|
+
const [error, setError] = (0, import_react2.useState)(null);
|
|
418
|
+
const watchIdRef = (0, import_react2.useRef)(null);
|
|
419
|
+
const stopTracking = (0, import_react2.useCallback)(() => {
|
|
381
420
|
if (watchIdRef.current !== null && typeof navigator !== "undefined" && navigator.geolocation) {
|
|
382
421
|
navigator.geolocation.clearWatch(watchIdRef.current);
|
|
383
422
|
}
|
|
384
423
|
watchIdRef.current = null;
|
|
385
424
|
setIsTracking(false);
|
|
386
425
|
}, []);
|
|
387
|
-
const startTracking = (0,
|
|
426
|
+
const startTracking = (0, import_react2.useCallback)(() => {
|
|
388
427
|
if (typeof navigator === "undefined" || !navigator.geolocation) {
|
|
389
428
|
setError({ code: 0, message: "La geolocalizaci\xF3n no est\xE1 disponible en este navegador." });
|
|
390
429
|
return;
|
|
@@ -410,15 +449,15 @@ function useGeolocation(options) {
|
|
|
410
449
|
}
|
|
411
450
|
);
|
|
412
451
|
}, [options?.enableHighAccuracy, options?.maximumAge, options?.timeout, stopTracking]);
|
|
413
|
-
const toggleTracking = (0,
|
|
452
|
+
const toggleTracking = (0, import_react2.useCallback)(() => {
|
|
414
453
|
if (isTracking) {
|
|
415
454
|
stopTracking();
|
|
416
455
|
} else {
|
|
417
456
|
startTracking();
|
|
418
457
|
}
|
|
419
458
|
}, [isTracking, startTracking, stopTracking]);
|
|
420
|
-
const clearError = (0,
|
|
421
|
-
(0,
|
|
459
|
+
const clearError = (0, import_react2.useCallback)(() => setError(null), []);
|
|
460
|
+
(0, import_react2.useEffect)(() => {
|
|
422
461
|
return () => {
|
|
423
462
|
stopTracking();
|
|
424
463
|
};
|
|
@@ -845,10 +884,10 @@ var LocateIcon = () => /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("svg", { wi
|
|
|
845
884
|
] });
|
|
846
885
|
var LocationControl = ({ position = "bottomleft", zoom = 16 }) => {
|
|
847
886
|
const map = (0, import_react_leaflet2.useMap)();
|
|
848
|
-
const controlRef = (0,
|
|
849
|
-
const hasCenteredRef = (0,
|
|
887
|
+
const controlRef = (0, import_react3.useRef)(null);
|
|
888
|
+
const hasCenteredRef = (0, import_react3.useRef)(false);
|
|
850
889
|
const { isTracking, location, error, toggleTracking, clearError } = useGeolocation();
|
|
851
|
-
(0,
|
|
890
|
+
(0, import_react3.useEffect)(() => {
|
|
852
891
|
if (typeof document === "undefined") return;
|
|
853
892
|
if (document.getElementById(LOCATION_STYLE_ID)) return;
|
|
854
893
|
const styleTag = document.createElement("style");
|
|
@@ -856,7 +895,7 @@ var LocationControl = ({ position = "bottomleft", zoom = 16 }) => {
|
|
|
856
895
|
styleTag.textContent = LOCATION_STYLES;
|
|
857
896
|
document.head.appendChild(styleTag);
|
|
858
897
|
}, []);
|
|
859
|
-
(0,
|
|
898
|
+
(0, import_react3.useEffect)(() => {
|
|
860
899
|
const control = import_leaflet3.default.control({ position });
|
|
861
900
|
control.onAdd = () => {
|
|
862
901
|
const container = import_leaflet3.default.DomUtil.create("div", "zenit-location-control");
|
|
@@ -870,13 +909,13 @@ var LocationControl = ({ position = "bottomleft", zoom = 16 }) => {
|
|
|
870
909
|
controlRef.current = null;
|
|
871
910
|
};
|
|
872
911
|
}, [map, position]);
|
|
873
|
-
(0,
|
|
912
|
+
(0, import_react3.useEffect)(() => {
|
|
874
913
|
if (!location || !isTracking) return;
|
|
875
914
|
if (hasCenteredRef.current) return;
|
|
876
915
|
hasCenteredRef.current = true;
|
|
877
916
|
map.flyTo([location.lat, location.lon], zoom, { animate: true });
|
|
878
917
|
}, [isTracking, location, map, zoom]);
|
|
879
|
-
const markerIcon = (0,
|
|
918
|
+
const markerIcon = (0, import_react3.useMemo)(() => createLocationIcon(), []);
|
|
880
919
|
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
|
|
881
920
|
controlRef.current && (0, import_react_dom.createPortal)(
|
|
882
921
|
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { children: [
|
|
@@ -917,7 +956,7 @@ var LocationControl = ({ position = "bottomleft", zoom = 16 }) => {
|
|
|
917
956
|
};
|
|
918
957
|
|
|
919
958
|
// src/react/map/map-handlers.tsx
|
|
920
|
-
var
|
|
959
|
+
var import_react4 = require("react");
|
|
921
960
|
var import_react_leaflet3 = require("react-leaflet");
|
|
922
961
|
function computeBBoxFromGeojson(geojson) {
|
|
923
962
|
if (!geojson || !Array.isArray(geojson.features)) return null;
|
|
@@ -965,9 +1004,9 @@ var BBoxZoomHandler = ({
|
|
|
965
1004
|
enabled = true
|
|
966
1005
|
}) => {
|
|
967
1006
|
const map = (0, import_react_leaflet3.useMap)();
|
|
968
|
-
const lastAppliedBBox = (0,
|
|
969
|
-
const lastUserInteracted = (0,
|
|
970
|
-
(0,
|
|
1007
|
+
const lastAppliedBBox = (0, import_react4.useRef)(null);
|
|
1008
|
+
const lastUserInteracted = (0, import_react4.useRef)(false);
|
|
1009
|
+
(0, import_react4.useEffect)(() => {
|
|
971
1010
|
const handleInteraction = () => {
|
|
972
1011
|
lastUserInteracted.current = true;
|
|
973
1012
|
};
|
|
@@ -978,7 +1017,7 @@ var BBoxZoomHandler = ({
|
|
|
978
1017
|
map.off("zoomstart", handleInteraction);
|
|
979
1018
|
};
|
|
980
1019
|
}, [map]);
|
|
981
|
-
(0,
|
|
1020
|
+
(0, import_react4.useEffect)(() => {
|
|
982
1021
|
if (!enabled) return;
|
|
983
1022
|
let resolvedBBox = bbox ?? null;
|
|
984
1023
|
if (!resolvedBBox && geojson) {
|
|
@@ -1006,7 +1045,7 @@ var BBoxZoomHandler = ({
|
|
|
1006
1045
|
};
|
|
1007
1046
|
var ZoomBasedOpacityHandler = ({ onZoomChange }) => {
|
|
1008
1047
|
const map = (0, import_react_leaflet3.useMap)();
|
|
1009
|
-
(0,
|
|
1048
|
+
(0, import_react4.useEffect)(() => {
|
|
1010
1049
|
const handleZoom = () => {
|
|
1011
1050
|
onZoomChange(map.getZoom());
|
|
1012
1051
|
};
|
|
@@ -1020,7 +1059,7 @@ var ZoomBasedOpacityHandler = ({ onZoomChange }) => {
|
|
|
1020
1059
|
};
|
|
1021
1060
|
var MapInstanceBridge = ({ onReady }) => {
|
|
1022
1061
|
const map = (0, import_react_leaflet3.useMap)();
|
|
1023
|
-
(0,
|
|
1062
|
+
(0, import_react4.useEffect)(() => {
|
|
1024
1063
|
onReady(map);
|
|
1025
1064
|
}, [map, onReady]);
|
|
1026
1065
|
return null;
|
|
@@ -1116,7 +1155,7 @@ function normalizeCenterTuple(center) {
|
|
|
1116
1155
|
}
|
|
1117
1156
|
return null;
|
|
1118
1157
|
}
|
|
1119
|
-
var ZenitMap = (0,
|
|
1158
|
+
var ZenitMap = (0, import_react5.forwardRef)(({
|
|
1120
1159
|
client,
|
|
1121
1160
|
mapId,
|
|
1122
1161
|
height = "500px",
|
|
@@ -1141,21 +1180,21 @@ var ZenitMap = (0, import_react4.forwardRef)(({
|
|
|
1141
1180
|
onZoomChange,
|
|
1142
1181
|
onMapReady
|
|
1143
1182
|
}, ref) => {
|
|
1144
|
-
const [map, setMap] = (0,
|
|
1145
|
-
const [layers, setLayers] = (0,
|
|
1146
|
-
const [effectiveStates, setEffectiveStates] = (0,
|
|
1147
|
-
const [loadingMap, setLoadingMap] = (0,
|
|
1148
|
-
const [mapError, setMapError] = (0,
|
|
1149
|
-
const [mapInstance, setMapInstance] = (0,
|
|
1150
|
-
const [panesReady, setPanesReady] = (0,
|
|
1151
|
-
const [currentZoom, setCurrentZoom] = (0,
|
|
1152
|
-
const [isPopupOpen, setIsPopupOpen] = (0,
|
|
1153
|
-
const [isMobile, setIsMobile] = (0,
|
|
1183
|
+
const [map, setMap] = (0, import_react5.useState)(null);
|
|
1184
|
+
const [layers, setLayers] = (0, import_react5.useState)([]);
|
|
1185
|
+
const [effectiveStates, setEffectiveStates] = (0, import_react5.useState)([]);
|
|
1186
|
+
const [loadingMap, setLoadingMap] = (0, import_react5.useState)(false);
|
|
1187
|
+
const [mapError, setMapError] = (0, import_react5.useState)(null);
|
|
1188
|
+
const [mapInstance, setMapInstance] = (0, import_react5.useState)(null);
|
|
1189
|
+
const [panesReady, setPanesReady] = (0, import_react5.useState)(false);
|
|
1190
|
+
const [currentZoom, setCurrentZoom] = (0, import_react5.useState)(initialZoom ?? DEFAULT_ZOOM);
|
|
1191
|
+
const [isPopupOpen, setIsPopupOpen] = (0, import_react5.useState)(false);
|
|
1192
|
+
const [isMobile, setIsMobile] = (0, import_react5.useState)(() => {
|
|
1154
1193
|
if (typeof window === "undefined") return false;
|
|
1155
1194
|
return window.matchMedia("(max-width: 768px)").matches;
|
|
1156
1195
|
});
|
|
1157
|
-
const normalizedLayers = (0,
|
|
1158
|
-
(0,
|
|
1196
|
+
const normalizedLayers = (0, import_react5.useMemo)(() => normalizeMapLayers(map), [map]);
|
|
1197
|
+
(0, import_react5.useEffect)(() => {
|
|
1159
1198
|
if (typeof window === "undefined") return;
|
|
1160
1199
|
const mql = window.matchMedia("(max-width: 768px)");
|
|
1161
1200
|
const onChange = (e) => {
|
|
@@ -1173,17 +1212,17 @@ var ZenitMap = (0, import_react4.forwardRef)(({
|
|
|
1173
1212
|
}
|
|
1174
1213
|
return;
|
|
1175
1214
|
}, []);
|
|
1176
|
-
(0,
|
|
1215
|
+
(0, import_react5.useEffect)(() => {
|
|
1177
1216
|
if (featureInfoMode === "popup") {
|
|
1178
1217
|
ensurePopupStyles();
|
|
1179
1218
|
}
|
|
1180
1219
|
}, [featureInfoMode]);
|
|
1181
|
-
(0,
|
|
1220
|
+
(0, import_react5.useEffect)(() => {
|
|
1182
1221
|
if (featureInfoMode !== "popup") {
|
|
1183
1222
|
setIsPopupOpen(false);
|
|
1184
1223
|
}
|
|
1185
1224
|
}, [featureInfoMode]);
|
|
1186
|
-
(0,
|
|
1225
|
+
(0, import_react5.useEffect)(() => {
|
|
1187
1226
|
if (!mapInstance) return;
|
|
1188
1227
|
const popupPane = mapInstance.getPane("popupPane");
|
|
1189
1228
|
if (popupPane) {
|
|
@@ -1192,7 +1231,7 @@ var ZenitMap = (0, import_react4.forwardRef)(({
|
|
|
1192
1231
|
const labelsPane = mapInstance.getPane(LABELS_PANE_NAME) ?? mapInstance.createPane(LABELS_PANE_NAME);
|
|
1193
1232
|
labelsPane.style.zIndex = "600";
|
|
1194
1233
|
}, [mapInstance]);
|
|
1195
|
-
(0,
|
|
1234
|
+
(0, import_react5.useEffect)(() => {
|
|
1196
1235
|
if (!mapInstance) return;
|
|
1197
1236
|
const handlePopupOpen = () => setIsPopupOpen(true);
|
|
1198
1237
|
const handlePopupClose = () => setIsPopupOpen(false);
|
|
@@ -1203,7 +1242,7 @@ var ZenitMap = (0, import_react4.forwardRef)(({
|
|
|
1203
1242
|
mapInstance.off("popupclose", handlePopupClose);
|
|
1204
1243
|
};
|
|
1205
1244
|
}, [mapInstance]);
|
|
1206
|
-
const layerStyleIndex = (0,
|
|
1245
|
+
const layerStyleIndex = (0, import_react5.useMemo)(() => {
|
|
1207
1246
|
const index = /* @__PURE__ */ new Map();
|
|
1208
1247
|
(map?.mapLayers ?? []).forEach((entry) => {
|
|
1209
1248
|
const layerStyle = entry.layer?.style ?? entry.mapLayer?.layer?.style ?? entry.style ?? null;
|
|
@@ -1214,7 +1253,7 @@ var ZenitMap = (0, import_react4.forwardRef)(({
|
|
|
1214
1253
|
});
|
|
1215
1254
|
return index;
|
|
1216
1255
|
}, [map]);
|
|
1217
|
-
const labelKeyIndex = (0,
|
|
1256
|
+
const labelKeyIndex = (0, import_react5.useMemo)(() => {
|
|
1218
1257
|
const index = /* @__PURE__ */ new Map();
|
|
1219
1258
|
normalizedLayers.forEach((entry) => {
|
|
1220
1259
|
const label = entry.layer?.label ?? entry.mapLayer?.label ?? entry.mapLayer.layerConfig?.label;
|
|
@@ -1224,7 +1263,7 @@ var ZenitMap = (0, import_react4.forwardRef)(({
|
|
|
1224
1263
|
});
|
|
1225
1264
|
return index;
|
|
1226
1265
|
}, [normalizedLayers]);
|
|
1227
|
-
const layerMetaIndex = (0,
|
|
1266
|
+
const layerMetaIndex = (0, import_react5.useMemo)(() => {
|
|
1228
1267
|
const index = /* @__PURE__ */ new Map();
|
|
1229
1268
|
normalizedLayers.forEach((entry) => {
|
|
1230
1269
|
index.set(String(entry.layerId), {
|
|
@@ -1234,7 +1273,7 @@ var ZenitMap = (0, import_react4.forwardRef)(({
|
|
|
1234
1273
|
});
|
|
1235
1274
|
return index;
|
|
1236
1275
|
}, [normalizedLayers]);
|
|
1237
|
-
const overlayStyleFunction = (0,
|
|
1276
|
+
const overlayStyleFunction = (0, import_react5.useMemo)(() => {
|
|
1238
1277
|
return (feature) => {
|
|
1239
1278
|
const featureLayerId = getFeatureLayerId(feature);
|
|
1240
1279
|
const featureStyleOverrides = getFeatureStyleOverrides(feature);
|
|
@@ -1253,15 +1292,15 @@ var ZenitMap = (0, import_react4.forwardRef)(({
|
|
|
1253
1292
|
return defaultOptions;
|
|
1254
1293
|
};
|
|
1255
1294
|
}, [layerStyleIndex, mapLayers, overlayStyle]);
|
|
1256
|
-
const overlayStyleFn = (0,
|
|
1295
|
+
const overlayStyleFn = (0, import_react5.useCallback)(
|
|
1257
1296
|
(feature, _layerType, _baseOpacity) => overlayStyleFunction(feature),
|
|
1258
1297
|
[overlayStyleFunction]
|
|
1259
1298
|
);
|
|
1260
|
-
const [baseStates, setBaseStates] = (0,
|
|
1261
|
-
const [mapOverrides, setMapOverrides] = (0,
|
|
1262
|
-
const [controlOverrides, setControlOverrides] = (0,
|
|
1263
|
-
const [uiOverrides, setUiOverrides] = (0,
|
|
1264
|
-
(0,
|
|
1299
|
+
const [baseStates, setBaseStates] = (0, import_react5.useState)([]);
|
|
1300
|
+
const [mapOverrides, setMapOverrides] = (0, import_react5.useState)([]);
|
|
1301
|
+
const [controlOverrides, setControlOverrides] = (0, import_react5.useState)([]);
|
|
1302
|
+
const [uiOverrides, setUiOverrides] = (0, import_react5.useState)([]);
|
|
1303
|
+
(0, import_react5.useEffect)(() => {
|
|
1265
1304
|
let isMounted = true;
|
|
1266
1305
|
setLoadingMap(true);
|
|
1267
1306
|
setMapError(null);
|
|
@@ -1284,7 +1323,7 @@ var ZenitMap = (0, import_react4.forwardRef)(({
|
|
|
1284
1323
|
isMounted = false;
|
|
1285
1324
|
};
|
|
1286
1325
|
}, [client.maps, mapId, onError, onLoadingChange]);
|
|
1287
|
-
(0,
|
|
1326
|
+
(0, import_react5.useEffect)(() => {
|
|
1288
1327
|
if (normalizedLayers.length === 0) {
|
|
1289
1328
|
setLayers([]);
|
|
1290
1329
|
setBaseStates([]);
|
|
@@ -1315,7 +1354,7 @@ var ZenitMap = (0, import_react4.forwardRef)(({
|
|
|
1315
1354
|
setMapOverrides(initialOverrides);
|
|
1316
1355
|
setUiOverrides([]);
|
|
1317
1356
|
}, [normalizedLayers]);
|
|
1318
|
-
(0,
|
|
1357
|
+
(0, import_react5.useEffect)(() => {
|
|
1319
1358
|
if (!layerControls) {
|
|
1320
1359
|
setControlOverrides([]);
|
|
1321
1360
|
return;
|
|
@@ -1327,7 +1366,7 @@ var ZenitMap = (0, import_react4.forwardRef)(({
|
|
|
1327
1366
|
}));
|
|
1328
1367
|
setControlOverrides(overrides);
|
|
1329
1368
|
}, [layerControls]);
|
|
1330
|
-
(0,
|
|
1369
|
+
(0, import_react5.useEffect)(() => {
|
|
1331
1370
|
if (layerStates) {
|
|
1332
1371
|
return;
|
|
1333
1372
|
}
|
|
@@ -1337,12 +1376,12 @@ var ZenitMap = (0, import_react4.forwardRef)(({
|
|
|
1337
1376
|
onLayerStateChange?.(reset);
|
|
1338
1377
|
}
|
|
1339
1378
|
}, [baseStates, effectiveStates.length, layerControls, layerStates, onLayerStateChange]);
|
|
1340
|
-
(0,
|
|
1379
|
+
(0, import_react5.useEffect)(() => {
|
|
1341
1380
|
if (layerStates) {
|
|
1342
1381
|
setEffectiveStates(layerStates);
|
|
1343
1382
|
}
|
|
1344
1383
|
}, [layerStates]);
|
|
1345
|
-
(0,
|
|
1384
|
+
(0, import_react5.useEffect)(() => {
|
|
1346
1385
|
if (layerStates) {
|
|
1347
1386
|
return;
|
|
1348
1387
|
}
|
|
@@ -1355,11 +1394,11 @@ var ZenitMap = (0, import_react4.forwardRef)(({
|
|
|
1355
1394
|
setEffectiveStates(next);
|
|
1356
1395
|
onLayerStateChange?.(next);
|
|
1357
1396
|
}, [baseStates, controlOverrides, layerStates, mapOverrides, onLayerStateChange, uiOverrides]);
|
|
1358
|
-
(0,
|
|
1397
|
+
(0, import_react5.useEffect)(() => {
|
|
1359
1398
|
if (!Array.isArray(layerControls) || layerControls.length > 0) return;
|
|
1360
1399
|
setUiOverrides([]);
|
|
1361
1400
|
}, [layerControls]);
|
|
1362
|
-
(0,
|
|
1401
|
+
(0, import_react5.useEffect)(() => {
|
|
1363
1402
|
if (layerStates) {
|
|
1364
1403
|
return;
|
|
1365
1404
|
}
|
|
@@ -1379,7 +1418,7 @@ var ZenitMap = (0, import_react4.forwardRef)(({
|
|
|
1379
1418
|
return [...filtered, nextEntry];
|
|
1380
1419
|
});
|
|
1381
1420
|
};
|
|
1382
|
-
const updateOpacityFromUi = (0,
|
|
1421
|
+
const updateOpacityFromUi = (0, import_react5.useCallback)(
|
|
1383
1422
|
(layerId, uiOpacity) => {
|
|
1384
1423
|
const meta = layerMetaIndex.get(String(layerId));
|
|
1385
1424
|
const baseOpacity = clampOpacity3(uiOpacity);
|
|
@@ -1418,7 +1457,7 @@ var ZenitMap = (0, import_react4.forwardRef)(({
|
|
|
1418
1457
|
},
|
|
1419
1458
|
[currentZoom, effectiveStates, layerMetaIndex, layerStates, onLayerStateChange]
|
|
1420
1459
|
);
|
|
1421
|
-
const center = (0,
|
|
1460
|
+
const center = (0, import_react5.useMemo)(() => {
|
|
1422
1461
|
if (initialCenter) {
|
|
1423
1462
|
return initialCenter;
|
|
1424
1463
|
}
|
|
@@ -1429,30 +1468,30 @@ var ZenitMap = (0, import_react4.forwardRef)(({
|
|
|
1429
1468
|
return DEFAULT_CENTER;
|
|
1430
1469
|
}, [initialCenter, map?.settings?.center]);
|
|
1431
1470
|
const zoom = initialZoom ?? map?.settings?.zoom ?? DEFAULT_ZOOM;
|
|
1432
|
-
(0,
|
|
1471
|
+
(0, import_react5.useEffect)(() => {
|
|
1433
1472
|
setCurrentZoom(zoom);
|
|
1434
1473
|
}, [zoom]);
|
|
1435
|
-
const decoratedLayers = (0,
|
|
1474
|
+
const decoratedLayers = (0, import_react5.useMemo)(() => {
|
|
1436
1475
|
return layers.map((layer) => ({
|
|
1437
1476
|
...layer,
|
|
1438
1477
|
effective: effectiveStates.find((state) => state.layerId === layer.mapLayer.layerId),
|
|
1439
1478
|
data: layerGeojson?.[layer.mapLayer.layerId] ?? layerGeojson?.[String(layer.mapLayer.layerId)] ?? null
|
|
1440
1479
|
}));
|
|
1441
1480
|
}, [effectiveStates, layerGeojson, layers]);
|
|
1442
|
-
const orderedLayers = (0,
|
|
1481
|
+
const orderedLayers = (0, import_react5.useMemo)(() => {
|
|
1443
1482
|
return [...decoratedLayers].filter((layer) => layer.effective?.visible && layer.data).sort((a, b) => a.displayOrder - b.displayOrder);
|
|
1444
1483
|
}, [decoratedLayers]);
|
|
1445
|
-
const autoZoomGeojson = (0,
|
|
1484
|
+
const autoZoomGeojson = (0, import_react5.useMemo)(
|
|
1446
1485
|
() => orderedLayers.map((layer) => layer.data).filter((collection) => !!collection),
|
|
1447
1486
|
[orderedLayers]
|
|
1448
1487
|
);
|
|
1449
|
-
const resolveLayerStyle = (0,
|
|
1488
|
+
const resolveLayerStyle = (0, import_react5.useCallback)(
|
|
1450
1489
|
(layerId) => {
|
|
1451
1490
|
return getStyleByLayerId(layerId, mapLayers) ?? layerStyleIndex.get(String(layerId)) ?? null;
|
|
1452
1491
|
},
|
|
1453
1492
|
[layerStyleIndex, mapLayers]
|
|
1454
1493
|
);
|
|
1455
|
-
const labelMarkers = (0,
|
|
1494
|
+
const labelMarkers = (0, import_react5.useMemo)(() => {
|
|
1456
1495
|
const markers = [];
|
|
1457
1496
|
decoratedLayers.forEach((layerState) => {
|
|
1458
1497
|
if (!layerState.effective?.visible) return;
|
|
@@ -1489,7 +1528,7 @@ var ZenitMap = (0, import_react4.forwardRef)(({
|
|
|
1489
1528
|
});
|
|
1490
1529
|
return markers;
|
|
1491
1530
|
}, [currentZoom, decoratedLayers, labelKeyIndex, layerMetaIndex, resolveLayerStyle]);
|
|
1492
|
-
const ensureLayerPanes = (0,
|
|
1531
|
+
const ensureLayerPanes = (0, import_react5.useCallback)(
|
|
1493
1532
|
(targetMap, targetLayers) => {
|
|
1494
1533
|
const baseZIndex = 400;
|
|
1495
1534
|
targetLayers.forEach((layer) => {
|
|
@@ -1505,7 +1544,7 @@ var ZenitMap = (0, import_react4.forwardRef)(({
|
|
|
1505
1544
|
},
|
|
1506
1545
|
[]
|
|
1507
1546
|
);
|
|
1508
|
-
const handleMapReady = (0,
|
|
1547
|
+
const handleMapReady = (0, import_react5.useCallback)(
|
|
1509
1548
|
(instance) => {
|
|
1510
1549
|
setPanesReady(false);
|
|
1511
1550
|
setMapInstance(instance);
|
|
@@ -1513,7 +1552,7 @@ var ZenitMap = (0, import_react4.forwardRef)(({
|
|
|
1513
1552
|
},
|
|
1514
1553
|
[onMapReady]
|
|
1515
1554
|
);
|
|
1516
|
-
(0,
|
|
1555
|
+
(0, import_react5.useEffect)(() => {
|
|
1517
1556
|
if (!mapInstance) {
|
|
1518
1557
|
setPanesReady(false);
|
|
1519
1558
|
return;
|
|
@@ -1533,7 +1572,7 @@ var ZenitMap = (0, import_react4.forwardRef)(({
|
|
|
1533
1572
|
setPanesReady(true);
|
|
1534
1573
|
}
|
|
1535
1574
|
}, [mapInstance, orderedLayers, ensureLayerPanes]);
|
|
1536
|
-
const overlayOnEachFeature = (0,
|
|
1575
|
+
const overlayOnEachFeature = (0, import_react5.useMemo)(() => {
|
|
1537
1576
|
return (feature, layer) => {
|
|
1538
1577
|
const layerId = getFeatureLayerId(feature) ?? void 0;
|
|
1539
1578
|
const geometryType = feature?.geometry?.type;
|
|
@@ -1644,7 +1683,7 @@ var ZenitMap = (0, import_react4.forwardRef)(({
|
|
|
1644
1683
|
return buildLayerStyle(layerId, baseOpacity ?? 1, feature, layerType);
|
|
1645
1684
|
};
|
|
1646
1685
|
};
|
|
1647
|
-
(0,
|
|
1686
|
+
(0, import_react5.useImperativeHandle)(ref, () => ({
|
|
1648
1687
|
setLayerOpacity: (layerId, opacity) => {
|
|
1649
1688
|
upsertUiOverride(layerId, { overrideOpacity: opacity });
|
|
1650
1689
|
},
|
|
@@ -1761,7 +1800,7 @@ var ZenitMap = (0, import_react4.forwardRef)(({
|
|
|
1761
1800
|
const pointsPaneName = `zenit-layer-${layerState.mapLayer.layerId}-points`;
|
|
1762
1801
|
const layerType = layerState.layer?.layerType ?? layerState.mapLayer.layerType ?? void 0;
|
|
1763
1802
|
const labelKey = labelKeyIndex.get(String(layerState.mapLayer.layerId));
|
|
1764
|
-
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
1803
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_react5.default.Fragment, { children: [
|
|
1765
1804
|
layerState.data && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
1766
1805
|
LayerGeoJson,
|
|
1767
1806
|
{
|
|
@@ -1918,7 +1957,7 @@ var ZenitMap = (0, import_react4.forwardRef)(({
|
|
|
1918
1957
|
ZenitMap.displayName = "ZenitMap";
|
|
1919
1958
|
|
|
1920
1959
|
// src/react/ZenitLayerManager.tsx
|
|
1921
|
-
var
|
|
1960
|
+
var import_react6 = __toESM(require("react"));
|
|
1922
1961
|
|
|
1923
1962
|
// src/react/icons.tsx
|
|
1924
1963
|
var import_lucide_react = require("lucide-react");
|
|
@@ -1964,15 +2003,15 @@ var ZenitLayerManager = ({
|
|
|
1964
2003
|
layerFeatureCounts,
|
|
1965
2004
|
mapLayers
|
|
1966
2005
|
}) => {
|
|
1967
|
-
const [map, setMap] = (0,
|
|
1968
|
-
const [loadingMap, setLoadingMap] = (0,
|
|
1969
|
-
const [mapError, setMapError] = (0,
|
|
1970
|
-
const [layers, setLayers] = (0,
|
|
1971
|
-
const [activeTab, setActiveTab] = (0,
|
|
1972
|
-
const [panelVisible, setPanelVisible] = (0,
|
|
1973
|
-
const lastEmittedStatesRef = (0,
|
|
2006
|
+
const [map, setMap] = (0, import_react6.useState)(null);
|
|
2007
|
+
const [loadingMap, setLoadingMap] = (0, import_react6.useState)(false);
|
|
2008
|
+
const [mapError, setMapError] = (0, import_react6.useState)(null);
|
|
2009
|
+
const [layers, setLayers] = (0, import_react6.useState)([]);
|
|
2010
|
+
const [activeTab, setActiveTab] = (0, import_react6.useState)("layers");
|
|
2011
|
+
const [panelVisible, setPanelVisible] = (0, import_react6.useState)(true);
|
|
2012
|
+
const lastEmittedStatesRef = (0, import_react6.useRef)(null);
|
|
1974
2013
|
const isControlled = Array.isArray(layerStates) && typeof onLayerStatesChange === "function";
|
|
1975
|
-
const baseStates = (0,
|
|
2014
|
+
const baseStates = (0, import_react6.useMemo)(
|
|
1976
2015
|
() => initLayerStates(
|
|
1977
2016
|
layers.map((entry) => ({
|
|
1978
2017
|
...entry.mapLayer,
|
|
@@ -1983,7 +2022,7 @@ var ZenitLayerManager = ({
|
|
|
1983
2022
|
),
|
|
1984
2023
|
[layers]
|
|
1985
2024
|
);
|
|
1986
|
-
const overrideStates = (0,
|
|
2025
|
+
const overrideStates = (0, import_react6.useMemo)(
|
|
1987
2026
|
() => layers.map(
|
|
1988
2027
|
(entry) => ({
|
|
1989
2028
|
layerId: entry.mapLayer.layerId,
|
|
@@ -1993,11 +2032,11 @@ var ZenitLayerManager = ({
|
|
|
1993
2032
|
),
|
|
1994
2033
|
[layers]
|
|
1995
2034
|
);
|
|
1996
|
-
const effectiveStates = (0,
|
|
2035
|
+
const effectiveStates = (0, import_react6.useMemo)(
|
|
1997
2036
|
() => layerStates ?? applyLayerOverrides(baseStates, overrideStates),
|
|
1998
2037
|
[baseStates, layerStates, overrideStates]
|
|
1999
2038
|
);
|
|
2000
|
-
const layerMetaIndex = (0,
|
|
2039
|
+
const layerMetaIndex = (0, import_react6.useMemo)(() => {
|
|
2001
2040
|
const index = /* @__PURE__ */ new Map();
|
|
2002
2041
|
mapLayers?.forEach((entry) => {
|
|
2003
2042
|
const key = String(entry.layerId);
|
|
@@ -2011,7 +2050,7 @@ var ZenitLayerManager = ({
|
|
|
2011
2050
|
});
|
|
2012
2051
|
return index;
|
|
2013
2052
|
}, [map, mapLayers]);
|
|
2014
|
-
const resolveUserOpacity =
|
|
2053
|
+
const resolveUserOpacity = import_react6.default.useCallback((state) => {
|
|
2015
2054
|
if (typeof state.overrideOpacity === "number") return state.overrideOpacity;
|
|
2016
2055
|
if (typeof state.overrideOpacity === "string") {
|
|
2017
2056
|
const parsed = Number.parseFloat(state.overrideOpacity);
|
|
@@ -2019,7 +2058,7 @@ var ZenitLayerManager = ({
|
|
|
2019
2058
|
}
|
|
2020
2059
|
return state.opacity ?? 1;
|
|
2021
2060
|
}, []);
|
|
2022
|
-
const resolveEffectiveOpacity =
|
|
2061
|
+
const resolveEffectiveOpacity = import_react6.default.useCallback(
|
|
2023
2062
|
(layerId, userOpacity) => {
|
|
2024
2063
|
if (!autoOpacityOnZoom || typeof mapZoom !== "number") {
|
|
2025
2064
|
return userOpacity;
|
|
@@ -2035,7 +2074,7 @@ var ZenitLayerManager = ({
|
|
|
2035
2074
|
},
|
|
2036
2075
|
[autoOpacityConfig, autoOpacityOnZoom, layerMetaIndex, mapZoom]
|
|
2037
2076
|
);
|
|
2038
|
-
const effectiveStatesWithZoom = (0,
|
|
2077
|
+
const effectiveStatesWithZoom = (0, import_react6.useMemo)(() => {
|
|
2039
2078
|
if (!autoOpacityOnZoom || typeof mapZoom !== "number") {
|
|
2040
2079
|
return effectiveStates;
|
|
2041
2080
|
}
|
|
@@ -2049,7 +2088,7 @@ var ZenitLayerManager = ({
|
|
|
2049
2088
|
};
|
|
2050
2089
|
});
|
|
2051
2090
|
}, [autoOpacityOnZoom, effectiveStates, mapZoom, resolveEffectiveOpacity, resolveUserOpacity]);
|
|
2052
|
-
(0,
|
|
2091
|
+
(0, import_react6.useEffect)(() => {
|
|
2053
2092
|
let cancelled = false;
|
|
2054
2093
|
setLoadingMap(true);
|
|
2055
2094
|
setMapError(null);
|
|
@@ -2081,12 +2120,12 @@ var ZenitLayerManager = ({
|
|
|
2081
2120
|
cancelled = true;
|
|
2082
2121
|
};
|
|
2083
2122
|
}, [client.maps, mapId]);
|
|
2084
|
-
(0,
|
|
2123
|
+
(0, import_react6.useEffect)(() => {
|
|
2085
2124
|
if (!showUploadTab && activeTab === "upload") {
|
|
2086
2125
|
setActiveTab("layers");
|
|
2087
2126
|
}
|
|
2088
2127
|
}, [activeTab, showUploadTab]);
|
|
2089
|
-
(0,
|
|
2128
|
+
(0, import_react6.useEffect)(() => {
|
|
2090
2129
|
if (isControlled) return;
|
|
2091
2130
|
if (!onLayerStatesChange) return;
|
|
2092
2131
|
const emitStates = autoOpacityOnZoom && typeof mapZoom === "number" ? effectiveStatesWithZoom : effectiveStates;
|
|
@@ -2104,7 +2143,7 @@ var ZenitLayerManager = ({
|
|
|
2104
2143
|
mapZoom,
|
|
2105
2144
|
onLayerStatesChange
|
|
2106
2145
|
]);
|
|
2107
|
-
const updateLayerVisible =
|
|
2146
|
+
const updateLayerVisible = import_react6.default.useCallback(
|
|
2108
2147
|
(layerId, visible) => {
|
|
2109
2148
|
if (!onLayerStatesChange) return;
|
|
2110
2149
|
const next = effectiveStates.map(
|
|
@@ -2114,7 +2153,7 @@ var ZenitLayerManager = ({
|
|
|
2114
2153
|
},
|
|
2115
2154
|
[effectiveStates, onLayerStatesChange]
|
|
2116
2155
|
);
|
|
2117
|
-
const updateLayerOpacity =
|
|
2156
|
+
const updateLayerOpacity = import_react6.default.useCallback(
|
|
2118
2157
|
(layerId, opacity) => {
|
|
2119
2158
|
if (!onLayerStatesChange) return;
|
|
2120
2159
|
const adjustedOpacity = resolveEffectiveOpacity(layerId, opacity);
|
|
@@ -2125,7 +2164,7 @@ var ZenitLayerManager = ({
|
|
|
2125
2164
|
},
|
|
2126
2165
|
[effectiveStates, onLayerStatesChange, resolveEffectiveOpacity]
|
|
2127
2166
|
);
|
|
2128
|
-
const resolveFeatureCount =
|
|
2167
|
+
const resolveFeatureCount = import_react6.default.useCallback(
|
|
2129
2168
|
(layerId, layer) => {
|
|
2130
2169
|
const resolvedFeatureCount = layerFeatureCounts?.[layerId] ?? layerFeatureCounts?.[String(layerId)];
|
|
2131
2170
|
if (typeof resolvedFeatureCount === "number") return resolvedFeatureCount;
|
|
@@ -2134,7 +2173,7 @@ var ZenitLayerManager = ({
|
|
|
2134
2173
|
},
|
|
2135
2174
|
[layerFeatureCounts]
|
|
2136
2175
|
);
|
|
2137
|
-
const decoratedLayers = (0,
|
|
2176
|
+
const decoratedLayers = (0, import_react6.useMemo)(() => {
|
|
2138
2177
|
return layers.map((entry) => ({
|
|
2139
2178
|
...entry,
|
|
2140
2179
|
effective: effectiveStates.find((state) => state.layerId === entry.mapLayer.layerId),
|
|
@@ -2163,7 +2202,7 @@ var ZenitLayerManager = ({
|
|
|
2163
2202
|
return String(a.mapLayer.layerId).localeCompare(String(b.mapLayer.layerId));
|
|
2164
2203
|
});
|
|
2165
2204
|
}, [effectiveStates, layers, resolveFeatureCount]);
|
|
2166
|
-
const resolveLayerStyle =
|
|
2205
|
+
const resolveLayerStyle = import_react6.default.useCallback(
|
|
2167
2206
|
(layerId) => {
|
|
2168
2207
|
const layerKey = String(layerId);
|
|
2169
2208
|
const fromProp = mapLayers?.find((entry) => String(entry.layerId) === layerKey)?.style;
|
|
@@ -2546,11 +2585,11 @@ var ZenitFeatureFilterPanel = ({
|
|
|
2546
2585
|
};
|
|
2547
2586
|
|
|
2548
2587
|
// src/react/ai/FloatingChatBox.tsx
|
|
2549
|
-
var
|
|
2588
|
+
var import_react8 = require("react");
|
|
2550
2589
|
var import_react_dom2 = require("react-dom");
|
|
2551
2590
|
|
|
2552
2591
|
// src/react/hooks/use-chat.ts
|
|
2553
|
-
var
|
|
2592
|
+
var import_react7 = require("react");
|
|
2554
2593
|
|
|
2555
2594
|
// src/ai/chat.service.ts
|
|
2556
2595
|
var DEFAULT_ERROR_MESSAGE = "No fue posible completar la solicitud al asistente.";
|
|
@@ -2682,9 +2721,9 @@ var sendMessageStream = async (mapId, request, callbacks = {}, options, config)
|
|
|
2682
2721
|
|
|
2683
2722
|
// src/react/hooks/use-chat.ts
|
|
2684
2723
|
var useSendMessage = (config) => {
|
|
2685
|
-
const [isLoading, setIsLoading] = (0,
|
|
2686
|
-
const [error, setError] = (0,
|
|
2687
|
-
const send = (0,
|
|
2724
|
+
const [isLoading, setIsLoading] = (0, import_react7.useState)(false);
|
|
2725
|
+
const [error, setError] = (0, import_react7.useState)(null);
|
|
2726
|
+
const send = (0, import_react7.useCallback)(
|
|
2688
2727
|
async (mapId, request, options) => {
|
|
2689
2728
|
setIsLoading(true);
|
|
2690
2729
|
setError(null);
|
|
@@ -2702,18 +2741,18 @@ var useSendMessage = (config) => {
|
|
|
2702
2741
|
return { sendMessage: send, isLoading, error };
|
|
2703
2742
|
};
|
|
2704
2743
|
var useSendMessageStream = (config) => {
|
|
2705
|
-
const [isStreaming, setIsStreaming] = (0,
|
|
2706
|
-
const [streamingText, setStreamingText] = (0,
|
|
2707
|
-
const [completeResponse, setCompleteResponse] = (0,
|
|
2708
|
-
const [error, setError] = (0,
|
|
2709
|
-
const requestIdRef = (0,
|
|
2710
|
-
const reset = (0,
|
|
2744
|
+
const [isStreaming, setIsStreaming] = (0, import_react7.useState)(false);
|
|
2745
|
+
const [streamingText, setStreamingText] = (0, import_react7.useState)("");
|
|
2746
|
+
const [completeResponse, setCompleteResponse] = (0, import_react7.useState)(null);
|
|
2747
|
+
const [error, setError] = (0, import_react7.useState)(null);
|
|
2748
|
+
const requestIdRef = (0, import_react7.useRef)(0);
|
|
2749
|
+
const reset = (0, import_react7.useCallback)(() => {
|
|
2711
2750
|
setIsStreaming(false);
|
|
2712
2751
|
setStreamingText("");
|
|
2713
2752
|
setCompleteResponse(null);
|
|
2714
2753
|
setError(null);
|
|
2715
2754
|
}, []);
|
|
2716
|
-
const send = (0,
|
|
2755
|
+
const send = (0, import_react7.useCallback)(
|
|
2717
2756
|
async (mapId, request, options) => {
|
|
2718
2757
|
const requestId = requestIdRef.current + 1;
|
|
2719
2758
|
requestIdRef.current = requestId;
|
|
@@ -3004,6 +3043,17 @@ var styles = {
|
|
|
3004
3043
|
width: 480,
|
|
3005
3044
|
height: 640
|
|
3006
3045
|
},
|
|
3046
|
+
panelMobileFullscreen: {
|
|
3047
|
+
position: "fixed",
|
|
3048
|
+
top: 0,
|
|
3049
|
+
left: 0,
|
|
3050
|
+
right: 0,
|
|
3051
|
+
bottom: 0,
|
|
3052
|
+
width: "100%",
|
|
3053
|
+
height: "100%",
|
|
3054
|
+
borderRadius: 0,
|
|
3055
|
+
margin: 0
|
|
3056
|
+
},
|
|
3007
3057
|
// Header with green gradient
|
|
3008
3058
|
header: {
|
|
3009
3059
|
padding: "14px 16px",
|
|
@@ -3237,42 +3287,42 @@ var FloatingChatBox = ({
|
|
|
3237
3287
|
open: openProp
|
|
3238
3288
|
}) => {
|
|
3239
3289
|
const isControlled = openProp !== void 0;
|
|
3240
|
-
const [internalOpen, setInternalOpen] = (0,
|
|
3290
|
+
const [internalOpen, setInternalOpen] = (0, import_react8.useState)(false);
|
|
3241
3291
|
const open = isControlled ? openProp : internalOpen;
|
|
3242
|
-
const setOpen = (0,
|
|
3292
|
+
const setOpen = (0, import_react8.useCallback)((value) => {
|
|
3243
3293
|
const newValue = typeof value === "function" ? value(open) : value;
|
|
3244
3294
|
if (!isControlled) {
|
|
3245
3295
|
setInternalOpen(newValue);
|
|
3246
3296
|
}
|
|
3247
3297
|
onOpenChange?.(newValue);
|
|
3248
3298
|
}, [isControlled, open, onOpenChange]);
|
|
3249
|
-
const [expanded, setExpanded] = (0,
|
|
3250
|
-
const [messages, setMessages] = (0,
|
|
3251
|
-
const [inputValue, setInputValue] = (0,
|
|
3252
|
-
const [conversationId, setConversationId] = (0,
|
|
3253
|
-
const [errorMessage, setErrorMessage] = (0,
|
|
3254
|
-
const [isFocused, setIsFocused] = (0,
|
|
3255
|
-
const [isMobile, setIsMobile] = (0,
|
|
3256
|
-
const messagesEndRef = (0,
|
|
3257
|
-
const messagesContainerRef = (0,
|
|
3258
|
-
const chatBoxRef = (0,
|
|
3259
|
-
const chatConfig = (0,
|
|
3299
|
+
const [expanded, setExpanded] = (0, import_react8.useState)(false);
|
|
3300
|
+
const [messages, setMessages] = (0, import_react8.useState)([]);
|
|
3301
|
+
const [inputValue, setInputValue] = (0, import_react8.useState)("");
|
|
3302
|
+
const [conversationId, setConversationId] = (0, import_react8.useState)();
|
|
3303
|
+
const [errorMessage, setErrorMessage] = (0, import_react8.useState)(null);
|
|
3304
|
+
const [isFocused, setIsFocused] = (0, import_react8.useState)(false);
|
|
3305
|
+
const [isMobile, setIsMobile] = (0, import_react8.useState)(false);
|
|
3306
|
+
const messagesEndRef = (0, import_react8.useRef)(null);
|
|
3307
|
+
const messagesContainerRef = (0, import_react8.useRef)(null);
|
|
3308
|
+
const chatBoxRef = (0, import_react8.useRef)(null);
|
|
3309
|
+
const chatConfig = (0, import_react8.useMemo)(() => {
|
|
3260
3310
|
if (!baseUrl) return void 0;
|
|
3261
3311
|
return { baseUrl, accessToken, getAccessToken };
|
|
3262
3312
|
}, [accessToken, baseUrl, getAccessToken]);
|
|
3263
3313
|
const { sendMessage: sendMessage2, isStreaming, streamingText, completeResponse } = useSendMessageStream(chatConfig);
|
|
3264
3314
|
const canSend = Boolean(mapId) && Boolean(baseUrl) && inputValue.trim().length > 0 && !isStreaming;
|
|
3265
|
-
(0,
|
|
3315
|
+
(0, import_react8.useEffect)(() => {
|
|
3266
3316
|
if (open && isMobile) {
|
|
3267
3317
|
setExpanded(true);
|
|
3268
3318
|
}
|
|
3269
3319
|
}, [open, isMobile]);
|
|
3270
|
-
const scrollToBottom = (0,
|
|
3320
|
+
const scrollToBottom = (0, import_react8.useCallback)(() => {
|
|
3271
3321
|
if (messagesEndRef.current) {
|
|
3272
3322
|
messagesEndRef.current.scrollIntoView({ behavior: "smooth" });
|
|
3273
3323
|
}
|
|
3274
3324
|
}, []);
|
|
3275
|
-
(0,
|
|
3325
|
+
(0, import_react8.useEffect)(() => {
|
|
3276
3326
|
if (open && messages.length === 0) {
|
|
3277
3327
|
setMessages([
|
|
3278
3328
|
{
|
|
@@ -3283,10 +3333,10 @@ var FloatingChatBox = ({
|
|
|
3283
3333
|
]);
|
|
3284
3334
|
}
|
|
3285
3335
|
}, [open, messages.length]);
|
|
3286
|
-
(0,
|
|
3336
|
+
(0, import_react8.useEffect)(() => {
|
|
3287
3337
|
scrollToBottom();
|
|
3288
3338
|
}, [messages, streamingText, scrollToBottom]);
|
|
3289
|
-
(0,
|
|
3339
|
+
(0, import_react8.useEffect)(() => {
|
|
3290
3340
|
if (!open) return;
|
|
3291
3341
|
if (isMobile && expanded) return;
|
|
3292
3342
|
const handleClickOutside = (event) => {
|
|
@@ -3299,7 +3349,7 @@ var FloatingChatBox = ({
|
|
|
3299
3349
|
document.removeEventListener("mousedown", handleClickOutside);
|
|
3300
3350
|
};
|
|
3301
3351
|
}, [open, isMobile, expanded]);
|
|
3302
|
-
(0,
|
|
3352
|
+
(0, import_react8.useEffect)(() => {
|
|
3303
3353
|
if (typeof window === "undefined") return;
|
|
3304
3354
|
const mediaQuery = window.matchMedia("(max-width: 768px)");
|
|
3305
3355
|
const updateMobile = () => setIsMobile(mediaQuery.matches);
|
|
@@ -3317,7 +3367,7 @@ var FloatingChatBox = ({
|
|
|
3317
3367
|
}
|
|
3318
3368
|
};
|
|
3319
3369
|
}, []);
|
|
3320
|
-
(0,
|
|
3370
|
+
(0, import_react8.useEffect)(() => {
|
|
3321
3371
|
if (typeof document === "undefined") return;
|
|
3322
3372
|
if (!open || !isMobile) return;
|
|
3323
3373
|
document.body.style.overflow = "hidden";
|
|
@@ -3325,10 +3375,10 @@ var FloatingChatBox = ({
|
|
|
3325
3375
|
document.body.style.overflow = "";
|
|
3326
3376
|
};
|
|
3327
3377
|
}, [open, isMobile]);
|
|
3328
|
-
const addMessage = (0,
|
|
3378
|
+
const addMessage = (0, import_react8.useCallback)((message) => {
|
|
3329
3379
|
setMessages((prev) => [...prev, message]);
|
|
3330
3380
|
}, []);
|
|
3331
|
-
const handleSend = (0,
|
|
3381
|
+
const handleSend = (0, import_react8.useCallback)(async () => {
|
|
3332
3382
|
if (!mapId) {
|
|
3333
3383
|
setErrorMessage("Selecciona un mapa para usar el asistente.");
|
|
3334
3384
|
return;
|
|
@@ -3381,7 +3431,7 @@ var FloatingChatBox = ({
|
|
|
3381
3431
|
sendMessage2,
|
|
3382
3432
|
userId
|
|
3383
3433
|
]);
|
|
3384
|
-
const handleKeyDown = (0,
|
|
3434
|
+
const handleKeyDown = (0, import_react8.useCallback)(
|
|
3385
3435
|
(event) => {
|
|
3386
3436
|
if (event.key === "Enter" && !event.shiftKey) {
|
|
3387
3437
|
event.preventDefault();
|
|
@@ -3392,7 +3442,7 @@ var FloatingChatBox = ({
|
|
|
3392
3442
|
},
|
|
3393
3443
|
[canSend, handleSend]
|
|
3394
3444
|
);
|
|
3395
|
-
const handleFollowUpClick = (0,
|
|
3445
|
+
const handleFollowUpClick = (0, import_react8.useCallback)((question) => {
|
|
3396
3446
|
setInputValue(question);
|
|
3397
3447
|
}, []);
|
|
3398
3448
|
const renderMetadata = (response) => {
|
|
@@ -3414,7 +3464,7 @@ var FloatingChatBox = ({
|
|
|
3414
3464
|
] }, index)) })
|
|
3415
3465
|
] });
|
|
3416
3466
|
};
|
|
3417
|
-
const handleActionClick = (0,
|
|
3467
|
+
const handleActionClick = (0, import_react8.useCallback)((action) => {
|
|
3418
3468
|
if (isStreaming) return;
|
|
3419
3469
|
setOpen(false);
|
|
3420
3470
|
requestAnimationFrame(() => {
|
|
@@ -3529,22 +3579,6 @@ var FloatingChatBox = ({
|
|
|
3529
3579
|
box-sizing: border-box;
|
|
3530
3580
|
}
|
|
3531
3581
|
@media (max-width: 768px) {
|
|
3532
|
-
.zenit-chat-panel.zenit-chat-panel--fullscreen {
|
|
3533
|
-
position: fixed !important;
|
|
3534
|
-
left: 0 !important;
|
|
3535
|
-
right: 0 !important;
|
|
3536
|
-
top: 4rem !important;
|
|
3537
|
-
bottom: 0 !important;
|
|
3538
|
-
width: 100% !important;
|
|
3539
|
-
max-width: 100% !important;
|
|
3540
|
-
height: auto !important;
|
|
3541
|
-
border-radius: 0 !important;
|
|
3542
|
-
display: flex !important;
|
|
3543
|
-
flex-direction: column !important;
|
|
3544
|
-
overflow: hidden !important;
|
|
3545
|
-
z-index: 100000 !important;
|
|
3546
|
-
padding-top: env(safe-area-inset-top);
|
|
3547
|
-
}
|
|
3548
3582
|
.zenit-chat-panel.zenit-chat-panel--fullscreen .zenit-ai-body {
|
|
3549
3583
|
flex: 1;
|
|
3550
3584
|
min-height: 0;
|
|
@@ -3564,16 +3598,20 @@ var FloatingChatBox = ({
|
|
|
3564
3598
|
"div",
|
|
3565
3599
|
{
|
|
3566
3600
|
ref: chatBoxRef,
|
|
3567
|
-
className: `zenit-chat-panel${expanded ? " zenit-chat-panel--expanded" : ""}${isMobile ? " zenit-chat-panel--fullscreen" : ""}`,
|
|
3568
|
-
style: {
|
|
3569
|
-
|
|
3570
|
-
|
|
3571
|
-
|
|
3601
|
+
className: `zenit-chat-panel${expanded && !isMobile ? " zenit-chat-panel--expanded" : ""}${isMobile ? " zenit-chat-panel--fullscreen" : ""}`,
|
|
3602
|
+
style: (() => {
|
|
3603
|
+
const desktopStyle = expanded ? styles.panelExpanded : styles.panelNormal;
|
|
3604
|
+
const mobileStyle = styles.panelMobileFullscreen;
|
|
3605
|
+
return {
|
|
3606
|
+
...styles.panel,
|
|
3607
|
+
...isMobile ? mobileStyle : desktopStyle
|
|
3608
|
+
};
|
|
3609
|
+
})(),
|
|
3572
3610
|
children: [
|
|
3573
3611
|
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("header", { style: styles.header, children: [
|
|
3574
3612
|
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("h3", { style: styles.title, children: "Asistente Zenit AI" }),
|
|
3575
3613
|
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { style: styles.headerButtons, children: [
|
|
3576
|
-
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
3614
|
+
!isMobile && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
3577
3615
|
"button",
|
|
3578
3616
|
{
|
|
3579
3617
|
type: "button",
|