@wordpress/edit-site 5.3.6 → 5.3.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (132) hide show
  1. package/build/components/block-editor/editor-canvas.js +2 -1
  2. package/build/components/block-editor/editor-canvas.js.map +1 -1
  3. package/build/components/layout/index.js +6 -0
  4. package/build/components/layout/index.js.map +1 -1
  5. package/build/components/list/index.js +2 -1
  6. package/build/components/list/index.js.map +1 -1
  7. package/build/components/routes/link.js +4 -1
  8. package/build/components/routes/link.js.map +1 -1
  9. package/build/components/save-button/index.js +2 -5
  10. package/build/components/save-button/index.js.map +1 -1
  11. package/build/components/save-hub/index.js +82 -0
  12. package/build/components/save-hub/index.js.map +1 -0
  13. package/build/components/sidebar/index.js +2 -4
  14. package/build/components/sidebar/index.js.map +1 -1
  15. package/build/components/sidebar-navigation-screen/index.js +5 -2
  16. package/build/components/sidebar-navigation-screen/index.js.map +1 -1
  17. package/build/components/sidebar-navigation-screen-main/index.js +1 -0
  18. package/build/components/sidebar-navigation-screen-main/index.js.map +1 -1
  19. package/build/components/sidebar-navigation-screen-navigation-item/index.js +9 -14
  20. package/build/components/sidebar-navigation-screen-navigation-item/index.js.map +1 -1
  21. package/build/components/sidebar-navigation-screen-navigation-menus/index.js +139 -11
  22. package/build/components/sidebar-navigation-screen-navigation-menus/index.js.map +1 -1
  23. package/build/components/sidebar-navigation-screen-navigation-menus/loader.js +19 -0
  24. package/build/components/sidebar-navigation-screen-navigation-menus/loader.js.map +1 -0
  25. package/build/components/sidebar-navigation-screen-navigation-menus/navigation-menu-content.js +77 -0
  26. package/build/components/sidebar-navigation-screen-navigation-menus/navigation-menu-content.js.map +1 -0
  27. package/build/components/sidebar-navigation-screen-template/index.js +18 -4
  28. package/build/components/sidebar-navigation-screen-template/index.js.map +1 -1
  29. package/build/components/sidebar-navigation-screen-templates/index.js +5 -2
  30. package/build/components/sidebar-navigation-screen-templates/index.js.map +1 -1
  31. package/build/components/sidebar-navigation-screen-templates-browse/index.js +6 -3
  32. package/build/components/sidebar-navigation-screen-templates-browse/index.js.map +1 -1
  33. package/build/components/sync-state-with-url/use-sync-canvas-mode-with-url.js +24 -8
  34. package/build/components/sync-state-with-url/use-sync-canvas-mode-with-url.js.map +1 -1
  35. package/build/components/sync-state-with-url/use-sync-path-with-url.js +9 -7
  36. package/build/components/sync-state-with-url/use-sync-path-with-url.js.map +1 -1
  37. package/build/components/template-details/index.js +0 -3
  38. package/build/components/template-details/index.js.map +1 -1
  39. package/build/components/use-edited-entity-record/index.js +6 -6
  40. package/build/components/use-edited-entity-record/index.js.map +1 -1
  41. package/build/index.js +3 -0
  42. package/build/index.js.map +1 -1
  43. package/build/utils/history.js +8 -2
  44. package/build/utils/history.js.map +1 -1
  45. package/build-module/components/block-editor/editor-canvas.js +2 -1
  46. package/build-module/components/block-editor/editor-canvas.js.map +1 -1
  47. package/build-module/components/layout/index.js +6 -0
  48. package/build-module/components/layout/index.js.map +1 -1
  49. package/build-module/components/list/index.js +2 -1
  50. package/build-module/components/list/index.js.map +1 -1
  51. package/build-module/components/routes/link.js +5 -2
  52. package/build-module/components/routes/link.js.map +1 -1
  53. package/build-module/components/save-button/index.js +2 -5
  54. package/build-module/components/save-button/index.js.map +1 -1
  55. package/build-module/components/save-hub/index.js +68 -0
  56. package/build-module/components/save-hub/index.js.map +1 -0
  57. package/build-module/components/sidebar/index.js +2 -4
  58. package/build-module/components/sidebar/index.js.map +1 -1
  59. package/build-module/components/sidebar-navigation-screen/index.js +5 -2
  60. package/build-module/components/sidebar-navigation-screen/index.js.map +1 -1
  61. package/build-module/components/sidebar-navigation-screen-main/index.js +1 -0
  62. package/build-module/components/sidebar-navigation-screen-main/index.js.map +1 -1
  63. package/build-module/components/sidebar-navigation-screen-navigation-item/index.js +13 -18
  64. package/build-module/components/sidebar-navigation-screen-navigation-item/index.js.map +1 -1
  65. package/build-module/components/sidebar-navigation-screen-navigation-menus/index.js +131 -11
  66. package/build-module/components/sidebar-navigation-screen-navigation-menus/index.js.map +1 -1
  67. package/build-module/components/sidebar-navigation-screen-navigation-menus/loader.js +11 -0
  68. package/build-module/components/sidebar-navigation-screen-navigation-menus/loader.js.map +1 -0
  69. package/build-module/components/sidebar-navigation-screen-navigation-menus/navigation-menu-content.js +66 -0
  70. package/build-module/components/sidebar-navigation-screen-navigation-menus/navigation-menu-content.js.map +1 -0
  71. package/build-module/components/sidebar-navigation-screen-template/index.js +18 -5
  72. package/build-module/components/sidebar-navigation-screen-template/index.js.map +1 -1
  73. package/build-module/components/sidebar-navigation-screen-templates/index.js +5 -2
  74. package/build-module/components/sidebar-navigation-screen-templates/index.js.map +1 -1
  75. package/build-module/components/sidebar-navigation-screen-templates-browse/index.js +6 -3
  76. package/build-module/components/sidebar-navigation-screen-templates-browse/index.js.map +1 -1
  77. package/build-module/components/sync-state-with-url/use-sync-canvas-mode-with-url.js +24 -8
  78. package/build-module/components/sync-state-with-url/use-sync-canvas-mode-with-url.js.map +1 -1
  79. package/build-module/components/sync-state-with-url/use-sync-path-with-url.js +9 -7
  80. package/build-module/components/sync-state-with-url/use-sync-path-with-url.js.map +1 -1
  81. package/build-module/components/template-details/index.js +0 -3
  82. package/build-module/components/template-details/index.js.map +1 -1
  83. package/build-module/components/use-edited-entity-record/index.js +6 -6
  84. package/build-module/components/use-edited-entity-record/index.js.map +1 -1
  85. package/build-module/index.js +4 -1
  86. package/build-module/index.js.map +1 -1
  87. package/build-module/utils/history.js +9 -3
  88. package/build-module/utils/history.js.map +1 -1
  89. package/build-style/style-rtl.css +80 -67
  90. package/build-style/style.css +80 -67
  91. package/package.json +7 -7
  92. package/src/components/block-editor/editor-canvas.js +2 -1
  93. package/src/components/layout/index.js +14 -0
  94. package/src/components/layout/style.scss +1 -3
  95. package/src/components/list/index.js +3 -1
  96. package/src/components/routes/link.js +9 -2
  97. package/src/components/save-button/index.js +2 -2
  98. package/src/components/save-hub/index.js +78 -0
  99. package/src/components/save-hub/style.scss +15 -0
  100. package/src/components/sidebar/index.js +2 -3
  101. package/src/components/sidebar/style.scss +4 -3
  102. package/src/components/sidebar-button/style.scss +2 -1
  103. package/src/components/sidebar-navigation-item/style.scss +0 -20
  104. package/src/components/sidebar-navigation-screen/index.js +6 -0
  105. package/src/components/sidebar-navigation-screen/style.scss +15 -0
  106. package/src/components/sidebar-navigation-screen-main/index.js +3 -0
  107. package/src/components/sidebar-navigation-screen-navigation-item/index.js +30 -21
  108. package/src/components/sidebar-navigation-screen-navigation-menus/index.js +141 -10
  109. package/src/components/sidebar-navigation-screen-navigation-menus/loader.js +9 -0
  110. package/src/components/sidebar-navigation-screen-navigation-menus/navigation-menu-content.js +78 -0
  111. package/src/components/sidebar-navigation-screen-navigation-menus/style.scss +55 -4
  112. package/src/components/sidebar-navigation-screen-template/index.js +21 -7
  113. package/src/components/sidebar-navigation-screen-templates/index.js +7 -0
  114. package/src/components/sidebar-navigation-screen-templates-browse/index.js +12 -1
  115. package/src/components/sync-state-with-url/use-sync-canvas-mode-with-url.js +38 -8
  116. package/src/components/sync-state-with-url/use-sync-path-with-url.js +12 -7
  117. package/src/components/template-details/index.js +0 -3
  118. package/src/components/use-edited-entity-record/index.js +26 -18
  119. package/src/index.js +5 -1
  120. package/src/style.scss +1 -1
  121. package/src/utils/history.js +13 -9
  122. package/build/components/navigation-inspector/index.js +0 -190
  123. package/build/components/navigation-inspector/index.js.map +0 -1
  124. package/build/components/navigation-inspector/navigation-menu.js +0 -62
  125. package/build/components/navigation-inspector/navigation-menu.js.map +0 -1
  126. package/build-module/components/navigation-inspector/index.js +0 -173
  127. package/build-module/components/navigation-inspector/index.js.map +0 -1
  128. package/build-module/components/navigation-inspector/navigation-menu.js +0 -52
  129. package/build-module/components/navigation-inspector/navigation-menu.js.map +0 -1
  130. package/src/components/navigation-inspector/index.js +0 -223
  131. package/src/components/navigation-inspector/navigation-menu.js +0 -66
  132. package/src/components/navigation-inspector/style.scss +0 -46
@@ -11,12 +11,28 @@ var _element = require("@wordpress/element");
11
11
 
12
12
  var _i18n = require("@wordpress/i18n");
13
13
 
14
- var _sidebarNavigationScreen = _interopRequireDefault(require("../sidebar-navigation-screen"));
14
+ var _data = require("@wordpress/data");
15
+
16
+ var _coreData = require("@wordpress/core-data");
17
+
18
+ var _blockEditor = require("@wordpress/block-editor");
15
19
 
16
- var _navigationInspector = _interopRequireDefault(require("../navigation-inspector"));
20
+ var _blocks = require("@wordpress/blocks");
21
+
22
+ var _sidebarNavigationScreen = _interopRequireDefault(require("../sidebar-navigation-screen"));
17
23
 
18
24
  var _routes = require("../routes");
19
25
 
26
+ var _navigationMenuContent = _interopRequireDefault(require("./navigation-menu-content"));
27
+
28
+ var _sidebarButton = _interopRequireDefault(require("../sidebar-button"));
29
+
30
+ var _loader = require("./loader");
31
+
32
+ var _privateApis = require("../../private-apis");
33
+
34
+ var _store = require("../../store");
35
+
20
36
  /**
21
37
  * WordPress dependencies
22
38
  */
