@wordpress/editor 12.2.2 → 12.3.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 +6 -0
- package/build/components/deprecated.js +1 -1
- package/build/components/deprecated.js.map +1 -1
- package/build/components/deprecated.native.js.map +1 -1
- package/build/components/editor-help/index.native.js.map +1 -1
- package/build/components/entities-saved-states/entity-record-item.js +1 -1
- package/build/components/entities-saved-states/entity-record-item.js.map +1 -1
- package/build/components/global-keyboard-shortcuts/register-shortcuts.js +1 -1
- package/build/components/global-keyboard-shortcuts/register-shortcuts.js.map +1 -1
- package/build/components/index.js.map +1 -1
- package/build/components/index.native.js.map +1 -1
- package/build/components/post-featured-image/index.js +4 -4
- package/build/components/post-featured-image/index.js.map +1 -1
- package/build/components/post-last-revision/index.js +3 -3
- package/build/components/post-last-revision/index.js.map +1 -1
- package/build/components/post-locked-modal/index.js +1 -3
- package/build/components/post-locked-modal/index.js.map +1 -1
- package/build/components/post-schedule/index.js +3 -3
- package/build/components/post-schedule/index.js.map +1 -1
- package/build/components/post-slug/index.js +2 -4
- package/build/components/post-slug/index.js.map +1 -1
- package/build/components/post-taxonomies/hierarchical-term-selector.js +2 -2
- package/build/components/post-taxonomies/hierarchical-term-selector.js.map +1 -1
- package/build/components/post-title/index.native.js +2 -2
- package/build/components/post-title/index.native.js.map +1 -1
- package/build/components/provider/index.js +1 -1
- package/build/components/provider/index.js.map +1 -1
- package/build/components/provider/index.native.js +7 -7
- package/build/components/provider/index.native.js.map +1 -1
- package/build/components/provider/use-block-editor-settings.js +0 -6
- package/build/components/provider/use-block-editor-settings.js.map +1 -1
- package/build/store/selectors.js +8 -10
- package/build/store/selectors.js.map +1 -1
- package/build/store/utils/notice-builder.js +4 -4
- package/build/store/utils/notice-builder.js.map +1 -1
- package/build/utils/url.js +9 -26
- package/build/utils/url.js.map +1 -1
- package/build-module/components/deprecated.js +1 -1
- package/build-module/components/deprecated.js.map +1 -1
- package/build-module/components/deprecated.native.js +1 -1
- package/build-module/components/deprecated.native.js.map +1 -1
- package/build-module/components/editor-help/index.native.js.map +1 -1
- package/build-module/components/entities-saved-states/entity-record-item.js +1 -1
- package/build-module/components/entities-saved-states/entity-record-item.js.map +1 -1
- package/build-module/components/global-keyboard-shortcuts/register-shortcuts.js +1 -1
- package/build-module/components/global-keyboard-shortcuts/register-shortcuts.js.map +1 -1
- package/build-module/components/index.js +3 -3
- package/build-module/components/index.js.map +1 -1
- package/build-module/components/index.native.js +3 -3
- package/build-module/components/index.native.js.map +1 -1
- package/build-module/components/post-featured-image/index.js +4 -4
- package/build-module/components/post-featured-image/index.js.map +1 -1
- package/build-module/components/post-last-revision/index.js +2 -2
- package/build-module/components/post-last-revision/index.js.map +1 -1
- package/build-module/components/post-locked-modal/index.js +1 -2
- package/build-module/components/post-locked-modal/index.js.map +1 -1
- package/build-module/components/post-schedule/index.js +3 -3
- package/build-module/components/post-schedule/index.js.map +1 -1
- package/build-module/components/post-slug/index.js +1 -2
- package/build-module/components/post-slug/index.js.map +1 -1
- package/build-module/components/post-taxonomies/hierarchical-term-selector.js +2 -2
- package/build-module/components/post-taxonomies/hierarchical-term-selector.js.map +1 -1
- package/build-module/components/post-title/index.native.js +2 -2
- package/build-module/components/post-title/index.native.js.map +1 -1
- package/build-module/components/provider/index.js +1 -1
- package/build-module/components/provider/index.js.map +1 -1
- package/build-module/components/provider/index.native.js +7 -7
- package/build-module/components/provider/index.native.js.map +1 -1
- package/build-module/components/provider/use-block-editor-settings.js +0 -6
- package/build-module/components/provider/use-block-editor-settings.js.map +1 -1
- package/build-module/store/selectors.js +8 -9
- package/build-module/store/selectors.js.map +1 -1
- package/build-module/store/utils/notice-builder.js +4 -4
- package/build-module/store/utils/notice-builder.js.map +1 -1
- package/build-module/utils/url.js +8 -25
- package/build-module/utils/url.js.map +1 -1
- package/package.json +26 -26
- package/src/components/deprecated.js +1 -1
- package/src/components/deprecated.native.js +1 -1
- package/src/components/document-outline/test/index.js +1 -1
- package/src/components/editor-help/index.native.js +2 -2
- package/src/components/entities-saved-states/entity-record-item.js +1 -1
- package/src/components/global-keyboard-shortcuts/register-shortcuts.js +1 -1
- package/src/components/index.js +3 -3
- package/src/components/index.native.js +3 -3
- package/src/components/post-author/test/check.js +1 -1
- package/src/components/post-featured-image/index.js +4 -4
- package/src/components/post-last-revision/index.js +2 -2
- package/src/components/post-locked-modal/index.js +1 -2
- package/src/components/post-saved-state/test/index.js +2 -2
- package/src/components/post-schedule/index.js +3 -3
- package/src/components/post-slug/index.js +1 -2
- package/src/components/post-taxonomies/hierarchical-term-selector.js +2 -2
- package/src/components/post-text-editor/test/index.js +1 -1
- package/src/components/post-title/index.native.js +2 -2
- package/src/components/provider/index.js +1 -1
- package/src/components/provider/index.native.js +7 -7
- package/src/components/provider/use-block-editor-settings.js +1 -14
- package/src/store/selectors.js +8 -9
- package/src/store/test/actions.js +31 -31
- package/src/store/test/selectors.js +1 -1
- package/src/store/utils/notice-builder.js +4 -4
- package/src/utils/url.js +8 -30
- package/src/utils/test/url.js +0 -22
|
@@ -147,7 +147,7 @@ describe( 'DocumentOutline', () => {
|
|
|
147
147
|
const blocks = [ headingH2, nestedHeading ];
|
|
148
148
|
const wrapper = mount( <DocumentOutline blocks={ blocks } /> );
|
|
149
149
|
|
|
150
|
-
// Unnested heading and nested heading should appear as items
|
|
150
|
+
// Unnested heading and nested heading should appear as items.
|
|
151
151
|
const tableOfContentItems = wrapper.find(
|
|
152
152
|
tableOfContentItemsSelector
|
|
153
153
|
);
|
|
@@ -133,7 +133,7 @@ function EditorHelpTopics( { close, isVisible, onClose } ) {
|
|
|
133
133
|
<Text style={ sectionTitle }>
|
|
134
134
|
{ __( 'The basics' ) }
|
|
135
135
|
</Text>
|
|
136
|
-
{ /* Print out help topics */ }
|
|
136
|
+
{ /* Print out help topics. */ }
|
|
137
137
|
{ HELP_TOPICS.map(
|
|
138
138
|
( { label, icon } ) => {
|
|
139
139
|
const labelSlug = kebabCase(
|
|
@@ -187,7 +187,7 @@ function EditorHelpTopics( { close, isVisible, onClose } ) {
|
|
|
187
187
|
</BottomSheetConsumer>
|
|
188
188
|
</View>
|
|
189
189
|
</BottomSheet.NavigationScreen>
|
|
190
|
-
{ /* Print out help detail screens */ }
|
|
190
|
+
{ /* Print out help detail screens. */ }
|
|
191
191
|
{ HELP_TOPICS.map( ( { view, label } ) => {
|
|
192
192
|
const labelSlug = kebabCase( label );
|
|
193
193
|
return (
|
|
@@ -36,7 +36,7 @@ export default function EntityRecordItem( {
|
|
|
36
36
|
return parents[ parents.length - 1 ];
|
|
37
37
|
}, [] );
|
|
38
38
|
|
|
39
|
-
// Handle templates that might use default descriptive titles
|
|
39
|
+
// Handle templates that might use default descriptive titles.
|
|
40
40
|
const entityRecordTitle = useSelect(
|
|
41
41
|
( select ) => {
|
|
42
42
|
if ( 'postType' !== kind || 'wp_template' !== name ) {
|
|
@@ -8,7 +8,7 @@ import { BlockEditorKeyboardShortcuts } from '@wordpress/block-editor';
|
|
|
8
8
|
import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';
|
|
9
9
|
|
|
10
10
|
function EditorKeyboardShortcutsRegister() {
|
|
11
|
-
// Registering the shortcuts
|
|
11
|
+
// Registering the shortcuts.
|
|
12
12
|
const { registerShortcut } = useDispatch( keyboardShortcutsStore );
|
|
13
13
|
useEffect( () => {
|
|
14
14
|
registerShortcut( {
|
package/src/components/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
// Block Creation Components
|
|
1
|
+
// Block Creation Components.
|
|
2
2
|
export * from './autocompleters';
|
|
3
3
|
|
|
4
|
-
// Post Related Components
|
|
4
|
+
// Post Related Components.
|
|
5
5
|
export { default as AutosaveMonitor } from './autosave-monitor';
|
|
6
6
|
export { default as DocumentOutline } from './document-outline';
|
|
7
7
|
export { default as DocumentOutlineCheck } from './document-outline/check';
|
|
@@ -64,7 +64,7 @@ export { default as ThemeSupportCheck } from './theme-support-check';
|
|
|
64
64
|
export { default as UnsavedChangesWarning } from './unsaved-changes-warning';
|
|
65
65
|
export { default as WordCount } from './word-count';
|
|
66
66
|
|
|
67
|
-
// State Related Components
|
|
67
|
+
// State Related Components.
|
|
68
68
|
export { default as EditorProvider } from './provider';
|
|
69
69
|
|
|
70
70
|
export * from './deprecated';
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
// Post Related Components
|
|
1
|
+
// Post Related Components.
|
|
2
2
|
export { default as AutosaveMonitor } from './autosave-monitor';
|
|
3
3
|
export { default as PostTitle } from './post-title';
|
|
4
4
|
export { default as EditorHistoryRedo } from './editor-history/redo';
|
|
5
5
|
export { default as EditorHistoryUndo } from './editor-history/undo';
|
|
6
6
|
|
|
7
|
-
// State Related Components
|
|
7
|
+
// State Related Components.
|
|
8
8
|
export { default as EditorProvider } from './provider';
|
|
9
9
|
|
|
10
|
-
// Other Components
|
|
10
|
+
// Other Components.
|
|
11
11
|
export { default as EditorHelpTopics } from './editor-help';
|
|
12
12
|
|
|
13
13
|
export * from './deprecated';
|
|
@@ -14,7 +14,7 @@ import { useSelect } from '@wordpress/data';
|
|
|
14
14
|
import PostAuthorCheck from '../check';
|
|
15
15
|
|
|
16
16
|
jest.mock( '@wordpress/data/src/components/use-select', () => {
|
|
17
|
-
// This allows us to tweak the returned value on each test
|
|
17
|
+
// This allows us to tweak the returned value on each test.
|
|
18
18
|
const mock = jest.fn();
|
|
19
19
|
return mock;
|
|
20
20
|
} );
|
|
@@ -66,12 +66,12 @@ function PostFeaturedImage( {
|
|
|
66
66
|
currentPostId
|
|
67
67
|
);
|
|
68
68
|
if ( has( media, [ 'media_details', 'sizes', mediaSize ] ) ) {
|
|
69
|
-
//
|
|
69
|
+
// Use mediaSize when available.
|
|
70
70
|
mediaWidth = media.media_details.sizes[ mediaSize ].width;
|
|
71
71
|
mediaHeight = media.media_details.sizes[ mediaSize ].height;
|
|
72
72
|
mediaSourceUrl = media.media_details.sizes[ mediaSize ].source_url;
|
|
73
73
|
} else {
|
|
74
|
-
//
|
|
74
|
+
// Get fallbackMediaSize if mediaSize is not available.
|
|
75
75
|
const fallbackMediaSize = applyFilters(
|
|
76
76
|
'editor.PostFeaturedImage.imageSize',
|
|
77
77
|
'thumbnail',
|
|
@@ -81,7 +81,7 @@ function PostFeaturedImage( {
|
|
|
81
81
|
if (
|
|
82
82
|
has( media, [ 'media_details', 'sizes', fallbackMediaSize ] )
|
|
83
83
|
) {
|
|
84
|
-
//
|
|
84
|
+
// Use fallbackMediaSize when mediaSize is not available.
|
|
85
85
|
mediaWidth =
|
|
86
86
|
media.media_details.sizes[ fallbackMediaSize ].width;
|
|
87
87
|
mediaHeight =
|
|
@@ -89,7 +89,7 @@ function PostFeaturedImage( {
|
|
|
89
89
|
mediaSourceUrl =
|
|
90
90
|
media.media_details.sizes[ fallbackMediaSize ].source_url;
|
|
91
91
|
} else {
|
|
92
|
-
//
|
|
92
|
+
// Use full image size when mediaFallbackSize and mediaSize are not available.
|
|
93
93
|
mediaWidth = media.media_details.width;
|
|
94
94
|
mediaHeight = media.media_details.height;
|
|
95
95
|
mediaSourceUrl = media.source_url;
|
|
@@ -5,19 +5,19 @@ import { sprintf, _n } from '@wordpress/i18n';
|
|
|
5
5
|
import { Button } from '@wordpress/components';
|
|
6
6
|
import { withSelect } from '@wordpress/data';
|
|
7
7
|
import { backup } from '@wordpress/icons';
|
|
8
|
+
import { addQueryArgs } from '@wordpress/url';
|
|
8
9
|
|
|
9
10
|
/**
|
|
10
11
|
* Internal dependencies
|
|
11
12
|
*/
|
|
12
13
|
import PostLastRevisionCheck from './check';
|
|
13
|
-
import { getWPAdminURL } from '../../utils/url';
|
|
14
14
|
import { store as editorStore } from '../../store';
|
|
15
15
|
|
|
16
16
|
function LastRevision( { lastRevisionId, revisionsCount } ) {
|
|
17
17
|
return (
|
|
18
18
|
<PostLastRevisionCheck>
|
|
19
19
|
<Button
|
|
20
|
-
href={
|
|
20
|
+
href={ addQueryArgs( 'revision.php', {
|
|
21
21
|
revision: lastRevisionId,
|
|
22
22
|
gutenberg: true,
|
|
23
23
|
} ) }
|
|
@@ -24,7 +24,6 @@ import { store as coreStore } from '@wordpress/core-data';
|
|
|
24
24
|
/**
|
|
25
25
|
* Internal dependencies
|
|
26
26
|
*/
|
|
27
|
-
import { getWPAdminURL } from '../../utils/url';
|
|
28
27
|
import { store as editorStore } from '../../store';
|
|
29
28
|
|
|
30
29
|
export default function PostLockedModal() {
|
|
@@ -164,7 +163,7 @@ export default function PostLockedModal() {
|
|
|
164
163
|
action: 'edit',
|
|
165
164
|
_wpnonce: postLockUtils.nonce,
|
|
166
165
|
} );
|
|
167
|
-
const allPostsUrl =
|
|
166
|
+
const allPostsUrl = addQueryArgs( 'edit.php', {
|
|
168
167
|
post_type: get( postType, [ 'slug' ] ),
|
|
169
168
|
} );
|
|
170
169
|
const allPostsLabel = __( 'Exit editor' );
|
|
@@ -23,13 +23,13 @@ jest.mock( '@wordpress/data/src/components/use-dispatch', () => {
|
|
|
23
23
|
} );
|
|
24
24
|
|
|
25
25
|
jest.mock( '@wordpress/data/src/components/use-select', () => {
|
|
26
|
-
// This allows us to tweak the returned value on each test
|
|
26
|
+
// This allows us to tweak the returned value on each test.
|
|
27
27
|
const mock = jest.fn();
|
|
28
28
|
return mock;
|
|
29
29
|
} );
|
|
30
30
|
|
|
31
31
|
jest.mock( '@wordpress/compose/src/hooks/use-viewport-match', () => {
|
|
32
|
-
// This allows us to tweak the returned value on each test
|
|
32
|
+
// This allows us to tweak the returned value on each test.
|
|
33
33
|
const mock = jest.fn();
|
|
34
34
|
return mock;
|
|
35
35
|
} );
|
|
@@ -68,11 +68,11 @@ export default function PostSchedule() {
|
|
|
68
68
|
// We also make sure this a is not escaped by a "/"
|
|
69
69
|
const is12HourTime = /a(?!\\)/i.test(
|
|
70
70
|
settings.formats.time
|
|
71
|
-
.toLowerCase() // Test only the lower case a
|
|
72
|
-
.replace( /\\\\/g, '' ) // Replace "//" with empty strings
|
|
71
|
+
.toLowerCase() // Test only the lower case a.
|
|
72
|
+
.replace( /\\\\/g, '' ) // Replace "//" with empty strings.
|
|
73
73
|
.split( '' )
|
|
74
74
|
.reverse()
|
|
75
|
-
.join( '' ) // Reverse the string and test for "a" not followed by a slash
|
|
75
|
+
.join( '' ) // Reverse the string and test for "a" not followed by a slash.
|
|
76
76
|
);
|
|
77
77
|
|
|
78
78
|
function onChange( newDate ) {
|
|
@@ -5,13 +5,12 @@ import { withDispatch, withSelect } from '@wordpress/data';
|
|
|
5
5
|
import { Component } from '@wordpress/element';
|
|
6
6
|
import { __ } from '@wordpress/i18n';
|
|
7
7
|
import { withInstanceId, compose } from '@wordpress/compose';
|
|
8
|
-
import { safeDecodeURIComponent } from '@wordpress/url';
|
|
8
|
+
import { safeDecodeURIComponent, cleanForSlug } from '@wordpress/url';
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* Internal dependencies
|
|
12
12
|
*/
|
|
13
13
|
import PostSlugCheck from './check';
|
|
14
|
-
import { cleanForSlug } from '../../utils/url';
|
|
15
14
|
import { store as editorStore } from '../../store';
|
|
16
15
|
|
|
17
16
|
export class PostSlug extends Component {
|
|
@@ -288,10 +288,10 @@ function HierarchicalTermSelector( { slug } ) {
|
|
|
288
288
|
return;
|
|
289
289
|
}
|
|
290
290
|
|
|
291
|
-
//
|
|
291
|
+
// Check if the term we are adding already exists.
|
|
292
292
|
const existingTerm = findTerm( availableTerms, formParent, formName );
|
|
293
293
|
if ( existingTerm ) {
|
|
294
|
-
//
|
|
294
|
+
// If the term we are adding exists but is not selected select it.
|
|
295
295
|
if ( ! some( terms, ( term ) => term === existingTerm.id ) ) {
|
|
296
296
|
onUpdateTerms( [ ...terms, existingTerm.id ] );
|
|
297
297
|
}
|
|
@@ -21,7 +21,7 @@ jest.mock( 'react-autosize-textarea', () => ( props ) => (
|
|
|
21
21
|
) );
|
|
22
22
|
|
|
23
23
|
jest.mock( '@wordpress/data/src/components/use-select', () => {
|
|
24
|
-
// This allows us to tweak the returned value on each test
|
|
24
|
+
// This allows us to tweak the returned value on each test.
|
|
25
25
|
const mock = jest.fn();
|
|
26
26
|
return mock;
|
|
27
27
|
} );
|
|
@@ -34,7 +34,7 @@ class PostTitle extends Component {
|
|
|
34
34
|
this.setRef = this.setRef.bind( this );
|
|
35
35
|
}
|
|
36
36
|
componentDidUpdate( prevProps ) {
|
|
37
|
-
// Unselect if any other block is selected and blur the RichText
|
|
37
|
+
// Unselect if any other block is selected and blur the RichText.
|
|
38
38
|
if (
|
|
39
39
|
this.props.isSelected &&
|
|
40
40
|
! prevProps.isAnyBlockSelected &&
|
|
@@ -142,7 +142,7 @@ class PostTitle extends Component {
|
|
|
142
142
|
tagName={ 'p' }
|
|
143
143
|
tagsToEliminate={ [ 'strong' ] }
|
|
144
144
|
unstableOnFocus={ this.props.onSelect }
|
|
145
|
-
onBlur={ this.props.onBlur } //
|
|
145
|
+
onBlur={ this.props.onBlur } // Always assign onBlur as a props.
|
|
146
146
|
multiline={ false }
|
|
147
147
|
style={ titleStyles }
|
|
148
148
|
styles={ styles }
|
|
@@ -66,7 +66,7 @@ class NativeEditorProvider extends Component {
|
|
|
66
66
|
constructor() {
|
|
67
67
|
super( ...arguments );
|
|
68
68
|
|
|
69
|
-
// Keep a local reference to `post` to detect changes
|
|
69
|
+
// Keep a local reference to `post` to detect changes.
|
|
70
70
|
this.post = this.props.post;
|
|
71
71
|
this.props.addEntities( postTypeEntities );
|
|
72
72
|
this.props.receiveEntityRecords(
|
|
@@ -167,15 +167,15 @@ class NativeEditorProvider extends Component {
|
|
|
167
167
|
this.setState( { isHelpVisible: true } );
|
|
168
168
|
} );
|
|
169
169
|
|
|
170
|
-
// Request current block impressions from native app
|
|
170
|
+
// Request current block impressions from native app.
|
|
171
171
|
requestBlockTypeImpressions( ( storedImpressions ) => {
|
|
172
172
|
const impressions = { ...NEW_BLOCK_TYPES, ...storedImpressions };
|
|
173
173
|
|
|
174
|
-
// Persist impressions to JavaScript store
|
|
174
|
+
// Persist impressions to JavaScript store.
|
|
175
175
|
updateSettings( { impressions } );
|
|
176
176
|
|
|
177
177
|
// Persist impressions to native store if they do not include latest
|
|
178
|
-
// `NEW_BLOCK_TYPES` configuration
|
|
178
|
+
// `NEW_BLOCK_TYPES` configuration.
|
|
179
179
|
const storedImpressionKeys = Object.keys( storedImpressions );
|
|
180
180
|
const storedImpressionsCurrent = Object.keys(
|
|
181
181
|
NEW_BLOCK_TYPES
|
|
@@ -262,7 +262,7 @@ class NativeEditorProvider extends Component {
|
|
|
262
262
|
|
|
263
263
|
if ( this.props.mode === 'text' ) {
|
|
264
264
|
// The HTMLTextInput component does not update the store when user is doing changes
|
|
265
|
-
// Let's request the HTML from the component's state directly
|
|
265
|
+
// Let's request the HTML from the component's state directly.
|
|
266
266
|
html = applyFilters( 'native.persist-html' );
|
|
267
267
|
} else {
|
|
268
268
|
html = serialize( this.props.blocks );
|
|
@@ -305,9 +305,9 @@ class NativeEditorProvider extends Component {
|
|
|
305
305
|
|
|
306
306
|
toggleMode() {
|
|
307
307
|
const { mode, switchMode } = this.props;
|
|
308
|
-
//
|
|
308
|
+
// Refresh html content first.
|
|
309
309
|
this.serializeToNativeAction();
|
|
310
|
-
//
|
|
310
|
+
// Make sure to blur the selected block and dismiss the keyboard.
|
|
311
311
|
this.props.clearSelectedBlock();
|
|
312
312
|
switchMode( mode === 'visual' ? 'text' : 'visual' );
|
|
313
313
|
}
|
|
@@ -39,21 +39,10 @@ function useBlockEditorSettings( settings, hasTemplate ) {
|
|
|
39
39
|
} = useSelect( ( select ) => {
|
|
40
40
|
const { canUserUseUnfilteredHTML } = select( editorStore );
|
|
41
41
|
const isWeb = Platform.OS === 'web';
|
|
42
|
-
const {
|
|
43
|
-
canUser,
|
|
44
|
-
getUnstableBase,
|
|
45
|
-
hasFinishedResolution,
|
|
46
|
-
getEntityRecord,
|
|
47
|
-
} = select( coreStore );
|
|
42
|
+
const { canUser, getEntityRecord } = select( coreStore );
|
|
48
43
|
|
|
49
44
|
const siteSettings = getEntityRecord( 'root', 'site' );
|
|
50
45
|
|
|
51
|
-
const siteData = getUnstableBase();
|
|
52
|
-
|
|
53
|
-
const hasFinishedResolvingSiteData = hasFinishedResolution(
|
|
54
|
-
'getUnstableBase'
|
|
55
|
-
);
|
|
56
|
-
|
|
57
46
|
return {
|
|
58
47
|
canUseUnfilteredHTML: canUserUseUnfilteredHTML(),
|
|
59
48
|
reusableBlocks: isWeb
|
|
@@ -67,8 +56,6 @@ function useBlockEditorSettings( settings, hasTemplate ) {
|
|
|
67
56
|
canUser( 'create', 'media' ),
|
|
68
57
|
true
|
|
69
58
|
),
|
|
70
|
-
hasResolvedLocalSiteData: hasFinishedResolvingSiteData,
|
|
71
|
-
baseUrl: siteData?.url || '',
|
|
72
59
|
userCanCreatePages: canUser( 'create', 'pages' ),
|
|
73
60
|
pageOnFront: siteSettings?.page_on_front,
|
|
74
61
|
};
|
package/src/store/selectors.js
CHANGED
|
@@ -13,7 +13,7 @@ import {
|
|
|
13
13
|
__unstableSerializeAndClean,
|
|
14
14
|
} from '@wordpress/blocks';
|
|
15
15
|
import { isInTheFuture, getDate } from '@wordpress/date';
|
|
16
|
-
import { addQueryArgs } from '@wordpress/url';
|
|
16
|
+
import { addQueryArgs, cleanForSlug } from '@wordpress/url';
|
|
17
17
|
import { createRegistrySelector } from '@wordpress/data';
|
|
18
18
|
import deprecated from '@wordpress/deprecated';
|
|
19
19
|
import { Platform } from '@wordpress/element';
|
|
@@ -32,7 +32,6 @@ import {
|
|
|
32
32
|
AUTOSAVE_PROPERTIES,
|
|
33
33
|
} from './constants';
|
|
34
34
|
import { getPostRawValue } from './reducer';
|
|
35
|
-
import { cleanForSlug } from '../utils/url';
|
|
36
35
|
import { getTemplatePartIcon } from '../utils/get-template-part-icon';
|
|
37
36
|
|
|
38
37
|
/**
|
|
@@ -336,7 +335,7 @@ const getNestedEditedPostProperty = ( state, attributeName ) => {
|
|
|
336
335
|
* @return {*} Post attribute value.
|
|
337
336
|
*/
|
|
338
337
|
export function getEditedPostAttribute( state, attributeName ) {
|
|
339
|
-
// Special cases
|
|
338
|
+
// Special cases.
|
|
340
339
|
switch ( attributeName ) {
|
|
341
340
|
case 'content':
|
|
342
341
|
return getEditedPostContent( state );
|
|
@@ -477,7 +476,7 @@ export function isEditedPostPublishable( state ) {
|
|
|
477
476
|
// TODO: Post being publishable should be superset of condition of post
|
|
478
477
|
// being saveable. Currently this restriction is imposed at UI.
|
|
479
478
|
//
|
|
480
|
-
// See: <PostPublishButton /> (`isButtonEnabled` assigned by `isSaveable`)
|
|
479
|
+
// See: <PostPublishButton /> (`isButtonEnabled` assigned by `isSaveable`).
|
|
481
480
|
|
|
482
481
|
return (
|
|
483
482
|
isEditedPostDirty( state ) ||
|
|
@@ -506,7 +505,7 @@ export function isEditedPostSaveable( state ) {
|
|
|
506
505
|
// See: `isEditedPostPublishable` (includes `isEditedPostDirty` condition)
|
|
507
506
|
// See: <PostSavedState /> (`forceIsDirty` prop)
|
|
508
507
|
// See: <PostPublishButton /> (`forceIsDirty` prop)
|
|
509
|
-
// See: https://github.com/WordPress/gutenberg/pull/4184
|
|
508
|
+
// See: https://github.com/WordPress/gutenberg/pull/4184.
|
|
510
509
|
|
|
511
510
|
return (
|
|
512
511
|
!! getEditedPostAttribute( state, 'title' ) ||
|
|
@@ -643,7 +642,7 @@ export const isEditedPostAutosaveable = createRegistrySelector(
|
|
|
643
642
|
*/
|
|
644
643
|
export function isEditedPostBeingScheduled( state ) {
|
|
645
644
|
const date = getEditedPostAttribute( state, 'date' );
|
|
646
|
-
// Offset the date by one minute (network latency)
|
|
645
|
+
// Offset the date by one minute (network latency).
|
|
647
646
|
const checkedDate = new Date(
|
|
648
647
|
Number( getDate( date ) ) - ONE_MINUTE_IN_MS
|
|
649
648
|
);
|
|
@@ -671,7 +670,7 @@ export function isEditedPostDateFloating( state ) {
|
|
|
671
670
|
// This should be the status of the persisted post
|
|
672
671
|
// It shouldn't use the "edited" status otherwise it breaks the
|
|
673
672
|
// inferred post data floating status
|
|
674
|
-
// See https://github.com/WordPress/gutenberg/issues/28083
|
|
673
|
+
// See https://github.com/WordPress/gutenberg/issues/28083.
|
|
675
674
|
const status = getCurrentPost( state ).status;
|
|
676
675
|
if (
|
|
677
676
|
status === 'draft' ||
|
|
@@ -808,7 +807,7 @@ export function getEditedPostPreviewLink( state ) {
|
|
|
808
807
|
// If the post is draft, ignore the preview link from the autosave record,
|
|
809
808
|
// because the preview could be a stale autosave if the post was switched from
|
|
810
809
|
// published to draft.
|
|
811
|
-
// See: https://github.com/WordPress/gutenberg/pull/37952
|
|
810
|
+
// See: https://github.com/WordPress/gutenberg/pull/37952.
|
|
812
811
|
if ( ! previewLink || 'draft' === getCurrentPost( state ).status ) {
|
|
813
812
|
previewLink = getEditedPostAttribute( state, 'link' );
|
|
814
813
|
if ( previewLink ) {
|
|
@@ -843,7 +842,7 @@ export function getSuggestedPostFormat( state ) {
|
|
|
843
842
|
// so we can derive a suitable post format from it.
|
|
844
843
|
if ( blocks.length === 1 ) {
|
|
845
844
|
name = blocks[ 0 ].name;
|
|
846
|
-
//
|
|
845
|
+
// Check for core/embed `video` and `audio` eligible suggestions.
|
|
847
846
|
if ( name === 'core/embed' ) {
|
|
848
847
|
const provider = blocks[ 0 ].attributes?.providerNameSlug;
|
|
849
848
|
if ( [ 'youtube', 'vimeo' ].includes( provider ) ) {
|
|
@@ -38,19 +38,19 @@ const postTypeEntity = {
|
|
|
38
38
|
};
|
|
39
39
|
|
|
40
40
|
function createRegistryWithStores() {
|
|
41
|
-
//
|
|
41
|
+
// Create a registry.
|
|
42
42
|
const registry = createRegistry();
|
|
43
43
|
|
|
44
|
-
//
|
|
44
|
+
// Register stores.
|
|
45
45
|
registry.register( blockEditorStore );
|
|
46
46
|
registry.register( coreStore );
|
|
47
47
|
registry.register( editorStore );
|
|
48
48
|
registry.register( noticesStore );
|
|
49
49
|
|
|
50
|
-
//
|
|
50
|
+
// Register post type entity.
|
|
51
51
|
registry.dispatch( coreStore ).addEntities( [ postTypeConfig ] );
|
|
52
52
|
|
|
53
|
-
//
|
|
53
|
+
// Store post type entity.
|
|
54
54
|
registry
|
|
55
55
|
.dispatch( coreStore )
|
|
56
56
|
.receiveEntityRecords( 'root', 'postType', [ postTypeEntity ] );
|
|
@@ -73,7 +73,7 @@ describe( 'Post actions', () => {
|
|
|
73
73
|
status: 'draft',
|
|
74
74
|
};
|
|
75
75
|
|
|
76
|
-
//
|
|
76
|
+
// Mock apiFetch response.
|
|
77
77
|
apiFetch.setFetchHandler( async ( options ) => {
|
|
78
78
|
const method = getMethod( options );
|
|
79
79
|
const { path, data } = options;
|
|
@@ -91,39 +91,39 @@ describe( 'Post actions', () => {
|
|
|
91
91
|
};
|
|
92
92
|
} );
|
|
93
93
|
|
|
94
|
-
//
|
|
94
|
+
// Create registry.
|
|
95
95
|
const registry = createRegistryWithStores();
|
|
96
96
|
|
|
97
|
-
//
|
|
97
|
+
// Store post.
|
|
98
98
|
registry
|
|
99
99
|
.dispatch( coreStore )
|
|
100
100
|
.receiveEntityRecords( 'postType', 'post', post );
|
|
101
101
|
|
|
102
|
-
//
|
|
102
|
+
// Setup editor with post and initial edits.
|
|
103
103
|
registry.dispatch( editorStore ).setupEditor( post, {
|
|
104
104
|
content: 'new bar',
|
|
105
105
|
} );
|
|
106
106
|
|
|
107
|
-
//
|
|
107
|
+
// Check that the post is dirty.
|
|
108
108
|
expect( registry.select( editorStore ).isEditedPostDirty() ).toBe(
|
|
109
109
|
true
|
|
110
110
|
);
|
|
111
111
|
|
|
112
|
-
//
|
|
112
|
+
// Save the post.
|
|
113
113
|
await registry.dispatch( editorStore ).savePost();
|
|
114
114
|
|
|
115
|
-
//
|
|
115
|
+
// Check the new content.
|
|
116
116
|
const content = registry
|
|
117
117
|
.select( editorStore )
|
|
118
118
|
.getEditedPostContent();
|
|
119
119
|
expect( content ).toBe( 'new bar' );
|
|
120
120
|
|
|
121
|
-
//
|
|
121
|
+
// Check that the post is no longer dirty.
|
|
122
122
|
expect( registry.select( editorStore ).isEditedPostDirty() ).toBe(
|
|
123
123
|
false
|
|
124
124
|
);
|
|
125
125
|
|
|
126
|
-
//
|
|
126
|
+
// Check that a success notice has been shown.
|
|
127
127
|
const notices = registry.select( noticesStore ).getNotices();
|
|
128
128
|
expect( notices ).toMatchObject( [
|
|
129
129
|
{
|
|
@@ -145,7 +145,7 @@ describe( 'Post actions', () => {
|
|
|
145
145
|
status: 'draft',
|
|
146
146
|
};
|
|
147
147
|
|
|
148
|
-
//
|
|
148
|
+
// Mock apiFetch response.
|
|
149
149
|
apiFetch.setFetchHandler( async ( options ) => {
|
|
150
150
|
const method = getMethod( options );
|
|
151
151
|
const { path, data } = options;
|
|
@@ -171,42 +171,42 @@ describe( 'Post actions', () => {
|
|
|
171
171
|
};
|
|
172
172
|
} );
|
|
173
173
|
|
|
174
|
-
//
|
|
174
|
+
// Create registry.
|
|
175
175
|
const registry = createRegistryWithStores();
|
|
176
176
|
|
|
177
|
-
//
|
|
177
|
+
// Set current user.
|
|
178
178
|
registry.dispatch( coreStore ).receiveCurrentUser( { id: 1 } );
|
|
179
179
|
|
|
180
|
-
//
|
|
180
|
+
// Store post.
|
|
181
181
|
registry
|
|
182
182
|
.dispatch( coreStore )
|
|
183
183
|
.receiveEntityRecords( 'postType', 'post', post );
|
|
184
184
|
|
|
185
|
-
//
|
|
185
|
+
// Setup editor with post and initial edits.
|
|
186
186
|
registry.dispatch( editorStore ).setupEditor( post, {
|
|
187
187
|
content: 'new bar',
|
|
188
188
|
} );
|
|
189
189
|
|
|
190
|
-
//
|
|
190
|
+
// Check that the post is dirty.
|
|
191
191
|
expect( registry.select( editorStore ).isEditedPostDirty() ).toBe(
|
|
192
192
|
true
|
|
193
193
|
);
|
|
194
194
|
|
|
195
|
-
//
|
|
195
|
+
// Autosave the post.
|
|
196
196
|
await registry.dispatch( editorStore ).autosave();
|
|
197
197
|
|
|
198
|
-
//
|
|
198
|
+
// Check the new content.
|
|
199
199
|
const content = registry
|
|
200
200
|
.select( editorStore )
|
|
201
201
|
.getEditedPostContent();
|
|
202
202
|
expect( content ).toBe( 'new bar' );
|
|
203
203
|
|
|
204
|
-
//
|
|
204
|
+
// Check that the post is no longer dirty.
|
|
205
205
|
expect( registry.select( editorStore ).isEditedPostDirty() ).toBe(
|
|
206
206
|
false
|
|
207
207
|
);
|
|
208
208
|
|
|
209
|
-
//
|
|
209
|
+
// Check that no notice has been shown on autosave.
|
|
210
210
|
const notices = registry.select( noticesStore ).getNotices();
|
|
211
211
|
expect( notices ).toMatchObject( [] );
|
|
212
212
|
} );
|
|
@@ -223,7 +223,7 @@ describe( 'Post actions', () => {
|
|
|
223
223
|
|
|
224
224
|
let gotTrashed = false;
|
|
225
225
|
|
|
226
|
-
//
|
|
226
|
+
// Mock apiFetch response.
|
|
227
227
|
apiFetch.setFetchHandler( async ( options ) => {
|
|
228
228
|
const method = getMethod( options );
|
|
229
229
|
const { path, data } = options;
|
|
@@ -247,25 +247,25 @@ describe( 'Post actions', () => {
|
|
|
247
247
|
};
|
|
248
248
|
} );
|
|
249
249
|
|
|
250
|
-
//
|
|
250
|
+
// Create registry.
|
|
251
251
|
const registry = createRegistryWithStores();
|
|
252
252
|
|
|
253
|
-
//
|
|
253
|
+
// Store post.
|
|
254
254
|
registry
|
|
255
255
|
.dispatch( coreStore )
|
|
256
256
|
.receiveEntityRecords( 'postType', 'post', post );
|
|
257
257
|
|
|
258
|
-
//
|
|
258
|
+
// Setup editor with post.
|
|
259
259
|
registry.dispatch( editorStore ).setupEditor( post );
|
|
260
260
|
|
|
261
|
-
//
|
|
261
|
+
// Trash the post.
|
|
262
262
|
await registry.dispatch( editorStore ).trashPost();
|
|
263
263
|
|
|
264
|
-
//
|
|
264
|
+
// Check that there are no notices.
|
|
265
265
|
const notices = registry.select( noticesStore ).getNotices();
|
|
266
266
|
expect( notices ).toEqual( [] );
|
|
267
267
|
|
|
268
|
-
//
|
|
268
|
+
// Check the new status.
|
|
269
269
|
const { status } = registry.select( editorStore ).getCurrentPost();
|
|
270
270
|
expect( status ).toBe( 'trash' );
|
|
271
271
|
} );
|
|
@@ -275,7 +275,7 @@ describe( 'Post actions', () => {
|
|
|
275
275
|
describe( 'Editor actions', () => {
|
|
276
276
|
describe( 'setupEditor()', () => {
|
|
277
277
|
it( 'should setup the editor', () => {
|
|
278
|
-
//
|
|
278
|
+
// Create registry.
|
|
279
279
|
const registry = createRegistryWithStores();
|
|
280
280
|
|
|
281
281
|
registry
|
|
@@ -1913,7 +1913,7 @@ describe( 'selectors', () => {
|
|
|
1913
1913
|
|
|
1914
1914
|
describe( 'isEditedPostBeingScheduled', () => {
|
|
1915
1915
|
it( 'should return true for posts with a future date', () => {
|
|
1916
|
-
const time = Date.now() + 1000 * 3600 * 24 * 7; // 7 days in the future
|
|
1916
|
+
const time = Date.now() + 1000 * 3600 * 24 * 7; // 7 days in the future.
|
|
1917
1917
|
const date = new Date( time );
|
|
1918
1918
|
const state = {
|
|
1919
1919
|
editor: {
|