@rimori/react-client 0.1.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/.prettierignore +35 -0
- package/LICENSE +201 -0
- package/README copy.md +1216 -0
- package/README.md +1 -0
- package/dist/components/MarkdownEditor.d.ts +8 -0
- package/dist/components/MarkdownEditor.js +48 -0
- package/dist/components/Spinner.d.ts +8 -0
- package/dist/components/Spinner.js +4 -0
- package/dist/components/ai/Assistant.d.ts +9 -0
- package/dist/components/ai/Assistant.js +58 -0
- package/dist/components/ai/Avatar.d.ts +14 -0
- package/dist/components/ai/Avatar.js +59 -0
- package/dist/components/ai/EmbeddedAssistent/AudioInputField.d.ts +7 -0
- package/dist/components/ai/EmbeddedAssistent/AudioInputField.js +37 -0
- package/dist/components/ai/EmbeddedAssistent/CircleAudioAvatar.d.ts +8 -0
- package/dist/components/ai/EmbeddedAssistent/CircleAudioAvatar.js +79 -0
- package/dist/components/ai/EmbeddedAssistent/TTS/MessageSender.d.ts +19 -0
- package/dist/components/ai/EmbeddedAssistent/TTS/MessageSender.js +91 -0
- package/dist/components/ai/EmbeddedAssistent/TTS/Player.d.ts +27 -0
- package/dist/components/ai/EmbeddedAssistent/TTS/Player.js +185 -0
- package/dist/components/ai/EmbeddedAssistent/VoiceRecoder.d.ts +11 -0
- package/dist/components/ai/EmbeddedAssistent/VoiceRecoder.js +95 -0
- package/dist/components/ai/utils.d.ts +6 -0
- package/dist/components/ai/utils.js +13 -0
- package/dist/components/audio/Playbutton.d.ts +15 -0
- package/dist/components/audio/Playbutton.js +80 -0
- package/dist/components/components/ContextMenu.d.ts +10 -0
- package/dist/components/components/ContextMenu.js +135 -0
- package/dist/hooks/I18nHooks.d.ts +11 -0
- package/dist/hooks/I18nHooks.js +25 -0
- package/dist/hooks/UseChatHook.d.ts +10 -0
- package/dist/hooks/UseChatHook.js +29 -0
- package/dist/providers/PluginProvider.d.ts +11 -0
- package/dist/providers/PluginProvider.js +142 -0
- package/dist/react-client/plugin/ThemeSetter.d.ts +2 -0
- package/dist/react-client/plugin/ThemeSetter.js +19 -0
- package/dist/react-client/src/components/ContextMenu.d.ts +10 -0
- package/dist/react-client/src/components/ContextMenu.js +135 -0
- package/dist/react-client/src/components/MarkdownEditor.d.ts +8 -0
- package/dist/react-client/src/components/MarkdownEditor.js +48 -0
- package/dist/react-client/src/components/Spinner.d.ts +8 -0
- package/dist/react-client/src/components/Spinner.js +4 -0
- package/dist/react-client/src/components/ai/Assistant.d.ts +9 -0
- package/dist/react-client/src/components/ai/Assistant.js +58 -0
- package/dist/react-client/src/components/ai/Avatar.d.ts +14 -0
- package/dist/react-client/src/components/ai/Avatar.js +59 -0
- package/dist/react-client/src/components/ai/EmbeddedAssistent/AudioInputField.d.ts +7 -0
- package/dist/react-client/src/components/ai/EmbeddedAssistent/AudioInputField.js +37 -0
- package/dist/react-client/src/components/ai/EmbeddedAssistent/CircleAudioAvatar.d.ts +8 -0
- package/dist/react-client/src/components/ai/EmbeddedAssistent/CircleAudioAvatar.js +79 -0
- package/dist/react-client/src/components/ai/EmbeddedAssistent/TTS/MessageSender.d.ts +19 -0
- package/dist/react-client/src/components/ai/EmbeddedAssistent/TTS/MessageSender.js +91 -0
- package/dist/react-client/src/components/ai/EmbeddedAssistent/TTS/Player.d.ts +27 -0
- package/dist/react-client/src/components/ai/EmbeddedAssistent/TTS/Player.js +185 -0
- package/dist/react-client/src/components/ai/EmbeddedAssistent/VoiceRecoder.d.ts +11 -0
- package/dist/react-client/src/components/ai/EmbeddedAssistent/VoiceRecoder.js +95 -0
- package/dist/react-client/src/components/ai/utils.d.ts +6 -0
- package/dist/react-client/src/components/ai/utils.js +13 -0
- package/dist/react-client/src/components/audio/Playbutton.d.ts +15 -0
- package/dist/react-client/src/components/audio/Playbutton.js +82 -0
- package/dist/react-client/src/components/components/ContextMenu.d.ts +10 -0
- package/dist/react-client/src/components/components/ContextMenu.js +135 -0
- package/dist/react-client/src/hooks/I18nHooks.d.ts +11 -0
- package/dist/react-client/src/hooks/I18nHooks.js +25 -0
- package/dist/react-client/src/hooks/UseChatHook.d.ts +10 -0
- package/dist/react-client/src/hooks/UseChatHook.js +29 -0
- package/dist/react-client/src/plugin/ThemeSetter.d.ts +2 -0
- package/dist/react-client/src/plugin/ThemeSetter.js +19 -0
- package/dist/react-client/src/providers/PluginProvider.d.ts +12 -0
- package/dist/react-client/src/providers/PluginProvider.js +142 -0
- package/dist/react-client/src/utils/FullscreenUtils.d.ts +2 -0
- package/dist/react-client/src/utils/FullscreenUtils.js +23 -0
- package/dist/react-client/src/utils/PluginUtils.d.ts +2 -0
- package/dist/react-client/src/utils/PluginUtils.js +23 -0
- package/dist/rimori-client/src/cli/types/DatabaseTypes.d.ts +103 -0
- package/dist/rimori-client/src/cli/types/DatabaseTypes.js +2 -0
- package/dist/rimori-client/src/controller/AIController.d.ts +15 -0
- package/dist/rimori-client/src/controller/AIController.js +255 -0
- package/dist/rimori-client/src/controller/AccomplishmentController.d.ts +38 -0
- package/dist/rimori-client/src/controller/AccomplishmentController.js +112 -0
- package/dist/rimori-client/src/controller/AudioController.d.ts +37 -0
- package/dist/rimori-client/src/controller/AudioController.js +68 -0
- package/dist/rimori-client/src/controller/ExerciseController.d.ts +54 -0
- package/dist/rimori-client/src/controller/ExerciseController.js +74 -0
- package/dist/rimori-client/src/controller/ObjectController.d.ts +42 -0
- package/dist/rimori-client/src/controller/ObjectController.js +76 -0
- package/dist/rimori-client/src/controller/SettingsController.d.ts +79 -0
- package/dist/rimori-client/src/controller/SettingsController.js +118 -0
- package/dist/rimori-client/src/controller/SharedContentController.d.ts +106 -0
- package/dist/rimori-client/src/controller/SharedContentController.js +285 -0
- package/dist/rimori-client/src/controller/TranslationController.d.ts +38 -0
- package/dist/rimori-client/src/controller/TranslationController.js +106 -0
- package/dist/rimori-client/src/controller/VoiceController.d.ts +9 -0
- package/dist/rimori-client/src/controller/VoiceController.js +37 -0
- package/dist/rimori-client/src/fromRimori/EventBus.d.ts +101 -0
- package/dist/rimori-client/src/fromRimori/EventBus.js +263 -0
- package/dist/rimori-client/src/fromRimori/PluginTypes.d.ts +174 -0
- package/dist/rimori-client/src/fromRimori/PluginTypes.js +1 -0
- package/dist/rimori-client/src/index.d.ts +11 -0
- package/dist/rimori-client/src/index.js +10 -0
- package/dist/rimori-client/src/plugin/CommunicationHandler.d.ts +48 -0
- package/dist/rimori-client/src/plugin/CommunicationHandler.js +234 -0
- package/dist/rimori-client/src/plugin/Logger.d.ts +73 -0
- package/dist/rimori-client/src/plugin/Logger.js +308 -0
- package/dist/rimori-client/src/plugin/RimoriClient.d.ts +258 -0
- package/dist/rimori-client/src/plugin/RimoriClient.js +375 -0
- package/dist/rimori-client/src/plugin/StandaloneClient.d.ts +17 -0
- package/dist/rimori-client/src/plugin/StandaloneClient.js +115 -0
- package/dist/rimori-client/src/utils/difficultyConverter.d.ts +4 -0
- package/dist/rimori-client/src/utils/difficultyConverter.js +10 -0
- package/dist/rimori-client/src/utils/endpoint.d.ts +2 -0
- package/dist/rimori-client/src/utils/endpoint.js +2 -0
- package/dist/style.css +110 -0
- package/dist/style.css.map +1 -0
- package/dist/utils/PluginUtils.d.ts +2 -0
- package/dist/utils/PluginUtils.js +23 -0
- package/eslint.config.js +53 -0
- package/index.ts +6 -0
- package/package.json +47 -0
- package/prettier.config.js +8 -0
- package/src/components/ContextMenu.tsx +177 -0
- package/src/components/MarkdownEditor.tsx +144 -0
- package/src/components/Spinner.tsx +29 -0
- package/src/components/ai/Assistant.tsx +96 -0
- package/src/components/ai/Avatar.tsx +99 -0
- package/src/components/ai/EmbeddedAssistent/AudioInputField.tsx +73 -0
- package/src/components/ai/EmbeddedAssistent/CircleAudioAvatar.tsx +107 -0
- package/src/components/ai/EmbeddedAssistent/TTS/MessageSender.ts +96 -0
- package/src/components/ai/EmbeddedAssistent/TTS/Player.ts +197 -0
- package/src/components/ai/EmbeddedAssistent/VoiceRecoder.tsx +129 -0
- package/src/components/ai/utils.ts +21 -0
- package/src/components/audio/Playbutton.tsx +126 -0
- package/src/hooks/I18nHooks.ts +33 -0
- package/src/hooks/UseChatHook.ts +38 -0
- package/src/plugin/ThemeSetter.ts +23 -0
- package/src/providers/PluginProvider.tsx +197 -0
- package/src/style.scss +136 -0
- package/src/utils/FullscreenUtils.ts +22 -0
- package/tsconfig.json +23 -0
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
11
|
+
import { createContext, useContext, useEffect, useState } from 'react';
|
|
12
|
+
import { RimoriClient, StandaloneClient } from '@rimori/client';
|
|
13
|
+
import ContextMenu from '../components/components/ContextMenu';
|
|
14
|
+
const PluginContext = createContext(null);
|
|
15
|
+
export const PluginProvider = ({ children, pluginId, settings }) => {
|
|
16
|
+
const [plugin, setPlugin] = useState(null);
|
|
17
|
+
const [standaloneClient, setStandaloneClient] = useState(false);
|
|
18
|
+
const [applicationMode, setApplicationMode] = useState(null);
|
|
19
|
+
const [theme, setTheme] = useState(null);
|
|
20
|
+
const isSidebar = applicationMode === 'sidebar';
|
|
21
|
+
const isSettings = applicationMode === 'settings';
|
|
22
|
+
useEffect(() => {
|
|
23
|
+
initEventBus(pluginId);
|
|
24
|
+
// Check if we're in an iframe context - if not, we're standalone
|
|
25
|
+
const standaloneDetected = window === window.parent;
|
|
26
|
+
if (standaloneDetected && !standaloneClient) {
|
|
27
|
+
StandaloneClient.getInstance().then((client) => {
|
|
28
|
+
client.needsLogin().then((needLogin) => setStandaloneClient(needLogin ? client : true));
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
if ((!standaloneDetected && !plugin) || (standaloneDetected && standaloneClient === true)) {
|
|
32
|
+
RimoriClient.getInstance(pluginId, standaloneDetected).then((client) => {
|
|
33
|
+
setPlugin(client);
|
|
34
|
+
// Get applicationMode and theme from MessageChannel query params
|
|
35
|
+
if (!standaloneDetected) {
|
|
36
|
+
const mode = client.getQueryParam('applicationMode');
|
|
37
|
+
const themeParam = client.getQueryParam('rm_theme');
|
|
38
|
+
setApplicationMode(mode);
|
|
39
|
+
setTheme(themeParam);
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
}, [pluginId, standaloneClient]);
|
|
44
|
+
//route change
|
|
45
|
+
useEffect(() => {
|
|
46
|
+
if (!plugin)
|
|
47
|
+
return;
|
|
48
|
+
//sidebar pages should not report url changes
|
|
49
|
+
if (isSidebar)
|
|
50
|
+
return;
|
|
51
|
+
let lastHash = window.location.hash;
|
|
52
|
+
const emitUrlChange = (url) => plugin.event.emit('session.triggerUrlChange', { url });
|
|
53
|
+
const interval = setInterval(() => {
|
|
54
|
+
if (lastHash === window.location.hash)
|
|
55
|
+
return;
|
|
56
|
+
lastHash = window.location.hash;
|
|
57
|
+
// console.log('url changed:', lastHash);
|
|
58
|
+
emitUrlChange(lastHash);
|
|
59
|
+
}, 1000);
|
|
60
|
+
emitUrlChange(lastHash);
|
|
61
|
+
return () => clearInterval(interval);
|
|
62
|
+
}, [plugin]);
|
|
63
|
+
if (standaloneClient instanceof StandaloneClient) {
|
|
64
|
+
return (_jsx(StandaloneAuth, { onLogin: (email, password) => __awaiter(void 0, void 0, void 0, function* () {
|
|
65
|
+
if (yield standaloneClient.login(email, password))
|
|
66
|
+
setStandaloneClient(true);
|
|
67
|
+
}) }));
|
|
68
|
+
}
|
|
69
|
+
if (!plugin) {
|
|
70
|
+
return '';
|
|
71
|
+
}
|
|
72
|
+
return (_jsxs(PluginContext.Provider, { value: plugin, children: [!(settings === null || settings === void 0 ? void 0 : settings.disableContextMenu) && !isSidebar && !isSettings && _jsx(ContextMenu, { client: plugin }), children] }));
|
|
73
|
+
};
|
|
74
|
+
export const useRimori = () => {
|
|
75
|
+
const context = useContext(PluginContext);
|
|
76
|
+
if (context === null) {
|
|
77
|
+
throw new Error('useRimori must be used within an PluginProvider');
|
|
78
|
+
}
|
|
79
|
+
return context;
|
|
80
|
+
};
|
|
81
|
+
function getUrlParam(name) {
|
|
82
|
+
// First try to get from URL hash query params (for compatibility)
|
|
83
|
+
const hashParts = window.location.hash.split('?');
|
|
84
|
+
if (hashParts.length > 1) {
|
|
85
|
+
const hashParams = new URLSearchParams(hashParts[1]);
|
|
86
|
+
const hashValue = hashParams.get(name);
|
|
87
|
+
if (hashValue)
|
|
88
|
+
return hashValue;
|
|
89
|
+
}
|
|
90
|
+
// Fallback to regular URL search params
|
|
91
|
+
const url = new URL(window.location.href);
|
|
92
|
+
return url.searchParams.get(name);
|
|
93
|
+
}
|
|
94
|
+
function initEventBus(pluginId) {
|
|
95
|
+
// For now, use URL fallback for EventBus naming - this will be updated once MessageChannel is ready
|
|
96
|
+
const isSidebar = getUrlParam('applicationMode') === 'sidebar';
|
|
97
|
+
EventBusHandler.getInstance('Plugin EventBus ' + pluginId + ' ' + (isSidebar ? 'sidebar' : 'main'));
|
|
98
|
+
}
|
|
99
|
+
function StandaloneAuth({ onLogin }) {
|
|
100
|
+
const [user, setUser] = useState('');
|
|
101
|
+
const [password, setPassword] = useState('');
|
|
102
|
+
return (_jsx("div", { style: {
|
|
103
|
+
position: 'fixed',
|
|
104
|
+
inset: 0,
|
|
105
|
+
display: 'flex',
|
|
106
|
+
alignItems: 'center',
|
|
107
|
+
justifyContent: 'center',
|
|
108
|
+
backgroundColor: 'rgba(0, 0, 0, 0.5)',
|
|
109
|
+
}, children: _jsxs("div", { style: {
|
|
110
|
+
backgroundColor: '#343534',
|
|
111
|
+
padding: '1rem',
|
|
112
|
+
borderRadius: '0.5rem',
|
|
113
|
+
width: '500px',
|
|
114
|
+
flexDirection: 'column',
|
|
115
|
+
display: 'flex',
|
|
116
|
+
alignItems: 'center',
|
|
117
|
+
justifyContent: 'center',
|
|
118
|
+
}, children: [_jsx("p", { style: { fontSize: '2rem', fontWeight: 'bold', marginBottom: '1rem', textAlign: 'center' }, children: "Rimori Login" }), _jsx("p", { style: { marginBottom: '1rem', textAlign: 'center' }, children: "Please login with your Rimori developer account for this plugin to be able to access the Rimori platform the same it will operate in the Rimori platform." }), _jsx("input", { style: {
|
|
119
|
+
marginBottom: '1rem',
|
|
120
|
+
width: '100%',
|
|
121
|
+
padding: '0.5rem',
|
|
122
|
+
borderRadius: '0.5rem',
|
|
123
|
+
border: 'none',
|
|
124
|
+
backgroundColor: '#444444',
|
|
125
|
+
}, type: "email", placeholder: "Email", onChange: (e) => setUser(e.target.value) }), _jsx("input", { style: {
|
|
126
|
+
marginBottom: '1rem',
|
|
127
|
+
width: '100%',
|
|
128
|
+
padding: '0.5rem',
|
|
129
|
+
borderRadius: '0.5rem',
|
|
130
|
+
border: 'none',
|
|
131
|
+
backgroundColor: '#444444',
|
|
132
|
+
}, type: "password", placeholder: "Password", onChange: (e) => setPassword(e.target.value) }), _jsx("button", { style: {
|
|
133
|
+
marginBottom: '1rem',
|
|
134
|
+
width: '100%',
|
|
135
|
+
padding: '0.5rem',
|
|
136
|
+
borderRadius: '0.5rem',
|
|
137
|
+
border: 'none',
|
|
138
|
+
backgroundColor: '#928358',
|
|
139
|
+
}, onClick: () => {
|
|
140
|
+
onLogin(user, password);
|
|
141
|
+
}, children: "Login" })] }) }));
|
|
142
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export function setTheme(theme) {
|
|
2
|
+
document.documentElement.classList.add('dark:text-gray-200');
|
|
3
|
+
if (isDarkTheme(theme)) {
|
|
4
|
+
document.documentElement.setAttribute('data-theme', 'dark');
|
|
5
|
+
document.documentElement.classList.add('dark', 'dark:bg-gray-950');
|
|
6
|
+
document.documentElement.style.background = 'hsl(var(--background))';
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
export function isDarkTheme(theme) {
|
|
10
|
+
// If no theme provided, try to get from URL as fallback (for standalone mode)
|
|
11
|
+
if (!theme) {
|
|
12
|
+
const urlParams = new URLSearchParams(window.location.search);
|
|
13
|
+
theme = urlParams.get('theme');
|
|
14
|
+
}
|
|
15
|
+
if (!theme || theme === 'system') {
|
|
16
|
+
return window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches;
|
|
17
|
+
}
|
|
18
|
+
return theme === 'dark';
|
|
19
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { RimoriClient } from '@rimori/client';
|
|
2
|
+
export interface Position {
|
|
3
|
+
x: number;
|
|
4
|
+
y: number;
|
|
5
|
+
text?: string;
|
|
6
|
+
}
|
|
7
|
+
declare const ContextMenu: ({ client }: {
|
|
8
|
+
client: RimoriClient;
|
|
9
|
+
}) => import("react/jsx-runtime").JSX.Element | null;
|
|
10
|
+
export default ContextMenu;
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useState, useEffect, useRef } from 'react';
|
|
3
|
+
import { EventBus } from '@rimori/client';
|
|
4
|
+
const ContextMenu = ({ client }) => {
|
|
5
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
6
|
+
const [actions, setActions] = useState([]);
|
|
7
|
+
const [position, setPosition] = useState({ x: 0, y: 0 });
|
|
8
|
+
const [openOnTextSelect, setOpenOnTextSelect] = useState(false);
|
|
9
|
+
const [menuWidth, setMenuWidth] = useState(0);
|
|
10
|
+
const menuRef = useRef(null);
|
|
11
|
+
const isMobile = window.innerWidth < 768;
|
|
12
|
+
/**
|
|
13
|
+
* Calculates position for mobile context menu based on selected text bounds.
|
|
14
|
+
* Centers the menu horizontally over the selected text and positions it 30px below the text's end.
|
|
15
|
+
* @param selectedText - The currently selected text
|
|
16
|
+
* @param menuWidth - The width of the menu to center properly
|
|
17
|
+
* @returns Position object with x and y coordinates
|
|
18
|
+
*/
|
|
19
|
+
const calculateMobilePosition = (selectedText, menuWidth = 0) => {
|
|
20
|
+
const selection = window.getSelection();
|
|
21
|
+
if (!selection || !selectedText) {
|
|
22
|
+
return { x: 0, y: 0, text: selectedText };
|
|
23
|
+
}
|
|
24
|
+
const range = selection.getRangeAt(0);
|
|
25
|
+
const rect = range.getBoundingClientRect();
|
|
26
|
+
// Center horizontally over the selected text, accounting for menu width
|
|
27
|
+
const centerX = rect.left + rect.width / 2 - menuWidth / 2;
|
|
28
|
+
// Position 12px below where the text ends vertically
|
|
29
|
+
const textEndY = rect.bottom + 12;
|
|
30
|
+
return { x: centerX, y: textEndY, text: selectedText };
|
|
31
|
+
};
|
|
32
|
+
useEffect(() => {
|
|
33
|
+
const actions = client.plugin
|
|
34
|
+
.getPluginInfo()
|
|
35
|
+
.installedPlugins.flatMap((p) => p.context_menu_actions)
|
|
36
|
+
.filter(Boolean);
|
|
37
|
+
setActions(actions);
|
|
38
|
+
setOpenOnTextSelect(client.plugin.getUserInfo().context_menu_on_select);
|
|
39
|
+
EventBus.on('global.contextMenu.createActions', ({ data }) => {
|
|
40
|
+
setActions([...data.actions, ...actions]);
|
|
41
|
+
});
|
|
42
|
+
}, []);
|
|
43
|
+
// Update menu width when menu is rendered
|
|
44
|
+
useEffect(() => {
|
|
45
|
+
if (isOpen && menuRef.current) {
|
|
46
|
+
setMenuWidth(menuRef.current.offsetWidth);
|
|
47
|
+
}
|
|
48
|
+
}, [isOpen, actions]);
|
|
49
|
+
useEffect(() => {
|
|
50
|
+
// Track mouse position globally
|
|
51
|
+
const handleMouseMove = (e) => {
|
|
52
|
+
var _a;
|
|
53
|
+
const selectedText = (_a = window.getSelection()) === null || _a === void 0 ? void 0 : _a.toString().trim();
|
|
54
|
+
if (isOpen && selectedText === position.text)
|
|
55
|
+
return;
|
|
56
|
+
if (isMobile && selectedText) {
|
|
57
|
+
setPosition(calculateMobilePosition(selectedText, menuWidth));
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
setPosition({ x: e.clientX, y: e.clientY, text: selectedText });
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
const handleMouseUp = (e) => {
|
|
64
|
+
var _a, _b;
|
|
65
|
+
const selectedText = (_a = window.getSelection()) === null || _a === void 0 ? void 0 : _a.toString().trim();
|
|
66
|
+
// Check if click is inside the context menu
|
|
67
|
+
if (menuRef.current && menuRef.current.contains(e.target)) {
|
|
68
|
+
// Don't close the menu if clicking inside
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
// Prevent context menu on textarea or text input selection
|
|
72
|
+
const target = e.target;
|
|
73
|
+
const isTextInput = target &&
|
|
74
|
+
(target.tagName === 'TEXTAREA' || (target.tagName === 'INPUT' && target.type === 'text'));
|
|
75
|
+
if (isTextInput) {
|
|
76
|
+
setIsOpen(false);
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
if (e.button === 0 && isOpen) {
|
|
80
|
+
setIsOpen(false);
|
|
81
|
+
(_b = window.getSelection()) === null || _b === void 0 ? void 0 : _b.removeAllRanges();
|
|
82
|
+
}
|
|
83
|
+
else if (selectedText && (openOnTextSelect || e.button === 2)) {
|
|
84
|
+
if (e.button === 2) {
|
|
85
|
+
e.preventDefault();
|
|
86
|
+
}
|
|
87
|
+
if (isMobile) {
|
|
88
|
+
setPosition(calculateMobilePosition(selectedText, menuWidth));
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
setPosition({ x: e.clientX, y: e.clientY, text: selectedText });
|
|
92
|
+
}
|
|
93
|
+
setIsOpen(true);
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
setIsOpen(false);
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
// Add selectionchange listener to close menu if selection is cleared and update position for mobile
|
|
100
|
+
const handleSelectionChange = () => {
|
|
101
|
+
var _a;
|
|
102
|
+
const selectedText = (_a = window.getSelection()) === null || _a === void 0 ? void 0 : _a.toString().trim();
|
|
103
|
+
if (!selectedText && isOpen) {
|
|
104
|
+
setIsOpen(false);
|
|
105
|
+
}
|
|
106
|
+
else if (selectedText && isOpen && isMobile) {
|
|
107
|
+
// Update position in real-time as text selection changes on mobile
|
|
108
|
+
setPosition(calculateMobilePosition(selectedText, menuWidth));
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
document.addEventListener('mouseup', handleMouseUp);
|
|
112
|
+
window.addEventListener('mousemove', handleMouseMove);
|
|
113
|
+
document.addEventListener('contextmenu', handleMouseUp);
|
|
114
|
+
document.addEventListener('selectionchange', handleSelectionChange);
|
|
115
|
+
return () => {
|
|
116
|
+
document.removeEventListener('mouseup', handleMouseUp);
|
|
117
|
+
window.removeEventListener('mousemove', handleMouseMove);
|
|
118
|
+
document.removeEventListener('contextmenu', handleMouseUp);
|
|
119
|
+
document.removeEventListener('selectionchange', handleSelectionChange);
|
|
120
|
+
};
|
|
121
|
+
}, [openOnTextSelect, isOpen, position.text]);
|
|
122
|
+
if (!isOpen) {
|
|
123
|
+
return null;
|
|
124
|
+
}
|
|
125
|
+
return (_jsx("div", { ref: menuRef, className: "fixed bg-gray-400 dark:bg-gray-700 shadow-lg border border-gray-400 rounded-md overflow-hidden dark:text-white z-50", style: { top: position.y, left: position.x }, children: actions.map((action, index) => (_jsx(MenuEntryItem, { icon: action.icon, text: action.text, onClick: () => {
|
|
126
|
+
var _a;
|
|
127
|
+
setIsOpen(false);
|
|
128
|
+
(_a = window.getSelection()) === null || _a === void 0 ? void 0 : _a.removeAllRanges();
|
|
129
|
+
client.event.emitSidebarAction(action.plugin_id, action.action_key, position.text);
|
|
130
|
+
} }, index))) }));
|
|
131
|
+
};
|
|
132
|
+
function MenuEntryItem(props) {
|
|
133
|
+
return (_jsxs("button", { onClick: props.onClick, className: "px-4 py-2 text-left hover:bg-gray-500 dark:hover:bg-gray-600 w-full flex flex-row", children: [_jsx("span", { className: "flex-grow", children: props.icon }), _jsx("span", { className: "flex-grow", children: props.text })] }));
|
|
134
|
+
}
|
|
135
|
+
export default ContextMenu;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Markdown } from 'tiptap-markdown';
|
|
3
|
+
import StarterKit from '@tiptap/starter-kit';
|
|
4
|
+
import { PiCodeBlock } from 'react-icons/pi';
|
|
5
|
+
import { TbBlockquote } from 'react-icons/tb';
|
|
6
|
+
import { GoListOrdered } from 'react-icons/go';
|
|
7
|
+
import { AiOutlineUnorderedList } from 'react-icons/ai';
|
|
8
|
+
import { EditorProvider, useCurrentEditor } from '@tiptap/react';
|
|
9
|
+
import { LuHeading1, LuHeading2, LuHeading3 } from 'react-icons/lu';
|
|
10
|
+
import { FaBold, FaCode, FaItalic, FaParagraph, FaStrikethrough } from 'react-icons/fa';
|
|
11
|
+
const EditorButton = ({ action, isActive, label, disabled }) => {
|
|
12
|
+
const { editor } = useCurrentEditor();
|
|
13
|
+
if (!editor) {
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
if (action.includes('heading')) {
|
|
17
|
+
const level = parseInt(action[action.length - 1]);
|
|
18
|
+
return (_jsx("button", { onClick: () => editor.chain().focus().toggleHeading({ level: level }).run(), className: `pl-2 ${isActive ? 'is-active' : ''}`, children: label }));
|
|
19
|
+
}
|
|
20
|
+
return (_jsx("button", { onClick: () => editor.chain().focus()[action]().run(), disabled: disabled ? !editor.can().chain().focus()[action]().run() : false, className: `pl-2 ${isActive ? 'is-active' : ''}`, children: label }));
|
|
21
|
+
};
|
|
22
|
+
const MenuBar = () => {
|
|
23
|
+
const { editor } = useCurrentEditor();
|
|
24
|
+
if (!editor) {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
return (_jsxs("div", { className: "bg-gray-400 dark:bg-gray-800 dark:text-white text-lg flex flex-row flex-wrap items-center p-1", children: [_jsx(EditorButton, { action: "toggleBold", isActive: editor.isActive('bold'), label: _jsx(FaBold, {}), disabled: true }), _jsx(EditorButton, { action: "toggleItalic", isActive: editor.isActive('italic'), label: _jsx(FaItalic, {}), disabled: true }), _jsx(EditorButton, { action: "toggleStrike", isActive: editor.isActive('strike'), label: _jsx(FaStrikethrough, {}), disabled: true }), _jsx(EditorButton, { action: "toggleCode", isActive: editor.isActive('code'), label: _jsx(FaCode, {}), disabled: true }), _jsx(EditorButton, { action: "setParagraph", isActive: editor.isActive('paragraph'), label: _jsx(FaParagraph, {}) }), _jsx(EditorButton, { action: "setHeading1", isActive: editor.isActive('heading', { level: 1 }), label: _jsx(LuHeading1, { size: '24px' }) }), _jsx(EditorButton, { action: "setHeading2", isActive: editor.isActive('heading', { level: 2 }), label: _jsx(LuHeading2, { size: '24px' }) }), _jsx(EditorButton, { action: "setHeading3", isActive: editor.isActive('heading', { level: 3 }), label: _jsx(LuHeading3, { size: '24px' }) }), _jsx(EditorButton, { action: "toggleBulletList", isActive: editor.isActive('bulletList'), label: _jsx(AiOutlineUnorderedList, { size: '24px' }) }), _jsx(EditorButton, { action: "toggleOrderedList", isActive: editor.isActive('orderedList'), label: _jsx(GoListOrdered, { size: '24px' }) }), _jsx(EditorButton, { action: "toggleCodeBlock", isActive: editor.isActive('codeBlock'), label: _jsx(PiCodeBlock, { size: '24px' }) }), _jsx(EditorButton, { action: "toggleBlockquote", isActive: editor.isActive('blockquote'), label: _jsx(TbBlockquote, { size: '24px' }) })] }));
|
|
28
|
+
};
|
|
29
|
+
const extensions = [
|
|
30
|
+
StarterKit.configure({
|
|
31
|
+
bulletList: {
|
|
32
|
+
HTMLAttributes: {
|
|
33
|
+
class: 'list-disc list-inside dark:text-white p-1 mt-1 [&_li]:mb-1 [&_p]:inline m-0',
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
orderedList: {
|
|
37
|
+
HTMLAttributes: {
|
|
38
|
+
className: 'list-decimal list-inside dark:text-white p-1 mt-1 [&_li]:mb-1 [&_p]:inline m-0',
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
}),
|
|
42
|
+
Markdown,
|
|
43
|
+
];
|
|
44
|
+
export const MarkdownEditor = (props) => {
|
|
45
|
+
return (_jsx("div", { className: 'text-md border border-gray-800 overflow-hidden ' + props.className, style: { borderWidth: props.editable ? 1 : 0 }, children: _jsx(EditorProvider, { slotBefore: props.editable ? _jsx(MenuBar, {}) : null, extensions: extensions, content: props.content, editable: props.editable, onUpdate: (e) => {
|
|
46
|
+
props.onUpdate && props.onUpdate(e.editor.storage.markdown.getMarkdown());
|
|
47
|
+
} }, (props.editable ? 'editable' : 'readonly') + props.content) }));
|
|
48
|
+
};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
export const Spinner = ({ text, className, size = '30px' }) => {
|
|
3
|
+
return (_jsxs("div", { className: 'flex items-center space-x-2 ' + className, children: [_jsxs("svg", { style: { width: size, height: size }, className: "animate-spin -ml-1 mr-3 h-5 w-5 text-white", xmlns: "http://www.w3.org/2000/svg", fill: "none", viewBox: "0 0 24 24", children: [_jsx("circle", { className: "opacity-25", cx: "12", cy: "12", r: "10", stroke: "currentColor", strokeWidth: "4" }), _jsx("path", { className: "opacity-75", fill: "currentColor", d: "M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z" })] }), text && _jsx("span", { className: "", children: text })] }));
|
|
4
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { FirstMessages } from './utils';
|
|
2
|
+
interface Props {
|
|
3
|
+
voiceId: any;
|
|
4
|
+
avatarImageUrl: string;
|
|
5
|
+
onComplete: (result: any) => void;
|
|
6
|
+
autoStartConversation?: FirstMessages;
|
|
7
|
+
}
|
|
8
|
+
export declare function AssistantChat({ avatarImageUrl, voiceId, onComplete, autoStartConversation }: Props): import("react/jsx-runtime").JSX.Element;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import React, { useEffect, useMemo } from 'react';
|
|
3
|
+
import { CircleAudioAvatar } from './EmbeddedAssistent/CircleAudioAvatar';
|
|
4
|
+
import { AudioInputField } from './EmbeddedAssistent/AudioInputField';
|
|
5
|
+
import { MessageSender } from './EmbeddedAssistent/TTS/MessageSender';
|
|
6
|
+
import Markdown from 'react-markdown';
|
|
7
|
+
import { useChat } from '../../hooks/UseChatHook';
|
|
8
|
+
import { useRimori } from '../../providers/PluginProvider';
|
|
9
|
+
import { getFirstMessages } from './utils';
|
|
10
|
+
export function AssistantChat({ avatarImageUrl, voiceId, onComplete, autoStartConversation }) {
|
|
11
|
+
var _a;
|
|
12
|
+
const [oralCommunication, setOralCommunication] = React.useState(true);
|
|
13
|
+
const { ai: llm, event } = useRimori();
|
|
14
|
+
const sender = useMemo(() => new MessageSender(llm.getVoice, voiceId), []);
|
|
15
|
+
const { messages, append, isLoading, setMessages } = useChat();
|
|
16
|
+
const lastAssistantMessage = (_a = [...messages].filter((m) => m.role === 'assistant').pop()) === null || _a === void 0 ? void 0 : _a.content;
|
|
17
|
+
useEffect(() => {
|
|
18
|
+
sender.setOnLoudnessChange((value) => event.emit('self.avatar.triggerLoudness', { loudness: value }));
|
|
19
|
+
if (!autoStartConversation) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
setMessages(getFirstMessages(autoStartConversation));
|
|
23
|
+
// append([{ role: 'user', content: autoStartConversation.userMessage }]);
|
|
24
|
+
if (autoStartConversation.assistantMessage) {
|
|
25
|
+
// console.log("autostartmessages", { autoStartConversation, isLoading });
|
|
26
|
+
sender.handleNewText(autoStartConversation.assistantMessage, isLoading);
|
|
27
|
+
}
|
|
28
|
+
}, []);
|
|
29
|
+
useEffect(() => {
|
|
30
|
+
var _a;
|
|
31
|
+
let message = lastAssistantMessage;
|
|
32
|
+
if (message !== ((_a = messages[messages.length - 1]) === null || _a === void 0 ? void 0 : _a.content)) {
|
|
33
|
+
message = undefined;
|
|
34
|
+
}
|
|
35
|
+
sender.handleNewText(message, isLoading);
|
|
36
|
+
}, [messages, isLoading]);
|
|
37
|
+
const lastMessage = messages[messages.length - 1];
|
|
38
|
+
useEffect(() => {
|
|
39
|
+
console.log('lastMessage', lastMessage);
|
|
40
|
+
const toolInvocations = lastMessage === null || lastMessage === void 0 ? void 0 : lastMessage.toolCalls;
|
|
41
|
+
if (toolInvocations && toolInvocations.length > 0) {
|
|
42
|
+
console.log('toolInvocations', toolInvocations);
|
|
43
|
+
onComplete(toolInvocations[0].args);
|
|
44
|
+
}
|
|
45
|
+
}, [lastMessage]);
|
|
46
|
+
if ((lastMessage === null || lastMessage === void 0 ? void 0 : lastMessage.toolCalls) && lastMessage.toolCalls.length > 0) {
|
|
47
|
+
console.log('lastMessage test2', lastMessage);
|
|
48
|
+
const args = lastMessage.toolCalls[0].args;
|
|
49
|
+
const success = args.explanationUnderstood === 'TRUE' || args.studentKnowsTopic === 'TRUE';
|
|
50
|
+
return (_jsxs("div", { className: "px-5 pt-5 overflow-y-auto text-center", style: { height: '478px' }, children: [_jsx("h1", { className: "text-center mt-5 mb-5", children: success ? 'Great job!' : 'You failed' }), _jsx("p", { children: args.improvementHints })] }));
|
|
51
|
+
}
|
|
52
|
+
return (_jsxs("div", { children: [oralCommunication && _jsx(CircleAudioAvatar, { imageUrl: avatarImageUrl, className: "mx-auto my-10" }), _jsx("div", { className: "w-full", children: lastAssistantMessage && (_jsx("div", { className: "px-5 pt-5 overflow-y-auto remirror-theme", style: { height: '4k78px' }, children: _jsx(Markdown, { children: lastAssistantMessage }) })) }), _jsx(AudioInputField, { blockSubmission: isLoading, onSubmit: (message) => {
|
|
53
|
+
append([{ role: 'user', content: message, id: messages.length.toString() }]);
|
|
54
|
+
}, onAudioControl: (voice) => {
|
|
55
|
+
setOralCommunication(voice);
|
|
56
|
+
sender.setVolume(voice ? 1 : 0);
|
|
57
|
+
} })] }));
|
|
58
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Tool } from '@rimori/client';
|
|
2
|
+
import { FirstMessages } from './utils';
|
|
3
|
+
interface Props {
|
|
4
|
+
voiceId: string;
|
|
5
|
+
agentTools: Tool[];
|
|
6
|
+
avatarImageUrl: string;
|
|
7
|
+
circleSize?: string;
|
|
8
|
+
isDarkTheme?: boolean;
|
|
9
|
+
children?: React.ReactNode;
|
|
10
|
+
autoStartConversation?: FirstMessages;
|
|
11
|
+
className?: string;
|
|
12
|
+
}
|
|
13
|
+
export declare function Avatar({ avatarImageUrl, voiceId, agentTools, autoStartConversation, children, isDarkTheme, circleSize, className, }: Props): import("react/jsx-runtime").JSX.Element;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useMemo, useState } from 'react';
|
|
3
|
+
import { VoiceRecorder } from './EmbeddedAssistent/VoiceRecoder';
|
|
4
|
+
import { MessageSender } from './EmbeddedAssistent/TTS/MessageSender';
|
|
5
|
+
import { CircleAudioAvatar } from './EmbeddedAssistent/CircleAudioAvatar';
|
|
6
|
+
import { useChat } from '../../hooks/UseChatHook';
|
|
7
|
+
import { useRimori } from '../../providers/PluginProvider';
|
|
8
|
+
import { getFirstMessages } from './utils';
|
|
9
|
+
export function Avatar({ avatarImageUrl, voiceId, agentTools, autoStartConversation, children, isDarkTheme = false, circleSize = '300px', className, }) {
|
|
10
|
+
const { ai, event } = useRimori();
|
|
11
|
+
const [agentReplying, setAgentReplying] = useState(false);
|
|
12
|
+
const [isProcessingMessage, setIsProcessingMessage] = useState(false);
|
|
13
|
+
const sender = useMemo(() => new MessageSender(ai.getVoice, voiceId), [voiceId]);
|
|
14
|
+
const { messages, append, isLoading, lastMessage, setMessages } = useChat(agentTools);
|
|
15
|
+
useEffect(() => {
|
|
16
|
+
console.log('messages', messages);
|
|
17
|
+
}, [messages]);
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
if (!isLoading)
|
|
20
|
+
setIsProcessingMessage(false);
|
|
21
|
+
}, [isLoading]);
|
|
22
|
+
useEffect(() => {
|
|
23
|
+
if (!voiceId)
|
|
24
|
+
return; //at the beginning when being mounted the voiceId is undefined
|
|
25
|
+
sender.setOnLoudnessChange((value) => event.emit('self.avatar.triggerLoudness', { loudness: value }));
|
|
26
|
+
sender.setOnEndOfSpeech(() => setAgentReplying(false));
|
|
27
|
+
if (!autoStartConversation)
|
|
28
|
+
return;
|
|
29
|
+
setMessages(getFirstMessages(autoStartConversation));
|
|
30
|
+
// append([{ role: 'user', content: autoStartConversation.userMessage }]);
|
|
31
|
+
if (autoStartConversation.assistantMessage) {
|
|
32
|
+
// console.log("autostartmessages", { autoStartConversation, isLoading });
|
|
33
|
+
sender.handleNewText(autoStartConversation.assistantMessage, isLoading);
|
|
34
|
+
}
|
|
35
|
+
else if (autoStartConversation.userMessage) {
|
|
36
|
+
append([{ role: 'user', content: autoStartConversation.userMessage, id: messages.length.toString() }]);
|
|
37
|
+
}
|
|
38
|
+
}, [autoStartConversation, voiceId]);
|
|
39
|
+
useEffect(() => {
|
|
40
|
+
if ((lastMessage === null || lastMessage === void 0 ? void 0 : lastMessage.role) === 'assistant') {
|
|
41
|
+
sender.handleNewText(lastMessage.content, isLoading);
|
|
42
|
+
if (lastMessage.toolCalls) {
|
|
43
|
+
// console.log("unlocking mic", lastMessage)
|
|
44
|
+
setAgentReplying(false);
|
|
45
|
+
setIsProcessingMessage(false);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}, [lastMessage, isLoading]);
|
|
49
|
+
return (_jsxs("div", { className: `md:pb-8 ${className || ''}`, children: [_jsx(CircleAudioAvatar, { width: circleSize, className: "mx-auto", imageUrl: avatarImageUrl, isDarkTheme: isDarkTheme }), children, _jsx(VoiceRecorder, { iconSize: "30", className: "w-16 h-16 shadow-lg rounded-full bg-gray-400 dark:bg-gray-800", disabled: agentReplying, loading: isProcessingMessage, enablePushToTalk: true, onVoiceRecorded: (message) => {
|
|
50
|
+
setAgentReplying(true);
|
|
51
|
+
append([
|
|
52
|
+
{
|
|
53
|
+
role: 'user',
|
|
54
|
+
content: 'Message(' + Math.floor((messages.length + 1) / 2) + '): ' + message,
|
|
55
|
+
id: messages.length.toString(),
|
|
56
|
+
},
|
|
57
|
+
]);
|
|
58
|
+
}, onRecordingStatusChange: (running) => !running && setIsProcessingMessage(true) })] }));
|
|
59
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
interface AudioInputFieldProps {
|
|
2
|
+
onSubmit: (text: string) => void;
|
|
3
|
+
onAudioControl?: (voice: boolean) => void;
|
|
4
|
+
blockSubmission?: boolean;
|
|
5
|
+
}
|
|
6
|
+
export declare function AudioInputField({ onSubmit, onAudioControl, blockSubmission }: AudioInputFieldProps): import("react/jsx-runtime").JSX.Element;
|
|
7
|
+
export {};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useState } from 'react';
|
|
3
|
+
import { VoiceRecorder } from './VoiceRecoder';
|
|
4
|
+
import { BiSolidRightArrow } from 'react-icons/bi';
|
|
5
|
+
import { HiMiniSpeakerXMark, HiMiniSpeakerWave } from 'react-icons/hi2';
|
|
6
|
+
export function AudioInputField({ onSubmit, onAudioControl, blockSubmission = false }) {
|
|
7
|
+
const [text, setText] = useState('');
|
|
8
|
+
const [audioEnabled, setAudioEnabled] = useState(true);
|
|
9
|
+
const handleSubmit = (manualText) => {
|
|
10
|
+
if (blockSubmission)
|
|
11
|
+
return;
|
|
12
|
+
const sendableText = manualText || text;
|
|
13
|
+
if (sendableText.trim()) {
|
|
14
|
+
onSubmit(sendableText);
|
|
15
|
+
setTimeout(() => {
|
|
16
|
+
setText('');
|
|
17
|
+
}, 100);
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
const handleKeyDown = (e) => {
|
|
21
|
+
if (blockSubmission)
|
|
22
|
+
return;
|
|
23
|
+
if (e.key === 'Enter' && e.ctrlKey) {
|
|
24
|
+
setText(text + '\n');
|
|
25
|
+
}
|
|
26
|
+
else if (e.key === 'Enter') {
|
|
27
|
+
handleSubmit();
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
return (_jsxs("div", { className: "flex items-center bg-gray-600 pt-2 pb-2 p-2", children: [onAudioControl && (_jsx("button", { onClick: () => {
|
|
31
|
+
onAudioControl(!audioEnabled);
|
|
32
|
+
setAudioEnabled(!audioEnabled);
|
|
33
|
+
}, className: "cursor-default", children: audioEnabled ? (_jsx(HiMiniSpeakerWave, { className: "w-9 h-9 cursor-pointer" })) : (_jsx(HiMiniSpeakerXMark, { className: "w-9 h-9 cursor-pointer" })) })), _jsx(VoiceRecorder, { onRecordingStatusChange: () => { }, onVoiceRecorded: (m) => {
|
|
34
|
+
console.log('onVoiceRecorded', m);
|
|
35
|
+
handleSubmit(m);
|
|
36
|
+
} }), _jsx("textarea", { value: text, onChange: (e) => setText(e.target.value), onKeyDown: handleKeyDown, className: "flex-1 border-none rounded-lg p-2 text-gray-800 focus::outline-none", placeholder: "Type a message...", disabled: blockSubmission }), _jsx("button", { onClick: () => handleSubmit(), className: "cursor-default", disabled: blockSubmission, children: _jsx(BiSolidRightArrow, { className: "w-9 h-10 cursor-pointer" }) })] }));
|
|
37
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
interface CircleAudioAvatarProps {
|
|
2
|
+
width?: string;
|
|
3
|
+
imageUrl: string;
|
|
4
|
+
className?: string;
|
|
5
|
+
isDarkTheme?: boolean;
|
|
6
|
+
}
|
|
7
|
+
export declare function CircleAudioAvatar({ imageUrl, className, isDarkTheme, width, }: CircleAudioAvatarProps): import("react/jsx-runtime").JSX.Element;
|
|
8
|
+
export {};
|