@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
@@ -0,0 +1,21 @@
1
+ /**
2
+ * External dependencies
3
+ */
4
+ import classnames from 'classnames';
5
+
6
+ /**
7
+ * WordPress dependencies
8
+ */
9
+ import { Button } from '@wordpress/components';
10
+
11
+ export default function SidebarButton( props ) {
12
+ return (
13
+ <Button
14
+ { ...props }
15
+ className={ classnames(
16
+ 'edit-site-sidebar-button',
17
+ props.className
18
+ ) }
19
+ />
20
+ );
21
+ }
@@ -0,0 +1,24 @@
1
+ .edit-site-sidebar-button {
2
+ color: $gray-200;
3
+ flex-shrink: 0;
4
+
5
+ // Focus (resets default button focus and use focus-visible).
6
+ &:focus:not(:disabled) {
7
+ box-shadow: none;
8
+ outline: none;
9
+ }
10
+ &:focus-visible:not(:disabled) {
11
+ box-shadow:
12
+ 0 0 0 var(--wp-admin-border-width-focus)
13
+ var(--wp-components-color-accent, var(--wp-admin-theme-color, #007cba));
14
+ outline: 3px solid transparent;
15
+ }
16
+
17
+ &:hover,
18
+ &:focus-visible,
19
+ &:focus,
20
+ &:not([aria-disabled="true"]):active,
21
+ &[aria-expanded="true"] {
22
+ color: $white;
23
+ }
24
+ }
@@ -15,26 +15,6 @@
15
15
  }
16
16
  }
17
17
 
