@wordpress/editor 12.14.1-next.d6164808d3.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.
Files changed (70) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/build/components/post-featured-image/index.js +6 -4
  3. package/build/components/post-featured-image/index.js.map +1 -1
  4. package/build/components/post-publish-panel/index.js +6 -1
  5. package/build/components/post-publish-panel/index.js.map +1 -1
  6. package/build/components/post-schedule/index.js +1 -1
  7. package/build/components/post-schedule/index.js.map +1 -1
  8. package/build/components/post-schedule/label.js +2 -2
  9. package/build/components/post-schedule/label.js.map +1 -1
  10. package/build/components/post-taxonomies/flat-term-selector.js +6 -15
  11. package/build/components/post-taxonomies/flat-term-selector.js.map +1 -1
  12. package/build/components/post-trash/index.js +5 -1
  13. package/build/components/post-trash/index.js.map +1 -1
  14. package/build/components/post-url/label.js +1 -1
  15. package/build/components/post-url/label.js.map +1 -1
  16. package/build/components/provider/use-block-editor-settings.js +13 -5
  17. package/build/components/provider/use-block-editor-settings.js.map +1 -1
  18. package/build/store/actions.js +7 -0
  19. package/build/store/actions.js.map +1 -1
  20. package/build/store/reducer.js +26 -0
  21. package/build/store/reducer.js.map +1 -1
  22. package/build/store/selectors.js +14 -0
  23. package/build/store/selectors.js.map +1 -1
  24. package/build-module/components/post-featured-image/index.js +7 -5
  25. package/build-module/components/post-featured-image/index.js.map +1 -1
  26. package/build-module/components/post-publish-panel/index.js +7 -2
  27. package/build-module/components/post-publish-panel/index.js.map +1 -1
  28. package/build-module/components/post-schedule/index.js +2 -4
  29. package/build-module/components/post-schedule/index.js.map +1 -1
  30. package/build-module/components/post-schedule/label.js +3 -4
  31. package/build-module/components/post-schedule/label.js.map +1 -1
  32. package/build-module/components/post-taxonomies/flat-term-selector.js +7 -15
  33. package/build-module/components/post-taxonomies/flat-term-selector.js.map +1 -1
  34. package/build-module/components/post-trash/index.js +5 -1
  35. package/build-module/components/post-trash/index.js.map +1 -1
  36. package/build-module/components/post-url/label.js +1 -1
  37. package/build-module/components/post-url/label.js.map +1 -1
  38. package/build-module/components/provider/use-block-editor-settings.js +14 -6
  39. package/build-module/components/provider/use-block-editor-settings.js.map +1 -1
  40. package/build-module/store/actions.js +7 -0
  41. package/build-module/store/actions.js.map +1 -1
  42. package/build-module/store/reducer.js +24 -0
  43. package/build-module/store/reducer.js.map +1 -1
  44. package/build-module/store/selectors.js +11 -0
  45. package/build-module/store/selectors.js.map +1 -1
  46. package/package.json +28 -28
  47. package/src/components/document-outline/test/__snapshots__/index.js.snap +92 -48
  48. package/src/components/document-outline/test/index.js +27 -44
  49. package/src/components/page-attributes/test/order.js +57 -64
  50. package/src/components/post-featured-image/index.js +3 -3
  51. package/src/components/post-publish-button/test/index.js +88 -71
  52. package/src/components/post-publish-panel/index.js +7 -6
  53. package/src/components/post-publish-panel/test/__snapshots__/index.js.snap +670 -130
  54. package/src/components/post-publish-panel/test/index.js +30 -13
  55. package/src/components/post-saved-state/test/__snapshots__/index.js.snap +33 -24
  56. package/src/components/post-saved-state/test/index.js +31 -14
  57. package/src/components/post-schedule/index.js +2 -2
  58. package/src/components/post-schedule/label.js +3 -3
  59. package/src/components/post-schedule/test/label.js +7 -7
  60. package/src/components/post-slug/test/index.js +12 -25
  61. package/src/components/post-taxonomies/flat-term-selector.js +7 -18
  62. package/src/components/post-taxonomies/test/index.js +112 -44
  63. package/src/components/post-trash/index.js +5 -2
  64. package/src/components/post-url/label.js +1 -1
  65. package/src/components/provider/use-block-editor-settings.js +28 -8
  66. package/src/components/theme-support-check/test/index.js +13 -15
  67. package/src/store/actions.js +2 -0
  68. package/src/store/reducer.js +21 -0
  69. package/src/store/selectors.js +11 -0
  70. 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
- onClick={ () => trashPost() }
33
+ isBusy={ isDeleting }
34
+ aria-disabled={ isDeleting }
35
+ onClick={ isDeleting ? undefined : () => trashPost() }
33
36
  >
34
37
  { __( 'Move to trash' ) }
35
38
  </Button>
