@wordpress/edit-site 3.0.15 → 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 (191) 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 +10 -10
  18. package/build/components/global-styles/gradients-palette-panel.js.map +1 -1
  19. package/build/components/global-styles/use-global-styles-output.js +1 -2
  20. package/build/components/global-styles/use-global-styles-output.js.map +1 -1
  21. package/build/components/header/document-actions/index.js +3 -6
  22. package/build/components/header/document-actions/index.js.map +1 -1
  23. package/build/components/list/index.js +17 -15
  24. package/build/components/list/index.js.map +1 -1
  25. package/build/components/list/table.js +4 -4
  26. package/build/components/list/table.js.map +1 -1
  27. package/build/components/navigation-sidebar/index.js +12 -13
  28. package/build/components/navigation-sidebar/index.js.map +1 -1
  29. package/build/components/navigation-sidebar/navigation-panel/index.js +26 -24
  30. package/build/components/navigation-sidebar/navigation-panel/index.js.map +1 -1
  31. package/build/components/routes/index.js +60 -0
  32. package/build/components/routes/index.js.map +1 -0
  33. package/build/components/routes/link.js +65 -0
  34. package/build/components/routes/link.js.map +1 -0
  35. package/build/components/routes/use-title.js +57 -0
  36. package/build/components/routes/use-title.js.map +1 -0
  37. package/build/components/sidebar/global-styles-sidebar.js +10 -0
  38. package/build/components/sidebar/global-styles-sidebar.js.map +1 -1
  39. package/build/components/sidebar/template-card/template-areas.js +7 -4
  40. package/build/components/sidebar/template-card/template-areas.js.map +1 -1
  41. package/build/components/template-details/index.js +12 -10
  42. package/build/components/template-details/index.js.map +1 -1
  43. package/build/components/template-details/template-areas.js +27 -10
  44. package/build/components/template-details/template-areas.js.map +1 -1
  45. package/build/components/template-part-converter/convert-to-template-part.js +7 -12
  46. package/build/components/template-part-converter/convert-to-template-part.js.map +1 -1
  47. package/build/components/url-query-controller/index.js +41 -50
  48. package/build/components/url-query-controller/index.js.map +1 -1
  49. package/build/components/welcome-guide/editor.js +6 -0
  50. package/build/components/welcome-guide/editor.js.map +1 -1
  51. package/build/components/welcome-guide/index.js +1 -28
  52. package/build/components/welcome-guide/index.js.map +1 -1
  53. package/build/components/welcome-guide/styles.js +18 -1
  54. package/build/components/welcome-guide/styles.js.map +1 -1
  55. package/build/index.js +29 -35
  56. package/build/index.js.map +1 -1
  57. package/build/plugins/index.js +3 -23
  58. package/build/plugins/index.js.map +1 -1
  59. package/build/plugins/site-export.js +61 -0
  60. package/build/plugins/site-export.js.map +1 -0
  61. package/build/plugins/welcome-guide-menu-item.js +1 -7
  62. package/build/plugins/welcome-guide-menu-item.js.map +1 -1
  63. package/build/store/actions.js +0 -27
  64. package/build/store/actions.js.map +1 -1
  65. package/build/store/constants.js +1 -14
  66. package/build/store/constants.js.map +1 -1
  67. package/build/store/reducer.js +7 -16
  68. package/build/store/reducer.js.map +1 -1
  69. package/build/store/selectors.js +1 -31
  70. package/build/store/selectors.js.map +1 -1
  71. package/build/utils/get-is-list-page.js +23 -0
  72. package/build/utils/get-is-list-page.js.map +1 -0
  73. package/build/utils/history.js +35 -0
  74. package/build/utils/history.js.map +1 -0
  75. package/build-module/components/add-new-template/new-template-part.js +27 -16
  76. package/build-module/components/add-new-template/new-template-part.js.map +1 -1
  77. package/build-module/components/add-new-template/new-template.js +28 -18
  78. package/build-module/components/add-new-template/new-template.js.map +1 -1
  79. package/build-module/components/app/index.js +35 -0
  80. package/build-module/components/app/index.js.map +1 -0
  81. package/build-module/components/block-editor/back-button.js +8 -19
  82. package/build-module/components/block-editor/back-button.js.map +1 -1
  83. package/build-module/components/block-editor/index.js +2 -1
  84. package/build-module/components/block-editor/index.js.map +1 -1
  85. package/build-module/components/create-template-part-modal/index.js +0 -2
  86. package/build-module/components/create-template-part-modal/index.js.map +1 -1
  87. package/build-module/components/edit-template-part-menu-button/index.js +17 -9
  88. package/build-module/components/edit-template-part-menu-button/index.js.map +1 -1
  89. package/build-module/components/editor/index.js +13 -33
  90. package/build-module/components/editor/index.js.map +1 -1
  91. package/build-module/components/global-styles/gradients-palette-panel.js +10 -10
  92. package/build-module/components/global-styles/gradients-palette-panel.js.map +1 -1
  93. package/build-module/components/global-styles/use-global-styles-output.js +1 -2
  94. package/build-module/components/global-styles/use-global-styles-output.js.map +1 -1
  95. package/build-module/components/header/document-actions/index.js +3 -6
  96. package/build-module/components/header/document-actions/index.js.map +1 -1
  97. package/build-module/components/list/index.js +15 -15
  98. package/build-module/components/list/index.js.map +1 -1
  99. package/build-module/components/list/table.js +4 -4
  100. package/build-module/components/list/table.js.map +1 -1
  101. package/build-module/components/navigation-sidebar/index.js +13 -13
  102. package/build-module/components/navigation-sidebar/index.js.map +1 -1
  103. package/build-module/components/navigation-sidebar/navigation-panel/index.js +24 -24
  104. package/build-module/components/navigation-sidebar/navigation-panel/index.js.map +1 -1
  105. package/build-module/components/routes/index.js +47 -0
  106. package/build-module/components/routes/index.js.map +1 -0
  107. package/build-module/components/routes/link.js +51 -0
  108. package/build-module/components/routes/link.js.map +1 -0
  109. package/build-module/components/routes/use-title.js +44 -0
  110. package/build-module/components/routes/use-title.js.map +1 -0
  111. package/build-module/components/sidebar/global-styles-sidebar.js +8 -0
  112. package/build-module/components/sidebar/global-styles-sidebar.js.map +1 -1
  113. package/build-module/components/sidebar/template-card/template-areas.js +8 -4
  114. package/build-module/components/sidebar/template-card/template-areas.js.map +1 -1
  115. package/build-module/components/template-details/index.js +10 -9
  116. package/build-module/components/template-details/index.js.map +1 -1
  117. package/build-module/components/template-details/template-areas.js +24 -9
  118. package/build-module/components/template-details/template-areas.js.map +1 -1
  119. package/build-module/components/template-part-converter/convert-to-template-part.js +7 -12
  120. package/build-module/components/template-part-converter/convert-to-template-part.js.map +1 -1
  121. package/build-module/components/url-query-controller/index.js +40 -49
  122. package/build-module/components/url-query-controller/index.js.map +1 -1
  123. package/build-module/components/welcome-guide/editor.js +7 -1
  124. package/build-module/components/welcome-guide/editor.js.map +1 -1
  125. package/build-module/components/welcome-guide/index.js +2 -26
  126. package/build-module/components/welcome-guide/index.js.map +1 -1
  127. package/build-module/components/welcome-guide/styles.js +18 -2
  128. package/build-module/components/welcome-guide/styles.js.map +1 -1
  129. package/build-module/index.js +28 -33
  130. package/build-module/index.js.map +1 -1
  131. package/build-module/plugins/index.js +2 -18
  132. package/build-module/plugins/index.js.map +1 -1
  133. package/build-module/plugins/site-export.js +45 -0
  134. package/build-module/plugins/site-export.js.map +1 -0
  135. package/build-module/plugins/welcome-guide-menu-item.js +2 -7
  136. package/build-module/plugins/welcome-guide-menu-item.js.map +1 -1
  137. package/build-module/store/actions.js +0 -23
  138. package/build-module/store/actions.js.map +1 -1
  139. package/build-module/store/constants.js +0 -11
  140. package/build-module/store/constants.js.map +1 -1
  141. package/build-module/store/reducer.js +7 -16
  142. package/build-module/store/reducer.js.map +1 -1
  143. package/build-module/store/selectors.js +1 -27
  144. package/build-module/store/selectors.js.map +1 -1
  145. package/build-module/utils/get-is-list-page.js +16 -0
  146. package/build-module/utils/get-is-list-page.js.map +1 -0
  147. package/build-module/utils/history.js +25 -0
  148. package/build-module/utils/history.js.map +1 -0
  149. package/build-style/style-rtl.css +1 -6
  150. package/build-style/style.css +1 -6
  151. package/package.json +9 -8
  152. package/src/components/add-new-template/new-template-part.js +29 -11
  153. package/src/components/add-new-template/new-template.js +26 -12
  154. package/src/components/app/index.js +47 -0
  155. package/src/components/block-editor/back-button.js +6 -14
  156. package/src/components/block-editor/index.js +1 -0
  157. package/src/components/create-template-part-modal/index.js +0 -2
  158. package/src/components/edit-template-part-menu-button/index.js +16 -5
  159. package/src/components/editor/index.js +105 -131
  160. package/src/components/global-styles/gradients-palette-panel.js +12 -12
  161. package/src/components/global-styles/use-global-styles-output.js +0 -1
  162. package/src/components/header/document-actions/index.js +3 -9
  163. package/src/components/list/index.js +11 -12
  164. package/src/components/list/style.scss +6 -11
  165. package/src/components/list/table.js +5 -5
  166. package/src/components/navigation-sidebar/index.js +18 -17
  167. package/src/components/navigation-sidebar/navigation-panel/index.js +16 -22
  168. package/src/components/routes/index.js +53 -0
  169. package/src/components/routes/link.js +44 -0
  170. package/src/components/routes/use-title.js +56 -0
  171. package/src/components/sidebar/global-styles-sidebar.js +8 -0
  172. package/src/components/sidebar/template-card/template-areas.js +16 -4
  173. package/src/components/template-details/index.js +8 -6
  174. package/src/components/template-details/template-areas.js +31 -8
  175. package/src/components/template-part-converter/convert-to-template-part.js +4 -2
  176. package/src/components/url-query-controller/index.js +34 -45
  177. package/src/components/welcome-guide/editor.js +10 -1
  178. package/src/components/welcome-guide/index.js +6 -25
  179. package/src/components/welcome-guide/styles.js +20 -2
  180. package/src/index.js +33 -36
  181. package/src/plugins/index.js +2 -32
  182. package/src/plugins/site-export.js +48 -0
  183. package/src/plugins/welcome-guide-menu-item.js +2 -16
  184. package/src/store/actions.js +0 -23
  185. package/src/store/constants.js +0 -12
  186. package/src/store/reducer.js +12 -26
  187. package/src/store/selectors.js +1 -27
  188. package/src/store/test/reducer.js +22 -39
  189. package/src/store/test/selectors.js +3 -34
  190. package/src/utils/get-is-list-page.js +11 -0
  191. package/src/utils/history.js +35 -0
