@carto/ps-react-ui 4.4.1 → 4.4.3

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 (225) hide show
  1. package/dist/components.js.map +1 -1
  2. package/dist/download-config-Dqu78h2a.js +57 -0
  3. package/dist/download-config-Dqu78h2a.js.map +1 -0
  4. package/dist/error-CEkRPccv.js.map +1 -1
  5. package/dist/exports-Cr43OCul.js.map +1 -1
  6. package/dist/formatter-B9Bxn1k7.js +6 -0
  7. package/dist/formatter-B9Bxn1k7.js.map +1 -0
  8. package/dist/lasso-tool-BYbxrJ-7.js.map +1 -1
  9. package/dist/note-t51drNe0.js.map +1 -1
  10. package/dist/options-D9wflre6.js.map +1 -1
  11. package/dist/row-DTCV0Ocm.js.map +1 -1
  12. package/dist/series-CYNOu2Ju.js.map +1 -1
  13. package/dist/smart-tooltip-D4vwQpFf.js.map +1 -1
  14. package/dist/styles-Y8q7Jff3.js +118 -0
  15. package/dist/styles-Y8q7Jff3.js.map +1 -0
  16. package/dist/tooltip-BDnrRKrp.js.map +1 -1
  17. package/dist/types/components/basemaps/basemaps.d.ts +20 -0
  18. package/dist/types/components/geolocation-controls/geolocation-controls.d.ts +11 -0
  19. package/dist/types/components/lasso-tool/lasso-tool-inline.d.ts +17 -0
  20. package/dist/types/components/lasso-tool/lasso-tool.d.ts +21 -0
  21. package/dist/types/components/list-data/list-data.d.ts +16 -0
  22. package/dist/types/components/measurement-tools/measurement-tools.d.ts +20 -0
  23. package/dist/types/components/smart-tooltip/smart-tooltip.d.ts +17 -0
  24. package/dist/types/components/tooltip/tooltip.d.ts +13 -0
  25. package/dist/types/components/zoom-controls/zoom-controls.d.ts +16 -0
  26. package/dist/types/hooks/use-widget-ref.d.ts +4 -4
  27. package/dist/types/widgets/actions/brush-toggle/types.d.ts +8 -2
  28. package/dist/types/widgets/actions/download/download.d.ts +11 -0
  29. package/dist/types/widgets/actions/download/exports.d.ts +15 -0
  30. package/dist/types/widgets/actions/fullscreen/fullscreen.d.ts +13 -0
  31. package/dist/types/widgets/actions/index.d.ts +1 -1
  32. package/dist/types/widgets/actions/relative-data/relative-data.d.ts +1 -0
  33. package/dist/types/widgets/bar/config.d.ts +8 -4
  34. package/dist/types/widgets/category/category-ui.d.ts +3 -0
  35. package/dist/types/widgets/category/components/category-bar.d.ts +3 -0
  36. package/dist/types/widgets/category/components/category-legend.d.ts +3 -0
  37. package/dist/types/widgets/category/components/category-row-multi.d.ts +5 -1
  38. package/dist/types/widgets/category/components/category-row-other.d.ts +3 -0
  39. package/dist/types/widgets/category/components/category-row-single.d.ts +5 -1
  40. package/dist/types/widgets/category/config.d.ts +11 -0
  41. package/dist/types/widgets/category/types.d.ts +1 -0
  42. package/dist/types/widgets/echart/echart-ui.d.ts +7 -0
  43. package/dist/types/widgets/echart/echart.d.ts +6 -0
  44. package/dist/types/widgets/echart/options.d.ts +7 -0
  45. package/dist/types/widgets/echart/types.d.ts +3 -0
  46. package/dist/types/widgets/echart/utils.d.ts +41 -0
  47. package/dist/types/widgets/error/error.d.ts +10 -0
  48. package/dist/types/widgets/formula/components/item.d.ts +3 -0
  49. package/dist/types/widgets/formula/components/prefix.d.ts +3 -0
  50. package/dist/types/widgets/formula/components/row.d.ts +3 -0
  51. package/dist/types/widgets/formula/components/series.d.ts +3 -0
  52. package/dist/types/widgets/formula/components/suffix.d.ts +3 -0
  53. package/dist/types/widgets/formula/components/value.d.ts +3 -0
  54. package/dist/types/widgets/formula/config.d.ts +11 -0
  55. package/dist/types/widgets/formula/formula-ui.d.ts +3 -0
  56. package/dist/types/widgets/histogram/config.d.ts +18 -2
  57. package/dist/types/widgets/histogram/index.d.ts +2 -1
  58. package/dist/types/widgets/histogram/types.d.ts +6 -3
  59. package/dist/types/widgets/loader/loader.d.ts +22 -0
  60. package/dist/types/widgets/loader/utils.d.ts +26 -3
  61. package/dist/types/widgets/markdown/config.d.ts +10 -0
  62. package/dist/types/widgets/markdown/markdown-ui.d.ts +7 -0
  63. package/dist/types/widgets/markdown/markdown.d.ts +3 -0
  64. package/dist/types/widgets/note/note.d.ts +10 -0
  65. package/dist/types/widgets/pie/config.d.ts +8 -4
  66. package/dist/types/widgets/range/components/range-item.d.ts +3 -0
  67. package/dist/types/widgets/range/config.d.ts +5 -0
  68. package/dist/types/widgets/range/range-ui.d.ts +3 -0
  69. package/dist/types/widgets/scatterplot/config.d.ts +7 -3
  70. package/dist/types/widgets/selection-summary/selection-summary.d.ts +11 -0
  71. package/dist/types/widgets/skeleton-loader/skeleton-loader.d.ts +10 -0
  72. package/dist/types/widgets/spread/components/max-value.d.ts +3 -0
  73. package/dist/types/widgets/spread/components/min-value.d.ts +3 -0
  74. package/dist/types/widgets/spread/components/separator.d.ts +3 -0
  75. package/dist/types/widgets/spread/config.d.ts +11 -0
  76. package/dist/types/widgets/spread/spread-ui.d.ts +3 -0
  77. package/dist/types/widgets/stores/types.d.ts +2 -0
  78. package/dist/types/widgets/subheader/subheader.d.ts +11 -0
  79. package/dist/types/widgets/table/config.d.ts +8 -3
  80. package/dist/types/widgets/table/hooks/use-pagination.d.ts +11 -3
  81. package/dist/types/widgets/table/hooks/use-selection.d.ts +11 -2
  82. package/dist/types/widgets/table/hooks/use-sort.d.ts +11 -3
  83. package/dist/types/widgets/timeseries/config.d.ts +8 -4
  84. package/dist/types/widgets/utils/chart-config/download-config.d.ts +3 -0
  85. package/dist/types/widgets/{_shared → utils}/chart-config/index.d.ts +2 -0
  86. package/dist/types/widgets/{_shared → utils}/chart-config/option-builders.d.ts +14 -9
  87. package/dist/types/widgets/utils/formatter.d.ts +2 -0
  88. package/dist/types/widgets/utils/index.d.ts +7 -0
  89. package/dist/types/widgets/wrapper/components/actions.d.ts +3 -0
  90. package/dist/types/widgets/wrapper/components/options.d.ts +3 -0
  91. package/dist/types/widgets/wrapper/components/title.d.ts +3 -0
  92. package/dist/types/widgets/wrapper/wrapper-ui.d.ts +14 -0
  93. package/dist/types/widgets/wrapper/wrapper.d.ts +14 -0
  94. package/dist/use-widget-ref-wtFLDFCD.js.map +1 -1
  95. package/dist/utils-BOhInag6.js.map +1 -1
  96. package/dist/widgets/actions.js +720 -681
  97. package/dist/widgets/actions.js.map +1 -1
  98. package/dist/widgets/bar.js +78 -92
  99. package/dist/widgets/bar.js.map +1 -1
  100. package/dist/widgets/category.js +206 -197
  101. package/dist/widgets/category.js.map +1 -1
  102. package/dist/widgets/echart.js.map +1 -1
  103. package/dist/widgets/formula.js +54 -54
  104. package/dist/widgets/formula.js.map +1 -1
  105. package/dist/widgets/histogram.js +106 -86
  106. package/dist/widgets/histogram.js.map +1 -1
  107. package/dist/widgets/loader.js.map +1 -1
  108. package/dist/widgets/markdown.js.map +1 -1
  109. package/dist/widgets/pie.js +147 -112
  110. package/dist/widgets/pie.js.map +1 -1
  111. package/dist/widgets/range.js +23 -22
  112. package/dist/widgets/range.js.map +1 -1
  113. package/dist/widgets/scatterplot.js +46 -60
  114. package/dist/widgets/scatterplot.js.map +1 -1
  115. package/dist/widgets/selection-summary.js.map +1 -1
  116. package/dist/widgets/skeleton-loader.js.map +1 -1
  117. package/dist/widgets/spread.js +40 -41
  118. package/dist/widgets/spread.js.map +1 -1
  119. package/dist/widgets/subheader.js.map +1 -1
  120. package/dist/widgets/table.js.map +1 -1
  121. package/dist/widgets/timeseries.js +51 -65
  122. package/dist/widgets/timeseries.js.map +1 -1
  123. package/dist/widgets/toolbar-actions.js +101 -6693
  124. package/dist/widgets/toolbar-actions.js.map +1 -1
  125. package/dist/widgets/utils.js +33 -0
  126. package/dist/widgets/utils.js.map +1 -0
  127. package/dist/widgets/wrapper.js.map +1 -1
  128. package/package.json +9 -4
  129. package/src/components/basemaps/basemaps.tsx +20 -0
  130. package/src/components/geolocation-controls/geolocation-controls.tsx +11 -0
  131. package/src/components/lasso-tool/lasso-tool-inline.tsx +17 -0
  132. package/src/components/lasso-tool/lasso-tool.tsx +21 -0
  133. package/src/components/list-data/list-data.tsx +16 -0
  134. package/src/components/measurement-tools/measurement-tools.tsx +20 -0
  135. package/src/components/smart-tooltip/smart-tooltip.tsx +17 -0
  136. package/src/components/tooltip/tooltip.tsx +13 -0
  137. package/src/components/zoom-controls/zoom-controls.tsx +16 -0
  138. package/src/hooks/use-widget-ref.ts +4 -4
  139. package/src/widgets/README.md +13 -13
  140. package/src/widgets/actions/brush-toggle/brush-toggle.tsx +42 -47
  141. package/src/widgets/actions/brush-toggle/types.ts +8 -2
  142. package/src/widgets/actions/download/download.tsx +11 -0
  143. package/src/widgets/actions/download/exports.tsx +15 -0
  144. package/src/widgets/actions/fullscreen/fullscreen.tsx +13 -0
  145. package/src/widgets/actions/index.ts +1 -0
  146. package/src/widgets/actions/relative-data/relative-data.test.tsx +62 -1
  147. package/src/widgets/actions/relative-data/relative-data.tsx +62 -39
  148. package/src/widgets/bar/config.ts +34 -34
  149. package/src/widgets/bar/style.ts +1 -1
  150. package/src/widgets/category/category-ui.tsx +12 -2
  151. package/src/widgets/category/components/category-bar.tsx +3 -0
  152. package/src/widgets/category/components/category-legend.tsx +3 -0
  153. package/src/widgets/category/components/category-row-multi.tsx +9 -2
  154. package/src/widgets/category/components/category-row-other.tsx +3 -0
  155. package/src/widgets/category/components/category-row-single.tsx +8 -1
  156. package/src/widgets/category/config.ts +11 -0
  157. package/src/widgets/category/types.ts +1 -0
  158. package/src/widgets/echart/echart-ui.tsx +7 -0
  159. package/src/widgets/echart/echart.tsx +6 -0
  160. package/src/widgets/echart/options.ts +7 -0
  161. package/src/widgets/echart/types.ts +3 -0
  162. package/src/widgets/echart/utils.ts +41 -0
  163. package/src/widgets/error/error.tsx +10 -0
  164. package/src/widgets/formula/components/item.tsx +3 -0
  165. package/src/widgets/formula/components/prefix.tsx +3 -0
  166. package/src/widgets/formula/components/row.tsx +3 -0
  167. package/src/widgets/formula/components/series.tsx +3 -0
  168. package/src/widgets/formula/components/suffix.tsx +3 -0
  169. package/src/widgets/formula/components/value.tsx +4 -2
  170. package/src/widgets/formula/config.ts +11 -0
  171. package/src/widgets/formula/formula-ui.tsx +3 -0
  172. package/src/widgets/histogram/config.ts +93 -21
  173. package/src/widgets/histogram/index.ts +6 -1
  174. package/src/widgets/histogram/style.ts +1 -1
  175. package/src/widgets/histogram/types.ts +9 -3
  176. package/src/widgets/loader/loader.tsx +22 -0
  177. package/src/widgets/loader/utils.ts +26 -3
  178. package/src/widgets/markdown/config.ts +10 -0
  179. package/src/widgets/markdown/markdown-ui.tsx +7 -0
  180. package/src/widgets/markdown/markdown.tsx +3 -0
  181. package/src/widgets/note/note.tsx +10 -0
  182. package/src/widgets/pie/config.ts +100 -33
  183. package/src/widgets/pie/style.ts +1 -1
  184. package/src/widgets/range/components/range-item.tsx +5 -2
  185. package/src/widgets/range/config.ts +5 -0
  186. package/src/widgets/range/range-ui.tsx +3 -0
  187. package/src/widgets/scatterplot/config.ts +19 -23
  188. package/src/widgets/scatterplot/style.ts +1 -1
  189. package/src/widgets/selection-summary/selection-summary.tsx +11 -0
  190. package/src/widgets/skeleton-loader/skeleton-loader.tsx +10 -0
  191. package/src/widgets/spread/components/max-value.tsx +4 -2
  192. package/src/widgets/spread/components/min-value.tsx +4 -2
  193. package/src/widgets/spread/components/separator.tsx +3 -0
  194. package/src/widgets/spread/config.ts +11 -0
  195. package/src/widgets/spread/spread-ui.tsx +3 -0
  196. package/src/widgets/stores/types.ts +2 -0
  197. package/src/widgets/subheader/subheader.tsx +11 -0
  198. package/src/widgets/table/config.ts +8 -3
  199. package/src/widgets/table/hooks/use-pagination.ts +11 -3
  200. package/src/widgets/table/hooks/use-selection.ts +11 -2
  201. package/src/widgets/table/hooks/use-sort.ts +11 -3
  202. package/src/widgets/timeseries/config.ts +32 -33
  203. package/src/widgets/timeseries/style.ts +1 -1
  204. package/src/widgets/utils/chart-config/download-config.ts +22 -0
  205. package/src/widgets/{_shared → utils}/chart-config/index.ts +4 -0
  206. package/src/widgets/{_shared → utils}/chart-config/option-builders.ts +23 -13
  207. package/src/widgets/utils/formatter.ts +2 -0
  208. package/src/widgets/utils/index.ts +26 -0
  209. package/src/widgets/wrapper/components/actions.tsx +3 -0
  210. package/src/widgets/wrapper/components/options.tsx +3 -0
  211. package/src/widgets/wrapper/components/title.tsx +3 -0
  212. package/src/widgets/wrapper/wrapper-ui.tsx +14 -0
  213. package/src/widgets/wrapper/wrapper.tsx +14 -0
  214. package/dist/styles-CAroD5Rc.js +0 -123
  215. package/dist/styles-CAroD5Rc.js.map +0 -1
  216. /package/dist/types/widgets/{_shared → utils}/chart-config/config-factory.d.ts +0 -0
  217. /package/dist/types/widgets/{_shared → utils}/chart-config/csv-modifiers.d.ts +0 -0
  218. /package/dist/types/widgets/{_shared → utils}/chart-config/option-builders.test.d.ts +0 -0
  219. /package/dist/types/widgets/{_shared → utils}/skeleton/index.d.ts +0 -0
  220. /package/dist/types/widgets/{_shared → utils}/skeleton/styles.d.ts +0 -0
  221. /package/src/widgets/{_shared → utils}/chart-config/config-factory.ts +0 -0
  222. /package/src/widgets/{_shared → utils}/chart-config/csv-modifiers.ts +0 -0
  223. /package/src/widgets/{_shared → utils}/chart-config/option-builders.test.ts +0 -0
  224. /package/src/widgets/{_shared → utils}/skeleton/index.ts +0 -0
  225. /package/src/widgets/{_shared → utils}/skeleton/styles.ts +0 -0
