Skip to content

Commit

Permalink
types: use more precise typings for event handlers, update peer deps …
Browse files Browse the repository at this point in the history
…for echarts
  • Loading branch information
Justineo committed Jan 2, 2023
1 parent ed4bd39 commit 0edfb39
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 60 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 6.5.0

* Use more precise typings for all event params.
* Updated peer deps for `echarts` to `^5.4.1`.

## 6.4.1

* Improve typings for mouse event params.
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ Drop `<script>` inside your HTML file and access the component via `window.VueEC
```html
<script src="https://cdn.jsdelivr.net/npm/[email protected]"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]"></script>
<script src="https://cdn.jsdelivr.net/npm/vue-echarts@6.4.1"></script>
<script src="https://cdn.jsdelivr.net/npm/vue-echarts@6.5.0"></script>
```
<!-- vue3Scripts:end -->

Expand All @@ -247,7 +247,7 @@ app.component('v-chart', VueECharts)
```html
<script src="https://cdn.jsdelivr.net/npm/[email protected]"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]"></script>
<script src="https://cdn.jsdelivr.net/npm/vue-echarts@6.4.1"></script>
<script src="https://cdn.jsdelivr.net/npm/vue-echarts@6.5.0"></script>
```
<!-- vue2Scripts:end -->

Expand Down
4 changes: 2 additions & 2 deletions README.zh-Hans.md
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ import "echarts";
```html
<script src="https://cdn.jsdelivr.net/npm/[email protected]"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]"></script>
<script src="https://cdn.jsdelivr.net/npm/vue-echarts@6.4.1"></script>
<script src="https://cdn.jsdelivr.net/npm/vue-echarts@6.5.0"></script>
```
<!-- vue3Scripts:end -->

Expand All @@ -245,7 +245,7 @@ app.component('v-chart', VueECharts)
```html
<script src="https://cdn.jsdelivr.net/npm/[email protected]"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]"></script>
<script src="https://cdn.jsdelivr.net/npm/vue-echarts@6.4.1"></script>
<script src="https://cdn.jsdelivr.net/npm/vue-echarts@6.5.0"></script>
```
<!-- vue2Scripts:end -->

Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vue-echarts",
"version": "6.4.1",
"version": "6.5.0",
"description": "Vue.js component for Apache ECharts.",
"author": "GU Yiling <[email protected]>",
"scripts": {
Expand Down Expand Up @@ -40,7 +40,7 @@
"@vue/eslint-config-typescript": "^10.0.0",
"comment-mark": "^1.0.0",
"core-js": "^3.23.0",
"echarts": "^5.3.2",
"echarts": "^5.4.1",
"echarts-liquidfill": "^3.1.0",
"eslint": "^7.20.0",
"eslint-plugin-prettier": "^3.3.1",
Expand All @@ -67,7 +67,7 @@
},
"peerDependencies": {
"@vue/composition-api": "^1.0.5",
"echarts": "^5.1.2",
"echarts": "^5.4.1",
"vue": "^2.6.12 || ^3.1.1"
},
"jsdelivr": "dist/index.umd.min.js",
Expand Down
20 changes: 10 additions & 10 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

78 changes: 35 additions & 43 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { init, type SetOptionOpts } from "echarts/core";
import {
init,
type SetOptionOpts,
type ECElementEvent,
type ElementEvent
} from "echarts/core";
import type { Ref } from "vue";

export type Injection<T> = T | null | Ref<T | null> | { value: T | null };
Expand All @@ -20,17 +25,28 @@ export type EventTarget = EChartsType | ZRenderType;
type SetOptionType = EChartsType["setOption"];
export type Option = Parameters<SetOptionType>[0];

type EChartsMouseEventName =
type ElementEventName =
| "click"
| "dblclick"
| "mousewheel"
| "mouseout"
| "mouseover"
| "mouseup"
| "mousedown"
| "mousemove"
| "mouseup"
| "mouseover"
| "mouseout"
| "globalout"
| "contextmenu";
type EChartsOtherEventName =
| "contextmenu"
| "drag"
| "dragstart"
| "dragend"
| "dragenter"
| "dragleave"
| "dragover"
| "drop"
| "globalout";

type ZRenderEventName = `zr:${ElementEventName}`;

type OtherEventName =
| "highlight"
| "downplay"
| "selectchanged"
Expand All @@ -57,46 +73,22 @@ type EChartsOtherEventName =
| "brush"
| "brushEnd"
| "brushselected"
| "globalcursortaken"
| "rendered"
| "finished";
type ZRenderEventName =
| "click"
| "dblclick"
| "mousewheel"
| "mouseout"
| "mouseover"
| "mouseup"
| "mousedown"
| "mousemove"
| "contextmenu"
| "drag"
| "dragstart"
| "dragend"
| "dragenter"
| "dragleave"
| "dragover"
| "drop"
| "globalout";
type OtherEventName = EChartsOtherEventName | `zr:${ZRenderEventName}`;
| "globalcursortaken";

// 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 ElementEmits = {
[key in ElementEventName]: (params: ECElementEvent) => boolean;
};

type MouseEmits = {
[k in EChartsMouseEventName]: (params: MouseEventParams) => boolean;
type ZRenderEmits = {
[key in ZRenderEventName]: (params: ElementEvent) => boolean;
};

type OtherEmits = {
[key in OtherEventName]: null;
};

export type Emits = MouseEmits & OtherEmits;
export type Emits = ElementEmits &
OtherEmits & {
rendered: (params: { elapsedTime: number }) => boolean;
finished: () => boolean;
} & ZRenderEmits;

1 comment on commit 0edfb39

@vercel
Copy link

@vercel vercel bot commented on 0edfb39 Jan 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.