@cashub/ui-elv 1.0.2 → 1.0.4

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 (310) hide show
  1. package/datetimePicker/index.js +2 -37
  2. package/esm/Tab/Tab.js +21 -0
  3. package/esm/Tab/TabList.js +160 -0
  4. package/esm/Tab/TabPanel.js +42 -0
  5. package/esm/Tab/TabTab.js +98 -0
  6. package/esm/Tab/index.js +23 -0
  7. package/esm/Tab/subComponent/TabContext.js +3 -0
  8. package/esm/Tab/subComponent/TabListV2.js +18 -0
  9. package/esm/Tab/subComponent/TabPanelV2.js +45 -0
  10. package/esm/Tab/subComponent/TabTabV2.js +56 -0
  11. package/esm/VerticalTab/TabList.js +20 -0
  12. package/esm/VerticalTab/TabPanel.js +45 -0
  13. package/esm/VerticalTab/TabTab.js +63 -0
  14. package/esm/VerticalTab/VerticalTab.js +34 -0
  15. package/esm/VerticalTab/index.js +9 -0
  16. package/esm/VerticalTab/subComponent/TabContext.js +3 -0
  17. package/esm/alert/Alert.js +22 -0
  18. package/esm/alert/index.js +1 -0
  19. package/esm/animate/Collapse.js +65 -0
  20. package/esm/animate/Loader.js +51 -0
  21. package/esm/animate/NumberCounter.js +45 -0
  22. package/esm/animate/PulseRing.js +26 -0
  23. package/esm/animate/Spinner.js +11 -0
  24. package/esm/animate/index.js +5 -0
  25. package/esm/assets/css/autocomplete.css +16 -0
  26. package/esm/assets/css/font.css +4 -0
  27. package/esm/assets/css/global.css +2 -0
  28. package/esm/assets/font/helvetica/Helvetica.ttf +0 -0
  29. package/esm/assets/font/nanumGothic/NanumGothic-Bold.ttf +0 -0
  30. package/esm/assets/font/nanumGothic/NanumGothic-ExtraBold.ttf +0 -0
  31. package/esm/assets/font/nanumGothic/NanumGothic-Regular.ttf +0 -0
  32. package/esm/assets/icons/app-management.png +0 -0
  33. package/esm/assets/icons/burger-black.png +0 -0
  34. package/esm/assets/icons/burger-white.png +0 -0
  35. package/esm/assets/icons/burger.png +0 -0
  36. package/esm/assets/icons/file.svg +1 -0
  37. package/esm/assets/icons/map_icon1.png +0 -0
  38. package/esm/assets/icons/map_icon4.png +0 -0
  39. package/esm/assets/images/bg-aside.png +0 -0
  40. package/esm/assets/images/bg-chart-circle.png +0 -0
  41. package/esm/assets/images/bg-chart-triangle.png +0 -0
  42. package/esm/assets/images/cashub-logo-only.png +0 -0
  43. package/esm/assets/images/default-user.jpg +0 -0
  44. package/esm/assets/images/logo-cashub.png +0 -0
  45. package/esm/assets/images/map.png +0 -0
  46. package/esm/assets/images/qrcode.png +0 -0
  47. package/esm/backdrop/BaseBackdrop.js +11 -0
  48. package/esm/backdrop/LoadingBackdrop.js +10 -0
  49. package/esm/backdrop/ModalBackdrop.js +8 -0
  50. package/esm/backdrop/index.js +3 -0
  51. package/esm/badge/Badge.js +19 -0
  52. package/esm/badge/BadgeDot.js +11 -0
  53. package/esm/badge/BadgeFill.js +42 -0
  54. package/esm/badge/BadgeFillTriangle.js +138 -0
  55. package/esm/badge/BadgeWithText.js +24 -0
  56. package/esm/badge/index.js +5 -0
  57. package/esm/billing/BarChart.js +45 -0
  58. package/esm/billing/Grid.js +38 -0
  59. package/esm/billing/Header2.js +19 -0
  60. package/esm/billing/Header3.js +31 -0
  61. package/esm/billing/Paragraph.js +27 -0
  62. package/esm/billing/ParagraphGroup.js +16 -0
  63. package/esm/billing/ParagraphText.js +20 -0
  64. package/esm/billing/Section.js +44 -0
  65. package/esm/billing/SectionBody.js +11 -0
  66. package/esm/billing/SectionHeader.js +20 -0
  67. package/esm/billing/__stories__/BarChart.stories.js_bak +46 -0
  68. package/esm/billing/__stories__/Grid.stories.js_bak +57 -0
  69. package/esm/billing/__stories__/Header2.stories.js_bak +62 -0
  70. package/esm/billing/__stories__/Header3.stories.js_bak +69 -0
  71. package/esm/billing/__stories__/Paragraph.stories.js_bak +84 -0
  72. package/esm/billing/__stories__/ParagraphGroup.stories.js_bak +68 -0
  73. package/esm/billing/__stories__/ParagraphText.stories.js_bak +64 -0
  74. package/esm/billing/__stories__/Section.stories.js_bak +115 -0
  75. package/esm/billing/__stories__/SectionBody.stories.js_bak +62 -0
  76. package/esm/billing/__stories__/SectionHeader.stories.js-bak +68 -0
  77. package/esm/breadcrumb/Breadcrumb.js +71 -0
  78. package/esm/breadcrumb/index.js +1 -0
  79. package/esm/button/Button.js +145 -0
  80. package/esm/button/ButtonGroup.js +54 -0
  81. package/esm/button/IconButton.js +64 -0
  82. package/esm/button/ScrollToTopButton.js +47 -0
  83. package/esm/button/index.js +4 -0
  84. package/esm/callout/Callout.js +45 -0
  85. package/esm/callout/index.js +1 -0
  86. package/esm/chart/BarChart.js +147 -0
  87. package/esm/chart/DoughnutChart.js +110 -0
  88. package/esm/chart/LineChart.js +140 -0
  89. package/esm/chart/SingleBarChart.js +35 -0
  90. package/esm/chart/index.js +5 -0
  91. package/esm/chart/utils/centerTextPlugin.js +56 -0
  92. package/esm/chart/utils/customTooltip.js +84 -0
  93. package/esm/chart/utils/customTooltipLifecyclePlugin.js +16 -0
  94. package/esm/chart/utils/htmlLegendPlugin.js +83 -0
  95. package/esm/chart/utils/index.js +3 -0
  96. package/esm/chart/utils/padEmptyChartBar.js +47 -0
  97. package/esm/chart/utils/tooltipElement.js +17 -0
  98. package/esm/chart/utils/xAxisLabelTooltipPlugin.js +101 -0
  99. package/esm/chart/utils/yAxisTopTitlePlugin.js +43 -0
  100. package/esm/container/FlexContainer.js +33 -0
  101. package/esm/container/index.js +1 -0
  102. package/esm/cropper/Cropper.js +47 -0
  103. package/esm/cropper/CropperModalHandler.js +34 -0
  104. package/esm/cropper/index.js +2 -0
  105. package/esm/cropper/subComponent/CropImageModal.js +72 -0
  106. package/{datetimePicker/DatetimePicker.js → esm/datetimePicker/DatetimePickerV3.js} +63 -31
  107. package/esm/datetimePicker/TimeInput.js +49 -0
  108. package/esm/datetimePicker/TimePickerStyle.js +58 -0
  109. package/esm/datetimePicker/TimePickerV2.js +199 -0
  110. package/esm/datetimePicker/accordion/Month.js +245 -0
  111. package/esm/datetimePicker/accordion/Year.js +275 -0
  112. package/esm/datetimePicker/index.js +4 -0
  113. package/esm/datetimePicker/provider/constant.js +38 -0
  114. package/esm/datetimePicker/subComponent/DateTimePickerContext.js +3 -0
  115. package/esm/datetimePicker/utils/GMTDate.js +9 -0
  116. package/esm/datetimePicker/utils/pad.js +7 -0
  117. package/esm/datetimePicker/utils/toUTC0.js +7 -0
  118. package/esm/descriptionList/DescriptionDetail.js +21 -0
  119. package/esm/descriptionList/DescriptionList.js +18 -0
  120. package/esm/descriptionList/DescriptionTerm.js +7 -0
  121. package/esm/descriptionList/index.js +3 -0
  122. package/esm/divider/Divider.js +24 -0
  123. package/esm/divider/index.js +1 -0
  124. package/esm/dropdown/Dropdown.js +48 -0
  125. package/esm/dropdown/DropdownButtonOption.js +36 -0
  126. package/esm/dropdown/DropdownContent.js +83 -0
  127. package/esm/dropdown/DropdownDivOption.js +19 -0
  128. package/esm/dropdown/DropdownItem.js +19 -0
  129. package/esm/dropdown/DropdownLinkOption.js +17 -0
  130. package/esm/dropdown/DropdownToggle.js +31 -0
  131. package/esm/dropdown/index.js +11 -0
  132. package/esm/dropdown/subComponent/DropdownContext.js +3 -0
  133. package/esm/dropzone/FileDropzone.js +472 -0
  134. package/esm/dropzone/ImageDropzone.js +327 -0
  135. package/esm/dropzone/index.js +2 -0
  136. package/esm/dropzone/subComponent/Message.js +19 -0
  137. package/esm/figure/IconFigure.js +35 -0
  138. package/esm/figure/ImageFigure.js +31 -0
  139. package/esm/figure/index.js +2 -0
  140. package/esm/file/HiddenFileInput.js +8 -0
  141. package/esm/file/index.js +1 -0
  142. package/esm/form/Checkbox.js +157 -0
  143. package/esm/form/Fieldset.js +11 -0
  144. package/esm/form/FormItem.js +15 -0
  145. package/esm/form/Input.js +59 -0
  146. package/esm/form/Label.js +54 -0
  147. package/esm/form/MutedText.js +14 -0
  148. package/esm/form/PasswordInput.js +40 -0
  149. package/esm/form/RadioButton.js +94 -0
  150. package/esm/form/SearchSelect.js +174 -0
  151. package/esm/form/Searchbox.js +91 -0
  152. package/esm/form/Slider.js +39 -0
  153. package/esm/form/SwitchButton.js +97 -0
  154. package/esm/form/Textarea.js +34 -0
  155. package/esm/form/TreeView.js +66 -0
  156. package/esm/form/index.js +14 -0
  157. package/esm/grid/Column.js +39 -0
  158. package/esm/grid/Grid.js +28 -0
  159. package/esm/grid/index.js +2 -0
  160. package/esm/heading/Heading1.js +14 -0
  161. package/esm/heading/Heading2.js +21 -0
  162. package/esm/heading/Heading3.js +42 -0
  163. package/esm/heading/index.js +3 -0
  164. package/esm/helmet/Helmet.js +17 -0
  165. package/esm/helmet/index.js +3 -0
  166. package/esm/iconbox/ApplicationIconBox.js +74 -0
  167. package/esm/iconbox/IconBox.js +60 -0
  168. package/esm/iconbox/IconBoxV2.js +63 -0
  169. package/esm/iconbox/index.js +3 -0
  170. package/esm/iconbox/subComponent/IconBoxFigure.js +43 -0
  171. package/esm/iconbox/subComponent/IconBoxImage.js +35 -0
  172. package/esm/image/ImageFluid.js +10 -0
  173. package/esm/image/UploadImage.js +243 -0
  174. package/esm/image/index.js +2 -0
  175. package/esm/index.js +47 -0
  176. package/esm/keyframe/Pulse.js +15 -0
  177. package/esm/keyframe/Spin.js +7 -0
  178. package/esm/layout/Aside.js +39 -0
  179. package/esm/layout/AsideHeader.jsx +27 -0
  180. package/esm/layout/Backdrop.js +16 -0
  181. package/esm/layout/Container.js +30 -0
  182. package/esm/layout/Footer.js +36 -0
  183. package/esm/layout/Header.jsx +55 -0
  184. package/esm/layout/Layout.jsx +84 -0
  185. package/esm/layout/Logo.jsx +17 -0
  186. package/esm/layout/MenuIcon.jsx +27 -0
  187. package/esm/layout/Sidebar.jsx +271 -0
  188. package/esm/layout/index.js +1 -0
  189. package/esm/link/LinkSpan.js +62 -0
  190. package/esm/link/index.js +1 -0
  191. package/esm/map/GoogleMap.js +439 -0
  192. package/esm/map/GoogleReverseGeolocation.js +193 -0
  193. package/esm/map/LeafletMap.js +224 -0
  194. package/esm/map/LeafletReverseGeolocation.js +94 -0
  195. package/esm/map/index.js +4 -0
  196. package/esm/map/subComponent/BasicLeafletMap.js +27 -0
  197. package/esm/map/subComponent/GoogleMapContainer.js +22 -0
  198. package/esm/map/subComponent/GoogleMapPopup.js +103 -0
  199. package/esm/map/subComponent/GoogleMapWrapper.js +34 -0
  200. package/esm/map/subComponent/LeafletDrawControl.js +116 -0
  201. package/esm/map/subComponent/LeafletMapContainer.js +166 -0
  202. package/esm/map/subComponent/MapSearchBoxControl.js +47 -0
  203. package/esm/modal/StateModal.js +169 -0
  204. package/esm/modal/TitleModal.js +241 -0
  205. package/esm/modal/index.js +2 -0
  206. package/esm/page/Disclaimer.js +121 -0
  207. package/esm/page/index.js +1 -0
  208. package/esm/paginate/Paginate.js +129 -0
  209. package/esm/paginate/index.js +1 -0
  210. package/esm/popover/Popover.js +82 -0
  211. package/esm/popover/index.js +1 -0
  212. package/esm/qrcode/QRCode.js +51 -0
  213. package/esm/qrcode/QRCodeContainter.js +27 -0
  214. package/esm/qrcode/index.js +2 -0
  215. package/esm/ribbon/Ribbon.js +35 -0
  216. package/esm/ribbon/index.js +1 -0
  217. package/esm/section/Section.js +126 -0
  218. package/esm/section/SectionBody.js +43 -0
  219. package/esm/section/SectionHeader.js +61 -0
  220. package/esm/section/SectionToolbar.js +11 -0
  221. package/esm/section/SectionToolbarItem.js +10 -0
  222. package/esm/section/index.js +5 -0
  223. package/esm/select/InputSelect.js +263 -0
  224. package/esm/select/Select.js +811 -0
  225. package/esm/select/index.js +2 -0
  226. package/esm/select/subComponent/Checkbox.js +40 -0
  227. package/esm/select/subComponent/Footer.js +6 -0
  228. package/esm/select/subComponent/ListBox.js +23 -0
  229. package/esm/select/subComponent/Option.js +37 -0
  230. package/esm/select/subComponent/OptionGroup.js +16 -0
  231. package/esm/select/subComponent/Options.js +25 -0
  232. package/esm/select/subComponent/SearchBox.js +51 -0
  233. package/esm/select/subComponent/SelectedMultipleCount.js +32 -0
  234. package/esm/select/subComponent/SelectedMultipleTags.js +47 -0
  235. package/esm/select/subComponent/SelectedMultipleText.js +63 -0
  236. package/esm/select/subComponent/SelectedSingle.js +10 -0
  237. package/esm/styles/GlobalStyle.js +328 -0
  238. package/esm/styles/config/breakpoint.style.js +7 -0
  239. package/esm/styles/config/header.style.js +4 -0
  240. package/esm/styles/config/sidebar.style.js +11 -0
  241. package/esm/styles/index.js +2 -0
  242. package/esm/styles/mixin/backgroundColor.js +38 -0
  243. package/esm/styles/mixin/borderColor.js +31 -0
  244. package/esm/styles/mixin/color.js +31 -0
  245. package/esm/styles/mixin/colorOnBackground.js +31 -0
  246. package/esm/styles/mixin/inputPlaceholder.js +24 -0
  247. package/esm/styles/mixin/media.js +15 -0
  248. package/esm/styles/mixin/rounded.js +24 -0
  249. package/esm/styles/mixin/scrollbar.js +26 -0
  250. package/esm/styles/theme/dark.theme.js +91 -0
  251. package/esm/styles/theme/light.theme.js +91 -0
  252. package/esm/styles/theme/white.theme.js +91 -0
  253. package/esm/styles/themes.js +9 -0
  254. package/esm/table/GridTable.js +329 -0
  255. package/esm/table/ImageBox.js +38 -0
  256. package/esm/table/InfiniteGridTable.js +396 -0
  257. package/esm/table/PermissionTable.js +57 -0
  258. package/esm/table/SimpleGridTable.js +136 -0
  259. package/esm/table/Table.js +559 -0
  260. package/esm/table/__mock__/columns.js +64 -0
  261. package/esm/table/__mock__/data.js +530 -0
  262. package/esm/table/hooks/index.js +2 -0
  263. package/esm/table/hooks/useCalculateDataRange.js +22 -0
  264. package/esm/table/hooks/useGenerateSort.js +32 -0
  265. package/esm/table/index.js +6 -0
  266. package/esm/table/subComponent/BaseTableHeadCell.js +54 -0
  267. package/esm/table/subComponent/GridTableFooter.js +17 -0
  268. package/esm/table/subComponent/GridTableHeadCell.js +13 -0
  269. package/esm/table/subComponent/Resizer.js +70 -0
  270. package/esm/table/subComponent/TableFooter.js +24 -0
  271. package/esm/table/subComponent/TableFooterInfo.js +6 -0
  272. package/esm/table/subComponent/TableFooterPager.js +26 -0
  273. package/esm/table/subComponent/TableHeadCell.js +12 -0
  274. package/esm/table/subComponent/TableSort.js +31 -0
  275. package/esm/tagify/TagifyStyle.js +54 -0
  276. package/esm/tagify/Tags.js +49 -0
  277. package/esm/tagify/index.js +3 -0
  278. package/esm/tagify/templates/getCreateButtonTemplate.js +12 -0
  279. package/esm/text/Paragraph.js +79 -0
  280. package/esm/text/index.js +1 -0
  281. package/esm/timeline/Timeline.js +132 -0
  282. package/esm/timeline/index.js +1 -0
  283. package/esm/toast/CustomToastContainer.js +38 -0
  284. package/esm/toast/MessageContainer.js +44 -0
  285. package/esm/toast/index.js +3 -0
  286. package/esm/toast/show.js +29 -0
  287. package/esm/toast/style.css +1 -0
  288. package/esm/tooltip/Tooltip.js +133 -0
  289. package/esm/tooltip/index.js +1 -0
  290. package/esm/treeView/TreeViewV2.js +32 -0
  291. package/esm/treeView/TreeflexStyle.js +43 -0
  292. package/esm/treeView/index.js +2 -0
  293. package/esm/wizard/Wizard.js +244 -0
  294. package/esm/wizard/index.js +1 -0
  295. package/helmet/index.js +3 -7
  296. package/index.js +0 -12
  297. package/layout/Sidebar.jsx +1 -1
  298. package/package.json +5 -4
  299. package/datetimePicker/DatePicker.js +0 -363
  300. package/datetimePicker/DatePickerV2.js +0 -407
  301. package/datetimePicker/DatetimePickerV2.js +0 -395
  302. package/datetimePicker/TimePicker.js +0 -317
  303. package/datetimePicker/hooks/index.js +0 -27
  304. package/datetimePicker/hooks/useChangeNumber.js +0 -42
  305. package/datetimePicker/hooks/useDecrease.js +0 -38
  306. package/datetimePicker/hooks/useIncrease.js +0 -38
  307. package/datetimePicker/subComponent/Accordion.js +0 -373
  308. package/datetimePicker/subComponent/CustomTimeInput.js +0 -47
  309. package/jsoneditor/JsonEditor.js +0 -142
  310. package/jsoneditor/index.js +0 -13
