@wordpress/edit-site 6.12.0 → 6.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (222) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/build/components/add-new-template/utils.js +1 -2
  3. package/build/components/add-new-template/utils.js.map +1 -1
  4. package/build/components/app/index.js +0 -3
  5. package/build/components/app/index.js.map +1 -1
  6. package/build/components/block-editor/use-site-editor-settings.js +4 -12
  7. package/build/components/block-editor/use-site-editor-settings.js.map +1 -1
  8. package/build/components/editor/index.js +18 -27
  9. package/build/components/editor/index.js.map +1 -1
  10. package/build/components/editor/use-editor-title.js +13 -5
  11. package/build/components/editor/use-editor-title.js.map +1 -1
  12. package/build/components/editor/use-resolve-edited-entity.js +133 -0
  13. package/build/components/editor/use-resolve-edited-entity.js.map +1 -0
  14. package/build/components/editor-canvas-container/index.js +1 -1
  15. package/build/components/editor-canvas-container/index.js.map +1 -1
  16. package/build/components/global-styles/block-preview-panel.js +8 -10
  17. package/build/components/global-styles/block-preview-panel.js.map +1 -1
  18. package/build/components/global-styles/screen-block.js +18 -5
  19. package/build/components/global-styles/screen-block.js.map +1 -1
  20. package/build/components/global-styles/screen-style-variations.js +11 -5
  21. package/build/components/global-styles/screen-style-variations.js.map +1 -1
  22. package/build/components/global-styles/ui.js.map +1 -1
  23. package/build/components/global-styles-sidebar/index.js +17 -1
  24. package/build/components/global-styles-sidebar/index.js.map +1 -1
  25. package/build/components/page-patterns/header.js +2 -2
  26. package/build/components/page-patterns/header.js.map +1 -1
  27. package/build/components/page-patterns/use-patterns.js +4 -8
  28. package/build/components/page-patterns/use-patterns.js.map +1 -1
  29. package/build/components/post-edit/index.js +10 -12
  30. package/build/components/post-edit/index.js.map +1 -1
  31. package/build/components/post-list/index.js +3 -3
  32. package/build/components/post-list/index.js.map +1 -1
  33. package/build/components/posts-app/index.js +3 -4
  34. package/build/components/posts-app/index.js.map +1 -1
  35. package/build/components/posts-app-routes/home.js +48 -0
  36. package/build/components/posts-app-routes/home.js.map +1 -0
  37. package/build/components/posts-app-routes/index.js +37 -0
  38. package/build/components/posts-app-routes/index.js.map +1 -0
  39. package/build/components/posts-app-routes/posts-edit.js +44 -0
  40. package/build/components/posts-app-routes/posts-edit.js.map +1 -0
  41. package/build/components/posts-app-routes/posts-list-view-quick-edit.js +63 -0
  42. package/build/components/posts-app-routes/posts-list-view-quick-edit.js.map +1 -0
  43. package/build/components/posts-app-routes/posts-list-view.js +48 -0
  44. package/build/components/posts-app-routes/posts-list-view.js.map +1 -0
  45. package/build/components/posts-app-routes/posts-view-quick-edit.js +60 -0
  46. package/build/components/posts-app-routes/posts-view-quick-edit.js.map +1 -0
  47. package/build/components/posts-app-routes/posts-view.js +41 -0
  48. package/build/components/posts-app-routes/posts-view.js.map +1 -0
  49. package/build/components/sidebar-navigation-screen-details-footer/index.js +17 -23
  50. package/build/components/sidebar-navigation-screen-details-footer/index.js.map +1 -1
  51. package/build/components/sidebar-navigation-screen-global-styles/index.js +4 -18
  52. package/build/components/sidebar-navigation-screen-global-styles/index.js.map +1 -1
  53. package/build/components/sidebar-navigation-screen-patterns/use-pattern-categories.js +1 -1
  54. package/build/components/sidebar-navigation-screen-patterns/use-pattern-categories.js.map +1 -1
  55. package/build/components/sidebar-navigation-screen-patterns/use-template-part-areas.js +2 -3
  56. package/build/components/sidebar-navigation-screen-patterns/use-template-part-areas.js.map +1 -1
  57. package/build/components/site-editor-routes/index.js +1 -2
  58. package/build/components/site-editor-routes/index.js.map +1 -1
  59. package/build/components/style-book/examples.js +24 -2
  60. package/build/components/style-book/examples.js.map +1 -1
  61. package/build/index.js +0 -9
  62. package/build/index.js.map +1 -1
  63. package/build/store/actions.js +13 -0
  64. package/build/store/actions.js.map +1 -1
  65. package/build/store/selectors.js +21 -1
  66. package/build/store/selectors.js.map +1 -1
  67. package/build-module/components/add-new-template/utils.js +1 -2
  68. package/build-module/components/add-new-template/utils.js.map +1 -1
  69. package/build-module/components/app/index.js +0 -3
  70. package/build-module/components/app/index.js.map +1 -1
  71. package/build-module/components/block-editor/use-site-editor-settings.js +4 -12
  72. package/build-module/components/block-editor/use-site-editor-settings.js.map +1 -1
  73. package/build-module/components/editor/index.js +18 -27
  74. package/build-module/components/editor/index.js.map +1 -1
  75. package/build-module/components/editor/use-editor-title.js +13 -5
  76. package/build-module/components/editor/use-editor-title.js.map +1 -1
  77. package/build-module/components/editor/use-resolve-edited-entity.js +125 -0
  78. package/build-module/components/editor/use-resolve-edited-entity.js.map +1 -0
  79. package/build-module/components/editor-canvas-container/index.js +1 -1
  80. package/build-module/components/editor-canvas-container/index.js.map +1 -1
  81. package/build-module/components/global-styles/block-preview-panel.js +8 -10
  82. package/build-module/components/global-styles/block-preview-panel.js.map +1 -1
  83. package/build-module/components/global-styles/screen-block.js +18 -5
  84. package/build-module/components/global-styles/screen-block.js.map +1 -1
  85. package/build-module/components/global-styles/screen-style-variations.js +11 -5
  86. package/build-module/components/global-styles/screen-style-variations.js.map +1 -1
  87. package/build-module/components/global-styles/ui.js +1 -1
  88. package/build-module/components/global-styles/ui.js.map +1 -1
  89. package/build-module/components/global-styles-sidebar/index.js +18 -2
  90. package/build-module/components/global-styles-sidebar/index.js.map +1 -1
  91. package/build-module/components/page-patterns/header.js +2 -2
  92. package/build-module/components/page-patterns/header.js.map +1 -1
  93. package/build-module/components/page-patterns/use-patterns.js +4 -8
  94. package/build-module/components/page-patterns/use-patterns.js.map +1 -1
  95. package/build-module/components/post-edit/index.js +9 -11
  96. package/build-module/components/post-edit/index.js.map +1 -1
  97. package/build-module/components/post-list/index.js +2 -2
  98. package/build-module/components/post-list/index.js.map +1 -1
  99. package/build-module/components/posts-app/index.js +3 -4
  100. package/build-module/components/posts-app/index.js.map +1 -1
  101. package/build-module/components/posts-app-routes/home.js +40 -0
  102. package/build-module/components/posts-app-routes/home.js.map +1 -0
  103. package/build-module/components/posts-app-routes/index.js +30 -0
  104. package/build-module/components/posts-app-routes/index.js.map +1 -0
  105. package/build-module/components/posts-app-routes/posts-edit.js +36 -0
  106. package/build-module/components/posts-app-routes/posts-edit.js.map +1 -0
  107. package/build-module/components/posts-app-routes/posts-list-view-quick-edit.js +55 -0
  108. package/build-module/components/posts-app-routes/posts-list-view-quick-edit.js.map +1 -0
  109. package/build-module/components/posts-app-routes/posts-list-view.js +40 -0
  110. package/build-module/components/posts-app-routes/posts-list-view.js.map +1 -0
  111. package/build-module/components/posts-app-routes/posts-view-quick-edit.js +52 -0
  112. package/build-module/components/posts-app-routes/posts-view-quick-edit.js.map +1 -0
  113. package/build-module/components/posts-app-routes/posts-view.js +33 -0
  114. package/build-module/components/posts-app-routes/posts-view.js.map +1 -0
  115. package/build-module/components/sidebar-navigation-screen-details-footer/index.js +20 -26
  116. package/build-module/components/sidebar-navigation-screen-details-footer/index.js.map +1 -1
  117. package/build-module/components/sidebar-navigation-screen-global-styles/index.js +4 -18
  118. package/build-module/components/sidebar-navigation-screen-global-styles/index.js.map +1 -1
  119. package/build-module/components/sidebar-navigation-screen-patterns/use-pattern-categories.js +1 -1
  120. package/build-module/components/sidebar-navigation-screen-patterns/use-pattern-categories.js.map +1 -1
  121. package/build-module/components/sidebar-navigation-screen-patterns/use-template-part-areas.js +3 -4
  122. package/build-module/components/sidebar-navigation-screen-patterns/use-template-part-areas.js.map +1 -1
  123. package/build-module/components/site-editor-routes/index.js +1 -2
  124. package/build-module/components/site-editor-routes/index.js.map +1 -1
  125. package/build-module/components/style-book/examples.js +24 -2
  126. package/build-module/components/style-book/examples.js.map +1 -1
  127. package/build-module/index.js +1 -10
  128. package/build-module/index.js.map +1 -1
  129. package/build-module/store/actions.js +13 -0
  130. package/build-module/store/actions.js.map +1 -1
  131. package/build-module/store/selectors.js +21 -1
  132. package/build-module/store/selectors.js.map +1 -1
  133. package/build-style/posts-rtl.css +59 -18
  134. package/build-style/posts.css +59 -18
  135. package/build-style/style-rtl.css +74 -57
  136. package/build-style/style.css +74 -57
  137. package/package.json +2 -2
  138. package/src/components/add-new-template/utils.js +2 -2
  139. package/src/components/app/index.js +0 -3
  140. package/src/components/block-editor/use-site-editor-settings.js +7 -21
  141. package/src/components/editor/index.js +22 -33
  142. package/src/components/editor/use-editor-title.js +17 -4
  143. package/src/components/editor/use-resolve-edited-entity.js +132 -0
  144. package/src/components/editor-canvas-container/index.js +1 -1
  145. package/src/components/global-styles/block-preview-panel.js +10 -10
  146. package/src/components/global-styles/screen-block.js +26 -8
  147. package/src/components/global-styles/screen-style-variations.js +14 -5
  148. package/src/components/global-styles/ui.js +1 -1
  149. package/src/components/global-styles-sidebar/index.js +16 -2
  150. package/src/components/page-patterns/header.js +3 -2
  151. package/src/components/page-patterns/use-patterns.js +9 -7
  152. package/src/components/page-templates/style.scss +1 -0
  153. package/src/components/post-edit/index.js +10 -13
  154. package/src/components/post-list/index.js +1 -2
  155. package/src/components/posts-app/index.js +3 -4
  156. package/src/components/posts-app-routes/home.js +36 -0
  157. package/src/components/posts-app-routes/index.js +36 -0
  158. package/src/components/posts-app-routes/posts-edit.js +31 -0
  159. package/src/components/posts-app-routes/posts-list-view-quick-edit.js +52 -0
  160. package/src/components/posts-app-routes/posts-list-view.js +40 -0
  161. package/src/components/posts-app-routes/posts-view-quick-edit.js +49 -0
  162. package/src/components/posts-app-routes/posts-view.js +35 -0
  163. package/src/components/sidebar-navigation-screen/style.scss +7 -2
  164. package/src/components/sidebar-navigation-screen-details-footer/index.js +27 -38
  165. package/src/components/sidebar-navigation-screen-details-footer/style.scss +0 -4
  166. package/src/components/sidebar-navigation-screen-global-styles/index.js +8 -17
  167. package/src/components/sidebar-navigation-screen-navigation-menus/style.scss +8 -0
  168. package/src/components/sidebar-navigation-screen-patterns/use-pattern-categories.js +1 -1
  169. package/src/components/sidebar-navigation-screen-patterns/use-template-part-areas.js +4 -4
  170. package/src/components/site-editor-routes/README.md +2 -2
  171. package/src/components/site-editor-routes/index.js +0 -2
  172. package/src/components/site-hub/style.scss +1 -1
  173. package/src/components/style-book/examples.tsx +24 -2
  174. package/src/index.js +1 -13
  175. package/src/store/actions.js +15 -0
  176. package/src/store/selectors.js +24 -1
  177. package/src/style.scss +0 -2
  178. package/build/components/post-fields/index.js +0 -96
  179. package/build/components/post-fields/index.js.map +0 -1
  180. package/build/components/posts-app/router.js +0 -85
  181. package/build/components/posts-app/router.js.map +0 -1
  182. package/build/components/sidebar-navigation-screen-details-panel/index.js +0 -54
  183. package/build/components/sidebar-navigation-screen-details-panel/index.js.map +0 -1
  184. package/build/components/sidebar-navigation-screen-details-panel/sidebar-navigation-screen-details-panel-label.js +0 -21
  185. package/build/components/sidebar-navigation-screen-details-panel/sidebar-navigation-screen-details-panel-label.js.map +0 -1
  186. package/build/components/sidebar-navigation-screen-details-panel/sidebar-navigation-screen-details-panel-row.js +0 -33
  187. package/build/components/sidebar-navigation-screen-details-panel/sidebar-navigation-screen-details-panel-row.js.map +0 -1
  188. package/build/components/sidebar-navigation-screen-details-panel/sidebar-navigation-screen-details-panel-value.js +0 -21
  189. package/build/components/sidebar-navigation-screen-details-panel/sidebar-navigation-screen-details-panel-value.js.map +0 -1
  190. package/build/components/site-editor-routes/styles-edit.js +0 -33
  191. package/build/components/site-editor-routes/styles-edit.js.map +0 -1
  192. package/build/components/sync-state-with-url/use-init-edited-entity-from-url.js +0 -219
  193. package/build/components/sync-state-with-url/use-init-edited-entity-from-url.js.map +0 -1
  194. package/build-module/components/post-fields/index.js +0 -88
  195. package/build-module/components/post-fields/index.js.map +0 -1
  196. package/build-module/components/posts-app/router.js +0 -77
  197. package/build-module/components/posts-app/router.js.map +0 -1
  198. package/build-module/components/sidebar-navigation-screen-details-panel/index.js +0 -29
  199. package/build-module/components/sidebar-navigation-screen-details-panel/index.js.map +0 -1
  200. package/build-module/components/sidebar-navigation-screen-details-panel/sidebar-navigation-screen-details-panel-label.js +0 -14
  201. package/build-module/components/sidebar-navigation-screen-details-panel/sidebar-navigation-screen-details-panel-label.js.map +0 -1
  202. package/build-module/components/sidebar-navigation-screen-details-panel/sidebar-navigation-screen-details-panel-row.js +0 -25
  203. package/build-module/components/sidebar-navigation-screen-details-panel/sidebar-navigation-screen-details-panel-row.js.map +0 -1
  204. package/build-module/components/sidebar-navigation-screen-details-panel/sidebar-navigation-screen-details-panel-value.js +0 -14
  205. package/build-module/components/sidebar-navigation-screen-details-panel/sidebar-navigation-screen-details-panel-value.js.map +0 -1
  206. package/build-module/components/site-editor-routes/styles-edit.js +0 -25
  207. package/build-module/components/site-editor-routes/styles-edit.js.map +0 -1
  208. package/build-module/components/sync-state-with-url/use-init-edited-entity-from-url.js +0 -212
  209. package/build-module/components/sync-state-with-url/use-init-edited-entity-from-url.js.map +0 -1
  210. package/src/components/post-fields/index.js +0 -107
  211. package/src/components/post-fields/style.scss +0 -3
  212. package/src/components/posts-app/router.js +0 -69
  213. package/src/components/sidebar-navigation-screen-details-panel/index.js +0 -40
  214. package/src/components/sidebar-navigation-screen-details-panel/sidebar-navigation-screen-details-panel-label.js +0 -14
  215. package/src/components/sidebar-navigation-screen-details-panel/sidebar-navigation-screen-details-panel-row.js +0 -31
  216. package/src/components/sidebar-navigation-screen-details-panel/sidebar-navigation-screen-details-panel-value.js +0 -14
  217. package/src/components/sidebar-navigation-screen-details-panel/style.scss +0 -26
  218. package/src/components/site-editor-routes/styles-edit.js +0 -26
  219. package/src/components/sync-state-with-url/use-init-edited-entity-from-url.js +0 -257
  220. package/src/store/test/actions.js +0 -83
  221. package/src/store/test/reducer.js +0 -69
  222. package/src/store/test/selectors.js +0 -41
