@wordpress/edit-post 6.7.0 → 6.10.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 (228) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/README.md +1 -1
  3. package/build/components/block-manager/category.js.map +1 -1
  4. package/build/components/block-manager/index.js +12 -4
  5. package/build/components/block-manager/index.js.map +1 -1
  6. package/build/components/device-preview/index.js.map +1 -1
  7. package/build/components/editor-initialization/listener-hooks.js.map +1 -1
  8. package/build/components/header/fullscreen-mode-close/index.js.map +1 -1
  9. package/build/components/header/header-toolbar/index.js.map +1 -1
  10. package/build/components/header/index.js.map +1 -1
  11. package/build/components/header/mode-switcher/index.js.map +1 -1
  12. package/build/components/header/post-publish-button-or-toggle.js.map +1 -1
  13. package/build/components/header/template-title/delete-template.js.map +1 -1
  14. package/build/components/header/template-title/edit-template-title.js +11 -2
  15. package/build/components/header/template-title/edit-template-title.js.map +1 -1
  16. package/build/components/header/template-title/index.js.map +1 -1
  17. package/build/components/header/tools-more-menu-group/index.js.map +1 -1
  18. package/build/components/keyboard-shortcut-help-modal/config.js +12 -0
  19. package/build/components/keyboard-shortcut-help-modal/config.js.map +1 -1
  20. package/build/components/keyboard-shortcut-help-modal/index.js +1 -3
  21. package/build/components/keyboard-shortcut-help-modal/index.js.map +1 -1
  22. package/build/components/keyboard-shortcuts/index.js.map +1 -1
  23. package/build/components/layout/actions-panel.js.map +1 -1
  24. package/build/components/layout/index.js.map +1 -1
  25. package/build/components/layout/index.native.js.map +1 -1
  26. package/build/components/preferences-modal/index.js +3 -26
  27. package/build/components/preferences-modal/index.js.map +1 -1
  28. package/build/components/preferences-modal/options/enable-custom-fields.js.map +1 -1
  29. package/build/components/preferences-modal/options/enable-panel.js.map +1 -1
  30. package/build/components/preferences-modal/options/enable-publish-sidebar.js.map +1 -1
  31. package/build/components/secondary-sidebar/inserter-sidebar.js.map +1 -1
  32. package/build/components/sidebar/discussion-panel/index.js.map +1 -1
  33. package/build/components/sidebar/featured-image/index.js.map +1 -1
  34. package/build/components/sidebar/page-attributes/index.js.map +1 -1
  35. package/build/components/sidebar/plugin-document-setting-panel/index.js.map +1 -1
  36. package/build/components/sidebar/plugin-post-status-info/index.js +2 -2
  37. package/build/components/sidebar/plugin-post-status-info/index.js.map +1 -1
  38. package/build/components/sidebar/plugin-sidebar/index.js.map +1 -1
  39. package/build/components/sidebar/post-excerpt/index.js.map +1 -1
  40. package/build/components/sidebar/post-format/index.js +3 -1
  41. package/build/components/sidebar/post-format/index.js.map +1 -1
  42. package/build/components/sidebar/post-schedule/index.js +28 -12
  43. package/build/components/sidebar/post-schedule/index.js.map +1 -1
  44. package/build/components/sidebar/post-slug/index.js +3 -1
  45. package/build/components/sidebar/post-slug/index.js.map +1 -1
  46. package/build/components/sidebar/post-status/index.js +6 -2
  47. package/build/components/sidebar/post-status/index.js.map +1 -1
  48. package/build/components/sidebar/post-template/create-modal.js +116 -0
  49. package/build/components/sidebar/post-template/create-modal.js.map +1 -0
  50. package/build/components/sidebar/post-template/form.js +123 -0
  51. package/build/components/sidebar/post-template/form.js.map +1 -0
  52. package/build/components/sidebar/post-template/index.js +124 -0
  53. package/build/components/sidebar/post-template/index.js.map +1 -0
  54. package/build/components/sidebar/post-url/index.js +68 -0
  55. package/build/components/sidebar/post-url/index.js.map +1 -0
  56. package/build/components/sidebar/post-visibility/index.js +21 -6
  57. package/build/components/sidebar/post-visibility/index.js.map +1 -1
  58. package/build/components/sidebar/settings-sidebar/index.js +2 -6
  59. package/build/components/sidebar/settings-sidebar/index.js.map +1 -1
  60. package/build/components/start-page-options/index.js +31 -13
  61. package/build/components/start-page-options/index.js.map +1 -1
  62. package/build/components/visual-editor/block-inspector-button.js +3 -7
  63. package/build/components/visual-editor/block-inspector-button.js.map +1 -1
  64. package/build/components/visual-editor/index.js +4 -2
  65. package/build/components/visual-editor/index.js.map +1 -1
  66. package/build/editor.js +1 -1
  67. package/build/editor.js.map +1 -1
  68. package/build/editor.native.js +1 -1
  69. package/build/editor.native.js.map +1 -1
  70. package/build/plugins/copy-content-menu-item/index.js +1 -1
  71. package/build/plugins/copy-content-menu-item/index.js.map +1 -1
  72. package/build/store/actions.js.map +1 -1
  73. package/build/store/selectors.js +8 -8
  74. package/build/store/selectors.js.map +1 -1
  75. package/build-module/components/block-manager/category.js.map +1 -1
  76. package/build-module/components/block-manager/index.js +13 -5
  77. package/build-module/components/block-manager/index.js.map +1 -1
  78. package/build-module/components/device-preview/index.js.map +1 -1
  79. package/build-module/components/editor-initialization/listener-hooks.js.map +1 -1
  80. package/build-module/components/header/fullscreen-mode-close/index.js.map +1 -1
  81. package/build-module/components/header/header-toolbar/index.js.map +1 -1
  82. package/build-module/components/header/index.js.map +1 -1
  83. package/build-module/components/header/mode-switcher/index.js.map +1 -1
  84. package/build-module/components/header/post-publish-button-or-toggle.js.map +1 -1
  85. package/build-module/components/header/template-title/delete-template.js.map +1 -1
  86. package/build-module/components/header/template-title/edit-template-title.js +12 -2
  87. package/build-module/components/header/template-title/edit-template-title.js.map +1 -1
  88. package/build-module/components/header/template-title/index.js.map +1 -1
  89. package/build-module/components/header/tools-more-menu-group/index.js.map +1 -1
  90. package/build-module/components/keyboard-shortcut-help-modal/config.js +12 -0
  91. package/build-module/components/keyboard-shortcut-help-modal/config.js.map +1 -1
  92. package/build-module/components/keyboard-shortcut-help-modal/index.js +1 -2
  93. package/build-module/components/keyboard-shortcut-help-modal/index.js.map +1 -1
  94. package/build-module/components/keyboard-shortcuts/index.js.map +1 -1
  95. package/build-module/components/layout/actions-panel.js.map +1 -1
  96. package/build-module/components/layout/index.js.map +1 -1
  97. package/build-module/components/layout/index.native.js.map +1 -1
  98. package/build-module/components/preferences-modal/index.js +3 -25
  99. package/build-module/components/preferences-modal/index.js.map +1 -1
  100. package/build-module/components/preferences-modal/options/enable-custom-fields.js.map +1 -1
  101. package/build-module/components/preferences-modal/options/enable-panel.js.map +1 -1
  102. package/build-module/components/preferences-modal/options/enable-publish-sidebar.js.map +1 -1
  103. package/build-module/components/secondary-sidebar/inserter-sidebar.js.map +1 -1
  104. package/build-module/components/sidebar/discussion-panel/index.js.map +1 -1
  105. package/build-module/components/sidebar/featured-image/index.js.map +1 -1
  106. package/build-module/components/sidebar/page-attributes/index.js.map +1 -1
  107. package/build-module/components/sidebar/plugin-document-setting-panel/index.js.map +1 -1
  108. package/build-module/components/sidebar/plugin-post-status-info/index.js +2 -2
  109. package/build-module/components/sidebar/plugin-post-status-info/index.js.map +1 -1
  110. package/build-module/components/sidebar/plugin-sidebar/index.js.map +1 -1
  111. package/build-module/components/sidebar/post-excerpt/index.js.map +1 -1
  112. package/build-module/components/sidebar/post-format/index.js +3 -1
  113. package/build-module/components/sidebar/post-format/index.js.map +1 -1
  114. package/build-module/components/sidebar/post-schedule/index.js +32 -13
  115. package/build-module/components/sidebar/post-schedule/index.js.map +1 -1
  116. package/build-module/components/sidebar/post-slug/index.js +3 -1
  117. package/build-module/components/sidebar/post-slug/index.js.map +1 -1
  118. package/build-module/components/sidebar/post-status/index.js +4 -2
  119. package/build-module/components/sidebar/post-status/index.js.map +1 -1
  120. package/build-module/components/sidebar/post-template/create-modal.js +104 -0
  121. package/build-module/components/sidebar/post-template/create-modal.js.map +1 -0
  122. package/build-module/components/sidebar/post-template/form.js +106 -0
  123. package/build-module/components/sidebar/post-template/form.js.map +1 -0
  124. package/build-module/components/sidebar/post-template/index.js +110 -0
  125. package/build-module/components/sidebar/post-template/index.js.map +1 -0
  126. package/build-module/components/sidebar/post-url/index.js +59 -0
  127. package/build-module/components/sidebar/post-url/index.js.map +1 -0
  128. package/build-module/components/sidebar/post-visibility/index.js +24 -8
  129. package/build-module/components/sidebar/post-visibility/index.js.map +1 -1
  130. package/build-module/components/sidebar/settings-sidebar/index.js +2 -4
  131. package/build-module/components/sidebar/settings-sidebar/index.js.map +1 -1
  132. package/build-module/components/start-page-options/index.js +32 -14
  133. package/build-module/components/start-page-options/index.js.map +1 -1
  134. package/build-module/components/visual-editor/block-inspector-button.js +3 -5
  135. package/build-module/components/visual-editor/block-inspector-button.js.map +1 -1
  136. package/build-module/components/visual-editor/index.js +4 -2
  137. package/build-module/components/visual-editor/index.js.map +1 -1
  138. package/build-module/editor.js +2 -2
  139. package/build-module/editor.js.map +1 -1
  140. package/build-module/editor.native.js +2 -2
  141. package/build-module/editor.native.js.map +1 -1
  142. package/build-module/plugins/copy-content-menu-item/index.js +1 -1
  143. package/build-module/plugins/copy-content-menu-item/index.js.map +1 -1
  144. package/build-module/store/actions.js.map +1 -1
  145. package/build-module/store/selectors.js +8 -7
  146. package/build-module/store/selectors.js.map +1 -1
  147. package/build-style/style-rtl.css +85 -87
  148. package/build-style/style.css +84 -90
  149. package/package.json +27 -27
  150. package/src/components/block-manager/category.js +2 -2
  151. package/src/components/block-manager/index.js +15 -4
  152. package/src/components/device-preview/index.js +4 -6
  153. package/src/components/editor-initialization/listener-hooks.js +2 -3
  154. package/src/components/header/fullscreen-mode-close/index.js +2 -3
  155. package/src/components/header/header-toolbar/index.js +6 -11
  156. package/src/components/header/index.js +6 -9
  157. package/src/components/header/mode-switcher/index.js +4 -4
  158. package/src/components/header/post-publish-button-or-toggle.js +4 -6
  159. package/src/components/header/template-title/delete-template.js +2 -3
  160. package/src/components/header/template-title/edit-template-title.js +11 -1
  161. package/src/components/header/template-title/index.js +2 -3
  162. package/src/components/header/tools-more-menu-group/index.js +2 -3
  163. package/src/components/keyboard-shortcut-help-modal/config.js +8 -0
  164. package/src/components/keyboard-shortcut-help-modal/index.js +1 -2
  165. package/src/components/keyboard-shortcut-help-modal/style.scss +0 -5
  166. package/src/components/keyboard-shortcut-help-modal/test/__snapshots__/index.js.snap +14 -0
  167. package/src/components/keyboard-shortcut-help-modal/test/index.js +2 -1
  168. package/src/components/keyboard-shortcuts/index.js +4 -8
  169. package/src/components/layout/actions-panel.js +6 -9
  170. package/src/components/layout/index.js +12 -21
  171. package/src/components/layout/index.native.js +4 -5
  172. package/src/components/preferences-modal/index.js +5 -23
  173. package/src/components/preferences-modal/options/enable-custom-fields.js +2 -2
  174. package/src/components/preferences-modal/options/enable-panel.js +2 -3
  175. package/src/components/preferences-modal/options/enable-publish-sidebar.js +2 -3
  176. package/src/components/preferences-modal/test/index.js +3 -3
  177. package/src/components/secondary-sidebar/inserter-sidebar.js +2 -3
  178. package/src/components/sidebar/discussion-panel/index.js +2 -3
  179. package/src/components/sidebar/featured-image/index.js +2 -3
  180. package/src/components/sidebar/page-attributes/index.js +2 -3
  181. package/src/components/sidebar/plugin-document-setting-panel/index.js +2 -3
  182. package/src/components/sidebar/plugin-post-status-info/index.js +2 -2
  183. package/src/components/sidebar/plugin-sidebar/index.js +2 -3
  184. package/src/components/sidebar/post-author/style.scss +4 -10
  185. package/src/components/sidebar/post-excerpt/index.js +2 -3
  186. package/src/components/sidebar/post-format/index.js +1 -1
  187. package/src/components/sidebar/post-format/style.scss +5 -0
  188. package/src/components/sidebar/post-schedule/index.js +27 -16
  189. package/src/components/sidebar/post-schedule/style.scss +17 -4
  190. package/src/components/sidebar/post-slug/index.js +1 -1
  191. package/src/components/sidebar/post-slug/style.scss +4 -3
  192. package/src/components/sidebar/post-status/index.js +8 -5
  193. package/src/components/sidebar/post-template/create-modal.js +146 -0
  194. package/src/components/sidebar/post-template/form.js +143 -0
  195. package/src/components/sidebar/post-template/index.js +102 -0
  196. package/src/components/sidebar/post-template/style.scss +36 -0
  197. package/src/components/sidebar/post-url/index.js +51 -0
  198. package/src/components/sidebar/post-url/style.scss +23 -0
  199. package/src/components/sidebar/post-visibility/index.js +22 -8
  200. package/src/components/sidebar/post-visibility/style.scss +5 -4
  201. package/src/components/sidebar/settings-sidebar/index.js +1 -5
  202. package/src/components/sidebar/template/style.scss +0 -8
  203. package/src/components/start-page-options/index.js +48 -28
  204. package/src/components/start-page-options/style.scss +0 -9
  205. package/src/components/visual-editor/block-inspector-button.js +4 -8
  206. package/src/components/visual-editor/index.js +2 -1
  207. package/src/editor.js +8 -10
  208. package/src/editor.native.js +5 -6
  209. package/src/plugins/copy-content-menu-item/index.js +1 -1
  210. package/src/store/actions.js +322 -295
  211. package/src/store/selectors.js +21 -24
  212. package/src/style.scss +3 -2
  213. package/build/components/sidebar/post-link/index.js +0 -182
  214. package/build/components/sidebar/post-link/index.js.map +0 -1
  215. package/build/components/sidebar/template/actions.js +0 -167
  216. package/build/components/sidebar/template/actions.js.map +0 -1
  217. package/build/components/sidebar/template/index.js +0 -164
  218. package/build/components/sidebar/template/index.js.map +0 -1
  219. package/build-module/components/sidebar/post-link/index.js +0 -165
  220. package/build-module/components/sidebar/post-link/index.js.map +0 -1
  221. package/build-module/components/sidebar/template/actions.js +0 -153
  222. package/build-module/components/sidebar/template/actions.js.map +0 -1
  223. package/build-module/components/sidebar/template/index.js +0 -145
  224. package/build-module/components/sidebar/template/index.js.map +0 -1
  225. package/src/components/sidebar/post-link/index.js +0 -180
  226. package/src/components/sidebar/post-link/style.scss +0 -20
  227. package/src/components/sidebar/template/actions.js +0 -203
  228. package/src/components/sidebar/template/index.js +0 -164
