实例方法
createClassicEditor() 返回的 ClassicEditor 是 CMS 应用主要操作界面。
| 方法 | 返回与行为 |
|---|---|
| getData() | string,规范 HTML |
| setData(source) | 更新规范内容 |
| focus() | 返回编辑区焦点 |
| setReadonly(value) | 改变只读状态 |
| setWorkspaceView(view) | void 或 Promise,调用时统一 await |
| save() / retrySave() | Promise,需配置保存适配器 |
| destroy() | Promise,释放实例资源 |
销毁后不能继续操作实例。低层命令与服务通过 classic.editor 的公开接口访问,不读取私有字段。
可运行代码
ts
export async function withHost(host: HTMLElement) {
const editor = await createClassicEditor(host, { data: '<p>Hello</p>' });
editor.setData('<p>Updated</p>');
const html = editor.getData();
editor.setReadonly(true);
await editor.destroy(); // Before removing the host element.
return html;
}此代码使用发布版类型检查;完整导入说明见入口与类型。