脚本 编辑器为插件开发者提供了多个供应商和内部脚本。脚本名称、句柄和描述详见下表。 WordPress 脚本 编辑器包含多个功能包以实现不同功能。插件开发者可利用它们创建区块、编辑器插件或通用插件。 Script Name Handle Description Blob wp-blob Blob utilities Block Library wp-block-library Block library for the editor Blocks wp-blocks Block creations Block Serialization Default Parser wp-block-serialization-default-parser Default block serialization parser implementations for WordPress documents Block Serialization Spec Parser wp-block-serialization-spec-parser Grammar file (grammar.pegjs) for WordPress posts Components wp-components Generic components to be used for creating common UI elements Compose wp-compose Collection of handy Higher Order Components (HOCs) Core Data wp-core-data Simplify access to and manipulation of core WordPress entities Data wp-data Data module serves as a hub to manage application state for both plugins and WordPress itself Date wp-date Date module for WordPress Deprecated wp-deprecated Utility to log a message to notify developers about a deprecated feature Dom wp-dom DOM utilities module for WordPress Dom Ready wp-dom-ready Execute callback after the DOM is loaded Editor wp-editor Building blocks for WordPress editors Edit Post wp-edit-post Edit Post Module for WordPress Element wp-element Element is, quite simply, an abstraction layer atop React Escape Html wp-escape-html Escape HTML utils Hooks wp-hooks A lightweight and efficient EventManager for JavaScript Html Entities wp-html-entities HTML entity utilities for WordPress I18N wp-i18n Internationalization utilities for client-side localization Is Shallow Equal wp-is-shallow-equal A function for performing a shallow comparison between two objects or arrays Keycodes wp-keycodes Keycodes utilities for WordPress, used to check the key pressed in events like onKeyDown List Reusable blocks wp-list-reusable-blocks Package used to add import/export links to the listing page of the reusable blocks NUX wp-nux Components, and wp.data methods useful for onboarding a new user to the WordPress admin interface Plugins wp-plugins Plugins module for WordPress Redux Routine wp-redux-routine Redux middleware for generator coroutines Rich Text wp-rich-text Helper functions to convert HTML or a DOM tree into a rich text value and back Shortcode wp-shortcode Shortcode module for WordPress Token List wp-token-list Constructable, plain JavaScript DOMTokenList implementation, supporting non-browser runtimes URL wp-url A collection of utilities to manipulate URLs Viewport wp-viewport Module for responding to changes in the browser viewport size Wordcount wp-wordcount WordPress word count utility Vendor scripts The editor also uses some popular third-party packages and scripts. Plugin developers can use these scripts as well without bundling them in their code (and increasing file sizes). Script Name Handle Description React react React is a JavaScript library for building user interfaces React Dom react-dom Serves as the entry point to the DOM and server renderers for React, intended to be paired with React Moment moment Parse, validate, manipulate, and display dates and times in JavaScript Lodash lodash Lodash is a JavaScript library which provides utility functions for common programming tasks Polyfill scripts The editor also provides polyfills for certain features that may not be available in all modern browsers. It is recommended to use the main wp-polyfill script handle which takes care of loading all the below mentioned polyfills. Script Name Handle Description Babel Polyfill wp-polyfill Emulate a full ES2015+ environment. Main script to load all the below mentioned additional polyfills Fetch Polyfill wp-polyfill-fetch Polyfill that implements a subset of the standard Fetch specification Promise Polyfill wp-polyfill-promise Lightweight ES6 Promise polyfill for the browser and node Formdata Polyfill wp-polyfill-formdata Polyfill conditionally replaces the native implementation Node Contains Polyfill wp-polyfill-node-contains Polyfill for Node.contains Element Closest Polyfill wp-polyfill-element-closest Return the closest element matching a selector up the DOM tree 打包与代码共享 当使用像 webpack 这样的 JavaScript 打包工具时,此处提到的脚本可以从打包文件中排除,并通过 WordPress 以脚本依赖项的形式提供,参见 wp_enqueue_script。 @wordpress/dependency-extraction-webpack-plugin 提供了一个 webpack 插件,用于帮助从打包文件中提取 WordPress 依赖项。 @wordpress/scripts 的 build 脚本默认已包含此插件。