@wordpress/edit-site 5.10.0 → 5.11.0

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 (252) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/build/components/add-new-template/{add-custom-generic-template-modal.js → add-custom-generic-template-modal-content.js} +7 -22
  3. package/build/components/add-new-template/add-custom-generic-template-modal-content.js.map +1 -0
  4. package/build/components/add-new-template/{add-custom-template-modal.js → add-custom-template-modal-content.js} +11 -21
  5. package/build/components/add-new-template/add-custom-template-modal-content.js.map +1 -0
  6. package/build/components/add-new-template/new-template.js +98 -65
  7. package/build/components/add-new-template/new-template.js.map +1 -1
  8. package/build/components/block-editor/index.js +1 -3
  9. package/build/components/block-editor/index.js.map +1 -1
  10. package/build/components/create-template-part-modal/index.js +6 -7
  11. package/build/components/create-template-part-modal/index.js.map +1 -1
  12. package/build/components/editor/index.js +15 -40
  13. package/build/components/editor/index.js.map +1 -1
  14. package/build/components/editor-canvas-container/index.js +10 -3
  15. package/build/components/editor-canvas-container/index.js.map +1 -1
  16. package/build/components/global-styles/screen-block.js +80 -3
  17. package/build/components/global-styles/screen-block.js.map +1 -1
  18. package/build/components/global-styles/screen-revisions/index.js +3 -10
  19. package/build/components/global-styles/screen-revisions/index.js.map +1 -1
  20. package/build/components/global-styles/screen-revisions/revisions-buttons.js +16 -18
  21. package/build/components/global-styles/screen-revisions/revisions-buttons.js.map +1 -1
  22. package/build/components/global-styles/screen-revisions/use-global-styles-revisions.js +15 -24
  23. package/build/components/global-styles/screen-revisions/use-global-styles-revisions.js.map +1 -1
  24. package/build/components/global-styles/screen-root.js +4 -4
  25. package/build/components/global-styles/screen-root.js.map +1 -1
  26. package/build/components/global-styles/style-variations-container.js +6 -10
  27. package/build/components/global-styles/style-variations-container.js.map +1 -1
  28. package/build/components/global-styles/ui.js +9 -9
  29. package/build/components/global-styles/ui.js.map +1 -1
  30. package/build/components/header-edit-mode/document-actions/index.js +28 -103
  31. package/build/components/header-edit-mode/document-actions/index.js.map +1 -1
  32. package/build/components/header-edit-mode/index.js +14 -1
  33. package/build/components/header-edit-mode/index.js.map +1 -1
  34. package/build/components/layout/hooks.js +54 -0
  35. package/build/components/layout/hooks.js.map +1 -0
  36. package/build/components/layout/index.js +45 -98
  37. package/build/components/layout/index.js.map +1 -1
  38. package/build/components/list/actions/index.js +5 -2
  39. package/build/components/list/actions/index.js.map +1 -1
  40. package/build/components/resizable-frame/index.js +242 -0
  41. package/build/components/resizable-frame/index.js.map +1 -0
  42. package/build/components/revisions/index.js +2 -1
  43. package/build/components/revisions/index.js.map +1 -1
  44. package/build/components/secondary-sidebar/list-view-sidebar.js +4 -3
  45. package/build/components/secondary-sidebar/list-view-sidebar.js.map +1 -1
  46. package/build/components/sidebar/index.js +4 -4
  47. package/build/components/sidebar/index.js.map +1 -1
  48. package/build/components/sidebar-edit-mode/template-revisions/index.js +1 -1
  49. package/build/components/sidebar-edit-mode/template-revisions/index.js.map +1 -1
  50. package/build/components/sidebar-navigation-screen-global-styles/index.js +75 -11
  51. package/build/components/sidebar-navigation-screen-global-styles/index.js.map +1 -1
  52. package/build/components/sidebar-navigation-screen-main/index.js +24 -33
  53. package/build/components/sidebar-navigation-screen-main/index.js.map +1 -1
  54. package/build/components/sidebar-navigation-screen-navigation-menu/index.js +162 -0
  55. package/build/components/sidebar-navigation-screen-navigation-menu/index.js.map +1 -0
  56. package/build/components/sidebar-navigation-screen-navigation-menus/constants.js +17 -0
  57. package/build/components/sidebar-navigation-screen-navigation-menus/constants.js.map +1 -0
  58. package/build/components/sidebar-navigation-screen-navigation-menus/index.js +53 -103
  59. package/build/components/sidebar-navigation-screen-navigation-menus/index.js.map +1 -1
  60. package/build/components/sidebar-navigation-screen-navigation-menus/leaf-more-menu.js +87 -0
  61. package/build/components/sidebar-navigation-screen-navigation-menus/leaf-more-menu.js.map +1 -0
  62. package/build/components/sidebar-navigation-screen-navigation-menus/navigation-menu-content.js +14 -71
  63. package/build/components/sidebar-navigation-screen-navigation-menus/navigation-menu-content.js.map +1 -1
  64. package/build/components/sidebar-navigation-screen-navigation-menus/navigator-button.js +53 -0
  65. package/build/components/sidebar-navigation-screen-navigation-menus/navigator-button.js.map +1 -0
  66. package/build/components/sidebar-navigation-screen-templates/index.js +36 -11
  67. package/build/components/sidebar-navigation-screen-templates/index.js.map +1 -1
  68. package/build/components/site-hub/index.js +1 -3
  69. package/build/components/site-hub/index.js.map +1 -1
  70. package/build/components/style-book/index.js +93 -19
  71. package/build/components/style-book/index.js.map +1 -1
  72. package/build/components/use-edited-entity-record/index.js +8 -4
  73. package/build/components/use-edited-entity-record/index.js.map +1 -1
  74. package/build/hooks/commands/use-edit-mode-commands.js +105 -0
  75. package/build/hooks/commands/use-edit-mode-commands.js.map +1 -0
  76. package/build/store/actions.js +5 -3
  77. package/build/store/actions.js.map +1 -1
  78. package/build-module/components/add-new-template/{add-custom-generic-template-modal.js → add-custom-generic-template-modal-content.js} +8 -20
  79. package/build-module/components/add-new-template/add-custom-generic-template-modal-content.js.map +1 -0
  80. package/build-module/components/add-new-template/{add-custom-template-modal.js → add-custom-template-modal-content.js} +13 -22
  81. package/build-module/components/add-new-template/add-custom-template-modal-content.js.map +1 -0
  82. package/build-module/components/add-new-template/new-template.js +98 -67
  83. package/build-module/components/add-new-template/new-template.js.map +1 -1
  84. package/build-module/components/block-editor/index.js +1 -3
  85. package/build-module/components/block-editor/index.js.map +1 -1
  86. package/build-module/components/create-template-part-modal/index.js +7 -8
  87. package/build-module/components/create-template-part-modal/index.js.map +1 -1
  88. package/build-module/components/editor/index.js +16 -43
  89. package/build-module/components/editor/index.js.map +1 -1
  90. package/build-module/components/editor-canvas-container/index.js +7 -3
  91. package/build-module/components/editor-canvas-container/index.js.map +1 -1
  92. package/build-module/components/global-styles/screen-block.js +82 -4
  93. package/build-module/components/global-styles/screen-block.js.map +1 -1
  94. package/build-module/components/global-styles/screen-revisions/index.js +3 -10
  95. package/build-module/components/global-styles/screen-revisions/index.js.map +1 -1
  96. package/build-module/components/global-styles/screen-revisions/revisions-buttons.js +16 -19
  97. package/build-module/components/global-styles/screen-revisions/revisions-buttons.js.map +1 -1
  98. package/build-module/components/global-styles/screen-revisions/use-global-styles-revisions.js +15 -24
  99. package/build-module/components/global-styles/screen-revisions/use-global-styles-revisions.js.map +1 -1
  100. package/build-module/components/global-styles/screen-root.js +4 -4
  101. package/build-module/components/global-styles/screen-root.js.map +1 -1
  102. package/build-module/components/global-styles/style-variations-container.js +7 -11
  103. package/build-module/components/global-styles/style-variations-container.js.map +1 -1
  104. package/build-module/components/global-styles/ui.js +10 -10
  105. package/build-module/components/global-styles/ui.js.map +1 -1
  106. package/build-module/components/header-edit-mode/document-actions/index.js +31 -107
  107. package/build-module/components/header-edit-mode/document-actions/index.js.map +1 -1
  108. package/build-module/components/header-edit-mode/index.js +14 -2
  109. package/build-module/components/header-edit-mode/index.js.map +1 -1
  110. package/build-module/components/layout/hooks.js +41 -0
  111. package/build-module/components/layout/hooks.js.map +1 -0
  112. package/build-module/components/layout/index.js +46 -101
  113. package/build-module/components/layout/index.js.map +1 -1
  114. package/build-module/components/list/actions/index.js +6 -3
  115. package/build-module/components/list/actions/index.js.map +1 -1
  116. package/build-module/components/resizable-frame/index.js +228 -0
  117. package/build-module/components/resizable-frame/index.js.map +1 -0
  118. package/build-module/components/revisions/index.js +2 -1
  119. package/build-module/components/revisions/index.js.map +1 -1
  120. package/build-module/components/secondary-sidebar/list-view-sidebar.js +3 -3
  121. package/build-module/components/secondary-sidebar/list-view-sidebar.js.map +1 -1
  122. package/build-module/components/sidebar/index.js +3 -3
  123. package/build-module/components/sidebar/index.js.map +1 -1
  124. package/build-module/components/sidebar-edit-mode/template-revisions/index.js +1 -1
  125. package/build-module/components/sidebar-edit-mode/template-revisions/index.js.map +1 -1
  126. package/build-module/components/sidebar-navigation-screen-global-styles/index.js +70 -14
  127. package/build-module/components/sidebar-navigation-screen-global-styles/index.js.map +1 -1
  128. package/build-module/components/sidebar-navigation-screen-main/index.js +21 -32
  129. package/build-module/components/sidebar-navigation-screen-main/index.js.map +1 -1
  130. package/build-module/components/sidebar-navigation-screen-navigation-menu/index.js +141 -0
  131. package/build-module/components/sidebar-navigation-screen-navigation-menu/index.js.map +1 -0
  132. package/build-module/components/sidebar-navigation-screen-navigation-menus/constants.js +10 -0
  133. package/build-module/components/sidebar-navigation-screen-navigation-menus/constants.js.map +1 -0
  134. package/build-module/components/sidebar-navigation-screen-navigation-menus/index.js +52 -103
  135. package/build-module/components/sidebar-navigation-screen-navigation-menus/index.js.map +1 -1
  136. package/build-module/components/sidebar-navigation-screen-navigation-menus/leaf-more-menu.js +71 -0
  137. package/build-module/components/sidebar-navigation-screen-navigation-menus/leaf-more-menu.js.map +1 -0
  138. package/build-module/components/sidebar-navigation-screen-navigation-menus/navigation-menu-content.js +12 -71
  139. package/build-module/components/sidebar-navigation-screen-navigation-menus/navigation-menu-content.js.map +1 -1
  140. package/build-module/components/sidebar-navigation-screen-navigation-menus/navigator-button.js +40 -0
  141. package/build-module/components/sidebar-navigation-screen-navigation-menus/navigator-button.js.map +1 -0
  142. package/build-module/components/sidebar-navigation-screen-templates/index.js +35 -11
  143. package/build-module/components/sidebar-navigation-screen-templates/index.js.map +1 -1
  144. package/build-module/components/site-hub/index.js +1 -3
  145. package/build-module/components/site-hub/index.js.map +1 -1
  146. package/build-module/components/style-book/index.js +93 -20
  147. package/build-module/components/style-book/index.js.map +1 -1
  148. package/build-module/components/use-edited-entity-record/index.js +8 -4
  149. package/build-module/components/use-edited-entity-record/index.js.map +1 -1
  150. package/build-module/hooks/commands/use-edit-mode-commands.js +86 -0
  151. package/build-module/hooks/commands/use-edit-mode-commands.js.map +1 -0
  152. package/build-module/store/actions.js +5 -3
  153. package/build-module/store/actions.js.map +1 -1
  154. package/build-style/style-rtl.css +233 -210
  155. package/build-style/style.css +234 -210
  156. package/package.json +37 -37
  157. package/src/components/add-new-template/add-custom-generic-template-modal-content.js +82 -0
  158. package/src/components/add-new-template/{add-custom-template-modal.js → add-custom-template-modal-content.js} +13 -26
  159. package/src/components/add-new-template/new-template.js +139 -153
  160. package/src/components/add-new-template/style.scss +79 -66
  161. package/src/components/block-editor/index.js +2 -3
  162. package/src/components/create-template-part-modal/index.js +19 -25
  163. package/src/components/editor/index.js +16 -45
  164. package/src/components/editor/style.scss +21 -6
  165. package/src/components/editor-canvas-container/index.js +28 -19
  166. package/src/components/global-styles/screen-block.js +74 -3
  167. package/src/components/global-styles/screen-revisions/index.js +3 -11
  168. package/src/components/global-styles/screen-revisions/revisions-buttons.js +33 -25
  169. package/src/components/global-styles/screen-revisions/style.scss +3 -2
  170. package/src/components/global-styles/screen-revisions/test/use-global-styles-revisions.js +16 -3
  171. package/src/components/global-styles/screen-revisions/use-global-styles-revisions.js +15 -19
  172. package/src/components/global-styles/screen-root.js +5 -3
  173. package/src/components/global-styles/style-variations-container.js +13 -18
  174. package/src/components/global-styles/style.scss +3 -0
  175. package/src/components/global-styles/ui.js +11 -9
  176. package/src/components/header-edit-mode/document-actions/index.js +26 -129
  177. package/src/components/header-edit-mode/document-actions/style.scss +28 -59
  178. package/src/components/header-edit-mode/index.js +18 -0
  179. package/src/components/header-edit-mode/style.scss +1 -0
  180. package/src/components/layout/hooks.js +46 -0
  181. package/src/components/layout/index.js +56 -125
  182. package/src/components/layout/style.scss +8 -2
  183. package/src/components/list/actions/index.js +12 -5
  184. package/src/components/list/style.scss +1 -0
  185. package/src/components/resizable-frame/index.js +253 -0
  186. package/src/components/resizable-frame/style.scss +69 -0
  187. package/src/components/revisions/index.js +1 -0
  188. package/src/components/secondary-sidebar/list-view-sidebar.js +2 -1
  189. package/src/components/sidebar/index.js +4 -4
  190. package/src/components/sidebar-edit-mode/template-revisions/index.js +1 -2
  191. package/src/components/sidebar-navigation-item/style.scss +9 -0
  192. package/src/components/sidebar-navigation-screen/style.scss +1 -2
  193. package/src/components/sidebar-navigation-screen-global-styles/index.js +106 -21
  194. package/src/components/sidebar-navigation-screen-main/index.js +35 -52
  195. package/src/components/sidebar-navigation-screen-navigation-menu/index.js +157 -0
  196. package/src/components/sidebar-navigation-screen-navigation-menus/constants.js +9 -0
  197. package/src/components/sidebar-navigation-screen-navigation-menus/index.js +63 -117
  198. package/src/components/sidebar-navigation-screen-navigation-menus/leaf-more-menu.js +83 -0
  199. package/src/components/sidebar-navigation-screen-navigation-menus/navigation-menu-content.js +6 -72
  200. package/src/components/sidebar-navigation-screen-navigation-menus/navigator-button.js +47 -0
  201. package/src/components/sidebar-navigation-screen-navigation-menus/style.scss +6 -20
  202. package/src/components/sidebar-navigation-screen-templates/index.js +53 -14
  203. package/src/components/site-hub/index.js +8 -9
  204. package/src/components/start-template-options/style.scss +20 -21
  205. package/src/components/style-book/index.js +132 -43
  206. package/src/components/style-book/style.scss +19 -0
  207. package/src/components/use-edited-entity-record/index.js +12 -3
  208. package/src/hooks/commands/use-edit-mode-commands.js +79 -0
  209. package/src/store/actions.js +4 -5
  210. package/src/store/test/utils.js +15 -5
  211. package/src/style.scss +1 -1
  212. package/build/components/add-new-template/add-custom-generic-template-modal.js.map +0 -1
  213. package/build/components/add-new-template/add-custom-template-modal.js.map +0 -1
  214. package/build/components/global-styles/border-panel.js +0 -135
  215. package/build/components/global-styles/border-panel.js.map +0 -1
  216. package/build/components/navigate-to-link/index.js +0 -51
  217. package/build/components/navigate-to-link/index.js.map +0 -1
  218. package/build/components/sidebar-navigation-screen-navigation-menus/loader.js +0 -19
  219. package/build/components/sidebar-navigation-screen-navigation-menus/loader.js.map +0 -1
  220. package/build/components/template-details/edit-template-title.js +0 -42
  221. package/build/components/template-details/edit-template-title.js.map +0 -1
  222. package/build/components/template-details/index.js +0 -103
  223. package/build/components/template-details/index.js.map +0 -1
  224. package/build/components/template-details/template-areas.js +0 -166
  225. package/build/components/template-details/template-areas.js.map +0 -1
  226. package/build/components/template-details/template-part-area-selector.js +0 -48
  227. package/build/components/template-details/template-part-area-selector.js.map +0 -1
  228. package/build-module/components/add-new-template/add-custom-generic-template-modal.js.map +0 -1
  229. package/build-module/components/add-new-template/add-custom-template-modal.js.map +0 -1
  230. package/build-module/components/global-styles/border-panel.js +0 -125
  231. package/build-module/components/global-styles/border-panel.js.map +0 -1
  232. package/build-module/components/navigate-to-link/index.js +0 -39
  233. package/build-module/components/navigate-to-link/index.js.map +0 -1
  234. package/build-module/components/sidebar-navigation-screen-navigation-menus/loader.js +0 -11
  235. package/build-module/components/sidebar-navigation-screen-navigation-menus/loader.js.map +0 -1
  236. package/build-module/components/template-details/edit-template-title.js +0 -33
  237. package/build-module/components/template-details/edit-template-title.js.map +0 -1
  238. package/build-module/components/template-details/index.js +0 -83
  239. package/build-module/components/template-details/index.js.map +0 -1
  240. package/build-module/components/template-details/template-areas.js +0 -145
  241. package/build-module/components/template-details/template-areas.js.map +0 -1
  242. package/build-module/components/template-details/template-part-area-selector.js +0 -36
  243. package/build-module/components/template-details/template-part-area-selector.js.map +0 -1
  244. package/src/components/add-new-template/add-custom-generic-template-modal.js +0 -101
  245. package/src/components/global-styles/border-panel.js +0 -114
  246. package/src/components/navigate-to-link/index.js +0 -46
  247. package/src/components/sidebar-navigation-screen-navigation-menus/loader.js +0 -9
  248. package/src/components/template-details/edit-template-title.js +0 -41
  249. package/src/components/template-details/index.js +0 -113
  250. package/src/components/template-details/style.scss +0 -72
  251. package/src/components/template-details/template-areas.js +0 -167
  252. package/src/components/template-details/template-part-area-selector.js +0 -39
