@wordpress/editor 12.15.1-next.957ca95e4c.0 → 12.16.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/CHANGELOG.md +6 -0
- package/build/components/post-publish-panel/index.js +6 -1
- package/build/components/post-publish-panel/index.js.map +1 -1
- package/build/components/post-schedule/index.js +1 -1
- package/build/components/post-schedule/index.js.map +1 -1
- package/build/components/post-schedule/label.js +2 -2
- package/build/components/post-schedule/label.js.map +1 -1
- package/build/components/post-taxonomies/flat-term-selector.js +6 -15
- package/build/components/post-taxonomies/flat-term-selector.js.map +1 -1
- package/build/components/post-trash/index.js +5 -1
- package/build/components/post-trash/index.js.map +1 -1
- package/build/components/provider/use-block-editor-settings.js +13 -5
- package/build/components/provider/use-block-editor-settings.js.map +1 -1
- package/build/store/actions.js +7 -0
- package/build/store/actions.js.map +1 -1
- package/build/store/reducer.js +26 -0
- package/build/store/reducer.js.map +1 -1
- package/build/store/selectors.js +14 -0
- package/build/store/selectors.js.map +1 -1
- package/build-module/components/post-publish-panel/index.js +7 -2
- package/build-module/components/post-publish-panel/index.js.map +1 -1
- package/build-module/components/post-schedule/index.js +2 -4
- package/build-module/components/post-schedule/index.js.map +1 -1
- package/build-module/components/post-schedule/label.js +3 -4
- package/build-module/components/post-schedule/label.js.map +1 -1
- package/build-module/components/post-taxonomies/flat-term-selector.js +7 -15
- package/build-module/components/post-taxonomies/flat-term-selector.js.map +1 -1
- package/build-module/components/post-trash/index.js +5 -1
- package/build-module/components/post-trash/index.js.map +1 -1
- package/build-module/components/provider/use-block-editor-settings.js +14 -6
- package/build-module/components/provider/use-block-editor-settings.js.map +1 -1
- package/build-module/store/actions.js +7 -0
- package/build-module/store/actions.js.map +1 -1
- package/build-module/store/reducer.js +24 -0
- package/build-module/store/reducer.js.map +1 -1
- package/build-module/store/selectors.js +11 -0
- package/build-module/store/selectors.js.map +1 -1
- package/package.json +28 -28
- package/src/components/document-outline/test/__snapshots__/index.js.snap +92 -48
- package/src/components/document-outline/test/index.js +27 -44
- package/src/components/page-attributes/test/order.js +57 -64
- package/src/components/post-publish-button/test/index.js +88 -71
- package/src/components/post-publish-panel/index.js +7 -6
- package/src/components/post-publish-panel/test/__snapshots__/index.js.snap +670 -130
- package/src/components/post-publish-panel/test/index.js +30 -13
- package/src/components/post-saved-state/test/__snapshots__/index.js.snap +33 -24
- package/src/components/post-saved-state/test/index.js +31 -14
- package/src/components/post-schedule/index.js +2 -2
- package/src/components/post-schedule/label.js +3 -3
- package/src/components/post-schedule/test/label.js +7 -7
- package/src/components/post-slug/test/index.js +12 -25
- package/src/components/post-taxonomies/flat-term-selector.js +7 -18
- package/src/components/post-taxonomies/test/index.js +112 -44
- package/src/components/post-trash/index.js +5 -2
- package/src/components/provider/use-block-editor-settings.js +28 -8
- package/src/store/actions.js +2 -0
- package/src/store/reducer.js +21 -0
- package/src/store/selectors.js +11 -0
- package/src/store/test/actions.js +42 -0
|
@@ -11,10 +11,11 @@ import { useSelect, useDispatch } from '@wordpress/data';
|
|
|
11
11
|
import { store as editorStore } from '../../store';
|
|
12
12
|
|
|
13
13
|
export default function PostTrash() {
|
|
14
|
-
const { isNew, postId } = useSelect( ( select ) => {
|
|
14
|
+
const { isNew, isDeleting, postId } = useSelect( ( select ) => {
|
|
15
15
|
const store = select( editorStore );
|
|
16
16
|
return {
|
|
17
17
|
isNew: store.isEditedPostNew(),
|
|
18
|
+
isDeleting: store.isDeletingPost(),
|
|
18
19
|
postId: store.getCurrentPostId(),
|
|
19
20
|
};
|
|
20
21
|
}, [] );
|
|
@@ -29,7 +30,9 @@ export default function PostTrash() {
|
|
|
29
30
|
className="editor-post-trash"
|
|
30
31
|
isDestructive
|
|
31
32
|
variant="secondary"
|
|
32
|
-
|
|
33
|
+
isBusy={ isDeleting }
|
|
34
|
+
aria-disabled={ isDeleting }
|
|
35
|
+
onClick={ isDeleting ? undefined : () => trashPost() }
|
|
33
36
|
>
|
|
34
37
|
{ __( 'Move to trash' ) }
|
|
35
38
|
</Button>
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* External dependencies
|
|
3
3
|
*/
|
|
4
|
-
import { pick
|
|
4
|
+
import { pick } from 'lodash';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* WordPress dependencies
|
|
@@ -36,8 +36,10 @@ function useBlockEditorSettings( settings, hasTemplate ) {
|
|
|
36
36
|
canUseUnfilteredHTML,
|
|
37
37
|
userCanCreatePages,
|
|
38
38
|
pageOnFront,
|
|
39
|
+
postType,
|
|
39
40
|
} = useSelect( ( select ) => {
|
|
40
|
-
const { canUserUseUnfilteredHTML } =
|
|
41
|
+
const { canUserUseUnfilteredHTML, getCurrentPostType } =
|
|
42
|
+
select( editorStore );
|
|
41
43
|
const isWeb = Platform.OS === 'web';
|
|
42
44
|
const { canUser, getEntityRecord } = select( coreStore );
|
|
43
45
|
|
|
@@ -57,6 +59,7 @@ function useBlockEditorSettings( settings, hasTemplate ) {
|
|
|
57
59
|
hasUploadPermissions: canUser( 'create', 'media' ) ?? true,
|
|
58
60
|
userCanCreatePages: canUser( 'create', 'pages' ),
|
|
59
61
|
pageOnFront: siteSettings?.page_on_front,
|
|
62
|
+
postType: getCurrentPostType(),
|
|
60
63
|
};
|
|
61
64
|
}, [] );
|
|
62
65
|
|
|
@@ -77,16 +80,33 @@ function useBlockEditorSettings( settings, hasTemplate ) {
|
|
|
77
80
|
);
|
|
78
81
|
|
|
79
82
|
const blockPatterns = useMemo(
|
|
80
|
-
() =>
|
|
81
|
-
|
|
83
|
+
() =>
|
|
84
|
+
[
|
|
85
|
+
...( settingsBlockPatterns || [] ),
|
|
86
|
+
...( restBlockPatterns || [] ),
|
|
87
|
+
]
|
|
88
|
+
.filter(
|
|
89
|
+
( x, index, arr ) =>
|
|
90
|
+
index === arr.findIndex( ( y ) => x.name === y.name )
|
|
91
|
+
)
|
|
92
|
+
.filter( ( { postTypes } ) => {
|
|
93
|
+
return (
|
|
94
|
+
! postTypes ||
|
|
95
|
+
( Array.isArray( postTypes ) &&
|
|
96
|
+
postTypes.includes( postType ) )
|
|
97
|
+
);
|
|
98
|
+
} ),
|
|
99
|
+
[ settingsBlockPatterns, restBlockPatterns, postType ]
|
|
82
100
|
);
|
|
83
101
|
|
|
84
102
|
const blockPatternCategories = useMemo(
|
|
85
103
|
() =>
|
|
86
|
-
|
|
87
|
-
settingsBlockPatternCategories,
|
|
88
|
-
restBlockPatternCategories,
|
|
89
|
-
|
|
104
|
+
[
|
|
105
|
+
...( settingsBlockPatternCategories || [] ),
|
|
106
|
+
...( restBlockPatternCategories || [] ),
|
|
107
|
+
].filter(
|
|
108
|
+
( x, index, arr ) =>
|
|
109
|
+
index === arr.findIndex( ( y ) => x.name === y.name )
|
|
90
110
|
),
|
|
91
111
|
[ settingsBlockPatternCategories, restBlockPatternCategories ]
|
|
92
112
|
);
|
package/src/store/actions.js
CHANGED
|
@@ -247,6 +247,7 @@ export const trashPost =
|
|
|
247
247
|
registry.dispatch( noticesStore ).removeNotice( TRASH_POST_NOTICE_ID );
|
|
248
248
|
const { rest_base: restBase, rest_namespace: restNamespace = 'wp/v2' } =
|
|
249
249
|
postType;
|
|
250
|
+
dispatch( { type: 'REQUEST_POST_DELETE_START' } );
|
|
250
251
|
try {
|
|
251
252
|
const post = select.getCurrentPost();
|
|
252
253
|
await apiFetch( {
|
|
@@ -262,6 +263,7 @@ export const trashPost =
|
|
|
262
263
|
...getNotificationArgumentsForTrashFail( { error } )
|
|
263
264
|
);
|
|
264
265
|
}
|
|
266
|
+
dispatch( { type: 'REQUEST_POST_DELETE_FINISH' } );
|
|
265
267
|
};
|
|
266
268
|
|
|
267
269
|
/**
|
package/src/store/reducer.js
CHANGED
|
@@ -141,6 +141,26 @@ export function saving( state = {}, action ) {
|
|
|
141
141
|
return state;
|
|
142
142
|
}
|
|
143
143
|
|
|
144
|
+
/**
|
|
145
|
+
* Reducer returning deleting post request state.
|
|
146
|
+
*
|
|
147
|
+
* @param {Object} state Current state.
|
|
148
|
+
* @param {Object} action Dispatched action.
|
|
149
|
+
*
|
|
150
|
+
* @return {Object} Updated state.
|
|
151
|
+
*/
|
|
152
|
+
export function deleting( state = {}, action ) {
|
|
153
|
+
switch ( action.type ) {
|
|
154
|
+
case 'REQUEST_POST_DELETE_START':
|
|
155
|
+
case 'REQUEST_POST_DELETE_FINISH':
|
|
156
|
+
return {
|
|
157
|
+
pending: action.type === 'REQUEST_POST_DELETE_START',
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
return state;
|
|
162
|
+
}
|
|
163
|
+
|
|
144
164
|
/**
|
|
145
165
|
* Post Lock State.
|
|
146
166
|
*
|
|
@@ -263,6 +283,7 @@ export default combineReducers( {
|
|
|
263
283
|
postId,
|
|
264
284
|
postType,
|
|
265
285
|
saving,
|
|
286
|
+
deleting,
|
|
266
287
|
postLock,
|
|
267
288
|
template,
|
|
268
289
|
postSavingLock,
|
package/src/store/selectors.js
CHANGED
|
@@ -672,6 +672,17 @@ export function isEditedPostDateFloating( state ) {
|
|
|
672
672
|
return false;
|
|
673
673
|
}
|
|
674
674
|
|
|
675
|
+
/**
|
|
676
|
+
* Returns true if the post is currently being deleted, or false otherwise.
|
|
677
|
+
*
|
|
678
|
+
* @param {Object} state Editor state.
|
|
679
|
+
*
|
|
680
|
+
* @return {boolean} Whether post is being deleted.
|
|
681
|
+
*/
|
|
682
|
+
export function isDeletingPost( state ) {
|
|
683
|
+
return !! state.deleting.pending;
|
|
684
|
+
}
|
|
685
|
+
|
|
675
686
|
/**
|
|
676
687
|
* Returns true if the post is currently being saved, or false otherwise.
|
|
677
688
|
*
|
|
@@ -294,6 +294,48 @@ describe( 'Post actions', () => {
|
|
|
294
294
|
const { status } = registry.select( editorStore ).getCurrentPost();
|
|
295
295
|
expect( status ).toBe( 'trash' );
|
|
296
296
|
} );
|
|
297
|
+
|
|
298
|
+
it( 'sets deleting state', async () => {
|
|
299
|
+
const post = {
|
|
300
|
+
id: postId,
|
|
301
|
+
type: 'post',
|
|
302
|
+
content: 'foo',
|
|
303
|
+
status: 'publish',
|
|
304
|
+
};
|
|
305
|
+
|
|
306
|
+
const dispatch = Object.assign( jest.fn(), {
|
|
307
|
+
savePost: jest.fn(),
|
|
308
|
+
} );
|
|
309
|
+
const select = {
|
|
310
|
+
getCurrentPostType: () => 'post',
|
|
311
|
+
getCurrentPost: () => post,
|
|
312
|
+
};
|
|
313
|
+
const registry = {
|
|
314
|
+
dispatch: () => ( {
|
|
315
|
+
removeNotice: jest.fn(),
|
|
316
|
+
createErrorNotice: jest.fn(),
|
|
317
|
+
} ),
|
|
318
|
+
resolveSelect: () => ( {
|
|
319
|
+
getPostType: () => ( {
|
|
320
|
+
rest_namespace: 'wp/v2',
|
|
321
|
+
rest_base: 'posts',
|
|
322
|
+
} ),
|
|
323
|
+
} ),
|
|
324
|
+
};
|
|
325
|
+
|
|
326
|
+
apiFetch.setFetchHandler( async () => {
|
|
327
|
+
return { ...post, status: 'trash' };
|
|
328
|
+
} );
|
|
329
|
+
|
|
330
|
+
await actions.trashPost()( { select, dispatch, registry } );
|
|
331
|
+
|
|
332
|
+
expect( dispatch ).toHaveBeenCalledWith( {
|
|
333
|
+
type: 'REQUEST_POST_DELETE_START',
|
|
334
|
+
} );
|
|
335
|
+
expect( dispatch ).toHaveBeenCalledWith( {
|
|
336
|
+
type: 'REQUEST_POST_DELETE_FINISH',
|
|
337
|
+
} );
|
|
338
|
+
} );
|
|
297
339
|
} );
|
|
298
340
|
} );
|
|
299
341
|
|