@eyeauras/workbench-monaco

中文文档
0.3.44发布于 2026/11/03MITTypeScriptES Module零依赖近 30 天下载 2510

Optional Monaco editor providers for @eyeauras/workbench.

原始使用文档
文档目录5 节
  1. Install
  2. Editor quickstart
  3. Output log
  4. Options and lifetime
  5. Projection and limits

@eyeauras/workbench-monaco

Optional Monaco-backed editor providers and a high-volume Output viewer for @eyeauras/workbench.

Install

npm install @eyeauras/[email protected] @eyeauras/[email protected] monaco-editor@^0.52.2

Editor quickstart

Use a CSS-aware browser bundler and a sized host. This Vite example configures the plain-text worker; add JSON, CSS, HTML or TypeScript workers when your host needs those languages.

import { createWorkbench } from "@eyeauras/workbench";
import { createMonacoEditorProvider } from "@eyeauras/workbench-monaco";
import * as monaco from "monaco-editor";
import EditorWorker from "monaco-editor/esm/vs/editor/editor.worker?worker";
window.MonacoEnvironment = { getWorker: () => new EditorWorker() };
const host = document.createElement("div");
host.style.cssText = "width:100%;height:600px";
document.body.append(host);
const workbench = createWorkbench(host);
workbench.registerEditorProvider(createMonacoEditorProvider(monaco, { languageFromInput: () => "plaintext" }));
workbench.openEditor({ id: "notes", title: "Notes", editorType: "monaco", data: "Hello" });
export function dispose() { workbench.dispose(); host.remove(); }

Vite TypeScript projects include vite/client for worker import types. Other bundlers supply their own worker integration. The provider owns mounted editors/models. Core installs shared styles; see the shell quickstart for codicons and themes.

The host can provide an existing Monaco namespace or use the lazy provider. See the EyeAuras UI Workbench repository for examples and API orientation.

Every provider also projects workbench.services.diagnostics for the editor input's exact resource into Monaco markers. Diagnostic owners remain isolated through namespaced Monaco marker owners, missing ranges fall back to the first character, and closing the editor clears only markers projected by that editor. Publish diagnostics through the core service; no Monaco-specific producer API is required.

Output log

createMonacoOutputView mounts a standalone, read-only Output editor. It takes an existing Monaco namespace and a core channel; it does not need a Workbench shell or React. Configure Monaco workers in your bundler as for the editor provider, and give the container a definite height.

import { WorkbenchOutputService } from "@eyeauras/workbench";
import { createMonacoOutputView } from "@eyeauras/workbench-monaco";
import * as monaco from "monaco-editor";

const output = new WorkbenchOutputService();
const channel = output.registerChannel("runtime", "Runtime", {
  maxEntries: 100_000,
  maxCharacters: 16 * 1024 * 1024,
});
// The application supplies current translated presentation, including count formatting.
const presentation = resolveOutputPresentation(currentLocale);
const view = createMonacoOutputView(container, monaco, channel, { presentation });
// On a locale change: updates controls/ARIA/counts without replacing the model or filters.
view.setPresentation(resolveOutputPresentation(nextLocale));
channel.appendLines([
  { timestamp: new Date(), level: "info", source: "Combat", message: "Target acquired" },
  { timestamp: new Date(), level: "error", source: "Runtime", message: "Attack failed\n  at attack()" },
]);
view.setFilter({ text: "attack,!cancelled", levels: ["warning", "error"] });

// On unmount: the view owns its editor/model; the service owns its channels.
view.dispose();
output.dispose();

The required MonacoOutputPresentation contains the viewer labels, level names and a count formatter. The host owns translation; the adapter has no default catalog or localization dependency.

The toolbar supports independent level and category (source) selection, literal include/!exclude terms, Follow, Wrap, Clear, and Copy filtered. Positive comma-separated terms use OR; any matching negative term excludes the whole record, including its multiline continuation. Matching is case-insensitive over message and source. Quotes keep commas inside a term and remain literal, matching VS Code Output's parser. This is not a regex or JavaScript expression evaluator. Missing levels/sources means all; an empty array means none. Timestamps display UTC. Raw sources can supply timestamp: null and level: "unknown"; these display as [--:--:--.---] [UNKNOWN] with neutral severity color and remain independently filterable.

The header uses the shared WorkbenchToolbar and context menus. Its filter stays available on the left; actions overflow right-to-left into More Actions as the container narrows, without adding header rows or resetting filter/toggle state. The standalone view installs the shared Workbench styles once per document; hosts can customize the same --vscode-* theme tokens as other controls. Filters, view modes and operations are separate menu groups; the same grouping remains in overflow.

