@wordpress/edit-site 5.31.0 → 5.32.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 (280) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/build/components/block-editor/editor-canvas.js +8 -1
  3. package/build/components/block-editor/editor-canvas.js.map +1 -1
  4. package/build/components/block-editor/site-editor-canvas.js +15 -4
  5. package/build/components/block-editor/site-editor-canvas.js.map +1 -1
  6. package/build/components/editor/index.js +12 -3
  7. package/build/components/editor/index.js.map +1 -1
  8. package/build/components/editor-canvas-container/index.js +1 -2
  9. package/build/components/editor-canvas-container/index.js.map +1 -1
  10. package/build/components/global-styles/background-panel.js +38 -0
  11. package/build/components/global-styles/background-panel.js.map +1 -0
  12. package/build/components/global-styles/font-families.js +1 -1
  13. package/build/components/global-styles/font-families.js.map +1 -1
  14. package/build/components/global-styles/font-library-modal/context.js +38 -9
  15. package/build/components/global-styles/font-library-modal/context.js.map +1 -1
  16. package/build/components/global-styles/font-library-modal/utils/index.js +20 -2
  17. package/build/components/global-styles/font-library-modal/utils/index.js.map +1 -1
  18. package/build/components/global-styles/palette.js +3 -1
  19. package/build/components/global-styles/palette.js.map +1 -1
  20. package/build/components/global-styles/preview-colors.js +2 -2
  21. package/build/components/global-styles/preview-colors.js.map +1 -1
  22. package/build/components/global-styles/root-menu.js +8 -2
  23. package/build/components/global-styles/root-menu.js.map +1 -1
  24. package/build/components/global-styles/screen-background.js +34 -0
  25. package/build/components/global-styles/screen-background.js.map +1 -0
  26. package/build/components/global-styles/screen-color-palette.js +2 -2
  27. package/build/components/global-styles/screen-color-palette.js.map +1 -1
  28. package/build/components/global-styles/screen-colors.js +6 -4
  29. package/build/components/global-styles/screen-colors.js.map +1 -1
  30. package/build/components/global-styles/screen-style-variations.js +3 -37
  31. package/build/components/global-styles/screen-style-variations.js.map +1 -1
  32. package/build/components/global-styles/screen-typography.js +6 -6
  33. package/build/components/global-styles/screen-typography.js.map +1 -1
  34. package/build/components/global-styles/style-variations-container.js +5 -2
  35. package/build/components/global-styles/style-variations-container.js.map +1 -1
  36. package/build/components/global-styles/ui.js +4 -1
  37. package/build/components/global-styles/ui.js.map +1 -1
  38. package/build/components/global-styles/variations/variations-color.js +10 -3
  39. package/build/components/global-styles/variations/variations-color.js.map +1 -1
  40. package/build/components/global-styles/variations/variations-typography.js +9 -2
  41. package/build/components/global-styles/variations/variations-typography.js.map +1 -1
  42. package/build/components/keyboard-shortcut-help-modal/index.js +3 -0
  43. package/build/components/keyboard-shortcut-help-modal/index.js.map +1 -1
  44. package/build/components/layout/animation.js +129 -0
  45. package/build/components/layout/animation.js.map +1 -0
  46. package/build/components/layout/index.js +9 -17
  47. package/build/components/layout/index.js.map +1 -1
  48. package/build/components/layout/router.js +21 -18
  49. package/build/components/layout/router.js.map +1 -1
  50. package/build/components/page-pages/index.js +19 -17
  51. package/build/components/page-pages/index.js.map +1 -1
  52. package/build/components/page-patterns/index.js +18 -28
  53. package/build/components/page-patterns/index.js.map +1 -1
  54. package/build/components/page-patterns/search-items.js +16 -58
  55. package/build/components/page-patterns/search-items.js.map +1 -1
  56. package/build/components/page-templates-template-parts/actions.js +54 -41
  57. package/build/components/page-templates-template-parts/actions.js.map +1 -1
  58. package/build/components/page-templates-template-parts/index.js +26 -59
  59. package/build/components/page-templates-template-parts/index.js.map +1 -1
  60. package/build/components/plugin-template-setting-panel/index.js +12 -1
  61. package/build/components/plugin-template-setting-panel/index.js.map +1 -1
  62. package/build/components/save-button/index.js +45 -16
  63. package/build/components/save-button/index.js.map +1 -1
  64. package/build/components/save-hub/index.js +8 -112
  65. package/build/components/save-hub/index.js.map +1 -1
  66. package/build/components/sidebar/index.js +1 -5
  67. package/build/components/sidebar/index.js.map +1 -1
  68. package/build/components/sidebar-dataviews/default-views.js +1 -1
  69. package/build/components/sidebar-dataviews/default-views.js.map +1 -1
  70. package/build/components/sidebar-dataviews/index.js +1 -1
  71. package/build/components/sidebar-dataviews/index.js.map +1 -1
  72. package/build/components/sidebar-edit-mode/index.js +1 -2
  73. package/build/components/sidebar-edit-mode/index.js.map +1 -1
  74. package/build/components/sidebar-edit-mode/page-panels/index.js +5 -15
  75. package/build/components/sidebar-edit-mode/page-panels/index.js.map +1 -1
  76. package/build/components/sidebar-edit-mode/page-panels/page-content.js +7 -5
  77. package/build/components/sidebar-edit-mode/page-panels/page-content.js.map +1 -1
  78. package/build/components/sidebar-edit-mode/template-panel/index.js +10 -16
  79. package/build/components/sidebar-edit-mode/template-panel/index.js.map +1 -1
  80. package/build/components/sidebar-navigation-screen-details-footer/index.js +5 -1
  81. package/build/components/sidebar-navigation-screen-details-footer/index.js.map +1 -1
  82. package/build/components/sidebar-navigation-screen-global-styles/index.js +10 -5
  83. package/build/components/sidebar-navigation-screen-global-styles/index.js.map +1 -1
  84. package/build/components/sidebar-navigation-screen-patterns/index.js +1 -5
  85. package/build/components/sidebar-navigation-screen-patterns/index.js.map +1 -1
  86. package/build/components/style-book/index.js +1 -1
  87. package/build/components/style-book/index.js.map +1 -1
  88. package/build/components/sync-state-with-url/use-init-edited-entity-from-url.js +2 -2
  89. package/build/components/sync-state-with-url/use-init-edited-entity-from-url.js.map +1 -1
  90. package/build/components/sync-state-with-url/use-sync-path-with-url.js +1 -1
  91. package/build/components/sync-state-with-url/use-sync-path-with-url.js.map +1 -1
  92. package/build/hooks/index.js +0 -1
  93. package/build/hooks/index.js.map +1 -1
  94. package/build/store/selectors.js +1 -9
  95. package/build/store/selectors.js.map +1 -1
  96. package/build-module/components/block-editor/editor-canvas.js +8 -1
  97. package/build-module/components/block-editor/editor-canvas.js.map +1 -1
  98. package/build-module/components/block-editor/site-editor-canvas.js +15 -4
  99. package/build-module/components/block-editor/site-editor-canvas.js.map +1 -1
  100. package/build-module/components/editor/index.js +13 -4
  101. package/build-module/components/editor/index.js.map +1 -1
  102. package/build-module/components/editor-canvas-container/index.js +1 -2
  103. package/build-module/components/editor-canvas-container/index.js.map +1 -1
  104. package/build-module/components/global-styles/background-panel.js +31 -0
  105. package/build-module/components/global-styles/background-panel.js.map +1 -0
  106. package/build-module/components/global-styles/font-families.js +1 -1
  107. package/build-module/components/global-styles/font-families.js.map +1 -1
  108. package/build-module/components/global-styles/font-library-modal/context.js +38 -9
  109. package/build-module/components/global-styles/font-library-modal/context.js.map +1 -1
  110. package/build-module/components/global-styles/font-library-modal/utils/index.js +20 -2
  111. package/build-module/components/global-styles/font-library-modal/utils/index.js.map +1 -1
  112. package/build-module/components/global-styles/palette.js +3 -1
  113. package/build-module/components/global-styles/palette.js.map +1 -1
  114. package/build-module/components/global-styles/preview-colors.js +2 -2
  115. package/build-module/components/global-styles/preview-colors.js.map +1 -1
  116. package/build-module/components/global-styles/root-menu.js +9 -3
  117. package/build-module/components/global-styles/root-menu.js.map +1 -1
  118. package/build-module/components/global-styles/screen-background.js +26 -0
  119. package/build-module/components/global-styles/screen-background.js.map +1 -0
  120. package/build-module/components/global-styles/screen-color-palette.js +2 -2
  121. package/build-module/components/global-styles/screen-color-palette.js.map +1 -1
  122. package/build-module/components/global-styles/screen-colors.js +6 -4
  123. package/build-module/components/global-styles/screen-colors.js.map +1 -1
  124. package/build-module/components/global-styles/screen-style-variations.js +4 -38
  125. package/build-module/components/global-styles/screen-style-variations.js.map +1 -1
  126. package/build-module/components/global-styles/screen-typography.js +6 -6
  127. package/build-module/components/global-styles/screen-typography.js.map +1 -1
  128. package/build-module/components/global-styles/style-variations-container.js +5 -2
  129. package/build-module/components/global-styles/style-variations-container.js.map +1 -1
  130. package/build-module/components/global-styles/ui.js +4 -1
  131. package/build-module/components/global-styles/ui.js.map +1 -1
  132. package/build-module/components/global-styles/variations/variations-color.js +10 -3
  133. package/build-module/components/global-styles/variations/variations-color.js.map +1 -1
  134. package/build-module/components/global-styles/variations/variations-typography.js +9 -2
  135. package/build-module/components/global-styles/variations/variations-typography.js.map +1 -1
  136. package/build-module/components/keyboard-shortcut-help-modal/index.js +3 -0
  137. package/build-module/components/keyboard-shortcut-help-modal/index.js.map +1 -1
  138. package/build-module/components/layout/animation.js +122 -0
  139. package/build-module/components/layout/animation.js.map +1 -0
  140. package/build-module/components/layout/index.js +9 -17
  141. package/build-module/components/layout/index.js.map +1 -1
  142. package/build-module/components/layout/router.js +21 -18
  143. package/build-module/components/layout/router.js.map +1 -1
  144. package/build-module/components/page-pages/index.js +19 -17
  145. package/build-module/components/page-pages/index.js.map +1 -1
  146. package/build-module/components/page-patterns/index.js +20 -30
  147. package/build-module/components/page-patterns/index.js.map +1 -1
  148. package/build-module/components/page-patterns/search-items.js +14 -55
  149. package/build-module/components/page-patterns/search-items.js.map +1 -1
  150. package/build-module/components/page-templates-template-parts/actions.js +54 -40
  151. package/build-module/components/page-templates-template-parts/actions.js.map +1 -1
  152. package/build-module/components/page-templates-template-parts/index.js +29 -62
  153. package/build-module/components/page-templates-template-parts/index.js.map +1 -1
  154. package/build-module/components/plugin-template-setting-panel/index.js +12 -1
  155. package/build-module/components/plugin-template-setting-panel/index.js.map +1 -1
  156. package/build-module/components/save-button/index.js +46 -17
  157. package/build-module/components/save-button/index.js.map +1 -1
  158. package/build-module/components/save-hub/index.js +10 -114
  159. package/build-module/components/save-hub/index.js.map +1 -1
  160. package/build-module/components/sidebar/index.js +1 -5
  161. package/build-module/components/sidebar/index.js.map +1 -1
  162. package/build-module/components/sidebar-dataviews/default-views.js +1 -1
  163. package/build-module/components/sidebar-dataviews/default-views.js.map +1 -1
  164. package/build-module/components/sidebar-dataviews/index.js +1 -1
  165. package/build-module/components/sidebar-dataviews/index.js.map +1 -1
  166. package/build-module/components/sidebar-edit-mode/index.js +1 -2
  167. package/build-module/components/sidebar-edit-mode/index.js.map +1 -1
  168. package/build-module/components/sidebar-edit-mode/page-panels/index.js +8 -18
  169. package/build-module/components/sidebar-edit-mode/page-panels/index.js.map +1 -1
  170. package/build-module/components/sidebar-edit-mode/page-panels/page-content.js +7 -5
  171. package/build-module/components/sidebar-edit-mode/page-panels/page-content.js.map +1 -1
  172. package/build-module/components/sidebar-edit-mode/template-panel/index.js +11 -17
  173. package/build-module/components/sidebar-edit-mode/template-panel/index.js.map +1 -1
  174. package/build-module/components/sidebar-navigation-screen-details-footer/index.js +5 -1
  175. package/build-module/components/sidebar-navigation-screen-details-footer/index.js.map +1 -1
  176. package/build-module/components/sidebar-navigation-screen-global-styles/index.js +10 -5
  177. package/build-module/components/sidebar-navigation-screen-global-styles/index.js.map +1 -1
  178. package/build-module/components/sidebar-navigation-screen-patterns/index.js +1 -5
  179. package/build-module/components/sidebar-navigation-screen-patterns/index.js.map +1 -1
  180. package/build-module/components/style-book/index.js +1 -1
  181. package/build-module/components/style-book/index.js.map +1 -1
  182. package/build-module/components/sync-state-with-url/use-init-edited-entity-from-url.js +2 -2
  183. package/build-module/components/sync-state-with-url/use-init-edited-entity-from-url.js.map +1 -1
  184. package/build-module/components/sync-state-with-url/use-sync-path-with-url.js +1 -1
  185. package/build-module/components/sync-state-with-url/use-sync-path-with-url.js.map +1 -1
  186. package/build-module/hooks/index.js +0 -1
  187. package/build-module/hooks/index.js.map +1 -1
  188. package/build-module/store/selectors.js +1 -9
  189. package/build-module/store/selectors.js.map +1 -1
  190. package/build-style/style-rtl.css +116 -104
  191. package/build-style/style.css +116 -104
  192. package/package.json +44 -44
  193. package/src/components/block-editor/editor-canvas.js +14 -2
  194. package/src/components/block-editor/site-editor-canvas.js +10 -7
  195. package/src/components/editor/index.js +11 -4
  196. package/src/components/editor-canvas-container/index.js +0 -1
  197. package/src/components/global-styles/background-panel.js +34 -0
  198. package/src/components/global-styles/font-families.js +1 -1
  199. package/src/components/global-styles/font-library-modal/context.js +43 -14
  200. package/src/components/global-styles/font-library-modal/style.scss +1 -1
  201. package/src/components/global-styles/font-library-modal/utils/index.js +17 -4
  202. package/src/components/global-styles/palette.js +3 -1
  203. package/src/components/global-styles/preview-colors.js +2 -2
  204. package/src/components/global-styles/root-menu.js +12 -1
  205. package/src/components/global-styles/screen-background.js +29 -0
  206. package/src/components/global-styles/screen-color-palette.js +2 -2
  207. package/src/components/global-styles/screen-colors.js +4 -4
  208. package/src/components/global-styles/screen-style-variations.js +4 -36
  209. package/src/components/global-styles/screen-typography.js +6 -9
  210. package/src/components/global-styles/style-variations-container.js +2 -1
  211. package/src/components/global-styles/style.scss +14 -12
  212. package/src/components/global-styles/ui.js +5 -0
  213. package/src/components/global-styles/variations/style.scss +32 -17
  214. package/src/components/global-styles/variations/variations-color.js +4 -2
  215. package/src/components/global-styles/variations/variations-typography.js +4 -1
  216. package/src/components/header-edit-mode/style.scss +28 -17
  217. package/src/components/keyboard-shortcut-help-modal/index.js +4 -0
  218. package/src/components/layout/animation.js +122 -0
  219. package/src/components/layout/index.js +12 -27
  220. package/src/components/layout/router.js +25 -19
  221. package/src/components/layout/style.scss +2 -0
  222. package/src/components/page-pages/index.js +27 -43
  223. package/src/components/page-patterns/index.js +20 -28
  224. package/src/components/page-patterns/search-items.js +13 -58
  225. package/src/components/page-templates-template-parts/actions.js +106 -91
  226. package/src/components/page-templates-template-parts/index.js +34 -78
  227. package/src/components/page-templates-template-parts/style.scss +5 -0
  228. package/src/components/plugin-template-setting-panel/index.js +14 -1
  229. package/src/components/save-button/index.js +55 -26
  230. package/src/components/save-hub/index.js +20 -164
  231. package/src/components/sidebar/index.js +0 -5
  232. package/src/components/sidebar-dataviews/default-views.js +1 -1
  233. package/src/components/sidebar-dataviews/index.js +1 -1
  234. package/src/components/sidebar-edit-mode/index.js +0 -2
  235. package/src/components/sidebar-edit-mode/page-panels/index.js +29 -60
  236. package/src/components/sidebar-edit-mode/page-panels/page-content.js +10 -10
  237. package/src/components/sidebar-edit-mode/template-panel/index.js +23 -33
  238. package/src/components/sidebar-edit-mode/template-panel/style.scss +1 -29
  239. package/src/components/sidebar-navigation-screen/style.scss +12 -9
  240. package/src/components/sidebar-navigation-screen-details-footer/index.js +6 -2
  241. package/src/components/sidebar-navigation-screen-global-styles/index.js +7 -13
  242. package/src/components/sidebar-navigation-screen-patterns/index.js +0 -7
  243. package/src/components/style-book/index.js +1 -3
  244. package/src/components/sync-state-with-url/use-init-edited-entity-from-url.js +2 -2
  245. package/src/components/sync-state-with-url/use-sync-path-with-url.js +1 -1
  246. package/src/hooks/index.js +0 -1
  247. package/src/store/selectors.js +3 -15
  248. package/src/style.scss +0 -1
  249. package/build/components/actions/index.js +0 -319
  250. package/build/components/actions/index.js.map +0 -1
  251. package/build/components/sidebar-edit-mode/sidebar-card/index.js +0 -48
  252. package/build/components/sidebar-edit-mode/sidebar-card/index.js.map +0 -1
  253. package/build/components/sidebar-edit-mode/template-panel/template-areas.js +0 -70
  254. package/build/components/sidebar-edit-mode/template-panel/template-areas.js.map +0 -1
  255. package/build/components/sidebar-navigation-screen-pages/index.js +0 -175
  256. package/build/components/sidebar-navigation-screen-pages/index.js.map +0 -1
  257. package/build/hooks/template-part-edit.js +0 -82
  258. package/build/hooks/template-part-edit.js.map +0 -1
  259. package/build/store/utils.js +0 -71
  260. package/build/store/utils.js.map +0 -1
  261. package/build-module/components/actions/index.js +0 -308
  262. package/build-module/components/actions/index.js.map +0 -1
  263. package/build-module/components/sidebar-edit-mode/sidebar-card/index.js +0 -40
  264. package/build-module/components/sidebar-edit-mode/sidebar-card/index.js.map +0 -1
  265. package/build-module/components/sidebar-edit-mode/template-panel/template-areas.js +0 -63
  266. package/build-module/components/sidebar-edit-mode/template-panel/template-areas.js.map +0 -1
  267. package/build-module/components/sidebar-navigation-screen-pages/index.js +0 -167
  268. package/build-module/components/sidebar-navigation-screen-pages/index.js.map +0 -1
  269. package/build-module/hooks/template-part-edit.js +0 -75
  270. package/build-module/hooks/template-part-edit.js.map +0 -1
  271. package/build-module/store/utils.js +0 -64
  272. package/build-module/store/utils.js.map +0 -1
  273. package/src/components/actions/index.js +0 -409
  274. package/src/components/sidebar-edit-mode/sidebar-card/index.js +0 -53
  275. package/src/components/sidebar-edit-mode/sidebar-card/style.scss +0 -36
  276. package/src/components/sidebar-edit-mode/template-panel/template-areas.js +0 -86
  277. package/src/components/sidebar-navigation-screen-pages/index.js +0 -238
  278. package/src/hooks/template-part-edit.js +0 -89
  279. package/src/store/test/utils.js +0 -191
  280. package/src/store/utils.js +0 -69
