@carto/ps-react-ui 4.3.3 → 4.3.5

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 (301) hide show
  1. package/dist/components.js +3 -3
  2. package/dist/components.js.map +1 -1
  3. package/dist/{lasso-tool-BwRzEW7k.js → lasso-tool-wFqOD6wk.js} +13 -13
  4. package/dist/lasso-tool-wFqOD6wk.js.map +1 -0
  5. package/dist/types/components/common-types.d.ts +41 -0
  6. package/dist/types/components/types.d.ts +1 -1
  7. package/dist/types/widgets/echart/echart-ui.d.ts +1 -1
  8. package/dist/types/widgets/echart/types.d.ts +4 -0
  9. package/dist/widgets/actions.js +1 -1
  10. package/dist/widgets/bar.js +1 -1
  11. package/dist/widgets/category.js +1 -1
  12. package/dist/widgets/echart.js +96 -85
  13. package/dist/widgets/echart.js.map +1 -1
  14. package/dist/widgets/formula.js +1 -1
  15. package/dist/widgets/histogram.js +1 -1
  16. package/dist/widgets/markdown.js +1 -1
  17. package/dist/widgets/pie.js +1 -1
  18. package/dist/widgets/scatterplot.js +1 -1
  19. package/dist/widgets/spread.js +1 -1
  20. package/dist/widgets/table.js +1 -1
  21. package/dist/widgets/timeseries.js +1 -1
  22. package/dist/widgets/toolbar-actions.js.map +1 -1
  23. package/dist/widgets/wrapper.js +1 -1
  24. package/package.json +8 -3
  25. package/src/components/basemaps/basemaps.test.tsx +196 -0
  26. package/src/components/basemaps/basemaps.tsx +128 -0
  27. package/src/components/basemaps/const.ts +13 -0
  28. package/src/components/basemaps/group-wrapper.test.tsx +38 -0
  29. package/src/components/basemaps/group-wrapper.tsx +28 -0
  30. package/src/components/basemaps/group.test.tsx +52 -0
  31. package/src/components/basemaps/group.tsx +42 -0
  32. package/src/components/basemaps/header.test.tsx +54 -0
  33. package/src/components/basemaps/header.tsx +36 -0
  34. package/src/components/basemaps/styles.ts +76 -0
  35. package/src/components/basemaps/types.ts +30 -0
  36. package/src/components/common-types.ts +1 -0
  37. package/src/components/geolocation-controls/const.ts +6 -0
  38. package/src/components/geolocation-controls/geolocation-controls.test.tsx +133 -0
  39. package/src/components/geolocation-controls/geolocation-controls.tsx +95 -0
  40. package/src/components/geolocation-controls/types.ts +17 -0
  41. package/src/components/index.ts +64 -0
  42. package/src/components/lasso-tool/chip.tsx +37 -0
  43. package/src/components/lasso-tool/const.tsx +70 -0
  44. package/src/components/lasso-tool/icons.tsx +91 -0
  45. package/src/components/lasso-tool/lasso-tool-inline.test.tsx +168 -0
  46. package/src/components/lasso-tool/lasso-tool-inline.tsx +245 -0
  47. package/src/components/lasso-tool/lasso-tool.test.tsx +212 -0
  48. package/src/components/lasso-tool/lasso-tool.tsx +479 -0
  49. package/src/components/lasso-tool/styles.ts +143 -0
  50. package/src/components/lasso-tool/types.ts +114 -0
  51. package/src/components/list-data/list-data-skeleton.test.tsx +10 -0
  52. package/src/components/list-data/list-data-skeleton.tsx +40 -0
  53. package/src/components/list-data/list-data.test.tsx +94 -0
  54. package/src/components/list-data/list-data.tsx +106 -0
  55. package/src/components/list-data/styles.ts +37 -0
  56. package/src/components/list-data/types.ts +25 -0
  57. package/src/components/measurement-tools/const.tsx +108 -0
  58. package/src/components/measurement-tools/icons.tsx +54 -0
  59. package/src/components/measurement-tools/measurement-tools.test.tsx +165 -0
  60. package/src/components/measurement-tools/measurement-tools.tsx +443 -0
  61. package/src/components/measurement-tools/styles.ts +91 -0
  62. package/src/components/measurement-tools/types.ts +77 -0
  63. package/src/components/no-data-alert/no-data-alert.test.tsx +31 -0
  64. package/src/components/no-data-alert/no-data-alert.tsx +59 -0
  65. package/src/components/responsive-drawer/responsive-drawer.test.tsx +91 -0
  66. package/src/components/responsive-drawer/responsive-drawer.tsx +53 -0
  67. package/src/components/smart-tooltip/smart-tooltip.test.tsx +168 -0
  68. package/src/components/smart-tooltip/smart-tooltip.tsx +40 -0
  69. package/src/components/tooltip/tooltip.test.tsx +86 -0
  70. package/src/components/tooltip/tooltip.tsx +30 -0
  71. package/src/components/types.ts +1 -0
  72. package/src/components/zoom-controls/styles.ts +27 -0
  73. package/src/components/zoom-controls/types.ts +19 -0
  74. package/src/components/zoom-controls/zoom-controls.test.tsx +101 -0
  75. package/src/components/zoom-controls/zoom-controls.tsx +114 -0
  76. package/src/hooks/index.ts +2 -0
  77. package/src/hooks/use-debounce.ts +55 -0
  78. package/src/hooks/use-skeleton.test.tsx +32 -0
  79. package/src/hooks/use-skeleton.ts +19 -0
  80. package/src/hooks/use-widget-ref.ts +33 -0
  81. package/src/widgets/README.md +277 -0
  82. package/src/widgets/_shared/chart-config/config-factory.ts +67 -0
  83. package/src/widgets/_shared/chart-config/csv-modifiers.ts +56 -0
  84. package/src/widgets/_shared/chart-config/index.ts +21 -0
  85. package/src/widgets/_shared/chart-config/option-builders.ts +203 -0
  86. package/src/widgets/_shared/skeleton/index.ts +5 -0
  87. package/src/widgets/_shared/skeleton/styles.ts +20 -0
  88. package/src/widgets/actions/change-column/change-column-icon.tsx +10 -0
  89. package/src/widgets/actions/change-column/change-column.test.tsx +163 -0
  90. package/src/widgets/actions/change-column/change-column.tsx +141 -0
  91. package/src/widgets/actions/change-column/sortable-column-item.tsx +49 -0
  92. package/src/widgets/actions/change-column/types.ts +20 -0
  93. package/src/widgets/actions/download/download.test.tsx +322 -0
  94. package/src/widgets/actions/download/download.tsx +118 -0
  95. package/src/widgets/actions/download/exports.test.tsx +275 -0
  96. package/src/widgets/actions/download/exports.tsx +103 -0
  97. package/src/widgets/actions/download/types.ts +21 -0
  98. package/src/widgets/actions/fullscreen/fullscreen.test.tsx +269 -0
  99. package/src/widgets/actions/fullscreen/fullscreen.tsx +82 -0
  100. package/src/widgets/actions/fullscreen/styles.ts +17 -0
  101. package/src/widgets/actions/fullscreen/types.ts +27 -0
  102. package/src/widgets/actions/index.ts +51 -0
  103. package/src/widgets/actions/lock-selection/lock-selection.test.tsx +186 -0
  104. package/src/widgets/actions/lock-selection/lock-selection.tsx +133 -0
  105. package/src/widgets/actions/lock-selection/types.ts +41 -0
  106. package/src/widgets/actions/relative-data/relative-data.test.tsx +267 -0
  107. package/src/widgets/actions/relative-data/relative-data.tsx +133 -0
  108. package/src/widgets/actions/relative-data/style.ts +9 -0
  109. package/src/widgets/actions/relative-data/types.ts +31 -0
  110. package/src/widgets/actions/relative-data/utils.test.ts +223 -0
  111. package/src/widgets/actions/relative-data/utils.ts +58 -0
  112. package/src/widgets/actions/searcher/searcher-toggle.test.tsx +354 -0
  113. package/src/widgets/actions/searcher/searcher-toggle.tsx +73 -0
  114. package/src/widgets/actions/searcher/searcher.tsx +205 -0
  115. package/src/widgets/actions/searcher/types.ts +72 -0
  116. package/src/widgets/actions/shared/styles.ts +12 -0
  117. package/src/widgets/actions/stack-toggle/grouped-bar-chart-icon.tsx +14 -0
  118. package/src/widgets/actions/stack-toggle/stack-toggle.test.tsx +270 -0
  119. package/src/widgets/actions/stack-toggle/stack-toggle.tsx +146 -0
  120. package/src/widgets/actions/stack-toggle/types.ts +29 -0
  121. package/src/widgets/actions/zoom-toggle/index.ts +2 -0
  122. package/src/widgets/actions/zoom-toggle/style.ts +14 -0
  123. package/src/widgets/actions/zoom-toggle/types.ts +44 -0
  124. package/src/widgets/actions/zoom-toggle/zoom-toggle.tsx +186 -0
  125. package/src/widgets/bar/config.ts +122 -0
  126. package/src/widgets/bar/index.ts +9 -0
  127. package/src/widgets/bar/skeleton.tsx +60 -0
  128. package/src/widgets/bar/style.ts +33 -0
  129. package/src/widgets/bar/types.ts +16 -0
  130. package/src/widgets/category/category-ui.test.tsx +399 -0
  131. package/src/widgets/category/category-ui.tsx +156 -0
  132. package/src/widgets/category/components/category-bar.tsx +28 -0
  133. package/src/widgets/category/components/category-legend.tsx +30 -0
  134. package/src/widgets/category/components/category-row-multi.tsx +50 -0
  135. package/src/widgets/category/components/category-row-other.tsx +23 -0
  136. package/src/widgets/category/components/category-row-single.tsx +47 -0
  137. package/src/widgets/category/components/index.ts +14 -0
  138. package/src/widgets/category/config.ts +85 -0
  139. package/src/widgets/category/index.ts +30 -0
  140. package/src/widgets/category/skeleton.tsx +24 -0
  141. package/src/widgets/category/style.ts +133 -0
  142. package/src/widgets/category/types.ts +40 -0
  143. package/src/widgets/echart/const.ts +1 -0
  144. package/src/widgets/echart/echart-ui.test.tsx +537 -0
  145. package/src/widgets/echart/echart-ui.tsx +92 -0
  146. package/src/widgets/echart/echart.test.tsx +562 -0
  147. package/src/widgets/echart/echart.tsx +68 -0
  148. package/src/widgets/echart/index.ts +16 -0
  149. package/src/widgets/echart/options.ts +53 -0
  150. package/src/widgets/echart/types.ts +45 -0
  151. package/src/widgets/echart/utils.ts +169 -0
  152. package/src/widgets/error/error.test.tsx +331 -0
  153. package/src/widgets/error/error.tsx +40 -0
  154. package/src/widgets/error/index.ts +2 -0
  155. package/src/widgets/error/types.ts +14 -0
  156. package/src/widgets/formula/components/item.test.tsx +249 -0
  157. package/src/widgets/formula/components/item.tsx +18 -0
  158. package/src/widgets/formula/components/prefix.test.tsx +341 -0
  159. package/src/widgets/formula/components/prefix.tsx +18 -0
  160. package/src/widgets/formula/components/row.test.tsx +364 -0
  161. package/src/widgets/formula/components/row.tsx +21 -0
  162. package/src/widgets/formula/components/series.tsx +34 -0
  163. package/src/widgets/formula/components/suffix.test.tsx +383 -0
  164. package/src/widgets/formula/components/suffix.tsx +28 -0
  165. package/src/widgets/formula/components/value.test.tsx +329 -0
  166. package/src/widgets/formula/components/value.tsx +29 -0
  167. package/src/widgets/formula/config.ts +27 -0
  168. package/src/widgets/formula/formula-ui.test.tsx +399 -0
  169. package/src/widgets/formula/formula-ui.tsx +27 -0
  170. package/src/widgets/formula/index.ts +24 -0
  171. package/src/widgets/formula/serializer.test.tsx +144 -0
  172. package/src/widgets/formula/serializer.ts +28 -0
  173. package/src/widgets/formula/skeleton.tsx +10 -0
  174. package/src/widgets/formula/style.ts +23 -0
  175. package/src/widgets/formula/types.ts +50 -0
  176. package/src/widgets/histogram/config.ts +143 -0
  177. package/src/widgets/histogram/index.ts +8 -0
  178. package/src/widgets/histogram/skeleton.tsx +52 -0
  179. package/src/widgets/histogram/style.ts +8 -0
  180. package/src/widgets/histogram/types.ts +17 -0
  181. package/src/widgets/index.ts +25 -0
  182. package/src/widgets/loader/index.ts +4 -0
  183. package/src/widgets/loader/loader.tsx +70 -0
  184. package/src/widgets/loader/types.ts +11 -0
  185. package/src/widgets/loader/utils.test.ts +112 -0
  186. package/src/widgets/loader/utils.ts +35 -0
  187. package/src/widgets/markdown/config.ts +18 -0
  188. package/src/widgets/markdown/index.ts +14 -0
  189. package/src/widgets/markdown/markdown-ui.test.tsx +341 -0
  190. package/src/widgets/markdown/markdown-ui.tsx +52 -0
  191. package/src/widgets/markdown/markdown.tsx +20 -0
  192. package/src/widgets/markdown/skeleton.tsx +12 -0
  193. package/src/widgets/markdown/style.ts +28 -0
  194. package/src/widgets/markdown/types.ts +28 -0
  195. package/src/widgets/no-data/index.ts +2 -0
  196. package/src/widgets/no-data/no-data.test.tsx +447 -0
  197. package/src/widgets/no-data/no-data.tsx +116 -0
  198. package/src/widgets/no-data/style.ts +18 -0
  199. package/src/widgets/no-data/types.ts +72 -0
  200. package/src/widgets/note/index.ts +2 -0
  201. package/src/widgets/note/note.test.tsx +391 -0
  202. package/src/widgets/note/note.tsx +114 -0
  203. package/src/widgets/note/style.ts +29 -0
  204. package/src/widgets/note/types.ts +9 -0
  205. package/src/widgets/pie/config.ts +177 -0
  206. package/src/widgets/pie/index.ts +8 -0
  207. package/src/widgets/pie/skeleton.tsx +70 -0
  208. package/src/widgets/pie/style.ts +8 -0
  209. package/src/widgets/pie/types.ts +16 -0
  210. package/src/widgets/range/components/range-item.tsx +213 -0
  211. package/src/widgets/range/config.ts +10 -0
  212. package/src/widgets/range/index.ts +16 -0
  213. package/src/widgets/range/range-ui.test.tsx +203 -0
  214. package/src/widgets/range/range-ui.tsx +11 -0
  215. package/src/widgets/range/serializer.test.ts +70 -0
  216. package/src/widgets/range/serializer.ts +27 -0
  217. package/src/widgets/range/skeleton.tsx +14 -0
  218. package/src/widgets/range/style.ts +37 -0
  219. package/src/widgets/range/types.ts +39 -0
  220. package/src/widgets/scatterplot/config.ts +138 -0
  221. package/src/widgets/scatterplot/index.ts +8 -0
  222. package/src/widgets/scatterplot/skeleton.tsx +59 -0
  223. package/src/widgets/scatterplot/style.ts +21 -0
  224. package/src/widgets/scatterplot/types.ts +17 -0
  225. package/src/widgets/selection-summary/index.ts +6 -0
  226. package/src/widgets/selection-summary/selection-summary.tsx +46 -0
  227. package/src/widgets/selection-summary/style.ts +10 -0
  228. package/src/widgets/selection-summary/types.ts +14 -0
  229. package/src/widgets/skeleton-loader/index.ts +2 -0
  230. package/src/widgets/skeleton-loader/skeleton-loader.test.tsx +139 -0
  231. package/src/widgets/skeleton-loader/skeleton-loader.tsx +28 -0
  232. package/src/widgets/skeleton-loader/types.ts +8 -0
  233. package/src/widgets/spread/components/max-value.tsx +29 -0
  234. package/src/widgets/spread/components/min-value.tsx +29 -0
  235. package/src/widgets/spread/components/separator.tsx +6 -0
  236. package/src/widgets/spread/config.ts +34 -0
  237. package/src/widgets/spread/index.ts +23 -0
  238. package/src/widgets/spread/skeleton.tsx +10 -0
  239. package/src/widgets/spread/spread-ui.test.tsx +368 -0
  240. package/src/widgets/spread/spread-ui.tsx +29 -0
  241. package/src/widgets/spread/style.ts +22 -0
  242. package/src/widgets/spread/types.ts +47 -0
  243. package/src/widgets/stores/index.ts +9 -0
  244. package/src/widgets/stores/types.ts +192 -0
  245. package/src/widgets/stores/widget-store.test.ts +601 -0
  246. package/src/widgets/stores/widget-store.ts +239 -0
  247. package/src/widgets/subheader/index.ts +3 -0
  248. package/src/widgets/subheader/style.ts +20 -0
  249. package/src/widgets/subheader/subheader.test.tsx +45 -0
  250. package/src/widgets/subheader/subheader.tsx +16 -0
  251. package/src/widgets/subheader/types.ts +11 -0
  252. package/src/widgets/table/components/cell-header.tsx +58 -0
  253. package/src/widgets/table/components/cell.tsx +80 -0
  254. package/src/widgets/table/components/index.ts +4 -0
  255. package/src/widgets/table/components/pagination-actions.tsx +67 -0
  256. package/src/widgets/table/components/pagination.tsx +41 -0
  257. package/src/widgets/table/components/row.tsx +60 -0
  258. package/src/widgets/table/config.ts +71 -0
  259. package/src/widgets/table/helpers.test.ts +244 -0
  260. package/src/widgets/table/helpers.ts +107 -0
  261. package/src/widgets/table/hooks/index.ts +7 -0
  262. package/src/widgets/table/hooks/use-pagination.test.ts +294 -0
  263. package/src/widgets/table/hooks/use-pagination.ts +155 -0
  264. package/src/widgets/table/hooks/use-selection.test.ts +504 -0
  265. package/src/widgets/table/hooks/use-selection.ts +189 -0
  266. package/src/widgets/table/hooks/use-sort.test.ts +296 -0
  267. package/src/widgets/table/hooks/use-sort.ts +138 -0
  268. package/src/widgets/table/index.ts +53 -0
  269. package/src/widgets/table/serializer.ts +54 -0
  270. package/src/widgets/table/skeleton.tsx +48 -0
  271. package/src/widgets/table/style.ts +34 -0
  272. package/src/widgets/table/table-ui.tsx +64 -0
  273. package/src/widgets/table/types.ts +223 -0
  274. package/src/widgets/timeseries/config.ts +135 -0
  275. package/src/widgets/timeseries/index.ts +8 -0
  276. package/src/widgets/timeseries/skeleton.tsx +55 -0
  277. package/src/widgets/timeseries/style.ts +36 -0
  278. package/src/widgets/timeseries/types.ts +17 -0
  279. package/src/widgets/toolbar-actions/index.ts +6 -0
  280. package/src/widgets/toolbar-actions/styles.ts +38 -0
  281. package/src/widgets/toolbar-actions/toolbar-actions.test.tsx +691 -0
  282. package/src/widgets/toolbar-actions/toolbar-actions.tsx +145 -0
  283. package/src/widgets/toolbar-actions/types.ts +60 -0
  284. package/src/widgets/wrapper/components/actions.test.tsx +101 -0
  285. package/src/widgets/wrapper/components/actions.tsx +30 -0
  286. package/src/widgets/wrapper/components/options.test.tsx +323 -0
  287. package/src/widgets/wrapper/components/options.tsx +73 -0
  288. package/src/widgets/wrapper/components/title.test.tsx +126 -0
  289. package/src/widgets/wrapper/components/title.tsx +32 -0
  290. package/src/widgets/wrapper/index.ts +16 -0
  291. package/src/widgets/wrapper/styles.ts +98 -0
  292. package/src/widgets/wrapper/types.ts +55 -0
  293. package/src/widgets/wrapper/wrapper-ui.test.tsx +232 -0
  294. package/src/widgets/wrapper/wrapper-ui.tsx +57 -0
  295. package/src/widgets/wrapper/wrapper.test.tsx +365 -0
  296. package/src/widgets/wrapper/wrapper.tsx +50 -0
  297. package/dist/lasso-tool-BwRzEW7k.js.map +0 -1
  298. package/dist/types/common/common.d.ts +0 -3
  299. package/dist/types/common/index.d.ts +0 -26
  300. package/dist/types/common/lasso-tools.d.ts +0 -36
  301. package/dist/types/common/measurement-tools.d.ts +0 -65
