@rimori/react-client 0.4.17-next.3 → 0.4.17-next.4
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.
|
@@ -1,12 +1,15 @@
|
|
|
1
|
-
export function useTheme(theme = 'system') {
|
|
1
|
+
export function useTheme(theme = 'system', isDisabled = false) {
|
|
2
2
|
const isDark = theme === 'system' ? systenUsesDarkMode() : theme === 'dark';
|
|
3
|
+
if (isDisabled) {
|
|
4
|
+
return { isDark, theme, isDisabled };
|
|
5
|
+
}
|
|
3
6
|
const dom = document.documentElement;
|
|
4
7
|
dom.dataset.theme = isDark ? 'dark' : 'light';
|
|
5
8
|
dom.style.colorScheme = isDark ? 'dark' : 'light';
|
|
6
9
|
dom.classList[isDark ? 'add' : 'remove']('dark');
|
|
7
10
|
const root = document.querySelector('#root');
|
|
8
11
|
root.classList.add('dark:bg-gradient-to-br', 'dark:from-gray-900', 'dark:to-gray-800', 'dark:text-white', 'min-h-screen', 'bg-fixed');
|
|
9
|
-
return { isDark, theme };
|
|
12
|
+
return { isDark, theme, isDisabled };
|
|
10
13
|
}
|
|
11
14
|
function systenUsesDarkMode() {
|
|
12
15
|
return window.matchMedia('(prefers-color-scheme: dark)').matches;
|
|
@@ -6,6 +6,12 @@ interface PluginProviderProps {
|
|
|
6
6
|
pluginId: string;
|
|
7
7
|
settings?: {
|
|
8
8
|
disableContextMenu?: boolean;
|
|
9
|
+
disableThemeSetting?: boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Skip the scrollbar detection that emits 'session.triggerScrollbarChange'.
|
|
12
|
+
* In federation mode, the host (FederatedPluginRenderer) handles this instead.
|
|
13
|
+
*/
|
|
14
|
+
disableScrollbarDetection?: boolean;
|
|
9
15
|
};
|
|
10
16
|
}
|
|
11
17
|
export declare const PluginProvider: React.FC<PluginProviderProps>;
|
|
@@ -20,7 +20,7 @@ export const PluginProvider = ({ children, pluginId, settings }) => {
|
|
|
20
20
|
const [applicationMode, setApplicationMode] = useState(null);
|
|
21
21
|
const [theme, setTheme] = useState(undefined);
|
|
22
22
|
const [userInfo, setUserInfo] = useState(null);
|
|
23
|
-
useTheme(theme);
|
|
23
|
+
useTheme(theme, settings === null || settings === void 0 ? void 0 : settings.disableThemeSetting);
|
|
24
24
|
// Init PostHog once per plugin iframe
|
|
25
25
|
useEffect(() => {
|
|
26
26
|
if (!posthog.__loaded) {
|
|
@@ -94,6 +94,8 @@ export const PluginProvider = ({ children, pluginId, settings }) => {
|
|
|
94
94
|
useEffect(() => {
|
|
95
95
|
if (!client)
|
|
96
96
|
return;
|
|
97
|
+
if (settings === null || settings === void 0 ? void 0 : settings.disableScrollbarDetection)
|
|
98
|
+
return;
|
|
97
99
|
const checkScrollbar = () => {
|
|
98
100
|
const hasScrollbar = document.documentElement.scrollHeight > window.innerHeight;
|
|
99
101
|
client.event.emit('session.triggerScrollbarChange', { hasScrollbar });
|
|
@@ -109,7 +111,7 @@ export const PluginProvider = ({ children, pluginId, settings }) => {
|
|
|
109
111
|
window.removeEventListener('resize', checkScrollbar);
|
|
110
112
|
resizeObserver.disconnect();
|
|
111
113
|
};
|
|
112
|
-
}, [client]);
|
|
114
|
+
}, [client, settings === null || settings === void 0 ? void 0 : settings.disableScrollbarDetection]);
|
|
113
115
|
if (standaloneClient instanceof StandaloneClient) {
|
|
114
116
|
return (_jsx(StandaloneAuth, { onLogin: (email, password) => __awaiter(void 0, void 0, void 0, function* () {
|
|
115
117
|
if (yield standaloneClient.login(email, password))
|
package/package.json
CHANGED
package/src/hooks/ThemeSetter.ts
CHANGED
|
@@ -1,8 +1,15 @@
|
|
|
1
1
|
import { Theme } from '@rimori/client';
|
|
2
2
|
|
|
3
|
-
export function useTheme(
|
|
3
|
+
export function useTheme(
|
|
4
|
+
theme: Theme = 'system',
|
|
5
|
+
isDisabled = false,
|
|
6
|
+
): { isDark: boolean; theme: Theme; isDisabled: boolean } {
|
|
4
7
|
const isDark = theme === 'system' ? systenUsesDarkMode() : theme === 'dark';
|
|
5
8
|
|
|
9
|
+
if (isDisabled) {
|
|
10
|
+
return { isDark, theme, isDisabled };
|
|
11
|
+
}
|
|
12
|
+
|
|
6
13
|
const dom = document.documentElement;
|
|
7
14
|
dom.dataset.theme = isDark ? 'dark' : 'light';
|
|
8
15
|
dom.style.colorScheme = isDark ? 'dark' : 'light';
|
|
@@ -19,7 +26,7 @@ export function useTheme(theme: Theme = 'system'): { isDark: boolean; theme: The
|
|
|
19
26
|
'bg-fixed',
|
|
20
27
|
);
|
|
21
28
|
|
|
22
|
-
return { isDark, theme };
|
|
29
|
+
return { isDark, theme, isDisabled };
|
|
23
30
|
}
|
|
24
31
|
|
|
25
32
|
function systenUsesDarkMode(): boolean {
|
|
@@ -11,6 +11,12 @@ interface PluginProviderProps {
|
|
|
11
11
|
pluginId: string;
|
|
12
12
|
settings?: {
|
|
13
13
|
disableContextMenu?: boolean;
|
|
14
|
+
disableThemeSetting?: boolean;
|
|
15
|
+
/**
|
|
16
|
+
* Skip the scrollbar detection that emits 'session.triggerScrollbarChange'.
|
|
17
|
+
* In federation mode, the host (FederatedPluginRenderer) handles this instead.
|
|
18
|
+
*/
|
|
19
|
+
disableScrollbarDetection?: boolean;
|
|
14
20
|
};
|
|
15
21
|
}
|
|
16
22
|
|
|
@@ -28,7 +34,7 @@ export const PluginProvider: React.FC<PluginProviderProps> = ({ children, plugin
|
|
|
28
34
|
const [theme, setTheme] = useState<Theme | undefined>(undefined);
|
|
29
35
|
const [userInfo, setUserInfo] = useState<UserInfo | null>(null);
|
|
30
36
|
|
|
31
|
-
useTheme(theme);
|
|
37
|
+
useTheme(theme, settings?.disableThemeSetting);
|
|
32
38
|
|
|
33
39
|
// Init PostHog once per plugin iframe
|
|
34
40
|
useEffect(() => {
|
|
@@ -112,6 +118,7 @@ export const PluginProvider: React.FC<PluginProviderProps> = ({ children, plugin
|
|
|
112
118
|
|
|
113
119
|
useEffect(() => {
|
|
114
120
|
if (!client) return;
|
|
121
|
+
if (settings?.disableScrollbarDetection) return;
|
|
115
122
|
|
|
116
123
|
const checkScrollbar = (): void => {
|
|
117
124
|
const hasScrollbar = document.documentElement.scrollHeight > window.innerHeight;
|
|
@@ -133,7 +140,7 @@ export const PluginProvider: React.FC<PluginProviderProps> = ({ children, plugin
|
|
|
133
140
|
window.removeEventListener('resize', checkScrollbar);
|
|
134
141
|
resizeObserver.disconnect();
|
|
135
142
|
};
|
|
136
|
-
}, [client]);
|
|
143
|
+
}, [client, settings?.disableScrollbarDetection]);
|
|
137
144
|
|
|
138
145
|
if (standaloneClient instanceof StandaloneClient) {
|
|
139
146
|
return (
|