utopia-ui 3.0.56 → 3.0.58

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 (138) hide show
  1. package/dist/index.cjs +1 -948
  2. package/dist/index.d.ts +269 -29
  3. package/dist/index.esm.js +1 -948
  4. package/dist/types/setupTest.d.ts +1 -0
  5. package/dist/types/src/Components/AppShell/AppShell.d.ts +7 -0
  6. package/dist/types/src/Components/AppShell/Content.d.ts +5 -0
  7. package/dist/types/src/Components/AppShell/ContextWrapper.d.ts +6 -0
  8. package/dist/types/src/Components/AppShell/NavBar.d.ts +4 -0
  9. package/dist/types/src/Components/AppShell/SetAppState.d.ts +5 -0
  10. package/dist/types/src/Components/AppShell/SideBar.d.ts +12 -0
  11. package/dist/types/src/Components/AppShell/SidebarSubmenu.d.ts +7 -0
  12. package/dist/types/src/Components/AppShell/Sitemap.d.ts +3 -0
  13. package/dist/types/src/Components/AppShell/hooks/useAppState.d.ts +16 -0
  14. package/dist/types/src/Components/AppShell/hooks/useAssets.d.ts +12 -0
  15. package/dist/types/src/Components/AppShell/index.d.ts +4 -0
  16. package/dist/types/src/Components/Auth/LoginPage.d.ts +1 -0
  17. package/dist/types/src/Components/Auth/RequestPasswordPage.d.ts +3 -0
  18. package/dist/types/src/Components/Auth/SetNewPasswordPage.d.ts +1 -0
  19. package/dist/types/src/Components/Auth/SignupPage.d.ts +1 -0
  20. package/dist/types/src/Components/Auth/index.d.ts +5 -0
  21. package/dist/types/src/Components/Auth/useAuth.d.ts +26 -0
  22. package/dist/types/src/Components/Gaming/Modal.d.ts +4 -0
  23. package/dist/types/src/Components/Gaming/Quests.d.ts +1 -0
  24. package/dist/types/src/Components/Gaming/hooks/useQuests.d.ts +12 -0
  25. package/dist/types/src/Components/Gaming/index.d.ts +2 -0
  26. package/dist/types/src/Components/Input/Autocomplete.d.ts +7 -0
  27. package/dist/types/src/Components/Input/ComboBoxInput.d.ts +8 -0
  28. package/dist/types/src/Components/Input/SelectBox.d.ts +16 -0
  29. package/dist/types/src/Components/Input/TextAreaInput.d.ts +13 -0
  30. package/dist/types/src/Components/Input/TextInput.d.ts +16 -0
  31. package/dist/types/src/Components/Input/TextInput.spec.d.ts +1 -0
  32. package/dist/types/src/Components/Input/index.d.ts +3 -0
  33. package/dist/types/src/Components/Map/ItemForm.d.ts +16 -0
  34. package/dist/types/src/Components/Map/ItemView.d.ts +14 -0
  35. package/dist/types/src/Components/Map/Layer.d.ts +2 -0
  36. package/dist/types/src/Components/Map/Permissions.d.ts +7 -0
  37. package/dist/types/src/Components/Map/Subcomponents/AddButton.d.ts +3 -0
  38. package/dist/types/src/Components/Map/Subcomponents/Controls/Control.d.ts +6 -0
  39. package/dist/types/src/Components/Map/Subcomponents/Controls/FilterControl.d.ts +1 -0
  40. package/dist/types/src/Components/Map/Subcomponents/Controls/GratitudeControl.d.ts +1 -0
  41. package/dist/types/src/Components/Map/Subcomponents/Controls/LayerControl.d.ts +1 -0
  42. package/dist/types/src/Components/Map/Subcomponents/Controls/LocateControl.d.ts +3 -0
  43. package/dist/types/src/Components/Map/Subcomponents/Controls/QuestControl.d.ts +1 -0
  44. package/dist/types/src/Components/Map/Subcomponents/Controls/SearchControl.d.ts +1 -0
  45. package/dist/types/src/Components/Map/Subcomponents/Controls/SidebarControl.d.ts +1 -0
  46. package/dist/types/src/Components/Map/Subcomponents/Controls/TagsControl.d.ts +1 -0
  47. package/dist/types/src/Components/Map/Subcomponents/ItemFormPopup.d.ts +2 -0
  48. package/dist/types/src/Components/Map/Subcomponents/ItemPopupComponents/HeaderView.d.ts +18 -0
  49. package/dist/types/src/Components/Map/Subcomponents/ItemPopupComponents/PopupButton.d.ts +8 -0
  50. package/dist/types/src/Components/Map/Subcomponents/ItemPopupComponents/PopupCheckboxInput.d.ts +6 -0
  51. package/dist/types/src/Components/Map/Subcomponents/ItemPopupComponents/PopupStartEndInput.d.ts +9 -0
  52. package/dist/types/src/Components/Map/Subcomponents/ItemPopupComponents/PopupTextAreaInput.d.ts +7 -0
  53. package/dist/types/src/Components/Map/Subcomponents/ItemPopupComponents/PopupTextInput.d.ts +7 -0
  54. package/dist/types/src/Components/Map/Subcomponents/ItemPopupComponents/StartEndView.d.ts +4 -0
  55. package/dist/types/src/Components/Map/Subcomponents/ItemPopupComponents/TextView.d.ts +7 -0
  56. package/dist/types/src/Components/Map/Subcomponents/ItemViewPopup.d.ts +8 -0
  57. package/dist/types/src/Components/Map/Subcomponents/SelectPosition.d.ts +3 -0
  58. package/dist/types/src/Components/Map/Tags.d.ts +6 -0
  59. package/dist/types/src/Components/Map/UtopiaMap.d.ts +4 -0
  60. package/dist/types/src/Components/Map/UtopiaMapInner.d.ts +4 -0
  61. package/dist/types/src/Components/Map/hooks/useClusterRef.d.ts +11 -0
  62. package/dist/types/src/Components/Map/hooks/useDebounce.d.ts +1 -0
  63. package/dist/types/src/Components/Map/hooks/useFilter.d.ts +40 -0
  64. package/dist/types/src/Components/Map/hooks/useItems.d.ts +26 -0
  65. package/dist/types/src/Components/Map/hooks/useLayers.d.ts +13 -0
  66. package/dist/types/src/Components/Map/hooks/useLeafletRefs.d.ts +21 -0
  67. package/dist/types/src/Components/Map/hooks/usePermissions.d.ts +23 -0
  68. package/dist/types/src/Components/Map/hooks/useSelectPosition.d.ts +23 -0
  69. package/dist/types/src/Components/Map/hooks/useTags.d.ts +23 -0
  70. package/dist/types/src/Components/Map/hooks/useTimeout.d.ts +4 -0
  71. package/dist/types/src/Components/Map/hooks/useWindowDimension.d.ts +4 -0
  72. package/dist/types/src/Components/Map/index.d.ts +13 -0
  73. package/dist/types/src/Components/Map/setItemLocation.d.ts +1 -0
  74. package/dist/types/src/Components/Profile/ProfileForm.d.ts +1 -0
  75. package/dist/types/src/Components/Profile/ProfileView.d.ts +4 -0
  76. package/dist/types/src/Components/Profile/Subcomponents/ActionsButton.d.ts +11 -0
  77. package/dist/types/src/Components/Profile/Subcomponents/AvatarWidget.d.ts +7 -0
  78. package/dist/types/src/Components/Profile/Subcomponents/ColorPicker.d.ts +6 -0
  79. package/dist/types/src/Components/Profile/Subcomponents/ContactInfoForm.d.ts +5 -0
  80. package/dist/types/src/Components/Profile/Subcomponents/ContactInfoView.d.ts +5 -0
  81. package/dist/types/src/Components/Profile/Subcomponents/FormHeader.d.ts +5 -0
  82. package/dist/types/src/Components/Profile/Subcomponents/GalleryView.d.ts +6 -0
  83. package/dist/types/src/Components/Profile/Subcomponents/GroupSubHeaderView.d.ts +6 -0
  84. package/dist/types/src/Components/Profile/Subcomponents/GroupSubheaderForm.d.ts +18 -0
  85. package/dist/types/src/Components/Profile/Subcomponents/LinkedItemsHeaderView.d.ts +10 -0
  86. package/dist/types/src/Components/Profile/Subcomponents/MarkdownHint.d.ts +1 -0
  87. package/dist/types/src/Components/Profile/Subcomponents/PlusButton.d.ts +7 -0
  88. package/dist/types/src/Components/Profile/Subcomponents/ProfileStartEndForm.d.ts +5 -0
  89. package/dist/types/src/Components/Profile/Subcomponents/ProfileStartEndView.d.ts +4 -0
  90. package/dist/types/src/Components/Profile/Subcomponents/ProfileTextForm.d.ts +10 -0
  91. package/dist/types/src/Components/Profile/Subcomponents/ProfileTextView.d.ts +7 -0
  92. package/dist/types/src/Components/Profile/Subcomponents/RelationCard.d.ts +6 -0
  93. package/dist/types/src/Components/Profile/Subcomponents/SocialShareBar.d.ts +6 -0
  94. package/dist/types/src/Components/Profile/Subcomponents/SocialShareButton.d.ts +6 -0
  95. package/dist/types/src/Components/Profile/Subcomponents/TagsWidget.d.ts +6 -0
  96. package/dist/types/src/Components/Profile/Templates/FlexForm.d.ts +7 -0
  97. package/dist/types/src/Components/Profile/Templates/FlexView.d.ts +4 -0
  98. package/dist/types/src/Components/Profile/Templates/OnepagerForm.d.ts +7 -0
  99. package/dist/types/src/Components/Profile/Templates/OnepagerView.d.ts +4 -0
  100. package/dist/types/src/Components/Profile/Templates/SimpleForm.d.ts +4 -0
  101. package/dist/types/src/Components/Profile/Templates/SimpleView.d.ts +4 -0
  102. package/dist/types/src/Components/Profile/Templates/TabsForm.d.ts +10 -0
  103. package/dist/types/src/Components/Profile/Templates/TabsView.d.ts +13 -0
  104. package/dist/types/src/Components/Profile/UserSettings.d.ts +1 -0
  105. package/dist/types/src/Components/Profile/hooks/useClickOutside.d.ts +2 -0
  106. package/dist/types/src/Components/Profile/index.d.ts +4 -0
  107. package/dist/types/src/Components/Profile/itemFunctions.d.ts +5 -0
  108. package/dist/types/src/Components/Templates/AttestationForm.d.ts +4 -0
  109. package/dist/types/src/Components/Templates/CardPage.d.ts +9 -0
  110. package/dist/types/src/Components/Templates/CircleLayout.d.ts +5 -0
  111. package/dist/types/src/Components/Templates/DateUserInfo.d.ts +4 -0
  112. package/dist/types/src/Components/Templates/DialogModal.d.ts +11 -0
  113. package/dist/types/src/Components/Templates/EmojiPicker.d.ts +10 -0
  114. package/dist/types/src/Components/Templates/ItemCard.d.ts +8 -0
  115. package/dist/types/src/Components/Templates/MapOverlayPage.d.ts +6 -0
  116. package/dist/types/src/Components/Templates/MarketView.d.ts +1 -0
  117. package/dist/types/src/Components/Templates/MoonCalendar.d.ts +1 -0
  118. package/dist/types/src/Components/Templates/OverlayItemsIndexPage.d.ts +6 -0
  119. package/dist/types/src/Components/Templates/SelectUser.d.ts +1 -0
  120. package/dist/types/src/Components/Templates/TagView.d.ts +7 -0
  121. package/dist/types/src/Components/Templates/TitleCard.d.ts +10 -0
  122. package/dist/types/src/Components/Templates/index.d.ts +8 -0
  123. package/dist/types/src/Components/Typography/ErrorText.d.ts +5 -0
  124. package/dist/types/src/Components/Typography/Subtitle.d.ts +5 -0
  125. package/dist/types/src/Utils/ContainsUUID.d.ts +1 -0
  126. package/dist/types/src/Utils/FormatTags.d.ts +2 -0
  127. package/dist/types/src/Utils/GetValue.d.ts +1 -0
  128. package/dist/types/src/Utils/HashTagRegex.d.ts +1 -0
  129. package/dist/types/src/Utils/MarkerIconFactory.d.ts +2 -0
  130. package/dist/types/src/Utils/Moon.d.ts +7 -0
  131. package/dist/types/src/Utils/RandomColor.d.ts +1 -0
  132. package/dist/types/src/Utils/ReplaceURLs.d.ts +3 -0
  133. package/dist/types/src/Utils/ReverseGeocoder.d.ts +1 -0
  134. package/dist/types/src/Utils/TimeAgo.d.ts +1 -0
  135. package/dist/types/src/index.d.ts +16 -0
  136. package/dist/types/src/types/index.d.ts +9 -0
  137. package/dist/types/vite.config.d.ts +2 -0
  138. package/package.json +6 -5
