@wordpress/edit-post 7.25.0 → 7.26.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 (199) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/LICENSE.md +1 -1
  3. package/build/components/browser-url/index.js +3 -2
  4. package/build/components/browser-url/index.js.map +1 -1
  5. package/build/components/header/index.js +25 -25
  6. package/build/components/header/index.js.map +1 -1
  7. package/build/components/header/writing-menu/index.js +11 -8
  8. package/build/components/header/writing-menu/index.js.map +1 -1
  9. package/build/components/keyboard-shortcuts/index.js +1 -20
  10. package/build/components/keyboard-shortcuts/index.js.map +1 -1
  11. package/build/components/layout/index.js +33 -26
  12. package/build/components/layout/index.js.map +1 -1
  13. package/build/components/layout/index.native.js +3 -1
  14. package/build/components/layout/index.native.js.map +1 -1
  15. package/build/components/meta-boxes/meta-box-visibility.js +2 -6
  16. package/build/components/meta-boxes/meta-box-visibility.js.map +1 -1
  17. package/build/components/preferences-modal/index.js +25 -8
  18. package/build/components/preferences-modal/index.js.map +1 -1
  19. package/build/components/preferences-modal/options/enable-feature.js +23 -23
  20. package/build/components/preferences-modal/options/enable-feature.js.map +1 -1
  21. package/build/components/preferences-modal/options/enable-panel.js +3 -6
  22. package/build/components/preferences-modal/options/enable-panel.js.map +1 -1
  23. package/build/components/sidebar/plugin-document-setting-panel/index.js +3 -3
  24. package/build/components/sidebar/plugin-document-setting-panel/index.js.map +1 -1
  25. package/build/components/sidebar/plugin-sidebar/index.js +2 -10
  26. package/build/components/sidebar/plugin-sidebar/index.js.map +1 -1
  27. package/build/components/sidebar/post-status/index.js +2 -3
  28. package/build/components/sidebar/post-status/index.js.map +1 -1
  29. package/build/components/sidebar/settings-sidebar/index.js +1 -7
  30. package/build/components/sidebar/settings-sidebar/index.js.map +1 -1
  31. package/build/editor.js +19 -28
  32. package/build/editor.js.map +1 -1
  33. package/build/editor.native.js +3 -10
  34. package/build/editor.native.js.map +1 -1
  35. package/build/hooks/commands/use-common-commands.js +16 -12
  36. package/build/hooks/commands/use-common-commands.js.map +1 -1
  37. package/build/hooks/use-post-history.js +79 -0
  38. package/build/hooks/use-post-history.js.map +1 -0
  39. package/build/index.js +19 -16
  40. package/build/index.js.map +1 -1
  41. package/build/index.native.js +7 -1
  42. package/build/index.native.js.map +1 -1
  43. package/build/store/actions.js +59 -73
  44. package/build/store/actions.js.map +1 -1
  45. package/build/store/reducer.js +1 -62
  46. package/build/store/reducer.js.map +1 -1
  47. package/build/store/selectors.js +66 -38
  48. package/build/store/selectors.js.map +1 -1
  49. package/build-module/components/browser-url/index.js +3 -2
  50. package/build-module/components/browser-url/index.js.map +1 -1
  51. package/build-module/components/header/index.js +25 -25
  52. package/build-module/components/header/index.js.map +1 -1
  53. package/build-module/components/header/writing-menu/index.js +11 -8
  54. package/build-module/components/header/writing-menu/index.js.map +1 -1
  55. package/build-module/components/keyboard-shortcuts/index.js +1 -20
  56. package/build-module/components/keyboard-shortcuts/index.js.map +1 -1
  57. package/build-module/components/layout/index.js +33 -25
  58. package/build-module/components/layout/index.js.map +1 -1
  59. package/build-module/components/layout/index.native.js +4 -2
  60. package/build-module/components/layout/index.native.js.map +1 -1
  61. package/build-module/components/meta-boxes/meta-box-visibility.js +2 -6
  62. package/build-module/components/meta-boxes/meta-box-visibility.js.map +1 -1
  63. package/build-module/components/preferences-modal/index.js +25 -8
  64. package/build-module/components/preferences-modal/index.js.map +1 -1
  65. package/build-module/components/preferences-modal/options/enable-feature.js +22 -23
  66. package/build-module/components/preferences-modal/options/enable-feature.js.map +1 -1
  67. package/build-module/components/preferences-modal/options/enable-panel.js +3 -7
  68. package/build-module/components/preferences-modal/options/enable-panel.js.map +1 -1
  69. package/build-module/components/sidebar/plugin-document-setting-panel/index.js +3 -3
  70. package/build-module/components/sidebar/plugin-document-setting-panel/index.js.map +1 -1
  71. package/build-module/components/sidebar/plugin-sidebar/index.js +2 -10
  72. package/build-module/components/sidebar/plugin-sidebar/index.js.map +1 -1
  73. package/build-module/components/sidebar/post-status/index.js +3 -4
  74. package/build-module/components/sidebar/post-status/index.js.map +1 -1
  75. package/build-module/components/sidebar/settings-sidebar/index.js +2 -8
  76. package/build-module/components/sidebar/settings-sidebar/index.js.map +1 -1
  77. package/build-module/editor.js +19 -28
  78. package/build-module/editor.js.map +1 -1
  79. package/build-module/editor.native.js +3 -10
  80. package/build-module/editor.native.js.map +1 -1
  81. package/build-module/hooks/commands/use-common-commands.js +16 -12
  82. package/build-module/hooks/commands/use-common-commands.js.map +1 -1
  83. package/build-module/hooks/use-post-history.js +73 -0
  84. package/build-module/hooks/use-post-history.js.map +1 -0
  85. package/build-module/index.js +17 -11
  86. package/build-module/index.js.map +1 -1
  87. package/build-module/index.native.js +7 -1
  88. package/build-module/index.native.js.map +1 -1
  89. package/build-module/store/actions.js +55 -69
  90. package/build-module/store/actions.js.map +1 -1
  91. package/build-module/store/reducer.js +1 -60
  92. package/build-module/store/reducer.js.map +1 -1
  93. package/build-module/store/selectors.js +58 -29
  94. package/build-module/store/selectors.js.map +1 -1
  95. package/build-style/style-rtl.css +13 -284
  96. package/build-style/style.css +13 -284
  97. package/package.json +32 -32
  98. package/src/components/browser-url/index.js +4 -2
  99. package/src/components/header/index.js +24 -40
  100. package/src/components/header/style.scss +3 -3
  101. package/src/components/header/writing-menu/index.js +10 -8
  102. package/src/components/keyboard-shortcut-help-modal/test/index.js +0 -15
  103. package/src/components/keyboard-shortcuts/index.js +1 -23
  104. package/src/components/layout/index.js +18 -27
  105. package/src/components/layout/index.native.js +9 -1
  106. package/src/components/meta-boxes/meta-box-visibility.js +2 -8
  107. package/src/components/preferences-modal/index.js +27 -9
  108. package/src/components/preferences-modal/options/enable-feature.js +26 -21
  109. package/src/components/preferences-modal/options/enable-panel.js +3 -7
  110. package/src/components/preferences-modal/test/__snapshots__/meta-boxes-section.js.snap +187 -175
  111. package/src/components/sidebar/plugin-document-setting-panel/index.js +3 -3
  112. package/src/components/sidebar/plugin-sidebar/index.js +1 -9
  113. package/src/components/sidebar/post-status/index.js +3 -3
  114. package/src/components/sidebar/settings-sidebar/index.js +15 -13
  115. package/src/components/text-editor/style.scss +0 -6
  116. package/src/editor.js +34 -33
  117. package/src/editor.native.js +2 -17
  118. package/src/hooks/commands/use-common-commands.js +14 -16
  119. package/src/hooks/use-post-history.js +73 -0
  120. package/src/index.js +22 -12
  121. package/src/index.native.js +8 -1
  122. package/src/store/actions.js +48 -85
  123. package/src/store/reducer.js +0 -60
  124. package/src/store/selectors.js +74 -46
  125. package/src/store/test/actions.js +10 -103
  126. package/src/store/test/reducer.js +1 -108
  127. package/src/store/test/selectors.js +0 -50
  128. package/src/style.scss +1 -5
  129. package/src/test/editor.native.js +17 -0
  130. package/build/components/header/header-toolbar/index.js +0 -160
  131. package/build/components/header/header-toolbar/index.js.map +0 -1
  132. package/build/components/secondary-sidebar/inserter-sidebar.js +0 -73
  133. package/build/components/secondary-sidebar/inserter-sidebar.js.map +0 -1
  134. package/build/components/secondary-sidebar/list-view-outline.js +0 -112
  135. package/build/components/secondary-sidebar/list-view-outline.js.map +0 -1
  136. package/build/components/secondary-sidebar/list-view-sidebar.js +0 -148
  137. package/build/components/secondary-sidebar/list-view-sidebar.js.map +0 -1
  138. package/build/components/sidebar/discussion-panel/index.js +0 -59
  139. package/build/components/sidebar/discussion-panel/index.js.map +0 -1
  140. package/build/components/sidebar/featured-image/index.js +0 -70
  141. package/build/components/sidebar/featured-image/index.js.map +0 -1
  142. package/build/components/sidebar/last-revision/index.js +0 -21
  143. package/build/components/sidebar/last-revision/index.js.map +0 -1
  144. package/build/components/sidebar/page-attributes/index.js +0 -65
  145. package/build/components/sidebar/page-attributes/index.js.map +0 -1
  146. package/build/components/sidebar/plugin-post-excerpt/index.js +0 -72
  147. package/build/components/sidebar/plugin-post-excerpt/index.js.map +0 -1
  148. package/build/components/sidebar/post-excerpt/index.js +0 -54
  149. package/build/components/sidebar/post-excerpt/index.js.map +0 -1
  150. package/build/components/sidebar/post-taxonomies/index.js +0 -30
  151. package/build/components/sidebar/post-taxonomies/index.js.map +0 -1
  152. package/build/components/sidebar/post-taxonomies/taxonomy-panel.js +0 -56
  153. package/build/components/sidebar/post-taxonomies/taxonomy-panel.js.map +0 -1
  154. package/build/components/view-link/index.js +0 -53
  155. package/build/components/view-link/index.js.map +0 -1
  156. package/build-module/components/header/header-toolbar/index.js +0 -152
  157. package/build-module/components/header/header-toolbar/index.js.map +0 -1
  158. package/build-module/components/secondary-sidebar/inserter-sidebar.js +0 -66
  159. package/build-module/components/secondary-sidebar/inserter-sidebar.js.map +0 -1
  160. package/build-module/components/secondary-sidebar/list-view-outline.js +0 -105
  161. package/build-module/components/secondary-sidebar/list-view-outline.js.map +0 -1
  162. package/build-module/components/secondary-sidebar/list-view-sidebar.js +0 -140
  163. package/build-module/components/secondary-sidebar/list-view-sidebar.js.map +0 -1
  164. package/build-module/components/sidebar/discussion-panel/index.js +0 -52
  165. package/build-module/components/sidebar/discussion-panel/index.js.map +0 -1
  166. package/build-module/components/sidebar/featured-image/index.js +0 -63
  167. package/build-module/components/sidebar/featured-image/index.js.map +0 -1
  168. package/build-module/components/sidebar/last-revision/index.js +0 -13
  169. package/build-module/components/sidebar/last-revision/index.js.map +0 -1
  170. package/build-module/components/sidebar/page-attributes/index.js +0 -57
  171. package/build-module/components/sidebar/page-attributes/index.js.map +0 -1
  172. package/build-module/components/sidebar/plugin-post-excerpt/index.js +0 -64
  173. package/build-module/components/sidebar/plugin-post-excerpt/index.js.map +0 -1
  174. package/build-module/components/sidebar/post-excerpt/index.js +0 -47
  175. package/build-module/components/sidebar/post-excerpt/index.js.map +0 -1
  176. package/build-module/components/sidebar/post-taxonomies/index.js +0 -21
  177. package/build-module/components/sidebar/post-taxonomies/index.js.map +0 -1
  178. package/build-module/components/sidebar/post-taxonomies/taxonomy-panel.js +0 -48
  179. package/build-module/components/sidebar/post-taxonomies/taxonomy-panel.js.map +0 -1
  180. package/build-module/components/view-link/index.js +0 -46
  181. package/build-module/components/view-link/index.js.map +0 -1
  182. package/src/components/header/header-toolbar/index.js +0 -186
  183. package/src/components/header/header-toolbar/style.scss +0 -116
  184. package/src/components/keyboard-shortcut-help-modal/test/__snapshots__/index.js.snap +0 -929
  185. package/src/components/secondary-sidebar/inserter-sidebar.js +0 -71
  186. package/src/components/secondary-sidebar/list-view-outline.js +0 -98
  187. package/src/components/secondary-sidebar/list-view-sidebar.js +0 -170
  188. package/src/components/secondary-sidebar/style.scss +0 -120
  189. package/src/components/sidebar/discussion-panel/index.js +0 -62
  190. package/src/components/sidebar/featured-image/index.js +0 -67
  191. package/src/components/sidebar/last-revision/index.js +0 -17
  192. package/src/components/sidebar/last-revision/style.scss +0 -10
  193. package/src/components/sidebar/page-attributes/index.js +0 -65
  194. package/src/components/sidebar/plugin-post-excerpt/index.js +0 -61
  195. package/src/components/sidebar/plugin-post-excerpt/test/index.js +0 -36
  196. package/src/components/sidebar/post-excerpt/index.js +0 -59
  197. package/src/components/sidebar/post-taxonomies/index.js +0 -30
  198. package/src/components/sidebar/post-taxonomies/taxonomy-panel.js +0 -48
  199. package/src/components/view-link/index.js +0 -48