@@ -24,11 +40,69 @@ var _routes = require("../routes");
24
40
  /**
25
41
  * Internal dependencies
26
42
  */
43
+ const noop = () => {};
44
+
45
+ const NAVIGATION_MENUS_QUERY = {
46
+ per_page: -1,
47
+ status: 'publish'
48
+ };
49
+
50
+ function SidebarNavigationScreenWrapper(_ref) {
51
+ let {
52
+ children,
53
+ actions
54
+ } = _ref;
55
+ return (0, _element.createElement)(_sidebarNavigationScreen.default, {
56
+ title: (0, _i18n.__)('Navigation'),
57
+ actions: actions,
58
+ description: (0, _i18n.__)('Browse your site, edit pages, and manage your primary navigation menu.'),
59
+ content: children
60
+ });
61
+ }
62
+
63
+ const prioritizedInserterBlocks = ['core/navigation-link/page', 'core/navigation-link'];
64
+
27
65
  function SidebarNavigationScreenNavigationMenus() {
66
+ var _orderedNavigationMen;
67
+
28
68
  const history = (0, _routes.useHistory)();
69
+ const {
70
+ navigationMenus,
71
+ hasResolvedNavigationMenus,
72
+ storedSettings
73
+ } = (0, _data.useSelect)(select => {
74
+ const {
75
+ getSettings
76
+ } = (0, _privateApis.unlock)(select(_store.store));
77
+ const {
78
+ getEntityRecords,
79
+ hasFinishedResolution
80
+ } = select(_coreData.store);
81
+ const navigationMenusQuery = ['postType', 'wp_navigation', NAVIGATION_MENUS_QUERY];
82
+ return {
83
+ storedSettings: getSettings(false),
84
+ navigationMenus: getEntityRecords(...navigationMenusQuery),
85
+ hasResolvedNavigationMenus: hasFinishedResolution('getEntityRecords', navigationMenusQuery)
86
+ };
87
+ }, []); // Sort navigation menus by date.
88
+
89
+ const orderedNavigationMenus = (0, _element.useMemo)(() => navigationMenus === null || navigationMenus === void 0 ? void 0 : navigationMenus.sort((menuA, menuB) => {
90
+ const menuADate = new Date(menuA.date);
91
+ const menuBDate = new Date(menuB.date);
92
+ return menuADate.getTime() > menuBDate.getTime();
93
+ }), [navigationMenus]);
94
+ const firstNavigationMenu = orderedNavigationMenus === null || orderedNavigationMenus === void 0 ? void 0 : (_orderedNavigationMen = orderedNavigationMenus[0]) === null || _orderedNavigationMen === void 0 ? void 0 : _orderedNavigationMen.id;
95
+ const blocks = (0, _element.useMemo)(() => {
96
+ return [(0, _blocks.createBlock)('core/navigation', {
97
+ ref: firstNavigationMenu
98
+ })];
99
+ }, [firstNavigationMenu]);
100
+ const isLoading = !hasResolvedNavigationMenus;
101
+ const hasNavigationMenus = !!(navigationMenus !== null && navigationMenus !== void 0 && navigationMenus.length);
29
102
  const onSelect = (0, _element.useCallback)(selectedBlock => {
30
103
  const {
31
- attributes
104
+ attributes,
105
+ name
32
106
  } = selectedBlock;
33
107
 
34
108
  if (attributes.kind === 'post-type' && attributes.id && attributes.type && history) {
@@ -37,14 +111,68 @@ function SidebarNavigationScreenNavigationMenus() {
37
111
  postId: attributes.id
38
112
  });
39
113
  }
114
+
115
+ if (name === 'core/page-list-item' && attributes.id && history) {
116
+ history.push({
117
+ postType: 'page',
118
+ postId: attributes.id
119
+ });
120
+ }
40
121
  }, [history]);
41
- return (0, _element.createElement)(_sidebarNavigationScreen.default, {
42
- title: (0, _i18n.__)('Navigation'),
43
- content: (0, _element.createElement)("div", {
44
- className: "edit-site-sidebar-navigation-screen-navigation-menus"
45
- }, (0, _element.createElement)(_navigationInspector.default, {
46
- onSelect: onSelect
47
- }))
48
- });
122
+ const orderInitialBlockItems = (0, _element.useCallback)(items => {
123
+ items.sort((_ref2, _ref3) => {
124
+ let {
125
+ id: aName
126
+ } = _ref2;
127
+ let {
128
+ id: bName
129
+ } = _ref3;
130
+ // Sort block items according to `prioritizedInserterBlocks`.
131
+ let aIndex = prioritizedInserterBlocks.indexOf(aName);
132
+ let bIndex = prioritizedInserterBlocks.indexOf(bName); // All other block items should come after that.
133
+
134
+ if (aIndex < 0) aIndex = prioritizedInserterBlocks.length;
135
+ if (bIndex < 0) bIndex = prioritizedInserterBlocks.length;
136
+ return aIndex - bIndex;
137
+ });
138
+ return items;
139
+ }, []);
140
+
141
+ if (hasResolvedNavigationMenus && !hasNavigationMenus) {
142
+ return (0, _element.createElement)(SidebarNavigationScreenWrapper, null, (0, _i18n.__)('There are no Navigation Menus.'));
143
+ }
144
+
145
+ if (!hasResolvedNavigationMenus || isLoading) {
146
+ return (0, _element.createElement)(SidebarNavigationScreenWrapper, null, (0, _element.createElement)(_loader.NavigationMenuLoader, null));
147
+ }
148
+
149
+ const {
150
+ PrivateInserter
151
+ } = (0, _privateApis.unlock)(_blockEditor.privateApis);
152
+ return (0, _element.createElement)(_blockEditor.BlockEditorProvider, {
153
+ settings: storedSettings,
154
+ value: blocks,
155
+ onChange: noop,
156
+ onInput: noop
157
+ }, (0, _element.createElement)(SidebarNavigationScreenWrapper, {
158
+ actions: (0, _element.createElement)(PrivateInserter, {
159
+ rootClientId: blocks[0].clientId,
160
+ position: "bottom right",
161
+ isAppender: true,
162
+ selectBlockOnInsert: false,
163
+ shouldDirectInsert: false,
164
+ __experimentalIsQuick: true,
165
+ toggleProps: {
166
+ as: _sidebarButton.default,
167
+ label: (0, _i18n.__)('Add menu item')
168
+ },
169
+ orderInitialBlockItems: orderInitialBlockItems
170
+ })
171
+ }, (0, _element.createElement)("div", {
172
+ className: "edit-site-sidebar-navigation-screen-navigation-menus__content"
173
+ }, (0, _element.createElement)(_navigationMenuContent.default, {
174
+ rootClientId: blocks[0].clientId,
175
+ onSelect: onSelect
176
+ }))));
49
177
  }
