@acrodata/code-editor

中文文档
0.6.1发布于 2026/03/23MITTypeScriptES Module近 30 天下载 3.6万

CodeMirror 6 wrapper for Angular

原始使用文档
文档目录8 节
  1. Installation
  2. Usage
  3. Code Editor
  4. Diff Editor
  5. API
  6. Code Editor
  7. Diff Editor
  8. License

Code Editor

npm license

codemirror+angular

CodeMirror 6 wrapper for Angular

Documentation | Playground

Installation

npm install @acrodata/code-editor --save

Usage

Code Editor

import { Component } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { CodeEditor } from '@acrodata/code-editor';

@Component({
  selector: 'your-app',
  template: `<code-editor [(ngModel)]="value" />`,
  imports: [FormsModule, CodeEditor],
})
export class YourAppComponent {
  value = `console.log("Hello world")`;
}

Diff Editor

import { Component } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { DiffEditor } from '@acrodata/code-editor';

@Component({
  selector: 'your-app',
  template: `<diff-editor [(ngModel)]="value" />`,
  imports: [FormsModule, DiffEditor],
})
export class YourAppComponent {
  value = {
    original: `bar`;
    modified: `foo`;
  }
}

API

Code Editor

NameTypeDefaultDescription
[value]string''The editor's value.
[root]Document | ShadowRootundefinedEditorView's root.
[autoFocus]booleanfalseWhether focus on the editor after init.
[disabled]booleanfalseWhether the editor is disabled.
[readonly]booleanfalseWhether the editor is readonly.
[theme]ThemelightThe editor's theme.
[placeholder]string''The editor's placecholder.
[indentWithTab]booleanfalseWhether indent with Tab key.
[indentUnit]string''Should be a string consisting either entirely of the same whitespace character.
[lineWrapping]booleanfalseWhether the editor wraps lines.
[highlightWhitespace]booleanfalseWhether highlight the whitespace.
[languages]LanguageDescription[][]An array of language descriptions for known language-data.
[language]string''The editor's language. You should set the languages prop at first.
[setup]Setup'basic'The editor's built-in setup. The value can be set to basic, minimal or null.
[extensions]Extension[][]It will be appended to the root extensions.
(change)EventEmitter<string>-Event emitted when the editor's value changes.
(focus)EventEmitter<void>-Event emitted when focus on the editor.
(blur)EventEmitter<void>-Event emitted when the editor has lost focus.

Diff Editor

NameTypeDefaultDescription
[setup]Setup'basic'The editor's built-in setup. The value can be set to basic, minimal or null.
[originalValue]string''The diff-editor's original value.
[originalExtensions]Extension[][]The MergeView original config's extensions.
[modifiedValue]string''The diff-editor's modified value.
[modifiedExtensions]Extension[][]The MergeView modified config's extensions.
[orientation]OrientationundefinedControls whether editor A or editor B is shown first. Defaults to "a-b".
[revertControls]RevertControlsundefinedControls whether revert controls are shown between changed chunks.
[renderRevertControl]RenderRevertControlundefinedWhen given, this function is called to render the button to revert a chunk.
[highlightChanges]booleantrueBy default, the merge view will mark inserted and deleted text in changed chunks.
[gutter]booleantrueControls whether a gutter marker is shown next to changed lines.
[disabled]booleanfalseWhether the diff-editor is disabled.
[collapseUnchanged]{ margin?: number; minSize?: number }undefinedWhen given, long stretches of unchanged text are collapsed.
[diffConfig]DiffConfigundefinedPass options to the diff algorithm.
(originalValueChange)EventEmitter<string>-Event emitted when the editor's original value changes.
(originalFocus)EventEmitter<void>-Event emitted when focus on the original editor.
(originalBlur)EventEmitter<void>-Event emitted when blur on the original editor.
(modifiedValueChange)EventEmitter<string>-Event emitted when the editor's modified value changes.
(modifiedFocus)EventEmitter<void>-Event emitted when focus on the modified editor.
(modifiedBlur)EventEmitter<void>-Event emitted when blur on the modified editor.

License

MIT

版本与发布记录

@acrodata/code-editor 共发布 8 个版本,首次发布于 2024/05/24;过去 12 个月发布了 2 个版本。

版本发布日期距今
0.6.1latest2026/03/237 个月前
0.6.02025/11/1411 个月前
0.5.12024/12/021.9 年前
0.5.02024/10/072 年前
0.4.02024/05/312 年前
0.3.02024/05/302 年前

关于 @acrodata/code-editor 的常见问题

@acrodata/code-editor 是什么?

CodeMirror 6 wrapper for Angular

如何安装 @acrodata/code-editor?

在项目目录运行 npm install @acrodata/code-editor,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@angular/core(>=16.0.0)、@angular/forms(>=16.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@acrodata/code-editor 支持 TypeScript 吗?

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

@acrodata/code-editor 支持 ESM 还是 CommonJS?

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

@acrodata/code-editor 可以商用吗?

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

@acrodata/code-editor 的下载量有多少?

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

@acrodata/code-editor 还在维护吗?

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