@wordpress/editor 14.19.3 → 14.21.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 (107) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/README.md +1 -1
  3. package/build/components/commands/index.js +1 -1
  4. package/build/components/commands/index.js.map +1 -1
  5. package/build/components/plugin-pre-publish-panel/index.js +1 -1
  6. package/build/components/plugin-pre-publish-panel/index.js.map +1 -1
  7. package/build/components/post-actions/actions.js +10 -8
  8. package/build/components/post-actions/actions.js.map +1 -1
  9. package/build/components/post-publish-panel/maybe-category-panel.js +19 -3
  10. package/build/components/post-publish-panel/maybe-category-panel.js.map +1 -1
  11. package/build/components/post-publish-panel/maybe-tags-panel.js +16 -6
  12. package/build/components/post-publish-panel/maybe-tags-panel.js.map +1 -1
  13. package/build/components/post-status/index.js +5 -1
  14. package/build/components/post-status/index.js.map +1 -1
  15. package/build/components/post-sticky/index.js +1 -1
  16. package/build/components/post-sticky/index.js.map +1 -1
  17. package/build/components/post-template/block-theme.js +1 -3
  18. package/build/components/post-template/block-theme.js.map +1 -1
  19. package/build/components/post-template/create-new-template-modal.js +1 -0
  20. package/build/components/post-template/create-new-template-modal.js.map +1 -1
  21. package/build/components/post-template/create-new-template.js +1 -4
  22. package/build/components/post-template/create-new-template.js.map +1 -1
  23. package/build/components/post-template/hooks.js +6 -5
  24. package/build/components/post-template/hooks.js.map +1 -1
  25. package/build/components/post-template/swap-template-button.js +2 -3
  26. package/build/components/post-template/swap-template-button.js.map +1 -1
  27. package/build/components/post-visibility/index.js +39 -109
  28. package/build/components/post-visibility/index.js.map +1 -1
  29. package/build/components/post-visibility/label.js +2 -2
  30. package/build/components/post-visibility/label.js.map +1 -1
  31. package/build/components/post-visibility/utils.js +14 -15
  32. package/build/components/post-visibility/utils.js.map +1 -1
  33. package/build/components/preview-dropdown/index.js +2 -4
  34. package/build/components/preview-dropdown/index.js.map +1 -1
  35. package/build-module/components/commands/index.js +1 -1
  36. package/build-module/components/commands/index.js.map +1 -1
  37. package/build-module/components/plugin-pre-publish-panel/index.js +1 -1
  38. package/build-module/components/plugin-pre-publish-panel/index.js.map +1 -1
  39. package/build-module/components/post-actions/actions.js +10 -8
  40. package/build-module/components/post-actions/actions.js.map +1 -1
  41. package/build-module/components/post-publish-panel/maybe-category-panel.js +19 -3
  42. package/build-module/components/post-publish-panel/maybe-category-panel.js.map +1 -1
  43. package/build-module/components/post-publish-panel/maybe-tags-panel.js +16 -6
  44. package/build-module/components/post-publish-panel/maybe-tags-panel.js.map +1 -1
  45. package/build-module/components/post-status/index.js +5 -1
  46. package/build-module/components/post-status/index.js.map +1 -1
  47. package/build-module/components/post-sticky/index.js +1 -1
  48. package/build-module/components/post-sticky/index.js.map +1 -1
  49. package/build-module/components/post-template/block-theme.js +1 -3
  50. package/build-module/components/post-template/block-theme.js.map +1 -1
  51. package/build-module/components/post-template/create-new-template-modal.js +1 -0
  52. package/build-module/components/post-template/create-new-template-modal.js.map +1 -1
  53. package/build-module/components/post-template/create-new-template.js +1 -4
  54. package/build-module/components/post-template/create-new-template.js.map +1 -1
  55. package/build-module/components/post-template/hooks.js +6 -5
  56. package/build-module/components/post-template/hooks.js.map +1 -1
  57. package/build-module/components/post-template/swap-template-button.js +2 -3
  58. package/build-module/components/post-template/swap-template-button.js.map +1 -1
  59. package/build-module/components/post-visibility/index.js +41 -111
  60. package/build-module/components/post-visibility/index.js.map +1 -1
  61. package/build-module/components/post-visibility/label.js +3 -3
  62. package/build-module/components/post-visibility/label.js.map +1 -1
  63. package/build-module/components/post-visibility/utils.js +13 -14
  64. package/build-module/components/post-visibility/utils.js.map +1 -1
  65. package/build-module/components/preview-dropdown/index.js +2 -4
  66. package/build-module/components/preview-dropdown/index.js.map +1 -1
  67. package/build-style/style-rtl.css +6 -137
  68. package/build-style/style.css +6 -137
  69. package/build-types/components/plugin-pre-publish-panel/index.d.ts +1 -1
  70. package/build-types/components/post-actions/actions.d.ts.map +1 -1
  71. package/build-types/components/post-publish-panel/maybe-category-panel.d.ts.map +1 -1
  72. package/build-types/components/post-publish-panel/maybe-tags-panel.d.ts.map +1 -1
  73. package/build-types/components/post-status/index.d.ts.map +1 -1
  74. package/build-types/components/post-template/block-theme.d.ts.map +1 -1
  75. package/build-types/components/post-template/create-new-template-modal.d.ts.map +1 -1
  76. package/build-types/components/post-template/create-new-template.d.ts +1 -3
  77. package/build-types/components/post-template/create-new-template.d.ts.map +1 -1
  78. package/build-types/components/post-template/hooks.d.ts.map +1 -1
  79. package/build-types/components/post-template/swap-template-button.d.ts +1 -1
  80. package/build-types/components/post-template/swap-template-button.d.ts.map +1 -1
  81. package/build-types/components/post-visibility/index.d.ts.map +1 -1
  82. package/build-types/components/post-visibility/label.d.ts.map +1 -1
  83. package/build-types/components/post-visibility/utils.d.ts +5 -20
  84. package/build-types/components/post-visibility/utils.d.ts.map +1 -1
  85. package/build-types/components/preview-dropdown/index.d.ts.map +1 -1
  86. package/package.json +37 -37
  87. package/src/components/autocompleters/style.scss +2 -3
  88. package/src/components/commands/index.js +1 -1
  89. package/src/components/plugin-pre-publish-panel/index.js +1 -1
  90. package/src/components/post-actions/actions.js +13 -8
  91. package/src/components/post-publish-panel/maybe-category-panel.js +20 -5
  92. package/src/components/post-publish-panel/maybe-tags-panel.js +39 -22
  93. package/src/components/post-status/index.js +7 -2
  94. package/src/components/post-sticky/index.js +1 -1
  95. package/src/components/post-template/block-theme.js +1 -3
  96. package/src/components/post-template/create-new-template-modal.js +1 -0
  97. package/src/components/post-template/create-new-template.js +1 -2
  98. package/src/components/post-template/hooks.js +12 -8
  99. package/src/components/post-template/style.scss +4 -0
  100. package/src/components/post-template/swap-template-button.js +6 -4
  101. package/src/components/post-visibility/index.js +41 -118
  102. package/src/components/post-visibility/label.js +7 -4
  103. package/src/components/post-visibility/utils.js +11 -8
  104. package/src/components/preview-dropdown/index.js +6 -3
  105. package/src/style.scss +0 -1
  106. package/tsconfig.tsbuildinfo +1 -1
  107. package/src/components/post-visibility/style.scss +0 -27
