@youversion/platform-react-hooks 1.13.0 → 1.14.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/.turbo/turbo-build.log +1 -1
- package/CHANGELOG.md +11 -0
- package/dist/context/YouVersionProvider.d.ts +1 -1
- package/dist/context/YouVersionProvider.d.ts.map +1 -1
- package/dist/context/YouVersionProvider.js +29 -3
- package/dist/context/YouVersionProvider.js.map +1 -1
- package/package.json +2 -2
- package/src/context/YouVersionProvider.tsx +33 -4
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
|
|
2
|
-
> @youversion/platform-react-hooks@1.
|
|
2
|
+
> @youversion/platform-react-hooks@1.14.0 build /home/runner/work/platform-sdk-react/platform-sdk-react/packages/hooks
|
|
3
3
|
> tsc -p tsconfig.build.json
|
|
4
4
|
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# @youversion/platform-react-hooks
|
|
2
2
|
|
|
3
|
+
## 1.14.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 2d2c597: Added 'system' as an option to YouVersionProvider theme prop that resolves via `prefers-color-scheme` with live OS change listener
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [2d2c597]
|
|
12
|
+
- @youversion/platform-core@1.14.0
|
|
13
|
+
|
|
3
14
|
## 1.13.0
|
|
4
15
|
|
|
5
16
|
### Minor Changes
|
|
@@ -3,7 +3,7 @@ interface YouVersionProviderPropsBase {
|
|
|
3
3
|
children: ReactNode;
|
|
4
4
|
appKey: string;
|
|
5
5
|
apiHost?: string;
|
|
6
|
-
theme?: 'light' | 'dark';
|
|
6
|
+
theme?: 'light' | 'dark' | 'system';
|
|
7
7
|
}
|
|
8
8
|
interface YouVersionProviderPropsWithAuth extends YouVersionProviderPropsBase {
|
|
9
9
|
authRedirectUrl: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"YouVersionProvider.d.ts","sourceRoot":"","sources":["../../src/context/YouVersionProvider.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,iBAAiB,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAK1D,UAAU,2BAA2B;IACnC,QAAQ,EAAE,SAAS,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"YouVersionProvider.d.ts","sourceRoot":"","sources":["../../src/context/YouVersionProvider.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,iBAAiB,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAK1D,UAAU,2BAA2B;IACnC,QAAQ,EAAE,SAAS,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,OAAO,GAAG,MAAM,GAAG,QAAQ,CAAC;CACrC;AAED,UAAU,+BAAgC,SAAQ,2BAA2B;IAC3E,eAAe,EAAE,MAAM,CAAC;IACxB,WAAW,EAAE,IAAI,CAAC;CACnB;AAED,UAAU,kCAAmC,SAAQ,2BAA2B;IAC9E,WAAW,CAAC,EAAE,KAAK,CAAC;IACpB,eAAe,CAAC,EAAE,KAAK,CAAC;CACzB;AAgCD,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,iBAAiB,CAAC,+BAA+B,GAAG,kCAAkC,CAAC,GAC7F,KAAK,CAAC,YAAY,CAkDpB"}
|
|
@@ -1,11 +1,37 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
-
import { lazy, Suspense, useEffect } from 'react';
|
|
3
|
+
import { lazy, Suspense, useEffect, useState } from 'react';
|
|
4
4
|
import { YouVersionContext } from './YouVersionContext';
|
|
5
5
|
import { YouVersionPlatformConfiguration } from '@youversion/platform-core';
|
|
6
6
|
const AuthProvider = lazy(() => import('./YouVersionAuthProvider'));
|
|
7
|
+
function useResolvedTheme(theme) {
|
|
8
|
+
const [resolved, setResolved] = useState(() => {
|
|
9
|
+
if (theme !== 'system')
|
|
10
|
+
return theme;
|
|
11
|
+
if (typeof window === 'undefined')
|
|
12
|
+
return 'light';
|
|
13
|
+
return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
|
|
14
|
+
});
|
|
15
|
+
useEffect(() => {
|
|
16
|
+
if (theme !== 'system') {
|
|
17
|
+
setResolved(theme);
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
if (typeof window === 'undefined')
|
|
21
|
+
return;
|
|
22
|
+
const mediaQueryList = window.matchMedia('(prefers-color-scheme: dark)');
|
|
23
|
+
setResolved(mediaQueryList.matches ? 'dark' : 'light');
|
|
24
|
+
const handler = (e) => {
|
|
25
|
+
setResolved(e.matches ? 'dark' : 'light');
|
|
26
|
+
};
|
|
27
|
+
mediaQueryList.addEventListener('change', handler);
|
|
28
|
+
return () => mediaQueryList.removeEventListener('change', handler);
|
|
29
|
+
}, [theme]);
|
|
30
|
+
return resolved;
|
|
31
|
+
}
|
|
7
32
|
export function YouVersionProvider(props) {
|
|
8
33
|
const { appKey, apiHost = 'api.youversion.com', includeAuth, theme = 'light', children } = props;
|
|
34
|
+
const resolvedTheme = useResolvedTheme(theme);
|
|
9
35
|
// Syncing appKey and apiHost to YouVersionPlatformConfiguration
|
|
10
36
|
// so that this can be in sync with any other code that uses
|
|
11
37
|
// the YouVersionPlatformConfiguration, of which a lot of our
|
|
@@ -21,7 +47,7 @@ export function YouVersionProvider(props) {
|
|
|
21
47
|
appKey,
|
|
22
48
|
apiHost,
|
|
23
49
|
installationId: YouVersionPlatformConfiguration.installationId,
|
|
24
|
-
theme,
|
|
50
|
+
theme: resolvedTheme,
|
|
25
51
|
authEnabled: !!includeAuth,
|
|
26
52
|
}, children: _jsx(Suspense, { children: _jsx(AuthProvider, { config: { appKey, apiHost, redirectUri: authRedirectUrl }, children: children }) }) }));
|
|
27
53
|
}
|
|
@@ -30,7 +56,7 @@ export function YouVersionProvider(props) {
|
|
|
30
56
|
appKey,
|
|
31
57
|
apiHost,
|
|
32
58
|
installationId: YouVersionPlatformConfiguration.installationId,
|
|
33
|
-
theme,
|
|
59
|
+
theme: resolvedTheme,
|
|
34
60
|
authEnabled: !!includeAuth,
|
|
35
61
|
}, children: children }));
|
|
36
62
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"YouVersionProvider.js","sourceRoot":"","sources":["../../src/context/YouVersionProvider.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAGb,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"YouVersionProvider.js","sourceRoot":"","sources":["../../src/context/YouVersionProvider.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAGb,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC5D,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,+BAA+B,EAAE,MAAM,2BAA2B,CAAC;AAmB5E,MAAM,YAAY,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,0BAA0B,CAAC,CAAC,CAAC;AAEpE,SAAS,gBAAgB,CAAC,KAAkC;IAC1D,MAAM,CAAC,QAAQ,EAAE,WAAW,CAAC,GAAG,QAAQ,CAAmB,GAAG,EAAE;QAC9D,IAAI,KAAK,KAAK,QAAQ;YAAE,OAAO,KAAK,CAAC;QACrC,IAAI,OAAO,MAAM,KAAK,WAAW;YAAE,OAAO,OAAO,CAAC;QAClD,OAAO,MAAM,CAAC,UAAU,CAAC,8BAA8B,CAAC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CAAC;IACpD,CAAC,EAAE,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IAEtB,IAAI,WAAW,EAAE,CAAC;QAChB,MAAM,EAAE,eAAe,EAAE,GAAG,KAAK,CAAC;QAElC,4EAA4E;QAC5E,OAAO,CACL,KAAC,iBAAiB,CAAC,QAAQ,IACzB,KAAK,EAAE;gBACL,MAAM;gBACN,OAAO;gBACP,cAAc,EAAE,+BAA+B,CAAC,cAAc;gBAC9D,KAAK,EAAE,aAAa;gBACpB,WAAW,EAAE,CAAC,CAAC,WAAW;aAC3B,YAED,KAAC,QAAQ,cACP,KAAC,YAAY,IAAC,MAAM,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,YACpE,QAAQ,GACI,GACN,GACgB,CAC9B,CAAC;IACJ,CAAC;IAED,4EAA4E;IAC5E,OAAO,CACL,KAAC,iBAAiB,CAAC,QAAQ,IACzB,KAAK,EAAE;YACL,MAAM;YACN,OAAO;YACP,cAAc,EAAE,+BAA+B,CAAC,cAAc;YAC9D,KAAK,EAAE,aAAa;YACpB,WAAW,EAAE,CAAC,CAAC,WAAW;SAC3B,YAEA,QAAQ,GACkB,CAC9B,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@youversion/platform-react-hooks",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.14.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
}
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@youversion/platform-core": "1.
|
|
25
|
+
"@youversion/platform-core": "1.14.0"
|
|
26
26
|
},
|
|
27
27
|
"peerDependencies": {
|
|
28
28
|
"react": ">=19.1.0 <20.0.0"
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
import type { PropsWithChildren, ReactNode } from 'react';
|
|
4
|
-
import { lazy, Suspense, useEffect } from 'react';
|
|
4
|
+
import { lazy, Suspense, useEffect, useState } from 'react';
|
|
5
5
|
import { YouVersionContext } from './YouVersionContext';
|
|
6
6
|
import { YouVersionPlatformConfiguration } from '@youversion/platform-core';
|
|
7
7
|
|
|
@@ -9,7 +9,7 @@ interface YouVersionProviderPropsBase {
|
|
|
9
9
|
children: ReactNode;
|
|
10
10
|
appKey: string;
|
|
11
11
|
apiHost?: string;
|
|
12
|
-
theme?: 'light' | 'dark';
|
|
12
|
+
theme?: 'light' | 'dark' | 'system';
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
interface YouVersionProviderPropsWithAuth extends YouVersionProviderPropsBase {
|
|
@@ -24,10 +24,39 @@ interface YouVersionProviderPropsWithoutAuth extends YouVersionProviderPropsBase
|
|
|
24
24
|
|
|
25
25
|
const AuthProvider = lazy(() => import('./YouVersionAuthProvider'));
|
|
26
26
|
|
|
27
|
+
function useResolvedTheme(theme: 'light' | 'dark' | 'system'): 'light' | 'dark' {
|
|
28
|
+
const [resolved, setResolved] = useState<'light' | 'dark'>(() => {
|
|
29
|
+
if (theme !== 'system') return theme;
|
|
30
|
+
if (typeof window === 'undefined') return 'light';
|
|
31
|
+
return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
useEffect(() => {
|
|
35
|
+
if (theme !== 'system') {
|
|
36
|
+
setResolved(theme);
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (typeof window === 'undefined') return;
|
|
41
|
+
|
|
42
|
+
const mediaQueryList = window.matchMedia('(prefers-color-scheme: dark)');
|
|
43
|
+
setResolved(mediaQueryList.matches ? 'dark' : 'light');
|
|
44
|
+
|
|
45
|
+
const handler = (e: MediaQueryListEvent) => {
|
|
46
|
+
setResolved(e.matches ? 'dark' : 'light');
|
|
47
|
+
};
|
|
48
|
+
mediaQueryList.addEventListener('change', handler);
|
|
49
|
+
return () => mediaQueryList.removeEventListener('change', handler);
|
|
50
|
+
}, [theme]);
|
|
51
|
+
|
|
52
|
+
return resolved;
|
|
53
|
+
}
|
|
54
|
+
|
|
27
55
|
export function YouVersionProvider(
|
|
28
56
|
props: PropsWithChildren<YouVersionProviderPropsWithAuth | YouVersionProviderPropsWithoutAuth>,
|
|
29
57
|
): React.ReactElement {
|
|
30
58
|
const { appKey, apiHost = 'api.youversion.com', includeAuth, theme = 'light', children } = props;
|
|
59
|
+
const resolvedTheme = useResolvedTheme(theme);
|
|
31
60
|
|
|
32
61
|
// Syncing appKey and apiHost to YouVersionPlatformConfiguration
|
|
33
62
|
// so that this can be in sync with any other code that uses
|
|
@@ -48,7 +77,7 @@ export function YouVersionProvider(
|
|
|
48
77
|
appKey,
|
|
49
78
|
apiHost,
|
|
50
79
|
installationId: YouVersionPlatformConfiguration.installationId,
|
|
51
|
-
theme,
|
|
80
|
+
theme: resolvedTheme,
|
|
52
81
|
authEnabled: !!includeAuth,
|
|
53
82
|
}}
|
|
54
83
|
>
|
|
@@ -68,7 +97,7 @@ export function YouVersionProvider(
|
|
|
68
97
|
appKey,
|
|
69
98
|
apiHost,
|
|
70
99
|
installationId: YouVersionPlatformConfiguration.installationId,
|
|
71
|
-
theme,
|
|
100
|
+
theme: resolvedTheme,
|
|
72
101
|
authEnabled: !!includeAuth,
|
|
73
102
|
}}
|
|
74
103
|
>
|