@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.
- package/CHANGELOG.md +18 -96
- package/dist/index.js +99 -86
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +87 -74
- package/dist/index.mjs.map +1 -1
- package/package.json +42 -40
- package/src/components/logic-hooks.tsx +7 -0
- package/src/hooks/__tests__/use-active-document-actions.test.ts +3 -11
- package/src/hooks/__tests__/use-active-document.test.tsx +1 -1
- package/src/hooks/__tests__/use-host-document.test.tsx +15 -11
- package/src/hooks/__tests__/use-sync-document-title.test.ts +109 -0
- package/src/hooks/use-sync-document-title.ts +23 -0
- package/src/index.ts +1 -3
- package/src/init.ts +7 -0
- package/src/store/index.ts +11 -11
- package/src/store/selectors.ts +5 -13
- package/src/sync/__tests__/sync-store.test.ts +105 -108
- package/src/sync/__tests__/test-utils.ts +23 -19
- package/src/sync/sync-store.ts +52 -71
- package/src/sync/utils.ts +3 -2
- package/src/types.ts +58 -58
package/src/init.ts
CHANGED
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
import { syncStore } from './sync';
|
|
2
2
|
import { __registerSlice } from '@elementor/store';
|
|
3
3
|
import { slice } from './store';
|
|
4
|
+
import { injectIntoLogic } from '@elementor/editor';
|
|
5
|
+
import { LogicHooks } from './components/logic-hooks';
|
|
4
6
|
|
|
5
7
|
export default function init() {
|
|
6
8
|
initStore();
|
|
9
|
+
|
|
10
|
+
injectIntoLogic( {
|
|
11
|
+
id: 'documents-hooks',
|
|
12
|
+
component: LogicHooks,
|
|
13
|
+
} );
|
|
7
14
|
}
|
|
8
15
|
|
|
9
16
|
function initStore() {
|
package/src/store/index.ts
CHANGED
|
@@ -2,10 +2,10 @@ import { Document } from '../types';
|
|
|
2
2
|
import { __createSlice, PayloadAction } from '@elementor/store';
|
|
3
3
|
|
|
4
4
|
type State = {
|
|
5
|
-
entities: Record<Document['id'], Document
|
|
6
|
-
activeId: Document['id'] | null
|
|
7
|
-
hostId: Document['id'] | null
|
|
8
|
-
}
|
|
5
|
+
entities: Record< Document[ 'id' ], Document >;
|
|
6
|
+
activeId: Document[ 'id' ] | null; // The currently editing document.
|
|
7
|
+
hostId: Document[ 'id' ] | null; // The document that host all the other documents.
|
|
8
|
+
};
|
|
9
9
|
|
|
10
10
|
const initialState: State = {
|
|
11
11
|
entities: {},
|
|
@@ -13,7 +13,7 @@ const initialState: State = {
|
|
|
13
13
|
hostId: null,
|
|
14
14
|
};
|
|
15
15
|
|
|
16
|
-
type StateWithActiveId = Omit<State, 'activeId'> & { activeId: NonNullable<State['activeId']> };
|
|
16
|
+
type StateWithActiveId = Omit< State, 'activeId' > & { activeId: NonNullable< State[ 'activeId' ] > };
|
|
17
17
|
|
|
18
18
|
function hasActiveEntity( state: State ): state is StateWithActiveId {
|
|
19
19
|
return !! ( state.activeId && state.entities[ state.activeId ] );
|
|
@@ -23,22 +23,22 @@ export const slice = __createSlice( {
|
|
|
23
23
|
name: 'documents',
|
|
24
24
|
initialState,
|
|
25
25
|
reducers: {
|
|
26
|
-
init( state, { payload }
|
|
26
|
+
init( state, { payload }: PayloadAction< State > ) {
|
|
27
27
|
state.entities = payload.entities;
|
|
28
28
|
state.hostId = payload.hostId;
|
|
29
29
|
state.activeId = payload.activeId;
|
|
30
30
|
},
|
|
31
31
|
|
|
32
|
-
activateDocument( state, action: PayloadAction<Document> ) {
|
|
32
|
+
activateDocument( state, action: PayloadAction< Document > ) {
|
|
33
33
|
state.entities[ action.payload.id ] = action.payload;
|
|
34
34
|
state.activeId = action.payload.id;
|
|
35
35
|
},
|
|
36
36
|
|
|
37
|
-
setAsHost( state, action: PayloadAction<Document['id']> ) {
|
|
37
|
+
setAsHost( state, action: PayloadAction< Document[ 'id' ] > ) {
|
|
38
38
|
state.hostId = action.payload;
|
|
39
39
|
},
|
|
40
40
|
|
|
41
|
-
updateActiveDocument( state, action: PayloadAction<Partial<Document
|
|
41
|
+
updateActiveDocument( state, action: PayloadAction< Partial< Document > > ) {
|
|
42
42
|
if ( hasActiveEntity( state ) ) {
|
|
43
43
|
state.entities[ state.activeId ] = {
|
|
44
44
|
...state.entities[ state.activeId ],
|
|
@@ -53,7 +53,7 @@ export const slice = __createSlice( {
|
|
|
53
53
|
}
|
|
54
54
|
},
|
|
55
55
|
|
|
56
|
-
endSaving( state, action: PayloadAction<Document> ) {
|
|
56
|
+
endSaving( state, action: PayloadAction< Document > ) {
|
|
57
57
|
if ( hasActiveEntity( state ) ) {
|
|
58
58
|
state.entities[ state.activeId ] = {
|
|
59
59
|
...action.payload,
|
|
@@ -68,7 +68,7 @@ export const slice = __createSlice( {
|
|
|
68
68
|
}
|
|
69
69
|
},
|
|
70
70
|
|
|
71
|
-
endSavingDraft( state, action: PayloadAction<Document> ) {
|
|
71
|
+
endSavingDraft( state, action: PayloadAction< Document > ) {
|
|
72
72
|
if ( hasActiveEntity( state ) ) {
|
|
73
73
|
state.entities[ state.activeId ] = {
|
|
74
74
|
...action.payload,
|
package/src/store/selectors.ts
CHANGED
|
@@ -1,24 +1,16 @@
|
|
|
1
1
|
import { slice } from './index';
|
|
2
2
|
import { __createSelector, SliceState } from '@elementor/store';
|
|
3
3
|
|
|
4
|
-
type State = SliceState<typeof slice>;
|
|
4
|
+
type State = SliceState< typeof slice >;
|
|
5
5
|
|
|
6
6
|
const selectEntities = ( state: State ) => state.documents.entities;
|
|
7
7
|
const selectActiveId = ( state: State ) => state.documents.activeId;
|
|
8
8
|
const selectHostId = ( state: State ) => state.documents.hostId;
|
|
9
9
|
|
|
10
|
-
export const selectActiveDocument = __createSelector(
|
|
11
|
-
|
|
12
|
-
selectActiveId,
|
|
13
|
-
( entities, activeId ) => activeId && entities[ activeId ]
|
|
14
|
-
? entities[ activeId ]
|
|
15
|
-
: null,
|
|
10
|
+
export const selectActiveDocument = __createSelector( selectEntities, selectActiveId, ( entities, activeId ) =>
|
|
11
|
+
activeId && entities[ activeId ] ? entities[ activeId ] : null
|
|
16
12
|
);
|
|
17
13
|
|
|
18
|
-
export const selectHostDocument = __createSelector(
|
|
19
|
-
|
|
20
|
-
selectHostId,
|
|
21
|
-
( entities, hostId ) => hostId && entities[ hostId ]
|
|
22
|
-
? entities[ hostId ]
|
|
23
|
-
: null,
|
|
14
|
+
export const selectHostDocument = __createSelector( selectEntities, selectHostId, ( entities, hostId ) =>
|
|
15
|
+
hostId && entities[ hostId ] ? entities[ hostId ] : null
|
|
24
16
|
);
|
|
@@ -12,12 +12,12 @@ import {
|
|
|
12
12
|
import { selectActiveDocument } from '../../store/selectors';
|
|
13
13
|
import { getV1DocumentPermalink, getV1DocumentsExitTo } from '../utils';
|
|
14
14
|
|
|
15
|
-
type WindowWithOptionalElementor = Omit<ExtendedWindow, 'elementor'> & {
|
|
16
|
-
elementor?: ExtendedWindow['elementor'];
|
|
17
|
-
}
|
|
15
|
+
type WindowWithOptionalElementor = Omit< ExtendedWindow, 'elementor' > & {
|
|
16
|
+
elementor?: ExtendedWindow[ 'elementor' ];
|
|
17
|
+
};
|
|
18
18
|
|
|
19
19
|
describe( '@elementor/editor-documents - Sync Store', () => {
|
|
20
|
-
let store: Store<SliceState<typeof slice
|
|
20
|
+
let store: Store< SliceState< typeof slice > >;
|
|
21
21
|
|
|
22
22
|
beforeEach( () => {
|
|
23
23
|
jest.useFakeTimers();
|
|
@@ -34,10 +34,7 @@ describe( '@elementor/editor-documents - Sync Store', () => {
|
|
|
34
34
|
|
|
35
35
|
it( 'should sync documents on V1 load', () => {
|
|
36
36
|
// Arrange.
|
|
37
|
-
mockV1DocumentsManager( [
|
|
38
|
-
makeMockV1Document( { id: 1 } ),
|
|
39
|
-
makeMockV1Document( { id: 2 } ),
|
|
40
|
-
], 'this_post' );
|
|
37
|
+
mockV1DocumentsManager( [ makeMockV1Document( { id: 1 } ), makeMockV1Document( { id: 2 } ) ], 'this_post' );
|
|
41
38
|
|
|
42
39
|
// Act.
|
|
43
40
|
dispatchV1ReadyEvent();
|
|
@@ -45,7 +42,7 @@ describe( '@elementor/editor-documents - Sync Store', () => {
|
|
|
45
42
|
// Assert.
|
|
46
43
|
const storeState = store.getState();
|
|
47
44
|
|
|
48
|
-
expect( storeState.documents.entities ).toEqual<Record<number, Document
|
|
45
|
+
expect( storeState.documents.entities ).toEqual< Record< number, Document > >( {
|
|
49
46
|
1: {
|
|
50
47
|
id: 1,
|
|
51
48
|
title: 'Document 1',
|
|
@@ -112,10 +109,7 @@ describe( '@elementor/editor-documents - Sync Store', () => {
|
|
|
112
109
|
},
|
|
113
110
|
] )( 'should sync active document on $type', ( { dispatchEvent } ) => {
|
|
114
111
|
// Arrange.
|
|
115
|
-
mockV1DocumentsManager( [
|
|
116
|
-
makeMockV1Document( { id: 1 } ),
|
|
117
|
-
makeMockV1Document( { id: 2 } ),
|
|
118
|
-
], 'this_post', 2 );
|
|
112
|
+
mockV1DocumentsManager( [ makeMockV1Document( { id: 1 } ), makeMockV1Document( { id: 2 } ) ], 'this_post', 2 );
|
|
119
113
|
|
|
120
114
|
// Act.
|
|
121
115
|
dispatchEvent();
|
|
@@ -123,7 +117,7 @@ describe( '@elementor/editor-documents - Sync Store', () => {
|
|
|
123
117
|
// Assert.
|
|
124
118
|
const currentDocument = selectActiveDocument( store.getState() );
|
|
125
119
|
|
|
126
|
-
expect( currentDocument ).toEqual<Document>( {
|
|
120
|
+
expect( currentDocument ).toEqual< Document >( {
|
|
127
121
|
id: 2,
|
|
128
122
|
title: 'Document 2',
|
|
129
123
|
type: {
|
|
@@ -160,30 +154,27 @@ describe( '@elementor/editor-documents - Sync Store', () => {
|
|
|
160
154
|
openAsHost: false,
|
|
161
155
|
expectedHost: 1,
|
|
162
156
|
},
|
|
163
|
-
] )(
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
157
|
+
] )(
|
|
158
|
+
'should sync host document when a new host is opened { openAsHost: $openAsHost }',
|
|
159
|
+
( { openAsHost, expectedHost } ) => {
|
|
160
|
+
// Arrange.
|
|
161
|
+
const mockDocument1 = makeMockV1Document( { id: 1 } );
|
|
162
|
+
const mockDocument2 = makeMockV1Document( { id: 2 } );
|
|
167
163
|
|
|
168
|
-
|
|
169
|
-
mockDocument1,
|
|
170
|
-
mockDocument2,
|
|
171
|
-
], 'this_post', 1, 1 );
|
|
164
|
+
mockV1DocumentsManager( [ mockDocument1, mockDocument2 ], 'this_post', 1, 1 );
|
|
172
165
|
|
|
173
|
-
|
|
174
|
-
|
|
166
|
+
// Populate the documents state.
|
|
167
|
+
dispatchV1ReadyEvent();
|
|
175
168
|
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
mockDocument1,
|
|
179
|
-
mockDocument2,
|
|
180
|
-
], 'this_post', 2, openAsHost ? 2 : 1 );
|
|
169
|
+
// Act - Mock a host document change.
|
|
170
|
+
mockV1DocumentsManager( [ mockDocument1, mockDocument2 ], 'this_post', 2, openAsHost ? 2 : 1 );
|
|
181
171
|
|
|
182
|
-
|
|
172
|
+
dispatchCommandAfter( 'editor/documents/open' );
|
|
183
173
|
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
174
|
+
// Assert.
|
|
175
|
+
expect( store.getState().documents.hostId ).toBe( expectedHost );
|
|
176
|
+
}
|
|
177
|
+
);
|
|
187
178
|
|
|
188
179
|
it( 'should sync saving state of a document on V1 load', () => {
|
|
189
180
|
// Arrange.
|
|
@@ -208,9 +199,7 @@ describe( '@elementor/editor-documents - Sync Store', () => {
|
|
|
208
199
|
|
|
209
200
|
it( 'should sync saving state of a document on save', () => {
|
|
210
201
|
// Arrange.
|
|
211
|
-
mockV1DocumentsManager( [
|
|
212
|
-
makeMockV1Document(),
|
|
213
|
-
] );
|
|
202
|
+
mockV1DocumentsManager( [ makeMockV1Document() ] );
|
|
214
203
|
|
|
215
204
|
// Populate the documents state.
|
|
216
205
|
dispatchV1ReadyEvent();
|
|
@@ -235,9 +224,7 @@ describe( '@elementor/editor-documents - Sync Store', () => {
|
|
|
235
224
|
|
|
236
225
|
it( 'should sync draft saving state of a document on save', () => {
|
|
237
226
|
// Arrange.
|
|
238
|
-
mockV1DocumentsManager( [
|
|
239
|
-
makeMockV1Document(),
|
|
240
|
-
] );
|
|
227
|
+
mockV1DocumentsManager( [ makeMockV1Document() ] );
|
|
241
228
|
|
|
242
229
|
// Populate the documents state.
|
|
243
230
|
dispatchV1ReadyEvent();
|
|
@@ -268,15 +255,17 @@ describe( '@elementor/editor-documents - Sync Store', () => {
|
|
|
268
255
|
// Arrange.
|
|
269
256
|
const mockDocument = makeMockV1Document( { id: 1 } );
|
|
270
257
|
|
|
271
|
-
mockV1DocumentsManager( [
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
258
|
+
mockV1DocumentsManager( [
|
|
259
|
+
{
|
|
260
|
+
...mockDocument,
|
|
261
|
+
config: {
|
|
262
|
+
...mockDocument.config,
|
|
263
|
+
revisions: {
|
|
264
|
+
current_id: 2,
|
|
265
|
+
},
|
|
277
266
|
},
|
|
278
267
|
},
|
|
279
|
-
|
|
268
|
+
] );
|
|
280
269
|
|
|
281
270
|
// Act.
|
|
282
271
|
dispatchV1ReadyEvent();
|
|
@@ -289,9 +278,7 @@ describe( '@elementor/editor-documents - Sync Store', () => {
|
|
|
289
278
|
// Arrange.
|
|
290
279
|
const mockDocument = makeMockV1Document();
|
|
291
280
|
|
|
292
|
-
mockV1DocumentsManager( [
|
|
293
|
-
mockDocument,
|
|
294
|
-
] );
|
|
281
|
+
mockV1DocumentsManager( [ mockDocument ] );
|
|
295
282
|
|
|
296
283
|
// Populate the documents state.
|
|
297
284
|
dispatchV1ReadyEvent();
|
|
@@ -373,30 +360,38 @@ describe( '@elementor/editor-documents - Sync Store', () => {
|
|
|
373
360
|
|
|
374
361
|
it( 'should update the document when finish saving', () => {
|
|
375
362
|
// Arrange.
|
|
376
|
-
mockV1DocumentsManager(
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
363
|
+
mockV1DocumentsManager(
|
|
364
|
+
[
|
|
365
|
+
makeMockV1Document( {
|
|
366
|
+
id: 1,
|
|
367
|
+
status: 'draft',
|
|
368
|
+
title: 'test',
|
|
369
|
+
} ),
|
|
370
|
+
],
|
|
371
|
+
'this_post'
|
|
372
|
+
);
|
|
383
373
|
|
|
384
374
|
// Populate the documents state.
|
|
385
375
|
dispatchV1ReadyEvent();
|
|
386
376
|
|
|
387
377
|
// Mock a change.
|
|
388
|
-
mockV1DocumentsManager(
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
378
|
+
mockV1DocumentsManager(
|
|
379
|
+
[
|
|
380
|
+
makeMockV1Document( {
|
|
381
|
+
id: 1,
|
|
382
|
+
status: 'publish',
|
|
383
|
+
title: 'test title changed',
|
|
384
|
+
} ),
|
|
385
|
+
],
|
|
386
|
+
'dashboard'
|
|
387
|
+
);
|
|
395
388
|
|
|
396
389
|
// Assert.
|
|
397
390
|
expect( selectActiveDocument( store.getState() )?.title ).toBe( 'test' );
|
|
398
391
|
expect( selectActiveDocument( store.getState() )?.status.value ).toBe( 'draft' );
|
|
399
|
-
expect( selectActiveDocument( store.getState() )?.links.platformEdit ).toBe(
|
|
392
|
+
expect( selectActiveDocument( store.getState() )?.links.platformEdit ).toBe(
|
|
393
|
+
'https://localhost/wp-admin/post.php?post=1&action=edit'
|
|
394
|
+
);
|
|
400
395
|
|
|
401
396
|
// Act.
|
|
402
397
|
dispatchCommandAfter( 'document/save/save' );
|
|
@@ -407,55 +402,57 @@ describe( '@elementor/editor-documents - Sync Store', () => {
|
|
|
407
402
|
expect( selectActiveDocument( store.getState() )?.links.platformEdit ).toBe( 'https://localhost/wp-admin/' );
|
|
408
403
|
} );
|
|
409
404
|
|
|
410
|
-
it.each( [
|
|
411
|
-
'
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
const mockDocument = makeMockV1Document( { id: 1 } );
|
|
417
|
-
mockV1DocumentsManager( [
|
|
418
|
-
mockDocument,
|
|
419
|
-
], exitTo );
|
|
405
|
+
it.each( [ 'dashboard', 'this_post', 'all_posts' ] as ExitTo[] )(
|
|
406
|
+
'should sync active document $ExitTo',
|
|
407
|
+
( exitTo ) => {
|
|
408
|
+
// Arrange.
|
|
409
|
+
const mockDocument = makeMockV1Document( { id: 1 } );
|
|
410
|
+
mockV1DocumentsManager( [ mockDocument ], exitTo );
|
|
420
411
|
|
|
421
|
-
|
|
422
|
-
|
|
412
|
+
// Populate the documents state.
|
|
413
|
+
dispatchV1ReadyEvent();
|
|
423
414
|
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
415
|
+
// Assert.
|
|
416
|
+
const currentDocument = selectActiveDocument( store.getState() );
|
|
417
|
+
const platformEdit = getV1DocumentsExitTo( mockDocument );
|
|
418
|
+
const permalink = getV1DocumentPermalink( mockDocument );
|
|
428
419
|
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
420
|
+
expect( currentDocument ).toEqual< Document >( {
|
|
421
|
+
id: 1,
|
|
422
|
+
title: 'Document 1',
|
|
423
|
+
type: {
|
|
424
|
+
value: 'wp-page',
|
|
425
|
+
label: 'WP-PAGE',
|
|
426
|
+
},
|
|
427
|
+
links: {
|
|
428
|
+
platformEdit,
|
|
429
|
+
permalink,
|
|
430
|
+
},
|
|
431
|
+
status: {
|
|
432
|
+
value: 'publish',
|
|
433
|
+
label: 'PUBLISH',
|
|
434
|
+
},
|
|
435
|
+
isDirty: false,
|
|
436
|
+
isSaving: false,
|
|
437
|
+
isSavingDraft: false,
|
|
438
|
+
userCan: {
|
|
439
|
+
publish: true,
|
|
440
|
+
},
|
|
441
|
+
permissions: {
|
|
442
|
+
allowAddingWidgets: true,
|
|
443
|
+
showCopyAndShare: false,
|
|
444
|
+
},
|
|
445
|
+
} );
|
|
446
|
+
}
|
|
447
|
+
);
|
|
456
448
|
} );
|
|
457
449
|
|
|
458
|
-
function mockV1DocumentsManager(
|
|
450
|
+
function mockV1DocumentsManager(
|
|
451
|
+
documentsArray: V1Document[],
|
|
452
|
+
exitTo: ExitTo = 'this_post',
|
|
453
|
+
current = 1,
|
|
454
|
+
initial = 1
|
|
455
|
+
) {
|
|
459
456
|
( window as unknown as WindowWithOptionalElementor ).elementor = {
|
|
460
457
|
getPreferences: () => exitTo,
|
|
461
458
|
documents: makeDocumentsManager( documentsArray, current, initial ),
|
|
@@ -1,21 +1,25 @@
|
|
|
1
1
|
import { V1Document } from '../../types';
|
|
2
2
|
|
|
3
3
|
export function dispatchCommandBefore( command: string, args: object = {} ) {
|
|
4
|
-
window.dispatchEvent(
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
4
|
+
window.dispatchEvent(
|
|
5
|
+
new CustomEvent( 'elementor/commands/run/before', {
|
|
6
|
+
detail: {
|
|
7
|
+
command,
|
|
8
|
+
args,
|
|
9
|
+
},
|
|
10
|
+
} )
|
|
11
|
+
);
|
|
10
12
|
}
|
|
11
13
|
|
|
12
14
|
export function dispatchCommandAfter( command: string, args: object = {} ) {
|
|
13
|
-
window.dispatchEvent(
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
window.dispatchEvent(
|
|
16
|
+
new CustomEvent( 'elementor/commands/run/after', {
|
|
17
|
+
detail: {
|
|
18
|
+
command,
|
|
19
|
+
args,
|
|
20
|
+
},
|
|
21
|
+
} )
|
|
22
|
+
);
|
|
19
23
|
}
|
|
20
24
|
|
|
21
25
|
export function dispatchWindowEvent( event: string ) {
|
|
@@ -27,7 +31,7 @@ export function dispatchV1ReadyEvent() {
|
|
|
27
31
|
}
|
|
28
32
|
|
|
29
33
|
export function makeDocumentsManager( documentsArray: V1Document[], current = 1, initial = current ) {
|
|
30
|
-
const documents = documentsArray.reduce( ( acc: Record<number, V1Document>, document ) => {
|
|
34
|
+
const documents = documentsArray.reduce( ( acc: Record< number, V1Document >, document ) => {
|
|
31
35
|
acc[ document.id ] = document;
|
|
32
36
|
|
|
33
37
|
return acc;
|
|
@@ -53,10 +57,10 @@ export function makeMockV1Document( {
|
|
|
53
57
|
status = 'publish',
|
|
54
58
|
type = 'wp-page',
|
|
55
59
|
}: {
|
|
56
|
-
id?: number
|
|
57
|
-
status?: string
|
|
58
|
-
title?: string
|
|
59
|
-
type?: string
|
|
60
|
+
id?: number;
|
|
61
|
+
status?: string;
|
|
62
|
+
title?: string;
|
|
63
|
+
type?: string;
|
|
60
64
|
} = {} ): V1Document {
|
|
61
65
|
return {
|
|
62
66
|
id,
|
|
@@ -97,10 +101,10 @@ export function makeMockV1Document( {
|
|
|
97
101
|
}
|
|
98
102
|
|
|
99
103
|
// Mock Backbone's settings model.
|
|
100
|
-
function makeV1Settings<T extends object>( settings: T ) {
|
|
104
|
+
function makeV1Settings< T extends object >( settings: T ) {
|
|
101
105
|
return {
|
|
102
106
|
get( key: keyof T ) {
|
|
103
107
|
return settings[ key ];
|
|
104
108
|
},
|
|
105
|
-
} as V1Document['container']['settings'];
|
|
109
|
+
} as V1Document[ 'container' ][ 'settings' ];
|
|
106
110
|
}
|