@wordpress/editor 12.9.0 → 12.10.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/build/components/editor-help/index.native.js.map +1 -1
- package/build/components/entities-saved-states/entity-record-item.js.map +1 -1
- package/build/components/entities-saved-states/index.js.map +1 -1
- package/build/components/global-keyboard-shortcuts/save-shortcut.js.map +1 -1
- package/build/components/local-autosave-monitor/index.js.map +1 -1
- package/build/components/page-attributes/parent.js.map +1 -1
- package/build/components/post-author/select.js.map +1 -1
- package/build/components/post-comments/index.js.map +1 -1
- package/build/components/post-format/index.js.map +1 -1
- package/build/components/post-last-revision/check.js.map +1 -1
- package/build/components/post-last-revision/index.js.map +1 -1
- package/build/components/post-pending-status/check.js.map +1 -1
- package/build/components/post-pingbacks/index.js.map +1 -1
- package/build/components/post-publish-button/index.js +4 -2
- package/build/components/post-publish-button/index.js.map +1 -1
- package/build/components/post-publish-panel/index.js.map +1 -1
- package/build/components/post-publish-panel/maybe-category-panel.js.map +1 -1
- package/build/components/post-publish-panel/maybe-post-format-panel.js.map +1 -1
- package/build/components/post-publish-panel/postpublish.js.map +1 -1
- package/build/components/post-publish-panel/prepublish.js.map +1 -1
- package/build/components/post-slug/index.js.map +1 -1
- package/build/components/post-sticky/index.js.map +1 -1
- package/build/components/post-switch-to-draft-button/index.js.map +1 -1
- package/build/components/post-taxonomies/flat-term-selector.js.map +1 -1
- package/build/components/post-taxonomies/hierarchical-term-selector.js.map +1 -1
- package/build/components/post-title/index.js.map +1 -1
- package/build/components/post-title/index.native.js.map +1 -1
- package/build/components/post-trash/check.js.map +1 -1
- package/build/components/post-visibility/index.js +8 -11
- package/build/components/post-visibility/index.js.map +1 -1
- package/build/components/provider/index.js.map +1 -1
- package/build/components/provider/index.native.js.map +1 -1
- package/build/components/provider/use-block-editor-settings.js +3 -1
- package/build/components/provider/use-block-editor-settings.js.map +1 -1
- package/build/components/template-validation-notice/index.js.map +1 -1
- package/build/components/theme-support-check/index.js +1 -1
- package/build/components/theme-support-check/index.js.map +1 -1
- package/build/hooks/custom-sources-backwards-compatibility.js.map +1 -1
- package/build/store/actions.js.map +1 -1
- package/build/store/selectors.js.map +1 -1
- package/build/utils/media-upload/index.js +4 -8
- package/build/utils/media-upload/index.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.map +1 -1
- package/build-module/components/entities-saved-states/index.js.map +1 -1
- package/build-module/components/global-keyboard-shortcuts/save-shortcut.js.map +1 -1
- package/build-module/components/local-autosave-monitor/index.js.map +1 -1
- package/build-module/components/page-attributes/parent.js.map +1 -1
- package/build-module/components/post-author/select.js.map +1 -1
- package/build-module/components/post-comments/index.js.map +1 -1
- package/build-module/components/post-format/index.js.map +1 -1
- package/build-module/components/post-last-revision/check.js.map +1 -1
- package/build-module/components/post-last-revision/index.js.map +1 -1
- package/build-module/components/post-pending-status/check.js.map +1 -1
- package/build-module/components/post-pingbacks/index.js.map +1 -1
- package/build-module/components/post-publish-button/index.js +4 -1
- package/build-module/components/post-publish-button/index.js.map +1 -1
- package/build-module/components/post-publish-panel/index.js.map +1 -1
- package/build-module/components/post-publish-panel/maybe-category-panel.js.map +1 -1
- package/build-module/components/post-publish-panel/maybe-post-format-panel.js.map +1 -1
- package/build-module/components/post-publish-panel/postpublish.js.map +1 -1
- package/build-module/components/post-publish-panel/prepublish.js.map +1 -1
- package/build-module/components/post-slug/index.js.map +1 -1
- package/build-module/components/post-sticky/index.js.map +1 -1
- package/build-module/components/post-switch-to-draft-button/index.js.map +1 -1
- package/build-module/components/post-taxonomies/flat-term-selector.js.map +1 -1
- package/build-module/components/post-taxonomies/hierarchical-term-selector.js.map +1 -1
- package/build-module/components/post-title/index.js.map +1 -1
- package/build-module/components/post-title/index.native.js.map +1 -1
- package/build-module/components/post-trash/check.js.map +1 -1
- package/build-module/components/post-visibility/index.js +9 -12
- package/build-module/components/post-visibility/index.js.map +1 -1
- package/build-module/components/provider/index.js.map +1 -1
- package/build-module/components/provider/index.native.js.map +1 -1
- package/build-module/components/provider/use-block-editor-settings.js +4 -2
- package/build-module/components/provider/use-block-editor-settings.js.map +1 -1
- package/build-module/components/template-validation-notice/index.js.map +1 -1
- package/build-module/components/theme-support-check/index.js +2 -2
- package/build-module/components/theme-support-check/index.js.map +1 -1
- package/build-module/hooks/custom-sources-backwards-compatibility.js.map +1 -1
- package/build-module/store/actions.js.map +1 -1
- package/build-module/store/selectors.js.map +1 -1
- package/build-module/utils/media-upload/index.js +3 -5
- package/build-module/utils/media-upload/index.js.map +1 -1
- package/build-style/style-rtl.css +0 -16
- package/build-style/style.css +0 -16
- package/package.json +28 -28
- package/src/components/editor-help/index.native.js +6 -6
- package/src/components/entities-saved-states/entity-record-item.js +6 -6
- package/src/components/entities-saved-states/index.js +6 -9
- package/src/components/global-keyboard-shortcuts/save-shortcut.js +2 -3
- package/src/components/local-autosave-monitor/index.js +15 -20
- package/src/components/page-attributes/parent.js +4 -6
- package/src/components/post-author/select.js +2 -3
- package/src/components/post-comments/index.js +4 -3
- package/src/components/post-format/index.js +2 -3
- package/src/components/post-last-revision/check.js +2 -4
- package/src/components/post-last-revision/index.js +2 -4
- package/src/components/post-pending-status/check.js +2 -5
- package/src/components/post-pingbacks/index.js +2 -3
- package/src/components/post-publish-button/index.js +7 -8
- package/src/components/post-publish-panel/index.js +2 -3
- package/src/components/post-publish-panel/maybe-category-panel.js +2 -3
- package/src/components/post-publish-panel/maybe-post-format-panel.js +2 -3
- package/src/components/post-publish-panel/postpublish.js +2 -5
- package/src/components/post-publish-panel/prepublish.js +2 -3
- package/src/components/post-slug/index.js +2 -3
- package/src/components/post-sticky/index.js +2 -3
- package/src/components/post-switch-to-draft-button/index.js +2 -5
- package/src/components/post-taxonomies/flat-term-selector.js +4 -8
- package/src/components/post-taxonomies/hierarchical-term-selector.js +4 -6
- package/src/components/post-title/index.js +21 -31
- package/src/components/post-title/index.native.js +10 -16
- package/src/components/post-trash/check.js +2 -3
- package/src/components/post-visibility/index.js +9 -15
- package/src/components/post-visibility/style.scss +0 -17
- package/src/components/provider/index.js +2 -3
- package/src/components/provider/index.native.js +11 -10
- package/src/components/provider/use-block-editor-settings.js +4 -8
- package/src/components/template-validation-notice/index.js +2 -3
- package/src/components/theme-support-check/index.js +2 -2
- package/src/hooks/custom-sources-backwards-compatibility.js +45 -44
- package/src/store/actions.js +211 -190
- package/src/store/selectors.js +12 -19
- package/src/store/test/selectors.js +2 -3
- package/src/utils/media-upload/index.js +2 -5
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* External dependencies
|
|
3
3
|
*/
|
|
4
|
-
import { pick,
|
|
4
|
+
import { pick, unionBy } from 'lodash';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* WordPress dependencies
|
|
@@ -52,10 +52,7 @@ function useBlockEditorSettings( settings, hasTemplate ) {
|
|
|
52
52
|
{ per_page: -1 }
|
|
53
53
|
)
|
|
54
54
|
: [], // Reusable blocks are fetched in the native version of this hook.
|
|
55
|
-
hasUploadPermissions:
|
|
56
|
-
canUser( 'create', 'media' ),
|
|
57
|
-
true
|
|
58
|
-
),
|
|
55
|
+
hasUploadPermissions: canUser( 'create', 'media' ) ?? true,
|
|
59
56
|
userCanCreatePages: canUser( 'create', 'pages' ),
|
|
60
57
|
pageOnFront: siteSettings?.page_on_front,
|
|
61
58
|
};
|
|
@@ -71,9 +68,8 @@ function useBlockEditorSettings( settings, hasTemplate ) {
|
|
|
71
68
|
const { restBlockPatterns, restBlockPatternCategories } = useSelect(
|
|
72
69
|
( select ) => ( {
|
|
73
70
|
restBlockPatterns: select( coreStore ).getBlockPatterns(),
|
|
74
|
-
restBlockPatternCategories:
|
|
75
|
-
coreStore
|
|
76
|
-
).getBlockPatternCategories(),
|
|
71
|
+
restBlockPatternCategories:
|
|
72
|
+
select( coreStore ).getBlockPatternCategories(),
|
|
77
73
|
} ),
|
|
78
74
|
[]
|
|
79
75
|
);
|
|
@@ -53,9 +53,8 @@ export default compose( [
|
|
|
53
53
|
isValid: select( blockEditorStore ).isValidTemplate(),
|
|
54
54
|
} ) ),
|
|
55
55
|
withDispatch( ( dispatch ) => {
|
|
56
|
-
const { setTemplateValidity, synchronizeTemplate } =
|
|
57
|
-
blockEditorStore
|
|
58
|
-
);
|
|
56
|
+
const { setTemplateValidity, synchronizeTemplate } =
|
|
57
|
+
dispatch( blockEditorStore );
|
|
59
58
|
return {
|
|
60
59
|
resetTemplateValidity: () => setTemplateValidity( true ),
|
|
61
60
|
synchronizeTemplate,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* External dependencies
|
|
3
3
|
*/
|
|
4
|
-
import { castArray, includes,
|
|
4
|
+
import { castArray, includes, get, some } from 'lodash';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* WordPress dependencies
|
|
@@ -26,7 +26,7 @@ export function ThemeSupportCheck( {
|
|
|
26
26
|
// In the latter case, we need to verify `postType` exists
|
|
27
27
|
// within `supported`. If `postType` isn't passed, then the check
|
|
28
28
|
// should fail.
|
|
29
|
-
if ( 'post-thumbnails' === key && isArray( supported ) ) {
|
|
29
|
+
if ( 'post-thumbnails' === key && Array.isArray( supported ) ) {
|
|
30
30
|
return includes( supported, postType );
|
|
31
31
|
}
|
|
32
32
|
return supported;
|
|
@@ -42,55 +42,56 @@ import { store as editorStore } from '../store';
|
|
|
42
42
|
*/
|
|
43
43
|
const createWithMetaAttributeSource = ( metaAttributes ) =>
|
|
44
44
|
createHigherOrderComponent(
|
|
45
|
-
( BlockEdit ) =>
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
45
|
+
( BlockEdit ) =>
|
|
46
|
+
( { attributes, setAttributes, ...props } ) => {
|
|
47
|
+
const postType = useSelect(
|
|
48
|
+
( select ) => select( editorStore ).getCurrentPostType(),
|
|
49
|
+
[]
|
|
50
|
+
);
|
|
51
|
+
const [ meta, setMeta ] = useEntityProp(
|
|
52
|
+
'postType',
|
|
53
|
+
postType,
|
|
54
|
+
'meta'
|
|
55
|
+
);
|
|
55
56
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
57
|
+
const mergedAttributes = useMemo(
|
|
58
|
+
() => ( {
|
|
59
|
+
...attributes,
|
|
60
|
+
...mapValues(
|
|
61
|
+
metaAttributes,
|
|
62
|
+
( metaKey ) => meta[ metaKey ]
|
|
63
|
+
),
|
|
64
|
+
} ),
|
|
65
|
+
[ attributes, meta ]
|
|
66
|
+
);
|
|
66
67
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
68
|
+
return (
|
|
69
|
+
<BlockEdit
|
|
70
|
+
attributes={ mergedAttributes }
|
|
71
|
+
setAttributes={ ( nextAttributes ) => {
|
|
72
|
+
const nextMeta = mapKeys(
|
|
73
|
+
// Filter to intersection of keys between the updated
|
|
74
|
+
// attributes and those with an associated meta key.
|
|
75
|
+
pickBy(
|
|
76
|
+
nextAttributes,
|
|
77
|
+
( value, key ) => metaAttributes[ key ]
|
|
78
|
+
),
|
|
78
79
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
80
|
+
// Rename the keys to the expected meta key name.
|
|
81
|
+
( value, attributeKey ) =>
|
|
82
|
+
metaAttributes[ attributeKey ]
|
|
83
|
+
);
|
|
83
84
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
85
|
+
if ( ! isEmpty( nextMeta ) ) {
|
|
86
|
+
setMeta( nextMeta );
|
|
87
|
+
}
|
|
87
88
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
89
|
+
setAttributes( nextAttributes );
|
|
90
|
+
} }
|
|
91
|
+
{ ...props }
|
|
92
|
+
/>
|
|
93
|
+
);
|
|
94
|
+
},
|
|
94
95
|
'withMetaAttributeSource'
|
|
95
96
|
);
|
|
96
97
|
|
package/src/store/actions.js
CHANGED
|
@@ -37,35 +37,38 @@ import {
|
|
|
37
37
|
* @param {Object} edits Initial edited attributes object.
|
|
38
38
|
* @param {Array?} template Block Template.
|
|
39
39
|
*/
|
|
40
|
-
export const setupEditor =
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
40
|
+
export const setupEditor =
|
|
41
|
+
( post, edits, template ) =>
|
|
42
|
+
( { dispatch } ) => {
|
|
43
|
+
dispatch.setupEditorState( post );
|
|
44
|
+
// Apply a template for new posts only, if exists.
|
|
45
|
+
const isNewPost = post.status === 'auto-draft';
|
|
46
|
+
if ( isNewPost && template ) {
|
|
47
|
+
// In order to ensure maximum of a single parse during setup, edits are
|
|
48
|
+
// included as part of editor setup action. Assume edited content as
|
|
49
|
+
// canonical if provided, falling back to post.
|
|
50
|
+
let content;
|
|
51
|
+
if ( has( edits, [ 'content' ] ) ) {
|
|
52
|
+
content = edits.content;
|
|
53
|
+
} else {
|
|
54
|
+
content = post.content.raw;
|
|
55
|
+
}
|
|
56
|
+
let blocks = parse( content );
|
|
57
|
+
blocks = synchronizeBlocksWithTemplate( blocks, template );
|
|
58
|
+
dispatch.resetEditorBlocks( blocks, {
|
|
59
|
+
__unstableShouldCreateUndoLevel: false,
|
|
60
|
+
} );
|
|
53
61
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
)
|
|
65
|
-
) {
|
|
66
|
-
dispatch.editPost( edits );
|
|
67
|
-
}
|
|
68
|
-
};
|
|
62
|
+
if (
|
|
63
|
+
edits &&
|
|
64
|
+
Object.values( edits ).some(
|
|
65
|
+
( [ key, edit ] ) =>
|
|
66
|
+
edit !== ( post[ key ]?.raw ?? post[ key ] )
|
|
67
|
+
)
|
|
68
|
+
) {
|
|
69
|
+
dispatch.editPost( edits );
|
|
70
|
+
}
|
|
71
|
+
};
|
|
69
72
|
|
|
70
73
|
/**
|
|
71
74
|
* Returns an action object signalling that the editor is being destroyed and
|
|
@@ -131,89 +134,96 @@ export function setupEditorState( post ) {
|
|
|
131
134
|
* @param {Object} edits Post attributes to edit.
|
|
132
135
|
* @param {Object} options Options for the edit.
|
|
133
136
|
*/
|
|
134
|
-
export const editPost =
|
|
135
|
-
|
|
136
|
-
registry
|
|
137
|
-
.
|
|
138
|
-
|
|
139
|
-
|
|
137
|
+
export const editPost =
|
|
138
|
+
( edits, options ) =>
|
|
139
|
+
( { select, registry } ) => {
|
|
140
|
+
const { id, type } = select.getCurrentPost();
|
|
141
|
+
registry
|
|
142
|
+
.dispatch( coreStore )
|
|
143
|
+
.editEntityRecord( 'postType', type, id, edits, options );
|
|
144
|
+
};
|
|
140
145
|
|
|
141
146
|
/**
|
|
142
147
|
* Action for saving the current post in the editor.
|
|
143
148
|
*
|
|
144
149
|
* @param {Object} options
|
|
145
150
|
*/
|
|
146
|
-
export const savePost =
|
|
147
|
-
|
|
148
|
-
dispatch,
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
151
|
+
export const savePost =
|
|
152
|
+
( options = {} ) =>
|
|
153
|
+
async ( { select, dispatch, registry } ) => {
|
|
154
|
+
if ( ! select.isEditedPostSaveable() ) {
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
const content = select.getEditedPostContent();
|
|
159
|
+
|
|
160
|
+
if ( ! options.isAutosave ) {
|
|
161
|
+
dispatch.editPost( { content }, { undoIgnore: true } );
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
const previousRecord = select.getCurrentPost();
|
|
165
|
+
const edits = {
|
|
166
|
+
id: previousRecord.id,
|
|
167
|
+
...registry
|
|
168
|
+
.select( coreStore )
|
|
169
|
+
.getEntityRecordNonTransientEdits(
|
|
170
|
+
'postType',
|
|
171
|
+
previousRecord.type,
|
|
172
|
+
previousRecord.id
|
|
173
|
+
),
|
|
174
|
+
content,
|
|
175
|
+
};
|
|
176
|
+
dispatch( { type: 'REQUEST_POST_UPDATE_START', options } );
|
|
177
|
+
await registry
|
|
178
|
+
.dispatch( coreStore )
|
|
179
|
+
.saveEntityRecord(
|
|
180
|
+
'postType',
|
|
181
|
+
previousRecord.type,
|
|
182
|
+
edits,
|
|
183
|
+
options
|
|
184
|
+
);
|
|
185
|
+
dispatch( { type: 'REQUEST_POST_UPDATE_FINISH', options } );
|
|
186
|
+
|
|
187
|
+
const error = registry
|
|
165
188
|
.select( coreStore )
|
|
166
|
-
.
|
|
189
|
+
.getLastEntitySaveError(
|
|
167
190
|
'postType',
|
|
168
191
|
previousRecord.type,
|
|
169
192
|
previousRecord.id
|
|
170
|
-
)
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
.getPostType( updatedRecord.type ),
|
|
203
|
-
options,
|
|
204
|
-
} );
|
|
205
|
-
if ( args.length ) {
|
|
206
|
-
registry.dispatch( noticesStore ).createSuccessNotice( ...args );
|
|
207
|
-
}
|
|
208
|
-
// Make sure that any edits after saving create an undo level and are
|
|
209
|
-
// considered for change detection.
|
|
210
|
-
if ( ! options.isAutosave ) {
|
|
211
|
-
registry
|
|
212
|
-
.dispatch( blockEditorStore )
|
|
213
|
-
.__unstableMarkLastChangeAsPersistent();
|
|
193
|
+
);
|
|
194
|
+
if ( error ) {
|
|
195
|
+
const args = getNotificationArgumentsForSaveFail( {
|
|
196
|
+
post: previousRecord,
|
|
197
|
+
edits,
|
|
198
|
+
error,
|
|
199
|
+
} );
|
|
200
|
+
if ( args.length ) {
|
|
201
|
+
registry.dispatch( noticesStore ).createErrorNotice( ...args );
|
|
202
|
+
}
|
|
203
|
+
} else {
|
|
204
|
+
const updatedRecord = select.getCurrentPost();
|
|
205
|
+
const args = getNotificationArgumentsForSaveSuccess( {
|
|
206
|
+
previousPost: previousRecord,
|
|
207
|
+
post: updatedRecord,
|
|
208
|
+
postType: await registry
|
|
209
|
+
.resolveSelect( coreStore )
|
|
210
|
+
.getPostType( updatedRecord.type ),
|
|
211
|
+
options,
|
|
212
|
+
} );
|
|
213
|
+
if ( args.length ) {
|
|
214
|
+
registry
|
|
215
|
+
.dispatch( noticesStore )
|
|
216
|
+
.createSuccessNotice( ...args );
|
|
217
|
+
}
|
|
218
|
+
// Make sure that any edits after saving create an undo level and are
|
|
219
|
+
// considered for change detection.
|
|
220
|
+
if ( ! options.isAutosave ) {
|
|
221
|
+
registry
|
|
222
|
+
.dispatch( blockEditorStore )
|
|
223
|
+
.__unstableMarkLastChangeAsPersistent();
|
|
224
|
+
}
|
|
214
225
|
}
|
|
215
|
-
}
|
|
216
|
-
};
|
|
226
|
+
};
|
|
217
227
|
|
|
218
228
|
/**
|
|
219
229
|
* Action for refreshing the current post.
|
|
@@ -232,28 +242,30 @@ export function refreshPost() {
|
|
|
232
242
|
/**
|
|
233
243
|
* Action for trashing the current post in the editor.
|
|
234
244
|
*/
|
|
235
|
-
export const trashPost =
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
.
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
245
|
+
export const trashPost =
|
|
246
|
+
() =>
|
|
247
|
+
async ( { select, dispatch, registry } ) => {
|
|
248
|
+
const postTypeSlug = select.getCurrentPostType();
|
|
249
|
+
const postType = await registry
|
|
250
|
+
.resolveSelect( coreStore )
|
|
251
|
+
.getPostType( postTypeSlug );
|
|
252
|
+
registry.dispatch( noticesStore ).removeNotice( TRASH_POST_NOTICE_ID );
|
|
253
|
+
try {
|
|
254
|
+
const post = select.getCurrentPost();
|
|
255
|
+
await apiFetch( {
|
|
256
|
+
path: `/wp/v2/${ postType.rest_base }/${ post.id }`,
|
|
257
|
+
method: 'DELETE',
|
|
258
|
+
} );
|
|
259
|
+
|
|
260
|
+
await dispatch.savePost();
|
|
261
|
+
} catch ( error ) {
|
|
262
|
+
registry
|
|
263
|
+
.dispatch( noticesStore )
|
|
264
|
+
.createErrorNotice(
|
|
265
|
+
...getNotificationArgumentsForTrashFail( { error } )
|
|
266
|
+
);
|
|
267
|
+
}
|
|
268
|
+
};
|
|
257
269
|
|
|
258
270
|
/**
|
|
259
271
|
* Action that autosaves the current post. This
|
|
@@ -263,35 +275,38 @@ export const trashPost = () => async ( { select, dispatch, registry } ) => {
|
|
|
263
275
|
*
|
|
264
276
|
* @param {Object?} options Extra flags to identify the autosave.
|
|
265
277
|
*/
|
|
266
|
-
export const autosave =
|
|
267
|
-
|
|
268
|
-
dispatch
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
}
|
|
280
|
-
};
|
|
278
|
+
export const autosave =
|
|
279
|
+
( { local = false, ...options } = {} ) =>
|
|
280
|
+
async ( { select, dispatch } ) => {
|
|
281
|
+
if ( local ) {
|
|
282
|
+
const post = select.getCurrentPost();
|
|
283
|
+
const isPostNew = select.isEditedPostNew();
|
|
284
|
+
const title = select.getEditedPostAttribute( 'title' );
|
|
285
|
+
const content = select.getEditedPostAttribute( 'content' );
|
|
286
|
+
const excerpt = select.getEditedPostAttribute( 'excerpt' );
|
|
287
|
+
localAutosaveSet( post.id, isPostNew, title, content, excerpt );
|
|
288
|
+
} else {
|
|
289
|
+
await dispatch.savePost( { isAutosave: true, ...options } );
|
|
290
|
+
}
|
|
291
|
+
};
|
|
281
292
|
|
|
282
293
|
/**
|
|
283
294
|
* Action that restores last popped state in undo history.
|
|
284
295
|
*/
|
|
285
|
-
export const redo =
|
|
286
|
-
|
|
287
|
-
}
|
|
296
|
+
export const redo =
|
|
297
|
+
() =>
|
|
298
|
+
( { registry } ) => {
|
|
299
|
+
registry.dispatch( coreStore ).redo();
|
|
300
|
+
};
|
|
288
301
|
|
|
289
302
|
/**
|
|
290
303
|
* Action that pops a record from undo history and undoes the edit.
|
|
291
304
|
*/
|
|
292
|
-
export const undo =
|
|
293
|
-
|
|
294
|
-
}
|
|
305
|
+
export const undo =
|
|
306
|
+
() =>
|
|
307
|
+
( { registry } ) => {
|
|
308
|
+
registry.dispatch( coreStore ).undo();
|
|
309
|
+
};
|
|
295
310
|
|
|
296
311
|
/**
|
|
297
312
|
* Action that creates an undo history record.
|
|
@@ -323,20 +338,24 @@ export function updatePostLock( lock ) {
|
|
|
323
338
|
/**
|
|
324
339
|
* Enable the publish sidebar.
|
|
325
340
|
*/
|
|
326
|
-
export const enablePublishSidebar =
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
341
|
+
export const enablePublishSidebar =
|
|
342
|
+
() =>
|
|
343
|
+
( { registry } ) => {
|
|
344
|
+
registry
|
|
345
|
+
.dispatch( preferencesStore )
|
|
346
|
+
.set( 'core/edit-post', 'isPublishSidebarEnabled', true );
|
|
347
|
+
};
|
|
331
348
|
|
|
332
349
|
/**
|
|
333
350
|
* Disables the publish sidebar.
|
|
334
351
|
*/
|
|
335
|
-
export const disablePublishSidebar =
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
352
|
+
export const disablePublishSidebar =
|
|
353
|
+
() =>
|
|
354
|
+
( { registry } ) => {
|
|
355
|
+
registry
|
|
356
|
+
.dispatch( preferencesStore )
|
|
357
|
+
.set( 'core/edit-post', 'isPublishSidebarEnabled', false );
|
|
358
|
+
};
|
|
340
359
|
|
|
341
360
|
/**
|
|
342
361
|
* Action that locks post saving.
|
|
@@ -454,37 +473,35 @@ export function unlockPostAutosaving( lockName ) {
|
|
|
454
473
|
* @param {Array} blocks Block Array.
|
|
455
474
|
* @param {?Object} options Optional options.
|
|
456
475
|
*/
|
|
457
|
-
export const resetEditorBlocks =
|
|
458
|
-
|
|
459
|
-
dispatch,
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
.
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
476
|
+
export const resetEditorBlocks =
|
|
477
|
+
( blocks, options = {} ) =>
|
|
478
|
+
( { select, dispatch, registry } ) => {
|
|
479
|
+
const { __unstableShouldCreateUndoLevel, selection } = options;
|
|
480
|
+
const edits = { blocks, selection };
|
|
481
|
+
|
|
482
|
+
if ( __unstableShouldCreateUndoLevel !== false ) {
|
|
483
|
+
const { id, type } = select.getCurrentPost();
|
|
484
|
+
const noChange =
|
|
485
|
+
registry
|
|
486
|
+
.select( coreStore )
|
|
487
|
+
.getEditedEntityRecord( 'postType', type, id ).blocks ===
|
|
488
|
+
edits.blocks;
|
|
489
|
+
if ( noChange ) {
|
|
490
|
+
registry
|
|
491
|
+
.dispatch( coreStore )
|
|
492
|
+
.__unstableCreateUndoLevel( 'postType', type, id );
|
|
493
|
+
return;
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
// We create a new function here on every persistent edit
|
|
497
|
+
// to make sure the edit makes the post dirty and creates
|
|
498
|
+
// a new undo level.
|
|
499
|
+
edits.content = ( { blocks: blocksForSerialization = [] } ) =>
|
|
500
|
+
__unstableSerializeAndClean( blocksForSerialization );
|
|
477
501
|
}
|
|
478
502
|
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
// a new undo level.
|
|
482
|
-
edits.content = ( { blocks: blocksForSerialization = [] } ) =>
|
|
483
|
-
__unstableSerializeAndClean( blocksForSerialization );
|
|
484
|
-
}
|
|
485
|
-
|
|
486
|
-
dispatch.editPost( edits );
|
|
487
|
-
};
|
|
503
|
+
dispatch.editPost( edits );
|
|
504
|
+
};
|
|
488
505
|
|
|
489
506
|
/*
|
|
490
507
|
* Returns an action object used in signalling that the post editor settings have been updated.
|
|
@@ -504,14 +521,18 @@ export function updateEditorSettings( settings ) {
|
|
|
504
521
|
* Backward compatibility
|
|
505
522
|
*/
|
|
506
523
|
|
|
507
|
-
const getBlockEditorAction =
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
524
|
+
const getBlockEditorAction =
|
|
525
|
+
( name ) =>
|
|
526
|
+
( ...args ) =>
|
|
527
|
+
( { registry } ) => {
|
|
528
|
+
deprecated( "`wp.data.dispatch( 'core/editor' )." + name + '`', {
|
|
529
|
+
since: '5.3',
|
|
530
|
+
alternative:
|
|
531
|
+
"`wp.data.dispatch( 'core/block-editor' )." + name + '`',
|
|
532
|
+
version: '6.2',
|
|
533
|
+
} );
|
|
534
|
+
registry.dispatch( blockEditorStore )[ name ]( ...args );
|
|
535
|
+
};
|
|
515
536
|
|
|
516
537
|
/**
|
|
517
538
|
* @see resetBlocks in core/block-editor store.
|