@wordpress/edit-site 5.27.0 → 5.27.2

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 (114) hide show
  1. package/build/components/block-editor/back-button.js +2 -3
  2. package/build/components/block-editor/back-button.js.map +1 -1
  3. package/build/components/block-editor/site-editor-canvas.js +8 -2
  4. package/build/components/block-editor/site-editor-canvas.js.map +1 -1
  5. package/build/components/block-editor/use-post-link-props.js +5 -1
  6. package/build/components/block-editor/use-post-link-props.js.map +1 -1
  7. package/build/components/editor/index.js +7 -7
  8. package/build/components/editor/index.js.map +1 -1
  9. package/build/components/global-styles/font-library-modal/context.js +14 -0
  10. package/build/components/global-styles/font-library-modal/context.js.map +1 -1
  11. package/build/components/global-styles/font-library-modal/font-collection.js +17 -33
  12. package/build/components/global-styles/font-library-modal/font-collection.js.map +1 -1
  13. package/build/components/global-styles/font-library-modal/font-demo.js +1 -1
  14. package/build/components/global-styles/font-library-modal/font-demo.js.map +1 -1
  15. package/build/components/global-styles/font-library-modal/google-fonts-confirm-dialog.js +1 -1
  16. package/build/components/global-styles/font-library-modal/google-fonts-confirm-dialog.js.map +1 -1
  17. package/build/components/global-styles/font-library-modal/index.js +10 -3
  18. package/build/components/global-styles/font-library-modal/index.js.map +1 -1
  19. package/build/components/global-styles/font-library-modal/installed-fonts.js +8 -21
  20. package/build/components/global-styles/font-library-modal/installed-fonts.js.map +1 -1
  21. package/build/components/global-styles/font-library-modal/library-font-variant.js +2 -2
  22. package/build/components/global-styles/font-library-modal/library-font-variant.js.map +1 -1
  23. package/build/components/global-styles/font-library-modal/resolvers.js +1 -1
  24. package/build/components/global-styles/font-library-modal/resolvers.js.map +1 -1
  25. package/build/components/global-styles/font-library-modal/tab-panel-layout.js +14 -2
  26. package/build/components/global-styles/font-library-modal/tab-panel-layout.js.map +1 -1
  27. package/build/components/global-styles/font-library-modal/upload-fonts.js +160 -4
  28. package/build/components/global-styles/font-library-modal/upload-fonts.js.map +1 -1
  29. package/build/components/global-styles/font-library-modal/utils/index.js +33 -31
  30. package/build/components/global-styles/font-library-modal/utils/index.js.map +1 -1
  31. package/build/components/global-styles/screen-block.js +10 -0
  32. package/build/components/global-styles/screen-block.js.map +1 -1
  33. package/build/components/routes/link.js +1 -1
  34. package/build/components/routes/link.js.map +1 -1
  35. package/build/components/sidebar-edit-mode/index.js +1 -2
  36. package/build/components/sidebar-edit-mode/index.js.map +1 -1
  37. package/build/components/sidebar-edit-mode/settings-header/index.js +7 -36
  38. package/build/components/sidebar-edit-mode/settings-header/index.js.map +1 -1
  39. package/build/components/welcome-guide/template.js +2 -2
  40. package/build/components/welcome-guide/template.js.map +1 -1
  41. package/build/hooks/commands/use-edit-mode-commands.js +16 -6
  42. package/build/hooks/commands/use-edit-mode-commands.js.map +1 -1
  43. package/build-module/components/block-editor/back-button.js +2 -3
  44. package/build-module/components/block-editor/back-button.js.map +1 -1
  45. package/build-module/components/block-editor/site-editor-canvas.js +8 -2
  46. package/build-module/components/block-editor/site-editor-canvas.js.map +1 -1
  47. package/build-module/components/block-editor/use-post-link-props.js +5 -1
  48. package/build-module/components/block-editor/use-post-link-props.js.map +1 -1
  49. package/build-module/components/editor/index.js +7 -7
  50. package/build-module/components/editor/index.js.map +1 -1
  51. package/build-module/components/global-styles/font-library-modal/context.js +14 -0
  52. package/build-module/components/global-styles/font-library-modal/context.js.map +1 -1
  53. package/build-module/components/global-styles/font-library-modal/font-collection.js +19 -35
  54. package/build-module/components/global-styles/font-library-modal/font-collection.js.map +1 -1
  55. package/build-module/components/global-styles/font-library-modal/font-demo.js +1 -1
  56. package/build-module/components/global-styles/font-library-modal/font-demo.js.map +1 -1
  57. package/build-module/components/global-styles/font-library-modal/google-fonts-confirm-dialog.js +1 -1
  58. package/build-module/components/global-styles/font-library-modal/google-fonts-confirm-dialog.js.map +1 -1
  59. package/build-module/components/global-styles/font-library-modal/index.js +10 -3
  60. package/build-module/components/global-styles/font-library-modal/index.js.map +1 -1
  61. package/build-module/components/global-styles/font-library-modal/installed-fonts.js +9 -22
  62. package/build-module/components/global-styles/font-library-modal/installed-fonts.js.map +1 -1
  63. package/build-module/components/global-styles/font-library-modal/library-font-variant.js +2 -2
  64. package/build-module/components/global-styles/font-library-modal/library-font-variant.js.map +1 -1
  65. package/build-module/components/global-styles/font-library-modal/resolvers.js +1 -1
  66. package/build-module/components/global-styles/font-library-modal/resolvers.js.map +1 -1
  67. package/build-module/components/global-styles/font-library-modal/tab-panel-layout.js +15 -3
  68. package/build-module/components/global-styles/font-library-modal/tab-panel-layout.js.map +1 -1
  69. package/build-module/components/global-styles/font-library-modal/upload-fonts.js +162 -6
  70. package/build-module/components/global-styles/font-library-modal/upload-fonts.js.map +1 -1
  71. package/build-module/components/global-styles/font-library-modal/utils/index.js +32 -30
  72. package/build-module/components/global-styles/font-library-modal/utils/index.js.map +1 -1
  73. package/build-module/components/global-styles/screen-block.js +10 -0
  74. package/build-module/components/global-styles/screen-block.js.map +1 -1
  75. package/build-module/components/routes/link.js +1 -1
  76. package/build-module/components/routes/link.js.map +1 -1
  77. package/build-module/components/sidebar-edit-mode/index.js +1 -2
  78. package/build-module/components/sidebar-edit-mode/index.js.map +1 -1
  79. package/build-module/components/sidebar-edit-mode/settings-header/index.js +7 -36
  80. package/build-module/components/sidebar-edit-mode/settings-header/index.js.map +1 -1
  81. package/build-module/components/welcome-guide/template.js +2 -2
  82. package/build-module/components/welcome-guide/template.js.map +1 -1
  83. package/build-module/hooks/commands/use-edit-mode-commands.js +16 -6
  84. package/build-module/hooks/commands/use-edit-mode-commands.js.map +1 -1
  85. package/build-style/style-rtl.css +16 -31
  86. package/build-style/style.css +16 -31
  87. package/package.json +13 -13
  88. package/src/components/block-editor/back-button.js +6 -3
  89. package/src/components/block-editor/site-editor-canvas.js +19 -12
  90. package/src/components/block-editor/use-post-link-props.js +5 -1
  91. package/src/components/editor/index.js +4 -9
  92. package/src/components/global-styles/font-library-modal/context.js +14 -0
  93. package/src/components/global-styles/font-library-modal/font-collection.js +16 -40
  94. package/src/components/global-styles/font-library-modal/font-demo.js +1 -1
  95. package/src/components/global-styles/font-library-modal/google-fonts-confirm-dialog.js +1 -1
  96. package/src/components/global-styles/font-library-modal/index.js +8 -3
  97. package/src/components/global-styles/font-library-modal/installed-fonts.js +12 -31
  98. package/src/components/global-styles/font-library-modal/library-font-variant.js +2 -2
  99. package/src/components/global-styles/font-library-modal/resolvers.js +1 -1
  100. package/src/components/global-styles/font-library-modal/style.scss +20 -43
  101. package/src/components/global-styles/font-library-modal/tab-panel-layout.js +45 -26
  102. package/src/components/global-styles/font-library-modal/upload-fonts.js +201 -6
  103. package/src/components/global-styles/font-library-modal/utils/index.js +44 -38
  104. package/src/components/global-styles/screen-block.js +10 -0
  105. package/src/components/routes/link.js +1 -1
  106. package/src/components/sidebar-edit-mode/index.js +1 -4
  107. package/src/components/sidebar-edit-mode/settings-header/index.js +12 -34
  108. package/src/components/welcome-guide/template.js +2 -2
  109. package/src/hooks/commands/use-edit-mode-commands.js +26 -14
  110. package/build/components/global-styles/font-library-modal/local-fonts.js +0 -196
  111. package/build/components/global-styles/font-library-modal/local-fonts.js.map +0 -1
  112. package/build-module/components/global-styles/font-library-modal/local-fonts.js +0 -187
  113. package/build-module/components/global-styles/font-library-modal/local-fonts.js.map +0 -1
  114. package/src/components/global-styles/font-library-modal/local-fonts.js +0 -239
