@wordpress/edit-site 4.0.0 → 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.
Files changed (81) hide show
  1. package/build/components/add-new-template/new-template-part.js +4 -1
  2. package/build/components/add-new-template/new-template-part.js.map +1 -1
  3. package/build/components/error-boundary/index.js +11 -27
  4. package/build/components/error-boundary/index.js.map +1 -1
  5. package/build/components/error-boundary/warning.js +70 -0
  6. package/build/components/error-boundary/warning.js.map +1 -0
  7. package/build/components/global-styles/navigation-button.js +7 -27
  8. package/build/components/global-styles/navigation-button.js.map +1 -1
  9. package/build/components/global-styles/typography-panel.js +5 -2
  10. package/build/components/global-styles/typography-panel.js.map +1 -1
  11. package/build/components/global-styles/use-global-styles-output.js +21 -4
  12. package/build/components/global-styles/use-global-styles-output.js.map +1 -1
  13. package/build/components/list/table.js +3 -1
  14. package/build/components/list/table.js.map +1 -1
  15. package/build/components/navigation-sidebar/navigation-toggle/index.js +15 -4
  16. package/build/components/navigation-sidebar/navigation-toggle/index.js.map +1 -1
  17. package/build/components/routes/redirect-to-homepage.js +22 -3
  18. package/build/components/routes/redirect-to-homepage.js.map +1 -1
  19. package/build/components/secondary-sidebar/list-view-sidebar.js +0 -11
  20. package/build/components/secondary-sidebar/list-view-sidebar.js.map +1 -1
  21. package/build/components/template-part-converter/convert-to-template-part.js +4 -1
  22. package/build/components/template-part-converter/convert-to-template-part.js.map +1 -1
  23. package/build/index.js +15 -1
  24. package/build/index.js.map +1 -1
  25. package/build/store/actions.js +191 -155
  26. package/build/store/actions.js.map +1 -1
  27. package/build/store/index.js +0 -3
  28. package/build/store/index.js.map +1 -1
  29. package/build/store/selectors.js +3 -2
  30. package/build/store/selectors.js.map +1 -1
  31. package/build-module/components/add-new-template/new-template-part.js +4 -1
  32. package/build-module/components/add-new-template/new-template-part.js.map +1 -1
  33. package/build-module/components/error-boundary/index.js +9 -26
  34. package/build-module/components/error-boundary/index.js.map +1 -1
  35. package/build-module/components/error-boundary/warning.js +60 -0
  36. package/build-module/components/error-boundary/warning.js.map +1 -0
  37. package/build-module/components/global-styles/navigation-button.js +8 -28
  38. package/build-module/components/global-styles/navigation-button.js.map +1 -1
  39. package/build-module/components/global-styles/typography-panel.js +6 -3
  40. package/build-module/components/global-styles/typography-panel.js.map +1 -1
  41. package/build-module/components/global-styles/use-global-styles-output.js +20 -4
  42. package/build-module/components/global-styles/use-global-styles-output.js.map +1 -1
  43. package/build-module/components/list/table.js +2 -1
  44. package/build-module/components/list/table.js.map +1 -1
  45. package/build-module/components/navigation-sidebar/navigation-toggle/index.js +12 -4
  46. package/build-module/components/navigation-sidebar/navigation-toggle/index.js.map +1 -1
  47. package/build-module/components/routes/redirect-to-homepage.js +22 -3
  48. package/build-module/components/routes/redirect-to-homepage.js.map +1 -1
  49. package/build-module/components/secondary-sidebar/list-view-sidebar.js +1 -12
  50. package/build-module/components/secondary-sidebar/list-view-sidebar.js.map +1 -1
  51. package/build-module/components/template-part-converter/convert-to-template-part.js +4 -1
  52. package/build-module/components/template-part-converter/convert-to-template-part.js.map +1 -1
  53. package/build-module/index.js +13 -1
  54. package/build-module/index.js.map +1 -1
  55. package/build-module/store/actions.js +170 -145
  56. package/build-module/store/actions.js.map +1 -1
  57. package/build-module/store/index.js +0 -2
  58. package/build-module/store/index.js.map +1 -1
  59. package/build-module/store/selectors.js +3 -2
  60. package/build-module/store/selectors.js.map +1 -1
  61. package/build-style/style-rtl.css +11 -10
  62. package/build-style/style.css +11 -10
  63. package/package.json +18 -18
  64. package/src/components/add-new-template/new-template-part.js +7 -1
  65. package/src/components/error-boundary/index.js +11 -28
  66. package/src/components/error-boundary/warning.js +59 -0
  67. package/src/components/global-styles/navigation-button.js +6 -25
  68. package/src/components/global-styles/typography-panel.js +12 -5
  69. package/src/components/global-styles/use-global-styles-output.js +19 -3
  70. package/src/components/list/table.js +5 -2
  71. package/src/components/navigation-sidebar/navigation-toggle/index.js +13 -4
  72. package/src/components/navigation-sidebar/navigation-toggle/style.scss +32 -31
  73. package/src/components/routes/redirect-to-homepage.js +27 -4
  74. package/src/components/secondary-sidebar/list-view-sidebar.js +1 -11
  75. package/src/components/template-part-converter/convert-to-template-part.js +6 -1
  76. package/src/index.js +17 -1
  77. package/src/store/actions.js +161 -205
  78. package/src/store/index.js +0 -2
  79. package/src/store/selectors.js +3 -0
  80. package/src/store/test/actions.js +186 -92
  81. package/src/store/test/selectors.js +8 -1
