@wordpress/edit-site 4.0.1 → 4.1.0-next.e230fbab09.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.
Files changed (174) 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/app/index.js +20 -0
  4. package/build/components/app/index.js.map +1 -1
  5. package/build/components/editor/global-styles-renderer.js +7 -3
  6. package/build/components/editor/global-styles-renderer.js.map +1 -1
  7. package/build/components/editor/index.js +3 -18
  8. package/build/components/editor/index.js.map +1 -1
  9. package/build/components/error-boundary/index.js +11 -27
  10. package/build/components/error-boundary/index.js.map +1 -1
  11. package/build/components/error-boundary/warning.js +70 -0
  12. package/build/components/error-boundary/warning.js.map +1 -0
  13. package/build/components/global-styles/navigation-button.js +7 -27
  14. package/build/components/global-styles/navigation-button.js.map +1 -1
  15. package/build/components/global-styles/screen-block-list.js +31 -1
  16. package/build/components/global-styles/screen-block-list.js.map +1 -1
  17. package/build/components/global-styles/screen-typography.js.map +1 -1
  18. package/build/components/global-styles/typography-panel.js +5 -2
  19. package/build/components/global-styles/typography-panel.js.map +1 -1
  20. package/build/components/global-styles/use-global-styles-output.js +21 -4
  21. package/build/components/global-styles/use-global-styles-output.js.map +1 -1
  22. package/build/components/global-styles/utils.js +2 -2
  23. package/build/components/global-styles/utils.js.map +1 -1
  24. package/build/components/header/index.js +1 -1
  25. package/build/components/header/index.js.map +1 -1
  26. package/build/components/header/more-menu/index.js +9 -21
  27. package/build/components/header/more-menu/index.js.map +1 -1
  28. package/build/components/header/more-menu/site-export.js +1 -1
  29. package/build/components/header/more-menu/site-export.js.map +1 -1
  30. package/build/components/header/more-menu/welcome-guide-menu-item.js +4 -8
  31. package/build/components/header/more-menu/welcome-guide-menu-item.js.map +1 -1
  32. package/build/components/keyboard-shortcuts/index.js +1 -1
  33. package/build/components/keyboard-shortcuts/index.js.map +1 -1
  34. package/build/components/list/table.js +9 -20
  35. package/build/components/list/table.js.map +1 -1
  36. package/build/components/navigation-sidebar/navigation-panel/index.js +9 -3
  37. package/build/components/navigation-sidebar/navigation-panel/index.js.map +1 -1
  38. package/build/components/navigation-sidebar/navigation-toggle/index.js +15 -4
  39. package/build/components/navigation-sidebar/navigation-toggle/index.js.map +1 -1
  40. package/build/components/secondary-sidebar/list-view-sidebar.js +0 -11
  41. package/build/components/secondary-sidebar/list-view-sidebar.js.map +1 -1
  42. package/build/components/sidebar/global-styles-sidebar.js +5 -5
  43. package/build/components/sidebar/global-styles-sidebar.js.map +1 -1
  44. package/build/components/template-part-converter/convert-to-template-part.js +4 -1
  45. package/build/components/template-part-converter/convert-to-template-part.js.map +1 -1
  46. package/build/components/welcome-guide/editor.js +6 -6
  47. package/build/components/welcome-guide/editor.js.map +1 -1
  48. package/build/components/welcome-guide/styles.js +6 -4
  49. package/build/components/welcome-guide/styles.js.map +1 -1
  50. package/build/index.js +22 -7
  51. package/build/index.js.map +1 -1
  52. package/build/store/actions.js +203 -163
  53. package/build/store/actions.js.map +1 -1
  54. package/build/store/index.js +3 -9
  55. package/build/store/index.js.map +1 -1
  56. package/build/store/reducer.js +0 -44
  57. package/build/store/reducer.js.map +1 -1
  58. package/build/store/selectors.js +33 -10
  59. package/build/store/selectors.js.map +1 -1
  60. package/build-module/components/add-new-template/new-template-part.js +4 -1
  61. package/build-module/components/add-new-template/new-template-part.js.map +1 -1
  62. package/build-module/components/app/index.js +16 -0
  63. package/build-module/components/app/index.js.map +1 -1
  64. package/build-module/components/editor/global-styles-renderer.js +6 -3
  65. package/build-module/components/editor/global-styles-renderer.js.map +1 -1
  66. package/build-module/components/editor/index.js +4 -17
  67. package/build-module/components/editor/index.js.map +1 -1
  68. package/build-module/components/error-boundary/index.js +9 -26
  69. package/build-module/components/error-boundary/index.js.map +1 -1
  70. package/build-module/components/error-boundary/warning.js +60 -0
  71. package/build-module/components/error-boundary/warning.js.map +1 -0
  72. package/build-module/components/global-styles/navigation-button.js +8 -28
  73. package/build-module/components/global-styles/navigation-button.js.map +1 -1
  74. package/build-module/components/global-styles/screen-block-list.js +31 -2
  75. package/build-module/components/global-styles/screen-block-list.js.map +1 -1
  76. package/build-module/components/global-styles/screen-typography.js.map +1 -1
  77. package/build-module/components/global-styles/typography-panel.js +6 -3
  78. package/build-module/components/global-styles/typography-panel.js.map +1 -1
  79. package/build-module/components/global-styles/use-global-styles-output.js +20 -4
  80. package/build-module/components/global-styles/use-global-styles-output.js.map +1 -1
  81. package/build-module/components/global-styles/utils.js +2 -2
  82. package/build-module/components/global-styles/utils.js.map +1 -1
  83. package/build-module/components/header/index.js +1 -1
  84. package/build-module/components/header/index.js.map +1 -1
  85. package/build-module/components/header/more-menu/index.js +11 -22
  86. package/build-module/components/header/more-menu/index.js.map +1 -1
  87. package/build-module/components/header/more-menu/site-export.js +1 -1
  88. package/build-module/components/header/more-menu/site-export.js.map +1 -1
  89. package/build-module/components/header/more-menu/welcome-guide-menu-item.js +4 -8
  90. package/build-module/components/header/more-menu/welcome-guide-menu-item.js.map +1 -1
  91. package/build-module/components/keyboard-shortcuts/index.js +1 -1
  92. package/build-module/components/keyboard-shortcuts/index.js.map +1 -1
  93. package/build-module/components/list/table.js +9 -21
  94. package/build-module/components/list/table.js.map +1 -1
  95. package/build-module/components/navigation-sidebar/navigation-panel/index.js +9 -3
  96. package/build-module/components/navigation-sidebar/navigation-panel/index.js.map +1 -1
  97. package/build-module/components/navigation-sidebar/navigation-toggle/index.js +12 -4
  98. package/build-module/components/navigation-sidebar/navigation-toggle/index.js.map +1 -1
  99. package/build-module/components/secondary-sidebar/list-view-sidebar.js +1 -12
  100. package/build-module/components/secondary-sidebar/list-view-sidebar.js.map +1 -1
  101. package/build-module/components/sidebar/global-styles-sidebar.js +4 -4
  102. package/build-module/components/sidebar/global-styles-sidebar.js.map +1 -1
  103. package/build-module/components/template-part-converter/convert-to-template-part.js +4 -1
  104. package/build-module/components/template-part-converter/convert-to-template-part.js.map +1 -1
  105. package/build-module/components/welcome-guide/editor.js +5 -5
  106. package/build-module/components/welcome-guide/editor.js.map +1 -1
  107. package/build-module/components/welcome-guide/styles.js +5 -4
  108. package/build-module/components/welcome-guide/styles.js.map +1 -1
  109. package/build-module/index.js +20 -7
  110. package/build-module/index.js.map +1 -1
  111. package/build-module/store/actions.js +181 -154
  112. package/build-module/store/actions.js.map +1 -1
  113. package/build-module/store/index.js +4 -9
  114. package/build-module/store/index.js.map +1 -1
  115. package/build-module/store/reducer.js +0 -40
  116. package/build-module/store/reducer.js.map +1 -1
  117. package/build-module/store/selectors.js +28 -10
  118. package/build-module/store/selectors.js.map +1 -1
  119. package/build-style/style-rtl.css +102 -39
  120. package/build-style/style.css +102 -39
  121. package/package.json +33 -27
  122. package/src/components/add-new-template/new-template-part.js +7 -1
  123. package/src/components/app/index.js +19 -0
  124. package/src/components/editor/global-styles-renderer.js +7 -1
  125. package/src/components/editor/index.js +2 -20
  126. package/src/components/error-boundary/index.js +11 -28
  127. package/src/components/error-boundary/warning.js +59 -0
  128. package/src/components/global-styles/navigation-button.js +6 -25
  129. package/src/components/global-styles/screen-block-list.js +27 -2
  130. package/src/components/global-styles/screen-typography.js +1 -2
  131. package/src/components/global-styles/typography-panel.js +12 -5
  132. package/src/components/global-styles/use-global-styles-output.js +19 -3
  133. package/src/components/global-styles/utils.js +2 -2
  134. package/src/components/header/index.js +1 -1
  135. package/src/components/header/more-menu/index.js +12 -29
  136. package/src/components/header/more-menu/site-export.js +1 -1
  137. package/src/components/header/more-menu/welcome-guide-menu-item.js +3 -7
  138. package/src/components/keyboard-shortcuts/index.js +1 -1
  139. package/src/components/list/table.js +18 -23
  140. package/src/components/navigation-sidebar/navigation-panel/index.js +16 -11
  141. package/src/components/navigation-sidebar/navigation-toggle/index.js +13 -4
  142. package/src/components/navigation-sidebar/navigation-toggle/style.scss +32 -31
  143. package/src/components/navigation-sidebar/navigation-toggle/test/index.js +1 -1
  144. package/src/components/secondary-sidebar/list-view-sidebar.js +1 -11
  145. package/src/components/sidebar/global-styles-sidebar.js +6 -3
  146. package/src/components/sidebar/style.scss +1 -1
  147. package/src/components/template-part-converter/convert-to-template-part.js +6 -1
  148. package/src/components/welcome-guide/editor.js +8 -4
  149. package/src/components/welcome-guide/styles.js +5 -3
  150. package/src/index.js +25 -7
  151. package/src/store/actions.js +180 -215
  152. package/src/store/index.js +2 -8
  153. package/src/store/reducer.js +0 -30
  154. package/src/store/selectors.js +37 -10
  155. package/src/store/test/actions.js +203 -92
  156. package/src/store/test/reducer.js +0 -22
  157. package/src/store/test/selectors.js +22 -53
  158. package/src/style.scss +0 -1
  159. package/build/components/header/feature-toggle/index.js +0 -66
  160. package/build/components/header/feature-toggle/index.js.map +0 -1
  161. package/build/components/routes/redirect-to-homepage.js +0 -87
  162. package/build/components/routes/redirect-to-homepage.js.map +0 -1
  163. package/build/store/defaults.js +0 -15
  164. package/build/store/defaults.js.map +0 -1
  165. package/build-module/components/header/feature-toggle/index.js +0 -52
  166. package/build-module/components/header/feature-toggle/index.js.map +0 -1
  167. package/build-module/components/routes/redirect-to-homepage.js +0 -75
  168. package/build-module/components/routes/redirect-to-homepage.js.map +0 -1
  169. package/build-module/store/defaults.js +0 -8
  170. package/build-module/store/defaults.js.map +0 -1
  171. package/src/components/header/feature-toggle/index.js +0 -55
  172. package/src/components/header/more-menu/style.scss +0 -29
  173. package/src/components/routes/redirect-to-homepage.js +0 -71
  174. package/src/store/defaults.js +0 -7
