块编辑器开发文档

@wordpress/interactivity

💡 云策文档标注

概述

@wordpress/interactivity 包提供了 Interactivity API 的核心逻辑,该 API 自 WordPress Core v6.5 起已内置。在 WordPress 环境中,此包已捆绑在 Core 中,无需额外安装;在外部使用时需通过 npm 安装。

关键要点

  • Interactivity API 自 WordPress Core v6.5 起引入,@wordpress/interactivity 包已内置在 Core 中。
  • 在 WordPress 外部使用 Interactivity API 时,需通过 npm install @wordpress/interactivity --save 命令安装。
  • 在 WordPress 内部使用时,确保脚本模块的依赖数组中包含 @wordpress/interactivity,通常由 wp-scripts 等工具自动处理。
  • 此包要求运行环境支持 ES2015+,否则需包含 @wordpress/babel-preset-default 中的 polyfill。
  • Interactivity API 遵循 GNU General Public License v2 或更高版本,详细信息见 LICENSE.md。

📄 原文内容

The package @wordpress/interactivity contains the logic that enables the Interactivity API which was introduced in WordPress Core in v6.5. This means this package is already bundled in Core in any version of WordPress higher than v6.5.

Check the Interactivity API Reference docs in the Block Editor handbook to learn more about the Interactivity API.

Installation

Install the Interactivity API using the command:

npm install @wordpress/interactivity --save

This step is only required if you use the Interactivity API outside WordPress.

Within WordPress, the package is already bundled in Core. To ensure it’s loaded, add @wordpress/interactivity to the dependency array of the script module. This process is often done automatically with tools like wp-scripts.

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

License

Interactivity API proposal, as part of Gutenberg and the WordPress project is free software, and is released under the terms of the GNU General Public License version 2 or (at your option) any later version. See LICENSE.md for complete license.