@@ -4,6 +4,9 @@ import type { MarkdownWidgetData } from './types'
4
4
  import { MarkdownUI } from '.'
5
5
  import { useShallow } from 'zustand/shallow'
6
6
 
7
+ /**
8
+ * Stateful markdown widget component that reads content from the widget store and renders it as formatted rich text.
9
+ */
7
10
  export function Markdown({ id }: MarkdownUIProps) {
8
11
  const content = useWidgetStore(
9
12
  useShallow(
@@ -37,6 +37,16 @@ const COMPONENTS: Components = {
37
37
  li: DEFAULT_P,
38
38
  }
39
39
 
40
+ /**
41
+ * Displays text content with markdown support and automatic show more/less functionality for long content. Automatically detects content exceeding 3 lines and shows an expand/collapse button.
42
+ *
43
+ * @example
44
+ * ```tsx
45
+ * <WidgetNote>
46
+ * {"**Important:** This data is from Q4 2024."}
47
+ * </WidgetNote>
48
+ * ```
49
+ */
40
50
  export function WidgetNote({
41
51
  children,
42
52
  labels = DEFAULT_LABELS,
@@ -8,33 +8,28 @@ import {
8
8
  buildGridConfig,
9
9
  buildLegendConfig,
10
10
  flattenObjectArrayToCSV,
11
+ createTooltipPositioner,
11
12
  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
- }
13
+ createChartDownloadConfig,
14
+ niceNum,
15
+ } from '../utils/chart-config'
33
16
 
17
+ export const pieDownloadConfig = createChartDownloadConfig<PieWidgetData>(
18
+ flattenObjectArrayToCSV,
19
+ )
20
+
21
+ /**
22
+ * Generates ECharts configuration for pie and donut chart widgets. Falls back to a horizontal bar layout when multiple data series are provided.
23
+ *
24
+ * @param props - Pie chart configuration including data and theme.
25
+ * @returns Widget config with ECharts option object.
26
+ */
34
27
  export function pieConfig(props: PieConfig): PieWidgetConfig {
35
28
  return {
36
29
  type: 'pie',
37
30
  option: mergeEchartWidgetConfig(getCommonOptions(props), getOption(props)),
31
+ formatter: props.formatter,
32
+ labelFormatter: props.labelFormatter,
38
33
  }
39
34
  }
40
35
 
@@ -42,26 +37,94 @@ function getOption({
42
37
  data = [],
43
38
  theme,
44
39
  formatter,
40
+ labelFormatter,
45
41
  }: PieConfig): EchartOptionsProps {
46
42
  const multiSeries = (data?.length ?? 0) > 1
47
43
 
48
44
  if (multiSeries) {
45
+ let niceMin = 0
46
+ let niceMax = 1
47
+
49
48
  return {
49
+ legend: buildLegendConfig({ hasLegend: true, labelFormatter }),
50
+ grid: {
51
+ ...buildGridConfig(true, theme),
52
+ right: parseInt(theme.spacing(4)),
53
+ },
50
54
  xAxis: {
51
55
  type: 'value',
52
- show: true,
56
+ min: (extent: { min: number }) => {
57
+ niceMin = extent.min < 0 ? niceNum(extent.min) : 0
58
+ return niceMin
59
+ },
60
+ max: (extent: { min: number; max: number }) => {
61
+ niceMax = extent.max <= 0 ? 1 : niceNum(extent.max)
62
+ return niceMax
63
+ },
64
+ axisLabel: {
65
+ fontSize: theme.typography.overlineDelicate.fontSize,
66
+ fontFamily: theme.typography.overlineDelicate.fontFamily,
67
+ margin: parseInt(theme.spacing(1)),
68
+ show: true,
69
+ showMaxLabel: true,
70
+ showMinLabel: true,
71
+ verticalAlign: 'bottom' as const,
72
+ inside: true,
73
+ formatter: (value: number) => {
74
+ if (value !== niceMax && value !== niceMin) return ''
75
+ if (value === 0) return ''
76
+ return formatter ? formatter(value) : String(value)
77
+ },
78
+ },
79
+ axisLine: {
80
+ show: false,
81
+ },
82
+ axisTick: {
83
+ show: false,
84
+ },
85
+ splitLine: {
86
+ show: true,
87
+ lineStyle: {
88
+ color: theme.palette.black[4],
89
+ },
90
+ },
53
91
  },
54
92
  yAxis: {
55
93
  type: 'category',
56
- show: true,
57
- },
58
- legend: {
59
- show: true,
60
- bottom: 0,
94
+ axisLine: {
95
+ show: false,
96
+ },
97
+ axisTick: {
98
+ show: false,
99
+ },
100
+ axisLabel: {
101
+ padding: [parseInt(theme.spacing(0.5)), 0, 0, 0],
102
+ ...(labelFormatter && {
103
+ formatter: (value: string | number) =>
104
+ String(labelFormatter(value)),
105
+ }),
106
+ },
61
107
  },
62
- grid: {
63
- bottom: parseInt(theme.spacing(4)),
64
- right: parseInt(theme.spacing(4)),
108
+ tooltip: {
109
+ position: createTooltipPositioner(theme),
110
+ formatter: createTooltipFormatter((item) => {
111
+ const value = item.value as Record<string, string | number>
112
+ const index = item.dimensionNames?.[item.encode?.x?.at(0) ?? 1]
113
+ const _value = value[index ?? '']
114
+
115
+ const formattedValue =
116
+ typeof _value === 'number' && formatter
117
+ ? formatter(_value)
118
+ : (_value ?? '')
119
+
120
+ const marker = typeof item.marker === 'string' ? item.marker : ''
121
+ const seriesName = item.seriesName ? `${item.seriesName}: ` : ''
122
+ const name = labelFormatter
123
+ ? String(labelFormatter(item.name ?? ''))
124
+ : (item.name ?? '')
125
+
126
+ return { name, seriesName, marker, value: formattedValue }
127
+ }),
65
128
  },
66
129
  series: data.map((_: unknown, index: number) => ({
67
130
  datasetIndex: index,
@@ -77,7 +140,7 @@ function getOption({
77
140
  const hasLegend = true
78
141
 
79
142
  return {
80
- legend: buildLegendConfig(hasLegend),
143
+ legend: buildLegendConfig({ hasLegend, labelFormatter }),
81
144
  grid: {
82
145
  ...buildGridConfig(hasLegend, theme),
83
146
  left: 0,
@@ -109,7 +172,9 @@ function getOption({
109
172
 
110
173
  const marker = typeof item.marker === 'string' ? item.marker : ''
111
174
  const seriesName = item.seriesName ? `${item.seriesName}: ` : ''
112
- const name = item.name ?? ''
175
+ const name = labelFormatter
176
+ ? String(labelFormatter(item.name ?? ''))
177
+ : (item.name ?? '')
113
178
 
114
179
  return {
115
180
  name: seriesName,
@@ -148,7 +213,9 @@ function getOption({
148
213
  ? formatter(value)
149
214
  : (value ?? '')
150
215
 
151
- const nameFormatted = name
216
+ const nameFormatted = labelFormatter
217
+ ? String(labelFormatter(name ?? ''))
218
+ : (name ?? '')
152
219
 
153
220
  return `{c|${formattedValue}}\n\n{b|${nameFormatted}}`
154
221
  },
@@ -1,5 +1,5 @@
1
1
  import type { SxProps, Theme } from '@mui/material'
2
- import { baseSkeletonStyles } from '../_shared/skeleton'
2
+ import { baseSkeletonStyles } from '../utils/skeleton'
3
3
 
4
4
  export const styles = {
5
5
  skeleton: {
@@ -5,10 +5,13 @@ import type { RangeItemProps, RangeWidgetState } from '../types'
5
5
  import { styles } from '../style'
6
6
  import { useShallow } from 'zustand/shallow'
7
7
 
8
- type EditingState = '' | 'min' | 'max'
8
+ import { defaultFormatter } from '../../utils/formatter'
9
9
 
10
- const defaultFormatter = (value: number) => value.toString()
10
+ type EditingState = '' | 'min' | 'max'
11
11
 
12
+ /**
13
+ * Renders a single range slider with editable min/max text inputs, reading its configuration from the widget store.
14
+ */
12
15
  export function RangeItem({ id, index }: RangeItemProps) {
13
16
  const item = useWidgetStore(
14
17
  useShallow((state) => state.getWidget<RangeWidgetState>(id)?.data[index]),
@@ -1,5 +1,10 @@
1
1
  import type { RangeWidgetConfig } from './types'
2
2
 
3
+ /**
4
+ * Returns the default configuration for range (value range with labels) widgets.
5
+ *
6
+ * @returns Default range widget config.
7
+ */
3
8
  export function rangeConfig(): RangeWidgetConfig {
4
9
  return {}
5
10
  }
@@ -2,6 +2,9 @@ import type { RangeUIProps } from './types'
2
2
  import { Row } from '../formula/components/row'
3
3
  import { RangeItem } from './components/range-item'
4
4
 
5
+ /**
6
+ * Renders a range widget with one or more interactive dual-slider controls for selecting value ranges.
7
+ */
5
8
  export function RangeUI(props: RangeUIProps) {
6
9
  return (
7
10
  <Row id={props.id}>
@@ -12,35 +12,28 @@ import {
12
12
  scatterplotDataToCSV,
13
13
  buildLegendConfig,
14
14
  createTooltipFormatter,
15
+ createChartDownloadConfig,
15
16
  applyYAxisFormatter,
16
- } from '../_shared/chart-config'
17
- import { downloadToCSV, downloadToPNG, type DownloadItem } from '../actions'
18
- import type { ConfigProps } from '../loader/types'
17
+ applyXAxisFormatter,
18
+ } from '../utils/chart-config'
19
19
 
20
- export function scatterplotDownloadConfig({
21
- refUI,
22
- }: ConfigProps): DownloadItem<ScatterplotWidgetData>[] {
23
- return [
24
- {
25
- ...downloadToPNG,
26
- modifier: () => downloadToPNG.modifier(refUI),
27
- },
28
- {
29
- ...downloadToCSV,
30
- modifier: async (data) => {
31
- const rows = scatterplotDataToCSV(data)
32
- return downloadToCSV.modifier(rows)
33
- },
34
- },
35
- ]
36
- }
20
+ export const scatterplotDownloadConfig =
21
+ createChartDownloadConfig<ScatterplotWidgetData>(scatterplotDataToCSV)
37
22
 
23
+ /**
24
+ * Generates ECharts configuration for X-Y scatter plot widgets with value axes, legend support, and CARTO qualitative color palette.
25
+ *
26
+ * @param props - Scatterplot configuration including data points and theme.
27
+ * @returns Widget config with ECharts option object.
28
+ */
38
29
  export function scatterplotConfig(
39
30
  props: ScatterplotConfig,
40
31
  ): ScatterplotWidgetConfig {
41
32
  return {
42
33
  type: 'scatterplot',
43
34
  option: mergeEchartWidgetConfig(getCommonOptions(props), getOption(props)),
35
+ formatter: props.formatter,
36
+ labelFormatter: props.labelFormatter,
44
37
  }
45
38
  }
46
39
 
@@ -48,6 +41,7 @@ function getOption({
48
41
  data = [],
49
42
  theme,
50
43
  formatter,
44
+ labelFormatter,
51
45
  }: ScatterplotConfig): EchartOptionsProps {
52
46
  const hasLegend = data.length > 1
53
47
 
@@ -103,12 +97,12 @@ function getOption({
103
97
  }
104
98
 
105
99
  return {
106
- legend: buildLegendConfig(hasLegend),
100
+ legend: buildLegendConfig({ hasLegend, labelFormatter }),
107
101
  grid: {
108
102
  ...(!hasLegend && { bottom: parseInt(theme.spacing(1)) }),
109
103
  ...(hasLegend && { bottom: parseInt(theme.spacing(10)) }),
110
104
  },
111
- xAxis,
105
+ xAxis: applyXAxisFormatter(xAxis, labelFormatter),
112
106
  yAxis: applyYAxisFormatter(yAxis, formatter),
113
107
  tooltip: {
114
108
  trigger: 'item',
@@ -123,7 +117,9 @@ function getOption({
123
117
  ? formatter(_value)
124
118
  : (_value ?? '')
125
119
  const marker = typeof item.marker === 'string' ? item.marker : ''
126
- const name = item.seriesName ?? ''
120
+ const name = labelFormatter
121
+ ? String(labelFormatter(item.seriesName ?? ''))
122
+ : (item.seriesName ?? '')
127
123
 
128
124
  return { name, seriesName: '', marker, value: formattedValue }
129
125
  }),
@@ -1,5 +1,5 @@
1
1
  import type { SxProps, Theme } from '@mui/material'
2
- import { baseSkeletonStyles } from '../_shared/skeleton'
2
+ import { baseSkeletonStyles } from '../utils/skeleton'
3
3
 
4
4
  export const styles = {
5
5
  skeleton: {
@@ -13,6 +13,17 @@ const DEFAULT_SELECTION_LABELS: SelectionSummaryLabels = {
13
13
  clear: 'Clear',
14
14
  }
15
15
 
16
+ /**
17
+ * Displays the count of selected items with an optional clear button. Commonly used with the LockSelection action to show selection state in widgets.
18
+ *
19
+ * @example
20
+ * ```tsx
21
+ * <WidgetSelectionSummary
22
+ * selections={selectedItems.length}
23
+ * onClear={() => setSelectedItems([])}
24
+ * />
25
+ * ```
26
+ */
16
27
  export function WidgetSelectionSummary({
17
28
  selections,
18
29
  onClear,
@@ -3,6 +3,16 @@ import { useWidgetStore } from '../stores/widget-store'
3
3
  import { Suspense } from 'react'
4
4
  import { useShallow } from 'zustand/shallow'
5
5
 
6
+ /**
7
+ * Displays a skeleton loading placeholder while widget data is loading. Subscribes to widget loading state in the store and renders the provided Skeleton component or children accordingly.
8
+ *
9
+ * @example
10
+ * ```tsx
11
+ * <SkeletonLoader id="sales-chart" Skeleton={BarSkeleton}>
12
+ * <Bar id="sales-chart" />
13
+ * </SkeletonLoader>
14
+ * ```
15
+ */
6
16
  export function SkeletonLoader({
7
17
  id,
8
18
  children,
@@ -2,9 +2,11 @@ import { type SpreadWidgetState, type ValueProps } from '../types'
2
2
  import { useWidgetStore } from '../../stores/widget-store'
3
3
  import { Item } from '../../formula/components/item'
4
4
  import { useShallow } from 'zustand/shallow'
5
+ import { defaultFormatter } from '../../utils/formatter'
5
6
 
6
- const defaultFormatter = (value: number) => value.toString()
7
-
7
+ /**
8
+ * Displays the formatted maximum value for a spread widget data item.
9
+ */
8
10
  export function MaxValue({ id, index = 0, ...props }: ValueProps) {
9
11
  const max = useWidgetStore(
10
12
  useShallow(
@@ -2,9 +2,11 @@ import { type SpreadWidgetState, type ValueProps } from '../types'
2
2
  import { useWidgetStore } from '../../stores/widget-store'
3
3
  import { Item } from '../../formula/components/item'
4
4
  import { useShallow } from 'zustand/shallow'
5
+ import { defaultFormatter } from '../../utils/formatter'
5
6
 
6
- const defaultFormatter = (value: number) => value.toString()
7
-
7
+ /**
8
+ * Displays the formatted minimum value for a spread widget data item.
9
+ */
8
10
  export function MinValue({ id, index = 0, ...props }: ValueProps) {
9
11
  const min = useWidgetStore(
10
12
  useShallow(
@@ -1,6 +1,9 @@
1
1
  import { Item } from '../../formula/components/item'
2
2
  import type { ItemProps } from '../../formula/types'
3
3
 
4
+ /**
5
+ * Renders a dash separator between the min and max values in a spread widget.
6
+ */
4
7
  export function Separator(props: Omit<ItemProps, 'children'>) {
5
8
  return <Item {...props}>-</Item>
6
9
  }
@@ -2,6 +2,12 @@ import { downloadToCSV, downloadToPNG, type DownloadItem } from '../actions'
2
2
  import type { ConfigProps } from '../loader/types'
3
3
  import type { SpreadWidgetConfig, SpreadWidgetData } from './types'
4
4
 
5
+ /**
6
+ * Creates download configuration for spread widgets, supporting PNG (screenshot) and CSV (min/max data) exports.
7
+ *
8
+ * @param props - Configuration with `refUI` reference for PNG export.
9
+ * @returns Array of download items for use with the Download action.
10
+ */
5
11
  export function spreadDownloadConfig({
6
12
  refUI,
7
13
  }: ConfigProps): DownloadItem<SpreadWidgetData>[] {
@@ -21,6 +27,11 @@ export function spreadDownloadConfig({
21
27
  ]
22
28
  }
23
29
 
30
+ /**
31
+ * Returns the default configuration for spread (min/max value range) widgets.
32
+ *
33
+ * @returns Default spread widget config with empty series.
34
+ */
24
35
  export function spreadConfig(): SpreadWidgetConfig {
25
36
  return {
26
37
  series: [],
@@ -7,6 +7,9 @@ import { Prefix, Row, Suffix, Series } from '../formula'
7
7
  import { useWidgetRef } from '../../hooks'
8
8
  import { Box } from '@mui/material'
9
9
 
10
+ /**
11
+ * Renders a spread widget displaying min-max value pairs with optional prefixes, suffixes, and series indicators.
12
+ */
10
13
  export function SpreadUI(props: SpreadUIProps) {
11
14
  const { ref } = useWidgetRef(props.id)
12
15
 
@@ -31,6 +31,8 @@ export interface WidgetsStoreProps {
31
31
  registeredTools?: ToolRegistration[]
32
32
  /** Formatter function for widget values */
33
33
  formatter?: (value: number) => string
34
+ /** Formatter function for widget label/category values */
35
+ labelFormatter?: (value: string | number) => string | number
34
36
  /** Locale for number formatting (e.g., 'en-US', 'es-ES', 'fr-FR') */
35
37
  locale?: string
36
38
  }
@@ -2,6 +2,17 @@ import { Box } from '@mui/material'
2
2
  import { styles } from './style'
3
3
  import type { WidgetSubHeaderProps } from './types'
4
4
 
5
+ /**
6
+ * Flexible two-slot layout for displaying supplementary widget information such as totals, timestamps, or controls. Uses flexbox with space-between justification.
7
+ *
8
+ * @example
9
+ * ```tsx
10
+ * <WidgetSubHeader
11
+ * slotLeft={<Typography variant="caption">Total: 1,234</Typography>}
12
+ * slotRight={<Typography variant="caption">Updated: 2m ago</Typography>}
13
+ * />
14
+ * ```
15
+ */
5
16
  export function WidgetSubHeader({
6
17
  slotLeft,
7
18
  slotRight,
@@ -17,8 +17,10 @@ export const DEFAULT_COLUMN_ID = null
17
17
  export const DEFAULT_DIRECTION: SortDirection = 'asc'
18
18
 
19
19
  /**
20
- * Default table download configuration
21
- * Supports PNG export (screenshot) and CSV export (data)
20
+ * Creates download configuration for table widgets, supporting PNG (screenshot) and CSV (data) exports. CSV output uses column keys as headers and filters out `id` fields.
21
+ *
22
+ * @param props - Configuration with `refUI` reference for PNG export.
23
+ * @returns Array of download items for use with the Download action.
22
24
  */
23
25
  export function tableDownloadConfig({
24
26
  refUI,
@@ -59,7 +61,10 @@ export function tableDownloadConfig({
59
61
  }
60
62
 
61
63
  /**
62
- * Default table widget configuration
64
+ * Returns the default configuration for table widgets with pagination and sorting, including column definitions and local data mode.
65
+ *
66
+ * @param columns - Array of column definitions for the table.
67
+ * @returns Default table widget config.
63
68
  */
64
69
  export function tableConfig(columns: TableColumn[] = []): TableWidgetConfig {
65
70
  return {
@@ -37,9 +37,17 @@ export interface UsePaginationResult<T> {
37
37
  }
38
38
 
39
39
  /**
40
- * Hook for managing table pagination
41
- * Supports both local (client-side) and remote (server-side) pagination
42
- * State is persisted in the widget store for the given widgetId
40
+ * Hook for managing table pagination with support for both local (client-side) and remote (server-side) modes.
41
+ * State is persisted in the widget store for the given widget ID.
42
+ *
43
+ * @param widgetId - The widget ID to persist pagination state under.
44
+ * @param data - The full data array (used for local pagination and total count fallback).
45
+ * @returns Pagination state and navigation helpers.
46
+ *
47
+ * @example
48
+ * ```tsx
49
+ * const { page, setPage, paginatedData, totalPages } = usePagination(widgetId, data)
50
+ * ```
43
51
  */
44
52
  export function usePagination<T extends TableRow>(
45
53
  widgetId: string,
@@ -30,8 +30,17 @@ export interface UseSelectionResult {
30
30
  }
31
31
 
32
32
  /**
33
- * Hook for managing table row selection
34
- * Selection persists across pagination and is stored in the widget store
33
+ * Hook for managing table row selection with persistence across pagination.
34
+ * Selection state is stored in the widget store for the given widget ID.
35
+ *
36
+ * @param widgetId - The widget ID to persist selection state under.
37
+ * @param options - Optional configuration including an `onSelectionChange` callback.
38
+ * @returns Selection state and control functions (toggle, select, deselect, clear).
39
+ *
40
+ * @example
41
+ * ```tsx
42
+ * const { selectedIds, isAllSelected, handleSelectRow, clearSelection } = useSelection(widgetId)
43
+ * ```
35
44
  */
36
45
  export function useSelection(
37
46
  widgetId: string,
@@ -27,9 +27,17 @@ export interface UseSortResult<T> extends SortState {
27
27
  }
28
28
 
29
29
  /**
30
- * Hook for managing table sorting
31
- * Supports both local (client-side) and remote (server-side) sorting
32
- * State is persisted in the widget store for the given widgetId
30
+ * Hook for managing table sorting with support for both local (client-side) and remote (server-side) modes.
31
+ * State is persisted in the widget store for the given widget ID.
32
+ *
33
+ * @param widgetId - The widget ID to persist sort state under.
34
+ * @param data - The data array to sort (for local mode).
35
+ * @returns Sort state, sorted data, and sort control functions.
36
+ *
37
+ * @example
38
+ * ```tsx
39
+ * const { sortedData, sortField, sortDirection, handleSort } = useSort(widgetId, data)
40
+ * ```
33
41
  */
34
42
  export function useSort<T extends TableRow>(
35
43
  widgetId: string,