@rimori/react-client 0.4.2-next.1 → 0.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -6,14 +6,14 @@ import { CircleAudioAvatar } from './EmbeddedAssistent/CircleAudioAvatar';
6
6
  import { useChat } from '../../hooks/UseChatHook';
7
7
  import { useRimori } from '../../providers/PluginProvider';
8
8
  import { getFirstMessages } from './utils';
9
- import { useTheme } from '../../hooks/ThemeSetter';
9
+ import { isDarkTheme } from '../../hooks/ThemeSetter';
10
10
  export function Avatar({ avatarImageUrl, voiceId, agentTools, autoStartConversation, children, circleSize = '300px', className, }) {
11
- const { ai, event, plugin } = useRimori();
12
- const { isDark: isDarkThemeValue } = useTheme(plugin.theme);
11
+ const { ai, event } = useRimori();
13
12
  const [agentReplying, setAgentReplying] = useState(false);
14
13
  const [isProcessingMessage, setIsProcessingMessage] = useState(false);
15
14
  const sender = useMemo(() => new MessageSender(ai.getVoice, voiceId), [voiceId]);
16
15
  const { messages, append, isLoading, lastMessage, setMessages } = useChat(agentTools);
16
+ const isDarkThemeValue = useMemo(() => isDarkTheme(), []);
17
17
  useEffect(() => {
18
18
  console.log('messages', messages);
19
19
  }, [messages]);
@@ -1,5 +1,2 @@
1
- import { Theme } from '@rimori/client';
2
- export declare function useTheme(theme?: Theme): {
3
- isDark: boolean;
4
- theme: Theme;
5
- };
1
+ export declare function useTheme(theme?: string | null): boolean;
2
+ export declare function isDarkTheme(theme?: string | null): boolean;
@@ -1,13 +1,31 @@
1
- export function useTheme(theme = 'system') {
2
- const isDark = theme === 'system' ? systenUsesDarkMode() : theme === 'dark';
3
- const dom = document.documentElement;
4
- dom.style.background = 'hsl(var(--background))';
5
- dom.classList.add('text-gray-900', 'dark:text-gray-200', 'bg-gray-50', 'dark:bg-gray-950');
6
- const root = document.querySelector('#root');
7
- root.style.background = 'hsl(var(--background))';
8
- dom.classList[isDark ? 'add' : 'remove']('dark');
9
- return { isDark, theme };
1
+ import { useEffect, useState } from 'react';
2
+ export function useTheme(theme) {
3
+ const [isDark, setIsDark] = useState(false);
4
+ useEffect(() => {
5
+ const root = document.documentElement;
6
+ const nextIsDark = isDarkTheme(theme);
7
+ setIsDark(nextIsDark);
8
+ root.classList.add('dark:text-gray-200');
9
+ if (nextIsDark) {
10
+ root.setAttribute('data-theme', 'dark');
11
+ root.classList.add('dark', 'dark:bg-gray-950');
12
+ root.style.background = 'hsl(var(--background))';
13
+ return;
14
+ }
15
+ root.removeAttribute('data-theme');
16
+ root.classList.remove('dark', 'dark:bg-gray-950');
17
+ root.style.background = '';
18
+ }, [theme]);
19
+ return isDark;
10
20
  }
11
- function systenUsesDarkMode() {
12
- return window.matchMedia('(prefers-color-scheme: dark)').matches;
21
+ export function isDarkTheme(theme) {
22
+ // If no theme provided, try to get from URL as fallback (for standalone mode)
23
+ if (!theme) {
24
+ const urlParams = new URLSearchParams(window.location.search);
25
+ theme = urlParams.get('theme');
26
+ }
27
+ if (!theme || theme === 'system') {
28
+ return window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches;
29
+ }
30
+ return theme === 'dark';
13
31
  }
@@ -17,7 +17,7 @@ export const PluginProvider = ({ children, pluginId, settings }) => {
17
17
  const [client, setClient] = useState(null);
18
18
  const [standaloneClient, setStandaloneClient] = useState(false);
19
19
  const [applicationMode, setApplicationMode] = useState(null);
20
- const [theme, setTheme] = useState(undefined);
20
+ const [theme, setTheme] = useState(null);
21
21
  const [userInfo, setUserInfo] = useState(null);
22
22
  useTheme(theme);
23
23
  const isSidebar = applicationMode === 'sidebar';
@@ -38,8 +38,10 @@ export const PluginProvider = ({ children, pluginId, settings }) => {
38
38
  setUserInfo(client.plugin.getUserInfo());
39
39
  // Get applicationMode and theme from MessageChannel query params
40
40
  if (!standaloneDetected) {
41
- setTheme(client.plugin.theme);
42
- setApplicationMode(client.plugin.applicationMode);
41
+ const mode = client.getQueryParam('applicationMode');
42
+ const themeParam = client.getQueryParam('rm_theme');
43
+ setApplicationMode(mode);
44
+ setTheme(themeParam);
43
45
  client.event.emit('self.rimori.triggerInitFinished');
44
46
  }
45
47
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rimori/react-client",
3
- "version": "0.4.2-next.1",
3
+ "version": "0.4.2",
4
4
  "license": "Apache-2.0",
5
5
  "repository": {
6
6
  "type": "git",
@@ -23,7 +23,7 @@
23
23
  "format": "prettier --write ."
24
24
  },
25
25
  "peerDependencies": {
26
- "@rimori/client": "2.5.4-next.2",
26
+ "@rimori/client": "^2.5.3",
27
27
  "react": "^18.1.0",
28
28
  "react-dom": "^18.1.0"
29
29
  },
@@ -34,7 +34,7 @@
34
34
  },
35
35
  "devDependencies": {
36
36
  "@eslint/js": "^9.37.0",
37
- "@rimori/client": "2.5.4-next.2",
37
+ "@rimori/client": "^2.5.3",
38
38
  "@types/react": "^18.3.21",
39
39
  "eslint-config-prettier": "^10.1.8",
40
40
  "eslint-plugin-prettier": "^5.5.4",
@@ -7,7 +7,7 @@ import { useChat } from '../../hooks/UseChatHook';
7
7
  import { useRimori } from '../../providers/PluginProvider';
8
8
  import { getFirstMessages } from './utils';
9
9
  import { FirstMessages } from './utils';
10
- import { useTheme } from '../../hooks/ThemeSetter';
10
+ import { isDarkTheme } from '../../hooks/ThemeSetter';
11
11
 
12
12
  interface Props {
13
13
  voiceId: string;
@@ -28,12 +28,12 @@ export function Avatar({
28
28
  circleSize = '300px',
29
29
  className,
30
30
  }: Props) {
31
- const { ai, event, plugin } = useRimori();
32
- const { isDark: isDarkThemeValue } = useTheme(plugin.theme);
31
+ const { ai, event } = useRimori();
33
32
  const [agentReplying, setAgentReplying] = useState(false);
34
33
  const [isProcessingMessage, setIsProcessingMessage] = useState(false);
35
34
  const sender = useMemo(() => new MessageSender(ai.getVoice, voiceId), [voiceId]);
36
35
  const { messages, append, isLoading, lastMessage, setMessages } = useChat(agentTools);
36
+ const isDarkThemeValue = useMemo(() => isDarkTheme(), []);
37
37
 
38
38
  useEffect(() => {
39
39
  console.log('messages', messages);
@@ -1,20 +1,40 @@
1
- import { Theme } from '@rimori/client';
1
+ import { useEffect, useState } from 'react';
2
2
 
3
- export function useTheme(theme: Theme = 'system'): { isDark: boolean; theme: Theme } {
4
- const isDark = theme === 'system' ? systenUsesDarkMode() : theme === 'dark';
3
+ export function useTheme(theme?: string | null): boolean {
4
+ const [isDark, setIsDark] = useState(false);
5
5
 
6
- const dom = document.documentElement;
7
- dom.style.background = 'hsl(var(--background))';
8
- dom.classList.add('text-gray-900', 'dark:text-gray-200', 'bg-gray-50', 'dark:bg-gray-950');
6
+ useEffect(() => {
7
+ const root = document.documentElement;
8
+ const nextIsDark = isDarkTheme(theme);
9
9
 
10
- const root = document.querySelector('#root') as HTMLDivElement;
11
- root.style.background = 'hsl(var(--background))';
10
+ setIsDark(nextIsDark);
11
+ root.classList.add('dark:text-gray-200');
12
12
 
13
- dom.classList[isDark ? 'add' : 'remove']('dark');
13
+ if (nextIsDark) {
14
+ root.setAttribute('data-theme', 'dark');
15
+ root.classList.add('dark', 'dark:bg-gray-950');
16
+ root.style.background = 'hsl(var(--background))';
17
+ return;
18
+ }
14
19
 
15
- return { isDark, theme };
20
+ root.removeAttribute('data-theme');
21
+ root.classList.remove('dark', 'dark:bg-gray-950');
22
+ root.style.background = '';
23
+ }, [theme]);
24
+
25
+ return isDark;
16
26
  }
17
27
 
18
- function systenUsesDarkMode(): boolean {
19
- return window.matchMedia('(prefers-color-scheme: dark)').matches;
28
+ export function isDarkTheme(theme?: string | null): boolean {
29
+ // If no theme provided, try to get from URL as fallback (for standalone mode)
30
+ if (!theme) {
31
+ const urlParams = new URLSearchParams(window.location.search);
32
+ theme = urlParams.get('theme');
33
+ }
34
+
35
+ if (!theme || theme === 'system') {
36
+ return window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches;
37
+ }
38
+
39
+ return theme === 'dark';
20
40
  }
@@ -3,7 +3,6 @@ import { EventBusHandler, RimoriClient, StandaloneClient } from '@rimori/client'
3
3
  import type { UserInfo } from '@rimori/client';
4
4
  import ContextMenu from '../components/ContextMenu';
5
5
  import { useTheme } from '../hooks/ThemeSetter';
6
- import { Theme } from '@rimori/client';
7
6
 
8
7
  interface PluginProviderProps {
9
8
  children: ReactNode;
@@ -24,7 +23,7 @@ export const PluginProvider: React.FC<PluginProviderProps> = ({ children, plugin
24
23
  const [client, setClient] = useState<RimoriClient | null>(null);
25
24
  const [standaloneClient, setStandaloneClient] = useState<StandaloneClient | boolean>(false);
26
25
  const [applicationMode, setApplicationMode] = useState<string | null>(null);
27
- const [theme, setTheme] = useState<Theme | undefined>(undefined);
26
+ const [theme, setTheme] = useState<string | null>(null);
28
27
  const [userInfo, setUserInfo] = useState<UserInfo | null>(null);
29
28
 
30
29
  useTheme(theme);
@@ -52,8 +51,10 @@ export const PluginProvider: React.FC<PluginProviderProps> = ({ children, plugin
52
51
 
53
52
  // Get applicationMode and theme from MessageChannel query params
54
53
  if (!standaloneDetected) {
55
- setTheme(client.plugin.theme);
56
- setApplicationMode(client.plugin.applicationMode);
54
+ const mode = client.getQueryParam('applicationMode');
55
+ const themeParam = client.getQueryParam('rm_theme');
56
+ setApplicationMode(mode);
57
+ setTheme(themeParam);
57
58
  client.event.emit('self.rimori.triggerInitFinished');
58
59
  }
59
60
  });