From 0bb1839392adb173a064f7625d1b793bb2595509 Mon Sep 17 00:00:00 2001 From: Justineo Date: Sun, 18 Dec 2022 19:38:04 +0800 Subject: [PATCH] feat: add basic types for events --- CHANGELOG.md | 4 +++ README.md | 12 ++++----- README.zh-Hans.md | 12 ++++----- package.json | 2 +- src/ECharts.ts | 4 ++- src/index.vue2.d.ts | 13 ++++++++-- src/types.ts | 62 +++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 93 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 136da62..11d0b9c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 6.3.2 + +* Added basic types for events (only event names). + ## 6.3.1 * Revert the style change to prevent tooltips from being clipped. diff --git a/README.md b/README.md index 0c86bb3..513d422 100644 --- a/README.md +++ b/README.md @@ -308,9 +308,9 @@ Drop ` - - + + + ``` @@ -328,9 +328,9 @@ app.component('v-chart', VueECharts) ```html - - - + + + ``` diff --git a/README.zh-Hans.md b/README.zh-Hans.md index 92098d1..6423bab 100644 --- a/README.zh-Hans.md +++ b/README.zh-Hans.md @@ -307,9 +307,9 @@ export default { ```html - - - + + + ``` @@ -327,9 +327,9 @@ app.component('v-chart', VueECharts) ```html - - - + + + ``` diff --git a/package.json b/package.json index f806f74..a6ea558 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "vue-echarts", - "version": "6.3.1", + "version": "6.3.2", "description": "Vue.js component for Apache ECharts.", "author": "GU Yiling ", "scripts": { diff --git a/src/ECharts.ts b/src/ECharts.ts index d1c62e4..1d51be3 100644 --- a/src/ECharts.ts +++ b/src/ECharts.ts @@ -27,7 +27,8 @@ import type { InitOptions, InitOptionsInjection, UpdateOptions, - UpdateOptionsInjection + UpdateOptionsInjection, + Emits } from "./types"; import { usePublicAPI, @@ -66,6 +67,7 @@ export default defineComponent({ ...autoresizeProps, ...loadingProps }, + emits: [] as unknown as Emits, inheritAttrs: false, setup(props, { attrs }) { const root = shallowRef(); diff --git a/src/index.vue2.d.ts b/src/index.vue2.d.ts index d6da152..d2f671c 100644 --- a/src/index.vue2.d.ts +++ b/src/index.vue2.d.ts @@ -1,6 +1,12 @@ /* eslint-disable @typescript-eslint/ban-types */ import type { Ref, DefineComponent } from "vue-demi"; -import type { Option, InitOptions, UpdateOptions, EChartsType } from "./types"; +import type { + Option, + InitOptions, + UpdateOptions, + EChartsType, + Emits +} from "./types"; declare const LOADING_OPTIONS_KEY = "ecLoadingOptions"; declare const THEME_KEY = "ecTheme"; @@ -47,7 +53,10 @@ declare const Chart: DefineComponent< }, {}, {}, - ChartMethods + ChartMethods, + {}, + {}, + Emits >; export default Chart; diff --git a/src/types.ts b/src/types.ts index a242d16..8cae704 100644 --- a/src/types.ts +++ b/src/types.ts @@ -19,3 +19,65 @@ type ZRenderType = ReturnType; export type EventTarget = EChartsType | ZRenderType; type SetOptionType = EChartsType["setOption"]; export type Option = Parameters[0]; + +type EChartsEventName = + | "click" + | "dblclick" + | "mousedown" + | "mousemove" + | "mouseup" + | "mouseover" + | "mouseout" + | "globalout" + | "contextmenu" + | "highlight" + | "downplay" + | "selectchanged" + | "legendselectchanged" + | "legendselected" + | "legendunselected" + | "legendselectall" + | "legendinverseselect" + | "legendscroll" + | "datazoom" + | "datarangeselected" + | "graphroam" + | "georoam" + | "treeroam" + | "timelinechanged" + | "timelineplaychanged" + | "restore" + | "dataviewchanged" + | "magictypechanged" + | "geoselectchanged" + | "geoselected" + | "geounselected" + | "axisareaselected" + | "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 EventName = EChartsEventName | `zr:${ZRenderEventName}`; +export type Emits = { + [key in EventName]: null; +};