react-alp-loading-bar 3.1.1 → 4.0.1
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/.eslintrc.json +1 -1
- package/CHANGELOG.md +45 -0
- package/dist/index-browser.es.js +9 -9
- package/dist/index-browser.es.js.map +1 -1
- package/dist/index-browsermodern.es.js +15 -18
- package/dist/index-browsermodern.es.js.map +1 -1
- package/dist/{index-node12.mjs → index-node14.mjs} +16 -19
- package/dist/index-node14.mjs.map +1 -0
- package/dist/index.d.ts +4 -6
- package/dist/index.d.ts.map +1 -1
- package/package.json +24 -47
- package/rollup.config.mjs +3 -0
- package/src/.eslintrc.json +18 -1
- package/src/index.tsx +12 -14
- package/dist/index-browser-dev.cjs.js +0 -181
- package/dist/index-browser-dev.cjs.js.map +0 -1
- package/dist/index-browser-dev.es.js +0 -171
- package/dist/index-browser-dev.es.js.map +0 -1
- package/dist/index-browser.cjs.js +0 -181
- package/dist/index-browser.cjs.js.map +0 -1
- package/dist/index-browsermodern-dev.es.js +0 -147
- package/dist/index-browsermodern-dev.es.js.map +0 -1
- package/dist/index-node12-dev.cjs.js +0 -156
- package/dist/index-node12-dev.cjs.js.map +0 -1
- package/dist/index-node12-dev.mjs +0 -147
- package/dist/index-node12-dev.mjs.map +0 -1
- package/dist/index-node12.cjs.js +0 -156
- package/dist/index-node12.cjs.js.map +0 -1
- package/dist/index-node12.mjs.map +0 -1
- package/index.js +0 -6
package/.eslintrc.json
CHANGED
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,51 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [4.0.1](https://github.com/christophehurpeau/alp/compare/react-alp-loading-bar@4.0.0...react-alp-loading-bar@4.0.1) (2022-01-15)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package react-alp-loading-bar
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
# [4.0.0](https://github.com/christophehurpeau/alp/compare/react-alp-loading-bar@3.1.3...react-alp-loading-bar@4.0.0) (2022-01-02)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
### Bug Fixes
|
|
18
|
+
|
|
19
|
+
* update nightingale and fix tests ([3691716](https://github.com/christophehurpeau/alp/commit/36917162d0ee3dccc07384caf018b7760d98b744))
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
### Features
|
|
23
|
+
|
|
24
|
+
* use ESM and drop node 12 ([f45054e](https://github.com/christophehurpeau/alp/commit/f45054e931eea88451d183722797eba057511236))
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
### BREAKING CHANGES
|
|
28
|
+
|
|
29
|
+
* requires node 14 and ESM
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
## [3.1.3](https://github.com/christophehurpeau/alp/compare/react-alp-loading-bar@3.1.2...react-alp-loading-bar@3.1.3) (2021-04-10)
|
|
36
|
+
|
|
37
|
+
**Note:** Version bump only for package react-alp-loading-bar
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
## [3.1.2](https://github.com/christophehurpeau/alp/compare/react-alp-loading-bar@3.1.1...react-alp-loading-bar@3.1.2) (2021-03-28)
|
|
44
|
+
|
|
45
|
+
**Note:** Version bump only for package react-alp-loading-bar
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
|
|
6
51
|
## [3.1.1](https://github.com/christophehurpeau/alp/compare/react-alp-loading-bar@3.1.0...react-alp-loading-bar@3.1.1) (2021-03-28)
|
|
7
52
|
|
|
8
53
|
**Note:** Version bump only for package react-alp-loading-bar
|
package/dist/index-browser.es.js
CHANGED
|
@@ -96,10 +96,10 @@ var LoadingBar = /*#__PURE__*/function (_PureComponent) {
|
|
|
96
96
|
};
|
|
97
97
|
|
|
98
98
|
_proto.componentWillUnmount = function componentWillUnmount() {
|
|
99
|
-
clearTimeout(this.fadeOffTimeout);
|
|
100
|
-
clearTimeout(this.resetTimeout);
|
|
101
|
-
clearTimeout(this.first20Timeout);
|
|
102
|
-
clearInterval(this.progressTimer);
|
|
99
|
+
if (this.fadeOffTimeout) clearTimeout(this.fadeOffTimeout);
|
|
100
|
+
if (this.resetTimeout) clearTimeout(this.resetTimeout);
|
|
101
|
+
if (this.first20Timeout) clearTimeout(this.first20Timeout);
|
|
102
|
+
if (this.progressTimer) clearInterval(this.progressTimer);
|
|
103
103
|
};
|
|
104
104
|
|
|
105
105
|
_proto.getWebsocket = function getWebsocket() {
|
|
@@ -110,8 +110,8 @@ var LoadingBar = /*#__PURE__*/function (_PureComponent) {
|
|
|
110
110
|
_proto.showBar = function showBar() {
|
|
111
111
|
var _this3 = this;
|
|
112
112
|
|
|
113
|
-
clearTimeout(this.fadeOffTimeout);
|
|
114
|
-
clearTimeout(this.resetTimeout);
|
|
113
|
+
if (this.fadeOffTimeout) clearTimeout(this.fadeOffTimeout);
|
|
114
|
+
if (this.resetTimeout) clearTimeout(this.resetTimeout);
|
|
115
115
|
this.first20Timeout = setTimeout(function () {
|
|
116
116
|
_this3.setState({
|
|
117
117
|
progress: 20
|
|
@@ -130,8 +130,8 @@ var LoadingBar = /*#__PURE__*/function (_PureComponent) {
|
|
|
130
130
|
_proto.hideBar = function hideBar() {
|
|
131
131
|
var _this4 = this;
|
|
132
132
|
|
|
133
|
-
clearTimeout(this.first20Timeout);
|
|
134
|
-
clearInterval(this.progressTimer);
|
|
133
|
+
if (this.first20Timeout) clearTimeout(this.first20Timeout);
|
|
134
|
+
if (this.progressTimer) clearInterval(this.progressTimer);
|
|
135
135
|
this.fadeOffTimeout = setTimeout(function () {
|
|
136
136
|
_this4.setState({
|
|
137
137
|
progress: 100
|
|
@@ -167,5 +167,5 @@ var LoadingBar = /*#__PURE__*/function (_PureComponent) {
|
|
|
167
167
|
|
|
168
168
|
LoadingBar.contextType = ReactAlpContext;
|
|
169
169
|
|
|
170
|
-
export default
|
|
170
|
+
export { LoadingBar as default };
|
|
171
171
|
//# sourceMappingURL=index-browser.es.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index-browser.es.js","sources":["../src/index.tsx"],"sourcesContent":["import type { ReactElement } from 'react';\nimport React, { PureComponent } from 'react';\nimport ReactAlpContext from 'react-alp-context';\n\n/*\nExample with antd:\nimport { Progress } from 'antd';\n\nconst LoadingBarComponent = ({ progress }) => (\n <Progress\n type=\"line\"\n status=\"active\"\n percent={progress}\n showInfo={false}\n />\n);\n*/\n\n/* number between 0 and 1 */\nconst random = (): number => Math.ceil(Math.random() * 100) / 100;\n\n/**\n * around:\n * at 100ms 20%\n * at 1s 40%\n * at 2s 60%\n * at 3s 80%\n */\nconst calculatePercent = (percent: number): number => {\n if (percent < 60) return percent + random() * 10 + 5;\n if (percent < 70) return percent + random() * 10 + 3;\n else if (percent < 80) return percent + random() + 5;\n else if (percent < 90) return percent + random() + 1;\n else if (percent < 95) return percent + 0.1;\n else return percent;\n};\n\ninterface LoadingBarProps {\n LoadingBarComponent: React.ComponentType<{ progress: number }>;\n}\n\ninterface LoadingBarState {\n loading: boolean;\n hidden: boolean;\n progress: number;\n}\n\ninterface WebsocketInterface {\n isConnected: () => boolean;\n on: (event: 'connect' | 'disconnect', callback: () => unknown) => void;\n}\n\nexport default class LoadingBar extends PureComponent<\n LoadingBarProps,\n LoadingBarState\n> {\n static contextType = ReactAlpContext;\n\n
|
|
1
|
+
{"version":3,"file":"index-browser.es.js","sources":["../src/index.tsx"],"sourcesContent":["import type { ReactElement } from 'react';\nimport React, { PureComponent } from 'react';\nimport ReactAlpContext from 'react-alp-context';\n\n/*\nExample with antd:\nimport { Progress } from 'antd';\n\nconst LoadingBarComponent = ({ progress }) => (\n <Progress\n type=\"line\"\n status=\"active\"\n percent={progress}\n showInfo={false}\n />\n);\n*/\n\n/* number between 0 and 1 */\nconst random = (): number => Math.ceil(Math.random() * 100) / 100;\n\n/**\n * around:\n * at 100ms 20%\n * at 1s 40%\n * at 2s 60%\n * at 3s 80%\n */\nconst calculatePercent = (percent: number): number => {\n if (percent < 60) return percent + random() * 10 + 5;\n if (percent < 70) return percent + random() * 10 + 3;\n else if (percent < 80) return percent + random() + 5;\n else if (percent < 90) return percent + random() + 1;\n else if (percent < 95) return percent + 0.1;\n else return percent;\n};\n\ninterface LoadingBarProps {\n LoadingBarComponent: React.ComponentType<{ progress: number }>;\n}\n\ninterface LoadingBarState {\n loading: boolean;\n hidden: boolean;\n progress: number;\n}\n\ninterface WebsocketInterface {\n isConnected: () => boolean;\n on: (event: 'connect' | 'disconnect', callback: () => unknown) => void;\n}\n\nexport default class LoadingBar extends PureComponent<\n LoadingBarProps,\n LoadingBarState\n> {\n static contextType = ReactAlpContext;\n\n state = {\n loading: true,\n hidden: true,\n progress: 1,\n };\n\n fadeOffTimeout?: ReturnType<typeof setTimeout>;\n\n resetTimeout?: ReturnType<typeof setTimeout>;\n\n first20Timeout?: ReturnType<typeof setTimeout>;\n\n progressTimer?: ReturnType<typeof setTimeout>;\n\n componentDidMount(): void {\n const websocket = this.getWebsocket();\n if (websocket.isConnected()) {\n this.setState((prevState) => ({\n loading: false,\n progress: 100,\n hidden: prevState.hidden || prevState.progress === 100,\n }));\n }\n websocket.on('connect', () => {\n this.setState({ loading: false });\n });\n websocket.on('disconnect', () => {\n this.setState({ loading: true, progress: 1, hidden: false });\n });\n }\n\n componentDidUpdate(\n prevProps: LoadingBarProps,\n prevState: LoadingBarState,\n ): void {\n if (this.state.loading !== prevState.loading) {\n if (this.state.loading) {\n this.showBar();\n } else {\n this.hideBar();\n }\n }\n }\n\n componentWillUnmount(): void {\n if (this.fadeOffTimeout) clearTimeout(this.fadeOffTimeout);\n if (this.resetTimeout) clearTimeout(this.resetTimeout);\n if (this.first20Timeout) clearTimeout(this.first20Timeout);\n if (this.progressTimer) clearInterval(this.progressTimer);\n }\n\n getWebsocket(): WebsocketInterface {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-return\n return this.context.app.websocket;\n }\n\n private showBar(): void {\n if (this.fadeOffTimeout) clearTimeout(this.fadeOffTimeout);\n if (this.resetTimeout) clearTimeout(this.resetTimeout);\n\n this.first20Timeout = setTimeout(() => {\n this.setState({ progress: 20 });\n }, 100);\n\n this.progressTimer = setInterval(() => {\n this.setState((prevState) => {\n const newValue = calculatePercent(prevState.progress);\n return { progress: newValue };\n });\n }, 500);\n }\n\n private hideBar(): void {\n if (this.first20Timeout) clearTimeout(this.first20Timeout);\n if (this.progressTimer) clearInterval(this.progressTimer);\n\n this.fadeOffTimeout = setTimeout(() => {\n this.setState({\n progress: 100,\n });\n }, 500);\n\n this.resetTimeout = setTimeout(() => {\n this.setState({\n hidden: true,\n progress: 1,\n });\n }, 1000);\n }\n\n render(): ReactElement {\n const LoadingBarComponent = this.props.LoadingBarComponent;\n\n return (\n <div\n hidden={this.state.hidden}\n style={{\n position: 'fixed',\n top: 0,\n left: 0,\n right: 0,\n zIndex: 4,\n pointerEvents: 'none',\n }}\n >\n <LoadingBarComponent progress={this.state.progress} />\n </div>\n );\n }\n}\n"],"names":["random","Math","ceil","calculatePercent","percent","LoadingBar","state","loading","hidden","progress","componentDidMount","websocket","getWebsocket","isConnected","setState","prevState","on","componentDidUpdate","prevProps","showBar","hideBar","componentWillUnmount","fadeOffTimeout","clearTimeout","resetTimeout","first20Timeout","progressTimer","clearInterval","context","app","setTimeout","setInterval","newValue","render","LoadingBarComponent","props","position","top","left","right","zIndex","pointerEvents","PureComponent","contextType","ReactAlpContext"],"mappings":";;;;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AACA,IAAMA,MAAM,GAAG,SAATA,MAAS;AAAA,SAAcC,IAAI,CAACC,IAAL,CAAUD,IAAI,CAACD,MAAL,KAAgB,GAA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C;;;;"}
|
|
@@ -33,14 +33,12 @@ const calculatePercent = percent => {
|
|
|
33
33
|
};
|
|
34
34
|
|
|
35
35
|
class LoadingBar extends PureComponent {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
};
|
|
43
|
-
}
|
|
36
|
+
static contextType = ReactAlpContext;
|
|
37
|
+
state = {
|
|
38
|
+
loading: true,
|
|
39
|
+
hidden: true,
|
|
40
|
+
progress: 1
|
|
41
|
+
};
|
|
44
42
|
|
|
45
43
|
componentDidMount() {
|
|
46
44
|
const websocket = this.getWebsocket();
|
|
@@ -78,10 +76,10 @@ class LoadingBar extends PureComponent {
|
|
|
78
76
|
}
|
|
79
77
|
|
|
80
78
|
componentWillUnmount() {
|
|
81
|
-
clearTimeout(this.fadeOffTimeout);
|
|
82
|
-
clearTimeout(this.resetTimeout);
|
|
83
|
-
clearTimeout(this.first20Timeout);
|
|
84
|
-
clearInterval(this.progressTimer);
|
|
79
|
+
if (this.fadeOffTimeout) clearTimeout(this.fadeOffTimeout);
|
|
80
|
+
if (this.resetTimeout) clearTimeout(this.resetTimeout);
|
|
81
|
+
if (this.first20Timeout) clearTimeout(this.first20Timeout);
|
|
82
|
+
if (this.progressTimer) clearInterval(this.progressTimer);
|
|
85
83
|
}
|
|
86
84
|
|
|
87
85
|
getWebsocket() {
|
|
@@ -90,8 +88,8 @@ class LoadingBar extends PureComponent {
|
|
|
90
88
|
}
|
|
91
89
|
|
|
92
90
|
showBar() {
|
|
93
|
-
clearTimeout(this.fadeOffTimeout);
|
|
94
|
-
clearTimeout(this.resetTimeout);
|
|
91
|
+
if (this.fadeOffTimeout) clearTimeout(this.fadeOffTimeout);
|
|
92
|
+
if (this.resetTimeout) clearTimeout(this.resetTimeout);
|
|
95
93
|
this.first20Timeout = setTimeout(() => {
|
|
96
94
|
this.setState({
|
|
97
95
|
progress: 20
|
|
@@ -108,8 +106,8 @@ class LoadingBar extends PureComponent {
|
|
|
108
106
|
}
|
|
109
107
|
|
|
110
108
|
hideBar() {
|
|
111
|
-
clearTimeout(this.first20Timeout);
|
|
112
|
-
clearInterval(this.progressTimer);
|
|
109
|
+
if (this.first20Timeout) clearTimeout(this.first20Timeout);
|
|
110
|
+
if (this.progressTimer) clearInterval(this.progressTimer);
|
|
113
111
|
this.fadeOffTimeout = setTimeout(() => {
|
|
114
112
|
this.setState({
|
|
115
113
|
progress: 100
|
|
@@ -141,7 +139,6 @@ class LoadingBar extends PureComponent {
|
|
|
141
139
|
}
|
|
142
140
|
|
|
143
141
|
}
|
|
144
|
-
LoadingBar.contextType = ReactAlpContext;
|
|
145
142
|
|
|
146
|
-
export default
|
|
143
|
+
export { LoadingBar as default };
|
|
147
144
|
//# sourceMappingURL=index-browsermodern.es.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index-browsermodern.es.js","sources":["../src/index.tsx"],"sourcesContent":["import type { ReactElement } from 'react';\nimport React, { PureComponent } from 'react';\nimport ReactAlpContext from 'react-alp-context';\n\n/*\nExample with antd:\nimport { Progress } from 'antd';\n\nconst LoadingBarComponent = ({ progress }) => (\n <Progress\n type=\"line\"\n status=\"active\"\n percent={progress}\n showInfo={false}\n />\n);\n*/\n\n/* number between 0 and 1 */\nconst random = (): number => Math.ceil(Math.random() * 100) / 100;\n\n/**\n * around:\n * at 100ms 20%\n * at 1s 40%\n * at 2s 60%\n * at 3s 80%\n */\nconst calculatePercent = (percent: number): number => {\n if (percent < 60) return percent + random() * 10 + 5;\n if (percent < 70) return percent + random() * 10 + 3;\n else if (percent < 80) return percent + random() + 5;\n else if (percent < 90) return percent + random() + 1;\n else if (percent < 95) return percent + 0.1;\n else return percent;\n};\n\ninterface LoadingBarProps {\n LoadingBarComponent: React.ComponentType<{ progress: number }>;\n}\n\ninterface LoadingBarState {\n loading: boolean;\n hidden: boolean;\n progress: number;\n}\n\ninterface WebsocketInterface {\n isConnected: () => boolean;\n on: (event: 'connect' | 'disconnect', callback: () => unknown) => void;\n}\n\nexport default class LoadingBar extends PureComponent<\n LoadingBarProps,\n LoadingBarState\n> {\n static contextType = ReactAlpContext;\n\n
|
|
1
|
+
{"version":3,"file":"index-browsermodern.es.js","sources":["../src/index.tsx"],"sourcesContent":["import type { ReactElement } from 'react';\nimport React, { PureComponent } from 'react';\nimport ReactAlpContext from 'react-alp-context';\n\n/*\nExample with antd:\nimport { Progress } from 'antd';\n\nconst LoadingBarComponent = ({ progress }) => (\n <Progress\n type=\"line\"\n status=\"active\"\n percent={progress}\n showInfo={false}\n />\n);\n*/\n\n/* number between 0 and 1 */\nconst random = (): number => Math.ceil(Math.random() * 100) / 100;\n\n/**\n * around:\n * at 100ms 20%\n * at 1s 40%\n * at 2s 60%\n * at 3s 80%\n */\nconst calculatePercent = (percent: number): number => {\n if (percent < 60) return percent + random() * 10 + 5;\n if (percent < 70) return percent + random() * 10 + 3;\n else if (percent < 80) return percent + random() + 5;\n else if (percent < 90) return percent + random() + 1;\n else if (percent < 95) return percent + 0.1;\n else return percent;\n};\n\ninterface LoadingBarProps {\n LoadingBarComponent: React.ComponentType<{ progress: number }>;\n}\n\ninterface LoadingBarState {\n loading: boolean;\n hidden: boolean;\n progress: number;\n}\n\ninterface WebsocketInterface {\n isConnected: () => boolean;\n on: (event: 'connect' | 'disconnect', callback: () => unknown) => void;\n}\n\nexport default class LoadingBar extends PureComponent<\n LoadingBarProps,\n LoadingBarState\n> {\n static contextType = ReactAlpContext;\n\n state = {\n loading: true,\n hidden: true,\n progress: 1,\n };\n\n fadeOffTimeout?: ReturnType<typeof setTimeout>;\n\n resetTimeout?: ReturnType<typeof setTimeout>;\n\n first20Timeout?: ReturnType<typeof setTimeout>;\n\n progressTimer?: ReturnType<typeof setTimeout>;\n\n componentDidMount(): void {\n const websocket = this.getWebsocket();\n if (websocket.isConnected()) {\n this.setState((prevState) => ({\n loading: false,\n progress: 100,\n hidden: prevState.hidden || prevState.progress === 100,\n }));\n }\n websocket.on('connect', () => {\n this.setState({ loading: false });\n });\n websocket.on('disconnect', () => {\n this.setState({ loading: true, progress: 1, hidden: false });\n });\n }\n\n componentDidUpdate(\n prevProps: LoadingBarProps,\n prevState: LoadingBarState,\n ): void {\n if (this.state.loading !== prevState.loading) {\n if (this.state.loading) {\n this.showBar();\n } else {\n this.hideBar();\n }\n }\n }\n\n componentWillUnmount(): void {\n if (this.fadeOffTimeout) clearTimeout(this.fadeOffTimeout);\n if (this.resetTimeout) clearTimeout(this.resetTimeout);\n if (this.first20Timeout) clearTimeout(this.first20Timeout);\n if (this.progressTimer) clearInterval(this.progressTimer);\n }\n\n getWebsocket(): WebsocketInterface {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-return\n return this.context.app.websocket;\n }\n\n private showBar(): void {\n if (this.fadeOffTimeout) clearTimeout(this.fadeOffTimeout);\n if (this.resetTimeout) clearTimeout(this.resetTimeout);\n\n this.first20Timeout = setTimeout(() => {\n this.setState({ progress: 20 });\n }, 100);\n\n this.progressTimer = setInterval(() => {\n this.setState((prevState) => {\n const newValue = calculatePercent(prevState.progress);\n return { progress: newValue };\n });\n }, 500);\n }\n\n private hideBar(): void {\n if (this.first20Timeout) clearTimeout(this.first20Timeout);\n if (this.progressTimer) clearInterval(this.progressTimer);\n\n this.fadeOffTimeout = setTimeout(() => {\n this.setState({\n progress: 100,\n });\n }, 500);\n\n this.resetTimeout = setTimeout(() => {\n this.setState({\n hidden: true,\n progress: 1,\n });\n }, 1000);\n }\n\n render(): ReactElement {\n const LoadingBarComponent = this.props.LoadingBarComponent;\n\n return (\n <div\n hidden={this.state.hidden}\n style={{\n position: 'fixed',\n top: 0,\n left: 0,\n right: 0,\n zIndex: 4,\n pointerEvents: 'none',\n }}\n >\n <LoadingBarComponent progress={this.state.progress} />\n </div>\n );\n }\n}\n"],"names":["random","Math","ceil","calculatePercent","percent","LoadingBar","PureComponent","contextType","ReactAlpContext","state","loading","hidden","progress","componentDidMount","websocket","getWebsocket","isConnected","setState","prevState","on","componentDidUpdate","prevProps","showBar","hideBar","componentWillUnmount","fadeOffTimeout","clearTimeout","resetTimeout","first20Timeout","progressTimer","clearInterval","context","app","setTimeout","setInterval","newValue","render","LoadingBarComponent","props","position","top","left","right","zIndex","pointerEvents"],"mappings":";;;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AACA,MAAMA,MAAM,GAAG,MAAcC,IAAI,CAACC,IAAL,CAAUD,IAAI,CAACD,MAAL,KAAgB,GAA1B,IAAiC,GAA9D;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,MAAMG,gBAAgB,GAAIC,OAAD,IAA6B;AACpD,MAAIA,OAAO,GAAG,EAAd,EAAkB,OAAOA,OAAO,GAAGJ,MAAM,KAAK,EAArB,GAA0B,CAAjC;AAClB,MAAII,OAAO,GAAG,EAAd,EAAkB,OAAOA,OAAO,GAAGJ,MAAM,KAAK,EAArB,GAA0B,CAAjC,CAAlB,KACK,IAAII,OAAO,GAAG,EAAd,EAAkB,OAAOA,OAAO,GAAGJ,MAAM,EAAhB,GAAqB,CAA5B,CAAlB,KACA,IAAII,OAAO,GAAG,EAAd,EAAkB,OAAOA,OAAO,GAAGJ,MAAM,EAAhB,GAAqB,CAA5B,CAAlB,KACA,IAAII,OAAO,GAAG,EAAd,EAAkB,OAAOA,OAAO,GAAG,GAAjB,CAAlB,KACA,OAAOA,OAAP;AACN,CAPD;;AAwBe,MAAMC,UAAN,SAAyBC,aAAzB,CAGb;AACkB,SAAXC,WAAW,GAAGC,eAAH;AAElBC,EAAAA,KAAK,GAAG;AACNC,IAAAA,OAAO,EAAE,IADH;AAENC,IAAAA,MAAM,EAAE,IAFF;AAGNC,IAAAA,QAAQ,EAAE;AAHJ,GAAH;;AAcLC,EAAAA,iBAAiB,GAAS;AACxB,UAAMC,SAAS,GAAG,KAAKC,YAAL,EAAlB;;AACA,QAAID,SAAS,CAACE,WAAV,EAAJ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AAQ,EAAE,OADL;AAELC,QAAAA,GAAG,EAAE,CAFA;AAGLC,QAAAA,IAAI,EAAE,CAHD;AAILC,QAAAA,KAAK,EAAE,CAJF;AAKLC,QAAAA,MAAM,EAAE,CALH;AAMLC,QAAAA,aAAa,EAAE;AANV;AAFT,oBAWE,oBAAC,mBAAD;AAAqB,MAAA,QAAQ,EAAE,KAAKnC,KAAL,CAAWG;AAA1C,MAXF,CADF;AAeD;;AA/GD;;;;"}
|
|
@@ -33,14 +33,12 @@ const calculatePercent = percent => {
|
|
|
33
33
|
};
|
|
34
34
|
|
|
35
35
|
class LoadingBar extends PureComponent {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
};
|
|
43
|
-
}
|
|
36
|
+
static contextType = ReactAlpContext;
|
|
37
|
+
state = {
|
|
38
|
+
loading: true,
|
|
39
|
+
hidden: true,
|
|
40
|
+
progress: 1
|
|
41
|
+
};
|
|
44
42
|
|
|
45
43
|
componentDidMount() {
|
|
46
44
|
const websocket = this.getWebsocket();
|
|
@@ -78,10 +76,10 @@ class LoadingBar extends PureComponent {
|
|
|
78
76
|
}
|
|
79
77
|
|
|
80
78
|
componentWillUnmount() {
|
|
81
|
-
clearTimeout(this.fadeOffTimeout);
|
|
82
|
-
clearTimeout(this.resetTimeout);
|
|
83
|
-
clearTimeout(this.first20Timeout);
|
|
84
|
-
clearInterval(this.progressTimer);
|
|
79
|
+
if (this.fadeOffTimeout) clearTimeout(this.fadeOffTimeout);
|
|
80
|
+
if (this.resetTimeout) clearTimeout(this.resetTimeout);
|
|
81
|
+
if (this.first20Timeout) clearTimeout(this.first20Timeout);
|
|
82
|
+
if (this.progressTimer) clearInterval(this.progressTimer);
|
|
85
83
|
}
|
|
86
84
|
|
|
87
85
|
getWebsocket() {
|
|
@@ -90,8 +88,8 @@ class LoadingBar extends PureComponent {
|
|
|
90
88
|
}
|
|
91
89
|
|
|
92
90
|
showBar() {
|
|
93
|
-
clearTimeout(this.fadeOffTimeout);
|
|
94
|
-
clearTimeout(this.resetTimeout);
|
|
91
|
+
if (this.fadeOffTimeout) clearTimeout(this.fadeOffTimeout);
|
|
92
|
+
if (this.resetTimeout) clearTimeout(this.resetTimeout);
|
|
95
93
|
this.first20Timeout = setTimeout(() => {
|
|
96
94
|
this.setState({
|
|
97
95
|
progress: 20
|
|
@@ -108,8 +106,8 @@ class LoadingBar extends PureComponent {
|
|
|
108
106
|
}
|
|
109
107
|
|
|
110
108
|
hideBar() {
|
|
111
|
-
clearTimeout(this.first20Timeout);
|
|
112
|
-
clearInterval(this.progressTimer);
|
|
109
|
+
if (this.first20Timeout) clearTimeout(this.first20Timeout);
|
|
110
|
+
if (this.progressTimer) clearInterval(this.progressTimer);
|
|
113
111
|
this.fadeOffTimeout = setTimeout(() => {
|
|
114
112
|
this.setState({
|
|
115
113
|
progress: 100
|
|
@@ -141,7 +139,6 @@ class LoadingBar extends PureComponent {
|
|
|
141
139
|
}
|
|
142
140
|
|
|
143
141
|
}
|
|
144
|
-
LoadingBar.contextType = ReactAlpContext;
|
|
145
142
|
|
|
146
|
-
export default
|
|
147
|
-
//# sourceMappingURL=index-
|
|
143
|
+
export { LoadingBar as default };
|
|
144
|
+
//# sourceMappingURL=index-node14.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index-node14.mjs","sources":["../src/index.tsx"],"sourcesContent":["import type { ReactElement } from 'react';\nimport React, { PureComponent } from 'react';\nimport ReactAlpContext from 'react-alp-context';\n\n/*\nExample with antd:\nimport { Progress } from 'antd';\n\nconst LoadingBarComponent = ({ progress }) => (\n <Progress\n type=\"line\"\n status=\"active\"\n percent={progress}\n showInfo={false}\n />\n);\n*/\n\n/* number between 0 and 1 */\nconst random = (): number => Math.ceil(Math.random() * 100) / 100;\n\n/**\n * around:\n * at 100ms 20%\n * at 1s 40%\n * at 2s 60%\n * at 3s 80%\n */\nconst calculatePercent = (percent: number): number => {\n if (percent < 60) return percent + random() * 10 + 5;\n if (percent < 70) return percent + random() * 10 + 3;\n else if (percent < 80) return percent + random() + 5;\n else if (percent < 90) return percent + random() + 1;\n else if (percent < 95) return percent + 0.1;\n else return percent;\n};\n\ninterface LoadingBarProps {\n LoadingBarComponent: React.ComponentType<{ progress: number }>;\n}\n\ninterface LoadingBarState {\n loading: boolean;\n hidden: boolean;\n progress: number;\n}\n\ninterface WebsocketInterface {\n isConnected: () => boolean;\n on: (event: 'connect' | 'disconnect', callback: () => unknown) => void;\n}\n\nexport default class LoadingBar extends PureComponent<\n LoadingBarProps,\n LoadingBarState\n> {\n static contextType = ReactAlpContext;\n\n state = {\n loading: true,\n hidden: true,\n progress: 1,\n };\n\n fadeOffTimeout?: ReturnType<typeof setTimeout>;\n\n resetTimeout?: ReturnType<typeof setTimeout>;\n\n first20Timeout?: ReturnType<typeof setTimeout>;\n\n progressTimer?: ReturnType<typeof setTimeout>;\n\n componentDidMount(): void {\n const websocket = this.getWebsocket();\n if (websocket.isConnected()) {\n this.setState((prevState) => ({\n loading: false,\n progress: 100,\n hidden: prevState.hidden || prevState.progress === 100,\n }));\n }\n websocket.on('connect', () => {\n this.setState({ loading: false });\n });\n websocket.on('disconnect', () => {\n this.setState({ loading: true, progress: 1, hidden: false });\n });\n }\n\n componentDidUpdate(\n prevProps: LoadingBarProps,\n prevState: LoadingBarState,\n ): void {\n if (this.state.loading !== prevState.loading) {\n if (this.state.loading) {\n this.showBar();\n } else {\n this.hideBar();\n }\n }\n }\n\n componentWillUnmount(): void {\n if (this.fadeOffTimeout) clearTimeout(this.fadeOffTimeout);\n if (this.resetTimeout) clearTimeout(this.resetTimeout);\n if (this.first20Timeout) clearTimeout(this.first20Timeout);\n if (this.progressTimer) clearInterval(this.progressTimer);\n }\n\n getWebsocket(): WebsocketInterface {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-return\n return this.context.app.websocket;\n }\n\n private showBar(): void {\n if (this.fadeOffTimeout) clearTimeout(this.fadeOffTimeout);\n if (this.resetTimeout) clearTimeout(this.resetTimeout);\n\n this.first20Timeout = setTimeout(() => {\n this.setState({ progress: 20 });\n }, 100);\n\n this.progressTimer = setInterval(() => {\n this.setState((prevState) => {\n const newValue = calculatePercent(prevState.progress);\n return { progress: newValue };\n });\n }, 500);\n }\n\n private hideBar(): void {\n if (this.first20Timeout) clearTimeout(this.first20Timeout);\n if (this.progressTimer) clearInterval(this.progressTimer);\n\n this.fadeOffTimeout = setTimeout(() => {\n this.setState({\n progress: 100,\n });\n }, 500);\n\n this.resetTimeout = setTimeout(() => {\n this.setState({\n hidden: true,\n progress: 1,\n });\n }, 1000);\n }\n\n render(): ReactElement {\n const LoadingBarComponent = this.props.LoadingBarComponent;\n\n return (\n <div\n hidden={this.state.hidden}\n style={{\n position: 'fixed',\n top: 0,\n left: 0,\n right: 0,\n zIndex: 4,\n pointerEvents: 'none',\n }}\n >\n <LoadingBarComponent progress={this.state.progress} />\n </div>\n );\n }\n}\n"],"names":["random","Math","ceil","calculatePercent","percent","LoadingBar","PureComponent","contextType","ReactAlpContext","state","loading","hidden","progress","componentDidMount","websocket","getWebsocket","isConnected","setState","prevState","on","componentDidUpdate","prevProps","showBar","hideBar","componentWillUnmount","fadeOffTimeout","clearTimeout","resetTimeout","first20Timeout","progressTimer","clearInterval","context","app","setTimeout","setInterval","newValue","render","LoadingBarComponent","props","position","top","left","right","zIndex","pointerEvents"],"mappings":";;;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AACA,MAAMA,MAAM,GAAG,MAAcC,IAAI,CAACC,IAAL,CAAUD,IAAI,CAACD,MAAL,KAAgB,GAA1B,IAAiC,GAA9D;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,MAAMG,gBAAgB,GAAIC,OAAD,IAA6B;AACpD,MAAIA,OAAO,GAAG,EAAd,EAAkB,OAAOA,OAAO,GAAGJ,MAAM,KAAK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;AAID,KAL+B,EAK7B,GAL6B,CAAhC;AAMD;;AAEOZ,EAAAA,OAAO,GAAS;AACtB,QAAI,KAAKK,cAAT,EAAyBF,YAAY,CAAC,KAAKE,cAAN,CAAZ;AACzB,QAAI,KAAKC,aAAT,EAAwBC,aAAa,CAAC,KAAKD,aAAN,CAAb;AAExB,SAAKJ,cAAL,GAAsBQ,UAAU,CAAC,MAAM;AACrC,WAAKhB,QAAL,CAAc;AACZL,QAAAA,QAAQ,EAAE;AADE,OAAd;AAGD,KAJ+B,EAI7B,GAJ6B,CAAhC;AAMA,SAAKe,YAAL,GAAoBM,UAAU,CAAC,MAAM;AACnC,WAAKhB,QAAL,CAAc;AACZN,QAAAA,MAAM,EAAE,IADI;AAEZC,QAAAA,QAAQ,EAAE;AAFE,OAAd;AAID,KAL6B,EAK3B,IAL2B,CAA9B;AAMD;;AAEDwB,EAAAA,MAAM,GAAiB;AACrB,UAAMC,mBAAmB,GAAG,KAAKC,KAAL,CAAWD,mBAAvC;AAEA,wBACE;AACE,MAAA,MAAM,EAAE,KAAK5B,KAAL,CAAWE,MADrB;AAEE,MAAA,KAAK,EAAE;AACL4B,QAAAA,QAAQ,EAAE,OADL;AAELC,QAAAA,GAAG,EAAE,CAFA;AAGLC,QAAAA,IAAI,EAAE,CAHD;AAILC,QAAAA,KAAK,EAAE,CAJF;AAKLC,QAAAA,MAAM,EAAE,CALH;AAMLC,QAAAA,aAAa,EAAE;AANV;AAFT,oBAWE,oBAAC,mBAAD;AAAqB,MAAA,QAAQ,EAAE,KAAKnC,KAAL,CAAWG;AAA1C,MAXF,CADF;AAeD;;AA/GD;;;;"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { ReactElement } from 'react';
|
|
2
2
|
import React, { PureComponent } from 'react';
|
|
3
|
-
import ReactAlpContext from 'react-alp-context';
|
|
4
3
|
interface LoadingBarProps {
|
|
5
4
|
LoadingBarComponent: React.ComponentType<{
|
|
6
5
|
progress: number;
|
|
@@ -17,16 +16,15 @@ interface WebsocketInterface {
|
|
|
17
16
|
}
|
|
18
17
|
export default class LoadingBar extends PureComponent<LoadingBarProps, LoadingBarState> {
|
|
19
18
|
static contextType: React.Context<import("alp-types").Context>;
|
|
20
|
-
context: React.ContextType<typeof ReactAlpContext>;
|
|
21
19
|
state: {
|
|
22
20
|
loading: boolean;
|
|
23
21
|
hidden: boolean;
|
|
24
22
|
progress: number;
|
|
25
23
|
};
|
|
26
|
-
fadeOffTimeout?:
|
|
27
|
-
resetTimeout?:
|
|
28
|
-
first20Timeout?:
|
|
29
|
-
progressTimer?:
|
|
24
|
+
fadeOffTimeout?: ReturnType<typeof setTimeout>;
|
|
25
|
+
resetTimeout?: ReturnType<typeof setTimeout>;
|
|
26
|
+
first20Timeout?: ReturnType<typeof setTimeout>;
|
|
27
|
+
progressTimer?: ReturnType<typeof setTimeout>;
|
|
30
28
|
componentDidMount(): void;
|
|
31
29
|
componentDidUpdate(prevProps: LoadingBarProps, prevState: LoadingBarState): void;
|
|
32
30
|
componentWillUnmount(): void;
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAC1C,OAAO,KAAK,EAAE,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAC1C,OAAO,KAAK,EAAE,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAoC7C,UAAU,eAAe;IACvB,mBAAmB,EAAE,KAAK,CAAC,aAAa,CAAC;QAAE,QAAQ,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CAChE;AAED,UAAU,eAAe;IACvB,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,OAAO,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,UAAU,kBAAkB;IAC1B,WAAW,EAAE,MAAM,OAAO,CAAC;IAC3B,EAAE,EAAE,CAAC,KAAK,EAAE,SAAS,GAAG,YAAY,EAAE,QAAQ,EAAE,MAAM,OAAO,KAAK,IAAI,CAAC;CACxE;AAED,MAAM,CAAC,OAAO,OAAO,UAAW,SAAQ,aAAa,CACnD,eAAe,EACf,eAAe,CAChB;IACC,MAAM,CAAC,WAAW,6CAAmB;IAErC,KAAK;;;;MAIH;IAEF,cAAc,CAAC,EAAE,UAAU,CAAC,OAAO,UAAU,CAAC,CAAC;IAE/C,YAAY,CAAC,EAAE,UAAU,CAAC,OAAO,UAAU,CAAC,CAAC;IAE7C,cAAc,CAAC,EAAE,UAAU,CAAC,OAAO,UAAU,CAAC,CAAC;IAE/C,aAAa,CAAC,EAAE,UAAU,CAAC,OAAO,UAAU,CAAC,CAAC;IAE9C,iBAAiB,IAAI,IAAI;IAiBzB,kBAAkB,CAChB,SAAS,EAAE,eAAe,EAC1B,SAAS,EAAE,eAAe,GACzB,IAAI;IAUP,oBAAoB,IAAI,IAAI;IAO5B,YAAY,IAAI,kBAAkB;IAKlC,OAAO,CAAC,OAAO;IAgBf,OAAO,CAAC,OAAO;IAkBf,MAAM,IAAI,YAAY;CAmBvB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-alp-loading-bar",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.1",
|
|
4
4
|
"description": "loading bar",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"author": "Christophe Hurpeau <christophe@hurpeau.com> (https://christophe.hurpeau.com)",
|
|
@@ -11,64 +11,44 @@
|
|
|
11
11
|
"directory": "packages/react-alp-loading-bar"
|
|
12
12
|
},
|
|
13
13
|
"homepage": "https://github.com/christophehurpeau/alp",
|
|
14
|
+
"type": "module",
|
|
14
15
|
"engines": {
|
|
15
|
-
"node": ">=
|
|
16
|
+
"node": "^14.13.1 || >=16.0.0"
|
|
16
17
|
},
|
|
17
18
|
"browserslist": [
|
|
19
|
+
"defaults",
|
|
18
20
|
"> 0.2%",
|
|
19
|
-
"Firefox ESR",
|
|
20
|
-
"last 2 Chrome versions",
|
|
21
|
-
"last 2 iOS versions",
|
|
22
|
-
"last 2 Edge versions",
|
|
23
|
-
"last 2 Safari versions",
|
|
24
21
|
"not ie < 12",
|
|
25
|
-
"not
|
|
26
|
-
"not
|
|
27
|
-
"not op_mini all"
|
|
22
|
+
"not safari < 10",
|
|
23
|
+
"not ios_saf < 10"
|
|
28
24
|
],
|
|
29
|
-
"main": "./index.
|
|
25
|
+
"main": "./dist/index-node14.mjs",
|
|
30
26
|
"types": "./dist/index.d.ts",
|
|
31
27
|
"module": "./dist/index-browser.es.js",
|
|
32
28
|
"browser": "./dist/index-browser.es.js",
|
|
33
29
|
"exports": {
|
|
30
|
+
"./package.json": "./package.json",
|
|
34
31
|
".": {
|
|
35
32
|
"node": {
|
|
36
|
-
"
|
|
37
|
-
"import": "./dist/index-node12-dev.mjs",
|
|
38
|
-
"require": "./dist/index-node12-dev.cjs.js"
|
|
39
|
-
},
|
|
40
|
-
"import": "./dist/index-node12.mjs",
|
|
41
|
-
"require": "./dist/index-node12.cjs.js"
|
|
33
|
+
"import": "./dist/index-node14.mjs"
|
|
42
34
|
},
|
|
43
35
|
"browser": {
|
|
44
36
|
"browser:modern": {
|
|
45
|
-
"development": {
|
|
46
|
-
"import": "./dist/index-browsermodern-dev.es.js"
|
|
47
|
-
},
|
|
48
37
|
"import": "./dist/index-browsermodern.es.js"
|
|
49
38
|
},
|
|
50
|
-
"
|
|
51
|
-
"import": "./dist/index-browser-dev.es.js",
|
|
52
|
-
"require": "./dist/index-browser-dev.cjs.js"
|
|
53
|
-
},
|
|
54
|
-
"import": "./dist/index-browser.es.js",
|
|
55
|
-
"require": "./dist/index-browser.cjs.js"
|
|
39
|
+
"import": "./dist/index-browser.es.js"
|
|
56
40
|
}
|
|
57
41
|
}
|
|
58
42
|
},
|
|
59
|
-
"module:node": "./dist/index-
|
|
60
|
-
"module:node-dev": "./dist/index-node12-dev.mjs",
|
|
61
|
-
"module:browser": "./dist/index-browser.es.js",
|
|
62
|
-
"module:browser-dev": "./dist/index-browser-dev.es.js",
|
|
43
|
+
"module:node": "./dist/index-node14.mjs",
|
|
63
44
|
"module:modern-browsers": "./dist/index-browsermodern.es.js",
|
|
64
|
-
"module:modern-browsers-dev": "./dist/index-browsermodern-dev.es.js",
|
|
65
45
|
"sideEffects": false,
|
|
66
46
|
"scripts": {
|
|
67
47
|
"build": "pob-build && yarn run build:definitions",
|
|
68
48
|
"build:definitions": "tsc -p tsconfig.build.json",
|
|
69
|
-
"clean": "rm -Rf
|
|
49
|
+
"clean": "rm -Rf dist",
|
|
70
50
|
"lint": "yarn run lint:eslint",
|
|
71
|
-
"lint:eslint": "
|
|
51
|
+
"lint:eslint": "cd ../.. && yarn run eslint --report-unused-disable-directives --resolve-plugins-relative-to . --quiet packages/react-alp-loading-bar",
|
|
72
52
|
"watch": "pob-watch"
|
|
73
53
|
},
|
|
74
54
|
"prettier": {
|
|
@@ -80,9 +60,8 @@
|
|
|
80
60
|
"babelEnvs": [
|
|
81
61
|
{
|
|
82
62
|
"target": "node",
|
|
83
|
-
"version": "
|
|
63
|
+
"version": "14",
|
|
84
64
|
"formats": [
|
|
85
|
-
"cjs",
|
|
86
65
|
"es"
|
|
87
66
|
]
|
|
88
67
|
},
|
|
@@ -96,7 +75,6 @@
|
|
|
96
75
|
{
|
|
97
76
|
"target": "browser",
|
|
98
77
|
"formats": [
|
|
99
|
-
"cjs",
|
|
100
78
|
"es"
|
|
101
79
|
]
|
|
102
80
|
}
|
|
@@ -107,22 +85,21 @@
|
|
|
107
85
|
"jsx": true
|
|
108
86
|
},
|
|
109
87
|
"peerDependencies": {
|
|
110
|
-
"react": "^
|
|
88
|
+
"react": "^17.0.2"
|
|
111
89
|
},
|
|
112
90
|
"dependencies": {
|
|
113
|
-
"@babel/runtime": "^7.
|
|
91
|
+
"@babel/runtime": "^7.16.7",
|
|
114
92
|
"alp-types": "^3.0.0",
|
|
115
|
-
"react-alp-context": "
|
|
93
|
+
"react-alp-context": "4.0.1"
|
|
116
94
|
},
|
|
117
95
|
"devDependencies": {
|
|
118
|
-
"@babel/core": "7.
|
|
119
|
-
"@babel/preset-env": "7.
|
|
120
|
-
"@babel/preset-react": "7.
|
|
121
|
-
"babel-preset-latest-node": "5.5.1",
|
|
96
|
+
"@babel/core": "7.16.7",
|
|
97
|
+
"@babel/preset-env": "7.16.8",
|
|
98
|
+
"@babel/preset-react": "7.16.7",
|
|
122
99
|
"babel-preset-modern-browsers": "15.0.2",
|
|
123
|
-
"pob-babel": "
|
|
124
|
-
"react": "
|
|
125
|
-
"
|
|
100
|
+
"pob-babel": "29.6.1",
|
|
101
|
+
"react": "17.0.2",
|
|
102
|
+
"typescript": "4.5.4"
|
|
126
103
|
},
|
|
127
|
-
"gitHead": "
|
|
104
|
+
"gitHead": "a69797c459e219e09fcf22cc2ea46aa60dce396b"
|
|
128
105
|
}
|
package/src/.eslintrc.json
CHANGED
|
@@ -9,5 +9,22 @@
|
|
|
9
9
|
"@pob/eslint-config-typescript",
|
|
10
10
|
"@pob/eslint-config-typescript-react"
|
|
11
11
|
],
|
|
12
|
-
"ignorePatterns": ["*.d.ts"]
|
|
12
|
+
"ignorePatterns": ["*.d.ts"],
|
|
13
|
+
"overrides": [
|
|
14
|
+
{
|
|
15
|
+
"files": ["**/*.test.{ts,tsx}", "__tests__/**/*.{ts,tsx}"],
|
|
16
|
+
"extends": ["@pob/eslint-config-typescript/test"],
|
|
17
|
+
"env": {
|
|
18
|
+
"jest": true
|
|
19
|
+
},
|
|
20
|
+
"rules": {
|
|
21
|
+
"import/no-extraneous-dependencies": [
|
|
22
|
+
"error",
|
|
23
|
+
{
|
|
24
|
+
"devDependencies": true
|
|
25
|
+
}
|
|
26
|
+
]
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
]
|
|
13
30
|
}
|
package/src/index.tsx
CHANGED
|
@@ -56,21 +56,19 @@ export default class LoadingBar extends PureComponent<
|
|
|
56
56
|
> {
|
|
57
57
|
static contextType = ReactAlpContext;
|
|
58
58
|
|
|
59
|
-
context!: React.ContextType<typeof ReactAlpContext>;
|
|
60
|
-
|
|
61
59
|
state = {
|
|
62
60
|
loading: true,
|
|
63
61
|
hidden: true,
|
|
64
62
|
progress: 1,
|
|
65
63
|
};
|
|
66
64
|
|
|
67
|
-
fadeOffTimeout?:
|
|
65
|
+
fadeOffTimeout?: ReturnType<typeof setTimeout>;
|
|
68
66
|
|
|
69
|
-
resetTimeout?:
|
|
67
|
+
resetTimeout?: ReturnType<typeof setTimeout>;
|
|
70
68
|
|
|
71
|
-
first20Timeout?:
|
|
69
|
+
first20Timeout?: ReturnType<typeof setTimeout>;
|
|
72
70
|
|
|
73
|
-
progressTimer?:
|
|
71
|
+
progressTimer?: ReturnType<typeof setTimeout>;
|
|
74
72
|
|
|
75
73
|
componentDidMount(): void {
|
|
76
74
|
const websocket = this.getWebsocket();
|
|
@@ -103,10 +101,10 @@ export default class LoadingBar extends PureComponent<
|
|
|
103
101
|
}
|
|
104
102
|
|
|
105
103
|
componentWillUnmount(): void {
|
|
106
|
-
clearTimeout(this.fadeOffTimeout);
|
|
107
|
-
clearTimeout(this.resetTimeout);
|
|
108
|
-
clearTimeout(this.first20Timeout);
|
|
109
|
-
clearInterval(this.progressTimer);
|
|
104
|
+
if (this.fadeOffTimeout) clearTimeout(this.fadeOffTimeout);
|
|
105
|
+
if (this.resetTimeout) clearTimeout(this.resetTimeout);
|
|
106
|
+
if (this.first20Timeout) clearTimeout(this.first20Timeout);
|
|
107
|
+
if (this.progressTimer) clearInterval(this.progressTimer);
|
|
110
108
|
}
|
|
111
109
|
|
|
112
110
|
getWebsocket(): WebsocketInterface {
|
|
@@ -115,8 +113,8 @@ export default class LoadingBar extends PureComponent<
|
|
|
115
113
|
}
|
|
116
114
|
|
|
117
115
|
private showBar(): void {
|
|
118
|
-
clearTimeout(this.fadeOffTimeout);
|
|
119
|
-
clearTimeout(this.resetTimeout);
|
|
116
|
+
if (this.fadeOffTimeout) clearTimeout(this.fadeOffTimeout);
|
|
117
|
+
if (this.resetTimeout) clearTimeout(this.resetTimeout);
|
|
120
118
|
|
|
121
119
|
this.first20Timeout = setTimeout(() => {
|
|
122
120
|
this.setState({ progress: 20 });
|
|
@@ -131,8 +129,8 @@ export default class LoadingBar extends PureComponent<
|
|
|
131
129
|
}
|
|
132
130
|
|
|
133
131
|
private hideBar(): void {
|
|
134
|
-
clearTimeout(this.first20Timeout);
|
|
135
|
-
clearInterval(this.progressTimer);
|
|
132
|
+
if (this.first20Timeout) clearTimeout(this.first20Timeout);
|
|
133
|
+
if (this.progressTimer) clearInterval(this.progressTimer);
|
|
136
134
|
|
|
137
135
|
this.fadeOffTimeout = setTimeout(() => {
|
|
138
136
|
this.setState({
|