@wordpress/edit-post 7.27.1 → 7.28.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 (169) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/build/components/block-settings-menu/plugin-block-settings-menu-item.js +1 -2
  3. package/build/components/block-settings-menu/plugin-block-settings-menu-item.js.map +1 -1
  4. package/build/components/browser-url/index.js +1 -2
  5. package/build/components/browser-url/index.js.map +1 -1
  6. package/build/components/header/fullscreen-mode-close/index.js +11 -8
  7. package/build/components/header/fullscreen-mode-close/index.js.map +1 -1
  8. package/build/components/header/header-toolbar/index.native.js +1 -2
  9. package/build/components/header/header-toolbar/index.native.js.map +1 -1
  10. package/build/components/header/index.js +8 -9
  11. package/build/components/header/index.js.map +1 -1
  12. package/build/components/header/main-dashboard-button/index.js +1 -2
  13. package/build/components/header/main-dashboard-button/index.js.map +1 -1
  14. package/build/components/header/mode-switcher/index.js +1 -7
  15. package/build/components/header/mode-switcher/index.js.map +1 -1
  16. package/build/components/header/more-menu/index.js +1 -2
  17. package/build/components/header/more-menu/index.js.map +1 -1
  18. package/build/components/header/plugin-more-menu-item/index.js +1 -2
  19. package/build/components/header/plugin-more-menu-item/index.js.map +1 -1
  20. package/build/components/header/post-publish-button-or-toggle.js +1 -2
  21. package/build/components/header/post-publish-button-or-toggle.js.map +1 -1
  22. package/build/components/header/tools-more-menu-group/index.js +1 -2
  23. package/build/components/header/tools-more-menu-group/index.js.map +1 -1
  24. package/build/components/header/writing-menu/index.js +4 -18
  25. package/build/components/header/writing-menu/index.js.map +1 -1
  26. package/build/components/keyboard-shortcut-help-modal/config.js +1 -2
  27. package/build/components/keyboard-shortcut-help-modal/config.js.map +1 -1
  28. package/build/components/keyboard-shortcut-help-modal/dynamic-shortcut.js +1 -2
  29. package/build/components/keyboard-shortcut-help-modal/dynamic-shortcut.js.map +1 -1
  30. package/build/components/keyboard-shortcut-help-modal/index.js +2 -5
  31. package/build/components/keyboard-shortcut-help-modal/index.js.map +1 -1
  32. package/build/components/keyboard-shortcut-help-modal/shortcut.js +1 -2
  33. package/build/components/keyboard-shortcut-help-modal/shortcut.js.map +1 -1
  34. package/build/components/keyboard-shortcuts/index.js +1 -2
  35. package/build/components/keyboard-shortcuts/index.js.map +1 -1
  36. package/build/components/layout/actions-panel.js +1 -2
  37. package/build/components/layout/actions-panel.js.map +1 -1
  38. package/build/components/layout/index.js +7 -5
  39. package/build/components/layout/index.js.map +1 -1
  40. package/build/components/layout/index.native.js +1 -2
  41. package/build/components/layout/index.native.js.map +1 -1
  42. package/build/components/meta-boxes/meta-box-visibility.js +1 -2
  43. package/build/components/meta-boxes/meta-box-visibility.js.map +1 -1
  44. package/build/components/meta-boxes/meta-boxes-area/index.js +1 -2
  45. package/build/components/meta-boxes/meta-boxes-area/index.js.map +1 -1
  46. package/build/components/preferences-modal/enable-custom-fields.js +1 -2
  47. package/build/components/preferences-modal/enable-custom-fields.js.map +1 -1
  48. package/build/components/preferences-modal/enable-panel.js +1 -2
  49. package/build/components/preferences-modal/enable-panel.js.map +1 -1
  50. package/build/components/preferences-modal/enable-publish-sidebar.js +1 -2
  51. package/build/components/preferences-modal/enable-publish-sidebar.js.map +1 -1
  52. package/build/components/preferences-modal/index.js +1 -2
  53. package/build/components/preferences-modal/index.js.map +1 -1
  54. package/build/components/preferences-modal/meta-boxes-section.js +1 -2
  55. package/build/components/preferences-modal/meta-boxes-section.js.map +1 -1
  56. package/build/components/sidebar/plugin-document-setting-panel/index.js +1 -2
  57. package/build/components/sidebar/plugin-document-setting-panel/index.js.map +1 -1
  58. package/build/components/sidebar/plugin-post-publish-panel/index.js +1 -2
  59. package/build/components/sidebar/plugin-post-publish-panel/index.js.map +1 -1
  60. package/build/components/sidebar/plugin-post-status-info/index.js +1 -2
  61. package/build/components/sidebar/plugin-post-status-info/index.js.map +1 -1
  62. package/build/components/sidebar/plugin-pre-publish-panel/index.js +1 -2
  63. package/build/components/sidebar/plugin-pre-publish-panel/index.js.map +1 -1
  64. package/build/components/sidebar/post-format/index.js +1 -2
  65. package/build/components/sidebar/post-format/index.js.map +1 -1
  66. package/build/components/sidebar/post-pending-status/index.js +1 -2
  67. package/build/components/sidebar/post-pending-status/index.js.map +1 -1
  68. package/build/components/sidebar/post-slug/index.js +1 -2
  69. package/build/components/sidebar/post-slug/index.js.map +1 -1
  70. package/build/components/sidebar/post-sticky/index.js +1 -2
  71. package/build/components/sidebar/post-sticky/index.js.map +1 -1
  72. package/build/components/sidebar/post-visibility/index.js +2 -2
  73. package/build/components/sidebar/post-visibility/index.js.map +1 -1
  74. package/build/components/sidebar/settings-header/index.js +16 -11
  75. package/build/components/sidebar/settings-header/index.js.map +1 -1
  76. package/build/components/sidebar/settings-sidebar/index.js +34 -12
  77. package/build/components/sidebar/settings-sidebar/index.js.map +1 -1
  78. package/build/components/sidebar/template-summary/index.js +5 -10
  79. package/build/components/sidebar/template-summary/index.js.map +1 -1
  80. package/build/components/visual-editor/block-inspector-button.js +1 -2
  81. package/build/components/visual-editor/block-inspector-button.js.map +1 -1
  82. package/build/components/visual-editor/header.native.js +1 -2
  83. package/build/components/visual-editor/header.native.js.map +1 -1
  84. package/build/components/visual-editor/index.js +5 -4
  85. package/build/components/visual-editor/index.js.map +1 -1
  86. package/build/components/welcome-guide/index.js +6 -6
  87. package/build/components/welcome-guide/index.js.map +1 -1
  88. package/build/editor.js +35 -34
  89. package/build/editor.js.map +1 -1
  90. package/build/editor.native.js +1 -2
  91. package/build/editor.native.js.map +1 -1
  92. package/build/hooks/{use-post-history.js → use-navigate-to-entity-record.js} +20 -26
  93. package/build/hooks/use-navigate-to-entity-record.js.map +1 -0
  94. package/build/hooks/validate-multiple-use/index.js +25 -4
  95. package/build/hooks/validate-multiple-use/index.js.map +1 -1
  96. package/build/plugins/keyboard-shortcuts-help-menu-item/index.js +1 -2
  97. package/build/plugins/keyboard-shortcuts-help-menu-item/index.js.map +1 -1
  98. package/build/plugins/welcome-guide-menu-item/index.js +2 -2
  99. package/build/plugins/welcome-guide-menu-item/index.js.map +1 -1
  100. package/build/store/actions.js +8 -12
  101. package/build/store/actions.js.map +1 -1
  102. package/build/store/constants.js +3 -6
  103. package/build/store/constants.js.map +1 -1
  104. package/build/store/index.js +3 -4
  105. package/build/store/index.js.map +1 -1
  106. package/build/store/reducer.js +1 -2
  107. package/build/store/reducer.js.map +1 -1
  108. package/build/store/selectors.js +21 -42
  109. package/build/store/selectors.js.map +1 -1
  110. package/build-module/components/header/fullscreen-mode-close/index.js +10 -6
  111. package/build-module/components/header/fullscreen-mode-close/index.js.map +1 -1
  112. package/build-module/components/header/index.js +7 -7
  113. package/build-module/components/header/index.js.map +1 -1
  114. package/build-module/components/header/mode-switcher/index.js +0 -5
  115. package/build-module/components/header/mode-switcher/index.js.map +1 -1
  116. package/build-module/components/header/writing-menu/index.js +4 -17
  117. package/build-module/components/header/writing-menu/index.js.map +1 -1
  118. package/build-module/components/keyboard-shortcut-help-modal/index.js +0 -1
  119. package/build-module/components/keyboard-shortcut-help-modal/index.js.map +1 -1
  120. package/build-module/components/layout/index.js +6 -3
  121. package/build-module/components/layout/index.js.map +1 -1
  122. package/build-module/components/sidebar/post-visibility/index.js +1 -0
  123. package/build-module/components/sidebar/post-visibility/index.js.map +1 -1
  124. package/build-module/components/sidebar/settings-header/index.js +16 -10
  125. package/build-module/components/sidebar/settings-header/index.js.map +1 -1
  126. package/build-module/components/sidebar/settings-sidebar/index.js +33 -9
  127. package/build-module/components/sidebar/settings-sidebar/index.js.map +1 -1
  128. package/build-module/components/sidebar/template-summary/index.js +4 -8
  129. package/build-module/components/sidebar/template-summary/index.js.map +1 -1
  130. package/build-module/components/visual-editor/index.js +5 -4
  131. package/build-module/components/visual-editor/index.js.map +1 -1
  132. package/build-module/components/welcome-guide/index.js +6 -6
  133. package/build-module/components/welcome-guide/index.js.map +1 -1
  134. package/build-module/editor.js +34 -32
  135. package/build-module/editor.js.map +1 -1
  136. package/build-module/hooks/{use-post-history.js → use-navigate-to-entity-record.js} +20 -26
  137. package/build-module/hooks/use-navigate-to-entity-record.js.map +1 -0
  138. package/build-module/hooks/validate-multiple-use/index.js +26 -4
  139. package/build-module/hooks/validate-multiple-use/index.js.map +1 -1
  140. package/build-module/plugins/welcome-guide-menu-item/index.js +2 -2
  141. package/build-module/plugins/welcome-guide-menu-item/index.js.map +1 -1
  142. package/build-module/store/actions.js +7 -10
  143. package/build-module/store/actions.js.map +1 -1
  144. package/build-style/style-rtl.css +29 -22
  145. package/build-style/style.css +29 -22
  146. package/package.json +32 -32
  147. package/src/components/header/fullscreen-mode-close/index.js +13 -10
  148. package/src/components/header/fullscreen-mode-close/test/index.js +31 -5
  149. package/src/components/header/index.js +10 -8
  150. package/src/components/header/mode-switcher/index.js +16 -25
  151. package/src/components/header/style.scss +40 -26
  152. package/src/components/header/writing-menu/index.js +3 -16
  153. package/src/components/layout/index.js +3 -2
  154. package/src/components/sidebar/post-visibility/index.js +1 -0
  155. package/src/components/sidebar/settings-header/index.js +17 -9
  156. package/src/components/sidebar/settings-sidebar/index.js +44 -9
  157. package/src/components/sidebar/template-summary/index.js +3 -7
  158. package/src/components/visual-editor/index.js +4 -2
  159. package/src/components/visual-editor/style.scss +1 -1
  160. package/src/components/welcome-guide/index.js +11 -6
  161. package/src/editor.js +50 -50
  162. package/src/hooks/{use-post-history.js → use-navigate-to-entity-record.js} +23 -27
  163. package/src/hooks/validate-multiple-use/index.js +28 -3
  164. package/src/plugins/welcome-guide-menu-item/index.js +3 -3
  165. package/src/store/actions.js +20 -12
  166. package/src/style.scss +0 -1
  167. package/src/test/editor.native.js +8 -5
  168. package/build/hooks/use-post-history.js.map +0 -1
  169. package/build-module/hooks/use-post-history.js.map +0 -1
