@covalent/code-editor

中文文档
11.23.0发布于 2026/10/02MITTypeScriptES Module近 30 天下载 2555

Teradata UI Platform Code Editor Module

原始使用文档
文档目录6 节
  1. TdCodeEditorComponent: td-code-editor
  2. API Summary
  3. Installation
  4. Setup
  5. Example
  6. Running unit tests

TdCodeEditorComponent: td-code-editor

<td-code-editor> is component for code editing based on Covalent and Monaco Editor. The component can run in both Electron and Web Browsers.

API Summary

Inputs

  • value?: string
    • value of the code editor instance
  • language?: string
    • language used for syntax in the editor instance
  • registerLanguage?: function()
    • registers a custom Language within the editor
  • editorStyle?: string
    • Additional Styling applied to Editor Container
  • theme?: string
    • Theme used to style the Editor
  • editorOptions?: object
  • layout?: function()
    • Instructs the editor to remeasure its container

Properties

Events

  • editorInitialized?: function($event)
    • Emitted when Editor is finished initializing. Event passes a reference to the actual editor instance that can be used to call additional operations outside of the Angular component.
  • editorConfigurationChanged?: function($event)
    • Emitted when configuration of the Editor changes
  • editorLanguageChanged?: function($event)
    • Emitted when the language of the Editor changes

Installation

This component can be installed as npm package.

npm install @covalent/code-editor

Setup

Due to an known issue in Monaco Editor version 0.20.0 https://github.com/microsoft/monaco-editor/issues/1842 regarding errors arising when quickly disposing editor instances, utilize the 0.17.1 version of monaco-editor.

If you notice issues with icons not loading there's a known issue with css-loader that prevents it from loading the file font correctly https://github.com/microsoft/monaco-editor/issues/2742 downgrade to [email protected].

We utilize the ESM build of the Monaco Editor. To include this build, you must utilize custom webpack. See https://github.com/Microsoft/monaco-editor/blob/master/docs/integrate-esm.md for more information.

Install the webpack custom builder.

npm install --save-dev @angular-builders/custom-webpack

Install the Monaco Editor webpack extension plugin.

npm install --save-dev monaco-editor-webpack-plugin

Create a webpack config file utilizing the Monaco Editor webpack plugin. Languages and features can be included/excluded to control the resulting image size.

const MonacoWebpackPlugin = require('monaco-editor-webpack-plugin');

module.exports = {
  // target should only be specified when including component in Electron app
  target: 'electron-renderer',
  module: {
    rules: [
      {
        test: /\.css$/,
        use: ['style-loader'],
      },
      {
        test: /\.ttf$/,
        type: 'asset/resource',
      },
    ],
  },
  plugins: [
    new MonacoWebpackPlugin({
      languages: ['css', 'html', 'javascript', 'sql', 'typescript'],
      features: ['contextmenu', 'clipboard', 'find'],
    }),
  ],
};

If using Webpack 4 or lower, it is necessary to use the file-loader instead of Asset Modules like the code below:

{
  test: /\.ttf$/,
  use: ['file-loader']
}

Note: If you are including this component in an Electron application, define the electron-renderer target. See Electron example here: https://github.com/Teradata/covalent-electron/blob/main/monaco-webpack.config.js

Reference the webpack file in your angular.json build config.

...
"build": {
  "builder": "@angular-builders/custom-webpack:browser",
  "options": {
    "customWebpackConfig": {
      "path": "./monaco-webpack.config.js",
      "mergeStrategies": {
        "module.rules": "prepend"
      }
    },
...

Import the CovalentCodeEditorModule in your NgModule:

import { CovalentCodeEditorModule } from '@covalent/code-editor';
@NgModule({
  imports: [
    CovalentCodeEditorModule,
    ...
  ],
  ...
})
export class MyModule {}

Example

<td-code-editor [style.height.px]="200" editorStyle="border:0;" flex theme="vs" language="sql" [editorOptions]="{readOnly:true, fontSize:20}" [(ngModel)]="model" (ngModelChange)="callBackFunc()"> </td-code-editor>

Running unit tests

Run nx test angular-code-editor to execute the unit tests.

版本与发布记录

@covalent/code-editor 共发布 422 个版本,首次发布于 2017/06/23;过去 12 个月发布了 74 个版本。

版本发布日期距今
11.23.0latest2026/10/021 个月前
11.22.12026/09/102 个月前
11.22.02026/09/102 个月前
11.21.02026/09/092 个月前
10.5.82026/07/293 个月前
11.20.12026/07/293 个月前

其他发布通道:beta → 2.0.0-beta.3,next → 11.5.2-beta.1。

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

@covalent/code-editor 是什么?

Teradata UI Platform Code Editor Module

如何安装 @covalent/code-editor?

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

@covalent/code-editor 支持 TypeScript 吗?

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

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

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

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

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

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

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

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

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