react-use-echarts 0.0.6 → 0.0.7
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/dist/index.d.ts +1 -1
- package/dist/index.es.js +56 -48
- package/dist/index.umd.js +1 -1
- package/package.json +12 -12
package/dist/index.d.ts
CHANGED
|
@@ -122,7 +122,7 @@ export declare interface UseEchartsReturn {
|
|
|
122
122
|
* Reference to the chart container element
|
|
123
123
|
* 图表容器元素的引用
|
|
124
124
|
*/
|
|
125
|
-
chartRef: React.RefObject<HTMLDivElement>;
|
|
125
|
+
chartRef: React.RefObject<HTMLDivElement | null>;
|
|
126
126
|
/**
|
|
127
127
|
* Function to update chart options
|
|
128
128
|
* 更新图表配置的函数
|
package/dist/index.es.js
CHANGED
|
@@ -1,72 +1,80 @@
|
|
|
1
|
-
import { useRef as
|
|
2
|
-
import * as
|
|
3
|
-
const
|
|
1
|
+
import { useRef as z, useCallback as a, useEffect as C } from "react";
|
|
2
|
+
import * as R from "echarts";
|
|
3
|
+
const v = ({
|
|
4
4
|
/** Chart configuration */
|
|
5
5
|
option: f,
|
|
6
6
|
/** Theme name */
|
|
7
|
-
theme:
|
|
7
|
+
theme: i,
|
|
8
8
|
/** Skip merging with previous options */
|
|
9
|
-
notMerge:
|
|
9
|
+
notMerge: l = !1,
|
|
10
10
|
/** Enable lazy update mode */
|
|
11
|
-
lazyUpdate:
|
|
11
|
+
lazyUpdate: p = !1,
|
|
12
12
|
/** Display loading animation */
|
|
13
|
-
showLoading:
|
|
13
|
+
showLoading: d = !1,
|
|
14
14
|
/** Loading animation config */
|
|
15
|
-
loadingOption:
|
|
15
|
+
loadingOption: O,
|
|
16
16
|
/** Event handlers map */
|
|
17
|
-
onEvents:
|
|
17
|
+
onEvents: c
|
|
18
18
|
}) => {
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
return t.current;
|
|
29
|
-
}, [
|
|
19
|
+
const s = z(null), t = z(void 0), k = () => t.current, b = a(() => ({
|
|
20
|
+
option: f,
|
|
21
|
+
theme: i,
|
|
22
|
+
notMerge: l,
|
|
23
|
+
lazyUpdate: p,
|
|
24
|
+
showLoading: d,
|
|
25
|
+
loadingOption: O,
|
|
26
|
+
onEvents: c
|
|
27
|
+
}), [
|
|
30
28
|
f,
|
|
31
|
-
|
|
32
|
-
m,
|
|
29
|
+
i,
|
|
33
30
|
l,
|
|
34
|
-
|
|
31
|
+
p,
|
|
35
32
|
d,
|
|
36
|
-
|
|
37
|
-
|
|
33
|
+
O,
|
|
34
|
+
c
|
|
35
|
+
]), o = a(() => {
|
|
36
|
+
if (s.current && !t.current) {
|
|
37
|
+
const e = R.init(s.current, i);
|
|
38
|
+
t.current = e;
|
|
39
|
+
const r = b();
|
|
40
|
+
return r.onEvents && Object.entries(r.onEvents).forEach(
|
|
41
|
+
([n, { handler: u, query: g, context: h }]) => {
|
|
42
|
+
g ? e.on(n, g, u, h) : e.on(n, 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 t.current;
|
|
50
|
+
}, [b, i]), M = a(
|
|
38
51
|
(e, r) => {
|
|
39
|
-
|
|
40
|
-
const n = t.current ||
|
|
52
|
+
queueMicrotask(() => {
|
|
53
|
+
const n = t.current || o();
|
|
41
54
|
n && n.setOption(e, r);
|
|
42
55
|
});
|
|
43
56
|
},
|
|
44
|
-
[
|
|
57
|
+
[o]
|
|
45
58
|
);
|
|
46
|
-
return
|
|
59
|
+
return C(() => {
|
|
47
60
|
const e = t.current;
|
|
48
61
|
if (!e) return;
|
|
49
|
-
const r = () => {
|
|
50
|
-
|
|
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
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
65
|
+
return r.observe(s.current), () => {
|
|
66
|
+
r.disconnect(), c && e && Object.entries(c).forEach(([n, { handler: u }]) => {
|
|
67
|
+
e.off(n, u);
|
|
68
|
+
}), e.dispose(), t.current = void 0;
|
|
69
|
+
};
|
|
70
|
+
}, [t, 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
|
-
|
|
79
|
+
v as useEcharts
|
|
72
80
|
};
|
package/dist/index.umd.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(r,
|
|
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 o in s)if(o!=="default"){const a=Object.getOwnPropertyDescriptor(s,o);Object.defineProperty(c,o,a.get?a:{enumerable:!0,get:()=>s[o]})}}return c.default=s,Object.freeze(c)}const C=k(y),z=({option:s,theme:c,notMerge:o=!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:o,lazyUpdate:a,showLoading:b,loadingOption:h,onEvents:d}),[s,c,o,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(([u,{handler:p,query:g,context:j}])=>{g?e.on(u,g,p,j):e.on(u,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 u=i.current||l();u&&u.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(([u,{handler:p}])=>{e.off(u,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.
|
|
4
|
+
"version": "0.0.7",
|
|
5
5
|
"description": "A powerful React hooks library for Apache ECharts",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"react",
|
|
@@ -42,30 +42,30 @@
|
|
|
42
42
|
],
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"@eslint/js": "^9.16.0",
|
|
45
|
-
"@testing-library/react": "^16.0
|
|
46
|
-
"@types/node": "^22.10.
|
|
47
|
-
"@types/react": "^
|
|
48
|
-
"@types/react-dom": "^
|
|
45
|
+
"@testing-library/react": "^16.1.0",
|
|
46
|
+
"@types/node": "^22.10.2",
|
|
47
|
+
"@types/react": "^19.0.1",
|
|
48
|
+
"@types/react-dom": "^19.0.2",
|
|
49
49
|
"@vitejs/plugin-react-swc": "^3.7.2",
|
|
50
50
|
"@vitest/coverage-v8": "2.1.8",
|
|
51
51
|
"echarts": "^5.5.1",
|
|
52
52
|
"eslint": "^9.16.0",
|
|
53
|
-
"eslint-plugin-react-hooks": "^5.
|
|
53
|
+
"eslint-plugin-react-hooks": "^5.1.0",
|
|
54
54
|
"eslint-plugin-react-refresh": "^0.4.16",
|
|
55
55
|
"globals": "^15.13.0",
|
|
56
56
|
"jsdom": "^25.0.1",
|
|
57
|
-
"react": "^
|
|
58
|
-
"react-dom": "^
|
|
57
|
+
"react": "^19.0.0",
|
|
58
|
+
"react-dom": "^19.0.0",
|
|
59
59
|
"typescript": "~5.7.2",
|
|
60
|
-
"typescript-eslint": "^8.
|
|
61
|
-
"vite": "^6.0.
|
|
60
|
+
"typescript-eslint": "^8.18.0",
|
|
61
|
+
"vite": "^6.0.3",
|
|
62
62
|
"vite-plugin-dts": "^4.3.0",
|
|
63
63
|
"vitest": "^2.1.8"
|
|
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",
|