@wordpress/edit-post 7.27.2 → 7.28.1

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 (156) 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 +6 -5
  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 -2
  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 +12 -4
  75. package/build/components/sidebar/settings-header/index.js.map +1 -1
  76. package/build/components/sidebar/settings-sidebar/index.js +28 -6
  77. package/build/components/sidebar/settings-sidebar/index.js.map +1 -1
  78. package/build/components/sidebar/template-summary/index.js +1 -2
  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/editor.js +32 -22
  85. package/build/editor.js.map +1 -1
  86. package/build/editor.native.js +1 -2
  87. package/build/editor.native.js.map +1 -1
  88. package/build/hooks/{use-post-history.js → use-navigate-to-entity-record.js} +20 -26
  89. package/build/hooks/use-navigate-to-entity-record.js.map +1 -0
  90. package/build/hooks/validate-multiple-use/index.js +25 -4
  91. package/build/hooks/validate-multiple-use/index.js.map +1 -1
  92. package/build/index.js +2 -2
  93. package/build/index.js.map +1 -1
  94. package/build/plugins/keyboard-shortcuts-help-menu-item/index.js +1 -2
  95. package/build/plugins/keyboard-shortcuts-help-menu-item/index.js.map +1 -1
  96. package/build/store/actions.js +7 -1
  97. package/build/store/actions.js.map +1 -1
  98. package/build/store/constants.js +3 -6
  99. package/build/store/constants.js.map +1 -1
  100. package/build/store/index.js +3 -4
  101. package/build/store/index.js.map +1 -1
  102. package/build/store/reducer.js +1 -2
  103. package/build/store/reducer.js.map +1 -1
  104. package/build/store/selectors.js +22 -43
  105. package/build/store/selectors.js.map +1 -1
  106. package/build-module/components/header/fullscreen-mode-close/index.js +10 -6
  107. package/build-module/components/header/fullscreen-mode-close/index.js.map +1 -1
  108. package/build-module/components/header/index.js +5 -3
  109. package/build-module/components/header/index.js.map +1 -1
  110. package/build-module/components/header/writing-menu/index.js +4 -17
  111. package/build-module/components/header/writing-menu/index.js.map +1 -1
  112. package/build-module/components/keyboard-shortcut-help-modal/index.js +0 -1
  113. package/build-module/components/keyboard-shortcut-help-modal/index.js.map +1 -1
  114. package/build-module/components/layout/index.js +6 -3
  115. package/build-module/components/layout/index.js.map +1 -1
  116. package/build-module/components/sidebar/post-visibility/index.js +1 -0
  117. package/build-module/components/sidebar/post-visibility/index.js.map +1 -1
  118. package/build-module/components/sidebar/settings-header/index.js +12 -3
  119. package/build-module/components/sidebar/settings-header/index.js.map +1 -1
  120. package/build-module/components/sidebar/settings-sidebar/index.js +27 -3
  121. package/build-module/components/sidebar/settings-sidebar/index.js.map +1 -1
  122. package/build-module/editor.js +31 -20
  123. package/build-module/editor.js.map +1 -1
  124. package/build-module/hooks/{use-post-history.js → use-navigate-to-entity-record.js} +20 -26
  125. package/build-module/hooks/use-navigate-to-entity-record.js.map +1 -0
  126. package/build-module/hooks/validate-multiple-use/index.js +26 -4
  127. package/build-module/hooks/validate-multiple-use/index.js.map +1 -1
  128. package/build-module/index.js +2 -2
  129. package/build-module/index.js.map +1 -1
  130. package/build-module/store/actions.js +7 -1
  131. package/build-module/store/actions.js.map +1 -1
  132. package/build-module/store/selectors.js +1 -1
  133. package/build-module/store/selectors.js.map +1 -1
  134. package/build-style/style-rtl.css +29 -22
  135. package/build-style/style.css +29 -22
  136. package/package.json +32 -32
  137. package/src/components/header/fullscreen-mode-close/index.js +13 -10
  138. package/src/components/header/fullscreen-mode-close/test/index.js +31 -5
  139. package/src/components/header/index.js +8 -3
  140. package/src/components/header/style.scss +40 -26
  141. package/src/components/header/writing-menu/index.js +3 -16
  142. package/src/components/layout/index.js +3 -2
  143. package/src/components/sidebar/post-visibility/index.js +1 -0
  144. package/src/components/sidebar/settings-header/index.js +16 -5
  145. package/src/components/sidebar/settings-sidebar/index.js +37 -2
  146. package/src/components/visual-editor/style.scss +1 -1
  147. package/src/editor.js +34 -24
  148. package/src/hooks/{use-post-history.js → use-navigate-to-entity-record.js} +23 -27
  149. package/src/hooks/validate-multiple-use/index.js +28 -3
  150. package/src/index.js +2 -8
  151. package/src/store/actions.js +20 -3
  152. package/src/store/selectors.js +1 -1
  153. package/src/style.scss +0 -1
  154. package/src/test/editor.native.js +8 -5
  155. package/build/hooks/use-post-history.js.map +0 -1
  156. 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,7 +15,7 @@ import { sidebars } from '../settings-sidebar';