@@ -1,9 +1,9 @@
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';
6
+ import deprecated from '@wordpress/deprecated';
7
7
  import { addQueryArgs, getPathAndQueryString } from '@wordpress/url';
8
8
  import { __, sprintf } from '@wordpress/i18n';
9
9
  import { store as noticesStore } from '@wordpress/notices';
@@ -11,6 +11,7 @@ import { store as coreStore } from '@wordpress/core-data';
11
11
  import { store as interfaceStore } from '@wordpress/interface';
12
12
  import { store as blockEditorStore } from '@wordpress/block-editor';
13
13
  import { speak } from '@wordpress/a11y';
14
+ import { store as preferencesStore } from '@wordpress/preferences';
14
15
 
15
16
  /**
16
17
  * Internal dependencies
@@ -19,21 +20,26 @@ import { STORE_NAME as editSiteStoreName } from './constants';
19
20
  import isTemplateRevertable from '../utils/is-template-revertable';
20
21
 
21
22
  /**
22
- * Returns an action object used to toggle a feature flag.
23
+ * Dispatches an action that toggles a feature flag.
23
24
  *
24
- * @param {string} feature Feature name.
25
- *
26
- * @return {Object} Action object.
25
+ * @param {string} featureName Feature name.
27
26
  */
28
- export function toggleFeature( feature ) {
29
- return {
30
- type: 'TOGGLE_FEATURE',
31
- feature,
27
+ export function toggleFeature( featureName ) {
28
+ return function ( { registry } ) {
29
+ deprecated( "select( 'core/edit-site' ).toggleFeature( featureName )", {
30
+ since: '6.0',
31
+ alternative:
32
+ "select( 'core/preferences').toggle( 'core/edit-site', featureName )",
33
+ } );
34
+
35
+ registry
36
+ .dispatch( preferencesStore )
37
+ .toggle( 'core/edit-site', featureName );
32
38
  };
33
39
  }
34
40
 
35
41
  /**
36
- * Returns an action object used to toggle the width of the editing canvas.
42
+ * Action that changes the width of the editing canvas.
37
43
  *
38
44
  * @param {string} deviceType
39
45
  *
@@ -47,97 +53,83 @@ export function __experimentalSetPreviewDeviceType( deviceType ) {
47
53
  }
48
54
 
49
55
  /**
50
- * Returns an action object used to set a template.
56
+ * Action that sets a template, optionally fetching it from REST API.
51
57
  *
52
58
  * @param {number} templateId The template ID.
53
59
  * @param {string} templateSlug The template slug.
54
60
  * @return {Object} Action object.
55
61
  */
56
- export function* setTemplate( templateId, templateSlug ) {
57
- const pageContext = { templateSlug };
62
+ export const setTemplate = ( templateId, templateSlug ) => async ( {
63
+ dispatch,
64
+ registry,
65
+ } ) => {
58
66
  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;
67
+ const template = await registry
68
+ .resolveSelect( coreStore )
69
+ .getEntityRecord( 'postType', 'wp_template', templateId );
70
+ templateSlug = template?.slug;
67
71
  }
68
- return {
72
+
73
+ dispatch( {
69
74
  type: 'SET_TEMPLATE',
70
75
  templateId,
71
- page: { context: pageContext },
72
- };
73
- }
76
+ page: { context: { templateSlug } },
77
+ } );
78
+ };
74
79
 
75
80
  /**
76
- * Adds a new template, and sets it as the current template.
81
+ * Action that adds a new template and sets it as the current template.
77
82
  *
78
83
  * @param {Object} template The template.
79
84
  *
80
85
  * @return {Object} Action object used to set the current template.
81
86
  */
82
- export function* addTemplate( template ) {
83
- const newTemplate = yield controls.dispatch(
84
- coreStore,
85
- 'saveEntityRecord',
86
- 'postType',
87
- 'wp_template',
88
- template
89
- );
87
+ export const addTemplate = ( template ) => async ( { dispatch, registry } ) => {
88
+ const newTemplate = await registry
89
+ .dispatch( coreStore )
90
+ .saveEntityRecord( 'postType', 'wp_template', template );
90
91
 
91
92
  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
- );
93
+ registry
94
+ .dispatch( coreStore )
95
+ .editEntityRecord(
96
+ 'postType',
97
+ 'wp_template',
98
+ newTemplate.id,
99
+ { blocks: parse( template.content ) },
100
+ { undoIgnore: true }
101
+ );
101
102
  }
102
103
 
103
- return {
104
+ dispatch( {
104
105
  type: 'SET_TEMPLATE',
105
106
  templateId: newTemplate.id,
106
107
  page: { context: { templateSlug: newTemplate.slug } },
107
- };
108
- }
108
+ } );
109
+ };
109
110
 