@@ -27,18 +27,22 @@ import { store as editPostStore } from '.';
27
27
  *
28
28
  * @param {?string} name Sidebar name to be opened.
29
29
  */
30
- export const openGeneralSidebar = ( name ) => ( { registry } ) =>
31
- registry
32
- .dispatch( interfaceStore )
33
- .enableComplementaryArea( editPostStore.name, name );
30
+ export const openGeneralSidebar =
31
+ ( name ) =>
32
+ ( { registry } ) =>
33
+ registry
34
+ .dispatch( interfaceStore )
35
+ .enableComplementaryArea( editPostStore.name, name );
34
36
 
35
37
  /**
36
38
  * Returns an action object signalling that the user closed the sidebar.
37
39
  */
38
- export const closeGeneralSidebar = () => ( { registry } ) =>
39
- registry
40
- .dispatch( interfaceStore )
41
- .disableComplementaryArea( editPostStore.name );
40
+ export const closeGeneralSidebar =
41
+ () =>
42
+ ( { registry } ) =>
43
+ registry
44
+ .dispatch( interfaceStore )
45
+ .disableComplementaryArea( editPostStore.name );
42
46
 
43
47
  /**
44
48
  * Returns an action object used in signalling that the user opened a modal.
@@ -107,58 +111,62 @@ export function togglePublishSidebar() {
107
111
  *
108
112
  * @return {Object} Action object.
109
113
  */