@@ -1,21 +1,6 @@
1
- export namespace visibilityOptions {
2
- export namespace _public {
3
- let label: string;
4
- let info: string;
5
- }
6
- export { _public as public };
7
- export namespace _private {
8
- let label_1: string;
9
- export { label_1 as label };
10
- let info_1: string;
11
- export { info_1 as info };
12
- }
13
- export { _private as private };
14
- export namespace password {
15
- let label_2: string;
16
- export { label_2 as label };
17
- let info_2: string;
18
- export { info_2 as info };
19
- }
20
- }
1
+ export const VISIBILITY_OPTIONS: {
2
+ label: string;
3
+ value: string;
4
+ description: string;
5
+ }[];
21
6
  //# sourceMappingURL=utils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/components/post-visibility/utils.js"],"names":[],"mappings":""}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/components/post-visibility/utils.js"],"names":[],"mappings":"AAKA;;;;IAgBE"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/preview-dropdown/index.js"],"names":[],"mappings":"AAgCA;;;uCAwKC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/preview-dropdown/index.js"],"names":[],"mappings":"AAgCA;;;uCA2KC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wordpress/editor",
3
- "version": "14.19.3",
3
+ "version": "14.21.0",
4
4
  "description": "Enhanced block editor for WordPress posts.",
5
5
  "author": "The WordPress Contributors",
