@wordpress/editor 12.2.0 → 12.2.2
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/build/components/editor-help/index.native.js +3 -3
- package/build/components/editor-help/index.native.js.map +1 -1
- package/build/components/local-autosave-monitor/index.js +5 -5
- package/build/components/local-autosave-monitor/index.js.map +1 -1
- package/build/components/post-saved-state/index.js +1 -1
- package/build/components/post-saved-state/index.js.map +1 -1
- package/build/components/post-switch-to-draft-button/index.js +19 -14
- package/build/components/post-switch-to-draft-button/index.js.map +1 -1
- package/build/components/post-trash/index.js +15 -29
- package/build/components/post-trash/index.js.map +1 -1
- package/build/components/provider/index.native.js +17 -8
- package/build/components/provider/index.native.js.map +1 -1
- package/build/components/provider/use-block-editor-settings.js +3 -2
- package/build/components/provider/use-block-editor-settings.js.map +1 -1
- package/build/store/actions.js +231 -225
- package/build/store/actions.js.map +1 -1
- package/build/store/actions.native.js +6 -4
- package/build/store/actions.native.js.map +1 -1
- package/build/store/index.js +1 -8
- package/build/store/index.js.map +1 -1
- package/build/store/{controls.js → local-autosave.js} +1 -18
- package/build/store/local-autosave.js.map +1 -0
- package/build/store/reducer.js +0 -2
- package/build/store/reducer.js.map +1 -1
- package/build/store/utils/notice-builder.js +5 -0
- package/build/store/utils/notice-builder.js.map +1 -1
- package/build-module/components/editor-help/index.native.js +4 -4
- package/build-module/components/editor-help/index.native.js.map +1 -1
- package/build-module/components/local-autosave-monitor/index.js +1 -1
- package/build-module/components/local-autosave-monitor/index.js.map +1 -1
- package/build-module/components/post-saved-state/index.js +1 -1
- package/build-module/components/post-saved-state/index.js.map +1 -1
- package/build-module/components/post-switch-to-draft-button/index.js +22 -16
- package/build-module/components/post-switch-to-draft-button/index.js.map +1 -1
- package/build-module/components/post-trash/index.js +15 -27
- package/build-module/components/post-trash/index.js.map +1 -1
- package/build-module/components/provider/index.native.js +19 -10
- package/build-module/components/provider/index.native.js.map +1 -1
- package/build-module/components/provider/use-block-editor-settings.js +3 -2
- package/build-module/components/provider/use-block-editor-settings.js.map +1 -1
- package/build-module/store/actions.js +208 -207
- package/build-module/store/actions.js.map +1 -1
- package/build-module/store/actions.native.js +3 -3
- package/build-module/store/actions.native.js.map +1 -1
- package/build-module/store/index.js +1 -6
- package/build-module/store/index.js.map +1 -1
- package/build-module/store/{controls.js → local-autosave.js} +1 -15
- package/build-module/store/local-autosave.js.map +1 -0
- package/build-module/store/reducer.js +0 -2
- package/build-module/store/reducer.js.map +1 -1
- package/build-module/store/utils/notice-builder.js +5 -0
- package/build-module/store/utils/notice-builder.js.map +1 -1
- package/package.json +14 -15
- package/src/components/editor-help/index.native.js +6 -6
- package/src/components/local-autosave-monitor/index.js +4 -1
- package/src/components/post-saved-state/index.js +1 -1
- package/src/components/post-switch-to-draft-button/index.js +35 -24
- package/src/components/post-trash/index.js +12 -24
- package/src/components/provider/index.native.js +20 -16
- package/src/components/provider/use-block-editor-settings.js +2 -0
- package/src/store/actions.js +137 -249
- package/src/store/actions.native.js +3 -3
- package/src/store/index.js +0 -6
- package/src/store/{controls.js → local-autosave.js} +0 -8
- package/src/store/reducer.js +0 -2
- package/src/store/test/actions.js +244 -416
- package/src/store/utils/notice-builder.js +5 -0
- package/src/store/utils/test/notice-builder.js +1 -0
- package/build/store/controls.js.map +0 -1
- package/build-module/store/controls.js.map +0 -1
|
@@ -6,9 +6,8 @@ import { has } from 'lodash';
|
|
|
6
6
|
* WordPress dependencies
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
+
import apiFetch from '@wordpress/api-fetch';
|
|
9
10
|
import deprecated from '@wordpress/deprecated';
|
|
10
|
-
import { controls } from '@wordpress/data';
|
|
11
|
-
import { apiFetch } from '@wordpress/data-controls';
|
|
12
11
|
import { parse, synchronizeBlocksWithTemplate, __unstableSerializeAndClean } from '@wordpress/blocks';
|
|
13
12
|
import { store as noticesStore } from '@wordpress/notices';
|
|
14
13
|
import { store as coreStore } from '@wordpress/core-data';
|
|
@@ -17,7 +16,8 @@ import { store as blockEditorStore } from '@wordpress/block-editor';
|
|
|
17
16
|
* Internal dependencies
|
|
18
17
|
*/
|
|
19
18
|
|
|
20
|
-
import {
|
|
19
|
+
import { TRASH_POST_NOTICE_ID } from './constants';
|
|
20
|
+
import { localAutosaveSet } from './local-autosave';
|
|
21
21
|
import { getNotificationArgumentsForSaveSuccess, getNotificationArgumentsForSaveFail, getNotificationArgumentsForTrashFail } from './utils/notice-builder';
|
|
22
22
|
/**
|
|
23
23
|
* Returns an action generator used in signalling that editor has initialized with
|
|
@@ -28,15 +28,11 @@ import { getNotificationArgumentsForSaveSuccess, getNotificationArgumentsForSave
|
|
|
28
28
|
* @param {Array?} template Block Template.
|
|
29
29
|
*/
|
|
30
30
|
|
|
31
|
-
export
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
edits,
|
|
37
|
-
template
|
|
38
|
-
};
|
|
39
|
-
yield setupEditorState(post); // Apply a template for new posts only, if exists.
|
|
31
|
+
export const setupEditor = (post, edits, template) => _ref => {
|
|
32
|
+
let {
|
|
33
|
+
dispatch
|
|
34
|
+
} = _ref;
|
|
35
|
+
dispatch.setupEditorState(post); // Apply a template for new posts only, if exists.
|
|
40
36
|
|
|
41
37
|
const isNewPost = post.status === 'auto-draft';
|
|
42
38
|
|
|
@@ -54,15 +50,20 @@ export function* setupEditor(post, edits, template) {
|
|
|
54
50
|
|
|
55
51
|
let blocks = parse(content);
|
|
56
52
|
blocks = synchronizeBlocksWithTemplate(blocks, template);
|
|
57
|
-
|
|
53
|
+
dispatch.resetEditorBlocks(blocks, {
|
|
58
54
|
__unstableShouldCreateUndoLevel: false
|
|
59
55
|
});
|
|
60
56
|
}
|
|
61
57
|
|
|
62
|
-
if (edits && Object.
|
|
63
|
-
|
|
58
|
+
if (edits && Object.values(edits).some(_ref2 => {
|
|
59
|
+
var _post$key$raw, _post$key;
|
|
60
|
+
|
|
61
|
+
let [key, edit] = _ref2;
|
|
62
|
+
return edit !== ((_post$key$raw = (_post$key = post[key]) === null || _post$key === void 0 ? void 0 : _post$key.raw) !== null && _post$key$raw !== void 0 ? _post$key$raw : post[key]);
|
|
63
|
+
})) {
|
|
64
|
+
dispatch.editPost(edits);
|
|
64
65
|
}
|
|
65
|
-
}
|
|
66
|
+
};
|
|
66
67
|
/**
|
|
67
68
|
* Returns an action object signalling that the editor is being destroyed and
|
|
68
69
|
* that any necessary state or side-effect cleanup should occur.
|
|
@@ -79,45 +80,17 @@ export function __experimentalTearDownEditor() {
|
|
|
79
80
|
* Returns an action object used in signalling that the latest version of the
|
|
80
81
|
* post has been received, either by initialization or save.
|
|
81
82
|
*
|
|
82
|
-
* @
|
|
83
|
-
*
|
|
84
|
-
* @return {Object} Action object.
|
|
85
|
-
*/
|
|
86
|
-
|
|
87
|
-
export function resetPost(post) {
|
|
88
|
-
return {
|
|
89
|
-
type: 'RESET_POST',
|
|
90
|
-
post
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
/**
|
|
94
|
-
* Action for dispatching that a post update request has started.
|
|
95
|
-
*
|
|
96
|
-
* @param {Object} options
|
|
97
|
-
*
|
|
98
|
-
* @return {Object} An action object
|
|
99
|
-
*/
|
|
100
|
-
|
|
101
|
-
export function __experimentalRequestPostUpdateStart() {
|
|
102
|
-
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
103
|
-
return {
|
|
104
|
-
type: 'REQUEST_POST_UPDATE_START',
|
|
105
|
-
options
|
|
106
|
-
};
|
|
107
|
-
}
|
|
108
|
-
/**
|
|
109
|
-
* Action for dispatching that a post update request has finished.
|
|
110
|
-
*
|
|
111
|
-
* @param {Object} options
|
|
112
|
-
*
|
|
113
|
-
* @return {Object} An action object
|
|
83
|
+
* @deprecated Since WordPress 6.0.
|
|
114
84
|
*/
|
|
115
85
|
|
|
116
|
-
export function
|
|
117
|
-
|
|
86
|
+
export function resetPost() {
|
|
87
|
+
deprecated("wp.data.dispatch( 'core/editor' ).resetPost", {
|
|
88
|
+
since: '6.0',
|
|
89
|
+
version: '6.3',
|
|
90
|
+
alternative: 'Initialize the editor with the setupEditorState action'
|
|
91
|
+
});
|
|
118
92
|
return {
|
|
119
|
-
type: '
|
|
120
|
-
options
|
|
93
|
+
type: 'DO_NOTHING'
|
|
121
94
|
};
|
|
122
95
|
}
|
|
123
96
|
/**
|
|
@@ -158,81 +131,96 @@ export function setupEditorState(post) {
|
|
|
158
131
|
*
|
|
159
132
|
* @param {Object} edits Post attributes to edit.
|
|
160
133
|
* @param {Object} options Options for the edit.
|
|
161
|
-
*
|
|
162
|
-
* @yield {Object} Action object or control.
|
|
163
134
|
*/
|
|
164
135
|
|
|
165
|
-
export
|
|
136
|
+
export const editPost = (edits, options) => _ref3 => {
|
|
137
|
+
let {
|
|
138
|
+
select,
|
|
139
|
+
registry
|
|
140
|
+
} = _ref3;
|
|
166
141
|
const {
|
|
167
142
|
id,
|
|
168
143
|
type
|
|
169
|
-
} =
|
|
170
|
-
|
|
171
|
-
}
|
|
144
|
+
} = select.getCurrentPost();
|
|
145
|
+
registry.dispatch(coreStore).editEntityRecord('postType', type, id, edits, options);
|
|
146
|
+
};
|
|
172
147
|
/**
|
|
173
|
-
* Action
|
|
148
|
+
* Action for saving the current post in the editor.
|
|
174
149
|
*
|
|
175
150
|
* @param {Object} options
|
|
176
151
|
*/
|
|
177
152
|
|
|
178
|
-
export function
|
|
153
|
+
export const savePost = function () {
|
|
179
154
|
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
155
|
+
return async _ref4 => {
|
|
156
|
+
let {
|
|
157
|
+
select,
|
|
158
|
+
dispatch,
|
|
159
|
+
registry
|
|
160
|
+
} = _ref4;
|
|
161
|
+
|
|
162
|
+
if (!select.isEditedPostSaveable()) {
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
180
165
|
|
|
181
|
-
|
|
182
|
-
return;
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
let edits = {
|
|
186
|
-
content: yield controls.select(STORE_NAME, 'getEditedPostContent')
|
|
187
|
-
};
|
|
166
|
+
const content = select.getEditedPostContent();
|
|
188
167
|
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
168
|
+
if (!options.isAutosave) {
|
|
169
|
+
dispatch.editPost({
|
|
170
|
+
content
|
|
171
|
+
}, {
|
|
172
|
+
undoIgnore: true
|
|
173
|
+
});
|
|
174
|
+
}
|
|
194
175
|
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
const error = yield controls.select(coreStore, 'getLastEntitySaveError', 'postType', previousRecord.type, previousRecord.id);
|
|
205
|
-
|
|
206
|
-
if (error) {
|
|
207
|
-
const args = getNotificationArgumentsForSaveFail({
|
|
208
|
-
post: previousRecord,
|
|
209
|
-
edits,
|
|
210
|
-
error
|
|
176
|
+
const previousRecord = select.getCurrentPost();
|
|
177
|
+
const edits = {
|
|
178
|
+
id: previousRecord.id,
|
|
179
|
+
...registry.select(coreStore).getEntityRecordNonTransientEdits('postType', previousRecord.type, previousRecord.id),
|
|
180
|
+
content
|
|
181
|
+
};
|
|
182
|
+
dispatch({
|
|
183
|
+
type: 'REQUEST_POST_UPDATE_START',
|
|
184
|
+
options
|
|
211
185
|
});
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
}
|
|
216
|
-
} else {
|
|
217
|
-
const updatedRecord = yield controls.select(STORE_NAME, 'getCurrentPost');
|
|
218
|
-
const args = getNotificationArgumentsForSaveSuccess({
|
|
219
|
-
previousPost: previousRecord,
|
|
220
|
-
post: updatedRecord,
|
|
221
|
-
postType: yield controls.resolveSelect(coreStore, 'getPostType', updatedRecord.type),
|
|
186
|
+
await registry.dispatch(coreStore).saveEntityRecord('postType', previousRecord.type, edits, options);
|
|
187
|
+
dispatch({
|
|
188
|
+
type: 'REQUEST_POST_UPDATE_FINISH',
|
|
222
189
|
options
|
|
223
190
|
});
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
191
|
+
const error = registry.select(coreStore).getLastEntitySaveError('postType', previousRecord.type, previousRecord.id);
|
|
192
|
+
|
|
193
|
+
if (error) {
|
|
194
|
+
const args = getNotificationArgumentsForSaveFail({
|
|
195
|
+
post: previousRecord,
|
|
196
|
+
edits,
|
|
197
|
+
error
|
|
198
|
+
});
|
|
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.resolveSelect(coreStore).getPostType(updatedRecord.type),
|
|
209
|
+
options
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
if (args.length) {
|
|
213
|
+
registry.dispatch(noticesStore).createSuccessNotice(...args);
|
|
214
|
+
} // Make sure that any edits after saving create an undo level and are
|
|
215
|
+
// considered for change detection.
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
if (!options.isAutosave) {
|
|
219
|
+
registry.dispatch(blockEditorStore).__unstableMarkLastChangeAsPersistent();
|
|
220
|
+
}
|
|
233
221
|
}
|
|
234
|
-
}
|
|
235
|
-
}
|
|
222
|
+
};
|
|
223
|
+
};
|
|
236
224
|
/**
|
|
237
225
|
* Action for refreshing the current post.
|
|
238
226
|
*
|
|
@@ -250,29 +238,34 @@ export function refreshPost() {
|
|
|
250
238
|
};
|
|
251
239
|
}
|
|
252
240
|
/**
|
|
253
|
-
* Action
|
|
241
|
+
* Action for trashing the current post in the editor.
|
|
254
242
|
*/
|
|
255
243
|
|
|
256
|
-
export
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
244
|
+
export const trashPost = () => async _ref5 => {
|
|
245
|
+
let {
|
|
246
|
+
select,
|
|
247
|
+
dispatch,
|
|
248
|
+
registry
|
|
249
|
+
} = _ref5;
|
|
250
|
+
const postTypeSlug = select.getCurrentPostType();
|
|
251
|
+
const postType = await registry.resolveSelect(coreStore).getPostType(postTypeSlug);
|
|
252
|
+
registry.dispatch(noticesStore).removeNotice(TRASH_POST_NOTICE_ID);
|
|
260
253
|
|
|
261
254
|
try {
|
|
262
|
-
const post =
|
|
263
|
-
|
|
255
|
+
const post = select.getCurrentPost();
|
|
256
|
+
await apiFetch({
|
|
264
257
|
path: `/wp/v2/${postType.rest_base}/${post.id}`,
|
|
265
258
|
method: 'DELETE'
|
|
266
259
|
});
|
|
267
|
-
|
|
260
|
+
await dispatch.savePost();
|
|
268
261
|
} catch (error) {
|
|
269
|
-
|
|
262
|
+
registry.dispatch(noticesStore).createErrorNotice(...getNotificationArgumentsForTrashFail({
|
|
270
263
|
error
|
|
271
264
|
}));
|
|
272
265
|
}
|
|
273
|
-
}
|
|
266
|
+
};
|
|
274
267
|
/**
|
|
275
|
-
* Action
|
|
268
|
+
* Action that autosaves the current post. This
|
|
276
269
|
* includes server-side autosaving (default) and client-side (a.k.a. local)
|
|
277
270
|
* autosaving (e.g. on the Web, the post might be committed to Session
|
|
278
271
|
* Storage).
|
|
@@ -280,52 +273,52 @@ export function* trashPost() {
|
|
|
280
273
|
* @param {Object?} options Extra flags to identify the autosave.
|
|
281
274
|
*/
|
|
282
275
|
|
|
283
|
-
export function
|
|
276
|
+
export const autosave = function () {
|
|
284
277
|
let {
|
|
285
278
|
local = false,
|
|
286
279
|
...options
|
|
287
280
|
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
content,
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
}
|
|
281
|
+
return async _ref6 => {
|
|
282
|
+
let {
|
|
283
|
+
select,
|
|
284
|
+
dispatch
|
|
285
|
+
} = _ref6;
|
|
286
|
+
|
|
287
|
+
if (local) {
|
|
288
|
+
const post = select.getCurrentPost();
|
|
289
|
+
const isPostNew = select.isEditedPostNew();
|
|
290
|
+
const title = select.getEditedPostAttribute('title');
|
|
291
|
+
const content = select.getEditedPostAttribute('content');
|
|
292
|
+
const excerpt = select.getEditedPostAttribute('excerpt');
|
|
293
|
+
localAutosaveSet(post.id, isPostNew, title, content, excerpt);
|
|
294
|
+
} else {
|
|
295
|
+
await dispatch.savePost({
|
|
296
|
+
isAutosave: true,
|
|
297
|
+
...options
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
};
|
|
301
|
+
};
|
|
310
302
|
/**
|
|
311
|
-
*
|
|
312
|
-
* restore last popped state.
|
|
313
|
-
*
|
|
314
|
-
* @yield {Object} Action object.
|
|
303
|
+
* Action that restores last popped state in undo history.
|
|
315
304
|
*/
|
|
316
305
|
|
|
317
|
-
export
|
|
318
|
-
|
|
319
|
-
|
|
306
|
+
export const redo = () => _ref7 => {
|
|
307
|
+
let {
|
|
308
|
+
registry
|
|
309
|
+
} = _ref7;
|
|
310
|
+
registry.dispatch(coreStore).redo();
|
|
311
|
+
};
|
|
320
312
|
/**
|
|
321
|
-
*
|
|
322
|
-
*
|
|
323
|
-
* @yield {Object} Action object.
|
|
313
|
+
* Action that pops a record from undo history and undoes the edit.
|
|
324
314
|
*/
|
|
325
315
|
|
|
326
|
-
export
|
|
327
|
-
|
|
328
|
-
|
|
316
|
+
export const undo = () => _ref8 => {
|
|
317
|
+
let {
|
|
318
|
+
registry
|
|
319
|
+
} = _ref8;
|
|
320
|
+
registry.dispatch(coreStore).undo();
|
|
321
|
+
};
|
|
329
322
|
/**
|
|
330
323
|
* Action that creates an undo history record.
|
|
331
324
|
*
|
|
@@ -343,10 +336,9 @@ export function createUndoLevel() {
|
|
|
343
336
|
};
|
|
344
337
|
}
|
|
345
338
|
/**
|
|
346
|
-
*
|
|
339
|
+
* Action that locks the editor.
|
|
347
340
|
*
|
|
348
341
|
* @param {Object} lock Details about the post lock status, user, and nonce.
|
|
349
|
-
*
|
|
350
342
|
* @return {Object} Action object.
|
|
351
343
|
*/
|
|
352
344
|
|
|
@@ -357,8 +349,7 @@ export function updatePostLock(lock) {
|
|
|
357
349
|
};
|
|
358
350
|
}
|
|
359
351
|
/**
|
|
360
|
-
*
|
|
361
|
-
* publish sidebar.
|
|
352
|
+
* Action that enables the publish sidebar.
|
|
362
353
|
*
|
|
363
354
|
* @return {Object} Action object
|
|
364
355
|
*/
|
|
@@ -369,8 +360,7 @@ export function enablePublishSidebar() {
|
|
|
369
360
|
};
|
|
370
361
|
}
|
|
371
362
|
/**
|
|
372
|
-
*
|
|
373
|
-
* publish sidebar.
|
|
363
|
+
* Action that disables the publish sidebar.
|
|
374
364
|
*
|
|
375
365
|
* @return {Object} Action object
|
|
376
366
|
*/
|
|
@@ -381,7 +371,7 @@ export function disablePublishSidebar() {
|
|
|
381
371
|
};
|
|
382
372
|
}
|
|
383
373
|
/**
|
|
384
|
-
*
|
|
374
|
+
* Action that locks post saving.
|
|
385
375
|
*
|
|
386
376
|
* @param {string} lockName The lock name.
|
|
387
377
|
*
|
|
@@ -431,7 +421,7 @@ export function lockPostSaving(lockName) {
|
|
|
431
421
|
};
|
|
432
422
|
}
|
|
433
423
|
/**
|
|
434
|
-
*
|
|
424
|
+
* Action that unlocks post saving.
|
|
435
425
|
*
|
|
436
426
|
* @param {string} lockName The lock name.
|
|
437
427
|
*
|
|
@@ -451,7 +441,7 @@ export function unlockPostSaving(lockName) {
|
|
|
451
441
|
};
|
|
452
442
|
}
|
|
453
443
|
/**
|
|
454
|
-
*
|
|
444
|
+
* Action that locks post autosaving.
|
|
455
445
|
*
|
|
456
446
|
* @param {string} lockName The lock name.
|
|
457
447
|
*
|
|
@@ -471,7 +461,7 @@ export function lockPostAutosaving(lockName) {
|
|
|
471
461
|
};
|
|
472
462
|
}
|
|
473
463
|
/**
|
|
474
|
-
*
|
|
464
|
+
* Action that unlocks post autosaving.
|
|
475
465
|
*
|
|
476
466
|
* @param {string} lockName The lock name.
|
|
477
467
|
*
|
|
@@ -495,45 +485,52 @@ export function unlockPostAutosaving(lockName) {
|
|
|
495
485
|
*
|
|
496
486
|
* @param {Array} blocks Block Array.
|
|
497
487
|
* @param {?Object} options Optional options.
|
|
498
|
-
*
|
|
499
|
-
* @yield {Object} Action object
|
|
500
488
|
*/
|
|
501
489
|
|
|
502
|
-
export function
|
|
490
|
+
export const resetEditorBlocks = function (blocks) {
|
|
503
491
|
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
selection
|
|
511
|
-
};
|
|
512
|
-
|
|
513
|
-
if (__unstableShouldCreateUndoLevel !== false) {
|
|
492
|
+
return _ref9 => {
|
|
493
|
+
let {
|
|
494
|
+
select,
|
|
495
|
+
dispatch,
|
|
496
|
+
registry
|
|
497
|
+
} = _ref9;
|
|
514
498
|
const {
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
} =
|
|
518
|
-
const
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
return yield controls.dispatch(coreStore, '__unstableCreateUndoLevel', 'postType', type, id);
|
|
522
|
-
} // We create a new function here on every persistent edit
|
|
523
|
-
// to make sure the edit makes the post dirty and creates
|
|
524
|
-
// a new undo level.
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
edits.content = _ref => {
|
|
528
|
-
let {
|
|
529
|
-
blocks: blocksForSerialization = []
|
|
530
|
-
} = _ref;
|
|
531
|
-
return __unstableSerializeAndClean(blocksForSerialization);
|
|
499
|
+
__unstableShouldCreateUndoLevel,
|
|
500
|
+
selection
|
|
501
|
+
} = options;
|
|
502
|
+
const edits = {
|
|
503
|
+
blocks,
|
|
504
|
+
selection
|
|
532
505
|
};
|
|
533
|
-
}
|
|
534
506
|
|
|
535
|
-
|
|
536
|
-
|
|
507
|
+
if (__unstableShouldCreateUndoLevel !== false) {
|
|
508
|
+
const {
|
|
509
|
+
id,
|
|
510
|
+
type
|
|
511
|
+
} = select.getCurrentPost();
|
|
512
|
+
const noChange = registry.select(coreStore).getEditedEntityRecord('postType', type, id).blocks === edits.blocks;
|
|
513
|
+
|
|
514
|
+
if (noChange) {
|
|
515
|
+
registry.dispatch(coreStore).__unstableCreateUndoLevel('postType', type, id);
|
|
516
|
+
|
|
517
|
+
return;
|
|
518
|
+
} // We create a new function here on every persistent edit
|
|
519
|
+
// to make sure the edit makes the post dirty and creates
|
|
520
|
+
// a new undo level.
|
|
521
|
+
|
|
522
|
+
|
|
523
|
+
edits.content = _ref10 => {
|
|
524
|
+
let {
|
|
525
|
+
blocks: blocksForSerialization = []
|
|
526
|
+
} = _ref10;
|
|
527
|
+
return __unstableSerializeAndClean(blocksForSerialization);
|
|
528
|
+
};
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
dispatch.editPost(edits);
|
|
532
|
+
};
|
|
533
|
+
};
|
|
537
534
|
/*
|
|
538
535
|
* Returns an action object used in signalling that the post editor settings have been updated.
|
|
539
536
|
*
|
|
@@ -552,18 +549,22 @@ export function updateEditorSettings(settings) {
|
|
|
552
549
|
* Backward compatibility
|
|
553
550
|
*/
|
|
554
551
|
|
|
555
|
-
const getBlockEditorAction = name => function
|
|
556
|
-
deprecated("`wp.data.dispatch( 'core/editor' )." + name + '`', {
|
|
557
|
-
since: '5.3',
|
|
558
|
-
alternative: "`wp.data.dispatch( 'core/block-editor' )." + name + '`',
|
|
559
|
-
version: '6.2'
|
|
560
|
-
});
|
|
561
|
-
|
|
552
|
+
const getBlockEditorAction = name => function () {
|
|
562
553
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
563
554
|
args[_key] = arguments[_key];
|
|
564
555
|
}
|
|
565
556
|
|
|
566
|
-
|
|
557
|
+
return _ref11 => {
|
|
558
|
+
let {
|
|
559
|
+
registry
|
|
560
|
+
} = _ref11;
|
|
561
|
+
deprecated("`wp.data.dispatch( 'core/editor' )." + name + '`', {
|
|
562
|
+
since: '5.3',
|
|
563
|
+
alternative: "`wp.data.dispatch( 'core/block-editor' )." + name + '`',
|
|
564
|
+
version: '6.2'
|
|
565
|
+
});
|
|
566
|
+
registry.dispatch(blockEditorStore)[name](...args);
|
|
567
|
+
};
|
|
567
568
|
};
|
|
568
569
|
/**
|
|
569
570
|
* @see resetBlocks in core/block-editor store.
|