@wordpress/edit-site 5.3.5 → 5.3.7

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 (196) hide show
  1. package/build/components/add-new-template/add-custom-template-modal.js +12 -3
  2. package/build/components/add-new-template/add-custom-template-modal.js.map +1 -1
  3. package/build/components/add-new-template/new-template-part.js +5 -1
  4. package/build/components/add-new-template/new-template-part.js.map +1 -1
  5. package/build/components/block-editor/editor-canvas.js +2 -1
  6. package/build/components/block-editor/editor-canvas.js.map +1 -1
  7. package/build/components/editor/index.js +3 -3
  8. package/build/components/editor/index.js.map +1 -1
  9. package/build/components/global-styles/screen-variations.js +1 -1
  10. package/build/components/global-styles/screen-variations.js.map +1 -1
  11. package/build/components/global-styles/shadow-panel.js +6 -4
  12. package/build/components/global-styles/shadow-panel.js.map +1 -1
  13. package/build/components/keyboard-shortcuts/edit-mode.js +124 -0
  14. package/build/components/keyboard-shortcuts/edit-mode.js.map +1 -0
  15. package/build/components/keyboard-shortcuts/global.js +48 -0
  16. package/build/components/keyboard-shortcuts/global.js.map +1 -0
  17. package/build/components/keyboard-shortcuts/register.js +153 -0
  18. package/build/components/keyboard-shortcuts/register.js.map +1 -0
  19. package/build/components/layout/index.js +11 -1
  20. package/build/components/layout/index.js.map +1 -1
  21. package/build/components/list/added-by.js +41 -42
  22. package/build/components/list/added-by.js.map +1 -1
  23. package/build/components/list/index.js +2 -1
  24. package/build/components/list/index.js.map +1 -1
  25. package/build/components/list/table.js +3 -1
  26. package/build/components/list/table.js.map +1 -1
  27. package/build/components/routes/link.js +4 -1
  28. package/build/components/routes/link.js.map +1 -1
  29. package/build/components/save-hub/index.js +82 -0
  30. package/build/components/save-hub/index.js.map +1 -0
  31. package/build/components/sidebar/index.js +14 -4
  32. package/build/components/sidebar/index.js.map +1 -1
  33. package/build/components/sidebar-button/index.js +30 -0
  34. package/build/components/sidebar-button/index.js.map +1 -0
  35. package/build/components/sidebar-navigation-screen/index.js +11 -5
  36. package/build/components/sidebar-navigation-screen/index.js.map +1 -1
  37. package/build/components/sidebar-navigation-screen-main/index.js +1 -0
  38. package/build/components/sidebar-navigation-screen-main/index.js.map +1 -1
  39. package/build/components/sidebar-navigation-screen-navigation-item/index.js +18 -18
  40. package/build/components/sidebar-navigation-screen-navigation-item/index.js.map +1 -1
  41. package/build/components/sidebar-navigation-screen-navigation-menus/index.js +139 -11
  42. package/build/components/sidebar-navigation-screen-navigation-menus/index.js.map +1 -1
  43. package/build/components/sidebar-navigation-screen-navigation-menus/loader.js +19 -0
  44. package/build/components/sidebar-navigation-screen-navigation-menus/loader.js.map +1 -0
  45. package/build/components/sidebar-navigation-screen-navigation-menus/navigation-menu-content.js +77 -0
  46. package/build/components/sidebar-navigation-screen-navigation-menus/navigation-menu-content.js.map +1 -0
  47. package/build/components/sidebar-navigation-screen-template/index.js +25 -8
  48. package/build/components/sidebar-navigation-screen-template/index.js.map +1 -1
  49. package/build/components/sidebar-navigation-screen-templates/index.js +22 -5
  50. package/build/components/sidebar-navigation-screen-templates/index.js.map +1 -1
  51. package/build/components/sidebar-navigation-screen-templates-browse/index.js +6 -3
  52. package/build/components/sidebar-navigation-screen-templates-browse/index.js.map +1 -1
  53. package/build/components/style-book/index.js +17 -2
  54. package/build/components/style-book/index.js.map +1 -1
  55. package/build/components/sync-state-with-url/use-init-edited-entity-from-url.js +7 -7
  56. package/build/components/sync-state-with-url/use-init-edited-entity-from-url.js.map +1 -1
  57. package/build/components/sync-state-with-url/use-sync-canvas-mode-with-url.js +24 -8
  58. package/build/components/sync-state-with-url/use-sync-canvas-mode-with-url.js.map +1 -1
  59. package/build/components/sync-state-with-url/use-sync-path-with-url.js +29 -29
  60. package/build/components/sync-state-with-url/use-sync-path-with-url.js.map +1 -1
  61. package/build/components/template-details/index.js +5 -10
  62. package/build/components/template-details/index.js.map +1 -1
  63. package/build/components/use-edited-entity-record/index.js +6 -6
  64. package/build/components/use-edited-entity-record/index.js.map +1 -1
  65. package/build/index.js +13 -22
  66. package/build/index.js.map +1 -1
  67. package/build/utils/history.js +8 -2
  68. package/build/utils/history.js.map +1 -1
  69. package/build-module/components/add-new-template/add-custom-template-modal.js +13 -4
  70. package/build-module/components/add-new-template/add-custom-template-modal.js.map +1 -1
  71. package/build-module/components/add-new-template/new-template-part.js +5 -1
  72. package/build-module/components/add-new-template/new-template-part.js.map +1 -1
  73. package/build-module/components/block-editor/editor-canvas.js +2 -1
  74. package/build-module/components/block-editor/editor-canvas.js.map +1 -1
  75. package/build-module/components/editor/index.js +3 -3
  76. package/build-module/components/editor/index.js.map +1 -1
  77. package/build-module/components/global-styles/screen-variations.js +1 -1
  78. package/build-module/components/global-styles/screen-variations.js.map +1 -1
  79. package/build-module/components/global-styles/shadow-panel.js +6 -4
  80. package/build-module/components/global-styles/shadow-panel.js.map +1 -1
  81. package/build-module/components/keyboard-shortcuts/edit-mode.js +108 -0
  82. package/build-module/components/keyboard-shortcuts/edit-mode.js.map +1 -0
  83. package/build-module/components/keyboard-shortcuts/global.js +37 -0
  84. package/build-module/components/keyboard-shortcuts/global.js.map +1 -0
  85. package/build-module/components/keyboard-shortcuts/register.js +141 -0
  86. package/build-module/components/keyboard-shortcuts/register.js.map +1 -0
  87. package/build-module/components/layout/index.js +9 -1
  88. package/build-module/components/layout/index.js.map +1 -1
  89. package/build-module/components/list/added-by.js +43 -44
  90. package/build-module/components/list/added-by.js.map +1 -1
  91. package/build-module/components/list/index.js +2 -1
  92. package/build-module/components/list/index.js.map +1 -1
  93. package/build-module/components/list/table.js +3 -1
  94. package/build-module/components/list/table.js.map +1 -1
  95. package/build-module/components/routes/link.js +5 -2
  96. package/build-module/components/routes/link.js.map +1 -1
  97. package/build-module/components/save-hub/index.js +68 -0
  98. package/build-module/components/save-hub/index.js.map +1 -0
  99. package/build-module/components/sidebar/index.js +10 -5
  100. package/build-module/components/sidebar/index.js.map +1 -1
  101. package/build-module/components/sidebar-button/index.js +18 -0
  102. package/build-module/components/sidebar-button/index.js.map +1 -0
  103. package/build-module/components/sidebar-navigation-screen/index.js +9 -6
  104. package/build-module/components/sidebar-navigation-screen/index.js.map +1 -1
  105. package/build-module/components/sidebar-navigation-screen-main/index.js +1 -0
  106. package/build-module/components/sidebar-navigation-screen-main/index.js.map +1 -1
  107. package/build-module/components/sidebar-navigation-screen-navigation-item/index.js +20 -22
  108. package/build-module/components/sidebar-navigation-screen-navigation-item/index.js.map +1 -1
  109. package/build-module/components/sidebar-navigation-screen-navigation-menus/index.js +131 -11
  110. package/build-module/components/sidebar-navigation-screen-navigation-menus/index.js.map +1 -1
  111. package/build-module/components/sidebar-navigation-screen-navigation-menus/loader.js +11 -0
  112. package/build-module/components/sidebar-navigation-screen-navigation-menus/loader.js.map +1 -0
  113. package/build-module/components/sidebar-navigation-screen-navigation-menus/navigation-menu-content.js +66 -0
  114. package/build-module/components/sidebar-navigation-screen-navigation-menus/navigation-menu-content.js.map +1 -0
  115. package/build-module/components/sidebar-navigation-screen-template/index.js +25 -10
  116. package/build-module/components/sidebar-navigation-screen-template/index.js.map +1 -1
  117. package/build-module/components/sidebar-navigation-screen-templates/index.js +19 -5
  118. package/build-module/components/sidebar-navigation-screen-templates/index.js.map +1 -1
  119. package/build-module/components/sidebar-navigation-screen-templates-browse/index.js +6 -3
  120. package/build-module/components/sidebar-navigation-screen-templates-browse/index.js.map +1 -1
  121. package/build-module/components/style-book/index.js +17 -3
  122. package/build-module/components/style-book/index.js.map +1 -1
  123. package/build-module/components/sync-state-with-url/use-init-edited-entity-from-url.js +7 -7
  124. package/build-module/components/sync-state-with-url/use-init-edited-entity-from-url.js.map +1 -1
  125. package/build-module/components/sync-state-with-url/use-sync-canvas-mode-with-url.js +24 -8
  126. package/build-module/components/sync-state-with-url/use-sync-canvas-mode-with-url.js.map +1 -1
  127. package/build-module/components/sync-state-with-url/use-sync-path-with-url.js +27 -29
  128. package/build-module/components/sync-state-with-url/use-sync-path-with-url.js.map +1 -1
  129. package/build-module/components/template-details/index.js +5 -9
  130. package/build-module/components/template-details/index.js.map +1 -1
  131. package/build-module/components/use-edited-entity-record/index.js +6 -6
  132. package/build-module/components/use-edited-entity-record/index.js.map +1 -1
  133. package/build-module/index.js +16 -23
  134. package/build-module/index.js.map +1 -1
  135. package/build-module/utils/history.js +9 -3
  136. package/build-module/utils/history.js.map +1 -1
  137. package/build-style/style-rtl.css +100 -94
  138. package/build-style/style.css +100 -94
  139. package/package.json +10 -10
  140. package/src/components/add-new-template/add-custom-template-modal.js +14 -10
  141. package/src/components/add-new-template/new-template-part.js +4 -3
  142. package/src/components/add-new-template/style.scss +0 -5
  143. package/src/components/block-editor/editor-canvas.js +2 -1
  144. package/src/components/block-editor/style.scss +1 -1
  145. package/src/components/editor/index.js +4 -3
  146. package/src/components/global-styles/screen-variations.js +0 -1
  147. package/src/components/global-styles/shadow-panel.js +4 -3
  148. package/src/components/keyboard-shortcuts/edit-mode.js +116 -0
  149. package/src/components/keyboard-shortcuts/global.js +35 -0
  150. package/src/components/keyboard-shortcuts/register.js +157 -0
  151. package/src/components/layout/index.js +18 -0
  152. package/src/components/layout/style.scss +1 -3
  153. package/src/components/list/added-by.js +48 -55
  154. package/src/components/list/index.js +3 -1
  155. package/src/components/list/style.scss +5 -13
  156. package/src/components/list/table.js +4 -1
  157. package/src/components/routes/link.js +9 -2
  158. package/src/components/save-hub/index.js +78 -0
  159. package/src/components/save-hub/style.scss +15 -0
  160. package/src/components/sidebar/index.js +11 -6
  161. package/src/components/sidebar/style.scss +4 -3
  162. package/src/components/sidebar-button/index.js +21 -0
  163. package/src/components/sidebar-button/style.scss +24 -0
  164. package/src/components/sidebar-navigation-item/style.scss +0 -20
  165. package/src/components/sidebar-navigation-screen/index.js +9 -4
  166. package/src/components/sidebar-navigation-screen/style.scss +16 -10
  167. package/src/components/sidebar-navigation-screen-main/index.js +3 -0
  168. package/src/components/sidebar-navigation-screen-navigation-item/index.js +33 -26
  169. package/src/components/sidebar-navigation-screen-navigation-menus/index.js +141 -10
  170. package/src/components/sidebar-navigation-screen-navigation-menus/loader.js +9 -0
  171. package/src/components/sidebar-navigation-screen-navigation-menus/navigation-menu-content.js +78 -0
  172. package/src/components/sidebar-navigation-screen-navigation-menus/style.scss +55 -4
  173. package/src/components/sidebar-navigation-screen-template/index.js +27 -13
  174. package/src/components/sidebar-navigation-screen-templates/index.js +23 -4
  175. package/src/components/sidebar-navigation-screen-templates/style.scss +0 -5
  176. package/src/components/sidebar-navigation-screen-templates-browse/index.js +12 -1
  177. package/src/components/style-book/index.js +25 -1
  178. package/src/components/sync-state-with-url/use-init-edited-entity-from-url.js +5 -9
  179. package/src/components/sync-state-with-url/use-sync-canvas-mode-with-url.js +38 -8
  180. package/src/components/sync-state-with-url/use-sync-path-with-url.js +34 -35
  181. package/src/components/template-details/index.js +4 -8
  182. package/src/components/use-edited-entity-record/index.js +26 -18
  183. package/src/index.js +11 -22
  184. package/src/style.scss +2 -1
  185. package/src/utils/history.js +13 -9
  186. package/build/components/navigation-inspector/index.js +0 -190
  187. package/build/components/navigation-inspector/index.js.map +0 -1
  188. package/build/components/navigation-inspector/navigation-menu.js +0 -62
  189. package/build/components/navigation-inspector/navigation-menu.js.map +0 -1
  190. package/build-module/components/navigation-inspector/index.js +0 -173
  191. package/build-module/components/navigation-inspector/index.js.map +0 -1
  192. package/build-module/components/navigation-inspector/navigation-menu.js +0 -52
  193. package/build-module/components/navigation-inspector/navigation-menu.js.map +0 -1
  194. package/src/components/navigation-inspector/index.js +0 -223
  195. package/src/components/navigation-inspector/navigation-menu.js +0 -66
  196. package/src/components/navigation-inspector/style.scss +0 -46