@@ -12,24 +12,6 @@
12
12
  @include break-zoomed-in {
13
13
  flex-wrap: nowrap;
14
14
  }
15
-
16
- // Some browsers, most notably IE11, honor an older version of the flexbox spec
17
- // which takes absolutely positioned items into account when calculating `space-between`.
18
- // https://www.w3.org/TR/2012/WD-css3-flexbox-20120612/#abspos-flex-items
19
- //
20
- // This difference is causing our header layout to break when focused in IE11.
21
- // Our focused region styles use an absolutely positioned :after pseudo element to draw an outline,
22
- // and IE11 is adding space between it and our last real child, shifting righthand UI elements
23
- // to the left. For a workaround, we change the flex order to move the undesired spacing to the middle
24
- // where it is no longer noticeable.
25
- > .edit-post-header__settings {
26
- order: 1;
27
-
28
- // Restore default order for all other browsers
29
- @supports (position: sticky) {
30
- order: initial;
31
- }
32
- }
33
15
  }
34
16
 
35
17
  .edit-post-header__toolbar {
@@ -53,18 +35,34 @@
53
35
  }
54
36
 
55
37
  .selected-block-tools-wrapper {
56
- overflow-x: hidden;
38
+ overflow: hidden;
57
39
  display: flex;
40
+ align-items: center;
41
+ height: $header-height;
58
42
 
59
43
  .block-editor-block-contextual-toolbar {
60
44
  border-bottom: 0;
45
+ height: 100%;
46
+ }
47
+
48
+ // These rules ensure that icons are always positioned in a way that lines up with the rest of the icons in the toolbar.
49
+ .block-editor-block-toolbar {
50
+ height: 100%;
51
+ // Push down so that buttons are centered vertically.
52
+ // It should be 14px (60px header height - 32px compact button height = 28 / 2),
53
+ // but there is a -1px top-margin down the stack that affects this.
54
+ padding-top: math.div($header-height - $button-size-compact, 2) + 1;
55
+
56
+ // Match the height of other buttons in the header toolbar.
57
+ .components-button:not(.block-editor-block-mover-button) {
58
+ height: $button-size-compact;
59
+ }
61
60
  }
62
61
 
63
62
  &::after {
64
63
  content: "";
65
64
  width: $border-width;
66
- margin-top: $grid-unit + $grid-unit-05;
67
- margin-bottom: $grid-unit + $grid-unit-05;
65
+ height: $grid-unit-30;
68
66
  background-color: $gray-300;
69
67
  margin-left: $grid-unit;
70
68
  }
@@ -77,9 +75,9 @@
77
75
  &::after {
78
76
  content: "";
79
77
  width: $border-width;
80
- margin-top: $grid-unit + $grid-unit-05;
81
- margin-bottom: $grid-unit + $grid-unit-05;
78
+ height: $grid-unit-30;
82
79
  background-color: $gray-300;
80
+ margin-top: $grid-unit-05;
83
81
  margin-left: $grid-unit;
84
82
  }
85
83
 
@@ -90,6 +88,22 @@
90
88
  }
