@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.
@@ -8,13 +8,10 @@ import {
8
8
  } from './types';
9
9
  import { isReady, setReady } from './is-ready';
10
10
 
11
- const callbacksByEvent = new Map<EventDescriptor['name'], ListenerCallback[]>();
11
+ const callbacksByEvent = new Map< EventDescriptor[ 'name' ], ListenerCallback[] >();
12
12
  let abortController = new AbortController();
13
13
 
14
- export function listenTo(
15
- eventDescriptors: EventDescriptor | EventDescriptor[],
16
- callback: ListenerCallback
17
- ) {
14
+ export function listenTo( eventDescriptors: EventDescriptor | EventDescriptor[], callback: ListenerCallback ) {
18
15
  if ( ! Array.isArray( eventDescriptors ) ) {
19
16
  eventDescriptors = [ eventDescriptors ];
20
17
  }
@@ -50,8 +47,8 @@ export function flushListeners() {
50
47
  }
51
48
 
52
49
  function registerCommandListener(
53
- command: CommandEventDescriptor['name'],
54
- state: CommandEventDescriptor['state'],
50
+ command: CommandEventDescriptor[ 'name' ],
51
+ state: CommandEventDescriptor[ 'state' ],
55
52
  callback: ListenerCallback
56
53
  ) {
57
54
  return registerWindowEventListener( `elementor/commands/run/${ state }`, ( e ) => {
@@ -64,8 +61,8 @@ function registerCommandListener(
64
61
  }
65
62
 
66
63
  function registerRouteListener(
67
- route: RouteEventDescriptor['name'],
68
- state: RouteEventDescriptor['state'],
64
+ route: RouteEventDescriptor[ 'name' ],
65
+ state: RouteEventDescriptor[ 'state' ],
69
66
  callback: ListenerCallback
70
67
  ) {
71
68
  return registerWindowEventListener( `elementor/routes/${ state }`, ( e ) => {
@@ -77,7 +74,7 @@ function registerRouteListener(
77
74
  } );
78
75
  }
79
76
 
80
- function registerWindowEventListener( event: WindowEventDescriptor['name'], callback: ListenerCallback ) {
77
+ function registerWindowEventListener( event: WindowEventDescriptor[ 'name' ], callback: ListenerCallback ) {
81
78
  const isFirstListener = ! callbacksByEvent.has( event );
82
79
 
83
80
  if ( isFirstListener ) {
@@ -101,15 +98,11 @@ function registerWindowEventListener( event: WindowEventDescriptor['name'], call
101
98
  };
102
99
  }
103
100
 
104
- function addListener( event: EventDescriptor['name'] ) {
105
- window.addEventListener(
106
- event,
107
- makeEventHandler( event ),
108
- { signal: abortController.signal }
109
- );
101
+ function addListener( event: EventDescriptor[ 'name' ] ) {
102
+ window.addEventListener( event, makeEventHandler( event ), { signal: abortController.signal } );
110
103
  }
111
104
 
112
- function makeEventHandler( event: EventDescriptor['name'] ): EventListener {
105
+ function makeEventHandler( event: EventDescriptor[ 'name' ] ): EventListener {
113
106
  return ( e ) => {
114
107
  if ( ! isReady() ) {
115
108
  return;
@@ -1,41 +1,41 @@
1
1
  export type ExtendedWindow = Window & {
2
- __elementorEditorV1LoadingPromise?: Promise<void>;
2
+ __elementorEditorV1LoadingPromise?: Promise< void >;
3
3
  };
4
4
 
5
5
  export type CommandEventDescriptor = {
6
- type: 'command',
7
- name: string,
8
- state: 'before' | 'after',
6
+ type: 'command';
7
+ name: string;
8
+ state: 'before' | 'after';
9
9
  };
10
10
 
11
11
  export type RouteEventDescriptor = {
12
- type: 'route',
13
- name: string,
14
- state: 'open' | 'close',
12
+ type: 'route';
13
+ name: string;
14
+ state: 'open' | 'close';
15
15
  };
16
16
 
17
17
  export type WindowEventDescriptor = {
18
- type: 'window-event',
19
- name: string,
18
+ type: 'window-event';
19
+ name: string;
20
20
  };
21
21
 
22
- export type CommandEvent<TArgs extends object = object> = {
23
- type: CommandEventDescriptor['type'],
24
- command: string,
25
- args: TArgs,
26
- originalEvent: CustomEvent,
22
+ export type CommandEvent< TArgs extends object = object > = {
23
+ type: CommandEventDescriptor[ 'type' ];
24
+ command: string;
25
+ args: TArgs;
26
+ originalEvent: CustomEvent;
27
27
  };
28
28
 
29
29
  export type RouteEvent = {
30
- type: RouteEventDescriptor['type'],
31
- route: string,
32
- originalEvent: CustomEvent,
30
+ type: RouteEventDescriptor[ 'type' ];
31
+ route: string;
32
+ originalEvent: CustomEvent;
33
33
  };
34
34
 
35
35
  export type WindowEvent = {
36
- type: WindowEventDescriptor['type'],
37
- event: string,
38
- originalEvent: Event,
36
+ type: WindowEventDescriptor[ 'type' ];
37
+ event: string;
38
+ originalEvent: Event;
39
39
  };
40
40
 
41
41
  export type EventDescriptor = CommandEventDescriptor | WindowEventDescriptor | RouteEventDescriptor;
@@ -18,7 +18,7 @@ function getV1LoadingPromise() {
18
18
  return v1LoadingPromise;
19
19
  }
20
20
 
21
- export function normalizeEvent( e: ListenerEvent['originalEvent'] ): ListenerEvent {
21
+ export function normalizeEvent( e: ListenerEvent[ 'originalEvent' ] ): ListenerEvent {
22
22
  if ( e instanceof CustomEvent && e.detail?.command ) {
23
23
  return {
24
24
  type: 'command',
@@ -4,20 +4,19 @@ type ExtendedWindow = Window & {
4
4
  $e: {
5
5
  routes: {
6
6
  isPartOf: jest.Mock;
7
- }
8
- },
7
+ };
8
+ };
9
9
  elementor: {
10
10
  channels: {
11
11
  dataEditMode: {
12
12
  request: jest.Mock;
13
- }
14
- }
15
- }
16
- }
13
+ };
14
+ };
15
+ };
16
+ };
17
17
 
18
18
  describe( '@elementor/editor-v1-adapters - Readers', () => {
19
- let eIsPartOf: jest.Mock,
20
- eGetEditMode: jest.Mock;
19
+ let eIsPartOf: jest.Mock, eGetEditMode: jest.Mock;
21
20
 
22
21
  beforeEach( () => {
23
22
  const extendedWindow = window as unknown as ExtendedWindow;
@@ -4,13 +4,13 @@ export type ExtendedWindow = Window & {
4
4
  $e: {
5
5
  routes: {
6
6
  isPartOf: ( route: string ) => boolean;
7
- }
8
- },
7
+ };
8
+ };
9
9
  elementor: {
10
10
  channels: {
11
11
  dataEditMode: {
12
12
  request: ( key: 'activeMode' ) => EditMode;
13
- }
14
- }
15
- }
16
- }
13
+ };
14
+ };
15
+ };
16
+ };
@@ -1,39 +0,0 @@
1
- export function dispatchCommandBefore( command: string ) {
2
- window.dispatchEvent( new CustomEvent( 'elementor/commands/run/before', {
3
- detail: {
4
- command,
5
- },
6
- } ) );
7
- }
8
-
9
- export function dispatchCommandAfter( command: string ) {
10
- window.dispatchEvent( new CustomEvent( 'elementor/commands/run/after', {
11
- detail: {
12
- command,
13
- },
14
- } ) );
15
- }
16
-
17
- export function dispatchRouteOpen( route: string ) {
18
- window.dispatchEvent( new CustomEvent( 'elementor/routes/open', {
19
- detail: {
20
- route,
21
- },
22
- } ) );
23
- }
24
-
25
- export function dispatchRouteClose( route: string ) {
26
- window.dispatchEvent( new CustomEvent( 'elementor/routes/close', {
27
- detail: {
28
- route,
29
- },
30
- } ) );
31
- }
32
-
33
- export function dispatchEditModeChange() {
34
- window.dispatchEvent( new CustomEvent( 'elementor/edit-mode/change' ) );
35
- }
36
-
37
- export function dispatchWindowEvent( event: string ) {
38
- window.dispatchEvent( new CustomEvent( event ) );
39
- }