18
- .edit-site-sidebar-navigation-screen__content .edit-site-navigation-inspector .components-button {
19
- color: $gray-600;
20
- &:hover,
21
- &:focus,
22
- &[aria-current] {
23
- color: $white;
24
- }
25
- }
26
-
27
- .edit-site-sidebar-navigation-screen__content .edit-site-navigation-inspector .offcanvas-editor-list-view-leaf {
28
- &:hover,
29
- &:focus,
30
- &[aria-current] {
31
- background: $gray-800;
32
- }
33
- .block-editor-list-view-block__menu {
34
- margin-left: -$grid-unit-10;
35
- }
36
- }
37
-
38
18
  .edit-site-sidebar-navigation-screen__content .block-editor-list-view-block-select-button {
39
19
  cursor: grab;
40
20
  width: calc(100% - #{ $border-width-focus });
@@ -5,7 +5,6 @@ import {
5
5
  __experimentalHStack as HStack,
6
6
  __experimentalVStack as VStack,
7
7
  __experimentalNavigatorToParentButton as NavigatorToParentButton,
8
- Button,
9
8
  } from '@wordpress/components';
10
9
  import { isRTL, __ } from '@wordpress/i18n';
11
10
  import { chevronRight, chevronLeft } from '@wordpress/icons';
@@ -16,12 +15,14 @@ import { useSelect } from '@wordpress/data';
16
15
  */
17
16
  import { store as editSiteStore } from '../../store';
18
17
  import { unlock } from '../../private-apis';
18
+ import SidebarButton from '../sidebar-button';
19
19
 
20
20
  export default function SidebarNavigationScreen( {
21
21
  isRoot,
22
22
  title,
23
23
  actions,
24
24
  content,
25
+ description,
25
26
  } ) {
26
27
  const { dashboardLink } = useSelect( ( select ) => {
27
28
  const { getSettings } = unlock( select( editSiteStore ) );
@@ -39,13 +40,12 @@ export default function SidebarNavigationScreen( {
39
40
  >
40
41
  { ! isRoot ? (
41
42
  <NavigatorToParentButton
42
- className="edit-site-sidebar-navigation-screen__back"
43
+ as={ SidebarButton }
43
44
  icon={ isRTL() ? chevronRight : chevronLeft }
44
45
  aria-label={ __( 'Back' ) }
45
46
  />
46
47
  ) : (
47
- <Button
48
- className="edit-site-sidebar-navigation-screen__back"
48
+ <SidebarButton
49
49
  icon={ isRTL() ? chevronRight : chevronLeft }
50
50
  aria-label={ __( 'Navigate to the Dashboard' ) }
51
51
  href={ dashboardLink || 'index.php' }
@@ -59,6 +59,11 @@ export default function SidebarNavigationScreen( {
59
59
  </HStack>
60
60
 
61
61
  <nav className="edit-site-sidebar-navigation-screen__content">
62
+ { description && (
63
+ <p className="edit-site-sidebar-navigation-screen__description">
64
+ { description }
65
+ </p>
66
+ ) }
62
67
  { content }
63
68
  </nav>
64
69
  </VStack>
@@ -10,6 +10,21 @@
10
10
  color: $gray-600;
11
11
  }
12
12
 
13
+ .edit-site-sidebar-navigation-screen__page-link {
14
+ color: $gray-600;
15
+
16
+ &:hover,
17
+ &:focus {
18
+ color: $white;
19
+ }
20
+
21
+ .components-external-link__icon {
22
+ margin-left: $grid-unit-05;
23
+ }
24
+ margin-left: $grid-unit-20;
25
+ display: inline-block;
26
+ }
27
+
13
28
  .edit-site-sidebar-navigation-screen__title-icon {
14
29
  position: sticky;
15
30
  top: 0;
@@ -23,18 +38,9 @@
23
38
 
24
39
  .edit-site-sidebar-navigation-screen__title {
25
40
  font-size: calc(1.56 * 13px);
41
+ line-height: normal;
26
42
  font-weight: 500;
27
43
  flex-grow: 1;
28
44
  color: $white;
29
45
  margin: 0;
30
46
  }
31
-
32
- .edit-site-sidebar-navigation-screen__back {
33
- color: $gray-200;
34
-
35
- &:hover,
36
- &:focus,
37
- &:not([aria-disabled="true"]):active {
38
- color: $white;
39
- }
40
- }
@@ -31,6 +31,9 @@ export default function SidebarNavigationScreenMain() {
31
31
  <SidebarNavigationScreen
32
32
  isRoot
33
33
  title={ __( 'Design' ) }
34
+ description={ __(
35
+ 'Customize the appearance of your website using the block editor.'
36
+ ) }
34
37
  content={
35
38
  <ItemGroup>
36
39
  { !! navigationMenus && navigationMenus.length > 0 && (
@@ -2,13 +2,14 @@
2
2
  * WordPress dependencies
3
3
  */
4
4
  import { __ } from '@wordpress/i18n';
5
- import { useDispatch, useSelect } from '@wordpress/data';
5
+ import { useDispatch } from '@wordpress/data';
6
6
  import {
7
- Button,
8
7
  __experimentalUseNavigator as useNavigator,
8
+ ExternalLink,
9
9
  } from '@wordpress/components';
10
- import { store as coreStore } from '@wordpress/core-data';
10
+ import { useEntityRecord } from '@wordpress/core-data';
11
11
  import { decodeEntities } from '@wordpress/html-entities';
12
+ import { pencil } from '@wordpress/icons';
12
13
 
13
14
  /**
14
15
  * Internal dependencies
@@ -16,42 +17,48 @@ import { decodeEntities } from '@wordpress/html-entities';
16
17
  import SidebarNavigationScreen from '../sidebar-navigation-screen';
17
18
  import { unlock } from '../../private-apis';
18
19
  import { store as editSiteStore } from '../../store';
20
+ import SidebarButton from '../sidebar-button';
19
21
 
20
22
  export default function SidebarNavigationScreenNavigationItem() {
21
23
  const { setCanvasMode } = unlock( useDispatch( editSiteStore ) );
22
24
  const {
23
25
  params: { postType, postId },
24
26
  } = useNavigator();
25
-
26
- const { post } = useSelect(
27
- ( select ) => {
28
- const { getEntityRecord } = select( coreStore );
29
-
30
- // The currently selected entity to display.
31
- // Typically template or template part in the site editor.
32
- return {
33
- post:
34
- postId && postType
35
- ? getEntityRecord( 'postType', postType, postId )
36
- : null,
37
- };
38
- },
39
- [ postType, postId ]
40
- );
27
+ const { record } = useEntityRecord( 'postType', postType, postId );
41
28
 
42
29
  return (
43
30
  <SidebarNavigationScreen
44
- title={ post ? decodeEntities( post?.title?.rendered ) : null }
31
+ title={ record ? decodeEntities( record?.title?.rendered ) : null }
45
32
  actions={
46
- <Button
47
- variant="primary"
33
+ <SidebarButton
48
34
  onClick={ () => setCanvasMode( 'edit' ) }
49
- >
50
- { __( 'Edit' ) }
51
- </Button>
35
+ label={ __( 'Edit' ) }
36
+ icon={ pencil }
37
+ />
38
+ }
39
+ description={
40
+ postType === 'page'
41
+ ? __(
42
+ 'Pages are static and are not listed by date. Pages do not use tags or categories.'
43
+ )
44
+ : __(
45
+ 'Posts are entries listed in reverse chronological order on the site homepage or on the posts page.'
46
+ )
52
47
  }
53
48
  content={
54
- post ? decodeEntities( post?.description?.rendered ) : null
49
+ <>
50
+ { record?.link ? (
51
+ <ExternalLink
52
+ className="edit-site-sidebar-navigation-screen__page-link"
53
+ href={ record.link }
54
+ >
55
+ { record.link }
56
+ </ExternalLink>
57
+ ) : null }
58
+ { record
59
+ ? decodeEntities( record?.description?.rendered )
60
+ : null }
61
+ </>
55
62
  }
56
63
  />
57
64
  );
@@ -2,20 +2,93 @@
2
2
  * WordPress dependencies
3
3
  */
4
4
  import { __ } from '@wordpress/i18n';
5
- import { useCallback } from '@wordpress/element';
5
+ import { useCallback, useMemo } from '@wordpress/element';
6
+ import { useSelect } from '@wordpress/data';
7
+ import { store as coreStore } from '@wordpress/core-data';
8
+ import {
9
+ BlockEditorProvider,
10
+ privateApis as blockEditorPrivateApis,
11
+ } from '@wordpress/block-editor';
12
+ import { createBlock } from '@wordpress/blocks';
6
13
 
7
14
  /**
8
15
  * Internal dependencies
9
16
  */
10
17
  import SidebarNavigationScreen from '../sidebar-navigation-screen';
11
- import NavigationInspector from '../navigation-inspector';
12
18
  import { useHistory } from '../routes';
19
+ import NavigationMenuContent from './navigation-menu-content';
20
+ import SidebarButton from '../sidebar-button';
21
+ import { NavigationMenuLoader } from './loader';
22
+ import { unlock } from '../../private-apis';
23
+ import { store as editSiteStore } from '../../store';
24
+
25
+ const noop = () => {};
26
+ const NAVIGATION_MENUS_QUERY = { per_page: -1, status: 'publish' };
27
+
28
+ function SidebarNavigationScreenWrapper( { children, actions } ) {
29
+ return (
30
+ <SidebarNavigationScreen
31
+ title={ __( 'Navigation' ) }
32
+ actions={ actions }
33
+ description={ __(
34
+ 'Browse your site, edit pages, and manage your primary navigation menu.'
35
+ ) }
36
+ content={ children }
37
+ />
38
+ );
39
+ }
40
+
41
+ const prioritizedInserterBlocks = [
42
+ 'core/navigation-link/page',
43
+ 'core/navigation-link',
44
+ ];
13
45
 
14
46
  export default function SidebarNavigationScreenNavigationMenus() {
15
47
  const history = useHistory();
48
+ const { navigationMenus, hasResolvedNavigationMenus, storedSettings } =
49
+ useSelect( ( select ) => {
50
+ const { getSettings } = unlock( select( editSiteStore ) );
51
+ const { getEntityRecords, hasFinishedResolution } =
52
+ select( coreStore );
53
+
54
+ const navigationMenusQuery = [
55
+ 'postType',
56
+ 'wp_navigation',
57
+ NAVIGATION_MENUS_QUERY,
58
+ ];
59
+ return {
60
+ storedSettings: getSettings( false ),
61
+ navigationMenus: getEntityRecords( ...navigationMenusQuery ),
62
+ hasResolvedNavigationMenus: hasFinishedResolution(
63
+ 'getEntityRecords',
64
+ navigationMenusQuery
65
+ ),
66
+ };
67
+ }, [] );
68
+
69
+ // Sort navigation menus by date.
70
+ const orderedNavigationMenus = useMemo(
71
+ () =>
72
+ navigationMenus?.sort( ( menuA, menuB ) => {
73
+ const menuADate = new Date( menuA.date );
74
+ const menuBDate = new Date( menuB.date );
75
+ return menuADate.getTime() > menuBDate.getTime();
76
+ } ),
77
+ [ navigationMenus ]
78
+ );
79
+ const firstNavigationMenu = orderedNavigationMenus?.[ 0 ]?.id;
80
+ const blocks = useMemo( () => {
81
+ return [
82
+ createBlock( 'core/navigation', { ref: firstNavigationMenu } ),
83
+ ];
84
+ }, [ firstNavigationMenu ] );
85
+
86
+ const isLoading = ! hasResolvedNavigationMenus;
87
+ const hasNavigationMenus = !! navigationMenus?.length;
88
+
16
89
  const onSelect = useCallback(
17
90
  ( selectedBlock ) => {
18
- const { attributes } = selectedBlock;
91
+ const { attributes, name } = selectedBlock;
19
92
  if (
20
93
  attributes.kind === 'post-type' &&
21
94
  attributes.id &&
@@ -27,17 +100,75 @@ export default function SidebarNavigationScreenNavigationMenus() {
27
100
  postId: attributes.id,
28
101
  } );
29
102
  }
103
+ if ( name === 'core/page-list-item' && attributes.id && history ) {
104
+ history.push( {
105
+ postType: 'page',
106
+ postId: attributes.id,
107
+ } );
108
+ }
30
109
  },
31
110
  [ history ]
32
111
  );
112
+ const orderInitialBlockItems = useCallback( ( items ) => {
113
+ items.sort( ( { id: aName }, { id: bName } ) => {
114
+ // Sort block items according to `prioritizedInserterBlocks`.
115
+ let aIndex = prioritizedInserterBlocks.indexOf( aName );
116
+ let bIndex = prioritizedInserterBlocks.indexOf( bName );
117
+ // All other block items should come after that.
118
+ if ( aIndex < 0 ) aIndex = prioritizedInserterBlocks.length;
119
+ if ( bIndex < 0 ) bIndex = prioritizedInserterBlocks.length;
120
+ return aIndex - bIndex;
121
+ } );
122
+ return items;
123
+ }, [] );
124
+
125
+ if ( hasResolvedNavigationMenus && ! hasNavigationMenus ) {
126
+ return (
127
+ <SidebarNavigationScreenWrapper>
128
+ { __( 'There are no Navigation Menus.' ) }
129
+ </SidebarNavigationScreenWrapper>
130
+ );
131
+ }
132
+
133
+ if ( ! hasResolvedNavigationMenus || isLoading ) {
134
+ return (
135
+ <SidebarNavigationScreenWrapper>
136
+ <NavigationMenuLoader />
137
+ </SidebarNavigationScreenWrapper>
138
+ );
139
+ }
140
+ const { PrivateInserter } = unlock( blockEditorPrivateApis );
33
141
  return (
34
- <SidebarNavigationScreen
35
- title={ __( 'Navigation' ) }
36
- content={
37
- <div className="edit-site-sidebar-navigation-screen-navigation-menus">
38
- <NavigationInspector onSelect={ onSelect } />
142
+ <BlockEditorProvider
143
+ settings={ storedSettings }
144
+ value={ blocks }
145
+ onChange={ noop }
146
+ onInput={ noop }
147
+ >
148
+ <SidebarNavigationScreenWrapper
149
+ actions={
150
+ <PrivateInserter
151
+ rootClientId={ blocks[ 0 ].clientId }
152
+ position="bottom right"
153
+ isAppender
154
+ selectBlockOnInsert={ false }
155
+ shouldDirectInsert={ false }
156
+ __experimentalIsQuick
157
+ toggleProps={ {
158
+ as: SidebarButton,
159
+ label: __( 'Add menu item' ),
160
+ } }
161
+ orderInitialBlockItems={ orderInitialBlockItems }
162
+ />
163
+ }
164
+ >
165
+ <div className="edit-site-sidebar-navigation-screen-navigation-menus__content">
166
+ <NavigationMenuContent
167
+ rootClientId={ blocks[ 0 ].clientId }
168
+ onSelect={ onSelect }
169
+ />
39
170
  </div>
40
- }
41
- />
171
+ </SidebarNavigationScreenWrapper>
172
+ </BlockEditorProvider>
42
173
  );
43
174
  }
@@ -0,0 +1,9 @@
1
+ export function NavigationMenuLoader() {
2
+ return (
3
+ <>
4
+ <div className="edit-site-sidebar-navigation-screen-navigation-menus__placeholder" />
5
+ <div className="edit-site-sidebar-navigation-screen-navigation-menus__placeholder" />
6
+ <div className="edit-site-sidebar-navigation-screen-navigation-menus__placeholder" />
7
+ </>
8
+ );
9
+ }
@@ -0,0 +1,78 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import {
5
+ privateApis as blockEditorPrivateApis,
6
+ store as blockEditorStore,
7
+ BlockList,
8
+ BlockTools,
9
+ } from '@wordpress/block-editor';
10
+ import { useDispatch, useSelect } from '@wordpress/data';
11
+ import { createBlock } from '@wordpress/blocks';
12
+ import { useCallback } from '@wordpress/element';
13
+
14
+ /**
15
+ * Internal dependencies
16
+ */
17
+ import { unlock } from '../../private-apis';
18
+ import { NavigationMenuLoader } from './loader';
19
+
20
+ export default function NavigationMenuContent( { rootClientId, onSelect } ) {
21
+ const { clientIdsTree, isLoading } = useSelect(
22
+ ( select ) => {
23
+ const { __unstableGetClientIdsTree, areInnerBlocksControlled } =
24
+ select( blockEditorStore );
25
+ return {
26
+ clientIdsTree: __unstableGetClientIdsTree( rootClientId ),
27
+
28
+ // This is a small hack to wait for the navigation block
29
+ // to actually load its inner blocks.
30
+ isLoading: ! areInnerBlocksControlled( rootClientId ),
31
+ };
32
+ },
33
+ [ rootClientId ]
34
+ );
35
+ const { replaceBlock, __unstableMarkNextChangeAsNotPersistent } =
36
+ useDispatch( blockEditorStore );
37
+
38
+ const { OffCanvasEditor, LeafMoreMenu } = unlock( blockEditorPrivateApis );
39
+
40
+ const offCanvasOnselect = useCallback(
41
+ ( block ) => {
42
+ if (
43
+ block.name === 'core/navigation-link' &&
44
+ ! block.attributes.url
45
+ ) {
46
+ __unstableMarkNextChangeAsNotPersistent();
47
+ replaceBlock(
48
+ block.clientId,
49
+ createBlock( 'core/navigation-link', block.attributes )
50
+ );
51
+ } else {
52
+ onSelect( block );
53
+ }
54
+ },
55
+ [ onSelect, __unstableMarkNextChangeAsNotPersistent, replaceBlock ]
56
+ );
57
+
58
+ // The hidden block is needed because it makes block edit side effects trigger.
59
+ // For example a navigation page list load its items has an effect on edit to load its items.
60
+ return (
61
+ <>
62
+ { isLoading && <NavigationMenuLoader /> }
63
+ { ! isLoading && (
64
+ <OffCanvasEditor
65
+ blocks={ clientIdsTree }
66
+ onSelect={ offCanvasOnselect }
67
+ LeafMoreMenu={ LeafMoreMenu }
68
+ showAppender={ false }
69
+ />
70
+ ) }
71
+ <div style={ { visibility: 'hidden' } }>
72
+ <BlockTools>
73
+ <BlockList />
74
+ </BlockTools>
75
+ </div>
76
+ </>
77
+ );
78
+ }
@@ -1,12 +1,63 @@
1
- .edit-site-sidebar-navigation-screen-navigation-menus {
2
- .block-editor-list-view-block__menu-edit,
3
- .edit-site-navigation-inspector__select-menu {
4
- display: none;
1
+ .edit-site-sidebar-navigation-screen__description {
2
+ margin: 0 0 $grid-unit-40 $grid-unit-20;
3
+ }
4
+
5
+ .edit-site-sidebar-navigation-screen-navigation-menus__placeholder {
6
+ padding: $grid-unit-10;
7
+ margin: $grid-unit-10;
8
+ background-color: $gray-100;
9
+ animation: loadingpulse 1s linear infinite;
10
+ animation-delay: 0.5s; // avoid animating for fast network responses
11
+ }
12
+
13
+ @keyframes loadingpulse {
14
+ 0% {
15
+ opacity: 1;
16
+ }
17
+ 50% {
18
+ opacity: 0.5;
5
19
  }
20
+ 100% {
21
+ opacity: 1;
22
+ }
23
+ }
24
+
25
+ .edit-site-sidebar-navigation-screen-navigation-menus__content {
6
26
  .offcanvas-editor-list-view-leaf {
7
27
  max-width: calc(100% - #{ $grid-unit-05 });
28
+ border-radius: $radius-block-ui;
29
+ &:hover,
30
+ &:focus,
31
+ &[aria-current] {
32
+ background: $gray-800;
33
+ }
34
+ .block-editor-list-view-block__menu {
35
+ margin-left: -$grid-unit-10;
36
+ }
8
37
  }
38
+
9
39
  .block-editor-list-view-leaf .block-editor-list-view-block__contents-cell {
10
40
  width: 100%;
11
41
  }
42
+
43
+ .block-editor-list-view-leaf .block-editor-list-view-block-contents {
44
+ white-space: normal;
45
+ }
46
+
47
+ .block-editor-list-view-block__title {
48
+ margin-top: 3px;
49
+ }
50
+
51
+ .block-editor-list-view-block__menu-cell {
52
+ padding-right: 0;
53
+ }
54
+
55
+ .components-button {
56
+ color: $gray-600;
57
+ &:hover,
58
+ &:focus,
59
+ &[aria-current] {
60
+ color: $white;
61
+ }
62
+ }
12
63
  }
@@ -1,9 +1,10 @@
1
1
  /**
2
2
  * WordPress dependencies
3
3
  */
4
- import { __ } from '@wordpress/i18n';
4
+ import { __, sprintf } from '@wordpress/i18n';
5
5
  import { useDispatch } from '@wordpress/data';
6
- import { Button } from '@wordpress/components';
6
+ import { pencil } from '@wordpress/icons';
7
+ import { __experimentalUseNavigator as useNavigator } from '@wordpress/components';
7
8
 
8
9
  /**
9
10
  * Internal dependencies
@@ -12,29 +13,42 @@ import SidebarNavigationScreen from '../sidebar-navigation-screen';
12
13
  import useEditedEntityRecord from '../use-edited-entity-record';
13
14
  import { unlock } from '../../private-apis';
14
15
  import { store as editSiteStore } from '../../store';
16
+ import SidebarButton from '../sidebar-button';
15
17
 
16
18
  export default function SidebarNavigationScreenTemplate() {
19
+ const { params } = useNavigator();
20
+ const { postType, postId } = params;
17
21
  const { setCanvasMode } = unlock( useDispatch( editSiteStore ) );
18
- const { getDescription, getTitle, record } = useEditedEntityRecord();
22
+ const { getDescription, getTitle, record } = useEditedEntityRecord(
23
+ postType,
24
+ postId
25
+ );
19
26
  let description = getDescription();
20
- if ( ! description && record.is_custom ) {
21
- description = __(
22
- 'This is a custom template that can be applied manually to any Post or Page.'
23
- );
27
+ if ( ! description ) {
28
+ if ( record.type === 'wp_template' && record.is_custom ) {
29
+ description = __(
30
+ 'This is a custom template that can be applied manually to any Post or Page.'
31
+ );
32
+ } else if ( record.type === 'wp_template_part' ) {
33
+ description = sprintf(
34
+ // translators: %s: template part title e.g: "Header".
35
+ __( 'This is your %s template part.' ),
36
+ getTitle()
37
+ );
38
+ }
24
39
  }
25
40
 
26
41
  return (
27
42
  <SidebarNavigationScreen
28
43
  title={ getTitle() }
29
44
  actions={
30
- <Button
31
- variant="primary"
45
+ <SidebarButton
32
46
  onClick={ () => setCanvasMode( 'edit' ) }
33
- >
34
- { __( 'Edit' ) }
35
- </Button>
47
+ label={ __( 'Edit' ) }
48
+ icon={ pencil }
49
+ />
36
50
  }
37
- content={ description ? <p>{ description }</p> : undefined }
51
+ description={ description }
38
52
  />
39
53
  );
40
54
  }