@rimori/client 1.4.10 → 2.0.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.
Files changed (185) hide show
  1. package/README.md +0 -49
  2. package/dist/react-client/src/plugin/ThemeSetter.d.ts +2 -0
  3. package/dist/react-client/src/plugin/ThemeSetter.js +19 -0
  4. package/dist/react-client/src/utils/PluginUtils.d.ts +2 -0
  5. package/dist/react-client/src/utils/PluginUtils.js +23 -0
  6. package/dist/{cli → rimori-client/src/cli}/scripts/init/main.js +0 -0
  7. package/dist/{cli → rimori-client/src/cli}/scripts/release/release.js +0 -0
  8. package/dist/{core → rimori-client/src}/controller/AIController.d.ts +1 -1
  9. package/dist/{core → rimori-client/src}/controller/AIController.js +2 -2
  10. package/dist/{plugin/AccomplishmentHandler.d.ts → rimori-client/src/controller/AccomplishmentController.d.ts} +1 -1
  11. package/dist/{plugin/AccomplishmentHandler.js → rimori-client/src/controller/AccomplishmentController.js} +1 -1
  12. package/dist/{core → rimori-client/src}/controller/ExerciseController.d.ts +8 -6
  13. package/dist/{core → rimori-client/src}/controller/ExerciseController.js +10 -9
  14. package/dist/{core → rimori-client/src}/controller/ObjectController.d.ts +1 -1
  15. package/dist/{core → rimori-client/src}/controller/ObjectController.js +1 -1
  16. package/dist/{core → rimori-client/src}/controller/SettingsController.d.ts +2 -2
  17. package/dist/{core → rimori-client/src}/controller/SharedContentController.d.ts +1 -1
  18. package/dist/{core → rimori-client/src}/controller/VoiceController.d.ts +1 -1
  19. package/dist/rimori-client/src/index.d.ts +11 -0
  20. package/dist/rimori-client/src/index.js +10 -0
  21. package/dist/{plugin/PluginController.d.ts → rimori-client/src/plugin/CommunicationHandler.d.ts} +3 -7
  22. package/dist/{plugin/PluginController.js → rimori-client/src/plugin/CommunicationHandler.js} +3 -28
  23. package/dist/{plugin → rimori-client/src/plugin}/RimoriClient.d.ts +67 -68
  24. package/dist/{plugin → rimori-client/src/plugin}/RimoriClient.js +101 -43
  25. package/dist/{worker → rimori-client/src/worker}/WorkerSetup.js +2 -2
  26. package/example/docs/devdocs.md +1 -1
  27. package/package.json +4 -26
  28. package/src/{core/controller → controller}/AIController.ts +3 -3
  29. package/src/{plugin/AccomplishmentHandler.ts → controller/AccomplishmentController.ts} +1 -1
  30. package/src/{core/controller → controller}/ExerciseController.ts +14 -11
  31. package/src/{core/controller → controller}/ObjectController.ts +2 -2
  32. package/src/{core/controller → controller}/SettingsController.ts +2 -2
  33. package/src/{core/controller → controller}/SharedContentController.ts +1 -1
  34. package/src/{core/controller → controller}/VoiceController.ts +2 -2
  35. package/src/fromRimori/readme.md +1 -1
  36. package/src/index.ts +8 -8
  37. package/src/plugin/{PluginController.ts → CommunicationHandler.ts} +8 -36
  38. package/src/plugin/RimoriClient.ts +125 -118
  39. package/src/worker/WorkerSetup.ts +5 -3
  40. package/tsconfig.json +4 -2
  41. package/dist/cli/scripts/release/release-translation-upload.d.ts +0 -6
  42. package/dist/cli/scripts/release/release-translation-upload.js +0 -87
  43. package/dist/components/CRUDModal.d.ts +0 -17
  44. package/dist/components/CRUDModal.js +0 -24
  45. package/dist/components/MarkdownEditor.d.ts +0 -8
  46. package/dist/components/MarkdownEditor.js +0 -48
  47. package/dist/components/Spinner.d.ts +0 -8
  48. package/dist/components/Spinner.js +0 -4
  49. package/dist/components/ai/Assistant.d.ts +0 -9
  50. package/dist/components/ai/Assistant.js +0 -58
  51. package/dist/components/ai/Avatar.d.ts +0 -14
  52. package/dist/components/ai/Avatar.js +0 -59
  53. package/dist/components/ai/EmbeddedAssistent/AudioInputField.d.ts +0 -7
  54. package/dist/components/ai/EmbeddedAssistent/AudioInputField.js +0 -37
  55. package/dist/components/ai/EmbeddedAssistent/CircleAudioAvatar.d.ts +0 -8
  56. package/dist/components/ai/EmbeddedAssistent/CircleAudioAvatar.js +0 -79
  57. package/dist/components/ai/EmbeddedAssistent/TTS/MessageSender.d.ts +0 -19
  58. package/dist/components/ai/EmbeddedAssistent/TTS/MessageSender.js +0 -91
  59. package/dist/components/ai/EmbeddedAssistent/TTS/Player.d.ts +0 -27
  60. package/dist/components/ai/EmbeddedAssistent/TTS/Player.js +0 -185
  61. package/dist/components/ai/EmbeddedAssistent/VoiceRecoder.d.ts +0 -11
  62. package/dist/components/ai/EmbeddedAssistent/VoiceRecoder.js +0 -95
  63. package/dist/components/ai/utils.d.ts +0 -6
  64. package/dist/components/ai/utils.js +0 -13
  65. package/dist/components/audio/Playbutton.d.ts +0 -15
  66. package/dist/components/audio/Playbutton.js +0 -80
  67. package/dist/components/components/ContextMenu.d.ts +0 -10
  68. package/dist/components/components/ContextMenu.js +0 -135
  69. package/dist/components.d.ts +0 -10
  70. package/dist/components.js +0 -11
  71. package/dist/core/controller/EnhancedUserInfo.d.ts +0 -0
  72. package/dist/core/controller/EnhancedUserInfo.js +0 -1
  73. package/dist/core/core.d.ts +0 -14
  74. package/dist/core/core.js +0 -7
  75. package/dist/hooks/I18nHooks.d.ts +0 -11
  76. package/dist/hooks/I18nHooks.js +0 -25
  77. package/dist/hooks/UseChatHook.d.ts +0 -10
  78. package/dist/hooks/UseChatHook.js +0 -29
  79. package/dist/i18n/I18nHooks.d.ts +0 -11
  80. package/dist/i18n/I18nHooks.js +0 -25
  81. package/dist/i18n/Translator.d.ts +0 -43
  82. package/dist/i18n/Translator.js +0 -118
  83. package/dist/i18n/config.d.ts +0 -7
  84. package/dist/i18n/config.js +0 -20
  85. package/dist/i18n/createI18nInstance.d.ts +0 -7
  86. package/dist/i18n/createI18nInstance.js +0 -31
  87. package/dist/i18n/hooks.d.ts +0 -11
  88. package/dist/i18n/hooks.js +0 -25
  89. package/dist/i18n/index.d.ts +0 -4
  90. package/dist/i18n/index.js +0 -4
  91. package/dist/i18n/types.d.ts +0 -7
  92. package/dist/i18n/types.js +0 -1
  93. package/dist/i18n/useRimoriI18n.d.ts +0 -11
  94. package/dist/i18n/useRimoriI18n.js +0 -41
  95. package/dist/index.d.ts +0 -11
  96. package/dist/index.js +0 -11
  97. package/dist/plugin/Translator.d.ts +0 -38
  98. package/dist/plugin/Translator.js +0 -101
  99. package/dist/providers/PluginProvider.d.ts +0 -12
  100. package/dist/providers/PluginProvider.js +0 -152
  101. package/dist/style.css +0 -110
  102. package/dist/style.css.map +0 -1
  103. package/dist/utils/Language.d.ts +0 -67
  104. package/dist/utils/Language.js +0 -69
  105. package/dist/utils/LanguageClass.d.ts +0 -36
  106. package/dist/utils/LanguageClass.example.d.ts +0 -0
  107. package/dist/utils/LanguageClass.example.js +0 -1
  108. package/dist/utils/LanguageClass.js +0 -50
  109. package/dist/utils/LanguageClass.test.d.ts +0 -0
  110. package/dist/utils/LanguageClass.test.js +0 -1
  111. package/src/components/CRUDModal.tsx +0 -75
  112. package/src/components/MarkdownEditor.tsx +0 -144
  113. package/src/components/Spinner.tsx +0 -29
  114. package/src/components/ai/Assistant.tsx +0 -96
  115. package/src/components/ai/Avatar.tsx +0 -99
  116. package/src/components/ai/EmbeddedAssistent/AudioInputField.tsx +0 -73
  117. package/src/components/ai/EmbeddedAssistent/CircleAudioAvatar.tsx +0 -107
  118. package/src/components/ai/EmbeddedAssistent/TTS/MessageSender.ts +0 -96
  119. package/src/components/ai/EmbeddedAssistent/TTS/Player.ts +0 -197
  120. package/src/components/ai/EmbeddedAssistent/VoiceRecoder.tsx +0 -129
  121. package/src/components/ai/utils.ts +0 -21
  122. package/src/components/audio/Playbutton.tsx +0 -126
  123. package/src/components/components/ContextMenu.tsx +0 -179
  124. package/src/components.ts +0 -11
  125. package/src/core/core.ts +0 -15
  126. package/src/hooks/I18nHooks.ts +0 -33
  127. package/src/hooks/UseChatHook.ts +0 -38
  128. package/src/plugin/ThemeSetter.ts +0 -23
  129. package/src/providers/PluginProvider.tsx +0 -209
  130. package/src/style.scss +0 -136
  131. package/src/utils/PluginUtils.ts +0 -22
  132. /package/dist/{plugin → react-client/plugin}/ThemeSetter.d.ts +0 -0
  133. /package/dist/{plugin → react-client/plugin}/ThemeSetter.js +0 -0
  134. /package/dist/{utils/PluginUtils.d.ts → react-client/src/utils/FullscreenUtils.d.ts} +0 -0
  135. /package/dist/{utils/PluginUtils.js → react-client/src/utils/FullscreenUtils.js} +0 -0
  136. /package/dist/{cli → rimori-client/src/cli}/scripts/init/dev-registration.d.ts +0 -0
  137. /package/dist/{cli → rimori-client/src/cli}/scripts/init/dev-registration.js +0 -0
  138. /package/dist/{cli → rimori-client/src/cli}/scripts/init/env-setup.d.ts +0 -0
  139. /package/dist/{cli → rimori-client/src/cli}/scripts/init/env-setup.js +0 -0
  140. /package/dist/{cli → rimori-client/src/cli}/scripts/init/file-operations.d.ts +0 -0
  141. /package/dist/{cli → rimori-client/src/cli}/scripts/init/file-operations.js +0 -0
  142. /package/dist/{cli → rimori-client/src/cli}/scripts/init/html-cleaner.d.ts +0 -0
  143. /package/dist/{cli → rimori-client/src/cli}/scripts/init/html-cleaner.js +0 -0
  144. /package/dist/{cli → rimori-client/src/cli}/scripts/init/main.d.ts +0 -0
  145. /package/dist/{cli → rimori-client/src/cli}/scripts/init/package-setup.d.ts +0 -0
  146. /package/dist/{cli → rimori-client/src/cli}/scripts/init/package-setup.js +0 -0
  147. /package/dist/{cli → rimori-client/src/cli}/scripts/init/router-transformer.d.ts +0 -0
  148. /package/dist/{cli → rimori-client/src/cli}/scripts/init/router-transformer.js +0 -0
  149. /package/dist/{cli → rimori-client/src/cli}/scripts/init/tailwind-config.d.ts +0 -0
  150. /package/dist/{cli → rimori-client/src/cli}/scripts/init/tailwind-config.js +0 -0
  151. /package/dist/{cli → rimori-client/src/cli}/scripts/init/vite-config.d.ts +0 -0
  152. /package/dist/{cli → rimori-client/src/cli}/scripts/init/vite-config.js +0 -0
  153. /package/dist/{cli → rimori-client/src/cli}/scripts/release/detect-translation-languages.d.ts +0 -0
  154. /package/dist/{cli → rimori-client/src/cli}/scripts/release/detect-translation-languages.js +0 -0
  155. /package/dist/{cli → rimori-client/src/cli}/scripts/release/release-config-upload.d.ts +0 -0
  156. /package/dist/{cli → rimori-client/src/cli}/scripts/release/release-config-upload.js +0 -0
  157. /package/dist/{cli → rimori-client/src/cli}/scripts/release/release-db-update.d.ts +0 -0
  158. /package/dist/{cli → rimori-client/src/cli}/scripts/release/release-db-update.js +0 -0
  159. /package/dist/{cli → rimori-client/src/cli}/scripts/release/release-file-upload.d.ts +0 -0
  160. /package/dist/{cli → rimori-client/src/cli}/scripts/release/release-file-upload.js +0 -0
  161. /package/dist/{cli → rimori-client/src/cli}/scripts/release/release.d.ts +0 -0
  162. /package/dist/{cli → rimori-client/src/cli}/types/DatabaseTypes.d.ts +0 -0
  163. /package/dist/{cli → rimori-client/src/cli}/types/DatabaseTypes.js +0 -0
  164. /package/dist/{plugin → rimori-client/src/controller}/AudioController.d.ts +0 -0
  165. /package/dist/{plugin → rimori-client/src/controller}/AudioController.js +0 -0
  166. /package/dist/{core → rimori-client/src}/controller/SettingsController.js +0 -0
  167. /package/dist/{core → rimori-client/src}/controller/SharedContentController.js +0 -0
  168. /package/dist/{plugin → rimori-client/src/controller}/TranslationController.d.ts +0 -0
  169. /package/dist/{plugin → rimori-client/src/controller}/TranslationController.js +0 -0
  170. /package/dist/{core → rimori-client/src}/controller/VoiceController.js +0 -0
  171. /package/dist/{fromRimori → rimori-client/src/fromRimori}/EventBus.d.ts +0 -0
  172. /package/dist/{fromRimori → rimori-client/src/fromRimori}/EventBus.js +0 -0
  173. /package/dist/{fromRimori → rimori-client/src/fromRimori}/PluginTypes.d.ts +0 -0
  174. /package/dist/{fromRimori → rimori-client/src/fromRimori}/PluginTypes.js +0 -0
  175. /package/dist/{plugin → rimori-client/src/plugin}/Logger.d.ts +0 -0
  176. /package/dist/{plugin → rimori-client/src/plugin}/Logger.js +0 -0
  177. /package/dist/{plugin → rimori-client/src/plugin}/StandaloneClient.d.ts +0 -0
  178. /package/dist/{plugin → rimori-client/src/plugin}/StandaloneClient.js +0 -0
  179. /package/dist/{utils → rimori-client/src/utils}/difficultyConverter.d.ts +0 -0
  180. /package/dist/{utils → rimori-client/src/utils}/difficultyConverter.js +0 -0
  181. /package/dist/{utils → rimori-client/src/utils}/endpoint.d.ts +0 -0
  182. /package/dist/{utils → rimori-client/src/utils}/endpoint.js +0 -0
  183. /package/dist/{worker → rimori-client/src/worker}/WorkerSetup.d.ts +0 -0
  184. /package/src/{plugin → controller}/AudioController.ts +0 -0
  185. /package/src/{plugin → controller}/TranslationController.ts +0 -0
