// Copyright 2025, Command Line Inc. // SPDX-License-Identifier: Apache-2.0 import { ErrorBoundary } from "@/app/element/errorboundary"; import { CenteredDiv } from "@/app/element/quickelems"; import { ModalsRenderer } from "@/app/modals/modalsrenderer"; import { NotificationPopover } from "@/app/notification/notificationpopover"; import { ContextMenuModel } from "@/app/store/contextmenu"; import { RpcApi } from "@/app/store/wshclientapi"; import { TabRpcClient } from "@/app/store/wshrpcutil"; import { TabBar } from "@/app/tab/tabbar"; import { TabContent } from "@/app/tab/tabcontent"; import { atoms, createBlock, getApi, isDev } from "@/store/global"; import { fireAndForget, isBlank, makeIconClass } from "@/util/util"; import clsx from "clsx"; import { useAtomValue } from "jotai"; import { memo } from "react"; 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"] ?? 0) - (b["display:order"] ?? 0); }); return wlist; } const Widgets = memo(() => { const fullConfig = useAtomValue(atoms.fullConfigAtom); 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 widgets = sortByDisplayOrder(fullConfig?.widgets); const handleWidgetsBarContextMenu = (e: React.MouseEvent) => { e.preventDefault(); const menu: ContextMenuItem[] = [ { label: "Edit widgets.json", click: () => { fireAndForget(async () => { const path = `${getApi().getConfigDir()}/widgets.json`; const blockDef: BlockDef = { meta: { view: "preview", file: path }, }; await createBlock(blockDef, false, true); }); }, }, { label: "Show Help Widgets", submenu: [ { label: "On", type: "checkbox", checked: showHelp, click: () => { fireAndForget(async () => { await RpcApi.SetConfigCommand(TabRpcClient, { "widget:showhelp": true }); }); }, }, { label: "Off", type: "checkbox", checked: !showHelp, click: () => { fireAndForget(async () => { await RpcApi.SetConfigCommand(TabRpcClient, { "widget:showhelp": false }); }); }, }, ], }, ]; ContextMenuModel.showContextMenu(menu, e); }; return (