// 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 } from "@/store/global"; 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; } WOS.SetActiveTab(tabId); } return (
setActiveTab(tabData?.oid)} > {tabData?.name ?? "..."}
); } function TabBar({ workspace }: { workspace: Workspace }) { 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: BlockDef) { const rtOpts: RuntimeOpts = { termsize: { rows: 25, cols: 80 } }; await WOS.CreateBlock(blockDef, rtOpts); } async function clickTerminal() { const termBlockDef = { controller: "shell", view: "term", }; createBlock(termBlockDef); } async function clickPreview(fileName: string) { const markdownDef = { view: "preview", meta: { file: fileName }, }; createBlock(markdownDef); } async function clickPlot() { const plotDef: 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 };