@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,177 @@
1
+ import {
2
+ getCommonOptions,
3
+ mergeEchartWidgetConfig,
4
+ type EchartOptionsProps,
5
+ } from '../echart'
6
+ import type { PieConfig, PieWidgetConfig, PieWidgetData } from './types'
7
+ import {
8
+ buildGridConfig,
9
+ buildLegendConfig,
10
+ flattenObjectArrayToCSV,
11
+ createTooltipFormatter,
12
+ } from '../_shared/chart-config'
13
+ import { downloadToCSV, downloadToPNG, type DownloadItem } from '../actions'
14
+ import type { ConfigProps } from '../loader/types'
15
+
16
+ export function pieDownloadConfig({
17
+ refUI,
18
+ }: ConfigProps): DownloadItem<PieWidgetData>[] {
19
+ return [
20
+ {
21
+ ...downloadToPNG,
22
+ modifier: () => downloadToPNG.modifier(refUI),
23
+ },
24
+ {
25
+ ...downloadToCSV,
26
+ modifier: async (data) => {
27
+ const rows = flattenObjectArrayToCSV(data)
28
+ return downloadToCSV.modifier(rows)
29
+ },
30
+ },
31
+ ]
32
+ }
33
+
34
+ export function pieConfig(props: PieConfig): PieWidgetConfig {
35
+ return {
36
+ type: 'pie',
37
+ option: mergeEchartWidgetConfig(getCommonOptions(props), getOption(props)),
38
+ }
39
+ }
40
+
41
+ function getOption({
42
+ data = [],
43
+ theme,
44
+ formatter,
45
+ }: PieConfig): EchartOptionsProps {
46
+ const multiSeries = (data?.length ?? 0) > 1
47
+
48
+ if (multiSeries) {
49
+ return {
50
+ xAxis: {
51
+ type: 'value',
52
+ show: true,
53
+ },
54
+ yAxis: {
55
+ type: 'category',
56
+ show: true,
57
+ },
58
+ legend: {
59
+ show: true,
60
+ bottom: 0,
61
+ },
62
+ grid: {
63
+ bottom: parseInt(theme.spacing(4)),
64
+ right: parseInt(theme.spacing(4)),
65
+ },
66
+ series: data.map((_: unknown, index: number) => ({
67
+ datasetIndex: index,
68
+ type: 'bar',
69
+ barMaxWidth: 100,
70
+ emphasis: {
71
+ focus: 'series',
72
+ },
73
+ })),
74
+ }
75
+ }
76
+
77
+ const hasLegend = true
78
+
79
+ return {
80
+ legend: buildLegendConfig(hasLegend),
81
+ grid: {
82
+ ...buildGridConfig(hasLegend, theme),
83
+ left: 0,
84
+ top: 0,
85
+ right: 0,
86
+ },
87
+ xAxis: {
88
+ show: false,
89
+ },
90
+ yAxis: {
91
+ show: false,
92
+ },
93
+ tooltip: {
94
+ trigger: 'item',
95
+ formatter: createTooltipFormatter((item) => {
96
+ const value =
97
+ item.value &&
98
+ typeof item.value === 'object' &&
99
+ !Array.isArray(item.value)
100
+ ? (Object.values(item.value) as (string | number)[])
101
+ : []
102
+ const index = item.encode?.value?.at(0)
103
+ const _value = value[index ?? 0]
104
+
105
+ const formattedValue =
106
+ typeof _value === 'number' && formatter
107
+ ? formatter(_value)
108
+ : (_value ?? '')
109
+
110
+ const marker = typeof item.marker === 'string' ? item.marker : ''
111
+ const seriesName = item.seriesName ? `${item.seriesName}: ` : ''
112
+ const name = item.name ?? ''
113
+
114
+ return {
115
+ name: seriesName,
116
+ seriesName: name,
117
+ marker,
118
+ value: formattedValue,
119
+ }
120
+ }),
121
+ },
122
+ color: Object.values(theme.palette.qualitative.bold),
123
+ series: data.map((_: unknown, index: number) => ({
124
+ datasetIndex: index,
125
+ type: 'pie',
126
+ colorBy: 'data',
127
+ radius: ['74%', '90%'],
128
+ avoidLabelOverlap: true,
129
+ selectedOffset: 0,
130
+ bottom: parseInt(theme.spacing(4)),
131
+
132
+ label: {
133
+ show: true,
134
+ position: 'center',
135
+ formatter: (params) => {
136
+ const { name } = params
137
+ const encodeIndex = params.encode?.value?.[0]
138
+ if (encodeIndex === undefined) {
139
+ return ''
140
+ }
141
+
142
+ const value = Object.values(params.data ?? {}).at(encodeIndex) as
143
+ | number
144
+ | string
145
+
146
+ const formattedValue =
147
+ typeof value === 'number' && formatter
148
+ ? formatter(value)
149
+ : (value ?? '')
150
+
151
+ const nameFormatted = name
152
+
153
+ return `{c|${formattedValue}}\n\n{b|${nameFormatted}}`
154
+ },
155
+ rich: {
156
+ b: {
157
+ fontSize: 16,
158
+ fontWeight: 'normal',
159
+ lineHeight: 20,
160
+ },
161
+ c: {
162
+ fontSize: 28,
163
+ fontWeight: 'bold',
164
+ lineHeight: 27,
165
+ },
166
+ },
167
+ },
168
+ emphasis: {
169
+ disabled: true,
170
+ },
171
+ itemStyle: {
172
+ borderColor: theme.palette.background.paper,
173
+ borderWidth: 1,
174
+ },
175
+ })),
176
+ } as EchartOptionsProps
177
+ }
@@ -0,0 +1,8 @@
1
+ export type {
2
+ PieWidgetData,
3
+ PieWidgetState,
4
+ PieWidgetConfig,
5
+ PieConfig,
6
+ } from './types'
7
+ export { pieConfig, pieDownloadConfig } from './config'
8
+ export { PieSkeleton } from './skeleton'
@@ -0,0 +1,70 @@
1
+ import { Box, Skeleton } from '@mui/material'
2
+ import { styles } from './style'
3
+
4
+ const GUTTER = 32
5
+ const SIZE = 294 - GUTTER
6
+ const INNER_SIZE = SIZE - GUTTER
7
+
8
+ export function PieSkeleton() {
9
+ return (
10
+ <Box sx={styles.skeleton.graph.container}>
11
+ <Box
12
+ sx={{
13
+ display: 'flex',
14
+ alignItems: 'center',
15
+ justifyContent: 'center',
16
+ position: 'relative',
17
+ }}
18
+ >
19
+ <Skeleton variant='circular' width={SIZE} height={SIZE} />
20
+ <Skeleton
21
+ sx={{
22
+ position: 'absolute',
23
+ zIndex: 1,
24
+ }}
25
+ variant='circular'
26
+ width={INNER_SIZE}
27
+ height={INNER_SIZE}
28
+ />
29
+ <Box
30
+ sx={{
31
+ position: 'absolute',
32
+ zIndex: 2,
33
+ display: 'flex',
34
+ flexDirection: 'column',
35
+ alignItems: 'center',
36
+ justifyContent: 'center',
37
+ gap: ({ spacing }) => spacing(1),
38
+ }}
39
+ >
40
+ <Skeleton height={24} width={72} />
41
+ <Skeleton height={8} width={48} />
42
+ </Box>
43
+ </Box>
44
+ <Box
45
+ sx={{
46
+ display: 'flex',
47
+ alignItems: 'center',
48
+ gap: ({ spacing }) => spacing(2),
49
+ height: ({ spacing }) => spacing(5),
50
+ }}
51
+ >
52
+ {Array(2)
53
+ .fill(0)
54
+ .map((_, i) => (
55
+ <Box
56
+ key={i}
57
+ sx={{
58
+ display: 'flex',
59
+ alignItems: 'center',
60
+ gap: ({ spacing }) => spacing(1.5),
61
+ }}
62
+ >
63
+ <Skeleton variant='circular' width={8} height={8} />
64
+ <Skeleton width={48} height={8} />
65
+ </Box>
66
+ ))}
67
+ </Box>
68
+ </Box>
69
+ )
70
+ }
@@ -0,0 +1,8 @@
1
+ import type { SxProps, Theme } from '@mui/material'
2
+ import { baseSkeletonStyles } from '../_shared/skeleton'
3
+
4
+ export const styles = {
5
+ skeleton: {
6
+ graph: baseSkeletonStyles.graph,
7
+ },
8
+ } satisfies Record<string, SxProps<Theme>>
@@ -0,0 +1,16 @@
1
+ import type { EchartWidgetData, EchartWidgetState } from '../echart'
2
+ import type {
3
+ EchartWidgetOptionProps,
4
+ EchartWidgetProps,
5
+ } from '../echart/types'
6
+ import type { ConfigProps } from '../loader'
7
+
8
+ export type PieWidgetData = EchartWidgetData
9
+
10
+ export type PieWidgetState = EchartWidgetState
11
+
12
+ export type PieWidgetConfig = EchartWidgetProps & {
13
+ type: 'pie'
14
+ }
15
+
16
+ export type PieConfig = ConfigProps & EchartWidgetOptionProps<PieWidgetData>
@@ -0,0 +1,213 @@
1
+ import { Box, Slider, TextField } from '@mui/material'
2
+ import { useState, useMemo, type FocusEvent, type KeyboardEvent } from 'react'
3
+ import { useWidgetStore } from '../../stores/widget-store'
4
+ import type { RangeItemProps, RangeWidgetState } from '../types'
5
+ import { styles } from '../style'
6
+ import { useShallow } from 'zustand/shallow'
7
+
8
+ type EditingState = '' | 'min' | 'max'
9
+
10
+ const defaultFormatter = (value: number) => value.toString()
11
+
12
+ export function RangeItem({ id, index }: RangeItemProps) {
13
+ const {
14
+ item,
15
+ onChange,
16
+ formatter = defaultFormatter,
17
+ } = useWidgetStore(
18
+ useShallow((state) => {
19
+ const widget = state.getWidget<RangeWidgetState>(id)
20
+ return {
21
+ item: widget?.data[index],
22
+ onChange: widget?.onChange,
23
+ formatter: widget?.formatter,
24
+ }
25
+ }),
26
+ )
27
+ const getWidget = useWidgetStore((store) => store.getWidget)
28
+ const setWidget = useWidgetStore((store) => store.setWidget)
29
+
30
+ const currentValue = useMemo(
31
+ () => (item ? (item.value ?? [item.min, item.max]) : [0, 0]),
32
+ [item],
33
+ )
34
+
35
+ // Local state for input values - track if user is editing
36
+ const [isEditing, setIsEditing] = useState<EditingState>('')
37
+
38
+ if (!item) return null
39
+
40
+ const handleSliderChange = (_: Event, newValue: number | number[]) => {
41
+ if (Array.isArray(newValue)) {
42
+ const [min, max] = newValue
43
+ const data = getWidget<RangeWidgetState>(id)?.data ?? []
44
+
45
+ data[index] = {
46
+ ...item,
47
+ value: newValue,
48
+ }
49
+
50
+ setWidget(id, {
51
+ data,
52
+ })
53
+
54
+ onChange?.([min!, max!], index)
55
+ }
56
+ }
57
+
58
+ const handleInputFocus = (e: FocusEvent<HTMLInputElement>) => {
59
+ setIsEditing(e.target.name as EditingState)
60
+ }
61
+
62
+ const handleInputChange = (event: React.ChangeEvent<HTMLInputElement>) => {
63
+ const { name, value } = event.target
64
+
65
+ let newValue: [number, number]
66
+ if (name === 'min') {
67
+ newValue = [
68
+ Math.min(
69
+ Math.max(item.min, parseFloat(value) || item.min),
70
+ currentValue[1]!,
71
+ ),
72
+ currentValue[1] ?? 0,
73
+ ]
74
+ } else {
75
+ newValue = [
76
+ currentValue[0] ?? 0,
77
+ Math.max(
78
+ Math.min(item.max, parseFloat(value) || item.max),
79
+ currentValue[0]!,
80
+ ),
81
+ ]
82
+ }
83
+
84
+ const data = getWidget<RangeWidgetState>(id)?.data ?? []
85
+
86
+ setWidget(id, {
87
+ data: data.map((d: RangeWidgetState['data'][number], i: number) =>
88
+ i === index
89
+ ? {
90
+ ...d,
91
+ value: newValue,
92
+ }
93
+ : d,
94
+ ),
95
+ })
96
+
97
+ onChange?.([newValue[0], newValue[1]], index)
98
+ }
99
+
100
+ const handleInputBlur = (e: FocusEvent<HTMLInputElement>) => {
101
+ setIsEditing('')
102
+ handleInputChange(e)
103
+ }
104
+
105
+ const handleInputKeyDown = (event: KeyboardEvent<HTMLInputElement>) => {
106
+ if (event.key === 'Enter') {
107
+ handleInputBlur(event as unknown as FocusEvent<HTMLInputElement>)
108
+ event.currentTarget.blur()
109
+ }
110
+ }
111
+
112
+ return (
113
+ <Box sx={styles.rangeItem}>
114
+ <Box sx={styles.sliderContainer}>
115
+ <Slider
116
+ value={currentValue}
117
+ onChange={handleSliderChange}
118
+ valueLabelDisplay='auto'
119
+ valueLabelFormat={formatter}
120
+ min={item.min}
121
+ max={item.max}
122
+ step={item.step}
123
+ marks={item.marks}
124
+ disabled={item.disabled}
125
+ sx={{
126
+ ...styles.slider,
127
+ ...(item.color && {
128
+ color: item.color,
129
+ }),
130
+ }}
131
+ />
132
+ </Box>
133
+
134
+ <Box sx={styles.inputsRow}>
135
+ <Input
136
+ key={`min-${currentValue[0]}`}
137
+ isEditing={isEditing}
138
+ name='min'
139
+ value={currentValue[0] ?? 0}
140
+ formatter={formatter}
141
+ onFocus={handleInputFocus}
142
+ onBlur={handleInputBlur}
143
+ onKeyDown={handleInputKeyDown}
144
+ disabled={item.disabled}
145
+ inputProps={{
146
+ 'aria-label': 'Minimum value',
147
+ }}
148
+ />
149
+ <Input
150
+ key={`max-${currentValue[1]}`}
151
+ isEditing={isEditing}
152
+ name='max'
153
+ value={currentValue[1] ?? 0}
154
+ formatter={formatter}
155
+ onFocus={handleInputFocus}
156
+ onBlur={handleInputBlur}
157
+ onKeyDown={handleInputKeyDown}
158
+ disabled={item.disabled}
159
+ inputProps={{
160
+ 'aria-label': 'Maximum value',
161
+ }}
162
+ />
163
+ </Box>
164
+ </Box>
165
+ )
166
+ }
167
+
168
+ function Input({
169
+ isEditing,
170
+ name,
171
+ disabled,
172
+ value,
173
+ formatter,
174
+ onFocus: onFocus,
175
+ onBlur: onBlur,
176
+ onKeyDown: onKeyDown,
177
+ inputProps,
178
+ }: {
179
+ isEditing: EditingState
180
+ name: 'min' | 'max'
181
+ disabled?: boolean
182
+ value: number
183
+ formatter: (value: number) => string
184
+ onFocus: (e: FocusEvent<HTMLInputElement>) => void
185
+ onBlur: (e: FocusEvent<HTMLInputElement>) => void
186
+ onKeyDown: (e: KeyboardEvent<HTMLInputElement>) => void
187
+ inputProps?: React.InputHTMLAttributes<HTMLInputElement>
188
+ }) {
189
+ const [currentValue, setCurrentValue] = useState<string>(String(value))
190
+
191
+ // Compute display values when not editing
192
+ const displayMinValue = useMemo(
193
+ () => formatter(Number(currentValue)),
194
+ [currentValue, formatter],
195
+ )
196
+
197
+ return (
198
+ <TextField
199
+ name={name}
200
+ value={isEditing === name ? currentValue : displayMinValue}
201
+ onChange={(e) => {
202
+ setCurrentValue(e.target.value)
203
+ }}
204
+ onFocus={onFocus}
205
+ onBlur={onBlur}
206
+ onKeyDown={onKeyDown}
207
+ disabled={disabled}
208
+ size='small'
209
+ sx={styles.input}
210
+ inputProps={inputProps}
211
+ />
212
+ )
213
+ }
@@ -0,0 +1,10 @@
1
+ import type { RangeWidgetConfig } from './types'
2
+
3
+ export interface RangeConfigProps {
4
+ formatter?: (value: number) => string
5
+ onChange?: (value: number[], index: number) => void
6
+ }
7
+
8
+ export function rangeConfig(): RangeWidgetConfig {
9
+ return {}
10
+ }
@@ -0,0 +1,16 @@
1
+ export { RangeUI } from './range-ui'
2
+ export { RangeSkeleton } from './skeleton'
3
+ export { rangeConfig } from './config'
4
+ export { RangeItem } from './components/range-item'
5
+
6
+ export type {
7
+ RangeWidgetState,
8
+ RangeWidgetConfig,
9
+ RangeDownloadConfig,
10
+ RangeUIProps,
11
+ RangeDataItem,
12
+ RangeWidgetData,
13
+ RangeItemProps,
14
+ } from './types'
15
+
16
+ export { sanitizeRangeDataItem, sanitizeRangeDataItems } from './serializer'