react-alp-connection-state 8.1.1 → 10.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/CHANGELOG.md +27 -0
- package/README.md +6 -6
- package/dist/definitions/index.d.ts +2 -2
- package/dist/definitions/index.d.ts.map +1 -1
- package/dist/index-browser.cjs.js +52 -45
- package/dist/index-browser.cjs.js.map +1 -1
- package/dist/index-browser.es.js +48 -43
- package/dist/index-browser.es.js.map +1 -1
- package/dist/index-node22.mjs +105 -0
- package/dist/index-node22.mjs.map +1 -0
- package/package.json +18 -28
- package/src/index.tsx +27 -27
- package/dist/index-node18.cjs +0 -102
- package/dist/index-node18.cjs.map +0 -1
- package/dist/index-node18.mjs +0 -100
- package/dist/index-node18.mjs.map +0 -1
- package/src/.eslintrc.json +0 -31
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,33 @@
|
|
|
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
|
+
## [10.0.0](https://github.com/christophehurpeau/alp/compare/react-alp-connection-state@9.0.0...react-alp-connection-state@10.0.0) (2025-10-27)
|
|
7
|
+
|
|
8
|
+
### ⚠ BREAKING CHANGES
|
|
9
|
+
|
|
10
|
+
* drop node 20 and build using esbuild
|
|
11
|
+
|
|
12
|
+
### Features
|
|
13
|
+
|
|
14
|
+
* drop node 20 and build using esbuild ([812c4c1](https://github.com/christophehurpeau/alp/commit/812c4c1b0ad19984e389af4382a8d1e60643e4f1))
|
|
15
|
+
|
|
16
|
+
## [9.0.0](https://github.com/christophehurpeau/alp/compare/react-alp-connection-state@8.1.1...react-alp-connection-state@9.0.0) (2025-08-02)
|
|
17
|
+
|
|
18
|
+
### ⚠ BREAKING CHANGES
|
|
19
|
+
|
|
20
|
+
* update dependencies and drop node 20
|
|
21
|
+
* update dev dependencies, replace parse-json-object-as-map with native JSON.parse, update koa
|
|
22
|
+
|
|
23
|
+
### Features
|
|
24
|
+
|
|
25
|
+
* update babel ([a4bf455](https://github.com/christophehurpeau/alp/commit/a4bf455c715134973c56693b7425aa05de5b10f9))
|
|
26
|
+
* update dependencies and drop node 20 ([fc5b322](https://github.com/christophehurpeau/alp/commit/fc5b322e076e9a3c7c4a235d16734b89fd85e211))
|
|
27
|
+
* update dev dependencies, replace parse-json-object-as-map with native JSON.parse, update koa ([5ae7723](https://github.com/christophehurpeau/alp/commit/5ae77238cafc573fe72c5eb63b103802b8b2e537))
|
|
28
|
+
|
|
29
|
+
### Bug Fixes
|
|
30
|
+
|
|
31
|
+
* **deps:** update react monorepo ([#611](https://github.com/christophehurpeau/alp/issues/611)) ([b9ece4d](https://github.com/christophehurpeau/alp/commit/b9ece4dc070bcd49fa6c4a40534162d10087405b))
|
|
32
|
+
|
|
6
33
|
## [8.1.1](https://github.com/christophehurpeau/alp/compare/react-alp-connection-state@8.1.0...react-alp-connection-state@8.1.1) (2024-01-06)
|
|
7
34
|
|
|
8
35
|
Note: no notable changes
|
package/README.md
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
<
|
|
1
|
+
<h1 align="center">
|
|
2
2
|
react-alp-connection-state
|
|
3
|
-
</
|
|
3
|
+
</h1>
|
|
4
4
|
|
|
5
5
|
<p align="center">
|
|
6
6
|
connection state
|
|
7
7
|
</p>
|
|
8
8
|
|
|
9
9
|
<p align="center">
|
|
10
|
-
<a href="https://npmjs.org/package/react-alp-connection-state"><img src="https://img.shields.io/npm/v/react-alp-connection-state.svg?style=flat-square"></a>
|
|
11
|
-
<a href="https://npmjs.org/package/react-alp-connection-state"><img src="https://img.shields.io/npm/dw/react-alp-connection-state.svg?style=flat-square"></a>
|
|
12
|
-
<a href="https://npmjs.org/package/react-alp-connection-state"><img src="https://img.shields.io/node/v/react-alp-connection-state.svg?style=flat-square"></a>
|
|
13
|
-
<a href="https://npmjs.org/package/react-alp-connection-state"><img src="https://img.shields.io/npm/types/react-alp-connection-state.svg?style=flat-square"></a>
|
|
10
|
+
<a href="https://npmjs.org/package/react-alp-connection-state"><img src="https://img.shields.io/npm/v/react-alp-connection-state.svg?style=flat-square" alt="npm version"></a>
|
|
11
|
+
<a href="https://npmjs.org/package/react-alp-connection-state"><img src="https://img.shields.io/npm/dw/react-alp-connection-state.svg?style=flat-square" alt="npm downloads"></a>
|
|
12
|
+
<a href="https://npmjs.org/package/react-alp-connection-state"><img src="https://img.shields.io/node/v/react-alp-connection-state.svg?style=flat-square" alt="node version"></a>
|
|
13
|
+
<a href="https://npmjs.org/package/react-alp-connection-state"><img src="https://img.shields.io/npm/types/react-alp-connection-state.svg?style=flat-square" alt="types"></a>
|
|
14
14
|
</p>
|
|
15
15
|
|
|
16
16
|
## Install
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ReactElement, ReactNode } from
|
|
1
|
+
import type { ReactElement, ReactNode } from "react";
|
|
2
2
|
declare const defaultTheme: {
|
|
3
3
|
container: {
|
|
4
4
|
backgroundColor: string;
|
|
@@ -13,7 +13,7 @@ declare const defaultTheme: {
|
|
|
13
13
|
backgroundColorConnected: string;
|
|
14
14
|
};
|
|
15
15
|
export type ConnectionStateTheme = typeof defaultTheme;
|
|
16
|
-
export type State =
|
|
16
|
+
export type State = "connected" | "connecting" | "disconnected" | null;
|
|
17
17
|
export interface ConnectionStateProps {
|
|
18
18
|
theme?: ConnectionStateTheme;
|
|
19
19
|
forceHidden?: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAWrD,QAAA,MAAM,YAAY;;;;;;;;;;;;CASjB,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG,OAAO,YAAY,CAAC;AACvD,MAAM,MAAM,KAAK,GAAG,WAAW,GAAG,YAAY,GAAG,cAAc,GAAG,IAAI,CAAC;AAEvE,MAAM,WAAW,oBAAoB;IACnC,KAAK,CAAC,EAAE,oBAAoB,CAAC;IAC7B,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,KAAK,EAAE,KAAK,CAAC;IACb,QAAQ,EAAE,WAAW,CAAC,SAAS,CAAC,CAAC;CAClC;AAuDD,wBAAgB,eAAe,CAAC,EAC9B,KAAK,EACL,WAAW,EACX,KAAK,EACL,QAAQ,GACT,EAAE,oBAAoB,GAAG,YAAY,GAAG,IAAI,CAgD5C"}
|
|
@@ -1,37 +1,33 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
+
|
|
5
5
|
const jsxRuntime = require('react/jsx-runtime');
|
|
6
|
+
const react = require('react');
|
|
7
|
+
const reactNativeWeb = require('react-native-web');
|
|
6
8
|
|
|
7
9
|
const defaultTheme = {
|
|
8
10
|
container: {
|
|
9
|
-
backgroundColor:
|
|
10
|
-
color:
|
|
11
|
-
|
|
12
|
-
textShadowOffset: {
|
|
13
|
-
width: 0,
|
|
14
|
-
height: -1
|
|
15
|
-
},
|
|
11
|
+
backgroundColor: "rgba(247, 25, 0, 0.8)",
|
|
12
|
+
color: "#fff",
|
|
13
|
+
textShadowOffset: { width: 0, height: -1 },
|
|
16
14
|
textShadowRadius: 1
|
|
17
15
|
},
|
|
18
|
-
backgroundColorConnected:
|
|
16
|
+
backgroundColorConnected: "rgba(25, 200, 60, 0.8)"
|
|
19
17
|
};
|
|
18
|
+
const zDepth1 = "0 2px 3px 0 rgba(0, 0, 0, 0.15), 0 2px 5px 0 rgba(0, 0, 0, 0.2)";
|
|
20
19
|
const useCreateCalcNative = () => {
|
|
21
|
-
const dimensions =
|
|
20
|
+
const dimensions = reactNativeWeb.useWindowDimensions();
|
|
22
21
|
return (webCalc, createCalc) => createCalc(dimensions);
|
|
23
22
|
};
|
|
24
23
|
const useCreateCalcWeb = () => {
|
|
25
|
-
return webCalc => `calc(${webCalc})`;
|
|
24
|
+
return (webCalc) => `calc(${webCalc})`;
|
|
26
25
|
};
|
|
27
|
-
const useCreateCalc =
|
|
28
|
-
|
|
29
|
-
// example: const left = createCalc('50% - 100px', ({ width }) => width / 2 - 100);
|
|
30
|
-
|
|
31
|
-
const styles = reactNative.StyleSheet.create({
|
|
26
|
+
const useCreateCalc = reactNativeWeb.Platform.OS === "web" ? useCreateCalcWeb : useCreateCalcNative;
|
|
27
|
+
const styles = reactNativeWeb.StyleSheet.create({
|
|
32
28
|
connectionStateContainer: {
|
|
33
29
|
backgroundColor: defaultTheme.container.backgroundColor,
|
|
34
|
-
position:
|
|
30
|
+
position: "absolute",
|
|
35
31
|
top: 0,
|
|
36
32
|
right: 0,
|
|
37
33
|
left: 0,
|
|
@@ -39,24 +35,25 @@ const styles = reactNative.StyleSheet.create({
|
|
|
39
35
|
color: defaultTheme.container.color,
|
|
40
36
|
textShadowOffset: defaultTheme.container.textShadowOffset,
|
|
41
37
|
textShadowRadius: defaultTheme.container.textShadowRadius,
|
|
42
|
-
boxShadow:
|
|
38
|
+
boxShadow: zDepth1,
|
|
43
39
|
zIndex: 9,
|
|
44
|
-
transition
|
|
40
|
+
// @ts-expect-error -- transition is not a valid style
|
|
41
|
+
transition: "top .8s, background-color .2s"
|
|
45
42
|
},
|
|
46
43
|
hide: {
|
|
47
44
|
top: -24
|
|
48
45
|
},
|
|
49
46
|
connectionStateText: {
|
|
50
47
|
backgroundColor: defaultTheme.container.backgroundColor,
|
|
51
|
-
position:
|
|
48
|
+
position: "absolute",
|
|
52
49
|
width: 200,
|
|
53
50
|
height: 22,
|
|
54
51
|
lineHeight: 22,
|
|
55
52
|
top: 2,
|
|
56
|
-
textAlign:
|
|
53
|
+
textAlign: "center",
|
|
57
54
|
borderBottomLeftRadius: 5,
|
|
58
55
|
borderBottomRightRadius: 5,
|
|
59
|
-
transition:
|
|
56
|
+
transition: "background-color .2s"
|
|
60
57
|
}
|
|
61
58
|
});
|
|
62
59
|
function ConnectionState({
|
|
@@ -67,35 +64,45 @@ function ConnectionState({
|
|
|
67
64
|
}) {
|
|
68
65
|
const unloadingRef = react.useRef(false);
|
|
69
66
|
const createCalc = useCreateCalc();
|
|
70
|
-
const left = createCalc(
|
|
71
|
-
width
|
|
72
|
-
}) => width / 2 - 100); // TODO use calc() in web ?
|
|
73
|
-
|
|
67
|
+
const left = createCalc("50% - 100px", ({ width }) => width / 2 - 100);
|
|
74
68
|
react.useEffect(() => {
|
|
75
|
-
if (typeof
|
|
69
|
+
if (typeof globalThis === "undefined") return;
|
|
76
70
|
const beforeUnloadHandler = () => {
|
|
77
71
|
unloadingRef.current = true;
|
|
78
72
|
};
|
|
79
|
-
window.addEventListener(
|
|
73
|
+
window.addEventListener("beforeunload", beforeUnloadHandler);
|
|
80
74
|
return () => {
|
|
81
|
-
window.removeEventListener(
|
|
75
|
+
window.removeEventListener("beforeunload", beforeUnloadHandler);
|
|
82
76
|
};
|
|
83
77
|
}, []);
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
children:
|
|
97
|
-
|
|
98
|
-
|
|
78
|
+
const shouldHide = forceHidden || !state || state === "connected";
|
|
79
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
80
|
+
reactNativeWeb.View,
|
|
81
|
+
{
|
|
82
|
+
style: [
|
|
83
|
+
styles.connectionStateContainer,
|
|
84
|
+
shouldHide && styles.hide,
|
|
85
|
+
theme?.container,
|
|
86
|
+
state === "connected" && {
|
|
87
|
+
backgroundColor: (theme || defaultTheme).backgroundColorConnected
|
|
88
|
+
}
|
|
89
|
+
],
|
|
90
|
+
children: !state ? null : /* @__PURE__ */ jsxRuntime.jsx(
|
|
91
|
+
reactNativeWeb.Text,
|
|
92
|
+
{
|
|
93
|
+
style: [
|
|
94
|
+
styles.connectionStateText,
|
|
95
|
+
theme && { backgroundColor: theme.container.backgroundColor },
|
|
96
|
+
state === "connected" && {
|
|
97
|
+
backgroundColor: (theme || defaultTheme).backgroundColorConnected
|
|
98
|
+
},
|
|
99
|
+
{ left }
|
|
100
|
+
],
|
|
101
|
+
children
|
|
102
|
+
}
|
|
103
|
+
)
|
|
104
|
+
}
|
|
105
|
+
);
|
|
99
106
|
}
|
|
100
107
|
|
|
101
108
|
exports.ConnectionState = ConnectionState;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index-browser.cjs.js","sources":["../src/index.tsx"],"sourcesContent":["import type { ReactElement, ReactNode } from
|
|
1
|
+
{"version":3,"file":"index-browser.cjs.js","sources":["../src/index.tsx"],"sourcesContent":["import type { ReactElement, ReactNode } from \"react\";\nimport { useEffect, useRef } from \"react\";\nimport type { DimensionValue, ScaledSize } from \"react-native\";\nimport {\n Platform,\n StyleSheet,\n Text,\n View,\n useWindowDimensions,\n} from \"react-native\";\n\nconst defaultTheme = {\n container: {\n backgroundColor: \"rgba(247, 25, 0, 0.8)\",\n color: \"#fff\",\n textShadowColor: \"#111\",\n textShadowOffset: { width: 0, height: -1 },\n textShadowRadius: 1,\n },\n backgroundColorConnected: \"rgba(25, 200, 60, 0.8)\",\n};\n\nexport type ConnectionStateTheme = typeof defaultTheme;\nexport type State = \"connected\" | \"connecting\" | \"disconnected\" | null;\n\nexport interface ConnectionStateProps {\n theme?: ConnectionStateTheme;\n forceHidden?: boolean;\n state: State;\n children: NonNullable<ReactNode>;\n}\n\nconst zDepth1 =\n \"0 2px 3px 0 rgba(0, 0, 0, 0.15), 0 2px 5px 0 rgba(0, 0, 0, 0.2)\";\n\ntype CreateCalc = (\n webCalc: string,\n createCalc: (dimensions: ScaledSize) => DimensionValue,\n) => DimensionValue;\n\nconst useCreateCalcNative = (): CreateCalc => {\n const dimensions = useWindowDimensions();\n return (webCalc, createCalc) => createCalc(dimensions);\n};\nconst useCreateCalcWeb = (): CreateCalc => {\n return (webCalc) => `calc(${webCalc})` as DimensionValue;\n};\nconst useCreateCalc =\n Platform.OS === \"web\" ? useCreateCalcWeb : useCreateCalcNative;\n\n// example: const left = createCalc('50% - 100px', ({ width }) => width / 2 - 100);\n\nconst styles = StyleSheet.create({\n connectionStateContainer: {\n backgroundColor: defaultTheme.container.backgroundColor,\n position: \"absolute\",\n top: 0,\n right: 0,\n left: 0,\n height: 2,\n color: defaultTheme.container.color,\n textShadowOffset: defaultTheme.container.textShadowOffset,\n textShadowRadius: defaultTheme.container.textShadowRadius,\n boxShadow: zDepth1,\n zIndex: 9,\n // @ts-expect-error -- transition is not a valid style\n transition: \"top .8s, background-color .2s\",\n },\n hide: {\n top: -24,\n },\n connectionStateText: {\n backgroundColor: defaultTheme.container.backgroundColor,\n position: \"absolute\",\n width: 200,\n height: 22,\n lineHeight: 22,\n top: 2,\n textAlign: \"center\",\n borderBottomLeftRadius: 5,\n borderBottomRightRadius: 5,\n transition: \"background-color .2s\",\n },\n});\n\nexport function ConnectionState({\n theme,\n forceHidden,\n state,\n children,\n}: ConnectionStateProps): ReactElement | null {\n const unloadingRef = useRef<boolean>(false);\n\n const createCalc = useCreateCalc();\n const left = createCalc(\"50% - 100px\", ({ width }) => width / 2 - 100); // TODO use calc() in web ?\n\n useEffect((): (() => void) | undefined => {\n if (typeof globalThis === \"undefined\") return;\n\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 const shouldHide = forceHidden || !state || state === \"connected\";\n\n return (\n <View\n style={[\n styles.connectionStateContainer,\n shouldHide && styles.hide,\n theme?.container,\n state === \"connected\" && {\n backgroundColor: (theme || defaultTheme).backgroundColorConnected,\n },\n ]}\n >\n {!state ? null : (\n <Text\n style={[\n styles.connectionStateText,\n theme && { backgroundColor: theme.container.backgroundColor },\n state === \"connected\" && {\n backgroundColor: (theme || defaultTheme).backgroundColorConnected,\n },\n { left },\n ]}\n >\n {children}\n </Text>\n )}\n </View>\n );\n}\n"],"names":["useWindowDimensions","Platform","StyleSheet","useRef","useEffect","jsx","View","Text"],"mappings":";;;;;;;;AAWA,MAAM,YAAA,GAAe;AAAA,EACnB,SAAA,EAAW;AAAA,IACT,eAAA,EAAiB,uBAAA;AAAA,IACjB,KAAA,EAAO,MAAA;AAAA,IAEP,gBAAA,EAAkB,EAAE,KAAA,EAAO,CAAA,EAAG,QAAQ,EAAA,EAAG;AAAA,IACzC,gBAAA,EAAkB;AAAA,GACpB;AAAA,EACA,wBAAA,EAA0B;AAC5B,CAAA;AAYA,MAAM,OAAA,GACJ,iEAAA;AAOF,MAAM,sBAAsB,MAAkB;AAC5C,EAAA,MAAM,aAAaA,kCAAA,EAAoB;AACvC,EAAA,OAAO,CAAC,OAAA,EAAS,UAAA,KAAe,UAAA,CAAW,UAAU,CAAA;AACvD,CAAA;AACA,MAAM,mBAAmB,MAAkB;AACzC,EAAA,OAAO,CAAC,OAAA,KAAY,CAAA,KAAA,EAAQ,OAAO,CAAA,CAAA,CAAA;AACrC,CAAA;AACA,MAAM,aAAA,GACJC,uBAAA,CAAS,EAAA,KAAO,KAAA,GAAQ,gBAAA,GAAmB,mBAAA;AAI7C,MAAM,MAAA,GAASC,0BAAW,MAAA,CAAO;AAAA,EAC/B,wBAAA,EAA0B;AAAA,IACxB,eAAA,EAAiB,aAAa,SAAA,CAAU,eAAA;AAAA,IACxC,QAAA,EAAU,UAAA;AAAA,IACV,GAAA,EAAK,CAAA;AAAA,IACL,KAAA,EAAO,CAAA;AAAA,IACP,IAAA,EAAM,CAAA;AAAA,IACN,MAAA,EAAQ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O,MAAY;AACjB,MAAA,MAAA,CAAO,mBAAA,CAAoB,gBAAgB,mBAAmB,CAAA;AAAA,KAChE;AAAA,GACF,EAAG,EAAE,CAAA;AAEL,EAAA,MAAM,UAAA,GAAa,WAAA,IAAe,CAAC,KAAA,IAAS,KAAA,KAAU,WAAA;AAEtD,EAAA,uBACEC,cAAA;AAAA,IAACC,mBAAA;AAAA,IAAA;AAAA,MACC,KAAA,EAAO;AAAA,QACL,MAAA,CAAO,wBAAA;AAAA,QACP,cAAc,MAAA,CAAO,IAAA;AAAA,QACrB,KAAA,EAAO,SAAA;AAAA,QACP,UAAU,WAAA,IAAe;AAAA,UACvB,eAAA,EAAA,CAAkB,SAAS,YAAA,EAAc;AAAA;AAC3C,OACF;AAAA,MAEC,QAAA,EAAA,CAAC,QAAQ,IAAA,mBACRD,cAAA;AAAA,QAACE,mBAAA;AAAA,QAAA;AAAA,UACC,KAAA,EAAO;AAAA,YACL,MAAA,CAAO,mBAAA;AAAA,YACP,KAAA,IAAS,EAAE,eAAA,EAAiB,KAAA,CAAM,UAAU,eAAA,EAAgB;AAAA,YAC5D,UAAU,WAAA,IAAe;AAAA,cACvB,eAAA,EAAA,CAAkB,SAAS,YAAA,EAAc;AAAA,aAC3C;AAAA,YACA,EAAE,IAAA;AAAK,WACT;AAAA,UAEC;AAAA;AAAA;AACH;AAAA,GAEJ;AAEJ;;;;"}
|
package/dist/index-browser.es.js
CHANGED
|
@@ -1,35 +1,29 @@
|
|
|
1
|
-
import { useRef, useEffect } from 'react';
|
|
2
|
-
import { Platform, StyleSheet, useWindowDimensions, View, Text } from 'react-native';
|
|
3
1
|
import { jsx } from 'react/jsx-runtime';
|
|
2
|
+
import { useRef, useEffect } from 'react';
|
|
3
|
+
import { Platform, StyleSheet, useWindowDimensions, View, Text } from 'react-native-web';
|
|
4
4
|
|
|
5
5
|
const defaultTheme = {
|
|
6
6
|
container: {
|
|
7
|
-
backgroundColor:
|
|
8
|
-
color:
|
|
9
|
-
|
|
10
|
-
textShadowOffset: {
|
|
11
|
-
width: 0,
|
|
12
|
-
height: -1
|
|
13
|
-
},
|
|
7
|
+
backgroundColor: "rgba(247, 25, 0, 0.8)",
|
|
8
|
+
color: "#fff",
|
|
9
|
+
textShadowOffset: { width: 0, height: -1 },
|
|
14
10
|
textShadowRadius: 1
|
|
15
11
|
},
|
|
16
|
-
backgroundColorConnected:
|
|
12
|
+
backgroundColorConnected: "rgba(25, 200, 60, 0.8)"
|
|
17
13
|
};
|
|
14
|
+
const zDepth1 = "0 2px 3px 0 rgba(0, 0, 0, 0.15), 0 2px 5px 0 rgba(0, 0, 0, 0.2)";
|
|
18
15
|
const useCreateCalcNative = () => {
|
|
19
16
|
const dimensions = useWindowDimensions();
|
|
20
17
|
return (webCalc, createCalc) => createCalc(dimensions);
|
|
21
18
|
};
|
|
22
19
|
const useCreateCalcWeb = () => {
|
|
23
|
-
return webCalc => `calc(${webCalc})`;
|
|
20
|
+
return (webCalc) => `calc(${webCalc})`;
|
|
24
21
|
};
|
|
25
|
-
const useCreateCalc = Platform.OS ===
|
|
26
|
-
|
|
27
|
-
// example: const left = createCalc('50% - 100px', ({ width }) => width / 2 - 100);
|
|
28
|
-
|
|
22
|
+
const useCreateCalc = Platform.OS === "web" ? useCreateCalcWeb : useCreateCalcNative;
|
|
29
23
|
const styles = StyleSheet.create({
|
|
30
24
|
connectionStateContainer: {
|
|
31
25
|
backgroundColor: defaultTheme.container.backgroundColor,
|
|
32
|
-
position:
|
|
26
|
+
position: "absolute",
|
|
33
27
|
top: 0,
|
|
34
28
|
right: 0,
|
|
35
29
|
left: 0,
|
|
@@ -37,24 +31,25 @@ const styles = StyleSheet.create({
|
|
|
37
31
|
color: defaultTheme.container.color,
|
|
38
32
|
textShadowOffset: defaultTheme.container.textShadowOffset,
|
|
39
33
|
textShadowRadius: defaultTheme.container.textShadowRadius,
|
|
40
|
-
boxShadow:
|
|
34
|
+
boxShadow: zDepth1,
|
|
41
35
|
zIndex: 9,
|
|
42
|
-
transition
|
|
36
|
+
// @ts-expect-error -- transition is not a valid style
|
|
37
|
+
transition: "top .8s, background-color .2s"
|
|
43
38
|
},
|
|
44
39
|
hide: {
|
|
45
40
|
top: -24
|
|
46
41
|
},
|
|
47
42
|
connectionStateText: {
|
|
48
43
|
backgroundColor: defaultTheme.container.backgroundColor,
|
|
49
|
-
position:
|
|
44
|
+
position: "absolute",
|
|
50
45
|
width: 200,
|
|
51
46
|
height: 22,
|
|
52
47
|
lineHeight: 22,
|
|
53
48
|
top: 2,
|
|
54
|
-
textAlign:
|
|
49
|
+
textAlign: "center",
|
|
55
50
|
borderBottomLeftRadius: 5,
|
|
56
51
|
borderBottomRightRadius: 5,
|
|
57
|
-
transition:
|
|
52
|
+
transition: "background-color .2s"
|
|
58
53
|
}
|
|
59
54
|
});
|
|
60
55
|
function ConnectionState({
|
|
@@ -65,35 +60,45 @@ function ConnectionState({
|
|
|
65
60
|
}) {
|
|
66
61
|
const unloadingRef = useRef(false);
|
|
67
62
|
const createCalc = useCreateCalc();
|
|
68
|
-
const left = createCalc(
|
|
69
|
-
width
|
|
70
|
-
}) => width / 2 - 100); // TODO use calc() in web ?
|
|
71
|
-
|
|
63
|
+
const left = createCalc("50% - 100px", ({ width }) => width / 2 - 100);
|
|
72
64
|
useEffect(() => {
|
|
73
|
-
if (typeof
|
|
65
|
+
if (typeof globalThis === "undefined") return;
|
|
74
66
|
const beforeUnloadHandler = () => {
|
|
75
67
|
unloadingRef.current = true;
|
|
76
68
|
};
|
|
77
|
-
window.addEventListener(
|
|
69
|
+
window.addEventListener("beforeunload", beforeUnloadHandler);
|
|
78
70
|
return () => {
|
|
79
|
-
window.removeEventListener(
|
|
71
|
+
window.removeEventListener("beforeunload", beforeUnloadHandler);
|
|
80
72
|
};
|
|
81
73
|
}, []);
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
children:
|
|
95
|
-
|
|
96
|
-
|
|
74
|
+
const shouldHide = forceHidden || !state || state === "connected";
|
|
75
|
+
return /* @__PURE__ */ jsx(
|
|
76
|
+
View,
|
|
77
|
+
{
|
|
78
|
+
style: [
|
|
79
|
+
styles.connectionStateContainer,
|
|
80
|
+
shouldHide && styles.hide,
|
|
81
|
+
theme?.container,
|
|
82
|
+
state === "connected" && {
|
|
83
|
+
backgroundColor: (theme || defaultTheme).backgroundColorConnected
|
|
84
|
+
}
|
|
85
|
+
],
|
|
86
|
+
children: !state ? null : /* @__PURE__ */ jsx(
|
|
87
|
+
Text,
|
|
88
|
+
{
|
|
89
|
+
style: [
|
|
90
|
+
styles.connectionStateText,
|
|
91
|
+
theme && { backgroundColor: theme.container.backgroundColor },
|
|
92
|
+
state === "connected" && {
|
|
93
|
+
backgroundColor: (theme || defaultTheme).backgroundColorConnected
|
|
94
|
+
},
|
|
95
|
+
{ left }
|
|
96
|
+
],
|
|
97
|
+
children
|
|
98
|
+
}
|
|
99
|
+
)
|
|
100
|
+
}
|
|
101
|
+
);
|
|
97
102
|
}
|
|
98
103
|
|
|
99
104
|
export { ConnectionState };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index-browser.es.js","sources":["../src/index.tsx"],"sourcesContent":["import type { ReactElement, ReactNode } from
|
|
1
|
+
{"version":3,"file":"index-browser.es.js","sources":["../src/index.tsx"],"sourcesContent":["import type { ReactElement, ReactNode } from \"react\";\nimport { useEffect, useRef } from \"react\";\nimport type { DimensionValue, ScaledSize } from \"react-native\";\nimport {\n Platform,\n StyleSheet,\n Text,\n View,\n useWindowDimensions,\n} from \"react-native\";\n\nconst defaultTheme = {\n container: {\n backgroundColor: \"rgba(247, 25, 0, 0.8)\",\n color: \"#fff\",\n textShadowColor: \"#111\",\n textShadowOffset: { width: 0, height: -1 },\n textShadowRadius: 1,\n },\n backgroundColorConnected: \"rgba(25, 200, 60, 0.8)\",\n};\n\nexport type ConnectionStateTheme = typeof defaultTheme;\nexport type State = \"connected\" | \"connecting\" | \"disconnected\" | null;\n\nexport interface ConnectionStateProps {\n theme?: ConnectionStateTheme;\n forceHidden?: boolean;\n state: State;\n children: NonNullable<ReactNode>;\n}\n\nconst zDepth1 =\n \"0 2px 3px 0 rgba(0, 0, 0, 0.15), 0 2px 5px 0 rgba(0, 0, 0, 0.2)\";\n\ntype CreateCalc = (\n webCalc: string,\n createCalc: (dimensions: ScaledSize) => DimensionValue,\n) => DimensionValue;\n\nconst useCreateCalcNative = (): CreateCalc => {\n const dimensions = useWindowDimensions();\n return (webCalc, createCalc) => createCalc(dimensions);\n};\nconst useCreateCalcWeb = (): CreateCalc => {\n return (webCalc) => `calc(${webCalc})` as DimensionValue;\n};\nconst useCreateCalc =\n Platform.OS === \"web\" ? useCreateCalcWeb : useCreateCalcNative;\n\n// example: const left = createCalc('50% - 100px', ({ width }) => width / 2 - 100);\n\nconst styles = StyleSheet.create({\n connectionStateContainer: {\n backgroundColor: defaultTheme.container.backgroundColor,\n position: \"absolute\",\n top: 0,\n right: 0,\n left: 0,\n height: 2,\n color: defaultTheme.container.color,\n textShadowOffset: defaultTheme.container.textShadowOffset,\n textShadowRadius: defaultTheme.container.textShadowRadius,\n boxShadow: zDepth1,\n zIndex: 9,\n // @ts-expect-error -- transition is not a valid style\n transition: \"top .8s, background-color .2s\",\n },\n hide: {\n top: -24,\n },\n connectionStateText: {\n backgroundColor: defaultTheme.container.backgroundColor,\n position: \"absolute\",\n width: 200,\n height: 22,\n lineHeight: 22,\n top: 2,\n textAlign: \"center\",\n borderBottomLeftRadius: 5,\n borderBottomRightRadius: 5,\n transition: \"background-color .2s\",\n },\n});\n\nexport function ConnectionState({\n theme,\n forceHidden,\n state,\n children,\n}: ConnectionStateProps): ReactElement | null {\n const unloadingRef = useRef<boolean>(false);\n\n const createCalc = useCreateCalc();\n const left = createCalc(\"50% - 100px\", ({ width }) => width / 2 - 100); // TODO use calc() in web ?\n\n useEffect((): (() => void) | undefined => {\n if (typeof globalThis === \"undefined\") return;\n\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 const shouldHide = forceHidden || !state || state === \"connected\";\n\n return (\n <View\n style={[\n styles.connectionStateContainer,\n shouldHide && styles.hide,\n theme?.container,\n state === \"connected\" && {\n backgroundColor: (theme || defaultTheme).backgroundColorConnected,\n },\n ]}\n >\n {!state ? null : (\n <Text\n style={[\n styles.connectionStateText,\n theme && { backgroundColor: theme.container.backgroundColor },\n state === \"connected\" && {\n backgroundColor: (theme || defaultTheme).backgroundColorConnected,\n },\n { left },\n ]}\n >\n {children}\n </Text>\n )}\n </View>\n );\n}\n"],"names":[],"mappings":";;;;AAWA,MAAM,YAAA,GAAe;AAAA,EACnB,SAAA,EAAW;AAAA,IACT,eAAA,EAAiB,uBAAA;AAAA,IACjB,KAAA,EAAO,MAAA;AAAA,IAEP,gBAAA,EAAkB,EAAE,KAAA,EAAO,CAAA,EAAG,QAAQ,EAAA,EAAG;AAAA,IACzC,gBAAA,EAAkB;AAAA,GACpB;AAAA,EACA,wBAAA,EAA0B;AAC5B,CAAA;AAYA,MAAM,OAAA,GACJ,iEAAA;AAOF,MAAM,sBAAsB,MAAkB;AAC5C,EAAA,MAAM,aAAa,mBAAA,EAAoB;AACvC,EAAA,OAAO,CAAC,OAAA,EAAS,UAAA,KAAe,UAAA,CAAW,UAAU,CAAA;AACvD,CAAA;AACA,MAAM,mBAAmB,MAAkB;AACzC,EAAA,OAAO,CAAC,OAAA,KAAY,CAAA,KAAA,EAAQ,OAAO,CAAA,CAAA,CAAA;AACrC,CAAA;AACA,MAAM,aAAA,GACJ,QAAA,CAAS,EAAA,KAAO,KAAA,GAAQ,gBAAA,GAAmB,mBAAA;AAI7C,MAAM,MAAA,GAAS,WAAW,MAAA,CAAO;A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AAgC;AACxC,IAAA,IAAI,OAAO,eAAe,WAAA,EAAa;AAEvC,IAAA,MAAM,sBAAsB,MAAY;AACtC,MAAA,YAAA,CAAa,OAAA,GAAU,IAAA;AAAA,KACzB;AACA,IAAA,MAAA,CAAO,gBAAA,CAAiB,gBAAgB,mBAAmB,CAAA;AAE3D,IAAA,OAAO,MAAY;AACjB,MAAA,MAAA,CAAO,mBAAA,CAAoB,gBAAgB,mBAAmB,CAAA;AAAA,KAChE;AAAA,GACF,EAAG,EAAE,CAAA;AAEL,EAAA,MAAM,UAAA,GAAa,WAAA,IAAe,CAAC,KAAA,IAAS,KAAA,KAAU,WAAA;AAEtD,EAAA,uBACE,GAAA;AAAA,IAAC,IAAA;AAAA,IAAA;AAAA,MACC,KAAA,EAAO;AAAA,QACL,MAAA,CAAO,wBAAA;AAAA,QACP,cAAc,MAAA,CAAO,IAAA;AAAA,QACrB,KAAA,EAAO,SAAA;AAAA,QACP,UAAU,WAAA,IAAe;AAAA,UACvB,eAAA,EAAA,CAAkB,SAAS,YAAA,EAAc;AAAA;AAC3C,OACF;AAAA,MAEC,QAAA,EAAA,CAAC,QAAQ,IAAA,mBACR,GAAA;AAAA,QAAC,IAAA;AAAA,QAAA;AAAA,UACC,KAAA,EAAO;AAAA,YACL,MAAA,CAAO,mBAAA;AAAA,YACP,KAAA,IAAS,EAAE,eAAA,EAAiB,KAAA,CAAM,UAAU,eAAA,EAAgB;AAAA,YAC5D,UAAU,WAAA,IAAe;AAAA,cACvB,eAAA,EAAA,CAAkB,SAAS,YAAA,EAAc;AAAA,aAC3C;AAAA,YACA,EAAE,IAAA;AAAK,WACT;AAAA,UAEC;AAAA;AAAA;AACH;AAAA,GAEJ;AAEJ;;;;"}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { jsx } from 'react/jsx-runtime';
|
|
2
|
+
import { useRef, useEffect } from 'react';
|
|
3
|
+
import { Platform, StyleSheet, useWindowDimensions, View, Text } from 'react-native';
|
|
4
|
+
|
|
5
|
+
const defaultTheme = {
|
|
6
|
+
container: {
|
|
7
|
+
backgroundColor: "rgba(247, 25, 0, 0.8)",
|
|
8
|
+
color: "#fff",
|
|
9
|
+
textShadowOffset: { width: 0, height: -1 },
|
|
10
|
+
textShadowRadius: 1
|
|
11
|
+
},
|
|
12
|
+
backgroundColorConnected: "rgba(25, 200, 60, 0.8)"
|
|
13
|
+
};
|
|
14
|
+
const zDepth1 = "0 2px 3px 0 rgba(0, 0, 0, 0.15), 0 2px 5px 0 rgba(0, 0, 0, 0.2)";
|
|
15
|
+
const useCreateCalcNative = () => {
|
|
16
|
+
const dimensions = useWindowDimensions();
|
|
17
|
+
return (webCalc, createCalc) => createCalc(dimensions);
|
|
18
|
+
};
|
|
19
|
+
const useCreateCalcWeb = () => {
|
|
20
|
+
return (webCalc) => `calc(${webCalc})`;
|
|
21
|
+
};
|
|
22
|
+
const useCreateCalc = Platform.OS === "web" ? useCreateCalcWeb : useCreateCalcNative;
|
|
23
|
+
const styles = StyleSheet.create({
|
|
24
|
+
connectionStateContainer: {
|
|
25
|
+
backgroundColor: defaultTheme.container.backgroundColor,
|
|
26
|
+
position: "absolute",
|
|
27
|
+
top: 0,
|
|
28
|
+
right: 0,
|
|
29
|
+
left: 0,
|
|
30
|
+
height: 2,
|
|
31
|
+
color: defaultTheme.container.color,
|
|
32
|
+
textShadowOffset: defaultTheme.container.textShadowOffset,
|
|
33
|
+
textShadowRadius: defaultTheme.container.textShadowRadius,
|
|
34
|
+
boxShadow: zDepth1,
|
|
35
|
+
zIndex: 9,
|
|
36
|
+
// @ts-expect-error -- transition is not a valid style
|
|
37
|
+
transition: "top .8s, background-color .2s"
|
|
38
|
+
},
|
|
39
|
+
hide: {
|
|
40
|
+
top: -24
|
|
41
|
+
},
|
|
42
|
+
connectionStateText: {
|
|
43
|
+
backgroundColor: defaultTheme.container.backgroundColor,
|
|
44
|
+
position: "absolute",
|
|
45
|
+
width: 200,
|
|
46
|
+
height: 22,
|
|
47
|
+
lineHeight: 22,
|
|
48
|
+
top: 2,
|
|
49
|
+
textAlign: "center",
|
|
50
|
+
borderBottomLeftRadius: 5,
|
|
51
|
+
borderBottomRightRadius: 5,
|
|
52
|
+
transition: "background-color .2s"
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
function ConnectionState({
|
|
56
|
+
theme,
|
|
57
|
+
forceHidden,
|
|
58
|
+
state,
|
|
59
|
+
children
|
|
60
|
+
}) {
|
|
61
|
+
const unloadingRef = useRef(false);
|
|
62
|
+
const createCalc = useCreateCalc();
|
|
63
|
+
const left = createCalc("50% - 100px", ({ width }) => width / 2 - 100);
|
|
64
|
+
useEffect(() => {
|
|
65
|
+
if (typeof globalThis === "undefined") return;
|
|
66
|
+
const beforeUnloadHandler = () => {
|
|
67
|
+
unloadingRef.current = true;
|
|
68
|
+
};
|
|
69
|
+
window.addEventListener("beforeunload", beforeUnloadHandler);
|
|
70
|
+
return () => {
|
|
71
|
+
window.removeEventListener("beforeunload", beforeUnloadHandler);
|
|
72
|
+
};
|
|
73
|
+
}, []);
|
|
74
|
+
const shouldHide = forceHidden || !state || state === "connected";
|
|
75
|
+
return /* @__PURE__ */ jsx(
|
|
76
|
+
View,
|
|
77
|
+
{
|
|
78
|
+
style: [
|
|
79
|
+
styles.connectionStateContainer,
|
|
80
|
+
shouldHide && styles.hide,
|
|
81
|
+
theme?.container,
|
|
82
|
+
state === "connected" && {
|
|
83
|
+
backgroundColor: (theme || defaultTheme).backgroundColorConnected
|
|
84
|
+
}
|
|
85
|
+
],
|
|
86
|
+
children: !state ? null : /* @__PURE__ */ jsx(
|
|
87
|
+
Text,
|
|
88
|
+
{
|
|
89
|
+
style: [
|
|
90
|
+
styles.connectionStateText,
|
|
91
|
+
theme && { backgroundColor: theme.container.backgroundColor },
|
|
92
|
+
state === "connected" && {
|
|
93
|
+
backgroundColor: (theme || defaultTheme).backgroundColorConnected
|
|
94
|
+
},
|
|
95
|
+
{ left }
|
|
96
|
+
],
|
|
97
|
+
children
|
|
98
|
+
}
|
|
99
|
+
)
|
|
100
|
+
}
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export { ConnectionState };
|
|
105
|
+
//# sourceMappingURL=index-node22.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index-node22.mjs","sources":["../src/index.tsx"],"sourcesContent":["import type { ReactElement, ReactNode } from \"react\";\nimport { useEffect, useRef } from \"react\";\nimport type { DimensionValue, ScaledSize } from \"react-native\";\nimport {\n Platform,\n StyleSheet,\n Text,\n View,\n useWindowDimensions,\n} from \"react-native\";\n\nconst defaultTheme = {\n container: {\n backgroundColor: \"rgba(247, 25, 0, 0.8)\",\n color: \"#fff\",\n textShadowColor: \"#111\",\n textShadowOffset: { width: 0, height: -1 },\n textShadowRadius: 1,\n },\n backgroundColorConnected: \"rgba(25, 200, 60, 0.8)\",\n};\n\nexport type ConnectionStateTheme = typeof defaultTheme;\nexport type State = \"connected\" | \"connecting\" | \"disconnected\" | null;\n\nexport interface ConnectionStateProps {\n theme?: ConnectionStateTheme;\n forceHidden?: boolean;\n state: State;\n children: NonNullable<ReactNode>;\n}\n\nconst zDepth1 =\n \"0 2px 3px 0 rgba(0, 0, 0, 0.15), 0 2px 5px 0 rgba(0, 0, 0, 0.2)\";\n\ntype CreateCalc = (\n webCalc: string,\n createCalc: (dimensions: ScaledSize) => DimensionValue,\n) => DimensionValue;\n\nconst useCreateCalcNative = (): CreateCalc => {\n const dimensions = useWindowDimensions();\n return (webCalc, createCalc) => createCalc(dimensions);\n};\nconst useCreateCalcWeb = (): CreateCalc => {\n return (webCalc) => `calc(${webCalc})` as DimensionValue;\n};\nconst useCreateCalc =\n Platform.OS === \"web\" ? useCreateCalcWeb : useCreateCalcNative;\n\n// example: const left = createCalc('50% - 100px', ({ width }) => width / 2 - 100);\n\nconst styles = StyleSheet.create({\n connectionStateContainer: {\n backgroundColor: defaultTheme.container.backgroundColor,\n position: \"absolute\",\n top: 0,\n right: 0,\n left: 0,\n height: 2,\n color: defaultTheme.container.color,\n textShadowOffset: defaultTheme.container.textShadowOffset,\n textShadowRadius: defaultTheme.container.textShadowRadius,\n boxShadow: zDepth1,\n zIndex: 9,\n // @ts-expect-error -- transition is not a valid style\n transition: \"top .8s, background-color .2s\",\n },\n hide: {\n top: -24,\n },\n connectionStateText: {\n backgroundColor: defaultTheme.container.backgroundColor,\n position: \"absolute\",\n width: 200,\n height: 22,\n lineHeight: 22,\n top: 2,\n textAlign: \"center\",\n borderBottomLeftRadius: 5,\n borderBottomRightRadius: 5,\n transition: \"background-color .2s\",\n },\n});\n\nexport function ConnectionState({\n theme,\n forceHidden,\n state,\n children,\n}: ConnectionStateProps): ReactElement | null {\n const unloadingRef = useRef<boolean>(false);\n\n const createCalc = useCreateCalc();\n const left = createCalc(\"50% - 100px\", ({ width }) => width / 2 - 100); // TODO use calc() in web ?\n\n useEffect((): (() => void) | undefined => {\n if (typeof globalThis === \"undefined\") return;\n\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 const shouldHide = forceHidden || !state || state === \"connected\";\n\n return (\n <View\n style={[\n styles.connectionStateContainer,\n shouldHide && styles.hide,\n theme?.container,\n state === \"connected\" && {\n backgroundColor: (theme || defaultTheme).backgroundColorConnected,\n },\n ]}\n >\n {!state ? null : (\n <Text\n style={[\n styles.connectionStateText,\n theme && { backgroundColor: theme.container.backgroundColor },\n state === \"connected\" && {\n backgroundColor: (theme || defaultTheme).backgroundColorConnected,\n },\n { left },\n ]}\n >\n {children}\n </Text>\n )}\n </View>\n );\n}\n"],"names":[],"mappings":";;;;AAWA,MAAM,YAAA,GAAe;AAAA,EACnB,SAAA,EAAW;AAAA,IACT,eAAA,EAAiB,uBAAA;AAAA,IACjB,KAAA,EAAO,MAAA;AAAA,IAEP,gBAAA,EAAkB,EAAE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QAAA,EAAA,CAAC,QAAQ,IAAA,mBACR,GAAA;AAAA,QAAC,IAAA;AAAA,QAAA;AAAA,UACC,KAAA,EAAO;AAAA,YACL,MAAA,CAAO,mBAAA;AAAA,YACP,KAAA,IAAS,EAAE,eAAA,EAAiB,KAAA,CAAM,UAAU,eAAA,EAAgB;AAAA,YAC5D,UAAU,WAAA,IAAe;AAAA,cACvB,eAAA,EAAA,CAAkB,SAAS,YAAA,EAAc;AAAA,aAC3C;AAAA,YACA,EAAE,IAAA;AAAK,WACT;AAAA,UAEC;AAAA;AAAA;AACH;AAAA,GAEJ;AAEJ;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-alp-connection-state",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "10.0.0",
|
|
4
4
|
"description": "connection state",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"author": "Christophe Hurpeau <christophe@hurpeau.com> (https://christophe.hurpeau.com)",
|
|
@@ -13,10 +13,10 @@
|
|
|
13
13
|
"homepage": "https://github.com/christophehurpeau/alp",
|
|
14
14
|
"type": "module",
|
|
15
15
|
"engines": {
|
|
16
|
-
"node": ">=18.
|
|
16
|
+
"node": ">=22.18.0"
|
|
17
17
|
},
|
|
18
18
|
"sideEffects": false,
|
|
19
|
-
"main": "./dist/index-
|
|
19
|
+
"main": "./dist/index-node22.mjs",
|
|
20
20
|
"types": "./dist/definitions/index.d.ts",
|
|
21
21
|
"module": "./dist/index-browser.es.js",
|
|
22
22
|
"browser": "./dist/index-browser.es.js",
|
|
@@ -25,8 +25,7 @@
|
|
|
25
25
|
".": {
|
|
26
26
|
"types": "./dist/definitions/index.d.ts",
|
|
27
27
|
"node": {
|
|
28
|
-
"import": "./dist/index-
|
|
29
|
-
"require": "./dist/index-node18.cjs"
|
|
28
|
+
"import": "./dist/index-node22.mjs"
|
|
30
29
|
},
|
|
31
30
|
"browser": {
|
|
32
31
|
"import": "./dist/index-browser.es.js",
|
|
@@ -42,9 +41,9 @@
|
|
|
42
41
|
"build": "yarn clean:build && rollup --config rollup.config.mjs && yarn run build:definitions",
|
|
43
42
|
"build:definitions": "tsc -p tsconfig.json",
|
|
44
43
|
"clean": "yarn clean:build",
|
|
45
|
-
"clean:build": "pob-
|
|
44
|
+
"clean:build": "pob-esbuild-clean-out dist",
|
|
46
45
|
"lint": "yarn run lint:eslint",
|
|
47
|
-
"lint:eslint": "yarn ../.. run eslint --
|
|
46
|
+
"lint:eslint": "yarn ../.. run eslint --quiet packages/react-alp-connection-state",
|
|
48
47
|
"watch": "yarn clean:build && rollup --config rollup.config.mjs --watch"
|
|
49
48
|
},
|
|
50
49
|
"browserslist": {
|
|
@@ -57,14 +56,14 @@
|
|
|
57
56
|
]
|
|
58
57
|
},
|
|
59
58
|
"pob": {
|
|
60
|
-
"
|
|
59
|
+
"bundler": "rollup-esbuild",
|
|
60
|
+
"entries": [
|
|
61
|
+
"index"
|
|
62
|
+
],
|
|
63
|
+
"envs": [
|
|
61
64
|
{
|
|
62
65
|
"target": "node",
|
|
63
|
-
"version": "
|
|
64
|
-
"formats": [
|
|
65
|
-
"cjs",
|
|
66
|
-
"es"
|
|
67
|
-
]
|
|
66
|
+
"version": "22"
|
|
68
67
|
},
|
|
69
68
|
{
|
|
70
69
|
"target": "browser",
|
|
@@ -74,14 +73,12 @@
|
|
|
74
73
|
]
|
|
75
74
|
}
|
|
76
75
|
],
|
|
77
|
-
"
|
|
78
|
-
|
|
79
|
-
],
|
|
80
|
-
"jsx": true
|
|
76
|
+
"jsx": true,
|
|
77
|
+
"typescript": true
|
|
81
78
|
},
|
|
82
79
|
"prettier": "@pob/root/prettier-config",
|
|
83
80
|
"peerDependencies": {
|
|
84
|
-
"react": "^
|
|
81
|
+
"react": "^19.0.0",
|
|
85
82
|
"react-native": "*"
|
|
86
83
|
},
|
|
87
84
|
"peerDependenciesMeta": {
|
|
@@ -89,16 +86,9 @@
|
|
|
89
86
|
"optional": true
|
|
90
87
|
}
|
|
91
88
|
},
|
|
92
|
-
"dependencies": {
|
|
93
|
-
"@babel/runtime": "^7.23.7"
|
|
94
|
-
},
|
|
95
89
|
"devDependencies": {
|
|
96
|
-
"@
|
|
97
|
-
"
|
|
98
|
-
"
|
|
99
|
-
"@types/react-native": "0.72.8",
|
|
100
|
-
"pob-babel": "38.0.2",
|
|
101
|
-
"react": "18.2.0",
|
|
102
|
-
"typescript": "5.3.3"
|
|
90
|
+
"@pob/rollup-esbuild": "6.7.0",
|
|
91
|
+
"react": "19.1.1",
|
|
92
|
+
"typescript": "5.9.2"
|
|
103
93
|
}
|
|
104
94
|
}
|
package/src/index.tsx
CHANGED
|
@@ -1,28 +1,27 @@
|
|
|
1
|
-
import type { ReactElement, ReactNode } from
|
|
2
|
-
import { useEffect, useRef } from
|
|
3
|
-
import type { DimensionValue, ScaledSize } from
|
|
1
|
+
import type { ReactElement, ReactNode } from "react";
|
|
2
|
+
import { useEffect, useRef } from "react";
|
|
3
|
+
import type { DimensionValue, ScaledSize } from "react-native";
|
|
4
4
|
import {
|
|
5
|
-
View,
|
|
6
|
-
Text,
|
|
7
|
-
StyleSheet,
|
|
8
5
|
Platform,
|
|
6
|
+
StyleSheet,
|
|
7
|
+
Text,
|
|
8
|
+
View,
|
|
9
9
|
useWindowDimensions,
|
|
10
|
-
|
|
11
|
-
} from 'react-native';
|
|
10
|
+
} from "react-native";
|
|
12
11
|
|
|
13
12
|
const defaultTheme = {
|
|
14
13
|
container: {
|
|
15
|
-
backgroundColor:
|
|
16
|
-
color:
|
|
17
|
-
textShadowColor:
|
|
14
|
+
backgroundColor: "rgba(247, 25, 0, 0.8)",
|
|
15
|
+
color: "#fff",
|
|
16
|
+
textShadowColor: "#111",
|
|
18
17
|
textShadowOffset: { width: 0, height: -1 },
|
|
19
18
|
textShadowRadius: 1,
|
|
20
19
|
},
|
|
21
|
-
backgroundColorConnected:
|
|
20
|
+
backgroundColorConnected: "rgba(25, 200, 60, 0.8)",
|
|
22
21
|
};
|
|
23
22
|
|
|
24
23
|
export type ConnectionStateTheme = typeof defaultTheme;
|
|
25
|
-
export type State =
|
|
24
|
+
export type State = "connected" | "connecting" | "disconnected" | null;
|
|
26
25
|
|
|
27
26
|
export interface ConnectionStateProps {
|
|
28
27
|
theme?: ConnectionStateTheme;
|
|
@@ -32,7 +31,7 @@ export interface ConnectionStateProps {
|
|
|
32
31
|
}
|
|
33
32
|
|
|
34
33
|
const zDepth1 =
|
|
35
|
-
|
|
34
|
+
"0 2px 3px 0 rgba(0, 0, 0, 0.15), 0 2px 5px 0 rgba(0, 0, 0, 0.2)";
|
|
36
35
|
|
|
37
36
|
type CreateCalc = (
|
|
38
37
|
webCalc: string,
|
|
@@ -47,14 +46,14 @@ const useCreateCalcWeb = (): CreateCalc => {
|
|
|
47
46
|
return (webCalc) => `calc(${webCalc})` as DimensionValue;
|
|
48
47
|
};
|
|
49
48
|
const useCreateCalc =
|
|
50
|
-
Platform.OS ===
|
|
49
|
+
Platform.OS === "web" ? useCreateCalcWeb : useCreateCalcNative;
|
|
51
50
|
|
|
52
51
|
// example: const left = createCalc('50% - 100px', ({ width }) => width / 2 - 100);
|
|
53
52
|
|
|
54
53
|
const styles = StyleSheet.create({
|
|
55
54
|
connectionStateContainer: {
|
|
56
55
|
backgroundColor: defaultTheme.container.backgroundColor,
|
|
57
|
-
position:
|
|
56
|
+
position: "absolute",
|
|
58
57
|
top: 0,
|
|
59
58
|
right: 0,
|
|
60
59
|
left: 0,
|
|
@@ -64,22 +63,23 @@ const styles = StyleSheet.create({
|
|
|
64
63
|
textShadowRadius: defaultTheme.container.textShadowRadius,
|
|
65
64
|
boxShadow: zDepth1,
|
|
66
65
|
zIndex: 9,
|
|
67
|
-
transition
|
|
66
|
+
// @ts-expect-error -- transition is not a valid style
|
|
67
|
+
transition: "top .8s, background-color .2s",
|
|
68
68
|
},
|
|
69
69
|
hide: {
|
|
70
70
|
top: -24,
|
|
71
71
|
},
|
|
72
72
|
connectionStateText: {
|
|
73
73
|
backgroundColor: defaultTheme.container.backgroundColor,
|
|
74
|
-
position:
|
|
74
|
+
position: "absolute",
|
|
75
75
|
width: 200,
|
|
76
76
|
height: 22,
|
|
77
77
|
lineHeight: 22,
|
|
78
78
|
top: 2,
|
|
79
|
-
textAlign:
|
|
79
|
+
textAlign: "center",
|
|
80
80
|
borderBottomLeftRadius: 5,
|
|
81
81
|
borderBottomRightRadius: 5,
|
|
82
|
-
transition:
|
|
82
|
+
transition: "background-color .2s",
|
|
83
83
|
},
|
|
84
84
|
});
|
|
85
85
|
|
|
@@ -92,22 +92,22 @@ export function ConnectionState({
|
|
|
92
92
|
const unloadingRef = useRef<boolean>(false);
|
|
93
93
|
|
|
94
94
|
const createCalc = useCreateCalc();
|
|
95
|
-
const left = createCalc(
|
|
95
|
+
const left = createCalc("50% - 100px", ({ width }) => width / 2 - 100); // TODO use calc() in web ?
|
|
96
96
|
|
|
97
97
|
useEffect((): (() => void) | undefined => {
|
|
98
|
-
if (typeof
|
|
98
|
+
if (typeof globalThis === "undefined") return;
|
|
99
99
|
|
|
100
100
|
const beforeUnloadHandler = (): void => {
|
|
101
101
|
unloadingRef.current = true;
|
|
102
102
|
};
|
|
103
|
-
window.addEventListener(
|
|
103
|
+
window.addEventListener("beforeunload", beforeUnloadHandler);
|
|
104
104
|
|
|
105
105
|
return (): void => {
|
|
106
|
-
window.removeEventListener(
|
|
106
|
+
window.removeEventListener("beforeunload", beforeUnloadHandler);
|
|
107
107
|
};
|
|
108
108
|
}, []);
|
|
109
109
|
|
|
110
|
-
const shouldHide = forceHidden || !state || state ===
|
|
110
|
+
const shouldHide = forceHidden || !state || state === "connected";
|
|
111
111
|
|
|
112
112
|
return (
|
|
113
113
|
<View
|
|
@@ -115,7 +115,7 @@ export function ConnectionState({
|
|
|
115
115
|
styles.connectionStateContainer,
|
|
116
116
|
shouldHide && styles.hide,
|
|
117
117
|
theme?.container,
|
|
118
|
-
state ===
|
|
118
|
+
state === "connected" && {
|
|
119
119
|
backgroundColor: (theme || defaultTheme).backgroundColorConnected,
|
|
120
120
|
},
|
|
121
121
|
]}
|
|
@@ -125,7 +125,7 @@ export function ConnectionState({
|
|
|
125
125
|
style={[
|
|
126
126
|
styles.connectionStateText,
|
|
127
127
|
theme && { backgroundColor: theme.container.backgroundColor },
|
|
128
|
-
state ===
|
|
128
|
+
state === "connected" && {
|
|
129
129
|
backgroundColor: (theme || defaultTheme).backgroundColorConnected,
|
|
130
130
|
},
|
|
131
131
|
{ left },
|
package/dist/index-node18.cjs
DELETED
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const react = require('react');
|
|
4
|
-
const reactNative = require('react-native');
|
|
5
|
-
const jsxRuntime = require('react/jsx-runtime');
|
|
6
|
-
|
|
7
|
-
const defaultTheme = {
|
|
8
|
-
container: {
|
|
9
|
-
backgroundColor: 'rgba(247, 25, 0, 0.8)',
|
|
10
|
-
color: '#fff',
|
|
11
|
-
textShadowColor: '#111',
|
|
12
|
-
textShadowOffset: {
|
|
13
|
-
width: 0,
|
|
14
|
-
height: -1
|
|
15
|
-
},
|
|
16
|
-
textShadowRadius: 1
|
|
17
|
-
},
|
|
18
|
-
backgroundColorConnected: 'rgba(25, 200, 60, 0.8)'
|
|
19
|
-
};
|
|
20
|
-
const useCreateCalcNative = () => {
|
|
21
|
-
const dimensions = reactNative.useWindowDimensions();
|
|
22
|
-
return (webCalc, createCalc) => createCalc(dimensions);
|
|
23
|
-
};
|
|
24
|
-
const useCreateCalcWeb = () => {
|
|
25
|
-
return webCalc => `calc(${webCalc})`;
|
|
26
|
-
};
|
|
27
|
-
const useCreateCalc = reactNative.Platform.OS === 'web' ? useCreateCalcWeb : useCreateCalcNative;
|
|
28
|
-
|
|
29
|
-
// example: const left = createCalc('50% - 100px', ({ width }) => width / 2 - 100);
|
|
30
|
-
|
|
31
|
-
const styles = reactNative.StyleSheet.create({
|
|
32
|
-
connectionStateContainer: {
|
|
33
|
-
backgroundColor: defaultTheme.container.backgroundColor,
|
|
34
|
-
position: 'absolute',
|
|
35
|
-
top: 0,
|
|
36
|
-
right: 0,
|
|
37
|
-
left: 0,
|
|
38
|
-
height: 2,
|
|
39
|
-
color: defaultTheme.container.color,
|
|
40
|
-
textShadowOffset: defaultTheme.container.textShadowOffset,
|
|
41
|
-
textShadowRadius: defaultTheme.container.textShadowRadius,
|
|
42
|
-
boxShadow: "0 2px 3px 0 rgba(0, 0, 0, 0.15), 0 2px 5px 0 rgba(0, 0, 0, 0.2)",
|
|
43
|
-
zIndex: 9,
|
|
44
|
-
transition: 'top .8s, background-color .2s'
|
|
45
|
-
},
|
|
46
|
-
hide: {
|
|
47
|
-
top: -24
|
|
48
|
-
},
|
|
49
|
-
connectionStateText: {
|
|
50
|
-
backgroundColor: defaultTheme.container.backgroundColor,
|
|
51
|
-
position: 'absolute',
|
|
52
|
-
width: 200,
|
|
53
|
-
height: 22,
|
|
54
|
-
lineHeight: 22,
|
|
55
|
-
top: 2,
|
|
56
|
-
textAlign: 'center',
|
|
57
|
-
borderBottomLeftRadius: 5,
|
|
58
|
-
borderBottomRightRadius: 5,
|
|
59
|
-
transition: 'background-color .2s'
|
|
60
|
-
}
|
|
61
|
-
});
|
|
62
|
-
function ConnectionState({
|
|
63
|
-
theme,
|
|
64
|
-
forceHidden,
|
|
65
|
-
state,
|
|
66
|
-
children
|
|
67
|
-
}) {
|
|
68
|
-
const unloadingRef = react.useRef(false);
|
|
69
|
-
const createCalc = useCreateCalc();
|
|
70
|
-
const left = createCalc('50% - 100px', ({
|
|
71
|
-
width
|
|
72
|
-
}) => width / 2 - 100); // TODO use calc() in web ?
|
|
73
|
-
|
|
74
|
-
react.useEffect(() => {
|
|
75
|
-
if (typeof window === 'undefined') return;
|
|
76
|
-
const beforeUnloadHandler = () => {
|
|
77
|
-
unloadingRef.current = true;
|
|
78
|
-
};
|
|
79
|
-
window.addEventListener('beforeunload', beforeUnloadHandler);
|
|
80
|
-
return () => {
|
|
81
|
-
window.removeEventListener('beforeunload', beforeUnloadHandler);
|
|
82
|
-
};
|
|
83
|
-
}, []);
|
|
84
|
-
return /*#__PURE__*/jsxRuntime.jsx(reactNative.View, {
|
|
85
|
-
style: [styles.connectionStateContainer, (forceHidden || !state || state === 'connected') && styles.hide, theme?.container, state === 'connected' && {
|
|
86
|
-
backgroundColor: (theme || defaultTheme).backgroundColorConnected
|
|
87
|
-
}],
|
|
88
|
-
children: !state ? null : /*#__PURE__*/jsxRuntime.jsx(reactNative.Text, {
|
|
89
|
-
style: [styles.connectionStateText, theme && {
|
|
90
|
-
backgroundColor: theme.container.backgroundColor
|
|
91
|
-
}, state === 'connected' && {
|
|
92
|
-
backgroundColor: (theme || defaultTheme).backgroundColorConnected
|
|
93
|
-
}, {
|
|
94
|
-
left
|
|
95
|
-
}],
|
|
96
|
-
children: children
|
|
97
|
-
})
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
exports.ConnectionState = ConnectionState;
|
|
102
|
-
//# sourceMappingURL=index-node18.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index-node18.cjs","sources":["../src/index.tsx"],"sourcesContent":["import type { ReactElement, ReactNode } from 'react';\nimport { useEffect, useRef } from 'react';\nimport type { DimensionValue, ScaledSize } from 'react-native';\nimport {\n View,\n Text,\n StyleSheet,\n Platform,\n useWindowDimensions,\n // eslint-disable-next-line import/no-unresolved -- react-native-web or react-native\n} from 'react-native';\n\nconst defaultTheme = {\n container: {\n backgroundColor: 'rgba(247, 25, 0, 0.8)',\n color: '#fff',\n textShadowColor: '#111',\n textShadowOffset: { width: 0, height: -1 },\n textShadowRadius: 1,\n },\n backgroundColorConnected: 'rgba(25, 200, 60, 0.8)',\n};\n\nexport type ConnectionStateTheme = typeof defaultTheme;\nexport type State = 'connected' | 'connecting' | 'disconnected' | null;\n\nexport interface ConnectionStateProps {\n theme?: ConnectionStateTheme;\n forceHidden?: boolean;\n state: State;\n children: NonNullable<ReactNode>;\n}\n\nconst zDepth1 =\n '0 2px 3px 0 rgba(0, 0, 0, 0.15), 0 2px 5px 0 rgba(0, 0, 0, 0.2)';\n\ntype CreateCalc = (\n webCalc: string,\n createCalc: (dimensions: ScaledSize) => DimensionValue,\n) => DimensionValue;\n\nconst useCreateCalcNative = (): CreateCalc => {\n const dimensions = useWindowDimensions();\n return (webCalc, createCalc) => createCalc(dimensions);\n};\nconst useCreateCalcWeb = (): CreateCalc => {\n return (webCalc) => `calc(${webCalc})` as DimensionValue;\n};\nconst useCreateCalc =\n Platform.OS === 'web' ? useCreateCalcWeb : useCreateCalcNative;\n\n// example: const left = createCalc('50% - 100px', ({ width }) => width / 2 - 100);\n\nconst styles = StyleSheet.create({\n connectionStateContainer: {\n backgroundColor: defaultTheme.container.backgroundColor,\n position: 'absolute',\n top: 0,\n right: 0,\n left: 0,\n height: 2,\n color: defaultTheme.container.color,\n textShadowOffset: defaultTheme.container.textShadowOffset,\n textShadowRadius: defaultTheme.container.textShadowRadius,\n boxShadow: zDepth1,\n zIndex: 9,\n transition: 'top .8s, background-color .2s',\n },\n hide: {\n top: -24,\n },\n connectionStateText: {\n backgroundColor: defaultTheme.container.backgroundColor,\n position: 'absolute',\n width: 200,\n height: 22,\n lineHeight: 22,\n top: 2,\n textAlign: 'center',\n borderBottomLeftRadius: 5,\n borderBottomRightRadius: 5,\n transition: 'background-color .2s',\n },\n});\n\nexport function ConnectionState({\n theme,\n forceHidden,\n state,\n children,\n}: ConnectionStateProps): ReactElement | null {\n const unloadingRef = useRef<boolean>(false);\n\n const createCalc = useCreateCalc();\n const left = createCalc('50% - 100px', ({ width }) => width / 2 - 100); // TODO use calc() in web ?\n\n useEffect((): (() => void) | undefined => {\n if (typeof window === 'undefined') return;\n\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 const shouldHide = forceHidden || !state || state === 'connected';\n\n return (\n <View\n style={[\n styles.connectionStateContainer,\n shouldHide && styles.hide,\n theme?.container,\n state === 'connected' && {\n backgroundColor: (theme || defaultTheme).backgroundColorConnected,\n },\n ]}\n >\n {!state ? null : (\n <Text\n style={[\n styles.connectionStateText,\n theme && { backgroundColor: theme.container.backgroundColor },\n state === 'connected' && {\n backgroundColor: (theme || defaultTheme).backgroundColorConnected,\n },\n { left },\n ]}\n >\n {children}\n </Text>\n )}\n </View>\n );\n}\n"],"names":["defaultTheme","container","backgroundColor","color","textShadowColor","textShadowOffset","width","height","textShadowRadius","backgroundColorConnected","useCreateCalcNative","dimensions","useWindowDimensions","webCalc","createCalc","useCreateCalcWeb","useCreateCalc","Platform","OS","styles","StyleSheet","create","connectionStateContainer","position","top","right","left","boxShadow","zIndex","transition","hide","connectionStateText","lineHeight","textAlign","borderBottomLeftRadius","borderBottomRightRadius","ConnectionState","theme","forceHidden","state","children","unloadingRef","useRef","useEffect","window","beforeUnloadHandler","current","addEventListener","removeEventListener","_jsx","View","style","Text"],"mappings":";;;;;;AAYA,MAAMA,YAAY,GAAG;AACnBC,EAAAA,SAAS,EAAE;AACTC,IAAAA,eAAe,EAAE,uBAAuB;AACxCC,IAAAA,KAAK,EAAE,MAAM;AACbC,IAAAA,eAAe,EAAE,MAAM;AACvBC,IAAAA,gBAAgB,EAAE;AAAEC,MAAAA,KAAK,EAAE,CAAC;AAAEC,MAAAA,MAAM,EAAE,CAAC,CAAA;KAAG;AAC1CC,IAAAA,gBAAgB,EAAE,CAAA;GACnB;AACDC,EAAAA,wBAAwB,EAAE,wBAAA;AAC5B,CAAC,CAAA;AAoBD,MAAMC,mBAAmB,GAAGA,MAAkB;AAC5C,EAAA,MAAMC,UAAU,GAAGC,+BAAmB,EAAE,CAAA;EACxC,OAAO,CAACC,OAAO,EAAEC,UAAU,KAAKA,UAAU,CAACH,UAAU,CAAC,CAAA;AACxD,CAAC,CAAA;AACD,MAAMI,gBAAgB,GAAGA,M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,KAAK,EAAE,CACLhC,MAAM,CAACY,mBAAmB,EAC1BM,KAAK,IAAI;AAAEnC,QAAAA,eAAe,EAAEmC,KAAK,CAACpC,SAAS,CAACC,eAAAA;AAAgB,OAAC,EAC7DqC,KAAK,KAAK,WAAW,IAAI;AACvBrC,QAAAA,eAAe,EAAE,CAACmC,KAAK,IAAIrC,YAAY,EAAES,wBAAAA;AAC3C,OAAC,EACD;AAAEiB,QAAAA,IAAAA;AAAK,OAAC,CACR;AAAAc,MAAAA,QAAA,EAEDA,QAAAA;KACG,CAAA;AACP,GACG,CAAC,CAAA;AAEX;;;;"}
|
package/dist/index-node18.mjs
DELETED
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
import { useRef, useEffect } from 'react';
|
|
2
|
-
import { Platform, StyleSheet, useWindowDimensions, View, Text } from 'react-native';
|
|
3
|
-
import { jsx } from 'react/jsx-runtime';
|
|
4
|
-
|
|
5
|
-
const defaultTheme = {
|
|
6
|
-
container: {
|
|
7
|
-
backgroundColor: 'rgba(247, 25, 0, 0.8)',
|
|
8
|
-
color: '#fff',
|
|
9
|
-
textShadowColor: '#111',
|
|
10
|
-
textShadowOffset: {
|
|
11
|
-
width: 0,
|
|
12
|
-
height: -1
|
|
13
|
-
},
|
|
14
|
-
textShadowRadius: 1
|
|
15
|
-
},
|
|
16
|
-
backgroundColorConnected: 'rgba(25, 200, 60, 0.8)'
|
|
17
|
-
};
|
|
18
|
-
const useCreateCalcNative = () => {
|
|
19
|
-
const dimensions = useWindowDimensions();
|
|
20
|
-
return (webCalc, createCalc) => createCalc(dimensions);
|
|
21
|
-
};
|
|
22
|
-
const useCreateCalcWeb = () => {
|
|
23
|
-
return webCalc => `calc(${webCalc})`;
|
|
24
|
-
};
|
|
25
|
-
const useCreateCalc = Platform.OS === 'web' ? useCreateCalcWeb : useCreateCalcNative;
|
|
26
|
-
|
|
27
|
-
// example: const left = createCalc('50% - 100px', ({ width }) => width / 2 - 100);
|
|
28
|
-
|
|
29
|
-
const styles = StyleSheet.create({
|
|
30
|
-
connectionStateContainer: {
|
|
31
|
-
backgroundColor: defaultTheme.container.backgroundColor,
|
|
32
|
-
position: 'absolute',
|
|
33
|
-
top: 0,
|
|
34
|
-
right: 0,
|
|
35
|
-
left: 0,
|
|
36
|
-
height: 2,
|
|
37
|
-
color: defaultTheme.container.color,
|
|
38
|
-
textShadowOffset: defaultTheme.container.textShadowOffset,
|
|
39
|
-
textShadowRadius: defaultTheme.container.textShadowRadius,
|
|
40
|
-
boxShadow: "0 2px 3px 0 rgba(0, 0, 0, 0.15), 0 2px 5px 0 rgba(0, 0, 0, 0.2)",
|
|
41
|
-
zIndex: 9,
|
|
42
|
-
transition: 'top .8s, background-color .2s'
|
|
43
|
-
},
|
|
44
|
-
hide: {
|
|
45
|
-
top: -24
|
|
46
|
-
},
|
|
47
|
-
connectionStateText: {
|
|
48
|
-
backgroundColor: defaultTheme.container.backgroundColor,
|
|
49
|
-
position: 'absolute',
|
|
50
|
-
width: 200,
|
|
51
|
-
height: 22,
|
|
52
|
-
lineHeight: 22,
|
|
53
|
-
top: 2,
|
|
54
|
-
textAlign: 'center',
|
|
55
|
-
borderBottomLeftRadius: 5,
|
|
56
|
-
borderBottomRightRadius: 5,
|
|
57
|
-
transition: 'background-color .2s'
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
function ConnectionState({
|
|
61
|
-
theme,
|
|
62
|
-
forceHidden,
|
|
63
|
-
state,
|
|
64
|
-
children
|
|
65
|
-
}) {
|
|
66
|
-
const unloadingRef = useRef(false);
|
|
67
|
-
const createCalc = useCreateCalc();
|
|
68
|
-
const left = createCalc('50% - 100px', ({
|
|
69
|
-
width
|
|
70
|
-
}) => width / 2 - 100); // TODO use calc() in web ?
|
|
71
|
-
|
|
72
|
-
useEffect(() => {
|
|
73
|
-
if (typeof window === 'undefined') return;
|
|
74
|
-
const beforeUnloadHandler = () => {
|
|
75
|
-
unloadingRef.current = true;
|
|
76
|
-
};
|
|
77
|
-
window.addEventListener('beforeunload', beforeUnloadHandler);
|
|
78
|
-
return () => {
|
|
79
|
-
window.removeEventListener('beforeunload', beforeUnloadHandler);
|
|
80
|
-
};
|
|
81
|
-
}, []);
|
|
82
|
-
return /*#__PURE__*/jsx(View, {
|
|
83
|
-
style: [styles.connectionStateContainer, (forceHidden || !state || state === 'connected') && styles.hide, theme?.container, state === 'connected' && {
|
|
84
|
-
backgroundColor: (theme || defaultTheme).backgroundColorConnected
|
|
85
|
-
}],
|
|
86
|
-
children: !state ? null : /*#__PURE__*/jsx(Text, {
|
|
87
|
-
style: [styles.connectionStateText, theme && {
|
|
88
|
-
backgroundColor: theme.container.backgroundColor
|
|
89
|
-
}, state === 'connected' && {
|
|
90
|
-
backgroundColor: (theme || defaultTheme).backgroundColorConnected
|
|
91
|
-
}, {
|
|
92
|
-
left
|
|
93
|
-
}],
|
|
94
|
-
children: children
|
|
95
|
-
})
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
export { ConnectionState };
|
|
100
|
-
//# sourceMappingURL=index-node18.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index-node18.mjs","sources":["../src/index.tsx"],"sourcesContent":["import type { ReactElement, ReactNode } from 'react';\nimport { useEffect, useRef } from 'react';\nimport type { DimensionValue, ScaledSize } from 'react-native';\nimport {\n View,\n Text,\n StyleSheet,\n Platform,\n useWindowDimensions,\n // eslint-disable-next-line import/no-unresolved -- react-native-web or react-native\n} from 'react-native';\n\nconst defaultTheme = {\n container: {\n backgroundColor: 'rgba(247, 25, 0, 0.8)',\n color: '#fff',\n textShadowColor: '#111',\n textShadowOffset: { width: 0, height: -1 },\n textShadowRadius: 1,\n },\n backgroundColorConnected: 'rgba(25, 200, 60, 0.8)',\n};\n\nexport type ConnectionStateTheme = typeof defaultTheme;\nexport type State = 'connected' | 'connecting' | 'disconnected' | null;\n\nexport interface ConnectionStateProps {\n theme?: ConnectionStateTheme;\n forceHidden?: boolean;\n state: State;\n children: NonNullable<ReactNode>;\n}\n\nconst zDepth1 =\n '0 2px 3px 0 rgba(0, 0, 0, 0.15), 0 2px 5px 0 rgba(0, 0, 0, 0.2)';\n\ntype CreateCalc = (\n webCalc: string,\n createCalc: (dimensions: ScaledSize) => DimensionValue,\n) => DimensionValue;\n\nconst useCreateCalcNative = (): CreateCalc => {\n const dimensions = useWindowDimensions();\n return (webCalc, createCalc) => createCalc(dimensions);\n};\nconst useCreateCalcWeb = (): CreateCalc => {\n return (webCalc) => `calc(${webCalc})` as DimensionValue;\n};\nconst useCreateCalc =\n Platform.OS === 'web' ? useCreateCalcWeb : useCreateCalcNative;\n\n// example: const left = createCalc('50% - 100px', ({ width }) => width / 2 - 100);\n\nconst styles = StyleSheet.create({\n connectionStateContainer: {\n backgroundColor: defaultTheme.container.backgroundColor,\n position: 'absolute',\n top: 0,\n right: 0,\n left: 0,\n height: 2,\n color: defaultTheme.container.color,\n textShadowOffset: defaultTheme.container.textShadowOffset,\n textShadowRadius: defaultTheme.container.textShadowRadius,\n boxShadow: zDepth1,\n zIndex: 9,\n transition: 'top .8s, background-color .2s',\n },\n hide: {\n top: -24,\n },\n connectionStateText: {\n backgroundColor: defaultTheme.container.backgroundColor,\n position: 'absolute',\n width: 200,\n height: 22,\n lineHeight: 22,\n top: 2,\n textAlign: 'center',\n borderBottomLeftRadius: 5,\n borderBottomRightRadius: 5,\n transition: 'background-color .2s',\n },\n});\n\nexport function ConnectionState({\n theme,\n forceHidden,\n state,\n children,\n}: ConnectionStateProps): ReactElement | null {\n const unloadingRef = useRef<boolean>(false);\n\n const createCalc = useCreateCalc();\n const left = createCalc('50% - 100px', ({ width }) => width / 2 - 100); // TODO use calc() in web ?\n\n useEffect((): (() => void) | undefined => {\n if (typeof window === 'undefined') return;\n\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 const shouldHide = forceHidden || !state || state === 'connected';\n\n return (\n <View\n style={[\n styles.connectionStateContainer,\n shouldHide && styles.hide,\n theme?.container,\n state === 'connected' && {\n backgroundColor: (theme || defaultTheme).backgroundColorConnected,\n },\n ]}\n >\n {!state ? null : (\n <Text\n style={[\n styles.connectionStateText,\n theme && { backgroundColor: theme.container.backgroundColor },\n state === 'connected' && {\n backgroundColor: (theme || defaultTheme).backgroundColorConnected,\n },\n { left },\n ]}\n >\n {children}\n </Text>\n )}\n </View>\n );\n}\n"],"names":["defaultTheme","container","backgroundColor","color","textShadowColor","textShadowOffset","width","height","textShadowRadius","backgroundColorConnected","useCreateCalcNative","dimensions","useWindowDimensions","webCalc","createCalc","useCreateCalcWeb","useCreateCalc","Platform","OS","styles","StyleSheet","create","connectionStateContainer","position","top","right","left","boxShadow","zIndex","transition","hide","connectionStateText","lineHeight","textAlign","borderBottomLeftRadius","borderBottomRightRadius","ConnectionState","theme","forceHidden","state","children","unloadingRef","useRef","useEffect","window","beforeUnloadHandler","current","addEventListener","removeEventListener","_jsx","View","style","Text"],"mappings":";;;;AAYA,MAAMA,YAAY,GAAG;AACnBC,EAAAA,SAAS,EAAE;AACTC,IAAAA,eAAe,EAAE,uBAAuB;AACxCC,IAAAA,KAAK,EAAE,MAAM;AACbC,IAAAA,eAAe,EAAE,MAAM;AACvBC,IAAAA,gBAAgB,EAAE;AAAEC,MAAAA,KAAK,EAAE,CAAC;AAAEC,MAAAA,MAAM,EAAE,CAAC,CAAA;KAAG;AAC1CC,IAAAA,gBAAgB,EAAE,CAAA;GACnB;AACDC,EAAAA,wBAAwB,EAAE,wBAAA;AAC5B,CAAC,CAAA;AAoBD,MAAMC,mBAAmB,GAAGA,MAAkB;AAC5C,EAAA,MAAMC,UAAU,GAAGC,mBAAmB,EAAE,CAAA;EACxC,OAAO,CAACC,OAAO,EAAEC,UAAU,KAAKA,UAAU,CAACH,UAAU,CAAC,CAAA;AACxD,CAAC,CAAA;AACD,MAAMI,gBAA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,MAAAA,KAAK,EAAE,CACLhC,MAAM,CAACY,mBAAmB,EAC1BM,KAAK,IAAI;AAAEnC,QAAAA,eAAe,EAAEmC,KAAK,CAACpC,SAAS,CAACC,eAAAA;AAAgB,OAAC,EAC7DqC,KAAK,KAAK,WAAW,IAAI;AACvBrC,QAAAA,eAAe,EAAE,CAACmC,KAAK,IAAIrC,YAAY,EAAES,wBAAAA;AAC3C,OAAC,EACD;AAAEiB,QAAAA,IAAAA;AAAK,OAAC,CACR;AAAAc,MAAAA,QAAA,EAEDA,QAAAA;KACG,CAAA;AACP,GACG,CAAC,CAAA;AAEX;;;;"}
|
package/src/.eslintrc.json
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"root": true,
|
|
3
|
-
"parser": "@typescript-eslint/parser",
|
|
4
|
-
"parserOptions": {
|
|
5
|
-
"EXPERIMENTAL_useProjectService": true,
|
|
6
|
-
"project": "packages/react-alp-connection-state/tsconfig.json"
|
|
7
|
-
},
|
|
8
|
-
"plugins": ["@typescript-eslint"],
|
|
9
|
-
"extends": [
|
|
10
|
-
"@pob/eslint-config-typescript",
|
|
11
|
-
"@pob/eslint-config-typescript-react"
|
|
12
|
-
],
|
|
13
|
-
"ignorePatterns": ["*.d.ts"],
|
|
14
|
-
"overrides": [
|
|
15
|
-
{
|
|
16
|
-
"files": ["**/*.test.{ts,tsx}", "__tests__/**/*.{ts,tsx}"],
|
|
17
|
-
"extends": ["@pob/eslint-config-typescript/test"],
|
|
18
|
-
"env": {
|
|
19
|
-
"jest": true
|
|
20
|
-
},
|
|
21
|
-
"rules": {
|
|
22
|
-
"import/no-extraneous-dependencies": [
|
|
23
|
-
"error",
|
|
24
|
-
{
|
|
25
|
-
"devDependencies": true
|
|
26
|
-
}
|
|
27
|
-
]
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
]
|
|
31
|
-
}
|