@rimori/client 1.0.3 → 1.0.5

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 (135) hide show
  1. package/README.md +51 -0
  2. package/dist/components/CRUDModal.js +0 -1
  3. package/dist/components/ai/Assistant.d.ts +9 -0
  4. package/dist/components/ai/Assistant.js +59 -0
  5. package/dist/components/ai/Avatar.d.ts +11 -0
  6. package/dist/components/ai/Avatar.js +39 -0
  7. package/dist/components/ai/EmbeddedAssistent/AudioInputField.d.ts +7 -0
  8. package/dist/components/ai/EmbeddedAssistent/AudioInputField.js +38 -0
  9. package/dist/components/ai/EmbeddedAssistent/CircleAudioAvatar.d.ts +7 -0
  10. package/dist/components/ai/EmbeddedAssistent/CircleAudioAvatar.js +59 -0
  11. package/dist/components/ai/EmbeddedAssistent/TTS/MessageSender.d.ts +19 -0
  12. package/dist/components/ai/EmbeddedAssistent/TTS/MessageSender.js +86 -0
  13. package/dist/components/ai/EmbeddedAssistent/TTS/Player.d.ts +25 -0
  14. package/dist/components/ai/EmbeddedAssistent/TTS/Player.js +180 -0
  15. package/dist/components/ai/EmbeddedAssistent/VoiceRecoder.d.ts +7 -0
  16. package/dist/components/ai/EmbeddedAssistent/VoiceRecoder.js +45 -0
  17. package/dist/components/ai/utils.d.ts +6 -0
  18. package/dist/components/ai/utils.js +14 -0
  19. package/dist/components/audio/Playbutton.js +4 -5
  20. package/dist/components/avatar/Assistant.d.ts +9 -0
  21. package/dist/components/avatar/Assistant.js +59 -0
  22. package/dist/components/avatar/Avatar.d.ts +12 -0
  23. package/dist/components/avatar/Avatar.js +42 -0
  24. package/dist/components/avatar/EmbeddedAssistent/AudioInputField.d.ts +7 -0
  25. package/dist/components/avatar/EmbeddedAssistent/AudioInputField.js +38 -0
  26. package/dist/components/avatar/EmbeddedAssistent/CircleAudioAvatar.d.ts +7 -0
  27. package/dist/components/avatar/EmbeddedAssistent/CircleAudioAvatar.js +59 -0
  28. package/dist/components/avatar/EmbeddedAssistent/TTS/MessageSender.d.ts +19 -0
  29. package/dist/components/avatar/EmbeddedAssistent/TTS/MessageSender.js +84 -0
  30. package/dist/components/avatar/EmbeddedAssistent/TTS/Player.d.ts +25 -0
  31. package/dist/components/avatar/EmbeddedAssistent/TTS/Player.js +180 -0
  32. package/dist/components/avatar/EmbeddedAssistent/VoiceRecoder.d.ts +7 -0
  33. package/dist/components/avatar/EmbeddedAssistent/VoiceRecoder.js +45 -0
  34. package/dist/components/avatar/utils.d.ts +6 -0
  35. package/dist/components/avatar/utils.js +14 -0
  36. package/dist/components.d.ts +9 -0
  37. package/dist/components.js +10 -0
  38. package/dist/controller/AIController.d.ts +4 -3
  39. package/dist/controller/AIController.js +32 -8
  40. package/dist/controller/ObjectController.d.ts +2 -2
  41. package/dist/controller/ObjectController.js +4 -5
  42. package/dist/controller/SettingsController.d.ts +19 -10
  43. package/dist/controller/SettingsController.js +33 -26
  44. package/dist/controller/SharedContentController.js +6 -6
  45. package/dist/core.d.ts +9 -0
  46. package/dist/core.js +10 -0
  47. package/dist/hooks/UseChatHook.js +2 -2
  48. package/dist/index.d.ts +3 -2
  49. package/dist/index.js +4 -2
  50. package/dist/plugin/PluginController.d.ts +4 -12
  51. package/dist/plugin/PluginController.js +45 -70
  52. package/dist/plugin/RimoriClient.d.ts +85 -32
  53. package/dist/plugin/RimoriClient.js +98 -77
  54. package/dist/plugin/ThemeSetter.js +3 -3
  55. package/dist/plugin/fromRimori/EventBus.d.ts +98 -0
  56. package/dist/plugin/fromRimori/EventBus.js +240 -0
  57. package/dist/providers/PluginProvider.d.ts +1 -0
  58. package/dist/providers/PluginProvider.js +10 -12
  59. package/dist/worker/WorkerSetup.d.ts +6 -0
  60. package/dist/worker/WorkerSetup.js +80 -0
  61. package/package.json +17 -3
  62. package/src/components/CRUDModal.tsx +1 -3
  63. package/src/components/ai/Assistant.tsx +96 -0
  64. package/src/components/ai/Avatar.tsx +61 -0
  65. package/src/components/ai/EmbeddedAssistent/AudioInputField.tsx +64 -0
  66. package/src/components/ai/EmbeddedAssistent/CircleAudioAvatar.tsx +75 -0
  67. package/src/components/ai/EmbeddedAssistent/TTS/MessageSender.ts +91 -0
  68. package/src/components/ai/EmbeddedAssistent/TTS/Player.ts +192 -0
  69. package/src/components/ai/EmbeddedAssistent/VoiceRecoder.tsx +56 -0
  70. package/src/components/ai/utils.ts +23 -0
  71. package/src/components/audio/Playbutton.tsx +4 -5
  72. package/src/components.ts +10 -0
  73. package/src/controller/AIController.ts +84 -60
  74. package/src/controller/ObjectController.ts +4 -6
  75. package/src/controller/SettingsController.ts +49 -35
  76. package/src/controller/SharedContentController.ts +6 -6
  77. package/src/core.ts +10 -0
  78. package/src/hooks/UseChatHook.ts +2 -2
  79. package/src/index.ts +4 -2
  80. package/src/plugin/PluginController.ts +51 -76
  81. package/src/plugin/RimoriClient.ts +147 -85
  82. package/src/plugin/ThemeSetter.ts +3 -4
  83. package/src/plugin/fromRimori/EventBus.ts +301 -0
  84. package/src/plugin/fromRimori/readme.md +2 -0
  85. package/src/providers/PluginProvider.tsx +12 -14
  86. package/src/worker/WorkerSetup.ts +81 -0
  87. package/dist/CRUDModal.d.ts +0 -16
  88. package/dist/CRUDModal.js +0 -31
  89. package/dist/MarkdownEditor.d.ts +0 -8
  90. package/dist/MarkdownEditor.js +0 -46
  91. package/dist/audio/Playbutton.d.ts +0 -14
  92. package/dist/audio/Playbutton.js +0 -73
  93. package/dist/components/hooks/UseChatHook.d.ts +0 -15
  94. package/dist/components/hooks/UseChatHook.js +0 -21
  95. package/dist/controller/PluginController.d.ts +0 -14
  96. package/dist/controller/PluginController.js +0 -30
  97. package/dist/plugin/AIController copy.d.ts +0 -22
  98. package/dist/plugin/AIController copy.js +0 -68
  99. package/dist/plugin/AIController.d.ts +0 -22
  100. package/dist/plugin/AIController.js +0 -68
  101. package/dist/plugin/ObjectController.d.ts +0 -34
  102. package/dist/plugin/ObjectController.js +0 -77
  103. package/dist/plugin/SettingController.d.ts +0 -13
  104. package/dist/plugin/SettingController.js +0 -55
  105. package/dist/plugin/VoiceController.d.ts +0 -2
  106. package/dist/plugin/VoiceController.js +0 -27
  107. package/dist/providers/EventEmitter.d.ts +0 -11
  108. package/dist/providers/EventEmitter.js +0 -41
  109. package/dist/providers/EventEmitterContext.d.ts +0 -6
  110. package/dist/providers/EventEmitterContext.js +0 -19
  111. package/dist/utils/DifficultyConverter.d.ts +0 -3
  112. package/dist/utils/DifficultyConverter.js +0 -7
  113. package/dist/utils/constants.d.ts +0 -4
  114. package/dist/utils/constants.js +0 -12
  115. package/dist/utils/plugin/Client.d.ts +0 -72
  116. package/dist/utils/plugin/Client.js +0 -118
  117. package/dist/utils/plugin/PluginController.d.ts +0 -36
  118. package/dist/utils/plugin/PluginController.js +0 -119
  119. package/dist/utils/plugin/PluginUtils.d.ts +0 -2
  120. package/dist/utils/plugin/PluginUtils.js +0 -23
  121. package/dist/utils/plugin/RimoriClient.d.ts +0 -72
  122. package/dist/utils/plugin/RimoriClient.js +0 -118
  123. package/dist/utils/plugin/ThemeSetter.d.ts +0 -1
  124. package/dist/utils/plugin/ThemeSetter.js +0 -13
  125. package/dist/utils/plugin/WhereClauseBuilder.d.ts +0 -24
  126. package/dist/utils/plugin/WhereClauseBuilder.js +0 -79
  127. package/dist/utils/plugin/providers/EventEmitter.d.ts +0 -11
  128. package/dist/utils/plugin/providers/EventEmitter.js +0 -41
  129. package/dist/utils/plugin/providers/EventEmitterContext.d.ts +0 -6
  130. package/dist/utils/plugin/providers/EventEmitterContext.js +0 -19
  131. package/dist/utils/plugin/providers/PluginProvider.d.ts +0 -8
  132. package/dist/utils/plugin/providers/PluginProvider.js +0 -49
  133. package/src/providers/EventEmitter.ts +0 -48
  134. package/src/providers/EventEmitterContext.tsx +0 -27
  135. package/src/utils/constants.ts +0 -18