@@ -1 +0,0 @@
1
- {"version":3,"names":["__experimentalItemGroup","ItemGroup","__experimentalItem","Item","__experimentalTruncate","Truncate","__experimentalVStack","VStack","useState","__","useEntityRecords","store","coreStore","decodeEntities","privateApis","routerPrivateApis","layout","page","home","verse","plus","useSelect","useViewportMatch","SidebarNavigationScreen","useLink","SidebarNavigationItem","SidebarButton","AddNewPageModal","unlock","TEMPLATE_POST_TYPE","useHistory","PageItem","postType","postId","props","linkInfo","backPath","createElement","SidebarNavigationScreenPages","isMobileViewport","records","pages","isResolving","isLoadingPages","status","per_page","templates","isLoadingTemplates","dynamicPageTemplates","filter","slug","includes","homeTemplate","find","template","getPostsPageTemplate","pagesAndTemplates","concat","frontPage","postsPage","select","getEntityRecord","siteSettings","page_on_front","page_for_posts","isHomePageBlog","reorderedPages","length","homePageIndex","findIndex","item","id","homePage","splice","postsPageIndex","blogPage","showAddPage","setShowAddPage","history","handleNewPage","type","push","canvas","getPageProps","itemIcon","postsPageTemplateId","icon","pagesLink","path","Fragment","onSave","onClose","title","description","actions","label","onClick","content","key","withChevron","numberOfLines","rendered","map","footer","spacing","className"],"sources":["@wordpress/edit-site/src/components/sidebar-navigation-screen-pages/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\t__experimentalItemGroup as ItemGroup,\n\t__experimentalItem as Item,\n\t__experimentalTruncate as Truncate,\n\t__experimentalVStack as VStack,\n} from '@wordpress/components';\nimport { useState } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport { useEntityRecords, store as coreStore } from '@wordpress/core-data';\nimport { decodeEntities } from '@wordpress/html-entities';\nimport { privateApis as routerPrivateApis } from '@wordpress/router';\nimport { layout, page, home, verse, plus } from '@wordpress/icons';\nimport { useSelect } from '@wordpress/data';\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 SidebarButton from '../sidebar-button';\nimport AddNewPageModal from '../add-new-page';\nimport { unlock } from '../../lock-unlock';\nimport { TEMPLATE_POST_TYPE } from '../../utils/constants';\n\nconst { useHistory } = unlock( routerPrivateApis );\n\nconst PageItem = ( { postType = 'page', postId, ...props } ) => {\n\tconst linkInfo = useLink(\n\t\t{\n\t\t\tpostType,\n\t\t\tpostId,\n\t\t},\n\t\t{\n\t\t\tbackPath: '/page',\n\t\t}\n\t);\n\treturn <SidebarNavigationItem { ...linkInfo } { ...props } />;\n};\n\nexport default function SidebarNavigationScreenPages() {\n\tconst isMobileViewport = useViewportMatch( 'medium', '<' );\n\tconst { records: pages, isResolving: isLoadingPages } = useEntityRecords(\n\t\t'postType',\n\t\t'page',\n\t\t{\n\t\t\tstatus: 'any',\n\t\t\tper_page: -1,\n\t\t}\n\t);\n\tconst { records: templates, isResolving: isLoadingTemplates } =\n\t\tuseEntityRecords( 'postType', TEMPLATE_POST_TYPE, {\n\t\t\tper_page: -1,\n\t\t} );\n\n\tconst dynamicPageTemplates = templates?.filter( ( { slug } ) =>\n\t\t[ '404', 'search' ].includes( slug )\n\t);\n\n\tconst homeTemplate =\n\t\ttemplates?.find( ( template ) => template.slug === 'front-page' ) ||\n\t\ttemplates?.find( ( template ) => template.slug === 'home' ) ||\n\t\ttemplates?.find( ( template ) => template.slug === 'index' );\n\n\tconst getPostsPageTemplate = () =>\n\t\ttemplates?.find( ( template ) => template.slug === 'home' ) ||\n\t\ttemplates?.find( ( template ) => template.slug === 'index' );\n\n\tconst pagesAndTemplates = pages?.concat( dynamicPageTemplates, [\n\t\thomeTemplate,\n\t] );\n\n\tconst { frontPage, postsPage } = useSelect( ( select ) => {\n\t\tconst { getEntityRecord } = select( coreStore );\n\t\tconst siteSettings = getEntityRecord( 'root', 'site' );\n\t\treturn {\n\t\t\tfrontPage: siteSettings?.page_on_front,\n\t\t\tpostsPage: siteSettings?.page_for_posts,\n\t\t};\n\t}, [] );\n\n\tconst isHomePageBlog = frontPage === postsPage;\n\n\tconst reorderedPages = pages && [ ...pages ];\n\n\tif ( ! isHomePageBlog && reorderedPages?.length ) {\n\t\tconst homePageIndex = reorderedPages.findIndex(\n\t\t\t( item ) => item.id === frontPage\n\t\t);\n\t\tconst homePage = reorderedPages.splice( homePageIndex, 1 );\n\t\treorderedPages?.splice( 0, 0, ...homePage );\n\n\t\tconst postsPageIndex = reorderedPages.findIndex(\n\t\t\t( item ) => item.id === postsPage\n\t\t);\n\n\t\tconst blogPage = reorderedPages.splice( postsPageIndex, 1 );\n\n\t\treorderedPages.splice( 1, 0, ...blogPage );\n\t}\n\n\tconst [ showAddPage, setShowAddPage ] = useState( false );\n\n\tconst history = useHistory();\n\n\tconst handleNewPage = ( { type, id } ) => {\n\t\t// Navigate to the created template editor.\n\t\thistory.push( {\n\t\t\tpostId: id,\n\t\t\tpostType: type,\n\t\t\tcanvas: 'edit',\n\t\t} );\n\t\tsetShowAddPage( false );\n\t};\n\n\tconst getPageProps = ( id ) => {\n\t\tlet itemIcon = page;\n\t\tconst postsPageTemplateId =\n\t\t\tpostsPage && postsPage === id ? getPostsPageTemplate()?.id : null;\n\n\t\tswitch ( id ) {\n\t\t\tcase frontPage:\n\t\t\t\titemIcon = home;\n\t\t\t\tbreak;\n\t\t\tcase postsPage:\n\t\t\t\titemIcon = verse;\n\t\t\t\tbreak;\n\t\t}\n\n\t\treturn {\n\t\t\ticon: itemIcon,\n\t\t\tpostType: postsPageTemplateId ? TEMPLATE_POST_TYPE : 'page',\n\t\t\tpostId: postsPageTemplateId || id,\n\t\t};\n\t};\n\n\tconst pagesLink = useLink( { path: '/pages' } );\n\n\treturn (\n\t\t<>\n\t\t\t{ showAddPage && (\n\t\t\t\t<AddNewPageModal\n\t\t\t\t\tonSave={ handleNewPage }\n\t\t\t\t\tonClose={ () => setShowAddPage( false ) }\n\t\t\t\t/>\n\t\t\t) }\n\t\t\t<SidebarNavigationScreen\n\t\t\t\ttitle={ __( 'Pages' ) }\n\t\t\t\tdescription={ __( 'Browse and manage pages.' ) }\n\t\t\t\tactions={\n\t\t\t\t\t<SidebarButton\n\t\t\t\t\t\ticon={ plus }\n\t\t\t\t\t\tlabel={ __( 'Draft a new page' ) }\n\t\t\t\t\t\tonClick={ () => setShowAddPage( true ) }\n\t\t\t\t\t/>\n\t\t\t\t}\n\t\t\t\tcontent={\n\t\t\t\t\t<>\n\t\t\t\t\t\t{ ( isLoadingPages || isLoadingTemplates ) && (\n\t\t\t\t\t\t\t<ItemGroup>\n\t\t\t\t\t\t\t\t<Item>{ __( 'Loading pages…' ) }</Item>\n\t\t\t\t\t\t\t</ItemGroup>\n\t\t\t\t\t\t) }\n\t\t\t\t\t\t{ ! ( isLoadingPages || isLoadingTemplates ) && (\n\t\t\t\t\t\t\t<ItemGroup>\n\t\t\t\t\t\t\t\t{ ! pagesAndTemplates?.length && (\n\t\t\t\t\t\t\t\t\t<Item>{ __( 'No page found' ) }</Item>\n\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t{ isHomePageBlog && homeTemplate && (\n\t\t\t\t\t\t\t\t\t<PageItem\n\t\t\t\t\t\t\t\t\t\tpostType={ TEMPLATE_POST_TYPE }\n\t\t\t\t\t\t\t\t\t\tpostId={ homeTemplate.id }\n\t\t\t\t\t\t\t\t\t\tkey={ homeTemplate.id }\n\t\t\t\t\t\t\t\t\t\ticon={ home }\n\t\t\t\t\t\t\t\t\t\twithChevron\n\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t<Truncate numberOfLines={ 1 }>\n\t\t\t\t\t\t\t\t\t\t\t{ decodeEntities(\n\t\t\t\t\t\t\t\t\t\t\t\thomeTemplate.title?.rendered ||\n\t\t\t\t\t\t\t\t\t\t\t\t\t__( '(no title)' )\n\t\t\t\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t\t\t</Truncate>\n\t\t\t\t\t\t\t\t\t</PageItem>\n\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t{ reorderedPages?.map( ( { id, title } ) => (\n\t\t\t\t\t\t\t\t\t<PageItem\n\t\t\t\t\t\t\t\t\t\t{ ...getPageProps( id ) }\n\t\t\t\t\t\t\t\t\t\tkey={ id }\n\t\t\t\t\t\t\t\t\t\twithChevron\n\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t<Truncate numberOfLines={ 1 }>\n\t\t\t\t\t\t\t\t\t\t\t{ decodeEntities(\n\t\t\t\t\t\t\t\t\t\t\t\ttitle?.rendered ||\n\t\t\t\t\t\t\t\t\t\t\t\t\t__( '(no title)' )\n\t\t\t\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t\t\t</Truncate>\n\t\t\t\t\t\t\t\t\t</PageItem>\n\t\t\t\t\t\t\t\t) ) }\n\t\t\t\t\t\t\t</ItemGroup>\n\t\t\t\t\t\t) }\n\t\t\t\t\t</>\n\t\t\t\t}\n\t\t\t\tfooter={\n\t\t\t\t\t<VStack spacing={ 0 }>\n\t\t\t\t\t\t{ dynamicPageTemplates?.map( ( item ) => (\n\t\t\t\t\t\t\t<PageItem\n\t\t\t\t\t\t\t\tpostType={ TEMPLATE_POST_TYPE }\n\t\t\t\t\t\t\t\tpostId={ item.id }\n\t\t\t\t\t\t\t\tkey={ item.id }\n\t\t\t\t\t\t\t\ticon={ layout }\n\t\t\t\t\t\t\t\twithChevron\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t<Truncate numberOfLines={ 1 }>\n\t\t\t\t\t\t\t\t\t{ decodeEntities(\n\t\t\t\t\t\t\t\t\t\titem.title?.rendered ||\n\t\t\t\t\t\t\t\t\t\t\t__( '(no title)' )\n\t\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t</Truncate>\n\t\t\t\t\t\t\t</PageItem>\n\t\t\t\t\t\t) ) }\n\t\t\t\t\t\t{ ! isMobileViewport && (\n\t\t\t\t\t\t\t<SidebarNavigationItem\n\t\t\t\t\t\t\t\tclassName=\"edit-site-sidebar-navigation-screen-pages__see-all\"\n\t\t\t\t\t\t\t\t{ ...pagesLink }\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t{ __( 'Manage all pages' ) }\n\t\t\t\t\t\t\t</SidebarNavigationItem>\n\t\t\t\t\t\t) }\n\t\t\t\t\t</VStack>\n\t\t\t\t}\n\t\t\t/>\n\t\t</>\n\t);\n}\n"],"mappings":";AAAA;AACA;AACA;AACA,SACCA,uBAAuB,IAAIC,SAAS,EACpCC,kBAAkB,IAAIC,IAAI,EAC1BC,sBAAsB,IAAIC,QAAQ,EAClCC,oBAAoB,IAAIC,MAAM,QACxB,uBAAuB;AAC9B,SAASC,QAAQ,QAAQ,oBAAoB;AAC7C,SAASC,EAAE,QAAQ,iBAAiB;AACpC,SAASC,gBAAgB,EAAEC,KAAK,IAAIC,SAAS,QAAQ,sBAAsB;AAC3E,SAASC,cAAc,QAAQ,0BAA0B;AACzD,SAASC,WAAW,IAAIC,iBAAiB,QAAQ,mBAAmB;AACpE,SAASC,MAAM,EAAEC,IAAI,EAAEC,IAAI,EAAEC,KAAK,EAAEC,IAAI,QAAQ,kBAAkB;AAClE,SAASC,SAAS,QAAQ,iBAAiB;AAC3C,SAASC,gBAAgB,QAAQ,oBAAoB;;AAErD;AACA;AACA;AACA,OAAOC,uBAAuB,MAAM,8BAA8B;AAClE,SAASC,OAAO,QAAQ,gBAAgB;AACxC,OAAOC,qBAAqB,MAAM,4BAA4B;AAC9D,OAAOC,aAAa,MAAM,mBAAmB;AAC7C,OAAOC,eAAe,MAAM,iBAAiB;AAC7C,SAASC,MAAM,QAAQ,mBAAmB;AAC1C,SAASC,kBAAkB,QAAQ,uBAAuB;AAE1D,MAAM;EAAEC;AAAW,CAAC,GAAGF,MAAM,CAAEb,iBAAkB,CAAC;AAElD,MAAMgB,QAAQ,GAAGA,CA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AAES,QAAQ,IACd5F,EAAE,CAAE,YAAa,CACnB,CACS,CACD,CACT,CACQ,CAEX,CACF;IACD8F,MAAM,EACLlE,aAAA,CAAC9B,MAAM;MAACiG,OAAO,EAAG;IAAG,GAClBxD,oBAAoB,EAAEsD,GAAG,CAAIhC,IAAI,IAClCjC,aAAA,CAACN,QAAQ;MACRC,QAAQ,EAAGH,kBAAoB;MAC/BI,MAAM,EAAGqC,IAAI,CAACC,EAAI;MAClB2B,GAAG,EAAG5B,IAAI,CAACC,EAAI;MACfe,IAAI,EAAGtE,MAAQ;MACfmF,WAAW;IAAA,GAEX9D,aAAA,CAAChC,QAAQ;MAAC+F,aAAa,EAAG;IAAG,GAC1BvF,cAAc,CACfyD,IAAI,CAACsB,KAAK,EAAES,QAAQ,IACnB5F,EAAE,CAAE,YAAa,CACnB,CACS,CACD,CACT,CAAC,EACD,CAAE8B,gBAAgB,IACnBF,aAAA,CAACZ,qBAAqB;MACrBgF,SAAS,EAAC,oDAAoD;MAAA,GACzDlB;IAAS,GAEZ9E,EAAE,CAAE,kBAAmB,CACH,CAEjB;EACR,CACD,CACA,CAAC;AAEL"}
@@ -1,75 +0,0 @@
1
- import { createElement, Fragment } from "react";
2
- /**
3
- * WordPress dependencies
4
- */
5
- import { __ } from '@wordpress/i18n';
6
- import { useSelect } from '@wordpress/data';
7
- import { BlockControls } from '@wordpress/block-editor';
8
- import { store as coreStore } from '@wordpress/core-data';
9
- import { ToolbarButton } from '@wordpress/components';
10
- import { addFilter } from '@wordpress/hooks';
11
- import { createHigherOrderComponent } from '@wordpress/compose';
12
- import { privateApis as routerPrivateApis } from '@wordpress/router';
13
-
14
- /**
15
- * Internal dependencies
16
- */
17
- import { useLink } from '../components/routes/link';
18
- import { unlock } from '../lock-unlock';
19
- import { TEMPLATE_PART_POST_TYPE } from '../utils/constants';
20
- const {
21
- useLocation
22
- } = unlock(routerPrivateApis);
23
- function EditTemplatePartMenuItem({
24
- attributes
25
- }) {
26
- const {
27
- theme,
28
- slug
29
- } = attributes;
30
- const {
31
- params
32
- } = useLocation();
33
- const templatePart = useSelect(select => {
34
- const {
35
- getCurrentTheme,
36
- getEntityRecord
37
- } = select(coreStore);
38
- return getEntityRecord('postType', TEMPLATE_PART_POST_TYPE,
39
- // Ideally this should be an official public API.
40
- `${theme || getCurrentTheme()?.stylesheet}//${slug}`);
41
- }, [theme, slug]);
42
- const linkProps = useLink({
43
- postId: templatePart?.id,
44
- postType: templatePart?.type,
45
- canvas: 'edit'
46
- }, {
47
- fromTemplateId: params.postId || templatePart?.id
48
- });
49
- if (!templatePart) {
50
- return null;
51
- }
52
- return createElement(ToolbarButton, {
53
- ...linkProps,
54
- onClick: event => {
55
- linkProps.onClick(event);
56
- }
57
- }, __('Edit'));
58
- }
59
- export const withEditBlockControls = createHigherOrderComponent(BlockEdit => props => {
60
- const {
61
- attributes,
62
- name
63
- } = props;
64
- const isDisplayed = name === 'core/template-part' && attributes.slug;
65
- return createElement(Fragment, null, createElement(BlockEdit, {
66
- key: "edit",
67
- ...props
68
- }), isDisplayed && createElement(BlockControls, {
69
- group: "other"
70
- }, createElement(EditTemplatePartMenuItem, {
71
- attributes: attributes
72
- })));
73
- }, 'withEditBlockControls');
74
- addFilter('editor.BlockEdit', 'core/edit-site/template-part-edit-button', withEditBlockControls);
75
- //# sourceMappingURL=template-part-edit.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["__","useSelect","BlockControls","store","coreStore","ToolbarButton","addFilter","createHigherOrderComponent","privateApis","routerPrivateApis","useLink","unlock","TEMPLATE_PART_POST_TYPE","useLocation","EditTemplatePartMenuItem","attributes","theme","slug","params","templatePart","select","getCurrentTheme","getEntityRecord","stylesheet","linkProps","postId","id","postType","type","canvas","fromTemplateId","createElement","onClick","event","withEditBlockControls","BlockEdit","props","name","isDisplayed","Fragment","key","group"],"sources":["@wordpress/edit-site/src/hooks/template-part-edit.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { useSelect } from '@wordpress/data';\nimport { BlockControls } from '@wordpress/block-editor';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { ToolbarButton } from '@wordpress/components';\nimport { addFilter } from '@wordpress/hooks';\nimport { createHigherOrderComponent } from '@wordpress/compose';\nimport { privateApis as routerPrivateApis } from '@wordpress/router';\n\n/**\n * Internal dependencies\n */\nimport { useLink } from '../components/routes/link';\nimport { unlock } from '../lock-unlock';\nimport { TEMPLATE_PART_POST_TYPE } from '../utils/constants';\n\nconst { useLocation } = unlock( routerPrivateApis );\n\nfunction EditTemplatePartMenuItem( { attributes } ) {\n\tconst { theme, slug } = attributes;\n\tconst { params } = useLocation();\n\tconst templatePart = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getCurrentTheme, getEntityRecord } = select( coreStore );\n\n\t\t\treturn getEntityRecord(\n\t\t\t\t'postType',\n\t\t\t\tTEMPLATE_PART_POST_TYPE,\n\t\t\t\t// Ideally this should be an official public API.\n\t\t\t\t`${ theme || getCurrentTheme()?.stylesheet }//${ slug }`\n\t\t\t);\n\t\t},\n\t\t[ theme, slug ]\n\t);\n\n\tconst linkProps = useLink(\n\t\t{\n\t\t\tpostId: templatePart?.id,\n\t\t\tpostType: templatePart?.type,\n\t\t\tcanvas: 'edit',\n\t\t},\n\t\t{\n\t\t\tfromTemplateId: params.postId || templatePart?.id,\n\t\t}\n\t);\n\n\tif ( ! templatePart ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<ToolbarButton\n\t\t\t{ ...linkProps }\n\t\t\tonClick={ ( event ) => {\n\t\t\t\tlinkProps.onClick( event );\n\t\t\t} }\n\t\t>\n\t\t\t{ __( 'Edit' ) }\n\t\t</ToolbarButton>\n\t);\n}\n\nexport const withEditBlockControls = createHigherOrderComponent(\n\t( BlockEdit ) => ( props ) => {\n\t\tconst { attributes, name } = props;\n\t\tconst isDisplayed = name === 'core/template-part' && attributes.slug;\n\n\t\treturn (\n\t\t\t<>\n\t\t\t\t<BlockEdit key=\"edit\" { ...props } />\n\t\t\t\t{ isDisplayed && (\n\t\t\t\t\t<BlockControls group=\"other\">\n\t\t\t\t\t\t<EditTemplatePartMenuItem attributes={ attributes } />\n\t\t\t\t\t</BlockControls>\n\t\t\t\t) }\n\t\t\t</>\n\t\t);\n\t},\n\t'withEditBlockControls'\n);\n\naddFilter(\n\t'editor.BlockEdit',\n\t'core/edit-site/template-part-edit-button',\n\twithEditBlockControls\n);\n"],"mappings":";AAAA;AACA;AACA;AACA,SAASA,EAAE,QAAQ,iBAAiB;AACpC,SAASC,SAAS,QAAQ,iBAAiB;AAC3C,SAASC,aAAa,QAAQ,yBAAyB;AACvD,SAASC,KAAK,IAAIC,SAAS,QAAQ,sBAAsB;AACzD,SAASC,aAAa,QAAQ,uBAAuB;AACrD,SAASC,SAAS,QAAQ,kBAAkB;AAC5C,SAASC,0BAA0B,QAAQ,oBAAoB;AAC/D,SAASC,WAAW,IAAIC,iBAAiB,QAAQ,mBAAmB;;AAEpE;AACA;AACA;AACA,SAASC,OAAO,QAAQ,2BAA2B;AACnD,SAASC,MAAM,QAAQ,gBAAgB;AACvC,SAASC,uBAAuB,QAAQ,oBAAoB;AAE5D,MAAM;EAAEC;AAAY,CAAC,GAAGF,MAAM,CAAEF,iBAAkB,CAAC;AAEnD,SAASK,wBAAwBA,CAAE;EAAEC;AAAW,CAAC,EAAG;EACnD,MAAM;IAAEC,KAAK;IAAEC;EAAK,CAAC,GAAGF,UAAU;EAClC,MAAM;IAAEG;EAAO,CAAC,GAAGL,WAAW,CAAC,CAAC;EAChC,MAAMM,YAAY,GAAGlB,SAAS,CAC3BmB,MAAM,IAAM;IACb,MAAM;MAAEC,eAAe;MAAEC;IAAgB,CAAC,GAAGF,MAAM,CAAEhB,SAAU,CAAC;IAEhE,OAAOkB,eAAe,CACrB,UAAU,EACVV,uBAAuB;IACvB;IACC,GAAGI,KAAK,IAAIK,eAAe,CAAC,CAAC,EAAEE,UAAY,KAAKN,IAAM,EACxD,CAAC;EACF,CAAC,EACD,CAAED,KAAK,EAAEC,IAAI,CACd,CAAC;EAED,MAAMO,SAAS,GAAGd,OAAO,CACxB;IACCe,MAAM,EAAEN,YAAY,EAAEO,EAAE;IACxBC,QAAQ,EAAER,YAAY,EAAES,IAAI;IAC5BC,MAAM,EAAE;EACT,CAAC,EACD;IACCC,cAAc,EAAEZ,MAAM,CAACO,MAAM,IAAIN,YAAY,EAAEO;EAChD,CACD,CAAC;EAED,IAAK,CAAEP,YAAY,EAAG;IACrB,OAAO,IAAI;EACZ;EAEA,OACCY,aAAA,CAAC1B,aAAa;IAAA,GACRmB,SAAS;IACdQ,OAAO,EAAKC,KAAK,IAAM;MACtBT,SAAS,CAACQ,OAAO,CAAEC,KAAM,CAAC;IAC3B;EAAG,GAEDjC,EAAE,CAAE,MAAO,CACC,CAAC;AAElB;AAEA,OAAO,MAAMkC,qBAAqB,GAAG3B,0BAA0B,CAC5D4B,SAAS,IAAQC,KAAK,IAAM;EAC7B,MAAM;IAAErB,UAAU;IAAEsB;EAAK,CAAC,GAAGD,KAAK;EAClC,MAAME,WAAW,GAAGD,IAAI,KAAK,oBAAoB,IAAItB,UAAU,CAACE,IAAI;EAEpE,OACCc,aAAA,CAAAQ,QAAA,QACCR,aAAA,CAACI,SAAS;IAACK,GAAG,EAAC,MAAM;IAAA,GAAMJ;EAAK,CAAI,CAAC,EACnCE,WAAW,IACZP,aAAA,CAAC7B,aAAa;IAACuC,KAAK,EAAC;EAAO,GAC3BV,aAAA,CAACjB,wBAAwB;IAACC,UAAU,EAAGA;EAAY,CAAE,CACvC,CAEf,CAAC;AAEL,CAAC,EACD,uBACD,CAAC;AAEDT,SAAS,CACR,kBAAkB,EAClB,0CAA0C,EAC1C4B,qBACD,CAAC"}
@@ -1,64 +0,0 @@
1
- /**
2
- * External dependencies
3
- */
4
- import memoize from 'memize';
5
-
6
- /**
7
- * WordPress dependencies
8
- */
9
- import { isTemplatePart } from '@wordpress/blocks';
10
- const EMPTY_ARRAY = [];
11
-
12
- /**
13
- * Get a flattened and filtered list of template parts and the matching block for that template part.
14
- *
15
- * Takes a list of blocks defined within a template, and a list of template parts, and returns a
16
- * flattened list of template parts and the matching block for that template part.
17
- *
18
- * @param {Array} blocks Blocks to flatten.
19
- * @param {?Array} templateParts Available template parts.
20
- * @return {Array} An array of template parts and their blocks.
21
- */
22
- function getFilteredTemplatePartBlocks(blocks = EMPTY_ARRAY, templateParts) {
23
- const templatePartsById = templateParts ?
24
- // Key template parts by their ID.
25
- templateParts.reduce((newTemplateParts, part) => ({
26
- ...newTemplateParts,
27
- [part.id]: part
28
- }), {}) : {};
29
- const result = [];
30
-
31
- // Iterate over all blocks, recursing into inner blocks.
32
- // Output will be based on a depth-first traversal.
33
- const stack = [...blocks];
34
- while (stack.length) {
35
- const {
36
- innerBlocks,
37
- ...block
38
- } = stack.shift();
39
- // Place inner blocks at the beginning of the stack to preserve order.
40
- stack.unshift(...innerBlocks);
41
- if (isTemplatePart(block)) {
42
- const {
43
- attributes: {
44
- theme,
45
- slug
46
- }
47
- } = block;
48
- const templatePartId = `${theme}//${slug}`;
49
- const templatePart = templatePartsById[templatePartId];
50
-
51
- // Only add to output if the found template part block is in the list of available template parts.
52
- if (templatePart) {
53
- result.push({
54
- templatePart,
55
- block
56
- });
57
- }
58
- }
59
- }
60
- return result;
61
- }
62
- const memoizedGetFilteredTemplatePartBlocks = memoize(getFilteredTemplatePartBlocks);
63
- export { memoizedGetFilteredTemplatePartBlocks as getFilteredTemplatePartBlocks };
64
- //# sourceMappingURL=utils.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["memoize","isTemplatePart","EMPTY_ARRAY","getFilteredTemplatePartBlocks","blocks","templateParts","templatePartsById","reduce","newTemplateParts","part","id","result","stack","length","innerBlocks","block","shift","unshift","attributes","theme","slug","templatePartId","templatePart","push","memoizedGetFilteredTemplatePartBlocks"],"sources":["@wordpress/edit-site/src/store/utils.js"],"sourcesContent":["/**\n * External dependencies\n */\nimport memoize from 'memize';\n\n/**\n * WordPress dependencies\n */\nimport { isTemplatePart } from '@wordpress/blocks';\n\nconst EMPTY_ARRAY = [];\n\n/**\n * Get a flattened and filtered list of template parts and the matching block for that template part.\n *\n * Takes a list of blocks defined within a template, and a list of template parts, and returns a\n * flattened list of template parts and the matching block for that template part.\n *\n * @param {Array} blocks Blocks to flatten.\n * @param {?Array} templateParts Available template parts.\n * @return {Array} An array of template parts and their blocks.\n */\nfunction getFilteredTemplatePartBlocks( blocks = EMPTY_ARRAY, templateParts ) {\n\tconst templatePartsById = templateParts\n\t\t? // Key template parts by their ID.\n\t\t templateParts.reduce(\n\t\t\t\t( newTemplateParts, part ) => ( {\n\t\t\t\t\t...newTemplateParts,\n\t\t\t\t\t[ part.id ]: part,\n\t\t\t\t} ),\n\t\t\t\t{}\n\t\t )\n\t\t: {};\n\n\tconst result = [];\n\n\t// Iterate over all blocks, recursing into inner blocks.\n\t// Output will be based on a depth-first traversal.\n\tconst stack = [ ...blocks ];\n\twhile ( stack.length ) {\n\t\tconst { innerBlocks, ...block } = stack.shift();\n\t\t// Place inner blocks at the beginning of the stack to preserve order.\n\t\tstack.unshift( ...innerBlocks );\n\n\t\tif ( isTemplatePart( block ) ) {\n\t\t\tconst {\n\t\t\t\tattributes: { theme, slug },\n\t\t\t} = block;\n\t\t\tconst templatePartId = `${ theme }//${ slug }`;\n\t\t\tconst templatePart = templatePartsById[ templatePartId ];\n\n\t\t\t// Only add to output if the found template part block is in the list of available template parts.\n\t\t\tif ( templatePart ) {\n\t\t\t\tresult.push( {\n\t\t\t\t\ttemplatePart,\n\t\t\t\t\tblock,\n\t\t\t\t} );\n\t\t\t}\n\t\t}\n\t}\n\n\treturn result;\n}\n\nconst memoizedGetFilteredTemplatePartBlocks = memoize(\n\tgetFilteredTemplatePartBlocks\n);\n\nexport { memoizedGetFilteredTemplatePartBlocks as getFilteredTemplatePartBlocks };\n"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,OAAO,MAAM,QAAQ;;AAE5B;AACA;AACA;AACA,SAASC,cAAc,QAAQ,mBAAmB;AAElD,MAAMC,WAAW,GAAG,EAAE;;AAEtB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,6BAA6BA,CAAEC,MAAM,GAAGF,WAAW,EAAEG,aAAa,EAAG;EAC7E,MAAMC,iBAAiB,GAAGD,aAAa;EACpC;EACAA,aAAa,CAACE,MAAM,CACpB,CAAEC,gBAAgB,EAAEC,IAAI,MAAQ;IAC/B,GAAGD,gBAAgB;IACnB,CAAEC,IAAI,CAACC,EAAE,GAAID;EACd,CAAC,CAAE,EACH,CAAC,CACD,CAAC,GACD,CAAC,CAAC;EAEL,MAAME,MAAM,GAAG,EAAE;;EAEjB;EACA;EACA,MAAMC,KAAK,GAAG,CAAE,GAAGR,MAAM,CAAE;EAC3B,OAAQQ,KAAK,CAACC,MAAM,EAAG;IACtB,MAAM;MAAEC,WAAW;MAAE,GAAGC;IAAM,CAAC,GAAGH,KAAK,CAACI,KAAK,CAAC,CAAC;IAC/C;IACAJ,KAAK,CAACK,OAAO,CAAE,GAAGH,WAAY,CAAC;IAE/B,IAAKb,cAAc,CAAEc,KAAM,CAAC,EAAG;MAC9B,MAAM;QACLG,UAAU,EAAE;UAAEC,KAAK;UAAEC;QAAK;MAC3B,CAAC,GAAGL,KAAK;MACT,MAAMM,cAAc,GAAI,GAAGF,KAAO,KAAKC,IAAM,EAAC;MAC9C,MAAME,YAAY,GAAGhB,iBAAiB,CAAEe,cAAc,CAAE;;MAExD;MACA,IAAKC,YAAY,EAAG;QACnBX,MAAM,CAACY,IAAI,CAAE;UACZD,YAAY;UACZP;QACD,CAAE,CAAC;MACJ;IACD;EACD;EAEA,OAAOJ,MAAM;AACd;AAEA,MAAMa,qCAAqC,GAAGxB,OAAO,CACpDG,6BACD,CAAC;AAED,SAASqB,qCAAqC,IAAIrB,6BAA6B"}
@@ -1,409 +0,0 @@
1
- /**
2
- * WordPress dependencies
3
- */
4
- import { external, edit, backup } from '@wordpress/icons';
5
- import { addQueryArgs } from '@wordpress/url';
6
- import { useDispatch } from '@wordpress/data';
7
- import { decodeEntities } from '@wordpress/html-entities';
8
- import { store as coreStore } from '@wordpress/core-data';
9
- import { __, sprintf } from '@wordpress/i18n';
10
- import { store as noticesStore } from '@wordpress/notices';
11
- import { useMemo } from '@wordpress/element';
12
- import { privateApis as routerPrivateApis } from '@wordpress/router';
13
- import {
14
- Button,
15
- __experimentalText as Text,
16
- __experimentalHStack as HStack,
17
- __experimentalVStack as VStack,
18
- } from '@wordpress/components';
19
-
20
- /**
21
- * Internal dependencies
22
- */
23
- import { unlock } from '../../lock-unlock';
24
-
25
- const { useHistory } = unlock( routerPrivateApis );
26
-
27
- export const trashPostAction = {
28
- id: 'move-to-trash',
29
- label: __( 'Move to Trash' ),
30
- isEligible( { status } ) {
31
- return status !== 'trash';
32
- },
33
- supportsBulk: true,
34
- hideModalHeader: true,
35
- RenderModal: ( { items: posts, closeModal, onPerform } ) => {
36
- const { createSuccessNotice, createErrorNotice } =
37
- useDispatch( noticesStore );
38
- const { deleteEntityRecord } = useDispatch( coreStore );
39
- return (
40
- <VStack spacing="5">
41
- <Text>
42
- { posts.length === 1
43
- ? sprintf(
44
- // translators: %s: The page's title.
45
- __( 'Are you sure you want to delete "%s"?' ),
46
- decodeEntities( posts[ 0 ].title.rendered )
47
- )
48
- : sprintf(
49
- // translators: %d: The number of pages (2 or more).
50
- __(
51
- 'Are you sure you want to delete %d pages?'
52
- ),
53
- posts.length
54
- ) }
55
- </Text>
56
- <HStack justify="right">
57
- <Button variant="tertiary" onClick={ closeModal }>
58
- { __( 'Cancel' ) }
59
- </Button>
60
- <Button
61
- variant="primary"
62
- onClick={ async () => {
63
- const promiseResult = await Promise.allSettled(
64
- posts.map( ( post ) => {
65
- return deleteEntityRecord(
66
- 'postType',
67
- post.type,
68
- post.id,
69
- {},
70
- { throwOnError: true }
71
- );
72
- } )
73
- );
74
- // If all the promises were fulfilled with success.
75
- if (
76
- promiseResult.every(
77
- ( { status } ) => status === 'fulfilled'
78
- )
79
- ) {
80
- let successMessage;
81
- if ( promiseResult.length === 1 ) {
82
- successMessage = sprintf(
83
- /* translators: The posts's title. */
84
- __( '"%s" moved to the Trash.' ),
85
- decodeEntities(
86
- posts[ 0 ].title.rendered
87
- )
88
- );
89
- } else {
90
- successMessage = __(
91
- 'Pages moved to the Trash.'
92
- );
93
- }
94
- createSuccessNotice( successMessage, {
95
- type: 'snackbar',
96
- id: 'edit-site-page-trashed',
97
- } );
98
- } else {
99
- // If there was at lease one failure.
100
- let errorMessage;
101
- // If we were trying to move a single post to the trash.
102
- if ( promiseResult.length === 1 ) {
103
- if ( promiseResult[ 0 ].reason?.message ) {
104
- errorMessage =
105
- promiseResult[ 0 ].reason.message;
106
- } else {
107
- errorMessage = __(
108
- 'An error occurred while moving the post to the trash.'
109
- );
110
- }
111
- // If we were trying to move multiple posts to the trash
112
- } else {
113
- const errorMessages = new Set();
114
- const failedPromises = promiseResult.filter(
115
- ( { status } ) => status === 'rejected'
116
- );
117
- for ( const failedPromise of failedPromises ) {
118
- if ( failedPromise.reason?.message ) {
119
- errorMessages.add(
120
- failedPromise.reason.message
121
- );
122
- }
123
- }
124
- if ( errorMessages.size === 0 ) {
125
- errorMessage = __(
126
- 'An error occurred while moving the posts to the trash.'
127
- );
128
- } else if ( errorMessages.size === 1 ) {
129
- errorMessage = sprintf(
130
- /* translators: %s: an error message */
131
- __(
132
- 'An error occurred while moving the posts to the trash: %s'
133
- ),
134
- [ ...errorMessages ][ 0 ]
135
- );
136
- } else {
137
- errorMessage = sprintf(
138
- /* translators: %s: a list of comma separated error messages */
139
- __(
140
- 'Some errors occurred while moving the pages to the trash: %s'
141
- ),
142
- [ ...errorMessages ].join( ',' )
143
- );
144
- }
145
- createErrorNotice( errorMessage, {
146
- type: 'snackbar',
147
- } );
148
- }
149
- }
150
- if ( onPerform ) {
151
- onPerform();
152
- }
153
- closeModal();
154
- } }
155
- >
156
- { __( 'Delete' ) }
157
- </Button>
158
- </HStack>
159
- </VStack>
160
- );
161
- },
162
- };
163
-
164
- export function usePermanentlyDeletePostAction() {
165
- const { createSuccessNotice, createErrorNotice } =
166
- useDispatch( noticesStore );
167
- const { deleteEntityRecord } = useDispatch( coreStore );
168
-
169
- return useMemo(
170
- () => ( {
171
- id: 'permanently-delete',
172
- label: __( 'Permanently delete' ),
173
- supportsBulk: true,
174
- isEligible( { status } ) {
175
- return status === 'trash';
176
- },
177
- async callback( posts ) {
178
- const promiseResult = await Promise.allSettled(
179
- posts.map( ( post ) => {
180
- return deleteEntityRecord(
181
- 'postType',
182
- post.type,
183
- post.id,
184
- { force: true },
185
- { throwOnError: true }
186
- );
187
- } )
188
- );
189
- // If all the promises were fulfilled with success.
190
- if (
191
- promiseResult.every(
192
- ( { status } ) => status === 'fulfilled'
193
- )
194
- ) {
195
- let successMessage;
196
- if ( promiseResult.length === 1 ) {
197
- successMessage = sprintf(
198
- /* translators: The posts's title. */
199
- __( '"%s" permanently deleted.' ),
200
- decodeEntities( posts[ 0 ].title.rendered )
201
- );
202
- } else {
203
- successMessage = __(
204
- 'The posts were permanently deleted.'
205
- );
206
- }
207
- createSuccessNotice( successMessage, {
208
- type: 'snackbar',
209
- id: 'edit-site-post-permanently-deleted',
210
- } );
211
- } else {
212
- // If there was at lease one failure.
213
- let errorMessage;
214
- // If we were trying to permanently delete a single post.
215
- if ( promiseResult.length === 1 ) {
216
- if ( promiseResult[ 0 ].reason?.message ) {
217
- errorMessage = promiseResult[ 0 ].reason.message;
218
- } else {
219
- errorMessage = __(
220
- 'An error occurred while permanently deleting the post.'
221
- );
222
- }
223
- // If we were trying to permanently delete multiple posts
224
- } else {
225
- const errorMessages = new Set();
226
- const failedPromises = promiseResult.filter(
227
- ( { status } ) => status === 'rejected'
228
- );
229
- for ( const failedPromise of failedPromises ) {
230
- if ( failedPromise.reason?.message ) {
231
- errorMessages.add(
232
- failedPromise.reason.message
233
- );
234
- }
235
- }
236
- if ( errorMessages.size === 0 ) {
237
- errorMessage = __(
238
- 'An error occurred while permanently deleting the posts.'
239
- );
240
- } else if ( errorMessages.size === 1 ) {
241
- errorMessage = sprintf(
242
- /* translators: %s: an error message */
243
- __(
244
- 'An error occurred while permanently deleting the posts: %s'
245
- ),
246
- [ ...errorMessages ][ 0 ]
247
- );
248
- } else {
249
- errorMessage = sprintf(
250
- /* translators: %s: a list of comma separated error messages */
251
- __(
252
- 'Some errors occurred while permanently deleting the posts: %s'
253
- ),
254
- [ ...errorMessages ].join( ',' )
255
- );
256
- }
257
- createErrorNotice( errorMessage, {
258
- type: 'snackbar',
259
- } );
260
- }
261
- }
262
- },
263
- } ),
264
- [ createSuccessNotice, createErrorNotice, deleteEntityRecord ]
265
- );
266
- }
267
-
268
- export function useRestorePostAction() {
269
- const { createSuccessNotice, createErrorNotice } =
270
- useDispatch( noticesStore );
271
- const { editEntityRecord, saveEditedEntityRecord } =
272
- useDispatch( coreStore );
273
-
274
- return useMemo(
275
- () => ( {
276
- id: 'restore',
277
- label: __( 'Restore' ),
278
- isPrimary: true,
279
- icon: backup,
280
- supportsBulk: true,
281
- isEligible( { status } ) {
282
- return status === 'trash';
283
- },
284
- async callback( posts ) {
285
- try {
286
- for ( const post of posts ) {
287
- await editEntityRecord(
288
- 'postType',
289
- post.type,
290
- post.id,
291
- {
292
- status: 'draft',
293
- }
294
- );
295
- await saveEditedEntityRecord(
296
- 'postType',
297
- post.type,
298
- post.id,
299
- { throwOnError: true }
300
- );
301
- }
302
-
303
- createSuccessNotice(
304
- posts.length > 1
305
- ? sprintf(
306
- /* translators: The number of posts. */
307
- __( '%d posts have been restored.' ),
308
- posts.length
309
- )
310
- : sprintf(
311
- /* translators: The number of posts. */
312
- __( '"%s" has been restored.' ),
313
- decodeEntities( posts[ 0 ].title.rendered )
314
- ),
315
- {
316
- type: 'snackbar',
317
- id: 'edit-site-post-restored',
318
- }
319
- );
320
- } catch ( error ) {
321
- let errorMessage;
322
- if (
323
- error.message &&
324
- error.code !== 'unknown_error' &&
325
- error.message
326
- ) {
327
- errorMessage = error.message;
328
- } else if ( posts.length > 1 ) {
329
- errorMessage = __(
330
- 'An error occurred while restoring the posts.'
331
- );
332
- } else {
333
- errorMessage = __(
334
- 'An error occurred while restoring the post.'
335
- );
336
- }
337
-
338
- createErrorNotice( errorMessage, { type: 'snackbar' } );
339
- }
340
- },
341
- } ),
342
- [
343
- createSuccessNotice,
344
- createErrorNotice,
345
- editEntityRecord,
346
- saveEditedEntityRecord,
347
- ]
348
- );
349
- }
350
-
351
- export const viewPostAction = {
352
- id: 'view-post',
353
- label: __( 'View' ),
354
- isPrimary: true,
355
- icon: external,
356
- isEligible( post ) {
357
- return post.status !== 'trash';
358
- },
359
- callback( posts ) {
360
- const post = posts[ 0 ];
361
- window.open( post.link, '_blank' );
362
- },
363
- };
364
-
365
- export function useEditPostAction() {
366
- const history = useHistory();
367
- return useMemo(
368
- () => ( {
369
- id: 'edit-post',
370
- label: __( 'Edit' ),
371
- isPrimary: true,
372
- icon: edit,
373
- isEligible( { status } ) {
374
- return status !== 'trash';
375
- },
376
- callback( posts ) {
377
- const post = posts[ 0 ];
378
- history.push( {
379
- postId: post.id,
380
- postType: post.type,
381
- canvas: 'edit',
382
- } );
383
- },
384
- } ),
385
- [ history ]
386
- );
387
- }
388
- export const postRevisionsAction = {
389
- id: 'view-post-revisions',
390
- label: __( 'View revisions' ),
391
- isPrimary: false,
392
- isEligible: ( post ) => {
393
- if ( post.status === 'trash' ) {
394
- return false;
395
- }
396
- const lastRevisionId =
397
- post?._links?.[ 'predecessor-version' ]?.[ 0 ]?.id ?? null;
398
- const revisionsCount =
399
- post?._links?.[ 'version-history' ]?.[ 0 ]?.count ?? 0;
400
- return lastRevisionId && revisionsCount > 1;
401
- },
402
- callback( posts ) {
403
- const post = posts[ 0 ];
404
- const href = addQueryArgs( 'revision.php', {
405
- revision: post?._links?.[ 'predecessor-version' ]?.[ 0 ]?.id,
406
- } );
407
- document.location.href = href;
408
- },
409
- };
@@ -1,53 +0,0 @@
1
- /**
2
- * External dependencies
3
- */
4
- import classnames from 'classnames';
5
-
6
- /**
7
- * WordPress dependencies
8
- */
9
- import {
10
- Icon,
11
- __experimentalText as Text,
12
- __experimentalHStack as HStack,
13
- __experimentalVStack as VStack,
14
- } from '@wordpress/components';
15
-
16
- export default function SidebarCard( {
17
- className,
18
- title,
19
- icon,
20
- description,
21
- actions,
22
- children,
23
- } ) {
24
- return (
25
- <div className={ classnames( 'edit-site-sidebar-card', className ) }>
26
- <HStack
27
- spacing={ 2 }
28
- className="edit-site-sidebar-card__header"
29
- align="flex-start"
30
- >
31
- <Icon className="edit-site-sidebar-card__icon" icon={ icon } />
32
- <Text
33
- numberOfLines={ 2 }
34
- truncate
35
- className="edit-site-sidebar-card__title"
36
- weight={ 500 }
37
- as="h2"
38
- >
39
- { title }
40
- </Text>
41
- { actions }
42
- </HStack>
43
- <VStack className="edit-site-sidebar-card__content">
44
- { description && (
45
- <div className="edit-site-sidebar-card__description">
46
- { description }
47
- </div>
48
- ) }
49
- { children }
50
- </VStack>
51
- </div>
52
- );
53
- }