@wordpress/editor 14.8.6 → 14.9.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 (115) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/build/components/block-settings-menu/content-only-settings-menu.js +15 -18
  3. package/build/components/block-settings-menu/content-only-settings-menu.js.map +1 -1
  4. package/build/components/document-tools/index.js +1 -6
  5. package/build/components/document-tools/index.js.map +1 -1
  6. package/build/components/header/index.js +22 -17
  7. package/build/components/header/index.js.map +1 -1
  8. package/build/components/inserter-sidebar/index.js +8 -9
  9. package/build/components/inserter-sidebar/index.js.map +1 -1
  10. package/build/components/provider/disable-non-page-content-blocks.js +17 -18
  11. package/build/components/provider/disable-non-page-content-blocks.js.map +1 -1
  12. package/build/components/provider/use-post-content-blocks.js +34 -0
  13. package/build/components/provider/use-post-content-blocks.js.map +1 -0
  14. package/build/components/resizable-editor/resize-handle.js +4 -0
  15. package/build/components/resizable-editor/resize-handle.js.map +1 -1
  16. package/build/components/zoom-out-toggle/index.js +1 -1
  17. package/build/components/zoom-out-toggle/index.js.map +1 -1
  18. package/build/dataviews/store/private-actions.js +2 -7
  19. package/build/dataviews/store/private-actions.js.map +1 -1
  20. package/build/store/actions.js +20 -5
  21. package/build/store/actions.js.map +1 -1
  22. package/build/store/private-selectors.js +3 -3
  23. package/build/store/private-selectors.js.map +1 -1
  24. package/build-module/components/block-settings-menu/content-only-settings-menu.js +14 -18
  25. package/build-module/components/block-settings-menu/content-only-settings-menu.js.map +1 -1
  26. package/build-module/components/document-tools/index.js +1 -6
  27. package/build-module/components/document-tools/index.js.map +1 -1
  28. package/build-module/components/header/index.js +22 -17
  29. package/build-module/components/header/index.js.map +1 -1
  30. package/build-module/components/inserter-sidebar/index.js +8 -9
  31. package/build-module/components/inserter-sidebar/index.js.map +1 -1
  32. package/build-module/components/provider/disable-non-page-content-blocks.js +17 -18
  33. package/build-module/components/provider/disable-non-page-content-blocks.js.map +1 -1
  34. package/build-module/components/provider/use-post-content-blocks.js +27 -0
  35. package/build-module/components/provider/use-post-content-blocks.js.map +1 -0
  36. package/build-module/components/resizable-editor/resize-handle.js +4 -0
  37. package/build-module/components/resizable-editor/resize-handle.js.map +1 -1
  38. package/build-module/components/zoom-out-toggle/index.js +1 -1
  39. package/build-module/components/zoom-out-toggle/index.js.map +1 -1
  40. package/build-module/dataviews/store/private-actions.js +4 -8
  41. package/build-module/dataviews/store/private-actions.js.map +1 -1
  42. package/build-module/store/actions.js +18 -5
  43. package/build-module/store/actions.js.map +1 -1
  44. package/build-module/store/private-selectors.js +2 -2
  45. package/build-module/store/private-selectors.js.map +1 -1
  46. package/build-style/style-rtl.css +10 -1
  47. package/build-style/style.css +10 -1
  48. package/build-types/components/document-tools/index.d.ts.map +1 -1
  49. package/build-types/components/header/index.d.ts.map +1 -1
  50. package/build-types/components/inserter-sidebar/index.d.ts.map +1 -1
  51. package/build-types/components/provider/disable-non-page-content-blocks.d.ts.map +1 -1
  52. package/build-types/components/provider/use-post-content-blocks.d.ts +2 -0
  53. package/build-types/components/provider/use-post-content-blocks.d.ts.map +1 -0
  54. package/build-types/components/resizable-editor/resize-handle.d.ts.map +1 -1
  55. package/build-types/store/actions.d.ts +1 -13
  56. package/build-types/store/actions.d.ts.map +1 -1
  57. package/build-types/store/private-selectors.d.ts +2 -2
  58. package/build-types/store/private-selectors.d.ts.map +1 -1
  59. package/package.json +37 -37
  60. package/src/components/block-settings-menu/content-only-settings-menu.js +19 -19
  61. package/src/components/document-tools/index.js +1 -4
  62. package/src/components/header/index.js +30 -14
  63. package/src/components/inserter-sidebar/index.js +8 -11
  64. package/src/components/provider/disable-non-page-content-blocks.js +20 -34
  65. package/src/components/provider/use-post-content-blocks.js +42 -0
  66. package/src/components/resizable-editor/resize-handle.js +5 -0
  67. package/src/components/zoom-out-toggle/index.js +1 -1
  68. package/src/dataviews/store/private-actions.ts +7 -7
  69. package/src/store/actions.js +23 -6
  70. package/src/store/private-selectors.js +2 -2
  71. package/src/store/test/actions.js +76 -0
  72. package/src/store/test/reducer.js +0 -22
  73. package/tsconfig.tsbuildinfo +1 -1
  74. package/build/dataviews/actions/delete-post.js +0 -98
  75. package/build/dataviews/actions/delete-post.js.map +0 -1
  76. package/build/dataviews/actions/rename-post.js +0 -125
  77. package/build/dataviews/actions/rename-post.js.map +0 -1
  78. package/build/dataviews/actions/reset-post.js +0 -113
  79. package/build/dataviews/actions/reset-post.js.map +0 -1
  80. package/build/dataviews/actions/restore-post.js +0 -112
  81. package/build/dataviews/actions/restore-post.js.map +0 -1
  82. package/build/dataviews/actions/trash-post.js +0 -144
  83. package/build/dataviews/actions/trash-post.js.map +0 -1
  84. package/build/dataviews/fields/index.js +0 -32
  85. package/build/dataviews/fields/index.js.map +0 -1
  86. package/build-module/dataviews/actions/delete-post.js +0 -89
  87. package/build-module/dataviews/actions/delete-post.js.map +0 -1
  88. package/build-module/dataviews/actions/rename-post.js +0 -118
  89. package/build-module/dataviews/actions/rename-post.js.map +0 -1
  90. package/build-module/dataviews/actions/reset-post.js +0 -106
  91. package/build-module/dataviews/actions/reset-post.js.map +0 -1
  92. package/build-module/dataviews/actions/restore-post.js +0 -104
  93. package/build-module/dataviews/actions/restore-post.js.map +0 -1
  94. package/build-module/dataviews/actions/trash-post.js +0 -137
  95. package/build-module/dataviews/actions/trash-post.js.map +0 -1
  96. package/build-module/dataviews/fields/index.js +0 -26
  97. package/build-module/dataviews/fields/index.js.map +0 -1
  98. package/build-types/dataviews/actions/delete-post.d.ts +0 -5
  99. package/build-types/dataviews/actions/delete-post.d.ts.map +0 -1
  100. package/build-types/dataviews/actions/rename-post.d.ts +0 -5
  101. package/build-types/dataviews/actions/rename-post.d.ts.map +0 -1
  102. package/build-types/dataviews/actions/reset-post.d.ts +0 -5
  103. package/build-types/dataviews/actions/reset-post.d.ts.map +0 -1
  104. package/build-types/dataviews/actions/restore-post.d.ts +0 -5
  105. package/build-types/dataviews/actions/restore-post.d.ts.map +0 -1
  106. package/build-types/dataviews/actions/trash-post.d.ts +0 -5
  107. package/build-types/dataviews/actions/trash-post.d.ts.map +0 -1
  108. package/build-types/dataviews/fields/index.d.ts +0 -8
  109. package/build-types/dataviews/fields/index.d.ts.map +0 -1
  110. package/src/dataviews/actions/delete-post.tsx +0 -109
  111. package/src/dataviews/actions/rename-post.tsx +0 -146
  112. package/src/dataviews/actions/reset-post.tsx +0 -147
  113. package/src/dataviews/actions/restore-post.tsx +0 -134
  114. package/src/dataviews/actions/trash-post.tsx +0 -198
  115. package/src/dataviews/fields/index.ts +0 -26