package/dist/index.cjs CHANGED
@@ -10,6 +10,7 @@ var reactToastify = require('react-toastify');
10
10
  require('leaflet/dist/leaflet.css');
11
11
  var MarkerClusterGroup = require('react-leaflet-cluster');
12
12
  var axios = require('axios');
13
+ require('leaflet.locatecontrol');
13
14
  require('leaflet.locatecontrol/dist/L.Control.Locate.css');
14
15
  var Markdown = require('react-markdown');
15
16
  var remarkBreaks = require('remark-breaks');
@@ -1496,954 +1497,6 @@ const MarkerIconFactory = (shape, color1, color2, icon) => {
1496
1497
  });
1497
1498
  };
1498
1499
 
1499
- /*!
1500
- Copyright (c) 2016 Dominik Moritz
1501
-
1502
- This file is part of the leaflet locate control. It is licensed under the MIT license.
1503
- You can find the project at: https://github.com/domoritz/leaflet-locatecontrol
1504
- */
1505
- (function (factory, window) {
1506
- // see https://github.com/Leaflet/Leaflet/blob/master/PLUGIN-GUIDE.md#module-loaders
1507
- // for details on how to structure a leaflet plugin.
1508
-
1509
- // define an AMD module that relies on 'leaflet'
1510
- if (typeof define === "function" && define.amd) {
1511
- define(["leaflet"], factory);
1512
-
1513
- // define a Common JS module that relies on 'leaflet'
1514
- } else if (typeof exports === "object") {
1515
- if (typeof window !== "undefined" && window.L) {
1516
- module.exports = factory(L);
1517
- } else {
1518
- module.exports = factory(require("leaflet"));
1519
- }
1520
- }
1521
-
1522
- // attach your plugin to the global 'L' variable
1523
- if (typeof window !== "undefined" && window.L) {
1524
- window.L.Control.Locate = factory(L);
1525
- }
1526
- })(function (L) {
1527
- const LDomUtilApplyClassesMethod = (method, element, classNames) => {
1528
- classNames = classNames.split(" ");
1529
- classNames.forEach(function (className) {
1530
- L.DomUtil[method].call(this, element, className);
1531
- });
1532
- };
1533
-
1534
- const addClasses = (el, names) => LDomUtilApplyClassesMethod("addClass", el, names);
1535
- const removeClasses = (el, names) => LDomUtilApplyClassesMethod("removeClass", el, names);
1536
-
1537
- /**
1538
- * Compatible with L.Circle but a true marker instead of a path
1539
- */
1540
- const LocationMarker = L.Marker.extend({
1541
- initialize(latlng, options) {
1542
- L.Util.setOptions(this, options);
1543
- this._latlng = latlng;
1544
- this.createIcon();
1545
- },
1546
-
1547
- /**
1548
- * Create a styled circle location marker
1549
- */
1550
- createIcon() {
1551
- const opt = this.options;
1552
-
1553
- let style = "";
1554
-
1555
- if (opt.color !== undefined) {
1556
- style += `stroke:${opt.color};`;
1557
- }
1558
- if (opt.weight !== undefined) {
1559
- style += `stroke-width:${opt.weight};`;
1560
- }
1561
- if (opt.fillColor !== undefined) {
1562
- style += `fill:${opt.fillColor};`;
1563
- }
1564
- if (opt.fillOpacity !== undefined) {
1565
- style += `fill-opacity:${opt.fillOpacity};`;
1566
- }
1567
- if (opt.opacity !== undefined) {
1568
- style += `opacity:${opt.opacity};`;
1569
- }
1570
-
1571
- const icon = this._getIconSVG(opt, style);
1572
-
1573
- this._locationIcon = L.divIcon({
1574
- className: icon.className,
1575
- html: icon.svg,
1576
- iconSize: [icon.w, icon.h]
1577
- });
1578
-
1579
- this.setIcon(this._locationIcon);
1580
- },
1581
-
1582
- /**
1583
- * Return the raw svg for the shape
1584
- *
1585
- * Split so can be easily overridden
1586
- */
1587
- _getIconSVG(options, style) {
1588
- const r = options.radius;
1589
- const w = options.weight;
1590
- const s = r + w;
1591
- const s2 = s * 2;
1592
- const svg =
1593
- `<svg xmlns="http://www.w3.org/2000/svg" width="${s2}" height="${s2}" version="1.1" viewBox="-${s} -${s} ${s2} ${s2}">` +
1594
- '<circle r="' +
1595
- r +
1596
- '" style="' +
1597
- style +
1598
- '" />' +
1599
- "</svg>";
1600
- return {
1601
- className: "leaflet-control-locate-location",
1602
- svg,
1603
- w: s2,
1604
- h: s2
1605
- };
1606
- },
1607
-
1608
- setStyle(style) {
1609
- L.Util.setOptions(this, style);
1610
- this.createIcon();
1611
- }
1612
- });
1613
-
1614
- const CompassMarker = LocationMarker.extend({
1615
- initialize(latlng, heading, options) {
1616
- L.Util.setOptions(this, options);
1617
- this._latlng = latlng;
1618
- this._heading = heading;
1619
- this.createIcon();
1620
- },
1621
-
1622
- setHeading(heading) {
1623
- this._heading = heading;
1624
- },
1625
-
1626
- /**
1627
- * Create a styled arrow compass marker
1628
- */
1629
- _getIconSVG(options, style) {
1630
- const r = options.radius;
1631
- const w = options.width + options.weight;
1632
- const h = (r + options.depth + options.weight) * 2;
1633
- const path = `M0,0 l${options.width / 2},${options.depth} l-${w},0 z`;
1634
- const svgstyle = `transform: rotate(${this._heading}deg)`;
1635
- const svg =
1636
- `<svg xmlns="http://www.w3.org/2000/svg" width="${w}" height="${h}" version="1.1" viewBox="-${w / 2} 0 ${w} ${h}" style="${svgstyle}">` +
1637
- '<path d="' +
1638
- path +
1639
- '" style="' +
1640
- style +
1641
- '" />' +
1642
- "</svg>";
1643
- return {
1644
- className: "leaflet-control-locate-heading",
1645
- svg,
1646
- w,
1647
- h
1648
- };
1649
- }
1650
- });
1651
-
1652
- const LocateControl = L.Control.extend({
1653
- options: {
1654
- /** Position of the control */
1655
- position: "topleft",
1656
- /** The layer that the user's location should be drawn on. By default creates a new layer. */
1657
- layer: undefined,
1658
- /**
1659
- * Automatically sets the map view (zoom and pan) to the user's location as it updates.
1660
- * While the map is following the user's location, the control is in the `following` state,
1661
- * which changes the style of the control and the circle marker.
1662
- *
1663
- * Possible values:
1664
- * - false: never updates the map view when location changes.
1665
- * - 'once': set the view when the location is first determined
1666
- * - 'always': always updates the map view when location changes.
1667
- * The map view follows the user's location.
1668
- * - 'untilPan': like 'always', except stops updating the
1669
- * view if the user has manually panned the map.
1670
- * The map view follows the user's location until she pans.
1671
- * - 'untilPanOrZoom': (default) like 'always', except stops updating the
1672
- * view if the user has manually panned the map.
1673
- * The map view follows the user's location until she pans.
1674
- */
1675
- setView: "untilPanOrZoom",
1676
- /** Keep the current map zoom level when setting the view and only pan. */
1677
- keepCurrentZoomLevel: false,
1678
- /** After activating the plugin by clicking on the icon, zoom to the selected zoom level, even when keepCurrentZoomLevel is true. Set to 'false' to disable this feature. */
1679
- initialZoomLevel: false,
1680
- /**
1681
- * This callback can be used to override the viewport tracking
1682
- * This function should return a LatLngBounds object.
1683
- *
1684
- * For example to extend the viewport to ensure that a particular LatLng is visible:
1685
- *
1686
- * getLocationBounds: function(locationEvent) {
1687
- * return locationEvent.bounds.extend([-33.873085, 151.219273]);
1688
- * },
1689
- */
1690
- getLocationBounds(locationEvent) {
1691
- return locationEvent.bounds;
1692
- },
1693
- /** Smooth pan and zoom to the location of the marker. Only works in Leaflet 1.0+. */
1694
- flyTo: false,
1695
- /**
1696
- * The user location can be inside and outside the current view when the user clicks on the
1697
- * control that is already active. Both cases can be configures separately.
1698
- * Possible values are:
1699
- * - 'setView': zoom and pan to the current location
1700
- * - 'stop': stop locating and remove the location marker
1701
- */
1702
- clickBehavior: {
1703
- /** What should happen if the user clicks on the control while the location is within the current view. */
1704
- inView: "stop",
1705
- /** What should happen if the user clicks on the control while the location is outside the current view. */
1706
- outOfView: "setView",
1707
- /**
1708
- * What should happen if the user clicks on the control while the location is within the current view
1709
- * and we could be following but are not. Defaults to a special value which inherits from 'inView';
1710
- */
1711
- inViewNotFollowing: "inView"
1712
- },
1713
- /**
1714
- * If set, save the map bounds just before centering to the user's
1715
- * location. When control is disabled, set the view back to the
1716
- * bounds that were saved.
1717
- */
1718
- returnToPrevBounds: false,
1719
- /**
1720
- * Keep a cache of the location after the user deactivates the control. If set to false, the user has to wait
1721
- * until the locate API returns a new location before they see where they are again.
1722
- */
1723
- cacheLocation: true,
1724
- /** If set, a circle that shows the location accuracy is drawn. */
1725
- drawCircle: true,
1726
- /** If set, the marker at the users' location is drawn. */
1727
- drawMarker: true,
1728
- /** If set and supported then show the compass heading */
1729
- showCompass: true,
1730
- /** The class to be used to create the marker. For example L.CircleMarker or L.Marker */
1731
- markerClass: LocationMarker,
1732
- /** The class us be used to create the compass bearing arrow */
1733
- compassClass: CompassMarker,
1734
- /** Accuracy circle style properties. NOTE these styles should match the css animations styles */
1735
- circleStyle: {
1736
- className: "leaflet-control-locate-circle",
1737
- color: "#136AEC",
1738
- fillColor: "#136AEC",
1739
- fillOpacity: 0.15,
1740
- weight: 0
1741
- },
1742
- /** Inner marker style properties. Only works if your marker class supports `setStyle`. */
1743
- markerStyle: {
1744
- className: "leaflet-control-locate-marker",
1745
- color: "#fff",
1746
- fillColor: "#2A93EE",
1747
- fillOpacity: 1,
1748
- weight: 3,
1749
- opacity: 1,
1750
- radius: 9
1751
- },
1752
- /** Compass */
1753
- compassStyle: {
1754
- fillColor: "#2A93EE",
1755
- fillOpacity: 1,
1756
- weight: 0,
1757
- color: "#fff",
1758
- opacity: 1,
1759
- radius: 9, // How far is the arrow is from the center of of the marker
1760
- width: 9, // Width of the arrow
1761
- depth: 6 // Length of the arrow
1762
- },
1763
- /**
1764
- * Changes to accuracy circle and inner marker while following.
1765
- * It is only necessary to provide the properties that should change.
1766
- */
1767
- followCircleStyle: {},
1768
- followMarkerStyle: {
1769
- // color: '#FFA500',
1770
- // fillColor: '#FFB000'
1771
- },
1772
- followCompassStyle: {},
1773
- /** The CSS class for the icon. For example fa-location-arrow or fa-map-marker */
1774
- icon: "leaflet-control-locate-location-arrow",
1775
- iconLoading: "leaflet-control-locate-spinner",
1776
- /** The element to be created for icons. For example span or i */
1777
- iconElementTag: "span",
1778
- /** The element to be created for the text. For example small or span */
1779
- textElementTag: "small",
1780
- /** Padding around the accuracy circle. */
1781
- circlePadding: [0, 0],
1782
- /** Use metric units. */
1783
- metric: true,
1784
- /**
1785
- * This callback can be used in case you would like to override button creation behavior.
1786
- * This is useful for DOM manipulation frameworks such as angular etc.
1787
- * This function should return an object with HtmlElement for the button (link property) and the icon (icon property).
1788
- */
1789
- createButtonCallback(container, options) {
1790
- const link = L.DomUtil.create("a", "leaflet-bar-part leaflet-bar-part-single", container);
1791
- link.title = options.strings.title;
1792
- link.href = "#";
1793
- link.setAttribute("role", "button");
1794
- const icon = L.DomUtil.create(options.iconElementTag, options.icon, link);
1795
-
1796
- if (options.strings.text !== undefined) {
1797
- const text = L.DomUtil.create(options.textElementTag, "leaflet-locate-text", link);
1798
- text.textContent = options.strings.text;
1799
- link.classList.add("leaflet-locate-text-active");
1800
- link.parentNode.style.display = "flex";
1801
- if (options.icon.length > 0) {
1802
- icon.classList.add("leaflet-locate-icon");
1803
- }
1804
- }
1805
-
1806
- return { link, icon };
1807
- },
1808
- /** This event is called in case of any location error that is not a time out error. */
1809
- onLocationError(err, control) {
1810
- alert(err.message);
1811
- },
1812
- /**
1813
- * This event is called when the user's location is outside the bounds set on the map.
1814
- * The event is called repeatedly when the location changes.
1815
- */
1816
- onLocationOutsideMapBounds(control) {
1817
- control.stop();
1818
- alert(control.options.strings.outsideMapBoundsMsg);
1819
- },
1820
- /** Display a pop-up when the user click on the inner marker. */
1821
- showPopup: true,
1822
- strings: {
1823
- title: "Show me where I am",
1824
- metersUnit: "meters",
1825
- feetUnit: "feet",
1826
- popup: "You are within {distance} {unit} from this point",
1827
- outsideMapBoundsMsg: "You seem located outside the boundaries of the map"
1828
- },
1829
- /** The default options passed to leaflets locate method. */
1830
- locateOptions: {
1831
- maxZoom: Infinity,
1832
- watch: true, // if you overwrite this, visualization cannot be updated
1833
- setView: false // have to set this to false because we have to
1834
- // do setView manually
1835
- }
1836
- },
1837
-
1838
- initialize(options) {
1839
- // set default options if nothing is set (merge one step deep)
1840
- for (const i in options) {
1841
- if (typeof this.options[i] === "object") {
1842
- L.extend(this.options[i], options[i]);
1843
- } else {
1844
- this.options[i] = options[i];
1845
- }
1846
- }
1847
-
1848
- // extend the follow marker style and circle from the normal style
1849
- this.options.followMarkerStyle = L.extend({}, this.options.markerStyle, this.options.followMarkerStyle);
1850
- this.options.followCircleStyle = L.extend({}, this.options.circleStyle, this.options.followCircleStyle);
1851
- this.options.followCompassStyle = L.extend({}, this.options.compassStyle, this.options.followCompassStyle);
1852
- },
1853
-
1854
- /**
1855
- * Add control to map. Returns the container for the control.
1856
- */
1857
- onAdd(map) {
1858
- const container = L.DomUtil.create("div", "leaflet-control-locate leaflet-bar leaflet-control");
1859
- this._container = container;
1860
- this._map = map;
1861
- this._layer = this.options.layer || new L.LayerGroup();
1862
- this._layer.addTo(map);
1863
- this._event = undefined;
1864
- this._compassHeading = null;
1865
- this._prevBounds = null;
1866
-
1867
- const linkAndIcon = this.options.createButtonCallback(container, this.options);
1868
- this._link = linkAndIcon.link;
1869
- this._icon = linkAndIcon.icon;
1870
-
1871
- L.DomEvent.on(
1872
- this._link,
1873
- "click",
1874
- function (ev) {
1875
- L.DomEvent.stopPropagation(ev);
1876
- L.DomEvent.preventDefault(ev);
1877
- this._onClick();
1878
- },
1879
- this
1880
- ).on(this._link, "dblclick", L.DomEvent.stopPropagation);
1881
-
1882
- this._resetVariables();
1883
-
1884
- this._map.on("unload", this._unload, this);
1885
-
1886
- return container;
1887
- },
1888
-
1889
- /**
1890
- * This method is called when the user clicks on the control.
1891
- */
1892
- _onClick() {
1893
- this._justClicked = true;
1894
- const wasFollowing = this._isFollowing();
1895
- this._userPanned = false;
1896
- this._userZoomed = false;
1897
-
1898
- if (this._active && !this._event) {
1899
- // click while requesting
1900
- this.stop();
1901
- } else if (this._active) {
1902
- const behaviors = this.options.clickBehavior;
1903
- let behavior = behaviors.outOfView;
1904
- if (this._map.getBounds().contains(this._event.latlng)) {
1905
- behavior = wasFollowing ? behaviors.inView : behaviors.inViewNotFollowing;
1906
- }
1907
-
1908
- // Allow inheriting from another behavior
1909
- if (behaviors[behavior]) {
1910
- behavior = behaviors[behavior];
1911
- }
1912
-
1913
- switch (behavior) {
1914
- case "setView":
1915
- this.setView();
1916
- break;
1917
- case "stop":
1918
- this.stop();
1919
- if (this.options.returnToPrevBounds) {
1920
- const f = this.options.flyTo ? this._map.flyToBounds : this._map.fitBounds;
1921
- f.bind(this._map)(this._prevBounds);
1922
- }
1923
- break;
1924
- }
1925
- } else {
1926
- if (this.options.returnToPrevBounds) {
1927
- this._prevBounds = this._map.getBounds();
1928
- }
1929
- this.start();
1930
- }
1931
-
1932
- this._updateContainerStyle();
1933
- },
1934
-
1935
- /**
1936
- * Starts the plugin:
1937
- * - activates the engine
1938
- * - draws the marker (if coordinates available)
1939
- */
1940
- start() {
1941
- this._activate();
1942
-
1943
- if (this._event) {
1944
- this._drawMarker(this._map);
1945
-
1946
- // if we already have a location but the user clicked on the control
1947
- if (this.options.setView) {
1948
- this.setView();
1949
- }
1950
- }
1951
- this._updateContainerStyle();
1952
- },
1953
-
1954
- /**
1955
- * Stops the plugin:
1956
- * - deactivates the engine
1957
- * - reinitializes the button
1958
- * - removes the marker
1959
- */
1960
- stop() {
1961
- this._deactivate();
1962
-
1963
- this._cleanClasses();
1964
- this._resetVariables();
1965
-
1966
- this._removeMarker();
1967
- },
1968
-
1969
- /**
1970
- * Keep the control active but stop following the location
1971
- */
1972
- stopFollowing() {
1973
- this._userPanned = true;
1974
- this._updateContainerStyle();
1975
- this._drawMarker();
1976
- },
1977
-
1978
- /**
1979
- * This method launches the location engine.
1980
- * It is called before the marker is updated,
1981
- * event if it does not mean that the event will be ready.
1982
- *
1983
- * Override it if you want to add more functionalities.
1984
- * It should set the this._active to true and do nothing if
1985
- * this._active is true.
1986
- */
1987
- _activate() {
1988
- if (this._active || !this._map) {
1989
- return;
1990
- }
1991
-
1992
- this._map.locate(this.options.locateOptions);
1993
- this._map.fire("locateactivate", this);
1994
- this._active = true;
1995
-
1996
- // bind event listeners
1997
- this._map.on("locationfound", this._onLocationFound, this);
1998
- this._map.on("locationerror", this._onLocationError, this);
1999
- this._map.on("dragstart", this._onDrag, this);
2000
- this._map.on("zoomstart", this._onZoom, this);
2001
- this._map.on("zoomend", this._onZoomEnd, this);
2002
- if (this.options.showCompass) {
2003
- const oriAbs = "ondeviceorientationabsolute" in window;
2004
- if (oriAbs || "ondeviceorientation" in window) {
2005
- const _this = this;
2006
- const deviceorientation = function () {
2007
- L.DomEvent.on(window, oriAbs ? "deviceorientationabsolute" : "deviceorientation", _this._onDeviceOrientation, _this);
2008
- };
2009
- if (DeviceOrientationEvent && typeof DeviceOrientationEvent.requestPermission === "function") {
2010
- DeviceOrientationEvent.requestPermission().then(function (permissionState) {
2011
- if (permissionState === "granted") {
2012
- deviceorientation();
2013
- }
2014
- });
2015
- } else {
2016
- deviceorientation();
2017
- }
2018
- }
2019
- }
2020
- },
2021
-
2022
- /**
2023
- * Called to stop the location engine.
2024
- *
2025
- * Override it to shutdown any functionalities you added on start.
2026
- */
2027
- _deactivate() {
2028
- if (!this._active || !this._map) {
2029
- return;
2030
- }
2031
-
2032
- this._map.stopLocate();
2033
- this._map.fire("locatedeactivate", this);
2034
- this._active = false;
2035
-
2036
- if (!this.options.cacheLocation) {
2037
- this._event = undefined;
2038
- }
2039
-
2040
- // unbind event listeners
2041
- this._map.off("locationfound", this._onLocationFound, this);
2042
- this._map.off("locationerror", this._onLocationError, this);
2043
- this._map.off("dragstart", this._onDrag, this);
2044
- this._map.off("zoomstart", this._onZoom, this);
2045
- this._map.off("zoomend", this._onZoomEnd, this);
2046
- if (this.options.showCompass) {
2047
- this._compassHeading = null;
2048
- if ("ondeviceorientationabsolute" in window) {
2049
- L.DomEvent.off(window, "deviceorientationabsolute", this._onDeviceOrientation, this);
2050
- } else if ("ondeviceorientation" in window) {
2051
- L.DomEvent.off(window, "deviceorientation", this._onDeviceOrientation, this);
2052
- }
2053
- }
2054
- },
2055
-
2056
- /**
2057
- * Zoom (unless we should keep the zoom level) and an to the current view.
2058
- */
2059
- setView() {
2060
- this._drawMarker();
2061
- if (this._isOutsideMapBounds()) {
2062
- this._event = undefined; // clear the current location so we can get back into the bounds
2063
- this.options.onLocationOutsideMapBounds(this);
2064
- } else {
2065
- if (this._justClicked && this.options.initialZoomLevel !== false) {
2066
- var f = this.options.flyTo ? this._map.flyTo : this._map.setView;
2067
- f.bind(this._map)([this._event.latitude, this._event.longitude], this.options.initialZoomLevel);
2068
- } else if (this.options.keepCurrentZoomLevel) {
2069
- var f = this.options.flyTo ? this._map.flyTo : this._map.panTo;
2070
- f.bind(this._map)([this._event.latitude, this._event.longitude]);
2071
- } else {
2072
- var f = this.options.flyTo ? this._map.flyToBounds : this._map.fitBounds;
2073
- // Ignore zoom events while setting the viewport as these would stop following
2074
- this._ignoreEvent = true;
2075
- f.bind(this._map)(this.options.getLocationBounds(this._event), {
2076
- padding: this.options.circlePadding,
2077
- maxZoom: this.options.initialZoomLevel || this.options.locateOptions.maxZoom
2078
- });
2079
- L.Util.requestAnimFrame(function () {
2080
- // Wait until after the next animFrame because the flyTo can be async
2081
- this._ignoreEvent = false;
2082
- }, this);
2083
- }
2084
- }
2085
- },
2086
-
2087
- /**
2088
- *
2089
- */
2090
- _drawCompass() {
2091
- if (!this._event) {
2092
- return;
2093
- }
2094
-
2095
- const latlng = this._event.latlng;
2096
-
2097
- if (this.options.showCompass && latlng && this._compassHeading !== null) {
2098
- const cStyle = this._isFollowing() ? this.options.followCompassStyle : this.options.compassStyle;
2099
- if (!this._compass) {
2100
- this._compass = new this.options.compassClass(latlng, this._compassHeading, cStyle).addTo(this._layer);
2101
- } else {
2102
- this._compass.setLatLng(latlng);
2103
- this._compass.setHeading(this._compassHeading);
2104
- // If the compassClass can be updated with setStyle, update it.
2105
- if (this._compass.setStyle) {
2106
- this._compass.setStyle(cStyle);
2107
- }
2108
- }
2109
- //
2110
- }
2111
- if (this._compass && (!this.options.showCompass || this._compassHeading === null)) {
2112
- this._compass.removeFrom(this._layer);
2113
- this._compass = null;
2114
- }
2115
- },
2116
-
2117
- /**
2118
- * Draw the marker and accuracy circle on the map.
2119
- *
2120
- * Uses the event retrieved from onLocationFound from the map.
2121
- */
2122
- _drawMarker() {
2123
- if (this._event.accuracy === undefined) {
2124
- this._event.accuracy = 0;
2125
- }
2126
-
2127
- const radius = this._event.accuracy;
2128
- const latlng = this._event.latlng;
2129
-
2130
- // circle with the radius of the location's accuracy
2131
- if (this.options.drawCircle) {
2132
- const style = this._isFollowing() ? this.options.followCircleStyle : this.options.circleStyle;
2133
-
2134
- if (!this._circle) {
2135
- this._circle = L.circle(latlng, radius, style).addTo(this._layer);
2136
- } else {
2137
- this._circle.setLatLng(latlng).setRadius(radius).setStyle(style);
2138
- }
2139
- }
2140
-
2141
- let distance;
2142
- let unit;
2143
- if (this.options.metric) {
2144
- distance = radius.toFixed(0);
2145
- unit = this.options.strings.metersUnit;
2146
- } else {
2147
- distance = (radius * 3.2808399).toFixed(0);
2148
- unit = this.options.strings.feetUnit;
2149
- }
2150
-
2151
- // small inner marker
2152
- if (this.options.drawMarker) {
2153
- const mStyle = this._isFollowing() ? this.options.followMarkerStyle : this.options.markerStyle;
2154
- if (!this._marker) {
2155
- this._marker = new this.options.markerClass(latlng, mStyle).addTo(this._layer);
2156
- } else {
2157
- this._marker.setLatLng(latlng);
2158
- // If the markerClass can be updated with setStyle, update it.
2159
- if (this._marker.setStyle) {
2160
- this._marker.setStyle(mStyle);
2161
- }
2162
- }
2163
- }
2164
-
2165
- this._drawCompass();
2166
-
2167
- const t = this.options.strings.popup;
2168
- function getPopupText() {
2169
- if (typeof t === "string") {
2170
- return L.Util.template(t, { distance, unit });
2171
- } else if (typeof t === "function") {
2172
- return t({ distance, unit });
2173
- } else {
2174
- return t;
2175
- }
2176
- }
2177
- if (this.options.showPopup && t && this._marker) {
2178
- this._marker.bindPopup(getPopupText())._popup.setLatLng(latlng);
2179
- }
2180
- if (this.options.showPopup && t && this._compass) {
2181
- this._compass.bindPopup(getPopupText())._popup.setLatLng(latlng);
2182
- }
2183
- },
2184
-
2185
- /**
2186
- * Remove the marker from map.
2187
- */
2188
- _removeMarker() {
2189
- this._layer.clearLayers();
2190
- this._marker = undefined;
2191
- this._circle = undefined;
2192
- },
2193
-
2194
- /**
2195
- * Unload the plugin and all event listeners.
2196
- * Kind of the opposite of onAdd.
2197
- */
2198
- _unload() {
2199
- this.stop();
2200
- this._map.off("unload", this._unload, this);
2201
- },
2202
-
2203
- /**
2204
- * Sets the compass heading
2205
- */
2206
- _setCompassHeading(angle) {
2207
- if (!isNaN(parseFloat(angle)) && isFinite(angle)) {
2208
- angle = Math.round(angle);
2209
-
2210
- this._compassHeading = angle;
2211
- L.Util.requestAnimFrame(this._drawCompass, this);
2212
- } else {
2213
- this._compassHeading = null;
2214
- }
2215
- },
2216
-
2217
- /**
2218
- * If the compass fails calibration just fail safely and remove the compass
2219
- */
2220
- _onCompassNeedsCalibration() {
2221
- this._setCompassHeading();
2222
- },
2223
-
2224
- /**
2225
- * Process and normalise compass events
2226
- */
2227
- _onDeviceOrientation(e) {
2228
- if (!this._active) {
2229
- return;
2230
- }
2231
-
2232
- if (e.webkitCompassHeading) {
2233
- // iOS
2234
- this._setCompassHeading(e.webkitCompassHeading);
2235
- } else if (e.absolute && e.alpha) {
2236
- // Android
2237
- this._setCompassHeading(360 - e.alpha);
2238
- }
2239
- },
2240
-
2241
- /**
2242
- * Calls deactivate and dispatches an error.
2243
- */
2244
- _onLocationError(err) {
2245
- // ignore time out error if the location is watched
2246
- if (err.code == 3 && this.options.locateOptions.watch) {
2247
- return;
2248
- }
2249
-
2250
- this.stop();
2251
- this.options.onLocationError(err, this);
2252
- },
2253
-
2254
- /**
2255
- * Stores the received event and updates the marker.
2256
- */
2257
- _onLocationFound(e) {
2258
- // no need to do anything if the location has not changed
2259
- if (this._event && this._event.latlng.lat === e.latlng.lat && this._event.latlng.lng === e.latlng.lng && this._event.accuracy === e.accuracy) {
2260
- return;
2261
- }
2262
-
2263
- if (!this._active) {
2264
- // we may have a stray event
2265
- return;
2266
- }
2267
-
2268
- this._event = e;
2269
-
2270
- this._drawMarker();
2271
- this._updateContainerStyle();
2272
-
2273
- switch (this.options.setView) {
2274
- case "once":
2275
- if (this._justClicked) {
2276
- this.setView();
2277
- }
2278
- break;
2279
- case "untilPan":
2280
- if (!this._userPanned) {
2281
- this.setView();
2282
- }
2283
- break;
2284
- case "untilPanOrZoom":
2285
- if (!this._userPanned && !this._userZoomed) {
2286
- this.setView();
2287
- }
2288
- break;
2289
- case "always":
2290
- this.setView();
2291
- break;
2292
- }
2293
-
2294
- this._justClicked = false;
2295
- },
2296
-
2297
- /**
2298
- * When the user drags. Need a separate event so we can bind and unbind event listeners.
2299
- */
2300
- _onDrag() {
2301
- // only react to drags once we have a location
2302
- if (this._event && !this._ignoreEvent) {
2303
- this._userPanned = true;
2304
- this._updateContainerStyle();
2305
- this._drawMarker();
2306
- }
2307
- },
2308
-
2309
- /**
2310
- * When the user zooms. Need a separate event so we can bind and unbind event listeners.
2311
- */
2312
- _onZoom() {
2313
- // only react to drags once we have a location
2314
- if (this._event && !this._ignoreEvent) {
2315
- this._userZoomed = true;
2316
- this._updateContainerStyle();
2317
- this._drawMarker();
2318
- }
2319
- },
2320
-
2321
- /**
2322
- * After a zoom ends update the compass and handle sideways zooms
2323
- */
2324
- _onZoomEnd() {
2325
- if (this._event) {
2326
- this._drawCompass();
2327
- }
2328
-
2329
- if (this._event && !this._ignoreEvent) {
2330
- // If we have zoomed in and out and ended up sideways treat it as a pan
2331
- if (this._marker && !this._map.getBounds().pad(-0.3).contains(this._marker.getLatLng())) {
2332
- this._userPanned = true;
2333
- this._updateContainerStyle();
2334
- this._drawMarker();
2335
- }
2336
- }
2337
- },
2338
-
2339
- /**
2340
- * Compute whether the map is following the user location with pan and zoom.
2341
- */
2342
- _isFollowing() {
2343
- if (!this._active) {
2344
- return false;
2345
- }
2346
-
2347
- if (this.options.setView === "always") {
2348
- return true;
2349
- } else if (this.options.setView === "untilPan") {
2350
- return !this._userPanned;
2351
- } else if (this.options.setView === "untilPanOrZoom") {
2352
- return !this._userPanned && !this._userZoomed;
2353
- }
2354
- },
2355
-
2356
- /**
2357
- * Check if location is in map bounds
2358
- */
2359
- _isOutsideMapBounds() {
2360
- if (this._event === undefined) {
2361
- return false;
2362
- }
2363
- return this._map.options.maxBounds && !this._map.options.maxBounds.contains(this._event.latlng);
2364
- },
2365
-
2366
- /**
2367
- * Toggles button class between following and active.
2368
- */
2369
- _updateContainerStyle() {
2370
- if (!this._container) {
2371
- return;
2372
- }
2373
-
2374
- if (this._active && !this._event) {
2375
- // active but don't have a location yet
2376
- this._setClasses("requesting");
2377
- } else if (this._isFollowing()) {
2378
- this._setClasses("following");
2379
- } else if (this._active) {
2380
- this._setClasses("active");
2381
- } else {
2382
- this._cleanClasses();
2383
- }
2384
- },
2385
-
2386
- /**
2387
- * Sets the CSS classes for the state.
2388
- */
2389
- _setClasses(state) {
2390
- if (state == "requesting") {
2391
- removeClasses(this._container, "active following");
2392
- addClasses(this._container, "requesting");
2393
-
2394
- removeClasses(this._icon, this.options.icon);
2395
- addClasses(this._icon, this.options.iconLoading);
2396
- } else if (state == "active") {
2397
- removeClasses(this._container, "requesting following");
2398
- addClasses(this._container, "active");
2399
-
2400
- removeClasses(this._icon, this.options.iconLoading);
2401
- addClasses(this._icon, this.options.icon);
2402
- } else if (state == "following") {
2403
- removeClasses(this._container, "requesting");
2404
- addClasses(this._container, "active following");
2405
-
2406
- removeClasses(this._icon, this.options.iconLoading);
2407
- addClasses(this._icon, this.options.icon);
2408
- }
2409
- },
2410
-
2411
- /**
2412
- * Removes all classes from button.
2413
- */
2414
- _cleanClasses() {
2415
- L.DomUtil.removeClass(this._container, "requesting");
2416
- L.DomUtil.removeClass(this._container, "active");
2417
- L.DomUtil.removeClass(this._container, "following");
2418
-
2419
- removeClasses(this._icon, this.options.iconLoading);
2420
- addClasses(this._icon, this.options.icon);
2421
- },
2422
-
2423
- /**
2424
- * Reinitializes state variables.
2425
- */
2426
- _resetVariables() {
2427
- // whether locate is active or not
2428
- this._active = false;
2429
-
2430
- // true if the control was clicked for the first time
2431
- // we need this so we can pan and zoom once we have the location
2432
- this._justClicked = false;
2433
-
2434
- // true if the user has panned the map after clicking the control
2435
- this._userPanned = false;
2436
-
2437
- // true if the user has zoomed the map after clicking the control
2438
- this._userZoomed = false;
2439
- }
2440
- });
2441
-
2442
- L.control.locate = (options) => new L.Control.Locate(options);
2443
-
2444
- return LocateControl;
2445
- }, window);
2446
-
2447
1500
  // Converts leaflet.locatecontrol to a React Component
2448
1501
  const LocateControl = () => {
2449
1502
  const map = reactLeaflet.useMap();