@wordpress/editor 13.28.2 → 13.29.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 (81) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/build/components/commands/index.js +201 -0
  3. package/build/components/commands/index.js.map +1 -0
  4. package/build/components/commands/index.native.js +9 -0
  5. package/build/components/commands/index.native.js.map +1 -0
  6. package/build/components/document-bar/index.js +78 -67
  7. package/build/components/document-bar/index.js.map +1 -1
  8. package/build/components/document-tools/index.js +4 -2
  9. package/build/components/document-tools/index.js.map +1 -1
  10. package/build/components/global-keyboard-shortcuts/index.js +20 -2
  11. package/build/components/global-keyboard-shortcuts/index.js.map +1 -1
  12. package/build/components/global-keyboard-shortcuts/register-shortcuts.js +18 -0
  13. package/build/components/global-keyboard-shortcuts/register-shortcuts.js.map +1 -1
  14. package/build/components/mode-switcher/index.js +86 -0
  15. package/build/components/mode-switcher/index.js.map +1 -0
  16. package/build/components/post-title/index.js +0 -5
  17. package/build/components/post-title/index.js.map +1 -1
  18. package/build/components/provider/index.js +6 -0
  19. package/build/components/provider/index.js.map +1 -1
  20. package/build/components/provider/index.native.js +4 -9
  21. package/build/components/provider/index.native.js.map +1 -1
  22. package/build/components/provider/use-block-editor-settings.js +4 -8
  23. package/build/components/provider/use-block-editor-settings.js.map +1 -1
  24. package/build/components/provider/use-hide-blocks-from-inserter.js +53 -0
  25. package/build/components/provider/use-hide-blocks-from-inserter.js.map +1 -0
  26. package/build/private-apis.js +2 -0
  27. package/build/private-apis.js.map +1 -1
  28. package/build/store/actions.js +69 -2
  29. package/build/store/actions.js.map +1 -1
  30. package/build/store/selectors.js +13 -1
  31. package/build/store/selectors.js.map +1 -1
  32. package/build-module/components/commands/index.js +194 -0
  33. package/build-module/components/commands/index.js.map +1 -0
  34. package/build-module/components/commands/index.native.js +3 -0
  35. package/build-module/components/commands/index.native.js.map +1 -0
  36. package/build-module/components/document-bar/index.js +81 -70
  37. package/build-module/components/document-bar/index.js.map +1 -1
  38. package/build-module/components/document-tools/index.js +4 -2
  39. package/build-module/components/document-tools/index.js.map +1 -1
  40. package/build-module/components/global-keyboard-shortcuts/index.js +20 -2
  41. package/build-module/components/global-keyboard-shortcuts/index.js.map +1 -1
  42. package/build-module/components/global-keyboard-shortcuts/register-shortcuts.js +18 -0
  43. package/build-module/components/global-keyboard-shortcuts/register-shortcuts.js.map +1 -1
  44. package/build-module/components/mode-switcher/index.js +80 -0
  45. package/build-module/components/mode-switcher/index.js.map +1 -0
  46. package/build-module/components/post-title/index.js +0 -5
  47. package/build-module/components/post-title/index.js.map +1 -1
  48. package/build-module/components/provider/index.js +6 -0
  49. package/build-module/components/provider/index.js.map +1 -1
  50. package/build-module/components/provider/index.native.js +4 -10
  51. package/build-module/components/provider/index.native.js.map +1 -1
  52. package/build-module/components/provider/use-block-editor-settings.js +5 -9
  53. package/build-module/components/provider/use-block-editor-settings.js.map +1 -1
  54. package/build-module/components/provider/use-hide-blocks-from-inserter.js +47 -0
  55. package/build-module/components/provider/use-hide-blocks-from-inserter.js.map +1 -0
  56. package/build-module/private-apis.js +2 -0
  57. package/build-module/private-apis.js.map +1 -1
  58. package/build-module/store/actions.js +66 -0
  59. package/build-module/store/actions.js.map +1 -1
  60. package/build-module/store/selectors.js +12 -0
  61. package/build-module/store/selectors.js.map +1 -1
  62. package/build-style/style-rtl.css +4 -47
  63. package/build-style/style.css +4 -47
  64. package/package.json +32 -32
  65. package/src/components/commands/index.js +202 -0
  66. package/src/components/commands/index.native.js +2 -0
  67. package/src/components/document-bar/index.js +115 -94
  68. package/src/components/document-bar/style.scss +4 -37
  69. package/src/components/document-tools/index.js +22 -16
  70. package/src/components/global-keyboard-shortcuts/index.js +35 -4
  71. package/src/components/global-keyboard-shortcuts/register-shortcuts.js +20 -0
  72. package/src/components/mode-switcher/index.js +90 -0
  73. package/src/components/post-title/index.js +0 -3
  74. package/src/components/provider/index.js +7 -0
  75. package/src/components/provider/index.native.js +7 -6
  76. package/src/components/provider/use-block-editor-settings.js +6 -15
  77. package/src/components/provider/use-hide-blocks-from-inserter.js +81 -0
  78. package/src/private-apis.js +2 -0
  79. package/src/store/actions.js +95 -0
  80. package/src/store/selectors.js +12 -0
  81. package/src/store/test/actions.js +82 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wordpress/editor",