@@ -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
  }
@@ -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
@@ -25,6 +24,7 @@ import {
25
24
  import { store as editSiteStore } from '../../store';
26
25
  import TemplateAreas from './template-areas';
27
26
  import EditTemplateTitle from './edit-template-title';
27
+ import { useLink } from '../routes/link';
28
28
 
29
29
  export default function TemplateDetails( { template, onClose } ) {
30
30
  const { title, description } = useSelect(
@@ -44,6 +44,12 @@ export default function TemplateDetails( { template, onClose } ) {
44
44
  );
45
45
  }, [ template ] );
46
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
+
47
53
  if ( ! template ) {
48
54
  return null;
49
55
  }
@@ -95,11 +101,7 @@ export default function TemplateDetails( { template, onClose } ) {
95
101
 
96
102
  <Button
97
103
  className="edit-site-template-details__show-all-button"
98
- href={ addQueryArgs( window.location.href, {
99
- // TODO: We should update this to filter by template part's areas as well.
100
- postId: undefined,
101
- postType: template.type,
102
- } ) }
104
+ { ...browseAllLinkProps }
103
105
  >
104
106
  { sprintf(
105
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' ),
@@ -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
  }
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * WordPress dependencies
3
3
  */
4
- import { useDispatch } from '@wordpress/data';
4
+ import { useDispatch, useSelect } from '@wordpress/data';
5
5
  import { Guide } from '@wordpress/components';
6
6
  import { __ } from '@wordpress/i18n';
7
7
  import { createInterpolateElement } from '@wordpress/element';
@@ -15,6 +15,15 @@ import { store as editSiteStore } from '../../store';
15
15
  export default function WelcomeGuideEditor() {
16
16
  const { toggleFeature } = useDispatch( editSiteStore );
17
17
 
18
+ const isActive = useSelect(
19
+ ( select ) => select( editSiteStore ).isFeatureActive( 'welcomeGuide' ),
20
+ []
21
+ );
22
+
23
+ if ( ! isActive ) {
24
+ return null;
25
+ }
26
+
18
27
  return (
19
28
  <Guide
20
29
  className="edit-site-welcome-guide"
@@ -1,33 +1,14 @@
1
- /**
2
- * WordPress dependencies
3
- */
4
- import { useSelect } from '@wordpress/data';
5
- import { store as interfaceStore } from '@wordpress/interface';
6
-
7
1
  /**
8
2
  * Internal dependencies
9
3
  */
10
4
  import WelcomeGuideEditor from './editor';
11
5
  import WelcomeGuideStyles from './styles';
12
- import { store as editSiteStore } from '../../store';
13
6
 
14
7
  export default function WelcomeGuide() {
15
- const { isActive, isStylesOpen } = useSelect( ( select ) => {
16
- const sidebar = select( interfaceStore ).getActiveComplementaryArea(
17
- editSiteStore.name
18
- );
19
- const isStylesSidebar = sidebar === 'edit-site/global-styles';
20
- const feature = isStylesSidebar ? 'welcomeGuideStyles' : 'welcomeGuide';
21
-
22
- return {
23
- isActive: select( editSiteStore ).isFeatureActive( feature ),
24
- isStylesOpen: isStylesSidebar,
25
- };
26
- }, [] );
27
-
28
- if ( ! isActive ) {
29
- return null;
30
- }
31
-
32
- return isStylesOpen ? <WelcomeGuideStyles /> : <WelcomeGuideEditor />;
8
+ return (
9
+ <>
10
+ <WelcomeGuideEditor />
11
+ <WelcomeGuideStyles />
12
+ </>
13
+ );
33
14
  }
@@ -1,9 +1,10 @@
1
1
  /**
2
2
  * WordPress dependencies
3
3
  */
4
- import { useDispatch } from '@wordpress/data';
4
+ import { useDispatch, useSelect } from '@wordpress/data';
5
5
  import { ExternalLink, Guide } from '@wordpress/components';
6
6
  import { __ } from '@wordpress/i18n';
7
+ import { store as interfaceStore } from '@wordpress/interface';
7
8
 
8
9
  /**
9
10
  * Internal dependencies
@@ -14,6 +15,23 @@ import { store as editSiteStore } from '../../store';
14
15
  export default function WelcomeGuideStyles() {
15
16
  const { toggleFeature } = useDispatch( editSiteStore );
16
17
 
18
+ const { isActive, isStylesOpen } = useSelect( ( select ) => {
19
+ const sidebar = select( interfaceStore ).getActiveComplementaryArea(
20
+ editSiteStore.name
21
+ );
22
+
23
+ return {
24
+ isActive: select( editSiteStore ).isFeatureActive(
25
+ 'welcomeGuideStyles'
26
+ ),
27
+ isStylesOpen: sidebar === 'edit-site/global-styles',
28
+ };
29
+ }, [] );
30
+
31
+ if ( ! isActive || ! isStylesOpen ) {
32
+ return null;
33
+ }
34
+
17
35
  return (
18
36
  <Guide
19
37
  className="edit-site-welcome-guide"
@@ -99,7 +117,7 @@ export default function WelcomeGuideStyles() {
99
117
  ) }
100
118
  <ExternalLink
101
119
  href={ __(
102
- 'https://wordpress.org/support/article/wordpress-editor/'
120
+ 'https://wordpress.org/support/article/styles-overview/'
103
121
  ) }
104
122
  >
105
123
  { __(
package/src/index.js CHANGED
@@ -14,6 +14,7 @@ import {
14
14
  } from '@wordpress/core-data';
15
15
  import { store as editorStore } from '@wordpress/editor';
16
16
  import { store as viewportStore } from '@wordpress/viewport';
17
+ import { getQueryArgs } from '@wordpress/url';
17
18
 
18
19
  /**
19
20
  * Internal dependencies
@@ -21,8 +22,8 @@ import { store as viewportStore } from '@wordpress/viewport';
21
22
  import './plugins';
22
23
  import './hooks';
23
24
  import { store as editSiteStore } from './store';
24
- import Editor from './components/editor';
25
- import List from './components/list';
25
+ import EditSiteApp from './components/app';
26
+ import getIsListPage from './utils/get-is-list-page';
26
27
 
27
28
  /**
28
29
  * Reinitializes the editor after the user chooses to reboot the editor after
@@ -33,12 +34,37 @@ import List from './components/list';
33
34
  * @param {?Object} settings Editor settings object.
34
35
  */
35
36
  export function reinitializeEditor( target, settings ) {
37
+ // This will be a no-op if the target doesn't have any React nodes.
36
38
  unmountComponentAtNode( target );
37
39
  const reboot = reinitializeEditor.bind( null, target, settings );
38
- render(
39
- <Editor initialSettings={ settings } onError={ reboot } />,
40
- target
41
- );
40
+
41
+ // We dispatch actions and update the store synchronously before rendering
42
+ // so that we won't trigger unnecessary re-renders with useEffect.
43
+ {
44
+ dispatch( editSiteStore ).updateSettings( settings );
45
+ // Keep the defaultTemplateTypes in the core/editor settings too,
46
+ // so that they can be selected with core/editor selectors in any editor.
47
+ // This is needed because edit-site doesn't initialize with EditorProvider,
48
+ // which internally uses updateEditorSettings as well.
49
+ dispatch( editorStore ).updateEditorSettings( {
50
+ defaultTemplateTypes: settings.defaultTemplateTypes,
51
+ defaultTemplatePartAreas: settings.defaultTemplatePartAreas,
52
+ } );
53
+
54
+ const isLandingOnListPage = getIsListPage(
55
+ getQueryArgs( window.location.href )
56
+ );
57
+
58
+ if ( isLandingOnListPage ) {
59
+ // Default the navigation panel to be opened when we're in a bigger
60
+ // screen and land in the list screen.
61
+ dispatch( editSiteStore ).setIsNavigationPanelOpened(
62
+ select( viewportStore ).isViewportMatch( 'medium' )
63
+ );
64
+ }
65
+ }
66
+
67
+ render( <EditSiteApp reboot={ reboot } />, target );
42
68
  }
43
69
 
44
70
  /**
@@ -54,7 +80,6 @@ export function initializeEditor( id, settings ) {
54
80
  settings.__experimentalSpotlightEntityBlocks = [ 'core/template-part' ];
55
81
 
56
82
  const target = document.getElementById( id );
57
- const reboot = reinitializeEditor.bind( null, target, settings );
58
83
 
59
84
  dispatch( blocksStore ).__experimentalReapplyBlockTypeFilters();
60
85
  registerCoreBlocks();
@@ -64,35 +89,7 @@ export function initializeEditor( id, settings ) {
64
89
  } );
65
90
  }
66
91
 
67
- render(
68
- <Editor initialSettings={ settings } onError={ reboot } />,
69
- target
70
- );
71
- }
72
-
73
- /**
74
- * Initializes the site editor templates list screen.
75
- *
76
- * @param {string} id ID of the root element to render the screen in.
77
- * @param {string} templateType The type of the list. "wp_template" or "wp_template_part".
78
- * @param {Object} settings Editor settings.
79
- */
80
- export function initializeList( id, templateType, settings ) {
81
- const target = document.getElementById( id );
82
-
83
- dispatch( editorStore ).updateEditorSettings( {
84
- defaultTemplateTypes: settings.defaultTemplateTypes,
85
- defaultTemplatePartAreas: settings.defaultTemplatePartAreas,
86
- } );
87
-
88
- // Default the navigation panel to be opened when we're in a bigger screen.
89
- // We update the store synchronously before rendering so that we won't
90
- // trigger an unnecessary re-render with useEffect.
91
- dispatch( editSiteStore ).setIsNavigationPanelOpened(
92
- select( viewportStore ).isViewportMatch( 'medium' )
93
- );
94
-
95
- render( <List templateType={ templateType } />, target );
92
+ reinitializeEditor( target, settings );
96
93
  }
97
94
 
98
95
  export { default as __experimentalMainDashboardButton } from './components/main-dashboard-button';