首页 全部提示词 Vibe Coding

CKEditor 5 插件

CKEditor 5 Plugin

文本 @bimbimkkay 2,283 字符 在 prompts.chat 查看 译文有问题?

中文译文

你是一位资深 CKEditor 5 插件架构师。

我需要你构建一个完整的 CKEditor 5 插件,名为 "NewsletterPlugin"。

背景:

环境:

  • CKEditor 5 自定义构建
  • ES6 模块
  • 优先使用 Typescript(如果可能)
  • 不使用 CKEditor 4 API

======================================== 功能需求

  1. 工具栏按钮:
  • 添加一个名为 "newsletter" 的工具栏按钮
  • 图标:简单的 SVG 占位符
  • 点击时 → 打开一个对话框(模态框)
  1. 对话框行为: 对话框必须包含输入字段:
  • title(文本输入框)
  • description(文本区域)
  • tabs(动态列表,用户可以添加/删除标签项) 每个标签项: - tabTitle - tabContent(允许 HTML)

按钮:

  • Cancel
  • OK
  1. 点击 OK 时:
  • 在编辑器内生成结构化 HTML 块
  • 结构示例:
  1. 编辑器内的行为:
  1. 必须使用:
  • GeneralHtmlSupport(GHS)以允许自定义类和属性
  • 正确的 upcast / downcast 转换器
  • Widget API(toWidget,如需要则使用 toWidgetEditable)
  • Command 类
  • UI 组件系统(ButtonView、View、InputTextView)
  • 编辑与 UI 部分分离
  • 正确注册 Schema
  1. 所需架构:

创建结构:

  • newsletter/
    • newsletterplugin.ts
    • newsletterediting.ts
    • newsletterui.ts
    • newslettercommand.ts
  1. 技术要求:
  • 注册 schema 元素: newsletterBlock

  • 必须允许: class id href data 属性

  • 使用: editor.model.change() conversion.for('upcast') conversion.for('downcast')

  • 通过编辑视图文档处理点击事件

  • 使用 editing.view.document.on( 'click', ... )

  • 检测双击事件

  1. 重要: 不要使用原生 DOM 操作。 所有更新必须通过 editor.model 进行。

  2. 所需输出:

  • 完整的插件代码
  • 正确的导入
  • 解释架构的注释
  • 解释与 CKEditor 4 的迁移差异
  • 展示如何在构建中注册插件
  1. 额外: 解释如何在编辑器配置中启用 GeneralHtmlSupport 配置。

========================================

请生成干净、可投入生产的代码。 不要简化逻辑。 严格遵循 CKEditor 5 最佳实践。

English original

You are a senior CKEditor 5 plugin architect.

I need you to build a complete CKEditor 5 plugin called "NewsletterPlugin".

Context:

Environment:

  • CKEditor 5 custom build
  • ES6 modules
  • Typescript preferred (if possible)
  • No usage of CKEditor 4 APIs

======================================== FEATURE REQUIREMENTS

  1. Toolbar Button:
  • Add a toolbar button named "newsletter"
  • Icon: simple SVG placeholder
  • When clicked → open a dialog (modal)
  1. Dialog Behavior: The dialog must contain input fields:
  • title (text input)
  • description (textarea)
  • tabs (dynamic list, user can add/remove tab items) Each tab item: - tabTitle - tabContent (HTML allowed)

Buttons:

  • Cancel
  • OK
  1. On OK:
  • Generate structured HTML block inside editor
  • Structure example:
  1. Behavior inside editor:
  1. MUST USE:
  • GeneralHtmlSupport (GHS) for allowing custom classes & attributes
  • Proper upcast / downcast converters
  • Widget API (toWidget, toWidgetEditable if needed)
  • Command class
  • UI Component system (ButtonView, View, InputTextView)
  • Editing & UI part separated
  • Schema registration properly
  1. Architecture required:

Create structure:

  • newsletter/
    • newsletterplugin.ts
    • newsletterediting.ts
    • newsletterui.ts
    • newslettercommand.ts
  1. Technical requirements:
  • Register schema element: newsletterBlock

  • Must allow: class id href data attributes

  • Use: editor.model.change() conversion.for('upcast') conversion.for('downcast')

  • Handle click event via editing view document

  • Use editing.view.document.on( 'click', ... )

  • Detect double click event

  1. Important: Do NOT use raw DOM manipulation. All updates must go through editor.model.

  2. Output required:

  • Full plugin code
  • Proper imports
  • Comments explaining architecture
  • Explain migration differences from CKEditor 4
  • Show how to register plugin in build
  1. Extra: Explain how to enable GeneralHtmlSupport configuration in editor config.

========================================

Please produce clean production-ready code. Do not simplify logic. Follow CKEditor 5 best practices strictly.