Options and lifetime

OptionDefault / contract
filterAll records. Optional text, levels, and sources; update later with setFilter.
followtrue. Follows the tail; reading earlier records pauses it. setFollow(true) resumes. Layout and Wrap changes do not disable it.
wordWraptrue. The Wrap action changes presentation, not record contents.
themevs-dark. Monaco themes are namespace-global, not isolated per viewer.
writeClipboardnavigator.clipboard.writeText. Supply a sync/async host callback when browser clipboard access is unavailable.

The returned view exposes element, the public Monaco editor, setFilter, setFollow, flush, getText, and idempotent dispose. A view owns its editor, model, toolbar, and subscriptions, not its channel or service. Reuse a host-owned channel without disposing the host's service on view unmount. Clipboard failures appear in the status; the current Copy action has no temporary success animation.

Projection and limits

Timestamp/severity decorations cover the visible viewport only and use Workbench CSS color variables. They remain colored when another Monaco editor changes the namespace-wide theme; the viewer does not register a global log language or theme.

Only matching records enter the Monaco model, so native Find and selection copy operate on visible text. Filter changes rebuild that projection synchronously and reset its selection. Batch appends and prefix eviction preserve the reading position when Follow is off and the selected record survives. A compaction periodically releases deleted Monaco text buffers. Source records remain available in the channel when hidden by a filter. UI updates are coalesced per animation frame; flush() applies pending changes immediately and getText() flushes before returning filtered text.

Both retention limits apply simultaneously. Defaults are 100,000 records and 16 Mi UTF-16 code units of message + source, not a JavaScript heap byte cap. An oversized record is evicted too; the status reports the number evicted since Clear. getEntries(afterId) returns the retained cursor tail without copying earlier history. IDs remain monotonic across Clear. onDidChange announces one complete append batch or Clear; onDidAppend reports new records that survived retention. Existing append, appendLine, and getLines producer calls continue to work.

The default clipboard uses navigator.clipboard; an embedded host can pass writeClipboard. Dispose the viewer before disposing its service. In React, mount it from an effect instead of passing each log batch through component state:

import { useEffect, useRef } from "react";
import type { OutputChannel } from "@eyeauras/workbench";
import { createMonacoOutputView, type MonacoNamespace } from "@eyeauras/workbench-monaco";

function Output({ channel, monaco }: { channel: OutputChannel; monaco: MonacoNamespace }) {
  const host = useRef<HTMLDivElement>(null);
  useEffect(() => {
    const view = createMonacoOutputView(host.current!, monaco, channel);
    return () => view.dispose();
  }, [channel, monaco]);
  return <div ref={host} style={{ height: "100%", minHeight: 0 }} />;
}

See the demo's Output Log page for 100k/1M batch loading and a live stream. Persistent archives and Studio/Vizor transport adapters remain host responsibilities. The renderer decision and benchmark limitations are recorded in issue #26.

版本与发布记录

@eyeauras/workbench-monaco 共发布 20 个版本,首次发布于 2026/10/14;过去 12 个月发布了 20 个版本。

版本发布日期距今
0.3.44latest2026/11/0311 天前
0.3.422026/10/2817 天前
0.3.392026/10/2520 天前
0.3.382026/10/2520 天前
0.3.372026/10/2420 天前
0.3.362026/10/2420 天前

关于 @eyeauras/workbench-monaco 的常见问题

@eyeauras/workbench-monaco 是什么?

Optional Monaco editor providers for @eyeauras/workbench.

如何安装 @eyeauras/workbench-monaco?

在项目目录运行 npm install @eyeauras/workbench-monaco,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:monaco-editor(^0.52.2)、@eyeauras/workbench(0.3.44)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@eyeauras/workbench-monaco 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@eyeauras/workbench-monaco 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@eyeauras/workbench-monaco 可以商用吗?

@eyeauras/workbench-monaco 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@eyeauras/workbench-monaco 的下载量有多少?

根据 npm 官方下载统计,@eyeauras/workbench-monaco 在 2026/10/14 – 2026/11/12 这 30 天内被下载 2,510 次,日均约 84 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@eyeauras/workbench-monaco 还在维护吗?

最新版本 0.3.44 发布于 2026/11/03(11 天前);至今共发布 20 个版本,其中过去 12 个月发布了 20 个;首次发布于 2026/10/14。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。