react-use-echarts 0.0.9 → 0.0.11

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/README.md CHANGED
@@ -16,7 +16,8 @@ A powerful React hooks library for Apache ECharts, making it easy to use ECharts
16
16
  - 📦 **Lightweight** - Zero dependencies except for React and ECharts
17
17
  - 🛠 **Flexible** - Full access to ECharts instance and options
18
18
  - ⚡ **Auto-updating** - Automatically updates chart when data or options change
19
- - 📱 **Responsive** - Handles container resizing automatically
19
+ - 📱 **Responsive** - Handles container resizing automatically with ResizeObserver
20
+ - 🎯 **Event handling** - Easy to use event system with flexible configuration
20
21
 
21
22
  ## 📦 Installation
22
23
 
@@ -34,10 +35,15 @@ pnpm add react-use-echarts echarts
34
35
  ## 🔨 Usage
35
36
 
36
37
  ```tsx
37
- import { useEcharts, UseEchartsOptions } from 'react-use-echarts';
38
+ import React from 'react';
39
+ import { useEcharts } from 'react-use-echarts';
40
+ import type { EChartsOption } from 'echarts';
38
41
 
39
42
  function MyChart() {
40
- const options: UseEchartsOptions['option'] = {
43
+ const options: EChartsOption = {
44
+ title: {
45
+ text: 'Basic Line Chart Example'
46
+ },
41
47
  xAxis: {
42
48
  type: 'category',
43
49
  data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
@@ -47,7 +53,8 @@ function MyChart() {
47
53
  },
48
54
  series: [{
49
55
  data: [820, 932, 901, 934, 1290, 1330, 1320],
50
- type: 'line'
56
+ type: 'line',
57
+ smooth: true
51
58
  }]
52
59
  };
53
60
 
@@ -55,7 +62,7 @@ function MyChart() {
55
62
  option: options
56
63
  });
57
64
 
58
- return <div ref={chartRef} style={{ width: '100%', height: '300px' }} />;
65
+ return <div ref={chartRef} style={{ width: '100%', height: '400px' }} />;
59
66
  }
60
67
  ```
61
68
 
