@wordpress/edit-site 4.7.0 → 4.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2 -0
- package/build/components/add-new-template/new-template.js.map +1 -1
- package/build/components/block-editor/block-inspector-button.js.map +1 -1
- package/build/components/block-editor/index.js.map +1 -1
- package/build/components/edit-template-part-menu-button/index.js.map +1 -1
- package/build/components/editor/index.js.map +1 -1
- package/build/components/global-styles/global-styles-provider.js.map +1 -1
- package/build/components/global-styles/gradients-palette-panel.js +3 -7
- package/build/components/global-styles/gradients-palette-panel.js.map +1 -1
- package/build/components/global-styles/hooks.js.map +1 -1
- package/build/components/global-styles/screen-block-list.js.map +1 -1
- package/build/components/global-styles/screen-root.js.map +1 -1
- package/build/components/global-styles/screen-style-variations.js +9 -1
- package/build/components/global-styles/screen-style-variations.js.map +1 -1
- package/build/components/header/index.js.map +1 -1
- package/build/components/header/mode-switcher/index.js.map +1 -1
- package/build/components/header/more-menu/copy-content-menu-item.js +1 -1
- package/build/components/header/more-menu/copy-content-menu-item.js.map +1 -1
- package/build/components/header/more-menu/site-export.js.map +1 -1
- package/build/components/keyboard-shortcuts/index.js.map +1 -1
- package/build/components/list/actions/index.js.map +1 -1
- package/build/components/list/actions/rename-menu-item.js.map +1 -1
- package/build/components/list/added-by.js.map +1 -1
- package/build/components/navigation-sidebar/index.js.map +1 -1
- package/build/components/save-button/index.js.map +1 -1
- package/build/components/sidebar/index.js.map +1 -1
- package/build/components/sidebar/navigation-menu-sidebar/navigation-inspector.js.map +1 -1
- package/build/components/sidebar/template-card/index.js.map +1 -1
- package/build/components/sidebar/template-card/template-areas.js.map +1 -1
- package/build/components/template-details/template-areas.js.map +1 -1
- package/build/components/template-part-converter/index.js.map +1 -1
- package/build/components/url-query-controller/index.js.map +1 -1
- package/build/store/actions.js.map +1 -1
- package/build/store/selectors.js.map +1 -1
- package/build-module/components/add-new-template/new-template.js.map +1 -1
- package/build-module/components/block-editor/block-inspector-button.js.map +1 -1
- package/build-module/components/block-editor/index.js.map +1 -1
- package/build-module/components/edit-template-part-menu-button/index.js.map +1 -1
- package/build-module/components/editor/index.js.map +1 -1
- package/build-module/components/global-styles/global-styles-provider.js.map +1 -1
- package/build-module/components/global-styles/gradients-palette-panel.js +3 -5
- package/build-module/components/global-styles/gradients-palette-panel.js.map +1 -1
- package/build-module/components/global-styles/hooks.js.map +1 -1
- package/build-module/components/global-styles/screen-block-list.js.map +1 -1
- package/build-module/components/global-styles/screen-root.js.map +1 -1
- package/build-module/components/global-styles/screen-style-variations.js +9 -1
- package/build-module/components/global-styles/screen-style-variations.js.map +1 -1
- package/build-module/components/header/index.js.map +1 -1
- package/build-module/components/header/mode-switcher/index.js.map +1 -1
- package/build-module/components/header/more-menu/copy-content-menu-item.js +1 -1
- package/build-module/components/header/more-menu/copy-content-menu-item.js.map +1 -1
- package/build-module/components/header/more-menu/site-export.js.map +1 -1
- package/build-module/components/keyboard-shortcuts/index.js.map +1 -1
- package/build-module/components/list/actions/index.js.map +1 -1
- package/build-module/components/list/actions/rename-menu-item.js.map +1 -1
- package/build-module/components/list/added-by.js.map +1 -1
- package/build-module/components/navigation-sidebar/index.js.map +1 -1
- package/build-module/components/save-button/index.js.map +1 -1
- package/build-module/components/sidebar/index.js.map +1 -1
- package/build-module/components/sidebar/navigation-menu-sidebar/navigation-inspector.js.map +1 -1
- package/build-module/components/sidebar/template-card/index.js.map +1 -1
- package/build-module/components/sidebar/template-card/template-areas.js.map +1 -1
- package/build-module/components/template-details/template-areas.js.map +1 -1
- package/build-module/components/template-part-converter/index.js.map +1 -1
- package/build-module/components/url-query-controller/index.js.map +1 -1
- package/build-module/store/actions.js.map +1 -1
- package/build-module/store/selectors.js.map +1 -1
- package/build-style/style-rtl.css +3 -6
- package/build-style/style.css +3 -6
- package/package.json +29 -29
- package/src/components/add-new-template/new-template.js +2 -3
- package/src/components/block-editor/block-inspector-button.js +2 -3
- package/src/components/block-editor/index.js +4 -9
- package/src/components/edit-template-part-menu-button/index.js +2 -3
- package/src/components/editor/index.js +4 -5
- package/src/components/global-styles/global-styles-provider.js +4 -8
- package/src/components/global-styles/gradients-palette-panel.js +2 -5
- package/src/components/global-styles/hooks.js +4 -3
- package/src/components/global-styles/screen-block-list.js +4 -4
- package/src/components/global-styles/screen-root.js +4 -3
- package/src/components/global-styles/screen-style-variations.js +10 -4
- package/src/components/header/index.js +2 -3
- package/src/components/header/mode-switcher/index.js +4 -4
- package/src/components/header/more-menu/copy-content-menu-item.js +3 -4
- package/src/components/header/more-menu/site-export.js +2 -3
- package/src/components/keyboard-shortcuts/index.js +6 -10
- package/src/components/list/actions/index.js +2 -3
- package/src/components/list/actions/rename-menu-item.js +4 -6
- package/src/components/list/added-by.js +4 -3
- package/src/components/navigation-sidebar/index.js +2 -4
- package/src/components/save-button/index.js +2 -4
- package/src/components/sidebar/index.js +6 -6
- package/src/components/sidebar/navigation-menu-sidebar/navigation-inspector.js +6 -9
- package/src/components/sidebar/template-card/index.js +2 -3
- package/src/components/sidebar/template-card/template-areas.js +6 -6
- package/src/components/template-details/template-areas.js +6 -6
- package/src/components/template-part-converter/index.js +2 -3
- package/src/components/url-query-controller/index.js +2 -3
- package/src/store/actions.js +257 -233
- package/src/store/selectors.js +9 -10
package/src/store/actions.js
CHANGED
|
@@ -59,23 +59,22 @@ export function __experimentalSetPreviewDeviceType( deviceType ) {
|
|
|
59
59
|
* @param {string} templateSlug The template slug.
|
|
60
60
|
* @return {Object} Action object.
|
|
61
61
|
*/
|
|
62
|
-
export const setTemplate =
|
|
63
|
-
|
|
64
|
-
registry
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
}
|
|
62
|
+
export const setTemplate =
|
|
63
|
+
( templateId, templateSlug ) =>
|
|
64
|
+
async ( { dispatch, registry } ) => {
|
|
65
|
+
if ( ! templateSlug ) {
|
|
66
|
+
const template = await registry
|
|
67
|
+
.resolveSelect( coreStore )
|
|
68
|
+
.getEntityRecord( 'postType', 'wp_template', templateId );
|
|
69
|
+
templateSlug = template?.slug;
|
|
70
|
+
}
|
|
72
71
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
};
|
|
72
|
+
dispatch( {
|
|
73
|
+
type: 'SET_TEMPLATE',
|
|
74
|
+
templateId,
|
|
75
|
+
page: { context: { templateSlug } },
|
|
76
|
+
} );
|
|
77
|
+
};
|
|
79
78
|
|
|
80
79
|
/**
|
|
81
80
|
* Action that adds a new template and sets it as the current template.
|
|
@@ -84,70 +83,78 @@ export const setTemplate = ( templateId, templateSlug ) => async ( {
|
|
|
84
83
|
*
|
|
85
84
|
* @return {Object} Action object used to set the current template.
|
|
86
85
|
*/
|
|
87
|
-
export const addTemplate =
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
if ( template.content ) {
|
|
93
|
-
registry
|
|
86
|
+
export const addTemplate =
|
|
87
|
+
( template ) =>
|
|
88
|
+
async ( { dispatch, registry } ) => {
|
|
89
|
+
const newTemplate = await registry
|
|
94
90
|
.dispatch( coreStore )
|
|
95
|
-
.
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
91
|
+
.saveEntityRecord( 'postType', 'wp_template', template );
|
|
92
|
+
|
|
93
|
+
if ( template.content ) {
|
|
94
|
+
registry
|
|
95
|
+
.dispatch( coreStore )
|
|
96
|
+
.editEntityRecord(
|
|
97
|
+
'postType',
|
|
98
|
+
'wp_template',
|
|
99
|
+
newTemplate.id,
|
|
100
|
+
{ blocks: parse( template.content ) },
|
|
101
|
+
{ undoIgnore: true }
|
|
102
|
+
);
|
|
103
|
+
}
|
|
103
104
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
};
|
|
105
|
+
dispatch( {
|
|
106
|
+
type: 'SET_TEMPLATE',
|
|
107
|
+
templateId: newTemplate.id,
|
|
108
|
+
page: { context: { templateSlug: newTemplate.slug } },
|
|
109
|
+
} );
|
|
110
|
+
};
|
|
110
111
|
|
|
111
112
|
/**
|
|
112
113
|
* Action that removes a template.
|
|
113
114
|
*
|
|
114
115
|
* @param {Object} template The template object.
|
|
115
116
|
*/
|
|
116
|
-
export const removeTemplate =
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
117
|
+
export const removeTemplate =
|
|
118
|
+
( template ) =>
|
|
119
|
+
async ( { registry } ) => {
|
|
120
|
+
try {
|
|
121
|
+
await registry
|
|
122
|
+
.dispatch( coreStore )
|
|
123
|
+
.deleteEntityRecord( 'postType', template.type, template.id, {
|
|
124
|
+
force: true,
|
|
125
|
+
} );
|
|
123
126
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
+
const lastError = registry
|
|
128
|
+
.select( coreStore )
|
|
129
|
+
.getLastEntityDeleteError(
|
|
130
|
+
'postType',
|
|
131
|
+
template.type,
|
|
132
|
+
template.id
|
|
133
|
+
);
|
|
127
134
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
135
|
+
if ( lastError ) {
|
|
136
|
+
throw lastError;
|
|
137
|
+
}
|
|
131
138
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
139
|
+
registry.dispatch( noticesStore ).createSuccessNotice(
|
|
140
|
+
sprintf(
|
|
141
|
+
/* translators: The template/part's name. */
|
|
142
|
+
__( '"%s" deleted.' ),
|
|
143
|
+
template.title.rendered
|
|
144
|
+
),
|
|
145
|
+
{ type: 'snackbar' }
|
|
146
|
+
);
|
|
147
|
+
} catch ( error ) {
|
|
148
|
+
const errorMessage =
|
|
149
|
+
error.message && error.code !== 'unknown_error'
|
|
150
|
+
? error.message
|
|
151
|
+
: __( 'An error occurred while deleting the template.' );
|
|
145
152
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
};
|
|
153
|
+
registry
|
|
154
|
+
.dispatch( noticesStore )
|
|
155
|
+
.createErrorNotice( errorMessage, { type: 'snackbar' } );
|
|
156
|
+
}
|
|
157
|
+
};
|
|
151
158
|
|
|
152
159
|
/**
|
|
153
160
|
* Action that sets a template part.
|
|
@@ -188,43 +195,45 @@ export function setHomeTemplateId( homeTemplateId ) {
|
|
|
188
195
|
*
|
|
189
196
|
* @return {number} The resolved template ID for the page route.
|
|
190
197
|
*/
|
|
191
|
-
export const setPage =
|
|
192
|
-
|
|
193
|
-
|
|
198
|
+
export const setPage =
|
|
199
|
+
( page ) =>
|
|
200
|
+
async ( { dispatch, registry } ) => {
|
|
201
|
+
if ( ! page.path && page.context?.postId ) {
|
|
202
|
+
const entity = await registry
|
|
203
|
+
.resolveSelect( coreStore )
|
|
204
|
+
.getEntityRecord(
|
|
205
|
+
'postType',
|
|
206
|
+
page.context.postType || 'post',
|
|
207
|
+
page.context.postId
|
|
208
|
+
);
|
|
209
|
+
// If the entity is undefined for some reason, path will resolve to "/"
|
|
210
|
+
page.path = getPathAndQueryString( entity?.link );
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
const template = await registry
|
|
194
214
|
.resolveSelect( coreStore )
|
|
195
|
-
.
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
context: {
|
|
218
|
-
...page.context,
|
|
219
|
-
templateSlug: template.slug,
|
|
220
|
-
},
|
|
221
|
-
}
|
|
222
|
-
: page,
|
|
223
|
-
templateId: template.id,
|
|
224
|
-
} );
|
|
225
|
-
|
|
226
|
-
return template.id;
|
|
227
|
-
};
|
|
215
|
+
.__experimentalGetTemplateForLink( page.path );
|
|
216
|
+
|
|
217
|
+
if ( ! template ) {
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
dispatch( {
|
|
222
|
+
type: 'SET_PAGE',
|
|
223
|
+
page: template.slug
|
|
224
|
+
? {
|
|
225
|
+
...page,
|
|
226
|
+
context: {
|
|
227
|
+
...page.context,
|
|
228
|
+
templateSlug: template.slug,
|
|
229
|
+
},
|
|
230
|
+
}
|
|
231
|
+
: page,
|
|
232
|
+
templateId: template.id,
|
|
233
|
+
} );
|
|
234
|
+
|
|
235
|
+
return template.id;
|
|
236
|
+
};
|
|
228
237
|
|
|
229
238
|
/**
|
|
230
239
|
* Action that sets the active navigation panel menu.
|
|
@@ -319,156 +328,171 @@ export function setIsListViewOpened( isOpen ) {
|
|
|
319
328
|
* @param {boolean} [options.allowUndo] Whether to allow the user to undo
|
|
320
329
|
* reverting the template. Default true.
|
|
321
330
|
*/
|
|
322
|
-
export const revertTemplate =
|
|
323
|
-
template,
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
if ( ! isTemplateRevertable( template ) ) {
|
|
327
|
-
registry
|
|
328
|
-
.dispatch( noticesStore )
|
|
329
|
-
.createErrorNotice( __( 'This template is not revertable.' ), {
|
|
330
|
-
type: 'snackbar',
|
|
331
|
-
} );
|
|
332
|
-
return;
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
try {
|
|
336
|
-
const templateEntityConfig = registry
|
|
337
|
-
.select( coreStore )
|
|
338
|
-
.getEntityConfig( 'postType', template.type );
|
|
339
|
-
|
|
340
|
-
if ( ! templateEntityConfig ) {
|
|
331
|
+
export const revertTemplate =
|
|
332
|
+
( template, { allowUndo = true } = {} ) =>
|
|
333
|
+
async ( { registry } ) => {
|
|
334
|
+
if ( ! isTemplateRevertable( template ) ) {
|
|
341
335
|
registry
|
|
342
336
|
.dispatch( noticesStore )
|
|
343
|
-
.createErrorNotice(
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
),
|
|
347
|
-
{ type: 'snackbar' }
|
|
348
|
-
);
|
|
337
|
+
.createErrorNotice( __( 'This template is not revertable.' ), {
|
|
338
|
+
type: 'snackbar',
|
|
339
|
+
} );
|
|
349
340
|
return;
|
|
350
341
|
}
|
|
351
342
|
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
343
|
+
try {
|
|
344
|
+
const templateEntityConfig = registry
|
|
345
|
+
.select( coreStore )
|
|
346
|
+
.getEntityConfig( 'postType', template.type );
|
|
356
347
|
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
return;
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
const serializeBlocks = ( { blocks: blocksForSerialization = [] } ) =>
|
|
371
|
-
__unstableSerializeAndClean( blocksForSerialization );
|
|
372
|
-
|
|
373
|
-
const edited = registry
|
|
374
|
-
.select( coreStore )
|
|
375
|
-
.getEditedEntityRecord( 'postType', template.type, template.id );
|
|
376
|
-
|
|
377
|
-
// We are fixing up the undo level here to make sure we can undo
|
|
378
|
-
// the revert in the header toolbar correctly.
|
|
379
|
-
registry.dispatch( coreStore ).editEntityRecord(
|
|
380
|
-
'postType',
|
|
381
|
-
template.type,
|
|
382
|
-
template.id,
|
|
383
|
-
{
|
|
384
|
-
content: serializeBlocks, // Required to make the `undo` behave correctly.
|
|
385
|
-
blocks: edited.blocks, // Required to revert the blocks in the editor.
|
|
386
|
-
source: 'custom', // required to avoid turning the editor into a dirty state
|
|
387
|
-
},
|
|
388
|
-
{
|
|
389
|
-
undoIgnore: true, // Required to merge this edit with the last undo level.
|
|
348
|
+
if ( ! templateEntityConfig ) {
|
|
349
|
+
registry
|
|
350
|
+
.dispatch( noticesStore )
|
|
351
|
+
.createErrorNotice(
|
|
352
|
+
__(
|
|
353
|
+
'The editor has encountered an unexpected error. Please reload.'
|
|
354
|
+
),
|
|
355
|
+
{ type: 'snackbar' }
|
|
356
|
+
);
|
|
357
|
+
return;
|
|
390
358
|
}
|
|
391
|
-
);
|
|
392
359
|
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
} );
|
|
401
|
-
|
|
402
|
-
if ( allowUndo ) {
|
|
403
|
-
const undoRevert = () => {
|
|
360
|
+
const fileTemplatePath = addQueryArgs(
|
|
361
|
+
`${ templateEntityConfig.baseURL }/${ template.id }`,
|
|
362
|
+
{ context: 'edit', source: 'theme' }
|
|
363
|
+
);
|
|
364
|
+
|
|
365
|
+
const fileTemplate = await apiFetch( { path: fileTemplatePath } );
|
|
366
|
+
if ( ! fileTemplate ) {
|
|
404
367
|
registry
|
|
405
|
-
.dispatch(
|
|
406
|
-
.
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
368
|
+
.dispatch( noticesStore )
|
|
369
|
+
.createErrorNotice(
|
|
370
|
+
__(
|
|
371
|
+
'The editor has encountered an unexpected error. Please reload.'
|
|
372
|
+
),
|
|
373
|
+
{ type: 'snackbar' }
|
|
374
|
+
);
|
|
375
|
+
return;
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
const serializeBlocks = ( {
|
|
379
|
+
blocks: blocksForSerialization = [],
|
|
380
|
+
} ) => __unstableSerializeAndClean( blocksForSerialization );
|
|
381
|
+
|
|
382
|
+
const edited = registry
|
|
383
|
+
.select( coreStore )
|
|
384
|
+
.getEditedEntityRecord(
|
|
385
|
+
'postType',
|
|
386
|
+
template.type,
|
|
387
|
+
template.id
|
|
388
|
+
);
|
|
412
389
|
|
|
390
|
+
// We are fixing up the undo level here to make sure we can undo
|
|
391
|
+
// the revert in the header toolbar correctly.
|
|
392
|
+
registry.dispatch( coreStore ).editEntityRecord(
|
|
393
|
+
'postType',
|
|
394
|
+
template.type,
|
|
395
|
+
template.id,
|
|
396
|
+
{
|
|
397
|
+
content: serializeBlocks, // Required to make the `undo` behave correctly.
|
|
398
|
+
blocks: edited.blocks, // Required to revert the blocks in the editor.
|
|
399
|
+
source: 'custom', // required to avoid turning the editor into a dirty state
|
|
400
|
+
},
|
|
401
|
+
{
|
|
402
|
+
undoIgnore: true, // Required to merge this edit with the last undo level.
|
|
403
|
+
}
|
|
404
|
+
);
|
|
405
|
+
|
|
406
|
+
const blocks = parse( fileTemplate?.content?.raw );
|
|
413
407
|
registry
|
|
414
|
-
.dispatch(
|
|
415
|
-
.
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
label: __( 'Undo' ),
|
|
420
|
-
onClick: undoRevert,
|
|
421
|
-
},
|
|
422
|
-
],
|
|
408
|
+
.dispatch( coreStore )
|
|
409
|
+
.editEntityRecord( 'postType', template.type, fileTemplate.id, {
|
|
410
|
+
content: serializeBlocks,
|
|
411
|
+
blocks,
|
|
412
|
+
source: 'theme',
|
|
423
413
|
} );
|
|
424
|
-
|
|
414
|
+
|
|
415
|
+
if ( allowUndo ) {
|
|
416
|
+
const undoRevert = () => {
|
|
417
|
+
registry
|
|
418
|
+
.dispatch( coreStore )
|
|
419
|
+
.editEntityRecord(
|
|
420
|
+
'postType',
|
|
421
|
+
template.type,
|
|
422
|
+
edited.id,
|
|
423
|
+
{
|
|
424
|
+
content: serializeBlocks,
|
|
425
|
+
blocks: edited.blocks,
|
|
426
|
+
source: 'custom',
|
|
427
|
+
}
|
|
428
|
+
);
|
|
429
|
+
};
|
|
430
|
+
|
|
431
|
+
registry
|
|
432
|
+
.dispatch( noticesStore )
|
|
433
|
+
.createSuccessNotice( __( 'Template reverted.' ), {
|
|
434
|
+
type: 'snackbar',
|
|
435
|
+
actions: [
|
|
436
|
+
{
|
|
437
|
+
label: __( 'Undo' ),
|
|
438
|
+
onClick: undoRevert,
|
|
439
|
+
},
|
|
440
|
+
],
|
|
441
|
+
} );
|
|
442
|
+
} else {
|
|
443
|
+
registry
|
|
444
|
+
.dispatch( noticesStore )
|
|
445
|
+
.createSuccessNotice( __( 'Template reverted.' ) );
|
|
446
|
+
}
|
|
447
|
+
} catch ( error ) {
|
|
448
|
+
const errorMessage =
|
|
449
|
+
error.message && error.code !== 'unknown_error'
|
|
450
|
+
? error.message
|
|
451
|
+
: __( 'Template revert failed. Please reload.' );
|
|
425
452
|
registry
|
|
426
453
|
.dispatch( noticesStore )
|
|
427
|
-
.
|
|
454
|
+
.createErrorNotice( errorMessage, { type: 'snackbar' } );
|
|
428
455
|
}
|
|
429
|
-
}
|
|
430
|
-
const errorMessage =
|
|
431
|
-
error.message && error.code !== 'unknown_error'
|
|
432
|
-
? error.message
|
|
433
|
-
: __( 'Template revert failed. Please reload.' );
|
|
434
|
-
registry
|
|
435
|
-
.dispatch( noticesStore )
|
|
436
|
-
.createErrorNotice( errorMessage, { type: 'snackbar' } );
|
|
437
|
-
}
|
|
438
|
-
};
|
|
456
|
+
};
|
|
439
457
|
/**
|
|
440
458
|
* Action that opens an editor sidebar.
|
|
441
459
|
*
|
|
442
460
|
* @param {?string} name Sidebar name to be opened.
|
|
443
461
|
*/
|
|
444
|
-
export const openGeneralSidebar =
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
462
|
+
export const openGeneralSidebar =
|
|
463
|
+
( name ) =>
|
|
464
|
+
( { registry } ) => {
|
|
465
|
+
registry
|
|
466
|
+
.dispatch( interfaceStore )
|
|
467
|
+
.enableComplementaryArea( editSiteStoreName, name );
|
|
468
|
+
};
|
|
449
469
|
|
|
450
470
|
/**
|
|
451
471
|
* Action that closes the sidebar.
|
|
452
472
|
*/
|
|
453
|
-
export const closeGeneralSidebar =
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
473
|
+
export const closeGeneralSidebar =
|
|
474
|
+
() =>
|
|
475
|
+
( { registry } ) => {
|
|
476
|
+
registry
|
|
477
|
+
.dispatch( interfaceStore )
|
|
478
|
+
.disableComplementaryArea( editSiteStoreName );
|
|
479
|
+
};
|
|
480
|
+
|
|
481
|
+
export const switchEditorMode =
|
|
482
|
+
( mode ) =>
|
|
483
|
+
( { registry } ) => {
|
|
484
|
+
registry
|
|
485
|
+
.dispatch( 'core/preferences' )
|
|
486
|
+
.set( 'core/edit-site', 'editorMode', mode );
|
|
487
|
+
|
|
488
|
+
// Unselect blocks when we switch to a non visual mode.
|
|
489
|
+
if ( mode !== 'visual' ) {
|
|
490
|
+
registry.dispatch( blockEditorStore ).clearSelectedBlock();
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
if ( mode === 'visual' ) {
|
|
494
|
+
speak( __( 'Visual editor selected' ), 'assertive' );
|
|
495
|
+
} else if ( mode === 'mosaic' ) {
|
|
496
|
+
speak( __( 'Mosaic view selected' ), 'assertive' );
|
|
497
|
+
}
|
|
498
|
+
};
|
package/src/store/selectors.js
CHANGED
|
@@ -82,8 +82,8 @@ export function __experimentalGetPreviewDeviceType( state ) {
|
|
|
82
82
|
*
|
|
83
83
|
* @return {Object} Whether the current user can create media or not.
|
|
84
84
|
*/
|
|
85
|
-
export const getCanUserCreateMedia = createRegistrySelector(
|
|
86
|
-
select( coreDataStore ).canUser( 'create', 'media' )
|
|
85
|
+
export const getCanUserCreateMedia = createRegistrySelector(
|
|
86
|
+
( select ) => () => select( coreDataStore ).canUser( 'create', 'media' )
|
|
87
87
|
);
|
|
88
88
|
|
|
89
89
|
/**
|
|
@@ -304,11 +304,8 @@ export function isInserterOpened( state ) {
|
|
|
304
304
|
* @return {Object} The root client ID, index to insert at and starting filter value.
|
|
305
305
|
*/
|
|
306
306
|
export function __experimentalGetInsertionPoint( state ) {
|
|
307
|
-
const {
|
|
308
|
-
|
|
309
|
-
insertionIndex,
|
|
310
|
-
filterValue,
|
|
311
|
-
} = state.blockInserterPanel;
|
|
307
|
+
const { rootClientId, insertionIndex, filterValue } =
|
|
308
|
+
state.blockInserterPanel;
|
|
312
309
|
return { rootClientId, insertionIndex, filterValue };
|
|
313
310
|
}
|
|
314
311
|
|
|
@@ -339,9 +336,11 @@ export const getCurrentTemplateTemplateParts = createRegistrySelector(
|
|
|
339
336
|
templateId
|
|
340
337
|
);
|
|
341
338
|
|
|
342
|
-
const templateParts = select(
|
|
343
|
-
|
|
344
|
-
|
|
339
|
+
const templateParts = select( coreDataStore ).getEntityRecords(
|
|
340
|
+
'postType',
|
|
341
|
+
'wp_template_part',
|
|
342
|
+
{ per_page: -1 }
|
|
343
|
+
);
|
|
345
344
|
const templatePartsById = keyBy(
|
|
346
345
|
templateParts,
|
|
347
346
|
( templatePart ) => templatePart.id
|