110
- export const toggleEditorPanelEnabled = ( panelName ) => ( { registry } ) => {
111
- const inactivePanels =
112
- registry
113
- .select( preferencesStore )
114
- .get( 'core/edit-post', 'inactivePanels' ) ?? [];
115
-
116
- const isPanelInactive = !! inactivePanels?.includes( panelName );
117
-
118
- // If the panel is inactive, remove it to enable it, else add it to
119
- // make it inactive.
120
- let updatedInactivePanels;
121
- if ( isPanelInactive ) {
122
- updatedInactivePanels = inactivePanels.filter(
123
- ( invactivePanelName ) => invactivePanelName !== panelName
124
- );
125
- } else {
126
- updatedInactivePanels = [ ...inactivePanels, panelName ];
127
- }
114
+ export const toggleEditorPanelEnabled =
115
+ ( panelName ) =>
116
+ ( { registry } ) => {
117
+ const inactivePanels =
118
+ registry
119
+ .select( preferencesStore )
120
+ .get( 'core/edit-post', 'inactivePanels' ) ?? [];
121
+
122
+ const isPanelInactive = !! inactivePanels?.includes( panelName );
123
+
124
+ // If the panel is inactive, remove it to enable it, else add it to
125
+ // make it inactive.
126
+ let updatedInactivePanels;
127
+ if ( isPanelInactive ) {
128
+ updatedInactivePanels = inactivePanels.filter(
129
+ ( invactivePanelName ) => invactivePanelName !== panelName
130
+ );
131
+ } else {
132
+ updatedInactivePanels = [ ...inactivePanels, panelName ];
133
+ }
128
134
 
129
- registry
130
- .dispatch( preferencesStore )
131
- .set( 'core/edit-post', 'inactivePanels', updatedInactivePanels );
132
- };
135
+ registry
136
+ .dispatch( preferencesStore )
137
+ .set( 'core/edit-post', 'inactivePanels', updatedInactivePanels );
138
+ };
133
139
 
