ublo-lib 1.6.18 → 1.6.20

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.
@@ -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
+ tooltipOpened
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: "Tooltip affich\xE9 par d\xE9faut",
83
+ checked: tooltipOpened,
84
+ onCheckedChange: updateMarker("tooltipOpened")
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: isInDialog,
55
+ scrollWheelZoom: scrollWheelZoom,
55
56
  className: css.map,
56
57
  attributionControl: false,
57
58
  children: [_jsx(TileLayer, {
@@ -5,7 +5,8 @@ const DEFAULT_MARKER_DATA = {
5
5
  title: "Nouveau point d'intérêt",
6
6
  description: "",
7
7
  url: "",
8
- label: ""
8
+ label: "",
9
+ tooltipOpened: false
9
10
  };
10
11
  const MapEvents = ({
11
12
  mapRef,
@@ -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,6 +9,69 @@ 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
+ marker,
14
+ setMarkers,
15
+ iconSet,
16
+ isEditing
17
+ }) => {
18
+ const popupRef = React.useRef();
19
+ const {
20
+ id,
21
+ icon,
22
+ title,
23
+ position,
24
+ tooltipOpened
25
+ } = marker;
26
+ const Icon = Icons[iconSet][icon] || Icons[iconSet].Location;
27
+ const updatePosition = e => {
28
+ setMarkers(currents => {
29
+ return currents.map(marker => {
30
+ if (marker.id === id) {
31
+ return {
32
+ ...marker,
33
+ position: e.target.getLatLng()
34
+ };
35
+ }
36
+ return marker;
37
+ });
38
+ });
39
+ };
40
+ const tooltipProps = tooltipOpened ? {
41
+ direction: "right",
42
+ permanent: true,
43
+ offset: [6, -14]
44
+ } : {
45
+ sticky: true
46
+ };
47
+ return _jsxs(LeafletMarker, {
48
+ draggable: isEditing,
49
+ eventHandlers: {
50
+ dragend(e) {
51
+ updatePosition(e);
52
+ }
53
+ },
54
+ position: position,
55
+ icon: L.divIcon({
56
+ className: css.markerIcon,
57
+ html: ReactDOM.renderToString(_jsx(Icon, {}))
58
+ }),
59
+ children: [!isEditing && _jsx(Tooltip, {
60
+ ...tooltipProps,
61
+ children: title
62
+ }), _jsx(Popup, {
63
+ ref: popupRef,
64
+ children: isEditing ? _jsx(EditForm, {
65
+ popupRef: popupRef,
66
+ marker: marker,
67
+ setMarkers: setMarkers,
68
+ iconSet: iconSet
69
+ }) : _jsx(PopupData, {
70
+ marker: marker
71
+ })
72
+ })]
73
+ }, id);
74
+ };
12
75
  const Markers = ({
13
76
  markers,
14
77
  setMarkers,
@@ -18,55 +81,13 @@ const Markers = ({
18
81
  cmsMode
19
82
  } = useUbloContext();
20
83
  const isEditing = cmsMode === "editing";
21
- return markers.map(marker => {
22
- const popupRef = React.createRef();
23
- const {
24
- id,
25
- icon,
26
- title,
27
- position
28
- } = marker;
29
- const Icon = Icons[iconSet][icon] || Icons[iconSet].Location;
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);
84
+ return markers.map((marker, i) => {
85
+ return _jsx(Marker, {
86
+ marker: marker,
87
+ setMarkers: setMarkers,
88
+ iconSet: iconSet,
89
+ isEditing: isEditing
90
+ }, i);
70
91
  });
71
92
  };
72
93
  export default Markers;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ublo-lib",
3
- "version": "1.6.18",
3
+ "version": "1.6.20",
4
4
  "peerDependencies": {
5
5
  "dt-design-system": "^2.1.0",
6
6
  "next": "^12.0.0",