6
6
  "license": "GPL-2.0-or-later",
@@ -34,41 +34,41 @@
34
34
  ],
35
35
  "dependencies": {
36
36
  "@babel/runtime": "7.25.7",
37
- "@wordpress/a11y": "^4.19.1",
38
- "@wordpress/api-fetch": "^7.19.1",
39
- "@wordpress/blob": "^4.19.1",
40
- "@wordpress/block-editor": "^14.14.2",
41
- "@wordpress/blocks": "^14.8.1",
42
- "@wordpress/commands": "^1.19.1",
43
- "@wordpress/components": "^29.5.1",
44
- "@wordpress/compose": "^7.19.1",
45
- "@wordpress/core-data": "^7.19.2",
46
- "@wordpress/data": "^10.19.1",
47
- "@wordpress/dataviews": "^4.15.1",
48
- "@wordpress/date": "^5.19.1",
49
- "@wordpress/deprecated": "^4.19.1",
50
- "@wordpress/dom": "^4.19.1",
51
- "@wordpress/element": "^6.19.1",
52
- "@wordpress/fields": "^0.11.2",
53
- "@wordpress/hooks": "^4.19.1",
54
- "@wordpress/html-entities": "^4.19.1",
55
- "@wordpress/i18n": "^5.19.1",
56
- "@wordpress/icons": "^10.19.1",
57
- "@wordpress/interface": "^9.4.1",
58
- "@wordpress/keyboard-shortcuts": "^5.19.1",
59
- "@wordpress/keycodes": "^4.19.1",
60
- "@wordpress/media-utils": "^5.19.1",
61
- "@wordpress/notices": "^5.19.1",
62
- "@wordpress/patterns": "^2.19.2",
63
- "@wordpress/plugins": "^7.19.1",
64
- "@wordpress/preferences": "^4.19.1",
65
- "@wordpress/private-apis": "^1.19.1",
66
- "@wordpress/reusable-blocks": "^5.19.2",
67
- "@wordpress/rich-text": "^7.19.1",
68
- "@wordpress/server-side-render": "^5.19.1",
69
- "@wordpress/url": "^4.19.1",
70
- "@wordpress/warning": "^3.19.1",
71
- "@wordpress/wordcount": "^4.19.1",
37
+ "@wordpress/a11y": "^4.21.0",
38
+ "@wordpress/api-fetch": "^7.21.0",
39
+ "@wordpress/blob": "^4.21.0",
40
+ "@wordpress/block-editor": "^14.16.0",
41
+ "@wordpress/blocks": "^14.10.0",
42
+ "@wordpress/commands": "^1.21.0",
43
+ "@wordpress/components": "^29.7.0",
44
+ "@wordpress/compose": "^7.21.0",
45
+ "@wordpress/core-data": "^7.21.0",
46
+ "@wordpress/data": "^10.21.0",
47
+ "@wordpress/dataviews": "^4.17.0",
48
+ "@wordpress/date": "^5.21.0",
49
+ "@wordpress/deprecated": "^4.21.0",
50
+ "@wordpress/dom": "^4.21.0",
51
+ "@wordpress/element": "^6.21.0",
52
+ "@wordpress/fields": "^0.13.0",
53
+ "@wordpress/hooks": "^4.21.0",
54
+ "@wordpress/html-entities": "^4.21.0",
55
+ "@wordpress/i18n": "^5.21.0",
56
+ "@wordpress/icons": "^10.21.0",
57
+ "@wordpress/interface": "^9.6.0",
58
+ "@wordpress/keyboard-shortcuts": "^5.21.0",
59
+ "@wordpress/keycodes": "^4.21.0",
60
+ "@wordpress/media-utils": "^5.21.0",
61
+ "@wordpress/notices": "^5.21.0",
62
+ "@wordpress/patterns": "^2.21.0",
63
+ "@wordpress/plugins": "^7.21.0",
64
+ "@wordpress/preferences": "^4.21.0",
65
+ "@wordpress/private-apis": "^1.21.0",
66
+ "@wordpress/reusable-blocks": "^5.21.0",
67
+ "@wordpress/rich-text": "^7.21.0",
68
+ "@wordpress/server-side-render": "^5.21.0",
69
+ "@wordpress/url": "^4.21.0",
70
+ "@wordpress/warning": "^3.21.0",
71
+ "@wordpress/wordcount": "^4.21.0",
72
72
  "change-case": "^4.1.2",
73
73
  "client-zip": "^2.4.5",
74
74
  "clsx": "^2.1.1",
@@ -88,5 +88,5 @@
88
88
  "publishConfig": {
89
89
  "access": "public"
90
90
  },
91
- "gitHead": "ebddb7a8df3d45e83f318436516d9b6225486703"
91
+ "gitHead": "104af00f9abcd7a4d36b87e648f148c72cc4ea5f"
92
92
  }
