@wordpress/editor 14.4.0 → 14.5.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 (222) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/build/bindings/post-meta.js +12 -0
  3. package/build/bindings/post-meta.js.map +1 -1
  4. package/build/components/blog-title/index.js +1 -1
  5. package/build/components/blog-title/index.js.map +1 -1
  6. package/build/components/commands/index.js +8 -2
  7. package/build/components/commands/index.js.map +1 -1
  8. package/build/components/document-bar/index.js +1 -1
  9. package/build/components/document-bar/index.js.map +1 -1
  10. package/build/components/header/index.js +2 -3
  11. package/build/components/header/index.js.map +1 -1
  12. package/build/components/page-attributes/parent.js +6 -2
  13. package/build/components/page-attributes/parent.js.map +1 -1
  14. package/build/components/post-actions/actions.js +38 -344
  15. package/build/components/post-actions/actions.js.map +1 -1
  16. package/build/components/post-actions/index.js +16 -6
  17. package/build/components/post-actions/index.js.map +1 -1
  18. package/build/components/post-author/hook.js +10 -3
  19. package/build/components/post-author/hook.js.map +1 -1
  20. package/build/components/post-author/panel.js +2 -1
  21. package/build/components/post-author/panel.js.map +1 -1
  22. package/build/components/post-card-panel/index.js +1 -1
  23. package/build/components/post-card-panel/index.js.map +1 -1
  24. package/build/components/post-comments/index.js +6 -20
  25. package/build/components/post-comments/index.js.map +1 -1
  26. package/build/components/post-status/index.js +17 -41
  27. package/build/components/post-status/index.js.map +1 -1
  28. package/build/components/post-template/create-new-template-modal.js +3 -0
  29. package/build/components/post-template/create-new-template-modal.js.map +1 -1
  30. package/build/components/post-url/panel.js +3 -2
  31. package/build/components/post-url/panel.js.map +1 -1
  32. package/build/components/preview-dropdown/index.js +82 -17
  33. package/build/components/preview-dropdown/index.js.map +1 -1
  34. package/build/components/provider/disable-non-page-content-blocks.js +14 -18
  35. package/build/components/provider/disable-non-page-content-blocks.js.map +1 -1
  36. package/build/components/site-discussion/index.js +6 -20
  37. package/build/components/site-discussion/index.js.map +1 -1
  38. package/build/components/template-content-panel/index.js +14 -12
  39. package/build/components/template-content-panel/index.js.map +1 -1
  40. package/build/components/visual-editor/index.js +2 -1
  41. package/build/components/visual-editor/index.js.map +1 -1
  42. package/build/dataviews/actions/export-pattern.native.js +9 -0
  43. package/build/dataviews/actions/export-pattern.native.js.map +1 -0
  44. package/build/dataviews/actions/permanently-delete-post.js +107 -0
  45. package/build/dataviews/actions/permanently-delete-post.js.map +1 -0
  46. package/build/dataviews/actions/restore-post.js +112 -0
  47. package/build/dataviews/actions/restore-post.js.map +1 -0
  48. package/build/dataviews/actions/trash-post.js +142 -0
  49. package/build/dataviews/actions/trash-post.js.map +1 -0
  50. package/build/dataviews/store/private-actions.js +45 -0
  51. package/build/dataviews/store/private-actions.js.map +1 -1
  52. package/build/dataviews/store/private-selectors.js +10 -10
  53. package/build/dataviews/store/private-selectors.js.map +1 -1
  54. package/build/dataviews/store/reducer.js +15 -1
  55. package/build/dataviews/store/reducer.js.map +1 -1
  56. package/build/dataviews/types.js.map +1 -1
  57. package/build/private-apis.js +0 -2
  58. package/build/private-apis.js.map +1 -1
  59. package/build/store/actions.js +16 -2
  60. package/build/store/actions.js.map +1 -1
  61. package/build/store/private-actions.js +8 -1
  62. package/build/store/private-actions.js.map +1 -1
  63. package/build/store/private-selectors.js +33 -2
  64. package/build/store/private-selectors.js.map +1 -1
  65. package/build-module/bindings/post-meta.js +12 -0
  66. package/build-module/bindings/post-meta.js.map +1 -1
  67. package/build-module/components/blog-title/index.js +1 -1
  68. package/build-module/components/blog-title/index.js.map +1 -1
  69. package/build-module/components/commands/index.js +8 -2
  70. package/build-module/components/commands/index.js.map +1 -1
  71. package/build-module/components/document-bar/index.js +1 -1
  72. package/build-module/components/document-bar/index.js.map +1 -1
  73. package/build-module/components/header/index.js +2 -3
  74. package/build-module/components/header/index.js.map +1 -1
  75. package/build-module/components/page-attributes/parent.js +7 -3
  76. package/build-module/components/page-attributes/parent.js.map +1 -1
  77. package/build-module/components/post-actions/actions.js +44 -350
  78. package/build-module/components/post-actions/actions.js.map +1 -1
  79. package/build-module/components/post-actions/index.js +16 -6
  80. package/build-module/components/post-actions/index.js.map +1 -1
  81. package/build-module/components/post-author/hook.js +10 -3
  82. package/build-module/components/post-author/hook.js.map +1 -1
  83. package/build-module/components/post-author/panel.js +2 -1
  84. package/build-module/components/post-author/panel.js.map +1 -1
  85. package/build-module/components/post-card-panel/index.js +1 -1
  86. package/build-module/components/post-card-panel/index.js.map +1 -1
  87. package/build-module/components/post-comments/index.js +7 -23
  88. package/build-module/components/post-comments/index.js.map +1 -1
  89. package/build-module/components/post-status/index.js +19 -43
  90. package/build-module/components/post-status/index.js.map +1 -1
  91. package/build-module/components/post-template/create-new-template-modal.js +3 -0
  92. package/build-module/components/post-template/create-new-template-modal.js.map +1 -1
  93. package/build-module/components/post-url/panel.js +4 -5
  94. package/build-module/components/post-url/panel.js.map +1 -1
  95. package/build-module/components/preview-dropdown/index.js +84 -19
  96. package/build-module/components/preview-dropdown/index.js.map +1 -1
  97. package/build-module/components/provider/disable-non-page-content-blocks.js +15 -19
  98. package/build-module/components/provider/disable-non-page-content-blocks.js.map +1 -1
  99. package/build-module/components/site-discussion/index.js +7 -21
  100. package/build-module/components/site-discussion/index.js.map +1 -1
  101. package/build-module/components/template-content-panel/index.js +15 -13
  102. package/build-module/components/template-content-panel/index.js.map +1 -1
  103. package/build-module/components/visual-editor/index.js +2 -1
  104. package/build-module/components/visual-editor/index.js.map +1 -1
  105. package/build-module/dataviews/actions/export-pattern.native.js +3 -0
  106. package/build-module/dataviews/actions/export-pattern.native.js.map +1 -0
  107. package/build-module/dataviews/actions/permanently-delete-post.js +99 -0
  108. package/build-module/dataviews/actions/permanently-delete-post.js.map +1 -0
  109. package/build-module/dataviews/actions/restore-post.js +104 -0
  110. package/build-module/dataviews/actions/restore-post.js.map +1 -0
  111. package/build-module/dataviews/actions/trash-post.js +135 -0
  112. package/build-module/dataviews/actions/trash-post.js.map +1 -0
  113. package/build-module/dataviews/store/private-actions.js +40 -0
  114. package/build-module/dataviews/store/private-actions.js.map +1 -1
  115. package/build-module/dataviews/store/private-selectors.js +8 -9
  116. package/build-module/dataviews/store/private-selectors.js.map +1 -1
  117. package/build-module/dataviews/store/reducer.js +15 -1
  118. package/build-module/dataviews/store/reducer.js.map +1 -1
  119. package/build-module/dataviews/types.js.map +1 -1
  120. package/build-module/private-apis.js +0 -2
  121. package/build-module/private-apis.js.map +1 -1
  122. package/build-module/store/actions.js +16 -2
  123. package/build-module/store/actions.js.map +1 -1
  124. package/build-module/store/private-actions.js +8 -1
  125. package/build-module/store/private-actions.js.map +1 -1
  126. package/build-module/store/private-selectors.js +32 -2
  127. package/build-module/store/private-selectors.js.map +1 -1
  128. package/build-style/style-rtl.css +19 -3
  129. package/build-style/style.css +19 -3
  130. package/build-types/bindings/post-meta.d.ts +6 -0
  131. package/build-types/bindings/post-meta.d.ts.map +1 -1
  132. package/build-types/components/commands/index.d.ts.map +1 -1
  133. package/build-types/components/header/index.d.ts.map +1 -1
  134. package/build-types/components/page-attributes/parent.d.ts.map +1 -1
  135. package/build-types/components/post-actions/actions.d.ts.map +1 -1
  136. package/build-types/components/post-actions/index.d.ts.map +1 -1
  137. package/build-types/components/post-author/hook.d.ts +1 -1
  138. package/build-types/components/post-author/hook.d.ts.map +1 -1
  139. package/build-types/components/post-author/panel.d.ts.map +1 -1
  140. package/build-types/components/post-comments/index.d.ts.map +1 -1
  141. package/build-types/components/post-status/index.d.ts +2 -1
  142. package/build-types/components/post-status/index.d.ts.map +1 -1
  143. package/build-types/components/post-template/create-new-template-modal.d.ts.map +1 -1
  144. package/build-types/components/post-url/panel.d.ts.map +1 -1
  145. package/build-types/components/preview-dropdown/index.d.ts.map +1 -1
  146. package/build-types/components/provider/disable-non-page-content-blocks.d.ts.map +1 -1
  147. package/build-types/components/site-discussion/index.d.ts.map +1 -1
  148. package/build-types/components/template-content-panel/index.d.ts.map +1 -1
  149. package/build-types/components/visual-editor/index.d.ts.map +1 -1
  150. package/build-types/dataviews/actions/export-pattern.native.d.ts +3 -0
  151. package/build-types/dataviews/actions/export-pattern.native.d.ts.map +1 -0
  152. package/build-types/dataviews/actions/permanently-delete-post.d.ts +5 -0
  153. package/build-types/dataviews/actions/permanently-delete-post.d.ts.map +1 -0
  154. package/build-types/dataviews/actions/restore-post.d.ts +5 -0
  155. package/build-types/dataviews/actions/restore-post.d.ts.map +1 -0
  156. package/build-types/dataviews/actions/trash-post.d.ts +5 -0
  157. package/build-types/dataviews/actions/trash-post.d.ts.map +1 -0
  158. package/build-types/dataviews/store/private-actions.d.ts +8 -3
  159. package/build-types/dataviews/store/private-actions.d.ts.map +1 -1
  160. package/build-types/dataviews/store/private-selectors.d.ts +2 -1
  161. package/build-types/dataviews/store/private-selectors.d.ts.map +1 -1
  162. package/build-types/dataviews/store/reducer.d.ts +4 -1
  163. package/build-types/dataviews/store/reducer.d.ts.map +1 -1
  164. package/build-types/dataviews/types.d.ts +9 -0
  165. package/build-types/dataviews/types.d.ts.map +1 -1
  166. package/build-types/private-apis.d.ts.map +1 -1
  167. package/build-types/store/actions.d.ts.map +1 -1
  168. package/build-types/store/private-actions.d.ts.map +1 -1
  169. package/build-types/store/private-selectors.d.ts +11 -0
  170. package/build-types/store/private-selectors.d.ts.map +1 -1
  171. package/build-types/store/reducer.d.ts +1 -0
  172. package/build-types/store/reducer.d.ts.map +1 -1
  173. package/package.json +36 -36
  174. package/src/bindings/post-meta.js +20 -0
  175. package/src/components/blog-title/index.js +1 -1
  176. package/src/components/commands/index.js +4 -2
  177. package/src/components/document-bar/index.js +1 -1
  178. package/src/components/document-bar/style.scss +1 -1
  179. package/src/components/editor-interface/style.scss +5 -0
  180. package/src/components/header/index.js +1 -2
  181. package/src/components/list-view-sidebar/style.scss +4 -0
  182. package/src/components/page-attributes/parent.js +25 -7
  183. package/src/components/post-actions/actions.js +47 -470
  184. package/src/components/post-actions/index.js +19 -7
  185. package/src/components/post-author/hook.js +11 -3
  186. package/src/components/post-author/panel.js +3 -1
  187. package/src/components/post-card-panel/index.js +1 -1
  188. package/src/components/post-comments/index.js +7 -20
  189. package/src/components/post-publish-panel/test/__snapshots__/index.js.snap +2 -2
  190. package/src/components/post-status/index.js +11 -41
  191. package/src/components/post-template/create-new-template-modal.js +7 -1
  192. package/src/components/post-url/panel.js +8 -2
  193. package/src/components/preview-dropdown/index.js +113 -35
  194. package/src/components/preview-dropdown/style.scss +5 -0
  195. package/src/components/provider/disable-non-page-content-blocks.js +27 -24
  196. package/src/components/site-discussion/index.js +7 -19
  197. package/src/components/template-content-panel/index.js +36 -21
  198. package/src/components/visual-editor/index.js +8 -6
  199. package/src/components/visual-editor/style.scss +1 -3
  200. package/src/dataviews/actions/export-pattern.native.tsx +3 -0
  201. package/src/dataviews/actions/permanently-delete-post.tsx +116 -0
  202. package/src/dataviews/actions/restore-post.tsx +134 -0
  203. package/src/dataviews/actions/trash-post.tsx +196 -0
  204. package/src/dataviews/store/private-actions.ts +68 -0
  205. package/src/dataviews/store/private-selectors.ts +9 -17
  206. package/src/dataviews/store/reducer.ts +20 -1
  207. package/src/dataviews/types.ts +11 -0
  208. package/src/private-apis.js +0 -2
  209. package/src/store/actions.js +36 -13
  210. package/src/store/private-actions.js +8 -4
  211. package/src/store/private-selectors.js +45 -2
  212. package/src/store/test/private-selectors.js +78 -0
  213. package/tsconfig.tsbuildinfo +1 -1
  214. package/build/dataviews/actions/index.js +0 -32
  215. package/build/dataviews/actions/index.js.map +0 -1
  216. package/build-module/dataviews/actions/index.js +0 -24
  217. package/build-module/dataviews/actions/index.js.map +0 -1
  218. package/build-types/dataviews/actions/index.d.ts +0 -2
  219. package/build-types/dataviews/actions/index.d.ts.map +0 -1
  220. package/src/components/document-outline/test/__snapshots__/index.js.snap +0 -111
  221. package/src/components/document-outline/test/index.js +0 -185
  222. package/src/dataviews/actions/index.ts +0 -25