50
178
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/edit-site/src/components/sidebar-navigation-screen-navigation-menus/index.js"],"names":["SidebarNavigationScreenNavigationMenus","history","onSelect","selectedBlock","attributes","kind","id","type","push","postType","postId"],"mappings":";;;;;;;;;AAIA;;AADA;;AAMA;;AACA;;AACA;;AAXA;AACA;AACA;;AAIA;AACA;AACA;AAKe,SAASA,sCAAT,GAAkD;AAChE,QAAMC,OAAO,GAAG,yBAAhB;AACA,QAAMC,QAAQ,GAAG,0BACdC,aAAF,IAAqB;AACpB,UAAM;AAAEC,MAAAA;AAAF,QAAiBD,aAAvB;;AACA,QACCC,UAAU,CAACC,IAAX,KAAoB,WAApB,IACAD,UAAU,CAACE,EADX,IAEAF,UAAU,CAACG,IAFX,IAGAN,OAJD,EAKE;AACDA,MAAAA,OAAO,CAACO,IAAR,CAAc;AACbC,QAAAA,QAAQ,EAAEL,UAAU,CAACG,IADR;AAEbG,QAAAA,MAAM,EAAEN,UAAU,CAACE;AAFN,OAAd;AAIA;AACD,GAde,EAehB,CAAEL,OAAF,CAfgB,CAAjB;AAiBA,SACC,4BAAC,gCAAD;AACC,IAAA,KAAK,EAAG,cAAI,YAAJ,CADT;AAEC,IAAA,OAAO,EACN;AAAK,MAAA,SAAS,EAAC;AAAf,OACC,4BAAC,4BAAD;AAAqB,MAAA,QAAQ,EAAGC;AAAhC,MADD;AAHF,IADD;AAUA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { useCallback } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport SidebarNavigationScreen from '../sidebar-navigation-screen';\nimport NavigationInspector from '../navigation-inspector';\nimport { useHistory } from '../routes';\n\nexport default function SidebarNavigationScreenNavigationMenus() {\n\tconst history = useHistory();\n\tconst onSelect = useCallback(\n\t\t( selectedBlock ) => {\n\t\t\tconst { attributes } = selectedBlock;\n\t\t\tif (\n\t\t\t\tattributes.kind === 'post-type' &&\n\t\t\t\tattributes.id &&\n\t\t\t\tattributes.type &&\n\t\t\t\thistory\n\t\t\t) {\n\t\t\t\thistory.push( {\n\t\t\t\t\tpostType: attributes.type,\n\t\t\t\t\tpostId: attributes.id,\n\t\t\t\t} );\n\t\t\t}\n\t\t},\n\t\t[ history ]\n\t);\n\treturn (\n\t\t<SidebarNavigationScreen\n\t\t\ttitle={ __( 'Navigation' ) }\n\t\t\tcontent={\n\t\t\t\t<div className=\"edit-site-sidebar-navigation-screen-navigation-menus\">\n\t\t\t\t\t<NavigationInspector onSelect={ onSelect } />\n\t\t\t\t</div>\n\t\t\t}\n\t\t/>\n\t);\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/edit-site/src/components/sidebar-navigation-screen-navigation-menus/index.js"],"names":["noop","NAVIGATION_MENUS_QUERY","per_page","status","SidebarNavigationScreenWrapper","children","actions","prioritizedInserterBlocks","SidebarNavigationScreenNavigationMenus","history","navigationMenus","hasResolvedNavigationMenus","storedSettings","select","getSettings","editSiteStore","getEntityRecords","hasFinishedResolution","coreStore","navigationMenusQuery","orderedNavigationMenus","sort","menuA","menuB","menuADate","Date","date","menuBDate","getTime","firstNavigationMenu","id","blocks","ref","isLoading","hasNavigationMenus","length","onSelect","selectedBlock","attributes","name","kind","type","push","postType","postId","orderInitialBlockItems","items","aName","bName","aIndex","indexOf","bIndex","PrivateInserter","blockEditorPrivateApis","clientId","as","SidebarButton","label"],"mappings":";;;;;;;;;AAIA;;AADA;;AAEA;;AACA;;AACA;;AAIA;;AAKA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAtBA;AACA;AACA;;AAWA;AACA;AACA;AASA,MAAMA,IAAI,GAAG,MAAM,CAAE,CAArB;;AACA,MA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G+B,MAAM,CAAE,CAAF,CAAN,CAAYuB,QAD5B;AAEC,MAAA,QAAQ,EAAC,cAFV;AAGC,MAAA,UAAU,MAHX;AAIC,MAAA,mBAAmB,EAAG,KAJvB;AAKC,MAAA,kBAAkB,EAAG,KALtB;AAMC,MAAA,qBAAqB,MANtB;AAOC,MAAA,WAAW,EAAG;AACbC,QAAAA,EAAE,EAAEC,sBADS;AAEbC,QAAAA,KAAK,EAAE,cAAI,eAAJ;AAFM,OAPf;AAWC,MAAA,sBAAsB,EAAGZ;AAX1B;AAFF,KAiBC;AAAK,IAAA,SAAS,EAAC;AAAf,KACC,4BAAC,8BAAD;AACC,IAAA,YAAY,EAAGd,MAAM,CAAE,CAAF,CAAN,CAAYuB,QAD5B;AAEC,IAAA,QAAQ,EAAGlB;AAFZ,IADD,CAjBD,CAND,CADD;AAiCA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { useCallback, useMemo } from '@wordpress/element';\nimport { useSelect } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport {\n\tBlockEditorProvider,\n\tprivateApis as blockEditorPrivateApis,\n} from '@wordpress/block-editor';\nimport { createBlock } from '@wordpress/blocks';\n\n/**\n * Internal dependencies\n */\nimport SidebarNavigationScreen from '../sidebar-navigation-screen';\nimport { useHistory } from '../routes';\nimport NavigationMenuContent from './navigation-menu-content';\nimport SidebarButton from '../sidebar-button';\nimport { NavigationMenuLoader } from './loader';\nimport { unlock } from '../../private-apis';\nimport { store as editSiteStore } from '../../store';\n\nconst noop = () => {};\nconst NAVIGATION_MENUS_QUERY = { per_page: -1, status: 'publish' };\n\nfunction SidebarNavigationScreenWrapper( { children, actions } ) {\n\treturn (\n\t\t<SidebarNavigationScreen\n\t\t\ttitle={ __( 'Navigation' ) }\n\t\t\tactions={ actions }\n\t\t\tdescription={ __(\n\t\t\t\t'Browse your site, edit pages, and manage your primary navigation menu.'\n\t\t\t) }\n\t\t\tcontent={ children }\n\t\t/>\n\t);\n}\n\nconst prioritizedInserterBlocks = [\n\t'core/navigation-link/page',\n\t'core/navigation-link',\n];\n\nexport default function SidebarNavigationScreenNavigationMenus() {\n\tconst history = useHistory();\n\tconst { navigationMenus, hasResolvedNavigationMenus, storedSettings } =\n\t\tuseSelect( ( select ) => {\n\t\t\tconst { getSettings } = unlock( select( editSiteStore ) );\n\t\t\tconst { getEntityRecords, hasFinishedResolution } =\n\t\t\t\tselect( coreStore );\n\n\t\t\tconst navigationMenusQuery = [\n\t\t\t\t'postType',\n\t\t\t\t'wp_navigation',\n\t\t\t\tNAVIGATION_MENUS_QUERY,\n\t\t\t];\n\t\t\treturn {\n\t\t\t\tstoredSettings: getSettings( false ),\n\t\t\t\tnavigationMenus: getEntityRecords( ...navigationMenusQuery ),\n\t\t\t\thasResolvedNavigationMenus: hasFinishedResolution(\n\t\t\t\t\t'getEntityRecords',\n\t\t\t\t\tnavigationMenusQuery\n\t\t\t\t),\n\t\t\t};\n\t\t}, [] );\n\n\t// Sort navigation menus by date.\n\tconst orderedNavigationMenus = useMemo(\n\t\t() =>\n\t\t\tnavigationMenus?.sort( ( menuA, menuB ) => {\n\t\t\t\tconst menuADate = new Date( menuA.date );\n\t\t\t\tconst menuBDate = new Date( menuB.date );\n\t\t\t\treturn menuADate.getTime() > menuBDate.getTime();\n\t\t\t} ),\n\t\t[ navigationMenus ]\n\t);\n\tconst firstNavigationMenu = orderedNavigationMenus?.[ 0 ]?.id;\n\tconst blocks = useMemo( () => {\n\t\treturn [\n\t\t\tcreateBlock( 'core/navigation', { ref: firstNavigationMenu } ),\n\t\t];\n\t}, [ firstNavigationMenu ] );\n\n\tconst isLoading = ! hasResolvedNavigationMenus;\n\tconst hasNavigationMenus = !! navigationMenus?.length;\n\n\tconst onSelect = useCallback(\n\t\t( selectedBlock ) => {\n\t\t\tconst { attributes, name } = selectedBlock;\n\t\t\tif (\n\t\t\t\tattributes.kind === 'post-type' &&\n\t\t\t\tattributes.id &&\n\t\t\t\tattributes.type &&\n\t\t\t\thistory\n\t\t\t) {\n\t\t\t\thistory.push( {\n\t\t\t\t\tpostType: attributes.type,\n\t\t\t\t\tpostId: attributes.id,\n\t\t\t\t} );\n\t\t\t}\n\t\t\tif ( name === 'core/page-list-item' && attributes.id && history ) {\n\t\t\t\thistory.push( {\n\t\t\t\t\tpostType: 'page',\n\t\t\t\t\tpostId: attributes.id,\n\t\t\t\t} );\n\t\t\t}\n\t\t},\n\t\t[ history ]\n\t);\n\tconst orderInitialBlockItems = useCallback( ( items ) => {\n\t\titems.sort( ( { id: aName }, { id: bName } ) => {\n\t\t\t// Sort block items according to `prioritizedInserterBlocks`.\n\t\t\tlet aIndex = prioritizedInserterBlocks.indexOf( aName );\n\t\t\tlet bIndex = prioritizedInserterBlocks.indexOf( bName );\n\t\t\t// All other block items should come after that.\n\t\t\tif ( aIndex < 0 ) aIndex = prioritizedInserterBlocks.length;\n\t\t\tif ( bIndex < 0 ) bIndex = prioritizedInserterBlocks.length;\n\t\t\treturn aIndex - bIndex;\n\t\t} );\n\t\treturn items;\n\t}, [] );\n\n\tif ( hasResolvedNavigationMenus && ! hasNavigationMenus ) {\n\t\treturn (\n\t\t\t<SidebarNavigationScreenWrapper>\n\t\t\t\t{ __( 'There are no Navigation Menus.' ) }\n\t\t\t</SidebarNavigationScreenWrapper>\n\t\t);\n\t}\n\n\tif ( ! hasResolvedNavigationMenus || isLoading ) {\n\t\treturn (\n\t\t\t<SidebarNavigationScreenWrapper>\n\t\t\t\t<NavigationMenuLoader />\n\t\t\t</SidebarNavigationScreenWrapper>\n\t\t);\n\t}\n\tconst { PrivateInserter } = unlock( blockEditorPrivateApis );\n\treturn (\n\t\t<BlockEditorProvider\n\t\t\tsettings={ storedSettings }\n\t\t\tvalue={ blocks }\n\t\t\tonChange={ noop }\n\t\t\tonInput={ noop }\n\t\t>\n\t\t\t<SidebarNavigationScreenWrapper\n\t\t\t\tactions={\n\t\t\t\t\t<PrivateInserter\n\t\t\t\t\t\trootClientId={ blocks[ 0 ].clientId }\n\t\t\t\t\t\tposition=\"bottom right\"\n\t\t\t\t\t\tisAppender\n\t\t\t\t\t\tselectBlockOnInsert={ false }\n\t\t\t\t\t\tshouldDirectInsert={ false }\n\t\t\t\t\t\t__experimentalIsQuick\n\t\t\t\t\t\ttoggleProps={ {\n\t\t\t\t\t\t\tas: SidebarButton,\n\t\t\t\t\t\t\tlabel: __( 'Add menu item' ),\n\t\t\t\t\t\t} }\n\t\t\t\t\t\torderInitialBlockItems={ orderInitialBlockItems }\n\t\t\t\t\t/>\n\t\t\t\t}\n\t\t\t>\n\t\t\t\t<div className=\"edit-site-sidebar-navigation-screen-navigation-menus__content\">\n\t\t\t\t\t<NavigationMenuContent\n\t\t\t\t\t\trootClientId={ blocks[ 0 ].clientId }\n\t\t\t\t\t\tonSelect={ onSelect }\n\t\t\t\t\t/>\n\t\t\t\t</div>\n\t\t\t</SidebarNavigationScreenWrapper>\n\t\t</BlockEditorProvider>\n\t);\n}\n"]}
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.NavigationMenuLoader = NavigationMenuLoader;
7
+
8
+ var _element = require("@wordpress/element");
9
+
10
+ function NavigationMenuLoader() {
11
+ return (0, _element.createElement)(_element.Fragment, null, (0, _element.createElement)("div", {
12
+ className: "edit-site-sidebar-navigation-screen-navigation-menus__placeholder"
13
+ }), (0, _element.createElement)("div", {
14
+ className: "edit-site-sidebar-navigation-screen-navigation-menus__placeholder"
15
+ }), (0, _element.createElement)("div", {
16
+ className: "edit-site-sidebar-navigation-screen-navigation-menus__placeholder"
17
+ }));
18
+ }
19
+ //# sourceMappingURL=loader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["@wordpress/edit-site/src/components/sidebar-navigation-screen-navigation-menus/loader.js"],"names":["NavigationMenuLoader"],"mappings":";;;;;;;;;AAAO,SAASA,oBAAT,GAAgC;AACtC,SACC,qDACC;AAAK,IAAA,SAAS,EAAC;AAAf,IADD,EAEC;AAAK,IAAA,SAAS,EAAC;AAAf,IAFD,EAGC;AAAK,IAAA,SAAS,EAAC;AAAf,IAHD,CADD;AAOA","sourcesContent":["export function NavigationMenuLoader() {\n\treturn (\n\t\t<>\n\t\t\t<div className=\"edit-site-sidebar-navigation-screen-navigation-menus__placeholder\" />\n\t\t\t<div className=\"edit-site-sidebar-navigation-screen-navigation-menus__placeholder\" />\n\t\t\t<div className=\"edit-site-sidebar-navigation-screen-navigation-menus__placeholder\" />\n\t\t</>\n\t);\n}\n"]}
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = NavigationMenuContent;
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 _blocks = require("@wordpress/blocks");
15
+
16
+ var _privateApis = require("../../private-apis");
17
+
18
+ var _loader = require("./loader");
19
+
20
+ /**
21
+ * WordPress dependencies
22
+ */
23
+
24
+ /**
25
+ * Internal dependencies
26
+ */
27
+ function NavigationMenuContent(_ref) {
28
+ let {
29
+ rootClientId,
30
+ onSelect
31
+ } = _ref;
32
+ const {
33
+ clientIdsTree,
34
+ isLoading
35
+ } = (0, _data.useSelect)(select => {
36
+ const {
37
+ __unstableGetClientIdsTree,
38
+ areInnerBlocksControlled
39
+ } = select(_blockEditor.store);
40
+ return {
41
+ clientIdsTree: __unstableGetClientIdsTree(rootClientId),
42
+ // This is a small hack to wait for the navigation block
43
+ // to actually load its inner blocks.
44
+ isLoading: !areInnerBlocksControlled(rootClientId)
45
+ };
46
+ }, [rootClientId]);
47
+ const {
48
+ replaceBlock,
49
+ __unstableMarkNextChangeAsNotPersistent
50
+ } = (0, _data.useDispatch)(_blockEditor.store);
51
+ const {
52
+ OffCanvasEditor,
53
+ LeafMoreMenu
54
+ } = (0, _privateApis.unlock)(_blockEditor.privateApis);
55
+ const offCanvasOnselect = (0, _element.useCallback)(block => {
56
+ if (block.name === 'core/navigation-link' && !block.attributes.url) {
57
+ __unstableMarkNextChangeAsNotPersistent();
58
+
59
+ replaceBlock(block.clientId, (0, _blocks.createBlock)('core/navigation-link', block.attributes));
60
+ } else {
61
+ onSelect(block);
62
+ }
63
+ }, [onSelect, __unstableMarkNextChangeAsNotPersistent, replaceBlock]); // The hidden block is needed because it makes block edit side effects trigger.
64
+ // For example a navigation page list load its items has an effect on edit to load its items.
65
+
66
+ return (0, _element.createElement)(_element.Fragment, null, isLoading && (0, _element.createElement)(_loader.NavigationMenuLoader, null), !isLoading && (0, _element.createElement)(OffCanvasEditor, {
67
+ blocks: clientIdsTree,
68
+ onSelect: offCanvasOnselect,
69
+ LeafMoreMenu: LeafMoreMenu,
70
+ showAppender: false
71
+ }), (0, _element.createElement)("div", {
72
+ style: {
73
+ visibility: 'hidden'
74
+ }
75
+ }, (0, _element.createElement)(_blockEditor.BlockTools, null, (0, _element.createElement)(_blockEditor.BlockList, null))));
76
+ }
77
+ //# sourceMappingURL=navigation-menu-content.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["@wordpress/edit-site/src/components/sidebar-navigation-screen-navigation-menus/navigation-menu-content.js"],"names":["NavigationMenuContent","rootClientId","onSelect","clientIdsTree","isLoading","select","__unstableGetClientIdsTree","areInnerBlocksControlled","blockEditorStore","replaceBlock","__unstableMarkNextChangeAsNotPersistent","OffCanvasEditor","LeafMoreMenu","blockEditorPrivateApis","offCanvasOnselect","block","name","attributes","url","clientId","visibility"],"mappings":";;;;;;;AAWA;;AARA;;AAMA;;AACA;;AAMA;;AACA;;AAjBA;AACA;AACA;;AAWA;AACA;AACA;AAIe,SAASA,qBAAT,OAA6D;AAAA,MAA7B;AAAEC,IAAAA,YAAF;AAAgBC,IAAAA;AAAhB,GAA6B;AAC3E,QAAM;AAAEC,IAAAA,aAAF;AAAiBC,IAAAA;AAAjB,MAA+B,qBAClCC,M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D;AAkBA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\tprivateApis as blockEditorPrivateApis,\n\tstore as blockEditorStore,\n\tBlockList,\n\tBlockTools,\n} from '@wordpress/block-editor';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { createBlock } from '@wordpress/blocks';\nimport { useCallback } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { unlock } from '../../private-apis';\nimport { NavigationMenuLoader } from './loader';\n\nexport default function NavigationMenuContent( { rootClientId, onSelect } ) {\n\tconst { clientIdsTree, isLoading } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { __unstableGetClientIdsTree, areInnerBlocksControlled } =\n\t\t\t\tselect( blockEditorStore );\n\t\t\treturn {\n\t\t\t\tclientIdsTree: __unstableGetClientIdsTree( rootClientId ),\n\n\t\t\t\t// This is a small hack to wait for the navigation block\n\t\t\t\t// to actually load its inner blocks.\n\t\t\t\tisLoading: ! areInnerBlocksControlled( rootClientId ),\n\t\t\t};\n\t\t},\n\t\t[ rootClientId ]\n\t);\n\tconst { replaceBlock, __unstableMarkNextChangeAsNotPersistent } =\n\t\tuseDispatch( blockEditorStore );\n\n\tconst { OffCanvasEditor, LeafMoreMenu } = unlock( blockEditorPrivateApis );\n\n\tconst offCanvasOnselect = useCallback(\n\t\t( block ) => {\n\t\t\tif (\n\t\t\t\tblock.name === 'core/navigation-link' &&\n\t\t\t\t! block.attributes.url\n\t\t\t) {\n\t\t\t\t__unstableMarkNextChangeAsNotPersistent();\n\t\t\t\treplaceBlock(\n\t\t\t\t\tblock.clientId,\n\t\t\t\t\tcreateBlock( 'core/navigation-link', block.attributes )\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\tonSelect( block );\n\t\t\t}\n\t\t},\n\t\t[ onSelect, __unstableMarkNextChangeAsNotPersistent, replaceBlock ]\n\t);\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{ isLoading && <NavigationMenuLoader /> }\n\t\t\t{ ! isLoading && (\n\t\t\t\t<OffCanvasEditor\n\t\t\t\t\tblocks={ clientIdsTree }\n\t\t\t\t\tonSelect={ offCanvasOnselect }\n\t\t\t\t\tLeafMoreMenu={ LeafMoreMenu }\n\t\t\t\t\tshowAppender={ false }\n\t\t\t\t/>\n\t\t\t) }\n\t\t\t<div style={ { visibility: 'hidden' } }>\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"]}
@@ -15,6 +15,8 @@ var _data = require("@wordpress/data");
15
15
 
