@automattic/jetpack-shared-extension-utils

中文文档
2.1.8发布于 2026/11/06GPL-2.0-or-laterCommonJS构建来源已验证近 30 天下载 2148

Utility functions used by the block editor extensions

原始使用文档
文档目录8 节
  1. Fetching modules data from the store
  2. Basic Usage
  3. How to install shared-extension-utils
  4. Installation From Git Repo
  5. Contribute
  6. Get Help
  7. Security
  8. License

Shared Extension Utilities

Utility functions used by the block editor extensions.

This package is the new home for the code in the extensions/shared directory of the Jetpack plugin, so that plugins can share it. To begin with, we moving the code used by the Publicize editor extension, but the goal is to bring over all the shared code.

Fetching modules data from the store

The package relies on controls and resolvers to pull modules data from the API, and put it into the package's Redux store.

Basic Usage

In order to have all modules related data synced within different packages, let's use this Redux store as a source of truth, for both, getting and updating the data.

Use withSelect, withDispatch higher-order component to pull the data or useSelect hook to pull the data from the store to pull directly in component. Example:

// Imports.
import { withSelect, withDispatch } from '@wordpress/data';
import { JETPACK_MODULES_STORE_ID } from '@automattic/jetpack-shared-extension-utils';

const SampleComponent = props => {
    const { isModuleActive, isLoadingModules, isChangingStatus, updateJetpackModuleStatus } = props;

    if ( isModuleActive ) {
        return <div>Module is active</div>;
    }

    if ( isLoadingModules ) {
        return <div>Loading modules...</div>;
    }
    
    if ( !isModuleActive ) {
        return <button onClick={ () => updateJetpackModuleStatus( 'contact-form', true ) }>
            Activate module
        </button>;
    }

    return <div>Active contact form module</div>;
}

// We wrap `SampleComponent` into the composition of `withSelect` and `withDispatch` HOCs,
// which will pull the data from the store and pass as a parameter into the component.
// Jetpack modules will be pulled after first selection `isModuleActive`.
export default compose( [
    withSelect( ( select, props ) => {
        const { isModuleActive, areModulesLoading, isModuleUpdating } = select( 'jetpack-modules' );
        return {
            isModuleActive: isModuleActive( 'contact-form' ),
            isLoadingModules: areModulesLoading(),
            isChangingStatus: isModuleUpdating( 'contact-form' ),
        };
    } ),
    withDispatch( dispatch => {
        const { updateJetpackModuleStatus } = dispatch( 'jetpack-modules' );
        return { updateJetpackModuleStatus };
    } ),
] )( ( SampleComponent ) );

How to install shared-extension-utils

Installation From Git Repo

Contribute

Get Help

Security

Need to report a security vulnerability? Go to https://automattic.com/security/ or directly to our security bug bounty site https://hackerone.com/automattic.

License

shared-extension-utils is licensed under GNU General Public License v2 (or later)

版本与发布记录

@automattic/jetpack-shared-extension-utils 共发布 265 个版本,首次发布于 2022/02/10;过去 12 个月发布了 82 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
2.1.8latest2026/11/061 天前
2.1.72026/11/053 天前
2.1.62026/11/035 天前
2.1.52026/10/2910 天前
2.1.42026/10/2612 天前
2.1.32026/10/2118 天前

关于 @automattic/jetpack-shared-extension-utils 的常见问题

@automattic/jetpack-shared-extension-utils 是什么?

Utility functions used by the block editor extensions

如何安装 @automattic/jetpack-shared-extension-utils?

在项目目录运行 npm install @automattic/jetpack-shared-extension-utils,或使用 pnpm add / yarn add / bun add。

@automattic/jetpack-shared-extension-utils 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/automattic__jetpack-shared-extension-utils 是否存在。

@automattic/jetpack-shared-extension-utils 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@automattic/jetpack-shared-extension-utils 可以商用吗?

@automattic/jetpack-shared-extension-utils 使用 GPL-2.0-or-later 许可。强 Copyleft:分发包含该代码的软件时,整个作品需以兼容的 GPL 许可开源。仅在内部使用、不对外分发时不触发此义务。以上为概括,不构成法律意见,请以许可原文为准。

@automattic/jetpack-shared-extension-utils 的下载量有多少?

根据 npm 官方下载统计,@automattic/jetpack-shared-extension-utils 在 2026/10/07 – 2026/11/05 这 30 天内被下载 2,148 次,日均约 72 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@automattic/jetpack-shared-extension-utils 还在维护吗?

最新版本 2.1.8 发布于 2026/11/06(1 天前);至今共发布 265 个版本,其中过去 12 个月发布了 82 个;首次发布于 2022/02/10。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。