@@ -24,7 +24,6 @@
24
24
  }
25
25
  .editor-autocompleters__user-slug {
26
26
  margin-left: 8px;
27
- color: $gray-700;
28
27
  white-space: nowrap;
29
28
  text-overflow: ellipsis;
30
29
  overflow: none;
@@ -32,7 +31,7 @@
32
31
  flex-grow: 0;
33
32
  flex-shrink: 0;
34
33
  }
35
- &:hover .editor-autocompleters__user-slug {
36
- color: var(--wp-admin-theme-color);
34
+ &:not(.is-primary) .editor-autocompleters__user-slug {
35
+ color: $gray-700;
37
36
  }
38
37
  }
@@ -223,7 +223,7 @@ const getEditorCommandLoader = () =>
223
223
 
224
224
  commands.push( {
225
225
  name: 'core/open-settings-sidebar',
226
- label: __( 'Show or hide the Settings panel.' ),
226
+ label: __( 'Show or hide the Settings panel' ),
227
227
  icon: isRTL() ? drawerLeft : drawerRight,
228
228
  callback: ( { close } ) => {
229
229
  const activeSidebar = getActiveComplementaryArea( 'core' );
@@ -17,7 +17,7 @@ const { Fill, Slot } = createSlotFill( 'PluginPrePublishPanel' );
17
17
  * When no title is provided it is always opened.
18
18
  * @param {WPBlockTypeIconRender} [props.icon=inherits from the plugin] The [Dashicon](https://developer.wordpress.org/resource/dashicons/)
19
19
  * icon slug string, or an SVG WP element, to be rendered when
20
- * the sidebar is pinned to toolbar.
20
+ * the sidebar is pinned to toolbar. If `false` is passed, no icon will be rendered.
21
21
  * @param {React.ReactNode} props.children Children to be rendered
22
22
  *
23
23
  * @example
@@ -26,21 +26,26 @@ export function usePostActions( { postType, onActionPerformed, context } ) {
26
26
 
27
27
  const { canManageOptions, hasFrontPageTemplate } = useSelect(
28
28
  ( select ) => {
29
- const { getEntityRecords } = select( coreStore );
30
- const templates = getEntityRecords( 'postType', 'wp_template', {
31
- per_page: -1,
29
+ const { getEntityRecords, canUser } = select( coreStore );
30
+ const canUpdateSettings = canUser( 'update', {
31
+ kind: 'root',
32
+ name: 'site',
32
33
  } );
34
+ const templates =
35
+ 'page' === postType && canUpdateSettings
36
+ ? getEntityRecords( 'postType', 'wp_template', {
37
+ per_page: -1,
38
+ } )
39
+ : [];
33
40
 
34
41
  return {
35
- canManageOptions: select( coreStore ).canUser( 'update', {
36
- kind: 'root',
37
- name: 'site',
38
- } ),
42
+ canManageOptions: canUpdateSettings,
39
43
  hasFrontPageTemplate: !! templates?.find(
40
44
  ( template ) => template?.slug === 'front-page'
41
45
  ),
42
46
  };
43
- }
47
+ },
48
+ [ postType ]
44
49
  );
45
50
 
46
51
  const setAsHomepageAction = useSetAsHomepageAction();
@@ -14,7 +14,7 @@ import HierarchicalTermSelector from '../post-taxonomies/hierarchical-term-selec
14
14
  import { store as editorStore } from '../../store';
15
15
 
16
16
  function MaybeCategoryPanel() {
17
- const hasNoCategory = useSelect( ( select ) => {
17
+ const { hasNoCategory, hasSiteCategories } = useSelect( ( select ) => {
18
18
  const postType = select( editorStore ).getCurrentPostType();
19
19
  const { canUser, getEntityRecord } = select( coreStore );
20
20
  const categoriesTaxonomy = getEntityRecord(
@@ -39,19 +39,30 @@ function MaybeCategoryPanel() {
39
39
  select( editorStore ).getEditedPostAttribute(
40
40
  categoriesTaxonomy.rest_base
41
41
  );
42
+ const siteCategories = postTypeSupportsCategories
43
+ ? !! select( coreStore ).getEntityRecords( 'taxonomy', 'category', {
44
+ exclude: [ defaultCategoryId ],
45
+ per_page: 1,
46
+ } )?.length
47
+ : false;
42
48
 
43
49
  // This boolean should return true if everything is loaded
44
50
  // ( categoriesTaxonomy, defaultCategory )
45
51
  // and the post has not been assigned a category different than "uncategorized".
46
- return (
52
+ const noCategory =
47
53
  !! categoriesTaxonomy &&
48
54
  !! defaultCategory &&
49
55
  postTypeSupportsCategories &&
50
56
  ( categories?.length === 0 ||
51
57
  ( categories?.length === 1 &&
52
- defaultCategory?.id === categories[ 0 ] ) )
53
- );
58
+ defaultCategory?.id === categories[ 0 ] ) );
59
+
60
+ return {
61
+ hasNoCategory: noCategory,
62
+ hasSiteCategories: siteCategories,
63
+ };
54
64
  }, [] );
65
+
55
66
  const [ shouldShowPanel, setShouldShowPanel ] = useState( false );
56
67
  useEffect( () => {
57
68
  // We use state to avoid hiding the panel if the user edits the categories
@@ -61,7 +72,11 @@ function MaybeCategoryPanel() {
61
72
  }
62
73
  }, [ hasNoCategory ] );
63
74
 
64
- if ( ! shouldShowPanel ) {
75
+ // We only want to show the category panel:
76
+ // if the post type supports categories,
77
+ // if the site has categories other than the default category,
78
+ // and if the post has no other categories than the default category.
79
+ if ( ! shouldShowPanel || ! hasSiteCategories ) {
65
80
  return null;
66
81
  }
67
82
 
@@ -34,28 +34,45 @@ const TagsPanel = () => {
34
34
  };
35
35
 
36
36
  const MaybeTagsPanel = () => {
37
- const { hasTags, isPostTypeSupported } = useSelect( ( select ) => {
38
- const postType = select( editorStore ).getCurrentPostType();
39
- const tagsTaxonomy = select( coreStore ).getEntityRecord(
40
- 'root',
41
- 'taxonomy',
42
- 'post_tag'
43
- );
44
- const _isPostTypeSupported = tagsTaxonomy?.types?.includes( postType );
45
- const areTagsFetched = tagsTaxonomy !== undefined;
46
- const tags =
47
- tagsTaxonomy &&
48
- select( editorStore ).getEditedPostAttribute(
49
- tagsTaxonomy.rest_base
37
+ const { postHasTags, siteHasTags, isPostTypeSupported } = useSelect(
38
+ ( select ) => {
39
+ const postType = select( editorStore ).getCurrentPostType();
40
+ const tagsTaxonomy = select( coreStore ).getEntityRecord(
41
+ 'root',
42
+ 'taxonomy',
43
+ 'post_tag'
50
44
  );
51
- return {
52
- hasTags: !! tags?.length,
53
- isPostTypeSupported: areTagsFetched && _isPostTypeSupported,
54
- };
55
- }, [] );
56
- const [ hadTagsWhenOpeningThePanel ] = useState( hasTags );
45
+ const _isPostTypeSupported =
46
+ tagsTaxonomy?.types?.includes( postType );
47
+ const areTagsFetched = tagsTaxonomy !== undefined;
48
+ const tags =
49
+ tagsTaxonomy &&
50
+ select( editorStore ).getEditedPostAttribute(
51
+ tagsTaxonomy.rest_base
52
+ );
53
+ const siteTags = _isPostTypeSupported
54
+ ? !! select( coreStore ).getEntityRecords(
55
+ 'taxonomy',
56
+ 'post_tag',
57
+ { per_page: 1 }
58
+ )?.length
59
+ : false;
57
60
 
58
- if ( ! isPostTypeSupported ) {
61
+ return {
62
+ postHasTags: !! tags?.length,
63
+ siteHasTags: siteTags,
64
+ isPostTypeSupported: areTagsFetched && _isPostTypeSupported,
65
+ };
66
+ },
67
+ []
68
+ );
69
+ const [ hadTagsWhenOpeningThePanel ] = useState( postHasTags );
70
+
71
+ /**
72
+ * We only want to show the tag panel if the post type supports
73
+ * tags and the site has tags.
74
+ */
75
+ if ( ! isPostTypeSupported || ! siteHasTags ) {
59
76
  return null;
60
77
  }
61
78
 
@@ -63,9 +80,9 @@ const MaybeTagsPanel = () => {
63
80
  * We only want to show the tag panel if the post didn't have
64
81
  * any tags when the user hit the Publish button.
65
82
  *
66
- * We can't use the prop.hasTags because it'll change to true
83
+ * We can't use the prop.postHasTags because it'll change to true
67
84
  * if the user adds a new tag within the pre-publish panel.
68
- * This would force a re-render and a new prop.hasTags check,
85
+ * This would force a re-render and a new prop.postHasTags check,
69
86
  * hiding this panel and keeping the user from adding
70
87
  * more than one tag.
71
88
  */
@@ -194,7 +194,12 @@ export default function PostStatus() {
194
194
  title={ __( 'Status & visibility' ) }
195
195
  onClose={ onClose }
196
196
  />
197
- <form>
197
+ <form
198
+ onSubmit={ ( event ) => {
199
+ event.preventDefault();
200
+ onClose();
201
+ } }
202
+ >
198
203
  <VStack spacing={ 4 }>
199
204
  <RadioControl
200
205
  className="editor-change-status__options"
@@ -230,7 +235,7 @@ export default function PostStatus() {
230
235
  'Password protected'
231
236
  ) }
232
237
  help={ __(
233
- 'Only visible to those who know the password'
238
+ 'Only visible to those who know the password.'
234
239
  ) }
235
240
  checked={ showPassword }
236
241
  onChange={
@@ -29,7 +29,7 @@ export default function PostSticky() {
29
29
  <CheckboxControl
30
30
  className="editor-post-sticky__checkbox-control"
31
31
  label={ __( 'Sticky' ) }
32
- help={ __( 'Pin this post to the top of the blog' ) }
32
+ help={ __( 'Pin this post to the top of the blog.' ) }
33
33
  checked={ postSticky }
34
34
  onChange={ () => editPost( { sticky: ! postSticky } ) }
35
35
  __nextHasNoMarginBottom
@@ -141,9 +141,7 @@ export default function BlockThemeControl( { id } ) {
141
141
 
142
142
  <SwapTemplateButton onClick={ onClose } />
143
143
  <ResetDefaultTemplate onClick={ onClose } />
144
- { canCreateTemplate && (
145
- <CreateNewTemplate onClick={ onClose } />
146
- ) }
144
+ { canCreateTemplate && <CreateNewTemplate /> }
147
145
  </MenuGroup>
148
146
  <MenuGroup>
149
147
  <MenuItem
@@ -111,6 +111,7 @@ export default function CreateNewTemplateModal( { onClose } ) {
111
111
  onRequestClose={ cancel }
112
112
  focusOnMount="firstContentElement"
113
113
  size="small"
114
+ overlayClassName="editor-post-template__create-template-modal"
114
115
  >
115
116
  <form
116
117
  className="editor-post-template__create-form"
@@ -13,7 +13,7 @@ import { useState } from '@wordpress/element';
13
13
  import CreateNewTemplateModal from './create-new-template-modal';
14
14
  import { useAllowSwitchingTemplates } from './hooks';
15
15
 
16
- export default function CreateNewTemplate( { onClick } ) {
16
+ export default function CreateNewTemplate() {
17
17
  const { canCreateTemplates } = useSelect( ( select ) => {
18
18
  const { canUser } = select( coreStore );
19
19
  return {
@@ -44,7 +44,6 @@ export default function CreateNewTemplate( { onClick } ) {
44
44
  <CreateNewTemplateModal
45
45
  onClose={ () => {
46
46
  setIsCreateModalOpen( false );
47
- onClick();
48
47
  } }
49
48
  />
50
49
  ) }
@@ -31,17 +31,21 @@ export function useAllowSwitchingTemplates() {
31
31
  } )
32
32
  ? getEntityRecord( 'root', 'site' )
33
33
  : undefined;
34
- const templates = getEntityRecords( 'postType', 'wp_template', {
35
- per_page: -1,
36
- } );
34
+
37
35
  const isPostsPage = +postId === siteSettings?.page_for_posts;
36
+ const isFrontPage =
37
+ postType === 'page' && +postId === siteSettings?.page_on_front;
38
38
  // If current page is set front page or posts page, we also need
39
39
  // to check if the current theme has a template for it. If not
40
- const isFrontPage =
41
- postType === 'page' &&
42
- +postId === siteSettings?.page_on_front &&
43
- templates?.some( ( { slug } ) => slug === 'front-page' );
44
- return ! isPostsPage && ! isFrontPage;
40
+ const templates = isFrontPage
41
+ ? getEntityRecords( 'postType', 'wp_template', {
42
+ per_page: -1,
43
+ } )
44
+ : [];
45
+ const hasFrontPage =
46
+ isFrontPage &&
47
+ !! templates?.some( ( { slug } ) => slug === 'front-page' );
48
+ return ! isPostsPage && ! hasFrontPage;
45
49
  },
46
50
  [ postId, postType ]
47
51
  );
@@ -2,6 +2,10 @@
2
2
  z-index: z-index(".editor-post-template__swap-template-modal");
3
3
  }
4
4
 
5
+ .editor-post-template__create-template-modal {
6
+ z-index: z-index(".editor-post-template__create-template-modal");
7
+ }
8
+
5
9
  .editor-post-template__swap-template-modal-content .block-editor-block-patterns-list {
6
10
  column-count: 2;
7
11
  column-gap: $grid-unit-30;
@@ -20,9 +20,7 @@ export default function SwapTemplateButton( { onClick } ) {
20
20
  const { postType, postId } = useEditedPostContext();
21
21
  const availableTemplates = useAvailableTemplates( postType );
22
22
  const { editEntityRecord } = useDispatch( coreStore );
23
- if ( ! availableTemplates?.length ) {
24
- return null;
25
- }
23
+
26
24
  const onTemplateSelect = async ( template ) => {
27
25
  editEntityRecord(
28
26
  'postType',
@@ -36,7 +34,11 @@ export default function SwapTemplateButton( { onClick } ) {
36
34
  };
37
35
  return (
38
36
  <>
39
- <MenuItem onClick={ () => setShowModal( true ) }>
37
+ <MenuItem
38
+ disabled={ ! availableTemplates?.length }
39
+ accessibleWhenDisabled
40
+ onClick={ () => setShowModal( true ) }
41
+ >
40
42
  { __( 'Change template' ) }
41
43
  </MenuItem>
42
44
  { showModal && (