utopia-ui 3.0.92 → 3.0.93

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -40,7 +40,7 @@ export { Popup } from 'leaflet';
40
40
  * ```
41
41
  * @category Map
42
42
  */
43
- declare function UtopiaMap({ height, width, center, zoom, children, geo, showFilterControl, showGratitudeControl, showLayerControl, showZoomControl, showThemeControl, defaultTheme, donationWidget, }: {
43
+ declare function UtopiaMap({ height, width, center, zoom, children, geo, showFilterControl, showGratitudeControl, showLayerControl, showZoomControl, showThemeControl, defaultTheme, donationWidget, expandLayerControl, }: {
44
44
  /** height of the map (default '500px') */
45
45
  height?: string;
46
46
  /** width of the map (default '100%') */
@@ -67,6 +67,8 @@ declare function UtopiaMap({ height, width, center, zoom, children, geo, showFil
67
67
  defaultTheme?: string;
68
68
  /** ask to donate to the Utopia Project OpenCollective campaign (default false) */
69
69
  donationWidget?: boolean;
70
+ /** open layer control on map initialisation */
71
+ expandLayerControl?: boolean;
70
72
  }): react_jsx_runtime.JSX.Element;
71
73
 
72
74
  /**
package/dist/index.esm.js CHANGED
@@ -236,6 +236,23 @@ function useFilterManager(initialTags) {
236
236
  throw new Error();
237
237
  }
238
238
  }, initialLayers);
239
+ const allLayers = useLayers();
240
+ useEffect(() => {
241
+ if (allLayers.length === 0)
242
+ return;
243
+ const visibleNames = visibleLayers.map((l) => l.name);
244
+ const allNames = allLayers.map((l) => l.name);
245
+ const params = new URLSearchParams(location.search);
246
+ const allVisible = visibleNames.length === allNames.length &&
247
+ visibleNames.every((name) => allNames.includes(name));
248
+ if (allVisible) {
249
+ params.delete('layers');
250
+ }
251
+ else {
252
+ params.set('layers', visibleNames.join(','));
253
+ }
254
+ navigate(`${location.pathname}?${params.toString()}`, { replace: true });
255
+ }, [visibleLayers, allLayers, navigate]);
239
256
  const [visibleGroupTypes, dispatchGroupTypes] = useReducer((state, action) => {
240
257
  switch (action.type) {
241
258
  case 'ADD_GROUP_TYPE':
@@ -1276,8 +1293,8 @@ const GratitudeControl = () => {
1276
1293
 
1277
1294
  var LayerSVG = 'data:image/svg+xml;base64,PHN2ZyB2ZXJzaW9uPScxLjEnIHZpZXdCb3g9JzAgMCAyMCAyMCcgc3Ryb2tlLXdpZHRoPSIyIiB4bWxucz0naHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmcnPgogICAgPHBhdGgKICAgICAgICBpZD0nc3ZnXzEnCiAgICAgICAgZmlsbD0nY3VycmVudENvbG9yJwogICAgICAgIGQ9J20yLjc1NTY1LDExLjkwNzI3bC0xLjAzODUyLDAuMjgzNzJjLTAuNzc3MTgsMC4zODg1OSAtMC43NzcxOCwxLjAxMzggMCwxLjQwMjNsNy4wMTU2LDMuNTA3OGMwLjc3NzE4LDAuMzg4NTkgMi4wMjc1LDAuMzg4NTkgMi44MDQ3LDBsNy4wMTU2LC0zLjUwNzhjMC43NzcxOCwtMC4zODg1OSAwLjc3NzE4LC0xLjAxMzggMCwtMS40MDIzbC0wLjYzMzExLC0wLjQ4NjQzbC00LjY3NzE4LDIuMjM2MjRjLTEuNTQ1MiwwLjc3MjYyIC0zLjMxODc3LDEuNTgzNDMgLTQuODY0MDcsMC44MTA4MWwtNS42MjMwMiwtMi44NDQzNHonCiAgICAvPgogICAgPHBhdGgKICAgICAgICBpZD0nc3ZnXzInCiAgICAgICAgc3Ryb2tlPSdjdXJyZW50Q29sb3InCiAgICAgICAgZmlsbD0nbm9uZScKICAgICAgICBkPSdtMTEuMjQ3LDQuMzA4NTFsNi4yMzQ5LDMuMDg3N2MwLjY5MDgzLDAuMzQyMTEgMC42OTA4MywwLjg5Mjk1IDAsMS4yMzUxbC02LjIzNDksMy4wODc3Yy0wLjY5MDgzLDAuMzQyMTEgLTEuODAzMSwwLjM0MjEyIC0yLjQ5NCwwbC02LjIzNDksLTMuMDg3N2MtMC42OTA4MywtMC4zNDIxMSAtMC42OTA4MywtMC44OTI5NSAwLC0xLjIzNTFsNi4yMzQ5LC0zLjA4NzdjMC42OTA4MywtMC4zNDIxMSAxLjgwMzEsLTAuMzQyMTEgMi40OTQsMHonCiAgICAvPgo8L3N2Zz4=';
1278
1295
 
1279
- function LayerControl() {
1280
- const [open, setOpen] = useState(false);
1296
+ function LayerControl({ expandLayerControl = false }) {
1297
+ const [open, setOpen] = useState(expandLayerControl);
1281
1298
  const layers = useLayers();
1282
1299
  const isLayerVisible = useIsLayerVisible();
1283
1300
  const toggleVisibleLayer = useToggleVisibleLayer();
@@ -2740,7 +2757,7 @@ const SelectPosition = ({ setSelectNewItemPosition }) => {
2740
2757
  }, children: jsx("p", { className: 'tw:text-center ', children: "\u2715" }) }), jsx("div", { className: 'tw:alert tw:bg-base-100 tw:text-base-content', children: jsx("div", { children: jsx("span", { className: 'tw:text-lg', children: "Select position on the map!" }) }) })] }));
2741
2758
  };
2742
2759
 
2743
- function UtopiaMapInner({ children, geo, showFilterControl = false, showGratitudeControl = false, showLayerControl = true, showThemeControl = false, defaultTheme = '', donationWidget, }) {
2760
+ function UtopiaMapInner({ children, geo, showFilterControl = false, showGratitudeControl = false, showLayerControl = true, showThemeControl = false, defaultTheme = '', donationWidget, expandLayerControl, }) {
2744
2761
  const selectNewItemPosition = useSelectPosition();
2745
2762
  const setSelectNewItemPosition = useSetSelectPosition();
2746
2763
  const setClusterRef = useSetClusterRef();
@@ -2850,7 +2867,50 @@ function UtopiaMapInner({ children, geo, showFilterControl = false, showGratitud
2850
2867
  layer.bindPopup(feature.properties.name);
2851
2868
  }
2852
2869
  };
2853
- return (jsxs("div", { className: `tw:h-full ${selectNewItemPosition != null ? 'crosshair-cursor-enabled' : ''}`, children: [jsx(Outlet, {}), jsxs(Control, { position: 'topLeft', zIndex: '1000', absolute: true, children: [jsx(SearchControl, {}), jsx(TagsControl, {})] }), jsxs(Control, { position: 'bottomLeft', zIndex: '999', absolute: true, children: [showFilterControl && jsx(FilterControl, {}), showLayerControl && jsx(LayerControl, {}), showGratitudeControl && jsx(GratitudeControl, {})] }), jsx(TileLayer, { maxZoom: 19, attribution: '\u00A9 <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors', url: 'https://tile.osmand.net/hd/{z}/{x}/{y}.png' }), jsx(MarkerClusterGroup, { ref: (r) => setClusterRef(r), showCoverageOnHover: true, chunkedLoading: true, maxClusterRadius: 50, removeOutsideVisibleBounds: false, children: children }), geo && (jsx(GeoJSON, { data: geo, onEachFeature: onEachFeature, eventHandlers: {
2870
+ const addFilterTag = useAddFilterTag();
2871
+ const resetFilterTags = useResetFilterTags();
2872
+ const tags = useTags();
2873
+ const filterTags = useFilterTags();
2874
+ useEffect(() => {
2875
+ const params = new URLSearchParams(location.search);
2876
+ const urlTags = params.get('tags');
2877
+ const decodedTags = urlTags ? decodeURIComponent(urlTags) : '';
2878
+ const decodedTagsArray = decodedTags.split(';').filter(Boolean);
2879
+ const urlDiffersFromState = decodedTagsArray.some((ut) => !filterTags.find((ft) => ut.toLowerCase() === ft.name.toLowerCase())) ||
2880
+ filterTags.some((ft) => !decodedTagsArray.find((ut) => ut.toLowerCase() === ft.name.toLowerCase()));
2881
+ if (urlDiffersFromState) {
2882
+ resetFilterTags();
2883
+ decodedTagsArray.forEach((urlTag) => {
2884
+ const match = tags.find((t) => t.name.toLowerCase() === urlTag.toLowerCase());
2885
+ if (match)
2886
+ addFilterTag(match);
2887
+ });
2888
+ }
2889
+ }, [location, tags, filterTags, addFilterTag, resetFilterTags]);
2890
+ const toggleVisibleLayer = useToggleVisibleLayer();
2891
+ const allLayers = useLayers();
2892
+ const initializedRef = useRef(false);
2893
+ useEffect(() => {
2894
+ if (initializedRef.current || allLayers.length === 0)
2895
+ return;
2896
+ const params = new URLSearchParams(location.search);
2897
+ const urlLayersParam = params.get('layers');
2898
+ if (!urlLayersParam) {
2899
+ initializedRef.current = true;
2900
+ return;
2901
+ }
2902
+ const urlLayerNames = urlLayersParam.split(',').filter(Boolean);
2903
+ const layerNamesToHide = allLayers
2904
+ .map((l) => l.name)
2905
+ .filter((name) => !urlLayerNames.includes(name));
2906
+ layerNamesToHide.forEach((name) => {
2907
+ const match = allLayers.find((l) => l.name === name);
2908
+ if (match)
2909
+ toggleVisibleLayer(match);
2910
+ });
2911
+ initializedRef.current = true;
2912
+ }, [location, allLayers, toggleVisibleLayer]);
2913
+ return (jsxs("div", { className: `tw:h-full ${selectNewItemPosition != null ? 'crosshair-cursor-enabled' : ''}`, children: [jsx(Outlet, {}), jsxs(Control, { position: 'topLeft', zIndex: '1000', absolute: true, children: [jsx(SearchControl, {}), jsx(TagsControl, {})] }), jsxs(Control, { position: 'bottomLeft', zIndex: '999', absolute: true, children: [showFilterControl && jsx(FilterControl, {}), showLayerControl && jsx(LayerControl, { expandLayerControl: expandLayerControl ?? false }), showGratitudeControl && jsx(GratitudeControl, {})] }), jsx(TileLayer, { maxZoom: 19, attribution: '\u00A9 <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors', url: 'https://tile.osmand.net/hd/{z}/{x}/{y}.png' }), jsx(MarkerClusterGroup, { ref: (r) => setClusterRef(r), showCoverageOnHover: true, chunkedLoading: true, maxClusterRadius: 50, removeOutsideVisibleBounds: false, children: children }), geo && (jsx(GeoJSON, { data: geo, onEachFeature: onEachFeature, eventHandlers: {
2854
2914
  click: (e) => {
2855
2915
  if (selectNewItemPosition) {
2856
2916
  e.layer.closePopup();
@@ -2894,8 +2954,8 @@ function UtopiaMapInner({ children, geo, showFilterControl = false, showGratitud
2894
2954
  * ```
