react-alp-loading-bar 3.1.2 → 4.0.2

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 CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "root": true,
3
- "extends": ["@pob/eslint-config/root", "@pob/eslint-config-node"],
3
+ "extends": ["@pob/eslint-config/root-module"],
4
4
  "ignorePatterns": ["*.d.ts", "/dist"]
5
5
  }
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.2](https://github.com/christophehurpeau/alp/compare/react-alp-loading-bar@4.0.1...react-alp-loading-bar@4.0.2) (2022-02-06)
7
+
8
+ **Note:** Version bump only for package react-alp-loading-bar
9
+
10
+
11
+
12
+
13
+
14
+ ## [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)
15
+
16
+ **Note:** Version bump only for package react-alp-loading-bar
17
+
18
+
19
+
20
+
21
+
22
+ # [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)
23
+
24
+
25
+ ### Bug Fixes
26
+
27
+ * update nightingale and fix tests ([3691716](https://github.com/christophehurpeau/alp/commit/36917162d0ee3dccc07384caf018b7760d98b744))
28
+
29
+
30
+ ### Features
31
+
32
+ * use ESM and drop node 12 ([f45054e](https://github.com/christophehurpeau/alp/commit/f45054e931eea88451d183722797eba057511236))
33
+
34
+
35
+ ### BREAKING CHANGES
36
+
37
+ * requires node 14 and ESM
38
+
39
+
40
+
41
+
42
+
43
+ ## [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)
44
+
45
+ **Note:** Version bump only for package react-alp-loading-bar
46
+
47
+
48
+
49
+
50
+
6
51
  ## [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)
7
52
 
8
53
  **Note:** Version bump only for package react-alp-loading-bar
@@ -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 LoadingBar;
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 context!: React.ContextType<typeof ReactAlpContext>;\n\n state = {\n loading: true,\n hidden: true,\n progress: 1,\n };\n\n fadeOffTimeout?: any;\n\n resetTimeout?: any;\n\n first20Timeout?: any;\n\n progressTimer?: any;\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 clearTimeout(this.fadeOffTimeout);\n clearTimeout(this.resetTimeout);\n clearTimeout(this.first20Timeout);\n 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 clearTimeout(this.fadeOffTimeout);\n 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 clearTimeout(this.first20Timeout);\n 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","clearTimeout","fadeOffTimeout","resetTimeout","first20Timeout","clearInterval","progressTimer","context","app","setTimeout","setInterval","newValue","render","LoadingBarComponent","props","position","top","left","right","zIndex","pointerEvents","PureComponent","contextType","ReactAlpContext"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AAAnBrC,WAIZsC,cAAcC;;;;"}
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,GAA1B,IAAiC,GAA/C;AAAA,CAAf;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,IAAMG,gBAAgB,GAAG,SAAnBA,gBAAmB,CAACC,OAAD,EAA6B;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;;IAwBqBC;;;;;;;;;;;UAMnBC,QAAQ;AACNC,MAAAA,OAAO,EAAE,IADH;AAENC,MAAAA,MAAM,EAAE,IAFF;AAGNC,MAAAA,QAAQ,EAAE;AAHJ;;;;;;SAcRC,oBAAA,6BAA0B;AAAA;;AACxB,QAAMC,SAAS,GAAG,KAAKC,YAAL,EAAlB;;AACA,QAAID,SAAS,CAACE,WAAV,EAAJ,EAA6B;AAC3B,WAAKC,QAAL,CAAc,UAACC,SAAD;AAAA,eAAgB;AAC5BR,UAAAA,OAAO,EAAE,KADmB;A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AG,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;;;EAlHqCiC;;AAAnBrC,WAIZsC,cAAcC;;;;"}
@@ -33,14 +33,12 @@ const calculatePercent = percent => {
33
33
  };
34
34
 
35
35
  class LoadingBar extends PureComponent {
36
- constructor(...args) {
37
- super(...args);
38
- this.state = {
39
- loading: true,
40
- hidden: true,
41
- progress: 1
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 LoadingBar;
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 context!: React.ContextType<typeof ReactAlpContext>;\n\n state = {\n loading: true,\n hidden: true,\n progress: 1,\n };\n\n fadeOffTimeout?: any;\n\n resetTimeout?: any;\n\n first20Timeout?: any;\n\n progressTimer?: any;\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 clearTimeout(this.fadeOffTimeout);\n clearTimeout(this.resetTimeout);\n clearTimeout(this.first20Timeout);\n 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 clearTimeout(this.fadeOffTimeout);\n 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 clearTimeout(this.first20Timeout);\n 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","state","loading","hidden","progress","componentDidMount","websocket","getWebsocket","isConnected","setState","prevState","on","componentDidUpdate","prevProps","showBar","hideBar","componentWillUnmount","clearTimeout","fadeOffTimeout","resetTimeout","first20Timeout","clearInterval","progressTimer","context","app","setTimeout","setInterval","newValue","render","LoadingBarComponent","props","position","top","left","right","zIndex","pointerEvents","contextType","ReactAlpContext"],"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;AAAA;AAAA;AAAA,SAKAC,KALA,GAKQ;AACNC,MAAAA,OAAO,EAAE,IADH;AAENC,MAAAA,MAAM,EAAE,IAFF;AAGNC,MAAAA,QAAQ,EAAE;AAHJ,KALR;AAAA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AGLC,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;;AAjHD;AAHmBL,WAIZsC,cAAcC;;;;"}
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;A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AAMC,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;;;;"}
@@ -33,14 +33,12 @@ const calculatePercent = percent => {
33
33
  };
34
34
 
35
35
  class LoadingBar extends PureComponent {
36
- constructor(...args) {
37
- super(...args);
38
- this.state = {
39
- loading: true,
40
- hidden: true,
41
- progress: 1
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 LoadingBar;
147
- //# sourceMappingURL=index-node12.mjs.map
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,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,GAAG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L,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?: any;
27
- resetTimeout?: any;
28
- first20Timeout?: any;
29
- progressTimer?: any;
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;
@@ -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;AAC7C,OAAO,eAAe,MAAM,mBAAmB,CAAC;AAmChD,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,OAAO,EAAG,KAAK,CAAC,WAAW,CAAC,OAAO,eAAe,CAAC,CAAC;IAEpD,KAAK;;;;MAIH;IAEF,cAAc,CAAC,EAAE,GAAG,CAAC;IAErB,YAAY,CAAC,EAAE,GAAG,CAAC;IAEnB,cAAc,CAAC,EAAE,GAAG,CAAC;IAErB,aAAa,CAAC,EAAE,GAAG,CAAC;IAEpB,iBAAiB,IAAI,IAAI;IAiBzB,k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Ae,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.1.2",
3
+ "version": "4.0.2",
4
4
  "description": "loading bar",
5
5
  "keywords": [],
6
6
  "author": "Christophe Hurpeau <christophe@hurpeau.com> (https://christophe.hurpeau.com)",
@@ -11,65 +11,46 @@
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": ">=12.10.0"
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 ios_saf < 10",
26
- "not dead",
27
- "not op_mini all"
22
+ "not safari < 10",
23
+ "not ios_saf < 10"
28
24
  ],
29
- "main": "./index.js",
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
- "development": {
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
- "development": {
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-node12.mjs",
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
- "build": "pob-build && yarn run build:definitions",
47
+ "build": "yarn clean:build && rollup --config rollup.config.mjs && yarn run build:definitions",
68
48
  "build:definitions": "tsc -p tsconfig.build.json",
69
- "clean": "rm -Rf docs dist test/node6 coverage",
49
+ "clean": "yarn clean:build",
50
+ "clean:build": "rm -Rf dist",
70
51
  "lint": "yarn run lint:eslint",
71
- "lint:eslint": "yarn --cwd ../.. run eslint --ext .js,.mjs,.ts,.tsx --report-unused-disable-directives --quiet packages/react-alp-loading-bar",
72
- "watch": "pob-watch"
52
+ "lint:eslint": "cd ../.. && yarn run eslint --report-unused-disable-directives --resolve-plugins-relative-to . --quiet packages/react-alp-loading-bar",
53
+ "watch": "yarn clean:build && rollup --config rollup.config.mjs --watch"
73
54
  },
74
55
  "prettier": {
75
56
  "trailingComma": "all",
@@ -80,9 +61,8 @@
80
61
  "babelEnvs": [
81
62
  {
82
63
  "target": "node",
83
- "version": "12",
64
+ "version": "14",
84
65
  "formats": [
85
- "cjs",
86
66
  "es"
87
67
  ]
88
68
  },
@@ -96,7 +76,6 @@
96
76
  {
97
77
  "target": "browser",
98
78
  "formats": [
99
- "cjs",
100
79
  "es"
101
80
  ]
102
81
  }
@@ -107,22 +86,21 @@
107
86
  "jsx": true
108
87
  },
109
88
  "peerDependencies": {
110
- "react": "^16.8.6"
89
+ "react": "^17.0.2"
111
90
  },
112
91
  "dependencies": {
113
- "@babel/runtime": "^7.13.10",
114
- "alp-types": "^3.0.0",
115
- "react-alp-context": "^3.1.2"
92
+ "@babel/runtime": "^7.17.0",
93
+ "alp-types": "3.1.0",
94
+ "react-alp-context": "4.0.2"
116
95
  },
117
96
  "devDependencies": {
118
- "@babel/core": "7.13.13",
119
- "@babel/preset-env": "7.13.12",
120
- "@babel/preset-react": "7.13.13",
121
- "babel-preset-latest-node": "5.5.1",
97
+ "@babel/core": "7.17.0",
98
+ "@babel/preset-env": "7.16.11",
99
+ "@babel/preset-react": "7.16.7",
122
100
  "babel-preset-modern-browsers": "15.0.2",
123
- "pob-babel": "26.8.0",
124
- "react": "16.14.0",
125
- "rollup": "2.43.1"
101
+ "pob-babel": "31.0.0",
102
+ "react": "17.0.2",
103
+ "typescript": "4.5.5"
126
104
  },
127
- "gitHead": "2f3c2a9cdeacf0c759f275e7e4ccbcb5d46db297"
105
+ "gitHead": "1af3cf2eb4bba25ab23f174cda860416ff68a63d"
128
106
  }
@@ -0,0 +1,5 @@
1
+ import createRollupConfig from 'pob-babel/createRollupConfig.js';
2
+
3
+ export default createRollupConfig({
4
+ cwd: new URL('.', import.meta.url).pathname,
5
+ });
@@ -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?: any;
65
+ fadeOffTimeout?: ReturnType<typeof setTimeout>;
68
66
 
69
- resetTimeout?: any;
67
+ resetTimeout?: ReturnType<typeof setTimeout>;
70
68
 
71
- first20Timeout?: any;
69
+ first20Timeout?: ReturnType<typeof setTimeout>;
72
70
 
73
- progressTimer?: any;
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({