@domternal/angular

中文文档
1.8.1发布于 2026/11/08MITTypeScriptES Module近 30 天下载 1957

MIT-licensed Angular components for the Domternal rich text editor

原始使用文档
文档目录5 节
  1. Install
  2. Quick start
  3. Forms and configuration
  4. Office paste and custom list labels
  5. Further reading

@domternal/angular

Version MIT License

Angular components for the Domternal rich text editor. The standalone editor integrates with reactive forms and ngModel through ControlValueAccessor. Toolbar, selection menu, insert menu, and picker components use signals and OnPush change detection.

Install

In an Angular application:

pnpm add @domternal/angular @domternal/core @domternal/theme

The current build is compiled with Angular 21.2.20. We recommend matching @angular/core, @angular/forms, and @angular/platform-browser packages at that version or later. Applications should use the same or a newer compiler, as described in Angular library compatibility. The manifest still declares a broader >=17.1.0 peer range; this is not a guarantee of compatibility with older Angular releases.

Requires @domternal/core >=1.8.0 <2.0.0. Use version 1.8.1 for all installed Domternal Free packages. The package declares Node.js 22 or later for tooling; also follow your Angular version's Node.js requirements.

Load the theme in your global stylesheet, such as styles.scss:

@use '@domternal/theme/scss';

Quick start

This standalone component binds the document to a form control and adds a toolbar:

import { Component, signal } from '@angular/core';
import { FormControl, ReactiveFormsModule } from '@angular/forms';
import {
  DomternalEditorComponent,
  DomternalToolbarComponent,
} from '@domternal/angular';
import { StarterKit, type Editor } from '@domternal/core';

@Component({
  selector: 'app-text-editor',
  standalone: true,
  imports: [ReactiveFormsModule, DomternalEditorComponent, DomternalToolbarComponent],
  template: `
    @if (editor(); as ed) {
      <domternal-toolbar [editor]="ed" />
    }
    <domternal-editor
      [extensions]="extensions"
      [formControl]="content"
      (editorCreated)="editor.set($event)"
    />
  `,
})
export class TextEditorComponent {
  readonly editor = signal<Editor | null>(null);
  readonly extensions = [StarterKit];
  readonly content = new FormControl('<p>Hello from Angular!</p>', { nonNullable: true });
}

The editor owns its lifecycle; editorCreated provides the instance for commands and sibling UI components. The toolbar renders the controls your extensions contribute. Subscribe to the form control's valueChanges to save content.

Forms and configuration

  • Form values are HTML by default. Use outputFormat="json" with a JSON content value for structured documents. Calling disable() or enable() on the form control updates editability, and a control created disabled starts the editor read-only. The editable input and the control decide in the order they change.
  • Without a form, pass HTML or JSON through [content], handle (contentUpdated), and read event.editor.getHTML() or getJSON(). The component also exposes htmlContent, jsonContent, isEmpty, isFocused, and isEditable signals.
  • The wrapper includes Document, Paragraph, Text, BaseKeymap, and History. For another undo manager, set [history]="false" and omit History from your extensions, including StarterKit's history.
  • preset="notion" is read at creation. The i18n input updates UI translations when replaced, without recreating the editor or changing its form value.
  • (contentError) reports invalid initial content. (contentDiagnostic) reports normalized values; initial reports arrive before editorCreated. See content diagnostics.
  • Custom icons inputs contain raw SVG. Supply trusted, developer-authored constants.

The Angular guide covers inputs, outputs, form behavior, and the toolbar, bubble menu, floating menu, emoji picker, and Notion color picker components.

Office paste and custom list labels

Register PasteCleanup in your editor's extensions to normalize supported Word and Google Docs clipboard HTML. It is not enabled by the wrapper. In 1.5.0, formattingForPaste lets your application choose Preserve or Adapt for each paste without recreating the editor. Add the corresponding formatting, Table and Image extensions for content you want to retain. Use ListLabels for supported custom markers, with the same schema on every collaborative writer.

Further reading

版本与发布记录

@domternal/angular 共发布 47 个版本,首次发布于 2026/03/22;过去 12 个月发布了 47 个版本。

版本发布日期距今
1.8.1latest2026/11/087 天前
1.8.02026/10/2126 天前
1.7.02026/10/2026 天前
1.6.02026/10/1928 天前
1.5.12026/10/1630 天前
1.5.02026/10/161 个月前

关于 @domternal/angular 的常见问题

@domternal/angular 是什么?

MIT-licensed Angular components for the Domternal rich text editor

如何安装 @domternal/angular?

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

@domternal/angular 支持 TypeScript 吗?

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

@domternal/angular 支持 ESM 还是 CommonJS?

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

@domternal/angular 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=22。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@domternal/angular 可以商用吗?

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

@domternal/angular 的下载量有多少?

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

@domternal/angular 还在维护吗?

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