@wordpress/editor 14.14.0 → 14.15.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 (180) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/LICENSE.md +1 -1
  3. package/README.md +1 -0
  4. package/build/components/commands/index.js +28 -0
  5. package/build/components/commands/index.js.map +1 -1
  6. package/build/components/document-bar/index.js +2 -1
  7. package/build/components/document-bar/index.js.map +1 -1
  8. package/build/components/document-tools/index.js +3 -6
  9. package/build/components/document-tools/index.js.map +1 -1
  10. package/build/components/editor-help/intro-to-blocks.native.js +1 -1
  11. package/build/components/editor-help/intro-to-blocks.native.js.map +1 -1
  12. package/build/components/entities-saved-states/index.js +2 -1
  13. package/build/components/entities-saved-states/index.js.map +1 -1
  14. package/build/components/error-boundary/index.native.js +1 -1
  15. package/build/components/error-boundary/index.native.js.map +1 -1
  16. package/build/components/more-menu/index.js +0 -1
  17. package/build/components/more-menu/index.js.map +1 -1
  18. package/build/components/post-actions/actions.js +9 -4
  19. package/build/components/post-actions/actions.js.map +1 -1
  20. package/build/components/post-actions/index.js +17 -14
  21. package/build/components/post-actions/index.js.map +1 -1
  22. package/build/components/post-actions/set-as-homepage.js +23 -34
  23. package/build/components/post-actions/set-as-homepage.js.map +1 -1
  24. package/build/components/post-actions/set-as-posts-page.js +154 -0
  25. package/build/components/post-actions/set-as-posts-page.js.map +1 -0
  26. package/build/components/post-card-panel/index.js +12 -5
  27. package/build/components/post-card-panel/index.js.map +1 -1
  28. package/build/components/post-publish-panel/maybe-upload-media.js +1 -1
  29. package/build/components/post-publish-panel/maybe-upload-media.js.map +1 -1
  30. package/build/components/preferences-modal/index.js +2 -4
  31. package/build/components/preferences-modal/index.js.map +1 -1
  32. package/build/components/preview-dropdown/index.js +0 -1
  33. package/build/components/preview-dropdown/index.js.map +1 -1
  34. package/build/components/provider/disable-non-page-content-blocks.js +65 -13
  35. package/build/components/provider/disable-non-page-content-blocks.js.map +1 -1
  36. package/build/components/provider/index.js +9 -13
  37. package/build/components/provider/index.js.map +1 -1
  38. package/build/components/provider/use-block-editor-settings.js +3 -1
  39. package/build/components/provider/use-block-editor-settings.js.map +1 -1
  40. package/build/components/start-page-options/index.js +20 -107
  41. package/build/components/start-page-options/index.js.map +1 -1
  42. package/build/components/template-part-menu-items/index.js +2 -10
  43. package/build/components/template-part-menu-items/index.js.map +1 -1
  44. package/build/store/actions.js +0 -2
  45. package/build/store/actions.js.map +1 -1
  46. package/build/store/constants.js +1 -3
  47. package/build/store/constants.js.map +1 -1
  48. package/build/store/private-actions.js +1 -1
  49. package/build/store/private-actions.js.map +1 -1
  50. package/build/store/utils/notice-builder.js +3 -8
  51. package/build/store/utils/notice-builder.js.map +1 -1
  52. package/build/utils/get-item-title.js +32 -0
  53. package/build/utils/get-item-title.js.map +1 -0
  54. package/build/utils/media-sideload/index.js +21 -0
  55. package/build/utils/media-sideload/index.js.map +1 -0
  56. package/build/utils/media-sideload/index.native.js +8 -0
  57. package/build/utils/media-sideload/index.native.js.map +1 -0
  58. package/build/utils/media-upload/index.js +5 -2
  59. package/build/utils/media-upload/index.js.map +1 -1
  60. package/build-module/components/commands/index.js +28 -0
  61. package/build-module/components/commands/index.js.map +1 -1
  62. package/build-module/components/document-bar/index.js +2 -1
  63. package/build-module/components/document-bar/index.js.map +1 -1
  64. package/build-module/components/document-tools/index.js +4 -7
  65. package/build-module/components/document-tools/index.js.map +1 -1
  66. package/build-module/components/editor-help/intro-to-blocks.native.js +1 -1
  67. package/build-module/components/editor-help/intro-to-blocks.native.js.map +1 -1
  68. package/build-module/components/entities-saved-states/index.js +2 -1
  69. package/build-module/components/entities-saved-states/index.js.map +1 -1
  70. package/build-module/components/error-boundary/index.native.js +2 -2
  71. package/build-module/components/error-boundary/index.native.js.map +1 -1
  72. package/build-module/components/more-menu/index.js +0 -1
  73. package/build-module/components/more-menu/index.js.map +1 -1
  74. package/build-module/components/post-actions/actions.js +9 -4
  75. package/build-module/components/post-actions/actions.js.map +1 -1
  76. package/build-module/components/post-actions/index.js +18 -15
  77. package/build-module/components/post-actions/index.js.map +1 -1
  78. package/build-module/components/post-actions/set-as-homepage.js +22 -33
  79. package/build-module/components/post-actions/set-as-homepage.js.map +1 -1
  80. package/build-module/components/post-actions/set-as-posts-page.js +146 -0
  81. package/build-module/components/post-actions/set-as-posts-page.js.map +1 -0
  82. package/build-module/components/post-card-panel/index.js +11 -6
  83. package/build-module/components/post-card-panel/index.js.map +1 -1
  84. package/build-module/components/post-publish-panel/maybe-upload-media.js +2 -2
  85. package/build-module/components/post-publish-panel/maybe-upload-media.js.map +1 -1
  86. package/build-module/components/preferences-modal/index.js +2 -4
  87. package/build-module/components/preferences-modal/index.js.map +1 -1
  88. package/build-module/components/preview-dropdown/index.js +0 -1
  89. package/build-module/components/preview-dropdown/index.js.map +1 -1
  90. package/build-module/components/provider/disable-non-page-content-blocks.js +65 -13
  91. package/build-module/components/provider/disable-non-page-content-blocks.js.map +1 -1
  92. package/build-module/components/provider/index.js +10 -14
  93. package/build-module/components/provider/index.js.map +1 -1
  94. package/build-module/components/provider/use-block-editor-settings.js +3 -1
  95. package/build-module/components/provider/use-block-editor-settings.js.map +1 -1
  96. package/build-module/components/start-page-options/index.js +21 -107
  97. package/build-module/components/start-page-options/index.js.map +1 -1
  98. package/build-module/components/template-part-menu-items/index.js +2 -10
  99. package/build-module/components/template-part-menu-items/index.js.map +1 -1
  100. package/build-module/store/actions.js +0 -2
  101. package/build-module/store/actions.js.map +1 -1
  102. package/build-module/store/constants.js +0 -2
  103. package/build-module/store/constants.js.map +1 -1
  104. package/build-module/store/private-actions.js +1 -1
  105. package/build-module/store/private-actions.js.map +1 -1
  106. package/build-module/store/utils/notice-builder.js +3 -8
  107. package/build-module/store/utils/notice-builder.js.map +1 -1
  108. package/build-module/utils/get-item-title.js +26 -0
  109. package/build-module/utils/get-item-title.js.map +1 -0
  110. package/build-module/utils/media-sideload/index.js +14 -0
  111. package/build-module/utils/media-sideload/index.js.map +1 -0
  112. package/build-module/utils/media-sideload/index.native.js +2 -0
  113. package/build-module/utils/media-sideload/index.native.js.map +1 -0
  114. package/build-module/utils/media-upload/index.js +5 -2
  115. package/build-module/utils/media-upload/index.js.map +1 -1
  116. package/build-style/style-rtl.css +5 -25
  117. package/build-style/style.css +5 -25
  118. package/build-types/components/commands/index.d.ts.map +1 -1
  119. package/build-types/components/document-bar/index.d.ts.map +1 -1
  120. package/build-types/components/document-tools/index.d.ts.map +1 -1
  121. package/build-types/components/entities-saved-states/index.d.ts.map +1 -1
  122. package/build-types/components/more-menu/index.d.ts.map +1 -1
  123. package/build-types/components/post-actions/actions.d.ts.map +1 -1
  124. package/build-types/components/post-actions/index.d.ts.map +1 -1
  125. package/build-types/components/post-actions/set-as-homepage.d.ts.map +1 -1
  126. package/build-types/components/post-actions/set-as-posts-page.d.ts +10 -0
  127. package/build-types/components/post-actions/set-as-posts-page.d.ts.map +1 -0
  128. package/build-types/components/post-card-panel/index.d.ts.map +1 -1
  129. package/build-types/components/preferences-modal/index.d.ts.map +1 -1
  130. package/build-types/components/preview-dropdown/index.d.ts.map +1 -1
  131. package/build-types/components/provider/disable-non-page-content-blocks.d.ts.map +1 -1
  132. package/build-types/components/provider/index.d.ts.map +1 -1
  133. package/build-types/components/provider/use-block-editor-settings.d.ts.map +1 -1
  134. package/build-types/components/start-page-options/index.d.ts +1 -2
  135. package/build-types/components/start-page-options/index.d.ts.map +1 -1
  136. package/build-types/store/actions.d.ts.map +1 -1
  137. package/build-types/store/constants.d.ts +0 -2
  138. package/build-types/store/constants.d.ts.map +1 -1
  139. package/build-types/store/private-actions.d.ts.map +1 -1
  140. package/build-types/store/utils/notice-builder.d.ts.map +1 -1
  141. package/build-types/utils/get-item-title.d.ts +10 -0
  142. package/build-types/utils/get-item-title.d.ts.map +1 -0
  143. package/build-types/utils/media-sideload/index.d.ts +3 -0
  144. package/build-types/utils/media-sideload/index.d.ts.map +1 -0
  145. package/build-types/utils/media-upload/index.d.ts +3 -1
  146. package/build-types/utils/media-upload/index.d.ts.map +1 -1
  147. package/package.json +37 -37
  148. package/src/components/commands/index.js +29 -0
  149. package/src/components/document-bar/index.js +2 -1
  150. package/src/components/document-tools/index.js +3 -6
  151. package/src/components/document-tools/style.scss +0 -6
  152. package/src/components/editor-help/intro-to-blocks.native.js +1 -1
  153. package/src/components/entities-saved-states/index.js +5 -1
  154. package/src/components/error-boundary/index.native.js +2 -2
  155. package/src/components/more-menu/index.js +0 -1
  156. package/src/components/post-actions/actions.js +12 -4
  157. package/src/components/post-actions/index.js +19 -17
  158. package/src/components/post-actions/set-as-homepage.js +29 -45
  159. package/src/components/post-actions/set-as-posts-page.js +164 -0
  160. package/src/components/post-card-panel/index.js +8 -6
  161. package/src/components/post-card-panel/style.scss +4 -13
  162. package/src/components/post-publish-panel/maybe-upload-media.js +2 -2
  163. package/src/components/preferences-modal/index.js +8 -13
  164. package/src/components/preview-dropdown/index.js +0 -1
  165. package/src/components/provider/disable-non-page-content-blocks.js +64 -13
  166. package/src/components/provider/index.js +13 -27
  167. package/src/components/provider/use-block-editor-settings.js +3 -0
  168. package/src/components/start-page-options/index.js +28 -119
  169. package/src/components/template-part-menu-items/index.js +2 -11
  170. package/src/store/actions.js +0 -2
  171. package/src/store/constants.ts +0 -2
  172. package/src/store/private-actions.js +1 -1
  173. package/src/store/utils/notice-builder.js +3 -8
  174. package/src/store/utils/test/notice-builder.js +3 -4
  175. package/src/utils/get-item-title.js +25 -0
  176. package/src/utils/media-sideload/index.js +13 -0
  177. package/src/utils/media-sideload/index.native.js +1 -0
  178. package/src/utils/media-upload/index.js +4 -1
  179. package/tsconfig.json +1 -4
  180. package/tsconfig.tsbuildinfo +1 -1