package/src/editor.js CHANGED
@@ -14,7 +14,6 @@ import { SlotFillProvider } from '@wordpress/components';
14
14
  import { store as coreStore } from '@wordpress/core-data';
15
15
  import { store as preferencesStore } from '@wordpress/preferences';
16
16
  import { CommandMenu } from '@wordpress/commands';
17
- import { useViewportMatch } from '@wordpress/compose';
18
17
 
19
18
  /**
20
19
  * Internal dependencies
@@ -23,22 +22,28 @@ import Layout from './components/layout';
23
22
  import EditorInitialization from './components/editor-initialization';
24
23
  import { store as editPostStore } from './store';
25
24
  import { unlock } from './lock-unlock';
25
+ import usePostHistory from './hooks/use-post-history';
26
26
 
27
27
  const { ExperimentalEditorProvider } = unlock( editorPrivateApis );
28
28
 
29
- function Editor( { postId, postType, settings, initialEdits, ...props } ) {
30
- const isLargeViewport = useViewportMatch( 'medium' );
29
+ function Editor( {
30
+ postId: initialPostId,
31
+ postType: initialPostType,
32
+ settings,
33
+ initialEdits,
34
+ ...props
35
+ } ) {
36
+ const { currentPost, getPostLinkProps, goBack } = usePostHistory(
37
+ initialPostId,
38
+ initialPostType
39
+ );
31
40
 
32
41
  const {
33
- hasFixedToolbar,
34
- focusMode,
35
- isDistractionFree,
36
42
  hasInlineToolbar,
37
43
  post,
38
44
  preferredStyleVariations,
39
45
  hiddenBlockTypes,
40
46
  blockTypes,
41
- keepCaretInsideBlock,
42
47
  template,
43
48
  } = useSelect(
44
49
  ( select ) => {
@@ -52,28 +57,33 @@ function Editor( { postId, postType, settings, initialEdits, ...props } ) {
52
57
  const { getEditorSettings } = select( editorStore );
53
58
  const { getBlockTypes } = select( blocksStore );
54
59
  const isTemplate = [ 'wp_template', 'wp_template_part' ].includes(
55
- postType
60
+ currentPost.postType
56
61
  );
57
62
  // Ideally the initializeEditor function should be called using the ID of the REST endpoint.
58
63
  // to avoid the special case.
59
64
  let postObject;
60
65
  if ( isTemplate ) {
61
- const posts = getEntityRecords( 'postType', postType, {
62
- wp_id: postId,
63
- } );
66
+ const posts = getEntityRecords(
67
+ 'postType',
68
+ currentPost.postType,
69
+ {
70
+ wp_id: currentPost.postId,
71
+ }
72
+ );
64
73
  postObject = posts?.[ 0 ];
65
74
  } else {
66
- postObject = getEntityRecord( 'postType', postType, postId );
75
+ postObject = getEntityRecord(
76
+ 'postType',
77
+ currentPost.postType,
78
+ currentPost.postId
79
+ );
67
80
  }
68
81
  const supportsTemplateMode =
69
82
  getEditorSettings().supportsTemplateMode;
70
- const isViewable = getPostType( postType )?.viewable ?? false;
83
+ const isViewable =
84
+ getPostType( currentPost.postType )?.viewable ?? false;
71
85
  const canEditTemplate = canUser( 'create', 'templates' );
72
86
  return {
73
- hasFixedToolbar:
74
- isFeatureActive( 'fixedToolbar' ) || ! isLargeViewport,
75
- focusMode: isFeatureActive( 'focusMode' ),
76
- isDistractionFree: isFeatureActive( 'distractionFree' ),
77
87
  hasInlineToolbar: isFeatureActive( 'inlineToolbar' ),
78
88
  preferredStyleVariations: select( preferencesStore ).get(
79
89
  'core/edit-post',
@@ -81,7 +91,6 @@ function Editor( { postId, postType, settings, initialEdits, ...props } ) {
81
91
  ),
82
92
  hiddenBlockTypes: getHiddenBlockTypes(),
83
93
  blockTypes: getBlockTypes(),
84
- keepCaretInsideBlock: isFeatureActive( 'keepCaretInsideBlock' ),
85
94
  template:
86
95
  supportsTemplateMode && isViewable && canEditTemplate
87
96
  ? getEditedPostTemplate()
@@ -89,27 +98,22 @@ function Editor( { postId, postType, settings, initialEdits, ...props } ) {
89
98
  post: postObject,
90
99
  };
91
100
  },
92
- [ postType, postId, isLargeViewport ]
101
+ [ currentPost.postType, currentPost.postId ]
93
102
  );
94
103
 
95
- const { updatePreferredStyleVariations, setIsInserterOpened } =
96
- useDispatch( editPostStore );
104
+ const { updatePreferredStyleVariations } = useDispatch( editPostStore );
97
105
 
98
106
  const editorSettings = useMemo( () => {
99
107
  const result = {
100
108
  ...settings,
109
+ getPostLinkProps,
110
+ goBack,
101
111
  __experimentalPreferredStyleVariations: {
102
112
  value: preferredStyleVariations,
103
113
  onChange: updatePreferredStyleVariations,
104
114
  },
105
- hasFixedToolbar,
106
- focusMode,
107
- isDistractionFree,
108
115
  hasInlineToolbar,
109
116
 
110
- // This is marked as experimental to give time for the quick inserter to mature.
111
- __experimentalSetIsInserterOpened: setIsInserterOpened,
112
- keepCaretInsideBlock,
113
117
  // Keep a reference of the `allowedBlockTypes` from the server to handle use cases
114
118
  // where we need to differentiate if a block is disabled by the user or some plugin.
115
119
  defaultAllowedBlockTypes: settings.allowedBlockTypes,
@@ -133,16 +137,13 @@ function Editor( { postId, postType, settings, initialEdits, ...props } ) {
133
137
  return result;
134
138
  }, [
135
139
  settings,
136
- hasFixedToolbar,
137
140
  hasInlineToolbar,
138
- focusMode,
139
- isDistractionFree,
140
141
  hiddenBlockTypes,
141
142
  blockTypes,
142
143
  preferredStyleVariations,
143
- setIsInserterOpened,
144
144
  updatePreferredStyleVariations,
145
- keepCaretInsideBlock,
145
+ getPostLinkProps,
146
+ goBack,
146
147
  ] );
147
148
 
148
149
  if ( ! post ) {
@@ -161,7 +162,7 @@ function Editor( { postId, postType, settings, initialEdits, ...props } ) {
161
162
  >
162
163
  <ErrorBoundary>
163
164
  <CommandMenu />
164
- <EditorInitialization postId={ postId } />
165
+ <EditorInitialization postId={ currentPost.postId } />
165
166
  <Layout />
166
167
  </ErrorBoundary>
167
168
  <PostLockedModal />
@@ -47,18 +47,10 @@ class Editor extends Component {
47
47
  this.setTitleRef = this.setTitleRef.bind( this );
48
48
  }
49
49
 
50
- getEditorSettings(
51
- settings,
52
- hasFixedToolbar,
53
- focusMode,
54
- hiddenBlockTypes,
55
- blockTypes
56
- ) {
50
+ getEditorSettings( settings, hiddenBlockTypes, blockTypes ) {
57
51
  settings = {
58
52
  ...settings,
59
53
  isRTL: I18nManager.isRTL,
60
- hasFixedToolbar,
61
- focusMode,
62
54
  };
63
55
 
64
56
  // Omit hidden block types if exists and non-empty.
@@ -134,8 +126,6 @@ class Editor extends Component {
134
126
  render() {
135
127
  const {
136
128
  settings,
137
- hasFixedToolbar,
138
- focusMode,
139
129
  initialEdits,
140
130
  hiddenBlockTypes,
141
131
  blockTypes,
@@ -149,8 +139,6 @@ class Editor extends Component {
149
139
 
150
140
  const editorSettings = this.getEditorSettings(
151
141
  settings,
152
- hasFixedToolbar,
153
- focusMode,
154
142
  hiddenBlockTypes,
155
143
  blockTypes
156
144
  );
@@ -192,13 +180,10 @@ class Editor extends Component {
192
180
 
193
181
  export default compose( [
194
182
  withSelect( ( select ) => {
195
- const { isFeatureActive, getEditorMode, getHiddenBlockTypes } =
196
- select( editPostStore );
183
+ const { getEditorMode, getHiddenBlockTypes } = select( editPostStore );
197
184
  const { getBlockTypes } = select( blocksStore );
198
185
 
199
186
  return {
200
- hasFixedToolbar: isFeatureActive( 'fixedToolbar' ),
201
- focusMode: isFeatureActive( 'focusMode' ),
202
187
  mode: getEditorMode(),
203
188
  hiddenBlockTypes: getHiddenBlockTypes(),
204
189
  blockTypes: getBlockTypes(),
@@ -32,7 +32,6 @@ export default function useCommonCommands() {
32
32
  openGeneralSidebar,
33
33
  closeGeneralSidebar,
34
34
  switchEditorMode,
35
- setIsListViewOpened,
36
35
  toggleDistractionFree,
37
36
  } = useDispatch( editPostStore );
38
37
  const { openModal } = useDispatch( interfaceStore );
@@ -44,8 +43,9 @@ export default function useCommonCommands() {
44
43
  showBlockBreadcrumbs,
45
44
  isDistractionFree,
46
45
  } = useSelect( ( select ) => {
47
- const { getEditorMode, isListViewOpened, isFeatureActive } =
48
- select( editPostStore );
46
+ const { get } = select( preferencesStore );
47
+ const { getEditorMode } = select( editPostStore );
48
+ const { isListViewOpened } = select( editorStore );
49
49
  return {
50
50
  activeSidebar: select( interfaceStore ).getActiveComplementaryArea(
51
51
  editPostStore.name
@@ -54,16 +54,14 @@ export default function useCommonCommands() {
54
54
  isListViewOpen: isListViewOpened(),
55
55
  isPublishSidebarEnabled:
56
56
  select( editorStore ).isPublishSidebarEnabled(),
57
- showBlockBreadcrumbs: isFeatureActive( 'showBlockBreadcrumbs' ),
58
- isDistractionFree: select( preferencesStore ).get(
59
- editPostStore.name,
60
- 'distractionFree'
61
- ),
57
+ showBlockBreadcrumbs: get( 'core', 'showBlockBreadcrumbs' ),
58
+ isDistractionFree: get( 'core', 'distractionFree' ),
62
59
  };
63
60
  }, [] );
64
61
  const { toggle } = useDispatch( preferencesStore );
65
62
  const { createInfoNotice } = useDispatch( noticesStore );
66
- const { __unstableSaveForPreview } = useDispatch( editorStore );
63
+ const { __unstableSaveForPreview, setIsListViewOpened } =
64
+ useDispatch( editorStore );
67
65
  const { getCurrentPostId } = useSelect( editorStore );
68
66
 
69
67
  useCommand( {
@@ -107,7 +105,7 @@ export default function useCommonCommands() {
107
105
  name: 'core/toggle-spotlight-mode',
108
106
  label: __( 'Toggle spotlight mode' ),
109
107
  callback: ( { close } ) => {
110
- toggle( 'core/edit-post', 'focusMode' );
108
+ toggle( 'core', 'focusMode' );
111
109
  close();
112
110
  },
113
111
  } );
@@ -136,7 +134,7 @@ export default function useCommonCommands() {
136
134
  name: 'core/toggle-top-toolbar',
137
135
  label: __( 'Toggle top toolbar' ),
138
136
  callback: ( { close } ) => {
139
- toggle( 'core/edit-post', 'fixedToolbar' );
137
+ toggle( 'core', 'fixedToolbar' );
140
138
  if ( isDistractionFree ) {
141
139
  toggleDistractionFree();
142
140
  }
@@ -177,7 +175,7 @@ export default function useCommonCommands() {
177
175
  ? __( 'Hide block breadcrumbs' )
178
176
  : __( 'Show block breadcrumbs' ),
179
177
  callback: ( { close } ) => {
180
- toggle( 'core/edit-post', 'showBlockBreadcrumbs' );
178
+ toggle( 'core', 'showBlockBreadcrumbs' );
181
179
  close();
182
180
  createInfoNotice(
183
181
  showBlockBreadcrumbs
@@ -194,16 +192,16 @@ export default function useCommonCommands() {
194
192
  useCommand( {
195
193
  name: 'core/toggle-publish-sidebar',
196
194
  label: isPublishSidebarEnabled
197
- ? __( 'Disable pre-publish checklist' )
198
- : __( 'Enable pre-publish checklist' ),
195
+ ? __( 'Disable pre-publish checks' )
196
+ : __( 'Enable pre-publish checks' ),
199
197
  icon: formatListBullets,
200
198
  callback: ( { close } ) => {
201
199
  close();
202
200
  toggle( 'core/edit-post', 'isPublishSidebarEnabled' );
203
201
  createInfoNotice(
204
202
  isPublishSidebarEnabled
205
- ? __( 'Pre-publish checklist off.' )
206
- : __( 'Pre-publish checklist on.' ),
203
+ ? __( 'Pre-publish checks disabled.' )
204
+ : __( 'Pre-publish checks enabled.' ),
207
205
  {
208
206
  id: 'core/edit-post/publish-sidebar/notice',
209
207
  type: 'snackbar',
@@ -0,0 +1,73 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import { useCallback, useReducer } from '@wordpress/element';
5
+ import { addQueryArgs, getQueryArgs, removeQueryArgs } from '@wordpress/url';
6
+
7
+ /**
8
+ * A hook that records the 'entity' history in the post editor as a user
9
+ * navigates between editing a post and editing the post template or patterns.
10
+ *
11
+ * Implemented as a stack, so a little similar to the browser history API.
12
+ *
13
+ * Used to control displaying UI elements like the back button.
14
+ *
15
+ * @param {number} initialPostId The post id of the post when the editor loaded.
16
+ * @param {string} initialPostType The post type of the post when the editor loaded.
17
+ *
18
+ * @return {Object} An object containing the `currentPost` variable and
19
+ * `getPostLinkProps` and `goBack` functions.
20
+ */
21
+ export default function usePostHistory( initialPostId, initialPostType ) {
22
+ const [ postHistory, dispatch ] = useReducer(
23
+ ( historyState, { type, post } ) => {
24
+ if ( type === 'push' ) {
25
+ return [ ...historyState, post ];
26
+ }
27
+ if ( type === 'pop' ) {
28
+ // Try to leave one item in the history.
29
+ if ( historyState.length > 1 ) {
30
+ return historyState.slice( 0, -1 );
31
+ }
32
+ }
33
+ return historyState;
34
+ },
35
+ [ { postId: initialPostId, postType: initialPostType } ]
36
+ );
37
+
38
+ const getPostLinkProps = useCallback( ( params ) => {
39
+ const currentArgs = getQueryArgs( window.location.href );
40
+ const currentUrlWithoutArgs = removeQueryArgs(
41
+ window.location.href,
42
+ ...Object.keys( currentArgs )
43
+ );
44
+
45
+ const newUrl = addQueryArgs( currentUrlWithoutArgs, {
46
+ post: params.postId,
47
+ action: 'edit',
48
+ } );
49
+
50
+ return {
51
+ href: newUrl,
52
+ onClick: ( event ) => {
53
+ event.preventDefault();
54
+ dispatch( {
55
+ type: 'push',
56
+ post: { postId: params.postId, postType: params.postType },
57
+ } );
58
+ },
59
+ };
60
+ }, [] );
61
+
62
+ const goBack = useCallback( () => {
63
+ dispatch( { type: 'pop' } );
64
+ }, [] );
65
+
66
+ const currentPost = postHistory[ postHistory.length - 1 ];
67
+
68
+ return {
69
+ currentPost,
70
+ getPostLinkProps,
71
+ goBack: postHistory.length > 1 ? goBack : undefined,
72
+ };
73
+ }
package/src/index.js CHANGED
@@ -15,7 +15,10 @@ import {
15
15
  registerLegacyWidgetBlock,
16
16
  registerWidgetGroupBlock,
17
17
  } from '@wordpress/widgets';
