@carto/ps-react-ui 5.1.0 → 5.3.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-Dhlz_adK.js +1167 -0
- package/dist/actions-Dhlz_adK.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/legend.js +34 -21
- package/dist/legend.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/legend/stores/types.d.ts +4 -2
- 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/actions/searcher/filter.d.ts +3 -2
- 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/types/widgets-v2/wrapper/style.d.ts +31 -2
- package/dist/types/widgets-v2/wrapper/widget-actions.d.ts +2 -2
- package/dist/types/widgets-v2/wrapper/widget-wrapper.d.ts +2 -2
- 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 +364 -376
- package/dist/widgets-v2.js.map +1 -1
- package/package.json +3 -3
- package/src/legend/components/legend-item/legend-item-ui.test.tsx +22 -1
- package/src/legend/components/legend-ramp/legend-ramp-ui.tsx +22 -6
- package/src/legend/stores/types.ts +4 -2
- 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/filter.test.ts +28 -0
- package/src/widgets-v2/actions/searcher/filter.ts +22 -4
- package/src/widgets-v2/actions/searcher/searcher-toggle.tsx +9 -4
- package/src/widgets-v2/actions/searcher/searcher.test.tsx +22 -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/src/widgets-v2/wrapper/style.ts +38 -2
- package/src/widgets-v2/wrapper/widget-actions.tsx +2 -2
- package/src/widgets-v2/wrapper/widget-wrapper.test.tsx +32 -2
- package/src/widgets-v2/wrapper/widget-wrapper.tsx +58 -32
- 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
|
* ```
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest'
|
|
2
|
+
import { filterBySearchText } from './filter'
|
|
3
|
+
|
|
4
|
+
const DATA = [
|
|
5
|
+
[
|
|
6
|
+
{ name: 'ES', value: 1 },
|
|
7
|
+
{ name: 'FR', value: 2 },
|
|
8
|
+
],
|
|
9
|
+
]
|
|
10
|
+
const COUNTRIES: Record<string, string> = { ES: 'Spain', FR: 'France' }
|
|
11
|
+
const label = (v: string | number) => COUNTRIES[v] ?? v
|
|
12
|
+
|
|
13
|
+
describe('filterBySearchText', () => {
|
|
14
|
+
it('matches the raw name when there is no label formatter', () => {
|
|
15
|
+
expect(filterBySearchText(DATA, 'es')).toEqual([[{ name: 'ES', value: 1 }]])
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
it('matches the formatted label, which is what the user sees', () => {
|
|
19
|
+
expect(filterBySearchText(DATA, 'spa', label)).toEqual([
|
|
20
|
+
[{ name: 'ES', value: 1 }],
|
|
21
|
+
])
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
it('no longer matches a raw name the label does not show', () => {
|
|
25
|
+
// "es" is in the raw code "ES" but in neither "Spain" nor "France".
|
|
26
|
+
expect(filterBySearchText(DATA, 'es', label)).toEqual([[]])
|
|
27
|
+
})
|
|
28
|
+
})
|
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Filters a 2D series of `{name, ...}` records by case-insensitive substring on
|
|
3
|
-
* the
|
|
3
|
+
* the label the user sees: `labelFormatter(name)` when a formatter is given,
|
|
4
|
+
* `name` otherwise. Keeps the dataset shape (one inner array per series).
|
|
4
5
|
* Used by the Searcher action's data transform.
|
|
5
6
|
*/
|
|
6
|
-
export function filterBySearchText(
|
|
7
|
+
export function filterBySearchText(
|
|
8
|
+
input: unknown,
|
|
9
|
+
search: string,
|
|
10
|
+
labelFormatter?: (value: string | number) => string | number,
|
|
11
|
+
): unknown {
|
|
7
12
|
if (!search) return input
|
|
8
13
|
const needle = search.toLowerCase()
|
|
9
14
|
if (!Array.isArray(input)) return input
|
|
@@ -13,14 +18,27 @@ export function filterBySearchText(input: unknown, search: string): unknown {
|
|
|
13
18
|
if (item == null) return false
|
|
14
19
|
if (typeof item === 'object' && 'name' in item) {
|
|
15
20
|
const rawName = (item as { name: unknown }).name
|
|
16
|
-
|
|
17
|
-
return name.toLowerCase().includes(needle)
|
|
21
|
+
return labelOf(rawName, labelFormatter).toLowerCase().includes(needle)
|
|
18
22
|
}
|
|
19
23
|
return stringifyPrimitive(item).toLowerCase().includes(needle)
|
|
20
24
|
})
|
|
21
25
|
})
|
|
22
26
|
}
|
|
23
27
|
|
|
28
|
+
function labelOf(
|
|
29
|
+
name: unknown,
|
|
30
|
+
labelFormatter?: (value: string | number) => string | number,
|
|
31
|
+
): string {
|
|
32
|
+
if (name == null) return ''
|
|
33
|
+
if (
|
|
34
|
+
labelFormatter &&
|
|
35
|
+
(typeof name === 'string' || typeof name === 'number')
|
|
36
|
+
) {
|
|
37
|
+
return stringifyPrimitive(labelFormatter(name))
|
|
38
|
+
}
|
|
39
|
+
return stringifyPrimitive(name)
|
|
40
|
+
}
|
|
41
|
+
|
|
24
42
|
function stringifyPrimitive(v: unknown): string {
|
|
25
43
|
if (typeof v === 'string') return v
|
|
26
44
|
if (typeof v === 'number' || typeof v === 'boolean') return String(v)
|
|
@@ -46,11 +46,16 @@ export function SearcherToggle({
|
|
|
46
46
|
(s) => (s.transformStates.searcher?.searchText as string | undefined) ?? '',
|
|
47
47
|
)
|
|
48
48
|
|
|
49
|
-
//
|
|
50
|
-
//
|
|
49
|
+
// Matched against the label the user sees, so a formatted name is found
|
|
50
|
+
// by what's on screen rather than by its raw value.
|
|
51
|
+
const labelFormatter = useWidget(id, (s) => s.labelFormatter)
|
|
52
|
+
|
|
53
|
+
// The transform fn closes over `text` and `labelFormatter`. Memoize via
|
|
54
|
+
// useCallback so identity only changes when either does, allowing
|
|
55
|
+
// useTransform to re-register.
|
|
51
56
|
const fn = useCallback(
|
|
52
|
-
(data: unknown) => filterBySearchText(data, text),
|
|
53
|
-
[text],
|
|
57
|
+
(data: unknown) => filterBySearchText(data, text, labelFormatter),
|
|
58
|
+
[text, labelFormatter],
|
|
54
59
|
)
|
|
55
60
|
|
|
56
61
|
const { enabled, toggle } = useSingleTransform(id, SEARCHER_DESCRIPTOR, fn, {
|
|
@@ -89,4 +89,26 @@ describe('<Searcher> + <SearcherToggle>', () => {
|
|
|
89
89
|
vi.useRealTimers()
|
|
90
90
|
}
|
|
91
91
|
})
|
|
92
|
+
|
|
93
|
+
it('filters by the formatted label the widget shows', () => {
|
|
94
|
+
const labelFormatter = (v: string | number) =>
|
|
95
|
+
({ apple: 'Manzana', banana: 'Plátano' })[String(v)] ?? v
|
|
96
|
+
render(
|
|
97
|
+
<Provider id='sr-label' data={DATA} labelFormatter={labelFormatter}>
|
|
98
|
+
<SearcherToggle initialEnabled />
|
|
99
|
+
<Searcher />
|
|
100
|
+
</Provider>,
|
|
101
|
+
)
|
|
102
|
+
act(() =>
|
|
103
|
+
getWidgetStore('sr-label').setState((s) => ({
|
|
104
|
+
transformStates: {
|
|
105
|
+
...s.transformStates,
|
|
106
|
+
searcher: { ...s.transformStates.searcher!, searchText: 'manz' },
|
|
107
|
+
},
|
|
108
|
+
})),
|
|
109
|
+
)
|
|
110
|
+
expect(getWidgetStore('sr-label').getState().data).toEqual([
|
|
111
|
+
[{ name: 'apple', value: 1 }],
|
|
112
|
+
])
|
|
113
|
+
})
|
|
92
114
|
})
|
|
@@ -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([])
|