@wordpress/edit-site 3.0.12 → 3.0.16

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 (217) hide show
  1. package/build/components/add-new-template/new-template-part.js +29 -18
  2. package/build/components/add-new-template/new-template-part.js.map +1 -1
  3. package/build/components/add-new-template/new-template.js +30 -23
  4. package/build/components/add-new-template/new-template.js.map +1 -1
  5. package/build/components/app/index.js +51 -0
  6. package/build/components/app/index.js.map +1 -0
  7. package/build/components/block-editor/back-button.js +8 -20
  8. package/build/components/block-editor/back-button.js.map +1 -1
  9. package/build/components/block-editor/index.js +2 -1
  10. package/build/components/block-editor/index.js.map +1 -1
  11. package/build/components/create-template-part-modal/index.js +0 -2
  12. package/build/components/create-template-part-modal/index.js.map +1 -1
  13. package/build/components/edit-template-part-menu-button/index.js +20 -8
  14. package/build/components/edit-template-part-menu-button/index.js.map +1 -1
  15. package/build/components/editor/index.js +11 -30
  16. package/build/components/editor/index.js.map +1 -1
  17. package/build/components/global-styles/gradients-palette-panel.js +16 -1
  18. package/build/components/global-styles/gradients-palette-panel.js.map +1 -1
  19. package/build/components/global-styles/screen-background-color.js +2 -1
  20. package/build/components/global-styles/screen-background-color.js.map +1 -1
  21. package/build/components/global-styles/screen-link-color.js +2 -1
  22. package/build/components/global-styles/screen-link-color.js.map +1 -1
  23. package/build/components/global-styles/screen-text-color.js +2 -1
  24. package/build/components/global-styles/screen-text-color.js.map +1 -1
  25. package/build/components/global-styles/use-global-styles-output.js +1 -2
  26. package/build/components/global-styles/use-global-styles-output.js.map +1 -1
  27. package/build/components/header/document-actions/index.js +3 -6
  28. package/build/components/header/document-actions/index.js.map +1 -1
  29. package/build/components/list/actions/index.js +1 -1
  30. package/build/components/list/actions/index.js.map +1 -1
  31. package/build/components/list/index.js +17 -15
  32. package/build/components/list/index.js.map +1 -1
  33. package/build/components/list/table.js +31 -27
  34. package/build/components/list/table.js.map +1 -1
  35. package/build/components/navigation-sidebar/index.js +12 -13
  36. package/build/components/navigation-sidebar/index.js.map +1 -1
  37. package/build/components/navigation-sidebar/navigation-panel/index.js +26 -24
  38. package/build/components/navigation-sidebar/navigation-panel/index.js.map +1 -1
  39. package/build/components/routes/index.js +60 -0
  40. package/build/components/routes/index.js.map +1 -0
  41. package/build/components/routes/link.js +65 -0
  42. package/build/components/routes/link.js.map +1 -0
  43. package/build/components/routes/use-title.js +57 -0
  44. package/build/components/routes/use-title.js.map +1 -0
  45. package/build/components/sidebar/global-styles-sidebar.js +10 -0
  46. package/build/components/sidebar/global-styles-sidebar.js.map +1 -1
  47. package/build/components/sidebar/template-card/template-areas.js +7 -4
  48. package/build/components/sidebar/template-card/template-areas.js.map +1 -1
  49. package/build/components/template-details/edit-template-title.js +33 -0
  50. package/build/components/template-details/edit-template-title.js.map +1 -0
  51. package/build/components/template-details/index.js +18 -12
  52. package/build/components/template-details/index.js.map +1 -1
  53. package/build/components/template-details/template-areas.js +28 -11
  54. package/build/components/template-details/template-areas.js.map +1 -1
  55. package/build/components/template-part-converter/convert-to-template-part.js +7 -12
  56. package/build/components/template-part-converter/convert-to-template-part.js.map +1 -1
  57. package/build/components/url-query-controller/index.js +41 -50
  58. package/build/components/url-query-controller/index.js.map +1 -1
  59. package/build/components/welcome-guide/editor.js +6 -0
  60. package/build/components/welcome-guide/editor.js.map +1 -1
  61. package/build/components/welcome-guide/index.js +1 -28
  62. package/build/components/welcome-guide/index.js.map +1 -1
  63. package/build/components/welcome-guide/styles.js +18 -1
  64. package/build/components/welcome-guide/styles.js.map +1 -1
  65. package/build/index.js +29 -35
  66. package/build/index.js.map +1 -1
  67. package/build/plugins/index.js +3 -23
  68. package/build/plugins/index.js.map +1 -1
  69. package/build/plugins/site-export.js +61 -0
  70. package/build/plugins/site-export.js.map +1 -0
  71. package/build/plugins/welcome-guide-menu-item.js +1 -7
  72. package/build/plugins/welcome-guide-menu-item.js.map +1 -1
  73. package/build/store/actions.js +0 -27
  74. package/build/store/actions.js.map +1 -1
  75. package/build/store/constants.js +1 -14
  76. package/build/store/constants.js.map +1 -1
  77. package/build/store/reducer.js +7 -16
  78. package/build/store/reducer.js.map +1 -1
  79. package/build/store/selectors.js +1 -31
  80. package/build/store/selectors.js.map +1 -1
  81. package/build/utils/get-is-list-page.js +23 -0
  82. package/build/utils/get-is-list-page.js.map +1 -0
  83. package/build/utils/history.js +35 -0
  84. package/build/utils/history.js.map +1 -0
  85. package/build-module/components/add-new-template/new-template-part.js +27 -16
  86. package/build-module/components/add-new-template/new-template-part.js.map +1 -1
  87. package/build-module/components/add-new-template/new-template.js +28 -18
  88. package/build-module/components/add-new-template/new-template.js.map +1 -1
  89. package/build-module/components/app/index.js +35 -0
  90. package/build-module/components/app/index.js.map +1 -0
  91. package/build-module/components/block-editor/back-button.js +8 -19
  92. package/build-module/components/block-editor/back-button.js.map +1 -1
  93. package/build-module/components/block-editor/index.js +2 -1
  94. package/build-module/components/block-editor/index.js.map +1 -1
  95. package/build-module/components/create-template-part-modal/index.js +0 -2
  96. package/build-module/components/create-template-part-modal/index.js.map +1 -1
  97. package/build-module/components/edit-template-part-menu-button/index.js +17 -9
  98. package/build-module/components/edit-template-part-menu-button/index.js.map +1 -1
  99. package/build-module/components/editor/index.js +13 -33
  100. package/build-module/components/editor/index.js.map +1 -1
  101. package/build-module/components/global-styles/gradients-palette-panel.js +16 -2
  102. package/build-module/components/global-styles/gradients-palette-panel.js.map +1 -1
  103. package/build-module/components/global-styles/screen-background-color.js +2 -1
  104. package/build-module/components/global-styles/screen-background-color.js.map +1 -1
  105. package/build-module/components/global-styles/screen-link-color.js +2 -1
  106. package/build-module/components/global-styles/screen-link-color.js.map +1 -1
  107. package/build-module/components/global-styles/screen-text-color.js +2 -1
  108. package/build-module/components/global-styles/screen-text-color.js.map +1 -1
  109. package/build-module/components/global-styles/use-global-styles-output.js +1 -2
  110. package/build-module/components/global-styles/use-global-styles-output.js.map +1 -1
  111. package/build-module/components/header/document-actions/index.js +3 -6
  112. package/build-module/components/header/document-actions/index.js.map +1 -1
  113. package/build-module/components/list/actions/index.js +1 -1
  114. package/build-module/components/list/actions/index.js.map +1 -1
  115. package/build-module/components/list/index.js +15 -15
  116. package/build-module/components/list/index.js.map +1 -1
  117. package/build-module/components/list/table.js +31 -27
  118. package/build-module/components/list/table.js.map +1 -1
  119. package/build-module/components/navigation-sidebar/index.js +13 -13
  120. package/build-module/components/navigation-sidebar/index.js.map +1 -1
  121. package/build-module/components/navigation-sidebar/navigation-panel/index.js +24 -24
  122. package/build-module/components/navigation-sidebar/navigation-panel/index.js.map +1 -1
  123. package/build-module/components/routes/index.js +47 -0
  124. package/build-module/components/routes/index.js.map +1 -0
  125. package/build-module/components/routes/link.js +51 -0
  126. package/build-module/components/routes/link.js.map +1 -0
  127. package/build-module/components/routes/use-title.js +44 -0
  128. package/build-module/components/routes/use-title.js.map +1 -0
  129. package/build-module/components/sidebar/global-styles-sidebar.js +8 -0
  130. package/build-module/components/sidebar/global-styles-sidebar.js.map +1 -1
  131. package/build-module/components/sidebar/template-card/template-areas.js +8 -4
  132. package/build-module/components/sidebar/template-card/template-areas.js.map +1 -1
  133. package/build-module/components/template-details/edit-template-title.js +23 -0
  134. package/build-module/components/template-details/edit-template-title.js.map +1 -0
  135. package/build-module/components/template-details/index.js +15 -11
  136. package/build-module/components/template-details/index.js.map +1 -1
  137. package/build-module/components/template-details/template-areas.js +25 -10
  138. package/build-module/components/template-details/template-areas.js.map +1 -1
  139. package/build-module/components/template-part-converter/convert-to-template-part.js +7 -12
  140. package/build-module/components/template-part-converter/convert-to-template-part.js.map +1 -1
  141. package/build-module/components/url-query-controller/index.js +40 -49
  142. package/build-module/components/url-query-controller/index.js.map +1 -1
  143. package/build-module/components/welcome-guide/editor.js +7 -1
  144. package/build-module/components/welcome-guide/editor.js.map +1 -1
  145. package/build-module/components/welcome-guide/index.js +2 -26
  146. package/build-module/components/welcome-guide/index.js.map +1 -1
  147. package/build-module/components/welcome-guide/styles.js +18 -2
  148. package/build-module/components/welcome-guide/styles.js.map +1 -1
  149. package/build-module/index.js +28 -33
  150. package/build-module/index.js.map +1 -1
  151. package/build-module/plugins/index.js +2 -18
  152. package/build-module/plugins/index.js.map +1 -1
  153. package/build-module/plugins/site-export.js +45 -0
  154. package/build-module/plugins/site-export.js.map +1 -0
  155. package/build-module/plugins/welcome-guide-menu-item.js +2 -7
  156. package/build-module/plugins/welcome-guide-menu-item.js.map +1 -1
  157. package/build-module/store/actions.js +0 -23
  158. package/build-module/store/actions.js.map +1 -1
  159. package/build-module/store/constants.js +0 -11
  160. package/build-module/store/constants.js.map +1 -1
  161. package/build-module/store/reducer.js +7 -16
  162. package/build-module/store/reducer.js.map +1 -1
  163. package/build-module/store/selectors.js +1 -27
  164. package/build-module/store/selectors.js.map +1 -1
  165. package/build-module/utils/get-is-list-page.js +16 -0
  166. package/build-module/utils/get-is-list-page.js.map +1 -0
  167. package/build-module/utils/history.js +25 -0
  168. package/build-module/utils/history.js.map +1 -0
  169. package/build-style/style-rtl.css +11 -10
  170. package/build-style/style.css +11 -10
  171. package/package.json +9 -8
  172. package/src/components/add-new-template/new-template-part.js +29 -11
  173. package/src/components/add-new-template/new-template.js +26 -12
  174. package/src/components/app/index.js +47 -0
  175. package/src/components/block-editor/back-button.js +6 -14
  176. package/src/components/block-editor/index.js +1 -0
  177. package/src/components/create-template-part-modal/index.js +0 -2
  178. package/src/components/edit-template-part-menu-button/index.js +16 -5
  179. package/src/components/editor/index.js +105 -131
  180. package/src/components/global-styles/gradients-palette-panel.js +20 -0
  181. package/src/components/global-styles/screen-background-color.js +1 -0
  182. package/src/components/global-styles/screen-link-color.js +1 -0
  183. package/src/components/global-styles/screen-text-color.js +1 -0
  184. package/src/components/global-styles/style.scss +12 -6
  185. package/src/components/global-styles/use-global-styles-output.js +0 -1
  186. package/src/components/header/document-actions/index.js +3 -9
  187. package/src/components/list/actions/index.js +1 -1
  188. package/src/components/list/index.js +11 -12
  189. package/src/components/list/style.scss +6 -11
  190. package/src/components/list/table.js +7 -6
  191. package/src/components/navigation-sidebar/index.js +18 -17
  192. package/src/components/navigation-sidebar/navigation-panel/index.js +16 -22
  193. package/src/components/routes/index.js +53 -0
  194. package/src/components/routes/link.js +44 -0
  195. package/src/components/routes/use-title.js +56 -0
  196. package/src/components/sidebar/global-styles-sidebar.js +8 -0
  197. package/src/components/sidebar/template-card/template-areas.js +16 -4
  198. package/src/components/template-details/edit-template-title.js +28 -0
  199. package/src/components/template-details/index.js +21 -14
  200. package/src/components/template-details/template-areas.js +32 -9
  201. package/src/components/template-part-converter/convert-to-template-part.js +4 -2
  202. package/src/components/url-query-controller/index.js +34 -45
  203. package/src/components/welcome-guide/editor.js +10 -1
  204. package/src/components/welcome-guide/index.js +6 -25
  205. package/src/components/welcome-guide/styles.js +20 -2
  206. package/src/index.js +33 -36
  207. package/src/plugins/index.js +2 -32
  208. package/src/plugins/site-export.js +48 -0
  209. package/src/plugins/welcome-guide-menu-item.js +2 -16
  210. package/src/store/actions.js +0 -23
  211. package/src/store/constants.js +0 -12
  212. package/src/store/reducer.js +12 -26
  213. package/src/store/selectors.js +1 -27
  214. package/src/store/test/reducer.js +22 -39
  215. package/src/store/test/selectors.js +3 -34
  216. package/src/utils/get-is-list-page.js +11 -0
  217. package/src/utils/history.js +35 -0