110
111
  /**
111
- * Removes a template.
112
+ * Action that removes a template.
112
113
  *
113
114
  * @param {Object} template The template object.
114
115
  */
115
- export function* removeTemplate( template ) {
116
+ export const removeTemplate = ( template ) => async ( { registry } ) => {
116
117
  try {
117
- yield controls.dispatch(
118
- coreStore,
119
- 'deleteEntityRecord',
120
- 'postType',
121
- template.type,
122
- template.id,
123
- { force: true }
124
- );
118
+ await registry
119
+ .dispatch( coreStore )
120
+ .deleteEntityRecord( 'postType', template.type, template.id, {
121
+ force: true,
122
+ } );
125
123
 
126
- const lastError = yield controls.select(
127
- coreStore,
128
- 'getLastEntityDeleteError',
129
- 'postType',
130
- template.type,
131
- template.id
132
- );
124
+ const lastError = registry
125
+ .select( coreStore )
126
+ .getLastEntityDeleteError( 'postType', template.type, template.id );
133
127
 
134
128
  if ( lastError ) {
135
129
  throw lastError;
136
130
  }
137
131
 
138
- yield controls.dispatch(
139
- noticesStore,
140
- 'createSuccessNotice',
132
+ registry.dispatch( noticesStore ).createSuccessNotice(
141
133
  sprintf(
142
134
  /* translators: The template/part's name. */
143
135
  __( '"%s" deleted.' ),
@@ -151,17 +143,14 @@ export function* removeTemplate( template ) {
151
143
  ? error.message
152
144
  : __( 'An error occurred while deleting the template.' );
153
145
 
154
- yield controls.dispatch(
155
- noticesStore,
156
- 'createErrorNotice',
157
- errorMessage,
158
- { type: 'snackbar' }
159
- );
146
+ registry
147
+ .dispatch( noticesStore )
148
+ .createErrorNotice( errorMessage, { type: 'snackbar' } );
160
149
  }
161
- }
150
+ };
162
151
 
163
152
  /**
164
- * Returns an action object used to set a template part.
153
+ * Action that sets a template part.
165
154
  *
166
155
  * @param {string} templatePartId The template part ID.
167
156
  *
@@ -175,8 +164,8 @@ export function setTemplatePart( templatePartId ) {
175
164
  }
176
165
 
177
166
  /**
178
- * Updates the homeTemplateId state with the templateId of the page resolved
179
- * from the given path.
167
+ * Action that sets the home template ID to the template ID of the page resolved
168
+ * from a given path.
180
169
  *
181
170
  * @param {number} homeTemplateId The template ID for the homepage.
182
171
  */
@@ -199,41 +188,46 @@ export function setHomeTemplateId( homeTemplateId ) {
199
188
  *
200
189
  * @return {number} The resolved template ID for the page route.
201
190
  */
202
- export function* setPage( page ) {
191
+ export const setPage = ( page ) => async ( { dispatch, registry } ) => {
203
192
  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
- );
193
+ const entity = await registry
194
+ .resolveSelect( coreStore )
195
+ .getEntityRecord(
196
+ 'postType',
197
+ page.context.postType || 'post',
198
+ page.context.postId
199
+ );
211
200
  // If the entity is undefined for some reason, path will resolve to "/"
212
201
  page.path = getPathAndQueryString( entity?.link );
213
202
  }
214
- const { id: templateId, slug: templateSlug } = yield controls.resolveSelect(
215
- coreStore,
216
- '__experimentalGetTemplateForLink',
217
- page.path
218
- );
219
- yield {
203
+
204
+ const template = await registry
205
+ .resolveSelect( coreStore )
206
+ .__experimentalGetTemplateForLink( page.path );
207
+
208
+ if ( ! template ) {
209
+ return;
210
+ }
211
+
212
+ dispatch( {
220
213
  type: 'SET_PAGE',
221
- page: ! templateSlug
222
- ? page
223
- : {
214
+ page: template.slug
215
+ ? {
224
216
  ...page,
225
217
  context: {
226
218
  ...page.context,
227
- templateSlug,
219
+ templateSlug: template.slug,
228
220
  },
229
- },
230
- templateId,
231
- };
232
- return templateId;
233
- }
221
+ }
222
+ : page,
223
+ templateId: template.id,
224
+ } );
225
+
226
+ return template.id;
227
+ };
234
228
 
235
229
  /**
236
- * Returns an action object used to set the active navigation panel menu.
230
+ * Action that sets the active navigation panel menu.
237
231
  *
238
232
  * @param {string} menu Menu prop of active menu.
239
233
  *
@@ -272,7 +266,7 @@ export function setIsNavigationPanelOpened( isOpen ) {
272
266
  }
273
267
 
274
268
  /**
275
- * Returns an action object used to open/close the inserter.
269
+ * Opens or closes the inserter.
276
270
  *
277
271
  * @param {boolean|Object} value Whether the inserter should be
278
272
  * opened (true) or closed (false).
@@ -325,33 +319,33 @@ export function setIsListViewOpened( isOpen ) {
325
319
  * @param {boolean} [options.allowUndo] Whether to allow the user to undo
326
320
  * reverting the template. Default true.
327
321
  */
328
- export function* revertTemplate( template, { allowUndo = true } = {} ) {
322
+ export const revertTemplate = (
323
+ template,
324
+ { allowUndo = true } = {}
325
+ ) => async ( { registry } ) => {
329
326
  if ( ! isTemplateRevertable( template ) ) {
330
- yield controls.dispatch(
331
- noticesStore,
332
- 'createErrorNotice',
333
- __( 'This template is not revertable.' ),
334
- { type: 'snackbar' }
335
- );
327
+ registry
328
+ .dispatch( noticesStore )
329
+ .createErrorNotice( __( 'This template is not revertable.' ), {
330
+ type: 'snackbar',
331
+ } );
336
332
  return;
337
333
  }
338
334
 
339
335
  try {
340
- const templateEntity = yield controls.select(
341
- coreStore,
342
- 'getEntity',
343
- 'postType',
344
- template.type
345
- );
336
+ const templateEntity = registry
337
+ .select( coreStore )
338
+ .getEntity( 'postType', template.type );
339
+
346
340
  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
- );
341
+ registry
342
+ .dispatch( noticesStore )
343
+ .createErrorNotice(
344
+ __(
345
+ 'The editor has encountered an unexpected error. Please reload.'
346
+ ),
347
+ { type: 'snackbar' }
348
+ );
355
349
  return;
356
350
  }
357
351
 
@@ -359,78 +353,66 @@ export function* revertTemplate( template, { allowUndo = true } = {} ) {
359
353
  `${ templateEntity.baseURL }/${ template.id }`,
360
354
  { context: 'edit', source: 'theme' }
361
355
  );
362
- const fileTemplate = yield apiFetch( { path: fileTemplatePath } );
356
+
357
+ const fileTemplate = await apiFetch( { path: fileTemplatePath } );
363
358
  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
- );
359
+ registry
360
+ .dispatch( noticesStore )
361
+ .createErrorNotice(
362
+ __(
363
+ 'The editor has encountered an unexpected error. Please reload.'
364
+ ),
365
+ { type: 'snackbar' }
366
+ );
372
367
  return;
373
368
  }
374
369
 
375
370
  const serializeBlocks = ( { blocks: blocksForSerialization = [] } ) =>
376
371
  __unstableSerializeAndClean( blocksForSerialization );
377
- const edited = yield controls.select(
378
- coreStore,
379
- 'getEditedEntityRecord',
380
- 'postType',
381
- template.type,
382
- template.id
383
- );
372
+
373
+ const edited = registry
374
+ .select( coreStore )
375
+ .getEditedEntityRecord( 'postType', template.type, template.id );
376
+
384
377
  // We are fixing up the undo level here to make sure we can undo
385
378
  // the revert in the header toolbar correctly.
386
- yield controls.dispatch(
387
- coreStore,
388
- 'editEntityRecord',
379
+ registry.dispatch( coreStore ).editEntityRecord(
389
380
  'postType',
390
381
  template.type,
391
382
  template.id,
392
383
  {
393
- content: serializeBlocks, // required to make the `undo` behave correctly
394
- blocks: edited.blocks, // required to revert the blocks in the editor
384
+ content: serializeBlocks, // Required to make the `undo` behave correctly.
385
+ blocks: edited.blocks, // Required to revert the blocks in the editor.
395
386
  source: 'custom', // required to avoid turning the editor into a dirty state
396
387
  },
397
388
  {
398
- undoIgnore: true, // required to merge this edit with the last undo level
389
+ undoIgnore: true, // Required to merge this edit with the last undo level.
399
390
  }
400
391
  );
401
392
 
402
393
  const blocks = parse( fileTemplate?.content?.raw );
403
- yield controls.dispatch(
404
- coreStore,
405
- 'editEntityRecord',
406
- 'postType',
407
- template.type,
408
- fileTemplate.id,
409
- {
394
+ registry
395
+ .dispatch( coreStore )
396
+ .editEntityRecord( 'postType', template.type, fileTemplate.id, {
410
397
  content: serializeBlocks,
411
398
  blocks,
412
399
  source: 'theme',
413
- }
414
- );
400
+ } );
415
401
 
416
402
  if ( allowUndo ) {
417
- const undoRevert = async () => {
418
- await dispatch( coreStore ).editEntityRecord(
419
- 'postType',
420
- template.type,
421
- edited.id,
422
- {
403
+ const undoRevert = () => {
404
+ registry
405
+ .dispatch( coreStore )
406
+ .editEntityRecord( 'postType', template.type, edited.id, {
423
407
  content: serializeBlocks,
424
408
  blocks: edited.blocks,
425
409
  source: 'custom',
426
- }
427
- );
410
+ } );
428
411
  };
429
- yield controls.dispatch(
430
- noticesStore,
431
- 'createSuccessNotice',
432
- __( 'Template reverted.' ),
433
- {
412
+
413
+ registry
414
+ .dispatch( noticesStore )
415
+ .createSuccessNotice( __( 'Template reverted.' ), {
434
416
  type: 'snackbar',
435
417
  actions: [
436
418
  {
@@ -438,72 +420,55 @@ export function* revertTemplate( template, { allowUndo = true } = {} ) {
438
420
  onClick: undoRevert,
439
421
  },
440
422
  ],
441
- }
442
- );
423
+ } );
443
424
  } else {
444
- yield controls.dispatch(
445
- noticesStore,
446
- 'createSuccessNotice',
447
- __( 'Template reverted.' )
448
- );
425
+ registry
426
+ .dispatch( noticesStore )
427
+ .createSuccessNotice( __( 'Template reverted.' ) );
449
428
  }
450
429
  } catch ( error ) {
451
430
  const errorMessage =
452
431
  error.message && error.code !== 'unknown_error'
453
432
  ? error.message
454
433
  : __( 'Template revert failed. Please reload.' );
455
- yield controls.dispatch(
456
- noticesStore,
457
- 'createErrorNotice',
458
- errorMessage,
459
- { type: 'snackbar' }
460
- );
434
+ registry
435
+ .dispatch( noticesStore )
436
+ .createErrorNotice( errorMessage, { type: 'snackbar' } );
461
437
  }
462
- }
438
+ };
463
439
  /**
464
- * Returns an action object used in signalling that the user opened an editor sidebar.
440
+ * Action that opens an editor sidebar.
465
441
  *
466
442
  * @param {?string} name Sidebar name to be opened.
467
- *
468
- * @yield {Object} Action object.
469
443
  */
470
- export function* openGeneralSidebar( name ) {
471
- yield controls.dispatch(
472
- interfaceStore,
473
- 'enableComplementaryArea',
474
- editSiteStoreName,
475
- name
476
- );
477
- }
444
+ export const openGeneralSidebar = ( name ) => ( { registry } ) => {
445
+ registry
446
+ .dispatch( interfaceStore )
447
+ .enableComplementaryArea( editSiteStoreName, name );
448
+ };
478
449
 
479
450
  /**
480
- * Returns an action object signalling that the user closed the sidebar.
481
- *
482
- * @yield {Object} Action object.
451
+ * Action that closes the sidebar.
483
452
  */
484
- export function* closeGeneralSidebar() {
485
- yield controls.dispatch(
486
- interfaceStore,
487
- 'disableComplementaryArea',
488
- editSiteStoreName
489
- );
490
- }
453
+ export const closeGeneralSidebar = () => ( { registry } ) => {
454
+ registry
455
+ .dispatch( interfaceStore )
456
+ .disableComplementaryArea( editSiteStoreName );
457
+ };
491
458
 
492
- export function* switchEditorMode( mode ) {
493
- yield {
494
- type: 'SWITCH_MODE',
495
- mode,
496
- };
459
+ export const switchEditorMode = ( mode ) => ( { registry } ) => {
460
+ registry
461
+ .dispatch( 'core/preferences' )
462
+ .set( 'core/edit-site', 'editorMode', mode );
497
463
 
498
464
  // Unselect blocks when we switch to a non visual mode.
499
465
  if ( mode !== 'visual' ) {
500
- yield controls.dispatch( blockEditorStore.name, 'clearSelectedBlock' );
466
+ registry.dispatch( blockEditorStore ).clearSelectedBlock();
501
467
  }
502
- const messages = {
503
- visual: __( 'Visual editor selected' ),
504
- mosaic: __( 'Mosaic view selected' ),
505
- };
506
- if ( messages[ mode ] ) {
507
- speak( messages[ mode ], 'assertive' );
468
+
469
+ if ( mode === 'visual' ) {
470
+ speak( __( 'Visual editor selected' ), 'assertive' );
471
+ } else if ( mode === 'mosaic' ) {
472
+ speak( __( 'Mosaic view selected' ), 'assertive' );
508
473
  }
509
- }
474
+ };
@@ -1,8 +1,7 @@
1
1
  /**
2
2
  * WordPress dependencies
3
3
  */
4
- import { createReduxStore, registerStore } from '@wordpress/data';
5
- import { controls } from '@wordpress/data-controls';
4
+ import { createReduxStore, register } from '@wordpress/data';
6
5
 
7
6
  /**
8
7
  * Internal dependencies
@@ -16,12 +15,7 @@ export const storeConfig = {
16
15
  reducer,
17
16
  actions,
18
17
  selectors,
19
- controls,
20
- persist: [ 'preferences' ],
21
18
  };
22
19
 
23
20
  export const store = createReduxStore( STORE_NAME, storeConfig );
24
-
25
- // Once we build a more generic persistence plugin that works across types of stores
26
- // we'd be able to replace this with a register call.
27
- registerStore( STORE_NAME, storeConfig );
21
+ register( store );
@@ -6,37 +6,8 @@ import { combineReducers } from '@wordpress/data';
6
6
  /**
7
7
  * Internal dependencies
8
8
  */
9
- import { PREFERENCES_DEFAULTS } from './defaults';
10
9
  import { MENU_ROOT } from '../components/navigation-sidebar/navigation-panel/constants';
11
10
 
12
- /**
13
- * Reducer returning the user preferences.
14
- *
15
- * @param {Object} state Current state.
16
- * @param {Object} action Dispatched action.
17
- * @return {Object} Updated state.
18
- */
19
- export const preferences = combineReducers( {
20
- features( state = PREFERENCES_DEFAULTS.features, action ) {
21
- switch ( action.type ) {
22
- case 'TOGGLE_FEATURE': {
23
- return {
24
- ...state,
25
- [ action.feature ]: ! state[ action.feature ],
26
- };
27
- }
28
- default:
29
- return state;
30
- }
31
- },
32
- editorMode( state = PREFERENCES_DEFAULTS.editorMode, action ) {
33
- if ( action.type === 'SWITCH_MODE' ) {
34
- return action.mode;
35
- }
36
- return state;
37
- },
38
- } );
39
-
40
11
  /**
41
12
  * Reducer returning the editing canvas device type.
42
13
  *
@@ -213,7 +184,6 @@ export function listViewPanel( state = false, action ) {
213
184
  }
214
185
 
215
186
  export default combineReducers( {
216
- preferences,
217
187
  deviceType,
218
188
  settings,
219
189
  editedPost,