ublo-lib 1.6.18 → 1.6.19
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/es/common/components/editable-map/edit-form.js +7 -1
- package/es/common/components/editable-map/editable-map.js +5 -2
- package/es/common/components/editable-map/map-events.js +2 -1
- package/es/common/components/editable-map/markers.js +81 -50
- package/es/common/components/editable-map/markers.module.css +5 -0
- package/package.json +1 -1
|
@@ -2,6 +2,7 @@ import * as React from "react";
|
|
|
2
2
|
import Input from "dt-design-system/es/input";
|
|
3
3
|
import Textarea from "dt-design-system/es/textarea";
|
|
4
4
|
import Button from "dt-design-system/es/button";
|
|
5
|
+
import Checkbox from "dt-design-system/es/checkbox";
|
|
5
6
|
import * as Icons from "dt-design-system/es/icons";
|
|
6
7
|
import IconPicker from "./icon-picker";
|
|
7
8
|
import css from "./edit-form.module.css";
|
|
@@ -19,7 +20,8 @@ const EditForm = ({
|
|
|
19
20
|
title,
|
|
20
21
|
description,
|
|
21
22
|
url,
|
|
22
|
-
label
|
|
23
|
+
label,
|
|
24
|
+
popupOpened
|
|
23
25
|
} = marker;
|
|
24
26
|
const removeMarker = e => {
|
|
25
27
|
e.stopPropagation();
|
|
@@ -76,6 +78,10 @@ const EditForm = ({
|
|
|
76
78
|
onValueChange: updateMarker("label"),
|
|
77
79
|
compact: true
|
|
78
80
|
})]
|
|
81
|
+
}), _jsx(Checkbox, {
|
|
82
|
+
label: "Ouvert par d\xE9faut",
|
|
83
|
+
checked: popupOpened,
|
|
84
|
+
onCheckedChange: updateMarker("popupOpened")
|
|
79
85
|
}), _jsxs("div", {
|
|
80
86
|
className: css.buttons,
|
|
81
87
|
children: [_jsxs(Button, {
|
|
@@ -26,6 +26,7 @@ const EditableMap = ({
|
|
|
26
26
|
const [center, setCenter] = React.useState(presets?.center || FRANCE_CENTER);
|
|
27
27
|
const [zoom, setZoom] = React.useState(presets?.zoom ?? DEFAULT_ZOOM);
|
|
28
28
|
const [markers, setMarkers] = React.useState(presets?.markers || []);
|
|
29
|
+
const scrollWheelZoom = isInDialog || Boolean(cmsMode);
|
|
29
30
|
const refreshSize = () => {
|
|
30
31
|
ref.current.invalidateSize();
|
|
31
32
|
};
|
|
@@ -51,7 +52,7 @@ const EditableMap = ({
|
|
|
51
52
|
ref: ref,
|
|
52
53
|
center: center,
|
|
53
54
|
zoom: zoom,
|
|
54
|
-
scrollWheelZoom:
|
|
55
|
+
scrollWheelZoom: scrollWheelZoom,
|
|
55
56
|
className: css.map,
|
|
56
57
|
attributionControl: false,
|
|
57
58
|
children: [_jsx(TileLayer, {
|
|
@@ -63,9 +64,11 @@ const EditableMap = ({
|
|
|
63
64
|
setZoom: setZoom,
|
|
64
65
|
setCenter: setCenter
|
|
65
66
|
}), _jsx(Markers, {
|
|
67
|
+
map: ref,
|
|
66
68
|
markers: markers,
|
|
67
69
|
setMarkers: setMarkers,
|
|
68
|
-
iconSet: iconSet
|
|
70
|
+
iconSet: iconSet,
|
|
71
|
+
isInDialog: isInDialog
|
|
69
72
|
})]
|
|
70
73
|
}), cmsMode === "editing" && _jsx(Helper, {})]
|
|
71
74
|
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import * as ReactDOM from "react-dom/server";
|
|
3
3
|
import * as L from "leaflet";
|
|
4
|
-
import { Marker, Popup, Tooltip } from "react-leaflet";
|
|
4
|
+
import { Marker as LeafletMarker, Popup, Tooltip } from "react-leaflet";
|
|
5
5
|
import { useUbloContext } from "ublo/with-ublo";
|
|
6
6
|
import EditForm from "./edit-form";
|
|
7
7
|
import * as Icons from "./icons";
|
|
@@ -9,7 +9,78 @@ import css from "./markers.module.css";
|
|
|
9
9
|
import PopupData from "./popup-data";
|
|
10
10
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
11
11
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
12
|
+
const Marker = ({
|
|
13
|
+
isInDialog,
|
|
14
|
+
map,
|
|
15
|
+
marker,
|
|
16
|
+
setMarkers,
|
|
17
|
+
iconSet,
|
|
18
|
+
isEditing
|
|
19
|
+
}) => {
|
|
20
|
+
const popupRef = React.useRef();
|
|
21
|
+
const {
|
|
22
|
+
id,
|
|
23
|
+
icon,
|
|
24
|
+
title,
|
|
25
|
+
position,
|
|
26
|
+
popupOpened
|
|
27
|
+
} = marker;
|
|
28
|
+
const Icon = Icons[iconSet][icon] || Icons[iconSet].Location;
|
|
29
|
+
const updatePosition = e => {
|
|
30
|
+
setMarkers(currents => {
|
|
31
|
+
return currents.map(marker => {
|
|
32
|
+
if (marker.id === id) {
|
|
33
|
+
return {
|
|
34
|
+
...marker,
|
|
35
|
+
position: e.target.getLatLng()
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
return marker;
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
};
|
|
42
|
+
React.useEffect(() => {
|
|
43
|
+
if (!isEditing && popupOpened) {
|
|
44
|
+
popupRef.current.setLatLng(position).openOn(map.current);
|
|
45
|
+
if (isInDialog) {
|
|
46
|
+
setInterval(() => {
|
|
47
|
+
popupRef.current.update();
|
|
48
|
+
}, 1000);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}, [isEditing, isInDialog, map, popupOpened, position]);
|
|
52
|
+
return _jsxs(LeafletMarker, {
|
|
53
|
+
draggable: isEditing,
|
|
54
|
+
eventHandlers: {
|
|
55
|
+
dragend(e) {
|
|
56
|
+
updatePosition(e);
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
position: position,
|
|
60
|
+
icon: L.divIcon({
|
|
61
|
+
className: css.markerIcon,
|
|
62
|
+
html: ReactDOM.renderToString(_jsx(Icon, {}))
|
|
63
|
+
}),
|
|
64
|
+
children: [!isEditing && _jsx(Tooltip, {
|
|
65
|
+
sticky: true,
|
|
66
|
+
children: title
|
|
67
|
+
}), _jsx(Popup, {
|
|
68
|
+
ref: popupRef,
|
|
69
|
+
className: css.popup,
|
|
70
|
+
children: isEditing ? _jsx(EditForm, {
|
|
71
|
+
popupRef: popupRef,
|
|
72
|
+
marker: marker,
|
|
73
|
+
setMarkers: setMarkers,
|
|
74
|
+
iconSet: iconSet
|
|
75
|
+
}) : _jsx(PopupData, {
|
|
76
|
+
marker: marker
|
|
77
|
+
})
|
|
78
|
+
})]
|
|
79
|
+
}, id);
|
|
80
|
+
};
|
|
12
81
|
const Markers = ({
|
|
82
|
+
isInDialog,
|
|
83
|
+
map,
|
|
13
84
|
markers,
|
|
14
85
|
setMarkers,
|
|
15
86
|
iconSet
|
|
@@ -18,55 +89,15 @@ const Markers = ({
|
|
|
18
89
|
cmsMode
|
|
19
90
|
} = useUbloContext();
|
|
20
91
|
const isEditing = cmsMode === "editing";
|
|
21
|
-
return markers.map(marker => {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
const updatePosition = e => {
|
|
31
|
-
setMarkers(currents => {
|
|
32
|
-
return currents.map(marker => {
|
|
33
|
-
if (marker.id === id) {
|
|
34
|
-
return {
|
|
35
|
-
...marker,
|
|
36
|
-
position: e.target.getLatLng()
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
return marker;
|
|
40
|
-
});
|
|
41
|
-
});
|
|
42
|
-
};
|
|
43
|
-
return _jsxs(Marker, {
|
|
44
|
-
draggable: isEditing,
|
|
45
|
-
eventHandlers: {
|
|
46
|
-
dragend(e) {
|
|
47
|
-
updatePosition(e);
|
|
48
|
-
}
|
|
49
|
-
},
|
|
50
|
-
position: position,
|
|
51
|
-
icon: L.divIcon({
|
|
52
|
-
className: css.markerIcon,
|
|
53
|
-
html: ReactDOM.renderToString(_jsx(Icon, {}))
|
|
54
|
-
}),
|
|
55
|
-
children: [!isEditing && _jsx(Tooltip, {
|
|
56
|
-
sticky: true,
|
|
57
|
-
children: title
|
|
58
|
-
}), _jsx(Popup, {
|
|
59
|
-
ref: popupRef,
|
|
60
|
-
children: isEditing ? _jsx(EditForm, {
|
|
61
|
-
popupRef: popupRef,
|
|
62
|
-
marker: marker,
|
|
63
|
-
setMarkers: setMarkers,
|
|
64
|
-
iconSet: iconSet
|
|
65
|
-
}) : _jsx(PopupData, {
|
|
66
|
-
marker: marker
|
|
67
|
-
})
|
|
68
|
-
})]
|
|
69
|
-
}, id);
|
|
92
|
+
return markers.map((marker, i) => {
|
|
93
|
+
return _jsx(Marker, {
|
|
94
|
+
isInDialog: isInDialog,
|
|
95
|
+
map: map,
|
|
96
|
+
marker: marker,
|
|
97
|
+
setMarkers: setMarkers,
|
|
98
|
+
iconSet: iconSet,
|
|
99
|
+
isEditing: isEditing
|
|
100
|
+
}, i);
|
|
70
101
|
});
|
|
71
102
|
};
|
|
72
103
|
export default Markers;
|