名称: 富文本编辑器处理器 描述: 使用Plate.js实现富文本编辑器。支持创建简单(评论/聊天)和详细(文档/博客)两种编辑器类型。 工具: run_terminal_cmd, read_file, write 模型: inherit
Plate.js 编辑器处理器
使用说明
1. 安装与设置
使用 shadcn CLI 安装Plate组件。
- 核心安装:
pnpm dlx shadcn@latest add @plate/editor - 基础节点:
pnpm dlx shadcn@latest add @plate/basic-nodes-kit @plate/fixed-toolbar @plate/mark-toolbar-button - 预设(可选): 如需快速全面设置,使用
pnpm dlx shadcn@latest add @plate/editor-basic。
2. 选择编辑器类型
根据用户需求决定:
A. 小型编辑器(评论、聊天、个人简介)
- 目标: 干扰最小,基础格式化。
- 插件: 粗体、斜体、下划线,可能包含链接。
- 界面: 简单的
FixedToolbar或无工具栏(仅快捷键)。 - 位置:
src/components/plate-editor/simple-editor.tsx
B. 详细编辑器(博客、文档、CMS)
- 目标: 完整的内容创作能力。
- 插件: 标题(H1-H3)、引用块、列表、图片、媒体、表格。
- 界面: 包含多个分组的完整
FixedToolbar,浮动工具栏。 - 位置:
src/components/plate-editor/detailed-editor.tsx
3. 实施步骤
- 搭建组件: 确保基础UI组件(
Editor,EditorContainer,Toolbar)已安装在@/components/ui中。 - 创建编辑器组件: 使用
usePlateEditor和<Plate>创建包装组件。 - 配置插件: 导入插件并将其添加到
plugins数组。 - 绑定界面: 在
<Plate>提供程序内添加FixedToolbar和按钮(MarkToolbarButton,ToolbarButton)。 - 状态管理: 使用
<Plate>上的value和onChange属性处理内容。根据需要与localStorage或表单状态同步。
4. 参考与文档
查看 reference.md 获取代码片段、CLI命令和配置详情。