3
- "version": "13.28.2",
3
+ "version": "13.29.0",
4
4
  "description": "Enhanced block editor for WordPress posts.",
5
5
  "author": "The WordPress Contributors",
6
6
  "license": "GPL-2.0-or-later",
@@ -31,36 +31,36 @@
31
31
  ],
32
32
  "dependencies": {
33
33
  "@babel/runtime": "^7.16.0",
34
- "@wordpress/a11y": "^3.51.1",
35
- "@wordpress/api-fetch": "^6.48.1",
36
- "@wordpress/blob": "^3.51.1",
37
- "@wordpress/block-editor": "^12.19.2",
38
- "@wordpress/blocks": "^12.28.2",
39
- "@wordpress/commands": "^0.22.2",
40
- "@wordpress/components": "^26.0.2",
41
- "@wordpress/compose": "^6.28.1",
42
- "@wordpress/core-data": "^6.28.2",
43
- "@wordpress/data": "^9.21.1",
44
- "@wordpress/date": "^4.51.1",
45
- "@wordpress/deprecated": "^3.51.1",
46
- "@wordpress/dom": "^3.51.1",
47
- "@wordpress/element": "^5.28.1",
48
- "@wordpress/hooks": "^3.51.1",
49
- "@wordpress/html-entities": "^3.51.1",
50
- "@wordpress/i18n": "^4.51.1",
51
- "@wordpress/icons": "^9.42.1",
52
- "@wordpress/keyboard-shortcuts": "^4.28.1",
53
- "@wordpress/keycodes": "^3.51.1",
54
- "@wordpress/media-utils": "^4.42.1",
55
- "@wordpress/notices": "^4.19.1",
56
- "@wordpress/patterns": "^1.12.2",
57
- "@wordpress/preferences": "^3.28.2",
58
- "@wordpress/private-apis": "^0.33.1",
59
- "@wordpress/reusable-blocks": "^4.28.2",
60
- "@wordpress/rich-text": "^6.28.2",
61
- "@wordpress/server-side-render": "^4.28.2",
62
- "@wordpress/url": "^3.52.1",
63
- "@wordpress/wordcount": "^3.51.1",
34
+ "@wordpress/a11y": "^3.52.0",
35
+ "@wordpress/api-fetch": "^6.49.0",
36
+ "@wordpress/blob": "^3.52.0",
37
+ "@wordpress/block-editor": "^12.20.0",
38
+ "@wordpress/blocks": "^12.29.0",
39
+ "@wordpress/commands": "^0.23.0",
40
+ "@wordpress/components": "^27.0.0",
41
+ "@wordpress/compose": "^6.29.0",
42
+ "@wordpress/core-data": "^6.29.0",
43
+ "@wordpress/data": "^9.22.0",
44
+ "@wordpress/date": "^4.52.0",
45
+ "@wordpress/deprecated": "^3.52.0",
46
+ "@wordpress/dom": "^3.52.0",
47
+ "@wordpress/element": "^5.29.0",
48
+ "@wordpress/hooks": "^3.52.0",
49
+ "@wordpress/html-entities": "^3.52.0",
50
+ "@wordpress/i18n": "^4.52.0",
51
+ "@wordpress/icons": "^9.43.0",
52
+ "@wordpress/keyboard-shortcuts": "^4.29.0",
53
+ "@wordpress/keycodes": "^3.52.0",
54
+ "@wordpress/media-utils": "^4.43.0",
55
+ "@wordpress/notices": "^4.20.0",
56
+ "@wordpress/patterns": "^1.13.0",
57
+ "@wordpress/preferences": "^3.29.0",
58
+ "@wordpress/private-apis": "^0.34.0",
59
+ "@wordpress/reusable-blocks": "^4.29.0",
60
+ "@wordpress/rich-text": "^6.29.0",
61
+ "@wordpress/server-side-render": "^4.29.0",
62
+ "@wordpress/url": "^3.53.0",
63
+ "@wordpress/wordcount": "^3.52.0",
64
64
  "classnames": "^2.3.1",
65
65
  "date-fns": "^2.28.0",
66
66
  "memize": "^2.1.0",
@@ -75,5 +75,5 @@
75
75
  "publishConfig": {
76
76
  "access": "public"
77
77
  },
78
- "gitHead": "730beb7fd33d3382d6032c3f33e451625a0fcf36"
78
+ "gitHead": "c139588f4c668b38bafbc5431f2f4e3903dbe683"
79
79
  }