134
140
  /**
135
141
  * Opens a closed panel and closes an open panel.
136
142
  *
137
143
  * @param {string} panelName A string that identifies the panel to open or close.
138
144
  */
139
- export const toggleEditorPanelOpened = ( panelName ) => ( { registry } ) => {
140
- const openPanels =
141
- registry
142
- .select( preferencesStore )
143
- .get( 'core/edit-post', 'openPanels' ) ?? [];
144
-
145
- const isPanelOpen = !! openPanels?.includes( panelName );
146
-
147
- // If the panel is open, remove it to close it, else add it to
148
- // make it open.
149
- let updatedOpenPanels;
150
- if ( isPanelOpen ) {
151
- updatedOpenPanels = openPanels.filter(
152
- ( openPanelName ) => openPanelName !== panelName
153
- );
154
- } else {
155
- updatedOpenPanels = [ ...openPanels, panelName ];
156
- }
145
+ export const toggleEditorPanelOpened =
146
+ ( panelName ) =>
147
+ ( { registry } ) => {
148
+ const openPanels =
149
+ registry
150
+ .select( preferencesStore )
151
+ .get( 'core/edit-post', 'openPanels' ) ?? [];
152
+
153
+ const isPanelOpen = !! openPanels?.includes( panelName );
154
+
155
+ // If the panel is open, remove it to close it, else add it to
156
+ // make it open.
157
+ let updatedOpenPanels;
158
+ if ( isPanelOpen ) {
159
+ updatedOpenPanels = openPanels.filter(
160
+ ( openPanelName ) => openPanelName !== panelName
161
+ );
162
+ } else {
163
+ updatedOpenPanels = [ ...openPanels, panelName ];
164
+ }
157
165
 
158
- registry
159
- .dispatch( preferencesStore )
160
- .set( 'core/edit-post', 'openPanels', updatedOpenPanels );
161
- };
166
+ registry
167
+ .dispatch( preferencesStore )
168
+ .set( 'core/edit-post', 'openPanels', updatedOpenPanels );
169
+ };
162
170
 
