@rimori/react-client 0.1.0 → 0.1.1
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/dist/{react-client/src/components → components}/ContextMenu.js +1 -2
- package/dist/components/ai/Assistant.js +1 -1
- package/dist/components/ai/Avatar.d.ts +1 -1
- package/dist/components/ai/Avatar.js +1 -1
- package/dist/components/ai/EmbeddedAssistent/CircleAudioAvatar.js +1 -1
- package/dist/components/ai/EmbeddedAssistent/VoiceRecoder.js +2 -2
- package/dist/components/audio/Playbutton.js +10 -8
- package/dist/hooks/I18nHooks.d.ts +1 -1
- package/dist/hooks/UseChatHook.d.ts +2 -2
- package/dist/index.d.ts +10 -0
- package/dist/index.js +10 -0
- package/dist/providers/PluginProvider.d.ts +2 -1
- package/dist/providers/PluginProvider.js +9 -8
- package/dist/{react-client/src/utils → utils}/FullscreenUtils.js +2 -2
- package/package.json +1 -1
- package/src/components/ContextMenu.tsx +2 -2
- package/src/index.ts +11 -0
- package/src/plugin/ThemeSetter.ts +1 -1
- package/src/providers/PluginProvider.tsx +10 -9
- package/src/utils/FullscreenUtils.ts +5 -5
- package/tsconfig.json +6 -12
- package/dist/components/components/ContextMenu.d.ts +0 -10
- package/dist/components/components/ContextMenu.js +0 -135
- package/dist/react-client/src/components/MarkdownEditor.d.ts +0 -8
- package/dist/react-client/src/components/MarkdownEditor.js +0 -48
- package/dist/react-client/src/components/Spinner.d.ts +0 -8
- package/dist/react-client/src/components/Spinner.js +0 -4
- package/dist/react-client/src/components/ai/Assistant.d.ts +0 -9
- package/dist/react-client/src/components/ai/Assistant.js +0 -58
- package/dist/react-client/src/components/ai/Avatar.d.ts +0 -14
- package/dist/react-client/src/components/ai/Avatar.js +0 -59
- package/dist/react-client/src/components/ai/EmbeddedAssistent/AudioInputField.d.ts +0 -7
- package/dist/react-client/src/components/ai/EmbeddedAssistent/AudioInputField.js +0 -37
- package/dist/react-client/src/components/ai/EmbeddedAssistent/CircleAudioAvatar.d.ts +0 -8
- package/dist/react-client/src/components/ai/EmbeddedAssistent/CircleAudioAvatar.js +0 -79
- package/dist/react-client/src/components/ai/EmbeddedAssistent/TTS/MessageSender.d.ts +0 -19
- package/dist/react-client/src/components/ai/EmbeddedAssistent/TTS/MessageSender.js +0 -91
- package/dist/react-client/src/components/ai/EmbeddedAssistent/TTS/Player.d.ts +0 -27
- package/dist/react-client/src/components/ai/EmbeddedAssistent/TTS/Player.js +0 -185
- package/dist/react-client/src/components/ai/EmbeddedAssistent/VoiceRecoder.d.ts +0 -11
- package/dist/react-client/src/components/ai/EmbeddedAssistent/VoiceRecoder.js +0 -95
- package/dist/react-client/src/components/ai/utils.d.ts +0 -6
- package/dist/react-client/src/components/ai/utils.js +0 -13
- package/dist/react-client/src/components/audio/Playbutton.d.ts +0 -15
- package/dist/react-client/src/components/audio/Playbutton.js +0 -82
- package/dist/react-client/src/components/components/ContextMenu.d.ts +0 -10
- package/dist/react-client/src/components/components/ContextMenu.js +0 -135
- package/dist/react-client/src/hooks/I18nHooks.d.ts +0 -11
- package/dist/react-client/src/hooks/I18nHooks.js +0 -25
- package/dist/react-client/src/hooks/UseChatHook.d.ts +0 -10
- package/dist/react-client/src/hooks/UseChatHook.js +0 -29
- package/dist/react-client/src/plugin/ThemeSetter.d.ts +0 -2
- package/dist/react-client/src/plugin/ThemeSetter.js +0 -19
- package/dist/react-client/src/providers/PluginProvider.d.ts +0 -12
- package/dist/react-client/src/providers/PluginProvider.js +0 -142
- package/dist/react-client/src/utils/PluginUtils.d.ts +0 -2
- package/dist/react-client/src/utils/PluginUtils.js +0 -23
- package/dist/rimori-client/src/cli/types/DatabaseTypes.d.ts +0 -103
- package/dist/rimori-client/src/cli/types/DatabaseTypes.js +0 -2
- package/dist/rimori-client/src/controller/AIController.d.ts +0 -15
- package/dist/rimori-client/src/controller/AIController.js +0 -255
- package/dist/rimori-client/src/controller/AccomplishmentController.d.ts +0 -38
- package/dist/rimori-client/src/controller/AccomplishmentController.js +0 -112
- package/dist/rimori-client/src/controller/AudioController.d.ts +0 -37
- package/dist/rimori-client/src/controller/AudioController.js +0 -68
- package/dist/rimori-client/src/controller/ExerciseController.d.ts +0 -54
- package/dist/rimori-client/src/controller/ExerciseController.js +0 -74
- package/dist/rimori-client/src/controller/ObjectController.d.ts +0 -42
- package/dist/rimori-client/src/controller/ObjectController.js +0 -76
- package/dist/rimori-client/src/controller/SettingsController.d.ts +0 -79
- package/dist/rimori-client/src/controller/SettingsController.js +0 -118
- package/dist/rimori-client/src/controller/SharedContentController.d.ts +0 -106
- package/dist/rimori-client/src/controller/SharedContentController.js +0 -285
- package/dist/rimori-client/src/controller/TranslationController.d.ts +0 -38
- package/dist/rimori-client/src/controller/TranslationController.js +0 -106
- package/dist/rimori-client/src/controller/VoiceController.d.ts +0 -9
- package/dist/rimori-client/src/controller/VoiceController.js +0 -37
- package/dist/rimori-client/src/fromRimori/EventBus.d.ts +0 -101
- package/dist/rimori-client/src/fromRimori/EventBus.js +0 -263
- package/dist/rimori-client/src/fromRimori/PluginTypes.d.ts +0 -174
- package/dist/rimori-client/src/fromRimori/PluginTypes.js +0 -1
- package/dist/rimori-client/src/index.d.ts +0 -11
- package/dist/rimori-client/src/index.js +0 -10
- package/dist/rimori-client/src/plugin/CommunicationHandler.d.ts +0 -48
- package/dist/rimori-client/src/plugin/CommunicationHandler.js +0 -234
- package/dist/rimori-client/src/plugin/Logger.d.ts +0 -73
- package/dist/rimori-client/src/plugin/Logger.js +0 -308
- package/dist/rimori-client/src/plugin/RimoriClient.d.ts +0 -258
- package/dist/rimori-client/src/plugin/RimoriClient.js +0 -375
- package/dist/rimori-client/src/plugin/StandaloneClient.d.ts +0 -17
- package/dist/rimori-client/src/plugin/StandaloneClient.js +0 -115
- package/dist/rimori-client/src/utils/difficultyConverter.d.ts +0 -4
- package/dist/rimori-client/src/utils/difficultyConverter.js +0 -10
- package/dist/rimori-client/src/utils/endpoint.d.ts +0 -2
- package/dist/rimori-client/src/utils/endpoint.js +0 -2
- package/dist/utils/PluginUtils.d.ts +0 -2
- package/dist/utils/PluginUtils.js +0 -23
- package/index.ts +0 -6
- /package/dist/{react-client/src/components → components}/ContextMenu.d.ts +0 -0
- /package/dist/{react-client/plugin → plugin}/ThemeSetter.d.ts +0 -0
- /package/dist/{react-client/plugin → plugin}/ThemeSetter.js +0 -0
- /package/dist/{react-client/src/utils → utils}/FullscreenUtils.d.ts +0 -0
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useState, useEffect, useRef } from 'react';
|
|
3
|
-
import { EventBus } from '@rimori/client';
|
|
4
3
|
const ContextMenu = ({ client }) => {
|
|
5
4
|
const [isOpen, setIsOpen] = useState(false);
|
|
6
5
|
const [actions, setActions] = useState([]);
|
|
@@ -36,7 +35,7 @@ const ContextMenu = ({ client }) => {
|
|
|
36
35
|
.filter(Boolean);
|
|
37
36
|
setActions(actions);
|
|
38
37
|
setOpenOnTextSelect(client.plugin.getUserInfo().context_menu_on_select);
|
|
39
|
-
|
|
38
|
+
client.event.on('global.contextMenu.createActions', ({ data }) => {
|
|
40
39
|
setActions([...data.actions, ...actions]);
|
|
41
40
|
});
|
|
42
41
|
}, []);
|
|
@@ -5,7 +5,7 @@ import { AudioInputField } from './EmbeddedAssistent/AudioInputField';
|
|
|
5
5
|
import { MessageSender } from './EmbeddedAssistent/TTS/MessageSender';
|
|
6
6
|
import Markdown from 'react-markdown';
|
|
7
7
|
import { useChat } from '../../hooks/UseChatHook';
|
|
8
|
-
import { useRimori } from '../../
|
|
8
|
+
import { useRimori } from '../../providers/PluginProvider';
|
|
9
9
|
import { getFirstMessages } from './utils';
|
|
10
10
|
export function AssistantChat({ avatarImageUrl, voiceId, onComplete, autoStartConversation }) {
|
|
11
11
|
var _a;
|
|
@@ -4,7 +4,7 @@ import { VoiceRecorder } from './EmbeddedAssistent/VoiceRecoder';
|
|
|
4
4
|
import { MessageSender } from './EmbeddedAssistent/TTS/MessageSender';
|
|
5
5
|
import { CircleAudioAvatar } from './EmbeddedAssistent/CircleAudioAvatar';
|
|
6
6
|
import { useChat } from '../../hooks/UseChatHook';
|
|
7
|
-
import { useRimori } from '../../
|
|
7
|
+
import { useRimori } from '../../providers/PluginProvider';
|
|
8
8
|
import { getFirstMessages } from './utils';
|
|
9
9
|
export function Avatar({ avatarImageUrl, voiceId, agentTools, autoStartConversation, children, isDarkTheme = false, circleSize = '300px', className, }) {
|
|
10
10
|
const { ai, event } = useRimori();
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { useEffect, useRef } from 'react';
|
|
3
|
-
import { EventBus } from '
|
|
3
|
+
import { EventBus } from '@rimori/client';
|
|
4
4
|
export function CircleAudioAvatar({ imageUrl, className, isDarkTheme = false, width = '150px', }) {
|
|
5
5
|
const canvasRef = useRef(null);
|
|
6
6
|
const currentLoudnessRef = useRef(0);
|
|
@@ -8,9 +8,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
11
|
-
import { useRimori } from '../../../
|
|
11
|
+
import { useRimori } from '../../../providers/PluginProvider';
|
|
12
12
|
import { FaMicrophone, FaSpinner } from 'react-icons/fa6';
|
|
13
|
-
import { AudioController } from '
|
|
13
|
+
import { AudioController } from '@rimori/client';
|
|
14
14
|
import { useState, useRef, forwardRef, useImperativeHandle, useEffect } from 'react';
|
|
15
15
|
export const VoiceRecorder = forwardRef(({ onVoiceRecorded, iconSize, className, disabled, loading, onRecordingStatusChange, enablePushToTalk = false, }, ref) => {
|
|
16
16
|
const [isRecording, setIsRecording] = useState(false);
|
|
@@ -12,7 +12,7 @@ import { useState, useEffect } from 'react';
|
|
|
12
12
|
import { FaPlayCircle, FaStopCircle } from 'react-icons/fa';
|
|
13
13
|
import { useRimori } from '../../providers/PluginProvider';
|
|
14
14
|
import { Spinner } from '../Spinner';
|
|
15
|
-
import { EventBus } from '
|
|
15
|
+
import { EventBus } from '@rimori/client';
|
|
16
16
|
export const AudioPlayOptions = [0.8, 0.9, 1.0, 1.1, 1.2, 1.5];
|
|
17
17
|
let isFetchingAudio = false;
|
|
18
18
|
export const AudioPlayer = ({ text, voice, language, hide, playListenerEvent, initialSpeed = 1.0, playOnMount = false, enableSpeedAdjustment = false, }) => {
|
|
@@ -22,14 +22,11 @@ export const AudioPlayer = ({ text, voice, language, hide, playListenerEvent, in
|
|
|
22
22
|
const [isLoading, setIsLoading] = useState(false);
|
|
23
23
|
const { ai } = useRimori();
|
|
24
24
|
useEffect(() => {
|
|
25
|
-
if (
|
|
26
|
-
|
|
27
|
-
EventBus.on(playListenerEvent, () => togglePlayback());
|
|
28
|
-
}, [playListenerEvent]);
|
|
29
|
-
useEffect(() => {
|
|
30
|
-
audioUrl && setAudioUrl(null);
|
|
25
|
+
if (audioUrl)
|
|
26
|
+
setAudioUrl(null);
|
|
31
27
|
return () => {
|
|
32
|
-
|
|
28
|
+
if (audioUrl)
|
|
29
|
+
URL.revokeObjectURL(audioUrl);
|
|
33
30
|
};
|
|
34
31
|
}, [text]);
|
|
35
32
|
// Function to generate audio from text using API
|
|
@@ -69,6 +66,11 @@ export const AudioPlayer = ({ text, voice, language, hide, playListenerEvent, in
|
|
|
69
66
|
setIsPlaying((prev) => !prev);
|
|
70
67
|
}
|
|
71
68
|
};
|
|
69
|
+
useEffect(() => {
|
|
70
|
+
if (!playListenerEvent)
|
|
71
|
+
return;
|
|
72
|
+
EventBus.on(playListenerEvent, () => togglePlayback());
|
|
73
|
+
}, [playListenerEvent]);
|
|
72
74
|
useEffect(() => {
|
|
73
75
|
if (!playOnMount || isFetchingAudio)
|
|
74
76
|
return;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { Tool } from '
|
|
3
|
-
import { Message } from '
|
|
2
|
+
import { Tool } from '@rimori/client';
|
|
3
|
+
import { Message } from '@rimori/client';
|
|
4
4
|
export declare function useChat(tools?: Tool[]): {
|
|
5
5
|
messages: Message[];
|
|
6
6
|
append: (appendMessages: Message[]) => void;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export * from './hooks/UseChatHook';
|
|
2
|
+
export * from './providers/PluginProvider';
|
|
3
|
+
export * from './utils/FullscreenUtils';
|
|
4
|
+
export * from './components/audio/Playbutton';
|
|
5
|
+
export * from './components/ai/EmbeddedAssistent/TTS/Player';
|
|
6
|
+
export * from './components/ContextMenu';
|
|
7
|
+
export * from './components/MarkdownEditor';
|
|
8
|
+
export * from './components/Spinner';
|
|
9
|
+
export { FirstMessages } from './components/ai/utils';
|
|
10
|
+
export { useTranslation } from './hooks/I18nHooks';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// Re-export everything
|
|
2
|
+
export * from './hooks/UseChatHook';
|
|
3
|
+
export * from './providers/PluginProvider';
|
|
4
|
+
export * from './utils/FullscreenUtils';
|
|
5
|
+
export * from './components/audio/Playbutton';
|
|
6
|
+
export * from './components/ai/EmbeddedAssistent/TTS/Player';
|
|
7
|
+
export * from './components/ContextMenu';
|
|
8
|
+
export * from './components/MarkdownEditor';
|
|
9
|
+
export * from './components/Spinner';
|
|
10
|
+
export { useTranslation } from './hooks/I18nHooks';
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import React, { ReactNode } from 'react';
|
|
2
|
+
import { RimoriClient } from '@rimori/client';
|
|
2
3
|
interface PluginProviderProps {
|
|
3
4
|
children: ReactNode;
|
|
4
5
|
pluginId: string;
|
|
@@ -7,5 +8,5 @@ interface PluginProviderProps {
|
|
|
7
8
|
};
|
|
8
9
|
}
|
|
9
10
|
export declare const PluginProvider: React.FC<PluginProviderProps>;
|
|
10
|
-
export declare const useRimori: () =>
|
|
11
|
+
export declare const useRimori: () => RimoriClient;
|
|
11
12
|
export {};
|
|
@@ -9,14 +9,14 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
11
11
|
import { createContext, useContext, useEffect, useState } from 'react';
|
|
12
|
-
import { RimoriClient, StandaloneClient } from '@rimori/client';
|
|
13
|
-
import ContextMenu from '../components/
|
|
12
|
+
import { EventBusHandler, RimoriClient, StandaloneClient } from '@rimori/client';
|
|
13
|
+
import ContextMenu from '../components/ContextMenu';
|
|
14
|
+
import { setTheme } from '../plugin/ThemeSetter';
|
|
14
15
|
const PluginContext = createContext(null);
|
|
15
16
|
export const PluginProvider = ({ children, pluginId, settings }) => {
|
|
16
17
|
const [plugin, setPlugin] = useState(null);
|
|
17
18
|
const [standaloneClient, setStandaloneClient] = useState(false);
|
|
18
19
|
const [applicationMode, setApplicationMode] = useState(null);
|
|
19
|
-
const [theme, setTheme] = useState(null);
|
|
20
20
|
const isSidebar = applicationMode === 'sidebar';
|
|
21
21
|
const isSettings = applicationMode === 'settings';
|
|
22
22
|
useEffect(() => {
|
|
@@ -24,12 +24,12 @@ export const PluginProvider = ({ children, pluginId, settings }) => {
|
|
|
24
24
|
// Check if we're in an iframe context - if not, we're standalone
|
|
25
25
|
const standaloneDetected = window === window.parent;
|
|
26
26
|
if (standaloneDetected && !standaloneClient) {
|
|
27
|
-
StandaloneClient.getInstance().then((client) => {
|
|
28
|
-
client.needsLogin().then((needLogin) => setStandaloneClient(needLogin ? client : true));
|
|
27
|
+
void StandaloneClient.getInstance().then((client) => {
|
|
28
|
+
void client.needsLogin().then((needLogin) => setStandaloneClient(needLogin ? client : true));
|
|
29
29
|
});
|
|
30
30
|
}
|
|
31
31
|
if ((!standaloneDetected && !plugin) || (standaloneDetected && standaloneClient === true)) {
|
|
32
|
-
RimoriClient.getInstance(pluginId
|
|
32
|
+
void RimoriClient.getInstance(pluginId).then((client) => {
|
|
33
33
|
setPlugin(client);
|
|
34
34
|
// Get applicationMode and theme from MessageChannel query params
|
|
35
35
|
if (!standaloneDetected) {
|
|
@@ -37,10 +37,11 @@ export const PluginProvider = ({ children, pluginId, settings }) => {
|
|
|
37
37
|
const themeParam = client.getQueryParam('rm_theme');
|
|
38
38
|
setApplicationMode(mode);
|
|
39
39
|
setTheme(themeParam);
|
|
40
|
+
client.event.emit('self.rimori.triggerInitFinished');
|
|
40
41
|
}
|
|
41
42
|
});
|
|
42
43
|
}
|
|
43
|
-
}, [pluginId, standaloneClient]);
|
|
44
|
+
}, [pluginId, standaloneClient, plugin]);
|
|
44
45
|
//route change
|
|
45
46
|
useEffect(() => {
|
|
46
47
|
if (!plugin)
|
|
@@ -59,7 +60,7 @@ export const PluginProvider = ({ children, pluginId, settings }) => {
|
|
|
59
60
|
}, 1000);
|
|
60
61
|
emitUrlChange(lastHash);
|
|
61
62
|
return () => clearInterval(interval);
|
|
62
|
-
}, [plugin]);
|
|
63
|
+
}, [plugin, isSidebar]);
|
|
63
64
|
if (standaloneClient instanceof StandaloneClient) {
|
|
64
65
|
return (_jsx(StandaloneAuth, { onLogin: (email, password) => __awaiter(void 0, void 0, void 0, function* () {
|
|
65
66
|
if (yield standaloneClient.login(email, password))
|
|
@@ -9,11 +9,11 @@ export function triggerFullscreen(onStateChange, selector) {
|
|
|
9
9
|
const ref = document.querySelector(selector || '#root');
|
|
10
10
|
if (!isFullscreen()) {
|
|
11
11
|
// @ts-ignore
|
|
12
|
-
ref.requestFullscreen() || ref.webkitRequestFullscreen();
|
|
12
|
+
void (ref.requestFullscreen() || ref.webkitRequestFullscreen());
|
|
13
13
|
}
|
|
14
14
|
else {
|
|
15
15
|
// @ts-ignore
|
|
16
|
-
document.exitFullscreen() || document.webkitExitFullscreen();
|
|
16
|
+
void (document.exitFullscreen() || document.webkitExitFullscreen());
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
19
|
catch (error) {
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React, { useState, useEffect, useRef } from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { RimoriClient, MenuEntry } from '@rimori/client';
|
|
3
3
|
|
|
4
4
|
export interface Position {
|
|
5
5
|
x: number;
|
|
@@ -49,7 +49,7 @@ const ContextMenu = ({ client }: { client: RimoriClient }) => {
|
|
|
49
49
|
setActions(actions);
|
|
50
50
|
setOpenOnTextSelect(client.plugin.getUserInfo().context_menu_on_select);
|
|
51
51
|
|
|
52
|
-
|
|
52
|
+
client.event.on<{ actions: MenuEntry[] }>('global.contextMenu.createActions', ({ data }) => {
|
|
53
53
|
setActions([...data.actions, ...actions]);
|
|
54
54
|
});
|
|
55
55
|
}, []);
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// Re-export everything
|
|
2
|
+
export * from './hooks/UseChatHook';
|
|
3
|
+
export * from './providers/PluginProvider';
|
|
4
|
+
export * from './utils/FullscreenUtils';
|
|
5
|
+
export * from './components/audio/Playbutton';
|
|
6
|
+
export * from './components/ai/EmbeddedAssistent/TTS/Player';
|
|
7
|
+
export * from './components/ContextMenu';
|
|
8
|
+
export * from './components/MarkdownEditor';
|
|
9
|
+
export * from './components/Spinner';
|
|
10
|
+
export { FirstMessages } from './components/ai/utils';
|
|
11
|
+
export { useTranslation } from './hooks/I18nHooks';
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import React, { createContext, useContext, ReactNode, useEffect, useState } from 'react';
|
|
2
2
|
import { EventBusHandler, RimoriClient, StandaloneClient } from '@rimori/client';
|
|
3
3
|
import ContextMenu from '../components/ContextMenu';
|
|
4
|
+
import { setTheme } from '../plugin/ThemeSetter';
|
|
4
5
|
|
|
5
6
|
interface PluginProviderProps {
|
|
6
7
|
children: ReactNode;
|
|
@@ -16,7 +17,6 @@ export const PluginProvider: React.FC<PluginProviderProps> = ({ children, plugin
|
|
|
16
17
|
const [plugin, setPlugin] = useState<RimoriClient | null>(null);
|
|
17
18
|
const [standaloneClient, setStandaloneClient] = useState<StandaloneClient | boolean>(false);
|
|
18
19
|
const [applicationMode, setApplicationMode] = useState<string | null>(null);
|
|
19
|
-
const [theme, setTheme] = useState<string | null>(null);
|
|
20
20
|
|
|
21
21
|
const isSidebar = applicationMode === 'sidebar';
|
|
22
22
|
const isSettings = applicationMode === 'settings';
|
|
@@ -28,13 +28,13 @@ export const PluginProvider: React.FC<PluginProviderProps> = ({ children, plugin
|
|
|
28
28
|
const standaloneDetected = window === window.parent;
|
|
29
29
|
|
|
30
30
|
if (standaloneDetected && !standaloneClient) {
|
|
31
|
-
StandaloneClient.getInstance().then((client) => {
|
|
32
|
-
client.needsLogin().then((needLogin) => setStandaloneClient(needLogin ? client : true));
|
|
31
|
+
void StandaloneClient.getInstance().then((client) => {
|
|
32
|
+
void client.needsLogin().then((needLogin) => setStandaloneClient(needLogin ? client : true));
|
|
33
33
|
});
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
if ((!standaloneDetected && !plugin) || (standaloneDetected && standaloneClient === true)) {
|
|
37
|
-
RimoriClient.getInstance(pluginId).then((client) => {
|
|
37
|
+
void RimoriClient.getInstance(pluginId).then((client) => {
|
|
38
38
|
setPlugin(client);
|
|
39
39
|
// Get applicationMode and theme from MessageChannel query params
|
|
40
40
|
if (!standaloneDetected) {
|
|
@@ -42,10 +42,11 @@ export const PluginProvider: React.FC<PluginProviderProps> = ({ children, plugin
|
|
|
42
42
|
const themeParam = client.getQueryParam('rm_theme');
|
|
43
43
|
setApplicationMode(mode);
|
|
44
44
|
setTheme(themeParam);
|
|
45
|
+
client.event.emit('self.rimori.triggerInitFinished');
|
|
45
46
|
}
|
|
46
47
|
});
|
|
47
48
|
}
|
|
48
|
-
}, [pluginId, standaloneClient]);
|
|
49
|
+
}, [pluginId, standaloneClient, plugin]);
|
|
49
50
|
|
|
50
51
|
//route change
|
|
51
52
|
useEffect(() => {
|
|
@@ -66,7 +67,7 @@ export const PluginProvider: React.FC<PluginProviderProps> = ({ children, plugin
|
|
|
66
67
|
|
|
67
68
|
emitUrlChange(lastHash);
|
|
68
69
|
return () => clearInterval(interval);
|
|
69
|
-
}, [plugin]);
|
|
70
|
+
}, [plugin, isSidebar]);
|
|
70
71
|
|
|
71
72
|
if (standaloneClient instanceof StandaloneClient) {
|
|
72
73
|
return (
|
|
@@ -98,7 +99,7 @@ export const useRimori = () => {
|
|
|
98
99
|
return context;
|
|
99
100
|
};
|
|
100
101
|
|
|
101
|
-
function getUrlParam(name: string) {
|
|
102
|
+
function getUrlParam(name: string): string | null {
|
|
102
103
|
// First try to get from URL hash query params (for compatibility)
|
|
103
104
|
const hashParts = window.location.hash.split('?');
|
|
104
105
|
if (hashParts.length > 1) {
|
|
@@ -112,13 +113,13 @@ function getUrlParam(name: string) {
|
|
|
112
113
|
return url.searchParams.get(name);
|
|
113
114
|
}
|
|
114
115
|
|
|
115
|
-
function initEventBus(pluginId: string) {
|
|
116
|
+
function initEventBus(pluginId: string): void {
|
|
116
117
|
// For now, use URL fallback for EventBus naming - this will be updated once MessageChannel is ready
|
|
117
118
|
const isSidebar = getUrlParam('applicationMode') === 'sidebar';
|
|
118
119
|
EventBusHandler.getInstance('Plugin EventBus ' + pluginId + ' ' + (isSidebar ? 'sidebar' : 'main'));
|
|
119
120
|
}
|
|
120
121
|
|
|
121
|
-
function StandaloneAuth({ onLogin }: { onLogin: (user: string, password: string) => void }) {
|
|
122
|
+
function StandaloneAuth({ onLogin }: { onLogin: (user: string, password: string) => void }): JSX.Element {
|
|
122
123
|
const [user, setUser] = useState('');
|
|
123
124
|
const [password, setPassword] = useState('');
|
|
124
125
|
return (
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
export function isFullscreen() {
|
|
1
|
+
export function isFullscreen(): boolean {
|
|
2
2
|
return !!document.fullscreenElement;
|
|
3
3
|
}
|
|
4
4
|
|
|
5
|
-
export function triggerFullscreen(onStateChange: (isFullscreen: boolean) => void, selector?: string) {
|
|
5
|
+
export function triggerFullscreen(onStateChange: (isFullscreen: boolean) => void, selector?: string): void {
|
|
6
6
|
document.addEventListener('fullscreenchange', () => {
|
|
7
7
|
onStateChange(isFullscreen());
|
|
8
8
|
});
|
|
9
9
|
try {
|
|
10
|
-
const ref = document.querySelector(selector || '#root')
|
|
10
|
+
const ref = document.querySelector(selector || '#root') as HTMLElement;
|
|
11
11
|
if (!isFullscreen()) {
|
|
12
12
|
// @ts-ignore
|
|
13
|
-
ref.requestFullscreen() || ref.webkitRequestFullscreen();
|
|
13
|
+
void (ref.requestFullscreen() || ref.webkitRequestFullscreen());
|
|
14
14
|
} else {
|
|
15
15
|
// @ts-ignore
|
|
16
|
-
document.exitFullscreen() || document.webkitExitFullscreen();
|
|
16
|
+
void (document.exitFullscreen() || document.webkitExitFullscreen());
|
|
17
17
|
}
|
|
18
18
|
} catch (error: any) {
|
|
19
19
|
console.error('Failed to enter fullscreen', error.message);
|
package/tsconfig.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"compilerOptions": {
|
|
3
3
|
"outDir": "dist",
|
|
4
|
+
"rootDir": "src",
|
|
4
5
|
"module": "ESNext",
|
|
5
6
|
"target": "ES6",
|
|
6
7
|
"declaration": true,
|
|
@@ -8,16 +9,9 @@
|
|
|
8
9
|
"moduleResolution": "node",
|
|
9
10
|
"esModuleInterop": true,
|
|
10
11
|
"skipLibCheck": true,
|
|
11
|
-
"strict": true
|
|
12
|
-
"baseUrl": ".",
|
|
13
|
-
"paths": {
|
|
14
|
-
"@rimori/client": [
|
|
15
|
-
"../rimori-client/src/index.ts"
|
|
16
|
-
],
|
|
17
|
-
"@rimori/client/*": [
|
|
18
|
-
"../rimori-client/src/*"
|
|
19
|
-
]
|
|
20
|
-
}
|
|
12
|
+
"strict": true
|
|
21
13
|
},
|
|
22
|
-
"include": [
|
|
23
|
-
|
|
14
|
+
"include": [
|
|
15
|
+
"src/**/*"
|
|
16
|
+
]
|
|
17
|
+
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { RimoriClient } from '../../plugin/RimoriClient';
|
|
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;
|
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { useState, useEffect, useRef } from 'react';
|
|
3
|
-
import { EventBus } from '../../fromRimori/EventBus';
|
|
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;
|
|
@@ -1,48 +0,0 @@
|
|
|
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
|
-
};
|
|
@@ -1,4 +0,0 @@
|
|
|
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
|
-
};
|