@wordpress/editor 12.9.0 → 12.12.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 (224) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/build/components/document-outline/index.js +7 -9
  3. package/build/components/document-outline/index.js.map +1 -1
  4. package/build/components/editor-help/index.native.js.map +1 -1
  5. package/build/components/entities-saved-states/entity-record-item.js.map +1 -1
  6. package/build/components/entities-saved-states/index.js.map +1 -1
  7. package/build/components/error-boundary/index.js +3 -0
  8. package/build/components/error-boundary/index.js.map +1 -1
  9. package/build/components/global-keyboard-shortcuts/save-shortcut.js.map +1 -1
  10. package/build/components/index.js +61 -9
  11. package/build/components/index.js.map +1 -1
  12. package/build/components/local-autosave-monitor/index.js +24 -19
  13. package/build/components/local-autosave-monitor/index.js.map +1 -1
  14. package/build/components/page-attributes/order.js +3 -7
  15. package/build/components/page-attributes/order.js.map +1 -1
  16. package/build/components/page-attributes/parent.js +2 -2
  17. package/build/components/page-attributes/parent.js.map +1 -1
  18. package/build/components/post-author/select.js.map +1 -1
  19. package/build/components/post-comments/index.js.map +1 -1
  20. package/build/components/post-format/index.js +5 -8
  21. package/build/components/post-format/index.js.map +1 -1
  22. package/build/components/post-last-revision/check.js.map +1 -1
  23. package/build/components/post-last-revision/index.js.map +1 -1
  24. package/build/components/post-pending-status/check.js.map +1 -1
  25. package/build/components/post-pingbacks/index.js.map +1 -1
  26. package/build/components/post-publish-button/index.js +4 -2
  27. package/build/components/post-publish-button/index.js.map +1 -1
  28. package/build/components/post-publish-panel/index.js.map +1 -1
  29. package/build/components/post-publish-panel/maybe-category-panel.js +5 -5
  30. package/build/components/post-publish-panel/maybe-category-panel.js.map +1 -1
  31. package/build/components/post-publish-panel/maybe-post-format-panel.js.map +1 -1
  32. package/build/components/post-publish-panel/postpublish.js.map +1 -1
  33. package/build/components/post-publish-panel/prepublish.js.map +1 -1
  34. package/build/components/post-schedule/label.js +93 -13
  35. package/build/components/post-schedule/label.js.map +1 -1
  36. package/build/components/post-slug/index.js +8 -13
  37. package/build/components/post-slug/index.js.map +1 -1
  38. package/build/components/post-sticky/index.js.map +1 -1
  39. package/build/components/post-switch-to-draft-button/index.js.map +1 -1
  40. package/build/components/post-taxonomies/flat-term-selector.js +8 -4
  41. package/build/components/post-taxonomies/flat-term-selector.js.map +1 -1
  42. package/build/components/post-taxonomies/hierarchical-term-selector.js +1 -0
  43. package/build/components/post-taxonomies/hierarchical-term-selector.js.map +1 -1
  44. package/build/components/post-taxonomies/index.js +3 -1
  45. package/build/components/post-taxonomies/index.js.map +1 -1
  46. package/build/components/post-template/index.js +1 -2
  47. package/build/components/post-template/index.js.map +1 -1
  48. package/build/components/post-title/index.js.map +1 -1
  49. package/build/components/post-title/index.native.js.map +1 -1
  50. package/build/components/post-trash/check.js.map +1 -1
  51. package/build/components/post-url/check.js +54 -0
  52. package/build/components/post-url/check.js.map +1 -0
  53. package/build/components/post-url/index.js +115 -0
  54. package/build/components/post-url/index.js.map +1 -0
  55. package/build/components/post-url/label.js +30 -0
  56. package/build/components/post-url/label.js.map +1 -0
  57. package/build/components/post-visibility/index.js +10 -11
  58. package/build/components/post-visibility/index.js.map +1 -1
  59. package/build/components/post-visibility/label.js +5 -0
  60. package/build/components/post-visibility/label.js.map +1 -1
  61. package/build/components/provider/index.js.map +1 -1
  62. package/build/components/provider/index.native.js +0 -1
  63. package/build/components/provider/index.native.js.map +1 -1
  64. package/build/components/provider/use-block-editor-settings.js +3 -1
  65. package/build/components/provider/use-block-editor-settings.js.map +1 -1
  66. package/build/components/table-of-contents/panel.js +5 -1
  67. package/build/components/table-of-contents/panel.js.map +1 -1
  68. package/build/components/template-validation-notice/index.js.map +1 -1
  69. package/build/components/theme-support-check/index.js +1 -1
  70. package/build/components/theme-support-check/index.js.map +1 -1
  71. package/build/components/time-to-read/index.js +60 -0
  72. package/build/components/time-to-read/index.js.map +1 -0
  73. package/build/hooks/custom-sources-backwards-compatibility.js.map +1 -1
  74. package/build/store/actions.js +5 -1
  75. package/build/store/actions.js.map +1 -1
  76. package/build/store/reducer.js +1 -1
  77. package/build/store/reducer.js.map +1 -1
  78. package/build/store/selectors.js +2 -2
  79. package/build/store/selectors.js.map +1 -1
  80. package/build/utils/media-upload/index.js +4 -8
  81. package/build/utils/media-upload/index.js.map +1 -1
  82. package/build-module/components/document-outline/index.js +7 -8
  83. package/build-module/components/document-outline/index.js.map +1 -1
  84. package/build-module/components/editor-help/index.native.js.map +1 -1
  85. package/build-module/components/entities-saved-states/entity-record-item.js.map +1 -1
  86. package/build-module/components/entities-saved-states/index.js.map +1 -1
  87. package/build-module/components/error-boundary/index.js +2 -0
  88. package/build-module/components/error-boundary/index.js.map +1 -1
  89. package/build-module/components/global-keyboard-shortcuts/save-shortcut.js.map +1 -1
  90. package/build-module/components/index.js +7 -4
  91. package/build-module/components/index.js.map +1 -1
  92. package/build-module/components/local-autosave-monitor/index.js +24 -18
  93. package/build-module/components/local-autosave-monitor/index.js.map +1 -1
  94. package/build-module/components/page-attributes/order.js +3 -6
  95. package/build-module/components/page-attributes/order.js.map +1 -1
  96. package/build-module/components/page-attributes/parent.js +3 -3
  97. package/build-module/components/page-attributes/parent.js.map +1 -1
  98. package/build-module/components/post-author/select.js.map +1 -1
  99. package/build-module/components/post-comments/index.js.map +1 -1
  100. package/build-module/components/post-format/index.js +5 -8
  101. package/build-module/components/post-format/index.js.map +1 -1
  102. package/build-module/components/post-last-revision/check.js.map +1 -1
  103. package/build-module/components/post-last-revision/index.js.map +1 -1
  104. package/build-module/components/post-pending-status/check.js.map +1 -1
  105. package/build-module/components/post-pingbacks/index.js.map +1 -1
  106. package/build-module/components/post-publish-button/index.js +4 -1
  107. package/build-module/components/post-publish-button/index.js.map +1 -1
  108. package/build-module/components/post-publish-panel/index.js.map +1 -1
  109. package/build-module/components/post-publish-panel/maybe-category-panel.js +5 -5
  110. package/build-module/components/post-publish-panel/maybe-category-panel.js.map +1 -1
  111. package/build-module/components/post-publish-panel/maybe-post-format-panel.js.map +1 -1
  112. package/build-module/components/post-publish-panel/postpublish.js.map +1 -1
  113. package/build-module/components/post-publish-panel/prepublish.js.map +1 -1
  114. package/build-module/components/post-schedule/label.js +90 -13
  115. package/build-module/components/post-schedule/label.js.map +1 -1
  116. package/build-module/components/post-slug/index.js +8 -14
  117. package/build-module/components/post-slug/index.js.map +1 -1
  118. package/build-module/components/post-sticky/index.js.map +1 -1
  119. package/build-module/components/post-switch-to-draft-button/index.js.map +1 -1
  120. package/build-module/components/post-taxonomies/flat-term-selector.js +8 -6
  121. package/build-module/components/post-taxonomies/flat-term-selector.js.map +1 -1
  122. package/build-module/components/post-taxonomies/hierarchical-term-selector.js +1 -2
  123. package/build-module/components/post-taxonomies/hierarchical-term-selector.js.map +1 -1
  124. package/build-module/components/post-taxonomies/index.js +4 -1
  125. package/build-module/components/post-taxonomies/index.js.map +1 -1
  126. package/build-module/components/post-template/index.js +1 -2
  127. package/build-module/components/post-template/index.js.map +1 -1
  128. package/build-module/components/post-title/index.js.map +1 -1
  129. package/build-module/components/post-title/index.native.js.map +1 -1
  130. package/build-module/components/post-trash/check.js.map +1 -1
  131. package/build-module/components/post-url/check.js +44 -0
  132. package/build-module/components/post-url/check.js.map +1 -0
  133. package/build-module/components/post-url/index.js +102 -0
  134. package/build-module/components/post-url/index.js.map +1 -0
  135. package/build-module/components/post-url/label.js +18 -0
  136. package/build-module/components/post-url/label.js.map +1 -0
  137. package/build-module/components/post-visibility/index.js +12 -13
  138. package/build-module/components/post-visibility/index.js.map +1 -1
  139. package/build-module/components/post-visibility/label.js +3 -0
  140. package/build-module/components/post-visibility/label.js.map +1 -1
  141. package/build-module/components/provider/index.js.map +1 -1
  142. package/build-module/components/provider/index.native.js +0 -1
  143. package/build-module/components/provider/index.native.js.map +1 -1
  144. package/build-module/components/provider/use-block-editor-settings.js +4 -2
  145. package/build-module/components/provider/use-block-editor-settings.js.map +1 -1
  146. package/build-module/components/table-of-contents/panel.js +4 -1
  147. package/build-module/components/table-of-contents/panel.js.map +1 -1
  148. package/build-module/components/template-validation-notice/index.js.map +1 -1
  149. package/build-module/components/theme-support-check/index.js +2 -2
  150. package/build-module/components/theme-support-check/index.js.map +1 -1
  151. package/build-module/components/time-to-read/index.js +50 -0
  152. package/build-module/components/time-to-read/index.js.map +1 -0
  153. package/build-module/hooks/custom-sources-backwards-compatibility.js.map +1 -1
  154. package/build-module/store/actions.js +5 -1
  155. package/build-module/store/actions.js.map +1 -1
  156. package/build-module/store/reducer.js +2 -2
  157. package/build-module/store/reducer.js.map +1 -1
  158. package/build-module/store/selectors.js +3 -3
  159. package/build-module/store/selectors.js.map +1 -1
  160. package/build-module/utils/media-upload/index.js +3 -5
  161. package/build-module/utils/media-upload/index.js.map +1 -1
  162. package/build-style/style-rtl.css +12 -30
  163. package/build-style/style.css +15 -29
  164. package/package.json +28 -28
  165. package/src/components/document-outline/index.js +9 -8
  166. package/src/components/editor-help/index.native.js +6 -6
  167. package/src/components/entities-saved-states/entity-record-item.js +6 -6
  168. package/src/components/entities-saved-states/index.js +6 -9
  169. package/src/components/error-boundary/index.js +3 -0
  170. package/src/components/global-keyboard-shortcuts/save-shortcut.js +2 -3
  171. package/src/components/index.js +13 -4
  172. package/src/components/local-autosave-monitor/index.js +39 -38
  173. package/src/components/page-attributes/order.js +1 -9
  174. package/src/components/page-attributes/parent.js +6 -10
  175. package/src/components/post-author/select.js +2 -3
  176. package/src/components/post-comments/index.js +4 -3
  177. package/src/components/post-format/index.js +15 -22
  178. package/src/components/post-format/style.scss +2 -17
  179. package/src/components/post-last-revision/check.js +2 -4
  180. package/src/components/post-last-revision/index.js +2 -4
  181. package/src/components/post-pending-status/check.js +2 -5
  182. package/src/components/post-pingbacks/index.js +2 -3
  183. package/src/components/post-publish-button/index.js +7 -8
  184. package/src/components/post-publish-panel/index.js +2 -3
  185. package/src/components/post-publish-panel/maybe-category-panel.js +7 -5
  186. package/src/components/post-publish-panel/maybe-post-format-panel.js +2 -3
  187. package/src/components/post-publish-panel/postpublish.js +2 -5
  188. package/src/components/post-publish-panel/prepublish.js +2 -3
  189. package/src/components/post-publish-panel/test/__snapshots__/index.js.snap +1 -1
  190. package/src/components/post-schedule/label.js +111 -17
  191. package/src/components/post-schedule/test/label.js +127 -15
  192. package/src/components/post-slug/index.js +9 -16
  193. package/src/components/post-slug/test/index.js +7 -6
  194. package/src/components/post-sticky/index.js +2 -3
  195. package/src/components/post-switch-to-draft-button/index.js +2 -5
  196. package/src/components/post-taxonomies/flat-term-selector.js +10 -13
  197. package/src/components/post-taxonomies/hierarchical-term-selector.js +5 -7
  198. package/src/components/post-taxonomies/index.js +3 -1
  199. package/src/components/post-template/index.js +1 -1
  200. package/src/components/post-title/index.js +21 -31
  201. package/src/components/post-title/index.native.js +10 -16
  202. package/src/components/post-title/style.scss +1 -1
  203. package/src/components/post-trash/check.js +2 -3
  204. package/src/components/post-url/check.js +38 -0
  205. package/src/components/post-url/index.js +122 -0
  206. package/src/components/post-url/label.js +22 -0
  207. package/src/components/post-url/style.scss +16 -0
  208. package/src/components/post-visibility/index.js +11 -17
  209. package/src/components/post-visibility/label.js +4 -0
  210. package/src/components/post-visibility/style.scss +0 -17
  211. package/src/components/provider/index.js +2 -3
  212. package/src/components/provider/index.native.js +12 -17
  213. package/src/components/provider/use-block-editor-settings.js +4 -8
  214. package/src/components/table-of-contents/panel.js +7 -2
  215. package/src/components/template-validation-notice/index.js +2 -3
  216. package/src/components/theme-support-check/index.js +2 -2
  217. package/src/components/time-to-read/index.js +59 -0
  218. package/src/hooks/custom-sources-backwards-compatibility.js +45 -44
  219. package/src/store/actions.js +213 -190
  220. package/src/store/reducer.js +2 -2
  221. package/src/store/selectors.js +17 -25
  222. package/src/store/test/selectors.js +10 -13
  223. package/src/style.scss +1 -0
  224. package/src/utils/media-upload/index.js +2 -5