@@ -0,0 +1,157 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import { useEntityRecord } from '@wordpress/core-data';
5
+ import {
6
+ __experimentalUseNavigator as useNavigator,
7
+ Spinner,
8
+ } from '@wordpress/components';
9
+ import { __ } from '@wordpress/i18n';
10
+ import { useCallback, useMemo } from '@wordpress/element';
11
+ import { useSelect } from '@wordpress/data';
12
+ import { privateApis as routerPrivateApis } from '@wordpress/router';
13
+ import { BlockEditorProvider } from '@wordpress/block-editor';
14
+ import { createBlock } from '@wordpress/blocks';
15
+ import { decodeEntities } from '@wordpress/html-entities';
16
+
17
+ /**
18
+ * Internal dependencies
19
+ */
20
+ import { unlock } from '../../private-apis';
21
+ import { store as editSiteStore } from '../../store';
22
+ import {
23
+ isPreviewingTheme,
24
+ currentlyPreviewingTheme,
25
+ } from '../../utils/is-previewing-theme';
26
+ import { SidebarNavigationScreenWrapper } from '../sidebar-navigation-screen-navigation-menus';
27
+ import NavigationMenuContent from '../sidebar-navigation-screen-navigation-menus/navigation-menu-content';
28
+
29
+ const { useHistory } = unlock( routerPrivateApis );
30
+ const noop = () => {};
31
+
32
+ export default function SidebarNavigationScreenNavigationMenu() {
33
+ const postType = `wp_navigation`;
34
+ const {
35
+ params: { postId },
36
+ } = useNavigator();
37
+
38
+ const { record: navigationMenu, isResolving: isLoading } = useEntityRecord(
39
+ 'postType',
40
+ postType,
41
+ postId
42
+ );
43
+
44
+ const menuTitle = navigationMenu?.title?.rendered || navigationMenu?.slug;
45
+
46
+ if ( isLoading ) {
47
+ return (
48
+ <SidebarNavigationScreenWrapper
49
+ description={ __(
50
+ 'Navigation menus are a curated collection of blocks that allow visitors to get around your site.'
51
+ ) }
52
+ >
53
+ <Spinner className="edit-site-sidebar-navigation-screen-navigation-menus__loading" />
54
+ </SidebarNavigationScreenWrapper>
55
+ );
56
+ }
57
+
58
+ if ( ! isLoading && ! navigationMenu ) {
59
+ return (
60
+ <SidebarNavigationScreenWrapper
61
+ description={ __( 'Navigation Menu missing.' ) }
62
+ />
63
+ );
64
+ }
65
+
66
+ if ( ! navigationMenu?.content?.raw ) {
67
+ return (
68
+ <SidebarNavigationScreenWrapper
69
+ title={ decodeEntities( menuTitle ) }
70
+ description={ __( 'This Navigation Menu is empty.' ) }
71
+ />
72
+ );
73
+ }
74
+
75
+ return (
76
+ <SidebarNavigationScreenWrapper
77
+ title={ decodeEntities( menuTitle ) }
78
+ description={ __(
79
+ 'Navigation menus are a curated collection of blocks that allow visitors to get around your site.'
80
+ ) }
81
+ >
82
+ <NavigationMenuEditor navigationMenu={ navigationMenu } />
83
+ </SidebarNavigationScreenWrapper>
84
+ );
85
+ }
86
+
87
+ function NavigationMenuEditor( { navigationMenu } ) {
88
+ const history = useHistory();
89
+
90
+ const onSelect = useCallback(
91
+ ( selectedBlock ) => {
92
+ const { attributes, name } = selectedBlock;
93
+ if (
94
+ attributes.kind === 'post-type' &&
95
+ attributes.id &&
96
+ attributes.type &&
97
+ history
98
+ ) {
99
+ history.push( {
100
+ postType: attributes.type,
101
+ postId: attributes.id,
102
+ ...( isPreviewingTheme() && {
103
+ theme_preview: currentlyPreviewingTheme(),
104
+ } ),
105
+ } );
106
+ }
107
+ if ( name === 'core/page-list-item' && attributes.id && history ) {
108
+ history.push( {
109
+ postType: 'page',
110
+ postId: attributes.id,
111
+ ...( isPreviewingTheme() && {
112
+ theme_preview: currentlyPreviewingTheme(),
113
+ } ),
114
+ } );
115
+ }
116
+ },
117
+ [ history ]
118
+ );
119
+
120
+ const { storedSettings } = useSelect( ( select ) => {
121
+ const { getSettings } = unlock( select( editSiteStore ) );
122
+
123
+ return {
124
+ storedSettings: getSettings( false ),
125
+ };
126
+ }, [] );
127
+
128
+ const blocks = useMemo( () => {
129
+ if ( ! NavigationMenuEditor ) {
130
+ return [];
131
+ }
132
+
133
+ return [
134
+ createBlock( 'core/navigation', { ref: navigationMenu?.id } ),
135
+ ];
136
+ }, [ navigationMenu ] );
137
+
138
+ if ( ! navigationMenu || ! blocks?.length ) {
139
+ return null;
140
+ }
141
+
142
+ return (
143
+ <BlockEditorProvider
144
+ settings={ storedSettings }
145
+ value={ blocks }
146
+ onChange={ noop }
147
+ onInput={ noop }
148
+ >
149
+ <div className="edit-site-sidebar-navigation-screen-navigation-menus__content">
150
+ <NavigationMenuContent
151
+ rootClientId={ blocks[ 0 ].clientId }
152
+ onSelect={ onSelect }
153
+ />
154
+ </div>
155
+ </BlockEditorProvider>
156
+ );
157
+ }
@@ -0,0 +1,9 @@
1
+ // This requested is preloaded in `gutenberg_preload_navigation_posts`.
2
+ // As unbounded queries are limited to 100 by `fetchAllMiddleware`
3
+ // on apiFetch this query is limited to 100.
4
+ export const PRELOADED_NAVIGATION_MENUS_QUERY = {
5
+ per_page: 100,
6
+ status: 'publish',
7
+ order: 'desc',
8
+ orderby: 'date',
9
+ };
@@ -2,143 +2,89 @@
2
2
  * WordPress dependencies