@@ -1,118 +0,0 @@
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 i18n from './config';
11
- import { createInstance } from 'i18next';
12
- /**
13
- * Translator class for handling internationalization
14
- */
15
- export class Translator {
16
- constructor(initialLanguage) {
17
- this.currentLanguage = initialLanguage;
18
- this.isInitialized = false;
19
- this.i18n = this.getI18n();
20
- }
21
- /**
22
- * Initialize translator with user's language
23
- * @param userLanguage - Language code from user info
24
- */
25
- initialize() {
26
- return __awaiter(this, void 0, void 0, function* () {
27
- if (this.isInitialized) {
28
- return;
29
- }
30
- try {
31
- // Fetch translations manually
32
- const translations = yield this.fetchTranslations(this.currentLanguage);
33
- // Add translations to i18n
34
- i18n.addResourceBundle(this.currentLanguage, 'translation', translations);
35
- // Change language
36
- yield i18n.changeLanguage(this.currentLanguage);
37
- this.isInitialized = true;
38
- }
39
- catch (error) {
40
- console.warn('Failed to initialize translator:', error);
41
- // Ensure we have at least English fallback
42
- if (!this.isInitialized) {
43
- this.currentLanguage = 'en';
44
- yield this.initialize();
45
- }
46
- }
47
- });
48
- }
49
- getTranslationUrl(language) {
50
- return `${window.location.origin}/locales/${language}/translation.json`;
51
- }
52
- /**
53
- * Initialize i18n with or without React support
54
- * @param isReact - Whether to use React-specific features
55
- */
56
- getI18n(isReact = false) {
57
- return createInstance({
58
- fallbackLng: 'en',
59
- debug: window.location.hostname === 'localhost',
60
- interpolation: {
61
- escapeValue: !isReact,
62
- },
63
- });
64
- }
65
- usePlugin(plugin) {
66
- this.i18n.use(plugin);
67
- }
68
- /**
69
- * Fetch translations manually from the current domain
70
- * @param language - Language code to fetch
71
- * @returns Promise with translation data
72
- */
73
- fetchTranslations(language) {
74
- return __awaiter(this, void 0, void 0, function* () {
75
- try {
76
- const response = yield fetch(this.getTranslationUrl(language));
77
- if (!response.ok) {
78
- throw new Error(`Failed to fetch translations for ${language}`);
79
- }
80
- return yield response.json();
81
- }
82
- catch (error) {
83
- console.warn(`Failed to fetch translations for ${language}:`, error);
84
- // Fallback to English if available
85
- if (language !== 'en') {
86
- try {
87
- return yield this.fetchTranslations('en');
88
- }
89
- catch (error) {
90
- console.warn('Failed to fetch fallback translations:', error);
91
- }
92
- }
93
- return {};
94
- }
95
- });
96
- }
97
- /**
98
- * Get translation for a key
99
- * @param key - Translation key
100
- * @param options - Translation options
101
- * @returns Translated string
102
- */
103
- t(key, options) {
104
- return i18n.t(key, options);
105
- }
106
- /**
107
- * Get current language
108
- */
109
- getCurrentLanguage() {
110
- return this.currentLanguage;
111
- }
112
- /**
113
- * Check if translator is initialized
114
- */
115
- isReady() {
116
- return this.isInitialized;
117
- }
118
- }
@@ -1,7 +0,0 @@
1
- import i18n from 'i18next';
2
- /**
3
- * Initialize i18n with or without React support
4
- * @param isReact - Whether to use React-specific features
5
- */
6
- export declare function getI18n(isReact?: boolean): import("i18next").i18n;
7
- export default i18n;
@@ -1,20 +0,0 @@
1
- import i18n, { createInstance } from 'i18next';
2
- import { initReactI18next } from 'react-i18next';
3
- /**
4
- * Initialize i18n with or without React support
5
- * @param isReact - Whether to use React-specific features
6
- */
7
- export function getI18n(isReact = false) {
8
- const i18n = createInstance({
9
- fallbackLng: 'en',
10
- debug: window.location.hostname === 'localhost',
11
- interpolation: {
12
- escapeValue: !isReact,
13
- },
14
- });
15
- if (isReact) {
16
- i18n.use(initReactI18next);
17
- }
18
- return i18n;
19
- }
20
- export default i18n;
@@ -1,7 +0,0 @@
1
- import { I18nConfig } from './types';
2
- /**
3
- * Creates a configured i18next instance for Rimori plugins
4
- * @param config - Configuration options for i18n
5
- * @returns Configured i18next instance
6
- */
7
- export declare const createI18nInstance: (config?: I18nConfig) => import("i18next").i18n;
@@ -1,31 +0,0 @@
1
- import i18n from 'i18next';
2
- import { initReactI18next } from 'react-i18next';
3
- import HttpBackend from 'i18next-http-backend';
4
- /**
5
- * Creates a configured i18next instance for Rimori plugins
6
- * @param config - Configuration options for i18n
7
- * @returns Configured i18next instance
8
- */
9
- export const createI18nInstance = (config = {}) => {
10
- const { fallbackLng = 'en', debug = false, loadPath = './locales/{{lng}}/translation.json', supportedLanguages = ['en', 'es', 'zh', 'hi', 'ar'], namespace = 'translation', } = config;
11
- i18n
12
- .use(HttpBackend)
13
- .use(initReactI18next)
14
- .init({
15
- fallbackLng,
16
- debug,
17
- supportedLngs: supportedLanguages,
18
- ns: [namespace],
19
- defaultNS: namespace,
20
- backend: {
21
- loadPath,
22
- },
23
- interpolation: {
24
- escapeValue: false, // React already escapes by default
25
- },
26
- react: {
27
- useSuspense: true,
28
- },
29
- });
30
- return i18n;
31
- };
@@ -1,11 +0,0 @@
1
- import { TOptions } from 'i18next';
2
- type TranslatorFn = (key: string, options?: TOptions) => string;
3
- /**
4
- * Custom useTranslation hook that provides a translation function and indicates readiness
5
- * @returns An object containing the translation function (`t`) and a boolean (`ready`) indicating if the translator is initialized.
6
- */
7
- export declare function useTranslation(): {
8
- t: TranslatorFn;
9
- ready: boolean;
10
- };
11
- export {};
@@ -1,25 +0,0 @@
1
- import { useEffect, useState } from 'react';
2
- import { useRimori } from '../providers/PluginProvider';
3
- /**
4
- * Custom useTranslation hook that provides a translation function and indicates readiness
5
- * @returns An object containing the translation function (`t`) and a boolean (`ready`) indicating if the translator is initialized.
6
- */
7
- export function useTranslation() {
8
- const { plugin } = useRimori();
9
- const [translatorInstance, setTranslatorInstance] = useState(null);
10
- useEffect(() => {
11
- void plugin.getTranslator().then(setTranslatorInstance);
12
- }, [plugin]);
13
- const safeT = (key, options) => {
14
- if (!translatorInstance)
15
- return '\u200B'; // zero-width space
16
- try {
17
- return translatorInstance.t(key, options);
18
- }
19
- catch (error) {
20
- console.error('Translation error:', error);
21
- return key;
22
- }
23
- };
24
- return { t: safeT, ready: translatorInstance !== null };
25
- }
@@ -1,4 +0,0 @@
1
- export { useTranslation } from './hooks';
2
- export { default as i18n, initializeI18n } from './config';
3
- export { useTranslation as useI18nTranslation } from 'react-i18next';
4
- export { Translator } from './Translator';
@@ -1,4 +0,0 @@
1
- export { useTranslation } from './hooks';
2
- export { default as i18n, initializeI18n } from './config';
3
- export { useTranslation as useI18nTranslation } from 'react-i18next';
4
- export { Translator } from './Translator';
@@ -1,7 +0,0 @@
1
- export interface I18nConfig {
2
- fallbackLng?: string;
3
- debug?: boolean;
4
- loadPath?: string;
5
- supportedLanguages?: string[];
6
- namespace?: string;
7
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,11 +0,0 @@
1
- /**
2
- * Custom hook that automatically initializes i18n with user's language
3
- * and provides the useTranslation hook functionality
4
- * @param namespace - Optional namespace for translations
5
- * @returns useTranslation hook result
6
- */
7
- export declare const useRimoriI18n: (namespace?: string) => {
8
- t: import("i18next").TFunction<string, undefined>;
9
- i18n: import("i18next").i18n;
10
- ready: boolean;
11
- };
@@ -1,41 +0,0 @@
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 { useEffect } from 'react';
11
- import { useTranslation } from 'react-i18next';
12
- import { useRimori } from '../providers/PluginProvider';
13
- /**
14
- * Custom hook that automatically initializes i18n with user's language
15
- * and provides the useTranslation hook functionality
16
- * @param namespace - Optional namespace for translations
17
- * @returns useTranslation hook result
18
- */
19
- export const useRimoriI18n = (namespace) => {
20
- const { t, i18n, ready } = useTranslation(namespace);
21
- const rimoriClient = useRimori();
22
- useEffect(() => {
23
- const initializeLanguage = () => __awaiter(void 0, void 0, void 0, function* () {
24
- try {
25
- const userInfo = rimoriClient.plugin.getUserInfo();
26
- const userLanguage = userInfo.mother_tongue.code.toLowerCase();
27
- // Only change language if it's different from current
28
- if (i18n.language !== userLanguage) {
29
- yield i18n.changeLanguage(userLanguage);
30
- }
31
- }
32
- catch (error) {
33
- console.warn('Failed to initialize i18n with user language, using fallback:', error);
34
- }
35
- });
36
- if (ready) {
37
- initializeLanguage();
38
- }
39
- }, [i18n, rimoriClient, ready]);
40
- return { t, i18n, ready };
41
- };
package/dist/index.d.ts DELETED
@@ -1,11 +0,0 @@
1
- export * from './components';
2
- export * from './hooks/UseChatHook';
3
- export * from './plugin/PluginController';
4
- export * from './providers/PluginProvider';
5
- export * from './cli/types/DatabaseTypes';
6
- export * from './utils/difficultyConverter';
7
- export * from './utils/PluginUtils';
8
- export * from './fromRimori/PluginTypes';
9
- export { FirstMessages } from './components/ai/utils';
10
- export { AudioController } from './plugin/AudioController';
11
- export { useTranslation } from './hooks/I18nHooks';
package/dist/index.js DELETED
@@ -1,11 +0,0 @@
1
- // Re-export everything
2
- export * from './components';
3
- export * from './hooks/UseChatHook';
4
- export * from './plugin/PluginController';
5
- export * from './providers/PluginProvider';
6
- export * from './cli/types/DatabaseTypes';
7
- export * from './utils/difficultyConverter';
8
- export * from './utils/PluginUtils';
9
- export * from './fromRimori/PluginTypes';
10
- export { AudioController } from './plugin/AudioController';
11
- export { useTranslation } from './hooks/I18nHooks';
@@ -1,38 +0,0 @@
1
- import { ThirdPartyModule, TOptions } from 'i18next';
2
- /**
3
- * Translator class for handling internationalization
4
- */
5
- export declare class Translator {
6
- private currentLanguage;
7
- private isInitialized;
8
- private i18n;
9
- constructor(initialLanguage: string);
10
- /**
11
- * Initialize translator with user's language
12
- * @param userLanguage - Language code from user info
13
- */
14
- initialize(): Promise<void>;
15
- private getTranslationUrl;
16
- usePlugin(plugin: ThirdPartyModule): void;
17
- /**
18
- * Fetch translations manually from the current domain
19
- * @param language - Language code to fetch
20
- * @returns Promise with translation data
21
- */
22
- private fetchTranslations;
23
- /**
24
- * Get translation for a key
25
- * @param key - Translation key
26
- * @param options - Translation options
27
- * @returns Translated string
28
- */
29
- t(key: string, options?: TOptions): string;
30
- /**
31
- * Get current language
32
- */
33
- getCurrentLanguage(): string;
34
- /**
35
- * Check if translator is initialized
36
- */
37
- isReady(): boolean;
38
- }
@@ -1,101 +0,0 @@
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 { createInstance } from 'i18next';
11
- /**
12
- * Translator class for handling internationalization
13
- */
14
- export class Translator {
15
- constructor(initialLanguage) {
16
- this.isInitialized = false;
17
- this.currentLanguage = initialLanguage;
18
- }
19
- /**
20
- * Initialize translator with user's language
21
- * @param userLanguage - Language code from user info
22
- */
23
- initialize() {
24
- return __awaiter(this, void 0, void 0, function* () {
25
- if (this.isInitialized)
26
- return;
27
- const translations = yield this.fetchTranslations(this.currentLanguage);
28
- const instance = createInstance({
29
- lng: this.currentLanguage,
30
- resources: {
31
- [this.currentLanguage]: {
32
- translation: translations,
33
- },
34
- },
35
- debug: window.location.hostname === 'localhost',
36
- });
37
- yield instance.init();
38
- this.i18n = instance;
39
- this.isInitialized = true;
40
- });
41
- }
42
- getTranslationUrl(language) {
43
- return `${window.location.origin}/locales/${language}/translation.json`;
44
- }
45
- usePlugin(plugin) {
46
- if (!this.i18n) {
47
- throw new Error('Translator is not initialized');
48
- }
49
- this.i18n.use(plugin);
50
- }
51
- /**
52
- * Fetch translations manually from the current domain
53
- * @param language - Language code to fetch
54
- * @returns Promise with translation data
55
- */
56
- fetchTranslations(language) {
57
- return __awaiter(this, void 0, void 0, function* () {
58
- try {
59
- const response = yield fetch(this.getTranslationUrl(language));
60
- if (!response.ok) {
61
- throw new Error(`Failed to fetch translations for ${language}`);
62
- }
63
- return (yield response.json());
64
- }
65
- catch (error) {
66
- console.warn(`Failed to fetch translations for ${language}:`, error);
67
- if (language === 'en')
68
- return {};
69
- // Fallback to English
70
- return this.fetchTranslations('en').catch((error) => {
71
- console.error('Failed to fetch fallback translations:', error);
72
- return {};
73
- });
74
- }
75
- });
76
- }
77
- /**
78
- * Get translation for a key
79
- * @param key - Translation key
80
- * @param options - Translation options
81
- * @returns Translated string
82
- */
83
- t(key, options) {
84
- if (!this.i18n) {
85
- throw new Error('Translator is not initialized');
86
- }
87
- return this.i18n.t(key, options);
88
- }
89
- /**
90
- * Get current language
91
- */
92
- getCurrentLanguage() {
93
- return this.currentLanguage;
94
- }
95
- /**
96
- * Check if translator is initialized
97
- */
98
- isReady() {
99
- return this.isInitialized;
100
- }
101
- }
@@ -1,12 +0,0 @@
1
- import React, { ReactNode } from 'react';
2
- import { RimoriClient } from '../plugin/RimoriClient';
3
- interface PluginProviderProps {
4
- children: ReactNode;
5
- pluginId: string;
6
- settings?: {
7
- disableContextMenu?: boolean;
8
- };
9
- }
10
- export declare const PluginProvider: React.FC<PluginProviderProps>;
11
- export declare const useRimori: () => RimoriClient;
12
- export {};
@@ -1,152 +0,0 @@
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 { PluginController } from '../plugin/PluginController';
13
- import { EventBusHandler } from '../fromRimori/EventBus';
14
- import ContextMenu from '../components/components/ContextMenu';
15
- import { StandaloneClient } from '../plugin/StandaloneClient';
16
- const PluginContext = createContext(null);
17
- export const PluginProvider = ({ children, pluginId, settings }) => {
18
- const [plugin, setPlugin] = useState(null);
19
- const [standaloneClient, setStandaloneClient] = useState(false);
20
- const [applicationMode, setApplicationMode] = useState(null);
21
- const [theme, setTheme] = useState(null);
22
- const isSidebar = applicationMode === 'sidebar';
23
- const isSettings = applicationMode === 'settings';
24
- useEffect(() => {
25
- initEventBus(pluginId);
26
- // Check if we're in an iframe context - if not, we're standalone
27
- const standaloneDetected = window === window.parent;
28
- if (standaloneDetected && !standaloneClient) {
29
- StandaloneClient.getInstance().then((client) => {
30
- client.needsLogin().then((needLogin) => setStandaloneClient(needLogin ? client : true));
31
- });
32
- }
33
- if ((!standaloneDetected && !plugin) || (standaloneDetected && standaloneClient === true)) {
34
- PluginController.getInstance(pluginId, standaloneDetected).then((client) => {
35
- setPlugin(client);
36
- // Get applicationMode and theme from MessageChannel query params
37
- if (!standaloneDetected) {
38
- const mode = client.getQueryParam('applicationMode');
39
- const themeParam = client.getQueryParam('rm_theme');
40
- setApplicationMode(mode);
41
- setTheme(themeParam);
42
- }
43
- });
44
- }
45
- }, [pluginId, standaloneClient]);
46
- //route change
47
- useEffect(() => {
48
- if (!plugin)
49
- return;
50
- //sidebar pages should not report url changes
51
- if (isSidebar)
52
- return;
53
- let lastHash = window.location.hash;
54
- const emitUrlChange = (url) => plugin.event.emit('session.triggerUrlChange', { url });
55
- const interval = setInterval(() => {
56
- if (lastHash === window.location.hash)
57
- return;
58
- lastHash = window.location.hash;
59
- // console.log('url changed:', lastHash);
60
- emitUrlChange(lastHash);
61
- }, 1000);
62
- emitUrlChange(lastHash);
63
- return () => clearInterval(interval);
64
- }, [plugin]);
65
- //detect page height change
66
- useEffect(() => {
67
- const body = document.body;
68
- const handleResize = () => plugin === null || plugin === void 0 ? void 0 : plugin.event.emit('session.triggerHeightChange', body.clientHeight);
69
- body.addEventListener('resize', handleResize);
70
- handleResize();
71
- return () => body.removeEventListener('resize', handleResize);
72
- }, [plugin]);
73
- if (standaloneClient instanceof StandaloneClient) {
74
- return (_jsx(StandaloneAuth, { onLogin: (email, password) => __awaiter(void 0, void 0, void 0, function* () {
75
- if (yield standaloneClient.login(email, password))
76
- setStandaloneClient(true);
77
- }) }));
78
- }
79
- if (!plugin) {
80
- return '';
81
- }
82
- return (_jsxs(PluginContext.Provider, { value: plugin, children: [!(settings === null || settings === void 0 ? void 0 : settings.disableContextMenu) && !isSidebar && !isSettings && _jsx(ContextMenu, { client: plugin }), children] }));
83
- };
84
- export const useRimori = () => {
85
- const context = useContext(PluginContext);
86
- if (context === null) {
87
- throw new Error('useRimori must be used within an PluginProvider');
88
- }
89
- return context;
90
- };
91
- function getUrlParam(name) {
92
- // First try to get from URL hash query params (for compatibility)
93
- const hashParts = window.location.hash.split('?');
94
- if (hashParts.length > 1) {
95
- const hashParams = new URLSearchParams(hashParts[1]);
96
- const hashValue = hashParams.get(name);
97
- if (hashValue)
98
- return hashValue;
99
- }
100
- // Fallback to regular URL search params
101
- const url = new URL(window.location.href);
102
- return url.searchParams.get(name);
103
- }
104
- function initEventBus(pluginId) {
105
- // For now, use URL fallback for EventBus naming - this will be updated once MessageChannel is ready
106
- const isSidebar = getUrlParam('applicationMode') === 'sidebar';
107
- EventBusHandler.getInstance('Plugin EventBus ' + pluginId + ' ' + (isSidebar ? 'sidebar' : 'main'));
108
- }
109
- function StandaloneAuth({ onLogin }) {
110
- const [user, setUser] = useState('');
111
- const [password, setPassword] = useState('');
112
- return (_jsx("div", { style: {
113
- position: 'fixed',
114
- inset: 0,
115
- display: 'flex',
116
- alignItems: 'center',
117
- justifyContent: 'center',
118
- backgroundColor: 'rgba(0, 0, 0, 0.5)',
119
- }, children: _jsxs("div", { style: {
120
- backgroundColor: '#343534',
121
- padding: '1rem',
122
- borderRadius: '0.5rem',
123
- width: '500px',
124
- flexDirection: 'column',
125
- display: 'flex',
126
- alignItems: 'center',
127
- justifyContent: 'center',
128
- }, 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: {
129
- marginBottom: '1rem',
130
- width: '100%',
131
- padding: '0.5rem',
132
- borderRadius: '0.5rem',
133
- border: 'none',
134
- backgroundColor: '#444444',
135
- }, type: "email", placeholder: "Email", onChange: (e) => setUser(e.target.value) }), _jsx("input", { style: {
136
- marginBottom: '1rem',
137
- width: '100%',
138
- padding: '0.5rem',
139
- borderRadius: '0.5rem',
140
- border: 'none',
141
- backgroundColor: '#444444',
142
- }, type: "password", placeholder: "Password", onChange: (e) => setPassword(e.target.value) }), _jsx("button", { style: {
143
- marginBottom: '1rem',
144
- width: '100%',
145
- padding: '0.5rem',
146
- borderRadius: '0.5rem',
147
- border: 'none',
148
- backgroundColor: '#928358',
149
- }, onClick: () => {
150
- onLogin(user, password);
151
- }, children: "Login" })] }) }));
152
- }