editor 是 AUP 跨设备 primitive,不是 Web Device 的 layout 组件,也不是 Web-only widget。它属于 AUP_PRIMITIVES 中的 18 个名称之一,并出现在每个 target 的 DeviceCaps.primitives map 中(取值为 native、webview、partial 或 unsupported)。
合同
| 字段 | 值 |
|---|---|
| Primitive 名称 | editor |
| 层级 | AUP 跨设备 primitive(AUP_PRIMITIVES) |
| 公共状态 | experimental |
| Document 能力 | native(renderer 存在;公开 sample 仅本地) |
| 共享 degradation chain | editor → input → text(unsupported 时) |
| 作者入口 | AUP tree / DSL · 通用 Markdown ::editor{…} |
| Document renderer / 备注 | renderer/primitives/editor.ts(textarea;仅当 AUP props 中布尔 true 时 readOnly) |
| Showcase 证据 | 使用 editor 节点的组合页 |
何时使用
在实现了 editor 的 target 上需要代码或长文编辑面时。
何时不要使用
不要从 docs 页承诺协作编辑、LSP、多人编辑或回写。
Sample 合同
| 字段 | 值 |
|---|---|
| 目的 | 诚实的 document-target editor 控件(仅本地 textarea) |
| 边界 | 无 LSP、无多人、无 AFS 写入、无 IDE 产品承诺 |
| 作者入口 | ::editor{…} 通用指令 |
| 表面 | Web Device document |
| 公共状态 | experimental |
| Fallback / 失败 | unsupported 时:chain 到 input → text;空 value → 空 textarea |
| 验证 | 下方路由 · arc --version = 2.0.0-beta.28 |
Document sample(本地 textarea)
document 注册了 editor renderer。下方 sample 是未绑定控件:输入只改变浏览器 textarea。Markdown 属性是字符串——不要假定 MD 的 readOnly=true 会像 AUP JSON 那样设置布尔 true。需要严格只读 props 时优先 AUP JSON/DSL。
源码:
::editor{id="docs-prim-editor" language="json" label="Example snippet" value="{ \"ok\": true }"}渲染:
::editor{id="docs-prim-editor" language="json" label="Example snippet" value="{ "ok": true }"}
AUP JSON 形状(需要布尔 readOnly 时):
{
"id": "snippet",
"type": "editor",
"props": {
"label": "Example",
"language": "json",
"readOnly": true,
"value": "{ \"ok\": true }\n"
}
}失败与限制
| 情形 | 预期结果 |
|---|---|
| 在 document sample 中输入 | 仅本地浏览器状态;无文档/AFS 写入 |
| 期望 LSP / 多人 | 超出合同 |
| unsupported target | 经 editor → input → text 降级 |
MD readOnly="true" 字符串 | 不保证等于 AUP 布尔 true |
验证证据
| 项 | 值 |
|---|---|
| 基线 | 2026-08-09 · arc --version → 2.0.0-beta.28 |
| 能力行 | docs/aup/capability-matrix.md(内部,不对外路由)· editor |
| 实现 | renderer/primitives/editor.ts;caps device-caps.ts;chain degradation.ts |
| 公开路由 | /en/docs/aup/primitives/editor/ · /zh/docs/aup/primitives/editor/ |
| 本地运行 | arc service start --blocklet blocklets/arcblock --port 4900 · 打开路由;输入保持本地 |
| 接受标准 | textarea 带种子值渲染;无网络写入;experimental 状态可见 |
证据锚点
| 项 | 值 |
|---|---|
| 注册表 | packages/aup/src/aup-types.ts · AUP_PRIMITIVES |
| Document caps | providers/runtime/web-device/src/device-caps.ts · DEVICE_CAPS_DOCUMENT |
| Degradation | packages/aup/src/degradation.ts · DEGRADATION_CHAINS |
| 内部矩阵 | docs/aup/capability-matrix.md(内部,不对外路由) |
| Taxonomy hub | Primitive 类型分类与证据 |
| Sample 合同规则 | Live 示例:范围与合同 |