@elementor/editor-app-bar 0.1.0
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/LICENSE +674 -0
- package/README.md +5 -0
- package/dist/index.d.ts +234 -0
- package/dist/index.js +1047 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +1017 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +50 -0
- package/src/components/__tests__/top-bar.test.tsx +15 -0
- package/src/components/actions/action.tsx +33 -0
- package/src/components/actions/link.tsx +33 -0
- package/src/components/actions/toggle-action.tsx +35 -0
- package/src/components/app-bar.tsx +37 -0
- package/src/components/locations/__tests__/locations-components.test.tsx +37 -0
- package/src/components/locations/__tests__/menus.test.tsx +89 -0
- package/src/components/locations/main-menu-location.tsx +50 -0
- package/src/components/locations/page-indication-location.tsx +9 -0
- package/src/components/locations/primary-action-location.tsx +9 -0
- package/src/components/locations/responsive-location.tsx +9 -0
- package/src/components/locations/tools-menu-location.tsx +26 -0
- package/src/components/locations/utilities-menu-location.tsx +35 -0
- package/src/components/ui/popover-menu-item.tsx +39 -0
- package/src/components/ui/popover-menu.tsx +23 -0
- package/src/components/ui/toolbar-logo.tsx +80 -0
- package/src/components/ui/toolbar-menu-item.tsx +18 -0
- package/src/components/ui/toolbar-menu-more.tsx +29 -0
- package/src/components/ui/toolbar-menu-toggle-item.tsx +18 -0
- package/src/components/ui/toolbar-menu.tsx +15 -0
- package/src/contexts/menu-context.tsx +20 -0
- package/src/extensions/documents-indicator/components/__tests__/settings-button.test.tsx +46 -0
- package/src/extensions/documents-indicator/components/settings-button.tsx +43 -0
- package/src/extensions/documents-indicator/index.ts +12 -0
- package/src/extensions/documents-preview/hooks/__tests__/use-document-preview-props.test.ts +43 -0
- package/src/extensions/documents-preview/hooks/use-action-props.ts +17 -0
- package/src/extensions/documents-preview/index.ts +10 -0
- package/src/extensions/documents-save/components/__tests__/primary-action-menu.test.tsx +41 -0
- package/src/extensions/documents-save/components/__tests__/primary-action.test.tsx +176 -0
- package/src/extensions/documents-save/components/primary-action-menu.tsx +48 -0
- package/src/extensions/documents-save/components/primary-action.tsx +79 -0
- package/src/extensions/documents-save/hooks/__tests__/use-document-save-draft-props.test.ts +64 -0
- package/src/extensions/documents-save/hooks/__tests__/use-document-save-template-props.test.ts +27 -0
- package/src/extensions/documents-save/hooks/use-document-save-draft-props.ts +16 -0
- package/src/extensions/documents-save/hooks/use-document-save-template-props.ts +14 -0
- package/src/extensions/documents-save/index.ts +26 -0
- package/src/extensions/elements/hooks/__tests__/use-action-props.test.ts +33 -0
- package/src/extensions/elements/hooks/use-action-props.ts +15 -0
- package/src/extensions/elements/index.ts +13 -0
- package/src/extensions/elements/sync/__tests__/sync-panel-title.test.ts +92 -0
- package/src/extensions/elements/sync/sync-panel-title.ts +47 -0
- package/src/extensions/finder/hooks/__tests__/use-action-props.test.ts +36 -0
- package/src/extensions/finder/hooks/use-action-props.ts +18 -0
- package/src/extensions/finder/index.ts +10 -0
- package/src/extensions/help/index.ts +18 -0
- package/src/extensions/history/hooks/__tests__/use-action-props.test.ts +33 -0
- package/src/extensions/history/hooks/use-action-props.ts +15 -0
- package/src/extensions/history/index.ts +10 -0
- package/src/extensions/index.ts +34 -0
- package/src/extensions/keyboard-shortcuts/hooks/__tests__/use-action-props.test.ts +20 -0
- package/src/extensions/keyboard-shortcuts/hooks/use-action-props.ts +12 -0
- package/src/extensions/keyboard-shortcuts/index.ts +11 -0
- package/src/extensions/site-settings/components/__tests__/portalled-primary-action.test.tsx +94 -0
- package/src/extensions/site-settings/components/__tests__/primary-action.test.tsx +100 -0
- package/src/extensions/site-settings/components/portal.tsx +27 -0
- package/src/extensions/site-settings/components/portalled-primary-action.tsx +11 -0
- package/src/extensions/site-settings/components/primary-action.tsx +32 -0
- package/src/extensions/site-settings/hooks/__tests__/use-action-props.test.ts +49 -0
- package/src/extensions/site-settings/hooks/use-action-props.ts +22 -0
- package/src/extensions/site-settings/index.ts +18 -0
- package/src/extensions/structure/hooks/__tests__/use-action-props.test.ts +33 -0
- package/src/extensions/structure/hooks/use-action-props.ts +16 -0
- package/src/extensions/structure/index.ts +10 -0
- package/src/extensions/theme-builder/hooks/__tests__/use-action-props.test.ts +22 -0
- package/src/extensions/theme-builder/hooks/use-action-props.ts +12 -0
- package/src/extensions/theme-builder/index.ts +9 -0
- package/src/extensions/user-preferences/hooks/__tests__/use-action-props.test.ts +34 -0
- package/src/extensions/user-preferences/hooks/use-action-props.ts +16 -0
- package/src/extensions/user-preferences/index.ts +10 -0
- package/src/extensions/wordpress/index.ts +21 -0
- package/src/index.ts +13 -0
- package/src/init.ts +15 -0
- package/src/locations/__tests__/menus.test.tsx +229 -0
- package/src/locations/consts.ts +4 -0
- package/src/locations/index.ts +29 -0
- package/src/locations/menus.tsx +141 -0
- package/src/sync/__tests__/redirect-old-menus.test.ts +34 -0
- package/src/sync/redirect-old-menus.ts +9 -0
- package/src/types.ts +3 -0
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { createMenu } from '../menus';
|
|
3
|
+
import { act, fireEvent, render } from '@testing-library/react';
|
|
4
|
+
import { createMockMenuAction, createMockMenuLink, createMockMenuToggleAction } from 'test-utils';
|
|
5
|
+
|
|
6
|
+
describe( '@elementor/editor-app-bar - Menus API', () => {
|
|
7
|
+
it( 'should create a menu with default group when not provided', () => {
|
|
8
|
+
// Act.
|
|
9
|
+
const menu = createMenu( {
|
|
10
|
+
name: 'test',
|
|
11
|
+
} );
|
|
12
|
+
|
|
13
|
+
menu.registerAction( createMockMenuAction() );
|
|
14
|
+
|
|
15
|
+
const { getByRole } = renderMenu( menu );
|
|
16
|
+
|
|
17
|
+
// Assert.
|
|
18
|
+
expect( getByRole( 'button' ) ).toBeInTheDocument();
|
|
19
|
+
} );
|
|
20
|
+
|
|
21
|
+
it( 'should create a menu with groups and append a default group', () => {
|
|
22
|
+
// Act.
|
|
23
|
+
const menu = createMenu( {
|
|
24
|
+
name: 'test',
|
|
25
|
+
groups: [ 'testGroup' ],
|
|
26
|
+
} );
|
|
27
|
+
|
|
28
|
+
menu.registerAction( createMockMenuAction() );
|
|
29
|
+
|
|
30
|
+
menu.registerLink( {
|
|
31
|
+
...createMockMenuLink(),
|
|
32
|
+
group: 'testGroup',
|
|
33
|
+
} );
|
|
34
|
+
|
|
35
|
+
const { getByRole } = renderMenu( menu );
|
|
36
|
+
|
|
37
|
+
// Assert.
|
|
38
|
+
expect( getByRole( 'button' ) ).toBeInTheDocument();
|
|
39
|
+
expect( getByRole( 'link' ) ).toBeInTheDocument();
|
|
40
|
+
} );
|
|
41
|
+
|
|
42
|
+
it( 'should register an action', () => {
|
|
43
|
+
// Arrange.
|
|
44
|
+
const onClick = jest.fn();
|
|
45
|
+
|
|
46
|
+
// Act.
|
|
47
|
+
const menu = createMenu( {
|
|
48
|
+
name: 'test',
|
|
49
|
+
} );
|
|
50
|
+
|
|
51
|
+
menu.registerAction( createMockMenuAction( { onClick } ) );
|
|
52
|
+
|
|
53
|
+
const { getByRole } = renderMenu( menu );
|
|
54
|
+
|
|
55
|
+
// Assert.
|
|
56
|
+
const action = getByRole( 'button' );
|
|
57
|
+
|
|
58
|
+
expect( action ).toBeInTheDocument();
|
|
59
|
+
expect( action ).toHaveAttribute( 'aria-label', 'Test' );
|
|
60
|
+
|
|
61
|
+
// Act.
|
|
62
|
+
action.click();
|
|
63
|
+
|
|
64
|
+
// Assert.
|
|
65
|
+
expect( onClick ).toHaveBeenCalled();
|
|
66
|
+
} );
|
|
67
|
+
|
|
68
|
+
it( 'should register a toggle action', () => {
|
|
69
|
+
// Act.
|
|
70
|
+
const menu = createMenu( {
|
|
71
|
+
name: 'test',
|
|
72
|
+
} );
|
|
73
|
+
|
|
74
|
+
menu.registerToggleAction( createMockMenuToggleAction() );
|
|
75
|
+
|
|
76
|
+
const { getByRole } = renderMenu( menu );
|
|
77
|
+
|
|
78
|
+
// Assert.
|
|
79
|
+
const toggleAction = getByRole( 'button' );
|
|
80
|
+
|
|
81
|
+
expect( toggleAction ).toHaveAttribute( 'aria-pressed', 'false' );
|
|
82
|
+
expect( toggleAction ).toHaveAttribute( 'value', 'test-value' );
|
|
83
|
+
|
|
84
|
+
// Act.
|
|
85
|
+
toggleAction.click();
|
|
86
|
+
|
|
87
|
+
// Assert.
|
|
88
|
+
expect( toggleAction ).toHaveAttribute( 'aria-pressed', 'true' );
|
|
89
|
+
|
|
90
|
+
// Act.
|
|
91
|
+
toggleAction.click();
|
|
92
|
+
|
|
93
|
+
// Assert.
|
|
94
|
+
expect( toggleAction ).toHaveAttribute( 'aria-pressed', 'false' );
|
|
95
|
+
expect( toggleAction ).toHaveAttribute( 'disabled' );
|
|
96
|
+
} );
|
|
97
|
+
|
|
98
|
+
it( 'should register a link', () => {
|
|
99
|
+
// Act.
|
|
100
|
+
const menu = createMenu( {
|
|
101
|
+
name: 'test',
|
|
102
|
+
} );
|
|
103
|
+
|
|
104
|
+
menu.registerLink( createMockMenuLink() );
|
|
105
|
+
|
|
106
|
+
const { getByRole } = renderMenu( menu );
|
|
107
|
+
|
|
108
|
+
// Assert.
|
|
109
|
+
const link = getByRole( 'link' );
|
|
110
|
+
|
|
111
|
+
expect( link ).toBeInTheDocument();
|
|
112
|
+
expect( link ).toHaveAttribute( 'href', 'https://elementor.com' );
|
|
113
|
+
expect( link ).toHaveAttribute( 'target', '_blank' );
|
|
114
|
+
expect( link ).toHaveAttribute( 'aria-label', 'Test' );
|
|
115
|
+
} );
|
|
116
|
+
|
|
117
|
+
it( 'should not register an action when passing a non-existing group', () => {
|
|
118
|
+
// Act.
|
|
119
|
+
const menu = createMenu( {
|
|
120
|
+
name: 'test',
|
|
121
|
+
} );
|
|
122
|
+
|
|
123
|
+
menu.registerLink( {
|
|
124
|
+
...createMockMenuLink(),
|
|
125
|
+
group: 'non-existing-group' as 'default', // Emulate a runtime error.
|
|
126
|
+
} );
|
|
127
|
+
|
|
128
|
+
const { queryByRole } = renderMenu( menu );
|
|
129
|
+
|
|
130
|
+
// Assert.
|
|
131
|
+
expect( queryByRole( 'link' ) ).not.toBeInTheDocument();
|
|
132
|
+
} );
|
|
133
|
+
|
|
134
|
+
it( 'should register an action tooltip', async () => {
|
|
135
|
+
// Arrange.
|
|
136
|
+
const menu = createMenu( {
|
|
137
|
+
name: 'test',
|
|
138
|
+
} );
|
|
139
|
+
|
|
140
|
+
// Act.
|
|
141
|
+
menu.registerAction( createMockMenuAction() );
|
|
142
|
+
|
|
143
|
+
// Assert.
|
|
144
|
+
const { getByLabelText, queryByRole, findByRole } = renderMenu( menu );
|
|
145
|
+
|
|
146
|
+
const button = getByLabelText( 'Test' );
|
|
147
|
+
|
|
148
|
+
expect( queryByRole( 'tooltip' ) ).not.toBeInTheDocument();
|
|
149
|
+
|
|
150
|
+
// Act.
|
|
151
|
+
act( () => {
|
|
152
|
+
fireEvent(
|
|
153
|
+
button,
|
|
154
|
+
new MouseEvent( 'mouseover', { bubbles: true } ),
|
|
155
|
+
);
|
|
156
|
+
} );
|
|
157
|
+
|
|
158
|
+
// Assert.
|
|
159
|
+
expect( await findByRole( 'tooltip' ) ).toHaveTextContent( 'Test' );
|
|
160
|
+
} );
|
|
161
|
+
|
|
162
|
+
it( 'should register an action icon', () => {
|
|
163
|
+
// Arrange.
|
|
164
|
+
const menu = createMenu( {
|
|
165
|
+
name: 'test',
|
|
166
|
+
} );
|
|
167
|
+
|
|
168
|
+
// Act.
|
|
169
|
+
menu.registerAction( createMockMenuAction() );
|
|
170
|
+
|
|
171
|
+
// Assert.
|
|
172
|
+
const { queryByText } = renderMenu( menu );
|
|
173
|
+
|
|
174
|
+
const icon = queryByText( 'a' );
|
|
175
|
+
|
|
176
|
+
expect( icon ).toBeInTheDocument();
|
|
177
|
+
expect( icon ).toHaveTextContent( 'a' );
|
|
178
|
+
} );
|
|
179
|
+
|
|
180
|
+
it.each( [
|
|
181
|
+
{
|
|
182
|
+
type: 'action',
|
|
183
|
+
action: 'registerAction',
|
|
184
|
+
},
|
|
185
|
+
{
|
|
186
|
+
type: 'toggle action',
|
|
187
|
+
action: 'registerToggleAction',
|
|
188
|
+
},
|
|
189
|
+
{
|
|
190
|
+
type: 'link',
|
|
191
|
+
action: 'registerLink',
|
|
192
|
+
},
|
|
193
|
+
] as const )( 'should register a hidden $type', ( { type, action } ) => {
|
|
194
|
+
// Arrange.
|
|
195
|
+
const menu = createMenu( {
|
|
196
|
+
name: 'test',
|
|
197
|
+
} );
|
|
198
|
+
|
|
199
|
+
// Act.
|
|
200
|
+
menu[ action ]( {
|
|
201
|
+
name: 'hidden',
|
|
202
|
+
useProps: () => ( {
|
|
203
|
+
title: `hidden-${ type }`,
|
|
204
|
+
icon: () => <div />,
|
|
205
|
+
visible: false,
|
|
206
|
+
} ),
|
|
207
|
+
} );
|
|
208
|
+
|
|
209
|
+
// Assert.
|
|
210
|
+
const { queryByLabelText } = renderMenu( menu );
|
|
211
|
+
|
|
212
|
+
expect( queryByLabelText( `hidden-${ type }` ) ).not.toBeInTheDocument();
|
|
213
|
+
} );
|
|
214
|
+
} );
|
|
215
|
+
|
|
216
|
+
function renderMenu<TGroup extends string>( menu: ReturnType<typeof createMenu<TGroup>> ) {
|
|
217
|
+
const MenuComponent = () => {
|
|
218
|
+
const groupedItems = menu.useMenuItems();
|
|
219
|
+
const allItems = Object.values( groupedItems ).flat();
|
|
220
|
+
|
|
221
|
+
return (
|
|
222
|
+
<div>
|
|
223
|
+
{ allItems.map( ( { MenuItem, id } ) => <MenuItem key={ id } /> ) }
|
|
224
|
+
</div>
|
|
225
|
+
);
|
|
226
|
+
};
|
|
227
|
+
|
|
228
|
+
return render( <MenuComponent /> );
|
|
229
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { createMenu } from './menus';
|
|
2
|
+
import { createInjectorFor } from '@elementor/locations';
|
|
3
|
+
import { LOCATION_PAGE_INDICATION, LOCATION_PRIMARY_ACTION, LOCATION_RESPONSIVE } from './consts';
|
|
4
|
+
|
|
5
|
+
export * from './consts';
|
|
6
|
+
|
|
7
|
+
export { createMenu } from './menus';
|
|
8
|
+
|
|
9
|
+
export const injectIntoPageIndication = createInjectorFor( LOCATION_PAGE_INDICATION );
|
|
10
|
+
export const injectIntoResponsive = createInjectorFor( LOCATION_RESPONSIVE );
|
|
11
|
+
export const injectIntoPrimaryAction = createInjectorFor( LOCATION_PRIMARY_ACTION );
|
|
12
|
+
|
|
13
|
+
export const mainMenu = createMenu( {
|
|
14
|
+
name: 'main',
|
|
15
|
+
groups: [ 'exits' ],
|
|
16
|
+
} );
|
|
17
|
+
|
|
18
|
+
export const toolsMenu = createMenu( {
|
|
19
|
+
name: 'tools',
|
|
20
|
+
} );
|
|
21
|
+
|
|
22
|
+
export const utilitiesMenu = createMenu( {
|
|
23
|
+
name: 'utilities',
|
|
24
|
+
} );
|
|
25
|
+
|
|
26
|
+
export const documentOptionsMenu = createMenu( {
|
|
27
|
+
name: 'document-options',
|
|
28
|
+
groups: [ 'save' ],
|
|
29
|
+
} );
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { ComponentPropsWithoutRef, ElementType, useMemo } from 'react';
|
|
3
|
+
import { inject, useInjectionsOf } from '@elementor/locations';
|
|
4
|
+
import Action from '../components/actions/action';
|
|
5
|
+
import ToggleAction from '../components/actions/toggle-action';
|
|
6
|
+
import Link from '../components/actions/link';
|
|
7
|
+
|
|
8
|
+
type MenuName = string;
|
|
9
|
+
type GroupName = string;
|
|
10
|
+
|
|
11
|
+
type Menu<TGroup extends GroupName = 'default'> = {
|
|
12
|
+
name: MenuName,
|
|
13
|
+
groups: TGroup[],
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
type MenuWithOptionalGroups<TGroup extends GroupName> = Omit<Menu<TGroup>, 'groups'> & { groups?: TGroup[] };
|
|
17
|
+
|
|
18
|
+
type MenuGroup<TGroup extends GroupName> = TGroup | 'default';
|
|
19
|
+
|
|
20
|
+
type GroupedItems<TGroup extends GroupName> = Record<MenuGroup<TGroup>, Array<{ id: string, MenuItem: ElementType }>>;
|
|
21
|
+
|
|
22
|
+
type MenuItem<
|
|
23
|
+
TGroup extends GroupName,
|
|
24
|
+
TComponent extends ElementType,
|
|
25
|
+
> = {
|
|
26
|
+
name: string,
|
|
27
|
+
group?: TGroup,
|
|
28
|
+
priority?: number,
|
|
29
|
+
overwrite?: boolean,
|
|
30
|
+
} & (
|
|
31
|
+
{ props: ComponentPropsWithoutRef<TComponent>, useProps?: never } |
|
|
32
|
+
{ useProps: () => ComponentPropsWithoutRef<TComponent>, props?: never }
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
export function createMenu<TGroup extends GroupName = 'default'>( { name: menuName, groups = [] }: MenuWithOptionalGroups<TGroup> ) {
|
|
36
|
+
const menuGroups: MenuGroup<TGroup>[] = [
|
|
37
|
+
...groups,
|
|
38
|
+
'default' as const,
|
|
39
|
+
];
|
|
40
|
+
|
|
41
|
+
const registerAction = createRegisterMenuItem( {
|
|
42
|
+
menuName,
|
|
43
|
+
menuGroups,
|
|
44
|
+
component: Action,
|
|
45
|
+
} );
|
|
46
|
+
|
|
47
|
+
const registerToggleAction = createRegisterMenuItem( {
|
|
48
|
+
menuName,
|
|
49
|
+
menuGroups,
|
|
50
|
+
component: ToggleAction,
|
|
51
|
+
} );
|
|
52
|
+
|
|
53
|
+
const registerLink = createRegisterMenuItem( {
|
|
54
|
+
menuName,
|
|
55
|
+
menuGroups,
|
|
56
|
+
component: Link,
|
|
57
|
+
} );
|
|
58
|
+
|
|
59
|
+
const useMenuItems = createUseMenuItems( {
|
|
60
|
+
menuName,
|
|
61
|
+
menuGroups,
|
|
62
|
+
} );
|
|
63
|
+
|
|
64
|
+
return {
|
|
65
|
+
registerAction,
|
|
66
|
+
registerToggleAction,
|
|
67
|
+
registerLink,
|
|
68
|
+
useMenuItems,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function createRegisterMenuItem<
|
|
73
|
+
TMenuName extends MenuName,
|
|
74
|
+
TGroup extends GroupName,
|
|
75
|
+
TComponent extends ElementType,
|
|
76
|
+
>( { menuName, menuGroups, component }: {
|
|
77
|
+
menuName: TMenuName,
|
|
78
|
+
menuGroups: MenuGroup<TGroup>[],
|
|
79
|
+
component: TComponent,
|
|
80
|
+
} ) {
|
|
81
|
+
return ( { group = 'default', name, overwrite, priority, ...args }: MenuItem<MenuGroup<TGroup>, TComponent> ) => {
|
|
82
|
+
if ( ! menuGroups.includes( group ) ) {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const useProps = 'props' in args ? () => args.props : args.useProps;
|
|
87
|
+
|
|
88
|
+
const Component = component as ElementType;
|
|
89
|
+
|
|
90
|
+
const Filler = ( props: object ) => {
|
|
91
|
+
const componentProps = useProps();
|
|
92
|
+
|
|
93
|
+
return <Component { ...props } { ...componentProps } />;
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
const location = getMenuLocationId( menuName, group );
|
|
97
|
+
|
|
98
|
+
inject( {
|
|
99
|
+
location,
|
|
100
|
+
name,
|
|
101
|
+
filler: Filler,
|
|
102
|
+
options: {
|
|
103
|
+
priority,
|
|
104
|
+
overwrite,
|
|
105
|
+
},
|
|
106
|
+
} );
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function createUseMenuItems<
|
|
111
|
+
TMenuName extends MenuName,
|
|
112
|
+
TGroup extends GroupName,
|
|
113
|
+
>( { menuName, menuGroups }: {
|
|
114
|
+
menuName: TMenuName,
|
|
115
|
+
menuGroups: MenuGroup<TGroup>[],
|
|
116
|
+
} ) {
|
|
117
|
+
const locations = menuGroups.map( ( group ) => getMenuLocationId( menuName, group ) );
|
|
118
|
+
|
|
119
|
+
return () => {
|
|
120
|
+
const injectionsGroups = useInjectionsOf( locations );
|
|
121
|
+
|
|
122
|
+
// Normalize the injections groups to an object with the groups as keys.
|
|
123
|
+
return useMemo( () => {
|
|
124
|
+
return injectionsGroups.reduce<GroupedItems<TGroup>>( ( acc, injections, index ) => {
|
|
125
|
+
const groupName = menuGroups[ index ];
|
|
126
|
+
|
|
127
|
+
return {
|
|
128
|
+
...acc,
|
|
129
|
+
[ groupName ]: injections.map( ( injection ) => ( {
|
|
130
|
+
id: injection.id,
|
|
131
|
+
MenuItem: injection.filler,
|
|
132
|
+
} ) ),
|
|
133
|
+
};
|
|
134
|
+
}, {} as GroupedItems<TGroup> );
|
|
135
|
+
}, [ injectionsGroups ] );
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function getMenuLocationId( menu: MenuName, group: GroupName ) {
|
|
140
|
+
return `editor/app-bar/${ menu }/${ group }` as const;
|
|
141
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { openRoute } from '@elementor/editor-v1-adapters';
|
|
2
|
+
import redirectOldMenus from '../redirect-old-menus';
|
|
3
|
+
|
|
4
|
+
jest.mock( '@elementor/editor-v1-adapters', () => ( {
|
|
5
|
+
...jest.requireActual( '@elementor/editor-v1-adapters' ),
|
|
6
|
+
openRoute: jest.fn(),
|
|
7
|
+
} ) );
|
|
8
|
+
|
|
9
|
+
describe( '@elementor/editor-app-bar - Redirect old menus', () => {
|
|
10
|
+
it( 'should redirect old hamburger menu to the default elements panel', () => {
|
|
11
|
+
// Arrange.
|
|
12
|
+
redirectOldMenus();
|
|
13
|
+
|
|
14
|
+
// Act.
|
|
15
|
+
window.dispatchEvent( new CustomEvent( 'elementor/routes/open', {
|
|
16
|
+
detail: {
|
|
17
|
+
route: 'panel/menu',
|
|
18
|
+
},
|
|
19
|
+
} ) );
|
|
20
|
+
|
|
21
|
+
// Assert.
|
|
22
|
+
expect( openRoute ).toHaveBeenCalledWith( 'panel/elements/categories' );
|
|
23
|
+
|
|
24
|
+
// Act - Change to non-related route.
|
|
25
|
+
window.dispatchEvent( new CustomEvent( 'elementor/routes/open', {
|
|
26
|
+
detail: {
|
|
27
|
+
route: 'some/other/route',
|
|
28
|
+
},
|
|
29
|
+
} ) );
|
|
30
|
+
|
|
31
|
+
// Assert - Should not be called again.
|
|
32
|
+
expect( openRoute ).toHaveBeenCalledTimes( 1 );
|
|
33
|
+
} );
|
|
34
|
+
} );
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { listenTo, openRoute, routeOpenEvent } from '@elementor/editor-v1-adapters';
|
|
2
|
+
|
|
3
|
+
export default function redirectOldMenus() {
|
|
4
|
+
// Currently, in V1, when you click `esc` it opens the hamburger menu in the panel.
|
|
5
|
+
// In V2, we don't have this panel, so we redirect the user to the elements panel instead.
|
|
6
|
+
listenTo( routeOpenEvent( 'panel/menu' ), () => {
|
|
7
|
+
openRoute( 'panel/elements/categories' );
|
|
8
|
+
} );
|
|
9
|
+
}
|
package/src/types.ts
ADDED