14
15
 
15
16
  const { Tabs } = unlock( componentsPrivateApis );
16
17
 
17
- const SettingsHeader = () => {
18
+ const SettingsHeader = ( _, ref ) => {
18
19
  const { documentLabel } = useSelect( ( select ) => {
19
20
  const { getPostTypeLabel } = select( editorStore );
20
21
 
@@ -25,9 +26,19 @@ const SettingsHeader = () => {
25
26
  }, [] );
26
27
 
27
28
  return (
28
- <Tabs.TabList>
29
- <Tabs.Tab tabId={ sidebars.document }>{ documentLabel }</Tabs.Tab>
30
- <Tabs.Tab tabId={ sidebars.block }>
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 }
36
+ </Tabs.Tab>
37
+ <Tabs.Tab
38
+ tabId={ sidebars.block }
39
+ // Used for focus management in the SettingsSidebar component.
40
+ data-tab-id={ sidebars.block }
41
+ >
31
42
  { /* translators: Text label for the Block Settings Sidebar tab. */ }
32
43
  { __( 'Block' ) }
33
44
  </Tabs.Tab>
@@ -35,4 +46,4 @@ const SettingsHeader = () => {
35
46
  );
36
47
  };
37
48
 
38
- 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';
@@ -50,17 +56,45 @@ const SidebarContent = ( {
50
56
  keyboardShortcut,
51
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' ) }
@@ -157,6 +191,7 @@ 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 }
@@ -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.
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,10 +42,12 @@ 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(
@@ -77,31 +89,28 @@ function Editor( {
77
89
  );
78
90
 
79
91
  const { updatePreferredStyleVariations } = useDispatch( editPostStore );
80
- const defaultRenderingMode =
81
- currentPost.postType === 'wp_template' ? 'all' : 'post-only';
82
92
 
83
- const editorSettings = useMemo( () => {
84
- const result = {
93
+ const editorSettings = useMemo(
94
+ () => ( {
85
95
  ...settings,
86
- getPostLinkProps,
87
- goBack,
88
- defaultRenderingMode,
96
+ onNavigateToEntityRecord,
97
+ onNavigateToPreviousEntityRecord,
98
+ defaultRenderingMode: 'post-only',
89
99
  __experimentalPreferredStyleVariations: {
90
100
  value: preferredStyleVariations,
91
101
  onChange: updatePreferredStyleVariations,
92
102
  },
93
103
  hasInlineToolbar,
94
- };
95
- return result;
96
- }, [
97
- settings,
98
- hasInlineToolbar,
99
- preferredStyleVariations,
100
- updatePreferredStyleVariations,
101
- getPostLinkProps,
102
- goBack,
103
- defaultRenderingMode,
104
- ] );
104
+ } ),
105
+ [
106
+ settings,
107
+ hasInlineToolbar,
108
+ preferredStyleVariations,
109
+ updatePreferredStyleVariations,
110
+ onNavigateToEntityRecord,
111
+ onNavigateToPreviousEntityRecord,
112
+ ]
113
+ );
105
114
 
106
115
  if ( ! post ) {
107
116
  return null;
@@ -120,7 +129,8 @@ function Editor( {
120
129
  <ErrorBoundary>
121
130
  <CommandMenu />
122
131
  <EditorInitialization postId={ currentPost.postId } />
123
- <Layout />
132
+ <Layout initialPost={ initialPost } />
133
+ <BlockRemovalWarningModal rules={ blockRemovalRules } />
124
134
  </ErrorBoundary>
125
135
  <PostLockedModal />
126
136
  </ExperimentalEditorProvider>
@@ -1,8 +1,7 @@
1
1
  /**
2
2
  * WordPress dependencies
3
3
  */
4
- import { useCallback, useReducer } from '@wordpress/element';
5
- import { addQueryArgs, getQueryArgs, removeQueryArgs } from '@wordpress/url';
4
+ import { useCallback, useReducer, useMemo } from '@wordpress/element';
6
5
 
7
6
  /**
8
7
  * A hook that records the 'entity' history in the post editor as a user
@@ -16,9 +15,12 @@ import { addQueryArgs, getQueryArgs, removeQueryArgs } from '@wordpress/url';
16
15
  * @param {string} initialPostType The post type of the post when the editor loaded.
17
16
  *
18
17
  * @return {Object} An object containing the `currentPost` variable and
19
- * `getPostLinkProps` and `goBack` functions.
18
+ * `onNavigateToEntityRecord` and `onNavigateToPreviousEntityRecord` functions.
20
19
  */
21
- export default function usePostHistory( initialPostId, initialPostType ) {
20
+ export default function useNavigateToEntityRecord(
21
+ initialPostId,
22
+ initialPostType
23
+ ) {
22
24
  const [ postHistory, dispatch ] = useReducer(
23
25
  ( historyState, { type, post } ) => {
24
26
  if ( type === 'push' ) {
@@ -35,31 +37,21 @@ export default function usePostHistory( initialPostId, initialPostType ) {
35
37
  [ { postId: initialPostId, postType: initialPostType } ]
36
38
  );
37
39
 
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
-
40
+ const initialPost = useMemo( () => {
50
41
  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
- },
42
+ type: initialPostType,
43
+ id: initialPostId,
59
44
  };
45
+ }, [ initialPostType, initialPostId ] );
46
+
47
+ const onNavigateToEntityRecord = useCallback( ( params ) => {
48
+ dispatch( {
49
+ type: 'push',
50
+ post: { postId: params.postId, postType: params.postType },
51
+ } );
60
52
  }, [] );
61
53
 
62
- const goBack = useCallback( () => {
54
+ const onNavigateToPreviousEntityRecord = useCallback( () => {
63
55
  dispatch( { type: 'pop' } );
64
56
  }, [] );
65
57
 
@@ -67,7 +59,11 @@ export default function usePostHistory( initialPostId, initialPostType ) {
67
59
 
68
60
  return {
69
61
  currentPost,
70
- getPostLinkProps,
71
- goBack: postHistory.length > 1 ? goBack : undefined,
62
+ initialPost,
63
+ onNavigateToEntityRecord,
64
+ onNavigateToPreviousEntityRecord:
65
+ postHistory.length > 1
66
+ ? onNavigateToPreviousEntityRecord
67
+ : undefined,
72
68
  };
73
69
  }
@@ -15,6 +15,33 @@ import { addFilter } from '@wordpress/hooks';
15
15
  import { __ } from '@wordpress/i18n';
16
16
  import { compose, createHigherOrderComponent } from '@wordpress/compose';
17
17
 
18
+ /**
19
+ * Recursively find very first block of an specific block type.
20
+ *
21
+ * @param {Object[]} blocks List of blocks.
22
+ * @param {string} name Block name to search.
23
+ *
24
+ * @return {Object|undefined} Return block object or undefined.
25
+ */
26
+ function findFirstOfSameType( blocks, name ) {
27
+ if ( ! Array.isArray( blocks ) || ! blocks.length ) {
28
+ return;
29
+ }
30
+
31
+ for ( const block of blocks ) {
32
+ if ( block.name === name ) {
33
+ return block;
34
+ }
35
+
36
+ // Search inside innerBlocks.
37
+ const firstBlock = findFirstOfSameType( block.innerBlocks, name );
38
+
39
+ if ( firstBlock ) {
40
+ return firstBlock;
41
+ }
42
+ }
43
+ }
44
+
18
45
  const enhance = compose(
19
46
  /**
20
47
  * For blocks whose block type doesn't support `multiple`, provides the
@@ -39,9 +66,7 @@ const enhance = compose(
39
66
  // Otherwise, only pass `originalBlockClientId` if it refers to a different
40
67
  // block from the current one.
41
68
  const blocks = select( blockEditorStore ).getBlocks();
42
- const firstOfSameType = blocks.find(
43
- ( { name } ) => block.name === name
44
- );
69
+ const firstOfSameType = findFirstOfSameType( blocks, block.name );
45
70
  const isInvalid =
46
71
  firstOfSameType && firstOfSameType.clientId !== block.clientId;
47
72
  return {
package/src/index.js CHANGED
@@ -103,10 +103,7 @@ export function initializeEditor(
103
103
  'blockEditor.__unstableCanInsertBlockType',
104
104
  'removeTemplatePartsFromInserter',
105
105
  ( canInsert, blockType ) => {
106
- if (
107
- select( editorStore ).getRenderingMode() === 'post-only' &&
108
- blockType.name === 'core/template-part'
109
- ) {
106
+ if ( blockType.name === 'core/template-part' ) {
110
107
  return false;
111
108
  }
112
109
  return canInsert;
@@ -128,10 +125,7 @@ export function initializeEditor(
128
125
  rootClientId,
129
126
  { getBlockParentsByBlockName }
130
127
  ) => {
131
- if (
132
- select( editorStore ).getRenderingMode() === 'post-only' &&
133
- blockType.name === 'core/post-content'
134
- ) {
128
+ if ( blockType.name === 'core/post-content' ) {
135
129
  return (
136
130
  getBlockParentsByBlockName( rootClientId, 'core/query' )
137
131
  .length > 0
@@ -541,6 +541,11 @@ export const toggleDistractionFree =
541
541
  const isDistractionFree = registry
542
542
  .select( preferencesStore )
543
543
  .get( 'core', 'distractionFree' );
544
+ if ( isDistractionFree ) {
545
+ registry
546
+ .dispatch( preferencesStore )
547
+ .set( 'core', 'fixedToolbar', false );
548
+ }
544
549
  if ( ! isDistractionFree ) {
545
550
  registry.batch( () => {
546
551
  registry
@@ -568,9 +573,21 @@ export const toggleDistractionFree =
568
573
  {
569
574
  label: __( 'Undo' ),
570
575
  onClick: () => {
571
- registry
572
- .dispatch( preferencesStore )
573
- .toggle( 'core', 'distractionFree' );
576
+ registry.batch( () => {
577
+ registry
578
+ .dispatch( preferencesStore )
579
+ .set(
580
+ 'core',
581
+ 'fixedToolbar',
582
+ isDistractionFree ? true : false
583
+ );
584
+ registry
585
+ .dispatch( preferencesStore )
586
+ .toggle(
587
+ 'core',
588
+ 'distractionFree'
589
+ );
590
+ } );
574
591
  },
575
592
  },
576
593
  ],
@@ -556,7 +556,7 @@ export const isEditingTemplate = createRegistrySelector( ( select ) => () => {
556
556
  since: '6.5',
557
557
  alternative: `select( 'core/editor' ).getRenderingMode`,
558
558
  } );
559
- return select( editorStore ).getRenderingMode() !== 'post-only';
559
+ return select( editorStore ).getCurrentPostType() !== 'post-only';
560
560
  } );
561
561
 
562
562
  /**
package/src/style.scss CHANGED
@@ -47,7 +47,6 @@ body.js.block-editor-page {
47
47
  .edit-post-text-editor,
48
48
  .edit-post-sidebar,
49
49
  .editor-post-publish-panel,
50
- .components-popover,
51
50
  .components-modal__frame {
52
51
  @include reset;
53
52
  }
@@ -103,8 +103,10 @@ describe( 'Editor', () => {
103
103
  await initializeEditor();
104
104
 
105
105
  // Act
106
- await act( () => mediaAppendCallback( MEDIA[ 0 ] ) );
107
- await act( () => mediaAppendCallback( MEDIA[ 2 ] ) );
106
+ act( () => mediaAppendCallback( MEDIA[ 0 ] ) );
107
+ act( () => mediaAppendCallback( MEDIA[ 2 ] ) );
108
+ await screen.findByTestId( `network-image-${ MEDIA[ 0 ].serverUrl }` );
109
+ await screen.findByTestId( `network-image-${ MEDIA[ 2 ].serverUrl }` );
108
110
 
109
111
  // Assert
110
112
  expect( getEditorHtml() ).toMatchSnapshot();
@@ -122,10 +124,11 @@ describe( 'Editor', () => {
122
124
  await initializeEditor();
123
125
 
124
126
  // Act
125
- await act( () => mediaAppendCallback( MEDIA[ 0 ] ) );
127
+ act( () => mediaAppendCallback( MEDIA[ 0 ] ) );
126
128
  // Unsupported type (PDF file)
127
- await act( () => mediaAppendCallback( MEDIA[ 1 ] ) );
128
- await act( () => mediaAppendCallback( MEDIA[ 3 ] ) );
129
+ act( () => mediaAppendCallback( MEDIA[ 1 ] ) );
130
+ act( () => mediaAppendCallback( MEDIA[ 3 ] ) );
131
+ await screen.findByTestId( `network-image-${ MEDIA[ 0 ].serverUrl }` );
129
132
 
130
133
  // Assert
131
134
  expect( getEditorHtml() ).toMatchSnapshot();
@@ -1 +0,0 @@
1
- {"version":3,"names":["_element","require","_url","usePostHistory","initialPostId","initialPostType","postHistory","dispatch","useReducer","historyState","type","post","length","slice","postId","postType","getPostLinkProps","useCallback","params","currentArgs","getQueryArgs","window","location","href","currentUrlWithoutArgs","removeQueryArgs","Object","keys","newUrl","addQueryArgs","action","onClick","event","preventDefault","goBack","currentPost","undefined"],"sources":["@wordpress/edit-post/src/hooks/use-post-history.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useCallback, useReducer } from '@wordpress/element';\nimport { addQueryArgs, getQueryArgs, removeQueryArgs } from '@wordpress/url';\n\n/**\n * A hook that records the 'entity' history in the post editor as a user\n * navigates between editing a post and editing the post template or patterns.\n *\n * Implemented as a stack, so a little similar to the browser history API.\n *\n * Used to control displaying UI elements like the back button.\n *\n * @param {number} initialPostId The post id of the post when the editor loaded.\n * @param {string} initialPostType The post type of the post when the editor loaded.\n *\n * @return {Object} An object containing the `currentPost` variable and\n * `getPostLinkProps` and `goBack` functions.\n */\nexport default function usePostHistory( initialPostId, initialPostType ) {\n\tconst [ postHistory, dispatch ] = useReducer(\n\t\t( historyState, { type, post } ) => {\n\t\t\tif ( type === 'push' ) {\n\t\t\t\treturn [ ...historyState, post ];\n\t\t\t}\n\t\t\tif ( type === 'pop' ) {\n\t\t\t\t// Try to leave one item in the history.\n\t\t\t\tif ( historyState.length > 1 ) {\n\t\t\t\t\treturn historyState.slice( 0, -1 );\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn historyState;\n\t\t},\n\t\t[ { postId: initialPostId, postType: initialPostType } ]\n\t);\n\n\tconst getPostLinkProps = useCallback( ( params ) => {\n\t\tconst currentArgs = getQueryArgs( window.location.href );\n\t\tconst currentUrlWithoutArgs = removeQueryArgs(\n\t\t\twindow.location.href,\n\t\t\t...Object.keys( currentArgs )\n\t\t);\n\n\t\tconst newUrl = addQueryArgs( currentUrlWithoutArgs, {\n\t\t\tpost: params.postId,\n\t\t\taction: 'edit',\n\t\t} );\n\n\t\treturn {\n\t\t\thref: newUrl,\n\t\t\tonClick: ( event ) => {\n\t\t\t\tevent?.preventDefault();\n\t\t\t\tdispatch( {\n\t\t\t\t\ttype: 'push',\n\t\t\t\t\tpost: { postId: params.postId, postType: params.postType },\n\t\t\t\t} );\n\t\t\t},\n\t\t};\n\t}, [] );\n\n\tconst goBack = useCallback( () => {\n\t\tdispatch( { type: 'pop' } );\n\t}, [] );\n\n\tconst currentPost = postHistory[ postHistory.length - 1 ];\n\n\treturn {\n\t\tcurrentPost,\n\t\tgetPostLinkProps,\n\t\tgoBack: postHistory.length > 1 ? goBack : undefined,\n\t};\n}\n"],"mappings":";;;;;;AAGA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,IAAA,GAAAD,OAAA;AAJA;AACA;AACA;;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASE,cAAcA,CAAEC,aAAa,EAAEC,eAAe,EAAG;EACxE,MAAM,CAAEC,WAAW,EAAEC,QAAQ,CAAE,GAAG,IAAAC,mBAAU,EAC3C,CAAEC,YAAY,EAAE;IAAEC,IAAI;IAAEC;EAAK,CAAC,KAAM;IACnC,IAAKD,IAAI,KAAK,MAAM,EAAG;MACtB,OAAO,CAAE,GAAGD,YAAY,EAAEE,IAAI,CAAE;IACjC;IACA,IAAKD,IAAI,KAAK,KAAK,EAAG;MACrB;MACA,IAAKD,YAAY,CAACG,MAAM,GAAG,CAAC,EAAG;QAC9B,OAAOH,YAAY,CAACI,KAAK,CAAE,CAAC,EAAE,CAAC,CAAE,CAAC;MACnC;IACD;IACA,OAAOJ,YAAY;EACpB,CAAC,EACD,CAAE;IAAEK,MAAM,EAAEV,aAAa;IAAEW,QAAQ,EAAEV;EAAgB,CAAC,CACvD,CAAC;EAED,MAAMW,gBAAgB,GAAG,IAAAC,oBAAW,EAAIC,MAAM,IAAM;IACnD,MAAMC,WAAW,GAAG,IAAAC,iBAAY,EAAEC,MAAM,CAACC,QAAQ,CAACC,IAAK,CAAC;IACxD,MAAMC,qBAAqB,GAAG,IAAAC,oBAAe,EAC5CJ,MAAM,CAACC,QAAQ,CAACC,IAAI,EACpB,GAAGG,MAAM,CAACC,IAAI,CAAER,WAAY,CAC7B,CAAC;IAED,MAAMS,MAAM,GAAG,IAAAC,iBAAY,EAAEL,qBAAqB,EAAE;MACnDb,IAAI,EAAEO,MAAM,CAACJ,MAAM;MACnBgB,MAAM,EAAE;IACT,CAAE,CAAC;IAEH,OAAO;MACNP,IAAI,EAAEK,MAAM;MACZG,OAAO,EAAIC,KAAK,IAAM;QACrBA,KAAK,EAAEC,cAAc,CAAC,CAAC;QACvB1B,QAAQ,CAAE;UACTG,IAAI,EAAE,MAAM;UACZC,IAAI,EAAE;YAAEG,MAAM,EAAEI,MAAM,CAACJ,MAAM;YAAEC,QAAQ,EAAEG,MAAM,CAACH;UAAS;QAC1D,CAAE,CAAC;MACJ;IACD,CAAC;EACF,CAAC,EAAE,EAAG,CAAC;EAEP,MAAMmB,MAAM,GAAG,IAAAjB,oBAAW,EAAE,MAAM;IACjCV,QAAQ,CAAE;MAAEG,IAAI,EAAE;IAAM,CAAE,CAAC;EAC5B,CAAC,EAAE,EAAG,CAAC;EAEP,MAAMyB,WAAW,GAAG7B,WAAW,CAAEA,WAAW,CAACM,MAAM,GAAG,CAAC,CAAE;EAEzD,OAAO;IACNuB,WAAW;IACXnB,gBAAgB;IAChBkB,MAAM,EAAE5B,WAAW,CAACM,MAAM,GAAG,CAAC,GAAGsB,MAAM,GAAGE;EAC3C,CAAC;AACF"}