@pulse-editor/react-api 0.1.1-alpha.45 → 0.1.1-alpha.47
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.
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function useSnapShotState<T>(key: string, initialValue?: T, onRestore?: (value: T) => void): readonly [T, import("react").Dispatch<import("react").SetStateAction<T>>];
|
package/dist/lib/use-imc.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { InterModuleCommunication } from "@pulse-editor/shared-utils";
|
|
2
|
-
import { ReceiverHandlerMap } from "@pulse-editor/shared-utils";
|
|
1
|
+
import { InterModuleCommunication, ReceiverHandlerMap } from "@pulse-editor/shared-utils";
|
|
3
2
|
export default function useIMC(handlerMap: ReceiverHandlerMap): {
|
|
4
3
|
imc: InterModuleCommunication | undefined;
|
|
5
4
|
isReady: boolean;
|
package/dist/main.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import useAgentTools from "./hooks/agent/use-agent-tools";
|
|
2
2
|
import useAgents from "./hooks/agent/use-agents";
|
|
3
|
-
import useRegisterAction from "./hooks/editor/use-register-action";
|
|
4
3
|
import useFileView from "./hooks/editor/use-file-view";
|
|
5
4
|
import useLoading from "./hooks/editor/use-loading";
|
|
6
5
|
import useNotification from "./hooks/editor/use-notification";
|
|
6
|
+
import useRegisterAction from "./hooks/editor/use-register-action";
|
|
7
7
|
import useTheme from "./hooks/editor/use-theme";
|
|
8
8
|
import useToolbar from "./hooks/editor/use-toolbar";
|
|
9
9
|
import useImageGen from "./hooks/ai-modality/use-image-gen";
|
|
@@ -13,5 +13,7 @@ import useSTT from "./hooks/ai-modality/use-stt";
|
|
|
13
13
|
import useTTS from "./hooks/ai-modality/use-tts";
|
|
14
14
|
import useVideoGen from "./hooks/ai-modality/use-video-gen";
|
|
15
15
|
import usePulseEnv from "./hooks/editor/use-env";
|
|
16
|
+
import useSnapshotState from "./hooks/editor/use-snapshot-state";
|
|
16
17
|
import useTerminal from "./hooks/terminal/use-terminal";
|
|
17
|
-
|
|
18
|
+
import SnapshotProvider from "./providers/snapshot-provider";
|
|
19
|
+
export { SnapshotProvider, useAgentTools, useAgents, useFileView, useImageGen, useLLM, useLoading, useNotification, useOCR, usePulseEnv, useRegisterAction, useSTT, useSnapshotState, useTTS, useTerminal, useTheme, useToolbar, useVideoGen, };
|
package/dist/main.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{InterModuleCommunication as e,IMCMessageTypeEnum as
|
|
1
|
+
import{InterModuleCommunication as e,IMCMessageTypeEnum as t}from"@pulse-editor/shared-utils";import n,{useState as r,useEffect as i,useRef as o,createContext as a,useContext as s}from"react";function c(n){const[o,a]=r(void 0),[s,c]=r(!1),[d,u]=r(!1),p=window.parent;return i(()=>(u(!0),()=>{u(!1),o?.close(),a(void 0)}),[]),i(()=>{!async function(){if(!d)return;if(void 0!==o)return;const r=new e;r.initThisWindow(window),r.updateReceiverHandlerMap(n),await r.initOtherWindow(p),a(r),await r.sendMessage(t.AppReady),c(!0)}()},[d,o]),{imc:o,isReady:s}}function d(){return c(new Map),{}}function u(){const e=new Map,{imc:n,isReady:r}=c(e);return{runAgentMethod:async function(e,r,i,o,a){if(!n)throw new Error("IMC not initialized.");return await n.sendMessage(t.EditorRunAgentMethod,{agentName:e,methodName:r,parameters:i,llmConfig:a},o).then(e=>e)},isReady:r}}function p(){const[e,n]=r(void 0),o=new Map,{imc:a,isReady:s}=c(o);return i(()=>{s&&a?.sendMessage(t.PlatformReadFile).then(e=>{n(e)})},[s]),{viewModel:e,updateViewModel:function(e){a?.sendMessage(t.PlatformWriteFile,e)}}}function f(){const e=new Map,{imc:n,isReady:o}=c(e),[a,s]=r(!0);return i(()=>{o&&n?.sendMessage(t.EditorLoadingApp,{isLoading:a})},[a]),{isReady:o,toggleLoading:function(e){s(t=>e)}}}function m(){const e=new Map,{imc:n}=c(e);return{openNotification:function(e,r){if(!n)throw new Error("IMC is not initialized.");n.sendMessage(t.EditorShowNotification,{text:e,type:r})}}}function w(e,n,a,s=!0){const{isReady:d,imc:u}=c(l()),p=o([]),[f,m]=r({name:e.name,description:e.description,parameters:e.parameters??{},returns:e.returns??{},handler:n});async function w(e){if(!f.handler)return;return await f.handler(e)}function l(){return new Map([[t.EditorRunAppAction,async(t,n)=>{const{name:r,args:i}=n.payload;if(e.name===r){const t=e.parameters??{};if(Object.keys(i).length!==Object.keys(t).length)throw new Error(`Invalid number of parameters: expected ${Object.keys(t).length}, got ${Object.keys(i).length}`);for(const[e,n]of Object.entries(i)){if(void 0===t[e])throw new Error(`Invalid parameter: ${e}`);if(typeof n!==t[e].type)throw new Error(`Invalid type for parameter ${e}: expected ${t[e].type}, got ${typeof n}. Value received: ${n}`)}return s?await w(i):new Promise(e=>{p.current.push({args:i,resolve:e})})}}]])}return i(()=>{if(s&&p.current.length>0){const e=[...p.current];p.current=[],e.forEach(async({args:e,resolve:t})=>{t(await w(e))})}},[s]),i(()=>{s&&async function(){await(u?.sendMessage(t.EditorRegisterAction,{name:f.name,description:f.description,parameters:f.parameters,returns:f.returns})),u?.updateReceiverHandlerMap(l())}()},[f,u,s]),i(()=>{m(t=>({...t,name:e.name,description:e.description,parameters:e.parameters??{},returns:e.returns??{},handler:n}))},[...a]),{isReady:d}}function l(){const[e,n]=r("light"),i=new Map;return i.set(t.EditorThemeUpdate,async(e,t)=>{const r=t.payload;n(e=>r)}),c(i),{theme:e}}function y(){return{}}function M(){const e=new Map,{imc:n,isReady:r}=c(e);return{runImageGen:async function(e,r,i){if(!n)throw new Error("IMC not initialized.");if(!e&&!r)throw new Error("At least one of textPrompt or imagePrompt is required.");return await n.sendMessage(t.ModalityImageGen,{textPrompt:e,imagePrompt:r,imageModelConfig:i}).then(e=>e)},isReady:r}}function h(){const e=new Map,{imc:n,isReady:r}=c(e);return{runLLM:async function(e,r){if(!n)throw new Error("IMC not initialized.");return await n.sendMessage(t.ModalityLLM,{prompt:e,llmConfig:r}).then(e=>e)},isReady:r}}function g(){const e=new Map,{imc:n}=c(e);return{recognizeText:async function(e){if(!n)throw new Error("IMC is not initialized.");return(await n.sendMessage(t.ModalityOCR,{image:e})).payload.text}}}function R(){const e=new Map,{imc:n,isReady:r}=c(e);return{runSTT:async function(e,r){if(!n)throw new Error("IMC not initialized.");return await n.sendMessage(t.ModalitySTT,{audio:e,sttConfig:r}).then(e=>e)},isReady:r}}function v(){const e=new Map,{imc:n,isReady:r}=c(e);return{runTTS:async function(e,r){if(!n)throw new Error("IMC not initialized.");return await n.sendMessage(t.ModalityTTS,{text:e,ttsConfig:r}).then(e=>e)},isReady:r}}function E(){const e=new Map,{imc:n,isReady:r}=c(e);return{runVideoGen:async function(e,r,i,o){if(!n)throw new Error("IMC not initialized.");if(!r&&!i)throw new Error("At least one of textPrompt or imagePrompt is required.");return await n.sendMessage(t.ModalityVideoGen,{duration:e,textPrompt:r,imagePrompt:i,videoModelConfig:o}).then(e=>e)},isReady:r}}function S(){const e=new Map,{imc:n,isReady:o}=c(e),[a,s]=r({});return i(()=>{o&&n?.sendMessage(t.EditorGetEnv).then(e=>{s(e)})},[o]),{isReady:o,envs:a}}const P=a(void 0);function C({children:e}){const o=new Map([[t.EditorAppStateSnapshotRestore,async(e,t)=>{const{states:n}=t.payload;u(e=>({...n}))}],[t.EditorAppStateSnapshotSave,async(e,t)=>({states:d})]]),{imc:a,isReady:s}=c(o),[d,u]=r({});return i(()=>{s&&a?.updateReceiverHandlerMap(o)},[s,d]),n.createElement(P.Provider,{value:{states:d,setStates:u}},e)}function I(e,t,n){const a=s(P);if(!a)throw new Error("useSnapShotState must be used within a SnapshotProvider");const{states:c,setStates:d}=a,[u,p]=r(void 0!==c[e]?c[e]:t),f=o(!1);return i(()=>{void 0===c[e]&&void 0!==t&&d(n=>({...n,[e]:t}))},[]),i(()=>{const t=c[e];void 0!==t&&(f.current?f.current=!1:t!==u&&(console.log("Restoring state for key:",e,t),p(t),n?.(t)))},[c[e]]),[u,t=>{p(n=>{const r="function"==typeof t?t(n):t;return f.current=!0,Promise.resolve().then(()=>{d(t=>({...t,[e]:r}))}),r})}]}function T(){const e=new Map,{imc:n,isReady:o}=c(e),[a,s]=r(void 0),[d,u]=r(void 0);return i(()=>{o&&n?.sendMessage(t.PlatformCreateTerminal).then(e=>{const{websocketUrl:t,projectHomePath:n}=e;s(t),u(n)})},[o]),{websocketUrl:a,projectHomePath:d}}export{C as SnapshotProvider,d as useAgentTools,u as useAgents,p as useFileView,M as useImageGen,h as useLLM,f as useLoading,m as useNotification,g as useOCR,S as usePulseEnv,w as useRegisterAction,R as useSTT,I as useSnapshotState,v as useTTS,T as useTerminal,l as useTheme,y as useToolbar,E as useVideoGen};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import React, { Dispatch, ReactNode, SetStateAction } from "react";
|
|
2
|
+
export declare const SnapshotContext: React.Context<SnapshotContextType | undefined>;
|
|
3
|
+
export type SnapshotContextType = {
|
|
4
|
+
states: {
|
|
5
|
+
[key: string]: any;
|
|
6
|
+
};
|
|
7
|
+
setStates: Dispatch<SetStateAction<{
|
|
8
|
+
[key: string]: any;
|
|
9
|
+
}>>;
|
|
10
|
+
};
|
|
11
|
+
export default function SnapshotProvider({ children, }: {
|
|
12
|
+
children: ReactNode;
|
|
13
|
+
}): React.JSX.Element;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pulse-editor/react-api",
|
|
3
|
-
"version": "0.1.1-alpha.
|
|
3
|
+
"version": "0.1.1-alpha.47",
|
|
4
4
|
"main": "dist/main.js",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist"
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"typescript-eslint": "^8.30.1"
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {
|
|
41
|
-
"@pulse-editor/shared-utils": "0.1.1-alpha.
|
|
41
|
+
"@pulse-editor/shared-utils": "0.1.1-alpha.47",
|
|
42
42
|
"react": "^19.0.0",
|
|
43
43
|
"react-dom": "^19.0.0"
|
|
44
44
|
}
|