@@ -20,10 +20,17 @@ function getNeedsHomepageRedirect( params ) {
20
20
  );
21
21
  }
22
22
 
23
+ /**
24
+ * Returns the postType and postId of the default homepage.
25
+ *
26
+ * @param {string} siteUrl The URL of the site.
27
+ * @return {Object} An object containing the postType and postId properties
28
+ * or `undefined` if a homepage could not be found.
29
+ */
23
30
  async function getHomepageParams( siteUrl ) {
24
31
  const siteSettings = await apiFetch( { path: '/wp/v2/settings' } );
25
32
  if ( ! siteSettings ) {
26
- return;
33
+ throw new Error( '`getHomepageParams`: unable to load site settings.' );
27
34
  }
28
35
 
29
36
  const {
@@ -44,11 +51,27 @@ async function getHomepageParams( siteUrl ) {
44
51
  // (packages/core-data/src/resolvers.js)
45
52
  const template = await window
46
53
  .fetch( addQueryArgs( siteUrl, { '_wp-find-template': true } ) )
47
- .then( ( res ) => res.json() )
48
- .then( ( { data } ) => data );
54
+ .then( ( response ) => {
55
+ if ( ! response.ok ) {
56
+ throw new Error(
57
+ `\`getHomepageParams\`: HTTP status error, ${ response.status } ${ response.statusText }`
58
+ );
59
+ }
60
+
61
+ return response.json();
62
+ } )
63
+ .then( ( { data } ) => {
64
+ if ( data.message ) {
65
+ throw new Error(
66
+ `\`getHomepageParams\`: REST API error, ${ data.message }`
67
+ );
68
+ }
69
+
70
+ return data;
71
+ } );
49
72
 
50
73
  if ( ! template?.id ) {
51
- return;
74
+ throw new Error( '`getHomepageParams`: unable to find home template.' );
52
75
  }
53
76
 
54
77
  return {
@@ -1,10 +1,7 @@
1
1
  /**
2
2
  * WordPress dependencies
3
3
  */
4
- import {
5
- __experimentalListView as ListView,
6
- store as blockEditorStore,
7
- } from '@wordpress/block-editor';
4
+ import { __experimentalListView as ListView } from '@wordpress/block-editor';
8
5
  import { Button } from '@wordpress/components';
9
6
  import {
10
7
  useFocusOnMount,
@@ -25,12 +22,6 @@ import { store as editSiteStore } from '../../store';
25
22
  export default function ListViewSidebar() {
26
23
  const { setIsListViewOpened } = useDispatch( editSiteStore );
27
24
 
28
- const { clearSelectedBlock, selectBlock } = useDispatch( blockEditorStore );
29
- async function selectEditorBlock( clientId ) {
30
- await clearSelectedBlock();
31
- selectBlock( clientId, -1 );
32
- }
33
-
34
25
  const focusOnMountRef = useFocusOnMount( 'firstElement' );
35
26
  const headerFocusReturnRef = useFocusReturn();
36
27
  const contentFocusReturnRef = useFocusReturn();
@@ -69,7 +60,6 @@ export default function ListViewSidebar() {
69
60
  ] ) }
70
61
  >
71
62
  <ListView
72
- onSelect={ selectEditorBlock }
73
63
  showNestedBlocks
74
64
  __experimentalFeatures
75
65
  __experimentalPersistentListViewFeatures
@@ -30,11 +30,16 @@ export default function ConvertToTemplatePart( { clientIds, blocks } ) {
30
30
  const { createSuccessNotice } = useDispatch( noticesStore );
31
31
 
32
32
  const onConvert = async ( { title, area } ) => {
33
+ // Currently template parts only allow latin chars.
34
+ // Fallback slug will receive suffix by default.
35
+ const cleanSlug =
36
+ kebabCase( title ).replace( /[^\w-]+/g, '' ) || 'wp-custom-part';
37
+
33
38
  const templatePart = await saveEntityRecord(
34
39
  'postType',
35
40
  'wp_template_part',
36
41
  {
37
- slug: kebabCase( title ),
42
+ slug: cleanSlug,
38
43
  title,
39
44
  content: serialize( blocks ),
40
45
  area,
package/src/index.js CHANGED
@@ -13,6 +13,7 @@ import {
13
13
  __experimentalFetchUrlData as fetchUrlData,
14
14
  } from '@wordpress/core-data';
15
15
  import { store as editorStore } from '@wordpress/editor';
16
+ import { __ } from '@wordpress/i18n';
16
17
  import { store as viewportStore } from '@wordpress/viewport';
17
18
  import { getQueryArgs } from '@wordpress/url';
18
19
 
@@ -24,6 +25,7 @@ import { store as editSiteStore } from './store';
24
25
  import EditSiteApp from './components/app';
25
26
  import getIsListPage from './utils/get-is-list-page';
26
27
  import redirectToHomepage from './components/routes/redirect-to-homepage';
28
+ import ErrorBoundaryWarning from './components/error-boundary/warning';
27
29
 
28
30
  /**
29
31
  * Reinitializes the editor after the user chooses to reboot the editor after
@@ -38,7 +40,21 @@ export async function reinitializeEditor( target, settings ) {
38
40
  // define what's being edited. When visiting via the dashboard link, these
39
41
  // won't be present. Do a client side redirect to the 'homepage' if that's
40
42
  // the case.
41
- await redirectToHomepage( settings.siteUrl );
43
+ try {
44
+ await redirectToHomepage( settings.siteUrl );
45
+ } catch ( error ) {
46
+ render(
47
+ <ErrorBoundaryWarning
48
+ message={ __(
49
+ 'The editor is unable to find a block template for the homepage.'
50
+ ) }
51
+ error={ error }
52
+ dashboardLink="index.php"
53
+ />,
54
+ target
55
+ );
56
+ return;
57
+ }
42
58
 
43
59
  // This will be a no-op if the target doesn't have any React nodes.
44
60
  unmountComponentAtNode( target );
@@ -1,9 +1,8 @@
1
1
  /**
2
2
  * WordPress dependencies
3
3
  */
4
+ import apiFetch from '@wordpress/api-fetch';
4
5
  import { parse, __unstableSerializeAndClean } from '@wordpress/blocks';
5
- import { controls, dispatch } from '@wordpress/data';
6
- import { apiFetch } from '@wordpress/data-controls';
7
6
  import { addQueryArgs, getPathAndQueryString } from '@wordpress/url';
8
7
  import { __, sprintf } from '@wordpress/i18n';
9
8
  import { store as noticesStore } from '@wordpress/notices';
@@ -19,7 +18,7 @@ import { STORE_NAME as editSiteStoreName } from './constants';
19
18
  import isTemplateRevertable from '../utils/is-template-revertable';
20
19
 
21
20
  /**
22
- * Returns an action object used to toggle a feature flag.
21
+ * Action that toggles a feature flag.
23
22
  *
24
23
  * @param {string} feature Feature name.
25
24
  *
@@ -33,7 +32,7 @@ export function toggleFeature( feature ) {
33
32
  }
34
33
 
35
34
  /**
36
- * Returns an action object used to toggle the width of the editing canvas.
35
+ * Action that changes the width of the editing canvas.
37
36
  *
38
37
  * @param {string} deviceType
39
38
  *
@@ -47,97 +46,83 @@ export function __experimentalSetPreviewDeviceType( deviceType ) {
47
46
  }
48
47
 
49
48
  /**
50
- * Returns an action object used to set a template.
49
+ * Action that sets a template, optionally fetching it from REST API.
51
50
  *
52
51
  * @param {number} templateId The template ID.
53
52
  * @param {string} templateSlug The template slug.
54
53
  * @return {Object} Action object.
55
54
  */
56
- export function* setTemplate( templateId, templateSlug ) {
57
- const pageContext = { templateSlug };
55
+ export const setTemplate = ( templateId, templateSlug ) => async ( {
56
+ dispatch,
57
+ registry,
58
+ } ) => {
58
59
  if ( ! templateSlug ) {
59
- const template = yield controls.resolveSelect(
60
- coreStore,
61
- 'getEntityRecord',
62
- 'postType',
63
- 'wp_template',
64
- templateId
65
- );
66
- pageContext.templateSlug = template?.slug;
60
+ const template = await registry
61
+ .resolveSelect( coreStore )
62
+ .getEntityRecord( 'postType', 'wp_template', templateId );
63
+ templateSlug = template?.slug;
67
64
  }
68
- return {
65
+
66
+ dispatch( {
69
67
  type: 'SET_TEMPLATE',
70
68
  templateId,
71
- page: { context: pageContext },
72
- };
73
- }
69
+ page: { context: { templateSlug } },
70
+ } );
71
+ };
74
72
 
75
73
  /**
76
- * Adds a new template, and sets it as the current template.
74
+ * Action that adds a new template and sets it as the current template.
77
75
  *
78
76
  * @param {Object} template The template.
79
77
  *
80
78
  * @return {Object} Action object used to set the current template.
81
79
  */
82
- export function* addTemplate( template ) {
83
- const newTemplate = yield controls.dispatch(
84
- coreStore,
85
- 'saveEntityRecord',
86
- 'postType',
87
- 'wp_template',
88
- template
89
- );
80
+ export const addTemplate = ( template ) => async ( { dispatch, registry } ) => {
81
+ const newTemplate = await registry
82
+ .dispatch( coreStore )
83
+ .saveEntityRecord( 'postType', 'wp_template', template );
90
84
 
91
85
  if ( template.content ) {
92
- yield controls.dispatch(
93
- coreStore,
94
- 'editEntityRecord',
95
- 'postType',
96
- 'wp_template',
97
- newTemplate.id,
98
- { blocks: parse( template.content ) },
99
- { undoIgnore: true }
100
- );
86
+ registry
87
+ .dispatch( coreStore )
88
+ .editEntityRecord(
89
+ 'postType',
90
+ 'wp_template',
91
+ newTemplate.id,
92
+ { blocks: parse( template.content ) },
93
+ { undoIgnore: true }
94
+ );
101
95
  }
102
96
 
103
- return {
97
+ dispatch( {
104
98
  type: 'SET_TEMPLATE',
105
99
  templateId: newTemplate.id,
106
100
  page: { context: { templateSlug: newTemplate.slug } },
107
- };
108
- }
101
+ } );
102
+ };
109
103
 
110
104
  /**
111
- * Removes a template.
105
+ * Action that removes a template.
112
106
  *
113
107
  * @param {Object} template The template object.
114
108
  */
115
- export function* removeTemplate( template ) {
109
+ export const removeTemplate = ( template ) => async ( { registry } ) => {
116
110
  try {
117
- yield controls.dispatch(
118
- coreStore,
119
- 'deleteEntityRecord',
120
- 'postType',
121
- template.type,
122
- template.id,
123
- { force: true }
124
- );
111
+ await registry
112
+ .dispatch( coreStore )
113
+ .deleteEntityRecord( 'postType', template.type, template.id, {
114
+ force: true,
115
+ } );
125
116
 
126
- const lastError = yield controls.select(
127
- coreStore,
128
- 'getLastEntityDeleteError',
129
- 'postType',
130
- template.type,
131
- template.id
132
- );
117
+ const lastError = registry
118
+ .select( coreStore )
119
+ .getLastEntityDeleteError( 'postType', template.type, template.id );
133
120
 
134
121
  if ( lastError ) {
135
122
  throw lastError;
136
123
  }
137
124
 
138
- yield controls.dispatch(
139
- noticesStore,
140
- 'createSuccessNotice',
125
+ registry.dispatch( noticesStore ).createSuccessNotice(
141
126
  sprintf(
142
127
  /* translators: The template/part's name. */
143
128
  __( '"%s" deleted.' ),
@@ -151,17 +136,14 @@ export function* removeTemplate( template ) {
151
136
  ? error.message
152
137
  : __( 'An error occurred while deleting the template.' );
153
138
 
154
- yield controls.dispatch(
155
- noticesStore,
156
- 'createErrorNotice',
157
- errorMessage,
158
- { type: 'snackbar' }
159
- );
139
+ registry
140
+ .dispatch( noticesStore )
141
+ .createErrorNotice( errorMessage, { type: 'snackbar' } );
160
142
  }
161
- }
143
+ };
162
144
 
163
145
  /**
164
- * Returns an action object used to set a template part.
146
+ * Action that sets a template part.
165
147
  *
166
148
  * @param {string} templatePartId The template part ID.
167
149
  *
@@ -175,8 +157,8 @@ export function setTemplatePart( templatePartId ) {
175
157
  }
176
158
 
177
159
  /**
178
- * Updates the homeTemplateId state with the templateId of the page resolved
179
- * from the given path.
160
+ * Action that sets the home template ID to the template ID of the page resolved
161
+ * from a given path.
180
162
  *
181
163
  * @param {number} homeTemplateId The template ID for the homepage.
182
164
  */
@@ -199,41 +181,46 @@ export function setHomeTemplateId( homeTemplateId ) {
199
181
  *
200
182
  * @return {number} The resolved template ID for the page route.
201
183
  */
202
- export function* setPage( page ) {
184
+ export const setPage = ( page ) => async ( { dispatch, registry } ) => {
203
185
  if ( ! page.path && page.context?.postId ) {
204
- const entity = yield controls.resolveSelect(
205
- coreStore,
206
- 'getEntityRecord',
207
- 'postType',
208
- page.context.postType || 'post',
209
- page.context.postId
210
- );
186
+ const entity = await registry
187
+ .resolveSelect( coreStore )
188
+ .getEntityRecord(
189
+ 'postType',
190
+ page.context.postType || 'post',
191
+ page.context.postId
192
+ );
211
193
  // If the entity is undefined for some reason, path will resolve to "/"
212
194
  page.path = getPathAndQueryString( entity?.link );
213
195
  }
214
- const { id: templateId, slug: templateSlug } = yield controls.resolveSelect(
215
- coreStore,
216
- '__experimentalGetTemplateForLink',
217
- page.path
218
- );
219
- yield {
196
+
197
+ const template = await registry
198
+ .resolveSelect( coreStore )
199
+ .__experimentalGetTemplateForLink( page.path );
200
+
201
+ if ( ! template ) {
202
+ return;
203
+ }
204
+
205
+ dispatch( {
220
206
  type: 'SET_PAGE',
221
- page: ! templateSlug
222
- ? page
223
- : {
207
+ page: template.slug
208
+ ? {
224
209
  ...page,
225
210
  context: {
226
211
  ...page.context,
227
- templateSlug,
212
+ templateSlug: template.slug,
228
213
  },
229
- },
230
- templateId,
231
- };
232
- return templateId;
233
- }
214
+ }
215
+ : page,
216
+ templateId: template.id,
217
+ } );
218
+
219
+ return template.id;
220
+ };
234
221
 
235
222
  /**
236
- * Returns an action object used to set the active navigation panel menu.
223
+ * Action that sets the active navigation panel menu.
237
224
  *
238
225
  * @param {string} menu Menu prop of active menu.
239
226
  *
@@ -272,7 +259,7 @@ export function setIsNavigationPanelOpened( isOpen ) {
272
259
  }
273
260
 
274
261
  /**
275
- * Returns an action object used to open/close the inserter.
262
+ * Opens or closes the inserter.
276
263
  *
277
264
  * @param {boolean|Object} value Whether the inserter should be
278
265
  * opened (true) or closed (false).
@@ -325,33 +312,33 @@ export function setIsListViewOpened( isOpen ) {
325
312
  * @param {boolean} [options.allowUndo] Whether to allow the user to undo
326
313
  * reverting the template. Default true.
327
314
  */
328
- export function* revertTemplate( template, { allowUndo = true } = {} ) {
315
+ export const revertTemplate = (
316
+ template,
317
+ { allowUndo = true } = {}
318
+ ) => async ( { registry } ) => {
329
319
  if ( ! isTemplateRevertable( template ) ) {
330
- yield controls.dispatch(
331
- noticesStore,
332
- 'createErrorNotice',
333
- __( 'This template is not revertable.' ),
334
- { type: 'snackbar' }
335
- );
320
+ registry
321
+ .dispatch( noticesStore )
322
+ .createErrorNotice( __( 'This template is not revertable.' ), {
323
+ type: 'snackbar',
324
+ } );
336
325
  return;
337
326
  }
338
327
 
339
328
  try {
340
- const templateEntity = yield controls.select(
341
- coreStore,
342
- 'getEntity',
343
- 'postType',
344
- template.type
345
- );
329
+ const templateEntity = registry
330
+ .select( coreStore )
331
+ .getEntity( 'postType', template.type );
332
+
346
333
  if ( ! templateEntity ) {
347
- yield controls.dispatch(
348
- noticesStore,
349
- 'createErrorNotice',
350
- __(
351
- 'The editor has encountered an unexpected error. Please reload.'
352
- ),
353
- { type: 'snackbar' }
354
- );
334
+ registry
335
+ .dispatch( noticesStore )
336
+ .createErrorNotice(
337
+ __(
338
+ 'The editor has encountered an unexpected error. Please reload.'
339
+ ),
340
+ { type: 'snackbar' }
341
+ );
355
342
  return;
356
343
  }
357
344
 
@@ -359,33 +346,30 @@ export function* revertTemplate( template, { allowUndo = true } = {} ) {
359
346
  `${ templateEntity.baseURL }/${ template.id }`,
360
347
  { context: 'edit', source: 'theme' }
361
348
  );
362
- const fileTemplate = yield apiFetch( { path: fileTemplatePath } );
349
+
350
+ const fileTemplate = await apiFetch( { path: fileTemplatePath } );
363
351
  if ( ! fileTemplate ) {
364
- yield controls.dispatch(
365
- noticesStore,
366
- 'createErrorNotice',
367
- __(
368
- 'The editor has encountered an unexpected error. Please reload.'
369
- ),
370
- { type: 'snackbar' }
371
- );
352
+ registry
353
+ .dispatch( noticesStore )
354
+ .createErrorNotice(
355
+ __(
356
+ 'The editor has encountered an unexpected error. Please reload.'
357
+ ),
358
+ { type: 'snackbar' }
359
+ );
372
360
  return;
373
361
  }
374
362
 
375
363
  const serializeBlocks = ( { blocks: blocksForSerialization = [] } ) =>
376
364
  __unstableSerializeAndClean( blocksForSerialization );
377
- const edited = yield controls.select(
378
- coreStore,
379
- 'getEditedEntityRecord',
380
- 'postType',
381
- template.type,
382
- template.id
383
- );
365
+
366
+ const edited = registry
367
+ .select( coreStore )
368
+ .getEditedEntityRecord( 'postType', template.type, template.id );
369
+
384
370
  // We are fixing up the undo level here to make sure we can undo
385
371
  // the revert in the header toolbar correctly.
386
- yield controls.dispatch(
387
- coreStore,
388
- 'editEntityRecord',
372
+ registry.dispatch( coreStore ).editEntityRecord(
389
373
  'postType',
390
374
  template.type,
391
375
  template.id,
@@ -400,37 +384,28 @@ export function* revertTemplate( template, { allowUndo = true } = {} ) {
400
384
  );
401
385
 
402
386
  const blocks = parse( fileTemplate?.content?.raw );
403
- yield controls.dispatch(
404
- coreStore,
405
- 'editEntityRecord',
406
- 'postType',
407
- template.type,
408
- fileTemplate.id,
409
- {
387
+ registry
388
+ .dispatch( coreStore )
389
+ .editEntityRecord( 'postType', template.type, fileTemplate.id, {
410
390
  content: serializeBlocks,
411
391
  blocks,
412
392
  source: 'theme',
413
- }
414
- );
393
+ } );
415
394
 
416
395
  if ( allowUndo ) {
417
- const undoRevert = async () => {
418
- await dispatch( coreStore ).editEntityRecord(
419
- 'postType',
420
- template.type,
421
- edited.id,
422
- {
396
+ const undoRevert = () => {
397
+ registry
398
+ .dispatch( coreStore )
399
+ .editEntityRecord( 'postType', template.type, edited.id, {
423
400
  content: serializeBlocks,
424
401
  blocks: edited.blocks,
425
402
  source: 'custom',
426
- }
427
- );
403
+ } );
428
404
  };
429
- yield controls.dispatch(
430
- noticesStore,
431
- 'createSuccessNotice',
432
- __( 'Template reverted.' ),
433
- {
405
+
406
+ registry
407
+ .dispatch( noticesStore )
408
+ .createSuccessNotice( __( 'Template reverted.' ), {
434
409
  type: 'snackbar',
435
410
  actions: [
436
411
  {
@@ -438,72 +413,53 @@ export function* revertTemplate( template, { allowUndo = true } = {} ) {
438
413
  onClick: undoRevert,
439
414
  },
440
415
  ],
441
- }
442
- );
416
+ } );
443
417
  } else {
444
- yield controls.dispatch(
445
- noticesStore,
446
- 'createSuccessNotice',
447
- __( 'Template reverted.' )
448
- );
418
+ registry
419
+ .dispatch( noticesStore )
420
+ .createSuccessNotice( __( 'Template reverted.' ) );
449
421
  }
450
422
  } catch ( error ) {
451
423
  const errorMessage =
452
424
  error.message && error.code !== 'unknown_error'
453
425
  ? error.message
454
426
  : __( 'Template revert failed. Please reload.' );
455
- yield controls.dispatch(
456
- noticesStore,
457
- 'createErrorNotice',
458
- errorMessage,
459
- { type: 'snackbar' }
460
- );
427
+ registry
428
+ .dispatch( noticesStore )
429
+ .createErrorNotice( errorMessage, { type: 'snackbar' } );
461
430
  }
462
- }
431
+ };
463
432
  /**
464
- * Returns an action object used in signalling that the user opened an editor sidebar.
433
+ * Action that opens an editor sidebar.
465
434
  *
466
435
  * @param {?string} name Sidebar name to be opened.
467
- *
468
- * @yield {Object} Action object.
469
436
  */
470
- export function* openGeneralSidebar( name ) {
471
- yield controls.dispatch(
472
- interfaceStore,
473
- 'enableComplementaryArea',
474
- editSiteStoreName,
475
- name
476
- );
477
- }
437
+ export const openGeneralSidebar = ( name ) => ( { registry } ) => {
438
+ registry
439
+ .dispatch( interfaceStore )
440
+ .enableComplementaryArea( editSiteStoreName, name );
441
+ };
478
442
 
479
443
  /**
480
- * Returns an action object signalling that the user closed the sidebar.
481
- *
482
- * @yield {Object} Action object.
444
+ * Action that closes the sidebar.
483
445
  */
484
- export function* closeGeneralSidebar() {
485
- yield controls.dispatch(
486
- interfaceStore,
487
- 'disableComplementaryArea',
488
- editSiteStoreName
489
- );
490
- }
446
+ export const closeGeneralSidebar = () => ( { registry } ) => {
447
+ registry
448
+ .dispatch( interfaceStore )
449
+ .disableComplementaryArea( editSiteStoreName );
450
+ };
491
451
 
492
- export function* switchEditorMode( mode ) {
493
- yield {
494
- type: 'SWITCH_MODE',
495
- mode,
496
- };
452
+ export const switchEditorMode = ( mode ) => ( { dispatch, registry } ) => {
453
+ dispatch( { type: 'SWITCH_MODE', mode } );
497
454
 
498
455
  // Unselect blocks when we switch to a non visual mode.
499
456
  if ( mode !== 'visual' ) {
500
- yield controls.dispatch( blockEditorStore.name, 'clearSelectedBlock' );
457
+ registry.dispatch( blockEditorStore ).clearSelectedBlock();
501
458
  }
502
- const messages = {
503
- visual: __( 'Visual editor selected' ),
504
- mosaic: __( 'Mosaic view selected' ),
505
- };
506
- if ( messages[ mode ] ) {
507
- speak( messages[ mode ], 'assertive' );
459
+
460
+ if ( mode === 'visual' ) {
461
+ speak( __( 'Visual editor selected' ), 'assertive' );
462
+ } else if ( mode === 'mosaic' ) {
463
+ speak( __( 'Mosaic view selected' ), 'assertive' );
508
464
  }
509
- }
465
+ };