@wordpress/editor 13.18.0 → 13.19.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.
- package/CHANGELOG.md +2 -0
- package/README.md +0 -5
- package/build/components/page-attributes/parent.js +14 -13
- package/build/components/page-attributes/parent.js.map +1 -1
- package/build/components/post-author/combobox.js +1 -0
- package/build/components/post-author/combobox.js.map +1 -1
- package/build/components/post-last-revision/index.js +1 -2
- package/build/components/post-last-revision/index.js.map +1 -1
- package/build/components/post-sync-status/index.js +10 -10
- package/build/components/post-sync-status/index.js.map +1 -1
- package/build/components/post-taxonomies/flat-term-selector.js +9 -0
- package/build/components/post-taxonomies/flat-term-selector.js.map +1 -1
- package/build/components/post-taxonomies/hierarchical-term-selector.js +19 -5
- package/build/components/post-taxonomies/hierarchical-term-selector.js.map +1 -1
- package/build/components/provider/use-block-editor-settings.js +11 -7
- package/build/components/provider/use-block-editor-settings.js.map +1 -1
- package/build/store/selectors.js +2 -2
- package/build/store/selectors.js.map +1 -1
- package/build-module/components/page-attributes/parent.js +14 -13
- package/build-module/components/page-attributes/parent.js.map +1 -1
- package/build-module/components/post-author/combobox.js +1 -0
- package/build-module/components/post-author/combobox.js.map +1 -1
- package/build-module/components/post-last-revision/index.js +1 -2
- package/build-module/components/post-last-revision/index.js.map +1 -1
- package/build-module/components/post-sync-status/index.js +10 -10
- package/build-module/components/post-sync-status/index.js.map +1 -1
- package/build-module/components/post-taxonomies/flat-term-selector.js +9 -0
- package/build-module/components/post-taxonomies/flat-term-selector.js.map +1 -1
- package/build-module/components/post-taxonomies/hierarchical-term-selector.js +19 -5
- package/build-module/components/post-taxonomies/hierarchical-term-selector.js.map +1 -1
- package/build-module/components/provider/use-block-editor-settings.js +12 -8
- package/build-module/components/provider/use-block-editor-settings.js.map +1 -1
- package/build-module/store/selectors.js +2 -2
- package/build-module/store/selectors.js.map +1 -1
- package/build-style/style-rtl.css +2 -2
- package/build-style/style.css +2 -2
- package/package.json +31 -31
- package/src/components/page-attributes/parent.js +18 -15
- package/src/components/post-author/combobox.js +1 -0
- package/src/components/post-last-revision/index.js +0 -1
- package/src/components/post-saved-state/test/index.js +3 -1
- package/src/components/post-sync-status/index.js +14 -8
- package/src/components/post-taxonomies/flat-term-selector.js +15 -6
- package/src/components/post-taxonomies/hierarchical-term-selector.js +18 -7
- package/src/components/provider/use-block-editor-settings.js +21 -11
- package/src/store/selectors.js +16 -10
- package/src/store/test/selectors.js +25 -0
|
@@ -20,12 +20,21 @@ import { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor';
|
|
|
20
20
|
import { store as editorStore } from '../../store';
|
|
21
21
|
import { unlock } from '../../lock-unlock';
|
|
22
22
|
|
|
23
|
+
const { ReusableBlocksRenameHint } = unlock( blockEditorPrivateApis );
|
|
24
|
+
|
|
23
25
|
export default function PostSyncStatus() {
|
|
24
|
-
const { syncStatus, postType
|
|
26
|
+
const { syncStatus, postType } = useSelect( ( select ) => {
|
|
25
27
|
const { getEditedPostAttribute } = select( editorStore );
|
|
28
|
+
const meta = getEditedPostAttribute( 'meta' );
|
|
29
|
+
|
|
30
|
+
// When the post is first created, the top level wp_pattern_sync_status is not set so get meta value instead.
|
|
31
|
+
const currentSyncStatus =
|
|
32
|
+
meta?.wp_pattern_sync_status === 'unsynced'
|
|
33
|
+
? 'unsynced'
|
|
34
|
+
: getEditedPostAttribute( 'wp_pattern_sync_status' );
|
|
35
|
+
|
|
26
36
|
return {
|
|
27
|
-
syncStatus:
|
|
28
|
-
meta: getEditedPostAttribute( 'meta' ),
|
|
37
|
+
syncStatus: currentSyncStatus,
|
|
29
38
|
postType: getEditedPostAttribute( 'type' ),
|
|
30
39
|
};
|
|
31
40
|
} );
|
|
@@ -33,15 +42,12 @@ export default function PostSyncStatus() {
|
|
|
33
42
|
if ( postType !== 'wp_block' ) {
|
|
34
43
|
return null;
|
|
35
44
|
}
|
|
36
|
-
// When the post is first created, the top level wp_pattern_sync_status is not set so get meta value instead.
|
|
37
|
-
const currentSyncStatus =
|
|
38
|
-
meta?.wp_pattern_sync_status === 'unsynced' ? 'unsynced' : syncStatus;
|
|
39
45
|
|
|
40
46
|
return (
|
|
41
47
|
<PanelRow className="edit-post-sync-status">
|
|
42
48
|
<span>{ __( 'Sync status' ) }</span>
|
|
43
49
|
<div>
|
|
44
|
-
{
|
|
50
|
+
{ syncStatus === 'unsynced'
|
|
45
51
|
? __( 'Not synced' )
|
|
46
52
|
: __( 'Fully synced' ) }
|
|
47
53
|
</div>
|
|
@@ -82,7 +88,7 @@ export function PostSyncStatusModal() {
|
|
|
82
88
|
if ( postType !== 'wp_block' || ! isNewPost ) {
|
|
83
89
|
return null;
|
|
84
90
|
}
|
|
85
|
-
|
|
91
|
+
|
|
86
92
|
return (
|
|
87
93
|
<>
|
|
88
94
|
{ isModalOpen && (
|
|
@@ -8,6 +8,7 @@ import { useSelect, useDispatch } from '@wordpress/data';
|
|
|
8
8
|
import { store as coreStore } from '@wordpress/core-data';
|
|
9
9
|
import { useDebounce } from '@wordpress/compose';
|
|
10
10
|
import { speak } from '@wordpress/a11y';
|
|
11
|
+
import { store as noticesStore } from '@wordpress/notices';
|
|
11
12
|
|
|
12
13
|
/**
|
|
13
14
|
* Internal dependencies
|
|
@@ -138,6 +139,7 @@ export function FlatTermSelector( { slug } ) {
|
|
|
138
139
|
|
|
139
140
|
const { editPost } = useDispatch( editorStore );
|
|
140
141
|
const { saveEntityRecord } = useDispatch( coreStore );
|
|
142
|
+
const { createErrorNotice } = useDispatch( noticesStore );
|
|
141
143
|
|
|
142
144
|
if ( ! hasAssignAction ) {
|
|
143
145
|
return null;
|
|
@@ -204,12 +206,18 @@ export function FlatTermSelector( { slug } ) {
|
|
|
204
206
|
newTermNames.map( ( termName ) =>
|
|
205
207
|
findOrCreateTerm( { name: termName } )
|
|
206
208
|
)
|
|
207
|
-
)
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
209
|
+
)
|
|
210
|
+
.then( ( newTerms ) => {
|
|
211
|
+
const newAvailableTerms = availableTerms.concat( newTerms );
|
|
212
|
+
return onUpdateTerms(
|
|
213
|
+
termNamesToIds( uniqueTerms, newAvailableTerms )
|
|
214
|
+
);
|
|
215
|
+
} )
|
|
216
|
+
.catch( ( error ) => {
|
|
217
|
+
createErrorNotice( error.message, {
|
|
218
|
+
type: 'snackbar',
|
|
219
|
+
} );
|
|
220
|
+
} );
|
|
213
221
|
}
|
|
214
222
|
|
|
215
223
|
function appendTerm( newTerm ) {
|
|
@@ -254,6 +262,7 @@ export function FlatTermSelector( { slug } ) {
|
|
|
254
262
|
return (
|
|
255
263
|
<>
|
|
256
264
|
<FormTokenField
|
|
265
|
+
__next40pxDefaultSize
|
|
257
266
|
value={ values }
|
|
258
267
|
suggestions={ suggestions }
|
|
259
268
|
onChange={ onChange }
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { __, _n, _x, sprintf } from '@wordpress/i18n';
|
|
5
5
|
import { useMemo, useState } from '@wordpress/element';
|
|
6
|
+
import { store as noticesStore } from '@wordpress/notices';
|
|
6
7
|
import {
|
|
7
8
|
Button,
|
|
8
9
|
CheckboxControl,
|
|
@@ -216,6 +217,8 @@ export function HierarchicalTermSelector( { slug } ) {
|
|
|
216
217
|
[ availableTerms ]
|
|
217
218
|
);
|
|
218
219
|
|
|
220
|
+
const { createErrorNotice } = useDispatch( noticesStore );
|
|
221
|
+
|
|
219
222
|
if ( ! hasAssignAction ) {
|
|
220
223
|
return null;
|
|
221
224
|
}
|
|
@@ -227,7 +230,9 @@ export function HierarchicalTermSelector( { slug } ) {
|
|
|
227
230
|
* @return {Promise} A promise that resolves to save term object.
|
|
228
231
|
*/
|
|
229
232
|
const addTerm = ( term ) => {
|
|
230
|
-
return saveEntityRecord( 'taxonomy', slug, term
|
|
233
|
+
return saveEntityRecord( 'taxonomy', slug, term, {
|
|
234
|
+
throwOnError: true,
|
|
235
|
+
} );
|
|
231
236
|
};
|
|
232
237
|
|
|
233
238
|
/**
|
|
@@ -289,12 +294,18 @@ export function HierarchicalTermSelector( { slug } ) {
|
|
|
289
294
|
return;
|
|
290
295
|
}
|
|
291
296
|
setAdding( true );
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
297
|
+
let newTerm;
|
|
298
|
+
try {
|
|
299
|
+
newTerm = await addTerm( {
|
|
300
|
+
name: formName,
|
|
301
|
+
parent: formParent ? formParent : undefined,
|
|
302
|
+
} );
|
|
303
|
+
} catch ( error ) {
|
|
304
|
+
createErrorNotice( error.message, {
|
|
305
|
+
type: 'snackbar',
|
|
306
|
+
} );
|
|
307
|
+
return;
|
|
308
|
+
}
|
|
298
309
|
const defaultName =
|
|
299
310
|
slug === 'category' ? __( 'Category' ) : __( 'Term' );
|
|
300
311
|
const termAddedMessage = sprintf(
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* WordPress dependencies
|
|
3
3
|
*/
|
|
4
|
-
import { Platform, useMemo } from '@wordpress/element';
|
|
4
|
+
import { Platform, useMemo, useCallback } from '@wordpress/element';
|
|
5
5
|
import { useDispatch, useSelect } from '@wordpress/data';
|
|
6
6
|
import {
|
|
7
7
|
store as coreStore,
|
|
@@ -76,7 +76,6 @@ const BLOCK_EDITOR_SETTINGS = [
|
|
|
76
76
|
'__unstableIsPreviewMode',
|
|
77
77
|
'__unstableResolvedAssets',
|
|
78
78
|
'__unstableIsBlockBasedTheme',
|
|
79
|
-
'behaviors',
|
|
80
79
|
];
|
|
81
80
|
|
|
82
81
|
/**
|
|
@@ -95,11 +94,13 @@ function useBlockEditorSettings( settings, hasTemplate ) {
|
|
|
95
94
|
userCanCreatePages,
|
|
96
95
|
pageOnFront,
|
|
97
96
|
postType,
|
|
97
|
+
userPatternCategories,
|
|
98
98
|
} = useSelect( ( select ) => {
|
|
99
99
|
const { canUserUseUnfilteredHTML, getCurrentPostType } =
|
|
100
100
|
select( editorStore );
|
|
101
101
|
const isWeb = Platform.OS === 'web';
|
|
102
|
-
const { canUser, getEntityRecord } =
|
|
102
|
+
const { canUser, getEntityRecord, getUserPatternCategories } =
|
|
103
|
+
select( coreStore );
|
|
103
104
|
|
|
104
105
|
const siteSettings = canUser( 'read', 'settings' )
|
|
105
106
|
? getEntityRecord( 'root', 'site' )
|
|
@@ -118,6 +119,7 @@ function useBlockEditorSettings( settings, hasTemplate ) {
|
|
|
118
119
|
userCanCreatePages: canUser( 'create', 'pages' ),
|
|
119
120
|
pageOnFront: siteSettings?.page_on_front,
|
|
120
121
|
postType: getCurrentPostType(),
|
|
122
|
+
userPatternCategories: getUserPatternCategories(),
|
|
121
123
|
};
|
|
122
124
|
}, [] );
|
|
123
125
|
|
|
@@ -180,14 +182,19 @@ function useBlockEditorSettings( settings, hasTemplate ) {
|
|
|
180
182
|
* @param {Object} options parameters for the post being created. These mirror those used on 3rd param of saveEntityRecord.
|
|
181
183
|
* @return {Object} the post type object that was created.
|
|
182
184
|
*/
|
|
183
|
-
const createPageEntity = (
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
185
|
+
const createPageEntity = useCallback(
|
|
186
|
+
( options ) => {
|
|
187
|
+
if ( ! userCanCreatePages ) {
|
|
188
|
+
return Promise.reject( {
|
|
189
|
+
message: __(
|
|
190
|
+
'You do not have permission to create Pages.'
|
|
191
|
+
),
|
|
192
|
+
} );
|
|
193
|
+
}
|
|
194
|
+
return saveEntityRecord( 'postType', 'page', options );
|
|
195
|
+
},
|
|
196
|
+
[ saveEntityRecord, userCanCreatePages ]
|
|
197
|
+
);
|
|
191
198
|
|
|
192
199
|
return useMemo(
|
|
193
200
|
() => ( {
|
|
@@ -200,6 +207,7 @@ function useBlockEditorSettings( settings, hasTemplate ) {
|
|
|
200
207
|
__experimentalReusableBlocks: reusableBlocks,
|
|
201
208
|
__experimentalBlockPatterns: blockPatterns,
|
|
202
209
|
__experimentalBlockPatternCategories: blockPatternCategories,
|
|
210
|
+
__experimentalUserPatternCategories: userPatternCategories,
|
|
203
211
|
__experimentalFetchLinkSuggestions: ( search, searchOptions ) =>
|
|
204
212
|
fetchLinkSuggestions( search, searchOptions, settings ),
|
|
205
213
|
inserterMediaCategories,
|
|
@@ -216,11 +224,13 @@ function useBlockEditorSettings( settings, hasTemplate ) {
|
|
|
216
224
|
settings,
|
|
217
225
|
hasUploadPermissions,
|
|
218
226
|
reusableBlocks,
|
|
227
|
+
userPatternCategories,
|
|
219
228
|
blockPatterns,
|
|
220
229
|
blockPatternCategories,
|
|
221
230
|
canUseUnfilteredHTML,
|
|
222
231
|
undo,
|
|
223
232
|
hasTemplate,
|
|
233
|
+
createPageEntity,
|
|
224
234
|
userCanCreatePages,
|
|
225
235
|
pageOnFront,
|
|
226
236
|
]
|
package/src/store/selectors.js
CHANGED
|
@@ -289,17 +289,23 @@ export function getCurrentPostAttribute( state, attributeName ) {
|
|
|
289
289
|
*
|
|
290
290
|
* @return {*} Post attribute value.
|
|
291
291
|
*/
|
|
292
|
-
const getNestedEditedPostProperty = (
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
292
|
+
const getNestedEditedPostProperty = createSelector(
|
|
293
|
+
( state, attributeName ) => {
|
|
294
|
+
const edits = getPostEdits( state );
|
|
295
|
+
if ( ! edits.hasOwnProperty( attributeName ) ) {
|
|
296
|
+
return getCurrentPostAttribute( state, attributeName );
|
|
297
|
+
}
|
|
297
298
|
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
}
|
|
299
|
+
return {
|
|
300
|
+
...getCurrentPostAttribute( state, attributeName ),
|
|
301
|
+
...edits[ attributeName ],
|
|
302
|
+
};
|
|
303
|
+
},
|
|
304
|
+
( state, attributeName ) => [
|
|
305
|
+
getCurrentPostAttribute( state, attributeName ),
|
|
306
|
+
getPostEdits( state )[ attributeName ],
|
|
307
|
+
]
|
|
308
|
+
);
|
|
303
309
|
|
|
304
310
|
/**
|
|
305
311
|
* Returns a single attribute of the post being edited, preferring the unsaved
|
|
@@ -725,6 +725,31 @@ describe( 'selectors', () => {
|
|
|
725
725
|
b: 2,
|
|
726
726
|
} );
|
|
727
727
|
} );
|
|
728
|
+
|
|
729
|
+
it( 'should return the same value for mergeable properties when called multiple times', () => {
|
|
730
|
+
const state = {
|
|
731
|
+
currentPost: {
|
|
732
|
+
meta: {
|
|
733
|
+
a: 1,
|
|
734
|
+
b: 1,
|
|
735
|
+
},
|
|
736
|
+
},
|
|
737
|
+
editor: {
|
|
738
|
+
present: {
|
|
739
|
+
edits: {
|
|
740
|
+
meta: {
|
|
741
|
+
b: 2,
|
|
742
|
+
},
|
|
743
|
+
},
|
|
744
|
+
},
|
|
745
|
+
},
|
|
746
|
+
initialEdits: {},
|
|
747
|
+
};
|
|
748
|
+
|
|
749
|
+
expect( getEditedPostAttribute( state, 'meta' ) ).toBe(
|
|
750
|
+
getEditedPostAttribute( state, 'meta' )
|
|
751
|
+
);
|
|
752
|
+
} );
|
|
728
753
|
} );
|
|
729
754
|
|
|
730
755
|
describe( 'getCurrentPostLastRevisionId', () => {
|