@@ -0,0 +1,439 @@
1
+ import { useState, useCallback, useRef, useMemo, useEffect } from 'react';
2
+ import { renderToString } from 'react-dom/server';
3
+ import { MarkerClusterer, SuperClusterAlgorithm } from '@googlemaps/markerclusterer';
4
+ import GoogleMapWrapper from './subComponent/GoogleMapWrapper';
5
+ import GoogleMapContainer from './subComponent/GoogleMapContainer';
6
+ import GoogleMapPopup from './subComponent/GoogleMapPopup';
7
+ import PrimaryMapIcon from '../assets/icons/map_icon1.png';
8
+ import MapIcon from '../assets/icons/map_icon4.png';
9
+ import { jsx as _jsx } from "react/jsx-runtime";
10
+ const GoogleMap = _ref => {
11
+ let {
12
+ apiKey,
13
+ height = 512,
14
+ zoom = 10,
15
+ data = {
16
+ defaultPosition: null,
17
+ position: null,
18
+ locations: [],
19
+ message: null
20
+ },
21
+ geoFence = false,
22
+ geoFenceOptions = {},
23
+ onError,
24
+ customPopup,
25
+ checkPrimaryLocation
26
+ } = _ref;
27
+ const [hasError, setHasError] = useState(true);
28
+ const [validLocations, setValidLocations] = useState([]);
29
+ const [validBounds, setValidBounds] = useState([]);
30
+ const handleError = useCallback(errorCode => {
31
+ if (onError) {
32
+ onError(errorCode);
33
+ }
34
+ }, [onError]);
35
+ useEffect(() => {
36
+ const {
37
+ defaultPosition,
38
+ position,
39
+ locations
40
+ } = data;
41
+ const validLocations = [];
42
+ const bounds = [];
43
+ if (!position && !defaultPosition) {
44
+ handleError('NO_COORDINATES');
45
+ setHasError(true);
46
+ return;
47
+ }
48
+ locations.forEach(location => {
49
+ let {
50
+ latitude,
51
+ longitude
52
+ } = location;
53
+ if (!latitude && latitude !== 0 || !longitude && longitude !== 0 || latitude === 0 && longitude === 0 || latitude === '0' && longitude === '0') {
54
+ return;
55
+ }
56
+
57
+ // make sure coordinate in number type
58
+ latitude = Number(latitude);
59
+ longitude = Number(longitude);
60
+ if (Number.isNaN(latitude) || Number.isNaN(longitude)) {
61
+ return;
62
+ }
63
+
64
+ // prevent duplicate LatLngBounds
65
+ if (!bounds.some(LatLng => {
66
+ return latitude === LatLng.lat && longitude === LatLng.lng;
67
+ })) {
68
+ bounds.push({
69
+ lat: latitude,
70
+ lng: longitude
71
+ });
72
+ }
73
+ validLocations.push({
74
+ ...location,
75
+ latitude,
76
+ longitude
77
+ });
78
+ });
79
+
80
+ // pass all checking
81
+ setHasError(false);
82
+ setValidLocations(validLocations);
83
+ setValidBounds(bounds);
84
+ }, [data, handleError]);
85
+ if (!hasError) {
86
+ return /*#__PURE__*/_jsx(GoogleMapWrapper, {
87
+ apiKey: apiKey,
88
+ height: height,
89
+ zoom: zoom,
90
+ defaultPosition: data.defaultPosition,
91
+ position: data.position,
92
+ locations: validLocations,
93
+ message: data.message,
94
+ bounds: validBounds,
95
+ geoFence: geoFence,
96
+ geoFenceOptions: geoFenceOptions,
97
+ onError: handleError,
98
+ customPopup: customPopup,
99
+ checkPrimaryLocation: checkPrimaryLocation,
100
+ children: /*#__PURE__*/_jsx(Map, {})
101
+ });
102
+ }
103
+ return /*#__PURE__*/_jsx("div", {});
104
+ };
105
+ const Map = _ref2 => {
106
+ let {
107
+ height,
108
+ zoom,
109
+ defaultPosition,
110
+ position,
111
+ locations,
112
+ message,
113
+ bounds,
114
+ geoFence,
115
+ geoFenceOptions,
116
+ customPopup,
117
+ checkPrimaryLocation
118
+ } = _ref2;
119
+ const ref = useRef(null);
120
+ const [map, setMap] = useState();
121
+ const [OverlappingMarkerSpiderfier, setOverlappingMarkerSpiderfier] = useState(null);
122
+ const options = useMemo(() => {
123
+ return {
124
+ zoom,
125
+ center: {
126
+ lat: 1,
127
+ lng: 1
128
+ },
129
+ scrollwheel: false,
130
+ zoomControl: true,
131
+ zoomControlOptions: {
132
+ position: window.google.maps.ControlPosition.LEFT_TOP
133
+ },
134
+ mapTypeControl: false,
135
+ scaleControl: false,
136
+ streetViewControl: false,
137
+ rotateControl: false,
138
+ fullscreenControl: false,
139
+ minZoom: 3,
140
+ maxZoom: 20,
141
+ restriction: {
142
+ latLngBounds: {
143
+ east: 179.9999,
144
+ north: 85,
145
+ south: -85,
146
+ west: -179.9999
147
+ },
148
+ strictBounds: true
149
+ }
150
+ };
151
+ }, [zoom]);
152
+
153
+ // setup map
154
+ useEffect(() => {
155
+ if (map) {
156
+ map.setOptions(options);
157
+ window.google.maps.event.addListenerOnce(map, 'idle', () => {
158
+ if (geoFence) {
159
+ map.setCenter({
160
+ lat: geoFenceOptions.latitude,
161
+ lng: geoFenceOptions.longitude
162
+ });
163
+ } else {
164
+ if (bounds.length === 1) {
165
+ // there is only one location, locate it
166
+ map.setCenter(bounds[0]);
167
+ } else if (locations.length > 0) {
168
+ // locate to the center of all coordinates on first load
169
+ const latLngBounds = new window.google.maps.LatLngBounds();
170
+ bounds.forEach(bound => {
171
+ latLngBounds.extend(bound);
172
+ });
173
+ map.fitBounds(latLngBounds);
174
+ const found = locations.find(location => {
175
+ return latLngBounds.contains({
176
+ lat: location.latitude,
177
+ lng: location.longitude
178
+ });
179
+ });
180
+
181
+ // if center no contain any marker then locate to first location
182
+ if (!found) {
183
+ map.setCenter(bounds[0]);
184
+ }
185
+ } else {
186
+ map.setCenter({
187
+ lat: position && position.latitude || defaultPosition.latitude,
188
+ lng: position && position.longitude || defaultPosition.longitude
189
+ });
190
+ }
191
+ }
192
+ });
193
+ return () => {
194
+ window.google.maps.event.clearListeners(map, 'click');
195
+ };
196
+ }
197
+ }, [map, options, locations, bounds, defaultPosition, position, geoFence, geoFenceOptions.latitude, geoFenceOptions.longitude]);
198
+
199
+ // render marker cluster
200
+ useEffect(() => {
201
+ if (map && OverlappingMarkerSpiderfier && locations.length > 0) {
202
+ const markers = [];
203
+
204
+ // set up popup
205
+ const popup = new GoogleMapPopup({
206
+ maxWidth: 400,
207
+ offset: 36
208
+ });
209
+ map.addListener('click', () => {
210
+ popup.setMap(null);
211
+ });
212
+ const oms = new OverlappingMarkerSpiderfier.default(map, {
213
+ markersWontMove: true,
214
+ markersWontHide: true,
215
+ basicFormatEvents: true
216
+ });
217
+ locations.forEach(location => {
218
+ const {
219
+ latitude,
220
+ longitude
221
+ } = location;
222
+ let icon;
223
+ if (checkPrimaryLocation && checkPrimaryLocation(location)) {
224
+ icon = {
225
+ url: PrimaryMapIcon,
226
+ scaledSize: new window.google.maps.Size(40, 50)
227
+ };
228
+ } else {
229
+ icon = {
230
+ url: MapIcon,
231
+ scaledSize: new window.google.maps.Size(40, 50)
232
+ };
233
+ }
234
+ const marker = new window.google.maps.Marker({
235
+ icon,
236
+ map,
237
+ position: {
238
+ lat: latitude,
239
+ lng: longitude
240
+ }
241
+ });
242
+ if (customPopup) {
243
+ marker.addListener('click', event => {
244
+ event.stop();
245
+ const coordinate = {
246
+ lat: latitude,
247
+ lng: longitude
248
+ };
249
+ popup.setMap(map);
250
+ popup.setPosition(coordinate);
251
+ popup.setContent(renderToString(customPopup(location)));
252
+ popup.draw();
253
+ });
254
+ }
255
+ markers.push(marker);
256
+ oms.addMarker(marker);
257
+ });
258
+ const markerClusterer = new MarkerClusterer({
259
+ map,
260
+ markers,
261
+ algorithm: new SuperClusterAlgorithm({
262
+ radius: 120
263
+ }),
264
+ onClusterClick: (event, cluster, map) => {
265
+ // fix: cluster marker spiderfier
266
+ // const targetPosition = cluster.markers[0].getPosition().toJSON();
267
+ // const isAllSamePosition = cluster.markers.every((marker) => {
268
+ // const position = marker.getPosition().toJSON();
269
+ // return (
270
+ // targetPosition.lat === position.lat &&
271
+ // targetPosition.lng === position.lng
272
+ // );
273
+ // });
274
+ // if (isAllSamePosition) {
275
+ // return;
276
+ // }
277
+
278
+ // fix: need to call twice to actually work
279
+ map.fitBounds(cluster.bounds);
280
+ map.fitBounds(cluster.bounds);
281
+
282
+ // check current view has marker, if not set view to first marker
283
+ const currentBounds = map.getBounds();
284
+ const found = cluster.markers.find(marker => {
285
+ return currentBounds.contains(marker.getPosition());
286
+ });
287
+ if (!found) {
288
+ map.setCenter(cluster.markers[0].getPosition());
289
+ }
290
+ }
291
+ });
292
+ return () => {
293
+ popup.setMap(null);
294
+ markerClusterer.setMap(null);
295
+ markers.forEach(marker => {
296
+ marker.setMap(null);
297
+ });
298
+ };
299
+ }
300
+ }, [map, OverlappingMarkerSpiderfier, locations, checkPrimaryLocation, customPopup]);
301
+
302
+ // geofencing
303
+ useEffect(() => {
304
+ if (map && geoFence) {
305
+ const circle = new window.google.maps.Circle({
306
+ strokeColor: '#597EF7',
307
+ strokeOpacity: 0,
308
+ strokeWeight: 0,
309
+ fillColor: '#597EF7',
310
+ fillOpacity: 0.5,
311
+ center: {
312
+ lat: geoFenceOptions.latitude,
313
+ lng: geoFenceOptions.longitude
314
+ },
315
+ radius: geoFenceOptions.radius,
316
+ editable: geoFenceOptions.editable,
317
+ draggable: geoFenceOptions.editable
318
+ });
319
+ circle.setMap(map);
320
+
321
+ // add event listener
322
+ if (geoFenceOptions.eventHandlers) {
323
+ const {
324
+ click,
325
+ edit,
326
+ drag
327
+ } = geoFenceOptions.eventHandlers;
328
+ if (click) {
329
+ window.google.maps.event.addListener(circle, 'click', click);
330
+ }
331
+ if (edit) {
332
+ circle.addListener('radius_changed', () => {
333
+ const radius = circle.getRadius();
334
+ if (geoFenceOptions.minRadius && radius < geoFenceOptions.minRadius) {
335
+ circle.setRadius(geoFenceOptions.minRadius);
336
+ return;
337
+ }
338
+ edit(circle.getRadius());
339
+ });
340
+ }
341
+ if (drag) {
342
+ circle.addListener('center_changed', () => {
343
+ drag(circle.getCenter().toJSON());
344
+ });
345
+ }
346
+ }
347
+ let repositionButton;
348
+ if (geoFenceOptions.enabledReposition) {
349
+ repositionButton = document.createElement('button');
350
+ repositionButton.style.margin = 'var(--spacing-s)';
351
+ repositionButton.style.padding = 'var(--spacing-xs)';
352
+ repositionButton.style.boxShadow = 'rgba(0, 0, 0, 0.3) 0px 1px 4px -1px';
353
+ repositionButton.style.border = 'none';
354
+ repositionButton.style.borderRadius = '2px';
355
+ repositionButton.style.cursor = 'pointer';
356
+ repositionButton.style.backgroundColor = 'rgb(255, 255, 255)';
357
+ repositionButton.style.fontSize = '1rem';
358
+ repositionButton.textContent = 'Reposition';
359
+ repositionButton.title = 'Click to reposition the map to geofence';
360
+ repositionButton.type = 'button';
361
+ repositionButton.addEventListener('click', () => {
362
+ map.setCenter({
363
+ lat: geoFenceOptions.latitude,
364
+ lng: geoFenceOptions.longitude
365
+ });
366
+ });
367
+ const controlDiv = document.createElement('div');
368
+ controlDiv.appendChild(repositionButton);
369
+ map.controls[google.maps.ControlPosition.RIGHT_BOTTOM].push(controlDiv);
370
+ }
371
+ return () => {
372
+ circle.setMap(null);
373
+ window.google.maps.event.clearListeners(circle, 'click');
374
+ window.google.maps.event.clearListeners(circle, 'radius_changed');
375
+ window.google.maps.event.clearListeners(circle, 'center_changed');
376
+
377
+ // remove reposition button if exist
378
+ const rightBottonControls = map.controls[google.maps.ControlPosition.RIGHT_BOTTOM];
379
+ if (rightBottonControls.getAt(0)) {
380
+ rightBottonControls.removeAt(0);
381
+ }
382
+ };
383
+ }
384
+ }, [map, geoFence, geoFenceOptions.latitude, geoFenceOptions.longitude, geoFenceOptions.radius, geoFenceOptions.minRadius, geoFenceOptions.editable, geoFenceOptions.eventHandlers]);
385
+
386
+ // show message
387
+ useEffect(() => {
388
+ if (map && message) {
389
+ const messageContainer = document.createElement('p');
390
+ messageContainer.style.margin = 'var(--spacing-s)';
391
+ messageContainer.style.padding = 'var(--spacing-xs)';
392
+ messageContainer.style.boxShadow = 'var(--box-shadow)';
393
+ messageContainer.style.border = 'none';
394
+ messageContainer.style.borderRadius = 'var(--border-radius-s)';
395
+ messageContainer.style.cursor = 'pointer';
396
+ messageContainer.style.color = 'rgb(0, 0, 0)';
397
+ messageContainer.style.backgroundColor = 'rgb(255, 255, 255)';
398
+ messageContainer.style.fontSize = 'var(--font-body1)';
399
+ messageContainer.textContent = message;
400
+ const index = map.controls[window.google.maps.ControlPosition.CENTER].push(messageContainer);
401
+ return () => {
402
+ map.controls[window.google.maps.ControlPosition.CENTER].removeAt(index - 1);
403
+ };
404
+ }
405
+ }, [map, message]);
406
+ useEffect(() => {
407
+ if (ref.current && !map) {
408
+ setMap(new window.google.maps.Map(ref.current, {}));
409
+ }
410
+ }, [map, options]);
411
+ useEffect(() => {
412
+ if (map && !OverlappingMarkerSpiderfier) {
413
+ import('overlapping-marker-spiderfier').then(module => {
414
+ setOverlappingMarkerSpiderfier(module);
415
+ }).catch(error => {
416
+ console.log(error);
417
+ });
418
+ }
419
+ }, [map, OverlappingMarkerSpiderfier]);
420
+ return /*#__PURE__*/_jsx(GoogleMapContainer, {
421
+ ref: ref,
422
+ height: height,
423
+ tabIndex: "0",
424
+ onClick: event => {
425
+ event.target.focus();
426
+ },
427
+ onFocus: () => {
428
+ map.setOptions({
429
+ scrollwheel: true
430
+ });
431
+ },
432
+ onBlur: () => {
433
+ map.setOptions({
434
+ scrollwheel: false
435
+ });
436
+ }
437
+ });
438
+ };
439
+ export default GoogleMap;
@@ -0,0 +1,193 @@
1
+ import { useState, useMemo, useRef, useEffect } from 'react';
2
+ import styled from 'styled-components';
3
+ import GoogleMapWrapper from './subComponent/GoogleMapWrapper';
4
+ import GoogleMapContainer from './subComponent/GoogleMapContainer';
5
+ import Searchbox from '../form/Searchbox';
6
+ import MapIcon from '../assets/icons/map_icon4.png';
7
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
8
+ const GoogleReverseGeolocation = _ref => {
9
+ let {
10
+ apiKey,
11
+ children,
12
+ defaultLatlng,
13
+ changeLatlng,
14
+ onChoose,
15
+ onSearch,
16
+ onError
17
+ } = _ref;
18
+ const [markerLatLng, setMarkerLatLng] = useState(defaultLatlng);
19
+ const handleChangeLatlng = latlng => {
20
+ setMarkerLatLng(latlng);
21
+ changeLatlng(latlng);
22
+ };
23
+ const confirmChooseLocation = async callback => {
24
+ if (markerLatLng.lat && markerLatLng.lng) {
25
+ try {
26
+ const address = await onChoose(markerLatLng);
27
+ if (address) {
28
+ callback({
29
+ address
30
+ });
31
+ } else {
32
+ callback({
33
+ error: 'ReverseGeo'
34
+ });
35
+ }
36
+ } catch (error) {
37
+ callback(error);
38
+ }
39
+ } else {
40
+ callback({
41
+ error: 'PleaseChooseLocation'
42
+ });
43
+ }
44
+ };
45
+ return /*#__PURE__*/_jsx(_Fragment, {
46
+ children: children(/*#__PURE__*/_jsx(GoogleMapWrapper, {
47
+ apiKey: apiKey,
48
+ height: 512,
49
+ zoom: 3,
50
+ markerLatLng: markerLatLng,
51
+ handleChangeLatlng: handleChangeLatlng,
52
+ onSearch: onSearch,
53
+ onError: onError,
54
+ children: /*#__PURE__*/_jsx(Map, {})
55
+ }), confirmChooseLocation)
56
+ });
57
+ };
58
+ const Map = _ref2 => {
59
+ let {
60
+ height,
61
+ zoom,
62
+ markerLatLng,
63
+ handleChangeLatlng,
64
+ onSearch,
65
+ onError
66
+ } = _ref2;
67
+ const ref = useRef(null);
68
+ const [map, setMap] = useState();
69
+ const options = useMemo(() => {
70
+ return {
71
+ zoom,
72
+ center: {
73
+ lat: 1,
74
+ lng: 1
75
+ },
76
+ scrollwheel: true,
77
+ zoomControl: true,
78
+ zoomControlOptions: {
79
+ position: window.google.maps.ControlPosition.LEFT_TOP
80
+ },
81
+ mapTypeControl: false,
82
+ scaleControl: false,
83
+ streetViewControl: false,
84
+ rotateControl: false,
85
+ fullscreenControl: false,
86
+ minZoom: 3,
87
+ restriction: {
88
+ latLngBounds: {
89
+ east: 179.9999,
90
+ north: 85,
91
+ south: -85,
92
+ west: -179.9999
93
+ },
94
+ strictBounds: true
95
+ }
96
+ };
97
+ }, [zoom]);
98
+ const handleError = errorCode => {
99
+ if (onError) {
100
+ onError(errorCode);
101
+ }
102
+ };
103
+ const handleSearch = async address => {
104
+ try {
105
+ const latlng = await onSearch(address);
106
+ if (latlng) {
107
+ map.setZoom(15);
108
+ map.panTo(latlng);
109
+ handleChangeLatlng(latlng);
110
+ } else {
111
+ handleError('NO_RESULT');
112
+ }
113
+ } catch (error) {
114
+ handleError(error.message);
115
+ }
116
+ };
117
+
118
+ // setup map
119
+ useEffect(() => {
120
+ if (map) {
121
+ map.setOptions(options);
122
+ }
123
+ }, [map, options]);
124
+
125
+ // click to choose location
126
+ useEffect(() => {
127
+ if (map) {
128
+ map.addListener('click', event => {
129
+ handleChangeLatlng(event.latLng.toJSON());
130
+ });
131
+ return () => {
132
+ window.google.maps.event.clearListeners(map, 'click');
133
+ };
134
+ }
135
+ }, [map, handleChangeLatlng]);
136
+
137
+ // render marker cluster
138
+ useEffect(() => {
139
+ if (map && markerLatLng.lat && markerLatLng.lng) {
140
+ const marker = new window.google.maps.Marker({
141
+ icon: {
142
+ url: MapIcon,
143
+ scaledSize: new window.google.maps.Size(40, 50)
144
+ },
145
+ position: markerLatLng
146
+ });
147
+ marker.setMap(map);
148
+ return () => {
149
+ marker.setMap(null);
150
+ };
151
+ }
152
+ }, [map, markerLatLng]);
153
+ useEffect(() => {
154
+ if (ref.current && !map) {
155
+ setMap(new window.google.maps.Map(ref.current, {}));
156
+ }
157
+ }, [map, options]);
158
+ return /*#__PURE__*/_jsxs("div", {
159
+ style: {
160
+ position: 'relative'
161
+ },
162
+ children: [/*#__PURE__*/_jsx(MapSearchBoxControl, {
163
+ children: /*#__PURE__*/_jsx(Searchbox, {
164
+ onSearch: handleSearch,
165
+ autoFocus: true
166
+ })
167
+ }), /*#__PURE__*/_jsx(GoogleMapContainer, {
168
+ ref: ref,
169
+ height: height,
170
+ tabIndex: "0",
171
+ onClick: event => {
172
+ event.target.focus();
173
+ },
174
+ onFocus: () => {
175
+ map.setOptions({
176
+ scrollwheel: true
177
+ });
178
+ },
179
+ onBlur: () => {
180
+ map.setOptions({
181
+ scrollwheel: false
182
+ });
183
+ }
184
+ })]
185
+ });
186
+ };
187
+ const MapSearchBoxControl = styled.div`
188
+ position: absolute;
189
+ top: var(--spacing-s);
190
+ right: var(--spacing-s);
191
+ z-index: 1;
192
+ `;
193
+ export default GoogleReverseGeolocation;