3
3
  */
4
4
  import { __ } from '@wordpress/i18n';
5
- import { useCallback, useMemo } from '@wordpress/element';
6
- import { useSelect } from '@wordpress/data';
7
- import { store as coreStore } from '@wordpress/core-data';
8
- import { BlockEditorProvider } from '@wordpress/block-editor';
9
- import { createBlock } from '@wordpress/blocks';
10
- import { privateApis as routerPrivateApis } from '@wordpress/router';
5
+ import { useEntityRecords } from '@wordpress/core-data';
6
+
7
+ import { decodeEntities } from '@wordpress/html-entities';
8
+ import {
9
+ __experimentalItemGroup as ItemGroup,
10
+ Spinner,
11
+ } from '@wordpress/components';
12
+ import { navigation } from '@wordpress/icons';
11
13
 
12
14
  /**
13
15
  * Internal dependencies
14
16
  */
15
17
  import SidebarNavigationScreen from '../sidebar-navigation-screen';
16
- import NavigationMenuContent from './navigation-menu-content';
17
- import { NavigationMenuLoader } from './loader';
18
- import { unlock } from '../../private-apis';
19
- import { store as editSiteStore } from '../../store';
20
- import {
21
- isPreviewingTheme,
22
- currentlyPreviewingTheme,
23
- } from '../../utils/is-previewing-theme';
24
-
25
- const { useHistory } = unlock( routerPrivateApis );
26
-
27
- const noop = () => {};
28
- const NAVIGATION_MENUS_QUERY = {
29
- per_page: 1,
30
- status: 'publish',
31
- order: 'desc',
32
- orderby: 'date',
33
- };
34
-
35
- function SidebarNavigationScreenWrapper( { children, actions } ) {
36
- return (
37
- <SidebarNavigationScreen
38
- title={ __( 'Navigation' ) }
39
- actions={ actions }
40
- description={ __(
41
- 'Browse your site, edit pages, and manage your primary navigation menu.'
42
- ) }
43
- content={ children }
44
- />
45
- );
46
- }
18
+ import SidebarNavigationItem from '../sidebar-navigation-item';
19
+ import { PRELOADED_NAVIGATION_MENUS_QUERY } from './constants';
20
+ import { useLink } from '../routes/link';
47
21
 
