@wordpress/edit-site 4.0.1 → 4.0.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/add-new-template/new-template-part.js +4 -1
- package/build/components/add-new-template/new-template-part.js.map +1 -1
- package/build/components/error-boundary/index.js +11 -27
- package/build/components/error-boundary/index.js.map +1 -1
- package/build/components/error-boundary/warning.js +70 -0
- package/build/components/error-boundary/warning.js.map +1 -0
- package/build/components/global-styles/navigation-button.js +7 -27
- package/build/components/global-styles/navigation-button.js.map +1 -1
- package/build/components/global-styles/typography-panel.js +5 -2
- package/build/components/global-styles/typography-panel.js.map +1 -1
- package/build/components/global-styles/use-global-styles-output.js +21 -4
- package/build/components/global-styles/use-global-styles-output.js.map +1 -1
- package/build/components/list/table.js +3 -1
- package/build/components/list/table.js.map +1 -1
- package/build/components/navigation-sidebar/navigation-toggle/index.js +15 -4
- package/build/components/navigation-sidebar/navigation-toggle/index.js.map +1 -1
- package/build/components/routes/redirect-to-homepage.js +22 -3
- package/build/components/routes/redirect-to-homepage.js.map +1 -1
- package/build/components/secondary-sidebar/list-view-sidebar.js +0 -11
- package/build/components/secondary-sidebar/list-view-sidebar.js.map +1 -1
- package/build/components/template-part-converter/convert-to-template-part.js +4 -1
- package/build/components/template-part-converter/convert-to-template-part.js.map +1 -1
- package/build/index.js +15 -1
- package/build/index.js.map +1 -1
- package/build/store/actions.js +191 -155
- package/build/store/actions.js.map +1 -1
- package/build/store/index.js +0 -3
- package/build/store/index.js.map +1 -1
- package/build/store/selectors.js +3 -2
- package/build/store/selectors.js.map +1 -1
- package/build-module/components/add-new-template/new-template-part.js +4 -1
- package/build-module/components/add-new-template/new-template-part.js.map +1 -1
- package/build-module/components/error-boundary/index.js +9 -26
- package/build-module/components/error-boundary/index.js.map +1 -1
- package/build-module/components/error-boundary/warning.js +60 -0
- package/build-module/components/error-boundary/warning.js.map +1 -0
- package/build-module/components/global-styles/navigation-button.js +8 -28
- package/build-module/components/global-styles/navigation-button.js.map +1 -1
- package/build-module/components/global-styles/typography-panel.js +6 -3
- package/build-module/components/global-styles/typography-panel.js.map +1 -1
- package/build-module/components/global-styles/use-global-styles-output.js +20 -4
- package/build-module/components/global-styles/use-global-styles-output.js.map +1 -1
- package/build-module/components/list/table.js +2 -1
- package/build-module/components/list/table.js.map +1 -1
- package/build-module/components/navigation-sidebar/navigation-toggle/index.js +12 -4
- package/build-module/components/navigation-sidebar/navigation-toggle/index.js.map +1 -1
- package/build-module/components/routes/redirect-to-homepage.js +22 -3
- package/build-module/components/routes/redirect-to-homepage.js.map +1 -1
- package/build-module/components/secondary-sidebar/list-view-sidebar.js +1 -12
- package/build-module/components/secondary-sidebar/list-view-sidebar.js.map +1 -1
- package/build-module/components/template-part-converter/convert-to-template-part.js +4 -1
- package/build-module/components/template-part-converter/convert-to-template-part.js.map +1 -1
- package/build-module/index.js +13 -1
- package/build-module/index.js.map +1 -1
- package/build-module/store/actions.js +170 -145
- package/build-module/store/actions.js.map +1 -1
- package/build-module/store/index.js +0 -2
- package/build-module/store/index.js.map +1 -1
- package/build-module/store/selectors.js +3 -2
- package/build-module/store/selectors.js.map +1 -1
- package/build-style/style-rtl.css +11 -10
- package/build-style/style.css +11 -10
- package/package.json +18 -18
- package/src/components/add-new-template/new-template-part.js +7 -1
- package/src/components/error-boundary/index.js +11 -28
- package/src/components/error-boundary/warning.js +59 -0
- package/src/components/global-styles/navigation-button.js +6 -25
- package/src/components/global-styles/typography-panel.js +12 -5
- package/src/components/global-styles/use-global-styles-output.js +19 -3
- package/src/components/list/table.js +5 -2
- package/src/components/navigation-sidebar/navigation-toggle/index.js +13 -4
- package/src/components/navigation-sidebar/navigation-toggle/style.scss +32 -31
- package/src/components/routes/redirect-to-homepage.js +27 -4
- package/src/components/secondary-sidebar/list-view-sidebar.js +1 -11
- package/src/components/template-part-converter/convert-to-template-part.js +6 -1
- package/src/index.js +17 -1
- package/src/store/actions.js +161 -205
- package/src/store/index.js +0 -2
- package/src/store/selectors.js +3 -0
- package/src/store/test/actions.js +186 -92
- package/src/store/test/selectors.js +8 -1
package/build/store/actions.js
CHANGED
|
@@ -6,29 +6,23 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
8
|
exports.__experimentalSetPreviewDeviceType = __experimentalSetPreviewDeviceType;
|
|
9
|
-
exports.addTemplate =
|
|
10
|
-
exports.closeGeneralSidebar = closeGeneralSidebar;
|
|
11
|
-
exports.openGeneralSidebar = openGeneralSidebar;
|
|
9
|
+
exports.openGeneralSidebar = exports.closeGeneralSidebar = exports.addTemplate = void 0;
|
|
12
10
|
exports.openNavigationPanelToMenu = openNavigationPanelToMenu;
|
|
13
|
-
exports.removeTemplate =
|
|
14
|
-
exports.revertTemplate = revertTemplate;
|
|
11
|
+
exports.revertTemplate = exports.removeTemplate = void 0;
|
|
15
12
|
exports.setHomeTemplateId = setHomeTemplateId;
|
|
16
13
|
exports.setIsInserterOpened = setIsInserterOpened;
|
|
17
14
|
exports.setIsListViewOpened = setIsListViewOpened;
|
|
18
15
|
exports.setIsNavigationPanelOpened = setIsNavigationPanelOpened;
|
|
19
16
|
exports.setNavigationPanelActiveMenu = setNavigationPanelActiveMenu;
|
|
20
|
-
exports.setPage =
|
|
21
|
-
exports.setTemplate = setTemplate;
|
|
17
|
+
exports.setTemplate = exports.setPage = void 0;
|
|
22
18
|
exports.setTemplatePart = setTemplatePart;
|
|
23
|
-
exports.switchEditorMode =
|
|
19
|
+
exports.switchEditorMode = void 0;
|
|
24
20
|
exports.toggleFeature = toggleFeature;
|
|
25
21
|
exports.updateSettings = updateSettings;
|
|
26
22
|
|
|
27
|
-
var
|
|
28
|
-
|
|
29
|
-
var _data = require("@wordpress/data");
|
|
23
|
+
var _apiFetch = _interopRequireDefault(require("@wordpress/api-fetch"));
|
|
30
24
|
|
|
31
|
-
var
|
|
25
|
+
var _blocks = require("@wordpress/blocks");
|
|
32
26
|
|
|
33
27
|
var _url = require("@wordpress/url");
|
|
34
28
|
|
|
@@ -57,7 +51,7 @@ var _isTemplateRevertable = _interopRequireDefault(require("../utils/is-template
|
|
|
57
51
|
*/
|
|
58
52
|
|
|
59
53
|
/**
|
|
60
|
-
*
|
|
54
|
+
* Action that toggles a feature flag.
|
|
61
55
|
*
|
|
62
56
|
* @param {string} feature Feature name.
|
|
63
57
|
*
|
|
@@ -70,7 +64,7 @@ function toggleFeature(feature) {
|
|
|
70
64
|
};
|
|
71
65
|
}
|
|
72
66
|
/**
|
|
73
|
-
*
|
|
67
|
+
* Action that changes the width of the editing canvas.
|
|
74
68
|
*
|
|
75
69
|
* @param {string} deviceType
|
|
76
70
|
*
|
|
@@ -85,7 +79,7 @@ function __experimentalSetPreviewDeviceType(deviceType) {
|
|
|
85
79
|
};
|
|
86
80
|
}
|
|
87
81
|
/**
|
|
88
|
-
*
|
|
82
|
+
* Action that sets a template, optionally fetching it from REST API.
|
|
89
83
|
*
|
|
90
84
|
* @param {number} templateId The template ID.
|
|
91
85
|
* @param {string} templateSlug The template slug.
|
|
@@ -93,26 +87,29 @@ function __experimentalSetPreviewDeviceType(deviceType) {
|
|
|
93
87
|
*/
|
|
94
88
|
|
|
95
89
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
90
|
+
const setTemplate = (templateId, templateSlug) => async _ref => {
|
|
91
|
+
let {
|
|
92
|
+
dispatch,
|
|
93
|
+
registry
|
|
94
|
+
} = _ref;
|
|
100
95
|
|
|
101
96
|
if (!templateSlug) {
|
|
102
|
-
const template =
|
|
103
|
-
|
|
97
|
+
const template = await registry.resolveSelect(_coreData.store).getEntityRecord('postType', 'wp_template', templateId);
|
|
98
|
+
templateSlug = template === null || template === void 0 ? void 0 : template.slug;
|
|
104
99
|
}
|
|
105
100
|
|
|
106
|
-
|
|
101
|
+
dispatch({
|
|
107
102
|
type: 'SET_TEMPLATE',
|
|
108
103
|
templateId,
|
|
109
104
|
page: {
|
|
110
|
-
context:
|
|
105
|
+
context: {
|
|
106
|
+
templateSlug
|
|
107
|
+
}
|
|
111
108
|
}
|
|
112
|
-
};
|
|
113
|
-
}
|
|
109
|
+
});
|
|
110
|
+
};
|
|
114
111
|
/**
|
|
115
|
-
*
|
|
112
|
+
* Action that adds a new template and sets it as the current template.
|
|
116
113
|
*
|
|
117
114
|
* @param {Object} template The template.
|
|
118
115
|
*
|
|
@@ -120,18 +117,24 @@ function* setTemplate(templateId, templateSlug) {
|
|
|
120
117
|
*/
|
|
121
118
|
|
|
122
119
|
|
|
123
|
-
|
|
124
|
-
|
|
120
|
+
exports.setTemplate = setTemplate;
|
|
121
|
+
|
|
122
|
+
const addTemplate = template => async _ref2 => {
|
|
123
|
+
let {
|
|
124
|
+
dispatch,
|
|
125
|
+
registry
|
|
126
|
+
} = _ref2;
|
|
127
|
+
const newTemplate = await registry.dispatch(_coreData.store).saveEntityRecord('postType', 'wp_template', template);
|
|
125
128
|
|
|
126
129
|
if (template.content) {
|
|
127
|
-
|
|
130
|
+
registry.dispatch(_coreData.store).editEntityRecord('postType', 'wp_template', newTemplate.id, {
|
|
128
131
|
blocks: (0, _blocks.parse)(template.content)
|
|
129
132
|
}, {
|
|
130
133
|
undoIgnore: true
|
|
131
134
|
});
|
|
132
135
|
}
|
|
133
136
|
|
|
134
|
-
|
|
137
|
+
dispatch({
|
|
135
138
|
type: 'SET_TEMPLATE',
|
|
136
139
|
templateId: newTemplate.id,
|
|
137
140
|
page: {
|
|
@@ -139,40 +142,46 @@ function* addTemplate(template) {
|
|
|
139
142
|
templateSlug: newTemplate.slug
|
|
140
143
|
}
|
|
141
144
|
}
|
|
142
|
-
};
|
|
143
|
-
}
|
|
145
|
+
});
|
|
146
|
+
};
|
|
144
147
|
/**
|
|
145
|
-
*
|
|
148
|
+
* Action that removes a template.
|
|
146
149
|
*
|
|
147
150
|
* @param {Object} template The template object.
|
|
148
151
|
*/
|
|
149
152
|
|
|
150
153
|
|
|
151
|
-
|
|
154
|
+
exports.addTemplate = addTemplate;
|
|
155
|
+
|
|
156
|
+
const removeTemplate = template => async _ref3 => {
|
|
157
|
+
let {
|
|
158
|
+
registry
|
|
159
|
+
} = _ref3;
|
|
160
|
+
|
|
152
161
|
try {
|
|
153
|
-
|
|
162
|
+
await registry.dispatch(_coreData.store).deleteEntityRecord('postType', template.type, template.id, {
|
|
154
163
|
force: true
|
|
155
164
|
});
|
|
156
|
-
const lastError =
|
|
165
|
+
const lastError = registry.select(_coreData.store).getLastEntityDeleteError('postType', template.type, template.id);
|
|
157
166
|
|
|
158
167
|
if (lastError) {
|
|
159
168
|
throw lastError;
|
|
160
169
|
}
|
|
161
170
|
|
|
162
|
-
|
|
171
|
+
registry.dispatch(_notices.store).createSuccessNotice((0, _i18n.sprintf)(
|
|
163
172
|
/* translators: The template/part's name. */
|
|
164
173
|
(0, _i18n.__)('"%s" deleted.'), template.title.rendered), {
|
|
165
174
|
type: 'snackbar'
|
|
166
175
|
});
|
|
167
176
|
} catch (error) {
|
|
168
177
|
const errorMessage = error.message && error.code !== 'unknown_error' ? error.message : (0, _i18n.__)('An error occurred while deleting the template.');
|
|
169
|
-
|
|
178
|
+
registry.dispatch(_notices.store).createErrorNotice(errorMessage, {
|
|
170
179
|
type: 'snackbar'
|
|
171
180
|
});
|
|
172
181
|
}
|
|
173
|
-
}
|
|
182
|
+
};
|
|
174
183
|
/**
|
|
175
|
-
*
|
|
184
|
+
* Action that sets a template part.
|
|
176
185
|
*
|
|
177
186
|
* @param {string} templatePartId The template part ID.
|
|
178
187
|
*
|
|
@@ -180,6 +189,8 @@ function* removeTemplate(template) {
|
|
|
180
189
|
*/
|
|
181
190
|
|
|
182
191
|
|
|
192
|
+
exports.removeTemplate = removeTemplate;
|
|
193
|
+
|
|
183
194
|
function setTemplatePart(templatePartId) {
|
|
184
195
|
return {
|
|
185
196
|
type: 'SET_TEMPLATE_PART',
|
|
@@ -187,8 +198,8 @@ function setTemplatePart(templatePartId) {
|
|
|
187
198
|
};
|
|
188
199
|
}
|
|
189
200
|
/**
|
|
190
|
-
*
|
|
191
|
-
* from
|
|
201
|
+
* Action that sets the home template ID to the template ID of the page resolved
|
|
202
|
+
* from a given path.
|
|
192
203
|
*
|
|
193
204
|
* @param {number} homeTemplateId The template ID for the homepage.
|
|
194
205
|
*/
|
|
@@ -214,32 +225,39 @@ function setHomeTemplateId(homeTemplateId) {
|
|
|
214
225
|
*/
|
|
215
226
|
|
|
216
227
|
|
|
217
|
-
|
|
228
|
+
const setPage = page => async _ref4 => {
|
|
218
229
|
var _page$context;
|
|
219
230
|
|
|
231
|
+
let {
|
|
232
|
+
dispatch,
|
|
233
|
+
registry
|
|
234
|
+
} = _ref4;
|
|
235
|
+
|
|
220
236
|
if (!page.path && (_page$context = page.context) !== null && _page$context !== void 0 && _page$context.postId) {
|
|
221
|
-
const entity =
|
|
237
|
+
const entity = await registry.resolveSelect(_coreData.store).getEntityRecord('postType', page.context.postType || 'post', page.context.postId); // If the entity is undefined for some reason, path will resolve to "/"
|
|
222
238
|
|
|
223
239
|
page.path = (0, _url.getPathAndQueryString)(entity === null || entity === void 0 ? void 0 : entity.link);
|
|
224
240
|
}
|
|
225
241
|
|
|
226
|
-
const
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
242
|
+
const template = await registry.resolveSelect(_coreData.store).__experimentalGetTemplateForLink(page.path);
|
|
243
|
+
|
|
244
|
+
if (!template) {
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
dispatch({
|
|
231
249
|
type: 'SET_PAGE',
|
|
232
|
-
page:
|
|
250
|
+
page: template.slug ? { ...page,
|
|
233
251
|
context: { ...page.context,
|
|
234
|
-
templateSlug
|
|
252
|
+
templateSlug: template.slug
|
|
235
253
|
}
|
|
236
|
-
},
|
|
237
|
-
templateId
|
|
238
|
-
};
|
|
239
|
-
return
|
|
240
|
-
}
|
|
254
|
+
} : page,
|
|
255
|
+
templateId: template.id
|
|
256
|
+
});
|
|
257
|
+
return template.id;
|
|
258
|
+
};
|
|
241
259
|
/**
|
|
242
|
-
*
|
|
260
|
+
* Action that sets the active navigation panel menu.
|
|
243
261
|
*
|
|
244
262
|
* @param {string} menu Menu prop of active menu.
|
|
245
263
|
*
|
|
@@ -247,6 +265,8 @@ function* setPage(page) {
|
|
|
247
265
|
*/
|
|
248
266
|
|
|
249
267
|
|
|
268
|
+
exports.setPage = setPage;
|
|
269
|
+
|
|
250
270
|
function setNavigationPanelActiveMenu(menu) {
|
|
251
271
|
return {
|
|
252
272
|
type: 'SET_NAVIGATION_PANEL_ACTIVE_MENU',
|
|
@@ -281,7 +301,7 @@ function setIsNavigationPanelOpened(isOpen) {
|
|
|
281
301
|
};
|
|
282
302
|
}
|
|
283
303
|
/**
|
|
284
|
-
*
|
|
304
|
+
* Opens or closes the inserter.
|
|
285
305
|
*
|
|
286
306
|
* @param {boolean|Object} value Whether the inserter should be
|
|
287
307
|
* opened (true) or closed (false).
|
|
@@ -339,139 +359,155 @@ function setIsListViewOpened(isOpen) {
|
|
|
339
359
|
*/
|
|
340
360
|
|
|
341
361
|
|
|
342
|
-
function
|
|
362
|
+
const revertTemplate = function (template) {
|
|
343
363
|
let {
|
|
344
364
|
allowUndo = true
|
|
345
365
|
} = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
366
|
+
return async _ref5 => {
|
|
367
|
+
let {
|
|
368
|
+
registry
|
|
369
|
+
} = _ref5;
|
|
346
370
|
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
type: 'snackbar'
|
|
350
|
-
});
|
|
351
|
-
return;
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
try {
|
|
355
|
-
var _fileTemplate$content;
|
|
356
|
-
|
|
357
|
-
const templateEntity = yield _data.controls.select(_coreData.store, 'getEntity', 'postType', template.type);
|
|
358
|
-
|
|
359
|
-
if (!templateEntity) {
|
|
360
|
-
yield _data.controls.dispatch(_notices.store, 'createErrorNotice', (0, _i18n.__)('The editor has encountered an unexpected error. Please reload.'), {
|
|
371
|
+
if (!(0, _isTemplateRevertable.default)(template)) {
|
|
372
|
+
registry.dispatch(_notices.store).createErrorNotice((0, _i18n.__)('This template is not revertable.'), {
|
|
361
373
|
type: 'snackbar'
|
|
362
374
|
});
|
|
363
375
|
return;
|
|
364
376
|
}
|
|
365
377
|
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
source: 'theme'
|
|
369
|
-
});
|
|
370
|
-
const fileTemplate = yield (0, _dataControls.apiFetch)({
|
|
371
|
-
path: fileTemplatePath
|
|
372
|
-
});
|
|
378
|
+
try {
|
|
379
|
+
var _fileTemplate$content;
|
|
373
380
|
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
381
|
+
const templateEntity = registry.select(_coreData.store).getEntity('postType', template.type);
|
|
382
|
+
|
|
383
|
+
if (!templateEntity) {
|
|
384
|
+
registry.dispatch(_notices.store).createErrorNotice((0, _i18n.__)('The editor has encountered an unexpected error. Please reload.'), {
|
|
385
|
+
type: 'snackbar'
|
|
386
|
+
});
|
|
387
|
+
return;
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
const fileTemplatePath = (0, _url.addQueryArgs)(`${templateEntity.baseURL}/${template.id}`, {
|
|
391
|
+
context: 'edit',
|
|
392
|
+
source: 'theme'
|
|
393
|
+
});
|
|
394
|
+
const fileTemplate = await (0, _apiFetch.default)({
|
|
395
|
+
path: fileTemplatePath
|
|
377
396
|
});
|
|
378
|
-
return;
|
|
379
|
-
}
|
|
380
397
|
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
398
|
+
if (!fileTemplate) {
|
|
399
|
+
registry.dispatch(_notices.store).createErrorNotice((0, _i18n.__)('The editor has encountered an unexpected error. Please reload.'), {
|
|
400
|
+
type: 'snackbar'
|
|
401
|
+
});
|
|
402
|
+
return;
|
|
403
|
+
}
|
|
387
404
|
|
|
388
|
-
|
|
389
|
-
|
|
405
|
+
const serializeBlocks = _ref6 => {
|
|
406
|
+
let {
|
|
407
|
+
blocks: blocksForSerialization = []
|
|
408
|
+
} = _ref6;
|
|
409
|
+
return (0, _blocks.__unstableSerializeAndClean)(blocksForSerialization);
|
|
410
|
+
};
|
|
390
411
|
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
// required to make the `undo` behave correctly
|
|
394
|
-
blocks: edited.blocks,
|
|
395
|
-
// required to revert the blocks in the editor
|
|
396
|
-
source: 'custom' // required to avoid turning the editor into a dirty state
|
|
412
|
+
const edited = registry.select(_coreData.store).getEditedEntityRecord('postType', template.type, template.id); // We are fixing up the undo level here to make sure we can undo
|
|
413
|
+
// the revert in the header toolbar correctly.
|
|
397
414
|
|
|
398
|
-
|
|
399
|
-
|
|
415
|
+
registry.dispatch(_coreData.store).editEntityRecord('postType', template.type, template.id, {
|
|
416
|
+
content: serializeBlocks,
|
|
417
|
+
// required to make the `undo` behave correctly
|
|
418
|
+
blocks: edited.blocks,
|
|
419
|
+
// required to revert the blocks in the editor
|
|
420
|
+
source: 'custom' // required to avoid turning the editor into a dirty state
|
|
400
421
|
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
yield _data.controls.dispatch(_coreData.store, 'editEntityRecord', 'postType', template.type, fileTemplate.id, {
|
|
404
|
-
content: serializeBlocks,
|
|
405
|
-
blocks,
|
|
406
|
-
source: 'theme'
|
|
407
|
-
});
|
|
422
|
+
}, {
|
|
423
|
+
undoIgnore: true // required to merge this edit with the last undo level
|
|
408
424
|
|
|
409
|
-
|
|
410
|
-
const
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
};
|
|
425
|
+
});
|
|
426
|
+
const blocks = (0, _blocks.parse)(fileTemplate === null || fileTemplate === void 0 ? void 0 : (_fileTemplate$content = fileTemplate.content) === null || _fileTemplate$content === void 0 ? void 0 : _fileTemplate$content.raw);
|
|
427
|
+
registry.dispatch(_coreData.store).editEntityRecord('postType', template.type, fileTemplate.id, {
|
|
428
|
+
content: serializeBlocks,
|
|
429
|
+
blocks,
|
|
430
|
+
source: 'theme'
|
|
431
|
+
});
|
|
417
432
|
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
433
|
+
if (allowUndo) {
|
|
434
|
+
const undoRevert = () => {
|
|
435
|
+
registry.dispatch(_coreData.store).editEntityRecord('postType', template.type, edited.id, {
|
|
436
|
+
content: serializeBlocks,
|
|
437
|
+
blocks: edited.blocks,
|
|
438
|
+
source: 'custom'
|
|
439
|
+
});
|
|
440
|
+
};
|
|
441
|
+
|
|
442
|
+
registry.dispatch(_notices.store).createSuccessNotice((0, _i18n.__)('Template reverted.'), {
|
|
443
|
+
type: 'snackbar',
|
|
444
|
+
actions: [{
|
|
445
|
+
label: (0, _i18n.__)('Undo'),
|
|
446
|
+
onClick: undoRevert
|
|
447
|
+
}]
|
|
448
|
+
});
|
|
449
|
+
} else {
|
|
450
|
+
registry.dispatch(_notices.store).createSuccessNotice((0, _i18n.__)('Template reverted.'));
|
|
451
|
+
}
|
|
452
|
+
} catch (error) {
|
|
453
|
+
const errorMessage = error.message && error.code !== 'unknown_error' ? error.message : (0, _i18n.__)('Template revert failed. Please reload.');
|
|
454
|
+
registry.dispatch(_notices.store).createErrorNotice(errorMessage, {
|
|
455
|
+
type: 'snackbar'
|
|
424
456
|
});
|
|
425
|
-
} else {
|
|
426
|
-
yield _data.controls.dispatch(_notices.store, 'createSuccessNotice', (0, _i18n.__)('Template reverted.'));
|
|
427
457
|
}
|
|
428
|
-
}
|
|
429
|
-
|
|
430
|
-
yield _data.controls.dispatch(_notices.store, 'createErrorNotice', errorMessage, {
|
|
431
|
-
type: 'snackbar'
|
|
432
|
-
});
|
|
433
|
-
}
|
|
434
|
-
}
|
|
458
|
+
};
|
|
459
|
+
};
|
|
435
460
|
/**
|
|
436
|
-
*
|
|
461
|
+
* Action that opens an editor sidebar.
|
|
437
462
|
*
|
|
438
463
|
* @param {?string} name Sidebar name to be opened.
|
|
439
|
-
*
|
|
440
|
-
* @yield {Object} Action object.
|
|
441
464
|
*/
|
|
442
465
|
|
|
443
466
|
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
467
|
+
exports.revertTemplate = revertTemplate;
|
|
468
|
+
|
|
469
|
+
const openGeneralSidebar = name => _ref7 => {
|
|
470
|
+
let {
|
|
471
|
+
registry
|
|
472
|
+
} = _ref7;
|
|
473
|
+
registry.dispatch(_interface.store).enableComplementaryArea(_constants.STORE_NAME, name);
|
|
474
|
+
};
|
|
447
475
|
/**
|
|
448
|
-
*
|
|
449
|
-
*
|
|
450
|
-
* @yield {Object} Action object.
|
|
476
|
+
* Action that closes the sidebar.
|
|
451
477
|
*/
|
|
452
478
|
|
|
453
479
|
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
480
|
+
exports.openGeneralSidebar = openGeneralSidebar;
|
|
481
|
+
|
|
482
|
+
const closeGeneralSidebar = () => _ref8 => {
|
|
483
|
+
let {
|
|
484
|
+
registry
|
|
485
|
+
} = _ref8;
|
|
486
|
+
registry.dispatch(_interface.store).disableComplementaryArea(_constants.STORE_NAME);
|
|
487
|
+
};
|
|
488
|
+
|
|
489
|
+
exports.closeGeneralSidebar = closeGeneralSidebar;
|
|
457
490
|
|
|
458
|
-
|
|
459
|
-
|
|
491
|
+
const switchEditorMode = mode => _ref9 => {
|
|
492
|
+
let {
|
|
493
|
+
dispatch,
|
|
494
|
+
registry
|
|
495
|
+
} = _ref9;
|
|
496
|
+
dispatch({
|
|
460
497
|
type: 'SWITCH_MODE',
|
|
461
498
|
mode
|
|
462
|
-
}; // Unselect blocks when we switch to a non visual mode.
|
|
499
|
+
}); // Unselect blocks when we switch to a non visual mode.
|
|
463
500
|
|
|
464
501
|
if (mode !== 'visual') {
|
|
465
|
-
|
|
502
|
+
registry.dispatch(_blockEditor.store).clearSelectedBlock();
|
|
466
503
|
}
|
|
467
504
|
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
if (messages[mode]) {
|
|
474
|
-
(0, _a11y.speak)(messages[mode], 'assertive');
|
|
505
|
+
if (mode === 'visual') {
|
|
506
|
+
(0, _a11y.speak)((0, _i18n.__)('Visual editor selected'), 'assertive');
|
|
507
|
+
} else if (mode === 'mosaic') {
|
|
508
|
+
(0, _a11y.speak)((0, _i18n.__)('Mosaic view selected'), 'assertive');
|
|
475
509
|
}
|
|
476
|
-
}
|
|
510
|
+
};
|
|
511
|
+
|
|
512
|
+
exports.switchEditorMode = switchEditorMode;
|
|
477
513
|
//# sourceMappingURL=actions.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/edit-site/src/store/actions.js"],"names":["toggleFeature","feature","type","__experimentalSetPreviewDeviceType","deviceType","setTemplate","templateId","templateSlug","pageContext","template","controls","resolveSelect","coreStore","slug","page","context","addTemplate","newTemplate","dispatch","content","id","blocks","undoIgnore","removeTemplate","force","lastError","select","noticesStore","title","rendered","error","errorMessage","message","code","setTemplatePart","templatePartId","setHomeTemplateId","homeTemplateId","setPage","path","postId","entity","postType","link","setNavigationPanelActiveMenu","menu","openNavigationPanelToMenu","setIsNavigationPanelOpened","isOpen","setIsInserterOpened","value","updateSettings","settings","setIsListViewOpened","revertTemplate","allowUndo","templateEntity","fileTemplatePath","baseURL","source","fileTemplate","serializeBlocks","blocksForSerialization","edited","raw","undoRevert","editEntityRecord","actions","label","onClick","openGeneralSidebar","name","interfaceStore","editSiteStoreName","closeGeneralSidebar","switchEditorMode","mode","blockEditorStore","messages","visual","mosaic"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAGA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAKA;;AACA;;AAlBA;AACA;AACA;;AAYA;AACA;AACA;;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,aAAT,CAAwBC,OAAxB,EAAkC;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AY,GACjBD,KAAK,CAACE,OAAN,IAAiBF,KAAK,CAACG,IAAN,KAAe,eAAhC,GACGH,KAAK,CAACE,OADT,GAEG,cAAI,wCAAJ,CAHJ;AAIA,UAAMtB,eAASQ,QAAT,CACLS,cADK,EAEL,mBAFK,EAGLI,YAHK,EAIL;AAAE7B,MAAAA,IAAI,EAAE;AAAR,KAJK,CAAN;AAMA;AACD;AACD;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,UAAUoE,kBAAV,CAA8BC,IAA9B,EAAqC;AAC3C,QAAM7D,eAASQ,QAAT,CACLsD,gBADK,EAEL,yBAFK,EAGLC,qBAHK,EAILF,IAJK,CAAN;AAMA;AAED;AACA;AACA;AACA;AACA;;;AACO,UAAUG,mBAAV,GAAgC;AACtC,QAAMhE,eAASQ,QAAT,CACLsD,gBADK,EAEL,0BAFK,EAGLC,qBAHK,CAAN;AAKA;;AAEM,UAAUE,gBAAV,CAA4BC,IAA5B,EAAmC;AACzC,QAAM;AACL1E,IAAAA,IAAI,EAAE,aADD;AAEL0E,IAAAA;AAFK,GAAN,CADyC,CAMzC;;AACA,MAAKA,IAAI,KAAK,QAAd,EAAyB;AACxB,UAAMlE,eAASQ,QAAT,CAAmB2D,mBAAiBN,IAApC,EAA0C,oBAA1C,CAAN;AACA;;AACD,QAAMO,QAAQ,GAAG;AAChBC,IAAAA,MAAM,EAAE,cAAI,wBAAJ,CADQ;AAEhBC,IAAAA,MAAM,EAAE,cAAI,sBAAJ;AAFQ,GAAjB;;AAIA,MAAKF,QAAQ,CAAEF,IAAF,CAAb,EAAwB;AACvB,qBAAOE,QAAQ,CAAEF,IAAF,CAAf,EAAyB,WAAzB;AACA;AACD","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { parse, __unstableSerializeAndClean } from '@wordpress/blocks';\nimport { controls, dispatch } from '@wordpress/data';\nimport { apiFetch } from '@wordpress/data-controls';\nimport { addQueryArgs, getPathAndQueryString } from '@wordpress/url';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { store as interfaceStore } from '@wordpress/interface';\nimport { store as blockEditorStore } from '@wordpress/block-editor';\nimport { speak } from '@wordpress/a11y';\n\n/**\n * Internal dependencies\n */\nimport { STORE_NAME as editSiteStoreName } from './constants';\nimport isTemplateRevertable from '../utils/is-template-revertable';\n\n/**\n * Returns an action object used to toggle a feature flag.\n *\n * @param {string} feature Feature name.\n *\n * @return {Object} Action object.\n */\nexport function toggleFeature( feature ) {\n\treturn {\n\t\ttype: 'TOGGLE_FEATURE',\n\t\tfeature,\n\t};\n}\n\n/**\n * Returns an action object used to toggle the width of the editing canvas.\n *\n * @param {string} deviceType\n *\n * @return {Object} Action object.\n */\nexport function __experimentalSetPreviewDeviceType( deviceType ) {\n\treturn {\n\t\ttype: 'SET_PREVIEW_DEVICE_TYPE',\n\t\tdeviceType,\n\t};\n}\n\n/**\n * Returns an action object used to set a template.\n *\n * @param {number} templateId The template ID.\n * @param {string} templateSlug The template slug.\n * @return {Object} Action object.\n */\nexport function* setTemplate( templateId, templateSlug ) {\n\tconst pageContext = { templateSlug };\n\tif ( ! templateSlug ) {\n\t\tconst template = yield controls.resolveSelect(\n\t\t\tcoreStore,\n\t\t\t'getEntityRecord',\n\t\t\t'postType',\n\t\t\t'wp_template',\n\t\t\ttemplateId\n\t\t);\n\t\tpageContext.templateSlug = template?.slug;\n\t}\n\treturn {\n\t\ttype: 'SET_TEMPLATE',\n\t\ttemplateId,\n\t\tpage: { context: pageContext },\n\t};\n}\n\n/**\n * Adds a new template, and sets it as the current template.\n *\n * @param {Object} template The template.\n *\n * @return {Object} Action object used to set the current template.\n */\nexport function* addTemplate( template ) {\n\tconst newTemplate = yield controls.dispatch(\n\t\tcoreStore,\n\t\t'saveEntityRecord',\n\t\t'postType',\n\t\t'wp_template',\n\t\ttemplate\n\t);\n\n\tif ( template.content ) {\n\t\tyield controls.dispatch(\n\t\t\tcoreStore,\n\t\t\t'editEntityRecord',\n\t\t\t'postType',\n\t\t\t'wp_template',\n\t\t\tnewTemplate.id,\n\t\t\t{ blocks: parse( template.content ) },\n\t\t\t{ undoIgnore: true }\n\t\t);\n\t}\n\n\treturn {\n\t\ttype: 'SET_TEMPLATE',\n\t\ttemplateId: newTemplate.id,\n\t\tpage: { context: { templateSlug: newTemplate.slug } },\n\t};\n}\n\n/**\n * Removes a template.\n *\n * @param {Object} template The template object.\n */\nexport function* removeTemplate( template ) {\n\ttry {\n\t\tyield controls.dispatch(\n\t\t\tcoreStore,\n\t\t\t'deleteEntityRecord',\n\t\t\t'postType',\n\t\t\ttemplate.type,\n\t\t\ttemplate.id,\n\t\t\t{ force: true }\n\t\t);\n\n\t\tconst lastError = yield controls.select(\n\t\t\tcoreStore,\n\t\t\t'getLastEntityDeleteError',\n\t\t\t'postType',\n\t\t\ttemplate.type,\n\t\t\ttemplate.id\n\t\t);\n\n\t\tif ( lastError ) {\n\t\t\tthrow lastError;\n\t\t}\n\n\t\tyield controls.dispatch(\n\t\t\tnoticesStore,\n\t\t\t'createSuccessNotice',\n\t\t\tsprintf(\n\t\t\t\t/* translators: The template/part's name. */\n\t\t\t\t__( '\"%s\" deleted.' ),\n\t\t\t\ttemplate.title.rendered\n\t\t\t),\n\t\t\t{ type: 'snackbar' }\n\t\t);\n\t} catch ( error ) {\n\t\tconst errorMessage =\n\t\t\terror.message && error.code !== 'unknown_error'\n\t\t\t\t? error.message\n\t\t\t\t: __( 'An error occurred while deleting the template.' );\n\n\t\tyield controls.dispatch(\n\t\t\tnoticesStore,\n\t\t\t'createErrorNotice',\n\t\t\terrorMessage,\n\t\t\t{ type: 'snackbar' }\n\t\t);\n\t}\n}\n\n/**\n * Returns an action object used to set a template part.\n *\n * @param {string} templatePartId The template part ID.\n *\n * @return {Object} Action object.\n */\nexport function setTemplatePart( templatePartId ) {\n\treturn {\n\t\ttype: 'SET_TEMPLATE_PART',\n\t\ttemplatePartId,\n\t};\n}\n\n/**\n * Updates the homeTemplateId state with the templateId of the page resolved\n * from the given path.\n *\n * @param {number} homeTemplateId The template ID for the homepage.\n */\nexport function setHomeTemplateId( homeTemplateId ) {\n\treturn {\n\t\ttype: 'SET_HOME_TEMPLATE',\n\t\thomeTemplateId,\n\t};\n}\n\n/**\n * Resolves the template for a page and displays both. If no path is given, attempts\n * to use the postId to generate a path like `?p=${ postId }`.\n *\n * @param {Object} page The page object.\n * @param {string} page.type The page type.\n * @param {string} page.slug The page slug.\n * @param {string} page.path The page path.\n * @param {Object} page.context The page context.\n *\n * @return {number} The resolved template ID for the page route.\n */\nexport function* setPage( page ) {\n\tif ( ! page.path && page.context?.postId ) {\n\t\tconst entity = yield controls.resolveSelect(\n\t\t\tcoreStore,\n\t\t\t'getEntityRecord',\n\t\t\t'postType',\n\t\t\tpage.context.postType || 'post',\n\t\t\tpage.context.postId\n\t\t);\n\t\t// If the entity is undefined for some reason, path will resolve to \"/\"\n\t\tpage.path = getPathAndQueryString( entity?.link );\n\t}\n\tconst { id: templateId, slug: templateSlug } = yield controls.resolveSelect(\n\t\tcoreStore,\n\t\t'__experimentalGetTemplateForLink',\n\t\tpage.path\n\t);\n\tyield {\n\t\ttype: 'SET_PAGE',\n\t\tpage: ! templateSlug\n\t\t\t? page\n\t\t\t: {\n\t\t\t\t\t...page,\n\t\t\t\t\tcontext: {\n\t\t\t\t\t\t...page.context,\n\t\t\t\t\t\ttemplateSlug,\n\t\t\t\t\t},\n\t\t\t },\n\t\ttemplateId,\n\t};\n\treturn templateId;\n}\n\n/**\n * Returns an action object used to set the active navigation panel menu.\n *\n * @param {string} menu Menu prop of active menu.\n *\n * @return {Object} Action object.\n */\nexport function setNavigationPanelActiveMenu( menu ) {\n\treturn {\n\t\ttype: 'SET_NAVIGATION_PANEL_ACTIVE_MENU',\n\t\tmenu,\n\t};\n}\n\n/**\n * Opens the navigation panel and sets its active menu at the same time.\n *\n * @param {string} menu Identifies the menu to open.\n */\nexport function openNavigationPanelToMenu( menu ) {\n\treturn {\n\t\ttype: 'OPEN_NAVIGATION_PANEL_TO_MENU',\n\t\tmenu,\n\t};\n}\n\n/**\n * Sets whether the navigation panel should be open.\n *\n * @param {boolean} isOpen If true, opens the nav panel. If false, closes it. It\n * does not toggle the state, but sets it directly.\n */\nexport function setIsNavigationPanelOpened( isOpen ) {\n\treturn {\n\t\ttype: 'SET_IS_NAVIGATION_PANEL_OPENED',\n\t\tisOpen,\n\t};\n}\n\n/**\n * Returns an action object used to open/close the inserter.\n *\n * @param {boolean|Object} value Whether the inserter should be\n * opened (true) or closed (false).\n * To specify an insertion point,\n * use an object.\n * @param {string} value.rootClientId The root client ID to insert at.\n * @param {number} value.insertionIndex The index to insert at.\n *\n * @return {Object} Action object.\n */\nexport function setIsInserterOpened( value ) {\n\treturn {\n\t\ttype: 'SET_IS_INSERTER_OPENED',\n\t\tvalue,\n\t};\n}\n\n/**\n * Returns an action object used to update the settings.\n *\n * @param {Object} settings New settings.\n *\n * @return {Object} Action object.\n */\nexport function updateSettings( settings ) {\n\treturn {\n\t\ttype: 'UPDATE_SETTINGS',\n\t\tsettings,\n\t};\n}\n\n/**\n * Sets whether the list view panel should be open.\n *\n * @param {boolean} isOpen If true, opens the list view. If false, closes it.\n * It does not toggle the state, but sets it directly.\n */\nexport function setIsListViewOpened( isOpen ) {\n\treturn {\n\t\ttype: 'SET_IS_LIST_VIEW_OPENED',\n\t\tisOpen,\n\t};\n}\n\n/**\n * Reverts a template to its original theme-provided file.\n *\n * @param {Object} template The template to revert.\n * @param {Object} [options]\n * @param {boolean} [options.allowUndo] Whether to allow the user to undo\n * reverting the template. Default true.\n */\nexport function* revertTemplate( template, { allowUndo = true } = {} ) {\n\tif ( ! isTemplateRevertable( template ) ) {\n\t\tyield controls.dispatch(\n\t\t\tnoticesStore,\n\t\t\t'createErrorNotice',\n\t\t\t__( 'This template is not revertable.' ),\n\t\t\t{ type: 'snackbar' }\n\t\t);\n\t\treturn;\n\t}\n\n\ttry {\n\t\tconst templateEntity = yield controls.select(\n\t\t\tcoreStore,\n\t\t\t'getEntity',\n\t\t\t'postType',\n\t\t\ttemplate.type\n\t\t);\n\t\tif ( ! templateEntity ) {\n\t\t\tyield controls.dispatch(\n\t\t\t\tnoticesStore,\n\t\t\t\t'createErrorNotice',\n\t\t\t\t__(\n\t\t\t\t\t'The editor has encountered an unexpected error. Please reload.'\n\t\t\t\t),\n\t\t\t\t{ type: 'snackbar' }\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\n\t\tconst fileTemplatePath = addQueryArgs(\n\t\t\t`${ templateEntity.baseURL }/${ template.id }`,\n\t\t\t{ context: 'edit', source: 'theme' }\n\t\t);\n\t\tconst fileTemplate = yield apiFetch( { path: fileTemplatePath } );\n\t\tif ( ! fileTemplate ) {\n\t\t\tyield controls.dispatch(\n\t\t\t\tnoticesStore,\n\t\t\t\t'createErrorNotice',\n\t\t\t\t__(\n\t\t\t\t\t'The editor has encountered an unexpected error. Please reload.'\n\t\t\t\t),\n\t\t\t\t{ type: 'snackbar' }\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\n\t\tconst serializeBlocks = ( { blocks: blocksForSerialization = [] } ) =>\n\t\t\t__unstableSerializeAndClean( blocksForSerialization );\n\t\tconst edited = yield controls.select(\n\t\t\tcoreStore,\n\t\t\t'getEditedEntityRecord',\n\t\t\t'postType',\n\t\t\ttemplate.type,\n\t\t\ttemplate.id\n\t\t);\n\t\t// We are fixing up the undo level here to make sure we can undo\n\t\t// the revert in the header toolbar correctly.\n\t\tyield controls.dispatch(\n\t\t\tcoreStore,\n\t\t\t'editEntityRecord',\n\t\t\t'postType',\n\t\t\ttemplate.type,\n\t\t\ttemplate.id,\n\t\t\t{\n\t\t\t\tcontent: serializeBlocks, // required to make the `undo` behave correctly\n\t\t\t\tblocks: edited.blocks, // required to revert the blocks in the editor\n\t\t\t\tsource: 'custom', // required to avoid turning the editor into a dirty state\n\t\t\t},\n\t\t\t{\n\t\t\t\tundoIgnore: true, // required to merge this edit with the last undo level\n\t\t\t}\n\t\t);\n\n\t\tconst blocks = parse( fileTemplate?.content?.raw );\n\t\tyield controls.dispatch(\n\t\t\tcoreStore,\n\t\t\t'editEntityRecord',\n\t\t\t'postType',\n\t\t\ttemplate.type,\n\t\t\tfileTemplate.id,\n\t\t\t{\n\t\t\t\tcontent: serializeBlocks,\n\t\t\t\tblocks,\n\t\t\t\tsource: 'theme',\n\t\t\t}\n\t\t);\n\n\t\tif ( allowUndo ) {\n\t\t\tconst undoRevert = async () => {\n\t\t\t\tawait dispatch( coreStore ).editEntityRecord(\n\t\t\t\t\t'postType',\n\t\t\t\t\ttemplate.type,\n\t\t\t\t\tedited.id,\n\t\t\t\t\t{\n\t\t\t\t\t\tcontent: serializeBlocks,\n\t\t\t\t\t\tblocks: edited.blocks,\n\t\t\t\t\t\tsource: 'custom',\n\t\t\t\t\t}\n\t\t\t\t);\n\t\t\t};\n\t\t\tyield controls.dispatch(\n\t\t\t\tnoticesStore,\n\t\t\t\t'createSuccessNotice',\n\t\t\t\t__( 'Template reverted.' ),\n\t\t\t\t{\n\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t\tactions: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tlabel: __( 'Undo' ),\n\t\t\t\t\t\t\tonClick: undoRevert,\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t}\n\t\t\t);\n\t\t} else {\n\t\t\tyield controls.dispatch(\n\t\t\t\tnoticesStore,\n\t\t\t\t'createSuccessNotice',\n\t\t\t\t__( 'Template reverted.' )\n\t\t\t);\n\t\t}\n\t} catch ( error ) {\n\t\tconst errorMessage =\n\t\t\terror.message && error.code !== 'unknown_error'\n\t\t\t\t? error.message\n\t\t\t\t: __( 'Template revert failed. Please reload.' );\n\t\tyield controls.dispatch(\n\t\t\tnoticesStore,\n\t\t\t'createErrorNotice',\n\t\t\terrorMessage,\n\t\t\t{ type: 'snackbar' }\n\t\t);\n\t}\n}\n/**\n * Returns an action object used in signalling that the user opened an editor sidebar.\n *\n * @param {?string} name Sidebar name to be opened.\n *\n * @yield {Object} Action object.\n */\nexport function* openGeneralSidebar( name ) {\n\tyield controls.dispatch(\n\t\tinterfaceStore,\n\t\t'enableComplementaryArea',\n\t\teditSiteStoreName,\n\t\tname\n\t);\n}\n\n/**\n * Returns an action object signalling that the user closed the sidebar.\n *\n * @yield {Object} Action object.\n */\nexport function* closeGeneralSidebar() {\n\tyield controls.dispatch(\n\t\tinterfaceStore,\n\t\t'disableComplementaryArea',\n\t\teditSiteStoreName\n\t);\n}\n\nexport function* switchEditorMode( mode ) {\n\tyield {\n\t\ttype: 'SWITCH_MODE',\n\t\tmode,\n\t};\n\n\t// Unselect blocks when we switch to a non visual mode.\n\tif ( mode !== 'visual' ) {\n\t\tyield controls.dispatch( blockEditorStore.name, 'clearSelectedBlock' );\n\t}\n\tconst messages = {\n\t\tvisual: __( 'Visual editor selected' ),\n\t\tmosaic: __( 'Mosaic view selected' ),\n\t};\n\tif ( messages[ mode ] ) {\n\t\tspeak( messages[ mode ], 'assertive' );\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/edit-site/src/store/actions.js"],"names":["toggleFeature","feature","type","__experimentalSetPreviewDeviceType","deviceType","setTemplate","templateId","templateSlug","dispatch","registry","template","resolveSelect","coreStore","getEntityRecord","slug","page","context","addTemplate","newTemplate","saveEntityRecord","content","editEntityRecord","id","blocks","undoIgnore","removeTemplate","deleteEntityRecord","force","lastError","select","getLastEntityDeleteError","noticesStore","createSuccessNotice","title","rendered","error","errorMessage","message","code","createErrorNotice","setTemplatePart","templatePartId","setHomeTemplateId","homeTemplateId","setPage","path","postId","entity","postType","link","__experimentalGetTemplateForLink","setNavigationPanelActiveMenu","menu","openNavigationPanelToMenu","setIsNavigationPanelOpened","isOpen","setIsInserterOpened","value","updateSettings","settings","setIsListViewOpened","revertTemplate","allowUndo","templateEntity","getEntity","fileTemplatePath","baseURL","source","fileTemplate","serializeBlocks","blocksForSerialization","edited","getEditedEntityRecord","raw","undoRevert","actions","label","onClick","openGeneralSidebar","name","interfaceStore","enableComplementaryArea","editSiteStoreName","closeGeneralSidebar","disableComplementaryArea","switchEditorMode","mode","blockEditorStore","clearSelectedBlock"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAGA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAKA;;AACA;;AAjBA;AACA;AACA;;AAWA;AACA;AACA;;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,aAAT,CAAwBC,OAAxB,EAAkC;AACxC,SAAO;AACNC,IAAAA,IAAI,EAAE,gBADA;AAEND,IAAAA;AAFM,GAAP;AAIA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASE,kCAAT,CAA6CC,UAA7C,EAA0D;AAChE,SAAO;AACNF,IAAAA,IAAI,EAAE,yBADA;AAENE,IAAAA;AAFM,GAAP;AAIA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,MAAMC,WAAW,GAAG,CAAEC,UAAF,EAAcC,YAAd,KAAgC,cAGpD;AAAA,MAH4D;AAClEC,IAAAA,QADkE;AAElEC,IAAAA;AAFkE,GAG5D;;AACN,MAAK,CAAEF,YAAP,EAAsB;AACrB,UAAMG,QAAQ,GAAG,MAAMD,QAAQ,CAC7BE,aADqB,CACNC,eADM,EAErBC,eAFqB,CAEJ,UAFI,EAEQ,aAFR,EAEuBP,UAFvB,CAAvB;AAGAC,IAAAA,YAAY,GAAGG,QAAH,aAAGA,QAAH,uBAAGA,QAAQ,CAAEI,IAAzB;AACA;;AAEDN,EAAAA,QAAQ,CAAE;AACTN,IAAAA,IAAI,EAAE,cADG;AAETI,IAAAA,UAFS;AAGTS,IAAAA,IAAI,EAAE;AAAEC,MAAAA,OAAO,EAAE;AAAET,QAAAA;AAAF;AAAX;AAHG,GAAF,CAAR;AAKA,CAhBM;AAkBP;AACA;AACA;AACA;AACA;AACA;AACA;;;;;AACO,MAAMU,WAAW,GAAKP,QAAF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,MAAM4E,kBAAkB,GAAKC,IAAF,IAAY,SAAoB;AAAA,MAAlB;AAAEtE,IAAAA;AAAF,GAAkB;AACjEA,EAAAA,QAAQ,CACND,QADF,CACYwE,gBADZ,EAEEC,uBAFF,CAE2BC,qBAF3B,EAE8CH,IAF9C;AAGA,CAJM;AAMP;AACA;AACA;;;;;AACO,MAAMI,mBAAmB,GAAG,MAAM,SAAoB;AAAA,MAAlB;AAAE1E,IAAAA;AAAF,GAAkB;AAC5DA,EAAAA,QAAQ,CACND,QADF,CACYwE,gBADZ,EAEEI,wBAFF,CAE4BF,qBAF5B;AAGA,CAJM;;;;AAMA,MAAMG,gBAAgB,GAAKC,IAAF,IAAY,SAA8B;AAAA,MAA5B;AAAE9E,IAAAA,QAAF;AAAYC,IAAAA;AAAZ,GAA4B;AACzED,EAAAA,QAAQ,CAAE;AAAEN,IAAAA,IAAI,EAAE,aAAR;AAAuBoF,IAAAA;AAAvB,GAAF,CAAR,CADyE,CAGzE;;AACA,MAAKA,IAAI,KAAK,QAAd,EAAyB;AACxB7E,IAAAA,QAAQ,CAACD,QAAT,CAAmB+E,kBAAnB,EAAsCC,kBAAtC;AACA;;AAED,MAAKF,IAAI,KAAK,QAAd,EAAyB;AACxB,qBAAO,cAAI,wBAAJ,CAAP,EAAuC,WAAvC;AACA,GAFD,MAEO,IAAKA,IAAI,KAAK,QAAd,EAAyB;AAC/B,qBAAO,cAAI,sBAAJ,CAAP,EAAqC,WAArC;AACA;AACD,CAbM","sourcesContent":["/**\n * WordPress dependencies\n */\nimport apiFetch from '@wordpress/api-fetch';\nimport { parse, __unstableSerializeAndClean } from '@wordpress/blocks';\nimport { addQueryArgs, getPathAndQueryString } from '@wordpress/url';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { store as interfaceStore } from '@wordpress/interface';\nimport { store as blockEditorStore } from '@wordpress/block-editor';\nimport { speak } from '@wordpress/a11y';\n\n/**\n * Internal dependencies\n */\nimport { STORE_NAME as editSiteStoreName } from './constants';\nimport isTemplateRevertable from '../utils/is-template-revertable';\n\n/**\n * Action that toggles a feature flag.\n *\n * @param {string} feature Feature name.\n *\n * @return {Object} Action object.\n */\nexport function toggleFeature( feature ) {\n\treturn {\n\t\ttype: 'TOGGLE_FEATURE',\n\t\tfeature,\n\t};\n}\n\n/**\n * Action that changes the width of the editing canvas.\n *\n * @param {string} deviceType\n *\n * @return {Object} Action object.\n */\nexport function __experimentalSetPreviewDeviceType( deviceType ) {\n\treturn {\n\t\ttype: 'SET_PREVIEW_DEVICE_TYPE',\n\t\tdeviceType,\n\t};\n}\n\n/**\n * Action that sets a template, optionally fetching it from REST API.\n *\n * @param {number} templateId The template ID.\n * @param {string} templateSlug The template slug.\n * @return {Object} Action object.\n */\nexport const setTemplate = ( templateId, templateSlug ) => async ( {\n\tdispatch,\n\tregistry,\n} ) => {\n\tif ( ! templateSlug ) {\n\t\tconst template = await registry\n\t\t\t.resolveSelect( coreStore )\n\t\t\t.getEntityRecord( 'postType', 'wp_template', templateId );\n\t\ttemplateSlug = template?.slug;\n\t}\n\n\tdispatch( {\n\t\ttype: 'SET_TEMPLATE',\n\t\ttemplateId,\n\t\tpage: { context: { templateSlug } },\n\t} );\n};\n\n/**\n * Action that adds a new template and sets it as the current template.\n *\n * @param {Object} template The template.\n *\n * @return {Object} Action object used to set the current template.\n */\nexport const addTemplate = ( template ) => async ( { dispatch, registry } ) => {\n\tconst newTemplate = await registry\n\t\t.dispatch( coreStore )\n\t\t.saveEntityRecord( 'postType', 'wp_template', template );\n\n\tif ( template.content ) {\n\t\tregistry\n\t\t\t.dispatch( coreStore )\n\t\t\t.editEntityRecord(\n\t\t\t\t'postType',\n\t\t\t\t'wp_template',\n\t\t\t\tnewTemplate.id,\n\t\t\t\t{ blocks: parse( template.content ) },\n\t\t\t\t{ undoIgnore: true }\n\t\t\t);\n\t}\n\n\tdispatch( {\n\t\ttype: 'SET_TEMPLATE',\n\t\ttemplateId: newTemplate.id,\n\t\tpage: { context: { templateSlug: newTemplate.slug } },\n\t} );\n};\n\n/**\n * Action that removes a template.\n *\n * @param {Object} template The template object.\n */\nexport const removeTemplate = ( template ) => async ( { registry } ) => {\n\ttry {\n\t\tawait registry\n\t\t\t.dispatch( coreStore )\n\t\t\t.deleteEntityRecord( 'postType', template.type, template.id, {\n\t\t\t\tforce: true,\n\t\t\t} );\n\n\t\tconst lastError = registry\n\t\t\t.select( coreStore )\n\t\t\t.getLastEntityDeleteError( 'postType', template.type, template.id );\n\n\t\tif ( lastError ) {\n\t\t\tthrow lastError;\n\t\t}\n\n\t\tregistry.dispatch( noticesStore ).createSuccessNotice(\n\t\t\tsprintf(\n\t\t\t\t/* translators: The template/part's name. */\n\t\t\t\t__( '\"%s\" deleted.' ),\n\t\t\t\ttemplate.title.rendered\n\t\t\t),\n\t\t\t{ type: 'snackbar' }\n\t\t);\n\t} catch ( error ) {\n\t\tconst errorMessage =\n\t\t\terror.message && error.code !== 'unknown_error'\n\t\t\t\t? error.message\n\t\t\t\t: __( 'An error occurred while deleting the template.' );\n\n\t\tregistry\n\t\t\t.dispatch( noticesStore )\n\t\t\t.createErrorNotice( errorMessage, { type: 'snackbar' } );\n\t}\n};\n\n/**\n * Action that sets a template part.\n *\n * @param {string} templatePartId The template part ID.\n *\n * @return {Object} Action object.\n */\nexport function setTemplatePart( templatePartId ) {\n\treturn {\n\t\ttype: 'SET_TEMPLATE_PART',\n\t\ttemplatePartId,\n\t};\n}\n\n/**\n * Action that sets the home template ID to the template ID of the page resolved\n * from a given path.\n *\n * @param {number} homeTemplateId The template ID for the homepage.\n */\nexport function setHomeTemplateId( homeTemplateId ) {\n\treturn {\n\t\ttype: 'SET_HOME_TEMPLATE',\n\t\thomeTemplateId,\n\t};\n}\n\n/**\n * Resolves the template for a page and displays both. If no path is given, attempts\n * to use the postId to generate a path like `?p=${ postId }`.\n *\n * @param {Object} page The page object.\n * @param {string} page.type The page type.\n * @param {string} page.slug The page slug.\n * @param {string} page.path The page path.\n * @param {Object} page.context The page context.\n *\n * @return {number} The resolved template ID for the page route.\n */\nexport const setPage = ( page ) => async ( { dispatch, registry } ) => {\n\tif ( ! page.path && page.context?.postId ) {\n\t\tconst entity = await registry\n\t\t\t.resolveSelect( coreStore )\n\t\t\t.getEntityRecord(\n\t\t\t\t'postType',\n\t\t\t\tpage.context.postType || 'post',\n\t\t\t\tpage.context.postId\n\t\t\t);\n\t\t// If the entity is undefined for some reason, path will resolve to \"/\"\n\t\tpage.path = getPathAndQueryString( entity?.link );\n\t}\n\n\tconst template = await registry\n\t\t.resolveSelect( coreStore )\n\t\t.__experimentalGetTemplateForLink( page.path );\n\n\tif ( ! template ) {\n\t\treturn;\n\t}\n\n\tdispatch( {\n\t\ttype: 'SET_PAGE',\n\t\tpage: template.slug\n\t\t\t? {\n\t\t\t\t\t...page,\n\t\t\t\t\tcontext: {\n\t\t\t\t\t\t...page.context,\n\t\t\t\t\t\ttemplateSlug: template.slug,\n\t\t\t\t\t},\n\t\t\t }\n\t\t\t: page,\n\t\ttemplateId: template.id,\n\t} );\n\n\treturn template.id;\n};\n\n/**\n * Action that sets the active navigation panel menu.\n *\n * @param {string} menu Menu prop of active menu.\n *\n * @return {Object} Action object.\n */\nexport function setNavigationPanelActiveMenu( menu ) {\n\treturn {\n\t\ttype: 'SET_NAVIGATION_PANEL_ACTIVE_MENU',\n\t\tmenu,\n\t};\n}\n\n/**\n * Opens the navigation panel and sets its active menu at the same time.\n *\n * @param {string} menu Identifies the menu to open.\n */\nexport function openNavigationPanelToMenu( menu ) {\n\treturn {\n\t\ttype: 'OPEN_NAVIGATION_PANEL_TO_MENU',\n\t\tmenu,\n\t};\n}\n\n/**\n * Sets whether the navigation panel should be open.\n *\n * @param {boolean} isOpen If true, opens the nav panel. If false, closes it. It\n * does not toggle the state, but sets it directly.\n */\nexport function setIsNavigationPanelOpened( isOpen ) {\n\treturn {\n\t\ttype: 'SET_IS_NAVIGATION_PANEL_OPENED',\n\t\tisOpen,\n\t};\n}\n\n/**\n * Opens or closes the inserter.\n *\n * @param {boolean|Object} value Whether the inserter should be\n * opened (true) or closed (false).\n * To specify an insertion point,\n * use an object.\n * @param {string} value.rootClientId The root client ID to insert at.\n * @param {number} value.insertionIndex The index to insert at.\n *\n * @return {Object} Action object.\n */\nexport function setIsInserterOpened( value ) {\n\treturn {\n\t\ttype: 'SET_IS_INSERTER_OPENED',\n\t\tvalue,\n\t};\n}\n\n/**\n * Returns an action object used to update the settings.\n *\n * @param {Object} settings New settings.\n *\n * @return {Object} Action object.\n */\nexport function updateSettings( settings ) {\n\treturn {\n\t\ttype: 'UPDATE_SETTINGS',\n\t\tsettings,\n\t};\n}\n\n/**\n * Sets whether the list view panel should be open.\n *\n * @param {boolean} isOpen If true, opens the list view. If false, closes it.\n * It does not toggle the state, but sets it directly.\n */\nexport function setIsListViewOpened( isOpen ) {\n\treturn {\n\t\ttype: 'SET_IS_LIST_VIEW_OPENED',\n\t\tisOpen,\n\t};\n}\n\n/**\n * Reverts a template to its original theme-provided file.\n *\n * @param {Object} template The template to revert.\n * @param {Object} [options]\n * @param {boolean} [options.allowUndo] Whether to allow the user to undo\n * reverting the template. Default true.\n */\nexport const revertTemplate = (\n\ttemplate,\n\t{ allowUndo = true } = {}\n) => async ( { registry } ) => {\n\tif ( ! isTemplateRevertable( template ) ) {\n\t\tregistry\n\t\t\t.dispatch( noticesStore )\n\t\t\t.createErrorNotice( __( 'This template is not revertable.' ), {\n\t\t\t\ttype: 'snackbar',\n\t\t\t} );\n\t\treturn;\n\t}\n\n\ttry {\n\t\tconst templateEntity = registry\n\t\t\t.select( coreStore )\n\t\t\t.getEntity( 'postType', template.type );\n\n\t\tif ( ! templateEntity ) {\n\t\t\tregistry\n\t\t\t\t.dispatch( noticesStore )\n\t\t\t\t.createErrorNotice(\n\t\t\t\t\t__(\n\t\t\t\t\t\t'The editor has encountered an unexpected error. Please reload.'\n\t\t\t\t\t),\n\t\t\t\t\t{ type: 'snackbar' }\n\t\t\t\t);\n\t\t\treturn;\n\t\t}\n\n\t\tconst fileTemplatePath = addQueryArgs(\n\t\t\t`${ templateEntity.baseURL }/${ template.id }`,\n\t\t\t{ context: 'edit', source: 'theme' }\n\t\t);\n\n\t\tconst fileTemplate = await apiFetch( { path: fileTemplatePath } );\n\t\tif ( ! fileTemplate ) {\n\t\t\tregistry\n\t\t\t\t.dispatch( noticesStore )\n\t\t\t\t.createErrorNotice(\n\t\t\t\t\t__(\n\t\t\t\t\t\t'The editor has encountered an unexpected error. Please reload.'\n\t\t\t\t\t),\n\t\t\t\t\t{ type: 'snackbar' }\n\t\t\t\t);\n\t\t\treturn;\n\t\t}\n\n\t\tconst serializeBlocks = ( { blocks: blocksForSerialization = [] } ) =>\n\t\t\t__unstableSerializeAndClean( blocksForSerialization );\n\n\t\tconst edited = registry\n\t\t\t.select( coreStore )\n\t\t\t.getEditedEntityRecord( 'postType', template.type, template.id );\n\n\t\t// We are fixing up the undo level here to make sure we can undo\n\t\t// the revert in the header toolbar correctly.\n\t\tregistry.dispatch( coreStore ).editEntityRecord(\n\t\t\t'postType',\n\t\t\ttemplate.type,\n\t\t\ttemplate.id,\n\t\t\t{\n\t\t\t\tcontent: serializeBlocks, // required to make the `undo` behave correctly\n\t\t\t\tblocks: edited.blocks, // required to revert the blocks in the editor\n\t\t\t\tsource: 'custom', // required to avoid turning the editor into a dirty state\n\t\t\t},\n\t\t\t{\n\t\t\t\tundoIgnore: true, // required to merge this edit with the last undo level\n\t\t\t}\n\t\t);\n\n\t\tconst blocks = parse( fileTemplate?.content?.raw );\n\t\tregistry\n\t\t\t.dispatch( coreStore )\n\t\t\t.editEntityRecord( 'postType', template.type, fileTemplate.id, {\n\t\t\t\tcontent: serializeBlocks,\n\t\t\t\tblocks,\n\t\t\t\tsource: 'theme',\n\t\t\t} );\n\n\t\tif ( allowUndo ) {\n\t\t\tconst undoRevert = () => {\n\t\t\t\tregistry\n\t\t\t\t\t.dispatch( coreStore )\n\t\t\t\t\t.editEntityRecord( 'postType', template.type, edited.id, {\n\t\t\t\t\t\tcontent: serializeBlocks,\n\t\t\t\t\t\tblocks: edited.blocks,\n\t\t\t\t\t\tsource: 'custom',\n\t\t\t\t\t} );\n\t\t\t};\n\n\t\t\tregistry\n\t\t\t\t.dispatch( noticesStore )\n\t\t\t\t.createSuccessNotice( __( 'Template reverted.' ), {\n\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t\tactions: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tlabel: __( 'Undo' ),\n\t\t\t\t\t\t\tonClick: undoRevert,\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t} );\n\t\t} else {\n\t\t\tregistry\n\t\t\t\t.dispatch( noticesStore )\n\t\t\t\t.createSuccessNotice( __( 'Template reverted.' ) );\n\t\t}\n\t} catch ( error ) {\n\t\tconst errorMessage =\n\t\t\terror.message && error.code !== 'unknown_error'\n\t\t\t\t? error.message\n\t\t\t\t: __( 'Template revert failed. Please reload.' );\n\t\tregistry\n\t\t\t.dispatch( noticesStore )\n\t\t\t.createErrorNotice( errorMessage, { type: 'snackbar' } );\n\t}\n};\n/**\n * Action that opens an editor sidebar.\n *\n * @param {?string} name Sidebar name to be opened.\n */\nexport const openGeneralSidebar = ( name ) => ( { registry } ) => {\n\tregistry\n\t\t.dispatch( interfaceStore )\n\t\t.enableComplementaryArea( editSiteStoreName, name );\n};\n\n/**\n * Action that closes the sidebar.\n */\nexport const closeGeneralSidebar = () => ( { registry } ) => {\n\tregistry\n\t\t.dispatch( interfaceStore )\n\t\t.disableComplementaryArea( editSiteStoreName );\n};\n\nexport const switchEditorMode = ( mode ) => ( { dispatch, registry } ) => {\n\tdispatch( { type: 'SWITCH_MODE', mode } );\n\n\t// Unselect blocks when we switch to a non visual mode.\n\tif ( mode !== 'visual' ) {\n\t\tregistry.dispatch( blockEditorStore ).clearSelectedBlock();\n\t}\n\n\tif ( mode === 'visual' ) {\n\t\tspeak( __( 'Visual editor selected' ), 'assertive' );\n\t} else if ( mode === 'mosaic' ) {\n\t\tspeak( __( 'Mosaic view selected' ), 'assertive' );\n\t}\n};\n"]}
|