@@ -1,147 +0,0 @@
1
- /**
2
- * WordPress dependencies
3
- */
4
- import { backup } from '@wordpress/icons';
5
- import { useDispatch } from '@wordpress/data';
6
- import { store as coreStore } from '@wordpress/core-data';
7
- import { __, sprintf } 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
- import type { StoreDescriptor } from '@wordpress/data';
18
-
19
- /**
20
- * Internal dependencies
21
- */
22
- import { TEMPLATE_POST_TYPE, TEMPLATE_ORIGINS } from '../../store/constants';
23
- import { store as editorStore } from '../../store';
24
- import { unlock } from '../../lock-unlock';
25
- import type { Post, CoreDataError } from '../types';
26
- import { isTemplateOrTemplatePart, getItemTitle } from './utils';
27
-
28
- const resetPost: Action< Post > = {
29
- id: 'reset-post',
30
- label: __( 'Reset' ),
31
- isEligible: ( item ) => {
32
- return (
33
- isTemplateOrTemplatePart( item ) &&
34
- item?.source === TEMPLATE_ORIGINS.custom &&
35
- ( Boolean( item.type === 'wp_template' && item?.plugin ) ||
36
- item?.has_theme_file )
37
- );
38
- },
39
- icon: backup,
40
- supportsBulk: true,
41
- hideModalHeader: true,
42
- RenderModal: ( { items, closeModal, onActionPerformed } ) => {
43
- const [ isBusy, setIsBusy ] = useState( false );
44
- const { revertTemplate } = unlock(
45
- useDispatch( editorStore as StoreDescriptor )
46
- );
47
- const { saveEditedEntityRecord } = useDispatch( coreStore );
48
- const { createSuccessNotice, createErrorNotice } =
49
- useDispatch( noticesStore );
50
- const onConfirm = async () => {
51
- try {
52
- for ( const template of items ) {
53
- await revertTemplate( template, {
54
- allowUndo: false,
55
- } );
56
- await saveEditedEntityRecord(
57
- 'postType',
58
- template.type,
59
- template.id
60
- );
61
- }
62
- createSuccessNotice(
63
- items.length > 1
64
- ? sprintf(
65
- /* translators: The number of items. */
66
- __( '%s items reset.' ),
67
- items.length
68
- )
69
- : sprintf(
70
- /* translators: The template/part's name. */
71
- __( '"%s" reset.' ),
72
- getItemTitle( items[ 0 ] )
73
- ),
74
- {
75
- type: 'snackbar',
76
- id: 'revert-template-action',
77
- }
78
- );
79
- } catch ( error ) {
80
- let fallbackErrorMessage;
81
- if ( items[ 0 ].type === TEMPLATE_POST_TYPE ) {
82
- fallbackErrorMessage =
83
- items.length === 1
84
- ? __(
85
- 'An error occurred while reverting the template.'
86
- )
87
- : __(
88
- 'An error occurred while reverting the templates.'
89
- );
90
- } else {
91
- fallbackErrorMessage =
92
- items.length === 1
93
- ? __(
94
- 'An error occurred while reverting the template part.'
95
- )
96
- : __(
97
- 'An error occurred while reverting the template parts.'
98
- );
99
- }
100
-
101
- const typedError = error as CoreDataError;
102
- const errorMessage =
103
- typedError.message && typedError.code !== 'unknown_error'
104
- ? typedError.message
105
- : fallbackErrorMessage;
106
-
107
- createErrorNotice( errorMessage, { type: 'snackbar' } );
108
- }
109
- };
110
- return (
111
- <VStack spacing="5">
112
- <Text>
113
- { __( 'Reset to default and clear all customizations?' ) }
114
- </Text>
115
- <HStack justify="right">
116
- <Button
117
- __next40pxDefaultSize
118
- variant="tertiary"
119
- onClick={ closeModal }
120
- disabled={ isBusy }
121
- accessibleWhenDisabled
122
- >
123
- { __( 'Cancel' ) }
124
- </Button>
125
- <Button
126
- __next40pxDefaultSize
127
- variant="primary"
128
- onClick={ async () => {
129
- setIsBusy( true );
130
- await onConfirm();
131
- onActionPerformed?.( items );
132
- setIsBusy( false );
133
- closeModal?.();
134
- } }
135
- isBusy={ isBusy }
136
- disabled={ isBusy }
137
- accessibleWhenDisabled
138
- >
139
- { __( 'Reset' ) }
140
- </Button>
141
- </HStack>
142
- </VStack>
143
- );
144
- },
145
- };
146
-
147
- export default resetPost;
@@ -1,134 +0,0 @@
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;
@@ -1,198 +0,0 @@
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
- __next40pxDefaultSize
71
- variant="tertiary"
72
- onClick={ closeModal }
73
- disabled={ isBusy }
74
- accessibleWhenDisabled
75
- >
76
- { __( 'Cancel' ) }
77
- </Button>
78
- <Button
79
- __next40pxDefaultSize
80
- variant="primary"
81
- onClick={ async () => {
82
- setIsBusy( true );
83
- const promiseResult = await Promise.allSettled(
84
- items.map( ( item ) =>
85
- deleteEntityRecord(
86
- 'postType',
87
- item.type,
88
- item.id.toString(),
89
- {},
90
- { throwOnError: true }
91
- )
92
- )
93
- );
94
- // If all the promises were fulfilled with success.
95
- if (
96
- promiseResult.every(
97
- ( { status } ) => status === 'fulfilled'
98
- )
99
- ) {
100
- let successMessage;
101
- if ( promiseResult.length === 1 ) {
102
- successMessage = sprintf(
103
- /* translators: The item's title. */
104
- __( '"%s" moved to the trash.' ),
105
- getItemTitle( items[ 0 ] )
106
- );
107
- } else {
108
- successMessage = sprintf(
109
- /* translators: The number of items. */
110
- _n(
111
- '%s item moved to the trash.',
112
- '%s items moved to the trash.',
113
- items.length
114
- ),
115
- items.length
116
- );
117
- }
118
- createSuccessNotice( successMessage, {
119
- type: 'snackbar',
120
- id: 'move-to-trash-action',
121
- } );
122
- } else {
123
- // If there was at least one failure.
124
- let errorMessage;
125
- // If we were trying to delete a single item.
126
- if ( promiseResult.length === 1 ) {
127
- const typedError = promiseResult[ 0 ] as {
128
- reason?: CoreDataError;
129
- };
130
- if ( typedError.reason?.message ) {
131
- errorMessage =
132
- typedError.reason.message;
133
- } else {
134
- errorMessage = __(
135
- 'An error occurred while moving the item to the trash.'
136
- );
137
- }
138
- // If we were trying to delete multiple items.
139
- } else {
140
- const errorMessages = new Set();
141
- const failedPromises = promiseResult.filter(
142
- ( { status } ) => status === 'rejected'
143
- );
144
- for ( const failedPromise of failedPromises ) {
145
- const typedError = failedPromise as {
146
- reason?: CoreDataError;
147
- };
148
- if ( typedError.reason?.message ) {
149
- errorMessages.add(
150
- typedError.reason.message
151
- );
152
- }
153
- }
154
- if ( errorMessages.size === 0 ) {
155
- errorMessage = __(
156
- 'An error occurred while moving the items to the trash.'
157
- );
158
- } else if ( errorMessages.size === 1 ) {
159
- errorMessage = sprintf(
160
- /* translators: %s: an error message */
161
- __(
162
- 'An error occurred while moving the item to the trash: %s'
163
- ),
164
- [ ...errorMessages ][ 0 ]
165
- );
166
- } else {
167
- errorMessage = sprintf(
168
- /* translators: %s: a list of comma separated error messages */
169
- __(
170
- 'Some errors occurred while moving the items to the trash: %s'
171
- ),
172
- [ ...errorMessages ].join( ',' )
173
- );
174
- }
175
- }
176
- createErrorNotice( errorMessage, {
177
- type: 'snackbar',
178
- } );
179
- }
180
- if ( onActionPerformed ) {
181
- onActionPerformed( items );
182
- }
183
- setIsBusy( false );
184
- closeModal?.();
185
- } }
186
- isBusy={ isBusy }
187
- disabled={ isBusy }
188
- accessibleWhenDisabled
189
- >
190
- { _x( 'Trash', 'verb' ) }
191
- </Button>
192
- </HStack>
193
- </VStack>
194
- );
195
- },
196
- };
197
-
198
- export default trashPost;
@@ -1,26 +0,0 @@
1
- /**
2
- * WordPress dependencies
3
- */
4
- import { __ } from '@wordpress/i18n';
5
- import type { Field } from '@wordpress/dataviews';
6
-
7
- /**
8
- * Internal dependencies
9
- */
10
- import type { BasePost } from '../types';
11
- import { getItemTitle } from '../actions/utils';
12
-
13
- export const titleField: Field< BasePost > = {
14
- type: 'text',
15
- id: 'title',
16
- label: __( 'Title' ),
17
- placeholder: __( 'No title' ),
18
- getValue: ( { item } ) => getItemTitle( item ),
19
- };
20
-
21
- export const orderField: Field< BasePost > = {
22
- type: 'integer',
23
- id: 'menu_order',
24
- label: __( 'Order' ),
25
- description: __( 'Determines the order of pages.' ),
26
- };