@@ -66,14 +73,17 @@ function MyChart() {
66
73
  The main hook for using ECharts in React components.
67
74
 
68
75
  ```tsx
76
+ import type { EChartsOption } from 'echarts';
77
+ import type { UseEchartsOptions } from 'react-use-echarts';
78
+
69
79
  const { chartRef, setOption, getInstance } = useEcharts({
70
- option: UseEchartsOptions['option']; // ECharts options configuration (required)
71
- theme?: string | object; // ECharts theme name or configuration
72
- notMerge?: boolean; // Whether to not merge with previous options
73
- lazyUpdate?: boolean; // Whether to update chart lazily
74
- showLoading?: boolean; // Whether to display loading animation
75
- loadingOption?: object; // Loading animation configuration
76
- onEvents?: { // Event handlers
80
+ option: EChartsOption; // ECharts options configuration (required)
81
+ theme?: string | object; // ECharts theme name or configuration
82
+ notMerge?: boolean; // Whether to not merge with previous options
83
+ lazyUpdate?: boolean; // Whether to update chart lazily
84
+ showLoading?: boolean; // Whether to display loading animation
85
+ loadingOption?: object; // Loading animation configuration
86
+ onEvents?: { // Event handlers
77
87
  [eventName: string]: {
78
88
  handler: (params: any) => void;
79
89
  query?: string | object;
@@ -99,4 +109,4 @@ Detailed changes for each release are documented in the [release notes](https://
99
109
 
100
110
  ## 📄 License
101
111
 
102
- [MIT](./LICENSE.txt) © [chin](https://github.com/chensid)
112
+ [MIT](./LICENSE.txt) © [Ethan](https://github.com/chensid)
package/dist/index.es.js CHANGED
@@ -1,45 +1,40 @@
1
- import { useRef as z, useCallback as f, useEffect as C } from "react";
2
- import * as R from "echarts";
3
- const w = ({
1
+ import { useRef as v, useCallback as a, useEffect as u } from "react";
2
+ import * as k from "echarts";
3
+ const M = ({
4
4
  /** Chart configuration */
5
- option: a,
5
+ option: f,
6
6
  /** Theme name */
7
7
  theme: i,
8
8
  /** Skip merging with previous options */
9
- notMerge: d = !1,
9
+ notMerge: l = !1,
10
10
  /** Enable lazy update mode */
11
- lazyUpdate: l = !1,
11
+ lazyUpdate: b = !1,
12
12
  /** Display loading animation */
13
13
  showLoading: p = !1,
14
14
  /** Loading animation config */
15
15
  loadingOption: O,
16
16
  /** Event handlers map */
17
- onEvents: c
17
+ onEvents: s
18
18
  }) => {
19
- const s = z(null), n = z(void 0), k = () => n.current, b = f(() => ({
20
- option: a,
21
- theme: i,
22
- notMerge: d,
23
- lazyUpdate: l,
24
- showLoading: p,
25
- loadingOption: O,
26
- onEvents: c
27
- }), [
28
- a,
29
- i,
30
- d,
31
- l,
32
- p,
33
- O,
34
- c
35
- ]), o = f(() => {
36
- if (s.current && !n.current) {
37
- const e = R.init(s.current, i);
19
+ const c = v(null), n = v(void 0), C = () => n.current, d = a(
20
+ () => ({
21
+ option: f,
22
+ theme: i,
23
+ notMerge: l,
24
+ lazyUpdate: b,
25
+ showLoading: p,
26
+ loadingOption: O,
27
+ onEvents: s
28
+ }),
29
+ [f, i, l, b, p, O, s]
30
+ ), o = a(() => {
31
+ if (c.current && !n.current) {
32
+ const e = k.init(c.current, i);
38
33
  n.current = e;
39
- const r = b();
34
+ const r = d();
40
35
  return r.onEvents && Object.entries(r.onEvents).forEach(
41
- ([t, { handler: u, query: g, context: h }]) => {
42
- g ? e.on(t, g, u, h) : e.on(t, u, h);
36
+ ([t, { handler: h, query: g, context: z }]) => {
37
+ g ? e.on(t, g, h, z) : e.on(t, h, z);
43
38
  }
44
39
  ), r.showLoading ? e.showLoading(r.loadingOption) : e.hideLoading(), e.setOption(r.option, {
45
40
  notMerge: r.notMerge,
@@ -47,7 +42,7 @@ const w = ({
47
42
  }), e;
48
43
  }
49
44
  return n.current;
50
- }, [b, i]), M = f(
45
+ }, [d, i]), R = a(
51
46
  (e, r) => {
52
47
  queueMicrotask(() => {
53
48
  const t = n.current || o();
@@ -56,25 +51,33 @@ const w = ({
56
51
  },
57
52
  [o]
58
53
  );
59
- return C(() => {
54
+ return u(() => {
60
55
  const e = n.current;
61
- if (!e) return;
62
- const r = new ResizeObserver(() => {
63
- e.resize();
64
- });
65
- return r.observe(s.current), () => {
66
- r.disconnect(), c && e && Object.entries(c).forEach(([t, { handler: u }]) => {
67
- e.off(t, u);
68
- }), e.dispose(), n.current = void 0;
56
+ if (!e || !c.current) return;
57
+ let r;
58
+ try {
59
+ r = new ResizeObserver(() => {
60
+ e.resize();
61
+ }), r.observe(c.current);
62
+ } catch (t) {
63
+ console.warn("ResizeObserver not available:", t);
64
+ }
65
+ return () => {
66
+ r?.disconnect();
69
67
  };
70
- }, [n, c]), C(() => {
71
- s.current && queueMicrotask(o);
72
- }, [s, o]), {
73
- chartRef: s,
74
- setOption: M,
75
- getInstance: k
68
+ }, []), u(() => {
69
+ c.current && queueMicrotask(o);
70
+ }, [c, o]), u(() => () => {
71
+ const e = n.current;
72
+ e && (s && Object.entries(s).forEach(([r, { handler: t }]) => {
73
+ e.off(r, t);
74
+ }), e.dispose(), n.current = void 0);
75
+ }, [s]), {
76
+ chartRef: c,
77
+ setOption: R,
78
+ getInstance: C
76
79
  };
77
80
  };
78
81
  export {
79
- w as useEcharts
82
+ M as useEcharts
80
83
  };
package/dist/index.umd.js CHANGED
@@ -1 +1 @@
1
- (function(r,n){typeof exports=="object"&&typeof module<"u"?n(exports,require("react"),require("echarts")):typeof define=="function"&&define.amd?define(["exports","react","echarts"],n):(r=typeof globalThis<"u"?globalThis:r||self,n(r["react-use-echarts"]={},r.React,r.echarts))})(this,function(r,n,y){"use strict";function k(s){const c=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(s){for(const u in s)if(u!=="default"){const a=Object.getOwnPropertyDescriptor(s,u);Object.defineProperty(c,u,a.get?a:{enumerable:!0,get:()=>s[u]})}}return c.default=s,Object.freeze(c)}const C=k(y),z=({option:s,theme:c,notMerge:u=!1,lazyUpdate:a=!1,showLoading:b=!1,loadingOption:h,onEvents:d})=>{const f=n.useRef(null),i=n.useRef(void 0),M=()=>i.current,O=n.useCallback(()=>({option:s,theme:c,notMerge:u,lazyUpdate:a,showLoading:b,loadingOption:h,onEvents:d}),[s,c,u,a,b,h,d]),l=n.useCallback(()=>{if(f.current&&!i.current){const e=C.init(f.current,c);i.current=e;const t=O();return t.onEvents&&Object.entries(t.onEvents).forEach(([o,{handler:p,query:g,context:j}])=>{g?e.on(o,g,p,j):e.on(o,p,j)}),t.showLoading?e.showLoading(t.loadingOption):e.hideLoading(),e.setOption(t.option,{notMerge:t.notMerge,lazyUpdate:t.lazyUpdate}),e}return i.current},[O,c]),R=n.useCallback((e,t)=>{queueMicrotask(()=>{const o=i.current||l();o&&o.setOption(e,t)})},[l]);return n.useEffect(()=>{const e=i.current;if(!e)return;const t=new ResizeObserver(()=>{e.resize()});return t.observe(f.current),()=>{t.disconnect(),d&&e&&Object.entries(d).forEach(([o,{handler:p}])=>{e.off(o,p)}),e.dispose(),i.current=void 0}},[i,d]),n.useEffect(()=>{f.current&&queueMicrotask(l)},[f,l]),{chartRef:f,setOption:R,getInstance:M}};r.useEcharts=z,Object.defineProperty(r,Symbol.toStringTag,{value:"Module"})});
1
+ (function(s,n){typeof exports=="object"&&typeof module<"u"?n(exports,require("react"),require("echarts")):typeof define=="function"&&define.amd?define(["exports","react","echarts"],n):(s=typeof globalThis<"u"?globalThis:s||self,n(s["react-use-echarts"]={},s.React,s.echarts))})(this,function(s,n,y){"use strict";function k(c){const i=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(c){for(const u in c)if(u!=="default"){const a=Object.getOwnPropertyDescriptor(c,u);Object.defineProperty(i,u,a.get?a:{enumerable:!0,get:()=>c[u]})}}return i.default=c,Object.freeze(i)}const v=k(y),z=({option:c,theme:i,notMerge:u=!1,lazyUpdate:a=!1,showLoading:p=!1,loadingOption:b,onEvents:l})=>{const f=n.useRef(null),o=n.useRef(void 0),C=()=>o.current,h=n.useCallback(()=>({option:c,theme:i,notMerge:u,lazyUpdate:a,showLoading:p,loadingOption:b,onEvents:l}),[c,i,u,a,p,b,l]),d=n.useCallback(()=>{if(f.current&&!o.current){const e=v.init(f.current,i);o.current=e;const t=h();return t.onEvents&&Object.entries(t.onEvents).forEach(([r,{handler:O,query:g,context:j}])=>{g?e.on(r,g,O,j):e.on(r,O,j)}),t.showLoading?e.showLoading(t.loadingOption):e.hideLoading(),e.setOption(t.option,{notMerge:t.notMerge,lazyUpdate:t.lazyUpdate}),e}return o.current},[h,i]),R=n.useCallback((e,t)=>{queueMicrotask(()=>{const r=o.current||d();r&&r.setOption(e,t)})},[d]);return n.useEffect(()=>{const e=o.current;if(!e||!f.current)return;let t;try{t=new ResizeObserver(()=>{e.resize()}),t.observe(f.current)}catch(r){console.warn("ResizeObserver not available:",r)}return()=>{t?.disconnect()}},[]),n.useEffect(()=>{f.current&&queueMicrotask(d)},[f,d]),n.useEffect(()=>()=>{const e=o.current;e&&(l&&Object.entries(l).forEach(([t,{handler:r}])=>{e.off(t,r)}),e.dispose(),o.current=void 0)},[l]),{chartRef:f,setOption:R,getInstance:C}};s.useEcharts=z,Object.defineProperty(s,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "react-use-echarts",
3
3
  "private": false,
4
- "version": "0.0.9",
4
+ "version": "0.0.11",
5
5
  "description": "A powerful React hooks library for Apache ECharts",
6
6
  "keywords": [
7
7
  "react",
@@ -12,7 +12,7 @@
12
12
  "typescript"
13
13
  ],
14
14
  "type": "module",
15
- "author": "chin",
15
+ "author": "Ethan",
16
16
  "license": "MIT",
17
17
  "publishConfig": {
18
18
  "access": "public",
@@ -41,29 +41,29 @@
41
41
  "dist"
42
42
  ],
43
43
  "devDependencies": {
44
- "@eslint/js": "^9.22.0",
45
- "@testing-library/react": "^16.2.0",
46
- "@types/node": "^22.13.10",
47
- "@types/react": "^19.0.10",
48
- "@types/react-dom": "^19.0.4",
49
- "@vitejs/plugin-react-swc": "^3.8.0",
50
- "@vitest/coverage-v8": "3.0.8",
51
- "echarts": "^5.6.0",
52
- "eslint": "^9.22.0",
53
- "eslint-plugin-react-hooks": "^5.2.0",
54
- "eslint-plugin-react-refresh": "^0.4.19",
55
- "globals": "^16.0.0",
56
- "jsdom": "^26.0.0",
57
- "react": "^19.0.0",
58
- "react-dom": "^19.0.0",
59
- "typescript": "~5.8.2",
60
- "typescript-eslint": "^8.26.1",
61
- "vite": "^6.2.1",
62
- "vite-plugin-dts": "^4.5.3",
63
- "vitest": "^3.0.8"
44
+ "@eslint/js": "^9.38.0",
45
+ "@testing-library/react": "^16.3.0",
46
+ "@types/node": "^24.9.1",
47
+ "@types/react": "^19.2.2",
48
+ "@types/react-dom": "^19.2.2",
49
+ "@vitejs/plugin-react-swc": "^4.1.0",
50
+ "@vitest/coverage-v8": "3.2.4",
51
+ "echarts": "^6.0.0",
52
+ "eslint": "^9.38.0",
53
+ "eslint-plugin-react-hooks": "^7.0.0",
54
+ "eslint-plugin-react-refresh": "^0.4.24",
55
+ "globals": "^16.4.0",
56
+ "jsdom": "^27.0.1",
57
+ "react": "^19.2.0",
58
+ "react-dom": "^19.2.0",
59
+ "typescript": "~5.9.3",
60
+ "typescript-eslint": "^8.46.2",
61
+ "vite": "^7.1.11",
62
+ "vite-plugin-dts": "^4.5.4",
63
+ "vitest": "^3.2.4"
64
64
  },
65
65
  "peerDependencies": {
66
- "echarts": "^5.5.1",
66
+ "echarts": "^5.6.0 || ^6.0.0",
67
67
  "react": "^18.3.1 || ^19.0.0",
68
68
  "react-dom": "^18.3.1 || ^19.0.0"
69
69
  },