@@ -1,19 +1,214 @@
1
1
  /**
2
2
  * WordPress dependencies
3
3
  */
4
- import { __experimentalSpacer as Spacer } from '@wordpress/components';
4
+ import { __, sprintf } from '@wordpress/i18n';
5
+ import {
6
+ Button,
7
+ DropZone,
8
+ __experimentalSpacer as Spacer,
9
+ __experimentalText as Text,
10
+ __experimentalVStack as VStack,
11
+ FormFileUpload,
12
+ FlexItem,
13
+ privateApis as componentsPrivateApis,
14
+ } from '@wordpress/components';
15
+ import { useContext, useState } from '@wordpress/element';
5
16
 
6
17
  /**
7
18
  * Internal dependencies
8
19
  */
9
- import LocalFonts from './local-fonts';
20
+ import { ALLOWED_FILE_EXTENSIONS } from './utils/constants';
21
+ import { FontLibraryContext } from './context';
22
+ import { Font } from '../../../../lib/lib-font.browser';
23
+ import makeFamiliesFromFaces from './utils/make-families-from-faces';
24
+ import { loadFontFaceInBrowser } from './utils';
25
+ import TabPanelLayout from './tab-panel-layout';
26
+ import { unlock } from '../../../lock-unlock';
27
+
28
+ const { ProgressBar } = unlock( componentsPrivateApis );
10
29
 