@@ -16,9 +16,13 @@ import usePostContentBlocks from './use-post-content-blocks';
16
16
  */
17
17
  export default function DisableNonPageContentBlocks() {
18
18
  const contentOnlyIds = usePostContentBlocks();
19
- const templateParts = useSelect( ( select ) => {
20
- const { getBlocksByName } = select( blockEditorStore );
21
- return getBlocksByName( 'core/template-part' );
19
+ const { templateParts, isNavigationMode } = useSelect( ( select ) => {
20
+ const { getBlocksByName, isNavigationMode: _isNavigationMode } =
21
+ select( blockEditorStore );
22
+ return {
23
+ templateParts: getBlocksByName( 'core/template-part' ),
24
+ isNavigationMode: _isNavigationMode(),
25
+ };
22
26
  }, [] );
23
27
  const disabledIds = useSelect(
24
28
  ( select ) => {
@@ -32,38 +36,85 @@ export default function DisableNonPageContentBlocks() {
32
36
 
33
37
  const registry = useRegistry();
34
38
 
39
+ // The code here is split into multiple `useEffects` calls.
40
+ // This is done to avoid setting/unsetting block editing modes multiple times unnecessarily.
41
+ //
42
+ // For example, the block editing mode of the root block (clientId: '') only
43
+ // needs to be set once, not when `contentOnlyIds` or `disabledIds` change.
44
+ //
45
+ // It's also unlikely that these different types of blocks are being inserted
46
+ // or removed at the same time, so using different effects reflects that.
47
+ useEffect( () => {
48
+ const { setBlockEditingMode, unsetBlockEditingMode } =
49
+ registry.dispatch( blockEditorStore );
50
+
51
+ setBlockEditingMode( '', 'disabled' );
52
+
53
+ return () => {
54
+ unsetBlockEditingMode( '' );
55
+ };
56
+ }, [ registry ] );
57
+
35
58
  useEffect( () => {
36
59
  const { setBlockEditingMode, unsetBlockEditingMode } =
37
60
  registry.dispatch( blockEditorStore );
38
61
 
39
62
  registry.batch( () => {
40
- setBlockEditingMode( '', 'disabled' );
41
63
  for ( const clientId of contentOnlyIds ) {
42
64
  setBlockEditingMode( clientId, 'contentOnly' );
43
65
  }
44
- for ( const clientId of templateParts ) {
45
- setBlockEditingMode( clientId, 'contentOnly' );
46
- }
47
- for ( const clientId of disabledIds ) {
48
- setBlockEditingMode( clientId, 'disabled' );
49
- }
50
66
  } );
51
67
 
52
68
  return () => {
53
69
  registry.batch( () => {
54
- unsetBlockEditingMode( '' );
55
70
  for ( const clientId of contentOnlyIds ) {
56
71
  unsetBlockEditingMode( clientId );
57
72
  }
73
+ } );
74
+ };
75
+ }, [ contentOnlyIds, registry ] );
76
+
77
+ useEffect( () => {
78
+ const { setBlockEditingMode, unsetBlockEditingMode } =
79
+ registry.dispatch( blockEditorStore );
80
+
81
+ registry.batch( () => {
82
+ if ( ! isNavigationMode ) {
58
83
  for ( const clientId of templateParts ) {
59
- unsetBlockEditingMode( clientId );
84
+ setBlockEditingMode( clientId, 'contentOnly' );
60
85
  }
86
+ }
87
+ } );
88
+
89
+ return () => {
90
+ registry.batch( () => {
91
+ if ( ! isNavigationMode ) {
92
+ for ( const clientId of templateParts ) {
93
+ unsetBlockEditingMode( clientId );
94
+ }
95
+ }
96
+ } );
97
+ };
98
+ }, [ templateParts, isNavigationMode, registry ] );
99
+
100
+ useEffect( () => {
101
+ const { setBlockEditingMode, unsetBlockEditingMode } =
102
+ registry.dispatch( blockEditorStore );
103
+
104
+ registry.batch( () => {
105
+ for ( const clientId of disabledIds ) {
106
+ setBlockEditingMode( clientId, 'disabled' );
107
+ }
108
+ } );
109
+
110
+ return () => {
111
+ registry.batch( () => {
61
112
  for ( const clientId of disabledIds ) {
62
113
  unsetBlockEditingMode( clientId );
63
114
  }
64
115
  } );
65
116
  };
66
- }, [ templateParts, contentOnlyIds, disabledIds, registry ] );
117
+ }, [ disabledIds, registry ] );
67
118
 
68
119
  return null;
69
120
  }
@@ -13,7 +13,6 @@ import {
13
13
  BlockEditorProvider,
14
14
  BlockContextProvider,
15
15
  privateApis as blockEditorPrivateApis,
16
- store as blockEditorStore,
17
16
  } from '@wordpress/block-editor';
18
17
  import { store as noticesStore } from '@wordpress/notices';
19
18
  import { privateApis as editPatternsPrivateApis } from '@wordpress/patterns';
@@ -164,6 +163,7 @@ export const ExperimentalEditorProvider = withRegistryProvider(
164
163
  BlockEditorProviderComponent = ExperimentalBlockEditorProvider,
165
164
  __unstableTemplate: template,
166
165
  } ) => {
166
+ const hasTemplate = !! template;
167
167
  const {
168
168
  editorSettings,
169
169
  selection,
@@ -196,7 +196,9 @@ export const ExperimentalEditorProvider = withRegistryProvider(
196
196
  isReady: __unstableIsEditorReady(),
197
197
  mode: getRenderingMode(),
198
198
  defaultMode:
199
- postTypeObject?.default_rendering_mode ?? 'post-only',
199
+ hasTemplate && postTypeObject?.default_rendering_mode
200
+ ? postTypeObject?.default_rendering_mode
201
+ : 'post-only',
200
202
  selection: getEditorSelection(),
201
203
  postTypeEntities:
202
204
  post.type === 'wp_template'
@@ -204,17 +206,9 @@ export const ExperimentalEditorProvider = withRegistryProvider(
204
206
  : null,
205
207
  };
206
208
  },
207
- [ post.type ]
209
+ [ post.type, hasTemplate ]
208
210
  );
209
211
 
210
- const isZoomOut = useSelect( ( select ) => {
211
- const { isZoomOut: _isZoomOut } = unlock(
212
- select( blockEditorStore )
213
- );
214
-
215
- return _isZoomOut();
216
- } );
217
-
218
212
  const shouldRenderTemplate = !! template && mode !== 'post-only';
219
213
  const rootLevelPost = shouldRenderTemplate ? template : post;
220
214
  const defaultBlockContext = useMemo( () => {
@@ -309,15 +303,11 @@ export const ExperimentalEditorProvider = withRegistryProvider(
309
303
  }
310
304
  );
311
305
  }
312
- }, [
313
- createWarningNotice,
314
- initialEdits,
315
- settings,
316
- post,
317
- recovery,
318
- setupEditor,
319
- updatePostLock,
320
- ] );
306
+
307
+ // The dependencies of the hook are omitted deliberately
308
+ // We only want to run setupEditor (with initialEdits) only once per post.
309
+ // A better solution in the future would be to split this effect into multiple ones.
310
+ }, [] );
321
311
 