@@ -15,11 +15,9 @@ import {
15
15
  } from '@wordpress/components';
16
16
  import { store as coreDataStore } from '@wordpress/core-data';
17
17
  import { useSelect, useDispatch } from '@wordpress/data';
18
- import { useEffect, useRef } from '@wordpress/element';
19
18
  import { __ } from '@wordpress/i18n';
20
19
  import { ESCAPE } from '@wordpress/keycodes';
21
20
  import { decodeEntities } from '@wordpress/html-entities';
22
- import { addQueryArgs } from '@wordpress/url';
23
21
  import {
24
22
  home as siteIcon,
25
23
  layout as templateIcon,
@@ -29,11 +27,18 @@ import {
29
27
  /**
30
28
  * Internal dependencies
31
29
  */
30
+ import { useLink } from '../../routes/link';
32
31
  import MainDashboardButton from '../../main-dashboard-button';
33
32
  import { store as editSiteStore } from '../../../store';
34
33
 
35
34
  const SITE_EDITOR_KEY = 'site-editor';
36
35
 
36
+ function NavLink( { params, replace, ...props } ) {
37
+ const linkProps = useLink( params, replace );
38
+
39
+ return <NavigationItem { ...linkProps } { ...props } />;
40
+ }
41
+
37
42
  const NavigationPanel = ( { activeItem = SITE_EDITOR_KEY } ) => {
38
43
  const { isNavigationOpen, siteTitle } = useSelect( ( select ) => {
39
44
  const { getEntityRecord } = select( coreDataStore );
@@ -48,15 +53,6 @@ const NavigationPanel = ( { activeItem = SITE_EDITOR_KEY } ) => {
48
53
  }, [] );
49
54
  const { setIsNavigationPanelOpened } = useDispatch( editSiteStore );
50
55
 
51
- // Ensures focus is moved to the panel area when it is activated
52
- // from a separate component (such as document actions in the header).
53
- const panelRef = useRef();
54
- useEffect( () => {
55
- if ( isNavigationOpen ) {
56
- panelRef.current.focus();
57
- }
58
- }, [ activeItem, isNavigationOpen ] );
59
-
60
56
  const closeOnEscape = ( event ) => {
61
57
  if ( event.keyCode === ESCAPE && ! event.defaultPrevented ) {
62
58
  event.preventDefault();
@@ -70,8 +66,6 @@ const NavigationPanel = ( { activeItem = SITE_EDITOR_KEY } ) => {
70
66
  className={ classnames( `edit-site-navigation-panel`, {
71
67
  'is-open': isNavigationOpen,
72
68
  } ) }
73
- ref={ panelRef }
74
- tabIndex="-1"
75
69
  onKeyDown={ closeOnEscape }
76
70
  >
77
71
  <div className="edit-site-navigation-panel__inner">
@@ -92,32 +86,32 @@ const NavigationPanel = ( { activeItem = SITE_EDITOR_KEY } ) => {
92
86
 
93
87
  <NavigationMenu>
94
88
  <NavigationGroup title={ __( 'Editor' ) }>
95
- <NavigationItem
89
+ <NavLink
96
90
  icon={ siteIcon }
97
91
  title={ __( 'Site' ) }
98
92
  item={ SITE_EDITOR_KEY }
99
- href={ addQueryArgs( window.location.href, {
93
+ params={ {
100
94
  postId: undefined,
101
95
  postType: undefined,
102
- } ) }
96
+ } }
103
97
  />
104
- <NavigationItem
98
+ <NavLink
105
99
  icon={ templateIcon }
106
100
  title={ __( 'Templates' ) }
107
101
  item="wp_template"
108
- href={ addQueryArgs( window.location.href, {
102
+ params={ {
109
103
  postId: undefined,
110
104
  postType: 'wp_template',
111
- } ) }
105
+ } }
112
106
  />
113
- <NavigationItem
107
+ <NavLink
114
108
  icon={ templatePartIcon }
115
109
  title={ __( 'Template Parts' ) }
116
110
  item="wp_template_part"
117
- href={ addQueryArgs( window.location.href, {
111
+ params={ {
118
112
  postId: undefined,
119
113
  postType: 'wp_template_part',
120
- } ) }
114
+ } }
121
115
  />
122
116
  </NavigationGroup>
123
117
  </NavigationMenu>
@@ -0,0 +1,53 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import {
5
+ createContext,
6
+ useState,
7
+ useEffect,
8
+ useContext,
9
+ } from '@wordpress/element';
10
+
11
+ /**
12
+ * Internal dependencies
13
+ */
14
+ import history from '../../utils/history';
15
+
16
+ const RoutesContext = createContext();
17
+ const HistoryContext = createContext();
18
+
19
+ export function useLocation() {
20
+ return useContext( RoutesContext );
21
+ }
22
+
23
+ export function useHistory() {
24
+ return useContext( HistoryContext );
25
+ }
26
+
27
+ function getLocationWithParams( location ) {
28
+ const searchParams = new URLSearchParams( location.search );
29
+ return {
30
+ ...location,
31
+ params: Object.fromEntries( searchParams.entries() ),
32
+ };
33
+ }
34
+
35
+ export function Routes( { children } ) {
36
+ const [ location, setLocation ] = useState( () =>
37
+ getLocationWithParams( history.location )
38
+ );
39
+
40
+ useEffect( () => {
41
+ return history.listen( ( { location: updatedLocation } ) => {
42
+ setLocation( getLocationWithParams( updatedLocation ) );
43
+ } );
44
+ }, [] );
45
+
46
+ return (
47
+ <HistoryContext.Provider value={ history }>
48
+ <RoutesContext.Provider value={ location }>
49
+ { children( location ) }
50
+ </RoutesContext.Provider>
51
+ </HistoryContext.Provider>
52
+ );
53
+ }
@@ -0,0 +1,44 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import { addQueryArgs } from '@wordpress/url';
5
+
6
+ /**
7
+ * Internal dependencies
8
+ */
9
+ import { useHistory } from './index';
10
+
11
+ export function useLink( params = {}, state, shouldReplace = false ) {
12
+ const history = useHistory();
13
+
14
+ function onClick( event ) {
15
+ event.preventDefault();
16
+
17
+ if ( shouldReplace ) {
18
+ history.replace( params, state );
19
+ } else {
20
+ history.push( params, state );
21
+ }
22
+ }
23
+
24
+ return {
25
+ href: addQueryArgs( window.location.href, params ),
26
+ onClick,
27
+ };
28
+ }
29
+
30
+ export default function Link( {
31
+ params = {},
32
+ state,
33
+ replace: shouldReplace = false,
34
+ children,
35
+ ...props
36
+ } ) {
37
+ const { href, onClick } = useLink( params, state, shouldReplace );
38
+
39
+ return (
40
+ <a href={ href } onClick={ onClick } { ...props }>
41
+ { children }
42
+ </a>
43
+ );
44
+ }
@@ -0,0 +1,56 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import { useEffect, useRef } from '@wordpress/element';
5
+ import { useSelect } from '@wordpress/data';
6
+ import { store as coreStore } from '@wordpress/core-data';
7
+ import { __, sprintf } from '@wordpress/i18n';
8
+ import { speak } from '@wordpress/a11y';
9
+
10
+ /**
11
+ * Internal dependencies
12
+ */
13
+ import { useLocation } from './index';
14
+
15
+ export default function useTitle( title ) {
16
+ const location = useLocation();
17
+ const siteTitle = useSelect(
18
+ ( select ) =>
19
+ select( coreStore ).getEntityRecord( 'root', 'site' )?.title,
20
+ []
21
+ );
22
+ const isInitialLocationRef = useRef( true );
23
+
24
+ useEffect( () => {
25
+ isInitialLocationRef.current = false;
26
+ }, [ location ] );
27
+
28
+ useEffect( () => {
29
+ // Don't update or announce the title for initial page load.
30
+ if ( isInitialLocationRef.current ) {
31
+ return;
32
+ }
33
+
34
+ if ( title && siteTitle ) {
35
+ // @see https://github.com/WordPress/wordpress-develop/blob/94849898192d271d533e09756007e176feb80697/src/wp-admin/admin-header.php#L67-L68
36
+ const formattedTitle = sprintf(
37
+ /* translators: Admin screen title. 1: Admin screen name, 2: Network or site name. */
38
+ __( '%1$s ‹ %2$s — WordPress' ),
39
+ title,
40
+ siteTitle
41
+ );
42
+
43
+ document.title = formattedTitle;
44
+
45
+ // Announce title on route change for screen readers.
46
+ speak(
47
+ sprintf(
48
+ /* translators: The page title that is currently displaying. */
49
+ __( 'Now displaying: %s' ),
50
+ document.title
51
+ ),
52
+ 'assertive'
53
+ );
54
+ }
55
+ }, [ title, siteTitle, location ] );
56
+ }
@@ -4,15 +4,18 @@
4
4
  import { DropdownMenu, FlexItem, FlexBlock, Flex } from '@wordpress/components';
5
5
  import { __ } from '@wordpress/i18n';
6
6
  import { styles, moreVertical } from '@wordpress/icons';
7
+ import { useDispatch } from '@wordpress/data';
7
8
 
8
9
  /**
9
10
  * Internal dependencies
10
11
  */
11
12
  import DefaultSidebar from './default-sidebar';
12
13
  import { GlobalStylesUI, useGlobalStylesReset } from '../global-styles';
14
+ import { store as editSiteStore } from '../../store';
13
15
 
14
16
  export default function GlobalStylesSidebar() {
15
17
  const [ canReset, onReset ] = useGlobalStylesReset();
18
+ const { toggleFeature } = useDispatch( editSiteStore );
16
19
 
17
20
  return (
18
21
  <DefaultSidebar
@@ -39,6 +42,11 @@ export default function GlobalStylesSidebar() {
39
42
  title: __( 'Reset to defaults' ),
40
43
  onClick: onReset,
41
44
  },
45
+ {
46
+ title: __( 'Welcome Guide' ),
47
+ onClick: () =>
48
+ toggleFeature( 'welcomeGuideStyles' ),
49
+ },
42
50
  ] }
43
51
  />
44
52
  </FlexItem>
@@ -6,7 +6,7 @@ import {
6
6
  Button,
7
7
  __experimentalHeading as Heading,
8
8
  } from '@wordpress/components';
9
- import { getTemplatePartIcon } from '@wordpress/editor';
9
+ import { store as editorStore } from '@wordpress/editor';
10
10
  import { store as blockEditorStore } from '@wordpress/block-editor';
11
11
  import { __ } from '@wordpress/i18n';
12
12
 
@@ -14,19 +14,31 @@ import { __ } from '@wordpress/i18n';
14
14
  * Internal dependencies
15
15
  */
16
16
  import { store as editSiteStore } from '../../../store';
17
- import { TEMPLATE_PART_AREA_TO_NAME } from '../../../store/constants';
18
17
 
19
18
  function TemplateAreaItem( { area, clientId } ) {
20
19
  const { selectBlock, toggleBlockHighlight } = useDispatch(
21
20
  blockEditorStore
22
21
  );
22
+ const templatePartArea = useSelect(
23
+ ( select ) => {
24
+ const defaultAreas = select(
25
+ editorStore
26
+ ).__experimentalGetDefaultTemplatePartAreas();
27
+
28
+ return defaultAreas.find(
29
+ ( defaultArea ) => defaultArea.area === area
30
+ );
31
+ },
32
+ [ area ]
33
+ );
34
+
23
35
  const highlightBlock = () => toggleBlockHighlight( clientId, true );
24
36
  const cancelHighlightBlock = () => toggleBlockHighlight( clientId, false );
25
37
 
26
38
  return (
27
39
  <Button
28
40
  className="edit-site-template-card__template-areas-item"
29
- icon={ getTemplatePartIcon( area ) }
41
+ icon={ templatePartArea?.icon }
30
42
  onMouseOver={ highlightBlock }
31
43
  onMouseLeave={ cancelHighlightBlock }
32
44
  onFocus={ highlightBlock }
@@ -35,7 +47,7 @@ function TemplateAreaItem( { area, clientId } ) {
35
47
  selectBlock( clientId );
36
48
  } }
37
49
  >
38
- { TEMPLATE_PART_AREA_TO_NAME[ area ] }
50
+ { templatePartArea?.label }
39
51
  </Button>
40
52
  );
41
53
  }
@@ -0,0 +1,28 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import { __ } from '@wordpress/i18n';
5
+ import { TextControl } from '@wordpress/components';
6
+ import { useEntityProp } from '@wordpress/core-data';
7
+
8
+ export default function EditTemplateTitle( { template } ) {
9
+ const [ title, setTitle ] = useEntityProp(
10
+ 'postType',
11
+ template.type,
12
+ 'title',
13
+ template.id
14
+ );
15
+
16
+ return (
17
+ <TextControl
18
+ label={ __( 'Title' ) }
19
+ value={ title }
20
+ help={ __(
21
+ 'Give the template a title that indicates its purpose, e.g. "Full Width".'
22
+ ) }
23
+ onChange={ ( newTitle ) => {
24
+ setTitle( newTitle || template.slug );
25
+ } }
26
+ />
27
+ );
28
+ }
@@ -12,7 +12,6 @@ import {
12
12
  } from '@wordpress/components';
13
13
  import { useDispatch, useSelect } from '@wordpress/data';
14
14
  import { store as editorStore } from '@wordpress/editor';
15
- import { addQueryArgs } from '@wordpress/url';
16
15
 
17
16
  /**
18
17
  * Internal dependencies
@@ -24,6 +23,8 @@ import {
24
23
  } from '../navigation-sidebar/navigation-panel/constants';
25
24
  import { store as editSiteStore } from '../../store';
26
25
  import TemplateAreas from './template-areas';
26
+ import EditTemplateTitle from './edit-template-title';
27
+ import { useLink } from '../routes/link';
27
28
 
28
29
  export default function TemplateDetails( { template, onClose } ) {
29
30
  const { title, description } = useSelect(
@@ -43,6 +44,12 @@ export default function TemplateDetails( { template, onClose } ) {
43
44
  );
44
45
  }, [ template ] );
45
46
 
47
+ const browseAllLinkProps = useLink( {
48
+ // TODO: We should update this to filter by template part's areas as well.
49
+ postType: template.type,
50
+ postId: undefined,
51
+ } );
52
+
46
53
  if ( ! template ) {
47
54
  return null;
48
55
  }
@@ -55,13 +62,17 @@ export default function TemplateDetails( { template, onClose } ) {
55
62
  return (
56
63
  <div className="edit-site-template-details">
57
64
  <div className="edit-site-template-details__group">
58
- <Heading
59
- level={ 4 }
60
- weight={ 600 }
61
- className="edit-site-template-details__title"
62
- >
63
- { title }
64
- </Heading>
65
+ { template.is_custom ? (
66
+ <EditTemplateTitle template={ template } />
67
+ ) : (
68
+ <Heading
69
+ level={ 4 }
70
+ weight={ 600 }
71
+ className="edit-site-template-details__title"
72
+ >
73
+ { title }
74
+ </Heading>
75
+ ) }
65
76
 
66
77
  { description && (
67
78
  <Text
@@ -80,7 +91,7 @@ export default function TemplateDetails( { template, onClose } ) {
80
91
  <MenuGroup className="edit-site-template-details__group edit-site-template-details__revert">
81
92
  <MenuItem
82
93
  className="edit-site-template-details__revert-button"
83
- info={ __( 'Restore template to theme default' ) }
94
+ info={ __( 'Restore template to default state' ) }
84
95
  onClick={ revert }
85
96
  >
86
97
  { __( 'Clear customizations' ) }
@@ -90,11 +101,7 @@ export default function TemplateDetails( { template, onClose } ) {
90
101
 
91
102
  <Button
92
103
  className="edit-site-template-details__show-all-button"
93
- href={ addQueryArgs( window.location.href, {
94
- // TODO: We should update this to filter by template part's areas as well.
95
- postId: undefined,
96
- postType: template.type,
97
- } ) }
104
+ { ...browseAllLinkProps }
98
105
  >
99
106
  { sprintf(
100
107
  /* translators: the template part's area name ("Headers", "Sidebars") or "templates". */
@@ -4,7 +4,7 @@
4
4
  import { sprintf, __ } from '@wordpress/i18n';
5
5
  import { DropdownMenu, MenuGroup, MenuItem } from '@wordpress/components';
6
6
  import { useSelect, useDispatch } from '@wordpress/data';
7
- import { getTemplatePartIcon } from '@wordpress/editor';
7
+ import { store as editorStore } from '@wordpress/editor';
8
8
  import { store as blockEditorStore } from '@wordpress/block-editor';
9
9
  import { moreVertical } from '@wordpress/icons';
10
10
 
@@ -12,18 +12,29 @@ import { moreVertical } from '@wordpress/icons';
12
12
  * Internal dependencies
13
13
  */
14
14
  import { store as editSiteStore } from '../../store';
15
- import { TEMPLATE_PART_AREA_TO_NAME } from '../../store/constants';
16
15
  import isTemplateRevertable from '../../utils/is-template-revertable';
16
+ import { useLocation } from '../routes';
17
+ import { useLink } from '../routes/link';
17
18
 
18
19
  function TemplatePartItemMore( {
19
20
  onClose,
20
21
  templatePart,
21
22
  closeTemplateDetailsDropdown,
22
23
  } ) {
23
- const { pushTemplatePart, revertTemplate } = useDispatch( editSiteStore );
24
+ const { revertTemplate } = useDispatch( editSiteStore );
25
+ const { params } = useLocation();
26
+ const editLinkProps = useLink(
27
+ {
28
+ postId: templatePart.id,
29
+ postType: templatePart.type,
30
+ },
31
+ {
32
+ fromTemplateId: params.postId,
33
+ }
34
+ );
24
35
 
25
- function editTemplatePart() {
26
- pushTemplatePart( templatePart.id );
36
+ function editTemplatePart( event ) {
37
+ editLinkProps.onClick( event );
27
38
  onClose();
28
39
  closeTemplateDetailsDropdown();
29
40
  }
@@ -37,7 +48,7 @@ function TemplatePartItemMore( {
37
48
  return (
38
49
  <>
39
50
  <MenuGroup>
40
- <MenuItem onClick={ editTemplatePart }>
51
+ <MenuItem { ...editLinkProps } onClick={ editTemplatePart }>
41
52
  { sprintf(
42
53
  /* translators: %s: template part title */
43
54
  __( 'Edit %s' ),
@@ -48,7 +59,7 @@ function TemplatePartItemMore( {
48
59
  { isTemplateRevertable( templatePart ) && (
49
60
  <MenuGroup>
50
61
  <MenuItem
51
- info={ __( 'Restore template to theme default' ) }
62
+ info={ __( 'Restore template to default state' ) }
52
63
  onClick={ clearCustomizations }
53
64
  >
54
65
  { __( 'Clear customizations' ) }
@@ -67,6 +78,18 @@ function TemplatePartItem( {
67
78
  const { selectBlock, toggleBlockHighlight } = useDispatch(
68
79
  blockEditorStore
69
80
  );
81
+ const templatePartArea = useSelect(
82
+ ( select ) => {
83
+ const defaultAreas = select(
84
+ editorStore
85
+ ).__experimentalGetDefaultTemplatePartAreas();
86
+
87
+ return defaultAreas.find(
88
+ ( defaultArea ) => defaultArea.area === templatePart.area
89
+ );
90
+ },
91
+ [ templatePart.area ]
92
+ );
70
93
  const highlightBlock = () => toggleBlockHighlight( clientId, true );
71
94
  const cancelHighlightBlock = () => toggleBlockHighlight( clientId, false );
72
95
 
@@ -77,7 +100,7 @@ function TemplatePartItem( {
77
100
  >
78
101
  <MenuItem
79
102
  role="button"
80
- icon={ getTemplatePartIcon( templatePart.area ) }
103
+ icon={ templatePartArea?.icon }
81
104
  iconPosition="left"
82
105
  onClick={ () => {
83
106
  selectBlock( clientId );
@@ -87,7 +110,7 @@ function TemplatePartItem( {
87
110
  onFocus={ highlightBlock }
88
111
  onBlur={ cancelHighlightBlock }
89
112
  >
90
- { TEMPLATE_PART_AREA_TO_NAME[ templatePart.area ] }
113
+ { templatePartArea?.label }
91
114
  </MenuItem>
92
115
 
93
116
  <DropdownMenu
@@ -50,16 +50,18 @@ export default function ConvertToTemplatePart( { clientIds, blocks } ) {
50
50
  createSuccessNotice( __( 'Template part created.' ), {
51
51
  type: 'snackbar',
52
52
  } );
53
+
54
+ // The modal and this component will be unmounted because of `replaceBlocks` above,
55
+ // so no need to call `closeModal` or `onClose`.
53
56
  };
54
57
 
55
58
  return (
56
59
  <>
57
60
  <BlockSettingsMenuControls>
58
- { ( { onClose } ) => (
61
+ { () => (
59
62
  <MenuItem
60
63
  onClick={ () => {
61
64
  setIsModalOpen( true );
62
- onClose();
63
65
  } }
64
66
  >
65
67
  { __( 'Make template part' ) }
@@ -3,29 +3,29 @@
3
3
  */
4
4
  import { useEffect } from '@wordpress/element';
5
5
  import { useDispatch, useSelect } from '@wordpress/data';
6
- import { getQueryArg, addQueryArgs, removeQueryArgs } from '@wordpress/url';
7
6
 
8
7
  /**
9
8
  * Internal dependencies
10
9
  */
10
+ import { useLocation, useHistory } from '../routes';
11
11
  import { store as editSiteStore } from '../../store';
12
12
 
13
13
  export default function URLQueryController() {
14
14
  const { setTemplate, setTemplatePart, showHomepage, setPage } = useDispatch(
15
15
  editSiteStore
16
16
  );
17
+ const history = useHistory();
18
+ const {
19
+ params: { postId, postType },
20
+ } = useLocation();
21
+ const { getPage, getEditedPostId, getEditedPostType } = useSelect(
22
+ editSiteStore
23
+ );
17
24
 
18
- // Set correct entity on load.
25
+ // Set correct entity on page navigation.
19
26
  useEffect( () => {
20
- const url = window.location.href;
21
- const postId = getQueryArg( url, 'postId' );
22
-
23
- if ( ! postId ) {
24
- showHomepage();
25
- return;
26
- }
27
+ let isMounted = true;
27
28
 
28
- const postType = getQueryArg( url, 'postType' );
29
29
  if ( 'page' === postType || 'post' === postType ) {
30
30
  setPage( { context: { postType, postId } } ); // Resolves correct template based on ID.
31
31
  } else if ( 'wp_template' === postType ) {
@@ -33,44 +33,33 @@ export default function URLQueryController() {
33
33
  } else if ( 'wp_template_part' === postType ) {
34
34
  setTemplatePart( postId );
35
35
  } else {
36
- showHomepage();
37
- }
38
- }, [] );
39
-
40
- // Update page URL when context changes.
41
- const pageContext = useCurrentPageContext();
42
- useEffect( () => {
43
- const newUrl = pageContext
44
- ? addQueryArgs( window.location.href, pageContext )
45
- : removeQueryArgs( window.location.href, 'postType', 'postId' );
36
+ showHomepage().then( () => {
37
+ if ( ! isMounted ) {
38
+ return;
39
+ }
46
40
 
47
- window.history.replaceState( {}, '', newUrl );
48
- }, [ pageContext ] );
41
+ const page = getPage();
42
+ const editedPostId = getEditedPostId();
43
+ const editedPostType = getEditedPostType();
49
44
 
50
- return null;
51
- }
52
-
53
- function useCurrentPageContext() {
54
- return useSelect( ( select ) => {
55
- const { getEditedPostType, getEditedPostId, getPage } = select(
56
- editSiteStore
57
- );
58
-
59
- const page = getPage();
60
- let _postId = getEditedPostId(),
61
- _postType = getEditedPostType();
62
- // This doesn't seem right to me,
63
- // we shouldn't be using the "page" and the "template" in the same way.
64
- // This need to be investigated.
65
- if ( page?.context?.postId && page?.context?.postType ) {
66
- _postId = page.context.postId;
67
- _postType = page.context.postType;
45
+ if ( page?.context?.postId && page?.context?.postType ) {
46
+ history.replace( {
47
+ postId: page.context.postId,
48
+ postType: page.context.postType,
49
+ } );
50
+ } else if ( editedPostId && editedPostType ) {
51
+ history.replace( {
52
+ postId: editedPostId,
53
+ postType: editedPostType,
54
+ } );
55
+ }
56
+ } );
68
57
  }
69
58
 
70
- if ( _postId && _postType ) {
71
- return { postId: _postId, postType: _postType };
72
- }
59
+ return () => {
60
+ isMounted = false;
61
+ };
62
+ }, [ postId, postType ] );
73
63
 
74
- return null;
75
- }, [] );
64
+ return null;
76
65
  }