// Copyright 2024, Command Line Inc. // SPDX-License-Identifier: Apache-2.0 import { ModalsRenderer } from "@/app/modals/modalsrenderer"; import { TabBar } from "@/app/tab/tabbar"; import { TabContent } from "@/app/tab/tabcontent"; import { atoms, createBlock } from "@/store/global"; import * as util from "@/util/util"; import * as jotai from "jotai"; import * as React from "react"; import { CenteredDiv } from "../element/quickelems"; import { ErrorBoundary } from "@/app/element/errorboundary"; import "./workspace.less"; const iconRegex = /^[a-z0-9-]+$/; function keyLen(obj: Object): number { if (obj == null) { return 0; } return Object.keys(obj).length; } function sortByDisplayOrder(wmap: { [key: string]: WidgetConfigType }): WidgetConfigType[] { if (wmap == null) { return []; } const wlist = Object.values(wmap); wlist.sort((a, b) => { return a["display:order"] - b["display:order"]; }); return wlist; } const Widgets = React.memo(() => { const fullConfig = jotai.useAtomValue(atoms.fullConfigAtom); const newWidgetModalVisible = React.useState(false); const helpWidget: WidgetConfigType = { icon: "circle-question", label: "help", blockdef: { meta: { view: "help", }, }, }; const tipsWidget: WidgetConfigType = { icon: "lightbulb", label: "tips", blockdef: { meta: { view: "tips", }, }, }; const showHelp = fullConfig?.settings?.["widget:showhelp"] ?? true; const showDivider = keyLen(fullConfig?.defaultwidgets) > 0 && keyLen(fullConfig?.widgets) > 0; const defaultWidgets = sortByDisplayOrder(fullConfig?.defaultwidgets); const widgets = sortByDisplayOrder(fullConfig?.widgets); return (
{defaultWidgets.map((data, idx) => ( ))} {showDivider ?
: null} {widgets?.map((data, idx) => )} {showHelp ? ( <>
) : null}
); }); async function handleWidgetSelect(blockDef: BlockDef) { createBlock(blockDef); } function isIconValid(icon: string): boolean { if (util.isBlank(icon)) { return false; } return icon.match(iconRegex) != null; } function getIconClass(icon: string): string { if (!isIconValid(icon)) { return "fa fa-regular fa-browser fa-fw"; } return `fa fa-solid fa-${icon} fa-fw`; } const Widget = React.memo(({ widget }: { widget: WidgetConfigType }) => { return (
handleWidgetSelect(widget.blockdef)} title={widget.description || widget.label} >
{!util.isBlank(widget.label) ?
{widget.label}
: null}
); }); const WorkspaceElem = React.memo(() => { const windowData = jotai.useAtomValue(atoms.waveWindow); const activeTabId = windowData?.activetabid; const ws = jotai.useAtomValue(atoms.workspace); return (
{activeTabId == "" ? ( No Active Tab ) : ( <> )}
); }); export { WorkspaceElem as Workspace };