块编辑器开发文档

@wordpress/edit-post

💡 云策文档标注

概述

@wordpress/edit-post 是 WordPress 核心的编辑文章模块,用于扩展文章编辑器的用户界面。它提供了 API 来初始化和配置编辑器实例,以及一系列插件组件来集成自定义功能。

关键要点

  • 该包主要用于 WordPress 核心,但也可在自有项目中使用,但可能缺乏完整文档。
  • 安装需通过 npm install @wordpress/edit-post,并确保运行环境支持 ES2015+,否则需包含 polyfill。
  • 扩展编辑器 UI 可通过 registerPlugin API 实现,允许在单处定义所有插件 UI 元素。
  • 导出的组件可通过全局变量 wp.editPost 访问,当定义 wp-edit-post 为脚本依赖时。
  • API 包括 initializeEditor 用于初始化编辑器实例,以及多个插件组件如 PluginBlockSettingsMenuItem、PluginDocumentSettingPanel 等。
  • reinitializeEditor 已弃用,store 定义了编辑文章命名空间的存储。
  • 该包是 Gutenberg 项目的一部分,采用 monorepo 结构,贡献需参考项目指南。

📄 原文内容

Edit Post Module for WordPress.

This package is meant to be used only with WordPress core. Feel free to use it in your own project but please keep in mind that it might never get fully documented.

Installation

Install the module

npm install @wordpress/edit-post

This package assumes that your code will run in an ES2015+ environment. If you’re using an environment that has limited or no support for such language features and APIs, you should include the polyfill shipped in @wordpress/babel-preset-default in your code.

Extending the post editor UI

Extending the editor UI can be accomplished with the registerPlugin API, allowing you to define all your plugin’s UI elements in one place.

Refer to the plugins module documentation for more information.

The components exported through the API can be used with the registerPlugin (see documentation) API.
They can be found in the global variable wp.editPost when defining wp-edit-post as a script dependency.

API

initializeEditor

Initializes and returns an instance of Editor.

Parameters

  • id string: Unique identifier for editor instance.
  • postType string: Post type of the post to edit.
  • postId Object: ID of the post to edit.
  • settings ?Object: Editor settings object.
  • initialEdits Object: Programmatic edits to apply initially, to be considered as non-user-initiated (bypass for unsaved changes prompt).

PluginBlockSettingsMenuItem

Related

  • PluginBlockSettingsMenuItem in @wordpress/editor package.

PluginDocumentSettingPanel

Related

  • PluginDocumentSettingPanel in @wordpress/editor package.

PluginMoreMenuItem

Related

  • PluginMoreMenuItem in @wordpress/editor package.

PluginPostPublishPanel

Related

  • PluginPostPublishPanel in @wordpress/editor package.

PluginPostStatusInfo

Related

  • PluginPostStatusInfo in @wordpress/editor package.

PluginPrePublishPanel

Related

  • PluginPrePublishPanel in @wordpress/editor package.

PluginSidebar

Related

  • PluginSidebar in @wordpress/editor package.

PluginSidebarMoreMenuItem

Related

  • PluginSidebarMoreMenuItem in @wordpress/editor package.

reinitializeEditor

Used to reinitialize the editor after an error. Now it’s a deprecated noop function.

store

Store definition for the edit post namespace.

Related

Type

  • Object

Contributing to this package

This is an individual package that’s part of the Gutenberg project. The project is organized as a monorepo. It’s made up of multiple self-contained software packages, each with a specific purpose. The packages in this monorepo are published to npm and used by WordPress as well as other software projects.

To find out more about contributing to this package or Gutenberg as a whole, please read the project’s main contributor guide.