@reltio/components 1.4.2257 → 1.4.2259

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.
Files changed (91) hide show
  1. package/ReltioMap/ReltioMap.d.ts +5 -8
  2. package/ReltioMap/ReltioMap.js +31 -39
  3. package/ReltioMap/ReltioMap.spec.js +299 -104
  4. package/ReltioMap/components/ClusteredMarkers/ClusteredMarkers.d.ts +2 -1
  5. package/ReltioMap/components/ClusteredMarkers/ClusteredMarkers.js +11 -13
  6. package/ReltioMap/components/EntityMarker/EntityMarker.d.ts +2 -1
  7. package/ReltioMap/components/EntityMarker/EntityMarker.js +3 -3
  8. package/ReltioMap/components/PolygonDrawing/PolygonDrawing.d.ts +4 -0
  9. package/ReltioMap/components/PolygonDrawing/PolygonDrawing.js +18 -0
  10. package/ReltioMap/components/PolygonDrawing/crosshair.inline.svg.d.ts +1 -0
  11. package/ReltioMap/components/PolygonDrawing/crosshair.inline.svg.js +1 -0
  12. package/ReltioMap/components/PolygonDrawing/index.d.ts +2 -0
  13. package/ReltioMap/components/PolygonDrawing/index.js +2 -0
  14. package/ReltioMap/components/PolygonDrawing/polygonRingHelpers.d.ts +5 -0
  15. package/ReltioMap/components/PolygonDrawing/polygonRingHelpers.js +43 -0
  16. package/ReltioMap/components/PolygonDrawing/useDrawingCursors.d.ts +6 -0
  17. package/ReltioMap/components/PolygonDrawing/useDrawingCursors.js +87 -0
  18. package/ReltioMap/components/PolygonDrawing/usePolygonDrawing.d.ts +9 -0
  19. package/ReltioMap/components/PolygonDrawing/usePolygonDrawing.js +197 -0
  20. package/ReltioMap/components/PolygonDrawing/usePreviewPolylines.d.ts +7 -0
  21. package/ReltioMap/components/PolygonDrawing/usePreviewPolylines.js +38 -0
  22. package/ReltioMap/components/PolygonDrawing/useVertexHandles.d.ts +14 -0
  23. package/ReltioMap/components/PolygonDrawing/useVertexHandles.js +85 -0
  24. package/ReltioMap/components/TopRightMapControls/TopRightMapControls.d.ts +3 -3
  25. package/ReltioMap/components/TopRightMapControls/TopRightMapControls.js +4 -18
  26. package/ReltioMap/helpers.d.ts +2 -1
  27. package/ReltioMap/helpers.js +3 -11
  28. package/ReltioMap/types.d.ts +2 -2
  29. package/cjs/ReltioMap/ReltioMap.d.ts +5 -8
  30. package/cjs/ReltioMap/ReltioMap.js +29 -37
  31. package/cjs/ReltioMap/ReltioMap.spec.js +298 -103
  32. package/cjs/ReltioMap/components/ClusteredMarkers/ClusteredMarkers.d.ts +2 -1
  33. package/cjs/ReltioMap/components/ClusteredMarkers/ClusteredMarkers.js +11 -13
  34. package/cjs/ReltioMap/components/EntityMarker/EntityMarker.d.ts +2 -1
  35. package/cjs/ReltioMap/components/EntityMarker/EntityMarker.js +3 -3
  36. package/cjs/ReltioMap/components/PolygonDrawing/PolygonDrawing.d.ts +4 -0
  37. package/cjs/ReltioMap/components/PolygonDrawing/PolygonDrawing.js +22 -0
  38. package/cjs/ReltioMap/components/PolygonDrawing/crosshair.inline.svg.d.ts +1 -0
  39. package/cjs/ReltioMap/components/PolygonDrawing/crosshair.inline.svg.js +4 -0
  40. package/cjs/ReltioMap/components/PolygonDrawing/index.d.ts +2 -0
  41. package/cjs/ReltioMap/components/PolygonDrawing/index.js +7 -0
  42. package/cjs/ReltioMap/components/PolygonDrawing/polygonRingHelpers.d.ts +5 -0
  43. package/cjs/ReltioMap/components/PolygonDrawing/polygonRingHelpers.js +50 -0
  44. package/cjs/ReltioMap/components/PolygonDrawing/useDrawingCursors.d.ts +6 -0
  45. package/cjs/ReltioMap/components/PolygonDrawing/useDrawingCursors.js +91 -0
  46. package/cjs/ReltioMap/components/PolygonDrawing/usePolygonDrawing.d.ts +9 -0
  47. package/cjs/ReltioMap/components/PolygonDrawing/usePolygonDrawing.js +202 -0
  48. package/cjs/ReltioMap/components/PolygonDrawing/usePreviewPolylines.d.ts +7 -0
  49. package/cjs/ReltioMap/components/PolygonDrawing/usePreviewPolylines.js +42 -0
  50. package/cjs/ReltioMap/components/PolygonDrawing/useVertexHandles.d.ts +14 -0
  51. package/cjs/ReltioMap/components/PolygonDrawing/useVertexHandles.js +89 -0
  52. package/cjs/ReltioMap/components/TopRightMapControls/TopRightMapControls.d.ts +3 -3
  53. package/cjs/ReltioMap/components/TopRightMapControls/TopRightMapControls.js +3 -17
  54. package/cjs/ReltioMap/helpers.d.ts +2 -1
  55. package/cjs/ReltioMap/helpers.js +8 -15
  56. package/cjs/ReltioMap/types.d.ts +2 -2
  57. package/cjs/constants/index.d.ts +1 -1
  58. package/cjs/constants/index.js +2 -2
  59. package/cjs/constants/map.d.ts +1 -2
  60. package/cjs/constants/map.js +2 -5
  61. package/cjs/features/workflow/AddWorkflowDialog/styles.d.ts +1 -1
  62. package/cjs/icons/index.d.ts +0 -1
  63. package/cjs/icons/index.js +2 -4
  64. package/constants/index.d.ts +1 -1
  65. package/constants/index.js +1 -1
  66. package/constants/map.d.ts +1 -2
  67. package/constants/map.js +1 -4
  68. package/features/workflow/AddWorkflowDialog/styles.d.ts +1 -1
  69. package/icons/index.d.ts +0 -1
  70. package/icons/index.js +0 -1
  71. package/package.json +2 -2
  72. package/ReltioMap/components/DrawingManager/DrawingManager.d.ts +0 -2
  73. package/ReltioMap/components/DrawingManager/DrawingManager.js +0 -5
  74. package/ReltioMap/components/DrawingManager/index.d.ts +0 -1
  75. package/ReltioMap/components/DrawingManager/index.js +0 -1
  76. package/ReltioMap/components/DrawingManager/useDrawingManager.d.ts +0 -7
  77. package/ReltioMap/components/DrawingManager/useDrawingManager.js +0 -36
  78. package/ReltioMap/googleMock.test-data.d.ts +0 -1
  79. package/ReltioMap/googleMock.test-data.js +0 -109
  80. package/cjs/ReltioMap/components/DrawingManager/DrawingManager.d.ts +0 -2
  81. package/cjs/ReltioMap/components/DrawingManager/DrawingManager.js +0 -9
  82. package/cjs/ReltioMap/components/DrawingManager/index.d.ts +0 -1
  83. package/cjs/ReltioMap/components/DrawingManager/index.js +0 -5
  84. package/cjs/ReltioMap/components/DrawingManager/useDrawingManager.d.ts +0 -7
  85. package/cjs/ReltioMap/components/DrawingManager/useDrawingManager.js +0 -40
  86. package/cjs/ReltioMap/googleMock.test-data.d.ts +0 -1
  87. package/cjs/ReltioMap/googleMock.test-data.js +0 -113
  88. package/cjs/icons/Radius.d.ts +0 -3
  89. package/cjs/icons/Radius.js +0 -22
  90. package/icons/Radius.d.ts +0 -3
  91. package/icons/Radius.js +0 -17
