菜单

编辑器组件与插件

相关源文件

本文档涵盖了 AppFlowy 中的 AppFlowyEditor 集成、块组件系统、编辑器插件和文档渲染架构。它着重于文档编辑器是如何使用模块化组件构建的,以及各种块类型和编辑功能是如何作为插件实现的。

有关编辑器中 AI 写作助手功能的信息,请参阅AI 写作助手。有关整体文档系统架构的详细信息,请参阅文档编辑器系统

AppFlowyEditor 集成架构

AppFlowy 将开源的 AppFlowyEditor 库作为其核心富文本编辑引擎进行集成。此集成围绕着AppFlowyEditorPage展开,它将核心AppFlowyEditor小部件与 AppFlowy 特定的自定义和配置进行了封装。

AppFlowyEditor 集成流程

来源:frontend/appflowy_flutter/lib/plugins/document/presentation/editor_page.dart43-74 frontend/appflowy_flutter/lib/plugins/document/presentation/editor_configuration.dart63-102

AppFlowyEditorPage作为主要的集成点,接受EditorState和各种自定义参数。它用平台特定的样式、自定义块组件、键盘快捷键和工具栏项来配置编辑器。

核心集成组件

组件目的配置文件位置
EditorState管理文档状态和操作DocumentBloc传递
EditorStyleCustomizer平台特定样式editor_style.dart31-75
块组件构建器自定义块类型editor_configuration.dart294-447
字符快捷键文本转换快捷键editor_page.dart118-129
命令快捷键键盘命令处理程序editor_page.dart91-94
工具栏项浮动工具栏配置editor_page.dart96-116

来源:frontend/appflowy_flutter/lib/plugins/document/presentation/editor_page.dart43-590 frontend/appflowy_flutter/lib/plugins/document/presentation/editor_style.dart31-606

块组件系统

块组件系统是 AppFlowy 文档结构的基础。每种块类型(段落、标题、标注等)都作为独立的组件实现,拥有自己的构建器、配置和渲染逻辑。

块组件架构

来源:frontend/appflowy_flutter/lib/plugins/document/presentation/editor_configuration.dart63-102 frontend/appflowy_flutter/lib/plugins/document/presentation/editor_configuration.dart294-447

块组件注册

块组件通过一个集中式的构建器映射进行注册,该映射将块类型与其对应的构建器关联起来

来源:frontend/appflowy_flutter/lib/plugins/document/presentation/editor_configuration.dart304-447

内置块组件和插件

AppFlowy 提供了一套全面的内置块组件,每个组件都实现了特定的功能和 UI 模式。

文本和结构组件

块类型构建器类主要功能
段落ParagraphBlockComponentBuilder带富文本格式的基本文本
标题HeadingBlockComponentBuilder6个级别,自定义样式
引用QuoteBlockComponentBuilder带自定义样式的引述块
项目符号列表BulletedListBlockComponentBuilder自定义项目符号图标
编号列表NumberedListBlockComponentBuilder自动编号
待办列表TodoListBlockComponentBuilder可勾选的项目

来源:frontend/appflowy_flutter/lib/plugins/document/presentation/editor_configuration.dart492-573

交互式组件

标注块组件

标注块展示了高级组件功能,包括表情符号选择、背景颜色和嵌套内容

来源:frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/callout/callout_block_component.dart18-379

折叠列表组件

折叠列表组件支持可折叠内容和标题级别

来源:frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/toggle/toggle_block_component.dart10-415

专业组件

数学公式组件

来源:frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/math_equation/math_equation_block_component.dart18-314

大纲组件

大纲组件从标题块自动生成目录

来源:frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/outline/outline_block_component.dart13-347

编辑器样式和自定义

EditorStyleCustomizer为编辑器组件提供了平台特定的样式和主题集成。

样式架构

来源:frontend/appflowy_flutter/lib/plugins/document/presentation/editor_style.dart68-192

自定义功能

功能桌面实现移动端实现
字体系列DocumentAppearanceCubit.fontFamilyDocumentPageStyleBloc.fontFamily
字体大小DocumentAppearanceCubit.fontSizeFontLayout.fontSize
行高固定为 1.4LineHeightLayout.lineHeight
文本方向DocumentAppearanceCubit.defaultTextDirection与桌面端相同
光标颜色appearance.cursorColor默认平台颜色
选区颜色appearance.selectionColor默认平台颜色

来源:frontend/appflowy_flutter/lib/plugins/document/presentation/editor_style.dart77-192

工具栏和菜单系统

编辑器包含了用于块操作和格式化的复杂工具栏和菜单系统。

块操作系统

来源:frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/actions/block_action_option_button.dart12-139

浮动工具栏配置

浮动工具栏提供上下文格式选项

来源:frontend/appflowy_flutter/lib/plugins/document/presentation/editor_page.dart96-116 frontend/appflowy_flutter/lib/plugins/document/presentation/editor_page.dart414-474