feat: improve typings for mouse events

This commit is contained in:
Justineo
2023-01-01 23:51:43 +08:00
parent 0a4601bc1a
commit 58e7b13652
3 changed files with 29 additions and 6 deletions

View File

@ -1,3 +1,7 @@
## 6.4.1
* Improve typings for mouse event params.
## 6.4.0
* Delay the disposal of the ECharts instance to the moment the element is disconnected from the DOM if possible (#433).

View File

@ -1,6 +1,6 @@
{
"name": "vue-echarts",
"version": "6.4.0",
"version": "6.4.1",
"description": "Vue.js component for Apache ECharts.",
"author": "GU Yiling <justice360@gmail.com>",
"scripts": {

View File

@ -20,7 +20,7 @@ export type EventTarget = EChartsType | ZRenderType;
type SetOptionType = EChartsType["setOption"];
export type Option = Parameters<SetOptionType>[0];
type EChartsEventName =
type EChartsMouseEventName =
| "click"
| "dblclick"
| "mousedown"
@ -29,7 +29,8 @@ type EChartsEventName =
| "mouseover"
| "mouseout"
| "globalout"
| "contextmenu"
| "contextmenu";
type EChartsOtherEventName =
| "highlight"
| "downplay"
| "selectchanged"
@ -77,7 +78,25 @@ type ZRenderEventName =
| "dragover"
| "drop"
| "globalout";
type EventName = EChartsEventName | `zr:${ZRenderEventName}`;
export type Emits = {
[key in EventName]: null;
type OtherEventName = EChartsOtherEventName | `zr:${ZRenderEventName}`;
// See https://echarts.apache.org/en/api.html#events.Mouse%20events
interface MouseEventParams {
componentType: string;
seriesType: string;
seriesIndex: number;
seriesName: string;
name: string;
dataIndex: number;
color: string;
}
type MouseEmits = {
[k in EChartsMouseEventName]: (params: MouseEventParams) => boolean;
};
type OtherEmits = {
[key in OtherEventName]: null;
};
export type Emits = MouseEmits & OtherEmits;