@wordpress/editor 12.2.1 → 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.
Files changed (65) hide show
  1. package/build/components/local-autosave-monitor/index.js +5 -5
  2. package/build/components/local-autosave-monitor/index.js.map +1 -1
  3. package/build/components/post-saved-state/index.js +1 -1
  4. package/build/components/post-saved-state/index.js.map +1 -1
  5. package/build/components/post-switch-to-draft-button/index.js +19 -14
  6. package/build/components/post-switch-to-draft-button/index.js.map +1 -1
  7. package/build/components/post-trash/index.js +15 -29
  8. package/build/components/post-trash/index.js.map +1 -1
  9. package/build/components/provider/index.native.js +17 -8
  10. package/build/components/provider/index.native.js.map +1 -1
  11. package/build/components/provider/use-block-editor-settings.js +3 -2
  12. package/build/components/provider/use-block-editor-settings.js.map +1 -1
  13. package/build/store/actions.js +231 -225
  14. package/build/store/actions.js.map +1 -1
  15. package/build/store/actions.native.js +6 -4
  16. package/build/store/actions.native.js.map +1 -1
  17. package/build/store/index.js +1 -8
  18. package/build/store/index.js.map +1 -1
  19. package/build/store/{controls.js → local-autosave.js} +1 -18
  20. package/build/store/local-autosave.js.map +1 -0
  21. package/build/store/reducer.js +0 -2
  22. package/build/store/reducer.js.map +1 -1
  23. package/build/store/utils/notice-builder.js +5 -0
  24. package/build/store/utils/notice-builder.js.map +1 -1
  25. package/build-module/components/local-autosave-monitor/index.js +1 -1
  26. package/build-module/components/local-autosave-monitor/index.js.map +1 -1
  27. package/build-module/components/post-saved-state/index.js +1 -1
  28. package/build-module/components/post-saved-state/index.js.map +1 -1
  29. package/build-module/components/post-switch-to-draft-button/index.js +22 -16
  30. package/build-module/components/post-switch-to-draft-button/index.js.map +1 -1
  31. package/build-module/components/post-trash/index.js +15 -27
  32. package/build-module/components/post-trash/index.js.map +1 -1
  33. package/build-module/components/provider/index.native.js +19 -10
  34. package/build-module/components/provider/index.native.js.map +1 -1
  35. package/build-module/components/provider/use-block-editor-settings.js +3 -2
  36. package/build-module/components/provider/use-block-editor-settings.js.map +1 -1
  37. package/build-module/store/actions.js +208 -207
  38. package/build-module/store/actions.js.map +1 -1
  39. package/build-module/store/actions.native.js +3 -3
  40. package/build-module/store/actions.native.js.map +1 -1
  41. package/build-module/store/index.js +1 -6
  42. package/build-module/store/index.js.map +1 -1
  43. package/build-module/store/{controls.js → local-autosave.js} +1 -15
  44. package/build-module/store/local-autosave.js.map +1 -0
  45. package/build-module/store/reducer.js +0 -2
  46. package/build-module/store/reducer.js.map +1 -1
  47. package/build-module/store/utils/notice-builder.js +5 -0
  48. package/build-module/store/utils/notice-builder.js.map +1 -1
  49. package/package.json +14 -15
  50. package/src/components/local-autosave-monitor/index.js +4 -1
  51. package/src/components/post-saved-state/index.js +1 -1
  52. package/src/components/post-switch-to-draft-button/index.js +35 -24
  53. package/src/components/post-trash/index.js +12 -24
  54. package/src/components/provider/index.native.js +20 -16
  55. package/src/components/provider/use-block-editor-settings.js +2 -0
  56. package/src/store/actions.js +137 -249
  57. package/src/store/actions.native.js +3 -3
  58. package/src/store/index.js +0 -6
  59. package/src/store/{controls.js → local-autosave.js} +0 -8
  60. package/src/store/reducer.js +0 -2
  61. package/src/store/test/actions.js +244 -416
  62. package/src/store/utils/notice-builder.js +5 -0
  63. package/src/store/utils/test/notice-builder.js +1 -0
  64. package/build/store/controls.js.map +0 -1
  65. package/build-module/store/controls.js.map +0 -1
