|
| 1 | +// Copyright 2026, Command Line Inc. |
| 2 | +// SPDX-License-Identifier: Apache-2.0 |
| 3 | + |
| 4 | +import { BlockNodeModel } from "@/app/block/blocktypes"; |
| 5 | +import type { TabModel } from "@/app/store/tab-model"; |
| 6 | +import { AiFileDiffViewModel } from "@/app/view/aifilediff/aifilediff"; |
| 7 | +import { LauncherViewModel } from "@/app/view/launcher/launcher"; |
| 8 | +import { PreviewModel } from "@/app/view/preview/preview-model"; |
| 9 | +import { ProcessViewerViewModel } from "@/app/view/processviewer/processviewer"; |
| 10 | +import { SysinfoViewModel } from "@/app/view/sysinfo/sysinfo"; |
| 11 | +import { TsunamiViewModel } from "@/app/view/tsunami/tsunami"; |
| 12 | +import { VDomModel } from "@/app/view/vdom/vdom-model"; |
| 13 | +import { WaveEnv } from "@/app/waveenv/waveenv"; |
| 14 | +import { atom } from "jotai"; |
| 15 | +import { QuickTipsViewModel } from "../view/quicktipsview/quicktipsview"; |
| 16 | +import { WaveConfigViewModel } from "../view/waveconfig/waveconfig-model"; |
| 17 | +import { blockViewToIcon, blockViewToName } from "./blockutil"; |
| 18 | +import { HelpViewModel } from "@/view/helpview/helpview"; |
| 19 | +import { TermViewModel } from "@/view/term/term-model"; |
| 20 | +import { WaveAiModel } from "@/view/waveai/waveai"; |
| 21 | +import { WebViewModel } from "@/view/webview/webview"; |
| 22 | + |
| 23 | +const BlockRegistry: Map<string, ViewModelClass> = new Map(); |
| 24 | +BlockRegistry.set("term", TermViewModel); |
| 25 | +BlockRegistry.set("preview", PreviewModel); |
| 26 | +BlockRegistry.set("web", WebViewModel); |
| 27 | +BlockRegistry.set("waveai", WaveAiModel); |
| 28 | +BlockRegistry.set("cpuplot", SysinfoViewModel); |
| 29 | +BlockRegistry.set("sysinfo", SysinfoViewModel); |
| 30 | +BlockRegistry.set("vdom", VDomModel); |
| 31 | +BlockRegistry.set("tips", QuickTipsViewModel); |
| 32 | +BlockRegistry.set("help", HelpViewModel); |
| 33 | +BlockRegistry.set("launcher", LauncherViewModel); |
| 34 | +BlockRegistry.set("tsunami", TsunamiViewModel); |
| 35 | +BlockRegistry.set("aifilediff", AiFileDiffViewModel); |
| 36 | +BlockRegistry.set("waveconfig", WaveConfigViewModel); |
| 37 | +BlockRegistry.set("processviewer", ProcessViewerViewModel); |
| 38 | + |
| 39 | +function makeDefaultViewModel(viewType: string): ViewModel { |
| 40 | + const viewModel: ViewModel = { |
| 41 | + viewType: viewType, |
| 42 | + viewIcon: atom(blockViewToIcon(viewType)), |
| 43 | + viewName: atom(blockViewToName(viewType)), |
| 44 | + preIconButton: atom(null), |
| 45 | + endIconButtons: atom(null), |
| 46 | + viewComponent: null, |
| 47 | + }; |
| 48 | + return viewModel; |
| 49 | +} |
| 50 | + |
| 51 | +function makeViewModel( |
| 52 | + blockId: string, |
| 53 | + blockView: string, |
| 54 | + nodeModel: BlockNodeModel, |
| 55 | + tabModel: TabModel, |
| 56 | + waveEnv: WaveEnv |
| 57 | +): ViewModel { |
| 58 | + const ctor = BlockRegistry.get(blockView); |
| 59 | + if (ctor != null) { |
| 60 | + return new ctor({ blockId, nodeModel, tabModel, waveEnv }); |
| 61 | + } |
| 62 | + return makeDefaultViewModel(blockView); |
| 63 | +} |
| 64 | + |
| 65 | +export { makeViewModel }; |
0 commit comments