@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.
- 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/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/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
package/build/store/actions.js
CHANGED
|
@@ -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 =
|
|
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 =
|
|
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 =
|
|
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
|
|
33
|
+
var _apiFetch = _interopRequireDefault(require("@wordpress/api-fetch"));
|
|
43
34
|
|
|
44
|
-
var
|
|
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
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
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
|
-
|
|
93
|
+
dispatch.resetEditorBlocks(blocks, {
|
|
107
94
|
__unstableShouldCreateUndoLevel: false
|
|
108
95
|
});
|
|
109
96
|
}
|
|
110
97
|
|
|
111
|
-
if (edits && Object.
|
|
112
|
-
|
|
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
|
-
* @
|
|
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
|
|
170
|
-
|
|
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: '
|
|
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
|
-
|
|
183
|
+
const editPost = (edits, options) => _ref3 => {
|
|
184
|
+
let {
|
|
185
|
+
select,
|
|
186
|
+
registry
|
|
187
|
+
} = _ref3;
|
|
222
188
|
const {
|
|
223
189
|
id,
|
|
224
190
|
type
|
|
225
|
-
} =
|
|
226
|
-
|
|
227
|
-
}
|
|
191
|
+
} = select.getCurrentPost();
|
|
192
|
+
registry.dispatch(_coreData.store).editEntityRecord('postType', type, id, edits, options);
|
|
193
|
+
};
|
|
228
194
|
/**
|
|
229
|
-
* Action
|
|
195
|
+
* Action for saving the current post in the editor.
|
|
230
196
|
*
|
|
231
197
|
* @param {Object} options
|
|
232
198
|
*/
|
|
233
199
|
|
|
234
200
|
|
|
235
|
-
|
|
236
|
-
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
201
|
+
exports.editPost = editPost;
|
|
237
202
|
|
|
238
|
-
|
|
239
|
-
|
|
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
|
-
|
|
243
|
-
content: yield _data.controls.select(_constants.STORE_NAME, 'getEditedPostContent')
|
|
244
|
-
};
|
|
216
|
+
const content = select.getEditedPostContent();
|
|
245
217
|
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
218
|
+
if (!options.isAutosave) {
|
|
219
|
+
dispatch.editPost({
|
|
220
|
+
content
|
|
221
|
+
}, {
|
|
222
|
+
undoIgnore: true
|
|
223
|
+
});
|
|
224
|
+
}
|
|
251
225
|
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
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
|
-
|
|
271
|
-
|
|
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
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
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
|
|
294
|
+
* Action for trashing the current post in the editor.
|
|
312
295
|
*/
|
|
313
296
|
|
|
314
297
|
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
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 =
|
|
322
|
-
|
|
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
|
-
|
|
314
|
+
await dispatch.savePost();
|
|
327
315
|
} catch (error) {
|
|
328
|
-
|
|
316
|
+
registry.dispatch(_notices.store).createErrorNotice(...(0, _noticeBuilder.getNotificationArgumentsForTrashFail)({
|
|
329
317
|
error
|
|
330
318
|
}));
|
|
331
319
|
}
|
|
332
|
-
}
|
|
320
|
+
};
|
|
333
321
|
/**
|
|
334
|
-
* Action
|
|
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
|
-
|
|
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
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
content,
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
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
|
-
*
|
|
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
|
-
|
|
379
|
-
|
|
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
|
-
*
|
|
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
|
-
|
|
389
|
-
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
|
564
|
+
const resetEditorBlocks = function (blocks) {
|
|
574
565
|
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
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
|
-
|
|
587
|
-
|
|
588
|
-
} =
|
|
589
|
-
const
|
|
590
|
-
|
|
591
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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.
|