163
171
  /**
164
172
  * Returns an action object used to remove a panel from the editor.
@@ -179,45 +187,56 @@ export function removeEditorPanel( panelName ) {
179
187
  *
180
188
  * @param {string} feature Feature name.
181
189
  */
182
- export const toggleFeature = ( feature ) => ( { registry } ) =>
183
- registry.dispatch( preferencesStore ).toggle( 'core/edit-post', feature );
190
+ export const toggleFeature =
191
+ ( feature ) =>
192
+ ( { registry } ) =>
193
+ registry
194
+ .dispatch( preferencesStore )
195
+ .toggle( 'core/edit-post', feature );
184
196
 
185
197
  /**
186
198
  * Triggers an action used to switch editor mode.
187
199
  *
188
200
  * @param {string} mode The editor mode.
189
201
  */
190
- export const switchEditorMode = ( mode ) => ( { registry } ) => {
191
- registry
192
- .dispatch( preferencesStore )
193
- .set( 'core/edit-post', 'editorMode', mode );
194
-
195
- // Unselect blocks when we switch to the code editor.
196
- if ( mode !== 'visual' ) {
197
- registry.dispatch( blockEditorStore ).clearSelectedBlock();
198
- }
199
-
200
- const message =
201
- mode === 'visual'
202
- ? __( 'Visual editor selected' )
203
- : __( 'Code editor selected' );
204
- speak( message, 'assertive' );
205
- };
202
+ export const switchEditorMode =
203
+ ( mode ) =>
204
+ ( { registry } ) => {
205
+ registry
206
+ .dispatch( preferencesStore )
207
+ .set( 'core/edit-post', 'editorMode', mode );
208
+
209
+ // Unselect blocks when we switch to the code editor.
210
+ if ( mode !== 'visual' ) {
211
+ registry.dispatch( blockEditorStore ).clearSelectedBlock();
212
+ }
213
+
214
+ const message =
215
+ mode === 'visual'
216
+ ? __( 'Visual editor selected' )
217
+ : __( 'Code editor selected' );
218
+ speak( message, 'assertive' );
219
+ };
206
220
 
207
221
  /**
208
222
  * Triggers an action object used to toggle a plugin name flag.
209
223
  *
210
224
  * @param {string} pluginName Plugin name.
211
225
  */
212
- export const togglePinnedPluginItem = ( pluginName ) => ( { registry } ) => {
213
- const isPinned = registry
214
- .select( interfaceStore )
215
- .isItemPinned( 'core/edit-post', pluginName );
226
+ export const togglePinnedPluginItem =
227
+ ( pluginName ) =>
228
+ ( { registry } ) => {
229
+ const isPinned = registry
230
+ .select( interfaceStore )
231
+ .isItemPinned( 'core/edit-post', pluginName );
216
232
 
217
- registry
218
- .dispatch( interfaceStore )
219
- [ isPinned ? 'unpinItem' : 'pinItem' ]( 'core/edit-post', pluginName );
220
- };
233
+ registry
234
+ .dispatch( interfaceStore )
235
+ [ isPinned ? 'unpinItem' : 'pinItem' ](
236
+ 'core/edit-post',
237
+ pluginName
238
+ );
239
+ };
221
240
 
222
241
  /**
223
242
  * Returns an action object used in signaling that a style should be auto-applied when a block is created.
@@ -225,85 +244,91 @@ export const togglePinnedPluginItem = ( pluginName ) => ( { registry } ) => {
225
244
  * @param {string} blockName Name of the block.
226
245
  * @param {?string} blockStyle Name of the style that should be auto applied. If undefined, the "auto apply" setting of the block is removed.
227
246
  */
228
- export const updatePreferredStyleVariations = ( blockName, blockStyle ) => ( {
229
- registry,
230
- } ) => {
231
- if ( ! blockName ) {
232
- return;
233
- }
234
-
235
- const existingVariations =
236
- registry
237
- .select( preferencesStore )
238
- .get( 'core/edit-post', 'preferredStyleVariations' ) ?? {};
239
-
240
- // When the blockStyle is omitted, remove the block's preferred variation.
241
- if ( ! blockStyle ) {
242
- const updatedVariations = {
243
- ...existingVariations,
244
- };
247
+ export const updatePreferredStyleVariations =
248
+ ( blockName, blockStyle ) =>
249
+ ( { registry } ) => {
250
+ if ( ! blockName ) {
251
+ return;
252
+ }
245
253
 
246
- delete updatedVariations[ blockName ];
254
+ const existingVariations =
255
+ registry
256
+ .select( preferencesStore )
257
+ .get( 'core/edit-post', 'preferredStyleVariations' ) ?? {};
247
258
 
248
- registry
249
- .dispatch( preferencesStore )
250
- .set(
251
- 'core/edit-post',
252
- 'preferredStyleVariations',
253
- updatedVariations
254
- );
255
- } else {
256
- // Else add the variation.
257
- registry
258
- .dispatch( preferencesStore )
259
- .set( 'core/edit-post', 'preferredStyleVariations', {
259
+ // When the blockStyle is omitted, remove the block's preferred variation.
260
+ if ( ! blockStyle ) {
261
+ const updatedVariations = {
260
262
  ...existingVariations,
261
- [ blockName ]: blockStyle,
262
- } );
263
- }
264
- };
263
+ };
264
+
265
+ delete updatedVariations[ blockName ];
266
+
267
+ registry
268
+ .dispatch( preferencesStore )
269
+ .set(
270
+ 'core/edit-post',
271
+ 'preferredStyleVariations',
272
+ updatedVariations
273
+ );
274
+ } else {
275
+ // Else add the variation.
276
+ registry
277
+ .dispatch( preferencesStore )
278
+ .set( 'core/edit-post', 'preferredStyleVariations', {
279
+ ...existingVariations,
280
+ [ blockName ]: blockStyle,
281
+ } );
282
+ }
283
+ };
265
284
 