@@ -0,0 +1,202 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import { useSelect, useDispatch } from '@wordpress/data';
5
+ import { __ } from '@wordpress/i18n';
6
+ import { code, listView, external } from '@wordpress/icons';
7
+ import { useCommandLoader } from '@wordpress/commands';
8
+ import { store as preferencesStore } from '@wordpress/preferences';
9
+ import { store as noticesStore } from '@wordpress/notices';
10
+ import { store as blockEditorStore } from '@wordpress/block-editor';
11
+ import { store as coreStore } from '@wordpress/core-data';
12
+
13
+ /**
14
+ * Internal dependencies
15
+ */
16
+ import { store as editorStore } from '../../store';
17
+
18
+ function useEditorCommandLoader() {
19
+ const {
20
+ editorMode,
21
+ isListViewOpen,
22
+ showBlockBreadcrumbs,
23
+ isDistractionFree,
24
+ isTopToolbar,
25
+ isFocusMode,
26
+ isPreviewMode,
27
+ isViewable,
28
+ } = useSelect( ( select ) => {
29
+ const { get } = select( preferencesStore );
30
+ const { isListViewOpened, getCurrentPostType } = select( editorStore );
31
+ const { getSettings } = select( blockEditorStore );
32
+ const { getPostType } = select( coreStore );
33
+
34
+ return {
35
+ editorMode: get( 'core', 'editorMode' ) ?? 'visual',
36
+ isListViewOpen: isListViewOpened(),
37
+ showBlockBreadcrumbs: get( 'core', 'showBlockBreadcrumbs' ),
38
+ isDistractionFree: get( 'core', 'distractionFree' ),
39
+ isFocusMode: get( 'core', 'focusMode' ),
40
+ isTopToolbar: get( 'core', 'fixedToolbar' ),
41
+ isPreviewMode: getSettings().__unstableIsPreviewMode,
42
+ isViewable: getPostType( getCurrentPostType() )?.viewable ?? false,
43
+ };
44
+ }, [] );
45
+ const { toggle } = useDispatch( preferencesStore );
46
+ const { createInfoNotice } = useDispatch( noticesStore );
47
+ const {
48
+ __unstableSaveForPreview,
49
+ setIsListViewOpened,
50
+ switchEditorMode,
51
+ toggleDistractionFree,
52
+ } = useDispatch( editorStore );
53
+ const { getCurrentPostId } = useSelect( editorStore );
54
+
55
+ if ( isPreviewMode ) {
56
+ return { commands: [], isLoading: false };
57
+ }
58
+
59
+ const commands = [];
60
+
61
+ commands.push( {
62
+ name: 'core/toggle-distraction-free',
63
+ label: isDistractionFree
64
+ ? __( 'Exit Distraction Free' )
65
+ : __( 'Enter Distraction Free ' ),
66
+ callback: ( { close } ) => {
67
+ toggleDistractionFree();
68
+ close();
69
+ },
70
+ } );
71
+
72
+ commands.push( {
73
+ name: 'core/toggle-spotlight-mode',
74
+ label: __( 'Toggle spotlight' ),
75
+ callback: ( { close } ) => {
76
+ toggle( 'core', 'focusMode' );
77
+ close();
78
+ createInfoNotice(
79
+ isFocusMode ? __( 'Spotlight off.' ) : __( 'Spotlight on.' ),
80
+ {
81
+ id: 'core/editor/toggle-spotlight-mode/notice',
82
+ type: 'snackbar',
83
+ actions: [
84
+ {
85
+ label: __( 'Undo' ),
86
+ onClick: () => {
87
+ toggle( 'core', 'focusMode' );
88
+ },
89
+ },
90
+ ],
91
+ }
92
+ );
93
+ },
94
+ } );
95
+
96
+ commands.push( {
97
+ name: 'core/toggle-list-view',
98
+ label: isListViewOpen
99
+ ? __( 'Close List View' )
100
+ : __( 'Open List View' ),
101
+ icon: listView,
102
+ callback: ( { close } ) => {
103
+ setIsListViewOpened( ! isListViewOpen );
104
+ close();
105
+ createInfoNotice(
106
+ isListViewOpen ? __( 'List View off.' ) : __( 'List View on.' ),
107
+ {
108
+ id: 'core/editor/toggle-list-view/notice',
109
+ type: 'snackbar',
110
+ }
111
+ );
112
+ },
113
+ } );
114
+
115
+ commands.push( {
116
+ name: 'core/toggle-top-toolbar',
117
+ label: __( 'Toggle top toolbar' ),
118
+ callback: ( { close } ) => {
119
+ toggle( 'core', 'fixedToolbar' );
120
+ if ( isDistractionFree ) {
121
+ toggleDistractionFree();
122
+ }
123
+ close();
124
+ createInfoNotice(
125
+ isTopToolbar
126
+ ? __( 'Top toolbar off.' )
127
+ : __( 'Top toolbar on.' ),
128
+ {
129
+ id: 'core/editor/toggle-top-toolbar/notice',
130
+ type: 'snackbar',
131
+ actions: [
132
+ {
133
+ label: __( 'Undo' ),
134
+ onClick: () => {
135
+ toggle( 'core', 'fixedToolbar' );
136
+ },
137
+ },
138
+ ],
139
+ }
140
+ );
141
+ },
142
+ } );
143
+
144
+ commands.push( {
145
+ name: 'core/toggle-code-editor',
146
+ label:
147
+ editorMode === 'visual'
148
+ ? __( 'Open code editor' )
149
+ : __( 'Exit code editor' ),
150
+ icon: code,
151
+ callback: ( { close } ) => {
152
+ switchEditorMode( editorMode === 'visual' ? 'text' : 'visual' );
153
+ close();
154
+ },
155
+ } );
156
+
157
+ commands.push( {
158
+ name: 'core/toggle-breadcrumbs',
159
+ label: showBlockBreadcrumbs
160
+ ? __( 'Hide block breadcrumbs' )
161
+ : __( 'Show block breadcrumbs' ),
162
+ callback: ( { close } ) => {
163
+ toggle( 'core', 'showBlockBreadcrumbs' );
164
+ close();
165
+ createInfoNotice(
166
+ showBlockBreadcrumbs
167
+ ? __( 'Breadcrumbs hidden.' )
168
+ : __( 'Breadcrumbs visible.' ),
169
+ {
170
+ id: 'core/editor/toggle-breadcrumbs/notice',
171
+ type: 'snackbar',
172
+ }
173
+ );
174
+ },
175
+ } );
176
+
177
+ if ( isViewable ) {
178
+ commands.push( {
179
+ name: 'core/preview-link',
180
+ label: __( 'Preview in a new tab' ),
181
+ icon: external,
182
+ callback: async ( { close } ) => {
183
+ close();
184
+ const postId = getCurrentPostId();
185
+ const link = await __unstableSaveForPreview();
186
+ window.open( link, `wp-preview-${ postId }` );
187
+ },
188
+ } );
189
+ }
190
+
191
+ return {
192
+ commands,
193
+ isLoading: false,
194
+ };
195
+ }
196
+
197
+ export default function useCommands() {
198
+ useCommandLoader( {
199
+ name: 'core/editor/edit-ui',
200
+ hook: useEditorCommandLoader,
201
+ } );
202
+ }
@@ -0,0 +1,2 @@
1
+ // Commands are disabled in the mobile native version.
2
+ export default function useCommands() {}
@@ -11,7 +11,8 @@ import { useSelect, useDispatch } from '@wordpress/data';
11
11
  import {
12
12
  Button,
13
13
  __experimentalText as Text,
14
- __experimentalHStack as HStack,
14
+ __unstableMotion as motion,
15
+ __unstableAnimatePresence as AnimatePresence,
15
16
  } from '@wordpress/components';
