react-use-echarts 0.0.6 → 0.0.8

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
@@ -55,7 +55,7 @@ function MyChart() {
55
55
  option: options
56
56
  });
57
57
 
58
- return <div ref={chartRef} style={{ width: '100%', height: '400px' }} />;
58
+ return <div ref={chartRef} style={{ width: '100%', height: '300px' }} />;
59
59
  }
60
60
  ```
61
61
 
package/dist/index.d.ts CHANGED
@@ -1,11 +1,3 @@
1
- /**
2
- * react-use-echarts
3
- * A React hook library for Apache ECharts with TypeScript support
4
- * 基于 TypeScript 的 Apache ECharts React Hook 库
5
- *
6
- * @packageDocumentation
7
- */
8
-
9
1
  import { ECharts } from 'echarts';
10
2
  import { EChartsOption } from 'echarts';
11
3
  import { SetOptionOpts } from 'echarts';
@@ -122,7 +114,7 @@ export declare interface UseEchartsReturn {
122
114
  * Reference to the chart container element
123
115
  * 图表容器元素的引用
124
116
  */
125
- chartRef: React.RefObject<HTMLDivElement>;
117
+ chartRef: React.RefObject<HTMLDivElement | null>;
126
118
  /**
127
119
  * Function to update chart options
128
120
  * 更新图表配置的函数
package/dist/index.es.js CHANGED
@@ -1,72 +1,80 @@
1
- import { useRef as p, useCallback as z, useEffect as w } from "react";
2
- import * as C from "echarts";
3
- const R = ({
1
+ import { useRef as z, useCallback as f, useEffect as C } from "react";
2
+ import * as R from "echarts";
3
+ const w = ({
4
4
  /** Chart configuration */
5
- option: f,
5
+ option: a,
6
6
  /** Theme name */
7
- theme: a,
7
+ theme: i,
8
8
  /** Skip merging with previous options */
9
- notMerge: m = !1,
9
+ notMerge: d = !1,
10
10
  /** Enable lazy update mode */
11
11
  lazyUpdate: l = !1,
12
12
  /** Display loading animation */
13
- showLoading: h = !1,
13
+ showLoading: p = !1,
14
14
  /** Loading animation config */
15
- loadingOption: d,
15
+ loadingOption: O,
16
16
  /** Event handlers map */
17
- onEvents: s
17
+ onEvents: c
18
18
  }) => {
19
- const c = p(null), t = p(), O = () => t.current, u = z(() => {
20
- if (c.current && !t.current) {
21
- const e = C.init(c.current, a);
22
- return t.current = e, s && Object.entries(s).forEach(
23
- ([r, { handler: n, query: i, context: o }]) => {
24
- i ? e.on(r, i, n, o) : e.on(r, n, o);
25
- }
26
- ), h ? e.showLoading(d) : e.hideLoading(), e.setOption(f, { notMerge: m, lazyUpdate: l }), e;
27
- }
28
- return t.current;
29
- }, [
30
- f,
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
+ }), [
31
28
  a,
32
- m,
33
- l,
34
- h,
29
+ i,
35
30
  d,
36
- s
37
- ]), b = z(
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);
38
+ n.current = e;
39
+ const r = b();
40
+ 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);
43
+ }
44
+ ), r.showLoading ? e.showLoading(r.loadingOption) : e.hideLoading(), e.setOption(r.option, {
45
+ notMerge: r.notMerge,
46
+ lazyUpdate: r.lazyUpdate
47
+ }), e;
48
+ }
49
+ return n.current;
50
+ }, [b, i]), M = f(
38
51
  (e, r) => {
39
- requestAnimationFrame(() => {
40
- const n = t.current || u();
41
- n && n.setOption(e, r);
52
+ queueMicrotask(() => {
53
+ const t = n.current || o();
54
+ t && t.setOption(e, r);
42
55
  });
43
56
  },
44
- [u]
57
+ [o]
45
58
  );
46
- return w(() => {
47
- const e = t.current;
59
+ return C(() => {
60
+ const e = n.current;
48
61
  if (!e) return;
49
- const r = () => {
50
- const i = setTimeout(() => {
51
- e == null || e.resize();
52
- }, 250);
53
- return () => clearTimeout(i);
54
- }, n = r();
55
- return window.addEventListener("resize", r), () => {
56
- s && Object.entries(s).forEach(([i, { handler: o }]) => {
57
- e.off(i, o);
58
- }), window.removeEventListener("resize", r), e.dispose(), t.current = void 0, n();
59
- };
60
- }, [s]), w(() => {
61
- c.current && requestAnimationFrame(() => {
62
- u();
62
+ const r = new ResizeObserver(() => {
63
+ e.resize();
63
64
  });
64
- }, [c, u]), {
65
- chartRef: c,
66
- setOption: b,
67
- getInstance: O
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;
69
+ };
70
+ }, [n, c]), C(() => {
71
+ s.current && queueMicrotask(o);
72
+ }, [s, o]), {
73
+ chartRef: s,
74
+ setOption: M,
75
+ getInstance: k
68
76
  };
69
77
  };
70
78
  export {
71
- R as useEcharts
79
+ w as useEcharts
72
80
  };
package/dist/index.umd.js CHANGED
@@ -1 +1 @@
1
- (function(r,t){typeof exports=="object"&&typeof module<"u"?t(exports,require("react"),require("echarts")):typeof define=="function"&&define.amd?define(["exports","react","echarts"],t):(r=typeof globalThis<"u"?globalThis:r||self,t(r["react-use-echarts"]={},r.React,r.echarts))})(this,function(r,t,O){"use strict";function j(n){const f=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(n){for(const i in n)if(i!=="default"){const d=Object.getOwnPropertyDescriptor(n,i);Object.defineProperty(f,i,d.get?d:{enumerable:!0,get:()=>n[i]})}}return f.default=n,Object.freeze(f)}const T=j(O),z=({option:n,theme:f,notMerge:i=!1,lazyUpdate:d=!1,showLoading:m=!1,loadingOption:b,onEvents:o})=>{const l=t.useRef(null),c=t.useRef(),g=()=>c.current,h=t.useCallback(()=>{if(l.current&&!c.current){const e=T.init(l.current,f);return c.current=e,o&&Object.entries(o).forEach(([s,{handler:u,query:a,context:p}])=>{a?e.on(s,a,u,p):e.on(s,u,p)}),m?e.showLoading(b):e.hideLoading(),e.setOption(n,{notMerge:i,lazyUpdate:d}),e}return c.current},[n,f,i,d,m,b,o]),w=t.useCallback((e,s)=>{requestAnimationFrame(()=>{const u=c.current||h();u&&u.setOption(e,s)})},[h]);return t.useEffect(()=>{const e=c.current;if(!e)return;const s=()=>{const a=setTimeout(()=>{e==null||e.resize()},250);return()=>clearTimeout(a)},u=s();return window.addEventListener("resize",s),()=>{o&&Object.entries(o).forEach(([a,{handler:p}])=>{e.off(a,p)}),window.removeEventListener("resize",s),e.dispose(),c.current=void 0,u()}},[o]),t.useEffect(()=>{l.current&&requestAnimationFrame(()=>{h()})},[l,h]),{chartRef:l,setOption:w,getInstance:g}};r.useEcharts=z,Object.defineProperty(r,Symbol.toStringTag,{value:"Module"})});
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"})});
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "react-use-echarts",
3
3
  "private": false,
4
- "version": "0.0.6",
4
+ "version": "0.0.8",
5
5
  "description": "A powerful React hooks library for Apache ECharts",
6
6
  "keywords": [
7
7
  "react",
@@ -41,31 +41,31 @@
41
41
  "dist"
42
42
  ],
43
43
  "devDependencies": {
44
- "@eslint/js": "^9.16.0",
45
- "@testing-library/react": "^16.0.1",
46
- "@types/node": "^22.10.1",
47
- "@types/react": "^18.3.12",
48
- "@types/react-dom": "^18.3.1",
49
- "@vitejs/plugin-react-swc": "^3.7.2",
50
- "@vitest/coverage-v8": "2.1.8",
51
- "echarts": "^5.5.1",
52
- "eslint": "^9.16.0",
53
- "eslint-plugin-react-hooks": "^5.0.0",
54
- "eslint-plugin-react-refresh": "^0.4.16",
55
- "globals": "^15.13.0",
56
- "jsdom": "^25.0.1",
57
- "react": "^18.3.1",
58
- "react-dom": "^18.3.1",
59
- "typescript": "~5.7.2",
60
- "typescript-eslint": "^8.17.0",
61
- "vite": "^6.0.2",
62
- "vite-plugin-dts": "^4.3.0",
63
- "vitest": "^2.1.8"
44
+ "@eslint/js": "^9.21.0",
45
+ "@testing-library/react": "^16.2.0",
46
+ "@types/node": "^22.13.9",
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.7",
51
+ "echarts": "^5.6.0",
52
+ "eslint": "^9.21.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.0",
61
+ "vite": "^6.2.0",
62
+ "vite-plugin-dts": "^4.5.3",
63
+ "vitest": "^3.0.7"
64
64
  },
65
65
  "peerDependencies": {
66
66
  "echarts": "^5.5.1",
67
- "react": "^18.3.1",
68
- "react-dom": "^18.3.1"
67
+ "react": "^18.3.1 || ^19.0.0",
68
+ "react-dom": "^18.3.1 || ^19.0.0"
69
69
  },
70
70
  "scripts": {
71
71
  "dev": "vite",