Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/afraid-moments-punch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@pulse-editor/shared-utils": patch
"@pulse-editor/react-api": patch
---

Add useWorkspace hook
1 change: 1 addition & 0 deletions .changeset/pre.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"@pulse-editor/web": "0.1.1-alpha.13"
},
"changesets": [
"afraid-moments-punch",
"angry-llamas-smash",
"beige-pandas-rhyme",
"bumpy-parents-pull",
Expand Down
8 changes: 8 additions & 0 deletions npm-packages/react-api/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# @pulse-editor/react-api

## 0.1.1-beta.56

### Patch Changes

- Add useWorkspace hook
- Updated dependencies
- @pulse-editor/[email protected]

## 0.1.1-beta.55

### Patch Changes
Expand Down
4 changes: 2 additions & 2 deletions npm-packages/react-api/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pulse-editor/react-api",
"version": "0.1.1-beta.55",
"version": "0.1.1-beta.56",
"main": "dist/main.js",
"files": [
"dist"
Expand Down Expand Up @@ -37,7 +37,7 @@
"typescript-eslint": "^8.30.1"
},
"peerDependencies": {
"@pulse-editor/shared-utils": "0.1.1-beta.55",
"@pulse-editor/shared-utils": "0.1.1-beta.56",
"react": "^19.0.0",
"react-dom": "^19.0.0"
}
Expand Down
3 changes: 0 additions & 3 deletions npm-packages/react-api/src/hooks/editor/use-toolbar.ts

This file was deleted.

30 changes: 30 additions & 0 deletions npm-packages/react-api/src/hooks/editor/use-workspace.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { IMCMessage, IMCMessageTypeEnum } from "@pulse-editor/shared-utils";
import { useEffect, useState } from "react";
import useIMC from "../imc/use-imc";

export default function useWorkspace() {
const [workspaceId, setWorkspaceId] = useState<string | undefined>(undefined);

const receiverHandlerMap = new Map<
IMCMessageTypeEnum,
(senderWindow: Window, message: IMCMessage) => Promise<void>
>();

const { imc, isReady } = useIMC(receiverHandlerMap, "theme");

// Upon initial load, request theme from main app
useEffect(() => {
if (isReady) {
imc
?.sendMessage(IMCMessageTypeEnum.EditorAppRequestWorkspace)
.then((result) => {
const { id }: { id: string } = result;
setWorkspaceId((prev) => id);
});
}
}, [isReady]);

return {
workspaceId,
};
}
4 changes: 2 additions & 2 deletions npm-packages/react-api/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import useLoading from "./hooks/editor/use-loading";
import useNotification from "./hooks/editor/use-notification";
import useRegisterAction from "./hooks/editor/use-register-action";
import useTheme from "./hooks/editor/use-theme";
import useToolbar from "./hooks/editor/use-toolbar";

import useImageGen from "./hooks/ai-modality/use-image-gen";
import useLLM from "./hooks/ai-modality/use-llm";
Expand All @@ -17,6 +16,7 @@ import usePulseEnv from "./hooks/editor/use-env";
import useOwnedAppView from "./hooks/editor/use-owned-app-view";
import useReceiveFile from "./hooks/editor/use-receive-file";
import useSnapshotState from "./hooks/editor/use-snapshot-state";
import useWorkspace from "./hooks/editor/use-workspace";
import useTerminal from "./hooks/terminal/use-terminal";
import ReceiveFileProvider from "./providers/receive-file-provider";
import SnapshotProvider from "./providers/snapshot-provider";
Expand All @@ -41,6 +41,6 @@ export {
useTTS,
useTerminal,
useTheme,
useToolbar,
useVideoGen,
useWorkspace,
};
6 changes: 6 additions & 0 deletions npm-packages/shared-utils/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @pulse-editor/shared-utils

## 0.1.1-beta.56

### Patch Changes

- Add useWorkspace hook

## 0.1.1-beta.55

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion npm-packages/shared-utils/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pulse-editor/shared-utils",
"version": "0.1.1-beta.55",
"version": "0.1.1-beta.56",
"main": "dist/main.js",
"files": [
"dist"
Expand Down
2 changes: 2 additions & 0 deletions npm-packages/shared-utils/src/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ export enum IMCMessageTypeEnum {
EditorAppReceiveFileUri = "editor-app-receive-file-uri",
// App uses owned app
EditorAppUseOwnedApp = "editor-app-use-owned-app",
// App requests workspace info
EditorAppRequestWorkspace = "editor-app-request-workspace",
// #endregion

// #region Platform API interaction messages (require OS-like environment)
Expand Down
14 changes: 10 additions & 4 deletions remote-workspace/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,20 @@ async function startServers() {
? true
: false;

await addAPIServer(server, expressApp, workspaceId, serverPort, frontendUrl);
await addAPIServer(
server,
expressApp,
"api-" + workspaceId,
serverPort,
frontendUrl,
);
console.log(
`API server is running at ${isHttps ? "https" : "http"}://${address}:${serverPort}/${workspaceId}`,
`API server is running at ${isHttps ? "https" : "http"}://${address}:${serverPort}/api-${workspaceId}`,
);

await addTerminalServer(server, workspaceId);
await addTerminalServer(server, "api-" + workspaceId);
console.log(
`Terminal server is running at ${isHttps ? "wss" : "ws"}://${address}:${serverPort}/${workspaceId}/terminal/ws`,
`Terminal server is running at ${isHttps ? "wss" : "ws"}://${address}:${serverPort}/api-${workspaceId}/terminal/ws`,
);
}

Expand Down
2 changes: 1 addition & 1 deletion remote-workspace/src/servers/api-server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ async function createEndpoints(
res.redirect(url.toString());
});

app.get("/:instanceId/test", (req, res) => {
app.get("/:instanceId/check-health", (req, res) => {
const id = req.params.instanceId;
if (id !== instanceId) {
return res.status(400).send("Invalid instance ID");
Expand Down
2 changes: 1 addition & 1 deletion web/components/app-loaders/sandbox-app-loader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ export default function SandboxAppLoader({
getHandlerMap(viewModel),
);
}
}, [viewModel, editorContext?.editorStates, editorContext?.persistSettings]);
}, [viewModel, editorContext?.editorStates, editorContext?.persistSettings, platformApi]);

function getHandlerMap(model: ViewModel) {
const newMap = new Map<IMCMessageTypeEnum, ReceiverHandler>();
Expand Down
35 changes: 27 additions & 8 deletions web/components/explorer/file-system/fs-explorer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import { IMCContext } from "@/components/providers/imc-provider";
import { PlatformEnum } from "@/lib/enums";
import { usePlatformApi } from "@/lib/hooks/use-platform-api";
import { useTabViewManager } from "@/lib/hooks/use-tab-view-manager";
import { useWorkspace } from "@/lib/hooks/use-workspace";
import { getPlatform } from "@/lib/platform-api/platform-checker";
import { TreeViewGroupRef } from "@/lib/types";
import { addToast, Button } from "@heroui/react";
import { addToast, Button, Spinner } from "@heroui/react";
import { IMCMessageTypeEnum, ViewModeEnum } from "@pulse-editor/shared-utils";
import { useContext, useEffect, useRef } from "react";
import { useContext, useEffect, useRef, useState } from "react";
import toast from "react-hot-toast";
import Icon from "../../misc/icon";
import { EditorContext } from "../../providers/editor-context-provider";
Expand All @@ -25,6 +26,9 @@ export default function FileSystemExplorer({
const platform = getPlatform();
const { platformApi } = usePlatformApi();
const { activeTabView } = useTabViewManager();
const { refreshWorkspaceContent } = useWorkspace();

const [isLoading, setIsLoading] = useState(true);

const rootGroupRef = useRef<TreeViewGroupRef | null>(null);

Expand All @@ -45,6 +49,14 @@ export default function FileSystemExplorer({
}
}, [editorContext?.editorStates.explorerSelectedNodeRefs]);

useEffect(() => {
if (editorContext?.editorStates.workspaceContent) {
setIsLoading(false);
} else {
setIsLoading(true);
}
}, [editorContext?.editorStates.workspaceContent]);

async function viewFile(uri: string) {
// Simply send uri to selected app node or app view
if (activeTabView?.type === ViewModeEnum.App) {
Expand Down Expand Up @@ -191,21 +203,28 @@ export default function FileSystemExplorer({
</div>
</div>

{content?.length === 0 && (
<p className="text-center">
Empty content. Create a new file to get started.
</p>
)}

<div className="overflow-y-auto">
<TreeViewGroup
ref={rootGroupRef}
objects={content}
viewFile={viewFile}
folderUri={fsPath}
platformApi={platformApi}
refreshWorkspaceContent={refreshWorkspaceContent}
/>
</div>

{isLoading && editorContext?.editorStates.currentWorkspace && (
<div className="flex justify-center">
<Spinner />
</div>
)}

{content.length === 0 && !isLoading && (
<p className="text-center">
Empty content. Create a new file to get started.
</p>
)}
</div>
</div>
);
Expand Down
Loading