@@ -1,23 +0,0 @@
1
- export function isFullscreen() {
2
- return !!document.fullscreenElement;
3
- }
4
- export function triggerFullscreen(onStateChange, selector) {
5
- document.addEventListener("fullscreenchange", () => {
6
- onStateChange(isFullscreen());
7
- });
8
- try {
9
- const ref = document.querySelector(selector || "#root");
10
- if (!isFullscreen()) {
11
- // @ts-ignore
12
- ref.requestFullscreen() || ref.webkitRequestFullscreen();
13
- }
14
- else {
15
- // @ts-ignore
16
- document.exitFullscreen() || document.webkitExitFullscreen();
17
- }
18
- }
19
- catch (error) {
20
- console.error("Failed to enter fullscreen", error.message);
21
- }
22
- onStateChange(isFullscreen());
23
- }
@@ -1,72 +0,0 @@
1
- import { SupabaseClient } from "@supabase/supabase-js";
2
- import { GenericSchema } from "@supabase/supabase-js/dist/module/lib/types";
3
- import { PostgrestQueryBuilder, PostgrestFilterBuilder } from "@supabase/postgrest-js";
4
- import { PluginController, Tool, ToolInvocation } from "./PluginController";
5
- import { LanguageLevel } from "../DifficultyConverter";
6
- export declare class RimoriClient {
7
- private static instance;
8
- private superbase;
9
- private plugin;
10
- functions: SupabaseClient["functions"];
11
- storage: SupabaseClient["storage"];
12
- private constructor();
13
- static getInstance(pluginController: PluginController): Promise<RimoriClient>;
14
- from<TableName extends string & keyof GenericSchema['Tables'], Table extends GenericSchema['Tables'][TableName]>(relation: TableName): PostgrestQueryBuilder<GenericSchema, Table, GenericSchema, Table extends {
15
- Relationships: infer R;
16
- } ? R : unknown>;
17
- /**
18
- * Perform a function call.
19
- *
20
- * @param fn - The function name to call
21
- * @param args - The arguments to pass to the function call
22
- * @param options - Named parameters
23
- * @param options.head - When set to `true`, `data` will not be returned.
24
- * Useful if you only need the count.
25
- * @param options.get - When set to `true`, the function will be called with
26
- * read-only access mode.
27
- * @param options.count - Count algorithm to use to count rows returned by the
28
- * function. Only applicable for [set-returning
29
- * functions](https://www.postgresql.org/docs/current/functions-srf.html).
30
- *
31
- * `"exact"`: Exact but slow count algorithm. Performs a `COUNT(*)` under the
32
- * hood.
33
- *
34
- * `"planned"`: Approximated but fast count algorithm. Uses the Postgres
35
- * statistics under the hood.
36
- *
37
- * `"estimated"`: Uses exact count for low numbers and planned count for high
38
- * numbers.
39
- */
40
- rpc<FnName extends string & keyof GenericSchema['Functions'], Fn extends GenericSchema['Functions'][FnName]>(fn: FnName, args?: Fn['Args'], options?: {
41
- head?: boolean;
42
- get?: boolean;
43
- count?: 'exact' | 'planned' | 'estimated';
44
- }): PostgrestFilterBuilder<GenericSchema, Fn['Returns'] extends any[] ? Fn['Returns'][number] extends Record<string, unknown> ? Fn['Returns'][number] : never : never, Fn['Returns'], FnName, null>;
45
- subscribe(eventName: string, callback: (_id: number, data: any) => void): void;
46
- request<T>(eventName: string, data: any): Promise<T>;
47
- emit(eventName: string, data: any): void;
48
- /**
49
- * Get the settings for the plugin. T can be any type of settings, UserSettings or SystemSettings.
50
- * @param defaultSettings The default settings to use if no settings are found.
51
- * @param genericSettings The type of settings to get.
52
- * @returns The settings for the plugin.
53
- */
54
- getSettings<T>(defaultSettings: T, genericSettings?: "user" | "system"): Promise<T>;
55
- setSettings(settings: any, genericSettings?: "user" | "system"): Promise<void>;
56
- getAIResponse(messages: {
57
- role: string;
58
- content: string;
59
- }[]): Promise<string>;
60
- getAIResponseStream(messages: {
61
- role: string;
62
- content: string;
63
- }[], onMessage: (id: string, message: string, finished: boolean, toolInvocations?: ToolInvocation[]) => void, tools?: Tool[]): Promise<void>;
64
- getVoiceResponse(text: string, voice?: string, speed?: number, language?: string): Promise<Blob>;
65
- getVoiceToTextResponse(file: Blob): Promise<string>;
66
- }
67
- export interface UserSettings {
68
- motherTongue: string;
69
- languageLevel: LanguageLevel;
70
- }
71
- export interface SystemSettings {
72
- }
@@ -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
- export class RimoriClient {
11
- constructor(pluginController, superbase) {
12
- this.superbase = superbase;
13
- this.plugin = pluginController;
14
- this.functions = this.superbase.functions;
15
- this.storage = this.superbase.storage;
16
- }
17
- static getInstance(pluginController) {
18
- return __awaiter(this, void 0, void 0, function* () {
19
- if (!RimoriClient.instance) {
20
- const superbase = yield pluginController.getClient();
21
- RimoriClient.instance = new RimoriClient(pluginController, superbase);
22
- }
23
- return RimoriClient.instance;
24
- });
25
- }
26
- from(relation) {
27
- return this.superbase.from(relation);
28
- }
29
- /**
30
- * Perform a function call.
31
- *
32
- * @param fn - The function name to call
33
- * @param args - The arguments to pass to the function call
34
- * @param options - Named parameters
35
- * @param options.head - When set to `true`, `data` will not be returned.
36
- * Useful if you only need the count.
37
- * @param options.get - When set to `true`, the function will be called with
38
- * read-only access mode.
39
- * @param options.count - Count algorithm to use to count rows returned by the
40
- * function. Only applicable for [set-returning
41
- * functions](https://www.postgresql.org/docs/current/functions-srf.html).
42
- *
43
- * `"exact"`: Exact but slow count algorithm. Performs a `COUNT(*)` under the
44
- * hood.
45
- *
46
- * `"planned"`: Approximated but fast count algorithm. Uses the Postgres
47
- * statistics under the hood.
48
- *
49
- * `"estimated"`: Uses exact count for low numbers and planned count for high
50
- * numbers.
51
- */
52
- rpc(fn, args = {}, options = {}) {
53
- return this.superbase.rpc(fn, args, options);
54
- }
55
- subscribe(eventName, callback) {
56
- this.plugin.subscribe(eventName, callback);
57
- }
58
- request(eventName, data) {
59
- return this.plugin.request(eventName, data);
60
- }
61
- emit(eventName, data) {
62
- this.plugin.emit(eventName, data);
63
- }
64
- /**
65
- * Get the settings for the plugin. T can be any type of settings, UserSettings or SystemSettings.
66
- * @param defaultSettings The default settings to use if no settings are found.
67
- * @param genericSettings The type of settings to get.
68
- * @returns The settings for the plugin.
69
- */
70
- getSettings(defaultSettings, genericSettings) {
71
- return __awaiter(this, void 0, void 0, function* () {
72
- const response = yield this.plugin.request("get_settings", { genericSettings });
73
- if (response === null) {
74
- this.setSettings(defaultSettings, genericSettings);
75
- return defaultSettings;
76
- //if the settings are not the same, merge the settings
77
- }
78
- else if (Object.keys(response).length !== Object.keys(defaultSettings).length) {
79
- const existingKeys = Object.fromEntries(Object.entries(response).filter(([k]) => k in defaultSettings));
80
- const mergedSettings = Object.assign(Object.assign({}, defaultSettings), existingKeys);
81
- console.warn("Settings mismatch", { response, defaultSettings, mergedSettings });
82
- this.setSettings(mergedSettings, genericSettings);
83
- return mergedSettings;
84
- }
85
- return response;
86
- });
87
- }
88
- setSettings(settings, genericSettings) {
89
- return __awaiter(this, void 0, void 0, function* () {
90
- yield this.plugin.request("set_settings", { settings, genericSettings });
91
- });
92
- }
93
- getAIResponse(messages) {
94
- return __awaiter(this, void 0, void 0, function* () {
95
- return this.plugin.request("getAIResponse", messages);
96
- });
97
- }
98
- getAIResponseStream(messages, onMessage, tools) {
99
- return __awaiter(this, void 0, void 0, function* () {
100
- throw new Error("Not implemented");
101
- // let triggered = false;
102
- // console.log("getAIResponseStream", messages);
103
- // const id = Math.random();
104
- // this.internalEmit("getAIResponseStream", id, { messages, tools: tools || [] });
105
- // this.subscribe("getAIResponseStream", (_id: number, data: { id: string, response: string, finished: boolean, toolInvocations?: ToolInvocation[] }) => {
106
- // if (triggered || (_id !== id && _id !== 0)) return;
107
- // triggered = data.finished;
108
- // onMessage(data.id, data.response, data.finished, data.toolInvocations);
109
- // })
110
- });
111
- }
112
- getVoiceResponse(text, voice = "alloy", speed = 1, language) {
113
- return this.plugin.request("getVoiceResponse", { text, voice, speed, language });
114
- }
115
- getVoiceToTextResponse(file) {
116
- return this.plugin.request("getSTTResponse", file);
117
- }
118
- }
@@ -1 +0,0 @@
1
- export declare function setTheme(): void;
@@ -1,13 +0,0 @@
1
- export function setTheme() {
2
- const urlParams = new URLSearchParams(window.location.search);
3
- let theme = urlParams.get('theme');
4
- const isSidebar = urlParams.get('applicationMode') === "sidebar";
5
- if (!theme || theme === 'system') {
6
- theme = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
7
- }
8
- document.documentElement.classList.add("dark:text-gray-200", "bg-white");
9
- if (theme === 'dark') {
10
- document.documentElement.classList.add('dark', isSidebar ? "bg-gray-920" : "bg-gray-950");
11
- document.documentElement.style.background = isSidebar ? "rgb(6, 12, 30)" : "rgb(3, 7, 18)";
12
- }
13
- }
@@ -1,24 +0,0 @@
1
- type Condition = {
2
- column?: string;
3
- operator?: string;
4
- value?: any;
5
- AND?: Condition[];
6
- OR?: Condition[];
7
- };
8
- export declare class WhereClauseBuilder {
9
- conditions: Condition[];
10
- constructor();
11
- eq(column: string, value: any): WhereClauseBuilder;
12
- neq(column: string, value: any): WhereClauseBuilder;
13
- gt(column: string, value: any): WhereClauseBuilder;
14
- lt(column: string, value: any): WhereClauseBuilder;
15
- gte(column: string, value: any): WhereClauseBuilder;
16
- lte(column: string, value: any): WhereClauseBuilder;
17
- like(column: string, pattern: string): WhereClauseBuilder;
18
- in(column: string, values: any[]): WhereClauseBuilder;
19
- isNull(column: string): WhereClauseBuilder;
20
- isNotNull(column: string): WhereClauseBuilder;
21
- between(column: string, start: any, end: any): WhereClauseBuilder;
22
- build(): Condition;
23
- }
24
- export {};
@@ -1,79 +0,0 @@
1
- export class WhereClauseBuilder {
2
- constructor() {
3
- this.conditions = [];
4
- }
5
- // Add AND condition
6
- // and(): WhereClauseBuilder {
7
- // const builder = new WhereClauseBuilder();
8
- // this.conditions.push({ AND: builder.conditions });
9
- // return builder;
10
- // }
11
- // Add OR condition
12
- // or(): WhereClauseBuilder {
13
- // const builder = new WhereClauseBuilder();
14
- // this.conditions.push({ OR: builder.conditions });
15
- // return builder;
16
- // }
17
- // Equality check
18
- eq(column, value) {
19
- this.conditions.push({ column, operator: "eq", value });
20
- return this;
21
- }
22
- // Not equal check
23
- neq(column, value) {
24
- this.conditions.push({ column, operator: "neq", value });
25
- return this;
26
- }
27
- // Greater than
28
- gt(column, value) {
29
- this.conditions.push({ column, operator: "gt", value });
30
- return this;
31
- }
32
- // Less than
33
- lt(column, value) {
34
- this.conditions.push({ column, operator: "lt", value });
35
- return this;
36
- }
37
- // Greater than or equal to
38
- gte(column, value) {
39
- this.conditions.push({ column, operator: "gte", value });
40
- return this;
41
- }
42
- // Less than or equal to
43
- lte(column, value) {
44
- this.conditions.push({ column, operator: "lte", value });
45
- return this;
46
- }
47
- // LIKE (pattern match)
48
- like(column, pattern) {
49
- this.conditions.push({ column, operator: "like", value: pattern });
50
- return this;
51
- }
52
- // IN (for multiple values)
53
- in(column, values) {
54
- this.conditions.push({ column, operator: "in", value: values });
55
- return this;
56
- }
57
- // IS NULL
58
- isNull(column) {
59
- this.conditions.push({ column, operator: "is", value: null });
60
- return this;
61
- }
62
- // IS NOT NULL
63
- isNotNull(column) {
64
- this.conditions.push({ column, operator: "is", value: { not: null } });
65
- return this;
66
- }
67
- // BETWEEN (for range checking)
68
- between(column, start, end) {
69
- this.conditions.push({ column, operator: "between", value: [start, end] });
70
- return this;
71
- }
72
- // Build and return the final condition object
73
- build() {
74
- // if (this.conditions.length === 1) {
75
- // return this.conditions; // Direct return if only one condition
76
- // }
77
- return { AND: this.conditions }; // If multiple conditions, combine using AND
78
- }
79
- }
@@ -1,11 +0,0 @@
1
- type Listener<T = any> = (event: T) => void;
2
- export declare class EventEmitter {
3
- private events;
4
- constructor();
5
- on<T = any>(eventName: string, listener: Listener<T>): void;
6
- once<T = any>(eventName: string, listener: Listener<T>): void;
7
- removeListener<T = any>(eventName: string, listener: Listener<T>): void;
8
- emit<T = any>(eventName: string, data?: T): void;
9
- }
10
- export declare const EmitterSingleton: EventEmitter;
11
- export {};
@@ -1,41 +0,0 @@
1
- export class EventEmitter {
2
- constructor() {
3
- this.events = new Map();
4
- this.on = this.on.bind(this);
5
- this.once = this.once.bind(this);
6
- this.emit = this.emit.bind(this);
7
- this.removeListener = this.removeListener.bind(this);
8
- }
9
- // Subscribe to an event
10
- on(eventName, listener) {
11
- if (!this.events.has(eventName)) {
12
- this.events.set(eventName, []);
13
- }
14
- this.events.get(eventName).push(listener);
15
- }
16
- // Subscribe to an event for a single invocation
17
- once(eventName, listener) {
18
- const onceWrapper = (event) => {
19
- this.removeListener(eventName, onceWrapper);
20
- listener(event);
21
- };
22
- this.on(eventName, onceWrapper);
23
- }
24
- // Remove a specific listener
25
- removeListener(eventName, listener) {
26
- const listeners = this.events.get(eventName);
27
- if (!listeners)
28
- return;
29
- this.events.set(eventName, listeners.filter((l) => l !== listener));
30
- }
31
- // Emit an event
32
- emit(eventName, data) {
33
- const listeners = this.events.get(eventName);
34
- console.log("emit", eventName, data, listeners);
35
- if (!listeners)
36
- return;
37
- listeners.forEach((listener) => listener(data));
38
- }
39
- }
40
- const emitter = new EventEmitter();
41
- export const EmitterSingleton = emitter;
@@ -1,6 +0,0 @@
1
- import React from "react";
2
- import { EventEmitter } from "./EventEmitter";
3
- export declare const EventEmitterProvider: React.FC<{
4
- children: React.ReactNode;
5
- }>;
6
- export declare const useEventEmitter: () => EventEmitter;
@@ -1,19 +0,0 @@
1
- "use client";
2
- import { jsx as _jsx } from "react/jsx-runtime";
3
- import { createContext, useContext, useRef } from "react";
4
- import { EmitterSingleton } from "./EventEmitter";
5
- // Create the Context
6
- const EventEmitterContext = createContext(null);
7
- // Provider Component
8
- export const EventEmitterProvider = ({ children }) => {
9
- const eventEmitterRef = useRef(EmitterSingleton);
10
- return (_jsx(EventEmitterContext.Provider, { value: eventEmitterRef.current, children: children }));
11
- };
12
- // Hook to use the EventEmitter
13
- export const useEventEmitter = () => {
14
- const context = useContext(EventEmitterContext);
15
- if (!context) {
16
- throw new Error("useEventEmitter must be used within an EventEmitterProvider");
17
- }
18
- return context;
19
- };
@@ -1,8 +0,0 @@
1
- import React, { ReactNode } from 'react';
2
- import { RimoriClient } from '../RimoriClient';
3
- interface PluginProviderProps {
4
- children: ReactNode;
5
- }
6
- export declare const PluginProvider: React.FC<PluginProviderProps>;
7
- export declare const usePlugin: () => RimoriClient;
8
- export {};
@@ -1,49 +0,0 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- import { createContext, useContext, useEffect, useState } from 'react';
3
- import { PluginController } from '../PluginController';
4
- const PluginContext = createContext(null);
5
- export const PluginProvider = ({ children }) => {
6
- const [plugin, setPlugin] = useState(null);
7
- //route change
8
- useEffect(() => {
9
- let lastHash = window.location.hash;
10
- setInterval(() => {
11
- if (lastHash !== window.location.hash) {
12
- lastHash = window.location.hash;
13
- console.log('url changed:', lastHash);
14
- plugin === null || plugin === void 0 ? void 0 : plugin.emit('urlChange', window.location.hash);
15
- }
16
- }, 100);
17
- PluginController.getInstance().then(setPlugin);
18
- }, []);
19
- //context menu
20
- useEffect(() => {
21
- let isOpen = false;
22
- const handleContextMenu = (e) => {
23
- var _a;
24
- const selection = (_a = window.getSelection()) === null || _a === void 0 ? void 0 : _a.toString().trim();
25
- if (selection) {
26
- e.preventDefault();
27
- // console.log('context menu', selection);
28
- plugin === null || plugin === void 0 ? void 0 : plugin.emit('contextMenu', { text: selection, x: e.clientX, y: e.clientY, open: true });
29
- isOpen = true;
30
- }
31
- };
32
- // Hide the menu on click outside
33
- const handleClick = () => isOpen && (plugin === null || plugin === void 0 ? void 0 : plugin.emit('contextMenu', { text: '', x: 0, y: 0, open: false }));
34
- document.addEventListener("click", handleClick);
35
- document.addEventListener('contextmenu', handleContextMenu);
36
- return () => {
37
- document.removeEventListener("click", handleClick);
38
- document.removeEventListener('contextmenu', handleContextMenu);
39
- };
40
- }, [plugin]);
41
- return (_jsx(PluginContext.Provider, { value: plugin, children: children }));
42
- };
43
- export const usePlugin = () => {
44
- const context = useContext(PluginContext);
45
- if (context === null) {
46
- throw new Error('usePlugin must be used within an PluginProvider');
47
- }
48
- return context;
49
- };
@@ -1,48 +0,0 @@
1
- type Listener<T = any> = (event: T) => void;
2
-
3
- export class EventEmitter {
4
- private events: Map<string, Listener[]> = new Map();
5
-
6
- constructor() {
7
- this.on = this.on.bind(this);
8
- this.once = this.once.bind(this);
9
- this.emit = this.emit.bind(this);
10
- this.removeListener = this.removeListener.bind(this);
11
- }
12
-
13
- // Subscribe to an event
14
- on<T = any>(eventName: string, listener: Listener<T>): void {
15
- if (!this.events.has(eventName)) {
16
- this.events.set(eventName, []);
17
- }
18
- this.events.get(eventName)!.push(listener);
19
- }
20
-
21
- // Subscribe to an event for a single invocation
22
- once<T = any>(eventName: string, listener: Listener<T>): void {
23
- const onceWrapper: Listener<T> = (event) => {
24
- this.removeListener(eventName, onceWrapper);
25
- listener(event);
26
- };
27
- this.on(eventName, onceWrapper);
28
- }
29
-
30
- // Remove a specific listener
31
- removeListener<T = any>(eventName: string, listener: Listener<T>): void {
32
- const listeners = this.events.get(eventName);
33
- if (!listeners) return;
34
-
35
- this.events.set(eventName, listeners.filter((l) => l !== listener));
36
- }
37
-
38
- // Emit an event
39
- emit<T = any>(eventName: string, data?: T): void {
40
- const listeners = this.events.get(eventName);
41
- console.log("emit", eventName, data, listeners);
42
- if (!listeners) return;
43
-
44
- listeners.forEach((listener) => listener(data));
45
- }
46
- }
47
- const emitter = new EventEmitter();
48
- export const EmitterSingleton = emitter;
@@ -1,27 +0,0 @@
1
- "use client";
2
-
3
- import React, { createContext, useContext, useRef } from "react";
4
- import { EmitterSingleton, EventEmitter } from "./EventEmitter";
5
-
6
- // Create the Context
7
- const EventEmitterContext = createContext<EventEmitter | null>(null);
8
-
9
- // Provider Component
10
- export const EventEmitterProvider: React.FC<{ children: React.ReactNode }> = ({ children }) => {
11
- const eventEmitterRef = useRef(EmitterSingleton);
12
-
13
- return (
14
- <EventEmitterContext.Provider value={eventEmitterRef.current}>
15
- {children}
16
- </EventEmitterContext.Provider>
17
- );
18
- };
19
-
20
- // Hook to use the EventEmitter
21
- export const useEventEmitter = (): EventEmitter => {
22
- const context = useContext(EventEmitterContext);
23
- if (!context) {
24
- throw new Error("useEventEmitter must be used within an EventEmitterProvider");
25
- }
26
- return context;
27
- };
@@ -1,18 +0,0 @@
1
- // import { unstable_noStore as noStore } from 'next/cache';
2
-
3
- // noStore();
4
-
5
- export type Env = typeof env;
6
-
7
- export const env = {
8
- // SUPABASE_URL: process?.env?.SUPABASE_URL || "https://pheptqdoqsdnadgoihvr.supabase.co",
9
- SUPABASE_URL: "https://pheptqdoqsdnadgoihvr.supabase.co",
10
- // SUPABASE_ANON_KEY: process.env.SUPABASE_ANON_KEY,
11
- };
12
-
13
- // Validate all environment variables are set
14
- Object.entries(env).forEach(([key, value]) => {
15
- if (!value) {
16
- throw new Error(`${key} is not set`);
17
- }
18
- });