16
16
  var _icons = require("@wordpress/icons");
17
17
 
18
+ var _components = require("@wordpress/components");
19
+
18
20
  var _sidebarNavigationScreen = _interopRequireDefault(require("../sidebar-navigation-screen"));
19
21
 
20
22
  var _useEditedEntityRecord = _interopRequireDefault(require("../use-edited-entity-record"));
@@ -33,6 +35,13 @@ var _sidebarButton = _interopRequireDefault(require("../sidebar-button"));
33
35
  * Internal dependencies
34
36
  */
35
37
  function SidebarNavigationScreenTemplate() {
38
+ const {
39
+ params
40
+ } = (0, _components.__experimentalUseNavigator)();
41
+ const {
42
+ postType,
43
+ postId
44
+ } = params;
36
45
  const {
37
46
  setCanvasMode
38
47
  } = (0, _privateApis.unlock)((0, _data.useDispatch)(_store.store));
@@ -40,11 +49,16 @@ function SidebarNavigationScreenTemplate() {
40
49
  getDescription,
41
50
  getTitle,
42
51
  record
43
- } = (0, _useEditedEntityRecord.default)();
52
+ } = (0, _useEditedEntityRecord.default)(postType, postId);
44
53
  let description = getDescription();
45
54
 
46
- if (!description && record.is_custom) {
47
- description = (0, _i18n.__)('This is a custom template that can be applied manually to any Post or Page.');
55
+ if (!description) {
56
+ if (record.type === 'wp_template' && record.is_custom) {
57
+ description = (0, _i18n.__)('This is a custom template that can be applied manually to any Post or Page.');
58
+ } else if (record.type === 'wp_template_part') {
59
+ description = (0, _i18n.sprintf)( // translators: %s: template part title e.g: "Header".
60
+ (0, _i18n.__)('This is your %s template part.'), getTitle());
61
+ }
48
62
  }
49
63
 
50
64
  return (0, _element.createElement)(_sidebarNavigationScreen.default, {
@@ -54,7 +68,7 @@ function SidebarNavigationScreenTemplate() {
54
68
  label: (0, _i18n.__)('Edit'),
55
69
  icon: _icons.pencil
56
70
  }),
57
- content: description ? (0, _element.createElement)("p", null, description) : undefined
71
+ description: description
58
72
  });
59
73
  }