@@ -8,6 +8,7 @@ import {
8
8
  } from '@wordpress/components';
9
9
  import { __ } from '@wordpress/i18n';
10
10
  import { useEntityRecords } from '@wordpress/core-data';
11
+ import { useSelect } from '@wordpress/data';
11
12
  import { decodeEntities } from '@wordpress/html-entities';
12
13
  import { useViewportMatch } from '@wordpress/compose';
13
14
 
@@ -18,6 +19,8 @@ import SidebarNavigationScreen from '../sidebar-navigation-screen';
18
19
  import { useLink } from '../routes/link';
19
20
  import SidebarNavigationItem from '../sidebar-navigation-item';
20
21
  import AddNewTemplate from '../add-new-template';
22
+ import { store as editSiteStore } from '../../store';
23
+ import SidebarButton from '../sidebar-button';
21
24
 
22
25
  const config = {
23
26
  wp_template: {
@@ -26,6 +29,9 @@ const config = {
26
29
  loading: __( 'Loading templates' ),
27
30
  notFound: __( 'No templates found' ),
28
31
  manage: __( 'Manage all templates' ),
32
+ description: __(
33
+ 'Express the layout of your site with templates.'
34
+ ),
29
35
  },
30
36
  },
31
37
  wp_template_part: {
@@ -34,6 +40,9 @@ const config = {
34
40
  loading: __( 'Loading template parts' ),
35
41
  notFound: __( 'No template parts found' ),
36
42
  manage: __( 'Manage all template parts' ),
43
+ description: __(
44
+ 'Template Parts are small pieces of a layout that can be reused across multiple templates and always appear the same way. Common template parts include the site header, footer, or sidebar.'
45
+ ),
37
46
  },
38
47
  },
39
48
  };
