@wordpress/edit-site 5.5.0 → 5.6.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 (224) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/build/components/add-new-template/new-template.js +16 -10
  3. package/build/components/add-new-template/new-template.js.map +1 -1
  4. package/build/components/app/index.js +4 -2
  5. package/build/components/app/index.js.map +1 -1
  6. package/build/components/block-editor/editor-canvas.js +2 -1
  7. package/build/components/block-editor/editor-canvas.js.map +1 -1
  8. package/build/components/editor/index.js +2 -4
  9. package/build/components/editor/index.js.map +1 -1
  10. package/build/components/global-styles/border-panel.js +20 -159
  11. package/build/components/global-styles/border-panel.js.map +1 -1
  12. package/build/components/global-styles/context-menu.js +2 -3
  13. package/build/components/global-styles/context-menu.js.map +1 -1
  14. package/build/components/global-styles/hooks.js +11 -26
  15. package/build/components/global-styles/hooks.js.map +1 -1
  16. package/build/components/global-styles/screen-block-list.js +2 -3
  17. package/build/components/global-styles/screen-block-list.js.map +1 -1
  18. package/build/components/global-styles/screen-border.js +13 -5
  19. package/build/components/global-styles/screen-border.js.map +1 -1
  20. package/build/components/global-styles/screen-root.js +2 -1
  21. package/build/components/global-styles/screen-root.js.map +1 -1
  22. package/build/components/global-styles/screen-style-variations.js +2 -1
  23. package/build/components/global-styles/screen-style-variations.js.map +1 -1
  24. package/build/components/layout/index.js +7 -0
  25. package/build/components/layout/index.js.map +1 -1
  26. package/build/components/list/added-by.js +128 -136
  27. package/build/components/list/added-by.js.map +1 -1
  28. package/build/components/list/index.js +2 -1
  29. package/build/components/list/index.js.map +1 -1
  30. package/build/components/list/table.js +6 -5
  31. package/build/components/list/table.js.map +1 -1
  32. package/build/components/routes/link.js +4 -1
  33. package/build/components/routes/link.js.map +1 -1
  34. package/build/components/save-button/index.js +2 -5
  35. package/build/components/save-button/index.js.map +1 -1
  36. package/build/components/save-hub/index.js +82 -0
  37. package/build/components/save-hub/index.js.map +1 -0
  38. package/build/components/sidebar/index.js +2 -4
  39. package/build/components/sidebar/index.js.map +1 -1
  40. package/build/components/sidebar-navigation-screen/index.js +5 -2
  41. package/build/components/sidebar-navigation-screen/index.js.map +1 -1
  42. package/build/components/sidebar-navigation-screen-main/index.js +13 -13
  43. package/build/components/sidebar-navigation-screen-main/index.js.map +1 -1
  44. package/build/components/sidebar-navigation-screen-navigation-item/index.js +9 -14
  45. package/build/components/sidebar-navigation-screen-navigation-item/index.js.map +1 -1
  46. package/build/components/sidebar-navigation-screen-navigation-menus/index.js +87 -10
  47. package/build/components/sidebar-navigation-screen-navigation-menus/index.js.map +1 -1
  48. package/build/components/sidebar-navigation-screen-navigation-menus/loader.js +19 -0
  49. package/build/components/sidebar-navigation-screen-navigation-menus/loader.js.map +1 -0
  50. package/build/components/sidebar-navigation-screen-navigation-menus/navigation-menu-content.js +77 -0
  51. package/build/components/sidebar-navigation-screen-navigation-menus/navigation-menu-content.js.map +1 -0
  52. package/build/components/sidebar-navigation-screen-template/index.js +59 -10
  53. package/build/components/sidebar-navigation-screen-template/index.js.map +1 -1
  54. package/build/components/sidebar-navigation-screen-templates/index.js +5 -2
  55. package/build/components/sidebar-navigation-screen-templates/index.js.map +1 -1
  56. package/build/components/sidebar-navigation-screen-templates-browse/index.js +6 -3
  57. package/build/components/sidebar-navigation-screen-templates-browse/index.js.map +1 -1
  58. package/build/components/site-hub/index.js +3 -1
  59. package/build/components/site-hub/index.js.map +1 -1
  60. package/build/components/style-book/index.js +134 -19
  61. package/build/components/style-book/index.js.map +1 -1
  62. package/build/components/sync-state-with-url/use-sync-canvas-mode-with-url.js +24 -8
  63. package/build/components/sync-state-with-url/use-sync-canvas-mode-with-url.js.map +1 -1
  64. package/build/components/sync-state-with-url/use-sync-path-with-url.js +9 -7
  65. package/build/components/sync-state-with-url/use-sync-path-with-url.js.map +1 -1
  66. package/build/components/template-details/index.js +0 -3
  67. package/build/components/template-details/index.js.map +1 -1
  68. package/build/components/template-part-converter/convert-to-regular.js +8 -12
  69. package/build/components/template-part-converter/convert-to-regular.js.map +1 -1
  70. package/build/components/template-part-converter/convert-to-template-part.js +2 -2
  71. package/build/components/template-part-converter/convert-to-template-part.js.map +1 -1
  72. package/build/components/template-part-converter/index.js +19 -14
  73. package/build/components/template-part-converter/index.js.map +1 -1
  74. package/build/components/use-edited-entity-record/index.js +6 -6
  75. package/build/components/use-edited-entity-record/index.js.map +1 -1
  76. package/build/index.js +3 -0
  77. package/build/index.js.map +1 -1
  78. package/build/utils/history.js +8 -2
  79. package/build/utils/history.js.map +1 -1
  80. package/build-module/components/add-new-template/new-template.js +18 -11
  81. package/build-module/components/add-new-template/new-template.js.map +1 -1
  82. package/build-module/components/app/index.js +3 -2
  83. package/build-module/components/app/index.js.map +1 -1
  84. package/build-module/components/block-editor/editor-canvas.js +2 -1
  85. package/build-module/components/block-editor/editor-canvas.js.map +1 -1
  86. package/build-module/components/editor/index.js +2 -3
  87. package/build-module/components/editor/index.js.map +1 -1
  88. package/build-module/components/global-styles/border-panel.js +21 -157
  89. package/build-module/components/global-styles/border-panel.js.map +1 -1
  90. package/build-module/components/global-styles/context-menu.js +2 -2
  91. package/build-module/components/global-styles/context-menu.js.map +1 -1
  92. package/build-module/components/global-styles/hooks.js +11 -26
  93. package/build-module/components/global-styles/hooks.js.map +1 -1
  94. package/build-module/components/global-styles/screen-block-list.js +2 -2
  95. package/build-module/components/global-styles/screen-block-list.js.map +1 -1
  96. package/build-module/components/global-styles/screen-border.js +11 -2
  97. package/build-module/components/global-styles/screen-border.js.map +1 -1
  98. package/build-module/components/global-styles/screen-root.js +2 -1
  99. package/build-module/components/global-styles/screen-root.js.map +1 -1
  100. package/build-module/components/global-styles/screen-style-variations.js +2 -1
  101. package/build-module/components/global-styles/screen-style-variations.js.map +1 -1
  102. package/build-module/components/layout/index.js +7 -0
  103. package/build-module/components/layout/index.js.map +1 -1
  104. package/build-module/components/list/added-by.js +126 -137
  105. package/build-module/components/list/added-by.js.map +1 -1
  106. package/build-module/components/list/index.js +2 -1
  107. package/build-module/components/list/index.js.map +1 -1
  108. package/build-module/components/list/table.js +6 -5
  109. package/build-module/components/list/table.js.map +1 -1
  110. package/build-module/components/routes/link.js +5 -2
  111. package/build-module/components/routes/link.js.map +1 -1
  112. package/build-module/components/save-button/index.js +2 -5
  113. package/build-module/components/save-button/index.js.map +1 -1
  114. package/build-module/components/save-hub/index.js +68 -0
  115. package/build-module/components/save-hub/index.js.map +1 -0
  116. package/build-module/components/sidebar/index.js +2 -4
  117. package/build-module/components/sidebar/index.js.map +1 -1
  118. package/build-module/components/sidebar-navigation-screen/index.js +5 -2
  119. package/build-module/components/sidebar-navigation-screen/index.js.map +1 -1
  120. package/build-module/components/sidebar-navigation-screen-main/index.js +13 -13
  121. package/build-module/components/sidebar-navigation-screen-main/index.js.map +1 -1
  122. package/build-module/components/sidebar-navigation-screen-navigation-item/index.js +13 -18
  123. package/build-module/components/sidebar-navigation-screen-navigation-item/index.js.map +1 -1
  124. package/build-module/components/sidebar-navigation-screen-navigation-menus/index.js +81 -10
  125. package/build-module/components/sidebar-navigation-screen-navigation-menus/index.js.map +1 -1
  126. package/build-module/components/sidebar-navigation-screen-navigation-menus/loader.js +11 -0
  127. package/build-module/components/sidebar-navigation-screen-navigation-menus/loader.js.map +1 -0
  128. package/build-module/components/sidebar-navigation-screen-navigation-menus/navigation-menu-content.js +66 -0
  129. package/build-module/components/sidebar-navigation-screen-navigation-menus/navigation-menu-content.js.map +1 -0
  130. package/build-module/components/sidebar-navigation-screen-template/index.js +60 -13
  131. package/build-module/components/sidebar-navigation-screen-template/index.js.map +1 -1
  132. package/build-module/components/sidebar-navigation-screen-templates/index.js +5 -2
  133. package/build-module/components/sidebar-navigation-screen-templates/index.js.map +1 -1
  134. package/build-module/components/sidebar-navigation-screen-templates-browse/index.js +6 -3
  135. package/build-module/components/sidebar-navigation-screen-templates-browse/index.js.map +1 -1
  136. package/build-module/components/site-hub/index.js +3 -1
  137. package/build-module/components/site-hub/index.js.map +1 -1
  138. package/build-module/components/style-book/index.js +135 -22
  139. package/build-module/components/style-book/index.js.map +1 -1
  140. package/build-module/components/sync-state-with-url/use-sync-canvas-mode-with-url.js +24 -8
  141. package/build-module/components/sync-state-with-url/use-sync-canvas-mode-with-url.js.map +1 -1
  142. package/build-module/components/sync-state-with-url/use-sync-path-with-url.js +9 -7
  143. package/build-module/components/sync-state-with-url/use-sync-path-with-url.js.map +1 -1
  144. package/build-module/components/template-details/index.js +0 -3
  145. package/build-module/components/template-details/index.js.map +1 -1
  146. package/build-module/components/template-part-converter/convert-to-regular.js +9 -13
  147. package/build-module/components/template-part-converter/convert-to-regular.js.map +1 -1
  148. package/build-module/components/template-part-converter/convert-to-template-part.js +3 -3
  149. package/build-module/components/template-part-converter/convert-to-template-part.js.map +1 -1
  150. package/build-module/components/template-part-converter/index.js +20 -15
  151. package/build-module/components/template-part-converter/index.js.map +1 -1
  152. package/build-module/components/use-edited-entity-record/index.js +6 -6
  153. package/build-module/components/use-edited-entity-record/index.js.map +1 -1
  154. package/build-module/index.js +4 -1
  155. package/build-module/index.js.map +1 -1
  156. package/build-module/utils/history.js +9 -3
  157. package/build-module/utils/history.js.map +1 -1
  158. package/build-style/style-rtl.css +168 -111
  159. package/build-style/style.css +168 -111
  160. package/package.json +31 -31
  161. package/src/components/add-new-template/new-template.js +57 -32
  162. package/src/components/add-new-template/style.scss +12 -1
  163. package/src/components/app/index.js +9 -6
  164. package/src/components/block-editor/editor-canvas.js +2 -1
  165. package/src/components/editor/index.js +61 -65
  166. package/src/components/global-styles/border-panel.js +24 -199
  167. package/src/components/global-styles/context-menu.js +2 -2
  168. package/src/components/global-styles/hooks.js +12 -36
  169. package/src/components/global-styles/screen-block-list.js +2 -2
  170. package/src/components/global-styles/screen-border.js +9 -2
  171. package/src/components/global-styles/screen-root.js +1 -1
  172. package/src/components/global-styles/screen-style-variations.js +5 -1
  173. package/src/components/global-styles/style.scss +10 -0
  174. package/src/components/layout/index.js +15 -0
  175. package/src/components/layout/style.scss +1 -3
  176. package/src/components/list/added-by.js +144 -140
  177. package/src/components/list/index.js +3 -1
  178. package/src/components/list/table.js +7 -4
  179. package/src/components/routes/link.js +9 -2
  180. package/src/components/save-button/index.js +2 -2
  181. package/src/components/save-hub/index.js +78 -0
  182. package/src/components/save-hub/style.scss +15 -0
  183. package/src/components/sidebar/index.js +2 -3
  184. package/src/components/sidebar/style.scss +4 -3
  185. package/src/components/sidebar-button/style.scss +2 -1
  186. package/src/components/sidebar-navigation-item/style.scss +1 -23
  187. package/src/components/sidebar-navigation-screen/index.js +6 -0
  188. package/src/components/sidebar-navigation-screen/style.scss +15 -0
  189. package/src/components/sidebar-navigation-screen-main/index.js +21 -8
  190. package/src/components/sidebar-navigation-screen-navigation-item/index.js +30 -21
  191. package/src/components/sidebar-navigation-screen-navigation-menus/index.js +92 -9
  192. package/src/components/sidebar-navigation-screen-navigation-menus/loader.js +9 -0
  193. package/src/components/sidebar-navigation-screen-navigation-menus/navigation-menu-content.js +78 -0
  194. package/src/components/sidebar-navigation-screen-navigation-menus/style.scss +108 -1
  195. package/src/components/sidebar-navigation-screen-template/index.js +82 -11
  196. package/src/components/sidebar-navigation-screen-template/style.scss +25 -0
  197. package/src/components/sidebar-navigation-screen-templates/index.js +7 -0
  198. package/src/components/sidebar-navigation-screen-templates-browse/index.js +12 -1
  199. package/src/components/site-hub/index.js +5 -1
  200. package/src/components/site-hub/style.scss +5 -1
  201. package/src/components/style-book/index.js +209 -54
  202. package/src/components/style-book/style.scss +1 -45
  203. package/src/components/sync-state-with-url/use-sync-canvas-mode-with-url.js +38 -8
  204. package/src/components/sync-state-with-url/use-sync-path-with-url.js +12 -7
  205. package/src/components/template-details/index.js +0 -3
  206. package/src/components/template-part-converter/convert-to-regular.js +10 -17
  207. package/src/components/template-part-converter/convert-to-template-part.js +9 -16
  208. package/src/components/template-part-converter/index.js +28 -12
  209. package/src/components/use-edited-entity-record/index.js +26 -18
  210. package/src/index.js +5 -1
  211. package/src/store/test/actions.js +0 -2
  212. package/src/style.scss +2 -1
  213. package/src/utils/history.js +13 -9
  214. package/build/components/navigation-inspector/index.js +0 -161
  215. package/build/components/navigation-inspector/index.js.map +0 -1
  216. package/build/components/navigation-inspector/navigation-menu.js +0 -79
  217. package/build/components/navigation-inspector/navigation-menu.js.map +0 -1
  218. package/build-module/components/navigation-inspector/index.js +0 -146
  219. package/build-module/components/navigation-inspector/index.js.map +0 -1
  220. package/build-module/components/navigation-inspector/navigation-menu.js +0 -69
  221. package/build-module/components/navigation-inspector/navigation-menu.js.map +0 -1
  222. package/src/components/navigation-inspector/index.js +0 -191
  223. package/src/components/navigation-inspector/navigation-menu.js +0 -84
  224. package/src/components/navigation-inspector/style.scss +0 -46
