@elementor/editor-v1-adapters 0.6.2 → 0.8.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.
@@ -1,12 +1,13 @@
1
- import { openRoute, registerRoute, runCommand } from '../index';
2
- import { ExtendedWindow } from '../types';
1
+ import { openRoute, blockDataCommand, registerRoute, runCommand } from '../index';
2
+ import { DependencyHook, ExtendedWindow } from '../types';
3
3
 
4
4
  describe( '@elementor/editor-v1-adapters/dispatchers', () => {
5
- let eRun: jest.Mock,
6
- eRoute: jest.Mock,
7
- eRegisterRoute: jest.Mock;
5
+ let eRun: jest.Mock, eRoute: jest.Mock, eRegisterRoute: jest.Mock, eDependencyRegisterSpy: jest.SpyInstance;
6
+
7
+ let hooks: DependencyHook[] = [];
8
8
 
9
9
  beforeEach( () => {
10
+ hooks = [];
10
11
  const extendedWindow = window as unknown as ExtendedWindow;
11
12
 
12
13
  extendedWindow.$e = {
@@ -15,11 +16,24 @@ describe( '@elementor/editor-v1-adapters/dispatchers', () => {
15
16
  routes: {
16
17
  register: jest.fn(),
17
18
  },
19
+ modules: {
20
+ hookData: {
21
+ Dependency: class {
22
+ register() {
23
+ hooks.push( this as never );
24
+ }
25
+ } as typeof DependencyHook,
26
+ },
27
+ },
18
28
  };
19
29
 
20
30
  eRun = jest.mocked( extendedWindow.$e.run );
21
31
  eRoute = jest.mocked( extendedWindow.$e.route );
22
32
  eRegisterRoute = jest.mocked( extendedWindow.$e?.routes?.register || jest.fn() );
33
+ eDependencyRegisterSpy = jest.spyOn(
34
+ extendedWindow.$e?.modules?.hookData?.Dependency?.prototype as DependencyHook,
35
+ 'register'
36
+ );
23
37
  } );
24
38
 
25
39
  it( 'should run a V1 command that returns Promise', () => {
@@ -88,9 +102,7 @@ describe( '@elementor/editor-v1-adapters/dispatchers', () => {
88
102
  } );
89
103
 
90
104
  // Act.
91
- expect( () => openRoute( route ) )
92
- .rejects
93
- .toEqual( 'Cannot find test/route' );
105
+ expect( () => openRoute( route ) ).rejects.toEqual( 'Cannot find test/route' );
94
106
  } );
95
107
 
96
108
  it.each( [
@@ -106,23 +118,92 @@ describe( '@elementor/editor-v1-adapters/dispatchers', () => {
106
118
 
107
119
  it( 'should throw if trying to register invalid route', () => {
108
120
  // Act & Assert.
109
- expect( () => registerRoute( 'test' ) )
110
- .rejects
111
- .toEqual( '`test` is an invalid route' );
121
+ expect( () => registerRoute( 'test' ) ).rejects.toEqual( '`test` is an invalid route' );
112
122
  } );
113
123
 
114
124
  it.each( [
115
125
  [ '$e.route()', () => openRoute( 'test/route' ) ],
116
126
  [ '$e.run()', () => runCommand( 'editor/documents/open' ) ],
117
127
  [ '$e.routes.register()', () => registerRoute( 'test/route' ) ],
128
+ [
129
+ '$e.modules.hookData.Dependency',
130
+ () =>
131
+ blockDataCommand( {
132
+ command: '',
133
+ condition: () => true,
134
+ } ),
135
+ ],
118
136
  ] )( 'should reject when trying to use V1 and `%s` is unavailable', ( v1Method, action ) => {
119
137
  // Arrange.
120
138
  delete ( window as { $e?: unknown } ).$e;
121
139
 
122
140
  // Act & Assert.
123
- expect( () => action() )
124
- .rejects
125
- .toEqual( `\`${ v1Method }\` is not available` );
141
+ expect( () => action() ).rejects.toEqual( `\`${ v1Method }\` is not available` );
142
+ } );
143
+
144
+ it( 'should register a V1 dependency hook that blocks a V1 command', () => {
145
+ // Act.
146
+ const result = blockDataCommand( {
147
+ command: '',
148
+ condition: () => true,
149
+ } );
150
+
151
+ // Assert.
152
+ expect( eDependencyRegisterSpy ).toHaveBeenCalled();
153
+ expect( result ).toEqual( Promise.resolve() );
154
+ } );
155
+
156
+ it( 'should reject when failing to register a V1 dependency hook that blocks a V1 command', () => {
157
+ // Arrange.
158
+ eDependencyRegisterSpy.mockImplementation( () => {
159
+ throw 'Error';
160
+ } );
161
+
162
+ // Act & Assert.
163
+ expect( () =>
164
+ blockDataCommand( {
165
+ command: '',
166
+ condition: () => true,
167
+ } )
168
+ ).rejects.toEqual( 'Error' );
169
+ } );
170
+
171
+ it( 'should get the right command name, id and condition when blocking a v1 command', () => {
172
+ // Arrange.
173
+ blockDataCommand( {
174
+ command: 'editor/documents/open',
175
+ condition: ( args ) => 'key' in args,
176
+ } );
177
+
178
+ blockDataCommand( {
179
+ command: 'editor/documents/open',
180
+ condition: () => false,
181
+ } );
182
+
183
+ blockDataCommand( {
184
+ command: 'editor/documents/close',
185
+ condition: () => false,
186
+ } );
187
+
188
+ // Act & Assert.
189
+ expect( hooks ).toHaveLength( 3 );
190
+
191
+ expect( hooks[ 0 ].getCommand() ).toEqual( 'editor/documents/open' );
192
+ expect( hooks[ 1 ].getCommand() ).toEqual( 'editor/documents/open' );
193
+ expect( hooks[ 2 ].getCommand() ).toEqual( 'editor/documents/close' );
194
+
195
+ const hookId1 = hooks[ 0 ].getId();
196
+ const hookId2 = hooks[ 1 ].getId();
197
+ const hookId3 = hooks[ 2 ].getId();
198
+
199
+ expect( hookId1 ).not.toEqual( hookId2 );
200
+
201
+ expect( hookId1 ).toMatch( /^editor\/documents\/open--block--\d+$/ );
202
+ expect( hookId2 ).toMatch( /^editor\/documents\/open--block--\d+$/ );
203
+ expect( hookId3 ).toMatch( /^editor\/documents\/close--block--\d+$/ );
204
+
205
+ expect( hooks[ 0 ].apply( { key: 'value' } ) ).toBe( false );
206
+ expect( hooks[ 0 ].apply( { value: 'value' } ) ).toBe( true );
126
207
  } );
127
208
  } );
128
209
 
@@ -29,9 +29,7 @@ export function openRoute( route: string ) {
29
29
  }
30
30
 
31
31
  try {
32
- return Promise.resolve(
33
- extendedWindow.$e.route( route )
34
- );
32
+ return Promise.resolve( extendedWindow.$e.route( route ) );
35
33
  } catch ( e ) {
36
34
  return Promise.reject( e );
37
35
  }
@@ -54,9 +52,52 @@ export function registerRoute( route: string ) {
54
52
  const component = routeParts.join( '/' );
55
53
 
56
54
  try {
57
- return Promise.resolve(
58
- extendedWindow.$e.routes.register( component, componentRoute, () => null )
59
- );
55
+ return Promise.resolve( extendedWindow.$e.routes.register( component, componentRoute, () => null ) );
56
+ } catch ( e ) {
57
+ return Promise.reject( e );
58
+ }
59
+ }
60
+
61
+ type UnknownArgs = Record< string, unknown >;
62
+
63
+ let hookId = 0;
64
+
65
+ export function blockDataCommand( {
66
+ command,
67
+ condition,
68
+ }: {
69
+ command: string;
70
+ condition: ( args: UnknownArgs ) => boolean;
71
+ } ) {
72
+ const extendedWindow = window as unknown as ExtendedWindow;
73
+ const DependencyHook = extendedWindow.$e?.modules?.hookData?.Dependency;
74
+
75
+ if ( ! DependencyHook ) {
76
+ return Promise.reject( '`$e.modules.hookData.Dependency` is not available' );
77
+ }
78
+
79
+ const __hookId = ++hookId;
80
+
81
+ const dependencyHook = new ( class extends DependencyHook {
82
+ getCommand() {
83
+ return command;
84
+ }
85
+
86
+ getId() {
87
+ return `${ command }--block--${ __hookId }`;
88
+ }
89
+
90
+ apply( args: UnknownArgs ) {
91
+ // If the condition is met, we will stop the original command from running.
92
+ const shouldStopOriginalAction = condition( args );
93
+
94
+ // We will return `false` if we want to stop the original action from running.
95
+ return ! shouldStopOriginalAction;
96
+ }
97
+ } )();
98
+
99
+ try {
100
+ return Promise.resolve( dependencyHook.register() );
60
101
  } catch ( e ) {
61
102
  return Promise.reject( e );
62
103
  }
@@ -1,5 +1,5 @@
1
- export type jQueryDeferred<T> = {
2
- then<U>( onFulfill: ( value: T ) => U, onReject?: ( error: unknown ) => U ): jQueryDeferred<U>;
1
+ export type jQueryDeferred< T > = {
2
+ then< U >( onFulfill: ( value: T ) => U, onReject?: ( error: unknown ) => U ): jQueryDeferred< U >;
3
3
  };
4
4
 
5
5
  export type ExtendedWindow = Window & {
@@ -7,11 +7,19 @@ export type ExtendedWindow = Window & {
7
7
  run: ( command: string, args?: object ) => unknown;
8
8
  route: ( route: string ) => unknown;
9
9
  routes?: {
10
- register?: (
11
- component: string,
12
- route: string,
13
- callback: () => unknown
14
- ) => unknown;
15
- }
16
- },
10
+ register?: ( component: string, route: string, callback: () => unknown ) => unknown;
11
+ };
12
+ modules?: {
13
+ hookData?: {
14
+ Dependency: typeof DependencyHook;
15
+ };
16
+ };
17
+ };
18
+ };
19
+
20
+ export declare class DependencyHook {
21
+ getCommand(): string;
22
+ getId(): string;
23
+ apply( args: Record< string, unknown > ): boolean;
24
+ register(): void;
17
25
  }
@@ -1,17 +1,19 @@
1
1
  import { jQueryDeferred } from './types';
2
2
 
3
- export function isJQueryDeferred<T>( value: unknown ): value is jQueryDeferred<T> {
3
+ export function isJQueryDeferred< T >( value: unknown ): value is jQueryDeferred< T > {
4
4
  // TODO: Copied from:
5
5
  // https://github.com/elementor/elementor/blob/6a74fc9/modules/web-cli/assets/js/core/commands.js#L410
6
6
 
7
- return ( !! value ) &&
7
+ return (
8
+ !! value &&
8
9
  'object' === typeof value &&
9
10
  Object.hasOwn( value, 'promise' ) &&
10
11
  Object.hasOwn( value, 'then' ) &&
11
- Object.hasOwn( value, 'fail' );
12
+ Object.hasOwn( value, 'fail' )
13
+ );
12
14
  }
13
15
 
14
- export function promisifyJQueryDeferred<T>( deferred: jQueryDeferred<T> ): Promise<T> {
16
+ export function promisifyJQueryDeferred< T >( deferred: jQueryDeferred< T > ): Promise< T > {
15
17
  return new Promise( ( resolve, reject ) => {
16
18
  deferred.then( resolve, reject );
17
19
  } );
@@ -1,6 +1,6 @@
1
1
  import { act, renderHook } from '@testing-library/react';
2
2
  import { __privateUseIsPreviewMode as useIsPreviewMode } from '../../index';
3
- import { dispatchEditModeChange } from '../../__tests__/utils';
3
+ import { dispatchEditModeChange } from 'test-utils';
4
4
  import { mockGetCurrentEditMode } from './test-utils';
5
5
 
6
6
  describe( '@elementor/editor-v1-adapters - useIsPreviewMode', () => {
@@ -1,6 +1,6 @@
1
1
  import { act, renderHook } from '@testing-library/react';
2
2
  import useIsRouteActive from '../use-is-route-active';
3
- import { dispatchRouteClose, dispatchRouteOpen } from '../../__tests__/utils';
3
+ import { dispatchRouteClose, dispatchRouteOpen } from 'test-utils';
4
4
  import { mockIsRouteActive } from './test-utils';
5
5
 
6
6
  describe( '@elementor/editor-v1-adapters - useIsRouteActive', () => {
@@ -42,20 +42,20 @@ describe( '@elementor/editor-v1-adapters - useRouteStatus', () => {
42
42
  },
43
43
  expected: false,
44
44
  },
45
- ] )( 'should check if the route is active: isRouteActive = $input.isRouteActive, isPreviewMode = $input.isPreviewMode, options: $input.options', ( {
46
- input: { isRouteActive, isKitRouteActive, isPreviewMode, options },
47
- expected,
48
- } ) => {
49
- // Arrange
50
- mockIsRouteActive( ( route ) => route === 'panel/global' ? isKitRouteActive : isRouteActive );
51
- mockGetCurrentEditMode( () => isPreviewMode ? 'preview' : 'edit' );
45
+ ] )(
46
+ 'should check if the route is active: isRouteActive = $input.isRouteActive, isPreviewMode = $input.isPreviewMode, options: $input.options',
47
+ ( { input: { isRouteActive, isKitRouteActive, isPreviewMode, options }, expected } ) => {
48
+ // Arrange
49
+ mockIsRouteActive( ( route ) => ( route === 'panel/global' ? isKitRouteActive : isRouteActive ) );
50
+ mockGetCurrentEditMode( () => ( isPreviewMode ? 'preview' : 'edit' ) );
52
51
 
53
- // Act.
54
- const { result } = renderHook( () => useRouteStatus( 'panel/page-settings', options ) );
52
+ // Act.
53
+ const { result } = renderHook( () => useRouteStatus( 'panel/page-settings', options ) );
55
54
 
56
- // Assert.
57
- expect( result.current.isActive ).toBe( expected );
58
- } );
55
+ // Assert.
56
+ expect( result.current.isActive ).toBe( expected );
57
+ }
58
+ );
59
59
 
60
60
  it.each( [
61
61
  {
@@ -107,18 +107,18 @@ describe( '@elementor/editor-v1-adapters - useRouteStatus', () => {
107
107
  },
108
108
  expected: true,
109
109
  },
110
- ] )( 'should check if the route is blocked: isKitRouteActive = $input.isKitRouteActive, isPreviewMode = $input.isPreviewMode, options: $input.options', ( {
111
- input: { isRouteActive, isKitRouteActive, isPreviewMode, options },
112
- expected,
113
- } ) => {
114
- // Arrange
115
- mockIsRouteActive( ( route ) => route === 'panel/global' ? isKitRouteActive : isRouteActive );
116
- mockGetCurrentEditMode( () => isPreviewMode ? 'preview' : 'edit' );
110
+ ] )(
111
+ 'should check if the route is blocked: isKitRouteActive = $input.isKitRouteActive, isPreviewMode = $input.isPreviewMode, options: $input.options',
112
+ ( { input: { isRouteActive, isKitRouteActive, isPreviewMode, options }, expected } ) => {
113
+ // Arrange
114
+ mockIsRouteActive( ( route ) => ( route === 'panel/global' ? isKitRouteActive : isRouteActive ) );
115
+ mockGetCurrentEditMode( () => ( isPreviewMode ? 'preview' : 'edit' ) );
117
116
 
118
- // Act.
119
- const { result } = renderHook( () => useRouteStatus( 'panel/page-settings', options ) );
117
+ // Act.
118
+ const { result } = renderHook( () => useRouteStatus( 'panel/page-settings', options ) );
120
119
 
121
- // Assert.
122
- expect( result.current.isBlocked ).toBe( expected );
123
- } );
120
+ // Assert.
121
+ expect( result.current.isBlocked ).toBe( expected );
122
+ }
123
+ );
124
124
  } );
@@ -3,8 +3,5 @@ import { getCurrentEditMode } from '../readers';
3
3
  import { editModeChangeEvent } from '../listeners';
4
4
 
5
5
  export default function useIsPreviewMode() {
6
- return useListenTo(
7
- editModeChangeEvent(),
8
- () => getCurrentEditMode() === 'preview'
9
- );
6
+ return useListenTo( editModeChangeEvent(), () => getCurrentEditMode() === 'preview' );
10
7
  }
@@ -2,13 +2,8 @@ import useListenTo from './use-listen-to';
2
2
  import { isRouteActive } from '../readers';
3
3
  import { routeCloseEvent, routeOpenEvent, RouteEventDescriptor } from '../listeners';
4
4
 
5
- export default function useIsRouteActive( route: RouteEventDescriptor['name'] ) {
6
- return useListenTo(
7
- [
8
- routeOpenEvent( route ),
9
- routeCloseEvent( route ),
10
- ],
11
- () => isRouteActive( route ),
12
- [ route ]
13
- );
5
+ export default function useIsRouteActive( route: RouteEventDescriptor[ 'name' ] ) {
6
+ return useListenTo( [ routeOpenEvent( route ), routeCloseEvent( route ) ], () => isRouteActive( route ), [
7
+ route,
8
+ ] );
14
9
  }
@@ -1,7 +1,7 @@
1
1
  import { useEffect, useState } from 'react';
2
2
  import { EventDescriptor, listenTo } from '../listeners';
3
3
 
4
- export default function useListenTo<T>(
4
+ export default function useListenTo< T >(
5
5
  event: EventDescriptor | EventDescriptor[],
6
6
  getSnapshot: () => T,
7
7
  deps: unknown[] = []
@@ -3,16 +3,13 @@ import useIsRouteActive from './use-is-route-active';
3
3
  import { RouteEventDescriptor } from '../listeners';
4
4
 
5
5
  type Options = {
6
- blockOnKitRoutes?: boolean,
7
- blockOnPreviewMode?: boolean,
8
- }
6
+ blockOnKitRoutes?: boolean;
7
+ blockOnPreviewMode?: boolean;
8
+ };
9
9
 
10
10
  export default function useRouteStatus(
11
- route: RouteEventDescriptor['name'],
12
- {
13
- blockOnKitRoutes = true,
14
- blockOnPreviewMode = true,
15
- }: Options = {}
11
+ route: RouteEventDescriptor[ 'name' ],
12
+ { blockOnKitRoutes = true, blockOnPreviewMode = true }: Options = {}
16
13
  ) {
17
14
  const isRouteActive = useIsRouteActive( route );
18
15
  const isKitRouteActive = useIsRouteActive( 'panel/global' );
@@ -20,10 +17,7 @@ export default function useRouteStatus(
20
17
 
21
18
  const isActive = isRouteActive && ! ( blockOnPreviewMode && isPreviewMode );
22
19
 
23
- const isBlocked = (
24
- ( blockOnPreviewMode && isPreviewMode ) ||
25
- ( blockOnKitRoutes && isKitRouteActive )
26
- );
20
+ const isBlocked = ( blockOnPreviewMode && isPreviewMode ) || ( blockOnKitRoutes && isKitRouteActive );
27
21
 
28
22
  return {
29
23
  isActive,
package/src/index.ts CHANGED
@@ -2,6 +2,7 @@ export {
2
2
  runCommand as __privateRunCommand,
3
3
  openRoute as __privateOpenRoute,
4
4
  registerRoute as __privateRegisterRoute,
5
+ blockDataCommand as __privateBlockDataCommand,
5
6
  } from './dispatchers';
6
7
 
7
8
  export {
@@ -27,7 +28,4 @@ export {
27
28
 
28
29
  export type * from './listeners';
29
30
 
30
- export {
31
- isRouteActive as __privateIsRouteActive,
32
- getCurrentEditMode as __privateGetCurrentEditMode,
33
- } from './readers';
31
+ export { isRouteActive as __privateIsRouteActive, getCurrentEditMode as __privateGetCurrentEditMode } from './readers';
@@ -17,7 +17,7 @@ import {
17
17
  dispatchRouteClose,
18
18
  dispatchRouteOpen,
19
19
  dispatchWindowEvent,
20
- } from '../../__tests__/utils';
20
+ } from 'test-utils';
21
21
 
22
22
  describe( '@elementor/editor-v1-adapters/listeners', () => {
23
23
  beforeEach( () => {
@@ -35,10 +35,7 @@ describe( '@elementor/editor-v1-adapters/listeners', () => {
35
35
  callback = jest.fn();
36
36
 
37
37
  // Act.
38
- listenTo(
39
- commandStartEvent( commandToListen ),
40
- callback
41
- );
38
+ listenTo( commandStartEvent( commandToListen ), callback );
42
39
 
43
40
  // Dispatch the command to test.
44
41
  dispatchCommandBefore( commandToListen );
@@ -64,10 +61,7 @@ describe( '@elementor/editor-v1-adapters/listeners', () => {
64
61
  callback = jest.fn();
65
62
 
66
63
  // Act.
67
- listenTo(
68
- commandEndEvent( commandToListen ),
69
- callback
70
- );
64
+ listenTo( commandEndEvent( commandToListen ), callback );
71
65
 
72
66
  // Dispatch the command to test.
73
67
  dispatchCommandBefore( commandToListen );
@@ -93,10 +87,7 @@ describe( '@elementor/editor-v1-adapters/listeners', () => {
93
87
  callback = jest.fn();
94
88
 
95
89
  // Act.
96
- listenTo(
97
- routeOpenEvent( routeToListen ),
98
- callback
99
- );
90
+ listenTo( routeOpenEvent( routeToListen ), callback );
100
91
 
101
92
  // Dispatch the route to test.
102
93
  dispatchRouteOpen( routeToListen );
@@ -120,10 +111,7 @@ describe( '@elementor/editor-v1-adapters/listeners', () => {
120
111
  callback = jest.fn();
121
112
 
122
113
  // Act.
123
- listenTo(
124
- routeCloseEvent( routeToListen ),
125
- callback
126
- );
114
+ listenTo( routeCloseEvent( routeToListen ), callback );
127
115
 
128
116
  // Dispatch the route to test.
129
117
  dispatchRouteClose( routeToListen );
@@ -146,10 +134,7 @@ describe( '@elementor/editor-v1-adapters/listeners', () => {
146
134
  callback = jest.fn();
147
135
 
148
136
  // Act.
149
- listenTo(
150
- windowEvent( event ),
151
- callback
152
- );
137
+ listenTo( windowEvent( event ), callback );
153
138
 
154
139
  // Dispatch events.
155
140
  dispatchWindowEvent( event );
@@ -170,15 +155,9 @@ describe( '@elementor/editor-v1-adapters/listeners', () => {
170
155
  callback2 = jest.fn();
171
156
 
172
157
  // Act.
173
- listenTo(
174
- windowEvent( event ),
175
- callback1
176
- );
158
+ listenTo( windowEvent( event ), callback1 );
177
159
 
178
- listenTo(
179
- windowEvent( event ),
180
- callback2
181
- );
160
+ listenTo( windowEvent( event ), callback2 );
182
161
 
183
162
  // Dispatch events.
184
163
  dispatchWindowEvent( event );
@@ -196,11 +175,7 @@ describe( '@elementor/editor-v1-adapters/listeners', () => {
196
175
  callback = jest.fn();
197
176
 
198
177
  // Act.
199
- listenTo( [
200
- windowEvent( event ),
201
- commandStartEvent( command ),
202
- routeOpenEvent( route ),
203
- ], callback );
178
+ listenTo( [ windowEvent( event ), commandStartEvent( command ), routeOpenEvent( route ) ], callback );
204
179
 
205
180
  // Dispatch events.
206
181
  dispatchCommandBefore( command );
@@ -240,18 +215,9 @@ describe( '@elementor/editor-v1-adapters/listeners', () => {
240
215
  callback1 = jest.fn(),
241
216
  callback2 = jest.fn();
242
217
 
243
- const cleanup1 = listenTo(
244
- [
245
- windowEvent( event1 ),
246
- windowEvent( event2 ),
247
- ],
248
- callback1,
249
- );
218
+ const cleanup1 = listenTo( [ windowEvent( event1 ), windowEvent( event2 ) ], callback1 );
250
219
 
251
- const cleanup2 = listenTo(
252
- windowEvent( event1 ),
253
- callback2,
254
- );
220
+ const cleanup2 = listenTo( windowEvent( event1 ), callback2 );
255
221
 
256
222
  // Act.
257
223
  cleanup1();
@@ -271,10 +237,7 @@ describe( '@elementor/editor-v1-adapters/listeners', () => {
271
237
  const event = 'test-event',
272
238
  callback = jest.fn();
273
239
 
274
- const cleanup = listenTo(
275
- windowEvent( event ),
276
- callback,
277
- );
240
+ const cleanup = listenTo( windowEvent( event ), callback );
278
241
 
279
242
  // Act.
280
243
  cleanup();
@@ -290,17 +253,14 @@ describe( '@elementor/editor-v1-adapters/listeners', () => {
290
253
  it( 'should trigger v1 ready when v1 is loaded after v2', async () => {
291
254
  // Arrange.
292
255
  const callback = jest.fn();
293
- const extendedWindow = ( window as unknown as ExtendedWindow );
256
+ const extendedWindow = window as unknown as ExtendedWindow;
294
257
 
295
258
  extendedWindow.__elementorEditorV1LoadingPromise = new Promise( ( resolve ) => {
296
259
  setTimeout( resolve, 1000 );
297
260
  } );
298
261
 
299
262
  // Act.
300
- listenTo(
301
- v1ReadyEvent(),
302
- callback
303
- );
263
+ listenTo( v1ReadyEvent(), callback );
304
264
 
305
265
  dispatchReadyEvent();
306
266
 
@@ -318,10 +278,7 @@ describe( '@elementor/editor-v1-adapters/listeners', () => {
318
278
  const callback = jest.fn();
319
279
 
320
280
  // Act.
321
- listenTo(
322
- windowEvent( event ),
323
- callback
324
- );
281
+ listenTo( windowEvent( event ), callback );
325
282
 
326
283
  // Dispatch events.
327
284
  dispatchWindowEvent( event );
@@ -1,6 +1,6 @@
1
1
  import { CommandEventDescriptor, RouteEventDescriptor, WindowEventDescriptor } from './types';
2
2
 
3
- export const commandStartEvent = ( command: CommandEventDescriptor['name'] ): CommandEventDescriptor => {
3
+ export const commandStartEvent = ( command: CommandEventDescriptor[ 'name' ] ): CommandEventDescriptor => {
4
4
  return {
5
5
  type: 'command',
6
6
  name: command,
@@ -8,7 +8,7 @@ export const commandStartEvent = ( command: CommandEventDescriptor['name'] ): Co
8
8
  };
9
9
  };
10
10
 
11
- export const commandEndEvent = ( command: CommandEventDescriptor['name'] ): CommandEventDescriptor => {
11
+ export const commandEndEvent = ( command: CommandEventDescriptor[ 'name' ] ): CommandEventDescriptor => {
12
12
  return {
13
13
  type: 'command',
14
14
  name: command,
@@ -16,7 +16,7 @@ export const commandEndEvent = ( command: CommandEventDescriptor['name'] ): Comm
16
16
  };
17
17
  };
18
18
 
19
- export const routeOpenEvent = ( route: RouteEventDescriptor['name'] ): RouteEventDescriptor => {
19
+ export const routeOpenEvent = ( route: RouteEventDescriptor[ 'name' ] ): RouteEventDescriptor => {
20
20
  return {
21
21
  type: 'route',
22
22
  name: route,
@@ -24,7 +24,7 @@ export const routeOpenEvent = ( route: RouteEventDescriptor['name'] ): RouteEven
24
24
  };
25
25
  };
26
26
 
27
- export const routeCloseEvent = ( route: RouteEventDescriptor['name'] ): RouteEventDescriptor => {
27
+ export const routeCloseEvent = ( route: RouteEventDescriptor[ 'name' ] ): RouteEventDescriptor => {
28
28
  return {
29
29
  type: 'route',
30
30
  name: route,
@@ -32,7 +32,7 @@ export const routeCloseEvent = ( route: RouteEventDescriptor['name'] ): RouteEve
32
32
  };
33
33
  };
34
34
 
35
- export const windowEvent = ( event: WindowEventDescriptor['name'] ): WindowEventDescriptor => {
35
+ export const windowEvent = ( event: WindowEventDescriptor[ 'name' ] ): WindowEventDescriptor => {
36
36
  return {
37
37
  type: 'window-event',
38
38
  name: event,