322
312
  // Synchronizes the active post with the state
323
313
  useEffect( () => {
@@ -367,13 +357,9 @@ export const ExperimentalEditorProvider = withRegistryProvider(
367
357
  { children }
368
358
  { ! settings.isPreviewMode && (
369
359
  <>
370
- { ! isZoomOut && (
371
- <>
372
- <PatternsMenuItems />
373
- <TemplatePartMenuItems />
374
- <ContentOnlySettingsMenu />
375
- </>
376
- ) }
360
+ <PatternsMenuItems />
361
+ <TemplatePartMenuItems />
362
+ <ContentOnlySettingsMenu />
377
363
  { mode === 'template-locked' && (
378
364
  <DisableNonPageContentBlocks />
379
365
  ) }
@@ -23,6 +23,7 @@ import {
23
23
  */
24
24
  import inserterMediaCategories from '../media-categories';
25
25
  import { mediaUpload } from '../../utils';
26
+ import { default as mediaSideload } from '../../utils/media-sideload';
26
27
  import { store as editorStore } from '../../store';
27
28
  import { unlock } from '../../lock-unlock';
28
29
  import { useGlobalStylesContext } from '../global-styles-provider';
@@ -45,6 +46,7 @@ const BLOCK_EDITOR_SETTINGS = [
45
46
  '__experimentalGlobalStylesBaseStyles',
46
47
  'alignWide',
47
48
  'blockInspectorTabs',
49
+ 'maxUploadFileSize',
48
50
  'allowedMimeTypes',
49
51
  'bodyPlaceholder',
50
52
  'canLockBlocks',
@@ -290,6 +292,7 @@ function useBlockEditorSettings( settings, postType, postId, renderingMode ) {
290
292
  isDistractionFree,
291
293
  keepCaretInsideBlock,
292
294
  mediaUpload: hasUploadPermissions ? mediaUpload : undefined,
295
+ mediaSideload: hasUploadPermissions ? mediaSideload : undefined,
293
296
  __experimentalBlockPatterns: blockPatterns,
294
297
  [ selectBlockPatternsKey ]: ( select ) => {
295
298
  const { hasFinishedResolution, getBlockPatternsForPostType } =
@@ -1,16 +1,8 @@
1
1
  /**
2
2
  * WordPress dependencies
3
3
  */
4
- import { Modal } from '@wordpress/components';
5
- import { __ } from '@wordpress/i18n';
6
- import { useState, useMemo } from '@wordpress/element';
7
- import {
8
- store as blockEditorStore,
9
- __experimentalBlockPatternsList as BlockPatternsList,
10
- } from '@wordpress/block-editor';
4
+ import { useEffect } from '@wordpress/element';
11
5
  import { useSelect, useDispatch } from '@wordpress/data';
12
- import { store as coreStore } from '@wordpress/core-data';
13
- import { __unstableSerializeAndClean } from '@wordpress/blocks';
14
6
  import { store as preferencesStore } from '@wordpress/preferences';
15
7
  import { store as interfaceStore } from '@wordpress/interface';
16
8
 
@@ -18,124 +10,41 @@ import { store as interfaceStore } from '@wordpress/interface';
18
10
  * Internal dependencies
19
11
  */
20
12
  import { store as editorStore } from '../../store';
21
- import { TEMPLATE_POST_TYPE } from '../../store/constants';
22
-
23
- export function useStartPatterns() {
24
- // A pattern is a start pattern if it includes 'core/post-content' in its blockTypes,
25
- // and it has no postTypes declared and the current post type is page or if
26
- // the current post type is part of the postTypes declared.
27
- const { blockPatternsWithPostContentBlockType, postType } = useSelect(
28
- ( select ) => {
29
- const { getPatternsByBlockTypes, getBlocksByName } =
30
- select( blockEditorStore );
31
- const { getCurrentPostType, getRenderingMode } =
32
- select( editorStore );
33
- const rootClientId =
34
- getRenderingMode() === 'post-only'
35
- ? ''
36
- : getBlocksByName( 'core/post-content' )?.[ 0 ];
37
- return {
38
- blockPatternsWithPostContentBlockType: getPatternsByBlockTypes(
39
- 'core/post-content',
40
- rootClientId
41
- ),
42
- postType: getCurrentPostType(),
43
- };
44
- },
45
- []
46
- );
47
-
48
- return useMemo( () => {
49
- if ( ! blockPatternsWithPostContentBlockType?.length ) {
50
- return [];
51
- }
52
-
53
- /*
54
- * Filter patterns without postTypes declared if the current postType is page
55
- * or patterns that declare the current postType in its post type array.
56
- */
57
- return blockPatternsWithPostContentBlockType.filter( ( pattern ) => {
58
- return (
59
- ( postType === 'page' && ! pattern.postTypes ) ||
60
- ( Array.isArray( pattern.postTypes ) &&
61
- pattern.postTypes.includes( postType ) )
62
- );
63
- } );
64
- }, [ postType, blockPatternsWithPostContentBlockType ] );
65
- }
66
-
67
- function PatternSelection( { blockPatterns, onChoosePattern } ) {
68
- const { editEntityRecord } = useDispatch( coreStore );
69
- const { postType, postId } = useSelect( ( select ) => {
70
- const { getCurrentPostType, getCurrentPostId } = select( editorStore );
71
-
72
- return {
73
- postType: getCurrentPostType(),
74
- postId: getCurrentPostId(),
75
- };
76
- }, [] );
77
- return (
78
- <BlockPatternsList
79
- blockPatterns={ blockPatterns }
80
- onClickPattern={ ( _pattern, blocks ) => {
81
- editEntityRecord( 'postType', postType, postId, {
82
- blocks,
83
- content: ( { blocks: blocksForSerialization = [] } ) =>
84
- __unstableSerializeAndClean( blocksForSerialization ),
85
- } );
86
- onChoosePattern();
87
- } }
88
- />
89
- );
90
- }
91
-
92
- function StartPageOptionsModal( { onClose } ) {
93
- const startPatterns = useStartPatterns();
94
- const hasStartPattern = startPatterns.length > 0;
95
-
96
- if ( ! hasStartPattern ) {
97
- return null;
98
- }
99
-
100
- return (
101
- <Modal
102
- title={ __( 'Choose a pattern' ) }
103
- isFullScreen
104
- onRequestClose={ onClose }
105
- >
106
- <div className="editor-start-page-options__modal-content">
107
- <PatternSelection
108
- blockPatterns={ startPatterns }
109
- onChoosePattern={ onClose }
110
- />
111
- </div>
112
- </Modal>
113
- );
114
- }
115
13
 
116
14
  export default function StartPageOptions() {
117
- const [ isClosed, setIsClosed ] = useState( false );
118
- const shouldEnableModal = useSelect( ( select ) => {
119
- const { isEditedPostDirty, isEditedPostEmpty, getCurrentPostType } =
120
- select( editorStore );
15
+ const { postId, shouldEnable } = useSelect( ( select ) => {
16
+ const {
17
+ isEditedPostDirty,
18
+ isEditedPostEmpty,
19
+ getCurrentPostId,
20
+ getCurrentPostType,
21
+ } = select( editorStore );
121
22
  const preferencesModalActive =
122
23
  select( interfaceStore ).isModalActive( 'editor/preferences' );
123
24
  const choosePatternModalEnabled = select( preferencesStore ).get(
124
25
  'core',
125
26
  'enableChoosePatternModal'
126
27
  );
127
- return (
128
- choosePatternModalEnabled &&
129
- ! preferencesModalActive &&
130
- ! isEditedPostDirty() &&
131
- isEditedPostEmpty() &&
132
- TEMPLATE_POST_TYPE !== getCurrentPostType()
133
- );
28
+ return {
29
+ postId: getCurrentPostId(),
30
+ shouldEnable:
31
+ choosePatternModalEnabled &&
32
+ ! preferencesModalActive &&
33
+ ! isEditedPostDirty() &&
34
+ isEditedPostEmpty() &&
35
+ 'page' === getCurrentPostType(),
36
+ };
134
37
  }, [] );
38
+ const { setIsInserterOpened } = useDispatch( editorStore );
39
+
40
+ useEffect( () => {
41
+ if ( shouldEnable ) {
42
+ setIsInserterOpened( {
43
+ tab: 'patterns',
44
+ category: 'core/starter-content',
45
+ } );
46
+ }
47
+ }, [ postId, shouldEnable, setIsInserterOpened ] );
135
48
 
136
- if ( ! shouldEnableModal || isClosed ) {
137
- return null;
138
- }
139
-
140
- return <StartPageOptionsModal onClose={ () => setIsClosed( true ) } />;
49
+ return null;
141
50
  }
@@ -27,25 +27,16 @@ export default function TemplatePartMenuItems() {
27
27
  }
28
28
 
29
29
  function TemplatePartConverterMenuItem( { clientIds, onClose } ) {
30
- const { isContentOnly, blocks } = useSelect(
30
+ const { blocks } = useSelect(
31
31
  ( select ) => {
32
- const { getBlocksByClientId, getBlockEditingMode } =
33
- select( blockEditorStore );
32
+ const { getBlocksByClientId } = select( blockEditorStore );
34
33
  return {
35
34
  blocks: getBlocksByClientId( clientIds ),
36
- isContentOnly:
37
- clientIds.length === 1 &&
38
- getBlockEditingMode( clientIds[ 0 ] ) === 'contentOnly',
39
35
  };
40
36
  },
41
37
  [ clientIds ]
42
38
  );
43
39
 
44
- // Do not show the convert button if the block is in content-only mode.
45
- if ( isContentOnly ) {
46
- return null;
47
- }
48
-
49
40
  // Allow converting a single template part to standard blocks.
50
41
  if ( blocks.length === 1 && blocks[ 0 ]?.name === 'core/template-part' ) {
51
42
  return (
@@ -23,7 +23,6 @@ import { __ } from '@wordpress/i18n';
23
23
  /**
24
24
  * Internal dependencies
25
25
  */
26
- import { TRASH_POST_NOTICE_ID } from './constants';
27
26
  import { localAutosaveSet } from './local-autosave';
28
27
  import {
29
28
  getNotificationArgumentsForSaveSuccess,
@@ -347,7 +346,6 @@ export const trashPost =
347
346
  const postType = await registry
348
347
  .resolveSelect( coreStore )
349
348
  .getPostType( postTypeSlug );
350
- registry.dispatch( noticesStore ).removeNotice( TRASH_POST_NOTICE_ID );
351
349
  const { rest_base: restBase, rest_namespace: restNamespace = 'wp/v2' } =
352
350
  postType;
353
351
  dispatch( { type: 'REQUEST_POST_DELETE_START' } );
@@ -11,8 +11,6 @@ export const EDIT_MERGE_PROPERTIES = new Set( [ 'meta' ] );
11
11
  */
12
12
  export const STORE_NAME = 'core/editor';
13
13
 
14
- export const SAVE_POST_NOTICE_ID = 'SAVE_POST_NOTICE_ID';
15
- export const TRASH_POST_NOTICE_ID = 'TRASH_POST_NOTICE_ID';
16
14
  export const PERMALINK_POSTNAME_REGEX = /%(?:postname|pagename)%/;
17
15
  export const ONE_MINUTE_IN_MS = 60 * 1000;
18
16
  export const AUTOSAVE_PROPERTIES = [ 'title', 'excerpt', 'content' ];
@@ -34,7 +34,7 @@ export function setCurrentTemplateId( id ) {
34
34
  /**
35
35
  * Create a block based template.
36
36
  *
37
- * @param {Object?} template Template to create and assign.
37
+ * @param {?Object} template Template to create and assign.
38
38
  */
39
39
  export const createTemplate =
40
40
  ( template ) =>
@@ -3,11 +3,6 @@
3
3
  */
4
4
  import { __ } from '@wordpress/i18n';
5
5
 
6
- /**
7
- * Internal dependencies
8
- */
9
- import { SAVE_POST_NOTICE_ID, TRASH_POST_NOTICE_ID } from '../constants';
10
-
11
6
  /**
12
7
  * Builds the arguments for a success notification dispatch.
13
8
  *
@@ -68,7 +63,7 @@ export function getNotificationArgumentsForSaveSuccess( data ) {
68
63
  return [
69
64
  noticeMessage,
70
65
  {
71
- id: SAVE_POST_NOTICE_ID,
66
+ id: 'editor-save',
72
67
  type: 'snackbar',
73
68
  actions,
74
69
  },
@@ -113,7 +108,7 @@ export function getNotificationArgumentsForSaveFail( data ) {
113
108
  return [
114
109
  noticeMessage,
115
110
  {
116
- id: SAVE_POST_NOTICE_ID,
111
+ id: 'editor-save',
117
112
  },
118
113
  ];
119
114
  }
@@ -131,7 +126,7 @@ export function getNotificationArgumentsForTrashFail( data ) {
131
126
  ? data.error.message
132
127
  : __( 'Trashing failed' ),
133
128
  {
134
- id: TRASH_POST_NOTICE_ID,
129
+ id: 'editor-trash-fail',
135
130
  },
136
131
  ];
137
132
  }
@@ -6,7 +6,6 @@ import {
6
6
  getNotificationArgumentsForSaveFail,
7
7
  getNotificationArgumentsForTrashFail,
8
8
  } from '../notice-builder';
9
- import { SAVE_POST_NOTICE_ID, TRASH_POST_NOTICE_ID } from '../../constants';
10
9
 
11
10
  describe( 'getNotificationArgumentsForSaveSuccess()', () => {
12
11
  const postType = {
@@ -27,7 +26,7 @@ describe( 'getNotificationArgumentsForSaveSuccess()', () => {
27
26
  };
28
27
  const post = { ...previousPost };
29
28
  const defaultExpectedAction = {
30
- id: SAVE_POST_NOTICE_ID,
29
+ id: 'editor-save',
31
30
  actions: [],
32
31
  type: 'snackbar',
33
32
  };
@@ -106,7 +105,7 @@ describe( 'getNotificationArgumentsForSaveFail()', () => {
106
105
  const error = { code: '42', message: 'Something went wrong.' };
107
106
  const post = { status: 'publish' };
108
107
  const edits = { status: 'publish' };
109
- const defaultExpectedAction = { id: SAVE_POST_NOTICE_ID };
108
+ const defaultExpectedAction = { id: 'editor-save' };
110
109
  [
111
110
  [
112
111
  'when error code is `rest_autosave_no_changes`',
@@ -190,7 +189,7 @@ describe( 'getNotificationArgumentsForTrashFail()', () => {
190
189
  ].forEach( ( [ description, error, message ] ) => {
191
190
  // eslint-disable-next-line jest/valid-title
192
191
  it( description, () => {
193
- const expectedValue = [ message, { id: TRASH_POST_NOTICE_ID } ];
192
+ const expectedValue = [ message, { id: 'editor-trash-fail' } ];
194
193
  expect( getNotificationArgumentsForTrashFail( { error } ) ).toEqual(
195
194
  expectedValue
196
195
  );
@@ -0,0 +1,25 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import { decodeEntities } from '@wordpress/html-entities';
5
+
6
+ /**
7
+ * Helper function to get the title of a post item.
8
+ * This is duplicated from the `@wordpress/fields` package.
9
+ * `packages/fields/src/actions/utils.ts`
10
+ *
11
+ * @param {Object} item The post item.
12
+ * @return {string} The title of the item, or an empty string if the title is not found.
13
+ */
14
+ export function getItemTitle( item ) {
15
+ if ( typeof item.title === 'string' ) {
16
+ return decodeEntities( item.title );
17
+ }
18
+ if ( item.title && 'rendered' in item.title ) {
19
+ return decodeEntities( item.title.rendered );
20
+ }
21
+ if ( item.title && 'raw' in item.title ) {
22
+ return decodeEntities( item.title.raw );
23
+ }
24
+ return '';
25
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import { privateApis } from '@wordpress/media-utils';
5
+
6
+ /**
7
+ * Internal dependencies
8
+ */
9
+ import { unlock } from '../../lock-unlock';
10
+
11
+ const { sideloadMedia: mediaSideload } = unlock( privateApis );
12
+
13
+ export default mediaSideload;
@@ -0,0 +1 @@
1
+ export default function mediaSideload() {}
@@ -27,6 +27,7 @@ const noop = () => {};
27
27
  * @param {?number} $0.maxUploadFileSize Maximum upload size in bytes allowed for the site.
28
28
  * @param {Function} $0.onError Function called when an error happens.
29
29
  * @param {Function} $0.onFileChange Function called each time a file or a temporary representation of the file is available.
30
+ * @param {Function} $0.onSuccess Function called after the final representation of the file is available.
30
31
  */
31
32
  export default function mediaUpload( {
32
33
  additionalData = {},
@@ -35,6 +36,7 @@ export default function mediaUpload( {
35
36
  maxUploadFileSize,
36
37
  onError = noop,
37
38
  onFileChange,
39
+ onSuccess,
38
40
  } ) {
39
41
  const { getCurrentPost, getEditorSettings } = select( editorStore );
40
42
  const {
@@ -77,8 +79,9 @@ export default function mediaUpload( {
77
79
  } else {
78
80
  clearSaveLock();
79
81
  }
80
- onFileChange( file );
82
+ onFileChange?.( file );
81
83
  },
84
+ onSuccess,
82
85
  additionalData: {
83
86
  ...postData,
84
87
  ...additionalData,
package/tsconfig.json CHANGED
@@ -2,8 +2,6 @@
2
2
  "$schema": "https://json.schemastore.org/tsconfig.json",
3
3
  "extends": "../../tsconfig.base.json",
4
4
  "compilerOptions": {
5
- "rootDir": "src",
6
- "declarationDir": "build-types",
7
5
  "checkJs": false
8
6
  },
9
7
  "references": [
@@ -34,6 +32,5 @@
34
32
  { "path": "../url" },
35
33
  { "path": "../warning" },
36
34
  { "path": "../wordcount" }
37
- ],
38
- "include": [ "src" ]
35
+ ]
39
36
  }