package/src/index.js CHANGED
@@ -17,7 +17,10 @@ import {
17
17
  import { store as editorStore } from '@wordpress/editor';
18
18
  import { store as interfaceStore } from '@wordpress/interface';
19
19
  import { store as preferencesStore } from '@wordpress/preferences';
20
- import { registerLegacyWidgetBlock } from '@wordpress/widgets';
20
+ import {
21
+ registerLegacyWidgetBlock,
22
+ registerWidgetGroupBlock,
23
+ } from '@wordpress/widgets';
21
24
 
22
25
  /**
23
26
  * Internal dependencies
@@ -47,6 +50,7 @@ export function initializeEditor( id, settings ) {
47
50
  registerCoreBlocks( coreBlocks );
48
51
  dispatch( blocksStore ).setFreeformFallbackBlockName( 'core/html' );
49
52
  registerLegacyWidgetBlock( { inserter: false } );
53
+ registerWidgetGroupBlock( { inserter: false } );
50
54
  if ( process.env.IS_GUTENBERG_PLUGIN ) {
51
55
  __experimentalRegisterExperimentalCoreBlocks( {
52
56
  enableFSEBlocks: true,
@@ -14,8 +14,6 @@ import { store as preferencesStore } from '@wordpress/preferences';
14
14
  */
15
15
  import { store as editSiteStore } from '..';
16
16
 
17
- jest.useRealTimers();
18
-
19
17
  const ENTITY_TYPES = {
20
18
  wp_template: {
21
19
  description: 'Templates to include in your theme.',
package/src/style.scss CHANGED
@@ -8,7 +8,6 @@
8
8
  @import "./components/header-edit-mode/style.scss";
9
9
  @import "./components/header-edit-mode/document-actions/style.scss";
10
10
  @import "./components/list/style.scss";
11
- @import "./components/navigation-inspector/style.scss";
12
11
  @import "./components/sidebar-edit-mode/style.scss";
13
12
  @import "./components/sidebar-edit-mode/settings-header/style.scss";
14
13
  @import "./components/sidebar-edit-mode/template-card/style.scss";
@@ -20,11 +19,13 @@
20
19
  @import "./components/start-template-options/style.scss";
21
20
  @import "./components/keyboard-shortcut-help-modal/style.scss";
22
21
  @import "./components/layout/style.scss";
22
+ @import "./components/save-hub/style.scss";
23
23
  @import "./components/save-panel/style.scss";
24
24
  @import "./components/sidebar/style.scss";
25
25
  @import "./components/sidebar-button/style.scss";
26
26
  @import "./components/sidebar-navigation-item/style.scss";
27
27
  @import "./components/sidebar-navigation-screen/style.scss";
28
+ @import "./components/sidebar-navigation-screen-template/style.scss";
28
29
  @import "./components/sidebar-navigation-screen-templates/style.scss";
29
30
  @import "./components/site-hub/style.scss";
30
31
  @import "./components/sidebar-navigation-screen-navigation-menus/style.scss";
@@ -6,7 +6,7 @@ import { createBrowserHistory } from 'history';
6
6
  /**
7
7
  * WordPress dependencies
8
8
  */
9
- import { addQueryArgs } from '@wordpress/url';
9
+ import { addQueryArgs, getQueryArgs, removeQueryArgs } from '@wordpress/url';
10
10
 
11
11
  const history = createBrowserHistory();
12
12
 
@@ -14,19 +14,23 @@ const originalHistoryPush = history.push;
14
14
  const originalHistoryReplace = history.replace;
15
15
 
16
16
  function push( params, state ) {
17
- return originalHistoryPush.call(
18
- history,
19
- addQueryArgs( window.location.href, params ),
20
- state
17
+ const currentArgs = getQueryArgs( window.location.href );
18
+ const currentUrlWithoutArgs = removeQueryArgs(
19
+ window.location.href,
20
+ ...Object.keys( currentArgs )
21
21
  );
22
+ const newUrl = addQueryArgs( currentUrlWithoutArgs, params );
23
+ return originalHistoryPush.call( history, newUrl, state );
22
24
  }
23
25
 
24
26
  function replace( params, state ) {
25
- return originalHistoryReplace.call(
26
- history,
27
- addQueryArgs( window.location.href, params ),
28
- state
27
+ const currentArgs = getQueryArgs( window.location.href );
28
+ const currentUrlWithoutArgs = removeQueryArgs(
29
+ window.location.href,
30
+ ...Object.keys( currentArgs )
29
31
  );
32
+ const newUrl = addQueryArgs( currentUrlWithoutArgs, params );
33
+ return originalHistoryReplace.call( history, newUrl, state );
30
34
  }
31
35
 
32
36
  history.push = push;
@@ -1,161 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports.default = NavigationInspector;
9
-
10
- var _element = require("@wordpress/element");
11
-
12
- var _data = require("@wordpress/data");
13
-
14
- var _coreData = require("@wordpress/core-data");
15
-
16
- var _blockEditor = require("@wordpress/block-editor");
17
-
18
- var _a11y = require("@wordpress/a11y");
19
-
20
- var _i18n = require("@wordpress/i18n");
21
-
22
- var _navigationMenu = _interopRequireDefault(require("./navigation-menu"));
23
-
24
- /**
25
- * WordPress dependencies
26
- */
27
-
28
- /**
29
- * Internal dependencies
30
- */
31
- const NAVIGATION_MENUS_QUERY = [{
32
- per_page: -1,
33
- status: 'publish'
34
- }];
35
-
36
- function NavigationInspector(_ref) {
37
- var _navigationMenus$;
38
-
39
- let {
40
- onSelect
41
- } = _ref;
42
- const {
43
- selectedNavigationBlockId,
44
- clientIdToRef,
45
- navigationMenus,
46
- isResolvingNavigationMenus,
47
- hasResolvedNavigationMenus,
48
- firstNavigationBlockId
49
- } = (0, _data.useSelect)(select => {
50
- const {
51
- __experimentalGetActiveBlockIdByBlockNames,
52
- __experimentalGetGlobalBlocksByName,
53
- getBlock
54
- } = select(_blockEditor.store);
55
- const {
56
- getEntityRecords,
57
- hasFinishedResolution,
58
- isResolving
59
- } = select(_coreData.store);
60
- const navigationMenusQuery = ['postType', 'wp_navigation', NAVIGATION_MENUS_QUERY[0]]; // Get the active Navigation block (if present).
61
-
62
- const selectedNavId = __experimentalGetActiveBlockIdByBlockNames('core/navigation'); // Get all Navigation blocks currently within the editor canvas.
63
-
64
-
65
- const navBlockIds = __experimentalGetGlobalBlocksByName('core/navigation');
66
-
67
- const idToRef = {};
68
- navBlockIds.forEach(id => {
69
- var _getBlock, _getBlock$attributes;
70
-
71
- idToRef[id] = (_getBlock = getBlock(id)) === null || _getBlock === void 0 ? void 0 : (_getBlock$attributes = _getBlock.attributes) === null || _getBlock$attributes === void 0 ? void 0 : _getBlock$attributes.ref;
72
- });
73
- return {
74
- selectedNavigationBlockId: selectedNavId,
75
- firstNavigationBlockId: navBlockIds === null || navBlockIds === void 0 ? void 0 : navBlockIds[0],
76
- clientIdToRef: idToRef,
77
- navigationMenus: getEntityRecords(...navigationMenusQuery),
78
- isResolvingNavigationMenus: isResolving('getEntityRecords', navigationMenusQuery),
79
- hasResolvedNavigationMenus: hasFinishedResolution('getEntityRecords', navigationMenusQuery)
80
- };
81
- }, []);
82
- const firstNavRefInTemplate = clientIdToRef[firstNavigationBlockId];
83
- const firstNavigationMenuRef = navigationMenus === null || navigationMenus === void 0 ? void 0 : (_navigationMenus$ = navigationMenus[0]) === null || _navigationMenus$ === void 0 ? void 0 : _navigationMenus$.id; // Default Navigation Menu is either:
84
- // - the Navigation Menu referenced by the first Nav block within the template.
85
- // - the first of the available Navigation Menus (`wp_navigation`) posts.
86
-
87
- const defaultNavigationMenuId = firstNavRefInTemplate || firstNavigationMenuRef; // The Navigation Menu manually selected by the user within the Nav inspector.
88
-
89
- const [currentMenuId, setCurrentMenuId] = (0, _element.useState)(firstNavRefInTemplate); // If a Nav block is selected within the canvas then set the
90
- // Navigation Menu referenced by it's `ref` attribute to be
91
- // active within the Navigation sidebar.
92
-
93
- (0, _element.useEffect)(() => {
94
- if (selectedNavigationBlockId) {
95
- setCurrentMenuId(clientIdToRef[selectedNavigationBlockId]);
96
- }
97
- }, [selectedNavigationBlockId]);
98
- const [innerBlocks, onInput, onChange] = (0, _coreData.useEntityBlockEditor)('postType', 'wp_navigation', {
99
- id: currentMenuId || defaultNavigationMenuId
100
- });
101
- const {
102
- isLoadingInnerBlocks,
103
- hasLoadedInnerBlocks
104
- } = (0, _data.useSelect)(select => {
105
- const {
106
- isResolving,
107
- hasFinishedResolution
108
- } = select(_coreData.store);
109
- return {
110
- isLoadingInnerBlocks: isResolving('getEntityRecord', ['postType', 'wp_navigation', currentMenuId || defaultNavigationMenuId]),
111
- hasLoadedInnerBlocks: hasFinishedResolution('getEntityRecord', ['postType', 'wp_navigation', currentMenuId || defaultNavigationMenuId])
112
- };
113
- }, [currentMenuId, defaultNavigationMenuId]);
114
- const isLoading = !(hasResolvedNavigationMenus && hasLoadedInnerBlocks);
115
- const hasNavigationMenus = !!(navigationMenus !== null && navigationMenus !== void 0 && navigationMenus.length); // Entity block editor will return entities that are not currently published.
116
- // Guard by only allowing their usage if there are published Nav Menus.
117
-
118
- const publishedInnerBlocks = hasNavigationMenus ? innerBlocks : [];
119
- const hasInnerBlocks = !!(publishedInnerBlocks !== null && publishedInnerBlocks !== void 0 && publishedInnerBlocks.length);
120
- (0, _element.useEffect)(() => {
121
- if (isResolvingNavigationMenus) {
122
- (0, _a11y.speak)('Loading Navigation sidebar menus.');
123
- }
124
-
125
- if (hasResolvedNavigationMenus) {
126
- (0, _a11y.speak)('Navigation sidebar menus have loaded.');
127
- }
128
- }, [isResolvingNavigationMenus, hasResolvedNavigationMenus]);
129
- (0, _element.useEffect)(() => {
130
- if (isLoadingInnerBlocks) {
131
- (0, _a11y.speak)('Loading Navigation sidebar selected menu items.');
132
- }
133
-
134
- if (hasLoadedInnerBlocks) {
135
- (0, _a11y.speak)('Navigation sidebar selected menu items have loaded.');
136
- }
137
- }, [isLoadingInnerBlocks, hasLoadedInnerBlocks]);
138
- return (0, _element.createElement)("div", {
139
- className: "edit-site-navigation-inspector"
140
- }, hasResolvedNavigationMenus && !hasNavigationMenus && (0, _element.createElement)("p", {
141
- className: "edit-site-navigation-inspector__empty-msg"
142
- }, (0, _i18n.__)('There are no Navigation Menus.')), !hasResolvedNavigationMenus && (0, _element.createElement)("div", {
143
- className: "edit-site-navigation-inspector__placeholder"
144
- }), isLoading && (0, _element.createElement)(_element.Fragment, null, (0, _element.createElement)("div", {
145
- className: "edit-site-navigation-inspector__placeholder is-child"
146
- }), (0, _element.createElement)("div", {
147
- className: "edit-site-navigation-inspector__placeholder is-child"
148
- }), (0, _element.createElement)("div", {
149
- className: "edit-site-navigation-inspector__placeholder is-child"
150
- })), hasInnerBlocks && !isLoading && (0, _element.createElement)(_blockEditor.BlockEditorProvider, {
151
- value: publishedInnerBlocks,
152
- onChange: onChange,
153
- onInput: onInput
154
- }, (0, _element.createElement)(_navigationMenu.default, {
155
- innerBlocks: publishedInnerBlocks,
156
- onSelect: onSelect
157
- })), !hasInnerBlocks && !isLoading && (0, _element.createElement)("p", {
158
- className: "edit-site-navigation-inspector__empty-msg"
159
- }, (0, _i18n.__)('Navigation Menu is empty.')));
160
- }
161
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["@wordpress/edit-site/src/components/navigation-inspector/index.js"],"names":["NAVIGATION_MENUS_QUERY","per_page","status","NavigationInspector","onSelect","selectedNavigationBlockId","clientIdToRef","navigationMenus","isResolvingNavigationMenus","hasResolvedNavigationMenus","firstNavigationBlockId","select","__experimentalGetActiveBlockIdByBlockNames","__experimentalGetGlobalBlocksByName","getBlock","blockEditorStore","getEntityRecords","hasFinishedResolution","isResolving","coreStore","navigationMenusQuery","selectedNavId","navBlockIds","idToRef","forEach","id","attributes","ref","firstNavRefInTemplate","firstNavigationMenuRef","defaultNavigationMenuId","currentMenuId","setCurrentMenuId","innerBlocks","onInput","onChange","isLoadingInnerBlocks","hasLoadedInnerBlocks","isLoading","hasNavigationMenus","length","publishedInnerBlocks","hasInnerBlocks"],"mappings":";;;;;;;;;AAIA;;AADA;;AAEA;;AACA;;AAIA;;AACA;;AAKA;;AAhBA;AACA;AACA;;AAWA;AACA;AACA;AAGA,MAAMA,sBAAsB,GAAG,C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GI,cAAc,IAAI,CAAEJ,SAApB,IACD,4BAAC,gCAAD;AACC,IAAA,KAAK,EAAGG,oBADT;AAEC,IAAA,QAAQ,EAAGN,QAFZ;AAGC,IAAA,OAAO,EAAGD;AAHX,KAKC,4BAAC,uBAAD;AACC,IAAA,WAAW,EAAGO,oBADf;AAEC,IAAA,QAAQ,EAAGrC;AAFZ,IALD,CAlBF,EA8BG,CAAEsC,cAAF,IAAoB,CAAEJ,SAAtB,IACD;AAAG,IAAA,SAAS,EAAC;AAAb,KACG,cAAI,2BAAJ,CADH,CA/BF,CADD;AAsCA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useSelect } from '@wordpress/data';\nimport { useState, useEffect } from '@wordpress/element';\nimport { store as coreStore, useEntityBlockEditor } from '@wordpress/core-data';\nimport {\n\tstore as blockEditorStore,\n\tBlockEditorProvider,\n} from '@wordpress/block-editor';\nimport { speak } from '@wordpress/a11y';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport NavigationMenu from './navigation-menu';\n\nconst NAVIGATION_MENUS_QUERY = [ { per_page: -1, status: 'publish' } ];\n\nexport default function NavigationInspector( { onSelect } ) {\n\tconst {\n\t\tselectedNavigationBlockId,\n\t\tclientIdToRef,\n\t\tnavigationMenus,\n\t\tisResolvingNavigationMenus,\n\t\thasResolvedNavigationMenus,\n\t\tfirstNavigationBlockId,\n\t} = useSelect( ( select ) => {\n\t\tconst {\n\t\t\t__experimentalGetActiveBlockIdByBlockNames,\n\t\t\t__experimentalGetGlobalBlocksByName,\n\t\t\tgetBlock,\n\t\t} = select( blockEditorStore );\n\n\t\tconst { getEntityRecords, hasFinishedResolution, isResolving } =\n\t\t\tselect( coreStore );\n\n\t\tconst navigationMenusQuery = [\n\t\t\t'postType',\n\t\t\t'wp_navigation',\n\t\t\tNAVIGATION_MENUS_QUERY[ 0 ],\n\t\t];\n\n\t\t// Get the active Navigation block (if present).\n\t\tconst selectedNavId =\n\t\t\t__experimentalGetActiveBlockIdByBlockNames( 'core/navigation' );\n\n\t\t// Get all Navigation blocks currently within the editor canvas.\n\t\tconst navBlockIds =\n\t\t\t__experimentalGetGlobalBlocksByName( 'core/navigation' );\n\t\tconst idToRef = {};\n\t\tnavBlockIds.forEach( ( id ) => {\n\t\t\tidToRef[ id ] = getBlock( id )?.attributes?.ref;\n\t\t} );\n\t\treturn {\n\t\t\tselectedNavigationBlockId: selectedNavId,\n\t\t\tfirstNavigationBlockId: navBlockIds?.[ 0 ],\n\t\t\tclientIdToRef: idToRef,\n\t\t\tnavigationMenus: getEntityRecords( ...navigationMenusQuery ),\n\t\t\tisResolvingNavigationMenus: isResolving(\n\t\t\t\t'getEntityRecords',\n\t\t\t\tnavigationMenusQuery\n\t\t\t),\n\t\t\thasResolvedNavigationMenus: hasFinishedResolution(\n\t\t\t\t'getEntityRecords',\n\t\t\t\tnavigationMenusQuery\n\t\t\t),\n\t\t};\n\t}, [] );\n\n\tconst firstNavRefInTemplate = clientIdToRef[ firstNavigationBlockId ];\n\tconst firstNavigationMenuRef = navigationMenus?.[ 0 ]?.id;\n\n\t// Default Navigation Menu is either:\n\t// - the Navigation Menu referenced by the first Nav block within the template.\n\t// - the first of the available Navigation Menus (`wp_navigation`) posts.\n\tconst defaultNavigationMenuId =\n\t\tfirstNavRefInTemplate || firstNavigationMenuRef;\n\n\t// The Navigation Menu manually selected by the user within the Nav inspector.\n\tconst [ currentMenuId, setCurrentMenuId ] = useState(\n\t\tfirstNavRefInTemplate\n\t);\n\n\t// If a Nav block is selected within the canvas then set the\n\t// Navigation Menu referenced by it's `ref` attribute to be\n\t// active within the Navigation sidebar.\n\tuseEffect( () => {\n\t\tif ( selectedNavigationBlockId ) {\n\t\t\tsetCurrentMenuId( clientIdToRef[ selectedNavigationBlockId ] );\n\t\t}\n\t}, [ selectedNavigationBlockId ] );\n\n\tconst [ innerBlocks, onInput, onChange ] = useEntityBlockEditor(\n\t\t'postType',\n\t\t'wp_navigation',\n\t\t{ id: currentMenuId || defaultNavigationMenuId }\n\t);\n\n\tconst { isLoadingInnerBlocks, hasLoadedInnerBlocks } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { isResolving, hasFinishedResolution } = select( coreStore );\n\t\t\treturn {\n\t\t\t\tisLoadingInnerBlocks: isResolving( 'getEntityRecord', [\n\t\t\t\t\t'postType',\n\t\t\t\t\t'wp_navigation',\n\t\t\t\t\tcurrentMenuId || defaultNavigationMenuId,\n\t\t\t\t] ),\n\t\t\t\thasLoadedInnerBlocks: hasFinishedResolution(\n\t\t\t\t\t'getEntityRecord',\n\t\t\t\t\t[\n\t\t\t\t\t\t'postType',\n\t\t\t\t\t\t'wp_navigation',\n\t\t\t\t\t\tcurrentMenuId || defaultNavigationMenuId,\n\t\t\t\t\t]\n\t\t\t\t),\n\t\t\t};\n\t\t},\n\t\t[ currentMenuId, defaultNavigationMenuId ]\n\t);\n\n\tconst isLoading = ! ( hasResolvedNavigationMenus && hasLoadedInnerBlocks );\n\n\tconst hasNavigationMenus = !! navigationMenus?.length;\n\n\t// Entity block editor will return entities that are not currently published.\n\t// Guard by only allowing their usage if there are published Nav Menus.\n\tconst publishedInnerBlocks = hasNavigationMenus ? innerBlocks : [];\n\n\tconst hasInnerBlocks = !! publishedInnerBlocks?.length;\n\n\tuseEffect( () => {\n\t\tif ( isResolvingNavigationMenus ) {\n\t\t\tspeak( 'Loading Navigation sidebar menus.' );\n\t\t}\n\n\t\tif ( hasResolvedNavigationMenus ) {\n\t\t\tspeak( 'Navigation sidebar menus have loaded.' );\n\t\t}\n\t}, [ isResolvingNavigationMenus, hasResolvedNavigationMenus ] );\n\n\tuseEffect( () => {\n\t\tif ( isLoadingInnerBlocks ) {\n\t\t\tspeak( 'Loading Navigation sidebar selected menu items.' );\n\t\t}\n\n\t\tif ( hasLoadedInnerBlocks ) {\n\t\t\tspeak( 'Navigation sidebar selected menu items have loaded.' );\n\t\t}\n\t}, [ isLoadingInnerBlocks, hasLoadedInnerBlocks ] );\n\n\treturn (\n\t\t<div className=\"edit-site-navigation-inspector\">\n\t\t\t{ hasResolvedNavigationMenus && ! hasNavigationMenus && (\n\t\t\t\t<p className=\"edit-site-navigation-inspector__empty-msg\">\n\t\t\t\t\t{ __( 'There are no Navigation Menus.' ) }\n\t\t\t\t</p>\n\t\t\t) }\n\n\t\t\t{ ! hasResolvedNavigationMenus && (\n\t\t\t\t<div className=\"edit-site-navigation-inspector__placeholder\" />\n\t\t\t) }\n\t\t\t{ isLoading && (\n\t\t\t\t<>\n\t\t\t\t\t<div className=\"edit-site-navigation-inspector__placeholder is-child\" />\n\t\t\t\t\t<div className=\"edit-site-navigation-inspector__placeholder is-child\" />\n\t\t\t\t\t<div className=\"edit-site-navigation-inspector__placeholder is-child\" />\n\t\t\t\t</>\n\t\t\t) }\n\t\t\t{ hasInnerBlocks && ! isLoading && (\n\t\t\t\t<BlockEditorProvider\n\t\t\t\t\tvalue={ publishedInnerBlocks }\n\t\t\t\t\tonChange={ onChange }\n\t\t\t\t\tonInput={ onInput }\n\t\t\t\t>\n\t\t\t\t\t<NavigationMenu\n\t\t\t\t\t\tinnerBlocks={ publishedInnerBlocks }\n\t\t\t\t\t\tonSelect={ onSelect }\n\t\t\t\t\t/>\n\t\t\t\t</BlockEditorProvider>\n\t\t\t) }\n\n\t\t\t{ ! hasInnerBlocks && ! isLoading && (\n\t\t\t\t<p className=\"edit-site-navigation-inspector__empty-msg\">\n\t\t\t\t\t{ __( 'Navigation Menu is empty.' ) }\n\t\t\t\t</p>\n\t\t\t) }\n\t\t</div>\n\t);\n}\n"]}
@@ -1,79 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = NavigationMenu;
7
-
8
- var _element = require("@wordpress/element");
9
-
10
- var _blockEditor = require("@wordpress/block-editor");
11
-
12
- var _data = require("@wordpress/data");
13
-
14
- var _privateApis = require("../../private-apis");
15
-
16
- /**
17
- * WordPress dependencies
18
- */
19
-
20
- /**
21
- * Internal dependencies
22
- */
23
- const ALLOWED_BLOCKS = {
24
- 'core/navigation': ['core/navigation-link', 'core/search', 'core/social-links', 'core/page-list', 'core/spacer', 'core/home-link', 'core/site-title', 'core/site-logo', 'core/navigation-submenu'],
25
- 'core/social-links': ['core/social-link'],
26
- 'core/navigation-submenu': ['core/navigation-link', 'core/navigation-submenu'],
27
- 'core/navigation-link': ['core/navigation-link', 'core/navigation-submenu'],
28
- 'core/page-list': ['core/page-list-item']
29
- };
30
-
31
- function NavigationMenu(_ref) {
32
- let {
33
- innerBlocks,
34
- onSelect
35
- } = _ref;
36
- const {
37
- clientIdsTree
38
- } = (0, _data.useSelect)(select => {
39
- const {
40
- __unstableGetClientIdsTree
41
- } = select(_blockEditor.store);
42
- return {
43
- clientIdsTree: __unstableGetClientIdsTree()
44
- };
45
- });
46
- const {
47
- updateBlockListSettings
48
- } = (0, _data.useDispatch)(_blockEditor.store);
49
- const {
50
- OffCanvasEditor,
51
- LeafMoreMenu
52
- } = (0, _privateApis.unlock)(_blockEditor.privateApis); //TODO: Block settings are normally updated as a side effect of rendering InnerBlocks in BlockList
53
- //Think through a better way of doing this, possible with adding allowed blocks to block library metadata
54
-
55
- (0, _element.useEffect)(() => {
56
- updateBlockListSettings('', {
57
- allowedBlocks: ALLOWED_BLOCKS['core/navigation']
58
- });
59
- innerBlocks.forEach(block => {
60
- if (ALLOWED_BLOCKS[block.name]) {
61
- updateBlockListSettings(block.clientId, {
62
- allowedBlocks: ALLOWED_BLOCKS[block.name]
63
- });
64
- }
65
- });
66
- }, [updateBlockListSettings, innerBlocks]); // The hidden block is needed because it makes block edit side effects trigger.
67
- // For example a navigation page list load its items has an effect on edit to load its items.
68
-
69
- return (0, _element.createElement)(_element.Fragment, null, (0, _element.createElement)(OffCanvasEditor, {
70
- blocks: clientIdsTree,
71
- onSelect: onSelect,
72
- LeafMoreMenu: LeafMoreMenu
73
- }), (0, _element.createElement)("div", {
74
- style: {
75
- display: 'none'
76
- }
77
- }, (0, _element.createElement)(_blockEditor.BlockTools, null, (0, _element.createElement)(_blockEditor.BlockList, null))));
78
- }
79
- //# sourceMappingURL=navigation-menu.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["@wordpress/edit-site/src/components/navigation-inspector/navigation-menu.js"],"names":["ALLOWED_BLOCKS","NavigationMenu","innerBlocks","onSelect","clientIdsTree","select","__unstableGetClientIdsTree","blockEditorStore","updateBlockListSettings","OffCanvasEditor","LeafMoreMenu","blockEditorPrivateApis","allowedBlocks","forEach","block","name","clientId","display"],"mappings":";;;;;;;AASA;;AANA;;AAOA;;AAKA;;AAfA;AACA;AACA;;AAUA;AACA;AACA;AAGA,MAAMA,cAAc,GAAG;AACtB,qBAAmB,CAClB,sBADkB,EAElB,aAFkB,EAGlB,mBAHkB,EAIlB,gBAJkB,EAKlB,aALkB,EAMlB,gBANkB,EAOlB,iBAPkB,EAQlB,gBARkB,EASlB,yBATkB,CADG;AAYtB,uBAAqB,CAAE,kBAAF,CAZC;AAatB,6BAA2B,CAC1B,sBAD0B,EAE1B,yBAF0B,CAbL;AAiBtB,0BAAwB,CACvB,sBADuB,EAEvB,yBAFuB,CAjBF;AAqBtB,oBAAkB,CAAE,qBAAF;AArBI,CAAvB;;AAwBe,SAASC,cAAT,OAAqD;AAAA,MAA5B;AAAEC,IAAAA,WAAF;AAAeC,IAAAA;AAAf,GAA4B;AACnE,QAAM;AAAEC,IAAAA;AAAF,MAAoB,qBAAaC,MAAF,IAAc;AAClD,UAAM;AAAEC,MAAAA;AAAF,QAAiCD,MAAM,CAAEE,kBAAF,CAA7C;AACA,WAAO;AACNH,MAAAA,aAAa,EAAEE,0BAA0B;AADnC,KAAP;AAGA,GALyB,CAA1B;AAMA,QAAM;AAAEE,IAAAA;AAAF,MAA8B,uBAAaD,kBAAb,CAApC;AAEA,QAAM;AAAEE,IAAAA,eAAF;AAAmBC,IAAAA;AAAnB,MAAoC,yBAAQC,wBAAR,CAA1C,CATmE,CAWnE;AACA;;AACA,0BAAW,MAAM;AAChBH,IAAAA,uBAAuB,CAAE,EAAF,EAAM;AAC5BI,MAAAA,aAAa,EAAEZ,cAAc,CAAE,iBAAF;AADD,KAAN,CAAvB;AAGAE,IAAAA,WAAW,CAACW,OAAZ,CAAuBC,KAAF,IAAa;AACjC,UAAKd,cAAc,CAAEc,KAAK,CAACC,IAAR,CAAnB,EAAoC;AACnCP,QAAAA,uBAAuB,CAAEM,KAAK,CAACE,QAAR,EAAkB;AACxCJ,UAAAA,aAAa,EAAEZ,cAAc,CAAEc,KAAK,CAACC,IAAR;AADW,SAAlB,CAAvB;AAGA;AACD,KAND;AAOA,GAXD,EAWG,CAAEP,uBAAF,EAA2BN,WAA3B,CAXH,EAbmE,CA0BnE;AACA;;AACA,SACC,qDACC,4BAAC,eAAD;AACC,IAAA,MAAM,EAAGE,aADV;AAEC,IAAA,QAAQ,EAAGD,QAFZ;AAGC,IAAA,YAAY,EAAGO;AAHhB,IADD,EAMC;AAAK,IAAA,KAAK,EAAG;AAAEO,MAAAA,OAAO,EAAE;AAAX;AAAb,KACC,4BAAC,uBAAD,QACC,4BAAC,sBAAD,OADD,CADD,CAND,CADD;AAcA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\tprivateApis as blockEditorPrivateApis,\n\tstore as blockEditorStore,\n\tBlockList,\n\tBlockTools,\n} from '@wordpress/block-editor';\nimport { useEffect } from '@wordpress/element';\nimport { useSelect, useDispatch } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { unlock } from '../../private-apis';\n\nconst ALLOWED_BLOCKS = {\n\t'core/navigation': [\n\t\t'core/navigation-link',\n\t\t'core/search',\n\t\t'core/social-links',\n\t\t'core/page-list',\n\t\t'core/spacer',\n\t\t'core/home-link',\n\t\t'core/site-title',\n\t\t'core/site-logo',\n\t\t'core/navigation-submenu',\n\t],\n\t'core/social-links': [ 'core/social-link' ],\n\t'core/navigation-submenu': [\n\t\t'core/navigation-link',\n\t\t'core/navigation-submenu',\n\t],\n\t'core/navigation-link': [\n\t\t'core/navigation-link',\n\t\t'core/navigation-submenu',\n\t],\n\t'core/page-list': [ 'core/page-list-item' ],\n};\n\nexport default function NavigationMenu( { innerBlocks, onSelect } ) {\n\tconst { clientIdsTree } = useSelect( ( select ) => {\n\t\tconst { __unstableGetClientIdsTree } = select( blockEditorStore );\n\t\treturn {\n\t\t\tclientIdsTree: __unstableGetClientIdsTree(),\n\t\t};\n\t} );\n\tconst { updateBlockListSettings } = useDispatch( blockEditorStore );\n\n\tconst { OffCanvasEditor, LeafMoreMenu } = unlock( blockEditorPrivateApis );\n\n\t//TODO: Block settings are normally updated as a side effect of rendering InnerBlocks in BlockList\n\t//Think through a better way of doing this, possible with adding allowed blocks to block library metadata\n\tuseEffect( () => {\n\t\tupdateBlockListSettings( '', {\n\t\t\tallowedBlocks: ALLOWED_BLOCKS[ 'core/navigation' ],\n\t\t} );\n\t\tinnerBlocks.forEach( ( block ) => {\n\t\t\tif ( ALLOWED_BLOCKS[ block.name ] ) {\n\t\t\t\tupdateBlockListSettings( block.clientId, {\n\t\t\t\t\tallowedBlocks: ALLOWED_BLOCKS[ block.name ],\n\t\t\t\t} );\n\t\t\t}\n\t\t} );\n\t}, [ updateBlockListSettings, innerBlocks ] );\n\n\t// The hidden block is needed because it makes block edit side effects trigger.\n\t// For example a navigation page list load its items has an effect on edit to load its items.\n\treturn (\n\t\t<>\n\t\t\t<OffCanvasEditor\n\t\t\t\tblocks={ clientIdsTree }\n\t\t\t\tonSelect={ onSelect }\n\t\t\t\tLeafMoreMenu={ LeafMoreMenu }\n\t\t\t/>\n\t\t\t<div style={ { display: 'none' } }>\n\t\t\t\t<BlockTools>\n\t\t\t\t\t<BlockList />\n\t\t\t\t</BlockTools>\n\t\t\t</div>\n\t\t</>\n\t);\n}\n"]}
@@ -1,146 +0,0 @@
1
- import { createElement, Fragment } from "@wordpress/element";
2
-
3
- /**
4
- * WordPress dependencies
5
- */
6
- import { useSelect } from '@wordpress/data';
7
- import { useState, useEffect } from '@wordpress/element';
8
- import { store as coreStore, useEntityBlockEditor } from '@wordpress/core-data';
9
- import { store as blockEditorStore, BlockEditorProvider } from '@wordpress/block-editor';
10
- import { speak } from '@wordpress/a11y';
11
- import { __ } from '@wordpress/i18n';
12
- /**
13
- * Internal dependencies
14
- */
15
-
16
- import NavigationMenu from './navigation-menu';
17
- const NAVIGATION_MENUS_QUERY = [{
18
- per_page: -1,
19
- status: 'publish'
20
- }];
21
- export default function NavigationInspector(_ref) {
22
- var _navigationMenus$;
23
-
24
- let {
25
- onSelect
26
- } = _ref;
27
- const {
28
- selectedNavigationBlockId,
29
- clientIdToRef,
30
- navigationMenus,
31
- isResolvingNavigationMenus,
32
- hasResolvedNavigationMenus,
33
- firstNavigationBlockId
34
- } = useSelect(select => {
35
- const {
36
- __experimentalGetActiveBlockIdByBlockNames,
37
- __experimentalGetGlobalBlocksByName,
38
- getBlock
39
- } = select(blockEditorStore);
40
- const {
41
- getEntityRecords,
42
- hasFinishedResolution,
43
- isResolving
44
- } = select(coreStore);
45
- const navigationMenusQuery = ['postType', 'wp_navigation', NAVIGATION_MENUS_QUERY[0]]; // Get the active Navigation block (if present).
46
-
47
- const selectedNavId = __experimentalGetActiveBlockIdByBlockNames('core/navigation'); // Get all Navigation blocks currently within the editor canvas.
48
-
49
-
50
- const navBlockIds = __experimentalGetGlobalBlocksByName('core/navigation');
51
-
52
- const idToRef = {};
53
- navBlockIds.forEach(id => {
54
- var _getBlock, _getBlock$attributes;
55
-
56
- idToRef[id] = (_getBlock = getBlock(id)) === null || _getBlock === void 0 ? void 0 : (_getBlock$attributes = _getBlock.attributes) === null || _getBlock$attributes === void 0 ? void 0 : _getBlock$attributes.ref;
57
- });
58
- return {
59
- selectedNavigationBlockId: selectedNavId,
60
- firstNavigationBlockId: navBlockIds === null || navBlockIds === void 0 ? void 0 : navBlockIds[0],
61
- clientIdToRef: idToRef,
62
- navigationMenus: getEntityRecords(...navigationMenusQuery),
63
- isResolvingNavigationMenus: isResolving('getEntityRecords', navigationMenusQuery),
64
- hasResolvedNavigationMenus: hasFinishedResolution('getEntityRecords', navigationMenusQuery)
65
- };
66
- }, []);
67
- const firstNavRefInTemplate = clientIdToRef[firstNavigationBlockId];
68
- const firstNavigationMenuRef = navigationMenus === null || navigationMenus === void 0 ? void 0 : (_navigationMenus$ = navigationMenus[0]) === null || _navigationMenus$ === void 0 ? void 0 : _navigationMenus$.id; // Default Navigation Menu is either:
69
- // - the Navigation Menu referenced by the first Nav block within the template.
70
- // - the first of the available Navigation Menus (`wp_navigation`) posts.
71
-
72
- const defaultNavigationMenuId = firstNavRefInTemplate || firstNavigationMenuRef; // The Navigation Menu manually selected by the user within the Nav inspector.
73
-
74
- const [currentMenuId, setCurrentMenuId] = useState(firstNavRefInTemplate); // If a Nav block is selected within the canvas then set the
75
- // Navigation Menu referenced by it's `ref` attribute to be
76
- // active within the Navigation sidebar.
77
-
78
- useEffect(() => {
79
- if (selectedNavigationBlockId) {
80
- setCurrentMenuId(clientIdToRef[selectedNavigationBlockId]);
81
- }
82
- }, [selectedNavigationBlockId]);
83
- const [innerBlocks, onInput, onChange] = useEntityBlockEditor('postType', 'wp_navigation', {
84
- id: currentMenuId || defaultNavigationMenuId
85
- });
86
- const {
87
- isLoadingInnerBlocks,
88
- hasLoadedInnerBlocks
89
- } = useSelect(select => {
90
- const {
91
- isResolving,
92
- hasFinishedResolution
93
- } = select(coreStore);
94
- return {
95
- isLoadingInnerBlocks: isResolving('getEntityRecord', ['postType', 'wp_navigation', currentMenuId || defaultNavigationMenuId]),
96
- hasLoadedInnerBlocks: hasFinishedResolution('getEntityRecord', ['postType', 'wp_navigation', currentMenuId || defaultNavigationMenuId])
97
- };
98
- }, [currentMenuId, defaultNavigationMenuId]);
99
- const isLoading = !(hasResolvedNavigationMenus && hasLoadedInnerBlocks);
100
- const hasNavigationMenus = !!(navigationMenus !== null && navigationMenus !== void 0 && navigationMenus.length); // Entity block editor will return entities that are not currently published.
101
- // Guard by only allowing their usage if there are published Nav Menus.
102
-
103
- const publishedInnerBlocks = hasNavigationMenus ? innerBlocks : [];
104
- const hasInnerBlocks = !!(publishedInnerBlocks !== null && publishedInnerBlocks !== void 0 && publishedInnerBlocks.length);
105
- useEffect(() => {
106
- if (isResolvingNavigationMenus) {
107
- speak('Loading Navigation sidebar menus.');
108
- }
109
-
110
- if (hasResolvedNavigationMenus) {
111
- speak('Navigation sidebar menus have loaded.');
112
- }
113
- }, [isResolvingNavigationMenus, hasResolvedNavigationMenus]);
114
- useEffect(() => {
115
- if (isLoadingInnerBlocks) {
116
- speak('Loading Navigation sidebar selected menu items.');
117
- }
118
-
119
- if (hasLoadedInnerBlocks) {
120
- speak('Navigation sidebar selected menu items have loaded.');
121
- }
122
- }, [isLoadingInnerBlocks, hasLoadedInnerBlocks]);
123
- return createElement("div", {
124
- className: "edit-site-navigation-inspector"
125
- }, hasResolvedNavigationMenus && !hasNavigationMenus && createElement("p", {
126
- className: "edit-site-navigation-inspector__empty-msg"
127
- }, __('There are no Navigation Menus.')), !hasResolvedNavigationMenus && createElement("div", {
128
- className: "edit-site-navigation-inspector__placeholder"
129
- }), isLoading && createElement(Fragment, null, createElement("div", {
130
- className: "edit-site-navigation-inspector__placeholder is-child"
131
- }), createElement("div", {
132
- className: "edit-site-navigation-inspector__placeholder is-child"
133
- }), createElement("div", {
134
- className: "edit-site-navigation-inspector__placeholder is-child"
135
- })), hasInnerBlocks && !isLoading && createElement(BlockEditorProvider, {
136
- value: publishedInnerBlocks,
137
- onChange: onChange,
138
- onInput: onInput
139
- }, createElement(NavigationMenu, {
140
- innerBlocks: publishedInnerBlocks,
141
- onSelect: onSelect
142
- })), !hasInnerBlocks && !isLoading && createElement("p", {
143
- className: "edit-site-navigation-inspector__empty-msg"
144
- }, __('Navigation Menu is empty.')));
145
- }
146
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["@wordpress/edit-site/src/components/navigation-inspector/index.js"],"names":["useSelect","useState","useEffect","store","coreStore","useEntityBlockEditor","blockEditorStore","BlockEditorProvider","speak","__","NavigationMenu","NAVIGATION_MENUS_QUERY","per_page","status","NavigationInspector","onSelect","selectedNavigationBlockId","clientIdToRef","navigationMenus","isResolvingNavigationMenus","hasResolvedNavigationMenus","firstNavigationBlockId","select","__experimentalGetActiveBlockIdByBlockNames","__experimentalGetGlobalBlocksByName","getBlock","getEntityRecords","hasFinishedResolution","isResolving","navigationMenusQuery","selectedNavId","navBlockIds","idToRef","forEach","id","attributes","ref","firstNavRefInTemplate","firstNavigationMenuRef","defaultNavigationMenuId","currentMenuId","setCurrentMenuId","innerBlocks","onInput","onChange","isLoadingInnerBlocks","hasLoadedInnerBlocks","isLoading","hasNavigationMenus","length","publishedInnerBlocks","hasInnerBlocks"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,SAAT,QAA0B,iBAA1B;AACA,SAASC,QAAT,EAAmBC,SAAnB,QAAoC,oBAApC;AACA,SAASC,KAAK,IAAIC,SAAlB,EAA6BC,oBAA7B,QAAyD,sBAAzD;AACA,SACCF,KAAK,IAAIG,gBADV,EAECC,mBAFD,QAGO,yBAHP;AAIA,SAASC,KAAT,QAAsB,iBAAtB;AACA,SAASC,EAAT,QAAmB,iBAAnB;AAEA;AACA;AACA;;AACA,OAAOC,cAAP,MAA2B,mBAA3B;AAEA,MAAMC,sBAAsB,GAAG,CAAE;AAAEC,EAAAA,QAAQ,EAAE,CAAC,CAAb;AAAgBC,EAAAA,MAAM,EAAE;AAAxB,CAAF,CAA/B;AAEA,eAAe,SAASC,mBAAT,OAA6C;AAAA;;AAAA,MAAf;AAAEC,IAAAA;AAAF,GAAe;AAC3D,QAAM;AACLC,IAAAA,yBADK;AAELC,IAAAA,aAFK;AAGLC,IAAAA,eAHK;AAILC,IAAAA,0BAJK;AAKLC,IAAAA,0BALK;AAMLC,IAAAA;AANK,MAOFrB,SAAS,CAAIsB,MAAF,IAAc;AAC5B,UAAM;AACLC,MAAAA,0CADK;AAELC,MAAAA,mCAFK;AAGLC,MAAAA;AAH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FZ,IALD,CAlBF,EA8BG,CAAEoC,cAAF,IAAoB,CAAEJ,SAAtB,IACD;AAAG,IAAA,SAAS,EAAC;AAAb,KACGtC,EAAE,CAAE,2BAAF,CADL,CA/BF,CADD;AAsCA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useSelect } from '@wordpress/data';\nimport { useState, useEffect } from '@wordpress/element';\nimport { store as coreStore, useEntityBlockEditor } from '@wordpress/core-data';\nimport {\n\tstore as blockEditorStore,\n\tBlockEditorProvider,\n} from '@wordpress/block-editor';\nimport { speak } from '@wordpress/a11y';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport NavigationMenu from './navigation-menu';\n\nconst NAVIGATION_MENUS_QUERY = [ { per_page: -1, status: 'publish' } ];\n\nexport default function NavigationInspector( { onSelect } ) {\n\tconst {\n\t\tselectedNavigationBlockId,\n\t\tclientIdToRef,\n\t\tnavigationMenus,\n\t\tisResolvingNavigationMenus,\n\t\thasResolvedNavigationMenus,\n\t\tfirstNavigationBlockId,\n\t} = useSelect( ( select ) => {\n\t\tconst {\n\t\t\t__experimentalGetActiveBlockIdByBlockNames,\n\t\t\t__experimentalGetGlobalBlocksByName,\n\t\t\tgetBlock,\n\t\t} = select( blockEditorStore );\n\n\t\tconst { getEntityRecords, hasFinishedResolution, isResolving } =\n\t\t\tselect( coreStore );\n\n\t\tconst navigationMenusQuery = [\n\t\t\t'postType',\n\t\t\t'wp_navigation',\n\t\t\tNAVIGATION_MENUS_QUERY[ 0 ],\n\t\t];\n\n\t\t// Get the active Navigation block (if present).\n\t\tconst selectedNavId =\n\t\t\t__experimentalGetActiveBlockIdByBlockNames( 'core/navigation' );\n\n\t\t// Get all Navigation blocks currently within the editor canvas.\n\t\tconst navBlockIds =\n\t\t\t__experimentalGetGlobalBlocksByName( 'core/navigation' );\n\t\tconst idToRef = {};\n\t\tnavBlockIds.forEach( ( id ) => {\n\t\t\tidToRef[ id ] = getBlock( id )?.attributes?.ref;\n\t\t} );\n\t\treturn {\n\t\t\tselectedNavigationBlockId: selectedNavId,\n\t\t\tfirstNavigationBlockId: navBlockIds?.[ 0 ],\n\t\t\tclientIdToRef: idToRef,\n\t\t\tnavigationMenus: getEntityRecords( ...navigationMenusQuery ),\n\t\t\tisResolvingNavigationMenus: isResolving(\n\t\t\t\t'getEntityRecords',\n\t\t\t\tnavigationMenusQuery\n\t\t\t),\n\t\t\thasResolvedNavigationMenus: hasFinishedResolution(\n\t\t\t\t'getEntityRecords',\n\t\t\t\tnavigationMenusQuery\n\t\t\t),\n\t\t};\n\t}, [] );\n\n\tconst firstNavRefInTemplate = clientIdToRef[ firstNavigationBlockId ];\n\tconst firstNavigationMenuRef = navigationMenus?.[ 0 ]?.id;\n\n\t// Default Navigation Menu is either:\n\t// - the Navigation Menu referenced by the first Nav block within the template.\n\t// - the first of the available Navigation Menus (`wp_navigation`) posts.\n\tconst defaultNavigationMenuId =\n\t\tfirstNavRefInTemplate || firstNavigationMenuRef;\n\n\t// The Navigation Menu manually selected by the user within the Nav inspector.\n\tconst [ currentMenuId, setCurrentMenuId ] = useState(\n\t\tfirstNavRefInTemplate\n\t);\n\n\t// If a Nav block is selected within the canvas then set the\n\t// Navigation Menu referenced by it's `ref` attribute to be\n\t// active within the Navigation sidebar.\n\tuseEffect( () => {\n\t\tif ( selectedNavigationBlockId ) {\n\t\t\tsetCurrentMenuId( clientIdToRef[ selectedNavigationBlockId ] );\n\t\t}\n\t}, [ selectedNavigationBlockId ] );\n\n\tconst [ innerBlocks, onInput, onChange ] = useEntityBlockEditor(\n\t\t'postType',\n\t\t'wp_navigation',\n\t\t{ id: currentMenuId || defaultNavigationMenuId }\n\t);\n\n\tconst { isLoadingInnerBlocks, hasLoadedInnerBlocks } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { isResolving, hasFinishedResolution } = select( coreStore );\n\t\t\treturn {\n\t\t\t\tisLoadingInnerBlocks: isResolving( 'getEntityRecord', [\n\t\t\t\t\t'postType',\n\t\t\t\t\t'wp_navigation',\n\t\t\t\t\tcurrentMenuId || defaultNavigationMenuId,\n\t\t\t\t] ),\n\t\t\t\thasLoadedInnerBlocks: hasFinishedResolution(\n\t\t\t\t\t'getEntityRecord',\n\t\t\t\t\t[\n\t\t\t\t\t\t'postType',\n\t\t\t\t\t\t'wp_navigation',\n\t\t\t\t\t\tcurrentMenuId || defaultNavigationMenuId,\n\t\t\t\t\t]\n\t\t\t\t),\n\t\t\t};\n\t\t},\n\t\t[ currentMenuId, defaultNavigationMenuId ]\n\t);\n\n\tconst isLoading = ! ( hasResolvedNavigationMenus && hasLoadedInnerBlocks );\n\n\tconst hasNavigationMenus = !! navigationMenus?.length;\n\n\t// Entity block editor will return entities that are not currently published.\n\t// Guard by only allowing their usage if there are published Nav Menus.\n\tconst publishedInnerBlocks = hasNavigationMenus ? innerBlocks : [];\n\n\tconst hasInnerBlocks = !! publishedInnerBlocks?.length;\n\n\tuseEffect( () => {\n\t\tif ( isResolvingNavigationMenus ) {\n\t\t\tspeak( 'Loading Navigation sidebar menus.' );\n\t\t}\n\n\t\tif ( hasResolvedNavigationMenus ) {\n\t\t\tspeak( 'Navigation sidebar menus have loaded.' );\n\t\t}\n\t}, [ isResolvingNavigationMenus, hasResolvedNavigationMenus ] );\n\n\tuseEffect( () => {\n\t\tif ( isLoadingInnerBlocks ) {\n\t\t\tspeak( 'Loading Navigation sidebar selected menu items.' );\n\t\t}\n\n\t\tif ( hasLoadedInnerBlocks ) {\n\t\t\tspeak( 'Navigation sidebar selected menu items have loaded.' );\n\t\t}\n\t}, [ isLoadingInnerBlocks, hasLoadedInnerBlocks ] );\n\n\treturn (\n\t\t<div className=\"edit-site-navigation-inspector\">\n\t\t\t{ hasResolvedNavigationMenus && ! hasNavigationMenus && (\n\t\t\t\t<p className=\"edit-site-navigation-inspector__empty-msg\">\n\t\t\t\t\t{ __( 'There are no Navigation Menus.' ) }\n\t\t\t\t</p>\n\t\t\t) }\n\n\t\t\t{ ! hasResolvedNavigationMenus && (\n\t\t\t\t<div className=\"edit-site-navigation-inspector__placeholder\" />\n\t\t\t) }\n\t\t\t{ isLoading && (\n\t\t\t\t<>\n\t\t\t\t\t<div className=\"edit-site-navigation-inspector__placeholder is-child\" />\n\t\t\t\t\t<div className=\"edit-site-navigation-inspector__placeholder is-child\" />\n\t\t\t\t\t<div className=\"edit-site-navigation-inspector__placeholder is-child\" />\n\t\t\t\t</>\n\t\t\t) }\n\t\t\t{ hasInnerBlocks && ! isLoading && (\n\t\t\t\t<BlockEditorProvider\n\t\t\t\t\tvalue={ publishedInnerBlocks }\n\t\t\t\t\tonChange={ onChange }\n\t\t\t\t\tonInput={ onInput }\n\t\t\t\t>\n\t\t\t\t\t<NavigationMenu\n\t\t\t\t\t\tinnerBlocks={ publishedInnerBlocks }\n\t\t\t\t\t\tonSelect={ onSelect }\n\t\t\t\t\t/>\n\t\t\t\t</BlockEditorProvider>\n\t\t\t) }\n\n\t\t\t{ ! hasInnerBlocks && ! isLoading && (\n\t\t\t\t<p className=\"edit-site-navigation-inspector__empty-msg\">\n\t\t\t\t\t{ __( 'Navigation Menu is empty.' ) }\n\t\t\t\t</p>\n\t\t\t) }\n\t\t</div>\n\t);\n}\n"]}
@@ -1,69 +0,0 @@
1
- import { createElement, Fragment } from "@wordpress/element";
2
-
3
- /**
4
- * WordPress dependencies
5
- */
6
- import { privateApis as blockEditorPrivateApis, store as blockEditorStore, BlockList, BlockTools } from '@wordpress/block-editor';
7
- import { useEffect } from '@wordpress/element';
8
- import { useSelect, useDispatch } from '@wordpress/data';
9
- /**
10
- * Internal dependencies
11
- */
12
-
13
- import { unlock } from '../../private-apis';
14
- const ALLOWED_BLOCKS = {
15
- 'core/navigation': ['core/navigation-link', 'core/search', 'core/social-links', 'core/page-list', 'core/spacer', 'core/home-link', 'core/site-title', 'core/site-logo', 'core/navigation-submenu'],
16
- 'core/social-links': ['core/social-link'],
17
- 'core/navigation-submenu': ['core/navigation-link', 'core/navigation-submenu'],
18
- 'core/navigation-link': ['core/navigation-link', 'core/navigation-submenu'],
19
- 'core/page-list': ['core/page-list-item']
20
- };
21
- export default function NavigationMenu(_ref) {
22
- let {
23
- innerBlocks,
24
- onSelect
25
- } = _ref;
26
- const {
27
- clientIdsTree
28
- } = useSelect(select => {
29
- const {
30
- __unstableGetClientIdsTree
31
- } = select(blockEditorStore);
32
- return {
33
- clientIdsTree: __unstableGetClientIdsTree()
34
- };
35
- });
36
- const {
37
- updateBlockListSettings
38
- } = useDispatch(blockEditorStore);
39
- const {
40
- OffCanvasEditor,
41
- LeafMoreMenu
42
- } = unlock(blockEditorPrivateApis); //TODO: Block settings are normally updated as a side effect of rendering InnerBlocks in BlockList
43
- //Think through a better way of doing this, possible with adding allowed blocks to block library metadata
44
-
45
- useEffect(() => {
46
- updateBlockListSettings('', {
47
- allowedBlocks: ALLOWED_BLOCKS['core/navigation']
48
- });
49
- innerBlocks.forEach(block => {
50
- if (ALLOWED_BLOCKS[block.name]) {
51
- updateBlockListSettings(block.clientId, {
52
- allowedBlocks: ALLOWED_BLOCKS[block.name]
53
- });
54
- }
55
- });
56
- }, [updateBlockListSettings, innerBlocks]); // The hidden block is needed because it makes block edit side effects trigger.
57
- // For example a navigation page list load its items has an effect on edit to load its items.
58
-
59
- return createElement(Fragment, null, createElement(OffCanvasEditor, {
60
- blocks: clientIdsTree,
61
- onSelect: onSelect,
62
- LeafMoreMenu: LeafMoreMenu
63
- }), createElement("div", {
64
- style: {
65
- display: 'none'
66
- }
67
- }, createElement(BlockTools, null, createElement(BlockList, null))));
68
- }
69
- //# sourceMappingURL=navigation-menu.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["@wordpress/edit-site/src/components/navigation-inspector/navigation-menu.js"],"names":["privateApis","blockEditorPrivateApis","store","blockEditorStore","BlockList","BlockTools","useEffect","useSelect","useDispatch","unlock","ALLOWED_BLOCKS","NavigationMenu","innerBlocks","onSelect","clientIdsTree","select","__unstableGetClientIdsTree","updateBlockListSettings","OffCanvasEditor","LeafMoreMenu","all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BAAF;AADD,KAAN,CAAvB;AAGAE,IAAAA,WAAW,CAACS,OAAZ,CAAuBC,KAAF,IAAa;AACjC,UAAKZ,cAAc,CAAEY,KAAK,CAACC,IAAR,CAAnB,EAAoC;AACnCN,QAAAA,uBAAuB,CAAEK,KAAK,CAACE,QAAR,EAAkB;AACxCJ,UAAAA,aAAa,EAAEV,cAAc,CAAEY,KAAK,CAACC,IAAR;AADW,SAAlB,CAAvB;AAGA;AACD,KAND;AAOA,GAXQ,EAWN,CAAEN,uBAAF,EAA2BL,WAA3B,CAXM,CAAT,CAbmE,CA0BnE;AACA;;AACA,SACC,8BACC,cAAC,eAAD;AACC,IAAA,MAAM,EAAGE,aADV;AAEC,IAAA,QAAQ,EAAGD,QAFZ;AAGC,IAAA,YAAY,EAAGM;AAHhB,IADD,EAMC;AAAK,IAAA,KAAK,EAAG;AAAEM,MAAAA,OAAO,EAAE;AAAX;AAAb,KACC,cAAC,UAAD,QACC,cAAC,SAAD,OADD,CADD,CAND,CADD;AAcA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\tprivateApis as blockEditorPrivateApis,\n\tstore as blockEditorStore,\n\tBlockList,\n\tBlockTools,\n} from '@wordpress/block-editor';\nimport { useEffect } from '@wordpress/element';\nimport { useSelect, useDispatch } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { unlock } from '../../private-apis';\n\nconst ALLOWED_BLOCKS = {\n\t'core/navigation': [\n\t\t'core/navigation-link',\n\t\t'core/search',\n\t\t'core/social-links',\n\t\t'core/page-list',\n\t\t'core/spacer',\n\t\t'core/home-link',\n\t\t'core/site-title',\n\t\t'core/site-logo',\n\t\t'core/navigation-submenu',\n\t],\n\t'core/social-links': [ 'core/social-link' ],\n\t'core/navigation-submenu': [\n\t\t'core/navigation-link',\n\t\t'core/navigation-submenu',\n\t],\n\t'core/navigation-link': [\n\t\t'core/navigation-link',\n\t\t'core/navigation-submenu',\n\t],\n\t'core/page-list': [ 'core/page-list-item' ],\n};\n\nexport default function NavigationMenu( { innerBlocks, onSelect } ) {\n\tconst { clientIdsTree } = useSelect( ( select ) => {\n\t\tconst { __unstableGetClientIdsTree } = select( blockEditorStore );\n\t\treturn {\n\t\t\tclientIdsTree: __unstableGetClientIdsTree(),\n\t\t};\n\t} );\n\tconst { updateBlockListSettings } = useDispatch( blockEditorStore );\n\n\tconst { OffCanvasEditor, LeafMoreMenu } = unlock( blockEditorPrivateApis );\n\n\t//TODO: Block settings are normally updated as a side effect of rendering InnerBlocks in BlockList\n\t//Think through a better way of doing this, possible with adding allowed blocks to block library metadata\n\tuseEffect( () => {\n\t\tupdateBlockListSettings( '', {\n\t\t\tallowedBlocks: ALLOWED_BLOCKS[ 'core/navigation' ],\n\t\t} );\n\t\tinnerBlocks.forEach( ( block ) => {\n\t\t\tif ( ALLOWED_BLOCKS[ block.name ] ) {\n\t\t\t\tupdateBlockListSettings( block.clientId, {\n\t\t\t\t\tallowedBlocks: ALLOWED_BLOCKS[ block.name ],\n\t\t\t\t} );\n\t\t\t}\n\t\t} );\n\t}, [ updateBlockListSettings, innerBlocks ] );\n\n\t// The hidden block is needed because it makes block edit side effects trigger.\n\t// For example a navigation page list load its items has an effect on edit to load its items.\n\treturn (\n\t\t<>\n\t\t\t<OffCanvasEditor\n\t\t\t\tblocks={ clientIdsTree }\n\t\t\t\tonSelect={ onSelect }\n\t\t\t\tLeafMoreMenu={ LeafMoreMenu }\n\t\t\t/>\n\t\t\t<div style={ { display: 'none' } }>\n\t\t\t\t<BlockTools>\n\t\t\t\t\t<BlockList />\n\t\t\t\t</BlockTools>\n\t\t\t</div>\n\t\t</>\n\t);\n}\n"]}