@@ -107,6 +107,7 @@ function VisualEditor( {
107
107
  } ) {
108
108
  const [ resizeObserver, sizes ] = useResizeObserver();
109
109
  const isMobileViewport = useViewportMatch( 'small', '<' );
110
+ const isTabletViewport = useViewportMatch( 'medium', '<' );
110
111
  const {
111
112
  renderingMode,
112
113
  postContentAttributes,
@@ -341,12 +342,13 @@ function VisualEditor( {
341
342
  } ),
342
343
  ] );
343
344
 
344
- const zoomOutProps = isZoomOutMode
345
- ? {
346
- scale: 'default',
347
- frameSize: '48px',
348
- }
349
- : {};
345
+ const zoomOutProps =
346
+ isZoomOutMode && ! isTabletViewport
347
+ ? {
348
+ scale: 'default',
349
+ frameSize: '48px',
350
+ }
351
+ : {};
350
352
 
351
353
  const forceFullHeight = postType === NAVIGATION_POST_TYPE;
352
354
  const enableResizing =
@@ -1,9 +1,7 @@
1
1
  .editor-visual-editor {
2
2
  position: relative;
3
- display: block;
3
+ display: flex;
4
4
  background-color: $gray-300;
5
- // Make this a stacking context to contain the z-index of children elements.
6
- isolation: isolate;
7
5
 
8
6
  // Centralize the editor horizontally (flex-direction is column).
9
7
  align-items: center;
@@ -0,0 +1,3 @@
1
+ const exportPattern = undefined;
2
+
3
+ export default exportPattern;
@@ -0,0 +1,116 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import { store as coreStore } from '@wordpress/core-data';
5
+ import { __, sprintf } from '@wordpress/i18n';
6
+ import { store as noticesStore } from '@wordpress/notices';
7
+ import type { Action } from '@wordpress/dataviews';
8
+
9
+ /**
10
+ * Internal dependencies
11
+ */
12
+ import { getItemTitle, isTemplateOrTemplatePart } from './utils';
13
+ import type { CoreDataError, PostWithPermissions } from '../types';
14
+
15
+ const permanentlyDeletePost: Action< PostWithPermissions > = {
16
+ id: 'permanently-delete',
17
+ label: __( 'Permanently delete' ),
18
+ supportsBulk: true,
19
+ isEligible( item ) {
20
+ if ( isTemplateOrTemplatePart( item ) || item.type === 'wp_block' ) {
21
+ return false;
22
+ }
23
+ const { status, permissions } = item;
24
+ return status === 'trash' && permissions?.delete;
25
+ },
26
+ async callback( posts, { registry, onActionPerformed } ) {
27
+ const { createSuccessNotice, createErrorNotice } =
28
+ registry.dispatch( noticesStore );
29
+ const { deleteEntityRecord } = registry.dispatch( coreStore );
30
+ const promiseResult = await Promise.allSettled(
31
+ posts.map( ( post ) => {
32
+ return deleteEntityRecord(
33
+ 'postType',
34
+ post.type,
35
+ post.id,
36
+ { force: true },
37
+ { throwOnError: true }
38
+ );
39
+ } )
40
+ );
41
+ // If all the promises were fulfilled with success.
42
+ if ( promiseResult.every( ( { status } ) => status === 'fulfilled' ) ) {
43
+ let successMessage;
44
+ if ( promiseResult.length === 1 ) {
45
+ successMessage = sprintf(
46
+ /* translators: The posts's title. */
47
+ __( '"%s" permanently deleted.' ),
48
+ getItemTitle( posts[ 0 ] )
49
+ );
50
+ } else {
51
+ successMessage = __( 'The items were permanently deleted.' );
52
+ }
53
+ createSuccessNotice( successMessage, {
54
+ type: 'snackbar',
55
+ id: 'permanently-delete-post-action',
56
+ } );
57
+ onActionPerformed?.( posts );
58
+ } else {
59
+ // If there was at lease one failure.
60
+ let errorMessage;
61
+ // If we were trying to permanently delete a single post.
62
+ if ( promiseResult.length === 1 ) {
63
+ const typedError = promiseResult[ 0 ] as {
64
+ reason?: CoreDataError;
65
+ };
66
+ if ( typedError.reason?.message ) {
67
+ errorMessage = typedError.reason.message;
68
+ } else {
69
+ errorMessage = __(
70
+ 'An error occurred while permanently deleting the item.'
71
+ );
72
+ }
73
+ // If we were trying to permanently delete multiple posts
74
+ } else {
75
+ const errorMessages = new Set();
76
+ const failedPromises = promiseResult.filter(
77
+ ( { status } ) => status === 'rejected'
78
+ );
79
+ for ( const failedPromise of failedPromises ) {
80
+ const typedError = failedPromise as {
81
+ reason?: CoreDataError;
82
+ };
83
+ if ( typedError.reason?.message ) {
84
+ errorMessages.add( typedError.reason.message );
85
+ }
86
+ }
87
+ if ( errorMessages.size === 0 ) {
88
+ errorMessage = __(
89
+ 'An error occurred while permanently deleting the items.'
90
+ );
91
+ } else if ( errorMessages.size === 1 ) {
92
+ errorMessage = sprintf(
93
+ /* translators: %s: an error message */
94
+ __(
95
+ 'An error occurred while permanently deleting the items: %s'
96
+ ),
97
+ [ ...errorMessages ][ 0 ]
98
+ );
99
+ } else {
100
+ errorMessage = sprintf(
101
+ /* translators: %s: a list of comma separated error messages */
102
+ __(
103
+ 'Some errors occurred while permanently deleting the items: %s'
104
+ ),
105
+ [ ...errorMessages ].join( ',' )
106
+ );
107
+ }
108
+ }
109
+ createErrorNotice( errorMessage, {
110
+ type: 'snackbar',
111
+ } );
112
+ }
113
+ },
114
+ };
115
+
116
+ export default permanentlyDeletePost;
@@ -0,0 +1,134 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import { backup } from '@wordpress/icons';
5
+ import { store as coreStore } from '@wordpress/core-data';
6
+ import { __, sprintf } from '@wordpress/i18n';
7
+ import { store as noticesStore } from '@wordpress/notices';
8
+ import type { Action } from '@wordpress/dataviews';
9
+
10
+ /**
11
+ * Internal dependencies
12
+ */
13
+ import { getItemTitle, isTemplateOrTemplatePart } from './utils';
14
+ import type { CoreDataError, PostWithPermissions } from '../types';
15
+
16
+ const restorePost: Action< PostWithPermissions > = {
17
+ id: 'restore',
18
+ label: __( 'Restore' ),
19
+ isPrimary: true,
20
+ icon: backup,
21
+ supportsBulk: true,
22
+ isEligible( item ) {
23
+ return (
24
+ ! isTemplateOrTemplatePart( item ) &&
25
+ item.type !== 'wp_block' &&
26
+ item.status === 'trash' &&
27
+ item.permissions?.update
28
+ );
29
+ },
30
+ async callback( posts, { registry, onActionPerformed } ) {
31
+ const { createSuccessNotice, createErrorNotice } =
32
+ registry.dispatch( noticesStore );
33
+ const { editEntityRecord, saveEditedEntityRecord } =
34
+ registry.dispatch( coreStore );
35
+ await Promise.allSettled(
36
+ posts.map( ( post ) => {
37
+ return editEntityRecord( 'postType', post.type, post.id, {
38
+ status: 'draft',
39
+ } );
40
+ } )
41
+ );
42
+ const promiseResult = await Promise.allSettled(
43
+ posts.map( ( post ) => {
44
+ return saveEditedEntityRecord( 'postType', post.type, post.id, {
45
+ throwOnError: true,
46
+ } );
47
+ } )
48
+ );
49
+
50
+ if ( promiseResult.every( ( { status } ) => status === 'fulfilled' ) ) {
51
+ let successMessage;
52
+ if ( posts.length === 1 ) {
53
+ successMessage = sprintf(
54
+ /* translators: The number of posts. */
55
+ __( '"%s" has been restored.' ),
56
+ getItemTitle( posts[ 0 ] )
57
+ );
58
+ } else if ( posts[ 0 ].type === 'page' ) {
59
+ successMessage = sprintf(
60
+ /* translators: The number of posts. */
61
+ __( '%d pages have been restored.' ),
62
+ posts.length
63
+ );
64
+ } else {
65
+ successMessage = sprintf(
66
+ /* translators: The number of posts. */
67
+ __( '%d posts have been restored.' ),
68
+ posts.length
69
+ );
70
+ }
71
+ createSuccessNotice( successMessage, {
72
+ type: 'snackbar',
73
+ id: 'restore-post-action',
74
+ } );
75
+ if ( onActionPerformed ) {
76
+ onActionPerformed( posts );
77
+ }
78
+ } else {
79
+ // If there was at lease one failure.
80
+ let errorMessage;
81
+ // If we were trying to move a single post to the trash.
82
+ if ( promiseResult.length === 1 ) {
83
+ const typedError = promiseResult[ 0 ] as {
84
+ reason?: CoreDataError;
85
+ };
86
+ if ( typedError.reason?.message ) {
87
+ errorMessage = typedError.reason.message;
88
+ } else {
89
+ errorMessage = __(
90
+ 'An error occurred while restoring the post.'
91
+ );
92
+ }
93
+ // If we were trying to move multiple posts to the trash
94
+ } else {
95
+ const errorMessages = new Set();
96
+ const failedPromises = promiseResult.filter(
97
+ ( { status } ) => status === 'rejected'
98
+ );
99
+ for ( const failedPromise of failedPromises ) {
100
+ const typedError = failedPromise as {
101
+ reason?: CoreDataError;
102
+ };
103
+ if ( typedError.reason?.message ) {
104
+ errorMessages.add( typedError.reason.message );
105
+ }
106
+ }
107
+ if ( errorMessages.size === 0 ) {
108
+ errorMessage = __(
109
+ 'An error occurred while restoring the posts.'
110
+ );
111
+ } else if ( errorMessages.size === 1 ) {
112
+ errorMessage = sprintf(
113
+ /* translators: %s: an error message */
114
+ __( 'An error occurred while restoring the posts: %s' ),
115
+ [ ...errorMessages ][ 0 ]
116
+ );
117
+ } else {
118
+ errorMessage = sprintf(
119
+ /* translators: %s: a list of comma separated error messages */
120
+ __(
121
+ 'Some errors occurred while restoring the posts: %s'
122
+ ),
123
+ [ ...errorMessages ].join( ',' )
124
+ );
125
+ }
126
+ }
127
+ createErrorNotice( errorMessage, {
128
+ type: 'snackbar',
129
+ } );
130
+ }
131
+ },
132
+ };
133
+
134
+ export default restorePost;
@@ -0,0 +1,196 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import { trash } from '@wordpress/icons';
5
+ import { useDispatch } from '@wordpress/data';
6
+ import { store as coreStore } from '@wordpress/core-data';
7
+ import { __, _n, sprintf, _x } from '@wordpress/i18n';
8
+ import { store as noticesStore } from '@wordpress/notices';
9
+ import { useState } from '@wordpress/element';
10
+ import {
11
+ Button,
12
+ __experimentalText as Text,
13
+ __experimentalHStack as HStack,
14
+ __experimentalVStack as VStack,
15
+ } from '@wordpress/components';
16
+ import type { Action } from '@wordpress/dataviews';
17
+
18
+ /**
19
+ * Internal dependencies
20
+ */
21
+ import { getItemTitle, isTemplateOrTemplatePart } from './utils';
22
+ import type { CoreDataError, PostWithPermissions } from '../types';
23
+
24
+ const trashPost: Action< PostWithPermissions > = {
25
+ id: 'move-to-trash',
26
+ label: __( 'Move to trash' ),
27
+ isPrimary: true,
28
+ icon: trash,
29
+ isEligible( item ) {
30
+ if ( isTemplateOrTemplatePart( item ) || item.type === 'wp_block' ) {
31
+ return false;
32
+ }
33
+
34
+ return (
35
+ !! item.status &&
36
+ ! [ 'auto-draft', 'trash' ].includes( item.status ) &&
37
+ item.permissions?.delete
38
+ );
39
+ },
40
+ supportsBulk: true,
41
+ hideModalHeader: true,
42
+ RenderModal: ( { items, closeModal, onActionPerformed } ) => {
43
+ const [ isBusy, setIsBusy ] = useState( false );
44
+ const { createSuccessNotice, createErrorNotice } =
45
+ useDispatch( noticesStore );
46
+ const { deleteEntityRecord } = useDispatch( coreStore );
47
+ return (
48
+ <VStack spacing="5">
49
+ <Text>
50
+ { items.length === 1
51
+ ? sprintf(
52
+ // translators: %s: The item's title.
53
+ __(
54
+ 'Are you sure you want to move "%s" to the trash?'
55
+ ),
56
+ getItemTitle( items[ 0 ] )
57
+ )
58
+ : sprintf(
59
+ // translators: %d: The number of items (2 or more).
60
+ _n(
61
+ 'Are you sure you want to move %d item to the trash ?',
62
+ 'Are you sure you want to move %d items to the trash ?',
63
+ items.length
64
+ ),
65
+ items.length
66
+ ) }
67
+ </Text>
68
+ <HStack justify="right">
69
+ <Button
70
+ variant="tertiary"
71
+ onClick={ closeModal }
72
+ disabled={ isBusy }
73
+ accessibleWhenDisabled
74
+ >
75
+ { __( 'Cancel' ) }
76
+ </Button>
77
+ <Button
78
+ variant="primary"
79
+ onClick={ async () => {
80
+ setIsBusy( true );
81
+ const promiseResult = await Promise.allSettled(
82
+ items.map( ( item ) =>
83
+ deleteEntityRecord(
84
+ 'postType',
85
+ item.type,
86
+ item.id.toString(),
87
+ {},
88
+ { throwOnError: true }
89
+ )
90
+ )
91
+ );
92
+ // If all the promises were fulfilled with success.
93
+ if (
94
+ promiseResult.every(
95
+ ( { status } ) => status === 'fulfilled'
96
+ )
97
+ ) {
98
+ let successMessage;
99
+ if ( promiseResult.length === 1 ) {
100
+ successMessage = sprintf(
101
+ /* translators: The item's title. */
102
+ __( '"%s" moved to the trash.' ),
103
+ getItemTitle( items[ 0 ] )
104
+ );
105
+ } else {
106
+ successMessage = sprintf(
107
+ /* translators: The number of items. */
108
+ _n(
109
+ '%s item moved to the trash.',
110
+ '%s items moved to the trash.',
111
+ items.length
112
+ ),
113
+ items.length
114
+ );
115
+ }
116
+ createSuccessNotice( successMessage, {
117
+ type: 'snackbar',
118
+ id: 'move-to-trash-action',
119
+ } );
120
+ } else {
121
+ // If there was at least one failure.
122
+ let errorMessage;
123
+ // If we were trying to delete a single item.
124
+ if ( promiseResult.length === 1 ) {
125
+ const typedError = promiseResult[ 0 ] as {
126
+ reason?: CoreDataError;
127
+ };
128
+ if ( typedError.reason?.message ) {
129
+ errorMessage =
130
+ typedError.reason.message;
131
+ } else {
132
+ errorMessage = __(
133
+ 'An error occurred while moving the item to the trash.'
134
+ );
135
+ }
136
+ // If we were trying to delete multiple items.
137
+ } else {
138
+ const errorMessages = new Set();
139
+ const failedPromises = promiseResult.filter(
140
+ ( { status } ) => status === 'rejected'
141
+ );
142
+ for ( const failedPromise of failedPromises ) {
143
+ const typedError = failedPromise as {
144
+ reason?: CoreDataError;
145
+ };
146
+ if ( typedError.reason?.message ) {
147
+ errorMessages.add(
148
+ typedError.reason.message
149
+ );
150
+ }
151
+ }
152
+ if ( errorMessages.size === 0 ) {
153
+ errorMessage = __(
154
+ 'An error occurred while moving the items to the trash.'
155
+ );
156
+ } else if ( errorMessages.size === 1 ) {
157
+ errorMessage = sprintf(
158
+ /* translators: %s: an error message */
159
+ __(
160
+ 'An error occurred while moving the item to the trash: %s'
161
+ ),
162
+ [ ...errorMessages ][ 0 ]
163
+ );
164
+ } else {
165
+ errorMessage = sprintf(
166
+ /* translators: %s: a list of comma separated error messages */
167
+ __(
168
+ 'Some errors occurred while moving the items to the trash: %s'
169
+ ),
170
+ [ ...errorMessages ].join( ',' )
171
+ );
172
+ }
173
+ }
174
+ createErrorNotice( errorMessage, {
175
+ type: 'snackbar',
176
+ } );
177
+ }
178
+ if ( onActionPerformed ) {
179
+ onActionPerformed( items );
180
+ }
181
+ setIsBusy( false );
182
+ closeModal?.();
183
+ } }
184
+ isBusy={ isBusy }
185
+ disabled={ isBusy }
186
+ accessibleWhenDisabled
187
+ >
188
+ { _x( 'Trash', 'verb' ) }
189
+ </Button>
190
+ </HStack>
191
+ </VStack>
192
+ );
193
+ },
194
+ };
195
+
196
+ export default trashPost;
@@ -1,7 +1,22 @@
1
1
  /**
2
2
  * WordPress dependencies
3
3
  */
4
+ import { store as coreStore } from '@wordpress/core-data';
4
5
  import type { Action } from '@wordpress/dataviews';
6
+ import { doAction } from '@wordpress/hooks';
7
+
8
+ /**
9
+ * Internal dependencies
10
+ */
11
+ import deletePost from '../actions/delete-post';
12
+ import exportPattern from '../actions/export-pattern';
13
+ import resetPost from '../actions/reset-post';
14
+ import trashPost from '../actions/trash-post';
15
+ import permanentlyDeletePost from '../actions/permanently-delete-post';
16
+ import restorePost from '../actions/restore-post';
17
+ import type { PostType } from '../types';
18
+ import { store as editorStore } from '../../store';
19
+ import { unlock } from '../../lock-unlock';
5
20
 
6
21
  export function registerEntityAction< Item >(
7
22
  kind: string,
@@ -28,3 +43,56 @@ export function unregisterEntityAction(
28
43
  actionId,
29
44
  };
30
45
  }
46
+
47
+ export function setIsReady( kind: string, name: string ) {
48
+ return {
49
+ type: 'SET_IS_READY' as const,
50
+ kind,
51
+ name,
52
+ };
53
+ }
54
+
55
+ export const registerPostTypeActions =
56
+ ( postType: string ) =>
57
+ async ( { registry }: { registry: any } ) => {
58
+ const isReady = unlock( registry.select( editorStore ) ).isEntityReady(
59
+ 'postType',
60
+ postType
61
+ );
62
+ if ( isReady ) {
63
+ return;
64
+ }
65
+
66
+ unlock( registry.dispatch( editorStore ) ).setIsReady(
67
+ 'postType',
68
+ postType
69
+ );
70
+
71
+ const postTypeConfig = ( await registry
72
+ .resolveSelect( coreStore )
73
+ .getPostType( postType ) ) as PostType;
74
+
75
+ const actions = [
76
+ postTypeConfig.slug === 'wp_block' ? exportPattern : undefined,
77
+ resetPost,
78
+ restorePost,
79
+ deletePost,
80
+ trashPost,
81
+ permanentlyDeletePost,
82
+ ];
83
+
84
+ registry.batch( () => {
85
+ actions.forEach( ( action ) => {
86
+ if ( action === undefined ) {
87
+ return;
88
+ }
89
+ unlock( registry.dispatch( editorStore ) ).registerEntityAction(
90
+ 'postType',
91
+ postType,
92
+ action
93
+ );
94
+ } );
95
+ } );
96
+
97
+ doAction( 'core.registerPostTypeActions', postType );
98
+ };
@@ -1,22 +1,14 @@
1
- /**
2
- * WordPress dependencies
3
- */
4
- import { createSelector } from '@wordpress/data';
5
-
6
1
  /**
7
2
  * Internal dependencies
8
3
  */
9
4
  import type { State } from './reducer';
10
5
 
11
- export const getEntityActions = createSelector(
12
- ( state: State, kind: string, name: string ) => {
13
- return [
14
- ...( state.actions[ kind ]?.[ name ] ?? [] ),
15
- ...( state.actions[ kind ]?.[ '*' ] ?? [] ),
16
- ];
17
- },
18
- ( state: State, kind: string, name: string ) => [
19
- state.actions[ kind ]?.[ name ],
20
- state.actions[ kind ]?.[ '*' ],
21
- ]
22
- );
6
+ const EMPTY_ARRAY = [] as [];
7
+
8
+ export function getEntityActions( state: State, kind: string, name: string ) {
9
+ return state.actions[ kind ]?.[ name ] ?? EMPTY_ARRAY;
10
+ }
11
+
12
+ export function isEntityReady( state: State, kind: string, name: string ) {
13
+ return state.isReady[ kind ]?.[ name ];
14
+ }
@@ -6,13 +6,31 @@ import type { Action } from '@wordpress/dataviews';
6
6
 
7
7
  type ReduxAction =
8
8
  | ReturnType< typeof import('./private-actions').registerEntityAction >
9
- | ReturnType< typeof import('./private-actions').unregisterEntityAction >;
9
+ | ReturnType< typeof import('./private-actions').unregisterEntityAction >
10
+ | ReturnType< typeof import('./private-actions').setIsReady >;
10
11
 
11
12
  export type ActionState = Record< string, Record< string, Action< any >[] > >;
13
+ export type ReadyState = Record< string, Record< string, boolean > >;
12
14
  export type State = {
13
15
  actions: ActionState;
16
+ isReady: ReadyState;
14
17
  };
15
18
 
19
+ function isReady( state: ReadyState = {}, action: ReduxAction ) {
20
+ switch ( action.type ) {
21
+ case 'SET_IS_READY':
22
+ return {
23
+ ...state,
24
+ [ action.kind ]: {
25
+ ...state[ action.kind ],
26
+ [ action.name ]: true,
27
+ },
28
+ };
29
+ }
30
+
31
+ return state;
32
+ }
33
+
16
34
  function actions( state: ActionState = {}, action: ReduxAction ) {
17
35
  switch ( action.type ) {
18
36
  case 'REGISTER_ENTITY_ACTION':
@@ -48,4 +66,5 @@ function actions( state: ActionState = {}, action: ReduxAction ) {
48
66
 
49
67
  export default combineReducers( {
50
68
  actions,
69
+ isReady,
51
70
  } );
@@ -29,5 +29,16 @@ export interface Pattern extends BasePost {
29
29
 
30
30
  export type Post = TemplateOrTemplatePart | Pattern | BasePost;
31
31
 
32
+ export type PostWithPermissions = Post & {
33
+ permissions: {
34
+ delete: boolean;
35
+ update: boolean;
36
+ };
37
+ };
38
+
39
+ export interface PostType {
40
+ slug: string;
41
+ }
42
+
32
43
  // Will be unnecessary after typescript 5.0 upgrade.
33
44
  export type CoreDataError = { message?: string; code?: string };
@@ -23,7 +23,6 @@ import {
23
23
  mergeBaseAndUserConfigs,
24
24
  GlobalStylesProvider,
25
25
  } from './components/global-styles-provider';
26
- import registerDefaultActions from './dataviews/actions';
27
26
  import {
28
27
  registerCoreBlockBindingsSources,
29
28
  bootstrapBlockBindingsSourcesFromServer,
@@ -46,7 +45,6 @@ lock( privateApis, {
46
45
  ToolsMoreMenuGroup,
47
46
  ViewMoreMenuGroup,
48
47
  ResizableEditor,
49
- registerDefaultActions,
50
48
  registerCoreBlockBindingsSources,
51
49
  bootstrapBlockBindingsSourcesFromServer,
52
50