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/index.js
CHANGED
|
@@ -1521,7 +1521,7 @@ function normalizeBbox(input) {
|
|
|
1521
1521
|
}
|
|
1522
1522
|
|
|
1523
1523
|
// src/react/ZenitMap.tsx
|
|
1524
|
-
var
|
|
1524
|
+
var import_react5 = __toESM(require("react"));
|
|
1525
1525
|
var import_react_leaflet4 = require("react-leaflet");
|
|
1526
1526
|
var import_leaflet4 = __toESM(require("leaflet"));
|
|
1527
1527
|
|
|
@@ -1585,6 +1585,7 @@ function getEffectiveLayerOpacity(baseOpacity, zoom, layerType, geometryType, op
|
|
|
1585
1585
|
}
|
|
1586
1586
|
|
|
1587
1587
|
// src/react/map/layer-geojson.tsx
|
|
1588
|
+
var import_react = require("react");
|
|
1588
1589
|
var import_react_leaflet = require("react-leaflet");
|
|
1589
1590
|
var import_leaflet = __toESM(require("leaflet"));
|
|
1590
1591
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
@@ -1626,6 +1627,44 @@ var LayerGeoJson = ({
|
|
|
1626
1627
|
const pointFeatures = features.filter(isPointGeometry);
|
|
1627
1628
|
const fillData = fillFeatures.length > 0 ? buildFeatureCollection(fillFeatures) : null;
|
|
1628
1629
|
const pointsData = pointFeatures.length > 0 ? buildFeatureCollection(pointFeatures) : null;
|
|
1630
|
+
const clusterLayerRef = (0, import_react.useRef)(null);
|
|
1631
|
+
const canCluster = typeof import_leaflet.default.markerClusterGroup === "function";
|
|
1632
|
+
(0, import_react.useEffect)(() => {
|
|
1633
|
+
if (!mapInstance || !panesReady || !pointsData || !canCluster) return;
|
|
1634
|
+
const markerClusterGroup = import_leaflet.default.markerClusterGroup;
|
|
1635
|
+
const clusterLayer = clusterLayerRef.current ?? markerClusterGroup();
|
|
1636
|
+
clusterLayerRef.current = clusterLayer;
|
|
1637
|
+
if (!mapInstance.hasLayer(clusterLayer)) {
|
|
1638
|
+
mapInstance.addLayer(clusterLayer);
|
|
1639
|
+
}
|
|
1640
|
+
clusterLayer.clearLayers();
|
|
1641
|
+
const geoJsonLayer = import_leaflet.default.geoJSON(pointsData, {
|
|
1642
|
+
pointToLayer: (feature, latlng) => import_leaflet.default.circleMarker(latlng, {
|
|
1643
|
+
radius: isMobile ? 8 : 6,
|
|
1644
|
+
pane: mapInstance.getPane(pointsPaneName) ? pointsPaneName : void 0,
|
|
1645
|
+
...styleFn(feature, layerType, baseOpacity)
|
|
1646
|
+
}),
|
|
1647
|
+
onEachFeature
|
|
1648
|
+
});
|
|
1649
|
+
clusterLayer.addLayer(geoJsonLayer);
|
|
1650
|
+
return () => {
|
|
1651
|
+
clusterLayer.clearLayers();
|
|
1652
|
+
if (mapInstance.hasLayer(clusterLayer)) {
|
|
1653
|
+
mapInstance.removeLayer(clusterLayer);
|
|
1654
|
+
}
|
|
1655
|
+
};
|
|
1656
|
+
}, [
|
|
1657
|
+
baseOpacity,
|
|
1658
|
+
canCluster,
|
|
1659
|
+
isMobile,
|
|
1660
|
+
layerType,
|
|
1661
|
+
mapInstance,
|
|
1662
|
+
onEachFeature,
|
|
1663
|
+
panesReady,
|
|
1664
|
+
pointsData,
|
|
1665
|
+
pointsPaneName,
|
|
1666
|
+
styleFn
|
|
1667
|
+
]);
|
|
1629
1668
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
|
1630
1669
|
fillData && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
1631
1670
|
import_react_leaflet.GeoJSON,
|
|
@@ -1640,7 +1679,7 @@ var LayerGeoJson = ({
|
|
|
1640
1679
|
},
|
|
1641
1680
|
`fill-${layerId}`
|
|
1642
1681
|
),
|
|
1643
|
-
pointsData && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
1682
|
+
pointsData && !canCluster && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
1644
1683
|
import_react_leaflet.GeoJSON,
|
|
1645
1684
|
{
|
|
1646
1685
|
data: pointsData,
|
|
@@ -1657,26 +1696,26 @@ var LayerGeoJson = ({
|
|
|
1657
1696
|
};
|
|
1658
1697
|
|
|
1659
1698
|
// src/react/map/location-control.tsx
|
|
1660
|
-
var
|
|
1699
|
+
var import_react3 = require("react");
|
|
1661
1700
|
var import_react_dom = require("react-dom");
|
|
1662
1701
|
var import_react_leaflet2 = require("react-leaflet");
|
|
1663
1702
|
var import_leaflet3 = __toESM(require("leaflet"));
|
|
1664
1703
|
|
|
1665
1704
|
// src/react/hooks/use-geolocation.ts
|
|
1666
|
-
var
|
|
1705
|
+
var import_react2 = require("react");
|
|
1667
1706
|
function useGeolocation(options) {
|
|
1668
|
-
const [isTracking, setIsTracking] = (0,
|
|
1669
|
-
const [location, setLocation] = (0,
|
|
1670
|
-
const [error, setError] = (0,
|
|
1671
|
-
const watchIdRef = (0,
|
|
1672
|
-
const stopTracking = (0,
|
|
1707
|
+
const [isTracking, setIsTracking] = (0, import_react2.useState)(false);
|
|
1708
|
+
const [location, setLocation] = (0, import_react2.useState)(null);
|
|
1709
|
+
const [error, setError] = (0, import_react2.useState)(null);
|
|
1710
|
+
const watchIdRef = (0, import_react2.useRef)(null);
|
|
1711
|
+
const stopTracking = (0, import_react2.useCallback)(() => {
|
|
1673
1712
|
if (watchIdRef.current !== null && typeof navigator !== "undefined" && navigator.geolocation) {
|
|
1674
1713
|
navigator.geolocation.clearWatch(watchIdRef.current);
|
|
1675
1714
|
}
|
|
1676
1715
|
watchIdRef.current = null;
|
|
1677
1716
|
setIsTracking(false);
|
|
1678
1717
|
}, []);
|
|
1679
|
-
const startTracking = (0,
|
|
1718
|
+
const startTracking = (0, import_react2.useCallback)(() => {
|
|
1680
1719
|
if (typeof navigator === "undefined" || !navigator.geolocation) {
|
|
1681
1720
|
setError({ code: 0, message: "La geolocalizaci\xF3n no est\xE1 disponible en este navegador." });
|
|
1682
1721
|
return;
|
|
@@ -1702,15 +1741,15 @@ function useGeolocation(options) {
|
|
|
1702
1741
|
}
|
|
1703
1742
|
);
|
|
1704
1743
|
}, [options?.enableHighAccuracy, options?.maximumAge, options?.timeout, stopTracking]);
|
|
1705
|
-
const toggleTracking = (0,
|
|
1744
|
+
const toggleTracking = (0, import_react2.useCallback)(() => {
|
|
1706
1745
|
if (isTracking) {
|
|
1707
1746
|
stopTracking();
|
|
1708
1747
|
} else {
|
|
1709
1748
|
startTracking();
|
|
1710
1749
|
}
|
|
1711
1750
|
}, [isTracking, startTracking, stopTracking]);
|
|
1712
|
-
const clearError = (0,
|
|
1713
|
-
(0,
|
|
1751
|
+
const clearError = (0, import_react2.useCallback)(() => setError(null), []);
|
|
1752
|
+
(0, import_react2.useEffect)(() => {
|
|
1714
1753
|
return () => {
|
|
1715
1754
|
stopTracking();
|
|
1716
1755
|
};
|
|
@@ -2137,10 +2176,10 @@ var LocateIcon = () => /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("svg", { wi
|
|
|
2137
2176
|
] });
|
|
2138
2177
|
var LocationControl = ({ position = "bottomleft", zoom = 16 }) => {
|
|
2139
2178
|
const map = (0, import_react_leaflet2.useMap)();
|
|
2140
|
-
const controlRef = (0,
|
|
2141
|
-
const hasCenteredRef = (0,
|
|
2179
|
+
const controlRef = (0, import_react3.useRef)(null);
|
|
2180
|
+
const hasCenteredRef = (0, import_react3.useRef)(false);
|
|
2142
2181
|
const { isTracking, location, error, toggleTracking, clearError } = useGeolocation();
|
|
2143
|
-
(0,
|
|
2182
|
+
(0, import_react3.useEffect)(() => {
|
|
2144
2183
|
if (typeof document === "undefined") return;
|
|
2145
2184
|
if (document.getElementById(LOCATION_STYLE_ID)) return;
|
|
2146
2185
|
const styleTag = document.createElement("style");
|
|
@@ -2148,7 +2187,7 @@ var LocationControl = ({ position = "bottomleft", zoom = 16 }) => {
|
|
|
2148
2187
|
styleTag.textContent = LOCATION_STYLES;
|
|
2149
2188
|
document.head.appendChild(styleTag);
|
|
2150
2189
|
}, []);
|
|
2151
|
-
(0,
|
|
2190
|
+
(0, import_react3.useEffect)(() => {
|
|
2152
2191
|
const control = import_leaflet3.default.control({ position });
|
|
2153
2192
|
control.onAdd = () => {
|
|
2154
2193
|
const container = import_leaflet3.default.DomUtil.create("div", "zenit-location-control");
|
|
@@ -2162,13 +2201,13 @@ var LocationControl = ({ position = "bottomleft", zoom = 16 }) => {
|
|
|
2162
2201
|
controlRef.current = null;
|
|
2163
2202
|
};
|
|
2164
2203
|
}, [map, position]);
|
|
2165
|
-
(0,
|
|
2204
|
+
(0, import_react3.useEffect)(() => {
|
|
2166
2205
|
if (!location || !isTracking) return;
|
|
2167
2206
|
if (hasCenteredRef.current) return;
|
|
2168
2207
|
hasCenteredRef.current = true;
|
|
2169
2208
|
map.flyTo([location.lat, location.lon], zoom, { animate: true });
|
|
2170
2209
|
}, [isTracking, location, map, zoom]);
|
|
2171
|
-
const markerIcon = (0,
|
|
2210
|
+
const markerIcon = (0, import_react3.useMemo)(() => createLocationIcon(), []);
|
|
2172
2211
|
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
|
|
2173
2212
|
controlRef.current && (0, import_react_dom.createPortal)(
|
|
2174
2213
|
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { children: [
|
|
@@ -2209,7 +2248,7 @@ var LocationControl = ({ position = "bottomleft", zoom = 16 }) => {
|
|
|
2209
2248
|
};
|
|
2210
2249
|
|
|
2211
2250
|
// src/react/map/map-handlers.tsx
|
|
2212
|
-
var
|
|
2251
|
+
var import_react4 = require("react");
|
|
2213
2252
|
var import_react_leaflet3 = require("react-leaflet");
|
|
2214
2253
|
function computeBBoxFromGeojson(geojson) {
|
|
2215
2254
|
if (!geojson || !Array.isArray(geojson.features)) return null;
|
|
@@ -2257,9 +2296,9 @@ var BBoxZoomHandler = ({
|
|
|
2257
2296
|
enabled = true
|
|
2258
2297
|
}) => {
|
|
2259
2298
|
const map = (0, import_react_leaflet3.useMap)();
|
|
2260
|
-
const lastAppliedBBox = (0,
|
|
2261
|
-
const lastUserInteracted = (0,
|
|
2262
|
-
(0,
|
|
2299
|
+
const lastAppliedBBox = (0, import_react4.useRef)(null);
|
|
2300
|
+
const lastUserInteracted = (0, import_react4.useRef)(false);
|
|
2301
|
+
(0, import_react4.useEffect)(() => {
|
|
2263
2302
|
const handleInteraction = () => {
|
|
2264
2303
|
lastUserInteracted.current = true;
|
|
2265
2304
|
};
|
|
@@ -2270,7 +2309,7 @@ var BBoxZoomHandler = ({
|
|
|
2270
2309
|
map.off("zoomstart", handleInteraction);
|
|
2271
2310
|
};
|
|
2272
2311
|
}, [map]);
|
|
2273
|
-
(0,
|
|
2312
|
+
(0, import_react4.useEffect)(() => {
|
|
2274
2313
|
if (!enabled) return;
|
|
2275
2314
|
let resolvedBBox = bbox ?? null;
|
|
2276
2315
|
if (!resolvedBBox && geojson) {
|
|
@@ -2298,7 +2337,7 @@ var BBoxZoomHandler = ({
|
|
|
2298
2337
|
};
|
|
2299
2338
|
var ZoomBasedOpacityHandler = ({ onZoomChange }) => {
|
|
2300
2339
|
const map = (0, import_react_leaflet3.useMap)();
|
|
2301
|
-
(0,
|
|
2340
|
+
(0, import_react4.useEffect)(() => {
|
|
2302
2341
|
const handleZoom = () => {
|
|
2303
2342
|
onZoomChange(map.getZoom());
|
|
2304
2343
|
};
|
|
@@ -2312,7 +2351,7 @@ var ZoomBasedOpacityHandler = ({ onZoomChange }) => {
|
|
|
2312
2351
|
};
|
|
2313
2352
|
var MapInstanceBridge = ({ onReady }) => {
|
|
2314
2353
|
const map = (0, import_react_leaflet3.useMap)();
|
|
2315
|
-
(0,
|
|
2354
|
+
(0, import_react4.useEffect)(() => {
|
|
2316
2355
|
onReady(map);
|
|
2317
2356
|
}, [map, onReady]);
|
|
2318
2357
|
return null;
|
|
@@ -2408,7 +2447,7 @@ function normalizeCenterTuple(center) {
|
|
|
2408
2447
|
}
|
|
2409
2448
|
return null;
|
|
2410
2449
|
}
|
|
2411
|
-
var ZenitMap = (0,
|
|
2450
|
+
var ZenitMap = (0, import_react5.forwardRef)(({
|
|
2412
2451
|
client,
|
|
2413
2452
|
mapId,
|
|
2414
2453
|
height = "500px",
|
|
@@ -2433,21 +2472,21 @@ var ZenitMap = (0, import_react4.forwardRef)(({
|
|
|
2433
2472
|
onZoomChange,
|
|
2434
2473
|
onMapReady
|
|
2435
2474
|
}, ref) => {
|
|
2436
|
-
const [map, setMap] = (0,
|
|
2437
|
-
const [layers, setLayers] = (0,
|
|
2438
|
-
const [effectiveStates, setEffectiveStates] = (0,
|
|
2439
|
-
const [loadingMap, setLoadingMap] = (0,
|
|
2440
|
-
const [mapError, setMapError] = (0,
|
|
2441
|
-
const [mapInstance, setMapInstance] = (0,
|
|
2442
|
-
const [panesReady, setPanesReady] = (0,
|
|
2443
|
-
const [currentZoom, setCurrentZoom] = (0,
|
|
2444
|
-
const [isPopupOpen, setIsPopupOpen] = (0,
|
|
2445
|
-
const [isMobile, setIsMobile] = (0,
|
|
2475
|
+
const [map, setMap] = (0, import_react5.useState)(null);
|
|
2476
|
+
const [layers, setLayers] = (0, import_react5.useState)([]);
|
|
2477
|
+
const [effectiveStates, setEffectiveStates] = (0, import_react5.useState)([]);
|
|
2478
|
+
const [loadingMap, setLoadingMap] = (0, import_react5.useState)(false);
|
|
2479
|
+
const [mapError, setMapError] = (0, import_react5.useState)(null);
|
|
2480
|
+
const [mapInstance, setMapInstance] = (0, import_react5.useState)(null);
|
|
2481
|
+
const [panesReady, setPanesReady] = (0, import_react5.useState)(false);
|
|
2482
|
+
const [currentZoom, setCurrentZoom] = (0, import_react5.useState)(initialZoom ?? DEFAULT_ZOOM);
|
|
2483
|
+
const [isPopupOpen, setIsPopupOpen] = (0, import_react5.useState)(false);
|
|
2484
|
+
const [isMobile, setIsMobile] = (0, import_react5.useState)(() => {
|
|
2446
2485
|
if (typeof window === "undefined") return false;
|
|
2447
2486
|
return window.matchMedia("(max-width: 768px)").matches;
|
|
2448
2487
|
});
|
|
2449
|
-
const normalizedLayers = (0,
|
|
2450
|
-
(0,
|
|
2488
|
+
const normalizedLayers = (0, import_react5.useMemo)(() => normalizeMapLayers(map), [map]);
|
|
2489
|
+
(0, import_react5.useEffect)(() => {
|
|
2451
2490
|
if (typeof window === "undefined") return;
|
|
2452
2491
|
const mql = window.matchMedia("(max-width: 768px)");
|
|
2453
2492
|
const onChange = (e) => {
|
|
@@ -2465,17 +2504,17 @@ var ZenitMap = (0, import_react4.forwardRef)(({
|
|
|
2465
2504
|
}
|
|
2466
2505
|
return;
|
|
2467
2506
|
}, []);
|
|
2468
|
-
(0,
|
|
2507
|
+
(0, import_react5.useEffect)(() => {
|
|
2469
2508
|
if (featureInfoMode === "popup") {
|
|
2470
2509
|
ensurePopupStyles();
|
|
2471
2510
|
}
|
|
2472
2511
|
}, [featureInfoMode]);
|
|
2473
|
-
(0,
|
|
2512
|
+
(0, import_react5.useEffect)(() => {
|
|
2474
2513
|
if (featureInfoMode !== "popup") {
|
|
2475
2514
|
setIsPopupOpen(false);
|
|
2476
2515
|
}
|
|
2477
2516
|
}, [featureInfoMode]);
|
|
2478
|
-
(0,
|
|
2517
|
+
(0, import_react5.useEffect)(() => {
|
|
2479
2518
|
if (!mapInstance) return;
|
|
2480
2519
|
const popupPane = mapInstance.getPane("popupPane");
|
|
2481
2520
|
if (popupPane) {
|
|
@@ -2484,7 +2523,7 @@ var ZenitMap = (0, import_react4.forwardRef)(({
|
|
|
2484
2523
|
const labelsPane = mapInstance.getPane(LABELS_PANE_NAME) ?? mapInstance.createPane(LABELS_PANE_NAME);
|
|
2485
2524
|
labelsPane.style.zIndex = "600";
|
|
2486
2525
|
}, [mapInstance]);
|
|
2487
|
-
(0,
|
|
2526
|
+
(0, import_react5.useEffect)(() => {
|
|
2488
2527
|
if (!mapInstance) return;
|
|
2489
2528
|
const handlePopupOpen = () => setIsPopupOpen(true);
|
|
2490
2529
|
const handlePopupClose = () => setIsPopupOpen(false);
|
|
@@ -2495,7 +2534,7 @@ var ZenitMap = (0, import_react4.forwardRef)(({
|
|
|
2495
2534
|
mapInstance.off("popupclose", handlePopupClose);
|
|
2496
2535
|
};
|
|
2497
2536
|
}, [mapInstance]);
|
|
2498
|
-
const layerStyleIndex = (0,
|
|
2537
|
+
const layerStyleIndex = (0, import_react5.useMemo)(() => {
|
|
2499
2538
|
const index = /* @__PURE__ */ new Map();
|
|
2500
2539
|
(map?.mapLayers ?? []).forEach((entry) => {
|
|
2501
2540
|
const layerStyle = entry.layer?.style ?? entry.mapLayer?.layer?.style ?? entry.style ?? null;
|
|
@@ -2506,7 +2545,7 @@ var ZenitMap = (0, import_react4.forwardRef)(({
|
|
|
2506
2545
|
});
|
|
2507
2546
|
return index;
|
|
2508
2547
|
}, [map]);
|
|
2509
|
-
const labelKeyIndex = (0,
|
|
2548
|
+
const labelKeyIndex = (0, import_react5.useMemo)(() => {
|
|
2510
2549
|
const index = /* @__PURE__ */ new Map();
|
|
2511
2550
|
normalizedLayers.forEach((entry) => {
|
|
2512
2551
|
const label = entry.layer?.label ?? entry.mapLayer?.label ?? entry.mapLayer.layerConfig?.label;
|
|
@@ -2516,7 +2555,7 @@ var ZenitMap = (0, import_react4.forwardRef)(({
|
|
|
2516
2555
|
});
|
|
2517
2556
|
return index;
|
|
2518
2557
|
}, [normalizedLayers]);
|
|
2519
|
-
const layerMetaIndex = (0,
|
|
2558
|
+
const layerMetaIndex = (0, import_react5.useMemo)(() => {
|
|
2520
2559
|
const index = /* @__PURE__ */ new Map();
|
|
2521
2560
|
normalizedLayers.forEach((entry) => {
|
|
2522
2561
|
index.set(String(entry.layerId), {
|
|
@@ -2526,7 +2565,7 @@ var ZenitMap = (0, import_react4.forwardRef)(({
|
|
|
2526
2565
|
});
|
|
2527
2566
|
return index;
|
|
2528
2567
|
}, [normalizedLayers]);
|
|
2529
|
-
const overlayStyleFunction = (0,
|
|
2568
|
+
const overlayStyleFunction = (0, import_react5.useMemo)(() => {
|
|
2530
2569
|
return (feature) => {
|
|
2531
2570
|
const featureLayerId = getFeatureLayerId(feature);
|
|
2532
2571
|
const featureStyleOverrides = getFeatureStyleOverrides(feature);
|
|
@@ -2545,15 +2584,15 @@ var ZenitMap = (0, import_react4.forwardRef)(({
|
|
|
2545
2584
|
return defaultOptions;
|
|
2546
2585
|
};
|
|
2547
2586
|
}, [layerStyleIndex, mapLayers, overlayStyle]);
|
|
2548
|
-
const overlayStyleFn = (0,
|
|
2587
|
+
const overlayStyleFn = (0, import_react5.useCallback)(
|
|
2549
2588
|
(feature, _layerType, _baseOpacity) => overlayStyleFunction(feature),
|
|
2550
2589
|
[overlayStyleFunction]
|
|
2551
2590
|
);
|
|
2552
|
-
const [baseStates, setBaseStates] = (0,
|
|
2553
|
-
const [mapOverrides, setMapOverrides] = (0,
|
|
2554
|
-
const [controlOverrides, setControlOverrides] = (0,
|
|
2555
|
-
const [uiOverrides, setUiOverrides] = (0,
|
|
2556
|
-
(0,
|
|
2591
|
+
const [baseStates, setBaseStates] = (0, import_react5.useState)([]);
|
|
2592
|
+
const [mapOverrides, setMapOverrides] = (0, import_react5.useState)([]);
|
|
2593
|
+
const [controlOverrides, setControlOverrides] = (0, import_react5.useState)([]);
|
|
2594
|
+
const [uiOverrides, setUiOverrides] = (0, import_react5.useState)([]);
|
|
2595
|
+
(0, import_react5.useEffect)(() => {
|
|
2557
2596
|
let isMounted = true;
|
|
2558
2597
|
setLoadingMap(true);
|
|
2559
2598
|
setMapError(null);
|
|
@@ -2576,7 +2615,7 @@ var ZenitMap = (0, import_react4.forwardRef)(({
|
|
|
2576
2615
|
isMounted = false;
|
|
2577
2616
|
};
|
|
2578
2617
|
}, [client.maps, mapId, onError, onLoadingChange]);
|
|
2579
|
-
(0,
|
|
2618
|
+
(0, import_react5.useEffect)(() => {
|
|
2580
2619
|
if (normalizedLayers.length === 0) {
|
|
2581
2620
|
setLayers([]);
|
|
2582
2621
|
setBaseStates([]);
|
|
@@ -2607,7 +2646,7 @@ var ZenitMap = (0, import_react4.forwardRef)(({
|
|
|
2607
2646
|
setMapOverrides(initialOverrides);
|
|
2608
2647
|
setUiOverrides([]);
|
|
2609
2648
|
}, [normalizedLayers]);
|
|
2610
|
-
(0,
|
|
2649
|
+
(0, import_react5.useEffect)(() => {
|
|
2611
2650
|
if (!layerControls) {
|
|
2612
2651
|
setControlOverrides([]);
|
|
2613
2652
|
return;
|
|
@@ -2619,7 +2658,7 @@ var ZenitMap = (0, import_react4.forwardRef)(({
|
|
|
2619
2658
|
}));
|
|
2620
2659
|
setControlOverrides(overrides);
|
|
2621
2660
|
}, [layerControls]);
|
|
2622
|
-
(0,
|
|
2661
|
+
(0, import_react5.useEffect)(() => {
|
|
2623
2662
|
if (layerStates) {
|
|
2624
2663
|
return;
|
|
2625
2664
|
}
|
|
@@ -2629,12 +2668,12 @@ var ZenitMap = (0, import_react4.forwardRef)(({
|
|
|
2629
2668
|
onLayerStateChange?.(reset);
|
|
2630
2669
|
}
|
|
2631
2670
|
}, [baseStates, effectiveStates.length, layerControls, layerStates, onLayerStateChange]);
|
|
2632
|
-
(0,
|
|
2671
|
+
(0, import_react5.useEffect)(() => {
|
|
2633
2672
|
if (layerStates) {
|
|
2634
2673
|
setEffectiveStates(layerStates);
|
|
2635
2674
|
}
|
|
2636
2675
|
}, [layerStates]);
|
|
2637
|
-
(0,
|
|
2676
|
+
(0, import_react5.useEffect)(() => {
|
|
2638
2677
|
if (layerStates) {
|
|
2639
2678
|
return;
|
|
2640
2679
|
}
|
|
@@ -2647,11 +2686,11 @@ var ZenitMap = (0, import_react4.forwardRef)(({
|
|
|
2647
2686
|
setEffectiveStates(next);
|
|
2648
2687
|
onLayerStateChange?.(next);
|
|
2649
2688
|
}, [baseStates, controlOverrides, layerStates, mapOverrides, onLayerStateChange, uiOverrides]);
|
|
2650
|
-
(0,
|
|
2689
|
+
(0, import_react5.useEffect)(() => {
|
|
2651
2690
|
if (!Array.isArray(layerControls) || layerControls.length > 0) return;
|
|
2652
2691
|
setUiOverrides([]);
|
|
2653
2692
|
}, [layerControls]);
|
|
2654
|
-
(0,
|
|
2693
|
+
(0, import_react5.useEffect)(() => {
|
|
2655
2694
|
if (layerStates) {
|
|
2656
2695
|
return;
|
|
2657
2696
|
}
|
|
@@ -2671,7 +2710,7 @@ var ZenitMap = (0, import_react4.forwardRef)(({
|
|
|
2671
2710
|
return [...filtered, nextEntry];
|
|
2672
2711
|
});
|
|
2673
2712
|
};
|
|
2674
|
-
const updateOpacityFromUi = (0,
|
|
2713
|
+
const updateOpacityFromUi = (0, import_react5.useCallback)(
|
|
2675
2714
|
(layerId, uiOpacity) => {
|
|
2676
2715
|
const meta = layerMetaIndex.get(String(layerId));
|
|
2677
2716
|
const baseOpacity = clampOpacity3(uiOpacity);
|
|
@@ -2710,7 +2749,7 @@ var ZenitMap = (0, import_react4.forwardRef)(({
|
|
|
2710
2749
|
},
|
|
2711
2750
|
[currentZoom, effectiveStates, layerMetaIndex, layerStates, onLayerStateChange]
|
|
2712
2751
|
);
|
|
2713
|
-
const center = (0,
|
|
2752
|
+
const center = (0, import_react5.useMemo)(() => {
|
|
2714
2753
|
if (initialCenter) {
|
|
2715
2754
|
return initialCenter;
|
|
2716
2755
|
}
|
|
@@ -2721,30 +2760,30 @@ var ZenitMap = (0, import_react4.forwardRef)(({
|
|
|
2721
2760
|
return DEFAULT_CENTER;
|
|
2722
2761
|
}, [initialCenter, map?.settings?.center]);
|
|
2723
2762
|
const zoom = initialZoom ?? map?.settings?.zoom ?? DEFAULT_ZOOM;
|
|
2724
|
-
(0,
|
|
2763
|
+
(0, import_react5.useEffect)(() => {
|
|
2725
2764
|
setCurrentZoom(zoom);
|
|
2726
2765
|
}, [zoom]);
|
|
2727
|
-
const decoratedLayers = (0,
|
|
2766
|
+
const decoratedLayers = (0, import_react5.useMemo)(() => {
|
|
2728
2767
|
return layers.map((layer) => ({
|
|
2729
2768
|
...layer,
|
|
2730
2769
|
effective: effectiveStates.find((state) => state.layerId === layer.mapLayer.layerId),
|
|
2731
2770
|
data: layerGeojson?.[layer.mapLayer.layerId] ?? layerGeojson?.[String(layer.mapLayer.layerId)] ?? null
|
|
2732
2771
|
}));
|
|
2733
2772
|
}, [effectiveStates, layerGeojson, layers]);
|
|
2734
|
-
const orderedLayers = (0,
|
|
2773
|
+
const orderedLayers = (0, import_react5.useMemo)(() => {
|
|
2735
2774
|
return [...decoratedLayers].filter((layer) => layer.effective?.visible && layer.data).sort((a, b) => a.displayOrder - b.displayOrder);
|
|
2736
2775
|
}, [decoratedLayers]);
|
|
2737
|
-
const autoZoomGeojson = (0,
|
|
2776
|
+
const autoZoomGeojson = (0, import_react5.useMemo)(
|
|
2738
2777
|
() => orderedLayers.map((layer) => layer.data).filter((collection) => !!collection),
|
|
2739
2778
|
[orderedLayers]
|
|
2740
2779
|
);
|
|
2741
|
-
const resolveLayerStyle = (0,
|
|
2780
|
+
const resolveLayerStyle = (0, import_react5.useCallback)(
|
|
2742
2781
|
(layerId) => {
|
|
2743
2782
|
return getStyleByLayerId(layerId, mapLayers) ?? layerStyleIndex.get(String(layerId)) ?? null;
|
|
2744
2783
|
},
|
|
2745
2784
|
[layerStyleIndex, mapLayers]
|
|
2746
2785
|
);
|
|
2747
|
-
const labelMarkers = (0,
|
|
2786
|
+
const labelMarkers = (0, import_react5.useMemo)(() => {
|
|
2748
2787
|
const markers = [];
|
|
2749
2788
|
decoratedLayers.forEach((layerState) => {
|
|
2750
2789
|
if (!layerState.effective?.visible) return;
|
|
@@ -2781,7 +2820,7 @@ var ZenitMap = (0, import_react4.forwardRef)(({
|
|
|
2781
2820
|
});
|
|
2782
2821
|
return markers;
|
|
2783
2822
|
}, [currentZoom, decoratedLayers, labelKeyIndex, layerMetaIndex, resolveLayerStyle]);
|
|
2784
|
-
const ensureLayerPanes = (0,
|
|
2823
|
+
const ensureLayerPanes = (0, import_react5.useCallback)(
|
|
2785
2824
|
(targetMap, targetLayers) => {
|
|
2786
2825
|
const baseZIndex = 400;
|
|
2787
2826
|
targetLayers.forEach((layer) => {
|
|
@@ -2797,7 +2836,7 @@ var ZenitMap = (0, import_react4.forwardRef)(({
|
|
|
2797
2836
|
},
|
|
2798
2837
|
[]
|
|
2799
2838
|
);
|
|
2800
|
-
const handleMapReady = (0,
|
|
2839
|
+
const handleMapReady = (0, import_react5.useCallback)(
|
|
2801
2840
|
(instance) => {
|
|
2802
2841
|
setPanesReady(false);
|
|
2803
2842
|
setMapInstance(instance);
|
|
@@ -2805,7 +2844,7 @@ var ZenitMap = (0, import_react4.forwardRef)(({
|
|
|
2805
2844
|
},
|
|
2806
2845
|
[onMapReady]
|
|
2807
2846
|
);
|
|
2808
|
-
(0,
|
|
2847
|
+
(0, import_react5.useEffect)(() => {
|
|
2809
2848
|
if (!mapInstance) {
|
|
2810
2849
|
setPanesReady(false);
|
|
2811
2850
|
return;
|
|
@@ -2825,7 +2864,7 @@ var ZenitMap = (0, import_react4.forwardRef)(({
|
|
|
2825
2864
|
setPanesReady(true);
|
|
2826
2865
|
}
|
|
2827
2866
|
}, [mapInstance, orderedLayers, ensureLayerPanes]);
|
|
2828
|
-
const overlayOnEachFeature = (0,
|
|
2867
|
+
const overlayOnEachFeature = (0, import_react5.useMemo)(() => {
|
|
2829
2868
|
return (feature, layer) => {
|
|
2830
2869
|
const layerId = getFeatureLayerId(feature) ?? void 0;
|
|
2831
2870
|
const geometryType = feature?.geometry?.type;
|
|
@@ -2936,7 +2975,7 @@ var ZenitMap = (0, import_react4.forwardRef)(({
|
|
|
2936
2975
|
return buildLayerStyle(layerId, baseOpacity ?? 1, feature, layerType);
|
|
2937
2976
|
};
|
|
2938
2977
|
};
|
|
2939
|
-
(0,
|
|
2978
|
+
(0, import_react5.useImperativeHandle)(ref, () => ({
|
|
2940
2979
|
setLayerOpacity: (layerId, opacity) => {
|
|
2941
2980
|
upsertUiOverride(layerId, { overrideOpacity: opacity });
|
|
2942
2981
|
},
|
|
@@ -3053,7 +3092,7 @@ var ZenitMap = (0, import_react4.forwardRef)(({
|
|
|
3053
3092
|
const pointsPaneName = `zenit-layer-${layerState.mapLayer.layerId}-points`;
|
|
3054
3093
|
const layerType = layerState.layer?.layerType ?? layerState.mapLayer.layerType ?? void 0;
|
|
3055
3094
|
const labelKey = labelKeyIndex.get(String(layerState.mapLayer.layerId));
|
|
3056
|
-
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
3095
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_react5.default.Fragment, { children: [
|
|
3057
3096
|
layerState.data && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
3058
3097
|
LayerGeoJson,
|
|
3059
3098
|
{
|
|
@@ -3210,7 +3249,7 @@ var ZenitMap = (0, import_react4.forwardRef)(({
|
|
|
3210
3249
|
ZenitMap.displayName = "ZenitMap";
|
|
3211
3250
|
|
|
3212
3251
|
// src/react/ZenitLayerManager.tsx
|
|
3213
|
-
var
|
|
3252
|
+
var import_react6 = __toESM(require("react"));
|
|
3214
3253
|
|
|
3215
3254
|
// src/react/icons.tsx
|
|
3216
3255
|
var import_lucide_react = require("lucide-react");
|
|
@@ -3256,15 +3295,15 @@ var ZenitLayerManager = ({
|
|
|
3256
3295
|
layerFeatureCounts,
|
|
3257
3296
|
mapLayers
|
|
3258
3297
|
}) => {
|
|
3259
|
-
const [map, setMap] = (0,
|
|
3260
|
-
const [loadingMap, setLoadingMap] = (0,
|
|
3261
|
-
const [mapError, setMapError] = (0,
|
|
3262
|
-
const [layers, setLayers] = (0,
|
|
3263
|
-
const [activeTab, setActiveTab] = (0,
|
|
3264
|
-
const [panelVisible, setPanelVisible] = (0,
|
|
3265
|
-
const lastEmittedStatesRef = (0,
|
|
3298
|
+
const [map, setMap] = (0, import_react6.useState)(null);
|
|
3299
|
+
const [loadingMap, setLoadingMap] = (0, import_react6.useState)(false);
|
|
3300
|
+
const [mapError, setMapError] = (0, import_react6.useState)(null);
|
|
3301
|
+
const [layers, setLayers] = (0, import_react6.useState)([]);
|
|
3302
|
+
const [activeTab, setActiveTab] = (0, import_react6.useState)("layers");
|
|
3303
|
+
const [panelVisible, setPanelVisible] = (0, import_react6.useState)(true);
|
|
3304
|
+
const lastEmittedStatesRef = (0, import_react6.useRef)(null);
|
|
3266
3305
|
const isControlled = Array.isArray(layerStates) && typeof onLayerStatesChange === "function";
|
|
3267
|
-
const baseStates = (0,
|
|
3306
|
+
const baseStates = (0, import_react6.useMemo)(
|
|
3268
3307
|
() => initLayerStates(
|
|
3269
3308
|
layers.map((entry) => ({
|
|
3270
3309
|
...entry.mapLayer,
|
|
@@ -3275,7 +3314,7 @@ var ZenitLayerManager = ({
|
|
|
3275
3314
|
),
|
|
3276
3315
|
[layers]
|
|
3277
3316
|
);
|
|
3278
|
-
const overrideStates = (0,
|
|
3317
|
+
const overrideStates = (0, import_react6.useMemo)(
|
|
3279
3318
|
() => layers.map(
|
|
3280
3319
|
(entry) => ({
|
|
3281
3320
|
layerId: entry.mapLayer.layerId,
|
|
@@ -3285,11 +3324,11 @@ var ZenitLayerManager = ({
|
|
|
3285
3324
|
),
|
|
3286
3325
|
[layers]
|
|
3287
3326
|
);
|
|
3288
|
-
const effectiveStates = (0,
|
|
3327
|
+
const effectiveStates = (0, import_react6.useMemo)(
|
|
3289
3328
|
() => layerStates ?? applyLayerOverrides(baseStates, overrideStates),
|
|
3290
3329
|
[baseStates, layerStates, overrideStates]
|
|
3291
3330
|
);
|
|
3292
|
-
const layerMetaIndex = (0,
|
|
3331
|
+
const layerMetaIndex = (0, import_react6.useMemo)(() => {
|
|
3293
3332
|
const index = /* @__PURE__ */ new Map();
|
|
3294
3333
|
mapLayers?.forEach((entry) => {
|
|
3295
3334
|
const key = String(entry.layerId);
|
|
@@ -3303,7 +3342,7 @@ var ZenitLayerManager = ({
|
|
|
3303
3342
|
});
|
|
3304
3343
|
return index;
|
|
3305
3344
|
}, [map, mapLayers]);
|
|
3306
|
-
const resolveUserOpacity =
|
|
3345
|
+
const resolveUserOpacity = import_react6.default.useCallback((state) => {
|
|
3307
3346
|
if (typeof state.overrideOpacity === "number") return state.overrideOpacity;
|
|
3308
3347
|
if (typeof state.overrideOpacity === "string") {
|
|
3309
3348
|
const parsed = Number.parseFloat(state.overrideOpacity);
|
|
@@ -3311,7 +3350,7 @@ var ZenitLayerManager = ({
|
|
|
3311
3350
|
}
|
|
3312
3351
|
return state.opacity ?? 1;
|
|
3313
3352
|
}, []);
|
|
3314
|
-
const resolveEffectiveOpacity =
|
|
3353
|
+
const resolveEffectiveOpacity = import_react6.default.useCallback(
|
|
3315
3354
|
(layerId, userOpacity) => {
|
|
3316
3355
|
if (!autoOpacityOnZoom || typeof mapZoom !== "number") {
|
|
3317
3356
|
return userOpacity;
|
|
@@ -3327,7 +3366,7 @@ var ZenitLayerManager = ({
|
|
|
3327
3366
|
},
|
|
3328
3367
|
[autoOpacityConfig, autoOpacityOnZoom, layerMetaIndex, mapZoom]
|
|
3329
3368
|
);
|
|
3330
|
-
const effectiveStatesWithZoom = (0,
|
|
3369
|
+
const effectiveStatesWithZoom = (0, import_react6.useMemo)(() => {
|
|
3331
3370
|
if (!autoOpacityOnZoom || typeof mapZoom !== "number") {
|
|
3332
3371
|
return effectiveStates;
|
|
3333
3372
|
}
|
|
@@ -3341,7 +3380,7 @@ var ZenitLayerManager = ({
|
|
|
3341
3380
|
};
|
|
3342
3381
|
});
|
|
3343
3382
|
}, [autoOpacityOnZoom, effectiveStates, mapZoom, resolveEffectiveOpacity, resolveUserOpacity]);
|
|
3344
|
-
(0,
|
|
3383
|
+
(0, import_react6.useEffect)(() => {
|
|
3345
3384
|
let cancelled = false;
|
|
3346
3385
|
setLoadingMap(true);
|
|
3347
3386
|
setMapError(null);
|
|
@@ -3373,12 +3412,12 @@ var ZenitLayerManager = ({
|
|
|
3373
3412
|
cancelled = true;
|
|
3374
3413
|
};
|
|
3375
3414
|
}, [client.maps, mapId]);
|
|
3376
|
-
(0,
|
|
3415
|
+
(0, import_react6.useEffect)(() => {
|
|
3377
3416
|
if (!showUploadTab && activeTab === "upload") {
|
|
3378
3417
|
setActiveTab("layers");
|
|
3379
3418
|
}
|
|
3380
3419
|
}, [activeTab, showUploadTab]);
|
|
3381
|
-
(0,
|
|
3420
|
+
(0, import_react6.useEffect)(() => {
|
|
3382
3421
|
if (isControlled) return;
|
|
3383
3422
|
if (!onLayerStatesChange) return;
|
|
3384
3423
|
const emitStates = autoOpacityOnZoom && typeof mapZoom === "number" ? effectiveStatesWithZoom : effectiveStates;
|
|
@@ -3396,7 +3435,7 @@ var ZenitLayerManager = ({
|
|
|
3396
3435
|
mapZoom,
|
|
3397
3436
|
onLayerStatesChange
|
|
3398
3437
|
]);
|
|
3399
|
-
const updateLayerVisible =
|
|
3438
|
+
const updateLayerVisible = import_react6.default.useCallback(
|
|
3400
3439
|
(layerId, visible) => {
|
|
3401
3440
|
if (!onLayerStatesChange) return;
|
|
3402
3441
|
const next = effectiveStates.map(
|
|
@@ -3406,7 +3445,7 @@ var ZenitLayerManager = ({
|
|
|
3406
3445
|
},
|
|
3407
3446
|
[effectiveStates, onLayerStatesChange]
|
|
3408
3447
|
);
|
|
3409
|
-
const updateLayerOpacity =
|
|
3448
|
+
const updateLayerOpacity = import_react6.default.useCallback(
|
|
3410
3449
|
(layerId, opacity) => {
|
|
3411
3450
|
if (!onLayerStatesChange) return;
|
|
3412
3451
|
const adjustedOpacity = resolveEffectiveOpacity(layerId, opacity);
|
|
@@ -3417,7 +3456,7 @@ var ZenitLayerManager = ({
|
|
|
3417
3456
|
},
|
|
3418
3457
|
[effectiveStates, onLayerStatesChange, resolveEffectiveOpacity]
|
|
3419
3458
|
);
|
|
3420
|
-
const resolveFeatureCount =
|
|
3459
|
+
const resolveFeatureCount = import_react6.default.useCallback(
|
|
3421
3460
|
(layerId, layer) => {
|
|
3422
3461
|
const resolvedFeatureCount = layerFeatureCounts?.[layerId] ?? layerFeatureCounts?.[String(layerId)];
|
|
3423
3462
|
if (typeof resolvedFeatureCount === "number") return resolvedFeatureCount;
|
|
@@ -3426,7 +3465,7 @@ var ZenitLayerManager = ({
|
|
|
3426
3465
|
},
|
|
3427
3466
|
[layerFeatureCounts]
|
|
3428
3467
|
);
|
|
3429
|
-
const decoratedLayers = (0,
|
|
3468
|
+
const decoratedLayers = (0, import_react6.useMemo)(() => {
|
|
3430
3469
|
return layers.map((entry) => ({
|
|
3431
3470
|
...entry,
|
|
3432
3471
|
effective: effectiveStates.find((state) => state.layerId === entry.mapLayer.layerId),
|
|
@@ -3455,7 +3494,7 @@ var ZenitLayerManager = ({
|
|
|
3455
3494
|
return String(a.mapLayer.layerId).localeCompare(String(b.mapLayer.layerId));
|
|
3456
3495
|
});
|
|
3457
3496
|
}, [effectiveStates, layers, resolveFeatureCount]);
|
|
3458
|
-
const resolveLayerStyle =
|
|
3497
|
+
const resolveLayerStyle = import_react6.default.useCallback(
|
|
3459
3498
|
(layerId) => {
|
|
3460
3499
|
const layerKey = String(layerId);
|
|
3461
3500
|
const fromProp = mapLayers?.find((entry) => String(entry.layerId) === layerKey)?.style;
|
|
@@ -3838,15 +3877,15 @@ var ZenitFeatureFilterPanel = ({
|
|
|
3838
3877
|
};
|
|
3839
3878
|
|
|
3840
3879
|
// src/react/ai/FloatingChatBox.tsx
|
|
3841
|
-
var
|
|
3880
|
+
var import_react8 = require("react");
|
|
3842
3881
|
var import_react_dom2 = require("react-dom");
|
|
3843
3882
|
|
|
3844
3883
|
// src/react/hooks/use-chat.ts
|
|
3845
|
-
var
|
|
3884
|
+
var import_react7 = require("react");
|
|
3846
3885
|
var useSendMessage = (config) => {
|
|
3847
|
-
const [isLoading, setIsLoading] = (0,
|
|
3848
|
-
const [error, setError] = (0,
|
|
3849
|
-
const send = (0,
|
|
3886
|
+
const [isLoading, setIsLoading] = (0, import_react7.useState)(false);
|
|
3887
|
+
const [error, setError] = (0, import_react7.useState)(null);
|
|
3888
|
+
const send = (0, import_react7.useCallback)(
|
|
3850
3889
|
async (mapId, request, options) => {
|
|
3851
3890
|
setIsLoading(true);
|
|
3852
3891
|
setError(null);
|
|
@@ -3864,18 +3903,18 @@ var useSendMessage = (config) => {
|
|
|
3864
3903
|
return { sendMessage: send, isLoading, error };
|
|
3865
3904
|
};
|
|
3866
3905
|
var useSendMessageStream = (config) => {
|
|
3867
|
-
const [isStreaming, setIsStreaming] = (0,
|
|
3868
|
-
const [streamingText, setStreamingText] = (0,
|
|
3869
|
-
const [completeResponse, setCompleteResponse] = (0,
|
|
3870
|
-
const [error, setError] = (0,
|
|
3871
|
-
const requestIdRef = (0,
|
|
3872
|
-
const reset = (0,
|
|
3906
|
+
const [isStreaming, setIsStreaming] = (0, import_react7.useState)(false);
|
|
3907
|
+
const [streamingText, setStreamingText] = (0, import_react7.useState)("");
|
|
3908
|
+
const [completeResponse, setCompleteResponse] = (0, import_react7.useState)(null);
|
|
3909
|
+
const [error, setError] = (0, import_react7.useState)(null);
|
|
3910
|
+
const requestIdRef = (0, import_react7.useRef)(0);
|
|
3911
|
+
const reset = (0, import_react7.useCallback)(() => {
|
|
3873
3912
|
setIsStreaming(false);
|
|
3874
3913
|
setStreamingText("");
|
|
3875
3914
|
setCompleteResponse(null);
|
|
3876
3915
|
setError(null);
|
|
3877
3916
|
}, []);
|
|
3878
|
-
const send = (0,
|
|
3917
|
+
const send = (0, import_react7.useCallback)(
|
|
3879
3918
|
async (mapId, request, options) => {
|
|
3880
3919
|
const requestId = requestIdRef.current + 1;
|
|
3881
3920
|
requestIdRef.current = requestId;
|
|
@@ -4166,6 +4205,17 @@ var styles = {
|
|
|
4166
4205
|
width: 480,
|
|
4167
4206
|
height: 640
|
|
4168
4207
|
},
|
|
4208
|
+
panelMobileFullscreen: {
|
|
4209
|
+
position: "fixed",
|
|
4210
|
+
top: 0,
|
|
4211
|
+
left: 0,
|
|
4212
|
+
right: 0,
|
|
4213
|
+
bottom: 0,
|
|
4214
|
+
width: "100%",
|
|
4215
|
+
height: "100%",
|
|
4216
|
+
borderRadius: 0,
|
|
4217
|
+
margin: 0
|
|
4218
|
+
},
|
|
4169
4219
|
// Header with green gradient
|
|
4170
4220
|
header: {
|
|
4171
4221
|
padding: "14px 16px",
|
|
@@ -4399,42 +4449,42 @@ var FloatingChatBox = ({
|
|
|
4399
4449
|
open: openProp
|
|
4400
4450
|
}) => {
|
|
4401
4451
|
const isControlled = openProp !== void 0;
|
|
4402
|
-
const [internalOpen, setInternalOpen] = (0,
|
|
4452
|
+
const [internalOpen, setInternalOpen] = (0, import_react8.useState)(false);
|
|
4403
4453
|
const open = isControlled ? openProp : internalOpen;
|
|
4404
|
-
const setOpen = (0,
|
|
4454
|
+
const setOpen = (0, import_react8.useCallback)((value) => {
|
|
4405
4455
|
const newValue = typeof value === "function" ? value(open) : value;
|
|
4406
4456
|
if (!isControlled) {
|
|
4407
4457
|
setInternalOpen(newValue);
|
|
4408
4458
|
}
|
|
4409
4459
|
onOpenChange?.(newValue);
|
|
4410
4460
|
}, [isControlled, open, onOpenChange]);
|
|
4411
|
-
const [expanded, setExpanded] = (0,
|
|
4412
|
-
const [messages, setMessages] = (0,
|
|
4413
|
-
const [inputValue, setInputValue] = (0,
|
|
4414
|
-
const [conversationId, setConversationId] = (0,
|
|
4415
|
-
const [errorMessage, setErrorMessage] = (0,
|
|
4416
|
-
const [isFocused, setIsFocused] = (0,
|
|
4417
|
-
const [isMobile, setIsMobile] = (0,
|
|
4418
|
-
const messagesEndRef = (0,
|
|
4419
|
-
const messagesContainerRef = (0,
|
|
4420
|
-
const chatBoxRef = (0,
|
|
4421
|
-
const chatConfig = (0,
|
|
4461
|
+
const [expanded, setExpanded] = (0, import_react8.useState)(false);
|
|
4462
|
+
const [messages, setMessages] = (0, import_react8.useState)([]);
|
|
4463
|
+
const [inputValue, setInputValue] = (0, import_react8.useState)("");
|
|
4464
|
+
const [conversationId, setConversationId] = (0, import_react8.useState)();
|
|
4465
|
+
const [errorMessage, setErrorMessage] = (0, import_react8.useState)(null);
|
|
4466
|
+
const [isFocused, setIsFocused] = (0, import_react8.useState)(false);
|
|
4467
|
+
const [isMobile, setIsMobile] = (0, import_react8.useState)(false);
|
|
4468
|
+
const messagesEndRef = (0, import_react8.useRef)(null);
|
|
4469
|
+
const messagesContainerRef = (0, import_react8.useRef)(null);
|
|
4470
|
+
const chatBoxRef = (0, import_react8.useRef)(null);
|
|
4471
|
+
const chatConfig = (0, import_react8.useMemo)(() => {
|
|
4422
4472
|
if (!baseUrl) return void 0;
|
|
4423
4473
|
return { baseUrl, accessToken, getAccessToken };
|
|
4424
4474
|
}, [accessToken, baseUrl, getAccessToken]);
|
|
4425
4475
|
const { sendMessage: sendMessage2, isStreaming, streamingText, completeResponse } = useSendMessageStream(chatConfig);
|
|
4426
4476
|
const canSend = Boolean(mapId) && Boolean(baseUrl) && inputValue.trim().length > 0 && !isStreaming;
|
|
4427
|
-
(0,
|
|
4477
|
+
(0, import_react8.useEffect)(() => {
|
|
4428
4478
|
if (open && isMobile) {
|
|
4429
4479
|
setExpanded(true);
|
|
4430
4480
|
}
|
|
4431
4481
|
}, [open, isMobile]);
|
|
4432
|
-
const scrollToBottom = (0,
|
|
4482
|
+
const scrollToBottom = (0, import_react8.useCallback)(() => {
|
|
4433
4483
|
if (messagesEndRef.current) {
|
|
4434
4484
|
messagesEndRef.current.scrollIntoView({ behavior: "smooth" });
|
|
4435
4485
|
}
|
|
4436
4486
|
}, []);
|
|
4437
|
-
(0,
|
|
4487
|
+
(0, import_react8.useEffect)(() => {
|
|
4438
4488
|
if (open && messages.length === 0) {
|
|
4439
4489
|
setMessages([
|
|
4440
4490
|
{
|
|
@@ -4445,10 +4495,10 @@ var FloatingChatBox = ({
|
|
|
4445
4495
|
]);
|
|
4446
4496
|
}
|
|
4447
4497
|
}, [open, messages.length]);
|
|
4448
|
-
(0,
|
|
4498
|
+
(0, import_react8.useEffect)(() => {
|
|
4449
4499
|
scrollToBottom();
|
|
4450
4500
|
}, [messages, streamingText, scrollToBottom]);
|
|
4451
|
-
(0,
|
|
4501
|
+
(0, import_react8.useEffect)(() => {
|
|
4452
4502
|
if (!open) return;
|
|
4453
4503
|
if (isMobile && expanded) return;
|
|
4454
4504
|
const handleClickOutside = (event) => {
|
|
@@ -4461,7 +4511,7 @@ var FloatingChatBox = ({
|
|
|
4461
4511
|
document.removeEventListener("mousedown", handleClickOutside);
|
|
4462
4512
|
};
|
|
4463
4513
|
}, [open, isMobile, expanded]);
|
|
4464
|
-
(0,
|
|
4514
|
+
(0, import_react8.useEffect)(() => {
|
|
4465
4515
|
if (typeof window === "undefined") return;
|
|
4466
4516
|
const mediaQuery = window.matchMedia("(max-width: 768px)");
|
|
4467
4517
|
const updateMobile = () => setIsMobile(mediaQuery.matches);
|
|
@@ -4479,7 +4529,7 @@ var FloatingChatBox = ({
|
|
|
4479
4529
|
}
|
|
4480
4530
|
};
|
|
4481
4531
|
}, []);
|
|
4482
|
-
(0,
|
|
4532
|
+
(0, import_react8.useEffect)(() => {
|
|
4483
4533
|
if (typeof document === "undefined") return;
|
|
4484
4534
|
if (!open || !isMobile) return;
|
|
4485
4535
|
document.body.style.overflow = "hidden";
|
|
@@ -4487,10 +4537,10 @@ var FloatingChatBox = ({
|
|
|
4487
4537
|
document.body.style.overflow = "";
|
|
4488
4538
|
};
|
|
4489
4539
|
}, [open, isMobile]);
|
|
4490
|
-
const addMessage = (0,
|
|
4540
|
+
const addMessage = (0, import_react8.useCallback)((message) => {
|
|
4491
4541
|
setMessages((prev) => [...prev, message]);
|
|
4492
4542
|
}, []);
|
|
4493
|
-
const handleSend = (0,
|
|
4543
|
+
const handleSend = (0, import_react8.useCallback)(async () => {
|
|
4494
4544
|
if (!mapId) {
|
|
4495
4545
|
setErrorMessage("Selecciona un mapa para usar el asistente.");
|
|
4496
4546
|
return;
|
|
@@ -4543,7 +4593,7 @@ var FloatingChatBox = ({
|
|
|
4543
4593
|
sendMessage2,
|
|
4544
4594
|
userId
|
|
4545
4595
|
]);
|
|
4546
|
-
const handleKeyDown = (0,
|
|
4596
|
+
const handleKeyDown = (0, import_react8.useCallback)(
|
|
4547
4597
|
(event) => {
|
|
4548
4598
|
if (event.key === "Enter" && !event.shiftKey) {
|
|
4549
4599
|
event.preventDefault();
|
|
@@ -4554,7 +4604,7 @@ var FloatingChatBox = ({
|
|
|
4554
4604
|
},
|
|
4555
4605
|
[canSend, handleSend]
|
|
4556
4606
|
);
|
|
4557
|
-
const handleFollowUpClick = (0,
|
|
4607
|
+
const handleFollowUpClick = (0, import_react8.useCallback)((question) => {
|
|
4558
4608
|
setInputValue(question);
|
|
4559
4609
|
}, []);
|
|
4560
4610
|
const renderMetadata = (response) => {
|
|
@@ -4576,7 +4626,7 @@ var FloatingChatBox = ({
|
|
|
4576
4626
|
] }, index)) })
|
|
4577
4627
|
] });
|
|
4578
4628
|
};
|
|
4579
|
-
const handleActionClick = (0,
|
|
4629
|
+
const handleActionClick = (0, import_react8.useCallback)((action) => {
|
|
4580
4630
|
if (isStreaming) return;
|
|
4581
4631
|
setOpen(false);
|
|
4582
4632
|
requestAnimationFrame(() => {
|
|
@@ -4691,22 +4741,6 @@ var FloatingChatBox = ({
|
|
|
4691
4741
|
box-sizing: border-box;
|
|
4692
4742
|
}
|
|
4693
4743
|
@media (max-width: 768px) {
|
|
4694
|
-
.zenit-chat-panel.zenit-chat-panel--fullscreen {
|
|
4695
|
-
position: fixed !important;
|
|
4696
|
-
left: 0 !important;
|
|
4697
|
-
right: 0 !important;
|
|
4698
|
-
top: 4rem !important;
|
|
4699
|
-
bottom: 0 !important;
|
|
4700
|
-
width: 100% !important;
|
|
4701
|
-
max-width: 100% !important;
|
|
4702
|
-
height: auto !important;
|
|
4703
|
-
border-radius: 0 !important;
|
|
4704
|
-
display: flex !important;
|
|
4705
|
-
flex-direction: column !important;
|
|
4706
|
-
overflow: hidden !important;
|
|
4707
|
-
z-index: 100000 !important;
|
|
4708
|
-
padding-top: env(safe-area-inset-top);
|
|
4709
|
-
}
|
|
4710
4744
|
.zenit-chat-panel.zenit-chat-panel--fullscreen .zenit-ai-body {
|
|
4711
4745
|
flex: 1;
|
|
4712
4746
|
min-height: 0;
|
|
@@ -4726,16 +4760,20 @@ var FloatingChatBox = ({
|
|
|
4726
4760
|
"div",
|
|
4727
4761
|
{
|
|
4728
4762
|
ref: chatBoxRef,
|
|
4729
|
-
className: `zenit-chat-panel${expanded ? " zenit-chat-panel--expanded" : ""}${isMobile ? " zenit-chat-panel--fullscreen" : ""}`,
|
|
4730
|
-
style: {
|
|
4731
|
-
|
|
4732
|
-
|
|
4733
|
-
|
|
4763
|
+
className: `zenit-chat-panel${expanded && !isMobile ? " zenit-chat-panel--expanded" : ""}${isMobile ? " zenit-chat-panel--fullscreen" : ""}`,
|
|
4764
|
+
style: (() => {
|
|
4765
|
+
const desktopStyle = expanded ? styles.panelExpanded : styles.panelNormal;
|
|
4766
|
+
const mobileStyle = styles.panelMobileFullscreen;
|
|
4767
|
+
return {
|
|
4768
|
+
...styles.panel,
|
|
4769
|
+
...isMobile ? mobileStyle : desktopStyle
|
|
4770
|
+
};
|
|
4771
|
+
})(),
|
|
4734
4772
|
children: [
|
|
4735
4773
|
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("header", { style: styles.header, children: [
|
|
4736
4774
|
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("h3", { style: styles.title, children: "Asistente Zenit AI" }),
|
|
4737
4775
|
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { style: styles.headerButtons, children: [
|
|
4738
|
-
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
4776
|
+
!isMobile && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
4739
4777
|
"button",
|
|
4740
4778
|
{
|
|
4741
4779
|
type: "button",
|