@wordpress/edit-site 5.3.6 → 5.3.8

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 (145) hide show
  1. package/build/components/add-new-template/new-template.js +16 -10
  2. package/build/components/add-new-template/new-template.js.map +1 -1
  3. package/build/components/block-editor/editor-canvas.js +2 -1
  4. package/build/components/block-editor/editor-canvas.js.map +1 -1
  5. package/build/components/layout/index.js +6 -0
  6. package/build/components/layout/index.js.map +1 -1
  7. package/build/components/list/index.js +2 -1
  8. package/build/components/list/index.js.map +1 -1
  9. package/build/components/routes/link.js +4 -1
  10. package/build/components/routes/link.js.map +1 -1
  11. package/build/components/save-button/index.js +2 -5
  12. package/build/components/save-button/index.js.map +1 -1
  13. package/build/components/save-hub/index.js +82 -0
  14. package/build/components/save-hub/index.js.map +1 -0
  15. package/build/components/sidebar/index.js +2 -4
  16. package/build/components/sidebar/index.js.map +1 -1
  17. package/build/components/sidebar-navigation-screen/index.js +5 -2
  18. package/build/components/sidebar-navigation-screen/index.js.map +1 -1
  19. package/build/components/sidebar-navigation-screen-main/index.js +1 -0
  20. package/build/components/sidebar-navigation-screen-main/index.js.map +1 -1
  21. package/build/components/sidebar-navigation-screen-navigation-item/index.js +9 -14
  22. package/build/components/sidebar-navigation-screen-navigation-item/index.js.map +1 -1
  23. package/build/components/sidebar-navigation-screen-navigation-menus/index.js +100 -11
  24. package/build/components/sidebar-navigation-screen-navigation-menus/index.js.map +1 -1
  25. package/build/components/sidebar-navigation-screen-navigation-menus/loader.js +19 -0
  26. package/build/components/sidebar-navigation-screen-navigation-menus/loader.js.map +1 -0
  27. package/build/components/sidebar-navigation-screen-navigation-menus/navigation-menu-content.js +77 -0
  28. package/build/components/sidebar-navigation-screen-navigation-menus/navigation-menu-content.js.map +1 -0
  29. package/build/components/sidebar-navigation-screen-template/index.js +18 -4
  30. package/build/components/sidebar-navigation-screen-template/index.js.map +1 -1
  31. package/build/components/sidebar-navigation-screen-templates/index.js +5 -2
  32. package/build/components/sidebar-navigation-screen-templates/index.js.map +1 -1
  33. package/build/components/sidebar-navigation-screen-templates-browse/index.js +6 -3
  34. package/build/components/sidebar-navigation-screen-templates-browse/index.js.map +1 -1
  35. package/build/components/style-book/index.js +134 -19
  36. package/build/components/style-book/index.js.map +1 -1
  37. package/build/components/sync-state-with-url/use-sync-canvas-mode-with-url.js +24 -8
  38. package/build/components/sync-state-with-url/use-sync-canvas-mode-with-url.js.map +1 -1
  39. package/build/components/sync-state-with-url/use-sync-path-with-url.js +9 -7
  40. package/build/components/sync-state-with-url/use-sync-path-with-url.js.map +1 -1
  41. package/build/components/template-details/index.js +0 -3
  42. package/build/components/template-details/index.js.map +1 -1
  43. package/build/components/use-edited-entity-record/index.js +6 -6
  44. package/build/components/use-edited-entity-record/index.js.map +1 -1
  45. package/build/index.js +3 -0
  46. package/build/index.js.map +1 -1
  47. package/build/utils/history.js +8 -2
  48. package/build/utils/history.js.map +1 -1
  49. package/build-module/components/add-new-template/new-template.js +18 -11
  50. package/build-module/components/add-new-template/new-template.js.map +1 -1
  51. package/build-module/components/block-editor/editor-canvas.js +2 -1
  52. package/build-module/components/block-editor/editor-canvas.js.map +1 -1
  53. package/build-module/components/layout/index.js +6 -0
  54. package/build-module/components/layout/index.js.map +1 -1
  55. package/build-module/components/list/index.js +2 -1
  56. package/build-module/components/list/index.js.map +1 -1
  57. package/build-module/components/routes/link.js +5 -2
  58. package/build-module/components/routes/link.js.map +1 -1
  59. package/build-module/components/save-button/index.js +2 -5
  60. package/build-module/components/save-button/index.js.map +1 -1
  61. package/build-module/components/save-hub/index.js +68 -0
  62. package/build-module/components/save-hub/index.js.map +1 -0
  63. package/build-module/components/sidebar/index.js +2 -4
  64. package/build-module/components/sidebar/index.js.map +1 -1
  65. package/build-module/components/sidebar-navigation-screen/index.js +5 -2
  66. package/build-module/components/sidebar-navigation-screen/index.js.map +1 -1
  67. package/build-module/components/sidebar-navigation-screen-main/index.js +1 -0
  68. package/build-module/components/sidebar-navigation-screen-main/index.js.map +1 -1
  69. package/build-module/components/sidebar-navigation-screen-navigation-item/index.js +13 -18
  70. package/build-module/components/sidebar-navigation-screen-navigation-item/index.js.map +1 -1
  71. package/build-module/components/sidebar-navigation-screen-navigation-menus/index.js +94 -11
  72. package/build-module/components/sidebar-navigation-screen-navigation-menus/index.js.map +1 -1
  73. package/build-module/components/sidebar-navigation-screen-navigation-menus/loader.js +11 -0
  74. package/build-module/components/sidebar-navigation-screen-navigation-menus/loader.js.map +1 -0
  75. package/build-module/components/sidebar-navigation-screen-navigation-menus/navigation-menu-content.js +66 -0
  76. package/build-module/components/sidebar-navigation-screen-navigation-menus/navigation-menu-content.js.map +1 -0
  77. package/build-module/components/sidebar-navigation-screen-template/index.js +18 -5
  78. package/build-module/components/sidebar-navigation-screen-template/index.js.map +1 -1
  79. package/build-module/components/sidebar-navigation-screen-templates/index.js +5 -2
  80. package/build-module/components/sidebar-navigation-screen-templates/index.js.map +1 -1
  81. package/build-module/components/sidebar-navigation-screen-templates-browse/index.js +6 -3
  82. package/build-module/components/sidebar-navigation-screen-templates-browse/index.js.map +1 -1
  83. package/build-module/components/style-book/index.js +135 -22
  84. package/build-module/components/style-book/index.js.map +1 -1
  85. package/build-module/components/sync-state-with-url/use-sync-canvas-mode-with-url.js +24 -8
  86. package/build-module/components/sync-state-with-url/use-sync-canvas-mode-with-url.js.map +1 -1
  87. package/build-module/components/sync-state-with-url/use-sync-path-with-url.js +9 -7
  88. package/build-module/components/sync-state-with-url/use-sync-path-with-url.js.map +1 -1
  89. package/build-module/components/template-details/index.js +0 -3
  90. package/build-module/components/template-details/index.js.map +1 -1
  91. package/build-module/components/use-edited-entity-record/index.js +6 -6
  92. package/build-module/components/use-edited-entity-record/index.js.map +1 -1
  93. package/build-module/index.js +4 -1
  94. package/build-module/index.js.map +1 -1
  95. package/build-module/utils/history.js +9 -3
  96. package/build-module/utils/history.js.map +1 -1
  97. package/build-style/style-rtl.css +96 -111
  98. package/build-style/style.css +96 -111
  99. package/package.json +10 -10
  100. package/src/components/add-new-template/new-template.js +57 -32
  101. package/src/components/add-new-template/style.scss +12 -1
  102. package/src/components/block-editor/editor-canvas.js +2 -1
  103. package/src/components/layout/index.js +14 -0
  104. package/src/components/layout/style.scss +1 -3
  105. package/src/components/list/index.js +3 -1
  106. package/src/components/routes/link.js +9 -2
  107. package/src/components/save-button/index.js +2 -2
  108. package/src/components/save-hub/index.js +78 -0
  109. package/src/components/save-hub/style.scss +15 -0
  110. package/src/components/sidebar/index.js +2 -3
  111. package/src/components/sidebar/style.scss +4 -3
  112. package/src/components/sidebar-button/style.scss +2 -1
  113. package/src/components/sidebar-navigation-item/style.scss +0 -20
  114. package/src/components/sidebar-navigation-screen/index.js +6 -0
  115. package/src/components/sidebar-navigation-screen/style.scss +15 -0
  116. package/src/components/sidebar-navigation-screen-main/index.js +3 -0
  117. package/src/components/sidebar-navigation-screen-navigation-item/index.js +30 -21
  118. package/src/components/sidebar-navigation-screen-navigation-menus/index.js +104 -10
  119. package/src/components/sidebar-navigation-screen-navigation-menus/loader.js +9 -0
  120. package/src/components/sidebar-navigation-screen-navigation-menus/navigation-menu-content.js +78 -0
  121. package/src/components/sidebar-navigation-screen-navigation-menus/style.scss +59 -4
  122. package/src/components/sidebar-navigation-screen-template/index.js +21 -7
  123. package/src/components/sidebar-navigation-screen-templates/index.js +7 -0
  124. package/src/components/sidebar-navigation-screen-templates-browse/index.js +12 -1
  125. package/src/components/site-hub/style.scss +1 -1
  126. package/src/components/style-book/index.js +209 -54
  127. package/src/components/style-book/style.scss +1 -45
  128. package/src/components/sync-state-with-url/use-sync-canvas-mode-with-url.js +38 -8
  129. package/src/components/sync-state-with-url/use-sync-path-with-url.js +12 -7
  130. package/src/components/template-details/index.js +0 -3
  131. package/src/components/use-edited-entity-record/index.js +26 -18
  132. package/src/index.js +5 -1
  133. package/src/style.scss +1 -1
  134. package/src/utils/history.js +13 -9
  135. package/build/components/navigation-inspector/index.js +0 -190
  136. package/build/components/navigation-inspector/index.js.map +0 -1
  137. package/build/components/navigation-inspector/navigation-menu.js +0 -62
  138. package/build/components/navigation-inspector/navigation-menu.js.map +0 -1
  139. package/build-module/components/navigation-inspector/index.js +0 -173
  140. package/build-module/components/navigation-inspector/index.js.map +0 -1
  141. package/build-module/components/navigation-inspector/navigation-menu.js +0 -52
  142. package/build-module/components/navigation-inspector/navigation-menu.js.map +0 -1
  143. package/src/components/navigation-inspector/index.js +0 -223
  144. package/src/components/navigation-inspector/navigation-menu.js +0 -66
  145. package/src/components/navigation-inspector/style.scss +0 -46
