@elementor/editor-app-bar

中文文档
4.4.1发布于 2026/11/16GPL-3.0-or-laterTypeScriptESM + CJS构建来源已验证近 30 天下载 1.1万

@ lementor/ editor 的 App 扩展栏

中文使用文档
文档目录4 节
  1. 使用量
  2. 菜单
  3. 自定义位置
  4. 从此仓库外部注册

编辑器 App 栏

[尖叫声] 请不要访问或依赖从双下划线开始的功能和变量,因为这些功能和变量无须通知即可更改. 双下划线命名公约__)作为一个前缀,用于表示某个函数或变量是用于内部使用的,不应被第三方开发者访问或依赖.

使用量

菜单

菜单有5个类型:

  • mainMenu - 提供对应用程序主要功能和功能的检索。 代表的是一个改变为汉堡的元素标志.
  • toolsMenu - 一个菜单,用户可以访问各种编辑工具(如"添加部件","结构"等),以某种方式来操纵数据或接口. 这个 区域可能包含有限数量的通用工具按钮,以及用于访问额外工具的下拉菜单 这些.
  • utilitiesMenu - 菜单,用户可以访问与主功能不直接相关的各种功能 应用程序的功能。 这可能包括访问查找者、获得帮助或访问其他杂项功能的选项.
  • documentOptionsMenu - 菜单,用户可以访问保存文档的各种选项。 这可能包括: 选项,用于保存为与文档相关的草稿或条件选项(如"显示条件"等).
  • integrationsMenu - 一个子菜单里面 mainMenu ,用户可以访问各种选项来整合其他服务. 这可能 包括连接第三方服务或访问其他杂项功能的选项.

每个菜单包含一个项目列表,每个项目可以是:

  • Action - 执行动作的按钮.
  • Link - 连接到另一页的链接.
  • ToggleAction - 一个在两个州之间切换的按钮(检查或不加控制).

让我们延伸 integrationsMenu 以多个实例涵盖所有类型项目:

行动

import { integrationsMenu } from '@elementor/editor-app-bar';
import { PlusIcon } from '@elementor/icons';
import { __ } from '@wordpress/i18n';

integrationsMenu.registerAction( {
    id: 'example-action-id',
    props: {
        title: __( 'My Custom Action', 'elementor' ),
        icon: PlusIcon, // A react component that renders an SVG icon
        disabled: false, // Optional
        onClick: () => alert( 'Custom action triggered!' ), // Optional
    }
} );    

切换动作

import { integrationsMenu } from '@elementor/editor-app-bar';
import { EyeIcon } from '@elementor/icons';
import { __ } from '@wordpress/i18n';

integrationsMenu.registerToggleAction( {
    id: 'my-custom-toggle',
    useProps: () => {
        const [ isSelected, setIsSelected ] = useState( false );

        return {
            title: __( 'My Custom Toggle', 'elementor' ),
            icon: EyeIcon,
            selected: isSelected, // Optional
            onClick: () => setIsSelected( ( prev ) => ! prev ), // Optional
            disabled: false, // Optional
        };
    },
} );
import { integrationsMenu } from '@elementor/editor-app-bar';
import { LinkIcon } from '@elementor/icons';
import { __ } from '@wordpress/i18n';

integrationsMenu.registerLink( {
    id: 'my-custom-link',
    props: {
        title: __( 'My Custom Link', 'elementor' ),
        icon: LinkIcon,
        href: 'https://elementor.com', // Optional
        target: '_blank', // Optional
    },
} );

[注] 你也可以用这个 props 或者说 useProps (视需要而定)所有物品类型:

  • props - 带动作道具的物体.
  • useProps - 一个反应钩子,可以返回动作道具,让你使道具具有反应性.

[注] 这个 icon 属性可以是使 SVG 图标成为任何 React 组件,建议使用 SVGIcon 从 @elementor/ui

自定义位置

