Skip to content

Generate d.ts #835

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jun 1, 2025
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"scripts": {
"dev": "vite",
"build": "pnpm run docs && rimraf dist && rollup -c",
"typecheck": "vue-tsc",
"typecheck": "tsc",
"lint": "eslint . --fix",
"format": "prettier . --write",
"publint": "publint",
Expand Down Expand Up @@ -41,7 +41,7 @@
},
"devDependencies": {
"@highlightjs/vue-plugin": "^2.1.0",
"@rollup/plugin-replace": "^5.0.7",
"@rollup/plugin-replace": "^6.0.2",
"@types/node": "^22.15.21",
"@typescript-eslint/utils": "^8.32.1",
"@vercel/analytics": "^1.3.1",
Expand All @@ -64,10 +64,10 @@
"prettier": "^3.5.3",
"publint": "^0.3.12",
"rimraf": "^6.0.1",
"rollup": "^4.19.0",
"rollup-plugin-dts": "^6.1.0",
"rollup-plugin-esbuild": "^6.1.1",
"rollup-plugin-import-css": "^3.5.1",
"rollup": "^4.41.1",
"rollup-plugin-dts": "^6.2.1",
"rollup-plugin-esbuild": "^6.2.1",
"rollup-plugin-import-css": "^3.5.8",
"typescript": "^5.8.3",
"vite": "^6.3.5",
"vue": "^3.5.13",
Expand Down
658 changes: 164 additions & 494 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

21 changes: 17 additions & 4 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import replace from "@rollup/plugin-replace";
import esbuild from "rollup-plugin-esbuild";
import { dts } from "rollup-plugin-dts";
import css from "rollup-plugin-import-css";
import { defineConfig } from "rollup";

/**
* Modifies the Rollup options for a build to support strict CSP
Expand Down Expand Up @@ -73,12 +74,24 @@ const builds = [
},
];

export default [
export default defineConfig([
...builds.map((options) => configBuild(options, false)),
...builds.map((options) => configBuild(options, true)),
{
input: "src/index.d.ts",
plugins: [dts()],
input: "src/index.ts",
plugins: [
dts({
// https://github.com/unjs/unbuild/pull/57/files
compilerOptions: {
preserveSymlinks: false,
},
}),
{
load(id) {
if (id.endsWith(".css")) return "";
},
},
],
output: [
{
file: "dist/index.d.ts",
Expand All @@ -90,4 +103,4 @@ export default [
},
],
},
];
]);
40 changes: 23 additions & 17 deletions src/ECharts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@ import {
autoresizeProps,
useLoading,
loadingProps,
type PublicMethods,
} from "./composables";
import { isOn, omitOn, toValue } from "./utils";
import { register, TAG_NAME } from "./wc";

import type { PropType, InjectionKey } from "vue";
import type {
EChartsType,
SetOptionType,
Option,
Theme,
ThemeInjection,
Expand Down Expand Up @@ -65,7 +67,7 @@ export default defineComponent({
},
emits: {} as unknown as Emits,
inheritAttrs: false,
setup(props, { attrs }) {
setup(props, { attrs, expose }) {
const root = shallowRef<EChartsElement>();
const chart = shallowRef<EChartsType>();
const manualOption = shallowRef<Option>();
Expand Down Expand Up @@ -189,8 +191,14 @@ export default defineComponent({
commit();
}
}
const setOption: SetOptionType = (
option,
notMerge,
lazyUpdate?: boolean,
) => {
const updateOptions =
typeof notMerge === "boolean" ? { notMerge, lazyUpdate } : notMerge;

function setOption(option: Option, updateOptions?: UpdateOptions) {
if (props.manualUpdate) {
manualOption.value = option;
}
Expand All @@ -200,7 +208,7 @@ export default defineComponent({
} else {
chart.value.setOption(option, updateOptions || {});
}
}
};

function cleanup() {
if (chart.value) {
Expand Down Expand Up @@ -284,21 +292,19 @@ export default defineComponent({
}
});

return {
chart,
root,
const exposed = {
setOption,
nonEventAttrs,
nativeListeners,
...publicApi,
root,
chart,
};
},
render() {
return h(TAG_NAME, {
...this.nonEventAttrs,
...this.nativeListeners,
ref: "root",
class: ["echarts", ...(this.nonEventAttrs.class || [])],
});
expose({ ...exposed, ...publicApi });

return (() =>
h(TAG_NAME, {
...nonEventAttrs.value,
...nativeListeners,
ref: root,
class: ["echarts", ...(nonEventAttrs.value.class || [])],
})) as unknown as typeof exposed & PublicMethods;
},
});
2 changes: 1 addition & 1 deletion src/composables/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const METHOD_NAMES = [

type MethodName = (typeof METHOD_NAMES)[number];

type PublicMethods = Pick<EChartsType, MethodName>;
export type PublicMethods = Pick<EChartsType, MethodName>;

export function usePublicAPI(
chart: Ref<EChartsType | undefined>,
Expand Down
12 changes: 7 additions & 5 deletions src/composables/loading.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@ import { inject, computed, watchEffect } from "vue";
import { toValue } from "../utils";

import type { Ref, InjectionKey, PropType } from "vue";
import type { EChartsType, LoadingOptions } from "../types";
import type {
EChartsType,
LoadingOptions,
LoadingOptionsInjection,
} from "../types";

export const LOADING_OPTIONS_KEY =
"ecLoadingOptions" as unknown as InjectionKey<
LoadingOptions | Ref<LoadingOptions>
>;
"ecLoadingOptions" as unknown as InjectionKey<LoadingOptionsInjection>;

export function useLoading(
chart: Ref<EChartsType | undefined>,
loading: Ref<boolean>,
loading: Ref<boolean | undefined>,
loadingOptions: Ref<LoadingOptions | undefined>,
): void {
const defaultLoadingOptions = inject(LOADING_OPTIONS_KEY, {});
Expand Down
75 changes: 0 additions & 75 deletions src/index.d.ts

This file was deleted.

4 changes: 1 addition & 3 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,13 @@ export type InitParameters = Parameters<InitType>;
export type Theme = NonNullable<InitParameters[1]>;
export type ThemeInjection = Injection<Theme>;
export type InitOptions = NonNullable<InitParameters[2]>;

export type InitOptionsInjection = Injection<InitOptions>;

export type UpdateOptions = SetOptionOpts;
export type UpdateOptionsInjection = Injection<UpdateOptions>;

export type EChartsType = ReturnType<InitType>;

type SetOptionType = EChartsType["setOption"];
export type SetOptionType = EChartsType["setOption"];
export type Option = Parameters<SetOptionType>[0];

export type AutoResize =
Expand Down
3 changes: 1 addition & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
{
"allowJs": true,
"compilerOptions": {
"target": "ESNext",
"module": "ESNext",
"strict": true,
"jsx": "preserve",
"importHelpers": true,
"moduleResolution": "node",
"moduleResolution": "bundler",
"removeComments": true,
"skipLibCheck": true,
"esModuleInterop": true,
Expand Down