react-alp-connection-state 4.1.3 → 6.0.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-alp-connection-state",
3
- "version": "4.1.3",
3
+ "version": "6.0.0",
4
4
  "description": "connection state",
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-connection-state"
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-connection-state",
72
- "watch": "pob-watch"
52
+ "lint:eslint": "cd ../.. && yarn run eslint --report-unused-disable-directives --resolve-plugins-relative-to . --quiet packages/react-alp-connection-state",
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,25 +86,27 @@
107
86
  "jsx": true
108
87
  },
109
88
  "peerDependencies": {
110
- "react": "^16.8.6",
111
- "ynnub": "^1.0.0 || ^2.0.0"
89
+ "react": "^17.0.2",
90
+ "react-native": "*"
91
+ },
92
+ "peerDependenciesMeta": {
93
+ "react-native": {
94
+ "optional": true
95
+ }
112
96
  },
113
97
  "dependencies": {
114
- "@babel/runtime": "^7.13.10",
115
- "alp-types": "^3.0.0",
116
- "react-alp-context": "^3.1.3",
117
- "react-alp-translate": "^5.1.3"
98
+ "@babel/runtime": "^7.17.2"
118
99
  },
119
100
  "devDependencies": {
120
- "@babel/core": "7.13.14",
121
- "@babel/preset-env": "7.13.12",
122
- "@babel/preset-react": "7.13.13",
123
- "babel-preset-latest-node": "5.5.1",
101
+ "@babel/core": "7.17.2",
102
+ "@babel/preset-env": "7.16.11",
103
+ "@babel/preset-react": "7.16.7",
104
+ "@types/react-native": "0.66.15",
124
105
  "babel-preset-modern-browsers": "15.0.2",
125
- "pob-babel": "26.8.0",
126
- "react": "16.14.0",
127
- "rollup": "2.43.1",
128
- "ynnub": "2.0.0"
106
+ "pob-babel": "32.0.1",
107
+ "react": "17.0.2",
108
+ "react-native": "0.67.2",
109
+ "typescript": "4.5.5"
129
110
  },
130
- "gitHead": "bf4ed59d61ee4b4ed741a9764263b1924c941546"
111
+ "gitHead": "1617223e61c2b76e0613a49012792fbf6d3b872b"
131
112
  }
@@ -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
+ });
@@ -2,12 +2,29 @@
2
2
  "root": true,
3
3
  "parser": "@typescript-eslint/parser",
4
4
  "parserOptions": {
5
- "project": "packages/react-alp-connection-state/tsconfig.json"
5
+ "project": "packages/react-alp-connection-state/tsconfig.eslint.json"
6
6
  },
7
7
  "plugins": ["@typescript-eslint"],