91
89
  }
92
90
 
91
+ .block-editor-block-mover {
92
+ // Match the height of other buttons in the header toolbar.
93
+ &.is-horizontal .block-editor-block-mover-button {
94
+ height: $button-size-compact;
95
+ overflow: visible;
96
+ }
97
+
98
+ // Move up a little to prevent the toolbar shift when focus is on the vertical movers.
99
+ @include break-small() {
100
+ &:not(.is-horizontal) .block-editor-block-mover__move-button-container {
101
+ position: relative;
102
+ top: -10px;
103
+ }
104
+ }
105
+ }
106
+
93
107
  &.is-collapsed {
94
108
  display: none;
95
109
  }
@@ -121,7 +135,7 @@
121
135
  padding-right: $grid-unit-05;
122
136
 
123
137
  @include break-small () {
124
- padding-right: $grid-unit-20 - ($grid-unit-15 * 0.5);
138
+ padding-right: $grid-unit-10;
125
139
  }
126
140
 
127
141
  gap: $grid-unit-10;
@@ -201,9 +215,9 @@
201
215
  &::before {
202
216
  content: "";
203
217
  width: $border-width;
204
- margin-top: $grid-unit-15;
205
- margin-bottom: $grid-unit-15;
218
+ height: $grid-unit-30;
206
219
  background-color: $gray-300;
220
+ margin-top: $grid-unit-05;
207
221
  margin-left: $grid-unit;
208
222
  }