@@ -0,0 +1,76 @@
1
+ import type { SxProps, Theme } from '@mui/material'
2
+
3
+ export const BASEMAPS_WIDTH = 288
4
+
5
+ export const styles = {
6
+ root: {
7
+ width: BASEMAPS_WIDTH,
8
+ overflow: 'auto',
9
+ },
10
+ toggle: {
11
+ padding: ({ spacing }) => spacing(0.5),
12
+
13
+ img: {
14
+ width: '100%',
15
+ aspectRatio: '1 / 1',
16
+ borderRadius: ({ spacing }) => spacing(0.25),
17
+ },
18
+ },
19
+ header: {
20
+ display: 'flex',
21
+ alignItems: 'center',
22
+ justifyContent: 'space-between',
23
+ padding: ({ spacing }) => spacing(1),
24
+ paddingInlineStart: ({ spacing }) => spacing(2),
25
+ position: 'sticky',
26
+ top: 0,
27
+ zIndex: 2,
28
+ background: ({ palette }) => palette.background.paper,
29
+ },
30
+ groupWrapper: {
31
+ content: {
32
+ paddingInline: ({ spacing }) => spacing(2),
33
+ paddingBlock: ({ spacing }) => spacing(0.5),
34
+ },
35
+ },
36
+ group: {
37
+ display: 'flex',
38
+ flexDirection: 'row',
39
+ flexWrap: 'wrap',
40
+ alignItems: 'center',
41
+ gap: ({ spacing }) => spacing(2),
42
+ paddingInline: ({ spacing }) => spacing(2),
43
+ paddingBlock: ({ spacing }) => spacing(1),
44
+ },
45
+ item: {
46
+ container: {
47
+ display: 'flex',
48
+ alignItems: 'center',
49
+ flexDirection: 'column',
50
+ gap: ({ spacing }) => spacing(1),
51
+ background: 'transparent',
52
+ border: 'none',
53
+ cursor: 'pointer',
54
+ padding: 0,
55
+ height: ({ spacing }) => spacing(12),
56
+
57
+ img: {
58
+ maxWidth: ({ spacing }) => spacing(9),
59
+ aspectRatio: '1 / 1',
60
+ borderRadius: ({ spacing }) => spacing(0.5),
61
+ border: `2px solid transparent`,
62
+
63
+ '&:hover': {
64
+ borderColor: ({ palette }) => palette.action.active,
65
+ },
66
+
67
+ '&[data-active="true"]': {
68
+ borderColor: ({ palette }) => palette.primary.main,
69
+ },
70
+ },
71
+ },
72
+ selected: {
73
+ color: ({ palette }) => palette.primary.main,
74
+ },
75
+ },
76
+ } satisfies Record<string, SxProps<Theme>>
@@ -0,0 +1,30 @@
1
+ import type { SxProps, Theme, TooltipProps } from '@mui/material'
2
+
3
+ export interface BasemapsUILabels {
4
+ toggle: {
5
+ title: string
6
+ }
7
+ header: {
8
+ title: string
9
+ actions: {
10
+ close: string
11
+ }
12
+ }
13
+ }
14
+
15
+ export interface BasemapOption {
16
+ id: string
17
+ label: string
18
+ icon: string
19
+ group?: string
20
+ }
21
+
22
+ export interface BasemapsUIProps {
23
+ options: BasemapOption[]
24
+ labels?: BasemapsUILabels
25
+ position?: 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right'
26
+ selected: string | null | undefined
27
+ sx?: SxProps<Theme>
28
+ onChange: (id: string) => void
29
+ TooltipProps?: Omit<TooltipProps, 'title'>
30
+ }
@@ -0,0 +1 @@
1
+ export * from '@carto/ps-common-types'
@@ -0,0 +1,6 @@
1
+ export const tooltipLabelsDefault = {
2
+ enabled: 'Show your current location',
3
+ disabled: 'Location unavailable',
4
+ }
5
+
6
+ export const ariaLabel = 'geolocation'
@@ -0,0 +1,133 @@
1
+ import { describe, expect, test, vi, beforeEach } from 'vitest'
2
+ import { render, within, fireEvent } from '@testing-library/react'
3
+ import { GeolocationControls } from './geolocation-controls'
4
+
5
+ describe('GeolocationControls', () => {
6
+ const mockOnChange = vi.fn()
7
+ const mockOnError = vi.fn()
8
+
9
+ const mockGeolocation = {
10
+ getCurrentPosition: vi.fn(),
11
+ watchPosition: vi.fn(),
12
+ clearWatch: vi.fn(),
13
+ }
14
+
15
+ const mockPermissions = {
16
+ query: vi.fn(),
17
+ state: 'granted' as const,
18
+ onchange: null as (() => void) | null,
19
+ }
20
+
21
+ const mockNavigator = {
22
+ geolocation: mockGeolocation,
23
+ permissions: mockPermissions,
24
+ }
25
+
26
+ beforeEach(() => {
27
+ vi.clearAllMocks()
28
+ // Mock navigator
29
+ Object.defineProperty(global, 'navigator', {
30
+ value: mockNavigator,
31
+ writable: true,
32
+ })
33
+ })
34
+
35
+ test('renders correctly with geolocation enabled', () => {
36
+ mockPermissions.query.mockResolvedValue(mockPermissions)
37
+ const { container } = render(
38
+ <GeolocationControls onChange={mockOnChange} onError={mockOnError} />,
39
+ )
40
+
41
+ const button = within(container).getByRole('button')
42
+ const buttonElement = button as unknown as HTMLButtonElement
43
+ expect(buttonElement.disabled).toBe(false)
44
+ })
45
+
46
+ test('handles geolocation permission denied', () => {
47
+ mockPermissions.query.mockResolvedValue({
48
+ ...mockPermissions,
49
+ state: 'denied',
50
+ })
51
+ const { container } = render(
52
+ <GeolocationControls onChange={mockOnChange} onError={mockOnError} />,
53
+ )
54
+
55
+ const button = within(container).getByRole('button')
56
+ const buttonElement = button as unknown as HTMLButtonElement
57
+ expect(buttonElement.disabled).toBe(false)
58
+ })
59
+
60
+ test('calls getCurrentPosition when clicked', () => {
61
+ mockPermissions.query.mockResolvedValue(mockPermissions)
62
+
63
+ const mockPosition = {
64
+ coords: {
65
+ latitude: 40.7128,
66
+ longitude: -74.006,
67
+ },
68
+ }
69
+
70
+ mockGeolocation.getCurrentPosition.mockImplementation(
71
+ (success: PositionCallback) =>
72
+ success(mockPosition as GeolocationPosition),
73
+ )
74
+
75
+ const { container } = render(
76
+ <GeolocationControls onChange={mockOnChange} onError={mockOnError} />,
77
+ )
78
+
79
+ const button = within(container).getByRole('button')
80
+ fireEvent.click(button)
81
+
82
+ expect(mockGeolocation.getCurrentPosition).toHaveBeenCalled()
83
+ expect(mockOnChange).toHaveBeenCalledWith(mockPosition.coords)
84
+ })
85
+
86
+ test('calls watchPosition when watch prop is true', () => {
87
+ mockPermissions.query.mockResolvedValue(mockPermissions)
88
+ const mockPosition = {
89
+ coords: {
90
+ latitude: 40.7128,
91
+ longitude: -74.006,
92
+ },
93
+ }
94
+ mockGeolocation.watchPosition.mockImplementation(
95
+ (success: PositionCallback) =>
96
+ success(mockPosition as GeolocationPosition),
97
+ )
98
+
99
+ const { container } = render(
100
+ <GeolocationControls
101
+ onChange={mockOnChange}
102
+ onError={mockOnError}
103
+ watch
104
+ />,
105
+ )
106
+
107
+ const button = within(container).getByRole('button')
108
+ fireEvent.click(button)
109
+
110
+ expect(mockGeolocation.watchPosition).toHaveBeenCalled()
111
+ expect(mockOnChange).toHaveBeenCalledWith(mockPosition.coords)
112
+ })
113
+
114
+ test('handles geolocation errors', () => {
115
+ mockPermissions.query.mockResolvedValue(mockPermissions)
116
+
117
+ const mockError = new Error('Geolocation error')
118
+ mockGeolocation.getCurrentPosition.mockImplementation(
119
+ (_, error: PositionErrorCallback) => {
120
+ error(mockError as unknown as GeolocationPositionError)
121
+ },
122
+ )
123
+
124
+ const { container } = render(
125
+ <GeolocationControls onChange={mockOnChange} onError={mockOnError} />,
126
+ )
127
+
128
+ const button = within(container).getByRole('button')
129
+ fireEvent.click(button)
130
+
131
+ expect(mockOnError).toHaveBeenCalledWith(mockError)
132
+ })
133
+ })
@@ -0,0 +1,95 @@
1
+ import { Paper, IconButton } from '@mui/material'
2
+ import {
3
+ MyLocationOutlined,
4
+ LocationDisabledOutlined,
5
+ } from '@mui/icons-material'
6
+ import type { GeolocationControlProps } from './types'
7
+ import { useCallback, useEffect, useRef, useState, type JSX } from 'react'
8
+ import { ariaLabel, tooltipLabelsDefault } from './const'
9
+ import { Tooltip } from '../tooltip/tooltip'
10
+
11
+ export function GeolocationControls({
12
+ disabled,
13
+ labels,
14
+ PaperProps,
15
+ TooltipProps,
16
+ watch,
17
+ onChange,
18
+ onError,
19
+ }: GeolocationControlProps): JSX.Element {
20
+ const watchRef = useRef<number>(null)
21
+ const hasGeolocation = 'geolocation' in navigator
22
+ const [allowed, setAllowed] = useState(hasGeolocation)
23
+
24
+ useEffect(() => {
25
+ if (hasGeolocation) {
26
+ navigator.permissions
27
+ .query({ name: 'geolocation' })
28
+ .then((result) => {
29
+ setAllowed(result.state === 'granted')
30
+ result.onchange = () => {
31
+ setAllowed(result.state === 'granted')
32
+ }
33
+ })
34
+ .catch((error: Parameters<PositionErrorCallback>[0]) => {
35
+ setAllowed(false)
36
+ onError?.(error)
37
+ })
38
+ }
39
+
40
+ return () => {
41
+ if (watchRef.current) {
42
+ navigator.geolocation.clearWatch(watchRef.current)
43
+ }
44
+ }
45
+ }, [hasGeolocation, onError])
46
+
47
+ const success = useCallback(
48
+ (position: Parameters<PositionCallback>[0]) => {
49
+ onChange(position.coords)
50
+ },
51
+ [onChange],
52
+ )
53
+
54
+ const error = useCallback(
55
+ (error: Parameters<PositionErrorCallback>[0]) => {
56
+ setAllowed(false)
57
+ onError?.(error)
58
+ },
59
+ [onError],
60
+ )
61
+
62
+ const handleClick = useCallback(() => {
63
+ if (watchRef.current) {
64
+ navigator.geolocation.clearWatch(watchRef.current)
65
+ }
66
+
67
+ if (watch) {
68
+ watchRef.current = navigator.geolocation.watchPosition(success, error)
69
+ return
70
+ }
71
+
72
+ navigator.geolocation.getCurrentPosition(success, error)
73
+ }, [watch, success, error])
74
+
75
+ const tooltipLabels = labels?.tooltip ?? tooltipLabelsDefault
76
+
77
+ return (
78
+ <Paper {...PaperProps}>
79
+ <Tooltip
80
+ arrow
81
+ placement='right'
82
+ title={tooltipLabels[allowed ? 'enabled' : 'disabled']}
83
+ {...TooltipProps}
84
+ >
85
+ <IconButton
86
+ onClick={handleClick}
87
+ aria-label={labels?.ariaLabel ?? ariaLabel}
88
+ disabled={!hasGeolocation || disabled}
89
+ >
90
+ {allowed ? <MyLocationOutlined /> : <LocationDisabledOutlined />}
91
+ </IconButton>
92
+ </Tooltip>
93
+ </Paper>
94
+ )
95
+ }
@@ -0,0 +1,17 @@
1
+ import type { PaperProps, TooltipProps } from '@mui/material'
2
+
3
+ export interface GeolocationControlProps {
4
+ disabled?: boolean
5
+ labels?: {
6
+ tooltip: {
7
+ enabled: string
8
+ disabled: string
9
+ }
10
+ ariaLabel: string
11
+ }
12
+ PaperProps?: PaperProps
13
+ TooltipProps?: Omit<TooltipProps, 'title'>
14
+ watch?: boolean
15
+ onChange: (props: Parameters<PositionCallback>[0]['coords']) => void
16
+ onError?: (error: Parameters<PositionErrorCallback>[0]) => void
17
+ }
@@ -0,0 +1,64 @@
1
+ export type {
2
+ // Common types
3
+ // Measurement tools
4
+ CustomMeasureMode,
5
+ MeasurementMode,
6
+ MeasurementModeOption,
7
+ MeasurementModes,
8
+ MeasurementModesMapping,
9
+ MeasurementOptionsMode,
10
+ MeasurementOptionsUnit,
11
+ MeasurementSystem,
12
+ MeasurementUnit,
13
+ MeasurementUnitImperialDistance,
14
+ MeasurementUnitMetricDistance,
15
+ MeasurementUnitOption,
16
+ MeasurementUnits,
17
+ // Lasso tools
18
+ LassoToolsMode,
19
+ LassoToolsModeOption,
20
+ LassoToolsModes,
21
+ LassoToolOptionsMode,
22
+ LassoToolsModesMapping,
23
+ } from './types'
24
+ export type {
25
+ LassoToolsComponentProps,
26
+ LassoToolsInlineComponentProps,
27
+ } from './lasso-tool/types'
28
+ export { LassoToolsUI } from './lasso-tool/lasso-tool'
29
+ export { LassoToolsInlineUI } from './lasso-tool/lasso-tool-inline'
30
+ export {
31
+ DEFAULT_LASSO_TOOLS_MODES_MAPPING,
32
+ LASSO_TOOLS_LABELS,
33
+ } from './lasso-tool/const'
34
+ export {
35
+ DrawCircleIcon,
36
+ DrawLassoIcon,
37
+ DrawPolygonIcon,
38
+ DrawSquareIcon,
39
+ SelectToolIcon,
40
+ } from './lasso-tool/icons'
41
+
42
+ export type { MeasurementToolsComponentProps } from './measurement-tools/types'
43
+ export {
44
+ DEFAULT_MEASUREMENT_TOOLS_LABELS,
45
+ DEFAULT_MEASUREMENT_TOOLS_UNITS_MAPPING,
46
+ DEFAULT_MEASUREMENT_TOOLS_MODES_MAPPING,
47
+ } from './measurement-tools/const'
48
+ export { AreaIcon, BufferIcon, RulerIcon } from './measurement-tools/icons'
49
+ export { MeasurementToolsUI } from './measurement-tools/measurement-tools'
50
+
51
+ export type { GeolocationControlProps } from './geolocation-controls/types'
52
+ export { GeolocationControls } from './geolocation-controls/geolocation-controls'
53
+
54
+ export type { ZoomControlProps } from './zoom-controls/types'
55
+ export { ZoomControlsUI } from './zoom-controls/zoom-controls'
56
+
57
+ export type { ListDataProps, DataItem } from './list-data/types'
58
+ export { ListDataUI } from './list-data/list-data'
59
+
60
+ export { BasemapsUI } from './basemaps/basemaps'
61
+ export type { BasemapsUIProps } from './basemaps/types'
62
+
63
+ export { Tooltip, setTooltipEnterDelay } from './tooltip/tooltip'
64
+ export { SmartTooltip } from './smart-tooltip/smart-tooltip'
@@ -0,0 +1,37 @@
1
+ import { Chip } from '@mui/material'
2
+ import type { PickDeep } from 'type-fest'
3
+ import { LASSO_TOOLS_LABELS } from './const'
4
+ import { styles } from './styles'
5
+ import type { LassoToolsComponentProps, LassoToolsData } from './types'
6
+ import { Tooltip } from '../tooltip/tooltip'
7
+
8
+ export function LassoToolsUIChip({
9
+ chipProps,
10
+ value,
11
+ labels,
12
+ onChipToggle,
13
+ onDelete,
14
+ }: Pick<LassoToolsComponentProps, 'chipProps' | 'onDelete' | 'onChipToggle'> & {
15
+ value: LassoToolsData
16
+ labels?: PickDeep<LassoToolsComponentProps['labels'], 'chip'>['chip']
17
+ }) {
18
+ const chipState = value.visible ? 'active' : 'inactive'
19
+ const chipLabel =
20
+ labels?.tooltip?.[chipState] ?? LASSO_TOOLS_LABELS.chip.tooltip[chipState]
21
+
22
+ return (
23
+ <Tooltip title={chipLabel} placement='bottom' {...chipProps?.TooltipProps}>
24
+ <Chip
25
+ sx={{
26
+ ...styles.chip.chip,
27
+ }}
28
+ color={value.visible ? 'secondary' : 'default'}
29
+ size='small'
30
+ onDelete={() => onDelete(value.id)}
31
+ label={value.label}
32
+ onClick={() => onChipToggle(value.id, !value.visible)}
33
+ {...chipProps?.ChipsProps}
34
+ />
35
+ </Tooltip>
36
+ )
37
+ }
@@ -0,0 +1,70 @@
1
+ import type { LassoToolsMode, LassoToolsModesMapping } from '../types'
2
+ import {
3
+ DrawPolygonIcon,
4
+ DrawSquareIcon,
5
+ DrawCircleIcon,
6
+ DrawLassoIcon,
7
+ SelectToolIcon,
8
+ } from './icons'
9
+ import type { LassoToolsComponentProps } from './types'
10
+ import type { RequiredDeep } from 'type-fest'
11
+
12
+ export const LASSO_TOOLS_LABELS: NonNullable<
13
+ RequiredDeep<LassoToolsComponentProps['labels']>
14
+ > = {
15
+ action: {
16
+ tooltip: {
17
+ active: 'Click on the map to draw your spatial filter',
18
+ inactive: 'Click on the map to draw your spatial filter',
19
+ },
20
+ },
21
+ chip: {
22
+ tooltip: {
23
+ active: 'Hide drawing',
24
+ inactive: 'Show drawing',
25
+ },
26
+ },
27
+ options: {
28
+ mode: {
29
+ title: 'Choose a drawing tool',
30
+ options: {
31
+ circle: 'Circle',
32
+ lasso: 'Lasso tool',
33
+ polygon: 'Polygon',
34
+ rectangle: 'Rectangle',
35
+ edit: 'Edit feature',
36
+ },
37
+ },
38
+ },
39
+ noData: {
40
+ title: 'Spatial filter not applied',
41
+ description:
42
+ 'Select a drawing or editing tool and click on the map to define your spatial filter',
43
+ },
44
+ actions: {
45
+ toggleAll: {
46
+ active: 'Hide all',
47
+ inactive: 'Show all',
48
+ },
49
+ deleteAll: 'Remove all',
50
+ },
51
+ } as const
52
+
53
+ export const DEFAULT_LASSO_TOOLS_MODES_MAPPING: LassoToolsModesMapping<LassoToolsMode> =
54
+ {
55
+ polygon: {
56
+ icon: <DrawPolygonIcon />,
57
+ },
58
+ rectangle: {
59
+ icon: <DrawSquareIcon />,
60
+ },
61
+ circle: {
62
+ icon: <DrawCircleIcon />,
63
+ },
64
+ lasso: {
65
+ icon: <DrawLassoIcon />,
66
+ },
67
+ edit: {
68
+ icon: <SelectToolIcon />,
69
+ },
70
+ } as const
@@ -0,0 +1,91 @@
1
+ import type { SVGProps } from 'react'
2
+
3
+ export function DrawPolygonIcon(props: SVGProps<SVGSVGElement>) {
4
+ return (
5
+ <svg
6
+ fill='none'
7
+ xmlns='http://www.w3.org/2000/svg'
8
+ viewBox='0 0 24 24'
9
+ {...props}
10
+ >
11
+ <path
12
+ fillRule='evenodd'
13
+ clipRule='evenodd'
14
+ d='M4 18a2 2 0 1 1 0 4 2 2 0 0 1 0-4Zm16 0a2 2 0 1 1 0 4 2 2 0 0 1 0-4Zm-2.829 1a2.996 2.996 0 0 0 0 2H6.829a2.995 2.995 0 0 0 0-2h10.342Zm-2.463-5.707 3.998 4a3.013 3.013 0 0 0-1.414 1.414l-4-3.999a3.014 3.014 0 0 0 1.31-1.214l.106-.201ZM2.998 6.829a2.995 2.995 0 0 0 2.002 0v10.342a2.993 2.993 0 0 0-2.002 0V6.83ZM12 10a2 2 0 1 1 0 4 2 2 0 0 1 0-4Zm1.84-3.919c.464.483 1.09.81 1.79.896l-1.47 2.94a2.992 2.992 0 0 0-1.79-.894l1.47-2.942ZM16 2a2 2 0 1 1 0 4 2 2 0 0 1 0-4ZM4 2a2 2 0 1 1 0 4 2 2 0 0 1 0-4Zm9.171.998a2.994 2.994 0 0 0 0 2.002H6.829a2.995 2.995 0 0 0 0-2.002h6.342Z'
15
+ fill='currentColor'
16
+ />
17
+ </svg>
18
+ )
19
+ }
20
+
21
+ export function DrawSquareIcon(props: SVGProps<SVGSVGElement>) {
22
+ return (
23
+ <svg
24
+ fill='none'
25
+ xmlns='http://www.w3.org/2000/svg'
26
+ viewBox='0 0 24 24'
27
+ {...props}
28
+ >
29
+ <path
30
+ fillRule='evenodd'
31
+ clipRule='evenodd'
32
+ d='M4 18a2 2 0 1 1 0 4 2 2 0 0 1 0-4Zm16 0a2 2 0 1 1 0 4 2 2 0 0 1 0-4Zm-2.829 1a2.993 2.993 0 0 0-.17.974l-.001.052.007.183a3 3 0 0 0 .164.79H6.829a2.995 2.995 0 0 0 0-2h10.342ZM2.998 6.828a2.995 2.995 0 0 0 2.002 0V17.17a2.993 2.993 0 0 0-2.002 0V6.83Zm16.001 0a2.995 2.995 0 0 0 2 0V17.17a2.993 2.993 0 0 0-2 0V6.829ZM20 2a2 2 0 1 1 0 4 2 2 0 0 1 0-4ZM4 2a2 2 0 1 1 0 4 2 2 0 0 1 0-4Zm13.171.998a2.991 2.991 0 0 0-.17.976L17 4.026l.007.183a3 3 0 0 0 .164.79H6.829a2.995 2.995 0 0 0 0-2H17.17Z'
33
+ fill='currentColor'
34
+ />
35
+ </svg>
36
+ )
37
+ }
38
+
39
+ export function DrawCircleIcon(props: SVGProps<SVGSVGElement>) {
40
+ return (
41
+ <svg
42
+ fill='none'
43
+ xmlns='http://www.w3.org/2000/svg'
44
+ viewBox='0 0 24 24'
45
+ {...props}
46
+ >
47
+ <path
48
+ fillRule='evenodd'
49
+ clipRule='evenodd'
50
+ d='M12 2c5.523 0 10 4.477 10 10s-4.477 10-10 10S2 17.523 2 12 6.477 2 12 2Zm0 2a8 8 0 1 0 0 16 8 8 0 0 0 0-16Zm0 6a2 2 0 1 1 0 4 2 2 0 0 1 0-4Z'
51
+ fill='currentColor'
52
+ />
53
+ </svg>
54
+ )
55
+ }
56
+
57
+ export function DrawLassoIcon(props: SVGProps<SVGSVGElement>) {
58
+ return (
59
+ <svg
60
+ fill='none'
61
+ xmlns='http://www.w3.org/2000/svg'
62
+ viewBox='0 0 24 24'
63
+ {...props}
64
+ >
65
+ <path
66
+ fillRule='evenodd'
67
+ clipRule='evenodd'
68
+ d='M12 3c4.935 0 9 3.736 9 9l-.002.343-.012.668c-.012.438-.033.86-.062 1.266l-.05.597C20.498 18.767 19.267 21 17 21c-1.192 0-1.971-.341-2.988-1.122l-.472-.375c-.401-.319-.64-.473-.888-.566a4.938 4.938 0 0 0-.415-.13l-.34-.085-.398-.086-.456-.086-.66-.111-1.708-.273a9.112 9.112 0 0 1-.952-.206C5.46 17.301 3 14.954 3 12.015c0-1.508.485-2.995 1.436-4.458.355.585.906 1.04 1.562 1.272C5.328 9.916 5 10.977 5 12.015c0 1.889 1.78 3.588 3.282 4.025l.085.023.345.076.517.092 1.619.257.583.1.518.098.237.05.433.103c.272.07.512.143.73.224.434.161.783.373 1.235.718l.457.362c.806.646 1.24.857 1.959.857.893 0 1.63-1.518 1.895-4.45l.045-.585c.013-.2.024-.407.033-.62l.02-.655c.005-.224.007-.454.007-.69 0-4.12-3.133-7-7-7a1 1 0 1 1 0-2ZM7 4a2 2 0 1 1 0 4 2 2 0 0 1 0-4Z'
69
+ fill='currentColor'
70
+ />
71
+ </svg>
72
+ )
73
+ }
74
+
75
+ export function SelectToolIcon(props: SVGProps<SVGSVGElement>) {
76
+ return (
77
+ <svg
78
+ fill='none'
79
+ xmlns='http://www.w3.org/2000/svg'
80
+ viewBox='0 0 24 24'
81
+ {...props}
82
+ >
83
+ <path
84
+ fillRule='evenodd'
85
+ clipRule='evenodd'
86
+ d='m10.083 19.394.057.113a1 1 0 0 0 1.72.007l2.869-4.786 4.786-2.87a1 1 0 0 0-.121-1.777l-14-6c-.83-.356-1.669.483-1.313 1.313l6.002 14ZM6.905 6.904l9.903 4.244-3.322 1.995-.102.069a1 1 0 0 0-.242.274l-1.992 3.321-4.245-9.903Z'
87
+ fill='currentColor'
88
+ />
89
+ </svg>
90
+ )
91
+ }