8
8
  "extends": [
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
@@ -1,29 +1,96 @@
1
- import type { ReactElement } from 'react';
2
- import React, { useContext, useEffect, useRef } from 'react';
3
- import ReactAlpContext from 'react-alp-context';
4
- import { T } from 'react-alp-translate';
5
- import '../ConnectionState.global.scss';
1
+ import type { ReactElement, ReactNode } from 'react';
2
+ import { useEffect, useRef } from 'react';
3
+ import type { ScaledSize } from 'react-native';
4
+ import { View, StyleSheet, Platform, useWindowDimensions } from 'react-native';
6
5
 
7
- type State = null | 'connecting' | 'connected' | 'disconnected';
6
+ const defaultTheme = {
7
+ container: {
8
+ backgroundColor: 'rgba(247, 25, 0, 0.8)',
9
+ color: '#fff',
10
+ textShadowColor: '#111',
11
+ textShadowOffset: { width: 0, height: -1 },
12
+ textShadowRadius: 1,
13
+ },
14
+ backgroundColorConnected: 'rgba(25, 200, 60, 0.8)',
15
+ };
8
16
 
9
- interface ConnectionStateProps {
17
+ export type ConnectionStateTheme = typeof defaultTheme;
18
+ export type State = null | 'connecting' | 'connected' | 'disconnected';
19
+
20
+ export interface ConnectionStateProps {
21
+ theme?: ConnectionStateTheme;
22
+ forceHidden?: boolean;
10
23
  state: State;
24
+ children: NonNullable<ReactNode>;
11
25
  }
12
26
 
13
- export default function ConnectionState({
14
- state,
15
- }: ConnectionStateProps): ReactElement {
16
- const ctx = useContext(ReactAlpContext);
17
- const notLoggedIn = !(ctx.sanitizedState as { user?: unknown }).user;
27
+ const zDepth1 =
28
+ '0 2px 3px 0 rgba(0, 0, 0, 0.15), 0 2px 5px 0 rgba(0, 0, 0, 0.2)';
29
+
30
+ type CreateCalc = (
31
+ webCalc: string,
32
+ createCalc: (dimensions: ScaledSize) => number,
33
+ ) => string | number;
34
+
35
+ const useCreateCalcNative = (): CreateCalc => {
36
+ const dimensions = useWindowDimensions();
37
+ return (webCalc, createCalc) => createCalc(dimensions);
38
+ };
39
+ const useCreateCalcWeb = (): CreateCalc => {
40
+ return (webCalc) => `calc(${webCalc})`;
41
+ };
42
+ const useCreateCalc =
43
+ Platform.OS === 'web' ? useCreateCalcWeb : useCreateCalcNative;
44
+
45
+ // example: const left = createCalc('50% - 100px', ({ width }) => width / 2 - 100);
18
46
 
47
+ const styles = StyleSheet.create({
48
+ connectionStateContainer: {
49
+ backgroundColor: defaultTheme.container.backgroundColor,
50
+ position: 'absolute',
51
+ top: 0,
52
+ right: 0,
53
+ left: 0,
54
+ height: 2,
55
+ color: defaultTheme.container.color,
56
+ textShadowOffset: defaultTheme.container.textShadowOffset,
57
+ textShadowRadius: defaultTheme.container.textShadowRadius,
58
+ boxShadow: zDepth1,
59
+ zIndex: 9,
60
+ transition: 'top .8s, background-color .2s',
61
+ },
62
+ hide: {
63
+ top: -24,
64
+ },
65
+ connectionStateText: {
66
+ backgroundColor: defaultTheme.container.backgroundColor,
67
+ position: 'absolute',
68
+ width: 200,
69
+ height: 22,
70
+ lineHeight: 22,
71
+ top: 2,
72
+ textAlign: 'center',
73
+ borderBottomLeftRadius: 5,
74
+ borderBottomRightRadius: 5,
75
+ transition: 'background-color .2s',
76
+ },
77
+ });
78
+
79
+ export function ConnectionState({
80
+ theme,
81
+ forceHidden,
82
+ state,
83
+ children,
84
+ }: ConnectionStateProps): ReactElement | null {
85
+ console.log({ state, forceHidden });
19
86
  const unloadingRef = useRef<boolean>(false);
20
- const currentStateRef = useRef(state);
21
- if (unloadingRef.current === false) {
22
- currentStateRef.current = state;
23
- }
24
- const currentState = currentStateRef.current;
25
87
 
26
- useEffect((): (() => void) => {
88
+ const createCalc = useCreateCalc();
89
+ const left = createCalc('50% - 100px', ({ width }) => width / 2 - 100); // TODO use calc() in web ?
90
+
91
+ useEffect((): (() => void) | undefined => {
92
+ if (typeof window === 'undefined') return;
93
+
27
94
  const beforeUnloadHandler = (): void => {
28
95
  unloadingRef.current = true;
29
96
  };
@@ -34,16 +101,33 @@ export default function ConnectionState({
34
101
  };
35
102
  }, []);
36
103
 
104
+ const shouldHide = forceHidden || !state || state === 'connected';
105
+
37
106
  return (
38
- <div
39
- hidden={!state || notLoggedIn || currentState === 'connected'}
40
- className="alp-connection-state"
107
+ <View
108
+ style={[
109
+ styles.connectionStateContainer,
110
+ shouldHide && styles.hide,
111
+ theme?.container,
112
+ state === 'connected' && {
113
+ backgroundColor: (theme || defaultTheme).backgroundColorConnected,
114
+ },
115
+ ]}
41
116
  >
42
- {!state || notLoggedIn ? null : (
43
- <div>
44
- <T id={`connectionState.${currentState as string}`} />
45
- </div>
117
+ {!state ? null : (
118
+ <View
119
+ style={[
120
+ styles.connectionStateText,
121
+ theme && { backgroundColor: theme.container.backgroundColor },
122
+ state === 'connected' && {
123
+ backgroundColor: (theme || defaultTheme).backgroundColorConnected,
124
+ },
125
+ { left },
126
+ ]}
127
+ >
128
+ {children}
129
+ </View>
46
130
  )}
47
- </div>
131
+ </View>
48
132
  );
49
133
  }
@@ -0,0 +1,7 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+
4
+ "compilerOptions": {
5
+ "noEmit": true
6
+ }
7
+ }
@@ -1,37 +0,0 @@
1
- @import '~ynnub/mixins/block';
2
- @import '~ynnub/mixins/typography';
3
-
4
- $connection-state-background: rgba(247, 25, 0, 0.8) !default;
5
- $connection-state-color: #fff !default;
6
- $connection-state-text-shadow: #111 0 1px 1px !default;
7
-
8
- .alp-connection-state {
9
- background: $connection-state-background;
10
- position: fixed;
11
- top: 0;
12
- right: 0;
13
- left: 0;
14
- height: 2px;
15
- color: $connection-state-color;
16
- text-shadow: $connection-state-text-shadow;
17
- @include bold();
18
- @include z-depth-1();
19
- z-index: 9;
20
-
21
- > div {
22
- background: $connection-state-background;
23
- position: fixed;
24
- width: 200px;
25
- height: 22px;
26
- line-height: 22px;
27
- // top: 50%;
28
- top: 2px;
29
- left: 50%;
30
- // overflow: hidden;
31
- // margin-top: -25px;
32
- margin-left: -100px;
33
- text-align: center;
34
-
35
- border-radius: 0 0 5px 5px;
36
- }
37
- }
@@ -1,46 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var React = require('react');
6
- var ReactAlpContext = require('react-alp-context');
7
- var reactAlpTranslate = require('react-alp-translate');
8
- require('../ConnectionState.global.scss');
9
-
10
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e['default'] : e; }
11
-
12
- var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
13
- var ReactAlpContext__default = /*#__PURE__*/_interopDefaultLegacy(ReactAlpContext);
14
-
15
- function ConnectionState(_ref) {
16
- var state = _ref.state;
17
- var ctx = React.useContext(ReactAlpContext__default);
18
- var notLoggedIn = !ctx.sanitizedState.user;
19
- var unloadingRef = React.useRef(false);
20
- var currentStateRef = React.useRef(state);
21
-
22
- if (unloadingRef.current === false) {
23
- currentStateRef.current = state;
24
- }
25
-
26
- var currentState = currentStateRef.current;
27
- React.useEffect(function () {
28
- var beforeUnloadHandler = function beforeUnloadHandler() {
29
- unloadingRef.current = true;
30
- };
31
-
32
- window.addEventListener('beforeunload', beforeUnloadHandler);
33
- return function () {
34
- window.removeEventListener('beforeunload', beforeUnloadHandler);
35
- };
36
- }, []);
37
- return /*#__PURE__*/React__default.createElement("div", {
38
- hidden: !state || notLoggedIn || currentState === 'connected',
39
- className: "alp-connection-state"
40
- }, !state || notLoggedIn ? null : /*#__PURE__*/React__default.createElement("div", null, /*#__PURE__*/React__default.createElement(reactAlpTranslate.T, {
41
- id: "connectionState." + currentState
42
- })));
43
- }
44
-
45
- exports.default = ConnectionState;
46
- //# sourceMappingURL=index-browser-dev.cjs.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index-browser-dev.cjs.js","sources":["../src/index.tsx"],"sourcesContent":["import type { ReactElement } from 'react';\nimport React, { useContext, useEffect, useRef } from 'react';\nimport ReactAlpContext from 'react-alp-context';\nimport { T } from 'react-alp-translate';\nimport '../ConnectionState.global.scss';\n\ntype State = null | 'connecting' | 'connected' | 'disconnected';\n\ninterface ConnectionStateProps {\n state: State;\n}\n\nexport default function ConnectionState({\n state,\n}: ConnectionStateProps): ReactElement {\n const ctx = useContext(ReactAlpContext);\n const notLoggedIn = !(ctx.sanitizedState as { user?: unknown }).user;\n\n const unloadingRef = useRef<boolean>(false);\n const currentStateRef = useRef(state);\n if (unloadingRef.current === false) {\n currentStateRef.current = state;\n }\n const currentState = currentStateRef.current;\n\n useEffect((): (() => void) => {\n const beforeUnloadHandler = (): void => {\n unloadingRef.current = true;\n };\n window.addEventListener('beforeunload', beforeUnloadHandler);\n\n return (): void => {\n window.removeEventListener('beforeunload', beforeUnloadHandler);\n };\n }, []);\n\n return (\n <div\n hidden={!state || notLoggedIn || currentState === 'connected'}\n className=\"alp-connection-state\"\n >\n {!state || notLoggedIn ? null : (\n <div>\n <T id={`connectionState.${currentState as string}`} />\n </div>\n )}\n </div>\n );\n}\n"],"names":["ConnectionState","state","ctx","useContext","ReactAlpContext","notLoggedIn","sanitizedState","user","unloadingRef","useRef","currentStateRef","current","currentState","useEffect","beforeUnloadHandler","window","addEventListener","removeEventListener","React","T"],"mappings":";;;;;;;;;;;;;;AAYe,SAASA,eAAT,OAEwB;AAAA,MADrCC,KACqC,QADrCA,KACqC;AACrC,MAAMC,GAAG,GAAGC,gBAAU,CAACC,wBAAD,CAAtB;AACA,MAAMC,WAAW,GAAG,CAAEH,GAAG,CAACI,cAAL,CAA2CC,IAAhE;AAEA,MAAMC,YAAY,GAAGC,YAAM,CAAU,KAAV,CAA3B;AACA,MAAMC,eAAe,GAAGD,YAAM,CAACR,KAAD,CAA9B;;AACA,MAAIO,YAAY,CAACG,OAAb,KAAyB,KAA7B,EAAoC;AAClCD,IAAAA,eAAe,CAACC,OAAhB,GAA0BV,KAA1B;AACD;;AACD,MAAMW,YAAY,GAAGF,eAAe,CAACC,OAArC;AAEAE,EAAAA,eAAS,CAAC,YAAoB;AAC5B,QAAMC,mBAAmB,GAAG,SAAtBA,mBAAsB,GAAY;AACtCN,MAAAA,YAAY,CAACG,OAAb,GAAuB,IAAvB;AACD,KAFD;;AAGAI,IAAAA,MAAM,CAACC,gBAAP,CAAwB,cAAxB,EAAwCF,mBAAxC;AAEA,WAAO,YAAY;AACjBC,MAAAA,MAAM,CAACE,mBAAP,CAA2B,cAA3B,EAA2CH,mBAA3C;AACD,KAFD;AAGD,GATQ,EASN,EATM,CAAT;AAWA,sBACEI;AACE,IAAA,MAAM,EAAE,CAACjB,KAAD,IAAUI,WAAV,IAAyBO,YAAY,KAAK,WADpD;AAEE,IAAA,SAAS,EAAC;AAFZ,KAIG,CAACX,KAAD,IAAUI,WAAV,GAAwB,IAAxB,gBACCa,uDACEA,6BAACC,mBAAD;AAAG,IAAA,EAAE,uBAAqBP;AAA1B,IADF,CALJ,CADF;AAYD;;;;"}
@@ -1,37 +0,0 @@
1
- import React, { useContext, useRef, useEffect } from 'react';
2
- import ReactAlpContext from 'react-alp-context';
3
- import { T } from 'react-alp-translate';
4
- import '../ConnectionState.global.scss';
5
-
6
- function ConnectionState(_ref) {
7
- var state = _ref.state;
8
- var ctx = useContext(ReactAlpContext);
9
- var notLoggedIn = !ctx.sanitizedState.user;
10
- var unloadingRef = useRef(false);
11
- var currentStateRef = useRef(state);
12
-
13
- if (unloadingRef.current === false) {
14
- currentStateRef.current = state;
15
- }
16
-
17
- var currentState = currentStateRef.current;
18
- useEffect(function () {
19
- var beforeUnloadHandler = function beforeUnloadHandler() {
20
- unloadingRef.current = true;
21
- };
22
-
23
- window.addEventListener('beforeunload', beforeUnloadHandler);
24
- return function () {
25
- window.removeEventListener('beforeunload', beforeUnloadHandler);
26
- };
27
- }, []);
28
- return /*#__PURE__*/React.createElement("div", {
29
- hidden: !state || notLoggedIn || currentState === 'connected',
30
- className: "alp-connection-state"
31
- }, !state || notLoggedIn ? null : /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(T, {
32
- id: "connectionState." + currentState
33
- })));
34
- }
35
-
36
- export default ConnectionState;
37
- //# sourceMappingURL=index-browser-dev.es.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index-browser-dev.es.js","sources":["../src/index.tsx"],"sourcesContent":["import type { ReactElement } from 'react';\nimport React, { useContext, useEffect, useRef } from 'react';\nimport ReactAlpContext from 'react-alp-context';\nimport { T } from 'react-alp-translate';\nimport '../ConnectionState.global.scss';\n\ntype State = null | 'connecting' | 'connected' | 'disconnected';\n\ninterface ConnectionStateProps {\n state: State;\n}\n\nexport default function ConnectionState({\n state,\n}: ConnectionStateProps): ReactElement {\n const ctx = useContext(ReactAlpContext);\n const notLoggedIn = !(ctx.sanitizedState as { user?: unknown }).user;\n\n const unloadingRef = useRef<boolean>(false);\n const currentStateRef = useRef(state);\n if (unloadingRef.current === false) {\n currentStateRef.current = state;\n }\n const currentState = currentStateRef.current;\n\n useEffect((): (() => void) => {\n const beforeUnloadHandler = (): void => {\n unloadingRef.current = true;\n };\n window.addEventListener('beforeunload', beforeUnloadHandler);\n\n return (): void => {\n window.removeEventListener('beforeunload', beforeUnloadHandler);\n };\n }, []);\n\n return (\n <div\n hidden={!state || notLoggedIn || currentState === 'connected'}\n className=\"alp-connection-state\"\n >\n {!state || notLoggedIn ? null : (\n <div>\n <T id={`connectionState.${currentState as string}`} />\n </div>\n )}\n </div>\n );\n}\n"],"names":["ConnectionState","state","ctx","useContext","ReactAlpContext","notLoggedIn","sanitizedState","user","unloadingRef","useRef","currentStateRef","current","currentState","useEffect","beforeUnloadHandler","window","addEventListener","removeEventListener"],"mappings":";;;;;AAYe,SAASA,eAAT,OAEwB;AAAA,MADrCC,KACqC,QADrCA,KACqC;AACrC,MAAMC,GAAG,GAAGC,UAAU,CAACC,eAAD,CAAtB;AACA,MAAMC,WAAW,GAAG,CAAEH,GAAG,CAACI,cAAL,CAA2CC,IAAhE;AAEA,MAAMC,YAAY,GAAGC,MAAM,CAAU,KAAV,CAA3B;AACA,MAAMC,eAAe,GAAGD,MAAM,CAACR,KAAD,CAA9B;;AACA,MAAIO,YAAY,CAACG,OAAb,KAAyB,KAA7B,EAAoC;AAClCD,IAAAA,eAAe,CAACC,OAAhB,GAA0BV,KAA1B;AACD;;AACD,MAAMW,YAAY,GAAGF,eAAe,CAACC,OAArC;AAEAE,EAAAA,SAAS,CAAC,YAAoB;AAC5B,QAAMC,mBAAmB,GAAG,SAAtBA,mBAAsB,GAAY;AACtCN,MAAAA,YAAY,CAACG,OAAb,GAAuB,IAAvB;AACD,KAFD;;AAGAI,IAAAA,MAAM,CAACC,gBAAP,CAAwB,cAAxB,EAAwCF,mBAAxC;AAEA,WAAO,YAAY;AACjBC,MAAAA,MAAM,CAACE,mBAAP,CAA2B,cAA3B,EAA2CH,mBAA3C;AACD,KAFD;AAGD,GATQ,EASN,EATM,CAAT;AAWA,sBACE;AACE,IAAA,MAAM,EAAE,CAACb,KAAD,IAAUI,WAAV,IAAyBO,YAAY,KAAK,WADpD;AAEE,IAAA,SAAS,EAAC;AAFZ,KAIG,CAACX,KAAD,IAAUI,WAAV,GAAwB,IAAxB,gBACC,8CACE,oBAAC,CAAD;AAAG,IAAA,EAAE,uBAAqBO;AAA1B,IADF,CALJ,CADF;AAYD;;;;"}
@@ -1,46 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var React = require('react');
6
- var ReactAlpContext = require('react-alp-context');
7
- var reactAlpTranslate = require('react-alp-translate');
8
- require('../ConnectionState.global.scss');
9
-
10
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e['default'] : e; }
11
-
12
- var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
13
- var ReactAlpContext__default = /*#__PURE__*/_interopDefaultLegacy(ReactAlpContext);
14
-
15
- function ConnectionState(_ref) {
16
- var state = _ref.state;
17
- var ctx = React.useContext(ReactAlpContext__default);
18
- var notLoggedIn = !ctx.sanitizedState.user;
19
- var unloadingRef = React.useRef(false);
20
- var currentStateRef = React.useRef(state);
21
-
22
- if (unloadingRef.current === false) {
23
- currentStateRef.current = state;
24
- }
25
-
26
- var currentState = currentStateRef.current;
27
- React.useEffect(function () {
28
- var beforeUnloadHandler = function beforeUnloadHandler() {
29
- unloadingRef.current = true;
30
- };
31
-
32
- window.addEventListener('beforeunload', beforeUnloadHandler);
33
- return function () {
34
- window.removeEventListener('beforeunload', beforeUnloadHandler);
35
- };
36
- }, []);
37
- return /*#__PURE__*/React__default.createElement("div", {
38
- hidden: !state || notLoggedIn || currentState === 'connected',
39
- className: "alp-connection-state"
40
- }, !state || notLoggedIn ? null : /*#__PURE__*/React__default.createElement("div", null, /*#__PURE__*/React__default.createElement(reactAlpTranslate.T, {
41
- id: "connectionState." + currentState
42
- })));
43
- }
44
-
45
- exports.default = ConnectionState;
46
- //# sourceMappingURL=index-browser.cjs.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index-browser.cjs.js","sources":["../src/index.tsx"],"sourcesContent":["import type { ReactElement } from 'react';\nimport React, { useContext, useEffect, useRef } from 'react';\nimport ReactAlpContext from 'react-alp-context';\nimport { T } from 'react-alp-translate';\nimport '../ConnectionState.global.scss';\n\ntype State = null | 'connecting' | 'connected' | 'disconnected';\n\ninterface ConnectionStateProps {\n state: State;\n}\n\nexport default function ConnectionState({\n state,\n}: ConnectionStateProps): ReactElement {\n const ctx = useContext(ReactAlpContext);\n const notLoggedIn = !(ctx.sanitizedState as { user?: unknown }).user;\n\n const unloadingRef = useRef<boolean>(false);\n const currentStateRef = useRef(state);\n if (unloadingRef.current === false) {\n currentStateRef.current = state;\n }\n const currentState = currentStateRef.current;\n\n useEffect((): (() => void) => {\n const beforeUnloadHandler = (): void => {\n unloadingRef.current = true;\n };\n window.addEventListener('beforeunload', beforeUnloadHandler);\n\n return (): void => {\n window.removeEventListener('beforeunload', beforeUnloadHandler);\n };\n }, []);\n\n return (\n <div\n hidden={!state || notLoggedIn || currentState === 'connected'}\n className=\"alp-connection-state\"\n >\n {!state || notLoggedIn ? null : (\n <div>\n <T id={`connectionState.${currentState as string}`} />\n </div>\n )}\n </div>\n );\n}\n"],"names":["ConnectionState","state","ctx","useContext","ReactAlpContext","notLoggedIn","sanitizedState","user","unloadingRef","useRef","currentStateRef","current","currentState","useEffect","beforeUnloadHandler","window","addEventListener","removeEventListener","React","T"],"mappings":";;;;;;;;;;;;;;AAYe,SAASA,eAAT,OAEwB;AAAA,MADrCC,KACqC,QADrCA,KACqC;AACrC,MAAMC,GAAG,GAAGC,gBAAU,CAACC,wBAAD,CAAtB;AACA,MAAMC,WAAW,GAAG,CAAEH,GAAG,CAACI,cAAL,CAA2CC,IAAhE;AAEA,MAAMC,YAAY,GAAGC,YAAM,CAAU,KAAV,CAA3B;AACA,MAAMC,eAAe,GAAGD,YAAM,CAACR,KAAD,CAA9B;;AACA,MAAIO,YAAY,CAACG,OAAb,KAAyB,KAA7B,EAAoC;AAClCD,IAAAA,eAAe,CAACC,OAAhB,GAA0BV,KAA1B;AACD;;AACD,MAAMW,YAAY,GAAGF,eAAe,CAACC,OAArC;AAEAE,EAAAA,eAAS,CAAC,YAAoB;AAC5B,QAAMC,mBAAmB,GAAG,SAAtBA,mBAAsB,GAAY;AACtCN,MAAAA,YAAY,CAACG,OAAb,GAAuB,IAAvB;AACD,KAFD;;AAGAI,IAAAA,MAAM,CAACC,gBAAP,CAAwB,cAAxB,EAAwCF,mBAAxC;AAEA,WAAO,YAAY;AACjBC,MAAAA,MAAM,CAACE,mBAAP,CAA2B,cAA3B,EAA2CH,mBAA3C;AACD,KAFD;AAGD,GATQ,EASN,EATM,CAAT;AAWA,sBACEI;AACE,IAAA,MAAM,EAAE,CAACjB,KAAD,IAAUI,WAAV,IAAyBO,YAAY,KAAK,WADpD;AAEE,IAAA,SAAS,EAAC;AAFZ,KAIG,CAACX,KAAD,IAAUI,WAAV,GAAwB,IAAxB,gBACCa,uDACEA,6BAACC,mBAAD;AAAG,IAAA,EAAE,uBAAqBP;AAA1B,IADF,CALJ,CADF;AAYD;;;;"}
@@ -1,38 +0,0 @@
1
- import React, { useContext, useRef, useEffect } from 'react';
2
- import ReactAlpContext from 'react-alp-context';
3
- import { T } from 'react-alp-translate';
4
- import '../ConnectionState.global.scss';
5
-
6
- function ConnectionState({
7
- state
8
- }) {
9
- const ctx = useContext(ReactAlpContext);
10
- const notLoggedIn = !ctx.sanitizedState.user;
11
- const unloadingRef = useRef(false);
12
- const currentStateRef = useRef(state);
13
-
14
- if (unloadingRef.current === false) {
15
- currentStateRef.current = state;
16
- }
17
-
18
- const currentState = currentStateRef.current;
19
- useEffect(() => {
20
- const beforeUnloadHandler = () => {
21
- unloadingRef.current = true;
22
- };
23
-
24
- window.addEventListener('beforeunload', beforeUnloadHandler);
25
- return () => {
26
- window.removeEventListener('beforeunload', beforeUnloadHandler);
27
- };
28
- }, []);
29
- return /*#__PURE__*/React.createElement("div", {
30
- hidden: !state || notLoggedIn || currentState === 'connected',
31
- className: "alp-connection-state"
32
- }, !state || notLoggedIn ? null : /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(T, {
33
- id: `connectionState.${currentState}`
34
- })));
35
- }
36
-
37
- export default ConnectionState;
38
- //# sourceMappingURL=index-browsermodern-dev.es.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index-browsermodern-dev.es.js","sources":["../src/index.tsx"],"sourcesContent":["import type { ReactElement } from 'react';\nimport React, { useContext, useEffect, useRef } from 'react';\nimport ReactAlpContext from 'react-alp-context';\nimport { T } from 'react-alp-translate';\nimport '../ConnectionState.global.scss';\n\ntype State = null | 'connecting' | 'connected' | 'disconnected';\n\ninterface ConnectionStateProps {\n state: State;\n}\n\nexport default function ConnectionState({\n state,\n}: ConnectionStateProps): ReactElement {\n const ctx = useContext(ReactAlpContext);\n const notLoggedIn = !(ctx.sanitizedState as { user?: unknown }).user;\n\n const unloadingRef = useRef<boolean>(false);\n const currentStateRef = useRef(state);\n if (unloadingRef.current === false) {\n currentStateRef.current = state;\n }\n const currentState = currentStateRef.current;\n\n useEffect((): (() => void) => {\n const beforeUnloadHandler = (): void => {\n unloadingRef.current = true;\n };\n window.addEventListener('beforeunload', beforeUnloadHandler);\n\n return (): void => {\n window.removeEventListener('beforeunload', beforeUnloadHandler);\n };\n }, []);\n\n return (\n <div\n hidden={!state || notLoggedIn || currentState === 'connected'}\n className=\"alp-connection-state\"\n >\n {!state || notLoggedIn ? null : (\n <div>\n <T id={`connectionState.${currentState as string}`} />\n </div>\n )}\n </div>\n );\n}\n"],"names":["ConnectionState","state","ctx","useContext","ReactAlpContext","notLoggedIn","sanitizedState","user","unloadingRef","useRef","currentStateRef","current","currentState","useEffect","beforeUnloadHandler","window","addEventListener","removeEventListener"],"mappings":";;;;;AAYe,SAASA,eAAT,CAAyB;AACtCC,EAAAA;AADsC,CAAzB,EAEwB;AACrC,QAAMC,GAAG,GAAGC,UAAU,CAACC,eAAD,CAAtB;AACA,QAAMC,WAAW,GAAG,CAAEH,GAAG,CAACI,cAAL,CAA2CC,IAAhE;AAEA,QAAMC,YAAY,GAAGC,MAAM,CAAU,KAAV,CAA3B;AACA,QAAMC,eAAe,GAAGD,MAAM,CAACR,KAAD,CAA9B;;AACA,MAAIO,YAAY,CAACG,OAAb,KAAyB,KAA7B,EAAoC;AAClCD,IAAAA,eAAe,CAACC,OAAhB,GAA0BV,KAA1B;AACD;;AACD,QAAMW,YAAY,GAAGF,eAAe,CAACC,OAArC;AAEAE,EAAAA,SAAS,CAAC,MAAoB;AAC5B,UAAMC,mBAAmB,GAAG,MAAY;AACtCN,MAAAA,YAAY,CAACG,OAAb,GAAuB,IAAvB;AACD,KAFD;;AAGAI,IAAAA,MAAM,CAACC,gBAAP,CAAwB,cAAxB,EAAwCF,mBAAxC;AAEA,WAAO,MAAY;AACjBC,MAAAA,MAAM,CAACE,mBAAP,CAA2B,cAA3B,EAA2CH,mBAA3C;AACD,KAFD;AAGD,GATQ,EASN,EATM,CAAT;AAWA,sBACE;AACE,IAAA,MAAM,EAAE,CAACb,KAAD,IAAUI,WAAV,IAAyBO,YAAY,KAAK,WADpD;AAEE,IAAA,SAAS,EAAC;AAFZ,KAIG,CAACX,KAAD,IAAUI,WAAV,GAAwB,IAAxB,gBACC,8CACE,oBAAC,CAAD;AAAG,IAAA,EAAE,EAAG,mBAAkBO,YAAuB;AAAjD,IADF,CALJ,CADF;AAYD;;;;"}
@@ -1,46 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- const React = require('react');
6
- const ReactAlpContext = require('react-alp-context');
7
- const reactAlpTranslate = require('react-alp-translate');
8
-
9
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e['default'] : e; }
10
-
11
- const React__default = /*#__PURE__*/_interopDefaultLegacy(React);
12
- const ReactAlpContext__default = /*#__PURE__*/_interopDefaultLegacy(ReactAlpContext);
13
-
14
- function ConnectionState({
15
- state
16
- }) {
17
- const ctx = React.useContext(ReactAlpContext__default);
18
- const notLoggedIn = !ctx.sanitizedState.user;
19
- const unloadingRef = React.useRef(false);
20
- const currentStateRef = React.useRef(state);
21
-
22
- if (unloadingRef.current === false) {
23
- currentStateRef.current = state;
24
- }
25
-
26
- const currentState = currentStateRef.current;
27
- React.useEffect(() => {
28
- const beforeUnloadHandler = () => {
29
- unloadingRef.current = true;
30
- };
31
-
32
- window.addEventListener('beforeunload', beforeUnloadHandler);
33
- return () => {
34
- window.removeEventListener('beforeunload', beforeUnloadHandler);
35
- };
36
- }, []);
37
- return /*#__PURE__*/React__default.createElement("div", {
38
- hidden: !state || notLoggedIn || currentState === 'connected',
39
- className: "alp-connection-state"
40
- }, !state || notLoggedIn ? null : /*#__PURE__*/React__default.createElement("div", null, /*#__PURE__*/React__default.createElement(reactAlpTranslate.T, {
41
- id: `connectionState.${currentState}`
42
- })));
43
- }
44
-
45
- exports.default = ConnectionState;
46
- //# sourceMappingURL=index-node12-dev.cjs.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index-node12-dev.cjs.js","sources":["../src/index.tsx"],"sourcesContent":["import type { ReactElement } from 'react';\nimport React, { useContext, useEffect, useRef } from 'react';\nimport ReactAlpContext from 'react-alp-context';\nimport { T } from 'react-alp-translate';\nimport '../ConnectionState.global.scss';\n\ntype State = null | 'connecting' | 'connected' | 'disconnected';\n\ninterface ConnectionStateProps {\n state: State;\n}\n\nexport default function ConnectionState({\n state,\n}: ConnectionStateProps): ReactElement {\n const ctx = useContext(ReactAlpContext);\n const notLoggedIn = !(ctx.sanitizedState as { user?: unknown }).user;\n\n const unloadingRef = useRef<boolean>(false);\n const currentStateRef = useRef(state);\n if (unloadingRef.current === false) {\n currentStateRef.current = state;\n }\n const currentState = currentStateRef.current;\n\n useEffect((): (() => void) => {\n const beforeUnloadHandler = (): void => {\n unloadingRef.current = true;\n };\n window.addEventListener('beforeunload', beforeUnloadHandler);\n\n return (): void => {\n window.removeEventListener('beforeunload', beforeUnloadHandler);\n };\n }, []);\n\n return (\n <div\n hidden={!state || notLoggedIn || currentState === 'connected'}\n className=\"alp-connection-state\"\n >\n {!state || notLoggedIn ? null : (\n <div>\n <T id={`connectionState.${currentState as string}`} />\n </div>\n )}\n </div>\n );\n}\n"],"names":["ConnectionState","state","ctx","useContext","ReactAlpContext","notLoggedIn","sanitizedState","user","unloadingRef","useRef","currentStateRef","current","currentState","useEffect","beforeUnloadHandler","window","addEventListener","removeEventListener","React","T"],"mappings":";;;;;;;;;;;;;AAYe,SAASA,eAAT,CAAyB;AACtCC,EAAAA;AADsC,CAAzB,EAEwB;AACrC,QAAMC,GAAG,GAAGC,gBAAU,CAACC,wBAAD,CAAtB;AACA,QAAMC,WAAW,GAAG,CAAEH,GAAG,CAACI,cAAL,CAA2CC,IAAhE;AAEA,QAAMC,YAAY,GAAGC,YAAM,CAAU,KAAV,CAA3B;AACA,QAAMC,eAAe,GAAGD,YAAM,CAACR,KAAD,CAA9B;;AACA,MAAIO,YAAY,CAACG,OAAb,KAAyB,KAA7B,EAAoC;AAClCD,IAAAA,eAAe,CAACC,OAAhB,GAA0BV,KAA1B;AACD;;AACD,QAAMW,YAAY,GAAGF,eAAe,CAACC,OAArC;AAEAE,EAAAA,eAAS,CAAC,MAAoB;AAC5B,UAAMC,mBAAmB,GAAG,MAAY;AACtCN,MAAAA,YAAY,CAACG,OAAb,GAAuB,IAAvB;AACD,KAFD;;AAGAI,IAAAA,MAAM,CAACC,gBAAP,CAAwB,cAAxB,EAAwCF,mBAAxC;AAEA,WAAO,MAAY;AACjBC,MAAAA,MAAM,CAACE,mBAAP,CAA2B,cAA3B,EAA2CH,mBAA3C;AACD,KAFD;AAGD,GATQ,EASN,EATM,CAAT;AAWA,sBACEI;AACE,IAAA,MAAM,EAAE,CAACjB,KAAD,IAAUI,WAAV,IAAyBO,YAAY,KAAK,WADpD;AAEE,IAAA,SAAS,EAAC;AAFZ,KAIG,CAACX,KAAD,IAAUI,WAAV,GAAwB,IAAxB,gBACCa,uDACEA,6BAACC,mBAAD;AAAG,IAAA,EAAE,EAAG,mBAAkBP,YAAuB;AAAjD,IADF,CALJ,CADF;AAYD;;;;"}