266
285
  /**
267
286
  * Update the provided block types to be visible.
268
287
  *
269
288
  * @param {string[]} blockNames Names of block types to show.
270
289
  */
271
- export const showBlockTypes = ( blockNames ) => ( { registry } ) => {
272
- const existingBlockNames =
273
- registry
274
- .select( preferencesStore )
275
- .get( 'core/edit-post', 'hiddenBlockTypes' ) ?? [];
276
-
277
- const newBlockNames = without(
278
- existingBlockNames,
279
- ...castArray( blockNames )
280
- );
290
+ export const showBlockTypes =
291
+ ( blockNames ) =>
292
+ ( { registry } ) => {
293
+ const existingBlockNames =
294
+ registry
295
+ .select( preferencesStore )
296
+ .get( 'core/edit-post', 'hiddenBlockTypes' ) ?? [];
297
+
298
+ const newBlockNames = without(
299
+ existingBlockNames,
300
+ ...castArray( blockNames )
301
+ );
281
302
 
282
- registry
283
- .dispatch( preferencesStore )
284
- .set( 'core/edit-post', 'hiddenBlockTypes', newBlockNames );
285
- };
303
+ registry
304
+ .dispatch( preferencesStore )
305
+ .set( 'core/edit-post', 'hiddenBlockTypes', newBlockNames );
306
+ };
286
307
 
287
308
  /**
288
309
  * Update the provided block types to be hidden.
289
310
  *
290
311
  * @param {string[]} blockNames Names of block types to hide.
291
312
  */
292
- export const hideBlockTypes = ( blockNames ) => ( { registry } ) => {
293
- const existingBlockNames =
294
- registry
295
- .select( preferencesStore )
296
- .get( 'core/edit-post', 'hiddenBlockTypes' ) ?? [];
297
-
298
- const mergedBlockNames = new Set( [
299
- ...existingBlockNames,
300
- ...castArray( blockNames ),
301
- ] );
313
+ export const hideBlockTypes =
314
+ ( blockNames ) =>
315
+ ( { registry } ) => {
316
+ const existingBlockNames =
317
+ registry
318
+ .select( preferencesStore )
319
+ .get( 'core/edit-post', 'hiddenBlockTypes' ) ?? [];
320
+
321
+ const mergedBlockNames = new Set( [
322
+ ...existingBlockNames,
323
+ ...castArray( blockNames ),
324
+ ] );
302
325
 
303
- registry
304
- .dispatch( preferencesStore )
305
- .set( 'core/edit-post', 'hiddenBlockTypes', [ ...mergedBlockNames ] );
306
- };
326
+ registry
327
+ .dispatch( preferencesStore )
328
+ .set( 'core/edit-post', 'hiddenBlockTypes', [
329
+ ...mergedBlockNames,
330
+ ] );
331
+ };
307
332
 
308
333
  /**
309
334
  * Returns an action object used in signaling
@@ -311,82 +336,82 @@ export const hideBlockTypes = ( blockNames ) => ( { registry } ) => {
311
336
  *
312
337
  * @param {Object} metaBoxesPerLocation Meta boxes per location.
313
338
  */
314
- export const setAvailableMetaBoxesPerLocation = ( metaBoxesPerLocation ) => ( {
315
- dispatch,
316
- } ) =>
317
- dispatch( {
318
- type: 'SET_META_BOXES_PER_LOCATIONS',
319
- metaBoxesPerLocation,
320
- } );
339
+ export const setAvailableMetaBoxesPerLocation =
340
+ ( metaBoxesPerLocation ) =>
341
+ ( { dispatch } ) =>
342
+ dispatch( {
343
+ type: 'SET_META_BOXES_PER_LOCATIONS',
344
+ metaBoxesPerLocation,
345
+ } );
321
346
 
322
347
  /**
323
348
  * Update a metabox.
324
349
  */