@@ -5,31 +5,22 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
- exports.__experimentalRequestPostUpdateFinish = __experimentalRequestPostUpdateFinish;
9
- exports.__experimentalRequestPostUpdateStart = __experimentalRequestPostUpdateStart;
10
8
  exports.__experimentalTearDownEditor = __experimentalTearDownEditor;
11
- exports.autosave = autosave;
12
- exports.clearSelectedBlock = void 0;
9
+ exports.clearSelectedBlock = exports.autosave = void 0;
13
10
  exports.createUndoLevel = createUndoLevel;
14
11
  exports.disablePublishSidebar = disablePublishSidebar;
15
- exports.editPost = editPost;
12
+ exports.editPost = void 0;
16
13
  exports.enablePublishSidebar = enablePublishSidebar;
17
14
  exports.insertDefaultBlock = exports.insertBlocks = exports.insertBlock = exports.hideInsertionPoint = exports.exitFormattedText = exports.enterFormattedText = void 0;
18
15
  exports.lockPostAutosaving = lockPostAutosaving;
19
16
  exports.lockPostSaving = lockPostSaving;
20
- exports.receiveBlocks = exports.multiSelect = exports.moveBlocksUp = exports.moveBlocksDown = exports.moveBlockToPosition = exports.mergeBlocks = void 0;
21
- exports.redo = redo;
17
+ exports.redo = exports.receiveBlocks = exports.multiSelect = exports.moveBlocksUp = exports.moveBlocksDown = exports.moveBlockToPosition = exports.mergeBlocks = void 0;
22
18
  exports.refreshPost = refreshPost;
23
- exports.resetBlocks = exports.replaceBlocks = exports.replaceBlock = exports.removeBlocks = exports.removeBlock = void 0;
24
- exports.resetEditorBlocks = resetEditorBlocks;
19
+ exports.resetEditorBlocks = exports.resetBlocks = exports.replaceBlocks = exports.replaceBlock = exports.removeBlocks = exports.removeBlock = void 0;
25
20
  exports.resetPost = resetPost;
26
- exports.savePost = savePost;
27
- exports.setTemplateValidity = exports.selectBlock = void 0;
28
- exports.setupEditor = setupEditor;
21
+ exports.setupEditor = exports.setTemplateValidity = exports.selectBlock = exports.savePost = void 0;
29
22
  exports.setupEditorState = setupEditorState;
30
- exports.toggleSelection = exports.toggleBlockMode = exports.synchronizeTemplate = exports.stopTyping = exports.stopMultiSelect = exports.startTyping = exports.startMultiSelect = exports.showInsertionPoint = void 0;
31
- exports.trashPost = trashPost;
32
- exports.undo = undo;
23
+ exports.undo = exports.trashPost = exports.toggleSelection = exports.toggleBlockMode = exports.synchronizeTemplate = exports.stopTyping = exports.stopMultiSelect = exports.startTyping = exports.startMultiSelect = exports.showInsertionPoint = void 0;
33
24
  exports.unlockPostAutosaving = unlockPostAutosaving;
34
25
  exports.unlockPostSaving = unlockPostSaving;
35
26
  exports.updateBlockListSettings = exports.updateBlockAttributes = exports.updateBlock = void 0;
@@ -39,11 +30,9 @@ exports.updatePostLock = updatePostLock;
39
30
 
40
31
  var _lodash = require("lodash");
41
32
 
42
- var _deprecated = _interopRequireDefault(require("@wordpress/deprecated"));
33
+ var _apiFetch = _interopRequireDefault(require("@wordpress/api-fetch"));
43
34
 
44
- var _data = require("@wordpress/data");
45
-
46
- var _dataControls = require("@wordpress/data-controls");
35
+ var _deprecated = _interopRequireDefault(require("@wordpress/deprecated"));
47
36
 