209
223
 
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * WordPress dependencies
3
3
  */
4
- import { useDispatch, useRegistry } from '@wordpress/data';
4
+ import { useDispatch } from '@wordpress/data';
5
5
  import { MenuGroup } from '@wordpress/components';
6
6
  import { __, _x } from '@wordpress/i18n';
7
7
  import { useViewportMatch } from '@wordpress/compose';
@@ -10,7 +10,6 @@ import {
10
10
  PreferenceToggleMenuItem,
11
11
  store as preferencesStore,
12
12
  } from '@wordpress/preferences';
13
- import { store as editorStore } from '@wordpress/editor';
14
13
 
15
14
  /**
16
15
  * Internal dependencies
@@ -18,21 +17,8 @@ import { store as editorStore } from '@wordpress/editor';
18
17
  import { store as postEditorStore } from '../../../store';
19
18
 
20
19
  function WritingMenu() {
21
- const registry = useRegistry();
22
-
23
- const { closeGeneralSidebar } = useDispatch( postEditorStore );
24
20
  const { set: setPreference } = useDispatch( preferencesStore );
25
- const { setIsInserterOpened, setIsListViewOpened } =
26
- useDispatch( editorStore );
27
-
28
- const toggleDistractionFree = () => {
29
- registry.batch( () => {
30
- setPreference( 'core', 'fixedToolbar', true );
31
- setIsInserterOpened( false );
32
- setIsListViewOpened( false );
33
- closeGeneralSidebar();
34
- } );
35
- };
21
+ const { toggleDistractionFree } = useDispatch( postEditorStore );
36
22
 
37
23
  const turnOffDistractionFree = () => {
38
24
  setPreference( 'core', 'distractionFree', false );
@@ -59,6 +45,7 @@ function WritingMenu() {
59
45
  <PreferenceToggleMenuItem
60
46
  scope="core"
61
47
  name="distractionFree"
48
+ handleToggling={ false }
62
49
  onToggle={ toggleDistractionFree }
63
50
  label={ __( 'Distraction free' ) }
64
51
  info={ __( 'Write with calmness' ) }
@@ -131,7 +131,7 @@ function useEditorStyles() {
131
131
  ] );
132
132
  }
133
133
 
134
- function Layout() {
134
+ function Layout( { initialPost } ) {
135
135
  useCommands();
136
136
  useCommonCommands();
137
137
  useBlockCommands();
@@ -196,7 +196,7 @@ function Layout() {
196
196
  documentLabel: postTypeLabel || _x( 'Document', 'noun' ),
197
197
  hasBlockSelected:
198
198
  !! select( blockEditorStore ).getBlockSelectionStart(),
199
- hasHistory: !! getEditorSettings().goBack,
199
+ hasHistory: !! getEditorSettings().onNavigateToPreviousEntityRecord,
200
200
  };
201
201
  }, [] );
202
202
 
@@ -304,6 +304,7 @@ function Layout() {
304
304
  setEntitiesSavedStatesCallback={
305
305
  setEntitiesSavedStatesCallback
306
306
  }
307
+ initialPost={ initialPost }
307
308
  />
308
309
  }
309
310
  editorNotices={ <EditorNotices /> }
@@ -72,6 +72,7 @@ function PostVisibilityToggle( { isOpen, onClick } ) {
72
72
  const label = usePostVisibilityLabel();
73
73
  return (
74
74
  <Button
75
+ __next40pxDefaultSize
75
76
  className="edit-post-post-visibility__toggle"
76
77
  variant="tertiary"
77
78
  aria-expanded={ isOpen }
@@ -4,6 +4,7 @@
4
4
  import { privateApis as componentsPrivateApis } from '@wordpress/components';
5
5
  import { __, _x } from '@wordpress/i18n';
6
6
  import { useSelect } from '@wordpress/data';
7
+ import { forwardRef } from '@wordpress/element';
7
8
  import { store as editorStore } from '@wordpress/editor';
8
9
 
9
10
  /**
@@ -14,23 +15,30 @@ import { sidebars } from '../settings-sidebar';
14
15
 
15
16
  const { Tabs } = unlock( componentsPrivateApis );
16
17
 
17
- const SettingsHeader = () => {
18
- const { documentLabel, isTemplateMode } = useSelect( ( select ) => {
19
- const { getPostTypeLabel, getRenderingMode } = select( editorStore );
18
+ const SettingsHeader = ( _, ref ) => {
19
+ const { documentLabel } = useSelect( ( select ) => {
20
+ const { getPostTypeLabel } = select( editorStore );
20
21
 
21
22
  return {
22
23
  // translators: Default label for the Document sidebar tab, not selected.
23
24
  documentLabel: getPostTypeLabel() || _x( 'Document', 'noun' ),
24
- isTemplateMode: getRenderingMode() === 'template-only',
25
25
  };
26
26
  }, [] );
27
27
 
28
28
  return (
29
- <Tabs.TabList>
30
- <Tabs.Tab tabId={ sidebars.document }>
31
- { isTemplateMode ? __( 'Template' ) : documentLabel }
29
+ <Tabs.TabList ref={ ref }>
30
+ <Tabs.Tab
31
+ tabId={ sidebars.document }
32
+ // Used for focus management in the SettingsSidebar component.
33
+ data-tab-id={ sidebars.document }
34
+ >
35
+ { documentLabel }
32
36
  </Tabs.Tab>
33
- <Tabs.Tab tabId={ sidebars.block }>
37
+ <Tabs.Tab
38
+ tabId={ sidebars.block }
39
+ // Used for focus management in the SettingsSidebar component.
40
+ data-tab-id={ sidebars.block }
41
+ >
34
42
  { /* translators: Text label for the Block Settings Sidebar tab. */ }