@@ -42,55 +42,56 @@ import { store as editorStore } from '../store';
42
42
  */
43
43
  const createWithMetaAttributeSource = ( metaAttributes ) =>
44
44
  createHigherOrderComponent(
45
- ( BlockEdit ) => ( { attributes, setAttributes, ...props } ) => {
46
- const postType = useSelect(
47
- ( select ) => select( editorStore ).getCurrentPostType(),
48
- []
49
- );
50
- const [ meta, setMeta ] = useEntityProp(
51
- 'postType',
52
- postType,
53
- 'meta'
54
- );
45
+ ( BlockEdit ) =>
46
+ ( { attributes, setAttributes, ...props } ) => {
47
+ const postType = useSelect(
48
+ ( select ) => select( editorStore ).getCurrentPostType(),
49
+ []
50
+ );
51
+ const [ meta, setMeta ] = useEntityProp(
52
+ 'postType',
53
+ postType,
54
+ 'meta'
55
+ );
55
56
 
56
- const mergedAttributes = useMemo(
57
- () => ( {
58
- ...attributes,
59
- ...mapValues(
60
- metaAttributes,
61
- ( metaKey ) => meta[ metaKey ]
62
- ),
63
- } ),
64
- [ attributes, meta ]
65
- );
57
+ const mergedAttributes = useMemo(
58
+ () => ( {
59
+ ...attributes,
60
+ ...mapValues(
61
+ metaAttributes,
62
+ ( metaKey ) => meta[ metaKey ]
63
+ ),
64
+ } ),
65
+ [ attributes, meta ]
66
+ );
66
67
 
67
- return (
68
- <BlockEdit
69
- attributes={ mergedAttributes }
70
- setAttributes={ ( nextAttributes ) => {
71
- const nextMeta = mapKeys(
72
- // Filter to intersection of keys between the updated
73
- // attributes and those with an associated meta key.
74
- pickBy(
75
- nextAttributes,
76
- ( value, key ) => metaAttributes[ key ]
77
- ),
68
+ return (
69
+ <BlockEdit
70
+ attributes={ mergedAttributes }
71
+ setAttributes={ ( nextAttributes ) => {
72
+ const nextMeta = mapKeys(
73
+ // Filter to intersection of keys between the updated
74
+ // attributes and those with an associated meta key.
75
+ pickBy(
76
+ nextAttributes,
77
+ ( value, key ) => metaAttributes[ key ]
78
+ ),
78
79
 
79
- // Rename the keys to the expected meta key name.
80
- ( value, attributeKey ) =>
81
- metaAttributes[ attributeKey ]
82
- );
80
+ // Rename the keys to the expected meta key name.
81
+ ( value, attributeKey ) =>
82
+ metaAttributes[ attributeKey ]
83
+ );
83
84
 
84
- if ( ! isEmpty( nextMeta ) ) {
85
- setMeta( nextMeta );
86
- }
85
+ if ( ! isEmpty( nextMeta ) ) {
86
+ setMeta( nextMeta );
87
+ }
87
88
 
88
- setAttributes( nextAttributes );
89
- } }
90
- { ...props }
91
- />
92
- );
93
- },
89
+ setAttributes( nextAttributes );
90
+ } }
91
+ { ...props }
92
+ />
93
+ );
94
+ },
94
95
  'withMetaAttributeSource'
95
96
  );