@@ -15,7 +15,7 @@ export default function PostURLLabel() {
15
15
 
16
16
  export function usePostURLLabel() {
17
17
  const postLink = useSelect(
18
- ( select ) => select( editorStore ).getCurrentPost().link,
18
+ ( select ) => select( editorStore ).getPermalink(),
19
19
  []
20
20
  );
21
21
  return filterURLForDisplay( safeDecodeURIComponent( postLink ) );
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * External dependencies
3
3
  */
4
- import { pick, unionBy } from 'lodash';
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 } = select( editorStore );
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
- () => unionBy( settingsBlockPatterns, restBlockPatterns, 'name' ),
81
- [ settingsBlockPatterns, restBlockPatterns ]
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
- unionBy(
87
- settingsBlockPatternCategories,
88
- restBlockPatternCategories,
89
- 'name'
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
  );
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * External dependencies
3
3
  */
4
- import { shallow } from 'enzyme';
4
+ import { render, screen } from '@testing-library/react';
5
5
 
6
6
  /**
7
7
  * Internal dependencies
@@ -10,10 +10,8 @@ import { ThemeSupportCheck } from '../index';
10
10
 
11
11
  describe( 'ThemeSupportCheck', () => {
12
12
  it( "should not render if there's no support check provided", () => {
13
- const wrapper = shallow(
14
- <ThemeSupportCheck>foobar</ThemeSupportCheck>
15
- );
16
- expect( wrapper.type() ).toBe( null );
13
+ render( <ThemeSupportCheck>foobar</ThemeSupportCheck> );
14
+ expect( screen.queryByText( 'foobar' ) ).not.toBeInTheDocument();
17
15
  } );
18
16
 
19
17
  it( 'should render if post-thumbnails are supported', () => {
@@ -21,7 +19,7 @@ describe( 'ThemeSupportCheck', () => {
21
19
  'post-thumbnails': true,
22
20
  };
23
21
  const supportKeys = 'post-thumbnails';
24
- const wrapper = shallow(
22
+ render(
25
23
  <ThemeSupportCheck
26
24
  supportKeys={ supportKeys }
27
25
  themeSupports={ themeSupports }
@@ -29,7 +27,7 @@ describe( 'ThemeSupportCheck', () => {
29
27
  foobar
30
28
  </ThemeSupportCheck>
31
29
  );
32
- expect( wrapper.type() ).not.toBe( null );
30
+ expect( screen.getByText( 'foobar' ) ).toBeVisible();
33
31
  } );
34
32
 
35
33
  it( 'should render if post-thumbnails are supported for the post type', () => {
@@ -37,7 +35,7 @@ describe( 'ThemeSupportCheck', () => {
37
35
  'post-thumbnails': [ 'post' ],
38
36
  };
39
37
  const supportKeys = 'post-thumbnails';
40
- const wrapper = shallow(
38
+ render(
41
39
  <ThemeSupportCheck
42
40
  supportKeys={ supportKeys }
43
41
  postType={ 'post' }
@@ -46,7 +44,7 @@ describe( 'ThemeSupportCheck', () => {
46
44
  foobar
47
45
  </ThemeSupportCheck>
48
46
  );
49
- expect( wrapper.type() ).not.toBe( null );
47
+ expect( screen.getByText( 'foobar' ) ).toBeVisible();
50
48
  } );
51
49
 
52
50
  it( "should not render if post-thumbnails aren't supported for the post type", () => {
@@ -54,7 +52,7 @@ describe( 'ThemeSupportCheck', () => {
54
52
  'post-thumbnails': [ 'post' ],
55
53
  };
56
54
  const supportKeys = 'post-thumbnails';
57
- const wrapper = shallow(
55
+ render(
58
56
  <ThemeSupportCheck
59
57
  supportKeys={ supportKeys }
60
58
  postType={ 'page' }
@@ -63,7 +61,7 @@ describe( 'ThemeSupportCheck', () => {
63
61
  foobar
64
62
  </ThemeSupportCheck>
65
63
  );
66
- expect( wrapper.type() ).toBe( null );
64
+ expect( screen.queryByText( 'foobar' ) ).not.toBeInTheDocument();
67
65
  } );
68
66
 
69
67
  it( 'should not render if post-thumbnails is limited and false is passed for postType', () => {
@@ -71,7 +69,7 @@ describe( 'ThemeSupportCheck', () => {
71
69
  'post-thumbnails': [ 'post' ],
72
70
  };
73
71
  const supportKeys = 'post-thumbnails';
74
- const wrapper = shallow(
72
+ render(
75
73
  <ThemeSupportCheck
76
74
  supportKeys={ supportKeys }
77
75
  postType={ false }
@@ -80,7 +78,7 @@ describe( 'ThemeSupportCheck', () => {
80
78
  foobar
81
79
  </ThemeSupportCheck>
82
80
  );
83
- expect( wrapper.type() ).toBe( null );
81
+ expect( screen.queryByText( 'foobar' ) ).not.toBeInTheDocument();
84
82
  } );
85
83
 
86
84
  it( "should not render if theme doesn't support post-thumbnails", () => {
@@ -88,7 +86,7 @@ describe( 'ThemeSupportCheck', () => {
88
86
  'post-thumbnails': false,
89
87
  };
90
88
  const supportKeys = 'post-thumbnails';
91
- const wrapper = shallow(
89
+ render(
92
90
  <ThemeSupportCheck
93
91
  supportKeys={ supportKeys }
94
92
  themeSupports={ themeSupports }
@@ -96,6 +94,6 @@ describe( 'ThemeSupportCheck', () => {
96
94
  foobar
97
95
  </ThemeSupportCheck>
98
96
  );
99
- expect( wrapper.type() ).toBe( null );
97
+ expect( screen.queryByText( 'foobar' ) ).not.toBeInTheDocument();
100
98
  } );
101
99
  } );
@@ -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
  /**
@@ -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,
@@ -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