48
37
  var _blocks = require("@wordpress/blocks");
49
38
 
@@ -55,6 +44,8 @@ var _blockEditor = require("@wordpress/block-editor");
55
44
 
56
45
  var _constants = require("./constants");
57
46
 
47
+ var _localAutosave = require("./local-autosave");
48
+
58
49
  var _noticeBuilder = require("./utils/notice-builder");
59
50
 
60
51
  /**
@@ -77,15 +68,11 @@ var _noticeBuilder = require("./utils/notice-builder");
77
68
  * @param {Object} edits Initial edited attributes object.
78
69
  * @param {Array?} template Block Template.
79
70
  */
80
- function* setupEditor(post, edits, template) {
81
- yield resetPost(post);
82
- yield {
83
- type: 'SETUP_EDITOR',
84
- post,
85
- edits,
86
- template
87
- };
88
- yield setupEditorState(post); // Apply a template for new posts only, if exists.
71
+ const setupEditor = (post, edits, template) => _ref => {
72
+ let {
73
+ dispatch
74
+ } = _ref;
75
+ dispatch.setupEditorState(post); // Apply a template for new posts only, if exists.
89
76
 
90
77
  const isNewPost = post.status === 'auto-draft';
91
78
 
@@ -103,15 +90,20 @@ function* setupEditor(post, edits, template) {
103
90
 
104
91
  let blocks = (0, _blocks.parse)(content);
105
92
  blocks = (0, _blocks.synchronizeBlocksWithTemplate)(blocks, template);
106
- yield resetEditorBlocks(blocks, {
93
+ dispatch.resetEditorBlocks(blocks, {
107
94
  __unstableShouldCreateUndoLevel: false
108
95
  });
109
96
  }
110
97
 
111
- if (edits && Object.keys(edits).some(key => edits[key] !== ((0, _lodash.has)(post, [key, 'raw']) ? post[key].raw : post[key]))) {
112
- yield editPost(edits);
98
+ if (edits && Object.values(edits).some(_ref2 => {
99
+ var _post$key$raw, _post$key;
100
+
101
+ let [key, edit] = _ref2;
102
+ 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]);
103
+ })) {
104
+ dispatch.editPost(edits);
113
105
  }
114
- }
106
+ };
115
107
  /**
116
108
  * Returns an action object signalling that the editor is being destroyed and
117
109
  * that any necessary state or side-effect cleanup should occur.
@@ -120,6 +112,8 @@ function* setupEditor(post, edits, template) {
120
112
  */
121
113
 
122
114
 
115
+ exports.setupEditor = setupEditor;
116
+
123
117
  function __experimentalTearDownEditor() {
124
118
  return {
125
119
  type: 'TEAR_DOWN_EDITOR'
@@ -129,48 +123,18 @@ function __experimentalTearDownEditor() {
129
123
  * Returns an action object used in signalling that the latest version of the
130
124
  * post has been received, either by initialization or save.
131
125
  *
132
- * @param {Object} post Post object.
133
- *
134
- * @return {Object} Action object.
135
- */
136
-
137
-
138
- function resetPost(post) {
139
- return {
140
- type: 'RESET_POST',
141
- post
142
- };
143
- }
144
- /**
145
- * Action for dispatching that a post update request has started.
146
- *
147
- * @param {Object} options
148
- *
149
- * @return {Object} An action object
150
- */
151
-
152
-
153
- function __experimentalRequestPostUpdateStart() {
154
- let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
155
- return {
156
- type: 'REQUEST_POST_UPDATE_START',
157
- options
158
- };
159
- }
160
- /**
161
- * Action for dispatching that a post update request has finished.
162
- *
163
- * @param {Object} options
164
- *
165
- * @return {Object} An action object
126
+ * @deprecated Since WordPress 6.0.
166
127
  */
167
128
 
168
129
 
169
- function __experimentalRequestPostUpdateFinish() {
170
- let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
130
+ function resetPost() {
131
+ (0, _deprecated.default)("wp.data.dispatch( 'core/editor' ).resetPost", {
132
+ since: '6.0',
133
+ version: '6.3',
134
+ alternative: 'Initialize the editor with the setupEditorState action'
135
+ });
171
136
  return {
172
- type: 'REQUEST_POST_UPDATE_FINISH',
173
- options
137
+ type: 'DO_NOTHING'
174
138
  };
175
139
  }
176
140
  /**
@@ -213,83 +177,100 @@ function setupEditorState(post) {
213
177
  *
214
178
  * @param {Object} edits Post attributes to edit.
215
179
  * @param {Object} options Options for the edit.
216
- *
217
- * @yield {Object} Action object or control.
218
180
  */
219
181
 
220
182
 
221
- function* editPost(edits, options) {
183
+ const editPost = (edits, options) => _ref3 => {
184
+ let {
185
+ select,
186
+ registry
187
+ } = _ref3;
222
188
  const {
223
189
  id,
224
190
  type
225
- } = yield _data.controls.select(_constants.STORE_NAME, 'getCurrentPost');
226
- yield _data.controls.dispatch(_coreData.store, 'editEntityRecord', 'postType', type, id, edits, options);
227
- }
191
+ } = select.getCurrentPost();
192
+ registry.dispatch(_coreData.store).editEntityRecord('postType', type, id, edits, options);
193
+ };
228
194
  /**
229
- * Action generator for saving the current post in the editor.
195
+ * Action for saving the current post in the editor.
230
196
  *
231
197
  * @param {Object} options
232
198
  */
233
199
 
234
200
 
235
- function* savePost() {
236
- let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
201
+ exports.editPost = editPost;
237
202
 
238
- if (!(yield _data.controls.select(_constants.STORE_NAME, 'isEditedPostSaveable'))) {
239
- return;
240
- }
203
+ const savePost = function () {
204
+ let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
205
+ return async _ref4 => {
206
+ let {
207
+ select,
208
+ dispatch,
209
+ registry
210
+ } = _ref4;
211
+
212
+ if (!select.isEditedPostSaveable()) {
213
+ return;
214
+ }
241
215
 
242
- let edits = {
243
- content: yield _data.controls.select(_constants.STORE_NAME, 'getEditedPostContent')
244
- };
216
+ const content = select.getEditedPostContent();
245
217
 
246
- if (!options.isAutosave) {
247
- yield _data.controls.dispatch(_constants.STORE_NAME, 'editPost', edits, {
248
- undoIgnore: true
249
- });
250
- }
218
+ if (!options.isAutosave) {
219
+ dispatch.editPost({
220
+ content
221
+ }, {
222
+ undoIgnore: true
223
+ });
224
+ }
251
225
 
252
- yield __experimentalRequestPostUpdateStart(options);
253
- const previousRecord = yield _data.controls.select(_constants.STORE_NAME, 'getCurrentPost');
254
- edits = {
255
- id: previousRecord.id,
256
- ...(yield _data.controls.select(_coreData.store, 'getEntityRecordNonTransientEdits', 'postType', previousRecord.type, previousRecord.id)),
257
- ...edits
258
- };
259
- yield _data.controls.dispatch(_coreData.store, 'saveEntityRecord', 'postType', previousRecord.type, edits, options);
260
- yield __experimentalRequestPostUpdateFinish(options);
261
- const error = yield _data.controls.select(_coreData.store, 'getLastEntitySaveError', 'postType', previousRecord.type, previousRecord.id);
262
-
263
- if (error) {
264
- const args = (0, _noticeBuilder.getNotificationArgumentsForSaveFail)({
265
- post: previousRecord,
266
- edits,
267
- error
226
+ const previousRecord = select.getCurrentPost();
227
+ const edits = {
228
+ id: previousRecord.id,
229
+ ...registry.select(_coreData.store).getEntityRecordNonTransientEdits('postType', previousRecord.type, previousRecord.id),
230
+ content
231
+ };
232
+ dispatch({
233
+ type: 'REQUEST_POST_UPDATE_START',
234
+ options
268
235
  });
269
-
270
- if (args.length) {
271
- yield _data.controls.dispatch(_notices.store, 'createErrorNotice', ...args);
272
- }
273
- } else {
274
- const updatedRecord = yield _data.controls.select(_constants.STORE_NAME, 'getCurrentPost');
275
- const args = (0, _noticeBuilder.getNotificationArgumentsForSaveSuccess)({
276
- previousPost: previousRecord,
277
- post: updatedRecord,
278
- postType: yield _data.controls.resolveSelect(_coreData.store, 'getPostType', updatedRecord.type),
236
+ await registry.dispatch(_coreData.store).saveEntityRecord('postType', previousRecord.type, edits, options);
237
+ dispatch({
238
+ type: 'REQUEST_POST_UPDATE_FINISH',
279
239
  options
280
240
  });
281
-
282
- if (args.length) {
283
- yield _data.controls.dispatch(_notices.store, 'createSuccessNotice', ...args);
284
- } // Make sure that any edits after saving create an undo level and are
285
- // considered for change detection.
286
-
287
-
288
- if (!options.isAutosave) {
289
- yield _data.controls.dispatch(_blockEditor.store, '__unstableMarkLastChangeAsPersistent');
241
+ const error = registry.select(_coreData.store).getLastEntitySaveError('postType', previousRecord.type, previousRecord.id);
242
+
243
+ if (error) {
244
+ const args = (0, _noticeBuilder.getNotificationArgumentsForSaveFail)({
245
+ post: previousRecord,
246
+ edits,
247
+ error
248
+ });
249
+
250
+ if (args.length) {
251
+ registry.dispatch(_notices.store).createErrorNotice(...args);
252
+ }
253
+ } else {
254
+ const updatedRecord = select.getCurrentPost();
255
+ const args = (0, _noticeBuilder.getNotificationArgumentsForSaveSuccess)({
256
+ previousPost: previousRecord,
257
+ post: updatedRecord,
258
+ postType: await registry.resolveSelect(_coreData.store).getPostType(updatedRecord.type),
259
+ options
260
+ });
261
+
262
+ if (args.length) {
263
+ registry.dispatch(_notices.store).createSuccessNotice(...args);
264
+ } // Make sure that any edits after saving create an undo level and are
265
+ // considered for change detection.
266
+
267
+
268
+ if (!options.isAutosave) {
269
+ registry.dispatch(_blockEditor.store).__unstableMarkLastChangeAsPersistent();
270
+ }
290
271
  }
291
- }
292
- }
272
+ };
273
+ };
293
274
  /**
294
275
  * Action for refreshing the current post.
295
276
  *
@@ -297,6 +278,8 @@ function* savePost() {
297
278
  */
298
279
 
299
280
 
281
+ exports.savePost = savePost;
282
+
300
283
  function refreshPost() {
301
284
  (0, _deprecated.default)("wp.data.dispatch( 'core/editor' ).refreshPost", {
302
285
  since: '6.0',
@@ -308,30 +291,35 @@ function refreshPost() {
308
291
  };
309
292
  }
310
293
  /**
311
- * Action generator for trashing the current post in the editor.
294
+ * Action for trashing the current post in the editor.
312
295
  */
313
296
 
314
297
 
315
- function* trashPost() {
316
- const postTypeSlug = yield _data.controls.select(_constants.STORE_NAME, 'getCurrentPostType');
317
- const postType = yield _data.controls.resolveSelect(_coreData.store, 'getPostType', postTypeSlug);
318
- yield _data.controls.dispatch(_notices.store, 'removeNotice', _constants.TRASH_POST_NOTICE_ID);
298
+ const trashPost = () => async _ref5 => {
299
+ let {
300
+ select,
301
+ dispatch,
302
+ registry
303
+ } = _ref5;
304
+ const postTypeSlug = select.getCurrentPostType();
305
+ const postType = await registry.resolveSelect(_coreData.store).getPostType(postTypeSlug);
306
+ registry.dispatch(_notices.store).removeNotice(_constants.TRASH_POST_NOTICE_ID);
319
307
 
320
308
  try {
321
- const post = yield _data.controls.select(_constants.STORE_NAME, 'getCurrentPost');
322
- yield (0, _dataControls.apiFetch)({
309
+ const post = select.getCurrentPost();
310
+ await (0, _apiFetch.default)({
323
311
  path: `/wp/v2/${postType.rest_base}/${post.id}`,
324
312
  method: 'DELETE'
325
313
  });
326
- yield _data.controls.dispatch(_constants.STORE_NAME, 'savePost');
314
+ await dispatch.savePost();
327
315
  } catch (error) {
328
- yield _data.controls.dispatch(_notices.store, 'createErrorNotice', ...(0, _noticeBuilder.getNotificationArgumentsForTrashFail)({
316
+ registry.dispatch(_notices.store).createErrorNotice(...(0, _noticeBuilder.getNotificationArgumentsForTrashFail)({
329
317
  error
330
318
  }));
331
319
  }
332
- }
320
+ };
333
321
  /**
334
- * Action generator used in signalling that the post should autosave. This
322
+ * Action that autosaves the current post. This
335
323
  * includes server-side autosaving (default) and client-side (a.k.a. local)
336
324
  * autosaving (e.g. on the Web, the post might be committed to Session
337
325
  * Storage).
@@ -340,54 +328,60 @@ function* trashPost() {
340
328
  */
341
329
 
342
330
 
343
- function* autosave() {
331
+ exports.trashPost = trashPost;
332
+
333
+ const autosave = function () {
344
334
  let {
345
335
  local = false,
346
336
  ...options
347
337
  } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
348
-
349
- if (local) {
350
- const post = yield _data.controls.select(_constants.STORE_NAME, 'getCurrentPost');
351
- const isPostNew = yield _data.controls.select(_constants.STORE_NAME, 'isEditedPostNew');
352
- const title = yield _data.controls.select(_constants.STORE_NAME, 'getEditedPostAttribute', 'title');
353
- const content = yield _data.controls.select(_constants.STORE_NAME, 'getEditedPostAttribute', 'content');
354
- const excerpt = yield _data.controls.select(_constants.STORE_NAME, 'getEditedPostAttribute', 'excerpt');
355
- yield {
356
- type: 'LOCAL_AUTOSAVE_SET',
357
- postId: post.id,
358
- isPostNew,
359
- title,
360
- content,
361
- excerpt
362
- };
363
- } else {
364
- yield _data.controls.dispatch(_constants.STORE_NAME, 'savePost', {
365
- isAutosave: true,
366
- ...options
367
- });
368
- }
369
- }
338
+ return async _ref6 => {
339
+ let {
340
+ select,
341
+ dispatch
342
+ } = _ref6;
343
+
344
+ if (local) {
345
+ const post = select.getCurrentPost();
346
+ const isPostNew = select.isEditedPostNew();
347
+ const title = select.getEditedPostAttribute('title');
348
+ const content = select.getEditedPostAttribute('content');
349
+ const excerpt = select.getEditedPostAttribute('excerpt');
350
+ (0, _localAutosave.localAutosaveSet)(post.id, isPostNew, title, content, excerpt);
351
+ } else {
352
+ await dispatch.savePost({
353
+ isAutosave: true,
354
+ ...options
355
+ });
356
+ }
357
+ };
358
+ };
370
359
  /**
371
- * Returns an action object used in signalling that undo history should
372
- * restore last popped state.
373
- *
374
- * @yield {Object} Action object.
360
+ * Action that restores last popped state in undo history.
375
361
  */
376
362
 
377
363
 
378
- function* redo() {
379
- yield _data.controls.dispatch(_coreData.store, 'redo');
380
- }
364
+ exports.autosave = autosave;
365
+
366
+ const redo = () => _ref7 => {
367
+ let {
368
+ registry
369
+ } = _ref7;
370
+ registry.dispatch(_coreData.store).redo();
371
+ };
381
372
  /**
382
- * Returns an action object used in signalling that undo history should pop.
383
- *
384
- * @yield {Object} Action object.
373
+ * Action that pops a record from undo history and undoes the edit.
385
374
  */
386
375
 
387
376
 
388
- function* undo() {
389
- yield _data.controls.dispatch(_coreData.store, 'undo');
390
- }
377
+ exports.redo = redo;
378
+
379
+ const undo = () => _ref8 => {
380
+ let {
381
+ registry
382
+ } = _ref8;
383
+ registry.dispatch(_coreData.store).undo();
384
+ };
391
385
  /**
392
386
  * Action that creates an undo history record.
393
387
  *
@@ -395,6 +389,8 @@ function* undo() {
395
389
  */
396
390
 
397
391
 
392
+ exports.undo = undo;
393
+
398
394
  function createUndoLevel() {
399
395
  (0, _deprecated.default)("wp.data.dispatch( 'core/editor' ).createUndoLevel", {
400
396
  since: '6.0',
@@ -406,10 +402,9 @@ function createUndoLevel() {
406
402
  };
407
403
  }
408
404
  /**
409
- * Returns an action object used to lock the editor.
405
+ * Action that locks the editor.
410
406
  *
411
407
  * @param {Object} lock Details about the post lock status, user, and nonce.
412
- *
413
408
  * @return {Object} Action object.
414
409
  */
415
410
 
@@ -421,8 +416,7 @@ function updatePostLock(lock) {
421
416
  };
422
417
  }
423
418
  /**
424
- * Returns an action object used in signalling that the user has enabled the
425
- * publish sidebar.
419
+ * Action that enables the publish sidebar.
426
420
  *
427
421
  * @return {Object} Action object
428
422
  */
@@ -434,8 +428,7 @@ function enablePublishSidebar() {
434
428
  };
435
429
  }
436
430
  /**
437
- * Returns an action object used in signalling that the user has disabled the
438
- * publish sidebar.
431
+ * Action that disables the publish sidebar.
439
432
  *
440
433
  * @return {Object} Action object
441
434
  */
@@ -447,7 +440,7 @@ function disablePublishSidebar() {
447
440
  };
448
441
  }
449
442
  /**
450
- * Returns an action object used to signal that post saving is locked.
443
+ * Action that locks post saving.
451
444
  *
452
445
  * @param {string} lockName The lock name.
453
446
  *
@@ -498,7 +491,7 @@ function lockPostSaving(lockName) {
498
491
  };
499
492
  }
500
493
  /**
501
- * Returns an action object used to signal that post saving is unlocked.
494
+ * Action that unlocks post saving.
502
495
  *
503
496
  * @param {string} lockName The lock name.
504
497
  *
@@ -519,7 +512,7 @@ function unlockPostSaving(lockName) {
519
512
  };
520
513
  }
521
514
  /**
522
- * Returns an action object used to signal that post autosaving is locked.
515
+ * Action that locks post autosaving.
523
516
  *
524
517
  * @param {string} lockName The lock name.
525
518
  *
@@ -540,7 +533,7 @@ function lockPostAutosaving(lockName) {
540
533
  };
541
534
  }
542
535
  /**
543
- * Returns an action object used to signal that post autosaving is unlocked.
536
+ * Action that unlocks post autosaving.
544
537
  *
545
538
  * @param {string} lockName The lock name.
546
539
  *
@@ -565,46 +558,53 @@ function unlockPostAutosaving(lockName) {
565
558
  *
566
559
  * @param {Array} blocks Block Array.
567
560
  * @param {?Object} options Optional options.
568
- *
569
- * @yield {Object} Action object
570
561
  */
571
562
 
572
563
 
573
- function* resetEditorBlocks(blocks) {
564
+ const resetEditorBlocks = function (blocks) {
574
565
  let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
575
- const {
576
- __unstableShouldCreateUndoLevel,
577
- selection
578
- } = options;
579
- const edits = {
580
- blocks,
581
- selection
582
- };
583
-
584
- if (__unstableShouldCreateUndoLevel !== false) {
566
+ return _ref9 => {
567
+ let {
568
+ select,
569
+ dispatch,
570
+ registry
571
+ } = _ref9;
585
572
  const {
586
- id,
587
- type
588
- } = yield _data.controls.select(_constants.STORE_NAME, 'getCurrentPost');
589
- const noChange = (yield _data.controls.select(_coreData.store, 'getEditedEntityRecord', 'postType', type, id)).blocks === edits.blocks;
590
-
591
- if (noChange) {
592
- return yield _data.controls.dispatch(_coreData.store, '__unstableCreateUndoLevel', 'postType', type, id);
593
- } // We create a new function here on every persistent edit
594
- // to make sure the edit makes the post dirty and creates
595
- // a new undo level.
596
-
597
-
598
- edits.content = _ref => {
599
- let {
600
- blocks: blocksForSerialization = []
601
- } = _ref;
602
- return (0, _blocks.__unstableSerializeAndClean)(blocksForSerialization);
573
+ __unstableShouldCreateUndoLevel,
574
+ selection
575
+ } = options;
576
+ const edits = {
577
+ blocks,
578
+ selection
603
579
  };
604
- }
605
580
 
606
- yield* editPost(edits);
607
- }
581
+ if (__unstableShouldCreateUndoLevel !== false) {
582
+ const {
583
+ id,
584
+ type
585
+ } = select.getCurrentPost();
586
+ const noChange = registry.select(_coreData.store).getEditedEntityRecord('postType', type, id).blocks === edits.blocks;
587
+
588
+ if (noChange) {
589
+ registry.dispatch(_coreData.store).__unstableCreateUndoLevel('postType', type, id);
590
+
591
+ return;
592
+ } // We create a new function here on every persistent edit
593
+ // to make sure the edit makes the post dirty and creates
594
+ // a new undo level.
595
+
596
+
597
+ edits.content = _ref10 => {
598
+ let {
599
+ blocks: blocksForSerialization = []
600
+ } = _ref10;
601
+ return (0, _blocks.__unstableSerializeAndClean)(blocksForSerialization);
602
+ };
603
+ }
604
+
605
+ dispatch.editPost(edits);
606
+ };
607
+ };
608
608
  /*
609
609
  * Returns an action object used in signalling that the post editor settings have been updated.
610
610
  *
@@ -614,6 +614,8 @@ function* resetEditorBlocks(blocks) {
614
614
  */
615
615
 
616
616
 
617
+ exports.resetEditorBlocks = resetEditorBlocks;
618
+
617
619
  function updateEditorSettings(settings) {
618
620
  return {
619
621
  type: 'UPDATE_EDITOR_SETTINGS',
@@ -625,18 +627,22 @@ function updateEditorSettings(settings) {
625
627
  */
626
628
 
627
629
 
628
- const getBlockEditorAction = name => function* () {
629
- (0, _deprecated.default)("`wp.data.dispatch( 'core/editor' )." + name + '`', {
630
- since: '5.3',
631
- alternative: "`wp.data.dispatch( 'core/block-editor' )." + name + '`',
632
- version: '6.2'
633
- });
634
-
630
+ const getBlockEditorAction = name => function () {
635
631
  for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
636
632
  args[_key] = arguments[_key];
637
633
  }
638
634
 
639
- yield _data.controls.dispatch(_blockEditor.store, name, ...args);
635
+ return _ref11 => {
636
+ let {
637
+ registry
638
+ } = _ref11;
639
+ (0, _deprecated.default)("`wp.data.dispatch( 'core/editor' )." + name + '`', {
640
+ since: '5.3',
641
+ alternative: "`wp.data.dispatch( 'core/block-editor' )." + name + '`',
642
+ version: '6.2'
643
+ });
644
+ registry.dispatch(_blockEditor.store)[name](...args);
645
+ };
640
646
  };
641
647
  /**
642
648
  * @see resetBlocks in core/block-editor store.