@@ -1,190 +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 _components = require("@wordpress/components");
15
-
16
- var _coreData = require("@wordpress/core-data");
17
-
18
- var _blockEditor = require("@wordpress/block-editor");
19
-
20
- var _a11y = require("@wordpress/a11y");
21
-
22
- var _compose = require("@wordpress/compose");
23
-
24
- var _i18n = require("@wordpress/i18n");
25
-
26
- var _navigationMenu = _interopRequireDefault(require("./navigation-menu"));
27
-
28
- /**
29
- * WordPress dependencies
30
- */
31
-
32
- /**
33
- * Internal dependencies
34
- */
35
- const NAVIGATION_MENUS_QUERY = [{
36
- per_page: -1,
37
- status: 'publish'
38
- }];
39
-
40
- function NavigationInspector(_ref) {
41
- var _navigationMenus$;
42
-
43
- let {
44
- onSelect
45
- } = _ref;
46
- const {
47
- selectedNavigationBlockId,
48
- clientIdToRef,
49
- navigationMenus,
50
- isResolvingNavigationMenus,
51
- hasResolvedNavigationMenus,
52
- firstNavigationBlockId
53
- } = (0, _data.useSelect)(select => {
54
- const {
55
- __experimentalGetActiveBlockIdByBlockNames,
56
- __experimentalGetGlobalBlocksByName,
57
- getBlock
58
- } = select(_blockEditor.store);
59
- const {
60
- getEntityRecords,
61
- hasFinishedResolution,
62
- isResolving
63
- } = select(_coreData.store);
64
- const navigationMenusQuery = ['postType', 'wp_navigation', NAVIGATION_MENUS_QUERY[0]]; // Get the active Navigation block (if present).
65
-
66
- const selectedNavId = __experimentalGetActiveBlockIdByBlockNames('core/navigation'); // Get all Navigation blocks currently within the editor canvas.
67
-
68
-
69
- const navBlockIds = __experimentalGetGlobalBlocksByName('core/navigation');
70
-
71
- const idToRef = {};
72
- navBlockIds.forEach(id => {
73
- var _getBlock, _getBlock$attributes;
74
-
75
- 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;
76
- });
77
- return {
78
- selectedNavigationBlockId: selectedNavId,
79
- firstNavigationBlockId: navBlockIds === null || navBlockIds === void 0 ? void 0 : navBlockIds[0],
80
- clientIdToRef: idToRef,
81
- navigationMenus: getEntityRecords(...navigationMenusQuery),
82
- isResolvingNavigationMenus: isResolving('getEntityRecords', navigationMenusQuery),
83
- hasResolvedNavigationMenus: hasFinishedResolution('getEntityRecords', navigationMenusQuery)
84
- };
85
- }, []);
86
- const navMenuListId = (0, _compose.useInstanceId)(_navigationMenu.default, 'edit-site-navigation-inspector-menu');
87
- const firstNavRefInTemplate = clientIdToRef[firstNavigationBlockId];
88
- 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:
89
- // - the Navigation Menu referenced by the first Nav block within the template.
90
- // - the first of the available Navigation Menus (`wp_navigation`) posts.
91
-
92
- const defaultNavigationMenuId = firstNavRefInTemplate || firstNavigationMenuRef; // The Navigation Menu manually selected by the user within the Nav inspector.
93
-
94
- const [currentMenuId, setCurrentMenuId] = (0, _element.useState)(firstNavRefInTemplate); // If a Nav block is selected within the canvas then set the
95
- // Navigation Menu referenced by it's `ref` attribute to be
96
- // active within the Navigation sidebar.
97
-
98
- (0, _element.useEffect)(() => {
99
- if (selectedNavigationBlockId) {
100
- setCurrentMenuId(clientIdToRef[selectedNavigationBlockId]);
101
- }
102
- }, [selectedNavigationBlockId]);
103
- let options = [];
104
-
105
- if (navigationMenus) {
106
- options = navigationMenus.map(_ref2 => {
107
- let {
108
- id,
109
- title
110
- } = _ref2;
111
- return {
112
- value: id,
113
- label: title.rendered
114
- };
115
- });
116
- }
117
-
118
- const [innerBlocks, onInput, onChange] = (0, _coreData.useEntityBlockEditor)('postType', 'wp_navigation', {
119
- id: currentMenuId || defaultNavigationMenuId
120
- });
121
- const {
122
- isLoadingInnerBlocks,
123
- hasLoadedInnerBlocks
124
- } = (0, _data.useSelect)(select => {
125
- const {
126
- isResolving,
127
- hasFinishedResolution
128
- } = select(_coreData.store);
129
- return {
130
- isLoadingInnerBlocks: isResolving('getEntityRecord', ['postType', 'wp_navigation', currentMenuId || defaultNavigationMenuId]),
131
- hasLoadedInnerBlocks: hasFinishedResolution('getEntityRecord', ['postType', 'wp_navigation', currentMenuId || defaultNavigationMenuId])
132
- };
133
- }, [currentMenuId, defaultNavigationMenuId]);
134
- const isLoading = !(hasResolvedNavigationMenus && hasLoadedInnerBlocks);
135
- const hasMoreThanOneNavigationMenu = (navigationMenus === null || navigationMenus === void 0 ? void 0 : navigationMenus.length) > 1;
136
- const hasNavigationMenus = !!(navigationMenus !== null && navigationMenus !== void 0 && navigationMenus.length); // Entity block editor will return entities that are not currently published.
137
- // Guard by only allowing their usage if there are published Nav Menus.
138
-
139
- const publishedInnerBlocks = hasNavigationMenus ? innerBlocks : [];
140
- const hasInnerBlocks = !!(publishedInnerBlocks !== null && publishedInnerBlocks !== void 0 && publishedInnerBlocks.length);
141
- (0, _element.useEffect)(() => {
142
- if (isResolvingNavigationMenus) {
143
- (0, _a11y.speak)('Loading Navigation sidebar menus.');
144
- }
145
-
146
- if (hasResolvedNavigationMenus) {
147
- (0, _a11y.speak)('Navigation sidebar menus have loaded.');
148
- }
149
- }, [isResolvingNavigationMenus, hasResolvedNavigationMenus]);
150
- (0, _element.useEffect)(() => {
151
- if (isLoadingInnerBlocks) {
152
- (0, _a11y.speak)('Loading Navigation sidebar selected menu items.');
153
- }
154
-
155
- if (hasLoadedInnerBlocks) {
156
- (0, _a11y.speak)('Navigation sidebar selected menu items have loaded.');
157
- }
158
- }, [isLoadingInnerBlocks, hasLoadedInnerBlocks]);
159
- return (0, _element.createElement)("div", {
160
- className: "edit-site-navigation-inspector"
161
- }, hasResolvedNavigationMenus && !hasNavigationMenus && (0, _element.createElement)("p", {
162
- className: "edit-site-navigation-inspector__empty-msg"
163
- }, (0, _i18n.__)('There are no Navigation Menus.')), !hasResolvedNavigationMenus && (0, _element.createElement)("div", {
164
- className: "edit-site-navigation-inspector__placeholder"
165
- }), hasResolvedNavigationMenus && hasMoreThanOneNavigationMenu && (0, _element.createElement)(_components.SelectControl, {
166
- __nextHasNoMarginBottom: true,
167
- className: "edit-site-navigation-inspector__select-menu",
168
- "aria-controls": // aria-controls should only apply when referenced element is in DOM
169
- hasLoadedInnerBlocks ? navMenuListId : undefined,
170
- value: currentMenuId || defaultNavigationMenuId,
171
- options: options,
172
- onChange: newMenuId => setCurrentMenuId(Number(newMenuId))
173
- }), isLoading && (0, _element.createElement)(_element.Fragment, null, (0, _element.createElement)("div", {
174
- className: "edit-site-navigation-inspector__placeholder is-child"
175
- }), (0, _element.createElement)("div", {
176
- className: "edit-site-navigation-inspector__placeholder is-child"
177
- }), (0, _element.createElement)("div", {
178
- className: "edit-site-navigation-inspector__placeholder is-child"
179
- })), hasInnerBlocks && !isLoading && (0, _element.createElement)(_blockEditor.BlockEditorProvider, {
180
- value: publishedInnerBlocks,
181
- onChange: onChange,
182
- onInput: onInput
183
- }, (0, _element.createElement)(_navigationMenu.default, {
184
- innerBlocks: publishedInnerBlocks,
185
- onSelect: onSelect
186
- })), !hasInnerBlocks && !isLoading && (0, _element.createElement)("p", {
187
- className: "edit-site-navigation-inspector__empty-msg"
188
- }, (0, _i18n.__)('Navigation Menu is empty.')));
189
- }
190
- //# 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","navMenuListId","NavigationMenu","firstNavRefInTemplate","firstNavigationMenuRef","defaultNavigationMenuId","currentMenuId","setCurrentMenuId","options","map","title","value","label","rendered","innerBlocks","onInput","onChange","isLoadingInnerBlocks","hasLoadedInnerBlocks","isLoading","hasMoreThanOneNavigationMenu","length","hasNavigationMenus","publishedInnerBlocks","hasInnerBlocks","undefined","newMenuId","Number"],"mappings":";;;;;;;;;AAIA;;AADA;;AAEA;;AACA;;AACA;;AAIA;;AACA;;AACA;;AAKA;;AAlBA;AACA;AACA;;AAaA;AACA;AACA;AAGA,MAAMA,sBAAsB,GAAG,CAAE;AAAEC,EAAAA,QAAQ,EAAE,CAAC,CAAb;AAAgBC,EAAAA,MAAM,EAAE;AAAxB,CAAF,CAA/B;;AAEe,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,MAOF,qBAAaC,MAAF,IAAc;AAC5B,UAAM;AACLC,MAAAA,0CADK;AAELC,MAAAA,mCAFK;AAGLC,MAAAA;AAHK,QAIFH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C,IAAA,SAAS,EAAC,6CAFX;AAGC,qBACC;AACAF,IAAAA,oBAAoB,GAAGjB,aAAH,GAAmBwB,SALzC;AAOC,IAAA,KAAK,EAAGnB,aAAa,IAAID,uBAP1B;AAQC,IAAA,OAAO,EAAGG,OARX;AASC,IAAA,QAAQ,EAAKkB,SAAF,IACVnB,gBAAgB,CAAEoB,MAAM,CAAED,SAAF,CAAR;AAVlB,IAXF,EAyBGP,SAAS,IACV,qDACC;AAAK,IAAA,SAAS,EAAC;AAAf,IADD,EAEC;AAAK,IAAA,SAAS,EAAC;AAAf,IAFD,EAGC;AAAK,IAAA,SAAS,EAAC;AAAf,IAHD,CA1BF,EAgCGK,cAAc,IAAI,CAAEL,SAApB,IACD,4BAAC,gCAAD;AACC,IAAA,KAAK,EAAGI,oBADT;AAEC,IAAA,QAAQ,EAAGP,QAFZ;AAGC,IAAA,OAAO,EAAGD;AAHX,KAKC,4BAAC,uBAAD;AACC,IAAA,WAAW,EAAGQ,oBADf;AAEC,IAAA,QAAQ,EAAG9C;AAFZ,IALD,CAjCF,EA6CG,CAAE+C,cAAF,IAAoB,CAAEL,SAAtB,IACD;AAAG,IAAA,SAAS,EAAC;AAAb,KACG,cAAI,2BAAJ,CADH,CA9CF,CADD;AAqDA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useSelect } from '@wordpress/data';\nimport { useState, useEffect } from '@wordpress/element';\nimport { SelectControl } from '@wordpress/components';\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 { useInstanceId } from '@wordpress/compose';\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 navMenuListId = useInstanceId(\n\t\tNavigationMenu,\n\t\t'edit-site-navigation-inspector-menu'\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\tlet options = [];\n\tif ( navigationMenus ) {\n\t\toptions = navigationMenus.map( ( { id, title } ) => ( {\n\t\t\tvalue: id,\n\t\t\tlabel: title.rendered,\n\t\t} ) );\n\t}\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 hasMoreThanOneNavigationMenu = navigationMenus?.length > 1;\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{ hasResolvedNavigationMenus && hasMoreThanOneNavigationMenu && (\n\t\t\t\t<SelectControl\n\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\tclassName=\"edit-site-navigation-inspector__select-menu\"\n\t\t\t\t\taria-controls={\n\t\t\t\t\t\t// aria-controls should only apply when referenced element is in DOM\n\t\t\t\t\t\thasLoadedInnerBlocks ? navMenuListId : undefined\n\t\t\t\t\t}\n\t\t\t\t\tvalue={ currentMenuId || defaultNavigationMenuId }\n\t\t\t\t\toptions={ options }\n\t\t\t\t\tonChange={ ( newMenuId ) =>\n\t\t\t\t\t\tsetCurrentMenuId( Number( newMenuId ) )\n\t\t\t\t\t}\n\t\t\t\t/>\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,62 +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
- };
29
-
30
- function NavigationMenu(_ref) {
31
- let {
32
- innerBlocks,
33
- onSelect
34
- } = _ref;
35
- const {
36
- updateBlockListSettings
37
- } = (0, _data.useDispatch)(_blockEditor.store);
38
- const {
39
- OffCanvasEditor,
40
- LeafMoreMenu
41
- } = (0, _privateApis.unlock)(_blockEditor.privateApis); //TODO: Block settings are normally updated as a side effect of rendering InnerBlocks in BlockList
42
- //Think through a better way of doing this, possible with adding allowed blocks to block library metadata
43
-
44
- (0, _element.useEffect)(() => {
45
- updateBlockListSettings('', {
46
- allowedBlocks: ALLOWED_BLOCKS['core/navigation']
47
- });
48
- innerBlocks.forEach(block => {
49
- if (ALLOWED_BLOCKS[block.name]) {
50
- updateBlockListSettings(block.clientId, {
51
- allowedBlocks: ALLOWED_BLOCKS[block.name]
52
- });
53
- }
54
- });
55
- }, [updateBlockListSettings, innerBlocks]);
56
- return (0, _element.createElement)(OffCanvasEditor, {
57
- blocks: innerBlocks,
58
- onSelect: onSelect,
59
- LeafMoreMenu: LeafMoreMenu
60
- });
61
- }
62
- //# 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","updateBlockListSettings","blockEditorStore","OffCanvasEditor","LeafMoreMenu","blockEditorPrivateApis","allowedBlocks","forEach","block","name","clientId"],"mappings":";;;;;;;AAOA;;AAJA;;AAKA;;AAKA;;AAbA;AACA;AACA;;AAQA;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;AAjBF,CAAvB;;AAuBe,SAASC,cAAT,OAAqD;AAAA,MAA5B;AAAEC,IAAAA,WAAF;AAAeC,IAAAA;AAAf,GAA4B;AACnE,QAAM;AAAEC,IAAAA;AAAF,MAA8B,uBAAaC,kBAAb,CAApC;AAEA,QAAM;AAAEC,IAAAA,eAAF;AAAmBC,IAAAA;AAAnB,MAAoC,yBAAQC,wBAAR,CAA1C,CAHmE,CAKnE;AACA;;AACA,0BAAW,MAAM;AAChBJ,IAAAA,uBAAuB,CAAE,EAAF,EAAM;AAC5BK,MAAAA,aAAa,EAAET,cAAc,CAAE,iBAAF;AADD,KAAN,CAAvB;AAGAE,IAAAA,WAAW,CAACQ,OAAZ,CAAuBC,KAAF,IAAa;AACjC,UAAKX,cAAc,CAAEW,KAAK,CAACC,IAAR,CAAnB,EAAoC;AACnCR,QAAAA,uBAAuB,CAAEO,KAAK,CAACE,QAAR,EAAkB;AACxCJ,UAAAA,aAAa,EAAET,cAAc,CAAEW,KAAK,CAACC,IAAR;AADW,SAAlB,CAAvB;AAGA;AACD,KAND;AAOA,GAXD,EAWG,CAAER,uBAAF,EAA2BF,WAA3B,CAXH;AAaA,SACC,4BAAC,eAAD;AACC,IAAA,MAAM,EAAGA,WADV;AAEC,IAAA,QAAQ,EAAGC,QAFZ;AAGC,IAAA,YAAY,EAAGI;AAHhB,IADD;AAOA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\tprivateApis as blockEditorPrivateApis,\n\tstore as blockEditorStore,\n} from '@wordpress/block-editor';\nimport { useEffect } from '@wordpress/element';\nimport { 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};\n\nexport default function NavigationMenu( { innerBlocks, onSelect } ) {\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\treturn (\n\t\t<OffCanvasEditor\n\t\t\tblocks={ innerBlocks }\n\t\t\tonSelect={ onSelect }\n\t\t\tLeafMoreMenu={ LeafMoreMenu }\n\t\t/>\n\t);\n}\n"]}
@@ -1,173 +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 { SelectControl } from '@wordpress/components';
9
- import { store as coreStore, useEntityBlockEditor } from '@wordpress/core-data';
10
- import { store as blockEditorStore, BlockEditorProvider } from '@wordpress/block-editor';
11
- import { speak } from '@wordpress/a11y';
12
- import { useInstanceId } from '@wordpress/compose';
13
- import { __ } from '@wordpress/i18n';
14
- /**
15
- * Internal dependencies
16
- */
17
-
18
- import NavigationMenu from './navigation-menu';
19
- const NAVIGATION_MENUS_QUERY = [{
20
- per_page: -1,
21
- status: 'publish'
22
- }];
23
- export default function NavigationInspector(_ref) {
24
- var _navigationMenus$;
25
-
26
- let {
27
- onSelect
28
- } = _ref;
29
- const {
30
- selectedNavigationBlockId,
31
- clientIdToRef,
32
- navigationMenus,
33
- isResolvingNavigationMenus,
34
- hasResolvedNavigationMenus,
35
- firstNavigationBlockId
36
- } = useSelect(select => {
37
- const {
38
- __experimentalGetActiveBlockIdByBlockNames,
39
- __experimentalGetGlobalBlocksByName,
40
- getBlock
41
- } = select(blockEditorStore);
42
- const {
43
- getEntityRecords,
44
- hasFinishedResolution,
45
- isResolving
46
- } = select(coreStore);
47
- const navigationMenusQuery = ['postType', 'wp_navigation', NAVIGATION_MENUS_QUERY[0]]; // Get the active Navigation block (if present).
48
-
49
- const selectedNavId = __experimentalGetActiveBlockIdByBlockNames('core/navigation'); // Get all Navigation blocks currently within the editor canvas.
50
-
51
-
52
- const navBlockIds = __experimentalGetGlobalBlocksByName('core/navigation');
53
-
54
- const idToRef = {};
55
- navBlockIds.forEach(id => {
56
- var _getBlock, _getBlock$attributes;
57
-
58
- 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;
59
- });
60
- return {
61
- selectedNavigationBlockId: selectedNavId,
62
- firstNavigationBlockId: navBlockIds === null || navBlockIds === void 0 ? void 0 : navBlockIds[0],
63
- clientIdToRef: idToRef,
64
- navigationMenus: getEntityRecords(...navigationMenusQuery),
65
- isResolvingNavigationMenus: isResolving('getEntityRecords', navigationMenusQuery),
66
- hasResolvedNavigationMenus: hasFinishedResolution('getEntityRecords', navigationMenusQuery)
67
- };
68
- }, []);
69
- const navMenuListId = useInstanceId(NavigationMenu, 'edit-site-navigation-inspector-menu');
70
- const firstNavRefInTemplate = clientIdToRef[firstNavigationBlockId];
71
- 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:
72
- // - the Navigation Menu referenced by the first Nav block within the template.
73
- // - the first of the available Navigation Menus (`wp_navigation`) posts.
74
-
75
- const defaultNavigationMenuId = firstNavRefInTemplate || firstNavigationMenuRef; // The Navigation Menu manually selected by the user within the Nav inspector.
76
-
77
- const [currentMenuId, setCurrentMenuId] = useState(firstNavRefInTemplate); // If a Nav block is selected within the canvas then set the
78
- // Navigation Menu referenced by it's `ref` attribute to be
79
- // active within the Navigation sidebar.
80
-
81
- useEffect(() => {
82
- if (selectedNavigationBlockId) {
83
- setCurrentMenuId(clientIdToRef[selectedNavigationBlockId]);
84
- }
85
- }, [selectedNavigationBlockId]);
86
- let options = [];
87
-
88
- if (navigationMenus) {
89
- options = navigationMenus.map(_ref2 => {
90
- let {
91
- id,
92
- title
93
- } = _ref2;
94
- return {
95
- value: id,
96
- label: title.rendered
97
- };
98
- });
99
- }
100
-
101
- const [innerBlocks, onInput, onChange] = useEntityBlockEditor('postType', 'wp_navigation', {
102
- id: currentMenuId || defaultNavigationMenuId
103
- });
104
- const {
105
- isLoadingInnerBlocks,
106
- hasLoadedInnerBlocks
107
- } = useSelect(select => {
108
- const {
109
- isResolving,
110
- hasFinishedResolution
111
- } = select(coreStore);
112
- return {
113
- isLoadingInnerBlocks: isResolving('getEntityRecord', ['postType', 'wp_navigation', currentMenuId || defaultNavigationMenuId]),
114
- hasLoadedInnerBlocks: hasFinishedResolution('getEntityRecord', ['postType', 'wp_navigation', currentMenuId || defaultNavigationMenuId])
115
- };
116
- }, [currentMenuId, defaultNavigationMenuId]);
117
- const isLoading = !(hasResolvedNavigationMenus && hasLoadedInnerBlocks);
118
- const hasMoreThanOneNavigationMenu = (navigationMenus === null || navigationMenus === void 0 ? void 0 : navigationMenus.length) > 1;
119
- const hasNavigationMenus = !!(navigationMenus !== null && navigationMenus !== void 0 && navigationMenus.length); // Entity block editor will return entities that are not currently published.
120
- // Guard by only allowing their usage if there are published Nav Menus.
121
-
122
- const publishedInnerBlocks = hasNavigationMenus ? innerBlocks : [];
123
- const hasInnerBlocks = !!(publishedInnerBlocks !== null && publishedInnerBlocks !== void 0 && publishedInnerBlocks.length);
124
- useEffect(() => {
125
- if (isResolvingNavigationMenus) {
126
- speak('Loading Navigation sidebar menus.');
127
- }
128
-
129
- if (hasResolvedNavigationMenus) {
130
- speak('Navigation sidebar menus have loaded.');
131
- }
132
- }, [isResolvingNavigationMenus, hasResolvedNavigationMenus]);
133
- useEffect(() => {
134
- if (isLoadingInnerBlocks) {
135
- speak('Loading Navigation sidebar selected menu items.');
136
- }
137
-
138
- if (hasLoadedInnerBlocks) {
139
- speak('Navigation sidebar selected menu items have loaded.');
140
- }
141
- }, [isLoadingInnerBlocks, hasLoadedInnerBlocks]);
142
- return createElement("div", {
143
- className: "edit-site-navigation-inspector"
144
- }, hasResolvedNavigationMenus && !hasNavigationMenus && createElement("p", {
145
- className: "edit-site-navigation-inspector__empty-msg"
146
- }, __('There are no Navigation Menus.')), !hasResolvedNavigationMenus && createElement("div", {
147
- className: "edit-site-navigation-inspector__placeholder"
148
- }), hasResolvedNavigationMenus && hasMoreThanOneNavigationMenu && createElement(SelectControl, {
149
- __nextHasNoMarginBottom: true,
150
- className: "edit-site-navigation-inspector__select-menu",
151
- "aria-controls": // aria-controls should only apply when referenced element is in DOM
152
- hasLoadedInnerBlocks ? navMenuListId : undefined,
153
- value: currentMenuId || defaultNavigationMenuId,
154
- options: options,
155
- onChange: newMenuId => setCurrentMenuId(Number(newMenuId))
156
- }), isLoading && createElement(Fragment, null, createElement("div", {
157
- className: "edit-site-navigation-inspector__placeholder is-child"
158
- }), createElement("div", {
159
- className: "edit-site-navigation-inspector__placeholder is-child"
160
- }), createElement("div", {
161
- className: "edit-site-navigation-inspector__placeholder is-child"
162
- })), hasInnerBlocks && !isLoading && createElement(BlockEditorProvider, {
163
- value: publishedInnerBlocks,
164
- onChange: onChange,
165
- onInput: onInput
166
- }, createElement(NavigationMenu, {
167
- innerBlocks: publishedInnerBlocks,
168
- onSelect: onSelect
169
- })), !hasInnerBlocks && !isLoading && createElement("p", {
170
- className: "edit-site-navigation-inspector__empty-msg"
171
- }, __('Navigation Menu is empty.')));
172
- }
173
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["@wordpress/edit-site/src/components/navigation-inspector/index.js"],"names":["useSelect","useState","useEffect","SelectControl","store","coreStore","useEntityBlockEditor","blockEditorStore","BlockEditorProvider","speak","useInstanceId","__","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","navMenuListId","firstNavRefInTemplate","firstNavigationMenuRef","defaultNavigationMenuId","currentMenuId","setCurrentMenuId","options","map","title","value","label","rendered","innerBlocks","onInput","onChange","isLoadingInnerBlocks","hasLoadedInnerBlocks","isLoading","hasMoreThanOneNavigationMenu","length","hasNavigationMenus","publishedInnerBlocks","hasInnerBlocks","undefined","newMenuId","Number"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,SAAT,QAA0B,iBAA1B;AACA,SAASC,QAAT,EAAmBC,SAAnB,QAAoC,oBAApC;AACA,SAASC,aAAT,QAA8B,uBAA9B;AAC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AAS,EAAC;AAAf,IAFD,EAGC;AAAK,IAAA,SAAS,EAAC;AAAf,IAHD,CA1BF,EAgCGK,cAAc,IAAI,CAAEL,SAApB,IACD,cAAC,mBAAD;AACC,IAAA,KAAK,EAAGI,oBADT;AAEC,IAAA,QAAQ,EAAGP,QAFZ;AAGC,IAAA,OAAO,EAAGD;AAHX,KAKC,cAAC,cAAD;AACC,IAAA,WAAW,EAAGQ,oBADf;AAEC,IAAA,QAAQ,EAAG3C;AAFZ,IALD,CAjCF,EA6CG,CAAE4C,cAAF,IAAoB,CAAEL,SAAtB,IACD;AAAG,IAAA,SAAS,EAAC;AAAb,KACG7C,EAAE,CAAE,2BAAF,CADL,CA9CF,CADD;AAqDA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useSelect } from '@wordpress/data';\nimport { useState, useEffect } from '@wordpress/element';\nimport { SelectControl } from '@wordpress/components';\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 { useInstanceId } from '@wordpress/compose';\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 navMenuListId = useInstanceId(\n\t\tNavigationMenu,\n\t\t'edit-site-navigation-inspector-menu'\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\tlet options = [];\n\tif ( navigationMenus ) {\n\t\toptions = navigationMenus.map( ( { id, title } ) => ( {\n\t\t\tvalue: id,\n\t\t\tlabel: title.rendered,\n\t\t} ) );\n\t}\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 hasMoreThanOneNavigationMenu = navigationMenus?.length > 1;\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{ hasResolvedNavigationMenus && hasMoreThanOneNavigationMenu && (\n\t\t\t\t<SelectControl\n\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\tclassName=\"edit-site-navigation-inspector__select-menu\"\n\t\t\t\t\taria-controls={\n\t\t\t\t\t\t// aria-controls should only apply when referenced element is in DOM\n\t\t\t\t\t\thasLoadedInnerBlocks ? navMenuListId : undefined\n\t\t\t\t\t}\n\t\t\t\t\tvalue={ currentMenuId || defaultNavigationMenuId }\n\t\t\t\t\toptions={ options }\n\t\t\t\t\tonChange={ ( newMenuId ) =>\n\t\t\t\t\t\tsetCurrentMenuId( Number( newMenuId ) )\n\t\t\t\t\t}\n\t\t\t\t/>\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,52 +0,0 @@
1
- import { createElement } from "@wordpress/element";
2
-
3
- /**
4
- * WordPress dependencies
5
- */
6
- import { privateApis as blockEditorPrivateApis, store as blockEditorStore } from '@wordpress/block-editor';
7
- import { useEffect } from '@wordpress/element';
8
- import { 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
- };
20
- export default function NavigationMenu(_ref) {
21
- let {
22
- innerBlocks,
23
- onSelect
24
- } = _ref;
25
- const {
26
- updateBlockListSettings
27
- } = useDispatch(blockEditorStore);
28
- const {
29
- OffCanvasEditor,
30
- LeafMoreMenu
31
- } = unlock(blockEditorPrivateApis); //TODO: Block settings are normally updated as a side effect of rendering InnerBlocks in BlockList
32
- //Think through a better way of doing this, possible with adding allowed blocks to block library metadata
33
-
34
- useEffect(() => {
35
- updateBlockListSettings('', {
36
- allowedBlocks: ALLOWED_BLOCKS['core/navigation']
37
- });
38
- innerBlocks.forEach(block => {
39
- if (ALLOWED_BLOCKS[block.name]) {
40
- updateBlockListSettings(block.clientId, {
41
- allowedBlocks: ALLOWED_BLOCKS[block.name]
42
- });
43
- }
44
- });
45
- }, [updateBlockListSettings, innerBlocks]);
46
- return createElement(OffCanvasEditor, {
47
- blocks: innerBlocks,
48
- onSelect: onSelect,
49
- LeafMoreMenu: LeafMoreMenu
50
- });
51
- }
52
- //# 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","useEffect","useDispatch","unlock","ALLOWED_BLOCKS","NavigationMenu","innerBlocks","onSelect","updateBlockListSettings","OffCanvasEditor","LeafMoreMenu","allowedBlocks","forEach","block","name","clientId"],"mappings":";;AAAA;AACA;AACA;AACA,SACCA,WAAW,IAAIC,sBADhB,EAECC,KAAK,IAAIC,gBAFV,QAGO,yBAHP;AAIA,SAASC,SAAT,QAA0B,oBAA1B;AACA,SAASC,WAAT,QAA4B,iBAA5B;AAEA;AACA;AACA;;AACA,SAASC,MAAT,QAAuB,oBAAvB;AAEA,MAAMC,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;AAjBF,CAAvB;AAuBA,eAAe,SAASC,cAAT,OAAqD;AAAA,MAA5B;AAAEC,IAAAA,WAAF;AAAeC,IAAAA;AAAf,GAA4B;AACnE,QAAM;AAAEC,IAAAA;AAAF,MAA8BN,WAAW,CAAEF,gBAAF,CAA/C;AAEA,QAAM;AAAES,IAAAA,eAAF;AAAmBC,IAAAA;AAAnB,MAAoCP,MAAM,CAAEL,sBAAF,CAAhD,CAHmE,CAKnE;AACA;;AACAG,EAAAA,SAAS,CAAE,MAAM;AAChBO,IAAAA,uBAAuB,CAAE,EAAF,EAAM;AAC5BG,MAAAA,aAAa,EAAEP,cAAc,CAAE,iBAAF;AADD,KAAN,CAAvB;AAGAE,IAAAA,WAAW,CAACM,OAAZ,CAAuBC,KAAF,IAAa;AACjC,UAAKT,cAAc,CAAES,KAAK,CAACC,IAAR,CAAnB,EAAoC;AACnCN,QAAAA,uBAAuB,CAAEK,KAAK,CAACE,QAAR,EAAkB;AACxCJ,UAAAA,aAAa,EAAEP,cAAc,CAAES,KAAK,CAACC,IAAR;AADW,SAAlB,CAAvB;AAGA;AACD,KAND;AAOA,GAXQ,EAWN,CAAEN,uBAAF,EAA2BF,WAA3B,CAXM,CAAT;AAaA,SACC,cAAC,eAAD;AACC,IAAA,MAAM,EAAGA,WADV;AAEC,IAAA,QAAQ,EAAGC,QAFZ;AAGC,IAAA,YAAY,EAAGG;AAHhB,IADD;AAOA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\tprivateApis as blockEditorPrivateApis,\n\tstore as blockEditorStore,\n} from '@wordpress/block-editor';\nimport { useEffect } from '@wordpress/element';\nimport { 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};\n\nexport default function NavigationMenu( { innerBlocks, onSelect } ) {\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\treturn (\n\t\t<OffCanvasEditor\n\t\t\tblocks={ innerBlocks }\n\t\t\tonSelect={ onSelect }\n\t\t\tLeafMoreMenu={ LeafMoreMenu }\n\t\t/>\n\t);\n}\n"]}