96
97
 
@@ -37,35 +37,38 @@ import {
37
37
  * @param {Object} edits Initial edited attributes object.
38
38
  * @param {Array?} template Block Template.
39
39
  */
40
- export const setupEditor = ( post, edits, template ) => ( { dispatch } ) => {
41
- dispatch.setupEditorState( post );
42
- // Apply a template for new posts only, if exists.
43
- const isNewPost = post.status === 'auto-draft';
44
- if ( isNewPost && template ) {
45
- // In order to ensure maximum of a single parse during setup, edits are
46
- // included as part of editor setup action. Assume edited content as
47
- // canonical if provided, falling back to post.
48
- let content;
49
- if ( has( edits, [ 'content' ] ) ) {
50
- content = edits.content;
51
- } else {
52
- content = post.content.raw;
40
+ export const setupEditor =
41
+ ( post, edits, template ) =>
42
+ ( { dispatch } ) => {
43
+ dispatch.setupEditorState( post );
44
+ // Apply a template for new posts only, if exists.
45
+ const isNewPost = post.status === 'auto-draft';
46
+ if ( isNewPost && template ) {
47
+ // In order to ensure maximum of a single parse during setup, edits are
48
+ // included as part of editor setup action. Assume edited content as
49
+ // canonical if provided, falling back to post.
50
+ let content;
51
+ if ( has( edits, [ 'content' ] ) ) {
52
+ content = edits.content;
53
+ } else {
54
+ content = post.content.raw;
55
+ }
56
+ let blocks = parse( content );
57
+ blocks = synchronizeBlocksWithTemplate( blocks, template );
58
+ dispatch.resetEditorBlocks( blocks, {
59
+ __unstableShouldCreateUndoLevel: false,
60
+ } );
53
61
  }
54
- let blocks = parse( content );
55
- blocks = synchronizeBlocksWithTemplate( blocks, template );
56
- dispatch.resetEditorBlocks( blocks, {
57
- __unstableShouldCreateUndoLevel: false,
58
- } );
59
- }
60
- if (
61
- edits &&
62
- Object.values( edits ).some(
63
- ( [ key, edit ] ) => edit !== ( post[ key ]?.raw ?? post[ key ] )
64
- )
65
- ) {
66
- dispatch.editPost( edits );
67
- }
68
- };
62
+ if (
63
+ edits &&
64
+ Object.values( edits ).some(
65
+ ( [ key, edit ] ) =>
66
+ edit !== ( post[ key ]?.raw ?? post[ key ] )
67
+ )
68
+ ) {
69
+ dispatch.editPost( edits );
70
+ }
71
+ };
69
72
 
70
73
  /**
71
74
  * Returns an action object signalling that the editor is being destroyed and
@@ -131,89 +134,96 @@ export function setupEditorState( post ) {
131
134
  * @param {Object} edits Post attributes to edit.
132
135
  * @param {Object} options Options for the edit.
133
136
  */
134
- export const editPost = ( edits, options ) => ( { select, registry } ) => {
135
- const { id, type } = select.getCurrentPost();
136
- registry
137
- .dispatch( coreStore )
138
- .editEntityRecord( 'postType', type, id, edits, options );
139
- };
137
+ export const editPost =
138
+ ( edits, options ) =>
139
+ ( { select, registry } ) => {
140
+ const { id, type } = select.getCurrentPost();
141
+ registry
142
+ .dispatch( coreStore )
143
+ .editEntityRecord( 'postType', type, id, edits, options );
144
+ };
140
145
 
141
146
  /**
142
147
  * Action for saving the current post in the editor.
143
148
  *
144
149
  * @param {Object} options
145
150
  */
146
- export const savePost = ( options = {} ) => async ( {
147
- select,
148
- dispatch,
149
- registry,
150
- } ) => {
151
- if ( ! select.isEditedPostSaveable() ) {
152
- return;
153
- }
154
-
155
- const content = select.getEditedPostContent();
156
-
157
- if ( ! options.isAutosave ) {
158
- dispatch.editPost( { content }, { undoIgnore: true } );
159
- }
160
-
161
- const previousRecord = select.getCurrentPost();
162
- const edits = {
163
- id: previousRecord.id,
164
- ...registry
151
+ export const savePost =
152
+ ( options = {} ) =>
153
+ async ( { select, dispatch, registry } ) => {
154
+ if ( ! select.isEditedPostSaveable() ) {
155
+ return;
156
+ }
157
+
158
+ const content = select.getEditedPostContent();
159
+
160
+ if ( ! options.isAutosave ) {
161
+ dispatch.editPost( { content }, { undoIgnore: true } );
162
+ }
163
+
164
+ const previousRecord = select.getCurrentPost();
165
+ const edits = {
166
+ id: previousRecord.id,
167
+ ...registry
168
+ .select( coreStore )
169
+ .getEntityRecordNonTransientEdits(
170
+ 'postType',
171
+ previousRecord.type,
172
+ previousRecord.id
173
+ ),
174
+ content,
175
+ };
176
+ dispatch( { type: 'REQUEST_POST_UPDATE_START', options } );
177
+ await registry
178
+ .dispatch( coreStore )
179
+ .saveEntityRecord(
180
+ 'postType',
181
+ previousRecord.type,
182
+ edits,
183
+ options
184
+ );
185
+ dispatch( { type: 'REQUEST_POST_UPDATE_FINISH', options } );
186
+
187
+ const error = registry
165
188
  .select( coreStore )
166
- .getEntityRecordNonTransientEdits(
189
+ .getLastEntitySaveError(
167
190
  'postType',
168
191
  previousRecord.type,
169
192
  previousRecord.id
170
- ),
171
- content,
172
- };
173
- dispatch( { type: 'REQUEST_POST_UPDATE_START', options } );
174
- await registry
175
- .dispatch( coreStore )
176
- .saveEntityRecord( 'postType', previousRecord.type, edits, options );
177
- dispatch( { type: 'REQUEST_POST_UPDATE_FINISH', options } );
178
-
179
- const error = registry
180
- .select( coreStore )
181
- .getLastEntitySaveError(
182
- 'postType',
183
- previousRecord.type,
184
- previousRecord.id
185
- );
186
- if ( error ) {
187
- const args = getNotificationArgumentsForSaveFail( {
188
- post: previousRecord,
189
- edits,
190
- error,
191
- } );
192
- if ( args.length ) {
193
- registry.dispatch( noticesStore ).createErrorNotice( ...args );
194
- }
195
- } else {
196
- const updatedRecord = select.getCurrentPost();
197
- const args = getNotificationArgumentsForSaveSuccess( {
198
- previousPost: previousRecord,
199
- post: updatedRecord,
200
- postType: await registry
201
- .resolveSelect( coreStore )
202
- .getPostType( updatedRecord.type ),
203
- options,
204
- } );
205
- if ( args.length ) {
206
- registry.dispatch( noticesStore ).createSuccessNotice( ...args );
207
- }
208
- // Make sure that any edits after saving create an undo level and are
209
- // considered for change detection.
210
- if ( ! options.isAutosave ) {
211
- registry
212
- .dispatch( blockEditorStore )
213
- .__unstableMarkLastChangeAsPersistent();
193
+ );
194
+ if ( error ) {
195
+ const args = getNotificationArgumentsForSaveFail( {
196
+ post: previousRecord,
197
+ edits,
198
+ error,
199
+ } );
200
+ if ( args.length ) {
201
+ registry.dispatch( noticesStore ).createErrorNotice( ...args );
202
+ }
203
+ } else {
204
+ const updatedRecord = select.getCurrentPost();
205
+ const args = getNotificationArgumentsForSaveSuccess( {
206
+ previousPost: previousRecord,
207
+ post: updatedRecord,
208
+ postType: await registry
209
+ .resolveSelect( coreStore )
210
+ .getPostType( updatedRecord.type ),
211
+ options,
212
+ } );
213
+ if ( args.length ) {
214
+ registry
215
+ .dispatch( noticesStore )
216
+ .createSuccessNotice( ...args );
217
+ }
218
+ // Make sure that any edits after saving create an undo level and are
219
+ // considered for change detection.
220
+ if ( ! options.isAutosave ) {
221
+ registry
222
+ .dispatch( blockEditorStore )
223
+ .__unstableMarkLastChangeAsPersistent();
224
+ }
214
225
  }
215
- }
216
- };
226
+ };
217
227
 
218
228
  /**
219
229
  * Action for refreshing the current post.
@@ -232,28 +242,32 @@ export function refreshPost() {
232
242
  /**
233
243
  * Action for trashing the current post in the editor.
234
244
  */
235
- export const trashPost = () => async ( { select, dispatch, registry } ) => {
236
- const postTypeSlug = select.getCurrentPostType();
237
- const postType = await registry
238
- .resolveSelect( coreStore )
239
- .getPostType( postTypeSlug );
240
- registry.dispatch( noticesStore ).removeNotice( TRASH_POST_NOTICE_ID );
241
- try {
242
- const post = select.getCurrentPost();
243
- await apiFetch( {
244
- path: `/wp/v2/${ postType.rest_base }/${ post.id }`,
245
- method: 'DELETE',
246
- } );
247
-
248
- await dispatch.savePost();
249
- } catch ( error ) {
250
- registry
251
- .dispatch( noticesStore )
252
- .createErrorNotice(
253
- ...getNotificationArgumentsForTrashFail( { error } )
254
- );
255
- }
256
- };
245
+ export const trashPost =
246
+ () =>
247
+ async ( { select, dispatch, registry } ) => {
248
+ const postTypeSlug = select.getCurrentPostType();
249
+ const postType = await registry
250
+ .resolveSelect( coreStore )
251
+ .getPostType( postTypeSlug );
252
+ registry.dispatch( noticesStore ).removeNotice( TRASH_POST_NOTICE_ID );
253
+ const { rest_base: restBase, rest_namespace: restNamespace = 'wp/v2' } =
254
+ postType;
255
+ try {
256
+ const post = select.getCurrentPost();
257
+ await apiFetch( {
258
+ path: `/${ restNamespace }/${ restBase }/${ post.id }`,
259
+ method: 'DELETE',
260
+ } );
261
+
262
+ await dispatch.savePost();
263
+ } catch ( error ) {
264
+ registry
265
+ .dispatch( noticesStore )
266
+ .createErrorNotice(
267
+ ...getNotificationArgumentsForTrashFail( { error } )
268
+ );
269
+ }
270
+ };
257
271
 
258
272
  /**
259
273
  * Action that autosaves the current post. This
@@ -263,35 +277,38 @@ export const trashPost = () => async ( { select, dispatch, registry } ) => {
263
277
  *
264
278
  * @param {Object?} options Extra flags to identify the autosave.
265
279
  */
266
- export const autosave = ( { local = false, ...options } = {} ) => async ( {
267
- select,
268
- dispatch,
269
- } ) => {
270
- if ( local ) {
271
- const post = select.getCurrentPost();
272
- const isPostNew = select.isEditedPostNew();
273
- const title = select.getEditedPostAttribute( 'title' );
274
- const content = select.getEditedPostAttribute( 'content' );
275
- const excerpt = select.getEditedPostAttribute( 'excerpt' );
276
- localAutosaveSet( post.id, isPostNew, title, content, excerpt );
277
- } else {
278
- await dispatch.savePost( { isAutosave: true, ...options } );
279
- }
280
- };
280
+ export const autosave =
281
+ ( { local = false, ...options } = {} ) =>
282
+ async ( { select, dispatch } ) => {
283
+ if ( local ) {
284
+ const post = select.getCurrentPost();
285
+ const isPostNew = select.isEditedPostNew();
286
+ const title = select.getEditedPostAttribute( 'title' );
287
+ const content = select.getEditedPostAttribute( 'content' );
288
+ const excerpt = select.getEditedPostAttribute( 'excerpt' );
289
+ localAutosaveSet( post.id, isPostNew, title, content, excerpt );
290
+ } else {
291
+ await dispatch.savePost( { isAutosave: true, ...options } );
292
+ }
293
+ };
281
294
 
282
295
  /**
283
296
  * Action that restores last popped state in undo history.
284
297
  */
285
- export const redo = () => ( { registry } ) => {
286
- registry.dispatch( coreStore ).redo();
287
- };
298
+ export const redo =
299
+ () =>
300
+ ( { registry } ) => {
301
+ registry.dispatch( coreStore ).redo();
302
+ };
288
303
 
289
304
  /**
290
305
  * Action that pops a record from undo history and undoes the edit.
291
306
  */
292
- export const undo = () => ( { registry } ) => {
293
- registry.dispatch( coreStore ).undo();
294
- };
307
+ export const undo =
308
+ () =>
309
+ ( { registry } ) => {
310
+ registry.dispatch( coreStore ).undo();
311
+ };
295
312
 
296
313
  /**
297
314
  * Action that creates an undo history record.
@@ -323,20 +340,24 @@ export function updatePostLock( lock ) {
323
340
  /**
324
341
  * Enable the publish sidebar.
325
342
  */
326
- export const enablePublishSidebar = () => ( { registry } ) => {
327
- registry
328
- .dispatch( preferencesStore )
329
- .set( 'core/edit-post', 'isPublishSidebarEnabled', true );
330
- };
343
+ export const enablePublishSidebar =
344
+ () =>
345
+ ( { registry } ) => {
346
+ registry
347
+ .dispatch( preferencesStore )
348
+ .set( 'core/edit-post', 'isPublishSidebarEnabled', true );
349
+ };
331
350
 
332
351
  /**
333
352
  * Disables the publish sidebar.
334
353
  */
335
- export const disablePublishSidebar = () => ( { registry } ) => {
336
- registry
337
- .dispatch( preferencesStore )
338
- .set( 'core/edit-post', 'isPublishSidebarEnabled', false );
339
- };
354
+ export const disablePublishSidebar =
355
+ () =>
356
+ ( { registry } ) => {
357
+ registry
358
+ .dispatch( preferencesStore )
359
+ .set( 'core/edit-post', 'isPublishSidebarEnabled', false );
360
+ };
340
361
 
341
362
  /**
342
363
  * Action that locks post saving.
@@ -454,37 +475,35 @@ export function unlockPostAutosaving( lockName ) {
454
475
  * @param {Array} blocks Block Array.
455
476
  * @param {?Object} options Optional options.
456
477
  */
457
- export const resetEditorBlocks = ( blocks, options = {} ) => ( {
458
- select,
459
- dispatch,
460
- registry,
461
- } ) => {
462
- const { __unstableShouldCreateUndoLevel, selection } = options;
463
- const edits = { blocks, selection };
464
-
465
- if ( __unstableShouldCreateUndoLevel !== false ) {
466
- const { id, type } = select.getCurrentPost();
467
- const noChange =
468
- registry
469
- .select( coreStore )
470
- .getEditedEntityRecord( 'postType', type, id ).blocks ===
471
- edits.blocks;
472
- if ( noChange ) {
473
- registry
474
- .dispatch( coreStore )
475
- .__unstableCreateUndoLevel( 'postType', type, id );
476
- return;
478
+ export const resetEditorBlocks =
479
+ ( blocks, options = {} ) =>
480
+ ( { select, dispatch, registry } ) => {
481
+ const { __unstableShouldCreateUndoLevel, selection } = options;
482
+ const edits = { blocks, selection };
483
+
484
+ if ( __unstableShouldCreateUndoLevel !== false ) {
485
+ const { id, type } = select.getCurrentPost();
486
+ const noChange =
487
+ registry
488
+ .select( coreStore )
489
+ .getEditedEntityRecord( 'postType', type, id ).blocks ===
490
+ edits.blocks;
491
+ if ( noChange ) {
492
+ registry
493
+ .dispatch( coreStore )
494
+ .__unstableCreateUndoLevel( 'postType', type, id );
495
+ return;
496
+ }
497
+
498
+ // We create a new function here on every persistent edit
499
+ // to make sure the edit makes the post dirty and creates
500
+ // a new undo level.
501
+ edits.content = ( { blocks: blocksForSerialization = [] } ) =>
502
+ __unstableSerializeAndClean( blocksForSerialization );
477
503
  }
478
504
 
479
- // We create a new function here on every persistent edit
480
- // to make sure the edit makes the post dirty and creates
481
- // a new undo level.
482
- edits.content = ( { blocks: blocksForSerialization = [] } ) =>
483
- __unstableSerializeAndClean( blocksForSerialization );
484
- }
485
-
486
- dispatch.editPost( edits );
487
- };
505
+ dispatch.editPost( edits );
506
+ };
488
507
 
489
508
  /*
490
509
  * Returns an action object used in signalling that the post editor settings have been updated.
@@ -504,14 +523,18 @@ export function updateEditorSettings( settings ) {
504
523
  * Backward compatibility
505
524
  */
506
525
 
507
- const getBlockEditorAction = ( name ) => ( ...args ) => ( { registry } ) => {
508
- deprecated( "`wp.data.dispatch( 'core/editor' )." + name + '`', {
509
- since: '5.3',
510
- alternative: "`wp.data.dispatch( 'core/block-editor' )." + name + '`',
511
- version: '6.2',
512
- } );
513
- registry.dispatch( blockEditorStore )[ name ]( ...args );
514
- };
526
+ const getBlockEditorAction =
527
+ ( name ) =>
528
+ ( ...args ) =>
529
+ ( { registry } ) => {
530
+ deprecated( "`wp.data.dispatch( 'core/editor' )." + name + '`', {
531
+ since: '5.3',
532
+ alternative:
533
+ "`wp.data.dispatch( 'core/block-editor' )." + name + '`',
534
+ version: '6.2',
535
+ } );
536
+ registry.dispatch( blockEditorStore )[ name ]( ...args );
537
+ };
515
538
 
516
539
  /**
517
540
  * @see resetBlocks in core/block-editor store.
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * External dependencies
3
3
  */
4
- import { omit, keys, isEqual } from 'lodash';
4
+ import { omit, isEqual } from 'lodash';
5
5
 
6
6
  /**
7
7
  * WordPress dependencies
@@ -39,7 +39,7 @@ export function getPostRawValue( value ) {
39
39
  * @return {boolean} Whether the two objects have the same keys.
40
40
  */
41
41
  export function hasSameKeys( a, b ) {
42
- return isEqual( keys( a ), keys( b ) );
42
+ return isEqual( Object.keys( a ), Object.keys( b ) );
43
43
  }
44
44
 
45
45
  /**