除了上面的菜单外,少数地点接受完整的自定义 React 组件通过 injectInto* 函数:

  • injectIntoPageIndication - 在文档标题旁边的应用程序栏中心注入一个组件.
  • injectIntoResponsive - 在应用程序栏中央插入一个响应/断点切换器旁边的组件.
  • injectIntoPrimaryAction - 在应用程序栏的右侧注入初级动作旁边的组件(如"publish"/"Save").
import { injectIntoPageIndication } from '@elementor/editor-app-bar';

injectIntoPageIndication( {
    id: 'my-custom-indication',
    component: () => <div>Custom content</div>,
    options: {
        priority: 10, // Optional, lower value means higher priority. Default is 10.
    },
} );

[注] 两种菜单(registerAction编号 :registerLink编号 :registerToggleAction)和自定义位置(injectInto*反应性: 在任何时间(包括编辑器已经装入之后)注册某个项目都会使它立即出现,所以 在编辑器后加载脚本的插件( 如 Pro 插件, 或第三方插件) 不需要注册 在应用栏打开之前.

从此仓库外部注册

第三方插件(如 Elementor Pro,或任何 WordPress 插件)可以将项目注册到应用栏中而不成为 单人建筑的一部分 取决于 elementor-v2-editor-app-bar 脚本处理和使用 elementorV2.editorAppBar global(即从 @elementor/editor-app-bar:

add_action( 'elementor/editor/v2/scripts/enqueue', function () {
    wp_enqueue_script(
        'my-plugin-editor-app-bar',
        plugins_url( 'assets/editor-app-bar.js', __FILE__ ),
        [ 'elementor-v2-editor-app-bar', 'elementor-v2-ui', 'elementor-v2-icons' ],
        '1.0.0',
        true
    );
} );
// my-plugin-editor-app-bar.js
if ( window.elementorV2?.editorAppBar ) {
    const { utilitiesMenu } = window.elementorV2.editorAppBar;

    utilitiesMenu.registerLink( {
        id: 'my-plugin-link',
        props: {
            title: 'My Plugin',
            icon: MyIcon,
            href: 'https://example.com',
        },
    } );
}

确保永远使用 id (无) name登记菜单项目时,并用支票保护电话 window.elementorV2.editorAppBar,因为无法保证整个插件的脚本加载顺序.

版本与发布记录

@elementor/editor-app-bar 共发布 1,185 个版本,首次发布于 2023/04/30;过去 12 个月发布了 858 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
4.4.1latest2026/11/16今天
4.5.0-1192build2026/11/16今天
4.5.0-11912026/11/16今天
4.5.0-11902026/11/16今天
4.5.0-11892026/11/16今天
4.5.0-11882026/11/151 天前

其他发布通道:manual → 4.1.0-manual,4.2-beta1 → 4.2.0-beta1,beta → 4.4.0-beta3,build → 4.5.0-1192。

关于 @elementor/editor-app-bar 的常见问题

@elementor/editor-app-bar 是什么?

@ lementor/ editor 的 App 扩展栏

如何安装 @elementor/editor-app-bar?

在项目目录运行 npm install @elementor/editor-app-bar,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react(^18.3.1)、react-dom(^18.3.1)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@elementor/editor-app-bar 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@elementor/editor-app-bar 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@elementor/editor-app-bar 可以商用吗?

@elementor/editor-app-bar 使用 GPL-3.0-or-later 许可。强 Copyleft:分发包含该代码的软件时,整个作品需以 GPL-3.0 兼容许可开源,并附带专利与反锁定条款。仅内部使用不触发此义务。以上为概括,不构成法律意见,请以许可原文为准。

@elementor/editor-app-bar 的下载量有多少?

根据 npm 官方下载统计,@elementor/editor-app-bar 在 2026/10/14 – 2026/11/12 这 30 天内被下载 11,370 次,日均约 379 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@elementor/editor-app-bar 还在维护吗?

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