@wordpress/editor 12.8.0 → 12.11.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/editor-help/help-section-title.native.js +43 -0
- package/build/components/editor-help/help-section-title.native.js.map +1 -0
- package/build/components/editor-help/help-topic-row.native.js +3 -2
- package/build/components/editor-help/help-topic-row.native.js.map +1 -1
- package/build/components/editor-help/icon-move-blocks.native.js +23 -0
- package/build/components/editor-help/icon-move-blocks.native.js.map +1 -0
- package/build/components/editor-help/index.native.js +10 -11
- package/build/components/editor-help/index.native.js.map +1 -1
- package/build/components/editor-help/move-blocks.native.js +14 -2
- package/build/components/editor-help/move-blocks.native.js.map +1 -1
- package/build/components/editor-help/view-sections.native.js +21 -5
- package/build/components/editor-help/view-sections.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/index.js +12 -1
- package/build/components/index.js.map +1 -1
- package/build/components/local-autosave-monitor/index.js +24 -19
- package/build/components/local-autosave-monitor/index.js.map +1 -1
- package/build/components/page-attributes/parent.js +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 +5 -5
- 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-schedule/index.js +11 -18
- package/build/components/post-schedule/index.js.map +1 -1
- package/build/components/post-schedule/label.js +93 -13
- package/build/components/post-schedule/label.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 +7 -4
- 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 +10 -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 +0 -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 +5 -1
- package/build/store/actions.js.map +1 -1
- package/build/store/reducer.js +1 -1
- package/build/store/reducer.js.map +1 -1
- package/build/store/selectors.js +2 -2
- 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/help-section-title.native.js +31 -0
- package/build-module/components/editor-help/help-section-title.native.js.map +1 -0
- package/build-module/components/editor-help/help-topic-row.native.js +3 -2
- package/build-module/components/editor-help/help-topic-row.native.js.map +1 -1
- package/build-module/components/editor-help/icon-move-blocks.native.js +13 -0
- package/build-module/components/editor-help/icon-move-blocks.native.js.map +1 -0
- package/build-module/components/editor-help/index.native.js +10 -12
- package/build-module/components/editor-help/index.native.js.map +1 -1
- package/build-module/components/editor-help/move-blocks.native.js +15 -3
- package/build-module/components/editor-help/move-blocks.native.js.map +1 -1
- package/build-module/components/editor-help/view-sections.native.js +22 -6
- package/build-module/components/editor-help/view-sections.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/index.js +1 -1
- package/build-module/components/index.js.map +1 -1
- package/build-module/components/local-autosave-monitor/index.js +24 -18
- package/build-module/components/local-autosave-monitor/index.js.map +1 -1
- package/build-module/components/page-attributes/parent.js +2 -2
- 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 +5 -5
- 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-schedule/index.js +12 -19
- package/build-module/components/post-schedule/index.js.map +1 -1
- package/build-module/components/post-schedule/label.js +90 -13
- package/build-module/components/post-schedule/label.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 +7 -4
- 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 +12 -13
- 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 +0 -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 +5 -1
- package/build-module/store/actions.js.map +1 -1
- package/build-module/store/reducer.js +2 -2
- package/build-module/store/reducer.js.map +1 -1
- package/build-module/store/selectors.js +2 -2
- 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 +1 -17
- package/build-style/style.css +1 -17
- package/package.json +29 -29
- package/src/components/editor-help/help-section-title.native.js +29 -0
- package/src/components/editor-help/help-topic-row.native.js +2 -2
- package/src/components/editor-help/icon-move-blocks.native.js +10 -0
- package/src/components/editor-help/images/drag-and-drop-dark.png +0 -0
- package/src/components/editor-help/images/drag-and-drop-dark@2x.png +0 -0
- package/src/components/editor-help/images/drag-and-drop-dark@3x.png +0 -0
- package/src/components/editor-help/images/drag-and-drop-light.png +0 -0
- package/src/components/editor-help/images/drag-and-drop-light@2x.png +0 -0
- package/src/components/editor-help/images/drag-and-drop-light@3x.png +0 -0
- package/src/components/editor-help/index.native.js +26 -28
- package/src/components/editor-help/move-blocks.native.js +22 -2
- package/src/components/editor-help/style.scss +36 -4
- package/src/components/editor-help/view-sections.native.js +23 -8
- 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/index.js +4 -1
- package/src/components/local-autosave-monitor/index.js +39 -38
- package/src/components/page-attributes/parent.js +5 -8
- 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 +7 -5
- 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-publish-panel/test/__snapshots__/index.js.snap +1 -1
- package/src/components/post-schedule/index.js +6 -13
- package/src/components/post-schedule/label.js +111 -17
- package/src/components/post-schedule/test/label.js +127 -15
- 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 +9 -12
- 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-title/style.scss +1 -1
- package/src/components/post-trash/check.js +2 -3
- package/src/components/post-visibility/index.js +11 -17
- package/src/components/post-visibility/style.scss +0 -17
- package/src/components/provider/index.js +2 -3
- package/src/components/provider/index.native.js +12 -17
- 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 +213 -190
- package/src/store/reducer.js +2 -2
- package/src/store/selectors.js +16 -21
- package/src/store/test/selectors.js +13 -16
- package/src/utils/media-upload/index.js +2 -5
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,32 @@ 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
|
+
const { rest_base: restBase, rest_namespace: restNamespace = 'wp/v2' } =
|
|
254
|
+
postType;
|
|
255
|
+
try {
|
|
256
|
+
const post = select.getCurrentPost();
|
|
257
|
+
await apiFetch( {
|
|
258
|
+
path: `/${ restNamespace }/${ restBase }/${ post.id }`,
|
|
259
|
+
method: 'DELETE',
|
|
260
|
+
} );
|
|
261
|
+
|
|
262
|
+
await dispatch.savePost();
|
|
263
|
+
} catch ( error ) {
|
|
264
|
+
registry
|
|
265
|
+
.dispatch( noticesStore )
|
|
266
|
+
.createErrorNotice(
|
|
267
|
+
...getNotificationArgumentsForTrashFail( { error } )
|
|
268
|
+
);
|
|
269
|
+
}
|
|
270
|
+
};
|
|
257
271
|
|
|
258
272
|
/**
|
|
259
273
|
* Action that autosaves the current post. This
|
|
@@ -263,35 +277,38 @@ export const trashPost = () => async ( { select, dispatch, registry } ) => {
|
|
|
263
277
|
*
|
|
264
278
|
* @param {Object?} options Extra flags to identify the autosave.
|
|
265
279
|
*/
|
|
266
|
-
export const autosave =
|
|
267
|
-
|
|
268
|
-
dispatch
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
}
|
|
280
|
-
};
|
|
280
|
+
export const autosave =
|
|
281
|
+
( { local = false, ...options } = {} ) =>
|
|
282
|
+
async ( { select, dispatch } ) => {
|
|
283
|
+
if ( local ) {
|
|
284
|
+
const post = select.getCurrentPost();
|
|
285
|
+
const isPostNew = select.isEditedPostNew();
|
|
286
|
+
const title = select.getEditedPostAttribute( 'title' );
|
|
287
|
+
const content = select.getEditedPostAttribute( 'content' );
|
|
288
|
+
const excerpt = select.getEditedPostAttribute( 'excerpt' );
|
|
289
|
+
localAutosaveSet( post.id, isPostNew, title, content, excerpt );
|
|
290
|
+
} else {
|
|
291
|
+
await dispatch.savePost( { isAutosave: true, ...options } );
|
|
292
|
+
}
|
|
293
|
+
};
|
|
281
294
|
|
|
282
295
|
/**
|
|
283
296
|
* Action that restores last popped state in undo history.
|
|
284
297
|
*/
|
|
285
|
-
export const redo =
|
|
286
|
-
|
|
287
|
-
}
|
|
298
|
+
export const redo =
|
|
299
|
+
() =>
|
|
300
|
+
( { registry } ) => {
|
|
301
|
+
registry.dispatch( coreStore ).redo();
|
|
302
|
+
};
|
|
288
303
|
|
|
289
304
|
/**
|
|
290
305
|
* Action that pops a record from undo history and undoes the edit.
|
|
291
306
|
*/
|
|
292
|
-
export const undo =
|
|
293
|
-
|
|
294
|
-
}
|
|
307
|
+
export const undo =
|
|
308
|
+
() =>
|
|
309
|
+
( { registry } ) => {
|
|
310
|
+
registry.dispatch( coreStore ).undo();
|
|
311
|
+
};
|
|
295
312
|
|
|
296
313
|
/**
|
|
297
314
|
* Action that creates an undo history record.
|
|
@@ -323,20 +340,24 @@ export function updatePostLock( lock ) {
|
|
|
323
340
|
/**
|
|
324
341
|
* Enable the publish sidebar.
|
|
325
342
|
*/
|
|
326
|
-
export const enablePublishSidebar =
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
343
|
+
export const enablePublishSidebar =
|
|
344
|
+
() =>
|
|
345
|
+
( { registry } ) => {
|
|
346
|
+
registry
|
|
347
|
+
.dispatch( preferencesStore )
|
|
348
|
+
.set( 'core/edit-post', 'isPublishSidebarEnabled', true );
|
|
349
|
+
};
|
|
331
350
|
|
|
332
351
|
/**
|
|
333
352
|
* Disables the publish sidebar.
|
|
334
353
|
*/
|
|
335
|
-
export const disablePublishSidebar =
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
354
|
+
export const disablePublishSidebar =
|
|
355
|
+
() =>
|
|
356
|
+
( { registry } ) => {
|
|
357
|
+
registry
|
|
358
|
+
.dispatch( preferencesStore )
|
|
359
|
+
.set( 'core/edit-post', 'isPublishSidebarEnabled', false );
|
|
360
|
+
};
|
|
340
361
|
|
|
341
362
|
/**
|
|
342
363
|
* Action that locks post saving.
|
|
@@ -454,37 +475,35 @@ export function unlockPostAutosaving( lockName ) {
|
|
|
454
475
|
* @param {Array} blocks Block Array.
|
|
455
476
|
* @param {?Object} options Optional options.
|
|
456
477
|
*/
|
|
457
|
-
export const resetEditorBlocks =
|
|
458
|
-
|
|
459
|
-
dispatch,
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
.
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
478
|
+
export const resetEditorBlocks =
|
|
479
|
+
( blocks, options = {} ) =>
|
|
480
|
+
( { select, dispatch, registry } ) => {
|
|
481
|
+
const { __unstableShouldCreateUndoLevel, selection } = options;
|
|
482
|
+
const edits = { blocks, selection };
|
|
483
|
+
|
|
484
|
+
if ( __unstableShouldCreateUndoLevel !== false ) {
|
|
485
|
+
const { id, type } = select.getCurrentPost();
|
|
486
|
+
const noChange =
|
|
487
|
+
registry
|
|
488
|
+
.select( coreStore )
|
|
489
|
+
.getEditedEntityRecord( 'postType', type, id ).blocks ===
|
|
490
|
+
edits.blocks;
|
|
491
|
+
if ( noChange ) {
|
|
492
|
+
registry
|
|
493
|
+
.dispatch( coreStore )
|
|
494
|
+
.__unstableCreateUndoLevel( 'postType', type, id );
|
|
495
|
+
return;
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
// We create a new function here on every persistent edit
|
|
499
|
+
// to make sure the edit makes the post dirty and creates
|
|
500
|
+
// a new undo level.
|
|
501
|
+
edits.content = ( { blocks: blocksForSerialization = [] } ) =>
|
|
502
|
+
__unstableSerializeAndClean( blocksForSerialization );
|
|
477
503
|
}
|
|
478
504
|
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
// a new undo level.
|
|
482
|
-
edits.content = ( { blocks: blocksForSerialization = [] } ) =>
|
|
483
|
-
__unstableSerializeAndClean( blocksForSerialization );
|
|
484
|
-
}
|
|
485
|
-
|
|
486
|
-
dispatch.editPost( edits );
|
|
487
|
-
};
|
|
505
|
+
dispatch.editPost( edits );
|
|
506
|
+
};
|
|
488
507
|
|
|
489
508
|
/*
|
|
490
509
|
* Returns an action object used in signalling that the post editor settings have been updated.
|
|
@@ -504,14 +523,18 @@ export function updateEditorSettings( settings ) {
|
|
|
504
523
|
* Backward compatibility
|
|
505
524
|
*/
|
|
506
525
|
|
|
507
|
-
const getBlockEditorAction =
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
526
|
+
const getBlockEditorAction =
|
|
527
|
+
( name ) =>
|
|
528
|
+
( ...args ) =>
|
|
529
|
+
( { registry } ) => {
|
|
530
|
+
deprecated( "`wp.data.dispatch( 'core/editor' )." + name + '`', {
|
|
531
|
+
since: '5.3',
|
|
532
|
+
alternative:
|
|
533
|
+
"`wp.data.dispatch( 'core/block-editor' )." + name + '`',
|
|
534
|
+
version: '6.2',
|
|
535
|
+
} );
|
|
536
|
+
registry.dispatch( blockEditorStore )[ name ]( ...args );
|
|
537
|
+
};
|
|
515
538
|
|
|
516
539
|
/**
|
|
517
540
|
* @see resetBlocks in core/block-editor store.
|
package/src/store/reducer.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* External dependencies
|
|
3
3
|
*/
|
|
4
|
-
import { omit,
|
|
4
|
+
import { omit, isEqual } from 'lodash';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* WordPress dependencies
|
|
@@ -39,7 +39,7 @@ export function getPostRawValue( value ) {
|
|
|
39
39
|
* @return {boolean} Whether the two objects have the same keys.
|
|
40
40
|
*/
|
|
41
41
|
export function hasSameKeys( a, b ) {
|
|
42
|
-
return isEqual( keys( a ), keys( b ) );
|
|
42
|
+
return isEqual( Object.keys( a ), Object.keys( b ) );
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
/**
|
package/src/store/selectors.js
CHANGED
|
@@ -146,9 +146,8 @@ export const isEditedPostDirty = createRegistrySelector(
|
|
|
146
146
|
*/
|
|
147
147
|
export const hasNonPostEntityChanges = createRegistrySelector(
|
|
148
148
|
( select ) => ( state ) => {
|
|
149
|
-
const dirtyEntityRecords =
|
|
150
|
-
coreStore
|
|
151
|
-
).__experimentalGetDirtyEntityRecords();
|
|
149
|
+
const dirtyEntityRecords =
|
|
150
|
+
select( coreStore ).__experimentalGetDirtyEntityRecords();
|
|
152
151
|
const { type, id } = getCurrentPost( state );
|
|
153
152
|
return some(
|
|
154
153
|
dirtyEntityRecords,
|
|
@@ -708,9 +707,8 @@ export const isSavingPost = createRegistrySelector( ( select ) => ( state ) => {
|
|
|
708
707
|
*/
|
|
709
708
|
export const isSavingNonPostEntityChanges = createRegistrySelector(
|
|
710
709
|
( select ) => ( state ) => {
|
|
711
|
-
const entitiesBeingSaved =
|
|
712
|
-
coreStore
|
|
713
|
-
).__experimentalGetEntitiesBeingSaved();
|
|
710
|
+
const entitiesBeingSaved =
|
|
711
|
+
select( coreStore ).__experimentalGetEntitiesBeingSaved();
|
|
714
712
|
const { type, id } = getCurrentPost( state );
|
|
715
713
|
return some(
|
|
716
714
|
entitiesBeingSaved,
|
|
@@ -1244,9 +1242,8 @@ export const isBlockValid = getBlockEditorSelector( 'isBlockValid' );
|
|
|
1244
1242
|
/**
|
|
1245
1243
|
* @see getBlockAttributes in core/block-editor store.
|
|
1246
1244
|
*/
|
|
1247
|
-
export const getBlockAttributes =
|
|
1248
|
-
'getBlockAttributes'
|
|
1249
|
-
);
|
|
1245
|
+
export const getBlockAttributes =
|
|
1246
|
+
getBlockEditorSelector( 'getBlockAttributes' );
|
|
1250
1247
|
|
|
1251
1248
|
/**
|
|
1252
1249
|
* @see getBlock in core/block-editor store.
|
|
@@ -1476,9 +1473,8 @@ export const isMultiSelecting = getBlockEditorSelector( 'isMultiSelecting' );
|
|
|
1476
1473
|
/**
|
|
1477
1474
|
* @see isSelectionEnabled in core/block-editor store.
|
|
1478
1475
|
*/
|
|
1479
|
-
export const isSelectionEnabled =
|
|
1480
|
-
'isSelectionEnabled'
|
|
1481
|
-
);
|
|
1476
|
+
export const isSelectionEnabled =
|
|
1477
|
+
getBlockEditorSelector( 'isSelectionEnabled' );
|
|
1482
1478
|
|
|
1483
1479
|
/**
|
|
1484
1480
|
* @see getBlockMode in core/block-editor store.
|
|
@@ -1529,9 +1525,8 @@ export const getTemplateLock = getBlockEditorSelector( 'getTemplateLock' );
|
|
|
1529
1525
|
/**
|
|
1530
1526
|
* @see canInsertBlockType in core/block-editor store.
|
|
1531
1527
|
*/
|
|
1532
|
-
export const canInsertBlockType =
|
|
1533
|
-
'canInsertBlockType'
|
|
1534
|
-
);
|
|
1528
|
+
export const canInsertBlockType =
|
|
1529
|
+
getBlockEditorSelector( 'canInsertBlockType' );
|
|
1535
1530
|
|
|
1536
1531
|
/**
|
|
1537
1532
|
* @see getInserterItems in core/block-editor store.
|
|
@@ -1606,14 +1601,14 @@ export function __experimentalGetTemplateInfo( state, template ) {
|
|
|
1606
1601
|
return {};
|
|
1607
1602
|
}
|
|
1608
1603
|
|
|
1609
|
-
const {
|
|
1610
|
-
const {
|
|
1611
|
-
|
|
1612
|
-
description: defaultDescription,
|
|
1613
|
-
} = __experimentalGetDefaultTemplateType( state, slug );
|
|
1604
|
+
const { description, slug, title, area } = template;
|
|
1605
|
+
const { title: defaultTitle, description: defaultDescription } =
|
|
1606
|
+
__experimentalGetDefaultTemplateType( state, slug );
|
|
1614
1607
|
|
|
1615
1608
|
const templateTitle = isString( title ) ? title : title?.rendered;
|
|
1616
|
-
const templateDescription = isString(
|
|
1609
|
+
const templateDescription = isString( description )
|
|
1610
|
+
? description
|
|
1611
|
+
: description?.raw;
|
|
1617
1612
|
const templateIcon =
|
|
1618
1613
|
__experimentalGetDefaultTemplatePartAreas( state ).find(
|
|
1619
1614
|
( item ) => area === item.area
|
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* External dependencies
|
|
3
|
-
*/
|
|
4
|
-
import { filter, without } from 'lodash';
|
|
5
|
-
|
|
6
1
|
/**
|
|
7
2
|
* WordPress dependencies
|
|
8
3
|
*/
|
|
@@ -227,7 +222,9 @@ describe( 'selectors', () => {
|
|
|
227
222
|
let cachedSelectors;
|
|
228
223
|
|
|
229
224
|
beforeAll( () => {
|
|
230
|
-
cachedSelectors =
|
|
225
|
+
cachedSelectors = Object.entries( selectors )
|
|
226
|
+
.filter( ( [ , selector ] ) => selector.clear )
|
|
227
|
+
.map( ( [ , selector ] ) => selector );
|
|
231
228
|
} );
|
|
232
229
|
|
|
233
230
|
beforeEach( () => {
|
|
@@ -1598,10 +1595,11 @@ describe( 'selectors', () => {
|
|
|
1598
1595
|
} );
|
|
1599
1596
|
|
|
1600
1597
|
it( 'should return true if title or excerpt have changed', () => {
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1598
|
+
const fields = [ 'title', 'excerpt' ];
|
|
1599
|
+
|
|
1600
|
+
for ( const variantField of fields ) {
|
|
1601
|
+
for ( const constantField of fields.filter(
|
|
1602
|
+
( f ) => ! f === variantField
|
|
1605
1603
|
) ) {
|
|
1606
1604
|
const state = {
|
|
1607
1605
|
editor: {
|
|
@@ -2871,9 +2869,8 @@ describe( 'selectors', () => {
|
|
|
2871
2869
|
} );
|
|
2872
2870
|
|
|
2873
2871
|
it( 'assigns an icon to each area', () => {
|
|
2874
|
-
const templatePartAreas =
|
|
2875
|
-
state
|
|
2876
|
-
);
|
|
2872
|
+
const templatePartAreas =
|
|
2873
|
+
__experimentalGetDefaultTemplatePartAreas( state );
|
|
2877
2874
|
templatePartAreas.forEach( ( area ) =>
|
|
2878
2875
|
expect( area.icon ).not.toBeNull()
|
|
2879
2876
|
);
|
|
@@ -2968,7 +2965,7 @@ describe( 'selectors', () => {
|
|
|
2968
2965
|
expect(
|
|
2969
2966
|
__experimentalGetTemplateInfo( state, {
|
|
2970
2967
|
slug: 'index',
|
|
2971
|
-
|
|
2968
|
+
description: { raw: 'test description' },
|
|
2972
2969
|
} ).description
|
|
2973
2970
|
).toEqual( 'test description' );
|
|
2974
2971
|
} );
|
|
@@ -2996,7 +2993,7 @@ describe( 'selectors', () => {
|
|
|
2996
2993
|
expect(
|
|
2997
2994
|
__experimentalGetTemplateInfo( state, {
|
|
2998
2995
|
slug: 'index',
|
|
2999
|
-
|
|
2996
|
+
description: { raw: 'test description' },
|
|
3000
2997
|
} )
|
|
3001
2998
|
).toEqual( {
|
|
3002
2999
|
title: 'Default (Index)',
|
|
@@ -3008,7 +3005,7 @@ describe( 'selectors', () => {
|
|
|
3008
3005
|
__experimentalGetTemplateInfo( state, {
|
|
3009
3006
|
slug: 'index',
|
|
3010
3007
|
title: { rendered: 'test title' },
|
|
3011
|
-
|
|
3008
|
+
description: { raw: 'test description' },
|
|
3012
3009
|
} )
|
|
3013
3010
|
).toEqual( {
|
|
3014
3011
|
title: 'test title',
|
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* External dependencies
|
|
3
|
-
*/
|
|
4
|
-
import { noop } from 'lodash';
|
|
5
|
-
|
|
6
1
|
/**
|
|
7
2
|
* WordPress dependencies
|
|
8
3
|
*/
|
|
@@ -14,6 +9,8 @@ import { uploadMedia } from '@wordpress/media-utils';
|
|
|
14
9
|
*/
|
|
15
10
|
import { store as editorStore } from '../../store';
|
|
16
11
|
|
|
12
|
+
const noop = () => {};
|
|
13
|
+
|
|
17
14
|
/**
|
|
18
15
|
* Upload a media file when the file upload button is activated.
|
|
19
16
|
* Wrapper around mediaUpload() that injects the current post ID.
|