@@ -6,6 +6,7 @@ type Props = {
6
6
  enabledClustering: boolean;
7
7
  options?: ClusteredMarkersOptions;
8
8
  onMarkerClick?: (marker: GeoPoint) => void;
9
+ disabled?: boolean;
9
10
  };
10
- export declare const ClusteredMarkers: React.MemoExoticComponent<({ entityMarkers, options, enabledClustering, onMarkerClick }: Props) => React.JSX.Element>;
11
+ export declare const ClusteredMarkers: React.MemoExoticComponent<({ entityMarkers, options, enabledClustering, onMarkerClick, disabled }: Props) => React.JSX.Element>;
11
12
  export {};
@@ -16,28 +16,26 @@ import React, { memo, useCallback, useEffect, useMemo, useState } from 'react';
16
16
  import { EntityMarker } from '../EntityMarker';
17
17
  import { CustomClusterRenderer } from './CustomClusterRenderer';
18
18
  export var ClusteredMarkers = memo(function (_a) {
19
- var entityMarkers = _a.entityMarkers, options = _a.options, enabledClustering = _a.enabledClustering, onMarkerClick = _a.onMarkerClick;
19
+ var entityMarkers = _a.entityMarkers, options = _a.options, enabledClustering = _a.enabledClustering, onMarkerClick = _a.onMarkerClick, disabled = _a.disabled;
20
20
  var _b = useState({}), markers = _b[0], setMarkers = _b[1];
21
21
  var map = useMap();
22
22
  var clusterer = useMemo(function () {
23
23
  if (!enabledClustering || !map)
24
24
  return null;
25
- return new MarkerClusterer({
26
- map: map,
27
- renderer: new CustomClusterRenderer(options),
28
- algorithmOptions: { maxZoom: options === null || options === void 0 ? void 0 : options.maxZoom }
29
- });
30
- }, [map, options, enabledClustering]);
31
- useEffect(function () {
32
- return function () {
33
- clusterer === null || clusterer === void 0 ? void 0 : clusterer.onRemove();
34
- };
35
- }, [entityMarkers]);
25
+ return new MarkerClusterer(__assign({ map: map, renderer: new CustomClusterRenderer(options), algorithmOptions: { maxZoom: options === null || options === void 0 ? void 0 : options.maxZoom } }, (disabled
26
+ ? {
27
+ onClusterClick: null
28
+ }
29
+ : {})));
30
+ }, [map, options, enabledClustering, disabled]);
36
31
  useEffect(function () {
37
32
  if (!clusterer)
38
33
  return;
39
34
  clusterer.clearMarkers();
40
35
  clusterer.addMarkers(Object.values(markers));
36
+ return function () {
37
+ clusterer.onRemove();
38
+ };
41
39
  }, [clusterer, markers]);
42
40
  var setMarkerRef = useCallback(function (marker, key) {
43
41
  setMarkers(function (markers) {
@@ -53,6 +51,6 @@ export var ClusteredMarkers = memo(function (_a) {
53
51
  }
54
52
  });
55
53
  }, []);
56
- return (React.createElement(React.Fragment, null, entityMarkers.filter(prop('point')).map(function (marker) { return (React.createElement(EntityMarker, { key: marker.id, marker: marker, clusterer: enabledClustering ? setMarkerRef : undefined, onClick: onMarkerClick })); })));
54
+ return (React.createElement(React.Fragment, null, entityMarkers.filter(prop('point')).map(function (marker) { return (React.createElement(EntityMarker, { key: marker.id, marker: marker, clusterer: enabledClustering ? setMarkerRef : undefined, onClick: onMarkerClick, disabled: disabled })); })));
57
55
  });
58
56
  ClusteredMarkers.displayName = 'ClusteredMarkers';
@@ -5,6 +5,7 @@ type Props = {
5
5
  marker: GeoPoint;
6
6
  onClick: (marker: GeoPoint) => void;
7
7
  clusterer?: (advancedMarker: google.maps.marker.AdvancedMarkerElement | null, id: string) => void;
8
+ disabled?: boolean;
8
9
  } & Omit<ComponentProps<typeof AdvancedMarker>, 'onClick' | 'position' | 'onMouseEnter' | 'onMouseLeave'>;
