@elementor/editor-app-bar 4.3.0-986 → 4.3.0-988
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +62 -3
- package/dist/index.js +174 -95
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +171 -92
- package/dist/index.mjs.map +1 -1
- package/package.json +12 -12
- package/src/components/app-bar.tsx +41 -19
- package/src/components/locations/tools-menu-location.tsx +4 -4
- package/src/components/locations/utilities-menu-location.tsx +6 -6
- package/src/constants.ts +14 -0
- package/src/contexts/app-bar-size-context.tsx +14 -0
- package/src/hooks/use-container-width.ts +29 -0
- package/src/utils/get-max-toolbar-actions.ts +25 -0
package/README.md
CHANGED
|
@@ -55,7 +55,7 @@ import { EyeIcon } from '@elementor/icons';
|
|
|
55
55
|
import { __ } from '@wordpress/i18n';
|
|
56
56
|
|
|
57
57
|
integrationsMenu.registerToggleAction( {
|
|
58
|
-
|
|
58
|
+
id: 'my-custom-toggle',
|
|
59
59
|
useProps: () => {
|
|
60
60
|
const [ isSelected, setIsSelected ] = useState( false );
|
|
61
61
|
|
|
@@ -78,7 +78,7 @@ import { LinkIcon } from '@elementor/icons';
|
|
|
78
78
|
import { __ } from '@wordpress/i18n';
|
|
79
79
|
|
|
80
80
|
integrationsMenu.registerLink( {
|
|
81
|
-
|
|
81
|
+
id: 'my-custom-link',
|
|
82
82
|
props: {
|
|
83
83
|
title: __( 'My Custom Link', 'elementor' ),
|
|
84
84
|
icon: LinkIcon,
|
|
@@ -100,4 +100,63 @@ integrationsMenu.registerLink( {
|
|
|
100
100
|
|
|
101
101
|
### Custom Locations
|
|
102
102
|
|
|
103
|
-
|
|
103
|
+
In addition to the menus above, a few locations accept full custom React components via `injectInto*` functions:
|
|
104
|
+
|
|
105
|
+
- `injectIntoPageIndication` - Injects a component next to the document title, in the center of the app bar.
|
|
106
|
+
- `injectIntoResponsive` - Injects a component next to the responsive/breakpoints switcher, in the center of the app bar.
|
|
107
|
+
- `injectIntoPrimaryAction` - Injects a component next to the primary action (e.g. "Publish"/"Save"), on the right side of the app bar.
|
|
108
|
+
|
|
109
|
+
```tsx
|
|
110
|
+
import { injectIntoPageIndication } from '@elementor/editor-app-bar';
|
|
111
|
+
|
|
112
|
+
injectIntoPageIndication( {
|
|
113
|
+
id: 'my-custom-indication',
|
|
114
|
+
component: () => <div>Custom content</div>,
|
|
115
|
+
options: {
|
|
116
|
+
priority: 10, // Optional, lower value means higher priority. Default is 10.
|
|
117
|
+
},
|
|
118
|
+
} );
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
> [!NOTE]
|
|
122
|
+
> Both the menus (`registerAction`/`registerLink`/`registerToggleAction`) and the custom locations (`injectInto*`) are reactive:
|
|
123
|
+
> registering an item at any time (including after the editor has already loaded) will make it appear immediately, so
|
|
124
|
+
> plugins that load their scripts after the editor (e.g. Pro plugins, or third-party plugins) don't need to register
|
|
125
|
+
> before the app bar has rendered.
|
|
126
|
+
|
|
127
|
+
### Registering from outside this repository
|
|
128
|
+
|
|
129
|
+
Third-party plugins (e.g. Elementor Pro, or any WordPress plugin) can register items into the app bar without being
|
|
130
|
+
part of this monorepo's build, by depending on the `elementor-v2-editor-app-bar` script handle and using the
|
|
131
|
+
`elementorV2.editorAppBar` global (which is the same object exported from `@elementor/editor-app-bar`):
|
|
132
|
+
|
|
133
|
+
```php
|
|
134
|
+
add_action( 'elementor/editor/v2/scripts/enqueue', function () {
|
|
135
|
+
wp_enqueue_script(
|
|
136
|
+
'my-plugin-editor-app-bar',
|
|
137
|
+
plugins_url( 'assets/editor-app-bar.js', __FILE__ ),
|
|
138
|
+
[ 'elementor-v2-editor-app-bar', 'elementor-v2-ui', 'elementor-v2-icons' ],
|
|
139
|
+
'1.0.0',
|
|
140
|
+
true
|
|
141
|
+
);
|
|
142
|
+
} );
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
```js
|
|
146
|
+
// my-plugin-editor-app-bar.js
|
|
147
|
+
if ( window.elementorV2?.editorAppBar ) {
|
|
148
|
+
const { utilitiesMenu } = window.elementorV2.editorAppBar;
|
|
149
|
+
|
|
150
|
+
utilitiesMenu.registerLink( {
|
|
151
|
+
id: 'my-plugin-link',
|
|
152
|
+
props: {
|
|
153
|
+
title: 'My Plugin',
|
|
154
|
+
icon: MyIcon,
|
|
155
|
+
href: 'https://example.com',
|
|
156
|
+
},
|
|
157
|
+
} );
|
|
158
|
+
}
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
Make sure to always use `id` (not `name`) when registering menu items, and to guard the call with a check for
|
|
162
|
+
`window.elementorV2.editorAppBar`, since script load order across plugins is not guaranteed.
|