11
30
  function UploadFonts() {
31
+ const { installFont, notice, setNotice } = useContext( FontLibraryContext );
32
+ const [ isUploading, setIsUploading ] = useState( false );
33
+ const supportedFormats =
34
+ ALLOWED_FILE_EXTENSIONS.slice( 0, -1 )
35
+ .map( ( extension ) => `.${ extension }` )
36
+ .join( ', ' ) +
37
+ ` ${ __( 'and' ) } .${ ALLOWED_FILE_EXTENSIONS.slice( -1 ) }`;
38
+
39
+ const handleDropZone = ( files ) => {
40
+ handleFilesUpload( files );
41
+ };
42
+ const onFilesUpload = ( event ) => {
43
+ handleFilesUpload( event.target.files );
44
+ };
45
+
46
+ /**
47
+ * Filters the selected files to only allow the ones with the allowed extensions
48
+ *
49
+ * @param {Array} files The files to be filtered
50
+ * @return {void}
51
+ */
52
+ const handleFilesUpload = ( files ) => {
53
+ setNotice( null );
54
+ setIsUploading( true );
55
+ const uniqueFilenames = new Set();
56
+ const selectedFiles = [ ...files ];
57
+ const allowedFiles = selectedFiles.filter( ( file ) => {
58
+ if ( uniqueFilenames.has( file.name ) ) {
59
+ return false; // Discard duplicates
60
+ }
61
+ // Eliminates files that are not allowed
62
+ const fileExtension = file.name.split( '.' ).pop().toLowerCase();
63
+ if ( ALLOWED_FILE_EXTENSIONS.includes( fileExtension ) ) {
64
+ uniqueFilenames.add( file.name );
65
+ return true; // Keep file if the extension is allowed
66
+ }
67
+ return false; // Discard file extension not allowed
68
+ } );
69
+ if ( allowedFiles.length > 0 ) {
70
+ loadFiles( allowedFiles );
71
+ }
72
+ };
73
+
74
+ /**
75
+ * Loads the selected files and reads the font metadata
76
+ *
77
+ * @param {Array} files The files to be loaded
78
+ * @return {void}
79
+ */
80
+ const loadFiles = async ( files ) => {
81
+ const fontFacesLoaded = await Promise.all(
82
+ files.map( async ( fontFile ) => {
83
+ const fontFaceData = await getFontFaceMetadata( fontFile );
84
+ await loadFontFaceInBrowser(
85
+ fontFaceData,
86
+ fontFaceData.file,
87
+ 'all'
88
+ );
89
+ return fontFaceData;
90
+ } )
91
+ );
92
+ handleInstall( fontFacesLoaded );
93
+ };
94
+
95
+ // Create a function to read the file as array buffer
96
+ async function readFileAsArrayBuffer( file ) {
97
+ return new Promise( ( resolve, reject ) => {
98
+ const reader = new window.FileReader();
99
+ reader.readAsArrayBuffer( file );
100
+ reader.onload = () => resolve( reader.result );
101
+ reader.onerror = reject;
102
+ } );
103
+ }
104
+
105
+ const getFontFaceMetadata = async ( fontFile ) => {
106
+ const buffer = await readFileAsArrayBuffer( fontFile );
107
+ const fontObj = new Font( 'Uploaded Font' );
108
+ fontObj.fromDataBuffer( buffer, fontFile.name );
109
+ // Assuming that fromDataBuffer triggers onload event and returning a Promise
110
+ const onloadEvent = await new Promise(
111
+ ( resolve ) => ( fontObj.onload = resolve )
112
+ );
113
+ const font = onloadEvent.detail.font;
114
+ const { name } = font.opentype.tables;
115
+ const fontName = name.get( 16 ) || name.get( 1 );
116
+ const isItalic = name.get( 2 ).toLowerCase().includes( 'italic' );
117
+ const fontWeight =
118
+ font.opentype.tables[ 'OS/2' ].usWeightClass || 'normal';
119
+ const isVariable = !! font.opentype.tables.fvar;
120
+ const weightAxis =
121
+ isVariable &&
122
+ font.opentype.tables.fvar.axes.find(
123
+ ( { tag } ) => tag === 'wght'
124
+ );
125
+ const weightRange = weightAxis
126
+ ? `${ weightAxis.minValue } ${ weightAxis.maxValue }`
127
+ : null;
128
+ return {
129
+ file: fontFile,
130
+ fontFamily: fontName,
131
+ fontStyle: isItalic ? 'italic' : 'normal',
132
+ fontWeight: weightRange || fontWeight,
133
+ };
134
+ };
135
+
136
+ /**
137
+ * Creates the font family definition and sends it to the server
138
+ *
139
+ * @param {Array} fontFaces The font faces to be installed
140
+ * @return {void}
141
+ */
142
+ const handleInstall = async ( fontFaces ) => {
143
+ const fontFamilies = makeFamiliesFromFaces( fontFaces );
144
+
145
+ if ( fontFamilies.length > 1 ) {
146
+ setNotice( {
147
+ type: 'error',
148
+ message: __(
149
+ 'Variants from only one font family can be uploaded at a time.'
150
+ ),
151
+ } );
152
+ setIsUploading( false );
153
+ return;
154
+ }
155
+
156
+ try {
157
+ await installFont( fontFamilies[ 0 ] );
158
+ setNotice( {
159
+ type: 'success',
160
+ message: __( 'Fonts were installed successfully.' ),
161
+ } );
162
+ } catch ( error ) {
163
+ setNotice( {
164
+ type: 'error',
165
+ message: error.message,
166
+ } );
167
+ }
168
+
169
+ setIsUploading( false );
170
+ };
171
+
12
172
  return (
13
- <>
14
- <Spacer margin={ 8 } />
15
- <LocalFonts />
16
- </>
173
+ <TabPanelLayout notice={ notice }>
174
+ <DropZone onFilesDrop={ handleDropZone } />
175
+ <VStack className="font-library-modal__local-fonts">
176
+ { isUploading && (
177
+ <FlexItem>
178
+ <div className="font-library-modal__upload-area">
179
+ <ProgressBar />
180
+ </div>
181
+ </FlexItem>
182
+ ) }
183
+ { ! isUploading && (
184
+ <FormFileUpload
185
+ accept={ ALLOWED_FILE_EXTENSIONS.map(
186
+ ( ext ) => `.${ ext }`
187
+ ).join( ',' ) }
188
+ multiple={ true }
189
+ onChange={ onFilesUpload }
190
+ render={ ( { openFileDialog } ) => (
191
+ <Button
192
+ className="font-library-modal__upload-area"
193
+ onClick={ openFileDialog }
194
+ >
195
+ <span>{ __( 'Upload font' ) }</span>
196
+ </Button>
197
+ ) }
198
+ />
199
+ ) }
200
+ <Spacer margin={ 2 } />
201
+ <Text className="font-library-modal__upload-area__text">
202
+ { sprintf(
203
+ /* translators: %s: supported font formats: ex: .ttf, .woff and .woff2 */
204
+ __(
205
+ 'Uploaded fonts appear in your library and can be used in your theme. Supported formats: %s.'
206
+ ),
207
+ supportedFormats
208
+ ) }
209
+ </Text>
210
+ </VStack>
211
+ </TabPanelLayout>
17
212
  );
18
213
  }