35
43
  { __( 'Block' ) }
36
44
  </Tabs.Tab>
@@ -38,4 +46,4 @@ const SettingsHeader = () => {
38
46
  );
39
47
  };
40
48
 
41
- export default SettingsHeader;
49
+ export default forwardRef( SettingsHeader );
@@ -6,7 +6,13 @@ import {
6
6
  store as blockEditorStore,
7
7
  } from '@wordpress/block-editor';
8
8
  import { useSelect, useDispatch } from '@wordpress/data';
9
- import { Platform, useCallback, useContext } from '@wordpress/element';
9
+ import {
10
+ Platform,
11
+ useCallback,
12
+ useContext,
13
+ useEffect,
14
+ useRef,
15
+ } from '@wordpress/element';
10
16
  import { isRTL, __ } from '@wordpress/i18n';
11
17
  import { drawerLeft, drawerRight } from '@wordpress/icons';
12
18
  import { store as interfaceStore } from '@wordpress/interface';
@@ -48,19 +54,47 @@ export const sidebars = {
48
54
  const SidebarContent = ( {
49
55
  sidebarName,
50
56
  keyboardShortcut,
51
- isTemplateMode,
57
+ isEditingTemplate,
52
58
  } ) => {
59
+ const tabListRef = useRef( null );
53
60
  // Because `PluginSidebarEditPost` renders a `ComplementaryArea`, we
54
61
  // need to forward the `Tabs` context so it can be passed through the
55
62
  // underlying slot/fill.
56
63
  const tabsContextValue = useContext( Tabs.Context );
57
64
 
65
+ // This effect addresses a race condition caused by tabbing from the last
66
+ // block in the editor into the settings sidebar. Without this effect, the
67
+ // selected tab and browser focus can become separated in an unexpected way
68
+ // (e.g the "block" tab is focused, but the "post" tab is selected).
69
+ useEffect( () => {
70
+ const tabsElements = Array.from(
71
+ tabListRef.current?.querySelectorAll( '[role="tab"]' ) || []
72
+ );
73
+ const selectedTabElement = tabsElements.find(
74
+ // We are purposefully using a custom `data-tab-id` attribute here
75
+ // because we don't want rely on any assumptions about `Tabs`
76
+ // component internals.
77
+ ( element ) => element.getAttribute( 'data-tab-id' ) === sidebarName
78
+ );
79
+ const activeElement = selectedTabElement?.ownerDocument.activeElement;
80
+ const tabsHasFocus = tabsElements.some( ( element ) => {
81
+ return activeElement && activeElement.id === element.id;
82
+ } );
83
+ if (
84
+ tabsHasFocus &&
85
+ selectedTabElement &&
86
+ selectedTabElement.id !== activeElement?.id
87
+ ) {
88
+ selectedTabElement?.focus();
89
+ }
90
+ }, [ sidebarName ] );
91
+
58
92
  return (
59
93
  <PluginSidebarEditPost
60
94
  identifier={ sidebarName }
61
95
  header={
62
96
  <Tabs.Context.Provider value={ tabsContextValue }>
63
- <SettingsHeader />
97
+ <SettingsHeader ref={ tabListRef } />
64
98
  </Tabs.Context.Provider>
65
99
  }
66
100
  closeLabel={ __( 'Close Settings' ) }
@@ -77,7 +111,7 @@ const SidebarContent = ( {
77
111
  >
78
112
  <Tabs.Context.Provider value={ tabsContextValue }>
79
113
  <Tabs.TabPanel tabId={ sidebars.document } focusable={ false }>
80
- { ! isTemplateMode && (
114
+ { ! isEditingTemplate && (
81
115
  <>
82
116
  <PostStatus />
83
117
  <PluginDocumentSettingPanel.Slot />
@@ -90,7 +124,7 @@ const SidebarContent = ( {
90
124
  <MetaBoxes location="side" />
91
125
  </>
92
126
  ) }
93
- { isTemplateMode && <TemplateSummary /> }
127
+ { isEditingTemplate && <TemplateSummary /> }
94
128
  </Tabs.TabPanel>
95
129
  <Tabs.TabPanel tabId={ sidebars.block } focusable={ false }>
96
130
  <BlockInspector />
@@ -105,7 +139,7 @@ const SettingsSidebar = () => {
105
139
  sidebarName,
106
140
  isSettingsSidebarActive,
107
141
  keyboardShortcut,
108
- isTemplateMode,
142
+ isEditingTemplate,
109
143
  } = useSelect( ( select ) => {
110
144
  // The settings sidebar is used by the edit-post/document and edit-post/block sidebars.
111
145
  // sidebarName represents the sidebar that is active or that should be active when the SettingsSidebar toggle button is pressed.
@@ -132,8 +166,8 @@ const SettingsSidebar = () => {
132
166
  sidebarName: sidebar,
133
167
  isSettingsSidebarActive: isSettingsSidebar,
134
168
  keyboardShortcut: shortcut,
135
- isTemplateMode:
136
- select( editorStore ).getRenderingMode() === 'template-only',
169
+ isEditingTemplate:
170
+ select( editorStore ).getCurrentPostType() === 'wp_template',
137
171
  };
138
172
  }, [] );
139
173
 
@@ -157,11 +191,12 @@ const SettingsSidebar = () => {
157
191
  // the selected tab to `null` avoids that.
158
192
  selectedTabId={ isSettingsSidebarActive ? sidebarName : null }
159
193
  onSelect={ onTabSelect }
194
+ selectOnMove={ false }
160
195
  >
161
196
  <SidebarContent
162
197
  sidebarName={ sidebarName }
163
198
  keyboardShortcut={ keyboardShortcut }
164
- isTemplateMode={ isTemplateMode }
199
+ isEditingTemplate={ isEditingTemplate }
165
200
  />
166
201
  </Tabs>
167
202
  );
@@ -4,16 +4,12 @@
4
4
  import { Icon, layout } from '@wordpress/icons';
5
5
  import { useSelect } from '@wordpress/data';
6
6
  import { Flex, FlexItem, FlexBlock, PanelBody } from '@wordpress/components';
7
-
8
- /**
9
- * Internal dependencies
10
- */
11
- import { store as editPostStore } from '../../../store';
7
+ import { store as editorStore } from '@wordpress/editor';
12
8
 
13
9
  function TemplateSummary() {
14
10
  const template = useSelect( ( select ) => {
15
- const { getEditedPostTemplate } = select( editPostStore );
16
- return getEditedPostTemplate();
11
+ const { getCurrentPost } = select( editorStore );
12
+ return getCurrentPost();
17
13
  }, [] );
18
14
 
19
15
  if ( ! template ) {
@@ -30,6 +30,7 @@ export default function VisualEditor( { styles } ) {
30
30
  renderingMode,
31
31
  isBlockBasedTheme,
32
32
  hasV3BlocksOnly,
33
+ isEditingTemplate,
33
34
  } = useSelect( ( select ) => {
34
35
  const { isFeatureActive } = select( editPostStore );
35
36
  const { getEditorSettings, getRenderingMode } = select( editorStore );
@@ -43,6 +44,8 @@ export default function VisualEditor( { styles } ) {
43
44
  hasV3BlocksOnly: getBlockTypes().every( ( type ) => {
44
45
  return type.apiVersion >= 3;
45
46
  } ),
47
+ isEditingTemplate:
48
+ select( editorStore ).getCurrentPostType() === 'wp_template',
46
49
  };
47
50
  }, [] );
48
51
  const hasMetaBoxes = useSelect(
@@ -74,12 +77,11 @@ export default function VisualEditor( { styles } ) {
74
77
  const isToBeIframed =
75
78
  ( ( hasV3BlocksOnly || ( isGutenbergPlugin && isBlockBasedTheme ) ) &&
76
79
  ! hasMetaBoxes ) ||
77
- renderingMode === 'template-only';
80
+ isEditingTemplate;
78
81
 
79
82
  return (
80
83
  <div
81
84
  className={ classnames( 'edit-post-visual-editor', {
82
- 'is-template-mode': renderingMode === 'template-only',
83
85
  'has-inline-canvas': ! isToBeIframed,
84
86
  } ) }
85
87
  >
@@ -11,7 +11,7 @@
11
11
  // Gray preview overlay (desktop/tablet/mobile) is intentionally not set on an element with scrolling content like
12
12
  // interface-interface-skeleton__content. This causes graphical glitches (flashes of the background color)
13
13
  // when scrolling in Safari due to incorrect ordering of large compositing layers (GPU acceleration).
14
- background-color: $gray-900;
14
+ background-color: $gray-300;
15
15
 
16
16
  // The button element easily inherits styles that are meant for the editor style.
17
17
  // These rules enhance the specificity to reduce that inheritance.
@@ -12,17 +12,18 @@ import WelcomeGuideTemplate from './template';
12
12
  import { store as editPostStore } from '../../store';
13
13
 
14
14
  export default function WelcomeGuide() {
15
- const { isActive, isTemplateMode } = useSelect( ( select ) => {
15
+ const { isActive, isEditingTemplate } = useSelect( ( select ) => {
16
16
  const { isFeatureActive } = select( editPostStore );
17
- const { getRenderingMode } = select( editorStore );
18
- const _isTemplateMode = getRenderingMode() === 'template-only';
19
- const feature = _isTemplateMode
17
+ const { getCurrentPostType } = select( editorStore );
18
+ const _isEditingTemplate = getCurrentPostType() === 'wp_template';
19
+
20
+ const feature = _isEditingTemplate
20
21
  ? 'welcomeGuideTemplate'
21
22
  : 'welcomeGuide';
22
23
 
23
24
  return {
24
25
  isActive: isFeatureActive( feature ),
25
- isTemplateMode: _isTemplateMode,
26
+ isEditingTemplate: _isEditingTemplate,
26
27
  };
27
28
  }, [] );
28
29
 
@@ -30,5 +31,9 @@ export default function WelcomeGuide() {
30
31
  return null;
31
32
  }
32
33
 
33
- return isTemplateMode ? <WelcomeGuideTemplate /> : <WelcomeGuideDefault />;
34
+ return isEditingTemplate ? (
35
+ <WelcomeGuideTemplate />
36
+ ) : (
37
+ <WelcomeGuideDefault />
38
+ );
34
39
  }
package/src/editor.js CHANGED
@@ -13,6 +13,8 @@ import { SlotFillProvider } from '@wordpress/components';
13
13
  import { store as coreStore } from '@wordpress/core-data';
14
14
  import { store as preferencesStore } from '@wordpress/preferences';
15
15
  import { CommandMenu } from '@wordpress/commands';
16
+ import { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor';
17
+ import { __ } from '@wordpress/i18n';
16
18
 
17
19
  /**
18
20
  * Internal dependencies
@@ -21,9 +23,17 @@ import Layout from './components/layout';
21
23
  import EditorInitialization from './components/editor-initialization';
22
24
  import { store as editPostStore } from './store';
23
25
  import { unlock } from './lock-unlock';
24
- import usePostHistory from './hooks/use-post-history';
26
+ import useNavigateToEntityRecord from './hooks/use-navigate-to-entity-record';
25
27
 
26
28
  const { ExperimentalEditorProvider } = unlock( editorPrivateApis );
29
+ const { BlockRemovalWarningModal } = unlock( blockEditorPrivateApis );
30
+ // Prevent accidental removal of certain blocks, asking the user for
31
+ // confirmation.
32
+ const blockRemovalRules = {
33
+ 'bindings/core/pattern-overrides': __(
34
+ 'Blocks from synced patterns that can have overriden content.'
35
+ ),
36
+ };
27
37
 
28
38
  function Editor( {
29
39
  postId: initialPostId,
@@ -32,46 +42,28 @@ function Editor( {
32
42
  initialEdits,
33
43
  ...props
34
44
  } ) {
35
- const { currentPost, getPostLinkProps, goBack } = usePostHistory(
36
- initialPostId,
37
- initialPostType
38
- );
45
+ const {
46
+ initialPost,
47
+ currentPost,
48
+ onNavigateToEntityRecord,
49
+ onNavigateToPreviousEntityRecord,
50
+ } = useNavigateToEntityRecord( initialPostId, initialPostType );
39
51
 
40
52
  const { hasInlineToolbar, post, preferredStyleVariations, template } =
41
53
  useSelect(
42
54
  ( select ) => {
43
55
  const { isFeatureActive, getEditedPostTemplate } =
44
56
  select( editPostStore );
45
- const {
46
- getEntityRecord,
47
- getPostType,
48
- getEntityRecords,
49
- canUser,
50
- } = select( coreStore );
57
+ const { getEntityRecord, getPostType, canUser } =
58
+ select( coreStore );
51
59
  const { getEditorSettings } = select( editorStore );
52
- const isTemplate = [
53
- 'wp_template',
54
- 'wp_template_part',
55
- ].includes( currentPost.postType );
56
- // Ideally the initializeEditor function should be called using the ID of the REST endpoint.
57
- // to avoid the special case.
58
- let postObject;
59
- if ( isTemplate ) {
60
- const posts = getEntityRecords(
61
- 'postType',
62
- currentPost.postType,
63
- {
64
- wp_id: currentPost.postId,
65
- }
66
- );
67
- postObject = posts?.[ 0 ];
68
- } else {
69
- postObject = getEntityRecord(
70
- 'postType',
71
- currentPost.postType,
72
- currentPost.postId
73
- );
74
- }
60
+
61
+ const postObject = getEntityRecord(
62
+ 'postType',
63
+ currentPost.postType,
64
+ currentPost.postId
65
+ );
66
+
75
67
  const supportsTemplateMode =
76
68
  getEditorSettings().supportsTemplateMode;
77
69
  const isViewable =
@@ -84,7 +76,10 @@ function Editor( {
84
76
  'preferredStyleVariations'
85
77
  ),
86
78
  template:
87
- supportsTemplateMode && isViewable && canEditTemplate
79
+ supportsTemplateMode &&
80
+ isViewable &&
81
+ canEditTemplate &&
82
+ currentPost.postType !== 'wp_template'
88
83
  ? getEditedPostTemplate()
89
84
  : null,
90
85
  post: postObject,
@@ -94,27 +89,31 @@ function Editor( {
94
89
  );
95
90
 
96
91
  const { updatePreferredStyleVariations } = useDispatch( editPostStore );
92
+ const defaultRenderingMode =
93
+ currentPost.postType === 'wp_template' ? 'all' : 'post-only';
97
94
 
98
- const editorSettings = useMemo( () => {
99
- const result = {
95
+ const editorSettings = useMemo(
96
+ () => ( {
100
97
  ...settings,
101
- getPostLinkProps,
102
- goBack,
98
+ onNavigateToEntityRecord,
99
+ onNavigateToPreviousEntityRecord,
100
+ defaultRenderingMode,
103
101
  __experimentalPreferredStyleVariations: {
104
102
  value: preferredStyleVariations,
105
103
  onChange: updatePreferredStyleVariations,
106
104
  },
107
105
  hasInlineToolbar,
108
- };
109
- return result;
110
- }, [
111
- settings,
112
- hasInlineToolbar,
113
- preferredStyleVariations,
114
- updatePreferredStyleVariations,
115
- getPostLinkProps,
116
- goBack,
117
- ] );
106
+ } ),
107
+ [
108
+ settings,
109
+ hasInlineToolbar,
110
+ preferredStyleVariations,
111
+ updatePreferredStyleVariations,
112
+ onNavigateToEntityRecord,
113
+ onNavigateToPreviousEntityRecord,
114
+ defaultRenderingMode,
115
+ ]
116
+ );
118
117
 
119
118
  if ( ! post ) {
120
119
  return null;
@@ -133,7 +132,8 @@ function Editor( {
133
132
  <ErrorBoundary>
134
133
  <CommandMenu />
135
134
  <EditorInitialization postId={ currentPost.postId } />
136
- <Layout />
135
+ <Layout initialPost={ initialPost } />
136
+ <BlockRemovalWarningModal rules={ blockRemovalRules } />
137
137
  </ErrorBoundary>
138
138
  <PostLockedModal />
139
139
  </ExperimentalEditorProvider>