@@ -51,6 +60,11 @@ export default function SidebarNavigationScreenTemplates() {
51
60
  params: { postType },
52
61
  } = useNavigator();
53
62
  const isMobileViewport = useViewportMatch( 'medium', '<' );
63
+ const isTemplatePartsMode = useSelect( ( select ) => {
64
+ const settings = select( editSiteStore ).getSettings();
65
+
66
+ return !! settings.supportsTemplatePartsMode;
67
+ }, [] );
54
68
 
55
69
  const { records: templates, isResolving: isLoading } = useEntityRecords(
56
70
  'postType',
@@ -59,21 +73,26 @@ export default function SidebarNavigationScreenTemplates() {
59
73
  per_page: -1,
60
74
  }
61
75
  );
76
+ const sortedTemplates = templates ? [ ...templates ] : [];
77
+ sortedTemplates.sort( ( a, b ) => a.slug.localeCompare( b.slug ) );
62
78
 
63
79
  const browseAllLink = useLink( {
64
80
  path: '/' + postType + '/all',
65
81
  } );
66
82
 
83
+ const canCreate = ! isMobileViewport && ! isTemplatePartsMode;
84
+
67
85
  return (
68
86
  <SidebarNavigationScreen
87
+ isRoot={ isTemplatePartsMode }
69
88
  title={ config[ postType ].labels.title }
89
+ description={ config[ postType ].labels.description }
70
90
  actions={
71
- ! isMobileViewport && (
91
+ canCreate && (
72
92
  <AddNewTemplate
73
93
  templateType={ postType }
74
94
  toggleProps={ {
75
- className:
76
- 'edit-site-sidebar-navigation-screen-templates__add-button',
95
+ as: SidebarButton,
77
96
  } }
78
97
  />
79
98
  )
@@ -88,7 +107,7 @@ export default function SidebarNavigationScreenTemplates() {
88
107
  { config[ postType ].labels.notFound }
89
108
  </Item>
90
109
  ) }
91
- { ( templates ?? [] ).map( ( template ) => (
110
+ { sortedTemplates.map( ( template ) => (
92
111
  <TemplateItem
93
112
  postType={ postType }
94
113
  postId={ template.id }
@@ -2,8 +2,3 @@
2
2
  /* Overrides the margin that comes from the Item component */
3
3
  margin-top: $grid-unit-20 !important;
4
4
  }
5
-
6
- .edit-site-sidebar-navigation-screen-templates__add-button {
7
- /* Overrides the color for all states of the button */
8
- color: inherit !important;
9
- }
@@ -12,9 +12,15 @@ import SidebarNavigationScreen from '../sidebar-navigation-screen';
12
12
  const config = {
13
13
  wp_template: {
14
14
  title: __( 'All templates' ),
15
+ description: __(
16
+ 'Create new templates, or reset any customizations made to the templates supplied by your theme.'
17
+ ),
15
18
  },
16
19
  wp_template_part: {
17
20
  title: __( 'All template parts' ),
21
+ description: __(
22
+ 'Create new template parts, or reset any customisations made to the template parts supplied by your theme.'
23
+ ),
18
24
  },
19
25
  };
20
26
 
@@ -22,5 +28,10 @@ export default function SidebarNavigationScreenTemplatesBrowse() {
22
28
  const {
23
29
  params: { postType },
24
30
  } = useNavigator();
25
- return <SidebarNavigationScreen title={ config[ postType ].title } />;
31
+ return (
32
+ <SidebarNavigationScreen
33
+ title={ config[ postType ].title }
34
+ description={ config[ postType ].description }
35
+ />
36
+ );
26
37
  }
@@ -24,8 +24,14 @@ import {
24
24
  privateApis as blockEditorPrivateApis,
25
25
  } from '@wordpress/block-editor';
26
26
  import { closeSmall } from '@wordpress/icons';
27
- import { useResizeObserver } from '@wordpress/compose';
27
+ import {
28
+ useResizeObserver,
29
+ useFocusOnMount,
30
+ useFocusReturn,
31
+ useMergeRefs,
32
+ } from '@wordpress/compose';
28
33
  import { useMemo, memo } from '@wordpress/element';
34
+ import { ESCAPE } from '@wordpress/keycodes';
29
35
 
30
36
  /**
31
37
  * Internal dependencies
@@ -90,6 +96,9 @@ function getExamples() {
90
96
 
91
97
  function StyleBook( { isSelected, onSelect, onClose } ) {
92
98
  const [ resizeObserver, sizes ] = useResizeObserver();
99
+ const focusOnMountRef = useFocusOnMount( 'firstElement' );
100
+ const sectionFocusReturnRef = useFocusReturn();
101
+
93
102
  const [ textColor ] = useGlobalStyle( 'color.text' );
94
103
  const [ backgroundColor ] = useGlobalStyle( 'color.background' );
95
104
  const examples = useMemo( getExamples, [] );
@@ -108,8 +117,17 @@ function StyleBook( { isSelected, onSelect, onClose } ) {
108
117
  } ) ),
109
118
  [ examples ]
110
119
  );
120
+
121
+ function closeOnEscape( event ) {
122
+ if ( event.keyCode === ESCAPE && ! event.defaultPrevented ) {
123
+ event.preventDefault();
124
+ onClose();
125
+ }
126
+ }
127
+
111
128
  return (
112
129
  <StyleBookFill>
130
+ { /* eslint-disable-next-line jsx-a11y/no-noninteractive-element-interactions */ }
113
131
  <section
114
132
  className={ classnames( 'edit-site-style-book', {
115
133
  'is-wide': sizes.width > 600,
@@ -119,6 +137,11 @@ function StyleBook( { isSelected, onSelect, onClose } ) {
119
137
  background: backgroundColor,
120
138
  } }
121
139
  aria-label={ __( 'Style Book' ) }
140
+ onKeyDown={ closeOnEscape }
141
+ ref={ useMergeRefs( [
142
+ sectionFocusReturnRef,
143
+ focusOnMountRef,
144
+ ] ) }
122
145
  >
123
146
  { resizeObserver }
124
147
  <Button
@@ -126,6 +149,7 @@ function StyleBook( { isSelected, onSelect, onClose } ) {
126
149
  icon={ closeSmall }
127
150
  label={ __( 'Close Style Book' ) }
128
151
  onClick={ onClose }
152
+ showTooltip={ false }
129
153
  />
130
154
  <TabPanel
131
155
  className="edit-site-style-book__tab-panel"
@@ -13,7 +13,7 @@ import { store as editSiteStore } from '../../store';
13
13
 
14
14
  export default function useInitEditedEntityFromURL() {
15
15
  const { params: { postId, postType } = {} } = useLocation();
16
- const { isRequestingSite, homepageId } = useSelect( ( select ) => {
16
+ const { isRequestingSite, homepageId, url } = useSelect( ( select ) => {
17
17
  const { getSite } = select( coreDataStore );
18
18
  const siteData = getSite();
19
19
 
@@ -23,6 +23,7 @@ export default function useInitEditedEntityFromURL() {
23
23
  siteData?.show_on_front === 'page'
24
24
  ? siteData.page_on_front
25
25
  : null,
26
+ url: siteData?.url,
26
27
  };
27
28
  }, [] );
28
29
 
@@ -30,13 +31,7 @@ export default function useInitEditedEntityFromURL() {
30
31
  useDispatch( editSiteStore );
31
32
 
32
33
  useEffect( () => {
33
- if (
34
- postType &&
35
- postId &&
36
- // This is just a special case to support old WP versions that perform redirects.
37
- // This code should be removed when we minimum WP version becomes 6.2.
38
- postId !== 'none'
39
- ) {
34
+ if ( postType && postId ) {
40
35
  switch ( postType ) {
41
36
  case 'wp_template':
42
37
  setTemplate( postId );
@@ -60,10 +55,11 @@ export default function useInitEditedEntityFromURL() {
60
55
  } );
61
56
  } else if ( ! isRequestingSite ) {
62
57
  setPage( {
63
- path: '/',
58
+ path: url,
64
59
  } );
65
60
  }
66
61
  }, [
62
+ url,
67
63
  postId,
68
64
  postType,
69
65
  homepageId,
@@ -20,22 +20,52 @@ export default function useSyncCanvasModeWithURL() {
20
20
  );
21
21
  const { setCanvasMode } = unlock( useDispatch( editSiteStore ) );
22
22
  const currentCanvasMode = useRef( canvasMode );
23
- const { canvas: canvasInUrl = 'view' } = params;
23
+ const { canvas: canvasInUrl } = params;
24
24
  const currentCanvasInUrl = useRef( canvasInUrl );
25
+ const currentUrlParams = useRef( params );
26
+ useEffect( () => {
27
+ currentUrlParams.current = params;
28
+ }, [ params ] );
29
+
25
30
  useEffect( () => {
26
31
  currentCanvasMode.current = canvasMode;
27
- if ( currentCanvasMode !== currentCanvasInUrl ) {
32
+ if ( canvasMode === 'init' ) {
33
+ return;
34
+ }
35
+
36
+ if (
37
+ canvasMode === 'edit' &&
38
+ currentCanvasInUrl.current !== canvasMode
39
+ ) {
40
+ history.push( {
41
+ ...currentUrlParams.current,
42
+ canvas: 'edit',
43
+ } );
44
+ }
45
+
46
+ if (
47
+ canvasMode === 'view' &&
48
+ currentCanvasInUrl.current !== undefined
49
+ ) {
28
50
  history.push( {
29
- ...params,
30
- canvas: canvasMode,
51
+ ...currentUrlParams.current,
52
+ canvas: undefined,
31
53
  } );
32
54
  }
33
- }, [ canvasMode ] );
55
+ }, [ canvasMode, history ] );
34
56
 
35
57
  useEffect( () => {
36
58
  currentCanvasInUrl.current = canvasInUrl;
37
- if ( canvasInUrl !== currentCanvasMode.current ) {
38
- setCanvasMode( canvasInUrl );
59
+ if (
60
+ canvasInUrl === undefined &&
61
+ currentCanvasMode.current !== 'view'
62
+ ) {
63
+ setCanvasMode( 'view' );
64
+ } else if (
65
+ canvasInUrl === 'edit' &&
66
+ currentCanvasMode.current !== 'edit'
67
+ ) {
68
+ setCanvasMode( 'edit' );
39
69
  }
40
- }, [ canvasInUrl ] );
70
+ }, [ canvasInUrl, setCanvasMode ] );
41
71
  }
@@ -9,6 +9,28 @@ import { useEffect, useRef } from '@wordpress/element';
9
9
  */
10
10
  import { useLocation, useHistory } from '../routes';
11
11
 
12
+ export function getPathFromURL( urlParams ) {
13
+ let path = urlParams?.path ?? '/';
14
+
15
+ // Compute the navigator path based on the URL params.
16
+ if ( urlParams?.postType && urlParams?.postId ) {
17
+ switch ( urlParams.postType ) {
18
+ case 'wp_template':
19
+ case 'wp_template_part':
20
+ path = `/${ encodeURIComponent(
21
+ urlParams.postType
22
+ ) }/${ encodeURIComponent( urlParams.postId ) }`;
23
+ break;
24
+ default:
25
+ path = `/navigation/${ encodeURIComponent(
26
+ urlParams.postType
27
+ ) }/${ encodeURIComponent( urlParams.postId ) }`;
28
+ }
29
+ }
30
+
31
+ return path;
32
+ }
33
+
12
34
  export default function useSyncPathWithURL() {
13
35
  const history = useHistory();
14
36
  const { params: urlParams } = useLocation();
@@ -18,13 +40,17 @@ export default function useSyncPathWithURL() {
18
40
  goTo,
19
41
  } = useNavigator();
20
42
  const currentUrlParams = useRef( urlParams );
21
- const currentPath = useRef();
43
+ const currentPath = useRef( navigatorLocation.path );
44
+ const isMounting = useRef( true );
22
45
 
23
46
  useEffect( () => {
24
- // Don't trust the navigator path on initial render.
25
- if ( currentPath.current === null ) {
47
+ // The navigatorParams are only initially filled properly when the
48
+ // navigator screens mount. so we ignore the first synchronisation.
49
+ if ( isMounting.current ) {
50
+ isMounting.current = false;
26
51
  return;
27
52
  }
53
+
28
54
  function updateUrlParams( newUrlParams ) {
29
55
  if (
30
56
  Object.entries( newUrlParams ).every( ( [ key, value ] ) => {
@@ -47,51 +73,24 @@ export default function useSyncPathWithURL() {
47
73
  postId: navigatorParams?.postId,
48
74
  path: undefined,
49
75
  } );
50
- } else if ( navigatorParams?.postType && ! navigatorParams?.postId ) {
51
- updateUrlParams( {
52
- postType: navigatorParams?.postType,
53
- path: navigatorLocation.path,
54
- postId: undefined,
55
- } );
56
76
  } else {
57
77
  updateUrlParams( {
58
78
  postType: undefined,
59
79
  postId: undefined,
60
- path: navigatorLocation.path,
80
+ path:
81
+ navigatorLocation.path === '/'
82
+ ? undefined
83
+ : navigatorLocation.path,
61
84
  } );
62
85
  }
63
86
  }, [ navigatorLocation?.path, navigatorParams, history ] );
64
87
 
65
88
  useEffect( () => {
66
89
  currentUrlParams.current = urlParams;
67
- let path = urlParams?.path ?? '/';
68
-
69
- // Compute the navigator path based on the URL params.
70
- if (
71
- urlParams?.postType &&
72
- urlParams?.postId &&
73
- // This is just a special case to support old WP versions that perform redirects.
74
- // This code should be removed when we minimum WP version becomes 6.2.
75
- urlParams?.postId !== 'none'
76
- ) {
77
- switch ( urlParams.postType ) {
78
- case 'wp_template':
79
- case 'wp_template_part':
80
- path = `/${ encodeURIComponent(
81
- urlParams.postType
82
- ) }/${ encodeURIComponent( urlParams.postId ) }`;
83
- break;
84
- default:
85
- path = `/navigation/${ encodeURIComponent(
86
- urlParams.postType
87
- ) }/${ encodeURIComponent( urlParams.postId ) }`;
88
- }
89
- }
90
-
90
+ const path = getPathFromURL( urlParams );
91
91
  if ( currentPath.current !== path ) {
92
92
  currentPath.current = path;
93
93
  goTo( path );
94
94
  }
95
- goTo( path );
96
95
  }, [ urlParams, goTo ] );
97
96
  }
@@ -18,7 +18,6 @@ import { decodeEntities } from '@wordpress/html-entities';
18
18
  */
19
19
  import isTemplateRevertable from '../../utils/is-template-revertable';
20
20
  import { store as editSiteStore } from '../../store';
21
- import TemplateAreas from './template-areas';
22
21
  import EditTemplateTitle from './edit-template-title';
23
22
  import { useLink } from '../routes/link';
24
23
  import TemplatePartAreaSelector from './template-part-area-selector';
@@ -31,10 +30,9 @@ export default function TemplateDetails( { template, onClose } ) {
31
30
  );
32
31
  const { revertTemplate } = useDispatch( editSiteStore );
33
32
 
33
+ // TODO: We should update this to filter by template part's areas as well.
34
34
  const browseAllLinkProps = useLink( {
35
- // TODO: We should update this to filter by template part's areas as well.
36
- postType: template.type,
37
- postId: undefined,
35
+ path: '/' + template.type + '/all',
38
36
  } );
39
37
 
40
38
  const isTemplatePart = template.type === 'wp_template_part';
@@ -87,8 +85,6 @@ export default function TemplateDetails( { template, onClose } ) {
87
85
  </div>
88
86
  ) }
89
87
 
90
- <TemplateAreas closeTemplateDetailsDropdown={ onClose } />
91
-
92
88
  { isTemplateRevertable( template ) && (
93
89
  <MenuGroup className="edit-site-template-details__group edit-site-template-details__revert">
94
90
  <MenuItem
@@ -108,8 +104,8 @@ export default function TemplateDetails( { template, onClose } ) {
108
104
  { ...browseAllLinkProps }
109
105
  >
110
106
  { template?.type === 'wp_template'
111
- ? __( 'Browse all templates' )
112
- : __( 'Browse all template parts' ) }
107
+ ? __( 'Manage all templates' )
108
+ : __( 'Manage all template parts' ) }
113
109
  </Button>
114
110
  </div>
115
111
  );
@@ -11,25 +11,33 @@ import { decodeEntities } from '@wordpress/html-entities';
11
11
  */
12
12
  import { store as editSiteStore } from '../../store';
13
13
 
14
- export default function useEditedEntityRecord() {
15
- const { record, title, description, isLoaded } = useSelect( ( select ) => {
16
- const { getEditedPostType, getEditedPostId } = select( editSiteStore );
17
- const { getEditedEntityRecord } = select( coreStore );
18
- const { __experimentalGetTemplateInfo: getTemplateInfo } =
19
- select( editorStore );
20
- const postType = getEditedPostType();
21
- const postId = getEditedPostId();
22
- const _record = getEditedEntityRecord( 'postType', postType, postId );
23
- const _isLoaded = !! postId;
24
- const templateInfo = getTemplateInfo( _record );
14
+ export default function useEditedEntityRecord( postType, postId ) {
15
+ const { record, title, description, isLoaded } = useSelect(
16
+ ( select ) => {
17
+ const { getEditedPostType, getEditedPostId } =
18
+ select( editSiteStore );
19
+ const { getEditedEntityRecord } = select( coreStore );
20
+ const { __experimentalGetTemplateInfo: getTemplateInfo } =
21
+ select( editorStore );
22
+ const usedPostType = postType ?? getEditedPostType();
23
+ const usedPostId = postId ?? getEditedPostId();
24
+ const _record = getEditedEntityRecord(
25
+ 'postType',
26
+ usedPostType,
27
+ usedPostId
28
+ );
29
+ const _isLoaded = !! usedPostId;
30
+ const templateInfo = getTemplateInfo( _record );
25
31
 
26
- return {
27
- record: _record,
28
- title: templateInfo.title,
29
- description: templateInfo.description,
30
- isLoaded: _isLoaded,
31
- };
32
- }, [] );
32
+ return {
33
+ record: _record,
34
+ title: templateInfo.title,
35
+ description: templateInfo.description,
36
+ isLoaded: _isLoaded,
37
+ };
38
+ },
39
+ [ postType, postId ]
40
+ );
33
41
 
34
42
  return {
35
43
  isLoaded,
package/src/index.js CHANGED
@@ -4,6 +4,7 @@
4
4
  import { store as blocksStore } from '@wordpress/blocks';
5
5
  import {
6
6
  registerCoreBlocks,
7
+ __experimentalGetCoreBlocks,
7
8
  __experimentalRegisterExperimentalCoreBlocks,
8
9
  } from '@wordpress/block-library';
9
10
  import { dispatch } from '@wordpress/data';
@@ -16,8 +17,10 @@ import {
16
17
  import { store as editorStore } from '@wordpress/editor';
17
18
  import { store as interfaceStore } from '@wordpress/interface';
18
19
  import { store as preferencesStore } from '@wordpress/preferences';
19
- import { addFilter } from '@wordpress/hooks';
20
- import { registerLegacyWidgetBlock } from '@wordpress/widgets';
20
+ import {
21
+ registerLegacyWidgetBlock,
22
+ registerWidgetGroupBlock,
23
+ } from '@wordpress/widgets';
21
24
 
22
25
  /**
23
26
  * Internal dependencies
@@ -41,32 +44,18 @@ export function initializeEditor( id, settings ) {
41
44
  settings.__experimentalFetchRichUrlData = fetchUrlData;
42
45
 
43
46
  dispatch( blocksStore ).__experimentalReapplyBlockTypeFilters();
44
- registerCoreBlocks();
47
+ const coreBlocks = __experimentalGetCoreBlocks().filter(
48
+ ( { name } ) => name !== 'core/freeform'
49
+ );
50
+ registerCoreBlocks( coreBlocks );
51
+ dispatch( blocksStore ).setFreeformFallbackBlockName( 'core/html' );
45
52
  registerLegacyWidgetBlock( { inserter: false } );
53
+ registerWidgetGroupBlock( { inserter: false } );
46
54
  if ( process.env.IS_GUTENBERG_PLUGIN ) {
47
55
  __experimentalRegisterExperimentalCoreBlocks( {
48
56
  enableFSEBlocks: true,
49
57
  } );
50
58
  }
51
- /*
52
- * Prevent adding the Clasic block in the site editor.
53
- * Only add the filter when the site editor is initialized, not imported.
54
- * Also only add the filter(s) after registerCoreBlocks()
55
- * so that common filters in the block library are not overwritten.
56
- *
57
- * This usage here is inspired by previous usage of the filter in the post editor:
58
- * https://github.com/WordPress/gutenberg/pull/37157
59
- */
60
- addFilter(
61
- 'blockEditor.__unstableCanInsertBlockType',
62
- 'removeClassicBlockFromInserter',
63
- ( canInsert, blockType ) => {
64
- if ( blockType.name === 'core/freeform' ) {
65
- return false;
66
- }
67
- return canInsert;
68
- }
69
- );
70
59
 
71
60
  // We dispatch actions and update the store synchronously before rendering
72
61
  // so that we won't trigger unnecessary re-renders with useEffect.
package/src/style.scss CHANGED
@@ -8,7 +8,6 @@
8
8
  @import "./components/header-edit-mode/style.scss";
9
9
  @import "./components/header-edit-mode/document-actions/style.scss";
10
10
  @import "./components/list/style.scss";
11
- @import "./components/navigation-inspector/style.scss";
12
11
  @import "./components/sidebar-edit-mode/style.scss";
13
12
  @import "./components/sidebar-edit-mode/settings-header/style.scss";
14
13
  @import "./components/sidebar-edit-mode/template-card/style.scss";
@@ -19,8 +18,10 @@
19
18
  @import "./components/welcome-guide/style.scss";
20
19
  @import "./components/keyboard-shortcut-help-modal/style.scss";
21
20
  @import "./components/layout/style.scss";
21
+ @import "./components/save-hub/style.scss";
22
22
  @import "./components/save-panel/style.scss";
23
23
  @import "./components/sidebar/style.scss";
24
+ @import "./components/sidebar-button/style.scss";
24
25
  @import "./components/sidebar-navigation-item/style.scss";
25
26
  @import "./components/sidebar-navigation-screen/style.scss";
26
27
  @import "./components/sidebar-navigation-screen-templates/style.scss";
@@ -6,7 +6,7 @@ import { createBrowserHistory } from 'history';
6
6
  /**
7
7
  * WordPress dependencies
8
8
  */
9
- import { addQueryArgs } from '@wordpress/url';
9
+ import { addQueryArgs, getQueryArgs, removeQueryArgs } from '@wordpress/url';
10
10
 
11
11
  const history = createBrowserHistory();
12
12
 
@@ -14,19 +14,23 @@ const originalHistoryPush = history.push;
14
14
  const originalHistoryReplace = history.replace;
15
15
 
16
16
  function push( params, state ) {
17
- return originalHistoryPush.call(
18
- history,
19
- addQueryArgs( window.location.href, params ),
20
- state
17
+ const currentArgs = getQueryArgs( window.location.href );
18
+ const currentUrlWithoutArgs = removeQueryArgs(
19
+ window.location.href,
20
+ ...Object.keys( currentArgs )
21
21
  );
22
+ const newUrl = addQueryArgs( currentUrlWithoutArgs, params );
23
+ return originalHistoryPush.call( history, newUrl, state );
22
24
  }
23
25
 
24
26
  function replace( params, state ) {
25
- return originalHistoryReplace.call(
26
- history,
27
- addQueryArgs( window.location.href, params ),
28
- state
27
+ const currentArgs = getQueryArgs( window.location.href );
28
+ const currentUrlWithoutArgs = removeQueryArgs(
29
+ window.location.href,
30
+ ...Object.keys( currentArgs )
29
31
  );
32
+ const newUrl = addQueryArgs( currentUrlWithoutArgs, params );
33
+ return originalHistoryReplace.call( history, newUrl, state );
30
34
  }
31
35
 
32
36
  history.push = push;