16
17
  import { BlockIcon } from '@wordpress/block-editor';
17
18
  import {
@@ -22,16 +23,17 @@ import {
22
23
  symbol,
23
24
  } from '@wordpress/icons';
24
25
  import { displayShortcut } from '@wordpress/keycodes';
25
- import { useEntityRecord } from '@wordpress/core-data';
26
+ import { store as coreStore } from '@wordpress/core-data';
26
27
  import { store as commandsStore } from '@wordpress/commands';
27
- import { useState, useEffect, useRef } from '@wordpress/element';
28
+ import { useRef, useEffect } from '@wordpress/element';
29
+ import { useReducedMotion } from '@wordpress/compose';
28
30
 
29
31
  /**
30
32
  * Internal dependencies
31
33
  */
32
34
  import { store as editorStore } from '../../store';
33
35
 
34
- const typeLabels = {
36
+ const TYPE_LABELS = {
35
37
  // translators: 1: Pattern title.
36
38
  wp_pattern: __( 'Editing pattern: %s' ),
37
39
  // translators: 1: Navigation menu title.
@@ -42,133 +44,152 @@ const typeLabels = {
42
44
  wp_template_part: __( 'Editing template part: %s' ),
43
45
  };
44
46
 
45
- const icons = {
47
+ const ICONS = {
46
48
  wp_block: symbol,
47
49
  wp_navigation: navigationIcon,
48
50
  };
49
51
 
50
- export default function DocumentBar() {
51
- const { postType, postId, onNavigateToPreviousEntityRecord } = useSelect(
52
- ( select ) => {
53
- const {
54
- getCurrentPostId,
55
- getCurrentPostType,
56
- getEditorSettings: getSettings,
57
- } = select( editorStore );
58
- return {
59
- postType: getCurrentPostType(),
60
- postId: getCurrentPostId(),
61
- onNavigateToPreviousEntityRecord:
62
- getSettings().onNavigateToPreviousEntityRecord,
63
- getEditorSettings: getSettings,
64
- };
65
- },
66
- []
67
- );
52
+ const TEMPLATE_POST_TYPES = [ 'wp_template', 'wp_template_part' ];
68
53
 
69
- const handleOnBack = () => {
70
- if ( onNavigateToPreviousEntityRecord ) {
71
- onNavigateToPreviousEntityRecord();
72
- }
73
- };
54
+ const GLOBAL_POST_TYPES = [
55
+ ...TEMPLATE_POST_TYPES,
56
+ 'wp_block',
57
+ 'wp_navigation',
58
+ ];
74
59
 
75
- return (
76
- <BaseDocumentActions
77
- postType={ postType }
78
- postId={ postId }
79
- onBack={
80
- onNavigateToPreviousEntityRecord ? handleOnBack : undefined
81
- }
82
- />
83
- );
84
- }
60
+ const MotionButton = motion( Button );
85
61
 
86
- function BaseDocumentActions( { postType, postId, onBack } ) {
87
- const { open: openCommandCenter } = useDispatch( commandsStore );
88
- const { editedRecord: doc, isResolving } = useEntityRecord(
89
- 'postType',
62
+ export default function DocumentBar() {
63
+ const {
90
64
  postType,
91
- postId
92
- );
93
- const { templateIcon, templateTitle } = useSelect( ( select ) => {
94
- const { __experimentalGetTemplateInfo: getTemplateInfo } =
95
- select( editorStore );
96
- const templateInfo = getTemplateInfo( doc );
65
+ document,
66
+ isResolving,
67
+ templateIcon,
68
+ templateTitle,
69
+ onNavigateToPreviousEntityRecord,
70
+ } = useSelect( ( select ) => {
71
+ const {
72
+ getCurrentPostType,
73
+ getCurrentPostId,
74
+ getEditorSettings,
75
+ __experimentalGetTemplateInfo: getTemplateInfo,
76
+ } = select( editorStore );
77
+ const { getEditedEntityRecord, getIsResolving } = select( coreStore );
78
+ const _postType = getCurrentPostType();
79
+ const _postId = getCurrentPostId();
80
+ const _document = getEditedEntityRecord(
81
+ 'postType',
82
+ _postType,
83
+ _postId
84
+ );
85
+ const _templateInfo = getTemplateInfo( _document );
97
86
  return {
98
- templateIcon: templateInfo.icon,
99
- templateTitle: templateInfo.title,
87
+ postType: _postType,
88
+ document: _document,
89
+ isResolving: getIsResolving(
90
+ 'getEditedEntityRecord',
91
+ 'postType',
92
+ _postType,
93
+ _postId
94
+ ),
95
+ templateIcon: _templateInfo.icon,
96
+ templateTitle: _templateInfo.title,
97
+ onNavigateToPreviousEntityRecord:
98
+ getEditorSettings().onNavigateToPreviousEntityRecord,
100
99
  };
101
- } );
102
- const isNotFound = ! doc && ! isResolving;
103
- const icon = icons[ postType ] ?? pageIcon;
104
- const [ isAnimated, setIsAnimated ] = useState( false );
105
- const isMounting = useRef( true );
106
- const isTemplate = [ 'wp_template', 'wp_template_part' ].includes(
107
- postType
108
- );
109
- const isGlobalEntity = [
110
- 'wp_template',
111
- 'wp_navigation',
112
- 'wp_template_part',
113
- 'wp_block',
114
- ].includes( postType );
100
+ }, [] );
115
101
 
116
- useEffect( () => {
117
- if ( ! isMounting.current ) {
118
- setIsAnimated( true );
119
- }
120
- isMounting.current = false;
121
- }, [ postType, postId ] );
102
+ const { open: openCommandCenter } = useDispatch( commandsStore );
103
+ const isReducedMotion = useReducedMotion();
104
+
105
+ const isNotFound = ! document && ! isResolving;
106
+ const icon = ICONS[ postType ] ?? pageIcon;
107
+ const isTemplate = TEMPLATE_POST_TYPES.includes( postType );
108
+ const isGlobalEntity = GLOBAL_POST_TYPES.includes( postType );
109
+ const hasBackButton = !! onNavigateToPreviousEntityRecord;
110
+ const title = isTemplate ? templateTitle : document.title;
122
111
 
123
- const title = isTemplate ? templateTitle : doc.title;
112
+ const mounted = useRef( false );
113
+ useEffect( () => {
114
+ mounted.current = true;
115
+ }, [] );
124
116
 
125
117
  return (
126
118
  <div
127
119
  className={ classnames( 'editor-document-bar', {
128
- 'has-back-button': !! onBack,
129
- 'is-animated': isAnimated,
120
+ 'has-back-button': hasBackButton,
130
121
  'is-global': isGlobalEntity,
131
122
  } ) }
132
123
  >
133
- { onBack && (
134
- <Button
135
- className="editor-document-bar__back"
136
- icon={ isRTL() ? chevronRightSmall : chevronLeftSmall }
137
- onClick={ ( event ) => {
138
- event.stopPropagation();
139
- onBack();
140
- } }
141
- size="compact"
142
- >
143
- { __( 'Back' ) }
144
- </Button>
145
- ) }
146
- { isNotFound && <Text>{ __( 'Document not found' ) }</Text> }
147
- { ! isNotFound && (
124
+ <AnimatePresence>
125
+ { hasBackButton && (
126
+ <MotionButton
127
+ className="editor-document-bar__back"
128
+ icon={ isRTL() ? chevronRightSmall : chevronLeftSmall }
129
+ onClick={ ( event ) => {
130
+ event.stopPropagation();
131
+ onNavigateToPreviousEntityRecord();
132
+ } }
133
+ size="compact"
134
+ initial={
135
+ mounted.current
136
+ ? { opacity: 0, transform: 'translateX(15%)' }
137
+ : false // Don't show entry animation when DocumentBar mounts.
138
+ }
139
+ animate={ { opacity: 1, transform: 'translateX(0%)' } }
140
+ exit={ { opacity: 0, transform: 'translateX(15%)' } }
141
+ transition={
142
+ isReducedMotion ? { duration: 0 } : undefined
143
+ }
144
+ >
145
+ { __( 'Back' ) }
146
+ </MotionButton>
147
+ ) }
148
+ </AnimatePresence>
149
+ { isNotFound ? (
150
+ <Text>{ __( 'Document not found' ) }</Text>
151
+ ) : (
148
152
  <Button
149
153
  className="editor-document-bar__command"
150
154
  onClick={ () => openCommandCenter() }
151
155
  size="compact"
152
156
  >
153
- <HStack
157
+ <motion.div
154
158
  className="editor-document-bar__title"
155
- spacing={ 1 }
156
- justify="center"
159
+ // Force entry animation when the back button is added or removed.
160
+ key={ hasBackButton }
161
+ initial={
162
+ mounted.current
163
+ ? {
164
+ opacity: 0,
165
+ transform: hasBackButton
166
+ ? 'translateX(15%)'
167
+ : 'translateX(-15%)',
168
+ }
169
+ : false // Don't show entry animation when DocumentBar mounts.
170
+ }
171
+ animate={ {
172
+ opacity: 1,
173
+ transform: 'translateX(0%)',
174
+ } }
175
+ transition={
176
+ isReducedMotion ? { duration: 0 } : undefined
177
+ }
157
178
  >
158
179
  <BlockIcon icon={ isTemplate ? templateIcon : icon } />
159
180
  <Text
160
181
  size="body"
161
182
  as="h1"
162
183
  aria-label={
163
- typeLabels[ postType ]
184
+ TYPE_LABELS[ postType ]
164
185
  ? // eslint-disable-next-line @wordpress/valid-sprintf
165
- sprintf( typeLabels[ postType ], title )
186
+ sprintf( TYPE_LABELS[ postType ], title )
166
187
  : undefined
167
188
  }
168
189
  >
169
190
  { title }
170
191
  </Text>
171
- </HStack>
192
+ </motion.div>
172
193
  <span className="editor-document-bar__shortcut">
173
194
  { displayShortcut.primary( 'k' ) }
174
195
  </span>
@@ -40,6 +40,10 @@
40
40
  flex-grow: 1;
41
41
  overflow: hidden;
42
42
  color: $gray-800;
43
+ gap: $grid-unit-05;
44
+ display: flex;
45
+ justify-content: center;
46
+ align-items: center;
43
47
 
44
48
  // Offset the layout based on the width of the ⌘K label. This ensures the title is centrally aligned.
45
49
  @include break-small() {
@@ -66,16 +70,6 @@
66
70
  max-width: 50%;
67
71
  color: currentColor;
68
72
  }
69
-
70
- .editor-document-bar.is-animated.has-back-button & {
71
- animation: editor-document-bar__slide-in-left 0.3s;
72
- @include reduce-motion("animation");
73
- }
74
-
75
- .editor-document-bar.is-animated & {
76
- animation: editor-document-bar__slide-in-right 0.3s;
77
- @include reduce-motion("animation");
78
- }
79
73
  }
80
74
 
81
75
  .editor-document-bar__shortcut {
@@ -100,31 +94,4 @@
100
94
  color: var(--wp-block-synced-color);
101
95
  background-color: transparent;
102
96
  }
103
-
104
- .editor-document-bar.is-animated & {
105
- animation: editor-document-bar__slide-in-left 0.3s;
106
- @include reduce-motion("animation");
107
- }
108
- }
109
-
110
- @keyframes editor-document-bar__slide-in-right {
111
- from {
112
- transform: translateX(-15%);
113
- opacity: 0;
114
- }
115
- to {
116
- transform: translateX(0);
117
- opacity: 1;
118
- }
119
- }
120
-
121
- @keyframes editor-document-bar__slide-in-left {
122
- from {
123
- transform: translateX(15%);
124
- opacity: 0;
125
- }
126
- to {
127
- transform: translateX(0);
128
- opacity: 1;
129
- }
130
97
  }
@@ -46,6 +46,7 @@ function DocumentTools( {
46
46
  const { setIsInserterOpened, setIsListViewOpened } =
47
47
  useDispatch( editorStore );
48
48
  const {
49
+ isDistractionFree,
49
50
  isInserterOpened,
50
51
  isListViewOpen,
51
52
  listViewShortcut,
@@ -69,6 +70,7 @@ function DocumentTools( {
69
70
  listViewToggleRef: getListViewToggleRef(),
70
71
  hasFixedToolbar: getSettings().hasFixedToolbar,
71
72
  showIconLabels: get( 'core', 'showIconLabels' ),
73
+ isDistractionFree: get( 'core', 'distractionFree' ),
72
74
  };
73
75
  }, [] );
74
76
 
@@ -158,22 +160,26 @@ function DocumentTools( {
158
160
  variant={ showIconLabels ? 'tertiary' : undefined }
159
161
  size="compact"
160
162
  />
161
- <ToolbarItem
162
- as={ Button }
163
- className="editor-document-tools__document-overview-toggle"
164
- icon={ listView }
165
- disabled={ disableBlockTools }
166
- isPressed={ isListViewOpen }
167
- /* translators: button label text should, if possible, be under 16 characters. */
168
- label={ listViewLabel }
169
- onClick={ toggleListView }
170
- shortcut={ listViewShortcut }
171
- showTooltip={ ! showIconLabels }
172
- variant={ showIconLabels ? 'tertiary' : undefined }
173
- aria-expanded={ isListViewOpen }
174
- ref={ listViewToggleRef }
175
- size="compact"
176
- />
163
+ { ! isDistractionFree && (
164
+ <ToolbarItem
165
+ as={ Button }
166
+ className="editor-document-tools__document-overview-toggle"
167
+ icon={ listView }
168
+ disabled={ disableBlockTools }
169
+ isPressed={ isListViewOpen }
170
+ /* translators: button label text should, if possible, be under 16 characters. */
171
+ label={ listViewLabel }
172
+ onClick={ toggleListView }
173
+ shortcut={ listViewShortcut }
174
+ showTooltip={ ! showIconLabels }
175
+ variant={
176
+ showIconLabels ? 'tertiary' : undefined
177
+ }
178
+ aria-expanded={ isListViewOpen }
179
+ ref={ listViewToggleRef }
180
+ size="compact"
181
+ />
182
+ ) }
177
183
  </>
178
184
  ) }
179
185
  { children }