18
- import { store as editorStore } from '@wordpress/editor';
18
+ import {
19
+ privateApis as editorPrivateApis,
20
+ store as editorStore,
21
+ } from '@wordpress/editor';
19
22
 
20
23
  /**
21
24
  * Internal dependencies
@@ -23,7 +26,10 @@ import { store as editorStore } from '@wordpress/editor';
23
26
  import './hooks';
24
27
  import './plugins';
25
28
  import Editor from './editor';
26
- import { store as editPostStore } from './store';
29
+ import { unlock } from './lock-unlock';
30
+
31
+ const { PluginPostExcerpt: __experimentalPluginPostExcerpt } =
32
+ unlock( editorPrivateApis );
27
33
 
28
34
  /**
29
35
  * Initializes and returns an instance of Editor.
@@ -48,30 +54,34 @@ export function initializeEditor(
48
54
 
49
55
  dispatch( preferencesStore ).setDefaults( 'core/edit-post', {
50
56
  editorMode: 'visual',
51
- fixedToolbar: false,
52
57
  fullscreenMode: true,
53
58
  hiddenBlockTypes: [],
54
- inactivePanels: [],
55
59
  isPublishSidebarEnabled: true,
56
- openPanels: [ 'post-status' ],
57
60
  preferredStyleVariations: {},
58
- showBlockBreadcrumbs: true,
59
- showIconLabels: false,
60
- showListViewByDefault: false,
61
61
  themeStyles: true,
62
62
  welcomeGuide: true,
63
63
  welcomeGuideTemplate: true,
64
64
  } );
65
65
 
66
+ dispatch( preferencesStore ).setDefaults( 'core', {
67
+ allowRightClickOverrides: true,
68
+ fixedToolbar: false,
69
+ inactivePanels: [],
70
+ openPanels: [ 'post-status' ],
71
+ showBlockBreadcrumbs: true,
72
+ showIconLabels: false,
73
+ showListViewByDefault: false,
74
+ } );
75
+
66
76
  dispatch( blocksStore ).reapplyBlockTypeFilters();
67
77
 
68
78
  // Check if the block list view should be open by default.
69
79
  // If `distractionFree` mode is enabled, the block list view should not be open.
70
80
  if (
71
- select( editPostStore ).isFeatureActive( 'showListViewByDefault' ) &&
72
- ! select( editPostStore ).isFeatureActive( 'distractionFree' )
81
+ select( preferencesStore ).get( 'core', 'showListViewByDefault' ) &&
82
+ ! select( preferencesStore ).get( 'core', 'distractionFree' )
73
83
  ) {
74
- dispatch( editPostStore ).setIsListViewOpened( true );
84
+ dispatch( editorStore ).setIsListViewOpened( true );
75
85
  }
76
86
 
77
87
  registerCoreBlocks();
@@ -207,5 +217,5 @@ export { default as PluginSidebar } from './components/sidebar/plugin-sidebar';
207
217
  export { default as PluginSidebarMoreMenuItem } from './components/header/plugin-sidebar-more-menu-item';
208
218
  export { default as __experimentalFullscreenModeClose } from './components/header/fullscreen-mode-close';
209
219
  export { default as __experimentalMainDashboardButton } from './components/header/main-dashboard-button';
210
- export { default as __experimentalPluginPostExcerpt } from './components/sidebar/plugin-post-excerpt';
220
+ export { __experimentalPluginPostExcerpt };
211
221
  export { store } from './store';
@@ -23,7 +23,6 @@ import Editor from './editor';
23
23
  export function initializeEditor( id, postType, postId ) {
24
24
  dispatch( preferencesStore ).setDefaults( 'core/edit-post', {
25
25
  editorMode: 'visual',
26
- fixedToolbar: false,
27
26
  fullscreenMode: true,
28
27
  hiddenBlockTypes: [],
29
28
  inactivePanels: [],
@@ -32,6 +31,14 @@ export function initializeEditor( id, postType, postId ) {
32
31
  preferredStyleVariations: {},
33
32
  welcomeGuide: true,
34
33
  } );
34
+ dispatch( preferencesStore ).setDefaults( 'core', {
35
+ inactivePanels: [],
36
+ openPanels: [ 'post-status' ],
37
+ } );
38
+
39
+ dispatch( preferencesStore ).setDefaults( 'core', {
40
+ fixedToolbar: false,
41
+ } );
35
42
 
36
43
  return <Editor postId={ postId } postType={ postType } />;
37
44
  }
@@ -28,7 +28,7 @@ export const openGeneralSidebar =
28
28
  ( { dispatch, registry } ) => {
29
29
  const isDistractionFree = registry
30
30
  .select( preferencesStore )
31
- .get( 'core/edit-post', 'distractionFree' );
31
+ .get( 'core', 'distractionFree' );
32
32
  if ( isDistractionFree ) {
33
33
  dispatch.toggleDistractionFree();
34
34
  }
@@ -122,6 +122,8 @@ export function togglePublishSidebar() {
122
122
  /**
123
123
  * Returns an action object used to enable or disable a panel in the editor.
124
124
  *
125
+ * @deprecated
126
+ *
125
127
  * @param {string} panelName A string that identifies the panel to enable or disable.
126
128
  *
127
129
  * @return {Object} Action object.
@@ -129,73 +131,48 @@ export function togglePublishSidebar() {
129
131
  export const toggleEditorPanelEnabled =
130
132
  ( panelName ) =>
131
133
  ( { registry } ) => {
132
- const inactivePanels =
133
- registry
134
- .select( preferencesStore )
135
- .get( 'core/edit-post', 'inactivePanels' ) ?? [];
136
-
137
- const isPanelInactive = !! inactivePanels?.includes( panelName );
138
-
139
- // If the panel is inactive, remove it to enable it, else add it to
140
- // make it inactive.
141
- let updatedInactivePanels;
142
- if ( isPanelInactive ) {
143
- updatedInactivePanels = inactivePanels.filter(
144
- ( invactivePanelName ) => invactivePanelName !== panelName
145
- );
146
- } else {
147
- updatedInactivePanels = [ ...inactivePanels, panelName ];
148
- }
149
-
150
- registry
151
- .dispatch( preferencesStore )
152
- .set( 'core/edit-post', 'inactivePanels', updatedInactivePanels );
134
+ deprecated( "dispatch( 'core/edit-post' ).toggleEditorPanelEnabled", {
135
+ since: '6.5',
136
+ alternative: "dispatch( 'core/editor').toggleEditorPanelEnabled",
137
+ } );
138
+ registry.dispatch( editorStore ).toggleEditorPanelEnabled( panelName );
153
139
  };
154
140
 
155
141
  /**
156
142
  * Opens a closed panel and closes an open panel.
157
143
  *
144
+ * @deprecated
145
+ *
158
146
  * @param {string} panelName A string that identifies the panel to open or close.
159
147
  */