48
22
  export default function SidebarNavigationScreenNavigationMenus() {
49
- const history = useHistory();
50
- const { navigationMenus, hasResolvedNavigationMenus, storedSettings } =
51
- useSelect( ( select ) => {
52
- const { getSettings } = unlock( select( editSiteStore ) );
53
- const { getEntityRecords, hasFinishedResolution } =
54
- select( coreStore );
55
-
56
- const navigationMenusQuery = [
57
- 'postType',
58
- 'wp_navigation',
59
- NAVIGATION_MENUS_QUERY,
60
- ];
61
- return {
62
- storedSettings: getSettings( false ),
63
- navigationMenus: getEntityRecords( ...navigationMenusQuery ),
64
- hasResolvedNavigationMenus: hasFinishedResolution(
65
- 'getEntityRecords',
66
- navigationMenusQuery
67
- ),
68
- };
69
- }, [] );
70
-
71
- const firstNavigationMenu = navigationMenus?.[ 0 ]?.id;
72
- const blocks = useMemo( () => {
73
- return [
74
- createBlock( 'core/navigation', { ref: firstNavigationMenu } ),
75
- ];
76
- }, [ firstNavigationMenu ] );
23
+ const { records: navigationMenus, isResolving: isLoading } =
24
+ useEntityRecords(
25
+ 'postType',
26
+ `wp_navigation`,
27
+ PRELOADED_NAVIGATION_MENUS_QUERY
28
+ );
77
29
 
78
- const isLoading = ! hasResolvedNavigationMenus;
79
30
  const hasNavigationMenus = !! navigationMenus?.length;
80
31
 
81
- const onSelect = useCallback(
82
- ( selectedBlock ) => {
83
- const { attributes, name } = selectedBlock;
84
- if (
85
- attributes.kind === 'post-type' &&
86
- attributes.id &&
87
- attributes.type &&
88
- history
89
- ) {
90
- history.push( {
91
- postType: attributes.type,
92
- postId: attributes.id,
93
- ...( isPreviewingTheme() && {
94
- theme_preview: currentlyPreviewingTheme(),
95
- } ),
96
- } );
97
- }
98
- if ( name === 'core/page-list-item' && attributes.id && history ) {
99
- history.push( {
100
- postType: 'page',
101
- postId: attributes.id,
102
- ...( isPreviewingTheme() && {
103
- theme_preview: currentlyPreviewingTheme(),
104
- } ),
105
- } );
106
- }
107
- },
108
- [ history ]
109
- );
110
-
111
- if ( hasResolvedNavigationMenus && ! hasNavigationMenus ) {
32
+ if ( isLoading ) {
112
33
  return (
113
34
  <SidebarNavigationScreenWrapper>
114
- { __( 'There are no Navigation Menus.' ) }
35
+ <Spinner className="edit-site-sidebar-navigation-screen-navigation-menus__loading" />
115
36
  </SidebarNavigationScreenWrapper>
116
37
  );
117
38
  }
118
39
 
119
- if ( ! hasResolvedNavigationMenus || isLoading ) {
40
+ if ( ! isLoading && ! hasNavigationMenus ) {
120
41
  return (
121
- <SidebarNavigationScreenWrapper>
122
- <NavigationMenuLoader />
123
- </SidebarNavigationScreenWrapper>
42
+ <SidebarNavigationScreenWrapper
43
+ description={ __( 'No Navigation Menus found.' ) }
44
+ />
124
45
  );
125
46
  }
126
47
 
127
48
  return (
128
- <BlockEditorProvider
129
- settings={ storedSettings }
130
- value={ blocks }
131
- onChange={ noop }
132
- onInput={ noop }
133
- >
134
- <SidebarNavigationScreenWrapper>
135
- <div className="edit-site-sidebar-navigation-screen-navigation-menus__content">
136
- <NavigationMenuContent
137
- rootClientId={ blocks[ 0 ].clientId }
138
- onSelect={ onSelect }
139
- />
140
- </div>
141
- </SidebarNavigationScreenWrapper>
142
- </BlockEditorProvider>
49
+ <SidebarNavigationScreenWrapper>
50
+ <ItemGroup>
51
+ { navigationMenus?.map( ( navMenu ) => (
52
+ <NavMenuItem
53
+ postId={ navMenu.id }
54
+ key={ navMenu.id }
55
+ withChevron
56
+ icon={ navigation }
57
+ >
58
+ { decodeEntities(
59
+ navMenu.title?.rendered || navMenu.slug
60
+ ) }
61
+ </NavMenuItem>
62
+ ) ) }
63
+ </ItemGroup>
64
+ </SidebarNavigationScreenWrapper>
65
+ );
66
+ }
67
+
68
+ export function SidebarNavigationScreenWrapper( {
69
+ children,
70
+ actions,
71
+ title,
72
+ description,
73
+ } ) {
74
+ return (
75
+ <SidebarNavigationScreen
76
+ title={ title || __( 'Navigation' ) }
77
+ actions={ actions }
78
+ description={ description || __( 'Manage your Navigation menus.' ) }
79
+ content={ children }
80
+ />
143
81
  );
144
82
  }
83
+
84
+ const NavMenuItem = ( { postId, ...props } ) => {
85
+ const linkInfo = useLink( {
86
+ postId,
87
+ postType: 'wp_navigation',
88
+ } );
89
+ return <SidebarNavigationItem { ...linkInfo } { ...props } />;
90
+ };
@@ -0,0 +1,83 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+
5
+ import { chevronUp, chevronDown, moreVertical } from '@wordpress/icons';
6
+ import { DropdownMenu, MenuItem, MenuGroup } from '@wordpress/components';
7
+ import { useDispatch, useSelect } from '@wordpress/data';
8
+ import { __, sprintf } from '@wordpress/i18n';
9
+ import { BlockTitle, store as blockEditorStore } from '@wordpress/block-editor';
10
+
11
+ const POPOVER_PROPS = {
12
+ className: 'block-editor-block-settings-menu__popover',
13
+ position: 'bottom right',
14
+ variant: 'toolbar',
15
+ };
16
+
17
+ export default function LeafMoreMenu( props ) {
18
+ const { block } = props;
19
+ const { clientId } = block;
20
+ const { moveBlocksDown, moveBlocksUp, removeBlocks } =
21
+ useDispatch( blockEditorStore );
22
+
23
+ const removeLabel = sprintf(
24
+ /* translators: %s: block name */
25
+ __( 'Remove %s' ),
26
+ BlockTitle( { clientId, maximumLength: 25 } )
27
+ );
28
+
29
+ const rootClientId = useSelect(
30
+ ( select ) => {
31
+ const { getBlockRootClientId } = select( blockEditorStore );
32
+
33
+ return getBlockRootClientId( clientId );
34
+ },
35
+ [ clientId ]
36
+ );
37
+
38
+ return (
39
+ <DropdownMenu
40
+ icon={ moreVertical }
41
+ label={ __( 'Options' ) }
42
+ className="block-editor-block-settings-menu"
43
+ popoverProps={ POPOVER_PROPS }
44
+ noIcons
45
+ { ...props }
46
+ >
47
+ { ( { onClose } ) => (
48
+ <>
49
+ <MenuGroup>
50
+ <MenuItem
51
+ icon={ chevronUp }
52
+ onClick={ () => {
53
+ moveBlocksUp( [ clientId ], rootClientId );
54
+ onClose();
55
+ } }
56
+ >
57
+ { __( 'Move up' ) }
58
+ </MenuItem>
59
+ <MenuItem
60
+ icon={ chevronDown }
61
+ onClick={ () => {
62
+ moveBlocksDown( [ clientId ], rootClientId );
63
+ onClose();
64
+ } }
65
+ >
66
+ { __( 'Move down' ) }
67
+ </MenuItem>
68
+ </MenuGroup>
69
+ <MenuGroup>
70
+ <MenuItem
71
+ onClick={ () => {
72
+ removeBlocks( [ clientId ], false );
73
+ onClose();
74
+ } }
75
+ >
76
+ { removeLabel }
77
+ </MenuItem>
78
+ </MenuGroup>
79
+ </>
80
+ ) }
81
+ </DropdownMenu>
82
+ );
83
+ }
@@ -6,12 +6,10 @@ import {
6
6
  store as blockEditorStore,
7
7
  BlockList,
8
8
  BlockTools,
9
- __experimentalLinkControl as LinkControl,
10
9
  } from '@wordpress/block-editor';
11
10
  import { useDispatch, useSelect } from '@wordpress/data';
12
11
  import { createBlock } from '@wordpress/blocks';
13
- import { Popover } from '@wordpress/components';
14
- import { __unstableStripHTML as stripHTML } from '@wordpress/dom';
12
+ import { VisuallyHidden } from '@wordpress/components';
15
13
  import { useCallback, useEffect, useState } from '@wordpress/element';
16
14
  import { store as coreStore } from '@wordpress/core-data';
17
15
 
@@ -19,35 +17,8 @@ import { store as coreStore } from '@wordpress/core-data';
19
17
  * Internal dependencies
20
18
  */
21
19
  import { unlock } from '../../private-apis';
22
- import { NavigationMenuLoader } from './loader';
20
+ import LeafMoreMenu from './leaf-more-menu';
23
21
 
24
- function CustomLinkAdditionalBlockUI( { block, onClose } ) {
25
- const { updateBlockAttributes } = useDispatch( blockEditorStore );
26
- const { label, url, opensInNewTab } = block.attributes;
27
- const link = {
28
- url,
29
- opensInNewTab,
30
- title: label && stripHTML( label ),
31
- };
32
- return (
33
- <Popover placement="bottom" shift onClose={ onClose }>
34
- <LinkControl
35
- hasTextControl
36
- hasRichPreviews
37
- value={ link }
38
- onChange={ ( updatedValue ) => {
39
- updateBlockAttributes( block.clientId, {
40
- label: updatedValue.title,
41
- url: updatedValue.url,
42
- opensInNewTab: updatedValue.opensInNewTab,
43
- } );
44
- onClose();
45
- } }
46
- onCancel={ onClose }
47
- />
48
- </Popover>
49
- );
50
- }
51
22
  // Needs to be kept in sync with the query used at packages/block-library/src/page-list/edit.js.
52
23
  const MAX_PAGE_COUNT = 100;
53
24
  const PAGES_QUERY = [
@@ -102,29 +73,6 @@ export default function NavigationMenuContent( { rootClientId, onSelect } ) {
102
73
  const { replaceBlock, __unstableMarkNextChangeAsNotPersistent } =
103
74
  useDispatch( blockEditorStore );
104
75
 
105
- const [ customLinkEditPopoverOpenId, setIsCustomLinkEditPopoverOpenId ] =
106
- useState( false );
107
-
108
- const renderAdditionalBlockUICallback = useCallback(
109
- ( block ) => {
110
- if (
111
- customLinkEditPopoverOpenId &&
112
- block.clientId === customLinkEditPopoverOpenId
113
- ) {
114
- return (
115
- <CustomLinkAdditionalBlockUI
116
- block={ block }
117
- onClose={ () => {
118
- setIsCustomLinkEditPopoverOpenId( false );
119
- } }
120
- />
121
- );
122
- }
123
- return null;
124
- },
125
- [ customLinkEditPopoverOpenId, setIsCustomLinkEditPopoverOpenId ]
126
- );
127
-
128
76
  // Delay loading stop by 50ms to avoid flickering.
129
77
  useEffect( () => {
130
78
  let timeoutId;
@@ -144,8 +92,7 @@ export default function NavigationMenuContent( { rootClientId, onSelect } ) {
144
92
  };
145
93
  }, [ shouldKeepLoading, clientIdsTree, isLoading ] );
146
94
 
147
- const { PrivateListView, LeafMoreMenu } = unlock( blockEditorPrivateApis );
148
-
95
+ const { PrivateListView } = unlock( blockEditorPrivateApis );
149
96
  const offCanvasOnselect = useCallback(
150
97
  ( block ) => {
151
98
  if (
@@ -157,29 +104,17 @@ export default function NavigationMenuContent( { rootClientId, onSelect } ) {
157
104
  block.clientId,
158
105
  createBlock( 'core/navigation-link', block.attributes )
159
106
  );
160
- } else if (
161
- block.name === 'core/navigation-link' &&
162
- block.attributes.kind === 'custom' &&
163
- block.attributes.url
164
- ) {
165
- setIsCustomLinkEditPopoverOpenId( block.clientId );
166
107
  } else {
167
108
  onSelect( block );
168
109
  }
169
110
  },
170
- [
171
- onSelect,
172
- __unstableMarkNextChangeAsNotPersistent,
173
- replaceBlock,
174
- setIsCustomLinkEditPopoverOpenId,
175
- ]
111
+ [ onSelect, __unstableMarkNextChangeAsNotPersistent, replaceBlock ]
176
112
  );
177
113
 
178
114
  // The hidden block is needed because it makes block edit side effects trigger.
179
115
  // For example a navigation page list load its items has an effect on edit to load its items.
180
116
  return (
181
117
  <>
182
- { isLoading && <NavigationMenuLoader /> }
183
118
  { ! isLoading && (
184
119
  <PrivateListView
185
120
  blocks={
@@ -190,14 +125,13 @@ export default function NavigationMenuContent( { rootClientId, onSelect } ) {
190
125
  onSelect={ offCanvasOnselect }
191
126
  blockSettingsMenu={ LeafMoreMenu }
192
127
  showAppender={ false }
193
- renderAdditionalBlockUI={ renderAdditionalBlockUICallback }
194
128
  />
195
129
  ) }
196
- <div style={ { visibility: 'hidden' } }>
130
+ <VisuallyHidden aria-hidden="true">
197
131
  <BlockTools>
198
132
  <BlockList />
199
133
  </BlockTools>
200
- </div>
134
+ </VisuallyHidden>
201
135
  </>
202
136
  );
203
137
  }
@@ -0,0 +1,47 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+
5
+ import { __experimentalNavigatorButton as NavigatorButton } from '@wordpress/components';
6
+ import { useEntityRecords } from '@wordpress/core-data';
7
+
8
+ /**
9
+ * Internal dependencies
10
+ */
11
+ import { PRELOADED_NAVIGATION_MENUS_QUERY } from './constants';
12
+
13
+ export default function SidebarNavigationScreenNavigationMenuButton( {
14
+ children,
15
+ ...props
16
+ } ) {
17
+ const { records: navigationMenus, isResolving: isLoading } =
18
+ useEntityRecords(
19
+ 'postType',
20
+ `wp_navigation`,
21
+ PRELOADED_NAVIGATION_MENUS_QUERY
22
+ );
23
+
24
+ const hasNavigationMenus = !! navigationMenus?.length;
25
+ const hasSingleNavigationMenu = navigationMenus?.length === 1;
26
+ const firstNavigationMenu = navigationMenus?.[ 0 ];
27
+
28
+ const showNavigationScreen = process.env.IS_GUTENBERG_PLUGIN
29
+ ? hasNavigationMenus
30
+ : false;
31
+
32
+ // If there is a single menu then we can go directly to that menu.
33
+ // Otherwise we go to the navigation listing screen.
34
+ const path = hasSingleNavigationMenu
35
+ ? `/navigation/wp_navigation/${ firstNavigationMenu?.id }`
36
+ : '/navigation';
37
+
38
+ if ( ! showNavigationScreen ) {
39
+ return null;
40
+ }
41
+
42
+ return (
43
+ <NavigatorButton { ...props } disabled={ isLoading } path={ path }>
44
+ { children }
45
+ </NavigatorButton>
46
+ );
47
+ }
@@ -2,26 +2,6 @@
2
2
  margin: 0 0 $grid-unit-40 $grid-unit-20;
3
3
  }
4
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;
19
- }
20
- 100% {
21
- opacity: 1;
22
- }
23
- }
24
-
25
5
  .edit-site-sidebar-navigation-screen-navigation-menus__content {
26
6
  .offcanvas-editor-list-view-leaf {
27
7
  max-width: calc(100% - #{ $grid-unit-05 });
@@ -113,3 +93,9 @@
113
93
  .edit-site-sidebar-navigation-screen-navigation-menus__content .popover-slot .wp-block-navigation-submenu {
114
94
  display: none;
115
95
  }
96
+
97
+ .edit-site-sidebar-navigation-screen-navigation-menus__loading.components-spinner {
98
+ margin-left: auto;
99
+ margin-right: auto;
100
+ display: block;
101
+ }