@tsingroc/tsingroc-components 5.0.0-alpha.11 → 5.0.0-alpha.13
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/components/Auth.d.ts +310 -0
- package/dist/components/Auth.js +267 -0
- package/dist/components/AutoResizedECharts.d.ts +21 -0
- package/dist/components/AutoResizedECharts.js +98 -0
- package/dist/components/Calendar.d.ts +50 -0
- package/dist/components/Calendar.js +130 -0
- package/dist/components/CircularProgress.d.ts +21 -0
- package/dist/components/CircularProgress.js +34 -0
- package/dist/components/ConnectedECharts.d.ts +31 -0
- package/dist/components/ConnectedECharts.js +100 -0
- package/dist/components/ECharts.d.ts +57 -0
- package/dist/components/ECharts.js +255 -0
- package/dist/components/Header.d.ts +67 -0
- package/dist/components/Header.js +171 -0
- package/dist/components/ImageBackground.d.ts +32 -0
- package/dist/components/ImageBackground.js +76 -0
- package/dist/components/IndicatorLight.d.ts +44 -0
- package/dist/components/IndicatorLight.js +124 -0
- package/dist/components/LeftAlignedECharts.d.ts +42 -0
- package/dist/components/LeftAlignedECharts.js +270 -0
- package/dist/components/LineChartEditor.d.ts +74 -0
- package/dist/components/LineChartEditor.js +458 -0
- package/dist/components/LineChartTable.d.ts +38 -0
- package/dist/components/LineChartTable.js +245 -0
- package/dist/components/LinkedLineChart.d.ts +45 -0
- package/dist/components/LinkedLineChart.js +159 -0
- package/dist/components/QuickDateRangePicker.d.ts +30 -0
- package/dist/components/QuickDateRangePicker.js +58 -0
- package/dist/components/SegmentedButtons.d.ts +22 -0
- package/dist/components/SegmentedButtons.js +86 -0
- package/dist/components/SelectableECharts.d.ts +22 -0
- package/dist/components/SelectableECharts.js +402 -0
- package/dist/components/Sidebar.d.ts +79 -0
- package/dist/components/Sidebar.js +178 -0
- package/dist/components/TsingrocDatePicker.d.ts +38 -0
- package/dist/components/TsingrocDatePicker.js +64 -0
- package/dist/components/TsingrocTheme.d.ts +15 -0
- package/dist/components/TsingrocTheme.js +72 -0
- package/dist/components/UserButton.d.ts +42 -0
- package/dist/components/UserButton.js +105 -0
- package/dist/components/VerticalColorLegend.d.ts +7 -0
- package/dist/components/VerticalColorLegend.js +208 -0
- package/dist/components/WeatherMap.d.ts +18 -0
- package/dist/components/WeatherMap.js +658 -0
- package/dist/deckgl/TiandituLayer.d.ts +13 -0
- package/dist/deckgl/TiandituLayer.js +44 -0
- package/dist/deckgl/WeatherData.d.ts +53 -0
- package/dist/deckgl/WeatherData.js +94 -0
- package/dist/deckgl/index.d.ts +1 -0
- package/dist/deckgl/index.js +1 -0
- package/dist/echarts/coordinateSystems/grid.d.ts +43 -0
- package/dist/echarts/coordinateSystems/grid.js +108 -0
- package/dist/echarts/coordinateSystems/index.js +2 -0
- package/dist/echarts/coordinateSystems/polar.d.ts +45 -0
- package/dist/echarts/coordinateSystems/polar.js +96 -0
- package/dist/echarts/gl-types.d.js +0 -0
- package/dist/echarts/gl.d.ts +115 -0
- package/dist/echarts/gl.js +47 -0
- package/dist/echarts/index.d.ts +46 -0
- package/dist/echarts/index.js +46 -0
- package/dist/echarts/legend.d.ts +17 -0
- package/dist/echarts/legend.js +15 -0
- package/dist/echarts/radar.d.ts +24 -0
- package/dist/echarts/radar.js +22 -0
- package/dist/echarts/series/barSeries.d.ts +23 -0
- package/dist/echarts/series/barSeries.js +18 -0
- package/dist/echarts/series/boxplotSeries.d.ts +21 -0
- package/dist/echarts/series/boxplotSeries.js +40 -0
- package/dist/echarts/series/index.js +7 -0
- package/dist/echarts/series/intervalSeries.d.ts +32 -0
- package/dist/echarts/series/intervalSeries.js +55 -0
- package/dist/echarts/series/lineSeries.d.ts +36 -0
- package/dist/echarts/series/lineSeries.js +45 -0
- package/dist/echarts/series/maxBarSeries.d.ts +18 -0
- package/dist/echarts/series/maxBarSeries.js +39 -0
- package/dist/echarts/series/pieSeries.d.ts +31 -0
- package/dist/echarts/series/pieSeries.js +47 -0
- package/dist/echarts/series/windLineSeries.d.ts +47 -0
- package/dist/echarts/series/windLineSeries.js +51 -0
- package/{src/echarts/tooltip.ts → dist/echarts/tooltip.d.ts} +1 -5
- package/dist/echarts/tooltip.js +22 -0
- package/dist/env.d.js +0 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.js +21 -0
- package/dist/utils/debug.d.ts +1 -0
- package/dist/utils/debug.js +25 -0
- package/dist/utils/destructureLineDataItem.d.ts +6 -0
- package/dist/utils/destructureLineDataItem.js +17 -0
- package/dist/utils/filterMap.d.ts +1 -0
- package/dist/utils/filterMap.js +11 -0
- package/dist/utils/index.d.ts +8 -0
- package/dist/utils/index.js +8 -0
- package/dist/utils/math.d.ts +9 -0
- package/{src/utils/math.ts → dist/utils/math.js} +2 -2
- package/dist/utils/mock.d.ts +8 -0
- package/dist/utils/mock.js +40 -0
- package/dist/utils/normalizeIntoArray.d.ts +1 -0
- package/dist/utils/normalizeIntoArray.js +3 -0
- package/dist/utils/startOfQuarter.d.ts +2 -0
- package/dist/utils/startOfQuarter.js +4 -0
- package/dist/utils/timeAxisLabel.d.ts +5 -0
- package/dist/utils/timeAxisLabel.js +18 -0
- package/package.json +26 -14
- package/src/components/Auth.tsx +0 -623
- package/src/components/AutoResizedECharts.tsx +0 -70
- package/src/components/Calendar.tsx +0 -182
- package/src/components/CircularProgress.tsx +0 -38
- package/src/components/ConnectedECharts.tsx +0 -62
- package/src/components/ECharts.tsx +0 -206
- package/src/components/Header.tsx +0 -136
- package/src/components/ImageBackground.tsx +0 -58
- package/src/components/IndicatorLight.tsx +0 -106
- package/src/components/LeftAlignedECharts.tsx +0 -190
- package/src/components/LineChartEditor.tsx +0 -558
- package/src/components/LineChartTable.tsx +0 -286
- package/src/components/LinkedECharts.tsx +0 -51
- package/src/components/LinkedLineChart.tsx +0 -144
- package/src/components/QuickDateRangePicker.tsx +0 -84
- package/src/components/SegmentedButtons.tsx +0 -46
- package/src/components/Sidebar.tsx +0 -271
- package/src/components/StrictECharts.d.ts +0 -47
- package/src/components/StrictECharts.js +0 -1
- package/src/components/TsingrocDatePicker.tsx +0 -103
- package/src/components/TsingrocTheme.tsx +0 -48
- package/src/components/UserButton.tsx +0 -165
- package/src/components/VerticalColorLegend.tsx +0 -73
- package/src/components/WeatherMap.tsx +0 -522
- package/src/deckgl/TiandituLayer.ts +0 -56
- package/src/deckgl/WeatherData.ts +0 -157
- package/src/deckgl/index.ts +0 -4
- package/src/echarts/coordinateSystems/grid.ts +0 -143
- package/src/echarts/coordinateSystems/polar.ts +0 -148
- package/src/echarts/gl.ts +0 -159
- package/src/echarts/index.ts +0 -129
- package/src/echarts/legend.ts +0 -36
- package/src/echarts/radar.ts +0 -46
- package/src/echarts/series/barSeries.ts +0 -37
- package/src/echarts/series/boxplotSeries.ts +0 -62
- package/src/echarts/series/intervalSeries.ts +0 -70
- package/src/echarts/series/lineSeries.ts +0 -78
- package/src/echarts/series/maxBarSeries.ts +0 -55
- package/src/echarts/series/pieSeries.ts +0 -76
- package/src/echarts/series/windLineSeries.ts +0 -113
- package/src/index.ts +0 -120
- package/src/types.d.ts +0 -5
- package/src/utils/debug.ts +0 -39
- package/src/utils/mock.ts +0 -69
- package/src/utils/startOfQuarter.ts +0 -6
- /package/{src/echarts/coordinateSystems/index.ts → dist/echarts/coordinateSystems/index.d.ts} +0 -0
- /package/{src/echarts/series/index.ts → dist/echarts/series/index.d.ts} +0 -0
|
@@ -1,182 +0,0 @@
|
|
|
1
|
-
import { createStyles } from "antd-style";
|
|
2
|
-
import dayjs, { type Dayjs } from "dayjs";
|
|
3
|
-
import localeData from "dayjs/plugin/localeData";
|
|
4
|
-
import { useState } from "react";
|
|
5
|
-
|
|
6
|
-
export interface CalendarProps
|
|
7
|
-
extends Omit<React.HTMLAttributes<HTMLTableElement>, "onChange"> {
|
|
8
|
-
/**
|
|
9
|
-
* 当前显示的月份。
|
|
10
|
-
*
|
|
11
|
-
* 注意:传入的月份的时区会决定整个日历所用的时区。
|
|
12
|
-
*/
|
|
13
|
-
month: Dayjs;
|
|
14
|
-
/** 当前选中的日期。*/
|
|
15
|
-
selected?: Dayjs;
|
|
16
|
-
/** 选中日期更改时的回调函数。*/
|
|
17
|
-
onChange?: (selected: Dayjs) => void;
|
|
18
|
-
/**
|
|
19
|
-
* 无论一个月需要占用多少周,都总是显示 6 周。
|
|
20
|
-
* @default false
|
|
21
|
-
*/
|
|
22
|
-
alwaysSixWeeks?: boolean;
|
|
23
|
-
/**
|
|
24
|
-
* 淡化第一周和最后几周不属于本月的日期。
|
|
25
|
-
* @default true
|
|
26
|
-
*/
|
|
27
|
-
fadeAdjacentDays?: boolean;
|
|
28
|
-
/**
|
|
29
|
-
* 表头单元格的属性,详见 [MDN][1]。可以通过设置这里的 `children` 来自定义表头内容。
|
|
30
|
-
*
|
|
31
|
-
* [1]: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/th
|
|
32
|
-
*/
|
|
33
|
-
thProps?: (
|
|
34
|
-
/**
|
|
35
|
-
* 范围 0-6,表示一周的第几天
|
|
36
|
-
*
|
|
37
|
-
* 注意:这个数字的含义会受到地区设置的影响!请使用 `dayjs.weekdays()` 获取每一天的名称。
|
|
38
|
-
*/
|
|
39
|
-
weekday: number,
|
|
40
|
-
) => React.HTMLAttributes<HTMLTableCellElement>;
|
|
41
|
-
/**
|
|
42
|
-
* 日期单元格的属性,详见 [MDN][1]。可以通过设置这里的 `children` 来自定义单元格内容。
|
|
43
|
-
*
|
|
44
|
-
* [1]: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/td
|
|
45
|
-
*/
|
|
46
|
-
tdProps?: (
|
|
47
|
-
date: Dayjs,
|
|
48
|
-
selected: boolean,
|
|
49
|
-
) => React.HTMLAttributes<HTMLTableCellElement>;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
dayjs.extend(localeData);
|
|
53
|
-
|
|
54
|
-
const useStyles = createStyles(({ token, css, cx }) => {
|
|
55
|
-
const calendarFade = css`
|
|
56
|
-
color: ${token.colorTextDisabled};
|
|
57
|
-
`;
|
|
58
|
-
const calendarSelected = css`
|
|
59
|
-
background: ${token.colorPrimaryBg};
|
|
60
|
-
color: ${token.colorPrimary};
|
|
61
|
-
`;
|
|
62
|
-
const calendar = css`
|
|
63
|
-
box-sizing: border-box;
|
|
64
|
-
width: 100%;
|
|
65
|
-
height: 100%;
|
|
66
|
-
border-collapse: collapse;
|
|
67
|
-
font-family: ${token.fontFamily};
|
|
68
|
-
font-size: ${token.fontSize}px;
|
|
69
|
-
line-height: ${token.lineHeight};
|
|
70
|
-
user-select: none;
|
|
71
|
-
|
|
72
|
-
> thead > tr > th {
|
|
73
|
-
box-sizing: border-box;
|
|
74
|
-
height: ${token.fontSize * token.lineHeight + token.paddingXXS * 2}px;
|
|
75
|
-
padding: ${token.paddingXXS}px;
|
|
76
|
-
font-weight: normal;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
> tbody > tr > td {
|
|
80
|
-
box-sizing: border-box;
|
|
81
|
-
width: calc(100% / 7);
|
|
82
|
-
border: 1px solid ${token.colorBorder};
|
|
83
|
-
padding: ${token.paddingXXS}px;
|
|
84
|
-
vertical-align: bottom;
|
|
85
|
-
transition:
|
|
86
|
-
background ease ${token.motionDurationFast},
|
|
87
|
-
color ease ${token.motionDurationFast};
|
|
88
|
-
|
|
89
|
-
&:hover:not(.${cx(calendarSelected)}) {
|
|
90
|
-
background: ${token.colorBgTextHover};
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
`;
|
|
94
|
-
return {
|
|
95
|
-
calendar,
|
|
96
|
-
calendarFade,
|
|
97
|
-
calendarSelected,
|
|
98
|
-
};
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* 一个日历组件。
|
|
103
|
-
*
|
|
104
|
-
* 除了文档列出的属性之外,也接受所有 [HTML Table 元素][1] 接受的属性。
|
|
105
|
-
*
|
|
106
|
-
* [1]: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/table
|
|
107
|
-
*/
|
|
108
|
-
function Calendar(props: CalendarProps) {
|
|
109
|
-
const {
|
|
110
|
-
month,
|
|
111
|
-
selected: propsSelected,
|
|
112
|
-
onChange,
|
|
113
|
-
alwaysSixWeeks,
|
|
114
|
-
fadeAdjacentDays = true,
|
|
115
|
-
thProps,
|
|
116
|
-
tdProps,
|
|
117
|
-
className,
|
|
118
|
-
...rest
|
|
119
|
-
} = props;
|
|
120
|
-
const { cx, styles } = useStyles();
|
|
121
|
-
|
|
122
|
-
const [selected, setSelected] =
|
|
123
|
-
propsSelected === undefined
|
|
124
|
-
? // eslint-disable-next-line react-hooks/rules-of-hooks
|
|
125
|
-
useState<Dayjs | undefined>()
|
|
126
|
-
: [propsSelected, () => {}];
|
|
127
|
-
|
|
128
|
-
const monthStart = month.startOf("month");
|
|
129
|
-
const calendarStart = monthStart.startOf("week");
|
|
130
|
-
const monthEnd = month.endOf("month");
|
|
131
|
-
const minWeeks = Math.ceil(monthEnd.diff(calendarStart, "week", true));
|
|
132
|
-
const weekdays = [...dayjs.weekdaysShort()];
|
|
133
|
-
// 按地区设置调整一周的第一天
|
|
134
|
-
weekdays.splice(0, 0, ...weekdays.splice(calendarStart.day()));
|
|
135
|
-
return (
|
|
136
|
-
<table {...rest} className={cx(styles.calendar, className)}>
|
|
137
|
-
<thead>
|
|
138
|
-
<tr>
|
|
139
|
-
{weekdays.map((name, weekday) => (
|
|
140
|
-
<th key={weekday} children={name} {...thProps?.(weekday)} />
|
|
141
|
-
))}
|
|
142
|
-
</tr>
|
|
143
|
-
</thead>
|
|
144
|
-
<tbody>
|
|
145
|
-
{Array.from({ length: alwaysSixWeeks ? 6 : minWeeks }, (_, week) => (
|
|
146
|
-
<tr key={week}>
|
|
147
|
-
{Array(7)
|
|
148
|
-
.fill(null)
|
|
149
|
-
.map((_, weekday) => {
|
|
150
|
-
const date = calendarStart.add(week * 7 + weekday, "day");
|
|
151
|
-
const fade =
|
|
152
|
-
fadeAdjacentDays && date.month() != monthStart.month();
|
|
153
|
-
const isSelected =
|
|
154
|
-
Math.floor(selected?.diff(date, "day", true) ?? NaN) === 0;
|
|
155
|
-
const { className, ...props } = tdProps?.(date, false) ?? {};
|
|
156
|
-
return (
|
|
157
|
-
<td
|
|
158
|
-
key={weekday}
|
|
159
|
-
children={date.date()}
|
|
160
|
-
onClick={() => {
|
|
161
|
-
setSelected(date);
|
|
162
|
-
onChange?.(date);
|
|
163
|
-
}}
|
|
164
|
-
{...props}
|
|
165
|
-
className={cx(
|
|
166
|
-
{
|
|
167
|
-
[styles.calendarFade]: fade,
|
|
168
|
-
[styles.calendarSelected]: isSelected,
|
|
169
|
-
},
|
|
170
|
-
className,
|
|
171
|
-
)}
|
|
172
|
-
/>
|
|
173
|
-
);
|
|
174
|
-
})}
|
|
175
|
-
</tr>
|
|
176
|
-
))}
|
|
177
|
-
</tbody>
|
|
178
|
-
</table>
|
|
179
|
-
);
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
export default Calendar;
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { Progress, type ProgressProps } from "antd";
|
|
2
|
-
import type { ProgressGradient } from "antd/es/progress/progress";
|
|
3
|
-
|
|
4
|
-
export interface CircularProgressProps
|
|
5
|
-
extends ProgressProps,
|
|
6
|
-
React.RefAttributes<HTMLDivElement> {
|
|
7
|
-
/** 进度百分比,范围是 0-100。*/
|
|
8
|
-
progress?: number;
|
|
9
|
-
/**
|
|
10
|
-
* 进度条已完成部分的颜色。
|
|
11
|
-
* @default "#34A9D4"
|
|
12
|
-
*/
|
|
13
|
-
color?: string | string[] | ProgressGradient;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* 环形进度条。
|
|
18
|
-
*
|
|
19
|
-
* 本组件基于 [Ant Design 的 `Progress`][1] 自定义而来。
|
|
20
|
-
* 因此,除了文档中列出的属性以外,也兼容 `Progress` 的所有属性。
|
|
21
|
-
*
|
|
22
|
-
* [1]: https://ant-design.antgroup.com/components/progress-cn
|
|
23
|
-
*/
|
|
24
|
-
function CircularProgress(props: CircularProgressProps) {
|
|
25
|
-
return (
|
|
26
|
-
<Progress
|
|
27
|
-
type="circle"
|
|
28
|
-
percent={props.progress}
|
|
29
|
-
strokeLinecap="butt"
|
|
30
|
-
strokeWidth={9}
|
|
31
|
-
strokeColor={props.color ?? "#34A9D4"}
|
|
32
|
-
trailColor="#22405A"
|
|
33
|
-
{...props}
|
|
34
|
-
/>
|
|
35
|
-
);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export default CircularProgress;
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import * as echarts from "echarts/core";
|
|
2
|
-
import {
|
|
3
|
-
createContext,
|
|
4
|
-
use,
|
|
5
|
-
useId,
|
|
6
|
-
type ComponentType,
|
|
7
|
-
type ReactNode,
|
|
8
|
-
} from "react";
|
|
9
|
-
|
|
10
|
-
import AutoResizedECharts, { type withAutoResize } from "./AutoResizedECharts"; // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
11
|
-
import type { EChartsHOCType, EChartsProps } from "./ECharts";
|
|
12
|
-
|
|
13
|
-
const EChartsConnectorContext = createContext<string>("default");
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* 为 {@linkcode ConnectedECharts}/{@linkcode withConnector | withConnector(ECharts)}
|
|
17
|
-
* 提供联动上下文,只有同一个上下文内的 ECharts 会联动。
|
|
18
|
-
*/
|
|
19
|
-
export function EChartsConnector({ children }: { children: ReactNode }) {
|
|
20
|
-
const group = useId();
|
|
21
|
-
return (
|
|
22
|
-
<EChartsConnectorContext.Provider value={group}>
|
|
23
|
-
{children}
|
|
24
|
-
</EChartsConnectorContext.Provider>
|
|
25
|
-
);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* 为 ECharts 增加联动能力。所有添加了该能力的 ECharts 都会相互联动。
|
|
30
|
-
*
|
|
31
|
-
* 可以使用 {@linkcode EChartsConnector} 将同一个页面上的 ECharts
|
|
32
|
-
* 划分为多个组,不同组的 ECharts 不会联动。也可以使用 `group` 属性手动指定联动组。
|
|
33
|
-
*/
|
|
34
|
-
export const withConnector: EChartsHOCType<{ group?: string }> =
|
|
35
|
-
<Props extends EChartsProps>(ECharts: ComponentType<Props>) =>
|
|
36
|
-
(props: Props & { group?: string }) => {
|
|
37
|
-
"use memo";
|
|
38
|
-
const contextGroup = use(EChartsConnectorContext);
|
|
39
|
-
const { onInit, group = contextGroup, ...rest } = props;
|
|
40
|
-
return (
|
|
41
|
-
// @ts-expect-error 见 ./AutoResizedECharts.tsx
|
|
42
|
-
<ECharts
|
|
43
|
-
onInit={(instance) => {
|
|
44
|
-
instance.group = group;
|
|
45
|
-
echarts.connect(group);
|
|
46
|
-
return onInit?.(instance);
|
|
47
|
-
}}
|
|
48
|
-
{...rest}
|
|
49
|
-
/>
|
|
50
|
-
);
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* 预置了联动和自适应容器尺寸能力的 ECharts。
|
|
55
|
-
*
|
|
56
|
-
* @see {@linkcode withConnector}
|
|
57
|
-
* @see {@linkcode withAutoResize}
|
|
58
|
-
*/
|
|
59
|
-
const ConnectedECharts = Object.assign(withConnector(AutoResizedECharts), {
|
|
60
|
-
displayName: "ConnectedECharts",
|
|
61
|
-
});
|
|
62
|
-
export default ConnectedECharts;
|
|
@@ -1,206 +0,0 @@
|
|
|
1
|
-
import type { EChartsOption } from "echarts";
|
|
2
|
-
import type {
|
|
3
|
-
EChartsCoreOption,
|
|
4
|
-
EChartsInitOpts,
|
|
5
|
-
ECharts as EChartsInstance,
|
|
6
|
-
SetOptionOpts,
|
|
7
|
-
} from "echarts/core";
|
|
8
|
-
import * as echarts from "echarts/core";
|
|
9
|
-
import {
|
|
10
|
-
useEffect,
|
|
11
|
-
useEffectEvent,
|
|
12
|
-
useImperativeHandle,
|
|
13
|
-
useRef,
|
|
14
|
-
type ComponentType,
|
|
15
|
-
type HTMLAttributes,
|
|
16
|
-
type ReactNode,
|
|
17
|
-
type Ref,
|
|
18
|
-
type RefObject,
|
|
19
|
-
} from "react";
|
|
20
|
-
|
|
21
|
-
import { debugAssert } from "../utils/debug";
|
|
22
|
-
|
|
23
|
-
export interface EChartsProps<Option extends EChartsCoreOption = EChartsOption>
|
|
24
|
-
extends HTMLAttributes<HTMLDivElement> {
|
|
25
|
-
/**
|
|
26
|
-
* 用于命令式操作 ECharts 容器和实例的 ref。
|
|
27
|
-
*
|
|
28
|
-
* 注意 effect 首次执行时 ECharts 实例尚未被创建。如果需要在 ECharts
|
|
29
|
-
* 实例上添加事件监听器或者执行其它的初始化操作,请使用 {@linkcode onInit}。
|
|
30
|
-
*/
|
|
31
|
-
ref?: Ref<EChartsRef>;
|
|
32
|
-
/** 主题。 @default "default" */
|
|
33
|
-
theme?: string | Record<string, any> | null;
|
|
34
|
-
/**
|
|
35
|
-
* 初始化实例时的选项。
|
|
36
|
-
*
|
|
37
|
-
* 修改该属性会导致 ECharts 实例被销毁并重新创建,因此建议不要频繁修改该属性,并且推荐使用
|
|
38
|
-
* React Compiler 或者 useMemo 将该属性记忆化。
|
|
39
|
-
*/
|
|
40
|
-
initOpts?: EChartsInitOpts;
|
|
41
|
-
/** 配置对象。 */
|
|
42
|
-
option?: Option;
|
|
43
|
-
/**
|
|
44
|
-
* 更新 {@linkcode option} 时的选项。其中的 {@linkcode SetOptionOpts.silent | silent}
|
|
45
|
-
* 选项也会在更新 {@linkcode theme} 时使用。
|
|
46
|
-
*
|
|
47
|
-
* 注意该属性变化后只会从下一次 option 更新开始生效。
|
|
48
|
-
*/
|
|
49
|
-
setOptionOpts?: SetOptionOpts;
|
|
50
|
-
/**
|
|
51
|
-
* 初始化实例(`echarts.init()`)后执行的回调。如果返回函数,则会在销毁实例(`instance.dispose()`)之前调用。
|
|
52
|
-
*
|
|
53
|
-
* 推荐在这个回调中为 ECharts 实例添加事件监听器。
|
|
54
|
-
*/
|
|
55
|
-
onInit?: (instance: EChartsInstance) => void | undefined | (() => void);
|
|
56
|
-
/** option 更新(`instance.setOption()`)后执行的回调。注意如果设置了 {@linkcode lazyUpdate},那么这个回调大概率没什么用。 */
|
|
57
|
-
onSetOption?: (instance: EChartsInstance) => void;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
export interface EChartsRef {
|
|
61
|
-
/** 容纳 ECharts 画布的 div 容器。 */
|
|
62
|
-
container: HTMLDivElement;
|
|
63
|
-
/** ECharts 实例。注意该实例在 ref 连接时尚未创建,如果要在实例创建时执行代码请使用 {@linkcode EChartsProps.onInit | onInit} 属性。 */
|
|
64
|
-
instance?: EChartsInstance;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/** 用于 HOC 的返回值。 */
|
|
68
|
-
export type EChartsComponentType<Extra> = <
|
|
69
|
-
Option extends EChartsCoreOption = EChartsOption,
|
|
70
|
-
>(
|
|
71
|
-
props: EChartsProps<Option> & Extra,
|
|
72
|
-
) => ReactNode;
|
|
73
|
-
|
|
74
|
-
/** 用于方便定义 HOC。 */
|
|
75
|
-
export interface EChartsHOCType<Extra = {}> {
|
|
76
|
-
<PrevExtra>(
|
|
77
|
-
ECharts: EChartsComponentType<PrevExtra>,
|
|
78
|
-
): EChartsComponentType<PrevExtra & Extra>;
|
|
79
|
-
<Props extends EChartsProps>(
|
|
80
|
-
ECharts: (props: Props) => ReactNode,
|
|
81
|
-
): (props: Props & Extra) => ReactNode;
|
|
82
|
-
<Props extends EChartsProps>(
|
|
83
|
-
ECharts: ComponentType<Props>,
|
|
84
|
-
): ComponentType<Props & Extra>;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* ECharts 的 React 封装,支持 `theme`、`opts` 等初始化参数和 `option` 配置的响应式更新。
|
|
89
|
-
*/
|
|
90
|
-
const ECharts: EChartsComponentType<{}> = <
|
|
91
|
-
Option extends EChartsCoreOption = EChartsOption,
|
|
92
|
-
>(
|
|
93
|
-
props: EChartsProps<Option>,
|
|
94
|
-
) => {
|
|
95
|
-
const {
|
|
96
|
-
ref: outerRef,
|
|
97
|
-
theme,
|
|
98
|
-
initOpts: opts,
|
|
99
|
-
option,
|
|
100
|
-
setOptionOpts,
|
|
101
|
-
onInit,
|
|
102
|
-
onSetOption,
|
|
103
|
-
...rest
|
|
104
|
-
} = props;
|
|
105
|
-
|
|
106
|
-
const ref = useRef<EChartsRef>(null);
|
|
107
|
-
useForwardEChartsRef(outerRef, ref);
|
|
108
|
-
|
|
109
|
-
// theme 变化时,设置 theme
|
|
110
|
-
const setTheme = useEffectEvent(
|
|
111
|
-
(theme: string | Record<string, any> | null | undefined) => {
|
|
112
|
-
debugAssert(ref.current, "effect should run after ref is connected");
|
|
113
|
-
ref.current.instance?.setTheme(theme ?? "default", {
|
|
114
|
-
silent: setOptionOpts?.silent,
|
|
115
|
-
});
|
|
116
|
-
},
|
|
117
|
-
);
|
|
118
|
-
// 没必要判断是否首次运行,因为首次运行时 ref.current?.instance 必定为 undefined
|
|
119
|
-
useEffect(() => setTheme(theme), [theme]);
|
|
120
|
-
|
|
121
|
-
// option 变化时,设置 option
|
|
122
|
-
const setOption = useEffectEvent(
|
|
123
|
-
(option: Option, isInit: boolean = false) => {
|
|
124
|
-
debugAssert(ref.current, "effect should run after ref is connected");
|
|
125
|
-
const { instance } = ref.current;
|
|
126
|
-
if (instance) {
|
|
127
|
-
instance.setOption(option, {
|
|
128
|
-
...setOptionOpts,
|
|
129
|
-
// 在实例创建时,由于我们已经处在一个 animation frame,没必要再等待下一个 animation frame
|
|
130
|
-
lazyUpdate: !isInit && setOptionOpts?.lazyUpdate,
|
|
131
|
-
});
|
|
132
|
-
onSetOption?.(instance);
|
|
133
|
-
}
|
|
134
|
-
},
|
|
135
|
-
);
|
|
136
|
-
// 同理,没必要判断是否首次运行
|
|
137
|
-
useEffect(() => option && setOption(option), [option]);
|
|
138
|
-
|
|
139
|
-
// opts 变化时,重新创建实例
|
|
140
|
-
const onDisposeRef = useRef<() => void>(null);
|
|
141
|
-
const init = useEffectEvent((opts: EChartsInitOpts | undefined) => {
|
|
142
|
-
debugAssert(ref.current, "effect should run after ref is connected");
|
|
143
|
-
const { container, instance: existingInstance } = ref.current;
|
|
144
|
-
// 严格模式下由于 effect 被执行两次,第二次执行时 instance 已经创建,故应该跳过
|
|
145
|
-
if (existingInstance) return;
|
|
146
|
-
const instance = echarts.init(container, theme, opts);
|
|
147
|
-
ref.current = { container, instance };
|
|
148
|
-
onDisposeRef.current = onInit?.(instance) ?? null;
|
|
149
|
-
if (option) {
|
|
150
|
-
setOption(option, true);
|
|
151
|
-
}
|
|
152
|
-
});
|
|
153
|
-
const dispose = useEffectEvent(() => {
|
|
154
|
-
if (ref.current) {
|
|
155
|
-
const { container, instance } = ref.current;
|
|
156
|
-
if (instance) {
|
|
157
|
-
onDisposeRef.current?.();
|
|
158
|
-
instance.dispose();
|
|
159
|
-
ref.current = { container };
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
});
|
|
163
|
-
useEffect(() => {
|
|
164
|
-
// 将实例创建延迟到下一个 animation frame 以确保首次渲染尺寸正确
|
|
165
|
-
const animationFrame = requestAnimationFrame(() => init(opts));
|
|
166
|
-
return () => {
|
|
167
|
-
cancelAnimationFrame(animationFrame);
|
|
168
|
-
dispose();
|
|
169
|
-
};
|
|
170
|
-
}, [opts]);
|
|
171
|
-
|
|
172
|
-
return (
|
|
173
|
-
<div
|
|
174
|
-
ref={(container) => {
|
|
175
|
-
if (container === null) {
|
|
176
|
-
ref.current = null;
|
|
177
|
-
} else {
|
|
178
|
-
ref.current = { container };
|
|
179
|
-
}
|
|
180
|
-
}}
|
|
181
|
-
{...rest}
|
|
182
|
-
/>
|
|
183
|
-
);
|
|
184
|
-
};
|
|
185
|
-
export default ECharts;
|
|
186
|
-
|
|
187
|
-
// React Compiler 无法处理 getter
|
|
188
|
-
function useForwardEChartsRef(
|
|
189
|
-
outerRef: Ref<EChartsRef> | undefined,
|
|
190
|
-
innerRef: RefObject<EChartsRef | null>,
|
|
191
|
-
) {
|
|
192
|
-
useImperativeHandle(outerRef, () => {
|
|
193
|
-
debugAssert(innerRef.current, "ref should be connected");
|
|
194
|
-
return {
|
|
195
|
-
get container() {
|
|
196
|
-
debugAssert(innerRef.current, "ref should be connected");
|
|
197
|
-
return innerRef.current.container;
|
|
198
|
-
},
|
|
199
|
-
get instance() {
|
|
200
|
-
debugAssert(innerRef.current, "ref should be connected");
|
|
201
|
-
return innerRef.current.instance;
|
|
202
|
-
},
|
|
203
|
-
};
|
|
204
|
-
// oxlint-disable-next-line exhaustive-deps
|
|
205
|
-
}, []);
|
|
206
|
-
}
|
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
import { Flex, Layout, Menu, theme, type MenuProps } from "antd";
|
|
2
|
-
import type { CSSProperties, ReactNode } from "react";
|
|
3
|
-
|
|
4
|
-
import UserButton from "./UserButton";
|
|
5
|
-
|
|
6
|
-
export type MenuItem = Required<MenuProps>["items"][number];
|
|
7
|
-
|
|
8
|
-
export interface HeaderProps extends MenuProps {
|
|
9
|
-
/**
|
|
10
|
-
* 网站 logo 的 URL。
|
|
11
|
-
*
|
|
12
|
-
* 建议导入图片,然后填入导入得到的地址,而不要硬编码地址。
|
|
13
|
-
*/
|
|
14
|
-
logo?: string;
|
|
15
|
-
/** 顶栏的标题。*/
|
|
16
|
-
title?: string;
|
|
17
|
-
/**
|
|
18
|
-
* 顶栏左端部分(logo 和标题)的宽度。在与边栏搭配时,推荐设置成与边栏同宽。
|
|
19
|
-
* @default 260
|
|
20
|
-
*/
|
|
21
|
-
leftEndWidth?: number | string;
|
|
22
|
-
/**
|
|
23
|
-
* 顶栏左端的内容(logo 和标题)。设置了该属性时,
|
|
24
|
-
* {@linkcode HeaderProps.logo | logo}、
|
|
25
|
-
* {@linkcode HeaderProps.title | title} 和
|
|
26
|
-
* {@linkcode HeaderProps.leftEndWidth | leftEndWidth} 将失去作用。
|
|
27
|
-
* 填 `null` 可以隐藏掉默认值(与 `undefined` 不同!)。
|
|
28
|
-
*/
|
|
29
|
-
leftEnd?: ReactNode;
|
|
30
|
-
/**
|
|
31
|
-
* 菜单项配置,默认为空。
|
|
32
|
-
*
|
|
33
|
-
* 该属性以及其余属性的用法可参考 [`Menu` 组件的文档][1]。
|
|
34
|
-
*
|
|
35
|
-
* [1]: https://ant-design.antgroup.com/components/menu-cn
|
|
36
|
-
*/
|
|
37
|
-
items?: MenuItem[];
|
|
38
|
-
/** 当前选中的菜单项 key 数组。 */
|
|
39
|
-
selectedKeys?: string[];
|
|
40
|
-
/** 当前展开的子菜单 key 数组。 */
|
|
41
|
-
openKeys?: string[];
|
|
42
|
-
/** 菜单项被选中时的回调函数。 */
|
|
43
|
-
onSelect?: MenuProps["onSelect"];
|
|
44
|
-
/** 子菜单展开/收起时的回调函数。 */
|
|
45
|
-
onOpenChange?: MenuProps["onOpenChange"];
|
|
46
|
-
/**
|
|
47
|
-
* 顶栏右端的额外内容。默认使用 {@linkcode UserButton} 组件。
|
|
48
|
-
* 填 `null` 可以隐藏掉默认值(与 `undefined` 不同!)。
|
|
49
|
-
* @default <UserButton layout="header" />
|
|
50
|
-
*/
|
|
51
|
-
rightEnd?: ReactNode;
|
|
52
|
-
/** 额外的 `className`。*/
|
|
53
|
-
className?: string;
|
|
54
|
-
/** 额外的 CSS 样式。*/
|
|
55
|
-
style?: CSSProperties;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* 顶栏组件。该组件需要放置在 [Ant Design 的 `Layout` 组件][1]内部才能正常工作。
|
|
60
|
-
* 如果没有指定 {@linkcode HeaderProps.rightEnd | rightEnd} 属性,
|
|
61
|
-
* 那么还需要包裹在 {@linkcode AuthProvider} 内,并且经过 {@linkcode AuthCheck} 验证后
|
|
62
|
-
* 才能正常显示顶栏右端的用户信息按钮。
|
|
63
|
-
*
|
|
64
|
-
* 一般来说,使用该组件时至少需要提供 `logo`、`items` 和 `onSelect` 三个属性,具体用法请参照范例。
|
|
65
|
-
*
|
|
66
|
-
* 除了文档中列出的属性之外,该组件会把额外的属性全部传递给内部的菜单 [`Menu` 组件][2]。
|
|
67
|
-
*
|
|
68
|
-
* [1]: https://ant-design.antgroup.com/components/layout-cn
|
|
69
|
-
* [2]: https://ant-design.antgroup.com/components/menu-cn
|
|
70
|
-
*/
|
|
71
|
-
function Header(props: HeaderProps) {
|
|
72
|
-
const { token } = theme.useToken();
|
|
73
|
-
const {
|
|
74
|
-
logo,
|
|
75
|
-
title,
|
|
76
|
-
leftEndWidth = 260,
|
|
77
|
-
leftEnd,
|
|
78
|
-
rightEnd,
|
|
79
|
-
className,
|
|
80
|
-
style,
|
|
81
|
-
...rest
|
|
82
|
-
} = props;
|
|
83
|
-
return (
|
|
84
|
-
<Layout.Header
|
|
85
|
-
className={className}
|
|
86
|
-
style={{
|
|
87
|
-
display: "flex",
|
|
88
|
-
alignItems: "center",
|
|
89
|
-
boxShadow: "rgba(0, 0, 0, 0.15) 0 0 8px",
|
|
90
|
-
zIndex: 1,
|
|
91
|
-
background: token.colorBgContainer,
|
|
92
|
-
padding: 0,
|
|
93
|
-
color: token.colorText,
|
|
94
|
-
...style,
|
|
95
|
-
}}
|
|
96
|
-
>
|
|
97
|
-
{leftEnd !== undefined ? (
|
|
98
|
-
leftEnd
|
|
99
|
-
) : (
|
|
100
|
-
<Flex
|
|
101
|
-
align="center"
|
|
102
|
-
gap={token.marginSM}
|
|
103
|
-
style={{
|
|
104
|
-
minWidth: leftEndWidth,
|
|
105
|
-
height: "100%",
|
|
106
|
-
paddingInlineStart: token.paddingLG + token.paddingXXS,
|
|
107
|
-
paddingInlineEnd: token.paddingSM,
|
|
108
|
-
}}
|
|
109
|
-
>
|
|
110
|
-
<img alt="logo" src={logo} style={{ height: "50%" }} />
|
|
111
|
-
<h1
|
|
112
|
-
style={{
|
|
113
|
-
flexBasis: "100%",
|
|
114
|
-
textAlign: "center",
|
|
115
|
-
color: token.colorText,
|
|
116
|
-
}}
|
|
117
|
-
>
|
|
118
|
-
{title}
|
|
119
|
-
</h1>
|
|
120
|
-
</Flex>
|
|
121
|
-
)}
|
|
122
|
-
<Menu
|
|
123
|
-
mode="horizontal"
|
|
124
|
-
{...rest}
|
|
125
|
-
style={{
|
|
126
|
-
flexBasis: "100%",
|
|
127
|
-
height: "100%",
|
|
128
|
-
borderBlockEnd: "none",
|
|
129
|
-
}}
|
|
130
|
-
/>
|
|
131
|
-
{rightEnd !== undefined ? rightEnd : <UserButton layout="header" />}
|
|
132
|
-
</Layout.Header>
|
|
133
|
-
);
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
export default Header;
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
export interface ImageBackgroundProps
|
|
2
|
-
extends React.HTMLAttributes<HTMLDivElement> {
|
|
3
|
-
/**
|
|
4
|
-
* 图片的 URL。
|
|
5
|
-
*
|
|
6
|
-
* 建议导入图片,然后填入导入得到的地址,而不要硬编码地址。
|
|
7
|
-
*
|
|
8
|
-
* ```jsx
|
|
9
|
-
* import img from "../public/image.png";
|
|
10
|
-
* <ImageBackground url={img}>...</ImageBackground>
|
|
11
|
-
* ```
|
|
12
|
-
*/
|
|
13
|
-
url: string;
|
|
14
|
-
children: React.ReactNode;
|
|
15
|
-
/**
|
|
16
|
-
* 容器的宽度。
|
|
17
|
-
* @default "100%"
|
|
18
|
-
*/
|
|
19
|
-
width?: React.CSSProperties["width"];
|
|
20
|
-
/**
|
|
21
|
-
* 容器的高度。
|
|
22
|
-
* @default "100%"
|
|
23
|
-
*/
|
|
24
|
-
height?: React.CSSProperties["height"];
|
|
25
|
-
style?: React.CSSProperties;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* 以图片作为背景的块级容器。除了文档列出的属性以外,也兼容所有 [HTML Div 元素][1] 的属性。
|
|
30
|
-
*
|
|
31
|
-
* [1]: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/div
|
|
32
|
-
*/
|
|
33
|
-
function ImageBackground(props: ImageBackgroundProps) {
|
|
34
|
-
const {
|
|
35
|
-
url,
|
|
36
|
-
children,
|
|
37
|
-
width = "100%",
|
|
38
|
-
height = "100%",
|
|
39
|
-
style,
|
|
40
|
-
...rest
|
|
41
|
-
} = props;
|
|
42
|
-
return (
|
|
43
|
-
<div
|
|
44
|
-
{...rest}
|
|
45
|
-
style={{
|
|
46
|
-
backgroundSize: "100% 100%",
|
|
47
|
-
width: width,
|
|
48
|
-
height: height,
|
|
49
|
-
backgroundImage: `url('${url}')`,
|
|
50
|
-
...style,
|
|
51
|
-
}}
|
|
52
|
-
>
|
|
53
|
-
{children}
|
|
54
|
-
</div>
|
|
55
|
-
);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export default ImageBackground;
|