@pulse-editor/react-api 0.0.1 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/hooks/use-agent-tools.d.ts +4 -0
- package/dist/hooks/use-agents.d.ts +6 -0
- package/dist/hooks/use-fetch.d.ts +3 -0
- package/dist/hooks/use-file-view.d.ts +6 -0
- package/dist/hooks/use-notification.d.ts +4 -0
- package/dist/hooks/use-orc.d.ts +3 -0
- package/dist/hooks/use-terminal.d.ts +3 -0
- package/dist/hooks/use-theme.d.ts +3 -0
- package/dist/lib/hooks/use-imc.d.ts +6 -0
- package/{src/main.ts → dist/main.d.ts} +7 -7
- package/dist/main.es.js +1 -0
- package/dist/main.js +1 -0
- package/package.json +41 -41
- package/babel.config.json +0 -5
- package/eslint.config.js +0 -29
- package/postcss.config.js +0 -6
- package/rollup.config.mjs +0 -40
- package/src/hooks/use-agent-tools.ts +0 -48
- package/src/hooks/use-agents.ts +0 -80
- package/src/hooks/use-fetch.ts +0 -45
- package/src/hooks/use-file-view.ts +0 -62
- package/src/hooks/use-notification.ts +0 -48
- package/src/hooks/use-orc.ts +0 -50
- package/src/hooks/use-theme.ts +0 -43
- package/src/hooks/use-toolbar.ts +0 -0
- package/src/tailwind.css +0 -3
- package/tailwind.config.js +0 -10
- package/tsconfig.json +0 -14
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Agent } from "@pulse-editor/shared-utils";
|
|
2
|
+
export default function useAgents(moduleName: string): {
|
|
3
|
+
installAgent: (config: Agent) => Promise<void>;
|
|
4
|
+
runAgentMethod: (agentName: string, methodName: string, parameters: Record<string, any>, abortSignal?: AbortSignal) => Promise<Record<string, any>>;
|
|
5
|
+
isReady: boolean;
|
|
6
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { FileViewModel } from "@pulse-editor/shared-utils";
|
|
2
|
+
export default function useFileView(moduleName: string): {
|
|
3
|
+
viewFile: FileViewModel | undefined;
|
|
4
|
+
updateViewFile: (file: FileViewModel) => void;
|
|
5
|
+
setIsLoaded: import("react").Dispatch<import("react").SetStateAction<boolean>>;
|
|
6
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { InterModuleCommunication } from "@pulse-editor/shared-utils";
|
|
2
|
+
import { ReceiverHandlerMap } from "@pulse-editor/shared-utils";
|
|
3
|
+
export default function useIMC(moduleName: string, handlerMap: ReceiverHandlerMap): {
|
|
4
|
+
imc: InterModuleCommunication | undefined;
|
|
5
|
+
isReady: boolean;
|
|
6
|
+
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import useFileView from "./hooks/use-file-view";
|
|
2
|
-
import useTheme from "./hooks/use-theme";
|
|
3
|
-
import useNotification from "./hooks/use-notification";
|
|
4
|
-
import useAgents from "./hooks/use-agents";
|
|
5
|
-
import useOCR from "./hooks/use-orc";
|
|
6
|
-
|
|
7
|
-
export { useFileView, useTheme, useNotification, useAgents
|
|
1
|
+
import useFileView from "./hooks/use-file-view";
|
|
2
|
+
import useTheme from "./hooks/use-theme";
|
|
3
|
+
import useNotification from "./hooks/use-notification";
|
|
4
|
+
import useAgents from "./hooks/use-agents";
|
|
5
|
+
import useOCR from "./hooks/use-orc";
|
|
6
|
+
import useTerminal from "./hooks/use-terminal";
|
|
7
|
+
export { useFileView, useTheme, useNotification, useAgents, useOCR, useTerminal, };
|
package/dist/main.es.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{InterModuleCommunication as e,IMCMessageTypeEnum as n}from"@pulse-editor/shared-utils";import{useState as t,useEffect as i}from"react";function o(o,s){const[a,r]=t(void 0),[d,c]=t(!1),w=window.parent;return i((()=>{const t=new e(o);return t.initThisWindow(window),t.updateReceiverHandlerMap(s),t.initOtherWindow(w),r(t),t.sendMessage(n.Ready).then((()=>{c(!0)})),()=>{t.close()}}),[]),{imc:a,isReady:d}}function s(e){const[s,a]=t(void 0),[r,d]=t(!1),c=new Map,{imc:w,isReady:u}=o(e,c);return i((()=>{u&&w?.sendMessage(n.RequestViewFile).then((e=>{a(e)}))}),[u]),i((()=>{r&&w?.sendMessage(n.Loaded)}),[r,w]),{viewFile:s,updateViewFile:function(e){w?.sendMessage(n.WriteViewFile,e)},setIsLoaded:d}}function a(e){const[i,s]=t("light"),a=new Map;return a.set(n.ThemeChange,(async(e,n)=>{const t=n.payload;s((e=>t))})),o(e,a),{theme:i}}function r(e){const t=new Map,{imc:i}=o(e,t);return{openNotification:function(e,t){if(!i)throw new Error("IMC is not initialized.");i.sendMessage(n.Notification,{text:e,type:t})}}}function d(e){const t=new Map,{imc:i,isReady:s}=o(e,t);return{installAgent:async function(e){if(!i)throw new Error("IMC not initialized.");await i.sendMessage(n.InstallAgent,e).catch((e=>{throw new Error(e)}))},runAgentMethod:async function(e,t,o,s){if(!i)throw new Error("IMC not initialized.");return await i.sendMessage(n.RunAgentMethod,{agentName:e,methodName:t,parameters:o},s).then((e=>e))},isReady:s}}function c(e){const t=new Map,{imc:i}=o(e,t);return{recognizeText:async function(e){if(!i)throw new Error("IMC is not initialized.");return(await i.sendMessage(n.OCR,{uri:e})).payload.text}}}function w(e){const s=new Map,{imc:a,isReady:r}=o(e,s),[d,c]=t(void 0);return i((()=>{r&&a?.sendMessage(n.RequestTerminal).then((e=>{const{websocketUrl:t}=e;c(t),a.sendMessage(n.Loaded)}))}),[r]),{websocketUrl:d}}export{d as useAgents,s as useFileView,r as useNotification,c as useOCR,w as useTerminal,a as useTheme};
|
package/dist/main.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var e=require("@pulse-editor/shared-utils"),n=require("react");function t(t,s){const[i,a]=n.useState(void 0),[o,r]=n.useState(!1),u=window.parent;return n.useEffect((()=>{const n=new e.InterModuleCommunication(t);return n.initThisWindow(window),n.updateReceiverHandlerMap(s),n.initOtherWindow(u),a(n),n.sendMessage(e.IMCMessageTypeEnum.Ready).then((()=>{r(!0)})),()=>{n.close()}}),[]),{imc:i,isReady:o}}exports.useAgents=function(n){const s=new Map,{imc:i,isReady:a}=t(n,s);return{installAgent:async function(n){if(!i)throw new Error("IMC not initialized.");await i.sendMessage(e.IMCMessageTypeEnum.InstallAgent,n).catch((e=>{throw new Error(e)}))},runAgentMethod:async function(n,t,s,a){if(!i)throw new Error("IMC not initialized.");return await i.sendMessage(e.IMCMessageTypeEnum.RunAgentMethod,{agentName:n,methodName:t,parameters:s},a).then((e=>e))},isReady:a}},exports.useFileView=function(s){const[i,a]=n.useState(void 0),[o,r]=n.useState(!1),u=new Map,{imc:c,isReady:M}=t(s,u);return n.useEffect((()=>{M&&c?.sendMessage(e.IMCMessageTypeEnum.RequestViewFile).then((e=>{a(e)}))}),[M]),n.useEffect((()=>{o&&c?.sendMessage(e.IMCMessageTypeEnum.Loaded)}),[o,c]),{viewFile:i,updateViewFile:function(n){c?.sendMessage(e.IMCMessageTypeEnum.WriteViewFile,n)},setIsLoaded:r}},exports.useNotification=function(n){const s=new Map,{imc:i}=t(n,s);return{openNotification:function(n,t){if(!i)throw new Error("IMC is not initialized.");i.sendMessage(e.IMCMessageTypeEnum.Notification,{text:n,type:t})}}},exports.useOCR=function(n){const s=new Map,{imc:i}=t(n,s);return{recognizeText:async function(n){if(!i)throw new Error("IMC is not initialized.");return(await i.sendMessage(e.IMCMessageTypeEnum.OCR,{uri:n})).payload.text}}},exports.useTerminal=function(s){const i=new Map,{imc:a,isReady:o}=t(s,i),[r,u]=n.useState(void 0);return n.useEffect((()=>{o&&a?.sendMessage(e.IMCMessageTypeEnum.RequestTerminal).then((n=>{const{websocketUrl:t}=n;u(t),a.sendMessage(e.IMCMessageTypeEnum.Loaded)}))}),[o]),{websocketUrl:r}},exports.useTheme=function(s){const[i,a]=n.useState("light"),o=new Map;return o.set(e.IMCMessageTypeEnum.ThemeChange,(async(e,n)=>{const t=n.payload;a((e=>t))})),t(s,o),{theme:i}};
|
package/package.json
CHANGED
|
@@ -1,42 +1,42 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@pulse-editor/react-api",
|
|
3
|
-
"version": "0.0
|
|
4
|
-
"main": "
|
|
5
|
-
"type": "module",
|
|
6
|
-
"
|
|
7
|
-
"
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
"
|
|
14
|
-
"
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
"@
|
|
18
|
-
"@
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
"typescript
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@pulse-editor/react-api",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"main": "dist/main.js",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"files": [
|
|
7
|
+
"dist"
|
|
8
|
+
],
|
|
9
|
+
"publishConfig": {
|
|
10
|
+
"access": "public"
|
|
11
|
+
},
|
|
12
|
+
"scripts": {
|
|
13
|
+
"build": "rollup -c",
|
|
14
|
+
"lint": "eslint ."
|
|
15
|
+
},
|
|
16
|
+
"devDependencies": {
|
|
17
|
+
"@babel/core": "^7.26.10",
|
|
18
|
+
"@babel/preset-env": "^7.26.9",
|
|
19
|
+
"@eslint/js": "^9.25.0",
|
|
20
|
+
"@rollup/plugin-babel": "^6.0.4",
|
|
21
|
+
"@rollup/plugin-node-resolve": "^16.0.1",
|
|
22
|
+
"@rollup/plugin-terser": "^0.4.4",
|
|
23
|
+
"@rollup/plugin-typescript": "^12.1.2",
|
|
24
|
+
"@types/react": "^19.1.2",
|
|
25
|
+
"eslint": "^9.25.0",
|
|
26
|
+
"eslint-plugin-react": "^7.37.5",
|
|
27
|
+
"globals": "^16.0.0",
|
|
28
|
+
"install": "^0.13.0",
|
|
29
|
+
"npm": "^11.3.0",
|
|
30
|
+
"react": "^19.1.0",
|
|
31
|
+
"react-dom": "^19.1.0",
|
|
32
|
+
"rollup": "^4.40.0",
|
|
33
|
+
"rollup-plugin-peer-deps-external": "^2.2.4",
|
|
34
|
+
"typescript": "^5.8.3",
|
|
35
|
+
"typescript-eslint": "^8.30.1"
|
|
36
|
+
},
|
|
37
|
+
"peerDependencies": {
|
|
38
|
+
"@pulse-editor/shared-utils": "0.1.0",
|
|
39
|
+
"react": "^19.0.0",
|
|
40
|
+
"react-dom": "^19.0.0"
|
|
41
|
+
}
|
|
42
42
|
}
|
package/babel.config.json
DELETED
package/eslint.config.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import globals from "globals";
|
|
2
|
-
import pluginJs from "@eslint/js";
|
|
3
|
-
import tseslint from "typescript-eslint";
|
|
4
|
-
import pluginReact from "eslint-plugin-react";
|
|
5
|
-
|
|
6
|
-
/** @type {import('eslint').Linter.Config[]} */
|
|
7
|
-
export default [
|
|
8
|
-
{
|
|
9
|
-
files: ["**/*.{js,mjs,cjs,ts,jsx,tsx}"],
|
|
10
|
-
},
|
|
11
|
-
{
|
|
12
|
-
ignores: ["node_modules/**", "dist/**"],
|
|
13
|
-
},
|
|
14
|
-
{
|
|
15
|
-
languageOptions: { globals: globals.browser },
|
|
16
|
-
settings: {
|
|
17
|
-
react: { version: "detect" },
|
|
18
|
-
},
|
|
19
|
-
},
|
|
20
|
-
pluginJs.configs.recommended,
|
|
21
|
-
...tseslint.configs.recommended,
|
|
22
|
-
pluginReact.configs.flat.recommended,
|
|
23
|
-
{
|
|
24
|
-
rules: {
|
|
25
|
-
"@typescript-eslint/no-explicit-any": "off",
|
|
26
|
-
"@typescript-eslint/no-unused-vars": "off",
|
|
27
|
-
},
|
|
28
|
-
},
|
|
29
|
-
];
|
package/postcss.config.js
DELETED
package/rollup.config.mjs
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import resolve from "@rollup/plugin-node-resolve";
|
|
2
|
-
import peerDepsExternal from "rollup-plugin-peer-deps-external";
|
|
3
|
-
import babel from "@rollup/plugin-babel";
|
|
4
|
-
import typescript from "@rollup/plugin-typescript";
|
|
5
|
-
import postcss from "rollup-plugin-postcss";
|
|
6
|
-
import terser from "@rollup/plugin-terser";
|
|
7
|
-
|
|
8
|
-
// rollup.config.mjs
|
|
9
|
-
export default {
|
|
10
|
-
input: "src/main.ts",
|
|
11
|
-
output: [
|
|
12
|
-
{
|
|
13
|
-
file: "dist/bundle.js",
|
|
14
|
-
format: "cjs",
|
|
15
|
-
},
|
|
16
|
-
{
|
|
17
|
-
file: "dist/bundle.es.js",
|
|
18
|
-
format: "es",
|
|
19
|
-
exports: "named",
|
|
20
|
-
},
|
|
21
|
-
],
|
|
22
|
-
plugins: [
|
|
23
|
-
postcss({
|
|
24
|
-
plugins: [],
|
|
25
|
-
minimize: true,
|
|
26
|
-
}),
|
|
27
|
-
resolve({
|
|
28
|
-
extensions: [".js", ".ts", ".tsx", ".jsx"],
|
|
29
|
-
}),
|
|
30
|
-
peerDepsExternal(),
|
|
31
|
-
babel({
|
|
32
|
-
babelHelpers: "bundled",
|
|
33
|
-
exclude: ["node_modules/**"],
|
|
34
|
-
}),
|
|
35
|
-
typescript({
|
|
36
|
-
exclude: ["node_modules/**", "src/stories/**"],
|
|
37
|
-
}),
|
|
38
|
-
terser(),
|
|
39
|
-
],
|
|
40
|
-
};
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { InterModuleCommunication } from "@pulse-editor/shared-utils";
|
|
2
|
-
import { AgentTool, IMCMessage, IMCMessageTypeEnum } from "@pulse-editor/types";
|
|
3
|
-
import { useEffect, useState } from "react";
|
|
4
|
-
|
|
5
|
-
export default function useAgentTools(moduleName: string) {
|
|
6
|
-
const [imc, setImc] = useState<InterModuleCommunication | undefined>(
|
|
7
|
-
undefined
|
|
8
|
-
);
|
|
9
|
-
const [isReady, setIsReady] = useState(false);
|
|
10
|
-
|
|
11
|
-
const receiverHandlerMap = new Map<
|
|
12
|
-
IMCMessageTypeEnum,
|
|
13
|
-
(senderWindow: Window, message: IMCMessage) => Promise<void>
|
|
14
|
-
>();
|
|
15
|
-
|
|
16
|
-
const targetWindow = window.parent;
|
|
17
|
-
|
|
18
|
-
useEffect(() => {
|
|
19
|
-
const imc = new InterModuleCommunication(moduleName);
|
|
20
|
-
imc.initThisWindow(window);
|
|
21
|
-
imc.updateReceiverHandlerMap(receiverHandlerMap);
|
|
22
|
-
imc.initOtherWindow(targetWindow);
|
|
23
|
-
setImc(imc);
|
|
24
|
-
setIsReady(true);
|
|
25
|
-
|
|
26
|
-
imc.sendMessage(IMCMessageTypeEnum.Ready);
|
|
27
|
-
|
|
28
|
-
return () => {
|
|
29
|
-
imc.close();
|
|
30
|
-
};
|
|
31
|
-
}, []);
|
|
32
|
-
|
|
33
|
-
async function installAgentTool(tool: AgentTool) {
|
|
34
|
-
if (!imc) {
|
|
35
|
-
throw new Error("IMC not initialized.");
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
await imc
|
|
39
|
-
.sendMessage(IMCMessageTypeEnum.InstallAgentTool, tool)
|
|
40
|
-
.then((response) => {
|
|
41
|
-
if (response.type === IMCMessageTypeEnum.Error) {
|
|
42
|
-
throw new Error(response.payload);
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
return { installAgentTool };
|
|
48
|
-
}
|
package/src/hooks/use-agents.ts
DELETED
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import { InterModuleCommunication } from "@pulse-editor/shared-utils";
|
|
2
|
-
import { Agent, IMCMessage, IMCMessageTypeEnum } from "@pulse-editor/types";
|
|
3
|
-
import { useEffect, useState } from "react";
|
|
4
|
-
|
|
5
|
-
export default function useAgents(moduleName: string) {
|
|
6
|
-
const [imc, setImc] = useState<InterModuleCommunication | undefined>(
|
|
7
|
-
undefined
|
|
8
|
-
);
|
|
9
|
-
const [isReady, setIsReady] = useState(false);
|
|
10
|
-
|
|
11
|
-
const receiverHandlerMap = new Map<
|
|
12
|
-
IMCMessageTypeEnum,
|
|
13
|
-
(senderWindow: Window, message: IMCMessage) => Promise<void>
|
|
14
|
-
>();
|
|
15
|
-
|
|
16
|
-
const targetWindow = window.parent;
|
|
17
|
-
|
|
18
|
-
useEffect(() => {
|
|
19
|
-
// Init IMC
|
|
20
|
-
const imc = new InterModuleCommunication(moduleName);
|
|
21
|
-
imc.initThisWindow(window);
|
|
22
|
-
imc.updateReceiverHandlerMap(receiverHandlerMap);
|
|
23
|
-
imc.initOtherWindow(targetWindow);
|
|
24
|
-
setImc(imc);
|
|
25
|
-
setIsReady(true);
|
|
26
|
-
|
|
27
|
-
imc.sendMessage(IMCMessageTypeEnum.Ready);
|
|
28
|
-
|
|
29
|
-
return () => {
|
|
30
|
-
imc.close();
|
|
31
|
-
};
|
|
32
|
-
}, []);
|
|
33
|
-
|
|
34
|
-
async function installAgent(config: Agent) {
|
|
35
|
-
if (!imc) {
|
|
36
|
-
throw new Error("IMC not initialized.");
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
await imc
|
|
40
|
-
.sendMessage(IMCMessageTypeEnum.InstallAgent, config)
|
|
41
|
-
.then((response) => {
|
|
42
|
-
if (response.type === IMCMessageTypeEnum.Error) {
|
|
43
|
-
throw new Error(response.payload);
|
|
44
|
-
}
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
async function runAgentMethod(
|
|
49
|
-
agentName: string,
|
|
50
|
-
methodName: string,
|
|
51
|
-
parameters: Record<string, any>,
|
|
52
|
-
abortSignal?: AbortSignal
|
|
53
|
-
): Promise<Record<string, any>> {
|
|
54
|
-
if (!imc) {
|
|
55
|
-
throw new Error("IMC not initialized.");
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
const result = await imc
|
|
59
|
-
.sendMessage(
|
|
60
|
-
IMCMessageTypeEnum.RunAgentMethod,
|
|
61
|
-
{
|
|
62
|
-
agentName,
|
|
63
|
-
methodName,
|
|
64
|
-
parameters,
|
|
65
|
-
},
|
|
66
|
-
abortSignal
|
|
67
|
-
)
|
|
68
|
-
.then((response) => {
|
|
69
|
-
return response as Record<string, any>;
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
return result;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
return {
|
|
76
|
-
installAgent,
|
|
77
|
-
runAgentMethod,
|
|
78
|
-
isReady,
|
|
79
|
-
};
|
|
80
|
-
}
|
package/src/hooks/use-fetch.ts
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { InterModuleCommunication } from "@pulse-editor/shared-utils";
|
|
2
|
-
import { IMCMessage, IMCMessageTypeEnum } from "@pulse-editor/types";
|
|
3
|
-
import { useEffect, useState } from "react";
|
|
4
|
-
|
|
5
|
-
export default function useFetch(moduleName: string) {
|
|
6
|
-
const [imc, setImc] = useState<InterModuleCommunication | undefined>(
|
|
7
|
-
undefined
|
|
8
|
-
);
|
|
9
|
-
|
|
10
|
-
const receiverHandlerMap = new Map<
|
|
11
|
-
IMCMessageTypeEnum,
|
|
12
|
-
(senderWindow: Window, message: IMCMessage) => Promise<void>
|
|
13
|
-
>();
|
|
14
|
-
|
|
15
|
-
const targetWindow = window.parent;
|
|
16
|
-
|
|
17
|
-
useEffect(() => {
|
|
18
|
-
// Init IMC
|
|
19
|
-
const imc = new InterModuleCommunication(moduleName);
|
|
20
|
-
imc.initThisWindow(window);
|
|
21
|
-
imc.updateReceiverHandlerMap(receiverHandlerMap);
|
|
22
|
-
imc.initOtherWindow(targetWindow);
|
|
23
|
-
setImc(imc);
|
|
24
|
-
|
|
25
|
-
console.log("Sent ready message");
|
|
26
|
-
imc.sendMessage(IMCMessageTypeEnum.Ready);
|
|
27
|
-
|
|
28
|
-
return () => {
|
|
29
|
-
imc.close();
|
|
30
|
-
};
|
|
31
|
-
}, []);
|
|
32
|
-
|
|
33
|
-
function fetch(uri: string, options?: RequestInit): Promise<Response> {
|
|
34
|
-
if (!imc) {
|
|
35
|
-
throw new Error("IMC is not initialized.");
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
return imc.sendMessage(
|
|
39
|
-
IMCMessageTypeEnum.Fetch,
|
|
40
|
-
JSON.stringify({ uri, options })
|
|
41
|
-
);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
return { fetch };
|
|
45
|
-
}
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import { InterModuleCommunication } from "@pulse-editor/shared-utils";
|
|
2
|
-
import {
|
|
3
|
-
IMCMessage,
|
|
4
|
-
IMCMessageTypeEnum,
|
|
5
|
-
FileViewModel,
|
|
6
|
-
} from "@pulse-editor/types";
|
|
7
|
-
import { useEffect, useState } from "react";
|
|
8
|
-
|
|
9
|
-
export default function useFileView(moduleName: string) {
|
|
10
|
-
const [viewFile, setViewFile] = useState<FileViewModel | undefined>(
|
|
11
|
-
undefined
|
|
12
|
-
);
|
|
13
|
-
const [isLoaded, setIsLoaded] = useState(false);
|
|
14
|
-
|
|
15
|
-
const targetWindow = window.parent;
|
|
16
|
-
|
|
17
|
-
const receiverHandlerMap = new Map<
|
|
18
|
-
IMCMessageTypeEnum,
|
|
19
|
-
(senderWindow: Window, message: IMCMessage) => Promise<void>
|
|
20
|
-
>();
|
|
21
|
-
|
|
22
|
-
const [imc, setImc] = useState<InterModuleCommunication | undefined>(
|
|
23
|
-
undefined
|
|
24
|
-
);
|
|
25
|
-
|
|
26
|
-
useEffect(() => {
|
|
27
|
-
// Init IMC
|
|
28
|
-
const imc = new InterModuleCommunication(moduleName);
|
|
29
|
-
imc.initThisWindow(window);
|
|
30
|
-
imc.updateReceiverHandlerMap(receiverHandlerMap);
|
|
31
|
-
imc.initOtherWindow(targetWindow);
|
|
32
|
-
setImc(imc);
|
|
33
|
-
|
|
34
|
-
imc.sendMessage(IMCMessageTypeEnum.Ready).then(() => {
|
|
35
|
-
imc.sendMessage(IMCMessageTypeEnum.RequestViewFile).then((model) => {
|
|
36
|
-
setViewFile(model);
|
|
37
|
-
});
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
return () => {
|
|
41
|
-
console.log("Closing IMC for extension: ", moduleName);
|
|
42
|
-
imc.close();
|
|
43
|
-
};
|
|
44
|
-
}, []);
|
|
45
|
-
|
|
46
|
-
useEffect(() => {
|
|
47
|
-
if (isLoaded) {
|
|
48
|
-
imc?.sendMessage(IMCMessageTypeEnum.Loaded);
|
|
49
|
-
}
|
|
50
|
-
}, [isLoaded, imc]);
|
|
51
|
-
|
|
52
|
-
function updateViewFile(file: FileViewModel) {
|
|
53
|
-
// sender.sendMessage(ViewBoxMessageTypeEnum.ViewFile, JSON.stringify(file));
|
|
54
|
-
imc?.sendMessage(IMCMessageTypeEnum.WriteViewFile, file);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
return {
|
|
58
|
-
viewFile,
|
|
59
|
-
updateViewFile,
|
|
60
|
-
setIsLoaded,
|
|
61
|
-
};
|
|
62
|
-
}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { InterModuleCommunication } from "@pulse-editor/shared-utils";
|
|
2
|
-
import {
|
|
3
|
-
NotificationTypeEnum,
|
|
4
|
-
IMCMessage,
|
|
5
|
-
IMCMessageTypeEnum,
|
|
6
|
-
} from "@pulse-editor/types";
|
|
7
|
-
import { useEffect, useState } from "react";
|
|
8
|
-
|
|
9
|
-
export default function useNotification(moduleName: string) {
|
|
10
|
-
const [imc, setImc] = useState<InterModuleCommunication | undefined>(
|
|
11
|
-
undefined
|
|
12
|
-
);
|
|
13
|
-
|
|
14
|
-
const receiverHandlerMap = new Map<
|
|
15
|
-
IMCMessageTypeEnum,
|
|
16
|
-
(senderWindow: Window, message: IMCMessage) => Promise<void>
|
|
17
|
-
>();
|
|
18
|
-
|
|
19
|
-
const targetWindow = window.parent;
|
|
20
|
-
|
|
21
|
-
useEffect(() => {
|
|
22
|
-
// Init IMC
|
|
23
|
-
const imc = new InterModuleCommunication(moduleName);
|
|
24
|
-
imc.initThisWindow(window);
|
|
25
|
-
imc.updateReceiverHandlerMap(receiverHandlerMap);
|
|
26
|
-
imc.initOtherWindow(targetWindow);
|
|
27
|
-
setImc(imc);
|
|
28
|
-
|
|
29
|
-
console.log("Sent ready message");
|
|
30
|
-
imc.sendMessage(IMCMessageTypeEnum.Ready);
|
|
31
|
-
|
|
32
|
-
return () => {
|
|
33
|
-
imc.close();
|
|
34
|
-
};
|
|
35
|
-
}, []);
|
|
36
|
-
|
|
37
|
-
function openNotification(text: string, type: NotificationTypeEnum) {
|
|
38
|
-
if (!imc) {
|
|
39
|
-
throw new Error("IMC is not initialized.");
|
|
40
|
-
}
|
|
41
|
-
imc.sendMessage(IMCMessageTypeEnum.Notification, {
|
|
42
|
-
text,
|
|
43
|
-
type,
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
return { openNotification };
|
|
48
|
-
}
|
package/src/hooks/use-orc.ts
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { InterModuleCommunication } from "@pulse-editor/shared-utils";
|
|
2
|
-
import { IMCMessage, IMCMessageTypeEnum } from "@pulse-editor/types";
|
|
3
|
-
import { useEffect, useState } from "react";
|
|
4
|
-
|
|
5
|
-
export default function useOCR(moduleName: string) {
|
|
6
|
-
const [imc, setImc] = useState<InterModuleCommunication | undefined>(
|
|
7
|
-
undefined
|
|
8
|
-
);
|
|
9
|
-
|
|
10
|
-
const receiverHandlerMap = new Map<
|
|
11
|
-
IMCMessageTypeEnum,
|
|
12
|
-
(senderWindow: Window, message: IMCMessage) => Promise<void>
|
|
13
|
-
>();
|
|
14
|
-
|
|
15
|
-
const targetWindow = window.parent;
|
|
16
|
-
|
|
17
|
-
useEffect(() => {
|
|
18
|
-
// Init IMC
|
|
19
|
-
const imc = new InterModuleCommunication(moduleName);
|
|
20
|
-
imc.initThisWindow(window);
|
|
21
|
-
imc.updateReceiverHandlerMap(receiverHandlerMap);
|
|
22
|
-
imc.initOtherWindow(targetWindow);
|
|
23
|
-
setImc(imc);
|
|
24
|
-
|
|
25
|
-
console.log("Sent ready message");
|
|
26
|
-
imc.sendMessage(IMCMessageTypeEnum.Ready);
|
|
27
|
-
|
|
28
|
-
return () => {
|
|
29
|
-
imc.close();
|
|
30
|
-
};
|
|
31
|
-
}, []);
|
|
32
|
-
|
|
33
|
-
async function recognizeText(uri: string): Promise<string> {
|
|
34
|
-
if (!imc) {
|
|
35
|
-
throw new Error("IMC is not initialized.");
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// Send the message to the extension
|
|
39
|
-
const result = await imc.sendMessage(
|
|
40
|
-
IMCMessageTypeEnum.OCR,
|
|
41
|
-
{ uri }
|
|
42
|
-
);
|
|
43
|
-
|
|
44
|
-
return result.payload.text;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
return {
|
|
48
|
-
recognizeText,
|
|
49
|
-
};
|
|
50
|
-
}
|
package/src/hooks/use-theme.ts
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { InterModuleCommunication } from "@pulse-editor/shared-utils";
|
|
2
|
-
import { IMCMessage, IMCMessageTypeEnum } from "@pulse-editor/types";
|
|
3
|
-
import { useEffect, useState } from "react";
|
|
4
|
-
|
|
5
|
-
export default function useTheme(moduleName: string) {
|
|
6
|
-
const [theme, setTheme] = useState<string>("light");
|
|
7
|
-
const receiverHandlerMap = new Map<
|
|
8
|
-
IMCMessageTypeEnum,
|
|
9
|
-
(senderWindow: Window, message: IMCMessage) => Promise<void>
|
|
10
|
-
>();
|
|
11
|
-
|
|
12
|
-
receiverHandlerMap.set(
|
|
13
|
-
IMCMessageTypeEnum.ThemeChange,
|
|
14
|
-
async (senderWindow: Window, message: IMCMessage) => {
|
|
15
|
-
const theme = message.payload;
|
|
16
|
-
setTheme((prev) => theme);
|
|
17
|
-
}
|
|
18
|
-
);
|
|
19
|
-
|
|
20
|
-
const [, setImc] = useState<InterModuleCommunication | undefined>(undefined);
|
|
21
|
-
|
|
22
|
-
const targetWindow = window.parent;
|
|
23
|
-
|
|
24
|
-
useEffect(() => {
|
|
25
|
-
// Init IMC
|
|
26
|
-
const imc = new InterModuleCommunication(moduleName);
|
|
27
|
-
imc.initThisWindow(window);
|
|
28
|
-
imc.updateReceiverHandlerMap(receiverHandlerMap);
|
|
29
|
-
imc.initOtherWindow(targetWindow);
|
|
30
|
-
setImc(imc);
|
|
31
|
-
|
|
32
|
-
console.log("Sent ready message");
|
|
33
|
-
imc.sendMessage(IMCMessageTypeEnum.Ready);
|
|
34
|
-
|
|
35
|
-
return () => {
|
|
36
|
-
imc.close();
|
|
37
|
-
};
|
|
38
|
-
}, []);
|
|
39
|
-
|
|
40
|
-
return {
|
|
41
|
-
theme,
|
|
42
|
-
};
|
|
43
|
-
}
|
package/src/hooks/use-toolbar.ts
DELETED
|
File without changes
|
package/src/tailwind.css
DELETED
package/tailwind.config.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/** @type {import('tailwindcss').Config} */
|
|
2
|
-
export default {
|
|
3
|
-
content: ["./src/**/*.{js,jsx,ts,tsx}"],
|
|
4
|
-
// Toggle dark-mode based on .dark class or data-mode="dark"
|
|
5
|
-
darkMode: ["class", '[data-mode="dark"]'],
|
|
6
|
-
theme: {
|
|
7
|
-
extend: {},
|
|
8
|
-
},
|
|
9
|
-
plugins: [],
|
|
10
|
-
};
|
package/tsconfig.json
DELETED