@hsu-react/ui 2.4.1 → 2.4.3
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/es/components/Chart/Bar/index.js +9 -2
- package/es/components/Chart/Common/index.js +9 -2
- package/es/components/Chart/Gauge/index.js +9 -2
- package/es/components/Chart/Heatmap/index.js +9 -2
- package/es/components/Chart/Line/index.js +9 -2
- package/es/components/Chart/Pie/Pie3D/index.js +9 -2
- package/es/components/Chart/Pie/index.js +9 -2
- package/es/components/Chart/Polar/index.js +9 -2
- package/es/components/Chart/Radar/index.js +9 -2
- package/es/components/Chart/Sankey/index.js +9 -2
- package/es/components/Chart/Tree/index.js +9 -2
- package/es/components/Chart/_hooks/useContainerReady.d.ts +18 -0
- package/es/components/Chart/_hooks/useContainerReady.js +56 -0
- package/es/layout/NavTabBar/_hooks/useTabPath.js +45 -8
- package/lib/components/Chart/Bar/index.js +9 -2
- package/lib/components/Chart/Common/index.js +9 -2
- package/lib/components/Chart/Gauge/index.js +9 -2
- package/lib/components/Chart/Heatmap/index.js +9 -2
- package/lib/components/Chart/Line/index.js +9 -2
- package/lib/components/Chart/Pie/Pie3D/index.js +9 -2
- package/lib/components/Chart/Pie/index.js +9 -2
- package/lib/components/Chart/Polar/index.js +9 -2
- package/lib/components/Chart/Radar/index.js +9 -2
- package/lib/components/Chart/Sankey/index.js +9 -2
- package/lib/components/Chart/Tree/index.js +9 -2
- package/lib/components/Chart/_hooks/useContainerReady.d.ts +18 -0
- package/lib/components/Chart/_hooks/useContainerReady.js +51 -0
- package/lib/layout/NavTabBar/_hooks/useTabPath.js +42 -7
- package/package.json +1 -1
- package/src/components/Chart/Bar/index.tsx +10 -1
- package/src/components/Chart/Common/index.tsx +12 -2
- package/src/components/Chart/Gauge/index.tsx +12 -2
- package/src/components/Chart/Heatmap/index.tsx +12 -2
- package/src/components/Chart/Line/index.tsx +10 -1
- package/src/components/Chart/Pie/Pie3D/index.tsx +10 -1
- package/src/components/Chart/Pie/index.tsx +10 -1
- package/src/components/Chart/Polar/index.tsx +12 -2
- package/src/components/Chart/Radar/index.tsx +10 -1
- package/src/components/Chart/Sankey/index.tsx +12 -2
- package/src/components/Chart/Tree/index.tsx +12 -2
- package/src/components/Chart/_hooks/useContainerReady.ts +50 -0
- package/src/layout/NavTabBar/_hooks/useTabPath.ts +43 -10
|
@@ -8,6 +8,7 @@ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e
|
|
|
8
8
|
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
9
9
|
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
10
10
|
import * as echarts from "echarts";
|
|
11
|
+
import useContainerReady from "../_hooks/useContainerReady";
|
|
11
12
|
import React, { useCallback, useEffect, useMemo, useRef } from "react";
|
|
12
13
|
import styles from "../index.module.scss";
|
|
13
14
|
import { autoScrollLegend } from "../_utils/autoScrollLegend";
|
|
@@ -46,6 +47,8 @@ var ChartBar = function ChartBar(props) {
|
|
|
46
47
|
coreOption = _objectWithoutProperties(props, _excluded);
|
|
47
48
|
var chartRef = useRef(null);
|
|
48
49
|
var chartInstanceRef = useRef(null);
|
|
50
|
+
// Defers `echarts.init` until the container has a box — see the hook for why
|
|
51
|
+
var containerReady = useContainerReady(chartRef);
|
|
49
52
|
var resizeObserverRef = useRef(null);
|
|
50
53
|
var prevXAxisKeyRef = useRef(null);
|
|
51
54
|
var legendScrollRef = useRef(null);
|
|
@@ -187,13 +190,17 @@ var ChartBar = function ChartBar(props) {
|
|
|
187
190
|
// Callback for handling chart resize
|
|
188
191
|
var handleResize = useCallback(function () {
|
|
189
192
|
var _chartInstanceRef$cur;
|
|
193
|
+
// A keep-alive tab losing focus fires the observer with a 0×0 box; resizing to that throws
|
|
194
|
+
// the laid-out canvas away and it has to be rebuilt when the tab comes back
|
|
195
|
+
var el = chartRef.current;
|
|
196
|
+
if (!el || el.clientWidth === 0 || el.clientHeight === 0) return;
|
|
190
197
|
(_chartInstanceRef$cur = chartInstanceRef.current) === null || _chartInstanceRef$cur === void 0 || _chartInstanceRef$cur.resize();
|
|
191
198
|
}, []);
|
|
192
199
|
|
|
193
200
|
// Initialize the chart
|
|
194
201
|
useEffect(function () {
|
|
195
202
|
var _xAxisData$join, _chart$getOption, _chart$getOption2, _opt$legend$, _opt$legend, _ref3;
|
|
196
|
-
if (!chartRef.current) return;
|
|
203
|
+
if (!chartRef.current || !containerReady) return;
|
|
197
204
|
|
|
198
205
|
// Initialize or reuse the existing instance
|
|
199
206
|
var chart = chartInstanceRef.current;
|
|
@@ -334,7 +341,7 @@ var ChartBar = function ChartBar(props) {
|
|
|
334
341
|
};
|
|
335
342
|
}, [chartOption, handleResize, onClick, onLegendSelectChanged, onDataZoomWindowChanged, xAxisData, enableLegendAutoScroll, legendVisibleCount, legendScrollInterval,
|
|
336
343
|
// 图例是否接管滚轮由它推导,漏了会拿到过期的滚动配置
|
|
337
|
-
normalizedScroll]);
|
|
344
|
+
normalizedScroll, containerReady]);
|
|
338
345
|
|
|
339
346
|
// Handle auto play
|
|
340
347
|
useEffect(function () {
|
|
@@ -8,6 +8,7 @@ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e
|
|
|
8
8
|
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
9
9
|
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
10
10
|
import React, { useCallback, useEffect, useMemo, useRef } from "react";
|
|
11
|
+
import useContainerReady from "../_hooks/useContainerReady";
|
|
11
12
|
import styles from "../index.module.scss";
|
|
12
13
|
import * as echarts from "echarts";
|
|
13
14
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
@@ -18,6 +19,8 @@ var Common = function Common(props) {
|
|
|
18
19
|
coreOption = _objectWithoutProperties(props, _excluded);
|
|
19
20
|
var chartRef = useRef(null);
|
|
20
21
|
var chartInstanceRef = useRef(null);
|
|
22
|
+
// Defers `echarts.init` until the container has a box — see the hook for why
|
|
23
|
+
var containerReady = useContainerReady(chartRef);
|
|
21
24
|
var resizeObserverRef = useRef(null);
|
|
22
25
|
|
|
23
26
|
// Cache the chart configuration with useMemo
|
|
@@ -29,12 +32,16 @@ var Common = function Common(props) {
|
|
|
29
32
|
// Callback that handles chart resize
|
|
30
33
|
var handleResize = useCallback(function () {
|
|
31
34
|
var _chartInstanceRef$cur;
|
|
35
|
+
// A keep-alive tab losing focus fires the observer with a 0×0 box; resizing to that throws
|
|
36
|
+
// the laid-out canvas away and it has to be rebuilt when the tab comes back
|
|
37
|
+
var el = chartRef.current;
|
|
38
|
+
if (!el || el.clientWidth === 0 || el.clientHeight === 0) return;
|
|
32
39
|
(_chartInstanceRef$cur = chartInstanceRef.current) === null || _chartInstanceRef$cur === void 0 || _chartInstanceRef$cur.resize();
|
|
33
40
|
}, []);
|
|
34
41
|
|
|
35
42
|
// Initialize the chart
|
|
36
43
|
useEffect(function () {
|
|
37
|
-
if (!chartRef.current) return;
|
|
44
|
+
if (!chartRef.current || !containerReady) return;
|
|
38
45
|
|
|
39
46
|
// Initialize or reuse an existing instance
|
|
40
47
|
var chart = chartInstanceRef.current;
|
|
@@ -62,7 +69,7 @@ var Common = function Common(props) {
|
|
|
62
69
|
return function () {
|
|
63
70
|
window.removeEventListener("resize", handleResize);
|
|
64
71
|
};
|
|
65
|
-
}, [chartOption, handleResize, onChart]);
|
|
72
|
+
}, [chartOption, handleResize, onChart, containerReady]);
|
|
66
73
|
|
|
67
74
|
// Clean up resources on component unmount
|
|
68
75
|
useEffect(function () {
|
|
@@ -8,6 +8,7 @@ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e
|
|
|
8
8
|
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
9
9
|
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
10
10
|
import * as echarts from "echarts";
|
|
11
|
+
import useContainerReady from "../_hooks/useContainerReady";
|
|
11
12
|
import React, { useCallback, useEffect, useMemo, useRef } from "react";
|
|
12
13
|
import styles from "../index.module.scss";
|
|
13
14
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
@@ -31,6 +32,8 @@ var Gauge = function Gauge(props) {
|
|
|
31
32
|
coreSeries = _objectWithoutProperties(_ref, _excluded);
|
|
32
33
|
var chartRef = useRef(null);
|
|
33
34
|
var chartInstanceRef = useRef(null);
|
|
35
|
+
// Defers `echarts.init` until the container has a box — see the hook for why
|
|
36
|
+
var containerReady = useContainerReady(chartRef);
|
|
34
37
|
var resizeObserverRef = useRef(null);
|
|
35
38
|
|
|
36
39
|
// Cache the chart option with useMemo
|
|
@@ -83,12 +86,16 @@ var Gauge = function Gauge(props) {
|
|
|
83
86
|
// Callback for handling chart resize
|
|
84
87
|
var handleResize = useCallback(function () {
|
|
85
88
|
var _chartInstanceRef$cur;
|
|
89
|
+
// A keep-alive tab losing focus fires the observer with a 0×0 box; resizing to that throws
|
|
90
|
+
// the laid-out canvas away and it has to be rebuilt when the tab comes back
|
|
91
|
+
var el = chartRef.current;
|
|
92
|
+
if (!el || el.clientWidth === 0 || el.clientHeight === 0) return;
|
|
86
93
|
(_chartInstanceRef$cur = chartInstanceRef.current) === null || _chartInstanceRef$cur === void 0 || _chartInstanceRef$cur.resize();
|
|
87
94
|
}, []);
|
|
88
95
|
|
|
89
96
|
// Initialize the chart
|
|
90
97
|
useEffect(function () {
|
|
91
|
-
if (!chartRef.current) return;
|
|
98
|
+
if (!chartRef.current || !containerReady) return;
|
|
92
99
|
|
|
93
100
|
// Initialize or reuse the existing instance
|
|
94
101
|
var chart = chartInstanceRef.current;
|
|
@@ -113,7 +120,7 @@ var Gauge = function Gauge(props) {
|
|
|
113
120
|
return function () {
|
|
114
121
|
window.removeEventListener("resize", handleResize);
|
|
115
122
|
};
|
|
116
|
-
}, [chartOption, handleResize]);
|
|
123
|
+
}, [chartOption, handleResize, containerReady]);
|
|
117
124
|
|
|
118
125
|
// Clean up resources when the component unmounts
|
|
119
126
|
useEffect(function () {
|
|
@@ -14,6 +14,7 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
|
|
|
14
14
|
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
15
15
|
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
16
16
|
import React, { useCallback, useEffect, useMemo, useRef } from "react";
|
|
17
|
+
import useContainerReady from "../_hooks/useContainerReady";
|
|
17
18
|
import styles from "../index.module.scss";
|
|
18
19
|
import * as echarts from "echarts";
|
|
19
20
|
import { createDefaultHeatmapXAxis, createDefaultHeatmapYAxis } from "../_utils/heatmap";
|
|
@@ -42,6 +43,8 @@ var Heatmap = function Heatmap(props) {
|
|
|
42
43
|
coreOption = _objectWithoutProperties(props, _excluded);
|
|
43
44
|
var chartRef = useRef(null);
|
|
44
45
|
var chartInstanceRef = useRef(null);
|
|
46
|
+
// Defers `echarts.init` until the container has a box — see the hook for why
|
|
47
|
+
var containerReady = useContainerReady(chartRef);
|
|
45
48
|
var resizeObserverRef = useRef(null);
|
|
46
49
|
// echarts options are plain JS and cannot read the `--vita-*` variables, so the axis and legend
|
|
47
50
|
// colours have to be resolved against the active appearance here
|
|
@@ -183,12 +186,16 @@ var Heatmap = function Heatmap(props) {
|
|
|
183
186
|
// Callback for handling chart resize
|
|
184
187
|
var handleResize = useCallback(function () {
|
|
185
188
|
var _chartInstanceRef$cur;
|
|
189
|
+
// A keep-alive tab losing focus fires the observer with a 0×0 box; resizing to that throws
|
|
190
|
+
// the laid-out canvas away and it has to be rebuilt when the tab comes back
|
|
191
|
+
var el = chartRef.current;
|
|
192
|
+
if (!el || el.clientWidth === 0 || el.clientHeight === 0) return;
|
|
186
193
|
(_chartInstanceRef$cur = chartInstanceRef.current) === null || _chartInstanceRef$cur === void 0 || _chartInstanceRef$cur.resize();
|
|
187
194
|
}, []);
|
|
188
195
|
|
|
189
196
|
// Initialize the chart
|
|
190
197
|
useEffect(function () {
|
|
191
|
-
if (!chartRef.current) return;
|
|
198
|
+
if (!chartRef.current || !containerReady) return;
|
|
192
199
|
|
|
193
200
|
// Initialize or reuse the existing instance
|
|
194
201
|
var chart = chartInstanceRef.current;
|
|
@@ -225,7 +232,7 @@ var Heatmap = function Heatmap(props) {
|
|
|
225
232
|
(_chartInstanceRef$cur3 = chartInstanceRef.current) === null || _chartInstanceRef$cur3 === void 0 || _chartInstanceRef$cur3.off("click", onClick);
|
|
226
233
|
}
|
|
227
234
|
};
|
|
228
|
-
}, [chartOption, handleResize, onChart, onClick]);
|
|
235
|
+
}, [chartOption, handleResize, onChart, onClick, containerReady]);
|
|
229
236
|
|
|
230
237
|
// Clean up resources when the component unmounts
|
|
231
238
|
useEffect(function () {
|
|
@@ -8,6 +8,7 @@ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e
|
|
|
8
8
|
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
9
9
|
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
10
10
|
import * as echarts from "echarts";
|
|
11
|
+
import useContainerReady from "../_hooks/useContainerReady";
|
|
11
12
|
import React, { useCallback, useEffect, useMemo, useRef } from "react";
|
|
12
13
|
import styles from "../index.module.scss";
|
|
13
14
|
import { autoScrollLegend } from "../_utils/autoScrollLegend";
|
|
@@ -46,6 +47,8 @@ var ChartLine = function ChartLine(props) {
|
|
|
46
47
|
coreOption = _objectWithoutProperties(props, _excluded);
|
|
47
48
|
var chartRef = useRef(null);
|
|
48
49
|
var chartInstanceRef = useRef(null);
|
|
50
|
+
// Defers `echarts.init` until the container has a box — see the hook for why
|
|
51
|
+
var containerReady = useContainerReady(chartRef);
|
|
49
52
|
var resizeObserverRef = useRef(null);
|
|
50
53
|
var prevXAxisKeyRef = useRef(null);
|
|
51
54
|
var legendScrollRef = useRef(null);
|
|
@@ -184,13 +187,17 @@ var ChartLine = function ChartLine(props) {
|
|
|
184
187
|
// Callback for handling chart resize
|
|
185
188
|
var handleResize = useCallback(function () {
|
|
186
189
|
var _chartInstanceRef$cur;
|
|
190
|
+
// A keep-alive tab losing focus fires the observer with a 0×0 box; resizing to that throws
|
|
191
|
+
// the laid-out canvas away and it has to be rebuilt when the tab comes back
|
|
192
|
+
var el = chartRef.current;
|
|
193
|
+
if (!el || el.clientWidth === 0 || el.clientHeight === 0) return;
|
|
187
194
|
(_chartInstanceRef$cur = chartInstanceRef.current) === null || _chartInstanceRef$cur === void 0 || _chartInstanceRef$cur.resize();
|
|
188
195
|
}, []);
|
|
189
196
|
|
|
190
197
|
// Initialize the chart
|
|
191
198
|
useEffect(function () {
|
|
192
199
|
var _xAxisData$join, _chart$getOption, _chart$getOption2, _opt$legend$, _opt$legend, _ref3;
|
|
193
|
-
if (!chartRef.current) return;
|
|
200
|
+
if (!chartRef.current || !containerReady) return;
|
|
194
201
|
|
|
195
202
|
// Initialize or reuse the existing instance
|
|
196
203
|
var chart = chartInstanceRef.current;
|
|
@@ -331,7 +338,7 @@ var ChartLine = function ChartLine(props) {
|
|
|
331
338
|
};
|
|
332
339
|
}, [chartOption, handleResize, onClick, onLegendSelectChanged, onDataZoomWindowChanged, xAxisData, enableLegendAutoScroll, legendVisibleCount, legendScrollInterval,
|
|
333
340
|
// 图例是否接管滚轮由它推导,漏了会拿到过期的滚动配置
|
|
334
|
-
normalizedScroll]);
|
|
341
|
+
normalizedScroll, containerReady]);
|
|
335
342
|
|
|
336
343
|
// Handle auto play
|
|
337
344
|
useEffect(function () {
|
|
@@ -2,6 +2,7 @@ var _excluded = ["className", "style", "pieData", "internalDiameterRatio", "auto
|
|
|
2
2
|
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
3
3
|
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
4
4
|
import * as echarts from "echarts";
|
|
5
|
+
import useContainerReady from "../../_hooks/useContainerReady";
|
|
5
6
|
import "echarts-gl";
|
|
6
7
|
import React, { useCallback, useEffect, useMemo, useRef } from "react";
|
|
7
8
|
import { useMouseOverHandler, useGlobalOutHandler } from "./_hooks";
|
|
@@ -45,6 +46,8 @@ var ChartPie3D = function ChartPie3D(props) {
|
|
|
45
46
|
coreOption = _objectWithoutProperties(props, _excluded);
|
|
46
47
|
var chartRef = useRef(null);
|
|
47
48
|
var chartInstanceRef = useRef(null);
|
|
49
|
+
// Defers `echarts.init` until the container has a box — see the hook for why
|
|
50
|
+
var containerReady = useContainerReady(chartRef);
|
|
48
51
|
var resizeObserverRef = useRef(null);
|
|
49
52
|
var hoveredIndexRef = useRef("");
|
|
50
53
|
var optionRef = useRef(null);
|
|
@@ -67,6 +70,10 @@ var ChartPie3D = function ChartPie3D(props) {
|
|
|
67
70
|
}, [pieData, internalDiameterRatio, tooltip, alpha, beta, autoRotate, distance, coreOption, minHeight, maxHeight, yOffset, label, enableMouseControl]);
|
|
68
71
|
var handleResize = useCallback(function () {
|
|
69
72
|
var _chartInstanceRef$cur;
|
|
73
|
+
// A keep-alive tab losing focus fires the observer with a 0×0 box; resizing to that throws
|
|
74
|
+
// the laid-out canvas away and it has to be rebuilt when the tab comes back
|
|
75
|
+
var el = chartRef.current;
|
|
76
|
+
if (!el || el.clientWidth === 0 || el.clientHeight === 0) return;
|
|
70
77
|
(_chartInstanceRef$cur = chartInstanceRef.current) === null || _chartInstanceRef$cur === void 0 || _chartInstanceRef$cur.resize();
|
|
71
78
|
}, []);
|
|
72
79
|
var handleMouseOver = useMouseOverHandler(optionRef, chartInstanceRef, hoveredIndexRef, {
|
|
@@ -83,7 +90,7 @@ var ChartPie3D = function ChartPie3D(props) {
|
|
|
83
90
|
autoRotate: autoRotate
|
|
84
91
|
});
|
|
85
92
|
useEffect(function () {
|
|
86
|
-
if (!chartRef.current) return;
|
|
93
|
+
if (!chartRef.current || !containerReady) return;
|
|
87
94
|
var chart = chartInstanceRef.current;
|
|
88
95
|
if (!chart) {
|
|
89
96
|
chart = echarts.init(chartRef.current);
|
|
@@ -112,7 +119,7 @@ var ChartPie3D = function ChartPie3D(props) {
|
|
|
112
119
|
}
|
|
113
120
|
}
|
|
114
121
|
};
|
|
115
|
-
}, [chartOption, handleResize, handleMouseOver, handleGlobalOut, onChart, onClick]);
|
|
122
|
+
}, [chartOption, handleResize, handleMouseOver, handleGlobalOut, onChart, onClick, containerReady]);
|
|
116
123
|
useEffect(function () {
|
|
117
124
|
return function () {
|
|
118
125
|
if (resizeObserverRef.current) {
|
|
@@ -14,6 +14,7 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
|
|
|
14
14
|
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
15
15
|
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
16
16
|
import * as echarts from "echarts";
|
|
17
|
+
import useContainerReady from "../_hooks/useContainerReady";
|
|
17
18
|
import React, { useCallback, useEffect, useMemo, useRef } from "react";
|
|
18
19
|
import { autoScrollLegend } from "../chartUtils";
|
|
19
20
|
import styles from "../index.module.scss";
|
|
@@ -49,6 +50,8 @@ var ChartPie = function ChartPie(props) {
|
|
|
49
50
|
coreOption = _objectWithoutProperties(props, _excluded);
|
|
50
51
|
var chartRef = useRef(null);
|
|
51
52
|
var chartInstanceRef = useRef(null);
|
|
53
|
+
// Defers `echarts.init` until the container has a box — see the hook for why
|
|
54
|
+
var containerReady = useContainerReady(chartRef);
|
|
52
55
|
var resizeObserverRef = useRef(null);
|
|
53
56
|
var legendScrollRef = useRef(null);
|
|
54
57
|
|
|
@@ -198,12 +201,16 @@ var ChartPie = function ChartPie(props) {
|
|
|
198
201
|
// Callback for handling chart resize
|
|
199
202
|
var handleResize = useCallback(function () {
|
|
200
203
|
var _chartInstanceRef$cur;
|
|
204
|
+
// A keep-alive tab losing focus fires the observer with a 0×0 box; resizing to that throws
|
|
205
|
+
// the laid-out canvas away and it has to be rebuilt when the tab comes back
|
|
206
|
+
var el = chartRef.current;
|
|
207
|
+
if (!el || el.clientWidth === 0 || el.clientHeight === 0) return;
|
|
201
208
|
(_chartInstanceRef$cur = chartInstanceRef.current) === null || _chartInstanceRef$cur === void 0 || _chartInstanceRef$cur.resize();
|
|
202
209
|
}, []);
|
|
203
210
|
|
|
204
211
|
// Initialize the chart
|
|
205
212
|
useEffect(function () {
|
|
206
|
-
if (!chartRef.current) return;
|
|
213
|
+
if (!chartRef.current || !containerReady) return;
|
|
207
214
|
|
|
208
215
|
// Initialize or reuse the existing instance
|
|
209
216
|
var chart = chartInstanceRef.current;
|
|
@@ -261,7 +268,7 @@ var ChartPie = function ChartPie(props) {
|
|
|
261
268
|
legendScrollRef.current = null;
|
|
262
269
|
}
|
|
263
270
|
};
|
|
264
|
-
}, [chartOption, handleResize, onChart, onClick, enableLegendAutoScroll, seriesData, legendVisibleCount, legendScrollInterval]);
|
|
271
|
+
}, [chartOption, handleResize, onChart, onClick, enableLegendAutoScroll, seriesData, legendVisibleCount, legendScrollInterval, containerReady]);
|
|
265
272
|
|
|
266
273
|
// Clean up resources when the component unmounts
|
|
267
274
|
useEffect(function () {
|
|
@@ -8,6 +8,7 @@ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e
|
|
|
8
8
|
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
9
9
|
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
10
10
|
import * as echarts from "echarts";
|
|
11
|
+
import useContainerReady from "../_hooks/useContainerReady";
|
|
11
12
|
import React, { useCallback, useEffect, useMemo, useRef } from "react";
|
|
12
13
|
import styles from "../index.module.scss";
|
|
13
14
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
@@ -29,6 +30,8 @@ var Polar = function Polar(props) {
|
|
|
29
30
|
coreOption = _objectWithoutProperties(props, _excluded);
|
|
30
31
|
var chartRef = useRef(null);
|
|
31
32
|
var chartInstanceRef = useRef(null);
|
|
33
|
+
// Defers `echarts.init` until the container has a box — see the hook for why
|
|
34
|
+
var containerReady = useContainerReady(chartRef);
|
|
32
35
|
var resizeObserverRef = useRef(null);
|
|
33
36
|
|
|
34
37
|
// Cache the chart option with useMemo
|
|
@@ -135,12 +138,16 @@ var Polar = function Polar(props) {
|
|
|
135
138
|
// Callback handling chart resize
|
|
136
139
|
var handleResize = useCallback(function () {
|
|
137
140
|
var _chartInstanceRef$cur;
|
|
141
|
+
// A keep-alive tab losing focus fires the observer with a 0×0 box; resizing to that throws
|
|
142
|
+
// the laid-out canvas away and it has to be rebuilt when the tab comes back
|
|
143
|
+
var el = chartRef.current;
|
|
144
|
+
if (!el || el.clientWidth === 0 || el.clientHeight === 0) return;
|
|
138
145
|
(_chartInstanceRef$cur = chartInstanceRef.current) === null || _chartInstanceRef$cur === void 0 || _chartInstanceRef$cur.resize();
|
|
139
146
|
}, []);
|
|
140
147
|
|
|
141
148
|
// Initialize the chart
|
|
142
149
|
useEffect(function () {
|
|
143
|
-
if (!chartRef.current) return;
|
|
150
|
+
if (!chartRef.current || !containerReady) return;
|
|
144
151
|
|
|
145
152
|
// Initialize a new instance or reuse the existing one
|
|
146
153
|
var chart = chartInstanceRef.current;
|
|
@@ -165,7 +172,7 @@ var Polar = function Polar(props) {
|
|
|
165
172
|
return function () {
|
|
166
173
|
window.removeEventListener("resize", handleResize);
|
|
167
174
|
};
|
|
168
|
-
}, [chartOption, handleResize]);
|
|
175
|
+
}, [chartOption, handleResize, containerReady]);
|
|
169
176
|
|
|
170
177
|
// Clean up resources on unmount
|
|
171
178
|
useEffect(function () {
|
|
@@ -14,6 +14,7 @@ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e
|
|
|
14
14
|
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
15
15
|
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
16
16
|
import * as echarts from "echarts";
|
|
17
|
+
import useContainerReady from "../_hooks/useContainerReady";
|
|
17
18
|
import React, { useCallback, useEffect, useMemo, useRef } from "react";
|
|
18
19
|
import styles from "../index.module.scss";
|
|
19
20
|
|
|
@@ -40,6 +41,8 @@ var Radar = function Radar(props) {
|
|
|
40
41
|
coreOption = _objectWithoutProperties(props, _excluded);
|
|
41
42
|
var chartRef = useRef(null);
|
|
42
43
|
var chartInstanceRef = useRef(null);
|
|
44
|
+
// Defers `echarts.init` until the container has a box — see the hook for why
|
|
45
|
+
var containerReady = useContainerReady(chartRef);
|
|
43
46
|
var resizeObserverRef = useRef(null);
|
|
44
47
|
var hoveredIndicatorRef = useRef(-1);
|
|
45
48
|
var singleIndicatorEnabled = Boolean(singleIndicatorTooltipProp) && singleIndicatorMode !== undefined;
|
|
@@ -154,10 +157,14 @@ var Radar = function Radar(props) {
|
|
|
154
157
|
}, [indicators, data, color, name, radar, series, coreOption, singleIndicatorEnabled, singleIndicatorFormatter, singleIndicatorRegion]);
|
|
155
158
|
var handleResize = useCallback(function () {
|
|
156
159
|
var _chartInstanceRef$cur;
|
|
160
|
+
// A keep-alive tab losing focus fires the observer with a 0×0 box; resizing to that throws
|
|
161
|
+
// the laid-out canvas away and it has to be rebuilt when the tab comes back
|
|
162
|
+
var el = chartRef.current;
|
|
163
|
+
if (!el || el.clientWidth === 0 || el.clientHeight === 0) return;
|
|
157
164
|
(_chartInstanceRef$cur = chartInstanceRef.current) === null || _chartInstanceRef$cur === void 0 || _chartInstanceRef$cur.resize();
|
|
158
165
|
}, []);
|
|
159
166
|
useEffect(function () {
|
|
160
|
-
if (!chartRef.current) return;
|
|
167
|
+
if (!chartRef.current || !containerReady) return;
|
|
161
168
|
var chart = chartInstanceRef.current;
|
|
162
169
|
if (!chart) {
|
|
163
170
|
chart = echarts.init(chartRef.current);
|
|
@@ -281,7 +288,7 @@ var Radar = function Radar(props) {
|
|
|
281
288
|
}
|
|
282
289
|
}
|
|
283
290
|
};
|
|
284
|
-
}, [chartOption, handleResize, singleIndicatorEnabled, singleIndicatorRegion, singleIndicatorHighlight, singleIndicatorHoverFill, color]);
|
|
291
|
+
}, [chartOption, handleResize, singleIndicatorEnabled, singleIndicatorRegion, singleIndicatorHighlight, singleIndicatorHoverFill, color, containerReady]);
|
|
285
292
|
useEffect(function () {
|
|
286
293
|
return function () {
|
|
287
294
|
if (resizeObserverRef.current) {
|
|
@@ -11,6 +11,7 @@ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key i
|
|
|
11
11
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
12
12
|
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
13
13
|
import React, { useCallback, useEffect, useMemo, useRef } from "react";
|
|
14
|
+
import useContainerReady from "../_hooks/useContainerReady";
|
|
14
15
|
import styles from "../index.module.scss";
|
|
15
16
|
import * as echarts from "echarts";
|
|
16
17
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
@@ -23,6 +24,8 @@ var Sankey = function Sankey(props) {
|
|
|
23
24
|
getImage = props.getImage;
|
|
24
25
|
var chartRef = useRef(null);
|
|
25
26
|
var chartInstanceRef = useRef(null);
|
|
27
|
+
// Defers `echarts.init` until the container has a box — see the hook for why
|
|
28
|
+
var containerReady = useContainerReady(chartRef);
|
|
26
29
|
var resizeObserverRef = useRef(null);
|
|
27
30
|
|
|
28
31
|
// Cache the chart option with useMemo
|
|
@@ -103,12 +106,16 @@ var Sankey = function Sankey(props) {
|
|
|
103
106
|
// Callback handling chart resize
|
|
104
107
|
var handleResize = useCallback(function () {
|
|
105
108
|
var _chartInstanceRef$cur;
|
|
109
|
+
// A keep-alive tab losing focus fires the observer with a 0×0 box; resizing to that throws
|
|
110
|
+
// the laid-out canvas away and it has to be rebuilt when the tab comes back
|
|
111
|
+
var el = chartRef.current;
|
|
112
|
+
if (!el || el.clientWidth === 0 || el.clientHeight === 0) return;
|
|
106
113
|
(_chartInstanceRef$cur = chartInstanceRef.current) === null || _chartInstanceRef$cur === void 0 || _chartInstanceRef$cur.resize();
|
|
107
114
|
}, []);
|
|
108
115
|
|
|
109
116
|
// Initialize the chart
|
|
110
117
|
useEffect(function () {
|
|
111
|
-
if (!chartRef.current) return;
|
|
118
|
+
if (!chartRef.current || !containerReady) return;
|
|
112
119
|
|
|
113
120
|
// Initialize a new instance or reuse the existing one
|
|
114
121
|
var chart = chartInstanceRef.current;
|
|
@@ -142,7 +149,7 @@ var Sankey = function Sankey(props) {
|
|
|
142
149
|
return function () {
|
|
143
150
|
window.removeEventListener("resize", handleResize);
|
|
144
151
|
};
|
|
145
|
-
}, [chartOption, handleResize, getImage]);
|
|
152
|
+
}, [chartOption, handleResize, getImage, containerReady]);
|
|
146
153
|
|
|
147
154
|
// Clean up resources on unmount
|
|
148
155
|
useEffect(function () {
|
|
@@ -5,6 +5,7 @@ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key i
|
|
|
5
5
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
6
6
|
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
7
7
|
import React, { useCallback, useEffect, useMemo, useRef } from "react";
|
|
8
|
+
import useContainerReady from "../_hooks/useContainerReady";
|
|
8
9
|
import styles from "../index.module.scss";
|
|
9
10
|
import * as echarts from "echarts";
|
|
10
11
|
import { deepCopy } from "hsu-utils";
|
|
@@ -18,6 +19,8 @@ var Tree = function Tree(props) {
|
|
|
18
19
|
getImage = props.getImage;
|
|
19
20
|
var chartRef = useRef(null);
|
|
20
21
|
var chartInstanceRef = useRef(null);
|
|
22
|
+
// Defers `echarts.init` until the container has a box — see the hook for why
|
|
23
|
+
var containerReady = useContainerReady(chartRef);
|
|
21
24
|
var resizeObserverRef = useRef(null);
|
|
22
25
|
|
|
23
26
|
// Cache the chart option with useMemo
|
|
@@ -38,12 +41,16 @@ var Tree = function Tree(props) {
|
|
|
38
41
|
// Callback handling chart resize
|
|
39
42
|
var handleResize = useCallback(function () {
|
|
40
43
|
var _chartInstanceRef$cur;
|
|
44
|
+
// A keep-alive tab losing focus fires the observer with a 0×0 box; resizing to that throws
|
|
45
|
+
// the laid-out canvas away and it has to be rebuilt when the tab comes back
|
|
46
|
+
var el = chartRef.current;
|
|
47
|
+
if (!el || el.clientWidth === 0 || el.clientHeight === 0) return;
|
|
41
48
|
(_chartInstanceRef$cur = chartInstanceRef.current) === null || _chartInstanceRef$cur === void 0 || _chartInstanceRef$cur.resize();
|
|
42
49
|
}, []);
|
|
43
50
|
|
|
44
51
|
// Initialize the chart
|
|
45
52
|
useEffect(function () {
|
|
46
|
-
if (!chartRef.current) return;
|
|
53
|
+
if (!chartRef.current || !containerReady) return;
|
|
47
54
|
|
|
48
55
|
// Initialize a new instance or reuse the existing one
|
|
49
56
|
var chart = chartInstanceRef.current;
|
|
@@ -77,7 +84,7 @@ var Tree = function Tree(props) {
|
|
|
77
84
|
return function () {
|
|
78
85
|
window.removeEventListener("resize", handleResize);
|
|
79
86
|
};
|
|
80
|
-
}, [chartOption, handleResize, getImage]);
|
|
87
|
+
}, [chartOption, handleResize, getImage, containerReady]);
|
|
81
88
|
|
|
82
89
|
// Clean up resources on unmount
|
|
83
90
|
useEffect(function () {
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { RefObject } from "react";
|
|
2
|
+
/**
|
|
3
|
+
* Whether the referenced element has a non-zero box yet.
|
|
4
|
+
*
|
|
5
|
+
* `echarts.init` on a 0×0 element logs `Can't get DOM width or height` and builds a canvas with no
|
|
6
|
+
* size, recovering only on the next `resize()`. A chart hits that path whenever it mounts before
|
|
7
|
+
* layout has given it space — inside a keep-alive tab that is not the active one, a collapsed
|
|
8
|
+
* panel, a modal that has not opened yet — so consuming apps see the warning for charts that end
|
|
9
|
+
* up rendering perfectly well.
|
|
10
|
+
*
|
|
11
|
+
* Gating `init` on this flag defers it to the first frame the element actually occupies space.
|
|
12
|
+
*
|
|
13
|
+
* It **latches**: once measured, the element going back to 0×0 (a keep-alive tab losing focus)
|
|
14
|
+
* must not read as "not ready" again, or the init effect would tear the chart down and re-create
|
|
15
|
+
* it on every tab switch.
|
|
16
|
+
*/
|
|
17
|
+
declare const useContainerReady: (ref: RefObject<HTMLElement | null>) => boolean;
|
|
18
|
+
export default useContainerReady;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
2
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
3
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
4
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
5
|
+
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
6
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
7
|
+
import { useEffect, useState } from "react";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Whether the referenced element has a non-zero box yet.
|
|
11
|
+
*
|
|
12
|
+
* `echarts.init` on a 0×0 element logs `Can't get DOM width or height` and builds a canvas with no
|
|
13
|
+
* size, recovering only on the next `resize()`. A chart hits that path whenever it mounts before
|
|
14
|
+
* layout has given it space — inside a keep-alive tab that is not the active one, a collapsed
|
|
15
|
+
* panel, a modal that has not opened yet — so consuming apps see the warning for charts that end
|
|
16
|
+
* up rendering perfectly well.
|
|
17
|
+
*
|
|
18
|
+
* Gating `init` on this flag defers it to the first frame the element actually occupies space.
|
|
19
|
+
*
|
|
20
|
+
* It **latches**: once measured, the element going back to 0×0 (a keep-alive tab losing focus)
|
|
21
|
+
* must not read as "not ready" again, or the init effect would tear the chart down and re-create
|
|
22
|
+
* it on every tab switch.
|
|
23
|
+
*/
|
|
24
|
+
var useContainerReady = function useContainerReady(ref) {
|
|
25
|
+
var _useState = useState(false),
|
|
26
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
27
|
+
ready = _useState2[0],
|
|
28
|
+
setReady = _useState2[1];
|
|
29
|
+
useEffect(function () {
|
|
30
|
+
if (ready) return;
|
|
31
|
+
var el = ref.current;
|
|
32
|
+
if (!el) return;
|
|
33
|
+
var measure = function measure() {
|
|
34
|
+
var _el$getBoundingClient = el.getBoundingClientRect(),
|
|
35
|
+
width = _el$getBoundingClient.width,
|
|
36
|
+
height = _el$getBoundingClient.height;
|
|
37
|
+
if (width > 0 && height > 0) {
|
|
38
|
+
setReady(true);
|
|
39
|
+
return true;
|
|
40
|
+
}
|
|
41
|
+
return false;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
// Already laid out on mount — the common case, and it must not cost an extra frame
|
|
45
|
+
if (measure()) return;
|
|
46
|
+
var observer = new ResizeObserver(function () {
|
|
47
|
+
if (measure()) observer.disconnect();
|
|
48
|
+
});
|
|
49
|
+
observer.observe(el);
|
|
50
|
+
return function () {
|
|
51
|
+
return observer.disconnect();
|
|
52
|
+
};
|
|
53
|
+
}, [ready, ref]);
|
|
54
|
+
return ready;
|
|
55
|
+
};
|
|
56
|
+
export default useContainerReady;
|