325
- export const requestMetaBoxUpdates = () => async ( {
326
- registry,
327
- select,
328
- dispatch,
329
- } ) => {
330
- dispatch( {
331
- type: 'REQUEST_META_BOX_UPDATES',
332
- } );
333
-
334
- // Saves the wp_editor fields.
335
- if ( window.tinyMCE ) {
336
- window.tinyMCE.triggerSave();
337
- }
338
-
339
- // Additional data needed for backward compatibility.
340
- // If we do not provide this data, the post will be overridden with the default values.
341
- const post = registry.select( editorStore ).getCurrentPost();
342
- const additionalData = [
343
- post.comment_status ? [ 'comment_status', post.comment_status ] : false,
344
- post.ping_status ? [ 'ping_status', post.ping_status ] : false,
345
- post.sticky ? [ 'sticky', post.sticky ] : false,
346
- post.author ? [ 'post_author', post.author ] : false,
347
- ].filter( Boolean );
348
-
349
- // We gather all the metaboxes locations data and the base form data.
350
- const baseFormData = new window.FormData(
351
- document.querySelector( '.metabox-base-form' )
352
- );
353
- const activeMetaBoxLocations = select.getActiveMetaBoxLocations();
354
- const formDataToMerge = [
355
- baseFormData,
356
- ...activeMetaBoxLocations.map(
357
- ( location ) =>
358
- new window.FormData( getMetaBoxContainer( location ) )
359
- ),
360
- ];
361
-
362
- // Merge all form data objects into a single one.
363
- const formData = reduce(
364
- formDataToMerge,
365
- ( memo, currentFormData ) => {
366
- for ( const [ key, value ] of currentFormData ) {
367
- memo.append( key, value );
368
- }
369
- return memo;
370
- },
371
- new window.FormData()
372
- );
373
- additionalData.forEach( ( [ key, value ] ) =>
374
- formData.append( key, value )
375
- );
376
-
377
- try {
378
- // Save the metaboxes.
379
- await apiFetch( {
380
- url: window._wpMetaBoxUrl,
381
- method: 'POST',
382
- body: formData,
383
- parse: false,
350
+ export const requestMetaBoxUpdates =
351
+ () =>
352
+ async ( { registry, select, dispatch } ) => {
353
+ dispatch( {
354
+ type: 'REQUEST_META_BOX_UPDATES',
384
355
  } );
385
- dispatch.metaBoxUpdatesSuccess();
386
- } catch {
387
- dispatch.metaBoxUpdatesFailure();
388
- }
389
- };
356
+
357
+ // Saves the wp_editor fields.
358
+ if ( window.tinyMCE ) {
359
+ window.tinyMCE.triggerSave();
360
+ }
361
+
362
+ // Additional data needed for backward compatibility.
363
+ // If we do not provide this data, the post will be overridden with the default values.
364
+ const post = registry.select( editorStore ).getCurrentPost();
365
+ const additionalData = [
366
+ post.comment_status
367
+ ? [ 'comment_status', post.comment_status ]
368
+ : false,
369
+ post.ping_status ? [ 'ping_status', post.ping_status ] : false,
370
+ post.sticky ? [ 'sticky', post.sticky ] : false,
371
+ post.author ? [ 'post_author', post.author ] : false,
372
+ ].filter( Boolean );
373
+
374
+ // We gather all the metaboxes locations data and the base form data.
375
+ const baseFormData = new window.FormData(
376
+ document.querySelector( '.metabox-base-form' )
377
+ );
378
+ const activeMetaBoxLocations = select.getActiveMetaBoxLocations();
379
+ const formDataToMerge = [
380
+ baseFormData,
381
+ ...activeMetaBoxLocations.map(
382
+ ( location ) =>
383
+ new window.FormData( getMetaBoxContainer( location ) )
384
+ ),
385
+ ];
386
+
387
+ // Merge all form data objects into a single one.
388
+ const formData = reduce(
389
+ formDataToMerge,
390
+ ( memo, currentFormData ) => {
391
+ for ( const [ key, value ] of currentFormData ) {
392
+ memo.append( key, value );
393
+ }
394
+ return memo;
395
+ },
396
+ new window.FormData()
397
+ );
398
+ additionalData.forEach( ( [ key, value ] ) =>
399
+ formData.append( key, value )
400
+ );
401
+
402
+ try {
403
+ // Save the metaboxes.
404
+ await apiFetch( {
405
+ url: window._wpMetaBoxUrl,
406
+ method: 'POST',
407
+ body: formData,
408
+ parse: false,
409
+ } );
410
+ dispatch.metaBoxUpdatesSuccess();
411
+ } catch {
412
+ dispatch.metaBoxUpdatesFailure();
413
+ }
414
+ };
390
415
 
391
416
  /**
392
417
  * Returns an action object used to signal a successful meta box update.
@@ -474,103 +499,105 @@ export function setIsEditingTemplate( value ) {
474
499
  *
475
500
  * @param {boolean} newTemplate Is new template.
476
501
  */
477
- export const __unstableSwitchToTemplateMode = ( newTemplate = false ) => ( {
478
- registry,
479
- select,
480
- dispatch,
481
- } ) => {
482
- dispatch( setIsEditingTemplate( true ) );
483
- const isWelcomeGuideActive = select.isFeatureActive(
484
- 'welcomeGuideTemplate'
485
- );
486
- if ( ! isWelcomeGuideActive ) {
487
- const message = newTemplate
488
- ? __( "Custom template created. You're in template mode now." )
489
- : __(
490
- 'Editing template. Changes made here affect all posts and pages that use the template.'
491
- );
492
- registry.dispatch( noticesStore ).createSuccessNotice( message, {
493
- type: 'snackbar',
494
- } );
495
- }
496
- };
502
+ export const __unstableSwitchToTemplateMode =
503
+ ( newTemplate = false ) =>
504
+ ( { registry, select, dispatch } ) => {
505
+ dispatch( setIsEditingTemplate( true ) );
506
+ const isWelcomeGuideActive = select.isFeatureActive(
507
+ 'welcomeGuideTemplate'
508
+ );
509
+ if ( ! isWelcomeGuideActive ) {
510
+ const message = newTemplate
511
+ ? __( "Custom template created. You're in template mode now." )
512
+ : __(
513
+ 'Editing template. Changes made here affect all posts and pages that use the template.'
514
+ );
515
+ registry.dispatch( noticesStore ).createSuccessNotice( message, {
516
+ type: 'snackbar',
517
+ } );
518
+ }
519
+ };
497
520
 
498
521
  /**
499
522
  * Create a block based template.
500
523
  *
501
524
  * @param {Object?} template Template to create and assign.
502
525
  */
503
- export const __unstableCreateTemplate = ( template ) => async ( {
504
- registry,
505
- } ) => {
506
- const savedTemplate = await registry
507
- .dispatch( coreStore )
508
- .saveEntityRecord( 'postType', 'wp_template', template );
509
- const post = registry.select( editorStore ).getCurrentPost();
510
- registry
511
- .dispatch( coreStore )
512
- .editEntityRecord( 'postType', post.type, post.id, {
513
- template: savedTemplate.slug,
514
- } );
515
- };
526
+ export const __unstableCreateTemplate =
527
+ ( template ) =>
528
+ async ( { registry } ) => {
529
+ const savedTemplate = await registry
530
+ .dispatch( coreStore )
531
+ .saveEntityRecord( 'postType', 'wp_template', template );
532
+ const post = registry.select( editorStore ).getCurrentPost();
533
+ registry
534
+ .dispatch( coreStore )
535
+ .editEntityRecord( 'postType', post.type, post.id, {
536
+ template: savedTemplate.slug,
537
+ } );
538
+ };
516
539
 
517
540
  let metaBoxesInitialized = false;
518
541
 
519
542
  /**
520
543
  * Initializes WordPress `postboxes` script and the logic for saving meta boxes.
521
544
  */
522
- export const initializeMetaBoxes = () => ( { registry, select, dispatch } ) => {
523
- const isEditorReady = registry
524
- .select( editorStore )
525
- .__unstableIsEditorReady();
526
-
527
- if ( ! isEditorReady ) {
528
- return;
529
- }
530
- // Only initialize once.
531
- if ( metaBoxesInitialized ) {
532
- return;
533
- }
534
- const postType = registry.select( editorStore ).getCurrentPostType();
535
- if ( window.postboxes.page !== postType ) {
536
- window.postboxes.add_postbox_toggles( postType );
537
- }
538
-
539
- metaBoxesInitialized = true;
540
-
541
- let wasSavingPost = registry.select( editorStore ).isSavingPost();
542
- let wasAutosavingPost = registry.select( editorStore ).isAutosavingPost();
543
- const hasMetaBoxes = select.hasMetaBoxes();
544
-
545
- // Save metaboxes when performing a full save on the post.
546
- registry.subscribe( async () => {
547
- const isSavingPost = registry.select( editorStore ).isSavingPost();
548
- const isAutosavingPost = registry
545
+ export const initializeMetaBoxes =
546
+ () =>
547
+ ( { registry, select, dispatch } ) => {
548
+ const isEditorReady = registry
549
549
  .select( editorStore )
550
- .isAutosavingPost();
550
+ .__unstableIsEditorReady();
551
551
 
552
- // Save metaboxes on save completion, except for autosaves that are not a post preview.
553
- //
554
- // Meta boxes are initialized once at page load. It is not necessary to
555
- // account for updates on each state change.
556
- //
557
- // See: https://github.com/WordPress/WordPress/blob/5.1.1/wp-admin/includes/post.php#L2307-L2309.
558
- const shouldTriggerMetaboxesSave =
559
- hasMetaBoxes &&
560
- wasSavingPost &&
561
- ! isSavingPost &&
562
- ! wasAutosavingPost;
563
-
564
- // Save current state for next inspection.
565
- wasSavingPost = isSavingPost;
566
- wasAutosavingPost = isAutosavingPost;
567
-
568
- if ( shouldTriggerMetaboxesSave ) {
569
- await dispatch.requestMetaBoxUpdates();
552
+ if ( ! isEditorReady ) {
553
+ return;
570
554
  }
571
- } );
555
+ // Only initialize once.
556
+ if ( metaBoxesInitialized ) {
557
+ return;
558
+ }
559
+ const postType = registry.select( editorStore ).getCurrentPostType();
560
+ if ( window.postboxes.page !== postType ) {
561
+ window.postboxes.add_postbox_toggles( postType );
562
+ }
563
+
564
+ metaBoxesInitialized = true;
565
+
566
+ let wasSavingPost = registry.select( editorStore ).isSavingPost();
567
+ let wasAutosavingPost = registry
568
+ .select( editorStore )
569
+ .isAutosavingPost();
570
+ const hasMetaBoxes = select.hasMetaBoxes();
571
+
572
+ // Save metaboxes when performing a full save on the post.
573
+ registry.subscribe( async () => {
574
+ const isSavingPost = registry.select( editorStore ).isSavingPost();
575
+ const isAutosavingPost = registry
576
+ .select( editorStore )
577
+ .isAutosavingPost();
578
+
579
+ // Save metaboxes on save completion, except for autosaves that are not a post preview.
580
+ //
581
+ // Meta boxes are initialized once at page load. It is not necessary to
582
+ // account for updates on each state change.
583
+ //
584
+ // See: https://github.com/WordPress/WordPress/blob/5.1.1/wp-admin/includes/post.php#L2307-L2309.
585
+ const shouldTriggerMetaboxesSave =
586
+ hasMetaBoxes &&
587
+ wasSavingPost &&
588
+ ! isSavingPost &&
589
+ ! wasAutosavingPost;
590
+
591
+ // Save current state for next inspection.
592
+ wasSavingPost = isSavingPost;
593
+ wasAutosavingPost = isAutosavingPost;
594
+
595
+ if ( shouldTriggerMetaboxesSave ) {
596
+ await dispatch.requestMetaBoxUpdates();
597
+ }
598
+ } );
572
599
 
573
- dispatch( {
574
- type: 'META_BOXES_INITIALIZED',
575
- } );
576
- };
600
+ dispatch( {
601
+ type: 'META_BOXES_INITIALIZED',
602
+ } );
603
+ };