160
148
  export const toggleEditorPanelOpened =
161
149
  ( panelName ) =>
162
150
  ( { registry } ) => {
163
- const openPanels =
164
- registry
165
- .select( preferencesStore )
166
- .get( 'core/edit-post', 'openPanels' ) ?? [];
167
-
168
- const isPanelOpen = !! openPanels?.includes( panelName );
169
-
170
- // If the panel is open, remove it to close it, else add it to
171
- // make it open.
172
- let updatedOpenPanels;
173
- if ( isPanelOpen ) {
174
- updatedOpenPanels = openPanels.filter(
175
- ( openPanelName ) => openPanelName !== panelName
176
- );
177
- } else {
178
- updatedOpenPanels = [ ...openPanels, panelName ];
179
- }
180
-
181
- registry
182
- .dispatch( preferencesStore )
183
- .set( 'core/edit-post', 'openPanels', updatedOpenPanels );
151
+ deprecated( "dispatch( 'core/edit-post' ).toggleEditorPanelOpened", {
152
+ since: '6.5',
153
+ alternative: "dispatch( 'core/editor').toggleEditorPanelOpened",
154
+ } );
155
+ registry.dispatch( editorStore ).toggleEditorPanelOpened( panelName );
184
156
  };
185
157
 
186
158
  /**
187
159
  * Returns an action object used to remove a panel from the editor.
188
160
  *
161
+ * @deprecated
162
+ *
189
163
  * @param {string} panelName A string that identifies the panel to remove.
190
164
  *
191
165
  * @return {Object} Action object.
192
166
  */