@@ -1,212 +0,0 @@
1
- /**
2
- * WordPress dependencies
3
- */
4
- import { useEffect, useMemo } from '@wordpress/element';
5
- import { useSelect, useDispatch } from '@wordpress/data';
6
- import { store as coreDataStore } from '@wordpress/core-data';
7
- import { privateApis as routerPrivateApis } from '@wordpress/router';
8
- import { store as blockEditorStore } from '@wordpress/block-editor';
9
-
10
- /**
11
- * Internal dependencies
12
- */
13
- import { store as editSiteStore } from '../../store';
14
- import { unlock } from '../../lock-unlock';
15
- import { TEMPLATE_POST_TYPE, TEMPLATE_PART_POST_TYPE, NAVIGATION_POST_TYPE, PATTERN_TYPES } from '../../utils/constants';
16
- const {
17
- useLocation
18
- } = unlock(routerPrivateApis);
19
- const postTypesWithoutParentTemplate = [TEMPLATE_POST_TYPE, TEMPLATE_PART_POST_TYPE, NAVIGATION_POST_TYPE, PATTERN_TYPES.user];
20
- const authorizedPostTypes = ['page', 'post'];
21
- function useResolveEditedEntityAndContext({
22
- postId,
23
- postType
24
- }) {
25
- const {
26
- hasLoadedAllDependencies,
27
- homepageId,
28
- postsPageId
29
- } = useSelect(select => {
30
- const {
31
- getEntityRecord
32
- } = select(coreDataStore);
33
- const siteData = getEntityRecord('root', 'site');
34
- const _homepageId = siteData?.show_on_front === 'page' && ['number', 'string'].includes(typeof siteData.page_on_front) && !!+siteData.page_on_front // We also need to check if it's not zero(`0`).
35
- ? siteData.page_on_front.toString() : null;
36
- const _postsPageId = siteData?.show_on_front === 'page' && ['number', 'string'].includes(typeof siteData.page_for_posts) ? siteData.page_for_posts.toString() : null;
37
- return {
38
- hasLoadedAllDependencies: !!siteData,
39
- homepageId: _homepageId,
40
- postsPageId: _postsPageId
41
- };
42
- }, []);
43
-
44
- /**
45
- * This is a hook that recreates the logic to resolve a template for a given WordPress postID postTypeId
46
- * in order to match the frontend as closely as possible in the site editor.
47
- *
48
- * It is not possible to rely on the server logic because there maybe unsaved changes that impact the template resolution.
49
- */
50
- const resolvedTemplateId = useSelect(select => {
51
- // If we're rendering a post type that doesn't have a template
52
- // no need to resolve its template.
53
- if (postTypesWithoutParentTemplate.includes(postType) && postId) {
54
- return undefined;
55
- }
56
-
57
- // Don't trigger resolution for multi-selected posts.
58
- if (postId && postId.includes(',')) {
59
- return undefined;
60
- }
61
- const {
62
- getEditedEntityRecord,
63
- getEntityRecords,
64
- getDefaultTemplateId
65
- } = select(coreDataStore);
66
- function resolveTemplateForPostTypeAndId(postTypeToResolve, postIdToResolve) {
67
- // For the front page, we always use the front page template if existing.
68
- if (postTypeToResolve === 'page' && homepageId === postIdToResolve) {
69
- // The /lookup endpoint cannot currently handle a lookup
70
- // when a page is set as the front page, so specifically in
71
- // that case, we want to check if there is a front page
72
- // template, and instead of falling back to the home
73
- // template, we want to fall back to the page template.
74
- const templates = getEntityRecords('postType', TEMPLATE_POST_TYPE, {
75
- per_page: -1
76
- });
77
- if (templates) {
78
- const id = templates?.find(({
79
- slug
80
- }) => slug === 'front-page')?.id;
81
- if (id) {
82
- return id;
83
- }
84
-
85
- // If no front page template is found, continue with the
86
- // logic below (fetching the page template).
87
- } else {
88
- // Still resolving `templates`.
89
- return undefined;
90
- }
91
- }
92
- const editedEntity = getEditedEntityRecord('postType', postTypeToResolve, postIdToResolve);
93
- if (!editedEntity) {
94
- return undefined;
95
- }
96
- // Check if the current page is the posts page.
97
- if (postTypeToResolve === 'page' && postsPageId === postIdToResolve) {
98
- return getDefaultTemplateId({
99
- slug: 'home'
100
- });
101
- }
102
- // First see if the post/page has an assigned template and fetch it.
103
- const currentTemplateSlug = editedEntity.template;
104
- if (currentTemplateSlug) {
105
- const currentTemplate = getEntityRecords('postType', TEMPLATE_POST_TYPE, {
106
- per_page: -1
107
- })?.find(({
108
- slug
109
- }) => slug === currentTemplateSlug);
110
- if (currentTemplate) {
111
- return currentTemplate.id;
112
- }
113
- }
114
- // If no template is assigned, use the default template.
115
- let slugToCheck;
116
- // In `draft` status we might not have a slug available, so we use the `single`
117
- // post type templates slug(ex page, single-post, single-product etc..).
118
- // Pages do not need the `single` prefix in the slug to be prioritized
119
- // through template hierarchy.
120
- if (editedEntity.slug) {
121
- slugToCheck = postTypeToResolve === 'page' ? `${postTypeToResolve}-${editedEntity.slug}` : `single-${postTypeToResolve}-${editedEntity.slug}`;
122
- } else {
123
- slugToCheck = postTypeToResolve === 'page' ? 'page' : `single-${postTypeToResolve}`;
124
- }
125
- return getDefaultTemplateId({
126
- slug: slugToCheck
127
- });
128
- }
129
- if (!hasLoadedAllDependencies) {
130
- return undefined;
131
- }
132
-
133
- // If we're rendering a specific page, we need to resolve its template.
134
- // The site editor only supports pages for now, not other CPTs.
135
- if (postType && postId && authorizedPostTypes.includes(postType)) {
136
- return resolveTemplateForPostTypeAndId(postType, postId);
137
- }
138
-
139
- // If we're rendering the home page, and we have a static home page, resolve its template.
140
- if (homepageId) {
141
- return resolveTemplateForPostTypeAndId('page', homepageId);
142
- }
143
-
144
- // If we're not rendering a specific page, use the front page template.
145
- return getDefaultTemplateId({
146
- slug: 'front-page'
147
- });
148
- }, [homepageId, postsPageId, hasLoadedAllDependencies, postId, postType]);
149
- const context = useMemo(() => {
150
- if (postTypesWithoutParentTemplate.includes(postType) && postId) {
151
- return {};
152
- }
153
- if (postType && postId && authorizedPostTypes.includes(postType)) {
154
- return {
155
- postType,
156
- postId
157
- };
158
- }
159
- // TODO: for post types lists we should probably not render the front page, but maybe a placeholder
160
- // with a message like "Select a page" or something similar.
161
- if (homepageId) {
162
- return {
163
- postType: 'page',
164
- postId: homepageId
165
- };
166
- }
167
- return {};
168
- }, [homepageId, postType, postId]);
169
- if (postTypesWithoutParentTemplate.includes(postType) && postId) {
170
- return {
171
- isReady: true,
172
- postType,
173
- postId,
174
- context
175
- };
176
- }
177
- if (hasLoadedAllDependencies) {
178
- return {
179
- isReady: resolvedTemplateId !== undefined,
180
- postType: TEMPLATE_POST_TYPE,
181
- postId: resolvedTemplateId,
182
- context
183
- };
184
- }
185
- return {
186
- isReady: false
187
- };
188
- }
189
- export default function useInitEditedEntityFromURL() {
190
- const {
191
- params = {}
192
- } = useLocation();
193
- const {
194
- postType,
195
- postId,
196
- context,
197
- isReady
198
- } = useResolveEditedEntityAndContext(params);
199
- const {
200
- setEditedEntity
201
- } = useDispatch(editSiteStore);
202
- const {
203
- resetZoomLevel
204
- } = unlock(useDispatch(blockEditorStore));
205
- useEffect(() => {
206
- if (isReady) {
207
- resetZoomLevel();
208
- setEditedEntity(postType, postId, context);
209
- }
210
- }, [isReady, postType, postId, context, setEditedEntity, resetZoomLevel]);
211
- }
212
- //# sourceMappingURL=use-init-edited-entity-from-url.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["useEffect","useMemo","useSelect","useDispatch","store","coreDataStore","privateApis","routerPrivateApis","blockEditorStore","editSiteStore","unlock","TEMPLATE_POST_TYPE","TEMPLATE_PART_POST_TYPE","NAVIGATION_POST_TYPE","PATTERN_TYPES","useLocation","postTypesWithoutParentTemplate","user","authorizedPostTypes","useResolveEditedEntityAndContext","postId","postType","hasLoadedAllDependencies","homepageId","postsPageId","select","getEntityRecord","siteData","_homepageId","show_on_front","includes","page_on_front","toString","_postsPageId","page_for_posts","resolvedTemplateId","undefined","getEditedEntityRecord","getEntityRecords","getDefaultTemplateId","resolveTemplateForPostTypeAndId","postTypeToResolve","postIdToResolve","templates","per_page","id","find","slug","editedEntity","currentTemplateSlug","template","currentTemplate","slugToCheck","context","isReady","useInitEditedEntityFromURL","params","setEditedEntity","resetZoomLevel"],"sources":["@wordpress/edit-site/src/components/sync-state-with-url/use-init-edited-entity-from-url.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useEffect, useMemo } from '@wordpress/element';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { store as coreDataStore } from '@wordpress/core-data';\nimport { privateApis as routerPrivateApis } from '@wordpress/router';\nimport { store as blockEditorStore } from '@wordpress/block-editor';\n\n/**\n * Internal dependencies\n */\nimport { store as editSiteStore } from '../../store';\nimport { unlock } from '../../lock-unlock';\nimport {\n\tTEMPLATE_POST_TYPE,\n\tTEMPLATE_PART_POST_TYPE,\n\tNAVIGATION_POST_TYPE,\n\tPATTERN_TYPES,\n} from '../../utils/constants';\n\nconst { useLocation } = unlock( routerPrivateApis );\n\nconst postTypesWithoutParentTemplate = [\n\tTEMPLATE_POST_TYPE,\n\tTEMPLATE_PART_POST_TYPE,\n\tNAVIGATION_POST_TYPE,\n\tPATTERN_TYPES.user,\n];\n\nconst authorizedPostTypes = [ 'page', 'post' ];\n\nfunction useResolveEditedEntityAndContext( { postId, postType } ) {\n\tconst { hasLoadedAllDependencies, homepageId, postsPageId } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getEntityRecord } = select( coreDataStore );\n\t\t\tconst siteData = getEntityRecord( 'root', 'site' );\n\t\t\tconst _homepageId =\n\t\t\t\tsiteData?.show_on_front === 'page' &&\n\t\t\t\t[ 'number', 'string' ].includes(\n\t\t\t\t\ttypeof siteData.page_on_front\n\t\t\t\t) &&\n\t\t\t\t!! +siteData.page_on_front // We also need to check if it's not zero(`0`).\n\t\t\t\t\t? siteData.page_on_front.toString()\n\t\t\t\t\t: null;\n\t\t\tconst _postsPageId =\n\t\t\t\tsiteData?.show_on_front === 'page' &&\n\t\t\t\t[ 'number', 'string' ].includes(\n\t\t\t\t\ttypeof siteData.page_for_posts\n\t\t\t\t)\n\t\t\t\t\t? siteData.page_for_posts.toString()\n\t\t\t\t\t: null;\n\t\t\treturn {\n\t\t\t\thasLoadedAllDependencies: !! siteData,\n\t\t\t\thomepageId: _homepageId,\n\t\t\t\tpostsPageId: _postsPageId,\n\t\t\t};\n\t\t},\n\t\t[]\n\t);\n\n\t/**\n\t * This is a hook that recreates the logic to resolve a template for a given WordPress postID postTypeId\n\t * in order to match the frontend as closely as possible in the site editor.\n\t *\n\t * It is not possible to rely on the server logic because there maybe unsaved changes that impact the template resolution.\n\t */\n\tconst resolvedTemplateId = useSelect(\n\t\t( select ) => {\n\t\t\t// If we're rendering a post type that doesn't have a template\n\t\t\t// no need to resolve its template.\n\t\t\tif (\n\t\t\t\tpostTypesWithoutParentTemplate.includes( postType ) &&\n\t\t\t\tpostId\n\t\t\t) {\n\t\t\t\treturn undefined;\n\t\t\t}\n\n\t\t\t// Don't trigger resolution for multi-selected posts.\n\t\t\tif ( postId && postId.includes( ',' ) ) {\n\t\t\t\treturn undefined;\n\t\t\t}\n\n\t\t\tconst {\n\t\t\t\tgetEditedEntityRecord,\n\t\t\t\tgetEntityRecords,\n\t\t\t\tgetDefaultTemplateId,\n\t\t\t} = select( coreDataStore );\n\n\t\t\tfunction resolveTemplateForPostTypeAndId(\n\t\t\t\tpostTypeToResolve,\n\t\t\t\tpostIdToResolve\n\t\t\t) {\n\t\t\t\t// For the front page, we always use the front page template if existing.\n\t\t\t\tif (\n\t\t\t\t\tpostTypeToResolve === 'page' &&\n\t\t\t\t\thomepageId === postIdToResolve\n\t\t\t\t) {\n\t\t\t\t\t// The /lookup endpoint cannot currently handle a lookup\n\t\t\t\t\t// when a page is set as the front page, so specifically in\n\t\t\t\t\t// that case, we want to check if there is a front page\n\t\t\t\t\t// template, and instead of falling back to the home\n\t\t\t\t\t// template, we want to fall back to the page template.\n\t\t\t\t\tconst templates = getEntityRecords(\n\t\t\t\t\t\t'postType',\n\t\t\t\t\t\tTEMPLATE_POST_TYPE,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tper_page: -1,\n\t\t\t\t\t\t}\n\t\t\t\t\t);\n\t\t\t\t\tif ( templates ) {\n\t\t\t\t\t\tconst id = templates?.find(\n\t\t\t\t\t\t\t( { slug } ) => slug === 'front-page'\n\t\t\t\t\t\t)?.id;\n\t\t\t\t\t\tif ( id ) {\n\t\t\t\t\t\t\treturn id;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// If no front page template is found, continue with the\n\t\t\t\t\t\t// logic below (fetching the page template).\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// Still resolving `templates`.\n\t\t\t\t\t\treturn undefined;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tconst editedEntity = getEditedEntityRecord(\n\t\t\t\t\t'postType',\n\t\t\t\t\tpostTypeToResolve,\n\t\t\t\t\tpostIdToResolve\n\t\t\t\t);\n\t\t\t\tif ( ! editedEntity ) {\n\t\t\t\t\treturn undefined;\n\t\t\t\t}\n\t\t\t\t// Check if the current page is the posts page.\n\t\t\t\tif (\n\t\t\t\t\tpostTypeToResolve === 'page' &&\n\t\t\t\t\tpostsPageId === postIdToResolve\n\t\t\t\t) {\n\t\t\t\t\treturn getDefaultTemplateId( { slug: 'home' } );\n\t\t\t\t}\n\t\t\t\t// First see if the post/page has an assigned template and fetch it.\n\t\t\t\tconst currentTemplateSlug = editedEntity.template;\n\t\t\t\tif ( currentTemplateSlug ) {\n\t\t\t\t\tconst currentTemplate = getEntityRecords(\n\t\t\t\t\t\t'postType',\n\t\t\t\t\t\tTEMPLATE_POST_TYPE,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tper_page: -1,\n\t\t\t\t\t\t}\n\t\t\t\t\t)?.find( ( { slug } ) => slug === currentTemplateSlug );\n\t\t\t\t\tif ( currentTemplate ) {\n\t\t\t\t\t\treturn currentTemplate.id;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t// If no template is assigned, use the default template.\n\t\t\t\tlet slugToCheck;\n\t\t\t\t// In `draft` status we might not have a slug available, so we use the `single`\n\t\t\t\t// post type templates slug(ex page, single-post, single-product etc..).\n\t\t\t\t// Pages do not need the `single` prefix in the slug to be prioritized\n\t\t\t\t// through template hierarchy.\n\t\t\t\tif ( editedEntity.slug ) {\n\t\t\t\t\tslugToCheck =\n\t\t\t\t\t\tpostTypeToResolve === 'page'\n\t\t\t\t\t\t\t? `${ postTypeToResolve }-${ editedEntity.slug }`\n\t\t\t\t\t\t\t: `single-${ postTypeToResolve }-${ editedEntity.slug }`;\n\t\t\t\t} else {\n\t\t\t\t\tslugToCheck =\n\t\t\t\t\t\tpostTypeToResolve === 'page'\n\t\t\t\t\t\t\t? 'page'\n\t\t\t\t\t\t\t: `single-${ postTypeToResolve }`;\n\t\t\t\t}\n\t\t\t\treturn getDefaultTemplateId( {\n\t\t\t\t\tslug: slugToCheck,\n\t\t\t\t} );\n\t\t\t}\n\n\t\t\tif ( ! hasLoadedAllDependencies ) {\n\t\t\t\treturn undefined;\n\t\t\t}\n\n\t\t\t// If we're rendering a specific page, we need to resolve its template.\n\t\t\t// The site editor only supports pages for now, not other CPTs.\n\t\t\tif (\n\t\t\t\tpostType &&\n\t\t\t\tpostId &&\n\t\t\t\tauthorizedPostTypes.includes( postType )\n\t\t\t) {\n\t\t\t\treturn resolveTemplateForPostTypeAndId( postType, postId );\n\t\t\t}\n\n\t\t\t// If we're rendering the home page, and we have a static home page, resolve its template.\n\t\t\tif ( homepageId ) {\n\t\t\t\treturn resolveTemplateForPostTypeAndId( 'page', homepageId );\n\t\t\t}\n\n\t\t\t// If we're not rendering a specific page, use the front page template.\n\t\t\treturn getDefaultTemplateId( { slug: 'front-page' } );\n\t\t},\n\t\t[ homepageId, postsPageId, hasLoadedAllDependencies, postId, postType ]\n\t);\n\n\tconst context = useMemo( () => {\n\t\tif ( postTypesWithoutParentTemplate.includes( postType ) && postId ) {\n\t\t\treturn {};\n\t\t}\n\n\t\tif ( postType && postId && authorizedPostTypes.includes( postType ) ) {\n\t\t\treturn { postType, postId };\n\t\t}\n\t\t// TODO: for post types lists we should probably not render the front page, but maybe a placeholder\n\t\t// with a message like \"Select a page\" or something similar.\n\t\tif ( homepageId ) {\n\t\t\treturn { postType: 'page', postId: homepageId };\n\t\t}\n\n\t\treturn {};\n\t}, [ homepageId, postType, postId ] );\n\n\tif ( postTypesWithoutParentTemplate.includes( postType ) && postId ) {\n\t\treturn { isReady: true, postType, postId, context };\n\t}\n\n\tif ( hasLoadedAllDependencies ) {\n\t\treturn {\n\t\t\tisReady: resolvedTemplateId !== undefined,\n\t\t\tpostType: TEMPLATE_POST_TYPE,\n\t\t\tpostId: resolvedTemplateId,\n\t\t\tcontext,\n\t\t};\n\t}\n\n\treturn { isReady: false };\n}\n\nexport default function useInitEditedEntityFromURL() {\n\tconst { params = {} } = useLocation();\n\tconst { postType, postId, context, isReady } =\n\t\tuseResolveEditedEntityAndContext( params );\n\n\tconst { setEditedEntity } = useDispatch( editSiteStore );\n\tconst { resetZoomLevel } = unlock( useDispatch( blockEditorStore ) );\n\n\tuseEffect( () => {\n\t\tif ( isReady ) {\n\t\t\tresetZoomLevel();\n\t\t\tsetEditedEntity( postType, postId, context );\n\t\t}\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AAEC,OAAO,EAAE;EAAM,CAAC;AAC1B;AAEA,eAAe,SAASC,0BAA0BA,CAAA,EAAG;EACpD,MAAM;IAAEC,MAAM,GAAG,CAAC;EAAE,CAAC,GAAGzC,WAAW,CAAC,CAAC;EACrC,MAAM;IAAEM,QAAQ;IAAED,MAAM;IAAEiC,OAAO;IAAEC;EAAQ,CAAC,GAC3CnC,gCAAgC,CAAEqC,MAAO,CAAC;EAE3C,MAAM;IAAEC;EAAgB,CAAC,GAAGtD,WAAW,CAAEM,aAAc,CAAC;EACxD,MAAM;IAAEiD;EAAe,CAAC,GAAGhD,MAAM,CAAEP,WAAW,CAAEK,gBAAiB,CAAE,CAAC;EAEpER,SAAS,CAAE,MAAM;IAChB,IAAKsD,OAAO,EAAG;MACdI,cAAc,CAAC,CAAC;MAChBD,eAAe,CAAEpC,QAAQ,EAAED,MAAM,EAAEiC,OAAQ,CAAC;IAC7C;EACD,CAAC,EAAE,CACFC,OAAO,EACPjC,QAAQ,EACRD,MAAM,EACNiC,OAAO,EACPI,eAAe,EACfC,cAAc,CACb,CAAC;AACJ","ignoreList":[]}
@@ -1,107 +0,0 @@
1
- /**
2
- * External dependencies
3
- */
4
- import clsx from 'clsx';
5
-
6
- /**
7
- * WordPress dependencies
8
- */
9
- import { __ } from '@wordpress/i18n';
10
- import {
11
- featuredImageField,
12
- slugField,
13
- parentField,
14
- passwordField,
15
- statusField,
16
- commentStatusField,
17
- titleField,
18
- dateField,
19
- } from '@wordpress/fields';
20
- import { useMemo, useState } from '@wordpress/element';
21
- import { commentAuthorAvatar as authorIcon } from '@wordpress/icons';
22
- import { __experimentalHStack as HStack, Icon } from '@wordpress/components';
23
- import { useSelect } from '@wordpress/data';
24
- import { useEntityRecords, store as coreStore } from '@wordpress/core-data';
25
-
26
- function PostAuthorField( { item } ) {
27
- const { text, imageUrl } = useSelect(
28
- ( select ) => {
29
- const { getUser } = select( coreStore );
30
- const user = getUser( item.author );
31
- return {
32
- imageUrl: user?.avatar_urls?.[ 48 ],
33
- text: user?.name,
34
- };
35
- },
36
- [ item ]
37
- );
38
- const [ isImageLoaded, setIsImageLoaded ] = useState( false );
39
- return (
40
- <HStack alignment="left" spacing={ 0 }>
41
- { !! imageUrl && (
42
- <div
43
- className={ clsx( 'page-templates-author-field__avatar', {
44
- 'is-loaded': isImageLoaded,
45
- } ) }
46
- >
47
- <img
48
- onLoad={ () => setIsImageLoaded( true ) }
49
- alt={ __( 'Author avatar' ) }
50
- src={ imageUrl }
51
- />
52
- </div>
53
- ) }
54
- { ! imageUrl && (
55
- <div className="page-templates-author-field__icon">
56
- <Icon icon={ authorIcon } />
57
- </div>
58
- ) }
59
- <span className="page-templates-author-field__name">{ text }</span>
60
- </HStack>
61
- );
62
- }
63
-
64
- function usePostFields() {
65
- const { records: authors, isResolving: isLoadingAuthors } =
66
- useEntityRecords( 'root', 'user', { per_page: -1 } );
67
-
68
- const fields = useMemo(
69
- () => [
70
- featuredImageField,
71
- titleField,
72
- {
73
- label: __( 'Author' ),
74
- id: 'author',
75
- type: 'integer',
76
- elements:
77
- authors?.map( ( { id, name } ) => ( {
78
- value: id,
79
- label: name,
80
- } ) ) || [],
81
- render: PostAuthorField,
82
- sort: ( a, b, direction ) => {
83
- const nameA = a._embedded?.author?.[ 0 ]?.name || '';
84
- const nameB = b._embedded?.author?.[ 0 ]?.name || '';
85
-
86
- return direction === 'asc'
87
- ? nameA.localeCompare( nameB )
88
- : nameB.localeCompare( nameA );
89
- },
90
- },
91
- statusField,
92
- dateField,
93
- slugField,
94
- parentField,
95
- commentStatusField,
96
- passwordField,
97
- ],
98
- [ authors ]
99
- );
100
-
101
- return {
102
- isLoading: isLoadingAuthors,
103
- fields,
104
- };
105
- }
106
-
107
- export default usePostFields;
@@ -1,3 +0,0 @@
1
- .components-popover.components-dropdown__content.dataforms-layouts-panel__field-dropdown {
2
- z-index: z-index(".components-popover.components-dropdown__content.dataforms-layouts-panel__field-dropdown");
3
- }
@@ -1,69 +0,0 @@
1
- /**
2
- * WordPress dependencies
3
- */
4
- import { privateApis as routerPrivateApis } from '@wordpress/router';
5
- import { useSelect } from '@wordpress/data';
6
- import { store as coreStore } from '@wordpress/core-data';
7
-
8
- /**
9
- * Internal dependencies
10
- */
11
- import { unlock } from '../../lock-unlock';
12
- import Editor from '../editor';
13
- import SidebarNavigationScreen from '../sidebar-navigation-screen';
14
- import SidebarNavigationScreenMain from '../sidebar-navigation-screen-main';
15
- import DataViewsSidebarContent from '../sidebar-dataviews';
16
- import PostList from '../post-list';
17
-
18
- const { useLocation } = unlock( routerPrivateApis );
19
-
20
- export default function useActiveRoute() {
21
- const { params = {} } = useLocation();
22
- const { postType, layout, canvas } = params;
23
- const labels = useSelect(
24
- ( select ) => {
25
- return select( coreStore ).getPostType( postType )?.labels;
26
- },
27
- [ postType ]
28
- );
29
-
30
- // Posts list.
31
- if ( [ 'post' ].includes( postType ) ) {
32
- const isListLayout = layout === 'list' || ! layout;
33
- return {
34
- name: 'posts-list',
35
- areas: {
36
- sidebar: (
37
- <SidebarNavigationScreen
38
- title={ labels?.name }
39
- isRoot
40
- content={ <DataViewsSidebarContent /> }
41
- />
42
- ),
43
- content: <PostList postType={ postType } />,
44
- preview: ( isListLayout || canvas === 'edit' ) && (
45
- <Editor isPostsList />
46
- ),
47
- mobile:
48
- canvas === 'edit' ? (
49
- <Editor isPostsList />
50
- ) : (
51
- <PostList postType={ postType } />
52
- ),
53
- },
54
- widths: {
55
- content: isListLayout ? 380 : undefined,
56
- },
57
- };
58
- }
59
-
60
- // Fallback shows the home page preview
61
- return {
62
- name: 'default',
63
- areas: {
64
- sidebar: <SidebarNavigationScreenMain />,
65
- preview: <Editor isPostsList />,
66
- mobile: canvas === 'edit' && <Editor isPostsList />,
67
- },
68
- };
69
- }
@@ -1,40 +0,0 @@
1
- /**
2
- * WordPress dependencies
3
- */
4
- import {
5
- __experimentalVStack as VStack,
6
- __experimentalHeading as Heading,
7
- } from '@wordpress/components';
8
-
9
- /**
10
- * Internal dependencies
11
- */
12
- import SidebarNavigationScreenDetailsPanelLabel from './sidebar-navigation-screen-details-panel-label';
13
- import SidebarNavigationScreenDetailsPanelRow from './sidebar-navigation-screen-details-panel-row';
14
- import SidebarNavigationScreenDetailsPanelValue from './sidebar-navigation-screen-details-panel-value';
15
-
16
- function SidebarNavigationScreenDetailsPanel( { title, children, spacing } ) {
17
- return (
18
- <VStack
19
- className="edit-site-sidebar-navigation-details-screen-panel"
20
- spacing={ spacing }
21
- >
22
- { title && (
23
- <Heading
24
- className="edit-site-sidebar-navigation-details-screen-panel__heading"
25
- level={ 2 }
26
- >
27
- { title }
28
- </Heading>
29
- ) }
30
- { children }
31
- </VStack>
32
- );
33
- }
34
-
35
- export {
36
- SidebarNavigationScreenDetailsPanel,
37
- SidebarNavigationScreenDetailsPanelRow,
38
- SidebarNavigationScreenDetailsPanelLabel,
39
- SidebarNavigationScreenDetailsPanelValue,
40
- };
@@ -1,14 +0,0 @@
1
- /**
2
- * WordPress dependencies
3
- */
4
- import { __experimentalText as Text } from '@wordpress/components';
5
-
6
- export default function SidebarNavigationScreenDetailsPanelLabel( {
7
- children,
8
- } ) {
9
- return (
10
- <Text className="edit-site-sidebar-navigation-details-screen-panel__label">
11
- { children }
12
- </Text>
13
- );
14
- }
@@ -1,31 +0,0 @@
1
- /**
2
- * External dependencies
3
- */
4
- import clsx from 'clsx';
5
-
6
- /**
7
- * WordPress dependencies
8
- */
9
- import { __experimentalHStack as HStack } from '@wordpress/components';
10
-
11
- export default function SidebarNavigationScreenDetailsPanelRow( {
12
- label,
13
- children,
14
- className,
15
- ...extraProps
16
- } ) {
17
- return (
18
- <HStack
19
- key={ label }
20
- spacing={ 5 }
21
- alignment="left"
22
- className={ clsx(
23
- 'edit-site-sidebar-navigation-details-screen-panel__row',
24
- className
25
- ) }
26
- { ...extraProps }
27
- >
28
- { children }
29
- </HStack>
30
- );
31
- }
@@ -1,14 +0,0 @@
1
- /**
2
- * WordPress dependencies
3
- */
4
- import { __experimentalText as Text } from '@wordpress/components';
5
-
6
- export default function SidebarNavigationScreenDetailsPanelValue( {
7
- children,
8
- } ) {
9
- return (
10
- <Text className="edit-site-sidebar-navigation-details-screen-panel__value">
11
- { children }
12
- </Text>
13
- );
14
- }
@@ -1,26 +0,0 @@
1
- .edit-site-sidebar-navigation-details-screen-panel {
2
- margin: $grid-unit-30 0;
3
-
4
- &:last-of-type {
5
- margin-bottom: 0;
6
- }
7
-
8
- .edit-site-sidebar-navigation-details-screen-panel__heading {
9
- color: $gray-400;
10
- text-transform: uppercase;
11
- font-weight: 500;
12
- font-size: 11px;
13
- padding: 0;
14
- margin-bottom: 0;
15
- }
16
- }
17
-
18
- .edit-site-sidebar-navigation-details-screen-panel__label.edit-site-sidebar-navigation-details-screen-panel__label {
19
- color: $gray-600;
20
- width: 100px;
21
- flex-shrink: 0;
22
- }
23
-
24
- .edit-site-sidebar-navigation-details-screen-panel__value.edit-site-sidebar-navigation-details-screen-panel__value {
25
- color: $gray-200;
26
- }
@@ -1,26 +0,0 @@
1
- /**
2
- * Internal dependencies
3
- */
4
- import Editor from '../editor';
5
- import SidebarNavigationScreenGlobalStyles from '../sidebar-navigation-screen-global-styles';
6
- import GlobalStylesUIWrapper from '../sidebar-global-styles-wrapper';
7
-
8
- export const stylesEditRoute = {
9
- name: 'styles-edit',
10
- match: ( params ) => {
11
- return (
12
- params.path &&
13
- params.path.startsWith( '/wp_global_styles' ) &&
14
- params.canvas !== 'edit'
15
- );
16
- },
17
- areas: {
18
- content: <GlobalStylesUIWrapper />,
19
- sidebar: <SidebarNavigationScreenGlobalStyles backPath={ {} } />,
20
- preview: <Editor />,
21
- mobile: <Editor />,
22
- },
23
- widths: {
24
- content: 380,
25
- },
26
- };