datocms-plugin
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseDatoCMS Plugin
DatoCMS插件
Plugin development workflow. Patch existing plugins in place; scaffold only when no plugin exists or the user asks for a new project.
插件开发工作流。直接修补现有插件;仅当不存在插件或用户要求创建新项目时才搭建脚手架。
Workflow
工作流
- Inspect silently:
- , package manager, scripts, plugin metadata, and installed SDK/UI versions
package.json - top-level call, usually
connect()orsrc/main.tsxsrc/index.tsx - touched hook pair, render component, helper, CSS file, and current UI pattern
- plugin-local if present
AGENTS.md
- Classify the request:
- Existing plugin: package already exists and user asks to patch, add, maintain, fix, release-prep, or restyle. Default here.
- New plugin: user asks to create/scaffold/bootstrap a plugin folder, or no plugin project exists.
- Design pass: request mentions styling, layout, density, spacing, theme, dark mode, Canvas tokens, legacy CSS variables, hardcoded colors, forms, tables, panels, controls, or matching DatoCMS UI patterns.
- Mixed: combine hook/scaffold work with design changes in one pass.
- Ask only when inspection cannot resolve a behavior-changing choice:
- plugin/folder name for a new scaffold
- private vs marketplace plugin when package metadata changes
- target model/field/surface when several are plausible
- whether a new permission or dependency is allowed
- whether direct browser CMA calls are required instead of SDK helpers
- Load references after file inspection. Use the reference for the touched surface; do not load the full bundle.
- Patch in place:
- keep the existing file layout, package manager, scripts, naming, and UI structure
- update paired hooks together: declaration + render, trigger + modal, dropdown declaration + execute handler
- update permissions and package metadata in the same patch when the code path needs them
- add dependencies only when the implementation imports them
- Verify with the plugin's existing command. Prefer the build script; add typecheck, lint, or tests only when the project already defines them and they cover the change.
- Report the patch, command result, and remaining DatoCMS check: config save, field render, modal resolve, asset select, permission branch, page navigation, or resize behavior.
- 静默检查:
- 、包管理器、脚本、插件元数据,以及已安装的SDK/UI版本
package.json - 顶层调用,通常位于
connect()或src/main.tsxsrc/index.tsx - 关联的钩子对、渲染组件、工具函数、CSS文件,以及当前UI模式
- 若存在则检查插件本地的
AGENTS.md
- 对请求进行分类:
- 现有插件:包已存在,用户要求修补、添加功能、维护、修复、准备发布或重新设计。默认采用此流程。
- 新插件:用户要求创建/搭建/初始化插件文件夹,或不存在插件项目。
- 设计优化:请求提及样式、布局、密度、间距、主题、深色模式、Canvas令牌、旧版CSS变量、硬编码颜色、表单、表格、面板、控件,或匹配DatoCMS UI模式。
- 混合需求:在一次处理中结合钩子/脚手架开发与设计变更。
- 仅当检查无法确定影响行为的选择时才询问用户:
- 新脚手架的插件/文件夹名称
- 包元数据变更时选择私有插件还是市场插件
- 当多个目标模型/字段/界面都合理时,确认目标对象
- 是否允许新增权限或依赖
- 是否需要直接调用浏览器端CMA而非使用SDK工具函数
- 文件检查完成后加载参考资料。仅加载与涉及界面相关的参考资料,无需加载完整包。
- 原地修补:
- 保留现有文件结构、包管理器、脚本、命名规则和UI结构
- 同步更新成对的钩子:声明+渲染、触发+模态框、下拉声明+执行处理函数
- 当代码路径需要时,在同一次修补中更新权限和包元数据
- 仅当实现需要导入时才添加依赖
- 使用插件现有命令验证。优先使用构建脚本;仅当项目已定义类型检查、 lint或测试且覆盖变更内容时,才执行这些操作。
- 报告修补内容、命令结果,以及剩余的DatoCMS验证项:配置保存、字段渲染、模态框解析、资源选择、权限分支、页面导航或 resize行为。
Reference map
参考资料映射
Common
通用
| Need | Load |
|---|---|
| Follow-up maintenance shortcuts | |
| Hook pairs, render conventions, sizing reminder | |
Exact | |
Base | |
| Target code has no clear precedent | |
| Plugin permission changes | |
| Localized values, field paths, Structured Text Slate form values | |
| 需求 | 加载资料 |
|---|---|
| 后续维护快捷方式 | |
| 钩子对、渲染约定、尺寸提醒 | |
精确的 | |
基础 | |
| 目标代码无明确先例 | |
| 插件权限变更 | |
| 本地化值、字段路径、结构化文本Slate表单值 | |
New plugin
新插件
| Need | Load |
|---|---|
| Project files and package baseline | |
| First hook pair selection | |
| 需求 | 加载资料 |
|---|---|
| 项目文件和包基准 | |
| 首个钩子对选择 | |
Surfaces
界面类型
| Surface | Load |
|---|---|
| Config screen | |
| Field extension | |
| Sidebar panel or full record sidebar | |
| Custom page | |
| Dropdown action | |
| Lifecycle hook | |
| Modal | |
| Outlet | |
| Inspector | |
| Asset source | |
| Upload sidebar or upload panel | |
| Structured Text customization | |
| Record presentation or picker query | |
| 界面 | 加载资料 |
|---|---|
| 配置界面 | |
| 字段扩展 | |
| 侧边栏面板或完整记录侧边栏 | |
| 自定义页面 | |
| 下拉操作 | |
| 生命周期钩子 | |
| 模态框 | |
| 输出口 | |
| 检查器 | |
| 资源源 | |
| 上传侧边栏或上传面板 | |
| 结构化文本定制 | |
| 记录展示或选择器查询 | |
Design
设计
| Need | Load |
|---|---|
| Dark-mode-only migration | |
| First design pass | |
| Token/variable lookup | |
| Layouts, pages, split views, toolbars | |
| Forms, controls, settings | |
| Dropdowns, tabs, tables, lists, notices | |
| Surface shell rules | |
| Raw CSS fallback snippets | |
For design work, prefer public components when they match the required shape. Fall back to local React/CSS only when public components do not express the layout cleanly. Use Canvas tokens and variables directly; customize beyond them only for explicit product styling, vendor widgets, media treatments, data visualization, or effects they cannot express.
datocms-react-ui| 需求 | 加载资料 |
|---|---|
| 仅深色模式迁移 | |
| 首次设计优化 | |
| 令牌/变量查询 | |
| 布局、页面、拆分视图、工具栏 | |
| 表单、控件、设置 | |
| 下拉菜单、标签页、表格、列表、通知 | |
| 界面外壳规则 | |
| 原始CSS备用代码片段 | |
进行设计工作时,若公共组件符合需求形态,优先使用。仅当公共组件无法清晰实现布局时,才退而使用本地React/CSS。直接使用Canvas令牌和变量;仅在明确的产品样式、供应商组件、媒体处理、数据可视化或令牌无法实现的效果场景下,才进行定制。
datocms-react-uiGuardrails
约束规则
- Keep exactly one top-level call.
connect() - Inspect existing before adding hooks.
connect() - Import once in the plugin entry file.
datocms-react-ui/styles.css - Wrap every rendered surface in .
<Canvas ctx={ctx}> - Use for pages, inspectors, and full-width sidebars.
<Canvas ctx={ctx} noAutoResizer> - Use for ID-dispatched render hooks.
switch - Use for SDK types.
import type { ... } - Guard before reading saved-record data.
ctx.item - Use in field extensions; use localized-value helpers elsewhere.
get(ctx.formValues, ctx.fieldPath) - Use deep-compare effects when depending on object properties.
ctx - Keep parameters and
ctx.openModal()values JSON-serializable.ctx.resolve() - Normalize stored plugin parameters at read/save boundaries.
- Use directly in
ctx.setParameters().renderManualFieldExtensionConfigScreen - Do not create editor field extensions for modular content, single block, or Structured Text fields; use addon extensions instead.
- Prefer SDK helpers before browser CMA calls. If browser CMA is required, use , add only required permissions, and guard missing
@datocms/cma-client-browser.ctx.currentUserAccessToken - Keep modals, sidebars, and config screens compact.
- 仅保留一个顶层调用。
connect() - 添加钩子前先检查现有。
connect() - 在插件入口文件中仅导入一次。
datocms-react-ui/styles.css - 将每个渲染的界面包裹在中。
<Canvas ctx={ctx}> - 页面、检查器和全宽侧边栏使用。
<Canvas ctx={ctx} noAutoResizer> - 对ID调度的渲染钩子使用语句。
switch - 对SDK类型使用。
import type { ... } - 读取已保存记录数据前先校验。
ctx.item - 在字段扩展中使用;在其他地方使用本地化值工具函数。
get(ctx.formValues, ctx.fieldPath) - 依赖对象属性时使用深度比较副作用。
ctx - 保持参数和
ctx.openModal()值可JSON序列化。ctx.resolve() - 在读取/保存边界处规范化存储的插件参数。
- 在中直接使用
renderManualFieldExtensionConfigScreen。ctx.setParameters() - 不要为模块化内容、单个块或结构化文本字段创建编辑器字段扩展;改用附加扩展。
- 优先使用SDK工具函数而非浏览器端CMA调用。若必须使用浏览器端CMA,使用,仅添加必要权限,并校验缺失的
@datocms/cma-client-browser。ctx.currentUserAccessToken - 保持模态框、侧边栏和配置界面紧凑。
Routing
路由规则
- Standalone CMA scripts, schema imports, record operations, or migrations outside a plugin iframe -> or
datocms-cma.datocms-cli - Website preview, Content Link, draft mode, cache tags, frontend rendering, or framework setup -> or
datocms-frontend-integrations.datocms-setup - Content modeling decisions -> .
datocms-content-modeling - Content delivery GraphQL query work -> .
datocms-cda
- 插件iframe外的独立CMA脚本、 schema导入、记录操作或迁移 -> 转至或
datocms-cma处理。datocms-cli - 网站预览、内容链接、草稿模式、缓存标签、前端渲染或框架配置 -> 转至或
datocms-frontend-integrations处理。datocms-setup - 内容建模决策 -> 转至处理。
datocms-content-modeling - 内容交付GraphQL查询工作 -> 转至处理。
datocms-cda