// Copyright 2024, Command Line Inc. // SPDX-License-Identifier: Apache-2.0 import * as React from "react"; import * as jotai from "jotai"; import { TabContent } from "@/app/tab/tab"; import { clsx } from "clsx"; import { atoms, blockDataMap } from "@/store/global"; import { v4 as uuidv4 } from "uuid"; import { BlockService } from "@/bindings/blockservice"; import { ClientService } from "@/bindings/clientservice"; import { Workspace } from "@/gopkg/wstore"; import * as wstore from "@/gopkg/wstore"; import * as jotaiUtil from "jotai/utils"; import * as WOS from "@/store/wos"; import { CenteredLoadingDiv, CenteredDiv } from "../element/quickelems"; import "./workspace.less"; function Tab({ tabId }: { tabId: string }) { const windowData = jotai.useAtomValue(atoms.waveWindow); const [tabData, tabLoading] = WOS.useWaveObjectValue(WOS.makeORef("tab", tabId)); function setActiveTab(tabId: string) { if (tabId == null) { return; } // TODO } return (
setActiveTab(tabData?.oid)} > {tabData?.name ?? "..."}
); } function TabBar({ workspace, waveWindow }: { workspace: Workspace; waveWindow: WaveWindow }) { function handleAddTab() { const newTabName = `Tab-${workspace.tabids.length + 1}`; WOS.AddTabToWorkspace(newTabName, true); } const tabIds = workspace?.tabids ?? []; return (
{tabIds.map((tabid, idx) => { return ; })}
handleAddTab()}>
); } function Widgets() { const windowData = jotai.useAtomValue(atoms.waveWindow); const activeTabId = windowData.activetabid; async function createBlock(blockDef: wstore.BlockDef) { const rtOpts: wstore.RuntimeOpts = new wstore.RuntimeOpts({ termsize: { rows: 25, cols: 80 } }); const rtnBlock: wstore.Block = await BlockService.CreateBlock(blockDef, rtOpts); const newBlockAtom = jotai.atom(rtnBlock); blockDataMap.set(rtnBlock.blockid, newBlockAtom); addBlockIdToTab(activeTabId, rtnBlock.blockid); } async function clickTerminal() { const termBlockDef = new wstore.BlockDef({ controller: "shell", view: "term", }); createBlock(termBlockDef); } async function clickPreview(fileName: string) { const markdownDef = new wstore.BlockDef({ view: "preview", meta: { file: fileName }, }); createBlock(markdownDef); } async function clickPlot() { const plotDef = new wstore.BlockDef({ view: "plot", }); createBlock(plotDef); } return (
clickTerminal()}>
clickPreview("README.md")}>
clickPreview("go.mod")}>
clickPreview("build/appicon.png")}>
clickPreview("~")}>
clickPlot()}>
); } function WorkspaceElem() { const windowData = jotai.useAtomValue(atoms.waveWindow); const activeTabId = windowData?.activetabid; const ws = jotai.useAtomValue(atoms.workspace); return (
); } export { WorkspaceElem as Workspace };