9
- declare const _default: React.MemoExoticComponent<({ marker, onClick, clusterer, ...otherProps }: Props) => React.JSX.Element>;
10
+ declare const _default: React.MemoExoticComponent<({ marker, onClick, clusterer, disabled, ...otherProps }: Props) => React.JSX.Element>;
10
11
  export default _default;
@@ -37,7 +37,7 @@ var hoveredMarkerIcon = svg2Url(HOVERED_MARKER);
37
37
  var markerIcon = svg2Url(MARKER);
38
38
  var EntityMarker = function (_a) {
39
39
  var _b;
40
- var marker = _a.marker, onClick = _a.onClick, clusterer = _a.clusterer, otherProps = __rest(_a, ["marker", "onClick", "clusterer"]);
40
+ var marker = _a.marker, onClick = _a.onClick, clusterer = _a.clusterer, disabled = _a.disabled, otherProps = __rest(_a, ["marker", "onClick", "clusterer", "disabled"]);
41
41
  var styles = useStyles();
42
42
  var _c = useState(false), hovered = _c[0], setHovered = _c[1];
43
43
  var activeEntityUri = useContext(EntityMarkerContext).activeEntityUri;
@@ -54,7 +54,7 @@ var EntityMarker = function (_a) {
54
54
  }, [clusterer, marker.id]);
55
55
  var anchorEl = (_b = advancedMarkerRef.current) === null || _b === void 0 ? void 0 : _b.element;