193
- export function removeEditorPanel( panelName ) {
194
- return {
195
- type: 'REMOVE_PANEL',
196
- panelName,
167
+ export const removeEditorPanel =
168
+ ( panelName ) =>
169
+ ( { registry } ) => {
170
+ deprecated( "dispatch( 'core/edit-post' ).removeEditorPanel", {
171
+ since: '6.5',
172
+ alternative: "dispatch( 'core/editor').removeEditorPanel",
173
+ } );
174
+ registry.dispatch( editorStore ).removeEditorPanel( panelName );
197
175
  };
198
- }
199
176
 
200
177
  /**
201
178
  * Triggers an action used to toggle a feature flag.
@@ -228,9 +205,7 @@ export const switchEditorMode =
228
205
 
229
206
  if (
230
207
  mode === 'text' &&
231
- registry
232
- .select( preferencesStore )
233
- .get( 'core/edit-post', 'distractionFree' )
208
+ registry.select( preferencesStore ).get( 'core', 'distractionFree' )
234
209
  ) {
235
210
  dispatch.toggleDistractionFree();
236
211
  }
@@ -461,8 +436,6 @@ export function metaBoxUpdatesFailure() {
461
436
  * @deprecated
462
437
  *
463
438
  * @param {string} deviceType
464
- *
465
- * @return {Object} Action object.
466
439
  */
467
440
  export const __experimentalSetPreviewDeviceType =
468
441
  ( deviceType ) =>
@@ -481,41 +454,35 @@ export const __experimentalSetPreviewDeviceType =
481
454
  /**
482
455
  * Returns an action object used to open/close the inserter.
483
456
  *
484
- * @param {boolean|Object} value Whether the inserter should be
485
- * opened (true) or closed (false).
486
- * To specify an insertion point,
487
- * use an object.
488
- * @param {string} value.rootClientId The root client ID to insert at.
489
- * @param {number} value.insertionIndex The index to insert at.
457
+ * @deprecated
490
458
  *
491
- * @return {Object} Action object.
459
+ * @param {boolean|Object} value Whether the inserter should be opened (true) or closed (false).
492
460
  */
493
- export function setIsInserterOpened( value ) {
494
- return {
495
- type: 'SET_IS_INSERTER_OPENED',
496
- value,
461
+ export const setIsInserterOpened =
462
+ ( value ) =>
463
+ ( { registry } ) => {
464
+ deprecated( "dispatch( 'core/edit-post' ).setIsInserterOpened", {
465
+ since: '6.5',
466
+ alternative: "dispatch( 'core/editor').setIsInserterOpened",
467
+ } );
468
+ registry.dispatch( editorStore ).setIsInserterOpened( value );
497
469
  };
498
- }
499
470
 
500
471
  /**
501
472
  * Returns an action object used to open/close the list view.
502
473
  *
474
+ * @deprecated
475
+ *
503
476
  * @param {boolean} isOpen A boolean representing whether the list view should be opened or closed.
504
- * @return {Object} Action object.
505
477
  */
506
478
  export const setIsListViewOpened =
507
479
  ( isOpen ) =>
508
- ( { dispatch, registry } ) => {
509
- const isDistractionFree = registry
510
- .select( preferencesStore )
511
- .get( 'core/edit-post', 'distractionFree' );
512
- if ( isDistractionFree && isOpen ) {
513
- dispatch.toggleDistractionFree();
514
- }
515
- dispatch( {
516
- type: 'SET_IS_LIST_VIEW_OPENED',
517
- isOpen,
480
+ ( { registry } ) => {
481
+ deprecated( "dispatch( 'core/edit-post' ).setIsListViewOpened", {
482
+ since: '6.5',
483
+ alternative: "dispatch( 'core/editor').setIsListViewOpened",
518
484
  } );
485
+ registry.dispatch( editorStore ).setIsListViewOpened( isOpen );
519
486
  };
520
487
 
521
488
  /**
@@ -611,25 +578,21 @@ export const toggleDistractionFree =
611
578
  ( { dispatch, registry } ) => {
612
579
  const isDistractionFree = registry
613
580
  .select( preferencesStore )
614
- .get( 'core/edit-post', 'distractionFree' );
581
+ .get( 'core', 'distractionFree' );
615
582
  if ( ! isDistractionFree ) {
616
583
  registry.batch( () => {
617
584
  registry
618
585
  .dispatch( preferencesStore )
619
- .set( 'core/edit-post', 'fixedToolbar', true );
620
- dispatch.setIsInserterOpened( false );
621
- dispatch.setIsListViewOpened( false );
586
+ .set( 'core', 'fixedToolbar', true );
587
+ registry.dispatch( editorStore ).setIsInserterOpened( false );
588
+ registry.dispatch( editorStore ).setIsListViewOpened( false );
622
589
  dispatch.closeGeneralSidebar();
623
590
  } );
624
591
  }
625
592
  registry.batch( () => {
626
593
  registry
627
594
  .dispatch( preferencesStore )
628
- .set(
629
- 'core/edit-post',
630
- 'distractionFree',
631
- ! isDistractionFree
632
- );
595
+ .set( 'core', 'distractionFree', ! isDistractionFree );
633
596
  registry
634
597
  .dispatch( noticesStore )
635
598
  .createInfoNotice(