@elementor/editor-documents 0.11.3 → 0.11.5

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.
@@ -23,50 +23,48 @@ export function syncStore() {
23
23
  function syncInitialization() {
24
24
  const { init } = slice.actions;
25
25
 
26
- listenTo(
27
- v1ReadyEvent(),
28
- () => {
29
- const documentsManager = getV1DocumentsManager();
26
+ listenTo( v1ReadyEvent(), () => {
27
+ const documentsManager = getV1DocumentsManager();
30
28
 
31
- const entities = Object.entries( documentsManager.documents )
32
- .reduce( ( acc: Record<string, Document>, [ id, document ] ) => {
33
- acc[ id ] = normalizeV1Document( document );
29
+ const entities = Object.entries( documentsManager.documents ).reduce(
30
+ ( acc: Record< string, Document >, [ id, document ] ) => {
31
+ acc[ id ] = normalizeV1Document( document );
34
32
 
35
- return acc;
36
- }, {} );
33
+ return acc;
34
+ },
35
+ {}
36
+ );
37
37
 
38
- __dispatch( init( {
38
+ __dispatch(
39
+ init( {
39
40
  entities,
40
41
  hostId: documentsManager.getInitialId(),
41
42
  activeId: documentsManager.getCurrentId(),
42
- } ) );
43
- }
44
- );
43
+ } )
44
+ );
45
+ } );
45
46
  }
46
47
 
47
48
  function syncActiveDocument() {
48
49
  const { activateDocument, setAsHost } = slice.actions;
49
50
 
50
- listenTo(
51
- commandEndEvent( 'editor/documents/open' ),
52
- () => {
53
- const documentsManager = getV1DocumentsManager();
54
- const currentDocument = normalizeV1Document( documentsManager.getCurrent() );
51
+ listenTo( commandEndEvent( 'editor/documents/open' ), () => {
52
+ const documentsManager = getV1DocumentsManager();
53
+ const currentDocument = normalizeV1Document( documentsManager.getCurrent() );
55
54
 
56
- __dispatch( activateDocument( currentDocument ) );
55
+ __dispatch( activateDocument( currentDocument ) );
57
56
 
58
- if ( documentsManager.getInitialId() === currentDocument.id ) {
59
- __dispatch( setAsHost( currentDocument.id ) );
60
- }
57
+ if ( documentsManager.getInitialId() === currentDocument.id ) {
58
+ __dispatch( setAsHost( currentDocument.id ) );
61
59
  }
62
- );
60
+ } );
63
61
  }
64
62
 
65
63
  function syncOnDocumentSave() {
66
64
  const { startSaving, endSaving, startSavingDraft, endSavingDraft } = slice.actions;
67
65
 
68
66
  const isDraft = ( e: ListenerEvent ) => {
69
- const event = e as CommandEvent<{ status: string }>;
67
+ const event = e as CommandEvent< { status: string } >;
70
68
 
71
69
  /**
72
70
  * @see https://github.com/elementor/elementor/blob/5f815d40a/assets/dev/js/editor/document/save/hooks/ui/save/before.js#L18-L22
@@ -74,39 +72,31 @@ function syncOnDocumentSave() {
74
72
  return event.args?.status === 'autosave';
75
73
  };
76
74
 
77
- listenTo(
78
- commandStartEvent( 'document/save/save' ),
79
- ( e ) => {
80
- if ( isDraft( e ) ) {
81
- __dispatch( startSavingDraft() );
82
- return;
83
- }
84
-
85
- __dispatch( startSaving() );
75
+ listenTo( commandStartEvent( 'document/save/save' ), ( e ) => {
76
+ if ( isDraft( e ) ) {
77
+ __dispatch( startSavingDraft() );
78
+ return;
86
79
  }
87
- );
88
-
89
- listenTo(
90
- commandEndEvent( 'document/save/save' ),
91
- ( e ) => {
92
- const activeDocument = normalizeV1Document(
93
- getV1DocumentsManager().getCurrent()
94
- );
95
-
96
- if ( isDraft( e ) ) {
97
- __dispatch( endSavingDraft( activeDocument ) );
98
- } else {
99
- __dispatch( endSaving( activeDocument ) );
100
- }
80
+
81
+ __dispatch( startSaving() );
82
+ } );
83
+
84
+ listenTo( commandEndEvent( 'document/save/save' ), ( e ) => {
85
+ const activeDocument = normalizeV1Document( getV1DocumentsManager().getCurrent() );
86
+
87
+ if ( isDraft( e ) ) {
88
+ __dispatch( endSavingDraft( activeDocument ) );
89
+ } else {
90
+ __dispatch( endSaving( activeDocument ) );
101
91
  }
102
- );
92
+ } );
103
93
  }
104
94
 
105
95
  function syncOnTitleChange() {
106
96
  const { updateActiveDocument } = slice.actions;
107
97
 
108
98
  const updateTitle = debounce( ( e: ListenerEvent ) => {
109
- const event = e as CommandEvent<{ settings: { post_title?: string } }>;
99
+ const event = e as CommandEvent< { settings: { post_title?: string } } >;
110
100
 
111
101
  if ( ! ( 'post_title' in event.args?.settings ) ) {
112
102
  return;
@@ -118,17 +108,14 @@ function syncOnTitleChange() {
118
108
  __dispatch( updateActiveDocument( { title: newTitle } ) );
119
109
  }, 400 );
120
110
 
121
- listenTo(
122
- commandEndEvent( 'document/elements/settings' ),
123
- updateTitle
124
- );
111
+ listenTo( commandEndEvent( 'document/elements/settings' ), updateTitle );
125
112
  }
126
113
 
127
114
  function syncOnExitToChange() {
128
115
  const { updateActiveDocument } = slice.actions;
129
116
 
130
117
  const updateExitTo = debounce( ( e: ListenerEvent ) => {
131
- const event = e as CommandEvent<{ settings: { exit_to?: string } }>;
118
+ const event = e as CommandEvent< { settings: { exit_to?: string } } >;
132
119
 
133
120
  if ( ! ( 'exit_to' in event.args?.settings ) ) {
134
121
  return;
@@ -141,32 +128,26 @@ function syncOnExitToChange() {
141
128
  __dispatch( updateActiveDocument( { links: { platformEdit: newExitTo, permalink } } ) );
142
129
  }, 400 );
143
130
 
144
- listenTo(
145
- commandEndEvent( 'document/elements/settings' ),
146
- updateExitTo
147
- );
131
+ listenTo( commandEndEvent( 'document/elements/settings' ), updateExitTo );
148
132
  }
149
133
 
150
134
  function syncOnDocumentChange() {
151
135
  const { markAsDirty, markAsPristine } = slice.actions;
152
136
 
153
- listenTo(
154
- commandEndEvent( 'document/save/set-is-modified' ),
155
- () => {
156
- const currentDocument = getV1DocumentsManager().getCurrent();
157
-
158
- if ( currentDocument.editor.isChanged ) {
159
- __dispatch( markAsDirty() );
160
- return;
161
- }
137
+ listenTo( commandEndEvent( 'document/save/set-is-modified' ), () => {
138
+ const currentDocument = getV1DocumentsManager().getCurrent();
162
139
 
163
- __dispatch( markAsPristine() );
140
+ if ( currentDocument.editor.isChanged ) {
141
+ __dispatch( markAsDirty() );
142
+ return;
164
143
  }
165
- );
144
+
145
+ __dispatch( markAsPristine() );
146
+ } );
166
147
  }
167
148
 
168
- function debounce<TArgs extends unknown[]>( fn: ( ...args: TArgs ) => unknown, timeout: number ) {
169
- let timer: ReturnType<typeof setTimeout>;
149
+ function debounce< TArgs extends unknown[] >( fn: ( ...args: TArgs ) => unknown, timeout: number ) {
150
+ let timer: ReturnType< typeof setTimeout >;
170
151
 
171
152
  return ( ...args: TArgs ) => {
172
153
  clearTimeout( timer );
package/src/sync/utils.ts CHANGED
@@ -11,7 +11,8 @@ export function getV1DocumentsManager() {
11
11
  }
12
12
 
13
13
  export function getV1DocumentsExitTo( documentData: V1Document ) {
14
- const exitPreference = ( window as unknown as ExtendedWindow ).elementor?.getPreferences?.( 'exit_to' ) || 'this_post';
14
+ const exitPreference =
15
+ ( window as unknown as ExtendedWindow ).elementor?.getPreferences?.( 'exit_to' ) || 'this_post';
15
16
 
16
17
  switch ( exitPreference ) {
17
18
  case 'dashboard':
@@ -26,7 +27,7 @@ export function getV1DocumentsExitTo( documentData: V1Document ) {
26
27
  }
27
28
  }
28
29
 
29
- export function getV1DocumentShowCopyAndShare( documentData: V1Document|null ) {
30
+ export function getV1DocumentShowCopyAndShare( documentData: V1Document | null ) {
30
31
  return documentData?.config?.panel?.show_copy_and_share ?? false;
31
32
  }
32
33
 
package/src/types.ts CHANGED
@@ -1,82 +1,82 @@
1
1
  export type ExitTo = 'dashboard' | 'all_posts' | 'this_post';
2
2
 
3
3
  export type Document = {
4
- id: number,
5
- title: string,
4
+ id: number;
5
+ title: string;
6
6
  type: {
7
- value: string,
8
- label: string,
9
- },
7
+ value: string;
8
+ label: string;
9
+ };
10
10
  status: {
11
- value: string,
12
- label: string,
13
- },
11
+ value: string;
12
+ label: string;
13
+ };
14
14
  links: {
15
- platformEdit: string,
16
- permalink: string,
17
- }
18
- isDirty: boolean,
19
- isSaving: boolean,
20
- isSavingDraft: boolean,
15
+ platformEdit: string;
16
+ permalink: string;
17
+ };
18
+ isDirty: boolean;
19
+ isSaving: boolean;
20
+ isSavingDraft: boolean;
21
21
  userCan: {
22
- publish?: boolean,
23
- },
22
+ publish?: boolean;
23
+ };
24
24
  permissions: {
25
- allowAddingWidgets: boolean,
26
- showCopyAndShare: boolean,
27
- },
25
+ allowAddingWidgets: boolean;
26
+ showCopyAndShare: boolean;
27
+ };
28
28
  };
29
29
 
30
30
  export type ExtendedWindow = Window & {
31
31
  elementor: {
32
32
  documents: {
33
- documents: Record<string, V1Document>,
34
- getCurrentId: () => number,
35
- getInitialId: () => number,
36
- getCurrent: () => V1Document,
37
- },
38
- getPreferences: ( key: 'exit_to' ) => ExitTo,
39
- }
40
- }
33
+ documents: Record< string, V1Document >;
34
+ getCurrentId: () => number;
35
+ getInitialId: () => number;
36
+ getCurrent: () => V1Document;
37
+ };
38
+ getPreferences: ( key: 'exit_to' ) => ExitTo;
39
+ };
40
+ };
41
41
 
42
42
  export type V1Document = {
43
- id: number,
43
+ id: number;
44
44
  config: {
45
- type: string,
45
+ type: string;
46
46
  user: {
47
- can_publish: boolean,
48
- },
47
+ can_publish: boolean;
48
+ };
49
49
  revisions: {
50
- current_id: number,
51
- }
50
+ current_id: number;
51
+ };
52
52
  panel: {
53
- title: string,
54
- allow_adding_widgets: boolean,
55
- show_copy_and_share: boolean,
56
- }
53
+ title: string;
54
+ allow_adding_widgets: boolean;
55
+ show_copy_and_share: boolean;
56
+ };
57
57
  status: {
58
- value: string,
59
- label: string,
60
- },
58
+ value: string;
59
+ label: string;
60
+ };
61
61
  urls: {
62
- exit_to_dashboard: string,
63
- permalink: string,
64
- main_dashboard: string,
65
- all_post_type: string,
66
- },
67
- },
62
+ exit_to_dashboard: string;
63
+ permalink: string;
64
+ main_dashboard: string;
65
+ all_post_type: string;
66
+ };
67
+ };
68
68
  editor: {
69
- isChanged: boolean,
70
- isSaving: boolean,
71
- },
69
+ isChanged: boolean;
70
+ isSaving: boolean;
71
+ };
72
72
  container: {
73
- settings: V1Model<{
74
- post_title: string,
75
- exit_to: ExitTo,
76
- }>,
77
- }
78
- }
73
+ settings: V1Model< {
74
+ post_title: string;
75
+ exit_to: ExitTo;
76
+ } >;
77
+ };
78
+ };
79
79
 
80
- type V1Model<T> = {
81
- get: <K extends keyof T = keyof T>( key: K ) => T[K],
82
- }
80
+ type V1Model< T > = {
81
+ get: < K extends keyof T = keyof T >( key: K ) => T[ K ];
82
+ };