60
74
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/edit-site/src/components/sidebar-navigation-screen-template/index.js"],"names":["SidebarNavigationScreenTemplate","setCanvasMode","editSiteStore","getDescription","getTitle","record","description","is_custom","pencil","undefined"],"mappings":";;;;;;;;;;;AAGA;;AACA;;AACA;;AAKA;;AACA;;AACA;;AACA;;AACA;;AAdA;AACA;AACA;;AAKA;AACA;AACA;AAOe,SAASA,+BAAT,GAA2C;AACzD,QAAM;AAAEC,IAAAA;AAAF,MAAoB,yBAAQ,uBAAaC,YAAb,CAAR,CAA1B;AACA,QAAM;AAAEC,IAAAA,cAAF;AAAkBC,IAAAA,QAAlB;AAA4BC,IAAAA;AAA5B,MAAuC,qCAA7C;AACA,MAAIC,WAAW,GAAGH,cAAc,EAAhC;;AACA,MAAK,CAAEG,WAAF,IAAiBD,MAAM,CAACE,SAA7B,EAAyC;AACxCD,IAAAA,WAAW,GAAG,cACb,6EADa,CAAd;AAGA;;AAED,SACC,4BAAC,gCAAD;AACC,IAAA,KAAK,EAAGF,QAAQ,EADjB;AAEC,IAAA,OAAO,EACN,4BAAC,sBAAD;AACC,MAAA,OAAO,EAAG,MAAMH,aAAa,CAAE,MAAF,CAD9B;AAEC,MAAA,KAAK,EAAG,cAAI,MAAJ,CAFT;AAGC,MAAA,IAAI,EAAGO;AAHR,MAHF;AASC,IAAA,OAAO,EAAGF,WAAW,GAAG,uCAAKA,WAAL,CAAH,GAA4BG;AATlD,IADD;AAaA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { useDispatch } from '@wordpress/data';\nimport { pencil } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport SidebarNavigationScreen from '../sidebar-navigation-screen';\nimport useEditedEntityRecord from '../use-edited-entity-record';\nimport { unlock } from '../../private-apis';\nimport { store as editSiteStore } from '../../store';\nimport SidebarButton from '../sidebar-button';\n\nexport default function SidebarNavigationScreenTemplate() {\n\tconst { setCanvasMode } = unlock( useDispatch( editSiteStore ) );\n\tconst { getDescription, getTitle, record } = useEditedEntityRecord();\n\tlet description = getDescription();\n\tif ( ! description && record.is_custom ) {\n\t\tdescription = __(\n\t\t\t'This is a custom template that can be applied manually to any Post or Page.'\n\t\t);\n\t}\n\n\treturn (\n\t\t<SidebarNavigationScreen\n\t\t\ttitle={ getTitle() }\n\t\t\tactions={\n\t\t\t\t<SidebarButton\n\t\t\t\t\tonClick={ () => setCanvasMode( 'edit' ) }\n\t\t\t\t\tlabel={ __( 'Edit' ) }\n\t\t\t\t\ticon={ pencil }\n\t\t\t\t/>\n\t\t\t}\n\t\t\tcontent={ description ? <p>{ description }</p> : undefined }\n\t\t/>\n\t);\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/edit-site/src/components/sidebar-navigation-screen-template/index.js"],"names":["SidebarNavigationScreenTemplate","params","postType","postId","setCanvasMode","editSiteStore","getDescription","getTitle","record","description","type","is_custom","pencil"],"mappings":";;;;;;;;;;;AAGA;;AACA;;AACA;;AACA;;AAKA;;AACA;;AACA;;AACA;;AACA;;AAfA;AACA;AACA;;AAMA;AACA;AACA;AAOe,SAASA,+BAAT,GAA2C;AACzD,QAAM;AAAEC,IAAAA;AAAF,MAAa,6CAAnB;AACA,QAAM;AAAEC,IAAAA,QAAF;AAAYC,IAAAA;AAAZ,MAAuBF,MAA7B;AACA,QAAM;AAAEG,IAAAA;AAAF,MAAoB,yBAAQ,uBAAaC,YAAb,CAAR,CAA1B;AACA,QAAM;AAAEC,IAAAA,cAAF;AAAkBC,IAAAA,QAAlB;AAA4BC,IAAAA;AAA5B,MAAuC,oCAC5CN,QAD4C,EAE5CC,MAF4C,CAA7C;AAIA,MAAIM,WAAW,GAAGH,cAAc,EAAhC;;AACA,MAAK,CAAEG,WAAP,EAAqB;AACpB,QAAKD,MAAM,CAACE,IAAP,KAAgB,aAAhB,IAAiCF,MAAM,CAACG,SAA7C,EAAyD;AACxDF,MAAAA,WAAW,GAAG,cACb,6EADa,CAAd;AAGA,KAJD,MAIO,IAAKD,MAAM,CAACE,IAAP,KAAgB,kBAArB,EAA0C;AAChDD,MAAAA,WAAW,GAAG,oBACb;AACA,oBAAI,gCAAJ,CAFa,EAGbF,QAAQ,EAHK,CAAd;AAKA;AACD;;AAED,SACC,4BAAC,gCAAD;AACC,IAAA,KAAK,EAAGA,QAAQ,EADjB;AAEC,IAAA,OAAO,EACN,4BAAC,sBAAD;AACC,MAAA,OAAO,EAAG,MAAMH,aAAa,CAAE,MAAF,CAD9B;AAEC,MAAA,KAAK,EAAG,cAAI,MAAJ,CAFT;AAGC,MAAA,IAAI,EAAGQ;AAHR,MAHF;AASC,IAAA,WAAW,EAAGH;AATf,IADD;AAaA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __, sprintf } from '@wordpress/i18n';\nimport { useDispatch } from '@wordpress/data';\nimport { pencil } from '@wordpress/icons';\nimport { __experimentalUseNavigator as useNavigator } from '@wordpress/components';\n\n/**\n * Internal dependencies\n */\nimport SidebarNavigationScreen from '../sidebar-navigation-screen';\nimport useEditedEntityRecord from '../use-edited-entity-record';\nimport { unlock } from '../../private-apis';\nimport { store as editSiteStore } from '../../store';\nimport SidebarButton from '../sidebar-button';\n\nexport default function SidebarNavigationScreenTemplate() {\n\tconst { params } = useNavigator();\n\tconst { postType, postId } = params;\n\tconst { setCanvasMode } = unlock( useDispatch( editSiteStore ) );\n\tconst { getDescription, getTitle, record } = useEditedEntityRecord(\n\t\tpostType,\n\t\tpostId\n\t);\n\tlet description = getDescription();\n\tif ( ! description ) {\n\t\tif ( record.type === 'wp_template' && record.is_custom ) {\n\t\t\tdescription = __(\n\t\t\t\t'This is a custom template that can be applied manually to any Post or Page.'\n\t\t\t);\n\t\t} else if ( record.type === 'wp_template_part' ) {\n\t\t\tdescription = sprintf(\n\t\t\t\t// translators: %s: template part title e.g: \"Header\".\n\t\t\t\t__( 'This is your %s template part.' ),\n\t\t\t\tgetTitle()\n\t\t\t);\n\t\t}\n\t}\n\n\treturn (\n\t\t<SidebarNavigationScreen\n\t\t\ttitle={ getTitle() }\n\t\t\tactions={\n\t\t\t\t<SidebarButton\n\t\t\t\t\tonClick={ () => setCanvasMode( 'edit' ) }\n\t\t\t\t\tlabel={ __( 'Edit' ) }\n\t\t\t\t\ticon={ pencil }\n\t\t\t\t/>\n\t\t\t}\n\t\t\tdescription={ description }\n\t\t/>\n\t);\n}\n"]}
@@ -48,7 +48,8 @@ const config = {
48
48
  title: (0, _i18n.__)('Templates'),
49
49
  loading: (0, _i18n.__)('Loading templates'),
50
50
  notFound: (0, _i18n.__)('No templates found'),
51
- manage: (0, _i18n.__)('Manage all templates')
51
+ manage: (0, _i18n.__)('Manage all templates'),
52
+ description: (0, _i18n.__)('Express the layout of your site with templates.')
52
53
  }
53
54
  },
54
55
  wp_template_part: {
@@ -56,7 +57,8 @@ const config = {
56
57
  title: (0, _i18n.__)('Template parts'),
57
58
  loading: (0, _i18n.__)('Loading template parts'),
58
59
  notFound: (0, _i18n.__)('No template parts found'),
59
- manage: (0, _i18n.__)('Manage all template parts')
60
+ manage: (0, _i18n.__)('Manage all template parts'),
61
+ description: (0, _i18n.__)('Template Parts are small pieces of a layout that can be reused across multiple templates and always appear the same way. Common template parts include the site header, footer, or sidebar.')
60
62
  }
61
63
  }
62
64
  };
@@ -100,6 +102,7 @@ function SidebarNavigationScreenTemplates() {
100
102
  return (0, _element.createElement)(_sidebarNavigationScreen.default, {
101
103
  isRoot: isTemplatePartsMode,
102
104
  title: config[postType].labels.title,
105
+ description: config[postType].labels.description,
103
106
  actions: canCreate && (0, _element.createElement)(_addNewTemplate.default, {
104
107
  templateType: postType,
105
108
  toggleProps: {
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/edit-site/src/components/sidebar-navigation-screen-templates/index.js"],"names":["config","wp_template","labels","title","loading","notFound","manage","wp_template_part","TemplateItem","postType","postId","props","linkInfo","SidebarNavigationScreenTemplates","params","isMobileViewport","isTemplatePartsMode","select","settings","editSiteStore","getSettings","supportsTemplatePartsMode","records","templates","isResolving","isLoading","per_page","sortedTemplates","sort","a","b","slug","localeCompare","browseAllLink","path","canCreate","as","SidebarButton","length","map","template","id","rendered"],"mappings":";;;;;;;;;;;;;AAGA;;AAKA;;AACA;;AACA;;AACA;;AACA;;AAKA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAtBA;AACA;AACA;;AAYA;AACA;AACA;AAQA,MAAMA,MAAM,GAAG;AACdC,EAAAA,WAAW,EAAE;AACZC,IAAAA,MAAM,EAAE;AACPC,MAAAA,KAAK,EAAE,cAAI,WAAJ,CADA;AAEPC,MAAAA,OAAO,EAAE,cAAI,mBAAJ,CAFF;AAGPC,MAAAA,QAAQ,EAAE,cAAI,oBAAJ,CAHH;AAIPC,MAAAA,MAAM,EAAE,cAAI,sBAAJ;AAJD;AADI,GADC;AASdC,EAAAA,gBAAgB,EAAE;AACjBL,IAAAA,MAAM,EAAE;AACPC,MAAAA,KAAK,EAAE,cAAI,gBAAJ,CADA;AAEPC,MAAAA,OAAO,EAAE,cAAI,wBAAJ,CAFF;AAGPC,MAAAA,QAAQ,EAAE,cAAI,yBAAJ,CAHH;AAIPC,MAAAA,MAAM,EAAE,cAAI,2BAAJ;AAJD;AADS;AATJ,CAAf;;AAmBA,MAAME,YAAY,GAAG,QAAsC;AAAA,MAApC;AAAEC,IAAAA,QAAF;AAAYC,IAAAA,MAAZ;AAAoB,OAAGC;AAAvB,GAAoC;AAC1D,QAAMC,QAAQ,GAAG,mBAAS;AACzBH,IAAAA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AAC,uBAAD;AACC,MAAA,YAAY,EAAG1B,QADhB;AAEC,MAAA,WAAW,EAAG;AACb2B,QAAAA,EAAE,EAAEC;AADS;AAFf,MALH;AAaC,IAAA,OAAO,EACN,qDACGZ,SAAS,IAAIzB,MAAM,CAAES,QAAF,CAAN,CAAmBP,MAAnB,CAA0BE,OAD1C,EAEG,CAAEqB,SAAF,IACD,4BAAC,mCAAD,QACG,EAAEF,SAAF,aAAEA,SAAF,eAAEA,SAAS,CAAEe,MAAb,KACD,4BAAC,8BAAD,QACGtC,MAAM,CAAES,QAAF,CAAN,CAAmBP,MAAnB,CAA0BG,QAD7B,CAFF,EAMGsB,eAAe,CAACY,GAAhB,CAAuBC,QAAF;AAAA;;AAAA,aACtB,4BAAC,YAAD;AACC,QAAA,QAAQ,EAAG/B,QADZ;AAEC,QAAA,MAAM,EAAG+B,QAAQ,CAACC,EAFnB;AAGC,QAAA,GAAG,EAAGD,QAAQ,CAACC;AAHhB,SAKG,kCACD,oBAAAD,QAAQ,CAACrC,KAAT,oEAAgBuC,QAAhB,KACCF,QAAQ,CAACT,IAFT,CALH,CADsB;AAAA,KAArB,CANH,EAkBG,CAAEhB,gBAAF,IACD,4BAAC,8BAAD;AACC,MAAA,SAAS,EAAC;AADX,OAEMkB,aAFN;AAGC,MAAA,QAAQ,EACPjC,MAAM,CAAES,QAAF,CAAN,CAAmBP,MAAnB,CAA0BI;AAJ5B,OAnBF,CAHF;AAdF,IADD;AAmDA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\t__experimentalItemGroup as ItemGroup,\n\t__experimentalItem as Item,\n\t__experimentalUseNavigator as useNavigator,\n} from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { useEntityRecords } from '@wordpress/core-data';\nimport { useSelect } from '@wordpress/data';\nimport { decodeEntities } from '@wordpress/html-entities';\nimport { useViewportMatch } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport SidebarNavigationScreen from '../sidebar-navigation-screen';\nimport { useLink } from '../routes/link';\nimport SidebarNavigationItem from '../sidebar-navigation-item';\nimport AddNewTemplate from '../add-new-template';\nimport { store as editSiteStore } from '../../store';\nimport SidebarButton from '../sidebar-button';\n\nconst config = {\n\twp_template: {\n\t\tlabels: {\n\t\t\ttitle: __( 'Templates' ),\n\t\t\tloading: __( 'Loading templates' ),\n\t\t\tnotFound: __( 'No templates found' ),\n\t\t\tmanage: __( 'Manage all templates' ),\n\t\t},\n\t},\n\twp_template_part: {\n\t\tlabels: {\n\t\t\ttitle: __( 'Template parts' ),\n\t\t\tloading: __( 'Loading template parts' ),\n\t\t\tnotFound: __( 'No template parts found' ),\n\t\t\tmanage: __( 'Manage all template parts' ),\n\t\t},\n\t},\n};\n\nconst TemplateItem = ( { postType, postId, ...props } ) => {\n\tconst linkInfo = useLink( {\n\t\tpostType,\n\t\tpostId,\n\t} );\n\treturn <SidebarNavigationItem { ...linkInfo } { ...props } />;\n};\n\nexport default function SidebarNavigationScreenTemplates() {\n\tconst {\n\t\tparams: { postType },\n\t} = useNavigator();\n\tconst isMobileViewport = useViewportMatch( 'medium', '<' );\n\tconst isTemplatePartsMode = useSelect( ( select ) => {\n\t\tconst settings = select( editSiteStore ).getSettings();\n\n\t\treturn !! settings.supportsTemplatePartsMode;\n\t}, [] );\n\n\tconst { records: templates, isResolving: isLoading } = useEntityRecords(\n\t\t'postType',\n\t\tpostType,\n\t\t{\n\t\t\tper_page: -1,\n\t\t}\n\t);\n\tconst sortedTemplates = templates ? [ ...templates ] : [];\n\tsortedTemplates.sort( ( a, b ) => a.slug.localeCompare( b.slug ) );\n\n\tconst browseAllLink = useLink( {\n\t\tpath: '/' + postType + '/all',\n\t} );\n\n\tconst canCreate = ! isMobileViewport && ! isTemplatePartsMode;\n\n\treturn (\n\t\t<SidebarNavigationScreen\n\t\t\tisRoot={ isTemplatePartsMode }\n\t\t\ttitle={ config[ postType ].labels.title }\n\t\t\tactions={\n\t\t\t\tcanCreate && (\n\t\t\t\t\t<AddNewTemplate\n\t\t\t\t\t\ttemplateType={ postType }\n\t\t\t\t\t\ttoggleProps={ {\n\t\t\t\t\t\t\tas: SidebarButton,\n\t\t\t\t\t\t} }\n\t\t\t\t\t/>\n\t\t\t\t)\n\t\t\t}\n\t\t\tcontent={\n\t\t\t\t<>\n\t\t\t\t\t{ isLoading && config[ postType ].labels.loading }\n\t\t\t\t\t{ ! isLoading && (\n\t\t\t\t\t\t<ItemGroup>\n\t\t\t\t\t\t\t{ ! templates?.length && (\n\t\t\t\t\t\t\t\t<Item>\n\t\t\t\t\t\t\t\t\t{ config[ postType ].labels.notFound }\n\t\t\t\t\t\t\t\t</Item>\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t{ sortedTemplates.map( ( template ) => (\n\t\t\t\t\t\t\t\t<TemplateItem\n\t\t\t\t\t\t\t\t\tpostType={ postType }\n\t\t\t\t\t\t\t\t\tpostId={ template.id }\n\t\t\t\t\t\t\t\t\tkey={ template.id }\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t{ decodeEntities(\n\t\t\t\t\t\t\t\t\t\ttemplate.title?.rendered ||\n\t\t\t\t\t\t\t\t\t\t\ttemplate.slug\n\t\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t</TemplateItem>\n\t\t\t\t\t\t\t) ) }\n\t\t\t\t\t\t\t{ ! isMobileViewport && (\n\t\t\t\t\t\t\t\t<SidebarNavigationItem\n\t\t\t\t\t\t\t\t\tclassName=\"edit-site-sidebar-navigation-screen-templates__see-all\"\n\t\t\t\t\t\t\t\t\t{ ...browseAllLink }\n\t\t\t\t\t\t\t\t\tchildren={\n\t\t\t\t\t\t\t\t\t\tconfig[ postType ].labels.manage\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t</ItemGroup>\n\t\t\t\t\t) }\n\t\t\t\t</>\n\t\t\t}\n\t\t/>\n\t);\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/edit-site/src/components/sidebar-navigation-screen-templates/index.js"],"names":["config","wp_template","labels","title","loading","notFound","manage","description","wp_template_part","TemplateItem","postType","postId","props","linkInfo","SidebarNavigationScreenTemplates","params","isMobileViewport","isTemplatePartsMode","select","settings","editSiteStore","getSettings","supportsTemplatePartsMode","records","templates","isResolving","isLoading","per_page","sortedTemplates","sort","a","b","slug","localeCompare","browseAllLink","path","canCreate","as","SidebarButton","length","map","template","id","rendered"],"mappings":";;;;;;;;;;;;;AAGA;;AAKA;;AACA;;AACA;;AACA;;AACA;;AAKA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAtBA;AACA;AACA;;AAYA;AACA;AACA;AAQA,MAAMA,MAAM,GAAG;AACdC,EAAAA,WAAW,EAAE;AACZC,IAAAA,MAAM,EAAE;AACPC,MAAAA,KAAK,EAAE,cAAI,WAAJ,CADA;AAEPC,MAAAA,OAAO,EAAE,cAAI,mBAAJ,CAFF;AAGPC,MAAAA,QAAQ,EAAE,cAAI,oBAAJ,CAHH;AAIPC,MAAAA,MAAM,EAAE,cAAI,sBAAJ,CAJD;AAKPC,MAAAA,WAAW,EAAE,cACZ,iDADY;AALN;AADI,GADC;AAYdC,EAAAA,gBAAgB,EAAE;AACjBN,IAAAA,MAAM,EAAE;AACPC,MAAAA,KAAK,EAAE,cAAI,gBAAJ,CADA;AAEPC,MAAAA,OAAO,EAAE,cAAI,wBAAJ,CAFF;AAGPC,MAAAA,QAAQ,EAAE,cAAI,yBAAJ,CAHH;AAIPC,MAAAA,MAAM,EAAE,cAAI,2BAAJ,CAJD;AAKPC,MAAAA,WAAW,EAAE,cACZ,6LADY;AALN;AADS;AAZJ,CAAf;;AAyBA,MAAME,YAAY,GAAG,QAAsC;AAAA,MAApC;AAAEC,IAAAA,QAAF;AAAYC,IAAAA,MAAZ;AAAoB,OAAGC;AAAvB,GAAoC;AAC1D,QAAMC,QAAQ,GAAG,mBAAS;AACzBH,IAAAA,QADyB;AAEzBC,IAAAA;AAFyB,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AA0BK,WAHzC;AAIC,IAAA,OAAO,EACN6B,SAAS,IACR,4BAAC,uBAAD;AACC,MAAA,YAAY,EAAG1B,QADhB;AAEC,MAAA,WAAW,EAAG;AACb2B,QAAAA,EAAE,EAAEC;AADS;AAFf,MANH;AAcC,IAAA,OAAO,EACN,qDACGZ,SAAS,IAAI1B,MAAM,CAAEU,QAAF,CAAN,CAAmBR,MAAnB,CAA0BE,OAD1C,EAEG,CAAEsB,SAAF,IACD,4BAAC,mCAAD,QACG,EAAEF,SAAF,aAAEA,SAAF,eAAEA,SAAS,CAAEe,MAAb,KACD,4BAAC,8BAAD,QACGvC,MAAM,CAAEU,QAAF,CAAN,CAAmBR,MAAnB,CAA0BG,QAD7B,CAFF,EAMGuB,eAAe,CAACY,GAAhB,CAAuBC,QAAF;AAAA;;AAAA,aACtB,4BAAC,YAAD;AACC,QAAA,QAAQ,EAAG/B,QADZ;AAEC,QAAA,MAAM,EAAG+B,QAAQ,CAACC,EAFnB;AAGC,QAAA,GAAG,EAAGD,QAAQ,CAACC;AAHhB,SAKG,kCACD,oBAAAD,QAAQ,CAACtC,KAAT,oEAAgBwC,QAAhB,KACCF,QAAQ,CAACT,IAFT,CALH,CADsB;AAAA,KAArB,CANH,EAkBG,CAAEhB,gBAAF,IACD,4BAAC,8BAAD;AACC,MAAA,SAAS,EAAC;AADX,OAEMkB,aAFN;AAGC,MAAA,QAAQ,EACPlC,MAAM,CAAEU,QAAF,CAAN,CAAmBR,MAAnB,CAA0BI;AAJ5B,OAnBF,CAHF;AAfF,IADD;AAoDA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\t__experimentalItemGroup as ItemGroup,\n\t__experimentalItem as Item,\n\t__experimentalUseNavigator as useNavigator,\n} from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { useEntityRecords } from '@wordpress/core-data';\nimport { useSelect } from '@wordpress/data';\nimport { decodeEntities } from '@wordpress/html-entities';\nimport { useViewportMatch } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport SidebarNavigationScreen from '../sidebar-navigation-screen';\nimport { useLink } from '../routes/link';\nimport SidebarNavigationItem from '../sidebar-navigation-item';\nimport AddNewTemplate from '../add-new-template';\nimport { store as editSiteStore } from '../../store';\nimport SidebarButton from '../sidebar-button';\n\nconst config = {\n\twp_template: {\n\t\tlabels: {\n\t\t\ttitle: __( 'Templates' ),\n\t\t\tloading: __( 'Loading templates' ),\n\t\t\tnotFound: __( 'No templates found' ),\n\t\t\tmanage: __( 'Manage all templates' ),\n\t\t\tdescription: __(\n\t\t\t\t'Express the layout of your site with templates.'\n\t\t\t),\n\t\t},\n\t},\n\twp_template_part: {\n\t\tlabels: {\n\t\t\ttitle: __( 'Template parts' ),\n\t\t\tloading: __( 'Loading template parts' ),\n\t\t\tnotFound: __( 'No template parts found' ),\n\t\t\tmanage: __( 'Manage all template parts' ),\n\t\t\tdescription: __(\n\t\t\t\t'Template Parts are small pieces of a layout that can be reused across multiple templates and always appear the same way. Common template parts include the site header, footer, or sidebar.'\n\t\t\t),\n\t\t},\n\t},\n};\n\nconst TemplateItem = ( { postType, postId, ...props } ) => {\n\tconst linkInfo = useLink( {\n\t\tpostType,\n\t\tpostId,\n\t} );\n\treturn <SidebarNavigationItem { ...linkInfo } { ...props } />;\n};\n\nexport default function SidebarNavigationScreenTemplates() {\n\tconst {\n\t\tparams: { postType },\n\t} = useNavigator();\n\tconst isMobileViewport = useViewportMatch( 'medium', '<' );\n\tconst isTemplatePartsMode = useSelect( ( select ) => {\n\t\tconst settings = select( editSiteStore ).getSettings();\n\n\t\treturn !! settings.supportsTemplatePartsMode;\n\t}, [] );\n\n\tconst { records: templates, isResolving: isLoading } = useEntityRecords(\n\t\t'postType',\n\t\tpostType,\n\t\t{\n\t\t\tper_page: -1,\n\t\t}\n\t);\n\tconst sortedTemplates = templates ? [ ...templates ] : [];\n\tsortedTemplates.sort( ( a, b ) => a.slug.localeCompare( b.slug ) );\n\n\tconst browseAllLink = useLink( {\n\t\tpath: '/' + postType + '/all',\n\t} );\n\n\tconst canCreate = ! isMobileViewport && ! isTemplatePartsMode;\n\n\treturn (\n\t\t<SidebarNavigationScreen\n\t\t\tisRoot={ isTemplatePartsMode }\n\t\t\ttitle={ config[ postType ].labels.title }\n\t\t\tdescription={ config[ postType ].labels.description }\n\t\t\tactions={\n\t\t\t\tcanCreate && (\n\t\t\t\t\t<AddNewTemplate\n\t\t\t\t\t\ttemplateType={ postType }\n\t\t\t\t\t\ttoggleProps={ {\n\t\t\t\t\t\t\tas: SidebarButton,\n\t\t\t\t\t\t} }\n\t\t\t\t\t/>\n\t\t\t\t)\n\t\t\t}\n\t\t\tcontent={\n\t\t\t\t<>\n\t\t\t\t\t{ isLoading && config[ postType ].labels.loading }\n\t\t\t\t\t{ ! isLoading && (\n\t\t\t\t\t\t<ItemGroup>\n\t\t\t\t\t\t\t{ ! templates?.length && (\n\t\t\t\t\t\t\t\t<Item>\n\t\t\t\t\t\t\t\t\t{ config[ postType ].labels.notFound }\n\t\t\t\t\t\t\t\t</Item>\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t{ sortedTemplates.map( ( template ) => (\n\t\t\t\t\t\t\t\t<TemplateItem\n\t\t\t\t\t\t\t\t\tpostType={ postType }\n\t\t\t\t\t\t\t\t\tpostId={ template.id }\n\t\t\t\t\t\t\t\t\tkey={ template.id }\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t{ decodeEntities(\n\t\t\t\t\t\t\t\t\t\ttemplate.title?.rendered ||\n\t\t\t\t\t\t\t\t\t\t\ttemplate.slug\n\t\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t</TemplateItem>\n\t\t\t\t\t\t\t) ) }\n\t\t\t\t\t\t\t{ ! isMobileViewport && (\n\t\t\t\t\t\t\t\t<SidebarNavigationItem\n\t\t\t\t\t\t\t\t\tclassName=\"edit-site-sidebar-navigation-screen-templates__see-all\"\n\t\t\t\t\t\t\t\t\t{ ...browseAllLink }\n\t\t\t\t\t\t\t\t\tchildren={\n\t\t\t\t\t\t\t\t\t\tconfig[ postType ].labels.manage\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t</ItemGroup>\n\t\t\t\t\t) }\n\t\t\t\t</>\n\t\t\t}\n\t\t/>\n\t);\n}\n"]}
@@ -24,10 +24,12 @@ var _sidebarNavigationScreen = _interopRequireDefault(require("../sidebar-naviga
24
24
  */
25
25
  const config = {
26
26
  wp_template: {
27
- title: (0, _i18n.__)('All templates')
27
+ title: (0, _i18n.__)('All templates'),
28
+ description: (0, _i18n.__)('Create new templates, or reset any customizations made to the templates supplied by your theme.')
28
29
  },
29
30
  wp_template_part: {
30
- title: (0, _i18n.__)('All template parts')
31
+ title: (0, _i18n.__)('All template parts'),
32
+ description: (0, _i18n.__)('Create new template parts, or reset any customisations made to the template parts supplied by your theme.')
31
33
  }
32
34
  };
33
35
 
@@ -38,7 +40,8 @@ function SidebarNavigationScreenTemplatesBrowse() {
38
40
  }
39
41
  } = (0, _components.__experimentalUseNavigator)();
40
42
  return (0, _element.createElement)(_sidebarNavigationScreen.default, {
41
- title: config[postType].title
43
+ title: config[postType].title,
44
+ description: config[postType].description
42
45
  });
43
46
  }
44
47
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/edit-site/src/components/sidebar-navigation-screen-templates-browse/index.js"],"names":["config","wp_template","title","wp_template_part","SidebarNavigationScreenTemplatesBrowse","params","postType"],"mappings":";;;;;;;;;;;AAGA;;AACA;;AAKA;;AATA;AACA;AACA;;AAIA;AACA;AACA;AAGA,MAAMA,MAAM,GAAG;AACdC,EAAAA,WAAW,EAAE;AACZC,IAAAA,KAAK,EAAE,cAAI,eAAJ;AADK,GADC;AAIdC,EAAAA,gBAAgB,EAAE;AACjBD,IAAAA,KAAK,EAAE,cAAI,oBAAJ;AADU;AAJJ,CAAf;;AASe,SAASE,sCAAT,GAAkD;AAChE,QAAM;AACLC,IAAAA,MAAM,EAAE;AAAEC,MAAAA;AAAF;AADH,MAEF,6CAFJ;AAGA,SAAO,4BAAC,gCAAD;AAAyB,IAAA,KAAK,EAAGN,MAAM,CAAEM,QAAF,CAAN,CAAmBJ;AAApD,IAAP;AACA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { __experimentalUseNavigator as useNavigator } from '@wordpress/components';\n\n/**\n * Internal dependencies\n */\nimport SidebarNavigationScreen from '../sidebar-navigation-screen';\n\nconst config = {\n\twp_template: {\n\t\ttitle: __( 'All templates' ),\n\t},\n\twp_template_part: {\n\t\ttitle: __( 'All template parts' ),\n\t},\n};\n\nexport default function SidebarNavigationScreenTemplatesBrowse() {\n\tconst {\n\t\tparams: { postType },\n\t} = useNavigator();\n\treturn <SidebarNavigationScreen title={ config[ postType ].title } />;\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/edit-site/src/components/sidebar-navigation-screen-templates-browse/index.js"],"names":["config","wp_template","title","description","wp_template_part","SidebarNavigationScreenTemplatesBrowse","params","postType"],"mappings":";;;;;;;;;;;AAGA;;AACA;;AAKA;;AATA;AACA;AACA;;AAIA;AACA;AACA;AAGA,MAAMA,MAAM,GAAG;AACdC,EAAAA,WAAW,EAAE;AACZC,IAAAA,KAAK,EAAE,cAAI,eAAJ,CADK;AAEZC,IAAAA,WAAW,EAAE,cACZ,iGADY;AAFD,GADC;AAOdC,EAAAA,gBAAgB,EAAE;AACjBF,IAAAA,KAAK,EAAE,cAAI,oBAAJ,CADU;AAEjBC,IAAAA,WAAW,EAAE,cACZ,2GADY;AAFI;AAPJ,CAAf;;AAee,SAASE,sCAAT,GAAkD;AAChE,QAAM;AACLC,IAAAA,MAAM,EAAE;AAAEC,MAAAA;AAAF;AADH,MAEF,6CAFJ;AAGA,SACC,4BAAC,gCAAD;AACC,IAAA,KAAK,EAAGP,MAAM,CAAEO,QAAF,CAAN,CAAmBL,KAD5B;AAEC,IAAA,WAAW,EAAGF,MAAM,CAAEO,QAAF,CAAN,CAAmBJ;AAFlC,IADD;AAMA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { __experimentalUseNavigator as useNavigator } from '@wordpress/components';\n\n/**\n * Internal dependencies\n */\nimport SidebarNavigationScreen from '../sidebar-navigation-screen';\n\nconst config = {\n\twp_template: {\n\t\ttitle: __( 'All templates' ),\n\t\tdescription: __(\n\t\t\t'Create new templates, or reset any customizations made to the templates supplied by your theme.'\n\t\t),\n\t},\n\twp_template_part: {\n\t\ttitle: __( 'All template parts' ),\n\t\tdescription: __(\n\t\t\t'Create new template parts, or reset any customisations made to the template parts supplied by your theme.'\n\t\t),\n\t},\n};\n\nexport default function SidebarNavigationScreenTemplatesBrowse() {\n\tconst {\n\t\tparams: { postType },\n\t} = useNavigator();\n\treturn (\n\t\t<SidebarNavigationScreen\n\t\t\ttitle={ config[ postType ].title }\n\t\t\tdescription={ config[ postType ].description }\n\t\t/>\n\t);\n}\n"]}
@@ -33,24 +33,40 @@ function useSyncCanvasModeWithURL() {
33
33
  } = (0, _privateApis.unlock)((0, _data.useDispatch)(_store.store));
34
34
  const currentCanvasMode = (0, _element.useRef)(canvasMode);
35
35
  const {
36
- canvas: canvasInUrl = 'view'
36
+ canvas: canvasInUrl
37
37
  } = params;
38
38
  const currentCanvasInUrl = (0, _element.useRef)(canvasInUrl);
39
+ const currentUrlParams = (0, _element.useRef)(params);
40
+ (0, _element.useEffect)(() => {
41
+ currentUrlParams.current = params;
42
+ }, [params]);
39
43
  (0, _element.useEffect)(() => {
40
44
  currentCanvasMode.current = canvasMode;
41
45
 
42
- if (currentCanvasMode !== currentCanvasInUrl) {
43
- history.push({ ...params,
44
- canvas: canvasMode
46
+ if (canvasMode === 'init') {
47
+ return;
48
+ }
49
+
50
+ if (canvasMode === 'edit' && currentCanvasInUrl.current !== canvasMode) {
51
+ history.push({ ...currentUrlParams.current,
52
+ canvas: 'edit'
53
+ });
54
+ }
55
+
56
+ if (canvasMode === 'view' && currentCanvasInUrl.current !== undefined) {
57
+ history.push({ ...currentUrlParams.current,
58
+ canvas: undefined
45
59
  });
46
60
  }
47
- }, [canvasMode]);
61
+ }, [canvasMode, history]);
48
62
  (0, _element.useEffect)(() => {
49
63
  currentCanvasInUrl.current = canvasInUrl;
50
64
 
51
- if (canvasInUrl !== currentCanvasMode.current) {
52
- setCanvasMode(canvasInUrl);
65
+ if (canvasInUrl === undefined && currentCanvasMode.current !== 'view') {
66
+ setCanvasMode('view');
67
+ } else if (canvasInUrl === 'edit' && currentCanvasMode.current !== 'edit') {
68
+ setCanvasMode('edit');
53
69
  }
54
- }, [canvasInUrl]);
70
+ }, [canvasInUrl, setCanvasMode]);
55
71
  }
56
72
  //# sourceMappingURL=use-sync-canvas-mode-with-url.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/edit-site/src/components/sync-state-with-url/use-sync-canvas-mode-with-url.js"],"names":["useSyncCanvasModeWithURL","history","params","canvasMode","select","editSiteStore","getCanvasMode","setCanvasMode","currentCanvasMode","canvas","canvasInUrl","currentCanvasInUrl","current","push"],"mappings":";;;;;;;AAGA;;AACA;;AAKA;;AACA;;AACA;;AAXA;AACA;AACA;;AAIA;AACA;AACA;AAKe,SAASA,wBAAT,GAAoC;AAClD,QAAMC,OAAO,GAAG,yBAAhB;AACA,QAAM;AAAEC,IAAAA;AAAF,MAAa,0BAAnB;AACA,QAAMC,UAAU,GAAG,qBAChBC,MAAF,IAAc,yBAAQA,MAAM,CAAEC,YAAF,CAAd,EAAkCC,aAAlC,EADI,EAElB,EAFkB,CAAnB;AAIA,QAAM;AAAEC,IAAAA;AAAF,MAAoB,yBAAQ,uBAAaF,YAAb,CAAR,CAA1B;AACA,QAAMG,iBAAiB,GAAG,qBAAQL,UAAR,CAA1B;AACA,QAAM;AAAEM,IAAAA,MAAM,EAAEC,WAAW,GAAG;AAAxB,MAAmCR,MAAzC;AACA,QAAMS,kBAAkB,GAAG,qBAAQD,WAAR,CAA3B;AACA,0BAAW,MAAM;AAChBF,IAAAA,iBAAiB,CAACI,OAAlB,GAA4BT,UAA5B;;AACA,QAAKK,iBAAiB,KAAKG,kBAA3B,EAAgD;AAC/CV,MAAAA,OAAO,CAACY,IAAR,CAAc,EACb,GAAGX,MADU;AAEbO,QAAAA,MAAM,EAAEN;AAFK,OAAd;AAIA;AACD,GARD,EAQG,CAAEA,UAAF,CARH;AAUA,0BAAW,MAAM;AAChBQ,IAAAA,kBAAkB,CAACC,OAAnB,GAA6BF,WAA7B;;AACA,QAAKA,WAAW,KAAKF,iBAAiB,CAACI,OAAvC,EAAiD;AAChDL,MAAAA,aAAa,CAAEG,WAAF,CAAb;AACA;AACD,GALD,EAKG,CAAEA,WAAF,CALH;AAMA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useEffect, useRef } from '@wordpress/element';\nimport { useSelect, useDispatch } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { store as editSiteStore } from '../../store';\nimport { useLocation, useHistory } from '../routes';\nimport { unlock } from '../../private-apis';\n\nexport default function useSyncCanvasModeWithURL() {\n\tconst history = useHistory();\n\tconst { params } = useLocation();\n\tconst canvasMode = useSelect(\n\t\t( select ) => unlock( select( editSiteStore ) ).getCanvasMode(),\n\t\t[]\n\t);\n\tconst { setCanvasMode } = unlock( useDispatch( editSiteStore ) );\n\tconst currentCanvasMode = useRef( canvasMode );\n\tconst { canvas: canvasInUrl = 'view' } = params;\n\tconst currentCanvasInUrl = useRef( canvasInUrl );\n\tuseEffect( () => {\n\t\tcurrentCanvasMode.current = canvasMode;\n\t\tif ( currentCanvasMode !== currentCanvasInUrl ) {\n\t\t\thistory.push( {\n\t\t\t\t...params,\n\t\t\t\tcanvas: canvasMode,\n\t\t\t} );\n\t\t}\n\t}, [ canvasMode ] );\n\n\tuseEffect( () => {\n\t\tcurrentCanvasInUrl.current = canvasInUrl;\n\t\tif ( canvasInUrl !== currentCanvasMode.current ) {\n\t\t\tsetCanvasMode( canvasInUrl );\n\t\t}\n\t}, [ canvasInUrl ] );\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/edit-site/src/components/sync-state-with-url/use-sync-canvas-mode-with-url.js"],"names":["useSyncCanvasModeWithURL","history","params","canvasMode","select","editSiteStore","getCanvasMode","setCanvasMode","currentCanvasMode","canvas","canvasInUrl","currentCanvasInUrl","currentUrlParams","current","push","undefined"],"mappings":";;;;;;;AAGA;;AACA;;AAKA;;AACA;;AACA;;AAXA;AACA;AACA;;AAIA;AACA;AACA;AAKe,SAASA,wBAAT,GAAoC;AAClD,QAAMC,OAAO,GAAG,yBAAhB;AACA,QAAM;AAAEC,IAAAA;AAAF,MAAa,0BAAnB;AACA,QAAMC,UAAU,GAAG,qBAChBC,MAAF,IAAc,yBAAQA,MAAM,CAAEC,YAAF,CAAd,EAAkCC,aAAlC,EADI,EAElB,EAFkB,CAAnB;AAIA,QAAM;AAAEC,IAAAA;AAAF,MAAoB,yBAAQ,uBAAaF,YAAb,CAAR,CAA1B;AACA,QAAMG,iBAAiB,GAAG,qBAAQL,UAAR,CAA1B;AACA,QAAM;AAAEM,IAAAA,MAAM,EAAEC;AAAV,MAA0BR,MAAhC;AACA,QAAMS,kBAAkB,GAAG,qBAAQD,WAAR,CAA3B;AACA,QAAME,gBAAgB,GAAG,qBAAQV,MAAR,CAAzB;AACA,0BAAW,MAAM;AAChBU,IAAAA,gBAAgB,CAACC,OAAjB,GAA2BX,MAA3B;AACA,GAFD,EAEG,CAAEA,MAAF,CAFH;AAIA,0BAAW,MAAM;AAChBM,IAAAA,iBAAiB,CAACK,OAAlB,GAA4BV,UAA5B;;AACA,QAAKA,UAAU,KAAK,MAApB,EAA6B;AAC5B;AACA;;AAED,QACCA,UAAU,KAAK,MAAf,IACAQ,kBAAkB,CAACE,OAAnB,KAA+BV,UAFhC,EAGE;AACDF,MAAAA,OAAO,CAACa,IAAR,CAAc,EACb,GAAGF,gBAAgB,CAACC,OADP;AAEbJ,QAAAA,MAAM,EAAE;AAFK,OAAd;AAIA;;AAED,QACCN,UAAU,KAAK,MAAf,IACAQ,kBAAkB,CAACE,OAAnB,KAA+BE,SAFhC,EAGE;AACDd,MAAAA,OAAO,CAACa,IAAR,CAAc,EACb,GAAGF,gBAAgB,CAACC,OADP;AAEbJ,QAAAA,MAAM,EAAEM;AAFK,OAAd;AAIA;AACD,GAzBD,EAyBG,CAAEZ,UAAF,EAAcF,OAAd,CAzBH;AA2BA,0BAAW,MAAM;AAChBU,IAAAA,kBAAkB,CAACE,OAAnB,GAA6BH,WAA7B;;AACA,QACCA,WAAW,KAAKK,SAAhB,IACAP,iBAAiB,CAACK,OAAlB,KAA8B,MAF/B,EAGE;AACDN,MAAAA,aAAa,CAAE,MAAF,CAAb;AACA,KALD,MAKO,IACNG,WAAW,KAAK,MAAhB,IACAF,iBAAiB,CAACK,OAAlB,KAA8B,MAFxB,EAGL;AACDN,MAAAA,aAAa,CAAE,MAAF,CAAb;AACA;AACD,GAbD,EAaG,CAAEG,WAAF,EAAeH,aAAf,CAbH;AAcA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useEffect, useRef } from '@wordpress/element';\nimport { useSelect, useDispatch } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { store as editSiteStore } from '../../store';\nimport { useLocation, useHistory } from '../routes';\nimport { unlock } from '../../private-apis';\n\nexport default function useSyncCanvasModeWithURL() {\n\tconst history = useHistory();\n\tconst { params } = useLocation();\n\tconst canvasMode = useSelect(\n\t\t( select ) => unlock( select( editSiteStore ) ).getCanvasMode(),\n\t\t[]\n\t);\n\tconst { setCanvasMode } = unlock( useDispatch( editSiteStore ) );\n\tconst currentCanvasMode = useRef( canvasMode );\n\tconst { canvas: canvasInUrl } = params;\n\tconst currentCanvasInUrl = useRef( canvasInUrl );\n\tconst currentUrlParams = useRef( params );\n\tuseEffect( () => {\n\t\tcurrentUrlParams.current = params;\n\t}, [ params ] );\n\n\tuseEffect( () => {\n\t\tcurrentCanvasMode.current = canvasMode;\n\t\tif ( canvasMode === 'init' ) {\n\t\t\treturn;\n\t\t}\n\n\t\tif (\n\t\t\tcanvasMode === 'edit' &&\n\t\t\tcurrentCanvasInUrl.current !== canvasMode\n\t\t) {\n\t\t\thistory.push( {\n\t\t\t\t...currentUrlParams.current,\n\t\t\t\tcanvas: 'edit',\n\t\t\t} );\n\t\t}\n\n\t\tif (\n\t\t\tcanvasMode === 'view' &&\n\t\t\tcurrentCanvasInUrl.current !== undefined\n\t\t) {\n\t\t\thistory.push( {\n\t\t\t\t...currentUrlParams.current,\n\t\t\t\tcanvas: undefined,\n\t\t\t} );\n\t\t}\n\t}, [ canvasMode, history ] );\n\n\tuseEffect( () => {\n\t\tcurrentCanvasInUrl.current = canvasInUrl;\n\t\tif (\n\t\t\tcanvasInUrl === undefined &&\n\t\t\tcurrentCanvasMode.current !== 'view'\n\t\t) {\n\t\t\tsetCanvasMode( 'view' );\n\t\t} else if (\n\t\t\tcanvasInUrl === 'edit' &&\n\t\t\tcurrentCanvasMode.current !== 'edit'\n\t\t) {\n\t\t\tsetCanvasMode( 'edit' );\n\t\t}\n\t}, [ canvasInUrl, setCanvasMode ] );\n}\n"]}
@@ -51,7 +51,15 @@ function useSyncPathWithURL() {
51
51
  } = (0, _components.__experimentalUseNavigator)();
52
52
  const currentUrlParams = (0, _element.useRef)(urlParams);
53
53
  const currentPath = (0, _element.useRef)(navigatorLocation.path);
54
+ const isMounting = (0, _element.useRef)(true);
54
55
  (0, _element.useEffect)(() => {
56
+ // The navigatorParams are only initially filled properly when the
57
+ // navigator screens mount. so we ignore the first synchronisation.
58
+ if (isMounting.current) {
59
+ isMounting.current = false;
60
+ return;
61
+ }
62
+
55
63
  function updateUrlParams(newUrlParams) {
56
64
  if (Object.entries(newUrlParams).every(_ref => {
57
65
  let [key, value] = _ref;
@@ -73,17 +81,11 @@ function useSyncPathWithURL() {
73
81
  postId: navigatorParams === null || navigatorParams === void 0 ? void 0 : navigatorParams.postId,
74
82
  path: undefined
75
83
  });
76
- } else if (navigatorParams !== null && navigatorParams !== void 0 && navigatorParams.postType && !(navigatorParams !== null && navigatorParams !== void 0 && navigatorParams.postId)) {
77
- updateUrlParams({
78
- postType: navigatorParams === null || navigatorParams === void 0 ? void 0 : navigatorParams.postType,
79
- path: navigatorLocation.path,
80
- postId: undefined
81
- });
82
84
  } else {
83
85
  updateUrlParams({
84
86
  postType: undefined,
85
87
  postId: undefined,
86
- path: navigatorLocation.path
88
+ path: navigatorLocation.path === '/' ? undefined : navigatorLocation.path
87
89
  });
88
90
  }
89
91
  }, [navigatorLocation === null || navigatorLocation === void 0 ? void 0 : navigatorLocation.path, navigatorParams, history]);