@carto/ps-react-ui 5.1.0 → 5.2.0
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.
- package/dist/actions-CF8RNKd6.js +1161 -0
- package/dist/actions-CF8RNKd6.js.map +1 -0
- package/dist/category-D01ruG-l.js +842 -0
- package/dist/category-D01ruG-l.js.map +1 -0
- package/dist/{download-DdaK3qgC.js → download-DGgFOaXj.js} +81 -80
- package/dist/download-DGgFOaXj.js.map +1 -0
- package/dist/{echart-CRihbmRv.js → echart-CwzbPElc.js} +3 -2
- package/dist/echart-CwzbPElc.js.map +1 -0
- package/dist/{formula-noJzQwKo.js → formula-BIxJr1P3.js} +6 -6
- package/dist/{formula-noJzQwKo.js.map → formula-BIxJr1P3.js.map} +1 -1
- package/dist/{markdown-2dfL6Cmb.js → markdown-oo9mnJun.js} +6 -6
- package/dist/{markdown-2dfL6Cmb.js.map → markdown-oo9mnJun.js.map} +1 -1
- package/dist/{spread-Ccpg9fi0.js → spread-CgCTKPQD.js} +7 -7
- package/dist/{spread-Ccpg9fi0.js.map → spread-CgCTKPQD.js.map} +1 -1
- package/dist/{table-Bx9Uj3U0.js → table-lb5momun.js} +3 -3
- package/dist/{table-Bx9Uj3U0.js.map → table-lb5momun.js.map} +1 -1
- package/dist/types/widgets-v2/actions/download/csv-item.d.ts +3 -3
- package/dist/types/widgets-v2/actions/download/index.d.ts +1 -1
- package/dist/types/widgets-v2/actions/download/png-item.d.ts +2 -2
- package/dist/types/widgets-v2/actions/download/types.d.ts +12 -1
- package/dist/types/widgets-v2/actions/fullscreen/fullscreen.d.ts +20 -13
- package/dist/types/widgets-v2/actions/index.d.ts +1 -1
- package/dist/types/widgets-v2/bar/download.d.ts +3 -3
- package/dist/types/widgets-v2/category/category-ui.d.ts +9 -1
- package/dist/types/widgets-v2/category/download.d.ts +3 -3
- package/dist/types/widgets-v2/echart/style.d.ts +1 -0
- package/dist/types/widgets-v2/formula/download.d.ts +3 -3
- package/dist/types/widgets-v2/histogram/download.d.ts +3 -3
- package/dist/types/widgets-v2/index.d.ts +1 -1
- package/dist/types/widgets-v2/markdown/download.d.ts +3 -3
- package/dist/types/widgets-v2/pie/download.d.ts +3 -3
- package/dist/types/widgets-v2/scatterplot/download.d.ts +3 -3
- package/dist/types/widgets-v2/spread/download.d.ts +3 -3
- package/dist/types/widgets-v2/table/download.d.ts +3 -3
- package/dist/types/widgets-v2/timeseries/download.d.ts +3 -3
- package/dist/types/widgets-v2/toolbox/toolbox.d.ts +1 -1
- package/dist/widgets-v2/actions.js +2 -2
- package/dist/widgets-v2/bar.js +7 -7
- package/dist/widgets-v2/bar.js.map +1 -1
- package/dist/widgets-v2/category.js +1 -1
- package/dist/widgets-v2/echart.js +1 -1
- package/dist/widgets-v2/formula.js +1 -1
- package/dist/widgets-v2/histogram.js +10 -10
- package/dist/widgets-v2/histogram.js.map +1 -1
- package/dist/widgets-v2/markdown.js +1 -1
- package/dist/widgets-v2/pie.js +10 -10
- package/dist/widgets-v2/pie.js.map +1 -1
- package/dist/widgets-v2/scatterplot.js +9 -9
- package/dist/widgets-v2/scatterplot.js.map +1 -1
- package/dist/widgets-v2/spread.js +1 -1
- package/dist/widgets-v2/table.js +1 -1
- package/dist/widgets-v2/timeseries.js +12 -12
- package/dist/widgets-v2/timeseries.js.map +1 -1
- package/dist/widgets-v2.js +274 -333
- package/dist/widgets-v2.js.map +1 -1
- package/package.json +3 -3
- package/src/widgets-v2/actions/download/csv-item.test.tsx +3 -3
- package/src/widgets-v2/actions/download/csv-item.tsx +6 -6
- package/src/widgets-v2/actions/download/download.tsx +5 -3
- package/src/widgets-v2/actions/download/index.ts +1 -1
- package/src/widgets-v2/actions/download/png-item.test.tsx +5 -3
- package/src/widgets-v2/actions/download/png-item.tsx +4 -4
- package/src/widgets-v2/actions/download/types.ts +15 -1
- package/src/widgets-v2/actions/fullscreen/fullscreen-store.test.tsx +155 -0
- package/src/widgets-v2/actions/fullscreen/fullscreen.test.tsx +39 -41
- package/src/widgets-v2/actions/fullscreen/fullscreen.tsx +211 -96
- package/src/widgets-v2/actions/index.ts +1 -0
- package/src/widgets-v2/actions/searcher/searcher.tsx +16 -0
- package/src/widgets-v2/bar/download.test.tsx +5 -3
- package/src/widgets-v2/bar/download.tsx +5 -4
- package/src/widgets-v2/category/category-ui.tsx +24 -13
- package/src/widgets-v2/category/category.tsx +37 -2
- package/src/widgets-v2/category/download.test.ts +4 -2
- package/src/widgets-v2/category/download.ts +5 -4
- package/src/widgets-v2/echart/style.ts +6 -0
- package/src/widgets-v2/formula/download.test.tsx +3 -1
- package/src/widgets-v2/formula/download.tsx +5 -4
- package/src/widgets-v2/histogram/download.test.ts +6 -4
- package/src/widgets-v2/histogram/download.ts +5 -4
- package/src/widgets-v2/index.ts +1 -0
- package/src/widgets-v2/markdown/download.test.ts +2 -2
- package/src/widgets-v2/markdown/download.tsx +5 -4
- package/src/widgets-v2/pie/download.test.ts +7 -3
- package/src/widgets-v2/pie/download.ts +5 -4
- package/src/widgets-v2/scatterplot/download.test.ts +4 -2
- package/src/widgets-v2/scatterplot/download.ts +5 -4
- package/src/widgets-v2/spread/download.test.ts +3 -1
- package/src/widgets-v2/spread/download.ts +5 -4
- package/src/widgets-v2/table/download.test.ts +5 -3
- package/src/widgets-v2/table/download.ts +4 -3
- package/src/widgets-v2/timeseries/download.test.ts +6 -4
- package/src/widgets-v2/timeseries/download.ts +5 -4
- package/src/widgets-v2/toolbox/toolbox.tsx +1 -1
- package/dist/actions-BjPfCLG9.js +0 -1024
- package/dist/actions-BjPfCLG9.js.map +0 -1
- package/dist/category-DGUDabsi.js +0 -829
- package/dist/category-DGUDabsi.js.map +0 -1
- package/dist/download-DdaK3qgC.js.map +0 -1
- package/dist/echart-CRihbmRv.js.map +0 -1
|
@@ -1,11 +1,12 @@
|
|
|
1
|
+
import type { ECharts } from 'echarts'
|
|
1
2
|
import {
|
|
2
3
|
useCallback,
|
|
3
4
|
useLayoutEffect,
|
|
5
|
+
useRef,
|
|
4
6
|
useState,
|
|
5
7
|
type ComponentType,
|
|
6
8
|
type ReactNode,
|
|
7
9
|
} from 'react'
|
|
8
|
-
import { createPortal } from 'react-dom'
|
|
9
10
|
import {
|
|
10
11
|
Box,
|
|
11
12
|
Dialog,
|
|
@@ -24,7 +25,19 @@ import { Fullscreen as FullscreenIcon } from '@mui/icons-material'
|
|
|
24
25
|
import { FullscreenExit as FullscreenExitIcon } from '@mui/icons-material'
|
|
25
26
|
import { Close as CloseIcon } from '@mui/icons-material'
|
|
26
27
|
import { Tooltip } from '../../../components'
|
|
27
|
-
import {
|
|
28
|
+
import { Provider } from '../../provider/widget-provider'
|
|
29
|
+
import {
|
|
30
|
+
createWidgetStore,
|
|
31
|
+
getEchartInstance,
|
|
32
|
+
getWidgetStore,
|
|
33
|
+
hasWidgetStore,
|
|
34
|
+
setWidgetStoreEntry,
|
|
35
|
+
subscribeEchartInstance,
|
|
36
|
+
useWidget,
|
|
37
|
+
useWidgetId,
|
|
38
|
+
useWidgetShallow,
|
|
39
|
+
type WidgetState,
|
|
40
|
+
} from '../../stores'
|
|
28
41
|
import { DEFAULT_FULLSCREEN_LABELS, type FullScreenLabels } from './labels'
|
|
29
42
|
import type { FullScreenWidgetState } from './types'
|
|
30
43
|
import { styles } from './style'
|
|
@@ -38,11 +51,18 @@ export interface FullScreenTriggerProps {
|
|
|
38
51
|
|
|
39
52
|
export interface FullScreenSlotProps {
|
|
40
53
|
/**
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
54
|
+
* The widget body. Rendered twice, identically: in the card, and again in
|
|
55
|
+
* the dialog while it's open. The components inside don't know which copy
|
|
56
|
+
* they are; the dialog's just runs on a widget store of its own — a copy
|
|
57
|
+
* of the card's taken on open, handed back to the card on close — so read
|
|
58
|
+
* the widget id with `useWidgetId()` inside the body rather than closing
|
|
59
|
+
* over the card's `id`.
|
|
60
|
+
*
|
|
61
|
+
* @deprecated The function form `(isFullScreen) => ReactNode` still works
|
|
62
|
+
* (`false` for the card, `true` for the dialog copy) but will be removed
|
|
63
|
+
* in the next major: pass the body as plain children.
|
|
44
64
|
*/
|
|
45
|
-
children: (isFullScreen: boolean) => ReactNode
|
|
65
|
+
children: ReactNode | ((isFullScreen: boolean) => ReactNode)
|
|
46
66
|
/** Header text rendered above the body when the modal is open. */
|
|
47
67
|
title?: ReactNode
|
|
48
68
|
/**
|
|
@@ -113,15 +133,42 @@ function FullScreenTrigger({
|
|
|
113
133
|
)
|
|
114
134
|
}
|
|
115
135
|
|
|
136
|
+
/** Id of the widget store the dialog copy runs on. */
|
|
137
|
+
export function fullScreenStoreId(id: string): string {
|
|
138
|
+
return `${id}::fullscreen`
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// Fields a copy doesn't carry between the card's store and the dialog's:
|
|
142
|
+
// what the consumer feeds through Provider props (kept live on both), what
|
|
143
|
+
// the pipeline derives, the transforms (functions each copy's actions
|
|
144
|
+
// register in their own store) and the open flag itself.
|
|
145
|
+
const NOT_COPIED = new Set<string>([
|
|
146
|
+
'rawData',
|
|
147
|
+
'data',
|
|
148
|
+
'dataTransforms',
|
|
149
|
+
'configTransforms',
|
|
150
|
+
'isLoading',
|
|
151
|
+
'isFetching',
|
|
152
|
+
'error',
|
|
153
|
+
'rawFormatter',
|
|
154
|
+
'labelFormatter',
|
|
155
|
+
'isFullScreen',
|
|
156
|
+
])
|
|
157
|
+
|
|
158
|
+
/** The UI state a copy carries: toggles, search text, sort, page… */
|
|
159
|
+
function copiedState(state: WidgetState): Partial<WidgetState> {
|
|
160
|
+
return Object.fromEntries(
|
|
161
|
+
Object.entries(state).filter(([key]) => !NOT_COPIED.has(key)),
|
|
162
|
+
) as Partial<WidgetState>
|
|
163
|
+
}
|
|
164
|
+
|
|
116
165
|
/**
|
|
117
|
-
* Body wrapper.
|
|
118
|
-
*
|
|
119
|
-
*
|
|
120
|
-
*
|
|
121
|
-
*
|
|
122
|
-
*
|
|
123
|
-
* ECharts (or any other heavy child) stays mounted while only its DOM
|
|
124
|
-
* parent changes.
|
|
166
|
+
* Body wrapper. The card keeps its copy of the body while the dialog is
|
|
167
|
+
* open, and the dialog mounts a second one on a store of its own: a copy
|
|
168
|
+
* of the card's UI state taken on open, and handed back to the card when
|
|
169
|
+
* the dialog closes. While open the two don't affect each other. MUI
|
|
170
|
+
* mounts the dialog copy on open and unmounts it after the close
|
|
171
|
+
* transition, which drops its store.
|
|
125
172
|
*/
|
|
126
173
|
function FullScreenSlot({
|
|
127
174
|
children,
|
|
@@ -144,59 +191,34 @@ function FullScreenSlot({
|
|
|
144
191
|
// margins — on a screen that small, fullscreen should mean fullscreen.
|
|
145
192
|
const theme = useTheme()
|
|
146
193
|
const fullBleed = useMediaQuery(theme.breakpoints.down('sm'))
|
|
147
|
-
const [inlineEl, setInlineEl] = useState<HTMLElement | null>(null)
|
|
148
|
-
const [dialogEl, setDialogEl] = useState<HTMLElement | null>(null)
|
|
149
|
-
// Stable, never-changing portal container created once per slot. Held in
|
|
150
|
-
// state (not a ref) so the React Compiler is happy reading it during
|
|
151
|
-
// render — it's immutable from React's perspective, only its DOM parent
|
|
152
|
-
// changes via `appendChild`. Switching `createPortal`'s `container`
|
|
153
|
-
// argument makes React unmount and remount the children, defeating the
|
|
154
|
-
// single-mount goal; keeping the container identical and moving the div
|
|
155
|
-
// imperatively avoids that.
|
|
156
|
-
const [portalDiv] = useState<HTMLDivElement | null>(() => {
|
|
157
|
-
if (typeof document === 'undefined') return null
|
|
158
|
-
const div = document.createElement('div')
|
|
159
|
-
// `display: contents` keeps the wrapper transparent in flow so it
|
|
160
|
-
// doesn't introduce a stray block when nested inside the inline slot.
|
|
161
|
-
div.style.display = 'contents'
|
|
162
|
-
return div
|
|
163
|
-
})
|
|
164
|
-
|
|
165
194
|
const handleClose = useCallback(() => {
|
|
166
195
|
getWidgetStore(id).setState({
|
|
167
196
|
isFullScreen: false,
|
|
168
197
|
} as Partial<FullScreenWidgetState>)
|
|
169
198
|
}, [id])
|
|
170
199
|
|
|
171
|
-
//
|
|
172
|
-
//
|
|
173
|
-
//
|
|
174
|
-
//
|
|
175
|
-
|
|
176
|
-
// Anti-blink: pin a `min-height` on the inline shell that's always live —
|
|
177
|
-
// not just while fullscreen is open. We re-measure whenever the body is
|
|
178
|
-
// inline (open=false) so the lock tracks data-driven height changes
|
|
179
|
-
// (Formula adding rows, Table growing, ECharts re-init…) and survives
|
|
180
|
-
// every fullscreen toggle. Briefly clearing minHeight before the measure
|
|
181
|
-
// lets the lock shrink as well as grow; both operations are synchronous
|
|
182
|
-
// within useLayoutEffect, so the browser never paints the intermediate
|
|
183
|
-
// "no lock" frame.
|
|
200
|
+
// Closing hands the dialog's state back to the card. Keyed on the flag,
|
|
201
|
+
// not on the close button, so every way out (Escape, backdrop, a Trigger)
|
|
202
|
+
// counts. The dialog copy is still mounted here — it unmounts after the
|
|
203
|
+
// transition — so its store still exists.
|
|
204
|
+
const wasOpen = useRef(open)
|
|
184
205
|
useLayoutEffect(() => {
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
206
|
+
const dialogId = fullScreenStoreId(id)
|
|
207
|
+
if (wasOpen.current && !open && hasWidgetStore(dialogId)) {
|
|
208
|
+
getWidgetStore(id).setState(
|
|
209
|
+
copiedState(getWidgetStore(dialogId).getState()),
|
|
210
|
+
)
|
|
189
211
|
}
|
|
190
|
-
|
|
191
|
-
}, [
|
|
212
|
+
wasOpen.current = open
|
|
213
|
+
}, [id, open])
|
|
192
214
|
|
|
193
215
|
const titleId = `widget-fullscreen-title-${id}`
|
|
194
|
-
const
|
|
216
|
+
const render = (inDialog: boolean) =>
|
|
217
|
+
typeof children === 'function' ? children(inDialog) : children
|
|
195
218
|
|
|
196
219
|
return (
|
|
197
220
|
<>
|
|
198
|
-
<Box
|
|
199
|
-
{portalDiv ? createPortal(rendered, portalDiv) : null}
|
|
221
|
+
<Box sx={styles.inlineSlot}>{render(false)}</Box>
|
|
200
222
|
<Dialog
|
|
201
223
|
open={open}
|
|
202
224
|
onClose={handleClose}
|
|
@@ -212,41 +234,146 @@ function FullScreenSlot({
|
|
|
212
234
|
// default modal layer the menu portals after the dialog and wins on
|
|
213
235
|
// DOM order, and the tooltip wins on z-index.
|
|
214
236
|
//
|
|
215
|
-
//
|
|
216
|
-
//
|
|
217
|
-
// already does it: `visibleCount` flips to `undefined` in fullscreen,
|
|
218
|
-
// overflow disappears and the popper unmounts. A consumer who keeps a
|
|
219
|
-
// numeric `visibleCount` in fullscreen keeps its popper above the
|
|
220
|
-
// dialog — which is the correct layer for a popover opened from
|
|
221
|
-
// inside it anyway.
|
|
237
|
+
// A Toolbox popover opened from inside the dialog portals after it
|
|
238
|
+
// too, so it stays above the dialog — the right layer for it.
|
|
222
239
|
>
|
|
223
|
-
<
|
|
224
|
-
<
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
{
|
|
233
|
-
|
|
234
|
-
<
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
240
|
+
<DialogStore sourceId={id}>
|
|
241
|
+
<DialogTitle id={titleId} component='div' sx={styles.dialogTitle}>
|
|
242
|
+
<Typography
|
|
243
|
+
variant='subtitle1'
|
|
244
|
+
component='span'
|
|
245
|
+
sx={styles.titleText}
|
|
246
|
+
>
|
|
247
|
+
{title}
|
|
248
|
+
</Typography>
|
|
249
|
+
<Box sx={styles.dialogActions}>
|
|
250
|
+
{actions}
|
|
251
|
+
<Tooltip title={_labels.close}>
|
|
252
|
+
<IconButton
|
|
253
|
+
size='medium'
|
|
254
|
+
aria-label={_labels.close}
|
|
255
|
+
onClick={handleClose}
|
|
256
|
+
>
|
|
257
|
+
<CloseSvg fontSize='small' {...iconProps} />
|
|
258
|
+
</IconButton>
|
|
259
|
+
</Tooltip>
|
|
260
|
+
</Box>
|
|
261
|
+
</DialogTitle>
|
|
262
|
+
<DialogContent sx={styles.dialogContent}>
|
|
263
|
+
{render(true)}
|
|
264
|
+
</DialogContent>
|
|
265
|
+
</DialogStore>
|
|
245
266
|
</Dialog>
|
|
246
267
|
</>
|
|
247
268
|
)
|
|
248
269
|
}
|
|
249
270
|
|
|
271
|
+
/**
|
|
272
|
+
* Gives the dialog copy (header actions included) its own widget store,
|
|
273
|
+
* seeded from the card's when the dialog mounts, and keeps the consumer's
|
|
274
|
+
* props (data, loading, error, formatters) flowing into it from the card
|
|
275
|
+
* while it's open. Does the same for the chart, if the widget has one: the
|
|
276
|
+
* dialog's starts from the card's and hands its state back on close.
|
|
277
|
+
*/
|
|
278
|
+
function DialogStore({
|
|
279
|
+
sourceId,
|
|
280
|
+
children,
|
|
281
|
+
}: {
|
|
282
|
+
sourceId: string
|
|
283
|
+
children: ReactNode
|
|
284
|
+
}) {
|
|
285
|
+
const dialogId = fullScreenStoreId(sourceId)
|
|
286
|
+
const live = useWidgetShallow(sourceId, (s) => ({
|
|
287
|
+
rawData: s.rawData,
|
|
288
|
+
isLoading: s.isLoading,
|
|
289
|
+
isFetching: s.isFetching,
|
|
290
|
+
error: s.error,
|
|
291
|
+
formatter: s.rawFormatter,
|
|
292
|
+
labelFormatter: s.labelFormatter,
|
|
293
|
+
}))
|
|
294
|
+
// Runs before the Provider below looks the id up, so it adopts this
|
|
295
|
+
// store instead of creating an empty one.
|
|
296
|
+
useState(() => {
|
|
297
|
+
const store = createWidgetStore(dialogId, {
|
|
298
|
+
data: live.rawData,
|
|
299
|
+
isLoading: live.isLoading,
|
|
300
|
+
isFetching: live.isFetching,
|
|
301
|
+
error: live.error,
|
|
302
|
+
formatter: live.formatter,
|
|
303
|
+
labelFormatter: live.labelFormatter,
|
|
304
|
+
})
|
|
305
|
+
store.setState(copiedState(getWidgetStore(sourceId).getState()))
|
|
306
|
+
setWidgetStoreEntry(dialogId, store)
|
|
307
|
+
return store
|
|
308
|
+
})
|
|
309
|
+
|
|
310
|
+
// A layout effect on purpose. It subscribes before the dialog chart's
|
|
311
|
+
// (passive) init effect publishes it, and its cleanup runs before that
|
|
312
|
+
// chart's (passive) dispose — so the chart is still alive to copy from.
|
|
313
|
+
useLayoutEffect(() => {
|
|
314
|
+
let dialogChart: ECharts | null = null
|
|
315
|
+
const unsubscribe = subscribeEchartInstance(dialogId, (chart) => {
|
|
316
|
+
// Published from inside the chart's init, before its first
|
|
317
|
+
// setOption, so the dialog's own option merges on top of the copy.
|
|
318
|
+
const card = liveChart(sourceId)
|
|
319
|
+
if (chart && card) copyChartState(card, chart)
|
|
320
|
+
dialogChart = chart
|
|
321
|
+
})
|
|
322
|
+
return () => {
|
|
323
|
+
unsubscribe()
|
|
324
|
+
const card = liveChart(sourceId)
|
|
325
|
+
if (card && dialogChart && !dialogChart.isDisposed()) {
|
|
326
|
+
copyChartState(dialogChart, card)
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
}, [dialogId, sourceId])
|
|
330
|
+
|
|
331
|
+
return (
|
|
332
|
+
<Provider
|
|
333
|
+
id={dialogId}
|
|
334
|
+
data={live.rawData}
|
|
335
|
+
isLoading={live.isLoading}
|
|
336
|
+
isFetching={live.isFetching}
|
|
337
|
+
error={live.error}
|
|
338
|
+
formatter={live.formatter}
|
|
339
|
+
labelFormatter={live.labelFormatter}
|
|
340
|
+
>
|
|
341
|
+
{children}
|
|
342
|
+
</Provider>
|
|
343
|
+
)
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
function liveChart(id: string): ECharts | null {
|
|
347
|
+
const chart = getEchartInstance(id)
|
|
348
|
+
return chart && !chart.isDisposed() ? chart : null
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
/**
|
|
352
|
+
* Put on `chart` what `peer` is showing: the legend selection, the dataZoom
|
|
353
|
+
* window and any drawn brush areas, which live in the ECharts instance
|
|
354
|
+
* rather than the widget store.
|
|
355
|
+
*/
|
|
356
|
+
function copyChartState(peer: ECharts, chart: ECharts): void {
|
|
357
|
+
chart.setOption(peer.getOption())
|
|
358
|
+
// The pointer was over `peer`, not `chart`: drop the tooltip and axis
|
|
359
|
+
// pointer that came along, or they'd stay drawn until the next hover.
|
|
360
|
+
chart.dispatchAction({ type: 'hideTip' })
|
|
361
|
+
chart.dispatchAction({ type: 'updateAxisPointer', currTrigger: 'leave' })
|
|
362
|
+
// Brush areas sit on the brush model, not in `getOption()`. `getModel` is
|
|
363
|
+
// private in the typings but stable across 5.x.
|
|
364
|
+
// ponytail: private API; if it goes away, track areas from the `brush` event instead.
|
|
365
|
+
const areas = (
|
|
366
|
+
peer as unknown as {
|
|
367
|
+
getModel?: () => {
|
|
368
|
+
getComponent: (type: string) => { areas?: unknown[] } | undefined
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
)
|
|
372
|
+
.getModel?.()
|
|
373
|
+
.getComponent('brush')?.areas
|
|
374
|
+
if (areas?.length) chart.dispatchAction({ type: 'brush', areas })
|
|
375
|
+
}
|
|
376
|
+
|
|
250
377
|
/**
|
|
251
378
|
* Merge a caller's `paperSx` over the default paper.
|
|
252
379
|
*
|
|
@@ -269,18 +396,6 @@ function resolvePaperSx(paperSx: SxProps<Theme> | undefined): SxProps<Theme> {
|
|
|
269
396
|
}
|
|
270
397
|
}
|
|
271
398
|
|
|
272
|
-
/**
|
|
273
|
-
* Briefly clear the inline shell's `min-height`, measure its natural
|
|
274
|
-
* height, then re-pin. Lives outside the component so the React Compiler
|
|
275
|
-
* doesn't see the DOM mutation as an attempt to modify a `useState` value
|
|
276
|
-
* — `el` here is just a parameter, not a tracked store value.
|
|
277
|
-
*/
|
|
278
|
-
function refreshInlineHeightLock(el: HTMLElement): void {
|
|
279
|
-
el.style.minHeight = ''
|
|
280
|
-
const h = el.getBoundingClientRect().height
|
|
281
|
-
if (h > 0) el.style.minHeight = `${h}px`
|
|
282
|
-
}
|
|
283
|
-
|
|
284
399
|
/**
|
|
285
400
|
* Namespace export. Consumers compose with:
|
|
286
401
|
*
|
|
@@ -290,7 +405,7 @@ function refreshInlineHeightLock(el: HTMLElement): void {
|
|
|
290
405
|
* </Widget.Actions>
|
|
291
406
|
* <Widget.Content>
|
|
292
407
|
* <Widget.FullScreen.Slot title={title} actions={<Widget.Download items={items} />}>
|
|
293
|
-
*
|
|
408
|
+
* <Body />
|
|
294
409
|
* </Widget.FullScreen.Slot>
|
|
295
410
|
* </Widget.Content>
|
|
296
411
|
* ```
|
|
@@ -40,6 +40,20 @@ export function Searcher({
|
|
|
40
40
|
string | undefined) ?? '',
|
|
41
41
|
)
|
|
42
42
|
|
|
43
|
+
// Follow text written by another Searcher of the same widget (the card
|
|
44
|
+
// and the fullscreen copy each render one). Skipped while this input has
|
|
45
|
+
// focus: its own debounced write lands late, and adopting it would drop
|
|
46
|
+
// whatever was typed since.
|
|
47
|
+
const [focused, setFocused] = useState(false)
|
|
48
|
+
const stored =
|
|
49
|
+
(useWidget(id, (s) => s.transformStates.searcher?.searchText) as
|
|
50
|
+
string | undefined) ?? ''
|
|
51
|
+
const [prevStored, setPrevStored] = useState(stored)
|
|
52
|
+
if (stored !== prevStored) {
|
|
53
|
+
setPrevStored(stored)
|
|
54
|
+
if (!focused) setLocal(stored)
|
|
55
|
+
}
|
|
56
|
+
|
|
43
57
|
const debouncedWrite = useMemo(
|
|
44
58
|
() =>
|
|
45
59
|
debounce(
|
|
@@ -78,6 +92,8 @@ export function Searcher({
|
|
|
78
92
|
placeholder={resolved.placeholder}
|
|
79
93
|
value={local}
|
|
80
94
|
onChange={handleSearchTextChange}
|
|
95
|
+
onFocus={() => setFocused(true)}
|
|
96
|
+
onBlur={() => setFocused(false)}
|
|
81
97
|
// The Searcher only mounts when the user explicitly toggles the
|
|
82
98
|
// SearcherToggle action — focusing the input on mount matches user
|
|
83
99
|
// intent, so the jsx-a11y/no-autofocus warning is the false-positive
|
|
@@ -50,7 +50,9 @@ describe('createBarDownloadConfig', () => {
|
|
|
50
50
|
})
|
|
51
51
|
const png = items.find((i) => i.id === 'png')
|
|
52
52
|
expect(png).toBeTruthy()
|
|
53
|
-
await expect(png!.resolve()).rejects.toThrow(
|
|
53
|
+
await expect(png!.resolve({ id: null })).rejects.toThrow(
|
|
54
|
+
/No PNG capture element/,
|
|
55
|
+
)
|
|
54
56
|
})
|
|
55
57
|
|
|
56
58
|
it('CSV resolve returns a download handle with the filename + revoke fn (single series)', async () => {
|
|
@@ -59,7 +61,7 @@ describe('createBarDownloadConfig', () => {
|
|
|
59
61
|
getData: () => sample,
|
|
60
62
|
})
|
|
61
63
|
const csv = items.find((i) => i.id === 'csv')!
|
|
62
|
-
const handle = await csv.resolve()
|
|
64
|
+
const handle = await csv.resolve({ id: null })
|
|
63
65
|
expect(handle.url).toBe('blob:mock')
|
|
64
66
|
expect(handle.filename).toBe('sales.csv')
|
|
65
67
|
expect(typeof handle.revoke).toBe('function')
|
|
@@ -84,7 +86,7 @@ describe('createBarDownloadConfig', () => {
|
|
|
84
86
|
filename: 'multi',
|
|
85
87
|
getData: () => multi,
|
|
86
88
|
})
|
|
87
|
-
await items.find((i) => i.id === 'csv')!.resolve()
|
|
89
|
+
await items.find((i) => i.id === 'csv')!.resolve({ id: null })
|
|
88
90
|
expect(csvText).toBe('name,value\na,1\nb,2\n\nname,value\nc,3')
|
|
89
91
|
vi.unstubAllGlobals()
|
|
90
92
|
})
|
|
@@ -1,20 +1,21 @@
|
|
|
1
1
|
import {
|
|
2
2
|
buildCsvDownloadItem,
|
|
3
3
|
buildPngDownloadItem,
|
|
4
|
+
type DownloadContext,
|
|
4
5
|
type DownloadItem,
|
|
5
6
|
} from '../actions/download'
|
|
6
7
|
import type { BarWidgetData } from './types'
|
|
7
8
|
|
|
8
9
|
export interface BarDownloadConfigArgs {
|
|
9
10
|
filename: string
|
|
10
|
-
getData: () => BarWidgetData
|
|
11
|
+
getData: (ctx: DownloadContext) => BarWidgetData
|
|
11
12
|
/**
|
|
12
13
|
* Optional getter for the widget's capture element (registered by
|
|
13
14
|
* `Widget.State` on its success path). When provided, a PNG item is
|
|
14
15
|
* prepended to the returned list. Wire it to
|
|
15
16
|
* `() => getCaptureEl(id)`.
|
|
16
17
|
*/
|
|
17
|
-
getCaptureEl?: () => HTMLElement | null
|
|
18
|
+
getCaptureEl?: (ctx: DownloadContext) => HTMLElement | null
|
|
18
19
|
/** PNG `pixelRatio` (default 2). */
|
|
19
20
|
pngPixelRatio?: number
|
|
20
21
|
/** PNG `backgroundColor` (default transparent). */
|
|
@@ -44,8 +45,8 @@ export function createBarDownloadConfig(
|
|
|
44
45
|
items.push(
|
|
45
46
|
buildCsvDownloadItem({
|
|
46
47
|
filename: args.filename,
|
|
47
|
-
getRows: () => {
|
|
48
|
-
const data = args.getData()
|
|
48
|
+
getRows: (ctx) => {
|
|
49
|
+
const data = args.getData(ctx)
|
|
49
50
|
const rows: unknown[][] = []
|
|
50
51
|
for (const [i, series] of data.entries()) {
|
|
51
52
|
if (i > 0) rows.push([])
|
|
@@ -96,6 +96,14 @@ export interface CategoryUIProps {
|
|
|
96
96
|
* No-op for single-series data — same convention as the legend.
|
|
97
97
|
*/
|
|
98
98
|
stacked?: boolean
|
|
99
|
+
/**
|
|
100
|
+
* Series indices hidden via the legend. Leave both this and
|
|
101
|
+
* `onHiddenSeriesChange` unset and CategoryUI keeps the set itself; pass
|
|
102
|
+
* them to own it — `Category` does, so the card and the fullscreen copy
|
|
103
|
+
* share it through the widget store.
|
|
104
|
+
*/
|
|
105
|
+
hiddenSeries?: ReadonlySet<number>
|
|
106
|
+
onHiddenSeriesChange?: (next: ReadonlySet<number>) => void
|
|
99
107
|
}
|
|
100
108
|
|
|
101
109
|
interface GroupedRow {
|
|
@@ -181,6 +189,8 @@ export function CategoryUI({
|
|
|
181
189
|
maxOverride,
|
|
182
190
|
size = 'small',
|
|
183
191
|
stacked = false,
|
|
192
|
+
hiddenSeries: hiddenSeriesProp,
|
|
193
|
+
onHiddenSeriesChange,
|
|
184
194
|
}: CategoryUIProps) {
|
|
185
195
|
const theme = useTheme()
|
|
186
196
|
const fmt = formatter ?? ((n: number) => String(n))
|
|
@@ -300,9 +310,10 @@ export function CategoryUI({
|
|
|
300
310
|
// selection, unrelated). Never allowed to reach "every series hidden":
|
|
301
311
|
// toggling the last visible one instead resets to "all visible" rather
|
|
302
312
|
// than leaving the widget blank.
|
|
303
|
-
const [
|
|
313
|
+
const [localHidden, setLocalHidden] = useState<ReadonlySet<number>>(
|
|
304
314
|
() => new Set(),
|
|
305
315
|
)
|
|
316
|
+
const hiddenSeries = hiddenSeriesProp ?? localHidden
|
|
306
317
|
// A reload with a different series breakdown invalidates hidden indices —
|
|
307
318
|
// index 2 may now point at an entirely different series. Reset rather
|
|
308
319
|
// than keep hiding whatever now occupies a stale index. Adjusted directly
|
|
@@ -317,7 +328,7 @@ export function CategoryUI({
|
|
|
317
328
|
const [prevSeriesKey, setPrevSeriesKey] = useState(seriesKey)
|
|
318
329
|
if (seriesKey !== prevSeriesKey) {
|
|
319
330
|
setPrevSeriesKey(seriesKey)
|
|
320
|
-
|
|
331
|
+
setLocalHidden(new Set())
|
|
321
332
|
}
|
|
322
333
|
// Real number of data series — NOT `series?.length`, which is legend
|
|
323
334
|
// metadata and may legitimately be shorter than the actual series count
|
|
@@ -327,18 +338,18 @@ export function CategoryUI({
|
|
|
327
338
|
const seriesCount = Math.max(data.length, 1)
|
|
328
339
|
const toggleSeries = useCallback(
|
|
329
340
|
(index: number) => {
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
341
|
+
// Start from what the user sees, not the stored set: `data` can
|
|
342
|
+
// shrink while the `series` names hold (the reset only watches the
|
|
343
|
+
// names), and a stale index would otherwise count toward the guard
|
|
344
|
+
// below — or make unchecking one series hide a different one.
|
|
345
|
+
const next = effectiveHidden(hiddenSeries, seriesCount)
|
|
346
|
+
if (next.has(index)) next.delete(index)
|
|
347
|
+
else next.add(index)
|
|
348
|
+
;(onHiddenSeriesChange ?? setLocalHidden)(
|
|
349
|
+
next.size >= seriesCount ? new Set() : next,
|
|
350
|
+
)
|
|
340
351
|
},
|
|
341
|
-
[seriesCount],
|
|
352
|
+
[hiddenSeries, onHiddenSeriesChange, seriesCount],
|
|
342
353
|
)
|
|
343
354
|
|
|
344
355
|
if (grouped.length === 0) return null
|
|
@@ -1,5 +1,11 @@
|
|
|
1
|
-
import { useMemo } from 'react'
|
|
2
|
-
import {
|
|
1
|
+
import { useCallback, useMemo } from 'react'
|
|
2
|
+
import {
|
|
3
|
+
getWidgetStore,
|
|
4
|
+
useWidget,
|
|
5
|
+
useWidgetId,
|
|
6
|
+
useWidgetShallow,
|
|
7
|
+
type WidgetState,
|
|
8
|
+
} from '../stores'
|
|
3
9
|
import { CategoryUI } from './category-ui'
|
|
4
10
|
import type {
|
|
5
11
|
CategoryKey,
|
|
@@ -23,6 +29,19 @@ const categorySelector = (s: WidgetState): CategorySlice => ({
|
|
|
23
29
|
labelFormatter: s.labelFormatter,
|
|
24
30
|
})
|
|
25
31
|
|
|
32
|
+
/**
|
|
33
|
+
* Legend-hidden series, kept on the widget store so every mounted Category
|
|
34
|
+
* of the widget — the card and its fullscreen copy — shows the same set.
|
|
35
|
+
* Tagged with the series breakdown it was made for: after a reload with
|
|
36
|
+
* different series the indices point elsewhere, so a stale set reads as
|
|
37
|
+
* empty instead of being reset with a write.
|
|
38
|
+
*/
|
|
39
|
+
interface CategoryWidgetState extends WidgetState {
|
|
40
|
+
categoryHiddenSeries?: { key: string; indices: ReadonlySet<number> }
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const NO_HIDDEN: ReadonlySet<number> = new Set()
|
|
44
|
+
|
|
26
45
|
function maxFromCategoryData(d: CategoryWidgetData | undefined): number {
|
|
27
46
|
if (!d) return 0
|
|
28
47
|
let m = 0
|
|
@@ -111,6 +130,20 @@ export function Category({
|
|
|
111
130
|
)
|
|
112
131
|
const effectiveMaxOverride =
|
|
113
132
|
maxOverride ?? (naturalMax > 0 ? naturalMax : undefined)
|
|
133
|
+
|
|
134
|
+
const seriesKey = JSON.stringify(series?.map((s) => s.name) ?? [])
|
|
135
|
+
const stored = useWidget<
|
|
136
|
+
CategoryWidgetState['categoryHiddenSeries'],
|
|
137
|
+
CategoryWidgetState
|
|
138
|
+
>(id, (s) => s.categoryHiddenSeries)
|
|
139
|
+
const hiddenSeries = stored?.key === seriesKey ? stored.indices : NO_HIDDEN
|
|
140
|
+
const onHiddenSeriesChange = useCallback(
|
|
141
|
+
(indices: ReadonlySet<number>) =>
|
|
142
|
+
getWidgetStore(id).setState({
|
|
143
|
+
categoryHiddenSeries: { key: seriesKey, indices },
|
|
144
|
+
} as Partial<CategoryWidgetState>),
|
|
145
|
+
[id, seriesKey],
|
|
146
|
+
)
|
|
114
147
|
return (
|
|
115
148
|
<CategoryUI
|
|
116
149
|
data={slice.data}
|
|
@@ -125,6 +158,8 @@ export function Category({
|
|
|
125
158
|
maxOverride={effectiveMaxOverride}
|
|
126
159
|
size={size}
|
|
127
160
|
stacked={stacked}
|
|
161
|
+
hiddenSeries={hiddenSeries}
|
|
162
|
+
onHiddenSeriesChange={onHiddenSeriesChange}
|
|
128
163
|
/>
|
|
129
164
|
)
|
|
130
165
|
}
|
|
@@ -60,7 +60,9 @@ describe('createCategoryDownloadConfig', () => {
|
|
|
60
60
|
filename: 'c',
|
|
61
61
|
getData: () => data,
|
|
62
62
|
})
|
|
63
|
-
const handle = await items
|
|
63
|
+
const handle = await items
|
|
64
|
+
.find((i) => i.id === 'csv')!
|
|
65
|
+
.resolve({ id: null })
|
|
64
66
|
expect(handle.filename).toBe('c.csv')
|
|
65
67
|
expect(csvText).toBe(
|
|
66
68
|
'series,name,value\nseries_1,a,1\nseries_1,b,2\nseries_2,a,10',
|
|
@@ -73,7 +75,7 @@ describe('createCategoryDownloadConfig', () => {
|
|
|
73
75
|
getData: () => data,
|
|
74
76
|
seriesNames: ['baseline', 'override'],
|
|
75
77
|
})
|
|
76
|
-
await items.find((i) => i.id === 'csv')!.resolve()
|
|
78
|
+
await items.find((i) => i.id === 'csv')!.resolve({ id: null })
|
|
77
79
|
expect(csvText.split('\n')[1]).toBe('baseline,a,1')
|
|
78
80
|
expect(csvText.split('\n')[3]).toBe('override,a,10')
|
|
79
81
|
})
|