2895
2955
  * @category Map
2896
2956
  */
2897
- function UtopiaMap({ height = '500px', width = '100%', center = [50.6, 9.5], zoom = 10, children, geo, showFilterControl = false, showGratitudeControl = false, showLayerControl = true, showZoomControl = false, showThemeControl = false, defaultTheme, donationWidget, }) {
2898
- return (jsx(ContextWrapper, { children: jsx(MapContainer, { style: { height, width }, center: new LatLng(center[0], center[1]), zoom: zoom, zoomControl: showZoomControl, maxZoom: 19, children: jsx(UtopiaMapInner, { geo: geo, showFilterControl: showFilterControl, showGratitudeControl: showGratitudeControl, showLayerControl: showLayerControl, donationWidget: donationWidget, showThemeControl: showThemeControl, defaultTheme: defaultTheme, children: children }) }) }));
2957
+ function UtopiaMap({ height = '500px', width = '100%', center = [50.6, 9.5], zoom = 10, children, geo, showFilterControl = false, showGratitudeControl = false, showLayerControl = true, showZoomControl = false, showThemeControl = false, defaultTheme, donationWidget, expandLayerControl, }) {
2958
+ return (jsx(ContextWrapper, { children: jsx(MapContainer, { style: { height, width }, center: new LatLng(center[0], center[1]), zoom: zoom, zoomControl: showZoomControl, maxZoom: 19, children: jsx(UtopiaMapInner, { geo: geo, showFilterControl: showFilterControl, showGratitudeControl: showGratitudeControl, showLayerControl: showLayerControl, donationWidget: donationWidget, showThemeControl: showThemeControl, defaultTheme: defaultTheme, expandLayerControl: expandLayerControl, children: children }) }) }));
2899
2959
  }
2900
2960
 
2901
2961
  const LayerContext = createContext({
@@ -3019,27 +3079,6 @@ function Tags({ data, api }) {
3019
3079
  api && setTagApi(api);
3020
3080
  // eslint-disable-next-line react-hooks/exhaustive-deps
3021
3081
  }, [api, data]);
3022
- const location = useLocation();
3023
- const addFilterTag = useAddFilterTag();
3024
- const resetFilterTags = useResetFilterTags();
3025
- const tags = useTags();
3026
- const filterTags = useFilterTags();
3027
- useEffect(() => {
3028
- const params = new URLSearchParams(location.search);
3029
- const urlTags = params.get('tags');
3030
- const decodedTags = urlTags ? decodeURIComponent(urlTags) : '';
3031
- const decodedTagsArray = decodedTags.split(';');
3032
- if (decodedTagsArray.some((ut) => !filterTags.find((ft) => ut.toLocaleLowerCase() === ft.name.toLocaleLowerCase())) ||
3033
- filterTags.some((ft) => !decodedTagsArray.find((ut) => ut.toLocaleLowerCase() === ft.name.toLocaleLowerCase()))) {
3034
- resetFilterTags();
3035
- decodedTagsArray.map((urlTag) => {
3036
- const tag = tags.find((t) => t.name.toLocaleLowerCase() === urlTag.toLocaleLowerCase());
3037
- tag && addFilterTag(tag);
3038
- return null;
3039
- });
3040
- }
3041
- // eslint-disable-next-line react-hooks/exhaustive-deps
3042
- }, [location, tags]);
3043
3082
  return jsx(Fragment, {});
3044
3083
  }
3045
3084