56
56
  return (React.createElement(React.Fragment, null,
57
- anchorEl && (React.createElement(Popper, { anchorEl: anchorEl, open: hovered, className: styles.popper, modal: false, placement: "top", modifiers: [
57
+ anchorEl && !disabled && (React.createElement(Popper, { anchorEl: anchorEl, open: hovered, className: styles.popper, modal: false, placement: "top", modifiers: [
58
58
  {
59
59
  name: 'offset',
60
60
  options: {
@@ -63,7 +63,7 @@ var EntityMarker = function (_a) {
63
63
  }
64
64
  ] },
65
65
  React.createElement(ProfileCard, { entity: marker.entity, onMouseOver: onMouseOver, onMouseOut: onMouseOut }))),
66
- React.createElement(AdvancedMarker, __assign({ ref: ref, position: position, onClick: handleClick, onMouseEnter: onMouseOver, onMouseLeave: onMouseOut }, otherProps),
66
+ React.createElement(AdvancedMarker, __assign({ ref: ref, position: position, onClick: disabled ? undefined : handleClick, onMouseEnter: disabled ? undefined : onMouseOver, onMouseLeave: disabled ? undefined : onMouseOut }, otherProps),
67
67
  React.createElement("img", { "data-reltio-id": "marker-icon", src: hovered || isActive ? hoveredMarkerIcon : markerIcon }))));
68
68
  };
69
69
  export default memo(EntityMarker);
@@ -0,0 +1,4 @@
1
+ import { UsePolygonDrawingParams } from './usePolygonDrawing';
2
+ type PolygonDrawingProps = Omit<UsePolygonDrawingParams, 'map'>;
3
+ export declare const PolygonDrawing: (props: PolygonDrawingProps) => any;
4
+ export {};
@@ -0,0 +1,18 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ import { useMap } from '@vis.gl/react-google-maps';
13
+ import { usePolygonDrawing } from './usePolygonDrawing';
14
+ export var PolygonDrawing = function (props) {
15
+ var map = useMap();
16
+ usePolygonDrawing(__assign(__assign({}, props), { map: map }));
17
+ return null;
18
+ };
@@ -0,0 +1 @@
1
+ export declare const CROSSHAIR = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"15\" height=\"15\" viewBox=\"0 0 15 15\" shape-rendering=\"crispEdges\">\n <g fill=\"#FFFFFF\">\n <rect x=\"6\" y=\"0\" width=\"3\" height=\"1\"/>\n <rect x=\"6\" y=\"1\" width=\"1\" height=\"1\"/>\n <rect x=\"8\" y=\"1\" width=\"1\" height=\"1\"/>\n <rect x=\"6\" y=\"2\" width=\"1\" height=\"1\"/>\n <rect x=\"8\" y=\"2\" width=\"1\" height=\"1\"/>\n <rect x=\"6\" y=\"3\" width=\"1\" height=\"1\"/>\n <rect x=\"8\" y=\"3\" width=\"1\" height=\"1\"/>\n <rect x=\"6\" y=\"4\" width=\"1\" height=\"1\"/>\n <rect x=\"8\" y=\"4\" width=\"1\" height=\"1\"/>\n <rect x=\"6\" y=\"5\" width=\"1\" height=\"1\"/>\n <rect x=\"8\" y=\"5\" width=\"1\" height=\"1\"/>\n <rect x=\"0\" y=\"6\" width=\"7\" height=\"1\"/>\n <rect x=\"8\" y=\"6\" width=\"7\" height=\"1\"/>\n <rect x=\"0\" y=\"7\" width=\"1\" height=\"1\"/>\n <rect x=\"14\" y=\"7\" width=\"1\" height=\"1\"/>\n <rect x=\"0\" y=\"8\" width=\"7\" height=\"1\"/>\n <rect x=\"8\" y=\"8\" width=\"7\" height=\"1\"/>\n <rect x=\"6\" y=\"9\" width=\"1\" height=\"1\"/>\n <rect x=\"8\" y=\"9\" width=\"1\" height=\"1\"/>\n <rect x=\"6\" y=\"10\" width=\"1\" height=\"1\"/>\n <rect x=\"8\" y=\"10\" width=\"1\" height=\"1\"/>\n <rect x=\"6\" y=\"11\" width=\"1\" height=\"1\"/>\n <rect x=\"8\" y=\"11\" width=\"1\" height=\"1\"/>\n <rect x=\"6\" y=\"12\" width=\"1\" height=\"1\"/>\n <rect x=\"8\" y=\"12\" width=\"1\" height=\"1\"/>\n <rect x=\"6\" y=\"13\" width=\"1\" height=\"1\"/>\n <rect x=\"8\" y=\"13\" width=\"1\" height=\"1\"/>\n <rect x=\"6\" y=\"14\" width=\"3\" height=\"1\"/>\n </g>\n <g fill=\"#000000\">\n <rect x=\"7\" y=\"1\" width=\"1\" height=\"1\"/>\n <rect x=\"7\" y=\"2\" width=\"1\" height=\"1\"/>\n <rect x=\"7\" y=\"3\" width=\"1\" height=\"1\"/>\n <rect x=\"7\" y=\"4\" width=\"1\" height=\"1\"/>\n <rect x=\"7\" y=\"5\" width=\"1\" height=\"1\"/>\n <rect x=\"7\" y=\"6\" width=\"1\" height=\"1\"/>\n <rect x=\"1\" y=\"7\" width=\"13\" height=\"1\"/>\n <rect x=\"7\" y=\"8\" width=\"1\" height=\"1\"/>\n <rect x=\"7\" y=\"9\" width=\"1\" height=\"1\"/>\n <rect x=\"7\" y=\"10\" width=\"1\" height=\"1\"/>\n <rect x=\"7\" y=\"11\" width=\"1\" height=\"1\"/>\n <rect x=\"7\" y=\"12\" width=\"1\" height=\"1\"/>\n <rect x=\"7\" y=\"13\" width=\"1\" height=\"1\"/>\n </g>\n</svg>";
@@ -0,0 +1 @@
1
+ export var CROSSHAIR = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"15\" height=\"15\" viewBox=\"0 0 15 15\" shape-rendering=\"crispEdges\">\n <g fill=\"#FFFFFF\">\n <rect x=\"6\" y=\"0\" width=\"3\" height=\"1\"/>\n <rect x=\"6\" y=\"1\" width=\"1\" height=\"1\"/>\n <rect x=\"8\" y=\"1\" width=\"1\" height=\"1\"/>\n <rect x=\"6\" y=\"2\" width=\"1\" height=\"1\"/>\n <rect x=\"8\" y=\"2\" width=\"1\" height=\"1\"/>\n <rect x=\"6\" y=\"3\" width=\"1\" height=\"1\"/>\n <rect x=\"8\" y=\"3\" width=\"1\" height=\"1\"/>\n <rect x=\"6\" y=\"4\" width=\"1\" height=\"1\"/>\n <rect x=\"8\" y=\"4\" width=\"1\" height=\"1\"/>\n <rect x=\"6\" y=\"5\" width=\"1\" height=\"1\"/>\n <rect x=\"8\" y=\"5\" width=\"1\" height=\"1\"/>\n <rect x=\"0\" y=\"6\" width=\"7\" height=\"1\"/>\n <rect x=\"8\" y=\"6\" width=\"7\" height=\"1\"/>\n <rect x=\"0\" y=\"7\" width=\"1\" height=\"1\"/>\n <rect x=\"14\" y=\"7\" width=\"1\" height=\"1\"/>\n <rect x=\"0\" y=\"8\" width=\"7\" height=\"1\"/>\n <rect x=\"8\" y=\"8\" width=\"7\" height=\"1\"/>\n <rect x=\"6\" y=\"9\" width=\"1\" height=\"1\"/>\n <rect x=\"8\" y=\"9\" width=\"1\" height=\"1\"/>\n <rect x=\"6\" y=\"10\" width=\"1\" height=\"1\"/>\n <rect x=\"8\" y=\"10\" width=\"1\" height=\"1\"/>\n <rect x=\"6\" y=\"11\" width=\"1\" height=\"1\"/>\n <rect x=\"8\" y=\"11\" width=\"1\" height=\"1\"/>\n <rect x=\"6\" y=\"12\" width=\"1\" height=\"1\"/>\n <rect x=\"8\" y=\"12\" width=\"1\" height=\"1\"/>\n <rect x=\"6\" y=\"13\" width=\"1\" height=\"1\"/>\n <rect x=\"8\" y=\"13\" width=\"1\" height=\"1\"/>\n <rect x=\"6\" y=\"14\" width=\"3\" height=\"1\"/>\n </g>\n <g fill=\"#000000\">\n <rect x=\"7\" y=\"1\" width=\"1\" height=\"1\"/>\n <rect x=\"7\" y=\"2\" width=\"1\" height=\"1\"/>\n <rect x=\"7\" y=\"3\" width=\"1\" height=\"1\"/>\n <rect x=\"7\" y=\"4\" width=\"1\" height=\"1\"/>\n <rect x=\"7\" y=\"5\" width=\"1\" height=\"1\"/>\n <rect x=\"7\" y=\"6\" width=\"1\" height=\"1\"/>\n <rect x=\"1\" y=\"7\" width=\"13\" height=\"1\"/>\n <rect x=\"7\" y=\"8\" width=\"1\" height=\"1\"/>\n <rect x=\"7\" y=\"9\" width=\"1\" height=\"1\"/>\n <rect x=\"7\" y=\"10\" width=\"1\" height=\"1\"/>\n <rect x=\"7\" y=\"11\" width=\"1\" height=\"1\"/>\n <rect x=\"7\" y=\"12\" width=\"1\" height=\"1\"/>\n <rect x=\"7\" y=\"13\" width=\"1\" height=\"1\"/>\n </g>\n</svg>";
@@ -0,0 +1,2 @@
1
+ export { PolygonDrawing } from './PolygonDrawing';
2
+ export { usePolygonDrawing } from './usePolygonDrawing';
@@ -0,0 +1,2 @@
1
+ export { PolygonDrawing } from './PolygonDrawing';
2
+ export { usePolygonDrawing } from './usePolygonDrawing';
@@ -0,0 +1,5 @@
1
+ export declare const buildPolygonFromVertices: (vertices: readonly google.maps.LatLng[], options: google.maps.PolygonOptions) => google.maps.Polygon;
2
+ export declare const serializeRing: (vertices: readonly google.maps.LatLng[]) => [number, number][];
3
+ export declare const validateRing: (vertices: readonly google.maps.LatLng[] | null | undefined) => boolean;
4
+ /** Drops the last vertex when it duplicates the previous (e.g. double-click emits an extra click at the same lat/lng). */
5
+ export declare const dedupeTrailingDuplicateVertex: (vertices: readonly google.maps.LatLng[]) => google.maps.LatLng[];
@@ -0,0 +1,43 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
13
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
14
+ if (ar || !(i in from)) {
15
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
16
+ ar[i] = from[i];
17
+ }
18
+ }
19
+ return to.concat(ar || Array.prototype.slice.call(from));
20
+ };
21
+ export var buildPolygonFromVertices = function (vertices, options) {
22
+ return new google.maps.Polygon(__assign({ paths: __spreadArray([], vertices, true), map: null }, options));
23
+ };
24
+ export var serializeRing = function (vertices) {
25
+ return vertices.map(function (v) { return [v.lat(), v.lng()]; });
26
+ };
27
+ export var validateRing = function (vertices) {
28
+ var _a;
29
+ return ((_a = vertices === null || vertices === void 0 ? void 0 : vertices.length) !== null && _a !== void 0 ? _a : 0) >= 3;
30
+ };
31
+ /** Drops the last vertex when it duplicates the previous (e.g. double-click emits an extra click at the same lat/lng). */
32
+ export var dedupeTrailingDuplicateVertex = function (vertices) {
33
+ var out = __spreadArray([], vertices, true);
34
+ if (out.length < 2) {
35
+ return out;
36
+ }
37
+ var last = out[out.length - 1];
38
+ var prev = out[out.length - 2];
39
+ if (last && prev && last.equals(prev)) {
40
+ out.pop();
41
+ }
42
+ return out;
43
+ };
@@ -0,0 +1,6 @@
1
+ export declare const MAP_DRAWING_CROSSHAIR_CURSOR: string;
2
+ type DrawingCursors = {
3
+ reapplyCursors: () => void;
4
+ };
5
+ export declare const useDrawingCursors: (map: google.maps.Map | null, isActive: boolean) => DrawingCursors;
6
+ export {};
@@ -0,0 +1,87 @@
1
+ import { useCallback, useEffect, useRef } from 'react';
2
+ import { svg2CursorUrl } from '@reltio/mdm-sdk';
3
+ import { CROSSHAIR } from './crosshair.inline.svg';
4
+ import { isDomElement } from '../../helpers';
5
+ var crosshairCursorDataUrl = svg2CursorUrl(CROSSHAIR);
6
+ export var MAP_DRAWING_CROSSHAIR_CURSOR = "url(\"".concat(crosshairCursorDataUrl, "\") 7 7, crosshair");
7
+ export var useDrawingCursors = function (map, isActive) {
8
+ var applyDrawingCursorsIfChangedRef = useRef(function () { });
9
+ var reapplyCursors = useCallback(function () {
10
+ applyDrawingCursorsIfChangedRef.current();
11
+ }, []);
12
+ useEffect(function () {
13
+ if (!map || !isActive) {
14
+ return undefined;
15
+ }
16
+ var mapDiv = map.getDiv();
17
+ var isMapDragging = false;
18
+ var lastCursor = '';
19
+ var moRaf = null;
20
+ var getCurrentCursor = function () { return (isMapDragging ? 'grabbing' : MAP_DRAWING_CROSSHAIR_CURSOR); };
21
+ var applyInlineCursorOnAdvancedMarkers = function (cursor) {
22
+ if (!isDomElement(mapDiv)) {
23
+ return;
24
+ }
25
+ mapDiv.querySelectorAll('gmp-advanced-marker').forEach(function (el) {
26
+ if (el instanceof HTMLElement) {
27
+ el.style.setProperty('cursor', cursor, 'important');
28
+ }
29
+ });
30
+ };
31
+ var apply = function () {
32
+ var cursor = getCurrentCursor();
33
+ if (isDomElement(mapDiv)) {
34
+ if (lastCursor !== cursor) {
35
+ lastCursor = cursor;
36
+ mapDiv.style.setProperty('cursor', cursor, 'important');
37
+ }
38
+ applyInlineCursorOnAdvancedMarkers(cursor);
39
+ }
40
+ };
41
+ var applyAfterDomMutations = function () {
42
+ if (!isDomElement(mapDiv) || moRaf !== null) {
43
+ return;
44
+ }
45
+ moRaf = requestAnimationFrame(function () {
46
+ moRaf = null;
47
+ applyInlineCursorOnAdvancedMarkers(getCurrentCursor());
48
+ });
49
+ };
50
+ var mapDomObserver = isDomElement(mapDiv) ? new MutationObserver(applyAfterDomMutations) : null;
51
+ if (mapDomObserver) {
52
+ mapDomObserver.observe(mapDiv, { childList: true, subtree: true });
53
+ }
54
+ var reapplyCursorsToDom = function () {
55
+ lastCursor = '';
56
+ apply();
57
+ };
58
+ applyDrawingCursorsIfChangedRef.current = reapplyCursorsToDom;
59
+ var dragStartListener = map.addListener('dragstart', function () {
60
+ isMapDragging = true;
61
+ apply();
62
+ });
63
+ var dragEndListener = map.addListener('dragend', function () {
64
+ isMapDragging = false;
65
+ apply();
66
+ });
67
+ apply();
68
+ return function () {
69
+ applyDrawingCursorsIfChangedRef.current = function () { };
70
+ if (moRaf !== null) {
71
+ cancelAnimationFrame(moRaf);
72
+ }
73
+ mapDomObserver === null || mapDomObserver === void 0 ? void 0 : mapDomObserver.disconnect();
74
+ if (isDomElement(mapDiv)) {
75
+ mapDiv.querySelectorAll('gmp-advanced-marker').forEach(function (el) {
76
+ if (el instanceof HTMLElement) {
77
+ el.style.removeProperty('cursor');
78
+ }
79
+ });
80
+ mapDiv.style.removeProperty('cursor');
81
+ }
82
+ google.maps.event.removeListener(dragStartListener);
83
+ google.maps.event.removeListener(dragEndListener);
84
+ };
85
+ }, [map, isActive]);
86
+ return { reapplyCursors: reapplyCursors };
87
+ };
@@ -0,0 +1,9 @@
1
+ export { MAP_DRAWING_CROSSHAIR_CURSOR } from './useDrawingCursors';
2
+ export type UsePolygonDrawingParams = {
3
+ map: google.maps.Map | null;
4
+ isActive: boolean;
5
+ previewPolylineOptions: google.maps.PolylineOptions;
6
+ completedPolygonOptions: google.maps.PolygonOptions;
7
+ onPolygonComplete: (polygon: google.maps.Polygon) => void;
8
+ };
9
+ export declare const usePolygonDrawing: ({ map, isActive, previewPolylineOptions, completedPolygonOptions, onPolygonComplete }: UsePolygonDrawingParams) => void;
@@ -0,0 +1,197 @@
1
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
2
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
3
+ if (ar || !(i in from)) {
4
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
5
+ ar[i] = from[i];
6
+ }
7
+ }
8
+ return to.concat(ar || Array.prototype.slice.call(from));
9
+ };
10
+ import { useCallback, useEffect, useRef, useState } from 'react';
11
+ import { isDomElement } from '../../helpers';
12
+ import { buildPolygonFromVertices, dedupeTrailingDuplicateVertex, validateRing } from './polygonRingHelpers';
13
+ import { MAP_DRAWING_CROSSHAIR_CURSOR, useDrawingCursors } from './useDrawingCursors';
14
+ import { usePreviewPolylines } from './usePreviewPolylines';
15
+ import { useVertexHandles } from './useVertexHandles';
16
+ export { MAP_DRAWING_CROSSHAIR_CURSOR } from './useDrawingCursors';
17
+ export var usePolygonDrawing = function (_a) {
18
+ var map = _a.map, isActive = _a.isActive, previewPolylineOptions = _a.previewPolylineOptions, completedPolygonOptions = _a.completedPolygonOptions, onPolygonComplete = _a.onPolygonComplete;
19
+ var _b = useState([]), vertices = _b[0], setVertices = _b[1];
20
+ var verticesRef = useRef([]);
21
+ var completionLockRef = useRef(false);
22
+ var previewPolylineOptionsRef = useRef(previewPolylineOptions);
23
+ previewPolylineOptionsRef.current = previewPolylineOptions;
24
+ verticesRef.current = vertices;
25
+ var prevDisableDoubleClickZoom = useRef(undefined);
26
+ var prevClickableIcons = useRef(undefined);
27
+ var prevDraggableCursor = useRef(undefined);
28
+ var syncDisposeVertexHandlesRef = useRef(function () { });
29
+ useEffect(function () {
30
+ if (map && isActive) {
31
+ setVertices([]);
32
+ completionLockRef.current = false;
33
+ }
34
+ else if (!isActive) {
35
+ setVertices([]);
36
+ }
37
+ }, [map, isActive]);
38
+ var reapplyCursors = useDrawingCursors(map, isActive).reapplyCursors;
39
+ var _c = usePreviewPolylines(map, previewPolylineOptionsRef, isActive), polylineRef = _c.polylineRef, rubberBandPolylineRef = _c.rubberBandPolylineRef, handleZIndexRef = _c.handleZIndexRef;
40
+ var reapplyCursorsRef = useRef(reapplyCursors);
41
+ reapplyCursorsRef.current = reapplyCursors;
42
+ var onPolygonCompleteRef = useRef(onPolygonComplete);
43
+ onPolygonCompleteRef.current = onPolygonComplete;
44
+ var completedPolygonOptionsRef = useRef(completedPolygonOptions);
45
+ completedPolygonOptionsRef.current = completedPolygonOptions;
46
+ var tryComplete = useCallback(function () {
47
+ var _a, _b;
48
+ if (completionLockRef.current) {
49
+ return;
50
+ }
51
+ var verts = dedupeTrailingDuplicateVertex(verticesRef.current);
52
+ if (!validateRing(verts)) {
53
+ return;
54
+ }
55
+ completionLockRef.current = true;
56
+ syncDisposeVertexHandlesRef.current();
57
+ (_a = rubberBandPolylineRef.current) === null || _a === void 0 ? void 0 : _a.setPath([]);
58
+ var polygon = buildPolygonFromVertices(verts, completedPolygonOptionsRef.current);
59
+ (_b = polylineRef.current) === null || _b === void 0 ? void 0 : _b.setPath([]);
60
+ setVertices([]);
61
+ reapplyCursorsRef.current();
62
+ onPolygonCompleteRef.current(polygon);
63
+ }, [polylineRef, rubberBandPolylineRef]);
64
+ var resetDraftPolygon = useCallback(function () {
65
+ var _a, _b;
66
+ if (verticesRef.current.length === 0) {
67
+ return;
68
+ }
69
+ setVertices([]);
70
+ (_a = polylineRef.current) === null || _a === void 0 ? void 0 : _a.setPath([]);
71
+ (_b = rubberBandPolylineRef.current) === null || _b === void 0 ? void 0 : _b.setPath([]);
72
+ reapplyCursorsRef.current();
73
+ }, [polylineRef, rubberBandPolylineRef]);
74
+ var tryCompleteRef = useRef(tryComplete);
75
+ tryCompleteRef.current = tryComplete;
76
+ var resetDraftPolygonRef = useRef(resetDraftPolygon);
77
+ resetDraftPolygonRef.current = resetDraftPolygon;
78
+ var previewPathVertexCountRef = useRef(0);
79
+ useVertexHandles({
80
+ map: map,
81
+ isActive: isActive,
82
+ vertices: vertices,
83
+ handleZIndexRef: handleZIndexRef,
84
+ onFirstHandleClick: tryComplete,
85
+ syncDisposeRef: syncDisposeVertexHandlesRef
86
+ });
87
+ useEffect(function () {
88
+ if (!isActive) {
89
+ previewPathVertexCountRef.current = 0;
90
+ return;
91
+ }
92
+ var line = polylineRef.current;
93
+ var band = rubberBandPolylineRef.current;
94
+ if (!line) {
95
+ return;
96
+ }
97
+ var path = line.getPath();
98
+ var prev = previewPathVertexCountRef.current;
99
+ var vertexCount = vertices.length;
100
+ if (vertexCount === 0) {
101
+ if (path.getLength() > 0) {
102
+ path.clear();
103
+ }
104
+ band === null || band === void 0 ? void 0 : band.setPath([]);
105
+ previewPathVertexCountRef.current = 0;
106
+ return;
107
+ }
108
+ var pathLen = path.getLength();
109
+ if (vertexCount < prev) {
110
+ line.setPath(vertices);
111
+ }
112
+ else if (vertexCount === prev + 1 && pathLen === prev) {
113
+ var added = vertices[vertexCount - 1];
114
+ if (added) {
115
+ path.push(added);
116
+ }
117
+ }
118
+ else if (vertexCount !== prev || pathLen !== vertexCount) {
119
+ line.setPath(vertices);
120
+ }
121
+ previewPathVertexCountRef.current = vertexCount;
122
+ var last = vertices[vertexCount - 1];
123
+ if (last) {
124
+ band === null || band === void 0 ? void 0 : band.setPath([last, last]);
125
+ }
126
+ }, [isActive, vertices, polylineRef, rubberBandPolylineRef]);
127
+ useEffect(function () {
128
+ if (!map || !isActive) {
129
+ return undefined;
130
+ }
131
+ prevDisableDoubleClickZoom.current = map.get('disableDoubleClickZoom');
132
+ prevClickableIcons.current = map.get('clickableIcons');
133
+ prevDraggableCursor.current = map.get('draggableCursor');
134
+ var mapDiv = map.getDiv();
135
+ var rubber = rubberBandPolylineRef;
136
+ var updateRubberBand = function (latLngFromEvent) {
137
+ var _a, _b, _c;
138
+ var verts = verticesRef.current;
139
+ if (!verts.length || !latLngFromEvent) {
140
+ (_a = rubber.current) === null || _a === void 0 ? void 0 : _a.setPath([]);
141
+ return;
142
+ }
143
+ var last = verts[verts.length - 1];
144
+ if (!last) {
145
+ (_b = rubber.current) === null || _b === void 0 ? void 0 : _b.setPath([]);
146
+ return;
147
+ }
148
+ (_c = rubber.current) === null || _c === void 0 ? void 0 : _c.setPath([last, latLngFromEvent]);
149
+ };
150
+ map.setOptions({
151
+ disableDoubleClickZoom: true,
152
+ clickableIcons: false,
153
+ draggableCursor: MAP_DRAWING_CROSSHAIR_CURSOR
154
+ });
155
+ var mouseMoveListener = map.addListener('mousemove', function (e) {
156
+ var _a;
157
+ updateRubberBand((_a = e.latLng) !== null && _a !== void 0 ? _a : null);
158
+ });
159
+ var onDrawingClick = function (e) {
160
+ var latLng = e.latLng;
161
+ if (!latLng) {
162
+ return;
163
+ }
164
+ if (completionLockRef.current) {
165
+ return;
166
+ }
167
+ setVertices(function (vs) { return __spreadArray(__spreadArray([], vs, true), [latLng], false); });
168
+ };
169
+ var clickListener = map.addListener('click', onDrawingClick);
170
+ var onMapDivDblClick = function (ev) {
171
+ ev.preventDefault();
172
+ ev.stopPropagation();
173
+ tryCompleteRef.current();
174
+ };
175
+ var onMapDivMouseLeave = function () {
176
+ resetDraftPolygonRef.current();
177
+ };
178
+ if (isDomElement(mapDiv)) {
179
+ mapDiv.addEventListener('dblclick', onMapDivDblClick, true);
180
+ mapDiv.addEventListener('mouseleave', onMapDivMouseLeave);
181
+ }
182
+ return function () {
183
+ var _a;
184
+ if (isDomElement(mapDiv)) {
185
+ mapDiv.removeEventListener('dblclick', onMapDivDblClick, true);
186
+ mapDiv.removeEventListener('mouseleave', onMapDivMouseLeave);
187
+ }
188
+ google.maps.event.removeListener(mouseMoveListener);
189
+ google.maps.event.removeListener(clickListener);
190
+ map.setOptions({
191
+ disableDoubleClickZoom: (_a = prevDisableDoubleClickZoom.current) !== null && _a !== void 0 ? _a : false,
192
+ clickableIcons: prevClickableIcons.current !== undefined ? prevClickableIcons.current : true,
193
+ draggableCursor: prevDraggableCursor.current
194
+ });
195
+ };
196
+ }, [map, isActive]);
197
+ };
@@ -0,0 +1,7 @@
1
+ import { type MutableRefObject, type RefObject } from 'react';
2
+ export type PreviewPolylinesRefs = {
3
+ polylineRef: RefObject<google.maps.Polyline | null>;
4
+ rubberBandPolylineRef: RefObject<google.maps.Polyline | null>;
5
+ handleZIndexRef: RefObject<number>;
6
+ };
7
+ export declare const usePreviewPolylines: (map: google.maps.Map | null, previewPolylineOptionsRef: MutableRefObject<google.maps.PolylineOptions>, isActive: boolean) => PreviewPolylinesRefs;
@@ -0,0 +1,38 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ import { useEffect, useRef } from 'react';
13
+ export var usePreviewPolylines = function (map, previewPolylineOptionsRef, isActive) {
14
+ var polylineRef = useRef(null);
15
+ var rubberBandPolylineRef = useRef(null);
16
+ var handleZIndexRef = useRef(4);
17
+ useEffect(function () {
18
+ var _a;
19
+ if (!map || !isActive) {
20
+ return undefined;
21
+ }
22
+ var options = previewPolylineOptionsRef.current;
23
+ var polyline = new google.maps.Polyline(__assign(__assign({ map: map, path: [] }, options), { clickable: false, draggable: false, editable: false }));
24
+ var previewBandZ = ((_a = options.zIndex) !== null && _a !== void 0 ? _a : 2) + 1;
25
+ var rubberBandPolyline = new google.maps.Polyline(__assign(__assign({ map: map, path: [] }, options), { clickable: false, draggable: false, editable: false, zIndex: previewBandZ, strokeOpacity: Math.min(1, typeof options.strokeOpacity === 'number' ? options.strokeOpacity * 0.65 : 0.65) }));
26
+ handleZIndexRef.current = previewBandZ + 2;
27
+ polylineRef.current = polyline;
28
+ rubberBandPolylineRef.current = rubberBandPolyline;
29
+ return function () {
30
+ polyline.setMap(null);
31
+ rubberBandPolyline.setMap(null);
32
+ polylineRef.current = null;
33
+ rubberBandPolylineRef.current = null;
34
+ };
35
+ // eslint-disable-next-line react-hooks/exhaustive-deps
36
+ }, [map, isActive]);
37
+ return { polylineRef: polylineRef, rubberBandPolylineRef: rubberBandPolylineRef, handleZIndexRef: handleZIndexRef };
38
+ };
@@ -0,0 +1,14 @@
1
+ import { type MutableRefObject, type RefObject } from 'react';
2
+ export type UseVertexHandlesParams = {
3
+ map: google.maps.Map | null;
4
+ isActive: boolean;
5
+ vertices: readonly google.maps.LatLng[];
6
+ handleZIndexRef: RefObject<number>;
7
+ onFirstHandleClick: () => void;
8
+ syncDisposeRef: MutableRefObject<() => void>;
9
+ };
10
+ /**
11
+ * N circular vertex markers. The first is clickable to close the ring; others swallow clicks to avoid
12
+ * double map-handling.
13
+ */
14
+ export declare const useVertexHandles: ({ map, isActive, vertices, handleZIndexRef, onFirstHandleClick, syncDisposeRef }: UseVertexHandlesParams) => void;
@@ -0,0 +1,85 @@
1
+ import { useEffect, useRef } from 'react';
2
+ import { MAP_DRAWING_CROSSHAIR_CURSOR } from './useDrawingCursors';
3
+ var createVertexHandleElement = function (isFirstHandle) {
4
+ var el = document.createElement('div');
5
+ el.style.width = '10px';
6
+ el.style.height = '10px';
7
+ el.style.borderRadius = '50%';
8
+ el.style.boxSizing = 'border-box';
9
+ el.style.backgroundColor = '#ffffff';
10
+ el.style.border = '1.25px solid #444444';
11
+ el.style.cursor = isFirstHandle ? 'pointer' : MAP_DRAWING_CROSSHAIR_CURSOR;
12
+ el.style.transform = 'translateY(50%)';
13
+ return el;
14
+ };
15
+ /**
16
+ * N circular vertex markers. The first is clickable to close the ring; others swallow clicks to avoid
17
+ * double map-handling.
18
+ */
19
+ export var useVertexHandles = function (_a) {
20
+ var map = _a.map, isActive = _a.isActive, vertices = _a.vertices, handleZIndexRef = _a.handleZIndexRef, onFirstHandleClick = _a.onFirstHandleClick, syncDisposeRef = _a.syncDisposeRef;
21
+ var markersRef = useRef([]);
22
+ var onFirstHandleClickRef = useRef(onFirstHandleClick);
23
+ onFirstHandleClickRef.current = onFirstHandleClick;
24
+ var dispose = function () {
25
+ markersRef.current.forEach(function (m) {
26
+ google.maps.event.clearInstanceListeners(m);
27
+ m.map = null;
28
+ });
29
+ markersRef.current = [];
30
+ };
31
+ useEffect(function () {
32
+ if (!map || !isActive) {
33
+ syncDisposeRef.current = function () {
34
+ dispose();
35
+ };
36
+ dispose();
37
+ return function () {
38
+ syncDisposeRef.current = function () { };
39
+ };
40
+ }
41
+ syncDisposeRef.current = dispose;
42
+ return function () {
43
+ syncDisposeRef.current = function () { };
44
+ dispose();
45
+ };
46
+ }, [map, isActive, syncDisposeRef]);
47
+ useEffect(function () {
48
+ if (!map || !isActive || typeof document === 'undefined') {
49
+ return;
50
+ }
51
+ if (vertices.length === 0) {
52
+ dispose();
53
+ return;
54
+ }
55
+ var handleZ = handleZIndexRef.current;
56
+ var AdvancedMarkerElement = google.maps.marker.AdvancedMarkerElement;
57
+ for (var i = markersRef.current.length; i < vertices.length; i += 1) {
58
+ var latLng = vertices[i];
59
+ if (!latLng) {
60
+ continue;
61
+ }
62
+ var isFirstHandle = i === 0;
63
+ var content = createVertexHandleElement(isFirstHandle);
64
+ var marker = new AdvancedMarkerElement({
65
+ map: map,
66
+ position: latLng,
67
+ content: content,
68
+ zIndex: handleZ + (isFirstHandle ? 1 : 0),
69
+ gmpClickable: true
70
+ });
71
+ if (isFirstHandle) {
72
+ google.maps.event.addListener(marker, 'click', function (e) {
73
+ e.stop();
74
+ onFirstHandleClickRef.current();
75
+ });
76
+ }
77
+ else {
78
+ google.maps.event.addListener(marker, 'click', function (e) {
79
+ e.stop();
80
+ });
81
+ }
82
+ markersRef.current.push(marker);
83
+ }
84
+ }, [map, isActive, vertices, handleZIndexRef]);
85
+ };