19
214
 
@@ -164,20 +164,24 @@ export function makeFontFacesFormData( font ) {
164
164
  const fontFacesFormData = font.fontFace.map( ( face, faceIndex ) => {
165
165
  const formData = new FormData();
166
166
  if ( face.file ) {
167
- // Slugified file name because the it might contain spaces or characters treated differently on the server.
168
- const fileId = `file-${ faceIndex }`;
169
- // Add the files to the formData
170
- formData.append( fileId, face.file, face.file.name );
171
- // remove the file object from the face object the file is referenced in src
172
- const { file, ...faceWithoutFileProperty } = face;
173
- const fontFaceSettings = {
174
- ...faceWithoutFileProperty,
175
- src: fileId,
176
- };
177
- formData.append(
178
- 'font_face_settings',
179
- JSON.stringify( fontFaceSettings )
180
- );
167
+ // Normalize to an array, since face.file may be a single file or an array of files.
168
+ const files = Array.isArray( face.file )
169
+ ? face.file
170
+ : [ face.file ];
171
+ const src = [];
172
+
173
+ files.forEach( ( file, key ) => {
174
+ // Slugified file name because the it might contain spaces or characters treated differently on the server.
175
+ const fileId = `file-${ faceIndex }-${ key }`;
176
+ // Add the files to the formData
177
+ formData.append( fileId, file, file.name );
178
+ src.push( fileId );
179
+ } );
180
+
181
+ face.src = src.length === 1 ? src[ 0 ] : src;
182
+ delete face.file;
183
+
184
+ formData.append( 'font_face_settings', JSON.stringify( face ) );
181
185
  } else {
182
186
  formData.append( 'font_face_settings', JSON.stringify( face ) );
183
187
  }
@@ -225,31 +229,33 @@ export async function batchInstallFontFaces( fontFamilyId, fontFacesData ) {
225
229
  /*
226
230
  * Downloads a font face asset from a URL to the client and returns a File object.
227
231
  */
228
- export async function downloadFontFaceAsset( url ) {
229
- return fetch( new Request( url ) )
230
- .then( ( response ) => {
231
- if ( ! response.ok ) {
232
- throw new Error(
233
- `Error downloading font face asset from ${ url }. Server responded with status: ${ response.status }`
234
- );
235
- }
236
- return response.blob();
237
- } )
238
- .then( ( blob ) => {
239
- const filename = url.split( '/' ).pop();
240
- const file = new File( [ blob ], filename, {
241
- type: blob.type,
242
- } );
243
- return file;
232
+ export async function downloadFontFaceAssets( src ) {
233
+ // Normalize to an array, since `src` could be a string or array.
234
+ src = Array.isArray( src ) ? src : [ src ];
235
+
236
+ const files = await Promise.all(
237
+ src.map( async ( url ) => {
238
+ return fetch( new Request( url ) )
239
+ .then( ( response ) => {
240
+ if ( ! response.ok ) {
241
+ throw new Error(
242
+ `Error downloading font face asset from ${ url }. Server responded with status: ${ response.status }`
243
+ );
244
+ }
245
+ return response.blob();
246
+ } )
247
+ .then( ( blob ) => {
248
+ const filename = url.split( '/' ).pop();
249
+ const file = new File( [ blob ], filename, {
250
+ type: blob.type,
251
+ } );
252
+ return file;
253
+ } );
244
254
  } )
245
- .catch( ( error ) => {
246
- // eslint-disable-next-line no-console
247
- console.error(
248
- `Error downloading font face asset from ${ url }:`,
249
- error
250
- );
251
- throw error;
252
- } );
255
+ );
256
+
257
+ // If we only have one file return it (not the array). Otherwise return all of them in the array.
258
+ return files.length === 1 ? files[ 0 ] : files;
253
259
  }
254
260
 
255
261
  /*
@@ -109,6 +109,16 @@ function ScreenBlock( { name, variation } ) {
109
109
  settings.spacing.blockGap = false;
110
110
  }
111
111
 
112
+ // Only allow `aspectRatio` support if the block is not the grouping block.
113
+ // The grouping block allows the user to use Group, Row and Stack variations,
114
+ // and it is highly likely that the user will not want to set an aspect ratio
115
+ // for all three at once. Until there is the ability to set a different aspect
116
+ // ratio for each variation, we disable the aspect ratio controls for the
117
+ // grouping block in global styles.
118
+ if ( settings?.dimensions?.aspectRatio && name === 'core/group' ) {
119
+ settings.dimensions.aspectRatio = false;
120
+ }
121
+
112
122
  const blockVariations = useBlockVariations( name );
113
123
  const hasTypographyPanel = useHasTypographyPanel( settings );
114
124
  const hasColorPanel = useHasColorPanel( settings );
@@ -22,7 +22,7 @@ export function getPostLinkProps(
22
22
  shouldReplace = false
23
23
  ) {
24
24
  function onClick( event ) {
25
- event.preventDefault();
25
+ event?.preventDefault();
26
26
 
27
27
  if ( shouldReplace ) {
28
28
  history.replace( params, state );
@@ -8,7 +8,6 @@ import { useEffect } from '@wordpress/element';
8
8
  import { useSelect, useDispatch } from '@wordpress/data';
9
9
  import { store as interfaceStore } from '@wordpress/interface';
10
10
  import { store as blockEditorStore } from '@wordpress/block-editor';
11
- import { store as editorStore } from '@wordpress/editor';
12
11
 
13
12
  /**
14
13
  * Internal dependencies
@@ -49,9 +48,7 @@ export function SidebarComplementaryAreaFills() {
49
48
  hasBlockSelection:
50
49
  !! select( blockEditorStore ).getBlockSelectionStart(),
51
50
  supportsGlobalStyles: ! settings?.supportsTemplatePartsMode,
52
- isEditingPage:
53
- select( editSiteStore ).isPage() &&
54
- select( editorStore ).getRenderingMode() !== 'template-only',
51
+ isEditingPage: select( editSiteStore ).isPage(),
55
52
  };
56
53
  }, [] );
57
54
  const { enableComplementaryArea } = useDispatch( interfaceStore );
@@ -17,23 +17,12 @@ import { store as editorStore } from '@wordpress/editor';
17
17
  */
18
18
  import { STORE_NAME } from '../../../store/constants';
19
19
  import { SIDEBAR_BLOCK, SIDEBAR_TEMPLATE } from '../constants';
20
- import { store as editSiteStore } from '../../../store';
21
- import { POST_TYPE_LABELS, TEMPLATE_POST_TYPE } from '../../../utils/constants';
22
20
 
23
21
  const SettingsHeader = ( { sidebarName } ) => {
24
- const { isEditingPage, entityType } = useSelect( ( select ) => {
25
- const { getEditedPostType, isPage } = select( editSiteStore );
26
- const { getRenderingMode } = select( editorStore );
27
-
28
- return {
29
- isEditingPage: isPage() && getRenderingMode() !== 'template-only',
30
- entityType: getEditedPostType(),
31
- };
32
- } );
33
-
34
- const entityLabel =
35
- POST_TYPE_LABELS[ entityType ] ||
36
- POST_TYPE_LABELS[ TEMPLATE_POST_TYPE ];
22
+ const postTypeLabel = useSelect(
23
+ ( select ) => select( editorStore ).getPostTypeLabel(),
24
+ []
25
+ );
37
26
 
38
27
  const { enableComplementaryArea } = useDispatch( interfaceStore );
39
28
  const openTemplateSettings = () =>
@@ -41,22 +30,11 @@ const SettingsHeader = ( { sidebarName } ) => {
41
30
  const openBlockSettings = () =>
42
31
  enableComplementaryArea( STORE_NAME, SIDEBAR_BLOCK );
43
32
 
44
- let templateAriaLabel;
45
- if ( isEditingPage ) {
46
- templateAriaLabel =
47
- sidebarName === SIDEBAR_TEMPLATE
48
- ? // translators: ARIA label for the Template sidebar tab, selected.
49
- __( 'Page (selected)' )
50
- : // translators: ARIA label for the Template Settings Sidebar tab, not selected.
51
- __( 'Page' );
52
- } else {
53
- templateAriaLabel =
54
- sidebarName === SIDEBAR_TEMPLATE
55
- ? // translators: ARIA label for the Template sidebar tab, selected.
56
- sprintf( __( '%s (selected)' ), entityLabel )
57
- : // translators: ARIA label for the Template Settings Sidebar tab, not selected.
58
- entityLabel;
59
- }
33
+ const documentAriaLabel =
34
+ sidebarName === SIDEBAR_TEMPLATE
35
+ ? // translators: ARIA label for the Template sidebar tab, selected.
36
+ sprintf( __( '%s (selected)' ), postTypeLabel )
37
+ : postTypeLabel;
60
38
 
61
39
  /* Use a list so screen readers will announce how many tabs there are. */
62
40
  return (
@@ -70,10 +48,10 @@ const SettingsHeader = ( { sidebarName } ) => {
70
48
  'is-active': sidebarName === SIDEBAR_TEMPLATE,
71
49
  }
72
50
  ) }
73
- aria-label={ templateAriaLabel }
74
- data-label={ isEditingPage ? __( 'Page' ) : entityLabel }
51
+ aria-label={ documentAriaLabel }
52
+ data-label={ postTypeLabel }
75
53
  >
76
- { isEditingPage ? __( 'Page' ) : entityLabel }
54
+ { postTypeLabel }
77
55
  </Button>
78
56
  </li>
79
57
  <li>
@@ -25,12 +25,12 @@ export default function WelcomeGuideTemplate() {
25
25
  'welcomeGuide'
26
26
  );
27
27
  const { isPage } = select( editSiteStore );
28
- const { getRenderingMode } = select( editorStore );
28
+ const { getCurrentPostType } = select( editorStore );
29
29
  return (
30
30
  isTemplateActive &&
31
31
  ! isEditorActive &&
32
32
  isPage() &&
33
- getRenderingMode() === 'template-only'
33
+ getCurrentPostType() === 'wp_template'
34
34
  );
35
35
  }, [] );
36
36
 
@@ -38,22 +38,34 @@ import { PREFERENCES_MODAL_NAME } from '../../components/preferences-modal';
38
38
  import { PATTERN_MODALS } from '../../components/pattern-modal';
39
39
  import { unlock } from '../../lock-unlock';
40
40
  import { TEMPLATE_POST_TYPE } from '../../utils/constants';
41
+ import { useLink } from '../../components/routes/link';
41
42
 
42
43
  const { useHistory } = unlock( routerPrivateApis );
43
44
 
44
45
  function usePageContentFocusCommands() {
45
46
  const { record: template } = useEditedEntityRecord();
46
- const { isPage, canvasMode, renderingMode } = useSelect( ( select ) => {
47
- const { isPage: _isPage, getCanvasMode } = unlock(
48
- select( editSiteStore )
49
- );
50
- const { getRenderingMode } = select( editorStore );
51
- return {
52
- isPage: _isPage(),
53
- canvasMode: getCanvasMode(),
54
- renderingMode: getRenderingMode(),
55
- };
56
- }, [] );
47
+ const { isPage, canvasMode, templateId, currentPostType } = useSelect(
48
+ ( select ) => {
49
+ const { isPage: _isPage, getCanvasMode } = unlock(
50
+ select( editSiteStore )
51
+ );
52
+ const { getCurrentPostType, getCurrentTemplateId } =
53
+ select( editorStore );
54
+ return {
55
+ isPage: _isPage(),
56
+ canvasMode: getCanvasMode(),
57
+ templateId: getCurrentTemplateId(),
58
+ currentPostType: getCurrentPostType(),
59
+ };
60
+ },
61
+ []
62
+ );
63
+
64
+ const { onClick: editTemplate } = useLink( {
65
+ postType: 'wp_template',
66
+ postId: templateId,
67
+ } );
68
+
57
69
  const { setRenderingMode } = useDispatch( editorStore );
58
70
 
59
71
  if ( ! isPage || canvasMode !== 'edit' ) {
@@ -62,7 +74,7 @@ function usePageContentFocusCommands() {
62
74
 
63
75
  const commands = [];
64
76
 
65
- if ( renderingMode !== 'template-only' ) {
77
+ if ( currentPostType !== 'wp_template' ) {
66
78
  commands.push( {
67
79
  name: 'core/switch-to-template-focus',
68
80
  /* translators: %1$s: template title */
@@ -72,7 +84,7 @@ function usePageContentFocusCommands() {
72
84
  ),
73
85
  icon: layout,
74
86
  callback: ( { close } ) => {
75
- setRenderingMode( 'template-only' );
87
+ editTemplate();
76
88
  close();
77
89
  },
78
90
  } );
@@ -129,7 +141,7 @@ function useManipulateDocumentCommands() {
129
141
  const isEditingPage = useSelect(
130
142
  ( select ) =>
131
143
  select( editSiteStore ).isPage() &&
132
- select( editorStore ).getRenderingMode() !== 'template-only',
144
+ select( editorStore ).getCurrentPostType() !== 'wp_template',
133
145
  []
134
146
  );
135
147